@trayio/commons 4.8.1 → 4.9.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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=RemoveNullValuesCodec.unit.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RemoveNullValuesCodec.unit.test.d.ts","sourceRoot":"","sources":["../../src/codec/RemoveNullValuesCodec.unit.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const RemoveNullValuesCodec_1 = require("./RemoveNullValuesCodec");
4
+ const testRemoveNullValuesCodec = RemoveNullValuesCodec_1.RemoveNullValuesCodec.instance;
5
+ describe('RemoveNullValuesCodec', () => {
6
+ test('should remove null values', () => {
7
+ const value = {
8
+ firtName: 'blah',
9
+ lastName: null,
10
+ addresses: [
11
+ {
12
+ street: 'blah street',
13
+ number: 123,
14
+ city: {
15
+ name: 'London',
16
+ province: null,
17
+ state: null,
18
+ },
19
+ notes: 'blah blah blah',
20
+ },
21
+ {
22
+ street: 'blah blah street',
23
+ number: 321,
24
+ city: {
25
+ name: 'New York',
26
+ province: null,
27
+ state: 'NY',
28
+ },
29
+ notes: null,
30
+ },
31
+ ],
32
+ phone: {
33
+ areaCode: null,
34
+ number: 1234567,
35
+ },
36
+ };
37
+ const actualValue = testRemoveNullValuesCodec.encode(value);
38
+ const expectedValue = {
39
+ firtName: 'blah',
40
+ addresses: [
41
+ {
42
+ street: 'blah street',
43
+ number: 123,
44
+ city: {
45
+ name: 'London',
46
+ },
47
+ notes: 'blah blah blah',
48
+ },
49
+ {
50
+ street: 'blah blah street',
51
+ number: 321,
52
+ city: {
53
+ name: 'New York',
54
+ state: 'NY',
55
+ },
56
+ },
57
+ ],
58
+ phone: {
59
+ number: 1234567,
60
+ },
61
+ };
62
+ expect(actualValue).toEqual(expectedValue);
63
+ });
64
+ });
@@ -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,cAAc,CAAC;AAClC,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAG3B,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;AA4CzE,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,aAAa,EAAE,OAAO,MAAM,CAAC;CACtC;AAED,MAAM,WAAW,sBAAsB;IACtC,iBAAiB,EAAE,CAClB,MAAM,EAAE,aAAa,EACrB,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KACtB,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACpC,QAAQ,EAAE,CACT,MAAM,EAAE,aAAa,GAAG,aAAa,EACrC,KAAK,EAAE,aAAa,EACpB,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KACtB,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;CACpC;AAED,eAAO,MAAM,aAAa,EAAE,sBA+B3B,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,cAAc,CAAC;AAClC,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAG3B,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;AA4CzE,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,aAAa,EAAE,OAAO,MAAM,CAAC;CACtC;AAED,MAAM,WAAW,sBAAsB;IACtC,iBAAiB,EAAE,CAClB,MAAM,EAAE,aAAa,EACrB,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KACtB,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACpC,QAAQ,EAAE,CACT,MAAM,EAAE,aAAa,GAAG,aAAa,EACrC,KAAK,EAAE,aAAa,EACpB,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KACtB,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;CACpC;AAED,eAAO,MAAM,aAAa,EAAE,sBAkC3B,CAAC"}
@@ -101,7 +101,10 @@ exports.DynamicSchema = {
101
101
  if (validate(copiedValue)) {
102
102
  return E.right(copiedValue);
103
103
  }
104
- return E.left(new Error(ajv.errorsText(validate.errors)));
104
+ const errorText = ajv
105
+ .errorsText(validate.errors)
106
+ .replace(/data\//g, '');
107
+ return E.left(new Error(errorText));
105
108
  }));
106
109
  },
107
110
  };
@@ -31,6 +31,7 @@ describe('DynamicSchema', () => {
31
31
  let invalidSchema;
32
32
  let value;
33
33
  let valueWithExtraFields;
34
+ let invalidValue;
34
35
  beforeEach(() => {
35
36
  validSchema = {
36
37
  type: 'object',
@@ -58,6 +59,7 @@ describe('DynamicSchema', () => {
58
59
  },
59
60
  },
60
61
  },
62
+ required: ['name', 'car'],
61
63
  },
62
64
  },
63
65
  },
@@ -103,6 +105,15 @@ describe('DynamicSchema', () => {
103
105
  },
104
106
  ],
105
107
  };
