@endo/compartment-mapper 1.3.1 → 1.5.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 (154) hide show
  1. package/README.md +64 -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-all-parsers.d.ts +2 -0
  13. package/import-archive-all-parsers.d.ts.map +1 -0
  14. package/import-archive-all-parsers.js +1 -0
  15. package/import-archive-lite.d.ts +1 -0
  16. package/import-archive-lite.js +3 -0
  17. package/import-archive-parsers.d.ts +1 -0
  18. package/import-archive-parsers.js +3 -0
  19. package/import-archive.d.ts +1 -0
  20. package/import-archive.js +3 -0
  21. package/import-lite.d.ts +1 -0
  22. package/import-lite.js +3 -0
  23. package/import-parsers.d.ts +1 -0
  24. package/import-parsers.js +3 -0
  25. package/import.d.ts +1 -0
  26. package/import.js +3 -0
  27. package/index.d.ts +1 -0
  28. package/index.js +3 -1
  29. package/node-modules.d.ts +1 -0
  30. package/node-modules.js +3 -0
  31. package/node-powers.d.ts +1 -0
  32. package/node-powers.js +3 -0
  33. package/package.json +16 -15
  34. package/src/archive-lite.d.ts +8 -10
  35. package/src/archive-lite.d.ts.map +1 -1
  36. package/src/archive-lite.js +35 -209
  37. package/src/archive.d.ts.map +1 -1
  38. package/src/archive.js +140 -28
  39. package/src/bundle.d.ts.map +1 -1
  40. package/src/bundle.js +62 -16
  41. package/src/capture-lite.d.ts +2 -2
  42. package/src/capture-lite.d.ts.map +1 -1
  43. package/src/capture-lite.js +27 -201
  44. package/src/compartment-map.d.ts +2 -1
  45. package/src/compartment-map.d.ts.map +1 -1
  46. package/src/compartment-map.js +11 -3
  47. package/src/digest.d.ts +5 -0
  48. package/src/digest.d.ts.map +1 -0
  49. package/src/digest.js +235 -0
  50. package/src/extension.d.ts.map +1 -1
  51. package/src/extension.js +1 -3
  52. package/src/import-archive-all-parsers.d.ts +11 -0
  53. package/src/import-archive-all-parsers.d.ts.map +1 -0
  54. package/src/import-archive-all-parsers.js +29 -0
  55. package/src/import-archive-lite.d.ts +3 -19
  56. package/src/import-archive-lite.d.ts.map +1 -1
  57. package/src/import-archive-lite.js +47 -57
  58. package/src/import-archive-parsers.d.ts.map +1 -1
  59. package/src/import-archive-parsers.js +1 -0
  60. package/src/import-archive.d.ts +2 -2
  61. package/src/import-archive.d.ts.map +1 -1
  62. package/src/import-archive.js +15 -12
  63. package/src/import-hook.d.ts +2 -1
  64. package/src/import-hook.d.ts.map +1 -1
  65. package/src/import-hook.js +87 -76
  66. package/src/import-lite.d.ts.map +1 -1
  67. package/src/import-lite.js +26 -23
  68. package/src/import.d.ts.map +1 -1
  69. package/src/import.js +49 -23
  70. package/src/infer-exports.d.ts.map +1 -1
  71. package/src/infer-exports.js +2 -3
  72. package/src/json.d.ts.map +1 -1
  73. package/src/json.js +1 -2
  74. package/src/link.d.ts.map +1 -1
  75. package/src/link.js +14 -29
  76. package/src/map-parser.d.ts.map +1 -1
  77. package/src/map-parser.js +25 -17
  78. package/src/node-module-specifier.d.ts.map +1 -1
  79. package/src/node-module-specifier.js +2 -3
  80. package/src/node-modules.d.ts +10 -8
  81. package/src/node-modules.d.ts.map +1 -1
  82. package/src/node-modules.js +212 -97
  83. package/src/node-powers.d.ts +8 -8
  84. package/src/node-powers.d.ts.map +1 -1
  85. package/src/node-powers.js +29 -24
  86. package/src/parse-archive-cjs.d.ts +3 -2
  87. package/src/parse-archive-cjs.d.ts.map +1 -1
  88. package/src/parse-archive-cjs.js +5 -4
  89. package/src/parse-archive-mjs.d.ts +3 -2
  90. package/src/parse-archive-mjs.d.ts.map +1 -1
  91. package/src/parse-archive-mjs.js +7 -5
  92. package/src/parse-bytes.d.ts +3 -2
  93. package/src/parse-bytes.d.ts.map +1 -1
  94. package/src/parse-bytes.js +7 -5
  95. package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
  96. package/src/parse-cjs-shared-export-wrapper.js +7 -6
  97. package/src/parse-cjs.d.ts +3 -2
  98. package/src/parse-cjs.d.ts.map +1 -1
  99. package/src/parse-cjs.js +14 -5
  100. package/src/parse-json.d.ts.map +1 -1
  101. package/src/parse-json.js +6 -6
  102. package/src/parse-mjs.d.ts +3 -2
  103. package/src/parse-mjs.d.ts.map +1 -1
  104. package/src/parse-mjs.js +3 -3
  105. package/src/parse-pre-cjs.d.ts +3 -2
  106. package/src/parse-pre-cjs.d.ts.map +1 -1
  107. package/src/parse-pre-cjs.js +14 -4
  108. package/src/parse-pre-mjs.d.ts +3 -2
  109. package/src/parse-pre-mjs.d.ts.map +1 -1
  110. package/src/parse-pre-mjs.js +4 -3
  111. package/src/parse-text.d.ts +3 -2
  112. package/src/parse-text.d.ts.map +1 -1
  113. package/src/parse-text.js +6 -5
  114. package/src/policy-format.d.ts +1 -1
  115. package/src/policy-format.d.ts.map +1 -1
  116. package/src/policy-format.js +5 -7
  117. package/src/policy.d.ts.map +1 -1
  118. package/src/policy.js +15 -10
  119. package/src/powers.d.ts.map +1 -1
  120. package/src/powers.js +15 -12
  121. package/src/search.d.ts.map +1 -1
  122. package/src/search.js +10 -7
  123. package/src/types/compartment-map-schema.d.ts +98 -0
  124. package/src/types/compartment-map-schema.d.ts.map +1 -0
  125. package/src/types/compartment-map-schema.ts +116 -0
  126. package/src/types/external.d.ts +299 -0
  127. package/src/types/external.d.ts.map +1 -0
  128. package/src/types/external.ts +428 -0
  129. package/src/types/internal.d.ts +162 -0
  130. package/src/types/internal.d.ts.map +1 -0
  131. package/src/types/internal.ts +217 -0
  132. package/src/types/node-powers.d.ts +46 -0
  133. package/src/types/node-powers.d.ts.map +1 -0
  134. package/src/types/node-powers.ts +52 -0
  135. package/src/types/policy-schema.d.ts +81 -0
  136. package/src/types/policy-schema.d.ts.map +1 -0
  137. package/src/types/policy-schema.ts +131 -0
  138. package/src/types/policy.d.ts +20 -0
  139. package/src/types/policy.d.ts.map +1 -0
  140. package/src/types/policy.ts +42 -0
  141. package/src/types/powers.d.ts +83 -0
  142. package/src/types/powers.d.ts.map +1 -0
  143. package/src/types/powers.ts +120 -0
  144. package/src/types/typescript.d.ts +28 -0
  145. package/src/types/typescript.d.ts.map +1 -0
  146. package/src/types/typescript.ts +41 -0
  147. package/src/types-external.d.ts +14 -0
  148. package/src/types-external.js +2 -0
  149. package/src/types.d.ts +9 -787
  150. package/src/url.d.ts.map +1 -1
  151. package/src/url.js +2 -3
  152. package/src/types.d.ts.map +0 -1
  153. package/src/types.js +0 -995
  154. package/types.d.ts +0 -19
