@endo/compartment-mapper 1.6.2 → 2.0.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 (94) hide show
  1. package/package.json +12 -16
  2. package/src/archive-lite.d.ts +7 -7
  3. package/src/archive-lite.d.ts.map +1 -1
  4. package/src/archive-lite.js +78 -27
  5. package/src/archive.d.ts.map +1 -1
  6. package/src/archive.js +7 -0
  7. package/src/bundle-lite.d.ts +3 -3
  8. package/src/bundle-lite.d.ts.map +1 -1
  9. package/src/bundle-lite.js +19 -24
  10. package/src/bundle.d.ts +3 -3
  11. package/src/bundle.d.ts.map +1 -1
  12. package/src/bundle.js +19 -24
  13. package/src/capture-lite.d.ts +2 -2
  14. package/src/capture-lite.d.ts.map +1 -1
  15. package/src/capture-lite.js +217 -25
  16. package/src/compartment-map.d.ts +9 -2
  17. package/src/compartment-map.d.ts.map +1 -1
  18. package/src/compartment-map.js +737 -254
  19. package/src/digest.d.ts +22 -2
  20. package/src/digest.d.ts.map +1 -1
  21. package/src/digest.js +179 -56
  22. package/src/generic-graph.d.ts +84 -0
  23. package/src/generic-graph.d.ts.map +1 -0
  24. package/src/generic-graph.js +356 -0
  25. package/src/guards.d.ts +18 -0
  26. package/src/guards.d.ts.map +1 -0
  27. package/src/guards.js +109 -0
  28. package/src/hooks.md +124 -0
  29. package/src/import-archive-lite.d.ts.map +1 -1
  30. package/src/import-archive-lite.js +15 -11
  31. package/src/import-archive.d.ts +5 -19
  32. package/src/import-archive.d.ts.map +1 -1
  33. package/src/import-archive.js +7 -27
  34. package/src/import-hook.d.ts +4 -3
  35. package/src/import-hook.d.ts.map +1 -1
  36. package/src/import-hook.js +156 -71
  37. package/src/import-lite.d.ts +6 -6
  38. package/src/import-lite.d.ts.map +1 -1
  39. package/src/import-lite.js +8 -5
  40. package/src/import.d.ts +3 -3
  41. package/src/import.d.ts.map +1 -1
  42. package/src/import.js +16 -6
  43. package/src/infer-exports.d.ts.map +1 -1
  44. package/src/infer-exports.js +16 -6
  45. package/src/json.d.ts +1 -1
  46. package/src/json.d.ts.map +1 -1
  47. package/src/json.js +10 -3
  48. package/src/link.d.ts +4 -3
  49. package/src/link.d.ts.map +1 -1
  50. package/src/link.js +70 -58
  51. package/src/node-modules.d.ts +5 -3
  52. package/src/node-modules.d.ts.map +1 -1
  53. package/src/node-modules.js +648 -245
  54. package/src/node-powers.d.ts +6 -5
  55. package/src/node-powers.d.ts.map +1 -1
  56. package/src/node-powers.js +11 -8
  57. package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
  58. package/src/parse-cjs-shared-export-wrapper.js +3 -1
  59. package/src/policy-format.d.ts +22 -5
  60. package/src/policy-format.d.ts.map +1 -1
  61. package/src/policy-format.js +342 -108
  62. package/src/policy.d.ts +13 -28
  63. package/src/policy.d.ts.map +1 -1
  64. package/src/policy.js +161 -106
  65. package/src/types/canonical-name.d.ts +97 -0
  66. package/src/types/canonical-name.d.ts.map +1 -0
  67. package/src/types/canonical-name.ts +151 -0
  68. package/src/types/compartment-map-schema.d.ts +114 -35
  69. package/src/types/compartment-map-schema.d.ts.map +1 -1
  70. package/src/types/compartment-map-schema.ts +202 -37
  71. package/src/types/external.d.ts +173 -29
  72. package/src/types/external.d.ts.map +1 -1
  73. package/src/types/external.ts +221 -27
  74. package/src/types/generic-graph.d.ts +17 -0
  75. package/src/types/generic-graph.d.ts.map +1 -0
  76. package/src/types/generic-graph.ts +17 -0
  77. package/src/types/internal.d.ts +24 -42
  78. package/src/types/internal.d.ts.map +1 -1
  79. package/src/types/internal.ts +52 -50
  80. package/src/types/node-modules.d.ts +101 -17
  81. package/src/types/node-modules.d.ts.map +1 -1
  82. package/src/types/node-modules.ts +142 -17
  83. package/src/types/policy-schema.d.ts +26 -11
  84. package/src/types/policy-schema.d.ts.map +1 -1
  85. package/src/types/policy-schema.ts +29 -16
  86. package/src/types/policy.d.ts +6 -2
  87. package/src/types/policy.d.ts.map +1 -1
  88. package/src/types/policy.ts +7 -2
  89. package/src/types/powers.d.ts +38 -11
  90. package/src/types/powers.d.ts.map +1 -1
  91. package/src/types/powers.ts +50 -17
  92. package/src/types/typescript.d.ts +28 -0
  93. package/src/types/typescript.d.ts.map +1 -1
  94. package/src/types/typescript.ts +37 -1
