akanjs 2.3.5-rc.8 → 2.3.5
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/base/base.ts +6 -2
- package/base/primitiveRegistry.ts +50 -46
- package/base/symbols.ts +16 -11
- package/base/types.ts +12 -0
- package/constant/constantRegistry.ts +10 -9
- package/constant/deserialize.ts +7 -7
- package/constant/fieldInfo.ts +173 -31
- package/constant/getDefault.ts +2 -2
- package/constant/immerify.ts +2 -2
- package/constant/purify.ts +19 -4
- package/constant/serialize.ts +6 -5
- package/constant/types.ts +9 -1
- package/constant/via.ts +312 -57
- package/dictionary/dictInfo.ts +28 -38
- package/dictionary/locale.ts +36 -38
- package/document/by.ts +84 -21
- package/document/database.ts +53 -18
- package/document/databaseRegistry.ts +7 -3
- package/document/filterMeta.ts +26 -14
- package/document/into.ts +71 -76
- package/document/types.ts +4 -2
- package/fetch/fetchType/endpointFetch.type.ts +6 -3
- package/fetch/fetchType/sliceFetch.type.ts +24 -13
- package/package.json +1 -1
- package/service/predefinedAdaptor/compress.adaptor.ts +9 -9
- package/service/predefinedAdaptor/database.adaptor.ts +3 -7
- package/service/serve.ts +17 -52
- package/service/types.ts +61 -21
- package/signal/endpoint.ts +2 -1
- package/signal/endpointInfo.ts +53 -23
- package/signal/internal.ts +2 -1
- package/signal/internalInfo.ts +71 -23
- package/signal/serverSignal.ts +23 -57
- package/signal/slice.ts +35 -35
- package/signal/sliceInfo.ts +63 -47
- package/signal/types.ts +23 -17
- package/store/action.ts +57 -44
- package/store/state.ts +47 -36
- package/store/stateBuilder.ts +3 -3
- package/store/store.ts +61 -15
- package/store/types.ts +16 -6
- package/types/base/base.d.ts +5 -1
- package/types/base/primitiveRegistry.d.ts +43 -38
- package/types/base/symbols.d.ts +5 -0
- package/types/base/types.d.ts +1 -0
- package/types/constant/constantRegistry.d.ts +3 -8
- package/types/constant/deserialize.d.ts +2 -2
- package/types/constant/fieldInfo.d.ts +41 -20
- package/types/constant/immerify.d.ts +2 -2
- package/types/constant/purify.d.ts +3 -2
- package/types/constant/serialize.d.ts +2 -2
- package/types/constant/types.d.ts +6 -1
- package/types/constant/via.d.ts +143 -22
- package/types/dictionary/dictInfo.d.ts +18 -11
- package/types/dictionary/locale.d.ts +23 -16
- package/types/document/by.d.ts +44 -7
- package/types/document/database.d.ts +9 -7
- package/types/document/databaseRegistry.d.ts +5 -4
- package/types/document/filterMeta.d.ts +18 -11
- package/types/document/into.d.ts +46 -19
- package/types/document/types.d.ts +3 -2
- package/types/fetch/fetchType/endpointFetch.type.d.ts +2 -2
- package/types/fetch/fetchType/sliceFetch.type.d.ts +11 -11
- package/types/service/serve.d.ts +4 -5
- package/types/service/serviceModule.d.ts +5 -5
- package/types/service/types.d.ts +23 -5
- package/types/signal/endpoint.d.ts +2 -1
- package/types/signal/endpointInfo.d.ts +40 -15
- package/types/signal/internal.d.ts +2 -1
- package/types/signal/internalInfo.d.ts +46 -12
- package/types/signal/serverSignal.d.ts +15 -12
- package/types/signal/slice.d.ts +8 -6
- package/types/signal/sliceInfo.d.ts +41 -20
- package/types/signal/types.d.ts +23 -17
- package/types/store/action.d.ts +25 -22
- package/types/store/baseSt.d.ts +42 -13
- package/types/store/state.d.ts +23 -26
- package/types/store/stateBuilder.d.ts +2 -2
- package/types/store/store.d.ts +17 -5
- package/types/store/types.d.ts +9 -3
- package/ui/Signal/makeExample.ts +3 -3
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import type { GetStateObject } from "akanjs/base";
|
|
2
2
|
import type { BaseInsight, BaseObject } from "akanjs/constant";
|
|
3
|
-
import type { BaseFilterQueryKey, BaseFilterSortKey, FilterInfo, FilterInstance } from "akanjs/document";
|
|
4
|
-
import type { EndpointInfo, SliceInfo } from "akanjs/signal";
|
|
3
|
+
import type { BaseFilterQueryKey, BaseFilterSortKey, FilterCls, FilterInfo, FilterInstance } from "akanjs/document";
|
|
4
|
+
import type { EndpInfoArgNames, EndpointInfo, SliceInfo, SliceInfoArgNames } from "akanjs/signal";
|
|
5
5
|
import type { RootDictionary } from "./trans.d.ts";
|
|
6
6
|
type EnumValueKey = string | number;
|
|
7
|
+
type AnyFilterShape = FilterInstance<Record<string, FilterInfo>, Record<string, unknown>>;
|
|
8
|
+
type DictFilterShape<Filter> = Filter extends FilterInstance ? Filter : Filter extends FilterCls<infer FilterShape> ? FilterShape : Filter extends {
|
|
9
|
+
query: Record<string, FilterInfo>;
|
|
10
|
+
sort: Record<string, unknown>;
|
|
11
|
+
} ? Filter : AnyFilterShape;
|
|
12
|
+
type DictFilterQuery<Filter> = DictFilterShape<Filter>["query"];
|
|
13
|
+
type DictFilterSort<Filter> = DictFilterShape<Filter>["sort"];
|
|
7
14
|
declare class FieldTranslation<Languages extends [string, ...string[]]> {
|
|
8
15
|
static translate: <Languages_1 extends [string, ...string[]]>(trans: Languages_1) => FieldTranslation<Languages_1>;
|
|
9
16
|
trans: Languages;
|
|
@@ -95,12 +102,12 @@ export declare class ModelDictInfo<Languages extends [string, ...string[]] = [st
|
|
|
95
102
|
insight<Insight extends object>(translate: (t: (trans: Languages) => FieldTranslation<Languages>) => {
|
|
96
103
|
[K in Exclude<keyof GetStateObject<Insight>, InsightKey>]: FieldTranslation<Languages>;
|
|
97
104
|
}): ModelDictInfo<Languages, ModelKey, keyof GetStateObject<Insight> & string, QueryKey, SortKey, EnumKey, BaseSignalKey, SliceKey, EndpointKey, ErrorKey, EtcKey>;
|
|
98
|
-
query<Filter
|
|
99
|
-
[K in Exclude<keyof Filter
|
|
100
|
-
}): ModelDictInfo<Languages, ModelKey, InsightKey, keyof Filter
|
|
101
|
-
sort<Filter
|
|
102
|
-
[K in Exclude<keyof Filter
|
|
103
|
-
}): ModelDictInfo<Languages, ModelKey, InsightKey, QueryKey, keyof Filter
|
|
105
|
+
query<Filter>(translate: (fn: (trans: Languages) => FunctionTranslation<Languages>) => {
|
|
106
|
+
[K in Exclude<keyof DictFilterQuery<Filter>, QueryKey>]: DictFilterQuery<Filter>[K] extends FilterInfo<infer ArgNames, any> ? FunctionTranslation<Languages, ArgNames[number]> : never;
|
|
107
|
+
}): ModelDictInfo<Languages, ModelKey, InsightKey, keyof DictFilterQuery<Filter> & string, SortKey, EnumKey, BaseSignalKey, SliceKey, EndpointKey, ErrorKey, EtcKey>;
|
|
108
|
+
sort<Filter>(translate: (t: (trans: Languages) => FieldTranslation<Languages>) => {
|
|
109
|
+
[K in Exclude<keyof DictFilterSort<Filter>, SortKey>]: FieldTranslation<Languages>;
|
|
110
|
+
}): ModelDictInfo<Languages, ModelKey, InsightKey, QueryKey, keyof DictFilterSort<Filter> & string, EnumKey, BaseSignalKey, SliceKey, EndpointKey, ErrorKey, EtcKey>;
|
|
104
111
|
enum<Enum extends {
|
|
105
112
|
refName: string;
|
|
106
113
|
value: EnumValueKey;
|
|
@@ -108,10 +115,10 @@ export declare class ModelDictInfo<Languages extends [string, ...string[]] = [st
|
|
|
108
115
|
[K in Enum["value"]]: FieldTranslation<Languages>;
|
|
109
116
|
}): ModelDictInfo<Languages, ModelKey, InsightKey, QueryKey, SortKey, EnumKey | Enum["refName"], BaseSignalKey, SliceKey, EndpointKey, ErrorKey, EtcKey>;
|
|
110
117
|
slice<Slice>(translate: (fn: (trans: Languages) => FunctionTranslation<Languages>) => {
|
|
111
|
-
[K in Exclude<keyof Slice, SliceKey>]: Slice[K] extends
|
|
118
|
+
[K in Exclude<keyof Slice, SliceKey>]: Slice[K] extends infer Info extends SliceInfo ? FunctionTranslation<Languages, SliceInfoArgNames<Info>[number]> : never;
|
|
112
119
|
}): ModelDictInfo<Languages, ModelKey, InsightKey, QueryKey, SortKey, EnumKey, BaseSignalKey, keyof Slice & string, EndpointKey, ErrorKey, EtcKey>;
|
|
113
120
|
endpoint<Endpoint>(translate: (fn: (trans: Languages) => FunctionTranslation<Languages>) => {
|
|
114
|
-
[K in Exclude<keyof Endpoint, EndpointKey>]: Endpoint[K] extends
|
|
121
|
+
[K in Exclude<keyof Endpoint, EndpointKey>]: Endpoint[K] extends infer Info extends EndpointInfo ? FunctionTranslation<Languages, EndpInfoArgNames<Info>[number]> : never;
|
|
115
122
|
}): ModelDictInfo<Languages, ModelKey, InsightKey, QueryKey, SortKey, EnumKey, BaseSignalKey, SliceKey, keyof Endpoint & string, ErrorKey, EtcKey>;
|
|
116
123
|
error<ErrorDict extends {
|
|
117
124
|
[key: string]: Languages;
|
|
@@ -189,7 +196,7 @@ export declare class ServiceDictInfo<Languages extends [string, ...string[]] = [
|
|
|
189
196
|
endpoint<Endpoint extends {
|
|
190
197
|
[key: string]: EndpointInfo;
|
|
191
198
|
}>(translate: (fn: (trans: Languages) => FunctionTranslation<Languages>) => {
|
|
192
|
-
[K in keyof Endpoint]: FunctionTranslation<Languages, Endpoint[K][
|
|
199
|
+
[K in keyof Endpoint]: FunctionTranslation<Languages, EndpInfoArgNames<Endpoint[K]>[number]>;
|
|
193
200
|
}): ServiceDictInfo<Languages, keyof Endpoint & string, ErrorKey, EtcKey>;
|
|
194
201
|
error<ErrorDict extends {
|
|
195
202
|
[key: string]: Languages;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GetStateObject, MergedValues } from "akanjs/base";
|
|
2
2
|
import type { BaseInsight, BaseObject } from "akanjs/constant";
|
|
3
|
-
import type { FilterInfo, FilterInstance } from "akanjs/document";
|
|
4
|
-
import type { EndpointInfo, SliceInfo } from "akanjs/signal";
|
|
3
|
+
import type { FilterCls, FilterInfo, FilterInstance } from "akanjs/document";
|
|
4
|
+
import type { EndpInfoArgNames, EndpointInfo, SliceInfo, SliceInfoArgNames, SliceInfoRefName } from "akanjs/signal";
|
|
5
5
|
import type { ModelDictInfo, ScalarDictInfo, ServiceDictInfo } from ".";
|
|
6
6
|
interface Trans {
|
|
7
7
|
t: string;
|
|
@@ -17,16 +17,23 @@ interface FnTrans<ArgKey extends string> {
|
|
|
17
17
|
[key in ArgKey]: FieldTrans;
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
type
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
type AnyFilterShape = FilterInstance<Record<string, FilterInfo>, Record<string, unknown>>;
|
|
21
|
+
type DictFilterShape<Filter> = Filter extends FilterInstance ? Filter : Filter extends FilterCls<infer FilterShape> ? FilterShape : Filter extends {
|
|
22
|
+
query: Record<string, FilterInfo>;
|
|
23
|
+
sort: Record<string, unknown>;
|
|
24
|
+
} ? Filter : AnyFilterShape;
|
|
25
|
+
type DictFilterQuery<Filter> = DictFilterShape<Filter>["query"];
|
|
26
|
+
type DictFilterSort<Filter> = DictFilterShape<Filter>["sort"];
|
|
27
|
+
type FilterTranslatorKey<Filter> = {
|
|
28
|
+
[Key in keyof DictFilterQuery<Filter> & string]: `${Key}` | `${Key}.desc` | (DictFilterQuery<Filter>[Key] extends FilterInfo<infer ArgNames, any> ? ArgNames[number] extends string ? `${Key}.arg.${ArgNames[number]}` | `${Key}.arg.${ArgNames[number]}.desc` : never : never);
|
|
29
|
+
}[keyof DictFilterQuery<Filter> & string];
|
|
23
30
|
type EndpointTranslatorKey<Endpoint extends {
|
|
24
31
|
[key: string]: EndpointInfo;
|
|
25
32
|
}> = {
|
|
26
|
-
[Key in keyof Endpoint & string]: `${Key}` | `${Key}.desc` | `${Key}.arg.${Endpoint[Key][
|
|
33
|
+
[Key in keyof Endpoint & string]: `${Key}` | `${Key}.desc` | `${Key}.arg.${EndpInfoArgNames<Endpoint[Key]>[number]}` | `${Key}.arg.${EndpInfoArgNames<Endpoint[Key]>[number]}.desc`;
|
|
27
34
|
}[keyof Endpoint & string];
|
|
28
35
|
type SliceTranslatorKey<Slice> = {
|
|
29
|
-
[Key in keyof Slice & string]: Slice[Key] extends
|
|
36
|
+
[Key in keyof Slice & string]: Slice[Key] extends infer Info extends SliceInfo ? `${SliceInfoRefName<Info>}List${Capitalize<Key>}` | `${SliceInfoRefName<Info>}List${Capitalize<Key>}.desc` | `${SliceInfoRefName<Info>}List${Capitalize<Key>}.arg.${SliceInfoArgNames<Info>[number] | "skip" | "limit" | "sort"}` | `${SliceInfoRefName<Info>}List${Capitalize<Key>}.arg.${SliceInfoArgNames<Info>[number] | "skip" | "limit" | "sort"}.desc` | `${SliceInfoRefName<Info>}Insight${Capitalize<Key>}` | `${SliceInfoRefName<Info>}Insight${Capitalize<Key>}.desc` | `${SliceInfoRefName<Info>}Insight${Capitalize<Key>}.arg.${SliceInfoArgNames<Info>[number]}` | `${SliceInfoRefName<Info>}Insight${Capitalize<Key>}.arg.${SliceInfoArgNames<Info>[number]}.desc` : never;
|
|
30
37
|
}[keyof Slice & string];
|
|
31
38
|
type SliceApiTrans<T extends string, Suffix extends string, ArgName extends string, _CapitalizedSuffix extends string = Capitalize<Suffix>> = {
|
|
32
39
|
[K in `${T}List${_CapitalizedSuffix}`]: FnTrans<ArgName | "skip" | "limit" | "sort">;
|
|
@@ -44,7 +51,7 @@ type BaseModelCrudGetApiTrans<T extends string> = {
|
|
|
44
51
|
} & {
|
|
45
52
|
[K in `remove${T}`]: FnTrans<`${T}Id`>;
|
|
46
53
|
};
|
|
47
|
-
export type ModelTrans<T extends string, Model extends BaseObject, Insight extends BaseInsight, Filter
|
|
54
|
+
export type ModelTrans<T extends string, Model extends BaseObject, Insight extends BaseInsight, Filter, Slice extends {
|
|
48
55
|
[key: string]: SliceInfo;
|
|
49
56
|
}, Endpoint extends {
|
|
50
57
|
[key: string]: EndpointInfo;
|
|
@@ -58,15 +65,15 @@ export type ModelTrans<T extends string, Model extends BaseObject, Insight exten
|
|
|
58
65
|
[K in keyof GetStateObject<Insight>]: FieldTrans;
|
|
59
66
|
};
|
|
60
67
|
query: {
|
|
61
|
-
[K in keyof Filter
|
|
68
|
+
[K in keyof DictFilterQuery<Filter>]: DictFilterQuery<Filter>[K] extends FilterInfo<infer ArgNames, any> ? FnTrans<ArgNames[number]> : never;
|
|
62
69
|
};
|
|
63
70
|
sort: {
|
|
64
|
-
[K in keyof Filter
|
|
71
|
+
[K in keyof DictFilterSort<Filter>]: FieldTrans;
|
|
65
72
|
};
|
|
66
73
|
api: {
|
|
67
|
-
[K in keyof Endpoint]: FnTrans<Endpoint[K][
|
|
74
|
+
[K in keyof Endpoint]: FnTrans<EndpInfoArgNames<Endpoint[K]>[number]>;
|
|
68
75
|
} & BaseModelCrudGetApiTrans<T> & MergedValues<{
|
|
69
|
-
[K in keyof Slice]: SliceApiTrans<Slice[K]
|
|
76
|
+
[K in keyof Slice]: SliceApiTrans<SliceInfoRefName<Slice[K]>, K & string, SliceInfoArgNames<Slice[K]>[number]>;
|
|
70
77
|
}>;
|
|
71
78
|
error: {
|
|
72
79
|
[K in ErrorKey]: Trans;
|
|
@@ -74,11 +81,11 @@ export type ModelTrans<T extends string, Model extends BaseObject, Insight exten
|
|
|
74
81
|
} & {
|
|
75
82
|
[K in EtcKey]: Trans;
|
|
76
83
|
};
|
|
77
|
-
export type ModelTranslatorKey<T extends string, Model, Insight, Filter
|
|
84
|
+
export type ModelTranslatorKey<T extends string, Model, Insight, Filter, Slice extends {
|
|
78
85
|
[key: string]: SliceInfo;
|
|
79
86
|
}, Endpoint extends {
|
|
80
87
|
[key: string]: EndpointInfo;
|
|
81
|
-
}, EtcKey extends string> = `${T}.modelName` | `${T}.modelDesc` | `${T}.${keyof GetStateObject<Model> & string}${"" | ".desc"}` | `${T}.insight.${keyof GetStateObject<Insight> & string}${"" | ".desc"}` | `${T}.query.${FilterTranslatorKey<Filter>}` | `${T}.sort.${keyof Filter
|
|
88
|
+
}, EtcKey extends string> = `${T}.modelName` | `${T}.modelDesc` | `${T}.${keyof GetStateObject<Model> & string}${"" | ".desc"}` | `${T}.insight.${keyof GetStateObject<Insight> & string}${"" | ".desc"}` | `${T}.query.${FilterTranslatorKey<Filter>}` | `${T}.sort.${keyof DictFilterSort<Filter> & string}${"" | ".desc"}` | `${T}.signal.${EndpointTranslatorKey<Endpoint> | SliceTranslatorKey<Slice>}` | `${T}.${EtcKey}`;
|
|
82
89
|
export type ScalarTrans<T extends string, Model, ErrorKey extends string, EtcKey extends string> = {
|
|
83
90
|
name: Trans;
|
|
84
91
|
desc: Trans;
|
|
@@ -96,7 +103,7 @@ export type ServiceTrans<T extends string, Endpoint extends {
|
|
|
96
103
|
[key: string]: EndpointInfo;
|
|
97
104
|
}, ErrorKey extends string, EtcKey extends string> = {
|
|
98
105
|
api: {
|
|
99
|
-
[K in keyof Endpoint]: FnTrans<Endpoint[K][
|
|
106
|
+
[K in keyof Endpoint]: FnTrans<EndpInfoArgNames<Endpoint[K]>[number]>;
|
|
100
107
|
};
|
|
101
108
|
error: {
|
|
102
109
|
[K in ErrorKey]: Trans;
|
|
@@ -116,7 +123,7 @@ export interface DictModule<DictKey extends string, ErrorKey extends string> {
|
|
|
116
123
|
__Error_Key__: ErrorKey;
|
|
117
124
|
dict: ModelDictInfo<any> | ScalarDictInfo<any> | ServiceDictInfo<any>;
|
|
118
125
|
}
|
|
119
|
-
export declare const registerModelTrans: <RefName extends string, Model extends BaseObject, Insight extends BaseInsight, Filter
|
|
126
|
+
export declare const registerModelTrans: <RefName extends string, Model extends BaseObject, Insight extends BaseInsight, Filter, Slice extends {
|
|
120
127
|
[key: string]: SliceInfo;
|
|
121
128
|
}, Endpoint extends {
|
|
122
129
|
[key: string]: EndpointInfo;
|
package/types/document/by.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { type Cls, FIELD_META, type
|
|
2
|
-
import { type
|
|
3
|
-
export type DatabaseCls<Schema =
|
|
1
|
+
import { type Cls, FIELD_META, type GetActionObject, SERVER_VALUE } from "akanjs/base";
|
|
2
|
+
import { type DocumentConstantModelRef, type DocumentModel, type FieldObject } from "akanjs/constant";
|
|
3
|
+
export type DatabaseCls<Schema = unknown> = Cls<Schema, {
|
|
4
4
|
refName: string;
|
|
5
5
|
[FIELD_META]: FieldObject;
|
|
6
6
|
}>;
|
|
7
|
+
export type DatabaseInstanceOf<DatabaseRef extends DatabaseCls> = DatabaseRef extends new (...args: never[]) => infer Instance ? Instance : never;
|
|
8
|
+
type ConstantModelCls = DocumentConstantModelRef<unknown>;
|
|
7
9
|
export interface DefaultDocMtds<TDocument> {
|
|
8
10
|
refresh(): Promise<this>;
|
|
9
11
|
isModified(field?: keyof TDocument & string): boolean;
|
|
@@ -12,11 +14,46 @@ export interface DefaultDocMtds<TDocument> {
|
|
|
12
14
|
toJSON(): DocumentModel<TDocument>;
|
|
13
15
|
toObject(): DocumentModel<TDocument>;
|
|
14
16
|
}
|
|
17
|
+
type HydratedDocumentMethods<TDocument, Self> = Omit<DefaultDocMtds<TDocument>, "isModified" | "refresh" | "save" | "set"> & {
|
|
18
|
+
refresh(): Promise<Self>;
|
|
19
|
+
isModified(field?: keyof TDocument & string): boolean;
|
|
20
|
+
set(data: Partial<TDocument>): Self;
|
|
21
|
+
save(): Promise<Self>;
|
|
22
|
+
};
|
|
15
23
|
type HydratedDocumentWithId<TDocument> = TDocument & {
|
|
16
24
|
id: string;
|
|
17
|
-
} &
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
} & HydratedDocumentMethods<TDocument, TDocument>;
|
|
26
|
+
interface ChainableHydratedMethods<TDocument> extends Omit<DefaultDocMtds<TDocument>, "isModified" | "refresh" | "save" | "set"> {
|
|
27
|
+
refresh(): Promise<this>;
|
|
28
|
+
isModified(field?: keyof TDocument & string): boolean;
|
|
29
|
+
set(data: Partial<TDocument>): this;
|
|
30
|
+
save(): Promise<this>;
|
|
31
|
+
}
|
|
32
|
+
type ChainableHydratedDocument<TDocument> = TDocument & {
|
|
33
|
+
id: string;
|
|
34
|
+
} & ChainableHydratedMethods<TDocument>;
|
|
35
|
+
export type Doc<M = unknown> = HydratedDocumentWithId<DocumentModel<M>>;
|
|
36
|
+
type DatabaseSchemaOf<ModelCls> = ModelCls extends {
|
|
20
37
|
_DatabaseSchema: infer Schema;
|
|
21
|
-
} ? Schema : never
|
|
38
|
+
} ? Schema : never;
|
|
39
|
+
type ConstantValueOf<ModelCls> = ModelCls extends {
|
|
40
|
+
[SERVER_VALUE]: infer Schema;
|
|
41
|
+
} ? Schema : ModelCls extends new (...args: never[]) => infer Schema ? Schema : never;
|
|
42
|
+
type ObjectDocumentModelType = "object" | "full" | "light";
|
|
43
|
+
type ModelTypeOf<ModelCls> = ModelCls extends {
|
|
44
|
+
_ModelType: infer ModelType;
|
|
45
|
+
} ? ModelType : never;
|
|
46
|
+
type IsObjectModel<ModelCls> = ModelTypeOf<ModelCls> extends ObjectDocumentModelType ? true : false;
|
|
47
|
+
type DocModelOf<ModelCls, Schema = DatabaseSchemaOf<ModelCls>> = IsObjectModel<ModelCls> extends true ? ChainableHydratedDocument<DocumentModel<Schema>> : DocumentModel<Schema>;
|
|
48
|
+
type DocActionOmitKey<ModelCls, Schema = DatabaseSchemaOf<ModelCls>> = (keyof Schema & string) | (IsObjectModel<ModelCls> extends true ? keyof DefaultDocMtds<unknown> | "id" : never);
|
|
49
|
+
type DatabaseSchemaFor<ModelCls extends ConstantModelCls> = DatabaseSchemaOf<ModelCls> & ConstantValueOf<ModelCls>;
|
|
50
|
+
type DocModelFor<ModelCls extends ConstantModelCls> = DocModelOf<ModelCls, DatabaseSchemaFor<ModelCls>>;
|
|
51
|
+
type DocActionOmitKeyFor<ModelCls extends ConstantModelCls> = DocActionOmitKey<ModelCls, DatabaseSchemaFor<ModelCls>>;
|
|
52
|
+
type StrictDocumentActions<T> = string extends keyof T ? T[string] extends never ? Record<never, never> : GetActionObject<T> : GetActionObject<T>;
|
|
53
|
+
type DocumentActionsOf<AddDbModel extends DatabaseCls, OmitKey extends string> = Omit<StrictDocumentActions<DatabaseInstanceOf<AddDbModel>>, OmitKey>;
|
|
54
|
+
type MergeDocumentActions<AddDbModels extends readonly DatabaseCls[], OmitKey extends string, Acc = Record<never, never>> = AddDbModels extends readonly [infer First extends DatabaseCls, ...infer Rest extends readonly DatabaseCls[]] ? MergeDocumentActions<Rest, OmitKey, Acc & DocumentActionsOf<First, OmitKey>> : AddDbModels extends readonly (infer AddDbModel extends DatabaseCls)[] ? Acc & DocumentActionsOf<AddDbModel, OmitKey> : Acc;
|
|
55
|
+
type ByInstance<ModelCls extends ConstantModelCls, AddDbModels extends readonly DatabaseCls[], _OmitKey extends string = DocActionOmitKeyFor<ModelCls> & string, _DocModel = DocModelFor<ModelCls>> = MergeDocumentActions<AddDbModels, _OmitKey> & _DocModel;
|
|
56
|
+
export declare function by<ModelCls extends ConstantModelCls>(modelRef: ModelCls): DatabaseCls<DocModelFor<ModelCls>>;
|
|
57
|
+
export declare function by<ModelCls extends ConstantModelCls, AddDbModel extends DatabaseCls>(modelRef: ModelCls, addRef: AddDbModel): DatabaseCls<DocumentActionsOf<AddDbModel, DocActionOmitKeyFor<ModelCls> & string> & DocModelFor<ModelCls>>;
|
|
58
|
+
export declare function by<ModelCls extends ConstantModelCls, const AddDbModels extends DatabaseCls[]>(modelRef: ModelCls, ...addRefs: AddDbModels): DatabaseCls<ByInstance<ModelCls, AddDbModels>>;
|
|
22
59
|
export {};
|
|
@@ -39,18 +39,19 @@ type QueryMethodOfKey<CapitalizedK extends string, Doc, Insight, _Args extends a
|
|
|
39
39
|
} & {
|
|
40
40
|
[K in `query${CapitalizedK}`]: (...args: _Args) => _QueryOfDoc;
|
|
41
41
|
};
|
|
42
|
-
|
|
42
|
+
type QueryMethodMap<Query, Doc, Insight, _FindQueryOption, _ListQueryOption, _QueryOfDoc> = {
|
|
43
43
|
[K in keyof Query]: K extends string ? Query[K] extends (...args: infer Args) => any ? QueryMethodOfKey<Capitalize<K>, Doc, Insight, Args, [
|
|
44
44
|
...Args,
|
|
45
45
|
queryOption?: _ListQueryOption
|
|
46
46
|
], [
|
|
47
47
|
...Args,
|
|
48
48
|
queryOption?: _FindQueryOption
|
|
49
|
-
]> : never : never;
|
|
50
|
-
}
|
|
51
|
-
type
|
|
49
|
+
], _QueryOfDoc> : never : never;
|
|
50
|
+
};
|
|
51
|
+
export type QueryMethodPart<Query, Sort, Obj, Doc, Insight, _FindQueryOption = FindQueryOption<Sort, Obj>, _ListQueryOption = ListQueryOption<Sort, Obj>, _QueryOfDoc = QueryOf<Doc>> = MergedValues<QueryMethodMap<Query, Doc, Insight, _FindQueryOption, _ListQueryOption, _QueryOfDoc>>;
|
|
52
|
+
type DatabaseModelWithQuerySort<T extends string, Input, Doc, Obj, Insight, Query, Sort, _CapitalizedRefName extends string = Capitalize<T>, _QueryOfDoc = QueryOf<Doc>, _DocumentObj = DocumentModel<Obj>, _DataInput = DataInputOf<Input, _DocumentObj>, _FindQueryOption = FindQueryOption<Sort, Obj>, _ListQueryOption = ListQueryOption<Sort, Obj>> = {
|
|
52
53
|
logger: Logger;
|
|
53
|
-
__model: Mdl<Doc, Obj>;
|
|
54
|
+
__model: Mdl<Doc, Obj, _DocumentObj>;
|
|
54
55
|
__cache: CacheDatabase<T>;
|
|
55
56
|
__loader: DataLoader<string, Doc, string>;
|
|
56
57
|
__get: (id: string) => Promise<Doc>;
|
|
@@ -74,7 +75,7 @@ type DatabaseModelWithQuerySort<T extends string, Input, Doc, Obj, Insight, Quer
|
|
|
74
75
|
listenPre: (type: SaveEventType, listener: (doc: Doc, type: CRUDEventType) => PromiseOrObject<void>) => () => void;
|
|
75
76
|
listenPost: (type: SaveEventType, listener: (doc: Doc, type: CRUDEventType) => PromiseOrObject<void>) => () => void;
|
|
76
77
|
} & {
|
|
77
|
-
[key in _CapitalizedRefName]: Mdl<Doc, Obj>;
|
|
78
|
+
[key in _CapitalizedRefName]: Mdl<Doc, Obj, _DocumentObj>;
|
|
78
79
|
} & {
|
|
79
80
|
[key in `${T}Loader`]: DataLoader<string, Doc, string>;
|
|
80
81
|
} & {
|
|
@@ -92,5 +93,6 @@ type DatabaseModelWithQuerySort<T extends string, Input, Doc, Obj, Insight, Quer
|
|
|
92
93
|
} & {
|
|
93
94
|
[K in `remove${_CapitalizedRefName}`]: (id: string) => Promise<Doc>;
|
|
94
95
|
} & QueryMethodPart<Query, Sort, Obj, Doc, Insight, _FindQueryOption, _ListQueryOption, _QueryOfDoc>;
|
|
95
|
-
export type
|
|
96
|
+
export type DatabaseInstanceWithQuerySort<T extends string = string, Input = any, Doc = any, Obj = any, Insight = any, Query = ExtractQuery<FilterInstance>, Sort = ExtractSort<FilterInstance>, _CapitalizedRefName extends string = Capitalize<T>, _QueryOfDoc = QueryOf<Doc>, _DocumentObj = DocumentModel<Obj>, _DataInput = DataInputOf<Input, _DocumentObj>, _FindQueryOption = FindQueryOption<Sort, Obj>, _ListQueryOption = ListQueryOption<Sort, Obj>> = DatabaseModelWithQuerySort<T, Input, Doc, Obj, Insight, Query, Sort, _CapitalizedRefName, _QueryOfDoc, _DocumentObj, _DataInput, _FindQueryOption, _ListQueryOption>;
|
|
97
|
+
export type DatabaseInstance<T extends string = string, Input = any, Doc = any, Obj = any, Insight = any, Filter extends FilterInstance = FilterInstance, _CapitalizedRefName extends string = Capitalize<T>, _QueryOfDoc = QueryOf<Doc>, _Query = ExtractQuery<Filter>, _Sort = ExtractSort<Filter>, _DocumentObj = DocumentModel<Obj>, _DataInput = DataInputOf<Input, _DocumentObj>, _FindQueryOption = FindQueryOption<_Sort, Obj>, _ListQueryOption = ListQueryOption<_Sort, Obj>> = DatabaseInstanceWithQuerySort<T, Input, Doc, Obj, Insight, _Query, _Sort, _CapitalizedRefName, _QueryOfDoc, _DocumentObj, _DataInput, _FindQueryOption, _ListQueryOption>;
|
|
96
98
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ConstantCls } from "akanjs/constant";
|
|
2
|
-
import type { DatabaseCls, ExtractSort, FilterCls, FilterInstance } from ".";
|
|
2
|
+
import type { DatabaseCls, ExtractQuery, ExtractSort, FilterCls, FilterInstance } from ".";
|
|
3
3
|
import type { ModelCls } from "./loaderInfo.d.ts";
|
|
4
|
-
export interface DatabaseModel<T extends string = string, Input = any, Doc = any, Model = any, Obj = any, Insight = any, Filter extends FilterInstance = any, _Sort extends ExtractSort<Filter> = ExtractSort<Filter>> {
|
|
4
|
+
export interface DatabaseModel<T extends string = string, Input = any, Doc = any, Model = any, Obj = any, Insight = any, Filter extends FilterInstance = any, _Query extends ExtractQuery<Filter> = ExtractQuery<Filter>, _Sort extends ExtractSort<Filter> = ExtractSort<Filter>> {
|
|
5
5
|
refName: T;
|
|
6
6
|
input: DatabaseCls<Input>;
|
|
7
7
|
doc: DatabaseCls<Doc>;
|
|
@@ -15,6 +15,7 @@ export interface DatabaseModel<T extends string = string, Input = any, Doc = any
|
|
|
15
15
|
_Obj: Obj;
|
|
16
16
|
_Insight: Insight;
|
|
17
17
|
_Filter: Filter;
|
|
18
|
+
_Query: _Query;
|
|
18
19
|
_Sort: _Sort;
|
|
19
20
|
}
|
|
20
21
|
export declare class DatabaseRegistry {
|
|
@@ -23,7 +24,7 @@ export declare class DatabaseRegistry {
|
|
|
23
24
|
static isDoc(modelRef: DatabaseCls): boolean;
|
|
24
25
|
static isModel(modelRef: DatabaseCls): boolean;
|
|
25
26
|
static isScalar(modelRef: DatabaseCls): boolean;
|
|
26
|
-
static setDatabase(refName: string, dbModel: DatabaseModel): DatabaseModel<string, any, any, any, any, any, any, string | number | symbol>;
|
|
27
|
+
static setDatabase(refName: string, dbModel: DatabaseModel): DatabaseModel<string, any, any, any, any, any, any, ExtractQuery<any>, string | number | symbol>;
|
|
27
28
|
static getDatabase<AllowEmpty extends boolean = false>(refName: string, { allowEmpty }?: {
|
|
28
29
|
allowEmpty?: AllowEmpty;
|
|
29
30
|
}): AllowEmpty extends true ? DatabaseModel | undefined : DatabaseModel;
|
|
@@ -31,6 +32,6 @@ export declare class DatabaseRegistry {
|
|
|
31
32
|
static getScalar<AllowEmpty extends boolean = false>(refName: string, { allowEmpty }?: {
|
|
32
33
|
allowEmpty?: AllowEmpty;
|
|
33
34
|
}): AllowEmpty extends true ? DatabaseCls | undefined : DatabaseCls;
|
|
34
|
-
static buildModel<T extends string, Input, Doc, Model, Obj, Insight, Filter extends FilterInstance, _Sort extends ExtractSort<Filter> = ExtractSort<Filter>>(refName: T, input: DatabaseCls<Input>, doc: DatabaseCls<Doc>, model: ModelCls<Model>, obj: ConstantCls<Obj>, insight: ConstantCls<Insight>, filter: FilterCls<Filter>): DatabaseModel<T, Input, Doc, Model, Obj, Insight, Filter, _Sort>;
|
|
35
|
+
static buildModel<T extends string, Input, Doc, Model, Obj, Insight, Filter extends FilterInstance, _Query extends ExtractQuery<Filter> = ExtractQuery<Filter>, _Sort extends ExtractSort<Filter> = ExtractSort<Filter>>(refName: T, input: DatabaseCls<Input>, doc: DatabaseCls<Doc>, model: ModelCls<Model>, obj: ConstantCls<Obj>, insight: ConstantCls<Insight>, filter: FilterCls<Filter>): DatabaseModel<T, Input, Doc, Model, Obj, Insight, Filter, _Query, _Sort>;
|
|
35
36
|
static buildScalar<T extends string, Model>(refName: T, Model: DatabaseCls<Model>): DatabaseCls<Model>;
|
|
36
37
|
}
|
|
@@ -41,26 +41,33 @@ interface BaseSort {
|
|
|
41
41
|
createdAt: 1;
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
|
+
type LibFilterQuery<LibFilters extends FilterCls[]> = MergeAllDoubleKeyOfObjects<LibFilters, typeof FILTER_META, "query">;
|
|
45
|
+
type LibFilterSort<LibFilters extends FilterCls[]> = MergeAllKeyOfTypes<LibFilters, "sort">;
|
|
46
|
+
type FilterQuery<Full, LibFilters extends FilterCls[], Filter extends FilterInstance> = BaseQuery<Full> & LibFilterQuery<LibFilters> & Filter["query"];
|
|
47
|
+
type FilterSort<LibFilters extends FilterCls[], Filter extends FilterInstance> = BaseSort & LibFilterSort<LibFilters> & Filter["sort"];
|
|
48
|
+
type MergedFilterInstance<Full, LibFilters extends FilterCls[], Filter extends FilterInstance> = {
|
|
49
|
+
query: FilterQuery<Full, LibFilters, Filter>;
|
|
50
|
+
sort: FilterSort<LibFilters, Filter>;
|
|
51
|
+
};
|
|
44
52
|
export type ExtractQuery<Filter extends FilterInstance> = {
|
|
45
53
|
[K in keyof Filter["query"]]: Filter["query"][K] extends FilterInfo<any, infer Args> ? (...args: Args) => QueryOf<any> : never;
|
|
46
54
|
};
|
|
47
55
|
export type ExtractSort<Filter extends FilterInstance> = keyof Filter["sort"];
|
|
48
|
-
export interface FilterCls<Filter extends FilterInstance = any> extends Cls<{
|
|
56
|
+
export interface FilterCls<Filter extends FilterInstance = any, Query = unknown, Sort = unknown> extends Cls<{
|
|
49
57
|
[key: string]: any;
|
|
50
58
|
}> {
|
|
51
59
|
[FILTER_META]: Filter;
|
|
52
60
|
sortField: Set<string>;
|
|
61
|
+
_Query: Query;
|
|
62
|
+
_Sort: Sort;
|
|
53
63
|
}
|
|
54
|
-
export
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
sortField: Set<string>;
|
|
63
|
-
}>;
|
|
64
|
+
export type FilterQueryOf<FilterRef extends FilterCls> = FilterRef extends {
|
|
65
|
+
_Query: infer Query;
|
|
66
|
+
} ? Query : never;
|
|
67
|
+
export type FilterSortOf<FilterRef extends FilterCls> = FilterRef extends {
|
|
68
|
+
_Sort: infer Sort;
|
|
69
|
+
} ? Sort : never;
|
|
70
|
+
export declare const from: <Full extends BaseObject, BuildFilter extends (filter: () => FilterInfo<[], [], Full>) => FilterInstance, LibFilters extends FilterCls[], _Filter extends ReturnType<BuildFilter>, _MergedFilter extends FilterInstance = MergedFilterInstance<Full, LibFilters, _Filter>, _Query = ExtractQuery<_MergedFilter>, _Sort = ExtractSort<_MergedFilter>>(modelRef: Cls<Full>, buildFilter: BuildFilter, ...libFilterRefs: LibFilters) => FilterCls<_MergedFilter, _Query, _Sort>;
|
|
64
71
|
interface ArgProps<Value = unknown> {
|
|
65
72
|
nullable?: boolean;
|
|
66
73
|
ref?: string;
|
package/types/document/into.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { type Cls, type
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
1
|
+
import { type Cls, type PromiseOrObject } from "akanjs/base";
|
|
2
|
+
import type { DocumentModel, QueryOf } from "akanjs/constant";
|
|
3
|
+
import type { FilterCls, FilterQueryOf, FilterSortOf } from ".";
|
|
4
|
+
import type { CacheDatabase, QueryMethodPart } from "./database.d.ts";
|
|
5
|
+
import type { DataLoader } from "./dataLoader.d.ts";
|
|
5
6
|
import type { DocumentUpdate, DocumentUpdateOptions } from "./documentQuery.d.ts";
|
|
6
7
|
import { type LoaderBuilder, type ModelCls } from "./loaderInfo.d.ts";
|
|
8
|
+
import type { DocumentProjection } from "./types.d.ts";
|
|
7
9
|
export type CRUDEventType = "create" | "update" | "remove";
|
|
8
10
|
export type SaveEventType = "save" | CRUDEventType;
|
|
9
|
-
interface DefaultMdlStats<TDocument, TSchema, _Partial extends Partial<TSchema> = Partial<TSchema>, _FilterQuery extends QueryOf<TSchema> = QueryOf<TSchema>, _Projection
|
|
11
|
+
interface DefaultMdlStats<TDocument, TSchema, _Partial extends Partial<TSchema> = Partial<TSchema>, _FilterQuery extends QueryOf<TSchema> = QueryOf<TSchema>, _Projection = DocumentProjection<TSchema>> {
|
|
10
12
|
pickOneAndWrite: (query: _FilterQuery, rawData: _Partial) => Promise<TDocument>;
|
|
11
13
|
pickAndWrite: (docId: string, rawData: _Partial) => Promise<TDocument>;
|
|
12
14
|
pickOne: (query: _FilterQuery, projection?: _Projection) => Promise<TDocument>;
|
|
@@ -30,9 +32,9 @@ export interface UpdateResult {
|
|
|
30
32
|
modifiedCount: number;
|
|
31
33
|
upsertedId?: string | null;
|
|
32
34
|
}
|
|
33
|
-
export interface BulkWriteOperation<Raw
|
|
35
|
+
export interface BulkWriteOperation<Raw, _RawDoc = DocumentModel<Raw>, _RawQuery = QueryOf<_RawDoc>> {
|
|
34
36
|
updateOne: {
|
|
35
|
-
filter:
|
|
37
|
+
filter: _RawQuery;
|
|
36
38
|
update: DocumentUpdate;
|
|
37
39
|
upsert?: boolean;
|
|
38
40
|
};
|
|
@@ -48,18 +50,43 @@ type FindOneChain<Doc> = Promise<Doc | null> & {
|
|
|
48
50
|
skip(skip: number): FindOneChain<Doc>;
|
|
49
51
|
select(projection?: unknown): FindOneChain<Doc>;
|
|
50
52
|
};
|
|
51
|
-
export type Mdl<Doc, Raw> = DefaultMdlStats<Doc,
|
|
53
|
+
export type Mdl<Doc, Raw, _RawDoc = DocumentModel<Raw>, _RawQuery = QueryOf<_RawDoc>, _Projection extends DocumentProjection<Raw> = DocumentProjection<Raw>> = DefaultMdlStats<Doc, _RawDoc, Partial<_RawDoc>, _RawQuery, _Projection> & {
|
|
52
54
|
refName: string;
|
|
53
|
-
new (data: Partial<
|
|
54
|
-
find(query:
|
|
55
|
-
findOne(query:
|
|
56
|
-
findById(id: string | undefined, projection?:
|
|
57
|
-
countDocuments(query:
|
|
58
|
-
exists(query:
|
|
59
|
-
updateOne(query:
|
|
60
|
-
updateMany(query:
|
|
61
|
-
deleteMany(query:
|
|
62
|
-
bulkWrite(operations: BulkWriteOperation<Raw>[]): Promise<UpdateResult>;
|
|
55
|
+
new (data: Partial<_RawDoc> | Partial<Doc>): Doc;
|
|
56
|
+
find(query: _RawQuery, projection?: _Projection): FindManyChain<Doc>;
|
|
57
|
+
findOne(query: _RawQuery, projection?: _Projection): FindOneChain<Doc>;
|
|
58
|
+
findById(id: string | undefined, projection?: _Projection): Promise<Doc | null>;
|
|
59
|
+
countDocuments(query: _RawQuery): Promise<number>;
|
|
60
|
+
exists(query: _RawQuery): Promise<string | null>;
|
|
61
|
+
updateOne(query: _RawQuery, update: DocumentUpdate, options?: DocumentUpdateOptions): Promise<UpdateResult>;
|
|
62
|
+
updateMany(query: _RawQuery, update: DocumentUpdate): Promise<UpdateResult>;
|
|
63
|
+
deleteMany(query: _RawQuery): Promise<UpdateResult>;
|
|
64
|
+
bulkWrite(operations: BulkWriteOperation<Raw, _RawDoc, _RawQuery>[]): Promise<UpdateResult>;
|
|
63
65
|
};
|
|
64
|
-
|
|
66
|
+
interface IntoConstantModel<T extends string, _CapitalizedRefName extends string, Raw> {
|
|
67
|
+
refName: T;
|
|
68
|
+
_CapitalizedRefName: _CapitalizedRefName;
|
|
69
|
+
_Full: Raw;
|
|
70
|
+
}
|
|
71
|
+
type NoInferType<T> = [T][T extends unknown ? 0 : never];
|
|
72
|
+
type IntoModelActions<T extends string, _CapitalizedRefName extends string, Doc, Raw, _Query, _Sort, _QueryOfDoc = QueryOf<Doc>> = {
|
|
73
|
+
[key in _CapitalizedRefName]: Mdl<Doc, Raw>;
|
|
74
|
+
} & {
|
|
75
|
+
[key in `${Uncapitalize<_CapitalizedRefName>}Loader`]: DataLoader<string, Doc, string>;
|
|
76
|
+
} & {
|
|
77
|
+
[key in `${Uncapitalize<_CapitalizedRefName>}Cache`]: CacheDatabase<T>;
|
|
78
|
+
} & {
|
|
79
|
+
[K in `get${_CapitalizedRefName}`]: (id: string) => Promise<Doc>;
|
|
80
|
+
} & {
|
|
81
|
+
[K in `load${_CapitalizedRefName}`]: (id?: string) => Promise<Doc | null>;
|
|
82
|
+
} & {
|
|
83
|
+
[K in `load${_CapitalizedRefName}Many`]: (ids: string[]) => Promise<Doc[]>;
|
|
84
|
+
} & {
|
|
85
|
+
[K in `create${_CapitalizedRefName}`]: (data: Partial<Doc>) => Promise<Doc>;
|
|
86
|
+
} & {
|
|
87
|
+
[K in `update${_CapitalizedRefName}`]: (id: string, data: Partial<Doc>) => Promise<Doc>;
|
|
88
|
+
} & {
|
|
89
|
+
[K in `remove${_CapitalizedRefName}`]: (id: string) => Promise<Doc>;
|
|
90
|
+
} & QueryMethodPart<_Query, _Sort, Raw, Doc, unknown, unknown, unknown, _QueryOfDoc>;
|
|
91
|
+
export declare const into: <Doc, FilterRef extends FilterCls, T extends string, Raw, AddDbModels extends ModelCls[], _CapitalizedRefName extends string, _QueryOfDoc = QueryOf<Doc>, _Query = FilterQueryOf<FilterRef>, _Sort = FilterSortOf<FilterRef>, _LoaderBuilder extends LoaderBuilder<NoInferType<Doc>> = LoaderBuilder<Doc>>(docRef: Cls<Doc>, filterRef: FilterRef, cnst: IntoConstantModel<T, _CapitalizedRefName, Raw>, loaderBuilder: _LoaderBuilder, ...addMdls: [...AddDbModels]) => ModelCls<IntoModelActions<T, _CapitalizedRefName, Doc, Raw, _Query, _Sort, _QueryOfDoc>, ReturnType<_LoaderBuilder>>;
|
|
65
92
|
export {};
|
|
@@ -20,17 +20,18 @@ export interface FilterArgProps {
|
|
|
20
20
|
renderOption?: (value: never) => string;
|
|
21
21
|
enum?: EnumInstance;
|
|
22
22
|
}
|
|
23
|
+
export type DocumentProjection<T> = Partial<Record<keyof T, boolean>>;
|
|
23
24
|
export interface ListQueryOption<Sort = never, Obj = any> {
|
|
24
25
|
skip?: number | null;
|
|
25
26
|
limit?: number | null;
|
|
26
27
|
sort?: Sort | null;
|
|
27
28
|
sample?: number;
|
|
28
|
-
select?:
|
|
29
|
+
select?: DocumentProjection<Obj>;
|
|
29
30
|
}
|
|
30
31
|
export interface FindQueryOption<Sort = never, Obj = any> {
|
|
31
32
|
skip?: number | null;
|
|
32
33
|
sort?: Sort | null;
|
|
33
34
|
sample?: boolean;
|
|
34
|
-
select?:
|
|
35
|
+
select?: DocumentProjection<Obj>;
|
|
35
36
|
}
|
|
36
37
|
export type { SchemaOf } from "./documentSchema.d.ts";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ENDPOINT_META, PromiseOrObject } from "akanjs/base";
|
|
2
2
|
import type { FetchPolicy } from "akanjs/common";
|
|
3
|
-
import type { EndpInfoArgs, EndpInfoClientReturns, EndpInfoNullable, EndpInfoReqType, EndpointCls, EndpointInfo, SliceCls } from "akanjs/signal";
|
|
3
|
+
import type { EndpInfoArgs, EndpInfoClientReturns, EndpInfoNullable, EndpInfoReqType, EndpointCls, EndpointInfo, SlceCnstFull, SlceCnstInsight, SlceCnstLight, SliceCls } from "akanjs/signal";
|
|
4
4
|
type ExtendedEndpointReturn<ClientReturns, Full, Light, Insight> = ClientReturns extends (infer R)[] ? ExtendedEndpointReturn<R, Full, Light, Insight>[] : Full extends ClientReturns ? Full : Light extends ClientReturns ? Light : Insight extends ClientReturns ? Insight : ClientReturns;
|
|
5
|
-
type EndpointClientReturns<E, SlceCls extends SliceCls | never> = [SlceCls] extends [never] ? EndpInfoClientReturns<E> : ExtendedEndpointReturn<EndpInfoClientReturns<E>, SlceCls
|
|
5
|
+
type EndpointClientReturns<E, SlceCls extends SliceCls | never> = [SlceCls] extends [never] ? EndpInfoClientReturns<E> : ExtendedEndpointReturn<EndpInfoClientReturns<E>, SlceCnstFull<SlceCls>, SlceCnstLight<SlceCls>, SlceCnstInsight<SlceCls>>;
|
|
6
6
|
type EndpInfoReturns<E, SlceCls extends SliceCls | never> = EndpointClientReturns<E, SlceCls> | (EndpInfoNullable<E> extends true ? null : never);
|
|
7
7
|
type QueryOrMutationFetchFn<E, SlceCls extends SliceCls | never> = (...args: [...EndpInfoArgs<E>, fetchPolicy?: FetchPolicy]) => Promise<EndpInfoReturns<E, SlceCls>>;
|
|
8
8
|
type MessageEmitFn<E, SlceCls extends SliceCls | never> = (...args: EndpInfoArgs<E>) => EndpInfoReturns<E, SlceCls>;
|
|
@@ -2,19 +2,19 @@ import type { GetStateObject, SLICE_META } from "akanjs/base";
|
|
|
2
2
|
import type { FetchPolicy } from "akanjs/common";
|
|
3
3
|
import type { ConstantModel, DefaultOf, ProtoFile, PurifiedModel } from "akanjs/constant";
|
|
4
4
|
import type { DatabaseModel, ExtractSort, FilterInstance } from "akanjs/document";
|
|
5
|
-
import type { SliceCls, SliceInfoArgs } from "akanjs/signal";
|
|
5
|
+
import type { SlceCnstCapitalizedRefName, SlceCnstDefaultInput, SlceCnstFull, SlceCnstInput, SlceCnstInsight, SlceCnstLight, SlceCnstPurifiedInput, SlceCnstRefName, SlceDbFilter, SlceDbSort, SliceCls, SliceInfoArgs } from "akanjs/signal";
|
|
6
6
|
import type { ClientEdit, ClientInit, ClientView, EditReturn, InitReturn, ViewReturn } from "./appliedReturn.type";
|
|
7
7
|
type _SliceMap<S extends SliceCls> = S[typeof SLICE_META];
|
|
8
|
-
type _RefName<S extends SliceCls> = S
|
|
9
|
-
type _Cap<S extends SliceCls> = S
|
|
10
|
-
type _Input<S extends SliceCls> = S
|
|
11
|
-
type _Full<S extends SliceCls> = S
|
|
12
|
-
type _Light<S extends SliceCls> = S
|
|
13
|
-
type _Insight<S extends SliceCls> = S
|
|
14
|
-
type _PurifiedInput<S extends SliceCls> = S
|
|
15
|
-
type _DefaultInput<S extends SliceCls> = S
|
|
16
|
-
type _Filter<S extends SliceCls> = S
|
|
17
|
-
type _Sort<S extends SliceCls> = S
|
|
8
|
+
type _RefName<S extends SliceCls> = SlceCnstRefName<S>;
|
|
9
|
+
type _Cap<S extends SliceCls> = SlceCnstCapitalizedRefName<S>;
|
|
10
|
+
type _Input<S extends SliceCls> = SlceCnstInput<S>;
|
|
11
|
+
type _Full<S extends SliceCls> = SlceCnstFull<S>;
|
|
12
|
+
type _Light<S extends SliceCls> = SlceCnstLight<S>;
|
|
13
|
+
type _Insight<S extends SliceCls> = SlceCnstInsight<S>;
|
|
14
|
+
type _PurifiedInput<S extends SliceCls> = SlceCnstPurifiedInput<S>;
|
|
15
|
+
type _DefaultInput<S extends SliceCls> = SlceCnstDefaultInput<S>;
|
|
16
|
+
type _Filter<S extends SliceCls> = SlceDbFilter<S>;
|
|
17
|
+
type _Sort<S extends SliceCls> = SlceDbSort<S>;
|
|
18
18
|
type _LightWithId<S extends SliceCls> = _Light<S> extends {
|
|
19
19
|
id: string;
|
|
20
20
|
} ? _Light<S> : {
|
package/types/service/serve.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type Cls, INJECT_META } from "akanjs/base";
|
|
2
2
|
import { Logger } from "akanjs/common";
|
|
3
|
-
import type { DatabaseModel
|
|
3
|
+
import type { DatabaseModel } from "akanjs/document";
|
|
4
4
|
import { type ExtractInjectInfoObject, type InjectBuilder, InjectInfo } from "./injectInfo.d.ts";
|
|
5
|
-
import type {
|
|
5
|
+
import type { DatabaseServiceForModel } from "./types.d.ts";
|
|
6
6
|
interface ServiceOptions {
|
|
7
7
|
enabled?: boolean;
|
|
8
8
|
serverMode?: "batch" | "federation";
|
|
@@ -25,7 +25,6 @@ export type ServiceCls<RefName extends string = string, Methods = {}, InjectMap
|
|
|
25
25
|
}>;
|
|
26
26
|
export declare function serve<RefName extends string, Injection extends InjectBuilder>(refName: RefName, injectBuilder: Injection, ...extendSrvs: Cls[]): ServiceCls<RefName, {}, ReturnType<Injection>>;
|
|
27
27
|
export declare function serve<RefName extends string, Injection extends InjectBuilder>(refName: RefName, option: ServiceOptions, injectBuilder: Injection, ...extendSrvs: Cls[]): ServiceCls<RefName, {}, ReturnType<Injection>>;
|
|
28
|
-
export declare function serve<
|
|
29
|
-
export declare function serve<
|
|
30
|
-
export declare function serve<T extends string, Input, Doc, Model, Obj, Insight, Filter extends FilterInstance, Injection extends InjectBuilder, LibSrvs extends ServiceCls[] = []>(db: DatabaseModel<T, Input, Doc, Model, Obj, Insight, Filter>, option: ServiceOptions, injectBuilder: Injection, ...extendSrvs: LibSrvs): ServiceCls<T, DatabaseService<T, Input, Doc, Obj, Model, Insight, Filter, LibSrvs>, ReturnType<Injection>>;
|
|
28
|
+
export declare function serve<Db extends DatabaseModel, Injection extends InjectBuilder, LibSrvs extends Cls[] = []>(db: Db, injectBuilder: Injection, ...extendSrvs: LibSrvs): ServiceCls<Db["refName"], DatabaseServiceForModel<Db, LibSrvs>, ReturnType<Injection>>;
|
|
29
|
+
export declare function serve<Db extends DatabaseModel, Injection extends InjectBuilder, LibSrvs extends Cls[] = []>(db: Db, option: ServiceOptions, injectBuilder: Injection, ...extendSrvs: LibSrvs): ServiceCls<Db["refName"], DatabaseServiceForModel<Db, LibSrvs>, ReturnType<Injection>>;
|
|
31
30
|
export {};
|
|
@@ -19,7 +19,7 @@ export declare class ServiceModel<Srv extends ServiceCls = ServiceCls, CnstModel
|
|
|
19
19
|
static from<Srv extends ServiceCls>(srv: Srv): ServiceModel<Srv, never, never, { [K in `${Uncapitalize<Srv["refName"]>}Service`]: UnCls<Srv>; }>;
|
|
20
20
|
with<SrvModules extends ServiceModel[]>(...srvs: SrvModules): ServiceModel<Srv, CnstModel, DbModel, SrvMap & MergeAllKeyOfObjects<SrvModules, "srvMap">>;
|
|
21
21
|
static getDefaultDbServiceMethods(className: string): {
|
|
22
|
-
[x: string]: ((this: DatabaseService, query: QueryOf<any>, queryOption?: ListQueryOption) => Promise<any>) | ((this: DatabaseService, query: QueryOf<any>, queryOption?: FindQueryOption) => Promise<any>) | ((this: DatabaseService, type: SaveEventType, listener: (doc: Doc, type: CRUDEventType) => PromiseOrObject<void>) => any) | ((this: DatabaseService, id: string, data: DataInputOf) => Promise<any>);
|
|
22
|
+
[x: string]: ((this: DatabaseService, query: QueryOf<any>, queryOption?: ListQueryOption) => Promise<any>) | ((this: DatabaseService, query: QueryOf<any>, queryOption?: FindQueryOption) => Promise<any>) | ((this: DatabaseService, id: string, data: Partial<Doc>) => Promise<Partial<Doc>>) | ((this: DatabaseService, type: SaveEventType, listener: (doc: Doc, type: CRUDEventType) => PromiseOrObject<void>) => any) | ((this: DatabaseService, id: string, data: DataInputOf) => Promise<any>);
|
|
23
23
|
__get(this: DatabaseService, id: string): Promise<any>;
|
|
24
24
|
__load(this: DatabaseService, id?: string): Promise<any>;
|
|
25
25
|
__loadMany(this: DatabaseService, ids: string[]): Promise<any>;
|
|
@@ -33,11 +33,11 @@ export declare class ServiceModel<Srv extends ServiceCls = ServiceCls, CnstModel
|
|
|
33
33
|
__count(this: DatabaseService, query: QueryOf<any>): Promise<any>;
|
|
34
34
|
__insight(this: DatabaseService, query: QueryOf<any>): Promise<any>;
|
|
35
35
|
_preCreate(this: DatabaseService, data: DataInputOf): Promise<DataInputOf>;
|
|
36
|
-
_postCreate(this: DatabaseService, doc: Doc): Promise<
|
|
37
|
-
_preUpdate(this: DatabaseService, id: string, data: Partial<Doc>): Promise<Partial<
|
|
38
|
-
_postUpdate(this: DatabaseService, doc: Doc): Promise<
|
|
36
|
+
_postCreate(this: DatabaseService, doc: Doc): Promise<Doc>;
|
|
37
|
+
_preUpdate(this: DatabaseService, id: string, data: Partial<Doc>): Promise<Partial<Doc>>;
|
|
38
|
+
_postUpdate(this: DatabaseService, doc: Doc): Promise<Doc>;
|
|
39
39
|
_preRemove(this: DatabaseService, id: string): Promise<void>;
|
|
40
|
-
_postRemove(this: DatabaseService, doc: Doc): Promise<
|
|
40
|
+
_postRemove(this: DatabaseService, doc: Doc): Promise<Doc>;
|
|
41
41
|
listenPre(this: DatabaseService, type: SaveEventType, listener: (doc: Doc, type: CRUDEventType) => PromiseOrObject<void>): any;
|
|
42
42
|
listenPost(this: DatabaseService, type: SaveEventType, listener: (doc: Doc, type: CRUDEventType) => PromiseOrObject<void>): any;
|
|
43
43
|
__create(this: DatabaseService, data: DataInputOf): Promise<any>;
|