@m1212e/rumble 0.12.16 → 0.12.18
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/out/index.cjs +76 -4
- package/out/index.cjs.map +1 -1
- package/out/index.d.cts +12 -10
- package/out/index.d.cts.map +1 -1
- package/out/index.d.mts +12 -10
- package/out/index.d.mts.map +1 -1
- package/out/index.mjs +76 -5
- package/out/index.mjs.map +1 -1
- package/package.json +3 -1
package/out/index.cjs
CHANGED
|
@@ -23,6 +23,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
//#endregion
|
|
24
24
|
let node_fs_promises = require("node:fs/promises");
|
|
25
25
|
let node_path = require("node:path");
|
|
26
|
+
let __urql_introspection = require("@urql/introspection");
|
|
27
|
+
let devalue = require("devalue");
|
|
26
28
|
let graphql = require("graphql");
|
|
27
29
|
let es_toolkit = require("es-toolkit");
|
|
28
30
|
let wonka = require("wonka");
|
|
@@ -46,20 +48,21 @@ __pothos_plugin_smart_subscriptions = __toESM(__pothos_plugin_smart_subscription
|
|
|
46
48
|
let graphql_scalars = require("graphql-scalars");
|
|
47
49
|
|
|
48
50
|
//#region lib/client/generate/client.ts
|
|
49
|
-
function generateClient({ apiUrl, rumbleImportPath, useExternalUrqlClient, availableSubscriptions }) {
|
|
51
|
+
function generateClient({ apiUrl, rumbleImportPath, useExternalUrqlClient, availableSubscriptions, schema }) {
|
|
50
52
|
const imports = [];
|
|
51
53
|
let code = "";
|
|
52
54
|
if (typeof useExternalUrqlClient === "string") imports.push(`import { urqlClient } from "${useExternalUrqlClient}";`);
|
|
53
55
|
else {
|
|
54
56
|
imports.push(`import { Client, fetchExchange } from '@urql/core';`);
|
|
55
57
|
imports.push(`import { cacheExchange } from '@urql/exchange-graphcache';`);
|
|
58
|
+
imports.push(`import { nativeDateExchange } from '${rumbleImportPath}';`);
|
|
56
59
|
}
|
|
57
60
|
imports.push(`import { makeLiveQuery, makeMutation, makeSubscription, makeQuery } from '${rumbleImportPath}';`);
|
|
58
61
|
if (!useExternalUrqlClient) code += `
|
|
59
62
|
const urqlClient = new Client({
|
|
60
63
|
url: "${apiUrl ?? "PLEASE PROVIDE A URL WHEN GENERATING OR IMPORT AN EXTERNAL URQL CLIENT"}",
|
|
61
64
|
fetchSubscriptions: true,
|
|
62
|
-
exchanges: [cacheExchange({}), fetchExchange],
|
|
65
|
+
exchanges: [cacheExchange({ schema: ${schema ? (0, devalue.uneval)((0, __urql_introspection.minifyIntrospectionQuery)((0, __urql_introspection.getIntrospectedSchema)(schema))) : "undefined"} }), nativeDateExchange, fetchExchange],
|
|
63
66
|
fetchOptions: {
|
|
64
67
|
credentials: "include",
|
|
65
68
|
},
|
|
@@ -227,6 +230,7 @@ export type ${key} = ${rep};
|
|
|
227
230
|
}
|
|
228
231
|
const c = generateClient({
|
|
229
232
|
apiUrl,
|
|
233
|
+
schema,
|
|
230
234
|
useExternalUrqlClient,
|
|
231
235
|
rumbleImportPath,
|
|
232
236
|
availableSubscriptions: new Set(Object.keys(schema.getSubscriptionType()?.getFields() || {}))
|
|
@@ -241,8 +245,8 @@ export type ${key} = ${rep};
|
|
|
241
245
|
const argsKey = "__args";
|
|
242
246
|
function makeGraphQLQuery({ queryName, input, client, enableSubscription = false }) {
|
|
243
247
|
const otwQueryName = `${(0, es_toolkit.capitalize)(queryName)}Query`;
|
|
244
|
-
const argsString = stringifyArgumentObjectToGraphqlList(input[argsKey] ?? {});
|
|
245
|
-
const operationString = (operationVerb) => `${operationVerb} ${otwQueryName} { ${queryName}${argsString} { ${stringifySelection(input)} }}`;
|
|
248
|
+
const argsString = stringifyArgumentObjectToGraphqlList(input?.[argsKey] ?? {});
|
|
249
|
+
const operationString = (operationVerb) => `${operationVerb} ${otwQueryName} { ${queryName}${argsString} ${input ? `{ ${stringifySelection(input)} }` : ""}}`;
|
|
246
250
|
let awaitedReturnValueReference;
|
|
247
251
|
const observable = (0, wonka.pipe)((0, wonka.merge)([client.query(operationString("query"), {}), enableSubscription ? client.subscription(operationString("subscription"), {}) : wonka.empty]), (0, wonka.map)((v) => {
|
|
248
252
|
const data = v.data?.[queryName];
|
|
@@ -349,6 +353,73 @@ function makeMutation({ urqlClient }) {
|
|
|
349
353
|
} });
|
|
350
354
|
}
|
|
351
355
|
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region lib/helpers/deepMap.ts
|
|
358
|
+
/**
|
|
359
|
+
* Recursively applies a mapping function to every value in a nested structure.
|
|
360
|
+
*
|
|
361
|
+
* This helper will traverse arrays and plain objects (objects with `constructor === Object`)
|
|
362
|
+
* and apply the provided `fn` to any value that is not an array or a plain object.
|
|
363
|
+
* - Arrays are mapped to new arrays (a fresh array is returned).
|
|
364
|
+
* - Plain objects are traversed and their own enumerable properties are replaced in-place.
|
|
365
|
+
* - Non-plain objects (e.g. Date, Map, Set, class instances, functions) are treated as leaves
|
|
366
|
+
* and passed directly to `fn`.
|
|
367
|
+
* - `null` and `undefined` are passed to `fn`.
|
|
368
|
+
* - Circular references are detected using a `WeakSet`. When a circular reference is encountered,
|
|
369
|
+
* the original reference is returned unchanged (it is not re-traversed or re-mapped).
|
|
370
|
+
*
|
|
371
|
+
* Note: Because plain objects are mutated in-place, callers who need immutability should first
|
|
372
|
+
* clone the object graph or pass a deep-cloned input to avoid modifying the original.
|
|
373
|
+
*
|
|
374
|
+
* @param input - The value to traverse and map. May be any value (primitive, array, object, etc.).
|
|
375
|
+
* @param fn - A function invoked for every non-array, non-plain-object value encountered.
|
|
376
|
+
* Receives the current value and should return the mapped value.
|
|
377
|
+
* @returns The transformed structure: arrays are returned as new arrays, plain objects are the
|
|
378
|
+
* same object instances with their property values replaced, and other values are the
|
|
379
|
+
* result of `fn`.
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* // Map all primitive values to their string representation:
|
|
383
|
+
* // const result = mapValuesDeep({ a: 1, b: [2, { c: 3 }] }, v => String(v));
|
|
384
|
+
* // result => { a: "1", b: ["2", { c: "3" }] }
|
|
385
|
+
*
|
|
386
|
+
* @remarks
|
|
387
|
+
* - Only plain objects (constructed by `Object`) are recursively traversed. This avoids
|
|
388
|
+
* unintentionally iterating internal structure of class instances or built-in collections.
|
|
389
|
+
* - Circular structures are preserved by returning the original reference when detected.
|
|
390
|
+
*/
|
|
391
|
+
function mapValuesDeep(input, fn) {
|
|
392
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
393
|
+
const recurse = (value) => {
|
|
394
|
+
if (Array.isArray(value)) return value.map(recurse);
|
|
395
|
+
if (value !== null && value !== void 0 && typeof value === "object" && value.constructor === Object) {
|
|
396
|
+
if (seen.has(value)) return value;
|
|
397
|
+
seen.add(value);
|
|
398
|
+
for (const key of Object.keys(value)) value[key] = recurse(value[key]);
|
|
399
|
+
return value;
|
|
400
|
+
}
|
|
401
|
+
return fn(value);
|
|
402
|
+
};
|
|
403
|
+
return recurse(input);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
//#endregion
|
|
407
|
+
//#region lib/client/nativeDateExchange.ts
|
|
408
|
+
const dateIsoRegex = /^\d{4}-\d{2}-\d{2}(?:[Tt ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})?)?$/;
|
|
409
|
+
const nativeDateExchange = ({ client, forward }) => {
|
|
410
|
+
return (operations$) => {
|
|
411
|
+
return (0, wonka.pipe)(forward(operations$), (0, wonka.map)((r) => {
|
|
412
|
+
r.data = mapValuesDeep(r.data, (value) => {
|
|
413
|
+
if (typeof value !== "string" || !dateIsoRegex.test(value)) return value;
|
|
414
|
+
const date = Date.parse(value);
|
|
415
|
+
if (!Number.isNaN(date)) return new Date(date);
|
|
416
|
+
return value;
|
|
417
|
+
});
|
|
418
|
+
return r;
|
|
419
|
+
}));
|
|
420
|
+
};
|
|
421
|
+
};
|
|
422
|
+
|
|
352
423
|
//#endregion
|
|
353
424
|
//#region lib/client/query.ts
|
|
354
425
|
function makeQuery({ urqlClient }) {
|
|
@@ -1939,5 +2010,6 @@ exports.makeMutation = makeMutation;
|
|
|
1939
2010
|
exports.makeQuery = makeQuery;
|
|
1940
2011
|
exports.makeSubscription = makeSubscription;
|
|
1941
2012
|
exports.mapNullFieldsToUndefined = mapNullFieldsToUndefined;
|
|
2013
|
+
exports.nativeDateExchange = nativeDateExchange;
|
|
1942
2014
|
exports.rumble = rumble;
|
|
1943
2015
|
//# sourceMappingURL=index.cjs.map
|