@m1212e/rumble 0.23.11 → 0.23.13
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.cjs +25 -19
- package/out/index.cjs.map +1 -1
- package/out/index.d.cts +29 -22
- package/out/index.d.cts.map +1 -1
- package/out/index.d.mts +29 -22
- package/out/index.d.mts.map +1 -1
- package/out/index.mjs +25 -19
- package/out/index.mjs.map +1 -1
- package/package.json +1 -1
package/out/index.cjs
CHANGED
|
@@ -208,7 +208,7 @@ function mapNullFieldsToUndefined(obj) {
|
|
|
208
208
|
}
|
|
209
209
|
//#endregion
|
|
210
210
|
//#region package.json
|
|
211
|
-
var version = "0.23.
|
|
211
|
+
var version = "0.23.13";
|
|
212
212
|
//#endregion
|
|
213
213
|
//#region lib/helpers/mergeFilters.ts
|
|
214
214
|
const EmptyFilter$1 = Symbol.for("drizzle:EmptyFilter");
|
|
@@ -418,6 +418,7 @@ function buildIndex(db) {
|
|
|
418
418
|
columns,
|
|
419
419
|
primaryKey,
|
|
420
420
|
relations: entry.relations ?? {},
|
|
421
|
+
isTable: (0, drizzle_orm.isTable)(tableObj),
|
|
421
422
|
foundRelation: entry
|
|
422
423
|
};
|
|
423
424
|
byTsName.set(resolved.name, resolved);
|
|
@@ -462,6 +463,7 @@ function tableHelper({ db, table }) {
|
|
|
462
463
|
dbName: entry.dbName,
|
|
463
464
|
tsName: entry.name,
|
|
464
465
|
table: entry.table,
|
|
466
|
+
isTable: entry.isTable,
|
|
465
467
|
foundRelation: entry.foundRelation
|
|
466
468
|
};
|
|
467
469
|
}
|
|
@@ -484,6 +486,10 @@ const makeNothingRegisteredWarner = (logger) => (0, es_toolkit.debounce)((model,
|
|
|
484
486
|
const createAbilityBuilder = ({ db, actions, defaultLimit, otel, logger: loggerConfig }) => {
|
|
485
487
|
const log = loggerConfig?.enabled ? loggerConfig.logger : void 0;
|
|
486
488
|
const nothingRegisteredWarningLogger = makeNothingRegisteredWarner(log);
|
|
489
|
+
const tableRelationNames = Object.keys(db.query).filter((name) => tableHelper({
|
|
490
|
+
db,
|
|
491
|
+
table: name
|
|
492
|
+
}).isTable);
|
|
487
493
|
let hasBeenBuilt = false;
|
|
488
494
|
const createBuilderForTable = () => {
|
|
489
495
|
const queryFilters = /* @__PURE__ */ new Map();
|
|
@@ -569,7 +575,7 @@ by: (explicitFilter) => {
|
|
|
569
575
|
}
|
|
570
576
|
};
|
|
571
577
|
};
|
|
572
|
-
const buildersPerTable = Object.fromEntries(
|
|
578
|
+
const buildersPerTable = Object.fromEntries(tableRelationNames.map((tableName) => [tableName, createBuilderForTable()]));
|
|
573
579
|
return {
|
|
574
580
|
...buildersPerTable,
|
|
575
581
|
/**
|
|
@@ -597,7 +603,7 @@ by: (explicitFilter) => {
|
|
|
597
603
|
db,
|
|
598
604
|
table: tableName
|
|
599
605
|
});
|
|
600
|
-
if (Object.keys(tableSchema.primaryKey).length === 0) throw new RumbleError(`No primary key found for entity ${tableName
|
|
606
|
+
if (Object.keys(tableSchema.primaryKey).length === 0) throw new RumbleError(`No primary key found for entity ${String(tableName)}`);
|
|
601
607
|
const primaryKeyField = Object.values(tableSchema.primaryKey)[0];
|
|
602
608
|
const distinctValues = createDistinctValuesFromSQLType(primaryKeyField.getSQLType());
|
|
603
609
|
const blockEverythingFilter = { where: { AND: [{ [primaryKeyField.name]: distinctValues.value1 }, { [primaryKeyField.name]: distinctValues.value2 }] } };
|
|
@@ -747,7 +753,7 @@ by: (explicitFilter) => {
|
|
|
747
753
|
}
|
|
748
754
|
if (!filters) {
|
|
749
755
|
span?.setAttribute("abilities.status", "blocked_everything");
|
|
750
|
-
nothingRegisteredWarningLogger(tableName
|
|
756
|
+
nothingRegisteredWarningLogger(String(tableName), action);
|
|
751
757
|
return transformToResponse(blockEverythingFilter);
|
|
752
758
|
}
|
|
753
759
|
const dynamicResults = new Array(dynamicQueryFilters[action].length);
|
|
@@ -776,10 +782,10 @@ by: (explicitFilter) => {
|
|
|
776
782
|
};
|
|
777
783
|
if (otel?.enabled && otel.tracer) return otel.tracer.startActiveSpan(`rumble.abilities.prepare`, (span) => {
|
|
778
784
|
span.setAttribute("rumble.action", action);
|
|
779
|
-
span.setAttribute("rumble.table", tableName
|
|
785
|
+
span.setAttribute("rumble.table", String(tableName));
|
|
780
786
|
try {
|
|
781
787
|
const attrs = {
|
|
782
|
-
"rumble.table": tableName
|
|
788
|
+
"rumble.table": String(tableName),
|
|
783
789
|
"rumble.action": action
|
|
784
790
|
};
|
|
785
791
|
const proxy = new Proxy(span, { get(target, prop) {
|
|
@@ -798,7 +804,7 @@ by: (explicitFilter) => {
|
|
|
798
804
|
});
|
|
799
805
|
else {
|
|
800
806
|
const attrs = {
|
|
801
|
-
"rumble.table": tableName
|
|
807
|
+
"rumble.table": String(tableName),
|
|
802
808
|
"rumble.action": action
|
|
803
809
|
};
|
|
804
810
|
const result = assembleAbilities(log ? { setAttribute: (k, v) => {
|
|
@@ -810,10 +816,10 @@ by: (explicitFilter) => {
|
|
|
810
816
|
} };
|
|
811
817
|
} };
|
|
812
818
|
};
|
|
813
|
-
const abilitiesPerTable = Object.fromEntries(
|
|
819
|
+
const abilitiesPerTable = Object.fromEntries(tableRelationNames.map((tableName) => [tableName, createFilterForTable(tableName)]));
|
|
814
820
|
hasBeenBuilt = true;
|
|
815
821
|
return (ctx) => {
|
|
816
|
-
return Object.fromEntries(
|
|
822
|
+
return Object.fromEntries(tableRelationNames.map((tableName) => [tableName, abilitiesPerTable[tableName].withContext(ctx)]));
|
|
817
823
|
};
|
|
818
824
|
}
|
|
819
825
|
}
|
|
@@ -1219,11 +1225,11 @@ const createCountQueryImplementer = ({ db, schemaBuilder, whereArgImplementer, m
|
|
|
1219
1225
|
table
|
|
1220
1226
|
});
|
|
1221
1227
|
return schemaBuilder.queryFields((t) => {
|
|
1222
|
-
return { [`${pluralize.default.plural(table
|
|
1228
|
+
return { [`${pluralize.default.plural(String(table))}Count`]: t.field({
|
|
1223
1229
|
type: "Int",
|
|
1224
1230
|
nullable: false,
|
|
1225
1231
|
smartSubscription: true,
|
|
1226
|
-
description: `Count all ${pluralize.default.plural(table
|
|
1232
|
+
description: `Count all ${pluralize.default.plural(String(table))}`,
|
|
1227
1233
|
subscribe: (subscriptions, _root, _args, _ctx, _info) => {
|
|
1228
1234
|
registerOnInstance({
|
|
1229
1235
|
instance: subscriptions,
|
|
@@ -1690,20 +1696,20 @@ const createObjectImplementer = ({ db, search, logger: loggerConfig, schemaBuild
|
|
|
1690
1696
|
});
|
|
1691
1697
|
if (Object.keys(tableSchema.primaryKey).length === 0) {
|
|
1692
1698
|
const log = loggerConfig?.enabled ? loggerConfig.logger : void 0;
|
|
1693
|
-
const msg = `Could not find primary key for ${table
|
|
1694
|
-
log ? log.warn({ "rumble.table": table
|
|
1699
|
+
const msg = `Could not find primary key for ${String(table)}. Cannot register subscriptions!`;
|
|
1700
|
+
log ? log.warn({ "rumble.table": String(table) }, msg) : console.warn(msg);
|
|
1695
1701
|
}
|
|
1696
1702
|
const primaryKey = Object.values(tableSchema.primaryKey)[0];
|
|
1697
1703
|
const { registerOnInstance } = makePubSubInstance({ table });
|
|
1698
1704
|
return schemaBuilder.drizzleObject(table, {
|
|
1699
|
-
name: refName ?? (0, es_toolkit.capitalize)(table
|
|
1705
|
+
name: refName ?? (0, es_toolkit.capitalize)(String(table)),
|
|
1700
1706
|
subscribe: (subscriptions, element, _context) => {
|
|
1701
1707
|
if (!primaryKey) return;
|
|
1702
1708
|
const primaryKeyValue = element[primaryKey.name];
|
|
1703
1709
|
if (!primaryKeyValue) {
|
|
1704
1710
|
const log = loggerConfig?.enabled ? loggerConfig.logger : void 0;
|
|
1705
|
-
const msg = `Could not find primary key value for element on ${table
|
|
1706
|
-
log ? log.warn({ "rumble.table": table
|
|
1711
|
+
const msg = `Could not find primary key value for element on ${String(table)}. Cannot register subscription!`;
|
|
1712
|
+
log ? log.warn({ "rumble.table": String(table) }, msg) : console.warn(msg);
|
|
1707
1713
|
return;
|
|
1708
1714
|
}
|
|
1709
1715
|
registerOnInstance({
|
|
@@ -1949,10 +1955,10 @@ const createQueryImplementer = ({ db, schemaBuilder, search, logger: loggerConfi
|
|
|
1949
1955
|
});
|
|
1950
1956
|
const primaryKeyField = Object.values(tableSchema.primaryKey)[0];
|
|
1951
1957
|
const { registerOnInstance } = makePubSubInstance({ table });
|
|
1952
|
-
const pluralName = pluralize.default.plural(table
|
|
1953
|
-
const singularName = pluralize.default.singular(table
|
|
1958
|
+
const pluralName = pluralize.default.plural(String(table));
|
|
1959
|
+
const singularName = pluralize.default.singular(String(table));
|
|
1954
1960
|
for (const name of [pluralName, singularName]) {
|
|
1955
|
-
if (registeredQueryFieldNames.has(name)) throw new RumbleError(`Duplicate query field "${name}": the table "${table
|
|
1961
|
+
if (registeredQueryFieldNames.has(name)) throw new RumbleError(`Duplicate query field "${name}": the table "${String(table)}" generates a query field that collides with one already registered. Use unique table names (or refNames) to avoid plural/singular collisions (e.g. "post" and "posts").`);
|
|
1956
1962
|
registeredQueryFieldNames.add(name);
|
|
1957
1963
|
}
|
|
1958
1964
|
return schemaBuilder.queryFields((t) => {
|