@akanjs/constant 0.9.42 → 0.9.43

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.
@@ -79,7 +79,13 @@ const lightModelOf = (objectRef, fields) => {
79
79
  class BaseGql {
80
80
  __ModelType__ = "light";
81
81
  }
82
- ["id", ...fields, "createdAt", "updatedAt", "removedAt"].forEach((key) => map.set(key, metadataMap.get(key)));
82
+ map.set("id", metadataMap.get("id"));
83
+ for (const field of fields) {
84
+ map.set(field, metadataMap.get(field));
85
+ }
86
+ map.set("createdAt", metadataMap.get("createdAt"));
87
+ map.set("updatedAt", metadataMap.get("updatedAt"));
88
+ map.set("removedAt", metadataMap.get("removedAt"));
83
89
  Reflect.defineMetadata("fields", map, BaseGql.prototype);
84
90
  return BaseGql;
85
91
  };
@@ -98,31 +104,28 @@ const fullModelOf = (modelRef, lightRef, overwriteRef, overwriteLightRef) => {
98
104
  (0, import_scalar.setFieldMetaMap)(modelRef, new Map([...modelFieldMetaMap, ...lightFieldMetaMap]));
99
105
  return modelRef;
100
106
  };
101
- const via = (modelRef, fieldsOrLightModelRef, overwriteRef, overwriteLightRef) => {
107
+ function via(modelRef, fieldsOrLightModelRef, overwriteRef, overwriteLightRef) {
102
108
  if (!fieldsOrLightModelRef)
103
109
  return baseModelOf(modelRef);
104
- else if (Array.isArray(fieldsOrLightModelRef))
110
+ if (Array.isArray(fieldsOrLightModelRef))
105
111
  return lightModelOf(modelRef, fieldsOrLightModelRef);
106
- else
107
- return fullModelOf(modelRef, fieldsOrLightModelRef, overwriteRef, overwriteLightRef);
108
- };
109
- const addModelOf = (modelRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => {
112
+ return fullModelOf(modelRef, fieldsOrLightModelRef, overwriteRef, overwriteLightRef);
113
+ }
114
+ const addModelOf = (modelRef, ...types) => {
110
115
  const modelMetadataMap = (0, import_scalar.getFieldMetaMap)(modelRef);
111
- const metadataMap = new Map(
112
- [t1, t2, t3, t4, t5, t6, t7, t8, t9, t10].filter((t) => !!t).reduce((acc, writeRef) => {
113
- const writeMetadataMap = (0, import_scalar.getFieldMetaMap)(writeRef);
114
- (0, import_common.applyMixins)(modelRef, [writeRef]);
115
- return new Map([...acc, ...writeMetadataMap]);
116
- }, modelMetadataMap)
117
- );
116
+ const metadataMap = types.filter(Boolean).reduce((acc, writeRef) => {
117
+ const writeMetadataMap = (0, import_scalar.getFieldMetaMap)(writeRef);
118
+ (0, import_common.applyMixins)(modelRef, [writeRef]);
119
+ return new Map([...acc, ...writeMetadataMap]);
120
+ }, modelMetadataMap);
118
121
  (0, import_scalar.setFieldMetaMap)(modelRef, metadataMap);
119
122
  return modelRef;
120
123
  };
121
- const addFilterOf = (filterRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => {
124
+ const addFilterOf = (filterRef, ...types) => {
122
125
  const filterMeta = (0, import_filterMeta.getFilterMeta)(filterRef);
123
126
  const filterQueryMap = (0, import_filterMeta.getFilterQueryMap)(filterRef);
124
127
  const metadataMap = new Map(
125
- [t1, t2, t3, t4, t5, t6, t7, t8, t9, t10].filter((t) => !!t).reduce((acc, writeRef) => {
128
+ types.filter(Boolean).reduce((acc, writeRef) => {
126
129
  const writeMetadataMap = (0, import_filterMeta.getFilterQueryMap)(writeRef);
127
130
  (0, import_common.applyMixins)(filterRef, [writeRef]);
128
131
  writeMetadataMap.forEach((value, key) => {
@@ -132,7 +135,7 @@ const addFilterOf = (filterRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => {
132
135
  return new Map([...acc, ...writeMetadataMap]);
133
136
  }, filterQueryMap)
134
137
  );
135
- const filterSort = [t1, t2, t3, t4, t5, t6, t7, t8, t9, t10].filter((t) => !!t).map((t) => (0, import_filterMeta.getFilterSortMap)(t)).reduce((acc, sort) => {
138
+ const filterSort = types.filter(Boolean).map((t) => (0, import_filterMeta.getFilterSortMap)(t)).reduce((acc, sort) => {
136
139
  Object.assign(acc, sort);
137
140
  return acc;
138
141
  }, filterMeta.sort);
@@ -140,19 +143,19 @@ const addFilterOf = (filterRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => {
140
143
  (0, import_filterMeta.setFilterMeta)(filterRef, { ...filterMeta, sort: filterSort });
141
144
  return filterRef;
142
145
  };
143
- const from = (modelRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => {
146
+ const from = (modelRef, ...types) => {
144
147
  if ((0, import_scalar.isConstantModel)(modelRef))
145
- return addModelOf(modelRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10);
148
+ return addModelOf(modelRef, ...types);
146
149
  else if ((0, import_filterMeta.isFilterModel)(modelRef))
147
- return addFilterOf(modelRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10);
150
+ return addFilterOf(modelRef, ...types);
148
151
  else
149
152
  throw new Error("Invalid modelRef");
150
153
  };
151
- const mixModelOf = (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20) => {
154
+ const mixModelOf = (...types) => {
152
155
  class Mix {
153
156
  }
154
157
  const metadataMap = new Map(
155
- [t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20].filter((t) => !!t).reduce((acc, modelRef) => {
158
+ types.reduce((acc, modelRef) => {
156
159
  const modelMetadataMap = (0, import_scalar.getFieldMetaMap)(modelRef);
157
160
  (0, import_common.applyMixins)(Mix, [modelRef]);
158
161
  return [...acc, ...modelMetadataMap];
@@ -18,7 +18,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
18
18
  var constantDecorator_exports = {};
19
19
  __export(constantDecorator_exports, {
20
20
  cnstOf: () => cnstOf,
21
- getCnstMeta: () => getCnstMeta
21
+ getCnstMeta: () => getCnstMeta,
22
+ scalarCnstOf: () => scalarCnstOf
22
23
  });
23
24
  module.exports = __toCommonJS(constantDecorator_exports);
24
25
  var import_reflect_metadata = require("reflect-metadata");
@@ -34,7 +35,34 @@ const getCnstMeta = (refName) => {
34
35
  return cnst;
35
36
  };
36
37
  const cnstOf = (refName, Input, Full, Light, Insight, Filter, Summary) => {
37
- const cnst = { refName, Input, Full, Light, Insight, Filter, Summary };
38
+ const cnst = {
39
+ refName,
40
+ Input,
41
+ Full,
42
+ Light,
43
+ Insight,
44
+ Filter,
45
+ Summary,
46
+ _CapitalizedT: null,
47
+ _Default: null,
48
+ _DefaultInput: null,
49
+ _DefaultState: null,
50
+ _DefaultStateInput: null,
51
+ _Doc: null,
52
+ _DocInput: null,
53
+ _QueryOfDoc: null,
54
+ _Query: null,
55
+ _Sort: null
56
+ };
38
57
  setCnstMeta(refName, cnst);
39
58
  return cnst;
40
59
  };
60
+ const scalarCnstOf = (refName, Model) => {
61
+ const cnst = {
62
+ refName,
63
+ Model,
64
+ _Default: null,
65
+ _Doc: null
66
+ };
67
+ return cnst;
68
+ };
package/cjs/src/types.js CHANGED
@@ -20,17 +20,11 @@ __export(types_exports, {
20
20
  DEFAULT_PAGE_SIZE: () => DEFAULT_PAGE_SIZE,
21
21
  MAX_INT: () => MAX_INT,
22
22
  Responsive: () => Responsive,
23
- defaultListOption: () => defaultListOption,
24
23
  responsiveWidths: () => responsiveWidths,
25
24
  unsetDate: () => unsetDate
26
25
  });
27
26
  module.exports = __toCommonJS(types_exports);
28
27
  var import_base = require("@akanjs/base");
29
- const defaultListOption = {
30
- limit: 20,
31
- skip: 0,
32
- sort: "latest"
33
- };
34
28
  const DEFAULT_PAGE_SIZE = 20;
35
29
  const unsetDate = (0, import_base.dayjs)(/* @__PURE__ */ new Date("0000"));
36
30
  const MAX_INT = 2147483647;
@@ -62,7 +62,13 @@ const lightModelOf = (objectRef, fields) => {
62
62
  class BaseGql {
63
63
  __ModelType__ = "light";
64
64
  }
65
- ["id", ...fields, "createdAt", "updatedAt", "removedAt"].forEach((key) => map.set(key, metadataMap.get(key)));
65
+ map.set("id", metadataMap.get("id"));
66
+ for (const field of fields) {
67
+ map.set(field, metadataMap.get(field));
68
+ }
69
+ map.set("createdAt", metadataMap.get("createdAt"));
70
+ map.set("updatedAt", metadataMap.get("updatedAt"));
71
+ map.set("removedAt", metadataMap.get("removedAt"));
66
72
  Reflect.defineMetadata("fields", map, BaseGql.prototype);
67
73
  return BaseGql;
68
74
  };
@@ -81,31 +87,28 @@ const fullModelOf = (modelRef, lightRef, overwriteRef, overwriteLightRef) => {
81
87
  setFieldMetaMap(modelRef, new Map([...modelFieldMetaMap, ...lightFieldMetaMap]));
82
88
  return modelRef;
83
89
  };
84
- const via = (modelRef, fieldsOrLightModelRef, overwriteRef, overwriteLightRef) => {
90
+ function via(modelRef, fieldsOrLightModelRef, overwriteRef, overwriteLightRef) {
85
91
  if (!fieldsOrLightModelRef)
86
92
  return baseModelOf(modelRef);
87
- else if (Array.isArray(fieldsOrLightModelRef))
93
+ if (Array.isArray(fieldsOrLightModelRef))
88
94
  return lightModelOf(modelRef, fieldsOrLightModelRef);
89
- else
90
- return fullModelOf(modelRef, fieldsOrLightModelRef, overwriteRef, overwriteLightRef);
91
- };
92
- const addModelOf = (modelRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => {
95
+ return fullModelOf(modelRef, fieldsOrLightModelRef, overwriteRef, overwriteLightRef);
96
+ }
97
+ const addModelOf = (modelRef, ...types) => {
93
98
  const modelMetadataMap = getFieldMetaMap(modelRef);
94
- const metadataMap = new Map(
95
- [t1, t2, t3, t4, t5, t6, t7, t8, t9, t10].filter((t) => !!t).reduce((acc, writeRef) => {
96
- const writeMetadataMap = getFieldMetaMap(writeRef);
97
- applyMixins(modelRef, [writeRef]);
98
- return new Map([...acc, ...writeMetadataMap]);
99
- }, modelMetadataMap)
100
- );
99
+ const metadataMap = types.filter(Boolean).reduce((acc, writeRef) => {
100
+ const writeMetadataMap = getFieldMetaMap(writeRef);
101
+ applyMixins(modelRef, [writeRef]);
102
+ return new Map([...acc, ...writeMetadataMap]);
103
+ }, modelMetadataMap);
101
104
  setFieldMetaMap(modelRef, metadataMap);
102
105
  return modelRef;
103
106
  };
104
- const addFilterOf = (filterRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => {
107
+ const addFilterOf = (filterRef, ...types) => {
105
108
  const filterMeta = getFilterMeta(filterRef);
106
109
  const filterQueryMap = getFilterQueryMap(filterRef);
107
110
  const metadataMap = new Map(
108
- [t1, t2, t3, t4, t5, t6, t7, t8, t9, t10].filter((t) => !!t).reduce((acc, writeRef) => {
111
+ types.filter(Boolean).reduce((acc, writeRef) => {
109
112
  const writeMetadataMap = getFilterQueryMap(writeRef);
110
113
  applyMixins(filterRef, [writeRef]);
111
114
  writeMetadataMap.forEach((value, key) => {
@@ -115,7 +118,7 @@ const addFilterOf = (filterRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => {
115
118
  return new Map([...acc, ...writeMetadataMap]);
116
119
  }, filterQueryMap)
117
120
  );
118
- const filterSort = [t1, t2, t3, t4, t5, t6, t7, t8, t9, t10].filter((t) => !!t).map((t) => getFilterSortMap(t)).reduce((acc, sort) => {
121
+ const filterSort = types.filter(Boolean).map((t) => getFilterSortMap(t)).reduce((acc, sort) => {
119
122
  Object.assign(acc, sort);
120
123
  return acc;
121
124
  }, filterMeta.sort);
@@ -123,19 +126,19 @@ const addFilterOf = (filterRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => {
123
126
  setFilterMeta(filterRef, { ...filterMeta, sort: filterSort });
124
127
  return filterRef;
125
128
  };
126
- const from = (modelRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => {
129
+ const from = (modelRef, ...types) => {
127
130
  if (isConstantModel(modelRef))
128
- return addModelOf(modelRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10);
131
+ return addModelOf(modelRef, ...types);
129
132
  else if (isFilterModel(modelRef))
130
- return addFilterOf(modelRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10);
133
+ return addFilterOf(modelRef, ...types);
131
134
  else
132
135
  throw new Error("Invalid modelRef");
133
136
  };
134
- const mixModelOf = (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20) => {
137
+ const mixModelOf = (...types) => {
135
138
  class Mix {
136
139
  }
137
140
  const metadataMap = new Map(
138
- [t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20].filter((t) => !!t).reduce((acc, modelRef) => {
141
+ types.reduce((acc, modelRef) => {
139
142
  const modelMetadataMap = getFieldMetaMap(modelRef);
140
143
  applyMixins(Mix, [modelRef]);
141
144
  return [...acc, ...modelMetadataMap];
@@ -11,11 +11,39 @@ const getCnstMeta = (refName) => {
11
11
  return cnst;
12
12
  };
13
13
  const cnstOf = (refName, Input, Full, Light, Insight, Filter, Summary) => {
14
- const cnst = { refName, Input, Full, Light, Insight, Filter, Summary };
14
+ const cnst = {
15
+ refName,
16
+ Input,
17
+ Full,
18
+ Light,
19
+ Insight,
20
+ Filter,
21
+ Summary,
22
+ _CapitalizedT: null,
23
+ _Default: null,
24
+ _DefaultInput: null,
25
+ _DefaultState: null,
26
+ _DefaultStateInput: null,
27
+ _Doc: null,
28
+ _DocInput: null,
29
+ _QueryOfDoc: null,
30
+ _Query: null,
31
+ _Sort: null
32
+ };
15
33
  setCnstMeta(refName, cnst);
16
34
  return cnst;
17
35
  };
36
+ const scalarCnstOf = (refName, Model) => {
37
+ const cnst = {
38
+ refName,
39
+ Model,
40
+ _Default: null,
41
+ _Doc: null
42
+ };
43
+ return cnst;
44
+ };
18
45
  export {
19
46
  cnstOf,
20
- getCnstMeta
47
+ getCnstMeta,
48
+ scalarCnstOf
21
49
  };
package/esm/src/types.js CHANGED
@@ -1,9 +1,4 @@
1
1
  import { dayjs, enumOf } from "@akanjs/base";
2
- const defaultListOption = {
3
- limit: 20,
4
- skip: 0,
5
- sort: "latest"
6
- };
7
2
  const DEFAULT_PAGE_SIZE = 20;
8
3
  const unsetDate = dayjs(/* @__PURE__ */ new Date("0000"));
9
4
  const MAX_INT = 2147483647;
@@ -13,7 +8,6 @@ export {
13
8
  DEFAULT_PAGE_SIZE,
14
9
  MAX_INT,
15
10
  Responsive,
16
- defaultListOption,
17
11
  responsiveWidths,
18
12
  unsetDate
19
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/constant",
3
- "version": "0.9.42",
3
+ "version": "0.9.43",
4
4
  "sourceType": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/baseGql.d.ts CHANGED
@@ -2,7 +2,16 @@ import "reflect-metadata";
2
2
  import { BaseObject, type Prettify, Type } from "@akanjs/base";
3
3
  import type { NonFunctionalKeys } from "./types";
4
4
  export declare const as: <T>(modelRef: Type<T>) => Type<T>;
5
- export declare const via: <T, LightOrFields extends readonly NonFunctionalKeys<Omit<T, "id" | "createdAt" | "updatedAt" | "removedAt">>[] | Type | undefined = undefined>(modelRef: Type<T>, fieldsOrLightModelRef?: LightOrFields, overwriteRef?: Type, overwriteLightRef?: Type) => LightOrFields extends undefined ? Type<Prettify<T & BaseObject>> : LightOrFields extends Type<infer Light> ? Type<Prettify<T & Light & BaseObject>> : LightOrFields extends readonly NonFunctionalKeys<Omit<T, "id" | "createdAt" | "updatedAt" | "removedAt">>[] ? Type<Prettify<{ [K in LightOrFields[number]]: T[K]; } & BaseObject>> : never;
6
- export declare const from: <A, T1, T2 = unknown, T3 = unknown, T4 = unknown, T5 = unknown, T6 = unknown, T7 = unknown, T8 = unknown, T9 = unknown, T10 = unknown>(modelRef: Type<A>, t1: Type<T1>, t2?: Type<T2>, t3?: Type<T3>, t4?: Type<T4>, t5?: Type<T5>, t6?: Type<T6>, t7?: Type<T7>, t8?: Type<T8>, t9?: Type<T9>, t10?: Type<T10>) => Type<A & T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8 & T9 & T10>;
7
- export declare const mixModelOf: <T1 = unknown, T2 = unknown, T3 = unknown, T4 = unknown, T5 = unknown, T6 = unknown, T7 = unknown, T8 = unknown, T9 = unknown, T10 = unknown, T11 = unknown, T12 = unknown, T13 = unknown, T14 = unknown, T15 = unknown, T16 = unknown, T17 = unknown, T18 = unknown, T19 = unknown, T20 = unknown>(t1: Type<T1>, t2?: Type<T2>, t3?: Type<T3>, t4?: Type<T4>, t5?: Type<T5>, t6?: Type<T6>, t7?: Type<T7>, t8?: Type<T8>, t9?: Type<T9>, t10?: Type<T10>, t11?: Type<T11>, t12?: Type<T12>, t13?: Type<T13>, t14?: Type<T14>, t15?: Type<T15>, t16?: Type<T16>, t17?: Type<T17>, t18?: Type<T18>, t19?: Type<T19>, t20?: Type<T20>) => Type<T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8 & T9 & T10 & T11 & T12 & T13 & T14 & T15 & T16 & T17 & T18 & T19 & T20>;
8
- export declare const over: <T1 = unknown, T2 = unknown, T3 = unknown, T4 = unknown, T5 = unknown, T6 = unknown, T7 = unknown, T8 = unknown, T9 = unknown, T10 = unknown, T11 = unknown, T12 = unknown, T13 = unknown, T14 = unknown, T15 = unknown, T16 = unknown, T17 = unknown, T18 = unknown, T19 = unknown, T20 = unknown>(t1: Type<T1>, t2?: Type<T2>, t3?: Type<T3>, t4?: Type<T4>, t5?: Type<T5>, t6?: Type<T6>, t7?: Type<T7>, t8?: Type<T8>, t9?: Type<T9>, t10?: Type<T10>, t11?: Type<T11>, t12?: Type<T12>, t13?: Type<T13>, t14?: Type<T14>, t15?: Type<T15>, t16?: Type<T16>, t17?: Type<T17>, t18?: Type<T18>, t19?: Type<T19>, t20?: Type<T20>) => Type<T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8 & T9 & T10 & T11 & T12 & T13 & T14 & T15 & T16 & T17 & T18 & T19 & T20>;
5
+ type BaseFields = "id" | "createdAt" | "updatedAt" | "removedAt";
6
+ type OmitBase<T> = Omit<T, BaseFields>;
7
+ export declare function via<T>(modelRef: Type<T>): Type<Prettify<T & BaseObject>>;
8
+ export declare function via<T, Light>(modelRef: Type<T>, lightModelRef: Type<Light>, overwriteRef?: Type, overwriteLightRef?: Type): Type<Prettify<T & Light & BaseObject>>;
9
+ export declare function via<T, K extends NonFunctionalKeys<OmitBase<T>>>(modelRef: Type<T>, fields: readonly K[]): Type<Prettify<Pick<T, K> & BaseObject>>;
10
+ type TypesFromArray<T extends Type[]> = {
11
+ [K in keyof T]: T[K] extends Type<infer U> ? U : never;
12
+ }[number];
13
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
14
+ export declare const from: <A, T extends Type[]>(modelRef: Type<A>, ...types: T) => Type<A & UnionToIntersection<TypesFromArray<T>>>;
15
+ export declare const mixModelOf: <T extends Type[]>(...types: T) => Type<UnionToIntersection<TypesFromArray<T>>>;
16
+ export declare const over: <T extends Type[]>(...types: T) => Type<UnionToIntersection<TypesFromArray<T>>>;
17
+ export {};
@@ -1,8 +1,8 @@
1
1
  import "reflect-metadata";
2
2
  import type { Type } from "@akanjs/base";
3
- import type { FilterType } from "./types";
3
+ import type { DefaultOf, DocumentModel, FilterType, GetActionObject, GetStateObject, QueryOf, SortOf } from "./types";
4
4
  export declare const getCnstMeta: (refName: string) => ConstantModel<any, any, any, any, any, any>;
5
- export interface ConstantModel<T extends string, Input, Full, Light, Insight, Filter extends FilterType, Summary = any> {
5
+ export interface ConstantModel<T extends string, Input, Full, Light, Insight, Filter extends FilterType, Summary = any, _CapitalizedT extends string = Capitalize<T>, _Default = DefaultOf<Full>, _DefaultInput = DefaultOf<Input>, _DefaultState = GetStateObject<Full>, _DefaultStateInput = GetStateObject<Input>, _Doc = DocumentModel<Full>, _DocInput = DocumentModel<Input>, _QueryOfDoc = QueryOf<_Doc>, _Query = GetActionObject<Filter>, _Sort = SortOf<Filter>> {
6
6
  refName: T;
7
7
  Input: Type<Input>;
8
8
  Full: Type<Full>;
@@ -10,5 +10,22 @@ export interface ConstantModel<T extends string, Input, Full, Light, Insight, Fi
10
10
  Insight: Type<Insight>;
11
11
  Filter: Type<Filter>;
12
12
  Summary?: Type<Summary>;
13
+ _CapitalizedT: _CapitalizedT;
14
+ _Default: _Default;
15
+ _DefaultInput: _DefaultInput;
16
+ _DefaultState: _DefaultState;
17
+ _DefaultStateInput: _DefaultStateInput;
18
+ _Doc: _Doc;
19
+ _DocInput: _DocInput;
20
+ _QueryOfDoc: _QueryOfDoc;
21
+ _Query: _Query;
22
+ _Sort: _Sort;
13
23
  }
14
- export declare const cnstOf: <T extends string, Input, Full, Light, Insight, Filter extends FilterType, Summary>(refName: T, Input: Type<Input>, Full: Type<Full>, Light: Type<Light>, Insight: Type<Insight>, Filter: Type<Filter>, Summary?: Type<Summary>) => ConstantModel<T, Input, Full, Light, Insight, Filter, Summary>;
24
+ export declare const cnstOf: <T extends string, Input, Full, Light, Insight, Filter extends FilterType, Summary>(refName: T, Input: Type<Input>, Full: Type<Full>, Light: Type<Light>, Insight: Type<Insight>, Filter: Type<Filter>, Summary?: Type<Summary>) => ConstantModel<T, Input, Full, Light, Insight, Filter, Summary, Capitalize<T>, DefaultOf<Full>, DefaultOf<Input>, GetStateObject<Full>, GetStateObject<Input>, DocumentModel<Full>, DocumentModel<Input>, QueryOf<DocumentModel<Full>>, GetActionObject<Filter>, SortOf<Filter>>;
25
+ export interface ScalarConstantModel<T extends string, Model, _Default = DefaultOf<Model>, _Doc = DocumentModel<Model>> {
26
+ refName: T;
27
+ Model: Type<Model>;
28
+ _Default: _Default;
29
+ _Doc: _Doc;
30
+ }
31
+ export declare const scalarCnstOf: <T extends string, Model>(refName: T, Model: Type<Model>) => ScalarConstantModel<T, Model>;
package/src/types.d.ts CHANGED
@@ -1,15 +1,27 @@
1
1
  import { type BaseObject, Dayjs, enumOf } from "@akanjs/base";
2
2
  import type { FilterQuery, HydratedDocument, ProjectionType } from "mongoose";
3
3
  export type { FilterQuery as QueryOf };
4
- type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
5
- type OptionalKeys<T> = T extends {
6
- [key: string]: any;
7
- } ? {
8
- [K in keyof T]-?: null extends T[K] ? K : never;
9
- }[keyof T] : never;
10
- type ObjectToId<O, D = Dayjs> = O extends BaseObject ? string : O extends BaseObject[] ? string[] : O extends Dayjs ? D : O extends {
4
+ type ObjectToId<O> = O extends BaseObject ? string : O extends BaseObject[] ? string[] : O extends Dayjs ? Dayjs : O extends {
11
5
  [key: string]: any;
12
6
  } ? DocumentModel<O> : O;
7
+ export type GetStateObject<T> = {
8
+ [K in keyof T as T[K] extends (...args: any) => any ? never : K extends "prototype" ? never : K]: T[K];
9
+ };
10
+ export type GetActionObject<T> = {
11
+ [K in keyof T as T[K] extends (...args: any) => any ? (K extends "prototype" ? never : K) : never]: T[K];
12
+ };
13
+ type NullToUndefinedWithObjectToId<T, StateKeys extends keyof GetStateObject<T> = keyof GetStateObject<T>> = {
14
+ [K in StateKeys as null extends T[K] ? never : K]: ObjectToId<T[K]>;
15
+ } & {
16
+ [K in StateKeys as null extends T[K] ? K : never]?: ObjectToId<Exclude<T[K], null>> | undefined;
17
+ };
18
+ export type DocumentModel<T> = T extends (infer S)[] ? DocumentModel<S>[] : T extends string | number | boolean | Dayjs ? T : T extends Map<infer K, infer V> ? Map<K, DocumentModel<V>> : NullToUndefinedWithObjectToId<T>;
19
+ export type FieldState<T> = T extends {
20
+ id: string;
21
+ } ? T | null : T;
22
+ export type DefaultOf<S> = {
23
+ [K in keyof S]: FieldState<S[K]>;
24
+ };
13
25
  export interface SortType {
14
26
  [key: string]: {
15
27
  [key: string]: number;
@@ -30,24 +42,9 @@ export interface FindQueryOption<Sort, Obj> {
30
42
  sample?: boolean;
31
43
  select?: ProjectionType<Obj>;
32
44
  }
33
- export type DocumentModel<T, D = Dayjs> = T extends (infer S)[] ? DocumentModel<S>[] : T extends string ? T : T extends number ? T : T extends boolean ? T : T extends Dayjs ? T : T extends Map<infer K, infer V> ? Map<K, DocumentModel<V, D>> : Optional<{
34
- [K in keyof GetStateObject<T>]: T[K] extends infer S ? S extends null ? undefined : ObjectToId<T[K], D> : never;
35
- }, OptionalKeys<GetStateObject<T>>>;
36
- export interface ListOption {
37
- limit?: number;
38
- skip?: number;
39
- sort?: string;
40
- }
41
- export declare const defaultListOption: ListOption;
42
45
  export type GetPlainObject<T, O extends string> = Omit<{
43
46
  [K in keyof T as T[K] extends (...args: any) => any ? never : K extends keyof HydratedDocument<any> ? never : K]: T[K];
44
47
  }, O>;
45
- export type GetStateObject<T> = Omit<{
46
- [K in keyof T as T[K] extends (...args: any) => any ? never : K]: T[K];
47
- }, "prototype">;
48
- export type GetActionObject<T> = Omit<{
49
- [K in keyof T as T[K] extends (...args: any) => any ? K : never]: T[K];
50
- }, "prototype">;
51
48
  export interface ProtoFile {
52
49
  id: string;
53
50
  filename: string;