@atscript/core 0.2.3 → 0.2.4

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/index.d.ts CHANGED
@@ -367,7 +367,12 @@ interface TPrimitiveTypeObject {
367
367
  propsPatterns: Record<string, TPrimitiveTypeDef>;
368
368
  optional?: boolean;
369
369
  }
370
- type TPrimitiveTypeFinal = 'string' | 'number' | 'boolean' | 'void' | 'null' | 'phantom' | 'decimal';
370
+ /**
371
+ * A final (scalar) primitive type. `'any'`: any value, not checked (the `unknown` primitive —
372
+ * TypeScript `unknown`, JSON Schema `{}`); `'phantom'`: no value at all (not in the data type,
373
+ * validation or schema).
374
+ */
375
+ type TPrimitiveTypeFinal = 'string' | 'number' | 'boolean' | 'void' | 'null' | 'phantom' | 'decimal' | 'any';
371
376
  interface TPrimitiveTypeFinalOptional {
372
377
  kind: 'final';
373
378
  value: TPrimitiveTypeFinal;
@@ -461,7 +466,7 @@ declare class SemanticPrimitiveNode extends SemanticNode {
461
466
  private readonly annotationTree?;
462
467
  constructor(_id: string, config: TPrimitiveConfig, parentKey?: string, annotationTree?: TAnnotationsTree | undefined);
463
468
  protected applyAnnotations(): void;
464
- readonly type?: 'union' | 'intersection' | 'tuple' | 'array' | 'object' | 'string' | 'number' | 'boolean' | 'void' | 'null' | 'phantom' | 'decimal';
469
+ readonly type?: 'union' | 'intersection' | 'tuple' | 'array' | 'object' | 'string' | 'number' | 'boolean' | 'void' | 'null' | 'phantom' | 'decimal' | 'any';
465
470
  get key(): string;
466
471
  getAllTags(_processed?: Set<SemanticPrimitiveNode>): string[];
467
472
  get id(): string;
@@ -502,6 +507,12 @@ declare const UNION_IN_RECURSIVE_MERGE = "union members are not supported in rec
502
507
  declare const MERGE_TOO_COMPLEX = "merge too complex: split it with named types";
503
508
  /** Why scalars (or an object and a scalar) merge to `never`. */
504
509
  declare const NOTHING_IN_COMMON = "values with nothing in common";
510
+ /**
511
+ * Why a merge of `unknown` (any value) with an object, an array or `null` is refused: TypeScript
512
+ * reads `unknown & X` as `X`, a merge of values would be `never` (a compile error, not a
513
+ * validator rejecting what the `.d.ts` accepts).
514
+ */
515
+ declare const OPAQUE_MERGE = "\"unknown\" cannot be merged with an object, an array or null";
505
516
  /** A type written as an operand of its own merge (`type X = A & X`). */
506
517
  declare const SELF_OPERAND = "a type cannot be an operand of its own merge; recurse through a field instead";
507
518
  /** A db entity whose flattening reaches a web of mutually recursive merges. */
@@ -679,8 +690,11 @@ type TStructShape = {
679
690
  k: 'uni';
680
691
  n: number;
681
692
  items: TStructShape[];
682
- } | {
693
+ }
694
+ /** `any`: the `unknown` primitive (any value), or a union holding it */
695
+ | {
683
696
  k: 'scalar';
697
+ any?: true;
684
698
  } | {
685
699
  k: 'never';
686
700
  reason: string;
@@ -2307,7 +2321,16 @@ declare class AtscriptDoc {
2307
2321
  * is `X & Z`; an alias `XN = X | null`: X, then XN's own).
2308
2322
  */
2309
2323
  intersectionMemberRefs(group: SemanticGroup): SemanticRefNode[];
2310
- mergeNodesAnnotations(left?: TAnnotationTokens[], right?: TAnnotationTokens[]): TAnnotationTokens[];
2324
+ /**
2325
+ * Annotations `right` over `left`: right's win, `append` ones of both kept (left's after).
2326
+ *
2327
+ * `layered`: `right` is a node's and `left` what the node is layered over (the type it
2328
+ * references, an `as` copy's target) — right's `@annotate.reset 'x'` drop left's x, and the
2329
+ * resets of both stay, for the layers further below (see {@link stripResets}). Else they are
2330
+ * siblings (the members of a merge): a reset applies within its member's own layers only, and
2331
+ * is left out.
2332
+ */
2333
+ mergeNodesAnnotations(left?: TAnnotationTokens[], right?: TAnnotationTokens[], layered?: boolean): TAnnotationTokens[];
2311
2334
  }
2312
2335
  /**
2313
2336
  * {@link unwoundFields}, each declared field once: several positions of a type path may be one
@@ -2575,6 +2598,11 @@ interface TQueryScope {
2575
2598
  */
2576
2599
  unqualifiedTarget: string | null;
2577
2600
  }
2601
+ /**
2602
+ * The built-in annotation of `annotate` blocks that removes another annotation from the node
2603
+ * (`@annotate.reset 'expect.pattern'`): a directive, never written as metadata.
2604
+ */
2605
+ declare const ANNOTATE_RESET = "annotate.reset";
2578
2606
  /** Annotation argument types written in backticks, each parsed by its own grammar. */
2579
2607
  type TBacktickArgKind = 'query' | 'expr' | 'order';
2580
2608
  /** Whether an annotation argument type is written in backticks (`query`, `expr`, `order`). */
@@ -2602,8 +2630,12 @@ interface TAnnotationArgument {
2602
2630
  * - `expr`: backtick arithmetic over field refs (`openCount * 10 + coalesce(overdue, 0)`):
2603
2631
  * `+ - * /`, unary `-`, parentheses, numeric literals, `coalesce(a, b, …)`
2604
2632
  * - `order`: backtick ordering (`raisedAt desc, id`): field refs with optional `asc` / `desc`
2633
+ * - `value`: a scalar literal — a string (`'active'`), a number (`0`, `-1.5`) or a boolean
2634
+ * (`true`). A number or boolean must fit the annotated field's type (a number for a number
2635
+ * field, …); a string is accepted for any field (read as text for a string field, else as
2636
+ * JSON by convention). The value is stored as written: a string, a number or a boolean.
2605
2637
  */
2606
- type: 'string' | 'number' | 'boolean' | 'ref' | TBacktickArgKind;
2638
+ type: 'string' | 'number' | 'boolean' | 'ref' | 'value' | TBacktickArgKind;
2607
2639
  description?: string;
2608
2640
  values?: string[];
2609
2641
  /**
@@ -2631,6 +2663,13 @@ interface TAnnotationArgument {
2631
2663
  * return `false` to hide the candidate. All declarations are offered when absent.
2632
2664
  */
2633
2665
  refFilter?: (decl: SemanticNode, doc: AtscriptDoc) => boolean;
2666
+ /**
2667
+ * The argument is user-facing text (a label, a description, an error message): i18n tooling
2668
+ * and translators read the annotations holding such text through {@link userTextAnnotations}
2669
+ * (build time) and `userTextOf` / `userTextKeys` of `@atscript/typescript/utils` (runtime).
2670
+ * A `string` argument only.
2671
+ */
2672
+ userText?: boolean;
2634
2673
  }
2635
2674
  interface TAnnotationSpecConfig {
2636
2675
  multiple?: boolean;
@@ -2673,6 +2712,12 @@ declare class AnnotationSpec {
2673
2712
  * by `getDiagMessages` (the `referred` loop) and is skipped here.
2674
2713
  */
2675
2714
  validateDeferred(mainToken: Token, args: Token[], doc: AtscriptDoc): TMessages | undefined;
2715
+ /**
2716
+ * `value` arguments written as a number or a boolean must fit the annotated field's type: a
2717
+ * number literal a field that holds numbers, a boolean literal one that holds booleans (a
2718
+ * union: one of its members; `unknown`: any). A string is accepted for any field.
2719
+ */
2720
+ private validateValueArgs;
2676
2721
  /**
2677
2722
  * Checks an already-resolved target node against this annotation's `defType`
2678
2723
  * guard (e.g. `@expect.minLength` requires `string | array`). Returns a
@@ -2697,6 +2742,18 @@ declare function isAnnotationSpec(a?: TAnnotationsTree | AnnotationSpec): a is A
2697
2742
  * reported under each.
2698
2743
  */
2699
2744
  declare function forEachAnnotationSpec(tree: TAnnotationsTree, cb: (name: string, spec: AnnotationSpec) => void): void;
2745
+ /**
2746
+ * Where annotation `spec` holds user-facing text (arguments flagged `userText`): `true` — its
2747
+ * value itself (a spec with one argument, not a list: the value is the string; for a `multiple`
2748
+ * annotation, each value); a list — those fields of its value object (a spec with an argument
2749
+ * list). `undefined`: no user-facing text.
2750
+ */
2751
+ declare function userTextFields(spec: AnnotationSpec): true | string[] | undefined;
2752
+ /**
2753
+ * Every annotation of `tree` (core and plugins) holding user-facing text, by full name (see
2754
+ * {@link userTextFields}): what i18n tooling extracts and a translator translates.
2755
+ */
2756
+ declare function userTextAnnotations(tree: TAnnotationsTree): Map<string, true | string[]>;
2700
2757
  declare function resolveAnnotation(name: string, annotationsTree?: TAnnotationsTree): AnnotationSpec | undefined;
2701
2758
  /**
2702
2759
  * Resolved members of a union other than `null` / `undefined`, or `undefined`
@@ -2714,6 +2771,13 @@ declare function resolveAnnotation(name: string, annotationsTree?: TAnnotationsT
2714
2771
  * ```
2715
2772
  */
2716
2773
  declare function nonNullishMembers(def: SemanticNode | undefined, doc: AtscriptDoc): SemanticNode[] | undefined;
2774
+ /**
2775
+ * The scalar kinds the field (or type) annotation `mainToken` is written on holds (see
2776
+ * `valueKinds`): `string`, `number`, `boolean`, `decimal`, `unknown` (any value), or another
2777
+ * kind name (`object`, `array`, …). `undefined` when the field does not resolve. Code generators
2778
+ * use it for `value` arguments: a number literal on a `decimal` field is written as its string.
2779
+ */
2780
+ declare function annotatedValueKinds(mainToken: Token, doc: AtscriptDoc): Set<string> | undefined;
2717
2781
 
2718
2782
  /**
2719
2783
  * Builds an {@link AnnotationSpec} `description` (shown in IDE hovers) that ends with an
@@ -2733,7 +2797,7 @@ declare function nonNullishMembers(def: SemanticNode | undefined, doc: AtscriptD
2733
2797
  */
2734
2798
  declare function annotationExample(description: string, ...lines: string[]): string;
2735
2799
 
2736
- declare function resolveAtscriptFromPath(from: string, id: string): string;
2800
+ declare function resolveAtscriptFromPath(written: string, id: string): string;
2737
2801
  declare function fileUriToPath(id: string): string;
2738
2802
  declare function getRelPath(fromUri: string, toUri: string): string;
2739
2803
 
@@ -2743,6 +2807,13 @@ declare function getRelPath(fromUri: string, toUri: string): string;
2743
2807
  * NOT bare: './user', '../shared', '/absolute/path'
2744
2808
  */
2745
2809
  declare function isBareSpecifier(specifier: string): boolean;
2810
+ /**
2811
+ * The import path of an `.as` import as atscript resolves it: without a trailing `.as` extension.
2812
+ * `.as` imports may name a file with or without its extension (`'./user'`, `'./user.as'`,
2813
+ * `'my-lib/models.as'`); both spellings resolve to the same module. A bare package name
2814
+ * (`'my-lib'`, no subpath) is kept as written.
2815
+ */
2816
+ declare function withoutAsExtension(specifier: string): string;
2746
2817
  /**
2747
2818
  * Returns true if the document ID is a bare specifier placeholder.
2748
2819
  */
@@ -2962,5 +3033,5 @@ declare const BACKTICK_ARG_VOCABULARY: {
2962
3033
  */
2963
3034
  declare function moduleId(doc: AtscriptDoc): string;
2964
3035
 
2965
- export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BACKTICK_ARG_VOCABULARY, BuildRepo, DB_ENTITY_ANNOTATIONS, DEFAULT_FORMAT, FLATTEN_WEB, MERGE_CAP, MERGE_TOO_COMPLEX, NAV_PROP_ANNOTATIONS, NOTHING_IN_COMMON, PRODUCT_CAP, PluginManager, SELF_OPERAND, SELF_SPLIT, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticExprBinaryNode, SemanticExprCallNode, SemanticExprNode, SemanticExprNumberNode, SemanticExprUnaryNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticOrderNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, StructureModel, Token, UNION_IN_RECURSIVE_MERGE, analyzeQueryCursorContext, andExprs, annotationExample, baseSlot, blockDependencies, blockTargetDocuments, build, clearResolveBareCache, componentOf, components, createAtscriptPlugin, defPosition, defineConfig, distinctFields, documentsEpoch, entryParts, fieldRefTokens, fileUriToPath, flatDefinitions, forEachAnnotationSpec, getDeclaredValue, getFieldPathCompletionScope, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, getSiblingAnnotation, getValueCandidates, hasMutatingAnnotates, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isAsView, isBacktickArgType, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isImport, isInterface, isNull, isPhantomNode, isPhantomPath, isPhantomPrimitive, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, moduleId, nonNullishMembers, parseBareSpecifier, pastViews, recordDocumentReads, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveFieldRefAt, resolveFieldRefsAt, resolveQueryFieldRef, unshell, unwoundFields };
3036
+ export { $n, ANNOTATE_RESET, AnnotationSpec, AtscriptDoc, AtscriptRepo, BACKTICK_ARG_VOCABULARY, BuildRepo, DB_ENTITY_ANNOTATIONS, DEFAULT_FORMAT, FLATTEN_WEB, MERGE_CAP, MERGE_TOO_COMPLEX, NAV_PROP_ANNOTATIONS, NOTHING_IN_COMMON, OPAQUE_MERGE, PRODUCT_CAP, PluginManager, SELF_OPERAND, SELF_SPLIT, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticExprBinaryNode, SemanticExprCallNode, SemanticExprNode, SemanticExprNumberNode, SemanticExprUnaryNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticOrderNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, StructureModel, Token, UNION_IN_RECURSIVE_MERGE, analyzeQueryCursorContext, andExprs, annotatedValueKinds, annotationExample, baseSlot, blockDependencies, blockTargetDocuments, build, clearResolveBareCache, componentOf, components, createAtscriptPlugin, defPosition, defineConfig, distinctFields, documentsEpoch, entryParts, fieldRefTokens, fileUriToPath, flatDefinitions, forEachAnnotationSpec, getDeclaredValue, getFieldPathCompletionScope, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, getSiblingAnnotation, getValueCandidates, hasMutatingAnnotates, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isAsView, isBacktickArgType, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isImport, isInterface, isNull, isPhantomNode, isPhantomPath, isPhantomPrimitive, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, moduleId, nonNullishMembers, parseBareSpecifier, pastViews, recordDocumentReads, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveFieldRefAt, resolveFieldRefsAt, resolveQueryFieldRef, unshell, unwoundFields, userTextAnnotations, userTextFields, withoutAsExtension };
2966
3037
  export type { SemanticExprItemNode, SemanticQueryExprNode, TAnnotationArgument, TAnnotationSpecConfig, TAnnotationTokens, TAnnotationsTree, TAtscriptConfig, TAtscriptConfigInput, TAtscriptConfigOutput, TAtscriptDocConfig, TAtscriptPlugin, TAtscriptRenderFormat, TAtscriptRenderOptions, TBacktickArgKind, TComponent, TDbConfig, TDbConfigDeclarative, TExprBinaryOperator, TFlatDefinition, TMergeRoot, TMessages, TNodeEntity, TOrderItem, TOutput, TOutputWithSource, TPluginManagers, TPluginOutput, TPrimitiveAnnotationArg, TPrimitiveAnnotationArgs, TPrimitiveAnnotationValue, TPrimitiveBaseConfig, TPrimitiveConfig, TPrimitiveTypeArray, TPrimitiveTypeComplex, TPrimitiveTypeDef, TPrimitiveTypeFinal, TPrimitiveTypeFinalOptional, TPrimitiveTypeObject, TQueryCursorContext, TQueryLogicalOperator, TQueryOperator, TQueryScope, TSemanticToken, TStructBlock, TStructDecl, TStructDef, TStructEntry, TStructError, TStructExpr, TStructLayer, TStructNever, TStructProp, TStructRank, TStructShape, TStructSlot, TUnwound, TUnwoundField, TValueCandidate };