@xemahq/api-client-generator 0.1.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/xema-openapi.js +2 -2
- package/dist/bin/xema-openapi.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/client-package.d.ts.map +1 -1
- package/dist/lib/client-package.js +9 -4
- package/dist/lib/client-package.js.map +1 -1
- package/dist/lib/default-stubs.d.ts.map +1 -1
- package/dist/lib/default-stubs.js +35 -10
- package/dist/lib/default-stubs.js.map +1 -1
- package/dist/lib/extract-openapi.d.ts +2 -2
- package/dist/lib/extract-openapi.d.ts.map +1 -1
- package/dist/lib/extract-openapi.js +35 -39
- package/dist/lib/extract-openapi.js.map +1 -1
- package/dist/lib/generate-clients.d.ts +1 -1
- package/dist/lib/generate-clients.d.ts.map +1 -1
- package/dist/lib/generate-clients.js +33 -6
- package/dist/lib/generate-clients.js.map +1 -1
- package/dist/lib/overrides.d.ts.map +1 -1
- package/dist/lib/overrides.js +10 -2
- package/dist/lib/overrides.js.map +1 -1
- package/dist/lib/repo-post-process.d.ts.map +1 -1
- package/dist/lib/repo-post-process.js +2 -1
- package/dist/lib/repo-post-process.js.map +1 -1
- package/dist/lib/seed-openapi-env.d.ts +2 -1
- package/dist/lib/seed-openapi-env.d.ts.map +1 -1
- package/dist/lib/seed-openapi-env.js +14 -24
- package/dist/lib/seed-openapi-env.js.map +1 -1
- package/dist/lib/service-config.d.ts +1 -1
- package/dist/lib/service-config.d.ts.map +1 -1
- package/dist/lib/service-config.js +2 -2
- package/dist/lib/service-config.js.map +1 -1
- package/dist/lib/service-nest.d.ts.map +1 -1
- package/dist/lib/service-nest.js.map +1 -1
- package/package.json +6 -4
- package/src/bin/xema-client-generate.ts +11 -0
- package/src/bin/xema-openapi.ts +51 -0
- package/src/index.ts +9 -0
- package/src/lib/client-package.ts +215 -0
- package/src/lib/client-readme.ts +124 -0
- package/src/lib/custom-fetch-template.ts +200 -0
- package/src/lib/default-stubs.ts +422 -0
- package/src/lib/extract-openapi.ts +240 -0
- package/src/lib/generate-clients.ts +240 -0
- package/src/lib/overrides.ts +81 -0
- package/src/lib/repo-post-process.ts +106 -0
- package/src/lib/seed-openapi-env.ts +137 -0
- package/src/lib/service-config.ts +170 -0
- package/src/lib/service-nest.ts +58 -0
- package/dist/lib/prune-spec.d.ts +0 -16
- package/dist/lib/prune-spec.d.ts.map +0 -1
- package/dist/lib/prune-spec.js +0 -100
- package/dist/lib/prune-spec.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.openApiScratchSchema = openApiScratchSchema;
|
|
3
4
|
exports.seedOpenApiEnv = seedOpenApiEnv;
|
|
4
5
|
const DUMMY_ENCRYPTION_KEY_HEX = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';
|
|
5
6
|
const DUMMY_BASE64_KEY = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=';
|
|
@@ -10,14 +11,22 @@ function seed(vars) {
|
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
const SCRATCH_DB_NAME = 'dummy_openapi';
|
|
15
|
+
function openApiScratchSchema(serviceId) {
|
|
16
|
+
return `extract_${serviceId.replace(/[^a-zA-Z0-9]+/g, '_')}`
|
|
17
|
+
.toLowerCase()
|
|
18
|
+
.slice(0, 63);
|
|
19
|
+
}
|
|
20
|
+
function seedOpenApiEnv(serviceId) {
|
|
21
|
+
const schema = openApiScratchSchema(serviceId);
|
|
14
22
|
seed({
|
|
15
23
|
NODE_ENV: 'development',
|
|
16
24
|
XEMA_OPENAPI_EXTRACTION: '1',
|
|
17
|
-
DATABASE_URL:
|
|
25
|
+
DATABASE_URL: `postgresql://dummy:dummy@localhost:5432/${SCRATCH_DB_NAME}?schema=${schema}`,
|
|
18
26
|
DB_HOST: 'localhost',
|
|
19
27
|
DB_PORT: '5432',
|
|
20
|
-
DB_NAME:
|
|
28
|
+
DB_NAME: SCRATCH_DB_NAME,
|
|
29
|
+
DB_SCHEMA: schema,
|
|
21
30
|
DB_USER: 'dummy',
|
|
22
31
|
DB_PASSWORD: 'dummy',
|
|
23
32
|
REDIS_URL: 'redis://localhost:6379',
|
|
@@ -31,38 +40,19 @@ function seedOpenApiEnv() {
|
|
|
31
40
|
OPENCODE_WORKER_PASSWORD: 'dummy-worker-password',
|
|
32
41
|
XEMA_ETCD_ENDPOINTS: 'localhost:2379',
|
|
33
42
|
EVENT_HUB_URL: 'http://localhost:3128',
|
|
34
|
-
|
|
43
|
+
WEBHOOK_URL: 'http://localhost:3000/webhooks/events',
|
|
35
44
|
BACKLOG_API_URL: 'http://localhost:3100',
|
|
36
45
|
MEMORY_API_URL: 'http://localhost:3060',
|
|
37
46
|
LLM_REGISTRY_API_URL: 'http://localhost:3112',
|
|
38
47
|
LLM_GATEWAY_API_URL: 'http://localhost:3110',
|
|
39
|
-
POOL_API_URL: 'http://localhost:3145',
|
|
40
48
|
ARTIFACT_STORE_API_URL: 'http://localhost:3130',
|
|
41
49
|
KNOWLEDGE_BASE_API_URL: 'http://localhost:3200',
|
|
42
50
|
PROJECT_REGISTRY_API_URL: 'http://localhost:3300',
|
|
43
|
-
|
|
51
|
+
CONNECTOR_GATEWAY_API_URL: 'http://localhost:3900',
|
|
44
52
|
DESIGN_SYSTEM_BUILDER_API_URL: 'http://localhost:3210',
|
|
45
53
|
SEARCH_API_URL: 'http://localhost:3220',
|
|
46
54
|
BILLING_API_URL: 'http://localhost:3140',
|
|
47
55
|
CAPABILITY_REGISTRY_API_URL: 'http://localhost:3700',
|
|
48
|
-
MCP_KNOWLEDGE_BASE_URL: 'http://localhost:3201/mcp',
|
|
49
|
-
MCP_BACKLOG_URL: 'http://localhost:3101/mcp',
|
|
50
|
-
MCP_DOC_TEMPLATE_URL: 'http://localhost:3231/mcp',
|
|
51
|
-
MCP_PROJECT_REGISTRY_URL: 'http://localhost:3301/mcp',
|
|
52
|
-
MCP_SEARCH_URL: 'http://localhost:3221/mcp',
|
|
53
|
-
KNOWLEDGE_BASE_MCP_URL: 'http://localhost:3201/mcp',
|
|
54
|
-
BACKLOG_MCP_URL: 'http://localhost:3101/mcp',
|
|
55
|
-
ARTIFACT_STORE_MCP_URL: 'http://localhost:3131/mcp',
|
|
56
|
-
MEMORY_MCP_URL: 'http://localhost:3061/mcp',
|
|
57
|
-
CATALOG_MCP_URL: 'http://localhost:3111/mcp',
|
|
58
|
-
REVIEW_GATE_MCP_URL: 'http://localhost:3501/mcp',
|
|
59
|
-
AUDIT_LOG_MCP_URL: 'http://localhost:3601/mcp',
|
|
60
|
-
PROJECT_REGISTRY_MCP_URL: 'http://localhost:3301/mcp',
|
|
61
|
-
DOC_TEMPLATE_MCP_URL: 'http://localhost:3231/mcp',
|
|
62
|
-
PHASE_GATE_MCP_URL: 'http://localhost:3801/mcp',
|
|
63
|
-
UI_TEMPLATES_MCP_URL: 'http://localhost:3901/mcp',
|
|
64
|
-
SEARCH_MCP_URL: 'http://localhost:3221/mcp',
|
|
65
|
-
DESIGN_SYSTEM_BUILDER_MCP_URL: 'http://localhost:3211/mcp',
|
|
66
56
|
SCM_WEBHOOK_SECRET: 'dummy-webhook-secret',
|
|
67
57
|
SCM_WEBHOOK_BASE_URL: 'http://localhost:3500/webhooks',
|
|
68
58
|
GITEA_URL: 'http://localhost:3000',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed-openapi-env.js","sourceRoot":"","sources":["../../src/lib/seed-openapi-env.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"seed-openapi-env.js","sourceRoot":"","sources":["../../src/lib/seed-openapi-env.ts"],"names":[],"mappings":";;AA0CA,oDAIC;AAMD,wCAoFC;AAxH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AAE,gBAAgB;QAMrC,aAAa,EAAE,uBAAuB;QACtC,WAAW,EAAE,uCAAuC;QAGpD,eAAe,EAAE,uBAAuB;QACxC,cAAc,EAAE,uBAAuB;QACvC,oBAAoB,EAAE,uBAAuB;QAC7C,mBAAmB,EAAE,uBAAuB;QAC5C,sBAAsB,EAAE,uBAAuB;QAC/C,sBAAsB,EAAE,uBAAuB;QAC/C,wBAAwB,EAAE,uBAAuB;QACjD,yBAAyB,EAAE,uBAAuB;QAClD,6BAA6B,EAAE,uBAAuB;QACtD,cAAc,EAAE,uBAAuB;QACvC,eAAe,EAAE,uBAAuB;QACxC,2BAA2B,EAAE,uBAAuB;QAGpD,kBAAkB,EAAE,sBAAsB;QAC1C,oBAAoB,EAAE,gCAAgC;QACtD,SAAS,EAAE,uBAAuB;QAClC,gBAAgB,EAAE,aAAa;QAC/B,gBAAgB,EAAE,kBAAkB;QAGpC,qBAAqB,EAAE,wBAAwB;QAC/C,qBAAqB,EAAE,gBAAgB;QACvC,2BAA2B,EACzB,kEAAkE;QACpE,uBAAuB,EACrB,kEAAkE;QAGpE,yBAAyB,EAAE,+BAA+B;QAC1D,uBAAuB,EAAE,6BAA6B;KACvD,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -16,5 +16,5 @@ export declare function resolveServiceContext(serviceDir: string): ResolvedServi
|
|
|
16
16
|
export declare function surfaceClientShortName(serviceId: string, surface: ApiSurface): string;
|
|
17
17
|
export declare function surfaceClientPackageName(serviceId: string, surface: ApiSurface): string;
|
|
18
18
|
export declare function surfaceClientDir(ctx: ResolvedServiceContext, surface: ApiSurface): string;
|
|
19
|
-
export declare function surfaceSpecPath(ctx: ResolvedServiceContext, surface: ApiSurface): string;
|
|
19
|
+
export declare function surfaceSpecPath(ctx: ResolvedServiceContext, surface: ApiSurface, outDir?: string): string;
|
|
20
20
|
//# sourceMappingURL=service-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-config.d.ts","sourceRoot":"","sources":["../../src/lib/service-config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAerD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,sBAAsB;IAErC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC;IAE5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAGD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAYlD;AAOD,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,sBAAsB,CA8ChF;AAeD,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,UAAU,GAClB,MAAM,CAUR;AAGD,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,UAAU,GAClB,MAAM,CAER;AAGD,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,sBAAsB,EAC3B,OAAO,EAAE,UAAU,GAClB,MAAM,CAMR;AAGD,wBAAgB,eAAe,CAC7B,GAAG,EAAE,sBAAsB,EAC3B,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"service-config.d.ts","sourceRoot":"","sources":["../../src/lib/service-config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAerD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,sBAAsB;IAErC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC;IAE5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAGD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAYlD;AAOD,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,sBAAsB,CA8ChF;AAeD,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,UAAU,GAClB,MAAM,CAUR;AAGD,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,UAAU,GAClB,MAAM,CAER;AAGD,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,sBAAsB,EAC3B,OAAO,EAAE,UAAU,GAClB,MAAM,CAMR;AAGD,wBAAgB,eAAe,CAC7B,GAAG,EAAE,sBAAsB,EAC3B,OAAO,EAAE,UAAU,EAWnB,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAER"}
|
|
@@ -74,7 +74,7 @@ function surfaceClientDir(ctx, surface) {
|
|
|
74
74
|
const dirName = surfaceClientShortName(ctx.api.serviceId, surface).replace(/-client$/, '');
|
|
75
75
|
return (0, node_path_1.join)(ctx.repoRoot, 'packages', 'clients', dirName);
|
|
76
76
|
}
|
|
77
|
-
function surfaceSpecPath(ctx, surface) {
|
|
78
|
-
return (0, node_path_1.join)(ctx.serviceDir, `openapi.${surface}.json`);
|
|
77
|
+
function surfaceSpecPath(ctx, surface, outDir) {
|
|
78
|
+
return (0, node_path_1.join)(outDir ?? ctx.serviceDir, `openapi.${surface}.json`);
|
|
79
79
|
}
|
|
80
80
|
//# sourceMappingURL=service-config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-config.js","sourceRoot":"","sources":["../../src/lib/service-config.ts"],"names":[],"mappings":";;AAqCA,oCAYC;AAOD,sDA8CC;AAeD,wDAaC;AAGD,4DAKC;AAGD,4CASC;AAGD,
|
|
1
|
+
{"version":3,"file":"service-config.js","sourceRoot":"","sources":["../../src/lib/service-config.ts"],"names":[],"mappings":";;AAqCA,oCAYC;AAOD,sDA8CC;AAeD,wDAaC;AAGD,4DAKC;AAGD,4CASC;AAGD,0CAgBC;AAzKD,qCAAmD;AACnD,yCAAmD;AAEnD,6DAAqD;AAkCrD,SAAgB,YAAY,CAAC,KAAa;IACxC,IAAI,GAAG,GAAG,IAAA,mBAAO,EAAC,KAAK,CAAC,CAAC;IACzB,OAAO,GAAG,KAAK,IAAA,mBAAO,EAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,IAAI,IAAA,oBAAU,EAAC,IAAA,gBAAI,EAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC,EAAE,CAAC;YACjD,OAAO,GAAG,CAAC;QACb,CAAC;QACD,GAAG,GAAG,IAAA,mBAAO,EAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,MAAM,IAAI,KAAK,CACb,2EAA2E;QACzE,mBAAmB,KAAK,GAAG,CAC9B,CAAC;AACJ,CAAC;AAOD,SAAgB,qBAAqB,CAAC,UAAkB;IACtD,MAAM,OAAO,GAAG,IAAA,gBAAI,EAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IACjD,IAAI,CAAC,IAAA,oBAAU,EAAC,OAAO,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,kDAAkD,OAAO,YAAY;YACnE,qCAAqC,CACxC,CAAC;IACJ,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,sBAAY,EAAC,OAAO,EAAE,MAAM,CAAC,CAGnD,CAAC;IACF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AAE,IAAI,CAAC,eAAe,CAAC,CAAC;IAChD,QAAQ,CAAC,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;CACnD;AAWD,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,WAAW,CAY/D;AAED,YAAY,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-nest.js","sourceRoot":"","sources":["../../src/lib/service-nest.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"service-nest.js","sourceRoot":"","sources":["../../src/lib/service-nest.ts"],"names":[],"mappings":";;AA2CA,0CAYC;AArBD,SAAS,WAAW,CAClB,UAAkB,EAClB,OAAe;IAEf,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAEnE,OAAO,OAAO,CAAC,QAAQ,CAA4B,CAAC;AACtD,CAAC;AAED,SAAgB,eAAe,CAAC,UAAkB;IAChD,MAAM,IAAI,GAAG,WAAW,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IACrD,MAAM,OAAO,GAAG,WAAW,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,WAAW,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IAC3D,OAAO;QACL,IAAI,EAAE,OAAO,CAAC,IAAmB;QACjC,eAAe,EAAE,OAAO,CAAC,eAAyC;QAClE,aAAa,EAAE,OAAO,CAAC,aAAqC;QAC5D,gBAAgB,EAAE,IAAI,CAAC,gBAA0C;QACjE,eAAe,EAAE,IAAI,CAAC,eAAwC;QAC9D,gBAAgB,EAAE,IAAI,CAAC,gBAA0C;KAClE,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xemahq/api-client-generator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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 (all sharing the owning service's version), 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.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xema",
|
|
@@ -30,14 +30,15 @@
|
|
|
30
30
|
"xema-client-generate": "dist/bin/xema-client-generate.js"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
|
-
"dist"
|
|
33
|
+
"dist",
|
|
34
|
+
"src"
|
|
34
35
|
],
|
|
35
36
|
"peerDependencies": {
|
|
36
37
|
"@nestjs/common": "^10 || ^11",
|
|
37
38
|
"@nestjs/core": "^10 || ^11",
|
|
38
39
|
"@nestjs/swagger": "^7 || ^8 || ^11",
|
|
39
40
|
"@nestjs/testing": "^10 || ^11",
|
|
40
|
-
"@xemahq/xema-decorators": "
|
|
41
|
+
"@xemahq/xema-decorators": ">=0.4.0",
|
|
41
42
|
"orval": "^8",
|
|
42
43
|
"reflect-metadata": "^0.2",
|
|
43
44
|
"ts-node": ">=10",
|
|
@@ -62,7 +63,7 @@
|
|
|
62
63
|
"prettier": "3.6.2",
|
|
63
64
|
"reflect-metadata": "0.2.2",
|
|
64
65
|
"typescript": "5.9.3",
|
|
65
|
-
"@xemahq/xema-decorators": "0.2
|
|
66
|
+
"@xemahq/xema-decorators": "0.5.2"
|
|
66
67
|
},
|
|
67
68
|
"exports": {
|
|
68
69
|
".": {
|
|
@@ -75,6 +76,7 @@
|
|
|
75
76
|
"clean": "rm -rf dist",
|
|
76
77
|
"build": "tsc -p tsconfig.build.json",
|
|
77
78
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
79
|
+
"lint": "eslint .",
|
|
78
80
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
79
81
|
}
|
|
80
82
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `xema-client-generate` — generate (and compile) one ORVAL client package per
|
|
4
|
+
* surface that has an `openapi.<surface>.json` spec in the current working
|
|
5
|
+
* directory. Run AFTER `xema-openapi`.
|
|
6
|
+
*
|
|
7
|
+
* Service package.json: `"client:generate": "xema-client-generate"`.
|
|
8
|
+
*/
|
|
9
|
+
import { runClientGenerateCli } from '../lib/generate-clients';
|
|
10
|
+
|
|
11
|
+
runClientGenerateCli();
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `xema-openapi` — extract one OpenAPI document per ApiSurface from the NestJS
|
|
4
|
+
* service in the current working directory.
|
|
5
|
+
*
|
|
6
|
+
* Run from a service dir (where package.json carries `xema.api`). Self-registers
|
|
7
|
+
* ts-node + tsconfig-paths from the SERVICE's own toolchain so the service's TS
|
|
8
|
+
* `AppModule` compiles on import, then delegates to the generator.
|
|
9
|
+
*
|
|
10
|
+
* Service package.json: `"openapi": "NODE_PATH=node_modules xema-openapi"`.
|
|
11
|
+
*/
|
|
12
|
+
// `node:module` is a side-effect-free builtin, so a static import is
|
|
13
|
+
// equivalent to the `require()` this used to do (the file compiles to
|
|
14
|
+
// CommonJS) — and it drops an inline `import()` type annotation whose only
|
|
15
|
+
// job was to type that `require`. The DYNAMIC requires below are different:
|
|
16
|
+
// they resolve paths computed at runtime, after `ts-node.register()` has
|
|
17
|
+
// patched the require hook, and must stay `require()`.
|
|
18
|
+
import { Module } from 'node:module';
|
|
19
|
+
import { delimiter } from 'node:path';
|
|
20
|
+
|
|
21
|
+
function registerTsNode(cwd: string): void {
|
|
22
|
+
const tsNode = require.resolve('ts-node', { paths: [cwd] });
|
|
23
|
+
|
|
24
|
+
(require(tsNode) as { register: (o: unknown) => void }).register({
|
|
25
|
+
transpileOnly: true,
|
|
26
|
+
});
|
|
27
|
+
try {
|
|
28
|
+
const paths = require.resolve('tsconfig-paths/register', { paths: [cwd] });
|
|
29
|
+
require(paths);
|
|
30
|
+
} catch {
|
|
31
|
+
// tsconfig-paths is optional — services without path aliases don't need it.
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function ensureNodePath(): void {
|
|
36
|
+
process.env.NODE_PATH = process.env.NODE_PATH
|
|
37
|
+
? `node_modules${delimiter}${process.env.NODE_PATH}`
|
|
38
|
+
: 'node_modules';
|
|
39
|
+
(Module as unknown as { _initPaths: () => void })._initPaths();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
ensureNodePath();
|
|
43
|
+
registerTsNode(process.cwd());
|
|
44
|
+
|
|
45
|
+
// Require AFTER ts-node is registered so the service's TS modules compile.
|
|
46
|
+
|
|
47
|
+
const { runOpenApiCli } = require('../lib/extract-openapi') as {
|
|
48
|
+
runOpenApiCli: () => void;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
runOpenApiCli();
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Public programmatic surface of the central API-client generator.
|
|
2
|
+
export * from './lib/service-config';
|
|
3
|
+
export * from './lib/overrides';
|
|
4
|
+
export * from './lib/seed-openapi-env';
|
|
5
|
+
export * from './lib/default-stubs';
|
|
6
|
+
export * from './lib/extract-openapi';
|
|
7
|
+
export * from './lib/repo-post-process';
|
|
8
|
+
export * from './lib/client-package';
|
|
9
|
+
export * from './lib/generate-clients';
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cpSync,
|
|
3
|
+
existsSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
readFileSync,
|
|
6
|
+
writeFileSync,
|
|
7
|
+
} from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
|
|
10
|
+
import { ApiSurface } from '@xemahq/xema-decorators';
|
|
11
|
+
|
|
12
|
+
import { CANONICAL_CUSTOM_FETCH } from './custom-fetch-template';
|
|
13
|
+
import {
|
|
14
|
+
surfaceClientDir,
|
|
15
|
+
surfaceClientPackageName,
|
|
16
|
+
type ResolvedServiceContext,
|
|
17
|
+
} from './service-config';
|
|
18
|
+
|
|
19
|
+
/** The authoritative package→Xema mapping stamped into each generated client. */
|
|
20
|
+
export interface GeneratedClientXemaBlock {
|
|
21
|
+
readonly kind: 'api-client';
|
|
22
|
+
readonly surface: ApiSurface;
|
|
23
|
+
readonly service: string;
|
|
24
|
+
readonly biome: string;
|
|
25
|
+
readonly target: 'server';
|
|
26
|
+
readonly generator: string;
|
|
27
|
+
readonly source: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const CLIENT_TSCONFIG = {
|
|
31
|
+
compilerOptions: {
|
|
32
|
+
target: 'ES2022',
|
|
33
|
+
module: 'commonjs',
|
|
34
|
+
lib: ['ES2022', 'DOM'],
|
|
35
|
+
types: [],
|
|
36
|
+
strict: true,
|
|
37
|
+
esModuleInterop: true,
|
|
38
|
+
skipLibCheck: true,
|
|
39
|
+
declaration: true,
|
|
40
|
+
outDir: './dist',
|
|
41
|
+
rootDir: './src',
|
|
42
|
+
},
|
|
43
|
+
include: ['src/**/*.ts'],
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
function generatorTag(): string {
|
|
47
|
+
const pkg = require('../../package.json') as { version: string };
|
|
48
|
+
return `@xemahq/api-client-generator@${pkg.version}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function recordOrEmpty(value: unknown): Record<string, unknown> {
|
|
52
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
53
|
+
? Object.fromEntries(Object.entries(value))
|
|
54
|
+
: {};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Parse a release semver core `x.y.z` (any prerelease/build suffix ignored). */
|
|
58
|
+
function parseVersionCore(v: string): [number, number, number] | null {
|
|
59
|
+
const m = /^(\d+)\.(\d+)\.(\d+)/.exec(v.trim());
|
|
60
|
+
return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Resolve the client `version` MONOTONICALLY. A published client MUST NEVER be
|
|
65
|
+
* downgraded by regeneration: we keep whichever of the existing client version
|
|
66
|
+
* and the service version is greater. A forward bump happens only when the
|
|
67
|
+
* service version genuinely exceeds the client's (an intentional, monotonic
|
|
68
|
+
* move). If either version is unparseable, the existing version is kept — the
|
|
69
|
+
* fail-safe default is "never downgrade".
|
|
70
|
+
*
|
|
71
|
+
* A fresh client (no existing version) adopts the service version.
|
|
72
|
+
*/
|
|
73
|
+
export function resolveMonotonicVersion(
|
|
74
|
+
existing: unknown,
|
|
75
|
+
serviceVersion: string,
|
|
76
|
+
): string {
|
|
77
|
+
if (typeof existing !== 'string' || existing.trim() === '') {
|
|
78
|
+
return serviceVersion;
|
|
79
|
+
}
|
|
80
|
+
const e = parseVersionCore(existing);
|
|
81
|
+
const s = parseVersionCore(serviceVersion);
|
|
82
|
+
if (!e || !s) {
|
|
83
|
+
return existing;
|
|
84
|
+
}
|
|
85
|
+
const [eMaj, eMin, ePat] = e;
|
|
86
|
+
const [sMaj, sMin, sPat] = s;
|
|
87
|
+
if (sMaj !== eMaj) {
|
|
88
|
+
return sMaj > eMaj ? serviceVersion : existing;
|
|
89
|
+
}
|
|
90
|
+
if (sMin !== eMin) {
|
|
91
|
+
return sMin > eMin ? serviceVersion : existing;
|
|
92
|
+
}
|
|
93
|
+
if (sPat !== ePat) {
|
|
94
|
+
return sPat > ePat ? serviceVersion : existing;
|
|
95
|
+
}
|
|
96
|
+
return existing;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Ensure the surface client package exists and carries the canonical stable
|
|
101
|
+
* metadata + the authoritative `xema` provenance block. Preserves any
|
|
102
|
+
* pre-existing `dependencies`/`peerDependencies` on an existing client.
|
|
103
|
+
*
|
|
104
|
+
* Returns the absolute client `src` directory (orval's output target).
|
|
105
|
+
*/
|
|
106
|
+
export function ensureClientPackage(
|
|
107
|
+
ctx: ResolvedServiceContext,
|
|
108
|
+
surface: ApiSurface,
|
|
109
|
+
): { clientDir: string; clientSrc: string } {
|
|
110
|
+
const clientDir = surfaceClientDir(ctx, surface);
|
|
111
|
+
const clientSrc = join(clientDir, 'src');
|
|
112
|
+
mkdirSync(clientSrc, { recursive: true });
|
|
113
|
+
|
|
114
|
+
const packageName = surfaceClientPackageName(ctx.api.serviceId, surface);
|
|
115
|
+
const xema: GeneratedClientXemaBlock = {
|
|
116
|
+
kind: 'api-client',
|
|
117
|
+
surface,
|
|
118
|
+
service: ctx.api.serviceId,
|
|
119
|
+
biome: ctx.api.biomeId,
|
|
120
|
+
target: 'server',
|
|
121
|
+
generator: generatorTag(),
|
|
122
|
+
source: `openapi.${surface}.json`,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const pkgPath = join(clientDir, 'package.json');
|
|
126
|
+
const existing = existsSync(pkgPath)
|
|
127
|
+
? (JSON.parse(readFileSync(pkgPath, 'utf8')) as Record<string, unknown>)
|
|
128
|
+
: {};
|
|
129
|
+
const existingScripts = recordOrEmpty(existing.scripts);
|
|
130
|
+
const existingDevDeps = recordOrEmpty(existing.devDependencies);
|
|
131
|
+
const existingPublishConfig = recordOrEmpty(existing.publishConfig);
|
|
132
|
+
// Start from the existing (hand-maintained) package and override ONLY the
|
|
133
|
+
// fields the generator is explicitly responsible for. Every other field
|
|
134
|
+
// authored by hand — `dependencies` (e.g. zod), `peerDependencies`, extra
|
|
135
|
+
// scripts (`clean`/`typecheck`), extra devDependencies (`@types/node`),
|
|
136
|
+
// license/repository/exports/etc. — is preserved verbatim. Regeneration is
|
|
137
|
+
// metadata-stable: it never silently drops hand-maintained config and, per
|
|
138
|
+
// {@link resolveMonotonicVersion}, never downgrades the package version.
|
|
139
|
+
const pkg: Record<string, unknown> = {
|
|
140
|
+
...existing,
|
|
141
|
+
name: packageName,
|
|
142
|
+
version: resolveMonotonicVersion(existing.version, ctx.version),
|
|
143
|
+
main: './dist/index.js',
|
|
144
|
+
types: './dist/index.d.ts',
|
|
145
|
+
files: ['dist'],
|
|
146
|
+
scripts: {
|
|
147
|
+
...existingScripts,
|
|
148
|
+
// Generator-owned: the client must build and build-before-publish.
|
|
149
|
+
build: 'tsc -p tsconfig.json',
|
|
150
|
+
prepublishOnly: 'npm run build',
|
|
151
|
+
},
|
|
152
|
+
// This block used to be replaced WHOLESALE, which silently dropped
|
|
153
|
+
// `access: "public"` from every client on every regeneration — contradicting
|
|
154
|
+
// the promise three lines above. npm refuses to publish a SCOPED package
|
|
155
|
+
// without it, so each regeneration quietly armed a publish failure, and the
|
|
156
|
+
// fix (re-adding `access`) had to be re-applied by hand every time.
|
|
157
|
+
//
|
|
158
|
+
// `access` defaults to `public` because every generated @xemahq client is a
|
|
159
|
+
// public package; a hand-authored override still wins. `registry` stays
|
|
160
|
+
// generator-owned.
|
|
161
|
+
publishConfig: {
|
|
162
|
+
access: 'public',
|
|
163
|
+
...existingPublishConfig,
|
|
164
|
+
registry: 'https://registry.npmjs.org/',
|
|
165
|
+
},
|
|
166
|
+
devDependencies: {
|
|
167
|
+
...existingDevDeps,
|
|
168
|
+
// Generator-owned: tsc is required to build the generated client.
|
|
169
|
+
typescript: 'catalog:',
|
|
170
|
+
},
|
|
171
|
+
// Generator-owned: the authoritative provenance block is always rewritten.
|
|
172
|
+
xema,
|
|
173
|
+
};
|
|
174
|
+
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`, 'utf8');
|
|
175
|
+
|
|
176
|
+
const tsconfigPath = join(clientDir, 'tsconfig.json');
|
|
177
|
+
if (!existsSync(tsconfigPath)) {
|
|
178
|
+
writeFileSync(
|
|
179
|
+
tsconfigPath,
|
|
180
|
+
`${JSON.stringify(CLIENT_TSCONFIG, null, 2)}\n`,
|
|
181
|
+
'utf8',
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
ensureCustomFetch(ctx, clientSrc);
|
|
186
|
+
|
|
187
|
+
return { clientDir, clientSrc };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* custom-fetch.ts is hand-maintained runtime config, identical across all
|
|
192
|
+
* clients. For an existing client it is left untouched. For a freshly
|
|
193
|
+
* scaffolded surface client we copy the service's public-surface sibling's
|
|
194
|
+
* custom-fetch when present (the most authoritative local copy), else write
|
|
195
|
+
* the canonical embedded template.
|
|
196
|
+
*/
|
|
197
|
+
function ensureCustomFetch(
|
|
198
|
+
ctx: ResolvedServiceContext,
|
|
199
|
+
clientSrc: string,
|
|
200
|
+
): void {
|
|
201
|
+
const target = join(clientSrc, 'custom-fetch.ts');
|
|
202
|
+
if (existsSync(target)) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const publicSibling = join(
|
|
206
|
+
surfaceClientDir(ctx, ApiSurface.Public),
|
|
207
|
+
'src',
|
|
208
|
+
'custom-fetch.ts',
|
|
209
|
+
);
|
|
210
|
+
if (existsSync(publicSibling)) {
|
|
211
|
+
cpSync(publicSibling, target);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
writeFileSync(target, CANONICAL_CUSTOM_FETCH, 'utf8');
|
|
215
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { ApiSurface } from '@xemahq/xema-decorators';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Generated API clients carry a README emitted from the canonical package-README
|
|
8
|
+
* template (see the `write-package-readme` skill). It is fully generator-owned —
|
|
9
|
+
* never hand-edit a generated client's README; change this emitter and
|
|
10
|
+
* regenerate. The content is derived ONLY from the client's own identity (name,
|
|
11
|
+
* the owning service's title, the repo license) so it never needs updating when
|
|
12
|
+
* other packages change.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** Teal accent — the banner taxonomy colour for a generated API client. */
|
|
16
|
+
const CLIENT_ACCENT = '#14B8A6';
|
|
17
|
+
|
|
18
|
+
function detectRepoSpdx(repoRoot: string): string {
|
|
19
|
+
const licensePath = join(repoRoot, 'LICENSE');
|
|
20
|
+
if (existsSync(licensePath)) {
|
|
21
|
+
const head = readFileSync(licensePath, 'utf8').slice(0, 200);
|
|
22
|
+
if (/Apache License/i.test(head)) {
|
|
23
|
+
return 'Apache-2.0';
|
|
24
|
+
}
|
|
25
|
+
if (/all rights reserved/i.test(head)) {
|
|
26
|
+
return 'Proprietary';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return 'Proprietary';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function banner(packageName: string, tagline: string): string {
|
|
33
|
+
return [
|
|
34
|
+
`<svg width="680" height="120" viewBox="0 0 680 120" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="${packageName}">`,
|
|
35
|
+
` <rect width="680" height="120" rx="14" fill="#0B1020"/>`,
|
|
36
|
+
` <g transform="translate(28,34)">`,
|
|
37
|
+
` <path d="M26 0 L52 15 L52 45 L26 60 L0 45 L0 15 Z" fill="${CLIENT_ACCENT}" opacity="0.18"/>`,
|
|
38
|
+
` <path d="M26 12 L41 21 L41 39 L26 48 L11 39 L11 21 Z" fill="${CLIENT_ACCENT}"/>`,
|
|
39
|
+
` </g>`,
|
|
40
|
+
` <text x="92" y="52" font-family="ui-monospace,SFMono-Regular,Menlo,monospace" font-size="22" fill="#F8FAFC" font-weight="700">${packageName}</text>`,
|
|
41
|
+
` <text x="92" y="80" font-family="ui-sans-serif,system-ui,sans-serif" font-size="15" fill="#94A3B8">${tagline}</text>`,
|
|
42
|
+
` <text x="652" y="105" text-anchor="end" font-family="ui-sans-serif,system-ui,sans-serif" font-size="12" fill="#475569">xema.dev</text>`,
|
|
43
|
+
`</svg>`,
|
|
44
|
+
].join('\n');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Write `README.md` for a generated client package. Returns nothing; always
|
|
49
|
+
* overwrites (the README is generator-owned).
|
|
50
|
+
*/
|
|
51
|
+
export function ensureClientReadme(params: {
|
|
52
|
+
clientDir: string;
|
|
53
|
+
packageName: string;
|
|
54
|
+
serviceTitle: string;
|
|
55
|
+
surface: ApiSurface;
|
|
56
|
+
repoRoot: string;
|
|
57
|
+
}): void {
|
|
58
|
+
const { clientDir, packageName, serviceTitle, surface, repoRoot } = params;
|
|
59
|
+
const enc = encodeURIComponent(packageName);
|
|
60
|
+
const spdx = detectRepoSpdx(repoRoot);
|
|
61
|
+
const surfaceWord = surface === ApiSurface.Public ? '' : `${surface} `;
|
|
62
|
+
const tagline = `Typed, generated ${surfaceWord}HTTP client for the ${serviceTitle}.`;
|
|
63
|
+
const licenseLine =
|
|
64
|
+
spdx === 'Apache-2.0'
|
|
65
|
+
? 'Apache-2.0 © Xema — [xema.dev](https://xema.dev)'
|
|
66
|
+
: 'Proprietary — © Xema. All rights reserved. — [xema.dev](https://xema.dev)';
|
|
67
|
+
|
|
68
|
+
const md = `<!-- Generated by @xemahq/api-client-generator. Do not edit by hand. -->
|
|
69
|
+
<p align="center">
|
|
70
|
+
${banner(packageName, tagline)}
|
|
71
|
+
</p>
|
|
72
|
+
|
|
73
|
+
<p align="center">
|
|
74
|
+
<a href="https://xema.dev">Website</a> ·
|
|
75
|
+
<a href="https://www.npmjs.com/package/${packageName}">npm</a>
|
|
76
|
+
</p>
|
|
77
|
+
|
|
78
|
+
<p align="center">
|
|
79
|
+
<img alt="npm" src="https://img.shields.io/npm/v/${enc}?color=2563eb&label=npm">
|
|
80
|
+
<img alt="license" src="https://img.shields.io/npm/l/${enc}?color=10b981">
|
|
81
|
+
<img alt="types" src="https://img.shields.io/npm/types/${enc}?color=3178c6">
|
|
82
|
+
</p>
|
|
83
|
+
|
|
84
|
+
# ${packageName}
|
|
85
|
+
|
|
86
|
+
> ${tagline}
|
|
87
|
+
|
|
88
|
+
## Overview
|
|
89
|
+
|
|
90
|
+
Auto-generated TypeScript client for the **${serviceTitle}**. It exports typed
|
|
91
|
+
request functions and response models that mirror the service's OpenAPI surface,
|
|
92
|
+
so callers get end-to-end type safety without hand-writing HTTP calls. This
|
|
93
|
+
package is produced by \`@xemahq/api-client-generator\` and regenerated whenever
|
|
94
|
+
the service's API changes — do not edit it by hand.
|
|
95
|
+
|
|
96
|
+
## When to use it
|
|
97
|
+
|
|
98
|
+
- Use it from any TypeScript service or app that calls the ${serviceTitle} over HTTP.
|
|
99
|
+
- You get compile-time types for every endpoint and payload; regenerate to pick
|
|
100
|
+
up API changes rather than editing the client.
|
|
101
|
+
|
|
102
|
+
## Installation
|
|
103
|
+
|
|
104
|
+
\`\`\`bash
|
|
105
|
+
pnpm add ${packageName}
|
|
106
|
+
\`\`\`
|
|
107
|
+
|
|
108
|
+
## Usage
|
|
109
|
+
|
|
110
|
+
\`\`\`ts
|
|
111
|
+
// Every endpoint function and response model is exported from the package root.
|
|
112
|
+
import * as client from '${packageName}';
|
|
113
|
+
\`\`\`
|
|
114
|
+
|
|
115
|
+
Call the typed endpoint functions; request and response shapes are fully typed
|
|
116
|
+
from the service's OpenAPI spec.
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
${licenseLine}
|
|
121
|
+
`;
|
|
122
|
+
|
|
123
|
+
writeFileSync(join(clientDir, 'README.md'), md, 'utf8');
|
|
124
|
+
}
|