@casekit/orm2-cli 0.0.0-20250331202540 → 1.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
@@ -1,55 +0,0 @@
1
- import * as prompts from "@inquirer/prompts";
2
- import fs from "fs";
3
- import { vol } from "memfs";
4
- import { beforeEach, describe, expect, test, vi } from "vitest";
5
- import yargs from "yargs";
6
- import { unindent } from "@casekit/unindent";
7
- import { globalOptions } from "#options.js";
8
- import { generateModel } from "./generate-model.js";
9
- describe("orm generate model", () => {
10
- beforeEach(() => {
11
- vi.spyOn(process, "cwd").mockReturnValue(".");
12
- });
13
- beforeEach(() => {
14
- vol.fromJSON({
15
- "app/db.server/models/index.ts": unindent `
16
- import { user } from "./user";
17
-
18
- export const models = {
19
- user
20
- };
21
- `,
22
- }, "/project");
23
- });
24
- test("it generates a model file merging the template and provided fields", async () => {
25
- vi.spyOn(prompts, "confirm").mockResolvedValue(true);
26
- vi.spyOn(process, "cwd").mockReturnValue("/project");
27
- await yargs()
28
- .options(globalOptions)
29
- .command(generateModel)
30
- .parseAsync("model --name post --fields title:text content:text");
31
- const modelFile = fs.readFileSync("./app/db.server/models/post.ts", "utf8");
32
- expect(modelFile.trim()).toEqual(unindent `
33
- import { ModelDefinition, sql } from "@casekit/orm2";
34
-
35
- export const post = {
36
- fields: {
37
- id: { type: "uuid", primaryKey: true },
38
- createdAt: { type: "timestamp", default: sql\`now()\` },
39
- title: { type: "text" },
40
- content: { type: "text" },
41
- },
42
- } as const satisfies ModelDefinition;
43
- `);
44
- const indexFile = fs.readFileSync("./app/db.server/models/index.ts", "utf8");
45
- expect(indexFile.trim()).toEqual(unindent `
46
- import { post } from "./post";
47
- import { user } from "./user";
48
-
49
- export const models = {
50
- user,
51
- post,
52
- };
53
- `);
54
- });
55
- });