@@ -3,7 +3,7 @@ export function makeReadNowPowers({ fs, url, crypto, path, }: {
3
3
  url?: UrlInterface | undefined;
4
4
  crypto?: CryptoInterface | undefined;
5
5
  path?: PathInterface | undefined;
6
- }): MaybeReadPowers & ReadNowPowers;
6
+ }): ReadNowPowers<FileUrlString>;
7
7
  /**
8
8
  * The implementation of `makeReadPowers` and the deprecated
9
9
  * `makeNodeReadPowers` handles the case when the `url` power is not provided,
@@ -14,14 +14,14 @@ export function makeReadNowPowers({ fs, url, crypto, path, }: {
14
14
  * @param {UrlInterface} [args.url]
15
15
  * @param {CryptoInterface} [args.crypto]
16
16
  * @param {PathInterface} [args.path]
17
- * @returns {MaybeReadPowers}
17
+ * @returns {MaybeReadPowers<FileUrlString>}
18
18
  */
19
19
  export function makeReadPowers({ fs, url, crypto, path, }: {
20
20
  fs: FsInterface;
21
21
  url?: UrlInterface | undefined;
22
22
  crypto?: CryptoInterface | undefined;
23
23
  path?: PathInterface | undefined;
24
- }): MaybeReadPowers;
24
+ }): MaybeReadPowers<FileUrlString>;
25
25
  /**
26
26
  * The implementation of `makeWritePowers` and the deprecated
27
27
  * `makeNodeWritePowers` handles the case when the `url` power is not provided,
@@ -37,14 +37,15 @@ export function makeWritePowers({ fs, url }: {
37
37
  }): {
38
38
  write: (location: string, data: Uint8Array) => Promise<void>;
39
39
  };
40
- export function makeNodeReadPowers(fs: FsInterface, crypto?: CryptoInterface): ReadPowers;
40
+ export function makeNodeReadPowers(fs: FsInterface, crypto?: CryptoInterface): ReadPowers<FileUrlString>;
41
41
  export function makeNodeWritePowers(fs: FsInterface): WritePowers;
42
42
  import type { FsInterface } from './types/node-powers.js';
43
43
  import type { UrlInterface } from './types/node-powers.js';
44
44
  import type { CryptoInterface } from './types/node-powers.js';
45
45
  import type { PathInterface } from './types/node-powers.js';
46
- import type { MaybeReadPowers } from './types/powers.js';
46
+ import type { FileUrlString } from './types/external.js';
47
47
  import type { ReadNowPowers } from './types/powers.js';
48
+ import type { MaybeReadPowers } from './types/powers.js';
48
49
  import type { ReadPowers } from './types/powers.js';
49
50
  import type { WritePowers } from './types/powers.js';
50
51
  //# sourceMappingURL=node-powers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node-powers.d.ts","sourceRoot":"","sources":["node-powers.js"],"names":[],"mappings":"AA4LO,8DANJ;IAA0B,EAAE,EAApB,WAAW;IACS,GAAG;IACA,MAAM;IACR,IAAI;CACjC,GAAU,eAAe,GAAG,aAAa,CAoC3C;AAlKD;;;;;;;;;;;GAWG;AACH,2DANG;IAA0B,EAAE,EAApB,WAAW;IACS,GAAG;IACA,MAAM;IACR,IAAI;CACjC,GAAU,eAAe,CA0G3B;AAgDD;;;;;;;;GAQG;AACH,6CAHG;IAA0B,EAAE,EAApB,WAAW;IACS,GAAG;CAAC;sBAOtB,MAAM,QACN,UAAU;EAYtB;AA2BM,uCALI,WAAW,WACX,eAAe,GACb,UAAU,CAKtB;AAWM,wCAJI,WAAW,GACT,WAAW,CAKvB;iCApRS,wBAAwB;kCAAxB,wBAAwB;qCAAxB,wBAAwB;mCAAxB,wBAAwB;qCAexB,mBAAmB;mCAAnB,mBAAmB;gCAAnB,mBAAmB;iCAAnB,mBAAmB"}
1
+ {"version":3,"file":"node-powers.d.ts","sourceRoot":"","sources":["node-powers.js"],"names":[],"mappings":"AA+LO,8DANJ;IAA0B,EAAE,EAApB,WAAW;IACS,GAAG;IACA,MAAM;IACR,IAAI;CACjC,GAAU,cAAc,aAAa,CAAC,CAoCxC;AApKD;;;;;;;;;;;GAWG;AACH,2DANG;IAA0B,EAAE,EAApB,WAAW;IACS,GAAG;IACA,MAAM;IACR,IAAI;CACjC,GAAU,gBAAgB,aAAa,CAAC,CA4G1C;AAgDD;;;;;;;;GAQG;AACH,6CAHG;IAA0B,EAAE,EAApB,WAAW;IACS,GAAG;CAAC;sBAOtB,MAAM,QACN,UAAU;EAYtB;AA2BM,uCALI,WAAW,WACX,eAAe,GACb,WAAW,aAAa,CAAC,CAKrC;AAWM,wCAJI,WAAW,GACT,WAAW,CAKvB;iCAvRS,wBAAwB;kCAAxB,wBAAwB;qCAAxB,wBAAwB;mCAAxB,wBAAwB;mCACF,qBAAqB;mCAe3C,mBAAmB;qCAAnB,mBAAmB;gCAAnB,mBAAmB;iCAAnB,mBAAmB"}
@@ -16,6 +16,7 @@
16
16
  * PathInterface,
17
17
  * UrlInterface,
18
18
  * } from './types/node-powers.js'
19
+ * @import {FileUrlString} from './types/external.js'
19
20
  * @import {
20
21
  * CanonicalFn,
21
22
  * FileURLToPathFn,
@@ -68,7 +69,7 @@ const fakeIsAbsolute = () => false;
68
69
  * @param {UrlInterface} [args.url]
69
70
  * @param {CryptoInterface} [args.crypto]
70
71
  * @param {PathInterface} [args.path]
71
- * @returns {MaybeReadPowers}
72
+ * @returns {MaybeReadPowers<FileUrlString>}
72
73
  */
