@based/schema 0.0.5 → 0.0.7

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 (48) hide show
  1. package/dist/set/collections.d.ts +5 -0
  2. package/dist/set/collections.js +123 -0
  3. package/dist/set/collections.js.map +1 -0
  4. package/dist/set/error.d.ts +10 -0
  5. package/dist/set/error.js +19 -0
  6. package/dist/set/error.js.map +1 -0
  7. package/dist/set/index.d.ts +1 -1
  8. package/dist/set/index.js +13 -17
  9. package/dist/set/index.js.map +1 -1
  10. package/dist/set/number copy.d.ts +4 -0
  11. package/dist/set/number copy.js +57 -0
  12. package/dist/set/number copy.js.map +1 -0
  13. package/dist/set/number.d.ts +4 -0
  14. package/dist/set/number.js +98 -0
  15. package/dist/set/number.js.map +1 -0
  16. package/dist/set/parsers.d.ts +2 -5
  17. package/dist/set/parsers.js +35 -357
  18. package/dist/set/parsers.js.map +1 -1
  19. package/dist/set/references.d.ts +3 -0
  20. package/dist/set/references.js +77 -0
  21. package/dist/set/references.js.map +1 -0
  22. package/dist/set/rest copy.d.ts +5 -0
  23. package/dist/set/rest copy.js +53 -0
  24. package/dist/set/rest copy.js.map +1 -0
  25. package/dist/set/rest.d.ts +5 -0
  26. package/dist/set/rest.js +57 -0
  27. package/dist/set/rest.js.map +1 -0
  28. package/dist/set/string.d.ts +3 -0
  29. package/dist/set/string.js +149 -0
  30. package/dist/set/string.js.map +1 -0
  31. package/dist/set/types.d.ts +5 -0
  32. package/dist/set/types.js +3 -0
  33. package/dist/set/types.js.map +1 -0
  34. package/dist/types.d.ts +36 -17
  35. package/dist/types.js.map +1 -1
  36. package/package.json +3 -1
  37. package/src/set/collections.ts +215 -0
  38. package/src/set/error.ts +17 -0
  39. package/src/set/index.ts +14 -21
  40. package/src/set/number.ts +136 -0
  41. package/src/set/parsers.ts +17 -553
  42. package/src/set/references.ts +107 -0
  43. package/src/set/rest.ts +83 -0
  44. package/src/set/string.ts +184 -0
  45. package/src/set/types.ts +20 -0
  46. package/src/types.ts +105 -20
  47. package/test/setWalker.ts +23 -7
  48. package/src/set/handleError.ts +0 -15
