@m1212e/rumble 0.18.8 → 0.20.0
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/client/generate.cjs +1 -1
- package/out/client/generate.d.cts.map +1 -1
- package/out/client/generate.d.mts.map +1 -1
- package/out/client/generate.mjs +1 -1
- package/out/client.cjs +2 -3
- package/out/client.cjs.map +1 -1
- package/out/client.d.cts +7 -3
- package/out/client.d.cts.map +1 -1
- package/out/client.d.mts +7 -3
- package/out/client.d.mts.map +1 -1
- package/out/client.mjs +2 -2
- package/out/client.mjs.map +1 -1
- package/out/{generate-BxAyU8HE.mjs → generate-B4w-hX0K.mjs} +1 -1
- package/out/{generate-BxAyU8HE.mjs.map → generate-B4w-hX0K.mjs.map} +1 -1
- package/out/{generate-v10zBoUq.cjs → generate-Ch5LEiBr.cjs} +1 -2
- package/out/{generate-v10zBoUq.cjs.map → generate-Ch5LEiBr.cjs.map} +1 -1
- package/out/index.cjs +40 -47
- package/out/index.cjs.map +1 -1
- package/out/index.d.cts +35 -41
- package/out/index.d.cts.map +1 -1
- package/out/index.d.mts +33 -39
- package/out/index.d.mts.map +1 -1
- package/out/index.mjs +41 -47
- package/out/index.mjs.map +1 -1
- package/out/{lazy-BgeBy3-B.mjs → lazy-C7IyM4M4.mjs} +1 -1
- package/out/{lazy-BgeBy3-B.mjs.map → lazy-C7IyM4M4.mjs.map} +1 -1
- package/out/{lazy-DT--QoPa.cjs → lazy-CAN0oaXD.cjs} +1 -1
- package/out/{lazy-DT--QoPa.cjs.map → lazy-CAN0oaXD.cjs.map} +1 -1
- package/package.json +20 -20
package/out/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as lazy } from "./lazy-
|
|
2
|
-
import { t as generateFromSchema } from "./generate-
|
|
1
|
+
import { t as lazy } from "./lazy-C7IyM4M4.mjs";
|
|
2
|
+
import { t as generateFromSchema } from "./generate-B4w-hX0K.mjs";
|
|
3
3
|
import { GraphQLError } from "graphql";
|
|
4
4
|
import { EnvelopArmorPlugin } from "@escape.tech/graphql-armor";
|
|
5
5
|
import { useDisableIntrospection } from "@graphql-yoga/plugin-disable-introspection";
|
|
@@ -8,7 +8,7 @@ import { AttributeNames, SpanNames, createOpenTelemetryWrapper } from "@pothos/t
|
|
|
8
8
|
import { capitalize, cloneDeep, debounce, merge, toMerged } from "es-toolkit";
|
|
9
9
|
import { createPubSub, createYoga } from "graphql-yoga";
|
|
10
10
|
import { One, count, relationsFilterToSQL, sql } from "drizzle-orm";
|
|
11
|
-
import {
|
|
11
|
+
import { toCamelCase } from "drizzle-orm/casing";
|
|
12
12
|
import { PgEnumColumn, PgTable } from "drizzle-orm/pg-core";
|
|
13
13
|
import pluralize from "pluralize";
|
|
14
14
|
import { MySqlTable } from "drizzle-orm/mysql-core";
|
|
@@ -180,7 +180,7 @@ function mapNullFieldsToUndefined(obj) {
|
|
|
180
180
|
}
|
|
181
181
|
//#endregion
|
|
182
182
|
//#region package.json
|
|
183
|
-
var version = "0.
|
|
183
|
+
var version = "0.20.0";
|
|
184
184
|
//#endregion
|
|
185
185
|
//#region lib/helpers/mergeFilters.ts
|
|
186
186
|
function mergeFilters(filterA, filterB, mode = "AND") {
|
|
@@ -303,23 +303,28 @@ function createDistinctValuesFromSQLType(sqlType) {
|
|
|
303
303
|
const drizzleNameSymbol = Symbol.for("drizzle:Name");
|
|
304
304
|
const drizzleOriginalNameSymbol = Symbol.for("drizzle:OriginalName");
|
|
305
305
|
const drizzleBaseNameSymbol = Symbol.for("drizzle:BaseName");
|
|
306
|
+
const drizzleColumnsSymbol = Symbol.for("drizzle:Columns");
|
|
306
307
|
function tableHelper({ db, table }) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
const
|
|
313
|
-
if (!
|
|
308
|
+
let tableName;
|
|
309
|
+
if (typeof table !== "string") {
|
|
310
|
+
const t = table;
|
|
311
|
+
tableName = t.name ?? t[drizzleNameSymbol] ?? t[drizzleOriginalNameSymbol] ?? t[drizzleBaseNameSymbol];
|
|
312
|
+
} else tableName = table;
|
|
313
|
+
const foundRelation = Object.values(db._.relations).find((entry) => entry.name === tableName || entry.table[drizzleNameSymbol] === tableName || entry.table[drizzleOriginalNameSymbol] === tableName || entry.table[drizzleBaseNameSymbol] === tableName);
|
|
314
|
+
if (!foundRelation) throw new RumbleError(`Could not find schema for ${JSON.stringify(tableName)}`);
|
|
315
|
+
const tableObj = foundRelation.table;
|
|
316
|
+
const columns = tableObj[drizzleColumnsSymbol] ?? {};
|
|
317
|
+
const primaryKey = Object.fromEntries(Object.entries(columns).filter(([_, col]) => col.primary));
|
|
318
|
+
const dbName = tableObj[drizzleOriginalNameSymbol] ?? tableObj[drizzleBaseNameSymbol] ?? tableObj[drizzleNameSymbol] ?? foundRelation.name;
|
|
319
|
+
const tsName = foundRelation.name;
|
|
314
320
|
return {
|
|
315
|
-
columns
|
|
316
|
-
primaryKey
|
|
321
|
+
columns,
|
|
322
|
+
primaryKey,
|
|
317
323
|
relations: foundRelation.relations,
|
|
318
|
-
dbName
|
|
319
|
-
tsName
|
|
320
|
-
|
|
321
|
-
foundRelation
|
|
322
|
-
fullSchema
|
|
324
|
+
dbName,
|
|
325
|
+
tsName,
|
|
326
|
+
table: tableObj,
|
|
327
|
+
foundRelation
|
|
323
328
|
};
|
|
324
329
|
}
|
|
325
330
|
//#endregion
|
|
@@ -472,7 +477,7 @@ by: (explicitFilter) => {
|
|
|
472
477
|
return limit ?? void 0;
|
|
473
478
|
});
|
|
474
479
|
const sqlTransformedWhere = lazy(() => {
|
|
475
|
-
const casing = db._.session?.dialect?.casing
|
|
480
|
+
const casing = db._.session?.dialect?.casing;
|
|
476
481
|
return filters?.where ? relationsFilterToSQL(tableSchema.foundRelation.table, filters.where, tableSchema.relations, db._.relations, casing) : void 0;
|
|
477
482
|
});
|
|
478
483
|
if (filters?.columns) return {
|
|
@@ -698,27 +703,30 @@ const createOrderArgImplementer = ({ db, schemaBuilder }) => {
|
|
|
698
703
|
//#endregion
|
|
699
704
|
//#region lib/enum.ts
|
|
700
705
|
/**
|
|
701
|
-
* Checks if a
|
|
706
|
+
* Checks if a column is a PgEnumColumn
|
|
702
707
|
*/
|
|
703
708
|
function isEnumSchema(schemaType) {
|
|
704
709
|
return schemaType instanceof PgEnumColumn;
|
|
705
710
|
}
|
|
706
|
-
const createEnumImplementer = ({
|
|
711
|
+
const createEnumImplementer = ({ schemaBuilder }) => {
|
|
707
712
|
const referenceStorage = /* @__PURE__ */ new Map();
|
|
708
|
-
|
|
713
|
+
/**
|
|
714
|
+
* Registers a Postgres enum as a GraphQL enum type.
|
|
715
|
+
*
|
|
716
|
+
* Pass the `enum` option with the pgEnum object (e.g. `moodEnum`),
|
|
717
|
+
* or pass the `enumColumn` option with a column that uses the enum.
|
|
718
|
+
* Use `refName` to override the auto-generated GraphQL type name.
|
|
719
|
+
*/
|
|
720
|
+
const enumImplementer = ({ enum: enumObject, enumColumn, refName }) => {
|
|
709
721
|
let enumSchemaName;
|
|
710
722
|
let enumValues;
|
|
711
|
-
if (
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
const enumCol = Object.values(db._.schema).filter((s) => typeof s === "object").map((s) => Object.values(s.columns)).flat(2).filter(isEnumSchema).find((e) => e.config.enum === schemaEnum);
|
|
715
|
-
if (!enumCol) throw new RumbleError(`Could not find applied enum column for ${tsName.toString()}.
|
|
716
|
-
Please ensure that you use the enum at least once as a column of a table!`);
|
|
717
|
-
enumValues = enumCol.enumValues;
|
|
723
|
+
if (enumObject) {
|
|
724
|
+
enumSchemaName = enumObject.enumName;
|
|
725
|
+
enumValues = enumObject.enumValues;
|
|
718
726
|
} else if (enumColumn) {
|
|
719
|
-
const
|
|
720
|
-
if (!
|
|
721
|
-
enumSchemaName =
|
|
727
|
+
const pgEnum = enumColumn.enum;
|
|
728
|
+
if (!pgEnum) throw new RumbleError(`Could not find enum definition on column. Make sure the column is a pgEnum column.`);
|
|
729
|
+
enumSchemaName = pgEnum.enumName;
|
|
722
730
|
enumValues = enumColumn.enumValues;
|
|
723
731
|
}
|
|
724
732
|
if (!enumSchemaName || !enumValues) throw new RumbleError("Could not determine enum structure!");
|
|
@@ -894,7 +902,7 @@ const createCountQueryImplementer = ({ db, schemaBuilder, whereArgImplementer, m
|
|
|
894
902
|
resolve: async (root, args, ctx, info) => {
|
|
895
903
|
if (isAllowed && !await isAllowed(ctx)) throw new RumbleErrorSafe("Not allowed to perform this action");
|
|
896
904
|
deepSetProto(args);
|
|
897
|
-
return db.select({ count: count() }).from(tableSchema.
|
|
905
|
+
return db.select({ count: count() }).from(tableSchema.table).where(ctx.abilities[table].filter(listAction).merge(mapNullFieldsToUndefined(args)).sql.where).then(assertFirstEntryExists).then((r) => r.count);
|
|
898
906
|
}
|
|
899
907
|
}) };
|
|
900
908
|
});
|
|
@@ -1639,19 +1647,6 @@ const createSchemaBuilder = ({ db, disableDefaultObjects, pubsub, pothosConfig,
|
|
|
1639
1647
|
//#endregion
|
|
1640
1648
|
//#region lib/rumble.ts
|
|
1641
1649
|
const rumble = (rumbleInput) => {
|
|
1642
|
-
if (!rumbleInput.db._.schema) throw new RumbleError(`
|
|
1643
|
-
rumble could not find any schema in the provided drizzle instance.
|
|
1644
|
-
Make sure you import the schema and pass it to the drizzle instance:
|
|
1645
|
-
|
|
1646
|
-
export const db = drizzle(
|
|
1647
|
-
"postgres://postgres:postgres@localhost:5432/postgres",
|
|
1648
|
-
{
|
|
1649
|
-
relations,
|
|
1650
|
-
schema, // <--- add this line
|
|
1651
|
-
},
|
|
1652
|
-
);
|
|
1653
|
-
|
|
1654
|
-
`);
|
|
1655
1650
|
if (!rumbleInput.db._.relations) throw new RumbleError(`
|
|
1656
1651
|
rumble could not find any relations in the provided drizzle instance.
|
|
1657
1652
|
Make sure you import the relations and pass them to the drizzle instance:
|
|
@@ -1660,7 +1655,6 @@ export const db = drizzle(
|
|
|
1660
1655
|
"postgres://postgres:postgres@localhost:5432/postgres",
|
|
1661
1656
|
{
|
|
1662
1657
|
relations, // <--- add this line
|
|
1663
|
-
schema,
|
|
1664
1658
|
},
|
|
1665
1659
|
);
|
|
1666
1660
|
|