liminal 0.4.0 → 1.0.0-beta.2

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 (239) hide show
  1. package/LICENSE +201 -15
  2. package/README.md +96 -81
  3. package/esm/client/Client.d.ts +39 -0
  4. package/esm/client/Client.d.ts.map +1 -0
  5. package/esm/client/Client.js +9 -0
  6. package/esm/client/Client.js.map +1 -0
  7. package/esm/client/Store.d.ts +3 -0
  8. package/esm/client/Store.d.ts.map +1 -0
  9. package/esm/client/Store.js +3 -0
  10. package/esm/client/Store.js.map +1 -0
  11. package/esm/client/Tx.d.ts +40 -0
  12. package/esm/client/Tx.d.ts.map +1 -0
  13. package/esm/client/Tx.js +36 -0
  14. package/esm/client/Tx.js.map +1 -0
  15. package/esm/client/mod.d.ts +4 -0
  16. package/esm/client/mod.d.ts.map +1 -0
  17. package/esm/client/mod.js +5 -0
  18. package/esm/client/mod.js.map +1 -0
  19. package/esm/core/Bool.d.ts +104 -0
  20. package/esm/core/Bool.d.ts.map +1 -0
  21. package/esm/core/Bool.js +73 -0
  22. package/esm/core/Bool.js.map +1 -0
  23. package/esm/core/Bytes.d.ts +39 -0
  24. package/esm/core/Bytes.d.ts.map +1 -0
  25. package/esm/core/Bytes.js +7 -0
  26. package/esm/core/Bytes.js.map +1 -0
  27. package/esm/core/Call.d.ts +11 -0
  28. package/esm/core/Call.d.ts.map +1 -0
  29. package/esm/core/Call.js +23 -0
  30. package/esm/core/Call.js.map +1 -0
  31. package/esm/core/Effect.d.ts +20 -0
  32. package/esm/core/Effect.d.ts.map +1 -0
  33. package/esm/core/Effect.js +37 -0
  34. package/esm/core/Effect.js.map +1 -0
  35. package/esm/core/Hash.d.ts +41 -0
  36. package/esm/core/Hash.d.ts.map +1 -0
  37. package/esm/core/Hash.js +8 -0
  38. package/esm/core/Hash.js.map +1 -0
  39. package/esm/core/Id.d.ts +198 -0
  40. package/esm/core/Id.d.ts.map +1 -0
  41. package/esm/core/Id.js +69 -0
  42. package/esm/core/Id.js.map +1 -0
  43. package/esm/core/Int.d.ts +768 -0
  44. package/esm/core/Int.d.ts.map +1 -0
  45. package/esm/core/Int.js +201 -0
  46. package/esm/core/Int.js.map +1 -0
  47. package/esm/core/Key.d.ts +40 -0
  48. package/esm/core/Key.d.ts.map +1 -0
  49. package/esm/core/Key.js +7 -0
  50. package/esm/core/Key.js.map +1 -0
  51. package/esm/core/MerkleList.d.ts +105 -0
  52. package/esm/core/MerkleList.d.ts.map +1 -0
  53. package/esm/core/MerkleList.js +82 -0
  54. package/esm/core/MerkleList.js.map +1 -0
  55. package/esm/core/MerkleMap.d.ts +87 -0
  56. package/esm/core/MerkleMap.d.ts.map +1 -0
  57. package/esm/core/MerkleMap.js +67 -0
  58. package/esm/core/MerkleMap.js.map +1 -0
  59. package/esm/core/None.d.ts +52 -0
  60. package/esm/core/None.d.ts.map +1 -0
  61. package/esm/core/None.js +12 -0
  62. package/esm/core/None.js.map +1 -0
  63. package/esm/core/State.d.ts +16 -0
  64. package/esm/core/State.d.ts.map +1 -0
  65. package/esm/core/State.js +22 -0
  66. package/esm/core/State.js.map +1 -0
  67. package/esm/core/String.d.ts +41 -0
  68. package/esm/core/String.d.ts.map +1 -0
  69. package/esm/core/String.js +4 -0
  70. package/esm/core/String.js.map +1 -0
  71. package/esm/core/Struct.d.ts +58 -0
  72. package/esm/core/Struct.d.ts.map +1 -0
  73. package/esm/core/Struct.js +13 -0
  74. package/esm/core/Struct.js.map +1 -0
  75. package/esm/core/Type.d.ts +78 -0
  76. package/esm/core/Type.d.ts.map +1 -0
  77. package/esm/core/Type.js +71 -0
  78. package/esm/core/Type.js.map +1 -0
  79. package/esm/core/Union.d.ts +43 -0
  80. package/esm/core/Union.d.ts.map +1 -0
  81. package/esm/core/Union.js +7 -0
  82. package/esm/core/Union.js.map +1 -0
  83. package/esm/core/Use.d.ts +62 -0
  84. package/esm/core/Use.d.ts.map +1 -0
  85. package/esm/core/Use.js +16 -0
  86. package/esm/core/Use.js.map +1 -0
  87. package/esm/core/mod.d.ts +18 -0
  88. package/esm/core/mod.d.ts.map +1 -0
  89. package/esm/core/mod.js +19 -0
  90. package/esm/core/mod.js.map +1 -0
  91. package/esm/lib/MerkleList.d.ts +4 -0
  92. package/esm/lib/MerkleList.d.ts.map +1 -0
  93. package/esm/lib/MerkleList.js +4 -0
  94. package/esm/lib/MerkleList.js.map +1 -0
  95. package/esm/lib/MerkleMap.d.ts +4 -0
  96. package/esm/lib/MerkleMap.d.ts.map +1 -0
  97. package/esm/lib/MerkleMap.js +4 -0
  98. package/esm/lib/MerkleMap.js.map +1 -0
  99. package/esm/lib/mod.d.ts +3 -0
  100. package/esm/lib/mod.d.ts.map +1 -0
  101. package/esm/lib/mod.js +3 -0
  102. package/esm/lib/mod.js.map +1 -0
  103. package/esm/mod.d.ts +3 -0
  104. package/esm/mod.d.ts.map +1 -0
  105. package/esm/mod.js +4 -0
  106. package/esm/mod.js.map +1 -0
  107. package/esm/package.json +3 -0
  108. package/esm/test/Signer.d.ts +10 -0
  109. package/esm/test/Signer.d.ts.map +1 -0
  110. package/esm/test/Signer.js +13 -0
  111. package/esm/test/Signer.js.map +1 -0
  112. package/esm/test/mod.d.ts +2 -0
  113. package/esm/test/mod.d.ts.map +1 -0
  114. package/esm/test/mod.js +2 -0
  115. package/esm/test/mod.js.map +1 -0
  116. package/esm/util/AbortController.d.ts +4 -0
  117. package/esm/util/AbortController.d.ts.map +1 -0
  118. package/esm/util/AbortController.js +2 -0
  119. package/esm/util/AbortController.js.map +1 -0
  120. package/esm/util/ArrayOfLength.d.ts +2 -0
  121. package/esm/util/ArrayOfLength.d.ts.map +1 -0
  122. package/esm/util/ArrayOfLength.js +2 -0
  123. package/esm/util/ArrayOfLength.js.map +1 -0
  124. package/esm/util/Flatten.d.ts +4 -0
  125. package/esm/util/Flatten.d.ts.map +1 -0
  126. package/esm/util/Flatten.js +2 -0
  127. package/esm/util/Flatten.js.map +1 -0
  128. package/esm/util/Rest.d.ts +2 -0
  129. package/esm/util/Rest.d.ts.map +1 -0
  130. package/esm/util/Rest.js +2 -0
  131. package/esm/util/Rest.js.map +1 -0
  132. package/esm/util/Subscription.d.ts +5 -0
  133. package/esm/util/Subscription.d.ts.map +1 -0
  134. package/esm/util/Subscription.js +2 -0
  135. package/esm/util/Subscription.js.map +1 -0
  136. package/esm/util/Tagged.d.ts +6 -0
  137. package/esm/util/Tagged.d.ts.map +1 -0
  138. package/esm/util/Tagged.js +6 -0
  139. package/esm/util/Tagged.js.map +1 -0
  140. package/esm/util/U2I.d.ts +2 -0
  141. package/esm/util/U2I.d.ts.map +1 -0
  142. package/esm/util/U2I.js +2 -0
  143. package/esm/util/U2I.js.map +1 -0
  144. package/esm/util/generator/collect.d.ts +3 -0
  145. package/esm/util/generator/collect.d.ts.map +1 -0
  146. package/esm/util/generator/collect.js +16 -0
  147. package/esm/util/generator/collect.js.map +1 -0
  148. package/esm/util/isKey.d.ts +2 -0
  149. package/esm/util/isKey.d.ts.map +1 -0
  150. package/esm/util/isKey.js +8 -0
  151. package/esm/util/isKey.js.map +1 -0
  152. package/esm/util/unimplemented.d.ts +2 -0
  153. package/esm/util/unimplemented.d.ts.map +1 -0
  154. package/esm/util/unimplemented.js +6 -0
  155. package/esm/util/unimplemented.js.map +1 -0
  156. package/package.json +21 -21
  157. package/src/client/Client.ts +49 -0
  158. package/src/client/Store.ts +1 -0
  159. package/src/client/Tx.ts +62 -0
  160. package/src/client/mod.ts +5 -0
  161. package/src/core/Bool.ts +75 -0
  162. package/src/core/Bytes.ts +9 -0
  163. package/src/core/Call.ts +38 -0
  164. package/src/core/Effect.ts +87 -0
  165. package/src/core/Hash.ts +23 -0
  166. package/src/core/Id.ts +97 -0
  167. package/src/core/Int.ts +177 -0
  168. package/src/core/Key.ts +9 -0
  169. package/src/core/MerkleList.ts +92 -0
  170. package/src/core/MerkleMap.ts +86 -0
  171. package/src/core/None.ts +11 -0
  172. package/src/core/State.ts +31 -0
  173. package/src/core/String.ts +5 -0
  174. package/src/core/Struct.ts +49 -0
  175. package/src/core/Type.ts +120 -0
  176. package/src/core/Union.ts +17 -0
  177. package/src/core/Use.ts +33 -0
  178. package/src/core/mod.ts +19 -0
  179. package/src/lib/MerkleList.ts +4 -0
  180. package/src/lib/MerkleMap.ts +4 -0
  181. package/src/lib/mod.ts +2 -0
  182. package/src/mod.ts +4 -0
  183. package/src/test/Signer.ts +22 -0
  184. package/src/test/mod.ts +1 -0
  185. package/src/util/AbortController.ts +3 -0
  186. package/src/util/ArrayOfLength.ts +5 -0
  187. package/src/util/Flatten.ts +2 -0
  188. package/src/util/Rest.ts +1 -0
  189. package/src/util/Subscription.ts +5 -0
  190. package/src/util/Tagged.ts +5 -0
  191. package/src/util/U2I.ts +1 -0
  192. package/src/util/generator/collect.ts +16 -0
  193. package/src/util/isKey.ts +7 -0
  194. package/src/util/unimplemented.ts +4 -0
  195. package/jest.config.js +0 -4
  196. package/lib/array/array.d.ts +0 -6
  197. package/lib/array/array.js +0 -21
  198. package/lib/array/index.d.ts +0 -11
  199. package/lib/array/index.js +0 -17
  200. package/lib/composition/composition.d.ts +0 -6
  201. package/lib/composition/composition.js +0 -37
  202. package/lib/composition/index.d.ts +0 -9
  203. package/lib/composition/index.js +0 -13
  204. package/lib/composition/types.d.ts +0 -2
  205. package/lib/composition/types.js +0 -2
  206. package/lib/dispatch/getType.d.ts +0 -2
  207. package/lib/dispatch/getType.js +0 -15
  208. package/lib/dispatch/identity.d.ts +0 -2
  209. package/lib/dispatch/identity.js +0 -4
  210. package/lib/dispatch/index.d.ts +0 -22
  211. package/lib/dispatch/index.js +0 -13
  212. package/lib/dispatch/types.d.ts +0 -14
  213. package/lib/dispatch/types.js +0 -16
  214. package/lib/error/error.d.ts +0 -24
  215. package/lib/error/error.js +0 -25
  216. package/lib/error/index.d.ts +0 -2
  217. package/lib/error/index.js +0 -4
  218. package/lib/index.d.ts +0 -67
  219. package/lib/index.js +0 -19
  220. package/lib/multimethod/index.d.ts +0 -7
  221. package/lib/multimethod/index.js +0 -9
  222. package/lib/multimethod/multimethod.d.ts +0 -3
  223. package/lib/multimethod/multimethod.js +0 -101
  224. package/src/array/array.ts +0 -29
  225. package/src/array/index.ts +0 -12
  226. package/src/composition/composition.ts +0 -45
  227. package/src/composition/index.ts +0 -10
  228. package/src/composition/types.ts +0 -6
  229. package/src/dispatch/getType.ts +0 -17
  230. package/src/dispatch/identity.ts +0 -3
  231. package/src/dispatch/index.ts +0 -11
  232. package/src/dispatch/types.ts +0 -15
  233. package/src/error/error.ts +0 -26
  234. package/src/error/index.ts +0 -3
  235. package/src/index.ts +0 -15
  236. package/src/multimethod/index.ts +0 -8
  237. package/src/multimethod/multimethod.test.ts +0 -10
  238. package/src/multimethod/multimethod.ts +0 -148
  239. package/tsconfig.json +0 -12
