@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/out/index.mjs CHANGED
@@ -185,7 +185,7 @@ function mapNullFieldsToUndefined(obj) {
185
185
 
186
186
  //#endregion
187
187
  //#region package.json
188
- var version = "0.16.22";
188
+ var version = "0.16.24";
189
189
 
190
190
  //#endregion
191
191
  //#region lib/helpers/mergeFilters.ts
@@ -375,9 +375,19 @@ const createAbilityBuilder = ({ db, actions, defaultLimit, otel }) => {
375
375
  },
376
376
  filter: (action) => {
377
377
  const actions = Array.isArray(action) ? action : [action];
378
- return { by: (explicitFilter) => {
379
- for (const action of actions) runtimeFilters.get(action).push(explicitFilter);
380
- } };
378
+ return {
379
+ prefetch: (prefetch) => {
380
+ return { by: (explicitFilter) => {
381
+ for (const action of actions) runtimeFilters.get(action).push({
382
+ filter: explicitFilter,
383
+ prefetch
384
+ });
385
+ } };
386
+ },
387
+ by: (explicitFilter) => {
388
+ for (const action of actions) runtimeFilters.get(action).push({ filter: explicitFilter });
389
+ }
390
+ };
381
391
  },
382
392
  _: {
383
393
  runtimeFilters,
@@ -1399,31 +1409,6 @@ function implementDefaultWhereInputArgs(schemaBuilder) {
1399
1409
  //#region lib/runtimeFiltersPlugin/filterTypes.ts
1400
1410
  const pluginName = "RuntimeFiltersPlugin";
1401
1411
 
1402
- //#endregion
1403
- //#region lib/helpers/applyFilters.ts
1404
- /**
1405
- * A helper to apply a list of filters to a given list of entities.
1406
- *
1407
- * @example
1408
- *
1409
- * ```ts
1410
- * const filtered = await applyFilters({
1411
- filters: abilityBuilder.registeredFilters.posts.update,
1412
- entities: entitiesToFilter,
1413
- context: ctx,
1414
- });
1415
- * ```
1416
- */
1417
- const applyFilters = async ({ filters, entities, context }) => {
1418
- return Array.from((await Promise.all(filters.map((f) => f({
1419
- context,
1420
- entities
1421
- })))).reduce((acc, val) => {
1422
- for (const element of val) acc.add(element);
1423
- return acc;
1424
- }, /* @__PURE__ */ new Set()));
1425
- };
1426
-
1427
1412
  //#endregion
1428
1413
  //#region lib/runtimeFiltersPlugin/runtimeFiltersPlugin.ts
1429
1414
  const applyFiltersKey = "applyFilters";
@@ -1443,15 +1428,30 @@ var RuntimeFiltersPlugin = class extends BasePlugin {
1443
1428
  else if (fieldType.kind === "Object") filters = fieldType.ref.currentConfig.pothosOptions[applyFiltersKey];
1444
1429
  if (!filters || !Array.isArray(filters) || filters.length === 0) return resolver(parent, args, context, info);
1445
1430
  const runFilters = async (span) => {
1446
- const resolved = await resolver(parent, args, context, info);
1447
- const allResolvedValues = Array.isArray(resolved) ? resolved : [resolved];
1448
1431
  const allFilters = Array.isArray(filters) ? filters : [filters];
1449
1432
  span?.setAttribute("filters.total", allFilters.length);
1450
- const allowed = await applyFilters({
1451
- filters: allFilters,
1452
- entities: allResolvedValues,
1453
- context
1454
- });
1433
+ const prefetchedFiltersPromises = Promise.all(allFilters.map(async (filter) => {
1434
+ if (filter.prefetch) {
1435
+ const prefetched = await filter.prefetch({ context });
1436
+ return ({ context, entities }) => filter.filter({
1437
+ context,
1438
+ entities,
1439
+ prefetched
1440
+ });
1441
+ }
1442
+ return ({ context, entities }) => filter.filter({
1443
+ context,
1444
+ entities
1445
+ });
1446
+ }));
1447
+ const [resolved, prefetchedFilters] = await Promise.all([resolver(parent, args, context, info), prefetchedFiltersPromises]);
1448
+ const allowed = Array.from((await Promise.all(prefetchedFilters.map((f) => f({
1449
+ context,
1450
+ entities: Array.isArray(resolved) ? resolved : [resolved]
1451
+ })))).reduce((acc, val) => {
1452
+ for (const element of val) acc.add(element);
1453
+ return acc;
1454
+ }, /* @__PURE__ */ new Set()));
1455
1455
  span?.setAttribute("filters.allowed", allowed.length);
1456
1456
  if (Array.isArray(resolved)) return allowed;
1457
1457
  return allowed[0] ?? null;