@based/schema 2.2.14 → 2.4.0

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.
@@ -55,6 +55,7 @@ export declare const languages: {
55
55
  lg: string;
56
56
  ka: string;
57
57
  de: string;
58
+ gsw: string;
58
59
  ki: string;
59
60
  el: string;
60
61
  kl: string;
@@ -55,6 +55,7 @@ export const languages = {
55
55
  lg: 'Ganda',
56
56
  ka: 'Georgian',
57
57
  de: 'German',
58
+ gsw: 'Swiss German',
58
59
  ki: 'Gikuyu, Kikuyu',
59
60
  el: 'Greek (Modern)',
60
61
  kl: 'Greenlandic, Kalaallisut',
@@ -57,7 +57,6 @@ export const fields = {
57
57
  }
58
58
  },
59
59
  enum: async (args) => {
60
- // args.stop()
61
60
  const enumValues = args.fieldSchema.enum;
62
61
  for (let i = 0; i < enumValues.length; i++) {
63
62
  if (deepEqual(enumValues[i], args.value)) {
@@ -6,6 +6,10 @@ const opts = {
6
6
  parsers: {
7
7
  keys: {
8
8
  $delete: async (args) => {
9
+ const type = args.fieldSchema?.type;
10
+ if (type === 'json') {
11
+ return;
12
+ }
9
13
  if (args.prev === args.root) {
10
14
  args.error(ParseError.cannotDeleteNodeFromModify);
11
15
  return;
@@ -18,6 +22,10 @@ const opts = {
18
22
  }
19
23
  },
20
24
  $alias: async (args) => {
25
+ const type = args.fieldSchema?.type;
26
+ if (type === 'json') {
27
+ return;
28
+ }
21
29
  if (Array.isArray(args.value)) {
22
30
  for (const field of args.value) {
23
31
  if (typeof field !== 'string') {
@@ -32,6 +40,10 @@ const opts = {
32
40
  }
33
41
  },
34
42
  $merge: async (args) => {
43
+ const type = args.fieldSchema?.type;
44
+ if (type === 'json') {
45
+ return;
46
+ }
35
47
  if (typeof args.value !== 'boolean') {
36
48
  args.error(ParseError.incorrectFormat);
37
49
  return;
@@ -42,12 +54,20 @@ const opts = {
42
54
  return;
43
55
  },
44
56
  $id: async (args) => {
57
+ const type = args.fieldSchema?.type;
58
+ if (type === 'json') {
59
+ return;
60
+ }
45
61
  if (!isValidId(args.schema, args.value)) {
46
62
  args.error(ParseError.incorrectFormat);
47
63
  return;
48
64
  }
49
65
  },
50
66
  $language: async (args) => {
67
+ const type = args.fieldSchema?.type;
68
+ if (type === 'json') {
69
+ return;
70
+ }
51
71
  if (!(args.schema.translations || [])
52
72
  .concat(args.schema.language)
53
73
  .includes(args.value)) {
@@ -57,7 +77,10 @@ const opts = {
57
77
  },
58
78
  $value: async (args) => {
59
79
  const type = args.fieldSchema?.type;
60
- if (type === 'text' || type === 'set' || type == 'references') {
80
+ if (type === 'text' ||
81
+ type === 'set' ||
82
+ type == 'references' ||
83
+ type === 'json') {
61
84
  return;
62
85
  }
63
86
  args.prev.stop();
@@ -73,7 +96,10 @@ const opts = {
73
96
  },
74
97
  $default: async (args) => {
75
98
  const type = args.fieldSchema?.type;
76
- if (type === 'number' || type === 'integer' || type === 'text') {
99
+ if (type === 'number' ||
100
+ type === 'integer' ||
101
+ type === 'text' ||
102
+ type === 'json') {
77
103
  // default can exist with $incr and $decr
78
104
  return;
79
105
  }
@@ -154,6 +154,7 @@ export type BasedSchemaField = BasedSchemaFields[keyof BasedSchemaFields] | (Bas
154
154
  $ref: string;
155
155
  });
156
156
  export type BasedSchemaType = {
157
+ directory?: string;
157
158
  fields: {
158
159
  [name: string]: BasedSchemaField;
159
160
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ import test from 'ava';
2
+ import { setWalker } from '../src/index.js';
3
+ import { errorCollect, resultCollect } from './utils/index.js';
4
+ const schema = {
5
+ types: {
6
+ aType: {
7
+ prefix: 'at',
8
+ fields: {
9
+ json: {
10
+ type: 'json',
11
+ },
12
+ },
13
+ },
14
+ },
15
+ $defs: {},
16
+ language: 'en',
17
+ root: {
18
+ fields: {},
19
+ },
20
+ prefixToTypeMapping: {
21
+ at: 'aType',
22
+ },
23
+ };
24
+ test('json field with keys in it', async (t) => {
25
+ const json = {
26
+ fieldA: 'record2FieldA',
27
+ $id: '$id_inside_json',
28
+ $alias: '$alias_inside_json',
29
+ };
30
+ const res = await setWalker(schema, {
31
+ // type: 'aType',
32
+ $id: 'at1',
33
+ json,
34
+ });
35
+ t.assert(!errorCollect(res).length);
36
+ t.deepEqual(resultCollect(res), [
37
+ { path: ['json'], value: JSON.stringify(json) },
38
+ ]);
39
+ });
40
+ //# sourceMappingURL=json.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/schema",
3
- "version": "2.2.14",
3
+ "version": "2.4.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/src/index.js",
6
6
  "files": [