constructa-schema 0.0.3 → 1.0.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 +21 -10
- package/dist/index.d.ts +50 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +174 -44
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,23 +1,34 @@
|
|
|
1
1
|
# `constructa-schema`
|
|
2
2
|
|
|
3
|
-
Portable generator definitions, validation schemas, and related types shared by every Constructa interface.
|
|
4
|
-
|
|
5
|
-
Planned areas include definition versioning, primitive and composite definitions, validation results, and safe serialization. This package must remain independent of execution, UI, network, and persistence concerns.
|
|
3
|
+
Portable generator definitions, versioned generator documents, validation schemas, and related types shared by every Constructa interface.
|
|
6
4
|
|
|
7
5
|
## Portable data constraint
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
Documents and definitions are JSON-only data. Supported values are strings, booleans, `null`, finite numbers other than negative zero, arrays, and plain object records whose properties are all JSON values. Functions, symbols, bigints, `NaN`, infinities, cyclic objects, sparse arrays, custom `toJSON` behavior, class instances, maps, sets, dates, accessors, symbol keys, and non-enumerable properties are rejected.
|
|
8
|
+
|
|
9
|
+
## Definitions and documents
|
|
10
|
+
|
|
11
|
+
A `GeneratorDefinition` is executable generator data. It has a stable, non-empty `type` discriminator, with generator-specific fields at the same level:
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
```json
|
|
14
|
+
{ "type": "integer", "min": 1, "max": 100 }
|
|
15
|
+
```
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
A `GeneratorDocumentV1` wraps exactly one root definition and carries versioning and optional display metadata:
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"schemaVersion": 1,
|
|
22
|
+
"name": "Small integer",
|
|
23
|
+
"description": "An integer in a bounded range.",
|
|
24
|
+
"definition": { "type": "integer", "min": 1, "max": 100 }
|
|
25
|
+
}
|
|
26
|
+
```
|
|
16
27
|
|
|
17
|
-
|
|
28
|
+
`name` and `description` are optional strings; empty strings are preserved rather than normalized. Unknown document keys are rejected. Document metadata, ownership, visibility, and timestamps do not belong in generator definitions. The former `{ type, configuration }` envelope is rejected; move its generator fields directly into `definition`.
|
|
18
29
|
|
|
19
|
-
Use `
|
|
30
|
+
Use `parseDocument` to validate and obtain a `GeneratorDocumentV1`, or `safeParseDocument` and `findDocumentFailure` for structured failures. Use `isGeneratorDefinition` or `assertGeneratorDefinition` when validating an unwrapped definition.
|
|
20
31
|
|
|
21
32
|
## Dependency boundary
|
|
22
33
|
|
|
23
|
-
This is the bottom of the domain dependency graph and has no Constructa runtime dependencies.
|
|
34
|
+
This is the bottom of the domain dependency graph and has no Constructa runtime dependencies.
|
package/dist/index.d.ts
CHANGED
|
@@ -8,9 +8,19 @@ type JsonObject = {
|
|
|
8
8
|
declare const CURRENT_SCHEMA_VERSION = 1;
|
|
9
9
|
declare const SUPPORTED_SCHEMA_VERSIONS: readonly [1];
|
|
10
10
|
type SchemaVersion = (typeof SUPPORTED_SCHEMA_VERSIONS)[number];
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/** Portable executable generator data. Generator fields live beside `type`. */
|
|
12
|
+
type GeneratorDefinition = JsonObject & {
|
|
13
|
+
readonly type: string;
|
|
13
14
|
};
|
|
15
|
+
/** Versioned document containing exactly one root generator definition. */
|
|
16
|
+
type GeneratorDocumentV1 = {
|
|
17
|
+
readonly schemaVersion: 1;
|
|
18
|
+
readonly definition: GeneratorDefinition;
|
|
19
|
+
readonly name?: string;
|
|
20
|
+
readonly description?: string;
|
|
21
|
+
};
|
|
22
|
+
type GeneratorDocument = GeneratorDocumentV1;
|
|
23
|
+
declare const GENERATOR_DOCUMENT_TOP_LEVEL_KEYS: readonly ["schemaVersion", "name", "description", "definition"];
|
|
14
24
|
type SchemaVersionFailureCode = "schema_version_missing" | "schema_version_unsupported";
|
|
15
25
|
type SchemaVersionFailure = {
|
|
16
26
|
readonly code: SchemaVersionFailureCode;
|
|
@@ -19,6 +29,27 @@ type SchemaVersionFailure = {
|
|
|
19
29
|
readonly severity: "error";
|
|
20
30
|
readonly supportedVersions: readonly SchemaVersion[];
|
|
21
31
|
};
|
|
32
|
+
type GeneratorDefinitionFailureCode = "generator_definition_not_json" | "generator_definition_not_object" | "generator_type_missing" | "generator_type_invalid" | "definition_document_metadata";
|
|
33
|
+
type GeneratorDefinitionFailure = {
|
|
34
|
+
readonly code: GeneratorDefinitionFailureCode;
|
|
35
|
+
readonly message: string;
|
|
36
|
+
readonly path: string;
|
|
37
|
+
readonly severity: "error";
|
|
38
|
+
};
|
|
39
|
+
type GeneratorDocumentFailureCode = SchemaVersionFailureCode | GeneratorDefinitionFailureCode | "generator_document_not_json" | "generator_document_not_object" | "definition_missing" | "name_invalid" | "description_invalid" | "top_level_property_unknown" | "configuration_envelope_removed";
|
|
40
|
+
type GeneratorDocumentFailure = SchemaVersionFailure | {
|
|
41
|
+
readonly code: Exclude<GeneratorDocumentFailureCode, SchemaVersionFailureCode>;
|
|
42
|
+
readonly message: string;
|
|
43
|
+
readonly path: string;
|
|
44
|
+
readonly severity: "error";
|
|
45
|
+
};
|
|
46
|
+
type GeneratorDocumentParseResult = {
|
|
47
|
+
readonly success: true;
|
|
48
|
+
readonly value: GeneratorDocumentV1;
|
|
49
|
+
} | {
|
|
50
|
+
readonly success: false;
|
|
51
|
+
readonly failure: GeneratorDocumentFailure;
|
|
52
|
+
};
|
|
22
53
|
declare class JsonValueError extends TypeError {
|
|
23
54
|
constructor(path: string, reason: string);
|
|
24
55
|
}
|
|
@@ -26,18 +57,32 @@ declare class SchemaVersionError extends TypeError {
|
|
|
26
57
|
readonly failure: SchemaVersionFailure;
|
|
27
58
|
constructor(failure: SchemaVersionFailure);
|
|
28
59
|
}
|
|
60
|
+
declare class GeneratorDefinitionError extends TypeError {
|
|
61
|
+
readonly failure: GeneratorDefinitionFailure;
|
|
62
|
+
constructor(failure: GeneratorDefinitionFailure);
|
|
63
|
+
}
|
|
64
|
+
declare class GeneratorDocumentError extends TypeError {
|
|
65
|
+
readonly failure: GeneratorDocumentFailure;
|
|
66
|
+
constructor(failure: GeneratorDocumentFailure);
|
|
67
|
+
}
|
|
29
68
|
declare function isJsonValue(value: unknown): value is JsonValue;
|
|
30
69
|
declare function isSchemaVersion(value: unknown): value is SchemaVersion;
|
|
31
|
-
declare function
|
|
70
|
+
declare function isGeneratorDefinition(value: unknown): value is GeneratorDefinition;
|
|
71
|
+
declare function isDocument(value: unknown): value is GeneratorDocumentV1;
|
|
32
72
|
declare function assertJsonValue(value: unknown, path?: string): asserts value is JsonValue;
|
|
33
73
|
declare function assertSchemaVersion(value: unknown, path?: string): asserts value is SchemaVersion;
|
|
34
|
-
declare function
|
|
74
|
+
declare function assertGeneratorDefinition(value: unknown, path?: string): asserts value is GeneratorDefinition;
|
|
75
|
+
declare function assertDocument(value: unknown, path?: string): asserts value is GeneratorDocumentV1;
|
|
76
|
+
declare function parseDocument(value: unknown, path?: string): GeneratorDocumentV1;
|
|
77
|
+
declare function safeParseDocument(value: unknown, path?: string): GeneratorDocumentParseResult;
|
|
35
78
|
declare function findJsonValueError(value: unknown, path?: string): {
|
|
36
79
|
path: string;
|
|
37
80
|
reason: string;
|
|
38
81
|
} | undefined;
|
|
82
|
+
declare function findGeneratorDefinitionFailure(value: unknown, path?: string): GeneratorDefinitionFailure | undefined;
|
|
83
|
+
declare function findDocumentFailure(value: unknown, path?: string): GeneratorDocumentFailure | undefined;
|
|
39
84
|
declare function findSchemaVersionFailure(value: unknown, path?: string): SchemaVersionFailure | undefined;
|
|
40
85
|
declare function findSchemaVersionValueFailure(value: unknown, path?: string): SchemaVersionFailure | undefined;
|
|
41
86
|
//#endregion
|
|
42
|
-
export { CURRENT_SCHEMA_VERSION, JsonArray, JsonObject, JsonPrimitive, JsonValue, JsonValueError, SUPPORTED_SCHEMA_VERSIONS, SchemaVersion, SchemaVersionError, SchemaVersionFailure, SchemaVersionFailureCode,
|
|
87
|
+
export { CURRENT_SCHEMA_VERSION, GENERATOR_DOCUMENT_TOP_LEVEL_KEYS, GeneratorDefinition, GeneratorDefinitionError, GeneratorDefinitionFailure, GeneratorDefinitionFailureCode, GeneratorDocument, GeneratorDocumentError, GeneratorDocumentFailure, GeneratorDocumentFailureCode, GeneratorDocumentParseResult, GeneratorDocumentV1, JsonArray, JsonObject, JsonPrimitive, JsonValue, JsonValueError, SUPPORTED_SCHEMA_VERSIONS, SchemaVersion, SchemaVersionError, SchemaVersionFailure, SchemaVersionFailureCode, assertDocument, assertGeneratorDefinition, assertJsonValue, assertSchemaVersion, findDocumentFailure, findGeneratorDefinitionFailure, findJsonValueError, findSchemaVersionFailure, findSchemaVersionValueFailure, isDocument, isGeneratorDefinition, isJsonValue, isSchemaVersion, parseDocument, safeParseDocument };
|
|
43
88
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";KAAY;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";KAAY;KACA,YAAY,YAAY,aAAa;KACrC,qBAAqB;KACrB;YAAyB,cAAc;;cAEtC;cACA;KACD,wBAAwB;;KAGxB,sBAAsB;WAAwB;;;KAG9C;WACD;WACA,YAAY;WACZ;WACA;;KAGC,oBAAoB;cAEnB;KAmBD;KAGA;WACD,MAAM;WACN;WACA;WACA;WACA,4BAA4B;;KAG3B;KAMA;WACD,MAAM;WACN;WACA;WACA;;KAGC,+BACR,2BACA;KAQQ,2BACR;WAEW,MAAM,QACb,8BACA;WAEO;WACA;WACA;;KAEH;WACG;WAAwB,OAAO;;WAC/B;WAAyB,SAAS;;cAEpC,uBAAuB;EACtB,YAAA,cAAc;;cAMf,2BAA2B;WAC7B,SAAS;EACN,YAAA,SAAS;;cAOV,iCAAiC;WACnC,SAAS;EACN,YAAA,SAAS;;cAOV,+BAA+B;WACjC,SAAS;EACN,YAAA,SAAS;;iBAOP,YAAY,iBAAiB,SAAS;iBAGtC,gBAAgB,iBAAiB,SAAS;iBAG1C,sBACd,iBACC,SAAS;iBAGI,WAAW,iBAAiB,SAAS;iBAGrC,gBACd,gBACA,wBACS,SAAS;iBAIJ,oBACd,gBACA,wBACS,SAAS;iBAIJ,0BACd,gBACA,wBACS,SAAS;iBAIJ,eACd,gBACA,wBACS,SAAS;iBAIJ,cAAc,gBAAgB,gBAAa;iBAI3C,kBACd,gBACA,gBACC;iBAOa,mBACd,gBACA;EACG;EAAc;;iBAGH,+BACd,gBACA,gBACC;iBAsCa,oBACd,gBACA,gBACC;iBAwCa,yBACd,gBACA,gBACC;iBAWa,8BACd,gBACA,gBACC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
//#region src/index.ts
|
|
2
2
|
const CURRENT_SCHEMA_VERSION = 1;
|
|
3
3
|
const SUPPORTED_SCHEMA_VERSIONS = [1];
|
|
4
|
+
const GENERATOR_DOCUMENT_TOP_LEVEL_KEYS = [
|
|
5
|
+
"schemaVersion",
|
|
6
|
+
"name",
|
|
7
|
+
"description",
|
|
8
|
+
"definition"
|
|
9
|
+
];
|
|
10
|
+
const DOCUMENT_METADATA_KEYS = /* @__PURE__ */ new Set([
|
|
11
|
+
"schemaVersion",
|
|
12
|
+
"name",
|
|
13
|
+
"description",
|
|
14
|
+
"owner",
|
|
15
|
+
"ownership",
|
|
16
|
+
"visibility",
|
|
17
|
+
"createdAt",
|
|
18
|
+
"updatedAt",
|
|
19
|
+
"timestamps"
|
|
20
|
+
]);
|
|
4
21
|
var JsonValueError = class extends TypeError {
|
|
5
22
|
constructor(path, reason) {
|
|
6
23
|
super(`${path}: ${reason}`);
|
|
@@ -15,14 +32,33 @@ var SchemaVersionError = class extends TypeError {
|
|
|
15
32
|
this.failure = failure;
|
|
16
33
|
}
|
|
17
34
|
};
|
|
35
|
+
var GeneratorDefinitionError = class extends TypeError {
|
|
36
|
+
failure;
|
|
37
|
+
constructor(failure) {
|
|
38
|
+
super(`${failure.path}: ${failure.message}`);
|
|
39
|
+
this.name = "GeneratorDefinitionError";
|
|
40
|
+
this.failure = failure;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var GeneratorDocumentError = class extends TypeError {
|
|
44
|
+
failure;
|
|
45
|
+
constructor(failure) {
|
|
46
|
+
super(`${failure.path}: ${failure.message}`);
|
|
47
|
+
this.name = "GeneratorDocumentError";
|
|
48
|
+
this.failure = failure;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
18
51
|
function isJsonValue(value) {
|
|
19
52
|
return findJsonValueError(value) === void 0;
|
|
20
53
|
}
|
|
21
54
|
function isSchemaVersion(value) {
|
|
22
55
|
return value === 1;
|
|
23
56
|
}
|
|
24
|
-
function
|
|
25
|
-
return
|
|
57
|
+
function isGeneratorDefinition(value) {
|
|
58
|
+
return findGeneratorDefinitionFailure(value) === void 0;
|
|
59
|
+
}
|
|
60
|
+
function isDocument(value) {
|
|
61
|
+
return findDocumentFailure(value) === void 0;
|
|
26
62
|
}
|
|
27
63
|
function assertJsonValue(value, path = "$") {
|
|
28
64
|
const error = findJsonValueError(value, path);
|
|
@@ -32,21 +68,134 @@ function assertSchemaVersion(value, path = "$.schemaVersion") {
|
|
|
32
68
|
const failure = findSchemaVersionValueFailure(value, path);
|
|
33
69
|
if (failure !== void 0) throw new SchemaVersionError(failure);
|
|
34
70
|
}
|
|
35
|
-
function
|
|
36
|
-
const failure =
|
|
37
|
-
if (failure !== void 0) throw new
|
|
38
|
-
|
|
71
|
+
function assertGeneratorDefinition(value, path = "$") {
|
|
72
|
+
const failure = findGeneratorDefinitionFailure(value, path);
|
|
73
|
+
if (failure !== void 0) throw new GeneratorDefinitionError(failure);
|
|
74
|
+
}
|
|
75
|
+
function assertDocument(value, path = "$") {
|
|
76
|
+
const failure = findDocumentFailure(value, path);
|
|
77
|
+
if (failure !== void 0) throw new GeneratorDocumentError(failure);
|
|
78
|
+
}
|
|
79
|
+
function parseDocument(value, path = "$") {
|
|
80
|
+
assertDocument(value, path);
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
function safeParseDocument(value, path = "$") {
|
|
84
|
+
const failure = findDocumentFailure(value, path);
|
|
85
|
+
return failure === void 0 ? {
|
|
86
|
+
success: true,
|
|
87
|
+
value
|
|
88
|
+
} : {
|
|
89
|
+
success: false,
|
|
90
|
+
failure
|
|
91
|
+
};
|
|
39
92
|
}
|
|
40
93
|
function findJsonValueError(value, path = "$") {
|
|
41
94
|
return findJsonValueErrorInternal(value, path, /* @__PURE__ */ new Set());
|
|
42
95
|
}
|
|
96
|
+
function findGeneratorDefinitionFailure(value, path = "$") {
|
|
97
|
+
const jsonError = findJsonValueError(value, path);
|
|
98
|
+
if (jsonError !== void 0) return definitionFailure("generator_definition_not_json", jsonError.path, jsonError.reason);
|
|
99
|
+
if (!isJsonRecord(value)) return definitionFailure("generator_definition_not_object", path);
|
|
100
|
+
if (!Object.hasOwn(value, "type")) return definitionFailure("generator_type_missing", appendPathSegment(path, "type"));
|
|
101
|
+
if (typeof value.type !== "string" || value.type.trim().length === 0) return definitionFailure("generator_type_invalid", appendPathSegment(path, "type"));
|
|
102
|
+
const metadataKey = Object.keys(value).find((key) => key !== "type" && DOCUMENT_METADATA_KEYS.has(key));
|
|
103
|
+
if (metadataKey !== void 0) return definitionFailure("definition_document_metadata", appendPathSegment(path, metadataKey));
|
|
104
|
+
const nestedMetadataPath = findNestedDefinitionMetadataPath(value, path);
|
|
105
|
+
return nestedMetadataPath === void 0 ? void 0 : definitionFailure("definition_document_metadata", nestedMetadataPath);
|
|
106
|
+
}
|
|
107
|
+
function findDocumentFailure(value, path = "$") {
|
|
108
|
+
const jsonError = findJsonValueError(value, path);
|
|
109
|
+
if (jsonError !== void 0) return documentFailure("generator_document_not_json", jsonError.path, jsonError.reason);
|
|
110
|
+
if (!isJsonRecord(value)) return documentFailure("generator_document_not_object", path);
|
|
111
|
+
if (Object.hasOwn(value, "configuration") && Object.hasOwn(value, "type")) return documentFailure("configuration_envelope_removed", path);
|
|
112
|
+
const unknownKey = Object.keys(value).find((key) => !GENERATOR_DOCUMENT_TOP_LEVEL_KEYS.includes(key));
|
|
113
|
+
if (unknownKey !== void 0) return documentFailure("top_level_property_unknown", appendPathSegment(path, unknownKey), `Unknown top-level property: ${unknownKey}`);
|
|
114
|
+
const versionFailure = findSchemaVersionFailure(value, path);
|
|
115
|
+
if (versionFailure !== void 0) return versionFailure;
|
|
116
|
+
for (const property of ["name", "description"]) if (Object.hasOwn(value, property) && typeof value[property] !== "string") return documentFailure(property === "name" ? "name_invalid" : "description_invalid", appendPathSegment(path, property));
|
|
117
|
+
if (!Object.hasOwn(value, "definition")) return documentFailure("definition_missing", appendPathSegment(path, "definition"));
|
|
118
|
+
return findGeneratorDefinitionFailure(value.definition, appendPathSegment(path, "definition"));
|
|
119
|
+
}
|
|
43
120
|
function findSchemaVersionFailure(value, path = "$") {
|
|
44
|
-
if (!isJsonRecord(value) || !Object.hasOwn(value, "schemaVersion")) return createSchemaVersionFailure("schema_version_missing",
|
|
121
|
+
if (!isJsonRecord(value) || !Object.hasOwn(value, "schemaVersion")) return createSchemaVersionFailure("schema_version_missing", appendPathSegment(path, "schemaVersion"));
|
|
45
122
|
return findSchemaVersionValueFailure(value.schemaVersion, appendPathSegment(path, "schemaVersion"));
|
|
46
123
|
}
|
|
47
124
|
function findSchemaVersionValueFailure(value, path = "$.schemaVersion") {
|
|
48
|
-
|
|
49
|
-
|
|
125
|
+
return isSchemaVersion(value) ? void 0 : createSchemaVersionFailure("schema_version_unsupported", path);
|
|
126
|
+
}
|
|
127
|
+
function createSchemaVersionFailure(code, path) {
|
|
128
|
+
return {
|
|
129
|
+
code,
|
|
130
|
+
message: code === "schema_version_missing" ? `schemaVersion is required and must be 1` : `schemaVersion must be 1`,
|
|
131
|
+
path,
|
|
132
|
+
severity: "error",
|
|
133
|
+
supportedVersions: SUPPORTED_SCHEMA_VERSIONS
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function definitionFailure(code, path, message) {
|
|
137
|
+
return {
|
|
138
|
+
code,
|
|
139
|
+
message: message ?? {
|
|
140
|
+
generator_definition_not_json: "generator definition must be portable JSON data",
|
|
141
|
+
generator_definition_not_object: "generator definition must be a JSON object",
|
|
142
|
+
generator_type_missing: "type is required",
|
|
143
|
+
generator_type_invalid: "type must be a non-empty string",
|
|
144
|
+
definition_document_metadata: "document metadata is not allowed in a generator definition"
|
|
145
|
+
}[code],
|
|
146
|
+
path,
|
|
147
|
+
severity: "error"
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function documentFailure(code, path, message) {
|
|
151
|
+
return {
|
|
152
|
+
code,
|
|
153
|
+
message: message ?? {
|
|
154
|
+
generator_document_not_json: "generator document must be portable JSON data",
|
|
155
|
+
generator_document_not_object: "generator document must be a JSON object",
|
|
156
|
+
generator_definition_not_json: "generator definition must be portable JSON data",
|
|
157
|
+
generator_definition_not_object: "generator definition must be a JSON object",
|
|
158
|
+
generator_type_missing: "type is required",
|
|
159
|
+
generator_type_invalid: "type must be a non-empty string",
|
|
160
|
+
definition_document_metadata: "document metadata is not allowed in a generator definition",
|
|
161
|
+
definition_missing: "definition is required",
|
|
162
|
+
name_invalid: "name must be a string when present",
|
|
163
|
+
description_invalid: "description must be a string when present",
|
|
164
|
+
top_level_property_unknown: "unknown top-level properties are not allowed",
|
|
165
|
+
configuration_envelope_removed: "The configuration envelope was removed; put generator fields directly inside definition."
|
|
166
|
+
}[code],
|
|
167
|
+
path,
|
|
168
|
+
severity: "error"
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function appendPathSegment(path, segment) {
|
|
172
|
+
return path === "$" ? `$.${segment}` : `${path}.${segment}`;
|
|
173
|
+
}
|
|
174
|
+
function findNestedDefinitionMetadataPath(value, path) {
|
|
175
|
+
for (const [key, child] of Object.entries(value)) {
|
|
176
|
+
if (key === "type") continue;
|
|
177
|
+
const metadataPath = findDefinitionMetadataPath(child, appendPathSegment(path, key));
|
|
178
|
+
if (metadataPath !== void 0) return metadataPath;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function findDefinitionMetadataPath(value, path) {
|
|
182
|
+
if (Array.isArray(value)) {
|
|
183
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
184
|
+
const metadataPath = findDefinitionMetadataPath(value[index], `${path}[${index}]`);
|
|
185
|
+
if (metadataPath !== void 0) return metadataPath;
|
|
186
|
+
}
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (!isJsonRecord(value)) return void 0;
|
|
190
|
+
if (typeof value.type === "string") {
|
|
191
|
+
const metadataKey = Object.keys(value).find((key) => key !== "type" && DOCUMENT_METADATA_KEYS.has(key));
|
|
192
|
+
if (metadataKey !== void 0) return appendPathSegment(path, metadataKey);
|
|
193
|
+
}
|
|
194
|
+
return findNestedDefinitionMetadataPath(value, path);
|
|
195
|
+
}
|
|
196
|
+
function isJsonRecord(value) {
|
|
197
|
+
const prototype = typeof value === "object" && value !== null ? Object.getPrototypeOf(value) : void 0;
|
|
198
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && (prototype === null || prototype === Object.prototype);
|
|
50
199
|
}
|
|
51
200
|
function findJsonValueErrorInternal(value, path, ancestors) {
|
|
52
201
|
switch (typeof value) {
|
|
@@ -57,14 +206,11 @@ function findJsonValueErrorInternal(value, path, ancestors) {
|
|
|
57
206
|
path,
|
|
58
207
|
reason: "number must be finite"
|
|
59
208
|
};
|
|
60
|
-
|
|
209
|
+
return Object.is(value, -0) ? {
|
|
61
210
|
path,
|
|
62
211
|
reason: "number must not be negative zero"
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
case "object":
|
|
66
|
-
if (value === null) return;
|
|
67
|
-
return findJsonObjectError(value, path, ancestors);
|
|
212
|
+
} : void 0;
|
|
213
|
+
case "object": return value === null ? void 0 : findJsonObjectError(value, path, ancestors);
|
|
68
214
|
case "bigint":
|
|
69
215
|
case "function":
|
|
70
216
|
case "symbol":
|
|
@@ -74,28 +220,12 @@ function findJsonValueErrorInternal(value, path, ancestors) {
|
|
|
74
220
|
};
|
|
75
221
|
}
|
|
76
222
|
}
|
|
77
|
-
function createSchemaVersionFailure(code, options) {
|
|
78
|
-
return {
|
|
79
|
-
code,
|
|
80
|
-
message: code === "schema_version_missing" ? `schemaVersion is required and must be 1` : `schemaVersion must be 1`,
|
|
81
|
-
path: options.path,
|
|
82
|
-
severity: "error",
|
|
83
|
-
supportedVersions: SUPPORTED_SCHEMA_VERSIONS
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
function appendPathSegment(path, segment) {
|
|
87
|
-
return path === "$" ? `$.${segment}` : `${path}.${segment}`;
|
|
88
|
-
}
|
|
89
|
-
function isJsonRecord(value) {
|
|
90
|
-
const prototype = typeof value === "object" && value !== null ? Object.getPrototypeOf(value) : void 0;
|
|
91
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) && (prototype === null || prototype === Object.prototype);
|
|
92
|
-
}
|
|
93
223
|
function findJsonObjectError(value, path, ancestors) {
|
|
94
224
|
if (ancestors.has(value)) return {
|
|
95
225
|
path,
|
|
96
226
|
reason: "cyclic objects are not JSON-compatible"
|
|
97
227
|
};
|
|
98
|
-
if (
|
|
228
|
+
if ("toJSON" in value && typeof value.toJSON === "function") return {
|
|
99
229
|
path,
|
|
100
230
|
reason: "objects with toJSON behavior are not portable"
|
|
101
231
|
};
|
|
@@ -104,17 +234,14 @@ function findJsonObjectError(value, path, ancestors) {
|
|
|
104
234
|
ancestors.delete(value);
|
|
105
235
|
return error;
|
|
106
236
|
}
|
|
107
|
-
function hasCallableToJson(value) {
|
|
108
|
-
return "toJSON" in value && typeof value.toJSON === "function";
|
|
109
|
-
}
|
|
110
237
|
function findJsonArrayError(value, path, ancestors) {
|
|
111
238
|
const extraProperty = Object.keys(value).find((key) => !isArrayIndexKey(key));
|
|
112
239
|
if (extraProperty !== void 0) return {
|
|
113
240
|
path: `${path}.${extraProperty}`,
|
|
114
241
|
reason: "array object properties would be omitted from JSON"
|
|
115
242
|
};
|
|
116
|
-
const
|
|
117
|
-
if (
|
|
243
|
+
const propertyError = findUnsupportedOwnProperty(value, path, ["length"]);
|
|
244
|
+
if (propertyError !== void 0) return propertyError;
|
|
118
245
|
for (let index = 0; index < value.length; index += 1) {
|
|
119
246
|
if (!(index in value)) return {
|
|
120
247
|
path: `${path}[${index}]`,
|
|
@@ -134,32 +261,35 @@ function findJsonRecordError(value, path, ancestors) {
|
|
|
134
261
|
path,
|
|
135
262
|
reason: "object must be a plain JSON record"
|
|
136
263
|
};
|
|
137
|
-
const
|
|
138
|
-
if (
|
|
264
|
+
const propertyError = findUnsupportedOwnProperty(value, path);
|
|
265
|
+
if (propertyError !== void 0) return propertyError;
|
|
139
266
|
for (const key of Object.keys(value)) {
|
|
140
267
|
const itemError = findJsonValueErrorInternal(value[key], `${path}.${key}`, ancestors);
|
|
141
268
|
if (itemError !== void 0) return itemError;
|
|
142
269
|
}
|
|
143
270
|
}
|
|
144
271
|
function findUnsupportedOwnProperty(value, path, allowedNonEnumerableProperties = []) {
|
|
272
|
+
if (Object.hasOwn(value, "__proto__")) return {
|
|
273
|
+
path: appendPathSegment(path, "__proto__"),
|
|
274
|
+
reason: "__proto__ keys are not portable JSON data"
|
|
275
|
+
};
|
|
145
276
|
if (Object.getOwnPropertySymbols(value).length > 0) return {
|
|
146
277
|
path,
|
|
147
278
|
reason: "symbol keys are not JSON-compatible"
|
|
148
279
|
};
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
280
|
+
const allowed = new Set(allowedNonEnumerableProperties);
|
|
281
|
+
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
|
|
152
282
|
if ("get" in descriptor || "set" in descriptor) return {
|
|
153
283
|
path: `${path}.${key}`,
|
|
154
284
|
reason: "accessor properties are not portable JSON data"
|
|
155
285
|
};
|
|
156
|
-
if (!descriptor.enumerable && !
|
|
286
|
+
if (!descriptor.enumerable && !allowed.has(key)) return {
|
|
157
287
|
path: `${path}.${key}`,
|
|
158
288
|
reason: "non-enumerable properties would be omitted from JSON"
|
|
159
289
|
};
|
|
160
290
|
}
|
|
161
291
|
}
|
|
162
292
|
//#endregion
|
|
163
|
-
export { CURRENT_SCHEMA_VERSION, JsonValueError, SUPPORTED_SCHEMA_VERSIONS, SchemaVersionError, assertJsonValue, assertSchemaVersion,
|
|
293
|
+
export { CURRENT_SCHEMA_VERSION, GENERATOR_DOCUMENT_TOP_LEVEL_KEYS, GeneratorDefinitionError, GeneratorDocumentError, JsonValueError, SUPPORTED_SCHEMA_VERSIONS, SchemaVersionError, assertDocument, assertGeneratorDefinition, assertJsonValue, assertSchemaVersion, findDocumentFailure, findGeneratorDefinitionFailure, findJsonValueError, findSchemaVersionFailure, findSchemaVersionValueFailure, isDocument, isGeneratorDefinition, isJsonValue, isSchemaVersion, parseDocument, safeParseDocument };
|
|
164
294
|
|
|
165
295
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export type JsonPrimitive = boolean | null | number | string;\n\nexport type JsonValue = JsonArray | JsonObject | JsonPrimitive;\n\nexport type JsonArray = readonly JsonValue[];\n\nexport type JsonObject = {\n readonly [key: string]: JsonValue;\n};\n\nexport const CURRENT_SCHEMA_VERSION = 1;\n\nexport const SUPPORTED_SCHEMA_VERSIONS = [CURRENT_SCHEMA_VERSION] as const;\n\nexport type SchemaVersion = (typeof SUPPORTED_SCHEMA_VERSIONS)[number];\n\nexport type VersionedDefinition = JsonObject & {\n readonly schemaVersion: SchemaVersion;\n};\n\nexport type SchemaVersionFailureCode =\n | \"schema_version_missing\"\n | \"schema_version_unsupported\";\n\nexport type SchemaVersionFailure = {\n readonly code: SchemaVersionFailureCode;\n readonly message: string;\n readonly path: string;\n readonly severity: \"error\";\n readonly supportedVersions: readonly SchemaVersion[];\n};\n\nexport class JsonValueError extends TypeError {\n constructor(path: string, reason: string) {\n super(`${path}: ${reason}`);\n this.name = \"JsonValueError\";\n }\n}\n\nexport class SchemaVersionError extends TypeError {\n readonly failure: SchemaVersionFailure;\n\n constructor(failure: SchemaVersionFailure) {\n super(`${failure.path}: ${failure.message}`);\n this.name = \"SchemaVersionError\";\n this.failure = failure;\n }\n}\n\nexport function isJsonValue(value: unknown): value is JsonValue {\n return findJsonValueError(value) === undefined;\n}\n\nexport function isSchemaVersion(value: unknown): value is SchemaVersion {\n return value === CURRENT_SCHEMA_VERSION;\n}\n\nexport function isVersionedDefinition(\n value: unknown,\n): value is VersionedDefinition {\n return (\n findSchemaVersionFailure(value) === undefined &&\n isJsonRecord(value) &&\n isJsonValue(value)\n );\n}\n\nexport function assertJsonValue(\n value: unknown,\n path = \"$\",\n): asserts value is JsonValue {\n const error = findJsonValueError(value, path);\n\n if (error !== undefined) {\n throw new JsonValueError(error.path, error.reason);\n }\n}\n\nexport function assertSchemaVersion(\n value: unknown,\n path = \"$.schemaVersion\",\n): asserts value is SchemaVersion {\n const failure = findSchemaVersionValueFailure(value, path);\n\n if (failure !== undefined) {\n throw new SchemaVersionError(failure);\n }\n}\n\nexport function assertVersionedDefinition(\n value: unknown,\n path = \"$\",\n): asserts value is VersionedDefinition {\n const failure = findSchemaVersionFailure(value, path);\n\n if (failure !== undefined) {\n throw new SchemaVersionError(failure);\n }\n\n assertJsonValue(value, path);\n}\n\nexport function findJsonValueError(\n value: unknown,\n path = \"$\",\n): { path: string; reason: string } | undefined {\n return findJsonValueErrorInternal(value, path, new Set());\n}\n\nexport function findSchemaVersionFailure(\n value: unknown,\n path = \"$\",\n): SchemaVersionFailure | undefined {\n if (!isJsonRecord(value) || !Object.hasOwn(value, \"schemaVersion\")) {\n return createSchemaVersionFailure(\"schema_version_missing\", {\n path: appendPathSegment(path, \"schemaVersion\"),\n });\n }\n\n return findSchemaVersionValueFailure(\n value.schemaVersion,\n appendPathSegment(path, \"schemaVersion\"),\n );\n}\n\nexport function findSchemaVersionValueFailure(\n value: unknown,\n path = \"$.schemaVersion\",\n): SchemaVersionFailure | undefined {\n if (isSchemaVersion(value)) {\n return undefined;\n }\n\n return createSchemaVersionFailure(\"schema_version_unsupported\", { path });\n}\n\nfunction findJsonValueErrorInternal(\n value: unknown,\n path: string,\n ancestors: Set<object>,\n): { path: string; reason: string } | undefined {\n switch (typeof value) {\n case \"boolean\":\n case \"string\":\n return undefined;\n case \"number\":\n if (!Number.isFinite(value)) {\n return { path, reason: \"number must be finite\" };\n }\n if (Object.is(value, -0)) {\n return { path, reason: \"number must not be negative zero\" };\n }\n return undefined;\n case \"object\":\n if (value === null) {\n return undefined;\n }\n return findJsonObjectError(value, path, ancestors);\n case \"bigint\":\n case \"function\":\n case \"symbol\":\n case \"undefined\":\n return { path, reason: `${typeof value} is not JSON-compatible` };\n }\n}\n\nfunction createSchemaVersionFailure(\n code: SchemaVersionFailureCode,\n options: { readonly path: string },\n): SchemaVersionFailure {\n return {\n code,\n message:\n code === \"schema_version_missing\"\n ? `schemaVersion is required and must be ${CURRENT_SCHEMA_VERSION}`\n : `schemaVersion must be ${CURRENT_SCHEMA_VERSION}`,\n path: options.path,\n severity: \"error\",\n supportedVersions: SUPPORTED_SCHEMA_VERSIONS,\n };\n}\n\nfunction appendPathSegment(path: string, segment: string) {\n return path === \"$\" ? `$.${segment}` : `${path}.${segment}`;\n}\n\nfunction isJsonRecord(value: unknown): value is Record<string, unknown> {\n const prototype =\n typeof value === \"object\" && value !== null\n ? Object.getPrototypeOf(value)\n : undefined;\n\n return (\n typeof value === \"object\" &&\n value !== null &&\n !Array.isArray(value) &&\n (prototype === null || prototype === Object.prototype)\n );\n}\n\nfunction findJsonObjectError(\n value: object,\n path: string,\n ancestors: Set<object>,\n): { path: string; reason: string } | undefined {\n if (ancestors.has(value)) {\n return { path, reason: \"cyclic objects are not JSON-compatible\" };\n }\n\n if (hasCallableToJson(value)) {\n return { path, reason: \"objects with toJSON behavior are not portable\" };\n }\n\n ancestors.add(value);\n const error = Array.isArray(value)\n ? findJsonArrayError(value, path, ancestors)\n : findJsonRecordError(value, path, ancestors);\n ancestors.delete(value);\n\n return error;\n}\n\nfunction hasCallableToJson(value: object) {\n return (\n \"toJSON\" in value &&\n typeof (value as { readonly toJSON?: unknown }).toJSON === \"function\"\n );\n}\n\nfunction findJsonArrayError(\n value: readonly unknown[],\n path: string,\n ancestors: Set<object>,\n): { path: string; reason: string } | undefined {\n const extraProperty = Object.keys(value).find((key) => !isArrayIndexKey(key));\n\n if (extraProperty !== undefined) {\n return {\n path: `${path}.${extraProperty}`,\n reason: \"array object properties would be omitted from JSON\",\n };\n }\n\n const ownPropertyError = findUnsupportedOwnProperty(value, path, [\"length\"]);\n\n if (ownPropertyError !== undefined) {\n return ownPropertyError;\n }\n\n for (let index = 0; index < value.length; index += 1) {\n if (!(index in value)) {\n return {\n path: `${path}[${index}]`,\n reason: \"sparse array slots are not JSON-compatible\",\n };\n }\n\n const itemError = findJsonValueErrorInternal(\n value[index],\n `${path}[${index}]`,\n ancestors,\n );\n\n if (itemError !== undefined) {\n return itemError;\n }\n }\n\n return undefined;\n}\n\nfunction isArrayIndexKey(key: string) {\n const index = Number(key);\n\n return (\n Number.isInteger(index) &&\n index >= 0 &&\n index < 2 ** 32 - 1 &&\n String(index) === key\n );\n}\n\nfunction findJsonRecordError(\n value: object,\n path: string,\n ancestors: Set<object>,\n): { path: string; reason: string } | undefined {\n const prototype = Object.getPrototypeOf(value);\n\n if (prototype !== null && prototype !== Object.prototype) {\n return { path, reason: \"object must be a plain JSON record\" };\n }\n\n const ownPropertyError = findUnsupportedOwnProperty(value, path);\n\n if (ownPropertyError !== undefined) {\n return ownPropertyError;\n }\n\n for (const key of Object.keys(value)) {\n const itemError = findJsonValueErrorInternal(\n (value as Record<string, unknown>)[key],\n `${path}.${key}`,\n ancestors,\n );\n\n if (itemError !== undefined) {\n return itemError;\n }\n }\n\n return undefined;\n}\n\nfunction findUnsupportedOwnProperty(\n value: object,\n path: string,\n allowedNonEnumerableProperties: readonly string[] = [],\n): { path: string; reason: string } | undefined {\n if (Object.getOwnPropertySymbols(value).length > 0) {\n return { path, reason: \"symbol keys are not JSON-compatible\" };\n }\n\n const allowedNonEnumerable = new Set(allowedNonEnumerableProperties);\n const descriptors = Object.getOwnPropertyDescriptors(value);\n\n for (const [key, descriptor] of Object.entries(descriptors)) {\n if (\"get\" in descriptor || \"set\" in descriptor) {\n return {\n path: `${path}.${key}`,\n reason: \"accessor properties are not portable JSON data\",\n };\n }\n\n if (!descriptor.enumerable && !allowedNonEnumerable.has(key)) {\n return {\n path: `${path}.${key}`,\n reason: \"non-enumerable properties would be omitted from JSON\",\n };\n }\n }\n\n return undefined;\n}\n"],"mappings":";AAUA,MAAa,yBAAyB;AAEtC,MAAa,4BAA4B,CAAA,CAAuB;AAoBhE,IAAa,iBAAb,cAAoC,UAAU;CAC5C,YAAY,MAAc,QAAgB;EACxC,MAAM,GAAG,KAAK,IAAI,QAAQ;EAC1B,KAAK,OAAO;CACd;AACF;AAEA,IAAa,qBAAb,cAAwC,UAAU;CAChD;CAEA,YAAY,SAA+B;EACzC,MAAM,GAAG,QAAQ,KAAK,IAAI,QAAQ,SAAS;EAC3C,KAAK,OAAO;EACZ,KAAK,UAAU;CACjB;AACF;AAEA,SAAgB,YAAY,OAAoC;CAC9D,OAAO,mBAAmB,KAAK,MAAM,KAAA;AACvC;AAEA,SAAgB,gBAAgB,OAAwC;CACtE,OAAO,UAAA;AACT;AAEA,SAAgB,sBACd,OAC8B;CAC9B,OACE,yBAAyB,KAAK,MAAM,KAAA,KACpC,aAAa,KAAK,KAClB,YAAY,KAAK;AAErB;AAEA,SAAgB,gBACd,OACA,OAAO,KACqB;CAC5B,MAAM,QAAQ,mBAAmB,OAAO,IAAI;CAE5C,IAAI,UAAU,KAAA,GACZ,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,GAAG;GACjB,QAAQ;EACV;CAEJ;AAGF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export type JsonPrimitive = boolean | null | number | string;\nexport type JsonValue = JsonArray | JsonObject | JsonPrimitive;\nexport type JsonArray = readonly JsonValue[];\nexport type JsonObject = { readonly [key: string]: JsonValue };\n\nexport const CURRENT_SCHEMA_VERSION = 1;\nexport const SUPPORTED_SCHEMA_VERSIONS = [CURRENT_SCHEMA_VERSION] as const;\nexport type SchemaVersion = (typeof SUPPORTED_SCHEMA_VERSIONS)[number];\n\n/** Portable executable generator data. Generator fields live beside `type`. */\nexport type GeneratorDefinition = JsonObject & { readonly type: string };\n\n/** Versioned document containing exactly one root generator definition. */\nexport type GeneratorDocumentV1 = {\n readonly schemaVersion: 1;\n readonly definition: GeneratorDefinition;\n readonly name?: string;\n readonly description?: string;\n};\n\nexport type GeneratorDocument = GeneratorDocumentV1;\n\nexport const GENERATOR_DOCUMENT_TOP_LEVEL_KEYS = [\n \"schemaVersion\",\n \"name\",\n \"description\",\n \"definition\",\n] as const;\n\nconst DOCUMENT_METADATA_KEYS = new Set([\n \"schemaVersion\",\n \"name\",\n \"description\",\n \"owner\",\n \"ownership\",\n \"visibility\",\n \"createdAt\",\n \"updatedAt\",\n \"timestamps\",\n]);\n\nexport type SchemaVersionFailureCode =\n | \"schema_version_missing\"\n | \"schema_version_unsupported\";\nexport type SchemaVersionFailure = {\n readonly code: SchemaVersionFailureCode;\n readonly message: string;\n readonly path: string;\n readonly severity: \"error\";\n readonly supportedVersions: readonly SchemaVersion[];\n};\n\nexport type GeneratorDefinitionFailureCode =\n | \"generator_definition_not_json\"\n | \"generator_definition_not_object\"\n | \"generator_type_missing\"\n | \"generator_type_invalid\"\n | \"definition_document_metadata\";\nexport type GeneratorDefinitionFailure = {\n readonly code: GeneratorDefinitionFailureCode;\n readonly message: string;\n readonly path: string;\n readonly severity: \"error\";\n};\n\nexport type GeneratorDocumentFailureCode =\n | SchemaVersionFailureCode\n | GeneratorDefinitionFailureCode\n | \"generator_document_not_json\"\n | \"generator_document_not_object\"\n | \"definition_missing\"\n | \"name_invalid\"\n | \"description_invalid\"\n | \"top_level_property_unknown\"\n | \"configuration_envelope_removed\";\nexport type GeneratorDocumentFailure =\n | SchemaVersionFailure\n | {\n readonly code: Exclude<\n GeneratorDocumentFailureCode,\n SchemaVersionFailureCode\n >;\n readonly message: string;\n readonly path: string;\n readonly severity: \"error\";\n };\nexport type GeneratorDocumentParseResult =\n | { readonly success: true; readonly value: GeneratorDocumentV1 }\n | { readonly success: false; readonly failure: GeneratorDocumentFailure };\n\nexport class JsonValueError extends TypeError {\n constructor(path: string, reason: string) {\n super(`${path}: ${reason}`);\n this.name = \"JsonValueError\";\n }\n}\n\nexport class SchemaVersionError extends TypeError {\n readonly failure: SchemaVersionFailure;\n constructor(failure: SchemaVersionFailure) {\n super(`${failure.path}: ${failure.message}`);\n this.name = \"SchemaVersionError\";\n this.failure = failure;\n }\n}\n\nexport class GeneratorDefinitionError extends TypeError {\n readonly failure: GeneratorDefinitionFailure;\n constructor(failure: GeneratorDefinitionFailure) {\n super(`${failure.path}: ${failure.message}`);\n this.name = \"GeneratorDefinitionError\";\n this.failure = failure;\n }\n}\n\nexport class GeneratorDocumentError extends TypeError {\n readonly failure: GeneratorDocumentFailure;\n constructor(failure: GeneratorDocumentFailure) {\n super(`${failure.path}: ${failure.message}`);\n this.name = \"GeneratorDocumentError\";\n this.failure = failure;\n }\n}\n\nexport function isJsonValue(value: unknown): value is JsonValue {\n return findJsonValueError(value) === undefined;\n}\nexport function isSchemaVersion(value: unknown): value is SchemaVersion {\n return value === CURRENT_SCHEMA_VERSION;\n}\nexport function isGeneratorDefinition(\n value: unknown,\n): value is GeneratorDefinition {\n return findGeneratorDefinitionFailure(value) === undefined;\n}\nexport function isDocument(value: unknown): value is GeneratorDocumentV1 {\n return findDocumentFailure(value) === undefined;\n}\nexport function assertJsonValue(\n value: unknown,\n path = \"$\",\n): asserts value is JsonValue {\n const error = findJsonValueError(value, path);\n if (error !== undefined) throw new JsonValueError(error.path, error.reason);\n}\nexport function assertSchemaVersion(\n value: unknown,\n path = \"$.schemaVersion\",\n): asserts value is SchemaVersion {\n const failure = findSchemaVersionValueFailure(value, path);\n if (failure !== undefined) throw new SchemaVersionError(failure);\n}\nexport function assertGeneratorDefinition(\n value: unknown,\n path = \"$\",\n): asserts value is GeneratorDefinition {\n const failure = findGeneratorDefinitionFailure(value, path);\n if (failure !== undefined) throw new GeneratorDefinitionError(failure);\n}\nexport function assertDocument(\n value: unknown,\n path = \"$\",\n): asserts value is GeneratorDocumentV1 {\n const failure = findDocumentFailure(value, path);\n if (failure !== undefined) throw new GeneratorDocumentError(failure);\n}\nexport function parseDocument(value: unknown, path = \"$\"): GeneratorDocumentV1 {\n assertDocument(value, path);\n return value;\n}\nexport function safeParseDocument(\n value: unknown,\n path = \"$\",\n): GeneratorDocumentParseResult {\n const failure = findDocumentFailure(value, path);\n return failure === undefined\n ? { success: true, value: value as GeneratorDocumentV1 }\n : { success: false, failure };\n}\n\nexport function findJsonValueError(\n value: unknown,\n path = \"$\",\n): { path: string; reason: string } | undefined {\n return findJsonValueErrorInternal(value, path, new Set());\n}\nexport function findGeneratorDefinitionFailure(\n value: unknown,\n path = \"$\",\n): GeneratorDefinitionFailure | undefined {\n const jsonError = findJsonValueError(value, path);\n if (jsonError !== undefined)\n return definitionFailure(\n \"generator_definition_not_json\",\n jsonError.path,\n jsonError.reason,\n );\n if (!isJsonRecord(value))\n return definitionFailure(\"generator_definition_not_object\", path);\n if (!Object.hasOwn(value, \"type\"))\n return definitionFailure(\n \"generator_type_missing\",\n appendPathSegment(path, \"type\"),\n );\n if (typeof value.type !== \"string\" || value.type.trim().length === 0)\n return definitionFailure(\n \"generator_type_invalid\",\n appendPathSegment(path, \"type\"),\n );\n const metadataKey = Object.keys(value).find(\n (key) => key !== \"type\" && DOCUMENT_METADATA_KEYS.has(key),\n );\n if (metadataKey !== undefined) {\n return definitionFailure(\n \"definition_document_metadata\",\n appendPathSegment(path, metadataKey),\n );\n }\n\n const nestedMetadataPath = findNestedDefinitionMetadataPath(\n value as JsonObject,\n path,\n );\n return nestedMetadataPath === undefined\n ? undefined\n : definitionFailure(\"definition_document_metadata\", nestedMetadataPath);\n}\nexport function findDocumentFailure(\n value: unknown,\n path = \"$\",\n): GeneratorDocumentFailure | undefined {\n const jsonError = findJsonValueError(value, path);\n if (jsonError !== undefined)\n return documentFailure(\n \"generator_document_not_json\",\n jsonError.path,\n jsonError.reason,\n );\n if (!isJsonRecord(value))\n return documentFailure(\"generator_document_not_object\", path);\n if (Object.hasOwn(value, \"configuration\") && Object.hasOwn(value, \"type\"))\n return documentFailure(\"configuration_envelope_removed\", path);\n const unknownKey = Object.keys(value).find(\n (key) => !GENERATOR_DOCUMENT_TOP_LEVEL_KEYS.includes(key as never),\n );\n if (unknownKey !== undefined)\n return documentFailure(\n \"top_level_property_unknown\",\n appendPathSegment(path, unknownKey),\n `Unknown top-level property: ${unknownKey}`,\n );\n const versionFailure = findSchemaVersionFailure(value, path);\n if (versionFailure !== undefined) return versionFailure;\n for (const property of [\"name\", \"description\"] as const) {\n if (Object.hasOwn(value, property) && typeof value[property] !== \"string\")\n return documentFailure(\n property === \"name\" ? \"name_invalid\" : \"description_invalid\",\n appendPathSegment(path, property),\n );\n }\n if (!Object.hasOwn(value, \"definition\"))\n return documentFailure(\n \"definition_missing\",\n appendPathSegment(path, \"definition\"),\n );\n return findGeneratorDefinitionFailure(\n value.definition,\n appendPathSegment(path, \"definition\"),\n );\n}\nexport function findSchemaVersionFailure(\n value: unknown,\n path = \"$\",\n): SchemaVersionFailure | undefined {\n if (!isJsonRecord(value) || !Object.hasOwn(value, \"schemaVersion\"))\n return createSchemaVersionFailure(\n \"schema_version_missing\",\n appendPathSegment(path, \"schemaVersion\"),\n );\n return findSchemaVersionValueFailure(\n value.schemaVersion,\n appendPathSegment(path, \"schemaVersion\"),\n );\n}\nexport function findSchemaVersionValueFailure(\n value: unknown,\n path = \"$.schemaVersion\",\n): SchemaVersionFailure | undefined {\n return isSchemaVersion(value)\n ? undefined\n : createSchemaVersionFailure(\"schema_version_unsupported\", path);\n}\n\nfunction createSchemaVersionFailure(\n code: SchemaVersionFailureCode,\n path: string,\n): SchemaVersionFailure {\n return {\n code,\n message:\n code === \"schema_version_missing\"\n ? `schemaVersion is required and must be ${CURRENT_SCHEMA_VERSION}`\n : `schemaVersion must be ${CURRENT_SCHEMA_VERSION}`,\n path,\n severity: \"error\",\n supportedVersions: SUPPORTED_SCHEMA_VERSIONS,\n };\n}\nfunction definitionFailure(\n code: GeneratorDefinitionFailureCode,\n path: string,\n message?: string,\n): GeneratorDefinitionFailure {\n const messages: Record<GeneratorDefinitionFailureCode, string> = {\n generator_definition_not_json:\n \"generator definition must be portable JSON data\",\n generator_definition_not_object:\n \"generator definition must be a JSON object\",\n generator_type_missing: \"type is required\",\n generator_type_invalid: \"type must be a non-empty string\",\n definition_document_metadata:\n \"document metadata is not allowed in a generator definition\",\n };\n return { code, message: message ?? messages[code], path, severity: \"error\" };\n}\nfunction documentFailure(\n code: Exclude<GeneratorDocumentFailureCode, SchemaVersionFailureCode>,\n path: string,\n message?: string,\n): Exclude<GeneratorDocumentFailure, SchemaVersionFailure> {\n const messages: Record<\n Exclude<GeneratorDocumentFailureCode, SchemaVersionFailureCode>,\n string\n > = {\n generator_document_not_json:\n \"generator document must be portable JSON data\",\n generator_document_not_object: \"generator document must be a JSON object\",\n generator_definition_not_json:\n \"generator definition must be portable JSON data\",\n generator_definition_not_object:\n \"generator definition must be a JSON object\",\n generator_type_missing: \"type is required\",\n generator_type_invalid: \"type must be a non-empty string\",\n definition_document_metadata:\n \"document metadata is not allowed in a generator definition\",\n definition_missing: \"definition is required\",\n name_invalid: \"name must be a string when present\",\n description_invalid: \"description must be a string when present\",\n top_level_property_unknown: \"unknown top-level properties are not allowed\",\n configuration_envelope_removed:\n \"The configuration envelope was removed; put generator fields directly inside definition.\",\n };\n return { code, message: message ?? messages[code], path, severity: \"error\" };\n}\nfunction appendPathSegment(path: string, segment: string) {\n return path === \"$\" ? `$.${segment}` : `${path}.${segment}`;\n}\n\nfunction findNestedDefinitionMetadataPath(\n value: JsonObject,\n path: string,\n): string | undefined {\n for (const [key, child] of Object.entries(value)) {\n if (key === \"type\") continue;\n\n const childPath = appendPathSegment(path, key);\n const metadataPath = findDefinitionMetadataPath(child, childPath);\n if (metadataPath !== undefined) return metadataPath;\n }\n\n return undefined;\n}\n\nfunction findDefinitionMetadataPath(\n value: JsonValue,\n path: string,\n): string | undefined {\n if (Array.isArray(value)) {\n for (let index = 0; index < value.length; index += 1) {\n const metadataPath = findDefinitionMetadataPath(\n value[index],\n `${path}[${index}]`,\n );\n if (metadataPath !== undefined) return metadataPath;\n }\n return undefined;\n }\n\n if (!isJsonRecord(value)) return undefined;\n\n if (typeof value.type === \"string\") {\n const metadataKey = Object.keys(value).find(\n (key) => key !== \"type\" && DOCUMENT_METADATA_KEYS.has(key),\n );\n if (metadataKey !== undefined) return appendPathSegment(path, metadataKey);\n }\n\n return findNestedDefinitionMetadataPath(value, path);\n}\nfunction isJsonRecord(value: unknown): value is Record<string, unknown> {\n const prototype =\n typeof value === \"object\" && value !== null\n ? Object.getPrototypeOf(value)\n : undefined;\n return (\n typeof value === \"object\" &&\n value !== null &&\n !Array.isArray(value) &&\n (prototype === null || prototype === Object.prototype)\n );\n}\nfunction findJsonValueErrorInternal(\n value: unknown,\n path: string,\n ancestors: Set<object>,\n): { path: string; reason: string } | undefined {\n switch (typeof value) {\n case \"boolean\":\n case \"string\":\n return undefined;\n case \"number\":\n if (!Number.isFinite(value))\n return { path, reason: \"number must be finite\" };\n return Object.is(value, -0)\n ? { path, reason: \"number must not be negative zero\" }\n : undefined;\n case \"object\":\n return value === null\n ? undefined\n : findJsonObjectError(value, path, ancestors);\n case \"bigint\":\n case \"function\":\n case \"symbol\":\n case \"undefined\":\n return { path, reason: `${typeof value} is not JSON-compatible` };\n }\n}\nfunction findJsonObjectError(\n value: object,\n path: string,\n ancestors: Set<object>,\n): { path: string; reason: string } | undefined {\n if (ancestors.has(value))\n return { path, reason: \"cyclic objects are not JSON-compatible\" };\n if (\n \"toJSON\" in value &&\n typeof (value as { readonly toJSON?: unknown }).toJSON === \"function\"\n )\n return { path, reason: \"objects with toJSON behavior are not portable\" };\n ancestors.add(value);\n const error = Array.isArray(value)\n ? findJsonArrayError(value, path, ancestors)\n : findJsonRecordError(value, path, ancestors);\n ancestors.delete(value);\n return error;\n}\nfunction findJsonArrayError(\n value: readonly unknown[],\n path: string,\n ancestors: Set<object>,\n): { path: string; reason: string } | undefined {\n const extraProperty = Object.keys(value).find((key) => !isArrayIndexKey(key));\n if (extraProperty !== undefined)\n return {\n path: `${path}.${extraProperty}`,\n reason: \"array object properties would be omitted from JSON\",\n };\n const propertyError = findUnsupportedOwnProperty(value, path, [\"length\"]);\n if (propertyError !== undefined) return propertyError;\n for (let index = 0; index < value.length; index += 1) {\n if (!(index in value))\n return {\n path: `${path}[${index}]`,\n reason: \"sparse array slots are not JSON-compatible\",\n };\n const itemError = findJsonValueErrorInternal(\n value[index],\n `${path}[${index}]`,\n ancestors,\n );\n if (itemError !== undefined) return itemError;\n }\n return undefined;\n}\nfunction isArrayIndexKey(key: string) {\n const index = Number(key);\n return (\n Number.isInteger(index) &&\n index >= 0 &&\n index < 2 ** 32 - 1 &&\n String(index) === key\n );\n}\nfunction findJsonRecordError(\n value: object,\n path: string,\n ancestors: Set<object>,\n): { path: string; reason: string } | undefined {\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== null && prototype !== Object.prototype)\n return { path, reason: \"object must be a plain JSON record\" };\n const propertyError = findUnsupportedOwnProperty(value, path);\n if (propertyError !== undefined) return propertyError;\n for (const key of Object.keys(value)) {\n const itemError = findJsonValueErrorInternal(\n (value as Record<string, unknown>)[key],\n `${path}.${key}`,\n ancestors,\n );\n if (itemError !== undefined) return itemError;\n }\n return undefined;\n}\nfunction findUnsupportedOwnProperty(\n value: object,\n path: string,\n allowedNonEnumerableProperties: readonly string[] = [],\n): { path: string; reason: string } | undefined {\n if (Object.hasOwn(value, \"__proto__\")) {\n return {\n path: appendPathSegment(path, \"__proto__\"),\n reason: \"__proto__ keys are not portable JSON data\",\n };\n }\n if (Object.getOwnPropertySymbols(value).length > 0)\n return { path, reason: \"symbol keys are not JSON-compatible\" };\n const allowed = new Set(allowedNonEnumerableProperties);\n for (const [key, descriptor] of Object.entries(\n Object.getOwnPropertyDescriptors(value),\n )) {\n if (\"get\" in descriptor || \"set\" in descriptor)\n return {\n path: `${path}.${key}`,\n reason: \"accessor properties are not portable JSON data\",\n };\n if (!descriptor.enumerable && !allowed.has(key))\n return {\n path: `${path}.${key}`,\n reason: \"non-enumerable properties would be omitted from JSON\",\n };\n }\n return undefined;\n}\n"],"mappings":";AAKA,MAAa,yBAAyB;AACtC,MAAa,4BAA4B,CAAA,CAAuB;AAgBhE,MAAa,oCAAoC;CAC/C;CACA;CACA;CACA;AACF;AAEA,MAAM,yCAAyB,IAAI,IAAI;CACrC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAmDD,IAAa,iBAAb,cAAoC,UAAU;CAC5C,YAAY,MAAc,QAAgB;EACxC,MAAM,GAAG,KAAK,IAAI,QAAQ;EAC1B,KAAK,OAAO;CACd;AACF;AAEA,IAAa,qBAAb,cAAwC,UAAU;CAChD;CACA,YAAY,SAA+B;EACzC,MAAM,GAAG,QAAQ,KAAK,IAAI,QAAQ,SAAS;EAC3C,KAAK,OAAO;EACZ,KAAK,UAAU;CACjB;AACF;AAEA,IAAa,2BAAb,cAA8C,UAAU;CACtD;CACA,YAAY,SAAqC;EAC/C,MAAM,GAAG,QAAQ,KAAK,IAAI,QAAQ,SAAS;EAC3C,KAAK,OAAO;EACZ,KAAK,UAAU;CACjB;AACF;AAEA,IAAa,yBAAb,cAA4C,UAAU;CACpD;CACA,YAAY,SAAmC;EAC7C,MAAM,G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