@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,703 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { unindent } from "@casekit/unindent";
3
+ import { renderModel } from "./renderModel.js";
4
+ describe("renderModel - types", () => {
5
+ it("handles basic PostgreSQL types", async () => {
6
+ const table = {
7
+ schema: "public",
8
+ name: "types_test",
9
+ columns: [
10
+ {
11
+ schema: "public",
12
+ table: "types_test",
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: "types_test",
29
+ column: "small_num",
30
+ ordinalPosition: 2,
31
+ type: "smallint",
32
+ default: null,
33
+ nullable: false,
34
+ udtSchema: "pg_catalog",
35
+ udt: "int2",
36
+ elementType: null,
37
+ elementTypeSchema: null,
38
+ cardinality: 0,
39
+ size: null,
40
+ isSerial: false,
41
+ },
42
+ {
43
+ schema: "public",
44
+ table: "types_test",
45
+ column: "big_num",
46
+ ordinalPosition: 3,
47
+ type: "bigint",
48
+ default: null,
49
+ nullable: false,
50
+ udtSchema: "pg_catalog",
51
+ udt: "int8",
52
+ elementType: null,
53
+ elementTypeSchema: null,
54
+ cardinality: 0,
55
+ size: null,
56
+ isSerial: false,
57
+ },
58
+ {
59
+ schema: "public",
60
+ table: "types_test",
61
+ column: "price",
62
+ ordinalPosition: 4,
63
+ type: "numeric",
64
+ default: null,
65
+ nullable: false,
66
+ udtSchema: "pg_catalog",
67
+ udt: "numeric",
68
+ elementType: null,
69
+ elementTypeSchema: null,
70
+ cardinality: 0,
71
+ size: null,
72
+ isSerial: false,
73
+ },
74
+ {
75
+ schema: "public",
76
+ table: "types_test",
77
+ column: "rating",
78
+ ordinalPosition: 5,
79
+ type: "real",
80
+ default: null,
81
+ nullable: false,
82
+ udtSchema: "pg_catalog",
83
+ udt: "float4",
84
+ elementType: null,
85
+ elementTypeSchema: null,
86
+ cardinality: 0,
87
+ size: null,
88
+ isSerial: false,
89
+ },
90
+ ],
91
+ foreignKeys: [],
92
+ primaryKey: null,
93
+ uniqueConstraints: [],
94
+ };
95
+ const result = await renderModel(table, []);
96
+ expect(result.trim()).toBe(unindent `
97
+ import { type ModelDefinition } from "@casekit/orm2";
98
+
99
+ export const typesTest = {
100
+ table: "types_test",
101
+ fields: {
102
+ id: { type: "integer" },
103
+ smallNum: { column: "small_num", type: "smallint" },
104
+ bigNum: { column: "big_num", type: "bigint" },
105
+ price: { type: "numeric" },
106
+ rating: { type: "real" },
107
+ },
108
+ } as const satisfies ModelDefinition;
109
+ `);
110
+ });
111
+ it("handles character and text types", async () => {
112
+ const table = {
113
+ schema: "public",
114
+ name: "text_test",
115
+ columns: [
116
+ {
117
+ schema: "public",
118
+ table: "text_test",
119
+ column: "id",
120
+ ordinalPosition: 1,
121
+ type: "integer",
122
+ default: null,
123
+ nullable: false,
124
+ udtSchema: "pg_catalog",
125
+ udt: "int4",
126
+ elementType: null,
127
+ elementTypeSchema: null,
128
+ cardinality: 0,
129
+ size: null,
130
+ isSerial: false,
131
+ },
132
+ {
133
+ schema: "public",
134
+ table: "text_test",
135
+ column: "description",
136
+ ordinalPosition: 2,
137
+ type: "text",
138
+ default: null,
139
+ nullable: false,
140
+ udtSchema: "pg_catalog",
141
+ udt: "text",
142
+ elementType: null,
143
+ elementTypeSchema: null,
144
+ cardinality: 0,
145
+ size: null,
146
+ isSerial: false,
147
+ },
148
+ {
149
+ schema: "public",
150
+ table: "text_test",
151
+ column: "name",
152
+ ordinalPosition: 3,
153
+ type: "character varying",
154
+ default: null,
155
+ nullable: false,
156
+ udtSchema: "pg_catalog",
157
+ udt: "varchar",
158
+ elementType: null,
159
+ elementTypeSchema: null,
160
+ cardinality: 0,
161
+ size: 100,
162
+ isSerial: false,
163
+ },
164
+ {
165
+ schema: "public",
166
+ table: "text_test",
167
+ column: "code",
168
+ ordinalPosition: 4,
169
+ type: "character",
170
+ default: null,
171
+ nullable: false,
172
+ udtSchema: "pg_catalog",
173
+ udt: "bpchar",
174
+ elementType: null,
175
+ elementTypeSchema: null,
176
+ cardinality: 0,
177
+ size: 10,
178
+ isSerial: false,
179
+ },
180
+ ],
181
+ foreignKeys: [],
182
+ primaryKey: null,
183
+ uniqueConstraints: [],
184
+ };
185
+ const result = await renderModel(table, []);
186
+ expect(result.trim()).toBe(unindent `
187
+ import { type ModelDefinition } from "@casekit/orm2";
188
+
189
+ export const textTest = {
190
+ table: "text_test",
191
+ fields: {
192
+ id: { type: "integer" },
193
+ description: { type: "text" },
194
+ name: { type: "character varying" },
195
+ code: { type: "character" },
196
+ },
197
+ } as const satisfies ModelDefinition;
198
+ `);
199
+ });
200
+ it("handles date and time types", async () => {
201
+ const table = {
202
+ schema: "public",
203
+ name: "time_test",
204
+ columns: [
205
+ {
206
+ schema: "public",
207
+ table: "time_test",
208
+ column: "id",
209
+ ordinalPosition: 1,
210
+ type: "integer",
211
+ default: null,
212
+ nullable: false,
213
+ udtSchema: "pg_catalog",
214
+ udt: "int4",
215
+ elementType: null,
216
+ elementTypeSchema: null,
217
+ cardinality: 0,
218
+ size: null,
219
+ isSerial: false,
220
+ },
221
+ {
222
+ schema: "public",
223
+ table: "time_test",
224
+ column: "birthday",
225
+ ordinalPosition: 2,
226
+ type: "date",
227
+ default: null,
228
+ nullable: false,
229
+ udtSchema: "pg_catalog",
230
+ udt: "date",
231
+ elementType: null,
232
+ elementTypeSchema: null,
233
+ cardinality: 0,
234
+ size: null,
235
+ isSerial: false,
236
+ },
237
+ {
238
+ schema: "public",
239
+ table: "time_test",
240
+ column: "created_at",
241
+ ordinalPosition: 3,
242
+ type: "timestamp without time zone",
243
+ default: null,
244
+ nullable: false,
245
+ udtSchema: "pg_catalog",
246
+ udt: "timestamp",
247
+ elementType: null,
248
+ elementTypeSchema: null,
249
+ cardinality: 0,
250
+ size: null,
251
+ isSerial: false,
252
+ },
253
+ {
254
+ schema: "public",
255
+ table: "time_test",
256
+ column: "updated_at",
257
+ ordinalPosition: 4,
258
+ type: "timestamp with time zone",
259
+ default: null,
260
+ nullable: false,
261
+ udtSchema: "pg_catalog",
262
+ udt: "timestamptz",
263
+ elementType: null,
264
+ elementTypeSchema: null,
265
+ cardinality: 0,
266
+ size: null,
267
+ isSerial: false,
268
+ },
269
+ {
270
+ schema: "public",
271
+ table: "time_test",
272
+ column: "lunch_time",
273
+ ordinalPosition: 5,
274
+ type: "time without time zone",
275
+ default: null,
276
+ nullable: false,
277
+ udtSchema: "pg_catalog",
278
+ udt: "time",
279
+ elementType: null,
280
+ elementTypeSchema: null,
281
+ cardinality: 0,
282
+ size: null,
283
+ isSerial: false,
284
+ },
285
+ {
286
+ schema: "public",
287
+ table: "time_test",
288
+ column: "meeting_time",
289
+ ordinalPosition: 6,
290
+ type: "time with time zone",
291
+ default: null,
292
+ nullable: false,
293
+ udtSchema: "pg_catalog",
294
+ udt: "timetz",
295
+ elementType: null,
296
+ elementTypeSchema: null,
297
+ cardinality: 0,
298
+ size: null,
299
+ isSerial: false,
300
+ },
301
+ ],
302
+ foreignKeys: [],
303
+ primaryKey: null,
304
+ uniqueConstraints: [],
305
+ };
306
+ const result = await renderModel(table, []);
307
+ expect(result.trim()).toBe(unindent `
308
+ import { type ModelDefinition } from "@casekit/orm2";
309
+
310
+ export const timeTest = {
311
+ table: "time_test",
312
+ fields: {
313
+ id: { type: "integer" },
314
+ birthday: { type: "date" },
315
+ createdAt: {
316
+ column: "created_at",
317
+ type: "timestamp without time zone",
318
+ },
319
+ updatedAt: { column: "updated_at", type: "timestamp with time zone" },
320
+ lunchTime: { column: "lunch_time", type: "time without time zone" },
321
+ meetingTime: { column: "meeting_time", type: "time with time zone" },
322
+ },
323
+ } as const satisfies ModelDefinition;
324
+ `);
325
+ });
326
+ it("handles array types", async () => {
327
+ const table = {
328
+ schema: "public",
329
+ name: "array_test",
330
+ columns: [
331
+ {
332
+ schema: "public",
333
+ table: "array_test",
334
+ column: "id",
335
+ ordinalPosition: 1,
336
+ type: "integer",
337
+ default: null,
338
+ nullable: false,
339
+ udtSchema: "pg_catalog",
340
+ udt: "int4",
341
+ elementType: null,
342
+ elementTypeSchema: null,
343
+ cardinality: 0,
344
+ size: null,
345
+ isSerial: false,
346
+ },
347
+ {
348
+ schema: "public",
349
+ table: "array_test",
350
+ column: "tags",
351
+ ordinalPosition: 2,
352
+ type: "ARRAY",
353
+ default: null,
354
+ nullable: false,
355
+ udtSchema: "pg_catalog",
356
+ udt: "_text",
357
+ elementType: "text",
358
+ elementTypeSchema: "pg_catalog",
359
+ cardinality: 1,
360
+ size: null,
361
+ isSerial: false,
362
+ },
363
+ {
364
+ schema: "public",
365
+ table: "array_test",
366
+ column: "numbers",
367
+ ordinalPosition: 3,
368
+ type: "ARRAY",
369
+ default: null,
370
+ nullable: false,
371
+ udtSchema: "pg_catalog",
372
+ udt: "_int4",
373
+ elementType: "integer",
374
+ elementTypeSchema: "pg_catalog",
375
+ cardinality: 1,
376
+ size: null,
377
+ isSerial: false,
378
+ },
379
+ {
380
+ schema: "public",
381
+ table: "array_test",
382
+ column: "matrix",
383
+ ordinalPosition: 4,
384
+ type: "ARRAY",
385
+ default: null,
386
+ nullable: false,
387
+ udtSchema: "pg_catalog",
388
+ udt: "_int4",
389
+ elementType: "integer",
390
+ elementTypeSchema: "pg_catalog",
391
+ cardinality: 2,
392
+ size: null,
393
+ isSerial: false,
394
+ },
395
+ {
396
+ schema: "public",
397
+ table: "array_test",
398
+ column: "cube",
399
+ ordinalPosition: 5,
400
+ type: "ARRAY",
401
+ default: null,
402
+ nullable: false,
403
+ udtSchema: "pg_catalog",
404
+ udt: "_text",
405
+ elementType: "text",
406
+ elementTypeSchema: "pg_catalog",
407
+ cardinality: 3,
408
+ size: null,
409
+ isSerial: false,
410
+ },
411
+ ],
412
+ foreignKeys: [],
413
+ primaryKey: null,
414
+ uniqueConstraints: [],
415
+ };
416
+ const result = await renderModel(table, []);
417
+ expect(result.trim()).toBe(unindent `
418
+ import { type ModelDefinition } from "@casekit/orm2";
419
+
420
+ export const arrayTest = {
421
+ table: "array_test",
422
+ fields: {
423
+ id: { type: "integer" },
424
+ tags: { type: "text[]" },
425
+ numbers: { type: "integer[]" },
426
+ matrix: { type: "integer[][]" },
427
+ cube: { type: "text[][][]" },
428
+ },
429
+ } as const satisfies ModelDefinition;
430
+ `);
431
+ });
432
+ it("handles JSON and UUID types", async () => {
433
+ const table = {
434
+ schema: "public",
435
+ name: "special_test",
436
+ columns: [
437
+ {
438
+ schema: "public",
439
+ table: "special_test",
440
+ column: "id",
441
+ ordinalPosition: 1,
442
+ type: "uuid",
443
+ default: null,
444
+ nullable: false,
445
+ udtSchema: "pg_catalog",
446
+ udt: "uuid",
447
+ elementType: null,
448
+ elementTypeSchema: null,
449
+ cardinality: 0,
450
+ size: null,
451
+ isSerial: false,
452
+ },
453
+ {
454
+ schema: "public",
455
+ table: "special_test",
456
+ column: "metadata",
457
+ ordinalPosition: 2,
458
+ type: "json",
459
+ default: null,
460
+ nullable: false,
461
+ udtSchema: "pg_catalog",
462
+ udt: "json",
463
+ elementType: null,
464
+ elementTypeSchema: null,
465
+ cardinality: 0,
466
+ size: null,
467
+ isSerial: false,
468
+ },
469
+ {
470
+ schema: "public",
471
+ table: "special_test",
472
+ column: "settings",
473
+ ordinalPosition: 3,
474
+ type: "jsonb",
475
+ default: null,
476
+ nullable: false,
477
+ udtSchema: "pg_catalog",
478
+ udt: "jsonb",
479
+ elementType: null,
480
+ elementTypeSchema: null,
481
+ cardinality: 0,
482
+ size: null,
483
+ isSerial: false,
484
+ },
485
+ {
486
+ schema: "public",
487
+ table: "special_test",
488
+ column: "is_active",
489
+ ordinalPosition: 4,
490
+ type: "boolean",
491
+ default: null,
492
+ nullable: false,
493
+ udtSchema: "pg_catalog",
494
+ udt: "bool",
495
+ elementType: null,
496
+ elementTypeSchema: null,
497
+ cardinality: 0,
498
+ size: null,
499
+ isSerial: false,
500
+ },
501
+ ],
502
+ foreignKeys: [],
503
+ primaryKey: null,
504
+ uniqueConstraints: [],
505
+ };
506
+ const result = await renderModel(table, []);
507
+ expect(result.trim()).toBe(unindent `
508
+ import { type ModelDefinition } from "@casekit/orm2";
509
+
510
+ export const specialTest = {
511
+ table: "special_test",
512
+ fields: {
513
+ id: { type: "uuid" },
514
+ metadata: { type: "json" },
515
+ settings: { type: "jsonb" },
516
+ isActive: { column: "is_active", type: "boolean" },
517
+ },
518
+ } as const satisfies ModelDefinition;
519
+ `);
520
+ });
521
+ it("handles double precision type mapping", async () => {
522
+ const table = {
523
+ schema: "public",
524
+ name: "precision_test",
525
+ columns: [
526
+ {
527
+ schema: "public",
528
+ table: "precision_test",
529
+ column: "id",
530
+ ordinalPosition: 1,
531
+ type: "integer",
532
+ default: null,
533
+ nullable: false,
534
+ udtSchema: "pg_catalog",
535
+ udt: "int4",
536
+ elementType: null,
537
+ elementTypeSchema: null,
538
+ cardinality: 0,
539
+ size: null,
540
+ isSerial: false,
541
+ },
542
+ {
543
+ schema: "public",
544
+ table: "precision_test",
545
+ column: "precise_value",
546
+ ordinalPosition: 2,
547
+ type: "double precision",
548
+ default: null,
549
+ nullable: false,
550
+ udtSchema: "pg_catalog",
551
+ udt: "float8",
552
+ elementType: null,
553
+ elementTypeSchema: null,
554
+ cardinality: 0,
555
+ size: null,
556
+ isSerial: false,
557
+ },
558
+ ],
559
+ foreignKeys: [],
560
+ primaryKey: null,
561
+ uniqueConstraints: [],
562
+ };
563
+ const result = await renderModel(table, []);
564
+ expect(result.trim()).toBe(unindent `
565
+ import { type ModelDefinition } from "@casekit/orm2";
566
+
567
+ export const precisionTest = {
568
+ table: "precision_test",
569
+ fields: {
570
+ id: { type: "integer" },
571
+ preciseValue: { column: "precise_value", type: "double precision" },
572
+ },
573
+ } as const satisfies ModelDefinition;
574
+ `);
575
+ });
576
+ it("handles custom enum types", async () => {
577
+ const table = {
578
+ schema: "public",
579
+ name: "enum_test",
580
+ columns: [
581
+ {
582
+ schema: "public",
583
+ table: "enum_test",
584
+ column: "id",
585
+ ordinalPosition: 1,
586
+ type: "integer",
587
+ default: null,
588
+ nullable: false,
589
+ udtSchema: "pg_catalog",
590
+ udt: "int4",
591
+ elementType: null,
592
+ elementTypeSchema: null,
593
+ cardinality: 0,
594
+ size: null,
595
+ isSerial: false,
596
+ },
597
+ {
598
+ schema: "public",
599
+ table: "enum_test",
600
+ column: "status",
601
+ ordinalPosition: 2,
602
+ type: "USER-DEFINED",
603
+ default: null,
604
+ nullable: false,
605
+ udtSchema: "public",
606
+ udt: "status_enum",
607
+ elementType: null,
608
+ elementTypeSchema: null,
609
+ cardinality: 0,
610
+ size: null,
611
+ isSerial: false,
612
+ },
613
+ {
614
+ schema: "public",
615
+ table: "enum_test",
616
+ column: "priority",
617
+ ordinalPosition: 3,
618
+ type: "USER-DEFINED",
619
+ default: null,
620
+ nullable: false,
621
+ udtSchema: "my_schema",
622
+ udt: "priority_level",
623
+ elementType: null,
624
+ elementTypeSchema: null,
625
+ cardinality: 0,
626
+ size: null,
627
+ isSerial: false,
628
+ },
629
+ ],
630
+ foreignKeys: [],
631
+ primaryKey: null,
632
+ uniqueConstraints: [],
633
+ };
634
+ const result = await renderModel(table, []);
635
+ expect(result.trim()).toBe(unindent `
636
+ import { type ModelDefinition } from "@casekit/orm2";
637
+
638
+ export const enumTest = {
639
+ table: "enum_test",
640
+ fields: {
641
+ id: { type: "integer" },
642
+ status: { type: "USER-DEFINED" },
643
+ priority: { type: "USER-DEFINED" },
644
+ },
645
+ } as const satisfies ModelDefinition;
646
+ `);
647
+ });
648
+ it("handles array type with missing cardinality", async () => {
649
+ const table = {
650
+ schema: "public",
651
+ name: "array_fallback_test",
652
+ columns: [
653
+ {
654
+ schema: "public",
655
+ table: "array_fallback_test",
656
+ column: "id",
657
+ ordinalPosition: 1,
658
+ type: "integer",
659
+ default: null,
660
+ nullable: false,
661
+ udtSchema: "pg_catalog",
662
+ udt: "int4",
663
+ elementType: null,
664
+ elementTypeSchema: null,
665
+ cardinality: 0,
666
+ size: null,
667
+ isSerial: false,
668
+ },
669
+ {
670
+ schema: "public",
671
+ table: "array_fallback_test",
672
+ column: "items",
673
+ ordinalPosition: 2,
674
+ type: "ARRAY",
675
+ default: null,
676
+ nullable: false,
677
+ udtSchema: "pg_catalog",
678
+ udt: "_text",
679
+ elementType: "text",
680
+ elementTypeSchema: "pg_catalog",
681
+ cardinality: 1, // Fixed cardinality
682
+ size: null,
683
+ isSerial: false,
684
+ },
685
+ ],
686
+ foreignKeys: [],
687
+ primaryKey: null,
688
+ uniqueConstraints: [],
689
+ };
690
+ const result = await renderModel(table, []);
691
+ expect(result.trim()).toBe(unindent `
692
+ import { type ModelDefinition } from "@casekit/orm2";
693
+
694
+ export const arrayFallbackTest = {
695
+ table: "array_fallback_test",
696
+ fields: {
697
+ id: { type: "integer" },
698
+ items: { type: "text[]" },
699
+ },
700
+ } as const satisfies ModelDefinition;
701
+ `);
702
+ });
703
+ });