@@ -0,0 +1,428 @@
1
+ /**
2
+ * @module External types of the compartment mapper.
3
+ */
4
+
5
+ /* eslint-disable no-use-before-define */
6
+
7
+ import type {
8
+ FinalStaticModuleType,
9
+ StaticModuleType,
10
+ ThirdPartyStaticModuleInterface,
11
+ Transform,
12
+ } from 'ses';
13
+ import type {
14
+ CompartmentMapDescriptor,
15
+ CompartmentDescriptor,
16
+ Language,
17
+ LanguageForExtension,
18
+ } from './compartment-map-schema.js';
19
+ import type { HashFn, ReadFn, ReadPowers } from './powers.js';
20
+
21
+ /**
22
+ * Set of options available in the context of code execution.
23
+ *
24
+ * May be used only as an intersection with other options types.
25
+ */
26
+ export type ExecuteOptions = Partial<{
27
+ globals: object;
28
+ transforms: Array<Transform>;
29
+ __shimTransforms__: Array<Transform>;
30
+ attenuations: Record<string, object>;
31
+ Compartment: typeof Compartment;
32
+ __native__: boolean;
33
+ }> &
34
+ ModulesOption &
35
+ ExitModuleImportHookOption;
36
+
37
+ export type ParseArchiveOptions = Partial<{
38
+ expectedSha512: string;
39
+ computeSha512: HashFn;
40
+ computeSourceLocation: ComputeSourceLocationHook;
41
+ computeSourceMapLocation: ComputeSourceMapLocationHook;
42
+ __native__: boolean;
43
+ }> &
44
+ ModulesOption &
45
+ CompartmentOption &
46
+ ParserForLanguageOption &
47
+ ExitModuleImportHookOption;
48
+
49
+ export type LoadArchiveOptions = ParseArchiveOptions;
50
+
51
+ export type MapNodeModulesOptions = MapNodeModulesOptionsOmitPolicy &
52
+ PolicyOption;
53
+ type MapNodeModulesOptionsOmitPolicy = Partial<{
54
+ /** @deprecated renamed `conditions` to be consistent with Node.js */
55
+ tags: Set<string>;
56
+ /**
57
+ * Conditions for package `"imports"` and `"exports"`.
58
+ * The `"development"` condition also implies that `devDependencies` of the
59
+ * entry package should be reachable.
60
+ * Common conditions include `"node"`, `"browser"`, `"require"`, `"import"`,
61
+ * and `"default"`.
62
+ * The conditions `"import"`, `"default"`, and `"endo"` need not be
63
+ * specified.
64
+ */
65
+ conditions: Set<string>;
66
+ /**
67
+ * @deprecated add `"development"` to the `conditions` Set option.
68
+ * Including `devDependencies` has been subsumed by implication
69
+ * of having the `"development"` condition.
70
+ */
71
+ dev: boolean;
72
+ /**
73
+ * Indicates that the node_modules tree should fail to map if it does not
74
+ * strictly reach every expected package.
75
+ * By default, unreachable packages are simply omitted from the map,
76
+ * which defers some errors to when modules load.
77
+ */
78
+ strict: boolean;
79
+ /** Dependencies to make reachable from any package */
80
+ commonDependencies: Record<string, string>;
81
+ /** Maps extensions to languages for all packages, like `txt` to `text` */
82
+ languageForExtension: LanguageForExtension;
83
+ /** Maps additional extensions to languages for all type=module packages */
84
+ moduleLanguageForExtension: LanguageForExtension;
85
+ /** Maps additional extensions to languages for all type=commonjs packages (default) */
86
+ commonjsLanguageForExtension: LanguageForExtension;
87
+ /** Maps extensions to languages for packages not under node_modules */
88
+ workspaceLanguageForExtension: LanguageForExtension;
89
+ /**
90
+ * Maps additional extensions to languages for all type=module packages that
91
+ * are not under node_modules
92
+ */
93
+ workspaceModuleLanguageForExtension: LanguageForExtension;
94
+ /**
95
+ * Maps additional extensions to languages for all type=commonjs packages
96
+ * (default)
97
+ */
98
+ workspaceCommonjsLanguageForExtension: LanguageForExtension;
99
+ /**
100
+ * Accounts for languages not present as values in any of the extension to
101
+ * language mappings.
102
+ * For higher level functions like `importLocation`, these are inferred
103
+ * from the `parserForLanguage` option.
104
+ */
105
+ languages: Array<Language>;
106
+ }>;
107
+
108
+ /**
109
+ * @deprecated Use `mapNodeModules()`.
110
+ */
111
+ export type CompartmentMapForNodeModulesOptions = Omit<
112
+ MapNodeModulesOptions,
113
+ 'conditions' | 'tags'
114
+ >;
115
+
116
+ export type CaptureLiteOptions = ImportingOptions &
117
+ LinkingOptions &
118
+ PolicyOption;
119
+
120
+ export type ArchiveLiteOptions = SyncOrAsyncArchiveOptions &
121
+ ModuleTransformsOption &
122
+ ImportingOptions &
123
+ ExitModuleImportHookOption &
124
+ LinkingOptions;
125
+
126
+ export type SyncArchiveLiteOptions = SyncOrAsyncArchiveOptions &
127
+ SyncModuleTransformsOption &
128
+ SyncImportingOptions &
129
+ ExitModuleImportNowHookOption;
130
+
131
+ export type ArchiveOptions = Omit<MapNodeModulesOptions, 'language'> &
132
+ ArchiveLiteOptions;
133
+
134
+ export type SyncArchiveOptions = Omit<MapNodeModulesOptions, 'languages'> &
135
+ SyncArchiveLiteOptions;
136
+
137
+ /**
138
+ * Options for `loadLocation()`
139
+ */
140
+ export type LoadLocationOptions = ArchiveOptions & SyncArchiveOptions;
141
+
142
+ /**
143
+ * Options for `importLocation()` necessary (but not sufficient--see
144
+ * `ReadNowPowers`) for dynamic require support
145
+ */
146
+ export type SyncImportLocationOptions = SyncArchiveOptions & ExecuteOptions;
147
+
148
+ export type ImportLocationOptions = ArchiveOptions & ExecuteOptions;
149
+
150
+ // ////////////////////////////////////////////////////////////////////////////////
151
+ // Single Options
152
+
153
+ export type SearchSuffixesOption = {
154
+ /**
155
+ * Suffixes to search if the unmodified specifier is not found. Pass `[]` to
156
+ * emulate Node.js' strict behavior. The default handles Node.js' CommonJS
157
+ * behavior.
158
+ * Unlike Node.js, the Compartment Mapper lifts CommonJS up, more like a
159
+ * bundler, and does not attempt to vary the behavior of resolution depending
160
+ * on the language of the importing module.
161
+ */
162
+ searchSuffixes?: string[];
163
+ };
164
+
165
+ export type SourceMapHookOption = {
166
+ sourceMapHook?: SourceMapHook;
167
+ };
168
+
169
+ export type ModulesOption = {
170
+ modules?: Record<string, any>;
171
+ };
172
+
173
+ export type ExitModuleImportHookOption = {
174
+ importHook?: ExitModuleImportHook;
175
+ };
176
+
177
+ export type ExitModuleImportNowHookOption = {
178
+ importNowHook?: ExitModuleImportNowHook;
179
+ };
180
+
181
+ export type ParserForLanguageOption = {
182
+ parserForLanguage?: ParserForLanguage;
183
+ };
184
+
185
+ export type CompartmentOption = {
186
+ Compartment?: typeof Compartment;
187
+ };
188
+
189
+ export type ModuleTransformsOption = {
190
+ moduleTransforms?: ModuleTransforms;
191
+ };
192
+
193
+ export type SyncModuleTransformsOption = {
194
+ syncModuleTransforms?: SyncModuleTransforms;
195
+ };
196
+
197
+ export type PolicyOption = {
198
+ policy?: any;
199
+ };
200
+
201
+ export type LanguageForExtensionOption = {
202
+ languageForExtension?: LanguageForExtension;
203
+ };
204
+
205
+ // ////////////////////////////////////////////////////////////////////////////////
206
+ // Common option groups:
207
+
208
+ export type SyncOrAsyncArchiveOptions = Partial<{
209
+ captureSourceLocation: CaptureSourceLocationHook;
210
+ }> &
211
+ ParserForLanguageOption &
212
+ CompartmentOption &
213
+ PolicyOption;
214
+
215
+ type SyncOrAsyncImportingOptions = SearchSuffixesOption & SourceMapHookOption;
216
+
217
+ type ImportingOptions = ModulesOption &
218
+ SyncOrAsyncImportingOptions &
219
+ ExitModuleImportHookOption;
220
+
221
+ type SyncImportingOptions = ModulesOption &
222
+ SyncOrAsyncImportingOptions &
223
+ ExitModuleImportNowHookOption;
224
+
225
+ type LinkingOptions = ParserForLanguageOption &
226
+ CompartmentOption &
227
+ SyncModuleTransformsOption &
228
+ ModuleTransformsOption;
229
+
230
+ // ////////////////////////////////////////////////////////////////////////////////
231
+
232
+ /**
233
+ * Result of `digestCompartmentMap()`
234
+ */
235
+ export interface DigestResult {
236
+ /**
237
+ * Normalized `CompartmentMapDescriptor`
238
+ */
239
+ compartmentMap: CompartmentMapDescriptor;
240
+
241
+ /**
242
+ * Sources found in the `CompartmentMapDescriptor`
243
+ */
244
+ sources: Sources;
245
+
246
+ /**
247
+ * A record of renamed {@link CompartmentDescriptor CompartmentDescriptors}
248
+ * from _new_ to _original_ name
249
+ */
250
+ newToOldCompartmentNames: Record<string, string>;
251
+
252
+ /**
253
+ * A record of renamed {@link CompartmentDescriptor CompartmentDescriptors}
254
+ * from _original_ to _new_ name
255
+ */
256
+ oldToNewCompartmentNames: Record<string, string>;
257
+
258
+ /**
259
+ * Alias for `newToOldCompartmentNames`
260
+ * @deprecated Use {@link newToOldCompartmentNames} instead.
261
+ */
262
+ compartmentRenames: Record<string, string>;
263
+ }
264
+
265
+ /**
266
+ * The result of `captureFromMap`.
267
+ */
268
+ export type CaptureResult = Omit<DigestResult, 'compartmentMap' | 'sources'> & {
269
+ captureCompartmentMap: DigestResult['compartmentMap'];
270
+ captureSources: DigestResult['sources'];
271
+ };
272
+
273
+ /**
274
+ * The result of `makeArchiveCompartmentMap`
275
+ */
276
+ export type ArchiveResult = Omit<DigestResult, 'compartmentMap' | 'sources'> & {
277
+ archiveCompartmentMap: DigestResult['compartmentMap'];
278
+ archiveSources: DigestResult['sources'];
279
+ };
280
+
281
+ /**
282
+ * The compartment mapper can capture the Sources for all loaded modules
283
+ * for bundling, archiving, or analysis.
284
+ */
285
+ export type Sources = Record<string, CompartmentSources>;
286
+ export type CompartmentSources = Record<string, ModuleSource>;
287
+
288
+ // TODO unionize:
289
+ export type ModuleSource = Partial<{
290
+ /** module loading error deferred to later stage */
291
+ deferredError: string;
292
+ /** package-relative location */
293
+ location: string;
294
+ /** fully qualified location */
295
+ sourceLocation: string;
296
+ bytes: Uint8Array;
297
+ /** in lowercase base-16 (hexadecimal) */
298
+ sha512: string;
299
+ parser: Language;
300
+ /** indicates that this is a reference that exits the mapped compartments */
301
+ exit: string;
302
+ /** module for the module */
303
+ record: StaticModuleType;
304
+ }>;
305
+
306
+ export type SourceMapHook = (
307
+ sourceMap: string,
308
+ details: SourceMapHookDetails,
309
+ ) => void;
310
+ export type SourceMapHookDetails = {
311
+ compartment: string;
312
+ module: string;
313
+ location: string;
314
+ sha512: string;
315
+ };
316
+
317
+ export type ModuleTransforms = Record<string, ModuleTransform>;
318
+
319
+ export type SyncModuleTransforms = Record<string, SyncModuleTransform>;
320
+
321
+ export type ModuleTransform = (
322
+ ...args: ModuleTransformArguments
323
+ ) => Promise<ModuleTransformResult>;
324
+ export type SyncModuleTransform = (
325
+ ...args: ModuleTransformArguments
326
+ ) => ModuleTransformResult;
327
+
328
+ type ModuleTransformArguments = [
329
+ bytes: Uint8Array,
330
+ specifier: string,
331
+ moduleLocation: string,
332
+ packageLocation: string,
333
+ params: {
334
+ sourceMap?: string;
335
+ },
336
+ ];
337
+
338
+ type ModuleTransformResult = {
339
+ bytes: Uint8Array;
340
+ parser: Language;
341
+ sourceMap?: string;
342
+ };
343
+
344
+ export type ExitModuleImportHook = (
345
+ specifier: string,
346
+ packageLocation: string,
347
+ ) => Promise<ThirdPartyStaticModuleInterface | undefined>;
348
+
349
+ export type ExitModuleImportNowHook = (
350
+ specifier: string,
351
+ packageLocation: string,
352
+ ) => ThirdPartyStaticModuleInterface | undefined;
353
+
354
+ export type ComputeSourceLocationHook = (
355
+ compartmentName: string,
356
+ moduleSpecifier: string,
357
+ ) => string | undefined;
358
+
359
+ /**
360
+ * A hook for archiving that allows the caller to create a side-table or
361
+ * out-of-band reference for where the archive's sources originated,
362
+ * intended to assist debuggers.
363
+ * When making and importing an archive locally, `import-archive.js` can inject
364
+ * the original source location for compartment name and module specifier chosen
365
+ * by `archive.js.
366
+ */
367
+ export type CaptureSourceLocationHook = (
368
+ compartmentName: string,
369
+ moduleSpecifier: string,
370
+ sourceLocation: string,
371
+ ) => void;
372
+
373
+ export type ComputeSourceMapLocationDetails = {
374
+ compartment: string;
375
+ module: string;
376
+ location: string;
377
+ sha512: string;
378
+ };
379
+
380
+ export type ComputeSourceMapLocationHook = (
381
+ details: ComputeSourceMapLocationDetails,
382
+ ) => string;
383
+
384
+ export type ParserImplementation = {
385
+ /**
386
+ * Whether a heuristic is used by parser to detect imports.
387
+ * CommonJS uses a lexer to heuristically discover static require calls.
388
+ */
389
+ heuristicImports: boolean;
390
+ parse: ParseFn;
391
+ synchronous: boolean;
392
+ };
393
+
394
+ type ParseArguments = [
395
+ bytes: Uint8Array,
396
+ specifier: string,
397
+ moduleLocation: string,
398
+ packageLocation: string,
399
+ options?: Partial<{
400
+ sourceMap: string;
401
+ sourceMapHook: SourceMapHook;
402
+ sourceMapUrl: string;
403
+ readPowers: ReadFn | ReadPowers;
404
+ compartmentDescriptor: CompartmentDescriptor;
405
+ }>,
406
+ ];
407
+
408
+ /**
409
+ * Result of a {@link ParseFn} or {@link AsyncParseFn}
410
+ */
411
+ export type ParseResult = {
412
+ bytes: Uint8Array;
413
+ parser: Language;
414
+ record: FinalStaticModuleType;
415
+ sourceMap?: string;
416
+ };
417
+
418
+ export type AsyncParseFn = (...args: ParseArguments) => Promise<ParseResult>;
419
+
420
+ export type ParseFn = { isSyncParser?: true } & ((
421
+ ...args: ParseArguments
422
+ ) => ParseResult);
423
+
424
+ /**
425
+ * Mapping of `Language` to {@link ParserImplementation
426
+ * ParserImplementations}
427
+ */
428
+ export type ParserForLanguage = Record<Language | string, ParserImplementation>;
@@ -0,0 +1,162 @@
1
+ /**
2
+ * @module Internal types of the compartment mapper that need not be visible to
3
+ * consumers.
4
+ */
5
+ import type { ImportHook, ImportNowHook } from 'ses';
6
+ import type { CompartmentDescriptor, Language, LanguageForExtension, LanguageForModuleSpecifier, ModuleDescriptor } from './compartment-map-schema.js';
7
+ import type { HashFn, MaybeReadFn, MaybeReadNowFn, ReadFn, ReadPowers } from './powers.js';
8
+ import type { DeferredAttenuatorsProvider } from './policy.js';
9
+ import type { AsyncParseFn, CompartmentSources, ExecuteOptions, ExitModuleImportNowHook, ModuleTransforms, ParseFn, ParserForLanguage, SearchSuffixesOption, SourceMapHook, SourceMapHookOption, Sources, SyncModuleTransforms } from './external.js';
10
+ export type LinkOptions = {
11
+ resolve?: ResolveHook;
12
+ makeImportHook: ImportHookMaker;
13
+ makeImportNowHook?: ImportNowHookMaker;
14
+ parserForLanguage?: ParserForLanguage;
15
+ moduleTransforms?: ModuleTransforms;
16
+ syncModuleTransforms?: SyncModuleTransforms;
17
+ archiveOnly?: boolean;
18
+ __native__?: boolean;
19
+ } & ExecuteOptions;
20
+ export type LinkResult = {
21
+ compartment: Compartment;
22
+ compartments: Record<string, Compartment>;
23
+ attenuatorsCompartment: Compartment;
24
+ pendingJobsPromise: Promise<void>;
25
+ };
26
+ export type ResolveHook = (importSpecifier: string, referrerSpecifier: string) => string;
27
+ export type ShouldDeferError = (language: Language | undefined) => boolean;
28
+ export type MakeImportNowHookMakerOptions = Partial<{
29
+ sources: Sources;
30
+ compartmentDescriptors: Record<string, CompartmentDescriptor>;
31
+ computeSha512: HashFn;
32
+ exitModuleImportNowHook: ExitModuleImportNowHook;
33
+ }> & SearchSuffixesOption & SourceMapHookOption;
34
+ export type ImportHookMaker = (params: {
35
+ packageLocation: string;
36
+ packageName: string;
37
+ attenuators: DeferredAttenuatorsProvider;
38
+ parse: ParseFn | AsyncParseFn;
39
+ shouldDeferError: ShouldDeferError;
40
+ compartments: Record<string, Compartment>;
41
+ }) => ImportHook;
42
+ export type ImportNowHookMaker = (params: {
43
+ packageLocation: string;
44
+ packageName: string;
45
+ parse: ParseFn | AsyncParseFn;
46
+ compartments: Record<string, Compartment>;
47
+ attenuators?: never;
48
+ shouldDeferError?: never;
49
+ }) => ImportNowHook;
50
+ /**
51
+ * The value returned by `makeMapParsers()`
52
+ */
53
+ export type MapParsersFn<ParseT = AsyncParseFn | ParseFn> = (
54
+ /** Mapping from file extension to Language (like `js` to `mjs`). */
55
+ languageForExtension: LanguageForExtension,
56
+ /** Mapping from module specifier to Language. */
57
+ languageForModuleSpecifier: LanguageForModuleSpecifier) => ParseT;
58
+ /**
59
+ * As used in `import-hook.js`
60
+ */
61
+ export type ChooseModuleDescriptorParams = {
62
+ /** Module specifiers with each search suffix appended */
63
+ candidates: string[];
64
+ moduleSpecifier: string;
65
+ packageLocation: string;
66
+ /** Compartment descriptor from the compartment map */
67
+ compartmentDescriptor: CompartmentDescriptor;
68
+ /** All compartment descriptors from the compartment map */
69
+ compartmentDescriptors: Record<string, CompartmentDescriptor>;
70
+ /** All module descriptors in same compartment */
71
+ moduleDescriptors: Record<string, ModuleDescriptor>;
72
+ /** All compartments */
73
+ compartments: Record<string, Compartment>;
74
+ packageSources: CompartmentSources;
75
+ /** Function to compute SHA-512 hash */
76
+ computeSha512?: HashFn;
77
+ readPowers: ReadPowers | ReadFn;
78
+ sourceMapHook?: SourceMapHook;
79
+ /**
80
+ * Function returning a set of module names (scoped to the compartment) whose
81
+ * parser is not using heuristics to determine imports.
82
+ */
83
+ strictlyRequiredForCompartment: (compartmentName: string) => Set<string>;
84
+ };
85
+ type SyncChooseModuleDescriptorOperators = {
86
+ /**
87
+ * A function that reads a file, returning its binary contents _or_
88
+ * `undefined` if the file is not found
89
+ */
90
+ maybeRead: MaybeReadNowFn;
91
+ /**
92
+ * A function that parses the (defined) binary contents from `maybeRad` into
93
+ * a `ParseResult`
94
+ */
95
+ parse: ParseFn;
96
+ /** Should be omitted */
97
+ shouldDeferError?: never;
98
+ };
99
+ /**
100
+ * Operators for `chooseModuleDescriptor` representing asynchronous operation.
101
+ */
102
+ export type AsyncChooseModuleDescriptorOperators = {
103
+ /**
104
+ * A function that reads a file, resolving with its binary contents _or_
105
+ * `undefined` if the file is not found
106
+ */
107
+ maybeRead: MaybeReadFn;
108
+ /**
109
+ * A function that parses the (defined) binary contents from `maybeRead` into
110
+ * a `ParseResult`
111
+ */
112
+ parse: AsyncParseFn | ParseFn;
113
+ /**
114
+ * A function that returns `true` if the language returned by `parse` should
115
+ * defer errors.
116
+ */
117
+ shouldDeferError: (language: Language) => boolean;
118
+ };
119
+ /**
120
+ * Either synchronous or asynchronous operators for `chooseModuleDescriptor`.
121
+ */
122
+ export type ChooseModuleDescriptorOperators = AsyncChooseModuleDescriptorOperators | SyncChooseModuleDescriptorOperators;
123
+ /**
124
+ * The agglomeration of things that the `chooseModuleDescriptor` generator can
125
+ * yield.
126
+ *
127
+ * The generator does not necessarily yield _all_ of these; it depends on
128
+ * whether the operators are {@link AsyncChooseModuleDescriptorOperators} or
129
+ * {@link SyncChooseModuleDescriptorOperators}.
130
+ */
131
+ export type ChooseModuleDescriptorYieldables = ReturnType<ChooseModuleDescriptorOperators['maybeRead']> | ReturnType<ChooseModuleDescriptorOperators['parse']>;
132
+ /**
133
+ * Parameters for `findRedirect()`.
134
+ */
135
+ export type FindRedirectParams = {
136
+ compartmentDescriptor: CompartmentDescriptor;
137
+ compartmentDescriptors: Record<string, CompartmentDescriptor>;
138
+ compartments: Record<string, Compartment>;
139
+ absoluteModuleSpecifier: string;
140
+ /** Location of the compartment descriptor's package. */
141
+ packageLocation: string;
142
+ };
143
+ /**
144
+ * Options for `makeMapParsers()`
145
+ */
146
+ export type MakeMapParsersOptions = {
147
+ /** Mapping of language to `ParserImplementation` */
148
+ parserForLanguage: ParserForLanguage;
149
+ /**
150
+ * Async or sync module transforms.
151
+ * If non-empty, synchronous import (specifically dynamic `require` in
152
+ * CommonJS or `compartment.importNow`) are unsupported.
153
+ */
154
+ moduleTransforms?: ModuleTransforms;
155
+ /**
156
+ * Sync module transforms.
157
+ * Always supported.
158
+ */
159
+ syncModuleTransforms?: SyncModuleTransforms;
160
+ };
161
+ export {};
162
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["internal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;A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