@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.mjs CHANGED
@@ -1157,7 +1157,8 @@ async function loadTsConfig(configFile, forceFormat) {
1157
1157
  pathToFileURL(file).href
1158
1158
  )).default;
1159
1159
  } catch (error) {
1160
- console.error("Could not load config file", file, error);
1160
+ const message = error instanceof Error ? error.message : String(error);
1161
+ console.error(`Could not load config file ${configFile}: ${message}`);
1161
1162
  return {};
1162
1163
  } finally {
1163
1164
  fs.unlink(file, () => {});
@@ -4020,1039 +4021,6 @@ function createSyntheticRef(name) {
4020
4021
  return ref$1;
4021
4022
  }
4022
4023
 
4023
- //#endregion
4024
- //#region packages/core/src/defaults/db-utils.ts
4025
- function validateRefArgument(token, doc, options) {
4026
- const messages = [];
4027
- const text$2 = token.text;
4028
- const [typeName, ...chain] = text$2.split(".");
4029
- const decl = doc.getDeclarationOwnerNode(typeName);
4030
- if (!decl) {
4031
- const regDef = doc.registry.definitions.get(typeName);
4032
- if (regDef?.imported) return messages;
4033
- messages.push({
4034
- severity: 1,
4035
- message: `Unknown type '${typeName}'.`,
4036
- range: token.range
4037
- });
4038
- return messages;
4039
- }
4040
- if (chain.length > 0) {
4041
- const unwound = doc.unwindType(typeName, chain);
4042
- if (!unwound) {
4043
- messages.push({
4044
- severity: 1,
4045
- message: `Field '${chain.join(".")}' does not exist on type '${typeName}'.`,
4046
- range: token.range
4047
- });
4048
- return messages;
4049
- }
4050
- }
4051
- if (options?.requireDbTable && decl.node) {
4052
- const hasDbTable = decl.node.countAnnotations("db.table") > 0;
4053
- if (!hasDbTable) messages.push({
4054
- severity: 1,
4055
- message: `Type '${typeName}' must have @db.table annotation.`,
4056
- range: token.range
4057
- });
4058
- }
4059
- return messages;
4060
- }
4061
- function findFKFieldsPointingTo(doc, iface, targetTypeName, alias) {
4062
- const results = [];
4063
- let struct;
4064
- if (isInterface(iface) && iface.hasExtends) {
4065
- const resolved = doc.resolveInterfaceExtends(iface);
4066
- if (resolved && isStructure(resolved)) struct = resolved;
4067
- }
4068
- if (!struct) struct = isStructure(iface) ? iface : isInterface(iface) && isStructure(iface.getDefinition()) ? iface.getDefinition() : undefined;
4069
- if (!struct) return results;
4070
- for (const [name, prop] of struct.props) {
4071
- if (prop.countAnnotations("db.rel.FK") === 0) continue;
4072
- const def = prop.getDefinition();
4073
- if (!def || !isRef(def)) continue;
4074
- const ref$1 = def;
4075
- if (!ref$1.hasChain) continue;
4076
- const refTypeName = ref$1.id;
4077
- const refField = ref$1.chain.map((c) => c.text).join(".");
4078
- if (refTypeName !== targetTypeName) continue;
4079
- if (alias !== undefined) {
4080
- const fkAnnotations = prop.annotations?.filter((a) => a.name === "db.rel.FK");
4081
- const hasMatchingAlias = fkAnnotations?.some((a) => a.args.length > 0 && a.args[0].text === alias);
4082
- if (!hasMatchingAlias) continue;
4083
- }
4084
- results.push({
4085
- name,
4086
- prop,
4087
- chainRef: {
4088
- type: refTypeName,
4089
- field: refField
4090
- }
4091
- });
4092
- }
4093
- return results;
4094
- }
4095
- const viewAnnotationNames = [
4096
- "db.view",
4097
- "db.view.for",
4098
- "db.view.joins",
4099
- "db.view.filter",
4100
- "db.view.materialized"
4101
- ];
4102
- function hasAnyViewAnnotation(node) {
4103
- return viewAnnotationNames.some((name) => node.countAnnotations(name) > 0);
4104
- }
4105
- function validateQueryScope(queryToken, allowedTypes, unqualifiedTarget, doc) {
4106
- const errors = [];
4107
- const queryNode = queryToken.queryNode;
4108
- if (!queryNode) return errors;
4109
- function walkFieldRef(ref$1) {
4110
- if (ref$1.typeRef) {
4111
- const typeName = ref$1.typeRef.text;
4112
- if (!allowedTypes.includes(typeName)) errors.push({
4113
- message: `Query references '${typeName}' which is not in scope — expected ${allowedTypes.map((t) => `'${t}'`).join(" or ")}`,
4114
- severity: 1,
4115
- range: ref$1.typeRef.range
4116
- });
4117
- } else if (unqualifiedTarget === null) errors.push({
4118
- message: `Unqualified field reference '${ref$1.fieldRef.text}' — use qualified form (e.g., Type.${ref$1.fieldRef.text})`,
4119
- severity: 1,
4120
- range: ref$1.fieldRef.range
4121
- });
4122
- else {
4123
- const unwound = doc.unwindType(unqualifiedTarget);
4124
- if (unwound) {
4125
- const targetDef = unwound.def;
4126
- if (isInterface(targetDef) || isStructure(targetDef)) {
4127
- const struct = isInterface(targetDef) ? targetDef.getDefinition() : targetDef;
4128
- if (struct && isStructure(struct) && !struct.props.has(ref$1.fieldRef.text)) errors.push({
4129
- message: `Field '${ref$1.fieldRef.text}' does not exist on '${unqualifiedTarget}'`,
4130
- severity: 1,
4131
- range: ref$1.fieldRef.range
4132
- });
4133
- }
4134
- }
4135
- }
4136
- }
4137
- function walkExpr(expr) {
4138
- if (isQueryLogical(expr)) for (const operand of expr.operands) walkExpr(operand);
4139
- else if (isQueryComparison(expr)) {
4140
- walkFieldRef(expr.left);
4141
- if (expr.right && "fieldRef" in expr.right) walkFieldRef(expr.right);
4142
- }
4143
- }
4144
- walkExpr(queryNode.expression);
4145
- return errors;
4146
- }
4147
-
4148
- //#endregion
4149
- //#region packages/core/src/defaults/db-annotations.ts
4150
- /**
4151
- * Traverse from annotation token → prop → structure → interface
4152
- * to check if the parent interface has @db.table.
4153
- */ function getDbTableOwner(token) {
4154
- const field = token.parentNode;
4155
- const struct = field.ownerNode;
4156
- if (!struct || !isStructure(struct)) return undefined;
4157
- const iface = struct.ownerNode;
4158
- return iface && isInterface(iface) ? iface : struct;
4159
- }
4160
- /**
4161
- * Get the parent structure node from an annotation token.
4162
- */ function getParentStruct(token) {
4163
- const field = token.parentNode;
4164
- const struct = field.ownerNode;
4165
- return struct && isStructure(struct) ? struct : undefined;
4166
- }
4167
- /**
4168
- * Get the parent interface name (for error messages and cross-type resolution).
4169
- */ function getParentTypeName(token) {
4170
- const struct = getParentStruct(token);
4171
- if (!struct) return undefined;
4172
- const iface = struct.ownerNode;
4173
- return iface && isInterface(iface) ? iface.id : struct.id;
4174
- }
4175
- /**
4176
- * Validate that an annotation is on a field with the expected base type.
4177
- */ function validateFieldBaseType(token, doc, annotationName, expectedType) {
4178
- const errors = [];
4179
- const field = token.parentNode;
4180
- const definition$1 = field.getDefinition();
4181
- if (!definition$1 || !isRef(definition$1)) return errors;
4182
- const unwound = doc.unwindType(definition$1.id, definition$1.chain);
4183
- if (!unwound || !isPrimitive(unwound.def)) return errors;
4184
- const baseType = unwound.def.config.type;
4185
- const allowed = Array.isArray(expectedType) ? expectedType : [expectedType];
4186
- if (!allowed.includes(baseType)) errors.push({
4187
- message: `${annotationName} is not compatible with type "${baseType}" — requires ${allowed.join(" or ")}`,
4188
- severity: 1,
4189
- range: token.range
4190
- });
4191
- return errors;
4192
- }
4193
- /**
4194
- * Extract target type name from a navigational field definition.
4195
- * Unwraps arrays (e.g., `Post[]` → `Post`).
4196
- */ function getNavTargetTypeName(field) {
4197
- let def = field.getDefinition();
4198
- if (isArray(def)) def = def?.getDefinition();
4199
- if (isRef(def)) return def.id;
4200
- return undefined;
4201
- }
4202
- /**
4203
- * Get the alias argument from an annotation on a field.
4204
- */ function getAnnotationAlias(prop, annotationName) {
4205
- const annotations$1 = prop.annotations?.filter((a) => a.name === annotationName);
4206
- if (!annotations$1 || annotations$1.length === 0) return undefined;
4207
- return annotations$1[0].args.length > 0 ? annotations$1[0].args[0].text : undefined;
4208
- }
4209
- /**
4210
- * Factory for @db.rel.onDelete / @db.rel.onUpdate — identical validation logic,
4211
- * only the annotation name and description verb differ.
4212
- */ function refActionAnnotation(name) {
4213
- return new AnnotationSpec({
4214
- 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",
4215
- nodeType: ["prop"],
4216
- argument: {
4217
- name: "action",
4218
- type: "string",
4219
- values: [
4220
- "cascade",
4221
- "restrict",
4222
- "noAction",
4223
- "setNull",
4224
- "setDefault"
4225
- ],
4226
- description: "Referential action: \"cascade\", \"restrict\", \"noAction\", \"setNull\", or \"setDefault\"."
4227
- },
4228
- validate(token, args, doc) {
4229
- const errors = [];
4230
- const field = token.parentNode;
4231
- if (field.countAnnotations("db.rel.FK") === 0) errors.push({
4232
- message: `@db.rel.${name} is only valid on @db.rel.FK fields`,
4233
- severity: 1,
4234
- range: token.range
4235
- });
4236
- if (args[0]) {
4237
- const action = args[0].text;
4238
- if (action === "setNull" && !field.has("optional")) errors.push({
4239
- message: `@db.rel.${name} "setNull" requires the FK field to be optional (?)`,
4240
- severity: 1,
4241
- range: token.range
4242
- });
4243
- if (action === "setDefault" && field.countAnnotations("db.default") === 0 && field.countAnnotations("db.default.increment") === 0 && field.countAnnotations("db.default.uuid") === 0 && field.countAnnotations("db.default.now") === 0) errors.push({
4244
- message: `@db.rel.${name} "setDefault" but no @db.default.* annotation — field will have no fallback value`,
4245
- severity: 2,
4246
- range: token.range
4247
- });
4248
- }
4249
- const fkAlias = getAnnotationAlias(field, "db.rel.FK");
4250
- if (fkAlias) {
4251
- const struct = getParentStruct(token);
4252
- if (struct) {
4253
- const annotationName = `db.rel.${name}`;
4254
- let count = 0;
4255
- for (const [, prop] of struct.props) {
4256
- if (prop.countAnnotations("db.rel.FK") === 0) continue;
4257
- if (prop.countAnnotations(annotationName) === 0) continue;
4258
- const propFkAlias = getAnnotationAlias(prop, "db.rel.FK");
4259
- if (propFkAlias === fkAlias) count++;
4260
- }
4261
- if (count > 1) errors.push({
4262
- message: `Composite FK '${fkAlias}' has @db.rel.${name} on multiple fields — declare it on exactly one`,
4263
- severity: 1,
4264
- range: token.range
4265
- });
4266
- }
4267
- }
4268
- return errors;
4269
- }
4270
- });
4271
- }
4272
- const dbAnnotations = {
4273
- patch: { strategy: new AnnotationSpec({
4274
- 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",
4275
- nodeType: ["prop"],
4276
- multiple: false,
4277
- argument: {
4278
- name: "strategy",
4279
- type: "string",
4280
- description: "The **patch strategy** for this field: `\"replace\"` (default) or `\"merge\"`.",
4281
- values: ["replace", "merge"]
4282
- },
4283
- validate(token, args, doc) {
4284
- const field = token.parentNode;
4285
- const errors = [];
4286
- const definition$1 = field.getDefinition();
4287
- if (!definition$1) return errors;
4288
- let wrongType = false;
4289
- if (isRef(definition$1)) {
4290
- const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
4291
- if (!isStructure(def) && !isInterface(def) && !isArray(def)) wrongType = true;
4292
- } else if (!isStructure(definition$1) && !isInterface(definition$1) && !isArray(definition$1)) wrongType = true;
4293
- if (wrongType) errors.push({
4294
- message: `@db.patch.strategy requires a field of type object or array`,
4295
- severity: 1,
4296
- range: token.range
4297
- });
4298
- return errors;
4299
- }
4300
- }) },
4301
- table: {
4302
- $self: new AnnotationSpec({
4303
- 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",
4304
- nodeType: ["interface"],
4305
- argument: {
4306
- optional: true,
4307
- name: "name",
4308
- type: "string",
4309
- description: "Table/collection name. If omitted, derived from interface name."
4310
- },
4311
- validate(token, _args, _doc) {
4312
- const errors = [];
4313
- const owner = token.parentNode;
4314
- if (hasAnyViewAnnotation(owner)) errors.push({
4315
- message: "An interface cannot be both a @db.table and a @db.view",
4316
- severity: 1,
4317
- range: token.range
4318
- });
4319
- return errors;
4320
- }
4321
- }),
4322
- renamed: new AnnotationSpec({
4323
- 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",
4324
- nodeType: ["interface"],
4325
- argument: {
4326
- name: "oldName",
4327
- type: "string",
4328
- description: "The previous table/collection name."
4329
- },
4330
- validate(token, _args, _doc) {
4331
- const errors = [];
4332
- const owner = token.parentNode;
4333
- if (owner.countAnnotations("db.table") === 0) errors.push({
4334
- message: "@db.table.renamed requires @db.table on the same interface",
4335
- severity: 1,
4336
- range: token.range
4337
- });
4338
- return errors;
4339
- }
4340
- })
4341
- },
4342
- schema: new AnnotationSpec({
4343
- 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",
4344
- nodeType: ["interface"],
4345
- argument: {
4346
- name: "name",
4347
- type: "string",
4348
- description: "Schema/namespace name."
4349
- }
4350
- }),
4351
- index: {
4352
- plain: new AnnotationSpec({
4353
- 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",
4354
- nodeType: ["prop"],
4355
- multiple: true,
4356
- mergeStrategy: "append",
4357
- argument: [{
4358
- optional: true,
4359
- name: "name",
4360
- type: "string",
4361
- description: "Index name / composite group name."
4362
- }, {
4363
- optional: true,
4364
- name: "sort",
4365
- type: "string",
4366
- values: ["asc", "desc"],
4367
- description: "Sort direction. Defaults to \"asc\"."
4368
- }]
4369
- }),
4370
- unique: new AnnotationSpec({
4371
- 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",
4372
- nodeType: ["prop"],
4373
- multiple: true,
4374
- mergeStrategy: "append",
4375
- argument: {
4376
- optional: true,
4377
- name: "name",
4378
- type: "string",
4379
- description: "Index name / composite group name."
4380
- }
4381
- }),
4382
- fulltext: new AnnotationSpec({
4383
- 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",
4384
- nodeType: ["prop"],
4385
- multiple: true,
4386
- mergeStrategy: "append",
4387
- argument: [{
4388
- optional: true,
4389
- name: "name",
4390
- type: "string",
4391
- description: "Index name / composite group name."
4392
- }, {
4393
- optional: true,
4394
- name: "weight",
4395
- type: "number",
4396
- description: "Field importance in search results (higher = more relevant). Defaults to `1`. Supported by databases with weighted fulltext (e.g., MongoDB, PostgreSQL)."
4397
- }]
4398
- })
4399
- },
4400
- column: {
4401
- $self: new AnnotationSpec({
4402
- 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",
4403
- nodeType: ["prop"],
4404
- argument: {
4405
- name: "name",
4406
- type: "string",
4407
- description: "The column/field name (without parent prefix for nested fields)."
4408
- }
4409
- }),
4410
- renamed: new AnnotationSpec({
4411
- 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",
4412
- nodeType: ["prop"],
4413
- argument: {
4414
- name: "oldName",
4415
- type: "string",
4416
- description: "The old local field name (parent prefix is reconstructed automatically)."
4417
- }
4418
- }),
4419
- collate: new AnnotationSpec({
4420
- description: "Portable collation for string comparison and sorting. Adapters map the generic value to their native collation.\n\n- **\"binary\"** — exact byte comparison (case-sensitive)\n- **\"nocase\"** — case-insensitive comparison\n- **\"unicode\"** — full Unicode-aware sorting\n\nFor adapter-specific collations, use `@db.<engine>.collate` instead.\n\n**Example:**\n```atscript\n@db.column.collate \"nocase\"\nusername: string\n```\n",
4421
- nodeType: ["prop"],
4422
- argument: {
4423
- name: "collation",
4424
- type: "string",
4425
- values: [
4426
- "binary",
4427
- "nocase",
4428
- "unicode"
4429
- ],
4430
- description: "Portable collation mode: \"binary\", \"nocase\", or \"unicode\"."
4431
- },
4432
- validate(token, args, doc) {
4433
- return validateFieldBaseType(token, doc, "@db.column.collate", "string");
4434
- }
4435
- }),
4436
- precision: new AnnotationSpec({
4437
- description: "Sets decimal precision and scale for database storage. Adapters map this to their native decimal type (e.g., `DECIMAL(10,2)` in SQL, ignored in MongoDB).\n\nThis is purely a DB storage hint — it does not affect runtime JavaScript number behavior.\n\n**Example:**\n```atscript\n@db.column.precision 10, 2\nprice: number\n```\n",
4438
- nodeType: ["prop"],
4439
- argument: [{
4440
- name: "precision",
4441
- type: "number",
4442
- description: "Total number of significant digits."
4443
- }, {
4444
- name: "scale",
4445
- type: "number",
4446
- description: "Number of digits after the decimal point."
4447
- }],
4448
- validate(token, args, doc) {
4449
- return validateFieldBaseType(token, doc, "@db.column.precision", "number");
4450
- }
4451
- })
4452
- },
4453
- default: {
4454
- $self: new AnnotationSpec({
4455
- 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",
4456
- nodeType: ["prop"],
4457
- argument: {
4458
- name: "value",
4459
- type: "string",
4460
- description: "Static default value. Strings used as-is; other types parsed via JSON.parse()."
4461
- }
4462
- }),
4463
- increment: new AnnotationSpec({
4464
- description: "Auto-incrementing integer default. Each adapter maps this to its native mechanism (e.g., `AUTO_INCREMENT` in MySQL, `INTEGER PRIMARY KEY` in SQLite, counter collection in MongoDB).\n\n**Example:**\n```atscript\n@db.default.increment\nid: number.int\n\n// With optional start value:\n@db.default.increment 1000\nid: number.int\n```\n",
4465
- nodeType: ["prop"],
4466
- argument: {
4467
- optional: true,
4468
- name: "start",
4469
- type: "number",
4470
- description: "Starting value for the auto-increment sequence. Adapter-specific behavior; some adapters may ignore this."
4471
- },
4472
- validate(token, args, doc) {
4473
- return validateFieldBaseType(token, doc, "db.default.increment", "number");
4474
- }
4475
- }),
4476
- uuid: new AnnotationSpec({
4477
- description: "UUID generation default. Each adapter maps this to its native mechanism (e.g., `DEFAULT (UUID())` in MySQL, `gen_random_uuid()` in PostgreSQL, app-level in SQLite).\n\n**Example:**\n```atscript\n@db.default.uuid\nid: string.uuid\n```\n",
4478
- nodeType: ["prop"],
4479
- validate(token, args, doc) {
4480
- return validateFieldBaseType(token, doc, "db.default.uuid", "string");
4481
- }
4482
- }),
4483
- now: new AnnotationSpec({
4484
- description: "Current timestamp default. Each adapter maps this to its native mechanism (e.g., `DEFAULT CURRENT_TIMESTAMP` in MySQL, `DEFAULT now()` in PostgreSQL).\n\n**Example:**\n```atscript\n@db.default.now\ncreatedAt: number.timestamp\n```\n",
4485
- nodeType: ["prop"],
4486
- validate(token, args, doc) {
4487
- return validateFieldBaseType(token, doc, "db.default.now", ["number", "string"]);
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
4024
  //#endregion
5057
4025
  //#region packages/core/src/defaults/emit-annotations.ts
5058
4026
  const emitAnnotations = { jsonSchema: new AnnotationSpec({
@@ -5595,6 +4563,10 @@ const primitives = {
5595
4563
  }
5596
4564
  }
5597
4565
  },
4566
+ decimal: {
4567
+ type: "decimal",
4568
+ documentation: "Decimal number stored as string to preserve precision. Use with @db.column.precision."
4569
+ },
5598
4570
  boolean: {
5599
4571
  type: "boolean",
5600
4572
  documentation: "Represents true/false values.",
@@ -5776,7 +4748,6 @@ function getDefaultAtscriptConfig() {
5776
4748
  meta: { ...metaAnnotations },
5777
4749
  expect: { ...expectAnnotations },
5778
4750
  emit: { ...emitAnnotations },
5779
- db: { ...dbAnnotations },
5780
4751
  ui: { ...uiAnnotations }
5781
4752
  }
5782
4753
  };
@@ -6452,4 +5423,4 @@ else if (isGroup(def) && def.entity !== "structure") {
6452
5423
  }
6453
5424
 
6454
5425
  //#endregion
6455
- export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, build, createAtscriptPlugin, defineConfig, findFKFieldsPointingTo, flattenInterfaceNode, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isConst, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile, resolveQueryFieldRef, validateRefArgument };
5426
+ export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, build, createAtscriptPlugin, defineConfig, flattenInterfaceNode, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isConst, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile, resolveQueryFieldRef };