@endo/compartment-mapper 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/README.md +50 -27
  2. package/archive-lite.d.ts +1 -0
  3. package/archive-lite.js +3 -0
  4. package/archive-parsers.d.ts +1 -0
  5. package/archive-parsers.js +3 -0
  6. package/archive.d.ts +1 -0
  7. package/archive.js +3 -0
  8. package/bundle.d.ts +1 -0
  9. package/bundle.js +3 -0
  10. package/capture-lite.d.ts +1 -0
  11. package/capture-lite.js +3 -0
  12. package/import-archive-lite.d.ts +1 -0
  13. package/import-archive-lite.js +3 -0
  14. package/import-archive-parsers.d.ts +1 -0
  15. package/import-archive-parsers.js +3 -0
  16. package/import-archive.d.ts +1 -0
  17. package/import-archive.js +3 -0
  18. package/import-lite.d.ts +1 -0
  19. package/import-lite.js +3 -0
  20. package/import-parsers.d.ts +1 -0
  21. package/import-parsers.js +3 -0
  22. package/import.d.ts +1 -0
  23. package/import.js +3 -0
  24. package/index.d.ts +1 -0
  25. package/index.js +3 -1
  26. package/node-modules.d.ts +1 -0
  27. package/node-modules.js +3 -0
  28. package/node-powers.d.ts +1 -0
  29. package/node-powers.js +3 -0
  30. package/package.json +10 -14
  31. package/src/archive-lite.d.ts +6 -6
  32. package/src/archive-lite.d.ts.map +1 -1
  33. package/src/archive-lite.js +35 -33
  34. package/src/archive.d.ts.map +1 -1
  35. package/src/archive.js +132 -28
  36. package/src/bundle.d.ts.map +1 -1
  37. package/src/bundle.js +54 -14
  38. package/src/capture-lite.d.ts +2 -2
  39. package/src/capture-lite.d.ts.map +1 -1
  40. package/src/capture-lite.js +21 -17
  41. package/src/compartment-map.d.ts +2 -1
  42. package/src/compartment-map.d.ts.map +1 -1
  43. package/src/compartment-map.js +11 -3
  44. package/src/extension.d.ts.map +1 -1
  45. package/src/extension.js +1 -3
  46. package/src/import-archive-lite.d.ts +3 -19
  47. package/src/import-archive-lite.d.ts.map +1 -1
  48. package/src/import-archive-lite.js +43 -57
  49. package/src/import-archive-parsers.d.ts.map +1 -1
  50. package/src/import-archive-parsers.js +1 -0
  51. package/src/import-archive.d.ts +2 -2
  52. package/src/import-archive.d.ts.map +1 -1
  53. package/src/import-archive.js +15 -12
  54. package/src/import-hook.d.ts +2 -1
  55. package/src/import-hook.d.ts.map +1 -1
  56. package/src/import-hook.js +87 -76
  57. package/src/import-lite.d.ts.map +1 -1
  58. package/src/import-lite.js +23 -23
  59. package/src/import.d.ts.map +1 -1
  60. package/src/import.js +47 -23
  61. package/src/infer-exports.d.ts.map +1 -1
  62. package/src/infer-exports.js +2 -3
  63. package/src/json.d.ts.map +1 -1
  64. package/src/json.js +1 -2
  65. package/src/link.d.ts.map +1 -1
  66. package/src/link.js +12 -29
  67. package/src/map-parser.d.ts.map +1 -1
  68. package/src/map-parser.js +21 -16
  69. package/src/node-module-specifier.d.ts.map +1 -1
  70. package/src/node-module-specifier.js +2 -3
  71. package/src/node-modules.d.ts +9 -7
  72. package/src/node-modules.d.ts.map +1 -1
  73. package/src/node-modules.js +176 -87
  74. package/src/node-powers.d.ts +8 -8
  75. package/src/node-powers.d.ts.map +1 -1
  76. package/src/node-powers.js +29 -24
  77. package/src/parse-archive-cjs.d.ts +3 -2
  78. package/src/parse-archive-cjs.d.ts.map +1 -1
  79. package/src/parse-archive-cjs.js +5 -4
  80. package/src/parse-archive-mjs.d.ts +3 -2
  81. package/src/parse-archive-mjs.d.ts.map +1 -1
  82. package/src/parse-archive-mjs.js +7 -5
  83. package/src/parse-bytes.d.ts +3 -2
  84. package/src/parse-bytes.d.ts.map +1 -1
  85. package/src/parse-bytes.js +7 -5
  86. package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
  87. package/src/parse-cjs-shared-export-wrapper.js +7 -6
  88. package/src/parse-cjs.d.ts +3 -2
  89. package/src/parse-cjs.d.ts.map +1 -1
  90. package/src/parse-cjs.js +14 -5
  91. package/src/parse-json.d.ts.map +1 -1
  92. package/src/parse-json.js +6 -6
  93. package/src/parse-mjs.d.ts +3 -2
  94. package/src/parse-mjs.d.ts.map +1 -1
  95. package/src/parse-mjs.js +3 -3
  96. package/src/parse-pre-cjs.d.ts +3 -2
  97. package/src/parse-pre-cjs.d.ts.map +1 -1
  98. package/src/parse-pre-cjs.js +14 -4
  99. package/src/parse-pre-mjs.d.ts +3 -2
  100. package/src/parse-pre-mjs.d.ts.map +1 -1
  101. package/src/parse-pre-mjs.js +4 -3
  102. package/src/parse-text.d.ts +3 -2
  103. package/src/parse-text.d.ts.map +1 -1
  104. package/src/parse-text.js +6 -5
  105. package/src/policy-format.d.ts +1 -1
  106. package/src/policy-format.d.ts.map +1 -1
  107. package/src/policy-format.js +5 -7
  108. package/src/policy.d.ts.map +1 -1
  109. package/src/policy.js +15 -10
  110. package/src/powers.d.ts.map +1 -1
  111. package/src/powers.js +15 -12
  112. package/src/search.d.ts.map +1 -1
  113. package/src/search.js +10 -7
  114. package/src/types/compartment-map-schema.d.ts +98 -0
  115. package/src/types/compartment-map-schema.d.ts.map +1 -0
  116. package/src/types/compartment-map-schema.ts +116 -0
  117. package/src/types/external.d.ts +256 -0
  118. package/src/types/external.d.ts.map +1 -0
  119. package/src/types/external.ts +379 -0
  120. package/src/types/internal.d.ts +161 -0
  121. package/src/types/internal.d.ts.map +1 -0
  122. package/src/types/internal.ts +216 -0
  123. package/src/types/node-powers.d.ts +46 -0
  124. package/src/types/node-powers.d.ts.map +1 -0
  125. package/src/types/node-powers.ts +52 -0
  126. package/src/types/policy-schema.d.ts +81 -0
  127. package/src/types/policy-schema.d.ts.map +1 -0
  128. package/src/types/policy-schema.ts +131 -0
  129. package/src/types/policy.d.ts +20 -0
  130. package/src/types/policy.d.ts.map +1 -0
  131. package/src/types/policy.ts +42 -0
  132. package/src/types/powers.d.ts +83 -0
  133. package/src/types/powers.d.ts.map +1 -0
  134. package/src/types/powers.ts +120 -0
  135. package/src/types/typescript.d.ts +28 -0
  136. package/src/types/typescript.d.ts.map +1 -0
  137. package/src/types/typescript.ts +41 -0
  138. package/src/types-external.d.ts +14 -0
  139. package/src/types-external.js +2 -0
  140. package/src/types.d.ts +9 -787
  141. package/src/url.d.ts.map +1 -1
  142. package/src/url.js +2 -3
  143. package/src/types.d.ts.map +0 -1
  144. package/src/types.js +0 -995
  145. package/types.d.ts +0 -19
