@atscript/core 0.1.36 → 0.1.37
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 +190 -53
- package/dist/index.mjs +190 -53
- package/package.json +1 -1
- package/skills/atscript-core/annotations.md +5 -1
- package/skills/atscript-core/primitives.md +16 -1
package/dist/index.cjs
CHANGED
|
@@ -4197,6 +4197,24 @@ else if (isQueryComparison(expr)) {
|
|
|
4197
4197
|
return iface && isInterface(iface) ? iface.id : struct.id;
|
|
4198
4198
|
}
|
|
4199
4199
|
/**
|
|
4200
|
+
* Validate that an annotation is on a field with the expected base type.
|
|
4201
|
+
*/ function validateFieldBaseType(token, doc, annotationName, expectedType) {
|
|
4202
|
+
const errors = [];
|
|
4203
|
+
const field = token.parentNode;
|
|
4204
|
+
const definition$1 = field.getDefinition();
|
|
4205
|
+
if (!definition$1 || !isRef(definition$1)) return errors;
|
|
4206
|
+
const unwound = doc.unwindType(definition$1.id, definition$1.chain);
|
|
4207
|
+
if (!unwound || !isPrimitive(unwound.def)) return errors;
|
|
4208
|
+
const baseType = unwound.def.config.type;
|
|
4209
|
+
const allowed = Array.isArray(expectedType) ? expectedType : [expectedType];
|
|
4210
|
+
if (!allowed.includes(baseType)) errors.push({
|
|
4211
|
+
message: `${annotationName} is not compatible with type "${baseType}" — requires ${allowed.join(" or ")}`,
|
|
4212
|
+
severity: 1,
|
|
4213
|
+
range: token.range
|
|
4214
|
+
});
|
|
4215
|
+
return errors;
|
|
4216
|
+
}
|
|
4217
|
+
/**
|
|
4200
4218
|
* Extract target type name from a navigational field definition.
|
|
4201
4219
|
* Unwraps arrays (e.g., `Post[]` → `Post`).
|
|
4202
4220
|
*/ function getNavTargetTypeName(field) {
|
|
@@ -4246,7 +4264,7 @@ else if (isQueryComparison(expr)) {
|
|
|
4246
4264
|
severity: 1,
|
|
4247
4265
|
range: token.range
|
|
4248
4266
|
});
|
|
4249
|
-
if (action === "setDefault" && field.countAnnotations("db.default") === 0 && field.countAnnotations("db.default.
|
|
4267
|
+
if (action === "setDefault" && field.countAnnotations("db.default") === 0 && field.countAnnotations("db.default.increment") === 0 && field.countAnnotations("db.default.uuid") === 0 && field.countAnnotations("db.default.now") === 0) errors.push({
|
|
4250
4268
|
message: `@db.rel.${name} "setDefault" but no @db.default.* annotation — field will have no fallback value`,
|
|
4251
4269
|
severity: 2,
|
|
4252
4270
|
range: token.range
|
|
@@ -4421,6 +4439,39 @@ const dbAnnotations = {
|
|
|
4421
4439
|
type: "string",
|
|
4422
4440
|
description: "The old local field name (parent prefix is reconstructed automatically)."
|
|
4423
4441
|
}
|
|
4442
|
+
}),
|
|
4443
|
+
collate: new AnnotationSpec({
|
|
4444
|
+
description: "Portable collation for string comparison and sorting. Adapters map the generic value to their native collation.\n\n- **\"binary\"** — exact byte comparison (case-sensitive)\n- **\"nocase\"** — case-insensitive comparison\n- **\"unicode\"** — full Unicode-aware sorting\n\nFor adapter-specific collations, use `@db.<engine>.collate` instead.\n\n**Example:**\n```atscript\n@db.column.collate \"nocase\"\nusername: string\n```\n",
|
|
4445
|
+
nodeType: ["prop"],
|
|
4446
|
+
argument: {
|
|
4447
|
+
name: "collation",
|
|
4448
|
+
type: "string",
|
|
4449
|
+
values: [
|
|
4450
|
+
"binary",
|
|
4451
|
+
"nocase",
|
|
4452
|
+
"unicode"
|
|
4453
|
+
],
|
|
4454
|
+
description: "Portable collation mode: \"binary\", \"nocase\", or \"unicode\"."
|
|
4455
|
+
},
|
|
4456
|
+
validate(token, args, doc) {
|
|
4457
|
+
return validateFieldBaseType(token, doc, "@db.column.collate", "string");
|
|
4458
|
+
}
|
|
4459
|
+
}),
|
|
4460
|
+
precision: new AnnotationSpec({
|
|
4461
|
+
description: "Sets decimal precision and scale for database storage. Adapters map this to their native decimal type (e.g., `DECIMAL(10,2)` in SQL, ignored in MongoDB).\n\nThis is purely a DB storage hint — it does not affect runtime JavaScript number behavior.\n\n**Example:**\n```atscript\n@db.column.precision 10, 2\nprice: number\n```\n",
|
|
4462
|
+
nodeType: ["prop"],
|
|
4463
|
+
argument: [{
|
|
4464
|
+
name: "precision",
|
|
4465
|
+
type: "number",
|
|
4466
|
+
description: "Total number of significant digits."
|
|
4467
|
+
}, {
|
|
4468
|
+
name: "scale",
|
|
4469
|
+
type: "number",
|
|
4470
|
+
description: "Number of digits after the decimal point."
|
|
4471
|
+
}],
|
|
4472
|
+
validate(token, args, doc) {
|
|
4473
|
+
return validateFieldBaseType(token, doc, "@db.column.precision", "number");
|
|
4474
|
+
}
|
|
4424
4475
|
})
|
|
4425
4476
|
},
|
|
4426
4477
|
default: {
|
|
@@ -4433,58 +4484,31 @@ const dbAnnotations = {
|
|
|
4433
4484
|
description: "Static default value. Strings used as-is; other types parsed via JSON.parse()."
|
|
4434
4485
|
}
|
|
4435
4486
|
}),
|
|
4436
|
-
|
|
4437
|
-
description: "
|
|
4487
|
+
increment: new AnnotationSpec({
|
|
4488
|
+
description: "Auto-incrementing integer default. Each adapter maps this to its native mechanism (e.g., `AUTO_INCREMENT` in MySQL, `INTEGER PRIMARY KEY` in SQLite, counter collection in MongoDB).\n\n**Example:**\n```atscript\n@db.default.increment\nid: number.int\n\n// With optional start value:\n@db.default.increment 1000\nid: number.int\n```\n",
|
|
4438
4489
|
nodeType: ["prop"],
|
|
4439
4490
|
argument: {
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
"uuid",
|
|
4445
|
-
"now"
|
|
4446
|
-
],
|
|
4447
|
-
description: "Generation function name: \"increment\", \"uuid\", or \"now\"."
|
|
4491
|
+
optional: true,
|
|
4492
|
+
name: "start",
|
|
4493
|
+
type: "number",
|
|
4494
|
+
description: "Starting value for the auto-increment sequence. Adapter-specific behavior; some adapters may ignore this."
|
|
4448
4495
|
},
|
|
4449
4496
|
validate(token, args, doc) {
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
}
|
|
4466
|
-
const field = token.parentNode;
|
|
4467
|
-
const definition$1 = field.getDefinition();
|
|
4468
|
-
if (!definition$1 || !isRef(definition$1)) return errors;
|
|
4469
|
-
const unwound = doc.unwindType(definition$1.id, definition$1.chain);
|
|
4470
|
-
if (!unwound || !isPrimitive(unwound.def)) return errors;
|
|
4471
|
-
const baseType = unwound.def.config.type;
|
|
4472
|
-
if (fnName === "increment" && baseType !== "number") errors.push({
|
|
4473
|
-
message: `@db.default.fn "increment" is not compatible with type "${baseType}" — requires number`,
|
|
4474
|
-
severity: 1,
|
|
4475
|
-
range: token.range
|
|
4476
|
-
});
|
|
4477
|
-
else if (fnName === "uuid" && baseType !== "string") errors.push({
|
|
4478
|
-
message: `@db.default.fn "uuid" is not compatible with type "${baseType}" — requires string`,
|
|
4479
|
-
severity: 1,
|
|
4480
|
-
range: token.range
|
|
4481
|
-
});
|
|
4482
|
-
else if (fnName === "now" && !["number", "string"].includes(baseType)) errors.push({
|
|
4483
|
-
message: `@db.default.fn "now" is not compatible with type "${baseType}" — requires number or string`,
|
|
4484
|
-
severity: 1,
|
|
4485
|
-
range: token.range
|
|
4486
|
-
});
|
|
4487
|
-
return errors;
|
|
4497
|
+
return validateFieldBaseType(token, doc, "db.default.increment", "number");
|
|
4498
|
+
}
|
|
4499
|
+
}),
|
|
4500
|
+
uuid: new AnnotationSpec({
|
|
4501
|
+
description: "UUID generation default. Each adapter maps this to its native mechanism (e.g., `DEFAULT (UUID())` in MySQL, `gen_random_uuid()` in PostgreSQL, app-level in SQLite).\n\n**Example:**\n```atscript\n@db.default.uuid\nid: string.uuid\n```\n",
|
|
4502
|
+
nodeType: ["prop"],
|
|
4503
|
+
validate(token, args, doc) {
|
|
4504
|
+
return validateFieldBaseType(token, doc, "db.default.uuid", "string");
|
|
4505
|
+
}
|
|
4506
|
+
}),
|
|
4507
|
+
now: new AnnotationSpec({
|
|
4508
|
+
description: "Current timestamp default. Each adapter maps this to its native mechanism (e.g., `DEFAULT CURRENT_TIMESTAMP` in MySQL, `DEFAULT now()` in PostgreSQL).\n\n**Example:**\n```atscript\n@db.default.now\ncreatedAt: number.timestamp\n```\n",
|
|
4509
|
+
nodeType: ["prop"],
|
|
4510
|
+
validate(token, args, doc) {
|
|
4511
|
+
return validateFieldBaseType(token, doc, "db.default.now", ["number", "string"]);
|
|
4488
4512
|
}
|
|
4489
4513
|
})
|
|
4490
4514
|
},
|
|
@@ -5370,6 +5394,8 @@ const metaAnnotations = {
|
|
|
5370
5394
|
|
|
5371
5395
|
//#endregion
|
|
5372
5396
|
//#region packages/core/src/defaults/primitives.ts
|
|
5397
|
+
const IPV4_PATTERN = "^((25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)\\.){3}(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)$";
|
|
5398
|
+
const IPV6_PATTERN = "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$";
|
|
5373
5399
|
const positive = {
|
|
5374
5400
|
documentation: "Number that greater than or equal to zero.",
|
|
5375
5401
|
annotations: { "expect.min": 0 }
|
|
@@ -5441,6 +5467,43 @@ const primitives = {
|
|
|
5441
5467
|
message: "Invalid UUID format."
|
|
5442
5468
|
} }
|
|
5443
5469
|
},
|
|
5470
|
+
url: {
|
|
5471
|
+
documentation: "Represents a URL.",
|
|
5472
|
+
annotations: { "expect.pattern": {
|
|
5473
|
+
pattern: "^https?:\\/\\/[^\\s]+$",
|
|
5474
|
+
message: "Invalid URL format."
|
|
5475
|
+
} }
|
|
5476
|
+
},
|
|
5477
|
+
ipv4: {
|
|
5478
|
+
documentation: "Represents an IPv4 address.",
|
|
5479
|
+
annotations: { "expect.pattern": {
|
|
5480
|
+
pattern: IPV4_PATTERN,
|
|
5481
|
+
message: "Invalid IPv4 address."
|
|
5482
|
+
} }
|
|
5483
|
+
},
|
|
5484
|
+
ipv6: {
|
|
5485
|
+
documentation: "Represents an IPv6 address.",
|
|
5486
|
+
annotations: { "expect.pattern": {
|
|
5487
|
+
pattern: IPV6_PATTERN,
|
|
5488
|
+
flags: "i",
|
|
5489
|
+
message: "Invalid IPv6 address."
|
|
5490
|
+
} }
|
|
5491
|
+
},
|
|
5492
|
+
ip: {
|
|
5493
|
+
documentation: "Represents an IP address (IPv4 or IPv6).",
|
|
5494
|
+
annotations: { "expect.pattern": {
|
|
5495
|
+
pattern: `(?:${IPV4_PATTERN.slice(1, -1)})|(?:${IPV6_PATTERN.slice(1, -1)})`,
|
|
5496
|
+
flags: "i",
|
|
5497
|
+
message: "Invalid IP address."
|
|
5498
|
+
} }
|
|
5499
|
+
},
|
|
5500
|
+
char: {
|
|
5501
|
+
documentation: "Represents a single character.",
|
|
5502
|
+
annotations: {
|
|
5503
|
+
"expect.minLength": 1,
|
|
5504
|
+
"expect.maxLength": 1
|
|
5505
|
+
}
|
|
5506
|
+
},
|
|
5444
5507
|
required: {
|
|
5445
5508
|
documentation: "Non-empty string that contains at least one non-whitespace character.",
|
|
5446
5509
|
annotations: { "meta.required": true }
|
|
@@ -5461,18 +5524,92 @@ const primitives = {
|
|
|
5461
5524
|
documentation: "Represents a double-precision floating-point number."
|
|
5462
5525
|
},
|
|
5463
5526
|
int: {
|
|
5464
|
-
extensions: positiveOrNegative,
|
|
5465
5527
|
documentation: "Represents an integer number.",
|
|
5466
|
-
annotations: { "expect.int": true }
|
|
5528
|
+
annotations: { "expect.int": true },
|
|
5529
|
+
extensions: {
|
|
5530
|
+
...positiveOrNegative,
|
|
5531
|
+
int8: {
|
|
5532
|
+
tags: ["int8"],
|
|
5533
|
+
documentation: "Signed 8-bit integer (-128 to 127).",
|
|
5534
|
+
annotations: {
|
|
5535
|
+
"expect.min": -128,
|
|
5536
|
+
"expect.max": 127
|
|
5537
|
+
}
|
|
5538
|
+
},
|
|
5539
|
+
int16: {
|
|
5540
|
+
tags: ["int16"],
|
|
5541
|
+
documentation: "Signed 16-bit integer (-32768 to 32767).",
|
|
5542
|
+
annotations: {
|
|
5543
|
+
"expect.min": -32768,
|
|
5544
|
+
"expect.max": 32767
|
|
5545
|
+
}
|
|
5546
|
+
},
|
|
5547
|
+
int32: {
|
|
5548
|
+
tags: ["int32"],
|
|
5549
|
+
documentation: "Signed 32-bit integer.",
|
|
5550
|
+
annotations: {
|
|
5551
|
+
"expect.min": -2147483648,
|
|
5552
|
+
"expect.max": 2147483647
|
|
5553
|
+
}
|
|
5554
|
+
},
|
|
5555
|
+
int64: {
|
|
5556
|
+
tags: ["int64"],
|
|
5557
|
+
documentation: "Signed 64-bit integer (clamped to JS safe integer range).",
|
|
5558
|
+
annotations: {
|
|
5559
|
+
"expect.min": Number.MIN_SAFE_INTEGER,
|
|
5560
|
+
"expect.max": Number.MAX_SAFE_INTEGER
|
|
5561
|
+
}
|
|
5562
|
+
},
|
|
5563
|
+
uint8: {
|
|
5564
|
+
tags: ["uint8"],
|
|
5565
|
+
documentation: "Unsigned 8-bit integer (0 to 255).",
|
|
5566
|
+
annotations: {
|
|
5567
|
+
"expect.min": 0,
|
|
5568
|
+
"expect.max": 255
|
|
5569
|
+
},
|
|
5570
|
+
extensions: { byte: {
|
|
5571
|
+
tags: ["byte"],
|
|
5572
|
+
documentation: "Byte value (alias for uint8)."
|
|
5573
|
+
} }
|
|
5574
|
+
},
|
|
5575
|
+
uint16: {
|
|
5576
|
+
tags: ["uint16"],
|
|
5577
|
+
documentation: "Unsigned 16-bit integer (0 to 65535).",
|
|
5578
|
+
annotations: {
|
|
5579
|
+
"expect.min": 0,
|
|
5580
|
+
"expect.max": 65535
|
|
5581
|
+
},
|
|
5582
|
+
extensions: { port: {
|
|
5583
|
+
tags: ["port"],
|
|
5584
|
+
documentation: "Network port number (0 to 65535)."
|
|
5585
|
+
} }
|
|
5586
|
+
},
|
|
5587
|
+
uint32: {
|
|
5588
|
+
tags: ["uint32"],
|
|
5589
|
+
documentation: "Unsigned 32-bit integer (0 to 4294967295).",
|
|
5590
|
+
annotations: {
|
|
5591
|
+
"expect.min": 0,
|
|
5592
|
+
"expect.max": 4294967295
|
|
5593
|
+
}
|
|
5594
|
+
},
|
|
5595
|
+
uint64: {
|
|
5596
|
+
tags: ["uint64"],
|
|
5597
|
+
documentation: "Unsigned 64-bit integer (clamped to JS safe integer range).",
|
|
5598
|
+
annotations: {
|
|
5599
|
+
"expect.min": 0,
|
|
5600
|
+
"expect.max": Number.MAX_SAFE_INTEGER
|
|
5601
|
+
}
|
|
5602
|
+
}
|
|
5603
|
+
}
|
|
5467
5604
|
},
|
|
5468
5605
|
timestamp: {
|
|
5469
5606
|
documentation: "Represents a timestamp.",
|
|
5470
5607
|
annotations: { "expect.int": true },
|
|
5471
5608
|
extensions: {
|
|
5472
5609
|
created: {
|
|
5473
|
-
documentation: "Timestamp auto-set on creation. Auto-applies @db.default.
|
|
5610
|
+
documentation: "Timestamp auto-set on creation. Auto-applies @db.default.now.",
|
|
5474
5611
|
tags: ["created"],
|
|
5475
|
-
annotations: { "db.default.
|
|
5612
|
+
annotations: { "db.default.now": true }
|
|
5476
5613
|
},
|
|
5477
5614
|
updated: {
|
|
5478
5615
|
documentation: "Timestamp auto-updated on every write. DB adapters read the \"updated\" tag.",
|
package/dist/index.mjs
CHANGED
|
@@ -4173,6 +4173,24 @@ else if (isQueryComparison(expr)) {
|
|
|
4173
4173
|
return iface && isInterface(iface) ? iface.id : struct.id;
|
|
4174
4174
|
}
|
|
4175
4175
|
/**
|
|
4176
|
+
* Validate that an annotation is on a field with the expected base type.
|
|
4177
|
+
*/ function validateFieldBaseType(token, doc, annotationName, expectedType) {
|
|
4178
|
+
const errors = [];
|
|
4179
|
+
const field = token.parentNode;
|
|
4180
|
+
const definition$1 = field.getDefinition();
|
|
4181
|
+
if (!definition$1 || !isRef(definition$1)) return errors;
|
|
4182
|
+
const unwound = doc.unwindType(definition$1.id, definition$1.chain);
|
|
4183
|
+
if (!unwound || !isPrimitive(unwound.def)) return errors;
|
|
4184
|
+
const baseType = unwound.def.config.type;
|
|
4185
|
+
const allowed = Array.isArray(expectedType) ? expectedType : [expectedType];
|
|
4186
|
+
if (!allowed.includes(baseType)) errors.push({
|
|
4187
|
+
message: `${annotationName} is not compatible with type "${baseType}" — requires ${allowed.join(" or ")}`,
|
|
4188
|
+
severity: 1,
|
|
4189
|
+
range: token.range
|
|
4190
|
+
});
|
|
4191
|
+
return errors;
|
|
4192
|
+
}
|
|
4193
|
+
/**
|
|
4176
4194
|
* Extract target type name from a navigational field definition.
|
|
4177
4195
|
* Unwraps arrays (e.g., `Post[]` → `Post`).
|
|
4178
4196
|
*/ function getNavTargetTypeName(field) {
|
|
@@ -4222,7 +4240,7 @@ else if (isQueryComparison(expr)) {
|
|
|
4222
4240
|
severity: 1,
|
|
4223
4241
|
range: token.range
|
|
4224
4242
|
});
|
|
4225
|
-
if (action === "setDefault" && field.countAnnotations("db.default") === 0 && field.countAnnotations("db.default.
|
|
4243
|
+
if (action === "setDefault" && field.countAnnotations("db.default") === 0 && field.countAnnotations("db.default.increment") === 0 && field.countAnnotations("db.default.uuid") === 0 && field.countAnnotations("db.default.now") === 0) errors.push({
|
|
4226
4244
|
message: `@db.rel.${name} "setDefault" but no @db.default.* annotation — field will have no fallback value`,
|
|
4227
4245
|
severity: 2,
|
|
4228
4246
|
range: token.range
|
|
@@ -4397,6 +4415,39 @@ const dbAnnotations = {
|
|
|
4397
4415
|
type: "string",
|
|
4398
4416
|
description: "The old local field name (parent prefix is reconstructed automatically)."
|
|
4399
4417
|
}
|
|
4418
|
+
}),
|
|
4419
|
+
collate: new AnnotationSpec({
|
|
4420
|
+
description: "Portable collation for string comparison and sorting. Adapters map the generic value to their native collation.\n\n- **\"binary\"** — exact byte comparison (case-sensitive)\n- **\"nocase\"** — case-insensitive comparison\n- **\"unicode\"** — full Unicode-aware sorting\n\nFor adapter-specific collations, use `@db.<engine>.collate` instead.\n\n**Example:**\n```atscript\n@db.column.collate \"nocase\"\nusername: string\n```\n",
|
|
4421
|
+
nodeType: ["prop"],
|
|
4422
|
+
argument: {
|
|
4423
|
+
name: "collation",
|
|
4424
|
+
type: "string",
|
|
4425
|
+
values: [
|
|
4426
|
+
"binary",
|
|
4427
|
+
"nocase",
|
|
4428
|
+
"unicode"
|
|
4429
|
+
],
|
|
4430
|
+
description: "Portable collation mode: \"binary\", \"nocase\", or \"unicode\"."
|
|
4431
|
+
},
|
|
4432
|
+
validate(token, args, doc) {
|
|
4433
|
+
return validateFieldBaseType(token, doc, "@db.column.collate", "string");
|
|
4434
|
+
}
|
|
4435
|
+
}),
|
|
4436
|
+
precision: new AnnotationSpec({
|
|
4437
|
+
description: "Sets decimal precision and scale for database storage. Adapters map this to their native decimal type (e.g., `DECIMAL(10,2)` in SQL, ignored in MongoDB).\n\nThis is purely a DB storage hint — it does not affect runtime JavaScript number behavior.\n\n**Example:**\n```atscript\n@db.column.precision 10, 2\nprice: number\n```\n",
|
|
4438
|
+
nodeType: ["prop"],
|
|
4439
|
+
argument: [{
|
|
4440
|
+
name: "precision",
|
|
4441
|
+
type: "number",
|
|
4442
|
+
description: "Total number of significant digits."
|
|
4443
|
+
}, {
|
|
4444
|
+
name: "scale",
|
|
4445
|
+
type: "number",
|
|
4446
|
+
description: "Number of digits after the decimal point."
|
|
4447
|
+
}],
|
|
4448
|
+
validate(token, args, doc) {
|
|
4449
|
+
return validateFieldBaseType(token, doc, "@db.column.precision", "number");
|
|
4450
|
+
}
|
|
4400
4451
|
})
|
|
4401
4452
|
},
|
|
4402
4453
|
default: {
|
|
@@ -4409,58 +4460,31 @@ const dbAnnotations = {
|
|
|
4409
4460
|
description: "Static default value. Strings used as-is; other types parsed via JSON.parse()."
|
|
4410
4461
|
}
|
|
4411
4462
|
}),
|
|
4412
|
-
|
|
4413
|
-
description: "
|
|
4463
|
+
increment: new AnnotationSpec({
|
|
4464
|
+
description: "Auto-incrementing integer default. Each adapter maps this to its native mechanism (e.g., `AUTO_INCREMENT` in MySQL, `INTEGER PRIMARY KEY` in SQLite, counter collection in MongoDB).\n\n**Example:**\n```atscript\n@db.default.increment\nid: number.int\n\n// With optional start value:\n@db.default.increment 1000\nid: number.int\n```\n",
|
|
4414
4465
|
nodeType: ["prop"],
|
|
4415
4466
|
argument: {
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
"uuid",
|
|
4421
|
-
"now"
|
|
4422
|
-
],
|
|
4423
|
-
description: "Generation function name: \"increment\", \"uuid\", or \"now\"."
|
|
4467
|
+
optional: true,
|
|
4468
|
+
name: "start",
|
|
4469
|
+
type: "number",
|
|
4470
|
+
description: "Starting value for the auto-increment sequence. Adapter-specific behavior; some adapters may ignore this."
|
|
4424
4471
|
},
|
|
4425
4472
|
validate(token, args, doc) {
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
}
|
|
4442
|
-
const field = token.parentNode;
|
|
4443
|
-
const definition$1 = field.getDefinition();
|
|
4444
|
-
if (!definition$1 || !isRef(definition$1)) return errors;
|
|
4445
|
-
const unwound = doc.unwindType(definition$1.id, definition$1.chain);
|
|
4446
|
-
if (!unwound || !isPrimitive(unwound.def)) return errors;
|
|
4447
|
-
const baseType = unwound.def.config.type;
|
|
4448
|
-
if (fnName === "increment" && baseType !== "number") errors.push({
|
|
4449
|
-
message: `@db.default.fn "increment" is not compatible with type "${baseType}" — requires number`,
|
|
4450
|
-
severity: 1,
|
|
4451
|
-
range: token.range
|
|
4452
|
-
});
|
|
4453
|
-
else if (fnName === "uuid" && baseType !== "string") errors.push({
|
|
4454
|
-
message: `@db.default.fn "uuid" is not compatible with type "${baseType}" — requires string`,
|
|
4455
|
-
severity: 1,
|
|
4456
|
-
range: token.range
|
|
4457
|
-
});
|
|
4458
|
-
else if (fnName === "now" && !["number", "string"].includes(baseType)) errors.push({
|
|
4459
|
-
message: `@db.default.fn "now" is not compatible with type "${baseType}" — requires number or string`,
|
|
4460
|
-
severity: 1,
|
|
4461
|
-
range: token.range
|
|
4462
|
-
});
|
|
4463
|
-
return errors;
|
|
4473
|
+
return validateFieldBaseType(token, doc, "db.default.increment", "number");
|
|
4474
|
+
}
|
|
4475
|
+
}),
|
|
4476
|
+
uuid: new AnnotationSpec({
|
|
4477
|
+
description: "UUID generation default. Each adapter maps this to its native mechanism (e.g., `DEFAULT (UUID())` in MySQL, `gen_random_uuid()` in PostgreSQL, app-level in SQLite).\n\n**Example:**\n```atscript\n@db.default.uuid\nid: string.uuid\n```\n",
|
|
4478
|
+
nodeType: ["prop"],
|
|
4479
|
+
validate(token, args, doc) {
|
|
4480
|
+
return validateFieldBaseType(token, doc, "db.default.uuid", "string");
|
|
4481
|
+
}
|
|
4482
|
+
}),
|
|
4483
|
+
now: new AnnotationSpec({
|
|
4484
|
+
description: "Current timestamp default. Each adapter maps this to its native mechanism (e.g., `DEFAULT CURRENT_TIMESTAMP` in MySQL, `DEFAULT now()` in PostgreSQL).\n\n**Example:**\n```atscript\n@db.default.now\ncreatedAt: number.timestamp\n```\n",
|
|
4485
|
+
nodeType: ["prop"],
|
|
4486
|
+
validate(token, args, doc) {
|
|
4487
|
+
return validateFieldBaseType(token, doc, "db.default.now", ["number", "string"]);
|
|
4464
4488
|
}
|
|
4465
4489
|
})
|
|
4466
4490
|
},
|
|
@@ -5346,6 +5370,8 @@ const metaAnnotations = {
|
|
|
5346
5370
|
|
|
5347
5371
|
//#endregion
|
|
5348
5372
|
//#region packages/core/src/defaults/primitives.ts
|
|
5373
|
+
const IPV4_PATTERN = "^((25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)\\.){3}(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)$";
|
|
5374
|
+
const IPV6_PATTERN = "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$";
|
|
5349
5375
|
const positive = {
|
|
5350
5376
|
documentation: "Number that greater than or equal to zero.",
|
|
5351
5377
|
annotations: { "expect.min": 0 }
|
|
@@ -5417,6 +5443,43 @@ const primitives = {
|
|
|
5417
5443
|
message: "Invalid UUID format."
|
|
5418
5444
|
} }
|
|
5419
5445
|
},
|
|
5446
|
+
url: {
|
|
5447
|
+
documentation: "Represents a URL.",
|
|
5448
|
+
annotations: { "expect.pattern": {
|
|
5449
|
+
pattern: "^https?:\\/\\/[^\\s]+$",
|
|
5450
|
+
message: "Invalid URL format."
|
|
5451
|
+
} }
|
|
5452
|
+
},
|
|
5453
|
+
ipv4: {
|
|
5454
|
+
documentation: "Represents an IPv4 address.",
|
|
5455
|
+
annotations: { "expect.pattern": {
|
|
5456
|
+
pattern: IPV4_PATTERN,
|
|
5457
|
+
message: "Invalid IPv4 address."
|
|
5458
|
+
} }
|
|
5459
|
+
},
|
|
5460
|
+
ipv6: {
|
|
5461
|
+
documentation: "Represents an IPv6 address.",
|
|
5462
|
+
annotations: { "expect.pattern": {
|
|
5463
|
+
pattern: IPV6_PATTERN,
|
|
5464
|
+
flags: "i",
|
|
5465
|
+
message: "Invalid IPv6 address."
|
|
5466
|
+
} }
|
|
5467
|
+
},
|
|
5468
|
+
ip: {
|
|
5469
|
+
documentation: "Represents an IP address (IPv4 or IPv6).",
|
|
5470
|
+
annotations: { "expect.pattern": {
|
|
5471
|
+
pattern: `(?:${IPV4_PATTERN.slice(1, -1)})|(?:${IPV6_PATTERN.slice(1, -1)})`,
|
|
5472
|
+
flags: "i",
|
|
5473
|
+
message: "Invalid IP address."
|
|
5474
|
+
} }
|
|
5475
|
+
},
|
|
5476
|
+
char: {
|
|
5477
|
+
documentation: "Represents a single character.",
|
|
5478
|
+
annotations: {
|
|
5479
|
+
"expect.minLength": 1,
|
|
5480
|
+
"expect.maxLength": 1
|
|
5481
|
+
}
|
|
5482
|
+
},
|
|
5420
5483
|
required: {
|
|
5421
5484
|
documentation: "Non-empty string that contains at least one non-whitespace character.",
|
|
5422
5485
|
annotations: { "meta.required": true }
|
|
@@ -5437,18 +5500,92 @@ const primitives = {
|
|
|
5437
5500
|
documentation: "Represents a double-precision floating-point number."
|
|
5438
5501
|
},
|
|
5439
5502
|
int: {
|
|
5440
|
-
extensions: positiveOrNegative,
|
|
5441
5503
|
documentation: "Represents an integer number.",
|
|
5442
|
-
annotations: { "expect.int": true }
|
|
5504
|
+
annotations: { "expect.int": true },
|
|
5505
|
+
extensions: {
|
|
5506
|
+
...positiveOrNegative,
|
|
5507
|
+
int8: {
|
|
5508
|
+
tags: ["int8"],
|
|
5509
|
+
documentation: "Signed 8-bit integer (-128 to 127).",
|
|
5510
|
+
annotations: {
|
|
5511
|
+
"expect.min": -128,
|
|
5512
|
+
"expect.max": 127
|
|
5513
|
+
}
|
|
5514
|
+
},
|
|
5515
|
+
int16: {
|
|
5516
|
+
tags: ["int16"],
|
|
5517
|
+
documentation: "Signed 16-bit integer (-32768 to 32767).",
|
|
5518
|
+
annotations: {
|
|
5519
|
+
"expect.min": -32768,
|
|
5520
|
+
"expect.max": 32767
|
|
5521
|
+
}
|
|
5522
|
+
},
|
|
5523
|
+
int32: {
|
|
5524
|
+
tags: ["int32"],
|
|
5525
|
+
documentation: "Signed 32-bit integer.",
|
|
5526
|
+
annotations: {
|
|
5527
|
+
"expect.min": -2147483648,
|
|
5528
|
+
"expect.max": 2147483647
|
|
5529
|
+
}
|
|
5530
|
+
},
|
|
5531
|
+
int64: {
|
|
5532
|
+
tags: ["int64"],
|
|
5533
|
+
documentation: "Signed 64-bit integer (clamped to JS safe integer range).",
|
|
5534
|
+
annotations: {
|
|
5535
|
+
"expect.min": Number.MIN_SAFE_INTEGER,
|
|
5536
|
+
"expect.max": Number.MAX_SAFE_INTEGER
|
|
5537
|
+
}
|
|
5538
|
+
},
|
|
5539
|
+
uint8: {
|
|
5540
|
+
tags: ["uint8"],
|
|
5541
|
+
documentation: "Unsigned 8-bit integer (0 to 255).",
|
|
5542
|
+
annotations: {
|
|
5543
|
+
"expect.min": 0,
|
|
5544
|
+
"expect.max": 255
|
|
5545
|
+
},
|
|
5546
|
+
extensions: { byte: {
|
|
5547
|
+
tags: ["byte"],
|
|
5548
|
+
documentation: "Byte value (alias for uint8)."
|
|
5549
|
+
} }
|
|
5550
|
+
},
|
|
5551
|
+
uint16: {
|
|
5552
|
+
tags: ["uint16"],
|
|
5553
|
+
documentation: "Unsigned 16-bit integer (0 to 65535).",
|
|
5554
|
+
annotations: {
|
|
5555
|
+
"expect.min": 0,
|
|
5556
|
+
"expect.max": 65535
|
|
5557
|
+
},
|
|
5558
|
+
extensions: { port: {
|
|
5559
|
+
tags: ["port"],
|
|
5560
|
+
documentation: "Network port number (0 to 65535)."
|
|
5561
|
+
} }
|
|
5562
|
+
},
|
|
5563
|
+
uint32: {
|
|
5564
|
+
tags: ["uint32"],
|
|
5565
|
+
documentation: "Unsigned 32-bit integer (0 to 4294967295).",
|
|
5566
|
+
annotations: {
|
|
5567
|
+
"expect.min": 0,
|
|
5568
|
+
"expect.max": 4294967295
|
|
5569
|
+
}
|
|
5570
|
+
},
|
|
5571
|
+
uint64: {
|
|
5572
|
+
tags: ["uint64"],
|
|
5573
|
+
documentation: "Unsigned 64-bit integer (clamped to JS safe integer range).",
|
|
5574
|
+
annotations: {
|
|
5575
|
+
"expect.min": 0,
|
|
5576
|
+
"expect.max": Number.MAX_SAFE_INTEGER
|
|
5577
|
+
}
|
|
5578
|
+
}
|
|
5579
|
+
}
|
|
5443
5580
|
},
|
|
5444
5581
|
timestamp: {
|
|
5445
5582
|
documentation: "Represents a timestamp.",
|
|
5446
5583
|
annotations: { "expect.int": true },
|
|
5447
5584
|
extensions: {
|
|
5448
5585
|
created: {
|
|
5449
|
-
documentation: "Timestamp auto-set on creation. Auto-applies @db.default.
|
|
5586
|
+
documentation: "Timestamp auto-set on creation. Auto-applies @db.default.now.",
|
|
5450
5587
|
tags: ["created"],
|
|
5451
|
-
annotations: { "db.default.
|
|
5588
|
+
annotations: { "db.default.now": true }
|
|
5452
5589
|
},
|
|
5453
5590
|
updated: {
|
|
5454
5591
|
documentation: "Timestamp auto-updated on every write. DB adapters read the \"updated\" tag.",
|
package/package.json
CHANGED
|
@@ -60,7 +60,11 @@
|
|
|
60
60
|
| `@db.index.fulltext`| `name?: string` | **yes** (append) | prop | Fulltext search index |
|
|
61
61
|
| `@db.column` | `name: string` | no | prop | Override database column name |
|
|
62
62
|
| `@db.default` | `value: string` | no | prop | Static default value |
|
|
63
|
-
| `@db.default.
|
|
63
|
+
| `@db.default.increment` | `start?: number` | no | prop | Auto-incrementing integer default |
|
|
64
|
+
| `@db.default.uuid` | _(none)_ | no | prop | UUID generation default |
|
|
65
|
+
| `@db.default.now` | _(none)_ | no | prop | Current timestamp default |
|
|
66
|
+
| `@db.column.collate`| `collation: string` | no | prop | Portable collation (binary/nocase/unicode)|
|
|
67
|
+
| `@db.column.precision`| `precision: number`, `scale: number` | no | prop | Decimal precision/scale for DB storage |
|
|
64
68
|
| `@db.ignore` | _(none)_ | no | prop | Exclude field from database |
|
|
65
69
|
|
|
66
70
|
### `@emit.*` — Build-time Directives
|
|
@@ -16,6 +16,11 @@ Base type for textual data. Extensions accessed via dot notation in `.as` files.
|
|
|
16
16
|
| `string.date` | Date string (multiple formats) | YYYY-MM-DD, MM/DD/YYYY, etc. |
|
|
17
17
|
| `string.isoDate` | ISO 8601 date | UTC and timezone variants |
|
|
18
18
|
| `string.uuid` | UUID | Standard UUID format (case-insensitive) |
|
|
19
|
+
| `string.url` | URL | Pattern: `^https?://[^\s]+$` |
|
|
20
|
+
| `string.ipv4` | IPv4 address | Pattern: standard IPv4 validation |
|
|
21
|
+
| `string.ipv6` | IPv6 address | Pattern: standard IPv6 validation (case-insensitive) |
|
|
22
|
+
| `string.ip` | IP address (IPv4 or IPv6) | Accepts either IPv4 or IPv6 format |
|
|
23
|
+
| `string.char` | Single character | `@expect.minLength 1`, `@expect.maxLength 1` |
|
|
19
24
|
| `string.required` | Non-empty string | `@meta.required` applied |
|
|
20
25
|
|
|
21
26
|
### `number`
|
|
@@ -30,10 +35,20 @@ Base type for numeric data.
|
|
|
30
35
|
| `number.int` | Integer | `@expect.int` |
|
|
31
36
|
| `number.int.positive` | Positive integer | `@expect.int` + `@expect.min 0` |
|
|
32
37
|
| `number.int.negative` | Negative integer | `@expect.int` + `@expect.max 0` |
|
|
38
|
+
| `number.int.int8` | Signed 8-bit (-128 to 127) | `@expect.min -128`, `@expect.max 127`, tag: `int8` |
|
|
39
|
+
| `number.int.int16` | Signed 16-bit (-32768 to 32767) | `@expect.min -32768`, `@expect.max 32767`, tag: `int16` |
|
|
40
|
+
| `number.int.int32` | Signed 32-bit integer | `@expect.min -2147483648`, `@expect.max 2147483647`, tag: `int32` |
|
|
41
|
+
| `number.int.int64` | Signed 64-bit (JS safe range) | `@expect.min MIN_SAFE_INTEGER`, `@expect.max MAX_SAFE_INTEGER`, tag: `int64` |
|
|
42
|
+
| `number.int.uint8` | Unsigned 8-bit (0 to 255) | `@expect.min 0`, `@expect.max 255`, tag: `uint8` |
|
|
43
|
+
| `number.int.uint8.byte` | Byte value (alias for uint8) | tag: `byte` |
|
|
44
|
+
| `number.int.uint16` | Unsigned 16-bit (0 to 65535) | `@expect.min 0`, `@expect.max 65535`, tag: `uint16` |
|
|
45
|
+
| `number.int.uint16.port` | Network port (0 to 65535) | tag: `port` |
|
|
46
|
+
| `number.int.uint32` | Unsigned 32-bit (0 to 4294967295) | `@expect.min 0`, `@expect.max 4294967295`, tag: `uint32` |
|
|
47
|
+
| `number.int.uint64` | Unsigned 64-bit (JS safe range) | `@expect.min 0`, `@expect.max MAX_SAFE_INTEGER`, tag: `uint64` |
|
|
33
48
|
| `number.single` | Single-precision float | — |
|
|
34
49
|
| `number.double` | Double-precision float | — |
|
|
35
50
|
| `number.timestamp` | Timestamp (integer) | `@expect.int` |
|
|
36
|
-
| `number.timestamp.created` | Auto-set on creation | `@db.default.
|
|
51
|
+
| `number.timestamp.created` | Auto-set on creation | `@db.default.now`, tag: `created` |
|
|
37
52
|
| `number.timestamp.updated` | Auto-updated on write | tag: `updated` |
|
|
38
53
|
|
|
39
54
|
### `boolean`
|