@casekit/orm2-cli 0.0.0-20250331181319 → 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.
- package/build/cli.js +1 -2
- package/build/commands/db-drop/handler.js +0 -3
- package/build/commands/db-drop.test.js +1 -0
- package/build/commands/db-pull/handler.js +21 -8
- package/build/commands/db-pull/options.d.ts +5 -0
- package/build/commands/db-pull/options.js +5 -0
- package/build/commands/db-pull/util/relationNames.d.ts +3 -0
- package/build/commands/db-pull/util/relationNames.js +14 -0
- package/build/commands/db-pull/util/relationNames.test.js +61 -0
- package/build/commands/db-pull/util/renderDefault.d.ts +3 -0
- package/build/commands/db-pull/util/renderDefault.js +46 -0
- package/build/commands/db-pull/util/renderDefault.test.d.ts +1 -0
- package/build/commands/db-pull/util/renderDefault.test.js +67 -0
- package/build/commands/db-pull/util/renderFieldDefinition.d.ts +2 -0
- package/build/commands/db-pull/util/renderFieldDefinition.js +50 -0
- package/build/commands/db-pull/util/renderFieldDefinition.test.d.ts +1 -0
- package/build/commands/db-pull/util/renderFieldDefinition.test.js +182 -0
- package/build/commands/db-pull/util/renderModel.basic.test.d.ts +1 -0
- package/build/commands/db-pull/util/renderModel.basic.test.js +169 -0
- package/build/commands/db-pull/util/renderModel.constraints.test.d.ts +1 -0
- package/build/commands/db-pull/util/renderModel.constraints.test.js +677 -0
- package/build/commands/db-pull/util/renderModel.d.ts +2 -0
- package/build/commands/db-pull/util/renderModel.defaultValues.test.d.ts +1 -0
- package/build/commands/db-pull/util/renderModel.defaultValues.test.js +518 -0
- package/build/commands/db-pull/util/renderModel.js +88 -0
- package/build/commands/db-pull/util/renderModel.relations.test.d.ts +1 -0
- package/build/commands/db-pull/util/renderModel.relations.test.js +880 -0
- package/build/commands/db-pull/util/renderModel.types.test.d.ts +1 -0
- package/build/commands/db-pull/util/renderModel.types.test.js +703 -0
- package/build/commands/db-pull/util/renderRelations.d.ts +2 -0
- package/build/commands/db-pull/util/renderRelations.js +55 -0
- package/build/commands/db-pull/util/renderRelations.test.d.ts +1 -0
- package/build/commands/db-pull/util/renderRelations.test.js +165 -0
- package/build/commands/db-pull/util/renderType.d.ts +6 -0
- package/build/commands/db-pull/util/renderType.js +55 -0
- package/build/commands/db-pull/util/renderType.test.d.ts +1 -0
- package/build/commands/db-pull/util/renderType.test.js +46 -0
- package/build/commands/db-pull.d.ts +10 -0
- package/build/commands/db-pull.test.js +625 -0
- package/build/commands/db-push/handler.js +0 -3
- package/build/commands/init/handler.js +16 -3
- package/build/commands/init/util/generateConfigFile.js +2 -3
- package/build/commands/init/util/generateDbFile.js +13 -24
- package/build/commands/init/util/generateModelsFile.d.ts +1 -1
- package/build/commands/init/util/generateModelsFile.js +6 -2
- package/build/commands/init.test.js +19 -31
- package/build/types.d.ts +2 -2
- package/build/util/createOrOverwriteFile.d.ts +1 -1
- package/build/util/createOrOverwriteFile.js +1 -1
- package/build/util/loadConfig.js +5 -1
- package/package.json +26 -25
- package/build/commands/generate-model/handler.d.ts +0 -3
- package/build/commands/generate-model/handler.js +0 -10
- package/build/commands/generate-model/options.d.ts +0 -18
- package/build/commands/generate-model/options.js +0 -18
- package/build/commands/generate-model/util/generateModelFile.d.ts +0 -3
- package/build/commands/generate-model/util/generateModelFile.js +0 -59
- package/build/commands/generate-model/util/generateModelFile.test.js +0 -67
- package/build/commands/generate-model/util/regenerateModelsFile.d.ts +0 -2
- package/build/commands/generate-model/util/regenerateModelsFile.js +0 -50
- package/build/commands/generate-model.d.ts +0 -40
- package/build/commands/generate-model.js +0 -8
- package/build/commands/generate-model.test.js +0 -55
- /package/build/commands/{generate-model/util/generateModelFile.test.d.ts → db-pull/util/relationNames.test.d.ts} +0 -0
- /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
|
-
});
|
|
File without changes
|
|
File without changes
|