buildgql 0.1.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.
@@ -0,0 +1,93 @@
1
+ import { O as Operation, H as HasVars } from '../operation-DxbEION8.cjs';
2
+
3
+ /** Headers, or a function producing them — evaluated per request so tokens can refresh. */
4
+ type HeadersSource = HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
5
+
6
+ interface GraphQLFormattedError {
7
+ readonly message: string;
8
+ readonly path?: readonly (string | number)[];
9
+ readonly locations?: readonly {
10
+ line: number;
11
+ column: number;
12
+ }[];
13
+ readonly extensions?: Record<string, unknown>;
14
+ }
15
+ /**
16
+ * Base class for every error buildgql throws from the client. Exists so consumers can
17
+ * write one `catch (e) { if (e instanceof BuildGQLError) ... }` instead of enumerating
18
+ * subclasses — and so adding a subclass later does not break that check.
19
+ *
20
+ * That `instanceof` holds for an error obtained from `buildgql` and one thrown through
21
+ * `buildgql/client`, in ESM and in CJS alike: both entries reach a single copy of this
22
+ * class through a shared chunk (`splitting: true` in `tsup.config.ts`), pinned by
23
+ * `test/built/interop.test.ts`.
24
+ *
25
+ * It cannot hold across a consumer that loads BOTH the ESM and the CJS build of this
26
+ * package — two module instances, two class objects, and `instanceof` is false between
27
+ * them. That is inherent to dual publishing rather than a defect here, and no packaging
28
+ * change can close it; a consumer in that position must compare `error.name` instead.
29
+ */
30
+ declare abstract class BuildGQLError extends Error {
31
+ }
32
+ /** The server answered 2xx but the payload contained `errors`. */
33
+ declare class BuildGQLResponseError extends BuildGQLError {
34
+ readonly errors: readonly GraphQLFormattedError[];
35
+ readonly data: unknown;
36
+ constructor(errors: readonly GraphQLFormattedError[], data: unknown);
37
+ }
38
+ /** The transport failed — non-2xx status or an unparseable body. */
39
+ declare class BuildGQLHttpError extends BuildGQLError {
40
+ readonly status: number;
41
+ readonly body: string;
42
+ constructor(status: number, body: string);
43
+ }
44
+
45
+ interface SubscribePayload {
46
+ readonly query: string;
47
+ readonly operationName: string;
48
+ readonly variables: Record<string, unknown>;
49
+ }
50
+ interface StreamChunk {
51
+ readonly data?: unknown;
52
+ readonly errors?: readonly GraphQLFormattedError[];
53
+ }
54
+ interface SubscriptionTransport {
55
+ /** `headers` carries per-subscription headers from `client.subscribe(op, vars, { headers })`. */
56
+ subscribe(payload: SubscribePayload, signal: AbortSignal, headers?: HeadersInit): AsyncIterable<StreamChunk>;
57
+ }
58
+
59
+ interface ClientOptions {
60
+ readonly url: string;
61
+ readonly headers?: HeadersSource;
62
+ readonly fetch?: typeof fetch;
63
+ readonly subscriptions?: SubscriptionTransport;
64
+ }
65
+ interface ExecuteOptions {
66
+ readonly signal?: AbortSignal;
67
+ readonly headers?: HeadersInit;
68
+ }
69
+ type VarArgs<V> = HasVars<V> extends true ? [vars: NoInfer<V>, opts?: ExecuteOptions] : [vars?: NoInfer<V>, opts?: ExecuteOptions];
70
+ interface Client {
71
+ execute<R, V>(op: Operation<R, V>, ...rest: VarArgs<V>): Promise<R>;
72
+ subscribe<R, V>(op: Operation<R, V>, ...rest: VarArgs<V>): AsyncIterable<R>;
73
+ readonly options: ClientOptions;
74
+ }
75
+ declare function createClient(options: ClientOptions): Client;
76
+
77
+ interface SseTransportOptions {
78
+ readonly url: string;
79
+ readonly headers?: HeadersSource;
80
+ readonly fetch?: typeof fetch;
81
+ }
82
+ /** graphql-sse "distinct connections mode": one POST per subscription. */
83
+ declare function sseTransport(opts: SseTransportOptions): SubscriptionTransport;
84
+
85
+ interface WsTransportOptions {
86
+ readonly url: string;
87
+ readonly connectionParams?: Record<string, unknown> | (() => Record<string, unknown> | Promise<Record<string, unknown>>);
88
+ readonly WebSocket?: typeof WebSocket;
89
+ }
90
+ /** graphql-ws protocol: connection_init -> subscribe -> next* -> complete. */
91
+ declare function wsTransport(opts: WsTransportOptions): SubscriptionTransport;
92
+
93
+ export { BuildGQLError, BuildGQLHttpError, BuildGQLResponseError, type Client, type ClientOptions, type ExecuteOptions, type GraphQLFormattedError, type HeadersSource, type SseTransportOptions, type StreamChunk, type SubscribePayload, type SubscriptionTransport, type WsTransportOptions, createClient, sseTransport, wsTransport };
@@ -0,0 +1,93 @@
1
+ import { O as Operation, H as HasVars } from '../operation-DxbEION8.js';
2
+
3
+ /** Headers, or a function producing them — evaluated per request so tokens can refresh. */
4
+ type HeadersSource = HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
5
+
6
+ interface GraphQLFormattedError {
7
+ readonly message: string;
8
+ readonly path?: readonly (string | number)[];
9
+ readonly locations?: readonly {
10
+ line: number;
11
+ column: number;
12
+ }[];
13
+ readonly extensions?: Record<string, unknown>;
14
+ }
15
+ /**
16
+ * Base class for every error buildgql throws from the client. Exists so consumers can
17
+ * write one `catch (e) { if (e instanceof BuildGQLError) ... }` instead of enumerating
18
+ * subclasses — and so adding a subclass later does not break that check.
19
+ *
20
+ * That `instanceof` holds for an error obtained from `buildgql` and one thrown through
21
+ * `buildgql/client`, in ESM and in CJS alike: both entries reach a single copy of this
22
+ * class through a shared chunk (`splitting: true` in `tsup.config.ts`), pinned by
23
+ * `test/built/interop.test.ts`.
24
+ *
25
+ * It cannot hold across a consumer that loads BOTH the ESM and the CJS build of this
26
+ * package — two module instances, two class objects, and `instanceof` is false between
27
+ * them. That is inherent to dual publishing rather than a defect here, and no packaging
28
+ * change can close it; a consumer in that position must compare `error.name` instead.
29
+ */
30
+ declare abstract class BuildGQLError extends Error {
31
+ }
32
+ /** The server answered 2xx but the payload contained `errors`. */
33
+ declare class BuildGQLResponseError extends BuildGQLError {
34
+ readonly errors: readonly GraphQLFormattedError[];
35
+ readonly data: unknown;
36
+ constructor(errors: readonly GraphQLFormattedError[], data: unknown);
37
+ }
38
+ /** The transport failed — non-2xx status or an unparseable body. */
39
+ declare class BuildGQLHttpError extends BuildGQLError {
40
+ readonly status: number;
41
+ readonly body: string;
42
+ constructor(status: number, body: string);
43
+ }
44
+
45
+ interface SubscribePayload {
46
+ readonly query: string;
47
+ readonly operationName: string;
48
+ readonly variables: Record<string, unknown>;
49
+ }
50
+ interface StreamChunk {
51
+ readonly data?: unknown;
52
+ readonly errors?: readonly GraphQLFormattedError[];
53
+ }
54
+ interface SubscriptionTransport {
55
+ /** `headers` carries per-subscription headers from `client.subscribe(op, vars, { headers })`. */
56
+ subscribe(payload: SubscribePayload, signal: AbortSignal, headers?: HeadersInit): AsyncIterable<StreamChunk>;
57
+ }
58
+
59
+ interface ClientOptions {
60
+ readonly url: string;
61
+ readonly headers?: HeadersSource;
62
+ readonly fetch?: typeof fetch;
63
+ readonly subscriptions?: SubscriptionTransport;
64
+ }
65
+ interface ExecuteOptions {
66
+ readonly signal?: AbortSignal;
67
+ readonly headers?: HeadersInit;
68
+ }
69
+ type VarArgs<V> = HasVars<V> extends true ? [vars: NoInfer<V>, opts?: ExecuteOptions] : [vars?: NoInfer<V>, opts?: ExecuteOptions];
70
+ interface Client {
71
+ execute<R, V>(op: Operation<R, V>, ...rest: VarArgs<V>): Promise<R>;
72
+ subscribe<R, V>(op: Operation<R, V>, ...rest: VarArgs<V>): AsyncIterable<R>;
73
+ readonly options: ClientOptions;
74
+ }
75
+ declare function createClient(options: ClientOptions): Client;
76
+
77
+ interface SseTransportOptions {
78
+ readonly url: string;
79
+ readonly headers?: HeadersSource;
80
+ readonly fetch?: typeof fetch;
81
+ }
82
+ /** graphql-sse "distinct connections mode": one POST per subscription. */
83
+ declare function sseTransport(opts: SseTransportOptions): SubscriptionTransport;
84
+
85
+ interface WsTransportOptions {
86
+ readonly url: string;
87
+ readonly connectionParams?: Record<string, unknown> | (() => Record<string, unknown> | Promise<Record<string, unknown>>);
88
+ readonly WebSocket?: typeof WebSocket;
89
+ }
90
+ /** graphql-ws protocol: connection_init -> subscribe -> next* -> complete. */
91
+ declare function wsTransport(opts: WsTransportOptions): SubscriptionTransport;
92
+
93
+ export { BuildGQLError, BuildGQLHttpError, BuildGQLResponseError, type Client, type ClientOptions, type ExecuteOptions, type GraphQLFormattedError, type HeadersSource, type SseTransportOptions, type StreamChunk, type SubscribePayload, type SubscriptionTransport, type WsTransportOptions, createClient, sseTransport, wsTransport };
@@ -0,0 +1,16 @@
1
+ import {
2
+ BuildGQLError,
3
+ BuildGQLHttpError,
4
+ BuildGQLResponseError,
5
+ createClient,
6
+ sseTransport,
7
+ wsTransport
8
+ } from "../chunk-RSDTCILU.js";
9
+ export {
10
+ BuildGQLError,
11
+ BuildGQLHttpError,
12
+ BuildGQLResponseError,
13
+ createClient,
14
+ sseTransport,
15
+ wsTransport
16
+ };
@@ -0,0 +1,16 @@
1
+ import { DocumentNode } from 'graphql';
2
+
3
+ /**
4
+ * A `DocumentNode` carrying its result and variable types as a phantom property.
5
+ *
6
+ * Declared here rather than imported from `@graphql-typed-document-node/core` so that
7
+ * neither buildgql nor its consumers take on that dependency: Apollo Client and urql read
8
+ * `__apiType` structurally, and TypeScript's structural typing makes this interface
9
+ * interchangeable with theirs. `test/types/adapters.test-d.ts` pins that interop against
10
+ * the real package.
11
+ */
12
+ interface TypedDocumentNode<R, V> extends DocumentNode {
13
+ __apiType?: (variables: V) => R;
14
+ }
15
+
16
+ export type { TypedDocumentNode as T };
@@ -0,0 +1,16 @@
1
+ import { DocumentNode } from 'graphql';
2
+
3
+ /**
4
+ * A `DocumentNode` carrying its result and variable types as a phantom property.
5
+ *
6
+ * Declared here rather than imported from `@graphql-typed-document-node/core` so that
7
+ * neither buildgql nor its consumers take on that dependency: Apollo Client and urql read
8
+ * `__apiType` structurally, and TypeScript's structural typing makes this interface
9
+ * interchangeable with theirs. `test/types/adapters.test-d.ts` pins that interop against
10
+ * the real package.
11
+ */
12
+ interface TypedDocumentNode<R, V> extends DocumentNode {
13
+ __apiType?: (variables: V) => R;
14
+ }
15
+
16
+ export type { TypedDocumentNode as T };
package/dist/index.cjs ADDED
@@ -0,0 +1,313 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+
6
+
7
+
8
+ var _chunk2Z2AKLA3cjs = require('./chunk-2Z2AKLA3.cjs');
9
+
10
+ // src/runtime/markers.ts
11
+ var VAR = /* @__PURE__ */ Symbol.for("buildgql.var");
12
+ var ENUM = /* @__PURE__ */ Symbol.for("buildgql.enum");
13
+ var VAR_REF = /* @__PURE__ */ Symbol.for("buildgql.varRef");
14
+ function makeVarMarker(name) {
15
+ return { [VAR]: true, __var: name };
16
+ }
17
+ function isVarMarker(x) {
18
+ return typeof x === "object" && x !== null && x[VAR] === true;
19
+ }
20
+ function markerName(m) {
21
+ return m.__var;
22
+ }
23
+ function enumValue(value) {
24
+ return { [ENUM]: value };
25
+ }
26
+ function isEnumValue(x) {
27
+ return typeof x === "object" && x !== null && typeof x[ENUM] === "string";
28
+ }
29
+ function varRefValue(name) {
30
+ return { [VAR_REF]: name };
31
+ }
32
+ function isVarRefValue(x) {
33
+ return typeof x === "object" && x !== null && typeof x[VAR_REF] === "string";
34
+ }
35
+
36
+ // src/runtime/builders.ts
37
+ function argSpec(gql, enums) {
38
+ return enums && enums.length > 0 ? { gql, enums } : { gql };
39
+ }
40
+ function markEnums(value) {
41
+ if (Array.isArray(value)) return value.map(markEnums);
42
+ return typeof value === "string" ? enumValue(value) : value;
43
+ }
44
+ function splitArgs(argv, spec) {
45
+ const literals = {};
46
+ const varRefs = [];
47
+ for (const [key, value] of Object.entries(argv)) {
48
+ if (isVarMarker(value)) {
49
+ const explicit = markerName(value);
50
+ const varName = _nullishCoalesce(explicit, () => ( key));
51
+ const gqlType = spec.gql[key];
52
+ if (gqlType === void 0) {
53
+ throw new Error(`buildgql: unknown argument "${key}" (no GraphQL type recorded for it)`);
54
+ }
55
+ varRefs.push({ varName, gqlType });
56
+ literals[key] = varRefValue(varName);
57
+ } else {
58
+ literals[key] = _optionalChain([spec, 'access', _ => _.enums, 'optionalAccess', _2 => _2.includes, 'call', _3 => _3(key)]) ? markEnums(value) : value;
59
+ }
60
+ }
61
+ return { literals, varRefs };
62
+ }
63
+ function makeFieldNode(name, alias, argv, sels, varRefs) {
64
+ return { kind: "field", name, alias, args: argv, sels, varRefs };
65
+ }
66
+ function leafField(name, _wrap) {
67
+ const base = makeFieldNode(name, void 0, void 0, void 0, []);
68
+ return Object.assign(base, {
69
+ as(alias) {
70
+ return makeFieldNode(name, alias, void 0, void 0, []);
71
+ }
72
+ });
73
+ }
74
+ function leafFieldArgs(name, _wrap, spec) {
75
+ const make = (alias) => (argv) => {
76
+ const { literals, varRefs } = splitArgs(argv, spec);
77
+ return makeFieldNode(name, alias, literals, void 0, varRefs);
78
+ };
79
+ return Object.assign(make(void 0), {
80
+ as(alias) {
81
+ return make(alias);
82
+ }
83
+ });
84
+ }
85
+ function objectField(name, _wrap, fields) {
86
+ const make = (alias) => (pick) => {
87
+ const sels = pick(fields);
88
+ return makeFieldNode(name, alias, void 0, sels, []);
89
+ };
90
+ return Object.assign(make(void 0), {
91
+ as(alias) {
92
+ return make(alias);
93
+ }
94
+ });
95
+ }
96
+ function objectFieldArgs(name, _wrap, fields, spec) {
97
+ const make = (alias) => (argv, pick) => {
98
+ const { literals, varRefs } = splitArgs(argv, spec);
99
+ const sels = pick(fields);
100
+ return makeFieldNode(name, alias, literals, sels, varRefs);
101
+ };
102
+ return Object.assign(make(void 0), {
103
+ as(alias) {
104
+ return make(alias);
105
+ }
106
+ });
107
+ }
108
+
109
+ // src/runtime/var.ts
110
+ var $ = new Proxy({}, {
111
+ get() {
112
+ return makeVarMarker(null);
113
+ }
114
+ });
115
+ function v(name) {
116
+ return makeVarMarker(name);
117
+ }
118
+
119
+ // src/runtime/directives.ts
120
+ function applyDirective(sel, name, cond) {
121
+ let directive;
122
+ if (typeof cond === "boolean") {
123
+ directive = { name, if: cond };
124
+ } else {
125
+ if (!isVarMarker(cond)) {
126
+ throw new Error(`buildgql: @${name} condition must be a boolean or a variable from v()`);
127
+ }
128
+ const varName = markerName(cond);
129
+ if (varName === null) {
130
+ throw new Error(
131
+ `buildgql: @${name} needs an explicitly named variable \u2014 use v('flagName'), not $.flagName. Directive conditions have no argument key to take their name from.`
132
+ );
133
+ }
134
+ directive = { name, if: { varName, gqlType: "Boolean!" } };
135
+ }
136
+ const next = { ...sel, directives: [..._nullishCoalesce(sel.directives, () => ( [])), directive] };
137
+ return next;
138
+ }
139
+ function include(sel, cond) {
140
+ return applyDirective(sel, "include", cond);
141
+ }
142
+ function skip(sel, cond) {
143
+ return applyDirective(sel, "skip", cond);
144
+ }
145
+
146
+ // src/runtime/fragment.ts
147
+ function makeFragment(typeCondition, fields) {
148
+ return (name, pick) => ({ name, typeCondition, sels: pick(fields) });
149
+ }
150
+ function spread(f) {
151
+ return { kind: "spread", fragment: f };
152
+ }
153
+ function collectFragments(sels) {
154
+ const found = /* @__PURE__ */ new Map();
155
+ const walk = (nodes) => {
156
+ for (const n of nodes) {
157
+ if (n.kind === "spread") {
158
+ const seen = found.get(n.fragment.name);
159
+ if (seen && seen !== n.fragment) {
160
+ throw new Error(
161
+ `buildgql: two different fragments are both named "${n.fragment.name}". Fragment names must be unique \u2014 give one of them a different name.`
162
+ );
163
+ }
164
+ if (!seen) {
165
+ found.set(n.fragment.name, n.fragment);
166
+ walk(n.fragment.sels);
167
+ }
168
+ continue;
169
+ }
170
+ if (n.kind === "on") {
171
+ walk(n.sels);
172
+ continue;
173
+ }
174
+ const sel = n;
175
+ if (sel.sels) walk(sel.sels);
176
+ }
177
+ };
178
+ walk(sels);
179
+ return [...found.values()];
180
+ }
181
+
182
+ // src/runtime/on.ts
183
+ function on(typename, fields, pick) {
184
+ return { kind: "on", typename, sels: pick(fields) };
185
+ }
186
+
187
+ // src/runtime/print.ts
188
+ function printValue(value) {
189
+ if (isVarRefValue(value)) return `$${value[VAR_REF]}`;
190
+ if (value === null || value === void 0) return "null";
191
+ if (isEnumValue(value)) return value[ENUM];
192
+ if (typeof value === "string") return JSON.stringify(value);
193
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
194
+ if (Array.isArray(value)) return `[${value.map(printValue).join(", ")}]`;
195
+ if (typeof value === "object") {
196
+ const entries = Object.entries(value).filter(([, v2]) => v2 !== void 0).map(([k, v2]) => `${k}: ${printValue(v2)}`);
197
+ return `{${entries.join(", ")}}`;
198
+ }
199
+ throw new Error(`buildgql: cannot serialise argument value of type ${typeof value}`);
200
+ }
201
+ function printArgs(argv) {
202
+ if (!argv) return "";
203
+ const entries = Object.entries(argv).filter(([, v2]) => v2 !== void 0);
204
+ if (entries.length === 0) return "";
205
+ return `(${entries.map(([k, v2]) => `${k}: ${printValue(v2)}`).join(", ")})`;
206
+ }
207
+ function printDirectives(ds) {
208
+ if (!ds || ds.length === 0) return "";
209
+ return ds.map((d) => {
210
+ const cond = typeof d.if === "boolean" ? String(d.if) : `$${d.if.varName}`;
211
+ return ` @${d.name}(if: ${cond})`;
212
+ }).join("");
213
+ }
214
+ function printNode(n) {
215
+ if (n.kind === "spread") return `...${n.fragment.name}`;
216
+ if (n.kind === "on") {
217
+ const o = n;
218
+ return `... on ${o.typename} ${printSels(o.sels)}`;
219
+ }
220
+ const s = n;
221
+ const head = s.alias ? `${s.alias}: ${s.name}` : s.name;
222
+ const body = s.sels && s.sels.length > 0 ? ` ${printSels(s.sels)}` : "";
223
+ return `${head}${printArgs(s.args)}${printDirectives(s.directives)}${body}`;
224
+ }
225
+ function printSels(sels) {
226
+ const hasInline = sels.some((n) => n.kind === "on");
227
+ const hasTypename = sels.some((n) => n.kind === "field" && n.name === "__typename");
228
+ const parts = sels.map(printNode);
229
+ if (hasInline && !hasTypename) parts.unshift("__typename");
230
+ return `{ ${parts.join(" ")} }`;
231
+ }
232
+ function collectVarRefs(sels) {
233
+ const out = [];
234
+ const walk = (nodes) => {
235
+ for (const n of nodes) {
236
+ if (n.kind === "on") {
237
+ walk(n.sels);
238
+ continue;
239
+ }
240
+ if (n.kind === "spread") {
241
+ walk(n.fragment.sels);
242
+ continue;
243
+ }
244
+ const s = n;
245
+ if (s.varRefs) out.push(...s.varRefs);
246
+ for (const d of _nullishCoalesce(s.directives, () => ( []))) {
247
+ if (typeof d.if !== "boolean") out.push(d.if);
248
+ }
249
+ if (s.sels) walk(s.sels);
250
+ }
251
+ };
252
+ walk(sels);
253
+ return out;
254
+ }
255
+ function dedupeVarRefs(refs) {
256
+ const byName = /* @__PURE__ */ new Map();
257
+ for (const ref of refs) {
258
+ const seen = byName.get(ref.varName);
259
+ if (seen && seen.gqlType !== ref.gqlType) {
260
+ throw new Error(
261
+ `buildgql: variable $${ref.varName} is used with two different types (${seen.gqlType} and ${ref.gqlType}). Give one of them an explicit name with v('otherName').`
262
+ );
263
+ }
264
+ if (!seen) byName.set(ref.varName, ref);
265
+ }
266
+ return [...byName.values()];
267
+ }
268
+ function printOperation(kind, name, sels, fragments = []) {
269
+ const vars = dedupeVarRefs(collectVarRefs(sels));
270
+ const sig = vars.length > 0 ? `(${vars.map((v2) => `$${v2.varName}: ${v2.gqlType}`).join(", ")})` : "";
271
+ const op = `${kind} ${name}${sig} ${printSels(sels)}`;
272
+ const frags = fragments.map((f) => `fragment ${f.name} on ${f.typeCondition} ${printSels(f.sels)}`);
273
+ return [op, ...frags].join(" ");
274
+ }
275
+
276
+ // src/runtime/operation.ts
277
+ function makeOperation(kind) {
278
+ return (root) => (name, build) => {
279
+ const sels = build($, root);
280
+ const document = printOperation(kind, name, sels, collectFragments(sels));
281
+ return { kind, name, document, sels };
282
+ };
283
+ }
284
+ var makeQuery = makeOperation("query");
285
+ var makeMutation = makeOperation("mutation");
286
+ var makeSubscription = makeOperation("subscription");
287
+
288
+ // src/index.ts
289
+ var VERSION = "0.1.0";
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+
312
+
313
+ exports.$ = $; exports.BuildGQLError = _chunk2Z2AKLA3cjs.BuildGQLError; exports.BuildGQLHttpError = _chunk2Z2AKLA3cjs.BuildGQLHttpError; exports.BuildGQLResponseError = _chunk2Z2AKLA3cjs.BuildGQLResponseError; exports.VERSION = VERSION; exports.argSpec = argSpec; exports.createClient = _chunk2Z2AKLA3cjs.createClient; exports.include = include; exports.leafField = leafField; exports.leafFieldArgs = leafFieldArgs; exports.makeFragment = makeFragment; exports.makeMutation = makeMutation; exports.makeQuery = makeQuery; exports.makeSubscription = makeSubscription; exports.objectField = objectField; exports.objectFieldArgs = objectFieldArgs; exports.on = on; exports.skip = skip; exports.spread = spread; exports.sseTransport = _chunk2Z2AKLA3cjs.sseTransport; exports.v = v; exports.wsTransport = _chunk2Z2AKLA3cjs.wsTransport;
@@ -0,0 +1,85 @@
1
+ export { BuildGQLError, BuildGQLHttpError, BuildGQLResponseError, Client, ClientOptions, ExecuteOptions, GraphQLFormattedError, HeadersSource, SseTransportOptions, StreamChunk, SubscribePayload, SubscriptionTransport, WsTransportOptions, createClient, sseTransport, wsTransport } from './client/index.cjs';
2
+ import { N as NonNull, A as ArgSpec, F as FieldSelection, a as ArgsInput, b as VarsOf, S as SelectionNode, c as Selected, d as VarsIn, e as VarMarker, f as FragmentDefinition, R as RESULT, g as VARS, h as FragmentSpread, I as InlineFragment, i as Simplify, j as VarProxy } from './operation-DxbEION8.cjs';
3
+ export { k as AnyFieldSelection, l as Arg, D as Directive, K as KEY, O as Operation, U as UnionToIntersection, m as VarRef, n as makeMutation, o as makeQuery, p as makeSubscription } from './operation-DxbEION8.cjs';
4
+
5
+ type WrapTok = 'l' | '!';
6
+ /** Outer-to-inner wrapper tuple. `[]` means "nullable named type". */
7
+ type Wrap = readonly WrapTok[];
8
+ type Apply<W extends Wrap, T> = W extends readonly ['!', ...infer R] ? R extends Wrap ? NonNull<Apply<R, T>> : never : W extends readonly ['l', ...infer R] ? R extends Wrap ? Apply<R, T>[] | null : never : T | null;
9
+
10
+ /** Declares a field's argument types (compile time) and GraphQL types (runtime). */
11
+ declare function argSpec<T>(gql: Readonly<Record<string, string>>, enums?: readonly string[]): ArgSpec<T>;
12
+ /**
13
+ * PHANTOM CASTS IN THIS FILE
14
+ *
15
+ * Every `as unknown as` below is a phantom-type attachment. The value produced by
16
+ * `makeFieldNode(...)` (or by `make(alias)`) is already the complete runtime value;
17
+ * the cast exists only to stamp type parameters — `N`/`AL`, `Apply<W, T>`,
18
+ * `VarsOf<A, Spec>`, `VarsIn<S>` — that have no runtime representation at all.
19
+ * None of them can be derived structurally from the runtime value.
20
+ */
21
+ /** A scalar or enum field. `W` MUST be a `const` parameter or wrappers degrade. */
22
+ declare function leafField<N extends string, const W extends Wrap, T>(name: N, _wrap: W): FieldSelection<N, Apply<W, T>> & {
23
+ as<A extends string>(alias: A): FieldSelection<A, Apply<W, T>>;
24
+ };
25
+ /** A scalar or enum field that takes arguments. */
26
+ declare function leafFieldArgs<N extends string, const W extends Wrap, T, Spec>(name: N, _wrap: W, spec: ArgSpec<Spec>): (<A extends ArgsInput<Spec>>(argv: A) => FieldSelection<N, Apply<W, T>, VarsOf<A, Spec>>) & {
27
+ as<AL extends string>(alias: AL): <A extends ArgsInput<Spec>>(argv: A) => FieldSelection<AL, Apply<W, T>, VarsOf<A, Spec>>;
28
+ };
29
+ /** An object/interface/union field. `F` is the child field map from codegen. */
30
+ declare function objectField<N extends string, const W extends Wrap, F>(name: N, _wrap: W, fields: F): (<S extends readonly SelectionNode[]>(pick: (f: F) => readonly [...S]) => FieldSelection<N, Apply<W, Selected<S>>, VarsIn<S>>) & {
31
+ as<AL extends string>(alias: AL): <S extends readonly SelectionNode[]>(pick: (f: F) => readonly [...S]) => FieldSelection<AL, Apply<W, Selected<S>>, VarsIn<S>>;
32
+ };
33
+ /** An object field that takes arguments. */
34
+ declare function objectFieldArgs<N extends string, const W extends Wrap, F, Spec>(name: N, _wrap: W, fields: F, spec: ArgSpec<Spec>): (<A extends ArgsInput<Spec>, S extends readonly SelectionNode[]>(argv: A, pick: (f: F) => readonly [...S]) => FieldSelection<N, Apply<W, Selected<S>>, VarsIn<S> & VarsOf<A, Spec>>) & {
35
+ as<AL extends string>(alias: AL): <A extends ArgsInput<Spec>, S extends readonly SelectionNode[]>(argv: A, pick: (f: F) => readonly [...S]) => FieldSelection<AL, Apply<W, Selected<S>>, VarsIn<S> & VarsOf<A, Spec>>;
36
+ };
37
+
38
+ /**
39
+ * `include`/`skip` MUST be overloaded, not declared with a single
40
+ * `cond: boolean | VarMarker<Name>` parameter. With the union form, a literal
41
+ * `true` leaves `Name` unconstrained, so TypeScript falls back to its constraint
42
+ * and infers `Name = string`. `{ [P in string]: boolean }` is an *index
43
+ * signature*, which then intersects into the operation's variables type and makes
44
+ * the whole operation untypeable by its caller.
45
+ */
46
+ declare function include<N extends string, R, V>(sel: FieldSelection<N, R, V, boolean>, cond: boolean): FieldSelection<N, R, V, true>;
47
+ declare function include<N extends string, R, V, Name extends string>(sel: FieldSelection<N, R, V, boolean>, cond: VarMarker<Name>): FieldSelection<N, R, V & {
48
+ [P in Name]: boolean;
49
+ }, true>;
50
+ declare function skip<N extends string, R, V>(sel: FieldSelection<N, R, V, boolean>, cond: boolean): FieldSelection<N, R, V, true>;
51
+ declare function skip<N extends string, R, V, Name extends string>(sel: FieldSelection<N, R, V, boolean>, cond: VarMarker<Name>): FieldSelection<N, R, V & {
52
+ [P in Name]: boolean;
53
+ }, true>;
54
+
55
+ interface Fragment<R, V> extends FragmentDefinition {
56
+ readonly [RESULT]?: R;
57
+ readonly [VARS]?: V;
58
+ }
59
+ /** Codegen emits one of these per object type so the type condition is fixed. */
60
+ declare function makeFragment<F>(typeCondition: string, fields: F): <S extends readonly SelectionNode[]>(name: string, pick: (f: F) => readonly [...S]) => Fragment<Selected<S>, VarsIn<S>>;
61
+ declare function spread<R, V>(f: Fragment<R, V>): FragmentSpread<R, V>;
62
+
63
+ /**
64
+ * Narrow a union or interface field to a concrete type.
65
+ * `__typename` is injected into the result type of every branch so the union
66
+ * discriminates; the printer adds the matching field to the document.
67
+ */
68
+ declare function on<TN extends string, F, S extends readonly SelectionNode[]>(typename: TN, fields: F, pick: (f: F) => readonly [...S]): InlineFragment<TN, Simplify<Selected<S> & {
69
+ __typename: TN;
70
+ }>, VarsIn<S>>;
71
+
72
+ /**
73
+ * Placeholder proxy. The accessed key is deliberately ignored: a mapped type
74
+ * over `string` cannot preserve it, so the type system names the variable after
75
+ * the *argument key* instead. Recording `null` here keeps runtime and types in
76
+ * agreement — see `splitArgs` in builders.ts.
77
+ */
78
+ declare const $: VarProxy;
79
+ /** Explicitly name a variable — use when two fields would collide on an arg key. */
80
+ declare function v<N extends string>(name: N): VarMarker<N>;
81
+
82
+ /** Kept in step with package.json by `test/unit/public-api.test.ts`. */
83
+ declare const VERSION = "0.1.0";
84
+
85
+ export { $, type Apply, ArgSpec, ArgsInput, FieldSelection, type Fragment, FragmentDefinition, FragmentSpread, InlineFragment, NonNull, RESULT, Selected, SelectionNode, Simplify, VARS, VERSION, VarMarker, VarProxy, VarsIn, VarsOf, type Wrap, type WrapTok, argSpec, include, leafField, leafFieldArgs, makeFragment, objectField, objectFieldArgs, on, skip, spread, v };