@endo/compartment-mapper 1.3.0 → 1.4.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.
Files changed (145) hide show
  1. package/README.md +50 -27
  2. package/archive-lite.d.ts +1 -0
  3. package/archive-lite.js +3 -0
  4. package/archive-parsers.d.ts +1 -0
  5. package/archive-parsers.js +3 -0
  6. package/archive.d.ts +1 -0
  7. package/archive.js +3 -0
  8. package/bundle.d.ts +1 -0
  9. package/bundle.js +3 -0
  10. package/capture-lite.d.ts +1 -0
  11. package/capture-lite.js +3 -0
  12. package/import-archive-lite.d.ts +1 -0
  13. package/import-archive-lite.js +3 -0
  14. package/import-archive-parsers.d.ts +1 -0
  15. package/import-archive-parsers.js +3 -0
  16. package/import-archive.d.ts +1 -0
  17. package/import-archive.js +3 -0
  18. package/import-lite.d.ts +1 -0
  19. package/import-lite.js +3 -0
  20. package/import-parsers.d.ts +1 -0
  21. package/import-parsers.js +3 -0
  22. package/import.d.ts +1 -0
  23. package/import.js +3 -0
  24. package/index.d.ts +1 -0
  25. package/index.js +3 -1
  26. package/node-modules.d.ts +1 -0
  27. package/node-modules.js +3 -0
  28. package/node-powers.d.ts +1 -0
  29. package/node-powers.js +3 -0
  30. package/package.json +10 -14
  31. package/src/archive-lite.d.ts +6 -6
  32. package/src/archive-lite.d.ts.map +1 -1
  33. package/src/archive-lite.js +35 -33
  34. package/src/archive.d.ts.map +1 -1
  35. package/src/archive.js +132 -28
  36. package/src/bundle.d.ts.map +1 -1
  37. package/src/bundle.js +54 -14
  38. package/src/capture-lite.d.ts +2 -2
  39. package/src/capture-lite.d.ts.map +1 -1
  40. package/src/capture-lite.js +21 -17
  41. package/src/compartment-map.d.ts +2 -1
  42. package/src/compartment-map.d.ts.map +1 -1
  43. package/src/compartment-map.js +11 -5
  44. package/src/extension.d.ts.map +1 -1
  45. package/src/extension.js +1 -3
  46. package/src/import-archive-lite.d.ts +3 -19
  47. package/src/import-archive-lite.d.ts.map +1 -1
  48. package/src/import-archive-lite.js +43 -57
  49. package/src/import-archive-parsers.d.ts.map +1 -1
  50. package/src/import-archive-parsers.js +1 -0
  51. package/src/import-archive.d.ts +2 -2
  52. package/src/import-archive.d.ts.map +1 -1
  53. package/src/import-archive.js +15 -12
  54. package/src/import-hook.d.ts +2 -1
  55. package/src/import-hook.d.ts.map +1 -1
  56. package/src/import-hook.js +87 -76
  57. package/src/import-lite.d.ts.map +1 -1
  58. package/src/import-lite.js +23 -23
  59. package/src/import.d.ts.map +1 -1
  60. package/src/import.js +47 -23
  61. package/src/infer-exports.d.ts.map +1 -1
  62. package/src/infer-exports.js +2 -3
  63. package/src/json.d.ts.map +1 -1
  64. package/src/json.js +1 -2
  65. package/src/link.d.ts.map +1 -1
  66. package/src/link.js +12 -29
  67. package/src/map-parser.d.ts.map +1 -1
  68. package/src/map-parser.js +21 -16
  69. package/src/node-module-specifier.d.ts.map +1 -1
  70. package/src/node-module-specifier.js +2 -3
  71. package/src/node-modules.d.ts +9 -7
  72. package/src/node-modules.d.ts.map +1 -1
  73. package/src/node-modules.js +176 -87
  74. package/src/node-powers.d.ts +8 -8
  75. package/src/node-powers.d.ts.map +1 -1
  76. package/src/node-powers.js +29 -24
  77. package/src/parse-archive-cjs.d.ts +3 -2
  78. package/src/parse-archive-cjs.d.ts.map +1 -1
  79. package/src/parse-archive-cjs.js +5 -4
  80. package/src/parse-archive-mjs.d.ts +3 -2
  81. package/src/parse-archive-mjs.d.ts.map +1 -1
  82. package/src/parse-archive-mjs.js +7 -5
  83. package/src/parse-bytes.d.ts +3 -2
  84. package/src/parse-bytes.d.ts.map +1 -1
  85. package/src/parse-bytes.js +7 -5
  86. package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
  87. package/src/parse-cjs-shared-export-wrapper.js +7 -6
  88. package/src/parse-cjs.d.ts +3 -2
  89. package/src/parse-cjs.d.ts.map +1 -1
  90. package/src/parse-cjs.js +14 -5
  91. package/src/parse-json.d.ts.map +1 -1
  92. package/src/parse-json.js +6 -6
  93. package/src/parse-mjs.d.ts +3 -2
  94. package/src/parse-mjs.d.ts.map +1 -1
  95. package/src/parse-mjs.js +3 -3
  96. package/src/parse-pre-cjs.d.ts +3 -2
  97. package/src/parse-pre-cjs.d.ts.map +1 -1
  98. package/src/parse-pre-cjs.js +14 -4
  99. package/src/parse-pre-mjs.d.ts +3 -2
  100. package/src/parse-pre-mjs.d.ts.map +1 -1
  101. package/src/parse-pre-mjs.js +4 -3
  102. package/src/parse-text.d.ts +3 -2
  103. package/src/parse-text.d.ts.map +1 -1
  104. package/src/parse-text.js +6 -5
  105. package/src/policy-format.d.ts +1 -1
  106. package/src/policy-format.d.ts.map +1 -1
  107. package/src/policy-format.js +5 -7
  108. package/src/policy.d.ts.map +1 -1
  109. package/src/policy.js +15 -10
  110. package/src/powers.d.ts.map +1 -1
  111. package/src/powers.js +15 -12
  112. package/src/search.d.ts.map +1 -1
  113. package/src/search.js +10 -7
  114. package/src/types/compartment-map-schema.d.ts +98 -0
  115. package/src/types/compartment-map-schema.d.ts.map +1 -0
  116. package/src/types/compartment-map-schema.ts +116 -0
  117. package/src/types/external.d.ts +256 -0
  118. package/src/types/external.d.ts.map +1 -0
  119. package/src/types/external.ts +379 -0
  120. package/src/types/internal.d.ts +161 -0
  121. package/src/types/internal.d.ts.map +1 -0
  122. package/src/types/internal.ts +216 -0
  123. package/src/types/node-powers.d.ts +46 -0
  124. package/src/types/node-powers.d.ts.map +1 -0
  125. package/src/types/node-powers.ts +52 -0
  126. package/src/types/policy-schema.d.ts +81 -0
  127. package/src/types/policy-schema.d.ts.map +1 -0
  128. package/src/types/policy-schema.ts +131 -0
  129. package/src/types/policy.d.ts +20 -0
  130. package/src/types/policy.d.ts.map +1 -0
  131. package/src/types/policy.ts +42 -0
  132. package/src/types/powers.d.ts +83 -0
  133. package/src/types/powers.d.ts.map +1 -0
  134. package/src/types/powers.ts +120 -0
  135. package/src/types/typescript.d.ts +28 -0
  136. package/src/types/typescript.d.ts.map +1 -0
  137. package/src/types/typescript.ts +41 -0
  138. package/src/types-external.d.ts +14 -0
  139. package/src/types-external.js +2 -0
  140. package/src/types.d.ts +9 -787
  141. package/src/url.d.ts.map +1 -1
  142. package/src/url.js +2 -3
  143. package/src/types.d.ts.map +0 -1
  144. package/src/types.js +0 -995
  145. package/types.d.ts +0 -19
