@xemahq/api-client-generator 0.18.1 → 0.18.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/dist/.source-stamp.json +2 -2
- package/dist/lib/plugin-metadata.d.ts.map +1 -1
- package/dist/lib/plugin-metadata.js +46 -3
- package/dist/lib/plugin-metadata.js.map +1 -1
- package/dist/lib/swagger-plugin-patches.d.ts +14 -0
- package/dist/lib/swagger-plugin-patches.d.ts.map +1 -0
- package/dist/lib/swagger-plugin-patches.js +101 -0
- package/dist/lib/swagger-plugin-patches.js.map +1 -0
- package/package.json +3 -3
package/dist/.source-stamp.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-metadata.d.ts","sourceRoot":"","sources":["../../src/lib/plugin-metadata.ts"],"names":[],"mappings":"AAkFA,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,MAAM,GACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CA+BrC;
|
|
1
|
+
{"version":3,"file":"plugin-metadata.d.ts","sourceRoot":"","sources":["../../src/lib/plugin-metadata.ts"],"names":[],"mappings":"AAkFA,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,MAAM,GACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CA+BrC;AAwGD,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE;IACb,kBAAkB,EAAE,CAClB,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KACvC,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,GACA,OAAO,CAAC,OAAO,CAAC,CA0HlB"}
|
|
@@ -36,8 +36,9 @@ function readSwaggerPluginOptions(serviceDir) {
|
|
|
36
36
|
return undefined;
|
|
37
37
|
}
|
|
38
38
|
const CHILD_SOURCE = `
|
|
39
|
-
const { join } = require('node:path');
|
|
40
|
-
const [serviceDir, filename, optionsJson] =
|
|
39
|
+
const { dirname, join } = require('node:path');
|
|
40
|
+
const [serviceDir, filename, optionsJson, patchModulePath, reportPath] =
|
|
41
|
+
process.argv.slice(2);
|
|
41
42
|
const { PluginMetadataGenerator } = require(
|
|
42
43
|
require.resolve('@nestjs/cli/lib/compiler/plugins/plugin-metadata-generator', {
|
|
43
44
|
paths: [serviceDir],
|
|
@@ -46,6 +47,20 @@ const { PluginMetadataGenerator } = require(
|
|
|
46
47
|
const { ReadonlyVisitor } = require(
|
|
47
48
|
require.resolve('@nestjs/swagger/dist/plugin', { paths: [serviceDir] }),
|
|
48
49
|
);
|
|
50
|
+
|
|
51
|
+
// The visitor emits two references it cannot evaluate — see
|
|
52
|
+
// \`swagger-plugin-patches.ts\`. Corrected BEFORE the visitor runs, so the
|
|
53
|
+
// \`t\` table's key and the lookup against it derive from one repaired string.
|
|
54
|
+
// Both the swagger copy and the compiler must be the SERVICE's own, for the
|
|
55
|
+
// same reason the generator reads \`nest-cli.json\` instead of hardcoding it.
|
|
56
|
+
const { installSwaggerPluginPatches, collectUnreferenceableHostTypes } = require(
|
|
57
|
+
patchModulePath,
|
|
58
|
+
);
|
|
59
|
+
const patchState = installSwaggerPluginPatches(
|
|
60
|
+
dirname(require.resolve('@nestjs/swagger/package.json', { paths: [serviceDir] })),
|
|
61
|
+
require(require.resolve('typescript', { paths: [serviceDir] })),
|
|
62
|
+
);
|
|
63
|
+
|
|
49
64
|
const srcDir = join(serviceDir, 'src');
|
|
50
65
|
// \`tsconfigPath\` is documented as relative to process.cwd().
|
|
51
66
|
process.chdir(serviceDir);
|
|
@@ -62,7 +77,26 @@ new PluginMetadataGenerator().generate({
|
|
|
62
77
|
: 'tsconfig.json',
|
|
63
78
|
printDiagnostics: false,
|
|
64
79
|
});
|
|
80
|
+
|
|
81
|
+
require('node:fs').writeFileSync(
|
|
82
|
+
reportPath,
|
|
83
|
+
JSON.stringify(collectUnreferenceableHostTypes(patchState)),
|
|
84
|
+
);
|
|
65
85
|
`;
|
|
86
|
+
function reportUnreferenceableHostTypes(serviceDir, reportPath) {
|
|
87
|
+
if (!(0, node_fs_1.existsSync)(reportPath)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const entries = JSON.parse((0, node_fs_1.readFileSync)(reportPath, 'utf8'));
|
|
91
|
+
if (entries.length === 0) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const lines = entries.map((entry) => ` ${entry.typeName} (${(0, node_path_1.relative)(serviceDir, entry.hostFilename)})`);
|
|
95
|
+
process.stderr.write(`[xema-openapi] ${entries.length} type(s) declared in a controller file ` +
|
|
96
|
+
'are NOT exported, so the swagger plugin cannot reference them from the ' +
|
|
97
|
+
'metadata module and infers nothing from them. Export them to close ' +
|
|
98
|
+
`it:\n${lines.join('\n')}\n`);
|
|
99
|
+
}
|
|
66
100
|
async function applyPluginMetadata(serviceDir, swaggerModule) {
|
|
67
101
|
const options = readSwaggerPluginOptions(serviceDir);
|
|
68
102
|
if (options === undefined) {
|
|
@@ -72,6 +106,7 @@ async function applyPluginMetadata(serviceDir, swaggerModule) {
|
|
|
72
106
|
const cjsPath = (0, node_path_1.join)(serviceDir, 'src', `${METADATA_BASENAME}.cjs`);
|
|
73
107
|
const childDir = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'xema-openapi-'));
|
|
74
108
|
const childPath = (0, node_path_1.join)(childDir, 'generate.cjs');
|
|
109
|
+
const reportPath = (0, node_path_1.join)(childDir, 'unreferenceable-host-types.json');
|
|
75
110
|
const cleanUp = () => {
|
|
76
111
|
(0, node_fs_1.rmSync)(tsPath, { force: true });
|
|
77
112
|
(0, node_fs_1.rmSync)(cjsPath, { force: true });
|
|
@@ -94,7 +129,14 @@ async function applyPluginMetadata(serviceDir, swaggerModule) {
|
|
|
94
129
|
(0, node_fs_1.rmSync)(tsPath, { force: true });
|
|
95
130
|
(0, node_fs_1.rmSync)(cjsPath, { force: true });
|
|
96
131
|
(0, node_fs_1.writeFileSync)(childPath, CHILD_SOURCE);
|
|
97
|
-
const child = (0, node_child_process_1.spawnSync)(process.execPath, [
|
|
132
|
+
const child = (0, node_child_process_1.spawnSync)(process.execPath, [
|
|
133
|
+
childPath,
|
|
134
|
+
serviceDir,
|
|
135
|
+
`${METADATA_BASENAME}.ts`,
|
|
136
|
+
JSON.stringify(options),
|
|
137
|
+
require.resolve('./swagger-plugin-patches'),
|
|
138
|
+
reportPath,
|
|
139
|
+
], { encoding: 'utf8' });
|
|
98
140
|
if (child.status !== 0 || !(0, node_fs_1.existsSync)(tsPath)) {
|
|
99
141
|
throw new Error('api-client-generator: the swagger plugin metadata generator failed ' +
|
|
100
142
|
`(exit ${String(child.status)}). This service DECLARES the plugin, so ` +
|
|
@@ -102,6 +144,7 @@ async function applyPluginMetadata(serviceDir, swaggerModule) {
|
|
|
102
144
|
'silently, in the document every client is generated from. Refusing ' +
|
|
103
145
|
`instead.\n${(child.stderr || child.stdout || '').slice(-1200)}`);
|
|
104
146
|
}
|
|
147
|
+
reportUnreferenceableHostTypes(serviceDir, reportPath);
|
|
105
148
|
const ts = require(require.resolve('typescript', { paths: [serviceDir] }));
|
|
106
149
|
(0, node_fs_1.writeFileSync)(cjsPath, ts.transpileModule((0, node_fs_1.readFileSync)(tsPath, 'utf8'), {
|
|
107
150
|
compilerOptions: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-metadata.js","sourceRoot":"","sources":["../../src/lib/plugin-metadata.ts"],"names":[],"mappings":";;AAkFA,4DAiCC;
|
|
1
|
+
{"version":3,"file":"plugin-metadata.js","sourceRoot":"","sources":["../../src/lib/plugin-metadata.ts"],"names":[],"mappings":";;AAkFA,4DAiCC;AAwGD,kDAiIC;AAtSD,2DAA+C;AAC/C,qCAAuF;AACvF,qCAAiC;AACjC,yCAAqD;AASrD,MAAM,iBAAiB,GAAG,8BAA8B,CAAC;AAgBzD,SAAgB,wBAAwB,C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C,CAC5E,CAAC;QACJ,CAAC;QACD,MAAM,aAAa,CAAC,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACvD,OAAO,EAAE,CAAC;QACV,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,GAAG,oBAAoB,EAAE,CAAC;QAGpC,IAAA,gBAAM,EAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAChC,IAAA,gBAAM,EAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACjC,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC9B,MAAM,IAAI,KAAK,CACb,4DAA4D,UAAU,GAAG;YACvE,CAAC,IAAI,KAAK,SAAS;gBACjB,CAAC,CAAC,sEAAsE;gBACxE,CAAC,CAAC,yCAAyC,IAAI,mBAAmB;oBAChE,+DAA+D;oBAC/D,qCAAqC,CAAC,EAC5C,EAAE,KAAK,EAAE,CACV,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type * as TypeScript from 'typescript';
|
|
2
|
+
export declare function stripImportAttributes(typeReference: string): string;
|
|
3
|
+
export declare function hostFileModuleSpecifier(hostFilename: string): string;
|
|
4
|
+
export interface HostLocalTypeReference {
|
|
5
|
+
readonly typeName: string;
|
|
6
|
+
readonly hostFilename: string;
|
|
7
|
+
readonly exported: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface SwaggerPluginPatchState {
|
|
10
|
+
readonly hostLocalTypes: HostLocalTypeReference[];
|
|
11
|
+
}
|
|
12
|
+
export declare function installSwaggerPluginPatches(swaggerRoot: string, ts: typeof TypeScript, requireModule?: (path: string) => unknown): SwaggerPluginPatchState;
|
|
13
|
+
export declare function collectUnreferenceableHostTypes(state: SwaggerPluginPatchState): readonly HostLocalTypeReference[];
|
|
14
|
+
//# sourceMappingURL=swagger-plugin-patches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger-plugin-patches.d.ts","sourceRoot":"","sources":["../../src/lib/swagger-plugin-patches.ts"],"names":[],"mappings":"AAsFA,OAAO,KAAK,KAAK,UAAU,MAAM,YAAY,CAAC;AAW9C,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAKnE;AAgBD,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAEpE;AAGD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAGD,MAAM,WAAW,uBAAuB;IAEtC,QAAQ,CAAC,cAAc,EAAE,sBAAsB,EAAE,CAAC;CACnD;AAsFD,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,MAAM,EACnB,EAAE,EAAE,OAAO,UAAU,EACrB,aAAa,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAiB,GACjD,uBAAuB,CA8GzB;AASD,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,uBAAuB,GAC7B,SAAS,sBAAsB,EAAE,CASnC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stripImportAttributes = stripImportAttributes;
|
|
4
|
+
exports.hostFileModuleSpecifier = hostFileModuleSpecifier;
|
|
5
|
+
exports.installSwaggerPluginPatches = installSwaggerPluginPatches;
|
|
6
|
+
exports.collectUnreferenceableHostTypes = collectUnreferenceableHostTypes;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
function stripImportAttributes(typeReference) {
|
|
10
|
+
return typeReference.replace(/(\bimport\(\s*(?:"[^"]*"|'[^']*')\s*),\s*\{\s*(?:with|assert)\s*:\s*\{[^{}]*\}\s*\}/g, '$1');
|
|
11
|
+
}
|
|
12
|
+
function hostFileModuleSpecifier(hostFilename) {
|
|
13
|
+
return hostFilename.replace(/\.[cm]?[jt]sx?$/, '');
|
|
14
|
+
}
|
|
15
|
+
function hostLocalDeclaration(ts, descriptor, hostFilename, sourceOfHostFile) {
|
|
16
|
+
if (descriptor.typeName.includes('import(')) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
const sourceFile = sourceOfHostFile(hostFilename);
|
|
20
|
+
if (sourceFile === undefined) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
for (const statement of sourceFile.statements) {
|
|
24
|
+
if (!ts.isClassDeclaration(statement) &&
|
|
25
|
+
!ts.isEnumDeclaration(statement) &&
|
|
26
|
+
!ts.isInterfaceDeclaration(statement)) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (statement.name?.text !== descriptor.typeName) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
typeName: descriptor.typeName,
|
|
34
|
+
hostFilename,
|
|
35
|
+
exported: (ts.getCombinedModifierFlags(statement) & ts.ModifierFlags.Export) !== 0,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
function installSwaggerPluginPatches(swaggerRoot, ts, requireModule = require) {
|
|
41
|
+
const pluginUtils = requireModule(node_path_1.posix.join(swaggerRoot, 'dist/plugin/utils/plugin-utils.js'));
|
|
42
|
+
const typeReferenceUtil = requireModule(node_path_1.posix.join(swaggerRoot, 'dist/plugin/utils/type-reference-to-identifier.util.js'));
|
|
43
|
+
for (const [name, host] of [
|
|
44
|
+
['replaceImportPath', pluginUtils],
|
|
45
|
+
[
|
|
46
|
+
'typeReferenceToIdentifier',
|
|
47
|
+
typeReferenceUtil,
|
|
48
|
+
],
|
|
49
|
+
]) {
|
|
50
|
+
if (typeof host[name] !== 'function') {
|
|
51
|
+
throw new Error(`api-client-generator: @nestjs/swagger at ${swaggerRoot} exports no ` +
|
|
52
|
+
`\`${name}\` to correct. The metadata emitter is patched there for ` +
|
|
53
|
+
'two defects that otherwise ship as a ReferenceError and a TypeError ' +
|
|
54
|
+
'from generated code; refusing rather than emitting a module that ' +
|
|
55
|
+
'cannot be evaluated.');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const state = { hostLocalTypes: [] };
|
|
59
|
+
const parsedHosts = new Map();
|
|
60
|
+
const sourceOfHostFile = (path) => {
|
|
61
|
+
if (!parsedHosts.has(path)) {
|
|
62
|
+
let parsed;
|
|
63
|
+
try {
|
|
64
|
+
parsed = ts.createSourceFile(path, (0, node_fs_1.readFileSync)(path, 'utf8'), ts.ScriptTarget.Latest, true);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
parsed = undefined;
|
|
68
|
+
}
|
|
69
|
+
parsedHosts.set(path, parsed);
|
|
70
|
+
}
|
|
71
|
+
return parsedHosts.get(path);
|
|
72
|
+
};
|
|
73
|
+
const originalReplaceImportPath = pluginUtils.replaceImportPath;
|
|
74
|
+
pluginUtils.replaceImportPath = (typeReference, fileName, options) => originalReplaceImportPath(stripImportAttributes(typeReference), fileName, options);
|
|
75
|
+
const originalTypeReferenceToIdentifier = typeReferenceUtil.typeReferenceToIdentifier;
|
|
76
|
+
typeReferenceUtil.typeReferenceToIdentifier = (descriptor, hostFilename, options, factory, type, typeImports) => {
|
|
77
|
+
const hostLocal = options.readonly === true
|
|
78
|
+
? hostLocalDeclaration(ts, descriptor, hostFilename, sourceOfHostFile)
|
|
79
|
+
: undefined;
|
|
80
|
+
if (hostLocal === undefined) {
|
|
81
|
+
return originalTypeReferenceToIdentifier(descriptor, hostFilename, options, factory, type, typeImports);
|
|
82
|
+
}
|
|
83
|
+
state.hostLocalTypes.push(hostLocal);
|
|
84
|
+
return originalTypeReferenceToIdentifier({
|
|
85
|
+
...descriptor,
|
|
86
|
+
typeName: `import("${hostFileModuleSpecifier(hostFilename)}").${descriptor.typeName}`,
|
|
87
|
+
}, hostFilename, options, factory, type, typeImports);
|
|
88
|
+
};
|
|
89
|
+
return state;
|
|
90
|
+
}
|
|
91
|
+
function collectUnreferenceableHostTypes(state) {
|
|
92
|
+
const byKey = new Map();
|
|
93
|
+
for (const entry of state.hostLocalTypes) {
|
|
94
|
+
if (entry.exported) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
byKey.set(`${entry.hostFilename}#${entry.typeName}`, entry);
|
|
98
|
+
}
|
|
99
|
+
return [...byKey.values()];
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=swagger-plugin-patches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger-plugin-patches.js","sourceRoot":"","sources":["../../src/lib/swagger-plugin-patches.ts"],"names":[],"mappings":";;AAiGA,sDAKC;AAgBD,0DAEC;AAoGD,kEAkHC;AASD,0EAWC;AA/QD,qCAAuC;AACvC,yCAAkC;AAalC,SAAgB,qBAAqB,CAAC,aAAqB;IACzD,OAAO,aAAa,CAAC,OAAO,CAC1B,sFAAsF,EACtF,IAAI,CACL,CAAC;AACJ,CAAC;AAgBD,SAAgB,uBAAuB,CAAC,YAAoB;IAC1D,OAAO,YAAY,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;AACrD,CAAC;AA2DD,SAAS,oBAAoB,CAC3B,EAAqB,EACrB,UAAgC,EAChC,YAAoB,EACpB,gBAAqE;IAErE,IAAI,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5C,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,UAAU,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAClD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAC;IACnB,CA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KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,iCAAiC,CACtC,UAAU,EACV,YAAY,EACZ,OAAO,EACP,OAAO,EACP,IAAI,EACJ,WAAW,CACZ,CAAC;QACJ,CAAC;QAED,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAOrC,OAAO,iCAAiC,CACtC;YACE,GAAG,UAAU;YACb,QAAQ,EAAE,WAAW,uBAAuB,CAAC,YAAY,CAAC,MAAM,UAAU,CAAC,QAAQ,EAAE;SACtF,EACD,YAAY,EACZ,OAAO,EACP,OAAO,EACP,IAAI,EACJ,WAAW,CACZ,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,KAAK,CAAC;AACf,CAAC;AASD,SAAgB,+BAA+B,CAC7C,KAA8B;IAE9B,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkC,CAAC;IACxD,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,cAAc,EAAE,CAAC;QACzC,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;YACnB,SAAS;QACX,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,QAAQ,EAAE,EAAE,KAAK,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;AAC7B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xemahq/api-client-generator",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.2",
|
|
4
4
|
"description": "Layer 1 — the single, central OpenAPI + ORVAL client generator for every Xema NestJS service. Replaces the per-service orval.config.ts / scripts/extract-openapi.ts / scripts/build-client-index.js trio with two bins (xema-openapi, xema-client-generate). Extracts one OpenAPI document per ApiSurface (public/internal/operator) using the @XemaApiSurface decorator metadata, generates one ORVAL client package per non-empty surface (every surface of a service landing on ONE derived version — the highest its clients already carry, advanced a patch when the generated output changes), and stamps deterministic `xema` provenance metadata into each generated client package.json. No heuristics: a route ships in a surface only if it (or its controller) is explicitly classified, and no client version is ever typed by hand.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xema",
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
"prettier": "3.6.2",
|
|
63
63
|
"reflect-metadata": "0.2.2",
|
|
64
64
|
"typescript": "5.9.3",
|
|
65
|
-
"@xemahq/
|
|
66
|
-
"@xemahq/
|
|
65
|
+
"@xemahq/xema-decorators": "0.14.0",
|
|
66
|
+
"@xemahq/eslint-config": "0.3.0"
|
|
67
67
|
},
|
|
68
68
|
"exports": {
|
|
69
69
|
".": {
|