@casekit/orm-cli 0.0.1-release-candidate

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 (99) hide show
  1. package/build/cli.d.ts +1 -0
  2. package/build/cli.js +21 -0
  3. package/build/commands/db-drop/handler.d.ts +3 -0
  4. package/build/commands/db-drop/handler.js +15 -0
  5. package/build/commands/db-drop/options.d.ts +1 -0
  6. package/build/commands/db-drop/options.js +1 -0
  7. package/build/commands/db-drop.d.ts +6 -0
  8. package/build/commands/db-drop.js +8 -0
  9. package/build/commands/db-drop.test.d.ts +1 -0
  10. package/build/commands/db-drop.test.js +22 -0
  11. package/build/commands/db-pull/handler.d.ts +3 -0
  12. package/build/commands/db-pull/handler.js +32 -0
  13. package/build/commands/db-pull/options.d.ts +13 -0
  14. package/build/commands/db-pull/options.js +13 -0
  15. package/build/commands/db-pull/util/relationNames.d.ts +3 -0
  16. package/build/commands/db-pull/util/relationNames.js +14 -0
  17. package/build/commands/db-pull/util/relationNames.test.d.ts +1 -0
  18. package/build/commands/db-pull/util/relationNames.test.js +61 -0
  19. package/build/commands/db-pull/util/renderDefault.d.ts +3 -0
  20. package/build/commands/db-pull/util/renderDefault.js +46 -0
  21. package/build/commands/db-pull/util/renderDefault.test.d.ts +1 -0
  22. package/build/commands/db-pull/util/renderDefault.test.js +67 -0
  23. package/build/commands/db-pull/util/renderFieldDefinition.d.ts +2 -0
  24. package/build/commands/db-pull/util/renderFieldDefinition.js +50 -0
  25. package/build/commands/db-pull/util/renderFieldDefinition.test.d.ts +1 -0
  26. package/build/commands/db-pull/util/renderFieldDefinition.test.js +182 -0
  27. package/build/commands/db-pull/util/renderModel.basic.test.d.ts +1 -0
  28. package/build/commands/db-pull/util/renderModel.basic.test.js +169 -0
  29. package/build/commands/db-pull/util/renderModel.constraints.test.d.ts +1 -0
  30. package/build/commands/db-pull/util/renderModel.constraints.test.js +677 -0
  31. package/build/commands/db-pull/util/renderModel.d.ts +2 -0
  32. package/build/commands/db-pull/util/renderModel.defaultValues.test.d.ts +1 -0
  33. package/build/commands/db-pull/util/renderModel.defaultValues.test.js +518 -0
  34. package/build/commands/db-pull/util/renderModel.js +88 -0
  35. package/build/commands/db-pull/util/renderModel.relations.test.d.ts +1 -0
  36. package/build/commands/db-pull/util/renderModel.relations.test.js +880 -0
  37. package/build/commands/db-pull/util/renderModel.types.test.d.ts +1 -0
  38. package/build/commands/db-pull/util/renderModel.types.test.js +703 -0
  39. package/build/commands/db-pull/util/renderRelations.d.ts +2 -0
  40. package/build/commands/db-pull/util/renderRelations.js +55 -0
  41. package/build/commands/db-pull/util/renderRelations.test.d.ts +1 -0
  42. package/build/commands/db-pull/util/renderRelations.test.js +165 -0
  43. package/build/commands/db-pull/util/renderType.d.ts +6 -0
  44. package/build/commands/db-pull/util/renderType.js +55 -0
  45. package/build/commands/db-pull/util/renderType.test.d.ts +1 -0
  46. package/build/commands/db-pull/util/renderType.test.js +46 -0
  47. package/build/commands/db-pull.d.ts +30 -0
  48. package/build/commands/db-pull.js +8 -0
  49. package/build/commands/db-pull.test.d.ts +1 -0
  50. package/build/commands/db-pull.test.js +633 -0
  51. package/build/commands/db-push/handler.d.ts +3 -0
  52. package/build/commands/db-push/handler.js +14 -0
  53. package/build/commands/db-push/options.d.ts +2 -0
  54. package/build/commands/db-push/options.js +1 -0
  55. package/build/commands/db-push.d.ts +6 -0
  56. package/build/commands/db-push.js +8 -0
  57. package/build/commands/db-push.test.d.ts +1 -0
  58. package/build/commands/db-push.test.js +21 -0
  59. package/build/commands/generate-model/handler.d.ts +3 -0
  60. package/build/commands/generate-model/handler.js +18 -0
  61. package/build/commands/generate-model/options.d.ts +7 -0
  62. package/build/commands/generate-model/options.js +7 -0
  63. package/build/commands/generate-model.d.ts +18 -0
  64. package/build/commands/generate-model.js +8 -0
  65. package/build/commands/generate-model.test.d.ts +1 -0
  66. package/build/commands/generate-model.test.js +58 -0
  67. package/build/commands/init/handler.d.ts +3 -0
  68. package/build/commands/init/handler.js +22 -0
  69. package/build/commands/init/options.d.ts +12 -0
  70. package/build/commands/init/options.js +12 -0
  71. package/build/commands/init.d.ts +28 -0
  72. package/build/commands/init.js +8 -0
  73. package/build/commands/init.test.d.ts +1 -0
  74. package/build/commands/init.test.js +125 -0
  75. package/build/generators/generateConfigFile.d.ts +1 -0
  76. package/build/generators/generateConfigFile.js +16 -0
  77. package/build/generators/generateDbFile.d.ts +1 -0
  78. package/build/generators/generateDbFile.js +37 -0
  79. package/build/generators/generateModelFile.d.ts +1 -0
  80. package/build/generators/generateModelFile.js +11 -0
  81. package/build/generators/generateModelFile.test.d.ts +1 -0
  82. package/build/generators/generateModelFile.test.js +19 -0
  83. package/build/generators/generateModelsFile.d.ts +1 -0
  84. package/build/generators/generateModelsFile.js +8 -0
  85. package/build/index.d.ts +1 -0
  86. package/build/index.js +1 -0
  87. package/build/options.d.ts +12 -0
  88. package/build/options.js +12 -0
  89. package/build/test/setup.d.ts +1 -0
  90. package/build/test/setup.js +35 -0
  91. package/build/types.d.ts +14 -0
  92. package/build/types.js +1 -0
  93. package/build/util/createOrOverwriteFile.d.ts +1 -0
  94. package/build/util/createOrOverwriteFile.js +17 -0
  95. package/build/util/loadConfig.d.ts +3 -0
  96. package/build/util/loadConfig.js +21 -0
  97. package/build/util/prettify.d.ts +1 -0
  98. package/build/util/prettify.js +8 -0
  99. package/package.json +70 -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/orm";
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/orm";
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/orm";
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
+ });