108
+ invalidValue = {
109
+ name: 'John Doe',
110
+ age: '30',
111
+ races: [
112
+ {
113
+ name: 'monza',
114
+ },
115
+ ],
116
+ };
106
117
  });
107
118
  describe('fromDynamicObject', () => {
108
119
  it('should return a Right DynamicSchema when given a valid schema object', () => {
@@ -254,6 +265,7 @@ describe('DynamicSchema', () => {
254
265
  items: {
255
266
  type: 'object',
256
267
  additionalProperties: false,
268
+ required: ['name', 'car'],
257
269
  properties: {
258
270
  name: {
259
271
  type: 'string',
@@ -531,7 +543,7 @@ describe('DynamicSchema', () => {
531
543
  it('should return a Left Error when the value does not match the schema', () => {
532
544
  const schema = DynamicSchema_1.DynamicSchema.fromDynamicObject(validSchema);
533
545
  if (E.isRight(schema)) {
534
- const result = DynamicSchema_1.DynamicSchema.validate(schema.right, invalidSchema, O.none);
546
+ const result = DynamicSchema_1.DynamicSchema.validate(schema.right, invalidValue, O.none);
535
547
  expect(E.isLeft(result)).toBe(true);
536
548
  if (E.isLeft(result)) {
537
549
  expect(result.left).toBeInstanceOf(Error);
@@ -7,6 +7,11 @@ export type DynamicObject = {
7
7
  [x: string]: DynamicType;
8
8
  };
9
9
  export type DynamicArray = Array<DynamicType>;
10
+ export interface DynamicObjectInterface {
11
+ fromBase64String: (base64Str: string) => E.Either<Error, DynamicObject>;
12
+ removeNullValues: (value: DynamicObject) => DynamicObject;
13
+ }
14
+ export declare const DynamicObject: DynamicObjectInterface;
10
15
  export interface DynamicTypeInterface {
11
16
  readFromFile: (path: string) => E.Either<Error, DynamicType>;
12
17
  writeToFile: (path: string, value: DynamicType) => E.Either<Error, undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"DynamicType.d.ts","sourceRoot":"","sources":["../../src/dynamictype/DynamicType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGvC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,MAAM,MAAM,WAAW,GACpB,MAAM,GACN,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AAO,MAAM,2BAA2B,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAG7D,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAG3D,CAAC"}
@@ -23,14 +23,23 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.dynamicArrayTypeDescriptor = exports.dynamicObjectTypeDescriptor = exports.dynamicTypeDescriptor = exports.DynamicType = void 0;
26
+ exports.dynamicArrayTypeDescriptor = exports.dynamicObjectTypeDescriptor = exports.dynamicTypeDescriptor = exports.DynamicType = exports.DynamicObject = void 0;
27
27
  const TE = __importStar(require("fp-ts/TaskEither"));
28
28
  const fs = __importStar(require("fs"));
29
29
  const fse = __importStar(require("fs-extra"));
30
30
  const E = __importStar(require("fp-ts/Either"));
31
31
  const function_1 = require("fp-ts/function");
32
32
  const t = __importStar(require("io-ts"));
33
+ const Base64_1 = require("../base64/Base64");
34
+ const JsonSerialization_1 = require("../serialization/JsonSerialization");
33
35
  const Try_1 = require("../try/Try");
36
+ const RemoveNullValuesCodec_1 = require("../codec/RemoveNullValuesCodec");
37
+ const serializer = new JsonSerialization_1.JsonSerialization();
38
+ const testRemoveNullValuesCodec = RemoveNullValuesCodec_1.RemoveNullValuesCodec.instance;
39
+ exports.DynamicObject = {
40
+ fromBase64String: (base64Str) => (0, function_1.pipe)(Base64_1.Base64.fromBase64String(base64Str), E.map((base64) => Base64_1.Base64.decodeBinary(base64)), E.chain((decoded) => serializer.deserialize(decoded)), E.map((decoded) => decoded)),
41
+ removeNullValues: (value) => testRemoveNullValuesCodec.encode(value),
42
+ };
34
43
  exports.DynamicType = {
35
44
  readFromFile: (path) => (0, Try_1.tryToEither)(() => JSON.parse(fs.readFileSync(path, 'utf8'))),
36
45
  writeToFile: (path, value) => (0, function_1.pipe)((0, Try_1.tryToEither)(() => fs.writeFileSync(path, JSON.stringify(value))), E.map(() => undefined)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/commons",
3
- "version": "4.8.1",
3
+ "version": "4.9.0",
4
4
  "description": "Extensions to the standard/core libraries and basic features",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"