@atscript/core 0.1.108 → 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
  /**
@@ -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: {
@@ -5208,42 +5240,30 @@ const emitAnnotations = { jsonSchema: new AnnotationSpec({
5208
5240
  //#endregion
5209
5241
  //#region packages/core/src/defaults/expect-annotations.ts
5210
5242
  const NULLABLE_NOTE = "Also allowed on a nullable field (`T | null`, `T | undefined`): `null` passes, any other value must satisfy the constraint.";
5211
- const expectAnnotations = {
5212
- minLength: new AnnotationSpec({
5213
- description: `Validates that a string or array has a minimum length. ${NULLABLE_NOTE}\n\n**Example:**\`\`\`atscript@expect.minLength 5name: string\`\`\``,
5214
- 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"],
5215
5247
  argument: [{
5216
- name: "length",
5248
+ name: argName,
5217
5249
  type: "number",
5218
- description: "The minimum length of the string or array."
5250
+ description: argDescription
5219
5251
  }, {
5220
5252
  name: "message",
5221
5253
  optional: true,
5222
5254
  type: "string",
5223
5255
  description: "Optional error message to display if the validation fails."
5224
5256
  }]
5225
- }),
5226
- maxLength: new AnnotationSpec({
5227
- 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"),
5228
5262
  defType: ["array", "string"],
5229
5263
  argument: [{
5230
5264
  name: "length",
5231
5265
  type: "number",
5232
- description: "The maximum length of the string or array."
5233
- }, {
5234
- name: "message",
5235
- optional: true,
5236
- type: "string",
5237
- description: "Optional error message to display if the validation fails."
5238
- }]
5239
- }),
5240
- min: new AnnotationSpec({
5241
- description: `Validates that a number is greater than or equal to a minimum value. ${NULLABLE_NOTE}\n\n**Example:**\`\`\`atscript@expect.min 18age: number\`\`\``,
5242
- defType: ["number"],
5243
- argument: [{
5244
- name: "minValue",
5245
- type: "number",
5246
- description: "The minimum value."
5266
+ description: "The minimum length of the string or array."
5247
5267
  }, {
5248
5268
  name: "message",
5249
5269
  optional: true,
@@ -5251,13 +5271,13 @@ const expectAnnotations = {
5251
5271
  description: "Optional error message to display if the validation fails."
5252
5272
  }]
5253
5273
  }),
5254
- max: new AnnotationSpec({
5255
- description: `Validates that a number is less than or equal to a maximum value. ${NULLABLE_NOTE}\n\n**Example:**\`\`\`atscript@expect.max 10count: number\`\`\``,
5256
- 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"],
5257
5277
  argument: [{
5258
- name: "maxValue",
5278
+ name: "length",
5259
5279
  type: "number",
5260
- description: "The maximum value."
5280
+ description: "The maximum length of the string or array."
5261
5281
  }, {
5262
5282
  name: "message",
5263
5283
  optional: true,
@@ -5265,12 +5285,16 @@ const expectAnnotations = {
5265
5285
  description: "Optional error message to display if the validation fails."
5266
5286
  }]
5267
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)."),
5268
5292
  int: new AnnotationSpec({
5269
- 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"),
5270
5294
  defType: ["number"]
5271
5295
  }),
5272
5296
  pattern: new AnnotationSpec({
5273
- 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"),
5274
5298
  defType: ["string"],
5275
5299
  multiple: true,
5276
5300
  mergeStrategy: "append",
@@ -5444,7 +5468,7 @@ const expectAnnotations = {
5444
5468
  //#region packages/core/src/defaults/meta-annotations.ts
5445
5469
  const metaAnnotations = {
5446
5470
  label: new AnnotationSpec({
5447
- 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"),
5448
5472
  argument: {
5449
5473
  name: "text",
5450
5474
  type: "string",
@@ -5452,12 +5476,12 @@ const metaAnnotations = {
5452
5476
  }
5453
5477
  }),
5454
5478
  id: new AnnotationSpec({
5455
- 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"),
5456
5480
  nodeType: ["prop"],
5457
5481
  passedWhenReferred: false
5458
5482
  }),
5459
5483
  description: new AnnotationSpec({
5460
- 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"),
5461
5485
  argument: {
5462
5486
  name: "text",
5463
5487
  type: "string",
@@ -5465,7 +5489,7 @@ const metaAnnotations = {
5465
5489
  }
5466
5490
  }),
5467
5491
  documentation: new AnnotationSpec({
5468
- 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"),
5469
5493
  multiple: true,
5470
5494
  argument: {
5471
5495
  name: "text",
@@ -5474,18 +5498,18 @@ const metaAnnotations = {
5474
5498
  }
5475
5499
  }),
5476
5500
  sensitive: new AnnotationSpec({
5477
- 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"),
5478
5502
  nodeType: ["prop", "type"],
5479
5503
  multiple: false
5480
5504
  }),
5481
5505
  readonly: new AnnotationSpec({
5482
- 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"),
5483
5507
  nodeType: ["prop", "type"],
5484
5508
  multiple: false,
5485
5509
  passedWhenReferred: false
5486
5510
  }),
5487
5511
  required: new AnnotationSpec({
5488
- 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"),
5489
5513
  defType: ["string", "boolean"],
5490
5514
  argument: [{
5491
5515
  name: "message",
@@ -5496,7 +5520,7 @@ const metaAnnotations = {
5496
5520
  passedWhenReferred: false
5497
5521
  }),
5498
5522
  default: new AnnotationSpec({
5499
- 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"),
5500
5524
  nodeType: ["prop", "type"],
5501
5525
  argument: {
5502
5526
  name: "value",
@@ -5506,7 +5530,7 @@ const metaAnnotations = {
5506
5530
  passedWhenReferred: false
5507
5531
  }),
5508
5532
  example: new AnnotationSpec({
5509
- 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[]"),
5510
5534
  nodeType: ["prop", "type"],
5511
5535
  argument: {
5512
5536
  name: "value",
@@ -6597,6 +6621,7 @@ exports.SemanticTupleNode = SemanticTupleNode;
6597
6621
  exports.SemanticTypeNode = SemanticTypeNode;
6598
6622
  exports.Token = Token;
6599
6623
  exports.analyzeQueryCursorContext = analyzeQueryCursorContext;
6624
+ exports.annotationExample = annotationExample;
6600
6625
  exports.build = build;
6601
6626
  exports.clearResolveBareCache = clearResolveBareCache;
6602
6627
  exports.createAtscriptPlugin = createAtscriptPlugin;
package/dist/index.d.ts CHANGED
@@ -1192,6 +1192,24 @@ declare function resolveAnnotation(name: string, annotationsTree?: TAnnotationsT
1192
1192
  */
