@snowtop/ent 0.1.0-alpha121 → 0.1.0-alpha122

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-alpha122",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -63,6 +63,30 @@ class StructField extends field_1.BaseField {
63
63
  if (this.type.globalType) {
64
64
  const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
65
65
  if (f && f.format) {
66
+ if (JSON.stringify(this.type.listElemType) !==
67
+ JSON.stringify(f?.type.listElemType)) {
68
+ if (this.jsonAsList) {
69
+ // handle as nested
70
+ // @ts-ignore
71
+ const formatted = obj.map((v) => f.format(v, true));
72
+ if (nested) {
73
+ return formatted;
74
+ }
75
+ else {
76
+ return JSON.stringify(formatted);
77
+ }
78
+ }
79
+ else {
80
+ const formatted = f.format([obj], true);
81
+ if (nested) {
82
+ return formatted[0];
83
+ }
84
+ else {
85
+ return JSON.stringify(formatted[0]);
86
+ }
87
+ }
88
+ }
89
+ // TODO handle format code
66
90
  return f.format(obj);
67
91
  }
68
92
  }
@@ -113,7 +137,23 @@ class StructField extends field_1.BaseField {
113
137
  async valid(obj) {
114
138
  if (this.type.globalType) {
115
139
  const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
140
+ // list and global type is not valid. todo
116
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;
147
+ }
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
+ }
156
+ }
117
157
  return f.valid(obj);
118
158
  }
119
159
  return false;