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.
Files changed (81) hide show
  1. package/base/base.ts +6 -2
  2. package/base/primitiveRegistry.ts +50 -46
  3. package/base/symbols.ts +16 -11
  4. package/base/types.ts +12 -0
  5. package/constant/constantRegistry.ts +10 -9
  6. package/constant/deserialize.ts +7 -7
  7. package/constant/fieldInfo.ts +173 -31
  8. package/constant/getDefault.ts +2 -2
  9. package/constant/immerify.ts +2 -2
  10. package/constant/purify.ts +19 -4
  11. package/constant/serialize.ts +6 -5
  12. package/constant/types.ts +9 -1
  13. package/constant/via.ts +312 -57
  14. package/dictionary/dictInfo.ts +28 -38
  15. package/dictionary/locale.ts +36 -38
  16. package/document/by.ts +84 -21
  17. package/document/database.ts +53 -18
  18. package/document/databaseRegistry.ts +7 -3
  19. package/document/filterMeta.ts +26 -14
  20. package/document/into.ts +71 -76
  21. package/document/types.ts +4 -2
  22. package/fetch/fetchType/endpointFetch.type.ts +6 -3
  23. package/fetch/fetchType/sliceFetch.type.ts +24 -13
  24. package/package.json +1 -1
  25. package/service/predefinedAdaptor/compress.adaptor.ts +9 -9
  26. package/service/predefinedAdaptor/database.adaptor.ts +3 -7
  27. package/service/serve.ts +17 -52
  28. package/service/types.ts +61 -21
  29. package/signal/endpoint.ts +2 -1
  30. package/signal/endpointInfo.ts +53 -23
  31. package/signal/internal.ts +2 -1
  32. package/signal/internalInfo.ts +71 -23
  33. package/signal/serverSignal.ts +23 -57
  34. package/signal/slice.ts +35 -35
  35. package/signal/sliceInfo.ts +63 -47
  36. package/signal/types.ts +23 -17
  37. package/store/action.ts +57 -44
  38. package/store/state.ts +47 -36
  39. package/store/stateBuilder.ts +3 -3
  40. package/store/store.ts +61 -15
  41. package/store/types.ts +16 -6
  42. package/types/base/base.d.ts +5 -1
  43. package/types/base/primitiveRegistry.d.ts +43 -38
  44. package/types/base/symbols.d.ts +5 -0
  45. package/types/base/types.d.ts +1 -0
  46. package/types/constant/constantRegistry.d.ts +3 -8
  47. package/types/constant/deserialize.d.ts +2 -2
  48. package/types/constant/fieldInfo.d.ts +41 -20
  49. package/types/constant/immerify.d.ts +2 -2
  50. package/types/constant/purify.d.ts +3 -2
  51. package/types/constant/serialize.d.ts +2 -2
  52. package/types/constant/types.d.ts +6 -1
  53. package/types/constant/via.d.ts +143 -22
  54. package/types/dictionary/dictInfo.d.ts +18 -11
  55. package/types/dictionary/locale.d.ts +23 -16
  56. package/types/document/by.d.ts +44 -7
  57. package/types/document/database.d.ts +9 -7
  58. package/types/document/databaseRegistry.d.ts +5 -4
  59. package/types/document/filterMeta.d.ts +18 -11
  60. package/types/document/into.d.ts +46 -19
  61. package/types/document/types.d.ts +3 -2
  62. package/types/fetch/fetchType/endpointFetch.type.d.ts +2 -2
  63. package/types/fetch/fetchType/sliceFetch.type.d.ts +11 -11
  64. package/types/service/serve.d.ts +4 -5
  65. package/types/service/serviceModule.d.ts +5 -5
  66. package/types/service/types.d.ts +23 -5
  67. package/types/signal/endpoint.d.ts +2 -1
  68. package/types/signal/endpointInfo.d.ts +40 -15
  69. package/types/signal/internal.d.ts +2 -1
  70. package/types/signal/internalInfo.d.ts +46 -12
  71. package/types/signal/serverSignal.d.ts +15 -12
  72. package/types/signal/slice.d.ts +8 -6
  73. package/types/signal/sliceInfo.d.ts +41 -20
  74. package/types/signal/types.d.ts +23 -17
  75. package/types/store/action.d.ts +25 -22
  76. package/types/store/baseSt.d.ts +42 -13
  77. package/types/store/state.d.ts +23 -26
  78. package/types/store/stateBuilder.d.ts +2 -2
  79. package/types/store/store.d.ts +17 -5
  80. package/types/store/types.d.ts +9 -3
  81. package/ui/Signal/makeExample.ts +3 -3
