@atscript/core 0.1.31 → 0.1.33

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.cjs CHANGED
@@ -601,7 +601,10 @@ var SemanticPropNode = class extends SemanticNode {
601
601
  registerAtDocument(doc) {
602
602
  super.registerAtDocument(doc);
603
603
  const token = this.token("identifier");
604
- if (token && token.type === "text" && token.multiline) doc.registerMessage(token, "Unexpected end of string");
604
+ if (token) {
605
+ doc.tokensIndex.add(token);
606
+ if (token.type === "text" && token.multiline) doc.registerMessage(token, "Unexpected end of string");
607
+ }
605
608
  }
606
609
  get isPattern() {
607
610
  return !!this.token("identifier")?.pattern;
@@ -2581,7 +2584,49 @@ else {
2581
2584
  }
2582
2585
  return refs;
2583
2586
  }
2584
- if (isProp(token.parentNode)) {} else {
2587
+ if (isProp(token.parentNode)) {
2588
+ const propName$1 = token.parentNode.id;
2589
+ if (!propName$1) return undefined;
2590
+ let parentName;
2591
+ for (const node of this.nodes) if ((isInterface(node) || isStructure(node)) && node.props.get(propName$1) === token.parentNode) {
2592
+ parentName = node.id;
2593
+ break;
2594
+ }
2595
+ if (!parentName) return undefined;
2596
+ const refs = [];
2597
+ const searchDoc = (doc, uri) => {
2598
+ for (const t of doc.referred) {
2599
+ if (t.text !== parentName || !isRef(t.parentNode) || !t.parentNode.hasChain) continue;
2600
+ const chainToken = t.parentNode.chain[0];
2601
+ if (chainToken?.text === propName$1) refs.push({
2602
+ uri,
2603
+ range: chainToken.range,
2604
+ token: chainToken
2605
+ });
2606
+ }
2607
+ for (const node of doc.nodes) {
2608
+ if (!isAnnotate(node) || node.targetName !== parentName) continue;
2609
+ for (const entry of node.entries) if (entry.id === propName$1) {
2610
+ const entryToken = entry.token("identifier");
2611
+ if (entryToken) refs.push({
2612
+ uri,
2613
+ range: entryToken.range,
2614
+ token: entryToken
2615
+ });
2616
+ }
2617
+ }
2618
+ };
2619
+ searchDoc(this, this.id);
2620
+ const parentDefToken = this.registry.definitions.get(parentName);
2621
+ if (parentDefToken?.exported) {
2622
+ const targetName = parentName;
2623
+ for (const d of this.dependants) {
2624
+ const imp = d.imports.get(this.id);
2625
+ if (imp?.imports.find((t) => t.text === targetName)) searchDoc(d, d.id);
2626
+ }
2627
+ }
2628
+ return refs;
2629
+ } else {
2585
2630
  const defForToken = this.getDefinitionFor(token);
2586
2631
  if (defForToken?.token?.isDefinition && defForToken.doc) return defForToken.doc.usageListFor(defForToken.token);
2587
2632
  }
@@ -2655,6 +2700,12 @@ else {
2655
2700
  }];
2656
2701
  return undefined;
2657
2702
  }
