@metamask/snaps-utils 0.24.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.
- package/LICENSE +15 -0
- package/README.md +3 -0
- package/dist/caveats.d.ts +22 -0
- package/dist/caveats.js +27 -0
- package/dist/caveats.js.map +1 -0
- package/dist/cronjob.d.ts +89 -0
- package/dist/cronjob.js +74 -0
- package/dist/cronjob.js.map +1 -0
- package/dist/deep-clone.d.ts +1 -0
- package/dist/deep-clone.js +9 -0
- package/dist/deep-clone.js.map +1 -0
- package/dist/default-endowments.d.ts +4 -0
- package/dist/default-endowments.js +43 -0
- package/dist/default-endowments.js.map +1 -0
- package/dist/eval-worker.d.ts +1 -0
- package/dist/eval-worker.js +32 -0
- package/dist/eval-worker.js.map +1 -0
- package/dist/eval.d.ts +8 -0
- package/dist/eval.js +28 -0
- package/dist/eval.js.map +1 -0
- package/dist/flatMap.d.ts +22 -0
- package/dist/flatMap.js +38 -0
- package/dist/flatMap.js.map +1 -0
- package/dist/fs.d.ts +69 -0
- package/dist/fs.js +144 -0
- package/dist/fs.js.map +1 -0
- package/dist/index.browser.d.ts +13 -0
- package/dist/index.browser.js +30 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/json-rpc.d.ts +10 -0
- package/dist/json-rpc.js +22 -0
- package/dist/json-rpc.js.map +1 -0
- package/dist/manifest/index.browser.d.ts +1 -0
- package/dist/manifest/index.browser.js +18 -0
- package/dist/manifest/index.browser.js.map +1 -0
- package/dist/manifest/index.d.ts +2 -0
- package/dist/manifest/index.js +19 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/manifest.d.ts +75 -0
- package/dist/manifest/manifest.js +237 -0
- package/dist/manifest/manifest.js.map +1 -0
- package/dist/manifest/validation.d.ts +483 -0
- package/dist/manifest/validation.js +142 -0
- package/dist/manifest/validation.js.map +1 -0
- package/dist/mock.d.ts +14 -0
- package/dist/mock.js +107 -0
- package/dist/mock.js.map +1 -0
- package/dist/namespace.d.ts +275 -0
- package/dist/namespace.js +223 -0
- package/dist/namespace.js.map +1 -0
- package/dist/notification.d.ts +66 -0
- package/dist/notification.js +58 -0
- package/dist/notification.js.map +1 -0
- package/dist/npm.d.ts +20 -0
- package/dist/npm.js +73 -0
- package/dist/npm.js.map +1 -0
- package/dist/object.d.ts +8 -0
- package/dist/object.js +15 -0
- package/dist/object.js.map +1 -0
- package/dist/post-process.d.ts +71 -0
- package/dist/post-process.js +321 -0
- package/dist/post-process.js.map +1 -0
- package/dist/snaps.d.ts +165 -0
- package/dist/snaps.js +123 -0
- package/dist/snaps.js.map +1 -0
- package/dist/types.d.ts +107 -0
- package/dist/types.js +82 -0
- package/dist/types.js.map +1 -0
- package/dist/url.d.ts +7 -0
- package/dist/url.js +19 -0
- package/dist/url.js.map +1 -0
- package/dist/versions.d.ts +44 -0
- package/dist/versions.js +77 -0
- package/dist/versions.js.map +1 -0
- package/package.json +100 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 MetaMask
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare enum SnapCaveatType {
|
|
2
|
+
/**
|
|
3
|
+
* Permitted derivation paths, used by `snap_getBip32Entropy`.
|
|
4
|
+
*/
|
|
5
|
+
PermittedDerivationPaths = "permittedDerivationPaths",
|
|
6
|
+
/**
|
|
7
|
+
* Permitted coin types, used by `snap_getBip44Entropy`.
|
|
8
|
+
*/
|
|
9
|
+
PermittedCoinTypes = "permittedCoinTypes",
|
|
10
|
+
/**
|
|
11
|
+
* Permission to use the Snap keyring API.
|
|
12
|
+
*/
|
|
13
|
+
SnapKeyring = "snapKeyring",
|
|
14
|
+
/**
|
|
15
|
+
* Caveat specifying a snap cronjob.
|
|
16
|
+
*/
|
|
17
|
+
SnapCronjob = "snapCronjob",
|
|
18
|
+
/**
|
|
19
|
+
* Caveat specifying access to the transaction origin, used by `endowment:transaction-insight`.
|
|
20
|
+
*/
|
|
21
|
+
TransactionOrigin = "transactionOrigin"
|
|
22
|
+
}
|
package/dist/caveats.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SnapCaveatType = void 0;
|
|
4
|
+
var SnapCaveatType;
|
|
5
|
+
(function (SnapCaveatType) {
|
|
6
|
+
/**
|
|
7
|
+
* Permitted derivation paths, used by `snap_getBip32Entropy`.
|
|
8
|
+
*/
|
|
9
|
+
SnapCaveatType["PermittedDerivationPaths"] = "permittedDerivationPaths";
|
|
10
|
+
/**
|
|
11
|
+
* Permitted coin types, used by `snap_getBip44Entropy`.
|
|
12
|
+
*/
|
|
13
|
+
SnapCaveatType["PermittedCoinTypes"] = "permittedCoinTypes";
|
|
14
|
+
/**
|
|
15
|
+
* Permission to use the Snap keyring API.
|
|
16
|
+
*/
|
|
17
|
+
SnapCaveatType["SnapKeyring"] = "snapKeyring";
|
|
18
|
+
/**
|
|
19
|
+
* Caveat specifying a snap cronjob.
|
|
20
|
+
*/
|
|
21
|
+
SnapCaveatType["SnapCronjob"] = "snapCronjob";
|
|
22
|
+
/**
|
|
23
|
+
* Caveat specifying access to the transaction origin, used by `endowment:transaction-insight`.
|
|
24
|
+
*/
|
|
25
|
+
SnapCaveatType["TransactionOrigin"] = "transactionOrigin";
|
|
26
|
+
})(SnapCaveatType = exports.SnapCaveatType || (exports.SnapCaveatType = {}));
|
|
27
|
+
//# sourceMappingURL=caveats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caveats.js","sourceRoot":"","sources":["../src/caveats.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAyBX;AAzBD,WAAY,cAAc;IACxB;;OAEG;IACH,uEAAqD,CAAA;IAErD;;OAEG;IACH,2DAAyC,CAAA;IAEzC;;OAEG;IACH,6CAA2B,CAAA;IAE3B;;OAEG;IACH,6CAA2B,CAAA;IAE3B;;OAEG;IACH,yDAAuC,CAAA;AACzC,CAAC,EAzBW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAyBzB","sourcesContent":["export enum SnapCaveatType {\n /**\n * Permitted derivation paths, used by `snap_getBip32Entropy`.\n */\n PermittedDerivationPaths = 'permittedDerivationPaths',\n\n /**\n * Permitted coin types, used by `snap_getBip44Entropy`.\n */\n PermittedCoinTypes = 'permittedCoinTypes',\n\n /**\n * Permission to use the Snap keyring API.\n */\n SnapKeyring = 'snapKeyring',\n\n /**\n * Caveat specifying a snap cronjob.\n */\n SnapCronjob = 'snapCronjob',\n\n /**\n * Caveat specifying access to the transaction origin, used by `endowment:transaction-insight`.\n */\n TransactionOrigin = 'transactionOrigin',\n}\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Infer } from 'superstruct';
|
|
2
|
+
export declare const CronjobRpcRequestStruct: import("superstruct").Struct<{
|
|
3
|
+
method: string;
|
|
4
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
5
|
+
id?: string | number | null | undefined;
|
|
6
|
+
jsonrpc?: "2.0" | undefined;
|
|
7
|
+
}, {
|
|
8
|
+
params: import("superstruct").Struct<Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined, null>;
|
|
9
|
+
method: import("superstruct").Struct<string, null>;
|
|
10
|
+
id: import("superstruct").Struct<string | number | null | undefined, unknown>;
|
|
11
|
+
jsonrpc: import("superstruct").Struct<"2.0" | undefined, unknown>;
|
|
12
|
+
}>;
|
|
13
|
+
export declare type CronjobRpcRequest = Infer<typeof CronjobRpcRequestStruct>;
|
|
14
|
+
export declare const CronExpressionStruct: import("superstruct").Struct<string, null>;
|
|
15
|
+
export declare type CronExpression = Infer<typeof CronExpressionStruct>;
|
|
16
|
+
/**
|
|
17
|
+
* Parses a cron expression.
|
|
18
|
+
*
|
|
19
|
+
* @param expression - Expression to parse.
|
|
20
|
+
* @returns A CronExpression class instance.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseCronExpression(expression: string | object): import("cron-parser").CronExpression<false>;
|
|
23
|
+
export declare const CronjobSpecificationStruct: import("superstruct").Struct<{
|
|
24
|
+
expression: string;
|
|
25
|
+
request: {
|
|
26
|
+
method: string;
|
|
27
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
28
|
+
id?: string | number | null | undefined;
|
|
29
|
+
jsonrpc?: "2.0" | undefined;
|
|
30
|
+
};
|
|
31
|
+
}, {
|
|
32
|
+
expression: import("superstruct").Struct<string, null>;
|
|
33
|
+
request: import("superstruct").Struct<{
|
|
34
|
+
method: string;
|
|
35
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
36
|
+
id?: string | number | null | undefined;
|
|
37
|
+
jsonrpc?: "2.0" | undefined;
|
|
38
|
+
}, {
|
|
39
|
+
params: import("superstruct").Struct<Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined, null>;
|
|
40
|
+
method: import("superstruct").Struct<string, null>;
|
|
41
|
+
id: import("superstruct").Struct<string | number | null | undefined, unknown>;
|
|
42
|
+
jsonrpc: import("superstruct").Struct<"2.0" | undefined, unknown>;
|
|
43
|
+
}>;
|
|
44
|
+
}>;
|
|
45
|
+
export declare type CronjobSpecification = Infer<typeof CronjobSpecificationStruct>;
|
|
46
|
+
/**
|
|
47
|
+
* Check if the given value is a {@link CronjobSpecification} object.
|
|
48
|
+
*
|
|
49
|
+
* @param value - The value to check.
|
|
50
|
+
* @returns Whether the value is a valid {@link CronjobSpecification} object.
|
|
51
|
+
*/
|
|
52
|
+
export declare function isCronjobSpecification(value: unknown): boolean;
|
|
53
|
+
export declare const CronjobSpecificationArrayStruct: import("superstruct").Struct<{
|
|
54
|
+
expression: string;
|
|
55
|
+
request: {
|
|
56
|
+
method: string;
|
|
57
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
58
|
+
id?: string | number | null | undefined;
|
|
59
|
+
jsonrpc?: "2.0" | undefined;
|
|
60
|
+
};
|
|
61
|
+
}[], import("superstruct").Struct<{
|
|
62
|
+
expression: string;
|
|
63
|
+
request: {
|
|
64
|
+
method: string;
|
|
65
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
66
|
+
id?: string | number | null | undefined;
|
|
67
|
+
jsonrpc?: "2.0" | undefined;
|
|
68
|
+
};
|
|
69
|
+
}, {
|
|
70
|
+
expression: import("superstruct").Struct<string, null>;
|
|
71
|
+
request: import("superstruct").Struct<{
|
|
72
|
+
method: string;
|
|
73
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
74
|
+
id?: string | number | null | undefined;
|
|
75
|
+
jsonrpc?: "2.0" | undefined;
|
|
76
|
+
}, {
|
|
77
|
+
params: import("superstruct").Struct<Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined, null>;
|
|
78
|
+
method: import("superstruct").Struct<string, null>;
|
|
79
|
+
id: import("superstruct").Struct<string | number | null | undefined, unknown>;
|
|
80
|
+
jsonrpc: import("superstruct").Struct<"2.0" | undefined, unknown>;
|
|
81
|
+
}>;
|
|
82
|
+
}>>;
|
|
83
|
+
/**
|
|
84
|
+
* Check if the given value is an array of {@link CronjobSpecification} objects.
|
|
85
|
+
*
|
|
86
|
+
* @param value - The value to check.
|
|
87
|
+
* @returns Whether the value is a valid array of {@link CronjobSpecification} objects.
|
|
88
|
+
*/
|
|
89
|
+
export declare function isCronjobSpecificationArray(value: unknown): boolean;
|
package/dist/cronjob.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isCronjobSpecificationArray = exports.CronjobSpecificationArrayStruct = exports.isCronjobSpecification = exports.CronjobSpecificationStruct = exports.parseCronExpression = exports.CronExpressionStruct = exports.CronjobRpcRequestStruct = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
const cron_parser_1 = require("cron-parser");
|
|
6
|
+
const superstruct_1 = require("superstruct");
|
|
7
|
+
exports.CronjobRpcRequestStruct = (0, superstruct_1.assign)((0, superstruct_1.partial)((0, superstruct_1.pick)(utils_1.JsonRpcRequestStruct, ['id', 'jsonrpc'])), (0, superstruct_1.omit)(utils_1.JsonRpcRequestStruct, ['id', 'jsonrpc']));
|
|
8
|
+
exports.CronExpressionStruct = (0, superstruct_1.refine)((0, superstruct_1.coerce)((0, superstruct_1.string)(), (0, superstruct_1.object)({
|
|
9
|
+
minute: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
10
|
+
hour: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
11
|
+
dayOfMonth: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
12
|
+
month: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
13
|
+
dayOfWeek: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
14
|
+
}), (value) => {
|
|
15
|
+
var _a, _b, _c, _d, _e;
|
|
16
|
+
return `${(_a = value.minute) !== null && _a !== void 0 ? _a : '*'} ${(_b = value.hour) !== null && _b !== void 0 ? _b : '*'} ${(_c = value.dayOfMonth) !== null && _c !== void 0 ? _c : '*'} ${(_d = value.month) !== null && _d !== void 0 ? _d : '*'} ${(_e = value.dayOfWeek) !== null && _e !== void 0 ? _e : '*'}`;
|
|
17
|
+
}), 'CronExpression', (value) => {
|
|
18
|
+
try {
|
|
19
|
+
(0, cron_parser_1.parseExpression)(value);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
catch (_a) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Parses a cron expression.
|
|
28
|
+
*
|
|
29
|
+
* @param expression - Expression to parse.
|
|
30
|
+
* @returns A CronExpression class instance.
|
|
31
|
+
*/
|
|
32
|
+
function parseCronExpression(expression) {
|
|
33
|
+
const ensureStringExpression = (0, superstruct_1.create)(expression, exports.CronExpressionStruct);
|
|
34
|
+
return (0, cron_parser_1.parseExpression)(ensureStringExpression);
|
|
35
|
+
}
|
|
36
|
+
exports.parseCronExpression = parseCronExpression;
|
|
37
|
+
exports.CronjobSpecificationStruct = (0, superstruct_1.object)({
|
|
38
|
+
expression: exports.CronExpressionStruct,
|
|
39
|
+
request: exports.CronjobRpcRequestStruct,
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* Check if the given value is a {@link CronjobSpecification} object.
|
|
43
|
+
*
|
|
44
|
+
* @param value - The value to check.
|
|
45
|
+
* @returns Whether the value is a valid {@link CronjobSpecification} object.
|
|
46
|
+
*/
|
|
47
|
+
function isCronjobSpecification(value) {
|
|
48
|
+
try {
|
|
49
|
+
(0, superstruct_1.create)(value, exports.CronjobSpecificationStruct);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
catch (_a) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.isCronjobSpecification = isCronjobSpecification;
|
|
57
|
+
exports.CronjobSpecificationArrayStruct = (0, superstruct_1.array)(exports.CronjobSpecificationStruct);
|
|
58
|
+
/**
|
|
59
|
+
* Check if the given value is an array of {@link CronjobSpecification} objects.
|
|
60
|
+
*
|
|
61
|
+
* @param value - The value to check.
|
|
62
|
+
* @returns Whether the value is a valid array of {@link CronjobSpecification} objects.
|
|
63
|
+
*/
|
|
64
|
+
function isCronjobSpecificationArray(value) {
|
|
65
|
+
try {
|
|
66
|
+
(0, superstruct_1.create)(value, exports.CronjobSpecificationArrayStruct);
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
catch (_a) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.isCronjobSpecificationArray = isCronjobSpecificationArray;
|
|
74
|
+
//# sourceMappingURL=cronjob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cronjob.js","sourceRoot":"","sources":["../src/cronjob.ts"],"names":[],"mappings":";;;AAAA,2CAAuD;AACvD,6CAA8C;AAC9C,6CAaqB;AAER,QAAA,uBAAuB,GAAG,IAAA,oBAAM,EAC3C,IAAA,qBAAO,EAAC,IAAA,kBAAI,EAAC,4BAAoB,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,EACtD,IAAA,kBAAI,EAAC,4BAAoB,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAC9C,CAAC;AAGW,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EACxC,IAAA,oBAAM,EACJ,IAAA,oBAAM,GAAE,EACR,IAAA,oBAAM,EAAC;IACL,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC1B,IAAI,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IACxB,UAAU,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC9B,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IACzB,SAAS,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;CAC9B,CAAC,EACF,CAAC,KAAK,EAAE,EAAE;;IACR,OAAA,GAAG,MAAA,KAAK,CAAC,MAAM,mCAAI,GAAG,IAAI,MAAA,KAAK,CAAC,IAAI,mCAAI,GAAG,IAAI,MAAA,KAAK,CAAC,UAAU,mCAAI,GAAG,IACpE,MAAA,KAAK,CAAC,KAAK,mCAAI,GACjB,IAAI,MAAA,KAAK,CAAC,SAAS,mCAAI,GAAG,EAAE,CAAA;CAAA,CAC/B,EACD,gBAAgB,EAChB,CAAC,KAAK,EAAE,EAAE;IACR,IAAI;QACF,IAAA,6BAAe,EAAC,KAAK,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;KACb;IAAC,WAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CACF,CAAC;AAIF;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,UAA2B;IAC7D,MAAM,sBAAsB,GAAG,IAAA,oBAAM,EAAC,UAAU,EAAE,4BAAoB,CAAC,CAAC;IACxE,OAAO,IAAA,6BAAe,EAAC,sBAAsB,CAAC,CAAC;AACjD,CAAC;AAHD,kDAGC;AAEY,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,UAAU,EAAE,4BAAoB;IAChC,OAAO,EAAE,+BAAuB;CACjC,CAAC,CAAC;AAGH;;;;;GAKG;AACH,SAAgB,sBAAsB,CAAC,KAAc;IACnD,IAAI;QACF,IAAA,oBAAM,EAAC,KAAK,EAAE,kCAA0B,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;KACb;IAAC,WAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAPD,wDAOC;AAEY,QAAA,+BAA+B,GAAG,IAAA,mBAAK,EAClD,kCAA0B,CAC3B,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,2BAA2B,CAAC,KAAc;IACxD,IAAI;QACF,IAAA,oBAAM,EAAC,KAAK,EAAE,uCAA+B,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC;KACb;IAAC,WAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAPD,kEAOC","sourcesContent":["import { JsonRpcRequestStruct } from '@metamask/utils';\nimport { parseExpression } from 'cron-parser';\nimport {\n array,\n assign,\n coerce,\n create,\n Infer,\n object,\n omit,\n optional,\n partial,\n pick,\n refine,\n string,\n} from 'superstruct';\n\nexport const CronjobRpcRequestStruct = assign(\n partial(pick(JsonRpcRequestStruct, ['id', 'jsonrpc'])),\n omit(JsonRpcRequestStruct, ['id', 'jsonrpc']),\n);\nexport type CronjobRpcRequest = Infer<typeof CronjobRpcRequestStruct>;\n\nexport const CronExpressionStruct = refine(\n coerce(\n string(),\n object({\n minute: optional(string()),\n hour: optional(string()),\n dayOfMonth: optional(string()),\n month: optional(string()),\n dayOfWeek: optional(string()),\n }),\n (value) =>\n `${value.minute ?? '*'} ${value.hour ?? '*'} ${value.dayOfMonth ?? '*'} ${\n value.month ?? '*'\n } ${value.dayOfWeek ?? '*'}`,\n ),\n 'CronExpression',\n (value) => {\n try {\n parseExpression(value);\n return true;\n } catch {\n return false;\n }\n },\n);\n\nexport type CronExpression = Infer<typeof CronExpressionStruct>;\n\n/**\n * Parses a cron expression.\n *\n * @param expression - Expression to parse.\n * @returns A CronExpression class instance.\n */\nexport function parseCronExpression(expression: string | object) {\n const ensureStringExpression = create(expression, CronExpressionStruct);\n return parseExpression(ensureStringExpression);\n}\n\nexport const CronjobSpecificationStruct = object({\n expression: CronExpressionStruct,\n request: CronjobRpcRequestStruct,\n});\nexport type CronjobSpecification = Infer<typeof CronjobSpecificationStruct>;\n\n/**\n * Check if the given value is a {@link CronjobSpecification} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link CronjobSpecification} object.\n */\nexport function isCronjobSpecification(value: unknown): boolean {\n try {\n create(value, CronjobSpecificationStruct);\n return true;\n } catch {\n return false;\n }\n}\n\nexport const CronjobSpecificationArrayStruct = array(\n CronjobSpecificationStruct,\n);\n\n/**\n * Check if the given value is an array of {@link CronjobSpecification} objects.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid array of {@link CronjobSpecification} objects.\n */\nexport function isCronjobSpecificationArray(value: unknown): boolean {\n try {\n create(value, CronjobSpecificationArrayStruct);\n return true;\n } catch {\n return false;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const deepClone: <T>(input: T) => T;
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
exports.deepClone = void 0;
|
|
7
|
+
const rfdc_1 = __importDefault(require("rfdc"));
|
|
8
|
+
exports.deepClone = (0, rfdc_1.default)({ proto: false, circles: false });
|
|
9
|
+
//# sourceMappingURL=deep-clone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-clone.js","sourceRoot":"","sources":["../src/deep-clone.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAEX,QAAA,SAAS,GAAG,IAAA,cAAI,EAAC,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC","sourcesContent":["import rfdc from 'rfdc';\n\nexport const deepClone = rfdc({ proto: false, circles: false });\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_ENDOWMENTS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Global JavaScript APIs exposed by default to all snaps.
|
|
6
|
+
*/
|
|
7
|
+
exports.DEFAULT_ENDOWMENTS = Object.freeze([
|
|
8
|
+
'atob',
|
|
9
|
+
'btoa',
|
|
10
|
+
'BigInt',
|
|
11
|
+
'console',
|
|
12
|
+
'crypto',
|
|
13
|
+
'Date',
|
|
14
|
+
'Math',
|
|
15
|
+
'setTimeout',
|
|
16
|
+
'clearTimeout',
|
|
17
|
+
'SubtleCrypto',
|
|
18
|
+
'TextDecoder',
|
|
19
|
+
'TextEncoder',
|
|
20
|
+
'URL',
|
|
21
|
+
'WebAssembly',
|
|
22
|
+
'setInterval',
|
|
23
|
+
'clearInterval',
|
|
24
|
+
'Int8Array',
|
|
25
|
+
'Uint8Array',
|
|
26
|
+
'Uint8ClampedArray',
|
|
27
|
+
'Int16Array',
|
|
28
|
+
'Uint16Array',
|
|
29
|
+
'Int32Array',
|
|
30
|
+
'Uint32Array',
|
|
31
|
+
'Float32Array',
|
|
32
|
+
'Float64Array',
|
|
33
|
+
'BigInt64Array',
|
|
34
|
+
'BigUint64Array',
|
|
35
|
+
'DataView',
|
|
36
|
+
'ArrayBuffer',
|
|
37
|
+
// Used by fetch, but also as API for some packages that don't do network connections
|
|
38
|
+
// https://github.com/MetaMask/snaps-monorepo/issues/662
|
|
39
|
+
// https://github.com/MetaMask/snaps-monorepo/discussions/678
|
|
40
|
+
'AbortController',
|
|
41
|
+
'AbortSignal',
|
|
42
|
+
]);
|
|
43
|
+
//# sourceMappingURL=default-endowments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-endowments.js","sourceRoot":"","sources":["../src/default-endowments.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,kBAAkB,GAAsB,MAAM,CAAC,MAAM,CAAC;IACjE,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,MAAM;IACN,MAAM;IACN,YAAY;IACZ,cAAc;IACd,cAAc;IACd,aAAa;IACb,aAAa;IACb,KAAK;IACL,aAAa;IACb,aAAa;IACb,eAAe;IACf,WAAW;IACX,YAAY;IACZ,mBAAmB;IACnB,YAAY;IACZ,aAAa;IACb,YAAY;IACZ,aAAa;IACb,cAAc;IACd,cAAc;IACd,eAAe;IACf,gBAAgB;IAChB,UAAU;IACV,aAAa;IACb,qFAAqF;IACrF,wDAAwD;IACxD,6DAA6D;IAC7D,iBAAiB;IACjB,aAAa;CACd,CAAC,CAAC","sourcesContent":["/**\n * Global JavaScript APIs exposed by default to all snaps.\n */\nexport const DEFAULT_ENDOWMENTS: readonly string[] = Object.freeze([\n 'atob',\n 'btoa',\n 'BigInt',\n 'console',\n 'crypto',\n 'Date',\n 'Math',\n 'setTimeout',\n 'clearTimeout',\n 'SubtleCrypto',\n 'TextDecoder',\n 'TextEncoder',\n 'URL',\n 'WebAssembly',\n 'setInterval',\n 'clearInterval',\n 'Int8Array',\n 'Uint8Array',\n 'Uint8ClampedArray',\n 'Int16Array',\n 'Uint16Array',\n 'Int32Array',\n 'Uint32Array',\n 'Float32Array',\n 'Float64Array',\n 'BigInt64Array',\n 'BigUint64Array',\n 'DataView',\n 'ArrayBuffer',\n // Used by fetch, but also as API for some packages that don't do network connections\n // https://github.com/MetaMask/snaps-monorepo/issues/662\n // https://github.com/MetaMask/snaps-monorepo/discussions/678\n 'AbortController',\n 'AbortSignal',\n]);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'ses/lockdown';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// eslint-disable-next-line import/no-unassigned-import
|
|
4
|
+
require("ses/lockdown");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const mock_1 = require("./mock");
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
lockdown(Object.assign({ consoleTaming: 'unsafe', errorTaming: 'unsafe', mathTaming: 'unsafe', dateTaming: 'unsafe', overrideTaming: 'severe' }, (process.env.NODE_ENV === 'test'
|
|
9
|
+
? {
|
|
10
|
+
domainTaming: 'unsafe',
|
|
11
|
+
}
|
|
12
|
+
: {})));
|
|
13
|
+
/**
|
|
14
|
+
* Get mock endowments that don't do anything. This is useful for running the
|
|
15
|
+
* eval, for snaps that try to communicate with the extension on initialisation,
|
|
16
|
+
* for example.
|
|
17
|
+
*
|
|
18
|
+
* @returns The mock endowments.
|
|
19
|
+
*/
|
|
20
|
+
function getMockEndowments() {
|
|
21
|
+
const endowments = (0, mock_1.generateMockEndowments)();
|
|
22
|
+
return Object.assign(Object.assign({}, endowments), { window: endowments, self: endowments });
|
|
23
|
+
}
|
|
24
|
+
const snapFilePath = process.argv[2];
|
|
25
|
+
const snapModule = { exports: {} };
|
|
26
|
+
new Compartment(Object.assign(Object.assign({}, getMockEndowments()), { module: snapModule, exports: snapModule.exports })).evaluate((0, fs_1.readFileSync)(snapFilePath, 'utf8'));
|
|
27
|
+
const invalidExports = Object.keys(snapModule.exports).filter((snapExport) => !types_1.SNAP_EXPORT_NAMES.includes(snapExport));
|
|
28
|
+
if (invalidExports.length > 0) {
|
|
29
|
+
console.warn(`Invalid snap exports detected:\n${invalidExports.join('\n')}`);
|
|
30
|
+
}
|
|
31
|
+
setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits
|
|
32
|
+
//# sourceMappingURL=eval-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eval-worker.js","sourceRoot":"","sources":["../src/eval-worker.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,wBAAsB;AAEtB,2BAAkC;AAClC,iCAAgD;AAChD,mCAAyD;AAIzD,QAAQ,iBACN,aAAa,EAAE,QAAQ,EACvB,WAAW,EAAE,QAAQ,EACrB,UAAU,EAAE,QAAQ,EACpB,UAAU,EAAE,QAAQ,EACpB,cAAc,EAAE,QAAQ,IAIrB,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM;IACjC,CAAC,CAAC;QACE,YAAY,EAAE,QAAQ;KACvB;IACH,CAAC,CAAC,EAAE,CAAC,EACP,CAAC;AAEH;;;;;;GAMG;AACH,SAAS,iBAAiB;IACxB,MAAM,UAAU,GAAG,IAAA,6BAAsB,GAAE,CAAC;IAC5C,uCACK,UAAU,KACb,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,UAAU,IAChB;AACJ,CAAC;AAED,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAErC,MAAM,UAAU,GAAsB,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAEtD,IAAI,WAAW,iCACV,iBAAiB,EAAE,KACtB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,UAAU,CAAC,OAAO,IAC3B,CAAC,QAAQ,CAAC,IAAA,iBAAY,EAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;AAEhD,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,CAC3D,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,yBAAiB,CAAC,QAAQ,CAAC,UAAyB,CAAC,CACvE,CAAC;AAEF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;IAC7B,OAAO,CAAC,IAAI,CAAC,mCAAmC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;CAC9E;AAED,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,8BAA8B","sourcesContent":["// eslint-disable-next-line import/no-unassigned-import\nimport 'ses/lockdown';\n\nimport { readFileSync } from 'fs';\nimport { generateMockEndowments } from './mock';\nimport { HandlerType, SNAP_EXPORT_NAMES } from './types';\n\ndeclare let lockdown: any, Compartment: any;\n\nlockdown({\n consoleTaming: 'unsafe',\n errorTaming: 'unsafe',\n mathTaming: 'unsafe',\n dateTaming: 'unsafe',\n overrideTaming: 'severe',\n\n // TODO: See if there's an easier way to do this. This file is ran in a\n // separate process, so we can't mock SES with Jest.\n ...(process.env.NODE_ENV === 'test'\n ? {\n domainTaming: 'unsafe',\n }\n : {}),\n});\n\n/**\n * Get mock endowments that don't do anything. This is useful for running the\n * eval, for snaps that try to communicate with the extension on initialisation,\n * for example.\n *\n * @returns The mock endowments.\n */\nfunction getMockEndowments() {\n const endowments = generateMockEndowments();\n return {\n ...endowments,\n window: endowments,\n self: endowments,\n };\n}\n\nconst snapFilePath = process.argv[2];\n\nconst snapModule: { exports?: any } = { exports: {} };\n\nnew Compartment({\n ...getMockEndowments(),\n module: snapModule,\n exports: snapModule.exports,\n}).evaluate(readFileSync(snapFilePath, 'utf8'));\n\nconst invalidExports = Object.keys(snapModule.exports).filter(\n (snapExport) => !SNAP_EXPORT_NAMES.includes(snapExport as HandlerType),\n);\n\nif (invalidExports.length > 0) {\n console.warn(`Invalid snap exports detected:\\n${invalidExports.join('\\n')}`);\n}\n\nsetTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits\n"]}
|
package/dist/eval.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spawn a new process to run the provided bundle in.
|
|
3
|
+
*
|
|
4
|
+
* @param bundlePath - The path to the bundle to run.
|
|
5
|
+
* @returns `null` if the worker ran successfully.
|
|
6
|
+
* @throws If the worker failed to run successfully.
|
|
7
|
+
*/
|
|
8
|
+
export declare function evalBundle(bundlePath: string): Promise<null>;
|
package/dist/eval.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evalBundle = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const fs_1 = require("./fs");
|
|
7
|
+
const WORKER_PATH = (0, path_1.join)(__dirname, 'eval-worker.js');
|
|
8
|
+
/**
|
|
9
|
+
* Spawn a new process to run the provided bundle in.
|
|
10
|
+
*
|
|
11
|
+
* @param bundlePath - The path to the bundle to run.
|
|
12
|
+
* @returns `null` if the worker ran successfully.
|
|
13
|
+
* @throws If the worker failed to run successfully.
|
|
14
|
+
*/
|
|
15
|
+
async function evalBundle(bundlePath) {
|
|
16
|
+
await (0, fs_1.validateFilePath)(bundlePath);
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const worker = (0, child_process_1.fork)(WORKER_PATH, [bundlePath]);
|
|
19
|
+
worker.on('exit', (exitCode) => {
|
|
20
|
+
if (exitCode === 0) {
|
|
21
|
+
return resolve(null);
|
|
22
|
+
}
|
|
23
|
+
return reject(new Error(`Process exited with non-zero exit code: ${exitCode}`));
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
exports.evalBundle = evalBundle;
|
|
28
|
+
//# sourceMappingURL=eval.js.map
|
package/dist/eval.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eval.js","sourceRoot":"","sources":["../src/eval.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAC5B,iDAAqC;AACrC,6BAAwC;AAExC,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AAEtD;;;;;;GAMG;AACI,KAAK,UAAU,UAAU,CAAC,UAAkB;IACjD,MAAM,IAAA,qBAAgB,EAAC,UAAoB,CAAC,CAAC;IAE7C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,IAAA,oBAAI,EAAC,WAAW,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;QAE/C,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,QAAgB,EAAE,EAAE;YACrC,IAAI,QAAQ,KAAK,CAAC,EAAE;gBAClB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;aACtB;YAED,OAAO,MAAM,CACX,IAAI,KAAK,CAAC,2CAA2C,QAAQ,EAAE,CAAC,CACjE,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAhBD,gCAgBC","sourcesContent":["import { join } from 'path';\nimport { fork } from 'child_process';\nimport { validateFilePath } from './fs';\n\nconst WORKER_PATH = join(__dirname, 'eval-worker.js');\n\n/**\n * Spawn a new process to run the provided bundle in.\n *\n * @param bundlePath - The path to the bundle to run.\n * @returns `null` if the worker ran successfully.\n * @throws If the worker failed to run successfully.\n */\nexport async function evalBundle(bundlePath: string): Promise<null> {\n await validateFilePath(bundlePath as string);\n\n return new Promise((resolve, reject) => {\n const worker = fork(WORKER_PATH, [bundlePath]);\n\n worker.on('exit', (exitCode: number) => {\n if (exitCode === 0) {\n return resolve(null);\n }\n\n return reject(\n new Error(`Process exited with non-zero exit code: ${exitCode}`),\n );\n });\n });\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flattens an array of arrays of up to 1 level deep into a single array.
|
|
3
|
+
*
|
|
4
|
+
* This is a non-recursive implementation of `Array.prototype.flat`, which is
|
|
5
|
+
* only available in ES2019 and above.
|
|
6
|
+
*
|
|
7
|
+
* @param array - The array to flatten.
|
|
8
|
+
* @returns The flattened array.
|
|
9
|
+
*/
|
|
10
|
+
export declare const flatten: <Type>(array: (Type | Type[])[]) => Type[];
|
|
11
|
+
/**
|
|
12
|
+
* Maps an array of values using the provided callback, then flattens the result
|
|
13
|
+
* into a single array, up to 1 level deep.
|
|
14
|
+
*
|
|
15
|
+
* This is a non-recursive implementation of `Array.prototype.flatMap`, which is
|
|
16
|
+
* only available in ES2019 and above.
|
|
17
|
+
*
|
|
18
|
+
* @param array - The array to map.
|
|
19
|
+
* @param callback - The callback to map each value with.
|
|
20
|
+
* @returns The mapped and flattened array.
|
|
21
|
+
*/
|
|
22
|
+
export declare const flatMap: <Type, Return>(array: Type[], callback: (value: Type) => Return | Return[]) => Return[];
|
package/dist/flatMap.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.flatMap = exports.flatten = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Flattens an array of arrays of up to 1 level deep into a single array.
|
|
6
|
+
*
|
|
7
|
+
* This is a non-recursive implementation of `Array.prototype.flat`, which is
|
|
8
|
+
* only available in ES2019 and above.
|
|
9
|
+
*
|
|
10
|
+
* @param array - The array to flatten.
|
|
11
|
+
* @returns The flattened array.
|
|
12
|
+
*/
|
|
13
|
+
const flatten = (array) => {
|
|
14
|
+
return array.reduce((acc, cur) => {
|
|
15
|
+
if (Array.isArray(cur)) {
|
|
16
|
+
return [...acc, ...cur];
|
|
17
|
+
}
|
|
18
|
+
acc.push(cur);
|
|
19
|
+
return acc;
|
|
20
|
+
}, []);
|
|
21
|
+
};
|
|
22
|
+
exports.flatten = flatten;
|
|
23
|
+
/**
|
|
24
|
+
* Maps an array of values using the provided callback, then flattens the result
|
|
25
|
+
* into a single array, up to 1 level deep.
|
|
26
|
+
*
|
|
27
|
+
* This is a non-recursive implementation of `Array.prototype.flatMap`, which is
|
|
28
|
+
* only available in ES2019 and above.
|
|
29
|
+
*
|
|
30
|
+
* @param array - The array to map.
|
|
31
|
+
* @param callback - The callback to map each value with.
|
|
32
|
+
* @returns The mapped and flattened array.
|
|
33
|
+
*/
|
|
34
|
+
const flatMap = (array, callback) => {
|
|
35
|
+
return (0, exports.flatten)(array.map(callback));
|
|
36
|
+
};
|
|
37
|
+
exports.flatMap = flatMap;
|
|
38
|
+
//# sourceMappingURL=flatMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatMap.js","sourceRoot":"","sources":["../src/flatMap.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACI,MAAM,OAAO,GAAG,CAAO,KAAwB,EAAU,EAAE;IAChE,OAAO,KAAK,CAAC,MAAM,CAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACvC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACtB,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;SACzB;QACD,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACd,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC,CAAC;AARW,QAAA,OAAO,WAQlB;AAEF;;;;;;;;;;GAUG;AACI,MAAM,OAAO,GAAG,CACrB,KAAa,EACb,QAA4C,EAClC,EAAE;IACZ,OAAO,IAAA,eAAO,EAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;AACtC,CAAC,CAAC;AALW,QAAA,OAAO,WAKlB","sourcesContent":["/**\n * Flattens an array of arrays of up to 1 level deep into a single array.\n *\n * This is a non-recursive implementation of `Array.prototype.flat`, which is\n * only available in ES2019 and above.\n *\n * @param array - The array to flatten.\n * @returns The flattened array.\n */\nexport const flatten = <Type>(array: (Type | Type[])[]): Type[] => {\n return array.reduce<Type[]>((acc, cur) => {\n if (Array.isArray(cur)) {\n return [...acc, ...cur];\n }\n acc.push(cur);\n return acc;\n }, []);\n};\n\n/**\n * Maps an array of values using the provided callback, then flattens the result\n * into a single array, up to 1 level deep.\n *\n * This is a non-recursive implementation of `Array.prototype.flatMap`, which is\n * only available in ES2019 and above.\n *\n * @param array - The array to map.\n * @param callback - The callback to map each value with.\n * @returns The mapped and flattened array.\n */\nexport const flatMap = <Type, Return>(\n array: Type[],\n callback: (value: Type) => Return | Return[],\n): Return[] => {\n return flatten(array.map(callback));\n};\n"]}
|
package/dist/fs.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Json } from '@metamask/utils';
|
|
2
|
+
import { NpmSnapFileNames } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Checks whether the given path string resolves to an existing directory, and
|
|
5
|
+
* optionally creates the directory if it doesn't exist.
|
|
6
|
+
*
|
|
7
|
+
* @param pathString - The path string to check.
|
|
8
|
+
* @param createDir - Whether to create the directory if it doesn't exist.
|
|
9
|
+
* @returns Whether the given path is an existing directory.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isDirectory(pathString: string, createDir: boolean): Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Checks whether the given path string resolves to an existing file.
|
|
14
|
+
*
|
|
15
|
+
* @param pathString - The path string to check.
|
|
16
|
+
* @returns Whether the given path is an existing file.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isFile(pathString: string): Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Reads a `.json` file, parses its contents, and returns them.
|
|
21
|
+
*
|
|
22
|
+
* @param pathString - The path to the JSON file.
|
|
23
|
+
* @returns The parsed contents of the JSON file.
|
|
24
|
+
*/
|
|
25
|
+
export declare function readJsonFile<Type = Json>(pathString: string): Promise<Type>;
|
|
26
|
+
/**
|
|
27
|
+
* Utility function for reading `package.json` or the Snap manifest file.
|
|
28
|
+
* These are assumed to be in the current working directory.
|
|
29
|
+
*
|
|
30
|
+
* @param pathString - The base path of the file to read.
|
|
31
|
+
* @param snapJsonFileName - The name of the file to read.
|
|
32
|
+
* @returns The parsed JSON file.
|
|
33
|
+
*/
|
|
34
|
+
export declare function readSnapJsonFile(pathString: string, snapJsonFileName: NpmSnapFileNames): Promise<Json>;
|
|
35
|
+
/**
|
|
36
|
+
* Gets the complete out file path from an output file name and parent
|
|
37
|
+
* directory path.
|
|
38
|
+
*
|
|
39
|
+
* @param outDir - The path to the out file's parent directory.
|
|
40
|
+
* @param outFileName - The out file's name.
|
|
41
|
+
* @returns The complete path to the out file.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getOutfilePath(outDir: string, outFileName: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Ensures that the outfile name is just a `.js` file name.
|
|
46
|
+
* Throws on validation failure.
|
|
47
|
+
*
|
|
48
|
+
* @param filename - The file name to validate.
|
|
49
|
+
* @returns `true` if validation succeeded.
|
|
50
|
+
* @throws If the file name is invalid.
|
|
51
|
+
*/
|
|
52
|
+
export declare function validateOutfileName(filename: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Validates a file path. Throws on validation failure.
|
|
55
|
+
*
|
|
56
|
+
* @param filePath - The file path to validate.
|
|
57
|
+
* @returns `true` if validation succeeded.
|
|
58
|
+
* @throws If the path does not resolve to a file.
|
|
59
|
+
*/
|
|
60
|
+
export declare function validateFilePath(filePath: string): Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* Validates a directory path. Throws on validation failure.
|
|
63
|
+
*
|
|
64
|
+
* @param dirPath - The directory path to validate.
|
|
65
|
+
* @param createDir - Whether to create the directory if it doesn't exist.
|
|
66
|
+
* @returns `true` if validation succeeded or the directory was created.
|
|
67
|
+
* @throws If the directory does not exist or could not be created.
|
|
68
|
+
*/
|
|
69
|
+
export declare function validateDirPath(dirPath: string, createDir: boolean): Promise<boolean>;
|