@vibeorm/generator 1.2.0 → 1.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibeorm/generator",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "TypeScript client generator for VibeORM — produces typed delegates, inputs, and Zod schemas from a Prisma schema",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -37,6 +37,6 @@
37
37
  "bun": ">=1.1.0"
38
38
  },
39
39
  "dependencies": {
40
- "@vibeorm/parser": "1.2.0"
40
+ "@vibeorm/parser": "1.3.1"
41
41
  }
42
42
  }
@@ -22,7 +22,7 @@ export function generateInputs(params: { schema: Schema }): string {
22
22
  }
23
23
 
24
24
  // Import model types for relation filter references
25
- parts.push(`import type { JsonValue } from "./models.ts";\n`);
25
+ parts.push(`import type { JsonValue, InputJsonValue } from "./models.ts";\n`);
26
26
 
27
27
  // Sort direction
28
28
  parts.push(`export type SortOrder = "asc" | "desc";
@@ -291,6 +291,15 @@ ${entries.join("\n")}
291
291
 
292
292
  function scalarTsType(params: { field: ScalarField; context?: "input" | "output" }): string {
293
293
  const { field, context } = params;
294
+ // Json input: use the looser InputJsonValue so Record<string, unknown>,
295
+ // typed catalogues, and toJSON-bearing objects can flow in (Bug 8). Output
296
+ // types keep the strict JsonValue (see generate-models.ts).
297
+ if (context === "input" && field.prismaType === "Json") {
298
+ const base = "InputJsonValue";
299
+ if (field.isList) return `${base}[]`;
300
+ if (!field.isRequired) return `${base} | null`;
301
+ return base;
302
+ }
294
303
  // For Decimal input types, accept both number and string for better DX
295
304
  const base = context === "input" && field.prismaType === "Decimal" ? "number | string" : field.tsType;
296
305
  if (field.isList) return `${base}[]`;
@@ -25,6 +25,27 @@ export function generateModels(params: { schema: Schema }): string {
25
25
  // type-level relaxation that's strictly more permissive in argument position.
26
26
  parts.push(`export type JsonValue = string | number | boolean | null | readonly JsonValue[] | { readonly [key: string]: JsonValue };\n`);
27
27
 
28
+ // InputJsonValue — looser than JsonValue, used in CreateInput/UpdateInput
29
+ // for Json fields (Bug 8). Accepts:
30
+ // - all JsonValue shapes (readonly arrays / readonly object index sigs)
31
+ // - any object exposing toJSON() (Date, Decimal wrappers, BigInt wrappers, …)
32
+ //
33
+ // The `toJSON` escape hatch is what lets users feed seed/factory data typed
34
+ // as `Record<string, unknown>` via a single intentional cast, instead of
35
+ // rewriting every call site. Postgres jsonb doesn't care about the JS shape —
36
+ // the adapter JSON.stringifies whatever it gets. Output types keep the strict
37
+ // `JsonValue`.
38
+ parts.push(`export type InputJsonObject = { readonly [key: string]: InputJsonValue | null | undefined };
39
+ export type InputJsonArray = ReadonlyArray<InputJsonValue | null>;
40
+ export type InputJsonValue =
41
+ | string
42
+ | number
43
+ | boolean
44
+ | InputJsonObject
45
+ | InputJsonArray
46
+ | { toJSON(): unknown };
47
+ `);
48
+
28
49
  // Generate the base OperationPayload interface
29
50
  parts.push(`export type OperationPayload = {
30
51
  name: string;