swallowkit 1.0.0-beta.7 → 1.0.0-beta.8

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.md CHANGED
@@ -139,6 +139,62 @@ pnpm dlx swallowkit dev
139
139
  - Next.js: http://localhost:3000
140
140
  - Azure Functions: http://localhost:7071
141
141
 
142
+ If you want to replace Cosmos DB Emulator data before startup, generate an environment template and then launch `dev` with that environment:
143
+
144
+ ```bash
145
+ npx swallowkit create-dev-seeds local
146
+ # edit dev-seeds/local/*.json
147
+ npx swallowkit dev --seed-env local
148
+ ```
149
+
150
+ This workflow is designed for local debugging against the Cosmos DB Emulator:
151
+
152
+ - `create-dev-seeds <environment>` generates one JSON template per schema under `dev-seeds/<environment>/`
153
+ - each file name maps to a schema/container, for example `shared/models/todo.ts` -> `dev-seeds/local/todo.json` -> `Todos`
154
+ - when you start `dev --seed-env <environment>`, SwallowKit replaces the existing data for each matching container with the JSON documents from that environment
155
+ - containers without a matching JSON file are left untouched
156
+ - if `--seed-env` is omitted, or `dev-seeds/<environment>/` does not exist, current emulator data is preserved
157
+
158
+ Example file layout:
159
+
160
+ ```text
161
+ dev-seeds/
162
+ local/
163
+ todo.json
164
+ category.json
165
+ staging-debug/
166
+ todo.json
167
+ ```
168
+
169
+ Each `{schema}.json` file can contain either a single JSON object or an array of JSON objects. Every document must include an `id`:
170
+
171
+ ```json
172
+ [
173
+ {
174
+ "id": "seed-todo-001",
175
+ "name": "Seed todo one",
176
+ "createdAt": "2026-03-21T00:00:00.000Z",
177
+ "updatedAt": "2026-03-21T00:00:00.000Z"
178
+ },
179
+ {
180
+ "id": "seed-todo-002",
181
+ "name": "Seed todo two",
182
+ "createdAt": "2026-03-21T00:00:01.000Z",
183
+ "updatedAt": "2026-03-21T00:00:01.000Z"
184
+ }
185
+ ]
186
+ ```
187
+
188
+ Recommended workflow:
189
+
190
+ ```bash
191
+ npx swallowkit create-model todo
192
+ npx swallowkit scaffold shared/models/todo.ts
193
+ npx swallowkit create-dev-seeds local
194
+ # edit dev-seeds/local/todo.json
195
+ npx swallowkit dev --seed-env local
196
+ ```
197
+
142
198
  ### 5. Use from Frontend
143
199
 
