@voiceflow/common 7.20.2 → 7.22.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.
Files changed (157) hide show
  1. package/build/common/constants/environment.js +0 -1
  2. package/build/common/constants/index.js +0 -1
  3. package/build/common/constants/intent.js +0 -1
  4. package/build/common/constants/regexp.js +0 -1
  5. package/build/common/constants/runtime.js +0 -1
  6. package/build/common/constants/slot.js +0 -1
  7. package/build/common/crypto/base64.js +0 -1
  8. package/build/common/crypto/hex2abc.js +0 -1
  9. package/build/common/crypto/index.js +0 -1
  10. package/build/common/crypto/murmurhash.js +0 -1
  11. package/build/common/crypto/synchronous.js +0 -1
  12. package/build/common/index.js +0 -1
  13. package/build/common/types.d.ts +6 -2
  14. package/build/common/types.js +0 -1
  15. package/build/common/utils/array.d.ts +12 -2
  16. package/build/common/utils/array.js +18 -12
  17. package/build/common/utils/emails.js +0 -1
  18. package/build/common/utils/functional.d.ts +1 -0
  19. package/build/common/utils/functional.js +4 -4
  20. package/build/common/utils/generate.js +0 -1
  21. package/build/common/utils/id.js +2 -4
  22. package/build/common/utils/index.js +0 -1
  23. package/build/common/utils/intent.js +0 -1
  24. package/build/common/utils/mathjs.js +0 -1
  25. package/build/common/utils/normalized.js +0 -1
  26. package/build/common/utils/number.js +0 -1
  27. package/build/common/utils/object/common.d.ts +26 -0
  28. package/build/common/utils/object/common.js +63 -0
  29. package/build/common/utils/object/deepMap.d.ts +5 -0
  30. package/build/common/utils/object/deepMap.js +76 -0
  31. package/build/common/utils/object/diff.d.ts +3 -0
  32. package/build/common/utils/object/diff.js +40 -0
  33. package/build/common/utils/object/index.d.ts +4 -0
  34. package/build/common/utils/object/index.js +16 -0
  35. package/build/common/utils/object/keys.d.ts +4 -0
  36. package/build/common/utils/object/keys.js +61 -0
  37. package/build/common/utils/promise.js +0 -1
  38. package/build/common/utils/protocol.js +0 -1
  39. package/build/common/utils/slot.js +0 -1
  40. package/build/common/utils/string.js +0 -1
  41. package/build/common/utils/time.js +0 -1
  42. package/build/common/utils/timezones.js +0 -1
  43. package/build/common/utils/typeguard.js +0 -1
  44. package/build/common/utils/variables.js +0 -1
  45. package/build/esm/constants/environment.js +0 -1
  46. package/build/esm/constants/index.js +0 -1
  47. package/build/esm/constants/intent.js +0 -1
  48. package/build/esm/constants/regexp.js +0 -1
  49. package/build/esm/constants/runtime.js +0 -1
  50. package/build/esm/constants/slot.js +0 -1
  51. package/build/esm/crypto/base64.js +0 -1
  52. package/build/esm/crypto/hex2abc.js +0 -1
  53. package/build/esm/crypto/index.js +0 -1
  54. package/build/esm/crypto/murmurhash.js +0 -1
  55. package/build/esm/crypto/synchronous.js +0 -1
  56. package/build/esm/index.js +0 -1
  57. package/build/esm/types.d.ts +6 -2
  58. package/build/esm/types.js +0 -1
  59. package/build/esm/utils/array.d.ts +12 -2
  60. package/build/esm/utils/array.js +16 -11
  61. package/build/esm/utils/emails.js +0 -1
  62. package/build/esm/utils/functional.d.ts +1 -0
  63. package/build/esm/utils/functional.js +2 -3
  64. package/build/esm/utils/generate.js +0 -1
  65. package/build/esm/utils/id.js +1 -3
  66. package/build/esm/utils/index.js +0 -1
  67. package/build/esm/utils/intent.js +0 -1
  68. package/build/esm/utils/mathjs.js +0 -1
  69. package/build/esm/utils/normalized.js +0 -1
  70. package/build/esm/utils/number.js +0 -1
  71. package/build/esm/utils/object/common.d.ts +26 -0
  72. package/build/esm/utils/object/common.js +53 -0
  73. package/build/esm/utils/object/deepMap.d.ts +5 -0
  74. package/build/esm/utils/object/deepMap.js +71 -0
  75. package/build/esm/utils/object/diff.d.ts +3 -0
  76. package/build/esm/utils/object/diff.js +32 -0
  77. package/build/esm/utils/object/index.d.ts +4 -0
  78. package/build/esm/utils/object/index.js +4 -0
  79. package/build/esm/utils/object/keys.d.ts +4 -0
  80. package/build/esm/utils/object/keys.js +52 -0
  81. package/build/esm/utils/promise.js +0 -1
  82. package/build/esm/utils/protocol.js +0 -1
  83. package/build/esm/utils/slot.js +0 -1
  84. package/build/esm/utils/string.js +0 -1
  85. package/build/esm/utils/time.js +0 -1
  86. package/build/esm/utils/timezones.js +0 -1
  87. package/build/esm/utils/typeguard.js +0 -1
  88. package/build/esm/utils/variables.js +0 -1
  89. package/package.json +4 -6
  90. package/build/common/constants/environment.js.map +0 -1
  91. package/build/common/constants/index.js.map +0 -1
  92. package/build/common/constants/intent.js.map +0 -1
  93. package/build/common/constants/regexp.js.map +0 -1
  94. package/build/common/constants/runtime.js.map +0 -1
  95. package/build/common/constants/slot.js.map +0 -1
  96. package/build/common/crypto/base64.js.map +0 -1
  97. package/build/common/crypto/hex2abc.js.map +0 -1
  98. package/build/common/crypto/index.js.map +0 -1
  99. package/build/common/crypto/murmurhash.js.map +0 -1
  100. package/build/common/crypto/synchronous.js.map +0 -1
  101. package/build/common/index.js.map +0 -1
  102. package/build/common/types.js.map +0 -1
  103. package/build/common/utils/array.js.map +0 -1
  104. package/build/common/utils/emails.js.map +0 -1
  105. package/build/common/utils/functional.js.map +0 -1
  106. package/build/common/utils/generate.js.map +0 -1
  107. package/build/common/utils/id.js.map +0 -1
  108. package/build/common/utils/index.js.map +0 -1
  109. package/build/common/utils/intent.js.map +0 -1
  110. package/build/common/utils/mathjs.js.map +0 -1
  111. package/build/common/utils/normalized.js.map +0 -1
  112. package/build/common/utils/number.js.map +0 -1
  113. package/build/common/utils/object.d.ts +0 -20
  114. package/build/common/utils/object.js +0 -113
  115. package/build/common/utils/object.js.map +0 -1
  116. package/build/common/utils/promise.js.map +0 -1
  117. package/build/common/utils/protocol.js.map +0 -1
  118. package/build/common/utils/slot.js.map +0 -1
  119. package/build/common/utils/string.js.map +0 -1
  120. package/build/common/utils/time.js.map +0 -1
  121. package/build/common/utils/timezones.js.map +0 -1
  122. package/build/common/utils/typeguard.js.map +0 -1
  123. package/build/common/utils/variables.js.map +0 -1
  124. package/build/esm/constants/environment.js.map +0 -1
  125. package/build/esm/constants/index.js.map +0 -1
  126. package/build/esm/constants/intent.js.map +0 -1
  127. package/build/esm/constants/regexp.js.map +0 -1
  128. package/build/esm/constants/runtime.js.map +0 -1
  129. package/build/esm/constants/slot.js.map +0 -1
  130. package/build/esm/crypto/base64.js.map +0 -1
  131. package/build/esm/crypto/hex2abc.js.map +0 -1
  132. package/build/esm/crypto/index.js.map +0 -1
  133. package/build/esm/crypto/murmurhash.js.map +0 -1
  134. package/build/esm/crypto/synchronous.js.map +0 -1
  135. package/build/esm/index.js.map +0 -1
  136. package/build/esm/types.js.map +0 -1
  137. package/build/esm/utils/array.js.map +0 -1
  138. package/build/esm/utils/emails.js.map +0 -1
  139. package/build/esm/utils/functional.js.map +0 -1
  140. package/build/esm/utils/generate.js.map +0 -1
  141. package/build/esm/utils/id.js.map +0 -1
  142. package/build/esm/utils/index.js.map +0 -1
  143. package/build/esm/utils/intent.js.map +0 -1
  144. package/build/esm/utils/mathjs.js.map +0 -1
  145. package/build/esm/utils/normalized.js.map +0 -1
  146. package/build/esm/utils/number.js.map +0 -1
  147. package/build/esm/utils/object.d.ts +0 -20
  148. package/build/esm/utils/object.js +0 -97
  149. package/build/esm/utils/object.js.map +0 -1
  150. package/build/esm/utils/promise.js.map +0 -1
  151. package/build/esm/utils/protocol.js.map +0 -1
  152. package/build/esm/utils/slot.js.map +0 -1
  153. package/build/esm/utils/string.js.map +0 -1
  154. package/build/esm/utils/time.js.map +0 -1
  155. package/build/esm/utils/timezones.js.map +0 -1
  156. package/build/esm/utils/typeguard.js.map +0 -1
  157. package/build/esm/utils/variables.js.map +0 -1
