@specverse/engines 6.5.4 → 6.7.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.
Files changed (19) hide show
  1. package/dist/libs/instance-factories/applications/templates/generic/backend-package-json-generator.js +26 -10
  2. package/dist/libs/instance-factories/controllers/templates/fastify/server-generator.js +1 -1
  3. package/dist/libs/instance-factories/services/mongodb-native-services.yaml +84 -0
  4. package/dist/libs/instance-factories/services/templates/mongodb-native/client-generator.js +43 -0
  5. package/dist/libs/instance-factories/services/templates/mongodb-native/controller-generator.js +252 -0
  6. package/dist/libs/instance-factories/services/templates/mongodb-native/service-generator.js +64 -0
  7. package/dist/libs/instance-factories/services/templates/prisma/ai-behaviors-generator.js +167 -26
  8. package/dist/realize/library/library.d.ts.map +1 -1
  9. package/dist/realize/library/library.js +11 -0
  10. package/dist/realize/library/library.js.map +1 -1
  11. package/libs/instance-factories/applications/templates/generic/backend-package-json-generator.ts +48 -12
  12. package/libs/instance-factories/controllers/templates/fastify/server-generator.ts +1 -1
  13. package/libs/instance-factories/services/mongodb-native-services.yaml +84 -0
  14. package/libs/instance-factories/services/templates/mongodb-native/__tests__/controller-generator.test.ts +113 -0
  15. package/libs/instance-factories/services/templates/mongodb-native/client-generator.ts +51 -0
  16. package/libs/instance-factories/services/templates/mongodb-native/controller-generator.ts +319 -0
  17. package/libs/instance-factories/services/templates/mongodb-native/service-generator.ts +83 -0
  18. package/libs/instance-factories/services/templates/prisma/ai-behaviors-generator.ts +231 -36
  19. package/package.json +4 -5
