@corpdk/codegen-cli 2026.10.0-alpha.13 → 2026.10.0-alpha.14
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/index.d.ts +0 -2
- package/dist/index.js +93 -59
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,5 @@ import type { Types } from "@graphql-codegen/plugin-helpers";
|
|
|
2
2
|
export interface Config {
|
|
3
3
|
/** Name of the env var that holds the HTTP endpoint. Default: DS_HTTP_URL */
|
|
4
4
|
httpUrlEnvVar?: string;
|
|
5
|
-
/** Name of the env var that holds the WebSocket endpoint. Default: DS_WS_URL */
|
|
6
|
-
wsUrlEnvVar?: string;
|
|
7
5
|
}
|
|
8
6
|
export declare const preset: Types.OutputPreset<Config>;
|
package/dist/index.js
CHANGED
|
@@ -169,7 +169,6 @@ var RUNTIME_LINES = [
|
|
|
169
169
|
"",
|
|
170
170
|
String.raw` h += "Environment:\n";`,
|
|
171
171
|
String.raw` h += " DS_HTTP_URL " + DS_HTTP_URL + "\n";`,
|
|
172
|
-
String.raw` h += " DS_WS_URL " + DS_WS_URL + "\n";`,
|
|
173
172
|
"",
|
|
174
173
|
" process.stdout.write(h);",
|
|
175
174
|
"}",
|
|
@@ -202,58 +201,101 @@ var RUNTIME_LINES = [
|
|
|
202
201
|
" return json;",
|
|
203
202
|
"}",
|
|
204
203
|
"",
|
|
205
|
-
"function executeSubscription(document, variables, opts) {",
|
|
204
|
+
"async function executeSubscription(document, variables, opts) {",
|
|
206
205
|
" const { count, timeout } = opts;",
|
|
207
|
-
"
|
|
208
|
-
"
|
|
209
|
-
"
|
|
210
|
-
' ws = new WebSocket(DS_WS_URL, "graphql-transport-ws");',
|
|
211
|
-
" } catch (err) {",
|
|
212
|
-
' reject(new Error("WebSocket connection failed: " + err.message));',
|
|
213
|
-
" return;",
|
|
214
|
-
" }",
|
|
215
|
-
" let received = 0;",
|
|
216
|
-
" let done = false;",
|
|
206
|
+
" let received = 0;",
|
|
207
|
+
" let done = false;",
|
|
208
|
+
" let reader;",
|
|
217
209
|
"",
|
|
218
|
-
"
|
|
219
|
-
"
|
|
220
|
-
"
|
|
221
|
-
"
|
|
222
|
-
"
|
|
223
|
-
" }",
|
|
210
|
+
" function finish() {",
|
|
211
|
+
" if (done) return;",
|
|
212
|
+
" done = true;",
|
|
213
|
+
" try { reader?.cancel?.(); } catch (_) {}",
|
|
214
|
+
" }",
|
|
224
215
|
"",
|
|
225
|
-
"
|
|
226
|
-
|
|
227
|
-
"
|
|
216
|
+
" let res;",
|
|
217
|
+
" try {",
|
|
218
|
+
" res = await fetch(DS_HTTP_URL, {",
|
|
219
|
+
' method: "POST",',
|
|
220
|
+
" headers: {",
|
|
221
|
+
' "Content-Type": "application/json",',
|
|
222
|
+
' Accept: "text/event-stream",',
|
|
223
|
+
" },",
|
|
224
|
+
" body: JSON.stringify({ query: document, variables }),",
|
|
225
|
+
" });",
|
|
226
|
+
" } catch (err) {",
|
|
227
|
+
String.raw` process.stderr.write("Connection failed: " + err.message + "\n");`,
|
|
228
|
+
" process.exit(1);",
|
|
229
|
+
" }",
|
|
228
230
|
"",
|
|
229
|
-
"
|
|
230
|
-
"
|
|
231
|
-
"
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
"
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
"
|
|
238
|
-
" if (count !== undefined && received >= count) finish();",
|
|
239
|
-
' } else if (msg.type === "error") {',
|
|
240
|
-
String.raw` process.stderr.write(JSON.stringify(msg.payload) + "\n");`,
|
|
241
|
-
" finish();",
|
|
242
|
-
' } else if (msg.type === "complete") {',
|
|
243
|
-
" finish();",
|
|
244
|
-
" }",
|
|
245
|
-
" };",
|
|
231
|
+
" if (!res.ok) {",
|
|
232
|
+
String.raw` process.stderr.write("HTTP " + res.status + " " + res.statusText + "\\n");`,
|
|
233
|
+
" process.exit(1);",
|
|
234
|
+
" }",
|
|
235
|
+
"",
|
|
236
|
+
" if (!res.body) {",
|
|
237
|
+
String.raw` process.stderr.write("No response body (streaming not supported)\\n");`,
|
|
238
|
+
" process.exit(1);",
|
|
239
|
+
" }",
|
|
246
240
|
"",
|
|
247
|
-
"
|
|
248
|
-
'
|
|
249
|
-
"
|
|
250
|
-
|
|
241
|
+
" function flushSseBlock(block) {",
|
|
242
|
+
' let eventName = "";',
|
|
243
|
+
" const dataParts = [];",
|
|
244
|
+
' for (const line of block.split("\\n")) {',
|
|
245
|
+
" if (!line) continue;",
|
|
246
|
+
' if (line.startsWith("event:")) eventName = line.slice(6).trim();',
|
|
247
|
+
' else if (line.startsWith("data:")) dataParts.push(line.slice(5).trimStart());',
|
|
248
|
+
" }",
|
|
249
|
+
' const raw = dataParts.join("\\n");',
|
|
250
|
+
" if (!raw) return;",
|
|
251
|
+
' if (eventName === "complete") { finish(); return; }',
|
|
252
|
+
' if (eventName && eventName !== "next") return;',
|
|
253
|
+
" let payload;",
|
|
254
|
+
" try { payload = JSON.parse(raw); }",
|
|
255
|
+
" catch { return; }",
|
|
256
|
+
" if (payload.errors) {",
|
|
257
|
+
String.raw` process.stderr.write(JSON.stringify(payload.errors, null, 2) + "\\n");`,
|
|
258
|
+
" finish();",
|
|
259
|
+
" process.exit(1);",
|
|
260
|
+
" }",
|
|
261
|
+
String.raw` process.stdout.write(JSON.stringify(payload) + "\\n");`,
|
|
262
|
+
" received++;",
|
|
263
|
+
" if (count !== undefined && received >= count) finish();",
|
|
264
|
+
" }",
|
|
251
265
|
"",
|
|
252
|
-
"
|
|
266
|
+
" reader = res.body.getReader();",
|
|
267
|
+
" const decoder = new TextDecoder();",
|
|
268
|
+
' let buffer = "";',
|
|
269
|
+
" let timeoutId;",
|
|
270
|
+
" const onSig = () => finish();",
|
|
271
|
+
' process.on("SIGINT", onSig);',
|
|
272
|
+
' process.on("SIGTERM", onSig);',
|
|
273
|
+
" if (timeout !== undefined) timeoutId = setTimeout(finish, timeout);",
|
|
253
274
|
"",
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
"
|
|
275
|
+
" try {",
|
|
276
|
+
" for (;;) {",
|
|
277
|
+
" const { value, done: streamEnded } = await reader.read();",
|
|
278
|
+
" if (value) buffer += decoder.decode(value, { stream: true });",
|
|
279
|
+
" let sep;",
|
|
280
|
+
' while ((sep = buffer.indexOf("\\n\\n")) !== -1) {',
|
|
281
|
+
" const block = buffer.slice(0, sep);",
|
|
282
|
+
" buffer = buffer.slice(sep + 2);",
|
|
283
|
+
" flushSseBlock(block);",
|
|
284
|
+
" if (done) return;",
|
|
285
|
+
" }",
|
|
286
|
+
" if (streamEnded) break;",
|
|
287
|
+
" }",
|
|
288
|
+
" buffer += decoder.decode();",
|
|
289
|
+
" if (buffer.trim()) flushSseBlock(buffer);",
|
|
290
|
+
" } catch (err) {",
|
|
291
|
+
String.raw` if (!done) process.stderr.write(err.message + "\\n");`,
|
|
292
|
+
" process.exit(1);",
|
|
293
|
+
" } finally {",
|
|
294
|
+
" if (timeoutId !== undefined) clearTimeout(timeoutId);",
|
|
295
|
+
' process.off("SIGINT", onSig);',
|
|
296
|
+
' process.off("SIGTERM", onSig);',
|
|
297
|
+
" try { reader.releaseLock(); } catch (_) {}",
|
|
298
|
+
" }",
|
|
257
299
|
"}",
|
|
258
300
|
"",
|
|
259
301
|
"async function readInputVars(inputFile) {",
|
|
@@ -349,19 +391,17 @@ var RUNTIME_LINES = [
|
|
|
349
391
|
];
|
|
350
392
|
function generateCli(ops, config) {
|
|
351
393
|
const httpEnvVar = config.httpUrlEnvVar ?? "DS_HTTP_URL";
|
|
352
|
-
const wsEnvVar = config.wsUrlEnvVar ?? "DS_WS_URL";
|
|
353
394
|
const header = [
|
|
354
395
|
"#!/usr/bin/env node",
|
|
355
396
|
"// @generated \u2014 do not edit manually",
|
|
356
397
|
"// Regenerate by running: pnpm codegen (in your DS package)",
|
|
357
|
-
"// Requires Node
|
|
398
|
+
"// Requires Node 18+ (fetch, ReadableStream)",
|
|
358
399
|
"",
|
|
359
400
|
'import { parseArgs } from "node:util";',
|
|
360
401
|
'import { readFileSync } from "node:fs";',
|
|
361
402
|
'import { basename } from "node:path";',
|
|
362
403
|
"",
|
|
363
404
|
`const DS_HTTP_URL = process.env.${httpEnvVar} ?? "http://localhost:4000/graphql";`,
|
|
364
|
-
`const DS_WS_URL = process.env.${wsEnvVar} ?? "ws://localhost:4000/graphql";`,
|
|
365
405
|
""
|
|
366
406
|
].join("\n");
|
|
367
407
|
const footer = [
|
|
@@ -464,10 +504,7 @@ function generateMan(ops) {
|
|
|
464
504
|
".SH ENVIRONMENT",
|
|
465
505
|
".TP",
|
|
466
506
|
".B DS_HTTP_URL",
|
|
467
|
-
"GraphQL HTTP endpoint. Default: http://localhost:4000/graphql",
|
|
468
|
-
".TP",
|
|
469
|
-
".B DS_WS_URL",
|
|
470
|
-
"GraphQL WebSocket endpoint. Default: ws://localhost:4000/graphql",
|
|
507
|
+
"GraphQL HTTP endpoint (queries, mutations, subscriptions over SSE). Default: http://localhost:4000/graphql",
|
|
471
508
|
"",
|
|
472
509
|
".SH EXIT STATUS",
|
|
473
510
|
".TP",
|
|
@@ -478,7 +515,7 @@ function generateMan(ops) {
|
|
|
478
515
|
"GraphQL error, connection failure, or invalid arguments.",
|
|
479
516
|
"",
|
|
480
517
|
".SH NOTES",
|
|
481
|
-
"Requires Node.js 18+ (fetch
|
|
518
|
+
"Requires Node.js 18+ (fetch, TextDecoder, ReadableStream).",
|
|
482
519
|
String.raw`This file is auto\-generated. Run`,
|
|
483
520
|
".B pnpm codegen",
|
|
484
521
|
"in your DS package to regenerate."
|
|
@@ -615,16 +652,13 @@ function generateInfo(ops) {
|
|
|
615
652
|
"",
|
|
616
653
|
"@table @env",
|
|
617
654
|
"@item DS_HTTP_URL",
|
|
618
|
-
"GraphQL HTTP endpoint. Default: @code{http://localhost:4000/graphql}",
|
|
619
|
-
"@item DS_WS_URL",
|
|
620
|
-
"GraphQL WebSocket endpoint. Default: @code{ws://localhost:4000/graphql}",
|
|
655
|
+
"GraphQL HTTP endpoint (queries, mutations, subscriptions via SSE). Default: @code{http://localhost:4000/graphql}",
|
|
621
656
|
"@end table",
|
|
622
657
|
"",
|
|
623
658
|
"@node Requirements",
|
|
624
659
|
"@chapter Requirements",
|
|
625
660
|
"",
|
|
626
|
-
"Requires Node.js 18 or later (
|
|
627
|
-
"WebSocket subscriptions require Node.js 22 or later.",
|
|
661
|
+
"Requires Node.js 18 or later (@code{fetch}, @code{TextDecoder}, readable streams).",
|
|
628
662
|
"",
|
|
629
663
|
"@bye"
|
|
630
664
|
].join("\n");
|
package/package.json
CHANGED