@m1212e/rumble 0.12.22 → 0.13.1
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 +25 -12
- package/out/index.cjs.map +1 -1
- package/out/index.d.cts +6 -2
- package/out/index.d.cts.map +1 -1
- package/out/index.d.mts +6 -2
- package/out/index.d.mts.map +1 -1
- package/out/index.mjs +25 -12
- 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,13 @@ 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
|
+
args.extras = { search_score: (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(", "))})` };
|
|
1368
1380
|
const originalOrderBy = (0, es_toolkit.cloneDeep)(args.orderBy);
|
|
1369
1381
|
args.orderBy = (table) => {
|
|
1370
1382
|
const argsOrderBySQL = drizzle_orm.sql.join(Object.entries(originalOrderBy ?? {}).map(([key, value]) => {
|
|
@@ -1372,17 +1384,9 @@ function adjustQueryArgsForSearch({ search, args, tableSchema, abilities }) {
|
|
|
1372
1384
|
else if (value === "desc") return drizzle_orm.sql`${table[key]} DESC`;
|
|
1373
1385
|
else throw new Error(`Invalid value ${value} for orderBy`);
|
|
1374
1386
|
}), 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`;
|
|
1387
|
+
const searchSQL = drizzle_orm.sql`search_score DESC`;
|
|
1379
1388
|
return originalOrderBy ? drizzle_orm.sql.join([argsOrderBySQL, searchSQL], drizzle_orm.sql.raw(", ")) : searchSQL;
|
|
1380
1389
|
};
|
|
1381
|
-
args.where = { AND: [(0, es_toolkit.cloneDeep)(args.where) ?? {}, { RAW: (table) => {
|
|
1382
|
-
return drizzle_orm.sql`GREATEST(${drizzle_orm.sql.join(Object.entries(tableSchema.columns).map(([key]) => {
|
|
1383
|
-
return drizzle_orm.sql`similarity(${table[key]}::TEXT, ${args.search})`;
|
|
1384
|
-
}), drizzle_orm.sql.raw(", "))}) > ${search.threshold ?? .1}`;
|
|
1385
|
-
} }] };
|
|
1386
1390
|
}
|
|
1387
1391
|
}
|
|
1388
1392
|
|
|
@@ -1532,7 +1536,8 @@ const createObjectImplementer = ({ db, search, schemaBuilder, makePubSubInstance
|
|
|
1532
1536
|
});
|
|
1533
1537
|
const filter = ctx.abilities[relationSchema.tsName].filter(readAction).merge({
|
|
1534
1538
|
where: args$1.where,
|
|
1535
|
-
limit: args$1.limit
|
|
1539
|
+
limit: args$1.limit,
|
|
1540
|
+
extras: args$1.extras
|
|
1536
1541
|
}).query[filterSpecifier];
|
|
1537
1542
|
if (args$1.offset) filter.offset = args$1.offset;
|
|
1538
1543
|
if (args$1.orderBy) filter.orderBy = args$1.orderBy;
|
|
@@ -1541,6 +1546,14 @@ const createObjectImplementer = ({ db, search, schemaBuilder, makePubSubInstance
|
|
|
1541
1546
|
});
|
|
1542
1547
|
return acc;
|
|
1543
1548
|
}, {});
|
|
1549
|
+
if (search?.enabled) {
|
|
1550
|
+
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.");
|
|
1551
|
+
fields.search_score = t.float({
|
|
1552
|
+
description: "The search score of the object. If a search is provided, this field will be populated with the search score.",
|
|
1553
|
+
nullable: true,
|
|
1554
|
+
resolve: (parent, args, ctx, info) => parent.search_score
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1544
1557
|
return {
|
|
1545
1558
|
...fields,
|
|
1546
1559
|
...relations,
|