swallowkit 1.0.0-beta.6 → 1.0.0-beta.60
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 +86 -177
- package/README.md +86 -178
- 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 +163 -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 +19 -81
- package/dist/cli/commands/create-model.js.map +1 -1
- package/dist/cli/commands/dev-seeds.d.ts +62 -0
- package/dist/cli/commands/dev-seeds.d.ts.map +1 -0
- package/dist/cli/commands/dev-seeds.js +474 -0
- package/dist/cli/commands/dev-seeds.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +38 -0
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +733 -155
- 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 +78 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +1453 -898
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/scaffold.d.ts +24 -0
- package/dist/cli/commands/scaffold.d.ts.map +1 -1
- package/dist/cli/commands/scaffold.js +473 -90
- 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 +333 -55
- package/dist/cli/index.js.map +1 -1
- package/dist/core/config.d.ts +14 -3
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +179 -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 +159 -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 +7 -1
- package/dist/core/scaffold/functions-generator.d.ts.map +1 -1
- package/dist/core/scaffold/functions-generator.js +771 -69
- package/dist/core/scaffold/functions-generator.js.map +1 -1
- package/dist/core/scaffold/model-parser.d.ts +21 -1
- package/dist/core/scaffold/model-parser.d.ts.map +1 -1
- package/dist/core/scaffold/model-parser.js +243 -43
- 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 +153 -9
- 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 +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/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 +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 +109 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/package-manager.d.ts +5 -2
- package/dist/utils/package-manager.d.ts.map +1 -1
- package/dist/utils/package-manager.js +30 -9
- 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 +9 -5
- package/src/__tests__/__snapshots__/functions-generator.test.ts.snap +1139 -0
- package/src/__tests__/__snapshots__/nextjs-generator.test.ts.snap +206 -0
- package/src/__tests__/__snapshots__/ui-generator.test.ts.snap +532 -0
- 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 +295 -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__/cosmos-worktree-isolation.test.ts +149 -0
- package/src/__tests__/dev-seeds.test.ts +236 -0
- package/src/__tests__/dev.test.ts +296 -0
- package/src/__tests__/file-session.test.ts +98 -0
- package/src/__tests__/fixtures.ts +184 -0
- package/src/__tests__/functions-generator.test.ts +237 -0
- package/src/__tests__/init.test.ts +411 -0
- 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 +81 -0
- package/src/__tests__/multi-auth.test.ts +160 -0
- package/src/__tests__/nextjs-generator.test.ts +105 -0
- package/src/__tests__/openapi-generator.test.ts +43 -0
- package/src/__tests__/package-manager.test.ts +227 -0
- package/src/__tests__/plan-apply.test.ts +499 -0
- package/src/__tests__/python-uv.test.ts +48 -0
- package/src/__tests__/scaffold.test.ts +302 -0
- package/src/__tests__/string-utils.test.ts +75 -0
- package/src/__tests__/tsconfig.json +15 -0
- package/src/__tests__/ui-generator.test.ts +248 -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 +158 -0
- package/src/cli/commands/cosmos-worktree-isolation.ts +130 -0
- package/src/cli/commands/create-model.ts +62 -0
- package/src/cli/commands/dev-seeds.ts +629 -0
- package/src/cli/commands/dev.ts +1252 -0
- package/src/cli/commands/index.ts +9 -0
- package/src/cli/commands/init.ts +3541 -0
- package/src/cli/commands/provision.ts +193 -0
- package/src/cli/commands/scaffold.ts +1081 -0
- package/src/cli/index.ts +350 -0
- package/src/core/config.ts +380 -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/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 +502 -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 +972 -0
- package/src/core/scaffold/model-parser.ts +854 -0
- package/src/core/scaffold/native-schema-generator.ts +904 -0
- package/src/core/scaffold/nextjs-generator.ts +382 -0
- package/src/core/scaffold/openapi-generator.ts +212 -0
- package/src/core/scaffold/ui-generator.ts +1100 -0
- package/src/core/verify/index.ts +468 -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 +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 +182 -0
- package/src/utils/package-manager.ts +246 -0
- package/src/utils/python-uv.ts +96 -0
- package/src/version.ts +13 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { createRequire } from "module";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { AuthConfig, AuthProvider, BackendLanguage, ConnectorDefinition, NormalizedAuthConfig, SwallowKitConfig } from "../types";
|
|
5
|
+
import { detectFromProject, getCommands } from "../utils/package-manager";
|
|
6
|
+
|
|
7
|
+
const requireFromHere = createRequire(__filename);
|
|
8
|
+
|
|
9
|
+
function unwrapConfigModule(
|
|
10
|
+
loadedConfig: Partial<SwallowKitConfig> | { default?: Partial<SwallowKitConfig> }
|
|
11
|
+
): Partial<SwallowKitConfig> {
|
|
12
|
+
if (typeof loadedConfig === "object" && loadedConfig !== null && "default" in loadedConfig) {
|
|
13
|
+
return loadedConfig.default ?? {};
|
|
14
|
+
}
|
|
15
|
+
return loadedConfig as Partial<SwallowKitConfig>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const VALID_BACKEND_LANGUAGES: BackendLanguage[] = ["typescript", "csharp", "python"];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* デフォルト設定
|
|
22
|
+
*/
|
|
23
|
+
const DEFAULT_CONFIG: SwallowKitConfig = {
|
|
24
|
+
database: {},
|
|
25
|
+
backend: {
|
|
26
|
+
language: "typescript",
|
|
27
|
+
},
|
|
28
|
+
api: {
|
|
29
|
+
endpoint: "/api/_swallowkit",
|
|
30
|
+
cors: {
|
|
31
|
+
origin: "*",
|
|
32
|
+
credentials: true,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 設定ファイルを読み込み
|
|
39
|
+
*/
|
|
40
|
+
export function loadConfig(configPath?: string, throwOnError = false, quiet = false): SwallowKitConfig {
|
|
41
|
+
const defaultPaths = [
|
|
42
|
+
"swallowkit.config.json",
|
|
43
|
+
"swallowkit.config.js",
|
|
44
|
+
".swallowkitrc.json",
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
const paths = configPath ? [configPath] : defaultPaths;
|
|
48
|
+
|
|
49
|
+
for (const filePath of paths) {
|
|
50
|
+
const fullPath = path.resolve(process.cwd(), filePath);
|
|
51
|
+
|
|
52
|
+
if (fs.existsSync(fullPath)) {
|
|
53
|
+
try {
|
|
54
|
+
if (!quiet) console.log(`📋 設定ファイルを読み込み: ${filePath}`);
|
|
55
|
+
|
|
56
|
+
if (filePath.endsWith(".json")) {
|
|
57
|
+
const configData = fs.readFileSync(fullPath, "utf-8");
|
|
58
|
+
const userConfig = JSON.parse(configData);
|
|
59
|
+
return mergeConfig(DEFAULT_CONFIG, userConfig);
|
|
60
|
+
} else if (filePath.endsWith(".js")) {
|
|
61
|
+
delete requireFromHere.cache[fullPath];
|
|
62
|
+
const loadedConfig = requireFromHere(fullPath) as Partial<SwallowKitConfig> | { default?: Partial<SwallowKitConfig> };
|
|
63
|
+
return mergeConfig(DEFAULT_CONFIG, unwrapConfigModule(loadedConfig));
|
|
64
|
+
}
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if (throwOnError) throw error;
|
|
67
|
+
if (!quiet) console.warn(`⚠️ 設定ファイルの読み込みに失敗: ${filePath}`, error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!quiet) console.log("📋 デフォルト設定を使用");
|
|
73
|
+
return DEFAULT_CONFIG;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 設定をマージ
|
|
78
|
+
*/
|
|
79
|
+
function mergeConfig(defaultConfig: SwallowKitConfig, userConfig: Partial<SwallowKitConfig>): SwallowKitConfig {
|
|
80
|
+
return {
|
|
81
|
+
database: {
|
|
82
|
+
...defaultConfig.database,
|
|
83
|
+
...userConfig.database,
|
|
84
|
+
},
|
|
85
|
+
backend: {
|
|
86
|
+
...defaultConfig.backend,
|
|
87
|
+
...userConfig.backend,
|
|
88
|
+
},
|
|
89
|
+
api: {
|
|
90
|
+
...defaultConfig.api,
|
|
91
|
+
...userConfig.api,
|
|
92
|
+
cors: {
|
|
93
|
+
...defaultConfig.api?.cors,
|
|
94
|
+
...userConfig.api?.cors,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
connectors: userConfig.connectors ?? defaultConfig.connectors,
|
|
98
|
+
auth: userConfig.auth
|
|
99
|
+
? { ...defaultConfig.auth, ...userConfig.auth }
|
|
100
|
+
: defaultConfig.auth,
|
|
101
|
+
verify: userConfig.verify ?? defaultConfig.verify,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 設定ファイルを生成
|
|
107
|
+
*/
|
|
108
|
+
export function generateConfig(outputPath: string = "swallowkit.config.json"): void {
|
|
109
|
+
const config = {
|
|
110
|
+
$schema: "https://swallowkit.dev/schema.json",
|
|
111
|
+
database: {
|
|
112
|
+
connectionString: "your-cosmos-connection-string",
|
|
113
|
+
databaseName: "SwallowKitDB",
|
|
114
|
+
},
|
|
115
|
+
backend: {
|
|
116
|
+
language: "typescript",
|
|
117
|
+
},
|
|
118
|
+
api: {
|
|
119
|
+
endpoint: "/api/_swallowkit",
|
|
120
|
+
cors: {
|
|
121
|
+
origin: ["http://localhost:3000"],
|
|
122
|
+
credentials: true,
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
fs.writeFileSync(outputPath, JSON.stringify(config, null, 2));
|
|
128
|
+
console.log(`✅ 設定ファイルを生成しました: ${outputPath}`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 環境変数からの設定読み込み
|
|
133
|
+
*/
|
|
134
|
+
export function loadConfigFromEnv(): Partial<SwallowKitConfig> {
|
|
135
|
+
const config: Partial<SwallowKitConfig> = {};
|
|
136
|
+
|
|
137
|
+
// データベース設定
|
|
138
|
+
if (process.env.SWALLOWKIT_DB_CONNECTION_STRING) {
|
|
139
|
+
config.database = {
|
|
140
|
+
...config.database,
|
|
141
|
+
connectionString: process.env.SWALLOWKIT_DB_CONNECTION_STRING,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (process.env.SWALLOWKIT_DB_NAME) {
|
|
146
|
+
config.database = {
|
|
147
|
+
...config.database,
|
|
148
|
+
databaseName: process.env.SWALLOWKIT_DB_NAME,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// API設定
|
|
153
|
+
if (process.env.SWALLOWKIT_API_ENDPOINT) {
|
|
154
|
+
config.api = {
|
|
155
|
+
...config.api,
|
|
156
|
+
endpoint: process.env.SWALLOWKIT_API_ENDPOINT,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (process.env.SWALLOWKIT_BACKEND_LANGUAGE) {
|
|
161
|
+
config.backend = {
|
|
162
|
+
...config.backend,
|
|
163
|
+
language: process.env.SWALLOWKIT_BACKEND_LANGUAGE as BackendLanguage,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return config;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function getBackendLanguage(configPath?: string): BackendLanguage {
|
|
171
|
+
const language = getFullConfig(configPath).backend?.language;
|
|
172
|
+
if (language && VALID_BACKEND_LANGUAGES.includes(language)) {
|
|
173
|
+
return language;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return "typescript";
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* 完全な設定を取得(ファイル + 環境変数)
|
|
181
|
+
*/
|
|
182
|
+
export function getFullConfig(configPath?: string): SwallowKitConfig {
|
|
183
|
+
const fileConfig = loadConfig(configPath);
|
|
184
|
+
const envConfig = loadConfigFromEnv();
|
|
185
|
+
|
|
186
|
+
return mergeConfig(fileConfig, envConfig);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* コネクタ定義を名前で取得
|
|
191
|
+
*/
|
|
192
|
+
export function getConnectorDefinition(connectorName: string, configPath?: string): ConnectorDefinition | undefined {
|
|
193
|
+
const config = getFullConfig(configPath);
|
|
194
|
+
return config.connectors?.[connectorName];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 認証設定を取得
|
|
199
|
+
*/
|
|
200
|
+
export function getAuthConfig(configPath?: string): AuthConfig | undefined {
|
|
201
|
+
const config = getFullConfig(configPath);
|
|
202
|
+
return config.auth;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Load configuration for mutating/generation commands and fail instead of silently falling back. */
|
|
206
|
+
export function getValidatedFullConfig(configPath?: string): SwallowKitConfig {
|
|
207
|
+
const config = mergeConfig(loadConfig(configPath, true), loadConfigFromEnv());
|
|
208
|
+
const validation = validateConfig(config);
|
|
209
|
+
if (!validation.valid) throw new Error(`Invalid SwallowKit configuration:\n${validation.errors.map(error => `- ${error}`).join("\n")}`);
|
|
210
|
+
return config;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const VALID_AUTH_PROVIDERS: AuthProvider[] = ["custom-jwt", "swa", "external-token", "swa-custom", "none"];
|
|
214
|
+
const AUTH_NAME = /^[A-Za-z][A-Za-z0-9_-]*$/;
|
|
215
|
+
|
|
216
|
+
/** Convert the legacy single-provider shape to the canonical named-scheme shape. */
|
|
217
|
+
export function normalizeAuthConfig(auth?: AuthConfig): NormalizedAuthConfig | undefined {
|
|
218
|
+
if (!auth) return undefined;
|
|
219
|
+
const schemes = { ...(auth.schemes ?? {}) };
|
|
220
|
+
if (auth.provider && auth.provider !== "none" && !schemes.default) {
|
|
221
|
+
schemes.default = { provider: auth.provider, customJwt: auth.customJwt, swa: auth.swa };
|
|
222
|
+
}
|
|
223
|
+
const rawDefault = auth.authorization?.defaultPolicy ?? (Object.keys(schemes).length ? "authenticated" : "anonymous");
|
|
224
|
+
return {
|
|
225
|
+
...auth,
|
|
226
|
+
schemes,
|
|
227
|
+
authorization: {
|
|
228
|
+
...auth.authorization,
|
|
229
|
+
defaultPolicy: rawDefault === "public" ? "anonymous" : rawDefault,
|
|
230
|
+
policies: { ...(auth.authorization?.policies ?? {}) },
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function getNormalizedAuthConfig(configPath?: string): NormalizedAuthConfig | undefined {
|
|
236
|
+
return normalizeAuthConfig(getAuthConfig(configPath));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* 設定の検証
|
|
241
|
+
*/
|
|
242
|
+
const VALID_CONNECTOR_TYPES = ["rdb", "api"];
|
|
243
|
+
const VALID_RDB_PROVIDERS = ["mysql", "postgres", "sqlserver"];
|
|
244
|
+
const VALID_API_AUTH_TYPES = ["apiKey", "bearer", "oauth2"];
|
|
245
|
+
|
|
246
|
+
function hasConfiguredDatabase(config: SwallowKitConfig): boolean {
|
|
247
|
+
return Boolean(config.database && Object.keys(config.database).length > 0);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function validateConfig(config: SwallowKitConfig): { valid: boolean; errors: string[] } {
|
|
251
|
+
const errors: string[] = [];
|
|
252
|
+
|
|
253
|
+
const auth = normalizeAuthConfig(config.auth);
|
|
254
|
+
if (auth) {
|
|
255
|
+
for (const [name, scheme] of Object.entries(auth.schemes)) {
|
|
256
|
+
const base = `auth.schemes.${name}`;
|
|
257
|
+
if (!AUTH_NAME.test(name)) errors.push(`${base}: scheme name must match ${AUTH_NAME}; rename the scheme`);
|
|
258
|
+
if (!VALID_AUTH_PROVIDERS.includes(scheme.provider)) errors.push(`${base}.provider: unsupported provider '${scheme.provider}'; use ${VALID_AUTH_PROVIDERS.join(", ")}`);
|
|
259
|
+
if (scheme.provider === "none" || scheme.provider === "swa-custom") errors.push(`${base}.provider: '${scheme.provider}' cannot be used as a named scheme; use swa, external-token, or custom-jwt`);
|
|
260
|
+
if (scheme.provider === "custom-jwt") {
|
|
261
|
+
const jwt = scheme.customJwt ?? (name === "default" ? auth.customJwt : undefined);
|
|
262
|
+
for (const key of ["userConnector", "userTable", "loginIdColumn", "passwordHashColumn", "rolesColumn"] as const) {
|
|
263
|
+
if (!jwt?.[key]) errors.push(`${base}.customJwt.${key}: required for custom-jwt; configure this value`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
for (const [name, policy] of Object.entries(auth.authorization.policies)) {
|
|
268
|
+
const base = `auth.authorization.policies.${name}`;
|
|
269
|
+
if (!AUTH_NAME.test(name)) errors.push(`${base}: policy name must match ${AUTH_NAME}; rename the policy`);
|
|
270
|
+
if (!Array.isArray(policy.schemes) || policy.schemes.length === 0) errors.push(`${base}.schemes: provide at least one named scheme`);
|
|
271
|
+
for (const scheme of policy.schemes ?? []) if (!auth.schemes[scheme]) errors.push(`${base}.schemes: undefined scheme '${scheme}'; define auth.schemes.${scheme}`);
|
|
272
|
+
const sources = new Map<string, string>();
|
|
273
|
+
for (const schemeName of policy.schemes ?? []) {
|
|
274
|
+
const provider = auth.schemes[schemeName]?.provider;
|
|
275
|
+
const source = provider === "swa" ? "x-ms-client-principal" : provider === "custom-jwt" || provider === "external-token" ? "authorization-bearer" : provider;
|
|
276
|
+
if (source && sources.has(source)) errors.push(`${base}.schemes: '${sources.get(source)}' and '${schemeName}' both use ${source}; split the policy so credential selection is deterministic`);
|
|
277
|
+
else if (source) sources.set(source, schemeName);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const defaultPolicy = auth.authorization.defaultPolicy;
|
|
281
|
+
if (defaultPolicy === "authenticated" && !auth.schemes.default && Object.keys(auth.schemes).length !== 1) errors.push("auth.authorization.defaultPolicy: 'authenticated' requires auth.schemes.default (or exactly one scheme); set a default scheme or use a named policy");
|
|
282
|
+
else if (!["anonymous", "authenticated"].includes(defaultPolicy) && !auth.authorization.policies[defaultPolicy]) errors.push(`auth.authorization.defaultPolicy: undefined policy '${defaultPolicy}'; define auth.authorization.policies.${defaultPolicy}`);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// データベース設定の検証
|
|
286
|
+
if (hasConfiguredDatabase(config) && !config.database?.connectionString) {
|
|
287
|
+
errors.push("Cosmos DB connection string is required");
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// API設定の検証
|
|
291
|
+
if (config.api?.endpoint && !config.api.endpoint.startsWith("/")) {
|
|
292
|
+
errors.push("API endpoint must start with '/'");
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (config.backend?.language && !VALID_BACKEND_LANGUAGES.includes(config.backend.language)) {
|
|
296
|
+
errors.push("Backend language must be one of: typescript, csharp, python");
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// コネクタ設定の検証
|
|
300
|
+
if (config.connectors) {
|
|
301
|
+
for (const [name, connector] of Object.entries(config.connectors)) {
|
|
302
|
+
if (!VALID_CONNECTOR_TYPES.includes(connector.type)) {
|
|
303
|
+
errors.push(`Connector '${name}': type must be one of: ${VALID_CONNECTOR_TYPES.join(", ")}`);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (connector.type === "rdb") {
|
|
308
|
+
if (!connector.provider || !VALID_RDB_PROVIDERS.includes(connector.provider)) {
|
|
309
|
+
errors.push(`Connector '${name}': provider must be one of: ${VALID_RDB_PROVIDERS.join(", ")}`);
|
|
310
|
+
}
|
|
311
|
+
if (!connector.connectionEnvVar) {
|
|
312
|
+
errors.push(`Connector '${name}': connectionEnvVar is required`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (connector.type === "api") {
|
|
317
|
+
if (!connector.baseUrlEnvVar) {
|
|
318
|
+
errors.push(`Connector '${name}': baseUrlEnvVar is required`);
|
|
319
|
+
}
|
|
320
|
+
if (connector.auth && !VALID_API_AUTH_TYPES.includes(connector.auth.type)) {
|
|
321
|
+
errors.push(`Connector '${name}': auth.type must be one of: ${VALID_API_AUTH_TYPES.join(", ")}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return {
|
|
328
|
+
valid: errors.length === 0,
|
|
329
|
+
errors,
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* SwallowKit プロジェクトディレクトリかどうかを検証するための設定ファイルパス一覧
|
|
335
|
+
*/
|
|
336
|
+
const SWALLOWKIT_PROJECT_MARKERS = [
|
|
337
|
+
"swallowkit.config.js",
|
|
338
|
+
"swallowkit.config.json",
|
|
339
|
+
".swallowkitrc.json",
|
|
340
|
+
];
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* 現在のディレクトリが SwallowKit プロジェクトディレクトリかどうかを検証
|
|
344
|
+
* @param projectRoot 検証するディレクトリパス(省略時は process.cwd())
|
|
345
|
+
* @returns プロジェクトが有効な場合は true、無効な場合は false
|
|
346
|
+
*/
|
|
347
|
+
export function isSwallowKitProject(projectRoot?: string): boolean {
|
|
348
|
+
const cwd = projectRoot || process.cwd();
|
|
349
|
+
|
|
350
|
+
// swallowkit 設定ファイルの存在をチェック
|
|
351
|
+
for (const marker of SWALLOWKIT_PROJECT_MARKERS) {
|
|
352
|
+
const markerPath = path.resolve(cwd, marker);
|
|
353
|
+
if (fs.existsSync(markerPath)) {
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* SwallowKit プロジェクトディレクトリかどうかを検証し、無効な場合はエラーメッセージを表示して終了
|
|
363
|
+
* init 以外のコマンドの冒頭で呼び出すこと
|
|
364
|
+
* @param commandName コマンド名(エラーメッセージ用)
|
|
365
|
+
* @param projectRoot 検証するディレクトリパス(省略時は process.cwd())
|
|
366
|
+
*/
|
|
367
|
+
export function ensureSwallowKitProject(commandName: string, projectRoot?: string): void {
|
|
368
|
+
if (!isSwallowKitProject(projectRoot)) {
|
|
369
|
+
console.error(`❌ Error: This directory is not a SwallowKit project.`);
|
|
370
|
+
console.error(`\n The '${commandName}' command must be run from a SwallowKit project directory.`);
|
|
371
|
+
console.error(` A SwallowKit project should contain one of the following files:`);
|
|
372
|
+
for (const marker of SWALLOWKIT_PROJECT_MARKERS) {
|
|
373
|
+
console.error(` - ${marker}`);
|
|
374
|
+
}
|
|
375
|
+
const pmCmd = getCommands(detectFromProject());
|
|
376
|
+
console.error(`\n💡 Tip: Run '${pmCmd.dlx} swallowkit init' first to create a new SwallowKit project,`);
|
|
377
|
+
console.error(` or navigate to an existing SwallowKit project directory.`);
|
|
378
|
+
process.exit(1);
|
|
379
|
+
}
|
|
380
|
+
}
|