@m1212e/rumble 0.16.22 → 0.16.24
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 +0 -1
- package/out/index.cjs +36 -36
- package/out/index.cjs.map +1 -1
- package/out/index.d.cts +15 -4
- package/out/index.d.cts.map +1 -1
- package/out/index.d.mts +15 -4
- package/out/index.d.mts.map +1 -1
- package/out/index.mjs +36 -36
- package/out/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -113,7 +113,6 @@ const PostRef = schemaBuilder.drizzleObject("posts", {
|
|
|
113
113
|
fields: (t) => ({
|
|
114
114
|
...
|
|
115
115
|
```
|
|
116
|
-
To apply filters in a custom handler implementation, like e.g. your mutations, you can use the `applyFilters` helper exported by rumble to easily filter a list of entities.
|
|
117
116
|
|
|
118
117
|
## Context & Configuration
|
|
119
118
|
The `rumble` initiator offers various configuration options which you can pass. Most importantly, the `context` provider function which creates the request context that is passed to your abilities and resolvers.
|
package/out/index.cjs
CHANGED
|
@@ -218,7 +218,7 @@ function mapNullFieldsToUndefined(obj) {
|
|
|
218
218
|
|
|
219
219
|
//#endregion
|
|
220
220
|
//#region package.json
|
|
221
|
-
var version = "0.16.
|
|
221
|
+
var version = "0.16.24";
|
|
222
222
|
|
|
223
223
|
//#endregion
|
|
224
224
|
//#region lib/helpers/mergeFilters.ts
|
|
@@ -408,9 +408,19 @@ const createAbilityBuilder = ({ db, actions, defaultLimit, otel }) => {
|
|
|
408
408
|
},
|
|
409
409
|
filter: (action) => {
|
|
410
410
|
const actions = Array.isArray(action) ? action : [action];
|
|
411
|
-
return {
|
|
412
|
-
|
|
413
|
-
|
|
411
|
+
return {
|
|
412
|
+
prefetch: (prefetch) => {
|
|
413
|
+
return { by: (explicitFilter) => {
|
|
414
|
+
for (const action of actions) runtimeFilters.get(action).push({
|
|
415
|
+
filter: explicitFilter,
|
|
416
|
+
prefetch
|
|
417
|
+
});
|
|
418
|
+
} };
|
|
419
|
+
},
|
|
420
|
+
by: (explicitFilter) => {
|
|
421
|
+
for (const action of actions) runtimeFilters.get(action).push({ filter: explicitFilter });
|
|
422
|
+
}
|
|
423
|
+
};
|
|
414
424
|
},
|
|
415
425
|
_: {
|
|
416
426
|
runtimeFilters,
|
|
@@ -1432,31 +1442,6 @@ function implementDefaultWhereInputArgs(schemaBuilder) {
|
|
|
1432
1442
|
//#region lib/runtimeFiltersPlugin/filterTypes.ts
|
|
1433
1443
|
const pluginName = "RuntimeFiltersPlugin";
|
|
1434
1444
|
|
|
1435
|
-
//#endregion
|
|
1436
|
-
//#region lib/helpers/applyFilters.ts
|
|
1437
|
-
/**
|
|
1438
|
-
* A helper to apply a list of filters to a given list of entities.
|
|
1439
|
-
*
|
|
1440
|
-
* @example
|
|
1441
|
-
*
|
|
1442
|
-
* ```ts
|
|
1443
|
-
* const filtered = await applyFilters({
|
|
1444
|
-
filters: abilityBuilder.registeredFilters.posts.update,
|
|
1445
|
-
entities: entitiesToFilter,
|
|
1446
|
-
context: ctx,
|
|
1447
|
-
});
|
|
1448
|
-
* ```
|
|
1449
|
-
*/
|
|
1450
|
-
const applyFilters = async ({ filters, entities, context }) => {
|
|
1451
|
-
return Array.from((await Promise.all(filters.map((f) => f({
|
|
1452
|
-
context,
|
|
1453
|
-
entities
|
|
1454
|
-
})))).reduce((acc, val) => {
|
|
1455
|
-
for (const element of val) acc.add(element);
|
|
1456
|
-
return acc;
|
|
1457
|
-
}, /* @__PURE__ */ new Set()));
|
|
1458
|
-
};
|
|
1459
|
-
|
|
1460
1445
|
//#endregion
|
|
1461
1446
|
//#region lib/runtimeFiltersPlugin/runtimeFiltersPlugin.ts
|
|
1462
1447
|
const applyFiltersKey = "applyFilters";
|
|
@@ -1476,15 +1461,30 @@ var RuntimeFiltersPlugin = class extends _pothos_core.BasePlugin {
|
|
|
1476
1461
|
else if (fieldType.kind === "Object") filters = fieldType.ref.currentConfig.pothosOptions[applyFiltersKey];
|
|
1477
1462
|
if (!filters || !Array.isArray(filters) || filters.length === 0) return resolver(parent, args, context, info);
|
|
1478
1463
|
const runFilters = async (span) => {
|
|
1479
|
-
const resolved = await resolver(parent, args, context, info);
|
|
1480
|
-
const allResolvedValues = Array.isArray(resolved) ? resolved : [resolved];
|
|
1481
1464
|
const allFilters = Array.isArray(filters) ? filters : [filters];
|
|
1482
1465
|
span?.setAttribute("filters.total", allFilters.length);
|
|
1483
|
-
const
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1466
|
+
const prefetchedFiltersPromises = Promise.all(allFilters.map(async (filter) => {
|
|
1467
|
+
if (filter.prefetch) {
|
|
1468
|
+
const prefetched = await filter.prefetch({ context });
|
|
1469
|
+
return ({ context, entities }) => filter.filter({
|
|
1470
|
+
context,
|
|
1471
|
+
entities,
|
|
1472
|
+
prefetched
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
return ({ context, entities }) => filter.filter({
|
|
1476
|
+
context,
|
|
1477
|
+
entities
|
|
1478
|
+
});
|
|
1479
|
+
}));
|
|
1480
|
+
const [resolved, prefetchedFilters] = await Promise.all([resolver(parent, args, context, info), prefetchedFiltersPromises]);
|
|
1481
|
+
const allowed = Array.from((await Promise.all(prefetchedFilters.map((f) => f({
|
|
1482
|
+
context,
|
|
1483
|
+
entities: Array.isArray(resolved) ? resolved : [resolved]
|
|
1484
|
+
})))).reduce((acc, val) => {
|
|
1485
|
+
for (const element of val) acc.add(element);
|
|
1486
|
+
return acc;
|
|
1487
|
+
}, /* @__PURE__ */ new Set()));
|
|
1488
1488
|
span?.setAttribute("filters.allowed", allowed.length);
|
|
1489
1489
|
if (Array.isArray(resolved)) return allowed;
|
|
1490
1490
|
return allowed[0] ?? null;
|