@trayio/commons 3.14.0-beta → 3.14.0

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.
@@ -8,7 +8,7 @@ export interface DynamicSchemaBrand {
8
8
  }
9
9
  export interface DynamicSchemaInterface {
10
10
  fromDynamicObject: (schemaObj: DynamicObject) => E.Either<Error, DynamicSchema>;
11
- validate: (schema: DynamicSchema, value: DynamicObject) => E.Either<Error, undefined>;
11
+ validate: (schema: DynamicSchema | DynamicObject, value: DynamicObject) => E.Either<Error, undefined>;
12
12
  }
13
13
  export declare const DynamicSchema: DynamicSchemaInterface;
14
14
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"DynamicSchema.d.ts","sourceRoot":"","sources":["../../src/dynamicschema/DynamicSchema.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,OAAO,EACN,aAAa,EAEb,MAAM,4BAA4B,CAAC;AAoBpC,QAAA,MAAM,2BAA2B,6EAKhC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAMzE,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,aAAa,EAAE,OAAO,MAAM,CAAC;CACtC;AAED,MAAM,WAAW,sBAAsB;IACtC,iBAAiB,EAAE,CAClB,SAAS,EAAE,aAAa,KACpB,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACpC,QAAQ,EAAE,CACT,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,aAAa,KAChB,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;CAChC;AAED,eAAO,MAAM,aAAa,EAAE,sBAkB3B,CAAC"}
1
+ {"version":3,"file":"DynamicSchema.d.ts","sourceRoot":"","sources":["../../src/dynamicschema/DynamicSchema.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,OAAO,EACN,aAAa,EAEb,MAAM,4BAA4B,CAAC;AAqBpC,QAAA,MAAM,2BAA2B,6EAKhC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAMzE,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,aAAa,EAAE,OAAO,MAAM,CAAC;CACtC;AAED,MAAM,WAAW,sBAAsB;IACtC,iBAAiB,EAAE,CAClB,SAAS,EAAE,aAAa,KACpB,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACpC,QAAQ,EAAE,CACT,MAAM,EAAE,aAAa,GAAG,aAAa,EACrC,KAAK,EAAE,aAAa,KAChB,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;CAChC;AAED,eAAO,MAAM,aAAa,EAAE,sBAuB3B,CAAC"}
@@ -34,6 +34,7 @@ const t = __importStar(require("io-ts"));
34
34
  const function_1 = require("fp-ts/function");
35
35
  const DynamicType_1 = require("../dynamictype/DynamicType");
36
36
  const TypeCodec_1 = require("../codec/TypeCodec");
37
+ const Try_1 = require("../try/Try");
37
38
  const ajv = new ajv_draft_04_1.default();
38
39
  /*
39
40
  We define additional formats for the JSON schema
@@ -54,10 +55,12 @@ const dynamicSchemaTypeCodec = TypeCodec_1.TypeCodec.fromDescriptor(dynamicSchem
54
55
  exports.DynamicSchema = {
55
56
  fromDynamicObject: (schemaObj) => (0, function_1.pipe)(dynamicSchemaTypeCodec.decode(schemaObj), E.mapLeft((e) => new Error(`Failed to create DynamicSchema: ${e}`))),
56
57
  validate: (schema, value) => {
57
- const validate = ajv.compile(schema);
58
- if (validate(value)) {
59
- return E.right(undefined);
60
- }
61
- return E.left(new Error(ajv.errorsText(validate.errors)));
58
+ const validateE = (0, Try_1.tryToEither)(() => ajv.compile(schema));
59
+ return (0, function_1.pipe)(validateE, E.chain((validate) => {
60
+ if (validate(value)) {
61
+ return E.right(undefined);
62
+ }
63
+ return E.left(new Error(ajv.errorsText(validate.errors)));
64
+ }));
62
65
  },
63
66
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/commons",
3
- "version": "3.14.0-beta",
3
+ "version": "3.14.0",
4
4
  "description": "Extensions to the standard/core libraries and basic features",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"