@atscript/core 0.1.13 → 0.1.15

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
@@ -443,6 +443,11 @@ var SemanticPrimitiveNode = class SemanticPrimitiveNode extends SemanticNode {
443
443
  });
444
444
  }
445
445
  if (this.type === "string") {
446
+ if (this.config.expect?.required === true) this.annotations.push({
447
+ name: "meta.required",
448
+ token: dummyToken,
449
+ args: []
450
+ });
446
451
  if (typeof this.config.expect?.pattern !== "undefined") {
447
452
  const patterns = Array.isArray(this.config.expect.pattern) ? this.config.expect.pattern : [this.config.expect.pattern];
448
453
  for (const p of patterns) {
@@ -473,6 +478,13 @@ var SemanticPrimitiveNode = class SemanticPrimitiveNode extends SemanticNode {
473
478
  args: []
474
479
  });
475
480
  }
481
+ if (this.type === "boolean") {
482
+ if (this.config.expect?.required === true) this.annotations.push({
483
+ name: "meta.required",
484
+ token: dummyToken,
485
+ args: []
486
+ });
487
+ }
476
488
  }
477
489
  get key() {
478
490
  return this.parentKey ? `${this.parentKey}.${this._id}` : this._id;
@@ -967,13 +979,13 @@ async function bundleTsConfig(configFile, forceFormat) {
967
979
  input: configFile,
968
980
  platform: "node",
969
981
  resolve: { mainFields: ["main"] },
970
- define: {
982
+ transform: { define: {
971
983
  "__dirname": dirnameVarName,
972
984
  "__filename": filenameVarName,
973
985
  "import.meta.url": importMetaUrlVarName,
974
986
  "import.meta.dirname": dirnameVarName,
975
987
  "import.meta.filename": filenameVarName
976
- },
988
+ } },
977
989
  treeshake: false,
978
990
  external: [/^[\w@][^:]/u],
979
991
  plugins: [{
@@ -3073,6 +3085,16 @@ const metaAnnotations = {
3073
3085
  nodeType: ["prop"],
3074
3086
  multiple: false
3075
3087
  }),
3088
+ required: new AnnotationSpec({
3089
+ 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```",
3090
+ defType: ["string", "boolean"],
3091
+ argument: [{
3092
+ name: "message",
3093
+ optional: true,
3094
+ type: "string",
3095
+ description: "Optional error message to display if the validation fails."
3096
+ }]
3097
+ }),
3076
3098
  isKey: new AnnotationSpec({
3077
3099
  description: "Marks a **key field** inside an array. This annotation is used to identify unique fields within an array that can be used as **lookup keys**.\n\n\n\n**Example:**\n```atscript\nexport interface User {\n id: string\n profiles: {\n @meta.isKey\n profileId: string\n name: string\n }[]\n}\n```\n",
3078
3100
  nodeType: ["prop"],
@@ -3162,6 +3184,10 @@ const primitives = {
3162
3184
  pattern: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
3163
3185
  message: "Invalid UUID format."
3164
3186
  }
3187
+ },
3188
+ required: {
3189
+ documentation: "Non-empty string that contains at least one non-whitespace character.",
3190
+ expect: { required: true }
3165
3191
  }
3166
3192
  }
3167
3193
  },
@@ -3193,6 +3219,10 @@ const primitives = {
3193
3219
  type: "boolean",
3194
3220
  documentation: "Represents true/false values.",
3195
3221
  extensions: {
3222
+ required: {
3223
+ documentation: "Boolean that must be true. Useful for checkboxes like \"accept terms\".",
3224
+ expect: { required: true }
3225
+ },
3196
3226
  true: { documentation: "Represents a true value." },
3197
3227
  false: { documentation: "Represents a false value." }
3198
3228
  }
package/dist/index.d.ts CHANGED
@@ -239,6 +239,7 @@ interface TPrimitiveBaseConfig {
239
239
  minLength?: number;
240
240
  maxLength?: number;
241
241
  pattern?: string | RegExp | (string | RegExp)[];
242
+ required?: boolean;
242
243
  message?: string;
243
244
  };
244
245
  }
package/dist/index.mjs CHANGED
@@ -419,6 +419,11 @@ var SemanticPrimitiveNode = class SemanticPrimitiveNode extends SemanticNode {
419
419
  });
420
420
  }
421
421
  if (this.type === "string") {
422
+ if (this.config.expect?.required === true) this.annotations.push({
423
+ name: "meta.required",
424
+ token: dummyToken,
425
+ args: []
426
+ });
422
427
  if (typeof this.config.expect?.pattern !== "undefined") {
423
428
  const patterns = Array.isArray(this.config.expect.pattern) ? this.config.expect.pattern : [this.config.expect.pattern];
424
429
  for (const p of patterns) {
@@ -449,6 +454,13 @@ var SemanticPrimitiveNode = class SemanticPrimitiveNode extends SemanticNode {
449
454
  args: []
450
455
  });
451
456
  }
457
+ if (this.type === "boolean") {
458
+ if (this.config.expect?.required === true) this.annotations.push({
459
+ name: "meta.required",
460
+ token: dummyToken,
461
+ args: []
462
+ });
463
+ }
452
464
  }
453
465
  get key() {
454
466
  return this.parentKey ? `${this.parentKey}.${this._id}` : this._id;
@@ -943,13 +955,13 @@ async function bundleTsConfig(configFile, forceFormat) {
943
955
  input: configFile,
944
956
  platform: "node",
945
957
  resolve: { mainFields: ["main"] },
946
- define: {
958
+ transform: { define: {
947
959
  "__dirname": dirnameVarName,
948
960
  "__filename": filenameVarName,
949
961
  "import.meta.url": importMetaUrlVarName,
950
962
  "import.meta.dirname": dirnameVarName,
951
963
  "import.meta.filename": filenameVarName
952
- },
964
+ } },
953
965
  treeshake: false,
954
966
  external: [/^[\w@][^:]/u],
955
967
  plugins: [{
@@ -3049,6 +3061,16 @@ const metaAnnotations = {
3049
3061
  nodeType: ["prop"],
3050
3062
  multiple: false
3051
3063
  }),
3064
+ required: new AnnotationSpec({
3065
+ 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```",
3066
+ defType: ["string", "boolean"],
3067
+ argument: [{
3068
+ name: "message",
3069
+ optional: true,
3070
+ type: "string",
3071
+ description: "Optional error message to display if the validation fails."
3072
+ }]
3073
+ }),
3052
3074
  isKey: new AnnotationSpec({
3053
3075
  description: "Marks a **key field** inside an array. This annotation is used to identify unique fields within an array that can be used as **lookup keys**.\n\n\n\n**Example:**\n```atscript\nexport interface User {\n id: string\n profiles: {\n @meta.isKey\n profileId: string\n name: string\n }[]\n}\n```\n",
3054
3076
  nodeType: ["prop"],
@@ -3138,6 +3160,10 @@ const primitives = {
3138
3160
  pattern: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
3139
3161
  message: "Invalid UUID format."
3140
3162
  }
3163
+ },
3164
+ required: {
3165
+ documentation: "Non-empty string that contains at least one non-whitespace character.",
3166
+ expect: { required: true }
3141
3167
  }
3142
3168
  }
3143
3169
  },
@@ -3169,6 +3195,10 @@ const primitives = {
3169
3195
  type: "boolean",
3170
3196
  documentation: "Represents true/false values.",
3171
3197
  extensions: {
3198
+ required: {
3199
+ documentation: "Boolean that must be true. Useful for checkboxes like \"accept terms\".",
3200
+ expect: { required: true }
3201
+ },
3172
3202
  true: { documentation: "Represents a true value." },
3173
3203
  false: { documentation: "Represents a false value." }
3174
3204
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/core",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "Core library for Atscript parsing and file generation.",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",