@m1212e/rumble 0.12.22 → 0.13.2
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 +27 -10
- package/out/index.cjs.map +1 -1
- package/out/index.d.cts +12 -1
- package/out/index.d.cts.map +1 -1
- package/out/index.d.mts +12 -1
- package/out/index.d.mts.map +1 -1
- package/out/index.mjs +27 -10
- package/out/index.mjs.map +1 -1
- package/package.json +1 -1
package/out/index.cjs
CHANGED
|
@@ -887,10 +887,12 @@ const createAbilityBuilder = ({ db, actions, defaultLimit }) => {
|
|
|
887
887
|
if (filters?.columns) return {
|
|
888
888
|
query: {
|
|
889
889
|
single: {
|
|
890
|
+
extras: filters?.extras,
|
|
890
891
|
where: filters?.where,
|
|
891
892
|
columns: filters?.columns
|
|
892
893
|
},
|
|
893
894
|
many: {
|
|
895
|
+
extras: filters?.extras,
|
|
894
896
|
where: filters?.where,
|
|
895
897
|
columns: filters?.columns,
|
|
896
898
|
get limit() {
|
|
@@ -904,8 +906,12 @@ const createAbilityBuilder = ({ db, actions, defaultLimit }) => {
|
|
|
904
906
|
};
|
|
905
907
|
else return {
|
|
906
908
|
query: {
|
|
907
|
-
single: {
|
|
909
|
+
single: {
|
|
910
|
+
extras: filters?.extras,
|
|
911
|
+
where: filters?.where
|
|
912
|
+
},
|
|
908
913
|
many: {
|
|
914
|
+
extras: filters?.extras,
|
|
909
915
|
where: filters?.where,
|
|
910
916
|
get limit() {
|
|
911
917
|
return limit();
|
|
@@ -1135,7 +1141,6 @@ const createWhereArgImplementer = ({ db, schemaBuilder, enumImplementer }) => {
|
|
|
1135
1141
|
//#endregion
|
|
1136
1142
|
//#region lib/client/client.ts
|
|
1137
1143
|
const clientCreatorImplementer = ({ builtSchema }) => {
|
|
1138
|
-
if (process.env.NODE_ENV !== "development") console.warn("Running rumble client generation in non development mode. Are you sure this is correct?");
|
|
1139
1144
|
const clientCreator = async ({ apiUrl, outputPath, rumbleImportPath, useExternalUrqlClient, removeExisting }) => {
|
|
1140
1145
|
if (process.env.NODE_ENV !== "development") console.warn("Running rumble client generation in non development mode. Are you sure this is correct?");
|
|
1141
1146
|
await generateFromSchema({
|
|
@@ -1365,6 +1370,14 @@ async function initSearchIfApplicable(db) {
|
|
|
1365
1370
|
*/
|
|
1366
1371
|
function adjustQueryArgsForSearch({ search, args, tableSchema, abilities }) {
|
|
1367
1372
|
if (search?.enabled && args.search && args.search.length > 0) {
|
|
1373
|
+
const columnsToSearch = abilities.query.many.columns ? Object.entries(tableSchema.columns).filter(([key]) => abilities.query.many.columns[key]) : Object.entries(tableSchema.columns);
|
|
1374
|
+
const searchParam = drizzle_orm.sql`${args.search}`;
|
|
1375
|
+
const scoring = (table) => (search?.score ?? "sum") === "sum" ? drizzle_orm.sql`(${drizzle_orm.sql.join(columnsToSearch.map(([key]) => {
|
|
1376
|
+
return drizzle_orm.sql`COALESCE(similarity(${table[key]}::TEXT, ${searchParam}), 0)`;
|
|
1377
|
+
}), drizzle_orm.sql.raw(" + "))})` : drizzle_orm.sql`GREATEST(${drizzle_orm.sql.join(columnsToSearch.map(([key]) => {
|
|
1378
|
+
return drizzle_orm.sql`similarity(${table[key]}::TEXT, ${searchParam})`;
|
|
1379
|
+
}), drizzle_orm.sql.raw(", "))})`;
|
|
1380
|
+
args.extras = { search_score: scoring };
|
|
1368
1381
|
const originalOrderBy = (0, es_toolkit.cloneDeep)(args.orderBy);
|
|
1369
1382
|
args.orderBy = (table) => {
|
|
1370
1383
|
const argsOrderBySQL = drizzle_orm.sql.join(Object.entries(originalOrderBy ?? {}).map(([key, value]) => {
|
|
@@ -1372,16 +1385,11 @@ function adjustQueryArgsForSearch({ search, args, tableSchema, abilities }) {
|
|
|
1372
1385
|
else if (value === "desc") return drizzle_orm.sql`${table[key]} DESC`;
|
|
1373
1386
|
else throw new Error(`Invalid value ${value} for orderBy`);
|
|
1374
1387
|
}), drizzle_orm.sql.raw(", "));
|
|
1375
|
-
const
|
|
1376
|
-
const searchSQL = drizzle_orm.sql`GREATEST(${drizzle_orm.sql.join(columnsToSearch.map(([key]) => {
|
|
1377
|
-
return drizzle_orm.sql`similarity(${table[key]}::TEXT, ${args.search})`;
|
|
1378
|
-
}), drizzle_orm.sql.raw(", "))}) DESC`;
|
|
1388
|
+
const searchSQL = drizzle_orm.sql`search_score DESC`;
|
|
1379
1389
|
return originalOrderBy ? drizzle_orm.sql.join([argsOrderBySQL, searchSQL], drizzle_orm.sql.raw(", ")) : searchSQL;
|
|
1380
1390
|
};
|
|
1381
1391
|
args.where = { AND: [(0, es_toolkit.cloneDeep)(args.where) ?? {}, { RAW: (table) => {
|
|
1382
|
-
return drizzle_orm.sql
|
|
1383
|
-
return drizzle_orm.sql`similarity(${table[key]}::TEXT, ${args.search})`;
|
|
1384
|
-
}), drizzle_orm.sql.raw(", "))}) > ${search.threshold ?? .1}`;
|
|
1392
|
+
return drizzle_orm.sql`${scoring(table)} > ${search.threshold ?? .15}`;
|
|
1385
1393
|
} }] };
|
|
1386
1394
|
}
|
|
1387
1395
|
}
|
|
@@ -1532,7 +1540,8 @@ const createObjectImplementer = ({ db, search, schemaBuilder, makePubSubInstance
|
|
|
1532
1540
|
});
|
|
1533
1541
|
const filter = ctx.abilities[relationSchema.tsName].filter(readAction).merge({
|
|
1534
1542
|
where: args$1.where,
|
|
1535
|
-
limit: args$1.limit
|
|
1543
|
+
limit: args$1.limit,
|
|
1544
|
+
extras: args$1.extras
|
|
1536
1545
|
}).query[filterSpecifier];
|
|
1537
1546
|
if (args$1.offset) filter.offset = args$1.offset;
|
|
1538
1547
|
if (args$1.orderBy) filter.orderBy = args$1.orderBy;
|
|
@@ -1541,6 +1550,14 @@ const createObjectImplementer = ({ db, search, schemaBuilder, makePubSubInstance
|
|
|
1541
1550
|
});
|
|
1542
1551
|
return acc;
|
|
1543
1552
|
}, {});
|
|
1553
|
+
if (search?.enabled) {
|
|
1554
|
+
if (fields.search_score) throw new Error("Reserved field name 'search_score' found on " + tableSchema.tsName + ". If search is enabled, the 'search_score' field is automatically added and cannot be defined manually.");
|
|
1555
|
+
fields.search_score = t.float({
|
|
1556
|
+
description: "The search score of the object. If a search is provided, this field will be populated with the search score.",
|
|
1557
|
+
nullable: true,
|
|
1558
|
+
resolve: (parent, args, ctx, info) => parent.search_score
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1544
1561
|
return {
|
|
1545
1562
|
...fields,
|
|
1546
1563
|
...relations,
|