@specverse/engines 6.5.3 → 6.6.3
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/dist/analyse-prepass/adapters/typescript-decorators.d.ts.map +1 -1
- package/dist/analyse-prepass/adapters/typescript-decorators.js +82 -20
- package/dist/analyse-prepass/adapters/typescript-decorators.js.map +1 -1
- package/dist/libs/instance-factories/services/mongodb-native-services.yaml +84 -0
- package/dist/libs/instance-factories/services/templates/mongodb-native/client-generator.js +43 -0
- package/dist/libs/instance-factories/services/templates/mongodb-native/controller-generator.js +259 -0
- package/dist/libs/instance-factories/services/templates/mongodb-native/service-generator.js +64 -0
- package/dist/realize/library/library.d.ts.map +1 -1
- package/dist/realize/library/library.js +11 -0
- package/dist/realize/library/library.js.map +1 -1
- package/libs/instance-factories/services/mongodb-native-services.yaml +84 -0
- package/libs/instance-factories/services/templates/mongodb-native/__tests__/controller-generator.test.ts +111 -0
- package/libs/instance-factories/services/templates/mongodb-native/client-generator.ts +51 -0
- package/libs/instance-factories/services/templates/mongodb-native/controller-generator.ts +316 -0
- package/libs/instance-factories/services/templates/mongodb-native/service-generator.ts +83 -0
- package/package.json +2 -2
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MongoDB Native Driver — Service Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates abstract business-logic services that use `getCollection` /
|
|
5
|
+
* `getDb` directly. The service body is intentionally skeletal: each
|
|
6
|
+
* declared operation gets a typed method, but the body is a TODO stub
|
|
7
|
+
* containing the spec steps as comments. Real-implementation generation
|
|
8
|
+
* is a separate concern (#43 follow-up: behavior-step → driver-call
|
|
9
|
+
* conventions parity with the prisma step library).
|
|
10
|
+
*/
|
|
11
|
+
import type { TemplateContext } from '@specverse/types';
|
|
12
|
+
|
|
13
|
+
export default function generateMongoNativeService(context: TemplateContext): string {
|
|
14
|
+
const { service } = context;
|
|
15
|
+
if (!service) throw new Error('Service is required in template context');
|
|
16
|
+
|
|
17
|
+
const serviceName = service.name;
|
|
18
|
+
const operationsCode = generateOperations(service);
|
|
19
|
+
const usesDb = /\bgetDb\b|\bgetCollection\b/.test(operationsCode);
|
|
20
|
+
const hasEvents = (service.publishes && service.publishes.length > 0) ||
|
|
21
|
+
(service.subscribes && service.subscribes.length > 0);
|
|
22
|
+
|
|
23
|
+
return `/**
|
|
24
|
+
* ${serviceName}
|
|
25
|
+
* Abstract business logic service (MongoDB native driver)
|
|
26
|
+
* ${service.description || ''}
|
|
27
|
+
*/
|
|
28
|
+
${usesDb ? `import { getDb, getCollection } from '../db/mongoClient.js';` : ''}
|
|
29
|
+
${hasEvents ? `import { eventBus } from '../events/eventBus.js';` : ''}
|
|
30
|
+
|
|
31
|
+
export class ${serviceName} {
|
|
32
|
+
${operationsCode}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const ${lowerFirst(serviceName)} = new ${serviceName}();
|
|
36
|
+
export const ${lowerFirst(serviceName)}Instance = ${lowerFirst(serviceName)};
|
|
37
|
+
export default ${lowerFirst(serviceName)};
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function lowerFirst(s: string): string {
|
|
42
|
+
return s.charAt(0).toLowerCase() + s.slice(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function generateOperations(service: any): string {
|
|
46
|
+
const ops = service.operations;
|
|
47
|
+
if (!ops || (Array.isArray(ops) && ops.length === 0) || (!Array.isArray(ops) && Object.keys(ops).length === 0)) {
|
|
48
|
+
return `
|
|
49
|
+
/**
|
|
50
|
+
* Default service entrypoint — replace with real operations once declared
|
|
51
|
+
* on the service's spec.
|
|
52
|
+
*/
|
|
53
|
+
public async execute(_params: any = {}): Promise<any> {
|
|
54
|
+
throw new Error('${service.name}.execute is not implemented');
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
}
|
|
58
|
+
const entries: [string, any][] = Array.isArray(ops)
|
|
59
|
+
? ops.map((op: any) => [op.name, op])
|
|
60
|
+
: Object.entries(ops);
|
|
61
|
+
return entries.map(([name, op]) => generateOperation(name, op, service.name)).join('\n');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function generateOperation(operationName: string, operation: any, serviceName: string): string {
|
|
65
|
+
const stepsHeader = (operation.steps && operation.steps.length > 0)
|
|
66
|
+
? operation.steps.map((s: any) => ` * - ${typeof s === 'string' ? s : (s.action || JSON.stringify(s))}`).join('\n')
|
|
67
|
+
: ' * (no spec steps declared)';
|
|
68
|
+
return `
|
|
69
|
+
/**
|
|
70
|
+
* ${operationName}
|
|
71
|
+
* ${operation.description || ''}
|
|
72
|
+
*
|
|
73
|
+
* Spec steps:
|
|
74
|
+
${stepsHeader}
|
|
75
|
+
*/
|
|
76
|
+
public async ${operationName}(_args: any = {}): Promise<any> {
|
|
77
|
+
// TODO (#43 follow-up): translate spec steps into native MongoDB driver
|
|
78
|
+
// calls. For now this is a stub so realize completes and the service
|
|
79
|
+
// surface is callable for parity tests.
|
|
80
|
+
throw new Error('${serviceName}.${operationName} is not implemented');
|
|
81
|
+
}
|
|
82
|
+
`;
|
|
83
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@specverse/engines",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.3",
|
|
4
4
|
"description": "SpecVerse toolchain — parser, inference, realize, generators, AI, registry, bundles",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"@ai-sdk/openai-compatible": "^2.0.41",
|
|
63
63
|
"@ai-sdk/provider": "^3.0.8",
|
|
64
64
|
"@specverse/assets": "^1.6.0",
|
|
65
|
-
"@specverse/engines": "^6.
|
|
65
|
+
"@specverse/engines": "^6.6.1",
|
|
66
66
|
"@specverse/entities": "^5.1.0",
|
|
67
67
|
"@specverse/runtime": "^5.0.1",
|
|
68
68
|
"@specverse/types": "^5.1.0",
|