@@ -62,4 +62,3 @@ const deepVariableSubstitution = (bodyData, variableMap) => {
62
62
  return _recurse(bodyData);
63
63
  };
64
64
  exports.deepVariableSubstitution = deepVariableSubstitution;
65
- //# sourceMappingURL=variables.js.map
@@ -8,4 +8,3 @@ export var Environment;
8
8
  /** @deprecated Voiceflow dev envs now use {@link Environment.DEVELOPMENT} */
9
9
  Environment["STAGING"] = "staging";
10
10
  })(Environment || (Environment = {}));
11
- //# sourceMappingURL=environment.js.map
@@ -3,4 +3,3 @@ export * from './intent';
3
3
  export * from './regexp';
4
4
  export * from './runtime';
5
5
  export * from './slot';
6
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=intent.js.map
@@ -13,4 +13,3 @@ export const VALID_SAMPLE_CHARACTERS_WITHOUT_CURLY_BRACES_OR_SPACES = `${VALID_S
13
13
  export const VALID_SAMPLE_CHARACTERS = `${VALID_SAMPLE_CHARACTERS_WITHOUT_CURLY_BRACES_OR_SPACES} \\[\\]`;
14
14
  // TYLER: lmao I decompiled the ADC front end source code so these regexes are good as it gets 👌
15
15
  export const VALID_SAMPLE_UTTERANCE = `[^${VALID_SAMPLE_CHARACTERS}|]`;
16
- //# sourceMappingURL=regexp.js.map
@@ -1,2 +1 @@
1
1
  export const VF_DM_PREFIX = 'dm_';
2
- //# sourceMappingURL=runtime.js.map
@@ -4,4 +4,3 @@ export const CustomSlot = {
4
4
  type: CUSTOM_SLOT_TYPE,
5
5
  label: CUSTOM_SLOT_TYPE,
6
6
  };
7
- //# sourceMappingURL=slot.js.map
@@ -15,4 +15,3 @@ class Base64 {
15
15
  }
16
16
  }
17
17
  export default Base64;
18
- //# sourceMappingURL=base64.js.map
@@ -25,4 +25,3 @@ const mapping = {
25
25
  * @returns A string of lowercase alphabetical characters
26
26
  */
27
27
  export const hex2abc = (hex) => Array.prototype.map.call(hex.toLowerCase(), (char) => mapping[char]).join('');
28
- //# sourceMappingURL=hex2abc.js.map
@@ -1,4 +1,3 @@
1
1
  export { default as Base64 } from './base64';
2
2
  export { default as MurmurHash } from './murmurhash';
3
3
  export { default as Synchronous } from './synchronous';
4
- //# sourceMappingURL=index.js.map
@@ -9,4 +9,3 @@ export class MurmurHash {
9
9
  }
10
10
  }
11
11
  export default MurmurHash;
12
- //# sourceMappingURL=murmurhash.js.map
@@ -36,4 +36,3 @@ class Synchronous {
36
36
  }
37
37
  _Synchronous_alg = new WeakMap(), _Synchronous_key = new WeakMap();
38
38
  export default Synchronous;
39
- //# sourceMappingURL=synchronous.js.map
@@ -4,4 +4,3 @@ export * from './types';
4
4
  export * as Utils from './utils';
5
5
  // TODO: Remove this export once we migrate all utils in other repos.
6
6
  export * from './utils';
7
- //# sourceMappingURL=index.js.map
@@ -15,10 +15,11 @@ export declare type WithRequired<T, K extends keyof T> = Omit<T, K> & Required<P
15
15
  export declare type Writeable<T> = {
16
16
  -readonly [P in keyof T]: T[P];
17
17
  };
18
- export declare type NullableRecord<T extends object> = {
18
+ export declare type PartialRecord<K extends PropertyKey, T> = Partial<Record<K, T>>;
19
+ export declare type NullableRecord<T> = {
19
20
  [K in keyof T]: Nullable<T[K]>;
20
21
  };
21
- export declare type NonNullishRecord<T extends object> = Required<{
22
+ export declare type NonNullishRecord<T> = Required<{
22
23
  [K in keyof T]: NonNullable<T[K]>;
23
24
  }>;
24
25
  export declare type Struct = Record<string, unknown>;
@@ -34,3 +35,6 @@ export declare type EmptyObject = Record<never, never>;
34
35
  /** Avoids accidentally converting an immutable array type to a mutable one. */
35
36
  export declare type SafeArray<Element, Original> = Original extends Array<Element> ? Element[] : Original extends ReadonlyArray<Element> ? ReadonlyArray<Element> : Original extends ArrayLike<Element> ? ArrayLike<Element> : never;
36
37
  export declare type ArrayUnionToIntersection<T extends ArrayLike<unknown>> = SafeArray<T[number], T>;
38
+ export declare type PrimitiveMap<T extends PropertyKey> = {
39
+ [P in T]: P;
40
+ };
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map
@@ -1,4 +1,4 @@
1
- import { AnyRecord, ArrayUnionToIntersection } from "../types";
1
+ import { AnyRecord, ArrayUnionToIntersection, PrimitiveMap } from "../types";
2
2
  export declare const unique: <T>(items: T[]) => T[];
3
3
  export declare const without: <T>(items: T[], index: number) => T[];
4
4
  export declare const withoutValue: <T>(items: T[], value: T) => T[];
@@ -12,7 +12,16 @@ export declare const head: <T>(items: T[]) => [T, T[]];
12
12
  export declare const tail: <T>(items: T[]) => [T[], T];
13
13
  export declare const reorder: <T>(items: T[], fromIndex: number, toIndex: number) => T[];
14
14
  export declare const separate: <T>(items: T[], predicate: (item: T, index: number) => boolean) => [T[], T[]];
15
- export declare const createMap: <T extends AnyRecord, K extends string | number = string>(array: T[], getKey: (value: T) => string) => Record<K, T>;
15
+ interface CreateEntries {
16
+ <T extends PropertyKey>(array: readonly T[]): Array<readonly [T, T]>;
17
+ <T extends AnyRecord, K extends PropertyKey = string>(array: readonly T[], getKey: (value: T) => K): Array<readonly [K, T]>;
18
+ }
19
+ interface CreateMap {
20
+ <T extends PropertyKey>(array: readonly T[]): PrimitiveMap<T>;
21
+ <T extends AnyRecord, K extends PropertyKey = string>(array: readonly T[], getKey: (value: T) => K): Record<K, T>;
22
+ }
23
+ export declare const createEntries: CreateEntries;
24
+ export declare const createMap: CreateMap;
16
25
  export declare const findUnion: <T>(lhs: T[], rhs: T[]) => {
17
26
  rhsOnly: T[];
18
27
  lhsOnly: T[];
@@ -27,3 +36,4 @@ export declare const isNotNullish: <T>(value: T) => value is NonNullable<T>;
27
36
  export declare const filterOutNullish: <T>(items: readonly T[]) => NonNullable<T>[];
28
37
  export declare const filterAndGetLastRemovedValue: <T>(list: T[], filter: (item: T) => boolean) => [T[], T | null];
29
38
  export declare const inferUnion: <T extends ArrayLike<unknown>>(array: T) => import("../types").SafeArray<T[number], T>;
39
+ export {};
@@ -37,23 +37,29 @@ export const separate = (items, predicate) => items.reduce(([passAcc, failAcc],
37
37
  }
38
38
  return [passAcc, failAcc];
39
39
  }, [[], []]);
40
- export const createMap = (array, getKey) => array.reduce((acc, item) => Object.assign(acc, { [getKey(item)]: item }), {});
40
+ export const createEntries = (array, getKey = (value) => value) => array.map((item) => [getKey(item), item]);
41
+ export const createMap = (array, getKey = (value) => value) => Object.fromEntries(createEntries(array, getKey));
41
42
  export const findUnion = (lhs, rhs) => {
42
- const unique = new Set([...lhs, ...rhs]);
43
- return Array.from(unique).reduce((acc, item) => {
44
- if (lhs.includes(item)) {
45
- if (rhs.includes(item)) {
46
- acc.union.push(item);
43
+ // using sets instead of arrays since .has is O(1)
44
+ const lSet = new Set(lhs);
45
+ const rSet = new Set(rhs);
46
+ const unionSet = new Set([...lhs, ...rhs]);
47
+ const result = { rhsOnly: [], lhsOnly: [], union: [] };
48
+ // eslint-disable-next-line no-restricted-syntax
49
+ for (const item of unionSet) {
50
+ if (lSet.has(item)) {
51
+ if (rSet.has(item)) {
52
+ result.union.push(item);
47
53
  }
48
54
  else {
49
- acc.lhsOnly.push(item);
55
+ result.lhsOnly.push(item);
50
56
  }
51
57
  }
52
58
  else {
53
- acc.rhsOnly.push(item);
59
+ result.rhsOnly.push(item);
54
60
  }
55
- return acc;
56
- }, { rhsOnly: [], lhsOnly: [], union: [] });
61
+ }
62
+ return result;
57
63
  };
58
64
  export const diff = (lhs, rhs) => {
59
65
  const { lhsOnly, rhsOnly } = findUnion(lhs, rhs);
@@ -90,4 +96,3 @@ export const filterAndGetLastRemovedValue = (list, filter) => {
90
96
  return [filteredList, lastItem];
91
97
  };
92
98
  export const inferUnion = (array) => array;
93
- //# sourceMappingURL=array.js.map
@@ -1,4 +1,3 @@
1
1
  const FORMAT = /^\w+(['+-.]\w+)*@\w+([.-]\w+)*\.\w+([.-]\w+)*$/;
2
2
  export const isValidEmail = (email) => !!email.match(FORMAT);
3
3
  export const getEmailDomain = (email) => email.slice(Math.max(0, email.lastIndexOf('@') + 1));
4
- //# sourceMappingURL=emails.js.map
@@ -1,4 +1,5 @@
1
1
  import { Nullish } from '../types';
2
+ export declare const isFunction: <T extends (...args: any[]) => any = (...args: any[]) => any>(value: unknown) => value is T;
2
3
  export declare type Transform<T = any, R = T> = (value: T) => R;
3
4
  export interface Compose {
4
5
  <R, T1>(t0: Transform<T1, R>): (value: T1) => R;
@@ -1,3 +1,4 @@
1
+ export const isFunction = (value) => typeof value === 'function';
1
2
  export const compose = (...transforms) => (value) => {
2
3
  if (transforms.length === 1) {
3
4
  return transforms[0](value);
@@ -7,8 +8,7 @@ export const compose = (...transforms) => (value) => {
7
8
  }
8
9
  return transforms.reduceRight((acc, transform) => transform(acc), value);
9
10
  };
10
- // eslint-disable-next-line @typescript-eslint/no-empty-function
11
- export const noop = () => { };
11
+ export const noop = () => undefined;
12
12
  export const identity = (value) => value;
13
13
  export const stringify = (value) => (typeof value === 'string' ? value : String(value));
14
14
  export const chain = (...fns) => (...args) => {
@@ -49,4 +49,3 @@ export const withEffect = (callback) => (value) => {
49
49
  callback(value);
50
50
  return value;
51
51
  };
52
- //# sourceMappingURL=functional.js.map
@@ -28,4 +28,3 @@ export const generate = {
28
28
  .reduce((acc, [key, value]) => Object.assign(acc, { [key]: value }), {}),
29
29
  array: (length = 3, factory = generate.string) => Array.from({ length }).map(() => factory()),
30
30
  };
31
- //# sourceMappingURL=generate.js.map
@@ -1,7 +1,6 @@
1
1
  import ObjectId from 'bson-objectid';
2
2
  import cuid from 'cuid';
3
- import deepMap from 'deep-map';
4
- import deepMapKeys from 'deep-map-keys';
3
+ import { deepMap, deepMapKeys } from './object';
5
4
  export { cuid };
6
5
  export const objectID = () => new ObjectId().toHexString();
7
6
  export const remapObjectIDs = (object, lookupMap) => {
@@ -14,4 +13,3 @@ export const remapObjectIDs = (object, lookupMap) => {
14
13
  };
15
14
  return deepMapKeys(deepMap(object, mapping), mapping);
16
15
  };
17
- //# sourceMappingURL=id.js.map
@@ -19,4 +19,3 @@ export * as variables from './variables';
19
19
  // TODO: Remove these exports once we migrate all utils in other repos.
20
20
  export * from './intent';
21
21
  export * from './variables';
22
- //# sourceMappingURL=index.js.map
@@ -137,4 +137,3 @@ export const injectUtteranceSpaces = (originalUtterance) => {
137
137
  };
138
138
  // VF.HELP -> help
139
139
  export const cleanVFIntentName = (intentName) => (intentName.startsWith('VF.') ? intentName.slice(3).toLowerCase() : intentName);
140
- //# sourceMappingURL=intent.js.map
@@ -56,4 +56,3 @@ export const parser = (exp) => {
56
56
  sanitized = sanitized.replace(EVAL_REGEX, 'eval($2)');
57
57
  return sanitized;
58
58
  };
59
- //# sourceMappingURL=mathjs.js.map
@@ -68,4 +68,3 @@ export const removeAllNormalizedByKeys = ({ allKeys, byKey }, targetKeys) => {
68
68
  byKey: buildLookup(filteredKeys, getByKey(byKey)),
69
69
  };
70
70
  };
71
- //# sourceMappingURL=normalized.js.map
@@ -3,4 +3,3 @@ export const NON_ALPHANUMERIC_REGEXP = /\W/g;
3
3
  export const convertToWord = (value) => numberToWords.toWords(value).replace(NON_ALPHANUMERIC_REGEXP, ' ');
4
4
  export const isInRange = (target, min, max) => target >= min && target <= max;
5
5
  export const clamp = (value, min, max) => Math.max(Math.min(value, max), min);
6
- //# sourceMappingURL=number.js.map
@@ -0,0 +1,26 @@
1
+ import { AnyRecord, Struct } from "../../types";
2
+ export declare const selectField: <K extends string | number>(field: K) => <T extends { [key in K]: any; }>(obj: T) => T[K];
3
+ export declare const selectID: <T extends {
4
+ id: any;
5
+ }>(obj: T) => T["id"];
6
+ export declare const selectKey: <T extends {
7
+ key: any;
8
+ }>(obj: T) => T["key"];
9
+ export declare const selectValue: <T extends {
10
+ value: any;
11
+ }>(obj: T) => T["value"];
12
+ export declare const isObject: (obj: unknown) => obj is Struct;
13
+ export declare const hasProperty: <T, K extends string | keyof T>(obj: T, key: K) => obj is T & Record<K, unknown>;
14
+ export declare const omit: <T, K extends keyof T>(obj: T, keys: K[]) => Omit<T, K>;
15
+ export declare const pick: <T, K extends keyof T>(obj: T, keys: K[]) => Pick<T, K>;
16
+ interface PickOmitBy {
17
+ <T extends AnyRecord>(obj: T, predicate: (key: keyof T, value: T[keyof T]) => boolean): Partial<T>;
18
+ <T extends AnyRecord, R extends AnyRecord>(obj: T, predicate: (key: keyof T, value: T[keyof T]) => boolean): R;
19
+ }
20
+ export declare const pickBy: PickOmitBy;
21
+ export declare const omitBy: PickOmitBy;
22
+ /**
23
+ * @deprecated use pickBy instead
24
+ */
25
+ export declare const filterEntries: PickOmitBy;
26
+ export {};
@@ -0,0 +1,53 @@
1
+ export const selectField = (field) => (obj) => obj[field];
2
+ export const selectID = selectField('id');
3
+ export const selectKey = selectField('key');
4
+ export const selectValue = selectField('value');
5
+ export const isObject = (obj) => obj !== null && typeof obj === 'object';
6
+ export const hasProperty = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
7
+ export const omit = (obj, keys) => {
8
+ const newObj = Object.assign({}, obj);
9
+ if (keys.length === 0) {
10
+ return newObj;
11
+ }
12
+ if (keys.length === 1) {
13
+ delete newObj[keys[0]];
14
+ return newObj;
15
+ }
16
+ if (keys.length === 2) {
17
+ delete newObj[keys[0]];
18
+ delete newObj[keys[1]];
19
+ return newObj;
20
+ }
21
+ return keys.reduce((acc, key) => {
22
+ delete acc[key];
23
+ return acc;
24
+ }, newObj);
25
+ };
26
+ export const pick = (obj, keys) => {
27
+ if (keys.length === 0) {
28
+ return {};
29
+ }
30
+ if (keys.length === 1) {
31
+ return { [keys[0]]: obj[keys[0]] };
32
+ }
33
+ if (keys.length === 2) {
34
+ return { [keys[0]]: obj[keys[0]], [keys[1]]: obj[keys[1]] };
35
+ }
36
+ return keys.reduce((acc, key) => Object.assign(acc, { [key]: obj[key] }), {});
37
+ };
38
+ export const pickBy = (obj, predicate) => Object.entries(obj).reduce((acc, [key, value]) => {
39
+ if (predicate(key, value)) {
40
+ acc[key] = value;
41
+ }
42
+ return acc;
43
+ }, {});
44
+ export const omitBy = (obj, predicate) => Object.entries(obj).reduce((acc, [key, value]) => {
45
+ if (predicate(key, value)) {
46
+ delete acc[key];
47
+ }
48
+ return acc;
49
+ }, Object.assign({}, obj));
50
+ /**
51
+ * @deprecated use pickBy instead
52
+ */
53
+ export const filterEntries = pickBy;
@@ -0,0 +1,5 @@
1
+ import { Struct } from "../../types";
2
+ export declare const deepMap: <T = Struct>(object: unknown, mapFunction: (value: unknown, key: string | number) => unknown, options?: {
3
+ inPlace?: boolean;
4
+ }) => T;
5
+ export declare const deepMapKeys: <T = Struct>(object: unknown, mapFunction: (key: string, value: unknown) => string) => T;
@@ -0,0 +1,71 @@
1
+ import { isObject } from './common';
2
+ export const deepMap = (object, mapFunction, options = {}) => {
3
+ const cache = new WeakMap();
4
+ const mapArray = (arr) => {
5
+ if (cache.has(arr)) {
6
+ return cache.get(arr);
7
+ }
8
+ const result = options.inPlace ? arr : [];
9
+ cache.set(arr, result);
10
+ const { length } = arr;
11
+ for (let index = 0; index < length; index++) {
12
+ result[index] = map(arr[index], index);
13
+ }
14
+ return result;
15
+ };
16
+ const mapObject = (obj) => {
17
+ if (cache.has(obj)) {
18
+ return cache.get(obj);
19
+ }
20
+ const result = options.inPlace ? obj : {};
21
+ cache.set(obj, result);
22
+ // eslint-disable-next-line no-restricted-syntax
23
+ for (const key of Object.keys(obj)) {
24
+ result[key] = map(obj[key], key);
25
+ }
26
+ return result;
27
+ };
28
+ const map = (value, key) => {
29
+ if (Array.isArray(value))
30
+ return mapArray(value);
31
+ if (isObject(value))
32
+ return mapObject(value);
33
+ return mapFunction(value, key);
34
+ };
35
+ return map(object);
36
+ };
37
+ export const deepMapKeys = (object, mapFunction) => {
38
+ const cache = new WeakMap();
39
+ const mapArray = (arr) => {
40
+ if (cache.has(arr)) {
41
+ return cache.get(arr);
42
+ }
43
+ const result = [];
44
+ cache.set(arr, result);
45
+ const { length } = arr;
46
+ for (let i = 0; i < length; i++) {
47
+ result.push(map(arr[i]));
48
+ }
49
+ return result;
50
+ };
51
+ const mapObject = (obj) => {
52
+ if (cache.has(obj)) {
53
+ return cache.get(obj);
54
+ }
55
+ const result = {};
56
+ cache.set(obj, result);
57
+ // eslint-disable-next-line no-restricted-syntax
58
+ for (const key of Object.keys(obj)) {
59
+ result[mapFunction(key, obj[key])] = map(obj[key]);
60
+ }
61
+ return result;
62
+ };
63
+ const map = (value) => {
64
+ if (Array.isArray(value))
65
+ return mapArray(value);
66
+ if (isObject(value))
67
+ return mapObject(value);
68
+ return value;
69
+ };
70
+ return map(object);
71
+ };
@@ -0,0 +1,3 @@
1
+ import { AnyRecord, DeepPartial } from "../../types";
2
+ export declare const getDiff: <S extends AnyRecord>(object: S, base: S, compare?: <T>(left: T, right: T) => boolean) => DeepPartial<S>;
3
+ export declare const getTopLevelDiff: <S extends AnyRecord>(object: S, base: S, compare?: <T>(left: T, right: T) => boolean) => Partial<S>;
@@ -0,0 +1,32 @@
1
+ import _transform from 'lodash/transform';
2
+ import { isObject } from './common';
3
+ const defaultCompare = (left, right) => left === right;
4
+ export const getDiff = (object, base, compare = defaultCompare) => {
5
+ const changes = (object, base) => _transform(object, (result, value, key) => {
6
+ var _a;
7
+ if (!compare(value, base[key])) {
8
+ if (isObject(value) && isObject(base[key])) {
9
+ // eslint-disable-next-line no-param-reassign
10
+ result[key] = changes(value, base[key]);
11
+ if (Object.keys((_a = result[key]) !== null && _a !== void 0 ? _a : {}).length === 0) {
12
+ // eslint-disable-next-line no-param-reassign
13
+ delete result[key];
14
+ }
15
+ }
16
+ else {
17
+ // eslint-disable-next-line no-param-reassign
18
+ result[key] = value;
19
+ }
20
+ }
21
+ });
22
+ return changes(object, base);
23
+ };
24
+ export const getTopLevelDiff = (object, base, compare = defaultCompare) => {
25
+ const changes = (object, base) => _transform(object, (result, value, key) => {
26
+ if (!compare(value, base[key])) {
27
+ // eslint-disable-next-line no-param-reassign
28
+ result[key] = value;
29
+ }
30
+ });
31
+ return changes(object, base);
32
+ };
@@ -0,0 +1,4 @@
1
+ export * from './common';
2
+ export * from './deepMap';
3
+ export * from './diff';
4
+ export * from './keys';
@@ -0,0 +1,4 @@
1
+ export * from './common';
2
+ export * from './deepMap';
3
+ export * from './diff';
4
+ export * from './keys';
@@ -0,0 +1,4 @@
1
+ import { AnyRecord } from "../../types";
2
+ export declare const getKeys: <T>(obj: T) => (keyof T)[];
3
+ export declare const getIn: <T, K extends string | keyof T>(rawObj: T, key: K | K[], def?: any, index?: number) => rawObj is T & Record<K, unknown>;
4
+ export declare const setIn: (obj: AnyRecord, path: unknown, value: unknown) => any;
@@ -0,0 +1,52 @@
1
+ import _cloneDeep from 'lodash/cloneDeep';
2
+ import _toPath from 'lodash/toPath';
3
+ export const getKeys = (obj) => Object.keys(obj);
4
+ export const getIn = (rawObj, key, def, index = 0) => {
5
+ const path = _toPath(key);
6
+ let obj = rawObj;
7
+ let i = index;
8
+ if (path.length === 1) {
9
+ return obj[path[0]];
10
+ }
11
+ while (obj && i < path.length) {
12
+ obj = obj[path[i++]];
13
+ }
14
+ return obj === undefined ? def : obj;
15
+ };
16
+ export const setIn = (obj, path, value) => {
17
+ const res = {};
18
+ const pathArray = _toPath(path);
19
+ let resVal = res;
20
+ let index = 0;
21
+ for (; index < pathArray.length - 1; index++) {
22
+ const currentPath = pathArray[index];
23
+ if (resVal[currentPath]) {
24
+ resVal = resVal[currentPath];
25
+ continue;
26
+ }
27
+ const currentObj = getIn(obj, pathArray.slice(0, index + 1));
28
+ if (currentObj) {
29
+ resVal[currentPath] = _cloneDeep(currentObj);
30
+ resVal = resVal[currentPath];
31
+ }
32
+ else {
33
+ const nextPath = pathArray[index + 1];
34
+ resVal[currentPath] = +nextPath >= 0 ? [] : {};
35
+ resVal = resVal[currentPath];
36
+ }
37
+ }
38
+ if ((index === 0 ? obj : resVal)[pathArray[index]] === value) {
39
+ return obj;
40
+ }
41
+ if (value === undefined) {
42
+ delete resVal[pathArray[index]];
43
+ }
44
+ else {
45
+ resVal[pathArray[index]] = value;
46
+ }
47
+ const result = Object.assign(Object.assign({}, obj), res);
48
+ if (index === 0 && value === undefined) {
49
+ delete result[pathArray[index]];
50
+ }
51
+ return result;
52
+ };
@@ -17,4 +17,3 @@ export const createControlledPromise = () => {
17
17
  promise.resolve = res;
18
18
  return promise;
19
19
  };
20
- //# sourceMappingURL=promise.js.map
@@ -15,4 +15,3 @@ export class Channel {
15
15
  }
16
16
  }
17
17
  export const createChannel = (variables, build) => new Channel(variables, build);
18
- //# sourceMappingURL=protocol.js.map
@@ -8,4 +8,3 @@ export const addPrebuiltEntities = (entities, prebuiltEntities) => entities.map(
8
8
  export const getUniqueSamples = (input) => _uniqBy(input.split(','), (sample) => sample.toLowerCase());
9
9
  // spread all synonyms into string array ['car, automobile', 'plane, jet'] => ['car', 'automobile', 'plane', 'jet']
10
10
  export const getAllSamples = (inputs = []) => inputs.flatMap((input) => input.split(',')).filter((sample) => !!sample.trim());
11
- //# sourceMappingURL=slot.js.map
@@ -8,4 +8,3 @@ export const removeTrailingUnderscores = (str) => str.replace(TRAILING_UNDERSCOR
8
8
  export const conditionalReplace = (base, pattern, value) => {
9
9
  return value ? base.replace(pattern, value) : base;
10
10
  };
11
- //# sourceMappingURL=string.js.map
@@ -61,4 +61,3 @@ export const getAbbrevatedFormat = (time) => time
61
61
  })
62
62
  .filter(Boolean)
63
63
  .join('');
64
- //# sourceMappingURL=time.js.map
@@ -2027,4 +2027,3 @@ const timezoneGroups = [
2027
2027
  ];
2028
2028
  const getTimezones = () => timezoneGroups.flatMap((group) => group.zones.map((zone) => zone.value));
2029
2029
  export const TIMEZONES = getTimezones();
2030
- //# sourceMappingURL=timezones.js.map
@@ -1,3 +1,2 @@
1
1
  export const createTypeguardCreator = () => (values) => (value) => !!value && (Array.isArray(values) ? values.includes(value) : values === value);
2
2
  export const createTypedTypeguardCreator = () => (values) => (value) => Array.isArray(values) ? values.includes(value.type) : value.type === values;
3
- //# sourceMappingURL=typeguard.js.map
@@ -54,4 +54,3 @@ export const deepVariableSubstitution = (bodyData, variableMap) => {
54
54
  };
55
55
  return _recurse(bodyData);
56
56
  };
57
- //# sourceMappingURL=variables.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@voiceflow/common",
3
3
  "description": "Junk drawer of utility functions",
4
- "version": "7.20.2",
4
+ "version": "7.22.1",
5
5
  "author": "Voiceflow",
6
6
  "bugs": {
7
7
  "url": "https://github.com/voiceflow/libs/issues"
@@ -11,10 +11,7 @@
11
11
  "bson-objectid": "^2.0.1",
12
12
  "crypto-js": "^4.1.1",
13
13
  "cuid": "^2.1.8",
14
- "dayjs": "^1.10.7",
15
- "deep-map": "2.0.0",
16
- "deep-map-keys": "2.0.1",
17
- "es6-weak-map": "2.0.3",
14
+ "dayjs": "1.10.7",
18
15
  "lodash": "^4.17.21",
19
16
  "murmurhash-wasm": "^1.3.0",
20
17
  "number-to-words": "^1.2.4",
@@ -37,6 +34,7 @@
37
34
  "mocha": "9.1.3",
38
35
  "nyc": "^15.1.0",
39
36
  "rimraf": "^3.0.2",
37
+ "sinon": "^10.0.0",
40
38
  "ts-mocha": "^8.0.0",
41
39
  "ts-node": "10.5.0",
42
40
  "tsconfig-paths": "3.12.0",
@@ -78,5 +76,5 @@
78
76
  "test:single": "NODE_ENV=test ts-mocha --paths --config config/tests/mocharc.yml",
79
77
  "test:unit": "NODE_ENV=test nyc --report-dir=nyc_coverage_unit ts-mocha --paths --config config/tests/mocharc.yml 'tests/**/*.unit.ts'"
80
78
  },
81
- "gitHead": "132bb4a23c41ee02103ac2f1e332cbf7793f2ba3"
79
+ "gitHead": "6f4ffd66f86bd1888f89fa1f44b431386544ccf0"
82
80
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"environment.js","sourceRoot":"","sources":["../../../src/constants/environment.ts"],"names":[],"mappings":";;;AAAA,IAAY,WAQX;AARD,WAAY,WAAW;IACrB,wCAAyB,CAAA;IACzB,0CAA2B,CAAA;IAC3B,8BAAe,CAAA;IACf,0BAAW,CAAA;IACX,4BAAa,CAAA;IACb,8EAA8E;IAC9E,kCAAmB,CAAA;AACrB,CAAC,EARW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAQtB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAA8B;AAC9B,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B;AAC1B,yCAAuB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"intent.js","sourceRoot":"","sources":["../../../src/constants/intent.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"regexp.js","sourceRoot":"","sources":["../../../src/constants/regexp.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG,IAAI,CAAC;AAEpB,QAAA,WAAW,GAAG,wCAAwC,CAAC;AAEvD,QAAA,kBAAkB,GAAG,QAAQ,CAAC;AAE9B,QAAA,wBAAwB,GAAG,eAAe,CAAC;AAE3C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAExC,0FAA0F;AAC7E,QAAA,qBAAqB,GAAG,GAAG,uBAAe,wBAAwB,CAAC;AAEhF,0EAA0E;AAC1E,qDAAqD;AACrD,kFAAkF;AACrE,QAAA,sBAAsB,GAAG,GAAG,6BAAqB,0GAA0G,CAAC;AAE5J,QAAA,sDAAsD,GAAG,GAAG,8BAAsB,QAAQ,CAAC;AAE3F,QAAA,uBAAuB,GAAG,GAAG,8DAAsD,SAAS,CAAC;AAE1G,iGAAiG;AACpF,QAAA,sBAAsB,GAAG,KAAK,+BAAuB,IAAI,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/constants/runtime.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG,KAAK,CAAC"}