swallowkit 1.0.0-beta.4 → 1.0.0-beta.41
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 +153 -215
- package/README.md +153 -216
- package/dist/__tests__/fixtures.d.ts +22 -0
- package/dist/__tests__/fixtures.d.ts.map +1 -0
- package/dist/__tests__/fixtures.js +146 -0
- package/dist/__tests__/fixtures.js.map +1 -0
- package/dist/cli/commands/add-auth.d.ts +10 -0
- package/dist/cli/commands/add-auth.d.ts.map +1 -0
- package/dist/cli/commands/add-auth.js +426 -0
- package/dist/cli/commands/add-auth.js.map +1 -0
- package/dist/cli/commands/add-connector.d.ts +20 -0
- package/dist/cli/commands/add-connector.d.ts.map +1 -0
- package/dist/cli/commands/add-connector.js +163 -0
- package/dist/cli/commands/add-connector.js.map +1 -0
- package/dist/cli/commands/create-model.d.ts +1 -4
- package/dist/cli/commands/create-model.d.ts.map +1 -1
- package/dist/cli/commands/create-model.js +21 -82
- package/dist/cli/commands/create-model.js.map +1 -1
- package/dist/cli/commands/dev-seeds.d.ts +57 -0
- package/dist/cli/commands/dev-seeds.d.ts.map +1 -0
- package/dist/cli/commands/dev-seeds.js +470 -0
- package/dist/cli/commands/dev-seeds.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +33 -0
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +628 -146
- 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 +45 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +2851 -1754
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/scaffold.d.ts +4 -0
- package/dist/cli/commands/scaffold.d.ts.map +1 -1
- package/dist/cli/commands/scaffold.js +439 -130
- package/dist/cli/commands/scaffold.js.map +1 -1
- package/dist/cli/index.d.ts +5 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +200 -42
- package/dist/cli/index.js.map +1 -1
- package/dist/core/config.d.ts +8 -2
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +94 -5
- package/dist/core/config.js.map +1 -1
- package/dist/core/mock/connector-mock-server.d.ts +101 -0
- package/dist/core/mock/connector-mock-server.d.ts.map +1 -0
- package/dist/core/mock/connector-mock-server.js +480 -0
- package/dist/core/mock/connector-mock-server.js.map +1 -0
- package/dist/core/mock/zod-mock-generator.d.ts +14 -0
- package/dist/core/mock/zod-mock-generator.d.ts.map +1 -0
- package/dist/core/mock/zod-mock-generator.js +163 -0
- package/dist/core/mock/zod-mock-generator.js.map +1 -0
- package/dist/core/operations/create-model.d.ts +15 -0
- package/dist/core/operations/create-model.d.ts.map +1 -0
- package/dist/core/operations/create-model.js +171 -0
- package/dist/core/operations/create-model.js.map +1 -0
- package/dist/core/operations/runtime.d.ts +32 -0
- package/dist/core/operations/runtime.d.ts.map +1 -0
- package/dist/core/operations/runtime.js +225 -0
- package/dist/core/operations/runtime.js.map +1 -0
- package/dist/core/operations/scaffold-machine.d.ts +16 -0
- package/dist/core/operations/scaffold-machine.d.ts.map +1 -0
- package/dist/core/operations/scaffold-machine.js +63 -0
- package/dist/core/operations/scaffold-machine.js.map +1 -0
- package/dist/core/project/manifest.d.ts +92 -0
- package/dist/core/project/manifest.d.ts.map +1 -0
- package/dist/core/project/manifest.js +321 -0
- package/dist/core/project/manifest.js.map +1 -0
- package/dist/core/project/validation.d.ts +20 -0
- package/dist/core/project/validation.d.ts.map +1 -0
- package/dist/core/project/validation.js +209 -0
- package/dist/core/project/validation.js.map +1 -0
- package/dist/core/scaffold/auth-generator.d.ts +38 -0
- package/dist/core/scaffold/auth-generator.d.ts.map +1 -0
- package/dist/core/scaffold/auth-generator.js +1244 -0
- package/dist/core/scaffold/auth-generator.js.map +1 -0
- package/dist/core/scaffold/connector-functions-generator.d.ts +41 -0
- package/dist/core/scaffold/connector-functions-generator.d.ts.map +1 -0
- package/dist/core/scaffold/connector-functions-generator.js +1027 -0
- package/dist/core/scaffold/connector-functions-generator.js.map +1 -0
- package/dist/core/scaffold/functions-generator.d.ts +7 -1
- package/dist/core/scaffold/functions-generator.d.ts.map +1 -1
- package/dist/core/scaffold/functions-generator.js +920 -220
- package/dist/core/scaffold/functions-generator.js.map +1 -1
- package/dist/core/scaffold/model-parser.d.ts +20 -1
- package/dist/core/scaffold/model-parser.d.ts.map +1 -1
- package/dist/core/scaffold/model-parser.js +328 -135
- package/dist/core/scaffold/model-parser.js.map +1 -1
- package/dist/core/scaffold/native-schema-generator.d.ts +13 -0
- package/dist/core/scaffold/native-schema-generator.d.ts.map +1 -0
- package/dist/core/scaffold/native-schema-generator.js +696 -0
- package/dist/core/scaffold/native-schema-generator.js.map +1 -0
- package/dist/core/scaffold/nextjs-generator.d.ts +8 -0
- package/dist/core/scaffold/nextjs-generator.d.ts.map +1 -1
- package/dist/core/scaffold/nextjs-generator.js +314 -182
- package/dist/core/scaffold/nextjs-generator.js.map +1 -1
- 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.d.ts +10 -4
- package/dist/core/scaffold/ui-generator.d.ts.map +1 -1
- package/dist/core/scaffold/ui-generator.js +768 -663
- package/dist/core/scaffold/ui-generator.js.map +1 -1
- 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/machine/contracts.d.ts +16 -0
- package/dist/machine/contracts.d.ts.map +1 -0
- package/dist/machine/contracts.js +3 -0
- package/dist/machine/contracts.js.map +1 -0
- package/dist/machine/errors.d.ts +11 -0
- package/dist/machine/errors.d.ts.map +1 -0
- package/dist/machine/errors.js +34 -0
- package/dist/machine/errors.js.map +1 -0
- package/dist/machine/index.d.ts +3 -0
- package/dist/machine/index.d.ts.map +1 -0
- package/dist/machine/index.js +156 -0
- package/dist/machine/index.js.map +1 -0
- package/dist/mcp/index.d.ts +25 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +186 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/types/index.d.ts +65 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/package-manager.d.ts +111 -0
- package/dist/utils/package-manager.d.ts.map +1 -0
- package/dist/utils/package-manager.js +234 -0
- package/dist/utils/package-manager.js.map +1 -0
- package/dist/utils/python-uv.d.ts +21 -0
- package/dist/utils/python-uv.d.ts.map +1 -0
- package/dist/utils/python-uv.js +111 -0
- package/dist/utils/python-uv.js.map +1 -0
- package/package.json +84 -73
- package/src/__tests__/__snapshots__/functions-generator.test.ts.snap +1139 -0
- package/src/__tests__/__snapshots__/nextjs-generator.test.ts.snap +194 -0
- package/src/__tests__/__snapshots__/ui-generator.test.ts.snap +532 -0
- package/src/__tests__/auth.test.ts +654 -0
- package/src/__tests__/config.test.ts +274 -0
- package/src/__tests__/connector-functions-generator.test.ts +288 -0
- package/src/__tests__/connector-mock-server.test.ts +439 -0
- package/src/__tests__/connector-model-bff.test.ts +162 -0
- package/src/__tests__/dev-seeds.test.ts +173 -0
- package/src/__tests__/dev.test.ts +252 -0
- package/src/__tests__/fixtures.ts +144 -0
- package/src/__tests__/functions-generator.test.ts +237 -0
- package/src/__tests__/init.test.ts +201 -0
- package/src/__tests__/jest-globals.d.ts +8 -0
- package/src/__tests__/machine.test.ts +356 -0
- package/src/__tests__/mcp.test.ts +124 -0
- package/src/__tests__/model-parser.test.ts +52 -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 +216 -0
- package/src/__tests__/python-uv.test.ts +48 -0
- package/src/__tests__/scaffold.test.ts +191 -0
- package/src/__tests__/string-utils.test.ts +75 -0
- package/src/__tests__/tsconfig.json +15 -0
- package/src/__tests__/ui-generator.test.ts +144 -0
- package/src/__tests__/zod-mock-generator.test.ts +132 -0
- package/src/cli/commands/add-auth.ts +482 -0
- package/src/cli/commands/add-connector.ts +158 -0
- package/src/cli/commands/create-model.ts +62 -0
- package/src/cli/commands/dev-seeds.ts +614 -0
- package/src/cli/commands/dev.ts +1134 -0
- package/src/cli/commands/index.ts +9 -0
- package/src/cli/commands/init.ts +3601 -0
- package/src/cli/commands/provision.ts +193 -0
- package/src/cli/commands/scaffold.ts +991 -0
- package/src/cli/index.ts +196 -0
- package/src/core/config.ts +312 -0
- package/src/core/mock/connector-mock-server.ts +555 -0
- package/src/core/mock/zod-mock-generator.ts +205 -0
- package/src/core/operations/create-model.ts +174 -0
- package/src/core/operations/runtime.ts +235 -0
- package/src/core/operations/scaffold-machine.ts +91 -0
- package/src/core/project/manifest.ts +402 -0
- package/src/core/project/validation.ts +229 -0
- package/src/core/scaffold/auth-generator.ts +1284 -0
- package/src/core/scaffold/connector-functions-generator.ts +1128 -0
- package/src/core/scaffold/functions-generator.ts +970 -0
- package/src/core/scaffold/model-parser.ts +841 -0
- package/src/core/scaffold/native-schema-generator.ts +822 -0
- package/src/core/scaffold/nextjs-generator.ts +370 -0
- package/src/core/scaffold/openapi-generator.ts +212 -0
- package/src/core/scaffold/ui-generator.ts +1061 -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/machine/contracts.ts +17 -0
- package/src/machine/errors.ts +34 -0
- package/src/machine/index.ts +173 -0
- package/src/mcp/index.ts +191 -0
- package/src/types/index.ts +134 -0
- package/src/utils/package-manager.ts +250 -0
- package/src/utils/python-uv.ts +96 -0
|
@@ -0,0 +1,237 @@
|
|
|
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 TodoCrudFunctions");
|
|
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
|
+
|
|
102
|
+
// --- Custom Partition Key Tests ---
|
|
103
|
+
|
|
104
|
+
describe("custom partition key (TS)", () => {
|
|
105
|
+
it("uses input binding when partitionKey is /id (default)", () => {
|
|
106
|
+
const model = createBasicModelInfo({ partitionKey: "/id" });
|
|
107
|
+
const code = generateCompactAzureFunctionsCRUD(model, "@myapp/shared");
|
|
108
|
+
expect(code).toContain("partitionKey: '{id}'");
|
|
109
|
+
expect(code).toContain("container.item(id, id).delete()");
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("uses SDK direct call when partitionKey is not /id", () => {
|
|
113
|
+
const model = createBasicModelInfo({
|
|
114
|
+
partitionKey: "/tenantId",
|
|
115
|
+
fields: [
|
|
116
|
+
{ name: "id", type: "string", isOptional: false, isArray: false },
|
|
117
|
+
{ name: "tenantId", type: "string", isOptional: false, isArray: false },
|
|
118
|
+
{ name: "title", type: "string", isOptional: false, isArray: false },
|
|
119
|
+
{ name: "createdAt", type: "string", isOptional: false, isArray: false },
|
|
120
|
+
{ name: "updatedAt", type: "string", isOptional: false, isArray: false },
|
|
121
|
+
],
|
|
122
|
+
});
|
|
123
|
+
const code = generateCompactAzureFunctionsCRUD(model, "@myapp/shared");
|
|
124
|
+
|
|
125
|
+
// Should NOT have input binding with partitionKey
|
|
126
|
+
expect(code).not.toContain("partitionKey: '{id}'");
|
|
127
|
+
// getById should use SDK query
|
|
128
|
+
expect(code).toContain("custom partition key");
|
|
129
|
+
expect(code).toContain("SELECT * FROM c WHERE c.id = @id");
|
|
130
|
+
// delete should read doc first to get PK value
|
|
131
|
+
expect(code).toContain("resources[0].tenantId");
|
|
132
|
+
expect(code).toContain("container.item(id, pkValue).delete()");
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("generates snapshot for custom partition key TS", () => {
|
|
136
|
+
const model = createBasicModelInfo({
|
|
137
|
+
partitionKey: "/tenantId",
|
|
138
|
+
fields: [
|
|
139
|
+
{ name: "id", type: "string", isOptional: false, isArray: false },
|
|
140
|
+
{ name: "tenantId", type: "string", isOptional: false, isArray: false },
|
|
141
|
+
{ name: "title", type: "string", isOptional: false, isArray: false },
|
|
142
|
+
{ name: "createdAt", type: "string", isOptional: false, isArray: false },
|
|
143
|
+
{ name: "updatedAt", type: "string", isOptional: false, isArray: false },
|
|
144
|
+
],
|
|
145
|
+
});
|
|
146
|
+
const code = generateCompactAzureFunctionsCRUD(model, "@myapp/shared");
|
|
147
|
+
expect(code).toMatchSnapshot();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe("custom partition key (C#)", () => {
|
|
152
|
+
it("uses ReadItemStreamAsync when partitionKey is /id", () => {
|
|
153
|
+
const model = createBasicModelInfo({ partitionKey: "/id" });
|
|
154
|
+
const code = generateCSharpAzureFunctionsCRUD(model);
|
|
155
|
+
expect(code).toContain("ReadItemStreamAsync(id, new PartitionKey(id))");
|
|
156
|
+
expect(code).toContain("DeleteItemAsync<JsonObject>(id, new PartitionKey(id))");
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("uses query when partitionKey is not /id", () => {
|
|
160
|
+
const model = createBasicModelInfo({
|
|
161
|
+
partitionKey: "/tenantId",
|
|
162
|
+
fields: [
|
|
163
|
+
{ name: "id", type: "string", isOptional: false, isArray: false },
|
|
164
|
+
{ name: "tenantId", type: "string", isOptional: false, isArray: false },
|
|
165
|
+
{ name: "title", type: "string", isOptional: false, isArray: false },
|
|
166
|
+
{ name: "createdAt", type: "string", isOptional: false, isArray: false },
|
|
167
|
+
{ name: "updatedAt", type: "string", isOptional: false, isArray: false },
|
|
168
|
+
],
|
|
169
|
+
});
|
|
170
|
+
const code = generateCSharpAzureFunctionsCRUD(model);
|
|
171
|
+
// ReadCosmosItemAsync should use query instead of point read
|
|
172
|
+
expect(code).toContain("GetItemQueryStreamIterator(query)");
|
|
173
|
+
expect(code).not.toContain("ReadItemStreamAsync(id, new PartitionKey(id))");
|
|
174
|
+
// Delete should read doc first for PK value
|
|
175
|
+
expect(code).toContain('existing["tenantId"]');
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("generates snapshot for custom partition key C#", () => {
|
|
179
|
+
const model = createBasicModelInfo({
|
|
180
|
+
partitionKey: "/tenantId",
|
|
181
|
+
fields: [
|
|
182
|
+
{ name: "id", type: "string", isOptional: false, isArray: false },
|
|
183
|
+
{ name: "tenantId", type: "string", isOptional: false, isArray: false },
|
|
184
|
+
{ name: "title", type: "string", isOptional: false, isArray: false },
|
|
185
|
+
{ name: "createdAt", type: "string", isOptional: false, isArray: false },
|
|
186
|
+
{ name: "updatedAt", type: "string", isOptional: false, isArray: false },
|
|
187
|
+
],
|
|
188
|
+
});
|
|
189
|
+
const code = generateCSharpAzureFunctionsCRUD(model);
|
|
190
|
+
expect(code).toMatchSnapshot();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("custom partition key (Python)", () => {
|
|
195
|
+
it("uses read_item with partition_key=item_id when partitionKey is /id", () => {
|
|
196
|
+
const model = createBasicModelInfo({ partitionKey: "/id" });
|
|
197
|
+
const generated = generatePythonAzureFunctionsCRUD(model);
|
|
198
|
+
expect(generated.blueprint).toContain("partition_key=item_id");
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("uses cross-partition query when partitionKey is not /id", () => {
|
|
202
|
+
const model = createBasicModelInfo({
|
|
203
|
+
partitionKey: "/tenantId",
|
|
204
|
+
fields: [
|
|
205
|
+
{ name: "id", type: "string", isOptional: false, isArray: false },
|
|
206
|
+
{ name: "tenantId", type: "string", isOptional: false, isArray: false },
|
|
207
|
+
{ name: "title", type: "string", isOptional: false, isArray: false },
|
|
208
|
+
{ name: "createdAt", type: "string", isOptional: false, isArray: false },
|
|
209
|
+
{ name: "updatedAt", type: "string", isOptional: false, isArray: false },
|
|
210
|
+
],
|
|
211
|
+
});
|
|
212
|
+
const generated = generatePythonAzureFunctionsCRUD(model);
|
|
213
|
+
// Should not use direct read_item with partition_key=item_id
|
|
214
|
+
expect(generated.blueprint).not.toContain("partition_key=item_id");
|
|
215
|
+
// Should use cross-partition query
|
|
216
|
+
expect(generated.blueprint).toContain("enable_cross_partition_query=True");
|
|
217
|
+
expect(generated.blueprint).toContain('SELECT * FROM c WHERE c.id = @id');
|
|
218
|
+
// Delete should get PK value from document
|
|
219
|
+
expect(generated.blueprint).toContain('.get("tenantId")');
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("generates snapshot for custom partition key Python", () => {
|
|
223
|
+
const model = createBasicModelInfo({
|
|
224
|
+
partitionKey: "/tenantId",
|
|
225
|
+
fields: [
|
|
226
|
+
{ name: "id", type: "string", isOptional: false, isArray: false },
|
|
227
|
+
{ name: "tenantId", type: "string", isOptional: false, isArray: false },
|
|
228
|
+
{ name: "title", type: "string", isOptional: false, isArray: false },
|
|
229
|
+
{ name: "createdAt", type: "string", isOptional: false, isArray: false },
|
|
230
|
+
{ name: "updatedAt", type: "string", isOptional: false, isArray: false },
|
|
231
|
+
],
|
|
232
|
+
});
|
|
233
|
+
const generated = generatePythonAzureFunctionsCRUD(model);
|
|
234
|
+
expect(generated.blueprint).toMatchSnapshot();
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
});
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildGeneratedProjectDependencies,
|
|
3
|
+
buildGeneratedProjectDevDependencies,
|
|
4
|
+
buildSharedTsConfig,
|
|
5
|
+
buildAzureSwaPipeline,
|
|
6
|
+
buildSwallowKitMcpProjectConfigSource,
|
|
7
|
+
buildGitHubSwaWorkflow,
|
|
8
|
+
buildCSharpFunctionsProgramSource,
|
|
9
|
+
buildCSharpFunctionsProjectSource,
|
|
10
|
+
buildSwallowKitConfigSource,
|
|
11
|
+
getAzureFunctionsPipeline,
|
|
12
|
+
getGitHubFunctionsWorkflow,
|
|
13
|
+
injectSwallowKitNextConfig,
|
|
14
|
+
parseIgnoredBuilds,
|
|
15
|
+
buildCosmosDbFreeTierBicepSource,
|
|
16
|
+
} from "../cli/commands/init";
|
|
17
|
+
|
|
18
|
+
describe("injectSwallowKitNextConfig", () => {
|
|
19
|
+
it("adds standalone settings without deprecated experimental options", () => {
|
|
20
|
+
const original = `import type { NextConfig } from "next";
|
|
21
|
+
|
|
22
|
+
const nextConfig: NextConfig = {
|
|
23
|
+
/* config options here */
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default nextConfig;
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
const updated = injectSwallowKitNextConfig(original, "sample-app");
|
|
30
|
+
|
|
31
|
+
expect(updated).toContain("output: 'standalone'");
|
|
32
|
+
expect(updated).toContain("transpilePackages: ['@sample-app/shared']");
|
|
33
|
+
expect(updated).toContain("serverExternalPackages: ['applicationinsights', 'diagnostic-channel-publishers']");
|
|
34
|
+
expect(updated).not.toContain("turbopackUseSystemTlsCerts");
|
|
35
|
+
expect(updated).not.toContain("experimental:");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("supports JavaScript next.config format", () => {
|
|
39
|
+
const original = `const nextConfig = {
|
|
40
|
+
/* config options here */
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
module.exports = nextConfig;
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
const updated = injectSwallowKitNextConfig(original, "sample-app");
|
|
47
|
+
|
|
48
|
+
expect(updated).toContain("transpilePackages: ['@sample-app/shared']");
|
|
49
|
+
expect(updated).toContain("module.exports = nextConfig;");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("generates a C# Program.cs compatible with the current worker packages", () => {
|
|
53
|
+
const source = buildCSharpFunctionsProgramSource();
|
|
54
|
+
|
|
55
|
+
expect(source).toContain("new HostBuilder()");
|
|
56
|
+
expect(source).toContain(".ConfigureFunctionsWorkerDefaults()");
|
|
57
|
+
expect(source).toContain("services.AddApplicationInsightsTelemetryWorkerService()");
|
|
58
|
+
expect(source).toContain("services.ConfigureFunctionsApplicationInsights()");
|
|
59
|
+
expect(source).toContain("Microsoft.Azure.Functions.Worker.ApplicationInsights");
|
|
60
|
+
expect(source).not.toContain("Microsoft.Azure.Functions.Worker.Builder");
|
|
61
|
+
expect(source).not.toContain("FunctionsApplication.CreateBuilder");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("excludes nested generated bin and obj files from the C# Functions project", () => {
|
|
65
|
+
const source = buildCSharpFunctionsProjectSource();
|
|
66
|
+
|
|
67
|
+
expect(source).toContain("<TargetFramework>net10.0</TargetFramework>");
|
|
68
|
+
expect(source).toContain('Version="2.52.0"');
|
|
69
|
+
expect(source).toContain('Version="3.3.0"');
|
|
70
|
+
expect(source).toContain('Version="2.0.7"');
|
|
71
|
+
expect(source).toContain('Version="2.50.0"');
|
|
72
|
+
expect(source).toContain('<Compile Remove="generated\\**\\bin\\**\\*.cs;generated\\**\\obj\\**\\*.cs" />');
|
|
73
|
+
expect(source).toContain('<EmbeddedResource Remove="generated\\**\\bin\\**;generated\\**\\obj\\**" />');
|
|
74
|
+
expect(source).toContain('<None Remove="generated\\**\\bin\\**;generated\\**\\obj\\**" />');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("builds swallowkit.config.js without a local swallowkit package type import", () => {
|
|
78
|
+
const source = buildSwallowKitConfigSource("typescript");
|
|
79
|
+
|
|
80
|
+
expect(source).toContain("language: 'typescript'");
|
|
81
|
+
expect(source).toContain("baseUrl: process.env.BACKEND_FUNCTIONS_BASE_URL");
|
|
82
|
+
expect(source).not.toContain("import('swallowkit').SwallowKitConfig");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("builds shared tsconfig with non-deprecated module resolution settings", () => {
|
|
86
|
+
const tsconfig = buildSharedTsConfig();
|
|
87
|
+
|
|
88
|
+
expect(tsconfig.compilerOptions.module).toBe("Node16");
|
|
89
|
+
expect(tsconfig.compilerOptions.moduleResolution).toBe("node16");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("does not add swallowkit as a generated project dependency", () => {
|
|
93
|
+
const dependencies = buildGeneratedProjectDependencies("sample-app");
|
|
94
|
+
|
|
95
|
+
expect(dependencies).toEqual({
|
|
96
|
+
"@azure/cosmos": "^4.0.0",
|
|
97
|
+
applicationinsights: "^3.3.0",
|
|
98
|
+
"@sample-app/shared": "workspace:*",
|
|
99
|
+
});
|
|
100
|
+
expect(dependencies).not.toHaveProperty("swallowkit");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("adds swallowkit as a generated project devDependency", () => {
|
|
104
|
+
const devDependencies = buildGeneratedProjectDevDependencies();
|
|
105
|
+
|
|
106
|
+
expect(devDependencies).toEqual({
|
|
107
|
+
swallowkit: expect.stringMatching(/.+/),
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("builds a project-scoped MCP config that launches the local swallowkit-mcp entrypoint", () => {
|
|
112
|
+
const source = buildSwallowKitMcpProjectConfigSource();
|
|
113
|
+
const parsed = JSON.parse(source) as {
|
|
114
|
+
mcpServers: {
|
|
115
|
+
swallowkit: {
|
|
116
|
+
command: string;
|
|
117
|
+
args: string[];
|
|
118
|
+
cwd?: string;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
expect(parsed.mcpServers.swallowkit.command).toBe("node");
|
|
124
|
+
expect(parsed.mcpServers.swallowkit.args).toEqual([
|
|
125
|
+
expect.stringMatching(/^\.\/node_modules\/swallowkit\/dist\/mcp\/index\.js$/),
|
|
126
|
+
]);
|
|
127
|
+
expect(parsed.mcpServers.swallowkit.cwd).toBe(".");
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe("parseIgnoredBuilds", () => {
|
|
132
|
+
it("extracts package names from the pnpm warning line", () => {
|
|
133
|
+
const output = [
|
|
134
|
+
"WARN Issues with peer dependencies found",
|
|
135
|
+
" ERR_PNPM_IGNORED_BUILDS Ignored build scripts: sharp@0.34.5, unrs-resolver@1.12.2",
|
|
136
|
+
"run pnpm approve-builds",
|
|
137
|
+
].join("\n");
|
|
138
|
+
expect(parseIgnoredBuilds(output)).toEqual(["sharp", "unrs-resolver"]);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("handles scoped packages and de-duplicates entries", () => {
|
|
142
|
+
const output = "Ignored build scripts: @scope/pkg@1.0.0, sharp@0.34.5, sharp@0.34.5";
|
|
143
|
+
expect(parseIgnoredBuilds(output)).toEqual(["@scope/pkg", "sharp"]);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("returns an empty array when no warning is present", () => {
|
|
147
|
+
expect(parseIgnoredBuilds("everything is fine")).toEqual([]);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe("buildCosmosDbFreeTierBicepSource", () => {
|
|
152
|
+
it("keeps database-level shared throughput at 1000 RU/s for Free Tier", () => {
|
|
153
|
+
const source = buildCosmosDbFreeTierBicepSource();
|
|
154
|
+
|
|
155
|
+
expect(source).toContain("throughput: 1000");
|
|
156
|
+
expect(source).not.toContain("containers");
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe("GitHub Actions workflow generation", () => {
|
|
161
|
+
it("uses npm install for the SWA workflow when the project was initialized with pnpm", () => {
|
|
162
|
+
const workflow = buildGitHubSwaWorkflow("npm", "pnpm");
|
|
163
|
+
|
|
164
|
+
expect(workflow).toContain("npm install && npm run build");
|
|
165
|
+
expect(workflow).not.toContain("npm ci && npm run build");
|
|
166
|
+
expect(workflow).not.toContain("pnpm/action-setup");
|
|
167
|
+
expect(workflow).not.toContain("pnpm install --frozen-lockfile");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("uses npm install for the Functions workflow when the project was initialized with pnpm", () => {
|
|
171
|
+
const workflow = getGitHubFunctionsWorkflow("npm", "typescript", "pnpm");
|
|
172
|
+
|
|
173
|
+
expect(workflow).toContain("npm install");
|
|
174
|
+
expect(workflow).not.toContain("npm ci");
|
|
175
|
+
expect(workflow).toContain("npm run --workspace=shared build");
|
|
176
|
+
expect(workflow).toContain("npm run --workspace=functions build");
|
|
177
|
+
expect(workflow).not.toContain("pnpm/action-setup");
|
|
178
|
+
expect(workflow).not.toContain("pnpm install --frozen-lockfile");
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("uses npm install for the SWA pipeline when the project was initialized with pnpm", () => {
|
|
182
|
+
const pipeline = buildAzureSwaPipeline("npm", "pnpm");
|
|
183
|
+
|
|
184
|
+
expect(pipeline).toContain("npm install");
|
|
185
|
+
expect(pipeline).not.toContain("npm ci");
|
|
186
|
+
expect(pipeline).toContain("npm run build");
|
|
187
|
+
expect(pipeline).not.toContain("corepack enable");
|
|
188
|
+
expect(pipeline).not.toContain("pnpm install --frozen-lockfile");
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("uses npm install for the Functions pipeline when the project was initialized with pnpm", () => {
|
|
192
|
+
const pipeline = getAzureFunctionsPipeline("npm", "typescript", "pnpm");
|
|
193
|
+
|
|
194
|
+
expect(pipeline).toContain("npm install");
|
|
195
|
+
expect(pipeline).not.toContain("npm ci");
|
|
196
|
+
expect(pipeline).toContain("npm run --workspace=shared build");
|
|
197
|
+
expect(pipeline).toContain("npm run --workspace=functions build");
|
|
198
|
+
expect(pipeline).not.toContain("corepack enable");
|
|
199
|
+
expect(pipeline).not.toContain("pnpm install --frozen-lockfile");
|
|
200
|
+
});
|
|
201
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const describe: typeof import("@jest/globals").describe;
|
|
2
|
+
declare const it: typeof import("@jest/globals").it;
|
|
3
|
+
declare const expect: typeof import("@jest/globals").expect;
|
|
4
|
+
declare const beforeAll: typeof import("@jest/globals").beforeAll;
|
|
5
|
+
declare const afterAll: typeof import("@jest/globals").afterAll;
|
|
6
|
+
declare const beforeEach: typeof import("@jest/globals").beforeEach;
|
|
7
|
+
declare const afterEach: typeof import("@jest/globals").afterEach;
|
|
8
|
+
declare const jest: typeof import("@jest/globals").jest;
|