@@ -1,6 +1,27 @@
1
+ function resolveOrmName(manifest) {
2
+ if (!manifest) return "PrismaORM";
3
+ const inner = manifest.manifests ? Object.values(manifest.manifests)[0] : manifest;
4
+ if (!inner) return "PrismaORM";
5
+ const caps = Array.isArray(inner.capabilityMappings) ? inner.capabilityMappings : [];
6
+ const ormCap = caps.find((m) => m?.capability === "orm.client") || caps.find((m) => m?.capability === "orm.schema");
7
+ if (ormCap) return ormCap.implementation || ormCap.instanceFactory || "PrismaORM";
8
+ return inner.defaultMappings?.orm || "PrismaORM";
9
+ }
1
10
  function generateBackendPackageJson(context) {
2
- const { spec } = context;
11
+ const { spec, manifest } = context;
3
12
  const appName = (spec.metadata?.component || "app").toLowerCase().replace(/\s+/g, "-");
13
+ const orm = resolveOrmName(manifest);
14
+ const isMongoNative = orm === "MongoDBNativeDriver";
15
+ const dbScripts = isMongoNative ? {} : {
16
+ "db:setup": "prisma generate && prisma db push",
17
+ "db:generate": "prisma generate",
18
+ "db:push": "prisma db push",
19
+ "db:migrate": "prisma migrate dev",
20
+ "db:studio": "prisma studio",
21
+ "db:seed": "tsx prisma/seed.ts"
22
+ };
23
+ const ormDeps = isMongoNative ? { "mongodb": "^6.3.0" } : { "@prisma/client": "^5.7.0" };
24
+ const ormDevDeps = isMongoNative ? {} : { "prisma": "^5.7.0" };
4
25
  const pkg = {
5
26
  name: `${appName}-backend`,
6
27
  version: spec.metadata?.version || "1.0.0",
@@ -18,13 +39,8 @@ function generateBackendPackageJson(context) {
18
39
  "build:watch": "tsc --watch",
19
40
  // Production
20
41
  "start": "node dist/main.js",
21
- // Database
22
- "db:setup": "prisma generate && prisma db push",
23
- "db:generate": "prisma generate",
24
- "db:push": "prisma db push",
25
- "db:migrate": "prisma migrate dev",
26
- "db:studio": "prisma studio",
27
- "db:seed": "tsx prisma/seed.ts",
42
+ // Database (ORM-specific; empty for native driver)
43
+ ...dbScripts,
28
44
  // Testing
29
45
  "test": "vitest run --passWithNoTests",
30
46
  "test:watch": "vitest watch",
@@ -36,7 +52,7 @@ function generateBackendPackageJson(context) {
36
52
  "typecheck": "tsc --noEmit"
37
53
  },
38
54
  dependencies: {
39
- "@prisma/client": "^5.7.0",
55
+ ...ormDeps,
40
56
  "fastify": "^5.8.3",
41
57
  "@fastify/cors": "^10.0.0",
42
58
  "@fastify/helmet": "^12.0.0",
@@ -51,7 +67,7 @@ function generateBackendPackageJson(context) {
51
67
  "typescript": "^5.3.0",
52
68
  "@types/node": "^20.10.0",
53
69
  "tsx": "^4.7.0",
54
- "prisma": "^5.7.0",
70
+ ...ormDevDeps,
55
71
  "vitest": "^3.0.0",
56
72
  "@vitest/coverage-v8": "^3.0.0",
57
73
  "eslint": "^9.0.0",
@@ -39,7 +39,7 @@ function generateFastifyServer(context) {
39
39
  // workspace before running the script.
40
40
  import { config as loadEnv } from 'dotenv';
41
41
  import { existsSync } from 'fs';
42
- import { resolve as resolvePath, dirname, join } from 'path';
42
+ import { dirname, join } from 'path';
43
43
  import { fileURLToPath } from 'url';
44
44
  {
45
45
  let dir = dirname(fileURLToPath(import.meta.url));
@@ -0,0 +1,84 @@
1
+ name: MongoDBNativeDriver
2
+ version: "1.0.0"
3
+ category: service
4
+ description: "Business logic services using the native MongoDB driver for collection access (no ORM layer)"
5
+
6
+ metadata:
7
+ author: "SpecVerse Team"
8
+ license: "MIT"
9
+ tags: [services, business-logic, mongodb, native-driver, controllers]
10
+
11
+ compatibility:
12
+ specverse: ">=5.0.0"
13
+ node: ">=18.0.0"
14
+
15
+ # With the MongoDB native driver, collection access IS the data layer — there
16
+ # is no ORM layer to swap in independently. So this single factory provides
17
+ # both the "orm.client" capability AND the service-layer capabilities.
18
+ capabilities:
19
+ provides:
20
+ - "orm.schema" # Emits the MongoDB client connector (the client IS the schema layer)
21
+ - "orm.client"
22
+ - "orm.mongodb.native"
23
+ - "service.controller"
24
+ - "service.business"
25
+ - "service.crud"
26
+ requires:
27
+ - "storage.database.document"
28
+
29
+ technology:
30
+ runtime: "node"
31
+ language: "typescript"
32
+ orm: "mongodb-native"
33
+ version: "^6.0.0"
34
+
35
+ dependencies:
36
+ runtime:
37
+ - name: "mongodb"
38
+ version: "^6.3.0"
39
+
40
+ dev:
41
+ - name: "@types/node"
42
+ version: "^20.8.0"
43
+ - name: "typescript"
44
+ version: "^5.2.0"
45
+
46
+ codeTemplates:
47
+ # `schema` is the orm.schema-capability slot the realize engine drives for
48
+ # ORM-side artifacts. With Prisma this emits `schema.prisma`; with the
49
+ # MongoDB native driver there is no separate db-schema artifact, so this
50
+ # slot emits the singleton client connector instead — same intent
51
+ # ("how does the app reach the data layer"), different physical output.
52
+ schema:
53
+ engine: typescript
54
+ generator: "libs/instance-factories/services/templates/mongodb-native/client-generator.ts"
55
+ outputPattern: "{backendDir}/src/db/mongoClient.ts"
56
+
57
+ controllers:
58
+ engine: typescript
59
+ generator: "libs/instance-factories/services/templates/mongodb-native/controller-generator.ts"
60
+ outputPattern: "{backendDir}/src/controllers/{model}Controller.ts"
61
+
62
+ services:
63
+ engine: typescript
64
+ generator: "libs/instance-factories/services/templates/mongodb-native/service-generator.ts"
65
+ outputPattern: "{backendDir}/src/services/{service}.ts"
66
+
67
+ configuration:
68
+ outputStructure: "monorepo"
69
+ backendDir: "backend"
70
+ collectionNaming: "lowercase-pluralized" # User → users, OrderItem → orderitems
71
+ validation: true
72
+ eventPublishing: true
73
+ errorHandling: "throw"
74
+
75
+ requirements:
76
+ dependencies:
77
+ npm:
78
+ dependencies:
79
+ "mongodb": "^6.3.0"
80
+ environment:
81
+ - name: "MONGODB_URI"
82
+ description: "MongoDB connection string (e.g. mongodb://localhost:27017/myapp)"
83
+ required: true
84
+ configuration: {}
@@ -0,0 +1,43 @@
1
+ function generateMongoClient(_context) {
2
+ return `/**
3
+ * MongoDB native driver \u2014 singleton client + helpers.
4
+ *
5
+ * Picks up MONGODB_URI / MONGODB_DB from the environment. The client is
6
+ * lazily initialised on first use and reused across requests; \`disconnect\`
7
+ * is exposed for graceful-shutdown wiring.
8
+ */
9
+ import { MongoClient, type Db, type Collection, type Document } from 'mongodb';
10
+
11
+ const uri = process.env.MONGODB_URI || 'mongodb://localhost:27017';
12
+ const dbName = process.env.MONGODB_DB || 'specverse';
13
+
14
+ let client: MongoClient | null = null;
15
+ let database: Db | null = null;
16
+
17
+ export async function getDb(): Promise<Db> {
18
+ if (database) return database;
19
+ client = new MongoClient(uri);
20
+ await client.connect();
21
+ database = client.db(dbName);
22
+ return database;
23
+ }
24
+
25
+ export async function getCollection<T extends Document = Document>(
26
+ name: string,
27
+ ): Promise<Collection<T>> {
28
+ const db = await getDb();
29
+ return db.collection<T>(name);
30
+ }
31
+
32
+ export async function disconnect(): Promise<void> {
33
+ if (client) {
34
+ await client.close();
35
+ client = null;
36
+ database = null;
37
+ }
38
+ }
39
+ `;
40
+ }
41
+ export {
42
+ generateMongoClient as default
43
+ };
@@ -0,0 +1,252 @@
1
+ import { buildTransitionMap, isAutoField } from "@specverse/types/spec-rules";
2
+ function generateMongoNativeController(context) {
3
+ const { controller, model } = context;
4
+ if (!controller) throw new Error("Controller is required in template context");
5
+ if (!model) throw new Error("Model is required for controller generation");
6
+ const controllerName = controller.name;
7
+ const modelName = model.name;
8
+ const modelVar = lowerFirst(modelName);
9
+ const collection = collectionName(model);
10
+ const curedOps = controller.cured || {};
11
+ const customActions = generateCustomActions(controller);
12
+ const validate = generateValidateMethod(model, modelName);
13
+ const create = curedOps.create ? generateCreateMethod(model, modelName, modelVar, collection) : "";
14
+ const retrieve = curedOps.retrieve ? generateRetrieveMethod(modelName, modelVar, collection) : "";
15
+ const update = curedOps.update ? generateUpdateMethod(modelName, modelVar, collection) : "";
16
+ const evolve = curedOps.evolve ? generateEvolveMethod(model, modelName, modelVar, collection) : "";
17
+ const del = curedOps.delete ? generateDeleteMethod(modelName, modelVar, collection) : "";
18
+ const hasEventPublishing = curedOps.create || curedOps.update || curedOps.evolve || curedOps.delete;
19
+ return `/**
20
+ * ${controllerName}
21
+ * Model-specific business logic for ${modelName} (MongoDB native driver)
22
+ * ${controller.description || ""}
23
+ */
24
+ import { ObjectId, type Filter, type Document } from 'mongodb';
25
+ import { getCollection } from '../db/mongoClient.js';
26
+ ${hasEventPublishing ? `import { eventBus } from '../events/eventBus.js';` : ""}
27
+
28
+ const COLLECTION_NAME = '${collection}';
29
+
30
+ /** Parse an id string to the value the collection expects: ObjectId for
31
+ * 24-hex-character ids, otherwise pass-through (UUIDs, slugs, ints-as-string). */
32
+ function parseId(id: string): ObjectId | string {
33
+ if (typeof id === 'string' && /^[a-fA-F0-9]{24}$/.test(id)) return new ObjectId(id);
34
+ return id;
35
+ }
36
+
37
+ /** _id-aware filter builder. */
38
+ function byId(id: string): Filter<Document> {
39
+ return { _id: parseId(id) as any };
40
+ }
41
+
42
+ export class ${controllerName} {
43
+ ${validate}
44
+ ${create}
45
+ ${retrieve}
46
+ ${update}
47
+ ${evolve}
48
+ ${del}
49
+ ${customActions.code}
50
+ }
51
+
52
+ export const ${modelVar}Controller = new ${controllerName}();
53
+ export default ${modelVar}Controller;
54
+ `;
55
+ }
56
+ function lowerFirst(s) {
57
+ return s.charAt(0).toLowerCase() + s.slice(1);
58
+ }
59
+ function collectionName(model) {
60
+ if (model?.storage?.collection) return String(model.storage.collection);
61
+ return model.name.toLowerCase() + "s";
62
+ }
63
+ function generateValidateMethod(model, modelName) {
64
+ return `
65
+ /**
66
+ * Validate ${modelName} data \u2014 runs before create / update / evolve.
67
+ */
68
+ public validate(
69
+ _data: any,
70
+ _context: { operation: 'create' | 'update' | 'evolve' }
71
+ ): { valid: boolean; errors: string[] } {
72
+ const errors: string[] = [];
73
+ ${generateValidationLogic(model)}
74
+ return { valid: errors.length === 0, errors };
75
+ }
76
+ `;
77
+ }
78
+ function generateValidationLogic(model) {
79
+ if (!model.attributes) return " // No validation rules defined";
80
+ const attrList = Array.isArray(model.attributes) ? model.attributes.map((a) => [a.name, a]) : Object.entries(model.attributes);
81
+ const out = [];
82
+ attrList.forEach(([name, attr]) => {
83
+ if (attr.required && !isAutoField(name, attr)) {
84
+ out.push(` if (_context.operation === 'create' && !_data.${name}) errors.push('${name} is required');`);
85
+ }
86
+ if (attr.type === "String" || attr.type === "string") {
87
+ if (attr.min) out.push(` if (_data.${name} && _data.${name}.length < ${attr.min}) errors.push('${name} must be at least ${attr.min} characters');`);
88
+ if (attr.max) out.push(` if (_data.${name} && _data.${name}.length > ${attr.max}) errors.push('${name} must be at most ${attr.max} characters');`);
89
+ }
90
+ if (attr.values && Array.isArray(attr.values)) {
91
+ const values = attr.values.map((v) => `'${v}'`).join(", ");
92
+ out.push(` if (_data.${name} && ![${values}].includes(_data.${name})) errors.push('${name} must be one of: ${attr.values.join(", ")}');`);
93
+ }
94
+ if (attr.format === "email") {
95
+ out.push(` if (_data.${name} && !/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(_data.${name})) errors.push('${name} must be a valid email address');`);
96
+ }
97
+ });
98
+ return out.join("\n") || " // No validation rules defined";
99
+ }
100
+ function generateCreateMethod(model, modelName, modelVar, collection) {
101
+ return `
102
+ /**
103
+ * Create a new ${modelName}.
104
+ */
105
+ public async create(data: any): Promise<any> {
106
+ const validation = this.validate(data, { operation: 'create' });
107
+ if (!validation.valid) throw new Error(\`Validation failed: \${validation.errors.join(', ')}\`);
108
+
109
+ const collection = await getCollection(COLLECTION_NAME);
110
+ const result = await collection.insertOne({ ...data });
111
+ const ${modelVar} = { _id: result.insertedId, ...data };
112
+
113
+ await eventBus.publish('${modelName}Created', { ...${modelVar}, timestamp: new Date().toISOString() } as any);
114
+ return ${modelVar};
115
+ }
116
+ `;
117
+ }
118
+ function generateRetrieveMethod(modelName, modelVar, collection) {
119
+ return `
120
+ /**
121
+ * Retrieve ${modelName} by id. Returns null when not found.
122
+ */
123
+ public async retrieve(id: string): Promise<any | null> {
124
+ const collection = await getCollection(COLLECTION_NAME);
125
+ return await collection.findOne(byId(id));
126
+ }
127
+
128
+ /**
129
+ * Retrieve a page of ${modelName}s.
130
+ */
131
+ public async retrieveAll(options: { skip?: number; take?: number } = {}): Promise<any[]> {
132
+ const collection = await getCollection(COLLECTION_NAME);
133
+ const cursor = collection.find({});
134
+ if (options.skip) cursor.skip(options.skip);
135
+ if (options.take) cursor.limit(options.take);
136
+ return await cursor.toArray();
137
+ }
138
+ `;
139
+ }
140
+ function generateUpdateMethod(modelName, modelVar, collection) {
141
+ return `
142
+ /**
143
+ * Update ${modelName}.
144
+ */
145
+ public async update(id: string, data: any): Promise<any> {
146
+ const validation = this.validate(data, { operation: 'update' });
147
+ if (!validation.valid) throw new Error(\`Validation failed: \${validation.errors.join(', ')}\`);
148
+
149
+ // Strip nested objects + id \u2014 only scalar fields are written.
150
+ const updateData: any = {};
151
+ for (const [key, value] of Object.entries(data)) {
152
+ if (key === 'id' || key === '_id') continue;
153
+ if (Array.isArray(value)) continue;
154
+ if (value !== null && typeof value === 'object' && !(value instanceof Date)) continue;
155
+ updateData[key] = value;
156
+ }
157
+
158
+ const collection = await getCollection(COLLECTION_NAME);
159
+ await collection.updateOne(byId(id), { $set: updateData });
160
+ const ${modelVar} = await collection.findOne(byId(id));
161
+ if (!${modelVar}) throw new Error('${modelName} not found after update');
162
+
163
+ await eventBus.publish('${modelName}Updated', { ...${modelVar}, timestamp: new Date().toISOString() } as any);
164
+ return ${modelVar};
165
+ }
166
+ `;
167
+ }
168
+ function generateEvolveMethod(model, modelName, modelVar, collection) {
169
+ const lifecycles = Array.isArray(model.lifecycles) ? model.lifecycles : model.lifecycles ? Object.entries(model.lifecycles).map(([name, lc]) => ({ name, ...lc })) : [];
170
+ const lifecycle = lifecycles[0];
171
+ const lifecycleName = lifecycle?.name || "status";
172
+ const validTransitions = lifecycle ? buildTransitionMap(lifecycle) : {};
173
+ const states = lifecycle?.states && lifecycle.states.length > 0 ? lifecycle.states.map((s) => typeof s === "string" ? s : s.name) : Array.from(/* @__PURE__ */ new Set([
174
+ ...Object.keys(validTransitions),
175
+ ...Object.values(validTransitions).flat()
176
+ ]));
177
+ return `
178
+ /**
179
+ * Evolve ${modelName} through lifecycle "${lifecycleName}"
180
+ * States: ${states.join(" \u2192 ") || "(none declared)"}
181
+ */
182
+ public async evolve(id: string, data: any): Promise<any> {
183
+ const collection = await getCollection(COLLECTION_NAME);
184
+ const current = await collection.findOne(byId(id));
185
+ if (!current) throw new Error('${modelName} not found');
186
+
187
+ const targetLifecycle = data?.lifecycleName || '${lifecycleName}';
188
+ const targetState = data?.toState ?? data?.state ?? data?.[targetLifecycle];
189
+ if (!targetState) throw new Error('evolve requires toState (or ${lifecycleName}) in the request body');
190
+
191
+ ${states.length > 0 ? `
192
+ const currentState = (current as any)[targetLifecycle];
193
+ const validTransitions: Record<string, string[]> = ${JSON.stringify(validTransitions)};
194
+ const allowed = validTransitions[currentState] || [];
195
+ if (!allowed.includes(targetState)) {
196
+ throw new Error(\`Invalid transition: \${currentState} \u2192 \${targetState}. Allowed: \${allowed.join(', ') || 'none'}\`);
197
+ }
198
+ ` : ""}
199
+
200
+ await collection.updateOne(byId(id), { $set: { [targetLifecycle]: targetState } });
201
+ const ${modelVar} = await collection.findOne(byId(id));
202
+ if (!${modelVar}) throw new Error('${modelName} not found after evolve');
203
+
204
+ await eventBus.publish('${modelName}Evolved', { ...${modelVar}, timestamp: new Date().toISOString() } as any);
205
+ return ${modelVar};
206
+ }
207
+ `;
208
+ }
209
+ function generateDeleteMethod(modelName, modelVar, collection) {
210
+ return `
211
+ /**
212
+ * Delete ${modelName}.
213
+ */
214
+ public async delete(id: string): Promise<void> {
215
+ const collection = await getCollection(COLLECTION_NAME);
216
+ const ${modelVar} = await collection.findOne(byId(id));
217
+ await collection.deleteOne(byId(id));
218
+ if (${modelVar}) {
219
+ await eventBus.publish('${modelName}Deleted', { ...${modelVar}, timestamp: new Date().toISOString() } as any);
220
+ }
221
+ }
222
+ `;
223
+ }
224
+ function generateCustomActions(controller) {
225
+ if (!controller.actions || Object.keys(controller.actions).length === 0) {
226
+ return { code: "" };
227
+ }
228
+ const out = [];
229
+ for (const [actionName, action] of Object.entries(controller.actions)) {
230
+ const stepsHeader = action.steps && action.steps.length > 0 ? action.steps.map((s) => ` * - ${typeof s === "string" ? s : s.action || JSON.stringify(s)}`).join("\n") : " * (no spec steps declared)";
231
+ out.push(`
232
+ /**
233
+ * ${actionName}
234
+ * ${action.description || ""}
235
+ *
236
+ * Spec steps:
237
+ ${stepsHeader}
238
+ */
239
+ public async ${actionName}(_args: any = {}): Promise<any> {
240
+ // TODO (#43F): translate spec steps into native MongoDB driver calls
241
+ // via a mongodb-native step-conventions library (mirror of the prisma
242
+ // one). For now this is a stub so realize completes and the action
243
+ // surface is callable for parity tests.
244
+ throw new Error('${controller.name}.${actionName} is not implemented');
245
+ }
246
+ `);
247
+ }
248
+ return { code: out.join("\n") };
249
+ }
250
+ export {
251
+ generateMongoNativeController as default
252
+ };
@@ -0,0 +1,64 @@
1
+ function generateMongoNativeService(context) {
2
+ const { service } = context;
3
+ if (!service) throw new Error("Service is required in template context");
4
+ const serviceName = service.name;
5
+ const operationsCode = generateOperations(service);
6
+ const usesDb = /\bgetDb\b|\bgetCollection\b/.test(operationsCode);
7
+ const hasEvents = service.publishes && service.publishes.length > 0 || service.subscribes && service.subscribes.length > 0;
8
+ return `/**
9
+ * ${serviceName}
10
+ * Abstract business logic service (MongoDB native driver)
11
+ * ${service.description || ""}
12
+ */
13
+ ${usesDb ? `import { getDb, getCollection } from '../db/mongoClient.js';` : ""}
14
+ ${hasEvents ? `import { eventBus } from '../events/eventBus.js';` : ""}
15
+
16
+ export class ${serviceName} {
17
+ ${operationsCode}
18
+ }
19
+
20
+ const ${lowerFirst(serviceName)} = new ${serviceName}();
21
+ export const ${lowerFirst(serviceName)}Instance = ${lowerFirst(serviceName)};
22
+ export default ${lowerFirst(serviceName)};
23
+ `;
24
+ }
25
+ function lowerFirst(s) {
26
+ return s.charAt(0).toLowerCase() + s.slice(1);
27
+ }
28
+ function generateOperations(service) {
29
+ const ops = service.operations;
30
+ if (!ops || Array.isArray(ops) && ops.length === 0 || !Array.isArray(ops) && Object.keys(ops).length === 0) {
31
+ return `
32
+ /**
33
+ * Default service entrypoint \u2014 replace with real operations once declared
34
+ * on the service's spec.
35
+ */
36
+ public async execute(_params: any = {}): Promise<any> {
37
+ throw new Error('${service.name}.execute is not implemented');
38
+ }
39
+ `;
40
+ }
41
+ const entries = Array.isArray(ops) ? ops.map((op) => [op.name, op]) : Object.entries(ops);
42
+ return entries.map(([name, op]) => generateOperation(name, op, service.name)).join("\n");
43
+ }
44
+ function generateOperation(operationName, operation, serviceName) {
45
+ const stepsHeader = operation.steps && operation.steps.length > 0 ? operation.steps.map((s) => ` * - ${typeof s === "string" ? s : s.action || JSON.stringify(s)}`).join("\n") : " * (no spec steps declared)";
46
+ return `
47
+ /**
48
+ * ${operationName}
49
+ * ${operation.description || ""}
50
+ *
51
+ * Spec steps:
52
+ ${stepsHeader}
53
+ */
54
+ public async ${operationName}(_args: any = {}): Promise<any> {
55
+ // TODO (#43 follow-up): translate spec steps into native MongoDB driver
56
+ // calls. For now this is a stub so realize completes and the service
57
+ // surface is callable for parity tests.
58
+ throw new Error('${serviceName}.${operationName} is not implemented');
59
+ }
60
+ `;
61
+ }
62
+ export {
63
+ generateMongoNativeService as default
64
+ };