@endo/compartment-mapper 1.6.3 → 2.1.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 (95) hide show
  1. package/package.json +24 -14
  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 +81 -30
  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 +243 -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 +738 -254
  19. package/src/digest.d.ts +22 -2
  20. package/src/digest.d.ts.map +1 -1
  21. package/src/digest.js +180 -57
  22. package/src/generic-graph.d.ts +7 -25
  23. package/src/generic-graph.d.ts.map +1 -1
  24. package/src/generic-graph.js +83 -108
  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 +140 -70
  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 +4 -2
  44. package/src/infer-exports.d.ts.map +1 -1
  45. package/src/infer-exports.js +172 -23
  46. package/src/link.d.ts +4 -3
  47. package/src/link.d.ts.map +1 -1
  48. package/src/link.js +122 -52
  49. package/src/node-modules.d.ts +4 -3
  50. package/src/node-modules.d.ts.map +1 -1
  51. package/src/node-modules.js +513 -151
  52. package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
  53. package/src/parse-cjs-shared-export-wrapper.js +3 -1
  54. package/src/pattern-replacement.d.ts +6 -0
  55. package/src/pattern-replacement.d.ts.map +1 -0
  56. package/src/pattern-replacement.js +198 -0
  57. package/src/policy-format.d.ts +22 -5
  58. package/src/policy-format.d.ts.map +1 -1
  59. package/src/policy-format.js +342 -108
  60. package/src/policy.d.ts +13 -28
  61. package/src/policy.d.ts.map +1 -1
  62. package/src/policy.js +161 -106
  63. package/src/types/canonical-name.d.ts +97 -0
  64. package/src/types/canonical-name.d.ts.map +1 -0
  65. package/src/types/canonical-name.ts +151 -0
  66. package/src/types/compartment-map-schema.d.ts +121 -35
  67. package/src/types/compartment-map-schema.d.ts.map +1 -1
  68. package/src/types/compartment-map-schema.ts +211 -37
  69. package/src/types/external.d.ts +240 -76
  70. package/src/types/external.d.ts.map +1 -1
  71. package/src/types/external.ts +305 -74
  72. package/src/types/generic-graph.d.ts +8 -2
  73. package/src/types/generic-graph.d.ts.map +1 -1
  74. package/src/types/generic-graph.ts +7 -2
  75. package/src/types/internal.d.ts +31 -50
  76. package/src/types/internal.d.ts.map +1 -1
  77. package/src/types/internal.ts +60 -58
  78. package/src/types/node-modules.d.ts +112 -14
  79. package/src/types/node-modules.d.ts.map +1 -1
  80. package/src/types/node-modules.ts +152 -13
  81. package/src/types/pattern-replacement.d.ts +62 -0
  82. package/src/types/pattern-replacement.d.ts.map +1 -0
  83. package/src/types/pattern-replacement.ts +70 -0
  84. package/src/types/policy-schema.d.ts +26 -11
  85. package/src/types/policy-schema.d.ts.map +1 -1
  86. package/src/types/policy-schema.ts +29 -16
  87. package/src/types/policy.d.ts +6 -2
  88. package/src/types/policy.d.ts.map +1 -1
  89. package/src/types/policy.ts +7 -2
  90. package/src/types/powers.d.ts +11 -9
  91. package/src/types/powers.d.ts.map +1 -1
  92. package/src/types/powers.ts +11 -10
  93. package/src/types/typescript.d.ts +28 -0
  94. package/src/types/typescript.d.ts.map +1 -1
  95. package/src/types/typescript.ts +37 -1
@@ -5,76 +5,157 @@
5
5
  *
6
6
  * @module
7
7
  */
8
+ import type { ATTENUATORS_COMPARTMENT, ENTRY_COMPARTMENT } from '../policy-format.js';
9
+ import type { CanonicalName } from './canonical-name.js';
10
+ import type { FileUrlString } from './external.js';
8
11
  import type { SomePackagePolicy } from './policy-schema.js';
