importmap_mocha-rails 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,238 @@
1
+ // src/glossary.ts
2
+ var IS_PATCHED_MODULE = Symbol("isPatchedModule");
3
+
4
+ // src/Interceptor.ts
5
+ import { Logger } from "@open-draft/logger";
6
+ import { Emitter } from "strict-event-emitter";
7
+ function getGlobalSymbol(symbol) {
8
+ return (
9
+ // @ts-ignore https://github.com/Microsoft/TypeScript/issues/24587
10
+ globalThis[symbol] || void 0
11
+ );
12
+ }
13
+ function setGlobalSymbol(symbol, value) {
14
+ globalThis[symbol] = value;
15
+ }
16
+ function deleteGlobalSymbol(symbol) {
17
+ delete globalThis[symbol];
18
+ }
19
+ var InterceptorReadyState = /* @__PURE__ */ ((InterceptorReadyState2) => {
20
+ InterceptorReadyState2["INACTIVE"] = "INACTIVE";
21
+ InterceptorReadyState2["APPLYING"] = "APPLYING";
22
+ InterceptorReadyState2["APPLIED"] = "APPLIED";
23
+ InterceptorReadyState2["DISPOSING"] = "DISPOSING";
24
+ InterceptorReadyState2["DISPOSED"] = "DISPOSED";
25
+ return InterceptorReadyState2;
26
+ })(InterceptorReadyState || {});
27
+ var Interceptor = class {
28
+ constructor(symbol) {
29
+ this.symbol = symbol;
30
+ this.readyState = "INACTIVE" /* INACTIVE */;
31
+ this.emitter = new Emitter();
32
+ this.subscriptions = [];
33
+ this.logger = new Logger(symbol.description);
34
+ this.emitter.setMaxListeners(0);
35
+ this.logger.info("constructing the interceptor...");
36
+ }
37
+ /**
38
+ * Determine if this interceptor can be applied
39
+ * in the current environment.
40
+ */
41
+ checkEnvironment() {
42
+ return true;
43
+ }
44
+ /**
45
+ * Apply this interceptor to the current process.
46
+ * Returns an already running interceptor instance if it's present.
47
+ */
48
+ apply() {
49
+ const logger = this.logger.extend("apply");
50
+ logger.info("applying the interceptor...");
51
+ if (this.readyState === "APPLIED" /* APPLIED */) {
52
+ logger.info("intercepted already applied!");
53
+ return;
54
+ }
55
+ const shouldApply = this.checkEnvironment();
56
+ if (!shouldApply) {
57
+ logger.info("the interceptor cannot be applied in this environment!");
58
+ return;
59
+ }
60
+ this.readyState = "APPLYING" /* APPLYING */;
61
+ const runningInstance = this.getInstance();
62
+ if (runningInstance) {
63
+ logger.info("found a running instance, reusing...");
64
+ this.on = (event, listener) => {
65
+ logger.info('proxying the "%s" listener', event);
66
+ runningInstance.emitter.addListener(event, listener);
67
+ this.subscriptions.push(() => {
68
+ runningInstance.emitter.removeListener(event, listener);
69
+ logger.info('removed proxied "%s" listener!', event);
70
+ });
71
+ return this;
72
+ };
73
+ this.readyState = "APPLIED" /* APPLIED */;
74
+ return;
75
+ }
76
+ logger.info("no running instance found, setting up a new instance...");
77
+ this.setup();
78
+ this.setInstance();
79
+ this.readyState = "APPLIED" /* APPLIED */;
80
+ }
81
+ /**
82
+ * Setup the module augments and stubs necessary for this interceptor.
83
+ * This method is not run if there's a running interceptor instance
84
+ * to prevent instantiating an interceptor multiple times.
85
+ */
86
+ setup() {
87
+ }
88
+ /**
89
+ * Listen to the interceptor's public events.
90
+ */
91
+ on(event, listener) {
92
+ const logger = this.logger.extend("on");
93
+ if (this.readyState === "DISPOSING" /* DISPOSING */ || this.readyState === "DISPOSED" /* DISPOSED */) {
94
+ logger.info("cannot listen to events, already disposed!");
95
+ return this;
96
+ }
97
+ logger.info('adding "%s" event listener:', event, listener);
98
+ this.emitter.on(event, listener);
99
+ return this;
100
+ }
101
+ once(event, listener) {
102
+ this.emitter.once(event, listener);
103
+ return this;
104
+ }
105
+ off(event, listener) {
106
+ this.emitter.off(event, listener);
107
+ return this;
108
+ }
109
+ removeAllListeners(event) {
110
+ this.emitter.removeAllListeners(event);
111
+ return this;
112
+ }
113
+ /**
114
+ * Disposes of any side-effects this interceptor has introduced.
115
+ */
116
+ dispose() {
117
+ const logger = this.logger.extend("dispose");
118
+ if (this.readyState === "DISPOSED" /* DISPOSED */) {
119
+ logger.info("cannot dispose, already disposed!");
120
+ return;
121
+ }
122
+ logger.info("disposing the interceptor...");
123
+ this.readyState = "DISPOSING" /* DISPOSING */;
124
+ if (!this.getInstance()) {
125
+ logger.info("no interceptors running, skipping dispose...");
126
+ return;
127
+ }
128
+ this.clearInstance();
129
+ logger.info("global symbol deleted:", getGlobalSymbol(this.symbol));
130
+ if (this.subscriptions.length > 0) {
131
+ logger.info("disposing of %d subscriptions...", this.subscriptions.length);
132
+ for (const dispose of this.subscriptions) {
133
+ dispose();
134
+ }
135
+ this.subscriptions = [];
136
+ logger.info("disposed of all subscriptions!", this.subscriptions.length);
137
+ }
138
+ this.emitter.removeAllListeners();
139
+ logger.info("destroyed the listener!");
140
+ this.readyState = "DISPOSED" /* DISPOSED */;
141
+ }
142
+ getInstance() {
143
+ var _a;
144
+ const instance = getGlobalSymbol(this.symbol);
145
+ this.logger.info("retrieved global instance:", (_a = instance == null ? void 0 : instance.constructor) == null ? void 0 : _a.name);
146
+ return instance;
147
+ }
148
+ setInstance() {
149
+ setGlobalSymbol(this.symbol, this);
150
+ this.logger.info("set global instance!", this.symbol.description);
151
+ }
152
+ clearInstance() {
153
+ deleteGlobalSymbol(this.symbol);
154
+ this.logger.info("cleared global instance!", this.symbol.description);
155
+ }
156
+ };
157
+
158
+ // src/BatchInterceptor.ts
159
+ var BatchInterceptor = class extends Interceptor {
160
+ constructor(options) {
161
+ BatchInterceptor.symbol = Symbol(options.name);
162
+ super(BatchInterceptor.symbol);
163
+ this.interceptors = options.interceptors;
164
+ }
165
+ setup() {
166
+ const logger = this.logger.extend("setup");
167
+ logger.info("applying all %d interceptors...", this.interceptors.length);
168
+ for (const interceptor of this.interceptors) {
169
+ logger.info('applying "%s" interceptor...', interceptor.constructor.name);
170
+ interceptor.apply();
171
+ logger.info("adding interceptor dispose subscription");
172
+ this.subscriptions.push(() => interceptor.dispose());
173
+ }
174
+ }
175
+ on(event, listener) {
176
+ for (const interceptor of this.interceptors) {
177
+ interceptor.on(event, listener);
178
+ }
179
+ return this;
180
+ }
181
+ once(event, listener) {
182
+ for (const interceptor of this.interceptors) {
183
+ interceptor.once(event, listener);
184
+ }
185
+ return this;
186
+ }
187
+ off(event, listener) {
188
+ for (const interceptor of this.interceptors) {
189
+ interceptor.off(event, listener);
190
+ }
191
+ return this;
192
+ }
193
+ removeAllListeners(event) {
194
+ for (const interceptors of this.interceptors) {
195
+ interceptors.removeAllListeners(event);
196
+ }
197
+ return this;
198
+ }
199
+ };
200
+
201
+ // src/utils/getCleanUrl.ts
202
+ function getCleanUrl(url, isAbsolute = true) {
203
+ return [isAbsolute && url.origin, url.pathname].filter(Boolean).join("");
204
+ }
205
+
206
+ // src/utils/bufferUtils.ts
207
+ var encoder = new TextEncoder();
208
+ function encodeBuffer(text) {
209
+ return encoder.encode(text);
210
+ }
211
+ function decodeBuffer(buffer, encoding) {
212
+ const decoder = new TextDecoder(encoding);
213
+ return decoder.decode(buffer);
214
+ }
215
+
216
+ // src/utils/responseUtils.ts
217
+ var RESPONSE_STATUS_CODES_WITHOUT_BODY = /* @__PURE__ */ new Set([
218
+ 101,
219
+ 103,
220
+ 204,
221
+ 205,
222
+ 304
223
+ ]);
224
+ function isResponseWithoutBody(status) {
225
+ return RESPONSE_STATUS_CODES_WITHOUT_BODY.has(status);
226
+ }
227
+ export {
228
+ BatchInterceptor,
229
+ IS_PATCHED_MODULE,
230
+ Interceptor,
231
+ InterceptorReadyState,
232
+ decodeBuffer,
233
+ deleteGlobalSymbol,
234
+ encodeBuffer,
235
+ getCleanUrl,
236
+ getGlobalSymbol,
237
+ isResponseWithoutBody
238
+ };
@@ -0,0 +1,2 @@
1
+ function createDeferredExecutor(){const executor=(e,t)=>{executor.state="pending";executor.resolve=t=>{if("pending"!==executor.state)return;executor.result=t;const onFulfilled=e=>{executor.state="fulfilled";return e};return e(t instanceof Promise?t:Promise.resolve(t).then(onFulfilled))};executor.reject=e=>{if("pending"===executor.state){queueMicrotask((()=>{executor.state="rejected"}));return t(executor.rejectionReason=e)}}};return executor}var e=class extends Promise{#e;resolve;reject;constructor(e=null){const t=createDeferredExecutor();super(((r,s)=>{t(r,s);e?.(t.resolve,t.reject)}));this.#e=t;this.resolve=this.#e.resolve;this.reject=this.#e.reject}get state(){return this.#e.state}get rejectionReason(){return this.#e.rejectionReason}then(e,t){return this.#t(super.then(e,t))}catch(e){return this.#t(super.catch(e))}finally(e){return this.#t(super.finally(e))}#t(e){return Object.defineProperties(e,{resolve:{configurable:true,value:this.resolve},reject:{configurable:true,value:this.reject}})}};export{e as DeferredPromise,createDeferredExecutor};
2
+
@@ -0,0 +1,2 @@
1
+ import{isNodeProcess as e}from"is-node-process";import{format as r}from"outvariant";var t=Object.defineProperty;var __export=(e,r)=>{for(var i in r)t(e,i,{get:r[i],enumerable:true})};var i={};__export(i,{blue:()=>blue,gray:()=>gray,green:()=>green,red:()=>red,yellow:()=>yellow});function yellow(e){return`${e}`}function blue(e){return`${e}`}function gray(e){return`${e}`}function red(e){return`${e}`}function green(e){return`${e}`}var s=e();var n=class{constructor(e){this.name=e;this.prefix=`[${this.name}]`;const r=getVariable("DEBUG");const t=getVariable("LOG_LEVEL");const i="1"===r||"true"===r||"undefined"!==typeof r&&this.name.startsWith(r);if(i){this.debug=isDefinedAndNotEquals(t,"debug")?noop:this.debug;this.info=isDefinedAndNotEquals(t,"info")?noop:this.info;this.success=isDefinedAndNotEquals(t,"success")?noop:this.success;this.warning=isDefinedAndNotEquals(t,"warning")?noop:this.warning;this.error=isDefinedAndNotEquals(t,"error")?noop:this.error}else{this.info=noop;this.success=noop;this.warning=noop;this.error=noop;this.only=noop}}prefix;extend(e){return new n(`${this.name}:${e}`)}debug(e,...r){this.logEntry({level:"debug",message:gray(e),positionals:r,prefix:this.prefix,colors:{prefix:"gray"}})}info(e,...r){this.logEntry({level:"info",message:e,positionals:r,prefix:this.prefix,colors:{prefix:"blue"}});const t=new o;return(e,...r)=>{t.measure();this.logEntry({level:"info",message:`${e} ${gray(`${t.deltaTime}ms`)}`,positionals:r,prefix:this.prefix,colors:{prefix:"blue"}})}}success(e,...r){this.logEntry({level:"info",message:e,positionals:r,prefix:`✔ ${this.prefix}`,colors:{timestamp:"green",prefix:"green"}})}warning(e,...r){this.logEntry({level:"warning",message:e,positionals:r,prefix:`⚠ ${this.prefix}`,colors:{timestamp:"yellow",prefix:"yellow"}})}error(e,...r){this.logEntry({level:"error",message:e,positionals:r,prefix:`✖ ${this.prefix}`,colors:{timestamp:"red",prefix:"red"}})}only(e){e()}createEntry(e,r){return{timestamp:new Date,level:e,message:r}}logEntry(e){const{level:r,message:t,prefix:s,colors:n,positionals:o=[]}=e;const a=this.createEntry(r,t);const l=n?.timestamp||"gray";const c=n?.prefix||"gray";const f={timestamp:i[l],prefix:i[c]};const u=this.getWriter(r);u([f.timestamp(this.formatTimestamp(a.timestamp))].concat(null!=s?f.prefix(s):[]).concat(serializeInput(t)).join(" "),...o.map(serializeInput))}formatTimestamp(e){return`${e.toLocaleTimeString("en-GB")}:${e.getMilliseconds()}`}getWriter(e){switch(e){case"debug":case"success":case"info":return log;case"warning":return warn;case"error":return error}}};var o=class{startTime;endTime;deltaTime;constructor(){this.startTime=performance.now()}measure(){this.endTime=performance.now();const e=this.endTime-this.startTime;this.deltaTime=e.toFixed(2)}};var noop=()=>{};function log(e,...t){s?process.stdout.write(r(e,...t)+"\n"):console.log(e,...t)}function warn(e,...t){s?process.stderr.write(r(e,...t)+"\n"):console.warn(e,...t)}function error(e,...t){s?process.stderr.write(r(e,...t)+"\n"):console.error(e,...t)}function getVariable(e){return s?process.env[e]:globalThis[e]?.toString()}function isDefinedAndNotEquals(e,r){return void 0!==e&&e!==r}function serializeInput(e){return"undefined"===typeof e?"undefined":null===e?"null":"string"===typeof e?e:"object"===typeof e?JSON.stringify(e):e.toString()}export{n as Logger};
2
+
@@ -0,0 +1,2 @@
1
+ var until=async r=>{try{const t=await r().catch((r=>{throw r}));return{error:null,data:t}}catch(r){return{error:r,data:null}}};export{until};
2
+