@m1212e/rumble 0.12.12 → 0.12.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 CHANGED
@@ -22,35 +22,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
 
23
23
  //#endregion
24
24
  let node_fs_promises = require("node:fs/promises");
25
- node_fs_promises = __toESM(node_fs_promises);
26
25
  let node_path = require("node:path");
27
- node_path = __toESM(node_path);
28
26
  let graphql = require("graphql");
29
- graphql = __toESM(graphql);
30
27
  let es_toolkit = require("es-toolkit");
31
- es_toolkit = __toESM(es_toolkit);
32
28
  let wonka = require("wonka");
33
- wonka = __toESM(wonka);
34
29
  let __escape_tech_graphql_armor = require("@escape.tech/graphql-armor");
35
- __escape_tech_graphql_armor = __toESM(__escape_tech_graphql_armor);
36
30
  let __graphql_yoga_plugin_disable_introspection = require("@graphql-yoga/plugin-disable-introspection");
37
- __graphql_yoga_plugin_disable_introspection = __toESM(__graphql_yoga_plugin_disable_introspection);
38
31
  let graphql_yoga = require("graphql-yoga");
39
- graphql_yoga = __toESM(graphql_yoga);
40
32
  let sofa_api = require("sofa-api");
41
- sofa_api = __toESM(sofa_api);
42
33
  let drizzle_orm = require("drizzle-orm");
43
- drizzle_orm = __toESM(drizzle_orm);
44
34
  let drizzle_orm_casing = require("drizzle-orm/casing");
45
- drizzle_orm_casing = __toESM(drizzle_orm_casing);
46
35
  let drizzle_orm_pg_core = require("drizzle-orm/pg-core");
47
- drizzle_orm_pg_core = __toESM(drizzle_orm_pg_core);
48
36
  let pluralize = require("pluralize");
49
37
  pluralize = __toESM(pluralize);
50
38
  let drizzle_orm_mysql_core = require("drizzle-orm/mysql-core");
51
- drizzle_orm_mysql_core = __toESM(drizzle_orm_mysql_core);
52
39
  let drizzle_orm_sqlite_core = require("drizzle-orm/sqlite-core");
53
- drizzle_orm_sqlite_core = __toESM(drizzle_orm_sqlite_core);
54
40
  let __pothos_core = require("@pothos/core");
55
41
  __pothos_core = __toESM(__pothos_core);
56
42
  let __pothos_plugin_drizzle = require("@pothos/plugin-drizzle");
@@ -58,7 +44,6 @@ __pothos_plugin_drizzle = __toESM(__pothos_plugin_drizzle);
58
44
  let __pothos_plugin_smart_subscriptions = require("@pothos/plugin-smart-subscriptions");
59
45
  __pothos_plugin_smart_subscriptions = __toESM(__pothos_plugin_smart_subscriptions);
60
46
  let graphql_scalars = require("graphql-scalars");
61
- graphql_scalars = __toESM(graphql_scalars);
62
47
 
63
48
  //#region lib/client/generate/client.ts
