Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Feature/concat schemas #432

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

dmitryt
Copy link
Contributor

@dmitryt dmitryt commented Aug 3, 2022

  • tests and linter show no problems (npm t)
  • tests are added/updated for bug fixes and new features
  • code is properly formatted (npm run fmt)
  • description of changes is added in CHANGELOG.md
  • update .d.ts typings

@@ -20,6 +20,37 @@ class Schema extends SchemaMetadata {
return null;
}

static concat(...sources) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to use Schema.protoype.toJSON to reduce amount of code. You can create new Schema with just typings from toJSON

// Q: How to merge options?
for (const schema of schemas) {
resultSchema.updateFromSchema(schema);
// Q: Can we have conflicts with indexes?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need examples of it, write tests please

const schema2 = Schema.from({ c: 'string', d: 'number' });
const schema3 = Schema.from({ e: 'string', f: 'number' });
test.strictEqual(
Schema.concat(schema1, schema2, schema3).toString(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use toJSON to check typings

}
const schema3 = Schema.from({ Custom: {}, type: 'string' });
const schema4 = Schema.from({ Custom: {}, type: 'number' });
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use test.throws(() => fn(), new Error(your error message))

(test) => {
const schema1 = Schema.from({ a: 'string', b: 'number' });
const schema2 = Schema.from({ Custom: {}, type: 'string' });
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use test.throws

}
}
const resultSchema = Schema.from(defs);
// Q: How to merge options?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to merge options and concat validate functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants