domain-driver 0.1.0 → 0.3.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.md +159 -145
- package/dist/cli.js +208 -0
- package/dist/commands/action.js +118 -0
- package/dist/commands/component.js +18 -19
- package/dist/commands/container.js +10 -31
- package/dist/commands/controller.js +85 -0
- package/dist/commands/feature.js +59 -51
- package/dist/commands/hints.js +28 -0
- package/dist/commands/hook.js +10 -111
- package/dist/commands/repository.js +17 -115
- package/dist/commands/resolve.js +61 -0
- package/dist/commands/schema.js +22 -69
- package/dist/commands/service.js +15 -113
- package/dist/commands/sides.js +34 -0
- package/dist/commands/target.js +32 -0
- package/dist/commands/types.js +9 -17
- package/dist/commands/update.js +148 -0
- package/dist/commands/write.js +66 -0
- package/dist/index.js +8 -122
- package/dist/init/content.js +73 -0
- package/dist/init/init.js +66 -0
- package/dist/init/markers.js +21 -0
- package/dist/postinstall.js +80 -0
- package/dist/stack/detect.js +125 -0
- package/dist/stack/profiles/nest.js +18 -0
- package/dist/stack/profiles/next-frontend.js +28 -0
- package/dist/stack/profiles/next-fullstack.js +44 -0
- package/dist/stack/profiles/node.js +17 -0
- package/dist/stack/profiles/react.js +19 -0
- package/dist/stack/registry.js +63 -0
- package/dist/stack/types.js +24 -0
- package/dist/templates/actions.js +68 -0
- package/dist/templates/backend/server-repository.js +22 -0
- package/dist/templates/context.js +52 -0
- package/dist/templates/controllers/express.js +60 -0
- package/dist/templates/controllers/fastify.js +54 -0
- package/dist/templates/controllers/generic.js +30 -0
- package/dist/templates/controllers/hono.js +52 -0
- package/dist/templates/controllers/nest.js +63 -0
- package/dist/templates/controllers/next-action-route.js +40 -0
- package/dist/templates/controllers/next-route.js +62 -0
- package/dist/templates/controllers/node.js +46 -0
- package/dist/templates/controllers/shape.js +28 -0
- package/dist/templates/frontend/client-repository.js +38 -0
- package/dist/templates/frontend/component.js +18 -0
- package/dist/templates/frontend/container.js +28 -0
- package/{src/commands/hook.ts → dist/templates/frontend/hook.js} +28 -41
- package/dist/templates/frontend/page.js +26 -0
- package/dist/templates/nest/dto.js +12 -0
- package/dist/templates/nest/injectable.js +4 -0
- package/dist/templates/nest/module.js +41 -0
- package/dist/templates/service.js +40 -0
- package/dist/templates/shared/schema.js +13 -0
- package/dist/templates/shared/types.js +12 -0
- package/dist/templates/signatures.js +15 -0
- package/dist/update/cache.js +80 -0
- package/dist/update/check.js +47 -0
- package/dist/update/install-mode.js +96 -0
- package/dist/update/package-manager.js +99 -0
- package/dist/update/registry.js +77 -0
- package/dist/update/version.js +70 -0
- package/dist/utils/alias.js +80 -0
- package/dist/utils/fs.js +70 -0
- package/dist/utils/imports.js +61 -0
- package/dist/utils/naming.js +31 -0
- package/dist/utils/paths.js +44 -0
- package/package.json +27 -6
- package/scripts/postinstall.js +7 -0
- package/.github/workflows/publish.yml +0 -28
- package/dist/utils.js +0 -132
- package/src/__tests__/utils.test.ts +0 -128
- package/src/commands/__tests__/feature.test.ts +0 -85
- package/src/commands/__tests__/imports.test.ts +0 -115
- package/src/commands/__tests__/individual.test.ts +0 -137
- package/src/commands/component.ts +0 -33
- package/src/commands/container.ts +0 -42
- package/src/commands/feature.ts +0 -74
- package/src/commands/repository.ts +0 -95
- package/src/commands/schema.ts +0 -47
- package/src/commands/service.ts +0 -93
- package/src/commands/types.ts +0 -25
- package/src/index.ts +0 -126
- package/src/utils.ts +0 -115
- package/tsconfig.json +0 -13
- package/vitest.config.ts +0 -7
|
@@ -1,121 +1,23 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.makeRepository = makeRepository;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
`;
|
|
55
|
-
case 'Show':
|
|
56
|
-
return `import { ${name} } from '${typePath}';
|
|
57
|
-
|
|
58
|
-
export class Show${name}Repository {
|
|
59
|
-
async handle(id: string): Promise<${name}> {
|
|
60
|
-
const response = await fetch(\`/api/${feature}/\${id}\`);
|
|
61
|
-
if (!response.ok) throw new Error('Failed to fetch ${name}');
|
|
62
|
-
return response.json();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
`;
|
|
66
|
-
case 'Create':
|
|
67
|
-
return `import { ${name} } from '${typePath}';
|
|
68
|
-
import { Create${name} } from '${schemaPath('Create')}';
|
|
69
|
-
|
|
70
|
-
export class Create${name}Repository {
|
|
71
|
-
async handle(data: Create${name}): Promise<${name}> {
|
|
72
|
-
const response = await fetch('/api/${feature}', {
|
|
73
|
-
method: 'POST',
|
|
74
|
-
headers: { 'Content-Type': 'application/json' },
|
|
75
|
-
body: JSON.stringify(data),
|
|
76
|
-
});
|
|
77
|
-
if (!response.ok) throw new Error('Failed to create ${name}');
|
|
78
|
-
return response.json();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
`;
|
|
82
|
-
case 'Update':
|
|
83
|
-
return `import { ${name} } from '${typePath}';
|
|
84
|
-
import { Update${name} } from '${schemaPath('Update')}';
|
|
85
|
-
|
|
86
|
-
export class Update${name}Repository {
|
|
87
|
-
async handle(id: string, data: Update${name}): Promise<${name}> {
|
|
88
|
-
const response = await fetch(\`/api/${feature}/\${id}\`, {
|
|
89
|
-
method: 'PUT',
|
|
90
|
-
headers: { 'Content-Type': 'application/json' },
|
|
91
|
-
body: JSON.stringify(data),
|
|
92
|
-
});
|
|
93
|
-
if (!response.ok) throw new Error('Failed to update ${name}');
|
|
94
|
-
return response.json();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
`;
|
|
98
|
-
case 'Delete':
|
|
99
|
-
return `export class Delete${name}Repository {
|
|
100
|
-
async handle(id: string): Promise<void> {
|
|
101
|
-
const response = await fetch(\`/api/${feature}/\${id}\`, {
|
|
102
|
-
method: 'DELETE',
|
|
103
|
-
});
|
|
104
|
-
if (!response.ok) throw new Error('Failed to delete ${name}');
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
`;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
function makeRepository(feature, name) {
|
|
111
|
-
const base = (0, utils_1.ensureFeatureExists)(feature, 'repositories');
|
|
112
|
-
for (const action of REPOSITORY_ACTIONS) {
|
|
113
|
-
const filePath = path.join(base, `${action}${name}.repository.ts`);
|
|
114
|
-
if ((0, utils_1.fileExists)(filePath)) {
|
|
115
|
-
console.warn(`⚠️ Skipping "${action}${name}.repository.ts" — already exists`);
|
|
116
|
-
continue;
|
|
4
|
+
const actions_1 = require("../templates/actions");
|
|
5
|
+
const server_repository_1 = require("../templates/backend/server-repository");
|
|
6
|
+
const client_repository_1 = require("../templates/frontend/client-repository");
|
|
7
|
+
const resolve_1 = require("./resolve");
|
|
8
|
+
const sides_1 = require("./sides");
|
|
9
|
+
const write_1 = require("./write");
|
|
10
|
+
function makeRepository(feature, name, side = 'both') {
|
|
11
|
+
const ctx = (0, resolve_1.requireFeature)(feature);
|
|
12
|
+
let wroteAny = false;
|
|
13
|
+
for (const current of (0, sides_1.resolveSides)(ctx.profile, side, sides_1.REPOSITORY_SIDES)) {
|
|
14
|
+
const dir = (0, resolve_1.ensureLayerDir)(ctx, sides_1.REPOSITORY_SIDES[current]);
|
|
15
|
+
const render = current === 'client' ? client_repository_1.renderClientRepository : server_repository_1.renderServerRepository;
|
|
16
|
+
const written = (0, write_1.writeSpecFiles)(dir, (0, actions_1.standardActions)(name), 'repository', (spec, filePath) => render(ctx, spec, name, filePath));
|
|
17
|
+
if (written > 0) {
|
|
18
|
+
console.log(`✅ Repositories (${current}) for "${name}" created at ${dir}`);
|
|
19
|
+
wroteAny = true;
|
|
117
20
|
}
|
|
118
|
-
(0, utils_1.writeFileSafe)(filePath, renderRepository(action, name, feature));
|
|
119
21
|
}
|
|
120
|
-
|
|
22
|
+
return wroteAny;
|
|
121
23
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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.resolveFeature = resolveFeature;
|
|
37
|
+
exports.requireFeature = requireFeature;
|
|
38
|
+
exports.ensureLayerDir = ensureLayerDir;
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const detect_1 = require("../stack/detect");
|
|
41
|
+
const registry_1 = require("../stack/registry");
|
|
42
|
+
const context_1 = require("../templates/context");
|
|
43
|
+
const fs_1 = require("../utils/fs");
|
|
44
|
+
const naming_1 = require("../utils/naming");
|
|
45
|
+
function resolveFeature(feature) {
|
|
46
|
+
(0, naming_1.validateFeatureName)(feature);
|
|
47
|
+
const stack = (0, detect_1.detectStack)();
|
|
48
|
+
return (0, context_1.createContext)(feature, stack, (0, registry_1.getProfile)(stack.stack));
|
|
49
|
+
}
|
|
50
|
+
function requireFeature(feature) {
|
|
51
|
+
const ctx = resolveFeature(feature);
|
|
52
|
+
if (!(0, fs_1.fileExists)(ctx.featureDir)) {
|
|
53
|
+
throw new Error(`Feature "${feature}" does not exist. Run: domain-driver make:feature ${feature}`);
|
|
54
|
+
}
|
|
55
|
+
return ctx;
|
|
56
|
+
}
|
|
57
|
+
function ensureLayerDir(ctx, layer) {
|
|
58
|
+
const dir = path.join(ctx.featureDir, (0, registry_1.layerDir)(ctx.profile, layer));
|
|
59
|
+
(0, fs_1.mkdirSafe)(dir);
|
|
60
|
+
return dir;
|
|
61
|
+
}
|
package/dist/commands/schema.js
CHANGED
|
@@ -1,74 +1,27 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.makeSchema = makeSchema;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
export const Create${name}Schema = z.object({
|
|
46
|
-
// add create fields here
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
export type Create${name} = z.infer<typeof Create${name}Schema>;
|
|
50
|
-
`;
|
|
51
|
-
case 'Update':
|
|
52
|
-
return `import { z } from 'zod';
|
|
53
|
-
|
|
54
|
-
export const Update${name}Schema = z.object({
|
|
55
|
-
id: z.string(),
|
|
56
|
-
// add update fields here
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
export type Update${name} = z.infer<typeof Update${name}Schema>;
|
|
60
|
-
`;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
4
|
+
const registry_1 = require("../stack/registry");
|
|
5
|
+
const actions_1 = require("../templates/actions");
|
|
6
|
+
const dto_1 = require("../templates/nest/dto");
|
|
7
|
+
const schema_1 = require("../templates/shared/schema");
|
|
8
|
+
const hints_1 = require("./hints");
|
|
9
|
+
const resolve_1 = require("./resolve");
|
|
10
|
+
const write_1 = require("./write");
|
|
63
11
|
function makeSchema(feature, name) {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
(
|
|
72
|
-
|
|
73
|
-
|
|
12
|
+
const ctx = (0, resolve_1.requireFeature)(feature);
|
|
13
|
+
(0, registry_1.assertLayer)(ctx.profile, 'schema', 'make:schema');
|
|
14
|
+
const schemaDir = (0, resolve_1.ensureLayerDir)(ctx, 'schema');
|
|
15
|
+
const written = (0, write_1.writeActionFiles)(schemaDir, name, 'schema', actions_1.WRITE_ACTIONS, (action) => (0, schema_1.renderSchema)(`${action}${name}`, action.toLowerCase()));
|
|
16
|
+
if (written > 0)
|
|
17
|
+
console.log(`✅ Schemas for "${name}" created at ${schemaDir}`);
|
|
18
|
+
if ((0, registry_1.hasLayer)(ctx.profile, 'dto'))
|
|
19
|
+
writeDtos(ctx, name);
|
|
20
|
+
}
|
|
21
|
+
function writeDtos(ctx, name) {
|
|
22
|
+
const dtoDir = (0, resolve_1.ensureLayerDir)(ctx, 'dto');
|
|
23
|
+
const written = (0, write_1.writeActionFiles)(dtoDir, name, 'dto', actions_1.WRITE_ACTIONS, (action, filePath) => (0, dto_1.renderDto)(ctx, `${action}${name}`, filePath));
|
|
24
|
+
(0, hints_1.hintNestjsZod)(ctx.stack);
|
|
25
|
+
if (written > 0)
|
|
26
|
+
console.log(`✅ DTOs for "${name}" created at ${dtoDir}`);
|
|
74
27
|
}
|
package/dist/commands/service.js
CHANGED
|
@@ -1,119 +1,21 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.makeService = makeService;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
export class List${name}Service {
|
|
52
|
-
async handle(): Promise<${name}[]> {
|
|
53
|
-
return repository.handle();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
`;
|
|
57
|
-
case 'Show':
|
|
58
|
-
return `import { ${name} } from '${typePath}';
|
|
59
|
-
import { Show${name}Repository } from '${repoPath('Show')}';
|
|
60
|
-
|
|
61
|
-
const repository = new Show${name}Repository();
|
|
62
|
-
|
|
63
|
-
export class Show${name}Service {
|
|
64
|
-
async handle(id: string): Promise<${name}> {
|
|
65
|
-
return repository.handle(id);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
`;
|
|
69
|
-
case 'Create':
|
|
70
|
-
return `import { ${name} } from '${typePath}';
|
|
71
|
-
import { Create${name} } from '${schemaPath('Create')}';
|
|
72
|
-
import { Create${name}Repository } from '${repoPath('Create')}';
|
|
73
|
-
|
|
74
|
-
const repository = new Create${name}Repository();
|
|
75
|
-
|
|
76
|
-
export class Create${name}Service {
|
|
77
|
-
async handle(data: Create${name}): Promise<${name}> {
|
|
78
|
-
return repository.handle(data);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
`;
|
|
82
|
-
case 'Update':
|
|
83
|
-
return `import { ${name} } from '${typePath}';
|
|
84
|
-
import { Update${name} } from '${schemaPath('Update')}';
|
|
85
|
-
import { Update${name}Repository } from '${repoPath('Update')}';
|
|
86
|
-
|
|
87
|
-
const repository = new Update${name}Repository();
|
|
88
|
-
|
|
89
|
-
export class Update${name}Service {
|
|
90
|
-
async handle(id: string, data: Update${name}): Promise<${name}> {
|
|
91
|
-
return repository.handle(id, data);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
`;
|
|
95
|
-
case 'Delete':
|
|
96
|
-
return `import { Delete${name}Repository } from '${repoPath('Delete')}';
|
|
97
|
-
|
|
98
|
-
const repository = new Delete${name}Repository();
|
|
99
|
-
|
|
100
|
-
export class Delete${name}Service {
|
|
101
|
-
async handle(id: string): Promise<void> {
|
|
102
|
-
return repository.handle(id);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
`;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
function makeService(feature, name) {
|
|
109
|
-
const base = (0, utils_1.ensureFeatureExists)(feature, 'services');
|
|
110
|
-
for (const action of SERVICE_ACTIONS) {
|
|
111
|
-
const filePath = path.join(base, `${action}${name}.service.ts`);
|
|
112
|
-
if ((0, utils_1.fileExists)(filePath)) {
|
|
113
|
-
console.warn(`⚠️ Skipping "${action}${name}.service.ts" — already exists`);
|
|
114
|
-
continue;
|
|
4
|
+
const actions_1 = require("../templates/actions");
|
|
5
|
+
const service_1 = require("../templates/service");
|
|
6
|
+
const resolve_1 = require("./resolve");
|
|
7
|
+
const sides_1 = require("./sides");
|
|
8
|
+
const write_1 = require("./write");
|
|
9
|
+
function makeService(feature, name, side = 'both') {
|
|
10
|
+
const ctx = (0, resolve_1.requireFeature)(feature);
|
|
11
|
+
let wroteAny = false;
|
|
12
|
+
for (const current of (0, sides_1.resolveSides)(ctx.profile, side, sides_1.SERVICE_SIDES)) {
|
|
13
|
+
const dir = (0, resolve_1.ensureLayerDir)(ctx, sides_1.SERVICE_SIDES[current]);
|
|
14
|
+
const written = (0, write_1.writeSpecFiles)(dir, (0, actions_1.standardActions)(name), 'service', (spec, filePath) => (0, service_1.renderService)(ctx, spec, name, filePath, current));
|
|
15
|
+
if (written > 0) {
|
|
16
|
+
console.log(`✅ Services (${current}) for "${name}" created at ${dir}`);
|
|
17
|
+
wroteAny = true;
|
|
115
18
|
}
|
|
116
|
-
(0, utils_1.writeFileSafe)(filePath, renderService(action, name, feature));
|
|
117
19
|
}
|
|
118
|
-
|
|
20
|
+
return wroteAny;
|
|
119
21
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REPOSITORY_SIDES = exports.SERVICE_SIDES = void 0;
|
|
4
|
+
exports.parseSide = parseSide;
|
|
5
|
+
exports.resolveSides = resolveSides;
|
|
6
|
+
const registry_1 = require("../stack/registry");
|
|
7
|
+
exports.SERVICE_SIDES = Object.freeze({
|
|
8
|
+
client: 'clientService',
|
|
9
|
+
server: 'serverService',
|
|
10
|
+
command: 'make:service',
|
|
11
|
+
noun: 'services',
|
|
12
|
+
});
|
|
13
|
+
exports.REPOSITORY_SIDES = Object.freeze({
|
|
14
|
+
client: 'clientRepository',
|
|
15
|
+
server: 'serverRepository',
|
|
16
|
+
command: 'make:repository',
|
|
17
|
+
noun: 'repositories',
|
|
18
|
+
});
|
|
19
|
+
const SIDES = ['client', 'server'];
|
|
20
|
+
function parseSide(value) {
|
|
21
|
+
if (value === 'client' || value === 'server' || value === 'both')
|
|
22
|
+
return value;
|
|
23
|
+
throw new Error(`Invalid --side "${value}". Use client, server, or both.`);
|
|
24
|
+
}
|
|
25
|
+
function resolveSides(profile, option, spec) {
|
|
26
|
+
const available = SIDES.filter((side) => (0, registry_1.hasLayer)(profile, spec[side]));
|
|
27
|
+
if (available.length === 0)
|
|
28
|
+
(0, registry_1.assertLayer)(profile, spec.server, spec.command);
|
|
29
|
+
if (option === 'both')
|
|
30
|
+
return available;
|
|
31
|
+
if (available.includes(option))
|
|
32
|
+
return [option];
|
|
33
|
+
throw new Error(`The ${profile.name} stack has no ${option}-side ${spec.noun}.`);
|
|
34
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseTarget = parseTarget;
|
|
4
|
+
exports.parseFeatureTarget = parseFeatureTarget;
|
|
5
|
+
const naming_1 = require("../utils/naming");
|
|
6
|
+
const NAME_PATTERN = /^[A-Za-z][A-Za-z0-9]*$/;
|
|
7
|
+
function validateName(name) {
|
|
8
|
+
if (!NAME_PATTERN.test(name)) {
|
|
9
|
+
throw new Error(`Name "${name}" must be letters and digits only, for example User.`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function parseTarget(value) {
|
|
13
|
+
const parts = value.split('/');
|
|
14
|
+
if (parts.length !== 2) {
|
|
15
|
+
throw new Error(`Target "${value}" must be <feature>/<Name>, for example users/User.`);
|
|
16
|
+
}
|
|
17
|
+
const [feature, name] = parts;
|
|
18
|
+
(0, naming_1.validateFeatureName)(feature);
|
|
19
|
+
validateName(name);
|
|
20
|
+
return Object.freeze({ feature, name });
|
|
21
|
+
}
|
|
22
|
+
function parseFeatureTarget(value) {
|
|
23
|
+
const parts = value.split('/');
|
|
24
|
+
if (parts.length > 2) {
|
|
25
|
+
throw new Error(`Target "${value}" must be <feature> or <feature>/<Entity>, for example users or users/User.`);
|
|
26
|
+
}
|
|
27
|
+
const [feature, entity] = parts;
|
|
28
|
+
(0, naming_1.validateFeatureName)(feature);
|
|
29
|
+
if (entity !== undefined)
|
|
30
|
+
validateName(entity);
|
|
31
|
+
return Object.freeze({ feature, entity: entity ?? null });
|
|
32
|
+
}
|
package/dist/commands/types.js
CHANGED
|
@@ -35,23 +35,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.makeTypes = makeTypes;
|
|
37
37
|
const path = __importStar(require("path"));
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// add ${name} fields here
|
|
43
|
-
createdAt: string;
|
|
44
|
-
updatedAt: string;
|
|
45
|
-
}
|
|
46
|
-
`;
|
|
47
|
-
}
|
|
38
|
+
const registry_1 = require("../stack/registry");
|
|
39
|
+
const types_1 = require("../templates/shared/types");
|
|
40
|
+
const resolve_1 = require("./resolve");
|
|
41
|
+
const write_1 = require("./write");
|
|
48
42
|
function makeTypes(feature, name) {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
const ctx = (0, resolve_1.requireFeature)(feature);
|
|
44
|
+
(0, registry_1.assertLayer)(ctx.profile, 'types', 'make:types');
|
|
45
|
+
const filePath = path.join((0, resolve_1.ensureLayerDir)(ctx, 'types'), `${name}.types.ts`);
|
|
46
|
+
if ((0, write_1.writeIfAbsent)(filePath, () => (0, types_1.renderTypes)(name))) {
|
|
47
|
+
console.log(`✅ Types for "${name}" created at ${filePath}`);
|
|
54
48
|
}
|
|
55
|
-
(0, utils_1.writeFileSafe)(filePath, renderTypes(name));
|
|
56
|
-
console.log(`✅ Types for "${name}" created at ${filePath}`);
|
|
57
49
|
}
|