@m1212e/rumble 0.16.23 → 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 +55 -104
- 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 +55 -104
- package/out/index.mjs.map +1 -1
- package/package.json +1 -1
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.
|
|
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 {
|
|
379
|
-
|
|
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
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
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;
|
|
@@ -1612,76 +1612,27 @@ export const db = drizzle(
|
|
|
1612
1612
|
plugins: [
|
|
1613
1613
|
...args?.plugins ?? [],
|
|
1614
1614
|
...enableApiDocs ? [] : [useDisableIntrospection(), EnvelopArmorPlugin()],
|
|
1615
|
-
rumbleInput.otel?.enabled ? {
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
for (const error of result.errors) span.recordException(error);
|
|
1625
|
-
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
1626
|
-
}
|
|
1627
|
-
return result;
|
|
1628
|
-
} catch (error) {
|
|
1629
|
-
if (error instanceof Error) span.recordException(error);
|
|
1615
|
+
rumbleInput.otel?.enabled ? { onExecute: ({ setExecuteFn, executeFn }) => {
|
|
1616
|
+
setExecuteFn((options) => rumbleInput.otel.tracer.startActiveSpan(SpanNames.EXECUTE, { attributes: {
|
|
1617
|
+
[AttributeNames.OPERATION_NAME]: options.operationName ?? "anonymous",
|
|
1618
|
+
[AttributeNames.SOURCE]: options.document
|
|
1619
|
+
} }, async (span) => {
|
|
1620
|
+
try {
|
|
1621
|
+
const result = await executeFn(options);
|
|
1622
|
+
if (result && "errors" in result && result.errors?.length) {
|
|
1623
|
+
for (const error of result.errors) span.recordException(error);
|
|
1630
1624
|
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
1631
|
-
throw error;
|
|
1632
|
-
} finally {
|
|
1633
|
-
span.end();
|
|
1634
1625
|
}
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
} finally {
|
|
1646
|
-
span.end();
|
|
1647
|
-
}
|
|
1648
|
-
}));
|
|
1649
|
-
},
|
|
1650
|
-
onValidate: ({ setValidationFn, validateFn }) => {
|
|
1651
|
-
setValidationFn((...args) => rumbleInput.otel.tracer.startActiveSpan(SpanNames.VALIDATE, (span) => {
|
|
1652
|
-
try {
|
|
1653
|
-
const errors = validateFn(...args);
|
|
1654
|
-
if (errors.length > 0) {
|
|
1655
|
-
for (const error of errors) span.recordException(error);
|
|
1656
|
-
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
1657
|
-
}
|
|
1658
|
-
return errors;
|
|
1659
|
-
} catch (error) {
|
|
1660
|
-
if (error instanceof Error) span.recordException(error);
|
|
1661
|
-
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
1662
|
-
throw error;
|
|
1663
|
-
} finally {
|
|
1664
|
-
span.end();
|
|
1665
|
-
}
|
|
1666
|
-
}));
|
|
1667
|
-
},
|
|
1668
|
-
onSubscribe: ({ setSubscribeFn, subscribeFn }) => {
|
|
1669
|
-
setSubscribeFn((options) => rumbleInput.otel.tracer.startActiveSpan("graphql.subscribe", { attributes: {
|
|
1670
|
-
[AttributeNames.OPERATION_NAME]: options.operationName ?? "anonymous",
|
|
1671
|
-
[AttributeNames.SOURCE]: options.document
|
|
1672
|
-
} }, async (span) => {
|
|
1673
|
-
try {
|
|
1674
|
-
return await subscribeFn(options);
|
|
1675
|
-
} catch (error) {
|
|
1676
|
-
if (error instanceof Error) span.recordException(error);
|
|
1677
|
-
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
1678
|
-
throw error;
|
|
1679
|
-
} finally {
|
|
1680
|
-
span.end();
|
|
1681
|
-
}
|
|
1682
|
-
}));
|
|
1683
|
-
}
|
|
1684
|
-
} : false
|
|
1626
|
+
return result;
|
|
1627
|
+
} catch (error) {
|
|
1628
|
+
if (error instanceof Error) span.recordException(error);
|
|
1629
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
1630
|
+
throw error;
|
|
1631
|
+
} finally {
|
|
1632
|
+
span.end();
|
|
1633
|
+
}
|
|
1634
|
+
}));
|
|
1635
|
+
} } : false
|
|
1685
1636
|
].filter(Boolean)
|
|
1686
1637
|
});
|
|
1687
1638
|
};
|