144
200
  ```typescript
@@ -0,0 +1,35 @@
1
+ import { Command } from "commander";
2
+ import { CosmosClient } from "@azure/cosmos";
3
+ import { ModelInfo } from "../../core/scaffold/model-parser";
4
+ export type SeedDocument = Record<string, unknown>;
5
+ interface GenerateDevSeedTemplatesOptions {
6
+ environment: string;
7
+ modelsDir?: string;
8
+ seedsDir?: string;
9
+ force?: boolean;
10
+ }
11
+ interface ApplyDevSeedEnvironmentOptions {
12
+ client: CosmosClient;
13
+ databaseName: string;
14
+ environment: string;
15
+ models: ModelInfo[];
16
+ seedsDir?: string;
17
+ }
18
+ interface LoadedSeedFile {
19
+ model: ModelInfo;
20
+ containerName: string;
21
+ documents: SeedDocument[];
22
+ filePath: string;
23
+ }
24
+ export declare function getContainerNameForModel(model: Pick<ModelInfo, "name">): string;
25
+ export declare function getSeedEnvironmentDir(environment: string, seedsDir?: string): string;
26
+ export declare function normalizeSeedIdentifier(value: string): string;
27
+ export declare function parseSeedDocuments(content: string, filePath: string): SeedDocument[];
28
+ export declare function loadProjectModels(modelsDir?: string): Promise<ModelInfo[]>;
29
+ export declare function buildSeedTemplateDocument(model: ModelInfo, allModels?: ModelInfo[], seenModels?: Set<string>): SeedDocument;
30
+ export declare function loadDevSeedFiles(environment: string, models: ModelInfo[], seedsDir?: string): Promise<LoadedSeedFile[]>;
31
+ export declare function applyDevSeedEnvironment({ client, databaseName, environment, models, seedsDir, }: ApplyDevSeedEnvironmentOptions): Promise<boolean>;
32
+ export declare function generateDevSeedTemplates({ environment, modelsDir, seedsDir, force, }: GenerateDevSeedTemplatesOptions): Promise<void>;
33
+ export declare const devSeedsCommand: Command;
34
+ export {};
35
+ //# sourceMappingURL=dev-seeds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-seeds.d.ts","sourceRoot":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BAAyB,CACvC,KAAK,EAAE,SAAS,EAChB,SAAS,GAAE,SAAS,EAAY,EAChC,UAAU,GAAE,GAAG,CAAC,MAAM,CAAa,GAClC,YAAY,CAGd;AAED,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,SAAS,EAAE,EACnB,QAAQ,GAAE,MAAoB,GAC7B,OAAO,CAAC,cAAc,EAAE,CAAC,CAgC3B;AAED,wBAAsB,uBAAuB,CAAC,EAC5C,MAAM,EACN,YAAY,EACZ,WAAW,EACX,MAAM,EACN,QAAsB,GACvB,EAAE,8BAA8B,GAAG,OAAO,CAAC,OAAO,CAAC,CA+BnD;AAED,wBAAsB,wBAAwB,CAAC,EAC7C,WAAW,EACX,SAA2B,EAC3B,QAAsB,EACtB,KAAa,GACd,EAAE,+BAA+B,GAAG,OAAO,CAAC,IAAI,CAAC,CAuCjD;AAED,eAAO,MAAM,eAAe,SAcxB,CAAC"}
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.devSeedsCommand = void 0;
37
+ exports.getContainerNameForModel = getContainerNameForModel;
38
+ exports.getSeedEnvironmentDir = getSeedEnvironmentDir;
39
+ exports.normalizeSeedIdentifier = normalizeSeedIdentifier;
40
+ exports.parseSeedDocuments = parseSeedDocuments;
41
+ exports.loadProjectModels = loadProjectModels;
42
+ exports.buildSeedTemplateDocument = buildSeedTemplateDocument;
43
+ exports.loadDevSeedFiles = loadDevSeedFiles;
44
+ exports.applyDevSeedEnvironment = applyDevSeedEnvironment;
45
+ exports.generateDevSeedTemplates = generateDevSeedTemplates;
46
+ const commander_1 = require("commander");
47
+ const cosmos_1 = require("@azure/cosmos");
48
+ const fs = __importStar(require("fs"));
49
+ const path = __importStar(require("path"));
50
+ const config_1 = require("../../core/config");
51
+ const model_parser_1 = require("../../core/scaffold/model-parser");
52
+ function getContainerNameForModel(model) {
53
+ return `${model.name}s`;
54
+ }
55
+ function getSeedEnvironmentDir(environment, seedsDir = "dev-seeds") {
56
+ return path.join(process.cwd(), seedsDir, environment);
57
+ }
58
+ function normalizeSeedIdentifier(value) {
59
+ return value.toLowerCase().replace(/[^a-z0-9]/g, "");
60
+ }
61
+ function parseSeedDocuments(content, filePath) {
62
+ const parsed = JSON.parse(content);
63
+ if (Array.isArray(parsed)) {
64
+ return parsed.map((item, index) => {
65
+ if (!isSeedDocument(item)) {
66
+ throw new Error(`${filePath} must contain only JSON objects. Invalid item at index ${index}.`);
67
+ }
68
+ return item;
69
+ });
70
+ }
71
+ if (isSeedDocument(parsed)) {
72
+ return [parsed];
73
+ }
74
+ throw new Error(`${filePath} must contain a JSON object or an array of JSON objects.`);
75
+ }
76
+ async function loadProjectModels(modelsDir = "shared/models") {
77
+ return (0, model_parser_1.getAllModels)(modelsDir);
78
+ }
79
+ function buildSeedTemplateDocument(model, allModels = [model], seenModels = new Set()) {
80
+ const modelLookup = new Map(allModels.map((candidate) => [candidate.name, candidate]));
81
+ return buildSeedTemplateDocumentInternal(model, modelLookup, seenModels);
82
+ }
83
+ async function loadDevSeedFiles(environment, models, seedsDir = "dev-seeds") {
84
+ const environmentDir = getSeedEnvironmentDir(environment, seedsDir);
85
+ if (!fs.existsSync(environmentDir)) {
86
+ return [];
87
+ }
88
+ const modelAliases = buildModelAliasMap(models);
89
+ const seedFiles = fs.readdirSync(environmentDir).filter((entry) => entry.endsWith(".json"));
90
+ const loaded = [];
91
+ for (const fileName of seedFiles) {
92
+ const filePath = path.join(environmentDir, fileName);
93
+ const fileStem = path.basename(fileName, ".json");
94
+ const model = modelAliases.get(normalizeSeedIdentifier(fileStem));
95
+ if (!model) {
96
+ console.warn(`⚠️ Skipping seed file without matching schema: ${filePath}`);
97
+ continue;
98
+ }
99
+ const documents = parseSeedDocuments(fs.readFileSync(filePath, "utf-8"), filePath);
100
+ validateSeedDocuments(documents, filePath);
101
+ loaded.push({
102
+ model,
103
+ containerName: getContainerNameForModel(model),
104
+ documents,
105
+ filePath,
106
+ });
107
+ }
108
+ return loaded;
109
+ }
110
+ async function applyDevSeedEnvironment({ client, databaseName, environment, models, seedsDir = "dev-seeds", }) {
111
+ const environmentDir = getSeedEnvironmentDir(environment, seedsDir);
112
+ if (!fs.existsSync(environmentDir)) {
113
+ console.log(`ℹ️ Seed environment "${environment}" not found at ${environmentDir}. Keeping existing Cosmos DB data.`);
114
+ return false;
115
+ }
116
+ const seedFiles = await loadDevSeedFiles(environment, models, seedsDir);
117
+ if (seedFiles.length === 0) {
118
+ console.log(`ℹ️ No seed files found for environment "${environment}". Keeping existing Cosmos DB data.`);
119
+ return false;
120
+ }
121
+ const database = client.database(databaseName);
122
+ console.log(`🧪 Applying Cosmos DB seed data for environment "${environment}"...`);
123
+ for (const seedFile of seedFiles) {
124
+ await recreateContainer(database, seedFile.containerName);
125
+ const container = database.container(seedFile.containerName);
126
+ for (const document of seedFile.documents) {
127
+ await container.items.create(document);
128
+ }
129
+ console.log(`✅ Seeded "${seedFile.containerName}" with ${seedFile.documents.length} item(s) from ${path.basename(seedFile.filePath)}`);
130
+ }
131
+ console.log("✅ Cosmos DB seed replacement complete\n");
132
+ return true;
133
+ }
134
+ async function generateDevSeedTemplates({ environment, modelsDir = "shared/models", seedsDir = "dev-seeds", force = false, }) {
135
+ (0, config_1.ensureSwallowKitProject)("create-dev-seeds");
136
+ console.log(`🧪 Generating dev seed templates for environment "${environment}"...\n`);
137
+ const models = await loadProjectModels(modelsDir);
138
+ if (models.length === 0) {
139
+ console.log("⚠️ No schemas found under shared/models. Nothing was generated.");
140
+ return;
141
+ }
142
+ const environmentDir = getSeedEnvironmentDir(environment, seedsDir);
143
+ fs.mkdirSync(environmentDir, { recursive: true });
144
+ const writtenFiles = [];
145
+ const skippedFiles = [];
146
+ for (const model of models) {
147
+ const filePath = path.join(environmentDir, `${(0, model_parser_1.toKebabCase)(model.name)}.json`);
148
+ if (!force && fs.existsSync(filePath)) {
149
+ skippedFiles.push(filePath);
150
+ continue;
151
+ }
152
+ const content = JSON.stringify([buildSeedTemplateDocument(model, models)], null, 2) + "\n";
153
+ fs.writeFileSync(filePath, content, "utf-8");
154
+ writtenFiles.push(filePath);
155
+ console.log(`✅ Created: ${filePath}`);
156
+ }
157
+ if (skippedFiles.length > 0) {
158
+ console.log("");
159
+ console.log(`⏭️ Skipped ${skippedFiles.length} existing file(s). Use --force to overwrite them.`);
160
+ }
161
+ console.log("");
162
+ console.log("📝 Next steps:");
163
+ console.log(` 1. Edit JSON files under ${environmentDir}`);
164
+ console.log(` 2. Run 'swallowkit dev --seed-env ${environment}' to replace emulator data before startup`);
165
+ }
166
+ exports.devSeedsCommand = new commander_1.Command()
167
+ .name("create-dev-seeds")
168
+ .description("Generate dev seed JSON templates under dev-seeds/<environment> from shared/models schemas")
169
+ .argument("<environment>", "Seed environment name")
170
+ .option("--models-dir <dir>", "Models directory", "shared/models")
171
+ .option("--seeds-dir <dir>", "Dev seeds directory", "dev-seeds")
172
+ .option("--force", "Overwrite existing seed JSON files", false)
173
+ .action(async (environment, options) => {
174
+ await generateDevSeedTemplates({
175
+ environment,
176
+ modelsDir: options.modelsDir,
177
+ seedsDir: options.seedsDir,
178
+ force: options.force,
179
+ });
180
+ });
181
+ function buildSeedTemplateDocumentInternal(model, modelLookup, seenModels) {
182
+ const nextSeen = new Set(seenModels);
183
+ nextSeen.add(model.name);
184
+ const document = {};
185
+ for (const field of model.fields) {
186
+ document[field.name] = buildTemplateValueForField(model, field, modelLookup, nextSeen);
187
+ }
188
+ return document;
189
+ }
190
+ function buildTemplateValueForField(model, field, modelLookup, seenModels) {
191
+ if (field.isNestedSchema && field.nestedModelName) {
192
+ const nestedModel = modelLookup.get(field.nestedModelName);
193
+ if (nestedModel) {
194
+ if (seenModels.has(nestedModel.name)) {
195
+ const fallback = { id: `${(0, model_parser_1.toKebabCase)(nestedModel.name)}-001` };
196
+ return field.isArray ? [fallback] : fallback;
197
+ }
198
+ const nestedDocument = buildSeedTemplateDocumentInternal(nestedModel, modelLookup, seenModels);
199
+ return field.isArray ? [nestedDocument] : nestedDocument;
200
+ }
201
+ }
202
+ if (field.isArray) {
203
+ return [buildScalarTemplateValue(model, field)];
204
+ }
205
+ return buildScalarTemplateValue(model, field);
206
+ }
207
+ function buildScalarTemplateValue(model, field) {
208
+ if (field.name === "id") {
209
+ return `${(0, model_parser_1.toKebabCase)(model.name)}-001`;
210
+ }
211
+ if (field.enumValues && field.enumValues.length > 0) {
212
+ return field.enumValues[0];
213
+ }
214
+ if (field.type === "number") {
215
+ return 0;
216
+ }
217
+ if (field.type === "boolean") {
218
+ return false;
219
+ }
220
+ if (field.type === "date" || field.name.endsWith("At")) {
221
+ return "2026-01-01T00:00:00.000Z";
222
+ }
223
+ if (field.type === "object") {
224
+ return {};
225
+ }
226
+ return `${(0, model_parser_1.toKebabCase)(model.name)}-${(0, model_parser_1.toKebabCase)(field.name)}-sample`;
227
+ }
228
+ function buildModelAliasMap(models) {
229
+ const aliases = new Map();
230
+ for (const model of models) {
231
+ const candidates = [
232
+ model.name,
233
+ model.schemaName,
234
+ (0, model_parser_1.toKebabCase)(model.name),
235
+ path.basename(model.filePath, path.extname(model.filePath)),
236
+ ];
237
+ for (const candidate of candidates) {
238
+ const normalized = normalizeSeedIdentifier(candidate);
239
+ if (!aliases.has(normalized)) {
240
+ aliases.set(normalized, model);
241
+ }
242
+ }
243
+ }
244
+ return aliases;
245
+ }
246
+ function isSeedDocument(value) {
247
+ return typeof value === "object" && value !== null && !Array.isArray(value);
248
+ }
249
+ function validateSeedDocuments(documents, filePath) {
250
+ const ids = new Set();
251
+ documents.forEach((document, index) => {
252
+ if (typeof document.id !== "string" || document.id.trim().length === 0) {
253
+ throw new Error(`${filePath} item at index ${index} must contain a non-empty string id.`);
254
+ }
255
+ if (ids.has(document.id)) {
256
+ throw new Error(`${filePath} contains duplicate id "${document.id}".`);
257
+ }
258
+ ids.add(document.id);
259
+ });
260
+ }
261
+ async function recreateContainer(database, containerName) {
262
+ try {
263
+ await database.container(containerName).delete();
264
+ }
265
+ catch (error) {
266
+ if (error?.code !== 404) {
267
+ throw error;
268
+ }
269
+ }
270
+ try {
271
+ await database.containers.createIfNotExists({
272
+ id: containerName,
273
+ partitionKey: {
274
+ paths: ["/id"],
275
+ kind: cosmos_1.PartitionKeyKind.Hash,
276
+ version: 2,
277
+ },
278
+ });
279
+ }
280
+ catch (error) {
281
+ const message = error instanceof Error ? error.message : String(error);
282
+ console.log(`⚠️ Failed to recreate "${containerName}" with full partition key definition: ${message}`);
283
+ console.log("🔄 Retrying with simple partition key...");
284
+ await database.containers.createIfNotExists({
285
+ id: containerName,
286
+ partitionKey: {
287
+ paths: ["/id"],
288
+ },
289
+ });
290
+ }
291
+ }
292
+ //# sourceMappingURL=dev-seeds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-seeds.js","sourceRoot":"","sources":["../../../src/cli/commands/dev-seeds.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,4DAEC;AAED,sDAEC;AAED,0DAEC;AAED,gDAkBC;AAED,8CAEC;AAED,8DAOC;AAED,4CAoCC;AAED,0DAqCC;AAED,4DA4CC;AArMD,yCAAoC;AACpC,0CAAyE;AACzE,uCAAyB;AACzB,2CAA6B;AAC7B,8CAA4D;AAC5D,mEAAmG;AA0BnG,SAAgB,wBAAwB,CAAC,KAA8B;IACrE,OAAO,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC;AAC1B,CAAC;AAED,SAAgB,qBAAqB,CAAC,WAAmB,EAAE,WAAmB,WAAW;IACvF,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;AACzD,CAAC;AAED,SAAgB,uBAAuB,CAAC,KAAa;IACnD,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;AACvD,CAAC;AAED,SAAgB,kBAAkB,CAAC,OAAe,EAAE,QAAgB;IAClE,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAE5C,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAChC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,0DAA0D,KAAK,GAAG,CAAC,CAAC;YACjG,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;I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,CAAC;IACL,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,CAAC,GAAG,CAAC,2BAA2B,aAAa,yCAAyC,OAAO,EAAE,CAAC,CAAC;QACxG,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;QACxD,MAAM,QAAQ,CAAC,UAAU,CAAC,iBAAiB,CAAC;YAC1C,EAAE,EAAE,aAAa;YACjB,YAAY,EAAE;gBACZ,KAAK,EAAE,CAAC,KAAK,CAAC;aACf;SACF,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmBpC,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,CAEvE;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAGnE;AAED,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,MAAM,GAAG;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAUA;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC,UAAU,CAW3G;AAiQD,eAAO,MAAM,UAAU,SAmBnB,CAAC"}
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsBpC,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,CAEvE;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAGnE;AAED,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,MAAM,GAAG;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAUA;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC,UAAU,CAW3G;AAiQD,eAAO,MAAM,UAAU,SAoBnB,CAAC"}
@@ -45,6 +45,7 @@ const fs = __importStar(require("fs"));
45
45
  const os = __importStar(require("os"));
46
46
  const cosmos_1 = require("@azure/cosmos");
47
47
  const config_1 = require("../../core/config");
48
+ const dev_seeds_1 = require("./dev-seeds");
48
49
  const package_manager_1 = require("../../utils/package-manager");
49
50
  function buildFunctionsStartArgs(functionsPort) {
50
51
  return ['start', '--port', functionsPort];
@@ -262,6 +263,7 @@ exports.devCommand = new commander_1.Command()
262
263
  .option('--open', 'Open browser automatically', false)
263
264
  .option('--verbose', 'Show verbose logs', false)
264
265
  .option('--no-functions', 'Skip Azure Functions startup', false)
266
+ .option('--seed-env <environment>', 'Replace Cosmos DB Emulator data from dev-seeds/<environment> before startup')
265
267
  .action(async (options) => {
266
268
  // SwallowKit プロジェクトディレクトリかどうかを検証
267
269
  (0, config_1.ensureSwallowKitProject)("dev");
@@ -278,14 +280,14 @@ async function initializeCosmosDB(databaseName) {
278
280
  const localSettingsPath = path.join(functionsDir, 'local.settings.json');
279
281
  if (!fs.existsSync(localSettingsPath)) {
280
282
  console.log('⚠️ local.settings.json not found. Skipping Cosmos DB initialization.');
281
- return;
283
+ return null;
282
284
  }
283
285
  const localSettings = JSON.parse(fs.readFileSync(localSettingsPath, 'utf-8'));
284
286
  const connectionString = localSettings.Values?.CosmosDBConnection;
285
287
  const dbName = localSettings.Values?.COSMOS_DB_DATABASE_NAME || databaseName;
286
288
  if (!connectionString) {
287
289
  console.log('⚠️ CosmosDBConnection not found in local.settings.json. Skipping Cosmos DB initialization.');
288
- return;
290
+ return null;
289
291
  }
290
292
  console.log('🗄️ Initializing Cosmos DB...');
291
293
  // Parse connection string
@@ -293,7 +295,7 @@ async function initializeCosmosDB(databaseName) {
293
295
  const keyMatch = connectionString.match(/AccountKey=([^;]+)/);
294
296
  if (!endpointMatch || !keyMatch) {
295
297
  console.log('⚠️ Invalid CosmosDB connection string format.');
296
- return;
298
+ return null;
297
299
  }
298
300
  const endpoint = endpointMatch[1];
299
301
  const client = new cosmos_1.CosmosClient({
@@ -303,62 +305,52 @@ async function initializeCosmosDB(databaseName) {
303
305
  // Create database if not exists
304
306
  const { database } = await client.databases.createIfNotExists({ id: dbName });
305
307
  console.log(`✅ Database "${dbName}" ready`);
306
- // Read lib/scaffold-config.ts to get list of models
307
- const scaffoldConfigPath = path.join(process.cwd(), 'lib', 'scaffold-config.ts');
308
- if (fs.existsSync(scaffoldConfigPath)) {
309
- const scaffoldConfigContent = fs.readFileSync(scaffoldConfigPath, 'utf-8');
310
- // Parse TypeScript file to extract models array
311
- const modelsMatch = scaffoldConfigContent.match(/models:\s*\[([\s\S]*?)\]\s*as\s*ScaffoldModel\[\]/);
312
- if (modelsMatch) {
313
- const modelsArrayContent = modelsMatch[1];
314
- // Extract model names from objects like { name: 'Task', path: '/task', label: 'Task' }
315
- const modelMatches = modelsArrayContent.matchAll(/\{\s*name:\s*['"](\w+)['"]/g);
316
- const models = Array.from(modelMatches, m => m[1]);
317
- for (const modelName of models) {
318
- const containerName = `${modelName}s`; // Pluralize model name
319
- // Try creating container with full partition key definition first
320
- let containerCreated = false;
321
- try {
322
- console.log(`🔧 Creating container "${containerName}" with partition key /id...`);
323
- const containerResponse = await database.containers.createIfNotExists({
324
- id: containerName,
325
- partitionKey: {
326
- paths: ['/id'],
327
- kind: cosmos_1.PartitionKeyKind.Hash,
328
- version: 2
329
- }
330
- });
331
- console.log(`✅ Container "${containerName}" ready (status: ${containerResponse.statusCode})`);
332
- containerCreated = true;
333
- }
334
- catch (error) {
335
- console.log(`⚠️ Failed with full partition key definition: ${error.message}`);
336
- console.log(`🔄 Retrying with simple partition key...`);
308
+ const models = await (0, dev_seeds_1.loadProjectModels)();
309
+ for (const model of models) {
310
+ const containerName = (0, dev_seeds_1.getContainerNameForModel)(model);
311
+ // Try creating container with full partition key definition first
312
+ let containerCreated = false;
313
+ try {
314
+ console.log(`🔧 Creating container "${containerName}" with partition key /id...`);
315
+ const containerResponse = await database.containers.createIfNotExists({
316
+ id: containerName,
317
+ partitionKey: {
318
+ paths: ['/id'],
319
+ kind: cosmos_1.PartitionKeyKind.Hash,
320
+ version: 2
337
321
  }
338
- // If first attempt failed, try with simple partition key definition
339
- if (!containerCreated) {
340
- try {
341
- const containerResponse = await database.containers.createIfNotExists({
342
- id: containerName,
343
- partitionKey: {
344
- paths: ['/id']
345
- }
346
- });
347
- console.log(`✅ Container "${containerName}" ready (status: ${containerResponse.statusCode})`);
348
- }
349
- catch (containerError) {
350
- console.error(`❌ Failed to create container "${containerName}":`, containerError.message);
351
- console.error(`Error code: ${containerError.code}`);
352
- if (containerError.body) {
353
- console.error(`Response body:`, JSON.stringify(containerError.body, null, 2));
354
- }
355
- // Continue with other containers
322
+ });
323
+ console.log(`✅ Container "${containerName}" ready (status: ${containerResponse.statusCode})`);
324
+ containerCreated = true;
325
+ }
326
+ catch (error) {
327
+ const message = error instanceof Error ? error.message : String(error);
328
+ console.log(`⚠️ Failed with full partition key definition: ${message}`);
329
+ console.log(`🔄 Retrying with simple partition key...`);
330
+ }
331
+ // If first attempt failed, try with simple partition key definition
332
+ if (!containerCreated) {
333
+ try {
334
+ const containerResponse = await database.containers.createIfNotExists({
335
+ id: containerName,
336
+ partitionKey: {
337
+ paths: ['/id']
356
338
  }
339
+ });
340
+ console.log(`✅ Container "${containerName}" ready (status: ${containerResponse.statusCode})`);
341
+ }
342
+ catch (containerError) {
343
+ console.error(`❌ Failed to create container "${containerName}":`, containerError.message);
344
+ console.error(`Error code: ${containerError.code}`);
345
+ if (containerError.body) {
346
+ console.error(`Response body:`, JSON.stringify(containerError.body, null, 2));
357
347
  }
348
+ // Continue with other containers
358
349
  }
359
350
  }
360
351
  }
361
352
  console.log('✅ Cosmos DB initialization complete\n');
353
+ return { endpoint, key: keyMatch[1], databaseName: dbName, models };
362
354
  }
363
355
  catch (error) {
364
356
  console.error('⚠️ Cosmos DB initialization failed:', error.message);
@@ -366,6 +358,7 @@ async function initializeCosmosDB(databaseName) {
366
358
  console.error('Stack trace:', error.stack);
367
359
  }
368
360
  console.log('💡 Make sure Cosmos DB Emulator is running');
361
+ return null;
369
362
  }
370
363
  }
371
364
  async function startDevEnvironment(options) {
@@ -473,7 +466,18 @@ async function startDevEnvironment(options) {
473
466
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
474
467
  const appName = packageJson.name || 'App';
475
468
  const databaseName = `${appName.charAt(0).toUpperCase() + appName.slice(1)}Database`;
476
- await initializeCosmosDB(databaseName);
469
+ const cosmosInitialization = await initializeCosmosDB(databaseName);
470
+ if (options.seedEnv && cosmosInitialization) {
471
+ await (0, dev_seeds_1.applyDevSeedEnvironment)({
472
+ client: new cosmos_1.CosmosClient({
473
+ endpoint: cosmosInitialization.endpoint,
474
+ key: cosmosInitialization.key,
475
+ }),
476
+ databaseName: cosmosInitialization.databaseName,
477
+ environment: options.seedEnv,
478
+ models: cosmosInitialization.models,
479
+ });
480
+ }
477
481
  console.log('');
478
482
  console.log('🚀 Starting Azure Functions...');
479
483
  if (backendLanguage === 'typescript') {