ddd-ts-kit 0.3.0 → 0.4.1
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 +44 -1
- package/dist/check/canonical/roles.d.ts.map +1 -1
- package/dist/check/canonical/roles.js +18 -1
- package/dist/check/canonical/roles.js.map +1 -1
- package/dist/check/catalogue/eslint-only-rules.d.ts.map +1 -1
- package/dist/check/catalogue/eslint-only-rules.js +12 -0
- package/dist/check/catalogue/eslint-only-rules.js.map +1 -1
- package/dist/check/declarations/classes-of.d.ts +2 -2
- package/dist/check/declarations/classes-of.js +4 -6
- package/dist/check/declarations/classes-of.js.map +1 -1
- package/dist/check/explain/tree-docs.d.ts.map +1 -1
- package/dist/check/explain/tree-docs.js +3 -2
- package/dist/check/explain/tree-docs.js.map +1 -1
- package/dist/check/fixtures/authz-declared-fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/authz-declared-fixtures.js +19 -0
- package/dist/check/fixtures/authz-declared-fixtures.js.map +1 -1
- package/dist/check/fixtures/errors-fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/errors-fixtures.js +10 -0
- package/dist/check/fixtures/errors-fixtures.js.map +1 -1
- package/dist/check/fixtures/tree-fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/tree-fixtures.js +25 -3
- package/dist/check/fixtures/tree-fixtures.js.map +1 -1
- package/dist/check/rules/authz-declared.d.ts.map +1 -1
- package/dist/check/rules/authz-declared.js +24 -0
- package/dist/check/rules/authz-declared.js.map +1 -1
- package/dist/check/rules/declarations-role-declared.js +1 -1
- package/dist/check/rules/declarations-role-declared.js.map +1 -1
- package/dist/check/rules/errors-known-code.js +2 -2
- package/dist/check/rules/errors-known-code.js.map +1 -1
- package/dist/commands/controllers.d.ts +8 -0
- package/dist/commands/controllers.d.ts.map +1 -0
- package/dist/commands/controllers.js +57 -0
- package/dist/commands/controllers.js.map +1 -0
- package/dist/commands/generate.js +10 -0
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +1 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/parse-stack.d.ts.map +1 -1
- package/dist/config/parse-stack.js +2 -1
- package/dist/config/parse-stack.js.map +1 -1
- package/dist/config/stack.d.ts +9 -0
- package/dist/config/stack.d.ts.map +1 -1
- package/dist/config/stack.js +1 -0
- package/dist/config/stack.js.map +1 -1
- package/dist/controllers/entries-of.d.ts +3 -0
- package/dist/controllers/entries-of.d.ts.map +1 -0
- package/dist/controllers/entries-of.js +19 -0
- package/dist/controllers/entries-of.js.map +1 -0
- package/dist/controllers/finish-migration.d.ts +8 -0
- package/dist/controllers/finish-migration.d.ts.map +1 -0
- package/dist/controllers/finish-migration.js +71 -0
- package/dist/controllers/finish-migration.js.map +1 -0
- package/dist/controllers/function-route.d.ts +23 -0
- package/dist/controllers/function-route.d.ts.map +1 -0
- package/dist/controllers/function-route.js +2 -0
- package/dist/controllers/function-route.js.map +1 -0
- package/dist/controllers/handle-body.d.ts +8 -0
- package/dist/controllers/handle-body.d.ts.map +1 -0
- package/dist/controllers/handle-body.js +29 -0
- package/dist/controllers/handle-body.js.map +1 -0
- package/dist/controllers/handle-types-of.d.ts +15 -0
- package/dist/controllers/handle-types-of.d.ts.map +1 -0
- package/dist/controllers/handle-types-of.js +48 -0
- package/dist/controllers/handle-types-of.js.map +1 -0
- package/dist/controllers/migrate-context.d.ts +4 -0
- package/dist/controllers/migrate-context.d.ts.map +1 -0
- package/dist/controllers/migrate-context.js +74 -0
- package/dist/controllers/migrate-context.js.map +1 -0
- package/dist/controllers/migrated-group.d.ts +11 -0
- package/dist/controllers/migrated-group.d.ts.map +1 -0
- package/dist/controllers/migrated-group.js +2 -0
- package/dist/controllers/migrated-group.js.map +1 -0
- package/dist/controllers/migration.d.ts +16 -0
- package/dist/controllers/migration.d.ts.map +1 -0
- package/dist/controllers/migration.js +2 -0
- package/dist/controllers/migration.js.map +1 -0
- package/dist/controllers/plan-context.d.ts +22 -0
- package/dist/controllers/plan-context.d.ts.map +1 -0
- package/dist/controllers/plan-context.js +70 -0
- package/dist/controllers/plan-context.js.map +1 -0
- package/dist/controllers/read-function-route.d.ts +4 -0
- package/dist/controllers/read-function-route.d.ts.map +1 -0
- package/dist/controllers/read-function-route.js +37 -0
- package/dist/controllers/read-function-route.js.map +1 -0
- package/dist/controllers/render-controller.d.ts +15 -0
- package/dist/controllers/render-controller.d.ts.map +1 -0
- package/dist/controllers/render-controller.js +104 -0
- package/dist/controllers/render-controller.js.map +1 -0
- package/dist/declared/declared-role.d.ts +8 -2
- package/dist/declared/declared-role.d.ts.map +1 -1
- package/dist/declared/declared-role.js +17 -3
- package/dist/declared/declared-role.js.map +1 -1
- package/dist/declared/index.d.ts +1 -1
- package/dist/declared/index.d.ts.map +1 -1
- package/dist/declared/index.js +1 -1
- package/dist/declared/index.js.map +1 -1
- package/dist/depcruise/hygiene-rules.js +2 -1
- package/dist/depcruise/hygiene-rules.js.map +1 -1
- package/dist/describe/context-description.d.ts +5 -0
- package/dist/describe/context-description.d.ts.map +1 -1
- package/dist/describe/decorator-options.d.ts +3 -0
- package/dist/describe/decorator-options.d.ts.map +1 -0
- package/dist/describe/decorator-options.js +20 -0
- package/dist/describe/decorator-options.js.map +1 -0
- package/dist/describe/format-description.js +4 -1
- package/dist/describe/format-description.js.map +1 -1
- package/dist/describe/listed-in.d.ts +3 -0
- package/dist/describe/listed-in.d.ts.map +1 -0
- package/dist/describe/listed-in.js +9 -0
- package/dist/describe/listed-in.js.map +1 -0
- package/dist/describe/read-controllers.d.ts +5 -0
- package/dist/describe/read-controllers.d.ts.map +1 -0
- package/dist/describe/read-controllers.js +98 -0
- package/dist/describe/read-controllers.js.map +1 -0
- package/dist/describe/read-route-groups.d.ts +5 -0
- package/dist/describe/read-route-groups.d.ts.map +1 -0
- package/dist/describe/read-route-groups.js +37 -0
- package/dist/describe/read-route-groups.js.map +1 -0
- package/dist/describe/read-routes.d.ts +4 -1
- package/dist/describe/read-routes.d.ts.map +1 -1
- package/dist/describe/read-routes.js +10 -4
- package/dist/describe/read-routes.js.map +1 -1
- package/dist/describe/reference-lines.js +13 -6
- package/dist/describe/reference-lines.js.map +1 -1
- package/dist/describe/route-group-fact.d.ts +11 -0
- package/dist/describe/route-group-fact.d.ts.map +1 -0
- package/dist/describe/route-group-fact.js +2 -0
- package/dist/describe/route-group-fact.js.map +1 -0
- package/dist/generate/kind.d.ts +12 -0
- package/dist/generate/kind.d.ts.map +1 -1
- package/dist/generate/kinds/declare-context-entries.d.ts +1 -1
- package/dist/generate/kinds/declare-context-entries.js +4 -3
- package/dist/generate/kinds/declare-context-entries.js.map +1 -1
- package/dist/generate/kinds/e2e-kind.d.ts.map +1 -1
- package/dist/generate/kinds/e2e-kind.js +29 -6
- package/dist/generate/kinds/e2e-kind.js.map +1 -1
- package/dist/generate/kinds/extraction/service-selection.d.ts.map +1 -1
- package/dist/generate/kinds/extraction/service-selection.js +2 -1
- package/dist/generate/kinds/extraction/service-selection.js.map +1 -1
- package/dist/generate/kinds/guard-kind.d.ts +3 -0
- package/dist/generate/kinds/guard-kind.d.ts.map +1 -0
- package/dist/generate/kinds/guard-kind.js +27 -0
- package/dist/generate/kinds/guard-kind.js.map +1 -0
- package/dist/generate/kinds/route/controller-imports.d.ts +17 -0
- package/dist/generate/kinds/route/controller-imports.d.ts.map +1 -0
- package/dist/generate/kinds/route/controller-imports.js +22 -0
- package/dist/generate/kinds/route/controller-imports.js.map +1 -0
- package/dist/generate/kinds/route/controller-plan.d.ts +12 -0
- package/dist/generate/kinds/route/controller-plan.d.ts.map +1 -0
- package/dist/generate/kinds/route/controller-plan.js +2 -0
- package/dist/generate/kinds/route/controller-plan.js.map +1 -0
- package/dist/generate/kinds/route/controller-types.d.ts +18 -0
- package/dist/generate/kinds/route/controller-types.d.ts.map +1 -0
- package/dist/generate/kinds/route/controller-types.js +27 -0
- package/dist/generate/kinds/route/controller-types.js.map +1 -0
- package/dist/generate/kinds/route/controller-vars.d.ts +6 -0
- package/dist/generate/kinds/route/controller-vars.d.ts.map +1 -0
- package/dist/generate/kinds/route/controller-vars.js +117 -0
- package/dist/generate/kinds/route/controller-vars.js.map +1 -0
- package/dist/generate/kinds/route/group-file.d.ts +3 -0
- package/dist/generate/kinds/route/group-file.d.ts.map +1 -0
- package/dist/generate/kinds/route/group-file.js +5 -0
- package/dist/generate/kinds/route/group-file.js.map +1 -0
- package/dist/generate/kinds/route/group-prefix.d.ts +4 -0
- package/dist/generate/kinds/route/group-prefix.d.ts.map +1 -0
- package/dist/generate/kinds/route/group-prefix.js +17 -0
- package/dist/generate/kinds/route/group-prefix.js.map +1 -0
- package/dist/generate/kinds/route/group-vars.d.ts +17 -0
- package/dist/generate/kinds/route/group-vars.d.ts.map +1 -0
- package/dist/generate/kinds/route/group-vars.js +33 -0
- package/dist/generate/kinds/route/group-vars.js.map +1 -0
- package/dist/generate/kinds/route/plan-controller.d.ts +6 -0
- package/dist/generate/kinds/route/plan-controller.d.ts.map +1 -0
- package/dist/generate/kinds/route/plan-controller.js +16 -0
- package/dist/generate/kinds/route/plan-controller.js.map +1 -0
- package/dist/generate/kinds/route/resolve-group.d.ts +11 -0
- package/dist/generate/kinds/route/resolve-group.d.ts.map +1 -0
- package/dist/generate/kinds/route/resolve-group.js +31 -0
- package/dist/generate/kinds/route/resolve-group.js.map +1 -0
- package/dist/generate/kinds/route/resource-of.d.ts +5 -0
- package/dist/generate/kinds/route/resource-of.d.ts.map +1 -0
- package/dist/generate/kinds/route/resource-of.js +6 -0
- package/dist/generate/kinds/route/resource-of.js.map +1 -0
- package/dist/generate/kinds/route/route-group.d.ts +11 -0
- package/dist/generate/kinds/route/route-group.d.ts.map +1 -0
- package/dist/generate/kinds/route/route-group.js +2 -0
- package/dist/generate/kinds/route/route-group.js.map +1 -0
- package/dist/generate/kinds/route/write-controller.d.ts +5 -0
- package/dist/generate/kinds/route/write-controller.d.ts.map +1 -0
- package/dist/generate/kinds/route/write-controller.js +55 -0
- package/dist/generate/kinds/route/write-controller.js.map +1 -0
- package/dist/generate/kinds/route-group-kind.d.ts +3 -0
- package/dist/generate/kinds/route-group-kind.d.ts.map +1 -0
- package/dist/generate/kinds/route-group-kind.js +55 -0
- package/dist/generate/kinds/route-group-kind.js.map +1 -0
- package/dist/generate/kinds/route-kind.d.ts +2 -0
- package/dist/generate/kinds/route-kind.d.ts.map +1 -1
- package/dist/generate/kinds/route-kind.js +19 -4
- package/dist/generate/kinds/route-kind.js.map +1 -1
- package/dist/generate/kinds/write-context-files.d.ts.map +1 -1
- package/dist/generate/kinds/write-context-files.js +5 -4
- package/dist/generate/kinds/write-context-files.js.map +1 -1
- package/dist/generate/kinds.d.ts.map +1 -1
- package/dist/generate/kinds.js +6 -1
- package/dist/generate/kinds.js.map +1 -1
- package/dist/generate/lists-routes.d.ts +8 -0
- package/dist/generate/lists-routes.d.ts.map +1 -0
- package/dist/generate/lists-routes.js +10 -0
- package/dist/generate/lists-routes.js.map +1 -0
- package/dist/init/files/audit-files.d.ts.map +1 -1
- package/dist/init/files/audit-files.js +2 -7
- package/dist/init/files/audit-files.js.map +1 -1
- package/dist/init/manifest/versions.js +25 -25
- package/dist/init/manifest/versions.js.map +1 -1
- package/dist/init/stack/resolve-stack.d.ts.map +1 -1
- package/dist/init/stack/resolve-stack.js +3 -1
- package/dist/init/stack/resolve-stack.js.map +1 -1
- package/dist/init/stack/stack-options.d.ts +1 -0
- package/dist/init/stack/stack-options.d.ts.map +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +7 -0
- package/dist/run.js.map +1 -1
- package/dist/stack/audit-vars.d.ts.map +1 -1
- package/dist/stack/audit-vars.js +3 -1
- package/dist/stack/audit-vars.js.map +1 -1
- package/dist/stack/stack-vars.d.ts.map +1 -1
- package/dist/stack/stack-vars.js +16 -0
- package/dist/stack/stack-vars.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/templates/context/wiring.declared.tpl +2 -2
- package/templates/controller/controller.class-validator.ts.tpl +85 -0
- package/templates/controller/controller.none.ts.tpl +101 -0
- package/templates/controller/controller.search.ts.tpl +84 -0
- package/templates/controller/controller.spec.ts.tpl +49 -0
- package/templates/controller/controller.standard-schema.ts.tpl +113 -0
- package/templates/controller/controller.zod.ts.tpl +99 -0
- package/templates/controller/group.ts.tpl +4 -0
- package/templates/controller/guard.spec.ts.tpl +27 -0
- package/templates/controller/guard.ts.tpl +14 -0
- package/templates/controller/mapper.ts.tpl +10 -0
- package/templates/controller/routes.tsyringe.tpl +5 -0
- package/templates/controller/serializer.ts.tpl +10 -0
- package/templates/controller/wiring.manual.tpl +5 -0
- package/templates/init/platform/audit/audit.module.manual.ts.tpl +18 -0
- package/templates/init/platform/audit/search-audit-entries.controller.ts.tpl +193 -0
- package/templates/init/platform/compose-application.tsyringe.ts.tpl +38 -4
- package/templates/init/rules/presentation.md.tpl +14 -6
- package/templates/pipeline/github/dependabot.yml +5 -0
- package/templates/pipeline/package-scripts.json +1 -1
- package/templates/pipeline/renovate.json +5 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { entriesOf } from './entries-of.js';
|
|
2
|
+
const PARTS = ['params', 'query', 'headers', 'body'];
|
|
3
|
+
/** Reads the request and the one response of a route; a string says why it cannot be a controller. */
|
|
4
|
+
export function handleTypesOf(route) {
|
|
5
|
+
const request = entriesOf(route.spec.get('request') ?? '{}');
|
|
6
|
+
const responses = [...entriesOf(route.spec.get('responses') ?? '{}')];
|
|
7
|
+
const [[status, written] = []] = responses;
|
|
8
|
+
if (responses.length !== 1 || status === undefined || written === undefined) {
|
|
9
|
+
return 'it declares several responses, and a controller answers one: keep it a function';
|
|
10
|
+
}
|
|
11
|
+
const response = entriesOf(written);
|
|
12
|
+
const body = response.get('body');
|
|
13
|
+
const declared = PARTS.filter((part) => request.has(part)).map((part) => [part, request.get(part) ?? part]);
|
|
14
|
+
const typed = declared.map(([part, schema]) => `${part}: ${typeOf(route, schema)}`);
|
|
15
|
+
const result = body === undefined ? 'void' : typeOf(route, body);
|
|
16
|
+
return {
|
|
17
|
+
parts: declared.map(([part, schema]) => entryOf(part, schema)),
|
|
18
|
+
request: typed.length === 0 ? 'HttpRequest' : `HttpRequest<{ ${typed.join('; ')} }>`,
|
|
19
|
+
result,
|
|
20
|
+
response: responseEntry(status, response),
|
|
21
|
+
usesInfer: [...typed, result].some((type) => type.includes('Infer<')),
|
|
22
|
+
usesPageBody: result.startsWith('PageBody<'),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function responseEntry(status, response) {
|
|
26
|
+
const fields = [
|
|
27
|
+
`status: ${status}`,
|
|
28
|
+
...['description', 'body'].flatMap((key) => (response.has(key) ? [`${key}: ${response.get(key) ?? ''}`] : [])),
|
|
29
|
+
];
|
|
30
|
+
return `response: { ${fields.join(', ')} }`;
|
|
31
|
+
}
|
|
32
|
+
function entryOf(key, value) {
|
|
33
|
+
return key === value ? key : `${key}: ${value}`;
|
|
34
|
+
}
|
|
35
|
+
/** The class a schema is built from, when the route says it; the output of the schema otherwise. */
|
|
36
|
+
function typeOf(route, schema) {
|
|
37
|
+
const page = /^pageSchemaOf\((.+)\)$/.exec(schema)?.[1];
|
|
38
|
+
if (page !== undefined) {
|
|
39
|
+
return `PageBody<${typeOf(route, page)}>`;
|
|
40
|
+
}
|
|
41
|
+
const built = /^classSchema\((\w+)/.exec(schema) ??
|
|
42
|
+
new RegExp(String.raw `\bconst ${schema} = classSchema\((\w+)`).exec(route.prelude);
|
|
43
|
+
if (built?.[1] !== undefined) {
|
|
44
|
+
return built[1];
|
|
45
|
+
}
|
|
46
|
+
return /^\w+$/.test(schema) ? `Infer<typeof ${schema}>` : 'unknown';
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=handle-types-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|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AAS,OAAO,CAAC,GAAW,EAAE,KAAa;IACzC,OAAO,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,KAAK,EAAE,CAAC;AAClD,CAAC;AAED,oGAAoG;AACpG,SAAS,MAAM,CAAC,KAAoB,EAAE,MAAc;IAClD,MAAM,IAAI,GAAG,wBAAwB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAExD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,YAAY,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC;IAC5C,CAAC;IAED,MAAM,KAAK,GACT,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC;QAClC,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAA,WAAW,MAAM,uBAAuB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAErF,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,gBAAgB,MAAM,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Migration } from './migration.js';
|
|
2
|
+
/** Turns the function routes of one context into controllers, their files moved; nothing is written when one route blocks. */
|
|
3
|
+
export declare function migrateContext(migration: Migration, context: string): boolean;
|
|
4
|
+
//# sourceMappingURL=migrate-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-context.d.ts","sourceRoot":"","sources":["../../src/controllers/migrate-context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAOhD,8HAA8H;AAC9H,wBAAgB,cAAc,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAiB7E"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { specifierOf } from '../alias/index.js';
|
|
2
|
+
import { toName } from '../naming/index.js';
|
|
3
|
+
import { planContext } from './plan-context.js';
|
|
4
|
+
import { renderController } from './render-controller.js';
|
|
5
|
+
/** The roles a file may play in the folder of a controller: what `naming/suffix` accepts there. */
|
|
6
|
+
const ROLES = ['params', 'query', 'headers', 'body', 'accepted', 'answer', 'line'];
|
|
7
|
+
/** Turns the function routes of one context into controllers, their files moved; nothing is written when one route blocks. */
|
|
8
|
+
export function migrateContext(migration, context) {
|
|
9
|
+
const plan = planContext(migration, context);
|
|
10
|
+
if (plan === undefined) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
writeGroups(migration, plan);
|
|
14
|
+
for (const controller of plan.controllers) {
|
|
15
|
+
writeController(migration, plan, controller);
|
|
16
|
+
moveSpec(migration, plan, controller);
|
|
17
|
+
}
|
|
18
|
+
moveSchemas(migration, plan);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
function writeGroups({ draft }, { http, groups }) {
|
|
22
|
+
for (const group of groups.values()) {
|
|
23
|
+
const options = [
|
|
24
|
+
...(group.prefix === '' ? [] : [`prefix: '${group.prefix}'`]),
|
|
25
|
+
`tags: [${group.tags.map((tag) => `'${tag}'`).join(', ')}]`,
|
|
26
|
+
'guards: [Authenticated]',
|
|
27
|
+
...(group.errors.length === 0 ? [] : [`errors: [${group.errors.map((code) => `'${code}'`).join(', ')}]`]),
|
|
28
|
+
];
|
|
29
|
+
draft.write(`${http}/${group.kebab}.routes.ts`, `import { Authenticated, RouteGroup } from '@ddd-ts-kit/http';\n\n@RouteGroup({ ${options.join(', ')} })\nexport class ${group.className} {}\n`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function writeController(migration, plan, controller) {
|
|
33
|
+
const { draft, config, renamed, moved } = migration;
|
|
34
|
+
const { route, types, body, resource, isPublic } = controller;
|
|
35
|
+
const group = isPublic ? undefined : plan.groups.get(resource);
|
|
36
|
+
const target = `${plan.http}/${resource}/${route.kebab}/${route.kebab}.controller.ts`;
|
|
37
|
+
const groupImport = group === undefined
|
|
38
|
+
? ''
|
|
39
|
+
: `import { ${group.className} } from '${specifierOf(config, `${plan.http}/${group.kebab}.routes.ts`)}';`;
|
|
40
|
+
draft.write(target, renderController({ route, types, group, body, groupImport }));
|
|
41
|
+
draft.remove(route.file);
|
|
42
|
+
renamed.set(route.file, target);
|
|
43
|
+
moved.push(`${route.kebab}.route.ts -> ${resource}/${route.kebab}/${route.kebab}.controller.ts`);
|
|
44
|
+
}
|
|
45
|
+
/** A schema file named after a route follows it, under the role its name ends with; any other is shared, under the name it had. */
|
|
46
|
+
function moveSchemas({ ws, draft, renamed }, plan) {
|
|
47
|
+
const byLength = [...plan.controllers].sort((left, right) => right.route.kebab.length - left.route.kebab.length);
|
|
48
|
+
for (const name of ws.list(plan.http).filter((file) => file.endsWith('.dto.ts'))) {
|
|
49
|
+
const stem = name.replace(/\.dto\.ts$/, '');
|
|
50
|
+
const owner = byLength.find(({ route }) => ROLES.includes(stem.slice(route.kebab.length + 1)) && stem.startsWith(`${route.kebab}-`));
|
|
51
|
+
const target = owner === undefined
|
|
52
|
+
? `${plan.http}/shared/${name}`
|
|
53
|
+
: `${plan.http}/${owner.resource}/${owner.route.kebab}/${owner.route.kebab}.${stem.slice(owner.route.kebab.length + 1)}.ts`;
|
|
54
|
+
draft.write(target, ws.read(`${plan.http}/${name}`) ?? '');
|
|
55
|
+
draft.remove(`${plan.http}/${name}`);
|
|
56
|
+
renamed.set(`${plan.http}/${name}`, target);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** The spec of the route becomes the spec of the controller alone: its guards have their own. */
|
|
60
|
+
function moveSpec({ ws, draft, config }, plan, { route }) {
|
|
61
|
+
const unit = `${config.contextsDir}/${plan.context}/test/unit`;
|
|
62
|
+
const source = ws.read(`${unit}/${route.kebab}.route.spec.ts`);
|
|
63
|
+
const factory = `${toName(route.kebab).camel}Route`;
|
|
64
|
+
if (source === undefined) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const rewritten = source
|
|
68
|
+
.replaceAll(new RegExp(String.raw `\b${factory}\(([^()]*)\)`, 'g'), `controllerRoute(new ${route.pascal}Controller($1), { guards: 'skip' })`)
|
|
69
|
+
.replace(new RegExp(String.raw `import \{ ${factory} \}`), `import { ${route.pascal}Controller }`)
|
|
70
|
+
.replace(/import \{([^}]*)\} from '@ddd-ts-kit\/http';/, (_all, names) => `import { controllerRoute,${names}} from '@ddd-ts-kit/http';`);
|
|
71
|
+
draft.write(`${unit}/${route.kebab}.controller.spec.ts`, rewritten);
|
|
72
|
+
draft.remove(`${unit}/${route.kebab}.route.spec.ts`);
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=migrate-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-context.js","sourceRoot":"","sources":["../../src/controllers/migrate-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAA4C,MAAM,mBAAmB,CAAC;AAC1F,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,mGAAmG;AACnG,MAAM,KAAK,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAEnF,8HAA8H;AAC9H,MAAM,UAAU,cAAc,CAAC,SAAoB,EAAE,OAAe;IAClE,MAAM,IAAI,GAAG,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAE7C,IAAI,IAAI,K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AAS,CAAC,CAAC;IACpE,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,KAAK,gBAAgB,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The group the routes of one resource are moved to: one per first segment of their paths. */
|
|
2
|
+
export interface MigratedGroup {
|
|
3
|
+
/** `appointments`, and `AppointmentsRoutes`. */
|
|
4
|
+
readonly kebab: string;
|
|
5
|
+
readonly className: string;
|
|
6
|
+
readonly prefix: string;
|
|
7
|
+
readonly tags: readonly string[];
|
|
8
|
+
/** `FORBIDDEN` when every route of the group declares it: said once, on the group. */
|
|
9
|
+
readonly errors: readonly string[];
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=migrated-group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrated-group.d.ts","sourceRoot":"","sources":["../../src/controllers/migrated-group.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,sFAAsF;IACtF,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrated-group.js","sourceRoot":"","sources":["../../src/controllers/migrated-group.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Config } from '../config/index.js';
|
|
2
|
+
import type { MigrationDraft } from '../refusals/migration-draft.js';
|
|
3
|
+
import type { Workspace } from '../workspace/index.js';
|
|
4
|
+
/** What a migration to controllers works on, and what it found on the way. */
|
|
5
|
+
export interface Migration {
|
|
6
|
+
readonly ws: Workspace;
|
|
7
|
+
readonly config: Config;
|
|
8
|
+
readonly draft: MigrationDraft;
|
|
9
|
+
/** Files that moved, old path to new path: their imports are rewritten everywhere at the end. */
|
|
10
|
+
readonly renamed: Map<string, string>;
|
|
11
|
+
/** `<Name>Route -> <Name>Controller`, for the report. */
|
|
12
|
+
readonly moved: string[];
|
|
13
|
+
/** Why a context was left as it is, one sentence per route that cannot be turned. */
|
|
14
|
+
readonly blockers: string[];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=migration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../src/controllers/migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,8EAA8E;AAC9E,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,iGAAiG;IACjG,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,yDAAyD;IACzD,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;IACzB,qFAAqF;IACrF,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.js","sourceRoot":"","sources":["../../src/controllers/migration.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type HandleTypes } from './handle-types-of.js';
|
|
2
|
+
import type { FunctionRoute } from './function-route.js';
|
|
3
|
+
import type { MigratedGroup } from './migrated-group.js';
|
|
4
|
+
import type { Migration } from './migration.js';
|
|
5
|
+
export interface PlannedController {
|
|
6
|
+
readonly route: FunctionRoute;
|
|
7
|
+
readonly types: HandleTypes;
|
|
8
|
+
readonly body: string;
|
|
9
|
+
/** The folder of its resource: the first literal segment of its path, or the context. */
|
|
10
|
+
readonly resource: string;
|
|
11
|
+
readonly isPublic: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface ContextPlan {
|
|
14
|
+
readonly context: string;
|
|
15
|
+
/** `<contextsDir>/<context>/presentation/http`. */
|
|
16
|
+
readonly http: string;
|
|
17
|
+
readonly controllers: readonly PlannedController[];
|
|
18
|
+
readonly groups: ReadonlyMap<string, MigratedGroup>;
|
|
19
|
+
}
|
|
20
|
+
/** Reads every function route of a context; one that cannot be turned blocks the whole context, said in `blockers`. */
|
|
21
|
+
export declare function planContext(migration: Migration, context: string): ContextPlan | undefined;
|
|
22
|
+
//# sourceMappingURL=plan-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-context.d.ts","sourceRoot":"","sources":["../../src/controllers/plan-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,yFAAyF;IACzF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACnD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CACrD;AAED,uHAAuH;AACvH,wBAAgB,WAAW,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAgB1F"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { toName } from '../naming/index.js';
|
|
2
|
+
import { handleTypesOf } from './handle-types-of.js';
|
|
3
|
+
import { handleBody } from './handle-body.js';
|
|
4
|
+
import { readFunctionRoute } from './read-function-route.js';
|
|
5
|
+
/** Reads every function route of a context; one that cannot be turned blocks the whole context, said in `blockers`. */
|
|
6
|
+
export function planContext(migration, context) {
|
|
7
|
+
const { ws, config, blockers } = migration;
|
|
8
|
+
const http = `${config.contextsDir}/${context}/presentation/http`;
|
|
9
|
+
const files = ws.list(http).filter((name) => name.endsWith('.route.ts'));
|
|
10
|
+
const planned = files.map((name) => plannedOf(`${http}/${name}`, ws.read(`${http}/${name}`) ?? '', context));
|
|
11
|
+
const refused = planned.filter((entry) => typeof entry === 'string');
|
|
12
|
+
if (files.length === 0 || refused.length > 0) {
|
|
13
|
+
blockers.push(...refused);
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const controllers = planned.filter((entry) => typeof entry !== 'string');
|
|
17
|
+
return { context, http, controllers, groups: groupsOf(controllers, context) };
|
|
18
|
+
}
|
|
19
|
+
function plannedOf(file, source, context) {
|
|
20
|
+
const route = readFunctionRoute(file, source);
|
|
21
|
+
if (typeof route === 'string') {
|
|
22
|
+
return `${file}: ${route}.`;
|
|
23
|
+
}
|
|
24
|
+
const types = handleTypesOf(route);
|
|
25
|
+
const body = handleBody(route);
|
|
26
|
+
if (typeof types === 'string') {
|
|
27
|
+
return `${file}: ${types}.`;
|
|
28
|
+
}
|
|
29
|
+
if (body === undefined) {
|
|
30
|
+
return `${file}: its handler answers something else than \`{ status, body }\` (headers, a status chosen at run time): keep it a function.`;
|
|
31
|
+
}
|
|
32
|
+
return { route, types, body, resource: resourceOf(route, context), isPublic: route.spec.get('security') === 'false' };
|
|
33
|
+
}
|
|
34
|
+
/** The first literal segment of the path names the resource; a path that starts with a parameter belongs to the context. */
|
|
35
|
+
function resourceOf(route, context) {
|
|
36
|
+
const [first = ''] = unquoted(route.spec.get('path') ?? '')
|
|
37
|
+
.split('/')
|
|
38
|
+
.filter((segment) => segment !== '');
|
|
39
|
+
return first === '' || first.startsWith(':') ? context : first.replaceAll(/[._~]/g, '-');
|
|
40
|
+
}
|
|
41
|
+
function groupsOf(controllers, context) {
|
|
42
|
+
const groups = new Map();
|
|
43
|
+
for (const { resource, route } of controllers.filter((controller) => !controller.isPublic)) {
|
|
44
|
+
const members = controllers.filter((other) => other.resource === resource && !other.isPublic);
|
|
45
|
+
groups.set(resource, {
|
|
46
|
+
kebab: resource,
|
|
47
|
+
className: `${toName(resource).pascal}Routes`,
|
|
48
|
+
prefix: resource === context && !pathStartsWith(route, resource) ? '' : `/${resource}`,
|
|
49
|
+
tags: groups.get(resource)?.tags ?? listed(route.spec.get('tags')).map(unquoted),
|
|
50
|
+
errors: members.every((member) => (member.route.spec.get('errors') ?? '').includes("'FORBIDDEN'"))
|
|
51
|
+
? ['FORBIDDEN']
|
|
52
|
+
: [],
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return groups;
|
|
56
|
+
}
|
|
57
|
+
function pathStartsWith(route, segment) {
|
|
58
|
+
return unquoted(route.spec.get('path') ?? '').startsWith(`/${segment}`);
|
|
59
|
+
}
|
|
60
|
+
function listed(list) {
|
|
61
|
+
return (list ?? '[]')
|
|
62
|
+
.replace(/^\[|\]$/g, '')
|
|
63
|
+
.split(',')
|
|
64
|
+
.map((entry) => entry.trim())
|
|
65
|
+
.filter((entry) => entry !== '');
|
|
66
|
+
}
|
|
67
|
+
function unquoted(text) {
|
|
68
|
+
return text.replace(/^['"]|['"]$/g, '');
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=plan-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-context.js","sourceRoot":"","sources":["../../src/controllers/plan-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAoB,MAAM,sBAAsB,CAAC;AAEvE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAmB7D,uHAAuH;AACvH,MAAM,UAAU,WAAW,CAAC,SAAoB,EAAE,OAAe;IAC/D,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;IAC3C,MAAM,IAAI,GAAG,GAAG,MAAM,CAAC,WAAW,IAAI,OAAO,oBAAoB,CAAC;IAClE,MAAM,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC;IACzE,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7G,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,C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AG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC;YAChF,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;gBAChG,CAAC,CAAC,CAAC,WAAW,CAAC;gBACf,CAAC,CAAC,EAAE;SACP,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,cAAc,CAAC,KAAoB,EAAE,OAAe;IAC3D,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC;AAC1E,CAAC;AAED,SAAS,MAAM,CAAC,IAAwB;IACtC,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC;SAClB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;SAC5B,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FunctionRoute } from './function-route.js';
|
|
2
|
+
/** Reads a route file, or says in one sentence what keeps it from being turned into a controller. */
|
|
3
|
+
export declare function readFunctionRoute(file: string, source: string): FunctionRoute | string;
|
|
4
|
+
//# sourceMappingURL=read-function-route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-function-route.d.ts","sourceRoot":"","sources":["../../src/controllers/read-function-route.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAMzD,qGAAqG;AACrG,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,MAAM,CAgCtF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { matchingBracket } from '../check/text/matching-bracket.js';
|
|
2
|
+
import { splitTopLevel } from '../check/text/split-top-level.js';
|
|
3
|
+
import { toName } from '../naming/index.js';
|
|
4
|
+
import { entriesOf } from './entries-of.js';
|
|
5
|
+
const FACTORY = /export function (\w+)Route\((\w+): (\w+)\): Route \{\s*return defineRoute\(/;
|
|
6
|
+
const IMPORT = /^import[\s\S]*?from '[^']+';\n/gm;
|
|
7
|
+
const HANDLER = /^async \((\w+)\) => \{([\s\S]*)\}$/;
|
|
8
|
+
/** Reads a route file, or says in one sentence what keeps it from being turned into a controller. */
|
|
9
|
+
export function readFunctionRoute(file, source) {
|
|
10
|
+
const factory = FACTORY.exec(source);
|
|
11
|
+
if (factory === null) {
|
|
12
|
+
return 'it is not written as `export function <name>Route(<bus>): Route { return defineRoute(..); }`';
|
|
13
|
+
}
|
|
14
|
+
const open = factory.index + factory[0].length - 1;
|
|
15
|
+
const close = matchingBracket(source, open);
|
|
16
|
+
const [spec, handler] = splitTopLevel(source.slice(open + 1, close)).map((part) => part.code);
|
|
17
|
+
const written = HANDLER.exec((handler ?? '').replace(/,\s*$/, '').trim());
|
|
18
|
+
if (spec === undefined || written === null) {
|
|
19
|
+
return 'its handler is not written as `async (input) => { .. }`';
|
|
20
|
+
}
|
|
21
|
+
const head = source.slice(0, factory.index);
|
|
22
|
+
const kebab = file.slice(file.lastIndexOf('/') + 1).replace(/\.route\.ts$/, '');
|
|
23
|
+
return {
|
|
24
|
+
file,
|
|
25
|
+
kebab,
|
|
26
|
+
pascal: toName(kebab).pascal,
|
|
27
|
+
bus: factory[2] ?? '',
|
|
28
|
+
busType: factory[3] ?? '',
|
|
29
|
+
imports: head.match(IMPORT) ?? [],
|
|
30
|
+
prelude: head.replace(IMPORT, '').trim(),
|
|
31
|
+
spec: entriesOf(spec),
|
|
32
|
+
input: written[1] ?? 'input',
|
|
33
|
+
body: written[2] ?? '',
|
|
34
|
+
trailer: source.slice(source.indexOf('\n}\n', close) + 3).trim(),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=read-function-route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-function-route.js","sourceRoot":"","sources":["../../src/controllers/read-function-route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,MAAM,OAAO,GAAG,6EAA6E,CAAC;AAC9F,MAAM,MAAM,GAAG,kCAAkC,CAAC;AAClD,MAAM,OAAO,GAAG,oCAAoC,CAAC;AAErD,qGAAqG;AACrG,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,MAAc;IAC5D,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAErC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,OAAO,8FAA8F,CAAC;IACxG,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC5C,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,aAAa,CA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CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE;KACjE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HandleTypes } from './handle-types-of.js';
|
|
2
|
+
import type { FunctionRoute } from './function-route.js';
|
|
3
|
+
import type { MigratedGroup } from './migrated-group.js';
|
|
4
|
+
export interface ControllerParts {
|
|
5
|
+
readonly route: FunctionRoute;
|
|
6
|
+
readonly types: HandleTypes;
|
|
7
|
+
/** Undefined for a route that named no security scheme: its controller is public and stands in no group. */
|
|
8
|
+
readonly group: MigratedGroup | undefined;
|
|
9
|
+
readonly body: string;
|
|
10
|
+
/** The import of the group, already written for the project. */
|
|
11
|
+
readonly groupImport: string;
|
|
12
|
+
}
|
|
13
|
+
/** The text of the controller file: the imports of the route, its schemas, the class, the helpers it kept. */
|
|
14
|
+
export declare function renderController(parts: ControllerParts): string;
|
|
15
|
+
//# sourceMappingURL=render-controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-controller.d.ts","sourceRoot":"","sources":["../../src/controllers/render-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,4GAA4G;IAC5G,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,gEAAgE;IAChE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAID,8GAA8G;AAC9G,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAoB/D"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const GUARD_ERRORS = ["'UNAUTHORIZED'"];
|
|
2
|
+
/** The text of the controller file: the imports of the route, its schemas, the class, the helpers it kept. */
|
|
3
|
+
export function renderController(parts) {
|
|
4
|
+
const { route, types, body } = parts;
|
|
5
|
+
const reads = /\brequest\b/.test(body);
|
|
6
|
+
const signature = `async handle(${reads ? `request: ${types.request}` : ''}): Promise<${types.result}>`;
|
|
7
|
+
const sections = [
|
|
8
|
+
importsOf(parts, reads).join(''),
|
|
9
|
+
route.prelude,
|
|
10
|
+
`@Controller({\n${declarationOf(parts)
|
|
11
|
+
.map((entry) => ` ${entry},\n`)
|
|
12
|
+
.join('')}})\nexport class ${route.pascal}Controller {\n constructor(private readonly ${route.bus}: ${route.busType}) {}\n\n ${signature} {\n${body}\n }\n}`,
|
|
13
|
+
route.trailer,
|
|
14
|
+
];
|
|
15
|
+
return `${sections
|
|
16
|
+
.filter((section) => section.trim() !== '')
|
|
17
|
+
.map((section) => section.trimEnd())
|
|
18
|
+
.join('\n\n')}\n`;
|
|
19
|
+
}
|
|
20
|
+
function declarationOf(parts) {
|
|
21
|
+
const { route, types, group } = parts;
|
|
22
|
+
const { spec } = route;
|
|
23
|
+
const path = unquoted(spec.get('path') ?? "'/'");
|
|
24
|
+
const rest = group === undefined ? path : path.slice(group.prefix.length);
|
|
25
|
+
const derived = `'${route.pascal.charAt(0).toLowerCase()}${route.pascal.slice(1)}'`;
|
|
26
|
+
const kept = (key) => (spec.has(key) ? [`${key}: ${spec.get(key) ?? ''}`] : []);
|
|
27
|
+
return [
|
|
28
|
+
...(group === undefined ? [...kept('tags'), 'guards: [Public]'] : [`group: ${group.className}`]),
|
|
29
|
+
`method: ${spec.get('method') ?? "'GET'"}`,
|
|
30
|
+
`path: '${rest === '' ? '/' : rest}'`,
|
|
31
|
+
...(spec.get('operationId') === derived ? [] : kept('operationId')),
|
|
32
|
+
...kept('summary'),
|
|
33
|
+
...kept('description'),
|
|
34
|
+
...(group === undefined || sameList(spec.get('tags'), group.tags) ? [] : kept('tags')),
|
|
35
|
+
...types.parts,
|
|
36
|
+
types.response,
|
|
37
|
+
`errors: [${errorsOf(parts).join(', ')}]`,
|
|
38
|
+
...kept('deprecated'),
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
/** What the guard and the group already say is not repeated on the controller. */
|
|
42
|
+
function errorsOf({ route, group }) {
|
|
43
|
+
const said = group === undefined ? [] : [...GUARD_ERRORS, ...group.errors.map((code) => `'${code}'`)];
|
|
44
|
+
return listed(route.spec.get('errors')).filter((code) => !said.includes(code));
|
|
45
|
+
}
|
|
46
|
+
function importsOf({ route, types, group, groupImport }, reads) {
|
|
47
|
+
const http = [
|
|
48
|
+
'Controller',
|
|
49
|
+
...(group === undefined ? ['Public'] : []),
|
|
50
|
+
...(reads ? ['type HttpRequest'] : []),
|
|
51
|
+
...(types.usesPageBody ? ['type PageBody'] : []),
|
|
52
|
+
];
|
|
53
|
+
const kept = route.imports
|
|
54
|
+
.filter((statement) => !fromAuth(statement) || namesOf(statement).some((name) => name !== 'actorOf'))
|
|
55
|
+
.map((statement) => (statement.includes("from '@ddd-ts-kit/http'") ? withNames(statement, http) : statement))
|
|
56
|
+
.map((statement) => (fromAuth(statement) ? without(statement, 'actorOf') : statement));
|
|
57
|
+
const infer = types.usesInfer && !kept.some((statement) => /\bInfer\b/.test(statement));
|
|
58
|
+
return [
|
|
59
|
+
...kept,
|
|
60
|
+
...(infer ? ["import type { Infer } from '@ddd-ts-kit/validation';\n"] : []),
|
|
61
|
+
...(group === undefined ? [] : [`${groupImport}\n`]),
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
function fromAuth(statement) {
|
|
65
|
+
return statement.includes("from '@ddd-ts-kit/auth'");
|
|
66
|
+
}
|
|
67
|
+
/** The import of `@ddd-ts-kit/http` without what a function route needed, with what a controller needs. */
|
|
68
|
+
function withNames(statement, added) {
|
|
69
|
+
const names = namesOf(statement).filter((name) => name !== 'defineRoute' && name !== 'type Route');
|
|
70
|
+
const all = [
|
|
71
|
+
...new Set([
|
|
72
|
+
...added.filter((name) => !name.startsWith('type ')),
|
|
73
|
+
...names,
|
|
74
|
+
...added.filter((name) => name.startsWith('type ')),
|
|
75
|
+
]),
|
|
76
|
+
];
|
|
77
|
+
return `import { ${all.join(', ')} } from '@ddd-ts-kit/http';\n`;
|
|
78
|
+
}
|
|
79
|
+
function without(statement, name) {
|
|
80
|
+
const specifier = /from '([^']+)'/.exec(statement)?.[1] ?? '';
|
|
81
|
+
return `import { ${namesOf(statement)
|
|
82
|
+
.filter((kept) => kept !== name)
|
|
83
|
+
.join(', ')} } from '${specifier}';\n`;
|
|
84
|
+
}
|
|
85
|
+
function namesOf(statement) {
|
|
86
|
+
return (/\{([\s\S]*)\}/.exec(statement)?.[1] ?? '')
|
|
87
|
+
.split(',')
|
|
88
|
+
.map((name) => name.trim())
|
|
89
|
+
.filter((name) => name !== '');
|
|
90
|
+
}
|
|
91
|
+
function listed(list) {
|
|
92
|
+
return (list ?? '[]')
|
|
93
|
+
.replace(/^\[|\]$/g, '')
|
|
94
|
+
.split(',')
|
|
95
|
+
.map((entry) => entry.trim())
|
|
96
|
+
.filter((entry) => entry !== '');
|
|
97
|
+
}
|
|
98
|
+
function sameList(written, tags) {
|
|
99
|
+
return listed(written).map(unquoted).join(',') === tags.join(',');
|
|
100
|
+
}
|
|
101
|
+
function unquoted(text) {
|
|
102
|
+
return text.replace(/^['"]|['"]$/g, '');
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=render-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-controller.js","sourceRoot":"","sources":["../../src/controllers/render-controller.ts"],"names":[],"mappings":"AAcA,MAAM,YAAY,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAExC,8GAA8G;AAC9G,MAAM,UAAU,gBAAgB,CAAC,KAAsB;IACrD,MAAM,EAAE,KA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5B,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,QAAQ,CAAC,OAA2B,EAAE,IAAuB;IACpE,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACpE,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -11,10 +11,16 @@ export interface DeclaredRole {
|
|
|
11
11
|
readonly folders: readonly string[];
|
|
12
12
|
/** The decorators one of which the exported class carries. */
|
|
13
13
|
readonly decorators: readonly string[];
|
|
14
|
+
/** The package entry the decorators are imported from, when it is not the declarations entry of the kernel. */
|
|
15
|
+
readonly entry?: string;
|
|
14
16
|
}
|
|
15
17
|
export declare const DECLARED_ROLES: readonly DeclaredRole[];
|
|
16
|
-
/** Every decorator of `@ddd-ts-kit/kernel/declarations
|
|
18
|
+
/** Every declaration decorator: those of `@ddd-ts-kit/kernel/declarations` and those of the edge. */
|
|
17
19
|
export declare const DECLARATION_DECORATORS: readonly string[];
|
|
18
|
-
/** The
|
|
20
|
+
/** The entry each decorator is imported from, for the ones that do not come from the kernel. */
|
|
21
|
+
export declare const DECORATOR_ENTRIES: Readonly<Record<string, string>>;
|
|
22
|
+
/** The suffixes `discoverContext` loads under `application/` and `infrastructure/`: every role but those of the edge. */
|
|
19
23
|
export declare const DISCOVERED_SUFFIXES: readonly string[];
|
|
24
|
+
/** The suffixes `discoverContext` loads under `presentation/`: the roles of the edge. */
|
|
25
|
+
export declare const EDGE_SUFFIXES: readonly string[];
|
|
20
26
|
//# sourceMappingURL=declared-role.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declared-role.d.ts","sourceRoot":"","sources":["../../src/declared/declared-role.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,kFAAkF;IAClF,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,8DAA8D;IAC9D,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"declared-role.d.ts","sourceRoot":"","sources":["../../src/declared/declared-role.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,kFAAkF;IAClF,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,8DAA8D;IAC9D,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,+GAA+G;IAC/G,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAKD,eAAO,MAAM,cAAc,EAAE,SAAS,YAAY,EAsBjD,CAAC;AAEF,qGAAqG;AACrG,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAEnD,CAAC;AAEF,gGAAgG;AAChG,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAI9D,CAAC;AAEF,yHAAyH;AACzH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAEhD,CAAC;AAEF,yFAAyF;AACzF,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAE1C,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** Where the decorators of the edge come from: the transport declares its own classes on the kernel. */
|
|
2
|
+
const HTTP = '@ddd-ts-kit/http';
|
|
1
3
|
export const DECLARED_ROLES = [
|
|
2
4
|
{ suffix: 'command', folders: ['application/commands'], decorators: ['Requires', 'Public'] },
|
|
3
5
|
{ suffix: 'query', folders: ['application/queries'], decorators: ['Requires', 'Public'] },
|
|
@@ -16,11 +18,23 @@ export const DECLARED_ROLES = [
|
|
|
16
18
|
{ suffix: 'repository', folders: ['infrastructure/persistence'], decorators: ['Repository'] },
|
|
17
19
|
{ suffix: 'gateway', folders: ['infrastructure'], decorators: ['Gateway'] },
|
|
18
20
|
{ suffix: 'adapter', folders: ['infrastructure'], decorators: ['Adapter'] },
|
|
21
|
+
{ suffix: 'controller', folders: ['presentation/http'], decorators: ['Controller'], entry: HTTP },
|
|
22
|
+
{ suffix: 'guard', folders: ['presentation/http'], decorators: ['Guard'], entry: HTTP },
|
|
23
|
+
{ suffix: 'mapper', folders: ['presentation/http'], decorators: ['RequestMapper'], entry: HTTP },
|
|
24
|
+
{ suffix: 'serializer', folders: ['presentation/http'], decorators: ['Serializer'], entry: HTTP },
|
|
19
25
|
];
|
|
20
|
-
/** Every decorator of `@ddd-ts-kit/kernel/declarations
|
|
26
|
+
/** Every declaration decorator: those of `@ddd-ts-kit/kernel/declarations` and those of the edge. */
|
|
21
27
|
export const DECLARATION_DECORATORS = [
|
|
22
28
|
...new Set(DECLARED_ROLES.flatMap((role) => role.decorators)),
|
|
23
29
|
];
|
|
24
|
-
/** The
|
|
25
|
-
export const
|
|
30
|
+
/** The entry each decorator is imported from, for the ones that do not come from the kernel. */
|
|
31
|
+
export const DECORATOR_ENTRIES = Object.fromEntries(DECLARED_ROLES.flatMap(({ entry, decorators }) => entry === undefined ? [] : decorators.map((name) => [name, entry])));
|
|
32
|
+
/** The suffixes `discoverContext` loads under `application/` and `infrastructure/`: every role but those of the edge. */
|
|
33
|
+
export const DISCOVERED_SUFFIXES = [
|
|
34
|
+
...new Set(DECLARED_ROLES.filter((role) => role.entry === undefined).map((role) => role.suffix)),
|
|
35
|
+
];
|
|
36
|
+
/** The suffixes `discoverContext` loads under `presentation/`: the roles of the edge. */
|
|
37
|
+
export const EDGE_SUFFIXES = [
|
|
38
|
+
...new Set(DECLARED_ROLES.filter((role) => role.entry !== undefined).map((role) => role.suffix)),
|
|
39
|
+
];
|
|
26
40
|
//# sourceMappingURL=declared-role.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declared-role.js","sourceRoot":"","sources":["../../src/declared/declared-role.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"declared-role.js","sourceRoot":"","sources":["../../src/declared/declared-role.ts"],"names":[],"mappings":"AAiBA,wGAAwG;AACxG,MAAM,IAAI,GAAG,kBAAkB,CAAC;AAEhC,MAAM,CAAC,MAAM,cAAc,GAA4B;IACrD,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,sBAAsB,CAAC,EAAE,UAAU,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE;IAC5F,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,qBAAqB,CAAC,EAAE,UAAU,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE;IACzF,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,sBAAsB,CAAC,EAAE,UAAU,EAAE,CAAC,gBAAgB,CAAC,EAAE;IACxF,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,qBAAqB,CAAC,EAAE,UAAU,EAAE,CAAC,cAAc,CAAC,EAAE;IACrF;QACE,MAAM,EAAE,qBAAqB;QAC7B,OAAO,EAAE,CAAC,kCAAkC,CAAC;QAC7C,UAAU,EAAE,CAAC,yBAAyB,CAAC;KACxC;IACD,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC,4BAA4B,CAAC,EAAE,UAAU,EAAE,CAAC,oBAAoB,CAAC,EAAE;IACxG,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,oCAAoC,CAAC,EAAE,UAAU,EAAE,CAAC,oBAAoB,CAAC,EAAE;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GAAqG;AACrG,MAAM,CAAC,MAAM,sBAAsB,GAAsB;IACvD,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;CAC9D,CAAC;AAEF,gGAAgG;AAChG,MAAM,CAAC,MAAM,iBAAiB,GAAqC,MAAM,CAAC,WAAW,CACnF,cAAc,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,CAC/C,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAoB,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CACrF,CACF,CAAC;AAEF,yHAAyH;AACzH,MAAM,CAAC,MAAM,mBAAmB,GAAsB;IACpD,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;CACjG,CAAC;AAEF,yFAAyF;AACzF,MAAM,CAAC,MAAM,aAAa,GAAsB;IAC9C,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;CACjG,CAAC"}
|
package/dist/declared/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { barrelFile } from './barrel-file.js';
|
|
2
|
-
export { DECLARED_ROLES, DISCOVERED_SUFFIXES, type DeclaredRole } from './declared-role.js';
|
|
2
|
+
export { DECLARED_ROLES, DISCOVERED_SUFFIXES, EDGE_SUFFIXES, type DeclaredRole } from './declared-role.js';
|
|
3
3
|
export { declaredRoleOf } from './declared-role-of.js';
|
|
4
4
|
export { dependenciesFile } from './dependencies-file.js';
|
|
5
5
|
export { generatedDrift } from './generated-drift.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/declared/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/declared/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC3G,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,YAAY,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/declared/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { barrelFile } from './barrel-file.js';
|
|
2
|
-
export { DECLARED_ROLES, DISCOVERED_SUFFIXES } from './declared-role.js';
|
|
2
|
+
export { DECLARED_ROLES, DISCOVERED_SUFFIXES, EDGE_SUFFIXES } from './declared-role.js';
|
|
3
3
|
export { declaredRoleOf } from './declared-role-of.js';
|
|
4
4
|
export { dependenciesFile } from './dependencies-file.js';
|
|
5
5
|
export { generatedDrift } from './generated-drift.js';
|