@m1212e/rumble 0.23.10 → 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.mjs CHANGED
@@ -180,7 +180,7 @@ function mapNullFieldsToUndefined(obj) {
180
180
  }
181
181
  //#endregion
182
182
  //#region package.json
183
- var version = "0.23.10";
183
+ var version = "0.23.13";
184
184
  //#endregion
185
185
  //#region lib/helpers/mergeFilters.ts
186
186
  const EmptyFilter$1 = Symbol.for("drizzle:EmptyFilter");
@@ -390,6 +390,7 @@ function buildIndex(db) {
390
390
  columns,
391
391
  primaryKey,
392
392
  relations: entry.relations ?? {},
393
+ isTable: isTable(tableObj),
393
394
  foundRelation: entry
394
395
  };
395
396
  byTsName.set(resolved.name, resolved);
@@ -434,6 +435,7 @@ function tableHelper({ db, table }) {
434
435
  dbName: entry.dbName,
435
436
  tsName: entry.name,
436
437
  table: entry.table,
438
+ isTable: entry.isTable,
437
439
  foundRelation: entry.foundRelation
438
440
  };
439
441
  }
@@ -456,6 +458,10 @@ const makeNothingRegisteredWarner = (logger) => debounce((model, action) => {
456
458
  const createAbilityBuilder = ({ db, actions, defaultLimit, otel, logger: loggerConfig }) => {
457
459
  const log = loggerConfig?.enabled ? loggerConfig.logger : void 0;
458
460
  const nothingRegisteredWarningLogger = makeNothingRegisteredWarner(log);
461
+ const tableRelationNames = Object.keys(db.query).filter((name) => tableHelper({
462
+ db,
463
+ table: name
464
+ }).isTable);
459
465
  let hasBeenBuilt = false;
460
466
  const createBuilderForTable = () => {
461
467
  const queryFilters = /* @__PURE__ */ new Map();
@@ -541,7 +547,7 @@ by: (explicitFilter) => {
541
547
  }
542
548
  };
543
549
  };
544
- const buildersPerTable = Object.fromEntries(Object.keys(db.query).map((tableName) => [tableName, createBuilderForTable()]));
550
+ const buildersPerTable = Object.fromEntries(tableRelationNames.map((tableName) => [tableName, createBuilderForTable()]));
545
551
  return {
546
552
  ...buildersPerTable,
547
553
  /**
@@ -569,7 +575,7 @@ by: (explicitFilter) => {
569
575
  db,
570
576
  table: tableName
571
577
  });
572
- if (Object.keys(tableSchema.primaryKey).length === 0) throw new RumbleError(`No primary key found for entity ${tableName.toString()}`);
578
+ if (Object.keys(tableSchema.primaryKey).length === 0) throw new RumbleError(`No primary key found for entity ${String(tableName)}`);
573
579
  const primaryKeyField = Object.values(tableSchema.primaryKey)[0];
574
580
  const distinctValues = createDistinctValuesFromSQLType(primaryKeyField.getSQLType());
575
581
  const blockEverythingFilter = { where: { AND: [{ [primaryKeyField.name]: distinctValues.value1 }, { [primaryKeyField.name]: distinctValues.value2 }] } };
@@ -719,7 +725,7 @@ by: (explicitFilter) => {
719
725
  }
720
726
  if (!filters) {
721
727
  span?.setAttribute("abilities.status", "blocked_everything");
722
- nothingRegisteredWarningLogger(tableName.toString(), action);
728
+ nothingRegisteredWarningLogger(String(tableName), action);
723
729
  return transformToResponse(blockEverythingFilter);
724
730
  }
725
731
  const dynamicResults = new Array(dynamicQueryFilters[action].length);
@@ -748,10 +754,10 @@ by: (explicitFilter) => {
748
754
  };
749
755
  if (otel?.enabled && otel.tracer) return otel.tracer.startActiveSpan(`rumble.abilities.prepare`, (span) => {
750
756
  span.setAttribute("rumble.action", action);
751
- span.setAttribute("rumble.table", tableName.toString());
757
+ span.setAttribute("rumble.table", String(tableName));
752
758
  try {
753
759
  const attrs = {
754
- "rumble.table": tableName.toString(),
760
+ "rumble.table": String(tableName),
755
761
  "rumble.action": action
756
762
  };
757
763
  const proxy = new Proxy(span, { get(target, prop) {
@@ -770,7 +776,7 @@ by: (explicitFilter) => {
770
776
  });
771
777
  else {
772
778
  const attrs = {
773
- "rumble.table": tableName.toString(),
779
+ "rumble.table": String(tableName),
774
780
  "rumble.action": action
775
781
  };
776
782
  const result = assembleAbilities(log ? { setAttribute: (k, v) => {
@@ -782,10 +788,10 @@ by: (explicitFilter) => {
782
788
  } };
783
789
  } };
784
790
  };
785
- const abilitiesPerTable = Object.fromEntries(Object.keys(db.query).map((tableName) => [tableName, createFilterForTable(tableName)]));
791
+ const abilitiesPerTable = Object.fromEntries(tableRelationNames.map((tableName) => [tableName, createFilterForTable(tableName)]));
786
792
  hasBeenBuilt = true;
787
793
  return (ctx) => {
788
- return Object.fromEntries(Object.keys(abilitiesPerTable).map((tableName) => [tableName, abilitiesPerTable[tableName].withContext(ctx)]));
794
+ return Object.fromEntries(tableRelationNames.map((tableName) => [tableName, abilitiesPerTable[tableName].withContext(ctx)]));
789
795
  };
790
796
  }
791
797
  }
@@ -1191,11 +1197,11 @@ const createCountQueryImplementer = ({ db, schemaBuilder, whereArgImplementer, m
1191
1197
  table
1192
1198
  });
1193
1199
  return schemaBuilder.queryFields((t) => {
1194
- return { [`${pluralize.plural(table.toString())}Count`]: t.field({
1200
+ return { [`${pluralize.plural(String(table))}Count`]: t.field({
1195
1201
  type: "Int",
1196
1202
  nullable: false,
1197
1203
  smartSubscription: true,
1198
- description: `Count all ${pluralize.plural(table.toString())}`,
1204
+ description: `Count all ${pluralize.plural(String(table))}`,
1199
1205
  subscribe: (subscriptions, _root, _args, _ctx, _info) => {
1200
1206
  registerOnInstance({
1201
1207
  instance: subscriptions,
@@ -1662,20 +1668,20 @@ const createObjectImplementer = ({ db, search, logger: loggerConfig, schemaBuild
1662
1668
  });
1663
1669
  if (Object.keys(tableSchema.primaryKey).length === 0) {
1664
1670
  const log = loggerConfig?.enabled ? loggerConfig.logger : void 0;
1665
- const msg = `Could not find primary key for ${table.toString()}. Cannot register subscriptions!`;
1666
- log ? log.warn({ "rumble.table": table.toString() }, msg) : console.warn(msg);
1671
+ const msg = `Could not find primary key for ${String(table)}. Cannot register subscriptions!`;
1672
+ log ? log.warn({ "rumble.table": String(table) }, msg) : console.warn(msg);
1667
1673
  }
1668
1674
  const primaryKey = Object.values(tableSchema.primaryKey)[0];
1669
1675
  const { registerOnInstance } = makePubSubInstance({ table });
1670
1676
  return schemaBuilder.drizzleObject(table, {
1671
- name: refName ?? capitalize(table.toString()),
1677
+ name: refName ?? capitalize(String(table)),
1672
1678
  subscribe: (subscriptions, element, _context) => {
1673
1679
  if (!primaryKey) return;
1674
1680
  const primaryKeyValue = element[primaryKey.name];
1675
1681
  if (!primaryKeyValue) {
1676
1682
  const log = loggerConfig?.enabled ? loggerConfig.logger : void 0;
1677
- const msg = `Could not find primary key value for element on ${table.toString()}. Cannot register subscription!`;
1678
- log ? log.warn({ "rumble.table": table.toString() }, msg) : console.warn(msg);
1683
+ const msg = `Could not find primary key value for element on ${String(table)}. Cannot register subscription!`;
1684
+ log ? log.warn({ "rumble.table": String(table) }, msg) : console.warn(msg);
1679
1685
  return;
1680
1686
  }
1681
1687
  registerOnInstance({
@@ -1921,10 +1927,10 @@ const createQueryImplementer = ({ db, schemaBuilder, search, logger: loggerConfi
1921
1927
  });
1922
1928
  const primaryKeyField = Object.values(tableSchema.primaryKey)[0];
1923
1929
  const { registerOnInstance } = makePubSubInstance({ table });
1924
- const pluralName = pluralize.plural(table.toString());
1925
- const singularName = pluralize.singular(table.toString());
1930
+ const pluralName = pluralize.plural(String(table));
1931
+ const singularName = pluralize.singular(String(table));
1926
1932
  for (const name of [pluralName, singularName]) {
1927
- if (registeredQueryFieldNames.has(name)) throw new RumbleError(`Duplicate query field "${name}": the table "${table.toString()}" 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").`);
1933
+ 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").`);
1928
1934
  registeredQueryFieldNames.add(name);
1929
1935
  }
1930
1936
  return schemaBuilder.queryFields((t) => {