@atscript/typescript 0.1.34 → 0.1.36

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/dist/utils.d.ts CHANGED
@@ -242,7 +242,10 @@ declare function defineAnnotatedType(_kind?: TKind, base?: any): TAnnotatedTypeH
242
242
  */
243
243
  interface TMetadataMap<O extends object> extends Map<keyof O, O[keyof O]> {
244
244
  get<K extends keyof O>(key: K): O[K] | undefined;
245
+ get(key: string): unknown;
245
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;
246
249
  }
247
250
  /** Fluent builder handle returned by {@link defineAnnotatedType}. */
248
251
  interface TAnnotatedTypeHandle {
@@ -372,7 +375,7 @@ interface TCreateDataOptions {
372
375
  * - `'empty'` — structural defaults only (`''`, `0`, `false`, `[]`, `{}`); optional props skipped
373
376
  * - `'default'` — use `@meta.default` annotations; optional props skipped unless annotated
374
377
  * - `'example'` — use `@meta.example` annotations; optional props always included; arrays get one sample item
375
- * - `'db'` — use `@db.default.value` (parsed) or `@db.default.fn` (returns fn name string); optional props skipped unless annotated
378
+ * - `'db'` — use `@db.default` (parsed) or `@db.default.fn` (returns fn name string); optional props skipped unless annotated
376
379
  * - `function` — custom resolver per field; optional props skipped unless resolver returns a value
377
380
  *
378
381
  * @default 'empty'
@@ -386,7 +389,7 @@ interface TCreateDataOptions {
386
389
  * - `'empty'` — structural defaults only; optional props omitted
387
390
  * - `'default'` — uses `@meta.default` annotations; optional props omitted unless annotated
388
391
  * - `'example'` — uses `@meta.example` annotations; optional props always included; arrays get one sample item
389
- * - `'db'` — uses `@db.default.value` (parsed) or `@db.default.fn` (fn name string); optional props omitted unless annotated
392
+ * - `'db'` — uses `@db.default` (parsed) or `@db.default.fn` (fn name string); optional props omitted unless annotated
390
393
  * - `function` — custom resolver; optional props omitted unless resolver returns a value
391
394
  *
392
395
  * When a `@meta.default` / `@meta.example` value is set on a complex type (object, array)
@@ -446,6 +449,31 @@ interface TFlattenOptions {
446
449
  */
447
450
  declare function flattenAnnotatedType(type: TAtscriptAnnotatedType<TAtscriptTypeObject>, options?: TFlattenOptions): Map<string, TAtscriptAnnotatedType>;
448
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
+
449
477
  /** Current serialization format version. Bumped on breaking changes to the serialized shape. */
450
478
  declare const SERIALIZE_VERSION = 1;
451
479
  /** Top-level serialized annotated type. JSON-safe representation of a {@link TAtscriptAnnotatedType}. */
@@ -579,6 +607,22 @@ type FlatOf<T> = T extends {
579
607
  type PrimaryKeyOf<T> = T extends {
580
608
  __pk: infer PK;
581
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>;
582
626
 
583
627
  export { SERIALIZE_VERSION, Validator, ValidatorError, annotate, buildJsonSchema, cloneRefProp, createAnnotatedTypeNode, createDataFromAnnotatedType, defineAnnotatedType, deserializeAnnotatedType, flattenAnnotatedType, forAnnotatedType, fromJsonSchema, isAnnotatedType, isAnnotatedTypeOfPrimitive, isPhantomType, mergeJsonSchemas, serializeAnnotatedType, throwFeatureDisabled };
584
- 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 };