@atscript/core 0.1.107 → 0.1.109

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
@@ -1293,6 +1293,27 @@ function describeUnionMembers(def, doc) {
1293
1293
  return members;
1294
1294
  }
1295
1295
 
1296
+ //#endregion
1297
+ //#region packages/core/src/annotations/annotation-example.ts
1298
+ /**
1299
+ * Builds an {@link AnnotationSpec} `description` (shown in IDE hovers) that ends with an
1300
+ * example block: `description`, then an **Example:** heading and an `atscript` code fence
1301
+ * with one `lines` entry per line (pass `''` for a blank line).
1302
+ *
1303
+ * @example
1304
+ * ```ts
1305
+ * new AnnotationSpec({
1306
+ * description: annotationExample(
1307
+ * 'Marks a field as **read-only**.',
1308
+ * '@meta.readonly',
1309
+ * 'createdAt: string.date'
1310
+ * ),
1311
+ * })
1312
+ * ```
1313
+ */ function annotationExample(description, ...lines) {
1314
+ return `${description}\n\n**Example:**\n\`\`\`atscript\n${lines.join("\n")}\n\`\`\``;
1315
+ }
1316
+
1296
1317
  //#endregion
1297
1318
  //#region packages/core/src/config/define-config.ts
1298
1319
  /**
@@ -1640,7 +1661,7 @@ var NodeIterator = class NodeIterator {
1640
1661
  return new NodeIterator(nodes || this.nodes, this.messages, this.badNodes, this.issues, nodes ? this.$ : this.parent, nodes ? 0 : this.i).update();
1641
1662
  }
1642
1663
  skip(pun) {
1643
- while (this.$?.type === "comment" || this.$?.type === "punctuation" && pun?.length && pun.includes(this.$.text)) this.move();
1664
+ while (this.$?.type === "punctuation" && pun?.includes(this.$.text)) this.move();
1644
1665
  return this;
1645
1666
  }
1646
1667
  skipUntil(pun) {
@@ -2940,7 +2961,19 @@ const REGEXP_LITERAL_RE = /\/(?![/*])(?:\\.|\[.*?]|[^/\\\n\r[])*\/[dgimsuy]*/;
2940
2961
  //#endregion
2941
2962
  //#region packages/core/src/tokenizer/tokens/text.node.ts
