@m1212e/rumble 0.23.5 → 0.23.8
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 +37 -29
- package/out/index.cjs.map +1 -1
- package/out/index.d.cts +13 -1
- package/out/index.d.cts.map +1 -1
- package/out/index.d.mts +13 -1
- package/out/index.d.mts.map +1 -1
- package/out/index.mjs +37 -29
- package/out/index.mjs.map +1 -1
- package/package.json +1 -1
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.
|
|
183
|
+
var version = "0.23.8";
|
|
184
184
|
//#endregion
|
|
185
185
|
//#region lib/helpers/mergeFilters.ts
|
|
186
186
|
const EmptyFilter$1 = Symbol.for("drizzle:EmptyFilter");
|
|
@@ -211,6 +211,20 @@ function mergeFilters(filterA, filterB, mode = "AND") {
|
|
|
211
211
|
};
|
|
212
212
|
}
|
|
213
213
|
//#endregion
|
|
214
|
+
//#region lib/helpers/sanitizeFilterValue.ts
|
|
215
|
+
const EmptyFilter = Symbol.for("drizzle:EmptyFilter");
|
|
216
|
+
function isPlainObject(value) {
|
|
217
|
+
if (typeof value !== "object" || value === null) return false;
|
|
218
|
+
const proto = Object.getPrototypeOf(value);
|
|
219
|
+
return proto === Object.prototype || proto === null;
|
|
220
|
+
}
|
|
221
|
+
function sanitizeFilterValue(value) {
|
|
222
|
+
if (value === void 0) return EmptyFilter;
|
|
223
|
+
if (Array.isArray(value)) return value.map(sanitizeFilterValue);
|
|
224
|
+
if (isPlainObject(value)) return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, sanitizeFilterValue(entry)]));
|
|
225
|
+
return value;
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
214
228
|
//#region lib/helpers/sqlTypes/types.ts
|
|
215
229
|
/**
|
|
216
230
|
* Strips parameter suffixes like `(256)`, `(10,2)` and timezone modifiers
|
|
@@ -425,21 +439,6 @@ function tableHelper({ db, table }) {
|
|
|
425
439
|
}
|
|
426
440
|
//#endregion
|
|
427
441
|
//#region lib/abilityBuilder.ts
|
|
428
|
-
/**
|
|
429
|
-
* drizzle-orm's sentinel value for "this filter field is deliberately
|
|
430
|
-
* skipped", as opposed to `undefined`, which some drizzle-orm versions
|
|
431
|
-
* reject when it ends up as an explicit (present but `undefined`) `where`
|
|
432
|
-
* property nested inside a relational `with` query.
|
|
433
|
-
*
|
|
434
|
-
* drizzle-orm defines this via `Symbol.for("drizzle:EmptyFilter")` — a
|
|
435
|
-
* globally registered symbol — so recreating it the same way here yields
|
|
436
|
-
* the exact same value drizzle-orm's relational query engine checks for,
|
|
437
|
-
* without importing it directly: not every drizzle-orm version rumble
|
|
438
|
-
* supports exports it as a named export, and older versions that don't know
|
|
439
|
-
* about it at all still handle it safely (`Object.entries` on a symbol
|
|
440
|
-
* yields no entries, i.e. "no filter").
|
|
441
|
-
*/
|
|
442
|
-
const EmptyFilter = Symbol.for("drizzle:EmptyFilter");
|
|
443
442
|
function isDynamicQueryFilter(filter) {
|
|
444
443
|
return typeof filter === "function" && filter.constructor.name !== "AsyncFunction";
|
|
445
444
|
}
|
|
@@ -590,7 +589,7 @@ by: (explicitFilter) => {
|
|
|
590
589
|
});
|
|
591
590
|
const sqlTransformedWhere = lazy(() => {
|
|
592
591
|
const casing = db._.session?.dialect?.casing;
|
|
593
|
-
return filters?.where ? relationsFilterToSQL(tableSchema.foundRelation.table, filters.where, tableSchema.relations, db._.relations, casing) : void 0;
|
|
592
|
+
return filters?.where ? relationsFilterToSQL(tableSchema.foundRelation.table, sanitizeFilterValue(filters.where), tableSchema.relations, db._.relations, casing) : void 0;
|
|
594
593
|
});
|
|
595
594
|
if (filters?.columns) return {
|
|
596
595
|
/**
|
|
@@ -608,7 +607,7 @@ by: (explicitFilter) => {
|
|
|
608
607
|
*/
|
|
609
608
|
single: {
|
|
610
609
|
extras: filters?.extras,
|
|
611
|
-
where: filters?.where
|
|
610
|
+
where: sanitizeFilterValue(filters?.where),
|
|
612
611
|
columns: filters?.columns
|
|
613
612
|
},
|
|
614
613
|
/**
|
|
@@ -616,7 +615,7 @@ by: (explicitFilter) => {
|
|
|
616
615
|
*/
|
|
617
616
|
many: {
|
|
618
617
|
extras: filters?.extras,
|
|
619
|
-
where: filters?.where
|
|
618
|
+
where: sanitizeFilterValue(filters?.where),
|
|
620
619
|
columns: filters?.columns,
|
|
621
620
|
get limit() {
|
|
622
621
|
return limit();
|
|
@@ -662,14 +661,14 @@ by: (explicitFilter) => {
|
|
|
662
661
|
*/
|
|
663
662
|
single: {
|
|
664
663
|
extras: filters?.extras,
|
|
665
|
-
where: filters?.where
|
|
664
|
+
where: sanitizeFilterValue(filters?.where)
|
|
666
665
|
},
|
|
667
666
|
/**
|
|
668
667
|
* For find many calls
|
|
669
668
|
*/
|
|
670
669
|
many: {
|
|
671
670
|
extras: filters?.extras,
|
|
672
|
-
where: filters?.where
|
|
671
|
+
where: sanitizeFilterValue(filters?.where),
|
|
673
672
|
get limit() {
|
|
674
673
|
return limit();
|
|
675
674
|
}
|
|
@@ -1862,7 +1861,7 @@ const createPubSubInstance = ({ subscriptions }) => {
|
|
|
1862
1861
|
//#region lib/query.ts
|
|
1863
1862
|
const createQueryImplementer = ({ db, schemaBuilder, search, logger: loggerConfig, whereArgImplementer, orderArgImplementer, makePubSubInstance }) => {
|
|
1864
1863
|
const registeredQueryFieldNames = /* @__PURE__ */ new Set();
|
|
1865
|
-
return ({ table, readAction = "read", listAction = "read" }) => {
|
|
1864
|
+
return ({ table, readAction = "read", listAction = "read", findFirst, findMany }) => {
|
|
1866
1865
|
const WhereArg = whereArgImplementer({ table });
|
|
1867
1866
|
const OrderArg = orderArgImplementer({ table });
|
|
1868
1867
|
const tableSchema = tableHelper({
|
|
@@ -1921,8 +1920,13 @@ const createQueryImplementer = ({ db, schemaBuilder, search, logger: loggerConfi
|
|
|
1921
1920
|
const filter = ctx.abilities[table].filter(listAction).merge(mappedArgs).query.many;
|
|
1922
1921
|
if (mappedArgs.offset) filter.offset = mappedArgs.offset;
|
|
1923
1922
|
if (mappedArgs.orderBy) filter.orderBy = mappedArgs.orderBy;
|
|
1924
|
-
const
|
|
1925
|
-
if (filter.columns)
|
|
1923
|
+
const queryArgs = query(filter);
|
|
1924
|
+
if (filter.columns) queryArgs.columns = filter.columns;
|
|
1925
|
+
const run = findMany ? (tx) => findMany({
|
|
1926
|
+
tx,
|
|
1927
|
+
filter,
|
|
1928
|
+
queryArgs
|
|
1929
|
+
}) : (tx) => tx.query[table].findMany(queryArgs);
|
|
1926
1930
|
if (search?.enabled && args.search && args.search.length > 0 && search?.cpu_operator_cost) return db.transaction(async (tx) => {
|
|
1927
1931
|
if (isPostgresDB(tx)) await tx.execute(sql.raw(`SET cpu_operator_cost = ${search.cpu_operator_cost};`));
|
|
1928
1932
|
else {
|
|
@@ -1930,9 +1934,9 @@ const createQueryImplementer = ({ db, schemaBuilder, search, logger: loggerConfi
|
|
|
1930
1934
|
const log = loggerConfig?.enabled ? loggerConfig.logger : void 0;
|
|
1931
1935
|
log ? log.info({}, msg) : console.info(msg);
|
|
1932
1936
|
}
|
|
1933
|
-
return tx
|
|
1937
|
+
return run(tx);
|
|
1934
1938
|
});
|
|
1935
|
-
return db
|
|
1939
|
+
return run(db);
|
|
1936
1940
|
}
|
|
1937
1941
|
}),
|
|
1938
1942
|
[singularName]: t.drizzleField({
|
|
@@ -1944,9 +1948,13 @@ const createQueryImplementer = ({ db, schemaBuilder, search, logger: loggerConfi
|
|
|
1944
1948
|
resolve: (query, _root, args, ctx, _info) => {
|
|
1945
1949
|
deepSetProto(args);
|
|
1946
1950
|
const filter = ctx.abilities[table].filter(readAction).merge({ where: { [primaryKeyField.name]: args.id } }).query.single;
|
|
1947
|
-
const
|
|
1948
|
-
if (filter.columns)
|
|
1949
|
-
return
|
|
1951
|
+
const queryArgs = query(filter);
|
|
1952
|
+
if (filter.columns) queryArgs.columns = filter.columns;
|
|
1953
|
+
return findFirst ? findFirst({
|
|
1954
|
+
tx: db,
|
|
1955
|
+
filter,
|
|
1956
|
+
queryArgs
|
|
1957
|
+
}) : db.query[table].findFirst(queryArgs).then(assertFindFirstExists);
|
|
1950
1958
|
}
|
|
1951
1959
|
})
|
|
1952
1960
|
};
|