@m1212e/rumble 0.12.18 → 0.12.20
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 +33 -28
- package/out/index.cjs.map +1 -1
- package/out/index.d.cts +9 -3
- package/out/index.d.cts.map +1 -1
- package/out/index.d.mts +9 -3
- package/out/index.d.mts.map +1 -1
- package/out/index.mjs +34 -29
- package/out/index.mjs.map +1 -1
- package/package.json +1 -1
package/out/index.cjs
CHANGED
|
@@ -52,22 +52,27 @@ function generateClient({ apiUrl, rumbleImportPath, useExternalUrqlClient, avail
|
|
|
52
52
|
const imports = [];
|
|
53
53
|
let code = "";
|
|
54
54
|
if (typeof useExternalUrqlClient === "string") imports.push(`import { urqlClient } from "${useExternalUrqlClient}";`);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
imports.push(`import { nativeDateExchange } from '${rumbleImportPath}';`);
|
|
59
|
-
}
|
|
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}';`);
|
|
60
58
|
imports.push(`import { makeLiveQuery, makeMutation, makeSubscription, makeQuery } from '${rumbleImportPath}';`);
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
code += `
|
|
60
|
+
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
export const schema = ${schema ? (0, devalue.uneval)((0, __urql_introspection.minifyIntrospectionQuery)((0, __urql_introspection.getIntrospectedSchema)(schema))) : "undefined"};
|
|
63
|
+
|
|
64
|
+
export const defaultOptions: ConstructorParameters<Client>[0] = {
|
|
63
65
|
url: "${apiUrl ?? "PLEASE PROVIDE A URL WHEN GENERATING OR IMPORT AN EXTERNAL URQL CLIENT"}",
|
|
64
66
|
fetchSubscriptions: true,
|
|
65
|
-
exchanges: [cacheExchange({ schema
|
|
67
|
+
exchanges: [cacheExchange({ schema }), nativeDateExchange, fetchExchange],
|
|
66
68
|
fetchOptions: {
|
|
67
69
|
credentials: "include",
|
|
68
70
|
},
|
|
69
71
|
requestPolicy: "cache-and-network",
|
|
70
|
-
}
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
if (!useExternalUrqlClient) code += `
|
|
75
|
+
const urqlClient = new Client(defaultOptions);
|
|
71
76
|
`;
|
|
72
77
|
code += `
|
|
73
78
|
export const client = {
|
|
@@ -204,8 +209,8 @@ function makeStringLiteralUnionFromEnum(enumType) {
|
|
|
204
209
|
|
|
205
210
|
//#endregion
|
|
206
211
|
//#region lib/client/generate/generate.ts
|
|
207
|
-
async function generateFromSchema({ outputPath, schema, rumbleImportPath = "@m1212e/rumble", apiUrl, useExternalUrqlClient = false }) {
|
|
208
|
-
try {
|
|
212
|
+
async function generateFromSchema({ outputPath, schema, rumbleImportPath = "@m1212e/rumble", apiUrl, useExternalUrqlClient = false, removeExisting = true }) {
|
|
213
|
+
if (removeExisting) try {
|
|
209
214
|
await (0, node_fs_promises.access)(outputPath);
|
|
210
215
|
await (0, node_fs_promises.rm)(outputPath, {
|
|
211
216
|
recursive: true,
|
|
@@ -247,21 +252,23 @@ function makeGraphQLQuery({ queryName, input, client, enableSubscription = false
|
|
|
247
252
|
const otwQueryName = `${(0, es_toolkit.capitalize)(queryName)}Query`;
|
|
248
253
|
const argsString = stringifyArgumentObjectToGraphqlList(input?.[argsKey] ?? {});
|
|
249
254
|
const operationString = (operationVerb) => `${operationVerb} ${otwQueryName} { ${queryName}${argsString} ${input ? `{ ${stringifySelection(input)} }` : ""}}`;
|
|
250
|
-
|
|
251
|
-
const
|
|
255
|
+
const awaitedReturnValueReference = {};
|
|
256
|
+
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) => {
|
|
252
257
|
const data = v.data?.[queryName];
|
|
253
258
|
if (!data && v.error) throw v.error;
|
|
254
259
|
return data;
|
|
255
260
|
}), (0, wonka.onPush)((data) => {
|
|
256
|
-
if (
|
|
257
|
-
})
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
261
|
+
if (typeof data === "object" && data !== null) Object.assign(awaitedReturnValueReference, data);
|
|
262
|
+
}));
|
|
263
|
+
const observable = (0, wonka.toObservable)(source);
|
|
264
|
+
const promise = (0, wonka.toPromise)((0, wonka.pipe)(source, (0, wonka.take)(1), (0, wonka.map)((data) => {
|
|
265
|
+
if (typeof data === "object" && data !== null) {
|
|
266
|
+
Object.assign(awaitedReturnValueReference, data);
|
|
267
|
+
Object.assign(awaitedReturnValueReference, observable);
|
|
268
|
+
return awaitedReturnValueReference;
|
|
269
|
+
}
|
|
270
|
+
return data;
|
|
271
|
+
})));
|
|
265
272
|
Object.assign(promise, observable);
|
|
266
273
|
return promise;
|
|
267
274
|
}
|
|
@@ -274,10 +281,7 @@ function makeGraphQLMutation({ mutationName, input, client }) {
|
|
|
274
281
|
return data;
|
|
275
282
|
}));
|
|
276
283
|
const observable = (0, wonka.toObservable)(response);
|
|
277
|
-
const promise = (0, wonka.toPromise)(
|
|
278
|
-
Object.assign(res, observable);
|
|
279
|
-
return res;
|
|
280
|
-
});
|
|
284
|
+
const promise = (0, wonka.toPromise)((0, wonka.pipe)(response, (0, wonka.take)(1)));
|
|
281
285
|
Object.assign(promise, observable);
|
|
282
286
|
return promise;
|
|
283
287
|
}
|
|
@@ -1132,14 +1136,15 @@ const createWhereArgImplementer = ({ db, schemaBuilder, enumImplementer }) => {
|
|
|
1132
1136
|
//#region lib/client/client.ts
|
|
1133
1137
|
const clientCreatorImplementer = ({ builtSchema }) => {
|
|
1134
1138
|
if (process.env.NODE_ENV !== "development") console.warn("Running rumble client generation in non development mode. Are you sure this is correct?");
|
|
1135
|
-
const clientCreator = async ({ apiUrl, outputPath, rumbleImportPath, useExternalUrqlClient }) => {
|
|
1139
|
+
const clientCreator = async ({ apiUrl, outputPath, rumbleImportPath, useExternalUrqlClient, removeExisting }) => {
|
|
1136
1140
|
if (process.env.NODE_ENV !== "development") console.warn("Running rumble client generation in non development mode. Are you sure this is correct?");
|
|
1137
1141
|
await generateFromSchema({
|
|
1138
1142
|
schema: builtSchema(),
|
|
1139
1143
|
outputPath,
|
|
1140
1144
|
rumbleImportPath,
|
|
1141
1145
|
apiUrl,
|
|
1142
|
-
useExternalUrqlClient
|
|
1146
|
+
useExternalUrqlClient,
|
|
1147
|
+
removeExisting
|
|
1143
1148
|
});
|
|
1144
1149
|
};
|
|
1145
1150
|
return clientCreator;
|