@azure-net/cli 2.0.1 → 2.0.2
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/package.json
CHANGED
|
@@ -13,7 +13,9 @@ const entityTemplate = `export interface I{{name}} {
|
|
|
13
13
|
\tupdated_at: string;
|
|
14
14
|
}`;
|
|
15
15
|
|
|
16
|
-
const portsIndexTemplate = `
|
|
16
|
+
const portsIndexTemplate = `import type { I{{name}} } from '../../Entities/{{name}}';
|
|
17
|
+
|
|
18
|
+
export interface I{{name}}Collection {
|
|
17
19
|
\tdata: I{{name}}[];
|
|
18
20
|
\ttotal: number;
|
|
19
21
|
}
|
|
@@ -33,13 +35,13 @@ export interface I{{name}}UpdateRequest {
|
|
|
33
35
|
}`;
|
|
34
36
|
|
|
35
37
|
const repositoryTemplate = `import { {{datasource}} } from '{{datasourceImport}}';
|
|
36
|
-
import type { I{{name}} } from '
|
|
38
|
+
import type { I{{name}} } from '\${{context}}/Domain/Entities/{{name}}';
|
|
37
39
|
import type {
|
|
38
40
|
\tI{{name}}Collection,
|
|
39
41
|
\tI{{name}}CollectionQuery,
|
|
40
42
|
\tI{{name}}CreateRequest,
|
|
41
43
|
\tI{{name}}UpdateRequest
|
|
42
|
-
} from '
|
|
44
|
+
} from '\${{context}}/Domain/Ports/{{name}}';
|
|
43
45
|
|
|
44
46
|
export class {{name}}Repository {
|
|
45
47
|
\tprivate endpoint = '{{endpoint}}';
|
|
@@ -93,7 +95,7 @@ export class {{name}}Service extends ClassMirror<{{name}}Repository> {
|
|
|
93
95
|
}`;
|
|
94
96
|
|
|
95
97
|
const createSchemaTemplate = `import { {{schemaFactory}} } from '{{schemaImport}}';
|
|
96
|
-
import type { I{{name}}CreateRequest } from '
|
|
98
|
+
import type { I{{name}}CreateRequest } from '\${{context}}/Domain/Ports/{{name}}';
|
|
97
99
|
|
|
98
100
|
export const Create{{name}}Schema = {{schemaFactory}}<I{{name}}CreateRequest>()
|
|
99
101
|
\t.rules((rules) => ({
|
|
@@ -102,7 +104,7 @@ export const Create{{name}}Schema = {{schemaFactory}}<I{{name}}CreateRequest>()
|
|
|
102
104
|
\t.create();`;
|
|
103
105
|
|
|
104
106
|
const updateSchemaTemplate = `import { {{schemaFactory}} } from '{{schemaImport}}';
|
|
105
|
-
import type { I{{name}}UpdateRequest } from '
|
|
107
|
+
import type { I{{name}}UpdateRequest } from '\${{context}}/Domain/Ports/{{name}}';
|
|
106
108
|
|
|
107
109
|
export const Update{{name}}Schema = {{schemaFactory}}<I{{name}}UpdateRequest>()
|
|
108
110
|
\t.rules((rules) => ({
|
|
@@ -111,13 +113,13 @@ export const Update{{name}}Schema = {{schemaFactory}}<I{{name}}UpdateRequest>()
|
|
|
111
113
|
\t.create();`;
|
|
112
114
|
|
|
113
115
|
const presenterTemplate = `import { {{presenterFactory}} } from '{{presenterImport}}';
|
|
114
|
-
import { ApplicationProvider } from '
|
|
116
|
+
import { ApplicationProvider } from '\${{context}}/Application';
|
|
115
117
|
import { Create{{name}}Schema, Update{{name}}Schema } from './Schema';
|
|
116
118
|
import type {
|
|
117
119
|
\tI{{name}}CollectionQuery,
|
|
118
120
|
\tI{{name}}CreateRequest,
|
|
119
121
|
\tI{{name}}UpdateRequest
|
|
120
|
-
} from '
|
|
122
|
+
} from '\${{context}}/Domain/Ports/{{name}}';
|
|
121
123
|
|
|
122
124
|
export const {{name}}Presenter = {{presenterFactory}}('{{name}}Presenter', ({ createAsyncResource, createAsyncAction }) => {
|
|
123
125
|
\tconst { {{name}}Service } = ApplicationProvider();
|
|
@@ -236,7 +238,7 @@ export default async function generateCrud() {
|
|
|
236
238
|
const repoPath = path.join(contextPath, 'Infrastructure', 'Http', 'Repositories');
|
|
237
239
|
const datasourceImport = datasource.from === 'core'
|
|
238
240
|
? '$core/Datasource'
|
|
239
|
-
:
|
|
241
|
+
: `\$${context}/Infrastructure/Http/Datasource`;
|
|
240
242
|
|
|
241
243
|
await writeIfNotExists(
|
|
242
244
|
path.join(repoPath, `${pascalName}Repository.ts`),
|
|
@@ -265,28 +267,54 @@ export default async function generateCrud() {
|
|
|
265
267
|
const schemaPath = path.join(deliveryModulePath, 'Schema');
|
|
266
268
|
|
|
267
269
|
// Create schemas
|
|
268
|
-
const schemaFactory = schemaType === 'package' ? '
|
|
270
|
+
const schemaFactory = schemaType === 'package' ? 'Schema' : schemaType;
|
|
269
271
|
const schemaImport = schemaType === 'package'
|
|
270
272
|
? '@azure-net/kit'
|
|
271
273
|
: '$core/Schema';
|
|
272
274
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
275
|
+
if (schemaType === 'package') {
|
|
276
|
+
// Add the import for createSchemaFactory and rules
|
|
277
|
+
const schemaImportFull = `import { createSchemaFactory } from '@azure-net/kit';
|
|
278
|
+
import { createRules, validationMessagesI18n } from '@azure-net/kit/schema';
|
|
279
|
+
|
|
280
|
+
const Schema = createSchemaFactory(createRules(validationMessagesI18n));`;
|
|
281
|
+
|
|
282
|
+
await writeIfNotExists(
|
|
283
|
+
path.join(schemaPath, `Create${pascalName}Schema.ts`),
|
|
284
|
+
schemaImportFull + '\n' + createSchemaTemplate
|
|
285
|
+
.replace('import { {{schemaFactory}} } from \'{{schemaImport}}\';\n', '')
|
|
286
|
+
.replace(/{{name}}/g, pascalName)
|
|
287
|
+
.replace(/{{context}}/g, context)
|
|
288
|
+
.replace(/{{schemaFactory}}/g, 'Schema')
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
await writeIfNotExists(
|
|
292
|
+
path.join(schemaPath, `Update${pascalName}Schema.ts`),
|
|
293
|
+
schemaImportFull + '\n' + updateSchemaTemplate
|
|
294
|
+
.replace('import { {{schemaFactory}} } from \'{{schemaImport}}\';\n', '')
|
|
295
|
+
.replace(/{{name}}/g, pascalName)
|
|
296
|
+
.replace(/{{context}}/g, context)
|
|
297
|
+
.replace(/{{schemaFactory}}/g, 'Schema')
|
|
298
|
+
);
|
|
299
|
+
} else {
|
|
300
|
+
await writeIfNotExists(
|
|
301
|
+
path.join(schemaPath, `Create${pascalName}Schema.ts`),
|
|
302
|
+
createSchemaTemplate
|
|
303
|
+
.replace(/{{name}}/g, pascalName)
|
|
304
|
+
.replace(/{{context}}/g, context)
|
|
305
|
+
.replace(/{{schemaFactory}}/g, schemaFactory)
|
|
306
|
+
.replace(/{{schemaImport}}/g, schemaImport)
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
await writeIfNotExists(
|
|
310
|
+
path.join(schemaPath, `Update${pascalName}Schema.ts`),
|
|
311
|
+
updateSchemaTemplate
|
|
312
|
+
.replace(/{{name}}/g, pascalName)
|
|
313
|
+
.replace(/{{context}}/g, context)
|
|
314
|
+
.replace(/{{schemaFactory}}/g, schemaFactory)
|
|
315
|
+
.replace(/{{schemaImport}}/g, schemaImport)
|
|
316
|
+
);
|
|
317
|
+
}
|
|
290
318
|
await updateIndexTs(schemaPath);
|
|
291
319
|
|
|
292
320
|
// 6. Create Presenter
|
|
@@ -3,7 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import { selectContext, getContextPath, toPascalCase, getAvailableFiles } from '../../utils/contextUtils.js';
|
|
4
4
|
import { writeIfNotExists, updateIndexTs } from '../../utils/fileUtils.js';
|
|
5
5
|
|
|
6
|
-
const presenterWithCoreTemplate = `import { {{corePresenter}} } from '
|
|
6
|
+
const presenterWithCoreTemplate = `import { {{corePresenter}} } from '\$core/Presenter';
|
|
7
7
|
{{serviceImport}}
|
|
8
8
|
|
|
9
9
|
export const {{name}}Presenter = {{corePresenter}}('{{name}}Presenter', ({ createAsyncResource, createAsyncAction }) => {
|
|
@@ -85,7 +85,7 @@ export default async function generatePresenter() {
|
|
|
85
85
|
const filePath = path.join(modulePath, `${pascalName}Presenter.ts`);
|
|
86
86
|
|
|
87
87
|
const serviceImport = service
|
|
88
|
-
? `import { ApplicationProvider } from '
|
|
88
|
+
? `import { ApplicationProvider } from '\$${context}/Application';`
|
|
89
89
|
: '';
|
|
90
90
|
|
|
91
91
|
const serviceInit = service
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import prompts from 'prompts';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import fs from 'fs/promises';
|
|
3
4
|
import { selectContext, getContextPath, toPascalCase, getAvailableFiles } from '../../utils/contextUtils.js';
|
|
4
5
|
import { writeIfNotExists, updateIndexTs } from '../../utils/fileUtils.js';
|
|
5
6
|
|
|
6
|
-
const schemaWithCoreTemplate = `import { {{coreSchema}} } from '
|
|
7
|
-
import type { I{{name}}Request } from '
|
|
7
|
+
const schemaWithCoreTemplate = `import { {{coreSchema}} } from '\$core/Schema';
|
|
8
|
+
import type { I{{name}}Request } from '\${{context}}/Domain/Ports/{{entity}}';
|
|
8
9
|
|
|
9
10
|
export const {{name}}Schema = {{coreSchema}}<I{{name}}Request>()
|
|
10
11
|
\t.rules((rules) => ({
|
|
@@ -14,7 +15,7 @@ export const {{name}}Schema = {{coreSchema}}<I{{name}}Request>()
|
|
|
14
15
|
|
|
15
16
|
const schemaWithPackageTemplate = `import { createSchemaFactory } from '@azure-net/kit';
|
|
16
17
|
import { createRules, validationMessagesI18n } from '@azure-net/kit/schema';
|
|
17
|
-
import type { I{{name}}Request } from '
|
|
18
|
+
import type { I{{name}}Request } from '\${{context}}/Domain/Ports/{{entity}}';
|
|
18
19
|
|
|
19
20
|
const Schema = createSchemaFactory(createRules(validationMessagesI18n));
|
|
20
21
|
|
|
@@ -6,7 +6,7 @@ import { writeIfNotExists, updateIndexTs } from '../../utils/fileUtils.js';
|
|
|
6
6
|
import { ensureProvider, addToProvider } from '../../utils/providerUtils.js';
|
|
7
7
|
|
|
8
8
|
const serviceTemplate = `import { ClassMirror } from '@azure-net/kit';
|
|
9
|
-
import { {{repository}} } from '../../Infrastructure/Repositories
|
|
9
|
+
import { {{repository}} } from '../../Infrastructure/Http/Repositories';
|
|
10
10
|
|
|
11
11
|
export class {{name}}Service extends ClassMirror<{{repository}}> {
|
|
12
12
|
\tconstructor(private {{repositoryVar}}: {{repository}}) {
|
|
@@ -42,12 +42,12 @@ export default async function generateService() {
|
|
|
42
42
|
// Get available repositories
|
|
43
43
|
const contextPath = getContextPath(context);
|
|
44
44
|
const repositories = await getAvailableFiles(
|
|
45
|
-
path.join(contextPath, 'Infrastructure', 'Repositories')
|
|
45
|
+
path.join(contextPath, 'Infrastructure', 'Http', 'Repositories')
|
|
46
46
|
);
|
|
47
47
|
|
|
48
48
|
const choices = [
|
|
49
49
|
{ title: 'Without repository', value: null },
|
|
50
|
-
...repositories.map(r => ({ title: `${r}
|
|
50
|
+
...repositories.map(r => ({ title: `${r}`, value: r }))
|
|
51
51
|
];
|
|
52
52
|
|
|
53
53
|
const { repository } = await prompts({
|
|
@@ -74,19 +74,20 @@ export default async function generateService() {
|
|
|
74
74
|
|
|
75
75
|
// Ensure ApplicationProvider exists and add service
|
|
76
76
|
const appProvider = await ensureProvider(context, 'Application', { infrastructure: true });
|
|
77
|
-
await addToProvider(
|
|
78
|
-
appProvider.path,
|
|
79
|
-
`${pascalName}Service`,
|
|
80
|
-
'../Services/index.js'
|
|
81
|
-
);
|
|
82
77
|
|
|
83
|
-
// Add repository dependency if selected
|
|
84
78
|
if (repository) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
79
|
+
await addToProvider(
|
|
80
|
+
appProvider.path,
|
|
81
|
+
`${pascalName}Service`,
|
|
82
|
+
'../Services',
|
|
83
|
+
`InfrastructureProvider.${repository}`
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
await addToProvider(
|
|
87
|
+
appProvider.path,
|
|
88
|
+
`${pascalName}Service`,
|
|
89
|
+
'../Services'
|
|
90
|
+
);
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
console.log(`✅ Service created at ${filePath}`);
|
|
@@ -43,7 +43,7 @@ function generateProviderContent(context, layer, dependencies) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
if (dependencies.infrastructure && layer === 'Application') {
|
|
46
|
-
imports.push(`import { InfrastructureProvider } from '
|
|
46
|
+
imports.push(`import { InfrastructureProvider } from '\$${context}/Infrastructure';`);
|
|
47
47
|
deps.push('InfrastructureProvider');
|
|
48
48
|
}
|
|
49
49
|
|