@based/schema 3.2.0 → 4.1.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.
- package/dist/index.d.ts +3 -5
- package/dist/index.js +2 -21
- package/dist/parse/assert.d.ts +7 -0
- package/dist/parse/assert.js +33 -0
- package/dist/parse/errors.d.ts +19 -0
- package/dist/parse/errors.js +19 -0
- package/dist/parse/index.d.ts +20 -0
- package/dist/parse/index.js +132 -0
- package/dist/parse/props.d.ts +7 -0
- package/dist/parse/props.js +290 -0
- package/dist/parse/utils.d.ts +3 -0
- package/dist/parse/utils.js +29 -0
- package/dist/parsePayload/index.d.ts +3 -0
- package/dist/parsePayload/index.js +2 -0
- package/dist/parseSchema/assert.d.ts +6 -0
- package/dist/parseSchema/assert.js +27 -0
- package/dist/parseSchema/errors.d.ts +19 -0
- package/dist/parseSchema/errors.js +19 -0
- package/dist/parseSchema/index.d.ts +20 -0
- package/dist/parseSchema/index.js +132 -0
- package/dist/parseSchema/props.d.ts +7 -0
- package/dist/parseSchema/props.js +256 -0
- package/dist/parseSchema/utils.d.ts +3 -0
- package/dist/parseSchema/utils.js +29 -0
- package/dist/src/compat/index.js +2 -2
- package/dist/src/set/fields/references.js +3 -30
- package/dist/src/types.d.ts +5 -13
- package/dist/src/types.js +14 -0
- package/dist/src/validateSchema/fieldValidators.js +4 -4
- package/dist/test/compat.js +1 -1
- package/dist/test/data/newSchemas.js +19 -21
- package/dist/test/reference.js +4 -2
- package/dist/test/walker.js +2 -2
- package/dist/types.d.ts +129 -194
- package/dist/types.js +3 -25
- package/package.json +14 -25
- package/README.md +0 -2
- package/dist/display/index.d.ts +0 -2
- package/dist/display/index.js +0 -26
- package/dist/display/number.d.ts +0 -3
- package/dist/display/number.js +0 -89
- package/dist/display/string.d.ts +0 -3
- package/dist/display/string.js +0 -23
- package/dist/display/timestamp.d.ts +0 -3
- package/dist/display/timestamp.js +0 -127
- package/dist/error.d.ts +0 -19
- package/dist/error.js +0 -24
- package/dist/languages.d.ts +0 -187
- package/dist/languages.js +0 -190
- package/dist/set/fields/array.d.ts +0 -2
- package/dist/set/fields/array.js +0 -123
- package/dist/set/fields/index.d.ts +0 -3
- package/dist/set/fields/index.js +0 -74
- package/dist/set/fields/number.d.ts +0 -4
- package/dist/set/fields/number.js +0 -129
- package/dist/set/fields/object.d.ts +0 -3
- package/dist/set/fields/object.js +0 -33
- package/dist/set/fields/references.d.ts +0 -3
- package/dist/set/fields/references.js +0 -128
- package/dist/set/fields/set.d.ts +0 -2
- package/dist/set/fields/set.js +0 -63
- package/dist/set/fields/string.d.ts +0 -3
- package/dist/set/fields/string.js +0 -284
- package/dist/set/index.d.ts +0 -3
- package/dist/set/index.js +0 -183
- package/dist/set/isValidId.d.ts +0 -2
- package/dist/set/isValidId.js +0 -21
- package/dist/set/types.d.ts +0 -0
- package/dist/set/types.js +0 -1
- package/dist/src/compat/newToOld.d.ts +0 -3
- package/dist/src/compat/newToOld.js +0 -218
- package/dist/src/compat/oldToNew.d.ts +0 -3
- package/dist/src/compat/oldToNew.js +0 -210
- package/dist/src/generateQuery.d.ts +0 -12
- package/dist/src/generateQuery.js +0 -75
- package/dist/test/query.d.ts +0 -1
- package/dist/test/query.js +0 -93
- package/dist/updateSchema.d.ts +0 -2
- package/dist/updateSchema.js +0 -16
- package/dist/validateSchema.d.ts +0 -4
- package/dist/validateSchema.js +0 -41
- package/dist/walker/args.d.ts +0 -36
- package/dist/walker/args.js +0 -162
- package/dist/walker/index.d.ts +0 -6
- package/dist/walker/index.js +0 -49
- package/dist/walker/parse.d.ts +0 -3
- package/dist/walker/parse.js +0 -186
- package/dist/walker/types.d.ts +0 -45
- package/dist/walker/types.js +0 -10
|
@@ -65,7 +65,7 @@ const testSchema = {
|
|
|
65
65
|
},
|
|
66
66
|
winner: {
|
|
67
67
|
type: 'reference',
|
|
68
|
-
|
|
68
|
+
allowedType: 'contestant',
|
|
69
69
|
},
|
|
70
70
|
countries: {
|
|
71
71
|
type: 'references',
|
|
@@ -87,7 +87,7 @@ const testSchema = {
|
|
|
87
87
|
},
|
|
88
88
|
image: {
|
|
89
89
|
type: 'reference',
|
|
90
|
-
|
|
90
|
+
allowedType: 'file',
|
|
91
91
|
},
|
|
92
92
|
startTime: {
|
|
93
93
|
type: 'timestamp',
|
|
@@ -99,11 +99,11 @@ const testSchema = {
|
|
|
99
99
|
},
|
|
100
100
|
producer: {
|
|
101
101
|
type: 'reference',
|
|
102
|
-
|
|
102
|
+
allowedType: 'broadcaster',
|
|
103
103
|
},
|
|
104
104
|
distributors: {
|
|
105
105
|
type: 'references',
|
|
106
|
-
|
|
106
|
+
allowedType: 'broadcaster',
|
|
107
107
|
},
|
|
108
108
|
},
|
|
109
109
|
},
|
|
@@ -141,7 +141,7 @@ const testSchema = {
|
|
|
141
141
|
},
|
|
142
142
|
image: {
|
|
143
143
|
type: 'reference',
|
|
144
|
-
|
|
144
|
+
allowedType: 'file',
|
|
145
145
|
},
|
|
146
146
|
content: {
|
|
147
147
|
type: 'text',
|
|
@@ -162,7 +162,7 @@ const testSchema = {
|
|
|
162
162
|
},
|
|
163
163
|
image: {
|
|
164
164
|
type: 'reference',
|
|
165
|
-
|
|
165
|
+
allowedType: 'file',
|
|
166
166
|
},
|
|
167
167
|
},
|
|
168
168
|
},
|
|
@@ -368,7 +368,7 @@ export const newSchemas = [
|
|
|
368
368
|
fields: {
|
|
369
369
|
usedIn: {
|
|
370
370
|
type: 'references',
|
|
371
|
-
|
|
371
|
+
inverseProperty: 'img',
|
|
372
372
|
},
|
|
373
373
|
caption: {
|
|
374
374
|
// needs translation?
|
|
@@ -390,13 +390,13 @@ export const newSchemas = [
|
|
|
390
390
|
seen: { type: 'timestamp' },
|
|
391
391
|
charges: {
|
|
392
392
|
type: 'references',
|
|
393
|
-
|
|
394
|
-
|
|
393
|
+
inverseProperty: 'user',
|
|
394
|
+
allowedType: 'charge',
|
|
395
395
|
},
|
|
396
396
|
articles: {
|
|
397
397
|
type: 'references',
|
|
398
|
-
|
|
399
|
-
|
|
398
|
+
inverseProperty: 'contributors',
|
|
399
|
+
allowedType: 'article',
|
|
400
400
|
},
|
|
401
401
|
},
|
|
402
402
|
},
|
|
@@ -405,8 +405,8 @@ export const newSchemas = [
|
|
|
405
405
|
// does this have a user?
|
|
406
406
|
user: {
|
|
407
407
|
type: 'reference',
|
|
408
|
-
|
|
409
|
-
|
|
408
|
+
inverseProperty: 'charges',
|
|
409
|
+
allowedType: 'user',
|
|
410
410
|
},
|
|
411
411
|
token: { type: 'string' },
|
|
412
412
|
description: { type: 'string' },
|
|
@@ -419,7 +419,7 @@ export const newSchemas = [
|
|
|
419
419
|
title: { type: 'text' },
|
|
420
420
|
children: {
|
|
421
421
|
type: 'references',
|
|
422
|
-
|
|
422
|
+
allowedType: 'article',
|
|
423
423
|
},
|
|
424
424
|
},
|
|
425
425
|
},
|
|
@@ -433,7 +433,7 @@ export const newSchemas = [
|
|
|
433
433
|
// meta_keywords: { type: 'array', values: { type: 'string' } },
|
|
434
434
|
children: {
|
|
435
435
|
type: 'references',
|
|
436
|
-
|
|
436
|
+
allowedType: 'article' // FIXME Can't have both 'category'],
|
|
437
437
|
},
|
|
438
438
|
},
|
|
439
439
|
},
|
|
@@ -444,10 +444,8 @@ export const newSchemas = [
|
|
|
444
444
|
title: 'Writers',
|
|
445
445
|
description: 'Writers or people involved with the article.',
|
|
446
446
|
type: 'references',
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
fromField: 'articles',
|
|
450
|
-
},
|
|
447
|
+
allowedType: 'user',
|
|
448
|
+
inverseProperty: 'articles',
|
|
451
449
|
},
|
|
452
450
|
contributorsText: {
|
|
453
451
|
title: 'Contributors text',
|
|
@@ -472,8 +470,8 @@ export const newSchemas = [
|
|
|
472
470
|
},
|
|
473
471
|
img: {
|
|
474
472
|
type: 'reference',
|
|
475
|
-
|
|
476
|
-
|
|
473
|
+
allowedType: 'file',
|
|
474
|
+
inverseProperty: 'usedIn',
|
|
477
475
|
},
|
|
478
476
|
hits: { type: 'number' }, // get a bit more going here maybe? what does this mean
|
|
479
477
|
// membership: { enum: ['Need membership', 'Free'] },
|
package/dist/test/reference.js
CHANGED
|
@@ -15,17 +15,19 @@ const schema = {
|
|
|
15
15
|
fields: {
|
|
16
16
|
ref: {
|
|
17
17
|
type: 'reference',
|
|
18
|
+
allowedType: 'bla',
|
|
18
19
|
},
|
|
19
20
|
children: {
|
|
20
21
|
type: 'references',
|
|
22
|
+
allowedType: 'bla',
|
|
21
23
|
},
|
|
22
24
|
referencesToThings: {
|
|
23
25
|
type: 'references',
|
|
24
|
-
|
|
26
|
+
allowedType: 'thing',
|
|
25
27
|
},
|
|
26
28
|
referenceToThing: {
|
|
27
29
|
type: 'reference',
|
|
28
|
-
|
|
30
|
+
allowedType: 'thing',
|
|
29
31
|
},
|
|
30
32
|
},
|
|
31
33
|
},
|
package/dist/test/walker.js
CHANGED
|
@@ -14,11 +14,11 @@ const schema = {
|
|
|
14
14
|
fields: {
|
|
15
15
|
referencesToThings: {
|
|
16
16
|
type: 'references',
|
|
17
|
-
|
|
17
|
+
allowedType: 'thing',
|
|
18
18
|
},
|
|
19
19
|
referenceToThing: {
|
|
20
20
|
type: 'reference',
|
|
21
|
-
|
|
21
|
+
allowedType: 'thing',
|
|
22
22
|
},
|
|
23
23
|
enum: {
|
|
24
24
|
enum: ['tony', 'jim'],
|
package/dist/types.d.ts
CHANGED
|
@@ -1,205 +1,140 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { ArgsClass, Path } from './walker';
|
|
5
|
-
import { StringFormat } from './display/string';
|
|
6
|
-
import { NumberFormat } from './display/number';
|
|
7
|
-
import { DateFormat } from './display/timestamp';
|
|
8
|
-
export type AllowedTypes = (string | {
|
|
1
|
+
type Letter = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';
|
|
2
|
+
type QueryFn = Function;
|
|
3
|
+
type PropValues = {
|
|
9
4
|
type?: string;
|
|
10
|
-
$filter: any | any[];
|
|
11
|
-
})[];
|
|
12
|
-
export declare const basedSchemaFieldTypes: readonly ["array", "object", "record", "set", "string", "boolean", "number", "json", "integer", "timestamp", "reference", "references", "text", "enum", "cardinality"];
|
|
13
|
-
export type BasedSchemaFieldType = (typeof basedSchemaFieldTypes)[number];
|
|
14
|
-
export declare const isCollection: (type: string) => boolean;
|
|
15
|
-
export type BasedSchemaPattern = string;
|
|
16
|
-
export type BasedSchemaLanguage = Language;
|
|
17
|
-
export declare const languages: string[];
|
|
18
|
-
export type BasedSchemaTypePrefix = string;
|
|
19
|
-
export type BasedSchemaContentMediaType = 'text/html' | 'text/plain' | 'text/markdown' | 'image/png' | 'image/jpeg' | 'video/mp4' | 'image/*' | 'video/*' | 'audio/*' | '*/*' | `${string}/${string}`;
|
|
20
|
-
export type BasedSchemaFieldShared = {
|
|
21
|
-
hooks?: {
|
|
22
|
-
interval?: number;
|
|
23
|
-
hook: string;
|
|
24
|
-
} | {
|
|
25
|
-
interval?: number;
|
|
26
|
-
hook: string;
|
|
27
|
-
}[];
|
|
28
|
-
type?: BasedSchemaFieldType;
|
|
29
|
-
$id?: string;
|
|
30
|
-
$schema?: string;
|
|
31
|
-
isRequired?: boolean;
|
|
32
|
-
title?: string;
|
|
33
|
-
description?: string;
|
|
34
|
-
index?: number;
|
|
35
|
-
readOnly?: boolean;
|
|
36
|
-
writeOnly?: boolean;
|
|
37
|
-
$comment?: string;
|
|
38
|
-
examples?: any[];
|
|
39
5
|
default?: any;
|
|
40
|
-
customValidator?: (value: any, path: (number | string)[], target: BasedSetTarget) => Promise<boolean>;
|
|
41
|
-
$defs?: {
|
|
42
|
-
[key: string]: BasedSchemaField;
|
|
43
|
-
};
|
|
44
|
-
$delete?: boolean;
|
|
45
|
-
};
|
|
46
|
-
export type BasedSchemaStringShared = {
|
|
47
|
-
minLength?: number;
|
|
48
|
-
maxLength?: number;
|
|
49
|
-
contentMediaEncoding?: string;
|
|
50
|
-
contentMediaType?: BasedSchemaContentMediaType;
|
|
51
|
-
pattern?: BasedSchemaPattern;
|
|
52
|
-
format?: 'email' | 'URL' | 'MACAddress' | 'IP' | 'IPRange' | 'FQDN' | 'IBAN' | 'BIC' | 'alpha' | 'alphaLocales' | 'alphanumeric' | 'alphanumericLocales' | 'passportNumber' | 'port' | 'lowercase' | 'uppercase' | 'ascii' | 'semVer' | 'surrogatePair' | 'IMEI' | 'hexadecimal' | 'octal' | 'hexColor' | 'rgbColor' | 'HSL' | 'ISRC' | 'MD5' | 'JWT' | 'UUID' | 'luhnNumber' | 'creditCard' | 'identityCard' | 'EAN' | 'ISIN' | 'ISBN' | 'ISSN' | 'mobilePhone' | 'mobilePhoneLocales' | 'postalCode' | 'postalCodeLocales' | 'ethereumAddress' | 'currency' | 'btcAddress' | 'ISO6391' | 'ISO8601' | 'RFC3339' | 'ISO31661Alpha2' | 'ISO31661Alpha3' | 'ISO4217' | 'base32' | 'base58' | 'base64' | 'dataURI' | 'magnetURI' | 'mimeType' | 'latLong' | 'slug' | 'strongPassword' | 'taxID' | 'licensePlate' | 'VAT';
|
|
53
|
-
display?: StringFormat;
|
|
54
|
-
multiline?: boolean;
|
|
55
6
|
};
|
|
56
|
-
type
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export type
|
|
65
|
-
|
|
7
|
+
type Prop<V extends PropValues> = {
|
|
8
|
+
required?: boolean;
|
|
9
|
+
label?: Record<string, string>;
|
|
10
|
+
description?: Record<string, string>;
|
|
11
|
+
path?: string;
|
|
12
|
+
query?: QueryFn;
|
|
13
|
+
} & V;
|
|
14
|
+
type EnumItem = string | number | boolean;
|
|
15
|
+
export type SchemaReferences = Prop<{
|
|
16
|
+
type?: 'references';
|
|
17
|
+
items: SchemaReference;
|
|
18
|
+
}>;
|
|
19
|
+
export type SchemaReferencesOneWay = Prop<{
|
|
20
|
+
type?: 'references';
|
|
21
|
+
items: SchemaReferenceOneWay;
|
|
22
|
+
}>;
|
|
23
|
+
export type SchemaText = Prop<{
|
|
24
|
+
type: 'text';
|
|
25
|
+
default?: Record<string, string>;
|
|
26
|
+
}>;
|
|
27
|
+
type NumberType = 'number' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32';
|
|
28
|
+
export type SchemaNumber = Prop<{
|
|
29
|
+
type: NumberType;
|
|
30
|
+
default?: number;
|
|
31
|
+
min?: number;
|
|
32
|
+
max?: number;
|
|
33
|
+
step?: number | 'any';
|
|
34
|
+
}>;
|
|
35
|
+
export type SchemaString = Prop<{
|
|
66
36
|
type: 'string';
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
export type
|
|
73
|
-
type: '
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
} & BasedSchemaFieldShared;
|
|
79
|
-
export type BasedSchemaFieldInteger = NumberDefaults & {
|
|
80
|
-
type: 'integer';
|
|
81
|
-
display?: BasedNumberDisplay;
|
|
82
|
-
} & BasedSchemaFieldShared;
|
|
83
|
-
export type BasedSchemaFieldTimeStamp = NumberDefaults & {
|
|
84
|
-
type: 'timestamp';
|
|
85
|
-
display?: BasedTimestampDisplay;
|
|
86
|
-
} & BasedSchemaFieldShared;
|
|
87
|
-
export type BasedSchemaFieldBoolean = {
|
|
37
|
+
default?: string;
|
|
38
|
+
maxBytes?: number;
|
|
39
|
+
max?: number;
|
|
40
|
+
min?: number;
|
|
41
|
+
}>;
|
|
42
|
+
export type SchemaBinary = Prop<{
|
|
43
|
+
type: 'binary';
|
|
44
|
+
default?: ArrayBuffer;
|
|
45
|
+
maxBytes?: number;
|
|
46
|
+
}>;
|
|
47
|
+
export type SchemaBoolean = Prop<{
|
|
88
48
|
type: 'boolean';
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
export type BasedSchemaFieldEnumerable = BasedSchemaFieldText | BasedSchemaFieldObject | BasedSchemaFieldRecord | BasedSchemaFieldArray | BasedSchemaFieldSet;
|
|
118
|
-
export type BasedSchemaFieldReference = {
|
|
119
|
-
type: 'reference';
|
|
120
|
-
bidirectional?: {
|
|
121
|
-
fromField: string;
|
|
122
|
-
};
|
|
123
|
-
allowedTypes?: AllowedTypes;
|
|
124
|
-
} & BasedSchemaFieldShared;
|
|
125
|
-
export type BasedSchemaFieldReferences = {
|
|
126
|
-
type: 'references';
|
|
127
|
-
bidirectional?: {
|
|
128
|
-
fromField: string;
|
|
129
|
-
};
|
|
130
|
-
allowedTypes?: AllowedTypes;
|
|
131
|
-
} & BasedSchemaFieldShared;
|
|
132
|
-
export type BasedSchemaFields = {
|
|
133
|
-
string: BasedSchemaFieldString;
|
|
134
|
-
number: BasedSchemaFieldNumber;
|
|
135
|
-
integer: BasedSchemaFieldInteger;
|
|
136
|
-
timestamp: BasedSchemaFieldTimeStamp;
|
|
137
|
-
json: BasedSchemaFieldJSON;
|
|
138
|
-
boolean: BasedSchemaFieldBoolean;
|
|
139
|
-
enum: BasedSchemaFieldEnum;
|
|
140
|
-
array: BasedSchemaFieldArray;
|
|
141
|
-
object: BasedSchemaFieldObject;
|
|
142
|
-
set: BasedSchemaFieldSet;
|
|
143
|
-
record: BasedSchemaFieldRecord;
|
|
144
|
-
reference: BasedSchemaFieldReference;
|
|
145
|
-
references: BasedSchemaFieldReferences;
|
|
146
|
-
text: BasedSchemaFieldText;
|
|
147
|
-
cardinality: BasedSchemaFieldCardinality;
|
|
49
|
+
default?: boolean;
|
|
50
|
+
}>;
|
|
51
|
+
export type SchemaTimestamp = Prop<{
|
|
52
|
+
type: 'timestamp';
|
|
53
|
+
default?: number | Date;
|
|
54
|
+
on?: 'create' | 'update';
|
|
55
|
+
}>;
|
|
56
|
+
export type SchemaReferenceOneWay = Prop<{
|
|
57
|
+
type?: 'reference';
|
|
58
|
+
default?: string;
|
|
59
|
+
ref: string;
|
|
60
|
+
}>;
|
|
61
|
+
export type SchemaReference = Prop<{
|
|
62
|
+
type?: 'reference';
|
|
63
|
+
default?: string;
|
|
64
|
+
ref: string;
|
|
65
|
+
prop: string;
|
|
66
|
+
}> & Record<`$${string}`, SchemaPropOneWay>;
|
|
67
|
+
export type SchemaObject = Prop<{
|
|
68
|
+
type?: 'object';
|
|
69
|
+
props: SchemaProps;
|
|
70
|
+
}>;
|
|
71
|
+
export type SchemaObjectOneWay = Prop<{
|
|
72
|
+
type?: 'object';
|
|
73
|
+
props: SchemaPropsOneWay;
|
|
74
|
+
}>;
|
|
75
|
+
export type SchemaReferenceWithQuery = SchemaReferenceOneWay & {
|
|
76
|
+
query: QueryFn;
|
|
148
77
|
};
|
|
149
|
-
export type
|
|
150
|
-
|
|
151
|
-
isRequired?: boolean;
|
|
152
|
-
$ref: string;
|
|
153
|
-
});
|
|
154
|
-
export type BasedSchemaType = {
|
|
155
|
-
fields: {
|
|
156
|
-
[name: string]: BasedSchemaField;
|
|
157
|
-
};
|
|
158
|
-
title?: string;
|
|
159
|
-
description?: string;
|
|
160
|
-
prefix?: BasedSchemaTypePrefix;
|
|
161
|
-
examples?: any[];
|
|
162
|
-
required?: string[];
|
|
163
|
-
$defs?: {
|
|
164
|
-
[key: string]: BasedSchemaField;
|
|
165
|
-
};
|
|
166
|
-
$delete?: boolean;
|
|
78
|
+
export type SchemaReferencesWithQuery = SchemaReferencesOneWay & {
|
|
79
|
+
query: QueryFn;
|
|
167
80
|
};
|
|
168
|
-
export type
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
};
|
|
176
|
-
types: {
|
|
177
|
-
[type: string]: BasedSchemaType;
|
|
178
|
-
};
|
|
179
|
-
prefixToTypeMapping: {
|
|
180
|
-
[prefix: string]: string;
|
|
181
|
-
};
|
|
182
|
-
};
|
|
183
|
-
export type BasedSchemaTypePartial = PartialDeep<BasedSchemaType>;
|
|
184
|
-
export type BasedSchemaFieldPartial = PartialDeep<BasedSchemaField>;
|
|
185
|
-
export type BasedSchemaPartial = PartialDeep<BasedSchema>;
|
|
186
|
-
export type BasedSetTarget = {
|
|
187
|
-
type: string;
|
|
188
|
-
$alias?: string;
|
|
189
|
-
$id?: string;
|
|
190
|
-
schema: BasedSchema;
|
|
191
|
-
$merge?: boolean;
|
|
192
|
-
$language?: BasedSchemaLanguage;
|
|
193
|
-
required: (number | string)[][];
|
|
194
|
-
collected: BasedSchemaCollectProps[];
|
|
195
|
-
errors: {
|
|
196
|
-
code: ParseError;
|
|
197
|
-
path: Path;
|
|
198
|
-
}[];
|
|
81
|
+
export type SchemaEnum = Prop<{
|
|
82
|
+
type?: 'enum';
|
|
83
|
+
default?: EnumItem;
|
|
84
|
+
enum: EnumItem[];
|
|
85
|
+
}>;
|
|
86
|
+
export type SchemaAlias = SchemaString & {
|
|
87
|
+
type: 'alias';
|
|
199
88
|
};
|
|
200
|
-
export type
|
|
201
|
-
|
|
202
|
-
|
|
89
|
+
export type SchemaPropShorthand = 'timestamp' | 'boolean' | 'string' | 'alias' | 'text' | NumberType | EnumItem[];
|
|
90
|
+
type SetItems = SchemaPropShorthand | SchemaTimestamp | SchemaBoolean | SchemaNumber | SchemaString | SchemaEnum;
|
|
91
|
+
export type SchemaSet<ItemsType extends SetItems = SetItems> = Prop<{
|
|
92
|
+
type?: 'set';
|
|
93
|
+
default?: ItemsType extends {
|
|
94
|
+
default: any;
|
|
95
|
+
} ? ItemsType['default'][] : undefined;
|
|
96
|
+
items: ItemsType;
|
|
97
|
+
}>;
|
|
98
|
+
type NonRefSchemaProps = SchemaPropShorthand | SchemaTimestamp | SchemaBoolean | SchemaNumber | SchemaString | SchemaAlias | SchemaText | SchemaEnum | SchemaSet;
|
|
99
|
+
export type SchemaProp = SchemaReferencesWithQuery | SchemaReferenceWithQuery | NonRefSchemaProps | SchemaReferences | SchemaReference | SchemaObject | SchemaBinary;
|
|
100
|
+
export type SchemaPropOneWay = SchemaReferencesOneWay | SchemaReferenceOneWay | SchemaObjectOneWay | NonRefSchemaProps;
|
|
101
|
+
export type SchemaAnyProp = SchemaPropOneWay | SchemaProp;
|
|
102
|
+
export type SchemaHook = string | Function;
|
|
103
|
+
export type SchemaProps = Record<string, SchemaProp>;
|
|
104
|
+
export type SchemaType = {
|
|
105
|
+
hooks?: {
|
|
106
|
+
create?: SchemaHook;
|
|
107
|
+
update?: SchemaHook;
|
|
108
|
+
delete?: SchemaHook;
|
|
203
109
|
};
|
|
110
|
+
id?: number;
|
|
111
|
+
props: SchemaProps;
|
|
112
|
+
};
|
|
113
|
+
export type SchemaTypes = Record<string, SchemaType>;
|
|
114
|
+
export type SchemaPropsOneWay = Record<`${Letter}${string}`, SchemaPropOneWay>;
|
|
115
|
+
export type Schema = {
|
|
116
|
+
types?: SchemaTypes;
|
|
117
|
+
props?: SchemaPropsOneWay;
|
|
118
|
+
locales?: SchemaLocales;
|
|
204
119
|
};
|
|
120
|
+
export type SchemaLocales = Record<string, {
|
|
121
|
+
required?: boolean;
|
|
122
|
+
fallback?: string[];
|
|
123
|
+
}>;
|
|
124
|
+
export type SchemaPropTypeMap = {
|
|
125
|
+
references: SchemaReferences;
|
|
126
|
+
timestamp: SchemaTimestamp;
|
|
127
|
+
reference: SchemaReference;
|
|
128
|
+
boolean: SchemaBoolean;
|
|
129
|
+
string: SchemaString;
|
|
130
|
+
object: SchemaObject;
|
|
131
|
+
alias: SchemaAlias;
|
|
132
|
+
enum: SchemaEnum;
|
|
133
|
+
text: SchemaText;
|
|
134
|
+
set: SchemaSet;
|
|
135
|
+
binary: SchemaBinary;
|
|
136
|
+
} & Record<NumberType, SchemaNumber>;
|
|
137
|
+
export type SchemaPropTypes = keyof SchemaPropTypeMap;
|
|
138
|
+
export declare const isPropType: <T extends "string" | "boolean" | "object" | "references" | "timestamp" | "alias" | "text" | NumberType | "binary" | "reference" | "enum" | "set">(type: T, prop: SchemaProp) => prop is SchemaPropTypeMap[T];
|
|
205
139
|
export {};
|
|
140
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.js
CHANGED
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const languages_1 = require("./languages");
|
|
5
|
-
exports.basedSchemaFieldTypes = [
|
|
6
|
-
'array',
|
|
7
|
-
'object',
|
|
8
|
-
'record',
|
|
9
|
-
'set',
|
|
10
|
-
'string',
|
|
11
|
-
'boolean',
|
|
12
|
-
'number',
|
|
13
|
-
'json',
|
|
14
|
-
'integer',
|
|
15
|
-
'timestamp',
|
|
16
|
-
'reference',
|
|
17
|
-
'references',
|
|
18
|
-
'text',
|
|
19
|
-
'enum',
|
|
20
|
-
'cardinality',
|
|
21
|
-
];
|
|
22
|
-
const isCollection = (type) => {
|
|
23
|
-
return type === 'array' || type === 'object' || type === 'record';
|
|
1
|
+
import { getPropType } from './parse/utils.js';
|
|
2
|
+
export const isPropType = (type, prop) => {
|
|
3
|
+
return getPropType(prop) === type;
|
|
24
4
|
};
|
|
25
|
-
exports.isCollection = isCollection;
|
|
26
|
-
exports.languages = Object.keys(languages_1.languages);
|
|
27
5
|
//# sourceMappingURL=types.js.map
|
package/package.json
CHANGED
|
@@ -1,41 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@based/schema",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"main": "dist/
|
|
5
|
+
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
8
8
|
"README.md",
|
|
9
9
|
"package.json",
|
|
10
|
-
"!dist/**/*.
|
|
10
|
+
"!dist/**/*.map"
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
|
-
"build": "
|
|
14
|
-
"watch": "
|
|
15
|
-
"
|
|
16
|
-
"test": "ava --color --timeout 3m --verbose",
|
|
17
|
-
"test-ci": "ava --color --concurrency 1 --timeout 3m"
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"watch": "tsc --watch",
|
|
15
|
+
"test": "tsc && tsc test/*.ts --noEmit && tsx --test test/*.ts"
|
|
18
16
|
},
|
|
17
|
+
"prettier": "@saulx/prettier-config",
|
|
19
18
|
"sideEffects": false,
|
|
20
19
|
"type": "module",
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"validator": "^13.9.0",
|
|
23
|
-
"@saulx/hash": "^2.0.0",
|
|
24
|
-
"@saulx/utils": "^3.5.0"
|
|
25
|
-
},
|
|
26
|
-
"ava": {
|
|
27
|
-
"timeout": "2m",
|
|
28
|
-
"files": [
|
|
29
|
-
"./dist/test/*.js",
|
|
30
|
-
"./dist/test/validateSchema/*.js"
|
|
31
|
-
]
|
|
32
|
-
},
|
|
33
20
|
"devDependencies": {
|
|
34
|
-
"
|
|
21
|
+
"@saulx/prettier-config": "2.0.0",
|
|
35
22
|
"@saulx/tsconfig": "^1.1.0",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
23
|
+
"@types/node": "22.5.3",
|
|
24
|
+
"tsx": "^4.19.0",
|
|
25
|
+
"typescript": "^5.1.6"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"picocolors": "^1.1.0"
|
|
40
29
|
}
|
|
41
30
|
}
|
package/README.md
DELETED
package/dist/display/index.d.ts
DELETED
package/dist/display/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.display = void 0;
|
|
7
|
-
const timestamp_1 = __importDefault(require("./timestamp"));
|
|
8
|
-
const number_1 = __importDefault(require("./number"));
|
|
9
|
-
const string_1 = __importDefault(require("./string"));
|
|
10
|
-
const display = (value, field) => {
|
|
11
|
-
if (field.type === 'timestamp' && typeof value === 'number') {
|
|
12
|
-
// @ts-ignore
|
|
13
|
-
return (0, timestamp_1.default)(value, field.display);
|
|
14
|
-
}
|
|
15
|
-
if (field.type === 'number' && typeof value === 'number') {
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
return (0, number_1.default)(value, field.display);
|
|
18
|
-
}
|
|
19
|
-
if (field.type === 'string' && typeof value === 'string') {
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
return (0, string_1.default)(value, field.display);
|
|
22
|
-
}
|
|
23
|
-
return value;
|
|
24
|
-
};
|
|
25
|
-
exports.display = display;
|
|
26
|
-
//# sourceMappingURL=index.js.map
|
package/dist/display/number.d.ts
DELETED