importmap_mocha-rails 0.3.4 → 0.3.6

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.
@@ -1,9 +1,543 @@
1
1
  // src/glossary.ts
2
2
  var IS_PATCHED_MODULE = Symbol("isPatchedModule");
3
3
 
4
+ // node_modules/.pnpm/is-node-process@1.2.0/node_modules/is-node-process/lib/index.mjs
5
+ function isNodeProcess() {
6
+ if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
7
+ return true;
8
+ }
9
+ if (typeof process !== "undefined") {
10
+ const type = process.type;
11
+ if (type === "renderer" || type === "worker") {
12
+ return false;
13
+ }
14
+ return !!(process.versions && process.versions.node);
15
+ }
16
+ return false;
17
+ }
18
+
19
+ // node_modules/.pnpm/outvariant@1.4.3/node_modules/outvariant/lib/index.mjs
20
+ var POSITIONALS_EXP = /(%?)(%([sdijo]))/g;
21
+ function serializePositional(positional, flag) {
22
+ switch (flag) {
23
+ case "s":
24
+ return positional;
25
+ case "d":
26
+ case "i":
27
+ return Number(positional);
28
+ case "j":
29
+ return JSON.stringify(positional);
30
+ case "o": {
31
+ if (typeof positional === "string") {
32
+ return positional;
33
+ }
34
+ const json = JSON.stringify(positional);
35
+ if (json === "{}" || json === "[]" || /^\[object .+?\]$/.test(json)) {
36
+ return positional;
37
+ }
38
+ return json;
39
+ }
40
+ }
41
+ }
42
+ function format(message, ...positionals) {
43
+ if (positionals.length === 0) {
44
+ return message;
45
+ }
46
+ let positionalIndex = 0;
47
+ let formattedMessage = message.replace(
48
+ POSITIONALS_EXP,
49
+ (match, isEscaped, _, flag) => {
50
+ const positional = positionals[positionalIndex];
51
+ const value = serializePositional(positional, flag);
52
+ if (!isEscaped) {
53
+ positionalIndex++;
54
+ return value;
55
+ }
56
+ return match;
57
+ }
58
+ );
59
+ if (positionalIndex < positionals.length) {
60
+ formattedMessage += ` ${positionals.slice(positionalIndex).join(" ")}`;
61
+ }
62
+ formattedMessage = formattedMessage.replace(/%{2,2}/g, "%");
63
+ return formattedMessage;
64
+ }
65
+ var STACK_FRAMES_TO_IGNORE = 2;
66
+ function cleanErrorStack(error2) {
67
+ if (!error2.stack) {
68
+ return;
69
+ }
70
+ const nextStack = error2.stack.split("\n");
71
+ nextStack.splice(1, STACK_FRAMES_TO_IGNORE);
72
+ error2.stack = nextStack.join("\n");
73
+ }
74
+ var InvariantError = class extends Error {
75
+ constructor(message, ...positionals) {
76
+ super(message);
77
+ this.message = message;
78
+ this.name = "Invariant Violation";
79
+ this.message = format(message, ...positionals);
80
+ cleanErrorStack(this);
81
+ }
82
+ };
83
+ var invariant = (predicate, message, ...positionals) => {
84
+ if (!predicate) {
85
+ throw new InvariantError(message, ...positionals);
86
+ }
87
+ };
88
+ invariant.as = (ErrorConstructor, predicate, message, ...positionals) => {
89
+ if (!predicate) {
90
+ const formatMessage = positionals.length === 0 ? message : format(message, ...positionals);
91
+ let error2;
92
+ try {
93
+ error2 = Reflect.construct(ErrorConstructor, [
94
+ formatMessage
95
+ ]);
96
+ } catch (err) {
97
+ error2 = ErrorConstructor(formatMessage);
98
+ }
99
+ throw error2;
100
+ }
101
+ };
102
+
103
+ // node_modules/.pnpm/@open-draft+logger@0.3.0/node_modules/@open-draft/logger/lib/index.mjs
104
+ var __defProp = Object.defineProperty;
105
+ var __export = (target, all) => {
106
+ for (var name in all)
107
+ __defProp(target, name, { get: all[name], enumerable: true });
108
+ };
109
+ var colors_exports = {};
110
+ __export(colors_exports, {
111
+ blue: () => blue,
112
+ gray: () => gray,
113
+ green: () => green,
114
+ red: () => red,
115
+ yellow: () => yellow
116
+ });
117
+ function yellow(text) {
118
+ return `\x1B[33m${text}\x1B[0m`;
119
+ }
120
+ function blue(text) {
121
+ return `\x1B[34m${text}\x1B[0m`;
122
+ }
123
+ function gray(text) {
124
+ return `\x1B[90m${text}\x1B[0m`;
125
+ }
126
+ function red(text) {
127
+ return `\x1B[31m${text}\x1B[0m`;
128
+ }
129
+ function green(text) {
130
+ return `\x1B[32m${text}\x1B[0m`;
131
+ }
132
+ var IS_NODE = isNodeProcess();
133
+ var Logger = class {
134
+ constructor(name) {
135
+ this.name = name;
136
+ this.prefix = `[${this.name}]`;
137
+ const LOGGER_NAME = getVariable("DEBUG");
138
+ const LOGGER_LEVEL = getVariable("LOG_LEVEL");
139
+ const isLoggingEnabled = LOGGER_NAME === "1" || LOGGER_NAME === "true" || typeof LOGGER_NAME !== "undefined" && this.name.startsWith(LOGGER_NAME);
140
+ if (isLoggingEnabled) {
141
+ this.debug = isDefinedAndNotEquals(LOGGER_LEVEL, "debug") ? noop : this.debug;
142
+ this.info = isDefinedAndNotEquals(LOGGER_LEVEL, "info") ? noop : this.info;
143
+ this.success = isDefinedAndNotEquals(LOGGER_LEVEL, "success") ? noop : this.success;
144
+ this.warning = isDefinedAndNotEquals(LOGGER_LEVEL, "warning") ? noop : this.warning;
145
+ this.error = isDefinedAndNotEquals(LOGGER_LEVEL, "error") ? noop : this.error;
146
+ } else {
147
+ this.info = noop;
148
+ this.success = noop;
149
+ this.warning = noop;
150
+ this.error = noop;
151
+ this.only = noop;
152
+ }
153
+ }
154
+ prefix;
155
+ extend(domain) {
156
+ return new Logger(`${this.name}:${domain}`);
157
+ }
158
+ /**
159
+ * Print a debug message.
160
+ * @example
161
+ * logger.debug('no duplicates found, creating a document...')
162
+ */
163
+ debug(message, ...positionals) {
164
+ this.logEntry({
165
+ level: "debug",
166
+ message: gray(message),
167
+ positionals,
168
+ prefix: this.prefix,
169
+ colors: {
170
+ prefix: "gray"
171
+ }
172
+ });
173
+ }
174
+ /**
175
+ * Print an info message.
176
+ * @example
177
+ * logger.info('start parsing...')
178
+ */
179
+ info(message, ...positionals) {
180
+ this.logEntry({
181
+ level: "info",
182
+ message,
183
+ positionals,
184
+ prefix: this.prefix,
185
+ colors: {
186
+ prefix: "blue"
187
+ }
188
+ });
189
+ const performance2 = new PerformanceEntry();
190
+ return (message2, ...positionals2) => {
191
+ performance2.measure();
192
+ this.logEntry({
193
+ level: "info",
194
+ message: `${message2} ${gray(`${performance2.deltaTime}ms`)}`,
195
+ positionals: positionals2,
196
+ prefix: this.prefix,
197
+ colors: {
198
+ prefix: "blue"
199
+ }
200
+ });
201
+ };
202
+ }
203
+ /**
204
+ * Print a success message.
205
+ * @example
206
+ * logger.success('successfully created document')
207
+ */
208
+ success(message, ...positionals) {
209
+ this.logEntry({
210
+ level: "info",
211
+ message,
212
+ positionals,
213
+ prefix: `\u2714 ${this.prefix}`,
214
+ colors: {
215
+ timestamp: "green",
216
+ prefix: "green"
217
+ }
218
+ });
219
+ }
220
+ /**
221
+ * Print a warning.
222
+ * @example
223
+ * logger.warning('found legacy document format')
224
+ */
225
+ warning(message, ...positionals) {
226
+ this.logEntry({
227
+ level: "warning",
228
+ message,
229
+ positionals,
230
+ prefix: `\u26A0 ${this.prefix}`,
231
+ colors: {
232
+ timestamp: "yellow",
233
+ prefix: "yellow"
234
+ }
235
+ });
236
+ }
237
+ /**
238
+ * Print an error message.
239
+ * @example
240
+ * logger.error('something went wrong')
241
+ */
242
+ error(message, ...positionals) {
243
+ this.logEntry({
244
+ level: "error",
245
+ message,
246
+ positionals,
247
+ prefix: `\u2716 ${this.prefix}`,
248
+ colors: {
249
+ timestamp: "red",
250
+ prefix: "red"
251
+ }
252
+ });
253
+ }
254
+ /**
255
+ * Execute the given callback only when the logging is enabled.
256
+ * This is skipped in its entirety and has no runtime cost otherwise.
257
+ * This executes regardless of the log level.
258
+ * @example
259
+ * logger.only(() => {
260
+ * logger.info('additional info')
261
+ * })
262
+ */
263
+ only(callback) {
264
+ callback();
265
+ }
266
+ createEntry(level, message) {
267
+ return {
268
+ timestamp: /* @__PURE__ */ new Date(),
269
+ level,
270
+ message
271
+ };
272
+ }
273
+ logEntry(args) {
274
+ const {
275
+ level,
276
+ message,
277
+ prefix,
278
+ colors: customColors,
279
+ positionals = []
280
+ } = args;
281
+ const entry = this.createEntry(level, message);
282
+ const timestampColor = customColors?.timestamp || "gray";
283
+ const prefixColor = customColors?.prefix || "gray";
284
+ const colorize = {
285
+ timestamp: colors_exports[timestampColor],
286
+ prefix: colors_exports[prefixColor]
287
+ };
288
+ const write = this.getWriter(level);
289
+ write(
290
+ [colorize.timestamp(this.formatTimestamp(entry.timestamp))].concat(prefix != null ? colorize.prefix(prefix) : []).concat(serializeInput(message)).join(" "),
291
+ ...positionals.map(serializeInput)
292
+ );
293
+ }
294
+ formatTimestamp(timestamp) {
295
+ return `${timestamp.toLocaleTimeString(
296
+ "en-GB"
297
+ )}:${timestamp.getMilliseconds()}`;
298
+ }
299
+ getWriter(level) {
300
+ switch (level) {
301
+ case "debug":
302
+ case "success":
303
+ case "info": {
304
+ return log;
305
+ }
306
+ case "warning": {
307
+ return warn;
308
+ }
309
+ case "error": {
310
+ return error;
311
+ }
312
+ }
313
+ }
314
+ };
315
+ var PerformanceEntry = class {
316
+ startTime;
317
+ endTime;
318
+ deltaTime;
319
+ constructor() {
320
+ this.startTime = performance.now();
321
+ }
322
+ measure() {
323
+ this.endTime = performance.now();
324
+ const deltaTime = this.endTime - this.startTime;
325
+ this.deltaTime = deltaTime.toFixed(2);
326
+ }
327
+ };
328
+ var noop = () => void 0;
329
+ function log(message, ...positionals) {
330
+ if (IS_NODE) {
331
+ process.stdout.write(format(message, ...positionals) + "\n");
332
+ return;
333
+ }
334
+ console.log(message, ...positionals);
335
+ }
336
+ function warn(message, ...positionals) {
337
+ if (IS_NODE) {
338
+ process.stderr.write(format(message, ...positionals) + "\n");
339
+ return;
340
+ }
341
+ console.warn(message, ...positionals);
342
+ }
343
+ function error(message, ...positionals) {
344
+ if (IS_NODE) {
345
+ process.stderr.write(format(message, ...positionals) + "\n");
346
+ return;
347
+ }
348
+ console.error(message, ...positionals);
349
+ }
350
+ function getVariable(variableName) {
351
+ if (IS_NODE) {
352
+ return process.env[variableName];
353
+ }
354
+ return globalThis[variableName]?.toString();
355
+ }
356
+ function isDefinedAndNotEquals(value, expected) {
357
+ return value !== void 0 && value !== expected;
358
+ }
359
+ function serializeInput(message) {
360
+ if (typeof message === "undefined") {
361
+ return "undefined";
362
+ }
363
+ if (message === null) {
364
+ return "null";
365
+ }
366
+ if (typeof message === "string") {
367
+ return message;
368
+ }
369
+ if (typeof message === "object") {
370
+ return JSON.stringify(message);
371
+ }
372
+ return message.toString();
373
+ }
374
+
375
+ // node_modules/.pnpm/strict-event-emitter@0.5.1/node_modules/strict-event-emitter/lib/index.mjs
376
+ var MemoryLeakError = class extends Error {
377
+ constructor(emitter, type, count) {
378
+ super(
379
+ `Possible EventEmitter memory leak detected. ${count} ${type.toString()} listeners added. Use emitter.setMaxListeners() to increase limit`
380
+ );
381
+ this.emitter = emitter;
382
+ this.type = type;
383
+ this.count = count;
384
+ this.name = "MaxListenersExceededWarning";
385
+ }
386
+ };
387
+ var _Emitter = class {
388
+ static listenerCount(emitter, eventName) {
389
+ return emitter.listenerCount(eventName);
390
+ }
391
+ constructor() {
392
+ this.events = /* @__PURE__ */ new Map();
393
+ this.maxListeners = _Emitter.defaultMaxListeners;
394
+ this.hasWarnedAboutPotentialMemoryLeak = false;
395
+ }
396
+ _emitInternalEvent(internalEventName, eventName, listener) {
397
+ this.emit(
398
+ internalEventName,
399
+ ...[eventName, listener]
400
+ );
401
+ }
402
+ _getListeners(eventName) {
403
+ return Array.prototype.concat.apply([], this.events.get(eventName)) || [];
404
+ }
405
+ _removeListener(listeners, listener) {
406
+ const index = listeners.indexOf(listener);
407
+ if (index > -1) {
408
+ listeners.splice(index, 1);
409
+ }
410
+ return [];
411
+ }
412
+ _wrapOnceListener(eventName, listener) {
413
+ const onceListener = (...data) => {
414
+ this.removeListener(eventName, onceListener);
415
+ return listener.apply(this, data);
416
+ };
417
+ Object.defineProperty(onceListener, "name", { value: listener.name });
418
+ return onceListener;
419
+ }
420
+ setMaxListeners(maxListeners) {
421
+ this.maxListeners = maxListeners;
422
+ return this;
423
+ }
424
+ /**
425
+ * Returns the current max listener value for the `Emitter` which is
426
+ * either set by `emitter.setMaxListeners(n)` or defaults to
427
+ * `Emitter.defaultMaxListeners`.
428
+ */
429
+ getMaxListeners() {
430
+ return this.maxListeners;
431
+ }
432
+ /**
433
+ * Returns an array listing the events for which the emitter has registered listeners.
434
+ * The values in the array will be strings or Symbols.
435
+ */
436
+ eventNames() {
437
+ return Array.from(this.events.keys());
438
+ }
439
+ /**
440
+ * Synchronously calls each of the listeners registered for the event named `eventName`,
441
+ * in the order they were registered, passing the supplied arguments to each.
442
+ * Returns `true` if the event has listeners, `false` otherwise.
443
+ *
444
+ * @example
445
+ * const emitter = new Emitter<{ hello: [string] }>()
446
+ * emitter.emit('hello', 'John')
447
+ */
448
+ emit(eventName, ...data) {
449
+ const listeners = this._getListeners(eventName);
450
+ listeners.forEach((listener) => {
451
+ listener.apply(this, data);
452
+ });
453
+ return listeners.length > 0;
454
+ }
455
+ addListener(eventName, listener) {
456
+ this._emitInternalEvent("newListener", eventName, listener);
457
+ const nextListeners = this._getListeners(eventName).concat(listener);
458
+ this.events.set(eventName, nextListeners);
459
+ if (this.maxListeners > 0 && this.listenerCount(eventName) > this.maxListeners && !this.hasWarnedAboutPotentialMemoryLeak) {
460
+ this.hasWarnedAboutPotentialMemoryLeak = true;
461
+ const memoryLeakWarning = new MemoryLeakError(
462
+ this,
463
+ eventName,
464
+ this.listenerCount(eventName)
465
+ );
466
+ console.warn(memoryLeakWarning);
467
+ }
468
+ return this;
469
+ }
470
+ on(eventName, listener) {
471
+ return this.addListener(eventName, listener);
472
+ }
473
+ once(eventName, listener) {
474
+ return this.addListener(
475
+ eventName,
476
+ this._wrapOnceListener(eventName, listener)
477
+ );
478
+ }
479
+ prependListener(eventName, listener) {
480
+ const listeners = this._getListeners(eventName);
481
+ if (listeners.length > 0) {
482
+ const nextListeners = [listener].concat(listeners);
483
+ this.events.set(eventName, nextListeners);
484
+ } else {
485
+ this.events.set(eventName, listeners.concat(listener));
486
+ }
487
+ return this;
488
+ }
489
+ prependOnceListener(eventName, listener) {
490
+ return this.prependListener(
491
+ eventName,
492
+ this._wrapOnceListener(eventName, listener)
493
+ );
494
+ }
495
+ removeListener(eventName, listener) {
496
+ const listeners = this._getListeners(eventName);
497
+ if (listeners.length > 0) {
498
+ this._removeListener(listeners, listener);
499
+ this.events.set(eventName, listeners);
500
+ this._emitInternalEvent("removeListener", eventName, listener);
501
+ }
502
+ return this;
503
+ }
504
+ /**
505
+ * Alias for `emitter.removeListener()`.
506
+ *
507
+ * @example
508
+ * emitter.off('hello', listener)
509
+ */
510
+ off(eventName, listener) {
511
+ return this.removeListener(eventName, listener);
512
+ }
513
+ removeAllListeners(eventName) {
514
+ if (eventName) {
515
+ this.events.delete(eventName);
516
+ } else {
517
+ this.events.clear();
518
+ }
519
+ return this;
520
+ }
521
+ /**
522
+ * Returns a copy of the array of listeners for the event named `eventName`.
523
+ */
524
+ listeners(eventName) {
525
+ return Array.from(this._getListeners(eventName));
526
+ }
527
+ /**
528
+ * Returns the number of listeners listening to the event named `eventName`.
529
+ */
530
+ listenerCount(eventName) {
531
+ return this._getListeners(eventName).length;
532
+ }
533
+ rawListeners(eventName) {
534
+ return this.listeners(eventName);
535
+ }
536
+ };
537
+ var Emitter = _Emitter;
538
+ Emitter.defaultMaxListeners = 10;
539
+
4
540
  // src/Interceptor.ts
