@akanjs/constant 0.9.43 → 0.9.45
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 +95 -60
- package/cjs/src/classMeta.js +36 -21
- package/cjs/src/constantDecorator.js +1 -2
- package/cjs/src/fieldMeta.js +2 -2
- package/cjs/src/filterMeta.js +15 -3
- package/cjs/src/scalar.js +4 -11
- package/esm/src/baseGql.js +92 -58
- package/esm/src/classMeta.js +36 -21
- package/esm/src/constantDecorator.js +1 -2
- package/esm/src/fieldMeta.js +2 -2
- package/esm/src/filterMeta.js +15 -3
- package/esm/src/scalar.js +4 -11
- package/package.json +1 -1
- package/src/baseGql.d.ts +3 -10
- package/src/classMeta.d.ts +3 -11
- package/src/constantDecorator.d.ts +4 -5
- package/src/filterMeta.d.ts +2 -2
- package/src/scalar.d.ts +14 -8
- package/src/types.d.ts +1 -7
package/cjs/src/baseGql.js
CHANGED
|
@@ -6,11 +6,11 @@ var __export = (target, all) => {
|
|
|
6
6
|
for (var name in all)
|
|
7
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
8
|
};
|
|
9
|
-
var __copyProps = (to,
|
|
10
|
-
if (
|
|
11
|
-
for (let key of __getOwnPropNames(
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
12
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () =>
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
14
|
}
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
@@ -18,15 +18,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
18
18
|
var baseGql_exports = {};
|
|
19
19
|
__export(baseGql_exports, {
|
|
20
20
|
as: () => as,
|
|
21
|
-
from: () => from,
|
|
22
|
-
mixModelOf: () => mixModelOf,
|
|
23
|
-
over: () => over,
|
|
24
21
|
via: () => via
|
|
25
22
|
});
|
|
26
23
|
module.exports = __toCommonJS(baseGql_exports);
|
|
27
24
|
var import_reflect_metadata = require("reflect-metadata");
|
|
28
25
|
var import_base = require("@akanjs/base");
|
|
29
26
|
var import_common = require("@akanjs/common");
|
|
27
|
+
var import_classMeta = require("./classMeta");
|
|
30
28
|
var import_filterMeta = require("./filterMeta");
|
|
31
29
|
var import_scalar = require("./scalar");
|
|
32
30
|
const defaultFieldMeta = {
|
|
@@ -40,7 +38,8 @@ const defaultFieldMeta = {
|
|
|
40
38
|
arrDepth: 0,
|
|
41
39
|
optArrDepth: 0,
|
|
42
40
|
default: null,
|
|
43
|
-
isMap: false
|
|
41
|
+
isMap: false,
|
|
42
|
+
meta: {}
|
|
44
43
|
};
|
|
45
44
|
const idFieldMeta = { ...defaultFieldMeta, key: "id", name: "ID", modelRef: import_base.ID };
|
|
46
45
|
const createdAtFieldMeta = { ...defaultFieldMeta, key: "createdAt", name: "Date", modelRef: Date };
|
|
@@ -65,7 +64,7 @@ const baseModelOf = (modelRef) => {
|
|
|
65
64
|
class BaseModel {
|
|
66
65
|
__ModelType__ = "full";
|
|
67
66
|
}
|
|
68
|
-
const metadataMap = (0, import_scalar.getFieldMetaMap)(modelRef);
|
|
67
|
+
const metadataMap = new Map((0, import_scalar.getFieldMetaMap)(modelRef));
|
|
69
68
|
metadataMap.set("id", idFieldMeta);
|
|
70
69
|
metadataMap.set("createdAt", createdAtFieldMeta);
|
|
71
70
|
metadataMap.set("updatedAt", updatedAtFieldMeta);
|
|
@@ -73,47 +72,105 @@ const baseModelOf = (modelRef) => {
|
|
|
73
72
|
Reflect.defineMetadata("fields", metadataMap, BaseModel.prototype);
|
|
74
73
|
return BaseModel;
|
|
75
74
|
};
|
|
76
|
-
const lightModelOf = (objectRef, fields) => {
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
75
|
+
const lightModelOf = (objectRef, fields, ...libLightModelRefs) => {
|
|
76
|
+
const objectFieldMetaMap = (0, import_scalar.getFieldMetaMap)(objectRef);
|
|
77
|
+
const baseLightModelRef = libLightModelRefs.at(0);
|
|
78
|
+
const fieldMetaMap = baseLightModelRef ? (0, import_scalar.getFieldMetaMap)(baseLightModelRef) : /* @__PURE__ */ new Map();
|
|
79
|
+
class BaseLightModel {
|
|
80
80
|
__ModelType__ = "light";
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
fieldMetaMap.set("id", idFieldMeta);
|
|
83
|
+
fieldMetaMap.set("createdAt", createdAtFieldMeta);
|
|
84
|
+
fieldMetaMap.set("updatedAt", updatedAtFieldMeta);
|
|
85
|
+
fieldMetaMap.set("removedAt", removedAtFieldMeta);
|
|
83
86
|
for (const field of fields) {
|
|
84
|
-
|
|
87
|
+
const fieldMeta = objectFieldMetaMap.get(field);
|
|
88
|
+
if (!fieldMeta)
|
|
89
|
+
throw new Error(`Field ${field} not found in objectRef`);
|
|
90
|
+
fieldMetaMap.set(field, fieldMeta);
|
|
85
91
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
Reflect.defineMetadata("fields", map, BaseGql.prototype);
|
|
90
|
-
return BaseGql;
|
|
92
|
+
(0, import_common.applyMixins)(BaseLightModel, libLightModelRefs);
|
|
93
|
+
Reflect.defineMetadata("fields", fieldMetaMap, BaseLightModel.prototype);
|
|
94
|
+
return BaseLightModel;
|
|
91
95
|
};
|
|
92
|
-
const fullModelOf = (modelRef, lightRef,
|
|
96
|
+
const fullModelOf = (modelRef, lightRef, ...libFullModelRefs) => {
|
|
93
97
|
const modelFieldMetaMap = (0, import_scalar.getFieldMetaMap)(modelRef);
|
|
94
98
|
const lightFieldMetaMap = (0, import_scalar.getFieldMetaMap)(lightRef);
|
|
95
|
-
(0, import_common.applyMixins)(modelRef, [lightRef]);
|
|
96
|
-
|
|
97
|
-
(0, import_common.applyMixins)(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (overwriteLightRef) {
|
|
101
|
-
(0, import_common.applyMixins)(overwriteLightRef, [lightRef]);
|
|
102
|
-
(0, import_scalar.setFieldMetaMap)(overwriteLightRef, lightFieldMetaMap);
|
|
103
|
-
}
|
|
104
|
-
(0, import_scalar.setFieldMetaMap)(modelRef, new Map([...modelFieldMetaMap, ...lightFieldMetaMap]));
|
|
99
|
+
(0, import_common.applyMixins)(modelRef, [...libFullModelRefs, lightRef]);
|
|
100
|
+
libFullModelRefs.forEach((libFullModelRef) => {
|
|
101
|
+
(0, import_common.applyMixins)(libFullModelRef, [lightRef, modelRef]);
|
|
102
|
+
});
|
|
103
|
+
lightFieldMetaMap.forEach((value, key) => modelFieldMetaMap.set(key, value));
|
|
105
104
|
return modelRef;
|
|
106
105
|
};
|
|
107
|
-
function via(modelRef, fieldsOrLightModelRef,
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
function via(modelRef, fieldsOrLightModelRef, ...fullOrLightModelRefs) {
|
|
107
|
+
const classMeta = (0, import_scalar.getClassMeta)(modelRef);
|
|
108
|
+
if (!fieldsOrLightModelRef) {
|
|
109
|
+
if (classMeta.type === "input") {
|
|
110
|
+
const objectRefName = classMeta.refName.slice(0, -5) + "Object";
|
|
111
|
+
const isFullModelRefDefined = (0, import_classMeta.getFullModelRefs)(objectRefName).length > 0;
|
|
112
|
+
if (isFullModelRefDefined)
|
|
113
|
+
return extendModelInputs(modelRef);
|
|
114
|
+
else
|
|
115
|
+
return baseModelOf(modelRef);
|
|
116
|
+
} else if (classMeta.modelType === "insight")
|
|
117
|
+
return extendModelInsights(modelRef);
|
|
118
|
+
else
|
|
119
|
+
throw new Error("Invalid modelRef args");
|
|
120
|
+
}
|
|
110
121
|
if (Array.isArray(fieldsOrLightModelRef))
|
|
111
|
-
return lightModelOf(modelRef, fieldsOrLightModelRef);
|
|
112
|
-
|
|
122
|
+
return lightModelOf(modelRef, fieldsOrLightModelRef, ...fullOrLightModelRefs);
|
|
123
|
+
const secondArgModelRef = fieldsOrLightModelRef;
|
|
124
|
+
const secondArgClassMeta = (0, import_scalar.getClassMeta)(secondArgModelRef);
|
|
125
|
+
if (classMeta.type === "input") {
|
|
126
|
+
if (secondArgClassMeta.type === "input")
|
|
127
|
+
return extendModelInputs(modelRef, secondArgModelRef, ...fullOrLightModelRefs);
|
|
128
|
+
else if (secondArgClassMeta.type === "full")
|
|
129
|
+
return extendModelObjects(modelRef, secondArgModelRef, ...fullOrLightModelRefs);
|
|
130
|
+
else
|
|
131
|
+
throw new Error("Invalid modelRef args");
|
|
132
|
+
} else if (classMeta.type === "full") {
|
|
133
|
+
if (secondArgClassMeta.type === "light")
|
|
134
|
+
return fullModelOf(modelRef, secondArgModelRef, ...fullOrLightModelRefs);
|
|
135
|
+
else
|
|
136
|
+
throw new Error("Invalid modelRef args");
|
|
137
|
+
} else if (classMeta.modelType === "insight")
|
|
138
|
+
return extendModelInsights(modelRef, secondArgModelRef, ...fullOrLightModelRefs);
|
|
139
|
+
else
|
|
140
|
+
throw new Error("Invalid modelRef");
|
|
113
141
|
}
|
|
142
|
+
const extendModelInputs = (...libInputModelRefs) => {
|
|
143
|
+
const baseInputModelRef = libInputModelRefs.at(0);
|
|
144
|
+
const fieldMetaMap = baseInputModelRef ? (0, import_scalar.getFieldMetaMap)(baseInputModelRef) : /* @__PURE__ */ new Map();
|
|
145
|
+
class BaseInput {
|
|
146
|
+
__ModelType__ = "input";
|
|
147
|
+
}
|
|
148
|
+
(0, import_scalar.setFieldMetaMap)(BaseInput, fieldMetaMap);
|
|
149
|
+
return BaseInput;
|
|
150
|
+
};
|
|
151
|
+
const extendModelObjects = (inputRef, ...libObjectModelRefs) => {
|
|
152
|
+
const baseObjectModelRef = libObjectModelRefs.at(0);
|
|
153
|
+
const inputFieldMetaMap = (0, import_scalar.getFieldMetaMap)(inputRef);
|
|
154
|
+
const fieldMetaMap = baseObjectModelRef ? (0, import_scalar.getFieldMetaMap)(baseObjectModelRef) : /* @__PURE__ */ new Map();
|
|
155
|
+
class BaseInput {
|
|
156
|
+
__ModelType__ = "object";
|
|
157
|
+
}
|
|
158
|
+
inputFieldMetaMap.forEach((value, key) => fieldMetaMap.set(key, value));
|
|
159
|
+
(0, import_scalar.setFieldMetaMap)(BaseInput, fieldMetaMap);
|
|
160
|
+
return BaseInput;
|
|
161
|
+
};
|
|
162
|
+
const extendModelInsights = (...insightModelRefs) => {
|
|
163
|
+
const baseInsightModelRef = insightModelRefs.at(0);
|
|
164
|
+
const insightFieldMetaMap = baseInsightModelRef ? (0, import_scalar.getFieldMetaMap)(baseInsightModelRef) : /* @__PURE__ */ new Map();
|
|
165
|
+
class BaseInsight {
|
|
166
|
+
__ModelType__ = "insight";
|
|
167
|
+
}
|
|
168
|
+
(0, import_scalar.setFieldMetaMap)(BaseInsight, insightFieldMetaMap);
|
|
169
|
+
return BaseInsight;
|
|
170
|
+
};
|
|
114
171
|
const addModelOf = (modelRef, ...types) => {
|
|
115
172
|
const modelMetadataMap = (0, import_scalar.getFieldMetaMap)(modelRef);
|
|
116
|
-
const metadataMap = types.
|
|
173
|
+
const metadataMap = types.reduce((acc, writeRef) => {
|
|
117
174
|
const writeMetadataMap = (0, import_scalar.getFieldMetaMap)(writeRef);
|
|
118
175
|
(0, import_common.applyMixins)(modelRef, [writeRef]);
|
|
119
176
|
return new Map([...acc, ...writeMetadataMap]);
|
|
@@ -125,7 +182,7 @@ const addFilterOf = (filterRef, ...types) => {
|
|
|
125
182
|
const filterMeta = (0, import_filterMeta.getFilterMeta)(filterRef);
|
|
126
183
|
const filterQueryMap = (0, import_filterMeta.getFilterQueryMap)(filterRef);
|
|
127
184
|
const metadataMap = new Map(
|
|
128
|
-
types.
|
|
185
|
+
types.reduce((acc, writeRef) => {
|
|
129
186
|
const writeMetadataMap = (0, import_filterMeta.getFilterQueryMap)(writeRef);
|
|
130
187
|
(0, import_common.applyMixins)(filterRef, [writeRef]);
|
|
131
188
|
writeMetadataMap.forEach((value, key) => {
|
|
@@ -143,25 +200,3 @@ const addFilterOf = (filterRef, ...types) => {
|
|
|
143
200
|
(0, import_filterMeta.setFilterMeta)(filterRef, { ...filterMeta, sort: filterSort });
|
|
144
201
|
return filterRef;
|
|
145
202
|
};
|
|
146
|
-
const from = (modelRef, ...types) => {
|
|
147
|
-
if ((0, import_scalar.isConstantModel)(modelRef))
|
|
148
|
-
return addModelOf(modelRef, ...types);
|
|
149
|
-
else if ((0, import_filterMeta.isFilterModel)(modelRef))
|
|
150
|
-
return addFilterOf(modelRef, ...types);
|
|
151
|
-
else
|
|
152
|
-
throw new Error("Invalid modelRef");
|
|
153
|
-
};
|
|
154
|
-
const mixModelOf = (...types) => {
|
|
155
|
-
class Mix {
|
|
156
|
-
}
|
|
157
|
-
const metadataMap = new Map(
|
|
158
|
-
types.reduce((acc, modelRef) => {
|
|
159
|
-
const modelMetadataMap = (0, import_scalar.getFieldMetaMap)(modelRef);
|
|
160
|
-
(0, import_common.applyMixins)(Mix, [modelRef]);
|
|
161
|
-
return [...acc, ...modelMetadataMap];
|
|
162
|
-
}, [])
|
|
163
|
-
);
|
|
164
|
-
(0, import_scalar.setFieldMetaMap)(Mix, metadataMap);
|
|
165
|
-
return Mix;
|
|
166
|
-
};
|
|
167
|
-
const over = mixModelOf;
|
package/cjs/src/classMeta.js
CHANGED
|
@@ -17,21 +17,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
var classMeta_exports = {};
|
|
19
19
|
__export(classMeta_exports, {
|
|
20
|
-
FilterModelStorage: () => FilterModelStorage,
|
|
21
|
-
FullModelStorage: () => FullModelStorage,
|
|
22
|
-
InputModelStorage: () => InputModelStorage,
|
|
23
|
-
LightModelStorage: () => LightModelStorage,
|
|
24
20
|
Model: () => Model,
|
|
25
|
-
ScalarModelStorage: () => ScalarModelStorage,
|
|
26
21
|
getAllFilterModelRefs: () => getAllFilterModelRefs,
|
|
27
22
|
getAllFullModelRefs: () => getAllFullModelRefs,
|
|
28
23
|
getAllScalarModelRefs: () => getAllScalarModelRefs,
|
|
29
24
|
getChildClassRefs: () => getChildClassRefs,
|
|
30
25
|
getFieldEnumMetas: () => getFieldEnumMetas,
|
|
31
26
|
getFullModelRef: () => getFullModelRef,
|
|
27
|
+
getFullModelRefs: () => getFullModelRefs,
|
|
32
28
|
getInputModelRef: () => getInputModelRef,
|
|
29
|
+
getInputModelRefs: () => getInputModelRefs,
|
|
33
30
|
getLightModelRef: () => getLightModelRef,
|
|
34
31
|
getScalarModelRef: () => getScalarModelRef,
|
|
32
|
+
getScalarModelRefs: () => getScalarModelRefs,
|
|
35
33
|
hasTextField: () => hasTextField
|
|
36
34
|
});
|
|
37
35
|
module.exports = __toCommonJS(classMeta_exports);
|
|
@@ -50,23 +48,38 @@ class ScalarModelStorage {
|
|
|
50
48
|
class FilterModelStorage {
|
|
51
49
|
}
|
|
52
50
|
const getFullModelRef = (refName) => {
|
|
53
|
-
const
|
|
51
|
+
const modelRefs = Reflect.getMetadata((0, import_common.capitalize)(refName), FullModelStorage.prototype);
|
|
52
|
+
const modelRef = modelRefs?.[0];
|
|
54
53
|
if (!modelRef)
|
|
55
54
|
throw new Error(`FullModel not found - ${refName}`);
|
|
56
55
|
return modelRef;
|
|
57
56
|
};
|
|
57
|
+
const getFullModelRefs = (refName) => {
|
|
58
|
+
const modelRefs = Reflect.getMetadata((0, import_common.capitalize)(refName), FullModelStorage.prototype);
|
|
59
|
+
return modelRefs ?? [];
|
|
60
|
+
};
|
|
58
61
|
const getInputModelRef = (refName) => {
|
|
59
|
-
const
|
|
62
|
+
const modelRefs = Reflect.getMetadata((0, import_common.capitalize)(refName), InputModelStorage.prototype);
|
|
63
|
+
const modelRef = modelRefs?.[0];
|
|
60
64
|
if (!modelRef)
|
|
61
65
|
throw new Error(`InputModel not found - ${refName}`);
|
|
62
66
|
return modelRef;
|
|
63
67
|
};
|
|
68
|
+
const getInputModelRefs = (refName) => {
|
|
69
|
+
const modelRefs = Reflect.getMetadata((0, import_common.capitalize)(refName), InputModelStorage.prototype);
|
|
70
|
+
return modelRefs ?? [];
|
|
71
|
+
};
|
|
64
72
|
const getScalarModelRef = (refName) => {
|
|
65
|
-
const
|
|
73
|
+
const modelRefs = Reflect.getMetadata((0, import_common.capitalize)(refName), ScalarModelStorage.prototype);
|
|
74
|
+
const modelRef = modelRefs?.[0];
|
|
66
75
|
if (!modelRef)
|
|
67
76
|
throw new Error(`ScalarModel not found - ${refName}`);
|
|
68
77
|
return modelRef;
|
|
69
78
|
};
|
|
79
|
+
const getScalarModelRefs = (refName) => {
|
|
80
|
+
const modelRefs = Reflect.getMetadata((0, import_common.capitalize)(refName), ScalarModelStorage.prototype);
|
|
81
|
+
return modelRefs ?? [];
|
|
82
|
+
};
|
|
70
83
|
const getChildClassRefs = (target) => {
|
|
71
84
|
const metadatas = (0, import_scalar.getFieldMetas)(target);
|
|
72
85
|
const refMap = /* @__PURE__ */ new Map();
|
|
@@ -92,7 +105,11 @@ const applyClassMeta = (type, modelType, storage) => {
|
|
|
92
105
|
const modelRef = target;
|
|
93
106
|
const classMeta = { refName, type, modelType, modelRef, hasTextField: hasTextField(modelRef) };
|
|
94
107
|
Reflect.defineMetadata("class", classMeta, modelRef.prototype);
|
|
95
|
-
Reflect.
|
|
108
|
+
const modelRefs = Reflect.getMetadata((0, import_common.capitalize)(refName), storage.prototype);
|
|
109
|
+
if (modelRefs)
|
|
110
|
+
modelRefs.push(modelRef);
|
|
111
|
+
else
|
|
112
|
+
Reflect.defineMetadata(refName, [modelRef], storage.prototype);
|
|
96
113
|
};
|
|
97
114
|
};
|
|
98
115
|
};
|
|
@@ -101,7 +118,11 @@ const applyFilterMeta = (storage) => {
|
|
|
101
118
|
return function(target) {
|
|
102
119
|
const modelRef = target;
|
|
103
120
|
(0, import_filterMeta.setFilterMeta)(modelRef, { refName, sort: {} });
|
|
104
|
-
Reflect.
|
|
121
|
+
const modelRefs = Reflect.getMetadata((0, import_common.capitalize)(refName), storage.prototype);
|
|
122
|
+
if (modelRefs)
|
|
123
|
+
modelRefs.push(modelRef);
|
|
124
|
+
else
|
|
125
|
+
Reflect.defineMetadata(refName, [modelRef], storage.prototype);
|
|
105
126
|
};
|
|
106
127
|
};
|
|
107
128
|
};
|
|
@@ -111,7 +132,6 @@ const Model = {
|
|
|
111
132
|
Full: applyClassMeta("full", "data", FullModelStorage),
|
|
112
133
|
Input: applyClassMeta("input", "data", InputModelStorage),
|
|
113
134
|
Scalar: applyClassMeta("scalar", "data", ScalarModelStorage),
|
|
114
|
-
Summary: applyClassMeta("scalar", "summary", ScalarModelStorage),
|
|
115
135
|
Insight: applyClassMeta("scalar", "insight", ScalarModelStorage),
|
|
116
136
|
Filter: applyFilterMeta(FilterModelStorage)
|
|
117
137
|
};
|
|
@@ -119,29 +139,24 @@ const getLightModelRef = (modelRef) => {
|
|
|
119
139
|
const classMeta = (0, import_scalar.getClassMeta)(modelRef);
|
|
120
140
|
if (classMeta.type !== "full")
|
|
121
141
|
return modelRef;
|
|
122
|
-
const
|
|
142
|
+
const lightModelRefs = Reflect.getMetadata(`Light${classMeta.refName}`, LightModelStorage.prototype);
|
|
143
|
+
const lightModelRef = lightModelRefs?.at(-1);
|
|
123
144
|
if (!lightModelRef)
|
|
124
145
|
throw new Error(`LightModel not found - ${classMeta.refName}`);
|
|
125
146
|
return lightModelRef;
|
|
126
147
|
};
|
|
127
148
|
const getAllFullModelRefs = () => {
|
|
128
149
|
const modelNames = Reflect.getMetadataKeys(FullModelStorage.prototype);
|
|
129
|
-
const modelRefs = modelNames.map(
|
|
130
|
-
(modelName) => Reflect.getMetadata(modelName, FullModelStorage.prototype)
|
|
131
|
-
);
|
|
150
|
+
const modelRefs = modelNames.map((modelName) => Reflect.getMetadata(modelName, FullModelStorage.prototype)).flat();
|
|
132
151
|
return modelRefs;
|
|
133
152
|
};
|
|
134
153
|
const getAllScalarModelRefs = () => {
|
|
135
154
|
const modelNames = Reflect.getMetadataKeys(ScalarModelStorage.prototype);
|
|
136
|
-
const modelRefs = modelNames.map(
|
|
137
|
-
(modelName) => Reflect.getMetadata(modelName, ScalarModelStorage.prototype)
|
|
138
|
-
);
|
|
155
|
+
const modelRefs = modelNames.map((modelName) => Reflect.getMetadata(modelName, ScalarModelStorage.prototype)).flat();
|
|
139
156
|
return modelRefs;
|
|
140
157
|
};
|
|
141
158
|
const getAllFilterModelRefs = () => {
|
|
142
159
|
const modelNames = Reflect.getMetadataKeys(FilterModelStorage.prototype);
|
|
143
|
-
const modelRefs = modelNames.map(
|
|
144
|
-
(modelName) => Reflect.getMetadata(modelName, FilterModelStorage.prototype)
|
|
145
|
-
);
|
|
160
|
+
const modelRefs = modelNames.map((modelName) => Reflect.getMetadata(modelName, FilterModelStorage.prototype)).flat();
|
|
146
161
|
return modelRefs;
|
|
147
162
|
};
|
|
@@ -34,7 +34,7 @@ const getCnstMeta = (refName) => {
|
|
|
34
34
|
throw new Error(`No cnst meta for ${refName}`);
|
|
35
35
|
return cnst;
|
|
36
36
|
};
|
|
37
|
-
const cnstOf = (refName, Input, Full, Light, Insight, Filter
|
|
37
|
+
const cnstOf = (refName, Input, Full, Light, Insight, Filter) => {
|
|
38
38
|
const cnst = {
|
|
39
39
|
refName,
|
|
40
40
|
Input,
|
|
@@ -42,7 +42,6 @@ const cnstOf = (refName, Input, Full, Light, Insight, Filter, Summary) => {
|
|
|
42
42
|
Light,
|
|
43
43
|
Insight,
|
|
44
44
|
Filter,
|
|
45
|
-
Summary,
|
|
46
45
|
_CapitalizedT: null,
|
|
47
46
|
_Default: null,
|
|
48
47
|
_DefaultInput: null,
|
package/cjs/src/fieldMeta.js
CHANGED
|
@@ -46,7 +46,6 @@ const applyFieldMeta = (modelRef, arrDepth, option, optionArrDepth) => {
|
|
|
46
46
|
select: option.select ?? true,
|
|
47
47
|
minlength: option.minlength,
|
|
48
48
|
maxlength: option.maxlength,
|
|
49
|
-
query: option.query,
|
|
50
49
|
accumulate: option.accumulate,
|
|
51
50
|
example: option.example,
|
|
52
51
|
validate: option.validate,
|
|
@@ -60,7 +59,8 @@ const applyFieldMeta = (modelRef, arrDepth, option, optionArrDepth) => {
|
|
|
60
59
|
optArrDepth: optionArrDepth,
|
|
61
60
|
isMap,
|
|
62
61
|
of: option.of,
|
|
63
|
-
text: option.text
|
|
62
|
+
text: option.text,
|
|
63
|
+
meta: option.meta ?? {}
|
|
64
64
|
};
|
|
65
65
|
const metadataMap = (0, import_scalar.getFieldMetaMapOnPrototype)(prototype);
|
|
66
66
|
metadataMap.set(key, metadata);
|
package/cjs/src/filterMeta.js
CHANGED
|
@@ -44,6 +44,7 @@ __export(filterMeta_exports, {
|
|
|
44
44
|
});
|
|
45
45
|
module.exports = __toCommonJS(filterMeta_exports);
|
|
46
46
|
var import_base = require("@akanjs/base");
|
|
47
|
+
var import_common = require("@akanjs/common");
|
|
47
48
|
var import_scalar = require("./scalar");
|
|
48
49
|
const isFilterModel = (filterRef) => {
|
|
49
50
|
return Reflect.getMetadata("filter", filterRef.prototype) !== void 0;
|
|
@@ -57,8 +58,9 @@ const getFilterMeta = (filterRef) => {
|
|
|
57
58
|
const setFilterMeta = (filterRef, filterMeta) => {
|
|
58
59
|
const existingFilterMeta = Reflect.getMetadata("filter", filterRef.prototype);
|
|
59
60
|
if (existingFilterMeta)
|
|
60
|
-
Object.assign(filterMeta.sort,
|
|
61
|
-
|
|
61
|
+
Object.assign(existingFilterMeta, { ...filterMeta, sort: { ...existingFilterMeta.sort, ...filterMeta.sort } });
|
|
62
|
+
else
|
|
63
|
+
Reflect.defineMetadata("filter", filterMeta, filterRef.prototype);
|
|
62
64
|
};
|
|
63
65
|
const getFilterKeyMetaMapOnPrototype = (prototype) => {
|
|
64
66
|
const metadataMap = Reflect.getMetadata("filterKey", prototype) ?? /* @__PURE__ */ new Map();
|
|
@@ -124,7 +126,7 @@ const Filter = {
|
|
|
124
126
|
// Meili: makeFilter({ fieldType: "hidden", nullable: true }),
|
|
125
127
|
Arg: applyFilterArgMeta
|
|
126
128
|
};
|
|
127
|
-
const sortOf = (modelRef, sort) => {
|
|
129
|
+
const sortOf = (modelRef, sort, ...libFilterRefs) => {
|
|
128
130
|
const fieldMetaMap = (0, import_scalar.getFieldMetaMap)(modelRef);
|
|
129
131
|
const statusFieldMeta = fieldMetaMap.get("status");
|
|
130
132
|
if (!statusFieldMeta)
|
|
@@ -151,6 +153,16 @@ const sortOf = (modelRef, sort) => {
|
|
|
151
153
|
refName: "BaseFilter",
|
|
152
154
|
sort: Object.assign({ latest: { createdAt: -1 }, oldest: { createdAt: 1 } }, sort)
|
|
153
155
|
});
|
|
156
|
+
(0, import_common.applyMixins)(BaseFilter2, libFilterRefs);
|
|
157
|
+
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(BaseFilter2.prototype);
|
|
158
|
+
libFilterRefs.forEach((libFilterRef) => {
|
|
159
|
+
const libFilterKeyMetaMap = getFilterKeyMetaMapOnPrototype(libFilterRef.prototype);
|
|
160
|
+
libFilterKeyMetaMap.forEach((value, key) => {
|
|
161
|
+
const libFilterArgMetas = getFilterArgMetas(libFilterRef, key);
|
|
162
|
+
filterKeyMetaMap.set(key, value);
|
|
163
|
+
setFilterArgMetasOnPrototype(BaseFilter2.prototype, key, libFilterArgMetas);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
154
166
|
return BaseFilter2;
|
|
155
167
|
};
|
|
156
168
|
function BaseFilter(modelRef, sort) {
|
package/cjs/src/scalar.js
CHANGED
|
@@ -23,7 +23,6 @@ __export(scalar_exports, {
|
|
|
23
23
|
getFieldMetaMapOnPrototype: () => getFieldMetaMapOnPrototype,
|
|
24
24
|
getFieldMetas: () => getFieldMetas,
|
|
25
25
|
getGqlTypeStr: () => getGqlTypeStr,
|
|
26
|
-
getQueryMap: () => getQueryMap,
|
|
27
26
|
getScalarExample: () => getScalarExample,
|
|
28
27
|
isConstantModel: () => isConstantModel,
|
|
29
28
|
scalarExampleMap: () => scalarExampleMap,
|
|
@@ -66,22 +65,16 @@ const isConstantModel = (modelRef) => {
|
|
|
66
65
|
const getFieldMetaMap = (modelRef) => {
|
|
67
66
|
const [target] = (0, import_base.getNonArrayModel)(modelRef);
|
|
68
67
|
const metadataMap = Reflect.getMetadata("fields", target.prototype) ?? /* @__PURE__ */ new Map();
|
|
69
|
-
return
|
|
68
|
+
return metadataMap;
|
|
70
69
|
};
|
|
71
70
|
const setFieldMetaMap = (modelRef, metadataMap) => {
|
|
72
71
|
const [target] = (0, import_base.getNonArrayModel)(modelRef);
|
|
73
|
-
Reflect.defineMetadata("fields",
|
|
72
|
+
Reflect.defineMetadata("fields", metadataMap, target.prototype);
|
|
74
73
|
};
|
|
75
74
|
const getFieldMetaMapOnPrototype = (prototype) => {
|
|
76
75
|
const metadataMap = Reflect.getMetadata("fields", prototype) ?? /* @__PURE__ */ new Map();
|
|
77
|
-
return
|
|
76
|
+
return metadataMap;
|
|
78
77
|
};
|
|
79
78
|
const setFieldMetaMapOnPrototype = (prototype, metadataMap) => {
|
|
80
|
-
Reflect.defineMetadata("fields",
|
|
81
|
-
};
|
|
82
|
-
const getQueryMap = (modelRef) => {
|
|
83
|
-
const fieldMetas = getFieldMetas(modelRef);
|
|
84
|
-
return Object.fromEntries(
|
|
85
|
-
fieldMetas.filter((fieldMeta) => !!fieldMeta.query).map((fieldMeta) => [fieldMeta.key, fieldMeta.query])
|
|
86
|
-
);
|
|
79
|
+
Reflect.defineMetadata("fields", metadataMap, prototype);
|
|
87
80
|
};
|
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,47 +57,105 @@ 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
|
-
|
|
67
|
+
fieldMetaMap.set("id", idFieldMeta);
|
|
68
|
+
fieldMetaMap.set("createdAt", createdAtFieldMeta);
|
|
69
|
+
fieldMetaMap.set("updatedAt", updatedAtFieldMeta);
|
|
70
|
+
fieldMetaMap.set("removedAt", removedAtFieldMeta);
|
|
66
71
|
for (const field of fields) {
|
|
67
|
-
|
|
72
|
+
const fieldMeta = objectFieldMetaMap.get(field);
|
|
73
|
+
if (!fieldMeta)
|
|
74
|
+
throw new Error(`Field ${field} not found in objectRef`);
|
|
75
|
+
fieldMetaMap.set(field, fieldMeta);
|
|
68
76
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
Reflect.defineMetadata("fields", map, BaseGql.prototype);
|
|
73
|
-
return BaseGql;
|
|
77
|
+
applyMixins(BaseLightModel, libLightModelRefs);
|
|
78
|
+
Reflect.defineMetadata("fields", fieldMetaMap, BaseLightModel.prototype);
|
|
79
|
+
return BaseLightModel;
|
|
74
80
|
};
|
|
75
|
-
const fullModelOf = (modelRef, lightRef,
|
|
81
|
+
const fullModelOf = (modelRef, lightRef, ...libFullModelRefs) => {
|
|
76
82
|
const modelFieldMetaMap = getFieldMetaMap(modelRef);
|
|
77
83
|
const lightFieldMetaMap = getFieldMetaMap(lightRef);
|
|
78
|
-
applyMixins(modelRef, [lightRef]);
|
|
79
|
-
|
|
80
|
-
applyMixins(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (overwriteLightRef) {
|
|
84
|
-
applyMixins(overwriteLightRef, [lightRef]);
|
|
85
|
-
setFieldMetaMap(overwriteLightRef, lightFieldMetaMap);
|
|
86
|
-
}
|
|
87
|
-
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));
|
|
88
89
|
return modelRef;
|
|
89
90
|
};
|
|
90
|
-
function via(modelRef, fieldsOrLightModelRef,
|
|
91
|
-
|
|
92
|
-
|
|
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
|
+
}
|
|
93
106
|
if (Array.isArray(fieldsOrLightModelRef))
|
|
94
|
-
return lightModelOf(modelRef, fieldsOrLightModelRef);
|
|
95
|
-
|
|
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);
|
|
124
|
+
else
|
|
125
|
+
throw new Error("Invalid modelRef");
|
|
96
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;
|
|
155
|
+
};
|
|
97
156
|
const addModelOf = (modelRef, ...types) => {
|
|
98
157
|
const modelMetadataMap = getFieldMetaMap(modelRef);
|
|
99
|
-
const metadataMap = types.
|
|
158
|
+
const metadataMap = types.reduce((acc, writeRef) => {
|
|
100
159
|
const writeMetadataMap = getFieldMetaMap(writeRef);
|
|
101
160
|
applyMixins(modelRef, [writeRef]);
|
|
102
161
|
return new Map([...acc, ...writeMetadataMap]);
|
|
@@ -108,7 +167,7 @@ const addFilterOf = (filterRef, ...types) => {
|
|
|
108
167
|
const filterMeta = getFilterMeta(filterRef);
|
|
109
168
|
const filterQueryMap = getFilterQueryMap(filterRef);
|
|
110
169
|
const metadataMap = new Map(
|
|
111
|
-
types.
|
|
170
|
+
types.reduce((acc, writeRef) => {
|
|
112
171
|
const writeMetadataMap = getFilterQueryMap(writeRef);
|
|
113
172
|
applyMixins(filterRef, [writeRef]);
|
|
114
173
|
writeMetadataMap.forEach((value, key) => {
|
|
@@ -126,32 +185,7 @@ const addFilterOf = (filterRef, ...types) => {
|
|
|
126
185
|
setFilterMeta(filterRef, { ...filterMeta, sort: filterSort });
|
|
127
186
|
return filterRef;
|
|
128
187
|
};
|
|
129
|
-
const from = (modelRef, ...types) => {
|
|
130
|
-
if (isConstantModel(modelRef))
|
|
131
|
-
return addModelOf(modelRef, ...types);
|
|
132
|
-
else if (isFilterModel(modelRef))
|
|
133
|
-
return addFilterOf(modelRef, ...types);
|
|
134
|
-
else
|
|
135
|
-
throw new Error("Invalid modelRef");
|
|
136
|
-
};
|
|
137
|
-
const mixModelOf = (...types) => {
|
|
138
|
-
class Mix {
|
|
139
|
-
}
|
|
140
|
-
const metadataMap = new Map(
|
|
141
|
-
types.reduce((acc, modelRef) => {
|
|
142
|
-
const modelMetadataMap = getFieldMetaMap(modelRef);
|
|
143
|
-
applyMixins(Mix, [modelRef]);
|
|
144
|
-
return [...acc, ...modelMetadataMap];
|
|
145
|
-
}, [])
|
|
146
|
-
);
|
|
147
|
-
setFieldMetaMap(Mix, metadataMap);
|
|
148
|
-
return Mix;
|
|
149
|
-
};
|
|
150
|
-
const over = mixModelOf;
|
|
151
188
|
export {
|
|
152
189
|
as,
|
|
153
|
-
from,
|
|
154
|
-
mixModelOf,
|
|
155
|
-
over,
|
|
156
190
|
via
|
|
157
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,7 +10,7 @@ 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
|
|
13
|
+
const cnstOf = (refName, Input, Full, Light, Insight, Filter) => {
|
|
14
14
|
const cnst = {
|
|
15
15
|
refName,
|
|
16
16
|
Input,
|
|
@@ -18,7 +18,6 @@ const cnstOf = (refName, Input, Full, Light, Insight, Filter, Summary) => {
|
|
|
18
18
|
Light,
|
|
19
19
|
Insight,
|
|
20
20
|
Filter,
|
|
21
|
-
Summary,
|
|
22
21
|
_CapitalizedT: null,
|
|
23
22
|
_Default: null,
|
|
24
23
|
_DefaultInput: null,
|
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/package.json
CHANGED
package/src/baseGql.d.ts
CHANGED
|
@@ -1,17 +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
5
|
type BaseFields = "id" | "createdAt" | "updatedAt" | "removedAt";
|
|
6
6
|
type OmitBase<T> = Omit<T, BaseFields>;
|
|
7
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>,
|
|
9
|
-
export declare function via<T, K extends NonFunctionalKeys<OmitBase<T
|
|
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>>>;
|
|
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>>;
|
|
17
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,15 +1,14 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import type { Type } from "@akanjs/base";
|
|
3
|
-
import type { DefaultOf, DocumentModel, FilterType,
|
|
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
|
-
Summary?: Type<Summary>;
|
|
13
12
|
_CapitalizedT: _CapitalizedT;
|
|
14
13
|
_Default: _Default;
|
|
15
14
|
_DefaultInput: _DefaultInput;
|
|
@@ -21,7 +20,7 @@ export interface ConstantModel<T extends string, Input, Full, Light, Insight, Fi
|
|
|
21
20
|
_Query: _Query;
|
|
22
21
|
_Sort: _Sort;
|
|
23
22
|
}
|
|
24
|
-
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>>;
|
|
25
24
|
export interface ScalarConstantModel<T extends string, Model, _Default = DefaultOf<Model>, _Doc = DocumentModel<Model>> {
|
|
26
25
|
refName: T;
|
|
27
26
|
Model: Type<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
|
};
|
package/src/scalar.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import { type Dayjs, type Enum, Float, type GqlScalar, ID, Int, JSON, type SingleFieldType, type Type, Upload } from "@akanjs/base";
|
|
3
3
|
import type { AccumulatorOperator } from "mongoose";
|
|
4
|
-
import { type
|
|
4
|
+
import { type SortType } from "./types";
|
|
5
5
|
export declare const scalarExampleMap: Map<MapConstructor | typeof Int | typeof Upload | typeof Float | typeof ID | typeof JSON | StringConstructor | BooleanConstructor | DateConstructor, string | number | boolean | object>;
|
|
6
6
|
export declare const getScalarExample: (ref: GqlScalar) => string | number | boolean | object | null;
|
|
7
7
|
export declare const getGqlTypeStr: (ref: GqlScalar) => string;
|
|
@@ -9,7 +9,7 @@ export interface ConstantClassMeta {
|
|
|
9
9
|
refName: string;
|
|
10
10
|
modelRef: any;
|
|
11
11
|
type: "input" | "full" | "light" | "scalar";
|
|
12
|
-
modelType: "data" | "ephemeral" | "
|
|
12
|
+
modelType: "data" | "ephemeral" | "insight";
|
|
13
13
|
hasTextField: boolean;
|
|
14
14
|
}
|
|
15
15
|
export interface ConstantFilterMeta {
|
|
@@ -40,7 +40,11 @@ export interface FilterArgMeta extends FilterArgProps {
|
|
|
40
40
|
export declare const fieldTypes: readonly ["email", "password", "url"];
|
|
41
41
|
export type FieldType = (typeof fieldTypes)[number];
|
|
42
42
|
export type ReturnType<T extends SingleFieldType = SingleFieldType> = (of?: any) => T | [T] | [[T]] | Map<string, any>;
|
|
43
|
-
export interface ConstantFieldProps {
|
|
43
|
+
export interface ConstantFieldProps<Metadata extends {
|
|
44
|
+
[key: string]: any;
|
|
45
|
+
} = {
|
|
46
|
+
[key: string]: any;
|
|
47
|
+
}> {
|
|
44
48
|
nullable?: boolean;
|
|
45
49
|
ref?: string;
|
|
46
50
|
refPath?: string;
|
|
@@ -55,14 +59,18 @@ export interface ConstantFieldProps {
|
|
|
55
59
|
select?: boolean;
|
|
56
60
|
minlength?: number;
|
|
57
61
|
maxlength?: number;
|
|
58
|
-
query?: QueryOf<any> | (() => QueryOf<any>);
|
|
59
62
|
accumulate?: AccumulatorOperator;
|
|
60
63
|
example?: string | number | boolean | Dayjs | string[] | number[] | boolean[] | Dayjs[];
|
|
61
64
|
of?: GqlScalar;
|
|
62
65
|
validate?: (value: any, model: any) => boolean;
|
|
63
66
|
text?: "search" | "filter";
|
|
67
|
+
meta?: Metadata;
|
|
64
68
|
}
|
|
65
|
-
export type ConstantFieldMeta
|
|
69
|
+
export type ConstantFieldMeta<Metadata extends {
|
|
70
|
+
[key: string]: any;
|
|
71
|
+
} = {
|
|
72
|
+
[key: string]: any;
|
|
73
|
+
}> = ConstantFieldProps<Metadata> & {
|
|
66
74
|
nullable: boolean;
|
|
67
75
|
default: any;
|
|
68
76
|
fieldType: "property" | "hidden" | "resolve";
|
|
@@ -78,6 +86,7 @@ export type ConstantFieldMeta = ConstantFieldProps & {
|
|
|
78
86
|
isArray: boolean;
|
|
79
87
|
optArrDepth: number;
|
|
80
88
|
isMap: boolean;
|
|
89
|
+
meta: Metadata;
|
|
81
90
|
};
|
|
82
91
|
export declare const getClassMeta: (modelRef: Type) => ConstantClassMeta;
|
|
83
92
|
export declare const getFieldMetas: (modelRef: Type) => ConstantFieldMeta[];
|
|
@@ -86,6 +95,3 @@ export declare const getFieldMetaMap: (modelRef: Type) => Map<string, ConstantFi
|
|
|
86
95
|
export declare const setFieldMetaMap: (modelRef: Type, metadataMap: Map<string, ConstantFieldMeta>) => void;
|
|
87
96
|
export declare const getFieldMetaMapOnPrototype: (prototype: object) => Map<string, ConstantFieldMeta>;
|
|
88
97
|
export declare const setFieldMetaMapOnPrototype: (prototype: object, metadataMap: Map<string, ConstantFieldMeta>) => void;
|
|
89
|
-
export declare const getQueryMap: (modelRef: Type) => {
|
|
90
|
-
[key: string]: QueryOf<any> | undefined | (() => QueryOf<any>);
|
|
91
|
-
};
|
package/src/types.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import { type BaseObject, Dayjs, enumOf } from "@akanjs/base";
|
|
1
|
+
import { type BaseObject, Dayjs, enumOf, type GetStateObject } from "@akanjs/base";
|
|
2
2
|
import type { FilterQuery, HydratedDocument, ProjectionType } from "mongoose";
|
|
3
3
|
export type { FilterQuery as QueryOf };
|
|
4
4
|
type ObjectToId<O> = O extends BaseObject ? string : O extends BaseObject[] ? string[] : O extends Dayjs ? Dayjs : O extends {
|
|
5
5
|
[key: string]: any;
|
|
6
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
7
|
type NullToUndefinedWithObjectToId<T, StateKeys extends keyof GetStateObject<T> = keyof GetStateObject<T>> = {
|
|
14
8
|
[K in StateKeys as null extends T[K] ? never : K]: ObjectToId<T[K]>;
|
|
15
9
|
} & {
|