73
74
  const makeReadPowersSloppy = ({
74
75
  fs,
@@ -125,9 +126,9 @@ const makeReadPowersSloppy = ({
125
126
 
126
127
  /**
127
128
  * There are two special things about the canonical function the compartment
128
- * mapper needs. It needs to use URLs instead of posix paths to avoid
129
+ * mapper needs. It needs to use URL's instead of posix paths to avoid
129
130
  * bundling up a bunch of cruft when we port this around. It needs to use
130
- * promises. URLs can and must logically distinguish a directory from a
131
+ * promises. URL's can and must logically distinguish a directory from a
131
132
  * file, by the final slash, whereas paths must never have a final slash
132
133
  * because that implies a blank file name within the enclosing directory. The
133
134
  * canonical function must also return the logical path instead of the real
@@ -136,7 +137,7 @@ const makeReadPowersSloppy = ({
136
137
  * non-existent directory on the next step after canonicalizing the package
137
138
  * location.
138
139
  *
139
- * @type {CanonicalFn}
140
+ * @type {CanonicalFn<FileUrlString>}
140
141
  */
141
142
  const canonical = async location => {
142
143
  await null;
@@ -145,10 +146,12 @@ const makeReadPowersSloppy = ({
145
146
  const realPath = await fs.promises.realpath(
146
147
  fileURLToPath(location).replace(/\/$/, ''),
147
148
  );
148
- return `${pathToFileURL(realPath).href}/`;
149
+ return /** @type {FileUrlString} */ (
150
+ `${pathToFileURL(realPath).href}/`
151
+ );
149
152
  } else {
150
153
  const realPath = await fs.promises.realpath(fileURLToPath(location));
151
- return pathToFileURL(realPath).href;
154
+ return /** @type {FileUrlString} */ (pathToFileURL(realPath).href);
152
155
  }
153
156
  } catch {
154
157
  return location;
@@ -184,7 +187,7 @@ const makeReadPowersSloppy = ({
184
187
  * @param {UrlInterface} [args.url]
185
188
  * @param {CryptoInterface} [args.crypto]
186
189
  * @param {PathInterface} [args.path]
187
- * @returns {MaybeReadPowers & ReadNowPowers}
190
+ * @returns {ReadNowPowers<FileUrlString>}
188
191
  */
189
192
  export const makeReadNowPowers = ({
190
193
  fs,
@@ -273,7 +276,7 @@ export const makeWritePowers = makeWritePowersSloppy;
273
276
  *
274
277
  * @param {FsInterface} fs
275
278
  * @param {CryptoInterface} [crypto]
276
- * @returns {ReadPowers}
279
+ * @returns {ReadPowers<FileUrlString>}
277
280
  * @deprecated
278
281
  */
279
282
  export const makeNodeReadPowers = (fs, crypto = undefined) => {
@@ -1 +1 @@
1
- {"version":3,"file":"parse-cjs-shared-export-wrapper.d.ts","sourceRoot":"","sources":["parse-cjs-shared-export-wrapper.js"],"names":[],"mappings":"AA0CO,2CAPI,UAAU,GAAG,MAAM,GAAG,SAAS,YAC/B,MAAM,GACJ;IACR,QAAQ,EAAC,MAAM,GAAC,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,GAAC,IAAI,CAAA;CACrB,CAgCH;AAmBM,uGAZJ;IAAmB,uBAAuB,EAAlC,MAAM;IACU,WAAW,EAA3B,WAAW;IACgB,eAAe,EAA1C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IACX,QAAQ,EAAnB,MAAM;IAC8B,UAAU,EAA9C,MAAM,GAAG,UAAU,GAAG,SAAS;CACvC,GAAU;IACR,MAAM,EAAE;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE,CAAC;IACzB,aAAa,EAAE,GAAG,CAAC;IACnB,YAAY,WAAW;IACvB,OAAO,WAAW;CACnB,CA+IH;gCAhOqC,YAAY;4BAAZ,YAAY"}
1
+ {"version":3,"file":"parse-cjs-shared-export-wrapper.d.ts","sourceRoot":"","sources":["parse-cjs-shared-export-wrapper.js"],"names":[],"mappings":"AA0CO,2CAPI,UAAU,GAAG,MAAM,GAAG,SAAS,YAC/B,MAAM,GACJ;IACR,QAAQ,EAAC,MAAM,GAAC,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,GAAC,IAAI,CAAA;CACrB,CAgCH;AAmBM,uGAZJ;IAAmB,uBAAuB,EAAlC,MAAM;IACU,WAAW,EAA3B,WAAW;IACgB,eAAe,EAA1C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IACX,QAAQ,EAAnB,MAAM;IAC8B,UAAU,EAA9C,MAAM,GAAG,UAAU,GAAG,SAAS;CACvC,GAAU;IACR,MAAM,EAAE;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE,CAAC;IACzB,aAAa,EAAE,GAAG,CAAC;IACnB,YAAY,WAAW;IACvB,OAAO,WAAW;CACnB,CAiJH;gCAlOqC,YAAY;4BAAZ,YAAY"}
@@ -219,7 +219,9 @@ export const wrap = ({
219
219
  }
220
220
  } else {
221
221
  for (const prop of redefined) {
222
- moduleEnvironmentRecord[prop] = moduleEnvironmentRecord.default[prop];
222
+ if (prop !== 'default') {
223
+ moduleEnvironmentRecord[prop] = moduleEnvironmentRecord.default[prop];
224
+ }
223
225
  }
224
226
  }
225
227
  };
@@ -1,10 +1,27 @@
1
+ /**
2
+ * Const string to identify the internal attenuators compartment
3
+ */
4
+ export const ATTENUATORS_COMPARTMENT: "<ATTENUATORS>";
5
+ export const ENTRY_COMPARTMENT: "$root$";
6
+ export function generateCanonicalName({ isEntry, name, path }: PackageNamingKit): string;
1
7
  export const WILDCARD_POLICY_VALUE: "any";
2
- export function policyLookupHelper(packagePolicy: import("./types.js").PackagePolicy, field: "builtins" | "globals" | "packages", itemName: string): boolean | import("./types.js").AttenuationDefinition;
3
- export function isAllowingEverything(policyValue: unknown): policyValue is import("./types.js").WildcardPolicy;
4
- export function isAttenuationDefinition(allegedDefinition: unknown): allegedDefinition is import("./types.js").AttenuationDefinition;
5
- export function getAttenuatorFromDefinition(attenuationDefinition: import("./types.js").AttenuationDefinition): import("./types.js").UnifiedAttenuationDefinition;
6
- export function assertPackagePolicy(allegedPackagePolicy: unknown, path: string, url?: string): asserts allegedPackagePolicy is SomePackagePolicy | undefined;
8
+ export function policyLookupHelper(packagePolicy: PackagePolicy, field: PolicyEnforcementField, canonicalName: string): boolean | AttenuationDefinition;
9
+ export function isAllowingEverything(policyValue: unknown): policyValue is WildcardPolicy;
10
+ /**
11
+ * Type guard for `AttenuationDefinition`
12
+ */
13
+ export const isAttenuationDefinition: (value: unknown) => value is FullAttenuationDefinition | ImplicitAttenuationDefinition;
14
+ export function getAttenuatorFromDefinition(attenuationDefinition: AttenuationDefinition): UnifiedAttenuationDefinition;
15
+ export function assertPackagePolicy(allegedPackagePolicy: unknown, keypath: string, url?: string): asserts allegedPackagePolicy is SomePackagePolicy | undefined;
7
16
  export function assertPolicy(allegedPolicy: unknown): asserts allegedPolicy is (SomePolicy | undefined);
17
+ import type { PackageNamingKit } from './types.js';
18
+ import type { PackagePolicy } from './types.js';
19
+ import type { PolicyEnforcementField } from './types.js';
20
+ import type { AttenuationDefinition } from './types.js';
21
+ import type { WildcardPolicy } from './types.js';
22
+ import type { FullAttenuationDefinition } from './types.js';
23
+ import type { ImplicitAttenuationDefinition } from './types.js';
24
+ import type { UnifiedAttenuationDefinition } from './types.js';
8
25
  import type { SomePackagePolicy } from './types.js';
9
26
  import type { SomePolicy } from './types.js';
10
27
  //# sourceMappingURL=policy-format.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"policy-format.d.ts","sourceRoot":"","sources":["policy-format.js"],"names":[],"mappings":"AAeA,oCAAqC,KAAK,CAAC;AAepC,kDALI,OAAO,YAAY,EAAE,aAAa,SAClC,UAAU,GAAC,SAAS,GAAC,UAAU,YAC/B,MAAM,GACJ,OAAO,GAAG,OAAO,YAAY,EAAE,qBAAqB,CAyBhE;AAQM,kDAHI,OAAO,GACL,WAAW,IAAI,OAAO,YAAY,EAAE,cAAc,CAGxB;AAOhC,2DAHI,OAAO,GACL,iBAAiB,IAAI,OAAO,YAAY,EAAE,qBAAqB,CAS3E;AAOM,mEAHI,OAAO,YAAY,EAAE,qBAAqB,GACxC,OAAO,YAAY,EAAE,4BAA4B,CAuB7D;AA0CM,0DALI,OAAO,QACP,MAAM,QACN,MAAM,GACJ,QAAQ,oBAAoB,IAAI,iBAAiB,GAAC,SAAS,CA4DvE;AAUM,4CAHI,OAAO,GACL,QAAQ,aAAa,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC,CAgC7D;uCA7OgD,YAAY;gCAAZ,YAAY"}
1
+ {"version":3,"file":"policy-format.d.ts","sourceRoot":"","sources":["policy-format.js"],"names":[],"mappings":"AA8BA;;GAEG;AACH,sCAAuC,eAAe,CAAC;AAEvD,gCAAiC,QAAQ,CAAC;AAmBnC,+DAJI,gBAAgB,GACd,MAAM,CAWlB;AAED,oCAAqC,KAAK,CAAC;AAqEpC,kDALI,aAAa,SACb,sBAAsB,iBACtB,MAAM,GACJ,OAAO,GAAG,qBAAqB,CA2B3C;AAQM,kDAHI,OAAO,GACL,WAAW,IAAI,cAAc,CAGH;AA6EvC;;GAEG;AACH,6HAGG;AAQI,mEAHI,qBAAqB,GACnB,4BAA4B,CAwBxC;AAqGM,0DALI,OAAO,WACP,MAAM,QACN,MAAM,GACJ,QAAQ,oBAAoB,IAAI,iBAAiB,GAAC,SAAS,CA0DvE;AAUM,4CAHI,OAAO,GACL,QAAQ,aAAa,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC,CAiC7D;sCAvcQ,YAAY;mCAAZ,YAAY;4CAAZ,YAAY;2CAAZ,YAAY;oCAAZ,YAAY;+CAAZ,YAAY;mDAAZ,YAAY;kDAAZ,YAAY;uCAAZ,YAAY;gCAAZ,YAAY"}