@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,217 @@
1
+ /**
2
+ * @module Internal types of the compartment mapper that need not be visible to
3
+ * consumers.
4
+ */
5
+
6
+ /* eslint-disable no-use-before-define */
7
+
8
+ import type { ImportHook, ImportNowHook } from 'ses';
9
+ import type {
10
+ CompartmentDescriptor,
11
+ Language,
12
+ LanguageForExtension,
13
+ LanguageForModuleSpecifier,
14
+ ModuleDescriptor,
15
+ } from './compartment-map-schema.js';
16
+ import type {
17
+ HashFn,
18
+ MaybeReadFn,
19
+ MaybeReadNowFn,
20
+ ReadFn,
21
+ ReadPowers,
22
+ } from './powers.js';
23
+ import type { DeferredAttenuatorsProvider } from './policy.js';
24
+ import type {
25
+ AsyncParseFn,
26
+ CompartmentSources,
27
+ ExecuteOptions,
28
+ ExitModuleImportNowHook,
29
+ ModuleTransforms,
30
+ ParseFn,
31
+ ParserForLanguage,
32
+ SearchSuffixesOption,
33
+ SourceMapHook,
34
+ SourceMapHookOption,
35
+ Sources,
36
+ SyncModuleTransforms,
37
+ } from './external.js';
38
+
39
+ export type LinkOptions = {
40
+ resolve?: ResolveHook;
41
+ makeImportHook: ImportHookMaker;
42
+ makeImportNowHook?: ImportNowHookMaker;
43
+ parserForLanguage?: ParserForLanguage;
44
+ moduleTransforms?: ModuleTransforms;
45
+ syncModuleTransforms?: SyncModuleTransforms;
46
+ archiveOnly?: boolean;
47
+ __native__?: boolean;
48
+ } & ExecuteOptions;
49
+
50
+ export type LinkResult = {
51
+ compartment: Compartment;
52
+ compartments: Record<string, Compartment>;
53
+ attenuatorsCompartment: Compartment;
54
+ pendingJobsPromise: Promise<void>;
55
+ };
56
+
57
+ export type ResolveHook = (
58
+ importSpecifier: string,
59
+ referrerSpecifier: string,
60
+ ) => string;
61
+
62
+ export type ShouldDeferError = (language: Language | undefined) => boolean;
63
+
64
+ export type MakeImportNowHookMakerOptions = Partial<{
65
+ sources: Sources;
66
+ compartmentDescriptors: Record<string, CompartmentDescriptor>;
67
+ computeSha512: HashFn;
68
+ exitModuleImportNowHook: ExitModuleImportNowHook;
69
+ }> &
70
+ SearchSuffixesOption &
71
+ SourceMapHookOption;
72
+
73
+ export type ImportHookMaker = (params: {
74
+ packageLocation: string;
75
+ packageName: string;
76
+ attenuators: DeferredAttenuatorsProvider;
77
+ parse: ParseFn | AsyncParseFn;
78
+ shouldDeferError: ShouldDeferError;
79
+ compartments: Record<string, Compartment>;
80
+ }) => ImportHook;
81
+
82
+ export type ImportNowHookMaker = (params: {
83
+ packageLocation: string;
84
+ packageName: string;
85
+ parse: ParseFn | AsyncParseFn;
86
+ compartments: Record<string, Compartment>;
87
+ // Unlike analogous prameters of ImportHookMaker, the Compartment Mapper
88
+ // ignores these two parameters, so they are expressly disallowed to avoid
89
+ // confusion about whether they would be respected.
90
+ attenuators?: never;
91
+ shouldDeferError?: never;
92
+ }) => ImportNowHook;
93
+
94
+ /**
95
+ * The value returned by `makeMapParsers()`
96
+ */
97
+ export type MapParsersFn<ParseT = AsyncParseFn | ParseFn> = (
98
+ /** Mapping from file extension to Language (like `js` to `mjs`). */
99
+ languageForExtension: LanguageForExtension,
100
+ /** Mapping from module specifier to Language. */
101
+ languageForModuleSpecifier: LanguageForModuleSpecifier,
102
+ ) => ParseT;
103
+
104
+ /**
105
+ * As used in `import-hook.js`
106
+ */
107
+ export type ChooseModuleDescriptorParams = {
108
+ /** Module specifiers with each search suffix appended */
109
+ candidates: string[];
110
+ moduleSpecifier: string;
111
+ packageLocation: string;
112
+ /** Compartment descriptor from the compartment map */
113
+ compartmentDescriptor: CompartmentDescriptor;
114
+ /** All compartment descriptors from the compartment map */
115
+ compartmentDescriptors: Record<string, CompartmentDescriptor>;
116
+ /** All module descriptors in same compartment */
117
+ moduleDescriptors: Record<string, ModuleDescriptor>;
118
+ /** All compartments */
119
+ compartments: Record<string, Compartment>;
120
+ packageSources: CompartmentSources;
121
+ /** Function to compute SHA-512 hash */
122
+ computeSha512?: HashFn;
123
+ readPowers: ReadPowers | ReadFn;
124
+ sourceMapHook?: SourceMapHook;
125
+ /**
126
+ * Function returning a set of module names (scoped to the compartment) whose
127
+ * parser is not using heuristics to determine imports.
128
+ */
129
+ strictlyRequiredForCompartment: (compartmentName: string) => Set<string>;
130
+ };
131
+
132
+ type SyncChooseModuleDescriptorOperators = {
133
+ /**
134
+ * A function that reads a file, returning its binary contents _or_
135
+ * `undefined` if the file is not found
136
+ */
137
+ maybeRead: MaybeReadNowFn;
138
+ /**
139
+ * A function that parses the (defined) binary contents from `maybeRad` into
140
+ * a `ParseResult`
141
+ */
142
+ parse: ParseFn;
143
+ /** Should be omitted */
144
+ shouldDeferError?: never;
145
+ };
146
+
147
+ /**
148
+ * Operators for `chooseModuleDescriptor` representing asynchronous operation.
149
+ */
150
+ export type AsyncChooseModuleDescriptorOperators = {
151
+ /**
152
+ * A function that reads a file, resolving with its binary contents _or_
153
+ * `undefined` if the file is not found
154
+ */
155
+ maybeRead: MaybeReadFn;
156
+ /**
157
+ * A function that parses the (defined) binary contents from `maybeRead` into
158
+ * a `ParseResult`
159
+ */
160
+ parse: AsyncParseFn | ParseFn;
161
+ /**
162
+ * A function that returns `true` if the language returned by `parse` should
163
+ * defer errors.
164
+ */
165
+ shouldDeferError: (language: Language) => boolean;
166
+ };
167
+
168
+ /**
169
+ * Either synchronous or asynchronous operators for `chooseModuleDescriptor`.
170
+ */
171
+ export type ChooseModuleDescriptorOperators =
172
+ | AsyncChooseModuleDescriptorOperators
173
+ | SyncChooseModuleDescriptorOperators;
174
+
175
+ /**
176
+ * The agglomeration of things that the `chooseModuleDescriptor` generator can
177
+ * yield.
178
+ *
179
+ * The generator does not necessarily yield _all_ of these; it depends on
180
+ * whether the operators are {@link AsyncChooseModuleDescriptorOperators} or
181
+ * {@link SyncChooseModuleDescriptorOperators}.
182
+ */
183
+ export type ChooseModuleDescriptorYieldables =
184
+ | ReturnType<ChooseModuleDescriptorOperators['maybeRead']>
185
+ | ReturnType<ChooseModuleDescriptorOperators['parse']>;
186
+
187
+ /**
188
+ * Parameters for `findRedirect()`.
189
+ */
190
+ export type FindRedirectParams = {
191
+ compartmentDescriptor: CompartmentDescriptor;
192
+ compartmentDescriptors: Record<string, CompartmentDescriptor>;
193
+ compartments: Record<string, Compartment>;
194
+ /* A module specifier which is an absolute path. NOT a `file://` URL. */
195
+ absoluteModuleSpecifier: string;
196
+ /** Location of the compartment descriptor's package. */
197
+ packageLocation: string;
198
+ };
199
+
200
+ /**
201
+ * Options for `makeMapParsers()`
202
+ */
203
+ export type MakeMapParsersOptions = {
204
+ /** Mapping of language to `ParserImplementation` */
205
+ parserForLanguage: ParserForLanguage;
206
+ /**
207
+ * Async or sync module transforms.
208
+ * If non-empty, synchronous import (specifically dynamic `require` in
209
+ * CommonJS or `compartment.importNow`) are unsupported.
210
+ */
211
+ moduleTransforms?: ModuleTransforms;
212
+ /**
213
+ * Sync module transforms.
214
+ * Always supported.
215
+ */
216
+ syncModuleTransforms?: SyncModuleTransforms;
217
+ };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @module These interfaces describe the powers needed in `node-powers.js` to
3
+ * adapt host capabilities for the compartment mapper.
4
+ */
5
+ /** For creating `ReadPowers` */
6
+ export type FsInterface = {
7
+ promises: {
8
+ realpath: (filepath: string) => Promise<string>;
9
+ writeFile: (location: string, bytes: Uint8Array) => Promise<void>;
10
+ readFile: (location: string) => Promise<Uint8Array>;
11
+ };
12
+ readFileSync: (location: string) => Uint8Array;
13
+ };
14
+ /**
15
+ * The portion of the "node:url" module needed to normalize paths to fully
16
+ * qualified file URLs, as used by the compartment mapper internally.
17
+ */
18
+ export type UrlInterface = {
19
+ fileURLToPath: (location: string | URL) => string;
20
+ pathToFileURL: (location: string) => URL;
21
+ };
22
+ /**
23
+ * The portion of the "node:path" module needed to support dynamic-require for
24
+ * a module specifier that is an absolute path.
25
+ */
26
+ export type PathInterface = {
27
+ isAbsolute: (location: string) => boolean;
28
+ };
29
+ /**
30
+ * The portion of the "node:crypto" module needed for generating and verifying
31
+ * integrity hashes, optionally consumed to make "read powers".
32
+ */
33
+ export type CryptoInterface = {
34
+ createHash: (algorithm: 'sha512') => Hash;
35
+ };
36
+ /**
37
+ * Object returned by function in `CryptoInterface`
38
+ */
39
+ type Hash = {
40
+ update: (data: Uint8Array | string) => Hash;
41
+ digest: () => {
42
+ toString: (radix: 'hex') => string;
43
+ };
44
+ };
45
+ export {};
46
+ //# sourceMappingURL=node-powers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-powers.d.ts","sourceRoot":"","sources":["node-powers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,gCAAgC;AAChC,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE;QACR,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;QAChD,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QAClE,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;KACrD,CAAC;IACF,YAAY,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,UAAU,CAAC;CAChD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,KAAK,MAAM,CAAC;IAClD,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,GAAG,CAAC;CAC1C,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;CAC3C,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,EAAE,CAAC,SAAS,EAAE,QAAQ,KAAK,IAAI,CAAC;CAC3C,CAAC;AAEF;;GAEG;AACH,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,KAAK,IAAI,CAAC;IAC5C,MAAM,EAAE,MAAM;QAEZ,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,CAAC;KACpC,CAAC;CACH,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @module These interfaces describe the powers needed in `node-powers.js` to
3
+ * adapt host capabilities for the compartment mapper.
4
+ */
5
+
6
+ /* eslint-disable no-use-before-define */
7
+
8
+ /** For creating `ReadPowers` */
9
+ export type FsInterface = {
10
+ promises: {
11
+ realpath: (filepath: string) => Promise<string>;
12
+ writeFile: (location: string, bytes: Uint8Array) => Promise<void>;
13
+ readFile: (location: string) => Promise<Uint8Array>;
14
+ };
15
+ readFileSync: (location: string) => Uint8Array;
16
+ };
17
+
18
+ /**
19
+ * The portion of the "node:url" module needed to normalize paths to fully
20
+ * qualified file URLs, as used by the compartment mapper internally.
21
+ */
22
+ export type UrlInterface = {
23
+ fileURLToPath: (location: string | URL) => string;
24
+ pathToFileURL: (location: string) => URL;
25
+ };
26
+
27
+ /**
28
+ * The portion of the "node:path" module needed to support dynamic-require for
29
+ * a module specifier that is an absolute path.
30
+ */
31
+ export type PathInterface = {
32
+ isAbsolute: (location: string) => boolean;
33
+ };
34
+
35
+ /**
36
+ * The portion of the "node:crypto" module needed for generating and verifying
37
+ * integrity hashes, optionally consumed to make "read powers".
38
+ */
39
+ export type CryptoInterface = {
40
+ createHash: (algorithm: 'sha512') => Hash;
41
+ };
42
+
43
+ /**
44
+ * Object returned by function in `CryptoInterface`
45
+ */
46
+ type Hash = {
47
+ update: (data: Uint8Array | string) => Hash;
48
+ digest: () => {
49
+ // This is the exact subset of Node.js Buffer that we need.
50
+ toString: (radix: 'hex') => string;
51
+ };
52
+ };
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @module Describes the portion of a compartment map dedicated to narrowing
3
+ * or attenuating the powers available to each compartment.
4
+ */
5
+ /**
6
+ * An object representing a full attenuation definition.
7
+ */
8
+ export type FullAttenuationDefinition = {
9
+ /** The type of attenuation. */
10
+ attenuate: string;
11
+ /** The parameters for the attenuation. */
12
+ params: ImplicitAttenuationDefinition;
13
+ };
14
+ /**
15
+ * An array of any type representing an implicit attenuation definition.
16
+ */
17
+ export type ImplicitAttenuationDefinition = [any, ...any[]];
18
+ /**
19
+ * A type representing an attenuation definition, which can be either a full or
20
+ * implicit definition.
21
+ */
22
+ export type AttenuationDefinition = FullAttenuationDefinition | ImplicitAttenuationDefinition;
23
+ export type UnifiedAttenuationDefinition = {
24
+ displayName: string;
25
+ specifier: string | null;
26
+ params?: any[] | undefined;
27
+ };
28
+ /**
29
+ * A type representing a wildcard policy, which can be 'any'.
30
+ */
31
+ export type WildcardPolicy = 'any';
32
+ /**
33
+ * A type representing a property policy, which is a record of string keys and
34
+ * boolean values
35
+ */
36
+ export type PropertyPolicy = Record<string, boolean>;
37
+ /**
38
+ * A type representing a policy item, which can be a {@link WildcardPolicy
39
+ * wildcard policy}, a property policy, `undefined`, or defined by an
40
+ * attenuator
41
+ */
42
+ export type PolicyItem<T = void> = WildcardPolicy | PropertyPolicy | T;
43
+ /**
44
+ * An object representing a nested attenuation definition.
45
+ */
46
+ export type NestedAttenuationDefinition = Record<string, AttenuationDefinition | boolean>;
47
+ /**
48
+ * An object representing a base package policy.
49
+ */
50
+ export type PackagePolicy<PackagePolicyItem = void, GlobalsPolicyItem = void, BuiltinsPolicyItem = void, ExtraOptions = unknown> = {
51
+ /** The default attenuator. */
52
+ defaultAttenuator?: string | undefined;
53
+ /** The policy item for packages. */
54
+ packages?: PolicyItem<PackagePolicyItem> | undefined;
55
+ /** The policy item or full attenuation definition for globals. */
56
+ globals?: AttenuationDefinition | PolicyItem<GlobalsPolicyItem> | undefined;
57
+ /** The policy item or nested attenuation definition for builtins. */
58
+ builtins?: NestedAttenuationDefinition | PolicyItem<BuiltinsPolicyItem> | undefined;
59
+ /** Whether to disable global freeze. */
60
+ noGlobalFreeze?: boolean | undefined;
61
+ /** Whether to allow dynamic imports */
62
+ dynamic?: boolean | undefined;
63
+ /** Any additional user-defined options can be added to the policy here */
64
+ options?: ExtraOptions | undefined;
65
+ };
66
+ /**
67
+ * An object representing a base policy.
68
+ */
69
+ export type Policy<PackagePolicyItem = void, GlobalsPolicyItem = void, BuiltinsPolicyItem = void, ExtraOptions = unknown> = {
70
+ /** The package policies for the resources. */
71
+ resources: Record<string, PackagePolicy<PackagePolicyItem, GlobalsPolicyItem, BuiltinsPolicyItem, ExtraOptions>>;
72
+ /** The default attenuator. */
73
+ defaultAttenuator?: string | undefined;
74
+ /** The package policy for the entry. */
75
+ entry?: PackagePolicy<PackagePolicyItem, GlobalsPolicyItem, BuiltinsPolicyItem, ExtraOptions> | undefined;
76
+ };
77
+ /** Any {@link Policy} */
78
+ export type SomePolicy = Policy<any, any, any, any>;
79
+ /** Any {@link PackagePolicy} */
80
+ export type SomePackagePolicy = PackagePolicy<PolicyItem, PolicyItem, PolicyItem, unknown>;
81
+ //# sourceMappingURL=policy-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy-schema.d.ts","sourceRoot":"","sources":["policy-schema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,0CAA0C;IAC1C,MAAM,EAAE,6BAA6B,CAAC;CACvC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC;AAE5D;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAC7B,yBAAyB,GACzB,6BAA6B,CAAC;AAClC,MAAM,MAAM,4BAA4B,GAAG;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC;AAEnC;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAErD;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,IAAI,IAAI,cAAc,GAAG,cAAc,GAAG,CAAC,CAAC;AAEvE;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,MAAM,CAC9C,MAAM,EACN,qBAAqB,GAAG,OAAO,CAChC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,CACvB,iBAAiB,GAAG,IAAI,EACxB,iBAAiB,GAAG,IAAI,EACxB,kBAAkB,GAAG,IAAI,EACzB,YAAY,GAAG,OAAO,IACpB;IACF,8BAA8B;IAC9B,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,oCAAoC;IACpC,QAAQ,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAC;IACrD,kEAAkE;IAClE,OAAO,CAAC,EAAE,qBAAqB,GAAG,UAAU,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAC;IAC5E,qEAAqE;IACrE,QAAQ,CAAC,EACL,2BAA2B,GAC3B,UAAU,CAAC,kBAAkB,CAAC,GAC9B,SAAS,CAAC;IACd,wCAAwC;IACxC,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACrC,uCAAuC;IACvC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,0EAA0E;IAC1E,OAAO,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;CACpC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,MAAM,CAChB,iBAAiB,GAAG,IAAI,EACxB,iBAAiB,GAAG,IAAI,EACxB,kBAAkB,GAAG,IAAI,EACzB,YAAY,GAAG,OAAO,IACpB;IACF,8CAA8C;IAC9C,SAAS,EAAE,MAAM,CACf,MAAM,EACN,aAAa,CACX,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,CACb,CACF,CAAC;IACF,8BAA8B;IAC9B,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,wCAAwC;IACxC,KAAK,CAAC,EACF,aAAa,CACX,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,CACb,GACD,SAAS,CAAC;CACf,CAAC;AAEF,yBAAyB;AACzB,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAEpD,gCAAgC;AAChC,MAAM,MAAM,iBAAiB,GAAG,aAAa,CAC3C,UAAU,EACV,UAAU,EACV,UAAU,EACV,OAAO,CACR,CAAC"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * @module Describes the portion of a compartment map dedicated to narrowing
3
+ * or attenuating the powers available to each compartment.
4
+ */
5
+
6
+ /* eslint-disable no-use-before-define */
7
+
8
+ /**
9
+ * An object representing a full attenuation definition.
10
+ */
11
+ export type FullAttenuationDefinition = {
12
+ /** The type of attenuation. */
13
+ attenuate: string;
14
+ /** The parameters for the attenuation. */
15
+ params: ImplicitAttenuationDefinition;
16
+ };
17
+
18
+ /**
19
+ * An array of any type representing an implicit attenuation definition.
20
+ */
21
+ export type ImplicitAttenuationDefinition = [any, ...any[]];
22
+
23
+ /**
24
+ * A type representing an attenuation definition, which can be either a full or
25
+ * implicit definition.
26
+ */
27
+ export type AttenuationDefinition =
28
+ | FullAttenuationDefinition
29
+ | ImplicitAttenuationDefinition;
30
+ export type UnifiedAttenuationDefinition = {
31
+ displayName: string;
32
+ specifier: string | null;
33
+ params?: any[] | undefined;
34
+ };
35
+
36
+ /**
37
+ * A type representing a wildcard policy, which can be 'any'.
38
+ */
39
+ export type WildcardPolicy = 'any';
40
+
41
+ /**
42
+ * A type representing a property policy, which is a record of string keys and
43
+ * boolean values
44
+ */
45
+ export type PropertyPolicy = Record<string, boolean>;
46
+
47
+ /**
48
+ * A type representing a policy item, which can be a {@link WildcardPolicy
49
+ * wildcard policy}, a property policy, `undefined`, or defined by an
50
+ * attenuator
51
+ */
52
+ export type PolicyItem<T = void> = WildcardPolicy | PropertyPolicy | T;
53
+
54
+ /**
55
+ * An object representing a nested attenuation definition.
56
+ */
57
+ export type NestedAttenuationDefinition = Record<
58
+ string,
59
+ AttenuationDefinition | boolean
60
+ >;
61
+
62
+ /**
63
+ * An object representing a base package policy.
64
+ */
65
+ export type PackagePolicy<
66
+ PackagePolicyItem = void,
67
+ GlobalsPolicyItem = void,
68
+ BuiltinsPolicyItem = void,
69
+ ExtraOptions = unknown,
70
+ > = {
71
+ /** The default attenuator. */
72
+ defaultAttenuator?: string | undefined;
73
+ /** The policy item for packages. */
74
+ packages?: PolicyItem<PackagePolicyItem> | undefined;
75
+ /** The policy item or full attenuation definition for globals. */
76
+ globals?: AttenuationDefinition | PolicyItem<GlobalsPolicyItem> | undefined;
77
+ /** The policy item or nested attenuation definition for builtins. */
78
+ builtins?:
79
+ | NestedAttenuationDefinition
80
+ | PolicyItem<BuiltinsPolicyItem>
81
+ | undefined;
82
+ /** Whether to disable global freeze. */
83
+ noGlobalFreeze?: boolean | undefined;
84
+ /** Whether to allow dynamic imports */
85
+ dynamic?: boolean | undefined;
86
+ /** Any additional user-defined options can be added to the policy here */
87
+ options?: ExtraOptions | undefined;
88
+ };
89
+
90
+ /**
91
+ * An object representing a base policy.
92
+ */
93
+ export type Policy<
94
+ PackagePolicyItem = void,
95
+ GlobalsPolicyItem = void,
96
+ BuiltinsPolicyItem = void,
97
+ ExtraOptions = unknown,
98
+ > = {
99
+ /** The package policies for the resources. */
100
+ resources: Record<
101
+ string,
102
+ PackagePolicy<
103
+ PackagePolicyItem,
104
+ GlobalsPolicyItem,
105
+ BuiltinsPolicyItem,
106
+ ExtraOptions
107
+ >
108
+ >;
109
+ /** The default attenuator. */
110
+ defaultAttenuator?: string | undefined;
111
+ /** The package policy for the entry. */
112
+ entry?:
113
+ | PackagePolicy<
114
+ PackagePolicyItem,
115
+ GlobalsPolicyItem,
116
+ BuiltinsPolicyItem,
117
+ ExtraOptions
118
+ >
119
+ | undefined;
120
+ };
121
+
122
+ /** Any {@link Policy} */
123
+ export type SomePolicy = Policy<any, any, any, any>;
124
+
125
+ /** Any {@link PackagePolicy} */
126
+ export type SomePackagePolicy = PackagePolicy<
127
+ PolicyItem,
128
+ PolicyItem,
129
+ PolicyItem,
130
+ unknown
131
+ >;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @module Types required for policy enforcement.
3
+ */
4
+ import type { SomeObject } from './typescript.js';
5
+ export type PackageNamingKit = {
6
+ /** true if location is the entry compartment */
7
+ isEntry?: boolean | undefined;
8
+ name: string;
9
+ path: Array<string>;
10
+ };
11
+ export type Attenuator<GlobalParams extends [any, ...any[]] = [any, ...any[]], ModuleParams extends [any, ...any[]] = [any, ...any[]]> = {
12
+ attenuateGlobals?: GlobalAttenuatorFn<GlobalParams> | undefined;
13
+ attenuateModule?: ModuleAttenuatorFn<ModuleParams, SomeObject, SomeObject> | undefined;
14
+ };
15
+ export type GlobalAttenuatorFn<Params extends [any, ...any[]] = [any, ...any[]]> = (params: Params, originalObject: Record<PropertyKey, any>, globalThis: Record<PropertyKey, any>) => void;
16
+ export type ModuleAttenuatorFn<Params extends [any, ...any[]] = [any, ...any[]], T = SomeObject, U = T> = (params: Params, ns: T) => U;
17
+ export type DeferredAttenuatorsProvider = {
18
+ import: (attenuatorSpecifier: string | null) => Promise<Attenuator>;
19
+ };
20
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["policy.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gDAAgD;IAChD,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,UAAU,CACpB,YAAY,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,EACtD,YAAY,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,IACpD;IACF,gBAAgB,CAAC,EAAE,kBAAkB,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;IAChE,eAAe,CAAC,EACZ,kBAAkB,CAAC,YAAY,EAAE,UAAU,EAAE,UAAU,CAAC,GACxD,SAAS,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,kBAAkB,CAC5B,MAAM,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,IAC9C,CACF,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,EACxC,UAAU,EAAE,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,KACjC,IAAI,CAAC;AAEV,MAAM,MAAM,kBAAkB,CAC5B,MAAM,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,EAChD,CAAC,GAAG,UAAU,EACd,CAAC,GAAG,CAAC,IACH,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;AAEjC,MAAM,MAAM,2BAA2B,GAAG;IACxC,MAAM,EAAE,CAAC,mBAAmB,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;CACrE,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @module Types required for policy enforcement.
3
+ */
4
+
5
+ /* eslint-disable no-use-before-define */
6
+
7
+ import type { SomeObject } from './typescript.js';
8
+
9
+ export type PackageNamingKit = {
10
+ /** true if location is the entry compartment */
11
+ isEntry?: boolean | undefined;
12
+ name: string;
13
+ path: Array<string>;
14
+ };
15
+
16
+ export type Attenuator<
17
+ GlobalParams extends [any, ...any[]] = [any, ...any[]],
18
+ ModuleParams extends [any, ...any[]] = [any, ...any[]],
19
+ > = {
20
+ attenuateGlobals?: GlobalAttenuatorFn<GlobalParams> | undefined;
21
+ attenuateModule?:
22
+ | ModuleAttenuatorFn<ModuleParams, SomeObject, SomeObject>
23
+ | undefined;
24
+ };
25
+
26
+ export type GlobalAttenuatorFn<
27
+ Params extends [any, ...any[]] = [any, ...any[]],
28
+ > = (
29
+ params: Params,
30
+ originalObject: Record<PropertyKey, any>,
31
+ globalThis: Record<PropertyKey, any>,
32
+ ) => void;
33
+
34
+ export type ModuleAttenuatorFn<
35
+ Params extends [any, ...any[]] = [any, ...any[]],
36
+ T = SomeObject,
37
+ U = T,
38
+ > = (params: Params, ns: T) => U;
39
+
40
+ export type DeferredAttenuatorsProvider = {
41
+ import: (attenuatorSpecifier: string | null) => Promise<Attenuator>;
42
+ };
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @module The compartment mapper requires certain host capabilities.
3
+ * These are the platform-neutral types for those capabilities.
4
+ * For example, {@file node-powers.js} adapts Node.js how modules
5
+ * to various subsets of these capabilities.
6
+ */
7
+ import type { SomeObject } from './typescript.js';
8
+ export type ReadPowers = {
9
+ canonical: CanonicalFn;
10
+ read: ReadFn;
11
+ maybeRead?: MaybeReadFn;
12
+ readNow?: ReadNowFn;
13
+ maybeReadNow?: MaybeReadNowFn;
14
+ computeSha512?: HashFn;
15
+ fileURLToPath?: FileURLToPathFn;
16
+ pathToFileURL?: PathToFileURLFn;
17
+ requireResolve?: RequireResolveFn;
18
+ isAbsolute?: IsAbsoluteFn;
19
+ };
20
+ export type MaybeReadPowers = ReadPowers & {
21
+ maybeRead: MaybeReadFn;
22
+ };
23
+ /**
24
+ * The extension of {@link ReadPowers} necessary for dynamic require support
25
+ *
26
+ * For a `ReadPowers` to be a `ReadNowPowers`:
27
+ *
28
+ * 1. It must be an object (not a {@link ReadFn})
29
+ * 2. Prop `maybeReadNow` is a function
30
+ * 3. Prop `fileURLToPath` is a function
31
+ * 4. Prop `isAbsolute` is a function
32
+ */
33
+ export type ReadNowPowers = Omit<ReadPowers, ReadNowPowersProp> & Required<Pick<ReadPowers, ReadNowPowersProp>>;
34
+ /**
35
+ * These properties are necessary for dynamic require support
36
+ */
37
+ export type ReadNowPowersProp = 'fileURLToPath' | 'isAbsolute' | 'maybeReadNow';
38
+ /**
39
+ * Returns a canonical URL for a given URL, following redirects or symbolic
40
+ * links if any exist along the path.
41
+ * Must return the given logical location if the real location does not exist.
42
+ */
43
+ export type CanonicalFn = (location: string) => Promise<string>;
44
+ export type ReadFn = (location: string) => Promise<Uint8Array>;
45
+ /**
46
+ * A resolution of `undefined` indicates `ENOENT` or the equivalent.
47
+ */
48
+ export type MaybeReadFn = (location: string) => Promise<Uint8Array | undefined>;
49
+ export type ReadNowFn = (location: string) => Uint8Array;
50
+ /**
51
+ * A resolution of `undefined` indicates `ENOENT` or the equivalent.
52
+ */
53
+ export type MaybeReadNowFn = (location: string) => Uint8Array | undefined;
54
+ export type HashFn = (bytes: Uint8Array) => string;
55
+ export type FileURLToPathFn = (location: string | URL) => string;
56
+ export type PathToFileURLFn = (location: string) => URL;
57
+ export type RequireResolveFn = (fromLocation: string, specifier: string, options?: {
58
+ paths?: string[];
59
+ } | undefined) => any;
60
+ export type IsAbsoluteFn = (location: string) => boolean;
61
+ export type ArchiveReader = {
62
+ read: ReadFn;
63
+ };
64
+ export type HashPowers = {
65
+ read: ReadFn;
66
+ canonical: CanonicalFn;
67
+ computeSha512: HashFn;
68
+ };
69
+ export type WritePowers = {
70
+ write: WriteFn;
71
+ };
72
+ export type WriteFn = (location: string, bytes: Uint8Array) => Promise<void>;
73
+ export type ArchiveWriter = {
74
+ write: WriteFn;
75
+ snapshot: SnapshotFn;
76
+ };
77
+ export type SnapshotFn = () => Promise<Uint8Array>;
78
+ export type Application = {
79
+ import: ExecuteFn;
80
+ sha512?: string | undefined;
81
+ };
82
+ export type ExecuteFn = (options?: any) => Promise<SomeObject>;
83
+ //# sourceMappingURL=powers.d.ts.map