@based/schema 2.6.0 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/src/compat/newToOld.d.ts +2 -2
  2. package/dist/src/compat/newToOld.js +172 -29
  3. package/dist/src/compat/oldToNew.d.ts +1 -1
  4. package/dist/src/compat/oldToNew.js +200 -25
  5. package/dist/src/display/number.d.ts +2 -1
  6. package/dist/src/display/number.js +10 -0
  7. package/dist/src/display/string.d.ts +3 -1
  8. package/dist/src/display/string.js +5 -0
  9. package/dist/src/display/timestamp.d.ts +3 -1
  10. package/dist/src/display/timestamp.js +9 -0
  11. package/dist/src/error.d.ts +3 -1
  12. package/dist/src/error.js +2 -0
  13. package/dist/src/index.d.ts +1 -1
  14. package/dist/src/index.js +1 -1
  15. package/dist/src/types.d.ts +4 -3
  16. package/dist/src/types.js +74 -0
  17. package/dist/src/validateSchema/basedSchemaTypeValidator.d.ts +3 -0
  18. package/dist/src/validateSchema/basedSchemaTypeValidator.js +45 -0
  19. package/dist/src/validateSchema/fieldValidators.d.ts +27 -0
  20. package/dist/src/validateSchema/fieldValidators.js +360 -0
  21. package/dist/src/validateSchema/index.d.ts +17 -0
  22. package/dist/src/validateSchema/index.js +109 -0
  23. package/dist/src/validateSchema/utils.d.ts +25 -0
  24. package/dist/src/validateSchema/utils.js +61 -0
  25. package/dist/test/compat.js +19 -3
  26. package/dist/test/data/newSchemas.d.ts +2 -2
  27. package/dist/test/data/newSchemas.js +241 -0
  28. package/dist/test/data/oldSchemas.js +122 -122
  29. package/dist/test/validateSchema/basic.js +94 -0
  30. package/dist/test/validateSchema/fields.d.ts +1 -0
  31. package/dist/test/validateSchema/fields.js +436 -0
  32. package/dist/test/validateSchema/languages.d.ts +1 -0
  33. package/dist/test/validateSchema/languages.js +124 -0
  34. package/dist/test/validateSchema/realWorld.d.ts +1 -0
  35. package/dist/test/validateSchema/realWorld.js +13 -0
  36. package/package.json +4 -3
  37. package/dist/src/validateSchema.d.ts +0 -4
  38. package/dist/src/validateSchema.js +0 -35
  39. package/dist/test/validateSchema.js +0 -38
  40. /package/dist/test/{validateSchema.d.ts → validateSchema/basic.d.ts} +0 -0
@@ -1,35 +0,0 @@
1
- // gaurd in the schema for refs in arrays
2
- export const validateType = (_fromSchema, typeName, type) => {
3
- if (type.prefix &&
4
- (typeof type.prefix !== 'string' || type.prefix.length !== 2)) {
5
- throw new Error(`Incorrect prefix "${type.prefix}" for type "${typeName}" has to be a string of 2 alphanumerical characters e.g. "Az", "ab", "cc", "10"`);
6
- }
7
- };
8
- export const validateField = (_fromSchema, _path, _field) => {
9
- //
10
- };
11
- export const validateSchema = (schema) => {
12
- // rewrite schema things like required / required: []
13
- if (typeof schema !== 'object') {
14
- throw new Error('Schema is not an object');
15
- }
16
- if (schema.language && typeof schema.language !== 'string') {
17
- throw new Error('Language must be a string');
18
- }
19
- if (schema.translations && !Array.isArray(schema.translations)) {
20
- throw new Error('Translations needs to be an array');
21
- }
22
- if (schema.$defs) {
23
- // first defs ofc
24
- }
25
- if (schema.root) {
26
- validateType(schema, 'root', schema.root);
27
- }
28
- if (schema.types) {
29
- for (const type in schema.types) {
30
- validateType(schema, type, schema.types[type]);
31
- }
32
- }
33
- return schema;
34
- };
35
- //# sourceMappingURL=validateSchema.js.map
@@ -1,38 +0,0 @@
1
- import test from 'ava';
2
- import { validateSchema } from '../src/index.js';
3
- test.serial('throw on invalid schema', async (t) => {
4
- const prefixError = t.throws(() => {
5
- validateSchema({
6
- $defs: {
7
- yuzi: {
8
- type: 'string',
9
- title: 'BLA',
10
- description: 'SNURP',
11
- },
12
- },
13
- types: {
14
- bla: {
15
- prefix: 'fix',
16
- fields: {
17
- yuzi: {
18
- type: 'object',
19
- customValidator: async (_value, _path, _target) => {
20
- return true;
21
- },
22
- properties: {
23
- gurt: {
24
- $ref: '/$defs/yuzi',
25
- },
26
- flap: {
27
- enum: ['bla', 'blap', 'flip'],
28
- },
29
- },
30
- },
31
- },
32
- },
33
- },
34
- });
35
- });
36
- t.is(prefixError.message, 'Incorrect prefix "fix" for type "bla" has to be a string of 2 alphanumerical characters e.g. "Az", "ab", "cc", "10"');
37
- });
38
- //# sourceMappingURL=validateSchema.js.map