@atscript/typescript 0.1.33 → 0.1.35
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/LICENSE +1 -1
- package/dist/cli.cjs +607 -126
- package/dist/index.cjs +171 -778
- package/dist/index.mjs +163 -770
- package/dist/json-schema-0UUPoHud.mjs +952 -0
- package/dist/json-schema-S5-XAOrR.cjs +1030 -0
- package/dist/utils.cjs +80 -945
- package/dist/utils.d.ts +64 -6
- package/dist/utils.mjs +58 -923
- package/package.json +11 -6
package/dist/utils.d.ts
CHANGED
|
@@ -103,6 +103,10 @@ declare class ValidatorError extends Error {
|
|
|
103
103
|
declare function createAnnotatedTypeNode(type: TAtscriptTypeDef, metadata: TMetadataMap<AtscriptMetadata>, opts?: {
|
|
104
104
|
id?: string;
|
|
105
105
|
optional?: boolean;
|
|
106
|
+
ref?: {
|
|
107
|
+
type: () => TAtscriptAnnotatedType;
|
|
108
|
+
field: string;
|
|
109
|
+
};
|
|
106
110
|
}): TAtscriptAnnotatedType;
|
|
107
111
|
/** Type definition for union, intersection, or tuple types. */
|
|
108
112
|
interface TAtscriptTypeComplex<DataType = unknown> {
|
|
@@ -191,6 +195,10 @@ interface TAtscriptAnnotatedType<T extends TAtscriptTypeDef = TAtscriptTypeDef,
|
|
|
191
195
|
metadata: TMetadataMap<AtscriptMetadata>;
|
|
192
196
|
optional?: boolean;
|
|
193
197
|
id?: string;
|
|
198
|
+
ref?: {
|
|
199
|
+
type: () => TAtscriptAnnotatedType;
|
|
200
|
+
field: string;
|
|
201
|
+
};
|
|
194
202
|
}
|
|
195
203
|
/** An annotated type that is also a class constructor (i.e. a generated interface class). */
|
|
196
204
|
type TAtscriptAnnotatedTypeConstructor = TAtscriptAnnotatedType & (new (...args: any[]) => any);
|
|
@@ -234,7 +242,10 @@ declare function defineAnnotatedType(_kind?: TKind, base?: any): TAnnotatedTypeH
|
|
|
234
242
|
*/
|
|
235
243
|
interface TMetadataMap<O extends object> extends Map<keyof O, O[keyof O]> {
|
|
236
244
|
get<K extends keyof O>(key: K): O[K] | undefined;
|
|
245
|
+
get(key: string): unknown;
|
|
237
246
|
set<K extends keyof O>(key: K, value: O[K]): this;
|
|
247
|
+
has<K extends keyof O>(key: K): boolean;
|
|
248
|
+
has(key: string): boolean;
|
|
238
249
|
}
|
|
239
250
|
/** Fluent builder handle returned by {@link defineAnnotatedType}. */
|
|
240
251
|
interface TAnnotatedTypeHandle {
|
|
@@ -252,9 +263,11 @@ interface TAnnotatedTypeHandle {
|
|
|
252
263
|
propPattern(pattern: RegExp, value: TAtscriptAnnotatedType): TAnnotatedTypeHandle;
|
|
253
264
|
optional(value?: boolean): TAnnotatedTypeHandle;
|
|
254
265
|
copyMetadata(fromMetadata: TMetadataMap<AtscriptMetadata>): TAnnotatedTypeHandle;
|
|
255
|
-
refTo(type: TAtscriptAnnotatedType & {
|
|
266
|
+
refTo(type: (TAtscriptAnnotatedType & {
|
|
267
|
+
name?: string;
|
|
268
|
+
}) | (() => TAtscriptAnnotatedType & {
|
|
256
269
|
name?: string;
|
|
257
|
-
}, chain?: string[]): TAnnotatedTypeHandle;
|
|
270
|
+
}), chain?: string[]): TAnnotatedTypeHandle;
|
|
258
271
|
annotate(key: keyof AtscriptMetadata, value: any, asArray?: boolean): TAnnotatedTypeHandle;
|
|
259
272
|
id(value: string): TAnnotatedTypeHandle;
|
|
260
273
|
}
|
|
@@ -362,7 +375,7 @@ interface TCreateDataOptions {
|
|
|
362
375
|
* - `'empty'` — structural defaults only (`''`, `0`, `false`, `[]`, `{}`); optional props skipped
|
|
363
376
|
* - `'default'` — use `@meta.default` annotations; optional props skipped unless annotated
|
|
364
377
|
* - `'example'` — use `@meta.example` annotations; optional props always included; arrays get one sample item
|
|
365
|
-
* - `'db'` — use `@db.default
|
|
378
|
+
* - `'db'` — use `@db.default` (parsed) or `@db.default.fn` (returns fn name string); optional props skipped unless annotated
|
|
366
379
|
* - `function` — custom resolver per field; optional props skipped unless resolver returns a value
|
|
367
380
|
*
|
|
368
381
|
* @default 'empty'
|
|
@@ -376,7 +389,7 @@ interface TCreateDataOptions {
|
|
|
376
389
|
* - `'empty'` — structural defaults only; optional props omitted
|
|
377
390
|
* - `'default'` — uses `@meta.default` annotations; optional props omitted unless annotated
|
|
378
391
|
* - `'example'` — uses `@meta.example` annotations; optional props always included; arrays get one sample item
|
|
379
|
-
* - `'db'` — uses `@db.default
|
|
392
|
+
* - `'db'` — uses `@db.default` (parsed) or `@db.default.fn` (fn name string); optional props omitted unless annotated
|
|
380
393
|
* - `function` — custom resolver; optional props omitted unless resolver returns a value
|
|
381
394
|
*
|
|
382
395
|
* When a `@meta.default` / `@meta.example` value is set on a complex type (object, array)
|
|
@@ -436,6 +449,31 @@ interface TFlattenOptions {
|
|
|
436
449
|
*/
|
|
437
450
|
declare function flattenAnnotatedType(type: TAtscriptAnnotatedType<TAtscriptTypeObject>, options?: TFlattenOptions): Map<string, TAtscriptAnnotatedType>;
|
|
438
451
|
|
|
452
|
+
/** Runtime shape of a ref annotation argument (lazy type reference with optional chain). */
|
|
453
|
+
type AtscriptRef = {
|
|
454
|
+
type: () => TAtscriptAnnotatedType;
|
|
455
|
+
field: string;
|
|
456
|
+
} | (() => TAtscriptAnnotatedType);
|
|
457
|
+
/** Field reference within a query expression. */
|
|
458
|
+
interface AtscriptQueryFieldRef {
|
|
459
|
+
type?: () => TAtscriptAnnotatedType;
|
|
460
|
+
field: string;
|
|
461
|
+
}
|
|
462
|
+
/** Single comparison in a query expression. */
|
|
463
|
+
interface AtscriptQueryComparison {
|
|
464
|
+
left: AtscriptQueryFieldRef;
|
|
465
|
+
op: string;
|
|
466
|
+
right?: AtscriptQueryFieldRef | unknown[] | unknown;
|
|
467
|
+
}
|
|
468
|
+
/** Query expression tree (recursive). */
|
|
469
|
+
type AtscriptQueryNode = AtscriptQueryComparison | {
|
|
470
|
+
$and: AtscriptQueryNode[];
|
|
471
|
+
} | {
|
|
472
|
+
$or: AtscriptQueryNode[];
|
|
473
|
+
} | {
|
|
474
|
+
$not: AtscriptQueryNode;
|
|
475
|
+
};
|
|
476
|
+
|
|
439
477
|
/** Current serialization format version. Bumped on breaking changes to the serialized shape. */
|
|
440
478
|
declare const SERIALIZE_VERSION = 1;
|
|
441
479
|
/** Top-level serialized annotated type. JSON-safe representation of a {@link TAtscriptAnnotatedType}. */
|
|
@@ -478,7 +516,11 @@ interface TSerializedTypeComplex {
|
|
|
478
516
|
items: TSerializedAnnotatedTypeInner[];
|
|
479
517
|
tags: string[];
|
|
480
518
|
}
|
|
481
|
-
|
|
519
|
+
interface TSerializedTypeRef {
|
|
520
|
+
kind: '$ref';
|
|
521
|
+
id: string;
|
|
522
|
+
}
|
|
523
|
+
type TSerializedTypeDef = TSerializedTypeFinal | TSerializedTypeObject | TSerializedTypeArray | TSerializedTypeComplex | TSerializedTypeRef;
|
|
482
524
|
/** Context passed to {@link TSerializeOptions.processAnnotation} for each annotation entry. */
|
|
483
525
|
interface TProcessAnnotationContext {
|
|
484
526
|
/** Annotation key, e.g. "meta.label" */
|
|
@@ -565,6 +607,22 @@ type FlatOf<T> = T extends {
|
|
|
565
607
|
type PrimaryKeyOf<T> = T extends {
|
|
566
608
|
__pk: infer PK;
|
|
567
609
|
} ? PK : unknown;
|
|
610
|
+
/**
|
|
611
|
+
* Extracts the own-props flat map from an Atscript annotated type.
|
|
612
|
+
* `__ownProps` contains only table-owned fields (no navigation property descendants).
|
|
613
|
+
* Falls back to `FlatOf<T>` for types generated before this feature was added.
|
|
614
|
+
*/
|
|
615
|
+
type OwnPropsOf<T> = T extends {
|
|
616
|
+
__ownProps: infer O;
|
|
617
|
+
} ? O : FlatOf<T>;
|
|
618
|
+
/**
|
|
619
|
+
* Extracts the navigation property map from an Atscript annotated type.
|
|
620
|
+
* `__navProps` maps nav prop names to their declared types (e.g., `{ author: Author, comments: Comment[] }`).
|
|
621
|
+
* Returns `Record<string, never>` when no `__navProps` exists (no nav props or pre-feature type).
|
|
622
|
+
*/
|
|
623
|
+
type NavPropsOf<T> = T extends {
|
|
624
|
+
__navProps: infer N extends Record<string, unknown>;
|
|
625
|
+
} ? N : Record<string, never>;
|
|
568
626
|
|
|
569
627
|
export { SERIALIZE_VERSION, Validator, ValidatorError, annotate, buildJsonSchema, cloneRefProp, createAnnotatedTypeNode, createDataFromAnnotatedType, defineAnnotatedType, deserializeAnnotatedType, flattenAnnotatedType, forAnnotatedType, fromJsonSchema, isAnnotatedType, isAnnotatedTypeOfPrimitive, isPhantomType, mergeJsonSchemas, serializeAnnotatedType, throwFeatureDisabled };
|
|
570
|
-
export type { FlatOf, InferDataType, PrimaryKeyOf, TAnnotatedTypeHandle, TAtscriptAnnotatedType, TAtscriptAnnotatedTypeConstructor, TAtscriptDataType, TAtscriptTypeArray, TAtscriptTypeComplex, TAtscriptTypeDef, TAtscriptTypeFinal, TAtscriptTypeObject, TCreateDataOptions, TFlattenOptions, TJsonSchema, TMetadataMap, TProcessAnnotationContext, TSerializeOptions, TSerializedAnnotatedType, TSerializedAnnotatedTypeInner, TSerializedTypeArray, TSerializedTypeComplex, TSerializedTypeDef, TSerializedTypeFinal, TSerializedTypeObject, TValidatorOptions, TValidatorPlugin, TValidatorPluginContext, TValueResolver };
|
|
628
|
+
export type { AtscriptQueryComparison, AtscriptQueryFieldRef, AtscriptQueryNode, AtscriptRef, FlatOf, InferDataType, NavPropsOf, OwnPropsOf, PrimaryKeyOf, TAnnotatedTypeHandle, TAtscriptAnnotatedType, TAtscriptAnnotatedTypeConstructor, TAtscriptDataType, TAtscriptTypeArray, TAtscriptTypeComplex, TAtscriptTypeDef, TAtscriptTypeFinal, TAtscriptTypeObject, TCreateDataOptions, TFlattenOptions, TJsonSchema, TMetadataMap, TProcessAnnotationContext, TSerializeOptions, TSerializedAnnotatedType, TSerializedAnnotatedTypeInner, TSerializedTypeArray, TSerializedTypeComplex, TSerializedTypeDef, TSerializedTypeFinal, TSerializedTypeObject, TValidatorOptions, TValidatorPlugin, TValidatorPluginContext, TValueResolver };
|