domain-driver 0.1.0 → 0.2.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 +138 -146
- 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/write.js +66 -0
- package/dist/index.js +109 -94
- package/dist/init/content.js +73 -0
- package/dist/init/init.js +60 -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/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
|
@@ -0,0 +1,85 @@
|
|
|
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.makeController = makeController;
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
const registry_1 = require("../stack/registry");
|
|
39
|
+
const actions_1 = require("../templates/actions");
|
|
40
|
+
const nest_1 = require("../templates/controllers/nest");
|
|
41
|
+
const next_route_1 = require("../templates/controllers/next-route");
|
|
42
|
+
const node_1 = require("../templates/controllers/node");
|
|
43
|
+
const fs_1 = require("../utils/fs");
|
|
44
|
+
const paths_1 = require("../utils/paths");
|
|
45
|
+
const resolve_1 = require("./resolve");
|
|
46
|
+
const write_1 = require("./write");
|
|
47
|
+
function makeController(feature, name) {
|
|
48
|
+
const ctx = (0, resolve_1.requireFeature)(feature);
|
|
49
|
+
(0, registry_1.assertLayer)(ctx.profile, 'controller', 'make:controller');
|
|
50
|
+
if (ctx.profile.name === 'next-fullstack') {
|
|
51
|
+
return writeNextRoutes(ctx, name);
|
|
52
|
+
}
|
|
53
|
+
const dir = (0, resolve_1.ensureLayerDir)(ctx, 'controller');
|
|
54
|
+
const render = ctx.profile.name === 'nest' ? nest_1.renderNestController : node_1.renderNodeController;
|
|
55
|
+
const written = (0, write_1.writeSpecFiles)(dir, (0, actions_1.standardActions)(name), 'controller', (spec, filePath) => render(ctx, spec, name, filePath));
|
|
56
|
+
if (written > 0)
|
|
57
|
+
console.log(`✅ Controllers for "${name}" created at ${dir}`);
|
|
58
|
+
const wroteRoutes = ctx.profile.name === 'node' ? writeNodeRoutes(ctx, name) : false;
|
|
59
|
+
return written > 0 || wroteRoutes;
|
|
60
|
+
}
|
|
61
|
+
function writeNodeRoutes(ctx, name) {
|
|
62
|
+
const filePath = path.join(ctx.featureDir, `${ctx.feature}.routes.ts`);
|
|
63
|
+
const content = (0, node_1.renderNodeRoutes)(ctx, name, filePath);
|
|
64
|
+
if (content === null) {
|
|
65
|
+
console.log('ℹ️ No HTTP framework detected, generating framework-agnostic controllers.');
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const wrote = (0, write_1.writeIfAbsent)(filePath, () => content);
|
|
69
|
+
if (wrote)
|
|
70
|
+
console.log(`✅ Routes for "${name}" created at ${filePath}`);
|
|
71
|
+
return wrote;
|
|
72
|
+
}
|
|
73
|
+
function writeNextRoutes(ctx, name) {
|
|
74
|
+
const collectionDir = (0, paths_1.apiRouteDir)(ctx.stack, ctx.feature);
|
|
75
|
+
const itemDir = path.join(collectionDir, '[id]');
|
|
76
|
+
(0, fs_1.mkdirSafe)(itemDir);
|
|
77
|
+
const collectionFile = path.join(collectionDir, 'route.ts');
|
|
78
|
+
const itemFile = path.join(itemDir, 'route.ts');
|
|
79
|
+
const wroteCollection = (0, write_1.writeIfAbsent)(collectionFile, () => (0, next_route_1.renderCollectionRoute)(ctx, name, collectionFile));
|
|
80
|
+
const wroteItem = (0, write_1.writeIfAbsent)(itemFile, () => (0, next_route_1.renderItemRoute)(ctx, name, itemFile));
|
|
81
|
+
const wroteAny = wroteCollection || wroteItem;
|
|
82
|
+
if (wroteAny)
|
|
83
|
+
console.log(`✅ Route handlers for "${name}" created at ${collectionDir}`);
|
|
84
|
+
return wroteAny;
|
|
85
|
+
}
|
package/dist/commands/feature.js
CHANGED
|
@@ -35,64 +35,72 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.makeFeature = makeFeature;
|
|
37
37
|
const path = __importStar(require("path"));
|
|
38
|
-
const
|
|
38
|
+
const registry_1 = require("../stack/registry");
|
|
39
|
+
const page_1 = require("../templates/frontend/page");
|
|
40
|
+
const module_1 = require("../templates/nest/module");
|
|
41
|
+
const fs_1 = require("../utils/fs");
|
|
42
|
+
const naming_1 = require("../utils/naming");
|
|
39
43
|
const component_1 = require("./component");
|
|
44
|
+
const container_1 = require("./container");
|
|
45
|
+
const controller_1 = require("./controller");
|
|
40
46
|
const hook_1 = require("./hook");
|
|
41
|
-
const service_1 = require("./service");
|
|
42
47
|
const repository_1 = require("./repository");
|
|
48
|
+
const resolve_1 = require("./resolve");
|
|
43
49
|
const schema_1 = require("./schema");
|
|
44
|
-
const
|
|
50
|
+
const service_1 = require("./service");
|
|
45
51
|
const types_1 = require("./types");
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
'hooks',
|
|
51
|
-
'services',
|
|
52
|
-
'repositories',
|
|
53
|
-
'schemas',
|
|
54
|
-
'types',
|
|
55
|
-
];
|
|
56
|
-
function renderPage(name, pascalName) {
|
|
57
|
-
const containerPath = (0, utils_1.resolveImport)(name, `containers/${pascalName}Container`, true);
|
|
58
|
-
return `import ${pascalName}Container from '${containerPath}';
|
|
59
|
-
|
|
60
|
-
export default function ${pascalName}Page() {
|
|
61
|
-
return (
|
|
62
|
-
<div>
|
|
63
|
-
<${pascalName}Container />
|
|
64
|
-
</div>
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
`;
|
|
68
|
-
}
|
|
69
|
-
async function makeFeature(name, all = false) {
|
|
70
|
-
const base = (0, utils_1.featureBasePath)(name);
|
|
71
|
-
const pascalName = (0, utils_1.toPascalCase)(name);
|
|
72
|
-
if ((0, utils_1.fileExists)(base)) {
|
|
73
|
-
throw new Error(`Feature "${name}" already exists at ${base}`);
|
|
52
|
+
async function makeFeature(name, all = false, entityName) {
|
|
53
|
+
const ctx = (0, resolve_1.resolveFeature)(name);
|
|
54
|
+
if ((0, fs_1.fileExists)(ctx.featureDir)) {
|
|
55
|
+
throw new Error(`Feature "${name}" already exists at ${ctx.featureDir}`);
|
|
74
56
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (all)
|
|
82
|
-
|
|
57
|
+
const entity = entityName ?? (0, naming_1.toPascalCase)(name);
|
|
58
|
+
createFolders(ctx, all);
|
|
59
|
+
console.log(`✅ Feature "${name}" scaffolded at ${ctx.featureDir}`);
|
|
60
|
+
if (all)
|
|
61
|
+
scaffoldLayers(ctx, entity);
|
|
62
|
+
writeEntryFile(ctx, entity, all);
|
|
63
|
+
if (all)
|
|
64
|
+
console.log(`✅ All files scaffolded for "${name}"`);
|
|
65
|
+
}
|
|
66
|
+
function createFolders(ctx, all) {
|
|
67
|
+
for (const folder of ctx.profile.folders) {
|
|
68
|
+
const dir = path.join(ctx.featureDir, folder);
|
|
69
|
+
(0, fs_1.mkdirSafe)(dir);
|
|
70
|
+
if (!all)
|
|
71
|
+
(0, fs_1.writeFileSafe)(path.join(dir, '.gitkeep'), '');
|
|
83
72
|
}
|
|
84
|
-
|
|
85
|
-
|
|
73
|
+
}
|
|
74
|
+
function scaffoldLayers(ctx, entity) {
|
|
75
|
+
const { feature, profile } = ctx;
|
|
76
|
+
if ((0, registry_1.hasLayer)(profile, 'types'))
|
|
77
|
+
(0, types_1.makeTypes)(feature, entity);
|
|
78
|
+
if ((0, registry_1.hasLayer)(profile, 'schema'))
|
|
79
|
+
(0, schema_1.makeSchema)(feature, entity);
|
|
80
|
+
if ((0, registry_1.hasLayer)(profile, 'serverRepository'))
|
|
81
|
+
(0, repository_1.makeRepository)(feature, entity, 'server');
|
|
82
|
+
if ((0, registry_1.hasLayer)(profile, 'serverService'))
|
|
83
|
+
(0, service_1.makeService)(feature, entity, 'server');
|
|
84
|
+
if ((0, registry_1.hasLayer)(profile, 'controller'))
|
|
85
|
+
(0, controller_1.makeController)(feature, entity);
|
|
86
|
+
if ((0, registry_1.hasLayer)(profile, 'clientRepository'))
|
|
87
|
+
(0, repository_1.makeRepository)(feature, entity, 'client');
|
|
88
|
+
if ((0, registry_1.hasLayer)(profile, 'clientService'))
|
|
89
|
+
(0, service_1.makeService)(feature, entity, 'client');
|
|
90
|
+
if ((0, registry_1.hasLayer)(profile, 'hook'))
|
|
91
|
+
(0, hook_1.makeHook)(feature, `use${entity}`, entity);
|
|
92
|
+
if ((0, registry_1.hasLayer)(profile, 'component'))
|
|
93
|
+
(0, component_1.makeComponent)(feature, entity, 'client');
|
|
94
|
+
if ((0, registry_1.hasLayer)(profile, 'container'))
|
|
95
|
+
(0, container_1.makeContainer)(feature, `${entity}Container`, entity);
|
|
96
|
+
}
|
|
97
|
+
function writeEntryFile(ctx, entity, all) {
|
|
98
|
+
if ((0, registry_1.hasLayer)(ctx.profile, 'page')) {
|
|
99
|
+
const filePath = path.join(ctx.featureDir, 'page.tsx');
|
|
100
|
+
(0, fs_1.writeFileSafe)(filePath, (0, page_1.renderPage)(ctx, entity, filePath, all));
|
|
86
101
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
(0,
|
|
90
|
-
(0, schema_1.makeSchema)(name, pascalName);
|
|
91
|
-
(0, repository_1.makeRepository)(name, pascalName);
|
|
92
|
-
(0, service_1.makeService)(name, pascalName);
|
|
93
|
-
(0, hook_1.makeHook)(name, `use${pascalName}`, pascalName);
|
|
94
|
-
(0, component_1.makeComponent)(name, pascalName, 'client');
|
|
95
|
-
(0, container_1.makeContainer)(name, `${pascalName}Container`, pascalName);
|
|
96
|
-
console.log(`✅ All files scaffolded for "${name}"`);
|
|
102
|
+
if ((0, registry_1.hasLayer)(ctx.profile, 'module')) {
|
|
103
|
+
const filePath = path.join(ctx.featureDir, `${ctx.feature}.module.ts`);
|
|
104
|
+
(0, fs_1.writeFileSafe)(filePath, (0, module_1.renderModule)(ctx, entity, filePath, all));
|
|
97
105
|
}
|
|
98
106
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resetHints = resetHints;
|
|
4
|
+
exports.hintNestjsZod = hintNestjsZod;
|
|
5
|
+
exports.standardClassNames = standardClassNames;
|
|
6
|
+
exports.hintRegisterInModule = hintRegisterInModule;
|
|
7
|
+
const detect_1 = require("../stack/detect");
|
|
8
|
+
const actions_1 = require("../templates/actions");
|
|
9
|
+
let nestjsZodHinted = false;
|
|
10
|
+
function resetHints() {
|
|
11
|
+
nestjsZodHinted = false;
|
|
12
|
+
}
|
|
13
|
+
function hintNestjsZod(stack) {
|
|
14
|
+
if (stack.stack !== 'nest' || stack.hasNestjsZod || nestjsZodHinted)
|
|
15
|
+
return;
|
|
16
|
+
nestjsZodHinted = true;
|
|
17
|
+
console.log('ℹ️ nestjs-zod is not installed. Run: npm install nestjs-zod');
|
|
18
|
+
console.log(' Then register the pipe in AppModule: { provide: APP_PIPE, useClass: ZodValidationPipe }');
|
|
19
|
+
}
|
|
20
|
+
function standardClassNames(name, suffix) {
|
|
21
|
+
return actions_1.ACTIONS.map((action) => `${action}${name}${suffix}`);
|
|
22
|
+
}
|
|
23
|
+
function hintRegisterInModule(feature, classNames, note) {
|
|
24
|
+
if ((0, detect_1.detectStack)().stack !== 'nest')
|
|
25
|
+
return;
|
|
26
|
+
const suffix = note !== undefined ? ` (${note})` : '';
|
|
27
|
+
console.log(`ℹ️ Register ${classNames.join(', ')} in ${feature}.module.ts${suffix}`);
|
|
28
|
+
}
|
package/dist/commands/hook.js
CHANGED
|
@@ -35,119 +35,18 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.makeHook = makeHook;
|
|
37
37
|
const path = __importStar(require("path"));
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const schemaPath = (op) => (0, utils_1.resolveImport)(feature, `schemas/${op}${name}.schema`);
|
|
43
|
-
return `'use client';
|
|
44
|
-
|
|
45
|
-
import { useState, useEffect, useCallback } from 'react';
|
|
46
|
-
import { ${name} } from '${typePath}';
|
|
47
|
-
import { List${name}Service } from '${svcPath('List')}';
|
|
48
|
-
import { Show${name}Service } from '${svcPath('Show')}';
|
|
49
|
-
import { Create${name}Service } from '${svcPath('Create')}';
|
|
50
|
-
import { Update${name}Service } from '${svcPath('Update')}';
|
|
51
|
-
import { Delete${name}Service } from '${svcPath('Delete')}';
|
|
52
|
-
import { Create${name} } from '${schemaPath('Create')}';
|
|
53
|
-
import { Update${name} } from '${schemaPath('Update')}';
|
|
54
|
-
|
|
55
|
-
const listService = new List${name}Service();
|
|
56
|
-
const showService = new Show${name}Service();
|
|
57
|
-
const createService = new Create${name}Service();
|
|
58
|
-
const updateService = new Update${name}Service();
|
|
59
|
-
const deleteService = new Delete${name}Service();
|
|
60
|
-
|
|
61
|
-
export function ${hookName}() {
|
|
62
|
-
const [items, setItems] = useState<${name}[]>([]);
|
|
63
|
-
const [selected, setSelected] = useState<${name} | null>(null);
|
|
64
|
-
const [loading, setLoading] = useState(false);
|
|
65
|
-
const [error, setError] = useState<string | null>(null);
|
|
66
|
-
|
|
67
|
-
const fetchAll = useCallback(async () => {
|
|
68
|
-
setLoading(true);
|
|
69
|
-
setError(null);
|
|
70
|
-
try {
|
|
71
|
-
const data = await listService.handle();
|
|
72
|
-
setItems(data);
|
|
73
|
-
} catch (err: unknown) {
|
|
74
|
-
setError(err instanceof Error ? err.message : 'Failed to fetch');
|
|
75
|
-
} finally {
|
|
76
|
-
setLoading(false);
|
|
77
|
-
}
|
|
78
|
-
}, []);
|
|
79
|
-
|
|
80
|
-
const fetchOne = useCallback(async (id: string) => {
|
|
81
|
-
setLoading(true);
|
|
82
|
-
setError(null);
|
|
83
|
-
try {
|
|
84
|
-
const data = await showService.handle(id);
|
|
85
|
-
setSelected(data);
|
|
86
|
-
} catch (err: unknown) {
|
|
87
|
-
setError(err instanceof Error ? err.message : 'Failed to fetch');
|
|
88
|
-
} finally {
|
|
89
|
-
setLoading(false);
|
|
90
|
-
}
|
|
91
|
-
}, []);
|
|
92
|
-
|
|
93
|
-
const create = useCallback(async (data: Create${name}) => {
|
|
94
|
-
setLoading(true);
|
|
95
|
-
setError(null);
|
|
96
|
-
try {
|
|
97
|
-
const created = await createService.handle(data);
|
|
98
|
-
setItems((prev) => [...prev, created]);
|
|
99
|
-
return created;
|
|
100
|
-
} catch (err: unknown) {
|
|
101
|
-
setError(err instanceof Error ? err.message : 'Failed to create');
|
|
102
|
-
return null;
|
|
103
|
-
} finally {
|
|
104
|
-
setLoading(false);
|
|
105
|
-
}
|
|
106
|
-
}, []);
|
|
107
|
-
|
|
108
|
-
const update = useCallback(async (id: string, data: Update${name}) => {
|
|
109
|
-
setLoading(true);
|
|
110
|
-
setError(null);
|
|
111
|
-
try {
|
|
112
|
-
const updated = await updateService.handle(id, data);
|
|
113
|
-
setItems((prev) => prev.map((item) => (item.id === id ? updated : item)));
|
|
114
|
-
return updated;
|
|
115
|
-
} catch (err: unknown) {
|
|
116
|
-
setError(err instanceof Error ? err.message : 'Failed to update');
|
|
117
|
-
return null;
|
|
118
|
-
} finally {
|
|
119
|
-
setLoading(false);
|
|
120
|
-
}
|
|
121
|
-
}, []);
|
|
122
|
-
|
|
123
|
-
const remove = useCallback(async (id: string) => {
|
|
124
|
-
setLoading(true);
|
|
125
|
-
setError(null);
|
|
126
|
-
try {
|
|
127
|
-
await deleteService.handle(id);
|
|
128
|
-
setItems((prev) => prev.filter((item) => item.id !== id));
|
|
129
|
-
} catch (err: unknown) {
|
|
130
|
-
setError(err instanceof Error ? err.message : 'Failed to delete');
|
|
131
|
-
} finally {
|
|
132
|
-
setLoading(false);
|
|
133
|
-
}
|
|
134
|
-
}, []);
|
|
135
|
-
|
|
136
|
-
useEffect(() => {
|
|
137
|
-
fetchAll();
|
|
138
|
-
}, [fetchAll]);
|
|
139
|
-
|
|
140
|
-
return { items, selected, loading, error, fetchAll, fetchOne, create, update, remove };
|
|
141
|
-
}
|
|
142
|
-
`;
|
|
143
|
-
}
|
|
38
|
+
const registry_1 = require("../stack/registry");
|
|
39
|
+
const hook_1 = require("../templates/frontend/hook");
|
|
40
|
+
const fs_1 = require("../utils/fs");
|
|
41
|
+
const resolve_1 = require("./resolve");
|
|
144
42
|
function makeHook(feature, name, pascalName) {
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
43
|
+
const ctx = (0, resolve_1.requireFeature)(feature);
|
|
44
|
+
(0, registry_1.assertLayer)(ctx.profile, 'hook', 'make:hook');
|
|
45
|
+
const filePath = path.join((0, resolve_1.ensureLayerDir)(ctx, 'hook'), `${name}.ts`);
|
|
46
|
+
if ((0, fs_1.fileExists)(filePath)) {
|
|
148
47
|
throw new Error(`Hook "${name}" already exists at ${filePath}`);
|
|
149
48
|
}
|
|
150
|
-
const
|
|
151
|
-
(0,
|
|
49
|
+
const entity = pascalName ?? name.replace(/^use/, '');
|
|
50
|
+
(0, fs_1.writeFileSafe)(filePath, (0, hook_1.renderHook)(ctx, name, entity, filePath));
|
|
152
51
|
console.log(`✅ Hook "${name}" created at ${filePath}`);
|
|
153
52
|
}
|
|
@@ -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
|
}
|