-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,469 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
report/* @menduz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
release: | ||
types: | ||
- created | ||
|
||
name: Publish NPM package | ||
jobs: | ||
install: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Use Node.js 14.x | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14.x | ||
- name: install | ||
run: npm ci | ||
- name: build | ||
run: npm run build | ||
- name: test | ||
run: npm run test | ||
- name: Publish | ||
uses: menduz/oddish-action@master | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
on: | ||
push: | ||
branches-ignore: | ||
- "master" | ||
- "main" | ||
pull_request: | ||
|
||
name: PR Validation | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Use Node.js 14.x | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14.x | ||
- name: install | ||
run: npm ci | ||
- name: build | ||
run: npm run build | ||
- name: test | ||
run: npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require: | ||
- 'test/index' | ||
reporter: | ||
- 'spec' | ||
watch-files: | ||
- 'dist/**/*.js' | ||
- 'test/**/*.ts' | ||
spec: 'test/**/*.spec.ts' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,39 @@ | ||
# common-schemas | ||
|
||
``` | ||
npm i @dcl/shemas | ||
``` | ||
|
||
### Design considerations | ||
|
||
- The main entrypoint of the library export namespaces only | ||
- Every namespace is a domain `MetaTransactions` | ||
- Type names are PascalCase | ||
- Validators and schemas are camelCase | ||
|
||
|
||
## Generating types, validators and schemas | ||
|
||
We will export types that act as values. We do that using the "namespaces" of typescript. | ||
|
||
```ts | ||
// Declare type | ||
export type MyType = { | ||
value: number | ||
} | ||
// Declare namespace | ||
export namespace MyType { | ||
export const schema: Schema<MyType> = { | ||
type: "object", | ||
properties: { | ||
value: { type: number } | ||
}, | ||
additionalProperties: false, | ||
required: ["value"] | ||
} | ||
|
||
export const validate = generateValidator<MyType>(schema) | ||
} | ||
``` | ||
|
||
In that sense, MyType can be both used as type `const a: MyType` and as object `MyType.validate(a)`. |
Oops, something went wrong.