@m1212e/rumble 0.16.7 → 0.16.15
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 +2 -1
- package/out/client/generate.d.cts.map +1 -1
- package/out/client/generate.d.mts.map +1 -1
- package/out/client/generate.mjs +1 -1
- package/out/client.cjs +37 -32
- package/out/client.cjs.map +1 -1
- package/out/client.d.cts +3 -5
- package/out/client.d.cts.map +1 -1
- package/out/client.d.mts +3 -5
- package/out/client.d.mts.map +1 -1
- package/out/client.mjs +37 -33
- package/out/client.mjs.map +1 -1
- package/out/{generate-D3FWZlGu.cjs → generate-9zSO5f7n.cjs} +5 -3
- package/out/generate-9zSO5f7n.cjs.map +1 -0
- package/out/{generate-DcdqYHG4.mjs → generate-PDRNfY6V.mjs} +3 -1
- package/out/generate-PDRNfY6V.mjs.map +1 -0
- package/out/index.cjs +81 -88
- package/out/index.cjs.map +1 -1
- package/out/index.d.cts +4140 -167
- package/out/index.d.cts.map +1 -1
- package/out/index.d.mts +4140 -167
- package/out/index.d.mts.map +1 -1
- package/out/index.mjs +49 -61
- package/out/index.mjs.map +1 -1
- package/out/lazy-BrDkNRyV.cjs +32 -0
- package/out/lazy-BrDkNRyV.cjs.map +1 -0
- package/out/lazy-CoMVcY4X.mjs +26 -0
- package/out/lazy-CoMVcY4X.mjs.map +1 -0
- package/package.json +20 -19
- package/out/generate-D3FWZlGu.cjs.map +0 -1
- package/out/generate-DcdqYHG4.mjs.map +0 -1
package/out/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as lazy } from "./lazy-CoMVcY4X.mjs";
|
|
2
|
+
import { t as generateFromSchema } from "./generate-PDRNfY6V.mjs";
|
|
2
3
|
import { GraphQLError } from "graphql";
|
|
3
4
|
import { EnvelopArmorPlugin } from "@escape.tech/graphql-armor";
|
|
4
5
|
import { useDisableIntrospection } from "@graphql-yoga/plugin-disable-introspection";
|
|
@@ -37,14 +38,14 @@ var RumbleErrorSafe = class extends GraphQLError {};
|
|
|
37
38
|
//#endregion
|
|
38
39
|
//#region lib/helpers/asserts.ts
|
|
39
40
|
/**
|
|
40
|
-
*
|
|
41
|
+
*
|
|
41
42
|
* Helper function to map a drizzle findFirst query result,
|
|
42
43
|
* which may be optional, to a correct drizzle type.
|
|
43
|
-
*
|
|
44
|
+
*
|
|
44
45
|
* @throws RumbleError
|
|
45
|
-
*
|
|
46
|
+
*
|
|
46
47
|
* @example
|
|
47
|
-
*
|
|
48
|
+
*
|
|
48
49
|
* ```ts
|
|
49
50
|
* schemaBuilder.queryFields((t) => {
|
|
50
51
|
return {
|
|
@@ -71,14 +72,14 @@ const assertFindFirstExists = (value) => {
|
|
|
71
72
|
return value;
|
|
72
73
|
};
|
|
73
74
|
/**
|
|
74
|
-
*
|
|
75
|
+
*
|
|
75
76
|
* Helper function to map a drizzle findFirst query result,
|
|
76
77
|
* which may be optional, to a correct drizzle type.
|
|
77
|
-
*
|
|
78
|
+
*
|
|
78
79
|
* @throws RumbleError
|
|
79
|
-
*
|
|
80
|
+
*
|
|
80
81
|
* @example
|
|
81
|
-
*
|
|
82
|
+
*
|
|
82
83
|
* ```ts
|
|
83
84
|
schemaBuilder.mutationFields((t) => {
|
|
84
85
|
return {
|
|
@@ -179,30 +180,6 @@ function mapNullFieldsToUndefined(obj) {
|
|
|
179
180
|
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, value === null ? void 0 : value]));
|
|
180
181
|
}
|
|
181
182
|
|
|
182
|
-
//#endregion
|
|
183
|
-
//#region lib/helpers/lazy.ts
|
|
184
|
-
/**
|
|
185
|
-
* Creates a lazily initialized function.
|
|
186
|
-
*
|
|
187
|
-
* The returned function will call the initializer function on its first call and
|
|
188
|
-
* store the result. On subsequent calls, it will return the stored result.
|
|
189
|
-
*
|
|
190
|
-
* @param initializer The function to be called for initialization.
|
|
191
|
-
* @returns A function that calls the initializer function on its first call and
|
|
192
|
-
* returns the stored result on subsequent calls.
|
|
193
|
-
*/
|
|
194
|
-
function lazy(initializer) {
|
|
195
|
-
let value;
|
|
196
|
-
let initialized = false;
|
|
197
|
-
return () => {
|
|
198
|
-
if (!initialized) {
|
|
199
|
-
value = initializer();
|
|
200
|
-
initialized = true;
|
|
201
|
-
}
|
|
202
|
-
return value;
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
206
183
|
//#endregion
|
|
207
184
|
//#region lib/helpers/mergeFilters.ts
|
|
208
185
|
function mergeFilters(filterA, filterB) {
|
|
@@ -374,25 +351,25 @@ const createAbilityBuilder = ({ db, actions, defaultLimit }) => {
|
|
|
374
351
|
return {
|
|
375
352
|
allow: (action) => {
|
|
376
353
|
if (hasBeenBuilt) throw new RumbleError("You can't call allow() after the ability builder has been built. Please ensure that you register all abilities before accessing them.");
|
|
377
|
-
const actions
|
|
378
|
-
for (const action
|
|
379
|
-
let filters = queryFilters.get(action
|
|
354
|
+
const actions = Array.isArray(action) ? action : [action];
|
|
355
|
+
for (const action of actions) {
|
|
356
|
+
let filters = queryFilters.get(action);
|
|
380
357
|
if (!filters) {
|
|
381
358
|
filters = "unrestricted";
|
|
382
|
-
queryFilters.set(action
|
|
359
|
+
queryFilters.set(action, filters);
|
|
383
360
|
}
|
|
384
361
|
}
|
|
385
362
|
return { when: (queryFilter) => {
|
|
386
|
-
for (const action
|
|
387
|
-
if (queryFilters.get(action
|
|
388
|
-
queryFilters.get(action
|
|
363
|
+
for (const action of actions) {
|
|
364
|
+
if (queryFilters.get(action) === "unrestricted") queryFilters.set(action, []);
|
|
365
|
+
queryFilters.get(action).push(queryFilter);
|
|
389
366
|
}
|
|
390
367
|
} };
|
|
391
368
|
},
|
|
392
369
|
filter: (action) => {
|
|
393
|
-
const actions
|
|
370
|
+
const actions = Array.isArray(action) ? action : [action];
|
|
394
371
|
return { by: (explicitFilter) => {
|
|
395
|
-
for (const action
|
|
372
|
+
for (const action of actions) runtimeFilters.get(action).push(explicitFilter);
|
|
396
373
|
} };
|
|
397
374
|
},
|
|
398
375
|
_: {
|
|
@@ -432,16 +409,16 @@ const createAbilityBuilder = ({ db, actions, defaultLimit }) => {
|
|
|
432
409
|
/**
|
|
433
410
|
* Packs the filters into a response object that can be applied for queries by the user
|
|
434
411
|
*/
|
|
435
|
-
function transformToResponse(queryFilters
|
|
412
|
+
function transformToResponse(queryFilters) {
|
|
436
413
|
const internalTransformer = (filters, mergedLimit) => {
|
|
437
414
|
const limit = lazy(() => {
|
|
438
415
|
if (mergedLimit !== void 0) {
|
|
439
416
|
if (!filters?.limit) return mergedLimit;
|
|
440
417
|
if (filters.limit > mergedLimit) return mergedLimit;
|
|
441
418
|
}
|
|
442
|
-
let limit
|
|
443
|
-
if (defaultLimit && (limit
|
|
444
|
-
return limit
|
|
419
|
+
let limit = filters?.limit;
|
|
420
|
+
if (defaultLimit && (limit === void 0 || limit > defaultLimit)) limit = defaultLimit;
|
|
421
|
+
return limit ?? void 0;
|
|
445
422
|
});
|
|
446
423
|
const sqlTransformedWhere = lazy(() => {
|
|
447
424
|
return filters?.where ? relationsFilterToSQL(tableSchema.foundRelation.table, filters.where) : void 0;
|
|
@@ -485,14 +462,14 @@ const createAbilityBuilder = ({ db, actions, defaultLimit }) => {
|
|
|
485
462
|
} }
|
|
486
463
|
};
|
|
487
464
|
};
|
|
488
|
-
const ret = internalTransformer(queryFilters
|
|
465
|
+
const ret = internalTransformer(queryFilters);
|
|
489
466
|
/**
|
|
490
467
|
* Merges the current query filters with the provided filters for this call only
|
|
491
468
|
*/
|
|
492
|
-
function merge
|
|
469
|
+
function merge(p) {
|
|
493
470
|
return internalTransformer(mergeFilters(ret.query.many, p), p.limit);
|
|
494
471
|
}
|
|
495
|
-
ret.merge = merge
|
|
472
|
+
ret.merge = merge;
|
|
496
473
|
return ret;
|
|
497
474
|
}
|
|
498
475
|
return { withContext: (userContext) => {
|
|
@@ -706,7 +683,13 @@ const createWhereArgImplementer = ({ db, schemaBuilder, enumImplementer }) => {
|
|
|
706
683
|
//#region lib/client/client.ts
|
|
707
684
|
const clientCreatorImplementer = ({ builtSchema }) => {
|
|
708
685
|
const clientCreator = async ({ apiUrl, outputPath, rumbleImportPath, useExternalUrqlClient, removeExisting, forceReactivity }) => {
|
|
709
|
-
if (process.env.NODE_ENV !== "development") console.warn(
|
|
686
|
+
if (process.env.NODE_ENV !== "development") console.warn(`Running rumble client generation in non development mode. Are you sure this is correct? Called from ${__filename} with arguments: ${JSON.stringify({
|
|
687
|
+
outputPath,
|
|
688
|
+
apiUrl,
|
|
689
|
+
rumbleImportPath,
|
|
690
|
+
useExternalUrqlClient,
|
|
691
|
+
removeExisting
|
|
692
|
+
})}`);
|
|
710
693
|
await generateFromSchema({
|
|
711
694
|
schema: builtSchema(),
|
|
712
695
|
outputPath,
|
|
@@ -1008,7 +991,7 @@ const createObjectImplementer = ({ db, search, schemaBuilder, makePubSubInstance
|
|
|
1008
991
|
fields: (t) => {
|
|
1009
992
|
const columns = tableSchema.columns;
|
|
1010
993
|
const configMap = /* @__PURE__ */ new Map();
|
|
1011
|
-
const userAdjustments = adjust?.(new Proxy(t, { get: (target, prop) => {
|
|
994
|
+
const userAdjustments = adjust?.(new Proxy(t, { get: (target, prop, receiver) => {
|
|
1012
995
|
if (typeof target[prop] !== "function" || prop === "arg" || prop === "builder" || prop === "graphqlKind" || prop === "kind" || prop === "listRef" || prop === "table" || prop === "typename" || prop === "variant" || prop.toString().startsWith("boolean") || prop.toString().startsWith("float") || prop.toString().startsWith("id") || prop.toString().startsWith("int") || prop.toString().startsWith("string") || prop.toString().startsWith("expose")) return target[prop];
|
|
1013
996
|
return (...params) => {
|
|
1014
997
|
const ref = target[prop](...params);
|
|
@@ -1098,21 +1081,21 @@ const createObjectImplementer = ({ db, search, schemaBuilder, makePubSubInstance
|
|
|
1098
1081
|
subscribe,
|
|
1099
1082
|
nullable,
|
|
1100
1083
|
description: `Get the ${pluralize.plural(relationSchema.tsName)} related to this ${pluralize.singular(tableSchema.tsName)}`,
|
|
1101
|
-
query: (args
|
|
1102
|
-
args
|
|
1084
|
+
query: (args, ctx) => {
|
|
1085
|
+
args = JSON.parse(JSON.stringify(args));
|
|
1103
1086
|
if (isMany) adjustQueryArgsForSearch({
|
|
1104
1087
|
search,
|
|
1105
|
-
args
|
|
1088
|
+
args,
|
|
1106
1089
|
tableSchema: relationSchema,
|
|
1107
1090
|
abilities: ctx.abilities[relationSchema.tsName].filter(readAction)
|
|
1108
1091
|
});
|
|
1109
1092
|
const filter = ctx.abilities[relationSchema.tsName].filter(readAction).merge({
|
|
1110
|
-
where: args
|
|
1111
|
-
limit: args
|
|
1112
|
-
extras: args
|
|
1093
|
+
where: args.where,
|
|
1094
|
+
limit: args.limit,
|
|
1095
|
+
extras: args.extras
|
|
1113
1096
|
}).query[filterSpecifier];
|
|
1114
|
-
if (args
|
|
1115
|
-
if (args
|
|
1097
|
+
if (args.offset) filter.offset = args.offset;
|
|
1098
|
+
if (args.orderBy) filter.orderBy = args.orderBy;
|
|
1116
1099
|
return filter;
|
|
1117
1100
|
}
|
|
1118
1101
|
});
|
|
@@ -1185,10 +1168,10 @@ const createPubSubInstance = ({ subscriptions }) => {
|
|
|
1185
1168
|
return pubsub.publish(key);
|
|
1186
1169
|
},
|
|
1187
1170
|
updated(primaryKeyValue) {
|
|
1188
|
-
const keys = (Array.isArray(primaryKeyValue) ? primaryKeyValue : [primaryKeyValue]).map((primaryKeyValue
|
|
1171
|
+
const keys = (Array.isArray(primaryKeyValue) ? primaryKeyValue : [primaryKeyValue]).map((primaryKeyValue) => makePubSubKey({
|
|
1189
1172
|
tableName: table.toString(),
|
|
1190
1173
|
action: "updated",
|
|
1191
|
-
primaryKeyValue
|
|
1174
|
+
primaryKeyValue
|
|
1192
1175
|
}));
|
|
1193
1176
|
const uniqueKeys = Array.from(new Set(keys));
|
|
1194
1177
|
for (const key of uniqueKeys) pubsub.publish(key);
|
|
@@ -1259,6 +1242,11 @@ const createQueryImplementer = ({ db, schemaBuilder, search, whereArgImplementer
|
|
|
1259
1242
|
if (mappedArgs.orderBy) filter.orderBy = mappedArgs.orderBy;
|
|
1260
1243
|
const queryInstance = query(filter);
|
|
1261
1244
|
if (filter.columns) queryInstance.columns = filter.columns;
|
|
1245
|
+
if (search?.cpu_operator_cost) return db.transaction(async (tx) => {
|
|
1246
|
+
if (isPostgresDB(tx)) await tx.execute(sql`SET LOCAL cpu_operator_cost = ${search.cpu_operator_cost};`);
|
|
1247
|
+
else console.info("Database dialect is not postgresql, cannot set cpu_operator_cost.");
|
|
1248
|
+
return tx.query[table].findMany(queryInstance);
|
|
1249
|
+
});
|
|
1262
1250
|
return db.query[table].findMany(queryInstance);
|
|
1263
1251
|
}
|
|
1264
1252
|
}),
|