@@ -1,2 +0,0 @@
1
- import error from './error';
2
- export default error;
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const error_1 = require("./error");
4
- exports.default = error_1.default;
package/lib/index.d.ts DELETED
@@ -1,67 +0,0 @@
1
- /// <reference types="node" />
2
- import array from './array';
3
- import composition from './composition';
4
- import dispatch from './dispatch';
5
- import error from './error';
6
- import multimethod from './multimethod';
7
- export { array, composition, dispatch, error, multimethod };
8
- declare const _default: {
9
- array: {
10
- filter: (fn: any) => (arr: any) => any;
11
- map: (fn: any) => (arr: any) => any;
12
- reduce: (fn: any, initialValue: any) => (arr: any) => any;
13
- reduceRight: (fn: any, initialValue: any) => (arr: any) => any;
14
- reverse: (arr: any) => any;
15
- sort: (fn: any) => (arr: any) => any[];
16
- };
17
- composition: {
18
- compose: import("./composition/types").ChainFunctions;
19
- pipe: import("./composition/types").ChainFunctions;
20
- rail: import("./composition/types").ChainFunctions;
21
- railSync: import("./composition/types").ChainFunctions;
22
- };
23
- dispatch: {
24
- getType: (val: any) => "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "array" | "null" | "regexp";
25
- identity: (x: any) => any;
26
- types: {
27
- array: string;
28
- object: string;
29
- function: string;
30
- string: string;
31
- number: string;
32
- bigint: string;
33
- symbol: string;
34
- regexp: string;
35
- null: string;
36
- undefined: string;
37
- boolean: string;
38
- };
39
- };
40
- error: {
41
- create: ({ name, defaultMessage }: {
42
- name: any;
43
- defaultMessage?: string;
44
- }) => {
45
- new (message?: string): {
46
- name: string;
47
- message: string;
48
- stack?: string;
49
- };
50
- captureStackTrace(targetObject: Object, constructorOpt?: Function): void;
51
- prepareStackTrace?: (err: Error, stackTraces: NodeJS.CallSite[]) => any;
52
- stackTraceLimit: number;
53
- };
54
- toJSON: (error: any) => {
55
- error: {
56
- name: any;
57
- message: any;
58
- stacktrace: any;
59
- };
60
- };
61
- };
62
- multimethod: {
63
- multi: (dispatch: any, ...methods: any[]) => any;
64
- method: (...args: any[]) => (multimethod: any) => any;
65
- };
66
- };
67
- export default _default;
package/lib/index.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const array_1 = require("./array");
4
- exports.array = array_1.default;
5
- const composition_1 = require("./composition");
6
- exports.composition = composition_1.default;
7
- const dispatch_1 = require("./dispatch");
8
- exports.dispatch = dispatch_1.default;
9
- const error_1 = require("./error");
10
- exports.error = error_1.default;
11
- const multimethod_1 = require("./multimethod");
12
- exports.multimethod = multimethod_1.default;
13
- exports.default = {
14
- array: array_1.default,
15
- composition: composition_1.default,
16
- dispatch: dispatch_1.default,
17
- error: error_1.default,
18
- multimethod: multimethod_1.default,
19
- };
@@ -1,7 +0,0 @@
1
- import { multi, method } from './multimethod';
2
- export { multi, method };
3
- declare const _default: {
4
- multi: (dispatch: any, ...methods: any[]) => any;
5
- method: (...args: any[]) => (multimethod: any) => any;
6
- };
7
- export default _default;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const multimethod_1 = require("./multimethod");
4
- exports.multi = multimethod_1.multi;
5
- exports.method = multimethod_1.method;
6
- exports.default = {
7
- multi: multimethod_1.multi,
8
- method: multimethod_1.method,
9
- };
@@ -1,3 +0,0 @@
1
- declare const multi: (dispatch: any, ...methods: any[]) => any;
2
- declare const method: (...args: any[]) => (multimethod: any) => any;
3
- export { multi, method };
@@ -1,101 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const equal = require("deep-strict-equal");
4
- const composition_1 = require("../composition");
5
- const multimethodKey = Symbol ? Symbol('multimethod') : 'multimethod';
6
- const countSegments = (dispatch) => {
7
- let count = 1;
8
- let current = dispatch;
9
- try {
10
- while (typeof current === 'function') {
11
- const next = current();
12
- if (typeof next === 'function') {
13
- count++;
14
- current = next;
15
- }
16
- else {
17
- return count;
18
- }
19
- }
20
- }
21
- catch (_a) { }
22
- return count;
23
- };
24
- const createSimpleTarget = (methodEntries, defaultMethod, dispatch) => {
25
- return (...args) => {
26
- let currentDispatchValue = dispatch(...args);
27
- const entry = methodEntries.find(([dispatchValue]) => equal(dispatchValue, currentDispatchValue));
28
- const target = entry ? entry[1] : defaultMethod;
29
- if (!entry && target === null) {
30
- throw new Error('No method specified for provided arguments');
31
- }
32
- if (typeof target !== 'function') {
33
- return target;
34
- }
35
- return target(...args);
36
- };
37
- };
38
- const createSegmentedTarget = (methodEntries, defaultMethod, dispatch, segmentsCount) => {
39
- const recur = (counter, previousSegmentsArgs = []) => {
40
- if (counter === 1) {
41
- return (...args) => {
42
- const segmentsArgs = [...previousSegmentsArgs, args];
43
- let count = segmentsArgs.length;
44
- let currentDispatchValue = dispatch;
45
- for (let i = 0; i < count; i++) {
46
- currentDispatchValue = currentDispatchValue(...segmentsArgs[i]);
47
- }
48
- const entry = methodEntries.find(([dispatchValue]) => equal(dispatchValue, currentDispatchValue));
49
- const target = entry ? entry[1] : defaultMethod;
50
- if (!entry && target === null) {
51
- throw new Error('No method specified for provided arguments');
52
- }
53
- if (typeof target !== 'function') {
54
- return target;
55
- }
56
- let result = target;
57
- for (let i = 0; i < count; i++) {
58
- result = result(...segmentsArgs[i]);
59
- }
60
- return result;
61
- };
62
- }
63
- return (...args) => {
64
- return recur(counter - 1, [...previousSegmentsArgs, args]);
65
- };
66
- };
67
- return recur(segmentsCount);
68
- };
69
- const createMultimethod = (methodEntries = []) => (defaultMethod = null) => (dispatch, ...methods) => {
70
- const segmentsCount = countSegments(dispatch);
71
- const resultFn = segmentsCount === 1
72
- ? createSimpleTarget(methodEntries, defaultMethod, dispatch)
73
- : createSegmentedTarget(methodEntries, defaultMethod, dispatch, segmentsCount);
74
- resultFn[multimethodKey] = {
75
- methodEntries,
76
- defaultMethod,
77
- dispatch,
78
- };
79
- if (methods.length !== 0) {
80
- return composition_1.pipe(...methods)(resultFn);
81
- }
82
- return resultFn;
83
- };
84
- const multi = createMultimethod()();
85
- exports.multi = multi;
86
- const method = (...args) => (multimethod) => {
87
- if (!multimethod[multimethodKey]) {
88
- throw new Error('Function is not a multimethod');
89
- }
90
- const [first, second] = args;
91
- const isNotDefault = second !== undefined;
92
- const fn = isNotDefault ? second : first;
93
- const dispatchValues = isNotDefault ? first : null;
94
- const { methodEntries, defaultMethod, dispatch } = multimethod[multimethodKey];
95
- if (isNotDefault) {
96
- const newMethodEntries = [[dispatchValues, fn], ...methodEntries];
97
- return createMultimethod(newMethodEntries)(defaultMethod)(dispatch);
98
- }
99
- return createMultimethod(methodEntries)(fn)(dispatch);
100
- };
101
- exports.method = method;
@@ -1,29 +0,0 @@
1
- export const filter = (fn) => (arr) => arr.filter(fn)
2
-
3
- export const map = (fn) => (arr) => arr.map(fn)
4
-
5
- export const reduce = (fn, initialValue) => (arr) =>
6
- arr.reduce(fn, initialValue)
7
-
8
- export const reduceRight = (fn, initialValue) => (arr) =>
9
- arr.reduceRight(fn, initialValue)
10
-
11
- export const reverse = (arr) => arr.reverse()
12
-
13
- export const sort = (fn) => (arr) => {
14
- if (fn) {
15
- return [...arr].sort(fn)
16
- }
17
-
18
- if (typeof arr[0] === 'number') {
19
- return [...arr].sort((a, b) => a - b)
20
- }
21
-
22
- if (typeof arr[0] === 'bigint') {
23
- return [...arr].sort((a, b) => {
24
- return 1
25
- })
26
- }
27
-
28
- return [...arr].sort()
29
- }
@@ -1,12 +0,0 @@
1
- import { filter, map, reduce, reduceRight, reverse, sort } from './array'
2
-
3
- export { filter, map, reduce, reduceRight, reverse, sort }
4
-
5
- export default {
6
- filter,
7
- map,
8
- reduce,
9
- reduceRight,
10
- reverse,
11
- sort,
12
- }
@@ -1,45 +0,0 @@
1
- import { reduce, reduceRight } from '../array'
2
- import { ChainFactory, ChainFunctions } from './types'
3
-
4
- const wrapSync = (fn) => (input) => {
5
- if (input instanceof Error) {
6
- return input
7
- }
8
-
9
- let result
10
-
11
- try {
12
- result = fn(input)
13
- } catch (error) {
14
- result = error
15
- }
16
-
17
- return typeof result === 'undefined' ? input : result
18
- }
19
-
20
- const wrap = (fn) => (input) => {
21
- if (input instanceof Promise) {
22
- return input.then((rawInput) => {
23
- return wrapSync(fn)(rawInput)
24
- })
25
- }
26
-
27
- return wrapSync(fn)(input)
28
- }
29
-
30
- const chain: ChainFactory = (reducingFn, wrappingFn = null) => (...fns) => (
31
- initialArg,
32
- ) => {
33
- return wrappingFn
34
- ? reducingFn((arg: any, fn: Function) => wrappingFn(fn)(arg), initialArg)(
35
- fns,
36
- )
37
- : reducingFn((arg: any, fn: Function) => fn(arg), initialArg)(fns)
38
- }
39
-
40
- const compose: ChainFunctions = chain(reduceRight)
41
- const pipe: ChainFunctions = chain(reduce)
42
- const rail: ChainFunctions = chain(reduce, wrap)
43
- const railSync: ChainFunctions = chain(reduce, wrapSync)
44
-
45
- export { compose, pipe, rail, railSync }
@@ -1,10 +0,0 @@
1
- import { compose, pipe, rail, railSync } from './composition'
2
-
3
- export { compose, pipe, rail, railSync }
4
-
5
- export default {
6
- compose,
7
- pipe,
8
- rail,
9
- railSync,
10
- }
@@ -1,6 +0,0 @@
1
- export type ChainFunctions = (...fns: Function[]) => (initialArg: any) => any
2
-
3
- export type ChainFactory = (
4
- reduceFn: Function,
5
- wrappingFn?: Function,
6
- ) => ChainFunctions
@@ -1,17 +0,0 @@
1
- const getType = (val) => {
2
- if (Array.isArray(val)) {
3
- return 'array'
4
- }
5
-
6
- if (val === null) {
7
- return 'null'
8
- }
9
-
10
- if (val instanceof RegExp) {
11
- return 'regexp'
12
- }
13
-
14
- return typeof val
15
- }
16
-
17
- export default getType
@@ -1,3 +0,0 @@
1
- const identity = (x) => x
2
-
3
- export default identity
@@ -1,11 +0,0 @@
1
- import getType from './getType'
2
- import identity from './identity'
3
- import types from './types'
4
-
5
- export { getType, identity, types }
6
-
7
- export default {
8
- getType,
9
- identity,
10
- types,
11
- }
@@ -1,15 +0,0 @@
1
- const types = {
2
- array: 'array',
3
- object: 'object',
4
- function: 'function',
5
- string: 'string',
6
- number: 'number',
7
- bigint: 'bigint',
8
- symbol: 'symbol',
9
- regexp: 'regexp',
10
- null: 'null',
11
- undefined: 'undefined',
12
- boolean: 'boolean',
13
- }
14
-
15
- export default types
@@ -1,26 +0,0 @@
1
- const create = ({ name, defaultMessage = '' }) => {
2
- const err = class extends Error {
3
- constructor(message = defaultMessage) {
4
- super(message)
5
- this.name = name
6
- this.message = message
7
- }
8
- }
9
-
10
- return err
11
- }
12
-
13
- const toJSON = (error) => {
14
- return {
15
- error: {
16
- name: error.name,
17
- message: error.message,
18
- stacktrace: error.stack,
19
- },
20
- }
21
- }
22
-
23
- export default {
24
- create,
25
- toJSON,
26
- }
@@ -1,3 +0,0 @@
1
- import error from './error'
2
-
3
- export default error
package/src/index.ts DELETED
@@ -1,15 +0,0 @@
1
- import array from './array'
2
- import composition from './composition'
3
- import dispatch from './dispatch'
4
- import error from './error'
5
- import multimethod from './multimethod'
6
-
7
- export { array, composition, dispatch, error, multimethod }
8
-
9
- export default {
10
- array,
11
- composition,
12
- dispatch,
13
- error,
14
- multimethod,
15
- }
@@ -1,8 +0,0 @@
1
- import { multi, method } from './multimethod'
2
-
3
- export { multi, method }
4
-
5
- export default {
6
- multi,
7
- method,
8
- }
@@ -1,10 +0,0 @@
1
- import { multi } from './multimethod'
2
-
3
- describe('multi', () => {
4
- describe('executed with dispatch function only', () => {
5
- it('creates multimethod that throws error: no matching method', () => {
6
- const fn = multi(() => true)
7
- expect(fn).toThrowError('No method specified for provided arguments')
8
- })
9
- })
10
- })
@@ -1,148 +0,0 @@
1
- import * as equal from 'deep-strict-equal'
2
- import { pipe } from '../composition'
3
-
4
- const multimethodKey = Symbol ? Symbol('multimethod') : 'multimethod'
5
-
6
- const countSegments = (dispatch) => {
7
- let count = 1
8
- let current = dispatch
9
-
10
- try {
11
- while (typeof current === 'function') {
12
- const next = current()
13
- if (typeof next === 'function') {
14
- count++
15
- current = next
16
- } else {
17
- return count
18
- }
19
- }
20
- } catch {}
21
-
22
- return count
23
- }
24
-
25
- const createSimpleTarget = (methodEntries, defaultMethod, dispatch) => {
26
- return (...args) => {
27
- let currentDispatchValue = dispatch(...args)
28
-
29
- const entry = methodEntries.find(([dispatchValue]) =>
30
- equal(dispatchValue, currentDispatchValue),
31
- )
32
-
33
- const target = entry ? entry[1] : defaultMethod
34
-
35
- if (!entry && target === null) {
36
- throw new Error('No method specified for provided arguments')
37
- }
38
-
39
- if (typeof target !== 'function') {
40
- return target
41
- }
42
-
43
- return target(...args)
44
- }
45
- }
46
-
47
- const createSegmentedTarget = (
48
- methodEntries,
49
- defaultMethod,
50
- dispatch,
51
- segmentsCount,
52
- ) => {
53
- const recur = (counter, previousSegmentsArgs = []) => {
54
- if (counter === 1) {
55
- return (...args) => {
56
- const segmentsArgs = [...previousSegmentsArgs, args]
57
- let count = segmentsArgs.length
58
-
59
- let currentDispatchValue = dispatch
60
-
61
- for (let i = 0; i < count; i++) {
62
- currentDispatchValue = currentDispatchValue(...segmentsArgs[i])
63
- }
64
-
65
- const entry = methodEntries.find(([dispatchValue]) =>
66
- equal(dispatchValue, currentDispatchValue),
67
- )
68
-
69
- const target = entry ? entry[1] : defaultMethod
70
-
71
- if (!entry && target === null) {
72
- throw new Error('No method specified for provided arguments')
73
- }
74
-
75
- if (typeof target !== 'function') {
76
- return target
77
- }
78
-
79
- let result: any = target
80
-
81
- for (let i = 0; i < count; i++) {
82
- result = result(...segmentsArgs[i])
83
- }
84
-
85
- return result
86
- }
87
- }
88
-
89
- return (...args) => {
90
- return recur(counter - 1, [...previousSegmentsArgs, args])
91
- }
92
- }
93
-
94
- return recur(segmentsCount)
95
- }
96
-
97
- const createMultimethod = (methodEntries = []) => (defaultMethod = null) => (
98
- dispatch,
99
- ...methods
100
- ) => {
101
- const segmentsCount = countSegments(dispatch)
102
-
103
- const resultFn =
104
- segmentsCount === 1
105
- ? createSimpleTarget(methodEntries, defaultMethod, dispatch)
106
- : createSegmentedTarget(
107
- methodEntries,
108
- defaultMethod,
109
- dispatch,
110
- segmentsCount,
111
- )
112
-
113
- resultFn[multimethodKey] = {
114
- methodEntries,
115
- defaultMethod,
116
- dispatch,
117
- }
118
-
119
- if (methods.length !== 0) {
120
- return pipe(...methods)(resultFn)
121
- }
122
-
123
- return resultFn
124
- }
125
-
126
- const multi = createMultimethod()()
127
-
128
- const method = (...args) => (multimethod) => {
129
- if (!multimethod[multimethodKey]) {
130
- throw new Error('Function is not a multimethod')
131
- }
132
-
133
- const [first, second] = args
134
- const isNotDefault = second !== undefined
135
- const fn = isNotDefault ? second : first
136
- const dispatchValues = isNotDefault ? first : null
137
-
138
- const { methodEntries, defaultMethod, dispatch } = multimethod[multimethodKey]
139
-
140
- if (isNotDefault) {
141
- const newMethodEntries = [[dispatchValues, fn], ...methodEntries]
142
- return createMultimethod(newMethodEntries)(defaultMethod)(dispatch)
143
- }
144
-
145
- return createMultimethod(methodEntries)(fn)(dispatch)
146
- }
147
-
148
- export { multi, method }
package/tsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2015",
4
- "module": "commonjs",
5
- "removeComments": true,
6
- "declaration": true,
7
- "outDir": "./lib",
8
- "preserveConstEnums": true
9
- },
10
- "include": ["src"],
11
- "exclude": ["node_modules", "src/**/*.test.ts", "src/**/*.temp.ts"]
12
- }