@m1212e/rumble 0.16.23 → 0.16.27
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 +57 -105
- 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 +58 -106
- package/out/index.mjs.map +1 -1
- package/package.json +1 -1
package/out/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { capitalize, cloneDeep, debounce, merge, toMerged } from "es-toolkit";
|
|
|
9
9
|
import { createPubSub, createYoga } from "graphql-yoga";
|
|
10
10
|
import { useSofa } from "sofa-api";
|
|
11
11
|
import { One, count, relationsFilterToSQL, sql } from "drizzle-orm";
|
|
12
|
-
import { toCamelCase } from "drizzle-orm/casing";
|
|
12
|
+
import { CasingCache, toCamelCase } from "drizzle-orm/casing";
|
|
13
13
|
import { PgEnumColumn, PgTable } from "drizzle-orm/pg-core";
|
|
14
14
|
import pluralize from "pluralize";
|
|
15
15
|
import { MySqlTable } from "drizzle-orm/mysql-core";
|
|
@@ -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.27";
|
|
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,
|
|
@@ -428,7 +438,8 @@ const createAbilityBuilder = ({ db, actions, defaultLimit, otel }) => {
|
|
|
428
438
|
return limit ?? void 0;
|
|
429
439
|
});
|
|
430
440
|
const sqlTransformedWhere = lazy(() => {
|
|
431
|
-
|
|
441
|
+
const casing = db._.session?.dialect?.casing ?? new CasingCache();
|
|
442
|
+
return filters?.where ? relationsFilterToSQL(tableSchema.foundRelation.table, filters.where, tableSchema.relations, db._.relations, casing) : void 0;
|
|
432
443
|
});
|
|
433
444
|
if (filters?.columns) return {
|
|
434
445
|
query: {
|
|
@@ -1399,31 +1410,6 @@ function implementDefaultWhereInputArgs(schemaBuilder) {
|
|
|
1399
1410
|
//#region lib/runtimeFiltersPlugin/filterTypes.ts
|
|
1400
1411
|
const pluginName = "RuntimeFiltersPlugin";
|
|
1401
1412
|
|
|
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
1413
|
//#endregion
|
|
1428
1414
|
//#region lib/runtimeFiltersPlugin/runtimeFiltersPlugin.ts
|
|
1429
1415
|
const applyFiltersKey = "applyFilters";
|
|
@@ -1443,15 +1429,30 @@ var RuntimeFiltersPlugin = class extends BasePlugin {
|
|
|
1443
1429
|
else if (fieldType.kind === "Object") filters = fieldType.ref.currentConfig.pothosOptions[applyFiltersKey];
|
|
1444
1430
|
if (!filters || !Array.isArray(filters) || filters.length === 0) return resolver(parent, args, context, info);
|
|
1445
1431
|
const runFilters = async (span) => {
|
|
1446
|
-
const resolved = await resolver(parent, args, context, info);
|
|
1447
|
-
const allResolvedValues = Array.isArray(resolved) ? resolved : [resolved];
|
|
1448
1432
|
const allFilters = Array.isArray(filters) ? filters : [filters];
|
|
1449
1433
|
span?.setAttribute("filters.total", allFilters.length);
|
|
1450
|
-
const
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1434
|
+
const prefetchedFiltersPromises = Promise.all(allFilters.map(async (filter) => {
|
|
1435
|
+
if (filter.prefetch) {
|
|
1436
|
+
const prefetched = await filter.prefetch({ context });
|
|
1437
|
+
return ({ context, entities }) => filter.filter({
|
|
1438
|
+
context,
|
|
1439
|
+
entities,
|
|
1440
|
+
prefetched
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1443
|
+
return ({ context, entities }) => filter.filter({
|
|
1444
|
+
context,
|
|
1445
|
+
entities
|
|
1446
|
+
});
|
|
1447
|
+
}));
|
|
1448
|
+
const [resolved, prefetchedFilters] = await Promise.all([resolver(parent, args, context, info), prefetchedFiltersPromises]);
|
|
1449
|
+
const allowed = Array.from((await Promise.all(prefetchedFilters.map((f) => f({
|
|
1450
|
+
context,
|
|
1451
|
+
entities: Array.isArray(resolved) ? resolved : [resolved]
|
|
1452
|
+
})))).reduce((acc, val) => {
|
|
1453
|
+
for (const element of val) acc.add(element);
|
|
1454
|
+
return acc;
|
|
1455
|
+
}, /* @__PURE__ */ new Set()));
|
|
1455
1456
|
span?.setAttribute("filters.allowed", allowed.length);
|
|
1456
1457
|
if (Array.isArray(resolved)) return allowed;
|
|
1457
1458
|
return allowed[0] ?? null;
|
|
@@ -1612,76 +1613,27 @@ export const db = drizzle(
|
|
|
1612
1613
|
plugins: [
|
|
1613
1614
|
...args?.plugins ?? [],
|
|
1614
1615
|
...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);
|
|
1616
|
+
rumbleInput.otel?.enabled ? { onExecute: ({ setExecuteFn, executeFn }) => {
|
|
1617
|
+
setExecuteFn((options) => rumbleInput.otel.tracer.startActiveSpan(SpanNames.EXECUTE, { attributes: {
|
|
1618
|
+
[AttributeNames.OPERATION_NAME]: options.operationName ?? "anonymous",
|
|
1619
|
+
[AttributeNames.SOURCE]: options.document
|
|
1620
|
+
} }, async (span) => {
|
|
1621
|
+
try {
|
|
1622
|
+
const result = await executeFn(options);
|
|
1623
|
+
if (result && "errors" in result && result.errors?.length) {
|
|
1624
|
+
for (const error of result.errors) span.recordException(error);
|
|
1630
1625
|
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
1631
|
-
throw error;
|
|
1632
|
-
} finally {
|
|
1633
|
-
span.end();
|
|
1634
1626
|
}
|
|
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
|
|
1627
|
+
return result;
|
|
1628
|
+
} catch (error) {
|
|
1629
|
+
if (error instanceof Error) span.recordException(error);
|
|
1630
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
1631
|
+
throw error;
|
|
1632
|
+
} finally {
|
|
1633
|
+
span.end();
|
|
1634
|
+
}
|
|
1635
|
+
}));
|
|
1636
|
+
} } : false
|
|
1685
1637
|
].filter(Boolean)
|
|
1686
1638
|
});
|
|
1687
1639
|
};
|