@nejs/basic-extensions 1.8.0 → 1.9.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/package.json CHANGED
@@ -49,7 +49,7 @@
49
49
  "name": "@nejs/basic-extensions",
50
50
  "scripts": {
51
51
  "preinstall": "npx only-allow pnpm",
52
- "build": "bin/clean && bin/esbuild && bin/build",
52
+ "build": "bin/clean && bin/esbuild && bin/build && npm run documentation",
53
53
  "browser": "bin/esbuild",
54
54
  "clean": "bin/clean",
55
55
  "jsdoc": "jsdoc -c jsdoc-config.json -p -a all -R README.md",
@@ -58,9 +58,9 @@
58
58
  "test": "jest"
59
59
  },
60
60
  "type": "module",
61
- "version": "1.8.0",
61
+ "version": "1.9.0",
62
62
  "dependencies": {
63
63
  "@nejs/extension": "^2.1.0"
64
64
  },
65
- "browser": "dist/@nejs/basic-extensions.bundle.1.7.0.js"
65
+ "browser": "dist/@nejs/basic-extensions.bundle.1.8.0.js"
66
66
  }
package/src/index.js CHANGED
@@ -10,6 +10,7 @@ import { DescriptorExtensions, Descriptor } from './newClasses/descriptor.js'
10
10
  import { GlobalFunctionsAndProps } from './globals.js'
11
11
  import { RefSetExtensions } from './newClasses/refset.js'
12
12
  import { RefMapExtensions } from './newClasses/refmap.js'
13
+ import { DeferredExtension } from './newClasses/deferred.js'
13
14
 
