akanjs 2.1.0-rc.7 → 2.1.0-rc.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/document/filterMeta.ts
CHANGED
|
@@ -93,6 +93,11 @@ export const getFilterSortByKey = (modelRef: FilterCls, key: string) => {
|
|
|
93
93
|
return filterMeta.sort[key];
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
+
export const fillMissingFilterArgs = (filterInfo: FilterInfo, args: unknown[]) => {
|
|
97
|
+
if (args.length >= filterInfo.args.length) return args;
|
|
98
|
+
return [...args, ...Array(filterInfo.args.length - args.length).fill(undefined)];
|
|
99
|
+
};
|
|
100
|
+
|
|
96
101
|
export type BaseFilterSortKey = "latest" | "oldest";
|
|
97
102
|
export type BaseFilterQueryKey = "any";
|
|
98
103
|
export type BaseFilterKey = BaseFilterSortKey | BaseFilterQueryKey;
|
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
DocumentSchema,
|
|
12
12
|
documentQueryHelper,
|
|
13
13
|
type FindQueryOption,
|
|
14
|
+
fillMissingFilterArgs,
|
|
14
15
|
getFilterInfoByKey,
|
|
15
16
|
getFilterMeta,
|
|
16
17
|
getFilterSortByKey,
|
|
@@ -338,7 +339,8 @@ export class DatabaseResolver {
|
|
|
338
339
|
const filterInfo = getFilterInfoByKey(database.filter, queryKey);
|
|
339
340
|
const queryFn = filterInfo.queryFn;
|
|
340
341
|
if (!queryFn) throw new Error(`No query function for key: ${queryKey}`);
|
|
341
|
-
const
|
|
342
|
+
const queryArgs = fillMissingFilterArgs(filterInfo, hasQueryOption ? args.slice(0, -1) : args);
|
|
343
|
+
const query = queryFn(...queryArgs, documentQueryHelper);
|
|
342
344
|
const queryOption = hasQueryOption ? lastArg : {};
|
|
343
345
|
return { query, queryOption };
|
|
344
346
|
};
|
|
@@ -371,18 +373,19 @@ export class DatabaseResolver {
|
|
|
371
373
|
return (this as unknown as DatabaseInstance).__pickId(query, queryOption);
|
|
372
374
|
},
|
|
373
375
|
[`exists${capitalize(queryKey)}`]: async function (...args: any) {
|
|
374
|
-
const query = queryFn(...args, documentQueryHelper);
|
|
376
|
+
const query = queryFn(...fillMissingFilterArgs(filterInfo, args), documentQueryHelper);
|
|
375
377
|
return (this as unknown as DatabaseInstance).__exists(query);
|
|
376
378
|
},
|
|
377
379
|
[`count${capitalize(queryKey)}`]: async function (...args: any) {
|
|
378
|
-
const query = queryFn(...args, documentQueryHelper);
|
|
380
|
+
const query = queryFn(...fillMissingFilterArgs(filterInfo, args), documentQueryHelper);
|
|
379
381
|
return (this as unknown as DatabaseInstance).__count(query);
|
|
380
382
|
},
|
|
381
383
|
[`insight${capitalize(queryKey)}`]: async function (...args: any) {
|
|
382
|
-
const query = queryFn(...args, documentQueryHelper);
|
|
384
|
+
const query = queryFn(...fillMissingFilterArgs(filterInfo, args), documentQueryHelper);
|
|
383
385
|
return (this as unknown as DatabaseInstance).__insight(query);
|
|
384
386
|
},
|
|
385
|
-
[`query${capitalize(queryKey)}`]: (...args: any) =>
|
|
387
|
+
[`query${capitalize(queryKey)}`]: (...args: any) =>
|
|
388
|
+
queryFn(...fillMissingFilterArgs(filterInfo, args), documentQueryHelper),
|
|
386
389
|
});
|
|
387
390
|
});
|
|
388
391
|
applyMixins(DatabaseModelInstance, [database.model]);
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
type Doc,
|
|
9
9
|
documentQueryHelper,
|
|
10
10
|
type FindQueryOption,
|
|
11
|
+
fillMissingFilterArgs,
|
|
11
12
|
getFilterInfoByKey,
|
|
12
13
|
getFilterMeta,
|
|
13
14
|
type ListQueryOption,
|
|
@@ -116,9 +117,11 @@ export class ServiceResolver {
|
|
|
116
117
|
typeof lastArg.skip === "number" ||
|
|
117
118
|
typeof lastArg.limit === "number" ||
|
|
118
119
|
typeof lastArg.sort === "string");
|
|
119
|
-
const
|
|
120
|
+
const filterInfo = getFilterInfoByKey(database.filter, queryKey);
|
|
121
|
+
const queryFn = filterInfo.queryFn;
|
|
120
122
|
if (!queryFn) throw new Error(`No query function for key: ${queryKey}`);
|
|
121
|
-
const
|
|
123
|
+
const queryArgs = fillMissingFilterArgs(filterInfo, hasQueryOption ? args.slice(0, -1) : args);
|
|
124
|
+
const query = queryFn(...queryArgs, documentQueryHelper);
|
|
122
125
|
const queryOption = hasQueryOption ? lastArg : {};
|
|
123
126
|
return { query, queryOption };
|
|
124
127
|
};
|
|
@@ -167,7 +170,7 @@ export class ServiceResolver {
|
|
|
167
170
|
return this.__insight(query);
|
|
168
171
|
},
|
|
169
172
|
[`query${capitalize(queryKey)}`]: function (this: DatabaseService, ...args: any) {
|
|
170
|
-
return queryFn(...args, documentQueryHelper);
|
|
173
|
+
return queryFn(...fillMissingFilterArgs(filterInfo, args), documentQueryHelper);
|
|
171
174
|
},
|
|
172
175
|
});
|
|
173
176
|
});
|
|
@@ -1003,7 +1003,8 @@ export class SqliteDocumentStore {
|
|
|
1003
1003
|
const store = this;
|
|
1004
1004
|
const original = JSON.parse(JSON.stringify(sanitizeJson(originalData) ?? {})) as Record<string, unknown>;
|
|
1005
1005
|
const isNew = !originalData.id;
|
|
1006
|
-
const
|
|
1006
|
+
const hydratedData = isNew ? this.prepareDocument(data) : data;
|
|
1007
|
+
const doc = Object.assign(Object.create(this.database.doc.prototype), hydratedData);
|
|
1007
1008
|
Object.defineProperties(doc, {
|
|
1008
1009
|
set: {
|
|
1009
1010
|
value(patch: DocumentRecord) {
|
|
@@ -18,6 +18,7 @@ export declare const setFilterMeta: (filterRef: Cls<unknown, {
|
|
|
18
18
|
export declare const getFilterInfoByKey: <ArgNames extends string[] = [], Args extends any[] = any[], Model = any>(modelRef: FilterCls, key: string) => FilterInfo<ArgNames, Args, Model>;
|
|
19
19
|
export declare const setFilterInfoByKey: <ArgNames extends string[] = [], Args extends any[] = any[], Model = any>(modelRef: Cls<Model>, key: string, filterInfo: FilterInfo<ArgNames, Args, Model>) => void;
|
|
20
20
|
export declare const getFilterSortByKey: (modelRef: FilterCls, key: string) => unknown;
|
|
21
|
+
export declare const fillMissingFilterArgs: (filterInfo: FilterInfo, args: unknown[]) => any[];
|
|
21
22
|
export type BaseFilterSortKey = "latest" | "oldest";
|
|
22
23
|
export type BaseFilterQueryKey = "any";
|
|
23
24
|
export type BaseFilterKey = BaseFilterSortKey | BaseFilterQueryKey;
|