@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha122",
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();
@@ -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. todo
141
- if (f && f.valid) {
142
- if (JSON.stringify(this.type.listElemType) !==
143
- JSON.stringify(f?.type.listElemType)) {
144
- if (this.jsonAsList) {
145
- if (!Array.isArray(obj)) {
146
- return false;
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 f.valid(obj);
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)) {