@atscript/core 0.1.77 → 0.1.79

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
@@ -3271,7 +3271,12 @@ var AtscriptDoc = class {
3271
3271
  return this.manager?.render(this, format);
3272
3272
  }
3273
3273
  resolveAnnotation(name) {
3274
- return resolveAnnotation(name, this.config.annotations);
3274
+ let spec = this._annotationSpecCache.get(name);
3275
+ if (spec === undefined && !this._annotationSpecCache.has(name)) {
3276
+ spec = resolveAnnotation(name, this.config.annotations);
3277
+ this._annotationSpecCache.set(name, spec);
3278
+ }
3279
+ return spec;
3275
3280
  }
3276
3281
  /**
3277
3282
  * Resolve a placeholder import ID (bare:xxx.as) to its actual file:// URI.
@@ -3480,20 +3485,36 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3480
3485
  let right = givenNode.annotations;
3481
3486
  let def = givenNode.getDefinition();
3482
3487
  if (def) {
3483
- if (isRef(def)) {
3484
- const unwound = this.unwindType(def.token("identifier").text, def.chain, (intermediate) => {
3485
- if (intermediate?.annotations) right = this.mergeNodesAnnotations(intermediate.annotations, right);
3488
+ const refDef = isRef(def) ? def : undefined;
3489
+ if (refDef) {
3490
+ const chainNodes = [];
3491
+ const unwound = this.unwindType(refDef.token("identifier").text, refDef.chain, (intermediate) => {
3492
+ if (intermediate?.annotations?.length) chainNodes.push(intermediate);
3486
3493
  });
3494
+ if (unwound?.node && unwound.node !== givenNode && unwound.node.annotations?.length && !chainNodes.includes(unwound.node)) chainNodes.unshift(unwound.node);
3495
+ for (const chainNode of chainNodes) right = this.mergeNodesAnnotations(this.filterPassedWhenReferred(chainNode.annotations), right);
3487
3496
  def = unwound?.def || def;
3488
3497
  }
3489
3498
  if (def) {
3490
3499
  const merged = this.mergeIntersection(def);
3491
- right = this.mergeNodesAnnotations(merged.annotations, right);
3500
+ right = this.mergeNodesAnnotations(refDef ? this.filterPassedWhenReferred(merged.annotations) : merged.annotations, right);
3492
3501
  }
3493
3502
  }
3494
3503
  return right;
3495
3504
  }
3496
3505
  /**
3506
+ * Drops annotations whose spec declares `passedWhenReferred: false` — used
3507
+ * when folding annotations across a ref boundary. Annotations without a
3508
+ * resolvable spec pass through (default is to inherit). Returns the input
3509
+ * array unchanged when nothing is dropped.
3510
+ */ filterPassedWhenReferred(annotations$1) {
3511
+ if (!annotations$1?.length) return annotations$1;
3512
+ let filtered;
3513
+ for (let i = 0; i < annotations$1.length; i++) if (this.resolveAnnotation(annotations$1[i].name)?.config.passedWhenReferred === false) filtered ?? (filtered = annotations$1.slice(0, i));
3514
+ else filtered?.push(annotations$1[i]);
3515
+ return filtered ?? annotations$1;
3516
+ }
3517
+ /**
3497
3518
  * If the position falls inside an `annotate` block, returns that block's node
3498
3519
  * (whose `targetName` is the annotated interface). Entry refs within the block
3499
3520
  * resolve through the target interface rather than as top-level definitions.
@@ -4318,6 +4339,7 @@ else group$1.nested.push({
4318
4339
  /**
4319
4340
  * Map of dependencies (documents) by URI
4320
4341
  */ _define_property$3(this, "dependenciesMap", void 0);
4342
+ _define_property$3(this, "_annotationSpecCache", void 0);
4321
4343
  _define_property$3(this, "nodes", void 0);
4322
4344
  _define_property$3(this, "_text", void 0);
4323
4345
  _define_property$3(this, "_annotateNodesByTarget", void 0);
