next-data-kit 7.0.0 → 7.1.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.
@@ -164,7 +164,7 @@ type TBaseOptions<TDoc, R> = {
164
164
  type TMongooseOptions<M, TDoc, R> = TBaseOptions<TDoc, R> & {
165
165
  model: M;
166
166
  adapter?: never;
167
- filter?: (filterInput?: Record<string, unknown>) => TMongoFilterQuery<TDoc>;
167
+ filter?: ((filterInput?: Record<string, unknown>) => TMongoFilterQuery<TDoc>) | TMongoFilterQuery<TDoc>;
168
168
  filterCustom?: TFilterCustomConfigWithFilter<TDoc, TMongoFilterQuery<TDoc>>;
169
169
  defaultSort?: TSortOptions<TDoc>;
170
170
  };
@@ -164,7 +164,7 @@ type TBaseOptions<TDoc, R> = {
164
164
  type TMongooseOptions<M, TDoc, R> = TBaseOptions<TDoc, R> & {
165
165
  model: M;
166
166
  adapter?: never;
167
- filter?: (filterInput?: Record<string, unknown>) => TMongoFilterQuery<TDoc>;
167
+ filter?: ((filterInput?: Record<string, unknown>) => TMongoFilterQuery<TDoc>) | TMongoFilterQuery<TDoc>;
168
168
  filterCustom?: TFilterCustomConfigWithFilter<TDoc, TMongoFilterQuery<TDoc>>;
169
169
  defaultSort?: TSortOptions<TDoc>;
170
170
  };
package/dist/index.cjs CHANGED
@@ -106,7 +106,7 @@ var calculatePagination = (page, limit, total) => ({
106
106
 
107
107
  // src/server/adapters/mongoose.ts
108
108
  var mongooseAdapter = (model, options = {}) => {
109
- const { filter: customFilterFn, filterCustom, defaultSort = { _id: -1 } } = options;
109
+ const { filter: customFilter, filterCustom, defaultSort = { _id: -1 } } = options;
110
110
  return async ({ filter, sorts, limit, skip, input }) => {
111
111
  let sortOption;
112
112
  if (input.sort && Object.keys(input.sort).length > 0) {
@@ -129,11 +129,11 @@ var mongooseAdapter = (model, options = {}) => {
129
129
  }
130
130
  });
131
131
  }
132
- if (customFilterFn) {
133
- const customQuery = customFilterFn(filter);
132
+ if (customFilter) {
133
+ const customQuery = typeof customFilter === "function" ? customFilter(filter) : customFilter;
134
134
  filterQuery = { ...filterQuery, ...customQuery };
135
135
  }
136
- if (filter && !customFilterFn) {
136
+ if (filter && !customFilter) {
137
137
  if (input.filterConfig) {
138
138
  Object.entries(filter).forEach(([key, value]) => {
139
139
  if (isProvided(value) && isSafeKey(key) && input.filterConfig?.[key]) {
@@ -167,8 +167,8 @@ var mongooseAdapter = (model, options = {}) => {
167
167
  if (filterCustom && filter) {
168
168
  Object.entries(filter).forEach(([key, value]) => {
169
169
  if (isProvided(value) && isSafeKey(key) && filterCustom[key]) {
170
- const customFilter = filterCustom[key](value);
171
- filterQuery = { ...filterQuery, ...customFilter };
170
+ const customFilter2 = filterCustom[key](value);
171
+ filterQuery = { ...filterQuery, ...customFilter2 };
172
172
  }
173
173
  });
174
174
  }