@casekit/orm2-cli 0.0.0-20250331202540 → 0.0.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.
Files changed (65) hide show
  1. package/build/cli.js +1 -2
  2. package/build/commands/db-drop/handler.js +0 -3
  3. package/build/commands/db-drop.test.js +1 -0
  4. package/build/commands/db-pull/handler.js +21 -8
  5. package/build/commands/db-pull/options.d.ts +5 -0
  6. package/build/commands/db-pull/options.js +5 -0
  7. package/build/commands/db-pull/util/relationNames.d.ts +3 -0
  8. package/build/commands/db-pull/util/relationNames.js +14 -0
  9. package/build/commands/db-pull/util/relationNames.test.js +61 -0
  10. package/build/commands/db-pull/util/renderDefault.d.ts +3 -0
  11. package/build/commands/db-pull/util/renderDefault.js +46 -0
  12. package/build/commands/db-pull/util/renderDefault.test.d.ts +1 -0
  13. package/build/commands/db-pull/util/renderDefault.test.js +67 -0
  14. package/build/commands/db-pull/util/renderFieldDefinition.d.ts +2 -0
  15. package/build/commands/db-pull/util/renderFieldDefinition.js +50 -0
  16. package/build/commands/db-pull/util/renderFieldDefinition.test.d.ts +1 -0
  17. package/build/commands/db-pull/util/renderFieldDefinition.test.js +182 -0
  18. package/build/commands/db-pull/util/renderModel.basic.test.d.ts +1 -0
  19. package/build/commands/db-pull/util/renderModel.basic.test.js +169 -0
  20. package/build/commands/db-pull/util/renderModel.constraints.test.d.ts +1 -0
  21. package/build/commands/db-pull/util/renderModel.constraints.test.js +677 -0
  22. package/build/commands/db-pull/util/renderModel.d.ts +2 -0
  23. package/build/commands/db-pull/util/renderModel.defaultValues.test.d.ts +1 -0
  24. package/build/commands/db-pull/util/renderModel.defaultValues.test.js +518 -0
  25. package/build/commands/db-pull/util/renderModel.js +88 -0
  26. package/build/commands/db-pull/util/renderModel.relations.test.d.ts +1 -0
  27. package/build/commands/db-pull/util/renderModel.relations.test.js +880 -0
  28. package/build/commands/db-pull/util/renderModel.types.test.d.ts +1 -0
  29. package/build/commands/db-pull/util/renderModel.types.test.js +703 -0
  30. package/build/commands/db-pull/util/renderRelations.d.ts +2 -0
  31. package/build/commands/db-pull/util/renderRelations.js +55 -0
  32. package/build/commands/db-pull/util/renderRelations.test.d.ts +1 -0
  33. package/build/commands/db-pull/util/renderRelations.test.js +165 -0
  34. package/build/commands/db-pull/util/renderType.d.ts +6 -0
  35. package/build/commands/db-pull/util/renderType.js +55 -0
  36. package/build/commands/db-pull/util/renderType.test.d.ts +1 -0
  37. package/build/commands/db-pull/util/renderType.test.js +46 -0
  38. package/build/commands/db-pull.d.ts +10 -0
  39. package/build/commands/db-pull.test.js +625 -0
  40. package/build/commands/db-push/handler.js +0 -3
  41. package/build/commands/init/handler.js +16 -3
  42. package/build/commands/init/util/generateConfigFile.js +2 -3
  43. package/build/commands/init/util/generateDbFile.js +13 -24
  44. package/build/commands/init/util/generateModelsFile.d.ts +1 -1
  45. package/build/commands/init/util/generateModelsFile.js +6 -2
  46. package/build/commands/init.test.js +19 -31
  47. package/build/types.d.ts +2 -2
  48. package/build/util/createOrOverwriteFile.d.ts +1 -1
  49. package/build/util/createOrOverwriteFile.js +1 -1
  50. package/build/util/loadConfig.js +5 -1
  51. package/package.json +26 -25
  52. package/build/commands/generate-model/handler.d.ts +0 -3
  53. package/build/commands/generate-model/handler.js +0 -10
  54. package/build/commands/generate-model/options.d.ts +0 -18
  55. package/build/commands/generate-model/options.js +0 -18
  56. package/build/commands/generate-model/util/generateModelFile.d.ts +0 -3
  57. package/build/commands/generate-model/util/generateModelFile.js +0 -59
  58. package/build/commands/generate-model/util/generateModelFile.test.js +0 -67
  59. package/build/commands/generate-model/util/regenerateModelsFile.d.ts +0 -2
  60. package/build/commands/generate-model/util/regenerateModelsFile.js +0 -50
  61. package/build/commands/generate-model.d.ts +0 -40
  62. package/build/commands/generate-model.js +0 -8
  63. package/build/commands/generate-model.test.js +0 -55
  64. /package/build/commands/{generate-model/util/generateModelFile.test.d.ts → db-pull/util/relationNames.test.d.ts} +0 -0
  65. /package/build/commands/{generate-model.test.d.ts → db-pull.test.d.ts} +0 -0
