@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/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,56 +72,117 @@ 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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
fieldMetaMap.set("id", idFieldMeta);
|
|
83
|
+
fieldMetaMap.set("createdAt", createdAtFieldMeta);
|
|
84
|
+
fieldMetaMap.set("updatedAt", updatedAtFieldMeta);
|
|
85
|
+
fieldMetaMap.set("removedAt", removedAtFieldMeta);
|
|
86
|
+
for (const field of fields) {
|
|
87
|
+
const fieldMeta = objectFieldMetaMap.get(field);
|
|
88
|
+
if (!fieldMeta)
|
|
89
|
+
throw new Error(`Field ${field} not found in objectRef`);
|
|
90
|
+
fieldMetaMap.set(field, fieldMeta);
|
|
91
|
+
}
|
|
92
|
+
(0, import_common.applyMixins)(BaseLightModel, libLightModelRefs);
|
|
93
|
+
Reflect.defineMetadata("fields", fieldMetaMap, BaseLightModel.prototype);
|
|
94
|
+
return BaseLightModel;
|
|
85
95
|
};
|
|
86
|
-
const fullModelOf = (modelRef, lightRef,
|
|
96
|
+
const fullModelOf = (modelRef, lightRef, ...libFullModelRefs) => {
|
|
87
97
|
const modelFieldMetaMap = (0, import_scalar.getFieldMetaMap)(modelRef);
|
|
88
98
|
const lightFieldMetaMap = (0, import_scalar.getFieldMetaMap)(lightRef);
|
|
89
|
-
(0, import_common.applyMixins)(modelRef, [lightRef]);
|
|
90
|
-
|
|
91
|
-
(0, import_common.applyMixins)(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (overwriteLightRef) {
|
|
95
|
-
(0, import_common.applyMixins)(overwriteLightRef, [lightRef]);
|
|
96
|
-
(0, import_scalar.setFieldMetaMap)(overwriteLightRef, lightFieldMetaMap);
|
|
97
|
-
}
|
|
98
|
-
(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));
|
|
99
104
|
return modelRef;
|
|
100
105
|
};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
+
}
|
|
121
|
+
if (Array.isArray(fieldsOrLightModelRef))
|
|
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);
|
|
106
139
|
else
|
|
107
|
-
|
|
140
|
+
throw new Error("Invalid modelRef");
|
|
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;
|
|
108
170
|
};
|
|
109
|
-
const addModelOf = (modelRef,
|
|
171
|
+
const addModelOf = (modelRef, ...types) => {
|
|
110
172
|
const modelMetadataMap = (0, import_scalar.getFieldMetaMap)(modelRef);
|
|
111
|
-
const metadataMap =
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}, modelMetadataMap)
|
|
117
|
-
);
|
|
173
|
+
const metadataMap = types.reduce((acc, writeRef) => {
|
|
174
|
+
const writeMetadataMap = (0, import_scalar.getFieldMetaMap)(writeRef);
|
|
175
|
+
(0, import_common.applyMixins)(modelRef, [writeRef]);
|
|
176
|
+
return new Map([...acc, ...writeMetadataMap]);
|
|
177
|
+
}, modelMetadataMap);
|
|
118
178
|
(0, import_scalar.setFieldMetaMap)(modelRef, metadataMap);
|
|
119
179
|
return modelRef;
|
|
120
180
|
};
|
|
121
|
-
const addFilterOf = (filterRef,
|
|
181
|
+
const addFilterOf = (filterRef, ...types) => {
|
|
122
182
|
const filterMeta = (0, import_filterMeta.getFilterMeta)(filterRef);
|
|
123
183
|
const filterQueryMap = (0, import_filterMeta.getFilterQueryMap)(filterRef);
|
|
124
184
|
const metadataMap = new Map(
|
|
125
|
-
|
|
185
|
+
types.reduce((acc, writeRef) => {
|
|
126
186
|
const writeMetadataMap = (0, import_filterMeta.getFilterQueryMap)(writeRef);
|
|
127
187
|
(0, import_common.applyMixins)(filterRef, [writeRef]);
|
|
128
188
|
writeMetadataMap.forEach((value, key) => {
|
|
@@ -132,7 +192,7 @@ const addFilterOf = (filterRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => {
|
|
|
132
192
|
return new Map([...acc, ...writeMetadataMap]);
|
|
133
193
|
}, filterQueryMap)
|
|
134
194
|
);
|
|
135
|
-
const filterSort =
|
|
195
|
+
const filterSort = types.filter(Boolean).map((t) => (0, import_filterMeta.getFilterSortMap)(t)).reduce((acc, sort) => {
|
|
136
196
|
Object.assign(acc, sort);
|
|
137
197
|
return acc;
|
|
138
198
|
}, filterMeta.sort);
|
|
@@ -140,25 +200,3 @@ const addFilterOf = (filterRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => {
|
|
|
140
200
|
(0, import_filterMeta.setFilterMeta)(filterRef, { ...filterMeta, sort: filterSort });
|
|
141
201
|
return filterRef;
|
|
142
202
|
};
|
|
143
|
-
const from = (modelRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) => {
|
|
144
|
-
if ((0, import_scalar.isConstantModel)(modelRef))
|
|
145
|
-
return addModelOf(modelRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10);
|
|
146
|
-
else if ((0, import_filterMeta.isFilterModel)(modelRef))
|
|
147
|
-
return addFilterOf(modelRef, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10);
|
|
148
|
-
else
|
|
149
|
-
throw new Error("Invalid modelRef");
|
|
150
|
-
};
|
|
151
|
-
const mixModelOf = (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20) => {
|
|
152
|
-
class Mix {
|
|
153
|
-
}
|
|
154
|
-
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) => {
|
|
156
|
-
const modelMetadataMap = (0, import_scalar.getFieldMetaMap)(modelRef);
|
|
157
|
-
(0, import_common.applyMixins)(Mix, [modelRef]);
|
|
158
|
-
return [...acc, ...modelMetadataMap];
|
|
159
|
-
}, [])
|
|
160
|
-
);
|
|
161
|
-
(0, import_scalar.setFieldMetaMap)(Mix, metadataMap);
|
|
162
|
-
return Mix;
|
|
163
|
-
};
|
|
164
|
-
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
|
};
|
|
@@ -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");
|
|
@@ -33,8 +34,34 @@ const getCnstMeta = (refName) => {
|
|
|
33
34
|
throw new Error(`No cnst meta for ${refName}`);
|
|
34
35
|
return cnst;
|
|
35
36
|
};
|
|
36
|
-
const cnstOf = (refName, Input, Full, Light, Insight, Filter
|
|
37
|
-
const cnst = {
|
|
37
|
+
const cnstOf = (refName, Input, Full, Light, Insight, Filter) => {
|
|
38
|
+
const cnst = {
|
|
39
|
+
refName,
|
|
40
|
+
Input,
|
|
41
|
+
Full,
|
|
42
|
+
Light,
|
|
43
|
+
Insight,
|
|
44
|
+
Filter,
|
|
45
|
+
_CapitalizedT: null,
|
|
46
|
+
_Default: null,
|
|
47
|
+
_DefaultInput: null,
|
|
48
|
+
_DefaultState: null,
|
|
49
|
+
_DefaultStateInput: null,
|
|
50
|
+
_Doc: null,
|
|
51
|
+
_DocInput: null,
|
|
52
|
+
_QueryOfDoc: null,
|
|
53
|
+
_Query: null,
|
|
54
|
+
_Sort: null
|
|
55
|
+
};
|
|
38
56
|
setCnstMeta(refName, cnst);
|
|
39
57
|
return cnst;
|
|
40
58
|
};
|
|
59
|
+
const scalarCnstOf = (refName, Model) => {
|
|
60
|
+
const cnst = {
|
|
61
|
+
refName,
|
|
62
|
+
Model,
|
|
63
|
+
_Default: null,
|
|
64
|
+
_Doc: null
|
|
65
|
+
};
|
|
66
|
+
return cnst;
|
|
67
|
+
};
|
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/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;
|