@@ -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
 
7
7
  interface Trans {
@@ -16,46 +16,44 @@ interface FnTrans<ArgKey extends string> {
16
16
  desc?: string;
17
17
  arg?: { [key in ArgKey]: FieldTrans };
18
18
  }
19
- type FilterTranslatorKey<Filter extends FilterInstance> = {
20
- [Key in keyof Filter["query"] & string]:
19
+ type AnyFilterShape = FilterInstance<Record<string, FilterInfo>, Record<string, unknown>>;
20
+ type DictFilterShape<Filter> = Filter extends FilterInstance
21
+ ? Filter
22
+ : Filter extends FilterCls<infer FilterShape>
23
+ ? FilterShape
24
+ : Filter extends { query: Record<string, FilterInfo>; sort: Record<string, unknown> }
25
+ ? Filter
26
+ : AnyFilterShape;
27
+ type DictFilterQuery<Filter> = DictFilterShape<Filter>["query"];
28
+ type DictFilterSort<Filter> = DictFilterShape<Filter>["sort"];
29
+ type FilterTranslatorKey<Filter> = {
30
+ [Key in keyof DictFilterQuery<Filter> & string]:
21
31
  | `${Key}`
22
32
  | `${Key}.desc`
23
- | (Filter["query"][Key] extends FilterInfo<infer ArgNames, any>
33
+ | (DictFilterQuery<Filter>[Key] extends FilterInfo<infer ArgNames, any>
24
34
  ? ArgNames[number] extends string
25
35
  ? `${Key}.arg.${ArgNames[number]}` | `${Key}.arg.${ArgNames[number]}.desc`
26
36
  : never
27
37
  : never);
28
- }[keyof Filter["query"] & string];
38
+ }[keyof DictFilterQuery<Filter> & string];
29
39
  type EndpointTranslatorKey<Endpoint extends { [key: string]: EndpointInfo }> = {
30
40
  [Key in keyof Endpoint & string]:
31
41
  | `${Key}`
32
42
  | `${Key}.desc`
33
- | `${Key}.arg.${Endpoint[Key]["argNames"][number]}`
34
- | `${Key}.arg.${Endpoint[Key]["argNames"][number]}.desc`;
43
+ | `${Key}.arg.${EndpInfoArgNames<Endpoint[Key]>[number]}`
44
+ | `${Key}.arg.${EndpInfoArgNames<Endpoint[Key]>[number]}.desc`;
35
45
  }[keyof Endpoint & string];
36
46
  type SliceTranslatorKey<Slice> = {
37
- [Key in keyof Slice & string]: Slice[Key] extends SliceInfo<
38
- infer T,
39
- any,
40
- any,
41
- any,
42
- any,
43
- any,
44
- any,
45
- infer ArgNames,
46
- any,
47
- any,
48
- any
49
- >
47
+ [Key in keyof Slice & string]: Slice[Key] extends infer Info extends SliceInfo
50
48
  ?
51
- | `${T}List${Capitalize<Key>}`
52
- | `${T}List${Capitalize<Key>}.desc`
53
- | `${T}List${Capitalize<Key>}.arg.${ArgNames[number] | "skip" | "limit" | "sort"}`
54
- | `${T}List${Capitalize<Key>}.arg.${ArgNames[number] | "skip" | "limit" | "sort"}.desc`
55
- | `${T}Insight${Capitalize<Key>}`
56
- | `${T}Insight${Capitalize<Key>}.desc`
57
- | `${T}Insight${Capitalize<Key>}.arg.${ArgNames[number]}`
58
- | `${T}Insight${Capitalize<Key>}.arg.${ArgNames[number]}.desc`
49
+ | `${SliceInfoRefName<Info>}List${Capitalize<Key>}`
50
+ | `${SliceInfoRefName<Info>}List${Capitalize<Key>}.desc`
51
+ | `${SliceInfoRefName<Info>}List${Capitalize<Key>}.arg.${SliceInfoArgNames<Info>[number] | "skip" | "limit" | "sort"}`
52
+ | `${SliceInfoRefName<Info>}List${Capitalize<Key>}.arg.${SliceInfoArgNames<Info>[number] | "skip" | "limit" | "sort"}.desc`
53
+ | `${SliceInfoRefName<Info>}Insight${Capitalize<Key>}`
54
+ | `${SliceInfoRefName<Info>}Insight${Capitalize<Key>}.desc`
55
+ | `${SliceInfoRefName<Info>}Insight${Capitalize<Key>}.arg.${SliceInfoArgNames<Info>[number]}`
56
+ | `${SliceInfoRefName<Info>}Insight${Capitalize<Key>}.arg.${SliceInfoArgNames<Info>[number]}.desc`
59
57
  : never;
60
58
  }[keyof Slice & string];
61
59
 
@@ -85,7 +83,7 @@ export type ModelTrans<
85
83
  T extends string,
86
84
  Model extends BaseObject,
87
85
  Insight extends BaseInsight,
88
- Filter extends FilterInstance,
86
+ Filter,
89
87
  Slice extends { [key: string]: SliceInfo },
90
88
  Endpoint extends { [key: string]: EndpointInfo },
91
89
  ErrorKey extends string,
@@ -96,16 +94,16 @@ export type ModelTrans<
96
94
  model: { [K in keyof GetStateObject<Model>]: FieldTrans };
97
95
  insight: { [K in keyof GetStateObject<Insight>]: FieldTrans };
98
96
  query: {
99
- [K in keyof Filter["query"]]: Filter["query"][K] extends FilterInfo<infer ArgNames, any>
97
+ [K in keyof DictFilterQuery<Filter>]: DictFilterQuery<Filter>[K] extends FilterInfo<infer ArgNames, any>
100
98
  ? FnTrans<ArgNames[number]>
101
99
  : never;
102
100
  };
103
- sort: { [K in keyof Filter["sort"]]: FieldTrans };
101
+ sort: { [K in keyof DictFilterSort<Filter>]: FieldTrans };
104
102
  api: {
105
- [K in keyof Endpoint]: FnTrans<Endpoint[K]["argNames"][number]>;
103
+ [K in keyof Endpoint]: FnTrans<EndpInfoArgNames<Endpoint[K]>[number]>;
106
104
  } & BaseModelCrudGetApiTrans<T> &
107
105
  MergedValues<{
108
- [K in keyof Slice]: SliceApiTrans<Slice[K]["refName"], K & string, Slice[K]["argNames"][number]>;
106
+ [K in keyof Slice]: SliceApiTrans<SliceInfoRefName<Slice[K]>, K & string, SliceInfoArgNames<Slice[K]>[number]>;
109
107
  }>;
110
108
  error: { [K in ErrorKey]: Trans };
111
109
  } & { [K in EtcKey]: Trans };
@@ -113,7 +111,7 @@ export type ModelTranslatorKey<
113
111
  T extends string,
114
112
  Model,
115
113
  Insight,
116
- Filter extends FilterInstance,
114
+ Filter,
117
115
  Slice extends { [key: string]: SliceInfo },
118
116
  Endpoint extends { [key: string]: EndpointInfo },
119
117
  EtcKey extends string,
@@ -123,7 +121,7 @@ export type ModelTranslatorKey<
123
121
  | `${T}.${keyof GetStateObject<Model> & string}${"" | ".desc"}`
124
122
  | `${T}.insight.${keyof GetStateObject<Insight> & string}${"" | ".desc"}`
125
123
  | `${T}.query.${FilterTranslatorKey<Filter>}`
126
- | `${T}.sort.${keyof Filter["sort"] & string}${"" | ".desc"}`
124
+ | `${T}.sort.${keyof DictFilterSort<Filter> & string}${"" | ".desc"}`
127
125
  | `${T}.signal.${EndpointTranslatorKey<Endpoint> | SliceTranslatorKey<Slice>}`
128
126
  | `${T}.${EtcKey}`;
129
127
 
@@ -146,7 +144,7 @@ export type ServiceTrans<
146
144
  EtcKey extends string,
147
145
  > = {
148
146
  api: {
149
- [K in keyof Endpoint]: FnTrans<Endpoint[K]["argNames"][number]>;
147
+ [K in keyof Endpoint]: FnTrans<EndpInfoArgNames<Endpoint[K]>[number]>;
150
148
  };
151
149
  error: { [K in ErrorKey]: Trans };
152
150
  } & { [K in EtcKey]: Trans };
@@ -171,7 +169,7 @@ export const registerModelTrans = <
171
169
  RefName extends string,
172
170
  Model extends BaseObject,
173
171
  Insight extends BaseInsight,
174
- Filter extends FilterInstance,
172
+ Filter,
175
173
  Slice extends { [key: string]: SliceInfo },
176
174
  Endpoint extends { [key: string]: EndpointInfo },
177
175
  ModelDict extends ModelDictInfo<any>,
package/document/by.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { type Cls, FIELD_META, type MergeAllActionTypes } from "akanjs/base";
1
+ import { type Cls, FIELD_META, type GetActionObject, SERVER_VALUE } from "akanjs/base";
2
2
  import { applyMixins } from "akanjs/common";
3
- import {
4
- type BaseObject,
5
- type ConstantCls,
6
- ConstantRegistry,
7
- type DocumentModel,
8
- type FieldObject,
9
- } from "akanjs/constant";
3
+ import { ConstantRegistry, type DocumentConstantModelRef, type DocumentModel, type FieldObject } from "akanjs/constant";
10
4
 
11
- export type DatabaseCls<Schema = any> = Cls<Schema, { refName: string; [FIELD_META]: FieldObject }>;
5
+ export type DatabaseCls<Schema = unknown> = Cls<Schema, { refName: string; [FIELD_META]: FieldObject }>;
6
+ export type DatabaseInstanceOf<DatabaseRef extends DatabaseCls> = DatabaseRef extends new (
7
+ ...args: never[]
8
+ ) => infer Instance
9
+ ? Instance
10
+ : never;
11
+ type ConstantModelCls = DocumentConstantModelRef<unknown>;
12
12
 
13
13
  export interface DefaultDocMtds<TDocument> {
14
14
  refresh(): Promise<this>;
@@ -18,23 +18,86 @@ export interface DefaultDocMtds<TDocument> {
18
18
  toJSON(): DocumentModel<TDocument>;
19
19
  toObject(): DocumentModel<TDocument>;
20
20
  }
21
- type HydratedDocumentWithId<TDocument> = TDocument & { id: string } & DefaultDocMtds<TDocument>;
22
- export type Doc<M = any> = HydratedDocumentWithId<DocumentModel<M>>;
21
+ type HydratedDocumentMethods<TDocument, Self> = Omit<
22
+ DefaultDocMtds<TDocument>,
23
+ "isModified" | "refresh" | "save" | "set"
24
+ > & {
25
+ refresh(): Promise<Self>;
26
+ isModified(field?: keyof TDocument & string): boolean;
27
+ set(data: Partial<TDocument>): Self;
28
+ save(): Promise<Self>;
29
+ };
30
+ type HydratedDocumentWithId<TDocument> = TDocument & { id: string } & HydratedDocumentMethods<TDocument, TDocument>;
31
+ interface ChainableHydratedMethods<TDocument>
32
+ extends Omit<DefaultDocMtds<TDocument>, "isModified" | "refresh" | "save" | "set"> {
33
+ refresh(): Promise<this>;
34
+ isModified(field?: keyof TDocument & string): boolean;
35
+ set(data: Partial<TDocument>): this;
36
+ save(): Promise<this>;
37
+ }
38
+ type ChainableHydratedDocument<TDocument> = TDocument & {
39
+ id: string;
40
+ } & ChainableHydratedMethods<TDocument>;
41
+ export type Doc<M = unknown> = HydratedDocumentWithId<DocumentModel<M>>;
42
+ type DatabaseSchemaOf<ModelCls> = ModelCls extends { _DatabaseSchema: infer Schema } ? Schema : never;
43
+ type ConstantValueOf<ModelCls> = ModelCls extends { [SERVER_VALUE]: infer Schema }
44
+ ? Schema
45
+ : ModelCls extends new (
46
+ ...args: never[]
47
+ ) => infer Schema
48
+ ? Schema
49
+ : never;
50
+ type ObjectDocumentModelType = "object" | "full" | "light";
51
+ type ModelTypeOf<ModelCls> = ModelCls extends { _ModelType: infer ModelType } ? ModelType : never;
52
+ type IsObjectModel<ModelCls> = ModelTypeOf<ModelCls> extends ObjectDocumentModelType ? true : false;
53
+ type DocModelOf<ModelCls, Schema = DatabaseSchemaOf<ModelCls>> =
54
+ IsObjectModel<ModelCls> extends true ? ChainableHydratedDocument<DocumentModel<Schema>> : DocumentModel<Schema>;
55
+ type DocActionOmitKey<ModelCls, Schema = DatabaseSchemaOf<ModelCls>> =
56
+ | (keyof Schema & string)
57
+ | (IsObjectModel<ModelCls> extends true ? keyof DefaultDocMtds<unknown> | "id" : never);
58
+ type DatabaseSchemaFor<ModelCls extends ConstantModelCls> = DatabaseSchemaOf<ModelCls> & ConstantValueOf<ModelCls>;
59
+ type DocModelFor<ModelCls extends ConstantModelCls> = DocModelOf<ModelCls, DatabaseSchemaFor<ModelCls>>;
60
+ type DocActionOmitKeyFor<ModelCls extends ConstantModelCls> = DocActionOmitKey<ModelCls, DatabaseSchemaFor<ModelCls>>;
61
+ type StrictDocumentActions<T> = string extends keyof T
62
+ ? T[string] extends never
63
+ ? Record<never, never>
64
+ : GetActionObject<T>
65
+ : GetActionObject<T>;
66
+ type DocumentActionsOf<AddDbModel extends DatabaseCls, OmitKey extends string> = Omit<
67
+ StrictDocumentActions<DatabaseInstanceOf<AddDbModel>>,
68
+ OmitKey
69
+ >;
70
+ type MergeDocumentActions<
71
+ AddDbModels extends readonly DatabaseCls[],
72
+ OmitKey extends string,
73
+ Acc = Record<never, never>,
74
+ > = AddDbModels extends readonly [infer First extends DatabaseCls, ...infer Rest extends readonly DatabaseCls[]]
75
+ ? MergeDocumentActions<Rest, OmitKey, Acc & DocumentActionsOf<First, OmitKey>>
76
+ : AddDbModels extends readonly (infer AddDbModel extends DatabaseCls)[]
77
+ ? Acc & DocumentActionsOf<AddDbModel, OmitKey>
78
+ : Acc;
79
+ type ByInstance<
80
+ ModelCls extends ConstantModelCls,
81
+ AddDbModels extends readonly DatabaseCls[],
82
+ _OmitKey extends string = DocActionOmitKeyFor<ModelCls> & string,
83
+ _DocModel = DocModelFor<ModelCls>,
84
+ > = MergeDocumentActions<AddDbModels, _OmitKey> & _DocModel;
23
85
 
24
- export const by = <
25
- ModelCls,
26
- AddDbModels extends DatabaseCls[],
27
- _DatabaseSchema = ModelCls extends { _DatabaseSchema: infer Schema } ? Schema : never,
28
- _DocModel = _DatabaseSchema extends BaseObject ? Doc<_DatabaseSchema> : DocumentModel<_DatabaseSchema>,
29
- >(
86
+ export function by<ModelCls extends ConstantModelCls>(modelRef: ModelCls): DatabaseCls<DocModelFor<ModelCls>>;
87
+ export function by<ModelCls extends ConstantModelCls, AddDbModel extends DatabaseCls>(
88
+ modelRef: ModelCls,
89
+ addRef: AddDbModel,
90
+ ): DatabaseCls<DocumentActionsOf<AddDbModel, DocActionOmitKeyFor<ModelCls> & string> & DocModelFor<ModelCls>>;
91
+ export function by<ModelCls extends ConstantModelCls, const AddDbModels extends DatabaseCls[]>(
30
92
  modelRef: ModelCls,
31
93
  ...addRefs: AddDbModels
32
- ): DatabaseCls<MergeAllActionTypes<AddDbModels, keyof _DocModel & string> & _DocModel> => {
94
+ ): DatabaseCls<ByInstance<ModelCls, AddDbModels>>;
95
+ export function by(modelRef: ConstantModelCls, ...addRefs: DatabaseCls[]): DatabaseCls {
33
96
  const refName = ConstantRegistry.getRefName(modelRef as Cls);
34
97
  const databaseCls = class DatabaseCls {
35
98
  static refName = refName;
36
- static [FIELD_META] = (modelRef as ConstantCls)[FIELD_META];
99
+ static [FIELD_META] = modelRef[FIELD_META];
37
100
  };
38
101
  applyMixins(databaseCls as Cls, addRefs);
39
- return databaseCls as any;
40
- };
102
+ return databaseCls as unknown as DatabaseCls;
103
+ }
@@ -58,17 +58,7 @@ type QueryMethodOfKey<
58
58
  } & {
59
59
  [K in `query${CapitalizedK}`]: (...args: _Args) => _QueryOfDoc;
60
60
  };
61
-
62
- export type QueryMethodPart<
63
- Query,
64
- Sort,
65
- Obj,
66
- Doc,
67
- Insight,
68
- _FindQueryOption = FindQueryOption<Sort, Obj>,
69
- _ListQueryOption = ListQueryOption<Sort, Obj>,
70
- _QueryOfDoc = QueryOf<Doc>,
71
- > = MergedValues<{
61
+ type QueryMethodMap<Query, Doc, Insight, _FindQueryOption, _ListQueryOption, _QueryOfDoc> = {
72
62
  [K in keyof Query]: K extends string
73
63
  ? Query[K] extends (...args: infer Args) => any
74
64
  ? QueryMethodOfKey<
@@ -77,11 +67,23 @@ export type QueryMethodPart<
77
67
  Insight,
78
68
  Args,
79
69
  [...Args, queryOption?: _ListQueryOption],
80
- [...Args, queryOption?: _FindQueryOption]
70
+ [...Args, queryOption?: _FindQueryOption],
71
+ _QueryOfDoc
81
72
  >
82
73
  : never
83
74
  : never;
84
- }>;
75
+ };
76
+
77
+ export type QueryMethodPart<
78
+ Query,
79
+ Sort,
80
+ Obj,
81
+ Doc,
82
+ Insight,
83
+ _FindQueryOption = FindQueryOption<Sort, Obj>,
84
+ _ListQueryOption = ListQueryOption<Sort, Obj>,
85
+ _QueryOfDoc = QueryOf<Doc>,
86
+ > = MergedValues<QueryMethodMap<Query, Doc, Insight, _FindQueryOption, _ListQueryOption, _QueryOfDoc>>;
85
87
  type DatabaseModelWithQuerySort<
86
88
  T extends string,
87
89
  Input,
@@ -92,12 +94,13 @@ type DatabaseModelWithQuerySort<
92
94
  Sort,
93
95
  _CapitalizedRefName extends string = Capitalize<T>,
94
96
  _QueryOfDoc = QueryOf<Doc>,
95
- _DataInput = DataInputOf<Input, DocumentModel<Obj>>,
97
+ _DocumentObj = DocumentModel<Obj>,
98
+ _DataInput = DataInputOf<Input, _DocumentObj>,
96
99
  _FindQueryOption = FindQueryOption<Sort, Obj>,
97
100
  _ListQueryOption = ListQueryOption<Sort, Obj>,
98
101
  > = {
99
102
  logger: Logger;
100
- __model: Mdl<Doc, Obj>;
103
+ __model: Mdl<Doc, Obj, _DocumentObj>;
101
104
  __cache: CacheDatabase<T>;
102
105
  __loader: DataLoader<string, Doc, string>;
103
106
  __get: (id: string) => Promise<Doc>;
@@ -119,7 +122,7 @@ type DatabaseModelWithQuerySort<
119
122
  listenPre: (type: SaveEventType, listener: (doc: Doc, type: CRUDEventType) => PromiseOrObject<void>) => () => void;
120
123
  listenPost: (type: SaveEventType, listener: (doc: Doc, type: CRUDEventType) => PromiseOrObject<void>) => () => void;
121
124
  } & {
122
- [key in _CapitalizedRefName]: Mdl<Doc, Obj>;
125
+ [key in _CapitalizedRefName]: Mdl<Doc, Obj, _DocumentObj>;
123
126
  } & {
124
127
  [key in `${T}Loader`]: DataLoader<string, Doc, string>;
125
128
  } & {
@@ -138,6 +141,36 @@ type DatabaseModelWithQuerySort<
138
141
  [K in `remove${_CapitalizedRefName}`]: (id: string) => Promise<Doc>;
139
142
  } & QueryMethodPart<Query, Sort, Obj, Doc, Insight, _FindQueryOption, _ListQueryOption, _QueryOfDoc>;
140
143
 
144
+ export type DatabaseInstanceWithQuerySort<
145
+ T extends string = string,
146
+ Input = any,
147
+ Doc = any,
148
+ Obj = any,
149
+ Insight = any,
150
+ Query = ExtractQuery<FilterInstance>,
151
+ Sort = ExtractSort<FilterInstance>,
152
+ _CapitalizedRefName extends string = Capitalize<T>,
153
+ _QueryOfDoc = QueryOf<Doc>,
154
+ _DocumentObj = DocumentModel<Obj>,
155
+ _DataInput = DataInputOf<Input, _DocumentObj>,
156
+ _FindQueryOption = FindQueryOption<Sort, Obj>,
157
+ _ListQueryOption = ListQueryOption<Sort, Obj>,
158
+ > = DatabaseModelWithQuerySort<
159
+ T,
160
+ Input,
161
+ Doc,
162
+ Obj,
163
+ Insight,
164
+ Query,
165
+ Sort,
166
+ _CapitalizedRefName,
167
+ _QueryOfDoc,
168
+ _DocumentObj,
169
+ _DataInput,
170
+ _FindQueryOption,
171
+ _ListQueryOption
172
+ >;
173
+
141
174
  export type DatabaseInstance<
142
175
  T extends string = string,
143
176
  Input = any,
@@ -149,10 +182,11 @@ export type DatabaseInstance<
149
182
  _QueryOfDoc = QueryOf<Doc>,
150
183
  _Query = ExtractQuery<Filter>,
151
184
  _Sort = ExtractSort<Filter>,
152
- _DataInput = DataInputOf<Input, DocumentModel<Obj>>,
185
+ _DocumentObj = DocumentModel<Obj>,
186
+ _DataInput = DataInputOf<Input, _DocumentObj>,
153
187
  _FindQueryOption = FindQueryOption<_Sort, Obj>,
154
188
  _ListQueryOption = ListQueryOption<_Sort, Obj>,
155
- > = DatabaseModelWithQuerySort<
189
+ > = DatabaseInstanceWithQuerySort<
156
190
  T,
157
191
  Input,
158
192
  Doc,
@@ -162,6 +196,7 @@ export type DatabaseInstance<
162
196
  _Sort,
163
197
  _CapitalizedRefName,
164
198
  _QueryOfDoc,
199
+ _DocumentObj,
165
200
  _DataInput,
166
201
  _FindQueryOption,
167
202
  _ListQueryOption
@@ -1,5 +1,5 @@
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";
4
4
 
5
5
  export interface DatabaseModel<
@@ -10,6 +10,7 @@ export interface DatabaseModel<
10
10
  Obj = any,
11
11
  Insight = any,
12
12
  Filter extends FilterInstance = any,
13
+ _Query extends ExtractQuery<Filter> = ExtractQuery<Filter>,
13
14
  _Sort extends ExtractSort<Filter> = ExtractSort<Filter>,
14
15
  > {
15
16
  refName: T;
@@ -25,6 +26,7 @@ export interface DatabaseModel<
25
26
  _Obj: Obj;
26
27
  _Insight: Insight;
27
28
  _Filter: Filter;
29
+ _Query: _Query;
28
30
  _Sort: _Sort;
29
31
  }
30
32
  export class DatabaseRegistry {
@@ -82,6 +84,7 @@ export class DatabaseRegistry {
82
84
  Obj,
83
85
  Insight,
84
86
  Filter extends FilterInstance,
87
+ _Query extends ExtractQuery<Filter> = ExtractQuery<Filter>,
85
88
  _Sort extends ExtractSort<Filter> = ExtractSort<Filter>,
86
89
  >(
87
90
  refName: T,
@@ -91,7 +94,7 @@ export class DatabaseRegistry {
91
94
  obj: ConstantCls<Obj>,
92
95
  insight: ConstantCls<Insight>,
93
96
  filter: FilterCls<Filter>,
94
- ): DatabaseModel<T, Input, Doc, Model, Obj, Insight, Filter, _Sort> {
97
+ ): DatabaseModel<T, Input, Doc, Model, Obj, Insight, Filter, _Query, _Sort> {
95
98
  const dbInfo = {
96
99
  refName,
97
100
  input,
@@ -100,8 +103,9 @@ export class DatabaseRegistry {
100
103
  obj,
101
104
  insight,
102
105
  filter,
106
+ _Query: null as unknown as _Query,
103
107
  _Sort: null as unknown as _Sort,
104
- } as DatabaseModel<T, Input, Doc, Model, Obj, Insight, Filter, _Sort>;
108
+ } as DatabaseModel<T, Input, Doc, Model, Obj, Insight, Filter, _Query, _Sort>;
105
109
  DatabaseRegistry.setDatabase(refName, dbInfo);
106
110
  return dbInfo;
107
111
  }
@@ -116,6 +116,22 @@ interface BaseSort {
116
116
  latest: { createdAt: -1 };
117
117
  oldest: { createdAt: 1 };
118
118
  }
119
+ type LibFilterQuery<LibFilters extends FilterCls[]> = MergeAllDoubleKeyOfObjects<
120
+ LibFilters,
121
+ typeof FILTER_META,
122
+ "query"
123
+ >;
124
+ type LibFilterSort<LibFilters extends FilterCls[]> = MergeAllKeyOfTypes<LibFilters, "sort">;
125
+ type FilterQuery<Full, LibFilters extends FilterCls[], Filter extends FilterInstance> = BaseQuery<Full> &
126
+ LibFilterQuery<LibFilters> &
127
+ Filter["query"];
128
+ type FilterSort<LibFilters extends FilterCls[], Filter extends FilterInstance> = BaseSort &
129
+ LibFilterSort<LibFilters> &
130
+ Filter["sort"];
131
+ type MergedFilterInstance<Full, LibFilters extends FilterCls[], Filter extends FilterInstance> = {
132
+ query: FilterQuery<Full, LibFilters, Filter>;
133
+ sort: FilterSort<LibFilters, Filter>;
134
+ };
119
135
 
120
136
  export type ExtractQuery<Filter extends FilterInstance> = {
121
137
  [K in keyof Filter["query"]]: Filter["query"][K] extends FilterInfo<any, infer Args>
@@ -123,16 +139,24 @@ export type ExtractQuery<Filter extends FilterInstance> = {
123
139
  : never;
124
140
  };
125
141
  export type ExtractSort<Filter extends FilterInstance> = keyof Filter["sort"];
126
- export interface FilterCls<Filter extends FilterInstance = any> extends Cls<{ [key: string]: any }> {
142
+ export interface FilterCls<Filter extends FilterInstance = any, Query = unknown, Sort = unknown>
143
+ extends Cls<{ [key: string]: any }> {
127
144
  [FILTER_META]: Filter;
128
145
  sortField: Set<string>;
146
+ _Query: Query;
147
+ _Sort: Sort;
129
148
  }
149
+ export type FilterQueryOf<FilterRef extends FilterCls> = FilterRef extends { _Query: infer Query } ? Query : never;
150
+ export type FilterSortOf<FilterRef extends FilterCls> = FilterRef extends { _Sort: infer Sort } ? Sort : never;
130
151
 
131
152
  export const from = <
132
153
  Full extends BaseObject,
133
154
  BuildFilter extends (filter: () => FilterInfo<[], [], Full>) => FilterInstance,
134
155
  LibFilters extends FilterCls[],
135
156
  _Filter extends ReturnType<BuildFilter>,
157
+ _MergedFilter extends FilterInstance = MergedFilterInstance<Full, LibFilters, _Filter>,
158
+ _Query = ExtractQuery<_MergedFilter>,
159
+ _Sort = ExtractSort<_MergedFilter>,
136
160
  >(
137
161
  modelRef: Cls<Full>,
138
162
  buildFilter: BuildFilter,
@@ -153,19 +177,7 @@ export const from = <
153
177
  },
154
178
  ...libFilterRefs.map((libFilterRef) => getFilterMeta(libFilterRef)),
155
179
  );
156
- return Base as unknown as Cls<
157
- {
158
- query: BaseQuery<Full> & MergeAllDoubleKeyOfObjects<LibFilters, typeof FILTER_META, "query"> & _Filter["query"];
159
- sort: BaseSort & MergeAllKeyOfTypes<LibFilters, "sort"> & _Filter["sort"];
160
- },
161
- {
162
- [FILTER_META]: {
163
- query: BaseQuery<Full> & MergeAllDoubleKeyOfObjects<LibFilters, typeof FILTER_META, "query"> & _Filter["query"];
164
- sort: BaseSort & MergeAllKeyOfTypes<LibFilters, "sort"> & _Filter["sort"];
165
- };
166
- sortField: Set<string>;
167
- }
168
- >;
180
+ return Base as unknown as FilterCls<_MergedFilter, _Query, _Sort>;
169
181
  };
170
182
 
171
183
  interface ArgProps<Value = unknown> {