@@ -0,0 +1 @@
1
+ {"version":3,"file":"powers.d.ts","sourceRoot":"","sources":["powers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAIlD,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,WAAW,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,YAAY,CAAC,EAAE,cAAc,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,eAAe,CAAC;IAChC,aAAa,CAAC,EAAE,eAAe,CAAC;IAChC,cAAc,CAAC,EAAE,gBAAgB,CAAC;IAClC,UAAU,CAAC,EAAE,YAAY,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG;IACzC,SAAS,EAAE,WAAW,CAAC;CACxB,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,GAC7D,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,eAAe,GAAG,YAAY,GAAG,cAAc,CAAC;AAEhF;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAEhE,MAAM,MAAM,MAAM,GAAG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AAE7E,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,UAAU,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;AAInD,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,SAAS,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC"}
@@ -0,0 +1,120 @@
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
+
8
+ /* eslint-disable no-use-before-define */
9
+
10
+ import type { SomeObject } from './typescript.js';
11
+
12
+ // Read
13
+
14
+ export type ReadPowers = {
15
+ canonical: CanonicalFn;
16
+ read: ReadFn;
17
+ maybeRead?: MaybeReadFn;
18
+ readNow?: ReadNowFn;
19
+ maybeReadNow?: MaybeReadNowFn;
20
+ computeSha512?: HashFn;
21
+ fileURLToPath?: FileURLToPathFn;
22
+ pathToFileURL?: PathToFileURLFn;
23
+ requireResolve?: RequireResolveFn;
24
+ isAbsolute?: IsAbsoluteFn;
25
+ };
26
+
27
+ export type MaybeReadPowers = ReadPowers & {
28
+ maybeRead: MaybeReadFn;
29
+ };
30
+
31
+ /**
32
+ * The extension of {@link ReadPowers} necessary for dynamic require support
33
+ *
34
+ * For a `ReadPowers` to be a `ReadNowPowers`:
35
+ *
36
+ * 1. It must be an object (not a {@link ReadFn})
37
+ * 2. Prop `maybeReadNow` is a function
38
+ * 3. Prop `fileURLToPath` is a function
39
+ * 4. Prop `isAbsolute` is a function
40
+ */
41
+ export type ReadNowPowers = Omit<ReadPowers, ReadNowPowersProp> &
42
+ Required<Pick<ReadPowers, ReadNowPowersProp>>;
43
+
44
+ /**
45
+ * These properties are necessary for dynamic require support
46
+ */
47
+ export type ReadNowPowersProp = 'fileURLToPath' | 'isAbsolute' | 'maybeReadNow';
48
+
49
+ /**
50
+ * Returns a canonical URL for a given URL, following redirects or symbolic
51
+ * links if any exist along the path.
52
+ * Must return the given logical location if the real location does not exist.
53
+ */
54
+ export type CanonicalFn = (location: string) => Promise<string>;
55
+
56
+ export type ReadFn = (location: string) => Promise<Uint8Array>;
57
+
58
+ /**
59
+ * A resolution of `undefined` indicates `ENOENT` or the equivalent.
60
+ */
61
+ export type MaybeReadFn = (location: string) => Promise<Uint8Array | undefined>;
62
+
63
+ export type ReadNowFn = (location: string) => Uint8Array;
64
+
65
+ /**
66
+ * A resolution of `undefined` indicates `ENOENT` or the equivalent.
67
+ */
68
+ export type MaybeReadNowFn = (location: string) => Uint8Array | undefined;
69
+
70
+ export type HashFn = (bytes: Uint8Array) => string;
71
+
72
+ export type FileURLToPathFn = (location: string | URL) => string;
73
+
74
+ export type PathToFileURLFn = (location: string) => URL;
75
+
76
+ export type RequireResolveFn = (
77
+ fromLocation: string,
78
+ specifier: string,
79
+ options?:
80
+ | {
81
+ paths?: string[];
82
+ }
83
+ | undefined,
84
+ ) => any;
85
+
86
+ export type IsAbsoluteFn = (location: string) => boolean;
87
+
88
+ export type ArchiveReader = {
89
+ read: ReadFn;
90
+ };
91
+
92
+ export type HashPowers = {
93
+ read: ReadFn;
94
+ canonical: CanonicalFn;
95
+ computeSha512: HashFn;
96
+ };
97
+
98
+ // Write
99
+
100
+ export type WritePowers = {
101
+ write: WriteFn;
102
+ };
103
+
104
+ export type WriteFn = (location: string, bytes: Uint8Array) => Promise<void>;
105
+
106
+ export type ArchiveWriter = {
107
+ write: WriteFn;
108
+ snapshot: SnapshotFn;
109
+ };
110
+
111
+ export type SnapshotFn = () => Promise<Uint8Array>;
112
+
113
+ // Execute
114
+
115
+ export type Application = {
116
+ import: ExecuteFn;
117
+ sha512?: string | undefined;
118
+ };
119
+
120
+ export type ExecuteFn = (options?: any) => Promise<SomeObject>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @module Helpers relevant to any TypeScript project.
3
+ */
4
+ /** Any object. All objects. Not `null`, though. */
5
+ export type SomeObject = Record<PropertyKey, any>;
6
+ /**
7
+ * Matches any {@link
8
+ * https://developer.mozilla.org/en-US/docs/Glossary/Primitive primitive
9
+ * value}.
10
+ */
11
+ export type Primitive = null | undefined | string | number | boolean | symbol | bigint;
12
+ /**
13
+ * Allows creating a union type by combining primitive types and literal types
14
+ * without sacrificing auto-completion in IDEs for the literal type part of the
15
+ * union.
16
+ *
17
+ * Currently, when a union type of a primitive type is combined with literal
18
+ * types, TypeScript loses all information about the combined literals. Thus,
19
+ * when such a type is used in an IDE with autocompletion, no suggestions are
20
+ * made for the declared literals.
21
+ *
22
+ * This type is a workaround for {@link
23
+ * https://github.com/Microsoft/TypeScript/issues/29729
24
+ * Microsoft/TypeScript#29729}. It will be removed as soon as it's not needed
25
+ * anymore.
26
+ */
27
+ export type LiteralUnion<LiteralType, PrimitiveType extends Primitive> = LiteralType | (PrimitiveType & Record<never, never>);
28
+ //# sourceMappingURL=typescript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["typescript.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,mDAAmD;AACnD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,SAAS,GACjB,IAAI,GACJ,SAAS,GACT,MAAM,GACN,MAAM,GACN,OAAO,GACP,MAAM,GACN,MAAM,CAAC;AAEX;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,YAAY,CAAC,WAAW,EAAE,aAAa,SAAS,SAAS,IACjE,WAAW,GACX,CAAC,aAAa,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @module Helpers relevant to any TypeScript project.
3
+ */
4
+
5
+ /** Any object. All objects. Not `null`, though. */
6
+ export type SomeObject = Record<PropertyKey, any>;
7
+
8
+ /**
9
+ * Matches any {@link
10
+ * https://developer.mozilla.org/en-US/docs/Glossary/Primitive primitive
11
+ * value}.
12
+ */
13
+ export type Primitive =
14
+ | null
15
+ | undefined
16
+ | string
17
+ | number
18
+ | boolean
19
+ | symbol
20
+ | bigint;
21
+
22
+ /**
23
+ * Allows creating a union type by combining primitive types and literal types
24
+ * without sacrificing auto-completion in IDEs for the literal type part of the
25
+ * union.
26
+ *
27
+ * Currently, when a union type of a primitive type is combined with literal
28
+ * types, TypeScript loses all information about the combined literals. Thus,
29
+ * when such a type is used in an IDE with autocompletion, no suggestions are
30
+ * made for the declared literals.
31
+ *
32
+ * This type is a workaround for {@link
33
+ * https://github.com/Microsoft/TypeScript/issues/29729
34
+ * Microsoft/TypeScript#29729}. It will be removed as soon as it's not needed
35
+ * anymore.
36
+ */
37
+ export type LiteralUnion<LiteralType, PrimitiveType extends Primitive> =
38
+ | LiteralType
39
+ | (PrimitiveType & Record<never, never>);
40
+
41
+ // LiteralUnion is from https://www.npmjs.com/package/type-fest
@@ -0,0 +1,14 @@
1
+ // ESlint does not understand export *
2
+ /* eslint-disable import/export */
3
+
4
+ // These type definitions include all of the external types for the compartment
5
+ // mapper that propagate through each of the exported modules of the
6
+ // compartment mapper.
7
+ // See ./types.d.ts for the additional internal types.
8
+
9
+ export type * from './types/external.js';
10
+ export type * from './types/compartment-map-schema.js';
11
+ export type * from './types/policy-schema.js';
12
+ export type * from './types/policy.js';
13
+ export type * from './types/powers.js';
14
+ export type * from './types/node-powers.js';
@@ -0,0 +1,2 @@
1
+ // Empty JS file to correspond with its .d.ts twin
2
+ export {};