@@ -4341,6 +4363,7 @@ else group$1.nested.push({
4341
4363
  this.referred = [];
4342
4364
  this.queryFieldRefs = [];
4343
4365
  this.dependenciesMap = new Map();
4366
+ this._annotationSpecCache = new Map();
4344
4367
  this.nodes = [];
4345
4368
  this._text = "";
4346
4369
  this.resolvedAnnotations = [];
@@ -4626,7 +4649,8 @@ const metaAnnotations = {
4626
4649
  }),
4627
4650
  id: new AnnotationSpec({
4628
4651
  description: "Marks a field as a unique identifier across multiple domains (DB, API, UI, logs). Multiple fields can be annotated with `@meta.id` to form a composite primary key.\n\n**Example:**```atscript@meta.idid: string```",
4629
- nodeType: ["prop"]
4652
+ nodeType: ["prop"],
4653
+ passedWhenReferred: false
4630
4654
  }),
4631
4655
  description: new AnnotationSpec({
4632
4656
  description: "Provides a **detailed description** of a field or entity, often used in documentation.\n\n**Example:**```atscript@meta.description \"Stores the user email address\"email: string```",
@@ -4653,7 +4677,8 @@ const metaAnnotations = {
4653
4677
  readonly: new AnnotationSpec({
4654
4678
  description: "Marks a field as **read-only**.\n\n**Example:**```atscript@meta.readonlycreatedAt: string.date```",
4655
4679
  nodeType: ["prop", "type"],
4656
- multiple: false
4680
+ multiple: false,
4681
+ passedWhenReferred: false
4657
4682
  }),
4658
4683
  required: new AnnotationSpec({
4659
4684
  description: "Marks a field as required for form validation. For strings: must contain at least one non-whitespace character. For booleans: must be true.\n\n**Example:**```atscript@meta.requiredname: string\n@meta.required \"You must accept the terms\"agreed: boolean```",
@@ -4663,7 +4688,8 @@ const metaAnnotations = {
4663
4688
  optional: true,
4664
4689
  type: "string",
4665
4690
  description: "Optional error message to display if the validation fails."
4666
- }]
4691
+ }],
4692
+ passedWhenReferred: false
4667
4693
  }),
4668
4694
  default: new AnnotationSpec({
4669
4695
  description: "Defines a **default value** for a property or type. For string fields the value is used as-is; for other types it is parsed as JSON.\n\n**Example:**```atscript@meta.default \"unknown\"name: string\n@meta.default \"0\"count: number\n@meta.default '{\"street\":\"\",\"city\":\"\"}'address: Address```",
@@ -4672,7 +4698,8 @@ const metaAnnotations = {
4672
4698
  name: "value",
4673
4699
  type: "string",
4674
4700
  description: "The default value. Strings are used as-is; other types are parsed as JSON."
4675
- }
4701
+ },
4702
+ passedWhenReferred: false
4676
4703
  }),