2703
+ if (isProp(token.parentNode)) return [{
2704
+ targetUri: this.id,
2705
+ targetRange: token.range,
2706
+ targetSelectionRange: token.range,
2707
+ originSelectionRange: token.range
2708
+ }];
2658
2709
  if (token.isChain && isRef(token.parentNode) && typeof token.index === "number") {
2659
2710
  const id = token.parentNode.id;
2660
2711
  const unwound = this.unwindType(id, token.parentNode.chain.slice(0, token.index));
@@ -2684,14 +2735,14 @@ else {
2684
2735
  this.blocksIndex.add(block$2);
2685
2736
  block$2.blockType = "import";
2686
2737
  block$2.fromPath = from.text;
2738
+ this.tokensIndex.add(from);
2739
+ from.fromPath = from.text;
2687
2740
  imports.forEach((t) => {
2688
2741
  t.imported = true;
2689
2742
  t.fromPath = from.text;
2690
2743
  this.registerDefinition(t, true);
2691
2744
  this.tokensIndex.add(t);
2692
- this.tokensIndex.add(from);
2693
2745
  this.importedDefs.set(t.text, from);
2694
- from.fromPath = from.text;
2695
2746
  });
2696
2747
  }
2697
2748
  nextTypeId() {
@@ -2760,7 +2811,7 @@ else {
2760
2811
  getUnusedTokens() {
2761
2812
  const refSet = new Set(this.referred.filter((r) => !r.imported).map((r) => r.text));
2762
2813
  const tokens$1 = [];
2763
- for (const [key, token] of Array.from(this.registry.definitions.entries())) if (!refSet.has(key) && !this.exports.has(key)) tokens$1.push(token);
2814
+ for (const [key, token] of this.registry.definitions) if (!refSet.has(key) && !this.exports.has(key)) tokens$1.push(token);
2764
2815
  return tokens$1;
2765
2816
  }
2766
2817
  renderDiagMessage(m, addSourceLinses = false, colors = false) {
@@ -2814,7 +2865,7 @@ else {
2814
2865
  l: lines[n - 1],
2815
2866
  i: n - 1
2816
2867
  }
2817
- ].filter(Boolean);
2868
+ ].filter((r) => r.l !== undefined);
2818
2869
  const nl = String(n).length + 1;
2819
2870
  for (const { l, i } of renderLines) {
2820
2871
  const prefix = `${c.dim + c.cyan}${`0${i}`.slice(-nl)} | ${c.reset}`;
@@ -3011,13 +3062,7 @@ else {
3011
3062
  if (!left || !right) return [_left, _right];
3012
3063
  if (isPrimitive(left) && isPrimitive(right)) {
3013
3064
  if (left.config.type === right.config.type) return [left];
3014
- const never$1 = new SemanticRefNode();
3015
- never$1.saveToken(new Token({
3016
- text: "never",
3017
- type: "identifier",
3018
- getRange: () => zeroRange
3019
- }), "identifier");
3020
- return [never$1];
3065
+ return [createSyntheticRef("never")];
3021
3066
  }
3022
3067
  if ((isStructure(left) || isInterface(left)) && (isStructure(right) || isInterface(right))) {
3023
3068
  const mergedProps = [];
@@ -3035,15 +3080,7 @@ else {
3035
3080
  }
3036
3081
  const prop = new SemanticPropNode();
3037
3082
  prop.saveToken((leftProp || rightProp).token("identifier"), "identifier");
3038
- if (isPrimitive(mergedDef)) {
3039
- const name = mergedDef.id;
3040
- mergedDef = new SemanticRefNode();
3041
- mergedDef.saveToken(new Token({
3042
- text: name,
3043
- type: "identifier",
3044
- getRange: () => zeroRange
3045
- }), "identifier");
3046
- }
3083
+ if (isPrimitive(mergedDef)) mergedDef = createSyntheticRef(mergedDef.id);
3047
3084
  prop.define(mergedDef);
3048
3085
  prop.annotations = this.mergeNodesAnnotations(leftProp?.annotations, rightProp?.annotations);
3049
3086
  const oldProps = [leftProp, rightProp].filter(Boolean);
@@ -3057,17 +3094,10 @@ else {
3057
3094
  }
3058
3095
  const mergedStructure = new SemanticStructureNode();
3059
3096
  mergedStructure.setProps(mergedProps);
3060
- this.resolveAnnotation;
3061
3097
  mergedStructure.annotations = this.mergeNodesAnnotations(left.annotations, right.annotations);
3062
3098
  return [mergedStructure];
3063
3099
  }
3064
- const never = new SemanticRefNode();
3065
- never.saveToken(new Token({
3066
- text: "never",
3067
- type: "identifier",
3068
- getRange: () => zeroRange
3069
- }), "identifier");
3070
- return [never];
3100
+ return [createSyntheticRef("never")];
3071
3101
  }
3072
3102
  /**
3073
3103
  * Merges two arrays of annotation tokens, ensuring that annotations from the
@@ -3167,10 +3197,47 @@ const zeroRange = {
3167
3197
  character: 0
3168
3198
  }
3169
3199
  };
3200
+ function createSyntheticRef(name) {
3201
+ const ref$1 = new SemanticRefNode();
3202
+ ref$1.saveToken(new Token({
3203
+ text: name,
3204
+ type: "identifier",
3205
+ getRange: () => zeroRange
3206
+ }), "identifier");
3207
+ return ref$1;
3208
+ }
3170
3209
 
3171
3210
  //#endregion
3172
3211
  //#region packages/core/src/defaults/db-annotations.ts
3173
3212
  const dbAnnotations = {
3213
+ patch: { strategy: new AnnotationSpec({
3214
+ description: "Defines the **patching strategy** for updating nested objects.\n\n- **\"replace\"** → The field or object will be **fully replaced**.\n- **\"merge\"** → The field or object will be **merged recursively** (applies only to objects, not arrays).\n\n**Example:**\n```atscript\n@db.patch.strategy \"merge\"\nsettings: {\n notifications: boolean\n preferences: {\n theme: string\n }\n}\n```\n",
3215
+ nodeType: ["prop"],
3216
+ multiple: false,
3217
+ argument: {
3218
+ name: "strategy",
3219
+ type: "string",
3220
+ description: "The **patch strategy** for this field: `\"replace\"` (default) or `\"merge\"`.",
3221
+ values: ["replace", "merge"]
3222
+ },
3223
+ validate(token, args, doc) {
3224
+ const field = token.parentNode;
3225
+ const errors = [];
3226
+ const definition$1 = field.getDefinition();
3227
+ if (!definition$1) return errors;
3228
+ let wrongType = false;
3229
+ if (isRef(definition$1)) {
3230
+ const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
3231
+ if (!isStructure(def) && !isInterface(def) && !isArray(def)) wrongType = true;
3232
+ } else if (!isStructure(definition$1) && !isInterface(definition$1) && !isArray(definition$1)) wrongType = true;
3233
+ if (wrongType) errors.push({
3234
+ message: `@db.patch.strategy requires a field of type object or array`,
3235
+ severity: 1,
3236
+ range: token.range
3237
+ });
3238
+ return errors;
3239
+ }
3240
+ }) },
3174
3241
  table: new AnnotationSpec({
3175
3242
  description: "Marks an interface as a database-persisted entity (table in SQL, collection in MongoDB). If the name argument is omitted, the adapter derives the table name from the interface name.\n\n**Example:**\n```atscript\n@db.table \"users\"\nexport interface User { ... }\n```\n",
3176
3243
  nodeType: ["interface"],
@@ -3222,16 +3289,21 @@ const dbAnnotations = {
3222
3289
  }
3223
3290
  }),
3224
3291
  fulltext: new AnnotationSpec({
3225
- description: "Full-text search index. Fields sharing the same index name form a composite full-text index.\n\n**Example:**\n```atscript\n@db.index.fulltext \"ft_content\"\ntitle: string\n```\n",
3292
+ description: "Full-text search index. Fields sharing the same index name form a composite full-text index.\n\n**Example:**\n```atscript\n@db.index.fulltext \"ft_content\"\ntitle: string\n\n@db.index.fulltext \"ft_content\", 5\nbio: string\n```\n",
3226
3293
  nodeType: ["prop"],
3227
3294
  multiple: true,
3228
3295
  mergeStrategy: "append",
3229
- argument: {
3296
+ argument: [{
3230
3297
  optional: true,
3231
3298
  name: "name",
3232
3299
  type: "string",
3233
3300
  description: "Index name / composite group name."
3234
- }
3301
+ }, {
3302
+ optional: true,
3303
+ name: "weight",
3304
+ type: "number",
3305
+ description: "Field importance in search results (higher = more relevant). Defaults to `1`. Supported by databases with weighted fulltext (e.g., MongoDB, PostgreSQL)."
3306
+ }]
3235
3307
  })
3236
3308
  },
3237
3309
  column: new AnnotationSpec({
@@ -3519,34 +3591,70 @@ const expectAnnotations = {
3519
3591
  return [];
3520
3592
  }
3521
3593
  }),
3522
- array: { key: new AnnotationSpec({
3523
- description: "Marks a **key field** inside an array. This annotation is used to identify unique fields within an array that can be used as **lookup keys**.\n\n\n\n**Example:**\n```atscript\nexport interface User {\n id: string\n profiles: {\n @expect.array.key\n profileId: string\n name: string\n }[]\n}\n```\n",
3524
- nodeType: ["prop", "type"],
3525
- multiple: false,
3526
- validate(token, args, doc) {
3527
- const field = token.parentNode;
3528
- const errors = [];
3529
- const isOptional = !!field.token("optional");
3530
- if (isOptional) errors.push({
3531
- message: `@expect.array.key can't be optional`,
3532
- severity: 1,
3533
- range: field.token("identifier").range
3534
- });
3535
- const definition$1 = field.getDefinition();
3536
- if (!definition$1) return errors;
3537
- let wrongType = false;
3538
- if (isRef(definition$1)) {
3539
- const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
3540
- if (isPrimitive(def) && !["string", "number"].includes(def.config.type)) wrongType = true;
3541
- } else wrongType = true;
3542
- if (wrongType) errors.push({
3543
- message: `@expect.array.key must be of type string or number`,
3544
- severity: 1,
3545
- range: token.range
3546
- });
3547
- return errors;
3548
- }
3549
- }) }
3594
+ array: {
3595
+ uniqueItems: new AnnotationSpec({
3596
+ description: "Enforces **unique items** in an array field.\n\nWorks with both **primitive arrays** and **object arrays**:\n\n- **Primitive arrays** (`string[]`, `number[]`) — duplicates are detected by deep equality.\n- **Object arrays** — if the element type defines `@expect.array.key` properties, uniqueness is checked by those keys only; otherwise by deep equality of the whole object.\n\nUnlike `@expect.array.key` (which only *identifies* key fields for lookup/patch operations), `@expect.array.uniqueItems` actively *enforces* uniqueness during validation.\n\n**Examples:**\n```atscript\n// Primitive array — no duplicates allowed\n@expect.array.uniqueItems\ntags: string[]\n\n// Object array with keys — unique by key fields\n@expect.array.uniqueItems\nitems: {\n @expect.array.key\n id: string\n value: number\n}[]\n```\n",
3597
+ nodeType: ["prop"],
3598
+ multiple: false,
3599
+ argument: [{
3600
+ name: "message",
3601
+ optional: true,
3602
+ type: "string",
3603
+ description: "Optional custom error message when duplicate items are found."
3604
+ }],
3605
+ validate(token, args, doc) {
3606
+ const field = token.parentNode;
3607
+ const errors = [];
3608
+ const definition$1 = field.getDefinition();
3609
+ if (!definition$1) return errors;
3610
+ let wrongType = false;
3611
+ if (isRef(definition$1)) {
3612
+ const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
3613
+ if (!isArray(def)) wrongType = true;
3614
+ } else if (!isArray(definition$1)) wrongType = true;
3615
+ if (wrongType) errors.push({
3616
+ message: `@expect.array.uniqueItems requires an array field`,
3617
+ severity: 1,
3618
+ range: token.range
3619
+ });
3620
+ return errors;
3621
+ }
3622
+ }),
3623
+ key: new AnnotationSpec({
3624
+ description: "Marks a **key field** inside an array of objects. Key fields *identify* elements for lookup and patch operations (`$upsert`, `$update`, `$remove`).\n\n`@expect.array.key` does **not** enforce uniqueness by itself — it only declares which fields form the element identity. To enforce that no two elements share the same key, also add `@expect.array.uniqueItems` on the array field.\n\nMultiple key fields form a **composite key** (all must match for elements to be considered equal).\n\n**Example:**\n```atscript\n@expect.array.uniqueItems // enforce uniqueness by key\nprofiles: {\n @expect.array.key\n profileId: string\n name: string\n}[]\n```\n",
3625
+ nodeType: ["prop", "type"],
3626
+ multiple: false,
3627
+ argument: [{
3628
+ name: "message",
3629
+ optional: true,
3630
+ type: "string",
3631
+ description: "Optional custom error message (used by @expect.array.uniqueItems when checking key-based uniqueness)."
3632
+ }],
3633
+ validate(token, args, doc) {
3634
+ const field = token.parentNode;
3635
+ const errors = [];
3636
+ const isOptional = !!field.token("optional");
3637
+ if (isOptional) errors.push({
3638
+ message: `@expect.array.key can't be optional`,
3639
+ severity: 1,
3640
+ range: field.token("identifier").range
3641
+ });
3642
+ const definition$1 = field.getDefinition();
3643
+ if (!definition$1) return errors;
3644
+ let wrongType = false;
3645
+ if (isRef(definition$1)) {
3646
+ const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
3647
+ if (isPrimitive(def) && !["string", "number"].includes(def.config.type)) wrongType = true;
3648
+ } else wrongType = true;
3649
+ if (wrongType) errors.push({
3650
+ message: `@expect.array.key must be of type string or number`,
3651
+ severity: 1,
3652
+ range: token.range
3653
+ });
3654
+ return errors;
3655
+ }
3656
+ })
3657
+ }
3550
3658
  };
3551
3659
 
3552
3660
  //#endregion
@@ -3944,31 +4052,22 @@ var PluginManager = class {
3944
4052
  const raw = await this.config();
3945
4053
  this._docConfig = {};
3946
4054
  if (raw?.primitives) {
3947
- this._docConfig.primitives = this._docConfig.primitives || new Map();
4055
+ this._docConfig.primitives = new Map();
3948
4056
  for (const [key, value] of Object.entries(raw.primitives)) this._docConfig.primitives.set(key, new SemanticPrimitiveNode(key, value, "", raw.annotations));
3949
4057
  }
3950
- if (raw?.annotations) {
3951
- this._docConfig.annotations = this._docConfig.annotations || {};
3952
- Object.assign(this._docConfig.annotations, raw.annotations);
3953
- }
4058
+ if (raw?.annotations) this._docConfig.annotations = { ...raw.annotations };
3954
4059
  this._docConfig.unknownAnnotation = raw?.unknownAnnotation;
3955
4060
  }
3956
4061
  return this._docConfig;
3957
4062
  }
3958
4063
  async config(config = this.cfg) {
3959
4064
  if (!this._config) {
3960
- const processed = new Set();
3961
4065
  config = (0, defu.defu)(config, getDefaultAtscriptConfig());
3962
- const filtered = this.plugins.filter((plugin) => !processed.has(plugin.name));
3963
- let i = 0;
3964
- while (processed.size !== filtered.length) {
3965
- i++;
3966
- for (const plugin of filtered) {
3967
- if (processed.has(plugin.name)) continue;
3968
- config = (0, defu.defu)(await plugin.config?.(config), config);
3969
- processed.add(plugin.name);
3970
- }
3971
- if (i > 100) throw new Error(`Too many iterations in config`);
4066
+ const seen = new Set();
4067
+ for (const plugin of this.plugins) {
4068
+ if (seen.has(plugin.name)) continue;
4069
+ seen.add(plugin.name);
4070
+ config = (0, defu.defu)(await plugin.config?.(config), config);
3972
4071
  }
3973
4072
  this._config = config;
3974
4073
  }
@@ -3976,28 +4075,28 @@ var PluginManager = class {
3976
4075
  }
3977
4076
  async resolve(id) {
3978
4077
  let newId = id;
3979
- for (const plugin of this.plugins) if (plugin.resolve) newId = await plugin.resolve(id);
4078
+ for (const plugin of this.plugins) if (plugin.resolve) newId = await plugin.resolve(newId) ?? newId;
3980
4079
  return newId;
3981
4080
  }
3982
4081
  async load(id) {
3983
4082
  const filePath = id.startsWith("file://") ? id.slice(7) : id;
3984
4083
  for (const plugin of this.plugins) if (plugin.load) {
3985
- const content$1 = await plugin.load(id);
3986
- if (content$1) return content$1;
4084
+ const content = await plugin.load(id);
4085
+ if (content) return content;
3987
4086
  }
3988
- const content = await (0, node_fs_promises.readFile)(filePath, "utf8");
3989
- return content.toString();
4087
+ return (0, node_fs_promises.readFile)(filePath, "utf8");
3990
4088
  }
3991
4089
  async onDocument(doc) {
3992
4090
  for (const plugin of this.plugins) if (plugin.onDocument) await plugin.onDocument(doc);
3993
4091
  }
3994
4092
  async render(doc, format) {
4093
+ const source = doc.id.startsWith("file://") ? doc.id.slice(7) : doc.id;
3995
4094
  const files = [];
3996
4095
  for (const plugin of this.plugins) if (plugin.render) {
3997
4096
  const newFiles = await plugin.render(doc, format);
3998
4097
  if (newFiles?.length > 0) files.push(...newFiles.map((f) => ({
3999
4098
  ...f,
4000
- source: doc.id.startsWith("file://") ? doc.id.slice(7) : doc.id
4099
+ source
4001
4100
  })));
4002
4101
  }
4003
4102
  return files;
@@ -4131,17 +4230,16 @@ else types.push({ type: "boolean" });
4131
4230
  }
4132
4231
  const configFile = await resolveConfigFile(id, this.root);
4133
4232
  if (configFile) {
4134
- const globalPathToConfig = configFile;
4135
- if (!this.configFiles.has(globalPathToConfig)) {
4233
+ if (!this.configFiles.has(configFile)) {
4136
4234
  const rawConfigPromise = loadConfig(configFile, this.configFormat);
4137
- this.configFiles.set(globalPathToConfig, rawConfigPromise);
4235
+ this.configFiles.set(configFile, rawConfigPromise);
4138
4236
  }
4139
- const rawConfig = await this.configFiles.get(globalPathToConfig);
4237
+ const rawConfig = await this.configFiles.get(configFile);
4140
4238
  if (!rawConfig.rootDir) rawConfig.rootDir = node_path.default.dirname(configFile);
4141
4239
  const manager = new PluginManager(rawConfig);
4142
4240
  await manager.getDocConfig();
4143
4241
  return {
4144
- file: globalPathToConfig,
4242
+ file: configFile,
4145
4243
  manager,
4146
4244
  dependants: new Set()
4147
4245
  };
@@ -4168,10 +4266,13 @@ else types.push({ type: "boolean" });
4168
4266
  async openDocument(id, text$2) {
4169
4267
  let atscript = this.atscripts.get(id);
4170
4268
  if (atscript) {
4171
- if (text$2) atscript.then((d) => {
4172
- d.update(text$2);
4173
- return d;
4174
- });
4269
+ if (text$2) {
4270
+ atscript = atscript.then((d) => {
4271
+ d.update(text$2);
4272
+ return d;
4273
+ });
4274
+ this.atscripts.set(id, atscript);
4275
+ }
4175
4276
  } else {
4176
4277
  atscript = this._openDocument(id, text$2);
4177
4278
  atscript.catch(() => {
@@ -4625,6 +4726,7 @@ exports.isConst = isConst
4625
4726
  exports.isGroup = isGroup
4626
4727
  exports.isImport = isImport
4627
4728
  exports.isInterface = isInterface
4729
+ exports.isPhantomNode = isPhantomNode
4628
4730
  exports.isPrimitive = isPrimitive
4629
4731
  exports.isProp = isProp
4630
4732
  exports.isRef = isRef
package/dist/index.d.ts CHANGED
@@ -217,7 +217,7 @@ declare class PluginManager {
217
217
  get plugins(): TAtscriptPlugin[];
218
218
  getDocConfig(): Promise<TAtscriptDocConfig>;
219
219
  config(config?: TAtscriptConfig): Promise<TAtscriptConfig>;
220
- resolve(id: string): Promise<string | undefined>;
220
+ resolve(id: string): Promise<string>;
221
221
  load(id: string): Promise<string>;
222
222
  onDocument(doc: AtscriptDoc): Promise<void>;
223
223
  render(doc: AtscriptDoc, format: TAtscriptRenderFormat): Promise<TOutputWithSource[]>;
@@ -825,6 +825,7 @@ interface TFlatFieldDescriptor {
825
825
  * @returns A map of dot-separated paths to their field descriptors.
826
826
  */
827
827
  declare function flattenInterfaceNode(doc: AtscriptDoc, node: SemanticInterfaceNode): Map<string, TFlatFieldDescriptor>;
828
+ declare function isPhantomNode(doc: AtscriptDoc, def?: SemanticNode): boolean;
828
829
 
829
- 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, isPrimitive, isProp, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile };
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 };
830
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 };
package/dist/index.mjs CHANGED
@@ -577,7 +577,10 @@ var SemanticPropNode = class extends SemanticNode {
577
577
  registerAtDocument(doc) {
578
578
  super.registerAtDocument(doc);
579
579
  const token = this.token("identifier");
580
- if (token && token.type === "text" && token.multiline) doc.registerMessage(token, "Unexpected end of string");
580
+ if (token) {
581
+ doc.tokensIndex.add(token);
582
+ if (token.type === "text" && token.multiline) doc.registerMessage(token, "Unexpected end of string");
583
+ }
581
584
  }
582
585
  get isPattern() {
583
586
  return !!this.token("identifier")?.pattern;
@@ -2557,7 +2560,49 @@ else {
2557
2560
  }
2558
2561
  return refs;
2559
2562
  }
2560
- if (isProp(token.parentNode)) {} else {
2563
+ if (isProp(token.parentNode)) {
2564
+ const propName$1 = token.parentNode.id;
2565
+ if (!propName$1) return undefined;
2566
+ let parentName;
2567
+ for (const node of this.nodes) if ((isInterface(node) || isStructure(node)) && node.props.get(propName$1) === token.parentNode) {
2568
+ parentName = node.id;
2569
+ break;
2570
+ }
2571
+ if (!parentName) return undefined;
2572
+ const refs = [];
2573
+ const searchDoc = (doc, uri) => {
2574
+ for (const t of doc.referred) {
2575
+ if (t.text !== parentName || !isRef(t.parentNode) || !t.parentNode.hasChain) continue;
2576
+ const chainToken = t.parentNode.chain[0];
2577
+ if (chainToken?.text === propName$1) refs.push({
2578
+ uri,
2579
+ range: chainToken.range,
2580
+ token: chainToken
2581
+ });
2582
+ }
2583
+ for (const node of doc.nodes) {
2584
+ if (!isAnnotate(node) || node.targetName !== parentName) continue;
2585
+ for (const entry of node.entries) if (entry.id === propName$1) {
2586
+ const entryToken = entry.token("identifier");
2587
+ if (entryToken) refs.push({
2588
+ uri,
2589
+ range: entryToken.range,
2590
+ token: entryToken
2591
+ });
2592
+ }
2593
+ }
2594
+ };
2595
+ searchDoc(this, this.id);
2596
+ const parentDefToken = this.registry.definitions.get(parentName);
2597
+ if (parentDefToken?.exported) {
2598
+ const targetName = parentName;
2599
+ for (const d of this.dependants) {
2600
+ const imp = d.imports.get(this.id);
2601
+ if (imp?.imports.find((t) => t.text === targetName)) searchDoc(d, d.id);
2602
+ }
2603
+ }
2604
+ return refs;
2605
+ } else {
2561
2606
  const defForToken = this.getDefinitionFor(token);
2562
2607
  if (defForToken?.token?.isDefinition && defForToken.doc) return defForToken.doc.usageListFor(defForToken.token);
2563
2608
  }
@@ -2631,6 +2676,12 @@ else {
2631
2676
  }];
2632
2677
  return undefined;
2633
2678
  }
