bonescript-compiler 0.7.0 → 0.9.0

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/src/index.ts CHANGED
@@ -17,6 +17,7 @@ export type { SolverResult } from "./solver";
17
17
  export { FullEmitter } from "./emit_full";
18
18
  export { NakamaEmitter } from "./emit_nakama";
19
19
  export { PrismaEmitter } from "./emit_prisma";
20
+ export { SqliteEmitter } from "./emit_sqlite";
20
21
  export type { NakamaEmittedFile } from "./emit_nakama";
21
22
  export type { EmittedFile } from "./emitter";
22
23
  export { Verifier } from "./verifier";
@@ -44,6 +45,7 @@ export { mergeWithExisting, extractImplementations, validateExtensions } from ".
44
45
  // New emitters
45
46
  export { emitOpenApiSpec, emitOpenApiJson } from "./emit_openapi";
46
47
  export { emitTypescriptSdk, emitSdkPackageJson } from "./emit_sdk";
48
+ export { emitReactHooks } from "./emit_react";
47
49
  export { emitZodSchemas } from "./emit_zod";
48
50
  export { emitPostmanCollection } from "./emit_postman";
49
51
  export { emitSeedFile } from "./emit_seed";
package/src/lowering.ts CHANGED
@@ -246,6 +246,32 @@ export class Lowering {
246
246
  fields.push(this.lowerField(f));
247
247
  }
248
248
 
249
+ // Auto-add foreign key columns for `belongs_to` relations.
250
+ //
251
+ // Without this, generated migrations reference a column that doesn't exist
252
+ // (e.g. `FOREIGN KEY (seller_id) REFERENCES sellers(id)` when no seller_id
253
+ // is declared in `owns:`). Users were having to duplicate the FK in
254
+ // `owns:` to make it work; we now synthesize it.
255
+ //
256
+ // If the user already declared a column with the same name (the legacy
257
+ // pattern), we don't add a duplicate — their declaration wins so they
258
+ // can override nullability or add @sensitive.
259
+ const existingFieldNames = new Set(fields.map(f => f.name));
260
+ for (const rel of entity.relations) {
261
+ if (rel.relationType !== "belongs_to") continue;
262
+ const fkName = toSnakeCase(rel.target) + "_id";
263
+ if (existingFieldNames.has(fkName)) continue;
264
+ fields.push({
265
+ name: fkName,
266
+ type: "uuid",
267
+ nullable: false,
268
+ unique: false,
269
+ indexed: true,
270
+ default_value: null,
271
+ });
272
+ existingFieldNames.add(fkName);
273
+ }
274
+
249
275
  // Add derived fields as generated columns (stored: false = virtual)
250
276
  const derivedFields: IR.IRField[] = entity.derived.map(d => ({
251
277
  name: d.name,