@@ -0,0 +1,107 @@
1
+ import { Parser } from './types'
2
+ import { error, ParseError } from './error'
3
+
4
+ export const reference: Parser<'reference'> = async (
5
+ path,
6
+ value,
7
+ fieldSchema,
8
+ typeSchema,
9
+ target,
10
+ handlers,
11
+ noCollect
12
+ ) => {
13
+ // $no root
14
+ // prob pass these as options
15
+ // value .default
16
+ // $value
17
+
18
+ if (typeof value !== 'string') {
19
+ error(path, ParseError.incorrectFormat)
20
+ }
21
+
22
+ if ('allowedTypes' in fieldSchema) {
23
+ const prefix = value.slice(0, 2)
24
+ const targetType = target.schema.prefixToTypeMapping[prefix]
25
+ if (!targetType) {
26
+ error(path, ParseError.referenceIsIncorrectType)
27
+ }
28
+ let typeMatches = false
29
+ for (const t of fieldSchema.allowedTypes) {
30
+ if (typeof t === 'string') {
31
+ if (t === targetType) {
32
+ typeMatches = true
33
+ break
34
+ }
35
+ } else {
36
+ if (t.type && t.type === targetType) {
37
+ typeMatches = true
38
+ if (t.$filter) {
39
+ if (!(await handlers.referenceFilterCondition(value, t.$filter))) {
40
+ error(path, ParseError.referenceIsIncorrectType)
41
+ }
42
+ }
43
+ } else if (!t.type && t.$filter) {
44
+ if (!(await handlers.referenceFilterCondition(value, t.$filter))) {
45
+ error(path, ParseError.referenceIsIncorrectType)
46
+ }
47
+ }
48
+ }
49
+ }
50
+ if (typeMatches === false) {
51
+ error(path, ParseError.referenceIsIncorrectType)
52
+ }
53
+ }
54
+ if (!noCollect) {
55
+ handlers.collect({ path, value, typeSchema, fieldSchema, target })
56
+ }
57
+ }
58
+
59
+ export const references: Parser<'references'> = async (
60
+ path,
61
+ value,
62
+ fieldSchema,
63
+ typeSchema,
64
+ target,
65
+ handlers,
66
+ noCollect
67
+ ) => {
68
+ // default
69
+ // $no root
70
+ if (Array.isArray(value)) {
71
+ await Promise.all(
72
+ value.map((v, i) => {
73
+ return reference(
74
+ [...path, i],
75
+ v,
76
+ // not nice slow
77
+ { ...fieldSchema, type: 'reference' },
78
+ typeSchema,
79
+ target,
80
+ handlers,
81
+ true
82
+ )
83
+ })
84
+ )
85
+ value = { $value: value }
86
+ } else if (typeof value === 'object') {
87
+ if (value.$add) {
88
+ await Promise.all(
89
+ value.$add.map((v, i) => {
90
+ return reference(
91
+ [...path, '$add', i],
92
+ v,
93
+ // not nice slow
94
+ { ...fieldSchema, type: 'reference' },
95
+ typeSchema,
96
+ target,
97
+ handlers,
98
+ true
99
+ )
100
+ })
101
+ )
102
+ }
103
+ }
104
+ if (!noCollect) {
105
+ handlers.collect({ path, value, typeSchema, fieldSchema, target })
106
+ }
107
+ }
@@ -0,0 +1,83 @@
1
+ import { Parser } from './types'
2
+ import { deepEqual } from '@saulx/utils'
3
+ import { hashObjectIgnoreKeyOrder, hash } from '@saulx/hash'
4
+ import { error, ParseError } from './error'
5
+
6
+ export const cardinality: Parser<'cardinality'> = async (
7
+ path,
8
+ value,
9
+ fieldSchema,
10
+ typeSchema,
11
+ target,
12
+ handlers
13
+ ) => {
14
+ if (value && typeof value === 'object') {
15
+ value = hashObjectIgnoreKeyOrder(value).toString(16)
16
+ } else {
17
+ value = hash(value).toString(16)
18
+ }
19
+ handlers.collect({ path, value, typeSchema, fieldSchema, target })
20
+ }
21
+
22
+ export const boolean: Parser<'boolean'> = async (
23
+ path,
24
+ value,
25
+ fieldSchema,
26
+ typeSchema,
27
+ target,
28
+ handlers,
29
+ noCollect
30
+ ) => {
31
+ if (typeof value !== 'boolean') {
32
+ error(path, ParseError.incorrectFormat)
33
+ }
34
+ if (!noCollect) {
35
+ handlers.collect({ path, value, typeSchema, fieldSchema, target })
36
+ }
37
+ }
38
+
39
+ export const enumParser: Parser<'enum'> = async (
40
+ path,
41
+ value,
42
+ fieldSchema,
43
+ typeSchema,
44
+ target,
45
+ handlers,
46
+ noCollect
47
+ ) => {
48
+ const enumValues = fieldSchema.enum
49
+ for (let i = 0; i < enumValues.length; i++) {
50
+ if (deepEqual(enumValues[i], value)) {
51
+ if (!noCollect) {
52
+ handlers.collect({ path, value: i, typeSchema, fieldSchema, target })
53
+ }
54
+ return
55
+ }
56
+ }
57
+ error(path, ParseError.incorrectFormat)
58
+ }
59
+
60
+ export const json: Parser<'json'> = async (
61
+ path,
62
+ value,
63
+ fieldSchema,
64
+ typeSchema,
65
+ target,
66
+ handlers,
67
+ noCollect
68
+ ) => {
69
+ try {
70
+ const parsedValue = JSON.stringify(value)
71
+ if (!noCollect) {
72
+ handlers.collect({
73
+ path,
74
+ value: parsedValue,
75
+ typeSchema,
76
+ fieldSchema,
77
+ target,
78
+ })
79
+ }
80
+ } catch (err) {
81
+ throw err(path, ParseError.incorrectFormat)
82
+ }
83
+ }
@@ -0,0 +1,184 @@
1
+ import { Parser } from './types'
2
+ import { error, ParseError } from './error'
3
+ import { BasedSchemaFieldString, BasedSchemaFieldText } from '../types'
4
+ import validators from 'validator'
5
+
6
+ const formatPatterns: Record<
7
+ BasedSchemaFieldString['format'],
8
+ (str: string) => boolean
9
+ > = {
10
+ email: validators.isEmail,
11
+ URL: validators.isURL,
12
+ MACAddress: validators.isMACAddress,
13
+ IP: validators.isIP,
14
+ IPRange: validators.isIPRange,
15
+ FQDN: validators.isFQDN,
16
+ IBAN: validators.isIBAN,
17
+ BIC: validators.isBIC,
18
+ alpha: validators.isAlpha,
19
+ alphaLocales: validators.isAlphaLocales,
20
+ alphanumeric: validators.isAlphanumeric,
21
+ alphanumericLocales: validators.isAlphanumericLocales,
22
+ passportNumber: validators.isPassportNumber,
23
+ port: validators.isPort,
24
+ lowercase: validators.isLowercase,
25
+ uppercase: validators.isUppercase,
26
+ ascii: validators.isAscii,
27
+ semVer: validators.isSemVer,
28
+ surrogatePair: validators.isSurrogatePair,
29
+ IMEI: validators.isIMEI,
30
+ hexadecimal: validators.isHexadecimal,
31
+ octal: validators.isOctal,
32
+ hexColor: validators.isHexColor,
33
+ rgbColor: validators.isRgbColor,
34
+ HSL: validators.isHSL,
35
+ ISRC: validators.isISRC,
36
+ MD5: validators.isMD5,
37
+ JWT: validators.isJWT,
38
+ UUID: validators.isUUID,
39
+ luhnNumber: validators.isLuhnNumber,
40
+ creditCard: validators.isCreditCard,
41
+ identityCard: validators.isIdentityCard,
42
+ EAN: validators.isEAN,
43
+ ISIN: validators.isISIN,
44
+ ISBN: validators.isISBN,
45
+ ISSN: validators.isISSN,
46
+ mobilePhone: validators.isMobilePhone,
47
+ mobilePhoneLocales: validators.isMobilePhoneLocales,
48
+ postalCode: validators.isPostalCode,
49
+ postalCodeLocales: validators.isPostalCodeLocales,
50
+ ethereumAddress: validators.isEthereumAddress,
51
+ currency: validators.isCurrency,
52
+ btcAddress: validators.isBtcAddress,
53
+ ISO6391: validators.isISO6391,
54
+ ISO8601: validators.isISO8601,
55
+ RFC3339: validators.isRFC3339,
56
+ ISO31661Alpha2: validators.isISO31661Alpha2,
57
+ ISO31661Alpha3: validators.isISO31661Alpha3,
58
+ ISO4217: validators.isISO4217,
59
+ base32: validators.isBase32,
60
+ base58: validators.isBase58,
61
+ base64: validators.isBase64,
62
+ dataURI: validators.isDataURI,
63
+ magnetURI: validators.isMagnetURI,
64
+ mimeType: validators.isMimeType,
65
+ latLong: validators.isLatLong,
66
+ slug: validators.isSlug,
67
+ strongPassword: validators.isStrongPassword,
68
+ taxID: validators.isTaxID,
69
+ licensePlate: validators.isLicensePlate,
70
+ VAT: validators.isVAT,
71
+ }
72
+
73
+ const validate = (
74
+ path: (string | number)[],
75
+ value: string,
76
+ fieldSchema: BasedSchemaFieldText | BasedSchemaFieldString
77
+ ) => {
78
+ if (typeof value !== 'string') {
79
+ error(path, ParseError.incorrectFormat)
80
+ }
81
+ if (fieldSchema.minLength && value.length < fieldSchema.minLength) {
82
+ error(path, ParseError.subceedsMinimum)
83
+ }
84
+ if (fieldSchema.maxLength && value.length > fieldSchema.maxLength) {
85
+ error(path, ParseError.exceedsMaximum)
86
+ }
87
+ if (fieldSchema.pattern) {
88
+ const re = new RegExp(fieldSchema.pattern)
89
+ if (!re.test(value)) {
90
+ error(path, ParseError.incorrectFormat)
91
+ }
92
+ }
93
+ if (fieldSchema.format && !formatPatterns[fieldSchema.format](value)) {
94
+ error(path, ParseError.incorrectFormat)
95
+ }
96
+ }
97
+
98
+ export const string: Parser<'string'> = async (
99
+ path,
100
+ value,
101
+ fieldSchema,
102
+ typeSchema,
103
+ target,
104
+ handlers,
105
+ noCollect
106
+ ) => {
107
+ validate(path, value, fieldSchema)
108
+ if (!noCollect) {
109
+ handlers.collect({ path, value, typeSchema, fieldSchema, target })
110
+ }
111
+ }
112
+
113
+ export const text: Parser<'text'> = async (
114
+ path,
115
+ value,
116
+ fieldSchema,
117
+ typeSchema,
118
+ target,
119
+ handlers,
120
+ noCollect
121
+ ) => {
122
+ const valueType = typeof value
123
+ if (target.$language && valueType === 'string') {
124
+ validate(path, value, fieldSchema)
125
+ if (!noCollect) {
126
+ handlers.collect({
127
+ path,
128
+ value: { [target.$language]: value },
129
+ typeSchema,
130
+ fieldSchema,
131
+ target,
132
+ })
133
+ }
134
+ return
135
+ }
136
+
137
+ if (valueType !== 'object') {
138
+ error(path, ParseError.incorrectFormat)
139
+ }
140
+
141
+ for (const key in value) {
142
+ const newPath = [...path, key]
143
+
144
+ if (typeof value[key] === 'object') {
145
+ if (value[key].$value) {
146
+ text(
147
+ [...path, key, '$value'],
148
+ value[key].$value,
149
+ fieldSchema,
150
+ typeSchema,
151
+ target,
152
+ handlers,
153
+ true
154
+ )
155
+ }
156
+
157
+ // if (value[key].$default) {
158
+ // }
159
+
160
+ if (!noCollect) {
161
+ handlers.collect({
162
+ path: newPath,
163
+ value: null,
164
+ typeSchema,
165
+ fieldSchema,
166
+ target,
167
+ })
168
+ }
169
+ continue
170
+ }
171
+
172
+ validate(newPath, value[key], fieldSchema)
173
+
174
+ if (!noCollect) {
175
+ handlers.collect({
176
+ path: newPath,
177
+ value: value[key],
178
+ typeSchema,
179
+ fieldSchema,
180
+ target,
181
+ })
182
+ }
183
+ }
184
+ }
@@ -0,0 +1,20 @@
1
+ import {
2
+ BasedSchemaType,
3
+ BasedSetHandlers,
4
+ BasedSetTarget,
5
+ BasedSchemaFields,
6
+ } from '../types'
7
+
8
+ export type Parser<K extends keyof BasedSchemaFields> = (
9
+ path: (string | number)[],
10
+ value: any,
11
+ fieldSchema: BasedSchemaFields[K],
12
+ typeSchema: BasedSchemaType,
13
+ target: BasedSetTarget,
14
+ handlers: BasedSetHandlers,
15
+ noCollect?: boolean
16
+ ) => Promise<void>
17
+
18
+ export type Parsers = {
19
+ [Key in keyof BasedSchemaFields]: Parser<Key>
20
+ }
package/src/types.ts CHANGED
@@ -28,14 +28,13 @@ export type BasedSchemaFieldType =
28
28
  | 'string'
