ses 1.5.0 → 1.7.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/types.d.ts CHANGED
@@ -25,7 +25,7 @@ export interface RepairOptions {
25
25
  consoleTaming?: 'safe' | 'unsafe';
26
26
  errorTrapping?: 'platform' | 'exit' | 'abort' | 'report' | 'none';
27
27
  unhandledRejectionTrapping?: 'report' | 'none';
28
- errorTaming?: 'safe' | 'unsafe';
28
+ errorTaming?: 'safe' | 'unsafe' | 'unsafe-debug';
29
29
  dateTaming?: 'safe' | 'unsafe'; // deprecated
30
30
  mathTaming?: 'safe' | 'unsafe'; // deprecated
31
31
  evalTaming?: 'safeEval' | 'unsafeEval' | 'noEval';
@@ -43,19 +43,23 @@ export type RepairIntrinsics = (options?: LockdownOptions) => void;
43
43
  export type HardenIntrinsics = () => void;
44
44
  export type Lockdown = (options?: LockdownOptions) => void;
45
45
 
46
+ export type ModuleExportsNamespace = Record<string, any>;
47
+
46
48
  export type __LiveExportMap__ = Record<string, [string, boolean]>;
47
49
  export type __FixedExportMap__ = Record<string, [string]>;
50
+ export type __ReexportMap__ = Record<string, Array<[string, string]>>;
48
51
 
49
- export interface PrecompiledStaticModuleInterface {
52
+ export interface PrecompiledModuleSource {
50
53
  imports: Array<string>;
51
54
  exports: Array<string>;
52
55
  reexports: Array<string>;
53
56
  __syncModuleProgram__: string;
54
57
  __liveExportMap__: __LiveExportMap__;
55
58
  __fixedExportMap__: __FixedExportMap__;
59
+ __reexportMap__: __ReexportMap__;
56
60
  }
57
61
 
58
- export interface ThirdPartyStaticModuleInterface {
62
+ export interface VirtualModuleSource {
59
63
  imports: Array<string>;
60
64
  exports: Array<string>;
61
65
  /**
@@ -68,34 +72,61 @@ export interface ThirdPartyStaticModuleInterface {
68
72
  ): void;
69
73
  }
70
74
 
71
- export type FinalStaticModuleType =
72
- | PrecompiledStaticModuleInterface
73
- | ThirdPartyStaticModuleInterface;
75
+ export type ModuleSource = PrecompiledModuleSource | VirtualModuleSource;
74
76
 
75
- export interface RedirectStaticModuleInterface {
76
- specifier: string;
77
- record?: FinalStaticModuleType;
77
+ export interface SourceModuleDescriptor {
78
+ source: string | ModuleSource;
79
+ specifier?: string;
78
80
  importMeta?: any;
81
+ compartment?: Compartment; // defaults to parent
82
+ }
83
+
84
+ export interface NamespaceModuleDescriptor {
85
+ namespace: string | ModuleExportsNamespace;
79
86
  compartment?: Compartment;
80
87
  }
81
88
 
82
- export type StaticModuleType =
83
- | RedirectStaticModuleInterface
84
- | FinalStaticModuleType;
89
+ // Deprecated in favor of SourceModuleDescriptor,
90
+ // but beware the change in default compartment.
91
+ export interface RecordModuleDescriptor {
92
+ specifier: string;
93
+ record?: ModuleSource;
94
+ importMeta?: any;
95
+ compartment?: Compartment; // defaults to self
96
+ }
85
97
 
86
- export type ModuleExportsNamespace = Record<string, any>;
98
+ export type ModuleDescriptor =
99
+ | SourceModuleDescriptor
100
+ | NamespaceModuleDescriptor
101
+ // To be deprecated:
102
+ | RecordModuleDescriptor
103
+ | ModuleExportsNamespace
104
+ | VirtualModuleSource
105
+ | PrecompiledModuleSource
106
+ | string;
107
+
108
+ // Deprecated type aliases:
109
+ export type PrecompiledStaticModuleInterface = PrecompiledModuleSource;
110
+ export type ThirdPartyStaticModuleInterface = VirtualModuleSource;
111
+ export type RedirectStaticModuleInterface = RecordModuleDescriptor;
112
+ export type FinalStaticModuleType = ModuleSource;
113
+ export type StaticModuleType = RedirectStaticModuleInterface | ModuleSource;
87
114
 
88
115
  export type Transform = (source: string) => string;
89
116
  export type ResolveHook = (
90
117
  importSpecifier: string,
91
118
  referrerSpecifier: string,
92
119
  ) => string;
93
- export type ModuleMap = Record<string, string | ModuleExportsNamespace>;
120
+ export type ModuleMap = Record<string, string | ModuleDescriptor>;
94
121
  export type ModuleMapHook = (
95
122
  moduleSpecifier: string,
96
- ) => string | ModuleExportsNamespace | void;
97
- export type ImportHook = (moduleSpecifier: string) => Promise<StaticModuleType>;
98
- export type ImportNowHook = (moduleSpecifier: string) => StaticModuleType;
123
+ ) => ModuleDescriptor | undefined;
124
+ export type ImportHook = (moduleSpecifier: string) => Promise<ModuleDescriptor>;
125
+ export type ImportNowHook = (moduleSpecifier: string) => ModuleDescriptor;
126
+ export type ImportMetaHook = (
127
+ moduleSpecifier: string,
128
+ importMeta: Object,
129
+ ) => void;
99
130
 
100
131
  export interface CompartmentOptions {
101
132
  name?: string;
@@ -103,8 +134,12 @@ export interface CompartmentOptions {
103
134
  moduleMapHook?: ModuleMapHook;
104
135
  importHook?: ImportHook;
105
136
  importNowHook?: ImportNowHook;
137
+ importMetaHook?: ImportMetaHook;
106
138
  resolveHook?: ResolveHook;
139
+ globals?: Map<string, any>;
140
+ modules?: Map<string, ModuleDescriptor>;
107
141
  __shimTransforms__?: Array<Transform>;
142
+ __noNamespaceBox__?: boolean;
108
143
  }
109
144
 
110
145
  export interface EvaluateOptions {
@@ -271,17 +306,17 @@ export interface AssertionFunctions extends BaseAssert {
271
306
  *
272
307
  * Assert that two values must be `Object.is`.
273
308
  */
274
- equal(
309
+ equal<T>(
275
310
  /** What we received */
276
- actual: any,
311
+ actual: unknown,
277
312
  /** What we wanted */
278
- expected: any,
313
+ expected: T,
279
314
  /** The details of what was asserted */
280
315
  details?: Details,
281
316
  /** An optional alternate error constructor to use */
282
317
  errConstructor?: GenericErrorConstructor,
283
318
  options?: AssertMakeErrorOptions,
284
- ): void;
319
+ ): asserts actual is T;
285
320
 
286
321
  /**
287
322
  * The `assert.string` method.
@@ -346,12 +381,10 @@ export interface AssertionUtilities {
346
381
  * ```js
347
382
  * assert(sky.isBlue(), details`${sky.color} should be "blue"`);
348
383
  * ```
349
- * // TODO Update SES-shim to new convention, where `details` is
350
- * // renamed to `X` rather than `d`.
351
- * or following the normal convention to locally rename `details` to `d`
352
- * and `quote` to `q` like `const { details: d, quote: q } = assert;`:
384
+ * or following the normal convention to locally rename `details` to `X`
385
+ * and `quote` to `q` like `const { details: X, quote: q } = assert;`:
353
386
  * ```js
354
- * assert(sky.isBlue(), d`${sky.color} should be "blue"`);
387
+ * assert(sky.isBlue(), X`${sky.color} should be "blue"`);
355
388
  * ```
356
389
  * However, note that in most cases it is preferable to instead use the `Fail`
357
390
  * template literal tag (which has the same input signature as `details`
@@ -427,10 +460,8 @@ export interface AssertionUtilities {
427
460
  * sky.color === expectedColor || Fail`${sky.color} should be ${quote(expectedColor)}`;
428
461
  * ```
429
462
  *
430
- * // TODO Update SES-shim to new convention, where `details` is
431
- * // renamed to `X` rather than `d`.
432
- * The normal convention is to locally rename `details` to `d` and `quote` to `q`
433
- * like `const { details: d, quote: q } = assert;`, so the above example would then be
463
+ * The normal convention is to locally rename `details` to `X` and `quote` to `q`
464
+ * like `const { details: X, quote: q } = assert;`, so the above example would then be
434
465
  * ```js
435
466
  * sky.color === expectedColor || Fail`${sky.color} should be ${q(expectedColor)}`;
436
467
  * ```
@@ -510,9 +541,12 @@ declare global {
510
541
  * code in a context bound to a new global creates a new compartment.
511
542
  */
512
543
  export class Compartment {
544
+ constructor(options?: CompartmentOptions & { __options__: true });
545
+
546
+ // Deprecated:
513
547
  constructor(
514
- globals?: Object,
515
- moduleMap?: ModuleMap,
548
+ globals?: Record<string, any> | undefined,
549
+ modules?: Record<string, ModuleDescriptor>,
516
550
  options?: CompartmentOptions,
517
551
  );
518
552