@atscript/core 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/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;
@@ -329,6 +333,15 @@ declare class SemanticRefNode extends SemanticNode {
329
333
  toString(level?: number, prefix?: string): string;
330
334
  }
331
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
+
332
345
  declare class SemanticPropNode extends SemanticNode {
333
346
  constructor();
334
347
  registerAtDocument(doc: AtscriptDoc): void;
@@ -440,6 +453,10 @@ declare class AtscriptDoc {
440
453
  * List of tokens that refer to some type or interface
441
454
  */
442
455
  referred: Token[];
456
+ /**
457
+ * List of query field ref nodes (for find-references support)
458
+ */
459
+ queryFieldRefs: Array<SemanticQueryFieldRefNode>;
443
460
  /**
444
461
  * Map of dependencies (documents) by URI
445
462
  */
@@ -624,12 +641,44 @@ declare class AtscriptDoc {
624
641
  mergeNodesAnnotations(left?: TAnnotationTokens[], right?: TAnnotationTokens[]): TAnnotationTokens[];
625
642
  }
626
643
 
627
- 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[];
628
681
  constructor();
629
- get isMutating(): boolean;
630
- get targetName(): string;
631
- get entries(): SemanticRefNode[];
632
- get id(): string;
633
682
  registerAtDocument(doc: AtscriptDoc): void;
634
683
  }
635
684
 
@@ -716,6 +765,18 @@ declare function isImport(node?: SemanticNode): node is SemanticImportNode;
716
765
  declare function isPrimitive(node?: SemanticNode): node is SemanticPrimitiveNode;
717
766
  declare function isAnnotate(node?: SemanticNode): node is SemanticAnnotateNode;
718
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;
719
780
  interface TAtscriptConfigInput {
720
781
  rootDir: string;
721
782
  entries?: string[];
@@ -725,6 +786,7 @@ interface TAtscriptConfigInput {
725
786
  plugins?: TAtscriptPlugin[];
726
787
  include?: string[];
727
788
  exclude?: string[];
789
+ db?: TDbConfig;
728
790
  }
729
791
  interface TAtscriptConfigOutput {
730
792
  format: TAtscriptRenderFormat;
@@ -732,7 +794,8 @@ interface TAtscriptConfigOutput {
732
794
  }
733
795
  type TAtscriptConfig = Partial<TAtscriptConfigInput & TAtscriptConfigOutput>;
734
796
  interface TAnnotationsTree {
735
- [key: string]: AnnotationSpec | TAnnotationsTree;
797
+ $self?: AnnotationSpec;
798
+ [key: string]: AnnotationSpec | TAnnotationsTree | undefined;
736
799
  }
737
800
 
738
801
  /**
@@ -750,7 +813,7 @@ declare function loadConfig(configPath: string, forceFormat?: 'cjs' | 'esm'): Pr
750
813
  interface TAnnotationArgument {
751
814
  optional?: boolean;
752
815
  name: string;
753
- type: 'string' | 'number' | 'boolean';
816
+ type: 'string' | 'number' | 'boolean' | 'ref' | 'query';
754
817
  description?: string;
755
818
  values?: string[];
756
819
  }
@@ -774,7 +837,7 @@ declare class AnnotationSpec {
774
837
  modify(mainToken: Token, args: Token[], doc: AtscriptDoc): void;
775
838
  validate(mainToken: Token, args: Token[], doc: AtscriptDoc): TMessages | undefined;
776
839
  renderDocs(index: number | string): string | undefined;
777
- protected getDefaultValueForType(name: string, type: 'string' | 'number' | 'boolean'): string;
840
+ protected getDefaultValueForType(name: string, type: TAnnotationArgument['type']): string;
778
841
  }
779
842
  declare function isAnnotationSpec(a?: TAnnotationsTree | AnnotationSpec): a is AnnotationSpec;
780
843
  declare function resolveAnnotation(name: string, annotationsTree?: TAnnotationsTree): AnnotationSpec | undefined;
@@ -804,6 +867,10 @@ interface TFlatFieldDescriptor {
804
867
  /** Whether this field has the `@db.json` annotation (stored as JSON string in DB). */
805
868
  dbJson?: boolean;
806
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
+ }
807
874
  /**
808
875
  * Flattens an interface node into a map of dot-notation paths to their type descriptors.
809
876
  *
@@ -825,9 +892,17 @@ interface TFlatFieldDescriptor {
825
892
  * @param node - The interface node to flatten.
826
893
  * @returns A map of dot-separated paths to their field descriptors.
827
894
  */
828
- 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;
829
897
  declare function isPhantomNode(doc: AtscriptDoc, def?: SemanticNode): boolean;
830
898
 
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;
831
906
  interface TFKFieldMatch {
832
907
  name: string;
833
908
  prop: SemanticPropNode;
@@ -842,5 +917,54 @@ interface TFKFieldMatch {
842
917
  */
843
918
  declare function findFKFieldsPointingTo(doc: AtscriptDoc, iface: SemanticInterfaceNode | SemanticStructureNode, targetTypeName: string, alias?: string): TFKFieldMatch[];
844
919
 
845
- 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, findFKFieldsPointingTo, flattenInterfaceNode, getRelPath, isAnnotate, isAnnotationSpec, isArray, isConst, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile };
846
- export type { TAnnotationArgument, TAnnotationSpecConfig, TAnnotationTokens, TAnnotationsTree, TAtscriptConfig, TAtscriptConfigInput, TAtscriptConfigOutput, TAtscriptDocConfig, TAtscriptPlugin, TAtscriptRenderFormat, TFKFieldMatch, TFlatFieldDescriptor, TMessages, TNodeEntity, TOutput, TOutputWithSource, TPluginManagers, TPluginOutput, TPrimitiveAnnotationArg, TPrimitiveAnnotationArgs, TPrimitiveAnnotationValue, TPrimitiveBaseConfig, TPrimitiveConfig, TPrimitiveTypeArray, TPrimitiveTypeComplex, TPrimitiveTypeDef, TPrimitiveTypeFinal, TPrimitiveTypeFinalOptional, TPrimitiveTypeObject, TSemanticToken };
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 };