@snowtop/ent 0.1.0-alpha122 → 0.1.0-alpha123
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/package.json +1 -1
- package/parse_schema/parse.d.ts +1 -1
- package/parse_schema/parse.js +3 -2
- package/schema/field.js +19 -6
- package/schema/struct_field.js +22 -16
package/package.json
CHANGED
package/parse_schema/parse.d.ts
CHANGED
package/parse_schema/parse.js
CHANGED
|
@@ -358,9 +358,10 @@ async function parseGlobalSchema(s) {
|
|
|
358
358
|
const ret = {
|
|
359
359
|
globalEdges: [],
|
|
360
360
|
extraEdgeFields: [],
|
|
361
|
-
|
|
361
|
+
init: !!s.extraEdgeFields ||
|
|
362
362
|
s.transformEdgeRead !== undefined ||
|
|
363
|
-
s.transformEdgeWrite !== undefined
|
|
363
|
+
s.transformEdgeWrite !== undefined ||
|
|
364
|
+
s.fields !== undefined,
|
|
364
365
|
};
|
|
365
366
|
if (s.extraEdgeFields) {
|
|
366
367
|
ret.extraEdgeFields = await processFields(s.extraEdgeFields);
|
package/schema/field.js
CHANGED
|
@@ -32,6 +32,7 @@ const base_1 = require("../core/base");
|
|
|
32
32
|
const db_1 = __importStar(require("../core/db"));
|
|
33
33
|
const schema_1 = require("./schema");
|
|
34
34
|
const global_schema_1 = require("../core/global_schema");
|
|
35
|
+
const logger_1 = require("../core/logger");
|
|
35
36
|
class BaseField {
|
|
36
37
|
logValue(val) {
|
|
37
38
|
if (this.sensitive) {
|
|
@@ -568,10 +569,16 @@ class EnumField extends BaseField {
|
|
|
568
569
|
async valid(val) {
|
|
569
570
|
if (this.type.globalType) {
|
|
570
571
|
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
571
|
-
if (f
|
|
572
|
-
|
|
572
|
+
if (f) {
|
|
573
|
+
if (f.valid) {
|
|
574
|
+
return f.valid(val);
|
|
575
|
+
}
|
|
576
|
+
return true;
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
(0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
|
|
580
|
+
return false;
|
|
573
581
|
}
|
|
574
|
-
return false;
|
|
575
582
|
}
|
|
576
583
|
// lookup table enum and indicated via presence of foreignKey
|
|
577
584
|
if (!this.values && !this.map) {
|
|
@@ -648,10 +655,16 @@ class IntegerEnumField extends BaseField {
|
|
|
648
655
|
async valid(val) {
|
|
649
656
|
if (this.type?.globalType) {
|
|
650
657
|
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
651
|
-
if (f
|
|
652
|
-
|
|
658
|
+
if (f) {
|
|
659
|
+
if (f.valid) {
|
|
660
|
+
return f.valid(val);
|
|
661
|
+
}
|
|
662
|
+
return true;
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
(0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
|
|
666
|
+
return false;
|
|
653
667
|
}
|
|
654
|
-
return false;
|
|
655
668
|
}
|
|
656
669
|
// lookup table enum and indicated via presence of foreignKey
|
|
657
670
|
for (const k in this.map) {
|
package/schema/struct_field.js
CHANGED
|
@@ -5,6 +5,7 @@ const camel_case_1 = require("camel-case");
|
|
|
5
5
|
const field_1 = require("./field");
|
|
6
6
|
const schema_1 = require("./schema");
|
|
7
7
|
const global_schema_1 = require("../core/global_schema");
|
|
8
|
+
const logger_1 = require("../core/logger");
|
|
8
9
|
class StructField extends field_1.BaseField {
|
|
9
10
|
constructor(options, jsonAsList) {
|
|
10
11
|
super();
|
|
@@ -137,26 +138,31 @@ class StructField extends field_1.BaseField {
|
|
|
137
138
|
async valid(obj) {
|
|
138
139
|
if (this.type.globalType) {
|
|
139
140
|
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
140
|
-
// list and global type is not valid.
|
|
141
|
-
if (f
|
|
142
|
-
if (
|
|
143
|
-
JSON.stringify(
|
|
144
|
-
|
|
145
|
-
if (
|
|
146
|
-
|
|
141
|
+
// list and global type is not valid.
|
|
142
|
+
if (f) {
|
|
143
|
+
if (f.valid) {
|
|
144
|
+
if (JSON.stringify(this.type.listElemType) !==
|
|
145
|
+
JSON.stringify(f?.type.listElemType)) {
|
|
146
|
+
if (this.jsonAsList) {
|
|
147
|
+
if (!Array.isArray(obj)) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
const valid = await Promise.all(obj.map((v) => f.valid(v)));
|
|
152
|
+
return valid.every((b) => b);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
return f.valid([obj]);
|
|
147
156
|
}
|
|
148
|
-
// @ts-ignore
|
|
149
|
-
const valid = await Promise.all(obj.map((v) => f.valid(v)));
|
|
150
|
-
return valid.every((b) => b);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
// TODO handle test
|
|
154
|
-
return f.valid([obj]);
|
|
155
157
|
}
|
|
158
|
+
return f.valid(obj);
|
|
156
159
|
}
|
|
157
|
-
return
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
(0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
|
|
164
|
+
return false;
|
|
158
165
|
}
|
|
159
|
-
return false;
|
|
160
166
|
}
|
|
161
167
|
if (this.jsonAsList) {
|
|
162
168
|
if (!Array.isArray(obj)) {
|