-
Notifications
You must be signed in to change notification settings - Fork 5
/
ConnectorMode.mjs
79 lines (78 loc) · 2.79 KB
/
ConnectorMode.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator,
m = s && o[s],
i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function() {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var e_1, _a, e_2, _b;
import { process } from './shim.mjs';
import { envDefault } from './shared_impl.mjs';
// Order is significant, earlier = default for shared prefix
// e.g. ETH defaults to ETH-devnet
var knownConnectorModes = [
'ETH-devnet',
'ETH-live',
'ETH-browser',
'ALGO-devnet',
'ALGO-live',
'ALGO-browser',
];
function isKnownConnector(s) {
return (s === 'ETH' || s === 'ALGO');
}
var connectorModeDefaults = {};
try {
// Populate connectorModeDefaults
for (var knownConnectorModes_1 = __values(knownConnectorModes), knownConnectorModes_1_1 = knownConnectorModes_1.next(); !knownConnectorModes_1_1.done; knownConnectorModes_1_1 = knownConnectorModes_1.next()) {
var knownConnectorMode = knownConnectorModes_1_1.value;
var prefix = null;
try {
for (var _c = (e_2 = void 0, __values(knownConnectorMode.split('-'))), _d = _c.next(); !_d.done; _d = _c.next()) {
var piece = _d.value;
prefix = prefix ? "".concat(prefix, "-").concat(piece) : piece;
if (!connectorModeDefaults[prefix]) {
connectorModeDefaults[prefix] = knownConnectorMode;
}
}
} catch (e_2_1) { e_2 = { error: e_2_1 }; } finally {
try {
if (_d && !_d.done && (_b = _c["return"])) _b.call(_c);
} finally { if (e_2) throw e_2.error; }
}
}
} catch (e_1_1) { e_1 = { error: e_1_1 }; } finally {
try {
if (knownConnectorModes_1_1 && !knownConnectorModes_1_1.done && (_a = knownConnectorModes_1["return"])) _a.call(knownConnectorModes_1);
} finally { if (e_1) throw e_1.error; }
}
export function canonicalizeConnectorMode(connectorMode) {
var canonicalized = connectorModeDefaults[connectorMode];
if (canonicalized) {
return canonicalized;
} else {
throw Error("Unrecognized REACH_CONNECTOR_MODE='".concat(connectorMode, "'"));
}
}
export function getConnectorMode() {
var connectorMode = envDefault(process.env.REACH_CONNECTOR_MODE, 'ETH');
return canonicalizeConnectorMode(connectorMode);
}
// The connectorMode arg is optional;
// It will use REACH_CONNECTOR_MODE if 0 args.
export function getConnector(connectorMode) {
connectorMode = connectorMode || getConnectorMode();
var connector = connectorMode.split('-')[0];
if (isKnownConnector(connector)) {
return connector;
} else {
throw Error("impossible: unknown connector: ".concat(connector));
}
}
//# sourceMappingURL=ConnectorMode.js.map