12
+ import type { PatternDescriptor } from './pattern-replacement.js';
9
13
  import type { LiteralUnion } from './typescript.js';
14
+ /**
15
+ * The type of a {@link CompartmentMapDescriptor.compartments} property.
16
+ */
17
+ export type CompartmentDescriptors<T extends CompartmentDescriptor = CompartmentDescriptor, K extends string = string> = Record<K, T>;
10
18
  /**
11
19
  * A compartment map describes how to construct an application as a graph of
12
20
  * Compartments, each corresponding to Node.js style packaged modules.
13
21
  */
14
- export type CompartmentMapDescriptor = {
22
+ export type CompartmentMapDescriptor<T extends CompartmentDescriptor = CompartmentDescriptor, Name extends string = string, EntryName extends string = Name> = {
15
23
  tags: Array<string>;
16
- entry: EntryDescriptor;
17
- compartments: Record<string, CompartmentDescriptor>;
24
+ entry: EntryDescriptor<EntryName>;
25
+ compartments: CompartmentDescriptors<T, Name>;
18
26
  };
27
+ /**
28
+ * The type of a {@link PackageCompartmentMapDescriptor.compartments} property.
29
+ */
30
+ export type PackageCompartmentDescriptors = CompartmentDescriptors<PackageCompartmentDescriptor, PackageCompartmentDescriptorName>;
31
+ /**
32
+ * The {@link CompartmentDescriptor} type in the
33
+ * {@link PackageCompartmentMapDescriptor} returned by `mapNodeModules()`
34
+ */
35
+ export type PackageCompartmentMapDescriptor = CompartmentMapDescriptor<PackageCompartmentDescriptor, PackageCompartmentDescriptorName, FileUrlString>;
36
+ export interface FileCompartmentDescriptor extends CompartmentDescriptor<FileModuleConfiguration | CompartmentModuleConfiguration> {
37
+ location: FileUrlString;
38
+ }
39
+ export type FileCompartmentDescriptors = CompartmentDescriptors<FileCompartmentDescriptor>;
40
+ export type FileCompartmentMapDescriptor = CompartmentMapDescriptor<FileCompartmentDescriptor>;
19
41
  /**
20
42
  * The entry descriptor of a compartment map denotes the root module of an
21
43
  * application and the compartment that contains it.
22
44
  */
23
- export type EntryDescriptor = {
24
- compartment: string;
45
+ export type EntryDescriptor<K extends string = string> = {
46
+ compartment: K;
25
47
  module: string;
26
48
  };
49
+ /**
50
+ * Keys of {@link PackageCompartmentMapDescriptor.compartments}
51
+ */
52
+ export type PackageCompartmentDescriptorName = LiteralUnion<typeof ATTENUATORS_COMPARTMENT, FileUrlString>;
53
+ export interface PackageCompartmentDescriptor extends CompartmentDescriptor<CompartmentModuleConfiguration> {
54
+ label: LiteralUnion<typeof ATTENUATORS_COMPARTMENT | typeof ENTRY_COMPARTMENT, string>;
55
+ version: string;
56
+ location: PackageCompartmentDescriptorName;
57
+ name: LiteralUnion<typeof ATTENUATORS_COMPARTMENT | typeof ENTRY_COMPARTMENT, string>;
58
+ scopes: Record<string, ScopeDescriptor<PackageCompartmentDescriptorName>>;
59
+ /**
60
+ * Wildcard patterns for dynamic module resolution within this compartment.
61
+ * `*` matches any substring including `/` (Node.js semantics).
62
+ * Stripped during digest/archiving - expanded patterns become concrete module entries.
63
+ */
64
+ patterns?: Array<PatternDescriptor>;
65
+ sourceDirname: string;
66
+ }
27
67
  /**
28
68
  * A compartment descriptor corresponds to a single Compartment
29
69
  * of an assembled Application and describes how to construct
30
70
  * one for a given library or application `package.json`.
31
71
  */
32
- export type CompartmentDescriptor = {
33
- label: string;
34
- /**
35
- * name of the parent directory of the package from which the compartment is derived,
36
- * for purposes of generating sourceURL comments that are most likely to unite with the original sources in an IDE workspace.
37
- */
38
- sourceDirname?: string;
39
- /** shortest path of dependency names to this compartment */
40
- path?: Array<string>;
72
+ export interface CompartmentDescriptor<T extends ModuleConfiguration = ModuleConfiguration, U extends string = string> {
73
+ label: CanonicalName<U>;
41
74
  /**
42
75
  * the name of the originating package suitable for constructing a sourceURL
43
76
  * prefix that will match it to files in a developer workspace.
44
77
  */
45
78
  name: string;
79
+ modules: Record<string, T>;
80
+ scopes?: Record<string, ScopeDescriptor>;
81
+ /** language for extension */
82
+ parsers?: LanguageForExtension;
83
+ /** language for module specifier */
84
+ types?: LanguageForModuleSpecifier;
85
+ /** policy specific to compartment */
86
+ policy?: SomePackagePolicy;
46
87
  location: string;
88
+ /**
89
+ * name of the parent directory of the package from which the compartment is derived,
90
+ * for purposes of generating sourceURL comments that are most likely to unite with the original sources in an IDE workspace.
91
+ */
92
+ sourceDirname?: string;
47
93
  /**
48
94
  * whether this compartment was retained by any module in the solution. This
49
95
  * property should never appear in an archived compartment map.
50
96
  */
51
- retained?: boolean;
52
- modules: Record<string, ModuleDescriptor>;
53
- scopes: Record<string, ScopeDescriptor>;
54
- /** language for extension */
55
- parsers: LanguageForExtension;
56
- /** language for module specifier */
57
- types: LanguageForModuleSpecifier;
58
- /** policy specific to compartment */
97
+ retained?: true;
98
+ }
99
+ export type CompartmentDescriptorWithPolicy<T extends ModuleConfiguration = ModuleConfiguration> = Omit<CompartmentDescriptor<T>, 'policy'> & {
59
100
  policy: SomePackagePolicy;
60
- /** List of compartment names this Compartment depends upon */
61
- compartments: Set<string>;
62
101
  };
102
+ /**
103
+ * A compartment descriptor digested by `digestCompartmentMap()`
104
+ */
105
+ export interface DigestedCompartmentDescriptor extends CompartmentDescriptor<ModuleConfiguration> {
106
+ path: never;
107
+ retained: never;
108
+ scopes: never;
109
+ parsers: never;
110
+ types: never;
111
+ __createdBy: never;
112
+ sourceDirname: never;
113
+ }
114
+ export type DigestedCompartmentDescriptors = CompartmentDescriptors<DigestedCompartmentDescriptor>;
115
+ export type DigestedCompartmentMapDescriptor = CompartmentMapDescriptor<DigestedCompartmentDescriptor>;
63
116
  /**
64
117
  * For every module explicitly mentioned in an `exports` field of a
65
- * `package.json`, there is a corresponding module descriptor.
118
+ * `package.json`, there is a corresponding `ModuleConfiguration`.
66
119
  */
67
- export type ModuleDescriptor = {
68
- compartment?: string;
69
- module?: string;
120
+ export type ModuleConfiguration = ErrorModuleConfiguration | ExitModuleConfiguration | FileModuleConfiguration | CompartmentModuleConfiguration;
121
+ export type ModuleConfigurationCreator = 'link' | 'link-pattern' | 'transform' | 'import-hook' | 'digest' | 'node-modules';
122
+ export interface BaseModuleConfiguration {
123
+ deferredError?: string;
124
+ retained?: true;
125
+ __createdBy?: ModuleConfigurationCreator;
126
+ }
127
+ export interface ErrorModuleConfiguration extends BaseModuleConfiguration {
128
+ deferredError: string;
129
+ }
130
+ /**
131
+ * This module configuration is a reference to another module in a a compartment descriptor (it may be the same compartment descriptor)
132
+ */
133
+ export interface CompartmentModuleConfiguration extends BaseModuleConfiguration {
134
+ /**
135
+ * The name of the compartment that contains this module.
136
+ */
137
+ compartment: LiteralUnion<typeof ATTENUATORS_COMPARTMENT, FileUrlString>;
138
+ /**
139
+ * The module name within {@link CompartmentDescriptor.modules} of the
140
+ * `CompartmentDescriptor` referred to by {@link compartment}
141
+ */
142
+ module: string;
143
+ }
144
+ /**
145
+ * A module configuration representing an exit module
146
+ */
147
+ export interface ExitModuleConfiguration extends BaseModuleConfiguration {
148
+ exit: string;
149
+ }
150
+ /**
151
+ * A module configuration representing a file on disk
152
+ */
153
+ export interface FileModuleConfiguration extends BaseModuleConfiguration {
70
154
  location?: string;
71
- parser?: Language;
155
+ parser: Language;
72
156
  /** in base 16, hex */
73
157
  sha512?: string;
74
- exit?: string;
75
- deferredError?: string;
76
- retained?: boolean;
77
- };
158
+ }
78
159
  /**
79
160
  * Scope descriptors link all names under a prefix to modules in another
80
161
  * compartment, like a wildcard.
@@ -82,8 +163,11 @@ export type ModuleDescriptor = {
82
163
  * in a `package.json` file, when that `package.json` file does not have
83
164
  * an explicit `exports` map.
84
165
  */
85
- export type ScopeDescriptor = {
86
- compartment: string;
166
+ export type ScopeDescriptor<T extends string = string> = {
167
+ /**
168
+ * A compartment name; not a `Compartment`.
169
+ */
170
+ compartment: T;
87
171
  module?: string;
88
172
  };
89
173
  /**
@@ -102,4 +186,6 @@ export type LanguageForExtension = Record<string, Language>;
102
186
  * Mapping of module specifier to {@link Language Languages}.
103
187
  */
104
188
  export type LanguageForModuleSpecifier = Record<string, Language>;
189
+ export type ModuleConfigurationKind = 'file' | 'compartment' | 'exit' | 'error';
190
+ export type ModuleConfigurationKindToType<T extends ModuleConfigurationKind> = T extends 'file' ? FileModuleConfiguration : T extends 'compartment' ? CompartmentModuleConfiguration : T extends 'exit' ? ExitModuleConfiguration : T extends 'error' ? ErrorModuleConfiguration : never;
105
191
  //# sourceMappingURL=compartment-map-schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compartment-map-schema.d.ts","sourceRoot":"","sources":["compartment-map-schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACpB,KAAK,EAAE,eAAe,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;CACrD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,4DAA4D;IAC5D,IAA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GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAElE,MAAM,MAAM,uBAAuB,GAAG,MAAM,GAAG,aAAa,GAAG,MAAM,GAAG,OAAO,CAAC;AAEhF,MAAM,MAAM,6BAA6B,CAAC,CAAC,SAAS,uBAAuB,IACzE,CAAC,SAAS,MAAM,GACZ,uBAAuB,GACvB,CAAC,SAAS,aAAa,GACrB,8BAA8B,GAC9B,CAAC,SAAS,MAAM,GACd,uBAAuB,GACvB,CAAC,SAAS,OAAO,GACf,wBAAwB,GACxB,KAAK,CAAC"}
@@ -8,80 +8,238 @@
8
8
 
9
9
  /* eslint-disable no-use-before-define */
10
10
 
11
+ import type {
12
+ ATTENUATORS_COMPARTMENT,
13
+ ENTRY_COMPARTMENT,
14
+ } from '../policy-format.js';
15
+ import type { CanonicalName } from './canonical-name.js';
16
+ import type { FileUrlString } from './external.js';
11
17
  import type { SomePackagePolicy } from './policy-schema.js';
18
+ import type { PatternDescriptor } from './pattern-replacement.js';
12
19
  import type { LiteralUnion } from './typescript.js';
13
20
 
21
+ /**
22
+ * The type of a {@link CompartmentMapDescriptor.compartments} property.
23
+ */
24
+ export type CompartmentDescriptors<
25
+ T extends CompartmentDescriptor = CompartmentDescriptor,
26
+ K extends string = string,
27
+ > = Record<K, T>;
28
+
14
29
  /**
15
30
  * A compartment map describes how to construct an application as a graph of
16
31
  * Compartments, each corresponding to Node.js style packaged modules.
17
32
  */
18
- export type CompartmentMapDescriptor = {
33
+ export type CompartmentMapDescriptor<
34
+ T extends CompartmentDescriptor = CompartmentDescriptor,
35
+ Name extends string = string,
36
+ EntryName extends string = Name,
37
+ > = {
19
38
  tags: Array<string>;
20
- entry: EntryDescriptor;
21
- compartments: Record<string, CompartmentDescriptor>;
39
+ entry: EntryDescriptor<EntryName>;
40
+ compartments: CompartmentDescriptors<T, Name>;
22
41
  };
23
42
 
43
+ /**
44
+ * The type of a {@link PackageCompartmentMapDescriptor.compartments} property.
45
+ */
46
+ export type PackageCompartmentDescriptors = CompartmentDescriptors<
47
+ PackageCompartmentDescriptor,
48
+ PackageCompartmentDescriptorName
49
+ >;
50
+
51
+ /**
52
+ * The {@link CompartmentDescriptor} type in the
53
+ * {@link PackageCompartmentMapDescriptor} returned by `mapNodeModules()`
54
+ */
55
+ export type PackageCompartmentMapDescriptor = CompartmentMapDescriptor<
56
+ PackageCompartmentDescriptor,
57
+ PackageCompartmentDescriptorName,
58
+ FileUrlString
59
+ >;
60
+
61
+ export interface FileCompartmentDescriptor
62
+ extends CompartmentDescriptor<
63
+ FileModuleConfiguration | CompartmentModuleConfiguration
64
+ > {
65
+ location: FileUrlString;
66
+ }
67
+
68
+ export type FileCompartmentDescriptors =
69
+ CompartmentDescriptors<FileCompartmentDescriptor>;
70
+
71
+ export type FileCompartmentMapDescriptor =
72
+ CompartmentMapDescriptor<FileCompartmentDescriptor>;
73
+
24
74
  /**
25
75
  * The entry descriptor of a compartment map denotes the root module of an
26
76
  * application and the compartment that contains it.
27
77
  */
28
- export type EntryDescriptor = {
29
- compartment: string;
78
+ export type EntryDescriptor<K extends string = string> = {
79
+ compartment: K;
30
80
  module: string;
31
81
  };
32
82
 
83
+ /**
84
+ * Keys of {@link PackageCompartmentMapDescriptor.compartments}
85
+ */
86
+ export type PackageCompartmentDescriptorName = LiteralUnion<
87
+ typeof ATTENUATORS_COMPARTMENT,
88
+ FileUrlString
89
+ >;
90
+
91
+ export interface PackageCompartmentDescriptor
92
+ extends CompartmentDescriptor<CompartmentModuleConfiguration> {
93
+ label: LiteralUnion<
94
+ typeof ATTENUATORS_COMPARTMENT | typeof ENTRY_COMPARTMENT,
95
+ string
96
+ >;
97
+
98
+ version: string;
99
+
100
+ location: PackageCompartmentDescriptorName;
101
+
102
+ name: LiteralUnion<
103
+ typeof ATTENUATORS_COMPARTMENT | typeof ENTRY_COMPARTMENT,
104
+ string
105
+ >;
106
+
107
+ scopes: Record<string, ScopeDescriptor<PackageCompartmentDescriptorName>>;
108
+
109
+ /**
110
+ * Wildcard patterns for dynamic module resolution within this compartment.
111
+ * `*` matches any substring including `/` (Node.js semantics).
112
+ * Stripped during digest/archiving - expanded patterns become concrete module entries.
113
+ */
114
+ patterns?: Array<PatternDescriptor>;
115
+
116
+ sourceDirname: string;
117
+ }
118
+
33
119
  /**
34
120
  * A compartment descriptor corresponds to a single Compartment
35
121
  * of an assembled Application and describes how to construct
36
122
  * one for a given library or application `package.json`.
37
123
  */
38
- export type CompartmentDescriptor = {
39
- label: string;
40
- /**
41
- * name of the parent directory of the package from which the compartment is derived,
42
- * for purposes of generating sourceURL comments that are most likely to unite with the original sources in an IDE workspace.
43
- */
44
- sourceDirname?: string;
45
- /** shortest path of dependency names to this compartment */
46
- path?: Array<string>;
124
+ export interface CompartmentDescriptor<
125
+ T extends ModuleConfiguration = ModuleConfiguration,
126
+ U extends string = string,
127
+ > {
128
+ label: CanonicalName<U>;
47
129
  /**
48
130
  * the name of the originating package suitable for constructing a sourceURL
49
131
  * prefix that will match it to files in a developer workspace.
50
132
  */
51
133
  name: string;
134
+ modules: Record<string, T>;
135
+ scopes?: Record<string, ScopeDescriptor>;
136
+ /** language for extension */
137
+ parsers?: LanguageForExtension;
138
+ /** language for module specifier */
139
+ types?: LanguageForModuleSpecifier;
140
+ /** policy specific to compartment */
141
+ policy?: SomePackagePolicy;
142
+
52
143
  location: string;
144
+ /**
145
+ * name of the parent directory of the package from which the compartment is derived,
146
+ * for purposes of generating sourceURL comments that are most likely to unite with the original sources in an IDE workspace.
147
+ */
148
+ sourceDirname?: string;
149
+
53
150
  /**
54
151
  * whether this compartment was retained by any module in the solution. This
55
152
  * property should never appear in an archived compartment map.
56
153
  */
57
- retained?: boolean;
58
- modules: Record<string, ModuleDescriptor>;
59
- scopes: Record<string, ScopeDescriptor>;
60
- /** language for extension */
61
- parsers: LanguageForExtension;
62
- /** language for module specifier */
63
- types: LanguageForModuleSpecifier;
64
- /** policy specific to compartment */
65
- policy: SomePackagePolicy;
66
- /** List of compartment names this Compartment depends upon */
67
- compartments: Set<string>;
68
- };
154
+ retained?: true;
155
+ }
156
+
157
+ export type CompartmentDescriptorWithPolicy<
158
+ T extends ModuleConfiguration = ModuleConfiguration,
159
+ > = Omit<CompartmentDescriptor<T>, 'policy'> & { policy: SomePackagePolicy };
160
+
161
+ /**
162
+ * A compartment descriptor digested by `digestCompartmentMap()`
163
+ */
164
+ export interface DigestedCompartmentDescriptor
165
+ extends CompartmentDescriptor<ModuleConfiguration> {
166
+ path: never;
167
+ retained: never;
168
+ scopes: never;
169
+ parsers: never;
170
+ types: never;
171
+ __createdBy: never;
172
+ sourceDirname: never;
173
+ }
174
+
175
+ export type DigestedCompartmentDescriptors =
176
+ CompartmentDescriptors<DigestedCompartmentDescriptor>;
177
+
178
+ export type DigestedCompartmentMapDescriptor =
179
+ CompartmentMapDescriptor<DigestedCompartmentDescriptor>;
69
180
 
70
181
  /**
71
182
  * For every module explicitly mentioned in an `exports` field of a
72
- * `package.json`, there is a corresponding module descriptor.
183
+ * `package.json`, there is a corresponding `ModuleConfiguration`.
73
184
  */
74
- export type ModuleDescriptor = {
75
- compartment?: string;
76
- module?: string;
185
+ export type ModuleConfiguration =
186
+ | ErrorModuleConfiguration
187
+ | ExitModuleConfiguration
188
+ | FileModuleConfiguration
189
+ | CompartmentModuleConfiguration;
190
+
191
+ export type ModuleConfigurationCreator =
192
+ | 'link'
193
+ | 'link-pattern'
194
+ | 'transform'
195
+ | 'import-hook'
196
+ | 'digest'
197
+ | 'node-modules';
198
+
199
+ export interface BaseModuleConfiguration {
200
+ deferredError?: string;
201
+
202
+ retained?: true;
203
+
204
+ __createdBy?: ModuleConfigurationCreator;
205
+ }
206
+
207
+ export interface ErrorModuleConfiguration extends BaseModuleConfiguration {
208
+ deferredError: string;
209
+ }
210
+
211
+ /**
212
+ * This module configuration is a reference to another module in a a compartment descriptor (it may be the same compartment descriptor)
213
+ */
214
+ export interface CompartmentModuleConfiguration
215
+ extends BaseModuleConfiguration {
216
+ /**
217
+ * The name of the compartment that contains this module.
218
+ */
219
+ compartment: LiteralUnion<typeof ATTENUATORS_COMPARTMENT, FileUrlString>;
220
+ /**
221
+ * The module name within {@link CompartmentDescriptor.modules} of the
222
+ * `CompartmentDescriptor` referred to by {@link compartment}
223
+ */
224
+ module: string;
225
+ }
226
+
227
+ /**
228
+ * A module configuration representing an exit module
229
+ */
230
+ export interface ExitModuleConfiguration extends BaseModuleConfiguration {
231
+ exit: string;
232
+ }
233
+
234
+ /**
235
+ * A module configuration representing a file on disk
236
+ */
237
+ export interface FileModuleConfiguration extends BaseModuleConfiguration {
77
238
  location?: string;
78
- parser?: Language;
239
+ parser: Language;
79
240
  /** in base 16, hex */
80
241
  sha512?: string;
81
- exit?: string;
82
- deferredError?: string;
83
- retained?: boolean;
84
- };
242
+ }
85
243
 
86
244
  /**
87
245
  * Scope descriptors link all names under a prefix to modules in another
@@ -90,8 +248,11 @@ export type ModuleDescriptor = {
90
248
  * in a `package.json` file, when that `package.json` file does not have
91
249
  * an explicit `exports` map.
92
250
  */
93
- export type ScopeDescriptor = {
94
- compartment: string;
251
+ export type ScopeDescriptor<T extends string = string> = {
252
+ /**
253
+ * A compartment name; not a `Compartment`.
254
+ */
255
+ compartment: T;
95
256
  module?: string;
96
257
  };
97
258
 
@@ -121,3 +282,16 @@ export type LanguageForExtension = Record<string, Language>;
121
282
  * Mapping of module specifier to {@link Language Languages}.
122
283
  */
123
284
  export type LanguageForModuleSpecifier = Record<string, Language>;
285
+
286
+ export type ModuleConfigurationKind = 'file' | 'compartment' | 'exit' | 'error';
287
+
288
+ export type ModuleConfigurationKindToType<T extends ModuleConfigurationKind> =
289
+ T extends 'file'
290
+ ? FileModuleConfiguration
291
+ : T extends 'compartment'
292
+ ? CompartmentModuleConfiguration
293
+ : T extends 'exit'
294
+ ? ExitModuleConfiguration
295
+ : T extends 'error'
296
+ ? ErrorModuleConfiguration
297
+ : never;