@modularizer/plat 0.16.1 → 0.17.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.
Files changed (120) hide show
  1. package/README.md +28 -0
  2. package/dist/args/index.d.ts +2 -1
  3. package/dist/args/index.d.ts.map +1 -1
  4. package/dist/args/index.js +1 -0
  5. package/dist/args/index.js.map +1 -1
  6. package/dist/args/method_name.d.ts +27 -0
  7. package/dist/args/method_name.d.ts.map +1 -0
  8. package/dist/args/method_name.js +52 -0
  9. package/dist/args/method_name.js.map +1 -0
  10. package/dist/args/validate.d.ts +1 -1
  11. package/dist/args/z2.d.ts +2 -2
  12. package/dist/bridge/http-forwarder.d.ts +2 -2
  13. package/dist/bridge/index.d.ts +3 -3
  14. package/dist/cli/commands/api-proxy.d.ts.map +1 -1
  15. package/dist/cli/commands/api-proxy.js +23 -2
  16. package/dist/cli/commands/api-proxy.js.map +1 -1
  17. package/dist/cli/core.d.ts +103 -0
  18. package/dist/cli/core.d.ts.map +1 -0
  19. package/dist/cli/core.js +177 -0
  20. package/dist/cli/core.js.map +1 -0
  21. package/dist/cli/format.d.ts +13 -0
  22. package/dist/cli/format.d.ts.map +1 -0
  23. package/dist/cli/format.js +160 -0
  24. package/dist/cli/format.js.map +1 -0
  25. package/dist/cli/http.d.ts +25 -0
  26. package/dist/cli/http.d.ts.map +1 -0
  27. package/dist/cli/http.js +56 -0
  28. package/dist/cli/http.js.map +1 -0
  29. package/dist/cli/index.d.ts +10 -10
  30. package/dist/cli/proxy.d.ts +2 -2
  31. package/dist/cli/runtime.d.ts +9 -2
  32. package/dist/cli/runtime.d.ts.map +1 -1
  33. package/dist/cli/runtime.js +24 -275
  34. package/dist/cli/runtime.js.map +1 -1
  35. package/dist/cli-bin.d.ts +3 -0
  36. package/dist/cli-bin.d.ts.map +1 -0
  37. package/dist/cli-bin.js +21 -0
  38. package/dist/cli-bin.js.map +1 -0
  39. package/dist/cli-entry.d.ts +5 -0
  40. package/dist/cli-entry.d.ts.map +1 -0
  41. package/dist/cli-entry.js +6 -0
  42. package/dist/cli-entry.js.map +1 -0
  43. package/dist/client/css-transport-plugin.d.ts +4 -4
  44. package/dist/client/file-transport-plugin.d.ts +1 -1
  45. package/dist/client/http-transport-plugin.d.ts +3 -3
  46. package/dist/client/index.d.ts +6 -6
  47. package/dist/client/openapi-client.d.ts +16 -8
  48. package/dist/client/openapi-client.d.ts.map +1 -1
  49. package/dist/client/openapi-client.js +59 -24
  50. package/dist/client/openapi-client.js.map +1 -1
  51. package/dist/client/proxy.d.ts +2 -2
  52. package/dist/client/request-builder.d.ts +2 -2
  53. package/dist/client/rpc-transport-plugin.d.ts +2 -2
  54. package/dist/client/tools.d.ts +1 -1
  55. package/dist/client/transport-plugin.d.ts +4 -4
  56. package/dist/client-entry.d.ts +29 -29
  57. package/dist/client-lite-entry.d.ts +6 -0
  58. package/dist/client-lite-entry.d.ts.map +1 -0
  59. package/dist/client-lite-entry.js +8 -0
  60. package/dist/client-lite-entry.js.map +1 -0
  61. package/dist/client-server-entry.d.ts +19 -19
  62. package/dist/client-side-python/runtime.d.ts +3 -3
  63. package/dist/client-side-server/bootstrap.d.ts +1 -1
  64. package/dist/client-side-server/channel.d.ts +1 -1
  65. package/dist/client-side-server/mqtt-webrtc.d.ts +6 -6
  66. package/dist/client-side-server/mqtt-webrtc.d.ts.map +1 -1
  67. package/dist/client-side-server/mqtt-webrtc.js +11 -3
  68. package/dist/client-side-server/mqtt-webrtc.js.map +1 -1
  69. package/dist/client-side-server/plat-bridge.d.ts +1 -1
  70. package/dist/client-side-server/plat-fetch.d.ts +2 -2
  71. package/dist/client-side-server/plat-service-worker-client.d.ts +1 -1
  72. package/dist/client-side-server/plat-service-worker.d.ts +1 -1
  73. package/dist/client-side-server/protocol.d.ts +2 -2
  74. package/dist/client-side-server/runtime.d.ts +5 -5
  75. package/dist/client-side-server/server.d.ts +8 -8
  76. package/dist/client-side-server/server.js +1 -1
  77. package/dist/client-side-server/worker-pool.d.ts +3 -3
  78. package/dist/generated/python-browser-sources.js +1 -1
  79. package/dist/generated/python-browser-sources.js.map +1 -1
  80. package/dist/index.d.ts +7 -7
  81. package/dist/python-browser-entry.d.ts +1 -1
  82. package/dist/server/auth/index.d.ts +1 -1
  83. package/dist/server/auth/jwt.d.ts +1 -1
  84. package/dist/server/authority-server.d.ts +1 -1
  85. package/dist/server/cache/index.d.ts +1 -1
  86. package/dist/server/cache/utils.d.ts +1 -1
  87. package/dist/server/config/bucket.d.ts +1 -1
  88. package/dist/server/config/defaults.d.ts +1 -1
  89. package/dist/server/config/index.d.ts +4 -4
  90. package/dist/server/config/logger.d.ts +1 -1
  91. package/dist/server/config/types.d.ts +6 -6
  92. package/dist/server/core.d.ts +3 -3
  93. package/dist/server/file-queue-protocol-plugin.d.ts +2 -2
  94. package/dist/server/help.d.ts +1 -1
  95. package/dist/server/index.d.ts +17 -17
  96. package/dist/server/operation-registry.d.ts +1 -1
  97. package/dist/server/protocol-plugin.d.ts +3 -3
  98. package/dist/server/rate-limit/index.d.ts +1 -1
  99. package/dist/server/rate-limit/utils.d.ts +1 -1
  100. package/dist/server/rpc-protocol-plugin.d.ts +1 -1
  101. package/dist/server/server.d.ts +2 -2
  102. package/dist/server/server.js +1 -1
  103. package/dist/server/token-limit/index.d.ts +1 -1
  104. package/dist/server/token-limit/utils.d.ts +1 -1
  105. package/dist/server/tools.d.ts +2 -2
  106. package/dist/server/transports.d.ts +1 -1
  107. package/dist/server/webrtc-plugin.d.ts +3 -3
  108. package/dist/server/websocket-plugin.d.ts +1 -1
  109. package/dist/shared/tools.d.ts +1 -1
  110. package/dist/spec/decorators.d.ts +3 -3
  111. package/dist/spec/index.d.ts +2 -2
  112. package/dist/spec/metadata.d.ts +1 -1
  113. package/dist/static/index.d.ts +5 -5
  114. package/dist/static/plat-static-folders.d.ts +1 -1
  115. package/dist/static/static-folder.d.ts +2 -2
  116. package/dist/types/client.d.ts +3 -3
  117. package/dist/types/endpoints.d.ts +2 -2
  118. package/dist/types/errors.d.ts +1 -1
  119. package/dist/types/index.d.ts +8 -8
  120. package/package.json +5 -1
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Built-in CLI output formatters. Pure (no node-only imports besides the optional terminal width),
3
+ * so the lightweight client package can ship them.
4
+ */
5
+ export function formatJson(data) {
6
+ return JSON.stringify(data, null, 2);
7
+ }
8
+ export function formatYaml(data, indent = 0) {
9
+ const pad = ' '.repeat(indent);
10
+ if (data === null || data === undefined)
11
+ return pad + 'null';
12
+ if (typeof data === 'string')
13
+ return data.includes('\n') ? `|\n${data.split('\n').map(l => pad + ' ' + l).join('\n')}` : data;
14
+ if (typeof data !== 'object')
15
+ return String(data);
16
+ if (Array.isArray(data)) {
17
+ if (data.length === 0)
18
+ return '[]';
19
+ return data.map(item => {
20
+ if (typeof item === 'object' && item !== null && !Array.isArray(item)) {
21
+ const entries = Object.entries(item);
22
+ const first = entries[0];
23
+ const rest = entries.slice(1);
24
+ let s = pad + '- ' + first[0] + ': ' + formatYaml(first[1], indent + 2);
25
+ for (const [k, v] of rest)
26
+ s += '\n' + pad + ' ' + k + ': ' + formatYaml(v, indent + 2);
27
+ return s;
28
+ }
29
+ return pad + '- ' + formatYaml(item, indent + 1);
30
+ }).join('\n');
31
+ }
32
+ const entries = Object.entries(data);
33
+ if (entries.length === 0)
34
+ return '{}';
35
+ return entries.map(([k, v]) => {
36
+ if (typeof v === 'object' && v !== null)
37
+ return pad + k + ':\n' + formatYaml(v, indent + 1);
38
+ return pad + k + ': ' + formatYaml(v, indent);
39
+ }).join('\n');
40
+ }
41
+ export function formatHuman(data, indent = 0) {
42
+ const pad = ' '.repeat(indent);
43
+ if (data === null || data === undefined)
44
+ return pad + '\u2014';
45
+ if (typeof data !== 'object')
46
+ return pad + String(data);
47
+ if (Array.isArray(data)) {
48
+ if (data.length === 0)
49
+ return pad + '(empty)';
50
+ return data.map((item, i) => {
51
+ const prefix = pad + (i + 1) + '. ';
52
+ const body = formatHuman(item, 0).trimStart();
53
+ const contPad = ' '.repeat(prefix.length);
54
+ return prefix + body.split('\n').map((line, j) => j === 0 ? line : contPad + line).join('\n');
55
+ }).join('\n');
56
+ }
57
+ return Object.entries(data).map(([k, v]) => {
58
+ if (typeof v === 'object' && v !== null)
59
+ return pad + k + ':\n' + formatHuman(v, indent + 1);
60
+ return pad + k + ': ' + (v ?? '\u2014');
61
+ }).join('\n');
62
+ }
63
+ export function formatTable(data) {
64
+ let rows;
65
+ if (Array.isArray(data))
66
+ rows = data;
67
+ else if (typeof data === 'object' && data !== null) {
68
+ const vals = Object.values(data);
69
+ const arrVal = vals.find(v => Array.isArray(v));
70
+ if (arrVal)
71
+ rows = arrVal;
72
+ else
73
+ rows = [data];
74
+ }
75
+ else {
76
+ return String(data);
77
+ }
78
+ if (rows.length === 0)
79
+ return '(empty)';
80
+ if (typeof rows[0] !== 'object' || rows[0] === null)
81
+ return rows.map(String).join('\n');
82
+ const flatRows = rows.map(row => {
83
+ const flat = {};
84
+ for (const [k, v] of Object.entries(row)) {
85
+ flat[k] = typeof v === 'object' && v !== null ? JSON.stringify(v) : String(v ?? '');
86
+ }
87
+ return flat;
88
+ });
89
+ const cols = Array.from(new Set(flatRows.flatMap(r => Object.keys(r))));
90
+ const termWidth = process.stdout.columns || 120;
91
+ const widths = {};
92
+ for (const col of cols) {
93
+ widths[col] = col.length;
94
+ for (const row of flatRows) {
95
+ widths[col] = Math.max(widths[col], (row[col] || '').length);
96
+ }
97
+ }
98
+ const borders = 1 + cols.length * 3;
99
+ let totalWidth = borders + cols.reduce((s, c) => s + widths[c], 0);
100
+ while (totalWidth > termWidth) {
101
+ let widest = cols[0], maxW = 0;
102
+ for (const c of cols) {
103
+ if (widths[c] > maxW) {
104
+ maxW = widths[c];
105
+ widest = c;
106
+ }
107
+ }
108
+ if (maxW <= 4)
109
+ break;
110
+ widths[widest] = Math.max(4, widths[widest] - 1);
111
+ totalWidth = borders + cols.reduce((s, c) => s + widths[c], 0);
112
+ }
113
+ const truncate = (s, w) => s.length > w ? s.slice(0, w - 1) + '\u2026' : s;
114
+ const hline = (left, mid, right) => left + cols.map(c => '\u2500'.repeat(widths[c] + 2)).join(mid) + right;
115
+ const dataRow = (row) => '\u2502' + cols.map(c => ' ' + truncate(row[c] || '', widths[c]).padEnd(widths[c]) + ' ').join('\u2502') + '\u2502';
116
+ const lines = [];
117
+ lines.push(hline('\u250c', '\u252c', '\u2510'));
118
+ lines.push('\u2502' + cols.map(c => ' ' + truncate(c, widths[c]).padEnd(widths[c]) + ' ').join('\u2502') + '\u2502');
119
+ lines.push(hline('\u251c', '\u253c', '\u2524'));
120
+ for (const row of flatRows)
121
+ lines.push(dataRow(row));
122
+ lines.push(hline('\u2514', '\u2534', '\u2518'));
123
+ return lines.join('\n');
124
+ }
125
+ export function formatCsv(data) {
126
+ let rows;
127
+ if (Array.isArray(data))
128
+ rows = data;
129
+ else if (typeof data === 'object' && data !== null) {
130
+ const arrVal = Object.values(data).find(v => Array.isArray(v));
131
+ if (arrVal)
132
+ rows = arrVal;
133
+ else
134
+ rows = [data];
135
+ }
136
+ else
137
+ return String(data);
138
+ if (rows.length === 0)
139
+ return '';
140
+ if (typeof rows[0] !== 'object' || rows[0] === null)
141
+ return rows.map(String).join('\n');
142
+ const cols = Array.from(new Set(rows.flatMap(r => Object.keys(r))));
143
+ const esc = (v) => {
144
+ const s = typeof v === 'object' && v !== null ? JSON.stringify(v) : String(v ?? '');
145
+ return s.includes(',') || s.includes('"') || s.includes('\n') ? '"' + s.replace(/"/g, '""') + '"' : s;
146
+ };
147
+ const lines = [cols.join(',')];
148
+ for (const row of rows)
149
+ lines.push(cols.map(c => esc(row[c])).join(','));
150
+ return lines.join('\n');
151
+ }
152
+ /** Name → formatter. A CLI adds or replaces entries through `CliOptions.formatters`. */
153
+ export const defaultFormatters = {
154
+ json: formatJson,
155
+ yaml: (data) => formatYaml(data),
156
+ table: formatTable,
157
+ csv: formatCsv,
158
+ human: (data) => formatHuman(data),
159
+ };
160
+ //# source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AAG,IAAI,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;IACxE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC;AAID,wFAAwF;AACxF,MAAM,CAAC,MAAM,iBAAiB,GAAiC;IAC7D,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;IAChC,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE,SAAS;IACd,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC;CACnC,CAAA"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Dependency-free HTTP transport for the CLI engine: plain `fetch`, nothing else.
3
+ * This is what the lightweight `@modularizer/plat-cli` package ships.
4
+ */
5
+ import { type CliCall, type CliOptions } from './core.js';
6
+ export interface HttpCallOptions {
7
+ baseUrl: string | (() => string | Promise<string>);
8
+ headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
9
+ fetch?: typeof fetch;
10
+ }
11
+ /** Where the OpenAPI document lives on a plat server. */
12
+ export declare function fetchSpec(baseUrl: string, fetchImpl?: typeof fetch): Promise<any>;
13
+ /** `{id}` path params come from the input; GET/DELETE send the rest as a query string, others as JSON. */
14
+ export declare function httpCall(options: HttpCallOptions): CliCall;
15
+ export interface HttpCliOptions extends Omit<CliOptions, 'spec' | 'call'> {
16
+ baseUrl: HttpCallOptions['baseUrl'];
17
+ headers?: HttpCallOptions['headers'];
18
+ /** Default: fetch `/openapi.json` from `baseUrl`. */
19
+ spec?: CliOptions['spec'];
20
+ call?: CliOptions['call'];
21
+ fetch?: typeof fetch;
22
+ }
23
+ /** Run a CLI against a plat server over plain HTTP. */
24
+ export declare function runHttpCli(options: HttpCliOptions, argv?: readonly string[]): Promise<void>;
25
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/cli/http.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAc,KAAK,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAA;AAElE,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;IAClD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;IACnG,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CACrB;AAED,yDAAyD;AACzD,wBAAsB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,OAAO,KAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CAI9F;AAED,0GAA0G;AAC1G,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CA0B1D;AAED,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;IACvE,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,CAAA;IACnC,OAAO,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,CAAA;IACpC,qDAAqD;IACrD,IAAI,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;IACzB,IAAI,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;IACzB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CACrB;AAED,uDAAuD;AACvD,wBAAsB,UAAU,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,GAAE,SAAS,MAAM,EAA0B,GAAG,OAAO,CAAC,IAAI,CAAC,CAOxH"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Dependency-free HTTP transport for the CLI engine: plain `fetch`, nothing else.
3
+ * This is what the lightweight `@modularizer/plat-cli` package ships.
4
+ */
5
+ import { runCliCore } from './core.js';
6
+ /** Where the OpenAPI document lives on a plat server. */
7
+ export async function fetchSpec(baseUrl, fetchImpl = fetch) {
8
+ const res = await fetchImpl(new URL('/openapi.json', baseUrl));
9
+ if (!res.ok)
10
+ throw new Error(`Could not load ${new URL('/openapi.json', baseUrl)}: HTTP ${res.status}`);
11
+ return res.json();
12
+ }
13
+ /** `{id}` path params come from the input; GET/DELETE send the rest as a query string, others as JSON. */
14
+ export function httpCall(options) {
15
+ return async (command, input) => {
16
+ const baseUrl = typeof options.baseUrl === 'function' ? await options.baseUrl() : options.baseUrl;
17
+ const extra = typeof options.headers === 'function' ? await options.headers() : options.headers;
18
+ const rest = { ...input };
19
+ const path = command.path.replace(/\{(\w+)\}/g, (_, key) => {
20
+ const value = rest[key];
21
+ delete rest[key];
22
+ return encodeURIComponent(String(value ?? ''));
23
+ });
24
+ const url = new URL(path, baseUrl);
25
+ const hasBody = command.method !== 'GET' && command.method !== 'DELETE' && command.method !== 'HEAD';
26
+ if (!hasBody) {
27
+ for (const [key, value] of Object.entries(rest)) {
28
+ url.searchParams.set(key, typeof value === 'object' ? JSON.stringify(value) : String(value));
29
+ }
30
+ }
31
+ const res = await (options.fetch ?? fetch)(url, {
32
+ method: command.method,
33
+ headers: { ...(hasBody ? { 'content-type': 'application/json' } : {}), ...extra },
34
+ ...(hasBody ? { body: JSON.stringify(rest) } : {}),
35
+ });
36
+ const text = await res.text();
37
+ if (!res.ok)
38
+ throw new Error(`${command.name}: HTTP ${res.status} ${text}`);
39
+ try {
40
+ return JSON.parse(text);
41
+ }
42
+ catch {
43
+ return text;
44
+ }
45
+ };
46
+ }
47
+ /** Run a CLI against a plat server over plain HTTP. */
48
+ export async function runHttpCli(options, argv = process.argv.slice(2)) {
49
+ const { baseUrl, headers, fetch: fetchImpl, spec, call, ...core } = options;
50
+ await runCliCore({
51
+ ...core,
52
+ spec: spec ?? (async () => fetchSpec(typeof baseUrl === 'function' ? await baseUrl() : baseUrl, fetchImpl)),
53
+ call: call ?? httpCall({ baseUrl, headers, fetch: fetchImpl }),
54
+ }, argv);
55
+ }
56
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/cli/http.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAiC,MAAM,QAAQ,CAAA;AAQlE,yDAAyD;AACzD,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,OAAe,EAAE,YAA0B,KAAK;IAC9E,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,IAAI,GAAG,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAA;IAC9D,IAAI,CAAC,GAAG,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,IAAI,GAAG,CAAC,eAAe,EAAE,OAAO,CAAC,UAAU,GAAG,CAAC,MAAM,EAAE,CAAC,CAAA;IACvG,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;AACnB,CAAC;AAED,0GAA0G;AAC1G,MAAM,UAAU,QAAQ,CAAC,OAAwB;IAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;QAC9B,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAA;QACjG,MAAM,KAAK,GAAG,OAAO,OAAO,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAA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AE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACnD,CAAC,CAAA;QACF,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAA;QAC7B,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,UAAU,GAAG,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC,CAAA;QAC3E,IAAI,CAAC;YAAC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;QAAC,MAAM,CAAC;YAAC,OAAO,IAAI,CAAA;QAAC,CAAC;IACvD,CAAC,CAAA;AACH,CAAC;AAWD,uDAAuD;AACvD,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAuB,EAAE,OAA0B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACvG,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAA;IAC3E,MAAM,UAAU,CAAC;QACf,GAAG,IAAI;QACP,IAAI,EAAE,IAAI,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,SAAS,CAAC,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC3G,IAAI,EAAE,IAAI,IAAI,QAAQ,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;KAC/D,EAAE,IAAI,CAAC,CAAA;AACV,CAAC"}
@@ -1,11 +1,11 @@
1
- export * from './runtime';
2
- export * from './proxy';
3
- export * from './jwt-helper';
4
- export * from './commands/env';
5
- export * from './commands/gen';
6
- export * from './commands/api-proxy';
7
- export * from './commands/jwt-cmd';
8
- export * from './commands/init-project';
9
- export * from './commands/watch';
10
- export * from './commands/run';
1
+ export * from './runtime.js';
2
+ export * from './proxy.js';
3
+ export * from './jwt-helper.js';
4
+ export * from './commands/env.js';
5
+ export * from './commands/gen.js';
6
+ export * from './commands/api-proxy.js';
7
+ export * from './commands/jwt-cmd.js';
8
+ export * from './commands/init-project.js';
9
+ export * from './commands/watch.js';
10
+ export * from './commands/run.js';
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
- import type { Clientified } from '../types/client';
2
- import type { EndpointDef, HttpMethod } from '../types';
1
+ import type { Clientified } from '../types/client.js';
2
+ import type { EndpointDef, HttpMethod } from '../types/index.js';
3
3
  type ApiClass<T> = abstract new (...args: any[]) => T;
4
4
  export interface CliAuthContext {
5
5
  controllerName: string;
@@ -4,14 +4,21 @@
4
4
  * Generated CLIs just pass in their spec — all arg parsing,
5
5
  * formatting, and dispatch lives here.
6
6
  */
7
- import { type OpenAPIClientConfig } from '../client/openapi-client';
8
- export interface RunCliOptions {
7
+ import { type OpenAPIClientConfig } from '../client/openapi-client.js';
8
+ import { type CliOptions } from './core.js';
9
+ export interface RunCliOptions extends Partial<Omit<CliOptions, 'spec' | 'call'>> {
9
10
  /** Override base URL (default: spec.servers[0].url or env) */
10
11
  baseUrl?: string;
11
12
  /** Extra headers to send */
12
13
  headers?: Record<string, string>;
13
14
  /** OpenAPIClient config overrides */
14
15
  clientConfig?: Partial<OpenAPIClientConfig>;
16
+ /** Replace the default OpenAPIClient transport. */
17
+ call?: CliOptions['call'];
15
18
  }
19
+ /**
20
+ * Run a CLI for `spec`. Every behaviour a CLI might want to change is an option (see `CliOptions`):
21
+ * extra commands, overrides, positional params, hooks, formatters, help. Do not hand-roll a CLI.
22
+ */
16
23
  export declare function runCli(spec: any, argvOrOptions?: string[] | RunCliOptions, maybeOptions?: RunCliOptions): Promise<void>;
17
24
  //# sourceMappingURL=runtime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/cli/runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAiB,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAclF,MAAM,WAAW,aAAa;IAC5B,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,qCAAqC;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAA;CAC5C;AA2MD,wBAAsB,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,YAAY,CAAC,EAAE,aAAa,iBA4D7G"}
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/cli/runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAiB,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAGlF,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAA;AAIpD,MAAM,WAAW,aAAc,SAAQ,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAC/E,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,qCAAqC;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAA;IAC3C,mDAAmD;IACnD,IAAI,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;CAC1B;AAED;;;GAGG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,YAAY,CAAC,EAAE,aAAa,iBAyB7G"}
@@ -7,284 +7,33 @@
7
7
  import { OpenAPIClient } from '../client/openapi-client.js';
8
8
  import { createClientSideServerMQTTWebRTCTransportPlugin } from '../client-side-server/mqtt-webrtc.js';
9
9
  import { PLAT_AUTHORITY_URL } from '../client-side-server/authority-default.js';
10
- // ── extract commands from spec ─────────────────────────────
11
- function extractCommands(spec) {
12
- const commands = [];
13
- for (const [urlPath, methods] of Object.entries(spec.paths ?? {})) {
14
- for (const [httpMethod, _op] of Object.entries(methods)) {
15
- const op = _op;
16
- if (!op.operationId)
17
- continue;
18
- const params = [];
19
- if (op.parameters) {
20
- for (const p of op.parameters) {
21
- params.push({ name: p.name, required: p.required ?? false });
22
- }
23
- }
24
- if (op.requestBody?.content?.['application/json']?.schema?.properties) {
25
- const schema = op.requestBody.content['application/json'].schema;
26
- const reqSet = new Set(schema.required ?? []);
27
- for (const name of Object.keys(schema.properties)) {
28
- params.push({ name, required: reqSet.has(name) });
29
- }
30
- }
31
- commands.push({
32
- name: op.operationId,
33
- method: httpMethod.toUpperCase(),
34
- path: urlPath,
35
- summary: op.summary,
36
- params,
37
- });
38
- }
39
- }
40
- return commands;
41
- }
42
- // ── arg parser ─────────────────────────────────────────────
43
- function parseArgs(argv) {
44
- const input = {};
45
- let format = 'json';
46
- for (const arg of argv) {
47
- const m = arg.match(/^--([\w-]+)=(.*)$/) || arg.match(/^--([\w-]+)$/);
48
- if (!m)
49
- continue;
50
- if (m[1] === 'format') {
51
- format = m[2] ?? 'json';
52
- continue;
53
- }
54
- const key = m[1].replace(/-([a-z])/g, (_, c) => c.toUpperCase());
55
- let val = m[2] ?? true;
56
- if (val === 'true')
57
- val = true;
58
- else if (val === 'false')
59
- val = false;
60
- else if (typeof val === 'string' && /^-?\d+(\.\d+)?$/.test(val))
61
- val = Number(val);
62
- else if (typeof val === 'string' && (val.startsWith('{') || val.startsWith('['))) {
63
- try {
64
- val = JSON.parse(val);
65
- }
66
- catch { }
67
- }
68
- input[key] = val;
69
- }
70
- return { input, format };
71
- }
72
- // ── formatters ─────────────────────────────────────────────
73
- function formatJson(data) {
74
- return JSON.stringify(data, null, 2);
75
- }
76
- function formatYaml(data, indent = 0) {
77
- const pad = ' '.repeat(indent);
78
- if (data === null || data === undefined)
79
- return pad + 'null';
80
- if (typeof data === 'string')
81
- return data.includes('\n') ? `|\n${data.split('\n').map(l => pad + ' ' + l).join('\n')}` : data;
82
- if (typeof data !== 'object')
83
- return String(data);
84
- if (Array.isArray(data)) {
85
- if (data.length === 0)
86
- return '[]';
87
- return data.map(item => {
88
- if (typeof item === 'object' && item !== null && !Array.isArray(item)) {
89
- const entries = Object.entries(item);
90
- const first = entries[0];
91
- const rest = entries.slice(1);
92
- let s = pad + '- ' + first[0] + ': ' + formatYaml(first[1], indent + 2);
93
- for (const [k, v] of rest)
94
- s += '\n' + pad + ' ' + k + ': ' + formatYaml(v, indent + 2);
95
- return s;
96
- }
97
- return pad + '- ' + formatYaml(item, indent + 1);
98
- }).join('\n');
99
- }
100
- const entries = Object.entries(data);
101
- if (entries.length === 0)
102
- return '{}';
103
- return entries.map(([k, v]) => {
104
- if (typeof v === 'object' && v !== null)
105
- return pad + k + ':\n' + formatYaml(v, indent + 1);
106
- return pad + k + ': ' + formatYaml(v, indent);
107
- }).join('\n');
108
- }
109
- function formatHuman(data, indent = 0) {
110
- const pad = ' '.repeat(indent);
111
- if (data === null || data === undefined)
112
- return pad + '\u2014';
113
- if (typeof data !== 'object')
114
- return pad + String(data);
115
- if (Array.isArray(data)) {
116
- if (data.length === 0)
117
- return pad + '(empty)';
118
- return data.map((item, i) => {
119
- const prefix = pad + (i + 1) + '. ';
120
- const body = formatHuman(item, 0).trimStart();
121
- const contPad = ' '.repeat(prefix.length);
122
- return prefix + body.split('\n').map((line, j) => j === 0 ? line : contPad + line).join('\n');
123
- }).join('\n');
124
- }
125
- return Object.entries(data).map(([k, v]) => {
126
- if (typeof v === 'object' && v !== null)
127
- return pad + k + ':\n' + formatHuman(v, indent + 1);
128
- return pad + k + ': ' + (v ?? '\u2014');
129
- }).join('\n');
130
- }
131
- function formatTable(data) {
132
- let rows;
133
- if (Array.isArray(data))
134
- rows = data;
135
- else if (typeof data === 'object' && data !== null) {
136
- const vals = Object.values(data);
137
- const arrVal = vals.find(v => Array.isArray(v));
138
- if (arrVal)
139
- rows = arrVal;
140
- else
141
- rows = [data];
142
- }
143
- else {
144
- return String(data);
145
- }
146
- if (rows.length === 0)
147
- return '(empty)';
148
- if (typeof rows[0] !== 'object' || rows[0] === null)
149
- return rows.map(String).join('\n');
150
- const flatRows = rows.map(row => {
151
- const flat = {};
152
- for (const [k, v] of Object.entries(row)) {
153
- flat[k] = typeof v === 'object' && v !== null ? JSON.stringify(v) : String(v ?? '');
154
- }
155
- return flat;
156
- });
157
- const cols = Array.from(new Set(flatRows.flatMap(r => Object.keys(r))));
158
- const termWidth = process.stdout.columns || 120;
159
- const widths = {};
160
- for (const col of cols) {
161
- widths[col] = col.length;
162
- for (const row of flatRows) {
163
- widths[col] = Math.max(widths[col], (row[col] || '').length);
164
- }
165
- }
166
- const borders = 1 + cols.length * 3;
167
- let totalWidth = borders + cols.reduce((s, c) => s + widths[c], 0);
168
- while (totalWidth > termWidth) {
169
- let widest = cols[0], maxW = 0;
170
- for (const c of cols) {
171
- if (widths[c] > maxW) {
172
- maxW = widths[c];
173
- widest = c;
174
- }
175
- }
176
- if (maxW <= 4)
177
- break;
178
- widths[widest] = Math.max(4, widths[widest] - 1);
179
- totalWidth = borders + cols.reduce((s, c) => s + widths[c], 0);
180
- }
181
- const truncate = (s, w) => s.length > w ? s.slice(0, w - 1) + '\u2026' : s;
182
- const hline = (left, mid, right) => left + cols.map(c => '\u2500'.repeat(widths[c] + 2)).join(mid) + right;
183
- const dataRow = (row) => '\u2502' + cols.map(c => ' ' + truncate(row[c] || '', widths[c]).padEnd(widths[c]) + ' ').join('\u2502') + '\u2502';
184
- const lines = [];
185
- lines.push(hline('\u250c', '\u252c', '\u2510'));
186
- lines.push('\u2502' + cols.map(c => ' ' + truncate(c, widths[c]).padEnd(widths[c]) + ' ').join('\u2502') + '\u2502');
187
- lines.push(hline('\u251c', '\u253c', '\u2524'));
188
- for (const row of flatRows)
189
- lines.push(dataRow(row));
190
- lines.push(hline('\u2514', '\u2534', '\u2518'));
191
- return lines.join('\n');
192
- }
193
- function formatCsv(data) {
194
- let rows;
195
- if (Array.isArray(data))
196
- rows = data;
197
- else if (typeof data === 'object' && data !== null) {
198
- const arrVal = Object.values(data).find(v => Array.isArray(v));
199
- if (arrVal)
200
- rows = arrVal;
201
- else
202
- rows = [data];
203
- }
204
- else
205
- return String(data);
206
- if (rows.length === 0)
207
- return '';
208
- if (typeof rows[0] !== 'object' || rows[0] === null)
209
- return rows.map(String).join('\n');
210
- const cols = Array.from(new Set(rows.flatMap(r => Object.keys(r))));
211
- const esc = (v) => {
212
- const s = typeof v === 'object' && v !== null ? JSON.stringify(v) : String(v ?? '');
213
- return s.includes(',') || s.includes('"') || s.includes('\n') ? '"' + s.replace(/"/g, '""') + '"' : s;
214
- };
215
- const lines = [cols.join(',')];
216
- for (const row of rows)
217
- lines.push(cols.map(c => esc(row[c])).join(','));
218
- return lines.join('\n');
219
- }
220
- function output(data, format) {
221
- switch (format) {
222
- case 'yaml':
223
- console.log(formatYaml(data));
224
- break;
225
- case 'table':
226
- console.log(formatTable(data));
227
- break;
228
- case 'csv':
229
- console.log(formatCsv(data));
230
- break;
231
- case 'human':
232
- console.log(formatHuman(data));
233
- break;
234
- default: console.log(formatJson(data));
235
- }
236
- }
237
- // ── main entry point ───────────────────────────────────────
10
+ import { runCliCore } from './core.js';
11
+ /**
12
+ * Run a CLI for `spec`. Every behaviour a CLI might want to change is an option (see `CliOptions`):
13
+ * extra commands, overrides, positional params, hooks, formatters, help. Do not hand-roll a CLI.
14
+ */
238
15
  export async function runCli(spec, argvOrOptions, maybeOptions) {
239
16
  const argv = Array.isArray(argvOrOptions) ? argvOrOptions : process.argv.slice(2);
240
- const options = Array.isArray(argvOrOptions) ? maybeOptions : argvOrOptions;
241
- const commands = extractCommands(spec);
242
- const [command, ...rest] = argv;
243
- if (!command || command === 'help' || command === '--help') {
244
- const title = spec.info?.title ?? 'API';
245
- console.log(`${title} CLI\n`);
246
- console.log('Usage: <command> [--key=value ...] [--format=json|yaml|table|csv|human]\n');
247
- console.log('Commands:');
248
- for (const cmd of commands) {
249
- const params = cmd.params.map(p => p.required ? `--${p.name}` : `[--${p.name}]`).join(' ');
250
- const summary = cmd.summary ? ` \u2014 ${cmd.summary}` : '';
251
- console.log(` ${cmd.name.padEnd(30)} ${params}${summary}`);
17
+ const options = (Array.isArray(argvOrOptions) ? maybeOptions : argvOrOptions) ?? {};
18
+ const { baseUrl: baseUrlOption, headers, clientConfig: clientOverrides, call, ...core } = options;
19
+ let client;
20
+ const defaultCall = async (command, input) => {
21
+ if (!client) {
22
+ const baseUrl = baseUrlOption ?? spec.servers?.[0]?.url ?? PLAT_AUTHORITY_URL;
23
+ const token = process.env.API_TOKEN;
24
+ const clientConfig = { ...clientOverrides };
25
+ if (baseUrl.startsWith('css://') && !clientConfig.transportPlugins?.length) {
26
+ clientConfig.transportPlugins = [createClientSideServerMQTTWebRTCTransportPlugin()];
27
+ }
28
+ client = new OpenAPIClient(spec, {
29
+ baseUrl,
30
+ headers: { ...headers, ...(token ? { authorization: `Bearer ${token}` } : {}) },
31
+ ...clientConfig,
32
+ });
252
33
  }
253
- process.exit(0);
254
- }
255
- const matched = commands.find(c => c.name === command);
256
- if (!matched) {
257
- console.error(`Unknown command: ${command}. Run with --help for available commands.`);
258
- process.exit(1);
259
- }
260
- const baseUrl = options?.baseUrl
261
- ?? spec.servers?.[0]?.url
262
- ?? PLAT_AUTHORITY_URL;
263
- const token = process.env.API_TOKEN;
264
- const clientConfig = {
265
- ...options?.clientConfig,
34
+ const method = command.method.toLowerCase();
35
+ return client[method](command.path, input);
266
36
  };
267
- if (baseUrl.startsWith('css://')
268
- && !clientConfig.transportPlugins?.length) {
269
- clientConfig.transportPlugins = [createClientSideServerMQTTWebRTCTransportPlugin()];
270
- }
271
- const client = new OpenAPIClient(spec, {
272
- baseUrl,
273
- headers: {
274
- ...options?.headers,
275
- ...(token ? { authorization: `Bearer ${token}` } : {}),
276
- },
277
- ...clientConfig,
278
- });
279
- const { input, format } = parseArgs(rest);
280
- try {
281
- const method = matched.method.toLowerCase();
282
- const result = await client[method](matched.path, input);
283
- output(result, format);
284
- }
285
- catch (err) {
286
- console.error(err.message);
287
- process.exit(1);
288
- }
37
+ await runCliCore({ ...core, spec, call: call ?? defaultCall }, argv);
289
38
  }
290
39
  //# sourceMappingURL=runtime.js.map