@m1212e/rumble 0.15.2 → 0.15.4

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 CHANGED
@@ -48,7 +48,7 @@ __pothos_plugin_smart_subscriptions = __toESM(__pothos_plugin_smart_subscription
48
48
  let graphql_scalars = require("graphql-scalars");
49
49
 
50
50
  //#region lib/client/generate/client.ts
51
- function generateClient({ apiUrl, rumbleImportPath, useExternalUrqlClient, availableSubscriptions, schemaPath }) {
51
+ function generateClient({ apiUrl, rumbleImportPath, useExternalUrqlClient, availableSubscriptions, schemaPath, forceReactivity }) {
52
52
  const imports = [];
53
53
  let code = "";
54
54
  if (typeof useExternalUrqlClient === "string") imports.push(`import { urqlClient } from "${useExternalUrqlClient}";`);
@@ -57,6 +57,8 @@ function generateClient({ apiUrl, rumbleImportPath, useExternalUrqlClient, avail
57
57
  imports.push(`import { nativeDateExchange } from '${rumbleImportPath}';`);
58
58
  imports.push(`import { schema } from '${schemaPath}';`);
59
59
  imports.push(`import { makeLiveQuery, makeMutation, makeSubscription, makeQuery } from '${rumbleImportPath}';`);
60
+ const forceReactivityValueString = typeof forceReactivity === "boolean" && forceReactivity ? "true" : "";
61
+ const forceReactivityFieldString = forceReactivityValueString !== "" ? `forceReactivity: ${forceReactivityValueString}` : "";
60
62
  code += `
61
63
  export const defaultOptions: ConstructorParameters<Client>[0] = {
62
64
  url: "${apiUrl ?? "PLEASE PROVIDE A URL WHEN GENERATING OR IMPORT AN EXTERNAL URQL CLIENT"}",
@@ -79,27 +81,31 @@ export const client = {
79
81
  * Assumes that the query and subscription return the same fields as per default when using the rumble query helpers.
80
82
  * If no subscription with the same name exists, this will just be a query.
81
83
  */
82
- liveQuery: makeLiveQuery<Query>({
84
+ liveQuery: makeLiveQuery<Query${`, ${forceReactivityValueString}`}>({
83
85
  urqlClient,
84
86
  availableSubscriptions: new Set([${availableSubscriptions.values().toArray().map((value) => `"${value}"`).join(", ")}]),
87
+ ${forceReactivityFieldString}
85
88
  }),
86
89
  /**
87
90
  * A mutation that can be used to e.g. create, update or delete data.
88
91
  */
89
- mutate: makeMutation<Mutation>({
92
+ mutate: makeMutation<Mutation${`, ${forceReactivityValueString}`}>({
90
93
  urqlClient,
94
+ ${forceReactivityFieldString}
91
95
  }),
92
96
  /**
93
97
  * A continuous stream of results that updates when the server sends new data.
94
98
  */
95
- subscribe: makeSubscription<Subscription>({
99
+ subscribe: makeSubscription<Subscription${`, ${forceReactivityValueString}`}>({
96
100
  urqlClient,
101
+ ${forceReactivityFieldString}
97
102
  }),
98
103
  /**
99
104
  * A one-time fetch of data.
100
105
  */
101
- query: makeQuery<Query>({
106
+ query: makeQuery<Query${`, ${forceReactivityValueString}`}>({
102
107
  urqlClient,
108
+ ${forceReactivityValueString !== "" ? `forceReactivity: ${forceReactivityValueString}` : ""}
103
109
  }),
104
110
  }`;
105
111
  return {
@@ -206,7 +212,7 @@ function makeStringLiteralUnionFromEnum(enumType) {
206
212
 
207
213
  //#endregion
208
214
  //#region lib/client/generate/generate.ts
209
- async function generateFromSchema({ outputPath, schema, rumbleImportPath = "@m1212e/rumble", apiUrl, useExternalUrqlClient = false, removeExisting = true }) {
215
+ async function generateFromSchema({ outputPath, schema, rumbleImportPath = "@m1212e/rumble", apiUrl, useExternalUrqlClient = false, removeExisting = true, forceReactivity }) {
210
216
  if (removeExisting) try {
211
217
  await (0, node_fs_promises.access)(outputPath);
212
218
  await (0, node_fs_promises.rm)(outputPath, {
@@ -236,7 +242,8 @@ export type ${key} = ${rep};
236
242
  schemaPath: `./${schemaFileName}`,
237
243
  useExternalUrqlClient,
238
244
  rumbleImportPath,
239
- availableSubscriptions: new Set(Object.keys(schema.getSubscriptionType()?.getFields() || {}))
245
+ availableSubscriptions: new Set(Object.keys(schema.getSubscriptionType()?.getFields() || {})),
246
+ forceReactivity
240
247
  });
241
248
  imports.push(...c.imports);
242
249
  code += c.code;
@@ -247,7 +254,7 @@ export const schema = ${(0, devalue.uneval)((0, __urql_introspection.minifyIntro
247
254
  //#endregion
248
255
  //#region lib/client/request.ts
249
256
  const argsKey = "__args";
250
- function makeGraphQLQueryRequest({ queryName, input, client, enableSubscription = false }) {
257
+ function makeGraphQLQueryRequest({ queryName, input, client, enableSubscription = false, forceReactivity }) {
251
258
  const otwQueryName = `${(0, es_toolkit.capitalize)(queryName)}Query`;
252
259
  const argsString = stringifyArgumentObjectToGraphqlList(input?.[argsKey] ?? {});
253
260
  const operationString = (operationVerb) => `${operationVerb} ${otwQueryName} { ${queryName}${argsString} ${input ? `{ ${stringifySelection(input)} }` : ""}}`;
@@ -257,13 +264,13 @@ function makeGraphQLQueryRequest({ queryName, input, client, enableSubscription
257
264
  if (!data && v.error) throw v.error;
258
265
  return data;
259
266
  }), (0, wonka.onPush)((data) => {
260
- if (typeof data === "object" && data !== null) Object.assign(awaitedReturnValueReference, data);
267
+ if (typeof data === "object" && data !== null && typeof forceReactivity === "boolean" && forceReactivity) Object.assign(awaitedReturnValueReference, data);
261
268
  }));
262
269
  const observable = (0, wonka.toObservable)(source);
263
270
  const promise = (0, wonka.toPromise)((0, wonka.pipe)(source, (0, wonka.take)(1), (0, wonka.map)((data) => {
264
- if (typeof data === "object" && data !== null) {
271
+ Object.assign(awaitedReturnValueReference, observable);
272
+ if (typeof data === "object" && data !== null && typeof forceReactivity === "boolean" && forceReactivity) {
265
273
  Object.assign(awaitedReturnValueReference, data);
266
- Object.assign(awaitedReturnValueReference, observable);
267
274
  return awaitedReturnValueReference;
268
275
  }
269
276
  return data;
@@ -271,10 +278,9 @@ function makeGraphQLQueryRequest({ queryName, input, client, enableSubscription
271
278
  Object.assign(promise, observable);
272
279
  return promise;
273
280
  }
274
- function makeGraphQLMutationRequest({ mutationName, input, client }) {
275
- const otwMutationName = `${(0, es_toolkit.capitalize)(mutationName)}Mutation`;
276
- const argsString = stringifyArgumentObjectToGraphqlList(input[argsKey] ?? {});
277
- const response = (0, wonka.pipe)(client.mutation(`mutation ${otwMutationName} { ${mutationName}${argsString} { ${stringifySelection(input)} }}`, {}), (0, wonka.map)((v) => {
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) => {
278
284
  const data = v.data?.[mutationName];
279
285
  if (!data && v.error) throw v.error;
280
286
  return data;
@@ -284,10 +290,9 @@ function makeGraphQLMutationRequest({ mutationName, input, client }) {
284
290
  Object.assign(promise, observable);
285
291
  return promise;
286
292
  }
287
- function makeGraphQLSubscriptionRequest({ subscriptionName, input, client }) {
288
- const otwSubscriptionName = `${(0, es_toolkit.capitalize)(subscriptionName)}Subscription`;
289
- const argsString = stringifyArgumentObjectToGraphqlList(input[argsKey] ?? {});
290
- return (0, wonka.pipe)(client.subscription(`subscription ${otwSubscriptionName} { ${subscriptionName}${argsString} { ${stringifySelection(input)} }}`, {}), (0, wonka.map)((v) => {
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) => {
291
296
  const data = v.data?.[subscriptionName];
292
297
  if (!data && v.error) throw v.error;
293
298
  return data;
@@ -302,7 +307,8 @@ function stringifySelection(selection) {
302
307
  `;
303
308
  return acc;
304
309
  }
305
- acc += `${key} { ${stringifySelection(value)} }
310
+ acc += `${key} {
311
+ ${stringifySelection(value)} }
306
312
  `;
307
313
  } else acc += `${key}
308
314
  `;
@@ -311,11 +317,13 @@ function stringifySelection(selection) {
311
317
  }
312
318
  function stringifyArgumentObjectToGraphqlList(args) {
313
319
  const entries = Object.entries(args);
314
- if (entries.length === 0) return "";
315
- return `(${entries.map(([key, value]) => `${key}: ${stringifyArgumentValue(value)}`).join(", ")})`;
320
+ if (Array.isArray(args)) return `(${stringifyArgumentValue(args)})`;
321
+ if (entries.length > 0) return `(${entries.map(([key, value]) => `${key}: ${stringifyArgumentValue(value)}`).join(", ")})`;
322
+ return "";
316
323
  }
317
324
  function stringifyArgumentValue(arg) {
318
325
  if (arg === null) return "null";
326
+ if (Array.isArray(arg)) return `[${arg.map(stringifyArgumentValue).join(", ")}]`;
319
327
  switch (typeof arg) {
320
328
  case "string": return `"${arg}"`;
321
329
  case "number": return `${arg}`;
@@ -330,14 +338,15 @@ function stringifyArgumentValue(arg) {
330
338
 
331
339
  //#endregion
332
340
  //#region lib/client/liveQuery.ts
333
- function makeLiveQuery({ urqlClient, availableSubscriptions }) {
341
+ function makeLiveQuery({ urqlClient, availableSubscriptions, forceReactivity }) {
334
342
  return new Proxy({}, { get: (_target, prop) => {
335
343
  return (input) => {
336
344
  return makeGraphQLQueryRequest({
337
345
  queryName: prop,
338
346
  input,
339
347
  client: urqlClient,
340
- enableSubscription: availableSubscriptions.has(prop)
348
+ enableSubscription: availableSubscriptions.has(prop),
349
+ forceReactivity
341
350
  });
342
351
  };
343
352
  } });
@@ -345,13 +354,14 @@ function makeLiveQuery({ urqlClient, availableSubscriptions }) {
345
354
 
346
355
  //#endregion
347
356
  //#region lib/client/mutation.ts
348
- function makeMutation({ urqlClient }) {
357
+ function makeMutation({ urqlClient, forceReactivity }) {
349
358
  return new Proxy({}, { get: (_target, prop) => {
350
359
  return (input) => {
351
360
  return makeGraphQLMutationRequest({
352
361
  mutationName: prop,
353
362
  input,
354
- client: urqlClient
363
+ client: urqlClient,
364
+ forceReactivity
355
365
  });
356
366
  };
357
367
  } });
@@ -426,14 +436,15 @@ const nativeDateExchange = ({ client, forward }) => {
426
436
 
427
437
  //#endregion
428
438
  //#region lib/client/query.ts
429
- function makeQuery({ urqlClient }) {
439
+ function makeQuery({ urqlClient, forceReactivity }) {
430
440
  return new Proxy({}, { get: (_target, prop) => {
431
441
  return (input) => {
432
442
  return makeGraphQLQueryRequest({
433
443
  queryName: prop,
434
444
  input,
435
445
  client: urqlClient,
436
- enableSubscription: false
446
+ enableSubscription: false,
447
+ forceReactivity
437
448
  });
438
449
  };
439
450
  } });
@@ -441,13 +452,14 @@ function makeQuery({ urqlClient }) {
441
452
 
442
453
  //#endregion
443
454
  //#region lib/client/subscription.ts
444
- function makeSubscription({ urqlClient }) {
455
+ function makeSubscription({ urqlClient, forceReactivity }) {
445
456
  return new Proxy({}, { get: (_target, prop) => {
446
457
  return (input) => {
447
458
  return makeGraphQLSubscriptionRequest({
448
459
  subscriptionName: prop,
449
460
  input,
450
- client: urqlClient
461
+ client: urqlClient,
462
+ forceReactivity
451
463
  });
452
464
  };
453
465
  } });
@@ -1143,7 +1155,7 @@ const createWhereArgImplementer = ({ db, schemaBuilder, enumImplementer }) => {
1143
1155
  //#endregion
1144
1156
  //#region lib/client/client.ts
1145
1157
  const clientCreatorImplementer = ({ builtSchema }) => {
1146
- const clientCreator = async ({ apiUrl, outputPath, rumbleImportPath, useExternalUrqlClient, removeExisting }) => {
1158
+ const clientCreator = async ({ apiUrl, outputPath, rumbleImportPath, useExternalUrqlClient, removeExisting, forceReactivity }) => {
1147
1159
  if (process.env.NODE_ENV !== "development") console.warn("Running rumble client generation in non development mode. Are you sure this is correct?");
1148
1160
  await generateFromSchema({
1149
1161
  schema: builtSchema(),
@@ -1151,7 +1163,8 @@ const clientCreatorImplementer = ({ builtSchema }) => {
1151
1163
  rumbleImportPath,
1152
1164
  apiUrl,
1153
1165
  useExternalUrqlClient,
1154
- removeExisting
1166
+ removeExisting,
1167
+ forceReactivity
1155
1168
  });
1156
1169
  };
1157
1170
  return clientCreator;