2679
+ if (isProp(token.parentNode)) return [{
2680
+ targetUri: this.id,
2681
+ targetRange: token.range,
2682
+ targetSelectionRange: token.range,
2683
+ originSelectionRange: token.range
2684
+ }];
2634
2685
  if (token.isChain && isRef(token.parentNode) && typeof token.index === "number") {
2635
2686
  const id = token.parentNode.id;
2636
2687
  const unwound = this.unwindType(id, token.parentNode.chain.slice(0, token.index));
@@ -2660,14 +2711,14 @@ else {
2660
2711
  this.blocksIndex.add(block$2);
2661
2712
  block$2.blockType = "import";
2662
2713
  block$2.fromPath = from.text;
2714
+ this.tokensIndex.add(from);
2715
+ from.fromPath = from.text;
2663
2716
  imports.forEach((t) => {
2664
2717
  t.imported = true;
2665
2718
  t.fromPath = from.text;
2666
2719
  this.registerDefinition(t, true);
2667
2720
  this.tokensIndex.add(t);
2668
- this.tokensIndex.add(from);
2669
2721
  this.importedDefs.set(t.text, from);
2670
- from.fromPath = from.text;
2671
2722
  });
2672
2723
  }
2673
2724
  nextTypeId() {
@@ -2736,7 +2787,7 @@ else {
2736
2787
  getUnusedTokens() {
2737
2788
  const refSet = new Set(this.referred.filter((r) => !r.imported).map((r) => r.text));
2738
2789
  const tokens$1 = [];
2739
- for (const [key, token] of Array.from(this.registry.definitions.entries())) if (!refSet.has(key) && !this.exports.has(key)) tokens$1.push(token);
2790
+ for (const [key, token] of this.registry.definitions) if (!refSet.has(key) && !this.exports.has(key)) tokens$1.push(token);
2740
2791
  return tokens$1;
2741
2792
  }
2742
2793
  renderDiagMessage(m, addSourceLinses = false, colors = false) {
@@ -2790,7 +2841,7 @@ else {
2790
2841
  l: lines[n - 1],
2791
2842
  i: n - 1
2792
2843
  }
2793
- ].filter(Boolean);
2844
+ ].filter((r) => r.l !== undefined);
2794
2845
  const nl = String(n).length + 1;
2795
2846
  for (const { l, i } of renderLines) {
2796
2847
  const prefix = `${c.dim + c.cyan}${`0${i}`.slice(-nl)} | ${c.reset}`;
@@ -2987,13 +3038,7 @@ else {
2987
3038
  if (!left || !right) return [_left, _right];
2988
3039
  if (isPrimitive(left) && isPrimitive(right)) {
2989
3040
  if (left.config.type === right.config.type) return [left];
2990
- const never$1 = new SemanticRefNode();
2991
- never$1.saveToken(new Token({
2992
- text: "never",
2993
- type: "identifier",
2994
- getRange: () => zeroRange
2995
- }), "identifier");
2996
- return [never$1];
3041
+ return [createSyntheticRef("never")];
2997
3042
  }
2998
3043
  if ((isStructure(left) || isInterface(left)) && (isStructure(right) || isInterface(right))) {
2999
3044
  const mergedProps = [];
@@ -3011,15 +3056,7 @@ else {
3011
3056
  }
3012
3057
  const prop = new SemanticPropNode();
3013
3058
  prop.saveToken((leftProp || rightProp).token("identifier"), "identifier");
3014
- if (isPrimitive(mergedDef)) {
3015
- const name = mergedDef.id;
3016
- mergedDef = new SemanticRefNode();
3017
- mergedDef.saveToken(new Token({
3018
- text: name,
3019
- type: "identifier",
3020
- getRange: () => zeroRange
3021
- }), "identifier");
3022
- }
3059
+ if (isPrimitive(mergedDef)) mergedDef = createSyntheticRef(mergedDef.id);
3023
3060
  prop.define(mergedDef);
3024
3061
  prop.annotations = this.mergeNodesAnnotations(leftProp?.annotations, rightProp?.annotations);
3025
3062
  const oldProps = [leftProp, rightProp].filter(Boolean);
@@ -3033,17 +3070,10 @@ else {
3033
3070
  }
3034
3071
  const mergedStructure = new SemanticStructureNode();
3035
3072
  mergedStructure.setProps(mergedProps);
3036
- this.resolveAnnotation;
3037
3073
  mergedStructure.annotations = this.mergeNodesAnnotations(left.annotations, right.annotations);
3038
3074
  return [mergedStructure];
3039
3075
  }
3040
- const never = new SemanticRefNode();
3041
- never.saveToken(new Token({
3042
- text: "never",
3043
- type: "identifier",
3044
- getRange: () => zeroRange
3045
- }), "identifier");
3046
- return [never];
3076
+ return [createSyntheticRef("never")];
3047
3077
  }
3048
3078
  /**
3049
3079
  * Merges two arrays of annotation tokens, ensuring that annotations from the
@@ -3143,10 +3173,47 @@ const zeroRange = {
3143
3173
  character: 0
3144
3174
  }
3145
3175
  };
3176
+ function createSyntheticRef(name) {
3177
+ const ref$1 = new SemanticRefNode();
3178
+ ref$1.saveToken(new Token({
3179
+ text: name,
3180
+ type: "identifier",
3181
+ getRange: () => zeroRange
3182
+ }), "identifier");
3183
+ return ref$1;
3184
+ }
3146
3185
 
3147
3186
  //#endregion
3148
3187
  //#region packages/core/src/defaults/db-annotations.ts
3149
3188
  const dbAnnotations = {
3189
+ patch: { strategy: new AnnotationSpec({
3190
+ description: "Defines the **patching strategy** for updating nested objects.\n\n- **\"replace\"** → The field or object will be **fully replaced**.\n- **\"merge\"** → The field or object will be **merged recursively** (applies only to objects, not arrays).\n\n**Example:**\n```atscript\n@db.patch.strategy \"merge\"\nsettings: {\n notifications: boolean\n preferences: {\n theme: string\n }\n}\n```\n",
3191
+ nodeType: ["prop"],
3192
+ multiple: false,
3193
+ argument: {
3194
+ name: "strategy",
3195
+ type: "string",
3196
+ description: "The **patch strategy** for this field: `\"replace\"` (default) or `\"merge\"`.",
3197
+ values: ["replace", "merge"]
3198
+ },
3199
+ validate(token, args, doc) {
3200
+ const field = token.parentNode;
3201
+ const errors = [];
3202
+ const definition$1 = field.getDefinition();
3203
+ if (!definition$1) return errors;
3204
+ let wrongType = false;
3205
+ if (isRef(definition$1)) {
3206
+ const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
3207
+ if (!isStructure(def) && !isInterface(def) && !isArray(def)) wrongType = true;
3208
+ } else if (!isStructure(definition$1) && !isInterface(definition$1) && !isArray(definition$1)) wrongType = true;
3209
+ if (wrongType) errors.push({
3210
+ message: `@db.patch.strategy requires a field of type object or array`,
3211
+ severity: 1,
3212
+ range: token.range
3213
+ });
3214
+ return errors;
3215
+ }
3216
+ }) },
3150
3217
  table: new AnnotationSpec({
3151
3218
  description: "Marks an interface as a database-persisted entity (table in SQL, collection in MongoDB). If the name argument is omitted, the adapter derives the table name from the interface name.\n\n**Example:**\n```atscript\n@db.table \"users\"\nexport interface User { ... }\n```\n",
3152
3219
  nodeType: ["interface"],
@@ -3198,16 +3265,21 @@ const dbAnnotations = {
3198
3265
  }
3199
3266
  }),
3200
3267
  fulltext: new AnnotationSpec({
3201
- description: "Full-text search index. Fields sharing the same index name form a composite full-text index.\n\n**Example:**\n```atscript\n@db.index.fulltext \"ft_content\"\ntitle: string\n```\n",
3268
+ description: "Full-text search index. Fields sharing the same index name form a composite full-text index.\n\n**Example:**\n```atscript\n@db.index.fulltext \"ft_content\"\ntitle: string\n\n@db.index.fulltext \"ft_content\", 5\nbio: string\n```\n",
3202
3269
  nodeType: ["prop"],
3203
3270
  multiple: true,
3204
3271
  mergeStrategy: "append",
3205
- argument: {
3272
+ argument: [{
3206
3273
  optional: true,
3207
3274
  name: "name",
3208
3275
  type: "string",
3209
3276
  description: "Index name / composite group name."
3210
- }
3277
+ }, {
3278
+ optional: true,
3279
+ name: "weight",
3280
+ type: "number",
3281
+ description: "Field importance in search results (higher = more relevant). Defaults to `1`. Supported by databases with weighted fulltext (e.g., MongoDB, PostgreSQL)."
3282
+ }]
3211
3283
  })
3212
3284
  },
3213
3285
  column: new AnnotationSpec({
@@ -3495,34 +3567,70 @@ const expectAnnotations = {
3495
3567
  return [];
3496
3568
  }
3497
3569
  }),
3498
- array: { key: new AnnotationSpec({
3499
- description: "Marks a **key field** inside an array. This annotation is used to identify unique fields within an array that can be used as **lookup keys**.\n\n\n\n**Example:**\n```atscript\nexport interface User {\n id: string\n profiles: {\n @expect.array.key\n profileId: string\n name: string\n }[]\n}\n```\n",
3500
- nodeType: ["prop", "type"],
3501
- multiple: false,
3502
- validate(token, args, doc) {
3503
- const field = token.parentNode;
3504
- const errors = [];
3505
- const isOptional = !!field.token("optional");
3506
- if (isOptional) errors.push({
3507
- message: `@expect.array.key can't be optional`,
3508
- severity: 1,
3509
- range: field.token("identifier").range
3510
- });
3511
- const definition$1 = field.getDefinition();
3512
- if (!definition$1) return errors;
3513
- let wrongType = false;
3514
- if (isRef(definition$1)) {
3515
- const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
3516
- if (isPrimitive(def) && !["string", "number"].includes(def.config.type)) wrongType = true;
3517
- } else wrongType = true;
3518
- if (wrongType) errors.push({
3519
- message: `@expect.array.key must be of type string or number`,
3520
- severity: 1,
3521
- range: token.range
3522
- });
3523
- return errors;
3524
- }
3525
- }) }
3570
+ array: {
3571
+ uniqueItems: new AnnotationSpec({
3572
+ description: "Enforces **unique items** in an array field.\n\nWorks with both **primitive arrays** and **object arrays**:\n\n- **Primitive arrays** (`string[]`, `number[]`) — duplicates are detected by deep equality.\n- **Object arrays** — if the element type defines `@expect.array.key` properties, uniqueness is checked by those keys only; otherwise by deep equality of the whole object.\n\nUnlike `@expect.array.key` (which only *identifies* key fields for lookup/patch operations), `@expect.array.uniqueItems` actively *enforces* uniqueness during validation.\n\n**Examples:**\n```atscript\n// Primitive array — no duplicates allowed\n@expect.array.uniqueItems\ntags: string[]\n\n// Object array with keys — unique by key fields\n@expect.array.uniqueItems\nitems: {\n @expect.array.key\n id: string\n value: number\n}[]\n```\n",
3573
+ nodeType: ["prop"],
3574
+ multiple: false,
3575
+ argument: [{
3576
+ name: "message",
3577
+ optional: true,
3578
+ type: "string",
3579
+ description: "Optional custom error message when duplicate items are found."
3580
+ }],
3581
+ validate(token, args, doc) {
3582
+ const field = token.parentNode;
3583
+ const errors = [];
3584
+ const definition$1 = field.getDefinition();
3585
+ if (!definition$1) return errors;
3586
+ let wrongType = false;
3587
+ if (isRef(definition$1)) {
3588
+ const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
3589
+ if (!isArray(def)) wrongType = true;
3590
+ } else if (!isArray(definition$1)) wrongType = true;
3591
+ if (wrongType) errors.push({
3592
+ message: `@expect.array.uniqueItems requires an array field`,
3593
+ severity: 1,
3594
+ range: token.range
3595
+ });
3596
+ return errors;
3597
+ }
3598
+ }),
3599
+ key: new AnnotationSpec({
3600
+ description: "Marks a **key field** inside an array of objects. Key fields *identify* elements for lookup and patch operations (`$upsert`, `$update`, `$remove`).\n\n`@expect.array.key` does **not** enforce uniqueness by itself — it only declares which fields form the element identity. To enforce that no two elements share the same key, also add `@expect.array.uniqueItems` on the array field.\n\nMultiple key fields form a **composite key** (all must match for elements to be considered equal).\n\n**Example:**\n```atscript\n@expect.array.uniqueItems // enforce uniqueness by key\nprofiles: {\n @expect.array.key\n profileId: string\n name: string\n}[]\n```\n",
3601
+ nodeType: ["prop", "type"],
3602
+ multiple: false,
3603
+ argument: [{
3604
+ name: "message",
3605
+ optional: true,
3606
+ type: "string",
3607
+ description: "Optional custom error message (used by @expect.array.uniqueItems when checking key-based uniqueness)."
3608
+ }],
3609
+ validate(token, args, doc) {
3610
+ const field = token.parentNode;
3611
+ const errors = [];
3612
+ const isOptional = !!field.token("optional");
3613
+ if (isOptional) errors.push({
3614
+ message: `@expect.array.key can't be optional`,
3615
+ severity: 1,
3616
+ range: field.token("identifier").range
3617
+ });
3618
+ const definition$1 = field.getDefinition();
3619
+ if (!definition$1) return errors;
3620
+ let wrongType = false;
3621
+ if (isRef(definition$1)) {
3622
+ const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
3623
+ if (isPrimitive(def) && !["string", "number"].includes(def.config.type)) wrongType = true;
3624
+ } else wrongType = true;
3625
+ if (wrongType) errors.push({
3626
+ message: `@expect.array.key must be of type string or number`,
3627
+ severity: 1,
3628
+ range: token.range
3629
+ });
3630
+ return errors;
3631
+ }
3632
+ })
3633
+ }
3526
3634
  };
3527
3635
 
3528
3636
  //#endregion
@@ -3920,31 +4028,22 @@ var PluginManager = class {
3920
4028
  const raw = await this.config();
3921
4029
  this._docConfig = {};
3922
4030
  if (raw?.primitives) {
3923
- this._docConfig.primitives = this._docConfig.primitives || new Map();
4031
+ this._docConfig.primitives = new Map();
3924
4032
  for (const [key, value] of Object.entries(raw.primitives)) this._docConfig.primitives.set(key, new SemanticPrimitiveNode(key, value, "", raw.annotations));
3925
4033
  }
3926
- if (raw?.annotations) {
3927
- this._docConfig.annotations = this._docConfig.annotations || {};
3928
- Object.assign(this._docConfig.annotations, raw.annotations);
3929
- }
4034
+ if (raw?.annotations) this._docConfig.annotations = { ...raw.annotations };
3930
4035
  this._docConfig.unknownAnnotation = raw?.unknownAnnotation;
3931
4036
  }
3932
4037
  return this._docConfig;
3933
4038
  }
3934
4039
  async config(config = this.cfg) {
3935
4040
  if (!this._config) {
3936
- const processed = new Set();
3937
4041
  config = defu(config, getDefaultAtscriptConfig());
3938
- const filtered = this.plugins.filter((plugin) => !processed.has(plugin.name));
3939
- let i = 0;
3940
- while (processed.size !== filtered.length) {
3941
- i++;
3942
- for (const plugin of filtered) {
3943
- if (processed.has(plugin.name)) continue;
3944
- config = defu(await plugin.config?.(config), config);
3945
- processed.add(plugin.name);
3946
- }
3947
- if (i > 100) throw new Error(`Too many iterations in config`);
4042
+ const seen = new Set();
4043
+ for (const plugin of this.plugins) {
4044
+ if (seen.has(plugin.name)) continue;
4045
+ seen.add(plugin.name);
4046
+ config = defu(await plugin.config?.(config), config);
3948
4047
  }
3949
4048
  this._config = config;
3950
4049
  }
@@ -3952,28 +4051,28 @@ var PluginManager = class {
3952
4051
  }
3953
4052
  async resolve(id) {
3954
4053
  let newId = id;
3955
- for (const plugin of this.plugins) if (plugin.resolve) newId = await plugin.resolve(id);
4054
+ for (const plugin of this.plugins) if (plugin.resolve) newId = await plugin.resolve(newId) ?? newId;
3956
4055
  return newId;
3957
4056
  }
3958
4057
  async load(id) {
3959
4058
  const filePath = id.startsWith("file://") ? id.slice(7) : id;
3960
4059
  for (const plugin of this.plugins) if (plugin.load) {
3961
- const content$1 = await plugin.load(id);
3962
- if (content$1) return content$1;
4060
+ const content = await plugin.load(id);
4061
+ if (content) return content;
3963
4062
  }
3964
- const content = await readFile(filePath, "utf8");
3965
- return content.toString();
4063
+ return readFile(filePath, "utf8");
3966
4064
  }
3967
4065
  async onDocument(doc) {
3968
4066
  for (const plugin of this.plugins) if (plugin.onDocument) await plugin.onDocument(doc);
3969
4067
  }
3970
4068
  async render(doc, format) {
4069
+ const source = doc.id.startsWith("file://") ? doc.id.slice(7) : doc.id;
3971
4070
  const files = [];
3972
4071
  for (const plugin of this.plugins) if (plugin.render) {
3973
4072
  const newFiles = await plugin.render(doc, format);
3974
4073
  if (newFiles?.length > 0) files.push(...newFiles.map((f) => ({
3975
4074
  ...f,
3976
- source: doc.id.startsWith("file://") ? doc.id.slice(7) : doc.id
4075
+ source
3977
4076
  })));
3978
4077
  }
3979
4078
  return files;
@@ -4107,17 +4206,16 @@ else types.push({ type: "boolean" });
4107
4206
  }
4108
4207
  const configFile = await resolveConfigFile(id, this.root);
4109
4208
  if (configFile) {
4110
- const globalPathToConfig = configFile;
4111
- if (!this.configFiles.has(globalPathToConfig)) {
4209
+ if (!this.configFiles.has(configFile)) {
4112
4210
  const rawConfigPromise = loadConfig(configFile, this.configFormat);
4113
- this.configFiles.set(globalPathToConfig, rawConfigPromise);
4211
+ this.configFiles.set(configFile, rawConfigPromise);
4114
4212
  }
4115
- const rawConfig = await this.configFiles.get(globalPathToConfig);
4213
+ const rawConfig = await this.configFiles.get(configFile);
4116
4214
  if (!rawConfig.rootDir) rawConfig.rootDir = path.dirname(configFile);
4117
4215
  const manager = new PluginManager(rawConfig);
4118
4216
  await manager.getDocConfig();
4119
4217
  return {
4120
- file: globalPathToConfig,
4218
+ file: configFile,
4121
4219
  manager,
4122
4220
  dependants: new Set()
4123
4221
  };
@@ -4144,10 +4242,13 @@ else types.push({ type: "boolean" });
4144
4242
  async openDocument(id, text$2) {
4145
4243
  let atscript = this.atscripts.get(id);
4146
4244
  if (atscript) {
4147
- if (text$2) atscript.then((d) => {
4148
- d.update(text$2);
4149
- return d;
4150
- });
4245
+ if (text$2) {
4246
+ atscript = atscript.then((d) => {
4247
+ d.update(text$2);
4248
+ return d;
4249
+ });
4250
+ this.atscripts.set(id, atscript);
4251
+ }
4151
4252
  } else {
4152
4253
  atscript = this._openDocument(id, text$2);
4153
4254
  atscript.catch(() => {
@@ -4568,4 +4669,4 @@ else if (isGroup(def) && def.entity !== "structure") {
4568
4669
  }
4569
4670
 
4570
4671
  //#endregion
4571
- 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, isPrimitive, isProp, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile };
4672
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/core",
3
- "version": "0.1.31",
3
+ "version": "0.1.33",
4
4
  "description": "Core library for Atscript parsing and file generation.",
5
5
  "keywords": [
6
6
  "annotations",
@@ -28,7 +28,8 @@
28
28
  | `@expect.max` | `maxValue: number`, `message?: string` | no | number | Maximum value |
29
29
  | `@expect.int` | _(none)_ | no | number | Must be integer |
30
30
  | `@expect.pattern` | `pattern: string`, `flags?: string`, `message?: string` | **yes** (append) | string | Regex validation |
31
- | `@expect.array.key` | _(none)_ | no | string, number | Key field in arrays |
31
+ | `@expect.array.key` | `message?: string` | no | string, number | Key field in arrays (non-optional, string/number only). Multiple = composite key |
32
+ | `@expect.array.uniqueItems` | `message?: string` | no | array | No duplicate items (by key fields or deep equality) |
32
33
 
33
34
  ### `@ui.*` — UI / Presentation Hints
34
35