@maroonedog/luq 2.2.0 → 2.3.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/README.md +47 -602
- package/dist/builder/compile-declarations.d.ts +7 -1
- package/dist/builder/compile-declarations.js +18 -8
- package/dist/builder/compile-declarations.mjs +18 -8
- package/dist/builder/create-builder.js +2 -3
- package/dist/builder/create-builder.mjs +2 -3
- package/dist/builder/create-field-builder.js +13 -1
- package/dist/builder/create-field-builder.mjs +13 -1
- package/dist/builder/declared-calls-store.d.ts +9 -0
- package/dist/builder/declared-calls-store.js +19 -0
- package/dist/builder/declared-calls-store.mjs +15 -0
- package/dist/builder/field-declared-calls.types.d.ts +6 -0
- package/dist/builder/field-declared-calls.types.js +2 -0
- package/dist/builder/field-declared-calls.types.mjs +1 -0
- package/dist/builder/field-entry.types.d.ts +9 -3
- package/dist/builder/field-options.types.d.ts +26 -0
- package/dist/chain/bundle-paths.types.d.ts +9 -12
- package/dist/chain/chain-node-store.d.ts +5 -0
- package/dist/chain/chain-node-store.js +15 -0
- package/dist/chain/chain-node-store.mjs +11 -0
- package/dist/chain/collect-field-rules.d.ts +13 -2
- package/dist/chain/collect-field-rules.js +10 -3
- package/dist/chain/collect-field-rules.mjs +10 -3
- package/dist/chain/create-chain-node.js +19 -9
- package/dist/chain/create-chain-node.mjs +19 -9
- package/dist/chain/declaration-recorder.port.d.ts +31 -0
- package/dist/chain/declaration-recorder.port.js +17 -0
- package/dist/chain/declaration-recorder.port.mjs +13 -0
- package/dist/chain/declared-call.types.d.ts +15 -0
- package/dist/chain/declared-call.types.js +2 -0
- package/dist/chain/declared-call.types.mjs +1 -0
- package/dist/chain/index.d.ts +3 -1
- package/dist/compile/compile-array-node.js +1 -0
- package/dist/compile/compile-array-node.mjs +1 -0
- package/dist/compile/compile-field.d.ts +1 -0
- package/dist/compile/compile-field.js +8 -6
- package/dist/compile/compile-field.mjs +8 -6
- package/dist/compile/compile-schema.js +4 -0
- package/dist/compile/compile-schema.mjs +4 -0
- package/dist/compile/group-array-fields.d.ts +1 -0
- package/dist/compile/split-rules-by-kind.js +10 -14
- package/dist/compile/split-rules-by-kind.mjs +10 -14
- package/dist/compile/validation-plan.types.d.ts +19 -6
- package/dist/core/type-erasure.d.ts +36 -30
- package/dist/core/type-erasure.js +36 -30
- package/dist/core/type-erasure.mjs +36 -30
- package/dist/json-schema/build-from-schema.js +8 -1
- package/dist/json-schema/build-from-schema.mjs +8 -1
- package/dist/json-schema/declare-additional-properties.d.ts +7 -7
- package/dist/json-schema/declare-additional-properties.js +7 -7
- package/dist/json-schema/declare-additional-properties.mjs +7 -7
- package/dist/json-schema/declare-object-keywords.js +4 -4
- package/dist/json-schema/declare-object-keywords.mjs +4 -4
- package/dist/json-schema/follow-json-pointer.d.ts +7 -6
- package/dist/json-schema/follow-json-pointer.js +24 -24
- package/dist/json-schema/follow-json-pointer.mjs +24 -24
- package/dist/json-schema/ref-resolution-error.js +3 -3
- package/dist/json-schema/ref-resolution-error.mjs +3 -3
- package/dist/json-schema/schema-registry.js +12 -11
- package/dist/json-schema/schema-registry.mjs +12 -11
- package/dist/json-schema/uri-reference.js +12 -12
- package/dist/json-schema/uri-reference.mjs +12 -12
- package/dist/path/create-value-writer.js +12 -12
- package/dist/path/create-value-writer.mjs +12 -12
- package/dist/path/reserved-segment.d.ts +16 -16
- package/dist/path/reserved-segment.js +17 -21
- package/dist/path/reserved-segment.mjs +17 -21
- package/dist/plugins/index.generated.js +2 -2
- package/dist/plugins/index.generated.mjs +2 -2
- package/dist/plugins/manifest.generated.js +2 -2
- package/dist/plugins/manifest.generated.mjs +2 -2
- package/dist/plugins/object-additional-properties/select-additional-keys.d.ts +8 -8
- package/dist/plugins/object-additional-properties/select-additional-keys.js +16 -16
- package/dist/plugins/object-additional-properties/select-additional-keys.mjs +16 -16
- package/dist/plugins/stitch/stitch.d.ts +10 -14
- package/dist/plugins/stitch-with/stitch-with.d.ts +1 -1
- package/dist/plugins/stitch-with/stitch-with.js +22 -24
- package/dist/plugins/stitch-with/stitch-with.mjs +22 -24
- package/dist/plugins/string-min/string-min.js +6 -8
- package/dist/plugins/string-min/string-min.mjs +6 -8
- package/dist/presets/presets.d.ts +10 -11
- package/dist/presets/presets.js +22 -23
- package/dist/presets/presets.mjs +22 -23
- package/dist/runtime/create-field-validator.js +4 -6
- package/dist/runtime/create-field-validator.mjs +4 -6
- package/dist/runtime/create-validator.js +11 -11
- package/dist/runtime/create-validator.mjs +11 -11
- package/dist/runtime/output-writer.js +5 -1
- package/dist/runtime/output-writer.mjs +5 -1
- package/dist/runtime/run-array-node.js +6 -6
- package/dist/runtime/run-array-node.mjs +6 -6
- package/dist/runtime/run-field.js +18 -19
- package/dist/runtime/run-field.mjs +18 -19
- package/dist/standard-schema/assemble-json-schema.d.ts +4 -0
- package/dist/standard-schema/assemble-json-schema.js +95 -0
- package/dist/standard-schema/assemble-json-schema.mjs +92 -0
- package/dist/standard-schema/declaration-recorder.d.ts +6 -0
- package/dist/standard-schema/declaration-recorder.js +30 -0
- package/dist/standard-schema/declaration-recorder.mjs +27 -0
- package/dist/standard-schema/declarations-unavailable-error.d.ts +4 -0
- package/dist/standard-schema/declarations-unavailable-error.js +32 -0
- package/dist/standard-schema/declarations-unavailable-error.mjs +28 -0
- package/dist/standard-schema/emit-field-schema.d.ts +9 -0
- package/dist/standard-schema/emit-field-schema.js +68 -0
- package/dist/standard-schema/emit-field-schema.mjs +65 -0
- package/dist/standard-schema/index.d.ts +5 -0
- package/dist/standard-schema/index.js +9 -1
- package/dist/standard-schema/index.mjs +4 -0
- package/dist/standard-schema/json-schema-target.d.ts +6 -0
- package/dist/standard-schema/json-schema-target.js +44 -0
- package/dist/standard-schema/json-schema-target.mjs +39 -0
- package/dist/standard-schema/plugin-keyword-map.d.ts +3 -0
- package/dist/standard-schema/plugin-keyword-map.js +93 -0
- package/dist/standard-schema/plugin-keyword-map.mjs +90 -0
- package/dist/standard-schema/split-issue-path.d.ts +6 -4
- package/dist/standard-schema/split-issue-path.js +15 -13
- package/dist/standard-schema/split-issue-path.mjs +15 -13
- package/dist/standard-schema/standard-schema.types.d.ts +8 -7
- package/dist/standard-schema/standard-schema.types.js +6 -6
- package/dist/standard-schema/standard-schema.types.mjs +6 -6
- package/dist/standard-schema/to-standard-json-schema.d.ts +19 -0
- package/dist/standard-schema/to-standard-json-schema.js +36 -0
- package/dist/standard-schema/to-standard-json-schema.mjs +33 -0
- package/dist/standard-schema/to-standard-schema.d.ts +16 -15
- package/dist/standard-schema/to-standard-schema.js +15 -22
- package/dist/standard-schema/to-standard-schema.mjs +15 -22
- package/dist/standard-schema/unrepresentable-rule-error.d.ts +15 -0
- package/dist/standard-schema/unrepresentable-rule-error.js +43 -0
- package/dist/standard-schema/unrepresentable-rule-error.mjs +38 -0
- package/dist/types/index.d.ts +12 -12
- package/dist/types/index.js +7 -7
- package/dist/types/index.mjs +7 -7
- package/package.json +1 -1
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { splitIssuePath } from "./split-issue-path.mjs";
|
|
2
|
-
/** package.
|
|
2
|
+
/** Matches the package name. Consumers show it in error output. */
|
|
3
3
|
const VENDOR = "luq";
|
|
4
4
|
const COLLECT_EVERY_ISSUE = {
|
|
5
5
|
abortEarly: false,
|
|
6
6
|
abortEarlyOnEachField: false,
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* The original validator's members stay. What comes back is still a
|
|
10
|
+
* Validator, so neither face has to be given up for the other.
|
|
11
11
|
*/
|
|
12
12
|
export function toStandardSchema(validator) {
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
// ここがコンパイルエラーになる — 黙って落ちるより良い。
|
|
13
|
+
// Assembled without a type assertion; this is not a file allowed to write
|
|
14
|
+
// one. Copying each member by name means a new member on Validator breaks
|
|
15
|
+
// the build here, which beats being dropped in silence.
|
|
17
16
|
const props = {
|
|
18
17
|
version: 1,
|
|
19
18
|
vendor: VENDOR,
|
|
@@ -33,25 +32,19 @@ export function toStandardSchema(validator) {
|
|
|
33
32
|
};
|
|
34
33
|
}
|
|
35
34
|
/**
|
|
36
|
-
* code
|
|
37
|
-
*
|
|
35
|
+
* code and severity have nowhere to go in the spec, so they are dropped. The
|
|
36
|
+
* message is passed through as already composed.
|
|
38
37
|
*/
|
|
39
38
|
function toStandardIssue(issue) {
|
|
40
39
|
return { message: issue.message, path: splitIssuePath(issue.path) };
|
|
41
40
|
}
|
|
42
41
|
// ---------------------------------------------------------------------------
|
|
43
|
-
//
|
|
42
|
+
// Why build() does not simply put ~standard on every validator.
|
|
44
43
|
//
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
// 7,420 B なので 4.2% にあたり、「使った分しか入らない」という約束と噛み合わない。
|
|
52
|
-
// サブパスにしておけば import しない限り 0 B で、tRPC などに渡したい人だけが払う。
|
|
53
|
-
//
|
|
54
|
-
// 代償は、利用者が toStandardSchema() で1回包む必要があること。build() が
|
|
55
|
-
// 直接 ~standard を持つほうが体験は良いが、その体験のために全員に課金する形に
|
|
56
|
-
// なるので取らなかった。将来コアに入れるなら、この 312 B が判断材料になる。
|
|
44
|
+
// It would be the nicer experience — no wrapping call — but it bills everyone
|
|
45
|
+
// for it, including the majority who never hand a validator to a spec
|
|
46
|
+
// consumer. Measured against the core bundle the surcharge was a few percent,
|
|
47
|
+
// which does not fit "you only ship what you used". As a subpath it costs
|
|
48
|
+
// nothing until imported. Re-measure before revisiting the decision; the
|
|
49
|
+
// figures live with the size budget, not here.
|
|
57
50
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class UnrepresentableRuleError extends Error {
|
|
2
|
+
readonly fieldPath: string;
|
|
3
|
+
readonly pluginName: string;
|
|
4
|
+
readonly reason: string;
|
|
5
|
+
constructor(fieldPath: string, pluginName: string, reason: string);
|
|
6
|
+
}
|
|
7
|
+
/** What to do with an unwritable declaration. Defaults to "throw". */
|
|
8
|
+
export type UnrepresentablePolicy = "throw" | "omit";
|
|
9
|
+
/**
|
|
10
|
+
* Reads the policy out of `libraryOptions`.
|
|
11
|
+
*
|
|
12
|
+
* An unrecognised value falls to throw. A misspelled `omit` landing on the
|
|
13
|
+
* strict side is correct; landing on the lax side is an incident.
|
|
14
|
+
*/
|
|
15
|
+
export declare function readUnrepresentablePolicy(libraryOptions: Record<string, unknown> | undefined): UnrepresentablePolicy;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ===========================================================================
|
|
3
|
+
// L10 src/standard-schema/unrepresentable-rule-error.ts
|
|
4
|
+
//
|
|
5
|
+
// Meeting a declaration that cannot be written as JSON Schema throws, by
|
|
6
|
+
// default.
|
|
7
|
+
//
|
|
8
|
+
// Dropping it silently is not on offer. What comes out of here gets USED FOR
|
|
9
|
+
// VALIDATION by whoever receives it, so dropping a `.custom()` produces a
|
|
10
|
+
// schema that admits values it must not — with no trace of the omission. The
|
|
11
|
+
// missing constraint is discovered by the incident it causes.
|
|
12
|
+
//
|
|
13
|
+
// Anyone for whom dropping is fine — emitting for documentation or for a form
|
|
14
|
+
// layout rather than for validation — can ask for it explicitly through
|
|
15
|
+
// libraryOptions, which the spec provides for exactly this kind of agreement.
|
|
16
|
+
// The point is that the lax choice is never the default, and that having made
|
|
17
|
+
// it stays visible in the caller's code.
|
|
18
|
+
// ===========================================================================
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.UnrepresentableRuleError = void 0;
|
|
21
|
+
exports.readUnrepresentablePolicy = readUnrepresentablePolicy;
|
|
22
|
+
class UnrepresentableRuleError extends Error {
|
|
23
|
+
constructor(fieldPath, pluginName, reason) {
|
|
24
|
+
super(`"${fieldPath}" declares ${pluginName}, which Luq cannot express in ` +
|
|
25
|
+
`JSON Schema: ${reason}. Pass ` +
|
|
26
|
+
`libraryOptions: { unrepresentable: "omit" } to drop it instead — ` +
|
|
27
|
+
`the emitted schema then accepts values this validator rejects.`);
|
|
28
|
+
this.fieldPath = fieldPath;
|
|
29
|
+
this.pluginName = pluginName;
|
|
30
|
+
this.reason = reason;
|
|
31
|
+
this.name = "UnrepresentableRuleError";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.UnrepresentableRuleError = UnrepresentableRuleError;
|
|
35
|
+
/**
|
|
36
|
+
* Reads the policy out of `libraryOptions`.
|
|
37
|
+
*
|
|
38
|
+
* An unrecognised value falls to throw. A misspelled `omit` landing on the
|
|
39
|
+
* strict side is correct; landing on the lax side is an incident.
|
|
40
|
+
*/
|
|
41
|
+
function readUnrepresentablePolicy(libraryOptions) {
|
|
42
|
+
return libraryOptions?.["unrepresentable"] === "omit" ? "omit" : "throw";
|
|
43
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// ===========================================================================
|
|
2
|
+
// L10 src/standard-schema/unrepresentable-rule-error.ts
|
|
3
|
+
//
|
|
4
|
+
// Meeting a declaration that cannot be written as JSON Schema throws, by
|
|
5
|
+
// default.
|
|
6
|
+
//
|
|
7
|
+
// Dropping it silently is not on offer. What comes out of here gets USED FOR
|
|
8
|
+
// VALIDATION by whoever receives it, so dropping a `.custom()` produces a
|
|
9
|
+
// schema that admits values it must not — with no trace of the omission. The
|
|
10
|
+
// missing constraint is discovered by the incident it causes.
|
|
11
|
+
//
|
|
12
|
+
// Anyone for whom dropping is fine — emitting for documentation or for a form
|
|
13
|
+
// layout rather than for validation — can ask for it explicitly through
|
|
14
|
+
// libraryOptions, which the spec provides for exactly this kind of agreement.
|
|
15
|
+
// The point is that the lax choice is never the default, and that having made
|
|
16
|
+
// it stays visible in the caller's code.
|
|
17
|
+
// ===========================================================================
|
|
18
|
+
export class UnrepresentableRuleError extends Error {
|
|
19
|
+
constructor(fieldPath, pluginName, reason) {
|
|
20
|
+
super(`"${fieldPath}" declares ${pluginName}, which Luq cannot express in ` +
|
|
21
|
+
`JSON Schema: ${reason}. Pass ` +
|
|
22
|
+
`libraryOptions: { unrepresentable: "omit" } to drop it instead — ` +
|
|
23
|
+
`the emitted schema then accepts values this validator rejects.`);
|
|
24
|
+
this.fieldPath = fieldPath;
|
|
25
|
+
this.pluginName = pluginName;
|
|
26
|
+
this.reason = reason;
|
|
27
|
+
this.name = "UnrepresentableRuleError";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Reads the policy out of `libraryOptions`.
|
|
32
|
+
*
|
|
33
|
+
* An unrecognised value falls to throw. A misspelled `omit` landing on the
|
|
34
|
+
* strict side is correct; landing on the lax side is an incident.
|
|
35
|
+
*/
|
|
36
|
+
export function readUnrepresentablePolicy(libraryOptions) {
|
|
37
|
+
return libraryOptions?.["unrepresentable"] === "omit" ? "omit" : "throw";
|
|
38
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -44,12 +44,12 @@ export type CheckOutcome = {
|
|
|
44
44
|
export declare const PASS: CheckOutcome;
|
|
45
45
|
export declare function fail(detail: IssueDetail): CheckOutcome;
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
47
|
+
* What a cross-field check may answer: a boolean, or a boolean with a message.
|
|
48
48
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
49
|
+
* It lives at the bottom layer because the chain layer needs it to build the
|
|
50
|
+
* caller-facing type of `stitch`. Left in the plugin, that would be an import
|
|
51
|
+
* running outward from the chain, which no layer may do. The plugin's
|
|
52
|
+
* `StitchOutcome` is an alias of this one, so the public name is unchanged.
|
|
53
53
|
*/
|
|
54
54
|
export interface CrossFieldOutcome {
|
|
55
55
|
readonly valid: boolean;
|
|
@@ -79,14 +79,14 @@ export declare function isArray(value: unknown): value is readonly unknown[];
|
|
|
79
79
|
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
80
80
|
export declare function isStringArray(value: unknown): value is readonly string[];
|
|
81
81
|
/**
|
|
82
|
-
*
|
|
82
|
+
* Counts a string's length in code points.
|
|
83
83
|
*
|
|
84
|
-
* `.length`
|
|
85
|
-
* JSON Schema §6.3.1
|
|
86
|
-
*
|
|
84
|
+
* `.length` counts UTF-16 code units, so an emoji or any astral character
|
|
85
|
+
* counts as two. JSON Schema §6.3.1 defines minLength / maxLength in code
|
|
86
|
+
* points, and code points are also what someone writing "three characters"
|
|
87
|
+
* means.
|
|
87
88
|
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* ここでその決定をした。星域文字を含む文字列では 1.x と判定が変わる。
|
|
89
|
+
* This is a deliberate decision, not an inherited one: strings containing
|
|
90
|
+
* astral characters are judged differently than under the legacy `.length`.
|
|
91
91
|
*/
|
|
92
92
|
export declare function countCodePoints(value: string): number;
|
package/dist/types/index.js
CHANGED
|
@@ -28,15 +28,15 @@ function isStringArray(value) {
|
|
|
28
28
|
return isArray(value) && value.every(isString);
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Counts a string's length in code points.
|
|
32
32
|
*
|
|
33
|
-
* `.length`
|
|
34
|
-
* JSON Schema §6.3.1
|
|
35
|
-
*
|
|
33
|
+
* `.length` counts UTF-16 code units, so an emoji or any astral character
|
|
34
|
+
* counts as two. JSON Schema §6.3.1 defines minLength / maxLength in code
|
|
35
|
+
* points, and code points are also what someone writing "three characters"
|
|
36
|
+
* means.
|
|
36
37
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* ここでその決定をした。星域文字を含む文字列では 1.x と判定が変わる。
|
|
38
|
+
* This is a deliberate decision, not an inherited one: strings containing
|
|
39
|
+
* astral characters are judged differently than under the legacy `.length`.
|
|
40
40
|
*/
|
|
41
41
|
function countCodePoints(value) {
|
|
42
42
|
let count = 0;
|
package/dist/types/index.mjs
CHANGED
|
@@ -18,15 +18,15 @@ export function isStringArray(value) {
|
|
|
18
18
|
return isArray(value) && value.every(isString);
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* Counts a string's length in code points.
|
|
22
22
|
*
|
|
23
|
-
* `.length`
|
|
24
|
-
* JSON Schema §6.3.1
|
|
25
|
-
*
|
|
23
|
+
* `.length` counts UTF-16 code units, so an emoji or any astral character
|
|
24
|
+
* counts as two. JSON Schema §6.3.1 defines minLength / maxLength in code
|
|
25
|
+
* points, and code points are also what someone writing "three characters"
|
|
26
|
+
* means.
|
|
26
27
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* ここでその決定をした。星域文字を含む文字列では 1.x と判定が変わる。
|
|
28
|
+
* This is a deliberate decision, not an inherited one: strings containing
|
|
29
|
+
* astral characters are judged differently than under the legacy `.length`.
|
|
30
30
|
*/
|
|
31
31
|
export function countCodePoints(value) {
|
|
32
32
|
let count = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maroonedog/luq",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Universal Model & API Definition Platform - TypeScript validation library evolving into cross-language code generation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|