29
29
  | 'boolean'
30
30
  | 'number'
31
- | 'float'
32
31
  | 'json'
33
32
  | 'integer'
34
33
  | 'timestamp'
35
34
  | 'reference'
36
35
  | 'references'
37
36
  | 'text'
38
- | 'hyperloglog'
37
+ | 'cardinality'
39
38
 
40
39
  export const isCollection = (type: string): boolean => {
41
40
  return type === 'array' || type === 'object' || type === 'record'
@@ -58,12 +57,17 @@ export type BasedSchemaContentMediaType =
58
57
  | string
59
58
 
60
59
  export type BasedSchemaFieldShared = {
60
+ hooks?:
61
+ | { interval?: number; hook: string }
62
+ | { interval?: number; hook: string }[]
63
+
61
64
  type?: BasedSchemaFieldType
62
65
  $id?: string
63
66
  $schema?: string
64
67
  isRequired?: boolean
65
68
  title?: string
66
69
  description?: string
70
+ index?: number // Determines the order of fields
67
71
  readOnly?: boolean
68
72
  writeOnly?: boolean
69
73
  $comment?: string
@@ -79,25 +83,92 @@ export type BasedSchemaFieldShared = {
79
83
  }
80
84
 
81
85
  // -------------- Primitive ---------------
82
- export type BasedSchemaFieldString = {
83
- type: 'string'
86
+
87
+ export type BasedSchemaStringShared = {
84
88
  minLength?: number
85
89
  maxLength?: number
86
90
  contentMediaEncoding?: string // base64
87
91
  contentMediaType?: BasedSchemaContentMediaType
88
92
  pattern?: BasedSchemaPattern
89
- format?: 'email' | 'hostname' | 'ipv4' | 'ipv6' | 'uuid' | 'uri'
93
+ format?:
94
+ | 'email'
95
+ | 'URL'
96
+ | 'MACAddress'
97
+ | 'IP'
98
+ | 'IPRange'
99
+ | 'FQDN'
100
+ | 'IBAN'
101
+ | 'BIC'
102
+ | 'alpha'
103
+ | 'alphaLocales'
104
+ | 'alphanumeric'
105
+ | 'alphanumericLocales'
106
+ | 'passportNumber'
107
+ | 'port'
108
+ | 'lowercase'
109
+ | 'uppercase'
110
+ | 'ascii'
111
+ | 'semVer'
112
+ | 'surrogatePair'
113
+ | 'IMEI'
114
+ | 'hexadecimal'
115
+ | 'octal'
116
+ | 'hexColor'
117
+ | 'rgbColor'
118
+ | 'HSL'
119
+ | 'ISRC'
120
+ | 'MD5'
121
+ | 'JWT'
122
+ | 'UUID'
123
+ | 'luhnNumber'
124
+ | 'creditCard'
125
+ | 'identityCard'
126
+ | 'EAN'
127
+ | 'ISIN'
128
+ | 'ISBN'
129
+ | 'ISSN'
130
+ | 'mobilePhone'
131
+ | 'mobilePhoneLocales'
132
+ | 'postalCode'
133
+ | 'postalCodeLocales'
134
+ | 'ethereumAddress'
135
+ | 'currency'
136
+ | 'btcAddress'
137
+ | 'ISO6391'
138
+ | 'ISO8601'
139
+ | 'RFC3339'
140
+ | 'ISO31661Alpha2'
141
+ | 'ISO31661Alpha3'
142
+ | 'ISO4217'
143
+ | 'base32'
144
+ | 'base58'
145
+ | 'base64'
146
+ | 'dataURI'
147
+ | 'magnetURI'
148
+ | 'mimeType'
149
+ | 'latLong'
150
+ | 'slug'
151
+ | 'strongPassword'
152
+ | 'taxID'
153
+ | 'licensePlate'
154
+ | 'VAT'
155
+ }
156
+
157
+ export type BasedSchemaFieldString = {
158
+ type: 'string'
159
+
90
160
  // maybe add some more? e.g. phone
91
- } & BasedSchemaFieldShared
161
+ } & BasedSchemaFieldShared &
162
+ BasedSchemaStringShared
92
163
 
93
164
  export type BasedSchemaFieldEnum = {
94
- enum: any[] // this changes behaviour pretty extreme
95
- // important to type as well because we want to enum based on the type e.g. for references
165
+ enum: any[]
96
166
  } & BasedSchemaFieldShared
97
167
 
98
- export type BasedSchemaFieldConst = {
99
- const: any
100
- } & BasedSchemaFieldShared
168
+ // TODO: check if we want this later
169
+ // export type BasedSchemaFieldConst = {
170
+ // const: any
171
+ // } & BasedSchemaFieldShared
101
172
 
102
173
  type NumberDefaults = {
103
174
  multipleOf?: number
@@ -111,8 +182,8 @@ export type BasedSchemaFieldNumber = NumberDefaults & {
111
182
  type: 'number'
112
183
  }
113
184
 
114
- export type BasedSchemaFieldHyperLogLog = {
115
- type: 'hyperloglog'
185
+ export type BasedSchemaFieldCardinality = {
186
+ type: 'cardinality'
116
187
  }
117
188
 
118
189
  export type BasedSchemaFieldInteger = NumberDefaults & {
@@ -146,12 +217,8 @@ export type BasedSchemaFieldPrimitive =
146
217
  export type BasedSchemaFieldText = {
147
218
  type: 'text'
148
219
  required?: BasedSchemaLanguage[]
149
- contentMediaType?: BasedSchemaContentMediaType
150
- minLength?: number
151
- maxLength?: number
152
- contentMediaEncoding?: string // base64
153
- pattern?: BasedSchemaPattern
154
- } & BasedSchemaFieldShared
220
+ } & BasedSchemaFieldShared &
221
+ BasedSchemaStringShared
155
222
 
156
223
  export type BasedSchemaFieldObject = {
157
224
  type: 'object'
@@ -208,13 +275,31 @@ export type BasedSchemaField =
208
275
  | BasedSchemaFieldPrimitive
209
276
  | BasedSchemaFieldReference
210
277
  | BasedSchemaFieldReferences
211
- | BasedSchemaFieldHyperLogLog
278
+ | BasedSchemaFieldCardinality
212
279
  | {
213
280
  type?: BasedSchemaFieldType
214
281
  isRequired?: boolean // our own
215
282
  $ref: string // to mimic json schema will just load it in place (so only for setting)
216
283
  }
217
284
 
285
+ export type BasedSchemaFields = {
286
+ enum: BasedSchemaFieldEnum
287
+ array: BasedSchemaFieldArray
288
+ object: BasedSchemaFieldObject
289
+ set: BasedSchemaFieldSet
290
+ record: BasedSchemaFieldRecord
291
+ string: BasedSchemaFieldString
292
+ boolean: BasedSchemaFieldBoolean
293
+ number: BasedSchemaFieldNumber
294
+ json: BasedSchemaFieldJSON
295
+ integer: BasedSchemaFieldInteger
296
+ timestamp: BasedSchemaFieldTimeStamp
297
+ reference: BasedSchemaFieldReference
298
+ references: BasedSchemaFieldReferences
299
+ text: BasedSchemaFieldText
300
+ cardinality: BasedSchemaFieldCardinality
301
+ }
302
+
218
303
  export type BasedSchemaType = {
219
304
  fields: {
220
305
  [name: string]: BasedSchemaField
package/test/setWalker.ts CHANGED
@@ -6,6 +6,12 @@ const schema: BasedSchema = {
6
6
  bla: {
7
7
  prefix: 'bl',
8
8
  fields: {
9
+ visits: {
10
+ type: 'cardinality',
11
+ },
12
+ blub: {
13
+ type: 'number',
14
+ },
9
15
  snurp: {
10
16
  type: 'array',
11
17
  values: {
@@ -141,6 +147,14 @@ test.serial('collect correctly', async (t) => {
141
147
  schema,
142
148
  {
143
149
  $id: 'bl1',
150
+ visits: {
151
+ flap: true,
152
+ snurp: false,
153
+ ua: '123435',
154
+ },
155
+ blub: {
156
+ $increment: 1,
157
+ },
144
158
  bla: false,
145
159
  time: now, // do more later
146
160
  setje: [1, 2, 3],
@@ -194,6 +208,8 @@ test.serial('collect correctly', async (t) => {
194
208
  )
195
209
 
196
210
  const result = [
211
+ { path: ['visits'], value: '3a9009740ee' },
212
+ { path: ['blub'], value: { $increment: 1 } },
197
213
  { path: ['bla'], value: false },
198
214
  { path: ['time'], value: now },
199
215
  { path: ['form', 'lastName'], value: 'de beer' },
@@ -201,21 +217,21 @@ test.serial('collect correctly', async (t) => {
201
217
  { path: ['form', 'snurp'], value: 'blx12' },
202
218
  { path: ['form', 'things'], value: 2 },
203
219
  { path: ['form', 'password'], value: 'mypassword!' },
220
+ { path: ['snurp', 0, 'x', 0], value: 1 },
221
+ { path: ['snurp', 0, 'x', 1], value: 2 },
222
+ { path: ['snurp', 0, 'x', 2], value: 3 },
223
+ { path: ['form', 'bla'], value: { $value: ['bl123', 'bl234'] } },
224
+ { path: ['form', 'blab'], value: { $add: ['bl456'] } },
204
225
  {
205
226
  path: ['snurpArray'],
206
227
  value: { $assign: { $idx: 0, $value: 100 } },
207
228
  },
229
+ { path: ['setje'], value: { $value: [1, 2, 3] } },
230
+ { path: ['form', 'blub'], value: { $value: ['x'] } },
208
231
  {
209
232
  path: ['specialArray'],
210
233
  value: { $insert: { $value: ['a', 'b', 'c'], $idx: 0 } },
211
234
  },
212
- { path: ['snurp', 0, 'x', 0], value: 1 },
213
- { path: ['snurp', 0, 'x', 1], value: 2 },
214
- { path: ['snurp', 0, 'x', 2], value: 3 },
215
- { path: ['form', 'bla'], value: { $value: ['bl123', 'bl234'] } },
216
- { path: ['form', 'blab'], value: { $add: ['bl456'] } },
217
- { path: ['setje'], value: { $value: [1, 2, 3] } },
218
- { path: ['form', 'blub'], value: { $value: ['x'] } },
219
235
  ]
220
236
 
221
237
  t.deepEqual(results, result)
@@ -1,15 +0,0 @@
1
- export const createError = (
2
- path: (number | string)[],
3
- fromType: string,
4
- fieldType: string,
5
- value: any,
6
- fieldDoesNotExist?: string,
7
- msg?: string
8
- ): Error => {
9
- const err = new Error()
10
- return new Error(
11
- `Type: "${fromType}" Field: "${path.join(
12
- '.'
13
- )}" is not a valid value for ${fieldType}`
14
- )
15
- }