@atscript/core 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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  interface TLexicalToken {
2
- type: 'annotation' | 'comment' | 'punctuation' | 'identifier' | 'text' | 'number' | 'block' | 'unknown' | 'regexp';
2
+ type: 'annotation' | 'comment' | 'punctuation' | 'identifier' | 'text' | 'number' | 'block' | 'unknown' | 'regexp' | 'query';
3
3
  text: string;
4
4
  children?: TLexicalToken[];
5
5
  startOffset?: number;
@@ -48,7 +48,7 @@ declare class Token {
48
48
  toString(): string;
49
49
  clone(replace: Partial<TLexicalToken>): Token;
50
50
  get text(): string;
51
- get type(): "number" | "annotation" | "comment" | "punctuation" | "identifier" | "text" | "block" | "unknown" | "regexp";
51
+ get type(): "number" | "annotation" | "comment" | "punctuation" | "identifier" | "text" | "block" | "unknown" | "regexp" | "query";
52
52
  get range(): {
53
53
  start: {
54
54
  line: number;
@@ -104,6 +104,10 @@ declare class Token {
104
104
  * Block type
105
105
  */
106
106
  blockType?: 'structure' | 'type' | 'import' | 'annotate';
107
+ /**
108
+ * Parsed query expression tree (for query-type annotation arguments)
109
+ */
110
+ queryNode?: SemanticQueryNode;
107
111
  }
108
112
 
109
113
  interface TPluginManagers {
@@ -139,11 +143,11 @@ declare class AtscriptRepo {
139
143
  type: "object";
140
144
  props: Record<string, {
141
145
  optional?: boolean;
142
- type: "string" | "number" | "boolean" | "unknown";
146
+ type: string;
143
147
  }>;
144
148
  } | {
145
149
  optional?: boolean;
146
- type: "string" | "number" | "boolean" | "unknown";
150
+ type: string;
147
151
  }>;
148
152
  } | undefined>>;
149
153
  loadPluginManagerFor(id: string): Promise<TPluginManagers>;
@@ -240,7 +244,7 @@ declare class IdRegistry {
240
244
  }
241
245
 
242
246
  type TSemanticToken = 'type' | 'identifier' | 'array' | 'export' | 'optional' | 'inner' | 'path' | 'from' | 'target';
243
- type TNodeEntity = 'interface' | 'type' | 'ref' | 'const' | 'prop' | 'structure' | 'tuple' | 'group' | 'array' | 'import' | 'primitive' | 'annotate';
247
+ type TNodeEntity = 'interface' | 'type' | 'ref' | 'const' | 'prop' | 'structure' | 'tuple' | 'group' | 'array' | 'import' | 'primitive' | 'annotate' | 'query';
244
248
  interface TAnnotationTokens {
245
249
  name: string;
246
250
  token: Token;
@@ -292,6 +296,7 @@ declare class SemanticNode {
292
296
  annotations?: TAnnotationTokens[];
293
297
  annotationsCounter?: Map<string, number>;
294
298
  __typeId?: number;
299
+ ownerNode?: SemanticNode;
295
300
  registerAtDocument(doc: AtscriptDoc): void;
296
301
  protected _documentation?: string;
297
302
  setDocumentation(s: string): void;
@@ -328,6 +333,15 @@ declare class SemanticRefNode extends SemanticNode {
328
333
  toString(level?: number, prefix?: string): string;
329
334
  }
330
335
 
336
+ declare class SemanticAnnotateNode extends SemanticNode {
337
+ constructor();
338
+ get isMutating(): boolean;
339
+ get targetName(): string;
340
+ get entries(): SemanticRefNode[];
341
+ get id(): string;
342
+ registerAtDocument(doc: AtscriptDoc): void;
343
+ }
344
+
331
345
  declare class SemanticPropNode extends SemanticNode {
332
346
  constructor();
333
347
  registerAtDocument(doc: AtscriptDoc): void;
@@ -439,6 +453,10 @@ declare class AtscriptDoc {
439
453
  * List of tokens that refer to some type or interface
440
454
  */
441
455
  referred: Token[];
456
+ /**
457
+ * List of query field ref nodes (for find-references support)
458
+ */
459
+ queryFieldRefs: Array<SemanticQueryFieldRefNode>;
442
460
  /**
443
461
  * Map of dependencies (documents) by URI
444
462
  */
@@ -623,12 +641,44 @@ declare class AtscriptDoc {
623
641
  mergeNodesAnnotations(left?: TAnnotationTokens[], right?: TAnnotationTokens[]): TAnnotationTokens[];
624
642
  }
625
643
 
626
- declare class SemanticAnnotateNode extends SemanticNode {
644
+ type TQueryOperator = '=' | '!=' | '>' | '>=' | '<' | '<=' | 'in' | 'not in' | 'matches' | 'exists' | 'not exists';
645
+ type TQueryLogicalOperator = 'and' | 'or' | 'not';
646
+ type SemanticQueryExprNode = SemanticQueryLogicalNode | SemanticQueryComparisonNode;
647
+ declare class SemanticQueryNode extends SemanticNode {
648
+ expression: SemanticQueryExprNode;
649
+ sourceToken: Token;
650
+ constructor();
651
+ registerAtDocument(doc: AtscriptDoc): void;
652
+ private propagateQueryArgToken;
653
+ }
654
+ declare class SemanticQueryLogicalNode extends SemanticNode {
655
+ operator: TQueryLogicalOperator;
656
+ operands: SemanticQueryExprNode[];
657
+ constructor();
658
+ registerAtDocument(doc: AtscriptDoc): void;
659
+ }
660
+ declare class SemanticQueryComparisonNode extends SemanticNode {
661
+ left: SemanticQueryFieldRefNode;
662
+ operator: TQueryOperator;
663
+ right?: SemanticQueryFieldRefNode | SemanticQueryValueNode | SemanticQueryValueListNode;
664
+ constructor();
665
+ registerAtDocument(doc: AtscriptDoc): void;
666
+ }
667
+ declare class SemanticQueryFieldRefNode extends SemanticNode {
668
+ typeRef?: Token;
669
+ fieldRef: Token;
670
+ queryArgToken?: Token;
671
+ constructor();
672
+ registerAtDocument(doc: AtscriptDoc): void;
673
+ }
674
+ declare class SemanticQueryValueNode extends SemanticNode {
675
+ valueToken: Token;
676
+ constructor();
677
+ registerAtDocument(doc: AtscriptDoc): void;
678
+ }
679
+ declare class SemanticQueryValueListNode extends SemanticNode {
680
+ values: SemanticQueryValueNode[];
627
681
  constructor();
628
- get isMutating(): boolean;
629
- get targetName(): string;
630
- get entries(): SemanticRefNode[];
631
- get id(): string;
632
682
  registerAtDocument(doc: AtscriptDoc): void;
633
683
  }
634
684
 
@@ -715,6 +765,18 @@ declare function isImport(node?: SemanticNode): node is SemanticImportNode;
715
765
  declare function isPrimitive(node?: SemanticNode): node is SemanticPrimitiveNode;
716
766
  declare function isAnnotate(node?: SemanticNode): node is SemanticAnnotateNode;
717
767
 
768
+ declare function isQueryLogical(node?: SemanticNode): node is SemanticQueryLogicalNode;
769
+ declare function isQueryComparison(node?: SemanticNode): node is SemanticQueryComparisonNode;
770
+ declare function isQueryFieldRef(node?: SemanticNode): node is SemanticQueryFieldRefNode;
771
+
772
+ interface TDbConfigDeclarative {
773
+ adapter: string;
774
+ connection: string | (() => string | Promise<string>);
775
+ options?: Record<string, unknown>;
776
+ include?: string[];
777
+ exclude?: string[];
778
+ }
779
+ type TDbConfig = (() => unknown | Promise<unknown>) | TDbConfigDeclarative;
718
780
  interface TAtscriptConfigInput {
719
781
  rootDir: string;
720
782
  entries?: string[];
@@ -724,6 +786,7 @@ interface TAtscriptConfigInput {
724
786
  plugins?: TAtscriptPlugin[];
725
787
  include?: string[];
726
788
  exclude?: string[];
789
+ db?: TDbConfig;
727
790
  }
728
791
  interface TAtscriptConfigOutput {
729
792
  format: TAtscriptRenderFormat;
@@ -731,7 +794,8 @@ interface TAtscriptConfigOutput {
731
794
  }
732
795
  type TAtscriptConfig = Partial<TAtscriptConfigInput & TAtscriptConfigOutput>;
733
796
  interface TAnnotationsTree {
734
- [key: string]: AnnotationSpec | TAnnotationsTree;
797
+ $self?: AnnotationSpec;
798
+ [key: string]: AnnotationSpec | TAnnotationsTree | undefined;
735
799
  }
736
800
 
737
801
  /**
@@ -749,7 +813,7 @@ declare function loadConfig(configPath: string, forceFormat?: 'cjs' | 'esm'): Pr
749
813
  interface TAnnotationArgument {
750
814
  optional?: boolean;
751
815
  name: string;
752
- type: 'string' | 'number' | 'boolean';
816
+ type: 'string' | 'number' | 'boolean' | 'ref' | 'query';
753
817
  description?: string;
754
818
  values?: string[];
755
819
  }
@@ -773,7 +837,7 @@ declare class AnnotationSpec {
773
837
  modify(mainToken: Token, args: Token[], doc: AtscriptDoc): void;
774
838
  validate(mainToken: Token, args: Token[], doc: AtscriptDoc): TMessages | undefined;
775
839
  renderDocs(index: number | string): string | undefined;
776
- protected getDefaultValueForType(name: string, type: 'string' | 'number' | 'boolean'): string;
840
+ protected getDefaultValueForType(name: string, type: TAnnotationArgument['type']): string;
777
841
  }
778
842
  declare function isAnnotationSpec(a?: TAnnotationsTree | AnnotationSpec): a is AnnotationSpec;
779
843
  declare function resolveAnnotation(name: string, annotationsTree?: TAnnotationsTree): AnnotationSpec | undefined;
@@ -803,6 +867,10 @@ interface TFlatFieldDescriptor {
803
867
  /** Whether this field has the `@db.json` annotation (stored as JSON string in DB). */
804
868
  dbJson?: boolean;
805
869
  }
870
+ interface TFlattenOptions {
871
+ /** When true, skip properties annotated with @db.rel.to, @db.rel.from, or @db.rel.via. */
872
+ skipNavProps?: boolean;
873
+ }
806
874
  /**
807
875
  * Flattens an interface node into a map of dot-notation paths to their type descriptors.
808
876
  *
@@ -824,8 +892,79 @@ interface TFlatFieldDescriptor {
824
892
  * @param node - The interface node to flatten.
825
893
  * @returns A map of dot-separated paths to their field descriptors.
826
894
  */
827
- declare function flattenInterfaceNode(doc: AtscriptDoc, node: SemanticInterfaceNode): Map<string, TFlatFieldDescriptor>;
895
+ declare function flattenInterfaceNode(doc: AtscriptDoc, node: SemanticInterfaceNode, options?: TFlattenOptions): Map<string, TFlatFieldDescriptor>;
896
+ declare function hasNavPropAnnotation(prop: SemanticPropNode): boolean;
828
897
  declare function isPhantomNode(doc: AtscriptDoc, def?: SemanticNode): boolean;
829
898
 
830
- export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, build, createAtscriptPlugin, defineConfig, flattenInterfaceNode, getRelPath, isAnnotate, isAnnotationSpec, isArray, isConst, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile };
831
- export type { TAnnotationArgument, TAnnotationSpecConfig, TAnnotationTokens, TAnnotationsTree, TAtscriptConfig, TAtscriptConfigInput, TAtscriptConfigOutput, TAtscriptDocConfig, TAtscriptPlugin, TAtscriptRenderFormat, TFlatFieldDescriptor, TMessages, TNodeEntity, TOutput, TOutputWithSource, TPluginManagers, TPluginOutput, TPrimitiveAnnotationArg, TPrimitiveAnnotationArgs, TPrimitiveAnnotationValue, TPrimitiveBaseConfig, TPrimitiveConfig, TPrimitiveTypeArray, TPrimitiveTypeComplex, TPrimitiveTypeDef, TPrimitiveTypeFinal, TPrimitiveTypeFinalOptional, TPrimitiveTypeObject, TSemanticToken };
899
+ /**
900
+ * Validate a ref annotation argument against the document's type registry.
901
+ * Returns diagnostic messages for unknown types or fields.
902
+ */
903
+ declare function validateRefArgument(token: Token, doc: AtscriptDoc, options?: {
904
+ requireDbTable?: boolean;
905
+ }): TMessages;
906
+ interface TFKFieldMatch {
907
+ name: string;
908
+ prop: SemanticPropNode;
909
+ chainRef: {
910
+ type: string;
911
+ field: string;
912
+ };
913
+ }
914
+ /**
915
+ * Find all `@db.rel.FK` fields on a type that reference `targetTypeName`.
916
+ * Resolves `extends` to include inherited fields.
917
+ */
918
+ declare function findFKFieldsPointingTo(doc: AtscriptDoc, iface: SemanticInterfaceNode | SemanticStructureNode, targetTypeName: string, alias?: string): TFKFieldMatch[];
919
+
920
+ interface TQueryScope {
921
+ allowedTypes: string[];
922
+ unqualifiedTarget: string | null;
923
+ }
924
+ /**
925
+ * Determine the allowed type scope for a query arg token
926
+ * by reading sibling annotations on the owner node.
927
+ */
928
+ declare function getQueryScope(queryArgToken: Token, doc: AtscriptDoc): TQueryScope | undefined;
929
+ /**
930
+ * Resolve a query field ref node to a property definition.
931
+ */
932
+ declare function resolveQueryFieldRef(fieldRefNode: SemanticQueryFieldRefNode, doc: AtscriptDoc, scope: TQueryScope): {
933
+ targetUri: string;
934
+ doc: AtscriptDoc;
935
+ prop?: SemanticPropNode;
936
+ } | undefined;
937
+ /**
938
+ * Get fields available for a type (resolving extends/intersections).
939
+ */
940
+ declare function getFieldsForType(doc: AtscriptDoc, typeName: string): SemanticPropNode[];
941
+ /**
942
+ * Get completion scope data for a query context.
943
+ */
944
+ declare function getQueryCompletionScope(queryArgToken: Token, doc: AtscriptDoc): {
945
+ typeNames: string[];
946
+ unqualifiedTarget: string | null;
947
+ getFields: (typeName: string) => SemanticPropNode[];
948
+ } | undefined;
949
+ type TQueryCursorContext = {
950
+ type: 'field-start';
951
+ } | {
952
+ type: 'after-dot';
953
+ typeName: string;
954
+ } | {
955
+ type: 'after-field';
956
+ } | {
957
+ type: 'after-operator';
958
+ } | {
959
+ type: 'after-comparison';
960
+ };
961
+ /**
962
+ * Analyze text inside backticks up to cursor position
963
+ * to determine what kind of completions to offer.
964
+ * Uses lightweight text scanning, not full AST parsing,
965
+ * so it works on incomplete/mid-typing input.
966
+ */
967
+ declare function analyzeQueryCursorContext(textBeforeCursor: string): TQueryCursorContext;
968
+
969
+ export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, build, createAtscriptPlugin, defineConfig, findFKFieldsPointingTo, flattenInterfaceNode, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isConst, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile, resolveQueryFieldRef, validateRefArgument };
970
+ export type { SemanticQueryExprNode, TAnnotationArgument, TAnnotationSpecConfig, TAnnotationTokens, TAnnotationsTree, TAtscriptConfig, TAtscriptConfigInput, TAtscriptConfigOutput, TAtscriptDocConfig, TAtscriptPlugin, TAtscriptRenderFormat, TDbConfig, TDbConfigDeclarative, TFKFieldMatch, TFlatFieldDescriptor, TFlattenOptions, TMessages, TNodeEntity, TOutput, TOutputWithSource, TPluginManagers, TPluginOutput, TPrimitiveAnnotationArg, TPrimitiveAnnotationArgs, TPrimitiveAnnotationValue, TPrimitiveBaseConfig, TPrimitiveConfig, TPrimitiveTypeArray, TPrimitiveTypeComplex, TPrimitiveTypeDef, TPrimitiveTypeFinal, TPrimitiveTypeFinalOptional, TPrimitiveTypeObject, TQueryCursorContext, TQueryLogicalOperator, TQueryOperator, TQueryScope, TSemanticToken };