4677
4704
  example: new AnnotationSpec({
4678
4705
  description: "Defines an **example value** for a property or type, useful for documentation and data generation. For string fields the value is used as-is; for other types it is parsed as JSON.\n\n**Example:**```atscript@meta.example \"John Doe\"name: string\n@meta.example \"42\"age: number\n@meta.example '[\"admin\",\"user\"]'roles: string[]```",
package/dist/index.d.ts CHANGED
@@ -472,6 +472,7 @@ declare class AtscriptDoc {
472
472
  readonly dependenciesMap: Map<string, AtscriptDoc>;
473
473
  get primitives(): SemanticPrimitiveNode[];
474
474
  render(format: TAtscriptRenderFormat): Promise<TOutputWithSource[] | undefined>;
475
+ private readonly _annotationSpecCache;
475
476
  resolveAnnotation(name: string): AnnotationSpec | undefined;
476
477
  /**
477
478
  * Resolve a placeholder import ID (bare:xxx.as) to its actual file:// URI.
@@ -525,6 +526,13 @@ declare class AtscriptDoc {
525
526
  token: Token;
526
527
  }[] | undefined;
527
528
  evalAnnotationsForNode(givenNode: SemanticNode): TAnnotationTokens[] | undefined;
529
+ /**
530
+ * Drops annotations whose spec declares `passedWhenReferred: false` — used
531
+ * when folding annotations across a ref boundary. Annotations without a
532
+ * resolvable spec pass through (default is to inherit). Returns the input
533
+ * array unchanged when nothing is dropped.
534
+ */
535
+ filterPassedWhenReferred(annotations?: TAnnotationTokens[]): TAnnotationTokens[] | undefined;
528
536
  /**
529
537
  * If the position falls inside an `annotate` block, returns that block's node
530
538
  * (whose `targetName` is the annotated interface). Entry refs within the block
@@ -873,6 +881,16 @@ interface TAnnotationArgument {
873
881
  interface TAnnotationSpecConfig {
874
882
  multiple?: boolean;
875
883
  mergeStrategy?: 'append' | 'replace';
884
+ /**
885
+ * Whether this annotation is inherited by a field that references the annotated
886
+ * node via a chain-ref (e.g. `ownerId: User.id`). Defaults to `true`
887
+ * (value/presentation annotations describe the value and travel with it).
888
+ * Set to `false` for annotations that describe the declaring scope itself
889
+ * (indexes, storage options, primary keys) — those must not leak into
890
+ * referring fields. Only affects ref boundaries; `extends`/intersection
891
+ * merging always inherits.
892
+ */
893
+ passedWhenReferred?: boolean;
876
894
  description?: string;
877
895
  nodeType?: TNodeEntity[];
878
896
  defType?: Array<SemanticPrimitiveNode['type']>;
package/dist/index.mjs CHANGED
@@ -3247,7 +3247,12 @@ var AtscriptDoc = class {
3247
3247
  return this.manager?.render(this, format);
3248
3248
  }
3249
3249
  resolveAnnotation(name) {
3250
- return resolveAnnotation(name, this.config.annotations);
3250
+ let spec = this._annotationSpecCache.get(name);
3251
+ if (spec === undefined && !this._annotationSpecCache.has(name)) {
3252
+ spec = resolveAnnotation(name, this.config.annotations);
3253
+ this._annotationSpecCache.set(name, spec);
3254
+ }
3255
+ return spec;
3251
3256
  }
3252
3257
  /**
3253
3258
  * Resolve a placeholder import ID (bare:xxx.as) to its actual file:// URI.
@@ -3456,20 +3461,36 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3456
3461
  let right = givenNode.annotations;
3457
3462
  let def = givenNode.getDefinition();
3458
3463
  if (def) {
3459
- if (isRef(def)) {
3460
- const unwound = this.unwindType(def.token("identifier").text, def.chain, (intermediate) => {
3461
- if (intermediate?.annotations) right = this.mergeNodesAnnotations(intermediate.annotations, right);
3464
+ const refDef = isRef(def) ? def : undefined;
3465
+ if (refDef) {
3466
+ const chainNodes = [];
3467
+ const unwound = this.unwindType(refDef.token("identifier").text, refDef.chain, (intermediate) => {
3468
+ if (intermediate?.annotations?.length) chainNodes.push(intermediate);
3462
3469
  });
3470
+ if (unwound?.node && unwound.node !== givenNode && unwound.node.annotations?.length && !chainNodes.includes(unwound.node)) chainNodes.unshift(unwound.node);
3471
+ for (const chainNode of chainNodes) right = this.mergeNodesAnnotations(this.filterPassedWhenReferred(chainNode.annotations), right);
3463
3472
  def = unwound?.def || def;
3464
3473
  }
3465
3474
  if (def) {
3466
3475
  const merged = this.mergeIntersection(def);
3467
- right = this.mergeNodesAnnotations(merged.annotations, right);
3476
+ right = this.mergeNodesAnnotations(refDef ? this.filterPassedWhenReferred(merged.annotations) : merged.annotations, right);
3468
3477
  }
3469
3478
  }
3470
3479
  return right;
3471
3480
  }
3472
3481
  /**
3482
+ * Drops annotations whose spec declares `passedWhenReferred: false` — used
3483
+ * when folding annotations across a ref boundary. Annotations without a
3484
+ * resolvable spec pass through (default is to inherit). Returns the input
3485
+ * array unchanged when nothing is dropped.
3486
+ */ filterPassedWhenReferred(annotations$1) {
3487
+ if (!annotations$1?.length) return annotations$1;
3488
+ let filtered;
3489
+ for (let i = 0; i < annotations$1.length; i++) if (this.resolveAnnotation(annotations$1[i].name)?.config.passedWhenReferred === false) filtered ?? (filtered = annotations$1.slice(0, i));
3490
+ else filtered?.push(annotations$1[i]);
3491
+ return filtered ?? annotations$1;
3492
+ }
3493
+ /**
3473
3494
  * If the position falls inside an `annotate` block, returns that block's node
3474
3495
  * (whose `targetName` is the annotated interface). Entry refs within the block
3475
3496
  * resolve through the target interface rather than as top-level definitions.
@@ -4294,6 +4315,7 @@ else group$1.nested.push({
4294
4315
  /**
4295
4316
  * Map of dependencies (documents) by URI
4296
4317
  */ _define_property$3(this, "dependenciesMap", void 0);
4318
+ _define_property$3(this, "_annotationSpecCache", void 0);
4297
4319
  _define_property$3(this, "nodes", void 0);
4298
4320
  _define_property$3(this, "_text", void 0);
4299
4321
  _define_property$3(this, "_annotateNodesByTarget", void 0);
@@ -4317,6 +4339,7 @@ else group$1.nested.push({
4317
4339
  this.referred = [];
4318
4340
  this.queryFieldRefs = [];
4319
4341
  this.dependenciesMap = new Map();
4342
+ this._annotationSpecCache = new Map();
4320
4343
  this.nodes = [];
4321
4344
  this._text = "";
4322
4345
  this.resolvedAnnotations = [];
@@ -4602,7 +4625,8 @@ const metaAnnotations = {
4602
4625
  }),
4603
4626
  id: new AnnotationSpec({
4604
4627
  description: "Marks a field as a unique identifier across multiple domains (DB, API, UI, logs). Multiple fields can be annotated with `@meta.id` to form a composite primary key.\n\n**Example:**```atscript@meta.idid: string```",
4605
- nodeType: ["prop"]
4628
+ nodeType: ["prop"],
4629
+ passedWhenReferred: false
4606
4630
  }),
4607
4631
  description: new AnnotationSpec({
4608
4632
  description: "Provides a **detailed description** of a field or entity, often used in documentation.\n\n**Example:**```atscript@meta.description \"Stores the user email address\"email: string```",
@@ -4629,7 +4653,8 @@ const metaAnnotations = {
4629
4653
  readonly: new AnnotationSpec({
4630
4654
  description: "Marks a field as **read-only**.\n\n**Example:**```atscript@meta.readonlycreatedAt: string.date```",
4631
4655
  nodeType: ["prop", "type"],
4632
- multiple: false
4656
+ multiple: false,
4657
+ passedWhenReferred: false
4633
4658
  }),
4634
4659
  required: new AnnotationSpec({
4635
4660
  description: "Marks a field as required for form validation. For strings: must contain at least one non-whitespace character. For booleans: must be true.\n\n**Example:**```atscript@meta.requiredname: string\n@meta.required \"You must accept the terms\"agreed: boolean```",
@@ -4639,7 +4664,8 @@ const metaAnnotations = {
4639
4664
  optional: true,
4640
4665
  type: "string",
4641
4666
  description: "Optional error message to display if the validation fails."
4642
- }]
4667
+ }],
4668
+ passedWhenReferred: false
4643
4669
  }),
4644
4670
  default: new AnnotationSpec({
4645
4671
  description: "Defines a **default value** for a property or type. For string fields the value is used as-is; for other types it is parsed as JSON.\n\n**Example:**```atscript@meta.default \"unknown\"name: string\n@meta.default \"0\"count: number\n@meta.default '{\"street\":\"\",\"city\":\"\"}'address: Address```",
@@ -4648,7 +4674,8 @@ const metaAnnotations = {
4648
4674
  name: "value",
4649
4675
  type: "string",
4650
4676
  description: "The default value. Strings are used as-is; other types are parsed as JSON."
4651
- }
4677
+ },
4678
+ passedWhenReferred: false
4652
4679
  }),
4653
4680
  example: new AnnotationSpec({
4654
4681
  description: "Defines an **example value** for a property or type, useful for documentation and data generation. For string fields the value is used as-is; for other types it is parsed as JSON.\n\n**Example:**```atscript@meta.example \"John Doe\"name: string\n@meta.example \"42\"age: number\n@meta.example '[\"admin\",\"user\"]'roles: string[]```",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/core",
3
- "version": "0.1.77",
3
+ "version": "0.1.79",
4
4
  "description": "Core library for Atscript parsing and file generation.",
5
5
  "keywords": [
6
6
  "annotations",