@asaidimu/anansi 4.0.2 → 8.6.2
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 +204 -685
- package/index.cjs +1 -65
- package/index.d.cts +926 -2192
- package/index.d.mts +1081 -0
- package/index.mjs +1 -0
- package/package.json +31 -37
- package/LICENSE.md +0 -21
- package/index.d.ts +0 -2347
- package/index.js +0 -65
package/index.d.mts
ADDED
|
@@ -0,0 +1,1081 @@
|
|
|
1
|
+
import "@asaidimu/query";
|
|
2
|
+
//#region src/schema/generated.d.ts
|
|
3
|
+
type ComparisonOperator = "eq" | "neq" | "lt" | "lte" | "gt" | "gte" | "in" | "nin" | "contains" | "ncontains" | "exists" | "nexists";
|
|
4
|
+
type Constraint = ConstraintMetadata & ConstraintUnion;
|
|
5
|
+
interface ConstraintGroup {
|
|
6
|
+
operator: LogicalOperatorEnum;
|
|
7
|
+
rules: ConstraintUnion[];
|
|
8
|
+
}
|
|
9
|
+
interface ConstraintMetadata {
|
|
10
|
+
description?: string;
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
interface ConstraintRule {
|
|
14
|
+
fields?: String[];
|
|
15
|
+
parameters?: unknown;
|
|
16
|
+
predicate: string;
|
|
17
|
+
}
|
|
18
|
+
type ConstraintUnion = ConstraintRule | ConstraintGroup;
|
|
19
|
+
interface FieldDefinition {
|
|
20
|
+
default?: unknown;
|
|
21
|
+
deprecated?: boolean;
|
|
22
|
+
description?: string;
|
|
23
|
+
metadata?: unknown;
|
|
24
|
+
name: string;
|
|
25
|
+
nullable?: boolean;
|
|
26
|
+
required?: boolean;
|
|
27
|
+
schema?: SchemaReference | SchemaReferenceArray | InlineTypeDescriptor;
|
|
28
|
+
type: FieldType;
|
|
29
|
+
unique?: boolean;
|
|
30
|
+
}
|
|
31
|
+
type FieldType = "unknown" | "string" | "number" | "integer" | "decimal" | "boolean" | "array" | "enum" | "object" | "record" | "union" | "composite" | "geometry" | "bytes";
|
|
32
|
+
interface IndexCondition {
|
|
33
|
+
field: string;
|
|
34
|
+
operator: ComparisonOperator;
|
|
35
|
+
value: unknown;
|
|
36
|
+
}
|
|
37
|
+
interface IndexConditionGroup {
|
|
38
|
+
conditions: IndexConditionUnion[];
|
|
39
|
+
operator: LogicalOperatorEnum;
|
|
40
|
+
}
|
|
41
|
+
type IndexConditionUnion = IndexCondition | IndexConditionGroup;
|
|
42
|
+
interface IndexDefinition {
|
|
43
|
+
condition?: IndexCondition | IndexConditionGroup;
|
|
44
|
+
description?: string;
|
|
45
|
+
fields: String[];
|
|
46
|
+
name: string;
|
|
47
|
+
order?: IndexOrder;
|
|
48
|
+
type: IndexType;
|
|
49
|
+
unique?: boolean;
|
|
50
|
+
}
|
|
51
|
+
type IndexOrder = "asc" | "desc";
|
|
52
|
+
type IndexType = "normal" | "unique" | "primary" | "spatial" | "fulltext";
|
|
53
|
+
interface InlineTypeDescriptor {
|
|
54
|
+
type: InlineTypeKind;
|
|
55
|
+
values?: Unknown[];
|
|
56
|
+
}
|
|
57
|
+
type InlineTypeKind = "string" | "number" | "integer" | "decimal" | "boolean" | "bytes" | "unknown" | "record";
|
|
58
|
+
type LogicalOperatorEnum = "and" | "or" | "not" | "nor" | "xor" | "nand" | "xnor";
|
|
59
|
+
interface NestedSchemaDefinition {
|
|
60
|
+
concrete?: boolean;
|
|
61
|
+
constraints?: Record<string, Constraint>;
|
|
62
|
+
default?: unknown;
|
|
63
|
+
description?: string;
|
|
64
|
+
fields?: Record<string, FieldDefinition>;
|
|
65
|
+
indexes?: Record<string, IndexDefinition>;
|
|
66
|
+
metadata?: unknown;
|
|
67
|
+
name: string;
|
|
68
|
+
schema?: SchemaReference | SchemaReferenceArray | InlineTypeDescriptor;
|
|
69
|
+
type?: FieldType;
|
|
70
|
+
values?: Unknown[];
|
|
71
|
+
}
|
|
72
|
+
interface SchemaReference {
|
|
73
|
+
constraints?: Record<string, Constraint>;
|
|
74
|
+
id: string;
|
|
75
|
+
indexes?: Record<string, IndexDefinition>;
|
|
76
|
+
}
|
|
77
|
+
type SchemaReferenceArray = SchemaReference[];
|
|
78
|
+
type String = string;
|
|
79
|
+
type Unknown = unknown;
|
|
80
|
+
/** Meta-schema defining the structure of schema definitions */
|
|
81
|
+
interface SchemaDefinition {
|
|
82
|
+
constraints?: Record<string, Constraint>;
|
|
83
|
+
description?: string;
|
|
84
|
+
fields?: Record<string, FieldDefinition>;
|
|
85
|
+
indexes?: Record<string, IndexDefinition>;
|
|
86
|
+
metadata?: unknown;
|
|
87
|
+
name: string;
|
|
88
|
+
schemas?: Record<string, NestedSchemaDefinition>;
|
|
89
|
+
version: string;
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/schema/types.d.ts
|
|
93
|
+
/** FieldDefinition plus Go-supported field-level enum `values`. */
|
|
94
|
+
type FieldDef = FieldDefinition & {
|
|
95
|
+
values?: unknown[];
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Parsed literal wrapper — mirrors Go LiteralValue zero/null semantics:
|
|
99
|
+
* absent key → "zero", explicit JSON null → "null".
|
|
100
|
+
*/
|
|
101
|
+
declare class Literal {
|
|
102
|
+
readonly kind: "zero" | "null" | "string" | "integer" | "float" | "boolean" | "object" | "array";
|
|
103
|
+
readonly value: unknown;
|
|
104
|
+
constructor(kind: "zero" | "null" | "string" | "integer" | "float" | "boolean" | "object" | "array", value: unknown);
|
|
105
|
+
isZero(): boolean;
|
|
106
|
+
isNull(): boolean;
|
|
107
|
+
static fromJSON(v: unknown): Literal;
|
|
108
|
+
}
|
|
109
|
+
declare function parseSchema(data: string | SchemaDefinition | Record<string, unknown>): SchemaDefinition;
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/schema/compile.d.ts
|
|
112
|
+
/** Canonical field-type union, straight from the meta schema. */
|
|
113
|
+
type FieldType$2 = FieldType;
|
|
114
|
+
interface ResolvedEnum {
|
|
115
|
+
lookup: Map<string, unknown>;
|
|
116
|
+
complex: unknown[];
|
|
117
|
+
expectNumeric: boolean;
|
|
118
|
+
}
|
|
119
|
+
interface ResolvedNested {
|
|
120
|
+
id: string;
|
|
121
|
+
name: string;
|
|
122
|
+
effectiveType: FieldType$2;
|
|
123
|
+
fields: ResolvedField[];
|
|
124
|
+
isRecursive: boolean;
|
|
125
|
+
values?: unknown[];
|
|
126
|
+
enumDef?: ResolvedEnum;
|
|
127
|
+
}
|
|
128
|
+
interface ResolvedContainer {
|
|
129
|
+
itemSchema?: ResolvedNested;
|
|
130
|
+
itemType?: FieldType$2;
|
|
131
|
+
itemEnum?: ResolvedEnum;
|
|
132
|
+
record: boolean;
|
|
133
|
+
}
|
|
134
|
+
type ResolvedKind = {
|
|
135
|
+
tag: "scalar";
|
|
136
|
+
} | {
|
|
137
|
+
tag: "enum";
|
|
138
|
+
enumDef: ResolvedEnum;
|
|
139
|
+
} | {
|
|
140
|
+
tag: "object";
|
|
141
|
+
schema: ResolvedNested;
|
|
142
|
+
} | {
|
|
143
|
+
tag: "container";
|
|
144
|
+
c: ResolvedContainer;
|
|
145
|
+
} | {
|
|
146
|
+
tag: "union";
|
|
147
|
+
variants: ResolvedNested[];
|
|
148
|
+
} | {
|
|
149
|
+
tag: "composite";
|
|
150
|
+
parts: ResolvedNested[];
|
|
151
|
+
} | {
|
|
152
|
+
tag: "recursive";
|
|
153
|
+
schemaId: string;
|
|
154
|
+
};
|
|
155
|
+
interface ResolvedField {
|
|
156
|
+
id: string;
|
|
157
|
+
name: string;
|
|
158
|
+
path: string;
|
|
159
|
+
type: FieldType$2;
|
|
160
|
+
required: boolean;
|
|
161
|
+
deprecated: boolean;
|
|
162
|
+
unique: boolean;
|
|
163
|
+
nullable: boolean;
|
|
164
|
+
hasDefault: boolean;
|
|
165
|
+
kind: ResolvedKind;
|
|
166
|
+
}
|
|
167
|
+
declare class Compiler {
|
|
168
|
+
readonly source: SchemaDefinition;
|
|
169
|
+
private readonly nested;
|
|
170
|
+
private readonly building;
|
|
171
|
+
constructor(source: SchemaDefinition);
|
|
172
|
+
compile(): {
|
|
173
|
+
root: ResolvedField[];
|
|
174
|
+
schemas: Map<string, ResolvedNested>;
|
|
175
|
+
};
|
|
176
|
+
private compileNested;
|
|
177
|
+
private compileFields;
|
|
178
|
+
private compileField;
|
|
179
|
+
private resolve;
|
|
180
|
+
private require;
|
|
181
|
+
private synthesizeInline;
|
|
182
|
+
}
|
|
183
|
+
declare function buildEnum(values: unknown[], t?: FieldType$2): ResolvedEnum;
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/schema/link.d.ts
|
|
186
|
+
declare const FD_NO_CHILD = 63;
|
|
187
|
+
declare const MAX_SCHEMA_SLOTS = 63;
|
|
188
|
+
declare const MULTI_STEP_BASE: number;
|
|
189
|
+
type FieldKind = 0 | 1 | 2 | 3;
|
|
190
|
+
interface FieldDescriptor {
|
|
191
|
+
raw: number;
|
|
192
|
+
dt: number;
|
|
193
|
+
kind: FieldKind;
|
|
194
|
+
schemaIdx: number;
|
|
195
|
+
fieldIdx: number;
|
|
196
|
+
childSchemaIdx: number;
|
|
197
|
+
terminal: boolean;
|
|
198
|
+
required: boolean;
|
|
199
|
+
hasDefault: boolean;
|
|
200
|
+
deprecated: boolean;
|
|
201
|
+
unique: boolean;
|
|
202
|
+
nullable: boolean;
|
|
203
|
+
recursive: boolean;
|
|
204
|
+
}
|
|
205
|
+
/** Internal DataPoint (side-table identity) — compiled.go:186 formula. */
|
|
206
|
+
declare function internalDP(fd: FieldDescriptor): number;
|
|
207
|
+
declare function makeDescriptor(dt: number, kind: FieldKind, schemaIdx: number, fieldIdx: number, o: {
|
|
208
|
+
required: boolean;
|
|
209
|
+
hasDefault: boolean;
|
|
210
|
+
deprecated: boolean;
|
|
211
|
+
unique: boolean;
|
|
212
|
+
terminal: boolean;
|
|
213
|
+
nullable: boolean;
|
|
214
|
+
recursive: boolean;
|
|
215
|
+
child: number;
|
|
216
|
+
}): FieldDescriptor;
|
|
217
|
+
declare function unpackDescriptor(raw: number): FieldDescriptor;
|
|
218
|
+
interface Slot {
|
|
219
|
+
fieldStart: number;
|
|
220
|
+
fieldCount: number;
|
|
221
|
+
footprint: number;
|
|
222
|
+
}
|
|
223
|
+
interface FieldMeta {
|
|
224
|
+
name: string;
|
|
225
|
+
path: string;
|
|
226
|
+
}
|
|
227
|
+
/** A linked field: everything the wire codec needs. */
|
|
228
|
+
interface LinkedField {
|
|
229
|
+
meta: FieldMeta;
|
|
230
|
+
fd: FieldDescriptor;
|
|
231
|
+
/** Canonical user-data DataPoint written by the Sparse format. */
|
|
232
|
+
dp: number;
|
|
233
|
+
/** Absolute descriptor index across all slots. */
|
|
234
|
+
abs: number;
|
|
235
|
+
/** For array_object fields: the linked child slot's fields. */
|
|
236
|
+
child?: LinkedSlot;
|
|
237
|
+
}
|
|
238
|
+
interface LinkedSlot {
|
|
239
|
+
idx: number;
|
|
240
|
+
slot: Slot;
|
|
241
|
+
fields: LinkedField[];
|
|
242
|
+
}
|
|
243
|
+
interface LinkResult {
|
|
244
|
+
slots: Slot[];
|
|
245
|
+
metas: FieldMeta[];
|
|
246
|
+
descriptors: FieldDescriptor[];
|
|
247
|
+
localOffsets: number[];
|
|
248
|
+
fieldTypes: FieldType$2[];
|
|
249
|
+
root: LinkedSlot;
|
|
250
|
+
/** abs index of each root-level array_object field's linked child */
|
|
251
|
+
childrenByPath: Map<string, LinkedSlot>;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Address computation (address.go computeAddress).
|
|
255
|
+
* steps = [(schemaIdx,fieldIdx), ...] with the LAST step being the leaf.
|
|
256
|
+
*/
|
|
257
|
+
declare function addressForSteps(slots: Slot[], descriptors: FieldDescriptor[], localOffsets: number[], steps: Array<[number, number]>): number;
|
|
258
|
+
/** Canonical Sparse DataPoint for an addressed leaf. */
|
|
259
|
+
declare function userDataDP(dt: number, addr: number): number;
|
|
260
|
+
declare function link(source: SchemaDefinition): LinkResult;
|
|
261
|
+
interface ManifestField {
|
|
262
|
+
/** Field's declared name (relative to its own slot). */
|
|
263
|
+
name: string;
|
|
264
|
+
/** Full dotted mount path from the document root ("address.street"). */
|
|
265
|
+
path: string;
|
|
266
|
+
/** container.DataType name tag. */
|
|
267
|
+
t: string;
|
|
268
|
+
/** Canonical Sparse DataPoint. */
|
|
269
|
+
dp: number;
|
|
270
|
+
/** TypeArrayObject element fields (full mount paths). */
|
|
271
|
+
child?: ManifestField[];
|
|
272
|
+
}
|
|
273
|
+
/** Build the language-neutral wire manifest from linked tables. */
|
|
274
|
+
declare function buildManifest(l: LinkResult): ManifestField[];
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/schema/dt.d.ts
|
|
277
|
+
declare const container: {
|
|
278
|
+
readonly TypeUnknown: 0;
|
|
279
|
+
readonly TypeInt: 1;
|
|
280
|
+
readonly TypeFloat: 2;
|
|
281
|
+
readonly TypeString: 3;
|
|
282
|
+
readonly TypeBool: 4;
|
|
283
|
+
readonly TypeBytes: 5;
|
|
284
|
+
readonly TypeGeometry: 6;
|
|
285
|
+
readonly TypeRecord: 7;
|
|
286
|
+
readonly TypeArrayUnknown: 8;
|
|
287
|
+
readonly TypeArrayInt: 9;
|
|
288
|
+
readonly TypeArrayFloat: 10;
|
|
289
|
+
readonly TypeArrayString: 11;
|
|
290
|
+
readonly TypeArrayBool: 12;
|
|
291
|
+
readonly TypeArrayBytes: 13;
|
|
292
|
+
readonly TypeArrayObject: 14;
|
|
293
|
+
readonly TypeArrayGeometry: 15;
|
|
294
|
+
};
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region src/wire/packet.d.ts
|
|
297
|
+
declare const FLAG_COMPRESSED = 4;
|
|
298
|
+
declare const FLAG_ENCRYPTED = 64;
|
|
299
|
+
declare const FLAG_HASH_PRESENT = 128;
|
|
300
|
+
type EncodeKind = "auto" | "dense" | "sparse";
|
|
301
|
+
declare function encodeDocument(fields: ManifestField[], doc: Record<string, unknown>, fullVersion?: number, kind?: EncodeKind): Uint8Array;
|
|
302
|
+
declare function decodeDocument(data: Uint8Array, fields: ManifestField[]): {
|
|
303
|
+
version: number;
|
|
304
|
+
doc: Record<string, unknown>;
|
|
305
|
+
};
|
|
306
|
+
declare function encodeBatchRows(fields: ManifestField[], docs: Record<string, unknown>[], fullVersion?: number): Uint8Array;
|
|
307
|
+
declare function encodeBatchColumnar(fields: ManifestField[], docs: Record<string, unknown>[], fullVersion?: number): Uint8Array;
|
|
308
|
+
declare function decodeBatch(data: Uint8Array, fields: ManifestField[]): {
|
|
309
|
+
version: number;
|
|
310
|
+
docs: Record<string, unknown>[];
|
|
311
|
+
};
|
|
312
|
+
//#endregion
|
|
313
|
+
//#region src/wire/transforms.d.ts
|
|
314
|
+
interface EncodeTransforms {
|
|
315
|
+
/** Compress the packet body (flags bit 2). */
|
|
316
|
+
compression?: boolean;
|
|
317
|
+
/** Embed BLAKE3-truncated digest over the plaintext body (bit 7). */
|
|
318
|
+
integrity?: boolean;
|
|
319
|
+
/** Seal with AES-256-GCM under this 32-byte key (bit 6). */
|
|
320
|
+
encryptionKey?: Uint8Array;
|
|
321
|
+
}
|
|
322
|
+
interface DecodeTransforms {
|
|
323
|
+
decryptionKey?: Uint8Array;
|
|
324
|
+
}
|
|
325
|
+
/** Full-duplex single-document encode with transforms. */
|
|
326
|
+
declare function encodeAnansiPacket(fields: ManifestField[], doc: Record<string, unknown>, fullVersion?: number, opts?: EncodeTransforms & {
|
|
327
|
+
kind?: EncodeKind;
|
|
328
|
+
}): Promise<Uint8Array>;
|
|
329
|
+
/** Full-duplex single-document decode with transforms. */
|
|
330
|
+
declare function decodeAnansiPacket(data: Uint8Array, fields: ManifestField[], opts?: DecodeTransforms): Promise<{
|
|
331
|
+
version: number;
|
|
332
|
+
doc: Record<string, unknown>;
|
|
333
|
+
}>;
|
|
334
|
+
/** Batch row-oriented encode with transforms. */
|
|
335
|
+
declare function encodeAnansiBatchRows(fields: ManifestField[], docs: Record<string, unknown>[], fullVersion?: number, opts?: EncodeTransforms): Promise<Uint8Array>;
|
|
336
|
+
/**
|
|
337
|
+
* Columnar batch encode. Transforms are supported only on the row paths —
|
|
338
|
+
* columnar ENCODE parity is still pending in TS; pass empty options to emit
|
|
339
|
+
* a plain packet (decoding transformed columnar packets IS supported).
|
|
340
|
+
*/
|
|
341
|
+
/** Columnar batch encode with transforms — full duplex. */
|
|
342
|
+
declare function encodeAnansiBatchColumnar(fields: ManifestField[], docs: Record<string, unknown>[], fullVersion?: number, opts?: EncodeTransforms): Promise<Uint8Array>;
|
|
343
|
+
/** Full-duplex batch decode (row dense/sparse and columnar) with transforms. */
|
|
344
|
+
declare function decodeAnansiBatch(data: Uint8Array, fields: ManifestField[], opts?: DecodeTransforms): Promise<{
|
|
345
|
+
version: number;
|
|
346
|
+
docs: Record<string, unknown>[];
|
|
347
|
+
}>;
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region src/codec.d.ts
|
|
350
|
+
interface AnansiCodecOptions extends EncodeTransforms {
|
|
351
|
+
/** Schema version stamped into outgoing packets (0–1023). */
|
|
352
|
+
fullVersion?: number;
|
|
353
|
+
/** Force Dense/Sparse instead of the density heuristic. */
|
|
354
|
+
kind?: EncodeKind;
|
|
355
|
+
/** Key used to decrypt incoming packets (if the server encrypts). */
|
|
356
|
+
decryptionKey?: Uint8Array;
|
|
357
|
+
}
|
|
358
|
+
declare class AnansiCodec {
|
|
359
|
+
readonly linked: LinkResult;
|
|
360
|
+
readonly fields: ManifestField[];
|
|
361
|
+
readonly fullVersion: number;
|
|
362
|
+
private readonly kind;
|
|
363
|
+
private readonly enc;
|
|
364
|
+
private readonly dec;
|
|
365
|
+
private constructor();
|
|
366
|
+
/**
|
|
367
|
+
* Compile a schema definition and bind it to a codec instance.
|
|
368
|
+
*
|
|
369
|
+
* ```ts
|
|
370
|
+
* const codec = await AnansiCodec.create(schemaJSON); // plain
|
|
371
|
+
* const codec = await AnansiCodec.create(schemaJSON, {
|
|
372
|
+
* fullVersion: 7,
|
|
373
|
+
* transforms: { compression: true, integrity: true },
|
|
374
|
+
* });
|
|
375
|
+
* ```
|
|
376
|
+
*
|
|
377
|
+
* Instances are immutable; cache one per schema version (or per endpoint)
|
|
378
|
+
* and share it freely across requests.
|
|
379
|
+
*/
|
|
380
|
+
static create(schema: string | SchemaDefinition | Record<string, unknown>, opts?: AnansiCodecOptions): Promise<AnansiCodec>;
|
|
381
|
+
/** Encode a single document (Dense/Sparse per configured strategy). */
|
|
382
|
+
encode(doc: Record<string, unknown>): Promise<Uint8Array>;
|
|
383
|
+
/** Decode a single-document packet. Accepts plain and transformed frames. */
|
|
384
|
+
decode(data: Uint8Array): Promise<{
|
|
385
|
+
version: number;
|
|
386
|
+
doc: Record<string, unknown>;
|
|
387
|
+
}>;
|
|
388
|
+
/** Encode many documents as one row-oriented batch. */
|
|
389
|
+
encodeBatch(docs: Record<string, unknown>[]): Promise<Uint8Array>;
|
|
390
|
+
/** Decode any batch packet (row dense/sparse, columnar, transformed). */
|
|
391
|
+
decodeBatch(data: Uint8Array): Promise<{
|
|
392
|
+
version: number;
|
|
393
|
+
docs: Record<string, unknown>[];
|
|
394
|
+
}>;
|
|
395
|
+
/**
|
|
396
|
+
* Columnar batch encode. Note: columnar output with transforms enabled is
|
|
397
|
+
* pending in TypeScript — with transforms unset this emits plain packets.
|
|
398
|
+
*/
|
|
399
|
+
encodeColumnar(docs: Record<string, unknown>[]): Promise<Uint8Array>;
|
|
400
|
+
}
|
|
401
|
+
//#endregion
|
|
402
|
+
//#region src/validation/types/hints.d.ts
|
|
403
|
+
/**
|
|
404
|
+
* hints.ts
|
|
405
|
+
*
|
|
406
|
+
* Defines type hints for generating form input controls based on schema field definitions.
|
|
407
|
+
* Each hint type corresponds to a specific input control, providing metadata for code generation.
|
|
408
|
+
*/
|
|
409
|
+
/**
|
|
410
|
+
* Hints for generating a file input control.
|
|
411
|
+
*/
|
|
412
|
+
type FileHint = {
|
|
413
|
+
type: "file";
|
|
414
|
+
subtype: "video" | "audio" | "image" | "pdf" | "doc" | "txt";
|
|
415
|
+
label?: string;
|
|
416
|
+
embed?: boolean;
|
|
417
|
+
mimes?: string | string[];
|
|
418
|
+
preview?: boolean;
|
|
419
|
+
size?: {
|
|
420
|
+
max?: number;
|
|
421
|
+
min?: number;
|
|
422
|
+
};
|
|
423
|
+
dimensions?: {
|
|
424
|
+
width: number;
|
|
425
|
+
height: number;
|
|
426
|
+
};
|
|
427
|
+
group?: string;
|
|
428
|
+
ignore?: boolean;
|
|
429
|
+
};
|
|
430
|
+
/**
|
|
431
|
+
* Hints for generating a text-based input control.
|
|
432
|
+
*/
|
|
433
|
+
type TextHint = {
|
|
434
|
+
type: "text" | "email" | "tel" | "url" | "textarea";
|
|
435
|
+
label?: string;
|
|
436
|
+
placeholder?: string;
|
|
437
|
+
group?: string;
|
|
438
|
+
ignore?: boolean;
|
|
439
|
+
};
|
|
440
|
+
/**
|
|
441
|
+
* Hints for generating a secret input control (e.g., passwords, API keys).
|
|
442
|
+
*/
|
|
443
|
+
type SecretHint = {
|
|
444
|
+
type: "secret";
|
|
445
|
+
label?: string;
|
|
446
|
+
placeholder?: string;
|
|
447
|
+
password?: boolean;
|
|
448
|
+
group?: string;
|
|
449
|
+
ignore?: boolean;
|
|
450
|
+
};
|
|
451
|
+
/**
|
|
452
|
+
* Hints for generating a number-based input control.
|
|
453
|
+
*/
|
|
454
|
+
type NumberHint = {
|
|
455
|
+
type: "number" | "range" | "integer" | "decimal";
|
|
456
|
+
label?: string;
|
|
457
|
+
step?: number;
|
|
458
|
+
group?: string;
|
|
459
|
+
ignore?: boolean;
|
|
460
|
+
};
|
|
461
|
+
/**
|
|
462
|
+
* Hints for generating a boolean input control.
|
|
463
|
+
*/
|
|
464
|
+
type BooleanHint = {
|
|
465
|
+
type: "checkbox" | "radio";
|
|
466
|
+
label?: string;
|
|
467
|
+
radioLabels?: {
|
|
468
|
+
true: string;
|
|
469
|
+
false: string;
|
|
470
|
+
};
|
|
471
|
+
group?: string;
|
|
472
|
+
ignore?: boolean;
|
|
473
|
+
};
|
|
474
|
+
/**
|
|
475
|
+
* Hints for generating an enum input control.
|
|
476
|
+
*/
|
|
477
|
+
type EnumHint = {
|
|
478
|
+
type: "select" | "radio";
|
|
479
|
+
label?: string;
|
|
480
|
+
group?: string;
|
|
481
|
+
ignore?: boolean;
|
|
482
|
+
options?: Array<{
|
|
483
|
+
value: string | number;
|
|
484
|
+
label: string;
|
|
485
|
+
}>;
|
|
486
|
+
};
|
|
487
|
+
/**
|
|
488
|
+
* Hints for generating an array input control.
|
|
489
|
+
*/
|
|
490
|
+
type ArrayHint = {
|
|
491
|
+
type: "list";
|
|
492
|
+
label?: string;
|
|
493
|
+
itemHint?: {
|
|
494
|
+
type: string;
|
|
495
|
+
};
|
|
496
|
+
group?: string;
|
|
497
|
+
ignore?: boolean;
|
|
498
|
+
};
|
|
499
|
+
/**
|
|
500
|
+
* Hints for generating a set input control.
|
|
501
|
+
*/
|
|
502
|
+
type SetHint = {
|
|
503
|
+
type: "tags";
|
|
504
|
+
label?: string;
|
|
505
|
+
itemHint?: {
|
|
506
|
+
type: string;
|
|
507
|
+
};
|
|
508
|
+
group?: string;
|
|
509
|
+
ignore?: boolean;
|
|
510
|
+
};
|
|
511
|
+
/**
|
|
512
|
+
* Hints for generating an object input control.
|
|
513
|
+
*/
|
|
514
|
+
type ObjectHint = {
|
|
515
|
+
type: "group";
|
|
516
|
+
label?: string;
|
|
517
|
+
collapsible?: boolean;
|
|
518
|
+
group?: string;
|
|
519
|
+
ignore?: boolean;
|
|
520
|
+
};
|
|
521
|
+
/**
|
|
522
|
+
* Hints for generating a date input control.
|
|
523
|
+
*/
|
|
524
|
+
type DateHint = {
|
|
525
|
+
type: "date" | "datetime" | "time";
|
|
526
|
+
label?: string;
|
|
527
|
+
placeholder?: string;
|
|
528
|
+
min?: string;
|
|
529
|
+
max?: string;
|
|
530
|
+
group?: string;
|
|
531
|
+
ignore?: boolean;
|
|
532
|
+
};
|
|
533
|
+
/**
|
|
534
|
+
* Hints for generating a code input control (e.g., for code snippets or scripts).
|
|
535
|
+
*/
|
|
536
|
+
type CodeHint = {
|
|
537
|
+
type: "code";
|
|
538
|
+
label?: string;
|
|
539
|
+
language?: string;
|
|
540
|
+
placeholder?: string;
|
|
541
|
+
readonly?: boolean;
|
|
542
|
+
editorOptions?: {
|
|
543
|
+
lineNumbers?: boolean;
|
|
544
|
+
wordWrap?: boolean;
|
|
545
|
+
minimap?: boolean;
|
|
546
|
+
};
|
|
547
|
+
group?: string;
|
|
548
|
+
ignore?: boolean;
|
|
549
|
+
};
|
|
550
|
+
/**
|
|
551
|
+
* Union type for all possible input hints.
|
|
552
|
+
* Note: DynamicHint removed to avoid overlap with TextHint; use TextHint for generic text needs.
|
|
553
|
+
*/
|
|
554
|
+
type InputHint = FileHint | TextHint | SecretHint | NumberHint | BooleanHint | EnumHint | ArrayHint | SetHint | ObjectHint | DateHint | CodeHint;
|
|
555
|
+
/**
|
|
556
|
+
* Defines metadata for a group of inputs at the schema level.
|
|
557
|
+
*/
|
|
558
|
+
type GroupDefinition = {
|
|
559
|
+
name: string;
|
|
560
|
+
label?: string;
|
|
561
|
+
description?: string;
|
|
562
|
+
};
|
|
563
|
+
/**
|
|
564
|
+
* Defines hints at the schema level, including group metadata.
|
|
565
|
+
*/
|
|
566
|
+
type SchemaHint = {
|
|
567
|
+
groups?: GroupDefinition[];
|
|
568
|
+
};
|
|
569
|
+
//#endregion
|
|
570
|
+
//#region src/validation/types/schema-definition.d.ts
|
|
571
|
+
/**
|
|
572
|
+
* Basic field types supported by the schema system.
|
|
573
|
+
* Matches the `FieldTypeEnum` in the meta‑schema.
|
|
574
|
+
*/
|
|
575
|
+
type FieldType$1 = "unknown" | "string" | "number" | "integer" | "decimal" | "boolean" | "array" | "set" | "enum" | "object" | "record" | "union" | "composite" | "geometry" | "bytes";
|
|
576
|
+
/**
|
|
577
|
+
* Index types for optimizing different query patterns.
|
|
578
|
+
* Matches the `IndexTypeEnum` in the meta‑schema.
|
|
579
|
+
*/
|
|
580
|
+
type IndexType$1 = "normal" | "unique" | "primary" | "spatial" | "fulltext";
|
|
581
|
+
/**
|
|
582
|
+
* Logical operators used in constraint groups and index condition groups.
|
|
583
|
+
* Matches the `LogicalOperatorEnum` in the meta‑schema.
|
|
584
|
+
*/
|
|
585
|
+
type LogicalOperatorEnum$1 = "and" | "or" | "not" | "nor" | "xor" | "nand" | "xnor";
|
|
586
|
+
/**
|
|
587
|
+
* Comparison operators for index conditions.
|
|
588
|
+
* Matches the `ComparisonOperatorEnum` in the meta‑schema.
|
|
589
|
+
*/
|
|
590
|
+
type ComparisonOperator$1 = "eq" | "neq" | "lt" | "lte" | "gt" | "gte" | "in" | "nin" | "contains" | "ncontains" | "exists" | "nexists";
|
|
591
|
+
/**
|
|
592
|
+
* Inline type descriptor kinds.
|
|
593
|
+
* Matches the `InlineTypeEnum` in the meta‑schema.
|
|
594
|
+
*/
|
|
595
|
+
type InlineTypeKind$1 = "string" | "number" | "integer" | "decimal" | "boolean" | "bytes" | "unknown" | "record";
|
|
596
|
+
/**
|
|
597
|
+
* Sort order for index fields.
|
|
598
|
+
* Matches the `IndexOrderEnum` in the meta‑schema.
|
|
599
|
+
*/
|
|
600
|
+
type IndexOrder$1 = "asc" | "desc";
|
|
601
|
+
/**
|
|
602
|
+
* Shared metadata properties for most schema components.
|
|
603
|
+
*/
|
|
604
|
+
interface BaseMetadata extends Record<string, any> {
|
|
605
|
+
description?: string;
|
|
606
|
+
/** Arbitrary key‑value pairs for implementation‑specific metadata. */
|
|
607
|
+
metadata?: Record<string, unknown>;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Metadata for components that also have a human‑readable name.
|
|
611
|
+
*/
|
|
612
|
+
interface NamedMetadata extends BaseMetadata {
|
|
613
|
+
name: string;
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Reference to another schema (e.g., for `object`, `array`, `union` types).
|
|
617
|
+
* May include local overrides for indexes and constraints.
|
|
618
|
+
*/
|
|
619
|
+
interface SchemaReference$1 extends BaseMetadata {
|
|
620
|
+
id: string;
|
|
621
|
+
indexes?: Record<string, IndexDefinition$1>;
|
|
622
|
+
constraints?: Record<string, Constraint$1 | ConstraintGroup$1>;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Inline type descriptor – used when a simple type is defined directly
|
|
626
|
+
* without a separate schema reference.
|
|
627
|
+
*/
|
|
628
|
+
interface InlineTypeDescriptor$1 extends BaseMetadata {
|
|
629
|
+
type: InlineTypeKind$1;
|
|
630
|
+
values?: Array<string | number>;
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Defines a field within a schema.
|
|
634
|
+
* Matches the `Field` schema in the meta‑schema.
|
|
635
|
+
*/
|
|
636
|
+
interface FieldDefinition$1<T = unknown> extends NamedMetadata {
|
|
637
|
+
type: FieldType$1;
|
|
638
|
+
required?: boolean;
|
|
639
|
+
nullable?: boolean;
|
|
640
|
+
deprecated?: boolean;
|
|
641
|
+
unique?: boolean;
|
|
642
|
+
default?: T;
|
|
643
|
+
/**
|
|
644
|
+
* The `schema` property is used for complex types:
|
|
645
|
+
* - For `array`/`set`: a single `SchemaReference` pointing to the item schema.
|
|
646
|
+
* - For `object`: a single `SchemaReference` pointing to the object schema.
|
|
647
|
+
* - For `union`: an array of `SchemaReference`s.
|
|
648
|
+
* - For `enum`: an `InlineTypeDescriptor` (or `values` on the field itself).
|
|
649
|
+
* - For primitive overrides: an `InlineTypeDescriptor`.
|
|
650
|
+
*/
|
|
651
|
+
schema?: SchemaReference$1 | SchemaReference$1[] | InlineTypeDescriptor$1;
|
|
652
|
+
/** @deprecated Use `schema` instead. */
|
|
653
|
+
nestedSchema?: SchemaReference$1;
|
|
654
|
+
hint?: {
|
|
655
|
+
input: InputHint;
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* A single index condition (leaf node).
|
|
660
|
+
* Matches the `IndexCondition` schema in the meta‑schema.
|
|
661
|
+
*/
|
|
662
|
+
interface IndexCondition$1 extends BaseMetadata {
|
|
663
|
+
operator: ComparisonOperator$1;
|
|
664
|
+
field: string;
|
|
665
|
+
value: unknown;
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* A group of index conditions combined with a logical operator.
|
|
669
|
+
* Matches the `IndexConditionGroup` schema in the meta‑schema.
|
|
670
|
+
*/
|
|
671
|
+
interface IndexConditionGroup$1 extends BaseMetadata {
|
|
672
|
+
operator: LogicalOperatorEnum$1;
|
|
673
|
+
conditions: Array<IndexCondition$1 | IndexConditionGroup$1>;
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Defines an index for optimizing queries or enforcing uniqueness.
|
|
677
|
+
* Matches the `Index` schema in the meta‑schema.
|
|
678
|
+
*/
|
|
679
|
+
interface IndexDefinition$1 extends NamedMetadata {
|
|
680
|
+
unique?: boolean;
|
|
681
|
+
type: IndexType$1;
|
|
682
|
+
fields: string[];
|
|
683
|
+
order?: IndexOrder$1;
|
|
684
|
+
condition?: IndexCondition$1 | IndexConditionGroup$1;
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* A predicate‑based constraint rule.
|
|
688
|
+
* Matches the `ConstraintRule` schema in the meta‑schema.
|
|
689
|
+
*/
|
|
690
|
+
interface ConstraintRule$1 extends NamedMetadata {
|
|
691
|
+
predicate: string;
|
|
692
|
+
parameters?: unknown;
|
|
693
|
+
fields?: string[];
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* A group of constraints combined with a logical operator.
|
|
697
|
+
* Matches the `ConstraintGroup` schema in the meta‑schema.
|
|
698
|
+
*/
|
|
699
|
+
interface ConstraintGroup$1 extends NamedMetadata {
|
|
700
|
+
operator: LogicalOperatorEnum$1;
|
|
701
|
+
rules: Array<ConstraintRule$1 | ConstraintGroup$1>;
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* A constraint can be either a single rule or a logical group of rules.
|
|
705
|
+
* Matches the `Constraint` composite in the meta‑schema.
|
|
706
|
+
*/
|
|
707
|
+
type Constraint$1 = ConstraintRule$1 | ConstraintGroup$1;
|
|
708
|
+
/**
|
|
709
|
+
* A reusable nested schema definition.
|
|
710
|
+
* Matches the `NestedSchema` schema in the meta‑schema.
|
|
711
|
+
*
|
|
712
|
+
* A nested schema can be either:
|
|
713
|
+
* - An **object schema** (with `fields`, and optionally `indexes`, `constraints`),
|
|
714
|
+
* - A **primitive type alias** (with `type` and optionally `default`, `values`, `schema`).
|
|
715
|
+
*/
|
|
716
|
+
type NestedSchemaDefinition$1<T = unknown> = NamedMetadata & {
|
|
717
|
+
indexes?: Record<string, IndexDefinition$1>;
|
|
718
|
+
constraints?: Record<string, Constraint$1>;
|
|
719
|
+
} & ({
|
|
720
|
+
/**
|
|
721
|
+
* Object schema: defines the fields of the nested object.
|
|
722
|
+
* The `fields` record maps field IDs to `FieldDefinition`s.
|
|
723
|
+
*/
|
|
724
|
+
fields: Record<string, FieldDefinition$1>;
|
|
725
|
+
} | {
|
|
726
|
+
/**
|
|
727
|
+
* Primitive type alias.
|
|
728
|
+
* The `type` must not be `"object"``.
|
|
729
|
+
*/
|
|
730
|
+
type: Exclude<FieldType$1, "object">;
|
|
731
|
+
default?: T;
|
|
732
|
+
values?: Array<string | number>;
|
|
733
|
+
schema?: SchemaReference$1 | SchemaReference$1[];
|
|
734
|
+
});
|
|
735
|
+
/**
|
|
736
|
+
* Defines a complete schema.
|
|
737
|
+
* Matches the top‑level `Schema` structure in the meta‑schema.
|
|
738
|
+
*/
|
|
739
|
+
interface SchemaDefinition$1 extends NamedMetadata {
|
|
740
|
+
version: string;
|
|
741
|
+
/** Map of field IDs to field definitions. */
|
|
742
|
+
fields: Record<string, FieldDefinition$1>;
|
|
743
|
+
/** Map of index IDs to index definitions. */
|
|
744
|
+
indexes?: Record<string, IndexDefinition$1>;
|
|
745
|
+
/** Map of constraint IDs to constraint definitions. */
|
|
746
|
+
constraints?: Record<string, Constraint$1>;
|
|
747
|
+
/** Map of nested schema IDs to nested schema definitions. */
|
|
748
|
+
schemas?: Record<string, NestedSchemaDefinition$1>;
|
|
749
|
+
/**
|
|
750
|
+
* Optional data migration definitions.
|
|
751
|
+
* @extension
|
|
752
|
+
*/
|
|
753
|
+
migrations?: Array<Migration>;
|
|
754
|
+
/**
|
|
755
|
+
* UI/input hints.
|
|
756
|
+
* @extension
|
|
757
|
+
*/
|
|
758
|
+
hints?: SchemaHint;
|
|
759
|
+
/**
|
|
760
|
+
* Mock data generator.
|
|
761
|
+
* @extension
|
|
762
|
+
*/
|
|
763
|
+
mock?: <T>(
|
|
764
|
+
/** Lazy-typed: @faker-js/faker is a dev-only peer; kept out of bundle. */
|
|
765
|
+
faker: unknown) => Generator<T, void, unknown>;
|
|
766
|
+
/**
|
|
767
|
+
* Domain dependencies.
|
|
768
|
+
* @extension
|
|
769
|
+
*/
|
|
770
|
+
dependencies?: string[];
|
|
771
|
+
/** @deprecated Use `schemas` instead. */
|
|
772
|
+
nestedSchemas?: Record<string, NestedSchemaDefinition$1>;
|
|
773
|
+
/** @deprecated Use top‑level `indexes`, `constraints`, `schemas` directly. */
|
|
774
|
+
registry?: {
|
|
775
|
+
schemas?: Record<string, NestedSchemaDefinition$1>;
|
|
776
|
+
constraints?: Record<string, Constraint$1>;
|
|
777
|
+
indexes?: Record<string, IndexDefinition$1>;
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Implements Partial Update Semantics:
|
|
782
|
+
* - `undefined`: No change to the property.
|
|
783
|
+
* - `null`: Clear/remove the property (if allowed by NonNullable).
|
|
784
|
+
* - `value`: Set the property to the provided value.
|
|
785
|
+
*/
|
|
786
|
+
type Patch<T, NonNullable extends keyof T = never> = { [K in keyof T]?: K extends NonNullable ? T[K] : T[K] | null; };
|
|
787
|
+
type FieldPatch = Patch<FieldDefinition$1, "name" | "type">;
|
|
788
|
+
type ConstraintPatch = Patch<Constraint$1, "name">;
|
|
789
|
+
type IndexPatch = Patch<IndexDefinition$1, "name">;
|
|
790
|
+
type SchemaChange = {
|
|
791
|
+
type: "modifyProperty";
|
|
792
|
+
id: keyof NamedMetadata | "version";
|
|
793
|
+
value: any;
|
|
794
|
+
} | {
|
|
795
|
+
type: "addField";
|
|
796
|
+
id: string;
|
|
797
|
+
definition: FieldDefinition$1;
|
|
798
|
+
} | {
|
|
799
|
+
type: "removeField";
|
|
800
|
+
id: string;
|
|
801
|
+
} | {
|
|
802
|
+
type: "modifyField";
|
|
803
|
+
id: string;
|
|
804
|
+
changes: FieldPatch;
|
|
805
|
+
} | {
|
|
806
|
+
type: "addIndex";
|
|
807
|
+
id: string;
|
|
808
|
+
definition: IndexDefinition$1;
|
|
809
|
+
} | {
|
|
810
|
+
type: "removeIndex";
|
|
811
|
+
id: string;
|
|
812
|
+
} | {
|
|
813
|
+
type: "modifyIndex";
|
|
814
|
+
id: string;
|
|
815
|
+
changes: IndexPatch;
|
|
816
|
+
} | {
|
|
817
|
+
type: "addConstraint";
|
|
818
|
+
id: string;
|
|
819
|
+
constraint: Constraint$1;
|
|
820
|
+
} | {
|
|
821
|
+
type: "removeConstraint";
|
|
822
|
+
id: string;
|
|
823
|
+
} | {
|
|
824
|
+
type: "modifyConstraint";
|
|
825
|
+
id: string;
|
|
826
|
+
changes: ConstraintPatch;
|
|
827
|
+
} | {
|
|
828
|
+
type: "addSchema";
|
|
829
|
+
id: string;
|
|
830
|
+
definition: NestedSchemaDefinition$1;
|
|
831
|
+
} | {
|
|
832
|
+
type: "removeSchema";
|
|
833
|
+
id: string;
|
|
834
|
+
} | {
|
|
835
|
+
type: "modifySchema";
|
|
836
|
+
id: string;
|
|
837
|
+
changes: Array<SchemaChange>;
|
|
838
|
+
};
|
|
839
|
+
type TransformFunction<Initial, Next> = (ctx: any, data: Initial) => Next | Promise<Next>;
|
|
840
|
+
interface DataTransform<Initial, Next> {
|
|
841
|
+
forward: TransformFunction<Initial, Next>;
|
|
842
|
+
backward: TransformFunction<Next, Initial>;
|
|
843
|
+
}
|
|
844
|
+
interface Migration<Initial = any, Next = any> {
|
|
845
|
+
id: string;
|
|
846
|
+
version: {
|
|
847
|
+
source: string;
|
|
848
|
+
target?: string;
|
|
849
|
+
};
|
|
850
|
+
changes: SchemaChange[];
|
|
851
|
+
description: string;
|
|
852
|
+
rollback?: SchemaChange[];
|
|
853
|
+
transform: string | DataTransform<Initial, Next>;
|
|
854
|
+
createdAt: string;
|
|
855
|
+
dependencies?: string[];
|
|
856
|
+
checksum: string;
|
|
857
|
+
}
|
|
858
|
+
//#endregion
|
|
859
|
+
//#region src/validation/types/validator.d.ts
|
|
860
|
+
/** A single validation failure produced by a node. */
|
|
861
|
+
interface Issue {
|
|
862
|
+
/** Machine-readable error code (e.g. "TYPE_MISMATCH", "REQUIRED_FIELD_MISSING"). */
|
|
863
|
+
code: string;
|
|
864
|
+
/** Human-readable description. */
|
|
865
|
+
message: string;
|
|
866
|
+
/** Dot-separated path to the offending value (e.g. "user.address.street"). */
|
|
867
|
+
path: string;
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Controls how strictly the validator interprets missing / unexpected fields.
|
|
871
|
+
*
|
|
872
|
+
* - `strict` — full validation; required, unexpected, type, and constraint issues are all reported.
|
|
873
|
+
* - `partialStrict` — missing-required issues are suppressed; everything else is reported.
|
|
874
|
+
* - `loose` — missing-required *and* unexpected-field issues are both suppressed.
|
|
875
|
+
*/
|
|
876
|
+
type ValidationMode = "strict" | "partialStrict" | "loose";
|
|
877
|
+
interface ValidationConfig {
|
|
878
|
+
/** Maximum nesting depth before aborting recursive traversal. Default: 20. */
|
|
879
|
+
maxDepth: number;
|
|
880
|
+
/** Validation strictness mode. Default: "strict". */
|
|
881
|
+
mode: ValidationMode;
|
|
882
|
+
}
|
|
883
|
+
declare function defaultValidationConfig(): ValidationConfig;
|
|
884
|
+
/** Parameters passed to every predicate invocation. */
|
|
885
|
+
interface PredicateParams {
|
|
886
|
+
/** The original top-level document (never changes across recursive calls). */
|
|
887
|
+
root: Record<string, unknown>;
|
|
888
|
+
/**
|
|
889
|
+
* The data being validated at the current scope.
|
|
890
|
+
* For global constraints this is the full root; for recursive/nested constraints
|
|
891
|
+
* this is the sub-document at the constraint's base path.
|
|
892
|
+
*/
|
|
893
|
+
data: unknown;
|
|
894
|
+
/** Resolved field keys (relative to `data`) that the predicate should inspect. */
|
|
895
|
+
keys: string[];
|
|
896
|
+
/** Arbitrary predicate-specific parameters declared in the schema. */
|
|
897
|
+
parameters?: unknown;
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* A predicate function.
|
|
901
|
+
* Returns an array of Issues (empty = success).
|
|
902
|
+
* May be synchronous or asynchronous.
|
|
903
|
+
*/
|
|
904
|
+
type PredicateFn = (params: PredicateParams) => Issue[] | Promise<Issue[]>;
|
|
905
|
+
/** Map of predicate name → predicate function. */
|
|
906
|
+
type PredicateMap = Record<string, PredicateFn>;
|
|
907
|
+
/**
|
|
908
|
+
* A leaf constraint: a named predicate with optional field paths and parameters.
|
|
909
|
+
* Mirrors Go's `ConstraintRule`.
|
|
910
|
+
*/
|
|
911
|
+
interface ValidatorConstraintRule {
|
|
912
|
+
kind: "rule";
|
|
913
|
+
name: string;
|
|
914
|
+
description: string | undefined;
|
|
915
|
+
predicate: string;
|
|
916
|
+
parameters: unknown;
|
|
917
|
+
fields: string[];
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* A logical group of constraints combined with a `LogicalOperator`.
|
|
921
|
+
* Mirrors Go's `ConstraintGroup`.
|
|
922
|
+
*/
|
|
923
|
+
interface ValidatorConstraintGroup {
|
|
924
|
+
kind: "group";
|
|
925
|
+
name: string;
|
|
926
|
+
description: string | undefined;
|
|
927
|
+
operator: string;
|
|
928
|
+
rules: ValidatorConstraint[];
|
|
929
|
+
}
|
|
930
|
+
/** A constraint is either a single rule or a logical group of rules. */
|
|
931
|
+
type ValidatorConstraint = ValidatorConstraintRule | ValidatorConstraintGroup;
|
|
932
|
+
/** Keyed map of constraint ID → ValidatorConstraint. */
|
|
933
|
+
type SchemaConstraintMap = Record<string, ValidatorConstraint>;
|
|
934
|
+
interface NodeResult {
|
|
935
|
+
issues: Issue[];
|
|
936
|
+
success: boolean;
|
|
937
|
+
skipped: boolean;
|
|
938
|
+
}
|
|
939
|
+
interface ValidationContext {
|
|
940
|
+
/** The original top-level document; never changes. */
|
|
941
|
+
originalRoot: Record<string, unknown>;
|
|
942
|
+
/** The current root being validated (may be a sub-document for recursive schemas). */
|
|
943
|
+
rootData: unknown;
|
|
944
|
+
/** Alias for rootData — kept for parity with Go. */
|
|
945
|
+
data: unknown;
|
|
946
|
+
/** The predicate function registry. */
|
|
947
|
+
functionMap: PredicateMap;
|
|
948
|
+
/** Maximum allowed nesting depth. */
|
|
949
|
+
maxDepth: number;
|
|
950
|
+
/** Validation strictness. */
|
|
951
|
+
mode: ValidationMode;
|
|
952
|
+
/**
|
|
953
|
+
* Per-node success state. Index = node ID, value = success (true) | failure (false) | absent (undefined).
|
|
954
|
+
* Used by the traversal loop to propagate skipping when a dependency failed.
|
|
955
|
+
*/
|
|
956
|
+
visited: Map<number, boolean>;
|
|
957
|
+
/** Accumulated issues for this traversal. */
|
|
958
|
+
issues: Issue[];
|
|
959
|
+
}
|
|
960
|
+
//#endregion
|
|
961
|
+
//#region src/validation/nodes.d.ts
|
|
962
|
+
interface ValidationNode {
|
|
963
|
+
execute(ctx: ValidationContext): Promise<NodeResult>;
|
|
964
|
+
getDependencies(): number[];
|
|
965
|
+
getID(): number;
|
|
966
|
+
getPath(): string;
|
|
967
|
+
getPathParts(): string[];
|
|
968
|
+
}
|
|
969
|
+
//#endregion
|
|
970
|
+
//#region src/validation/graph.d.ts
|
|
971
|
+
declare class BuildContext {
|
|
972
|
+
/** Ref-count of schemas currently being built. */
|
|
973
|
+
private readonly buildingSchemas;
|
|
974
|
+
/** Cache of pre-built recursive graphs keyed by schemaID + constraint hash. */
|
|
975
|
+
private readonly recursiveGraphCache;
|
|
976
|
+
isRecursive(schemaID: string): boolean;
|
|
977
|
+
markBuilding(schemaID: string): void;
|
|
978
|
+
unmarkBuilding(schemaID: string): void;
|
|
979
|
+
makeGraphCacheKey(schemaID: string, constraints: SchemaConstraintMap): string;
|
|
980
|
+
getOrBuildRecursiveGraph(schemaID: string, schemaDef: NestedSchemaDefinition$1, instanceConstraints: SchemaConstraintMap, topLevelSchema: SchemaDefinition$1): Promise<ValidationGraph>;
|
|
981
|
+
}
|
|
982
|
+
/** Internal tracking node used only during graph construction. */
|
|
983
|
+
interface TrackNode {
|
|
984
|
+
id: number;
|
|
985
|
+
deps: number[];
|
|
986
|
+
}
|
|
987
|
+
declare class ValidationGraph {
|
|
988
|
+
private nodes;
|
|
989
|
+
private dependencies;
|
|
990
|
+
private visitedState;
|
|
991
|
+
private executionOrder;
|
|
992
|
+
private nextNodeID;
|
|
993
|
+
/** Paths explicitly marked nullable:true (null is a legal value). */
|
|
994
|
+
readonly nullablePaths: Set<string>;
|
|
995
|
+
buildNodeID(): number;
|
|
996
|
+
addNode(node: ValidationNode): void;
|
|
997
|
+
private createUnexpectedFieldsNode;
|
|
998
|
+
private createRequiredFieldNode;
|
|
999
|
+
private createTypeCheckNode;
|
|
1000
|
+
private createCompletionNode;
|
|
1001
|
+
finalize(): void;
|
|
1002
|
+
traverse(fmap: PredicateMap, document: Record<string, unknown>, mode: ValidationMode, maxDepth: number, originalRoot: Record<string, unknown>): Promise<Issue[]>;
|
|
1003
|
+
/**
|
|
1004
|
+
* Builds the validation graph from a SchemaDefinition.
|
|
1005
|
+
* Returns the root TrackNodes (for wiring dependencies).
|
|
1006
|
+
* Mirrors Go's `graph.buildFromSchema`.
|
|
1007
|
+
*/
|
|
1008
|
+
buildFromSchema(schema: SchemaDefinition$1, basePath: string, baseParts: string[], addedConstraints: Map<string, boolean>, nsd: NestedSchemaDefinition$1 | null, schemaRefConstraints: SchemaConstraintMap, topLevelSchema: SchemaDefinition$1, buildCtx: BuildContext, skipUnexpectedCheck: boolean, skipUnexpectedForObjects: boolean): Promise<TrackNode[]>;
|
|
1009
|
+
private buildFieldNodes;
|
|
1010
|
+
private buildFieldTypeNodes;
|
|
1011
|
+
private buildObjectFieldNodes;
|
|
1012
|
+
/**
|
|
1013
|
+
* Mirrors Go's `buildContainerNode`.
|
|
1014
|
+
* Returns an ArrayValidationNode or RecordValidationNode depending on `itemKind`.
|
|
1015
|
+
*/
|
|
1016
|
+
private buildContainerNode;
|
|
1017
|
+
private buildEnumNode;
|
|
1018
|
+
private buildUnionNode;
|
|
1019
|
+
private buildCompositeNode;
|
|
1020
|
+
private buildFromEffectiveConstraints;
|
|
1021
|
+
private buildFromConstraintRuleWithScope;
|
|
1022
|
+
/**
|
|
1023
|
+
* Creates a standalone ValidationGraph for a single field, used by array /
|
|
1024
|
+
* record / union / composite nodes.
|
|
1025
|
+
* Mirrors Go's `graph.createSubGraph`.
|
|
1026
|
+
*/
|
|
1027
|
+
createSubGraph(rootFieldName: string, rootFieldDef: FieldDefinition$1, basePath: string, originalTopLevelSchema: SchemaDefinition$1, buildCtx: BuildContext, skipUnexpectedCheck: boolean, skipUnexpectedForObjects: boolean): Promise<ValidationGraph>;
|
|
1028
|
+
}
|
|
1029
|
+
//#endregion
|
|
1030
|
+
//#region src/validation/validator.d.ts
|
|
1031
|
+
declare class DocumentValidator {
|
|
1032
|
+
private readonly fmap;
|
|
1033
|
+
private readonly graph;
|
|
1034
|
+
private readonly config;
|
|
1035
|
+
protected constructor(graph: ValidationGraph, fmap: PredicateMap, config: ValidationConfig);
|
|
1036
|
+
/**
|
|
1037
|
+
* Full validation: reports missing required fields, unexpected fields,
|
|
1038
|
+
* type mismatches, and constraint violations.
|
|
1039
|
+
*/
|
|
1040
|
+
validate(document: Record<string, unknown>): Promise<Issue[]>;
|
|
1041
|
+
/**
|
|
1042
|
+
* Partial-strict validation: suppresses REQUIRED_FIELD_MISSING issues.
|
|
1043
|
+
* Use when validating partial updates (e.g. PATCH payloads).
|
|
1044
|
+
*/
|
|
1045
|
+
validatePartial(document: Record<string, unknown>): Promise<Issue[]>;
|
|
1046
|
+
/**
|
|
1047
|
+
* Loose validation: suppresses both REQUIRED_FIELD_MISSING and
|
|
1048
|
+
* UNEXPECTED_FIELD issues. Validates only present fields for type and
|
|
1049
|
+
* constraints.
|
|
1050
|
+
*/
|
|
1051
|
+
validateLoose(document: Record<string, unknown>): Promise<Issue[]>;
|
|
1052
|
+
/**
|
|
1053
|
+
* Builds a DocumentValidator from a SchemaDefinition.
|
|
1054
|
+
*
|
|
1055
|
+
* This compiles the schema into a validation DAG exactly once; subsequent
|
|
1056
|
+
* calls to `validate()` / `validatePartial()` / `validateLoose()` traverse
|
|
1057
|
+
* the pre-compiled graph and are fast.
|
|
1058
|
+
*
|
|
1059
|
+
* Throws if the schema contains structural errors that prevent graph construction
|
|
1060
|
+
* (e.g. dangling schema references, composite parts with unsupported types).
|
|
1061
|
+
*/
|
|
1062
|
+
static create(schema: SchemaDefinition$1, fmap: PredicateMap, config?: ValidationConfig): Promise<DocumentValidator>;
|
|
1063
|
+
}
|
|
1064
|
+
//#endregion
|
|
1065
|
+
//#region src/validation/schema-validator.d.ts
|
|
1066
|
+
/**
|
|
1067
|
+
* A dedicated validator for ensuring schema definitions themselves
|
|
1068
|
+
* conform to the meta-schema rules.
|
|
1069
|
+
*/
|
|
1070
|
+
declare class SchemaValidator {
|
|
1071
|
+
private static validator;
|
|
1072
|
+
/**
|
|
1073
|
+
* Validates a schema definition against the meta-schema rules.
|
|
1074
|
+
*/
|
|
1075
|
+
static validate(schemaDef: SchemaDefinition$1): Promise<Issue[]>;
|
|
1076
|
+
}
|
|
1077
|
+
//#endregion
|
|
1078
|
+
//#region src/validation/predicates.d.ts
|
|
1079
|
+
declare const metaSchemaPredicateMap: PredicateMap;
|
|
1080
|
+
//#endregion
|
|
1081
|
+
export { AnansiCodec, type AnansiCodecOptions, ComparisonOperator, Compiler, Constraint, ConstraintGroup, ConstraintMetadata, ConstraintRule, ConstraintUnion, container as DataTypes, type DecodeTransforms, DocumentValidator, type EncodeKind, type EncodeTransforms, FD_NO_CHILD, FLAG_COMPRESSED, FLAG_ENCRYPTED, FLAG_HASH_PRESENT, FieldDef, FieldDefinition, type FieldDescriptor, FieldType, IndexCondition, IndexConditionGroup, IndexConditionUnion, IndexDefinition, IndexOrder, IndexType, InlineTypeDescriptor, InlineTypeKind, type Issue, type LinkResult, type LinkedField, type LinkedSlot, Literal, LogicalOperatorEnum, MAX_SCHEMA_SLOTS, MULTI_STEP_BASE, type ManifestField, NestedSchemaDefinition, type PredicateMap, type ResolvedEnum, type ResolvedField, type ResolvedNested, SchemaDefinition, SchemaReference, SchemaReferenceArray, SchemaValidator, type Slot, String, Unknown, type ValidationConfig, addressForSteps, buildEnum, buildManifest, decodeAnansiBatch, decodeAnansiPacket, decodeBatch, decodeDocument, defaultValidationConfig, encodeAnansiBatchColumnar, encodeAnansiBatchRows, encodeAnansiPacket, encodeBatchColumnar, encodeBatchRows, encodeDocument, internalDP, link, makeDescriptor, metaSchemaPredicateMap, parseSchema, unpackDescriptor, userDataDP };
|