2942
2963
  /**
2943
- * Text node single or doublequoted
2964
+ * Lookbehind: the end token is preceded by an EVEN run of backslashes (zero included).
2965
+ * An odd run means the last backslash escapes the quote (or newline), so the string
2966
+ * goes on; `"a\\"` ends at its last quote. The parser's own `backslash` option only
2967
+ * checks the single preceding char, so it can't tell `\"` from `\\"`. The lookbehind
2968
+ * can see the source before the search position, which always holds the opening quote.
2969
+ */ const EVEN_BACKSLASHES = "(?<=(?:^|[^\\\\])(?:\\\\\\\\)*)";
2970
+ const END_RE = {
2971
+ "\"": new RegExp(`${EVEN_BACKSLASHES}(?<end>"|\\n)`, "u"),
2972
+ "'": new RegExp(`${EVEN_BACKSLASHES}(?<end>'|\\n)`, "u")
2973
+ };
2974
+ /**
2975
+ * Text node single or doublequoted.
2976
+ * Content is RAW: escapes are not decoded (`\"` stays `\"`, `\\` stays `\\`).
2944
2977
  */ const TextToken = new _prostojs_parser.Node({
2945
2978
  name: "text",
2946
2979
  start: {
@@ -2948,9 +2981,8 @@ const REGEXP_LITERAL_RE = /\/(?![/*])(?:\\.|\[.*?]|[^/\\\n\r[])*\/[dgimsuy]*/;
2948
2981
  omit: true
2949
2982
  },
2950
2983
  end: {
2951
- token: (ctx) => new RegExp(`(?<end>${ctx.node.data.quote || ""}|\\n)`),
2952
- omit: true,
2953
- backslash: true
2984
+ token: (ctx) => END_RE[ctx.node.data.quote],
2985
+ omit: true
2954
2986
  },
2955
2987
  eofClose: true,
2956
2988
  data: {
@@ -3010,42 +3042,63 @@ QueryBlockToken.recognize(QueryRegExpToken, QueryOperatorToken, QueryBlockToken,
3010
3042
  * Recursively extract TLexicalToken[] from a ParsedNode tree.
3011
3043
  * Replaces the v0.5 mapContent('children', callback) + global loop.
3012
3044
  *
3045
+ * Comments are dropped here, so the parser never sees them; their spans go to
3046
+ * `comments` (in source order) when given. A block comment spanning a line break
3047
+ * becomes a synthetic `'\n'` punctuation token, so it ends a line like the break
3048
+ * itself would.
3049
+ *
3013
3050
  * v0.6 Position has { offset, line, column }.
3014
3051
  * line is 1-based, column is 1-based.
3015
3052
  * VSCode expects 0-based line, 0-based character.
3016
- */ function extractTokens(node) {
3053
+ */ function extractTokens(node, comments) {
3017
3054
  const content = node.content;
3018
- return content.map((item, index) => {
3055
+ const tokens = [];
3056
+ content.forEach((item, index) => {
3019
3057
  if (typeof item === "string") {
3020
3058
  const prev = content[index - 1];
3021
3059
  const next = content[index + 1];
3022
3060
  const start = typeof prev === "object" ? prev.end : node.start;
3023
3061
  const end = typeof next === "object" ? next.start : node.end;
3024
- return {
3062
+ tokens.push({
3025
3063
  type: "unknown",
3026
3064
  text: item,
3027
3065
  getRange: () => ({
3028
3066
  start: toPos(start),
3029
3067
  end: toPos(end)
3030
3068
  })
3031
- };
3069
+ });
3070
+ return;
3032
3071
  }
3033
3072
  const data = item.data;
3034
3073
  data.getRange = () => ({
3035
3074
  start: toPos(item.start, data.startOffset),
3036
3075
  end: toPos(item.end, data.endOffset)
3037
3076
  });
3038
- data.children = extractTokens(item);
3039
- return data;
3077
+ if (data.type === "comment") {
3078
+ const closed = item.node === commentNodes.block && item.end.offset - item.start.offset === data.text.length + 4;
3079
+ comments?.push({
3080
+ start: item.start.offset,
3081
+ end: item.end.offset + (closed ? 0 : 1)
3082
+ });
3083
+ if (/[\n\r]/u.test(data.text)) tokens.push({
3084
+ type: "punctuation",
3085
+ text: "\n",
3086
+ getRange: data.getRange
3087
+ });
3088
+ return;
3089
+ }
3090
+ data.children = extractTokens(item, comments);
3091
+ tokens.push(data);
3040
3092
  });
3093
+ return tokens;
3041
3094
  }
3042
3095
 
3043
3096
  //#endregion
3044
3097
  //#region packages/core/src/tokenizer/index.ts
3045
- function tokenize(source, debug = false) {
3098
+ /** Lexes `source`; comment spans are collected into `comments` when given. */ function tokenize(source, debug = false, comments) {
3046
3099
  const result = root.parse(source);
3047
3100
  if (debug) console.log((0, _prostojs_parser.printTree)(result));
3048
- return extractTokens(result);
3101
+ return extractTokens(result, comments);
3049
3102
  }
3050
3103
 
3051
3104
  //#endregion
@@ -3417,7 +3470,7 @@ function annotations() {
3417
3470
  ni.accepted();
3418
3471
  ni.move();
3419
3472
  }
3420
- while (ni.satisfies(...opts.argument)) {
3473
+ while (ni.$ && ni.satisfies(...opts.argument)) {
3421
3474
  let argToken = new Token(ni.$);
3422
3475
  ni.accepted();
3423
3476
  ni.move();
@@ -3729,10 +3782,6 @@ const importPipe = $pipe("import", [
3729
3782
  const annotateEntry = $pipe("ref", [
3730
3783
  annotations(),
3731
3784
  refWithChain(),
3732
- { handler(ni) {
3733
- ni.skip();
3734
- return true;
3735
- } },
3736
3785
  pun(";", ",", "\n").orEob().lookBehind()
3737
3786
  ]).skip("\n", ";", ",");
3738
3787
  const annotatePipe = $pipe("annotate", [
@@ -3996,10 +4045,22 @@ var AtscriptDoc = class AtscriptDoc {
3996
4045
  get text() {
3997
4046
  return this._text;
3998
4047
  }
4048
+ /** Whether `offset` into `text` falls inside a comment (e.g. a cursor in `// …`). */ isInComment(offset) {
4049
+ let lo = 0;
4050
+ let hi = this.commentSpans.length;
4051
+ while (lo < hi) {
4052
+ const mid = lo + hi >>> 1;
4053
+ if (this.commentSpans[mid].start < offset) lo = mid + 1;
4054
+ else hi = mid;
4055
+ }
4056
+ const span = this.commentSpans[lo - 1];
4057
+ return span !== void 0 && offset < span.end;
4058
+ }
3999
4059
  update(text, debug = false) {
4000
4060
  this._text = text;
4001
4061
  this.cleanup();
4002
- const rawTokens = tokenize(text, debug);
4062
+ this.commentSpans = [];
4063
+ const rawTokens = tokenize(text, debug, this.commentSpans);
4003
4064
  const ni = new NodeIterator(rawTokens, []).move();
4004
4065
  this.nodes = runPipes([
4005
4066
  pipes.importPipe,
@@ -5106,6 +5167,7 @@ var AtscriptDoc = class AtscriptDoc {
5106
5167
  _define_property$3(this, "nodes", void 0);
5107
5168
  _define_property$3(this, "_text", void 0);
5108
5169
  _define_property$3(this, "_annotateNodesByTarget", void 0);
5170
+ /** Comment spans of `text`, in source order. */ _define_property$3(this, "commentSpans", void 0);
5109
5171
  /** Lexical backtick tokens already parsed by `registerAnnotation`. */ _define_property$3(this, "parsedBacktickArgs", void 0);
5110
5172
  _define_property$3(this, "resolvedAnnotations", void 0);
5111
5173
  _define_property$3(this, "annotations", void 0);
@@ -5131,6 +5193,7 @@ var AtscriptDoc = class AtscriptDoc {
5131
5193
  this._annotationSpecCache = /* @__PURE__ */ new Map();
5132
5194
  this.nodes = [];
5133
5195
  this._text = "";
5196
+ this.commentSpans = [];
5134
5197
  this.parsedBacktickArgs = /* @__PURE__ */ new WeakSet();
5135
5198
  this.resolvedAnnotations = [];
5136
5199
  this.annotations = [];
@@ -5177,42 +5240,30 @@ const emitAnnotations = { jsonSchema: new AnnotationSpec({
5177
5240
  //#endregion
5178
5241
  //#region packages/core/src/defaults/expect-annotations.ts
5179
5242
  const NULLABLE_NOTE = "Also allowed on a nullable field (`T | null`, `T | undefined`): `null` passes, any other value must satisfy the constraint.";
5180
- const expectAnnotations = {
5181
- minLength: new AnnotationSpec({
5182
- description: `Validates that a string or array has a minimum length. ${NULLABLE_NOTE}\n\n**Example:**\`\`\`atscript@expect.minLength 5name: string\`\`\``,
5183
- defType: ["array", "string"],
5243
+ /** `@expect.min` / `max` / `exclusiveMin` / `exclusiveMax`: a number bound plus an optional message. */ function numberBoundSpec(summary, example, argName, argDescription) {
5244
+ return new AnnotationSpec({
5245
+ description: annotationExample(`${summary} ${NULLABLE_NOTE}`, ...example),
5246
+ defType: ["number"],
5184
5247
  argument: [{
5185
- name: "length",
5248
+ name: argName,
5186
5249
  type: "number",
5187
- description: "The minimum length of the string or array."
5250
+ description: argDescription
5188
5251
  }, {
5189
5252
  name: "message",
5190
5253
  optional: true,
5191
5254
  type: "string",
5192
5255
  description: "Optional error message to display if the validation fails."
5193
5256
  }]
5194
- }),
5195
- maxLength: new AnnotationSpec({
5196
- description: `Validates that a string or array has a maximum length. ${NULLABLE_NOTE}\n\n**Example:**\`\`\`atscript@expect.maxLength 5name: string\`\`\``,
5257
+ });
5258
+ }
5259
+ const expectAnnotations = {
5260
+ minLength: new AnnotationSpec({
5261
+ description: annotationExample(`Validates that a string or array has a minimum length. ${NULLABLE_NOTE}`, "@expect.minLength 5", "name: string"),
5197
5262
  defType: ["array", "string"],
5198
5263
  argument: [{
5199
5264
  name: "length",
5200
5265
  type: "number",
5201
- description: "The maximum length of the string or array."
5202
- }, {
5203
- name: "message",
5204
- optional: true,
5205
- type: "string",
5206
- description: "Optional error message to display if the validation fails."
5207
- }]
5208
- }),
5209
- min: new AnnotationSpec({
5210
- description: `Validates that a number is greater than or equal to a minimum value. ${NULLABLE_NOTE}\n\n**Example:**\`\`\`atscript@expect.min 18age: number\`\`\``,
5211
- defType: ["number"],
5212
- argument: [{
5213
- name: "minValue",
5214
- type: "number",
5215
- description: "The minimum value."
5266
+ description: "The minimum length of the string or array."
5216
5267
  }, {
5217
5268
  name: "message",
5218
5269
  optional: true,
@@ -5220,13 +5271,13 @@ const expectAnnotations = {
5220
5271
  description: "Optional error message to display if the validation fails."
5221
5272
  }]
5222
5273
  }),
5223
- max: new AnnotationSpec({
5224
- description: `Validates that a number is less than or equal to a maximum value. ${NULLABLE_NOTE}\n\n**Example:**\`\`\`atscript@expect.max 10count: number\`\`\``,
5225
- defType: ["number"],
5274
+ maxLength: new AnnotationSpec({
5275
+ description: annotationExample(`Validates that a string or array has a maximum length. ${NULLABLE_NOTE}`, "@expect.maxLength 5", "name: string"),
5276
+ defType: ["array", "string"],
5226
5277
  argument: [{
5227
- name: "maxValue",
5278
+ name: "length",
5228
5279
  type: "number",
5229
- description: "The maximum value."
5280
+ description: "The maximum length of the string or array."
5230
5281
  }, {
5231
5282
  name: "message",
5232
5283
  optional: true,
@@ -5234,12 +5285,16 @@ const expectAnnotations = {
5234
5285
  description: "Optional error message to display if the validation fails."
5235
5286
  }]
5236
5287
  }),
5288
+ min: numberBoundSpec("Validates that a number is greater than or equal to a minimum value.", ["@expect.min 18", "age: number"], "minValue", "The minimum value."),
5289
+ max: numberBoundSpec("Validates that a number is less than or equal to a maximum value.", ["@expect.max 10", "count: number"], "maxValue", "The maximum value."),
5290
+ exclusiveMin: numberBoundSpec("Validates that a number is strictly greater than a value (the value itself is rejected).", ["@expect.exclusiveMin 0", "price: number"], "exclusiveMinValue", "The exclusive lower bound (the value must be greater than this)."),
5291
+ exclusiveMax: numberBoundSpec("Validates that a number is strictly less than a value (the value itself is rejected).", ["@expect.exclusiveMax 1", "ratio: number"], "exclusiveMaxValue", "The exclusive upper bound (the value must be less than this)."),
5237
5292
  int: new AnnotationSpec({
5238
- description: `Validates that a number is an integer (no decimal places). ${NULLABLE_NOTE}\n\n**Example:**\`\`\`atscript@expect.intage: number\`\`\``,
5293
+ description: annotationExample(`Validates that a number is an integer (no decimal places). ${NULLABLE_NOTE}`, "@expect.int", "age: number"),
5239
5294
  defType: ["number"]
5240
5295
  }),
5241
5296
  pattern: new AnnotationSpec({
5242
- description: `Validates that a string matches a specific pattern. ${NULLABLE_NOTE}\n\n**Example:**\`\`\`atscript@expect.pattern "[a-z]+", "u"name: string\`\`\``,
5297
+ description: annotationExample(`Validates that a string matches a specific pattern. ${NULLABLE_NOTE}`, "@expect.pattern \"[a-z]+\", \"u\"", "name: string"),
5243
5298
  defType: ["string"],
5244
5299
  multiple: true,
5245
5300
  mergeStrategy: "append",
@@ -5413,7 +5468,7 @@ const expectAnnotations = {
5413
5468
  //#region packages/core/src/defaults/meta-annotations.ts
5414
5469
  const metaAnnotations = {
5415
5470
  label: new AnnotationSpec({
5416
- description: "Defines a **human-readable label** for a property or entity. Useful for UI, logs, and documentation.\n\n**Example:**```atscript@meta.label \"User Name\"name: string```",
5471
+ description: annotationExample("Defines a **human-readable label** for a property or entity. Useful for UI, logs, and documentation.", "@meta.label \"User Name\"", "name: string"),
5417
5472
  argument: {
5418
5473
  name: "text",
5419
5474
  type: "string",
@@ -5421,12 +5476,12 @@ const metaAnnotations = {
5421
5476
  }
5422
5477
  }),
5423
5478
  id: new AnnotationSpec({
5424
- 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```",
5479
+ description: annotationExample("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.", "@meta.id", "id: string"),
5425
5480
  nodeType: ["prop"],
5426
5481
  passedWhenReferred: false
5427
5482
  }),
5428
5483
  description: new AnnotationSpec({
5429
- 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```",
5484
+ description: annotationExample("Provides a **detailed description** of a field or entity, often used in documentation.", "@meta.description \"Stores the user email address\"", "email: string"),
5430
5485
  argument: {
5431
5486
  name: "text",
5432
5487
  type: "string",
@@ -5434,7 +5489,7 @@ const metaAnnotations = {
5434
5489
  }
5435
5490
  }),
5436
5491
  documentation: new AnnotationSpec({
5437
- description: "Provides **multi-line documentation** for a field or entity.\n\n**Example:**```atscript@meta.documentation \"# bio\"@meta.documentation \"## documentation of bio\"@meta.documentation \"your documentation\"bio: string```",
5492
+ description: annotationExample("Provides **multi-line documentation** for a field or entity.", "@meta.documentation \"# bio\"", "@meta.documentation \"## documentation of bio\"", "@meta.documentation \"your documentation\"", "bio: string"),
5438
5493
  multiple: true,
5439
5494
  argument: {
5440
5495
  name: "text",
@@ -5443,18 +5498,18 @@ const metaAnnotations = {
5443
5498
  }
5444
5499
  }),
5445
5500
  sensitive: new AnnotationSpec({
5446
- description: "Marks a field as **sensitive** (e.g., passwords, API keys), ensuring it is hidden in logs and UI.\n\n**Example:**```atscript@meta.sensitivepassword: string```",
5501
+ description: annotationExample("Marks a field as **sensitive** (e.g., passwords, API keys), ensuring it is hidden in logs and UI.", "@meta.sensitive", "password: string"),
5447
5502
  nodeType: ["prop", "type"],
5448
5503
  multiple: false
5449
5504
  }),
5450
5505
  readonly: new AnnotationSpec({
5451
- description: "Marks a field as **read-only**.\n\n**Example:**```atscript@meta.readonlycreatedAt: string.date```",
5506
+ description: annotationExample("Marks a field as **read-only**.", "@meta.readonly", "createdAt: string.date"),
5452
5507
  nodeType: ["prop", "type"],
5453
5508
  multiple: false,
5454
5509
  passedWhenReferred: false
5455
5510
  }),
5456
5511
  required: new AnnotationSpec({
5457
- description: "Marks a field as required for form validation. For strings: must contain at least one non-whitespace character. For booleans: must be true. On an optional field (`name?: string`) the field may be omitted, but `null` is rejected. On a nullable field (`string | null`) `null` is accepted and a string must not be empty.\n\n**Example:**```atscript@meta.requiredname: string\n@meta.required \"You must accept the terms\"agreed: boolean```",
5512
+ description: annotationExample("Marks a field as required for form validation. For strings: must contain at least one non-whitespace character. For booleans: must be true. On an optional field (`name?: string`) the field may be omitted, but `null` is rejected. On a nullable field (`string | null`) `null` is accepted and a string must not be empty.", "@meta.required", "name: string", "", "@meta.required \"You must accept the terms\"", "agreed: boolean"),
5458
5513
  defType: ["string", "boolean"],
5459
5514
  argument: [{
5460
5515
  name: "message",
@@ -5465,7 +5520,7 @@ const metaAnnotations = {
5465
5520
  passedWhenReferred: false
5466
5521
  }),
5467
5522
  default: new AnnotationSpec({
5468
- 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```",
5523
+ description: annotationExample("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.", "@meta.default \"unknown\"", "name: string", "", "@meta.default \"0\"", "count: number", "", "@meta.default '{\"street\":\"\",\"city\":\"\"}'", "address: Address"),
5469
5524
  nodeType: ["prop", "type"],
5470
5525
  argument: {
5471
5526
  name: "value",
@@ -5475,7 +5530,7 @@ const metaAnnotations = {
5475
5530
  passedWhenReferred: false
5476
5531
  }),
5477
5532
  example: new AnnotationSpec({
5478
- 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[]```",
5533
+ description: annotationExample("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.", "@meta.example \"John Doe\"", "name: string", "", "@meta.example \"42\"", "age: number", "", "@meta.example '[\"admin\",\"user\"]'", "roles: string[]"),
5479
5534
  nodeType: ["prop", "type"],
5480
5535
  argument: {
5481
5536
  name: "value",
@@ -6566,6 +6621,7 @@ exports.SemanticTupleNode = SemanticTupleNode;
6566
6621
  exports.SemanticTypeNode = SemanticTypeNode;
6567
6622
  exports.Token = Token;
6568
6623
  exports.analyzeQueryCursorContext = analyzeQueryCursorContext;
6624
+ exports.annotationExample = annotationExample;
6569
6625
  exports.build = build;
6570
6626
  exports.clearResolveBareCache = clearResolveBareCache;
6571
6627
  exports.createAtscriptPlugin = createAtscriptPlugin;
package/dist/index.d.ts CHANGED
@@ -538,6 +538,10 @@ declare class AtscriptDoc {
538
538
  private _text;
539
539
  private _annotateNodesByTarget;
540
540
  get text(): string;
541
+ /** Comment spans of `text`, in source order. */
542
+ private commentSpans;
543
+ /** Whether `offset` into `text` falls inside a comment (e.g. a cursor in `// …`). */
544
+ isInComment(offset: number): boolean;
541
545
  update(text: string, debug?: boolean): void;
542
546
  /** Lexical backtick tokens already parsed by `registerAnnotation`. */
543
547
  private parsedBacktickArgs;
@@ -1188,6 +1192,24 @@ declare function resolveAnnotation(name: string, annotationsTree?: TAnnotationsT
1188
1192
  */
1189
1193
  declare function nonNullishMembers(def: SemanticNode | undefined, doc: AtscriptDoc): SemanticNode[] | undefined;
1190
1194
 
1195
+ /**
1196
+ * Builds an {@link AnnotationSpec} `description` (shown in IDE hovers) that ends with an
1197
+ * example block: `description`, then an **Example:** heading and an `atscript` code fence
1198
+ * with one `lines` entry per line (pass `''` for a blank line).
1199
+ *
1200
+ * @example
1201
+ * ```ts
1202
+ * new AnnotationSpec({
1203
+ * description: annotationExample(
1204
+ * 'Marks a field as **read-only**.',
1205
+ * '@meta.readonly',
1206
+ * 'createdAt: string.date'
1207
+ * ),
1208
+ * })
1209
+ * ```
1210
+ */
1211
+ declare function annotationExample(description: string, ...lines: string[]): string;
1212
+
1191
1213
  declare function resolveAtscriptFromPath(from: string, id: string): string;
1192
1214
  declare function fileUriToPath(id: string): string;
1193
1215
  declare function getRelPath(fromUri: string, toUri: string): string;
@@ -1408,5 +1430,5 @@ declare const BACKTICK_ARG_VOCABULARY: {
1408
1430
  readonly orderDirections: readonly ["asc", "desc"];
1409
1431
  };
1410
1432
 
1411
- export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BACKTICK_ARG_VOCABULARY, BuildRepo, DB_ENTITY_ANNOTATIONS, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticExprBinaryNode, SemanticExprCallNode, SemanticExprNode, SemanticExprNumberNode, SemanticExprUnaryNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticOrderNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, build, clearResolveBareCache, createAtscriptPlugin, defineConfig, fileUriToPath, flattenInterfaceNode, getDeclaredValue, getFieldPathCompletionScope, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, getSiblingAnnotation, getValueCandidates, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isBacktickArgType, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, nonNullishMembers, parseBareSpecifier, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveFieldRefAt, resolveQueryFieldRef };
1433
+ export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BACKTICK_ARG_VOCABULARY, BuildRepo, DB_ENTITY_ANNOTATIONS, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticExprBinaryNode, SemanticExprCallNode, SemanticExprNode, SemanticExprNumberNode, SemanticExprUnaryNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticOrderNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, annotationExample, build, clearResolveBareCache, createAtscriptPlugin, defineConfig, fileUriToPath, flattenInterfaceNode, getDeclaredValue, getFieldPathCompletionScope, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, getSiblingAnnotation, getValueCandidates, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isBacktickArgType, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, nonNullishMembers, parseBareSpecifier, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveFieldRefAt, resolveQueryFieldRef };
1412
1434
  export type { SemanticExprItemNode, SemanticQueryExprNode, TAnnotationArgument, TAnnotationSpecConfig, TAnnotationTokens, TAnnotationsTree, TAtscriptConfig, TAtscriptConfigInput, TAtscriptConfigOutput, TAtscriptDocConfig, TAtscriptPlugin, TAtscriptRenderFormat, TBacktickArgKind, TDbConfig, TDbConfigDeclarative, TExprBinaryOperator, TFlatFieldDescriptor, TFlattenOptions, TMessages, TNodeEntity, TOrderItem, TOutput, TOutputWithSource, TPluginManagers, TPluginOutput, TPrimitiveAnnotationArg, TPrimitiveAnnotationArgs, TPrimitiveAnnotationValue, TPrimitiveBaseConfig, TPrimitiveConfig, TPrimitiveTypeArray, TPrimitiveTypeComplex, TPrimitiveTypeDef, TPrimitiveTypeFinal, TPrimitiveTypeFinalOptional, TPrimitiveTypeObject, TQueryCursorContext, TQueryLogicalOperator, TQueryOperator, TQueryScope, TSemanticToken, TValueCandidate };
package/dist/index.mjs CHANGED
@@ -1262,6 +1262,27 @@ function describeUnionMembers(def, doc) {
1262
1262
  return members;
1263
1263
  }
1264
1264
 
1265
+ //#endregion
1266
+ //#region packages/core/src/annotations/annotation-example.ts
1267
+ /**
1268
+ * Builds an {@link AnnotationSpec} `description` (shown in IDE hovers) that ends with an
1269
+ * example block: `description`, then an **Example:** heading and an `atscript` code fence
1270
+ * with one `lines` entry per line (pass `''` for a blank line).
1271
+ *
1272
+ * @example
1273
+ * ```ts
1274
+ * new AnnotationSpec({
1275
+ * description: annotationExample(
1276
+ * 'Marks a field as **read-only**.',
1277
+ * '@meta.readonly',
1278
+ * 'createdAt: string.date'
1279
+ * ),
1280
+ * })
1281
+ * ```
1282
+ */ function annotationExample(description, ...lines) {
1283
+ return `${description}\n\n**Example:**\n\`\`\`atscript\n${lines.join("\n")}\n\`\`\``;
1284
+ }
1285
+
1265
1286
  //#endregion
1266
1287
  //#region packages/core/src/config/define-config.ts
1267
1288
  /**
@@ -1609,7 +1630,7 @@ var NodeIterator = class NodeIterator {
1609
1630
  return new NodeIterator(nodes || this.nodes, this.messages, this.badNodes, this.issues, nodes ? this.$ : this.parent, nodes ? 0 : this.i).update();
1610
1631
  }
1611
1632
  skip(pun) {
1612
- while (this.$?.type === "comment" || this.$?.type === "punctuation" && pun?.length && pun.includes(this.$.text)) this.move();
1633
+ while (this.$?.type === "punctuation" && pun?.includes(this.$.text)) this.move();
1613
1634
  return this;
1614
1635
  }
1615
1636
  skipUntil(pun) {
@@ -2909,7 +2930,19 @@ const REGEXP_LITERAL_RE = /\/(?![/*])(?:\\.|\[.*?]|[^/\\\n\r[])*\/[dgimsuy]*/;
2909
2930
  //#endregion
2910
2931
  //#region packages/core/src/tokenizer/tokens/text.node.ts
2911
2932
  /**
2912
- * Text node single or doublequoted
2933
+ * Lookbehind: the end token is preceded by an EVEN run of backslashes (zero included).
2934
+ * An odd run means the last backslash escapes the quote (or newline), so the string
2935
+ * goes on; `"a\\"` ends at its last quote. The parser's own `backslash` option only
2936
+ * checks the single preceding char, so it can't tell `\"` from `\\"`. The lookbehind
2937
+ * can see the source before the search position, which always holds the opening quote.
2938
+ */ const EVEN_BACKSLASHES = "(?<=(?:^|[^\\\\])(?:\\\\\\\\)*)";
2939
+ const END_RE = {
2940
+ "\"": new RegExp(`${EVEN_BACKSLASHES}(?<end>"|\\n)`, "u"),
2941
+ "'": new RegExp(`${EVEN_BACKSLASHES}(?<end>'|\\n)`, "u")
2942
+ };
2943
+ /**
2944
+ * Text node single or doublequoted.
2945
+ * Content is RAW: escapes are not decoded (`\"` stays `\"`, `\\` stays `\\`).
2913
2946
  */ const TextToken = new Node({
2914
2947
  name: "text",
2915
2948
  start: {
@@ -2917,9 +2950,8 @@ const REGEXP_LITERAL_RE = /\/(?![/*])(?:\\.|\[.*?]|[^/\\\n\r[])*\/[dgimsuy]*/;
2917
2950
  omit: true
2918
2951
  },
2919
2952
  end: {
2920
- token: (ctx) => new RegExp(`(?<end>${ctx.node.data.quote || ""}|\\n)`),
2921
- omit: true,
2922
- backslash: true
2953
+ token: (ctx) => END_RE[ctx.node.data.quote],
2954
+ omit: true
2923
2955
  },
2924
2956
  eofClose: true,
2925
2957
  data: {
@@ -2979,42 +3011,63 @@ QueryBlockToken.recognize(QueryRegExpToken, QueryOperatorToken, QueryBlockToken,
2979
3011
  * Recursively extract TLexicalToken[] from a ParsedNode tree.
2980
3012
  * Replaces the v0.5 mapContent('children', callback) + global loop.
2981
3013
  *
3014
+ * Comments are dropped here, so the parser never sees them; their spans go to
3015
+ * `comments` (in source order) when given. A block comment spanning a line break
3016
+ * becomes a synthetic `'\n'` punctuation token, so it ends a line like the break
3017
+ * itself would.
3018
+ *
2982
3019
  * v0.6 Position has { offset, line, column }.
2983
3020
  * line is 1-based, column is 1-based.
2984
3021
  * VSCode expects 0-based line, 0-based character.
2985
- */ function extractTokens(node) {
3022
+ */ function extractTokens(node, comments) {
2986
3023
  const content = node.content;
2987
- return content.map((item, index) => {
3024
+ const tokens = [];
3025
+ content.forEach((item, index) => {
2988
3026
  if (typeof item === "string") {
2989
3027
  const prev = content[index - 1];
2990
3028
  const next = content[index + 1];
2991
3029
  const start = typeof prev === "object" ? prev.end : node.start;
2992
3030
  const end = typeof next === "object" ? next.start : node.end;
2993
- return {
3031
+ tokens.push({
2994
3032
  type: "unknown",
2995
3033
  text: item,
2996
3034
  getRange: () => ({
2997
3035
  start: toPos(start),
2998
3036
  end: toPos(end)
2999
3037
  })
3000
- };
3038
+ });
3039
+ return;
3001
3040
  }
3002
3041
  const data = item.data;
3003
3042
  data.getRange = () => ({
3004
3043
  start: toPos(item.start, data.startOffset),
3005
3044
  end: toPos(item.end, data.endOffset)
3006
3045
  });
3007
- data.children = extractTokens(item);
3008
- return data;
3046
+ if (data.type === "comment") {
3047
+ const closed = item.node === commentNodes.block && item.end.offset - item.start.offset === data.text.length + 4;
3048
+ comments?.push({
3049
+ start: item.start.offset,
3050
+ end: item.end.offset + (closed ? 0 : 1)
3051
+ });
3052
+ if (/[\n\r]/u.test(data.text)) tokens.push({
3053
+ type: "punctuation",
3054
+ text: "\n",
3055
+ getRange: data.getRange
3056
+ });
3057
+ return;
3058
+ }
3059
+ data.children = extractTokens(item, comments);
3060
+ tokens.push(data);
3009
3061
  });
3062
+ return tokens;
3010
3063
  }
3011
3064
 
3012
3065
  //#endregion
3013
3066
  //#region packages/core/src/tokenizer/index.ts
3014
- function tokenize(source, debug = false) {
3067
+ /** Lexes `source`; comment spans are collected into `comments` when given. */ function tokenize(source, debug = false, comments) {
3015
3068
  const result = root.parse(source);
3016
3069
  if (debug) console.log(printTree(result));
3017
- return extractTokens(result);
3070
+ return extractTokens(result, comments);
3018
3071
  }
3019
3072
 
3020
3073
  //#endregion
@@ -3386,7 +3439,7 @@ function annotations() {
3386
3439
  ni.accepted();
3387
3440
  ni.move();
3388
3441
  }
3389
- while (ni.satisfies(...opts.argument)) {
3442
+ while (ni.$ && ni.satisfies(...opts.argument)) {
3390
3443
  let argToken = new Token(ni.$);
3391
3444
  ni.accepted();
3392
3445
  ni.move();
@@ -3698,10 +3751,6 @@ const importPipe = $pipe("import", [
3698
3751
  const annotateEntry = $pipe("ref", [
3699
3752
  annotations(),
3700
3753
  refWithChain(),
3701
- { handler(ni) {
3702
- ni.skip();
3703
- return true;
3704
- } },
3705
3754
  pun(";", ",", "\n").orEob().lookBehind()
3706
3755
  ]).skip("\n", ";", ",");
3707
3756
  const annotatePipe = $pipe("annotate", [
@@ -3965,10 +4014,22 @@ var AtscriptDoc = class AtscriptDoc {
3965
4014
  get text() {
3966
4015
  return this._text;
3967
4016
  }
4017
+ /** Whether `offset` into `text` falls inside a comment (e.g. a cursor in `// …`). */ isInComment(offset) {
4018
+ let lo = 0;
4019
+ let hi = this.commentSpans.length;
4020
+ while (lo < hi) {
4021
+ const mid = lo + hi >>> 1;
4022
+ if (this.commentSpans[mid].start < offset) lo = mid + 1;
4023
+ else hi = mid;
4024
+ }
4025
+ const span = this.commentSpans[lo - 1];
4026
+ return span !== void 0 && offset < span.end;
4027
+ }
3968
4028
  update(text, debug = false) {
3969
4029
  this._text = text;
3970
4030
  this.cleanup();
3971
- const rawTokens = tokenize(text, debug);
4031
+ this.commentSpans = [];
4032
+ const rawTokens = tokenize(text, debug, this.commentSpans);
3972
4033
  const ni = new NodeIterator(rawTokens, []).move();
3973
4034
  this.nodes = runPipes([
3974
4035
  pipes.importPipe,
@@ -5075,6 +5136,7 @@ var AtscriptDoc = class AtscriptDoc {
5075
5136
  _define_property$3(this, "nodes", void 0);
5076
5137
  _define_property$3(this, "_text", void 0);
5077
5138
  _define_property$3(this, "_annotateNodesByTarget", void 0);
5139
+ /** Comment spans of `text`, in source order. */ _define_property$3(this, "commentSpans", void 0);
5078
5140
  /** Lexical backtick tokens already parsed by `registerAnnotation`. */ _define_property$3(this, "parsedBacktickArgs", void 0);
5079
5141
  _define_property$3(this, "resolvedAnnotations", void 0);
5080
5142
  _define_property$3(this, "annotations", void 0);
@@ -5100,6 +5162,7 @@ var AtscriptDoc = class AtscriptDoc {
5100
5162
  this._annotationSpecCache = /* @__PURE__ */ new Map();
5101
5163
  this.nodes = [];
5102
5164
  this._text = "";
5165
+ this.commentSpans = [];
5103
5166
  this.parsedBacktickArgs = /* @__PURE__ */ new WeakSet();
5104
5167
  this.resolvedAnnotations = [];
5105
5168
  this.annotations = [];
@@ -5146,42 +5209,30 @@ const emitAnnotations = { jsonSchema: new AnnotationSpec({
5146
5209
  //#endregion
5147
5210
  //#region packages/core/src/defaults/expect-annotations.ts
5148
5211
  const NULLABLE_NOTE = "Also allowed on a nullable field (`T | null`, `T | undefined`): `null` passes, any other value must satisfy the constraint.";
5149
- const expectAnnotations = {
5150
- minLength: new AnnotationSpec({
5151
- description: `Validates that a string or array has a minimum length. ${NULLABLE_NOTE}\n\n**Example:**\`\`\`atscript@expect.minLength 5name: string\`\`\``,
5152
- defType: ["array", "string"],
5212
+ /** `@expect.min` / `max` / `exclusiveMin` / `exclusiveMax`: a number bound plus an optional message. */ function numberBoundSpec(summary, example, argName, argDescription) {
5213
+ return new AnnotationSpec({
5214
+ description: annotationExample(`${summary} ${NULLABLE_NOTE}`, ...example),
5215
+ defType: ["number"],
5153
5216
  argument: [{
5154
- name: "length",
5217
+ name: argName,
5155
5218
  type: "number",
5156
- description: "The minimum length of the string or array."
5219
+ description: argDescription
5157
5220
  }, {
5158
5221
  name: "message",
5159
5222
  optional: true,
5160
5223
  type: "string",
5161
5224
  description: "Optional error message to display if the validation fails."
5162
5225
  }]
5163
- }),
5164
- maxLength: new AnnotationSpec({
5165
- description: `Validates that a string or array has a maximum length. ${NULLABLE_NOTE}\n\n**Example:**\`\`\`atscript@expect.maxLength 5name: string\`\`\``,
5226
+ });
5227
+ }
5228
+ const expectAnnotations = {
5229
+ minLength: new AnnotationSpec({
5230
+ description: annotationExample(`Validates that a string or array has a minimum length. ${NULLABLE_NOTE}`, "@expect.minLength 5", "name: string"),
5166
5231
  defType: ["array", "string"],
5167
5232
  argument: [{
5168
5233
  name: "length",
5169
5234
  type: "number",
5170
- description: "The maximum length of the string or array."
5171
- }, {
5172
- name: "message",
5173
- optional: true,
5174
- type: "string",
5175
- description: "Optional error message to display if the validation fails."
5176
- }]
5177
- }),
5178
- min: new AnnotationSpec({
5179
- description: `Validates that a number is greater than or equal to a minimum value. ${NULLABLE_NOTE}\n\n**Example:**\`\`\`atscript@expect.min 18age: number\`\`\``,
5180
- defType: ["number"],
5181
- argument: [{
5182
- name: "minValue",
5183
- type: "number",
5184
- description: "The minimum value."
5235
+ description: "The minimum length of the string or array."
5185
5236
  }, {
5186
5237
  name: "message",
5187
5238
  optional: true,
@@ -5189,13 +5240,13 @@ const expectAnnotations = {
5189
5240
  description: "Optional error message to display if the validation fails."
5190
5241
  }]
5191
5242
  }),
5192
- max: new AnnotationSpec({
5193
- description: `Validates that a number is less than or equal to a maximum value. ${NULLABLE_NOTE}\n\n**Example:**\`\`\`atscript@expect.max 10count: number\`\`\``,
5194
- defType: ["number"],
5243
+ maxLength: new AnnotationSpec({
5244
+ description: annotationExample(`Validates that a string or array has a maximum length. ${NULLABLE_NOTE}`, "@expect.maxLength 5", "name: string"),
5245
+ defType: ["array", "string"],
5195
5246
  argument: [{
5196
- name: "maxValue",
5247
+ name: "length",
5197
5248
  type: "number",
5198
- description: "The maximum value."
5249
+ description: "The maximum length of the string or array."
5199
5250
  }, {
5200
5251
  name: "message",
5201
5252
  optional: true,
@@ -5203,12 +5254,16 @@ const expectAnnotations = {
5203
5254
  description: "Optional error message to display if the validation fails."
5204
5255
  }]
5205
5256
  }),
5257
+ min: numberBoundSpec("Validates that a number is greater than or equal to a minimum value.", ["@expect.min 18", "age: number"], "minValue", "The minimum value."),
5258
+ max: numberBoundSpec("Validates that a number is less than or equal to a maximum value.", ["@expect.max 10", "count: number"], "maxValue", "The maximum value."),
5259
+ exclusiveMin: numberBoundSpec("Validates that a number is strictly greater than a value (the value itself is rejected).", ["@expect.exclusiveMin 0", "price: number"], "exclusiveMinValue", "The exclusive lower bound (the value must be greater than this)."),
5260
+ exclusiveMax: numberBoundSpec("Validates that a number is strictly less than a value (the value itself is rejected).", ["@expect.exclusiveMax 1", "ratio: number"], "exclusiveMaxValue", "The exclusive upper bound (the value must be less than this)."),
5206
5261
  int: new AnnotationSpec({
5207
- description: `Validates that a number is an integer (no decimal places). ${NULLABLE_NOTE}\n\n**Example:**\`\`\`atscript@expect.intage: number\`\`\``,
5262
+ description: annotationExample(`Validates that a number is an integer (no decimal places). ${NULLABLE_NOTE}`, "@expect.int", "age: number"),
5208
5263
  defType: ["number"]
5209
5264
  }),
5210
5265
  pattern: new AnnotationSpec({
5211
- description: `Validates that a string matches a specific pattern. ${NULLABLE_NOTE}\n\n**Example:**\`\`\`atscript@expect.pattern "[a-z]+", "u"name: string\`\`\``,
5266
+ description: annotationExample(`Validates that a string matches a specific pattern. ${NULLABLE_NOTE}`, "@expect.pattern \"[a-z]+\", \"u\"", "name: string"),
5212
5267
  defType: ["string"],
5213
5268
  multiple: true,
5214
5269
  mergeStrategy: "append",
@@ -5382,7 +5437,7 @@ const expectAnnotations = {
5382
5437
  //#region packages/core/src/defaults/meta-annotations.ts
5383
5438
  const metaAnnotations = {
5384
5439
  label: new AnnotationSpec({
5385
- description: "Defines a **human-readable label** for a property or entity. Useful for UI, logs, and documentation.\n\n**Example:**```atscript@meta.label \"User Name\"name: string```",
5440
+ description: annotationExample("Defines a **human-readable label** for a property or entity. Useful for UI, logs, and documentation.", "@meta.label \"User Name\"", "name: string"),
5386
5441
  argument: {
5387
5442
  name: "text",
5388
5443
  type: "string",
@@ -5390,12 +5445,12 @@ const metaAnnotations = {
5390
5445
  }
5391
5446
  }),
5392
5447
  id: new AnnotationSpec({
5393
- 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```",
5448
+ description: annotationExample("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.", "@meta.id", "id: string"),
5394
5449
  nodeType: ["prop"],
5395
5450
  passedWhenReferred: false
5396
5451
  }),
5397
5452
  description: new AnnotationSpec({
5398
- 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```",
5453
+ description: annotationExample("Provides a **detailed description** of a field or entity, often used in documentation.", "@meta.description \"Stores the user email address\"", "email: string"),
5399
5454
  argument: {
5400
5455
  name: "text",
5401
5456
  type: "string",
@@ -5403,7 +5458,7 @@ const metaAnnotations = {
5403
5458
  }
5404
5459
  }),
5405
5460
  documentation: new AnnotationSpec({
5406
- description: "Provides **multi-line documentation** for a field or entity.\n\n**Example:**```atscript@meta.documentation \"# bio\"@meta.documentation \"## documentation of bio\"@meta.documentation \"your documentation\"bio: string```",
5461
+ description: annotationExample("Provides **multi-line documentation** for a field or entity.", "@meta.documentation \"# bio\"", "@meta.documentation \"## documentation of bio\"", "@meta.documentation \"your documentation\"", "bio: string"),
5407
5462
  multiple: true,
5408
5463
  argument: {
5409
5464
  name: "text",
@@ -5412,18 +5467,18 @@ const metaAnnotations = {
5412
5467
  }
5413
5468
  }),
5414
5469
  sensitive: new AnnotationSpec({
5415
- description: "Marks a field as **sensitive** (e.g., passwords, API keys), ensuring it is hidden in logs and UI.\n\n**Example:**```atscript@meta.sensitivepassword: string```",
5470
+ description: annotationExample("Marks a field as **sensitive** (e.g., passwords, API keys), ensuring it is hidden in logs and UI.", "@meta.sensitive", "password: string"),
5416
5471
  nodeType: ["prop", "type"],
5417
5472
  multiple: false
5418
5473
  }),
5419
5474
  readonly: new AnnotationSpec({
5420
- description: "Marks a field as **read-only**.\n\n**Example:**```atscript@meta.readonlycreatedAt: string.date```",
5475
+ description: annotationExample("Marks a field as **read-only**.", "@meta.readonly", "createdAt: string.date"),
5421
5476
  nodeType: ["prop", "type"],
5422
5477
  multiple: false,
5423
5478
  passedWhenReferred: false
5424
5479
  }),
5425
5480
  required: new AnnotationSpec({
5426
- description: "Marks a field as required for form validation. For strings: must contain at least one non-whitespace character. For booleans: must be true. On an optional field (`name?: string`) the field may be omitted, but `null` is rejected. On a nullable field (`string | null`) `null` is accepted and a string must not be empty.\n\n**Example:**```atscript@meta.requiredname: string\n@meta.required \"You must accept the terms\"agreed: boolean```",
5481
+ description: annotationExample("Marks a field as required for form validation. For strings: must contain at least one non-whitespace character. For booleans: must be true. On an optional field (`name?: string`) the field may be omitted, but `null` is rejected. On a nullable field (`string | null`) `null` is accepted and a string must not be empty.", "@meta.required", "name: string", "", "@meta.required \"You must accept the terms\"", "agreed: boolean"),
5427
5482
  defType: ["string", "boolean"],
5428
5483
  argument: [{
5429
5484
  name: "message",
@@ -5434,7 +5489,7 @@ const metaAnnotations = {
5434
5489
  passedWhenReferred: false
5435
5490
  }),
5436
5491
  default: new AnnotationSpec({
5437
- 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```",
5492
+ description: annotationExample("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.", "@meta.default \"unknown\"", "name: string", "", "@meta.default \"0\"", "count: number", "", "@meta.default '{\"street\":\"\",\"city\":\"\"}'", "address: Address"),
5438
5493
  nodeType: ["prop", "type"],
5439
5494
  argument: {
5440
5495
  name: "value",
@@ -5444,7 +5499,7 @@ const metaAnnotations = {
5444
5499
  passedWhenReferred: false
5445
5500
  }),
5446
5501
  example: new AnnotationSpec({
5447
- 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[]```",
5502
+ description: annotationExample("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.", "@meta.example \"John Doe\"", "name: string", "", "@meta.example \"42\"", "age: number", "", "@meta.example '[\"admin\",\"user\"]'", "roles: string[]"),
5448
5503
  nodeType: ["prop", "type"],
5449
5504
  argument: {
5450
5505
  name: "value",
@@ -6499,4 +6554,4 @@ function walkArrayElement(doc, arrayNode, prefix, parentOptional, flatMap, stack
6499
6554
  }
6500
6555
 
6501
6556
  //#endregion
6502
- export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BACKTICK_ARG_VOCABULARY, BuildRepo, DB_ENTITY_ANNOTATIONS, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticExprBinaryNode, SemanticExprCallNode, SemanticExprNode, SemanticExprNumberNode, SemanticExprUnaryNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticOrderNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, build, clearResolveBareCache, createAtscriptPlugin, defineConfig, fileUriToPath, flattenInterfaceNode, getDeclaredValue, getFieldPathCompletionScope, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, getSiblingAnnotation, getValueCandidates, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isBacktickArgType, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, nonNullishMembers, parseBareSpecifier, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveFieldRefAt, resolveQueryFieldRef };
6557
+ export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BACKTICK_ARG_VOCABULARY, BuildRepo, DB_ENTITY_ANNOTATIONS, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticExprBinaryNode, SemanticExprCallNode, SemanticExprNode, SemanticExprNumberNode, SemanticExprUnaryNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticOrderNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, annotationExample, build, clearResolveBareCache, createAtscriptPlugin, defineConfig, fileUriToPath, flattenInterfaceNode, getDeclaredValue, getFieldPathCompletionScope, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, getSiblingAnnotation, getValueCandidates, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isBacktickArgType, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, nonNullishMembers, parseBareSpecifier, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveFieldRefAt, resolveQueryFieldRef };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/core",
3
- "version": "0.1.107",
3
+ "version": "0.1.109",
4
4
  "description": "Core library for Atscript parsing and file generation.",
5
5
  "keywords": [
6
6
  "annotations",