swallowkit 0.4.0-beta.3 → 1.0.0-beta.10
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/LICENSE +21 -21
- package/README.ja.md +254 -183
- package/README.md +311 -184
- package/dist/__tests__/fixtures.d.ts +14 -0
- package/dist/__tests__/fixtures.d.ts.map +1 -0
- package/dist/__tests__/fixtures.js +85 -0
- package/dist/__tests__/fixtures.js.map +1 -0
- package/dist/cli/commands/create-model.d.ts.map +1 -1
- package/dist/cli/commands/create-model.js +16 -15
- package/dist/cli/commands/create-model.js.map +1 -1
- package/dist/cli/commands/dev-seeds.d.ts +35 -0
- package/dist/cli/commands/dev-seeds.d.ts.map +1 -0
- package/dist/cli/commands/dev-seeds.js +292 -0
- package/dist/cli/commands/dev-seeds.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +8 -0
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +308 -87
- package/dist/cli/commands/dev.js.map +1 -1
- package/dist/cli/commands/index.d.ts +1 -0
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +3 -1
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/init.d.ts +13 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +2639 -1708
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/scaffold.d.ts +3 -0
- package/dist/cli/commands/scaffold.d.ts.map +1 -1
- package/dist/cli/commands/scaffold.js +283 -118
- package/dist/cli/commands/scaffold.js.map +1 -1
- package/dist/cli/index.js +17 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/core/config.d.ts +2 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +31 -1
- package/dist/core/config.js.map +1 -1
- package/dist/core/scaffold/functions-generator.d.ts +5 -0
- package/dist/core/scaffold/functions-generator.d.ts.map +1 -1
- package/dist/core/scaffold/functions-generator.js +649 -211
- package/dist/core/scaffold/functions-generator.js.map +1 -1
- package/dist/core/scaffold/model-parser.d.ts +1 -1
- package/dist/core/scaffold/model-parser.d.ts.map +1 -1
- package/dist/core/scaffold/model-parser.js +105 -101
- package/dist/core/scaffold/model-parser.js.map +1 -1
- package/dist/core/scaffold/nextjs-generator.js +181 -181
- package/dist/core/scaffold/openapi-generator.d.ts +3 -0
- package/dist/core/scaffold/openapi-generator.d.ts.map +1 -0
- package/dist/core/scaffold/openapi-generator.js +190 -0
- package/dist/core/scaffold/openapi-generator.js.map +1 -0
- package/dist/core/scaffold/ui-generator.js +656 -656
- package/dist/database/base-model.d.ts +3 -3
- package/dist/database/base-model.js +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/package-manager.d.ts +109 -0
- package/dist/utils/package-manager.d.ts.map +1 -0
- package/dist/utils/package-manager.js +215 -0
- package/dist/utils/package-manager.js.map +1 -0
- package/package.json +81 -73
- package/src/__tests__/__snapshots__/functions-generator.test.ts.snap +445 -0
- package/src/__tests__/__snapshots__/nextjs-generator.test.ts.snap +194 -0
- package/src/__tests__/__snapshots__/ui-generator.test.ts.snap +524 -0
- package/src/__tests__/config.test.ts +122 -0
- package/src/__tests__/dev-seeds.test.ts +112 -0
- package/src/__tests__/dev.test.ts +42 -0
- package/src/__tests__/fixtures.ts +83 -0
- package/src/__tests__/functions-generator.test.ts +101 -0
- package/src/__tests__/init.test.ts +80 -0
- package/src/__tests__/nextjs-generator.test.ts +97 -0
- package/src/__tests__/openapi-generator.test.ts +43 -0
- package/src/__tests__/package-manager.test.ts +189 -0
- package/src/__tests__/scaffold.test.ts +39 -0
- package/src/__tests__/string-utils.test.ts +75 -0
- package/src/__tests__/ui-generator.test.ts +144 -0
- package/src/cli/commands/create-model.ts +141 -0
- package/src/cli/commands/dev-seeds.ts +358 -0
- package/src/cli/commands/dev.ts +805 -0
- package/src/cli/commands/index.ts +9 -0
- package/src/cli/commands/init.ts +3370 -0
- package/src/cli/commands/provision.ts +193 -0
- package/src/cli/commands/scaffold.ts +786 -0
- package/src/cli/index.ts +74 -0
- package/src/core/config.ts +244 -0
- package/src/core/scaffold/functions-generator.ts +674 -0
- package/src/core/scaffold/model-parser.ts +627 -0
- package/src/core/scaffold/nextjs-generator.ts +217 -0
- package/src/core/scaffold/openapi-generator.ts +212 -0
- package/src/core/scaffold/ui-generator.ts +945 -0
- package/src/database/base-model.ts +184 -0
- package/src/database/client.ts +140 -0
- package/src/database/repository.ts +104 -0
- package/src/database/runtime-check.ts +25 -0
- package/src/index.ts +27 -0
- package/src/types/index.ts +45 -0
- package/src/utils/package-manager.ts +229 -0
- package/dist/cli/commands/build.d.ts +0 -6
- package/dist/cli/commands/build.d.ts.map +0 -1
- package/dist/cli/commands/build.js +0 -177
- package/dist/cli/commands/build.js.map +0 -1
- package/dist/cli/commands/deploy.d.ts +0 -3
- package/dist/cli/commands/deploy.d.ts.map +0 -1
- package/dist/cli/commands/deploy.js +0 -147
- package/dist/cli/commands/deploy.js.map +0 -1
- package/dist/cli/commands/setup.d.ts +0 -6
- package/dist/cli/commands/setup.d.ts.map +0 -1
- package/dist/cli/commands/setup.js +0 -254
- package/dist/cli/commands/setup.js.map +0 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as os from "os";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { createBasicModelInfo } from "./fixtures";
|
|
5
|
+
import {
|
|
6
|
+
buildSeedTemplateDocument,
|
|
7
|
+
getContainerNameForModel,
|
|
8
|
+
loadDevSeedFiles,
|
|
9
|
+
normalizeSeedIdentifier,
|
|
10
|
+
parseSeedDocuments,
|
|
11
|
+
} from "../cli/commands/dev-seeds";
|
|
12
|
+
|
|
13
|
+
describe("dev seed helpers", () => {
|
|
14
|
+
const originalCwd = process.cwd();
|
|
15
|
+
let tempDir: string;
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "swallowkit-dev-seeds-"));
|
|
19
|
+
process.chdir(tempDir);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
process.chdir(originalCwd);
|
|
24
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("builds Cosmos container names from model names", () => {
|
|
28
|
+
expect(getContainerNameForModel(createBasicModelInfo())).toBe("Todos");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("normalizes seed identifiers across common naming styles", () => {
|
|
32
|
+
expect(normalizeSeedIdentifier("todo-items")).toBe("todoitems");
|
|
33
|
+
expect(normalizeSeedIdentifier("Todo_Items")).toBe("todoitems");
|
|
34
|
+
expect(normalizeSeedIdentifier("todoSchema")).toBe("todoschema");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("wraps a single JSON object into a document array", () => {
|
|
38
|
+
expect(parseSeedDocuments('{"id":"todo-001","title":"Hello"}', "todo.json")).toEqual([
|
|
39
|
+
{ id: "todo-001", title: "Hello" },
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("loads matching seed files for an environment", async () => {
|
|
44
|
+
const seedsDir = path.join(tempDir, "dev-seeds", "local");
|
|
45
|
+
fs.mkdirSync(seedsDir, { recursive: true });
|
|
46
|
+
fs.writeFileSync(
|
|
47
|
+
path.join(seedsDir, "todo.json"),
|
|
48
|
+
JSON.stringify([{ id: "todo-001", title: "First task" }], null, 2),
|
|
49
|
+
"utf-8"
|
|
50
|
+
);
|
|
51
|
+
fs.writeFileSync(
|
|
52
|
+
path.join(seedsDir, "ignored.json"),
|
|
53
|
+
JSON.stringify([{ id: "ignored-001" }], null, 2),
|
|
54
|
+
"utf-8"
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const loaded = await loadDevSeedFiles("local", [createBasicModelInfo()]);
|
|
58
|
+
|
|
59
|
+
expect(loaded).toHaveLength(1);
|
|
60
|
+
expect(loaded[0]).toMatchObject({
|
|
61
|
+
containerName: "Todos",
|
|
62
|
+
documents: [{ id: "todo-001", title: "First task" }],
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("rejects seed documents without ids", async () => {
|
|
67
|
+
const seedsDir = path.join(tempDir, "dev-seeds", "local");
|
|
68
|
+
fs.mkdirSync(seedsDir, { recursive: true });
|
|
69
|
+
fs.writeFileSync(path.join(seedsDir, "todo.json"), JSON.stringify([{ title: "Missing id" }], null, 2), "utf-8");
|
|
70
|
+
|
|
71
|
+
await expect(loadDevSeedFiles("local", [createBasicModelInfo()])).rejects.toThrow(/non-empty string id/);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("builds nested template documents from related schemas", () => {
|
|
75
|
+
const category = createBasicModelInfo({
|
|
76
|
+
name: "Category",
|
|
77
|
+
displayName: "Category",
|
|
78
|
+
schemaName: "categorySchema",
|
|
79
|
+
filePath: "/models/category.ts",
|
|
80
|
+
fields: [
|
|
81
|
+
{ name: "id", type: "string", isOptional: false, isArray: false },
|
|
82
|
+
{ name: "name", type: "string", isOptional: false, isArray: false },
|
|
83
|
+
],
|
|
84
|
+
hasCreatedAt: false,
|
|
85
|
+
hasUpdatedAt: false,
|
|
86
|
+
});
|
|
87
|
+
const todo = createBasicModelInfo({
|
|
88
|
+
fields: [
|
|
89
|
+
{ name: "id", type: "string", isOptional: false, isArray: false },
|
|
90
|
+
{ name: "title", type: "string", isOptional: false, isArray: false },
|
|
91
|
+
{
|
|
92
|
+
name: "category",
|
|
93
|
+
type: "object",
|
|
94
|
+
isOptional: true,
|
|
95
|
+
isArray: false,
|
|
96
|
+
isNestedSchema: true,
|
|
97
|
+
nestedModelName: "Category",
|
|
98
|
+
nestedSchemaName: "categorySchema",
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
expect(buildSeedTemplateDocument(todo, [todo, category])).toEqual({
|
|
104
|
+
id: "todo-001",
|
|
105
|
+
title: "todo-title-sample",
|
|
106
|
+
category: {
|
|
107
|
+
id: "category-001",
|
|
108
|
+
name: "category-name-sample",
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import {
|
|
3
|
+
buildFunctionsStartArgs,
|
|
4
|
+
buildNextDevArgs,
|
|
5
|
+
buildPythonFunctionsEnv,
|
|
6
|
+
getPythonVirtualEnvPaths,
|
|
7
|
+
} from "../cli/commands/dev";
|
|
8
|
+
|
|
9
|
+
describe("dev command helpers", () => {
|
|
10
|
+
it("passes the requested port to Azure Functions Core Tools", () => {
|
|
11
|
+
expect(buildFunctionsStartArgs("7076")).toEqual(["start", "--port", "7076"]);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("uses webpack mode for npm-based Next.js dev", () => {
|
|
15
|
+
expect(buildNextDevArgs("npm", "3012")).toEqual(["next", "dev", "--port", "3012", "--webpack"]);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("uses pnpm exec for pnpm-based Next.js dev", () => {
|
|
19
|
+
expect(buildNextDevArgs("pnpm", "3012")).toEqual(["exec", "next", "dev", "--port", "3012", "--webpack"]);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("builds Python virtual environment paths under functions/.venv", () => {
|
|
23
|
+
const functionsDir = path.join("C:\\repo", "functions");
|
|
24
|
+
const paths = getPythonVirtualEnvPaths(functionsDir);
|
|
25
|
+
|
|
26
|
+
expect(paths.venvDir).toBe(path.join(functionsDir, ".venv"));
|
|
27
|
+
expect(paths.binDir.endsWith(process.platform === "win32" ? path.join(".venv", "Scripts") : path.join(".venv", "bin"))).toBe(true);
|
|
28
|
+
expect(paths.pythonExecutable.endsWith(process.platform === "win32" ? path.join("Scripts", "python.exe") : path.join("bin", "python"))).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("injects Python virtual environment settings for Functions", () => {
|
|
32
|
+
const functionsDir = path.join("C:\\repo", "functions");
|
|
33
|
+
const env = buildPythonFunctionsEnv({ PATH: "C:\\Windows\\System32" }, functionsDir);
|
|
34
|
+
const expectedBinDir = getPythonVirtualEnvPaths(functionsDir).binDir;
|
|
35
|
+
|
|
36
|
+
expect(env.VIRTUAL_ENV).toBe(path.join(functionsDir, ".venv"));
|
|
37
|
+
expect(env.languageWorkers__python__defaultExecutablePath).toBe(
|
|
38
|
+
getPythonVirtualEnvPaths(functionsDir).pythonExecutable
|
|
39
|
+
);
|
|
40
|
+
expect(env.PATH?.startsWith(`${expectedBinDir}${path.delimiter}`)).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ModelInfo } from "../core/scaffold/model-parser";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* テスト用の基本的な ModelInfo フィクスチャ
|
|
5
|
+
*/
|
|
6
|
+
export function createBasicModelInfo(overrides?: Partial<ModelInfo>): ModelInfo {
|
|
7
|
+
return {
|
|
8
|
+
name: "Todo",
|
|
9
|
+
displayName: "Todo",
|
|
10
|
+
schemaName: "todoSchema",
|
|
11
|
+
filePath: "/models/todo.ts",
|
|
12
|
+
fields: [
|
|
13
|
+
{ name: "id", type: "string", isOptional: false, isArray: false },
|
|
14
|
+
{ name: "title", type: "string", isOptional: false, isArray: false },
|
|
15
|
+
{ name: "description", type: "string", isOptional: true, isArray: false },
|
|
16
|
+
{ name: "completed", type: "boolean", isOptional: false, isArray: false },
|
|
17
|
+
{ name: "createdAt", type: "string", isOptional: false, isArray: false },
|
|
18
|
+
{ name: "updatedAt", type: "string", isOptional: false, isArray: false },
|
|
19
|
+
],
|
|
20
|
+
hasId: true,
|
|
21
|
+
hasCreatedAt: true,
|
|
22
|
+
hasUpdatedAt: true,
|
|
23
|
+
nestedSchemaRefs: [],
|
|
24
|
+
...overrides,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 外部キーを含む ModelInfo フィクスチャ
|
|
30
|
+
*/
|
|
31
|
+
export function createModelInfoWithForeignKey(): ModelInfo {
|
|
32
|
+
return createBasicModelInfo({
|
|
33
|
+
name: "Task",
|
|
34
|
+
displayName: "Task",
|
|
35
|
+
schemaName: "taskSchema",
|
|
36
|
+
filePath: "/models/task.ts",
|
|
37
|
+
fields: [
|
|
38
|
+
{ name: "id", type: "string", isOptional: false, isArray: false },
|
|
39
|
+
{ name: "title", type: "string", isOptional: false, isArray: false },
|
|
40
|
+
{
|
|
41
|
+
name: "categoryId",
|
|
42
|
+
type: "string",
|
|
43
|
+
isOptional: false,
|
|
44
|
+
isArray: false,
|
|
45
|
+
isForeignKey: true,
|
|
46
|
+
referencedModel: "Category",
|
|
47
|
+
},
|
|
48
|
+
{ name: "createdAt", type: "string", isOptional: false, isArray: false },
|
|
49
|
+
{ name: "updatedAt", type: "string", isOptional: false, isArray: false },
|
|
50
|
+
],
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* enum フィールドを含む ModelInfo フィクスチャ
|
|
56
|
+
*/
|
|
57
|
+
export function createModelInfoWithEnum(): ModelInfo {
|
|
58
|
+
return createBasicModelInfo({
|
|
59
|
+
name: "Issue",
|
|
60
|
+
displayName: "Issue",
|
|
61
|
+
schemaName: "issueSchema",
|
|
62
|
+
filePath: "/models/issue.ts",
|
|
63
|
+
fields: [
|
|
64
|
+
{ name: "id", type: "string", isOptional: false, isArray: false },
|
|
65
|
+
{ name: "title", type: "string", isOptional: false, isArray: false },
|
|
66
|
+
{
|
|
67
|
+
name: "status",
|
|
68
|
+
type: "string",
|
|
69
|
+
isOptional: false,
|
|
70
|
+
isArray: false,
|
|
71
|
+
enumValues: ["open", "in_progress", "closed"],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: "priority",
|
|
75
|
+
type: "number",
|
|
76
|
+
isOptional: true,
|
|
77
|
+
isArray: false,
|
|
78
|
+
},
|
|
79
|
+
{ name: "createdAt", type: "string", isOptional: false, isArray: false },
|
|
80
|
+
{ name: "updatedAt", type: "string", isOptional: false, isArray: false },
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateCSharpAzureFunctionsCRUD,
|
|
3
|
+
generateCompactAzureFunctionsCRUD,
|
|
4
|
+
generatePythonAzureFunctionsCRUD,
|
|
5
|
+
} from "../core/scaffold/functions-generator";
|
|
6
|
+
import { createBasicModelInfo, createModelInfoWithEnum } from "./fixtures";
|
|
7
|
+
|
|
8
|
+
describe("generateCompactAzureFunctionsCRUD", () => {
|
|
9
|
+
it("generates correct CRUD code for a basic model", () => {
|
|
10
|
+
const model = createBasicModelInfo();
|
|
11
|
+
const code = generateCompactAzureFunctionsCRUD(model, "@myapp/shared");
|
|
12
|
+
expect(code).toMatchSnapshot();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("generates correct CRUD code for a model with enum fields", () => {
|
|
16
|
+
const model = createModelInfoWithEnum();
|
|
17
|
+
const code = generateCompactAzureFunctionsCRUD(model, "@myapp/shared");
|
|
18
|
+
expect(code).toMatchSnapshot();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("imports the correct schema from shared package", () => {
|
|
22
|
+
const model = createBasicModelInfo();
|
|
23
|
+
const code = generateCompactAzureFunctionsCRUD(model, "@myapp/shared");
|
|
24
|
+
expect(code).toContain("import { todoSchema } from '@myapp/shared'");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("uses correct container name (PascalCase + s)", () => {
|
|
28
|
+
const model = createBasicModelInfo();
|
|
29
|
+
const code = generateCompactAzureFunctionsCRUD(model, "@myapp/shared");
|
|
30
|
+
expect(code).toContain("const containerName = 'Todos'");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("registers correct route names (camelCase)", () => {
|
|
34
|
+
const model = createBasicModelInfo();
|
|
35
|
+
const code = generateCompactAzureFunctionsCRUD(model, "@myapp/shared");
|
|
36
|
+
expect(code).toContain("'todo-get-all'");
|
|
37
|
+
expect(code).toContain("'todo-get-by-id'");
|
|
38
|
+
expect(code).toContain("'todo-create'");
|
|
39
|
+
expect(code).toContain("'todo-update'");
|
|
40
|
+
expect(code).toContain("'todo-delete'");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("generates all CRUD HTTP methods", () => {
|
|
44
|
+
const model = createBasicModelInfo();
|
|
45
|
+
const code = generateCompactAzureFunctionsCRUD(model, "@myapp/shared");
|
|
46
|
+
expect(code).toContain("methods: ['GET']");
|
|
47
|
+
expect(code).toContain("methods: ['POST']");
|
|
48
|
+
expect(code).toContain("methods: ['PUT']");
|
|
49
|
+
expect(code).toContain("methods: ['DELETE']");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("uses correct route patterns", () => {
|
|
53
|
+
const model = createBasicModelInfo();
|
|
54
|
+
const code = generateCompactAzureFunctionsCRUD(model, "@myapp/shared");
|
|
55
|
+
expect(code).toContain("route: 'todo'");
|
|
56
|
+
expect(code).toContain("route: 'todo/{id}'");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("handles multi-word model names correctly", () => {
|
|
60
|
+
const model = createBasicModelInfo({
|
|
61
|
+
name: "TodoItem",
|
|
62
|
+
schemaName: "todoItemSchema",
|
|
63
|
+
});
|
|
64
|
+
const code = generateCompactAzureFunctionsCRUD(model, "@myapp/shared");
|
|
65
|
+
expect(code).toContain("const containerName = 'TodoItems'");
|
|
66
|
+
expect(code).toContain("route: 'todoItem'");
|
|
67
|
+
expect(code).toContain("'todoItem-get-all'");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("generates C# Cosmos-backed CRUD handlers", () => {
|
|
71
|
+
const model = createBasicModelInfo();
|
|
72
|
+
const code = generateCSharpAzureFunctionsCRUD(model);
|
|
73
|
+
expect(code).toContain("public sealed class TodoFunctions");
|
|
74
|
+
expect(code).toContain('[Function("todoGetAll")]');
|
|
75
|
+
expect(code).toContain('Route = "todo/{id}"');
|
|
76
|
+
expect(code).toContain("CreateCosmosClient()");
|
|
77
|
+
expect(code).toContain('new CosmosClientOptions { ConnectionMode = ConnectionMode.Gateway }');
|
|
78
|
+
expect(code).toContain('endpoint.Contains("localhost:8081", StringComparison.OrdinalIgnoreCase)');
|
|
79
|
+
expect(code).toContain("container.ReadItemStreamAsync");
|
|
80
|
+
expect(code).toContain("JsonNode.Parse(document.RootElement.GetRawText())?.AsObject()");
|
|
81
|
+
expect(code).toContain("container.CreateItemStreamAsync");
|
|
82
|
+
expect(code).toContain("container.ReplaceItemStreamAsync");
|
|
83
|
+
expect(code).toContain("payload.ToJsonString()");
|
|
84
|
+
expect(code).toContain("container.DeleteItemAsync<JsonObject>");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("generates Python Cosmos-backed CRUD handlers", () => {
|
|
88
|
+
const model = createBasicModelInfo();
|
|
89
|
+
const generated = generatePythonAzureFunctionsCRUD(model);
|
|
90
|
+
expect(generated.registration).toContain("from blueprints.todo import bp as todo_bp");
|
|
91
|
+
expect(generated.registration).toContain("app.register_blueprint(todo_bp)");
|
|
92
|
+
expect(generated.blueprint).toContain('@bp.route(route="todo", methods=["GET"])');
|
|
93
|
+
expect(generated.blueprint).toContain("def todo_create");
|
|
94
|
+
expect(generated.blueprint).toContain("from azure.cosmos import CosmosClient, exceptions");
|
|
95
|
+
expect(generated.blueprint).toContain("container.query_items");
|
|
96
|
+
expect(generated.blueprint).toContain("container.read_item");
|
|
97
|
+
expect(generated.blueprint).toContain("container.create_item");
|
|
98
|
+
expect(generated.blueprint).toContain("container.replace_item");
|
|
99
|
+
expect(generated.blueprint).toContain("container.delete_item");
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildGeneratedProjectDependencies,
|
|
3
|
+
buildCSharpFunctionsProgramSource,
|
|
4
|
+
buildCSharpFunctionsProjectSource,
|
|
5
|
+
buildSwallowKitConfigSource,
|
|
6
|
+
injectSwallowKitNextConfig,
|
|
7
|
+
} from "../cli/commands/init";
|
|
8
|
+
|
|
9
|
+
describe("injectSwallowKitNextConfig", () => {
|
|
10
|
+
it("adds standalone settings without deprecated experimental options", () => {
|
|
11
|
+
const original = `import type { NextConfig } from "next";
|
|
12
|
+
|
|
13
|
+
const nextConfig: NextConfig = {
|
|
14
|
+
/* config options here */
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default nextConfig;
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
const updated = injectSwallowKitNextConfig(original, "sample-app");
|
|
21
|
+
|
|
22
|
+
expect(updated).toContain("output: 'standalone'");
|
|
23
|
+
expect(updated).toContain("transpilePackages: ['@sample-app/shared']");
|
|
24
|
+
expect(updated).toContain("serverExternalPackages: ['applicationinsights', 'diagnostic-channel-publishers']");
|
|
25
|
+
expect(updated).not.toContain("turbopackUseSystemTlsCerts");
|
|
26
|
+
expect(updated).not.toContain("experimental:");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("supports JavaScript next.config format", () => {
|
|
30
|
+
const original = `const nextConfig = {
|
|
31
|
+
/* config options here */
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
module.exports = nextConfig;
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
const updated = injectSwallowKitNextConfig(original, "sample-app");
|
|
38
|
+
|
|
39
|
+
expect(updated).toContain("transpilePackages: ['@sample-app/shared']");
|
|
40
|
+
expect(updated).toContain("module.exports = nextConfig;");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("generates a C# Program.cs compatible with the current worker packages", () => {
|
|
44
|
+
const source = buildCSharpFunctionsProgramSource();
|
|
45
|
+
|
|
46
|
+
expect(source).toContain("new HostBuilder()");
|
|
47
|
+
expect(source).toContain(".ConfigureFunctionsWorkerDefaults()");
|
|
48
|
+
expect(source).toContain("services.AddApplicationInsightsTelemetryWorkerService()");
|
|
49
|
+
expect(source).not.toContain("Microsoft.Azure.Functions.Worker.Builder");
|
|
50
|
+
expect(source).not.toContain("FunctionsApplication.CreateBuilder");
|
|
51
|
+
expect(source).not.toContain("ConfigureFunctionsApplicationInsights");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("excludes nested generated bin and obj files from the C# Functions project", () => {
|
|
55
|
+
const source = buildCSharpFunctionsProjectSource();
|
|
56
|
+
|
|
57
|
+
expect(source).toContain('<Compile Remove="generated\\**\\bin\\**\\*.cs;generated\\**\\obj\\**\\*.cs" />');
|
|
58
|
+
expect(source).toContain('<EmbeddedResource Remove="generated\\**\\bin\\**;generated\\**\\obj\\**" />');
|
|
59
|
+
expect(source).toContain('<None Remove="generated\\**\\bin\\**;generated\\**\\obj\\**" />');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("builds swallowkit.config.js without a local swallowkit package type import", () => {
|
|
63
|
+
const source = buildSwallowKitConfigSource("typescript");
|
|
64
|
+
|
|
65
|
+
expect(source).toContain("language: 'typescript'");
|
|
66
|
+
expect(source).toContain("baseUrl: process.env.BACKEND_FUNCTIONS_BASE_URL");
|
|
67
|
+
expect(source).not.toContain("import('swallowkit').SwallowKitConfig");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("does not add swallowkit as a generated project dependency", () => {
|
|
71
|
+
const dependencies = buildGeneratedProjectDependencies("sample-app");
|
|
72
|
+
|
|
73
|
+
expect(dependencies).toEqual({
|
|
74
|
+
"@azure/cosmos": "^4.0.0",
|
|
75
|
+
applicationinsights: "^3.3.0",
|
|
76
|
+
"@sample-app/shared": "*",
|
|
77
|
+
});
|
|
78
|
+
expect(dependencies).not.toHaveProperty("swallowkit");
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateBFFCallFunction,
|
|
3
|
+
generateCompactBFFRoutes,
|
|
4
|
+
} from "../core/scaffold/nextjs-generator";
|
|
5
|
+
import { createBasicModelInfo } from "./fixtures";
|
|
6
|
+
|
|
7
|
+
describe("generateBFFCallFunction", () => {
|
|
8
|
+
it("generates call function helper code", () => {
|
|
9
|
+
const code = generateBFFCallFunction();
|
|
10
|
+
expect(code).toMatchSnapshot();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("includes getFunctionsBaseUrl helper", () => {
|
|
14
|
+
const code = generateBFFCallFunction();
|
|
15
|
+
expect(code).toContain("getFunctionsBaseUrl");
|
|
16
|
+
expect(code).toContain("BACKEND_FUNCTIONS_BASE_URL");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("includes callFunction export", () => {
|
|
20
|
+
const code = generateBFFCallFunction();
|
|
21
|
+
expect(code).toContain("export async function callFunction");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("includes z.ZodSchema typings", () => {
|
|
25
|
+
const code = generateBFFCallFunction();
|
|
26
|
+
expect(code).toContain("z.ZodSchema");
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("generateCompactBFFRoutes", () => {
|
|
31
|
+
it("generates list and detail routes", () => {
|
|
32
|
+
const model = createBasicModelInfo();
|
|
33
|
+
const routes = generateCompactBFFRoutes(model, "@myapp/shared");
|
|
34
|
+
|
|
35
|
+
expect(routes.listRoute).toMatchSnapshot();
|
|
36
|
+
expect(routes.detailRoute).toMatchSnapshot();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("imports the correct schema", () => {
|
|
40
|
+
const model = createBasicModelInfo();
|
|
41
|
+
const routes = generateCompactBFFRoutes(model, "@myapp/shared");
|
|
42
|
+
|
|
43
|
+
expect(routes.listRoute).toContain(
|
|
44
|
+
"import { todoSchema } from '@myapp/shared'"
|
|
45
|
+
);
|
|
46
|
+
expect(routes.detailRoute).toContain(
|
|
47
|
+
"import { todoSchema } from '@myapp/shared'"
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("uses correct API paths (camelCase)", () => {
|
|
52
|
+
const model = createBasicModelInfo();
|
|
53
|
+
const routes = generateCompactBFFRoutes(model, "@myapp/shared");
|
|
54
|
+
|
|
55
|
+
expect(routes.listRoute).toContain("path: '/api/todo'");
|
|
56
|
+
expect(routes.detailRoute).toContain("/api/todo/");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("list route has GET and POST handlers", () => {
|
|
60
|
+
const model = createBasicModelInfo();
|
|
61
|
+
const routes = generateCompactBFFRoutes(model, "@myapp/shared");
|
|
62
|
+
|
|
63
|
+
expect(routes.listRoute).toContain("export async function GET()");
|
|
64
|
+
expect(routes.listRoute).toContain("export async function POST(");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("detail route has GET, PUT, and DELETE handlers", () => {
|
|
68
|
+
const model = createBasicModelInfo();
|
|
69
|
+
const routes = generateCompactBFFRoutes(model, "@myapp/shared");
|
|
70
|
+
|
|
71
|
+
expect(routes.detailRoute).toContain("export async function GET(");
|
|
72
|
+
expect(routes.detailRoute).toContain("export async function PUT(");
|
|
73
|
+
expect(routes.detailRoute).toContain("export async function DELETE(");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("creates InputSchema that omits managed fields", () => {
|
|
77
|
+
const model = createBasicModelInfo();
|
|
78
|
+
const routes = generateCompactBFFRoutes(model, "@myapp/shared");
|
|
79
|
+
|
|
80
|
+
expect(routes.listRoute).toContain(
|
|
81
|
+
"todoSchema.omit({ id: true, createdAt: true, updatedAt: true })"
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("handles multi-word model names", () => {
|
|
86
|
+
const model = createBasicModelInfo({
|
|
87
|
+
name: "BlogPost",
|
|
88
|
+
schemaName: "blogPostSchema",
|
|
89
|
+
});
|
|
90
|
+
const routes = generateCompactBFFRoutes(model, "@myapp/shared");
|
|
91
|
+
|
|
92
|
+
expect(routes.listRoute).toContain("path: '/api/blogPost'");
|
|
93
|
+
expect(routes.listRoute).toContain(
|
|
94
|
+
"import { blogPostSchema } from '@myapp/shared'"
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { generateOpenApiDocument } from "../core/scaffold/openapi-generator";
|
|
2
|
+
import { createBasicModelInfo } from "./fixtures";
|
|
3
|
+
|
|
4
|
+
describe("generateOpenApiDocument", () => {
|
|
5
|
+
it("emits an OpenAPI document for the root model", () => {
|
|
6
|
+
const model = createBasicModelInfo();
|
|
7
|
+
const document = JSON.parse(generateOpenApiDocument([model], model));
|
|
8
|
+
|
|
9
|
+
expect(document.openapi).toBe("3.0.3");
|
|
10
|
+
expect(document.components.schemas.Todo.properties.title.type).toBe("string");
|
|
11
|
+
expect(document.paths["/api/todo"].post.requestBody.content["application/json"].schema.$ref)
|
|
12
|
+
.toBe("#/components/schemas/Todo");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("emits nested schema references when present", () => {
|
|
16
|
+
const todo = createBasicModelInfo({
|
|
17
|
+
fields: [
|
|
18
|
+
{ name: "id", type: "string", isOptional: false, isArray: false },
|
|
19
|
+
{ name: "title", type: "string", isOptional: false, isArray: false },
|
|
20
|
+
{
|
|
21
|
+
name: "category",
|
|
22
|
+
type: "object",
|
|
23
|
+
isOptional: false,
|
|
24
|
+
isArray: false,
|
|
25
|
+
isNestedSchema: true,
|
|
26
|
+
nestedModelName: "Category",
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
const category = createBasicModelInfo({
|
|
31
|
+
name: "Category",
|
|
32
|
+
schemaName: "categorySchema",
|
|
33
|
+
fields: [
|
|
34
|
+
{ name: "id", type: "string", isOptional: false, isArray: false },
|
|
35
|
+
{ name: "name", type: "string", isOptional: false, isArray: false },
|
|
36
|
+
],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const document = JSON.parse(generateOpenApiDocument([todo, category], todo));
|
|
40
|
+
expect(document.components.schemas.Todo.properties.category.$ref).toBe("#/components/schemas/Category");
|
|
41
|
+
expect(document.components.schemas.Category.properties.name.type).toBe("string");
|
|
42
|
+
});
|
|
43
|
+
});
|