@plasius/schema 1.2.18 → 1.3.1

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.
Files changed (36) hide show
  1. package/README.md +207 -1
  2. package/THIRD_PARTY_NOTICES.md +75 -0
  3. package/dist/chunk-6FE4FLKF.js +254 -0
  4. package/dist/chunk-6FE4FLKF.js.map +1 -0
  5. package/dist/chunk-AG2NAPDC.js +117 -0
  6. package/dist/chunk-AG2NAPDC.js.map +1 -0
  7. package/dist/chunk-UQHPDQZX.js +2606 -0
  8. package/dist/chunk-UQHPDQZX.js.map +1 -0
  9. package/dist/feedback-diagnostics-BaniQAFS.d.cts +353 -0
  10. package/dist/feedback-diagnostics-CnsI0B9-.d.ts +353 -0
  11. package/dist/feedback-diagnostics-vocabulary.cjs +156 -0
  12. package/dist/feedback-diagnostics-vocabulary.cjs.map +1 -0
  13. package/dist/feedback-diagnostics-vocabulary.d.cts +70 -0
  14. package/dist/feedback-diagnostics-vocabulary.d.ts +70 -0
  15. package/dist/feedback-diagnostics-vocabulary.js +33 -0
  16. package/dist/feedback-diagnostics-vocabulary.js.map +1 -0
  17. package/dist/feedback-diagnostics.cjs +2696 -0
  18. package/dist/feedback-diagnostics.cjs.map +1 -0
  19. package/dist/feedback-diagnostics.d.cts +2 -0
  20. package/dist/feedback-diagnostics.d.ts +2 -0
  21. package/dist/feedback-diagnostics.js +39 -0
  22. package/dist/feedback-diagnostics.js.map +1 -0
  23. package/dist/feedback-unicode-profile.cjs +283 -0
  24. package/dist/feedback-unicode-profile.cjs.map +1 -0
  25. package/dist/feedback-unicode-profile.d.cts +28 -0
  26. package/dist/feedback-unicode-profile.d.ts +28 -0
  27. package/dist/feedback-unicode-profile.js +13 -0
  28. package/dist/feedback-unicode-profile.js.map +1 -0
  29. package/dist/index.cjs +2258 -14
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +987 -286
  32. package/dist/index.d.ts +987 -286
  33. package/dist/index.js +1532 -2197
  34. package/dist/index.js.map +1 -1
  35. package/package.json +36 -12
  36. package/unicode/feedback-unicode-15.1.0-unassigned.json +13 -0
