@atscript/core 0.1.36 → 0.1.38

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
@@ -1181,7 +1181,8 @@ async function loadTsConfig(configFile, forceFormat) {
1181
1181
  (0, node_url.pathToFileURL)(file).href
1182
1182
  )).default;
1183
1183
  } catch (error) {
1184
- console.error("Could not load config file", file, error);
1184
+ const message = error instanceof Error ? error.message : String(error);
1185
+ console.error(`Could not load config file ${configFile}: ${message}`);
1185
1186
  return {};
1186
1187
  } finally {
1187
1188
  node_fs.default.unlink(file, () => {});
@@ -4044,1015 +4045,6 @@ function createSyntheticRef(name) {
4044
4045
  return ref$1;
4045
4046
  }
4046
4047
 
4047
- //#endregion
4048
- //#region packages/core/src/defaults/db-utils.ts
4049
- function validateRefArgument(token, doc, options) {
4050
- const messages = [];
4051
- const text$2 = token.text;
4052
- const [typeName, ...chain] = text$2.split(".");
4053
- const decl = doc.getDeclarationOwnerNode(typeName);
4054
- if (!decl) {
4055
- const regDef = doc.registry.definitions.get(typeName);
4056
- if (regDef?.imported) return messages;
4057
- messages.push({
4058
- severity: 1,
4059
- message: `Unknown type '${typeName}'.`,
4060
- range: token.range
4061
- });
4062
- return messages;
4063
- }
4064
- if (chain.length > 0) {
4065
- const unwound = doc.unwindType(typeName, chain);
4066
- if (!unwound) {
4067
- messages.push({
4068
- severity: 1,
4069
- message: `Field '${chain.join(".")}' does not exist on type '${typeName}'.`,
4070
- range: token.range
4071
- });
4072
- return messages;
4073
- }
4074
- }
4075
- if (options?.requireDbTable && decl.node) {
4076
- const hasDbTable = decl.node.countAnnotations("db.table") > 0;
4077
- if (!hasDbTable) messages.push({
4078
- severity: 1,
4079
- message: `Type '${typeName}' must have @db.table annotation.`,
4080
- range: token.range
4081
- });
4082
- }
4083
- return messages;
4084
- }
4085
- function findFKFieldsPointingTo(doc, iface, targetTypeName, alias) {
4086
- const results = [];
4087
- let struct;
4088
- if (isInterface(iface) && iface.hasExtends) {
4089
- const resolved = doc.resolveInterfaceExtends(iface);
4090
- if (resolved && isStructure(resolved)) struct = resolved;
4091
- }
4092
- if (!struct) struct = isStructure(iface) ? iface : isInterface(iface) && isStructure(iface.getDefinition()) ? iface.getDefinition() : undefined;
4093
- if (!struct) return results;
4094
- for (const [name, prop] of struct.props) {
4095
- if (prop.countAnnotations("db.rel.FK") === 0) continue;
4096
- const def = prop.getDefinition();
4097
- if (!def || !isRef(def)) continue;
4098
- const ref$1 = def;
4099
- if (!ref$1.hasChain) continue;
4100
- const refTypeName = ref$1.id;
4101
- const refField = ref$1.chain.map((c) => c.text).join(".");
4102
- if (refTypeName !== targetTypeName) continue;
4103
- if (alias !== undefined) {
4104
- const fkAnnotations = prop.annotations?.filter((a) => a.name === "db.rel.FK");
4105
- const hasMatchingAlias = fkAnnotations?.some((a) => a.args.length > 0 && a.args[0].text === alias);
4106
- if (!hasMatchingAlias) continue;
4107
- }
4108
- results.push({
4109
- name,
4110
- prop,
4111
- chainRef: {
4112
- type: refTypeName,
4113
- field: refField
4114
- }
4115
- });
4116
- }
4117
- return results;
4118
- }
4119
- const viewAnnotationNames = [
4120
- "db.view",
4121
- "db.view.for",
4122
- "db.view.joins",
4123
- "db.view.filter",
4124
- "db.view.materialized"
4125
- ];
4126
- function hasAnyViewAnnotation(node) {
4127
- return viewAnnotationNames.some((name) => node.countAnnotations(name) > 0);
4128
- }
4129
- function validateQueryScope(queryToken, allowedTypes, unqualifiedTarget, doc) {
4130
- const errors = [];
4131
- const queryNode = queryToken.queryNode;
4132
- if (!queryNode) return errors;
4133
- function walkFieldRef(ref$1) {
4134
- if (ref$1.typeRef) {
4135
- const typeName = ref$1.typeRef.text;
4136
- if (!allowedTypes.includes(typeName)) errors.push({
4137
- message: `Query references '${typeName}' which is not in scope — expected ${allowedTypes.map((t) => `'${t}'`).join(" or ")}`,
4138
- severity: 1,
4139
- range: ref$1.typeRef.range
4140
- });
4141
- } else if (unqualifiedTarget === null) errors.push({
4142
- message: `Unqualified field reference '${ref$1.fieldRef.text}' — use qualified form (e.g., Type.${ref$1.fieldRef.text})`,
4143
- severity: 1,
4144
- range: ref$1.fieldRef.range
4145
- });
4146
- else {
4147
- const unwound = doc.unwindType(unqualifiedTarget);
4148
- if (unwound) {
4149
- const targetDef = unwound.def;
4150
- if (isInterface(targetDef) || isStructure(targetDef)) {
4151
- const struct = isInterface(targetDef) ? targetDef.getDefinition() : targetDef;
4152
- if (struct && isStructure(struct) && !struct.props.has(ref$1.fieldRef.text)) errors.push({
4153
- message: `Field '${ref$1.fieldRef.text}' does not exist on '${unqualifiedTarget}'`,
4154
- severity: 1,
4155
- range: ref$1.fieldRef.range
4156
- });
4157
- }
4158
- }
4159
- }
4160
- }
4161
- function walkExpr(expr) {
4162
- if (isQueryLogical(expr)) for (const operand of expr.operands) walkExpr(operand);
4163
- else if (isQueryComparison(expr)) {
4164
- walkFieldRef(expr.left);
4165
- if (expr.right && "fieldRef" in expr.right) walkFieldRef(expr.right);
4166
- }
4167
- }
4168
- walkExpr(queryNode.expression);
4169
- return errors;
4170
- }
4171
-
4172
- //#endregion
4173
- //#region packages/core/src/defaults/db-annotations.ts
4174
- /**
4175
- * Traverse from annotation token → prop → structure → interface
4176
- * to check if the parent interface has @db.table.
4177
- */ function getDbTableOwner(token) {
4178
- const field = token.parentNode;
4179
- const struct = field.ownerNode;
4180
- if (!struct || !isStructure(struct)) return undefined;
4181
- const iface = struct.ownerNode;
4182
- return iface && isInterface(iface) ? iface : struct;
4183
- }
4184
- /**
4185
- * Get the parent structure node from an annotation token.
4186
- */ function getParentStruct(token) {
4187
- const field = token.parentNode;
4188
- const struct = field.ownerNode;
4189
- return struct && isStructure(struct) ? struct : undefined;
4190
- }
4191
- /**
4192
- * Get the parent interface name (for error messages and cross-type resolution).
4193
- */ function getParentTypeName(token) {
4194
- const struct = getParentStruct(token);
4195
- if (!struct) return undefined;
4196
- const iface = struct.ownerNode;
4197
- return iface && isInterface(iface) ? iface.id : struct.id;
4198
- }
4199
- /**
4200
- * Extract target type name from a navigational field definition.
4201
- * Unwraps arrays (e.g., `Post[]` → `Post`).
4202
- */ function getNavTargetTypeName(field) {
4203
- let def = field.getDefinition();
4204
- if (isArray(def)) def = def?.getDefinition();
4205
- if (isRef(def)) return def.id;
4206
- return undefined;
4207
- }
4208
- /**
4209
- * Get the alias argument from an annotation on a field.
4210
- */ function getAnnotationAlias(prop, annotationName) {
4211
- const annotations$1 = prop.annotations?.filter((a) => a.name === annotationName);
4212
- if (!annotations$1 || annotations$1.length === 0) return undefined;
4213
- return annotations$1[0].args.length > 0 ? annotations$1[0].args[0].text : undefined;
4214
- }
4215
- /**
4216
- * Factory for @db.rel.onDelete / @db.rel.onUpdate — identical validation logic,
4217
- * only the annotation name and description verb differ.
4218
- */ function refActionAnnotation(name) {
4219
- return new AnnotationSpec({
4220
- description: `Referential action when the target ${name === "onDelete" ? "row is deleted" : "key is updated"}. Only valid on @db.rel.FK fields.\n\n` + "**Example:**\n" + "```atscript\n" + "@db.rel.FK\n" + `@db.rel.${name} "cascade"\n` + "authorId: User.id\n" + "```\n",
4221
- nodeType: ["prop"],
4222
- argument: {
4223
- name: "action",
4224
- type: "string",
4225
- values: [
4226
- "cascade",
4227
- "restrict",
4228
- "noAction",
4229
- "setNull",
4230
- "setDefault"
4231
- ],
4232
- description: "Referential action: \"cascade\", \"restrict\", \"noAction\", \"setNull\", or \"setDefault\"."
4233
- },
4234
- validate(token, args, doc) {
4235
- const errors = [];
4236
- const field = token.parentNode;
4237
- if (field.countAnnotations("db.rel.FK") === 0) errors.push({
4238
- message: `@db.rel.${name} is only valid on @db.rel.FK fields`,
4239
- severity: 1,
4240
- range: token.range
4241
- });
4242
- if (args[0]) {
4243
- const action = args[0].text;
4244
- if (action === "setNull" && !field.has("optional")) errors.push({
4245
- message: `@db.rel.${name} "setNull" requires the FK field to be optional (?)`,
4246
- severity: 1,
4247
- range: token.range
4248
- });
4249
- if (action === "setDefault" && field.countAnnotations("db.default") === 0 && field.countAnnotations("db.default.fn") === 0) errors.push({
4250
- message: `@db.rel.${name} "setDefault" but no @db.default.* annotation — field will have no fallback value`,
4251
- severity: 2,
4252
- range: token.range
4253
- });
4254
- }
4255
- const fkAlias = getAnnotationAlias(field, "db.rel.FK");
4256
- if (fkAlias) {
4257
- const struct = getParentStruct(token);
4258
- if (struct) {
4259
- const annotationName = `db.rel.${name}`;
4260
- let count = 0;
4261
- for (const [, prop] of struct.props) {
4262
- if (prop.countAnnotations("db.rel.FK") === 0) continue;
4263
- if (prop.countAnnotations(annotationName) === 0) continue;
4264
- const propFkAlias = getAnnotationAlias(prop, "db.rel.FK");
4265
- if (propFkAlias === fkAlias) count++;
4266
- }
4267
- if (count > 1) errors.push({
4268
- message: `Composite FK '${fkAlias}' has @db.rel.${name} on multiple fields — declare it on exactly one`,
4269
- severity: 1,
4270
- range: token.range
4271
- });
4272
- }
4273
- }
4274
- return errors;
4275
- }
4276
- });
4277
- }
4278
- const dbAnnotations = {
4279
- patch: { strategy: new AnnotationSpec({
4280
- description: "Defines the **patching strategy** for updating nested objects.\n\n- **\"replace\"** → The field or object will be **fully replaced**.\n- **\"merge\"** → The field or object will be **merged recursively** (applies only to objects, not arrays).\n\n**Example:**\n```atscript\n@db.patch.strategy \"merge\"\nsettings: {\n notifications: boolean\n preferences: {\n theme: string\n }\n}\n```\n",
4281
- nodeType: ["prop"],
4282
- multiple: false,
4283
- argument: {
4284
- name: "strategy",
4285
- type: "string",
4286
- description: "The **patch strategy** for this field: `\"replace\"` (default) or `\"merge\"`.",
4287
- values: ["replace", "merge"]
4288
- },
4289
- validate(token, args, doc) {
4290
- const field = token.parentNode;
4291
- const errors = [];
4292
- const definition$1 = field.getDefinition();
4293
- if (!definition$1) return errors;
4294
- let wrongType = false;
4295
- if (isRef(definition$1)) {
4296
- const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
4297
- if (!isStructure(def) && !isInterface(def) && !isArray(def)) wrongType = true;
4298
- } else if (!isStructure(definition$1) && !isInterface(definition$1) && !isArray(definition$1)) wrongType = true;
4299
- if (wrongType) errors.push({
4300
- message: `@db.patch.strategy requires a field of type object or array`,
4301
- severity: 1,
4302
- range: token.range
4303
- });
4304
- return errors;
4305
- }
4306
- }) },
4307
- table: {
4308
- $self: new AnnotationSpec({
4309
- description: "Marks an interface as a database-persisted entity (table in SQL, collection in MongoDB). If the name argument is omitted, the adapter derives the table name from the interface name.\n\n**Example:**\n```atscript\n@db.table \"users\"\nexport interface User { ... }\n```\n",
4310
- nodeType: ["interface"],
4311
- argument: {
4312
- optional: true,
4313
- name: "name",
4314
- type: "string",
4315
- description: "Table/collection name. If omitted, derived from interface name."
4316
- },
4317
- validate(token, _args, _doc) {
4318
- const errors = [];
4319
- const owner = token.parentNode;
4320
- if (hasAnyViewAnnotation(owner)) errors.push({
4321
- message: "An interface cannot be both a @db.table and a @db.view",
4322
- severity: 1,
4323
- range: token.range
4324
- });
4325
- return errors;
4326
- }
4327
- }),
4328
- renamed: new AnnotationSpec({
4329
- description: "Specifies the previous table name for table rename migration. The sync engine generates ALTER TABLE RENAME instead of drop+create.\n\n**Example:**\n```atscript\n@db.table \"app_users\"\n@db.table.renamed \"users\"\nexport interface User { ... }\n```\n",
4330
- nodeType: ["interface"],
4331
- argument: {
4332
- name: "oldName",
4333
- type: "string",
4334
- description: "The previous table/collection name."
4335
- },
4336
- validate(token, _args, _doc) {
4337
- const errors = [];
4338
- const owner = token.parentNode;
4339
- if (owner.countAnnotations("db.table") === 0) errors.push({
4340
- message: "@db.table.renamed requires @db.table on the same interface",
4341
- severity: 1,
4342
- range: token.range
4343
- });
4344
- return errors;
4345
- }
4346
- })
4347
- },
4348
- schema: new AnnotationSpec({
4349
- description: "Assigns the entity to a database schema/namespace.\n\n**Example:**\n```atscript\n@db.table \"users\"\n@db.schema \"auth\"\nexport interface User { ... }\n```\n",
4350
- nodeType: ["interface"],
4351
- argument: {
4352
- name: "name",
4353
- type: "string",
4354
- description: "Schema/namespace name."
4355
- }
4356
- }),
4357
- index: {
4358
- plain: new AnnotationSpec({
4359
- description: "Standard (non-unique) index for query performance. Fields sharing the same index name form a composite index.\n\n**Example:**\n```atscript\n@db.index.plain \"idx_timeline\", \"desc\"\ncreatedAt: number.timestamp\n```\n",
4360
- nodeType: ["prop"],
4361
- multiple: true,
4362
- mergeStrategy: "append",
4363
- argument: [{
4364
- optional: true,
4365
- name: "name",
4366
- type: "string",
4367
- description: "Index name / composite group name."
4368
- }, {
4369
- optional: true,
4370
- name: "sort",
4371
- type: "string",
4372
- values: ["asc", "desc"],
4373
- description: "Sort direction. Defaults to \"asc\"."
4374
- }]
4375
- }),
4376
- unique: new AnnotationSpec({
4377
- description: "Unique index — ensures no two rows/documents have the same value(s). Fields sharing the same index name form a composite unique constraint.\n\n**Example:**\n```atscript\n@db.index.unique \"tenant_email\"\nemail: string.email\n```\n",
4378
- nodeType: ["prop"],
4379
- multiple: true,
4380
- mergeStrategy: "append",
4381
- argument: {
4382
- optional: true,
4383
- name: "name",
4384
- type: "string",
4385
- description: "Index name / composite group name."
4386
- }
4387
- }),
4388
- fulltext: new AnnotationSpec({
4389
- description: "Full-text search index. Fields sharing the same index name form a composite full-text index.\n\n**Example:**\n```atscript\n@db.index.fulltext \"ft_content\"\ntitle: string\n\n@db.index.fulltext \"ft_content\", 5\nbio: string\n```\n",
4390
- nodeType: ["prop"],
4391
- multiple: true,
4392
- mergeStrategy: "append",
4393
- argument: [{
4394
- optional: true,
4395
- name: "name",
4396
- type: "string",
4397
- description: "Index name / composite group name."
4398
- }, {
4399
- optional: true,
4400
- name: "weight",
4401
- type: "number",
4402
- description: "Field importance in search results (higher = more relevant). Defaults to `1`. Supported by databases with weighted fulltext (e.g., MongoDB, PostgreSQL)."
4403
- }]
4404
- })
4405
- },
4406
- column: {
4407
- $self: new AnnotationSpec({
4408
- description: "Overrides the physical column name in the database. For nested (flattened) fields, the parent prefix is still prepended automatically.\n\n**Example:**\n```atscript\n@db.column \"first_name\"\nfirstName: string\n// → physical column: first_name\n\n// Nested:\naddress: {\n @db.column \"zip_code\"\n zip: string\n}\n// → physical column: address__zip_code\n```\n",
4409
- nodeType: ["prop"],
4410
- argument: {
4411
- name: "name",
4412
- type: "string",
4413
- description: "The column/field name (without parent prefix for nested fields)."
4414
- }
4415
- }),
4416
- renamed: new AnnotationSpec({
4417
- description: "Specifies the previous local field name for column rename migration. The sync engine generates ALTER TABLE RENAME COLUMN instead of drop+add.\n\n**Example:**\n```atscript\n@db.column.renamed \"zip\"\npostalCode: string\n// Renames address__zip → address__postalCode\n```\n",
4418
- nodeType: ["prop"],
4419
- argument: {
4420
- name: "oldName",
4421
- type: "string",
4422
- description: "The old local field name (parent prefix is reconstructed automatically)."
4423
- }
4424
- })
4425
- },
4426
- default: {
4427
- $self: new AnnotationSpec({
4428
- description: "Sets a static DB-level default value (used in DDL DEFAULT clause). For string fields the value is used as-is; for other types it is parsed as JSON.\n\n**Example:**\n```atscript\n@db.default \"active\"\nstatus: string\n```\n",
4429
- nodeType: ["prop"],
4430
- argument: {
4431
- name: "value",
4432
- type: "string",
4433
- description: "Static default value. Strings used as-is; other types parsed via JSON.parse()."
4434
- }
4435
- }),
4436
- fn: new AnnotationSpec({
4437
- description: "Sets a DB-level generated default. The function name is portable — each adapter maps it to the appropriate DB mechanism.\n\n**Example:**\n```atscript\n@db.default.fn \"increment\"\nid: number\n```\n",
4438
- nodeType: ["prop"],
4439
- argument: {
4440
- name: "fn",
4441
- type: "string",
4442
- values: [
4443
- "increment",
4444
- "uuid",
4445
- "now"
4446
- ],
4447
- description: "Generation function name: \"increment\", \"uuid\", or \"now\"."
4448
- },
4449
- validate(token, args, doc) {
4450
- const errors = [];
4451
- if (!args[0]) return errors;
4452
- const fnName = args[0].text;
4453
- const validFns = [
4454
- "increment",
4455
- "uuid",
4456
- "now"
4457
- ];
4458
- if (!validFns.includes(fnName)) {
4459
- errors.push({
4460
- message: `Unknown @db.default.fn "${fnName}" — expected "increment", "uuid", or "now"`,
4461
- severity: 1,
4462
- range: args[0].range
4463
- });
4464
- return errors;
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;
4488
- }
4489
- })
4490
- },
4491
- json: new AnnotationSpec({
4492
- description: "Forces a field to be stored as a single JSON column instead of being flattened into separate columns. Use on nested object fields that should remain as JSON in the database.\n\n**Example:**\n```atscript\n@db.json\nmetadata: { key: string, value: string }\n```\n",
4493
- nodeType: ["prop"],
4494
- validate(token, _args, doc) {
4495
- const errors = [];
4496
- const field = token.parentNode;
4497
- const definition$1 = field.getDefinition();
4498
- if (definition$1 && isRef(definition$1)) {
4499
- const unwound = doc.unwindType(definition$1.id, definition$1.chain);
4500
- if (unwound && isPrimitive(unwound.def)) errors.push({
4501
- message: "@db.json on a primitive field has no effect — primitive fields are already stored as scalar columns",
4502
- severity: 2,
4503
- range: token.range
4504
- });
4505
- }
4506
- return errors;
4507
- }
4508
- }),
4509
- ignore: new AnnotationSpec({
4510
- description: "Excludes a field from the database schema. The field exists in the Atscript type but has no column in the DB.\n\n**Example:**\n```atscript\n@db.ignore\ndisplayName: string\n```\n",
4511
- nodeType: ["prop"],
4512
- validate(token, args, doc) {
4513
- const errors = [];
4514
- const field = token.parentNode;
4515
- if (field.countAnnotations("meta.id") > 0) errors.push({
4516
- message: `@db.ignore cannot coexist with @meta.id — a field cannot be both a primary key and excluded from the database`,
4517
- severity: 1,
4518
- range: token.range
4519
- });
4520
- return errors;
4521
- }
4522
- }),
4523
- sync: { method: new AnnotationSpec({
4524
- description: "Controls how the sync engine handles structural changes that cannot be applied via ALTER TABLE.\n\n- `\"recreate\"` — lossless: create temp table, copy data, drop old, rename.\n- `\"drop\"` — lossy: drop table entirely and create from scratch.\n\nWithout this annotation, structural changes fail with an error requiring manual intervention.\n\n**Example:**\n```atscript\n@db.sync.method \"drop\"\ninterface Logs { ... }\n```\n",
4525
- nodeType: ["interface"],
4526
- argument: {
4527
- name: "method",
4528
- type: "string",
4529
- description: "Sync method: \"drop\" (lossy) or \"recreate\" (lossless with data copy).",
4530
- values: ["drop", "recreate"]
4531
- }
4532
- }) },
4533
- rel: {
4534
- FK: new AnnotationSpec({
4535
- description: "Declares a foreign key constraint on this field. The field must use a chain reference type (e.g., `User.id`) to specify the FK target.\n\n**Example:**\n```atscript\n@db.rel.FK\nauthorId: User.id\n\n// With alias (required when multiple FKs point to the same type)\n@db.rel.FK \"author\"\nauthorId: User.id\n```\n",
4536
- nodeType: ["prop"],
4537
- argument: {
4538
- optional: true,
4539
- name: "alias",
4540
- type: "string",
4541
- description: "Alias for pairing with @db.rel.to. Required when multiple FKs point to the same target type."
4542
- },
4543
- validate(token, args, doc) {
4544
- const errors = [];
4545
- const field = token.parentNode;
4546
- const alias = args[0]?.text;
4547
- const owner = getDbTableOwner(token);
4548
- if (!owner || owner.countAnnotations("db.table") === 0) errors.push({
4549
- message: "@db.rel.FK is only valid on fields of a @db.table interface",
4550
- severity: 1,
4551
- range: token.range
4552
- });
4553
- if (field.countAnnotations("db.rel.to") > 0 || field.countAnnotations("db.rel.from") > 0) errors.push({
4554
- message: "A field cannot be both a foreign key and a navigational property",
4555
- severity: 1,
4556
- range: token.range
4557
- });
4558
- const definition$1 = field.getDefinition();
4559
- if (!definition$1 || !isRef(definition$1) || !definition$1.hasChain) {
4560
- errors.push({
4561
- message: `@db.rel.FK requires a chain reference type (e.g. User.id), got scalar type`,
4562
- severity: 1,
4563
- range: token.range
4564
- });
4565
- return errors;
4566
- }
4567
- const ref$1 = definition$1;
4568
- const refTypeName = ref$1.id;
4569
- const chainFields = ref$1.chain.map((c) => c.text);
4570
- const targetUnwound = doc.unwindType(refTypeName);
4571
- if (targetUnwound) {
4572
- const targetDef = targetUnwound.def;
4573
- if (isInterface(targetDef) || isStructure(targetDef)) {
4574
- const struct = isInterface(targetDef) ? targetDef.getDefinition() : targetDef;
4575
- if (struct && isStructure(struct) && chainFields.length > 0) {
4576
- const targetProp = struct.props.get(chainFields[0]);
4577
- if (targetProp) {
4578
- if (targetProp.countAnnotations("meta.id") === 0 && targetProp.countAnnotations("db.index.unique") === 0) errors.push({
4579
- message: `@db.rel.FK target '${refTypeName}.${chainFields.join(".")}' is not a primary key (@meta.id) or unique (@db.index.unique) field`,
4580
- severity: 1,
4581
- range: token.range
4582
- });
4583
- const propDef = targetProp.getDefinition();
4584
- if (propDef && isRef(propDef)) {
4585
- const propUnwound = targetUnwound.doc.unwindType(propDef.id, propDef.chain);
4586
- if (propUnwound && !isPrimitive(propUnwound.def)) errors.push({
4587
- message: `Foreign key field must resolve to a scalar type (number, string, etc.), got '${propDef.id}'`,
4588
- severity: 1,
4589
- range: token.range
4590
- });
4591
- } else if (propDef && !isPrimitive(propDef)) errors.push({
4592
- message: `Foreign key field must resolve to a scalar type (number, string, etc.)`,
4593
- severity: 1,
4594
- range: token.range
4595
- });
4596
- }
4597
- }
4598
- }
4599
- }
4600
- if (!alias) {
4601
- const struct = getParentStruct(token);
4602
- if (struct) {
4603
- let sameTargetCount = 0;
4604
- for (const [, prop] of struct.props) {
4605
- if (prop.countAnnotations("db.rel.FK") === 0) continue;
4606
- const def = prop.getDefinition();
4607
- if (!def || !isRef(def)) continue;
4608
- const r = def;
4609
- if (!r.hasChain) continue;
4610
- if (r.id === refTypeName) {
4611
- const fkAnnotations = prop.annotations?.filter((a) => a.name === "db.rel.FK");
4612
- const hasAlias = fkAnnotations?.some((a) => a.args.length > 0);
4613
- if (!hasAlias) sameTargetCount++;
4614
- }
4615
- }
4616
- if (sameTargetCount > 1) errors.push({
4617
- message: `Multiple @db.rel.FK fields resolve to type '${refTypeName}' — add alias to disambiguate`,
4618
- severity: 1,
4619
- range: token.range
4620
- });
4621
- }
4622
- }
4623
- return errors;
4624
- }
4625
- }),
4626
- to: new AnnotationSpec({
4627
- description: "Forward navigational property — the FK is on **this** interface. The compiler resolves the matching @db.rel.FK by target type or alias.\n\n**Example:**\n```atscript\n@db.rel.to\nauthor?: User\n\n// With alias\n@db.rel.to \"author\"\nauthor?: User\n```\n",
4628
- nodeType: ["prop"],
4629
- argument: {
4630
- optional: true,
4631
- name: "alias",
4632
- type: "string",
4633
- description: "Match a local @db.rel.FK by alias."
4634
- },
4635
- validate(token, args, doc) {
4636
- const errors = [];
4637
- const field = token.parentNode;
4638
- const alias = args[0]?.text;
4639
- const owner = getDbTableOwner(token);
4640
- if (!owner || owner.countAnnotations("db.table") === 0) errors.push({
4641
- message: "@db.rel.to is only valid on fields of a @db.table interface",
4642
- severity: 1,
4643
- range: token.range
4644
- });
4645
- if (field.countAnnotations("db.rel.FK") > 0) errors.push({
4646
- message: "A field cannot be both a foreign key and a navigational property",
4647
- severity: 1,
4648
- range: token.range
4649
- });
4650
- const targetTypeName = getNavTargetTypeName(field);
4651
- if (!targetTypeName) return errors;
4652
- const unwound = doc.unwindType(targetTypeName);
4653
- if (unwound) {
4654
- const targetDef = unwound.def;
4655
- const targetNode = isInterface(targetDef) ? targetDef : undefined;
4656
- if (!targetNode || targetNode.countAnnotations("db.table") === 0) errors.push({
4657
- message: `@db.rel.to target '${targetTypeName}' is not a @db.table entity`,
4658
- severity: 1,
4659
- range: token.range
4660
- });
4661
- }
4662
- const fieldDef = field.getDefinition();
4663
- if (fieldDef && fieldDef.entity === "group" && fieldDef.op === "|") errors.push({
4664
- message: "@db.rel.to does not support union types — use separate relations",
4665
- severity: 1,
4666
- range: token.range
4667
- });
4668
- const struct = getParentStruct(token);
4669
- if (struct) {
4670
- const fieldName = field.id;
4671
- for (const [name, prop] of struct.props) {
4672
- if (name === fieldName) continue;
4673
- if (prop.countAnnotations("db.rel.to") === 0) continue;
4674
- const propAlias = getAnnotationAlias(prop, "db.rel.to");
4675
- if ((alias || undefined) === (propAlias || undefined)) {
4676
- const otherTarget = getNavTargetTypeName(prop);
4677
- if (otherTarget === targetTypeName) {
4678
- errors.push({
4679
- message: `Duplicate @db.rel.to '${alias || targetTypeName}' — only one forward navigational property per alias`,
4680
- severity: 1,
4681
- range: token.range
4682
- });
4683
- break;
4684
- }
4685
- }
4686
- }
4687
- if (alias) {
4688
- const matches = findFKFieldsPointingTo(doc, struct, targetTypeName, alias);
4689
- if (matches.length === 0) errors.push({
4690
- message: `No @db.rel.FK '${alias}' found on this interface`,
4691
- severity: 1,
4692
- range: token.range
4693
- });
4694
- } else {
4695
- const matches = findFKFieldsPointingTo(doc, struct, targetTypeName);
4696
- if (matches.length === 0) errors.push({
4697
- message: `No @db.rel.FK on this interface points to '${targetTypeName}' — did you mean @db.rel.from?`,
4698
- severity: 1,
4699
- range: token.range
4700
- });
4701
- else if (matches.length > 1) errors.push({
4702
- message: `Multiple @db.rel.FK fields point to '${targetTypeName}' — add alias to disambiguate`,
4703
- severity: 1,
4704
- range: token.range
4705
- });
4706
- }
4707
- }
4708
- return errors;
4709
- }
4710
- }),
4711
- from: new AnnotationSpec({
4712
- description: "Inverse navigational property — the FK is on the **target** interface, pointing back to this one.\n\n**Example:**\n```atscript\n@db.rel.from\nposts: Post[]\n\n// With alias\n@db.rel.from \"original\"\ncomments: Comment[]\n```\n",
4713
- nodeType: ["prop"],
4714
- argument: {
4715
- optional: true,
4716
- name: "alias",
4717
- type: "string",
4718
- description: "Match a @db.rel.FK on the target interface by alias."
4719
- },
4720
- validate(token, args, doc) {
4721
- const errors = [];
4722
- const field = token.parentNode;
4723
- const alias = args[0]?.text;
4724
- const owner = getDbTableOwner(token);
4725
- if (!owner || owner.countAnnotations("db.table") === 0) errors.push({
4726
- message: "@db.rel.from is only valid on fields of a @db.table interface",
4727
- severity: 1,
4728
- range: token.range
4729
- });
4730
- if (field.countAnnotations("db.rel.FK") > 0) errors.push({
4731
- message: "A field cannot be both a foreign key and a navigational property",
4732
- severity: 1,
4733
- range: token.range
4734
- });
4735
- const targetTypeName = getNavTargetTypeName(field);
4736
- if (!targetTypeName) return errors;
4737
- const unwound = doc.unwindType(targetTypeName);
4738
- if (!unwound) return errors;
4739
- const targetDef = unwound.def;
4740
- const targetDoc = unwound.doc;
4741
- if (!isInterface(targetDef) || targetDef.countAnnotations("db.table") === 0) {
4742
- errors.push({
4743
- message: `@db.rel.from target '${targetTypeName}' is not a @db.table entity`,
4744
- severity: 1,
4745
- range: token.range
4746
- });
4747
- return errors;
4748
- }
4749
- const struct = getParentStruct(token);
4750
- if (struct) {
4751
- const fieldName = field.id;
4752
- for (const [name, prop] of struct.props) {
4753
- if (name === fieldName) continue;
4754
- if (prop.countAnnotations("db.rel.from") === 0) continue;
4755
- const propAlias = getAnnotationAlias(prop, "db.rel.from");
4756
- if ((alias || undefined) === (propAlias || undefined)) {
4757
- const otherTarget = getNavTargetTypeName(prop);
4758
- if (otherTarget === targetTypeName) {
4759
- errors.push({
4760
- message: `Duplicate @db.rel.from '${alias || targetTypeName}' — only one inverse navigational property per alias`,
4761
- severity: 1,
4762
- range: token.range
4763
- });
4764
- break;
4765
- }
4766
- }
4767
- }
4768
- }
4769
- const thisTypeName = getParentTypeName(token);
4770
- if (!thisTypeName) return errors;
4771
- const matches = findFKFieldsPointingTo(targetDoc, targetDef, thisTypeName, alias);
4772
- if (alias) {
4773
- if (matches.length === 0) errors.push({
4774
- message: `No @db.rel.FK '${alias}' found on '${targetTypeName}'`,
4775
- severity: 1,
4776
- range: token.range
4777
- });
4778
- } else if (matches.length === 0) errors.push({
4779
- message: `No @db.rel.FK on '${targetTypeName}' points to '${thisTypeName}'`,
4780
- severity: 1,
4781
- range: token.range
4782
- });
4783
- else if (matches.length > 1) errors.push({
4784
- message: `'${targetTypeName}' has multiple @db.rel.FK fields pointing to '${thisTypeName}' — add alias`,
4785
- severity: 1,
4786
- range: token.range
4787
- });
4788
- const fieldDef = field.getDefinition();
4789
- if (!isArray(fieldDef) && matches.length === 1) {
4790
- const fkProp = matches[0].prop;
4791
- if (fkProp.countAnnotations("db.index.unique") === 0) errors.push({
4792
- message: `@db.rel.from '${field.id}' has singular type '${targetTypeName}' (1:1) but the FK on '${targetTypeName}' is not @db.index.unique — did you mean '${targetTypeName}[]' (1:N)?`,
4793
- severity: 2,
4794
- range: token.range
4795
- });
4796
- }
4797
- return errors;
4798
- }
4799
- }),
4800
- onDelete: refActionAnnotation("onDelete"),
4801
- onUpdate: refActionAnnotation("onUpdate"),
4802
- via: new AnnotationSpec({
4803
- description: "Declares a many-to-many navigational property through an explicit junction table. `@db.rel.via` is self-sufficient — no `@db.rel.from` pairing is needed.\n\n**Example:**\n```atscript\n@db.rel.via PostTag\ntags: Tag[]\n```\n",
4804
- nodeType: ["prop"],
4805
- argument: {
4806
- name: "junction",
4807
- type: "ref",
4808
- description: "The junction table type (must have @db.table and @db.rel.FK fields pointing to both sides)."
4809
- },
4810
- validate(token, args, doc) {
4811
- const errors = [];
4812
- const field = token.parentNode;
4813
- if (field.countAnnotations("db.rel.to") > 0 || field.countAnnotations("db.rel.from") > 0) errors.push({
4814
- message: "@db.rel.via is self-sufficient — cannot be combined with @db.rel.to or @db.rel.from",
4815
- severity: 1,
4816
- range: token.range
4817
- });
4818
- const definition$1 = field.getDefinition();
4819
- if (!isArray(definition$1)) errors.push({
4820
- message: "@db.rel.via requires an array type (e.g. Tag[])",
4821
- severity: 1,
4822
- range: token.range
4823
- });
4824
- if (!args[0]) return errors;
4825
- const junctionName = args[0].text;
4826
- errors.push(...validateRefArgument(args[0], doc, { requireDbTable: true }));
4827
- if (errors.length > 0) return errors;
4828
- const junctionUnwound = doc.unwindType(junctionName);
4829
- if (!junctionUnwound) return errors;
4830
- const junctionDef = junctionUnwound.def;
4831
- if (!isInterface(junctionDef)) return errors;
4832
- const thisTypeName = getParentTypeName(token);
4833
- const targetTypeName = getNavTargetTypeName(field);
4834
- if (!thisTypeName || !targetTypeName) return errors;
4835
- const fksToThis = findFKFieldsPointingTo(junctionUnwound.doc, junctionDef, thisTypeName);
4836
- if (fksToThis.length === 0) errors.push({
4837
- message: `Junction '${junctionName}' has no @db.rel.FK pointing to '${thisTypeName}'`,
4838
- severity: 1,
4839
- range: args[0].range
4840
- });
4841
- else if (fksToThis.length > 1) errors.push({
4842
- message: `Junction '${junctionName}' has multiple @db.rel.FK pointing to '${thisTypeName}' — not supported`,
4843
- severity: 1,
4844
- range: args[0].range
4845
- });
4846
- if (targetTypeName !== thisTypeName) {
4847
- const fksToTarget = findFKFieldsPointingTo(junctionUnwound.doc, junctionDef, targetTypeName);
4848
- if (fksToTarget.length === 0) errors.push({
4849
- message: `Junction '${junctionName}' has no @db.rel.FK pointing to '${targetTypeName}'`,
4850
- severity: 1,
4851
- range: args[0].range
4852
- });
4853
- else if (fksToTarget.length > 1) errors.push({
4854
- message: `Junction '${junctionName}' has multiple @db.rel.FK pointing to '${targetTypeName}' — not supported`,
4855
- severity: 1,
4856
- range: args[0].range
4857
- });
4858
- }
4859
- return errors;
4860
- }
4861
- }),
4862
- filter: new AnnotationSpec({
4863
- description: "Applies a filter to a navigational property, restricting which related records are loaded.\n\n**Example:**\n```atscript\n@db.rel.from\n@db.rel.filter `Post.published = true`\npublishedPosts: Post[]\n```\n",
4864
- nodeType: ["prop"],
4865
- argument: {
4866
- name: "condition",
4867
- type: "query",
4868
- description: "Filter expression restricting which related records are loaded."
4869
- },
4870
- validate(token, args, doc) {
4871
- const errors = [];
4872
- const field = token.parentNode;
4873
- const hasTo = field.countAnnotations("db.rel.to") > 0;
4874
- const hasFrom = field.countAnnotations("db.rel.from") > 0;
4875
- const hasVia = field.countAnnotations("db.rel.via") > 0;
4876
- if (!hasTo && !hasFrom && !hasVia) {
4877
- errors.push({
4878
- message: "@db.rel.filter is only valid on navigational fields (@db.rel.to, @db.rel.from, or @db.rel.via)",
4879
- severity: 1,
4880
- range: token.range
4881
- });
4882
- return errors;
4883
- }
4884
- if (!args[0]?.queryNode) return errors;
4885
- const targetTypeName = getNavTargetTypeName(field);
4886
- if (!targetTypeName) return errors;
4887
- const allowedTypes = [targetTypeName];
4888
- if (hasVia) {
4889
- const viaAnnotations = field.annotations?.filter((a) => a.name === "db.rel.via");
4890
- if (viaAnnotations?.[0]?.args[0]) allowedTypes.push(viaAnnotations[0].args[0].text);
4891
- }
4892
- errors.push(...validateQueryScope(args[0], allowedTypes, targetTypeName, doc));
4893
- return errors;
4894
- }
4895
- })
4896
- },
4897
- view: {
4898
- $self: new AnnotationSpec({
4899
- description: "Marks an interface as a **database view**. Optionally takes a view name argument.\n\n**Example:**\n```atscript\n@db.view \"active_premium_users\"\n@db.view.for User\nexport interface ActivePremiumUser { ... }\n```\n",
4900
- nodeType: ["interface"],
4901
- argument: {
4902
- optional: true,
4903
- name: "name",
4904
- type: "string",
4905
- description: "The view name in the database. If omitted, derived from the interface name."
4906
- },
4907
- validate(token, _args, _doc) {
4908
- const errors = [];
4909
- const owner = token.parentNode;
4910
- if (owner.countAnnotations("db.table") > 0) errors.push({
4911
- message: "An interface cannot be both a @db.table and a @db.view",
4912
- severity: 1,
4913
- range: token.range
4914
- });
4915
- return errors;
4916
- }
4917
- }),
4918
- for: new AnnotationSpec({
4919
- description: "Specifies the entry/primary table for a computed view. Required for views that map fields via chain refs.\n\n**Example:**\n```atscript\n@db.view.for Order\n@db.view.filter `Order.status = 'active'`\nexport interface ActiveOrderDetails { ... }\n```\n",
4920
- nodeType: ["interface"],
4921
- argument: {
4922
- name: "entry",
4923
- type: "ref",
4924
- description: "The primary/entry table type (must have @db.table)."
4925
- },
4926
- validate(token, args, doc) {
4927
- const errors = [];
4928
- const owner = token.parentNode;
4929
- if (owner.countAnnotations("db.table") > 0) errors.push({
4930
- message: "An interface cannot be both a @db.table and a @db.view",
4931
- severity: 1,
4932
- range: token.range
4933
- });
4934
- if (args[0]) errors.push(...validateRefArgument(args[0], doc, { requireDbTable: true }));
4935
- return errors;
4936
- }
4937
- }),
4938
- joins: new AnnotationSpec({
4939
- description: "Declares an explicit join for a view. Use when no `@db.rel.*` path exists between the entry table and the target.\n\n**Example:**\n```atscript\n@db.view.for Order\n@db.view.joins Warehouse, `Warehouse.regionId = Order.regionId`\nexport interface OrderWarehouse { ... }\n```\n",
4940
- nodeType: ["interface"],
4941
- multiple: true,
4942
- mergeStrategy: "append",
4943
- argument: [{
4944
- name: "target",
4945
- type: "ref",
4946
- description: "The table type to join (must have @db.table)."
4947
- }, {
4948
- name: "condition",
4949
- type: "query",
4950
- description: "Join condition expression."
4951
- }],
4952
- validate(token, args, doc) {
4953
- const errors = [];
4954
- const owner = token.parentNode;
4955
- if (!hasAnyViewAnnotation(owner) && !args[0]) {
4956
- errors.push({
4957
- message: "@db.view.joins is only valid on @db.view interfaces",
4958
- severity: 1,
4959
- range: token.range
4960
- });
4961
- return errors;
4962
- }
4963
- if (args[0]) errors.push(...validateRefArgument(args[0], doc, { requireDbTable: true }));
4964
- const forAnnotations = owner.annotations?.filter((a) => a.name === "db.view.for");
4965
- const entryTypeName = forAnnotations?.[0]?.args[0]?.text;
4966
- if (!entryTypeName) {
4967
- errors.push({
4968
- message: "@db.view.joins requires @db.view.for to identify the entry table",
4969
- severity: 1,
4970
- range: token.range
4971
- });
4972
- return errors;
4973
- }
4974
- if (args[1]?.queryNode && args[0]) {
4975
- const joinTargetName = args[0].text;
4976
- errors.push(...validateQueryScope(args[1], [joinTargetName, entryTypeName], entryTypeName, doc));
4977
- }
4978
- return errors;
4979
- }
4980
- }),
4981
- filter: new AnnotationSpec({
4982
- description: "WHERE clause for a view, filtering which rows are included.\n\n**Example:**\n```atscript\n@db.view.for User\n@db.view.filter `User.status = 'active' and User.age >= 18`\nexport interface ActiveUser { ... }\n```\n",
4983
- nodeType: ["interface"],
4984
- argument: {
4985
- name: "condition",
4986
- type: "query",
4987
- description: "Filter expression for the view WHERE clause."
4988
- },
4989
- validate(token, args, doc) {
4990
- const errors = [];
4991
- const owner = token.parentNode;
4992
- if (!hasAnyViewAnnotation(owner) && !args[0]) {
4993
- errors.push({
4994
- message: "@db.view.filter is only valid on @db.view interfaces",
4995
- severity: 1,
4996
- range: token.range
4997
- });
4998
- return errors;
4999
- }
5000
- if (!args[0]?.queryNode) return errors;
5001
- const forAnnotations = owner.annotations?.filter((a) => a.name === "db.view.for");
5002
- const entryTypeName = forAnnotations?.[0]?.args[0]?.text;
5003
- if (!entryTypeName) {
5004
- errors.push({
5005
- message: "@db.view.filter requires @db.view.for to identify the entry table",
5006
- severity: 1,
5007
- range: token.range
5008
- });
5009
- return errors;
5010
- }
5011
- const allowedTypes = [entryTypeName];
5012
- const joinsAnnotations = owner.annotations?.filter((a) => a.name === "db.view.joins");
5013
- if (joinsAnnotations) {
5014
- for (const join of joinsAnnotations) if (join.args[0]) allowedTypes.push(join.args[0].text);
5015
- }
5016
- errors.push(...validateQueryScope(args[0], allowedTypes, entryTypeName, doc));
5017
- return errors;
5018
- }
5019
- }),
5020
- materialized: new AnnotationSpec({
5021
- description: "Marks a view as materialized (precomputed, stored on disk). Supported by PostgreSQL, CockroachDB, Oracle, SQL Server (indexed views), Snowflake. MongoDB supports on-demand materialized views via $merge/$out. Not applicable to MySQL or SQLite.\n\n**Example:**\n```atscript\n@db.view.materialized\n@db.view.for User\n@db.view.filter `User.status = 'active'`\nexport interface ActiveUsers { ... }\n```\n",
5022
- nodeType: ["interface"],
5023
- validate(token, _args, _doc) {
5024
- const errors = [];
5025
- const owner = token.parentNode;
5026
- if (!hasAnyViewAnnotation(owner)) errors.push({
5027
- message: "@db.view.materialized is only valid on @db.view interfaces",
5028
- severity: 1,
5029
- range: token.range
5030
- });
5031
- return errors;
5032
- }
5033
- }),
5034
- renamed: new AnnotationSpec({
5035
- description: "Specifies the previous view name for view rename migration. The sync engine drops the old view and creates the new one.\n\n**Example:**\n```atscript\n@db.view \"active_premium_users\"\n@db.view.renamed \"active_users\"\n@db.view.for User\nexport interface ActivePremiumUser { ... }\n```\n",
5036
- nodeType: ["interface"],
5037
- argument: {
5038
- name: "oldName",
5039
- type: "string",
5040
- description: "The previous view name."
5041
- },
5042
- validate(token, _args, _doc) {
5043
- const errors = [];
5044
- const owner = token.parentNode;
5045
- if (!hasAnyViewAnnotation(owner)) errors.push({
5046
- message: "@db.view.renamed requires @db.view on the same interface",
5047
- severity: 1,
5048
- range: token.range
5049
- });
5050
- return errors;
5051
- }
5052
- })
5053
- }
5054
- };
5055
-
5056
4048
  //#endregion
5057
4049
  //#region packages/core/src/defaults/emit-annotations.ts
5058
4050
  const emitAnnotations = { jsonSchema: new AnnotationSpec({
@@ -5370,6 +4362,8 @@ const metaAnnotations = {
5370
4362
 
5371
4363
  //#endregion
5372
4364
  //#region packages/core/src/defaults/primitives.ts
4365
+ 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)$";
4366
+ 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
4367
  const positive = {
5374
4368
  documentation: "Number that greater than or equal to zero.",
5375
4369
  annotations: { "expect.min": 0 }
@@ -5441,6 +4435,43 @@ const primitives = {
5441
4435
  message: "Invalid UUID format."
5442
4436
  } }
5443
4437
  },
4438
+ url: {
4439
+ documentation: "Represents a URL.",
4440
+ annotations: { "expect.pattern": {
4441
+ pattern: "^https?:\\/\\/[^\\s]+$",
4442
+ message: "Invalid URL format."
4443
+ } }
4444
+ },
4445
+ ipv4: {
4446
+ documentation: "Represents an IPv4 address.",
4447
+ annotations: { "expect.pattern": {
4448
+ pattern: IPV4_PATTERN,
4449
+ message: "Invalid IPv4 address."
4450
+ } }
4451
+ },
4452
+ ipv6: {
4453
+ documentation: "Represents an IPv6 address.",
4454
+ annotations: { "expect.pattern": {
4455
+ pattern: IPV6_PATTERN,
4456
+ flags: "i",
4457
+ message: "Invalid IPv6 address."
4458
+ } }
4459
+ },
4460
+ ip: {
4461
+ documentation: "Represents an IP address (IPv4 or IPv6).",
4462
+ annotations: { "expect.pattern": {
4463
+ pattern: `(?:${IPV4_PATTERN.slice(1, -1)})|(?:${IPV6_PATTERN.slice(1, -1)})`,
4464
+ flags: "i",
4465
+ message: "Invalid IP address."
4466
+ } }
4467
+ },
4468
+ char: {
4469
+ documentation: "Represents a single character.",
4470
+ annotations: {
4471
+ "expect.minLength": 1,
4472
+ "expect.maxLength": 1
4473
+ }
4474
+ },
5444
4475
  required: {
5445
4476
  documentation: "Non-empty string that contains at least one non-whitespace character.",
5446
4477
  annotations: { "meta.required": true }
@@ -5461,18 +4492,92 @@ const primitives = {
5461
4492
  documentation: "Represents a double-precision floating-point number."
5462
4493
  },
5463
4494
  int: {
5464
- extensions: positiveOrNegative,
5465
4495
  documentation: "Represents an integer number.",
5466
- annotations: { "expect.int": true }
4496
+ annotations: { "expect.int": true },
4497
+ extensions: {
4498
+ ...positiveOrNegative,
4499
+ int8: {
4500
+ tags: ["int8"],
4501
+ documentation: "Signed 8-bit integer (-128 to 127).",
4502
+ annotations: {
4503
+ "expect.min": -128,
4504
+ "expect.max": 127
4505
+ }
4506
+ },
4507
+ int16: {
4508
+ tags: ["int16"],
4509
+ documentation: "Signed 16-bit integer (-32768 to 32767).",
4510
+ annotations: {
4511
+ "expect.min": -32768,
4512
+ "expect.max": 32767
4513
+ }
4514
+ },
4515
+ int32: {
4516
+ tags: ["int32"],
4517
+ documentation: "Signed 32-bit integer.",
4518
+ annotations: {
4519
+ "expect.min": -2147483648,
4520
+ "expect.max": 2147483647
4521
+ }
4522
+ },
4523
+ int64: {
4524
+ tags: ["int64"],
4525
+ documentation: "Signed 64-bit integer (clamped to JS safe integer range).",
4526
+ annotations: {
4527
+ "expect.min": Number.MIN_SAFE_INTEGER,
4528
+ "expect.max": Number.MAX_SAFE_INTEGER
4529
+ }
4530
+ },
4531
+ uint8: {
4532
+ tags: ["uint8"],
4533
+ documentation: "Unsigned 8-bit integer (0 to 255).",
4534
+ annotations: {
4535
+ "expect.min": 0,
4536
+ "expect.max": 255
4537
+ },
4538
+ extensions: { byte: {
4539
+ tags: ["byte"],
4540
+ documentation: "Byte value (alias for uint8)."
4541
+ } }
4542
+ },
4543
+ uint16: {
4544
+ tags: ["uint16"],
4545
+ documentation: "Unsigned 16-bit integer (0 to 65535).",
4546
+ annotations: {
4547
+ "expect.min": 0,
4548
+ "expect.max": 65535
4549
+ },
4550
+ extensions: { port: {
4551
+ tags: ["port"],
4552
+ documentation: "Network port number (0 to 65535)."
4553
+ } }
4554
+ },
4555
+ uint32: {
4556
+ tags: ["uint32"],
4557
+ documentation: "Unsigned 32-bit integer (0 to 4294967295).",
4558
+ annotations: {
4559
+ "expect.min": 0,
4560
+ "expect.max": 4294967295
4561
+ }
4562
+ },
4563
+ uint64: {
4564
+ tags: ["uint64"],
4565
+ documentation: "Unsigned 64-bit integer (clamped to JS safe integer range).",
4566
+ annotations: {
4567
+ "expect.min": 0,
4568
+ "expect.max": Number.MAX_SAFE_INTEGER
4569
+ }
4570
+ }
4571
+ }
5467
4572
  },
5468
4573
  timestamp: {
5469
4574
  documentation: "Represents a timestamp.",
5470
4575
  annotations: { "expect.int": true },
5471
4576
  extensions: {
5472
4577
  created: {
5473
- documentation: "Timestamp auto-set on creation. Auto-applies @db.default.fn \"now\".",
4578
+ documentation: "Timestamp auto-set on creation. Auto-applies @db.default.now.",
5474
4579
  tags: ["created"],
5475
- annotations: { "db.default.fn": "now" }
4580
+ annotations: { "db.default.now": true }
5476
4581
  },
5477
4582
  updated: {
5478
4583
  documentation: "Timestamp auto-updated on every write. DB adapters read the \"updated\" tag.",
@@ -5482,6 +4587,10 @@ const primitives = {
5482
4587
  }
5483
4588
  }
5484
4589
  },
4590
+ decimal: {
4591
+ type: "decimal",
4592
+ documentation: "Decimal number stored as string to preserve precision. Use with @db.column.precision."
4593
+ },
5485
4594
  boolean: {
5486
4595
  type: "boolean",
5487
4596
  documentation: "Represents true/false values.",
@@ -5663,7 +4772,6 @@ function getDefaultAtscriptConfig() {
5663
4772
  meta: { ...metaAnnotations },
5664
4773
  expect: { ...expectAnnotations },
5665
4774
  emit: { ...emitAnnotations },
5666
- db: { ...dbAnnotations },
5667
4775
  ui: { ...uiAnnotations }
5668
4776
  }
5669
4777
  };
@@ -6370,7 +5478,6 @@ exports.analyzeQueryCursorContext = analyzeQueryCursorContext
6370
5478
  exports.build = build
6371
5479
  exports.createAtscriptPlugin = createAtscriptPlugin
6372
5480
  exports.defineConfig = defineConfig
6373
- exports.findFKFieldsPointingTo = findFKFieldsPointingTo
6374
5481
  exports.flattenInterfaceNode = flattenInterfaceNode
6375
5482
  exports.getFieldsForType = getFieldsForType
6376
5483
  exports.getQueryCompletionScope = getQueryCompletionScope
@@ -6399,5 +5506,4 @@ exports.loadTsConfig = loadTsConfig
6399
5506
  exports.resolveAnnotation = resolveAnnotation
6400
5507
  exports.resolveAtscriptFromPath = resolveAtscriptFromPath
6401
5508
  exports.resolveConfigFile = resolveConfigFile
6402
- exports.resolveQueryFieldRef = resolveQueryFieldRef
6403
- exports.validateRefArgument = validateRefArgument
5509
+ exports.resolveQueryFieldRef = resolveQueryFieldRef