@@ -0,0 +1,169 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { unindent } from "@casekit/unindent";
3
+ import { renderModel } from "./renderModel.js";
4
+ describe("renderModel - basic functionality", () => {
5
+ it("renders a simple table with basic fields", async () => {
6
+ const table = {
7
+ schema: "public",
8
+ name: "users",
9
+ columns: [
10
+ {
11
+ schema: "public",
12
+ table: "users",
13
+ column: "id",
14
+ ordinalPosition: 1,
15
+ type: "integer",
16
+ default: null,
17
+ nullable: false,
18
+ udtSchema: "pg_catalog",
19
+ udt: "int4",
20
+ elementType: null,
21
+ elementTypeSchema: null,
22
+ cardinality: 0,
23
+ size: null,
24
+ isSerial: false,
25
+ },
26
+ {
27
+ schema: "public",
28
+ table: "users",
29
+ column: "name",
30
+ ordinalPosition: 2,
31
+ type: "text",
32
+ default: null,
33
+ nullable: false,
34
+ udtSchema: "pg_catalog",
35
+ udt: "text",
36
+ elementType: null,
37
+ elementTypeSchema: null,
38
+ cardinality: 0,
39
+ size: null,
40
+ isSerial: false,
41
+ },
42
+ {
43
+ schema: "public",
44
+ table: "users",
45
+ column: "email",
46
+ ordinalPosition: 3,
47
+ type: "text",
48
+ default: null,
49
+ nullable: true,
50
+ udtSchema: "pg_catalog",
51
+ udt: "text",
52
+ elementType: null,
53
+ elementTypeSchema: null,
54
+ cardinality: 0,
55
+ size: null,
56
+ isSerial: false,
57
+ },
58
+ ],
59
+ foreignKeys: [],
60
+ primaryKey: null,
61
+ uniqueConstraints: [],
62
+ };
63
+ const result = await renderModel(table, []);
64
+ expect(result.trim()).toBe(unindent `
65
+ import { type ModelDefinition } from "@casekit/orm2";
66
+
67
+ export const users = {
68
+ fields: {
69
+ id: { type: "integer" },
70
+ name: { type: "text" },
71
+ email: { type: "text", nullable: true },
72
+ },
73
+ } as const satisfies ModelDefinition;
74
+ `);
75
+ });
76
+ it("renders a table with schema and table name different from model name", async () => {
77
+ const table = {
78
+ schema: "my_schema",
79
+ name: "user_accounts",
80
+ columns: [
81
+ {
82
+ schema: "my_schema",
83
+ table: "user_accounts",
84
+ column: "id",
85
+ ordinalPosition: 1,
86
+ type: "integer",
87
+ default: null,
88
+ nullable: false,
89
+ udtSchema: "pg_catalog",
90
+ udt: "int4",
91
+ elementType: null,
92
+ elementTypeSchema: null,
93
+ cardinality: 0,
94
+ size: null,
95
+ isSerial: false,
96
+ },
97
+ ],
98
+ foreignKeys: [],
99
+ primaryKey: null,
100
+ uniqueConstraints: [],
101
+ };
102
+ const result = await renderModel(table, []);
103
+ expect(result.trim()).toBe(unindent `
104
+ import { type ModelDefinition } from "@casekit/orm2";
105
+
106
+ export const userAccounts = {
107
+ schema: "my_schema",
108
+ table: "user_accounts",
109
+ fields: {
110
+ id: { type: "integer" },
111
+ },
112
+ } as const satisfies ModelDefinition;
113
+ `);
114
+ });
115
+ it("preserves column names when different from field names", async () => {
116
+ const table = {
117
+ schema: "public",
118
+ name: "users",
119
+ columns: [
120
+ {
121
+ schema: "public",
122
+ table: "users",
123
+ column: "first_name",
124
+ ordinalPosition: 1,
125
+ type: "text",
126
+ default: null,
127
+ nullable: false,
128
+ udtSchema: "pg_catalog",
129
+ udt: "text",
130
+ elementType: null,
131
+ elementTypeSchema: null,
132
+ cardinality: 0,
133
+ size: null,
134
+ isSerial: false,
135
+ },
136
+ {
137
+ schema: "public",
138
+ table: "users",
139
+ column: "created_at",
140
+ ordinalPosition: 2,
141
+ type: "timestamp",
142
+ default: null,
143
+ nullable: false,
144
+ udtSchema: "pg_catalog",
145
+ udt: "timestamp",
146
+ elementType: null,
147
+ elementTypeSchema: null,
148
+ cardinality: 0,
149
+ size: null,
150
+ isSerial: false,
151
+ },
152
+ ],
153
+ foreignKeys: [],
154
+ primaryKey: null,
155
+ uniqueConstraints: [],
156
+ };
157
+ const result = await renderModel(table, []);
158
+ expect(result.trim()).toBe(unindent `
159
+ import { type ModelDefinition } from "@casekit/orm2";
160
+
161
+ export const users = {
162
+ fields: {
163
+ firstName: { column: "first_name", type: "text" },
164
+ createdAt: { column: "created_at", type: "timestamp" },
165
+ },
166
+ } as const satisfies ModelDefinition;
167
+ `);
168
+ });
169
+ });