@voiceflow/common 8.2.8 → 8.3.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.
Files changed (188) hide show
  1. package/build/cjs/constants/environment.js +1 -1
  2. package/build/cjs/constants/regexp.d.ts +5 -5
  3. package/build/cjs/constants/regexp.d.ts.map +1 -1
  4. package/build/cjs/crypto/hex2abc.d.ts.map +1 -1
  5. package/build/cjs/types.d.ts +26 -26
  6. package/build/cjs/types.d.ts.map +1 -1
  7. package/build/cjs/utils/array.d.ts +3 -3
  8. package/build/cjs/utils/array.d.ts.map +1 -1
  9. package/build/cjs/utils/array.js +2 -3
  10. package/build/cjs/utils/emails.d.ts.map +1 -1
  11. package/build/cjs/utils/functional.d.ts +4 -4
  12. package/build/cjs/utils/functional.d.ts.map +1 -1
  13. package/build/cjs/utils/functional.js +0 -1
  14. package/build/cjs/utils/id.d.ts +1 -1
  15. package/build/cjs/utils/id.d.ts.map +1 -1
  16. package/build/cjs/utils/intent.d.ts +6 -6
  17. package/build/cjs/utils/intent.d.ts.map +1 -1
  18. package/build/cjs/utils/intent.js +4 -2
  19. package/build/cjs/utils/mathjs.js +1 -1
  20. package/build/cjs/utils/normalized.d.ts +5 -5
  21. package/build/cjs/utils/normalized.d.ts.map +1 -1
  22. package/build/cjs/utils/number.d.ts.map +1 -1
  23. package/build/cjs/utils/object/common.d.ts +1 -1
  24. package/build/cjs/utils/object/common.d.ts.map +1 -1
  25. package/build/cjs/utils/object/deepMap.d.ts +1 -1
  26. package/build/cjs/utils/object/deepMap.d.ts.map +1 -1
  27. package/build/cjs/utils/object/deepMap.js +0 -2
  28. package/build/cjs/utils/object/diff.d.ts +1 -1
  29. package/build/cjs/utils/object/diff.d.ts.map +1 -1
  30. package/build/cjs/utils/object/keys.d.ts +2 -1
  31. package/build/cjs/utils/object/keys.d.ts.map +1 -1
  32. package/build/cjs/utils/promise.d.ts.map +1 -1
  33. package/build/cjs/utils/protocol.d.ts +2 -2
  34. package/build/cjs/utils/protocol.d.ts.map +1 -1
  35. package/build/cjs/utils/slot.d.ts.map +1 -1
  36. package/build/cjs/utils/typeguard.d.ts +2 -2
  37. package/build/cjs/utils/typeguard.d.ts.map +1 -1
  38. package/build/cjs/utils/variables.d.ts +2 -2
  39. package/build/cjs/utils/variables.d.ts.map +1 -1
  40. package/build/esm/constants/regexp.d.ts +5 -5
  41. package/build/esm/constants/regexp.d.ts.map +1 -1
  42. package/build/esm/crypto/hex2abc.d.ts.map +1 -1
  43. package/build/esm/types.d.ts +26 -26
  44. package/build/esm/types.d.ts.map +1 -1
  45. package/build/esm/utils/array.d.ts +3 -3
  46. package/build/esm/utils/array.d.ts.map +1 -1
  47. package/build/esm/utils/array.js +2 -3
  48. package/build/esm/utils/emails.d.ts.map +1 -1
  49. package/build/esm/utils/functional.d.ts +4 -4
  50. package/build/esm/utils/functional.d.ts.map +1 -1
  51. package/build/esm/utils/functional.js +0 -1
  52. package/build/esm/utils/id.d.ts +1 -1
  53. package/build/esm/utils/id.d.ts.map +1 -1
  54. package/build/esm/utils/intent.d.ts +6 -6
  55. package/build/esm/utils/intent.d.ts.map +1 -1
  56. package/build/esm/utils/intent.js +4 -2
  57. package/build/esm/utils/mathjs.js +1 -1
  58. package/build/esm/utils/normalized.d.ts +5 -5
  59. package/build/esm/utils/normalized.d.ts.map +1 -1
  60. package/build/esm/utils/number.d.ts.map +1 -1
  61. package/build/esm/utils/object/common.d.ts +1 -1
  62. package/build/esm/utils/object/common.d.ts.map +1 -1
  63. package/build/esm/utils/object/deepMap.d.ts +1 -1
  64. package/build/esm/utils/object/deepMap.d.ts.map +1 -1
  65. package/build/esm/utils/object/deepMap.js +0 -2
  66. package/build/esm/utils/object/diff.d.ts +1 -1
  67. package/build/esm/utils/object/diff.d.ts.map +1 -1
  68. package/build/esm/utils/object/keys.d.ts +2 -1
  69. package/build/esm/utils/object/keys.d.ts.map +1 -1
  70. package/build/esm/utils/promise.d.ts.map +1 -1
  71. package/build/esm/utils/protocol.d.ts +2 -2
  72. package/build/esm/utils/protocol.d.ts.map +1 -1
  73. package/build/esm/utils/slot.d.ts.map +1 -1
  74. package/build/esm/utils/typeguard.d.ts +2 -2
  75. package/build/esm/utils/typeguard.d.ts.map +1 -1
  76. package/build/esm/utils/variables.d.ts +2 -2
  77. package/build/esm/utils/variables.d.ts.map +1 -1
  78. package/package.json +46 -48
  79. package/build/cjs/crypto/hex2abc.test.d.ts +0 -2
  80. package/build/cjs/crypto/hex2abc.test.d.ts.map +0 -1
  81. package/build/cjs/crypto/hex2abc.test.js +0 -12
  82. package/build/cjs/crypto/murmurhash.test.d.ts +0 -2
  83. package/build/cjs/crypto/murmurhash.test.d.ts.map +0 -1
  84. package/build/cjs/crypto/murmurhash.test.js +0 -23
  85. package/build/cjs/utils/__fixtures__/name.json +0 -64
  86. package/build/cjs/utils/array.test.d.ts +0 -2
  87. package/build/cjs/utils/array.test.d.ts.map +0 -1
  88. package/build/cjs/utils/array.test.js +0 -237
  89. package/build/cjs/utils/email.test.d.ts +0 -2
  90. package/build/cjs/utils/email.test.d.ts.map +0 -1
  91. package/build/cjs/utils/email.test.js +0 -22
  92. package/build/cjs/utils/functional.test.d.ts +0 -2
  93. package/build/cjs/utils/functional.test.d.ts.map +0 -1
  94. package/build/cjs/utils/functional.test.js +0 -139
  95. package/build/cjs/utils/id.test.d.ts +0 -2
  96. package/build/cjs/utils/id.test.d.ts.map +0 -1
  97. package/build/cjs/utils/id.test.js +0 -66
  98. package/build/cjs/utils/intent.test.d.ts +0 -2
  99. package/build/cjs/utils/intent.test.d.ts.map +0 -1
  100. package/build/cjs/utils/intent.test.js +0 -100
  101. package/build/cjs/utils/map.test.d.ts +0 -2
  102. package/build/cjs/utils/map.test.d.ts.map +0 -1
  103. package/build/cjs/utils/map.test.js +0 -22
  104. package/build/cjs/utils/object/common.test.d.ts +0 -2
  105. package/build/cjs/utils/object/common.test.d.ts.map +0 -1
  106. package/build/cjs/utils/object/common.test.js +0 -175
  107. package/build/cjs/utils/object/deepMap.test.d.ts +0 -2
  108. package/build/cjs/utils/object/deepMap.test.d.ts.map +0 -1
  109. package/build/cjs/utils/object/deepMap.test.js +0 -114
  110. package/build/cjs/utils/object/diff.test.d.ts +0 -2
  111. package/build/cjs/utils/object/diff.test.d.ts.map +0 -1
  112. package/build/cjs/utils/object/diff.test.js +0 -19
  113. package/build/cjs/utils/object/keys.test.d.ts +0 -2
  114. package/build/cjs/utils/object/keys.test.d.ts.map +0 -1
  115. package/build/cjs/utils/object/keys.test.js +0 -15
  116. package/build/cjs/utils/promise.test.d.ts +0 -2
  117. package/build/cjs/utils/promise.test.d.ts.map +0 -1
  118. package/build/cjs/utils/promise.test.js +0 -25
  119. package/build/cjs/utils/protocol.test.d.ts +0 -2
  120. package/build/cjs/utils/protocol.test.d.ts.map +0 -1
  121. package/build/cjs/utils/protocol.test.js +0 -40
  122. package/build/cjs/utils/slot.test.d.ts +0 -2
  123. package/build/cjs/utils/slot.test.d.ts.map +0 -1
  124. package/build/cjs/utils/slot.test.js +0 -38
  125. package/build/cjs/utils/string.test.d.ts +0 -2
  126. package/build/cjs/utils/string.test.d.ts.map +0 -1
  127. package/build/cjs/utils/string.test.js +0 -53
  128. package/build/cjs/utils/timezones.test.d.ts +0 -2
  129. package/build/cjs/utils/timezones.test.d.ts.map +0 -1
  130. package/build/cjs/utils/timezones.test.js +0 -12
  131. package/build/cjs/utils/typeguard.test.d.ts +0 -2
  132. package/build/cjs/utils/typeguard.test.d.ts.map +0 -1
  133. package/build/cjs/utils/typeguard.test.js +0 -55
  134. package/build/esm/crypto/hex2abc.test.d.ts +0 -2
  135. package/build/esm/crypto/hex2abc.test.d.ts.map +0 -1
  136. package/build/esm/crypto/hex2abc.test.js +0 -10
  137. package/build/esm/crypto/murmurhash.test.d.ts +0 -2
  138. package/build/esm/crypto/murmurhash.test.d.ts.map +0 -1
  139. package/build/esm/crypto/murmurhash.test.js +0 -21
  140. package/build/esm/utils/__fixtures__/name.json +0 -64
  141. package/build/esm/utils/array.test.d.ts +0 -2
  142. package/build/esm/utils/array.test.d.ts.map +0 -1
  143. package/build/esm/utils/array.test.js +0 -235
  144. package/build/esm/utils/email.test.d.ts +0 -2
  145. package/build/esm/utils/email.test.d.ts.map +0 -1
  146. package/build/esm/utils/email.test.js +0 -20
  147. package/build/esm/utils/functional.test.d.ts +0 -2
  148. package/build/esm/utils/functional.test.d.ts.map +0 -1
  149. package/build/esm/utils/functional.test.js +0 -137
  150. package/build/esm/utils/id.test.d.ts +0 -2
  151. package/build/esm/utils/id.test.d.ts.map +0 -1
  152. package/build/esm/utils/id.test.js +0 -64
  153. package/build/esm/utils/intent.test.d.ts +0 -2
  154. package/build/esm/utils/intent.test.d.ts.map +0 -1
  155. package/build/esm/utils/intent.test.js +0 -75
  156. package/build/esm/utils/map.test.d.ts +0 -2
  157. package/build/esm/utils/map.test.d.ts.map +0 -1
  158. package/build/esm/utils/map.test.js +0 -20
  159. package/build/esm/utils/object/common.test.d.ts +0 -2
  160. package/build/esm/utils/object/common.test.d.ts.map +0 -1
  161. package/build/esm/utils/object/common.test.js +0 -173
  162. package/build/esm/utils/object/deepMap.test.d.ts +0 -2
  163. package/build/esm/utils/object/deepMap.test.d.ts.map +0 -1
  164. package/build/esm/utils/object/deepMap.test.js +0 -109
  165. package/build/esm/utils/object/diff.test.d.ts +0 -2
  166. package/build/esm/utils/object/diff.test.d.ts.map +0 -1
  167. package/build/esm/utils/object/diff.test.js +0 -17
  168. package/build/esm/utils/object/keys.test.d.ts +0 -2
  169. package/build/esm/utils/object/keys.test.d.ts.map +0 -1
  170. package/build/esm/utils/object/keys.test.js +0 -13
  171. package/build/esm/utils/promise.test.d.ts +0 -2
  172. package/build/esm/utils/promise.test.d.ts.map +0 -1
  173. package/build/esm/utils/promise.test.js +0 -23
  174. package/build/esm/utils/protocol.test.d.ts +0 -2
  175. package/build/esm/utils/protocol.test.d.ts.map +0 -1
  176. package/build/esm/utils/protocol.test.js +0 -38
  177. package/build/esm/utils/slot.test.d.ts +0 -2
  178. package/build/esm/utils/slot.test.d.ts.map +0 -1
  179. package/build/esm/utils/slot.test.js +0 -13
  180. package/build/esm/utils/string.test.d.ts +0 -2
  181. package/build/esm/utils/string.test.d.ts.map +0 -1
  182. package/build/esm/utils/string.test.js +0 -51
  183. package/build/esm/utils/timezones.test.d.ts +0 -2
  184. package/build/esm/utils/timezones.test.d.ts.map +0 -1
  185. package/build/esm/utils/timezones.test.js +0 -10
  186. package/build/esm/utils/typeguard.test.d.ts +0 -2
  187. package/build/esm/utils/typeguard.test.d.ts.map +0 -1
  188. package/build/esm/utils/typeguard.test.js +0 -53
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=id.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"id.test.d.ts","sourceRoot":"","sources":["../../../src/utils/id.test.ts"],"names":[],"mappings":""}
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const id_1 = require("./id");
4
- // sample ObjectIds
5
- const Sample = {
6
- A: 'aaaaaaaaaaaaaaaaaaaaaaaa',
7
- B: 'bbbbbbbbbbbbbbbbbbbbbbbb',
8
- C: 'cccccccccccccccccccccccc',
9
- REAL: '61dcebb839fc80002d048dbd',
10
- };
11
- describe('Utils | id', () => {
12
- describe('remapObjectIDs()', () => {
13
- it('shallow nested', () => {
14
- const map = { [Sample.A]: Sample.B };
15
- expect((0, id_1.remapObjectIDs)({ cool: Sample.A }, map)).toEqual({ cool: Sample.B });
16
- });
17
- it('converts string', () => {
18
- const map = { [Sample.A]: Sample.B };
19
- expect((0, id_1.remapObjectIDs)(Sample.A, map)).toBe(Sample.B);
20
- });
21
- it('converts multiple', () => {
22
- const map = { [Sample.A]: Sample.B, [Sample.REAL]: Sample.C };
23
- expect((0, id_1.remapObjectIDs)({ 1: Sample.A, 2: Sample.REAL }, map)).toEqual({ 1: Sample.B, 2: Sample.C });
24
- expect((0, id_1.remapObjectIDs)({ 1: { 2: { 3: Sample.A, 4: [Sample.REAL] } } }, map)).toEqual({ 1: { 2: { 3: Sample.B, 4: [Sample.C] } } });
25
- });
26
- it('converts multiple maps', () => {
27
- const map = new Map([
28
- [Sample.A, Sample.B],
29
- [Sample.REAL, Sample.C],
30
- ]);
31
- expect((0, id_1.remapObjectIDs)({ 1: Sample.A, 2: Sample.REAL }, map)).toEqual({ 1: Sample.B, 2: Sample.C });
32
- expect((0, id_1.remapObjectIDs)({ 1: { 2: { 3: Sample.A, 4: [Sample.REAL] } } }, map)).toEqual({ 1: { 2: { 3: Sample.B, 4: [Sample.C] } } });
33
- });
34
- it('converts very nested', () => {
35
- const object = {
36
- a: { b: { c: { d: { e: 'id1' } } } },
37
- id1: {
38
- id2: {
39
- id3: {
40
- id4: ['id5'],
41
- },
42
- },
43
- b: 'id2',
44
- },
45
- };
46
- const map = {
47
- id1: 'new1',
48
- id2: 'new2',
49
- id3: 'new3',
50
- id4: 'new4',
51
- id5: 'new5',
52
- };
53
- expect((0, id_1.remapObjectIDs)(object, map)).toEqual({
54
- a: { b: { c: { d: { e: 'new1' } } } },
55
- new1: {
56
- new2: {
57
- new3: {
58
- new4: ['new5'],
59
- },
60
- },
61
- b: 'new2',
62
- },
63
- });
64
- });
65
- });
66
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=intent.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"intent.test.d.ts","sourceRoot":"","sources":["../../../src/utils/intent.test.ts"],"names":[],"mappings":""}
@@ -1,100 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const data = __importStar(require("./__fixtures__/name.json"));
27
- const intent_1 = require("./intent");
28
- describe('utteranceEntityPermutations unit tests', () => {
29
- it('works correctly', async () => {
30
- const utterances = data.intents[0].inputs.map(({ text }) => text);
31
- const entitiesByID = Object.fromEntries(data.slots.map((slot) => [slot.key, slot]));
32
- const key = '4i3h3mmi';
33
- const luisUtterances = (0, intent_1.utteranceEntityPermutations)({ utterances, entitiesByID });
34
- expect(luisUtterances.length).toBe(Math.min(entitiesByID[key].inputs.length, 22));
35
- // Check that each slot value is within one of the utterances
36
- entitiesByID[key].inputs.forEach((input, i) => {
37
- if (i < 22) {
38
- expect(luisUtterances.filter((utt) => utt.text?.includes(input)).length).toBeGreaterThan(0);
39
- }
40
- });
41
- // Check that a fake name is not within the utterances
42
- expect(luisUtterances.filter((utt) => utt.text?.includes('fakeName')).length).toBe(0);
43
- });
44
- it('with replacer', async () => {
45
- const utterances = [
46
- '{{[slot].4i3h3mmi}} testing {{[slotmans].4i3h3mmi}} {{[third].third}}',
47
- 'close {{[slotmans].4i3h3mmi}}{{[third].third}} together',
48
- ];
49
- const entitiesByID = {
50
- '4i3h3mmi': { name: 'slotmans', inputs: ['value1', 'value_super_long', 'v3'] },
51
- third: { name: 'third', inputs: ['thirdvalue'] },
52
- };
53
- // this generates the rasa format
54
- const replacer = (sample, entityID) => {
55
- return `[${sample}](${entitiesByID[entityID].name})`;
56
- };
57
- const replacedUtterances = (0, intent_1.utteranceEntityPermutations)({ utterances, entitiesByID, replacer });
58
- expect(replacedUtterances.map(({ text }) => text)).toEqual([
59
- '[value1](slotmans) testing [value_super_long](slotmans) [thirdvalue](third)',
60
- 'close [v3](slotmans)[thirdvalue](third) together',
61
- ]);
62
- });
63
- });
64
- describe('injectUtteranceSpaces', () => {
65
- const testUtterances = [
66
- '',
67
- '{{[slot].4i3h3mmi}}',
68
- '{{[slot].4i3h3mmi}}{{[slotmans].4i3h3mmi}}',
69
- 'hello there {{[slotmans].4i3h3mma}}',
70
- 'hello there {{[slotmans].4i3h3mmb}} words',
71
- 'hello there{{[slotmans].4i3h3mmc}} words',
72
- 'hello there {{[slotmans].4i3h3mmd}}words',
73
- 'hello there{{[slotmans].4i3h3mme}}words',
74
- 'hello there {{[slotmans].4i3h3mmf}}, words',
75
- 'hello there:{{[slotmans].4i3h3mmg}},words',
76
- '{{[slot].4i3h3mmi}}and{{[third].third}}',
77
- '{{[slot].4i3h3mmi}}{{[slotmans].4i3h3mmi}}{{[third].third}}',
78
- 'multiple{{[slotmans].4i3h3mmi}}slots{{[slotmans].4i3h3mmi}}words{{[slotmans].4i3h3mmi}}',
79
- ];
80
- const expectedResults = [
81
- '',
82
- '{{[slot].4i3h3mmi}}',
83
- '{{[slot].4i3h3mmi}} {{[slotmans].4i3h3mmi}}',
84
- 'hello there {{[slotmans].4i3h3mma}}',
85
- 'hello there {{[slotmans].4i3h3mmb}} words',
86
- 'hello there {{[slotmans].4i3h3mmc}} words',
87
- 'hello there {{[slotmans].4i3h3mmd}} words',
88
- 'hello there {{[slotmans].4i3h3mme}} words',
89
- 'hello there {{[slotmans].4i3h3mmf}}, words',
90
- 'hello there:{{[slotmans].4i3h3mmg}},words',
91
- '{{[slot].4i3h3mmi}} and {{[third].third}}',
92
- '{{[slot].4i3h3mmi}} {{[slotmans].4i3h3mmi}} {{[third].third}}',
93
- 'multiple {{[slotmans].4i3h3mmi}} slots {{[slotmans].4i3h3mmi}} words {{[slotmans].4i3h3mmi}}',
94
- ];
95
- it('add spaces around slots if needed', () => {
96
- for (let i = 0; i < testUtterances.length; ++i) {
97
- expect((0, intent_1.injectUtteranceSpaces)(testUtterances[i])).toBe(expectedResults[i]);
98
- }
99
- });
100
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=map.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"map.test.d.ts","sourceRoot":"","sources":["../../../src/utils/map.test.ts"],"names":[],"mappings":""}
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const map_1 = require("./map");
4
- describe('Utils | map', () => {
5
- describe('getOrDefault', () => {
6
- it('returns the value at the given key if it exists in the map', () => {
7
- const map = new Map([['key', 'value']]);
8
- const value = (0, map_1.getOrDefault)(map, 'key', 'other');
9
- expect(value).toBe('value');
10
- });
11
- it('inserts and returns the default value if key does not exist in the map', () => {
12
- const map = new Map();
13
- const value = (0, map_1.getOrDefault)(map, 'key', 'other');
14
- expect(value).toBe('other');
15
- });
16
- it('inserts and returns the result of the default value function if key does not exist in the map', () => {
17
- const map = new Map();
18
- const value = (0, map_1.getOrDefault)(map, 'key', () => 'other');
19
- expect(value).toBe('other');
20
- });
21
- });
22
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=common.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/object/common.test.ts"],"names":[],"mappings":""}
@@ -1,175 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const common_1 = require("./common");
4
- describe('Utils | object | common', () => {
5
- describe('selectField()', () => {
6
- it('creates function', () => {
7
- expect(typeof (0, common_1.selectField)('field')).toBe('function');
8
- });
9
- it('works', () => {
10
- expect((0, common_1.selectField)('field')({ field: 1 })).toBe(1);
11
- expect((0, common_1.selectField)('field2')({ field1: 1, field2: 2 })).toBe(2);
12
- });
13
- });
14
- describe('selectID()', () => {
15
- it('works', () => {
16
- expect((0, common_1.selectID)({ id: '1' })).toBe('1');
17
- expect((0, common_1.selectID)({ id: 0 })).toBe(0);
18
- });
19
- });
20
- describe('selectKey()', () => {
21
- it('works', () => {
22
- expect((0, common_1.selectKey)({ key: '1' })).toBe('1');
23
- expect((0, common_1.selectKey)({ key: 0 })).toBe(0);
24
- });
25
- });
26
- describe('selectValue()', () => {
27
- it('works', () => {
28
- expect((0, common_1.selectValue)({ value: '1' })).toBe('1');
29
- expect((0, common_1.selectValue)({ value: 0 })).toBe(0);
30
- });
31
- });
32
- describe('isObject()', () => {
33
- it('works positive', () => {
34
- expect((0, common_1.isObject)({})).toBe(true);
35
- expect((0, common_1.isObject)({})).toBe(true);
36
- expect((0, common_1.isObject)([])).toBe(true);
37
- // eslint-disable-next-line no-new-wrappers
38
- expect((0, common_1.isObject)(new Number(1))).toBe(true);
39
- });
40
- it('works negative', () => {
41
- expect((0, common_1.isObject)(null)).toBe(false);
42
- expect((0, common_1.isObject)(undefined)).toBe(false);
43
- expect((0, common_1.isObject)('')).toBe(false);
44
- expect((0, common_1.isObject)('lorem')).toBe(false);
45
- expect((0, common_1.isObject)(0)).toBe(false);
46
- expect((0, common_1.isObject)(Symbol('s'))).toBe(false);
47
- });
48
- });
49
- describe('hasProperty()', () => {
50
- it('works', () => {
51
- expect((0, common_1.hasProperty)({ value: '1' }, 'value')).toBe(true);
52
- expect((0, common_1.hasProperty)({}, 'key')).toBe(false);
53
- });
54
- });
55
- describe('omit()', () => {
56
- it('works with 0-3 keys', () => {
57
- expect((0, common_1.omit)({ value1: '1' }, [])).toEqual({ value1: '1' });
58
- expect((0, common_1.omit)({ value1: '1' }, ['value1'])).toEqual({});
59
- expect((0, common_1.omit)({ value1: '1', value2: '2', value3: 3 }, ['value1', 'value2'])).toEqual({ value3: 3 });
60
- expect((0, common_1.omit)({ value1: '1', value2: '2', value3: 3, value4: 4 }, ['value1', 'value2', 'value3'])).toEqual({ value4: 4 });
61
- });
62
- it('works with 3+ keys', () => {
63
- expect((0, common_1.omit)({ value1: '1', value2: '2', value3: 3 }, ['value1', 'value2', 'value3'])).toEqual({});
64
- expect((0, common_1.omit)({ value1: '1', value2: '2', value3: 3, value4: undefined, value5: null }, ['value1', 'value2', 'value3', 'value5'])).toEqual({
65
- value4: undefined,
66
- });
67
- });
68
- });
69
- describe('pick()', () => {
70
- it('works with 0-3 keys', () => {
71
- expect((0, common_1.pick)({ value1: '1' }, [])).toEqual({});
72
- expect((0, common_1.pick)({ value1: '1' }, ['value1'])).toEqual({ value1: '1' });
73
- expect((0, common_1.pick)({ value1: '1', value2: '2', value3: 3 }, ['value1', 'value2'])).toEqual({ value1: '1', value2: '2' });
74
- expect((0, common_1.pick)({ value1: '1', value2: '2', value3: 3, value4: 4 }, ['value1', 'value2', 'value3'])).toEqual({
75
- value1: '1',
76
- value2: '2',
77
- value3: 3,
78
- });
79
- });
80
- it('works with 3+ keys', () => {
81
- expect((0, common_1.pick)({ value1: '1', value2: '2', value3: 3 }, ['value1', 'value2', 'value3'])).toEqual({ value1: '1', value2: '2', value3: 3 });
82
- expect((0, common_1.pick)({ value1: '1', value2: '2', value3: 3, value4: undefined, value5: null }, ['value1', 'value2', 'value3', 'value5'])).toEqual({
83
- value1: '1',
84
- value2: '2',
85
- value3: 3,
86
- value5: null,
87
- });
88
- });
89
- it('works with undefined keys', () => {
90
- expect((0, common_1.pick)({ value1: '1', value2: '2' }, ['value1', 'value2', 'value3'])).toEqual({ value1: '1', value2: '2' });
91
- });
92
- });
93
- describe('omitBy()', () => {
94
- it('works', () => {
95
- const keys = new Set(['value1', 'value2', 'value5']);
96
- expect((0, common_1.omitBy)({ value1: '1' }, () => false)).toEqual({ value1: '1' });
97
- expect((0, common_1.omitBy)({ value1: '1' }, (key) => keys.has(key))).toEqual({});
98
- expect((0, common_1.omitBy)({ value1: '1', value2: '2', value3: 3 }, (key) => keys.has(key))).toEqual({ value3: 3 });
99
- expect((0, common_1.omitBy)({ value1: '1', value2: '2', value3: 3 }, (key) => key === 'value3' || keys.has(key))).toEqual({});
100
- expect((0, common_1.omitBy)({ value1: '1', value2: '2', value3: 3, value4: undefined, value5: null }, (key) => keys.has(key))).toEqual({
101
- value3: 3,
102
- value4: undefined,
103
- });
104
- });
105
- });
106
- describe('pickBy()', () => {
107
- it('works', () => {
108
- const keys = new Set(['value1', 'value2', 'value5']);
109
- expect((0, common_1.pickBy)({ value1: '1' }, () => false)).toEqual({});
110
- expect((0, common_1.pickBy)({ value1: '1' }, (key) => keys.has(key))).toEqual({ value1: '1' });
111
- expect((0, common_1.pickBy)({ value1: '1', value2: '2', value3: 3 }, (key) => keys.has(key))).toEqual({
112
- value1: '1',
113
- value2: '2',
114
- });
115
- expect((0, common_1.pickBy)({ value1: '1', value2: '2', value3: 3 }, (key) => key === 'value3' || keys.has(key))).toEqual({
116
- value1: '1',
117
- value2: '2',
118
- value3: 3,
119
- });
120
- expect((0, common_1.pickBy)({ value1: '1', value2: '2', value3: 3, value4: undefined, value5: null }, (key) => keys.has(key))).toEqual({
121
- value1: '1',
122
- value2: '2',
123
- value5: null,
124
- });
125
- });
126
- });
127
- describe('mapValue()', () => {
128
- it('works', () => {
129
- const objects = {
130
- a: { id: 1 },
131
- b: { id: 2 },
132
- c: { id: 3 },
133
- };
134
- expect((0, common_1.mapValue)(objects, ({ id }) => id)).toEqual({ a: 1, b: 2, c: 3 });
135
- });
136
- });
137
- describe('mapEntry()', () => {
138
- it('works', () => {
139
- const objects = {
140
- a: { id: 1 },
141
- b: { id: 2 },
142
- c: { id: 3 },
143
- };
144
- expect((0, common_1.mapEntry)(objects, ([key, { id }]) => [`new_${key}`, id])).toEqual({ new_a: 1, new_b: 2, new_c: 3 });
145
- });
146
- });
147
- describe('shallowPartialEquals()', () => {
148
- it('works', () => {
149
- const obj1 = {
150
- a: 1,
151
- b: 2,
152
- };
153
- const obj1Update = {
154
- a: 1,
155
- c: undefined,
156
- };
157
- expect((0, common_1.shallowPartialEquals)(obj1, obj1Update)).toBe(false);
158
- const obj2 = {
159
- a: 1,
160
- b: 2,
161
- };
162
- const obj2Update = {
163
- a: 1,
164
- };
165
- expect((0, common_1.shallowPartialEquals)(obj2, obj2Update)).toBe(true);
166
- const obj3 = {
167
- a: 1,
168
- };
169
- const obj3Update = {
170
- b: 1,
171
- };
172
- expect((0, common_1.shallowPartialEquals)(obj3, obj3Update)).toBe(false);
173
- });
174
- });
175
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=deepMap.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deepMap.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/object/deepMap.test.ts"],"names":[],"mappings":""}
@@ -1,114 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const bson_objectid_1 = __importDefault(require("bson-objectid"));
7
- const deepMap_1 = require("./deepMap");
8
- describe('Utils | object | deepMap', () => {
9
- describe('deepMap()', () => {
10
- const transform = (n) => (typeof n === 'number' ? n ** 2 : Number(n) ** 2);
11
- it('transforms simple object', () => {
12
- expect((0, deepMap_1.deepMap)({ two: 2, three: '3' }, transform)).toEqual({ two: 4, three: 9 });
13
- });
14
- it('transforms simple array', () => {
15
- expect((0, deepMap_1.deepMap)(['2', 3], transform)).toEqual([4, 9]);
16
- });
17
- it("don't change non plain objects", () => {
18
- const transform = (n) => (typeof n === 'string' ? Number(n) ** 2 : n);
19
- const date = new Date();
20
- expect((0, deepMap_1.deepMap)(['2', date], transform)).toEqual([4, date]);
21
- });
22
- it('transform objectID', () => {
23
- const originalID = new bson_objectid_1.default();
24
- const transformedID = new bson_objectid_1.default();
25
- const transform = (n) => (n === originalID ? transformedID : n);
26
- const date = new Date();
27
- expect((0, deepMap_1.deepMap)(['2', date, originalID], transform)).toEqual(['2', date, transformedID]);
28
- });
29
- it('transforms object with nested objects/arrays', () => {
30
- expect((0, deepMap_1.deepMap)({ two: '2', obj: { three: '3', four: 4 }, arr: [5, '6'] }, transform)).toEqual({
31
- two: 4,
32
- obj: { three: 9, four: 16 },
33
- arr: [25, 36],
34
- });
35
- });
36
- it('transforms array with nested objects/arrays', () => {
37
- expect((0, deepMap_1.deepMap)([2, { three: 3, four: 4 }, [5, 6]], transform)).toEqual([4, { three: 9, four: 16 }, [25, 36]]);
38
- });
39
- it('transforms an object with circular references', () => {
40
- const obj = { two: 2, arr: [3, 4], self: null, arr2: null };
41
- obj.self = obj;
42
- obj.arr2 = obj.arr;
43
- const exp = { two: 4, arr: [9, 16], self: null, arr2: null };
44
- exp.self = exp;
45
- exp.arr2 = exp.arr;
46
- expect((0, deepMap_1.deepMap)(obj, transform)).toEqual(exp);
47
- });
48
- it('transforms object in place', () => {
49
- const arr = [3];
50
- const obj = { two: 2, arr };
51
- const result = (0, deepMap_1.deepMap)(obj, transform, { inPlace: true });
52
- expect(result).toEqual({ two: 4, arr: [9] });
53
- expect(result).toEqual(obj);
54
- });
55
- it('transforms sub-objects/sub-arrays in place', () => {
56
- const arr = [3];
57
- const obj = { two: 2, arr };
58
- expect((0, deepMap_1.deepMap)(obj, transform, { inPlace: true }).arr).toEqual(arr);
59
- });
60
- it('defaults to false', () => {
61
- const arr = [3];
62
- const obj = { two: 2, arr };
63
- expect((0, deepMap_1.deepMap)(obj, transform)).not.toEqual(obj);
64
- });
65
- it('mapFunction is called once per primitive value', () => {
66
- const square = jest.fn(transform);
67
- (0, deepMap_1.deepMap)({ two: 2, obj: { three: 3 }, arr: [4] }, square);
68
- expect(square).toHaveBeenCalledTimes(3);
69
- });
70
- it('mapFunction is called with value and key', () => {
71
- const square = jest.fn(transform);
72
- (0, deepMap_1.deepMap)({ two: 2, arr: [3, 6] }, square);
73
- expect(square).toHaveBeenNthCalledWith(1, 2, 'two');
74
- expect(square).toHaveBeenNthCalledWith(2, 3, 0);
75
- expect(square).toHaveBeenNthCalledWith(3, 6, 1);
76
- });
77
- });
78
- describe('deepMapKeys()', () => {
79
- const transform = (key) => key.toUpperCase();
80
- it('transforms keys of simple object', () => {
81
- expect((0, deepMap_1.deepMapKeys)({ one: 1, two: 2 }, transform)).toEqual({ ONE: 1, TWO: 2 });
82
- });
83
- it('transforms keys of object with nested objects/arrays', () => {
84
- expect((0, deepMap_1.deepMapKeys)({ one: 1, obj: { two: 2, three: 3 }, arr: [4, 5] }, transform)).toEqual({
85
- ONE: 1,
86
- OBJ: { TWO: 2, THREE: 3 },
87
- ARR: [4, 5],
88
- });
89
- });
90
- it('transforms keys of array with nested object/array', () => {
91
- expect((0, deepMap_1.deepMapKeys)([1, { two: 2, three: 3, arr: [4, { five: 5 }] }], transform)).toEqual([1, { TWO: 2, THREE: 3, ARR: [4, { FIVE: 5 }] }]);
92
- });
93
- it('transforms an object with circular references', () => {
94
- const obj = { one: 1, arr: [2, 3], self: null, arr2: [] };
95
- obj.self = obj;
96
- obj.arr2 = obj.arr;
97
- const exp = { ONE: 1, ARR: [2, 3], SELF: null, ARR2: [] };
98
- exp.SELF = exp;
99
- exp.ARR2 = exp.ARR;
100
- expect((0, deepMap_1.deepMapKeys)(obj, transform)).toEqual(exp);
101
- });
102
- it('mapFunction is called once per object property', () => {
103
- const caps = jest.fn(transform);
104
- (0, deepMap_1.deepMapKeys)({ one: 1, obj: { two: 2, three: 3 }, arr: [4, 5] }, caps);
105
- expect(caps).toHaveBeenCalledTimes(5);
106
- });
107
- it('mapFunction is called with key and value', () => {
108
- const caps = jest.fn(transform);
109
- (0, deepMap_1.deepMapKeys)({ one: 1, arr: [2, 3] }, caps);
110
- expect(caps).toHaveBeenNthCalledWith(1, 'one', 1);
111
- expect(caps).toHaveBeenNthCalledWith(2, 'arr', [2, 3]);
112
- });
113
- });
114
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=diff.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"diff.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/object/diff.test.ts"],"names":[],"mappings":""}
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const diff_1 = require("./diff");
4
- describe('Utils | object | diff', () => {
5
- describe('getTopLevelDiff()', () => {
6
- it('gets diff of arrays', () => {
7
- expect((0, diff_1.getTopLevelDiff)(['foo', 'bar', 'fuzz'], ['fizz', 'buzz', 'fuzz'])).toEqual(['foo', 'bar']);
8
- });
9
- it('gets diff of objects', () => {
10
- expect((0, diff_1.getTopLevelDiff)({ foo: 1, bar: 2, fuzz: 3 }, { fizz: 4, buzz: 5, fuzz: 3 })).toEqual({ foo: 1, bar: 2 });
11
- });
12
- it('gets diff of objects with custom compare', () => {
13
- expect((0, diff_1.getTopLevelDiff)({ foo: 1, bar: 2, fuzz: 6 }, { fizz: 4, buzz: 5, fuzz: 9 }, (lhs, rhs) => typeof lhs === typeof rhs)).toEqual({
14
- foo: 1,
15
- bar: 2,
16
- });
17
- });
18
- });
19
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=keys.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"keys.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/object/keys.test.ts"],"names":[],"mappings":""}
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const keys_1 = require("./keys");
4
- describe('Utils | object | keys', () => {
5
- describe('getKeys()', () => {
6
- it('gets keys with a strict type', () => {
7
- const foo = Symbol('foo');
8
- const bar = Symbol('bar');
9
- const fizz = Symbol('fizz');
10
- const keys = (0, keys_1.getKeys)({ [foo]: 1, [bar]: 2, [fizz]: 3 });
11
- // this would throw a compiler error if `keys[0]` was a `string`
12
- keys[0] === foo;
13
- });
14
- });
15
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=promise.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"promise.test.d.ts","sourceRoot":"","sources":["../../../src/utils/promise.test.ts"],"names":[],"mappings":""}
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const promise_1 = require("./promise");
4
- describe('Utils | promise', () => {
5
- describe('delay()', () => {
6
- it('delay for the provided time before resolving', async () => {
7
- const timeout = 10;
8
- const start = Date.now();
9
- await (0, promise_1.delay)(timeout);
10
- expect(Date.now() - start).toBeGreaterThanOrEqual(timeout);
11
- });
12
- });
13
- describe('rejectIn()', () => {
14
- it('delay for the provided time before rejecting', async () => {
15
- const timeout = 10;
16
- const start = Date.now();
17
- try {
18
- await (0, promise_1.rejectIn)(timeout);
19
- }
20
- catch (err) {
21
- expect(Date.now() - start).toBeGreaterThanOrEqual(timeout);
22
- }
23
- });
24
- });
25
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=protocol.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"protocol.test.d.ts","sourceRoot":"","sources":["../../../src/utils/protocol.test.ts"],"names":[],"mappings":""}
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const protocol_1 = require("./protocol");
4
- describe('Utils | protocol', () => {
5
- describe('typeFactory()', () => {
6
- it('should generate a prefixed type', () => {
7
- expect((0, protocol_1.typeFactory)('red', 'blue')('green')).toBe('red.blue.green');
8
- });
9
- });
10
- describe('Channel', () => {
11
- describe('build()', () => {
12
- it('store original build function directly', () => {
13
- const channel = new protocol_1.Channel(['foo', 'bar'], ({ foo, bar }) => `${foo}/fizz/buzz/${bar}`);
14
- expect(channel.build({ foo: '123', bar: '456' })).toBe('123/fizz/buzz/456');
15
- });
16
- });
17
- describe('buildMatcher()', () => {
18
- it('store build a matcher using the provided argument names', () => {
19
- const channel = new protocol_1.Channel(['foo', 'bar'], ({ foo, bar }) => `${foo}/fizz/buzz/${bar}`);
20
- expect(channel.buildMatcher()).toBe(':foo/fizz/buzz/:bar');
21
- });
22
- });
23
- describe('extend()', () => {
24
- it('create a channel built to be suffixed to the output of an existing channel', () => {
25
- const fooChannel = new protocol_1.Channel(['foo'], ({ foo }) => `foo/${foo}`);
26
- const barChannel = fooChannel.extend(['bar'], ({ bar }) => `bar/${bar}`);
27
- expect(barChannel.buildMatcher()).toBe('foo/:foo/bar/:bar');
28
- expect(barChannel.build({ foo: '123', bar: '456' })).toBe('foo/123/bar/456');
29
- });
30
- });
31
- describe('createChannel()', () => {
32
- it('constructs a new Channel', () => {
33
- const channel = (0, protocol_1.createChannel)(['foo'], ({ foo }) => `foo/${foo}`);
34
- expect(channel).toBeInstanceOf(protocol_1.Channel);
35
- expect(channel.buildMatcher()).toBe('foo/:foo');
36
- expect(channel.build({ foo: '123' })).toBe('foo/123');
37
- });
38
- });
39
- });
40
- });