@fougere/schema 0.19.1-alpha.0 → 0.20.1-alpha.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/field/Word.d.ts +31 -0
- package/dist/field/Word.d.ts.map +1 -0
- package/dist/field/Word.js +50 -0
- package/dist/field/Word.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/vocabulary/preset/created.d.ts.map +1 -1
- package/dist/vocabulary/preset/created.js +3 -0
- package/dist/vocabulary/preset/created.js.map +1 -1
- package/dist/vocabulary/preset/updated.d.ts.map +1 -1
- package/dist/vocabulary/preset/updated.js +3 -0
- package/dist/vocabulary/preset/updated.js.map +1 -1
- package/dist/vocabulary/primitive/bool.d.ts +1 -2
- package/dist/vocabulary/primitive/bool.d.ts.map +1 -1
- package/dist/vocabulary/primitive/bool.js +2 -4
- package/dist/vocabulary/primitive/bool.js.map +1 -1
- package/dist/vocabulary/primitive/date.d.ts +1 -2
- package/dist/vocabulary/primitive/date.d.ts.map +1 -1
- package/dist/vocabulary/primitive/date.js +2 -4
- package/dist/vocabulary/primitive/date.js.map +1 -1
- package/dist/vocabulary/primitive/json.d.ts.map +1 -1
- package/dist/vocabulary/primitive/json.js +3 -0
- package/dist/vocabulary/primitive/json.js.map +1 -1
- package/dist/vocabulary/primitive/list.d.ts +8 -4
- package/dist/vocabulary/primitive/list.d.ts.map +1 -1
- package/dist/vocabulary/primitive/list.js +5 -0
- package/dist/vocabulary/primitive/list.js.map +1 -1
- package/dist/vocabulary/primitive/many.d.ts.map +1 -1
- package/dist/vocabulary/primitive/many.js +3 -0
- package/dist/vocabulary/primitive/many.js.map +1 -1
- package/dist/vocabulary/primitive/number.d.ts +8 -7
- package/dist/vocabulary/primitive/number.d.ts.map +1 -1
- package/dist/vocabulary/primitive/number.js +8 -10
- package/dist/vocabulary/primitive/number.js.map +1 -1
- package/dist/vocabulary/primitive/oneOf.d.ts.map +1 -1
- package/dist/vocabulary/primitive/oneOf.js +3 -0
- package/dist/vocabulary/primitive/oneOf.js.map +1 -1
- package/dist/vocabulary/primitive/primary.d.ts +6 -3
- package/dist/vocabulary/primitive/primary.d.ts.map +1 -1
- package/dist/vocabulary/primitive/primary.js +5 -0
- package/dist/vocabulary/primitive/primary.js.map +1 -1
- package/dist/vocabulary/primitive/ref.d.ts +7 -4
- package/dist/vocabulary/primitive/ref.d.ts.map +1 -1
- package/dist/vocabulary/primitive/ref.js +6 -1
- package/dist/vocabulary/primitive/ref.js.map +1 -1
- package/dist/vocabulary/primitive/text.d.ts +10 -9
- package/dist/vocabulary/primitive/text.d.ts.map +1 -1
- package/dist/vocabulary/primitive/text.js +9 -12
- package/dist/vocabulary/primitive/text.js.map +1 -1
- package/package.json +1 -1
- package/src/field/Word.ts +71 -0
- package/src/index.ts +1 -1
- package/src/vocabulary/preset/created.ts +5 -0
- package/src/vocabulary/preset/updated.ts +5 -0
- package/src/vocabulary/primitive/bool.ts +2 -4
- package/src/vocabulary/primitive/date.ts +2 -6
- package/src/vocabulary/primitive/json.ts +4 -0
- package/src/vocabulary/primitive/list.ts +7 -4
- package/src/vocabulary/primitive/many.ts +5 -0
- package/src/vocabulary/primitive/number.ts +9 -15
- package/src/vocabulary/primitive/oneOf.ts +5 -0
- package/src/vocabulary/primitive/primary.ts +7 -3
- package/src/vocabulary/primitive/ref.ts +9 -4
- package/src/vocabulary/primitive/text.ts +11 -19
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Shape } from '../axis/shape/Shape.js';
|
|
2
|
+
import { Format, type Accepted } from '../lib/Format.js';
|
|
3
|
+
import { Field, type Shared } from './Field.js';
|
|
4
|
+
/** One option of a word: the JSON Schema keyword it writes, the format of its value, and how it writes it. */
|
|
5
|
+
export type WordOption = readonly [keyword: string, format: Format<any>, write?: (value: any) => unknown];
|
|
6
|
+
/** What a word admits, read off its table — the type is never written beside it. */
|
|
7
|
+
export type OptionsOf<Table extends Record<string, WordOption>> = {
|
|
8
|
+
[K in keyof Table]?: Accepted<Table[K][1]>;
|
|
9
|
+
};
|
|
10
|
+
/** The same, for a word whose keys write no keyword — read off the formats of its keys. */
|
|
11
|
+
export type OptionsIn<Keys extends Record<string, Format<any>>> = {
|
|
12
|
+
[K in keyof Keys]?: Accepted<Keys[K]>;
|
|
13
|
+
};
|
|
14
|
+
/** What a word that shapes no value admits — a relation, a stamp: the sentence and nothing else. */
|
|
15
|
+
export declare const DESCRIBED: {
|
|
16
|
+
readonly description: Format<string>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The keys a word admits, as a closed format — so an option it does not know is refused under its
|
|
20
|
+
* own name, where reading only the keys it knew used to drop `minn` without a word.
|
|
21
|
+
*/
|
|
22
|
+
export declare function admits(word: string, keys: Record<string, Format<unknown>>, shared?: Record<string, Format<unknown>>): Format<unknown>;
|
|
23
|
+
/** Judge a word's options by the format of its keys — `text(42)` and `text({ minn: 1 })` alike. */
|
|
24
|
+
export declare function judgeOptions(word: string, format: Format<unknown>, opts: unknown): void;
|
|
25
|
+
/**
|
|
26
|
+
* A word, declared as a table: its base shape, and each option with the keyword it writes. The
|
|
27
|
+
* closed format, the options type and the shape all derive from that one table.
|
|
28
|
+
* `word<string>()('text', { type: 'string' }, { max: ['maxLength', Format.count] })`
|
|
29
|
+
*/
|
|
30
|
+
export declare function word<T>(): <Table extends Record<string, WordOption>>(name: string, base: Shape, table: Table) => (opts?: OptionsOf<Table> & Shared<T>) => Field<T>;
|
|
31
|
+
//# sourceMappingURL=Word.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Word.d.ts","sourceRoot":"","sources":["../../src/field/Word.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAMzD,OAAO,EAAE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C,QAAQ,MAAM,QAAQ,KAAK,SAAS,KAAK,aAGxE,SAAS,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,KAAG,KAAK,CAAC,CAAC,CAAC,CAczD"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Format } from '../lib/Format.js';
|
|
2
|
+
import { dotted } from '../lib/ValidationResult.js';
|
|
3
|
+
import { isObject } from '../lib/utils.js';
|
|
4
|
+
import { JsonSchemaValidator } from '../validator/JsonSchemaValidator.js';
|
|
5
|
+
import { SchemaError } from '../SchemaError.js';
|
|
6
|
+
import { Field } from './Field.js';
|
|
7
|
+
/** The two keys every shaping word admits: the sentence it carries, and the value it is born with. */
|
|
8
|
+
const SHARED = { description: Format.text, default: Format.anything };
|
|
9
|
+
/** What a word that shapes no value admits — a relation, a stamp: the sentence and nothing else. */
|
|
10
|
+
export const DESCRIBED = { description: Format.text };
|
|
11
|
+
/**
|
|
12
|
+
* The keys a word admits, as a closed format — so an option it does not know is refused under its
|
|
13
|
+
* own name, where reading only the keys it knew used to drop `minn` without a word.
|
|
14
|
+
*/
|
|
15
|
+
export function admits(word, keys, shared = SHARED) {
|
|
16
|
+
return Object.entries({ ...shared, ...keys })
|
|
17
|
+
.reduce((held, [name, format]) => held.key(name, format), Format.of(`vocabulary/${word}`))
|
|
18
|
+
.closed();
|
|
19
|
+
}
|
|
20
|
+
/** Judge a word's options by the format of its keys — `text(42)` and `text({ minn: 1 })` alike. */
|
|
21
|
+
export function judgeOptions(word, format, opts) {
|
|
22
|
+
if (opts === undefined)
|
|
23
|
+
return;
|
|
24
|
+
if (!isObject(opts))
|
|
25
|
+
throw new SchemaError('Options must go in an object, like { max: 200 }', { received: opts });
|
|
26
|
+
const refusal = JsonSchemaValidator.of(format.schema).refusalOf(opts, [`${word}()`]);
|
|
27
|
+
if (refusal)
|
|
28
|
+
throw new SchemaError(`${dotted(refusal.path)}: ${refusal.message}`);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A word, declared as a table: its base shape, and each option with the keyword it writes. The
|
|
32
|
+
* closed format, the options type and the shape all derive from that one table.
|
|
33
|
+
* `word<string>()('text', { type: 'string' }, { max: ['maxLength', Format.count] })`
|
|
34
|
+
*/
|
|
35
|
+
export function word() {
|
|
36
|
+
return (name, base, table) => {
|
|
37
|
+
const format = admits(name, Object.fromEntries(Object.entries(table).map(([key, [, value]]) => [key, value])));
|
|
38
|
+
return (opts) => {
|
|
39
|
+
judgeOptions(name, format, opts);
|
|
40
|
+
const written = Object.entries(table)
|
|
41
|
+
.filter(([key]) => opts?.[key] !== undefined)
|
|
42
|
+
.map(([key, [keyword, , write]]) => {
|
|
43
|
+
const value = opts[key];
|
|
44
|
+
return [keyword, write ? write(value) : value];
|
|
45
|
+
});
|
|
46
|
+
return new Field({ shape: { ...base, ...Object.fromEntries(written) } }).setShared(opts);
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=Word.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Word.js","sourceRoot":"","sources":["../../src/field/Word.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAiB,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAe,MAAM,YAAY,CAAC;AAWhD,sGAAsG;AACtG,MAAM,MAAM,GAAG,EAAE,WAAW,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,QAAQ,EAAW,CAAC;AAE/E,oGAAoG;AACpG,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,WAAW,EAAE,MAAM,CAA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K,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAE/G,OAAO,CAAC,IAAmC,EAAY,EAAE;YACvD,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;YAEjC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;iBAClC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,GAAwB,CAAC,KAAK,SAAS,CAAC;iBACjE,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,AAAD,EAAG,KAAK,CAAC,CAAC,EAAE,EAAE;gBACjC,MAAM,KAAK,GAAG,IAAK,CAAC,GAAwB,CAAC,CAAC;gBAE9C,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAU,CAAC;YAC1D,CAAC,CAAC,CAAC;YAEL,OAAO,IAAI,KAAK,CAAI,EAAE,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,EAAW,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACvG,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -43,6 +43,6 @@ export { FieldValueValidator } from './validator/FieldValueValidator.js';
|
|
|
43
43
|
export { JsonSchemaValidator } from './validator/JsonSchemaValidator.js';
|
|
44
44
|
export type { JsonSchema } from './lib/JsonSchema.js';
|
|
45
45
|
export { Axes } from './axis/Axes.js';
|
|
46
|
-
export { Format } from './lib/Format.js';
|
|
46
|
+
export { Format, type Accepted } from './lib/Format.js';
|
|
47
47
|
export type { Axis } from './axis/Axis.js';
|
|
48
48
|
//# sourceMappingURL=index.d.ts.map
|
package/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AC;AAE1E,OAAO,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAU9C,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAGxD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"created.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/preset/created.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"created.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/preset/created.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAM7D,wBAAgB,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,CAMrD"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { date } from '../primitive/date.js';
|
|
2
|
+
import { DESCRIBED, admits, judgeOptions } from '../../field/Word.js';
|
|
3
|
+
const ADMITS = admits('created', {}, DESCRIBED);
|
|
2
4
|
export function created(opts) {
|
|
5
|
+
judgeOptions('created', ADMITS, opts);
|
|
3
6
|
return date(opts).with({
|
|
4
7
|
lifecycle: { create: 'now', update: 'forbidden' },
|
|
5
8
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"created.js","sourceRoot":"","sources":["../../../src/vocabulary/preset/created.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"created.js","sourceRoot":"","sources":["../../../src/vocabulary/preset/created.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEtE,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;AAEhD,MAAM,UAAU,OAAO,CAAC,IAAgB;IACtC,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAEtC,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;QACrB,SAAS,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE;KAClD,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updated.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/preset/updated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"updated.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/preset/updated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAM7D,wBAAgB,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,CAMrD"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { created } from './created.js';
|
|
2
|
+
import { DESCRIBED, admits, judgeOptions } from '../../field/Word.js';
|
|
3
|
+
const ADMITS = admits('updated', {}, DESCRIBED);
|
|
2
4
|
export function updated(opts) {
|
|
5
|
+
judgeOptions('updated', ADMITS, opts);
|
|
3
6
|
const base = created(opts);
|
|
4
7
|
return base.with({ lifecycle: { ...base.lifecycle, update: 'now' } });
|
|
5
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updated.js","sourceRoot":"","sources":["../../../src/vocabulary/preset/updated.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"updated.js","sourceRoot":"","sources":["../../../src/vocabulary/preset/updated.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEtE,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;AAEhD,MAAM,UAAU,OAAO,CAAC,IAAgB;IACtC,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAEtC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3B,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;AACxE,CAAC"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function bool(opts?: Shared<boolean>): Field<boolean>;
|
|
1
|
+
export declare const bool: (opts?: (import("../../field/Word.js").OptionsOf<{}> & import("../../field/Field.js").Shared<boolean>) | undefined) => import("../../index.js").Field<boolean>;
|
|
3
2
|
//# sourceMappingURL=bool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bool.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/bool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bool.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/bool.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,gKAAmD,CAAC"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
return new Field({ shape: { type: 'boolean' } }).setShared(opts);
|
|
4
|
-
}
|
|
1
|
+
import { word } from '../../field/Word.js';
|
|
2
|
+
export const bool = word()('bool', { type: 'boolean' }, {});
|
|
5
3
|
//# sourceMappingURL=bool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bool.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/bool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"bool.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/bool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,EAAW,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Field, type Shared } from '../../field/Field.js';
|
|
2
1
|
/**
|
|
3
2
|
* A `Date` in a handler, an ISO string on the wire — the `isoDate` boundary converts.
|
|
4
3
|
* `date()` → `{ type: 'string', format: 'date-time' }`
|
|
5
4
|
*/
|
|
6
|
-
export declare
|
|
5
|
+
export declare const date: (opts?: (import("../../field/Word.js").OptionsOf<{}> & import("../../field/Field.js").Shared<Date>) | undefined) => import("../../index.js").Field<Date>;
|
|
7
6
|
//# sourceMappingURL=date.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/date.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/date.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,IAAI,0JAAoE,CAAC"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { word } from '../../field/Word.js';
|
|
2
2
|
/**
|
|
3
3
|
* A `Date` in a handler, an ISO string on the wire — the `isoDate` boundary converts.
|
|
4
4
|
* `date()` → `{ type: 'string', format: 'date-time' }`
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
7
|
-
return new Field({ shape: { type: 'string', format: 'date-time' } }).setShared(opts);
|
|
8
|
-
}
|
|
6
|
+
export const date = word()('date', { type: 'string', format: 'date-time' }, {});
|
|
9
7
|
//# sourceMappingURL=date.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/date.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/date.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,EAAQ,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAQrD,wBAAgB,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;AAC9D,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,EACnC,EAAE,EAAE,CAAC,EACL,IAAI,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAC7B,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Field } from '../../field/Field.js';
|
|
2
2
|
import { InputValidator } from '../../validator/InputValidator.js';
|
|
3
3
|
import { SchemaError } from '../../SchemaError.js';
|
|
4
|
+
import { admits, judgeOptions } from '../../field/Word.js';
|
|
5
|
+
const ADMITS = admits('json', {});
|
|
4
6
|
/**
|
|
5
7
|
* `json(Address)` → the entity's properties, and its required keys
|
|
6
8
|
*/
|
|
7
9
|
export function json(of, opts) {
|
|
8
10
|
const [schema, shared] = typeof of === 'function' ? [of, opts] : [undefined, of];
|
|
11
|
+
judgeOptions('json', ADMITS, shared);
|
|
9
12
|
if (schema && typeof schema.getFields !== 'function')
|
|
10
13
|
throw new SchemaError('json() takes an entity, such as json(Address) — got a function that is not one');
|
|
11
14
|
if (!schema)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EA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AQ,GAAa,EAAE,CAAC;IAE9B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,UAAU,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;QAE9B,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,IAAI,KAAK,CAAC;QACf,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;KAChF,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Field, type Shared } from '../../field/Field.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { Format } from '../../lib/Format.js';
|
|
3
|
+
import { type OptionsIn } from '../../field/Word.js';
|
|
4
|
+
declare const KEYS: {
|
|
5
|
+
min: Format<number>;
|
|
6
|
+
max: Format<number>;
|
|
7
|
+
};
|
|
8
|
+
export type ListOptions<T = unknown> = OptionsIn<typeof KEYS> & Shared<T[]>;
|
|
6
9
|
/**
|
|
7
10
|
* A list of values. It keeps the shape of the item and nothing else: `nullable()` and a
|
|
8
11
|
* `description` write in the shape, so they work. A rule writes beside it, and an item of a
|
|
@@ -10,4 +13,5 @@ export interface ListOptions<T = unknown> extends Shared<T[]> {
|
|
|
10
13
|
* `list(text(), { max: 5 })` → `{ type: 'array', items: { type: 'string' }, maxItems: 5 }`
|
|
11
14
|
*/
|
|
12
15
|
export declare function list<T>(field: Field<T>, opts?: ListOptions<T>): Field<T[]>;
|
|
16
|
+
export {};
|
|
13
17
|
//# sourceMappingURL=list.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAE3E,QAAA,MAAM,IAAI;IAAK,GAAG;IAAgB,GAAG;CAAgB,CAAC;AAGtD,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,OAAO,IAAI,SAAS,CAAC,OAAO,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;AAE5E;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAe1E"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Field } from '../../field/Field.js';
|
|
2
2
|
import { SchemaError } from '../../SchemaError.js';
|
|
3
|
+
import { Format } from '../../lib/Format.js';
|
|
4
|
+
import { admits, judgeOptions } from '../../field/Word.js';
|
|
5
|
+
const KEYS = { min: Format.count, max: Format.count };
|
|
6
|
+
const ADMITS = admits('list', KEYS);
|
|
3
7
|
/**
|
|
4
8
|
* A list of values. It keeps the shape of the item and nothing else: `nullable()` and a
|
|
5
9
|
* `description` write in the shape, so they work. A rule writes beside it, and an item of a
|
|
@@ -7,6 +11,7 @@ import { SchemaError } from '../../SchemaError.js';
|
|
|
7
11
|
* `list(text(), { max: 5 })` → `{ type: 'array', items: { type: 'string' }, maxItems: 5 }`
|
|
8
12
|
*/
|
|
9
13
|
export function list(field, opts) {
|
|
14
|
+
judgeOptions('list', ADMITS, opts);
|
|
10
15
|
if (field.hasAxes())
|
|
11
16
|
throw new SchemaError('list() takes a value, not a rule. Put the rule on the list: unique(list(text())).');
|
|
12
17
|
return new Field({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAe,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAe,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAkB,MAAM,qBAAqB,CAAC;AAE3E,MAAM,IAAI,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;AACtD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAIpC;;;;;GAKG;AACH,MAAM,UAAU,IAAI,CAAI,KAAe,EAAE,IAAqB;IAC5D,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACnC,IAAI,KAAK,CAAC,OAAO,EAAE;QACjB,MAAM,IAAI,WAAW,CACnB,mFAAmF,CACpF,CAAC;IAEJ,OAAO,IAAI,KAAK,CAAM;QACpB,KAAK,EAAE;YACL,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,QAAQ,EAAE,IAAI,EAAE,GAAG;YACnB,QAAQ,EAAE,IAAI,EAAE,GAAG;SACpB;KACF,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"many.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/many.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"many.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/many.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAK7D;;GAEG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,EACnC,MAAM,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EACrB,IAAI,CAAC,EAAE,SAAS,GACf,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAO1B"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Relation } from '../../axis/role/Relation.js';
|
|
2
2
|
import { Field } from '../../field/Field.js';
|
|
3
|
+
import { DESCRIBED, admits, judgeOptions } from '../../field/Word.js';
|
|
4
|
+
const ADMITS = admits('many', {}, DESCRIBED);
|
|
3
5
|
/**
|
|
4
6
|
* `many(() => Post)` → `{ type: 'array' }` with `role.relation.kind` `'many'`
|
|
5
7
|
*/
|
|
6
8
|
export function many(target, opts) {
|
|
9
|
+
judgeOptions('many', ADMITS, opts);
|
|
7
10
|
return new Field({
|
|
8
11
|
shape: { type: 'array' },
|
|
9
12
|
role: { relation: Relation.many(target) },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"many.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/many.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,KAAK,EAAkB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"many.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/many.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,KAAK,EAAkB,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEtE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;AAE7C;;GAEG;AACH,MAAM,UAAU,IAAI,CAClB,MAAqB,EACrB,IAAgB;IAEhB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAEnC,OAAO,IAAI,KAAK,CAAoB;QAClC,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;QACxB,IAAI,EAAE,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;KAC1C,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { Format } from '../../lib/Format.js';
|
|
2
|
+
/** `number({ integer: true, min: 1 })` → `{ type: 'integer', minimum: 1 }` */
|
|
3
|
+
export declare const number: (opts?: (import("../../field/Word.js").OptionsOf<{
|
|
4
|
+
min: [string, Format<number>];
|
|
5
|
+
max: [string, Format<number>];
|
|
6
|
+
integer: [string, Format<boolean>, (integer: boolean) => "integer" | "number"];
|
|
7
|
+
}> & import("../../field/Field.js").Shared<number>) | undefined) => import("../../index.js").Field<number>;
|
|
8
|
+
export type NumberOptions = NonNullable<Parameters<typeof number>[0]>;
|
|
8
9
|
//# sourceMappingURL=number.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/number.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/number.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,8EAA8E;AAC9E,eAAO,MAAM,MAAM;;;iDAGwB,OAAO;0GAChD,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}).setShared(opts);
|
|
10
|
-
}
|
|
1
|
+
import { Format } from '../../lib/Format.js';
|
|
2
|
+
import { word } from '../../field/Word.js';
|
|
3
|
+
/** `number({ integer: true, min: 1 })` → `{ type: 'integer', minimum: 1 }` */
|
|
4
|
+
export const number = word()('number', { type: 'number' }, {
|
|
5
|
+
min: ['minimum', Format.number],
|
|
6
|
+
max: ['maximum', Format.number],
|
|
7
|
+
integer: ['type', Format.flag, (integer) => (integer ? 'integer' : 'number')],
|
|
8
|
+
});
|
|
11
9
|
//# sourceMappingURL=number.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/number.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/number.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C,8EAA8E;AAC9E,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,EAAU,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;IACjE,GAAG,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC;IAC/B,GAAG,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC;IAC/B,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,OAAgB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;CACvF,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oneOf.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/oneOf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"oneOf.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/oneOf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAQ1D,KAAK,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;AAE9E,wBAAgB,KAAK,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAEnF,wBAAgB,KAAK,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAC1C,GAAG,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GACjC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Field } from '../../field/Field.js';
|
|
2
2
|
import { isArrayOf, isObject } from '../../lib/utils.js';
|
|
3
3
|
import { SchemaError } from '../../SchemaError.js';
|
|
4
|
+
import { admits, judgeOptions } from '../../field/Word.js';
|
|
5
|
+
const ADMITS = admits('oneOf', {});
|
|
4
6
|
/**
|
|
5
7
|
* `oneOf('draft', 'published', { default: 'draft' })` → `{ type: 'string', enum: [...] }`
|
|
6
8
|
*/
|
|
@@ -21,6 +23,7 @@ export function oneOf(...args) {
|
|
|
21
23
|
};
|
|
22
24
|
if (shape === undefined)
|
|
23
25
|
throw new SchemaError('oneOf() takes strings or numbers, then an optional object of options', { received: given });
|
|
26
|
+
judgeOptions('oneOf', ADMITS, opts);
|
|
24
27
|
return new Field({ shape }).setShared(opts);
|
|
25
28
|
}
|
|
26
29
|
//# sourceMappingURL=oneOf.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oneOf.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/oneOf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAe,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"oneOf.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/oneOf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAe,MAAM,sBAAsB,CAA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;YAC3D,IAAI,EAAE,MAAM;SACb,CAAC;IAEJ,IAAI,KAAK,KAAK,SAAS;QACrB,MAAM,IAAI,WAAW,CACnB,sEAAsE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAC5F,CAAC;IAEJ,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAEpC,OAAO,IAAI,KAAK,CAAY,EAAE,KAAK,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Field, type Described } from '../../field/Field.js';
|
|
2
2
|
import { type GeneratorRef } from '../../axis/lifecycle/Generators.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { Format } from '../../lib/Format.js';
|
|
4
|
+
import { type OptionsIn } from '../../field/Word.js';
|
|
5
|
+
declare const KEYS: {
|
|
6
|
+
generate: Format<[name: string, fn: () => string] | GeneratorRef>;
|
|
7
|
+
};
|
|
8
|
+
type PrimaryOptions = OptionsIn<typeof KEYS> & Described;
|
|
6
9
|
export declare function primary(opts?: PrimaryOptions): Field<string>;
|
|
7
10
|
export declare function primary<T>(field: Field<T>): Field<T>;
|
|
8
11
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primary.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/primary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"primary.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/primary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAmC,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEtF,QAAA,MAAM,IAAI;IAAK,QAAQ,kCAA6D,MAAM;CAAM,CAAC;AAGjG,KAAK,cAAc,GAAG,SAAS,CAAC,OAAO,IAAI,CAAC,GAAG,SAAS,CAAC;AAEzD,wBAAgB,OAAO,CAAC,IAAI,CAAC,EAAE,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;AAC9D,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Field } from '../../field/Field.js';
|
|
2
2
|
import { Generators } from '../../axis/lifecycle/Generators.js';
|
|
3
|
+
import { Format } from '../../lib/Format.js';
|
|
4
|
+
import { DESCRIBED, admits, judgeOptions } from '../../field/Word.js';
|
|
5
|
+
const KEYS = { generate: Format.anything.as() };
|
|
6
|
+
const ADMITS = admits('primary', KEYS, DESCRIBED);
|
|
3
7
|
/**
|
|
4
8
|
* `primary()` for a generated id; `primary(number())` to make a declared field the key.
|
|
5
9
|
* `primary()` → `create: { generate: 'cuid2' }`, `update: 'forbidden'`
|
|
@@ -13,6 +17,7 @@ export function primary(fieldOrOptions) {
|
|
|
13
17
|
});
|
|
14
18
|
}
|
|
15
19
|
const opts = fieldOrOptions ?? {};
|
|
20
|
+
judgeOptions('primary', ADMITS, fieldOrOptions);
|
|
16
21
|
let generate;
|
|
17
22
|
if (Array.isArray(opts.generate)) {
|
|
18
23
|
const [name, fn] = opts.generate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primary.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/primary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAkB,MAAM,sBAAsB,CAAC;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,IAAI,EAAE,EAAE,CAAC,CAAC;QAE9B,QAAQ,GAAG,IAAI,CAAC;IAClB,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC;IACtC,CAAC;IAED,OAAO,IAAI,KAAK,CAAS;QACvB,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACzB,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;QACvB,SAAS,EAAE,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE;KACzD,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { Entity } from '../../entity/Entity.js';
|
|
2
|
-
import { type OnDelete } from '../../axis/role/Relation.js';
|
|
3
2
|
import { Field, type Shared } from '../../field/Field.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { Format } from '../../lib/Format.js';
|
|
4
|
+
import { type OptionsIn } from '../../field/Word.js';
|
|
5
|
+
declare const KEYS: {
|
|
6
|
+
onDelete: Format<"cascade" | "restrict" | "set null">;
|
|
7
|
+
};
|
|
8
|
+
export type RefOptions = OptionsIn<typeof KEYS> & Shared<string>;
|
|
7
9
|
export declare function ref<E extends Entity>(target: E | (() => E), opts?: RefOptions): Field<string>;
|
|
10
|
+
export {};
|
|
8
11
|
//# sourceMappingURL=ref.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAE3E,QAAA,MAAM,IAAI;IAAK,QAAQ;CAA4B,CAAC;AAGpD,MAAM,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAEjE,wBAAgB,GAAG,CAAC,CAAC,SAAS,MAAM,EAClC,MAAM,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EACrB,IAAI,CAAC,EAAE,UAAU,GAChB,KAAK,CAAC,MAAM,CAAC,CAOf"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { Relation } from '../../axis/role/Relation.js';
|
|
1
|
+
import { ON_DELETE, Relation } from '../../axis/role/Relation.js';
|
|
2
2
|
import { Field } from '../../field/Field.js';
|
|
3
|
+
import { Format } from '../../lib/Format.js';
|
|
4
|
+
import { admits, judgeOptions } from '../../field/Word.js';
|
|
5
|
+
const KEYS = { onDelete: Format.tokens(ON_DELETE) };
|
|
6
|
+
const ADMITS = admits('ref', KEYS);
|
|
3
7
|
export function ref(target, opts) {
|
|
8
|
+
judgeOptions('ref', ADMITS, opts);
|
|
4
9
|
return new Field({
|
|
5
10
|
shape: { type: 'string' },
|
|
6
11
|
role: { relation: Relation.one(target, opts?.onDelete) },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/ref.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/ref.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,KAAK,EAAe,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAkB,MAAM,qBAAqB,CAAC;AAE3E,MAAM,IAAI,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;AACpD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAInC,MAAM,UAAU,GAAG,CACjB,MAAqB,EACrB,IAAiB;IAEjB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAElC,OAAO,IAAI,KAAK,CAAS;QACvB,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACzB,IAAI,EAAE,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE;KACzD,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { Format } from '../../lib/Format.js';
|
|
2
|
+
import type { StringFormat } from '../../axis/shape/StringFormat.js';
|
|
3
|
+
/** `text({ min: 1, max: 160 })` → `{ type: 'string', minLength: 1, maxLength: 160 }` */
|
|
4
|
+
export declare const text: (opts?: (import("../../field/Word.js").OptionsOf<{
|
|
5
|
+
min: [string, Format<number>];
|
|
6
|
+
max: [string, Format<number>];
|
|
7
|
+
pattern: [string, Format<string>];
|
|
8
|
+
format: [string, Format<StringFormat>];
|
|
9
|
+
}> & import("../../field/Field.js").Shared<string>) | undefined) => import("../../index.js").Field<string>;
|
|
10
|
+
export type TextOptions = NonNullable<Parameters<typeof text>[0]>;
|
|
10
11
|
//# sourceMappingURL=text.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/vocabulary/primitive/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAErE,wFAAwF;AACxF,eAAO,MAAM,IAAI;;;;;0GAKf,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
}).setShared(opts);
|
|
12
|
-
}
|
|
1
|
+
import { Format } from '../../lib/Format.js';
|
|
2
|
+
import { word } from '../../field/Word.js';
|
|
3
|
+
/** `text({ min: 1, max: 160 })` → `{ type: 'string', minLength: 1, maxLength: 160 }` */
|
|
4
|
+
export const text = word()('text', { type: 'string' }, {
|
|
5
|
+
min: ['minLength', Format.count],
|
|
6
|
+
max: ['maxLength', Format.count],
|
|
7
|
+
pattern: ['pattern', Format.text],
|
|
8
|
+
format: ['format', Format.text.as()],
|
|
9
|
+
});
|
|
13
10
|
//# sourceMappingURL=text.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/vocabulary/primitive/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAG3C,wFAAwF;AACxF,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,EAAU,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;IAC7D,GAAG,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,KAAK,CAAC;IAChC,GAAG,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,KAAK,CAAC;IAChC,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC;IACjC,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,EAAgB,CAAC;CACnD,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Shape } from '../axis/shape/Shape.js';
|
|
2
|
+
import { Format, type Accepted } from '../lib/Format.js';
|
|
3
|
+
import type { JsonSchema } from '../lib/JsonSchema.js';
|
|
4
|
+
import { dotted } from '../lib/ValidationResult.js';
|
|
5
|
+
import { isObject } from '../lib/utils.js';
|
|
6
|
+
import { JsonSchemaValidator } from '../validator/JsonSchemaValidator.js';
|
|
7
|
+
import { SchemaError } from '../SchemaError.js';
|
|
8
|
+
import { Field, type Shared } from './Field.js';
|
|
9
|
+
|
|
10
|
+
/** One option of a word: the JSON Schema keyword it writes, the format of its value, and how it writes it. */
|
|
11
|
+
export type WordOption = readonly [keyword: string, format: Format<any>, write?: (value: any) => unknown];
|
|
12
|
+
|
|
13
|
+
/** What a word admits, read off its table — the type is never written beside it. */
|
|
14
|
+
export type OptionsOf<Table extends Record<string, WordOption>> = { [K in keyof Table]?: Accepted<Table[K][1]> };
|
|
15
|
+
|
|
16
|
+
/** The same, for a word whose keys write no keyword — read off the formats of its keys. */
|
|
17
|
+
export type OptionsIn<Keys extends Record<string, Format<any>>> = { [K in keyof Keys]?: Accepted<Keys[K]> };
|
|
18
|
+
|
|
19
|
+
/** The two keys every shaping word admits: the sentence it carries, and the value it is born with. */
|
|
20
|
+
const SHARED = { description: Format.text, default: Format.anything } as const;
|
|
21
|
+
|
|
22
|
+
/** What a word that shapes no value admits — a relation, a stamp: the sentence and nothing else. */
|
|
23
|
+
export const DESCRIBED = { description: Format.text } as const;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The keys a word admits, as a closed format — so an option it does not know is refused under its
|
|
27
|
+
* own name, where reading only the keys it knew used to drop `minn` without a word.
|
|
28
|
+
*/
|
|
29
|
+
export function admits(
|
|
30
|
+
word: string,
|
|
31
|
+
keys: Record<string, Format<unknown>>,
|
|
32
|
+
shared: Record<string, Format<unknown>> = SHARED,
|
|
33
|
+
): Format<unknown> {
|
|
34
|
+
return Object.entries({ ...shared, ...keys })
|
|
35
|
+
.reduce((held, [name, format]) => held.key(name, format), Format.of(`vocabulary/${word}`))
|
|
36
|
+
.closed();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Judge a word's options by the format of its keys — `text(42)` and `text({ minn: 1 })` alike. */
|
|
40
|
+
export function judgeOptions(word: string, format: Format<unknown>, opts: unknown): void {
|
|
41
|
+
if (opts === undefined) return;
|
|
42
|
+
if (!isObject(opts)) throw new SchemaError('Options must go in an object, like { max: 200 }', { received: opts });
|
|
43
|
+
|
|
44
|
+
const refusal = JsonSchemaValidator.of(format.schema as JsonSchema).refusalOf(opts, [`${word}()`]);
|
|
45
|
+
if (refusal) throw new SchemaError(`${dotted(refusal.path)}: ${refusal.message}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A word, declared as a table: its base shape, and each option with the keyword it writes. The
|
|
50
|
+
* closed format, the options type and the shape all derive from that one table.
|
|
51
|
+
* `word<string>()('text', { type: 'string' }, { max: ['maxLength', Format.count] })`
|
|
52
|
+
*/
|
|
53
|
+
export function word<T>() {
|
|
54
|
+
return <Table extends Record<string, WordOption>>(name: string, base: Shape, table: Table) => {
|
|
55
|
+
const format = admits(name, Object.fromEntries(Object.entries(table).map(([key, [, value]]) => [key, value])));
|
|
56
|
+
|
|
57
|
+
return (opts?: OptionsOf<Table> & Shared<T>): Field<T> => {
|
|
58
|
+
judgeOptions(name, format, opts);
|
|
59
|
+
|
|
60
|
+
const written = Object.entries(table)
|
|
61
|
+
.filter(([key]) => opts?.[key as keyof typeof opts] !== undefined)
|
|
62
|
+
.map(([key, [keyword, , write]]) => {
|
|
63
|
+
const value = opts![key as keyof typeof opts];
|
|
64
|
+
|
|
65
|
+
return [keyword, write ? write(value) : value] as const;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return new Field<T>({ shape: { ...base, ...Object.fromEntries(written) } as Shape }).setShared(opts);
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -47,5 +47,5 @@ export { FieldValueValidator } from './validator/FieldValueValidator.js';
|
|
|
47
47
|
export { JsonSchemaValidator } from './validator/JsonSchemaValidator.js';
|
|
48
48
|
export type { JsonSchema } from './lib/JsonSchema.js';
|
|
49
49
|
export { Axes } from './axis/Axes.js';
|
|
50
|
-
export { Format } from './lib/Format.js';
|
|
50
|
+
export { Format, type Accepted } from './lib/Format.js';
|
|
51
51
|
export type { Axis } from './axis/Axis.js';
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { Field, type Described } from '../../field/Field.js';
|
|
2
2
|
import { date } from '../primitive/date.js';
|
|
3
|
+
import { DESCRIBED, admits, judgeOptions } from '../../field/Word.js';
|
|
4
|
+
|
|
5
|
+
const ADMITS = admits('created', {}, DESCRIBED);
|
|
3
6
|
|
|
4
7
|
export function created(opts?: Described): Field<Date> {
|
|
8
|
+
judgeOptions('created', ADMITS, opts);
|
|
9
|
+
|
|
5
10
|
return date(opts).with({
|
|
6
11
|
lifecycle: { create: 'now', update: 'forbidden' },
|
|
7
12
|
});
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { Field, type Described } from '../../field/Field.js';
|
|
2
2
|
import { created } from './created.js';
|
|
3
|
+
import { DESCRIBED, admits, judgeOptions } from '../../field/Word.js';
|
|
4
|
+
|
|
5
|
+
const ADMITS = admits('updated', {}, DESCRIBED);
|
|
3
6
|
|
|
4
7
|
export function updated(opts?: Described): Field<Date> {
|
|
8
|
+
judgeOptions('updated', ADMITS, opts);
|
|
9
|
+
|
|
5
10
|
const base = created(opts);
|
|
6
11
|
|
|
7
12
|
return base.with({ lifecycle: { ...base.lifecycle, update: 'now' } });
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { word } from '../../field/Word.js';
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
return new Field<boolean>({ shape: { type: 'boolean' } }).setShared(opts);
|
|
5
|
-
}
|
|
3
|
+
export const bool = word<boolean>()('bool', { type: 'boolean' }, {});
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { word } from '../../field/Word.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A `Date` in a handler, an ISO string on the wire — the `isoDate` boundary converts.
|
|
5
5
|
* `date()` → `{ type: 'string', format: 'date-time' }`
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
return new Field<Date>({ shape: { type: 'string', format: 'date-time' } }).setShared(
|
|
9
|
-
opts,
|
|
10
|
-
);
|
|
11
|
-
}
|
|
7
|
+
export const date = word<Date>()('date', { type: 'string', format: 'date-time' }, {});
|
|
@@ -3,6 +3,9 @@ import type { SchemaView } from '../../SchemaView.js';
|
|
|
3
3
|
import type { Entity } from '../../entity/Entity.js';
|
|
4
4
|
import { InputValidator } from '../../validator/InputValidator.js';
|
|
5
5
|
import { SchemaError } from '../../SchemaError.js';
|
|
6
|
+
import { admits, judgeOptions } from '../../field/Word.js';
|
|
7
|
+
|
|
8
|
+
const ADMITS = admits('json', {});
|
|
6
9
|
|
|
7
10
|
|
|
8
11
|
export function json<T = unknown>(opts?: Shared<T>): Field<T>;
|
|
@@ -19,6 +22,7 @@ export function json(
|
|
|
19
22
|
opts?: Shared<unknown>,
|
|
20
23
|
): Field<unknown> {
|
|
21
24
|
const [schema, shared] = typeof of === 'function' ? [of, opts] : [undefined, of];
|
|
25
|
+
judgeOptions('json', ADMITS, shared);
|
|
22
26
|
|
|
23
27
|
if (schema && typeof schema.getFields !== 'function')
|
|
24
28
|
throw new SchemaError(
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Field, type Shared } from '../../field/Field.js';
|
|
2
2
|
import { SchemaError } from '../../SchemaError.js';
|
|
3
|
+
import { Format } from '../../lib/Format.js';
|
|
4
|
+
import { admits, judgeOptions, type OptionsIn } from '../../field/Word.js';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const KEYS = { min: Format.count, max: Format.count };
|
|
7
|
+
const ADMITS = admits('list', KEYS);
|
|
8
|
+
|
|
9
|
+
export type ListOptions<T = unknown> = OptionsIn<typeof KEYS> & Shared<T[]>;
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* A list of values. It keeps the shape of the item and nothing else: `nullable()` and a
|
|
@@ -13,6 +15,7 @@ export interface ListOptions<T = unknown> extends Shared<T[]> {
|
|
|
13
15
|
* `list(text(), { max: 5 })` → `{ type: 'array', items: { type: 'string' }, maxItems: 5 }`
|
|
14
16
|
*/
|
|
15
17
|
export function list<T>(field: Field<T>, opts?: ListOptions<T>): Field<T[]> {
|
|
18
|
+
judgeOptions('list', ADMITS, opts);
|
|
16
19
|
if (field.hasAxes())
|
|
17
20
|
throw new SchemaError(
|
|
18
21
|
'list() takes a value, not a rule. Put the rule on the list: unique(list(text())).',
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { Entity } from '../../entity/Entity.js';
|
|
2
2
|
import { Relation } from '../../axis/role/Relation.js';
|
|
3
3
|
import { Field, type Described } from '../../field/Field.js';
|
|
4
|
+
import { DESCRIBED, admits, judgeOptions } from '../../field/Word.js';
|
|
5
|
+
|
|
6
|
+
const ADMITS = admits('many', {}, DESCRIBED);
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* `many(() => Post)` → `{ type: 'array' }` with `role.relation.kind` `'many'`
|
|
@@ -9,6 +12,8 @@ export function many<E extends Entity>(
|
|
|
9
12
|
target: E | (() => E),
|
|
10
13
|
opts?: Described,
|
|
11
14
|
): Field<InstanceType<E>[]> {
|
|
15
|
+
judgeOptions('many', ADMITS, opts);
|
|
16
|
+
|
|
12
17
|
return new Field<InstanceType<E>[]>({
|
|
13
18
|
shape: { type: 'array' },
|
|
14
19
|
role: { relation: Relation.many(target) },
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Format } from '../../lib/Format.js';
|
|
2
|
+
import { word } from '../../field/Word.js';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/** `number({ integer: true, min: 1 })` → `{ type: 'integer', minimum: 1 }` */
|
|
5
|
+
export const number = word<number>()('number', { type: 'number' }, {
|
|
6
|
+
min: ['minimum', Format.number],
|
|
7
|
+
max: ['maximum', Format.number],
|
|
8
|
+
integer: ['type', Format.flag, (integer: boolean) => (integer ? 'integer' : 'number')],
|
|
9
|
+
});
|
|
8
10
|
|
|
9
|
-
export
|
|
10
|
-
return new Field<number>({
|
|
11
|
-
shape: {
|
|
12
|
-
type: opts?.integer ? 'integer' : 'number',
|
|
13
|
-
minimum: opts?.min,
|
|
14
|
-
maximum: opts?.max,
|
|
15
|
-
},
|
|
16
|
-
}).setShared(opts);
|
|
17
|
-
}
|
|
11
|
+
export type NumberOptions = NonNullable<Parameters<typeof number>[0]>;
|
|
@@ -2,6 +2,9 @@ import { Field, type Shared } from '../../field/Field.js';
|
|
|
2
2
|
import type { Shape } from '../../axis/shape/Shape.js';
|
|
3
3
|
import { isArrayOf, isObject } from '../../lib/utils.js';
|
|
4
4
|
import { SchemaError } from '../../SchemaError.js';
|
|
5
|
+
import { admits, judgeOptions } from '../../field/Word.js';
|
|
6
|
+
|
|
7
|
+
const ADMITS = admits('oneOf', {});
|
|
5
8
|
|
|
6
9
|
type Values = readonly [string, ...string[]] | readonly [number, ...number[]];
|
|
7
10
|
|
|
@@ -44,5 +47,7 @@ export function oneOf<const T extends Values>(
|
|
|
44
47
|
'oneOf() takes strings or numbers, then an optional object of options', { received: given },
|
|
45
48
|
);
|
|
46
49
|
|
|
50
|
+
judgeOptions('oneOf', ADMITS, opts);
|
|
51
|
+
|
|
47
52
|
return new Field<T[number]>({ shape }).setShared(opts);
|
|
48
53
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Field, type Described } from '../../field/Field.js';
|
|
2
2
|
import { Generators, type GeneratorRef } from '../../axis/lifecycle/Generators.js';
|
|
3
|
+
import { Format } from '../../lib/Format.js';
|
|
4
|
+
import { DESCRIBED, admits, judgeOptions, type OptionsIn } from '../../field/Word.js';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
const KEYS = { generate: Format.anything.as<GeneratorRef | [name: string, fn: () => string]>() };
|
|
7
|
+
const ADMITS = admits('primary', KEYS, DESCRIBED);
|
|
8
|
+
|
|
9
|
+
type PrimaryOptions = OptionsIn<typeof KEYS> & Described;
|
|
7
10
|
|
|
8
11
|
export function primary(opts?: PrimaryOptions): Field<string>;
|
|
9
12
|
export function primary<T>(field: Field<T>): Field<T>;
|
|
@@ -22,6 +25,7 @@ export function primary(fieldOrOptions?: Field | PrimaryOptions): Field {
|
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
const opts: PrimaryOptions = fieldOrOptions ?? {};
|
|
28
|
+
judgeOptions('primary', ADMITS, fieldOrOptions);
|
|
25
29
|
|
|
26
30
|
let generate: GeneratorRef;
|
|
27
31
|
if (Array.isArray(opts.generate)) {
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import type { Entity } from '../../entity/Entity.js';
|
|
2
|
-
import {
|
|
2
|
+
import { ON_DELETE, Relation } from '../../axis/role/Relation.js';
|
|
3
3
|
import { Field, type Shared } from '../../field/Field.js';
|
|
4
|
+
import { Format } from '../../lib/Format.js';
|
|
5
|
+
import { admits, judgeOptions, type OptionsIn } from '../../field/Word.js';
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
const KEYS = { onDelete: Format.tokens(ON_DELETE) };
|
|
8
|
+
const ADMITS = admits('ref', KEYS);
|
|
9
|
+
|
|
10
|
+
export type RefOptions = OptionsIn<typeof KEYS> & Shared<string>;
|
|
8
11
|
|
|
9
12
|
export function ref<E extends Entity>(
|
|
10
13
|
target: E | (() => E),
|
|
11
14
|
opts?: RefOptions,
|
|
12
15
|
): Field<string> {
|
|
16
|
+
judgeOptions('ref', ADMITS, opts);
|
|
17
|
+
|
|
13
18
|
return new Field<string>({
|
|
14
19
|
shape: { type: 'string' },
|
|
15
20
|
role: { relation: Relation.one(target, opts?.onDelete) },
|
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Format } from '../../lib/Format.js';
|
|
2
|
+
import { word } from '../../field/Word.js';
|
|
3
|
+
import type { StringFormat } from '../../axis/shape/StringFormat.js';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
/** `text({ min: 1, max: 160 })` → `{ type: 'string', minLength: 1, maxLength: 160 }` */
|
|
6
|
+
export const text = word<string>()('text', { type: 'string' }, {
|
|
7
|
+
min: ['minLength', Format.count],
|
|
8
|
+
max: ['maxLength', Format.count],
|
|
9
|
+
pattern: ['pattern', Format.text],
|
|
10
|
+
format: ['format', Format.text.as<StringFormat>()],
|
|
11
|
+
});
|
|
10
12
|
|
|
11
|
-
export
|
|
12
|
-
return new Field<string>({
|
|
13
|
-
shape: {
|
|
14
|
-
type: 'string',
|
|
15
|
-
minLength: opts?.min,
|
|
16
|
-
maxLength: opts?.max,
|
|
17
|
-
pattern: opts?.pattern,
|
|
18
|
-
format: opts?.format,
|
|
19
|
-
},
|
|
20
|
-
}).setShared(opts);
|
|
21
|
-
}
|
|
13
|
+
export type TextOptions = NonNullable<Parameters<typeof text>[0]>;
|