@endo/compartment-mapper 1.6.2 → 2.0.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/package.json +12 -16
- package/src/archive-lite.d.ts +7 -7
- package/src/archive-lite.d.ts.map +1 -1
- package/src/archive-lite.js +78 -27
- package/src/archive.d.ts.map +1 -1
- package/src/archive.js +7 -0
- package/src/bundle-lite.d.ts +3 -3
- package/src/bundle-lite.d.ts.map +1 -1
- package/src/bundle-lite.js +19 -24
- package/src/bundle.d.ts +3 -3
- package/src/bundle.d.ts.map +1 -1
- package/src/bundle.js +19 -24
- package/src/capture-lite.d.ts +2 -2
- package/src/capture-lite.d.ts.map +1 -1
- package/src/capture-lite.js +217 -25
- package/src/compartment-map.d.ts +9 -2
- package/src/compartment-map.d.ts.map +1 -1
- package/src/compartment-map.js +737 -254
- package/src/digest.d.ts +22 -2
- package/src/digest.d.ts.map +1 -1
- package/src/digest.js +179 -56
- package/src/generic-graph.d.ts +84 -0
- package/src/generic-graph.d.ts.map +1 -0
- package/src/generic-graph.js +356 -0
- package/src/guards.d.ts +18 -0
- package/src/guards.d.ts.map +1 -0
- package/src/guards.js +109 -0
- package/src/hooks.md +124 -0
- package/src/import-archive-lite.d.ts.map +1 -1
- package/src/import-archive-lite.js +15 -11
- package/src/import-archive.d.ts +5 -19
- package/src/import-archive.d.ts.map +1 -1
- package/src/import-archive.js +7 -27
- package/src/import-hook.d.ts +4 -3
- package/src/import-hook.d.ts.map +1 -1
- package/src/import-hook.js +156 -71
- package/src/import-lite.d.ts +6 -6
- package/src/import-lite.d.ts.map +1 -1
- package/src/import-lite.js +8 -5
- package/src/import.d.ts +3 -3
- package/src/import.d.ts.map +1 -1
- package/src/import.js +16 -6
- package/src/infer-exports.d.ts.map +1 -1
- package/src/infer-exports.js +16 -6
- package/src/json.d.ts +1 -1
- package/src/json.d.ts.map +1 -1
- package/src/json.js +10 -3
- package/src/link.d.ts +4 -3
- package/src/link.d.ts.map +1 -1
- package/src/link.js +70 -58
- package/src/node-modules.d.ts +5 -3
- package/src/node-modules.d.ts.map +1 -1
- package/src/node-modules.js +648 -245
- package/src/node-powers.d.ts +6 -5
- package/src/node-powers.d.ts.map +1 -1
- package/src/node-powers.js +11 -8
- package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
- package/src/parse-cjs-shared-export-wrapper.js +3 -1
- package/src/policy-format.d.ts +22 -5
- package/src/policy-format.d.ts.map +1 -1
- package/src/policy-format.js +342 -108
- package/src/policy.d.ts +13 -28
- package/src/policy.d.ts.map +1 -1
- package/src/policy.js +161 -106
- package/src/types/canonical-name.d.ts +97 -0
- package/src/types/canonical-name.d.ts.map +1 -0
- package/src/types/canonical-name.ts +151 -0
- package/src/types/compartment-map-schema.d.ts +114 -35
- package/src/types/compartment-map-schema.d.ts.map +1 -1
- package/src/types/compartment-map-schema.ts +202 -37
- package/src/types/external.d.ts +173 -29
- package/src/types/external.d.ts.map +1 -1
- package/src/types/external.ts +221 -27
- package/src/types/generic-graph.d.ts +17 -0
- package/src/types/generic-graph.d.ts.map +1 -0
- package/src/types/generic-graph.ts +17 -0
- package/src/types/internal.d.ts +24 -42
- package/src/types/internal.d.ts.map +1 -1
- package/src/types/internal.ts +52 -50
- package/src/types/node-modules.d.ts +101 -17
- package/src/types/node-modules.d.ts.map +1 -1
- package/src/types/node-modules.ts +142 -17
- package/src/types/policy-schema.d.ts +26 -11
- package/src/types/policy-schema.d.ts.map +1 -1
- package/src/types/policy-schema.ts +29 -16
- package/src/types/policy.d.ts +6 -2
- package/src/types/policy.d.ts.map +1 -1
- package/src/types/policy.ts +7 -2
- package/src/types/powers.d.ts +38 -11
- package/src/types/powers.d.ts.map +1 -1
- package/src/types/powers.ts +50 -17
- package/src/types/typescript.d.ts +28 -0
- package/src/types/typescript.d.ts.map +1 -1
- package/src/types/typescript.ts +37 -1
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import type { WILDCARD_POLICY_VALUE } from '../policy-format.js';
|
|
9
|
+
|
|
8
10
|
/* eslint-disable no-use-before-define */
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -14,7 +16,7 @@ export type FullAttenuationDefinition = {
|
|
|
14
16
|
/** The type of attenuation. */
|
|
15
17
|
attenuate: string;
|
|
16
18
|
/** The parameters for the attenuation. */
|
|
17
|
-
params
|
|
19
|
+
params?: ImplicitAttenuationDefinition;
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
/**
|
|
@@ -38,7 +40,7 @@ export type UnifiedAttenuationDefinition = {
|
|
|
38
40
|
/**
|
|
39
41
|
* A type representing a wildcard policy, which can be 'any'.
|
|
40
42
|
*/
|
|
41
|
-
export type WildcardPolicy =
|
|
43
|
+
export type WildcardPolicy = typeof WILDCARD_POLICY_VALUE;
|
|
42
44
|
|
|
43
45
|
/**
|
|
44
46
|
* A type representing a property policy, which is a record of string keys and
|
|
@@ -51,7 +53,9 @@ export type PropertyPolicy = Record<string, boolean>;
|
|
|
51
53
|
* wildcard policy}, a property policy, `undefined`, or defined by an
|
|
52
54
|
* attenuator
|
|
53
55
|
*/
|
|
54
|
-
export type PolicyItem<T = void> =
|
|
56
|
+
export type PolicyItem<T = void> = [T] extends [void]
|
|
57
|
+
? WildcardPolicy | PropertyPolicy
|
|
58
|
+
: WildcardPolicy | PropertyPolicy | T;
|
|
55
59
|
|
|
56
60
|
/**
|
|
57
61
|
* An object representing a nested attenuation definition.
|
|
@@ -70,22 +74,36 @@ export type PackagePolicy<
|
|
|
70
74
|
BuiltinsPolicyItem = void,
|
|
71
75
|
ExtraOptions = unknown,
|
|
72
76
|
> = {
|
|
73
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* The default attenuator, if any.
|
|
79
|
+
*/
|
|
74
80
|
defaultAttenuator?: string | undefined;
|
|
75
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* The policy item for packages.
|
|
83
|
+
*/
|
|
76
84
|
packages?: PolicyItem<PackagePolicyItem> | undefined;
|
|
77
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* The policy item or full attenuation definition for globals.
|
|
87
|
+
*/
|
|
78
88
|
globals?: AttenuationDefinition | PolicyItem<GlobalsPolicyItem> | undefined;
|
|
79
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* The policy item or nested attenuation definition for builtins.
|
|
91
|
+
*/
|
|
80
92
|
builtins?:
|
|
81
93
|
| NestedAttenuationDefinition
|
|
82
94
|
| PolicyItem<BuiltinsPolicyItem>
|
|
83
95
|
| undefined;
|
|
84
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Whether to disable global freeze.
|
|
98
|
+
*/
|
|
85
99
|
noGlobalFreeze?: boolean | undefined;
|
|
86
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* Whether to allow dynamic imports
|
|
102
|
+
*/
|
|
87
103
|
dynamic?: boolean | undefined;
|
|
88
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* Any additional user-defined options can be added to the policy here
|
|
106
|
+
*/
|
|
89
107
|
options?: ExtraOptions | undefined;
|
|
90
108
|
};
|
|
91
109
|
|
|
@@ -125,9 +143,4 @@ export type Policy<
|
|
|
125
143
|
export type SomePolicy = Policy<any, any, any, any>;
|
|
126
144
|
|
|
127
145
|
/** Any {@link PackagePolicy} */
|
|
128
|
-
export type SomePackagePolicy = PackagePolicy<
|
|
129
|
-
PolicyItem,
|
|
130
|
-
PolicyItem,
|
|
131
|
-
PolicyItem,
|
|
132
|
-
unknown
|
|
133
|
-
>;
|
|
146
|
+
export type SomePackagePolicy = PackagePolicy<void, void, void, unknown>;
|
package/src/types/policy.d.ts
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import type { SomeObject } from './typescript.js';
|
|
6
|
+
import type { LiteralUnion, SomeObject } from './typescript.js';
|
|
7
7
|
export type PackageNamingKit = {
|
|
8
8
|
/** true if location is the entry compartment */
|
|
9
9
|
isEntry?: boolean | undefined;
|
|
10
|
-
name
|
|
10
|
+
name?: LiteralUnion<'<ATTENUATORS>', string>;
|
|
11
11
|
path: Array<string>;
|
|
12
12
|
};
|
|
13
13
|
export type Attenuator<GlobalParams extends [any, ...any[]] = [any, ...any[]], ModuleParams extends [any, ...any[]] = [any, ...any[]]> = {
|
|
@@ -19,4 +19,8 @@ export type ModuleAttenuatorFn<Params extends [any, ...any[]] = [any, ...any[]],
|
|
|
19
19
|
export type DeferredAttenuatorsProvider = {
|
|
20
20
|
import: (attenuatorSpecifier: string | null) => Promise<Attenuator>;
|
|
21
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* A fieldname of `PackagePolicy`; used with `policyLookupHelper()`
|
|
24
|
+
*/
|
|
25
|
+
export type PolicyEnforcementField = 'builtins' | 'globals' | 'packages';
|
|
22
26
|
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["policy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["policy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEhE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gDAAgD;IAChD,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,IAAI,CAAC,EAAE,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAC7C,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,UAAU,CACpB,YAAY,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,EA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import type { LiteralUnion, SomeObject } from './typescript.js';
|
|
10
10
|
|
|
11
11
|
export type PackageNamingKit = {
|
|
12
12
|
/** true if location is the entry compartment */
|
|
13
13
|
isEntry?: boolean | undefined;
|
|
14
|
-
name
|
|
14
|
+
name?: LiteralUnion<'<ATTENUATORS>', string>;
|
|
15
15
|
path: Array<string>;
|
|
16
16
|
};
|
|
17
17
|
|
|
@@ -42,3 +42,8 @@ export type ModuleAttenuatorFn<
|
|
|
42
42
|
export type DeferredAttenuatorsProvider = {
|
|
43
43
|
import: (attenuatorSpecifier: string | null) => Promise<Attenuator>;
|
|
44
44
|
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A fieldname of `PackagePolicy`; used with `policyLookupHelper()`
|
|
48
|
+
*/
|
|
49
|
+
export type PolicyEnforcementField = 'builtins' | 'globals' | 'packages';
|
package/src/types/powers.d.ts
CHANGED
|
@@ -7,8 +7,13 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
import type { SomeObject } from './typescript.js';
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* All available read powers
|
|
12
|
+
*
|
|
13
|
+
* @template T The expected input/output type of the {@link CanonicalFn}.
|
|
14
|
+
*/
|
|
15
|
+
export type ReadPowers<T extends string = any> = {
|
|
16
|
+
canonical: CanonicalFn<T>;
|
|
12
17
|
read: ReadFn;
|
|
13
18
|
maybeRead?: MaybeReadFn;
|
|
14
19
|
readNow?: ReadNowFn;
|
|
@@ -19,7 +24,10 @@ export type ReadPowers = {
|
|
|
19
24
|
requireResolve?: RequireResolveFn;
|
|
20
25
|
isAbsolute?: IsAbsoluteFn;
|
|
21
26
|
};
|
|
22
|
-
|
|
27
|
+
/**
|
|
28
|
+
* @template T The expected input/output type of the {@link CanonicalFn}.
|
|
29
|
+
*/
|
|
30
|
+
export type MaybeReadPowers<T extends string = any> = ReadPowers<T> & {
|
|
23
31
|
maybeRead: MaybeReadFn;
|
|
24
32
|
};
|
|
25
33
|
/**
|
|
@@ -31,31 +39,45 @@ export type MaybeReadPowers = ReadPowers & {
|
|
|
31
39
|
* 2. Prop `maybeReadNow` is a function
|
|
32
40
|
* 3. Prop `fileURLToPath` is a function
|
|
33
41
|
* 4. Prop `isAbsolute` is a function
|
|
42
|
+
*
|
|
43
|
+
* @template T The expected input/output type of the {@link CanonicalFn}.
|
|
34
44
|
*/
|
|
35
|
-
export type ReadNowPowers = Omit<ReadPowers
|
|
45
|
+
export type ReadNowPowers<T extends string = any> = Omit<ReadPowers<T>, ReadNowPowersProp> & Required<Pick<ReadPowers<T>, ReadNowPowersProp>>;
|
|
36
46
|
/**
|
|
37
47
|
* These properties are necessary for dynamic require support
|
|
38
48
|
*/
|
|
39
49
|
export type ReadNowPowersProp = 'fileURLToPath' | 'isAbsolute' | 'maybeReadNow';
|
|
40
50
|
/**
|
|
41
51
|
* Returns a canonical URL for a given URL, following redirects or symbolic
|
|
42
|
-
* links if any exist along the path.
|
|
43
|
-
*
|
|
52
|
+
* links if any exist along the path. Must return the given logical location if
|
|
53
|
+
* the real location does not exist.
|
|
54
|
+
*
|
|
55
|
+
* @template T The expected input/output type of the {@link CanonicalFn}. This
|
|
56
|
+
* may be a particular type of URL, such as a `FileUrlString`.
|
|
57
|
+
*/
|
|
58
|
+
export type CanonicalFn<T extends string = string> = (location: T) => Promise<T>;
|
|
59
|
+
/**
|
|
60
|
+
* A function which reads some location and resolves with bytes.
|
|
44
61
|
*/
|
|
45
|
-
export type CanonicalFn = (location: string) => Promise<string>;
|
|
46
62
|
export type ReadFn = (location: string) => Promise<Uint8Array>;
|
|
47
63
|
/**
|
|
48
64
|
* A resolution of `undefined` indicates `ENOENT` or the equivalent.
|
|
49
65
|
*/
|
|
50
66
|
export type MaybeReadFn = (location: string) => Promise<Uint8Array | undefined>;
|
|
67
|
+
/**
|
|
68
|
+
* A function which reads some location and returns bytes.
|
|
69
|
+
*/
|
|
51
70
|
export type ReadNowFn = (location: string) => Uint8Array;
|
|
52
71
|
/**
|
|
53
72
|
* A resolution of `undefined` indicates `ENOENT` or the equivalent.
|
|
54
73
|
*/
|
|
55
74
|
export type MaybeReadNowFn = (location: string) => Uint8Array | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Returns a string hash of a byte array
|
|
77
|
+
*/
|
|
56
78
|
export type HashFn = (bytes: Uint8Array) => string;
|
|
57
|
-
export type FileURLToPathFn =
|
|
58
|
-
export type PathToFileURLFn =
|
|
79
|
+
export type FileURLToPathFn = (url: URL | string) => string;
|
|
80
|
+
export type PathToFileURLFn = (path: string) => URL;
|
|
59
81
|
export type RequireResolveFn = (fromLocation: string, specifier: string, options?: {
|
|
60
82
|
paths?: string[];
|
|
61
83
|
} | undefined) => any;
|
|
@@ -63,9 +85,14 @@ export type IsAbsoluteFn = (location: string) => boolean;
|
|
|
63
85
|
export type ArchiveReader = {
|
|
64
86
|
read: ReadFn;
|
|
65
87
|
};
|
|
66
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Read powers with a {@link HashFn}.
|
|
90
|
+
*
|
|
91
|
+
* @template T The expected input/output type of the {@link CanonicalFn}.
|
|
92
|
+
*/
|
|
93
|
+
export type HashPowers<T extends string = any> = {
|
|
67
94
|
read: ReadFn;
|
|
68
|
-
canonical: CanonicalFn
|
|
95
|
+
canonical: CanonicalFn<T>;
|
|
69
96
|
computeSha512: HashFn;
|
|
70
97
|
};
|
|
71
98
|
export type WritePowers = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"powers.d.ts","sourceRoot":"","sources":["powers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAIlD,MAAM,MAAM,UAAU,GAAG;
|
|
1
|
+
{"version":3,"file":"powers.d.ts","sourceRoot":"","sources":["powers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC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aAAa,GAAG;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,UAAU,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;AAInD,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,SAAS,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC"}
|
package/src/types/powers.ts
CHANGED
|
@@ -11,10 +11,15 @@
|
|
|
11
11
|
|
|
12
12
|
import type { SomeObject } from './typescript.js';
|
|
13
13
|
|
|
14
|
-
//
|
|
14
|
+
// #region read
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* All available read powers
|
|
18
|
+
*
|
|
19
|
+
* @template T The expected input/output type of the {@link CanonicalFn}.
|
|
20
|
+
*/
|
|
21
|
+
export type ReadPowers<T extends string = any> = {
|
|
22
|
+
canonical: CanonicalFn<T>;
|
|
18
23
|
read: ReadFn;
|
|
19
24
|
maybeRead?: MaybeReadFn;
|
|
20
25
|
readNow?: ReadNowFn;
|
|
@@ -26,7 +31,10 @@ export type ReadPowers = {
|
|
|
26
31
|
isAbsolute?: IsAbsoluteFn;
|
|
27
32
|
};
|
|
28
33
|
|
|
29
|
-
|
|
34
|
+
/**
|
|
35
|
+
* @template T The expected input/output type of the {@link CanonicalFn}.
|
|
36
|
+
*/
|
|
37
|
+
export type MaybeReadPowers<T extends string = any> = ReadPowers<T> & {
|
|
30
38
|
maybeRead: MaybeReadFn;
|
|
31
39
|
};
|
|
32
40
|
|
|
@@ -39,9 +47,14 @@ export type MaybeReadPowers = ReadPowers & {
|
|
|
39
47
|
* 2. Prop `maybeReadNow` is a function
|
|
40
48
|
* 3. Prop `fileURLToPath` is a function
|
|
41
49
|
* 4. Prop `isAbsolute` is a function
|
|
50
|
+
*
|
|
51
|
+
* @template T The expected input/output type of the {@link CanonicalFn}.
|
|
42
52
|
*/
|
|
43
|
-
export type ReadNowPowers = Omit<
|
|
44
|
-
|
|
53
|
+
export type ReadNowPowers<T extends string = any> = Omit<
|
|
54
|
+
ReadPowers<T>,
|
|
55
|
+
ReadNowPowersProp
|
|
56
|
+
> &
|
|
57
|
+
Required<Pick<ReadPowers<T>, ReadNowPowersProp>>;
|
|
45
58
|
|
|
46
59
|
/**
|
|
47
60
|
* These properties are necessary for dynamic require support
|
|
@@ -50,11 +63,19 @@ export type ReadNowPowersProp = 'fileURLToPath' | 'isAbsolute' | 'maybeReadNow';
|
|
|
50
63
|
|
|
51
64
|
/**
|
|
52
65
|
* Returns a canonical URL for a given URL, following redirects or symbolic
|
|
53
|
-
* links if any exist along the path.
|
|
54
|
-
*
|
|
66
|
+
* links if any exist along the path. Must return the given logical location if
|
|
67
|
+
* the real location does not exist.
|
|
68
|
+
*
|
|
69
|
+
* @template T The expected input/output type of the {@link CanonicalFn}. This
|
|
70
|
+
* may be a particular type of URL, such as a `FileUrlString`.
|
|
55
71
|
*/
|
|
56
|
-
export type CanonicalFn =
|
|
72
|
+
export type CanonicalFn<T extends string = string> = (
|
|
73
|
+
location: T,
|
|
74
|
+
) => Promise<T>;
|
|
57
75
|
|
|
76
|
+
/**
|
|
77
|
+
* A function which reads some location and resolves with bytes.
|
|
78
|
+
*/
|
|
58
79
|
export type ReadFn = (location: string) => Promise<Uint8Array>;
|
|
59
80
|
|
|
60
81
|
/**
|
|
@@ -62,6 +83,9 @@ export type ReadFn = (location: string) => Promise<Uint8Array>;
|
|
|
62
83
|
*/
|
|
63
84
|
export type MaybeReadFn = (location: string) => Promise<Uint8Array | undefined>;
|
|
64
85
|
|
|
86
|
+
/**
|
|
87
|
+
* A function which reads some location and returns bytes.
|
|
88
|
+
*/
|
|
65
89
|
export type ReadNowFn = (location: string) => Uint8Array;
|
|
66
90
|
|
|
67
91
|
/**
|
|
@@ -69,11 +93,14 @@ export type ReadNowFn = (location: string) => Uint8Array;
|
|
|
69
93
|
*/
|
|
70
94
|
export type MaybeReadNowFn = (location: string) => Uint8Array | undefined;
|
|
71
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Returns a string hash of a byte array
|
|
98
|
+
*/
|
|
72
99
|
export type HashFn = (bytes: Uint8Array) => string;
|
|
73
100
|
|
|
74
|
-
export type FileURLToPathFn =
|
|
101
|
+
export type FileURLToPathFn = (url: URL | string) => string;
|
|
75
102
|
|
|
76
|
-
export type PathToFileURLFn =
|
|
103
|
+
export type PathToFileURLFn = (path: string) => URL;
|
|
77
104
|
|
|
78
105
|
export type RequireResolveFn = (
|
|
79
106
|
fromLocation: string,
|
|
@@ -91,14 +118,19 @@ export type ArchiveReader = {
|
|
|
91
118
|
read: ReadFn;
|
|
92
119
|
};
|
|
93
120
|
|
|
94
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Read powers with a {@link HashFn}.
|
|
123
|
+
*
|
|
124
|
+
* @template T The expected input/output type of the {@link CanonicalFn}.
|
|
125
|
+
*/
|
|
126
|
+
export type HashPowers<T extends string = any> = {
|
|
95
127
|
read: ReadFn;
|
|
96
|
-
canonical: CanonicalFn
|
|
128
|
+
canonical: CanonicalFn<T>;
|
|
97
129
|
computeSha512: HashFn;
|
|
98
130
|
};
|
|
131
|
+
// #endregion
|
|
99
132
|
|
|
100
|
-
//
|
|
101
|
-
|
|
133
|
+
// #region write
|
|
102
134
|
export type WritePowers = {
|
|
103
135
|
write: WriteFn;
|
|
104
136
|
};
|
|
@@ -111,12 +143,13 @@ export type ArchiveWriter = {
|
|
|
111
143
|
};
|
|
112
144
|
|
|
113
145
|
export type SnapshotFn = () => Promise<Uint8Array>;
|
|
146
|
+
// #endregion
|
|
114
147
|
|
|
115
|
-
//
|
|
116
|
-
|
|
148
|
+
// #region execute
|
|
117
149
|
export type Application = {
|
|
118
150
|
import: ExecuteFn;
|
|
119
151
|
sha512?: string | undefined;
|
|
120
152
|
};
|
|
121
153
|
|
|
122
154
|
export type ExecuteFn = (options?: any) => Promise<SomeObject>;
|
|
155
|
+
// #endregion
|
|
@@ -25,6 +25,34 @@ export type Primitive = null | undefined | string | number | boolean | symbol |
|
|
|
25
25
|
* https://github.com/Microsoft/TypeScript/issues/29729
|
|
26
26
|
* Microsoft/TypeScript#29729}. It will be removed as soon as it's not needed
|
|
27
27
|
* anymore.
|
|
28
|
+
* @see {@link https://www.npmjs.com/package/type-fest}
|
|
28
29
|
*/
|
|
29
30
|
export type LiteralUnion<LiteralType, PrimitiveType extends Primitive> = LiteralType | (PrimitiveType & Record<never, never>);
|
|
31
|
+
/**
|
|
32
|
+
* Generic type guard function that checks if a value of type `T` is also of type `U`.
|
|
33
|
+
* @template T The type of the value to check.
|
|
34
|
+
* @template U The type that the value should be checked against.
|
|
35
|
+
*/
|
|
36
|
+
export type TypeGuard<T, U extends T> = (value: T) => value is U;
|
|
37
|
+
/**
|
|
38
|
+
* Helper type for a generic type guard used in an "extends" clause
|
|
39
|
+
*/
|
|
40
|
+
export type SomeTypeGuard = TypeGuard<any, any>;
|
|
41
|
+
/**
|
|
42
|
+
* Infers the type that a type guard function checks for.
|
|
43
|
+
*
|
|
44
|
+
* @template T The type guard function type itself
|
|
45
|
+
* @returns The type that the guard checks for
|
|
46
|
+
*/
|
|
47
|
+
export type GuardedType<T> = T extends (value: any) => value is infer U ? U : never;
|
|
48
|
+
/**
|
|
49
|
+
* Converts a union type to an intersection type
|
|
50
|
+
*/
|
|
51
|
+
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
52
|
+
/**
|
|
53
|
+
* Makes a nicer tooltip for `T` in IDEs (most of the time).
|
|
54
|
+
*/
|
|
55
|
+
export type Simplify<T> = {
|
|
56
|
+
[K in keyof T]: T[K];
|
|
57
|
+
} & {};
|
|
30
58
|
//# sourceMappingURL=typescript.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["typescript.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,mDAAmD;AACnD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,SAAS,GACjB,IAAI,GACJ,SAAS,GACT,MAAM,GACN,MAAM,GACN,OAAO,GACP,MAAM,GACN,MAAM,CAAC;AAEX
|
|
1
|
+
{"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["typescript.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,mDAAmD;AACnD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,SAAS,GACjB,IAAI,GACJ,SAAS,GACT,MAAM,GACN,MAAM,GACN,OAAO,GACP,MAAM,GACN,MAAM,CAAC;AAEX;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,YAAY,CAAC,WAAW,EAAE,aAAa,SAAS,SAAS,IACjE,WAAW,GACX,CAAC,aAAa,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;AAE3C;;;;GAIG;AAEH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,KAAK,KAAK,IAAI,MAAM,CAAC,GACnE,CAAC,GACD,KAAK,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CACnC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CACvC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,IAAI,GAC1B,CAAC,GACD,KAAK,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,EAAE,CAAC"}
|
package/src/types/typescript.ts
CHANGED
|
@@ -35,9 +35,45 @@ export type Primitive =
|
|
|
35
35
|
* https://github.com/Microsoft/TypeScript/issues/29729
|
|
36
36
|
* Microsoft/TypeScript#29729}. It will be removed as soon as it's not needed
|
|
37
37
|
* anymore.
|
|
38
|
+
* @see {@link https://www.npmjs.com/package/type-fest}
|
|
38
39
|
*/
|
|
39
40
|
export type LiteralUnion<LiteralType, PrimitiveType extends Primitive> =
|
|
40
41
|
| LiteralType
|
|
41
42
|
| (PrimitiveType & Record<never, never>);
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Generic type guard function that checks if a value of type `T` is also of type `U`.
|
|
46
|
+
* @template T The type of the value to check.
|
|
47
|
+
* @template U The type that the value should be checked against.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
export type TypeGuard<T, U extends T> = (value: T) => value is U;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Helper type for a generic type guard used in an "extends" clause
|
|
54
|
+
*/
|
|
55
|
+
export type SomeTypeGuard = TypeGuard<any, any>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Infers the type that a type guard function checks for.
|
|
59
|
+
*
|
|
60
|
+
* @template T The type guard function type itself
|
|
61
|
+
* @returns The type that the guard checks for
|
|
62
|
+
*/
|
|
63
|
+
export type GuardedType<T> = T extends (value: any) => value is infer U
|
|
64
|
+
? U
|
|
65
|
+
: never;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Converts a union type to an intersection type
|
|
69
|
+
*/
|
|
70
|
+
export type UnionToIntersection<U> = (
|
|
71
|
+
U extends any ? (k: U) => void : never
|
|
72
|
+
) extends (k: infer I) => void
|
|
73
|
+
? I
|
|
74
|
+
: never;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Makes a nicer tooltip for `T` in IDEs (most of the time).
|
|
78
|
+
*/
|
|
79
|
+
export type Simplify<T> = { [K in keyof T]: T[K] } & {};
|