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.
- package/LICENSE +201 -15
- package/README.md +96 -81
- package/esm/client/Client.d.ts +39 -0
- package/esm/client/Client.d.ts.map +1 -0
- package/esm/client/Client.js +9 -0
- package/esm/client/Client.js.map +1 -0
- package/esm/client/Store.d.ts +3 -0
- package/esm/client/Store.d.ts.map +1 -0
- package/esm/client/Store.js +3 -0
- package/esm/client/Store.js.map +1 -0
- package/esm/client/Tx.d.ts +40 -0
- package/esm/client/Tx.d.ts.map +1 -0
- package/esm/client/Tx.js +36 -0
- package/esm/client/Tx.js.map +1 -0
- package/esm/client/mod.d.ts +4 -0
- package/esm/client/mod.d.ts.map +1 -0
- package/esm/client/mod.js +5 -0
- package/esm/client/mod.js.map +1 -0
- package/esm/core/Bool.d.ts +104 -0
- package/esm/core/Bool.d.ts.map +1 -0
- package/esm/core/Bool.js +73 -0
- package/esm/core/Bool.js.map +1 -0
- package/esm/core/Bytes.d.ts +39 -0
- package/esm/core/Bytes.d.ts.map +1 -0
- package/esm/core/Bytes.js +7 -0
- package/esm/core/Bytes.js.map +1 -0
- package/esm/core/Call.d.ts +11 -0
- package/esm/core/Call.d.ts.map +1 -0
- package/esm/core/Call.js +23 -0
- package/esm/core/Call.js.map +1 -0
- package/esm/core/Effect.d.ts +20 -0
- package/esm/core/Effect.d.ts.map +1 -0
- package/esm/core/Effect.js +37 -0
- package/esm/core/Effect.js.map +1 -0
- package/esm/core/Hash.d.ts +41 -0
- package/esm/core/Hash.d.ts.map +1 -0
- package/esm/core/Hash.js +8 -0
- package/esm/core/Hash.js.map +1 -0
- package/esm/core/Id.d.ts +198 -0
- package/esm/core/Id.d.ts.map +1 -0
- package/esm/core/Id.js +69 -0
- package/esm/core/Id.js.map +1 -0
- package/esm/core/Int.d.ts +768 -0
- package/esm/core/Int.d.ts.map +1 -0
- package/esm/core/Int.js +201 -0
- package/esm/core/Int.js.map +1 -0
- package/esm/core/Key.d.ts +40 -0
- package/esm/core/Key.d.ts.map +1 -0
- package/esm/core/Key.js +7 -0
- package/esm/core/Key.js.map +1 -0
- package/esm/core/MerkleList.d.ts +105 -0
- package/esm/core/MerkleList.d.ts.map +1 -0
- package/esm/core/MerkleList.js +82 -0
- package/esm/core/MerkleList.js.map +1 -0
- package/esm/core/MerkleMap.d.ts +87 -0
- package/esm/core/MerkleMap.d.ts.map +1 -0
- package/esm/core/MerkleMap.js +67 -0
- package/esm/core/MerkleMap.js.map +1 -0
- package/esm/core/None.d.ts +52 -0
- package/esm/core/None.d.ts.map +1 -0
- package/esm/core/None.js +12 -0
- package/esm/core/None.js.map +1 -0
- package/esm/core/State.d.ts +16 -0
- package/esm/core/State.d.ts.map +1 -0
- package/esm/core/State.js +22 -0
- package/esm/core/State.js.map +1 -0
- package/esm/core/String.d.ts +41 -0
- package/esm/core/String.d.ts.map +1 -0
- package/esm/core/String.js +4 -0
- package/esm/core/String.js.map +1 -0
- package/esm/core/Struct.d.ts +58 -0
- package/esm/core/Struct.d.ts.map +1 -0
- package/esm/core/Struct.js +13 -0
- package/esm/core/Struct.js.map +1 -0
- package/esm/core/Type.d.ts +78 -0
- package/esm/core/Type.d.ts.map +1 -0
- package/esm/core/Type.js +71 -0
- package/esm/core/Type.js.map +1 -0
- package/esm/core/Union.d.ts +43 -0
- package/esm/core/Union.d.ts.map +1 -0
- package/esm/core/Union.js +7 -0
- package/esm/core/Union.js.map +1 -0
- package/esm/core/Use.d.ts +62 -0
- package/esm/core/Use.d.ts.map +1 -0
- package/esm/core/Use.js +16 -0
- package/esm/core/Use.js.map +1 -0
- package/esm/core/mod.d.ts +18 -0
- package/esm/core/mod.d.ts.map +1 -0
- package/esm/core/mod.js +19 -0
- package/esm/core/mod.js.map +1 -0
- package/esm/lib/MerkleList.d.ts +4 -0
- package/esm/lib/MerkleList.d.ts.map +1 -0
- package/esm/lib/MerkleList.js +4 -0
- package/esm/lib/MerkleList.js.map +1 -0
- package/esm/lib/MerkleMap.d.ts +4 -0
- package/esm/lib/MerkleMap.d.ts.map +1 -0
- package/esm/lib/MerkleMap.js +4 -0
- package/esm/lib/MerkleMap.js.map +1 -0
- package/esm/lib/mod.d.ts +3 -0
- package/esm/lib/mod.d.ts.map +1 -0
- package/esm/lib/mod.js +3 -0
- package/esm/lib/mod.js.map +1 -0
- package/esm/mod.d.ts +3 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +4 -0
- package/esm/mod.js.map +1 -0
- package/esm/package.json +3 -0
- package/esm/test/Signer.d.ts +10 -0
- package/esm/test/Signer.d.ts.map +1 -0
- package/esm/test/Signer.js +13 -0
- package/esm/test/Signer.js.map +1 -0
- package/esm/test/mod.d.ts +2 -0
- package/esm/test/mod.d.ts.map +1 -0
- package/esm/test/mod.js +2 -0
- package/esm/test/mod.js.map +1 -0
- package/esm/util/AbortController.d.ts +4 -0
- package/esm/util/AbortController.d.ts.map +1 -0
- package/esm/util/AbortController.js +2 -0
- package/esm/util/AbortController.js.map +1 -0
- package/esm/util/ArrayOfLength.d.ts +2 -0
- package/esm/util/ArrayOfLength.d.ts.map +1 -0
- package/esm/util/ArrayOfLength.js +2 -0
- package/esm/util/ArrayOfLength.js.map +1 -0
- package/esm/util/Flatten.d.ts +4 -0
- package/esm/util/Flatten.d.ts.map +1 -0
- package/esm/util/Flatten.js +2 -0
- package/esm/util/Flatten.js.map +1 -0
- package/esm/util/Rest.d.ts +2 -0
- package/esm/util/Rest.d.ts.map +1 -0
- package/esm/util/Rest.js +2 -0
- package/esm/util/Rest.js.map +1 -0
- package/esm/util/Subscription.d.ts +5 -0
- package/esm/util/Subscription.d.ts.map +1 -0
- package/esm/util/Subscription.js +2 -0
- package/esm/util/Subscription.js.map +1 -0
- package/esm/util/Tagged.d.ts +6 -0
- package/esm/util/Tagged.d.ts.map +1 -0
- package/esm/util/Tagged.js +6 -0
- package/esm/util/Tagged.js.map +1 -0
- package/esm/util/U2I.d.ts +2 -0
- package/esm/util/U2I.d.ts.map +1 -0
- package/esm/util/U2I.js +2 -0
- package/esm/util/U2I.js.map +1 -0
- package/esm/util/generator/collect.d.ts +3 -0
- package/esm/util/generator/collect.d.ts.map +1 -0
- package/esm/util/generator/collect.js +16 -0
- package/esm/util/generator/collect.js.map +1 -0
- package/esm/util/isKey.d.ts +2 -0
- package/esm/util/isKey.d.ts.map +1 -0
- package/esm/util/isKey.js +8 -0
- package/esm/util/isKey.js.map +1 -0
- package/esm/util/unimplemented.d.ts +2 -0
- package/esm/util/unimplemented.d.ts.map +1 -0
- package/esm/util/unimplemented.js +6 -0
- package/esm/util/unimplemented.js.map +1 -0
- package/package.json +21 -21
- package/src/client/Client.ts +49 -0
- package/src/client/Store.ts +1 -0
- package/src/client/Tx.ts +62 -0
- package/src/client/mod.ts +5 -0
- package/src/core/Bool.ts +75 -0
- package/src/core/Bytes.ts +9 -0
- package/src/core/Call.ts +38 -0
- package/src/core/Effect.ts +87 -0
- package/src/core/Hash.ts +23 -0
- package/src/core/Id.ts +97 -0
- package/src/core/Int.ts +177 -0
- package/src/core/Key.ts +9 -0
- package/src/core/MerkleList.ts +92 -0
- package/src/core/MerkleMap.ts +86 -0
- package/src/core/None.ts +11 -0
- package/src/core/State.ts +31 -0
- package/src/core/String.ts +5 -0
- package/src/core/Struct.ts +49 -0
- package/src/core/Type.ts +120 -0
- package/src/core/Union.ts +17 -0
- package/src/core/Use.ts +33 -0
- package/src/core/mod.ts +19 -0
- package/src/lib/MerkleList.ts +4 -0
- package/src/lib/MerkleMap.ts +4 -0
- package/src/lib/mod.ts +2 -0
- package/src/mod.ts +4 -0
- package/src/test/Signer.ts +22 -0
- package/src/test/mod.ts +1 -0
- package/src/util/AbortController.ts +3 -0
- package/src/util/ArrayOfLength.ts +5 -0
- package/src/util/Flatten.ts +2 -0
- package/src/util/Rest.ts +1 -0
- package/src/util/Subscription.ts +5 -0
- package/src/util/Tagged.ts +5 -0
- package/src/util/U2I.ts +1 -0
- package/src/util/generator/collect.ts +16 -0
- package/src/util/isKey.ts +7 -0
- package/src/util/unimplemented.ts +4 -0
- package/jest.config.js +0 -4
- package/lib/array/array.d.ts +0 -6
- package/lib/array/array.js +0 -21
- package/lib/array/index.d.ts +0 -11
- package/lib/array/index.js +0 -17
- package/lib/composition/composition.d.ts +0 -6
- package/lib/composition/composition.js +0 -37
- package/lib/composition/index.d.ts +0 -9
- package/lib/composition/index.js +0 -13
- package/lib/composition/types.d.ts +0 -2
- package/lib/composition/types.js +0 -2
- package/lib/dispatch/getType.d.ts +0 -2
- package/lib/dispatch/getType.js +0 -15
- package/lib/dispatch/identity.d.ts +0 -2
- package/lib/dispatch/identity.js +0 -4
- package/lib/dispatch/index.d.ts +0 -22
- package/lib/dispatch/index.js +0 -13
- package/lib/dispatch/types.d.ts +0 -14
- package/lib/dispatch/types.js +0 -16
- package/lib/error/error.d.ts +0 -24
- package/lib/error/error.js +0 -25
- package/lib/error/index.d.ts +0 -2
- package/lib/error/index.js +0 -4
- package/lib/index.d.ts +0 -67
- package/lib/index.js +0 -19
- package/lib/multimethod/index.d.ts +0 -7
- package/lib/multimethod/index.js +0 -9
- package/lib/multimethod/multimethod.d.ts +0 -3
- package/lib/multimethod/multimethod.js +0 -101
- package/src/array/array.ts +0 -29
- package/src/array/index.ts +0 -12
- package/src/composition/composition.ts +0 -45
- package/src/composition/index.ts +0 -10
- package/src/composition/types.ts +0 -6
- package/src/dispatch/getType.ts +0 -17
- package/src/dispatch/identity.ts +0 -3
- package/src/dispatch/index.ts +0 -11
- package/src/dispatch/types.ts +0 -15
- package/src/error/error.ts +0 -26
- package/src/error/index.ts +0 -3
- package/src/index.ts +0 -15
- package/src/multimethod/index.ts +0 -8
- package/src/multimethod/multimethod.test.ts +0 -10
- package/src/multimethod/multimethod.ts +0 -148
- package/tsconfig.json +0 -12
package/lib/error/index.d.ts
DELETED
package/lib/error/index.js
DELETED
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
|
-
};
|
package/lib/multimethod/index.js
DELETED
|
@@ -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,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;
|
package/src/array/array.ts
DELETED
|
@@ -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
|
-
}
|
package/src/array/index.ts
DELETED
|
@@ -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 }
|
package/src/composition/index.ts
DELETED
package/src/composition/types.ts
DELETED
package/src/dispatch/getType.ts
DELETED
package/src/dispatch/identity.ts
DELETED
package/src/dispatch/index.ts
DELETED
package/src/dispatch/types.ts
DELETED
|
@@ -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
|
package/src/error/error.ts
DELETED
|
@@ -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
|
-
}
|
package/src/error/index.ts
DELETED
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
|
-
}
|
package/src/multimethod/index.ts
DELETED
|
@@ -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
|
-
}
|