@nejs/basic-extensions 2.3.0 → 2.4.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.
@@ -90,6 +90,26 @@ export class Deferred extends Promise<any> {
90
90
  * {@link Deferred.reject} have been invoked; `false` otherwise
91
91
  */
92
92
  get settled(): boolean;
93
+ /**
94
+ * A getter that returns a boolean indicating whether the Deferred instance
95
+ * was rejected. This property can be used to check if the Deferred has been
96
+ * settled with a rejection. It is particularly useful in scenarios where
97
+ * the resolution status of the Deferred needs to be checked without
98
+ * accessing the rejection reason or invoking any additional logic.
99
+ *
100
+ * @returns {boolean} `true` if the Deferred was rejected, otherwise `false`.
101
+ */
102
+ get wasRejected(): boolean;
103
+ /**
104
+ * A getter that returns a boolean indicating whether the Deferred instance
105
+ * was resolved. This property is useful for checking if the Deferred has been
106
+ * settled with a resolution, allowing for checks on the Deferred's status
107
+ * without needing to access the resolved value or trigger any additional
108
+ * logic.
109
+ *
110
+ * @returns {boolean} `true` if the Deferred was resolved, otherwise `false`.
111
+ */
112
+ get wasResolved(): boolean;
93
113
  /**
94
114
  * Accessor for the promise managed by this Deferred instance.
95
115
  *
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _Deferred_promise, _Deferred_reject, _Deferred_resolve, _Deferred_settled;
13
+ var _Deferred_promise, _Deferred_reject, _Deferred_resolve, _Deferred_rejected, _Deferred_resolved, _Deferred_settled;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.DeferredExtension = exports.Deferred = void 0;
16
16
  const extension_1 = require("@nejs/extension");
@@ -130,7 +130,9 @@ class Deferred extends Promise {
130
130
  *
131
131
  * @type {function}
132
132
  */
133
- _Deferred_resolve.set(this, null
133
+ _Deferred_resolve.set(this, null);
134
+ _Deferred_rejected.set(this, false);
135
+ _Deferred_resolved.set(this, false
134
136
  /**
135
137
  * When the Deferred is settled with {@link Deferred.resolve}, the `value`
136
138
  * passed to that function will be set here as well.
@@ -205,6 +207,8 @@ class Deferred extends Promise {
205
207
  }
206
208
  // Mark the Deferred instance as settled
207
209
  __classPrivateFieldSet(this, _Deferred_settled, true, "f");
210
+ // Mark the Deferred instance as resolved
211
+ __classPrivateFieldSet(this, _Deferred_resolved, true, "f");
208
212
  // Resolve the promise with the provided value
209
213
  return _resolve(value);
210
214
  }, "f");
@@ -216,6 +220,8 @@ class Deferred extends Promise {
216
220
  }
217
221
  // Mark the Deferred instance as settled
218
222
  __classPrivateFieldSet(this, _Deferred_settled, true, "f");
223
+ // Mark the Deferred as being rejected.
224
+ __classPrivateFieldSet(this, _Deferred_rejected, true, "f");
219
225
  // Reject the promise with the provided reason
220
226
  return _reject(reason);
221
227
  }, "f");
@@ -239,6 +245,30 @@ class Deferred extends Promise {
239
245
  get settled() {
240
246
  return __classPrivateFieldGet(this, _Deferred_settled, "f");
241
247
  }
248
+ /**
249
+ * A getter that returns a boolean indicating whether the Deferred instance
250
+ * was rejected. This property can be used to check if the Deferred has been
251
+ * settled with a rejection. It is particularly useful in scenarios where
252
+ * the resolution status of the Deferred needs to be checked without
253
+ * accessing the rejection reason or invoking any additional logic.
254
+ *
255
+ * @returns {boolean} `true` if the Deferred was rejected, otherwise `false`.
256
+ */
257
+ get wasRejected() {
258
+ return __classPrivateFieldGet(this, _Deferred_rejected, "f");
259
+ }
260
+ /**
261
+ * A getter that returns a boolean indicating whether the Deferred instance
262
+ * was resolved. This property is useful for checking if the Deferred has been
263
+ * settled with a resolution, allowing for checks on the Deferred's status
264
+ * without needing to access the resolved value or trigger any additional
265
+ * logic.
266
+ *
267
+ * @returns {boolean} `true` if the Deferred was resolved, otherwise `false`.
268
+ */
269
+ get wasResolved() {
270
+ return __classPrivateFieldGet(this, _Deferred_resolved, "f");
271
+ }
242
272
  /**
243
273
  * Accessor for the promise managed by this Deferred instance.
244
274
  *
@@ -275,6 +305,33 @@ class Deferred extends Promise {
275
305
  reject(reason) {
276
306
  return __classPrivateFieldGet(this, _Deferred_reject, "f").call(this, reason);
277
307
  }
308
+ /**
309
+ * Customizes the output of `util.inspect` on instances of Deferred when
310
+ * used in Node.js. This method is invoked by Node.js's `util.inspect`
311
+ * utility to format the inspection output of a Deferred instance.
312
+ *
313
+ * The output includes the state of the Deferred (resolved, rejected, or
314
+ * unsettled) along with the resolved value or rejection reason, if
315
+ * applicable. This provides a quick, readable status of the Deferred
316
+ * instance directly in the console or debugging tools.
317
+ *
318
+ * @param {number} depth The depth to which `util.inspect` will recurse.
319
+ * @param {object} options Formatting options provided by `util.inspect`.
320
+ * @param {function} inspect Reference to the `util.inspect` function.
321
+ * @returns {string} A formatted string representing the Deferred instance.
322
+ */
323
+ [(_Deferred_promise = new WeakMap(), _Deferred_reject = new WeakMap(), _Deferred_resolve = new WeakMap(), _Deferred_rejected = new WeakMap(), _Deferred_resolved = new WeakMap(), _Deferred_settled = new WeakMap(), Symbol.for('nodejs.util.inspect.custom'))](depth, options, inspect) {
324
+ return [
325
+ '\x1b[1mDeferred [\x1b[22;3mPromise\x1b[23;1m]\x1b[22m ',
326
+ '{ ',
327
+ (this.settled
328
+ ? (this.wasResolved
329
+ ? `resolved with \x1b[32m${this.value}\x1b[39m`
330
+ : `rejected with \x1b[31m${this.reason?.message ?? this.reason}\x1b[39m`)
331
+ : '\x1b[33munsettled valued or reason\x1b[39m'),
332
+ ' }'
333
+ ].join('');
334
+ }
278
335
  /**
279
336
  * A getter for the species symbol which returns a custom DeferredPromise
280
337
  * class. This class extends from Deferred and is used to ensure that the
@@ -285,7 +342,7 @@ class Deferred extends Promise {
285
342
  *
286
343
  * @returns {DeferredPromise} A DeferredPromise class that extends Deferred.
287
344
  */
288
- static get [(_Deferred_promise = new WeakMap(), _Deferred_reject = new WeakMap(), _Deferred_resolve = new WeakMap(), _Deferred_settled = new WeakMap(), Symbol.species)]() {
345
+ static get [Symbol.species]() {
289
346
  return class DeferredPromise extends Deferred {
290
347
  /**
291
348
  * The constructor for the DeferredPromise class.
@@ -1 +1 @@
1
- {"version":3,"file":"deferred.js","sourceRoot":"","sources":["../../../src/newClasses/deferred.js"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAA2C;AAE3C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,QAAS,SAAQ,OAAO;IAqDnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,YAAY,OAAO;QACjB,0EAA0E;QAC1E,MAAM,MAAM,GAAG,CAAC,OAAO,IAAI,OAAM,CAAC,OAAO,CAAC,KAAK,QAAQ;YACrD,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,EAAE,CACL,CAAA;QAED,iEAAiE;QACjE,IAAI,MAAM,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,EAAE,CAAC;YACtC,MAAM,IAAI,SAAS,CACjB,8DAA8D,CAC/D,CAAA;QACH,CAAC;QAED,mEAAmE;QACnE,IAAI,QAAQ,EAAE,OAAO,CAAC;QAEtB,gFAAgF;QAChF,KAAK,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACxB,QAAQ,GAAG,OAAO,CAAA;YAClB,OAAO,GAAG,MAAM,CAAA;YAEhB,IAAI,MAAM,EAAE,QAAQ,IAAI,OAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,UAAU,EAAE,CAAC;gBAChE,MAAM,EAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;YACnC,CAAC;QACH,CAAC,CAAC,CAAA;QAjHJ;;;;;;WAMG;QACH,4BAAW,IAAI;QAEf;;;;;;WAMG;UARY;QAEf;;;;;;WAMG;QACH,2BAAU,IAAI;QAEd;;;;;;WAMG;UARW;QAEd;;;;;;WAMG;QACH,4BAAW,IAAI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AAM,CAAC,MAAM;QACX,OAAO,uBAAA,IAAI,wBAAQ,MAAZ,IAAI,EAAS,MAAM,CAAC,CAAA;IAC7B,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,qNAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,EAAC,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO;QAChE,OAAO;YACL,wDAAwD;YACxD,IAAI;YACJ,CAAC,IAAI,CAAC,OAAO;gBACX,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW;oBACjB,CAAC,CAAC,yBAAyB,IAAI,CAAC,KAAK,UAAU;oBAC/C,CAAC,CAAC,yBAAyB,IAAI,CAAC,MAAM,EAAE,OAAO,IAAI,IAAI,CAAC,MAAM,UAAU,CAAC;gBAC3E,CAAC,CAAC,4CAA4C,CAC/C;YACD,IAAI;SACL,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACZ,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC;QACzB,OAAO,MAAM,eAAgB,SAAQ,QAAQ;YAC3C;;;;;;;eAOG;YACH,YAAY,QAAQ;gBAClB,KAAK,CAAC,EAAC,QAAQ,EAAC,CAAC,CAAA;YACnB,CAAC;SACF,CAAA;IACH,CAAC;CACF;AAtSD,4BAsSC;AAEY,QAAA,iBAAiB,GAAG,IAAI,qBAAS,CAAC,QAAQ,CAAC,CAAA"}
@@ -90,6 +90,26 @@ export class Deferred extends Promise<any> {
90
90
  * {@link Deferred.reject} have been invoked; `false` otherwise
91
91
  */
92
92
  get settled(): boolean;
93
+ /**
94
+ * A getter that returns a boolean indicating whether the Deferred instance
95
+ * was rejected. This property can be used to check if the Deferred has been
96
+ * settled with a rejection. It is particularly useful in scenarios where
97
+ * the resolution status of the Deferred needs to be checked without
98
+ * accessing the rejection reason or invoking any additional logic.
99
+ *
100
+ * @returns {boolean} `true` if the Deferred was rejected, otherwise `false`.
101
+ */
102
+ get wasRejected(): boolean;
103
+ /**
104
+ * A getter that returns a boolean indicating whether the Deferred instance
105
+ * was resolved. This property is useful for checking if the Deferred has been
106
+ * settled with a resolution, allowing for checks on the Deferred's status
107
+ * without needing to access the resolved value or trigger any additional
108
+ * logic.
109
+ *
110
+ * @returns {boolean} `true` if the Deferred was resolved, otherwise `false`.
111
+ */
112
+ get wasResolved(): boolean;
93
113
  /**
94
114
  * Accessor for the promise managed by this Deferred instance.
95
115
  *
@@ -45,6 +45,8 @@ export class Deferred extends Promise {
45
45
  * @type {function}
46
46
  */
47
47
  #resolve = null;
48
+ #rejected = false;
49
+ #resolved = false;
48
50
  /**
49
51
  * When the Deferred is settled with {@link Deferred.resolve}, the `value`
50
52
  * passed to that function will be set here as well.
@@ -130,6 +132,8 @@ export class Deferred extends Promise {
130
132
  }
131
133
  // Mark the Deferred instance as settled
132
134
  this.#settled = true;
135
+ // Mark the Deferred instance as resolved
136
+ this.#resolved = true;
133
137
  // Resolve the promise with the provided value
134
138
  return _resolve(value);
135
139
  };
@@ -141,6 +145,8 @@ export class Deferred extends Promise {
141
145
  }
142
146
  // Mark the Deferred instance as settled
143
147
  this.#settled = true;
148
+ // Mark the Deferred as being rejected.
149
+ this.#rejected = true;
144
150
  // Reject the promise with the provided reason
145
151
  return _reject(reason);
146
152
  };
@@ -164,6 +170,30 @@ export class Deferred extends Promise {
164
170
  get settled() {
165
171
  return this.#settled;
166
172
  }
173
+ /**
174
+ * A getter that returns a boolean indicating whether the Deferred instance
175
+ * was rejected. This property can be used to check if the Deferred has been
176
+ * settled with a rejection. It is particularly useful in scenarios where
177
+ * the resolution status of the Deferred needs to be checked without
178
+ * accessing the rejection reason or invoking any additional logic.
179
+ *
180
+ * @returns {boolean} `true` if the Deferred was rejected, otherwise `false`.
181
+ */
182
+ get wasRejected() {
183
+ return this.#rejected;
184
+ }
185
+ /**
186
+ * A getter that returns a boolean indicating whether the Deferred instance
187
+ * was resolved. This property is useful for checking if the Deferred has been
188
+ * settled with a resolution, allowing for checks on the Deferred's status
189
+ * without needing to access the resolved value or trigger any additional
190
+ * logic.
191
+ *
192
+ * @returns {boolean} `true` if the Deferred was resolved, otherwise `false`.
193
+ */
194
+ get wasResolved() {
195
+ return this.#resolved;
196
+ }
167
197
  /**
168
198
  * Accessor for the promise managed by this Deferred instance.
169
199
  *
@@ -200,6 +230,33 @@ export class Deferred extends Promise {
200
230
  reject(reason) {
201
231
  return this.#reject(reason);
202
232
  }
233
+ /**
234
+ * Customizes the output of `util.inspect` on instances of Deferred when
235
+ * used in Node.js. This method is invoked by Node.js's `util.inspect`
236
+ * utility to format the inspection output of a Deferred instance.
237
+ *
238
+ * The output includes the state of the Deferred (resolved, rejected, or
239
+ * unsettled) along with the resolved value or rejection reason, if
240
+ * applicable. This provides a quick, readable status of the Deferred
241
+ * instance directly in the console or debugging tools.
242
+ *
243
+ * @param {number} depth The depth to which `util.inspect` will recurse.
244
+ * @param {object} options Formatting options provided by `util.inspect`.
245
+ * @param {function} inspect Reference to the `util.inspect` function.
246
+ * @returns {string} A formatted string representing the Deferred instance.
247
+ */
248
+ [Symbol.for('nodejs.util.inspect.custom')](depth, options, inspect) {
249
+ return [
250
+ '\x1b[1mDeferred [\x1b[22;3mPromise\x1b[23;1m]\x1b[22m ',
251
+ '{ ',
252
+ (this.settled
253
+ ? (this.wasResolved
254
+ ? `resolved with \x1b[32m${this.value}\x1b[39m`
255
+ : `rejected with \x1b[31m${this.reason?.message ?? this.reason}\x1b[39m`)
256
+ : '\x1b[33munsettled valued or reason\x1b[39m'),
257
+ ' }'
258
+ ].join('');
259
+ }
203
260
  /**
204
261
  * A getter for the species symbol which returns a custom DeferredPromise
205
262
  * class. This class extends from Deferred and is used to ensure that the
@@ -1 +1 @@
1
- {"version":3,"file":"deferred.js","sourceRoot":"","sources":["../../../src/newClasses/deferred.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,M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