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