@akanjs/constant 0.9.42 → 0.9.44
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/cjs/src/baseGql.js +104 -66
- package/cjs/src/classMeta.js +36 -21
- package/cjs/src/constantDecorator.js +30 -3
- package/cjs/src/fieldMeta.js +2 -2
- package/cjs/src/filterMeta.js +15 -3
- package/cjs/src/scalar.js +4 -11
- package/cjs/src/types.js +0 -6
- package/esm/src/baseGql.js +101 -64
- package/esm/src/classMeta.js +36 -21
- package/esm/src/constantDecorator.js +30 -3
- package/esm/src/fieldMeta.js +2 -2
- package/esm/src/filterMeta.js +15 -3
- package/esm/src/scalar.js +4 -11
- package/esm/src/types.js +0 -6
- package/package.json +1 -1
- package/src/baseGql.d.ts +7 -5
- package/src/classMeta.d.ts +3 -11
- package/src/constantDecorator.d.ts +21 -5
- package/src/filterMeta.d.ts +2 -2
- package/src/scalar.d.ts +14 -8
- package/src/types.d.ts +14 -23
package/esm/src/baseGql.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import { ID } from "@akanjs/base";
|
|
3
3
|
import { applyMixins } from "@akanjs/common";
|
|
4
|
+
import { getFullModelRefs } from "./classMeta";
|
|
4
5
|
import {
|
|
5
6
|
getFilterArgMetas,
|
|
6
7
|
getFilterMeta,
|
|
7
8
|
getFilterQueryMap,
|
|
8
9
|
getFilterSortMap,
|
|
9
|
-
isFilterModel,
|
|
10
10
|
setFilterArgMetasOnPrototype,
|
|
11
11
|
setFilterKeyMetaMapOnPrototype,
|
|
12
12
|
setFilterMeta
|
|
13
13
|
} from "./filterMeta";
|
|
14
|
-
import {
|
|
14
|
+
import { getClassMeta, getFieldMetaMap, setFieldMetaMap } from "./scalar";
|
|
15
15
|
const defaultFieldMeta = {
|
|
16
16
|
fieldType: "property",
|
|
17
17
|
immutable: false,
|
|
@@ -23,7 +23,8 @@ const defaultFieldMeta = {
|
|
|
23
23
|
arrDepth: 0,
|
|
24
24
|
optArrDepth: 0,
|
|
25
25
|
default: null,
|
|
26
|
-
isMap: false
|
|
26
|
+
isMap: false,
|
|
27
|
+
meta: {}
|
|
27
28
|
};
|
|
28
29
|
const idFieldMeta = { ...defaultFieldMeta, key: "id", name: "ID", modelRef: ID };
|
|
29
30
|
const createdAtFieldMeta = { ...defaultFieldMeta, key: "createdAt", name: "Date", modelRef: Date };
|
|
@@ -48,7 +49,7 @@ const baseModelOf = (modelRef) => {
|
|
|
48
49
|
class BaseModel {
|
|
49
50
|
__ModelType__ = "full";
|
|
50
51
|
}
|
|
51
|
-
const metadataMap = getFieldMetaMap(modelRef);
|
|
52
|
+
const metadataMap = new Map(getFieldMetaMap(modelRef));
|
|
52
53
|
metadataMap.set("id", idFieldMeta);
|
|
53
54
|
metadataMap.set("createdAt", createdAtFieldMeta);
|
|
54
55
|
metadataMap.set("updatedAt", updatedAtFieldMeta);
|
|
@@ -56,56 +57,117 @@ const baseModelOf = (modelRef) => {
|
|
|
56
57
|
Reflect.defineMetadata("fields", metadataMap, BaseModel.prototype);
|
|
57
58
|
return BaseModel;
|
|
58
59
|
};
|
|
59
|
-
const lightModelOf = (objectRef, fields) => {
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
60
|
+
const lightModelOf = (objectRef, fields, ...libLightModelRefs) => {
|
|
61
|
+
const objectFieldMetaMap = getFieldMetaMap(objectRef);
|
|
62
|
+
const baseLightModelRef = libLightModelRefs.at(0);
|
|
63
|
+
const fieldMetaMap = baseLightModelRef ? getFieldMetaMap(baseLightModelRef) : /* @__PURE__ */ new Map();
|
|
64
|
+
class BaseLightModel {
|
|
63
65
|
__ModelType__ = "light";
|
|
64
66
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
fieldMetaMap.set("id", idFieldMeta);
|
|
68
|
+
fieldMetaMap.set("createdAt", createdAtFieldMeta);
|
|
69
|
+
fieldMetaMap.set("updatedAt", updatedAtFieldMeta);
|
|
70
|
+
fieldMetaMap.set("removedAt", removedAtFieldMeta);
|
|
71
|
+
for (const field of fields) {
|
|
72
|
+
const fieldMeta = objectFieldMetaMap.get(field);
|
|
73
|
+
if (!fieldMeta)
|
|
74
|
+
throw new Error(`Field ${field} not found in objectRef`);
|
|
75
|
+
fieldMetaMap.set(field, fieldMeta);
|
|
76
|
+
}
|
|
77
|
+
applyMixins(BaseLightModel, libLightModelRefs);
|
|
78
|
+
Reflect.defineMetadata("fields", fieldMetaMap, BaseLightModel.prototype);
|
|
79
|
+
return BaseLightModel;
|
|
68
80
|
};
|
|
69
|
-
const fullModelOf = (modelRef, lightRef,
|
|
81
|
+
const fullModelOf = (modelRef, lightRef, ...libFullModelRefs) => {
|
|
70
82
|
const modelFieldMetaMap = getFieldMetaMap(modelRef);
|
|
71
83
|
const lightFieldMetaMap = getFieldMetaMap(lightRef);
|
|
72
|
-
applyMixins(modelRef, [lightRef]);
|
|
73
|
-
|
|
74
|
-
applyMixins(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (overwriteLightRef) {
|
|
78
|
-
applyMixins(overwriteLightRef, [lightRef]);
|
|
79
|
-
setFieldMetaMap(overwriteLightRef, lightFieldMetaMap);
|
|
80
|
-
}
|
|
81
|
-
setFieldMetaMap(modelRef, new Map([...modelFieldMetaMap, ...lightFieldMetaMap]));
|
|
84
|
+
applyMixins(modelRef, [...libFullModelRefs, lightRef]);
|
|
85
|
+
libFullModelRefs.forEach((libFullModelRef) => {
|
|
86
|
+
applyMixins(libFullModelRef, [lightRef, modelRef]);
|
|
87
|
+
});
|
|
88
|
+
lightFieldMetaMap.forEach((value, key) => modelFieldMetaMap.set(key, value));
|
|
82
89
|
return modelRef;
|
|
83
90
|
};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
function via(modelRef, fieldsOrLightModelRef, ...fullOrLightModelRefs) {
|
|
92
|
+
const classMeta = getClassMeta(modelRef);
|
|
93
|
+
if (!fieldsOrLightModelRef) {
|
|
94
|
+
if (classMeta.type === "input") {
|
|
95
|
+
const objectRefName = classMeta.refName.slice(0, -5) + "Object";
|
|
96
|
+
const isFullModelRefDefined = getFullModelRefs(objectRefName).length > 0;
|
|
97
|
+
if (isFullModelRefDefined)
|
|
98
|
+
return extendModelInputs(modelRef);
|
|
99
|
+
else
|
|
100
|
+
return baseModelOf(modelRef);
|
|
101
|
+
} else if (classMeta.modelType === "insight")
|
|
102
|
+
return extendModelInsights(modelRef);
|
|
103
|
+
else
|
|
104
|
+
throw new Error("Invalid modelRef args");
|
|
105
|
+
}
|
|
106
|
+
if (Array.isArray(fieldsOrLightModelRef))
|
|
107
|
+
return lightModelOf(modelRef, fieldsOrLightModelRef, ...fullOrLightModelRefs);
|
|
108
|
+
const secondArgModelRef = fieldsOrLightModelRef;
|
|
109
|
+
const secondArgClassMeta = getClassMeta(secondArgModelRef);
|
|
110
|
+
if (classMeta.type === "input") {
|
|
111
|
+
if (secondArgClassMeta.type === "input")
|
|
112
|
+
return extendModelInputs(modelRef, secondArgModelRef, ...fullOrLightModelRefs);
|
|
113
|
+
else if (secondArgClassMeta.type === "full")
|
|
114
|
+
return extendModelObjects(modelRef, secondArgModelRef, ...fullOrLightModelRefs);
|
|
115
|
+
else
|
|
116
|
+
throw new Error("Invalid modelRef args");
|
|
117
|
+
} else if (classMeta.type === "full") {
|
|
118
|
+
if (secondArgClassMeta.type === "light")
|
|
119
|
+
return fullModelOf(modelRef, secondArgModelRef, ...fullOrLightModelRefs);
|
|
120
|
+
else
|
|
121
|
+
throw new Error("Invalid modelRef args");
|
|
122
|
+
} else if (classMeta.modelType === "insight")
|
|
123
|
+
return extendModelInsights(modelRef, secondArgModelRef, ...fullOrLightModelRefs);
|
|
89
124
|
else
|
|
90
|
-
|
|
125
|
+
throw new Error("Invalid modelRef");
|
|
126
|
+
}
|
|
127
|
+
const extendModelInputs = (...libInputModelRefs) => {
|
|
128
|
+
const baseInputModelRef = libInputModelRefs.at(0);
|
|
129
|
+
const fieldMetaMap = baseInputModelRef ? getFieldMetaMap(baseInputModelRef) : /* @__PURE__ */ new Map();
|
|
130
|
+
class BaseInput {
|
|
131
|
+
__ModelType__ = "input";
|
|
132
|
+
}
|
|
133
|
+
setFieldMetaMap(BaseInput, fieldMetaMap);
|
|
134
|
+
return BaseInput;
|
|
135
|
+
};
|
|
136
|
+
const extendModelObjects = (inputRef, ...libObjectModelRefs) => {
|
|
137
|
+
const baseObjectModelRef = libObjectModelRefs.at(0);
|
|
138
|
+
const inputFieldMetaMap = getFieldMetaMap(inputRef);
|
|
139
|
+
const fieldMetaMap = baseObjectModelRef ? getFieldMetaMap(baseObjectModelRef) : /* @__PURE__ */ new Map();
|
|
140
|
+
class BaseInput {
|
|
141
|
+
__ModelType__ = "object";
|
|
142
|
+
}
|
|
143
|
+
inputFieldMetaMap.forEach((value, key) => fieldMetaMap.set(key, value));
|
|
144
|
+
setFieldMetaMap(BaseInput, fieldMetaMap);
|
|
145
|
+
return BaseInput;
|
|
146
|
+
};
|
|
147
|
+
const extendModelInsights = (...insightModelRefs) => {
|
|
148
|
+
const baseInsightModelRef = insightModelRefs.at(0);
|
|
149
|
+
const insightFieldMetaMap = baseInsightModelRef ? getFieldMetaMap(baseInsightModelRef) : /* @__PURE__ */ new Map();
|
|
150
|
+
class BaseInsight {
|
|
151
|
+
__ModelType__ = "insight";
|
|
152
|
+
}
|
|
153
|
+
setFieldMetaMap(BaseInsight, insightFieldMetaMap);
|
|
154
|
+
return BaseInsight;
|
|
91
155
|
};
|
|
92
|
-
const addModelOf = (modelRef,
|
|
156
|
+
const addModelOf = (modelRef, ...types) => {
|
|
93
157
|
const modelMetadataMap = getFieldMetaMap(modelRef);
|
|
94
|
-
const metadataMap =
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}, modelMetadataMap)
|
|
100
|
-
);
|
|
158
|
+
const metadataMap = types.reduce((acc, writeRef) => {
|
|
159
|
+
const writeMetadataMap = getFieldMetaMap(writeRef);
|
|
160
|
+
applyMixins(modelRef, [writeRef]);
|
|
161
|
+
return new Map([...acc, ...writeMetadataMap]);
|
|
162
|
+
}, modelMetadataMap);
|
|
101
163
|
setFieldMetaMap(modelRef, metadataMap);
|
|
102
164
|
return modelRef;
|
|
103
165
|
};
|
|
104
|
-
const addFilterOf = (filterRef,
|
|
166
|
+
const addFilterOf = (filterRef, ...types) => {
|
|
105
167
|
const filterMeta = getFilterMeta(filterRef);
|
|
106
168
|
const filterQueryMap = getFilterQueryMap(filterRef);
|
|
107
169
|
const metadataMap = new Map(
|
|
108
|
-
|
|
170
|
+
types.reduce((acc, writeRef) => {
|
|
109
171
|
const writeMetadataMap = getFilterQueryMap(writeRef);
|
|
110
172
|
applyMixins(filterRef, [writeRef]);
|
|
111
173
|
writeMetadataMap.forEach((value, key) => {
|
|
@@ -115,7 +177,7 @@ const addFilterOf = (filterRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => {
|
|
|
115
177
|
return new Map([...acc, ...writeMetadataMap]);
|
|
116
178
|
}, filterQueryMap)
|
|
117
179
|
);
|
|
118
|
-
const filterSort =
|
|
180
|
+
const filterSort = types.filter(Boolean).map((t) => getFilterSortMap(t)).reduce((acc, sort) => {
|
|
119
181
|
Object.assign(acc, sort);
|
|
120
182
|
return acc;
|
|
121
183
|
}, filterMeta.sort);
|
|
@@ -123,32 +185,7 @@ const addFilterOf = (filterRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => {
|
|
|
123
185
|
setFilterMeta(filterRef, { ...filterMeta, sort: filterSort });
|
|
124
186
|
return filterRef;
|
|
125
187
|
};
|
|
126
|
-
const from = (modelRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => {
|
|
127
|
-
if (isConstantModel(modelRef))
|
|
128
|
-
return addModelOf(modelRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10);
|
|
129
|
-
else if (isFilterModel(modelRef))
|
|
130
|
-
return addFilterOf(modelRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10);
|
|
131
|
-
else
|
|
132
|
-
throw new Error("Invalid modelRef");
|
|
133
|
-
};
|
|
134
|
-
const mixModelOf = (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20) => {
|
|
135
|
-
class Mix {
|
|
136
|
-
}
|
|
137
|
-
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) => {
|
|
139
|
-
const modelMetadataMap = getFieldMetaMap(modelRef);
|
|
140
|
-
applyMixins(Mix, [modelRef]);
|
|
141
|
-
return [...acc, ...modelMetadataMap];
|
|
142
|
-
}, [])
|
|
143
|
-
);
|
|
144
|
-
setFieldMetaMap(Mix, metadataMap);
|
|
145
|
-
return Mix;
|
|
146
|
-
};
|
|
147
|
-
const over = mixModelOf;
|
|
148
188
|
export {
|
|
149
189
|
as,
|
|
150
|
-
from,
|
|
151
|
-
mixModelOf,
|
|
152
|
-
over,
|
|
153
190
|
via
|
|
154
191
|
};
|
package/esm/src/classMeta.js
CHANGED
|
@@ -13,23 +13,38 @@ class ScalarModelStorage {
|
|
|
13
13
|
class FilterModelStorage {
|
|
14
14
|
}
|
|
15
15
|
const getFullModelRef = (refName) => {
|
|
16
|
-
const
|
|
16
|
+
const modelRefs = Reflect.getMetadata(capitalize(refName), FullModelStorage.prototype);
|
|
17
|
+
const modelRef = modelRefs?.[0];
|
|
17
18
|
if (!modelRef)
|
|
18
19
|
throw new Error(`FullModel not found - ${refName}`);
|
|
19
20
|
return modelRef;
|
|
20
21
|
};
|
|
22
|
+
const getFullModelRefs = (refName) => {
|
|
23
|
+
const modelRefs = Reflect.getMetadata(capitalize(refName), FullModelStorage.prototype);
|
|
24
|
+
return modelRefs ?? [];
|
|
25
|
+
};
|
|
21
26
|
const getInputModelRef = (refName) => {
|
|
22
|
-
const
|
|
27
|
+
const modelRefs = Reflect.getMetadata(capitalize(refName), InputModelStorage.prototype);
|
|
28
|
+
const modelRef = modelRefs?.[0];
|
|
23
29
|
if (!modelRef)
|
|
24
30
|
throw new Error(`InputModel not found - ${refName}`);
|
|
25
31
|
return modelRef;
|
|
26
32
|
};
|
|
33
|
+
const getInputModelRefs = (refName) => {
|
|
34
|
+
const modelRefs = Reflect.getMetadata(capitalize(refName), InputModelStorage.prototype);
|
|
35
|
+
return modelRefs ?? [];
|
|
36
|
+
};
|
|
27
37
|
const getScalarModelRef = (refName) => {
|
|
28
|
-
const
|
|
38
|
+
const modelRefs = Reflect.getMetadata(capitalize(refName), ScalarModelStorage.prototype);
|
|
39
|
+
const modelRef = modelRefs?.[0];
|
|
29
40
|
if (!modelRef)
|
|
30
41
|
throw new Error(`ScalarModel not found - ${refName}`);
|
|
31
42
|
return modelRef;
|
|
32
43
|
};
|
|
44
|
+
const getScalarModelRefs = (refName) => {
|
|
45
|
+
const modelRefs = Reflect.getMetadata(capitalize(refName), ScalarModelStorage.prototype);
|
|
46
|
+
return modelRefs ?? [];
|
|
47
|
+
};
|
|
33
48
|
const getChildClassRefs = (target) => {
|
|
34
49
|
const metadatas = getFieldMetas(target);
|
|
35
50
|
const refMap = /* @__PURE__ */ new Map();
|
|
@@ -55,7 +70,11 @@ const applyClassMeta = (type, modelType, storage) => {
|
|
|
55
70
|
const modelRef = target;
|
|
56
71
|
const classMeta = { refName, type, modelType, modelRef, hasTextField: hasTextField(modelRef) };
|
|
57
72
|
Reflect.defineMetadata("class", classMeta, modelRef.prototype);
|
|
58
|
-
Reflect.
|
|
73
|
+
const modelRefs = Reflect.getMetadata(capitalize(refName), storage.prototype);
|
|
74
|
+
if (modelRefs)
|
|
75
|
+
modelRefs.push(modelRef);
|
|
76
|
+
else
|
|
77
|
+
Reflect.defineMetadata(refName, [modelRef], storage.prototype);
|
|
59
78
|
};
|
|
60
79
|
};
|
|
61
80
|
};
|
|
@@ -64,7 +83,11 @@ const applyFilterMeta = (storage) => {
|
|
|
64
83
|
return function(target) {
|
|
65
84
|
const modelRef = target;
|
|
66
85
|
setFilterMeta(modelRef, { refName, sort: {} });
|
|
67
|
-
Reflect.
|
|
86
|
+
const modelRefs = Reflect.getMetadata(capitalize(refName), storage.prototype);
|
|
87
|
+
if (modelRefs)
|
|
88
|
+
modelRefs.push(modelRef);
|
|
89
|
+
else
|
|
90
|
+
Reflect.defineMetadata(refName, [modelRef], storage.prototype);
|
|
68
91
|
};
|
|
69
92
|
};
|
|
70
93
|
};
|
|
@@ -74,7 +97,6 @@ const Model = {
|
|
|
74
97
|
Full: applyClassMeta("full", "data", FullModelStorage),
|
|
75
98
|
Input: applyClassMeta("input", "data", InputModelStorage),
|
|
76
99
|
Scalar: applyClassMeta("scalar", "data", ScalarModelStorage),
|
|
77
|
-
Summary: applyClassMeta("scalar", "summary", ScalarModelStorage),
|
|
78
100
|
Insight: applyClassMeta("scalar", "insight", ScalarModelStorage),
|
|
79
101
|
Filter: applyFilterMeta(FilterModelStorage)
|
|
80
102
|
};
|
|
@@ -82,47 +104,40 @@ const getLightModelRef = (modelRef) => {
|
|
|
82
104
|
const classMeta = getClassMeta(modelRef);
|
|
83
105
|
if (classMeta.type !== "full")
|
|
84
106
|
return modelRef;
|
|
85
|
-
const
|
|
107
|
+
const lightModelRefs = Reflect.getMetadata(`Light${classMeta.refName}`, LightModelStorage.prototype);
|
|
108
|
+
const lightModelRef = lightModelRefs?.at(-1);
|
|
86
109
|
if (!lightModelRef)
|
|
87
110
|
throw new Error(`LightModel not found - ${classMeta.refName}`);
|
|
88
111
|
return lightModelRef;
|
|
89
112
|
};
|
|
90
113
|
const getAllFullModelRefs = () => {
|
|
91
114
|
const modelNames = Reflect.getMetadataKeys(FullModelStorage.prototype);
|
|
92
|
-
const modelRefs = modelNames.map(
|
|
93
|
-
(modelName) => Reflect.getMetadata(modelName, FullModelStorage.prototype)
|
|
94
|
-
);
|
|
115
|
+
const modelRefs = modelNames.map((modelName) => Reflect.getMetadata(modelName, FullModelStorage.prototype)).flat();
|
|
95
116
|
return modelRefs;
|
|
96
117
|
};
|
|
97
118
|
const getAllScalarModelRefs = () => {
|
|
98
119
|
const modelNames = Reflect.getMetadataKeys(ScalarModelStorage.prototype);
|
|
99
|
-
const modelRefs = modelNames.map(
|
|
100
|
-
(modelName) => Reflect.getMetadata(modelName, ScalarModelStorage.prototype)
|
|
101
|
-
);
|
|
120
|
+
const modelRefs = modelNames.map((modelName) => Reflect.getMetadata(modelName, ScalarModelStorage.prototype)).flat();
|
|
102
121
|
return modelRefs;
|
|
103
122
|
};
|
|
104
123
|
const getAllFilterModelRefs = () => {
|
|
105
124
|
const modelNames = Reflect.getMetadataKeys(FilterModelStorage.prototype);
|
|
106
|
-
const modelRefs = modelNames.map(
|
|
107
|
-
(modelName) => Reflect.getMetadata(modelName, FilterModelStorage.prototype)
|
|
108
|
-
);
|
|
125
|
+
const modelRefs = modelNames.map((modelName) => Reflect.getMetadata(modelName, FilterModelStorage.prototype)).flat();
|
|
109
126
|
return modelRefs;
|
|
110
127
|
};
|
|
111
128
|
export {
|
|
112
|
-
FilterModelStorage,
|
|
113
|
-
FullModelStorage,
|
|
114
|
-
InputModelStorage,
|
|
115
|
-
LightModelStorage,
|
|
116
129
|
Model,
|
|
117
|
-
ScalarModelStorage,
|
|
118
130
|
getAllFilterModelRefs,
|
|
119
131
|
getAllFullModelRefs,
|
|
120
132
|
getAllScalarModelRefs,
|
|
121
133
|
getChildClassRefs,
|
|
122
134
|
getFieldEnumMetas,
|
|
123
135
|
getFullModelRef,
|
|
136
|
+
getFullModelRefs,
|
|
124
137
|
getInputModelRef,
|
|
138
|
+
getInputModelRefs,
|
|
125
139
|
getLightModelRef,
|
|
126
140
|
getScalarModelRef,
|
|
141
|
+
getScalarModelRefs,
|
|
127
142
|
hasTextField
|
|
128
143
|
};
|
|
@@ -10,12 +10,39 @@ const getCnstMeta = (refName) => {
|
|
|
10
10
|
throw new Error(`No cnst meta for ${refName}`);
|
|
11
11
|
return cnst;
|
|
12
12
|
};
|
|
13
|
-
const cnstOf = (refName, Input, Full, Light, Insight, Filter
|
|
14
|
-
const cnst = {
|
|
13
|
+
const cnstOf = (refName, Input, Full, Light, Insight, Filter) => {
|
|
14
|
+
const cnst = {
|
|
15
|
+
refName,
|
|
16
|
+
Input,
|
|
17
|
+
Full,
|
|
18
|
+
Light,
|
|
19
|
+
Insight,
|
|
20
|
+
Filter,
|
|
21
|
+
_CapitalizedT: null,
|
|
22
|
+
_Default: null,
|
|
23
|
+
_DefaultInput: null,
|
|
24
|
+
_DefaultState: null,
|
|
25
|
+
_DefaultStateInput: null,
|
|
26
|
+
_Doc: null,
|
|
27
|
+
_DocInput: null,
|
|
28
|
+
_QueryOfDoc: null,
|
|
29
|
+
_Query: null,
|
|
30
|
+
_Sort: null
|
|
31
|
+
};
|
|
15
32
|
setCnstMeta(refName, cnst);
|
|
16
33
|
return cnst;
|
|
17
34
|
};
|
|
35
|
+
const scalarCnstOf = (refName, Model) => {
|
|
36
|
+
const cnst = {
|
|
37
|
+
refName,
|
|
38
|
+
Model,
|
|
39
|
+
_Default: null,
|
|
40
|
+
_Doc: null
|
|
41
|
+
};
|
|
42
|
+
return cnst;
|
|
43
|
+
};
|
|
18
44
|
export {
|
|
19
45
|
cnstOf,
|
|
20
|
-
getCnstMeta
|
|
46
|
+
getCnstMeta,
|
|
47
|
+
scalarCnstOf
|
|
21
48
|
};
|
package/esm/src/fieldMeta.js
CHANGED
|
@@ -28,7 +28,6 @@ const applyFieldMeta = (modelRef, arrDepth, option, optionArrDepth) => {
|
|
|
28
28
|
select: option.select ?? true,
|
|
29
29
|
minlength: option.minlength,
|
|
30
30
|
maxlength: option.maxlength,
|
|
31
|
-
query: option.query,
|
|
32
31
|
accumulate: option.accumulate,
|
|
33
32
|
example: option.example,
|
|
34
33
|
validate: option.validate,
|
|
@@ -42,7 +41,8 @@ const applyFieldMeta = (modelRef, arrDepth, option, optionArrDepth) => {
|
|
|
42
41
|
optArrDepth: optionArrDepth,
|
|
43
42
|
isMap,
|
|
44
43
|
of: option.of,
|
|
45
|
-
text: option.text
|
|
44
|
+
text: option.text,
|
|
45
|
+
meta: option.meta ?? {}
|
|
46
46
|
};
|
|
47
47
|
const metadataMap = getFieldMetaMapOnPrototype(prototype);
|
|
48
48
|
metadataMap.set(key, metadata);
|
package/esm/src/filterMeta.js
CHANGED
|
@@ -11,6 +11,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
11
11
|
};
|
|
12
12
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
13
13
|
import { getNonArrayModel } from "@akanjs/base";
|
|
14
|
+
import { applyMixins } from "@akanjs/common";
|
|
14
15
|
import {
|
|
15
16
|
getFieldMetaMap
|
|
16
17
|
} from "./scalar";
|
|
@@ -26,8 +27,9 @@ const getFilterMeta = (filterRef) => {
|
|
|
26
27
|
const setFilterMeta = (filterRef, filterMeta) => {
|
|
27
28
|
const existingFilterMeta = Reflect.getMetadata("filter", filterRef.prototype);
|
|
28
29
|
if (existingFilterMeta)
|
|
29
|
-
Object.assign(filterMeta.sort,
|
|
30
|
-
|
|
30
|
+
Object.assign(existingFilterMeta, { ...filterMeta, sort: { ...existingFilterMeta.sort, ...filterMeta.sort } });
|
|
31
|
+
else
|
|
32
|
+
Reflect.defineMetadata("filter", filterMeta, filterRef.prototype);
|
|
31
33
|
};
|
|
32
34
|
const getFilterKeyMetaMapOnPrototype = (prototype) => {
|
|
33
35
|
const metadataMap = Reflect.getMetadata("filterKey", prototype) ?? /* @__PURE__ */ new Map();
|
|
@@ -93,7 +95,7 @@ const Filter = {
|
|
|
93
95
|
// Meili: makeFilter({ fieldType: "hidden", nullable: true }),
|
|
94
96
|
Arg: applyFilterArgMeta
|
|
95
97
|
};
|
|
96
|
-
const sortOf = (modelRef, sort) => {
|
|
98
|
+
const sortOf = (modelRef, sort, ...libFilterRefs) => {
|
|
97
99
|
const fieldMetaMap = getFieldMetaMap(modelRef);
|
|
98
100
|
const statusFieldMeta = fieldMetaMap.get("status");
|
|
99
101
|
if (!statusFieldMeta)
|
|
@@ -120,6 +122,16 @@ const sortOf = (modelRef, sort) => {
|
|
|
120
122
|
refName: "BaseFilter",
|
|
121
123
|
sort: Object.assign({ latest: { createdAt: -1 }, oldest: { createdAt: 1 } }, sort)
|
|
122
124
|
});
|
|
125
|
+
applyMixins(BaseFilter2, libFilterRefs);
|
|
126
|
+
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(BaseFilter2.prototype);
|
|
127
|
+
libFilterRefs.forEach((libFilterRef) => {
|
|
128
|
+
const libFilterKeyMetaMap = getFilterKeyMetaMapOnPrototype(libFilterRef.prototype);
|
|
129
|
+
libFilterKeyMetaMap.forEach((value, key) => {
|
|
130
|
+
const libFilterArgMetas = getFilterArgMetas(libFilterRef, key);
|
|
131
|
+
filterKeyMetaMap.set(key, value);
|
|
132
|
+
setFilterArgMetasOnPrototype(BaseFilter2.prototype, key, libFilterArgMetas);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
123
135
|
return BaseFilter2;
|
|
124
136
|
};
|
|
125
137
|
function BaseFilter(modelRef, sort) {
|
package/esm/src/scalar.js
CHANGED
|
@@ -41,24 +41,18 @@ const isConstantModel = (modelRef) => {
|
|
|
41
41
|
const getFieldMetaMap = (modelRef) => {
|
|
42
42
|
const [target] = getNonArrayModel(modelRef);
|
|
43
43
|
const metadataMap = Reflect.getMetadata("fields", target.prototype) ?? /* @__PURE__ */ new Map();
|
|
44
|
-
return
|
|
44
|
+
return metadataMap;
|
|
45
45
|
};
|
|
46
46
|
const setFieldMetaMap = (modelRef, metadataMap) => {
|
|
47
47
|
const [target] = getNonArrayModel(modelRef);
|
|
48
|
-
Reflect.defineMetadata("fields",
|
|
48
|
+
Reflect.defineMetadata("fields", metadataMap, target.prototype);
|
|
49
49
|
};
|
|
50
50
|
const getFieldMetaMapOnPrototype = (prototype) => {
|
|
51
51
|
const metadataMap = Reflect.getMetadata("fields", prototype) ?? /* @__PURE__ */ new Map();
|
|
52
|
-
return
|
|
52
|
+
return metadataMap;
|
|
53
53
|
};
|
|
54
54
|
const setFieldMetaMapOnPrototype = (prototype, metadataMap) => {
|
|
55
|
-
Reflect.defineMetadata("fields",
|
|
56
|
-
};
|
|
57
|
-
const getQueryMap = (modelRef) => {
|
|
58
|
-
const fieldMetas = getFieldMetas(modelRef);
|
|
59
|
-
return Object.fromEntries(
|
|
60
|
-
fieldMetas.filter((fieldMeta) => !!fieldMeta.query).map((fieldMeta) => [fieldMeta.key, fieldMeta.query])
|
|
61
|
-
);
|
|
55
|
+
Reflect.defineMetadata("fields", metadataMap, prototype);
|
|
62
56
|
};
|
|
63
57
|
export {
|
|
64
58
|
fieldTypes,
|
|
@@ -67,7 +61,6 @@ export {
|
|
|
67
61
|
getFieldMetaMapOnPrototype,
|
|
68
62
|
getFieldMetas,
|
|
69
63
|
getGqlTypeStr,
|
|
70
|
-
getQueryMap,
|
|
71
64
|
getScalarExample,
|
|
72
65
|
isConstantModel,
|
|
73
66
|
scalarExampleMap,
|
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
package/src/baseGql.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import { BaseObject, type Prettify, Type } from "@akanjs/base";
|
|
2
|
+
import { BaseObject, type MergeAllTypes, 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
|
-
|
|
6
|
-
|
|
7
|
-
export declare
|
|
8
|
-
export declare
|
|
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, FullModels extends Type[]>(modelRef: Type<T>, lightModelRef: Type<Light>, ...fullModelRefs: FullModels): Type<Prettify<MergeAllTypes<FullModels> & T & Light & BaseObject>>;
|
|
9
|
+
export declare function via<T, K extends NonFunctionalKeys<OmitBase<T>>, LightModels extends Type[]>(modelRef: Type<T>, fields: readonly K[], ...lightModelRefs: LightModels): Type<Prettify<MergeAllTypes<LightModels> & Pick<T, K> & BaseObject>>;
|
|
10
|
+
export {};
|
package/src/classMeta.d.ts
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import { type Enum, type Type } from "@akanjs/base";
|
|
3
|
-
export declare class InputModelStorage {
|
|
4
|
-
}
|
|
5
|
-
export declare class LightModelStorage {
|
|
6
|
-
}
|
|
7
|
-
export declare class FullModelStorage {
|
|
8
|
-
}
|
|
9
|
-
export declare class ScalarModelStorage {
|
|
10
|
-
}
|
|
11
|
-
export declare class FilterModelStorage {
|
|
12
|
-
}
|
|
13
3
|
export declare const getFullModelRef: (refName: string) => Type;
|
|
4
|
+
export declare const getFullModelRefs: (refName: string) => Type[];
|
|
14
5
|
export declare const getInputModelRef: (refName: string) => Type;
|
|
6
|
+
export declare const getInputModelRefs: (refName: string) => Type[];
|
|
15
7
|
export declare const getScalarModelRef: (refName: string) => Type;
|
|
8
|
+
export declare const getScalarModelRefs: (refName: string) => Type[];
|
|
16
9
|
export declare const getChildClassRefs: (target: Type) => Type[];
|
|
17
10
|
export declare const getFieldEnumMetas: (modelRef: Type) => {
|
|
18
11
|
key: string;
|
|
@@ -26,7 +19,6 @@ export declare const Model: {
|
|
|
26
19
|
Full: (refName: string) => (target: Type) => void;
|
|
27
20
|
Input: (refName: string) => (target: Type) => void;
|
|
28
21
|
Scalar: (refName: string) => (target: Type) => void;
|
|
29
|
-
Summary: (refName: string) => (target: Type) => void;
|
|
30
22
|
Insight: (refName: string) => (target: Type) => void;
|
|
31
23
|
Filter: (refName: string) => (target: Type) => void;
|
|
32
24
|
};
|
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import type { Type } from "@akanjs/base";
|
|
3
|
-
import type { FilterType } from "./types";
|
|
2
|
+
import type { GetActionObject, GetStateObject, Type } from "@akanjs/base";
|
|
3
|
+
import type { DefaultOf, DocumentModel, FilterType, 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,
|
|
5
|
+
export interface ConstantModel<T extends string, Input, Full, Light, Insight, Filter extends FilterType, _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>;
|
|
9
9
|
Light: Type<Light>;
|
|
10
10
|
Insight: Type<Insight>;
|
|
11
11
|
Filter: Type<Filter>;
|
|
12
|
-
|
|
12
|
+
_CapitalizedT: _CapitalizedT;
|
|
13
|
+
_Default: _Default;
|
|
14
|
+
_DefaultInput: _DefaultInput;
|
|
15
|
+
_DefaultState: _DefaultState;
|
|
16
|
+
_DefaultStateInput: _DefaultStateInput;
|
|
17
|
+
_Doc: _Doc;
|
|
18
|
+
_DocInput: _DocInput;
|
|
19
|
+
_QueryOfDoc: _QueryOfDoc;
|
|
20
|
+
_Query: _Query;
|
|
21
|
+
_Sort: _Sort;
|
|
13
22
|
}
|
|
14
|
-
export declare const cnstOf: <T extends string, Input, Full, Light, Insight, Filter extends FilterType
|
|
23
|
+
export declare const cnstOf: <T extends string, Input, Full, Light, Insight, Filter extends FilterType>(refName: T, Input: Type<Input>, Full: Type<Full>, Light: Type<Light>, Insight: Type<Insight>, Filter: Type<Filter>) => ConstantModel<T, Input, Full, Light, Insight, Filter, Capitalize<T>, DefaultOf<Full>, DefaultOf<Input>, GetStateObject<Full>, GetStateObject<Input>, DocumentModel<Full>, DocumentModel<Input>, QueryOf<DocumentModel<Full>>, GetActionObject<Filter>, SortOf<Filter>>;
|
|
24
|
+
export interface ScalarConstantModel<T extends string, Model, _Default = DefaultOf<Model>, _Doc = DocumentModel<Model>> {
|
|
25
|
+
refName: T;
|
|
26
|
+
Model: Type<Model>;
|
|
27
|
+
_Default: _Default;
|
|
28
|
+
_Doc: _Doc;
|
|
29
|
+
}
|
|
30
|
+
export declare const scalarCnstOf: <T extends string, Model>(refName: T, Model: Type<Model>) => ScalarConstantModel<T, Model>;
|
package/src/filterMeta.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Prettify, type Type } from "@akanjs/base";
|
|
1
|
+
import { type MergeAllTypes, type Prettify, type Type } from "@akanjs/base";
|
|
2
2
|
import { type ConstantFilterMeta, type FilterArgMeta, type FilterArgProps, type FilterKeyMeta, type FilterKeyProps, type ReturnType } from "./scalar";
|
|
3
3
|
import type { QueryOf, SortType } from "./types";
|
|
4
4
|
export declare const isFilterModel: (filterRef: Type) => boolean;
|
|
@@ -19,7 +19,7 @@ export declare const Filter: {
|
|
|
19
19
|
Arg: (name: string, returns: ReturnType, argOption?: FilterArgProps | FilterArgProps[]) => (prototype: object, key: string, idx: number) => void;
|
|
20
20
|
};
|
|
21
21
|
export type BaseFilterKey = "latest" | "oldest" | "any" | "byStatuses";
|
|
22
|
-
export declare const sortOf: <Sort extends SortType>(modelRef: Type, sort: Sort) => Type<Prettify<{
|
|
22
|
+
export declare const sortOf: <Sort extends SortType, LibFilters extends Type[]>(modelRef: Type, sort: Sort, ...libFilterRefs: LibFilters) => Type<Prettify<MergeAllTypes<LibFilters> & {
|
|
23
23
|
latest: {
|
|
24
24
|
createdAt: number;
|
|
25
25
|
};
|