swallowkit 1.0.0-beta.8 → 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.
- package/README.ja.md +87 -181
- package/README.md +87 -238
- package/dist/__tests__/fixtures.d.ts +12 -0
- package/dist/__tests__/fixtures.d.ts.map +1 -1
- package/dist/__tests__/fixtures.js +101 -0
- package/dist/__tests__/fixtures.js.map +1 -1
- package/dist/cli/commands/add-auth.d.ts +15 -0
- package/dist/cli/commands/add-auth.d.ts.map +1 -0
- package/dist/cli/commands/add-auth.js +790 -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 +164 -0
- package/dist/cli/commands/add-connector.js.map +1 -0
- package/dist/cli/commands/cosmos-worktree-isolation.d.ts +25 -0
- package/dist/cli/commands/cosmos-worktree-isolation.d.ts.map +1 -0
- package/dist/cli/commands/cosmos-worktree-isolation.js +124 -0
- package/dist/cli/commands/cosmos-worktree-isolation.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 +20 -82
- package/dist/cli/commands/create-model.js.map +1 -1
- package/dist/cli/commands/dev-seeds.d.ts +27 -0
- package/dist/cli/commands/dev-seeds.d.ts.map +1 -1
- package/dist/cli/commands/dev-seeds.js +188 -6
- package/dist/cli/commands/dev-seeds.js.map +1 -1
- package/dist/cli/commands/dev.d.ts +30 -0
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +495 -129
- package/dist/cli/commands/dev.js.map +1 -1
- package/dist/cli/commands/init.d.ts +70 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +797 -768
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/scaffold.d.ts +24 -3
- package/dist/cli/commands/scaffold.d.ts.map +1 -1
- package/dist/cli/commands/scaffold.js +408 -189
- 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 +335 -58
- package/dist/cli/index.js.map +1 -1
- package/dist/core/config.d.ts +13 -3
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +151 -8
- 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/auth-operations.d.ts +61 -0
- package/dist/core/operations/auth-operations.d.ts.map +1 -0
- package/dist/core/operations/auth-operations.js +272 -0
- package/dist/core/operations/auth-operations.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 +185 -0
- package/dist/core/operations/create-model.js.map +1 -0
- package/dist/core/operations/file-session.d.ts +56 -0
- package/dist/core/operations/file-session.d.ts.map +1 -0
- package/dist/core/operations/file-session.js +203 -0
- package/dist/core/operations/file-session.js.map +1 -0
- package/dist/core/operations/provision-operations.d.ts +52 -0
- package/dist/core/operations/provision-operations.d.ts.map +1 -0
- package/dist/core/operations/provision-operations.js +211 -0
- package/dist/core/operations/provision-operations.js.map +1 -0
- package/dist/core/operations/runtime.d.ts +37 -0
- package/dist/core/operations/runtime.d.ts.map +1 -0
- package/dist/core/operations/runtime.js +248 -0
- package/dist/core/operations/runtime.js.map +1 -0
- package/dist/core/operations/scaffold-apply.d.ts +21 -0
- package/dist/core/operations/scaffold-apply.d.ts.map +1 -0
- package/dist/core/operations/scaffold-apply.js +57 -0
- package/dist/core/operations/scaffold-apply.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 +51 -0
- package/dist/core/operations/scaffold-machine.js.map +1 -0
- package/dist/core/operations/scaffold-plan.d.ts +43 -0
- package/dist/core/operations/scaffold-plan.d.ts.map +1 -0
- package/dist/core/operations/scaffold-plan.js +187 -0
- package/dist/core/operations/scaffold-plan.js.map +1 -0
- package/dist/core/project/agent-instructions.d.ts +29 -0
- package/dist/core/project/agent-instructions.d.ts.map +1 -0
- package/dist/core/project/agent-instructions.js +160 -0
- package/dist/core/project/agent-instructions.js.map +1 -0
- package/dist/core/project/artifacts.d.ts +58 -0
- package/dist/core/project/artifacts.d.ts.map +1 -0
- package/dist/core/project/artifacts.js +179 -0
- package/dist/core/project/artifacts.js.map +1 -0
- package/dist/core/project/boundaries.d.ts +50 -0
- package/dist/core/project/boundaries.d.ts.map +1 -0
- package/dist/core/project/boundaries.js +117 -0
- package/dist/core/project/boundaries.js.map +1 -0
- package/dist/core/project/capabilities.d.ts +58 -0
- package/dist/core/project/capabilities.d.ts.map +1 -0
- package/dist/core/project/capabilities.js +135 -0
- package/dist/core/project/capabilities.js.map +1 -0
- package/dist/core/project/drift.d.ts +29 -0
- package/dist/core/project/drift.d.ts.map +1 -0
- package/dist/core/project/drift.js +188 -0
- package/dist/core/project/drift.js.map +1 -0
- package/dist/core/project/infra.d.ts +49 -0
- package/dist/core/project/infra.d.ts.map +1 -0
- package/dist/core/project/infra.js +167 -0
- package/dist/core/project/infra.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/state.d.ts +15 -0
- package/dist/core/project/state.d.ts.map +1 -0
- package/dist/core/project/state.js +106 -0
- package/dist/core/project/state.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 +274 -0
- package/dist/core/project/validation.js.map +1 -0
- package/dist/core/project/workflows.d.ts +43 -0
- package/dist/core/project/workflows.d.ts.map +1 -0
- package/dist/core/project/workflows.js +299 -0
- package/dist/core/project/workflows.js.map +1 -0
- package/dist/core/scaffold/auth-generator.d.ts +63 -0
- package/dist/core/scaffold/auth-generator.d.ts.map +1 -0
- package/dist/core/scaffold/auth-generator.js +1774 -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 +1029 -0
- package/dist/core/scaffold/connector-functions-generator.js.map +1 -0
- package/dist/core/scaffold/functions-generator.d.ts +4 -3
- package/dist/core/scaffold/functions-generator.d.ts.map +1 -1
- package/dist/core/scaffold/functions-generator.js +405 -134
- package/dist/core/scaffold/functions-generator.js.map +1 -1
- package/dist/core/scaffold/model-parser.d.ts +20 -0
- package/dist/core/scaffold/model-parser.d.ts.map +1 -1
- package/dist/core/scaffold/model-parser.js +229 -78
- package/dist/core/scaffold/model-parser.js.map +1 -1
- package/dist/core/scaffold/native-schema-generator.d.ts +19 -0
- package/dist/core/scaffold/native-schema-generator.d.ts.map +1 -0
- package/dist/core/scaffold/native-schema-generator.js +753 -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 +152 -8
- package/dist/core/scaffold/nextjs-generator.js.map +1 -1
- package/dist/core/scaffold/ui-generator.d.ts +17 -4
- package/dist/core/scaffold/ui-generator.d.ts.map +1 -1
- package/dist/core/scaffold/ui-generator.js +174 -34
- package/dist/core/scaffold/ui-generator.js.map +1 -1
- package/dist/core/verify/index.d.ts +69 -0
- package/dist/core/verify/index.d.ts.map +1 -0
- package/dist/core/verify/index.js +412 -0
- package/dist/core/verify/index.js.map +1 -0
- package/dist/machine/contracts.d.ts +24 -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 +14 -0
- package/dist/machine/errors.d.ts.map +1 -0
- package/dist/machine/errors.js +42 -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 +566 -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 +425 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/types/index.d.ts +105 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/package-manager.d.ts +7 -11
- package/dist/utils/package-manager.d.ts.map +1 -1
- package/dist/utils/package-manager.js +42 -17
- package/dist/utils/package-manager.js.map +1 -1
- 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/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +49 -0
- package/dist/version.js.map +1 -0
- package/package.json +15 -17
- package/src/__tests__/__snapshots__/functions-generator.test.ts.snap +716 -22
- package/src/__tests__/__snapshots__/nextjs-generator.test.ts.snap +19 -7
- package/src/__tests__/__snapshots__/ui-generator.test.ts.snap +20 -12
- package/src/__tests__/agent-instructions.test.ts +237 -0
- package/src/__tests__/agent-loop-phase34.test.ts +513 -0
- package/src/__tests__/auth.test.ts +770 -0
- package/src/__tests__/bff-swa-auth.test.ts +275 -0
- package/src/__tests__/config.test.ts +176 -3
- package/src/__tests__/connector-functions-generator.test.ts +288 -0
- package/src/__tests__/connector-mock-server.test.ts +459 -0
- package/src/__tests__/connector-model-bff.test.ts +162 -0
- package/src/__tests__/cosmos-worktree-isolation.test.ts +149 -0
- package/src/__tests__/dev-seeds.test.ts +124 -0
- package/src/__tests__/dev.test.ts +254 -0
- package/src/__tests__/file-session.test.ts +98 -0
- package/src/__tests__/fixtures.ts +101 -0
- package/src/__tests__/functions-generator.test.ts +137 -1
- package/src/__tests__/init.test.ts +386 -1
- package/src/__tests__/jest-globals.d.ts +8 -0
- package/src/__tests__/machine.test.ts +371 -0
- package/src/__tests__/mcp.test.ts +253 -0
- package/src/__tests__/model-parser.test.ts +142 -0
- package/src/__tests__/multi-auth.test.ts +160 -0
- package/src/__tests__/nextjs-generator.test.ts +8 -0
- package/src/__tests__/package-manager.test.ts +59 -4
- package/src/__tests__/plan-apply.test.ts +499 -0
- package/src/__tests__/python-uv.test.ts +48 -0
- package/src/__tests__/scaffold.test.ts +287 -24
- package/src/__tests__/tsconfig.json +15 -0
- package/src/__tests__/ui-generator.test.ts +104 -0
- package/src/__tests__/zod-mock-generator.test.ts +132 -0
- package/src/cli/commands/add-auth.ts +853 -0
- package/src/cli/commands/add-connector.ts +159 -0
- package/src/cli/commands/cosmos-worktree-isolation.ts +130 -0
- package/src/cli/commands/create-model.ts +21 -100
- package/src/cli/commands/dev-seeds.ts +278 -7
- package/src/cli/commands/dev.ts +607 -160
- package/src/cli/commands/init.ts +880 -808
- package/src/cli/commands/scaffold.ts +531 -236
- package/src/cli/index.ts +338 -60
- package/src/core/config.ts +145 -9
- package/src/core/mock/connector-mock-server.ts +555 -0
- package/src/core/mock/zod-mock-generator.ts +205 -0
- package/src/core/operations/auth-operations.ts +360 -0
- package/src/core/operations/create-model.ts +191 -0
- package/src/core/operations/file-session.ts +222 -0
- package/src/core/operations/provision-operations.ts +297 -0
- package/src/core/operations/runtime.ts +258 -0
- package/src/core/operations/scaffold-apply.ts +106 -0
- package/src/core/operations/scaffold-machine.ts +77 -0
- package/src/core/operations/scaffold-plan.ts +215 -0
- package/src/core/project/agent-instructions.ts +167 -0
- package/src/core/project/agent-templates/AGENTS.md +504 -0
- package/src/core/project/agent-templates/CLAUDE.md +31 -0
- package/src/core/project/agent-templates/azure-functions.instructions.md +22 -0
- package/src/core/project/agent-templates/bff-routes.instructions.md +18 -0
- package/src/core/project/agent-templates/copilot-instructions.md +27 -0
- package/src/core/project/agent-templates/shared-models.instructions.md +72 -0
- package/src/core/project/artifacts.ts +205 -0
- package/src/core/project/boundaries.ts +170 -0
- package/src/core/project/capabilities.ts +193 -0
- package/src/core/project/drift.ts +202 -0
- package/src/core/project/infra.ts +196 -0
- package/src/core/project/manifest.ts +402 -0
- package/src/core/project/state.ts +77 -0
- package/src/core/project/validation.ts +295 -0
- package/src/core/project/workflows.ts +295 -0
- package/src/core/scaffold/auth-generator.ts +1824 -0
- package/src/core/scaffold/connector-functions-generator.ts +1133 -0
- package/src/core/scaffold/functions-generator.ts +432 -134
- package/src/core/scaffold/model-parser.ts +244 -90
- package/src/core/scaffold/native-schema-generator.ts +904 -0
- package/src/core/scaffold/nextjs-generator.ts +174 -9
- package/src/core/scaffold/ui-generator.ts +191 -36
- package/src/core/verify/index.ts +468 -0
- package/src/machine/contracts.ts +33 -0
- package/src/machine/errors.ts +45 -0
- package/src/machine/index.ts +690 -0
- package/src/mcp/index.ts +423 -0
- package/src/types/index.ts +137 -0
- package/src/utils/package-manager.ts +41 -19
- package/src/utils/python-uv.ts +96 -0
- package/src/version.ts +13 -0
|
@@ -21,10 +21,71 @@ export function createBasicModelInfo(overrides?: Partial<ModelInfo>): ModelInfo
|
|
|
21
21
|
hasCreatedAt: true,
|
|
22
22
|
hasUpdatedAt: true,
|
|
23
23
|
nestedSchemaRefs: [],
|
|
24
|
+
partitionKey: '/id',
|
|
24
25
|
...overrides,
|
|
25
26
|
};
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
/**
|
|
30
|
+
* RDB コネクタ (read-only) 付きの ModelInfo フィクスチャ
|
|
31
|
+
*/
|
|
32
|
+
export function createRdbConnectorModelInfo(overrides?: Partial<ModelInfo>): ModelInfo {
|
|
33
|
+
return createBasicModelInfo({
|
|
34
|
+
name: "User",
|
|
35
|
+
displayName: "User",
|
|
36
|
+
schemaName: "userSchema",
|
|
37
|
+
filePath: "/models/user.ts",
|
|
38
|
+
fields: [
|
|
39
|
+
{ name: "id", type: "string", isOptional: false, isArray: false },
|
|
40
|
+
{ name: "employeeCode", type: "string", isOptional: false, isArray: false },
|
|
41
|
+
{ name: "name", type: "string", isOptional: false, isArray: false },
|
|
42
|
+
{ name: "email", type: "string", isOptional: false, isArray: false },
|
|
43
|
+
{ name: "department", type: "string", isOptional: true, isArray: false },
|
|
44
|
+
{ name: "createdAt", type: "string", isOptional: true, isArray: false },
|
|
45
|
+
{ name: "updatedAt", type: "string", isOptional: true, isArray: false },
|
|
46
|
+
],
|
|
47
|
+
connectorConfig: {
|
|
48
|
+
connector: "mysql",
|
|
49
|
+
operations: ["getAll", "getById"],
|
|
50
|
+
table: "users",
|
|
51
|
+
idColumn: "id",
|
|
52
|
+
},
|
|
53
|
+
...overrides,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* API コネクタ (read-write) 付きの ModelInfo フィクスチャ
|
|
59
|
+
*/
|
|
60
|
+
export function createApiConnectorModelInfo(overrides?: Partial<ModelInfo>): ModelInfo {
|
|
61
|
+
return createBasicModelInfo({
|
|
62
|
+
name: "BacklogIssue",
|
|
63
|
+
displayName: "BacklogIssue",
|
|
64
|
+
schemaName: "backlogIssueSchema",
|
|
65
|
+
filePath: "/models/backlog-issue.ts",
|
|
66
|
+
fields: [
|
|
67
|
+
{ name: "id", type: "string", isOptional: false, isArray: false },
|
|
68
|
+
{ name: "projectId", type: "string", isOptional: false, isArray: false },
|
|
69
|
+
{ name: "issueKey", type: "string", isOptional: false, isArray: false },
|
|
70
|
+
{ name: "summary", type: "string", isOptional: false, isArray: false },
|
|
71
|
+
{ name: "description", type: "string", isOptional: true, isArray: false },
|
|
72
|
+
{ name: "createdAt", type: "string", isOptional: true, isArray: false },
|
|
73
|
+
{ name: "updatedAt", type: "string", isOptional: true, isArray: false },
|
|
74
|
+
],
|
|
75
|
+
connectorConfig: {
|
|
76
|
+
connector: "backlog",
|
|
77
|
+
operations: ["getAll", "getById", "create", "update"],
|
|
78
|
+
endpoints: {
|
|
79
|
+
getAll: "GET /issues",
|
|
80
|
+
getById: "GET /issues/{id}",
|
|
81
|
+
create: "POST /issues",
|
|
82
|
+
update: "PATCH /issues/{id}",
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
...overrides,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
28
89
|
/**
|
|
29
90
|
* 外部キーを含む ModelInfo フィクスチャ
|
|
30
91
|
*/
|
|
@@ -51,6 +112,46 @@ export function createModelInfoWithForeignKey(): ModelInfo {
|
|
|
51
112
|
});
|
|
52
113
|
}
|
|
53
114
|
|
|
115
|
+
/**
|
|
116
|
+
* 必須・optional・nullable の外部キーを含む ModelInfo フィクスチャ
|
|
117
|
+
*/
|
|
118
|
+
export function createModelInfoWithNullableForeignKeys(): ModelInfo {
|
|
119
|
+
return createBasicModelInfo({
|
|
120
|
+
name: "Coupon",
|
|
121
|
+
displayName: "Coupon",
|
|
122
|
+
schemaName: "couponSchema",
|
|
123
|
+
filePath: "/models/coupon.ts",
|
|
124
|
+
fields: [
|
|
125
|
+
{ name: "id", type: "string", isOptional: false, isArray: false },
|
|
126
|
+
{
|
|
127
|
+
name: "requiredUserId",
|
|
128
|
+
type: "string",
|
|
129
|
+
isOptional: false,
|
|
130
|
+
isArray: false,
|
|
131
|
+
isForeignKey: true,
|
|
132
|
+
referencedModel: "RequiredUser",
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: "optionalUserId",
|
|
136
|
+
type: "string",
|
|
137
|
+
isOptional: true,
|
|
138
|
+
isArray: false,
|
|
139
|
+
isForeignKey: true,
|
|
140
|
+
referencedModel: "OptionalUser",
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: "nullableUserId",
|
|
144
|
+
type: "string",
|
|
145
|
+
isOptional: false,
|
|
146
|
+
isNullable: true,
|
|
147
|
+
isArray: false,
|
|
148
|
+
isForeignKey: true,
|
|
149
|
+
referencedModel: "NullableUser",
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
54
155
|
/**
|
|
55
156
|
* enum フィールドを含む ModelInfo フィクスチャ
|
|
56
157
|
*/
|
|
@@ -70,7 +70,7 @@ describe("generateCompactAzureFunctionsCRUD", () => {
|
|
|
70
70
|
it("generates C# Cosmos-backed CRUD handlers", () => {
|
|
71
71
|
const model = createBasicModelInfo();
|
|
72
72
|
const code = generateCSharpAzureFunctionsCRUD(model);
|
|
73
|
-
expect(code).toContain("public sealed class
|
|
73
|
+
expect(code).toContain("public sealed class TodoCrudFunctions");
|
|
74
74
|
expect(code).toContain('[Function("todoGetAll")]');
|
|
75
75
|
expect(code).toContain('Route = "todo/{id}"');
|
|
76
76
|
expect(code).toContain("CreateCosmosClient()");
|
|
@@ -98,4 +98,140 @@ describe("generateCompactAzureFunctionsCRUD", () => {
|
|
|
98
98
|
expect(generated.blueprint).toContain("container.replace_item");
|
|
99
99
|
expect(generated.blueprint).toContain("container.delete_item");
|
|
100
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
|
+
});
|
|
101
237
|
});
|