@@ -0,0 +1,353 @@
1
+ import { FeedbackGameDiagnostics } from './feedback-diagnostics-vocabulary.cjs';
2
+
3
+ type PIIClassification = "none" | "low" | "high";
4
+ type PIIAction = "encrypt" | "hash" | "clear" | "none";
5
+ type PIILogHandling = "redact" | "omit" | "pseudonym" | "plain";
6
+ interface PII {
7
+ classification: PIIClassification;
8
+ action: PIIAction;
9
+ logHandling?: PIILogHandling;
10
+ purpose?: string;
11
+ }
12
+
13
+ interface ValidationIssueInput {
14
+ code: string;
15
+ message: string;
16
+ path?: string;
17
+ }
18
+ interface ValidationIssue {
19
+ path: string;
20
+ code: string;
21
+ message: string;
22
+ }
23
+ type FieldValidatorResult = boolean | string | ValidationIssueInput | ValidationIssueInput[];
24
+ type FieldValidator<T = unknown> = {
25
+ bivarianceHack(value: T): FieldValidatorResult;
26
+ }["bivarianceHack"];
27
+
28
+ type FieldType$1 = "string" | "number" | "boolean" | "object" | "array" | "ref";
29
+
30
+ type FieldExposure = "public" | "internal";
31
+ declare class FieldBuilder<TExternal = unknown, TInternal = TExternal> {
32
+ type: FieldType$1;
33
+ _type: TExternal;
34
+ _storageType: TInternal;
35
+ isSystem: boolean;
36
+ isImmutable: boolean;
37
+ isRequired: boolean;
38
+ _validator?: FieldValidator<TInternal>;
39
+ _description: string;
40
+ _version: string;
41
+ _default?: TInternal | (() => TInternal);
42
+ _upgrade?: (value: any, ctx: {
43
+ entityFrom: string;
44
+ entityTo: string;
45
+ fieldTo: string;
46
+ fieldName: string;
47
+ }) => {
48
+ ok: boolean;
49
+ value?: any;
50
+ error?: string;
51
+ };
52
+ _shape?: Record<string, FieldBuilder<any>>;
53
+ itemType?: FieldBuilder<any>;
54
+ refType?: string;
55
+ _pii: PII;
56
+ _exposure: FieldExposure;
57
+ enumValues?: readonly TInternal[];
58
+ constructor(type: FieldType$1, options?: {
59
+ shape?: Record<string, FieldBuilder<any>>;
60
+ itemType?: FieldBuilder<any>;
61
+ refType?: string;
62
+ });
63
+ immutable(): FieldBuilder<TExternal, TInternal>;
64
+ system(): FieldBuilder<TExternal, TInternal>;
65
+ exposure(exposure: FieldExposure): FieldBuilder<TExternal, TInternal>;
66
+ internal(): FieldBuilder<TExternal, TInternal>;
67
+ public(): FieldBuilder<TExternal, TInternal>;
68
+ required(): FieldBuilder<TExternal, TInternal>;
69
+ optional(): FieldBuilder<TExternal, TInternal>;
70
+ validator(fn: FieldValidator<TInternal>): FieldBuilder<TExternal, TInternal>;
71
+ description(desc: string): FieldBuilder<TExternal, TInternal>;
72
+ default(value: TInternal | (() => TInternal)): FieldBuilder<TExternal, TInternal>;
73
+ /**
74
+ * Configure an upgrader used when validating older entities against a newer schema.
75
+ * The upgrader receives the current field value and version context, and should
76
+ * return { ok: true, value } with the upgraded value, or { ok: false, error }.
77
+ */
78
+ upgrade(fn: (value: any, ctx: {
79
+ entityFrom: string;
80
+ entityTo: string;
81
+ fieldTo: string;
82
+ fieldName: string;
83
+ }) => {
84
+ ok: boolean;
85
+ value?: any;
86
+ error?: string;
87
+ }): FieldBuilder<TExternal, TInternal>;
88
+ getDefault(): TInternal | undefined;
89
+ version(ver: string): FieldBuilder<TExternal, TInternal>;
90
+ PID(pii: PII): FieldBuilder<TExternal, TInternal>;
91
+ min(min: number): FieldBuilder<TExternal, TInternal>;
92
+ max(max: number): FieldBuilder<TExternal, TInternal>;
93
+ pattern(regex: RegExp): FieldBuilder<TExternal, TInternal>;
94
+ enum<const U extends readonly TInternal[]>(values: U): FieldBuilder<U[number]>;
95
+ /**
96
+ * Create a shallow clone with a different external type parameter.
97
+ * Note: shape and itemType are passed by reference (shallow). If you need
98
+ * deep isolation of nested FieldBuilders, clone them explicitly.
99
+ */
100
+ as<U>(): FieldBuilder<U, TInternal>;
101
+ }
102
+
103
+ type InferField<T> = T extends {
104
+ _type: infer U;
105
+ } ? U : T extends {
106
+ type: "string";
107
+ } ? string : T extends {
108
+ type: "number";
109
+ } ? number : T extends {
110
+ type: "boolean";
111
+ } ? boolean : T extends {
112
+ type: "array";
113
+ itemType: infer Item;
114
+ } ? InferField<Item>[] : T extends {
115
+ type: "object";
116
+ shape: infer Shape extends SchemaShape;
117
+ } ? InferFromShape<Shape> : unknown;
118
+ type IsOptional<T> = T extends {
119
+ isRequired: false;
120
+ } ? true : false;
121
+ type InferFromShape<S extends SchemaShape> = {
122
+ [K in keyof S]: IsOptional<S[K]> extends true ? InferField<S[K]> | undefined : InferField<S[K]>;
123
+ };
124
+ type InferFromSchema<T extends {
125
+ shape: SchemaShape;
126
+ }> = InferFromShape<T["shape"]>;
127
+ type IsSchema<T> = T extends {
128
+ shape: SchemaShape;
129
+ } ? true : false;
130
+ type Infer<T> = IsSchema<T> extends true ? InferFromSchema<T & {
131
+ shape: SchemaShape;
132
+ }> : InferFromShape<T & SchemaShape>;
133
+
134
+ type FieldTypeMap = {
135
+ string: string;
136
+ number: number;
137
+ boolean: boolean;
138
+ object: Record<string, unknown>;
139
+ "string[]": string[];
140
+ "number[]": number[];
141
+ "boolean[]": boolean[];
142
+ "object[]": Record<string, unknown>[];
143
+ ref: RefEntityId;
144
+ "ref[]": RefEntityId[];
145
+ };
146
+ type FieldType = keyof FieldTypeMap;
147
+ type PIIEnforcement = "strict" | "warn" | "none";
148
+ /** Supported unknown-field policies in backwards-compatible order. */
149
+ declare const SCHEMA_UNKNOWN_FIELDS_POLICIES: readonly ["strip", "reject"];
150
+ /** Controls whether fields outside a schema shape are stripped or rejected. */
151
+ type UnknownFieldsPolicy = (typeof SCHEMA_UNKNOWN_FIELDS_POLICIES)[number];
152
+ /** Supported schema-identity policies in backwards-compatible order. */
153
+ declare const SCHEMA_IDENTITY_POLICIES: readonly ["compatible", "exact"];
154
+ /** Controls exact enforcement of a schema's declared type and version. */
155
+ type SchemaIdentityPolicy = (typeof SCHEMA_IDENTITY_POLICIES)[number];
156
+ /** Result returned by a schema upgrade function. */
157
+ type SchemaUpgradeResult = {
158
+ ok: boolean;
159
+ /** Upgraded entity (must include all required fields for the new schema). */
160
+ value?: Record<string, any>;
161
+ /** Optional human-readable errors if upgrade fails. */
162
+ errors?: string[];
163
+ };
164
+ /**
165
+ * A function that upgrades an entity from an older schema version to a newer one.
166
+ * It should be **pure** and not mutate its arguments.
167
+ */
168
+ type SchemaUpgradeFunction = (input: Record<string, any>, ctx: {
169
+ from: string;
170
+ to: string;
171
+ entityType: string;
172
+ /** Describe function for the target schema – useful for dynamic migrations. */
173
+ describe: () => {
174
+ entityType: string;
175
+ version: string;
176
+ shape: Record<string, any>;
177
+ };
178
+ log?: (msg: string) => void;
179
+ }) => SchemaUpgradeResult;
180
+ type SchemaUpgradeStep = {
181
+ /** The target version this step upgrades to (e.g., "1.1.0"). */
182
+ to: string;
183
+ /** The migration function that upgrades from the previous step's version to `to`. */
184
+ run: SchemaUpgradeFunction;
185
+ };
186
+ /**
187
+ * Schema-level upgrade specification can be either:
188
+ * - a single `SchemaUpgradeFunction` that handles any from->to, OR
189
+ * - an ordered array of steps, each targeting a specific `to` version, which
190
+ * will be applied sequentially to cascade from the oldest known version to the latest.
191
+ */
192
+ type SchemaUpgradeSpec = SchemaUpgradeFunction | SchemaUpgradeStep[];
193
+ /**
194
+ * Presence-only metadata supplied to a schema-level validator.
195
+ *
196
+ * Raw input values are intentionally withheld. `wasProvided` distinguishes
197
+ * an omitted optional field from an explicitly supplied `null`/`undefined`.
198
+ */
199
+ interface SchemaValidationContext {
200
+ readonly wasProvided: (fieldName: string) => boolean;
201
+ }
202
+ interface SchemaOptions {
203
+ version?: string;
204
+ table?: string;
205
+ schemaValidator?: (value: any, context?: SchemaValidationContext) => boolean;
206
+ piiEnforcement?: PIIEnforcement;
207
+ /**
208
+ * How validation handles properties not declared by the schema.
209
+ *
210
+ * `strip` preserves the historical behaviour. `reject` is intended for
211
+ * trust boundaries where silently accepting extra data would be unsafe.
212
+ */
213
+ unknownFields?: UnknownFieldsPolicy;
214
+ /**
215
+ * `exact` rejects a mismatched `type` or `version` after any configured
216
+ * upgrade. The backwards-compatible default validates only their field
217
+ * shapes.
218
+ */
219
+ identity?: SchemaIdentityPolicy;
220
+ schemaUpgrade?: SchemaUpgradeStep[] | SchemaUpgradeFunction | undefined;
221
+ }
222
+ interface SerializeOptions {
223
+ includeInternal?: boolean;
224
+ }
225
+ type SchemaShape = Record<string, FieldBuilder<any>>;
226
+ interface FieldDefinition<T = unknown> {
227
+ type: FieldType;
228
+ __valueType?: T;
229
+ optional?: boolean;
230
+ immutable?: boolean;
231
+ description?: string;
232
+ refType?: string;
233
+ version?: string;
234
+ deprecated?: boolean;
235
+ deprecatedVersion?: string;
236
+ system?: boolean;
237
+ autoValidate?: boolean;
238
+ refPolicy?: "eager" | "lazy";
239
+ enum?: string[];
240
+ _shape?: SchemaShape;
241
+ pii?: PII;
242
+ exposure?: FieldExposure;
243
+ validator?: FieldValidator<T>;
244
+ }
245
+ interface ValidateCompositionOptions {
246
+ resolveEntity: (type: string, id: string) => Promise<any | null>;
247
+ validatorContext?: {
248
+ visited: Set<string>;
249
+ };
250
+ maxDepth?: number;
251
+ log?: (msg: string) => void;
252
+ onlyFields?: string[];
253
+ }
254
+ interface Schema<T extends SchemaShape> {
255
+ _shape: T;
256
+ meta: {
257
+ entityType: string;
258
+ version: string;
259
+ };
260
+ schemaValidator: (entity: Infer<T>, context?: SchemaValidationContext) => boolean;
261
+ /**
262
+ * Runs the optional schema-level upgrade function once, without validating.
263
+ * Useful for offline migrations or testing migration logic.
264
+ */
265
+ upgrade(input: Record<string, any>, log?: (msg: string) => void): {
266
+ ok: boolean;
267
+ value?: Record<string, any>;
268
+ errors?: string[];
269
+ };
270
+ validate: (input: unknown, existing?: Record<string, any>) => ValidationResult<Infer<T>>;
271
+ validateComposition: (entity: Infer<T>, options: ValidateCompositionOptions) => Promise<void>;
272
+ serialize: (input: Record<string, any>, options?: SerializeOptions) => Record<string, any>;
273
+ tableName?: () => string | undefined;
274
+ prepareForRead(stored: Record<string, any>, decryptFn: (value: string) => any | null): Record<string, any>;
275
+ prepareForStorage(input: Record<string, any>, encryptFn: (value: any) => string, hashFn: (value: any) => string): Record<string, any>;
276
+ sanitizeForLog(data: Record<string, any>, pseudonymFn: (value: any) => string): Record<string, any>;
277
+ getPiiAudit(): Array<{
278
+ field: string;
279
+ classification: PIIClassification;
280
+ action: PIIAction;
281
+ logHandling?: PIILogHandling;
282
+ purpose?: string;
283
+ }> | null;
284
+ scrubPiiForDelete(stored: Record<string, any>): Record<string, any>;
285
+ describe(): {
286
+ entityType: string;
287
+ version: string;
288
+ shape: Record<string, {
289
+ type: FieldType;
290
+ optional: boolean;
291
+ immutable: boolean;
292
+ description: string;
293
+ version: string;
294
+ deprecated: boolean;
295
+ deprecatedVersion: string | null;
296
+ system: boolean;
297
+ enum: string[] | null;
298
+ refType: string | null;
299
+ pii: PII | null;
300
+ exposure: FieldExposure;
301
+ }>;
302
+ };
303
+ }
304
+ type DeepReadonly<T> = {
305
+ readonly [K in keyof T]: T[K] extends object ? T[K] extends (...args: any[]) => any ? T[K] : DeepReadonly<T[K]> : T[K];
306
+ };
307
+ interface ValidationResult<T> {
308
+ valid: boolean;
309
+ value?: DeepReadonly<T>;
310
+ errors?: string[];
311
+ issues?: ValidationIssue[];
312
+ }
313
+ type RefEntityId<T extends string = string> = {
314
+ type: T;
315
+ id: string;
316
+ };
317
+
318
+ /** Bucketed, consented renderer diagnostics; it cannot express pixels or DOM. */
319
+ declare const FeedbackGameDiagnosticsSchema: Schema<{
320
+ surfaceId: FieldBuilder<"site.generator" | "site.gpu-demo", "site.generator" | "site.gpu-demo">;
321
+ consentConfirmed: FieldBuilder<boolean, boolean>;
322
+ provenanceContractId: FieldBuilder<"generator.renderer-diagnostics.v1" | "gpu-demo.renderer-diagnostics.v1", "generator.renderer-diagnostics.v1" | "gpu-demo.renderer-diagnostics.v1">;
323
+ renderer: FieldBuilder<"webgl2" | "webgpu" | "canvas2d" | "unknown", "webgl2" | "webgpu" | "canvas2d" | "unknown">;
324
+ backend: FieldBuilder<"unknown" | "browser" | "worker", "unknown" | "browser" | "worker">;
325
+ viewportBucket: FieldBuilder<"unknown" | "small-portrait" | "small-landscape" | "medium-portrait" | "medium-landscape" | "large-portrait" | "large-landscape", "unknown" | "small-portrait" | "small-landscape" | "medium-portrait" | "medium-landscape" | "large-portrait" | "large-landscape">;
326
+ frameRateBucket: FieldBuilder<"unknown" | "under-15" | "15-29" | "30-59" | "60-plus", "unknown" | "under-15" | "15-29" | "30-59" | "60-plus">;
327
+ frameTimeBucket: FieldBuilder<"unknown" | "under-17ms" | "17-33ms" | "34-66ms" | "over-66ms", "unknown" | "under-17ms" | "17-33ms" | "34-66ms" | "over-66ms">;
328
+ featureIds: FieldBuilder<unknown, unknown>;
329
+ counters: FieldBuilder<unknown, unknown>;
330
+ errorCodes: FieldBuilder<unknown, unknown>;
331
+ type?: FieldBuilder<"feedback-game-diagnostics", "feedback-game-diagnostics"> | undefined;
332
+ version?: FieldBuilder<"1.0.0", "1.0.0"> | undefined;
333
+ }>;
334
+ type FeedbackGameDiagnosticsValidationResult = {
335
+ readonly valid: true;
336
+ readonly value: FeedbackGameDiagnostics;
337
+ readonly errors?: never;
338
+ readonly issues?: never;
339
+ } | {
340
+ readonly valid: false;
341
+ readonly value?: never;
342
+ readonly errors: readonly string[];
343
+ readonly issues?: readonly ValidationIssue[];
344
+ };
345
+ /**
346
+ * Validate and clone diagnostics while preserving the correlated public type.
347
+ *
348
+ * `createSchema` intentionally exposes its generic inferred shape; this
349
+ * domain wrapper is the typed boundary consumers should use.
350
+ */
351
+ declare const validateFeedbackGameDiagnostics: (input: unknown) => FeedbackGameDiagnosticsValidationResult;
352
+
353
+ export { type DeepReadonly as D, FieldBuilder as F, type Infer as I, type PIIEnforcement as P, type RefEntityId as R, type SchemaShape as S, type UnknownFieldsPolicy as U, type ValidationIssue as V, type SchemaOptions as a, type Schema as b, type FieldType as c, FeedbackGameDiagnosticsSchema as d, type FeedbackGameDiagnosticsValidationResult as e, type FieldDefinition as f, type FieldExposure as g, type FieldTypeMap as h, type FieldValidator as i, type FieldValidatorResult as j, SCHEMA_IDENTITY_POLICIES as k, SCHEMA_UNKNOWN_FIELDS_POLICIES as l, type SchemaIdentityPolicy as m, type SchemaUpgradeFunction as n, type SchemaUpgradeResult as o, type SchemaUpgradeSpec as p, type SchemaUpgradeStep as q, type SchemaValidationContext as r, type SerializeOptions as s, type ValidateCompositionOptions as t, type ValidationIssueInput as u, type ValidationResult as v, validateFeedbackGameDiagnostics as w };