5
- import { Logger } from "@open-draft/logger";
6
- import { Emitter } from "strict-event-emitter";
7
541
  var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
8
542
  function getGlobalSymbol(symbol) {
9
543
  return (
@@ -141,9 +675,8 @@ var Interceptor = class {
141
675
  this.readyState = "DISPOSED" /* DISPOSED */;
142
676
  }
143
677
  getInstance() {
144
- var _a;
145
678
  const instance = getGlobalSymbol(this.symbol);
146
- this.logger.info("retrieved global instance:", (_a = instance == null ? void 0 : instance.constructor) == null ? void 0 : _a.name);
679
+ this.logger.info("retrieved global instance:", instance?.constructor?.name);
147
680
  return instance;
148
681
  }
149
682
  setInstance() {
@@ -157,10 +690,10 @@ var Interceptor = class {
157
690
  };
158
691
 
159
692
  // src/BatchInterceptor.ts
160
- var BatchInterceptor = class extends Interceptor {
693
+ var BatchInterceptor = class _BatchInterceptor extends Interceptor {
161
694
  constructor(options) {
162
- BatchInterceptor.symbol = Symbol(options.name);
163
- super(BatchInterceptor.symbol);
695
+ _BatchInterceptor.symbol = Symbol(options.name);
696
+ super(_BatchInterceptor.symbol);
164
697
  this.interceptors = options.interceptors;
165
698
  }
166
699
  setup() {
@@ -219,19 +752,85 @@ function decodeBuffer(buffer, encoding) {
219
752
  return decoder.decode(buffer);
220
753
  }
221
754
 
222
- // src/utils/responseUtils.ts
223
- var RESPONSE_STATUS_CODES_WITHOUT_BODY = /* @__PURE__ */ new Set([
224
- 101,
225
- 103,
226
- 204,
227
- 205,
228
- 304
229
- ]);
230
- function isResponseWithoutBody(status) {
231
- return RESPONSE_STATUS_CODES_WITHOUT_BODY.has(status);
232
- }
755
+ // src/utils/fetchUtils.ts
756
+ var FetchResponse = class _FetchResponse extends Response {
757
+ static {
758
+ /**
759
+ * Response status codes for responses that cannot have body.
760
+ * @see https://fetch.spec.whatwg.org/#statuses
761
+ */
762
+ this.STATUS_CODES_WITHOUT_BODY = [101, 103, 204, 205, 304];
763
+ }
764
+ static {
765
+ this.STATUS_CODES_WITH_REDIRECT = [301, 302, 303, 307, 308];
766
+ }
767
+ static isConfigurableStatusCode(status) {
768
+ return status >= 200 && status <= 599;
769
+ }
770
+ static isRedirectResponse(status) {
771
+ return _FetchResponse.STATUS_CODES_WITH_REDIRECT.includes(status);
772
+ }
773
+ /**
774
+ * Returns a boolean indicating whether the given response status
775
+ * code represents a response that can have a body.
776
+ */
777
+ static isResponseWithBody(status) {
778
+ return !_FetchResponse.STATUS_CODES_WITHOUT_BODY.includes(status);
779
+ }
780
+ static setUrl(url, response) {
781
+ if (!url) {
782
+ return;
783
+ }
784
+ if (response.url != "") {
785
+ return;
786
+ }
787
+ Object.defineProperty(response, "url", {
788
+ value: url,
789
+ enumerable: true,
790
+ configurable: true,
791
+ writable: false
792
+ });
793
+ }
794
+ /**
795
+ * Parses the given raw HTTP headers into a Fetch API `Headers` instance.
796
+ */
797
+ static parseRawHeaders(rawHeaders) {
798
+ const headers = new Headers();
799
+ for (let line = 0; line < rawHeaders.length; line += 2) {
800
+ headers.append(rawHeaders[line], rawHeaders[line + 1]);
801
+ }
802
+ return headers;
803
+ }
804
+ constructor(body, init = {}) {
805
+ const status = init.status ?? 200;
806
+ const safeStatus = _FetchResponse.isConfigurableStatusCode(status) ? status : 200;
807
+ const finalBody = _FetchResponse.isResponseWithBody(status) ? body : null;
808
+ super(finalBody, {
809
+ ...init,
810
+ status: safeStatus
811
+ });
812
+ if (status !== safeStatus) {
813
+ const stateSymbol = Object.getOwnPropertySymbols(this).find(
814
+ (symbol) => symbol.description === "state"
815
+ );
816
+ if (stateSymbol) {
817
+ const state = Reflect.get(this, stateSymbol);
818
+ Reflect.set(state, "status", status);
819
+ } else {
820
+ Object.defineProperty(this, "status", {
821
+ value: status,
822
+ enumerable: true,
823
+ configurable: true,
824
+ writable: false
825
+ });
826
+ }
827
+ }
828
+ _FetchResponse.setUrl(init.url, this);
829
+ }
830
+ };
233
831
  export {
234
832
  BatchInterceptor,
833
+ FetchResponse,
235
834
  INTERNAL_REQUEST_ID_HEADER_NAME,
236
835
  IS_PATCHED_MODULE,
237
836
  Interceptor,
@@ -241,6 +840,5 @@ export {
241
840
  deleteGlobalSymbol,
242
841
  encodeBuffer,
243
842
  getCleanUrl,
244
- getGlobalSymbol,
245
- isResponseWithoutBody
843
+ getGlobalSymbol
246
844
  };