quetch 0.2.0 → 0.3.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.
- package/dist/errors/RequestError.d.ts +3 -3
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/middlewares/aggregate.d.ts +3 -3
- package/dist/middlewares/aggregate.js +1 -1
- package/dist/middlewares/aggregate.js.map +1 -1
- package/dist/middlewares/cache.d.ts +4 -4
- package/dist/middlewares/cache.js +3 -3
- package/dist/middlewares/cache.js.map +1 -1
- package/dist/middlewares.d.ts +9 -9
- package/dist/middlewares.js +9 -9
- package/dist/middlewares.js.map +1 -1
- package/dist/tools/cork.d.ts +5 -0
- package/dist/tools/cork.js +5 -0
- package/dist/tools/cork.js.map +1 -0
- package/dist/tools/defineCheckQuery.d.ts +12 -7
- package/dist/tools/defineCheckQuery.js +5 -0
- package/dist/tools/defineCheckQuery.js.map +1 -1
- package/dist/tools/defineCustomFetch.d.ts +26 -18
- package/dist/tools/defineCustomFetch.js +9 -3
- package/dist/tools/defineCustomFetch.js.map +1 -1
- package/dist/tools/defineGenericFetch.d.ts +14 -0
- package/dist/tools/defineGenericFetch.js +12 -0
- package/dist/tools/defineGenericFetch.js.map +1 -0
- package/dist/tools/queryItemList.js +3 -3
- package/dist/tools/queryItemList.js.map +1 -1
- package/dist/tools/sortItemList.js +3 -3
- package/dist/tools/sortItemList.js.map +1 -1
- package/dist/tools.d.ts +9 -8
- package/dist/tools.js +9 -8
- package/dist/tools.js.map +1 -1
- package/dist/types/AggregateFunction.d.ts +9 -0
- package/dist/types/AggregateFunction.js +2 -0
- package/dist/types/AggregateFunction.js.map +1 -0
- package/dist/types/AggregateFunctionOperator.d.ts +2 -0
- package/dist/types/AggregateFunctionOperator.js +2 -0
- package/dist/types/AggregateFunctionOperator.js.map +1 -0
- package/dist/types/Any.d.ts +1 -0
- package/dist/types/Any.js +2 -0
- package/dist/types/Any.js.map +1 -0
- package/dist/types/Context.d.ts +3 -0
- package/dist/types/Context.js +2 -0
- package/dist/types/Context.js.map +1 -0
- package/dist/types/CustomFieldAggregateMap.d.ts +2 -0
- package/dist/types/CustomFieldAggregateMap.js +2 -0
- package/dist/types/CustomFieldAggregateMap.js.map +1 -0
- package/dist/types/CustomFieldMap.d.ts +2 -0
- package/dist/types/CustomFieldMap.js +2 -0
- package/dist/types/CustomFieldMap.js.map +1 -0
- package/dist/types/CustomRequest.d.ts +16 -0
- package/dist/types/CustomRequest.js +2 -0
- package/dist/types/CustomRequest.js.map +1 -0
- package/dist/types/FieldFunction.d.ts +3 -0
- package/dist/types/FieldFunction.js +2 -0
- package/dist/types/FieldFunction.js.map +1 -0
- package/dist/types/FieldFunctionCustom.d.ts +7 -0
- package/dist/types/FieldFunctionCustom.js +2 -0
- package/dist/types/FieldFunctionCustom.js.map +1 -0
- package/dist/types/FieldFunctionFormatDate.d.ts +9 -0
- package/dist/types/FieldFunctionFormatDate.js +2 -0
- package/dist/types/FieldFunctionFormatDate.js.map +1 -0
- package/dist/types/FieldFunctionReturn.d.ts +6 -0
- package/dist/types/FieldFunctionReturn.js +2 -0
- package/dist/types/FieldFunctionReturn.js.map +1 -0
- package/dist/types/Filter.d.ts +12 -0
- package/dist/types/Filter.js +2 -0
- package/dist/types/Filter.js.map +1 -0
- package/dist/types/FilterArray.d.ts +10 -0
- package/dist/types/FilterArray.js +2 -0
- package/dist/types/FilterArray.js.map +1 -0
- package/dist/types/FilterBoolean.d.ts +9 -0
- package/dist/types/FilterBoolean.js +2 -0
- package/dist/types/FilterBoolean.js.map +1 -0
- package/dist/types/FilterField.d.ts +7 -0
- package/dist/types/FilterField.js +2 -0
- package/dist/types/FilterField.js.map +1 -0
- package/dist/types/FilterKeys.d.ts +6 -0
- package/dist/types/FilterKeys.js +2 -0
- package/dist/types/FilterKeys.js.map +1 -0
- package/dist/types/FilterNumber.d.ts +9 -0
- package/dist/types/FilterNumber.js +2 -0
- package/dist/types/FilterNumber.js.map +1 -0
- package/dist/types/FilterOperator.d.ts +2 -0
- package/dist/types/FilterOperator.js +2 -0
- package/dist/types/FilterOperator.js.map +1 -0
- package/dist/types/FilterSequence.d.ts +23 -0
- package/dist/types/FilterSequence.js +2 -0
- package/dist/types/FilterSequence.js.map +1 -0
- package/dist/types/FilterString.d.ts +9 -0
- package/dist/types/FilterString.js +2 -0
- package/dist/types/FilterString.js.map +1 -0
- package/dist/types/FilterStringIntersect.d.ts +9 -0
- package/dist/types/FilterStringIntersect.js +2 -0
- package/dist/types/FilterStringIntersect.js.map +1 -0
- package/dist/types/FilterStringMatch.d.ts +29 -0
- package/dist/types/FilterStringMatch.js +2 -0
- package/dist/types/FilterStringMatch.js.map +1 -0
- package/dist/types/Get.d.ts +6 -0
- package/dist/types/Get.js +2 -0
- package/dist/types/Get.js.map +1 -0
- package/dist/types/Group.d.ts +8 -0
- package/dist/types/Group.js +2 -0
- package/dist/types/Group.js.map +1 -0
- package/dist/types/Handler.d.ts +5 -0
- package/dist/types/Handler.js +2 -0
- package/dist/types/Handler.js.map +1 -0
- package/dist/types/Immutable.d.ts +3 -0
- package/dist/types/Immutable.js +2 -0
- package/dist/types/Immutable.js.map +1 -0
- package/dist/types/InjectCustomFields.d.ts +9 -0
- package/dist/types/InjectCustomFields.js +2 -0
- package/dist/types/InjectCustomFields.js.map +1 -0
- package/dist/types/Item.d.ts +4 -0
- package/dist/types/Item.js +2 -0
- package/dist/types/Item.js.map +1 -0
- package/dist/types/Key.d.ts +1 -0
- package/dist/types/Key.js +2 -0
- package/dist/types/Key.js.map +1 -0
- package/dist/types/Mutable.d.ts +3 -0
- package/dist/types/Mutable.js +2 -0
- package/dist/types/Mutable.js.map +1 -0
- package/dist/types/NextHandler.d.ts +4 -0
- package/dist/types/NextHandler.js +2 -0
- package/dist/types/NextHandler.js.map +1 -0
- package/dist/types/Order.d.ts +7 -0
- package/dist/types/Order.js +2 -0
- package/dist/types/Order.js.map +1 -0
- package/dist/types/Query.d.ts +23 -0
- package/dist/types/Query.js +2 -0
- package/dist/types/Query.js.map +1 -0
- package/dist/types/QueryAggregate.d.ts +10 -0
- package/dist/types/QueryAggregate.js +2 -0
- package/dist/types/QueryAggregate.js.map +1 -0
- package/dist/types/QueryAny.d.ts +7 -0
- package/dist/types/QueryAny.js +2 -0
- package/dist/types/QueryAny.js.map +1 -0
- package/dist/types/QueryCreate.d.ts +7 -0
- package/dist/types/QueryCreate.js +2 -0
- package/dist/types/QueryCreate.js.map +1 -0
- package/dist/types/QueryCreateMultiple.d.ts +8 -0
- package/dist/types/QueryCreateMultiple.js +2 -0
- package/dist/types/QueryCreateMultiple.js.map +1 -0
- package/dist/types/QueryDelete.d.ts +10 -0
- package/dist/types/QueryDelete.js +2 -0
- package/dist/types/QueryDelete.js.map +1 -0
- package/dist/types/QueryDeleteMultiple.d.ts +11 -0
- package/dist/types/QueryDeleteMultiple.js +2 -0
- package/dist/types/QueryDeleteMultiple.js.map +1 -0
- package/dist/types/QueryMethod.d.ts +5 -0
- package/dist/types/QueryMethod.js +2 -0
- package/dist/types/QueryMethod.js.map +1 -0
- package/dist/types/QueryRead.d.ts +23 -0
- package/dist/types/QueryRead.js +2 -0
- package/dist/types/QueryRead.js.map +1 -0
- package/dist/types/QueryReadMultiple.d.ts +34 -0
- package/dist/types/QueryReadMultiple.js +2 -0
- package/dist/types/QueryReadMultiple.js.map +1 -0
- package/dist/types/QueryUpdate.d.ts +18 -0
- package/dist/types/QueryUpdate.js +2 -0
- package/dist/types/QueryUpdate.js.map +1 -0
- package/dist/types/QueryUpdateMultiple.d.ts +26 -0
- package/dist/types/QueryUpdateMultiple.js +2 -0
- package/dist/types/QueryUpdateMultiple.js.map +1 -0
- package/dist/types/Result.d.ts +25 -0
- package/dist/types/Result.js +2 -0
- package/dist/types/Result.js.map +1 -0
- package/dist/types/Store.d.ts +6 -0
- package/dist/types/Store.js +2 -0
- package/dist/types/Store.js.map +1 -0
- package/dist/types.d.ts +46 -396
- package/doc/README.md +543 -211
- package/lib/errors/RequestError.ts +2 -2
- package/lib/errors.ts +1 -1
- package/lib/middlewares/aggregate.ts +5 -5
- package/lib/middlewares/cache.ts +7 -12
- package/lib/middlewares.ts +9 -9
- package/lib/tools/cork.ts +6 -0
- package/lib/tools/defineCheckQuery.ts +20 -15
- package/lib/tools/defineCustomFetch.ts +40 -62
- package/lib/tools/defineGenericFetch.ts +33 -0
- package/lib/tools/queryItemList.test.ts +6 -6
- package/lib/tools/queryItemList.ts +3 -3
- package/lib/tools/sortItemList.ts +3 -3
- package/lib/tools.ts +9 -8
- package/lib/types/AggregateFunction.ts +17 -0
- package/lib/types/AggregateFunctionOperator.ts +6 -0
- package/lib/types/Any.ts +10 -0
- package/lib/types/Context.ts +3 -0
- package/lib/types/CustomFieldAggregateMap.ts +6 -0
- package/lib/types/CustomFieldMap.ts +3 -0
- package/lib/types/CustomRequest.ts +21 -0
- package/lib/types/FieldFunction.ts +6 -0
- package/lib/types/FieldFunctionCustom.ts +7 -0
- package/lib/types/FieldFunctionFormatDate.ts +10 -0
- package/lib/types/FieldFunctionReturn.ts +6 -0
- package/lib/types/Filter.ts +20 -0
- package/lib/types/FilterArray.ts +11 -0
- package/lib/types/FilterBoolean.ts +10 -0
- package/lib/types/FilterField.ts +7 -0
- package/lib/types/FilterKeys.ts +6 -0
- package/lib/types/FilterNumber.ts +16 -0
- package/lib/types/FilterOperator.ts +3 -0
- package/lib/types/FilterSequence.ts +26 -0
- package/lib/types/FilterString.ts +19 -0
- package/lib/types/FilterStringIntersect.ts +10 -0
- package/lib/types/FilterStringMatch.ts +30 -0
- package/lib/types/Get.ts +8 -0
- package/lib/types/Group.ts +11 -0
- package/lib/types/Handler.ts +9 -0
- package/lib/types/Immutable.ts +3 -0
- package/lib/types/InjectCustomFields.ts +23 -0
- package/lib/types/Item.ts +8 -0
- package/lib/types/Key.ts +1 -0
- package/lib/types/Mutable.ts +3 -0
- package/lib/types/NextHandler.ts +4 -0
- package/lib/types/Order.ts +9 -0
- package/lib/types/Query.ts +36 -0
- package/lib/types/QueryAggregate.ts +11 -0
- package/lib/types/QueryAny.ts +8 -0
- package/lib/types/QueryCreate.ts +7 -0
- package/lib/types/QueryCreateMultiple.ts +8 -0
- package/lib/types/QueryDelete.ts +11 -0
- package/lib/types/QueryDeleteMultiple.ts +12 -0
- package/lib/types/QueryMethod.ts +6 -0
- package/lib/types/QueryRead.ts +24 -0
- package/lib/types/QueryReadMultiple.ts +36 -0
- package/lib/types/QueryUpdate.ts +19 -0
- package/lib/types/QueryUpdateMultiple.ts +27 -0
- package/lib/types/Result.ts +38 -0
- package/lib/types/Store.ts +7 -0
- package/lib/types.ts +47 -554
- package/package.json +3 -3
- package/dist/errors/QueryError.d.ts +0 -5
- package/dist/errors/QueryError.js +0 -23
- package/dist/errors/QueryError.js.map +0 -1
- package/dist/middlewares/concurrent.d.ts +0 -2
- package/dist/middlewares/concurrent.js +0 -20
- package/dist/middlewares/concurrent.js.map +0 -1
- package/dist/middlewares/fetch.d.ts +0 -2
- package/dist/middlewares/fetch.js +0 -20
- package/dist/middlewares/fetch.js.map +0 -1
- package/dist/middlewares/logQuery.d.ts +0 -2
- package/dist/middlewares/logQuery.js +0 -25
- package/dist/middlewares/logQuery.js.map +0 -1
- package/dist/tools/add.d.ts +0 -8
- package/dist/tools/add.js +0 -11
- package/dist/tools/add.js.map +0 -1
- package/dist/tools/add.test.d.ts +0 -1
- package/dist/tools/add.test.js +0 -6
- package/dist/tools/add.test.js.map +0 -1
- package/dist/tools/filterItem.test.d.ts +0 -1
- package/dist/tools/filterItem.test.js +0 -86
- package/dist/tools/filterItem.test.js.map +0 -1
- package/dist/tools/impasse.d.ts +0 -2
- package/dist/tools/impasse.js +0 -2
- package/dist/tools/impasse.js.map +0 -1
- package/dist/tools/queryItemList.test.d.ts +0 -1
- package/dist/tools/queryItemList.test.js +0 -181
- package/dist/tools/queryItemList.test.js.map +0 -1
- package/dist/tools/sortItemList.test.d.ts +0 -1
- package/dist/tools/sortItemList.test.js +0 -47
- package/dist/tools/sortItemList.test.js.map +0 -1
- package/lib/tools/impasse.ts +0 -3
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FilterKeys } from "./FilterKeys";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a given string field matches a given string value according to a given operator.
|
|
5
|
+
*/
|
|
6
|
+
export type FilterString<T extends object> = {
|
|
7
|
+
operator:
|
|
8
|
+
| "equal"
|
|
9
|
+
| "notEqual"
|
|
10
|
+
| "startWith"
|
|
11
|
+
| "endWith"
|
|
12
|
+
| "include"
|
|
13
|
+
| "greaterThan"
|
|
14
|
+
| "greaterThanOrEqual"
|
|
15
|
+
| "lowerThan"
|
|
16
|
+
| "lowerThanOrEqual";
|
|
17
|
+
field: FilterKeys<T, string>;
|
|
18
|
+
value: string;
|
|
19
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FilterKeys } from "./FilterKeys";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a given string field has any of the provided values.
|
|
5
|
+
*/
|
|
6
|
+
export type FilterStringIntersect<T extends object> = {
|
|
7
|
+
operator: "intersect";
|
|
8
|
+
field: FilterKeys<T, string>;
|
|
9
|
+
value: string[];
|
|
10
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { FilterKeys } from "./FilterKeys";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a given string field matches a given regular expression.
|
|
5
|
+
*/
|
|
6
|
+
export type FilterStringMatch<T extends object> = {
|
|
7
|
+
operator: "match";
|
|
8
|
+
field: FilterKeys<T, string>;
|
|
9
|
+
/**
|
|
10
|
+
* Raw regular expression string.
|
|
11
|
+
*/
|
|
12
|
+
value: string;
|
|
13
|
+
/**
|
|
14
|
+
* Regular expression options.
|
|
15
|
+
*/
|
|
16
|
+
options?: {
|
|
17
|
+
/**
|
|
18
|
+
* When matching, casing differences are ignored.
|
|
19
|
+
*/
|
|
20
|
+
ignoreCase?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Allows . to match newlines.
|
|
23
|
+
*/
|
|
24
|
+
dotAll?: boolean;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Compiled regular expression generated by the `testFilter` function.
|
|
28
|
+
*/
|
|
29
|
+
regularExpression?: RegExp;
|
|
30
|
+
};
|
package/lib/types/Get.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CustomFieldMap } from "./CustomFieldMap";
|
|
2
|
+
import type { FieldFunctionCustom } from "./FieldFunctionCustom";
|
|
3
|
+
import type { FieldFunctionReturn } from "./FieldFunctionReturn";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Injects the custom fields into the entity type.
|
|
7
|
+
*/
|
|
8
|
+
export type InjectCustomFields<
|
|
9
|
+
T extends object,
|
|
10
|
+
C extends CustomFieldMap<T> | undefined,
|
|
11
|
+
> = C extends CustomFieldMap<T>
|
|
12
|
+
? {
|
|
13
|
+
readonly [K in keyof T | keyof C]: K extends keyof T
|
|
14
|
+
? T[K]
|
|
15
|
+
: K extends keyof C
|
|
16
|
+
? C[K] extends FieldFunctionCustom<T>
|
|
17
|
+
? ReturnType<C[K]["value"]>
|
|
18
|
+
: C[K]["operator"] extends keyof FieldFunctionReturn
|
|
19
|
+
? FieldFunctionReturn[C[K]["operator"]]
|
|
20
|
+
: never
|
|
21
|
+
: never;
|
|
22
|
+
}
|
|
23
|
+
: T;
|
package/lib/types/Key.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Key = string | number | symbol;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Context } from "./Context";
|
|
2
|
+
import type { CustomFieldMap } from "./CustomFieldMap";
|
|
3
|
+
import type { InjectCustomFields } from "./InjectCustomFields";
|
|
4
|
+
import type { QueryAggregate } from "./QueryAggregate";
|
|
5
|
+
import type { QueryCreate } from "./QueryCreate";
|
|
6
|
+
import type { QueryCreateMultiple } from "./QueryCreateMultiple";
|
|
7
|
+
import type { QueryDelete } from "./QueryDelete";
|
|
8
|
+
import type { QueryDeleteMultiple } from "./QueryDeleteMultiple";
|
|
9
|
+
import type { QueryRead } from "./QueryRead";
|
|
10
|
+
import type { QueryReadMultiple } from "./QueryReadMultiple";
|
|
11
|
+
import type { QueryUpdate } from "./QueryUpdate";
|
|
12
|
+
import type { QueryUpdateMultiple } from "./QueryUpdateMultiple";
|
|
13
|
+
|
|
14
|
+
type QueryBase<T extends object> =
|
|
15
|
+
| QueryRead<T>
|
|
16
|
+
| QueryReadMultiple<T>
|
|
17
|
+
| QueryCreate<T>
|
|
18
|
+
| QueryCreateMultiple<T>
|
|
19
|
+
| QueryUpdate<T>
|
|
20
|
+
| QueryUpdateMultiple<T>
|
|
21
|
+
| QueryDelete<T>
|
|
22
|
+
| QueryDeleteMultiple<T>
|
|
23
|
+
| QueryAggregate<T>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Query that fetches or mutates an entity.
|
|
27
|
+
*/
|
|
28
|
+
export type Query<
|
|
29
|
+
T extends object,
|
|
30
|
+
C extends CustomFieldMap<T> | undefined,
|
|
31
|
+
> = QueryBase<InjectCustomFields<T, C>> & {
|
|
32
|
+
/**
|
|
33
|
+
* Common item properties to use for identifying the item.
|
|
34
|
+
*/
|
|
35
|
+
context?: Context<T>;
|
|
36
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AggregateFunction } from "./AggregateFunction";
|
|
2
|
+
import type { Filter } from "./Filter";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Query for computing an aggregated value.
|
|
6
|
+
*/
|
|
7
|
+
export type QueryAggregate<T extends object> = {
|
|
8
|
+
method: "aggregate";
|
|
9
|
+
aggregator: AggregateFunction<T>;
|
|
10
|
+
filter?: Filter<T>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CustomFieldMap } from "./CustomFieldMap";
|
|
2
|
+
import type { Filter } from "./Filter";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Query for deleting an item.
|
|
6
|
+
*/
|
|
7
|
+
export type QueryDelete<T extends object> = {
|
|
8
|
+
method: "delete";
|
|
9
|
+
filter?: Filter<T>;
|
|
10
|
+
customFields?: CustomFieldMap<T>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CustomFieldMap } from "./CustomFieldMap";
|
|
2
|
+
import type { Filter } from "./Filter";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Query for deleting multiple items.
|
|
6
|
+
*/
|
|
7
|
+
export type QueryDeleteMultiple<T extends object> = {
|
|
8
|
+
method: "delete";
|
|
9
|
+
multiple: true;
|
|
10
|
+
filter?: Filter<T>;
|
|
11
|
+
customFields?: CustomFieldMap<T>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Filter } from "./Filter";
|
|
2
|
+
import type { Order } from "./Order";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Query for reading a single item.
|
|
6
|
+
*/
|
|
7
|
+
export type QueryRead<T extends object> = {
|
|
8
|
+
method?: "read";
|
|
9
|
+
multiple?: false;
|
|
10
|
+
offset?: never;
|
|
11
|
+
group?: never;
|
|
12
|
+
/**
|
|
13
|
+
* Item fields to pick. If omitted, all fields are picked.
|
|
14
|
+
*/
|
|
15
|
+
fields?: readonly (keyof T)[];
|
|
16
|
+
/**
|
|
17
|
+
* Filter for finding the item, if it cannot be found based on the `context`.
|
|
18
|
+
*/
|
|
19
|
+
filter?: Filter<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Order by which the items should be sorted.
|
|
22
|
+
*/
|
|
23
|
+
order?: Order<T>[];
|
|
24
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Filter } from "./Filter";
|
|
2
|
+
import type { Group } from "./Group";
|
|
3
|
+
import type { Order } from "./Order";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Query for getting a list of items.
|
|
7
|
+
*/
|
|
8
|
+
export type QueryReadMultiple<T extends object> = {
|
|
9
|
+
method?: "read";
|
|
10
|
+
multiple: true;
|
|
11
|
+
/**
|
|
12
|
+
* Offset of the first matching item.
|
|
13
|
+
*/
|
|
14
|
+
offset?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Upper bound of the number of items to return.
|
|
17
|
+
*/
|
|
18
|
+
limit?: number;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Item fields to pick. If omitted, all fields are picked.
|
|
22
|
+
*/
|
|
23
|
+
fields?: readonly (keyof T)[];
|
|
24
|
+
/**
|
|
25
|
+
* Filter that picks the items.
|
|
26
|
+
*/
|
|
27
|
+
filter?: Filter<T>;
|
|
28
|
+
/**
|
|
29
|
+
* Order by which the items should be sorted.
|
|
30
|
+
*/
|
|
31
|
+
order?: Order<T>[];
|
|
32
|
+
/**
|
|
33
|
+
* Groups items by specified fields.
|
|
34
|
+
*/
|
|
35
|
+
group?: Group<T>[];
|
|
36
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Filter } from "./Filter";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Query for updating an item.
|
|
5
|
+
*/
|
|
6
|
+
export type QueryUpdate<T extends object> = {
|
|
7
|
+
method: "update";
|
|
8
|
+
/**
|
|
9
|
+
* Partial property values to update.
|
|
10
|
+
*/
|
|
11
|
+
value: Partial<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Filter for finding the item, if it cannot be found based on the `context`.
|
|
14
|
+
*/
|
|
15
|
+
filter?: Filter<T>;
|
|
16
|
+
offset?: never;
|
|
17
|
+
order: never;
|
|
18
|
+
group?: never;
|
|
19
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Filter } from "./Filter";
|
|
2
|
+
import type { Order } from "./Order";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Query for updating multiple items.
|
|
6
|
+
*/
|
|
7
|
+
export type QueryUpdateMultiple<T extends object> = {
|
|
8
|
+
method: "update";
|
|
9
|
+
multiple: true;
|
|
10
|
+
/**
|
|
11
|
+
* Partial property values to update.
|
|
12
|
+
*/
|
|
13
|
+
value: Partial<T>[];
|
|
14
|
+
filter?: Filter<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Order by which the items should be sorted.
|
|
17
|
+
*/
|
|
18
|
+
order?: Order<T>[];
|
|
19
|
+
/**
|
|
20
|
+
* Offset of the first matching item to update.
|
|
21
|
+
*/
|
|
22
|
+
offset?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Sets the upper bound of the number of items to update.
|
|
25
|
+
*/
|
|
26
|
+
limit?: number;
|
|
27
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { CustomFieldMap } from "./CustomFieldMap";
|
|
2
|
+
import type { InjectCustomFields } from "./InjectCustomFields";
|
|
3
|
+
import type { Item } from "./Item";
|
|
4
|
+
import type { Query } from "./Query";
|
|
5
|
+
|
|
6
|
+
export type PickFields<T extends object, F extends string | number | symbol> = [
|
|
7
|
+
F,
|
|
8
|
+
] extends [keyof T]
|
|
9
|
+
? { readonly [K in F]: T[K] }
|
|
10
|
+
: { readonly [K in keyof T]: T[K] };
|
|
11
|
+
|
|
12
|
+
export type ResultRead<
|
|
13
|
+
T extends object,
|
|
14
|
+
Q extends Query<T, C>,
|
|
15
|
+
C extends CustomFieldMap<T>,
|
|
16
|
+
U extends InjectCustomFields<T, C> = InjectCustomFields<T, C>,
|
|
17
|
+
> = [C] extends [CustomFieldMap<T>]
|
|
18
|
+
? [Q] extends [{ fields: (keyof U)[] }]
|
|
19
|
+
? PickFields<U, Item<Q["fields"]>>
|
|
20
|
+
: U
|
|
21
|
+
: [Q] extends [{ fields: (keyof T)[] }]
|
|
22
|
+
? PickFields<T, Item<Q["fields"]>>
|
|
23
|
+
: T;
|
|
24
|
+
|
|
25
|
+
export type Result<
|
|
26
|
+
T extends object,
|
|
27
|
+
Q extends Query<T, C>,
|
|
28
|
+
C extends CustomFieldMap<T>,
|
|
29
|
+
U extends InjectCustomFields<T, C> = InjectCustomFields<T, C>,
|
|
30
|
+
> = [Q] extends [{ method: "read" }]
|
|
31
|
+
? [Q] extends [{ multiple: true }]
|
|
32
|
+
? ResultRead<T, Q, C, U>[]
|
|
33
|
+
: ResultRead<T, Q, C, U>
|
|
34
|
+
: [Q] extends [{ method: "aggregate" }]
|
|
35
|
+
? number
|
|
36
|
+
: [Q] extends [{ multiple: true }]
|
|
37
|
+
? ResultRead<T, Q, C, U>[]
|
|
38
|
+
: ResultRead<T, Q, C, U>;
|