@m1212e/rumble 0.15.4 → 0.16.3
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/README.md +4 -1
- package/out/client/generate.cjs +3 -0
- package/out/client/generate.d.cts +23 -0
- package/out/client/generate.d.cts.map +1 -0
- package/out/client/generate.d.mts +23 -0
- package/out/client/generate.d.mts.map +1 -0
- package/out/client/generate.mjs +3 -0
- package/out/client.cjs +300 -0
- package/out/client.cjs.map +1 -0
- package/out/client.d.cts +88 -0
- package/out/client.d.cts.map +1 -0
- package/out/client.d.mts +88 -0
- package/out/client.d.mts.map +1 -0
- package/out/client.mjs +295 -0
- package/out/client.mjs.map +1 -0
- package/out/generate-HCpRd3Cx.cjs +224 -0
- package/out/generate-HCpRd3Cx.cjs.map +1 -0
- package/out/generate-rRldfRei.mjs +218 -0
- package/out/generate-rRldfRei.mjs.map +1 -0
- package/out/index.cjs +6 -434
- package/out/index.cjs.map +1 -1
- package/out/index.d.cts +3 -101
- package/out/index.d.cts.map +1 -1
- package/out/index.d.mts +3 -101
- package/out/index.d.mts.map +1 -1
- package/out/index.mjs +6 -429
- package/out/index.mjs.map +1 -1
- package/package.json +9 -1
package/out/index.cjs
CHANGED
|
@@ -21,15 +21,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
}) : target, mod));
|
|
22
22
|
|
|
23
23
|
//#endregion
|
|
24
|
-
|
|
25
|
-
let node_path = require("node:path");
|
|
26
|
-
let __urql_introspection = require("@urql/introspection");
|
|
27
|
-
let devalue = require("devalue");
|
|
24
|
+
const require_generate = require('./generate-HCpRd3Cx.cjs');
|
|
28
25
|
let graphql = require("graphql");
|
|
29
|
-
let es_toolkit = require("es-toolkit");
|
|
30
|
-
let wonka = require("wonka");
|
|
31
26
|
let __escape_tech_graphql_armor = require("@escape.tech/graphql-armor");
|
|
32
27
|
let __graphql_yoga_plugin_disable_introspection = require("@graphql-yoga/plugin-disable-introspection");
|
|
28
|
+
let es_toolkit = require("es-toolkit");
|
|
33
29
|
let graphql_yoga = require("graphql-yoga");
|
|
34
30
|
let sofa_api = require("sofa-api");
|
|
35
31
|
let drizzle_orm = require("drizzle-orm");
|
|
@@ -47,425 +43,6 @@ let __pothos_plugin_smart_subscriptions = require("@pothos/plugin-smart-subscrip
|
|
|
47
43
|
__pothos_plugin_smart_subscriptions = __toESM(__pothos_plugin_smart_subscriptions);
|
|
48
44
|
let graphql_scalars = require("graphql-scalars");
|
|
49
45
|
|
|
50
|
-
//#region lib/client/generate/client.ts
|
|
51
|
-
function generateClient({ apiUrl, rumbleImportPath, useExternalUrqlClient, availableSubscriptions, schemaPath, forceReactivity }) {
|
|
52
|
-
const imports = [];
|
|
53
|
-
let code = "";
|
|
54
|
-
if (typeof useExternalUrqlClient === "string") imports.push(`import { urqlClient } from "${useExternalUrqlClient}";`);
|
|
55
|
-
imports.push(`import { Client, fetchExchange } from '@urql/core';`);
|
|
56
|
-
imports.push(`import { cacheExchange } from '@urql/exchange-graphcache';`);
|
|
57
|
-
imports.push(`import { nativeDateExchange } from '${rumbleImportPath}';`);
|
|
58
|
-
imports.push(`import { schema } from '${schemaPath}';`);
|
|
59
|
-
imports.push(`import { makeLiveQuery, makeMutation, makeSubscription, makeQuery } from '${rumbleImportPath}';`);
|
|
60
|
-
const forceReactivityValueString = typeof forceReactivity === "boolean" && forceReactivity ? "true" : "";
|
|
61
|
-
const forceReactivityFieldString = forceReactivityValueString !== "" ? `forceReactivity: ${forceReactivityValueString}` : "";
|
|
62
|
-
code += `
|
|
63
|
-
export const defaultOptions: ConstructorParameters<Client>[0] = {
|
|
64
|
-
url: "${apiUrl ?? "PLEASE PROVIDE A URL WHEN GENERATING OR IMPORT AN EXTERNAL URQL CLIENT"}",
|
|
65
|
-
fetchSubscriptions: true,
|
|
66
|
-
exchanges: [cacheExchange({ schema }), nativeDateExchange, fetchExchange],
|
|
67
|
-
fetchOptions: {
|
|
68
|
-
credentials: "include",
|
|
69
|
-
},
|
|
70
|
-
requestPolicy: "cache-and-network",
|
|
71
|
-
}
|
|
72
|
-
`;
|
|
73
|
-
if (!useExternalUrqlClient) code += `
|
|
74
|
-
const urqlClient = new Client(defaultOptions);
|
|
75
|
-
`;
|
|
76
|
-
code += `
|
|
77
|
-
export const client = {
|
|
78
|
-
/**
|
|
79
|
-
* A query and subscription combination. First queries and if exists, also subscribes to a subscription of the same name.
|
|
80
|
-
* Combines the results of both, so the result is first the query result and then live updates from the subscription.
|
|
81
|
-
* Assumes that the query and subscription return the same fields as per default when using the rumble query helpers.
|
|
82
|
-
* If no subscription with the same name exists, this will just be a query.
|
|
83
|
-
*/
|
|
84
|
-
liveQuery: makeLiveQuery<Query${`, ${forceReactivityValueString}`}>({
|
|
85
|
-
urqlClient,
|
|
86
|
-
availableSubscriptions: new Set([${availableSubscriptions.values().toArray().map((value) => `"${value}"`).join(", ")}]),
|
|
87
|
-
${forceReactivityFieldString}
|
|
88
|
-
}),
|
|
89
|
-
/**
|
|
90
|
-
* A mutation that can be used to e.g. create, update or delete data.
|
|
91
|
-
*/
|
|
92
|
-
mutate: makeMutation<Mutation${`, ${forceReactivityValueString}`}>({
|
|
93
|
-
urqlClient,
|
|
94
|
-
${forceReactivityFieldString}
|
|
95
|
-
}),
|
|
96
|
-
/**
|
|
97
|
-
* A continuous stream of results that updates when the server sends new data.
|
|
98
|
-
*/
|
|
99
|
-
subscribe: makeSubscription<Subscription${`, ${forceReactivityValueString}`}>({
|
|
100
|
-
urqlClient,
|
|
101
|
-
${forceReactivityFieldString}
|
|
102
|
-
}),
|
|
103
|
-
/**
|
|
104
|
-
* A one-time fetch of data.
|
|
105
|
-
*/
|
|
106
|
-
query: makeQuery<Query${`, ${forceReactivityValueString}`}>({
|
|
107
|
-
urqlClient,
|
|
108
|
-
${forceReactivityValueString !== "" ? `forceReactivity: ${forceReactivityValueString}` : ""}
|
|
109
|
-
}),
|
|
110
|
-
}`;
|
|
111
|
-
return {
|
|
112
|
-
imports,
|
|
113
|
-
code
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
//#endregion
|
|
118
|
-
//#region lib/client/generate/tsRepresentation.ts
|
|
119
|
-
function makeTSRepresentation(model) {
|
|
120
|
-
if (model instanceof graphql.GraphQLObjectType) return makeTSTypeFromObject(model);
|
|
121
|
-
else if (model instanceof graphql.GraphQLScalarType) return mapGraphqlScalarToTSTypeString(model);
|
|
122
|
-
else if (model instanceof graphql.GraphQLEnumType) return makeStringLiteralUnionFromEnum(model);
|
|
123
|
-
else if (model instanceof graphql.GraphQLInputObjectType) return makeTSTypeFromInputObject(model);
|
|
124
|
-
throw new Error(`Unknown model type: ${model}`);
|
|
125
|
-
}
|
|
126
|
-
function makeTSTypeFromObject(model) {
|
|
127
|
-
const stringifiedFields = /* @__PURE__ */ new Map();
|
|
128
|
-
for (const [key, value] of Object.entries(model.getFields())) stringifiedFields.set(key, makeTSObjectTypeField(value.type, value.args));
|
|
129
|
-
return `{
|
|
130
|
-
${stringifiedFields.entries().map(([key, value]) => `${key}: ${value}`).toArray().join(",\n ")}
|
|
131
|
-
}`;
|
|
132
|
-
}
|
|
133
|
-
function makeTSTypeFromInputObject(model) {
|
|
134
|
-
const stringifiedFields = /* @__PURE__ */ new Map();
|
|
135
|
-
for (const [key, value] of Object.entries(model.getFields())) stringifiedFields.set(key, makeTSInputObjectTypeField(value.type));
|
|
136
|
-
return `{
|
|
137
|
-
${stringifiedFields.entries().map(([key, value]) => `${key}${value.includes("| undefined") ? "?" : ""}: ${value}`).toArray().join(",\n ")}
|
|
138
|
-
}`;
|
|
139
|
-
}
|
|
140
|
-
function makeTSObjectTypeField(returnType, args) {
|
|
141
|
-
let isNonNullReturnType = false;
|
|
142
|
-
let isList = false;
|
|
143
|
-
for (let index = 0; index < 3; index++) {
|
|
144
|
-
if (returnType instanceof graphql.GraphQLList) {
|
|
145
|
-
isList = true;
|
|
146
|
-
returnType = returnType.ofType;
|
|
147
|
-
}
|
|
148
|
-
if (returnType instanceof graphql.GraphQLNonNull) {
|
|
149
|
-
isNonNullReturnType = true;
|
|
150
|
-
returnType = returnType.ofType;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
let returnTypeString = returnType.name;
|
|
154
|
-
if (isList) returnTypeString += "[]";
|
|
155
|
-
if (!isNonNullReturnType) returnTypeString += " | null";
|
|
156
|
-
const isRelationType = returnType instanceof graphql.GraphQLObjectType;
|
|
157
|
-
const argsStringMap = /* @__PURE__ */ new Map();
|
|
158
|
-
for (const arg of args ?? []) argsStringMap.set(arg.name, stringifyTSObjectArg(arg.type));
|
|
159
|
-
if (isRelationType) {
|
|
160
|
-
const makePOptional = argsStringMap.entries().every(([, value]) => value.includes("| undefined"));
|
|
161
|
-
return `(${(args ?? []).length > 0 ? `p${makePOptional ? "?" : ""}: {
|
|
162
|
-
${argsStringMap.entries().map(([key, value]) => ` ${key}${value.includes("| undefined") ? "?" : ""}: ${value}`).toArray().join(",\n ")}
|
|
163
|
-
}` : ""}) => ${returnTypeString}`;
|
|
164
|
-
} else return returnTypeString;
|
|
165
|
-
}
|
|
166
|
-
function makeTSInputObjectTypeField(returnType) {
|
|
167
|
-
let isNonNullReturnType = false;
|
|
168
|
-
let isList = false;
|
|
169
|
-
for (let index = 0; index < 3; index++) {
|
|
170
|
-
if (returnType instanceof graphql.GraphQLList) {
|
|
171
|
-
isList = true;
|
|
172
|
-
returnType = returnType.ofType;
|
|
173
|
-
}
|
|
174
|
-
if (returnType instanceof graphql.GraphQLNonNull) {
|
|
175
|
-
isNonNullReturnType = true;
|
|
176
|
-
returnType = returnType.ofType;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
let returnTypeString = returnType.name;
|
|
180
|
-
if (isList) returnTypeString += "[]";
|
|
181
|
-
if (!isNonNullReturnType) returnTypeString += " | null | undefined";
|
|
182
|
-
else if (isList) returnTypeString += " | undefined";
|
|
183
|
-
return returnTypeString;
|
|
184
|
-
}
|
|
185
|
-
function stringifyTSObjectArg(arg) {
|
|
186
|
-
let ret = "unknown";
|
|
187
|
-
let isNullable = true;
|
|
188
|
-
if (arg instanceof graphql.GraphQLNonNull) {
|
|
189
|
-
isNullable = false;
|
|
190
|
-
arg = arg.ofType;
|
|
191
|
-
}
|
|
192
|
-
if (arg instanceof graphql.GraphQLInputObjectType || arg instanceof graphql.GraphQLScalarType) ret = arg.name;
|
|
193
|
-
if (isNullable) ret += " | null | undefined";
|
|
194
|
-
return ret;
|
|
195
|
-
}
|
|
196
|
-
function mapGraphqlScalarToTSTypeString(arg) {
|
|
197
|
-
switch (arg.name) {
|
|
198
|
-
case "ID": return "string";
|
|
199
|
-
case "String": return "string";
|
|
200
|
-
case "Boolean": return "boolean";
|
|
201
|
-
case "Int": return "number";
|
|
202
|
-
case "Float": return "number";
|
|
203
|
-
case "Date": return "Date";
|
|
204
|
-
case "DateTime": return "Date";
|
|
205
|
-
case "JSON": return "any";
|
|
206
|
-
default: return "unknown";
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
function makeStringLiteralUnionFromEnum(enumType) {
|
|
210
|
-
return enumType.getValues().map((value) => `"${value.name}"`).join(" | ");
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
//#endregion
|
|
214
|
-
//#region lib/client/generate/generate.ts
|
|
215
|
-
async function generateFromSchema({ outputPath, schema, rumbleImportPath = "@m1212e/rumble", apiUrl, useExternalUrqlClient = false, removeExisting = true, forceReactivity }) {
|
|
216
|
-
if (removeExisting) try {
|
|
217
|
-
await (0, node_fs_promises.access)(outputPath);
|
|
218
|
-
await (0, node_fs_promises.rm)(outputPath, {
|
|
219
|
-
recursive: true,
|
|
220
|
-
force: true
|
|
221
|
-
});
|
|
222
|
-
} catch (_error) {}
|
|
223
|
-
await (0, node_fs_promises.mkdir)(outputPath, { recursive: true });
|
|
224
|
-
if (!outputPath.endsWith("/")) outputPath += "/";
|
|
225
|
-
const imports = [];
|
|
226
|
-
let code = "";
|
|
227
|
-
const typeMap = /* @__PURE__ */ new Map();
|
|
228
|
-
for (const [key, object] of Object.entries(schema.getTypeMap())) {
|
|
229
|
-
if (key.startsWith("__")) continue;
|
|
230
|
-
typeMap.set(key, object);
|
|
231
|
-
}
|
|
232
|
-
for (const [key, object] of typeMap.entries()) {
|
|
233
|
-
const rep = makeTSRepresentation(object);
|
|
234
|
-
if (rep === key) continue;
|
|
235
|
-
code += `
|
|
236
|
-
export type ${key} = ${rep};
|
|
237
|
-
`;
|
|
238
|
-
}
|
|
239
|
-
const schemaFileName = "schema";
|
|
240
|
-
const c = generateClient({
|
|
241
|
-
apiUrl,
|
|
242
|
-
schemaPath: `./${schemaFileName}`,
|
|
243
|
-
useExternalUrqlClient,
|
|
244
|
-
rumbleImportPath,
|
|
245
|
-
availableSubscriptions: new Set(Object.keys(schema.getSubscriptionType()?.getFields() || {})),
|
|
246
|
-
forceReactivity
|
|
247
|
-
});
|
|
248
|
-
imports.push(...c.imports);
|
|
249
|
-
code += c.code;
|
|
250
|
-
await Promise.all([(0, node_fs_promises.writeFile)((0, node_path.join)(outputPath, "client.ts"), `${imports.join("\n")}\n${code}`), (0, node_fs_promises.writeFile)((0, node_path.join)(outputPath, `${schemaFileName}.ts`), `// @ts-ignore
|
|
251
|
-
export const schema = ${(0, devalue.uneval)((0, __urql_introspection.minifyIntrospectionQuery)((0, __urql_introspection.getIntrospectedSchema)(schema)))}`)]);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
//#endregion
|
|
255
|
-
//#region lib/client/request.ts
|
|
256
|
-
const argsKey = "__args";
|
|
257
|
-
function makeGraphQLQueryRequest({ queryName, input, client, enableSubscription = false, forceReactivity }) {
|
|
258
|
-
const otwQueryName = `${(0, es_toolkit.capitalize)(queryName)}Query`;
|
|
259
|
-
const argsString = stringifyArgumentObjectToGraphqlList(input?.[argsKey] ?? {});
|
|
260
|
-
const operationString = (operationVerb) => `${operationVerb} ${otwQueryName} { ${queryName}${argsString} ${input ? `{ ${stringifySelection(input)} }` : ""}}`;
|
|
261
|
-
const awaitedReturnValueReference = {};
|
|
262
|
-
const source = (0, wonka.pipe)((0, wonka.merge)([client.query(operationString("query"), {}), enableSubscription ? client.subscription(operationString("subscription"), {}) : wonka.empty]), wonka.share, (0, wonka.map)((v) => {
|
|
263
|
-
const data = v.data?.[queryName];
|
|
264
|
-
if (!data && v.error) throw v.error;
|
|
265
|
-
return data;
|
|
266
|
-
}), (0, wonka.onPush)((data) => {
|
|
267
|
-
if (typeof data === "object" && data !== null && typeof forceReactivity === "boolean" && forceReactivity) Object.assign(awaitedReturnValueReference, data);
|
|
268
|
-
}));
|
|
269
|
-
const observable = (0, wonka.toObservable)(source);
|
|
270
|
-
const promise = (0, wonka.toPromise)((0, wonka.pipe)(source, (0, wonka.take)(1), (0, wonka.map)((data) => {
|
|
271
|
-
Object.assign(awaitedReturnValueReference, observable);
|
|
272
|
-
if (typeof data === "object" && data !== null && typeof forceReactivity === "boolean" && forceReactivity) {
|
|
273
|
-
Object.assign(awaitedReturnValueReference, data);
|
|
274
|
-
return awaitedReturnValueReference;
|
|
275
|
-
}
|
|
276
|
-
return data;
|
|
277
|
-
})));
|
|
278
|
-
Object.assign(promise, observable);
|
|
279
|
-
return promise;
|
|
280
|
-
}
|
|
281
|
-
function makeGraphQLMutationRequest({ mutationName, input, client, forceReactivity }) {
|
|
282
|
-
const operationString = `mutation ${`${(0, es_toolkit.capitalize)(mutationName)}Mutation`} { ${mutationName}${stringifyArgumentObjectToGraphqlList(input[argsKey] ?? {})} { ${stringifySelection(input)} }}`;
|
|
283
|
-
const response = (0, wonka.pipe)(client.mutation(operationString, {}), (0, wonka.map)((v) => {
|
|
284
|
-
const data = v.data?.[mutationName];
|
|
285
|
-
if (!data && v.error) throw v.error;
|
|
286
|
-
return data;
|
|
287
|
-
}));
|
|
288
|
-
const observable = (0, wonka.toObservable)(response);
|
|
289
|
-
const promise = (0, wonka.toPromise)((0, wonka.pipe)(response, (0, wonka.take)(1)));
|
|
290
|
-
Object.assign(promise, observable);
|
|
291
|
-
return promise;
|
|
292
|
-
}
|
|
293
|
-
function makeGraphQLSubscriptionRequest({ subscriptionName, input, client, forceReactivity }) {
|
|
294
|
-
const operationString = `subscription ${`${(0, es_toolkit.capitalize)(subscriptionName)}Subscription`} { ${subscriptionName}${stringifyArgumentObjectToGraphqlList(input[argsKey] ?? {})} { ${stringifySelection(input)} }}`;
|
|
295
|
-
return (0, wonka.pipe)(client.subscription(operationString, {}), (0, wonka.map)((v) => {
|
|
296
|
-
const data = v.data?.[subscriptionName];
|
|
297
|
-
if (!data && v.error) throw v.error;
|
|
298
|
-
return data;
|
|
299
|
-
}), wonka.toObservable);
|
|
300
|
-
}
|
|
301
|
-
function stringifySelection(selection) {
|
|
302
|
-
return Object.entries(selection).filter(([key]) => key !== argsKey).reduce((acc, [key, value]) => {
|
|
303
|
-
if (typeof value === "object") {
|
|
304
|
-
if (value[argsKey]) {
|
|
305
|
-
const argsString = stringifyArgumentObjectToGraphqlList(value[argsKey]);
|
|
306
|
-
acc += `${key}${argsString} { ${stringifySelection(value)} }
|
|
307
|
-
`;
|
|
308
|
-
return acc;
|
|
309
|
-
}
|
|
310
|
-
acc += `${key} {
|
|
311
|
-
${stringifySelection(value)} }
|
|
312
|
-
`;
|
|
313
|
-
} else acc += `${key}
|
|
314
|
-
`;
|
|
315
|
-
return acc;
|
|
316
|
-
}, "");
|
|
317
|
-
}
|
|
318
|
-
function stringifyArgumentObjectToGraphqlList(args) {
|
|
319
|
-
const entries = Object.entries(args);
|
|
320
|
-
if (Array.isArray(args)) return `(${stringifyArgumentValue(args)})`;
|
|
321
|
-
if (entries.length > 0) return `(${entries.map(([key, value]) => `${key}: ${stringifyArgumentValue(value)}`).join(", ")})`;
|
|
322
|
-
return "";
|
|
323
|
-
}
|
|
324
|
-
function stringifyArgumentValue(arg) {
|
|
325
|
-
if (arg === null) return "null";
|
|
326
|
-
if (Array.isArray(arg)) return `[${arg.map(stringifyArgumentValue).join(", ")}]`;
|
|
327
|
-
switch (typeof arg) {
|
|
328
|
-
case "string": return `"${arg}"`;
|
|
329
|
-
case "number": return `${arg}`;
|
|
330
|
-
case "bigint": return `${arg}`;
|
|
331
|
-
case "boolean": return `${arg}`;
|
|
332
|
-
case "symbol": throw new Error("Cannot stringify a symbol to send as gql arg");
|
|
333
|
-
case "undefined": return "null";
|
|
334
|
-
case "object": return `{ ${Object.entries(arg).map(([key, value]) => `${key}: ${stringifyArgumentValue(value)}`).join(", ")} }`;
|
|
335
|
-
case "function": throw new Error("Cannot stringify a function to send as gql arg");
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
//#endregion
|
|
340
|
-
//#region lib/client/liveQuery.ts
|
|
341
|
-
function makeLiveQuery({ urqlClient, availableSubscriptions, forceReactivity }) {
|
|
342
|
-
return new Proxy({}, { get: (_target, prop) => {
|
|
343
|
-
return (input) => {
|
|
344
|
-
return makeGraphQLQueryRequest({
|
|
345
|
-
queryName: prop,
|
|
346
|
-
input,
|
|
347
|
-
client: urqlClient,
|
|
348
|
-
enableSubscription: availableSubscriptions.has(prop),
|
|
349
|
-
forceReactivity
|
|
350
|
-
});
|
|
351
|
-
};
|
|
352
|
-
} });
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
//#endregion
|
|
356
|
-
//#region lib/client/mutation.ts
|
|
357
|
-
function makeMutation({ urqlClient, forceReactivity }) {
|
|
358
|
-
return new Proxy({}, { get: (_target, prop) => {
|
|
359
|
-
return (input) => {
|
|
360
|
-
return makeGraphQLMutationRequest({
|
|
361
|
-
mutationName: prop,
|
|
362
|
-
input,
|
|
363
|
-
client: urqlClient,
|
|
364
|
-
forceReactivity
|
|
365
|
-
});
|
|
366
|
-
};
|
|
367
|
-
} });
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
//#endregion
|
|
371
|
-
//#region lib/helpers/deepMap.ts
|
|
372
|
-
/**
|
|
373
|
-
* Recursively applies a mapping function to every value in a nested structure.
|
|
374
|
-
*
|
|
375
|
-
* This helper will traverse arrays and plain objects (objects with `constructor === Object`)
|
|
376
|
-
* and apply the provided `fn` to any value that is not an array or a plain object.
|
|
377
|
-
* - Arrays are mapped to new arrays (a fresh array is returned).
|
|
378
|
-
* - Plain objects are traversed and their own enumerable properties are replaced in-place.
|
|
379
|
-
* - Non-plain objects (e.g. Date, Map, Set, class instances, functions) are treated as leaves
|
|
380
|
-
* and passed directly to `fn`.
|
|
381
|
-
* - `null` and `undefined` are passed to `fn`.
|
|
382
|
-
* - Circular references are detected using a `WeakSet`. When a circular reference is encountered,
|
|
383
|
-
* the original reference is returned unchanged (it is not re-traversed or re-mapped).
|
|
384
|
-
*
|
|
385
|
-
* Note: Because plain objects are mutated in-place, callers who need immutability should first
|
|
386
|
-
* clone the object graph or pass a deep-cloned input to avoid modifying the original.
|
|
387
|
-
*
|
|
388
|
-
* @param input - The value to traverse and map. May be any value (primitive, array, object, etc.).
|
|
389
|
-
* @param fn - A function invoked for every non-array, non-plain-object value encountered.
|
|
390
|
-
* Receives the current value and should return the mapped value.
|
|
391
|
-
* @returns The transformed structure: arrays are returned as new arrays, plain objects are the
|
|
392
|
-
* same object instances with their property values replaced, and other values are the
|
|
393
|
-
* result of `fn`.
|
|
394
|
-
*
|
|
395
|
-
* @example
|
|
396
|
-
* // Map all primitive values to their string representation:
|
|
397
|
-
* // const result = mapValuesDeep({ a: 1, b: [2, { c: 3 }] }, v => String(v));
|
|
398
|
-
* // result => { a: "1", b: ["2", { c: "3" }] }
|
|
399
|
-
*
|
|
400
|
-
* @remarks
|
|
401
|
-
* - Only plain objects (constructed by `Object`) are recursively traversed. This avoids
|
|
402
|
-
* unintentionally iterating internal structure of class instances or built-in collections.
|
|
403
|
-
* - Circular structures are preserved by returning the original reference when detected.
|
|
404
|
-
*/
|
|
405
|
-
function mapValuesDeep(input, fn) {
|
|
406
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
407
|
-
const recurse = (value) => {
|
|
408
|
-
if (Array.isArray(value)) return value.map(recurse);
|
|
409
|
-
if (value !== null && value !== void 0 && typeof value === "object" && value.constructor === Object) {
|
|
410
|
-
if (seen.has(value)) return value;
|
|
411
|
-
seen.add(value);
|
|
412
|
-
for (const key of Object.keys(value)) value[key] = recurse(value[key]);
|
|
413
|
-
return value;
|
|
414
|
-
}
|
|
415
|
-
return fn(value);
|
|
416
|
-
};
|
|
417
|
-
return recurse(input);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
//#endregion
|
|
421
|
-
//#region lib/client/nativeDateExchange.ts
|
|
422
|
-
const dateIsoRegex = /^\d{4}-\d{2}-\d{2}(?:[Tt ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})?)?$/;
|
|
423
|
-
const nativeDateExchange = ({ client, forward }) => {
|
|
424
|
-
return (operations$) => {
|
|
425
|
-
return (0, wonka.pipe)(forward(operations$), (0, wonka.map)((r) => {
|
|
426
|
-
r.data = mapValuesDeep(r.data, (value) => {
|
|
427
|
-
if (typeof value !== "string" || !dateIsoRegex.test(value)) return value;
|
|
428
|
-
const date = Date.parse(value);
|
|
429
|
-
if (!Number.isNaN(date)) return new Date(date);
|
|
430
|
-
return value;
|
|
431
|
-
});
|
|
432
|
-
return r;
|
|
433
|
-
}));
|
|
434
|
-
};
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
//#endregion
|
|
438
|
-
//#region lib/client/query.ts
|
|
439
|
-
function makeQuery({ urqlClient, forceReactivity }) {
|
|
440
|
-
return new Proxy({}, { get: (_target, prop) => {
|
|
441
|
-
return (input) => {
|
|
442
|
-
return makeGraphQLQueryRequest({
|
|
443
|
-
queryName: prop,
|
|
444
|
-
input,
|
|
445
|
-
client: urqlClient,
|
|
446
|
-
enableSubscription: false,
|
|
447
|
-
forceReactivity
|
|
448
|
-
});
|
|
449
|
-
};
|
|
450
|
-
} });
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
//#endregion
|
|
454
|
-
//#region lib/client/subscription.ts
|
|
455
|
-
function makeSubscription({ urqlClient, forceReactivity }) {
|
|
456
|
-
return new Proxy({}, { get: (_target, prop) => {
|
|
457
|
-
return (input) => {
|
|
458
|
-
return makeGraphQLSubscriptionRequest({
|
|
459
|
-
subscriptionName: prop,
|
|
460
|
-
input,
|
|
461
|
-
client: urqlClient,
|
|
462
|
-
forceReactivity
|
|
463
|
-
});
|
|
464
|
-
};
|
|
465
|
-
} });
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
//#endregion
|
|
469
46
|
//#region lib/types/rumbleError.ts
|
|
470
47
|
/**
|
|
471
48
|
* An error that gets raised by rumble whenever something does not go according to plan.
|
|
@@ -939,10 +516,10 @@ const createAbilityBuilder = ({ db, actions, defaultLimit }) => {
|
|
|
939
516
|
/**
|
|
940
517
|
* Merges the current query filters with the provided filters for this call only
|
|
941
518
|
*/
|
|
942
|
-
function merge$
|
|
519
|
+
function merge$1(p) {
|
|
943
520
|
return internalTransformer(mergeFilters(ret.query.many, p), p.limit);
|
|
944
521
|
}
|
|
945
|
-
ret.merge = merge$
|
|
522
|
+
ret.merge = merge$1;
|
|
946
523
|
return ret;
|
|
947
524
|
}
|
|
948
525
|
return { withContext: (userContext) => {
|
|
@@ -1157,7 +734,7 @@ const createWhereArgImplementer = ({ db, schemaBuilder, enumImplementer }) => {
|
|
|
1157
734
|
const clientCreatorImplementer = ({ builtSchema }) => {
|
|
1158
735
|
const clientCreator = async ({ apiUrl, outputPath, rumbleImportPath, useExternalUrqlClient, removeExisting, forceReactivity }) => {
|
|
1159
736
|
if (process.env.NODE_ENV !== "development") console.warn("Running rumble client generation in non development mode. Are you sure this is correct?");
|
|
1160
|
-
await generateFromSchema({
|
|
737
|
+
await require_generate.generateFromSchema({
|
|
1161
738
|
schema: builtSchema(),
|
|
1162
739
|
outputPath,
|
|
1163
740
|
rumbleImportPath,
|
|
@@ -2043,14 +1620,9 @@ export const db = drizzle(
|
|
|
2043
1620
|
//#endregion
|
|
2044
1621
|
exports.RumbleError = RumbleError;
|
|
2045
1622
|
exports.RumbleErrorSafe = RumbleErrorSafe;
|
|
1623
|
+
exports.__toESM = __toESM;
|
|
2046
1624
|
exports.assertFindFirstExists = assertFindFirstExists;
|
|
2047
1625
|
exports.assertFirstEntryExists = assertFirstEntryExists;
|
|
2048
|
-
exports.generateFromSchema = generateFromSchema;
|
|
2049
|
-
exports.makeLiveQuery = makeLiveQuery;
|
|
2050
|
-
exports.makeMutation = makeMutation;
|
|
2051
|
-
exports.makeQuery = makeQuery;
|
|
2052
|
-
exports.makeSubscription = makeSubscription;
|
|
2053
1626
|
exports.mapNullFieldsToUndefined = mapNullFieldsToUndefined;
|
|
2054
|
-
exports.nativeDateExchange = nativeDateExchange;
|
|
2055
1627
|
exports.rumble = rumble;
|
|
2056
1628
|
//# sourceMappingURL=index.cjs.map
|