1193
1193
  declare function nonNullishMembers(def: SemanticNode | undefined, doc: AtscriptDoc): SemanticNode[] | undefined;
1194
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
+
1195
1213
  declare function resolveAtscriptFromPath(from: string, id: string): string;
1196
1214
  declare function fileUriToPath(id: string): string;
1197
1215
  declare function getRelPath(fromUri: string, toUri: string): string;
@@ -1412,5 +1430,5 @@ declare const BACKTICK_ARG_VOCABULARY: {
1412
1430
  readonly orderDirections: readonly ["asc", "desc"];
1413
1431
  };
1414
1432
 
1415
- 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 };
1416
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
  /**
@@ -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: {
@@ -5177,42 +5209,30 @@ const emitAnnotations = { jsonSchema: new AnnotationSpec({
5177
5209
  //#endregion
5178
5210
  //#region packages/core/src/defaults/expect-annotations.ts
5179
5211
  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"],
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"],
5184
5216
  argument: [{
5185
- name: "length",
5217
+ name: argName,
5186
5218
  type: "number",
5187
- description: "The minimum length of the string or array."
5219
+ description: argDescription
5188
5220
  }, {
5189
5221
  name: "message",
5190
5222
  optional: true,
5191
5223
  type: "string",
5192
5224
  description: "Optional error message to display if the validation fails."
5193
5225
  }]
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\`\`\``,
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"),
5197
5231
  defType: ["array", "string"],
5198
5232
  argument: [{
5199
5233
  name: "length",
5200
5234
  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."
5235
+ description: "The minimum length of the string or array."
5216
5236
  }, {
5217
5237
  name: "message",
5218
5238
  optional: true,
@@ -5220,13 +5240,13 @@ const expectAnnotations = {
5220
5240
  description: "Optional error message to display if the validation fails."
5221
5241
  }]
5222
5242
  }),
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"],
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"],
5226
5246
  argument: [{
5227
- name: "maxValue",
5247
+ name: "length",
5228
5248
  type: "number",
5229
- description: "The maximum value."
5249
+ description: "The maximum length of the string or array."
5230
5250
  }, {
5231
5251
  name: "message",
5232
5252
  optional: true,
@@ -5234,12 +5254,16 @@ const expectAnnotations = {
5234
5254
  description: "Optional error message to display if the validation fails."
5235
5255
  }]
5236
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)."),
5237
5261
  int: new AnnotationSpec({
5238
- 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"),
5239
5263
  defType: ["number"]
5240
5264
  }),
5241
5265
  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\`\`\``,
5266
+ description: annotationExample(`Validates that a string matches a specific pattern. ${NULLABLE_NOTE}`, "@expect.pattern \"[a-z]+\", \"u\"", "name: string"),
5243
5267
  defType: ["string"],
5244
5268
  multiple: true,
5245
5269
  mergeStrategy: "append",
@@ -5413,7 +5437,7 @@ const expectAnnotations = {
5413
5437
  //#region packages/core/src/defaults/meta-annotations.ts
5414
5438
  const metaAnnotations = {
5415
5439
  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```",
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"),
5417
5441
  argument: {
5418
5442
  name: "text",
5419
5443
  type: "string",
@@ -5421,12 +5445,12 @@ const metaAnnotations = {
5421
5445
  }
5422
5446
  }),
5423
5447
  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```",
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"),
5425
5449
  nodeType: ["prop"],
5426
5450
  passedWhenReferred: false
5427
5451
  }),
5428
5452
  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```",
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"),
5430
5454
  argument: {
5431
5455
  name: "text",
5432
5456
  type: "string",
@@ -5434,7 +5458,7 @@ const metaAnnotations = {
5434
5458
  }
5435
5459
  }),
5436
5460
  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```",
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"),
5438
5462
  multiple: true,
5439
5463
  argument: {
5440
5464
  name: "text",
@@ -5443,18 +5467,18 @@ const metaAnnotations = {
5443
5467
  }
5444
5468
  }),
5445
5469
  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```",
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"),
5447
5471
  nodeType: ["prop", "type"],
5448
5472
  multiple: false
5449
5473
  }),
5450
5474
  readonly: new AnnotationSpec({
5451
- 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"),
5452
5476
  nodeType: ["prop", "type"],
5453
5477
  multiple: false,
5454
5478
  passedWhenReferred: false
5455
5479
  }),
5456
5480
  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```",
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"),
5458
5482
  defType: ["string", "boolean"],
5459
5483
  argument: [{
5460
5484
  name: "message",
@@ -5465,7 +5489,7 @@ const metaAnnotations = {
5465
5489
  passedWhenReferred: false
5466
5490
  }),
5467
5491
  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```",
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"),
5469
5493
  nodeType: ["prop", "type"],
5470
5494
  argument: {
5471
5495
  name: "value",
@@ -5475,7 +5499,7 @@ const metaAnnotations = {
5475
5499
  passedWhenReferred: false
5476
5500
  }),
5477
5501
  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[]```",
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[]"),
5479
5503
  nodeType: ["prop", "type"],
5480
5504
  argument: {
5481
5505
  name: "value",
@@ -6530,4 +6554,4 @@ function walkArrayElement(doc, arrayNode, prefix, parentOptional, flatMap, stack
6530
6554
  }
6531
6555
 
6532
6556
  //#endregion
6533
- 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.108",
3
+ "version": "0.1.109",
4
4
  "description": "Core library for Atscript parsing and file generation.",
5
5
  "keywords": [
6
6
  "annotations",