@endo/compartment-mapper 1.6.1 → 1.6.3

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.
@@ -11,10 +11,15 @@
11
11
 
12
12
  import type { SomeObject } from './typescript.js';
13
13
 
14
- // Read
14
+ // #region read
15
15
 
16
- export type ReadPowers = {
17
- canonical: CanonicalFn;
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
- export type MaybeReadPowers = ReadPowers & {
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<ReadPowers, ReadNowPowersProp> &
44
- Required<Pick<ReadPowers, ReadNowPowersProp>>;
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
- * Must return the given logical location if the real location does not exist.
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 = (location: string) => Promise<string>;
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 = typeof import('node:url').fileURLToPath;
101
+ export type FileURLToPathFn = (url: URL | string) => string;
75
102
 
76
- export type PathToFileURLFn = typeof import('node:url').pathToFileURL;
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
- export type HashPowers = {
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
- // Write
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
- // Execute
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