package/src/types.js DELETED
@@ -1,995 +0,0 @@
1
- // @ts-check
2
-
3
- export {};
4
-
5
- /** @import {FinalStaticModuleType} from 'ses' */
6
- /** @import {ImportHook} from 'ses' */
7
- /** @import {ImportNowHook} from 'ses' */
8
- /** @import {StaticModuleType} from 'ses' */
9
- /** @import {ThirdPartyStaticModuleInterface} from 'ses' */
10
- /** @import {Transform} from 'ses' */
11
-
12
- // /////////////////////////////////////////////////////////////////////////////
13
-
14
- // The schema of a compartment map JSON file:
15
-
16
- /**
17
- * A compartment map describes how to construct an application as a graph of
18
- * Compartments, each corresponding to Node.js style packaged modules.
19
- *
20
- * @typedef {object} CompartmentMapDescriptor
21
- * @property {Array<string>} tags
22
- * @property {EntryDescriptor} entry
23
- * @property {Record<string, CompartmentDescriptor>} compartments
24
- */
25
-
26
- /**
27
- * The entry descriptor of a compartment map denotes the root module of an
28
- * application and the compartment that contains it.
29
- *
30
- * @typedef {object} EntryDescriptor
31
- * @property {string} compartment
32
- * @property {string} module
33
- */
34
-
35
- /**
36
- * A compartment descriptor corresponds to a single Compartment
37
- * of an assembled Application and describes how to construct
38
- * one for a given library or application `package.json`.
39
- *
40
- * @typedef {object} CompartmentDescriptor
41
- * @property {string} label
42
- * @property {Array<string>} [path] - shortest path of dependency names to this
43
- * compartment
44
- * @property {string} name - the name of the originating package suitable for
45
- * constructing a sourceURL prefix that will match it to files in a developer
46
- * workspace.
47
- * @property {string} location
48
- * @property {boolean} [retained] - whether this compartment was retained by
49
- * any module in the solution. This property should never appear in an archived
50
- * compartment map.
51
- * @property {Record<string, ModuleDescriptor>} modules
52
- * @property {Record<string, ScopeDescriptor>} scopes
53
- * @property {LanguageForExtension} parsers - language for extension
54
- * @property {LanguageForModuleSpecifier} types - language for module specifier
55
- * @property {SomePackagePolicy} policy - policy specific to compartment
56
- * @property {Set<string>} compartments - List of compartment names this Compartment depends upon
57
- */
58
-
59
- /**
60
- * For every module explicitly mentioned in an `exports` field of a
61
- * `package.json`, there is a corresponding module descriptor.
62
- *
63
- * @typedef {object} ModuleDescriptor
64
- * @property {string=} [compartment]
65
- * @property {string} [module]
66
- * @property {string} [location]
67
- * @property {Language} [parser]
68
- * @property {string} [sha512] in base 16, hex
69
- * @property {string} [exit]
70
- * @property {string} [deferredError]
71
- */
72
-
73
- /**
74
- * Scope descriptors link all names under a prefix to modules in another
75
- * compartment, like a wildcard.
76
- * These are employed to link any module not explicitly mentioned
77
- * in a `package.json` file, when that `package.json` file does not have
78
- * an explicit `exports` map.
79
- *
80
- * @typedef {object} ScopeDescriptor
81
- * @property {string} compartment
82
- * @property {string} [module]
83
- */
84
-
85
- /**
86
- * Natively-recognized and custom languages
87
- *
88
- * @typedef {LiteralUnion<BuiltinLanguage, string>} Language
89
- */
90
-
91
- /**
92
- * Languages natively recognized by `compartment-mapper`
93
- *
94
- * @typedef {'mjs' | 'cjs' | 'json' | 'bytes' | 'text' | 'pre-mjs-json' | 'pre-cjs-json'} BuiltinLanguage
95
- */
96
-
97
- // /////////////////////////////////////////////////////////////////////////////
98
-
99
- // IO capabilities and archives:
100
-
101
- /**
102
- * @typedef {object} ArchiveWriter
103
- * @property {WriteFn} write
104
- * @property {SnapshotFn} snapshot
105
- */
106
-
107
- /**
108
- * @callback WriteFn
109
- * @param {string} location
110
- * @param {Uint8Array} bytes
111
- * @returns {Promise<void>}
112
- */
113
-
114
- /**
115
- * @typedef {object} ArchiveReader
116
- * @property {ReadFn} read
117
- */
118
-
119
- /**
120
- * @callback ReadFn
121
- * @param {string} location
122
- * @returns {Promise<Uint8Array>} bytes
123
- */
124
-
125
- /**
126
- * @callback ReadNowFn
127
- * @param {string} location
128
- * @returns {Uint8Array} bytes
129
- */
130
-
131
- /**
132
- * A resolution of `undefined` indicates `ENOENT` or the equivalent.
133
- *
134
- * @callback MaybeReadFn
135
- * @param {string} location
136
- * @returns {Promise<Uint8Array | undefined>} bytes
137
- */
138
-
139
- /**
140
- * A resolution of `undefined` indicates `ENOENT` or the equivalent.
141
- *
142
- * @callback MaybeReadNowFn
143
- * @param {string} location
144
- * @returns {Uint8Array | undefined} bytes
145
- */
146
-
147
- /**
148
- * Returns a canonical URL for a given URL, following redirects or symbolic
149
- * links if any exist along the path.
150
- * Must return the given logical location if the real location does not exist.
151
- *
152
- * @callback CanonicalFn
153
- * @param {string} location
154
- * @returns {Promise<string>} canonical location
155
- */
156
-
157
- /**
158
- * @callback HashFn
159
- * @param {string | Uint8Array} bytes
160
- * @returns {string} hash
161
- */
162
-
163
- /**
164
- * @typedef {object} Application
165
- * @property {ExecuteFn} import
166
- * @property {string} [sha512]
167
- */
168
-
169
- /**
170
- * @callback ExecuteFn
171
- * @param {ExecuteOptions} [options]
172
- * @returns {Promise<SomeObject>}
173
- */
174
-
175
- /**
176
- * @callback SnapshotFn
177
- * @returns {Promise<Uint8Array>}
178
- */
179
-
180
- /**
181
- * @callback FileURLToPathFn
182
- * @param {string|URL} location
183
- * @returns {string}
184
- */
185
-
186
- /**
187
- * @callback IsAbsoluteFn
188
- * @param {string} location
189
- * @returns {boolean}
190
- */
191
-
192
- /**
193
- * Node.js' `url.pathToFileURL` only returns a {@link URL}.
194
- * @callback PathToFileURLFn
195
- * @param {string} location
196
- * @returns {URL|string}
197
- */
198
-
199
- /**
200
- * @callback RequireResolveFn
201
- * @param {string} fromLocation
202
- * @param {string} specifier
203
- * @param {{paths?: string[]}} [options]
204
- */
205
-
206
- /**
207
- * @typedef {object} ReadPowers
208
- * @property {ReadFn} read
209
- * @property {CanonicalFn} canonical
210
- * @property {MaybeReadNowFn} [maybeReadNow]
211
- * @property {HashFn} [computeSha512]
212
- * @property {FileURLToPathFn} [fileURLToPath]
213
- * @property {PathToFileURLFn} [pathToFileURL]
214
- * @property {RequireResolveFn} [requireResolve]
215
- * @property {IsAbsoluteFn} [isAbsolute]
216
- */
217
-
218
- /**
219
- * These properties are necessary for dynamic require support
220
- *
221
- * @typedef {'fileURLToPath' | 'isAbsolute' | 'maybeReadNow'} ReadNowPowersProp
222
- * @see {@link ReadNowPowers}
223
- */
224
-
225
- /**
226
- * The extension of {@link ReadPowers} necessary for dynamic require support
227
- *
228
- * For a `ReadPowers` to be a `ReadNowPowers`:
229
- *
230
- * 1. It must be an object (not a {@link ReadFn})
231
- * 2. Prop `maybeReadNow` is a function
232
- * 3. Prop `fileURLToPath` is a function
233
- * 4. Prop `isAbsolute` is a function
234
- *
235
- * @typedef {Omit<ReadPowers, ReadNowPowersProp> & Required<Pick<ReadPowers, ReadNowPowersProp>>} ReadNowPowers
236
- */
237
-
238
- /**
239
- * @typedef MakeImportNowHookMakerOptions
240
- * @property {Sources} [sources]
241
- * @property {Record<string, CompartmentDescriptor>} [compartmentDescriptors]
242
- * @property {HashFn} [computeSha512]
243
- * @property {string[]} [searchSuffixes] Suffixes to search if the unmodified
244
- * specifier is not found. Pass `[]` to emulate Node.js' strict behavior. The
245
- * default handles Node.js' CommonJS behavior. Unlike Node.js, the Compartment
246
- * Mapper lifts CommonJS up, more like a bundler, and does not attempt to vary
247
- * the behavior of resolution depending on the language of the importing module.
248
- * @property {SourceMapHook} [sourceMapHook]
249
- * @property {ExitModuleImportNowHook} [exitModuleImportNowHook]
250
- */
251
-
252
- /**
253
- * @typedef {ReadPowers & {maybeRead: MaybeReadFn}} MaybeReadPowers
254
- */
255
-
256
- /**
257
- * @typedef {object} HashPowers
258
- * @property {ReadFn} read
259
- * @property {CanonicalFn} canonical
260
- * @property {HashFn} computeSha512
261
- */
262
-
263
- /**
264
- * @typedef {object} WritePowers
265
- * @property {WriteFn} write
266
- */
267
-
268
- // /////////////////////////////////////////////////////////////////////////////
269
-
270
- // Shared machinery for assembling applications:
271
-
272
- /**
273
- * @callback ResolveHook
274
- * @param {string} importSpecifier
275
- * @param {string} referrerSpecifier
276
- * @returns {string} moduleSpecifier
277
- */
278
-
279
- /**
280
- * @callback ShouldDeferError
281
- * @param {Language | undefined} language
282
- * @returns {boolean}
283
- */
284
-
285
- /**
286
- * @typedef {object} ImportHookMakerOptions
287
- * @property {string} packageLocation
288
- * @property {string} packageName
289
- * @property {DeferredAttenuatorsProvider} attenuators
290
- * @property {ParseFn|ParseFnAsync} parse
291
- * @property {ShouldDeferError} shouldDeferError
292
- * @property {Record<string, Compartment>} compartments
293
- */
294
-
295
- /**
296
- * @callback ImportHookMaker
297
- * @param {ImportHookMakerOptions} options
298
- * @returns {ImportHook}
299
- */
300
-
301
- /**
302
- * @typedef {object} ImportNowHookMakerParams
303
- * @property {string} packageLocation
304
- * @property {string} packageName
305
- * @property {ParseFn|ParseFnAsync} parse
306
- * @property {Record<string, Compartment>} compartments
307
- */
308
-
309
- /**
310
- * @callback ImportNowHookMaker
311
- * @param {ImportNowHookMakerParams} params
312
- * @returns {ImportNowHook}
313
- */
314
-
315
- /**
316
- * @typedef {object} SourceMapHookDetails
317
- * @property {string} compartment
318
- * @property {string} module
319
- * @property {string} location
320
- * @property {string} sha512
321
- */
322
-
323
- /**
324
- * @callback SourceMapHook
325
- * @param {string} sourceMap
326
- * @param {SourceMapHookDetails} details
327
- */
328
-
329
- /**
330
- * @typedef {object} ComputeSourceMapLocationDetails
331
- * @property {string} compartment
332
- * @property {string} module
333
- * @property {string} location
334
- * @property {string} sha512
335
- */
336
-
337
- /**
338
- * @callback ComputeSourceMapLocationHook
339
- * @param {ComputeSourceMapLocationDetails} details
340
- * @returns {string}
341
- */
342
-
343
- /**
344
- * Result of a {@link ParseFn}
345
- *
346
- * @typedef ParseResult
347
- * @property {Uint8Array} bytes
348
- * @property {Language} parser
349
- * @property {FinalStaticModuleType} record
350
- * @property {string} [sourceMap]
351
- */
352
-
353
- /**
354
- * @callback ParseFn_
355
- * @param {Uint8Array} bytes
356
- * @param {string} specifier
357
- * @param {string} location
358
- * @param {string} packageLocation
359
- * @param {object} [options]
360
- * @param {string} [options.sourceMap]
361
- * @param {SourceMapHook} [options.sourceMapHook]
362
- * @param {string} [options.sourceMapUrl]
363
- * @param {ReadFn | ReadPowers} [options.readPowers]
364
- * @param {CompartmentDescriptor} [options.compartmentDescriptor]
365
- * @returns {ParseResult}
366
- */
367
-
368
- /**
369
- * @typedef {ParseFn_ & {isSyncParser?: true}} ParseFn
370
- */
371
-
372
- /**
373
- * @callback ParseFnAsync
374
- * @param {Uint8Array} bytes
375
- * @param {string} specifier
376
- * @param {string} location
377
- * @param {string} packageLocation
378
- * @param {object} [options]
379
- * @param {string} [options.sourceMap]
380
- * @param {SourceMapHook} [options.sourceMapHook]
381
- * @param {string} [options.sourceMapUrl]
382
- * @param {ReadFn | ReadPowers} [options.readPowers]
383
- * @returns {Promise<ParseResult>}
384
- */
385
-
386
- /**
387
- * ParserImplementation declares if a heuristic is used by parser to detect
388
- * imports - is set to true for cjs, which uses a lexer to find require calls
389
- *
390
- * @typedef {object} ParserImplementation
391
- * @property {boolean} heuristicImports
392
- * @property {boolean} [synchronous]
393
- * @property {ParseFn} parse
394
- */
395
-
396
- /**
397
- * @callback ComputeSourceLocationHook
398
- * @param {string} compartmentName
399
- * @param {string} moduleSpecifier
400
- * @returns {string|undefined} sourceLocation
401
- */
402
-
403
- /**
404
- * @callback ExitModuleImportHook
405
- * @param {string} specifier
406
- * @returns {Promise<ThirdPartyStaticModuleInterface|undefined>} module namespace
407
- */
408
-
409
- /**
410
- * @callback ExitModuleImportNowHook
411
- * @param {string} specifier
412
- * @param {string} referrer
413
- * @returns {ThirdPartyStaticModuleInterface|undefined} module namespace
414
- */
415
-
416
- /**
417
- * @see {@link LoadArchiveOptions}
418
- * @typedef {object} ExtraLoadArchiveOptions
419
- * @property {string} [expectedSha512]
420
- * @property {Record<string, any>} [modules]
421
- * @property {typeof Compartment} [Compartment]
422
- * @property {ComputeSourceLocationHook} [computeSourceLocation]
423
- * @property {ComputeSourceMapLocationHook} [computeSourceMapLocation]
424
- * @property {ParserForLanguage} [parserForLanguage]
425
- * @property {LanguageForExtension} [languageForExtension]
426
- */
427
-
428
- /**
429
- * Options for `loadArchive()`
430
- *
431
- * @typedef {ExecuteOptions & ExtraLoadArchiveOptions} LoadArchiveOptions
432
- */
433
-
434
- /**
435
- * Set of options available in the context of code execution.
436
- *
437
- * May be used only as an intersection with other "options" types
438
- *
439
- * @typedef {object} ExecuteOptions
440
- * @property {object} [globals]
441
- * @property {Array<Transform>} [transforms]
442
- * @property {Array<Transform>} [__shimTransforms__]
443
- * @property {Record<string, object>} [modules]
444
- * @property {ExitModuleImportHook} [importHook]
445
- * @property {Record<string, object>} [attenuations]
446
- * @property {typeof Compartment} [Compartment]
447
- */
448
-
449
- /**
450
- * Mapping of {@link Language Languages} to {@link ParserImplementation ParserImplementations}
451
- *
452
- * @typedef {Record<Language | string, ParserImplementation>} ParserForLanguage
453
- */
454
-
455
- /**
456
- * Mapping of file extension to {@link Language Languages}.
457
- *
458
- * @typedef {Record<string, Language>} LanguageForExtension
459
- */
460
-
461
- /**
462
- * Mapping of module specifier to {@link Language Languages}.
463
- *
464
- * @typedef {Record<string, Language>} LanguageForModuleSpecifier
465
- */
466
-
467
- /**
468
- * Options for `loadLocation()`
469
- *
470
- * @typedef {ArchiveOptions|SyncArchiveOptions} LoadLocationOptions
471
- */
472
-
473
- /**
474
- * @see {@link LinkOptions}
475
- * @typedef {object} ExtraLinkOptions
476
- * @property {ResolveHook} [resolve]
477
- * @property {ImportHookMaker} makeImportHook
478
- * @property {ImportNowHookMaker} [makeImportNowHook]
479
- * @property {ParserForLanguage} [parserForLanguage]
480
- * @property {LanguageForExtension} [languageForExtension]
481
- * @property {ModuleTransforms} [moduleTransforms]
482
- * @property {SyncModuleTransforms} [syncModuleTransforms]
483
- * @property {boolean} [archiveOnly]
484
- */
485
-
486
- /**
487
- * @typedef LinkResult
488
- * @property {Compartment} compartment,
489
- * @property {Record<string, Compartment>} compartments
490
- * @property {Compartment} attenuatorsCompartment
491
- * @property {Promise<void>} pendingJobsPromise
492
- */
493
-
494
- /**
495
- * Options for `link()`
496
- *
497
- * @typedef {ExecuteOptions & ExtraLinkOptions} LinkOptions
498
- */
499
-
500
- /**
501
- * @typedef {Record<string, ModuleTransform>} ModuleTransforms
502
- */
503
-
504
- /**
505
- * @typedef {Record<string, SyncModuleTransform>} SyncModuleTransforms
506
- */
507
-
508
- /**
509
- * @callback ModuleTransform
510
- * @param {Uint8Array} bytes
511
- * @param {string} specifier
512
- * @param {string} location
513
- * @param {string} packageLocation
514
- * @param {object} [params]
515
- * @param {string} [params.sourceMap]
516
- * @returns {Promise<{bytes: Uint8Array, parser: Language, sourceMap?: string}>}
517
- */
518
-
519
- /**
520
- * @callback SyncModuleTransform
521
- * @param {Uint8Array} bytes
522
- * @param {string} specifier
523
- * @param {string} location
524
- * @param {string} packageLocation
525
- * @param {object} [params]
526
- * @param {string} [params.sourceMap]
527
- * @returns {{bytes: Uint8Array, parser: Language, sourceMap?: string}}
528
- */
529
-
530
- // /////////////////////////////////////////////////////////////////////////////
531
-
532
- // Communicating source files from an archive snapshot, from archive.js to
533
- // import-hook.js:
534
-
535
- /**
536
- * @typedef {Record<string, CompartmentSources>} Sources
537
- */
538
-
539
- /**
540
- * @typedef {Record<string, ModuleSource>} CompartmentSources
541
- */
542
-
543
- /**
544
- * @typedef {object} ModuleSource
545
- * @property {string} [deferredError] - module loading error deferred to later stage
546
- * @property {string} [location] - package relative location
547
- * @property {string} [sourceLocation] - fully qualified location
548
- * @property {Uint8Array} [bytes]
549
- * @property {string} [sha512] in base16, hex
550
- * @property {Language} [parser]
551
- * @property {string} [exit]
552
- * @property {StaticModuleType} [record]
553
- */
554
-
555
- /**
556
- * @typedef {object} Artifact
557
- * @property {Uint8Array} bytes
558
- * @property {Language} parser
559
- */
560
-
561
- /**
562
- * @callback CaptureSourceLocationHook
563
- * @param {string} compartmentName
564
- * @param {string} moduleSpecifier
565
- * @param {string} sourceLocation
566
- */
567
-
568
- /**
569
- * @typedef {object} ArchiveOptions
570
- * @property {ModuleTransforms} [moduleTransforms]
571
- * @property {SyncModuleTransforms} [syncModuleTransforms]
572
- * @property {Record<string, any>} [modules]
573
- * @property {boolean} [dev]
574
- * @property {SomePolicy} [policy]
575
- * @property {Set<string>} [tags] deprecated in favor of `conditions`
576
- * @property {Set<string>} [conditions]
577
- * @property {CaptureSourceLocationHook} [captureSourceLocation]
578
- * @property {ExitModuleImportHook} [importHook]
579
- * @property {Array<string>} [searchSuffixes]
580
- * @property {Record<string, string>} [commonDependencies]
581
- * @property {SourceMapHook} [sourceMapHook]
582
- * @property {Record<string, ParserImplementation>} [parserForLanguage]
583
- * @property {LanguageForExtension} [languageForExtension]
584
- */
585
-
586
- /**
587
- * @typedef SyncArchiveOptions
588
- * @property {SyncModuleTransforms} [syncModuleTransforms]
589
- * @property {Record<string, any>} [modules]
590
- * @property {boolean} [dev]
591
- * @property {object} [policy]
592
- * @property {Set<string>} [tags]
593
- * @property {CaptureSourceLocationHook} [captureSourceLocation]
594
- * @property {ExitModuleImportHook} [importHook]
595
- * @property {Array<string>} [searchSuffixes]
596
- * @property {Record<string, string>} [commonDependencies]
597
- * @property {SourceMapHook} [sourceMapHook]
598
- * @property {ExitModuleImportNowHook} [importNowHook]
599
- * @property {Record<string, ParserImplementation>} [parserForLanguage]
600
- * @property {LanguageForExtension} [languageForExtension]
601
- */
602
-
603
- // /////////////////////////////////////////////////////////////////////////////
604
-
605
- // Policy enforcement infrastructure
606
-
607
- /**
608
- * @typedef {object} PackageNamingKit
609
- * @property {boolean} [isEntry] - true if location is the entry compartment
610
- * @property {string} name
611
- * @property {Array<string>} path
612
- */
613
-
614
- /**
615
- * An object representing a full attenuation definition.
616
- * @typedef {object} FullAttenuationDefinition
617
- * @property {string} attenuate - The type of attenuation.
618
- * @property {ImplicitAttenuationDefinition} params - The parameters for the attenuation.
619
- */
620
-
621
- /**
622
- * An array of any type representing an implicit attenuation definition.
623
- * @typedef {[any, ...any[]]} ImplicitAttenuationDefinition
624
- */
625
-
626
- /**
627
- * A type representing an attenuation definition, which can be either a full or implicit definition.
628
- * @typedef {FullAttenuationDefinition | ImplicitAttenuationDefinition} AttenuationDefinition
629
- */
630
-
631
- /**
632
- * @typedef {object} UnifiedAttenuationDefinition
633
- * @property {string} displayName
634
- * @property {string | null} specifier
635
- * @property {Array<any>} [params]
636
- */
637
-
638
- /**
639
- * @template {[any, ...any[]]} [GlobalParams=[any, ...any[]]]
640
- * @template {[any, ...any[]]} [ModuleParams=[any, ...any[]]]
641
- * @typedef Attenuator
642
- * @property {GlobalAttenuatorFn<GlobalParams>} [attenuateGlobals]
643
- * @property {ModuleAttenuatorFn<ModuleParams>} [attenuateModule]
644
- */
645
-
646
- /**
647
- * @template {[any, ...any[]]} [Params=[any, ...any[]]]
648
- * @callback GlobalAttenuatorFn
649
- * @param {Params} params
650
- * @param {Record<PropertyKey, any>} originalObject
651
- * @param {Record<PropertyKey, any>} globalThis
652
- * @returns {void}
653
- * @todo Unsure if we can do much typing of `originalObject` and `globalThis` here.
654
- */
655
-
656
- /**
657
- * @template {[any, ...any[]]} [Params=[any, ...any[]]]
658
- * @template [T=SomeObject]
659
- * @template [U=T]
660
- * @callback ModuleAttenuatorFn
661
- * @param {Params} params
662
- * @param {T} ns
663
- * @returns {U}
664
- */
665
-
666
- /**
667
- * @typedef {object} DeferredAttenuatorsProvider
668
- * @property {(attenuatorSpecifier: string|null) => Promise<Attenuator>} import
669
- */
670
-
671
- /**
672
- * A type representing a wildcard policy, which can be 'any'.
673
- * @typedef {'any'} WildcardPolicy
674
- */
675
-
676
- /**
677
- * A type representing a property policy, which is a record of string keys and boolean values
678
- * @typedef {Record<string, boolean>} PropertyPolicy
679
- */
680
-
681
- /**
682
- * A type representing a policy item, which can be a {@link WildcardPolicy wildcard policy}, a property policy, `undefined`, or defined by an attenuator
683
- * @template [T=void]
684
- * @typedef {WildcardPolicy|PropertyPolicy|T} PolicyItem
685
- */
686
-
687
- /**
688
- * An object representing a nested attenuation definition.
689
- * @typedef {Record<string, AttenuationDefinition | boolean>} NestedAttenuationDefinition
690
- */
691
-
692
- /**
693
- * An object representing a base package policy.
694
- *
695
- * @template [PackagePolicyItem=void] Additional types for a package policy item
696
- * @template [GlobalsPolicyItem=void] Additional types for a global policy item
697
- * @template [BuiltinsPolicyItem=void] Additional types for a builtin policy item
698
- * @template [ExtraOptions=unknown] Additional options
699
- * @typedef {object} PackagePolicy
700
- * @property {string} [defaultAttenuator] - The default attenuator.
701
- * @property {PolicyItem<PackagePolicyItem>} [packages] - The policy item for packages.
702
- * @property {PolicyItem<GlobalsPolicyItem>|AttenuationDefinition} [globals] - The policy item or full attenuation definition for globals.
703
- * @property {PolicyItem<BuiltinsPolicyItem>|NestedAttenuationDefinition} [builtins] - The policy item or nested attenuation definition for builtins.
704
- * @property {boolean} [noGlobalFreeze] - Whether to disable global freeze.
705
- * @property {boolean} [dynamic] - Whether to allow dynamic imports
706
- * @property {ExtraOptions} [options] - Any additional user-defined options can be added to the policy here
707
- */
708
-
709
- /**
710
- * An object representing a base policy.
711
- *
712
- * @template [PackagePolicyItem=void] Additional types for a package policy item
713
- * @template [GlobalsPolicyItem=void] Additional types for a global policy item
714
- * @template [BuiltinsPolicyItem=void] Additional types for a builtin policy item
715
- * @template [ExtraOptions=unknown] Additional package-level options
716
- * @typedef {object} Policy
717
- * @property {Record<string, PackagePolicy<PackagePolicyItem, GlobalsPolicyItem, BuiltinsPolicyItem, ExtraOptions>>} resources - The package policies for the resources.
718
- * @property {string} [defaultAttenuator] - The default attenuator.
719
- * @property {PackagePolicy<PackagePolicyItem, GlobalsPolicyItem, BuiltinsPolicyItem, ExtraOptions>} [entry] - The package policy for the entry.
720
- */
721
-
722
- /**
723
- * Any object. All objects. Not `null`, though.
724
- * @typedef {Record<PropertyKey, any>} SomeObject
725
- */
726
-
727
- /**
728
- * Function in {@link CryptoInterface}
729
- *
730
- * @callback CreateHashFn
731
- * @param {'sha512'} algorithm
732
- * @returns {Hash}
733
- */
734
-
735
- /**
736
- * Object returned by function in {@link CryptoInterface}
737
- *
738
- * @typedef Hash
739
- * @property {(data: Uint8Array|string) => Hash} update
740
- * @property {() => Buffer} digest
741
- * @see {@link https://nodejs.org/api/crypto.html#class-hash}
742
- */
743
-
744
- /**
745
- * Function in {@link FsPromisesInterface}
746
- *
747
- * @callback RealpathFn
748
- * @param {string} filepath
749
- * @returns {Promise<string>}
750
- */
751
-
752
- /**
753
- * Object within {@link FsPromisesInterface}
754
- *
755
- * @typedef FsPromisesInterface
756
- * @property {RealpathFn} realpath
757
- * @property {WriteFn} writeFile
758
- * @property {ReadFn} readFile
759
- * @see {@link https://nodejs.org/api/fs.html#promises-api}
760
- */
761
-
762
- /**
763
- * For creating {@link ReadPowers}
764
- *
765
- * @typedef FsInterface
766
- * @property {FsPromisesInterface} promises
767
- * @property {ReadNowFn} readFileSync
768
- * @see {@link https://nodejs.org/api/fs.html}
769
- */
770
-
771
- /**
772
- * For creating {@link ReadPowers}
773
- *
774
- * @typedef UrlInterface
775
- * @property {FileURLToPathFn} fileURLToPath
776
- * @property {PathToFileURLFn} pathToFileURL
777
- * @see {@link https://nodejs.org/api/url.html}
778
- */
779
-
780
- /**
781
- * For creating {@link ReadPowers}
782
- * @typedef CryptoInterface
783
- * @property {CreateHashFn} createHash
784
- * @see {@link https://nodejs.org/api/crypto.html}
785
- */
786
-
787
- /**
788
- * @typedef PathInterface
789
- * @property {IsAbsoluteFn} isAbsolute
790
- * @see {@link https://nodejs.org/api/path.html}
791
- */
792
-
793
- /**
794
- * Options for `compartmentMapForNodeModules`
795
- *
796
- * @typedef {Pick<ArchiveOptions, 'dev' | 'commonDependencies' | 'policy'>} CompartmentMapForNodeModulesOptions
797
- */
798
-
799
- /**
800
- * Any {@link PackagePolicy}
801
- *
802
- * @typedef {PackagePolicy<PolicyItem, PolicyItem, PolicyItem, unknown>} SomePackagePolicy
803
- */
804
-
805
- /**
806
- * Any {@link Policy}
807
- *
808
- * @typedef {Policy<any, any, any, any>} SomePolicy
809
- */
810
-
811
- /**
812
- * Matches any {@link https://developer.mozilla.org/en-US/docs/Glossary/Primitive primitive value}.
813
- *
814
- * @typedef {null|undefined|string|number|boolean|symbol|bigint} Primitive
815
- * @see {@link https://github.com/sindresorhus/type-fest/blob/main/source/primitive.d.ts original source}
816
- */
817
-
818
- /**
819
- * Allows creating a union type by combining primitive types and literal
820
- * types without sacrificing auto-completion in IDEs for the literal type part
821
- * of the union.
822
- *
823
- * Currently, when a union type of a primitive type is combined with literal types,
824
- * TypeScript loses all information about the combined literals. Thus, when such
825
- * a type is used in an IDE with autocompletion, no suggestions are made for the
826
- * declared literals.
827
- *
828
- * This type is a workaround for {@link https://github.com/Microsoft/TypeScript/issues/29729 Microsoft/TypeScript#29729}.
829
- * It will be removed as soon as it's not needed anymore.
830
- *
831
- *
832
- * @see {@link https://github.com/sindresorhus/type-fest/blob/main/source/literal-union.d.ts original source}
833
- * @template LiteralType The literal type
834
- * @template {Primitive} PrimitiveType The primitive type
835
- * @typedef {LiteralType | (PrimitiveType & Record<never, never>)} LiteralUnion
836
- * @example
837
- * ```ts
838
- * // Before
839
- *
840
- * type Pet = 'dog' | 'cat' | string;
841
- *
842
- * const pet: Pet = '';
843
- * // Start typing in your TypeScript-enabled IDE.
844
- * // You **will not** get auto-completion for `dog` and `cat` literals.
845
- *
846
- * // After
847
- *
848
- * type Pet2 = LiteralUnion<'dog' | 'cat', string>;
849
- *
850
- * const pet: Pet2 = '';
851
- * // You **will** get auto-completion for `dog` and `cat` literals.
852
- * ```
853
- */
854
-
855
- /**
856
- * Options for `importLocation()`
857
- *
858
- * @typedef {ExecuteOptions & ArchiveOptions} ImportLocationOptions
859
- */
860
-
861
- /**
862
- * Options for `importLocation()` necessary (but not sufficient--see
863
- * {@link ReadNowPowers}) for dynamic require support
864
- *
865
- * @typedef {ExecuteOptions & SyncArchiveOptions} SyncImportLocationOptions
866
- */
867
-
868
- /**
869
- * Options for `captureFromMap()`
870
- *
871
- * @typedef CaptureOptions
872
- * @property {ModuleTransforms} [moduleTransforms]
873
- * @property {SyncModuleTransforms} [syncModuleTransforms]
874
- * @property {Record<string, any>} [modules]
875
- * @property {boolean} [dev]
876
- * @property {SomePolicy} [policy]
877
- * @property {Set<string>} [tags] deprecated in favor of `conditions`
878
- * @property {Set<string>} [conditions]
879
- * @property {ExitModuleImportHook} [importHook]
880
- * @property {Array<string>} [searchSuffixes]
881
- * @property {Record<string, string>} [commonDependencies]
882
- * @property {SourceMapHook} [sourceMapHook]
883
- * @property {Record<string, ParserImplementation>} [parserForLanguage]
884
- * @property {LanguageForExtension} [languageForExtension]
885
- * @property {ExitModuleImportNowHook} [importNowHook]
886
- */
887
-
888
- /**
889
- * The result of `captureFromMap()`
890
- *
891
- * @typedef CaptureResult
892
- * @property {CompartmentMapDescriptor} captureCompartmentMap
893
- * @property {Sources} captureSources
894
- * @property {Record<string, string>} compartmentRenames
895
- */
896
-
897
- /**
898
- * Options object for `chooseModuleDescriptor`.
899
- *
900
- * @typedef ChooseModuleDescriptorOptions
901
- * @property {string[]} candidates List of `moduleSpecifier` with search
902
- * suffixes appended
903
- * @property {CompartmentDescriptor} compartmentDescriptor Compartment
904
- * descriptor
905
- * @property {Record<string, CompartmentDescriptor>} compartmentDescriptors All
906
- * compartment descriptors
907
- * @property {Record<string, Compartment>} compartments All compartments
908
- * @property {HashFn} [computeSha512] Function to compute SHA-512 hash
909
- * @property {Record<string, ModuleDescriptor>} moduleDescriptors All module
910
- * descriptors
911
- * @property {string} moduleSpecifier Module specifier
912
- * @property {string} packageLocation Package location
913
- * @property {CompartmentSources} packageSources Sources
914
- * @property {ReadPowers|ReadFn} readPowers Powers
915
- * @property {SourceMapHook} [sourceMapHook] Source map hook
916
- * @property {(compartmentName: string) => Set<string>} strictlyRequiredForCompartment Function
917
- * returning a set of module names (scoped to the compartment) whose parser is not using
918
- * heuristics to determine imports.
919
- */
920
-
921
- /**
922
- * Operators for `chooseModuleDescriptor` representing synchronous operation.
923
- *
924
- * @typedef SyncChooseModuleDescriptorOperators
925
- * @property {MaybeReadNowFn} maybeRead A function that reads a file, returning
926
- * its binary contents _or_ `undefined` if the file is not found
927
- * @property {ParseFn} parse A function which parses the (defined) binary
928
- * contents from `maybeRead` into a `ParseResult`
929
- * @property {never} [shouldDeferError] Should be omitted.
930
- */
931
-
932
- /**
933
- * Operators for `chooseModuleDescriptor` representing asynchronous operation.
934
- *
935
- * @typedef AsyncChooseModuleDescriptorOperators
936
- * @property {MaybeReadFn} maybeRead A function that reads a file, resolving w/
937
- * its binary contents _or_ `undefined` if the file is not found
938
- * @property {ParseFnAsync|ParseFn} parse A function which parses the (defined)
939
- * binary contents from `maybeRead` into a `ParseResult`
940
- * @property {(language: Language) => boolean} shouldDeferError A function that
941
- * returns `true` if the language returned by `parse` should defer errors.
942
- */
943
-
944
- /**
945
- * Either synchronous or asynchronous operators for `chooseModuleDescriptor`.
946
- *
947
- * @typedef {AsyncChooseModuleDescriptorOperators | SyncChooseModuleDescriptorOperators} ChooseModuleDescriptorOperators
948
- */
949
-
950
- /**
951
- * The agglomeration of things that the `chooseModuleDescriptor` generator can
952
- * yield.
953
- *
954
- * The generator does not necessarily yield _all_ of these; it depends on
955
- * whether the operators are {@link AsyncChooseModuleDescriptorOperators} or
956
- * {@link SyncChooseModuleDescriptorOperators}.
957
- *
958
- * @typedef {ReturnType<ChooseModuleDescriptorOperators['maybeRead']> |
959
- * ReturnType<ChooseModuleDescriptorOperators['parse']>} ChooseModuleDescriptorYieldables
960
- */
961
-
962
- /**
963
- * Parameters for `findRedirect()`.
964
- *
965
- * @typedef FindRedirectParams
966
- * @property {CompartmentDescriptor} compartmentDescriptor
967
- * @property {Record<string, CompartmentDescriptor>} compartmentDescriptors
968
- * @property {Record<string, Compartment>} compartments
969
- * @property {string} absoluteModuleSpecifier A module specifier which is an absolute path. NOT a file:// URL.
970
- * @property {string} packageLocation Location of the compartment descriptor's package
971
- */
972
-
973
- /**
974
- * Options for `makeMapParsers()`
975
- *
976
- * @typedef MakeMapParsersOptions
977
- * @property {ParserForLanguage} parserForLanguage Mapping of language to
978
- * {@link ParserImplementation}
979
- * @property {ModuleTransforms} [moduleTransforms] Async or sync module
980
- * transforms. If non-empty, dynamic requires are unsupported.
981
- * @property {SyncModuleTransforms} [syncModuleTransforms] Sync module
982
- * transforms
983
- */
984
-
985
- /**
986
- * The value returned by `makeMapParsers()`
987
- *
988
- * @template {ParseFn|ParseFnAsync} [T=ParseFn|ParseFnAsync]
989
- * @callback MapParsersFn
990
- * @param {LanguageForExtension} languageForExtension Mapping of file extension
991
- * to {@link Language}
992
- * @param {LanguageForModuleSpecifier} languageForModuleSpecifier Mapping of
993
- * module specifier to {@link Language}
994
- * @returns {T} Parser function
995
- */