@snowtop/ent 0.1.0-alpha121 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha121",
3
+ "version": "0.1.0-alpha123",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -83,7 +83,7 @@ interface RomeConfig {
83
83
  interface ProcessedGlobalSchema {
84
84
  globalEdges: ProcessedAssocEdge[];
85
85
  extraEdgeFields: ProcessedField[];
86
- initForEdges?: boolean;
86
+ init?: boolean;
87
87
  globalFields?: ProcessedField[];
88
88
  }
89
89
  export {};
@@ -358,9 +358,10 @@ async function parseGlobalSchema(s) {
358
358
  const ret = {
359
359
  globalEdges: [],
360
360
  extraEdgeFields: [],
361
- initForEdges: !!s.extraEdgeFields ||
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 && f.valid) {
572
- return f.valid(val);
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 && f.valid) {
652
- return f.valid(val);
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) {
@@ -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();
@@ -63,6 +64,30 @@ class StructField extends field_1.BaseField {
63
64
  if (this.type.globalType) {
64
65
  const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
65
66
  if (f && f.format) {
67
+ if (JSON.stringify(this.type.listElemType) !==
68
+ JSON.stringify(f?.type.listElemType)) {
69
+ if (this.jsonAsList) {
70
+ // handle as nested
71
+ // @ts-ignore
72
+ const formatted = obj.map((v) => f.format(v, true));
73
+ if (nested) {
74
+ return formatted;
75
+ }
76
+ else {
77
+ return JSON.stringify(formatted);
78
+ }
79
+ }
80
+ else {
81
+ const formatted = f.format([obj], true);
82
+ if (nested) {
83
+ return formatted[0];
84
+ }
85
+ else {
86
+ return JSON.stringify(formatted[0]);
87
+ }
88
+ }
89
+ }
90
+ // TODO handle format code
66
91
  return f.format(obj);
67
92
  }
68
93
  }
@@ -113,10 +138,31 @@ class StructField extends field_1.BaseField {
113
138
  async valid(obj) {
114
139
  if (this.type.globalType) {
115
140
  const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
116
- if (f && f.valid) {
117
- return f.valid(obj);
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]);
156
+ }
157
+ }
158
+ return f.valid(obj);
159
+ }
160
+ return true;
161
+ }
162
+ else {
163
+ (0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
164
+ return false;
118
165
  }
119
- return false;
120
166
  }
121
167
  if (this.jsonAsList) {
122
168
  if (!Array.isArray(obj)) {