@snowtop/ent 0.1.10 → 0.1.11
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/schema/struct_field.d.ts +4 -1
- package/schema/struct_field.js +11 -1
package/package.json
CHANGED
package/schema/struct_field.d.ts
CHANGED
|
@@ -6,10 +6,13 @@ interface structFieldOptions extends FieldOptions {
|
|
|
6
6
|
graphQLType?: string;
|
|
7
7
|
jsonNotJSONB?: boolean;
|
|
8
8
|
}
|
|
9
|
+
interface structFieldListOptions extends structFieldOptions {
|
|
10
|
+
validateUniqueKey?: string;
|
|
11
|
+
}
|
|
9
12
|
interface GlobalStructOptions extends FieldOptions {
|
|
10
13
|
globalType: string;
|
|
11
14
|
}
|
|
12
|
-
export type StructOptions = structFieldOptions | GlobalStructOptions;
|
|
15
|
+
export type StructOptions = structFieldOptions | GlobalStructOptions | structFieldListOptions;
|
|
13
16
|
export declare class StructField extends BaseField implements Field {
|
|
14
17
|
private options;
|
|
15
18
|
private jsonAsList?;
|
package/schema/struct_field.js
CHANGED
|
@@ -168,7 +168,17 @@ class StructField extends field_1.BaseField {
|
|
|
168
168
|
if (!Array.isArray(obj)) {
|
|
169
169
|
return false;
|
|
170
170
|
}
|
|
171
|
-
const
|
|
171
|
+
const unique = new Set();
|
|
172
|
+
const valid = await Promise.all(obj.map((v) => {
|
|
173
|
+
if (this.options.validateUniqueKey) {
|
|
174
|
+
const value = v[this.options.validateUniqueKey];
|
|
175
|
+
if (unique.has(value)) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
unique.add(value);
|
|
179
|
+
}
|
|
180
|
+
return this.validImpl(v);
|
|
181
|
+
}));
|
|
172
182
|
return valid.every((b) => b);
|
|
173
183
|
}
|
|
174
184
|
if (!(obj instanceof Object)) {
|