14
15
  import {
15
16
  AsyncIteratorExtensions,
@@ -21,29 +22,38 @@ import {
21
22
  IterableExtensions
22
23
  } from './newClasses/iterable.js'
23
24
 
24
- const Patches = new Map([
25
+ const StaticPatches = [
25
26
  [Object, ObjectExtensions],
26
27
  [Function, FunctionExtensions],
27
28
  [Reflect, ReflectExtensions],
28
29
  [String, StringExtensions],
29
30
  [Symbol, SymbolExtensions],
31
+ ]
30
32
 
33
+ const InstancePatches = [
31
34
  [Object.prototype, ObjectPrototypeExtensions],
32
35
  [Function.prototype, FunctionPrototypeExtensions],
33
36
  [Array.prototype, ArrayPrototypeExtensions],
34
37
  [Map.prototype, MapPrototypeExtensions],
35
38
  [Set.prototype, SetPrototypeExtensions],
36
- [globalThis, GlobalFunctionsAndProps],
39
+ ]
40
+
41
+ const Patches = new Map([
42
+ ...StaticPatches,
43
+ ...InstancePatches,
37
44
  ])
38
45
 
39
46
  const Extensions = {
40
- [DescriptorExtensions.key]: DescriptorExtensions,
47
+ global: GlobalFunctionsAndProps,
48
+
41
49
  [AsyncIterableExtensions.key]: AsyncIterableExtensions,
42
50
  [AsyncIteratorExtensions.key]: AsyncIteratorExtensions,
51
+ [DeferredExtension.key]: DeferredExtension,
52
+ [DescriptorExtensions.key]: DescriptorExtensions,
43
53
  [IterableExtensions.key]: IterableExtensions,
44
54
  [IteratorExtensions.key]: IteratorExtensions,
45
- [RefSetExtensions.key]: RefSetExtensions,
46
55
  [RefMapExtensions.key]: RefMapExtensions,
56
+ [RefSetExtensions.key]: RefSetExtensions,
47
57
  }
48
58
 
49
59
  const Controls = {}
@@ -58,11 +68,19 @@ Object.assign(Controls, {
58
68
  Patches.forEach((extension) => { extension.apply() })
59
69
  },
60
70
 
71
+ enableStaticPatches(filter = (extension) => true) {
72
+ StaticPatches.filter(filter).forEach(extension => extension.apply())
73
+ },
74
+
75
+ enableInstancePatches(filter = (extension) => true) {
76
+ InstancePatches.filter(filter).forEach(extension => extension.apply())
77
+ },
78
+
61
79
  enableExtensions() {
62
80
  Object.values(Extensions).forEach((extension) => { extension.apply() })
63
81
  },
64
82
 
65
- disableAll(owners) {
83
+ disableAll() {
66
84
  Controls.disablePatches()
67
85
  Controls.disableExtensions()
68
86
  },
@@ -71,6 +89,14 @@ Object.assign(Controls, {
71
89
  Patches.forEach((extension) => { extension.revert() })
72
90
  },
73
91
 
92
+ disableStaticPatches(filter = (extension) => true) {
93
+ StaticPatches.filter(filter).forEach(extension => extension.revert())
94
+ },
95
+
96
+ disableInstancePatches(filter = (extension) => true) {
97
+ InstancePatches.filter(filter).forEach(extension => extension.revert())
98
+ },
99
+
74
100
  disableExtensions() {
75
101
  Object.values(Extensions).forEach((extension) => { extension.revert() })
76
102
  },
@@ -0,0 +1,253 @@
1
+ import { Extension } from '@nejs/extension'
2
+
3
+ /**
4
+ * Deferreds, which were first introduced by jQuery for browsers in the early
5
+ * 2000s, are a way to manage asynchronous operations. They have been widely
6
+ * used and replicated by engineers since then. Although the Promise class in
7
+ * modern JavaScript provides a static method called `withResolvers` that
8
+ * returns an object with similar properties to a Deferred, it is not directly
9
+ * supported by Node.js.
10
+ *
11
+ * ```
12
+ * const withResolvers = Promise.withResolvers()
13
+ * Reflect.has(withResolvers, 'promise') // true
14
+ * Reflect.has(withResolvers, 'resolve') // true
15
+ * Reflect.has(withResolvers, 'reject') // true
16
+ * ```
17
+ *
18
+ * This Deferred class extends the Promise class, allowing it to capture the
19
+ * value or reason for easy access after resolution, akin to
20
+ * {@link Promise.withResolvers}. As it extends {@link Promise}, it is
21
+ * 'thenable' and works with `await` as if it were a native Promise. This
22
+ * allows seamless integration with code expecting Promise-like objects.
23
+ */
24
+ export class Deferred extends Promise {
25
+ /**
26
+ * The promise backing this deferred object. Created when the constructor
27
+ * runs, this promise is what all `Promise.prototype` functions are routed
28
+ * to.
29
+ *
30
+ * @type {Promise}
31
+ */
32
+ #promise = null
33
+
34
+ /**
35
+ * The reject() resolver that will be assigned when a new instance is
36
+ * created. Invoking this function with or without a `reason` will cause
37
+ * the deferred's promise to be settled.
38
+ *
39
+ * @type {function}
40
+ */
41
+ #reject = null
42
+
43
+ /**
44
+ * The resolve() resolver that will be assigned when a new instance is
45
+ * created. Invoking this function with or without a `value` will cause
46
+ * the deferred's promise to be settled.
47
+ *
48
+ * @type {function}
49
+ */
50
+ #resolve = null
51
+
52
+ /**
53
+ * When the Deferred is settled with {@link Deferred.resolve}, the `value`
54
+ * passed to that function will be set here as well.
55
+ *
56
+ * @type {*}
57
+ */
58
+ value = null
59
+
60
+ /**
61
+ * When the Deferred is settled with {@link Deferred.reject}, the `reason`
62
+ * passed to that rejection will also be stored here.
63
+ *
64
+ * @type {*}
65
+ */
66
+ reason = null
67
+
68
+ /**
69
+ * When either {@link Deferred.resolve} or {@link Deferred.reject} are called,
70
+ * this property is set to `true`. Its current status at any time can be
71
+ * queried using the {@link Deferred.settled} getter.
72
+ *
73
+ * @type {boolean}
74
+ */
75
+ #settled = false
76
+
77
+ /**
78
+ * The constructor for Deferred instances. By default, a new Deferred will
79
+ * have three important properties: `promise`, `resolve`, and `reject`.
80
+ *
81
+ * The constructor takes an object called `options`. It can have the
82
+ * following properties:
83
+ *
84
+ * ```
85
+ * interface BaseDeferredOptions {
86
+ * // Deferreds store the value or reason. To turn this off, pass true
87
+ * // to this option.
88
+ * doNotTrackAnswers?: boolean;
89
+ * }
90
+ *
91
+ * interface ResolveDeferredOptions {
92
+ * // Passing in an option object with a resolve value will auto resolve
93
+ * // the Deferred with your value. An error will be raised if both
94
+ * // resolve and reject are supplied at the same time.
95
+ * resolve?: (value: any) => void;
96
+ * }
97
+ *
98
+ * interface RejectDeferredOptions {
99
+ * // Passing in an option object with a reject reason will auto reject
100
+ * // the Deferred with your reason. An error will be raised if both
101
+ * // resolve and reject are supplied at the same time.
102
+ * reject?: (reason: any) => void;
103
+ * }
104
+ *
105
+ * type DeferredOptions = BaseDeferredOptions &
106
+ * (ResolveDeferredOptions | RejectDeferredOptions)
107
+ * ```
108
+ *
109
+ * @param {object} options see above for examples on supported options, but
110
+ * when supplied, the constructor can take instructions on how to auto
111
+ * resolve or reject the deferred created here.
112
+ */
113
+ constructor(options) {
114
+ // Check if options is an object, if not, assign an empty object to config
115
+ const config = (options && typeof(options) === 'object'
116
+ ? options
117
+ : {}
118
+ )
119
+
120
+ // Throw an error if both resolve and reject options are provided
121
+ if (config?.resolve && config?.reject) {
122
+ throw new TypeError(
123
+ 'resolve and reject options cannot be simultaneously provided'
124
+ )
125
+ }
126
+
127
+ // Create an empty object to store the resolve and reject functions
128
+ let _resolve, _reject;
129
+
130
+ // Create a new promise and assign its resolve and reject functions to resolvers
131
+ super((resolve, reject) =>{
132
+ _resolve = resolve
133
+ _reject = reject
134
+
135
+ if (config?.executor && typeof(config?.executor) === 'function') {
136
+ config?.executor(resolve, reject)
137
+ }
138
+ })
139
+
140
+ // Define the resolve function for the Deferred instance
141
+ this.#resolve = (value) => {
142
+ // If doNotTrackAnswers is not set to true, store the value
143
+ if (config?.doNotTrackAnswers !== true) {
144
+ this.value = value
145
+ }
146
+ // Mark the Deferred instance as settled
147
+ this.#settled = true
148
+ // Resolve the promise with the provided value
149
+ return _resolve(value)
150
+ }
151
+
152
+ // Define the reject function for the Deferred instance
153
+ this.#reject = async (reason) => {
154
+ // If doNotTrackAnswers is not set to true, store the reason
155
+ if (config?.doNotTrackAnswers !== true) {
156
+ this.reason = reason
157
+ }
158
+ // Mark the Deferred instance as settled
159
+ this.#settled = true
160
+ // Reject the promise with the provided reason
161
+ return _reject(reason)
162
+ }
163
+
164
+ this.#promise = this
165
+
166
+ // If a resolve option is provided, resolve the Deferred instance with it
167
+ if (config?.resolve) {
168
+ this.#resolve(config?.resolve)
169
+ }
170
+ // If a reject option is provided, reject the Deferred instance with it
171
+ else if (config?.reject) {
172
+ this.#reject(config?.reject)
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Returns a boolean value that indicates whether or not this Deferred
178
+ * has been settled (either resolve or reject have been invoked).
179
+ *
180
+ * @returns {boolean} `true` if either {@link Deferred.resolve} or
181
+ * {@link Deferred.reject} have been invoked; `false` otherwise
182
+ */
183
+ get settled() {
184
+ return this.#settled
185
+ }
186
+
187
+ /**
188
+ * Accessor for the promise managed by this Deferred instance.
189
+ *
190
+ * This getter provides access to the internal promise which is controlled
191
+ * by the Deferred's resolve and reject methods. It allows external code to
192
+ * attach callbacks for the resolution or rejection of the Deferred without
193
+ * the ability to directly resolve or reject it.
194
+ *
195
+ * @returns {Promise} The promise controlled by this Deferred instance.
196
+ */
197
+ get promise() {
198
+ return this.#promise
199
+ }
200
+
201
+ /**
202
+ * Resolves the Deferred with the given value. If the value is a thenable
203
+ * (i.e., has a "then" method), the Deferred will "follow" that thenable,
204
+ * adopting its eventual state; otherwise, the Deferred will be fulfilled
205
+ * with the value. This function behaves the same as Promise.resolve.
206
+ *
207
+ * @param {*} value - The value to resolve the Deferred with.
208
+ * @returns {Promise} A Promise that is resolved with the given value.
209
+ */
210
+ resolve(value) {
211
+ return this.#resolve(value)
212
+ }
213
+
214
+ /**
215
+ * Rejects the Deferred with the given reason. This function behaves the
216
+ * same as Promise.reject. The Deferred will be rejected with the provided
217
+ * reason.
218
+ *
219
+ * @param {*} reason - The reason to reject the Deferred with.
220
+ * @returns {Promise} A Promise that is rejected with the given reason.
221
+ */
222
+ reject(reason) {
223
+ return this.#reject(reason)
224
+ }
225
+
226
+ /**
227
+ * A getter for the species symbol which returns a custom DeferredPromise
228
+ * class. This class extends from Deferred and is used to ensure that the
229
+ * constructor signature matches that of a Promise. The executor function
230
+ * passed to the constructor of this class is used to initialize the Deferred
231
+ * object with resolve and reject functions, similar to how a Promise would
232
+ * be initialized.
233
+ *
234
+ * @returns {DeferredPromise} A DeferredPromise class that extends Deferred.
235
+ */
236
+ static get [Symbol.species]() {
237
+ return class DeferredPromise extends Deferred {
238
+ /**
239
+ * The constructor for the DeferredPromise class.
240
+ * It takes an executor function which is used to initialize the Deferred.
241
+ *
242
+ * @param {Function} executor - A function that is passed with the resolve
243
+ * and reject functions. The executor is expected to initialize the
244
+ * Deferred by calling resolve or reject at some point.
245
+ */
246
+ constructor(executor) {
247
+ super({executor})
248
+ }
249
+ }
250
+ }
251
+ }
252
+
253
+ export const DeferredExtension = new Extension(Deferred)
@@ -0,0 +1,86 @@
1
+ const { Extensions } = require('../../dist/cjs/index.js')
2
+ const Deferred = Extensions.Deferred.class
3
+
4
+ describe('Deferred', () => {
5
+ let deferred;
6
+
7
+ beforeEach(() => {
8
+ deferred = new Deferred();
9
+ });
10
+
11
+ test('should create a Deferred instance with a promise', () => {
12
+ expect(deferred).toBeInstanceOf(Deferred);
13
+ expect(deferred.promise).toBeInstanceOf(Promise);
14
+ });
15
+
16
+ test('should resolve with a value', async () => {
17
+ const value = 'resolved value';
18
+ deferred.resolve(value);
19
+ await expect(deferred.promise).resolves.toBe(value);
20
+ expect(deferred.value).toBe(value);
21
+ expect(deferred.settled).toBe(true);
22
+ });
23
+
24
+ test('should reject with a reason', async () => {
25
+ const reason = 'rejected reason';
26
+ deferred.reject(reason);
27
+ await expect(deferred.promise).rejects.toBe(reason);
28
+ expect(deferred.reason).toBe(reason);
29
+ expect(deferred.settled).toBe(true);
30
+ });
31
+
32
+ test('should call then with the resolved value', async () => {
33
+ const value = 'resolved value';
34
+ const onFulfilled = jest.fn();
35
+ deferred.resolve(value);
36
+ await deferred.then(onFulfilled);
37
+ expect(onFulfilled).toHaveBeenCalledWith(value);
38
+ });
39
+
40
+ test('should call catch with the rejection reason', async () => {
41
+ const reason = 'rejected reason';
42
+ const onRejected = jest.fn();
43
+ deferred.reject(reason);
44
+ await deferred.catch(onRejected);
45
+ expect(onRejected).toHaveBeenCalledWith(reason);
46
+ });
47
+
48
+ test('should call finally regardless of resolution or rejection', async () => {
49
+ const onFinally = jest.fn();
50
+ deferred.resolve('resolved value');
51
+ await deferred.finally(onFinally);
52
+ expect(onFinally).toHaveBeenCalled();
53
+
54
+ deferred = new Deferred(); // Reset for rejection test
55
+ deferred.reject('rejected reason')
56
+ expect(deferred.settled).toBe(true)
57
+ try { await deferred.finally(onFinally); } catch {}
58
+ expect(onFinally).toHaveBeenCalledTimes(2);
59
+ });
60
+
61
+ test('should not track value or reason if doNotTrackAnswers is true', () => {
62
+ const value = 'resolved value';
63
+ const reason = 'rejected reason';
64
+ const deferredNoTrack = new Deferred({ doNotTrackAnswers: true });
65
+
66
+ deferredNoTrack.resolve(value);
67
+ expect(deferredNoTrack.value).toBeNull();
68
+
69
+ deferredNoTrack.reject(reason);
70
+ expect(deferredNoTrack.reason).toBeNull();
71
+ });
72
+
73
+ test('should auto-resolve or auto-reject based on options', async () => {
74
+ const resolvedDeferred = new Deferred({ resolve: 'auto-resolved value' });
75
+ await expect(resolvedDeferred.promise).resolves.toBe('auto-resolved value');
76
+
77
+ const rejectedDeferred = new Deferred({ reject: 'auto-rejected reason' });
78
+ await expect(rejectedDeferred.promise).rejects.toBe('auto-rejected reason');
79
+ });
80
+
81
+ test('should throw an error if both resolve and reject options are provided', () => {
82
+ expect(() => {
83
+ new Deferred({ resolve: 'value', reject: 'reason' });
84
+ }).toThrow(TypeError);
85
+ });
86
+ });
@@ -1,4 +0,0 @@
1
- var nejsBasicExtensions=(()=>{var N=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var ot=Object.getOwnPropertyNames;var it=Object.prototype.hasOwnProperty;var ct=(r,t)=>{for(var e in t)N(r,e,{get:t[e],enumerable:!0})},at=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ot(t))!it.call(r,o)&&o!==e&&N(r,o,{get:()=>t[o],enumerable:!(s=nt(t,o))||s.enumerable});return r};var ft=r=>at(N({},"__esModule",{value:!0}),r);var xt={};ct(xt,{Controls:()=>y,Extensions:()=>O,Patches:()=>R,all:()=>st,default:()=>St});var ut=r=>/(\w+)]/.exec(Object.prototype.toString.call(r))[1],w=class extends Error{constructor(t,e){super(`${ut(t)} disallows tampering with ${e}.`),Object.assign(this,{owner:t,key:e})}get[Symbol.toStringTag](){return this.constructor.name}};var lt=r=>/(\w+)]/.exec(Object.prototype.toString.call(r))[1],S=class extends Error{constructor(t,e){super(`${lt(t)} does not have a property named '${e}'.`),Object.assign(this,{owner:t,key:e})}get[Symbol.toStringTag](){return this.constructor.name}};var x=class{constructor(t,e=!1){this.started=!1,this.preventRevert=e,this.patch=t,this.patchName=t.owner?.name??t.owner?.constructor?.name??/(\w+)]/.exec(Object.prototype.toString.call(t.owner))[1],this.state={needsApplication:!1,needsReversion:!1}}start(){return this.started||(this.state.needsApplication=!this.patch.applied,this.state.needsReversion=this.patch.applied,this.started=!0,this.state.needsApplication&&this.patch.apply()),this}stop(){return this.started&&((this.preventRevert||this.patch.applied)&&this.patch.revert(),this.state.needsApplication=!1,this.state.needsReversion=!1,this.started=!1),this}get[Symbol.toStringTag](){return`${this.constructor.name}:${this.patchName}`}[Symbol.for("nodejs.util.inspect.custom")](t,e,s){let o=this[Symbol.toStringTag],n=`(started: ${this.started} needed: ${this.state.needsApplication})`;return s(`${o} ${n}`,{...e,depth:t})}};var m=class{constructor(t,e=globalThis,s=void 0){let o=c=>c==null,n=(c,u=["string","symbol"])=>!o(c)&&!!u.find(f=>f===typeof c),i=c=>n(c,["object"]);if(!n(t))throw console.error("Property",t,`(type: ${typeof t})`,"owningObject",e,`(type: ${typeof e})`,"condition",s,`(type: ${typeof s})`),new TypeError("Property must be non-null and either a string or symbol");if(!i(e))throw new TypeError("Cannot create Patch entry as owning object is invalid");Object.assign(this,{key:t,descriptor:Object.getOwnPropertyDescriptor(e,t),owner:e,condition:typeof s=="function"?s:void 0})}get computed(){return this.isAccessor?this.descriptor.get.bind(this.owner).call():this.descriptor.value}get isData(){return Reflect.has(this.descriptor,"value")}get isAccessor(){return Reflect.has(this.descriptor,"get")}get isReadOnly(){return Reflect.has(this.descriptor,"configurable")&&!this.descriptor.configurable||Reflect.has(this.descriptor,"writable")&&!this.descriptor.writable}get isAllowed(){return this.condition&&typeof this.condition=="function"?this.condition():!0}get[Symbol.toStringTag](){return this.constructor.name}[Symbol.for("nodejs.util.inspect.custom")](t,e,s){let o=this.isData?" Data":" Accessor",n=this.isReadOnly?" [ReadOnly]":"";return`PatchEntry<${this.key}${o}${n}>`}};var a=class r{constructor(t,e,s={}){Object.assign(this,{owner:t,options:s}),this.patchConflicts={},this.patchEntries={},this.patchesOwner=e,this.patchCount=0,this.patchesApplied=0;let o=this?.options.condition;Reflect.ownKeys(e).forEach(n=>{let i=this?.options?.conditions?.[n]??o;try{this.patchEntries[n]=new m(n,this.patchesOwner,i),this.patchCount+=1}catch(c){console.error(`Failed to process patch for ${n}
2
- `,c)}if(Reflect.has(this.owner,n))try{this.patchConflicts[n]=new m(n,this.owner)}catch(c){console.error(`Cannot capture conflicting patch key ${n}
3
- `,c)}}),r.patches.has(t)||r.patches.set(t,[]),r.patches.get(t).push(this)}get entries(){return Reflect.ownKeys(this.patchEntries).map(t=>[t,this.patchEntries[t]])}get patches(){return this.entries.reduce((t,[e,s])=>(t[e]=s.computed,t),{})}get conflicts(){return Reflect.ownKeys(this.patchConflicts).map(t=>[t,this.patchConflicts[t]])}get applied(){return this.patchesApplied>0}get isPartiallyPatched(){return this.applied}get isFullyPatched(){return this.patchCount==this.patchesApplied}apply(t){let e=this.entries,s={patches:e.length,applied:0,errors:[],notApplied:e.length};e.forEach(([,o])=>{if(o.isAllowed){Object.defineProperty(this.owner,o.key,o.descriptor);let n=Object.getOwnPropertyDescriptor(this.owner,o.key);this.#t(n,o.descriptor)?(s.applied+=1,s.notApplied-=1):s.errors.push([o,new Error(`Could not apply patch for key ${o.key}`)])}}),this.patchesApplied=s.applied,typeof t=="function"&&t(s)}createToggle(t=!1){return new x(this,t)}revert(t){if(!this.applied)return;let e=this.entries,s=this.conflicts,o={patches:e.length,reverted:0,restored:0,conflicts:s.length,errors:[],stillApplied:0};e.forEach(([,n])=>{delete this.owner[n.key]?(this.patchesApplied-=1,o.reverted+=1):o.errors.push([n,new Error(`Failed to revert patch ${n.key}`)])}),s.forEach(([,n])=>{Object.defineProperty(this.owner,n.key,n.descriptor);let i=Object.getOwnPropertyDescriptor(this.owner,n.key);this.#t(n.descriptor,i)?o.restored+=1:o.errors.push([n,new Error(`Failed to restore original ${n.key}`)])}),o.stillApplied=this.patchesApplied,typeof t=="function"&&t(o)}release(){let t=r.patches.get(this.owner);t.splice(t.find(e=>e===this),1)}owner=null;options=null;#t(t,e){if(!t||!e)return!1;let s=!0;return s=s&&t.configurable===e.configurable,s=s&&t.enumerable===e.enumerable,s=s&&t.value===e.value,s=s&&t.writable===e.writable,s=s&&t.get===e.get,s=s&&t.set===e.set,s}static patches=new Map;static enableFor(t){if(r.patches.has(t))for(let e of r.patches.get(t))e.apply()}static disableFor(t){if(r.patches.has(t))for(let e of r.patches.get(t))e.revert()}};var pt=["number","boolean","bigint","string","symbol"],l=class r extends a{constructor(t,e,s=globalThis,o={}){let n=r.determineInput(t),{key:i,extension:c,valid:u}=n;if(c=e||c,!u)throw new S(s,i);let f=Object.getOwnPropertyDescriptor(s,i);if(f&&(Reflect.has(f,"writable")&&!f.writable||Reflect.has(f,"configurable")&&!f.configurable))throw new w(s,i);super(s,{[i]:c},o),this.key=i,this.class=n.class,this.function=n.function}get isFunction(){return!!this.function}get isClass(){return!!this.class}get isPrimitive(){return~pt.indexOf(typeof this.value)}get isObject(){return Object(this.value)===this.value}static determineInput(t){let e={key:null,extension:null,valid:!1};return t instanceof Function?(e={key:t.name,extension:t,valid:!0},/^class .*/.exec(t.toString())&&(e.class=t),/^(async )?function .*/.exec(t.toString())&&(e.function=t)):(typeof t=="string"||t instanceof String)&&(e={key:t,extension:null,valid:!0}),e}[Symbol.for("nodejs.util.inspect.custom")](t,e,s){return`Extension<${this.key}>`}get[Symbol.toStringTag](){return this.constructor.name}};var p=new a(Object,{isNullDefined(r){return r==null},hasStringTag(r){return Object.isObject(r)&&Reflect.has(r,Symbol.toStringTag)},getStringTag(r,t=!1){if(Object.hasStringTag(r))return r[Symbol.toStringTag];if(!t)return r&&typeof r=="function"?r.name:/\s(.+)]/.exec(Object.prototype.toString.call(r))[1]},getType(r,t=globalThis){let e=Object.getStringTag(r);switch(e){case"Null":return null;case"Undefined":return;default:return t[e]}},isObject(r){return r&&(r instanceof Object||typeof r=="object")},isPrimitive(r){if(r===null)return!0;switch(typeof r){case"string":case"number":case"bigint":case"boolean":case"undefined":case"symbol":return!0;default:return!1}},isValidKey(r){return typeof r=="string"||typeof r=="symbol"},stripTo(r,t,e=!0){if(!r||typeof r!="object")throw new TypeError("Object.stripTo requires an object to strip. Received",r);let s={};if(!Array.isArray(t))return s;for(let o of t)if(Reflect.has(r,o)){let i={...Object.getOwnPropertyDescriptor(r,o)};(typeof i.get=="function"||typeof i.set=="function")&&e&&(i.get=i.get?.bind(r),i.set=i.set?.bind(r)),Object.defineProperty(s,o,i)}return s}}),q=new a(Object.prototype,{stripTo(r,t=!0){return Object.stripTo(this,r,t)}});var{getStringTag:z}=p.patches,T=new a(Function,{isAsync(r){let t=/(\w+)]/g.exec(Object.prototype.toString.call(r))[1];return r instanceof Function&&t.includes("Async")},isAsyncGenerator(r){let t=z(r);return r instanceof Function&&t=="AsyncGeneratorFunction"},isBigArrow(r){return r instanceof Function&&String(r).includes("=>")&&!String(r).startsWith("bound")&&!Reflect.has(r,"prototype")},isBound(r){return r instanceof Function&&String(r).startsWith("bound")&&!Reflect.has(r,"prototype")},isClass(r){return r instanceof Function&&!!/^class\s/.exec(String(r))},isFunction(r){return r instanceof Function&&!Function.isClass(r)},isGenerator(r){let t=z(r);return r instanceof Function&&t=="GeneratorFunction"}}),H=new a(Function.prototype,{get isAsync(){return Function.isAsync(this)},get isAsyncGenerator(){return Function.isAsyncGenerator(this)},get isBigArrow(){return Function.isBigArrow(this)},get isBound(){return Function.isBound(this)},get isClass(){return Function.isClass(this)},get isFunction(){return Function.isFunction(this)},get isGenerator(){return Function.isGenerator(this)}});var J=new a(Map.prototype,{getKey(r,t=!0){for(let[e,s]of this)return t&&r===s&&!t&&r==s?e:null}});var Q=new a(Set.prototype,{concat(...r){for(let t of r){if(typeof t=="string"||!Reflect.has(t,Symbol.iterator)){this.add(t);continue}for(let e of t)this.add(e)}},contains(r){for(let t of this)if(r==t)return!0;return!1},every(r,t){if(typeof r!="function")throw new TypeError(`everyFn must be a function! Received ${String(r)}`);let e=0;for(let s of this)r.call(t,s,NaN,this)&&e++;return e===this.size},find(r,t){if(typeof r!="function")throw new TypeError(`findFn must be a function! Received ${String(r)}`);for(let e of this)if(r.call(t,e,NaN,this))return e},findLast(r,t){if(typeof r!="function")throw new TypeError(`findFn must be a function! Received ${String(r)}`);let e=[];for(let s of this)r.call(t,s,NaN,this)&&e.push(s);if(e.length)return e[e.length-1]},get length(){return this.size},map(r,t){if(typeof r!="function")throw new TypeError(`mapFn must be a function! Received ${String(r)}`);let e=[];for(let s of this)e.push(r.call(t,s,NaN,this));return e},reduce(r,t,e){if(typeof r!="function")throw new TypeError(`reduceFn must be a Function! Received ${String(r)}`);let s=t;for(let o of this)s=r.call(e,s,o,NaN,this);return s},some(r,t){if(typeof r!="function")throw new TypeError(`someFn must be a function! Received ${String(r)}`);for(let e of this)if(r.call(t,e,NaN,this))return!0;return!1}});var{isObject:X}=p.patches,P=new a(Reflect,{hasAll(r,...t){return Object.isObject(r)&&t.flat(1/0).map(e=>Reflect.has(r,e)).every(e=>e)},ownDescriptors(r){if(!X(r))throw new TypeError("The supplied object must be non-null and an object");let t={},e=Reflect.ownKeys(r);for(let s of e)t[s]=Object.getOwnPropertyDescriptor(s);return t},hasSome(r,...t){return X(r)&&t.flat(1/0).map(e=>Reflect.has(r,e)).some(e=>e)},entries(r){return!r||typeof r!="object"?[]:Reflect.ownKeys(r).map(t=>[t,Object.getOwnPropertyDescriptor(r,t)])},values(r){return Reflect.entries.map(([,t])=>t)}});var Z=new a(String,{isString(r){return r&&(typeof r=="string"||r instanceof String)?r.length>0:!1}});var v=new a(Symbol,{isSymbol(r){return r&&typeof r=="symbol"},isRegistered(r,t=!1){if(!Symbol.isSymbol(r)){if(t)throw new TypeError("allowOnlySymbols specified; value is not a symbol");return!1}return Symbol.keyFor(r)!==void 0},isNonRegistered(r,t=!1){return!Symbol.isRegistered(r,t)}});var _=new a(Array.prototype,{contains(r){return!!this.find(t=>t===r)},findEntry(r){let t=this.entries(),e=1;for(let s of t)if(r(s[e]))return s},get first(){return this[0]},get last(){return this[this.length-1]}});var{isObject:d,isValidKey:k}=p.patches,{hasSome:$}=P.patches,E=class r{#t=void 0;#e=void 0;constructor(t,e){if((t??e)===void 0&&(this.#t=r.enigmatic),r.isDescriptor(t)?(this.#t=t,this.#e=void 0):d(t)&&k(e)&&(this.#t=Object.getOwnPropertyDescriptor(t,e),this.#e=t),!this.isDescriptor)throw console.error("Current descriptor:",this.#t),new Error("Not a valid descriptor:",this.#t)}get isAccessor(){return r.isAccessor(this.#t)}get isData(){return r.isData(this.#t)}get isDescriptor(){return r.isDescriptor(this.#t)}get configurable(){return!!this.#t?.configurable}set configurable(t){(this.#t||{}).configurable=!!t}get enumerable(){return this.#t?.enumerable}set enumerable(t){(this.#t||{}).enumerable=t}get writable(){return this.#t?.writable}set writable(t){(this.#t||{}).writable=t}get value(){return this.#t?.value}set value(t){(this.#t||{}).value=t}get get(){return this.#t?.get}get boundGet(){return d(this.#e)?this.get?.bind(this.#e):this.get}set get(t){(this.#t||{}).get=t}get set(){return(this.#t||{}).set}get boundSet(){return d(this.#e)?this.set?.bind(this.#e):this.set}set set(t){(this.#t||{}).set=t}get hasObject(){return d(this.#e)}get object(){return this.#e}set object(t){this.#e=Object(t)}[Symbol.for("nodejs.util.inspect.custom")](t,e,s){return`Descriptor${this.isAccessor?" (Accessor)":this.isData?" (Data)":""} ${s(this.#t,{...e,depth:t})}`}static for(t,e,s=!1){return!d(t)||!k(e)||!Reflect.has(t,e)?null:s?new r(Object.getOwnPropertyDescriptor(t,e)):Object.getOwnPropertyDescriptor(t,e)}applyTo(t,e){if(!d(t)||!k(e))throw new Error("Cannot apply descriptor to non-object or invalid key");return Object.defineProperty(t,e,this.#t)}[Symbol.toPrimitive](t){switch(t){case"string":if(this.isAccessor){let e=Reflect.has(this.#t,"get")?"getter":"",s=Reflect.has(this.#t,"set")?"setter":"";return`Accessor (${e}${e&&s?", ":""}${s})`}else if(this.isData){let e=Reflect.has(this.#t,"value")?"value":"",s=Reflect.has(this.#t,"writable")?"writable":"";return`Data (${e}${e&&s?", ":""}${s})`}break;case"number":return NaN;default:return this.#t}}get[Symbol.toStringTag](){return this.constructor.name}static getData(t,e){if(!d(t)||!Reflect.has(t,e))return;let s=r.for(t,e,!0);return s.isData?s.value:null}static getAccessor(t,e){if(!d(t)||!Reflect.has(t,e))return;let s=r.for(t,e,!0);return s.isAccessor?s.get.bind(t)():null}static base(t=!1,e=!1){return{enumerable:t,configurable:e}}static accessor(t,e,{enumerable:s,configurable:o}=r.base()){return{get:t,set:e,enumerable:s,configurable:o}}static data(t,e=!0,{enumerable:s,configurable:o}=r.base()){return{value:t,enumerable:s,writable:e,configurable:o}}static isDescriptor(t){let e=[...r.SHARED_KEYS,...r.ACCESSOR_KEYS,...r.DATA_KEYS];return $(t,e)}static isData(t,e){let o=(typeof t=="object"||t instanceof Object)&&e instanceof String?r.for(t,e):t,{DATA_KEYS:n}=this,i=!1;return $(o,n)&&(i=!0),i}static isAccessor(t,e){let o=t&&e&&(typeof t=="object"||t instanceof Object)&&(e instanceof String||typeof e=="symbol")?r.for(t,e):t,{ACCESSOR_KEYS:n}=this,i=!1;return $(o,n)&&(i=!0),i}static get flexible(){return this.base(!0,!0)}static get enigmatic(){return this.base(!1,!0)}static get intrinsic(){return this.base(!1,!1)}static get transparent(){return this.base(!0,!1)}static get SHARED_KEYS(){return["configurable","enumerable"]}static get ACCESSOR_KEYS(){return["get","set"]}static get DATA_KEYS(){return["value","writable"]}},I=new l(E);var{isClass:ht,isFunction:D}=T.patches,dt=Symbol.for("nodejs.util.inspect.custom"),tt=new a(globalThis,{maskAs(r,t,e){let{prototype:s,toPrimitive:o}=GenericMask({...e,prototype:t}),n={configurable:!0,enumerable:!1},i=D(s)?s.prototype:s,c=ht(s)?s:i?.constructor;return!c&&!i?null:(Object.setPrototypeOf(r,i),Object.defineProperties(r,{valueOf:{value(){return String(o("default",r))},...n},[Symbol.toPrimitive]:{value(u){return o(u,r)},...n},[Symbol.toStringTag]:{value:c.name,...n},[Symbol.species]:{get(){return c},...n},[dt]:{...n,value(u,f,h){return h(this[Symbol.toPrimitive](),{...f,depth:u})}}}),r)},maskAsString(r,t,e){return r&&Reflect.has(r,t)?maskAs(r,StringMask(t??"value",e)):null},maskAsNumber(r,t,e){return r&&Reflect.has(r,t)?maskAs(r,NumberMask(t??"value",e)):null},GenericMask({prototype:r,targetKey:t="value",toPrimitive:e}){let s={targetKey:t,toPrimitive:e,prototype:r};return D(e)||(s.toPrimitive=(o,n)=>{let i=n[t],c=typeof i=="number"&&Number.isFinite(i)||typeof i=="string"&&!isNaN(parseFloat(i))&&isFinite(i);switch(o){case"string":return c?String(i):i??String(n);case"number":return c?Number(i):NaN;case"default":default:return c?Number(i):i}}),s},StringMask(r,t){let e={targetKey:r,toPrimitive:t,prototype:String.prototype};return D(t)||(e.toPrimitive=function(o,n){switch(o){case"default":return n[r];case"number":return parseInt(n[r],36);case"string":return String(n[r]);default:return n}}),e},NumberMask(r,t){let e={targetKey:r,toPrimitive:t,prototype:Number.prototype};return D(t)||(e.toPrimitive=function(o,n){switch(o){case"default":return n[r];case"number":return Number(n[r]);case"string":return String(n[r]);default:return n}}),e}});var F=class r extends Set{#t=!1;objectifying(t=!0){return this.objectifyValues=t,this}get objectifyValues(){return this.#t}set objectifyValues(t){this.#t=!!t}add(t){if(this.#t&&(typeof t=="number"||typeof t=="string"||typeof t=="boolean"||typeof t=="bigint")&&(t=Object(t)),typeof t=="symbol"&&Symbol.keyFor(t)!==void 0)throw new TypeError("RefSet cannot accept registered symbols as values");if(typeof t!="object"&&typeof t!="symbol")throw new TypeError("RefSet values must be objects, non-registered symbols, or objectified primitives");if(t==null)throw new TypeError("RefSet values cannot be null or undefined");super.add(new WeakRef(t))}addAll(t){if(!t||typeof t!="object"||!Reflect.has(t,Symbol.iterator))throw new TypeError("The supplied values are either falsey or non-iterable");for(let e of t)this.add(e)}clean(){for(let t of this)t.deref()||this.delete(t);return this}entries(){return Array.from(super.entries()).map(([e,s])=>[s.deref(),s.deref()]).filter(([e,s])=>!!s)}forEach(t,e){let s=this;super.forEach(function(o){let n=o.deref();n&&t.call(e,n,n,s)})}values(){let t=[];for(let e of this){let s=e.deref();s&&t.push(s)}return t}keys(){return this.values()}has(t){if(this.#t)return this.contains(t);for(let e of this.values())if(e===t)return!0;return!1}contains(t){return!!Array.from(this.values()).filter(e=>t==e).length}filter(t,e){let s=[];for(let o of this){let n=o?.deref();n&&t.call(e,n,NaN,this)&&s.push(n)}return s}find(t,e){for(let s of this){let o=s?.deref();if(o&&t.call(e,o,NaN,this))return o}}map(t,e,s,o){let n=[],i=!0,c=!0;for(let u of this){let f=u?.deref();if(f){let h=t.call(e,f,NaN,this);(i||c)&&(this.#e(h)||(i=!1,c&&(c=this.#e(Object(h))))),n.push(h)}}if(s){if(i)return new r(n).objectifying(o?this.objectifyValues:!1);if(c)return new r(n.map(u=>this.#e(u)?u:Object(u))).objectifying()}return n}get[Symbol.toStringTag](){return this.constructor.name}#e(t){return!(typeof t=="symbol"&&Symbol.keyFor(t)===void 0||typeof t!="object"&&typeof t!="symbol"||t==null)}},V=new l(F);var et=new a(WeakRef,{isValidReference(r){return!(typeof r=="symbol"&&Symbol.keyFor(r)===void 0||typeof r!="object"&&typeof r!="symbol"||r==null)}});var A=class{#t=[];constructor(t,...e){t!=null&&typeof t[Symbol.iterator]=="function"?this.#t=[...t,...e]:this.#t=[t,...e]}*[Symbol.iterator](){for(let t of this.#t)yield t}get asArray(){return this.#t}get[Symbol.toStringTag](){return this.constructor.name}static isIterable(t){return Object.prototype.toString.call(t?.[Symbol.iterator])==="[object GeneratorFunction]"}},b=class{#t=void 0;constructor(t,e){if(!t||!Reflect.has(t,Symbol.iterator))throw new TypeError("Value used to instantiate Iterator is not iterable");this.#e=t,this.#r=t[Symbol.iterator](),this.#t=typeof e=="function"?e:void 0}get asArray(){return Array.from(this.#e)}get iterable(){return this.#e}next(){let t=this.#r.next(),e=t;return e.done?{value:void 0,done:!0}:(this.#t&&typeof this.#t=="function"&&(e.value=this.#t(t.value)),{value:e.value,done:!1})}reset(){this.#r=this.#e[Symbol.iterator]()}[Symbol.iterator](){return this}get[Symbol.toStringTag](){return this.constructor.name}#e=null;#r=null},C=new l(A),M=new l(b);var{isObject:yt,isNullDefined:mt,isValidKey:bt}=p.patches,{isRegistered:gt}=v.patches,{isValidReference:rt}=et.patches,G=class r extends Map{#t=!1;constructor(...t){super(...t)}objectifying(t=!0){return this.objectifyValues=t,this}asObject(){let t={};for(let[e,s]of this){let o=bt(e)?e:String(e),n=s?.valueOf()||s;t[o]=n}return t}get objectifyValues(){return this.#t}get(t,e){let s=super.get(t);return!s||!s?.deref()?e:s?.deref()}set objectifyValues(t){this.#t=!!t}set(t,e){let s=e;if(this.#t&&(typeof s=="number"||typeof s=="string"||typeof s=="boolean"||typeof s=="bigint")&&(s=Object(s)),typeof s=="symbol"&&Symbol.keyFor(s)!==void 0)throw new TypeError("RefMap cannot accept registered symbols as values");if(typeof s!="object"&&typeof s!="symbol")throw new TypeError("RefMap values must be objects, non-registered symbols, or objectified primitives");if(s==null)throw new TypeError("RefMap values cannot be null or undefined");let o=new WeakRef(s);super.set(t,o)}setAll(t){if(!A.isIterable(t))throw new TypeError("The supplied list of entries must be an array of arrays in the format [[key1, value1], [key2, value2], ...].");let e=s=>{let[o,n]=s;!o||!yt(n)||!gt(n)||this.set(o,n)};for(let s of t)e(s);return this}clean(){for(let[t,e]of this)e||this.delete(t);return this}entries(){let t=super.entries();return new b(t,s=>{if(s){let[o,n]=s,i=n?.deref();return[o,i]}return s})}forEach(t,e){for(let[s,o]of super.entries()){let n=o?.deref();n&&t.call(e,n,s,this)}}values(){return new b(super.values(),function(e){return e?.deref()||e})}hasValue(t,e=!0){if(mt(t))return!1;this.#t&&(e=!1);for(let[s,o]of this)if(e&&t===o||!e&&t==o)return!0;return!1}filter(t,e){let s=[];for(let[o,n]of this)t.call(e,n,o,this)&&s.push([o,n]);return s}find(t,e){for(let[s,o]of this){let n=super.get(s),i=t.call(e,n,s,map);if(i||(i=t.call(e,o,s,map)),i)return o}return null}map(t,e,s,o){if(typeof t!="function")throw new TypeError("mapFn must be a function! Received",t);let n=[],i=[],c=o&&this.objectifyValues,u=o===void 0,f=c;for(let[h,U]of this){let[,j]=[0,1],g=t.call(e,[h,U],h,this);rt(g[j])||rt(Object(g[j]))&&(c=!0,u&&!f&&(f=!0,g[j]=Object(g[j]))),n.push(g)}return s?new r(n).objectifying(f):n}*[Symbol.iterator](){for(let[t,e]of this.entries())yield[t,e]}get[Symbol.toStringTag](){return this.constructor.name}},K=new l(G);var B=class{#t=[];constructor(t,...e){t!=null&&typeof t[Symbol.iterator]=="function"?this.#t=[...t,...e]:this.#t=[t,...e]}async*[Symbol.asyncIterator](){for(let t of this.#t)yield Promise.resolve(t)}get[Symbol.toStringTag](){return this.constructor.name}static isAsyncIterable(t){return Object.prototype.toString.call(t?.[Symbol.asyncIterator])==="[object AsyncGeneratorFunction]"}},W=class{constructor(t){if(!t||!Reflect.has(t,Symbol.asyncIterator))throw new TypeError("Value used to instantiate AsyncIterator is not an async iterable");this.#t=t,this.#e=t[Symbol.asyncIterator]()}async asArray(){let t=[];for await(let e of this)t.push(e);return t}get asyncIterable(){return this.#t}async next(){let t=await this.#e.next();return t.done?{value:void 0,done:!0}:{value:t.value,done:!1}}async reset(){this.#e=this.#t[Symbol.asyncIterator]()}[Symbol.asyncIterator](){return this}get[Symbol.toStringTag](){return this.constructor.name}#t=null;#e=null},Y=new l(B),L=new l(W);var R=new Map([[Object,p],[Function,T],[Reflect,P],[String,Z],[Symbol,v],[Object.prototype,q],[Function.prototype,H],[Array.prototype,_],[Map.prototype,J],[Set.prototype,Q],[globalThis,tt]]),O={[I.key]:I,[Y.key]:Y,[L.key]:L,[C.key]:C,[M.key]:M,[V.key]:V,[K.key]:K},y={};Object.assign(y,{enableAll(){y.enablePatches(),y.enableExtensions()},enablePatches(){R.forEach(r=>{r.apply()})},enableExtensions(){Object.values(O).forEach(r=>{r.apply()})},disableAll(r){y.disablePatches(),y.disableExtensions()},disablePatches(){R.forEach(r=>{r.revert()})},disableExtensions(){Object.values(O).forEach(r=>{r.revert()})}});var st=[...Array.from(R.values()),...Array.from(Object.values(O))].reduce((e,s)=>(Reflect.ownKeys(s.patchEntries).reduce((o,n)=>{let i=s.patchEntries[n];return i.isAccessor?e[n]=new E(i.descriptor):e[n]=i.computed,e},e),e),{}),wt={...y,extensions:O,patches:R,all:st},St=wt;return ft(xt);})();
4
- //# sourceMappingURL=basic-extensions.bundle.1.7.0.js.map