@atscript/core 0.0.15 → 0.0.17

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
@@ -2728,9 +2728,37 @@ const metaAnnotations = {
2728
2728
  multiple: false
2729
2729
  }),
2730
2730
  readonly: new AnnotationSpec({
2731
- description: "Marks a field as **read-only**, preventing modifications after creation.\n\n**Example:**```atscript@meta.readonlycreatedAt: date```",
2731
+ description: "Marks a field as **read-only**.\n\n**Example:**```atscript@meta.readonlycreatedAt: string.date```",
2732
2732
  nodeType: ["prop"],
2733
2733
  multiple: false
2734
+ }),
2735
+ isKey: new AnnotationSpec({
2736
+ 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 @meta.isKey\n profileId: string\n name: string\n }[]\n}\n```\n",
2737
+ nodeType: ["prop"],
2738
+ multiple: false,
2739
+ validate(token, args, doc) {
2740
+ const field = token.parentNode;
2741
+ const errors = [];
2742
+ const isOptional = !!field.token("optional");
2743
+ if (isOptional) errors.push({
2744
+ message: `@meta.isKey can't be optional`,
2745
+ severity: 1,
2746
+ range: field.token("identifier").range
2747
+ });
2748
+ const definition$1 = field.getDefinition();
2749
+ if (!definition$1) return errors;
2750
+ let wrongType = false;
2751
+ if (isRef(definition$1)) {
2752
+ const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
2753
+ if (isPrimitive(def) && !["string", "number"].includes(def.config.type)) wrongType = true;
2754
+ } else wrongType = true;
2755
+ if (wrongType) errors.push({
2756
+ message: `@meta.isKey must be of type string or number`,
2757
+ severity: 1,
2758
+ range: token.range
2759
+ });
2760
+ return errors;
2761
+ }
2734
2762
  })
2735
2763
  };
2736
2764
 
@@ -3211,7 +3239,7 @@ else types.push({ type: "boolean" });
3211
3239
  }
3212
3240
  const configFile = await resolveConfigFile(id, this.root);
3213
3241
  if (configFile) {
3214
- const globalPathToConfig = node_path.default.join(this.root, configFile);
3242
+ const globalPathToConfig = configFile;
3215
3243
  if (!this.configFiles.has(globalPathToConfig)) {
3216
3244
  const rawConfigPromise = loadConfig(configFile, this.configFormat);
3217
3245
  this.configFiles.set(globalPathToConfig, rawConfigPromise);
package/dist/index.mjs CHANGED
@@ -2704,9 +2704,37 @@ const metaAnnotations = {
2704
2704
  multiple: false
2705
2705
  }),
2706
2706
  readonly: new AnnotationSpec({
2707
- description: "Marks a field as **read-only**, preventing modifications after creation.\n\n**Example:**```atscript@meta.readonlycreatedAt: date```",
2707
+ description: "Marks a field as **read-only**.\n\n**Example:**```atscript@meta.readonlycreatedAt: string.date```",
2708
2708
  nodeType: ["prop"],
2709
2709
  multiple: false
2710
+ }),
2711
+ isKey: new AnnotationSpec({
2712
+ 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 @meta.isKey\n profileId: string\n name: string\n }[]\n}\n```\n",
2713
+ nodeType: ["prop"],
2714
+ multiple: false,
2715
+ validate(token, args, doc) {
2716
+ const field = token.parentNode;
2717
+ const errors = [];
2718
+ const isOptional = !!field.token("optional");
2719
+ if (isOptional) errors.push({
2720
+ message: `@meta.isKey can't be optional`,
2721
+ severity: 1,
2722
+ range: field.token("identifier").range
2723
+ });
2724
+ const definition$1 = field.getDefinition();
2725
+ if (!definition$1) return errors;
2726
+ let wrongType = false;
2727
+ if (isRef(definition$1)) {
2728
+ const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
2729
+ if (isPrimitive(def) && !["string", "number"].includes(def.config.type)) wrongType = true;
2730
+ } else wrongType = true;
2731
+ if (wrongType) errors.push({
2732
+ message: `@meta.isKey must be of type string or number`,
2733
+ severity: 1,
2734
+ range: token.range
2735
+ });
2736
+ return errors;
2737
+ }
2710
2738
  })
2711
2739
  };
2712
2740
 
@@ -3187,7 +3215,7 @@ else types.push({ type: "boolean" });
3187
3215
  }
3188
3216
  const configFile = await resolveConfigFile(id, this.root);
3189
3217
  if (configFile) {
3190
- const globalPathToConfig = path.join(this.root, configFile);
3218
+ const globalPathToConfig = configFile;
3191
3219
  if (!this.configFiles.has(globalPathToConfig)) {
3192
3220
  const rawConfigPromise = loadConfig(configFile, this.configFormat);
3193
3221
  this.configFiles.set(globalPathToConfig, rawConfigPromise);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/core",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "Core library for Atscript parsing and file generation.",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",