pqb 0.61.12 → 0.61.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/dist/index.d.ts CHANGED
@@ -9331,13 +9331,13 @@ interface JoinedParsers {
9331
9331
  type QueryBeforeHook = (query: Query) => void | Promise<void>;
9332
9332
  type QueryBeforeActionHook = (utils: QueryHookUtils<PickQueryInputType>) => void | Promise<void>;
9333
9333
  type QueryAfterHook<Data = unknown> = (data: Data, query: Query) => unknown | Promise<unknown>;
9334
- interface QueryDataScopes {
9334
+ type QueryDataScopes = {
9335
9335
  [K: string]: QueryScopeData;
9336
- }
9337
- interface QueryScopeData {
9336
+ };
9337
+ type QueryScopeData = (q: Query) => {
9338
9338
  and?: WhereItem[];
9339
9339
  or?: WhereItem[][];
9340
- }
9340
+ };
9341
9341
  type QueryDataFromItem = string | SubQueryForSql | Expression;
9342
9342
  interface QueryDataJoinTo extends PickQueryTable, PickQueryQ {
9343
9343
  }
package/dist/index.js CHANGED
@@ -9555,8 +9555,9 @@ const whereToSql = (ctx, table, query, quotedAs, parens) => {
9555
9555
  const data = Object.create(query);
9556
9556
  for (const key in query.scopes) {
9557
9557
  const scope = query.scopes[key];
9558
- data.and = scope.and;
9559
- data.or = scope.or;
9558
+ const scopeResult = scope(table.baseQuery);
9559
+ data.and = scopeResult.and;
9560
+ data.or = scopeResult.or;
9560
9561
  const scopeSql = andOrToSql(ctx, table, data, quotedAs, true);
9561
9562
  if (scopeSql) sql = sql ? sql + " AND " + scopeSql : scopeSql;
9562
9563
  }
@@ -14765,9 +14766,7 @@ function enableSoftDelete(query, table, shape, softDelete, scopes) {
14765
14766
  `Table ${table} is missing ${column} column which is required for soft delete`
14766
14767
  );
14767
14768
  }
14768
- const scope = {
14769
- and: [{ [column]: null }]
14770
- };
14769
+ const scope = () => ({ and: [{ [column]: null }] });
14771
14770
  scopes.deleted = scope;
14772
14771
  const { q } = query;
14773
14772
  setObjectValueImmutable(q, "scopes", "nonDeleted", scope);
@@ -15836,10 +15835,10 @@ class Db extends QueryMethods {
15836
15835
  };
15837
15836
  if (options.scopes) {
15838
15837
  for (const key in options.scopes) {
15839
- const q = options.scopes[key](this).q;
15840
- scopes[key] = {
15841
- and: q.and,
15842
- or: q.or
15838
+ const scopeFn = options.scopes[key];
15839
+ scopes[key] = (q) => {
15840
+ const result = scopeFn(q);
15841
+ return { and: result.q.and, or: result.q.or };
15843
15842
  };
15844
15843
  }
15845
15844
  if (scopes.default) {