@atscript/core 0.1.37 → 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,1039 +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
- * 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
- /**
4218
- * Extract target type name from a navigational field definition.
4219
- * Unwraps arrays (e.g., `Post[]` → `Post`).
4220
- */ function getNavTargetTypeName(field) {
4221
- let def = field.getDefinition();
4222
- if (isArray(def)) def = def?.getDefinition();
4223
- if (isRef(def)) return def.id;
4224
- return undefined;
4225
- }
4226
- /**
4227
- * Get the alias argument from an annotation on a field.
4228
- */ function getAnnotationAlias(prop, annotationName) {
4229
- const annotations$1 = prop.annotations?.filter((a) => a.name === annotationName);
4230
- if (!annotations$1 || annotations$1.length === 0) return undefined;
4231
- return annotations$1[0].args.length > 0 ? annotations$1[0].args[0].text : undefined;
4232
- }
4233
- /**
4234
- * Factory for @db.rel.onDelete / @db.rel.onUpdate — identical validation logic,
4235
- * only the annotation name and description verb differ.
4236
- */ function refActionAnnotation(name) {
4237
- return new AnnotationSpec({
4238
- 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",
4239
- nodeType: ["prop"],
4240
- argument: {
4241
- name: "action",
4242
- type: "string",
4243
- values: [
4244
- "cascade",
4245
- "restrict",
4246
- "noAction",
4247
- "setNull",
4248
- "setDefault"
4249
- ],
4250
- description: "Referential action: \"cascade\", \"restrict\", \"noAction\", \"setNull\", or \"setDefault\"."
4251
- },
4252
- validate(token, args, doc) {
4253
- const errors = [];
4254
- const field = token.parentNode;
4255
- if (field.countAnnotations("db.rel.FK") === 0) errors.push({
4256
- message: `@db.rel.${name} is only valid on @db.rel.FK fields`,
4257
- severity: 1,
4258
- range: token.range
4259
- });
4260
- if (args[0]) {
4261
- const action = args[0].text;
4262
- if (action === "setNull" && !field.has("optional")) errors.push({
4263
- message: `@db.rel.${name} "setNull" requires the FK field to be optional (?)`,
4264
- severity: 1,
4265
- range: token.range
4266
- });
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({
4268
- message: `@db.rel.${name} "setDefault" but no @db.default.* annotation — field will have no fallback value`,
4269
- severity: 2,
4270
- range: token.range
4271
- });
4272
- }
4273
- const fkAlias = getAnnotationAlias(field, "db.rel.FK");
4274
- if (fkAlias) {
4275
- const struct = getParentStruct(token);
4276
- if (struct) {
4277
- const annotationName = `db.rel.${name}`;
4278
- let count = 0;
4279
- for (const [, prop] of struct.props) {
4280
- if (prop.countAnnotations("db.rel.FK") === 0) continue;
4281
- if (prop.countAnnotations(annotationName) === 0) continue;
4282
- const propFkAlias = getAnnotationAlias(prop, "db.rel.FK");
4283
- if (propFkAlias === fkAlias) count++;
4284
- }
4285
- if (count > 1) errors.push({
4286
- message: `Composite FK '${fkAlias}' has @db.rel.${name} on multiple fields — declare it on exactly one`,
4287
- severity: 1,
4288
- range: token.range
4289
- });
4290
- }
4291
- }
4292
- return errors;
4293
- }
4294
- });
4295
- }
4296
- const dbAnnotations = {
4297
- patch: { strategy: new AnnotationSpec({
4298
- 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",
4299
- nodeType: ["prop"],
4300
- multiple: false,
4301
- argument: {
4302
- name: "strategy",
4303
- type: "string",
4304
- description: "The **patch strategy** for this field: `\"replace\"` (default) or `\"merge\"`.",
4305
- values: ["replace", "merge"]
4306
- },
4307
- validate(token, args, doc) {
4308
- const field = token.parentNode;
4309
- const errors = [];
4310
- const definition$1 = field.getDefinition();
4311
- if (!definition$1) return errors;
4312
- let wrongType = false;
4313
- if (isRef(definition$1)) {
4314
- const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
4315
- if (!isStructure(def) && !isInterface(def) && !isArray(def)) wrongType = true;
4316
- } else if (!isStructure(definition$1) && !isInterface(definition$1) && !isArray(definition$1)) wrongType = true;
4317
- if (wrongType) errors.push({
4318
- message: `@db.patch.strategy requires a field of type object or array`,
4319
- severity: 1,
4320
- range: token.range
4321
- });
4322
- return errors;
4323
- }
4324
- }) },
4325
- table: {
4326
- $self: new AnnotationSpec({
4327
- 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",
4328
- nodeType: ["interface"],
4329
- argument: {
4330
- optional: true,
4331
- name: "name",
4332
- type: "string",
4333
- description: "Table/collection name. If omitted, derived from interface name."
4334
- },
4335
- validate(token, _args, _doc) {
4336
- const errors = [];
4337
- const owner = token.parentNode;
4338
- if (hasAnyViewAnnotation(owner)) errors.push({
4339
- message: "An interface cannot be both a @db.table and a @db.view",
4340
- severity: 1,
4341
- range: token.range
4342
- });
4343
- return errors;
4344
- }
4345
- }),
4346
- renamed: new AnnotationSpec({
4347
- 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",
4348
- nodeType: ["interface"],
4349
- argument: {
4350
- name: "oldName",
4351
- type: "string",
4352
- description: "The previous table/collection name."
4353
- },
4354
- validate(token, _args, _doc) {
4355
- const errors = [];
4356
- const owner = token.parentNode;
4357
- if (owner.countAnnotations("db.table") === 0) errors.push({
4358
- message: "@db.table.renamed requires @db.table on the same interface",
4359
- severity: 1,
4360
- range: token.range
4361
- });
4362
- return errors;
4363
- }
4364
- })
4365
- },
4366
- schema: new AnnotationSpec({
4367
- 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",
4368
- nodeType: ["interface"],
4369
- argument: {
4370
- name: "name",
4371
- type: "string",
4372
- description: "Schema/namespace name."
4373
- }
4374
- }),
4375
- index: {
4376
- plain: new AnnotationSpec({
4377
- 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",
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
- optional: true,
4388
- name: "sort",
4389
- type: "string",
4390
- values: ["asc", "desc"],
4391
- description: "Sort direction. Defaults to \"asc\"."
4392
- }]
4393
- }),
4394
- unique: new AnnotationSpec({
4395
- 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",
4396
- nodeType: ["prop"],
4397
- multiple: true,
4398
- mergeStrategy: "append",
4399
- argument: {
4400
- optional: true,
4401
- name: "name",
4402
- type: "string",
4403
- description: "Index name / composite group name."
4404
- }
4405
- }),
4406
- fulltext: new AnnotationSpec({
4407
- 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",
4408
- nodeType: ["prop"],
4409
- multiple: true,
4410
- mergeStrategy: "append",
4411
- argument: [{
4412
- optional: true,
4413
- name: "name",
4414
- type: "string",
4415
- description: "Index name / composite group name."
4416
- }, {
4417
- optional: true,
4418
- name: "weight",
4419
- type: "number",
4420
- description: "Field importance in search results (higher = more relevant). Defaults to `1`. Supported by databases with weighted fulltext (e.g., MongoDB, PostgreSQL)."
4421
- }]
4422
- })
4423
- },
4424
- column: {
4425
- $self: new AnnotationSpec({
4426
- 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",
4427
- nodeType: ["prop"],
4428
- argument: {
4429
- name: "name",
4430
- type: "string",
4431
- description: "The column/field name (without parent prefix for nested fields)."
4432
- }
4433
- }),
4434
- renamed: new AnnotationSpec({
4435
- 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",
4436
- nodeType: ["prop"],
4437
- argument: {
4438
- name: "oldName",
4439
- type: "string",
4440
- description: "The old local field name (parent prefix is reconstructed automatically)."
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
- }
4475
- })
4476
- },
4477
- default: {
4478
- $self: new AnnotationSpec({
4479
- 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",
4480
- nodeType: ["prop"],
4481
- argument: {
4482
- name: "value",
4483
- type: "string",
4484
- description: "Static default value. Strings used as-is; other types parsed via JSON.parse()."
4485
- }
4486
- }),
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",
4489
- nodeType: ["prop"],
4490
- argument: {
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."
4495
- },
4496
- validate(token, args, doc) {
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"]);
4512
- }
4513
- })
4514
- },
4515
- json: new AnnotationSpec({
4516
- 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",
4517
- nodeType: ["prop"],
4518
- validate(token, _args, doc) {
4519
- const errors = [];
4520
- const field = token.parentNode;
4521
- const definition$1 = field.getDefinition();
4522
- if (definition$1 && isRef(definition$1)) {
4523
- const unwound = doc.unwindType(definition$1.id, definition$1.chain);
4524
- if (unwound && isPrimitive(unwound.def)) errors.push({
4525
- message: "@db.json on a primitive field has no effect — primitive fields are already stored as scalar columns",
4526
- severity: 2,
4527
- range: token.range
4528
- });
4529
- }
4530
- return errors;
4531
- }
4532
- }),
4533
- ignore: new AnnotationSpec({
4534
- 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",
4535
- nodeType: ["prop"],
4536
- validate(token, args, doc) {
4537
- const errors = [];
4538
- const field = token.parentNode;
4539
- if (field.countAnnotations("meta.id") > 0) errors.push({
4540
- message: `@db.ignore cannot coexist with @meta.id — a field cannot be both a primary key and excluded from the database`,
4541
- severity: 1,
4542
- range: token.range
4543
- });
4544
- return errors;
4545
- }
4546
- }),
4547
- sync: { method: new AnnotationSpec({
4548
- 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",
4549
- nodeType: ["interface"],
4550
- argument: {
4551
- name: "method",
4552
- type: "string",
4553
- description: "Sync method: \"drop\" (lossy) or \"recreate\" (lossless with data copy).",
4554
- values: ["drop", "recreate"]
4555
- }
4556
- }) },
4557
- rel: {
4558
- FK: new AnnotationSpec({
4559
- 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",
4560
- nodeType: ["prop"],
4561
- argument: {
4562
- optional: true,
4563
- name: "alias",
4564
- type: "string",
4565
- description: "Alias for pairing with @db.rel.to. Required when multiple FKs point to the same target type."
4566
- },
4567
- validate(token, args, doc) {
4568
- const errors = [];
4569
- const field = token.parentNode;
4570
- const alias = args[0]?.text;
4571
- const owner = getDbTableOwner(token);
4572
- if (!owner || owner.countAnnotations("db.table") === 0) errors.push({
4573
- message: "@db.rel.FK is only valid on fields of a @db.table interface",
4574
- severity: 1,
4575
- range: token.range
4576
- });
4577
- if (field.countAnnotations("db.rel.to") > 0 || field.countAnnotations("db.rel.from") > 0) errors.push({
4578
- message: "A field cannot be both a foreign key and a navigational property",
4579
- severity: 1,
4580
- range: token.range
4581
- });
4582
- const definition$1 = field.getDefinition();
4583
- if (!definition$1 || !isRef(definition$1) || !definition$1.hasChain) {
4584
- errors.push({
4585
- message: `@db.rel.FK requires a chain reference type (e.g. User.id), got scalar type`,
4586
- severity: 1,
4587
- range: token.range
4588
- });
4589
- return errors;
4590
- }
4591
- const ref$1 = definition$1;
4592
- const refTypeName = ref$1.id;
4593
- const chainFields = ref$1.chain.map((c) => c.text);
4594
- const targetUnwound = doc.unwindType(refTypeName);
4595
- if (targetUnwound) {
4596
- const targetDef = targetUnwound.def;
4597
- if (isInterface(targetDef) || isStructure(targetDef)) {
4598
- const struct = isInterface(targetDef) ? targetDef.getDefinition() : targetDef;
4599
- if (struct && isStructure(struct) && chainFields.length > 0) {
4600
- const targetProp = struct.props.get(chainFields[0]);
4601
- if (targetProp) {
4602
- if (targetProp.countAnnotations("meta.id") === 0 && targetProp.countAnnotations("db.index.unique") === 0) errors.push({
4603
- message: `@db.rel.FK target '${refTypeName}.${chainFields.join(".")}' is not a primary key (@meta.id) or unique (@db.index.unique) field`,
4604
- severity: 1,
4605
- range: token.range
4606
- });
4607
- const propDef = targetProp.getDefinition();
4608
- if (propDef && isRef(propDef)) {
4609
- const propUnwound = targetUnwound.doc.unwindType(propDef.id, propDef.chain);
4610
- if (propUnwound && !isPrimitive(propUnwound.def)) errors.push({
4611
- message: `Foreign key field must resolve to a scalar type (number, string, etc.), got '${propDef.id}'`,
4612
- severity: 1,
4613
- range: token.range
4614
- });
4615
- } else if (propDef && !isPrimitive(propDef)) errors.push({
4616
- message: `Foreign key field must resolve to a scalar type (number, string, etc.)`,
4617
- severity: 1,
4618
- range: token.range
4619
- });
4620
- }
4621
- }
4622
- }
4623
- }
4624
- if (!alias) {
4625
- const struct = getParentStruct(token);
4626
- if (struct) {
4627
- let sameTargetCount = 0;
4628
- for (const [, prop] of struct.props) {
4629
- if (prop.countAnnotations("db.rel.FK") === 0) continue;
4630
- const def = prop.getDefinition();
4631
- if (!def || !isRef(def)) continue;
4632
- const r = def;
4633
- if (!r.hasChain) continue;
4634
- if (r.id === refTypeName) {
4635
- const fkAnnotations = prop.annotations?.filter((a) => a.name === "db.rel.FK");
4636
- const hasAlias = fkAnnotations?.some((a) => a.args.length > 0);
4637
- if (!hasAlias) sameTargetCount++;
4638
- }
4639
- }
4640
- if (sameTargetCount > 1) errors.push({
4641
- message: `Multiple @db.rel.FK fields resolve to type '${refTypeName}' — add alias to disambiguate`,
4642
- severity: 1,
4643
- range: token.range
4644
- });
4645
- }
4646
- }
4647
- return errors;
4648
- }
4649
- }),
4650
- to: new AnnotationSpec({
4651
- 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",
4652
- nodeType: ["prop"],
4653
- argument: {
4654
- optional: true,
4655
- name: "alias",
4656
- type: "string",
4657
- description: "Match a local @db.rel.FK by alias."
4658
- },
4659
- validate(token, args, doc) {
4660
- const errors = [];
4661
- const field = token.parentNode;
4662
- const alias = args[0]?.text;
4663
- const owner = getDbTableOwner(token);
4664
- if (!owner || owner.countAnnotations("db.table") === 0) errors.push({
4665
- message: "@db.rel.to is only valid on fields of a @db.table interface",
4666
- severity: 1,
4667
- range: token.range
4668
- });
4669
- if (field.countAnnotations("db.rel.FK") > 0) errors.push({
4670
- message: "A field cannot be both a foreign key and a navigational property",
4671
- severity: 1,
4672
- range: token.range
4673
- });
4674
- const targetTypeName = getNavTargetTypeName(field);
4675
- if (!targetTypeName) return errors;
4676
- const unwound = doc.unwindType(targetTypeName);
4677
- if (unwound) {
4678
- const targetDef = unwound.def;
4679
- const targetNode = isInterface(targetDef) ? targetDef : undefined;
4680
- if (!targetNode || targetNode.countAnnotations("db.table") === 0) errors.push({
4681
- message: `@db.rel.to target '${targetTypeName}' is not a @db.table entity`,
4682
- severity: 1,
4683
- range: token.range
4684
- });
4685
- }
4686
- const fieldDef = field.getDefinition();
4687
- if (fieldDef && fieldDef.entity === "group" && fieldDef.op === "|") errors.push({
4688
- message: "@db.rel.to does not support union types — use separate relations",
4689
- severity: 1,
4690
- range: token.range
4691
- });
4692
- const struct = getParentStruct(token);
4693
- if (struct) {
4694
- const fieldName = field.id;
4695
- for (const [name, prop] of struct.props) {
4696
- if (name === fieldName) continue;
4697
- if (prop.countAnnotations("db.rel.to") === 0) continue;
4698
- const propAlias = getAnnotationAlias(prop, "db.rel.to");
4699
- if ((alias || undefined) === (propAlias || undefined)) {
4700
- const otherTarget = getNavTargetTypeName(prop);
4701
- if (otherTarget === targetTypeName) {
4702
- errors.push({
4703
- message: `Duplicate @db.rel.to '${alias || targetTypeName}' — only one forward navigational property per alias`,
4704
- severity: 1,
4705
- range: token.range
4706
- });
4707
- break;
4708
- }
4709
- }
4710
- }
4711
- if (alias) {
4712
- const matches = findFKFieldsPointingTo(doc, struct, targetTypeName, alias);
4713
- if (matches.length === 0) errors.push({
4714
- message: `No @db.rel.FK '${alias}' found on this interface`,
4715
- severity: 1,
4716
- range: token.range
4717
- });
4718
- } else {
4719
- const matches = findFKFieldsPointingTo(doc, struct, targetTypeName);
4720
- if (matches.length === 0) errors.push({
4721
- message: `No @db.rel.FK on this interface points to '${targetTypeName}' — did you mean @db.rel.from?`,
4722
- severity: 1,
4723
- range: token.range
4724
- });
4725
- else if (matches.length > 1) errors.push({
4726
- message: `Multiple @db.rel.FK fields point to '${targetTypeName}' — add alias to disambiguate`,
4727
- severity: 1,
4728
- range: token.range
4729
- });
4730
- }
4731
- }
4732
- return errors;
4733
- }
4734
- }),
4735
- from: new AnnotationSpec({
4736
- 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",
4737
- nodeType: ["prop"],
4738
- argument: {
4739
- optional: true,
4740
- name: "alias",
4741
- type: "string",
4742
- description: "Match a @db.rel.FK on the target interface by alias."
4743
- },
4744
- validate(token, args, doc) {
4745
- const errors = [];
4746
- const field = token.parentNode;
4747
- const alias = args[0]?.text;
4748
- const owner = getDbTableOwner(token);
4749
- if (!owner || owner.countAnnotations("db.table") === 0) errors.push({
4750
- message: "@db.rel.from is only valid on fields of a @db.table interface",
4751
- severity: 1,
4752
- range: token.range
4753
- });
4754
- if (field.countAnnotations("db.rel.FK") > 0) errors.push({
4755
- message: "A field cannot be both a foreign key and a navigational property",
4756
- severity: 1,
4757
- range: token.range
4758
- });
4759
- const targetTypeName = getNavTargetTypeName(field);
4760
- if (!targetTypeName) return errors;
4761
- const unwound = doc.unwindType(targetTypeName);
4762
- if (!unwound) return errors;
4763
- const targetDef = unwound.def;
4764
- const targetDoc = unwound.doc;
4765
- if (!isInterface(targetDef) || targetDef.countAnnotations("db.table") === 0) {
4766
- errors.push({
4767
- message: `@db.rel.from target '${targetTypeName}' is not a @db.table entity`,
4768
- severity: 1,
4769
- range: token.range
4770
- });
4771
- return errors;
4772
- }
4773
- const struct = getParentStruct(token);
4774
- if (struct) {
4775
- const fieldName = field.id;
4776
- for (const [name, prop] of struct.props) {
4777
- if (name === fieldName) continue;
4778
- if (prop.countAnnotations("db.rel.from") === 0) continue;
4779
- const propAlias = getAnnotationAlias(prop, "db.rel.from");
4780
- if ((alias || undefined) === (propAlias || undefined)) {
4781
- const otherTarget = getNavTargetTypeName(prop);
4782
- if (otherTarget === targetTypeName) {
4783
- errors.push({
4784
- message: `Duplicate @db.rel.from '${alias || targetTypeName}' — only one inverse navigational property per alias`,
4785
- severity: 1,
4786
- range: token.range
4787
- });
4788
- break;
4789
- }
4790
- }
4791
- }
4792
- }
4793
- const thisTypeName = getParentTypeName(token);
4794
- if (!thisTypeName) return errors;
4795
- const matches = findFKFieldsPointingTo(targetDoc, targetDef, thisTypeName, alias);
4796
- if (alias) {
4797
- if (matches.length === 0) errors.push({
4798
- message: `No @db.rel.FK '${alias}' found on '${targetTypeName}'`,
4799
- severity: 1,
4800
- range: token.range
4801
- });
4802
- } else if (matches.length === 0) errors.push({
4803
- message: `No @db.rel.FK on '${targetTypeName}' points to '${thisTypeName}'`,
4804
- severity: 1,
4805
- range: token.range
4806
- });
4807
- else if (matches.length > 1) errors.push({
4808
- message: `'${targetTypeName}' has multiple @db.rel.FK fields pointing to '${thisTypeName}' — add alias`,
4809
- severity: 1,
4810
- range: token.range
4811
- });
4812
- const fieldDef = field.getDefinition();
4813
- if (!isArray(fieldDef) && matches.length === 1) {
4814
- const fkProp = matches[0].prop;
4815
- if (fkProp.countAnnotations("db.index.unique") === 0) errors.push({
4816
- 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)?`,
4817
- severity: 2,
4818
- range: token.range
4819
- });
4820
- }
4821
- return errors;
4822
- }
4823
- }),
4824
- onDelete: refActionAnnotation("onDelete"),
4825
- onUpdate: refActionAnnotation("onUpdate"),
4826
- via: new AnnotationSpec({
4827
- 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",
4828
- nodeType: ["prop"],
4829
- argument: {
4830
- name: "junction",
4831
- type: "ref",
4832
- description: "The junction table type (must have @db.table and @db.rel.FK fields pointing to both sides)."
4833
- },
4834
- validate(token, args, doc) {
4835
- const errors = [];
4836
- const field = token.parentNode;
4837
- if (field.countAnnotations("db.rel.to") > 0 || field.countAnnotations("db.rel.from") > 0) errors.push({
4838
- message: "@db.rel.via is self-sufficient — cannot be combined with @db.rel.to or @db.rel.from",
4839
- severity: 1,
4840
- range: token.range
4841
- });
4842
- const definition$1 = field.getDefinition();
4843
- if (!isArray(definition$1)) errors.push({
4844
- message: "@db.rel.via requires an array type (e.g. Tag[])",
4845
- severity: 1,
4846
- range: token.range
4847
- });
4848
- if (!args[0]) return errors;
4849
- const junctionName = args[0].text;
4850
- errors.push(...validateRefArgument(args[0], doc, { requireDbTable: true }));
4851
- if (errors.length > 0) return errors;
4852
- const junctionUnwound = doc.unwindType(junctionName);
4853
- if (!junctionUnwound) return errors;
4854
- const junctionDef = junctionUnwound.def;
4855
- if (!isInterface(junctionDef)) return errors;
4856
- const thisTypeName = getParentTypeName(token);
4857
- const targetTypeName = getNavTargetTypeName(field);
4858
- if (!thisTypeName || !targetTypeName) return errors;
4859
- const fksToThis = findFKFieldsPointingTo(junctionUnwound.doc, junctionDef, thisTypeName);
4860
- if (fksToThis.length === 0) errors.push({
4861
- message: `Junction '${junctionName}' has no @db.rel.FK pointing to '${thisTypeName}'`,
4862
- severity: 1,
4863
- range: args[0].range
4864
- });
4865
- else if (fksToThis.length > 1) errors.push({
4866
- message: `Junction '${junctionName}' has multiple @db.rel.FK pointing to '${thisTypeName}' — not supported`,
4867
- severity: 1,
4868
- range: args[0].range
4869
- });
4870
- if (targetTypeName !== thisTypeName) {
4871
- const fksToTarget = findFKFieldsPointingTo(junctionUnwound.doc, junctionDef, targetTypeName);
4872
- if (fksToTarget.length === 0) errors.push({
4873
- message: `Junction '${junctionName}' has no @db.rel.FK pointing to '${targetTypeName}'`,
4874
- severity: 1,
4875
- range: args[0].range
4876
- });
4877
- else if (fksToTarget.length > 1) errors.push({
4878
- message: `Junction '${junctionName}' has multiple @db.rel.FK pointing to '${targetTypeName}' — not supported`,
4879
- severity: 1,
4880
- range: args[0].range
4881
- });
4882
- }
4883
- return errors;
4884
- }
4885
- }),
4886
- filter: new AnnotationSpec({
4887
- 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",
4888
- nodeType: ["prop"],
4889
- argument: {
4890
- name: "condition",
4891
- type: "query",
4892
- description: "Filter expression restricting which related records are loaded."
4893
- },
4894
- validate(token, args, doc) {
4895
- const errors = [];
4896
- const field = token.parentNode;
4897
- const hasTo = field.countAnnotations("db.rel.to") > 0;
4898
- const hasFrom = field.countAnnotations("db.rel.from") > 0;
4899
- const hasVia = field.countAnnotations("db.rel.via") > 0;
4900
- if (!hasTo && !hasFrom && !hasVia) {
4901
- errors.push({
4902
- message: "@db.rel.filter is only valid on navigational fields (@db.rel.to, @db.rel.from, or @db.rel.via)",
4903
- severity: 1,
4904
- range: token.range
4905
- });
4906
- return errors;
4907
- }
4908
- if (!args[0]?.queryNode) return errors;
4909
- const targetTypeName = getNavTargetTypeName(field);
4910
- if (!targetTypeName) return errors;
4911
- const allowedTypes = [targetTypeName];
4912
- if (hasVia) {
4913
- const viaAnnotations = field.annotations?.filter((a) => a.name === "db.rel.via");
4914
- if (viaAnnotations?.[0]?.args[0]) allowedTypes.push(viaAnnotations[0].args[0].text);
4915
- }
4916
- errors.push(...validateQueryScope(args[0], allowedTypes, targetTypeName, doc));
4917
- return errors;
4918
- }
4919
- })
4920
- },
4921
- view: {
4922
- $self: new AnnotationSpec({
4923
- 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",
4924
- nodeType: ["interface"],
4925
- argument: {
4926
- optional: true,
4927
- name: "name",
4928
- type: "string",
4929
- description: "The view name in the database. If omitted, derived from the interface name."
4930
- },
4931
- validate(token, _args, _doc) {
4932
- const errors = [];
4933
- const owner = token.parentNode;
4934
- if (owner.countAnnotations("db.table") > 0) errors.push({
4935
- message: "An interface cannot be both a @db.table and a @db.view",
4936
- severity: 1,
4937
- range: token.range
4938
- });
4939
- return errors;
4940
- }
4941
- }),
4942
- for: new AnnotationSpec({
4943
- 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",
4944
- nodeType: ["interface"],
4945
- argument: {
4946
- name: "entry",
4947
- type: "ref",
4948
- description: "The primary/entry table type (must have @db.table)."
4949
- },
4950
- validate(token, args, doc) {
4951
- const errors = [];
4952
- const owner = token.parentNode;
4953
- if (owner.countAnnotations("db.table") > 0) errors.push({
4954
- message: "An interface cannot be both a @db.table and a @db.view",
4955
- severity: 1,
4956
- range: token.range
4957
- });
4958
- if (args[0]) errors.push(...validateRefArgument(args[0], doc, { requireDbTable: true }));
4959
- return errors;
4960
- }
4961
- }),
4962
- joins: new AnnotationSpec({
4963
- 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",
4964
- nodeType: ["interface"],
4965
- multiple: true,
4966
- mergeStrategy: "append",
4967
- argument: [{
4968
- name: "target",
4969
- type: "ref",
4970
- description: "The table type to join (must have @db.table)."
4971
- }, {
4972
- name: "condition",
4973
- type: "query",
4974
- description: "Join condition expression."
4975
- }],
4976
- validate(token, args, doc) {
4977
- const errors = [];
4978
- const owner = token.parentNode;
4979
- if (!hasAnyViewAnnotation(owner) && !args[0]) {
4980
- errors.push({
4981
- message: "@db.view.joins is only valid on @db.view interfaces",
4982
- severity: 1,
4983
- range: token.range
4984
- });
4985
- return errors;
4986
- }
4987
- if (args[0]) errors.push(...validateRefArgument(args[0], doc, { requireDbTable: true }));
4988
- const forAnnotations = owner.annotations?.filter((a) => a.name === "db.view.for");
4989
- const entryTypeName = forAnnotations?.[0]?.args[0]?.text;
4990
- if (!entryTypeName) {
4991
- errors.push({
4992
- message: "@db.view.joins requires @db.view.for to identify the entry table",
4993
- severity: 1,
4994
- range: token.range
4995
- });
4996
- return errors;
4997
- }
4998
- if (args[1]?.queryNode && args[0]) {
4999
- const joinTargetName = args[0].text;
5000
- errors.push(...validateQueryScope(args[1], [joinTargetName, entryTypeName], entryTypeName, doc));
5001
- }
5002
- return errors;
5003
- }
5004
- }),
5005
- filter: new AnnotationSpec({
5006
- 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",
5007
- nodeType: ["interface"],
5008
- argument: {
5009
- name: "condition",
5010
- type: "query",
5011
- description: "Filter expression for the view WHERE clause."
5012
- },
5013
- validate(token, args, doc) {
5014
- const errors = [];
5015
- const owner = token.parentNode;
5016
- if (!hasAnyViewAnnotation(owner) && !args[0]) {
5017
- errors.push({
5018
- message: "@db.view.filter is only valid on @db.view interfaces",
5019
- severity: 1,
5020
- range: token.range
5021
- });
5022
- return errors;
5023
- }
5024
- if (!args[0]?.queryNode) return errors;
5025
- const forAnnotations = owner.annotations?.filter((a) => a.name === "db.view.for");
5026
- const entryTypeName = forAnnotations?.[0]?.args[0]?.text;
5027
- if (!entryTypeName) {
5028
- errors.push({
5029
- message: "@db.view.filter requires @db.view.for to identify the entry table",
5030
- severity: 1,
5031
- range: token.range
5032
- });
5033
- return errors;
5034
- }
5035
- const allowedTypes = [entryTypeName];
5036
- const joinsAnnotations = owner.annotations?.filter((a) => a.name === "db.view.joins");
5037
- if (joinsAnnotations) {
5038
- for (const join of joinsAnnotations) if (join.args[0]) allowedTypes.push(join.args[0].text);
5039
- }
5040
- errors.push(...validateQueryScope(args[0], allowedTypes, entryTypeName, doc));
5041
- return errors;
5042
- }
5043
- }),
5044
- materialized: new AnnotationSpec({
5045
- 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",
5046
- nodeType: ["interface"],
5047
- validate(token, _args, _doc) {
5048
- const errors = [];
5049
- const owner = token.parentNode;
5050
- if (!hasAnyViewAnnotation(owner)) errors.push({
5051
- message: "@db.view.materialized is only valid on @db.view interfaces",
5052
- severity: 1,
5053
- range: token.range
5054
- });
5055
- return errors;
5056
- }
5057
- }),
5058
- renamed: new AnnotationSpec({
5059
- 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",
5060
- nodeType: ["interface"],
5061
- argument: {
5062
- name: "oldName",
5063
- type: "string",
5064
- description: "The previous view name."
5065
- },
5066
- validate(token, _args, _doc) {
5067
- const errors = [];
5068
- const owner = token.parentNode;
5069
- if (!hasAnyViewAnnotation(owner)) errors.push({
5070
- message: "@db.view.renamed requires @db.view on the same interface",
5071
- severity: 1,
5072
- range: token.range
5073
- });
5074
- return errors;
5075
- }
5076
- })
5077
- }
5078
- };
5079
-
5080
4048
  //#endregion
5081
4049
  //#region packages/core/src/defaults/emit-annotations.ts
5082
4050
  const emitAnnotations = { jsonSchema: new AnnotationSpec({
@@ -5619,6 +4587,10 @@ const primitives = {
5619
4587
  }
5620
4588
  }
5621
4589
  },
4590
+ decimal: {
4591
+ type: "decimal",
4592
+ documentation: "Decimal number stored as string to preserve precision. Use with @db.column.precision."
4593
+ },
5622
4594
  boolean: {
5623
4595
  type: "boolean",
5624
4596
  documentation: "Represents true/false values.",
@@ -5800,7 +4772,6 @@ function getDefaultAtscriptConfig() {
5800
4772
  meta: { ...metaAnnotations },
5801
4773
  expect: { ...expectAnnotations },
5802
4774
  emit: { ...emitAnnotations },
5803
- db: { ...dbAnnotations },
5804
4775
  ui: { ...uiAnnotations }
5805
4776
  }
5806
4777
  };
@@ -6507,7 +5478,6 @@ exports.analyzeQueryCursorContext = analyzeQueryCursorContext
6507
5478
  exports.build = build
6508
5479
  exports.createAtscriptPlugin = createAtscriptPlugin
6509
5480
  exports.defineConfig = defineConfig
6510
- exports.findFKFieldsPointingTo = findFKFieldsPointingTo
6511
5481
  exports.flattenInterfaceNode = flattenInterfaceNode
6512
5482
  exports.getFieldsForType = getFieldsForType
6513
5483
  exports.getQueryCompletionScope = getQueryCompletionScope
@@ -6536,5 +5506,4 @@ exports.loadTsConfig = loadTsConfig
6536
5506
  exports.resolveAnnotation = resolveAnnotation
6537
5507
  exports.resolveAtscriptFromPath = resolveAtscriptFromPath
6538
5508
  exports.resolveConfigFile = resolveConfigFile
6539
- exports.resolveQueryFieldRef = resolveQueryFieldRef
6540
- exports.validateRefArgument = validateRefArgument
5509
+ exports.resolveQueryFieldRef = resolveQueryFieldRef