64
49
  function generateClient({ apiUrl, rumbleImportPath, useExternalUrqlClient, availableSubscriptions }) {
@@ -716,6 +701,8 @@ function tableHelper({ db, table }) {
716
701
  if (!foundRelation) throw new RumbleError(`Could not find schema for ${JSON.stringify(table)}`);
717
702
  const foundSchema = Object.values(db._.schema).find((schema) => schema.dbName === foundRelation.table[drizzleOriginalNameSymbol]);
718
703
  if (!foundSchema) throw new RumbleError(`Could not find schema for ${JSON.stringify(table)}`);
704
+ const fullSchema = db._.fullSchema?.[foundSchema.tsName];
705
+ if (!fullSchema) throw new RumbleError(`Could not find full schema for ${JSON.stringify(table)}`);
719
706
  return {
720
707
  columns: foundSchema.columns,
721
708
  primaryKey: foundSchema.primaryKey,
@@ -723,7 +710,8 @@ function tableHelper({ db, table }) {
723
710
  dbName: foundSchema.dbName,
724
711
  tsName: foundSchema.tsName,
725
712
  foundSchema,
726
- foundRelation
713
+ foundRelation,
714
+ fullSchema
727
715
  };
728
716
  }
729
717
 
@@ -1078,6 +1066,7 @@ const createWhereArgImplementer = ({ db, schemaBuilder, enumImplementer }) => {
1078
1066
  const clientCreatorImplementer = ({ builtSchema }) => {
1079
1067
  if (process.env.NODE_ENV !== "development") console.warn("Running rumble client generation in non development mode. Are you sure this is correct?");
1080
1068
  const clientCreator = async ({ apiUrl, outputPath, rumbleImportPath, useExternalUrqlClient }) => {
1069
+ if (process.env.NODE_ENV !== "development") console.warn("Running rumble client generation in non development mode. Are you sure this is correct?");
1081
1070
  await generateFromSchema({
1082
1071
  schema: builtSchema(),
1083
1072
  outputPath,
@@ -1102,6 +1091,46 @@ const createContextFunction = ({ context: makeUserContext, abilityBuilder }) =>
1102
1091
  };
1103
1092
  };
1104
1093
 
1094
+ //#endregion
1095
+ //#region lib/countQuery.ts
1096
+ const createCountQueryImplementer = ({ db, schemaBuilder, whereArgImplementer, makePubSubInstance }) => {
1097
+ return ({ table, listAction = "read", isAllowed }) => {
1098
+ const WhereArg = whereArgImplementer({ table });
1099
+ const { registerOnInstance } = makePubSubInstance({ table });
1100
+ const tableSchema = tableHelper({
1101
+ db,
1102
+ table
1103
+ });
1104
+ return schemaBuilder.queryFields((t) => {
1105
+ return { [`${pluralize.default.plural(table.toString())}Count`]: t.field({
1106
+ type: "Int",
1107
+ nullable: false,
1108
+ smartSubscription: true,
1109
+ description: `Count all ${pluralize.default.plural(table.toString())}`,
1110
+ subscribe: (subscriptions, _root, _args, _ctx, _info) => {
1111
+ registerOnInstance({
1112
+ instance: subscriptions,
1113
+ action: "created"
1114
+ });
1115
+ registerOnInstance({
1116
+ instance: subscriptions,
1117
+ action: "removed"
1118
+ });
1119
+ },
1120
+ args: { where: t.arg({
1121
+ type: WhereArg,
1122
+ required: false
1123
+ }) },
1124
+ resolve: async (root, args, ctx, info) => {
1125
+ if (isAllowed && !await isAllowed(ctx)) throw new RumbleErrorSafe("Not allowed to perform this action");
1126
+ Object.setPrototypeOf(args, Object.prototype);
1127
+ return db.select({ count: (0, drizzle_orm.count)() }).from(tableSchema.fullSchema).where(ctx.abilities[table].filter(listAction).merge(mapNullFieldsToUndefined(args)).sql.where).then(assertFirstEntryExists).then((r) => r.count);
1128
+ }
1129
+ }) };
1130
+ });
1131
+ };
1132
+ };
1133
+
1105
1134
  //#endregion
1106
1135
  //#region lib/helpers/sofaOpenAPIWebhookDocs.ts
1107
1136
  const sofaOpenAPIWebhookDocs = {
@@ -1849,6 +1878,12 @@ export const db = drizzle(
1849
1878
  orderArgImplementer: orderArg,
1850
1879
  makePubSubInstance
1851
1880
  });
1881
+ const countQuery = createCountQueryImplementer({
1882
+ ...rumbleInput,
1883
+ schemaBuilder,
1884
+ whereArgImplementer: whereArg,
1885
+ makePubSubInstance
1886
+ });
1852
1887
  const builtSchema = lazy(() => schemaBuilder.toSchema());
1853
1888
  const createYoga = (args) => {
1854
1889
  const enableApiDocs = args?.enableApiDocs ?? process?.env?.NODE_ENV === "development";
@@ -1882,7 +1917,8 @@ export const db = drizzle(
1882
1917
  clientCreator: clientCreatorImplementer({
1883
1918
  ...rumbleInput,
1884
1919
  builtSchema
1885
- })
1920
+ }),
1921
+ countQuery
1886
1922
  };
1887
1923
  };
1888
1924