@sprucelabs/schema 28.7.0 → 28.7.1
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.
|
@@ -14,6 +14,6 @@ export default class SchemaField<F extends SchemaFieldFieldDefinition = SchemaFi
|
|
|
14
14
|
static generateTemplateDetails(options: FieldTemplateDetailOptions<SchemaFieldFieldDefinition>): FieldTemplateDetails;
|
|
15
15
|
private static mapFieldDefinitionToSchemas;
|
|
16
16
|
validate(value: any, options?: ValidateOptions<SchemaFieldFieldDefinition>): FieldError[];
|
|
17
|
-
private
|
|
17
|
+
private Schema;
|
|
18
18
|
toValueType<CreateEntityInstances extends boolean>(value: any, options?: ToValueTypeOptions<SchemaFieldFieldDefinition, CreateEntityInstances>): FieldDefinitionValueType<F, CreateEntityInstances>;
|
|
19
19
|
}
|
|
@@ -195,7 +195,7 @@ export default class SchemaField extends AbstractField {
|
|
|
195
195
|
let instance;
|
|
196
196
|
if (schemas && schemas.length === 1) {
|
|
197
197
|
// @ts-ignore warns about infinite recursion, which is true, because relationships between schemas can go forever
|
|
198
|
-
instance = this.
|
|
198
|
+
instance = this.Schema(schemas[0], value);
|
|
199
199
|
}
|
|
200
200
|
else if (schemas && schemas.length > 0) {
|
|
201
201
|
const { schemaId, version, values } = value || {};
|
|
@@ -226,7 +226,7 @@ export default class SchemaField extends AbstractField {
|
|
|
226
226
|
});
|
|
227
227
|
}
|
|
228
228
|
else {
|
|
229
|
-
instance = this.
|
|
229
|
+
instance = this.Schema(matchSchema, values);
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
}
|
|
@@ -248,7 +248,7 @@ export default class SchemaField extends AbstractField {
|
|
|
248
248
|
}
|
|
249
249
|
return errors;
|
|
250
250
|
}
|
|
251
|
-
|
|
251
|
+
Schema(schema, value) {
|
|
252
252
|
return schema.dynamicFieldSignature
|
|
253
253
|
? new DynamicSchemaEntityImplementation(schema, value)
|
|
254
254
|
: new StaticSchemaEntity(schema, value);
|
|
@@ -275,7 +275,7 @@ export default class SchemaField extends AbstractField {
|
|
|
275
275
|
}
|
|
276
276
|
// if we are only pointing 1 one possible definition, then mapping is pretty easy
|
|
277
277
|
else if (!isUnion) {
|
|
278
|
-
instance = this.
|
|
278
|
+
instance = this.Schema(destinationSchemas[0], value);
|
|
279
279
|
}
|
|
280
280
|
else {
|
|
281
281
|
// this could be one of a few types, lets check the "schemaId" prop
|
|
@@ -305,21 +305,19 @@ export default class SchemaField extends AbstractField {
|
|
|
305
305
|
else {
|
|
306
306
|
matchedSchema = allMatches[0];
|
|
307
307
|
}
|
|
308
|
-
instance = this.
|
|
308
|
+
instance = this.Schema(matchedSchema, values);
|
|
309
309
|
}
|
|
310
310
|
if (createEntityInstances) {
|
|
311
311
|
return instance;
|
|
312
312
|
}
|
|
313
|
+
const getValueOptions = Object.assign({ validate: false }, options);
|
|
313
314
|
if (isUnion) {
|
|
314
315
|
return {
|
|
315
316
|
schemaId: instance.schemaId,
|
|
316
|
-
values: instance.getValues(
|
|
317
|
+
values: instance.getValues(getValueOptions),
|
|
317
318
|
};
|
|
318
319
|
}
|
|
319
|
-
return instance.getValues(
|
|
320
|
-
validate: false,
|
|
321
|
-
createEntityInstances,
|
|
322
|
-
});
|
|
320
|
+
return instance.getValues(getValueOptions);
|
|
323
321
|
}
|
|
324
322
|
}
|
|
325
323
|
function throwInvalidReferenceError(item) {
|
|
@@ -14,6 +14,6 @@ export default class SchemaField<F extends SchemaFieldFieldDefinition = SchemaFi
|
|
|
14
14
|
static generateTemplateDetails(options: FieldTemplateDetailOptions<SchemaFieldFieldDefinition>): FieldTemplateDetails;
|
|
15
15
|
private static mapFieldDefinitionToSchemas;
|
|
16
16
|
validate(value: any, options?: ValidateOptions<SchemaFieldFieldDefinition>): FieldError[];
|
|
17
|
-
private
|
|
17
|
+
private Schema;
|
|
18
18
|
toValueType<CreateEntityInstances extends boolean>(value: any, options?: ToValueTypeOptions<SchemaFieldFieldDefinition, CreateEntityInstances>): FieldDefinitionValueType<F, CreateEntityInstances>;
|
|
19
19
|
}
|
|
@@ -200,7 +200,7 @@ class SchemaField extends AbstractField_1.default {
|
|
|
200
200
|
let instance;
|
|
201
201
|
if (schemas && schemas.length === 1) {
|
|
202
202
|
// @ts-ignore warns about infinite recursion, which is true, because relationships between schemas can go forever
|
|
203
|
-
instance = this.
|
|
203
|
+
instance = this.Schema(schemas[0], value);
|
|
204
204
|
}
|
|
205
205
|
else if (schemas && schemas.length > 0) {
|
|
206
206
|
const { schemaId, version, values } = value || {};
|
|
@@ -231,7 +231,7 @@ class SchemaField extends AbstractField_1.default {
|
|
|
231
231
|
});
|
|
232
232
|
}
|
|
233
233
|
else {
|
|
234
|
-
instance = this.
|
|
234
|
+
instance = this.Schema(matchSchema, values);
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
}
|
|
@@ -253,7 +253,7 @@ class SchemaField extends AbstractField_1.default {
|
|
|
253
253
|
}
|
|
254
254
|
return errors;
|
|
255
255
|
}
|
|
256
|
-
|
|
256
|
+
Schema(schema, value) {
|
|
257
257
|
return schema.dynamicFieldSignature
|
|
258
258
|
? new DynamicSchemaEntityImplementation_1.default(schema, value)
|
|
259
259
|
: new StaticSchemaEntityImplementation_1.default(schema, value);
|
|
@@ -280,7 +280,7 @@ class SchemaField extends AbstractField_1.default {
|
|
|
280
280
|
}
|
|
281
281
|
// if we are only pointing 1 one possible definition, then mapping is pretty easy
|
|
282
282
|
else if (!isUnion) {
|
|
283
|
-
instance = this.
|
|
283
|
+
instance = this.Schema(destinationSchemas[0], value);
|
|
284
284
|
}
|
|
285
285
|
else {
|
|
286
286
|
// this could be one of a few types, lets check the "schemaId" prop
|
|
@@ -310,21 +310,19 @@ class SchemaField extends AbstractField_1.default {
|
|
|
310
310
|
else {
|
|
311
311
|
matchedSchema = allMatches[0];
|
|
312
312
|
}
|
|
313
|
-
instance = this.
|
|
313
|
+
instance = this.Schema(matchedSchema, values);
|
|
314
314
|
}
|
|
315
315
|
if (createEntityInstances) {
|
|
316
316
|
return instance;
|
|
317
317
|
}
|
|
318
|
+
const getValueOptions = Object.assign({ validate: false }, options);
|
|
318
319
|
if (isUnion) {
|
|
319
320
|
return {
|
|
320
321
|
schemaId: instance.schemaId,
|
|
321
|
-
values: instance.getValues(
|
|
322
|
+
values: instance.getValues(getValueOptions),
|
|
322
323
|
};
|
|
323
324
|
}
|
|
324
|
-
return instance.getValues(
|
|
325
|
-
validate: false,
|
|
326
|
-
createEntityInstances,
|
|
327
|
-
});
|
|
325
|
+
return instance.getValues(getValueOptions);
|
|
328
326
|
}
|
|
329
327
|
}
|
|
330
328
|
exports.default = SchemaField;
|