@endo/compartment-mapper 1.2.1 → 1.3.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.
- package/archive-lite.d.ts.map +1 -0
- package/archive-parsers.d.ts.map +1 -0
- package/archive.d.ts.map +1 -0
- package/bundle.d.ts.map +1 -0
- package/capture-lite.d.ts.map +1 -0
- package/import-archive-lite.d.ts.map +1 -0
- package/import-archive-parsers.d.ts.map +1 -0
- package/import-archive.d.ts.map +1 -0
- package/import-lite.d.ts.map +1 -0
- package/import-parsers.d.ts.map +1 -0
- package/import.d.ts.map +1 -0
- package/index.d.ts.map +1 -0
- package/node-modules.d.ts.map +1 -0
- package/node-powers.d.ts +1 -1
- package/node-powers.d.ts.map +1 -0
- package/node-powers.js +5 -1
- package/package.json +15 -11
- package/src/compartment-map.d.ts +1 -1
- package/src/compartment-map.d.ts.map +1 -1
- package/src/compartment-map.js +1 -1
- package/src/import-hook.d.ts +14 -1
- package/src/import-hook.d.ts.map +1 -1
- package/src/import-hook.js +493 -144
- package/src/import-lite.d.ts +20 -3
- package/src/import-lite.d.ts.map +1 -1
- package/src/import-lite.js +137 -15
- package/src/import.d.ts +45 -5
- package/src/import.d.ts.map +1 -1
- package/src/import.js +52 -6
- package/src/link.d.ts +2 -11
- package/src/link.d.ts.map +1 -1
- package/src/link.js +76 -154
- package/src/map-parser.d.ts +4 -0
- package/src/map-parser.d.ts.map +1 -0
- package/src/map-parser.js +339 -0
- package/src/node-modules.d.ts +2 -5
- package/src/node-modules.d.ts.map +1 -1
- package/src/node-modules.js +12 -5
- package/src/node-powers.d.ts +29 -23
- package/src/node-powers.d.ts.map +1 -1
- package/src/node-powers.js +102 -25
- package/src/parse-archive-cjs.js +2 -1
- package/src/parse-archive-mjs.js +2 -1
- package/src/parse-bytes.d.ts.map +1 -1
- package/src/parse-bytes.js +2 -6
- package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
- package/src/parse-cjs-shared-export-wrapper.js +23 -6
- package/src/parse-cjs.js +3 -2
- package/src/parse-json.d.ts +5 -3
- package/src/parse-json.d.ts.map +1 -1
- package/src/parse-json.js +9 -9
- package/src/parse-mjs.js +2 -1
- package/src/parse-pre-cjs.js +3 -2
- package/src/parse-pre-mjs.js +2 -1
- package/src/parse-text.d.ts.map +1 -1
- package/src/parse-text.js +2 -6
- package/src/policy.d.ts +21 -14
- package/src/policy.d.ts.map +1 -1
- package/src/policy.js +56 -37
- package/src/powers.d.ts +8 -1
- package/src/powers.d.ts.map +1 -1
- package/src/powers.js +60 -10
- package/src/search.d.ts.map +1 -1
- package/src/search.js +1 -2
- package/src/types.d.ts +343 -21
- package/src/types.d.ts.map +1 -1
- package/src/types.js +369 -22
package/src/policy.d.ts
CHANGED
|
@@ -2,30 +2,30 @@
|
|
|
2
2
|
* Const string to identify the internal attenuators compartment
|
|
3
3
|
*/
|
|
4
4
|
export const ATTENUATORS_COMPARTMENT: "<ATTENUATORS>";
|
|
5
|
-
export function detectAttenuators(policy?:
|
|
6
|
-
export function dependencyAllowedByPolicy(namingKit:
|
|
5
|
+
export function detectAttenuators(policy?: Policy | undefined): Array<string>;
|
|
6
|
+
export function dependencyAllowedByPolicy(namingKit: PackageNamingKit, packagePolicy: PackagePolicy): boolean;
|
|
7
7
|
/**
|
|
8
8
|
* Returns the policy applicable to the canonicalName of the package
|
|
9
9
|
*
|
|
10
10
|
* @overload
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {
|
|
13
|
-
* @returns {
|
|
11
|
+
* @param {PackageNamingKit} namingKit - a key in the policy resources spec is derived from these
|
|
12
|
+
* @param {SomePolicy} policy - user supplied policy
|
|
13
|
+
* @returns {SomePackagePolicy} packagePolicy if policy was specified
|
|
14
14
|
*/
|
|
15
|
-
export function getPolicyForPackage(namingKit:
|
|
15
|
+
export function getPolicyForPackage(namingKit: PackageNamingKit, policy: SomePolicy): SomePackagePolicy;
|
|
16
16
|
/**
|
|
17
17
|
* Returns `undefined`
|
|
18
18
|
*
|
|
19
19
|
* @overload
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {
|
|
22
|
-
* @returns {
|
|
20
|
+
* @param {PackageNamingKit} namingKit - a key in the policy resources spec is derived from these
|
|
21
|
+
* @param {SomePolicy} [policy] - user supplied policy
|
|
22
|
+
* @returns {SomePackagePolicy|undefined} packagePolicy if policy was specified
|
|
23
23
|
*/
|
|
24
|
-
export function getPolicyForPackage(namingKit:
|
|
25
|
-
export function makeDeferredAttenuatorsProvider(compartments: Record<string, Compartment>, compartmentDescriptors: Record<string,
|
|
26
|
-
export function attenuateGlobals(globalThis: object, globals: object, packagePolicy:
|
|
27
|
-
export function enforceModulePolicy(specifier: string, compartmentDescriptor:
|
|
28
|
-
export function attenuateModuleHook(specifier: string, originalModuleRecord: import("ses").ThirdPartyStaticModuleInterface, policy:
|
|
24
|
+
export function getPolicyForPackage(namingKit: PackageNamingKit, policy?: SomePolicy | undefined): SomePackagePolicy | undefined;
|
|
25
|
+
export function makeDeferredAttenuatorsProvider(compartments: Record<string, Compartment>, compartmentDescriptors: Record<string, CompartmentDescriptor>): DeferredAttenuatorsProvider;
|
|
26
|
+
export function attenuateGlobals(globalThis: object, globals: object, packagePolicy: PackagePolicy, attenuators: DeferredAttenuatorsProvider, pendingJobs: Array<Promise<any>>, name?: string): void;
|
|
27
|
+
export function enforceModulePolicy(specifier: string, compartmentDescriptor: CompartmentDescriptor, { exit, errorHint }?: EnforceModulePolicyOptions | undefined): void;
|
|
28
|
+
export function attenuateModuleHook(specifier: string, originalModuleRecord: import("ses").ThirdPartyStaticModuleInterface, policy: PackagePolicy, attenuators: DeferredAttenuatorsProvider): Promise<import("ses").ThirdPartyStaticModuleInterface>;
|
|
29
29
|
/**
|
|
30
30
|
* Options for {@link enforceModulePolicy}
|
|
31
31
|
*/
|
|
@@ -39,4 +39,11 @@ export type EnforceModulePolicyOptions = {
|
|
|
39
39
|
*/
|
|
40
40
|
errorHint?: string | undefined;
|
|
41
41
|
};
|
|
42
|
+
import type { Policy } from './types.js';
|
|
43
|
+
import type { PackageNamingKit } from './types.js';
|
|
44
|
+
import type { PackagePolicy } from './types.js';
|
|
45
|
+
import type { SomePolicy } from './types.js';
|
|
46
|
+
import type { SomePackagePolicy } from './types.js';
|
|
47
|
+
import type { CompartmentDescriptor } from './types.js';
|
|
48
|
+
import type { DeferredAttenuatorsProvider } from './types.js';
|
|
42
49
|
//# sourceMappingURL=policy.d.ts.map
|
package/src/policy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["policy.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["policy.js"],"names":[],"mappings":"AA2BA;;GAEG;AACH,sDAAuD;AAyDhD,gEAFM,KAAK,CAAC,MAAM,CAAC,CAezB;AA0BM,qDAJI,gBAAgB,iBAChB,aAAa,GACX,OAAO,CASnB;;;;;;;;;AAKE,+CACQ,gBAAgB,UAChB,UAAU,GACR,iBAAiB,CAC7B;;;;;;;;;AAKE,+CACQ,gBAAgB,oCAEd,iBAAiB,GAAC,SAAS,CACvC;AAkFM,8DAJI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,0BAC3B,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,GACnC,2BAA2B,CA0CvC;AAoDM,6CARI,MAAM,WACN,MAAM,iBACN,aAAa,eACb,2BAA2B,eAC3B,KAAK,cAAS,SACd,MAAM,GACJ,IAAI,CAgDhB;AA2BM,+CAJI,MAAM,yBACN,qBAAqB,sEAiC/B;AAgDM,+CANI,MAAM,wBACN,OAAO,KAAK,EAAE,+BAA+B,UAC7C,aAAa,eACb,2BAA2B,GACzB,OAAO,CAAC,OAAO,KAAK,EAAE,+BAA+B,CAAC,CAyBlE;;;;;;;;;;;;;;4BA9eyB,YAAY;sCAGF,YAAY;mCAFf,YAAY;gCAMf,YAAY;uCACL,YAAY;2CAHR,YAAY;iDADN,YAAY"}
|
package/src/policy.js
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
|
|
4
4
|
// @ts-check
|
|
5
5
|
|
|
6
|
+
/** @import {Policy} from './types.js' */
|
|
7
|
+
/** @import {PackagePolicy} from './types.js' */
|
|
8
|
+
/** @import {AttenuationDefinition} from './types.js' */
|
|
9
|
+
/** @import {PackageNamingKit} from './types.js' */
|
|
10
|
+
/** @import {DeferredAttenuatorsProvider} from './types.js' */
|
|
11
|
+
/** @import {CompartmentDescriptor} from './types.js' */
|
|
12
|
+
/** @import {Attenuator} from './types.js' */
|
|
13
|
+
/** @import {SomePolicy} from './types.js' */
|
|
14
|
+
/** @import {SomePackagePolicy} from './types.js' */
|
|
15
|
+
|
|
6
16
|
import {
|
|
7
17
|
getAttenuatorFromDefinition,
|
|
8
18
|
isAllowingEverything,
|
|
@@ -10,7 +20,9 @@ import {
|
|
|
10
20
|
policyLookupHelper,
|
|
11
21
|
} from './policy-format.js';
|
|
12
22
|
|
|
13
|
-
const { create, entries, values, assign,
|
|
23
|
+
const { create, entries, values, assign, freeze, getOwnPropertyDescriptors } =
|
|
24
|
+
Object;
|
|
25
|
+
const { ownKeys } = Reflect;
|
|
14
26
|
const q = JSON.stringify;
|
|
15
27
|
|
|
16
28
|
/**
|
|
@@ -20,18 +32,25 @@ export const ATTENUATORS_COMPARTMENT = '<ATTENUATORS>';
|
|
|
20
32
|
|
|
21
33
|
/**
|
|
22
34
|
* Copies properties (optionally limited to a specific list) from one object to another.
|
|
23
|
-
*
|
|
24
|
-
* @
|
|
25
|
-
* @
|
|
26
|
-
* @param {
|
|
27
|
-
* @
|
|
35
|
+
* @template {Record<PropertyKey, any>} T
|
|
36
|
+
* @template {Record<PropertyKey, any>} U
|
|
37
|
+
* @template {Array<Partial<keyof T>>} [K=Array<keyof T>]
|
|
38
|
+
* @param {T} from
|
|
39
|
+
* @param {U} to
|
|
40
|
+
* @param {K} [list]
|
|
41
|
+
* @returns {Omit<U, K[number]> & Pick<T, K[number]>}
|
|
28
42
|
*/
|
|
29
43
|
const selectiveCopy = (from, to, list) => {
|
|
44
|
+
/** @type {Array<Partial<keyof T>>} */
|
|
45
|
+
let props;
|
|
30
46
|
if (!list) {
|
|
31
|
-
|
|
47
|
+
const descs = getOwnPropertyDescriptors(from);
|
|
48
|
+
props = ownKeys(from).filter(key => descs[key].enumerable);
|
|
49
|
+
} else {
|
|
50
|
+
props = list;
|
|
32
51
|
}
|
|
33
|
-
for (let index = 0; index <
|
|
34
|
-
const key =
|
|
52
|
+
for (let index = 0; index < props.length; index += 1) {
|
|
53
|
+
const key = props[index];
|
|
35
54
|
// If an endowment is missing, global value is undefined.
|
|
36
55
|
// This is an expected behavior if globals are used for platform feature detection
|
|
37
56
|
to[key] = from[key];
|
|
@@ -44,7 +63,7 @@ const selectiveCopy = (from, to, list) => {
|
|
|
44
63
|
*
|
|
45
64
|
* Note: this function is recursive
|
|
46
65
|
* @param {string[]} attenuators - List of attenuator names; may be mutated
|
|
47
|
-
* @param {
|
|
66
|
+
* @param {AttenuationDefinition|Policy} policyFragment
|
|
48
67
|
*/
|
|
49
68
|
const collectAttenuators = (attenuators, policyFragment) => {
|
|
50
69
|
if ('attenuate' in policyFragment) {
|
|
@@ -63,7 +82,7 @@ const attenuatorsCache = new WeakMap();
|
|
|
63
82
|
* Goes through policy and lists all attenuator specifiers used.
|
|
64
83
|
* Memoization keyed on policy object reference
|
|
65
84
|
*
|
|
66
|
-
* @param {
|
|
85
|
+
* @param {Policy} [policy]
|
|
67
86
|
* @returns {Array<string>} attenuators
|
|
68
87
|
*/
|
|
69
88
|
export const detectAttenuators = policy => {
|
|
@@ -84,7 +103,7 @@ export const detectAttenuators = policy => {
|
|
|
84
103
|
/**
|
|
85
104
|
* Generates a string identifying a package for policy lookup purposes.
|
|
86
105
|
*
|
|
87
|
-
* @param {
|
|
106
|
+
* @param {PackageNamingKit} namingKit
|
|
88
107
|
* @returns {string}
|
|
89
108
|
*/
|
|
90
109
|
const generateCanonicalName = ({ isEntry = false, name, path }) => {
|
|
@@ -101,8 +120,8 @@ const generateCanonicalName = ({ isEntry = false, name, path }) => {
|
|
|
101
120
|
* Verifies if a module identified by `namingKit` can be a dependency of a package per `packagePolicy`.
|
|
102
121
|
* `packagePolicy` is required, when policy is not set, skipping needs to be handled by the caller.
|
|
103
122
|
*
|
|
104
|
-
* @param {
|
|
105
|
-
* @param {
|
|
123
|
+
* @param {PackageNamingKit} namingKit
|
|
124
|
+
* @param {PackagePolicy} packagePolicy
|
|
106
125
|
* @returns {boolean}
|
|
107
126
|
*/
|
|
108
127
|
export const dependencyAllowedByPolicy = (namingKit, packagePolicy) => {
|
|
@@ -118,25 +137,25 @@ export const dependencyAllowedByPolicy = (namingKit, packagePolicy) => {
|
|
|
118
137
|
* Returns the policy applicable to the canonicalName of the package
|
|
119
138
|
*
|
|
120
139
|
* @overload
|
|
121
|
-
* @param {
|
|
122
|
-
* @param {
|
|
123
|
-
* @returns {
|
|
140
|
+
* @param {PackageNamingKit} namingKit - a key in the policy resources spec is derived from these
|
|
141
|
+
* @param {SomePolicy} policy - user supplied policy
|
|
142
|
+
* @returns {SomePackagePolicy} packagePolicy if policy was specified
|
|
124
143
|
*/
|
|
125
144
|
|
|
126
145
|
/**
|
|
127
146
|
* Returns `undefined`
|
|
128
147
|
*
|
|
129
148
|
* @overload
|
|
130
|
-
* @param {
|
|
131
|
-
* @param {
|
|
132
|
-
* @returns {
|
|
149
|
+
* @param {PackageNamingKit} namingKit - a key in the policy resources spec is derived from these
|
|
150
|
+
* @param {SomePolicy} [policy] - user supplied policy
|
|
151
|
+
* @returns {SomePackagePolicy|undefined} packagePolicy if policy was specified
|
|
133
152
|
*/
|
|
134
153
|
|
|
135
154
|
/**
|
|
136
155
|
* Returns the policy applicable to the canonicalName of the package
|
|
137
156
|
*
|
|
138
|
-
* @param {
|
|
139
|
-
* @param {
|
|
157
|
+
* @param {PackageNamingKit} namingKit - a key in the policy resources spec is derived from these
|
|
158
|
+
* @param {SomePolicy} [policy] - user supplied policy
|
|
140
159
|
*/
|
|
141
160
|
export const getPolicyForPackage = (namingKit, policy) => {
|
|
142
161
|
if (!policy) {
|
|
@@ -162,7 +181,7 @@ export const getPolicyForPackage = (namingKit, policy) => {
|
|
|
162
181
|
|
|
163
182
|
/**
|
|
164
183
|
* Get list of globals from package policy
|
|
165
|
-
* @param {
|
|
184
|
+
* @param {PackagePolicy} [packagePolicy]
|
|
166
185
|
* @returns {Array<string>}
|
|
167
186
|
*/
|
|
168
187
|
const getGlobalsList = packagePolicy => {
|
|
@@ -179,8 +198,8 @@ const MODULE_ATTENUATOR = 'attenuateModule';
|
|
|
179
198
|
|
|
180
199
|
/**
|
|
181
200
|
* Imports attenuator per its definition and provider
|
|
182
|
-
* @param {
|
|
183
|
-
* @param {
|
|
201
|
+
* @param {AttenuationDefinition} attenuationDefinition
|
|
202
|
+
* @param {DeferredAttenuatorsProvider} attenuatorsProvider
|
|
184
203
|
* @param {string} attenuatorExportName
|
|
185
204
|
* @returns {Promise<Function>}
|
|
186
205
|
*/
|
|
@@ -209,8 +228,8 @@ const importAttenuatorForDefinition = async (
|
|
|
209
228
|
/**
|
|
210
229
|
* Makes an async provider for attenuators
|
|
211
230
|
* @param {Record<string, Compartment>} compartments
|
|
212
|
-
* @param {Record<string,
|
|
213
|
-
* @returns {
|
|
231
|
+
* @param {Record<string, CompartmentDescriptor>} compartmentDescriptors
|
|
232
|
+
* @returns {DeferredAttenuatorsProvider}
|
|
214
233
|
*/
|
|
215
234
|
export const makeDeferredAttenuatorsProvider = (
|
|
216
235
|
compartments,
|
|
@@ -234,7 +253,7 @@ export const makeDeferredAttenuatorsProvider = (
|
|
|
234
253
|
/**
|
|
235
254
|
*
|
|
236
255
|
* @param {string} attenuatorSpecifier
|
|
237
|
-
* @returns {Promise<
|
|
256
|
+
* @returns {Promise<Attenuator>}
|
|
238
257
|
*/
|
|
239
258
|
importAttenuator = async attenuatorSpecifier => {
|
|
240
259
|
if (!attenuatorSpecifier) {
|
|
@@ -258,8 +277,8 @@ export const makeDeferredAttenuatorsProvider = (
|
|
|
258
277
|
* Attenuates the `globalThis` object
|
|
259
278
|
*
|
|
260
279
|
* @param {object} options
|
|
261
|
-
* @param {
|
|
262
|
-
* @param {
|
|
280
|
+
* @param {DeferredAttenuatorsProvider} options.attenuators
|
|
281
|
+
* @param {AttenuationDefinition} options.attenuationDefinition
|
|
263
282
|
* @param {object} options.globalThis
|
|
264
283
|
* @param {object} options.globals
|
|
265
284
|
*/
|
|
@@ -298,8 +317,8 @@ async function attenuateGlobalThis({
|
|
|
298
317
|
*
|
|
299
318
|
* @param {object} globalThis
|
|
300
319
|
* @param {object} globals
|
|
301
|
-
* @param {
|
|
302
|
-
* @param {
|
|
320
|
+
* @param {PackagePolicy} packagePolicy
|
|
321
|
+
* @param {DeferredAttenuatorsProvider} attenuators
|
|
303
322
|
* @param {Array<Promise>} pendingJobs
|
|
304
323
|
* @param {string} name
|
|
305
324
|
* @returns {void}
|
|
@@ -374,7 +393,7 @@ const diagnoseModulePolicy = errorHint => {
|
|
|
374
393
|
* Throws if importing of the specifier is not allowed by the policy
|
|
375
394
|
*
|
|
376
395
|
* @param {string} specifier
|
|
377
|
-
* @param {
|
|
396
|
+
* @param {CompartmentDescriptor} compartmentDescriptor
|
|
378
397
|
* @param {EnforceModulePolicyOptions} [options]
|
|
379
398
|
*/
|
|
380
399
|
export const enforceModulePolicy = (
|
|
@@ -412,8 +431,8 @@ export const enforceModulePolicy = (
|
|
|
412
431
|
/**
|
|
413
432
|
* Attenuates a module
|
|
414
433
|
* @param {object} options
|
|
415
|
-
* @param {
|
|
416
|
-
* @param {
|
|
434
|
+
* @param {DeferredAttenuatorsProvider} options.attenuators
|
|
435
|
+
* @param {AttenuationDefinition} options.attenuationDefinition
|
|
417
436
|
* @param {import('ses').ThirdPartyStaticModuleInterface} options.originalModuleRecord
|
|
418
437
|
* @returns {Promise<import('ses').ThirdPartyStaticModuleInterface>}
|
|
419
438
|
*/
|
|
@@ -451,8 +470,8 @@ async function attenuateModule({
|
|
|
451
470
|
*
|
|
452
471
|
* @param {string} specifier - exit module name
|
|
453
472
|
* @param {import('ses').ThirdPartyStaticModuleInterface} originalModuleRecord - reference to the exit module
|
|
454
|
-
* @param {
|
|
455
|
-
* @param {
|
|
473
|
+
* @param {PackagePolicy} policy - local compartment policy
|
|
474
|
+
* @param {DeferredAttenuatorsProvider} attenuators - a key-value where attenuations can be found
|
|
456
475
|
* @returns {Promise<import('ses').ThirdPartyStaticModuleInterface>} - the attenuated module
|
|
457
476
|
*/
|
|
458
477
|
export const attenuateModuleHook = async (
|
package/src/powers.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
export function unpackReadPowers(powers:
|
|
1
|
+
export function unpackReadPowers(powers: ReadFn | ReadPowers | MaybeReadPowers): MaybeReadPowers;
|
|
2
|
+
export function isReadNowPowers(value: ReadPowers | ReadFn | undefined): value is ReadNowPowers;
|
|
3
|
+
export function findInvalidReadNowPowersProps(value?: ReadFn | ReadPowers | undefined): ReadNowPowersProp[];
|
|
4
|
+
import type { ReadFn } from './types.js';
|
|
5
|
+
import type { ReadPowers } from './types.js';
|
|
6
|
+
import type { MaybeReadPowers } from './types.js';
|
|
7
|
+
import type { ReadNowPowers } from './types.js';
|
|
8
|
+
import type { ReadNowPowersProp } from './types.js';
|
|
2
9
|
//# sourceMappingURL=powers.d.ts.map
|
package/src/powers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"powers.d.ts","sourceRoot":"","sources":["powers.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"powers.d.ts","sourceRoot":"","sources":["powers.js"],"names":[],"mappings":"AA0BO,yCAHI,MAAM,GAAG,UAAU,GAAG,eAAe,GACnC,eAAe,CAgC3B;AAiBM,uCAHI,UAAU,GAAC,MAAM,GAAC,SAAS,GACzB,KAAK,IAAI,aAAa,CAShC;AAWI,wFAFM,iBAAiB,EAAE,CAS/B;4BAtFyB,YAAY;gCACR,YAAY;qCACP,YAAY;mCAJd,YAAY;uCACR,YAAY"}
|
package/src/powers.js
CHANGED
|
@@ -7,25 +7,35 @@
|
|
|
7
7
|
|
|
8
8
|
// @ts-check
|
|
9
9
|
|
|
10
|
-
/** @
|
|
10
|
+
/** @import {CanonicalFn} from './types.js' */
|
|
11
|
+
/** @import {ReadNowPowers} from './types.js' */
|
|
12
|
+
/** @import {ReadNowPowersProp} from './types.js' */
|
|
13
|
+
/** @import {ReadFn} from './types.js' */
|
|
14
|
+
/** @import {ReadPowers} from './types.js' */
|
|
15
|
+
/** @import {MaybeReadPowers} from './types.js' */
|
|
16
|
+
/** @import {MaybeReadFn} from './types.js' */
|
|
17
|
+
|
|
18
|
+
const { freeze } = Object;
|
|
19
|
+
|
|
20
|
+
/** @type {CanonicalFn} */
|
|
11
21
|
const canonicalShim = async path => path;
|
|
12
22
|
|
|
13
23
|
/**
|
|
14
|
-
* @param {
|
|
15
|
-
* @returns {
|
|
24
|
+
* @param {ReadFn | ReadPowers | MaybeReadPowers} powers
|
|
25
|
+
* @returns {MaybeReadPowers}
|
|
16
26
|
*/
|
|
17
27
|
export const unpackReadPowers = powers => {
|
|
18
|
-
/** @type {
|
|
28
|
+
/** @type {ReadFn | undefined} */
|
|
19
29
|
let read;
|
|
20
|
-
/** @type {
|
|
30
|
+
/** @type {MaybeReadFn | undefined} */
|
|
21
31
|
let maybeRead;
|
|
22
|
-
/** @type {
|
|
32
|
+
/** @type {CanonicalFn | undefined} */
|
|
23
33
|
let canonical;
|
|
24
34
|
|
|
25
35
|
if (typeof powers === 'function') {
|
|
26
36
|
read = powers;
|
|
27
37
|
} else {
|
|
28
|
-
({ read, maybeRead, canonical } = powers);
|
|
38
|
+
({ read, maybeRead, canonical } = /** @type {MaybeReadPowers} */ (powers));
|
|
29
39
|
}
|
|
30
40
|
|
|
31
41
|
if (canonical === undefined) {
|
|
@@ -35,9 +45,7 @@ export const unpackReadPowers = powers => {
|
|
|
35
45
|
if (maybeRead === undefined) {
|
|
36
46
|
/** @param {string} path */
|
|
37
47
|
maybeRead = path =>
|
|
38
|
-
/** @type {
|
|
39
|
-
_error => undefined,
|
|
40
|
-
);
|
|
48
|
+
/** @type {ReadFn} */ (read)(path).catch(_error => undefined);
|
|
41
49
|
}
|
|
42
50
|
|
|
43
51
|
return {
|
|
@@ -47,3 +55,45 @@ export const unpackReadPowers = powers => {
|
|
|
47
55
|
canonical,
|
|
48
56
|
};
|
|
49
57
|
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Ordered array of every property in {@link ReadNowPowers} which is _required_.
|
|
61
|
+
*
|
|
62
|
+
* @satisfies {Readonly<{[K in ReadNowPowersProp]-?: {} extends Pick<ReadNowPowers, K> ? never : K}[ReadNowPowersProp][]>}
|
|
63
|
+
*/
|
|
64
|
+
const requiredReadNowPowersProps = freeze(
|
|
65
|
+
/** @type {const} */ (['fileURLToPath', 'isAbsolute', 'maybeReadNow']),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Returns `true` if `value` is a {@link ReadNowPowers}
|
|
70
|
+
*
|
|
71
|
+
* @param {ReadPowers|ReadFn|undefined} value
|
|
72
|
+
* @returns {value is ReadNowPowers}
|
|
73
|
+
*/
|
|
74
|
+
export const isReadNowPowers = value =>
|
|
75
|
+
Boolean(
|
|
76
|
+
value &&
|
|
77
|
+
typeof value === 'object' &&
|
|
78
|
+
requiredReadNowPowersProps.every(
|
|
79
|
+
prop => prop in value && typeof value[prop] === 'function',
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns a list of the properties missing from (or invalid within) `value` that are required for
|
|
85
|
+
* `value` to be a {@link ReadNowPowers}.
|
|
86
|
+
*
|
|
87
|
+
* Used for human-friendly error messages
|
|
88
|
+
*
|
|
89
|
+
* @param {ReadPowers | ReadFn} [value] The value to check for missing properties.
|
|
90
|
+
* @returns {ReadNowPowersProp[]}
|
|
91
|
+
*/
|
|
92
|
+
export const findInvalidReadNowPowersProps = value => {
|
|
93
|
+
if (!value || typeof value === 'function') {
|
|
94
|
+
return [...requiredReadNowPowersProps];
|
|
95
|
+
}
|
|
96
|
+
return requiredReadNowPowersProps.filter(
|
|
97
|
+
prop => !(prop in value) || typeof value[prop] !== 'function',
|
|
98
|
+
);
|
|
99
|
+
};
|
package/src/search.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["search.js"],"names":[],"mappings":"AAqCO,iCALM,CAAC,YACH,MAAM,uBACN,CAAC,QAAQ,EAAC,MAAM,KAAG,OAAO,CAAC,CAAC,GAAC,SAAS,CAAC,GACrC,OAAO,CAAC;IAAC,IAAI,EAAC,CAAC,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAC,MAAM,CAAC;IAAC,yBAAyB,EAAE,MAAM,CAAA;CAAC,CAAC,CA0BpG;AAoCM,mCATI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,MAAM,GACJ,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["search.js"],"names":[],"mappings":"AAqCO,iCALM,CAAC,YACH,MAAM,uBACN,CAAC,QAAQ,EAAC,MAAM,KAAG,OAAO,CAAC,CAAC,GAAC,SAAS,CAAC,GACrC,OAAO,CAAC;IAAC,IAAI,EAAC,CAAC,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAC,MAAM,CAAC;IAAC,yBAAyB,EAAE,MAAM,CAAA;CAAC,CAAC,CA0BpG;AAoCM,mCATI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,MAAM,GACJ,OAAO,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,yBAAyB,EAAE,MAAM,CAAC;IAClC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC,CAoBJ;4BA7GyB,YAAY;gCACR,YAAY;qCACP,YAAY"}
|
package/src/search.js
CHANGED
|
@@ -96,10 +96,9 @@ const maybeReadDescriptorDefault = async (
|
|
|
96
96
|
* }>}
|
|
97
97
|
*/
|
|
98
98
|
export const search = async (readPowers, moduleLocation) => {
|
|
99
|
-
const { maybeRead } = unpackReadPowers(readPowers);
|
|
100
99
|
const { data, directory, location, packageDescriptorLocation } =
|
|
101
100
|
await searchDescriptor(moduleLocation, loc =>
|
|
102
|
-
maybeReadDescriptorDefault(
|
|
101
|
+
maybeReadDescriptorDefault(readPowers, loc),
|
|
103
102
|
);
|
|
104
103
|
|
|
105
104
|
if (!data) {
|