@nejs/basic-extensions 1.9.0 → 2.0.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
@@ -58,9 +58,9 @@
58
58
  "test": "jest"
59
59
  },
60
60
  "type": "module",
61
- "version": "1.9.0",
61
+ "version": "2.0.0",
62
62
  "dependencies": {
63
- "@nejs/extension": "^2.1.0"
63
+ "@nejs/extension": "^2.5.0"
64
64
  },
65
- "browser": "dist/@nejs/basic-extensions.bundle.1.8.0.js"
65
+ "browser": "dist/@nejs/basic-extensions.bundle.1.10.0.js"
66
66
  }
package/src/index.js CHANGED
@@ -23,19 +23,19 @@ import {
23
23
  } from './newClasses/iterable.js'
24
24
 
25
25
  const StaticPatches = [
26
- [Object, ObjectExtensions],
27
- [Function, FunctionExtensions],
28
- [Reflect, ReflectExtensions],
29
- [String, StringExtensions],
30
- [Symbol, SymbolExtensions],
26
+ [Object, ObjectExtensions, Object.name],
27
+ [Function, FunctionExtensions, Function.name],
28
+ [Reflect, ReflectExtensions, 'Reflect'], // Missing a .name property
29
+ [String, StringExtensions, String.name],
30
+ [Symbol, SymbolExtensions, 'Symbol'], // Missing a .name property
31
31
  ]
32
32
 
33
33
  const InstancePatches = [
34
- [Object.prototype, ObjectPrototypeExtensions],
35
- [Function.prototype, FunctionPrototypeExtensions],
36
- [Array.prototype, ArrayPrototypeExtensions],
37
- [Map.prototype, MapPrototypeExtensions],
38
- [Set.prototype, SetPrototypeExtensions],
34
+ [Object.prototype, ObjectPrototypeExtensions, Object.name],
35
+ [Function.prototype, FunctionPrototypeExtensions, Function.name],
36
+ [Array.prototype, ArrayPrototypeExtensions, Array.name],
37
+ [Map.prototype, MapPrototypeExtensions, Map.name],
38
+ [Set.prototype, SetPrototypeExtensions, Set.name],
39
39
  ]
40
40
 
41
41
  const Patches = new Map([
@@ -44,8 +44,6 @@ const Patches = new Map([
44
44
  ])
45
45
 
46
46
  const Extensions = {
47
- global: GlobalFunctionsAndProps,
48
-
49
47
  [AsyncIterableExtensions.key]: AsyncIterableExtensions,
50
48
  [AsyncIteratorExtensions.key]: AsyncIteratorExtensions,
51
49
  [DeferredExtension.key]: DeferredExtension,
@@ -68,16 +66,21 @@ Object.assign(Controls, {
68
66
  Patches.forEach((extension) => { extension.apply() })
69
67
  },
70
68
 
71
- enableStaticPatches(filter = (extension) => true) {
72
- StaticPatches.filter(filter).forEach(extension => extension.apply())
69
+ enableStaticPatches(filter = ([owner, extension]) => true) {
70
+ const patches = StaticPatches.filter(toFilterFn(filter))
71
+ patches.forEach(([_, extension]) => extension.apply())
72
+ return patches
73
73
  },
74
74
 
75
- enableInstancePatches(filter = (extension) => true) {
76
- InstancePatches.filter(filter).forEach(extension => extension.apply())
75
+ enableInstancePatches(filter = ([owner, extension]) => true) {
76
+ const patches = InstancePatches.filter(toFilterFn(filter))
77
+ patches.forEach(([_, extension]) => extension.apply())
78
+ return patches
77
79
  },
78
80
 
79
81
  enableExtensions() {
80
82
  Object.values(Extensions).forEach((extension) => { extension.apply() })
83
+ GlobalFunctionsAndProps.apply()
81
84
  },
82
85
 
83
86
  disableAll() {
@@ -89,45 +92,82 @@ Object.assign(Controls, {
89
92
  Patches.forEach((extension) => { extension.revert() })
90
93
  },
91
94
 
92
- disableStaticPatches(filter = (extension) => true) {
93
- StaticPatches.filter(filter).forEach(extension => extension.revert())
95
+ disableStaticPatches(filter = ([owner, extension]) => true) {
96
+ const patches = StaticPatches.filter(toFilterFn(filter))
97
+ patches.forEach(([_, extension]) => extension.revert())
98
+ return patches
94
99
  },
95
100
 
96
- disableInstancePatches(filter = (extension) => true) {
97
- InstancePatches.filter(filter).forEach(extension => extension.revert())
101
+ disableInstancePatches(filter = ([owner, extension]) => true) {
102
+ const patches = InstancePatches.filter(toFilterFn(filter))
103
+ patches.forEach(([_, extension]) => extension.revert())
104
+ return patches
98
105
  },
99
106
 
100
107
  disableExtensions() {
101
108
  Object.values(Extensions).forEach((extension) => { extension.revert() })
109
+ GlobalFunctionsAndProps.revert()
102
110
  },
103
111
  })
104
112
 
105
113
  export const all = (() => {
106
- const extensions = [
107
- ...Array.from(Patches.values()),
108
- ...Array.from(Object.values(Extensions)),
109
- ]
114
+ const dest = {
115
+ patches: {},
116
+ classes: {},
117
+ global: {},
118
+ };
119
+
120
+ const entriesReducer = (accumulator, [key, entry]) => {
121
+ const descriptor = new Descriptor(entry.descriptor, entry.owner)
110
122
 
111
- const dest = extensions.reduce((accumulator, extension) => {
112
- Reflect.ownKeys(extension.patchEntries).reduce((_, key) => {
113
- const entry = extension.patchEntries[key]
123
+ descriptor.applyTo(accumulator, key, true)
114
124
 
115
- if (entry.isAccessor)
116
- accumulator[key] = new Descriptor(entry.descriptor)
117
- else
118
- accumulator[key] = entry.computed
125
+ return accumulator
126
+ }
119
127
 
120
- return accumulator
121
- }, accumulator)
128
+ const staticPatchReducer = (accumulator, [_, patch, ownerName]) => {
129
+ if (!accumulator?.[ownerName]) {
130
+ accumulator[ownerName] = {}
131
+ }
122
132
 
133
+ [...patch].reduce(entriesReducer, accumulator[ownerName])
123
134
  return accumulator
124
- }, {})
135
+ };
125
136
 
126
- return dest
137
+ const instancePatchReducer = (accumulator, [_, patch, ownerName]) => {
138
+ if (!accumulator?.[ownerName])
139
+ accumulator[ownerName] = {};
140
+
141
+ if (!accumulator[ownerName]?.prototype)
142
+ accumulator[ownerName].prototype = {};
143
+
144
+ [...patch].reduce(entriesReducer, accumulator[ownerName].prototype)
145
+ return accumulator
146
+ }
147
+
148
+ StaticPatches.reduce(staticPatchReducer, dest.patches);
149
+ InstancePatches.reduce(instancePatchReducer, dest.patches);
150
+ (Object.entries(Extensions)
151
+ .map(([k,v]) => [k, v, k])
152
+ .reduce(staticPatchReducer, dest.classes)
153
+ )
154
+
155
+ for (const [key, entry] of GlobalFunctionsAndProps) {
156
+ const descriptor = new Descriptor(entry.descriptor, entry.owner)
157
+ Object.defineProperty(dest.global, key, descriptor.toObject(true))
158
+ }
159
+
160
+ return dest
127
161
  })()
128
162
 
129
163
  const results = {
130
164
  ...Controls,
165
+ Extensions,
166
+ Patches,
167
+ GlobalFunctionsAndProps,
168
+ StaticPatches,
169
+ InstancePatches,
170
+ Controls,
131
171
  extensions: Extensions,
132
172
  patches: Patches,
133
173
  all,
@@ -138,5 +178,32 @@ export default results
138
178
  export {
139
179
  Extensions,
140
180
  Patches,
181
+ StaticPatches,
182
+ InstancePatches,
141
183
  Controls,
184
+ GlobalFunctionsAndProps,
142
185
  }
186
+
187
+ function toFilterFn(filter = ([owner, extension]) => true) {
188
+ let filterFn = filter
189
+
190
+ if (typeof filterFn !== 'function') {
191
+ const elements = Array.isArray(filter) ? filter : [filter]
192
+ filterFn = ([owner, _]) => {
193
+ for (const element of elements) {
194
+ const elementStr = String(element)
195
+ if (elementStr.startsWith('^')) {
196
+ if ((owner?.name ?? owner) != elementStr.substring(1)) {
197
+ return true
198
+ }
199
+ }
200
+ if ((owner?.name ?? owner) == elementStr) {
201
+ return true
202
+ }
203
+ }
204
+ return false
205
+ }
206
+ }
207
+
208
+ return filterFn
209
+ }
@@ -17,24 +17,32 @@ export class AsyncIterable {
17
17
 
18
18
  /**
19
19
  * Constructs an instance of AsyncIterable. Similar to Iterable, it can be
20
- * initialized with either an iterable object or individual elements. The
21
- * elements can be promises, direct values, or a mix of both. If the first
22
- * argument is an iterable, the instance is initialized with the elements
23
- * from the iterable, followed by any additional arguments. If the first
24
- * argument is not an iterable, all arguments are treated as individual
25
- * elements.
20
+ * initialized with either an iterable object, an async generator function,
21
+ * or individual elements. The elements can be promises, direct values, or a
22
+ * mix of both. If the first argument is an iterable or an async generator
23
+ * function, the instance is initialized with the elements from the iterable
24
+ * or the generated elements from the async generator function, followed by
25
+ * any additional arguments. If the first argument is not an iterable or an
26
+ * async generator function, all arguments are treated as individual elements.
26
27
  *
27
- * @param {Iterable|Promise|*} elementsOrFirstElement - An iterable object,
28
- * a Promise, or the first element.
28
+ * @param {Iterable|AsyncGeneratorFunction|Promise|*} elementsOrFirstElement -
29
+ * An iterable object, an async generator function, a Promise, or the first
30
+ * element.
29
31
  * @param {...Promise|*} moreElements - Additional elements if the first
30
- * argument is not an iterable.
32
+ * argument is not an iterable or an async generator function.
31
33
  */
32
34
  constructor(elementsOrFirstElement, ...moreElements) {
33
35
  if (
34
36
  elementsOrFirstElement != null &&
35
- typeof elementsOrFirstElement[Symbol.iterator] === 'function'
37
+ (typeof elementsOrFirstElement[Symbol.iterator] === 'function' ||
38
+ typeof elementsOrFirstElement[Symbol.asyncIterator] === 'function')
36
39
  ) {
37
40
  this.#elements = [...elementsOrFirstElement, ...moreElements];
41
+ } else if (
42
+ typeof elementsOrFirstElement === 'function' &&
43
+ elementsOrFirstElement.constructor.name === 'AsyncGeneratorFunction'
44
+ ) {
45
+ this.#elements = elementsOrFirstElement();
38
46
  } else {
39
47
  this.#elements = [elementsOrFirstElement, ...moreElements];
40
48
  }
@@ -51,10 +59,10 @@ export class AsyncIterable {
51
59
  * a Promise.
52
60
  */
53
61
  async *[Symbol.asyncIterator]() {
54
- for (const element of this.#elements) {
55
- // Treat each element as a promise. If it's not, it's automatically
56
- // wrapped as a resolved promise.
57
- yield Promise.resolve(element);
62
+ for await (const element of this.#elements) {
63
+ // No need to wrap as a promise here since `for await...of` can handle
64
+ // both Promises and non-Promise values.
65
+ yield element;
58
66
  }
59
67
  }
60
68
 
@@ -98,18 +106,25 @@ export class AsyncIterator {
98
106
  /**
99
107
  * Creates a new `AsyncIterator` object instance.
100
108
  *
101
- * @param {object} asyncIterable any object that has a
102
- * `[Symbol.asyncIterable]` property assigned to a generator function.
109
+ * @param {object|AsyncGeneratorFunction} asyncIterable any object that has a
110
+ * `[Symbol.asyncIterable]` property assigned to a generator function or an
111
+ * async generator function itself.
103
112
  */
104
113
  constructor(asyncIterable) {
105
- if (!asyncIterable || !Reflect.has(asyncIterable, Symbol.asyncIterator)) {
114
+ if (typeof asyncIterable === 'function' &&
115
+ asyncIterable.constructor.name === 'AsyncGeneratorFunction') {
116
+ this.#asyncIterable = asyncIterable();
117
+ } else if (
118
+ !asyncIterable ||
119
+ !Reflect.has(asyncIterable, Symbol.asyncIterator)
120
+ ) {
106
121
  throw new TypeError(
107
122
  'Value used to instantiate AsyncIterator is not an async iterable'
108
123
  );
124
+ } else {
125
+ this.#asyncIterable = asyncIterable;
109
126
  }
110
-
111
- this.#asyncIterable = asyncIterable;
112
- this.#asyncIterator = asyncIterable[Symbol.asyncIterator]();
127
+ this.#asyncIterator = this.#asyncIterable[Symbol.asyncIterator]();
113
128
  }
114
129
 
115
130
  /**
@@ -24,30 +24,41 @@ export class Descriptor {
24
24
  #object = undefined
25
25
 
26
26
  /**
27
- * Creates a new instance of Descriptor either from another object or
28
- * around the supplied object descriptor value.
29
- *
30
- * @param {object} object either an object descriptor or the object
31
- * from which to get the descriptor
32
- * @param {symbol|string} key a valid key for accessing the descriptor
33
- * on the aforesupplied object.
27
+ * Constructs a Descriptor instance which wraps and manages an object
28
+ * property descriptor. The constructor can handle an existing descriptor
29
+ * object or create a new one based on an object and a property key.
30
+ *
31
+ * @param {object|Descriptor} object - The target object or an existing
32
+ * Descriptor instance. If it's an object, it is used in conjunction with
33
+ * `key` to create a descriptor. If it's a Descriptor instance, it is used
34
+ * directly as the descriptor.
35
+ * @param {string|symbol} [key] - The property key for which the descriptor
36
+ * is to be created. This parameter is ignored if `object` is a Descriptor
37
+ * instance. If `key` is an object and `object` is a valid descriptor, `key`
38
+ * is treated as the associated object.
39
+ * @throws {Error} Throws an error if the constructed descriptor is not
40
+ * valid.
34
41
  */
35
42
  constructor(object, key) {
36
43
  if ((object ?? key) === undefined) {
37
44
  this.#desc = Descriptor.enigmatic
38
45
  }
39
-
40
- if (Descriptor.isDescriptor(object)) {
46
+ else if (Descriptor.isDescriptor(object)) {
41
47
  this.#desc = object
42
- this.#object = undefined
43
- }
48
+ this.#object = isObject(key) ? key : undefined
49
+ }
44
50
  else if (isObject(object) && isValidKey(key)) {
45
51
  this.#desc = Object.getOwnPropertyDescriptor(object, key)
46
52
  this.#object = object
47
53
  }
48
54
 
49
55
  if (!this.isDescriptor) {
50
- console.error('Current descriptor:', this.#desc)
56
+ console.error(`
57
+ Descriptor(object,key) FAILED:
58
+ object: ${object === globalThis ? '[GLOBAL]' : (typeof key === 'object' ? JSON.stringify(object) : String(object))}
59
+ key: ${key === globalThis ? '[GLOBAL]' : (typeof key === 'object' ? JSON.stringify(key) : String(key))}
60
+ descriptor: `, this.#desc
61
+ )
51
62
  throw new Error(`Not a valid descriptor:`, this.#desc)
52
63
  }
53
64
  }
@@ -314,12 +325,48 @@ export class Descriptor {
314
325
  * @param {string|symbol} forKey the string or symbol for which this
315
326
  * descriptor will abe applied
316
327
  */
317
- applyTo(object, forKey) {
328
+ applyTo(object, forKey, bindAccessors = false) {
318
329
  if (!isObject(object) || !isValidKey(forKey)) {
319
330
  throw new Error(`Cannot apply descriptor to non-object or invalid key`)
320
331
  }
321
332
 
322
- return Object.defineProperty(object, forKey, this.#desc)
333
+ return Object.defineProperty(object, forKey, this.toObject(bindAccessors))
334
+ }
335
+
336
+ /**
337
+ * Converts this Descriptor class instance into a basic object descriptor
338
+ * that is accepted by all the standard JavaScript runtime methods that
339
+ * deal with object descriptors.
340
+ *
341
+ * @param {boolean|object} bindAccessors if `true`, a non-fatal attempt to
342
+ * bind accessor getter and setter methods is made before returning the
343
+ * object. If `bindAccessors` is truthy and is also an object, this is the
344
+ * object the accessors will be bound to. If the value is falsy or if the
345
+ * descriptor instance represents a data descriptor, nothing happens.
346
+ * @returns {object} the object instance's basic object representation as
347
+ * a descriptor.
348
+ */
349
+ toObject(bindAccessors = false) {
350
+ let descriptor = { ...this.#desc }
351
+
352
+ if (bindAccessors && this.isAccessor) {
353
+ if (this.hasObject) {
354
+ descriptor = {
355
+ ...descriptor,
356
+ get: this.boundGet,
357
+ set: this.boundSet
358
+ }
359
+ }
360
+ else if (isObject(bindAccessors)) {
361
+ descriptor = {
362
+ ...descriptor,
363
+ get: this.get?.bind(bindAccessors),
364
+ set: this.set?.bind(bindAccessors)
365
+ }
366
+ }
367
+ }
368
+
369
+ return descriptor
323
370
  }
324
371
 
325
372
  /**
@@ -352,7 +399,7 @@ export class Descriptor {
352
399
  return NaN
353
400
 
354
401
  default:
355
- return this.#desc
402
+ return this.toObject()
356
403
  }
357
404
  }
358
405
 
@@ -1,4 +0,0 @@
1
- var nejsBasicExtensions=(()=>{var N=Object.defineProperty;var at=Object.getOwnPropertyDescriptor;var ft=Object.getOwnPropertyNames;var ut=Object.prototype.hasOwnProperty;var lt=(r,t)=>{for(var e in t)N(r,e,{get:t[e],enumerable:!0})},pt=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ft(t))!ut.call(r,o)&&o!==e&&N(r,o,{get:()=>t[o],enumerable:!(s=at(t,o))||s.enumerable});return r};var ht=r=>pt(N({},"__esModule",{value:!0}),r);var Ot={};lt(Ot,{Controls:()=>y,Extensions:()=>O,Patches:()=>R,all:()=>ct,default:()=>Rt});var dt=r=>/(\w+)]/.exec(Object.prototype.toString.call(r))[1],w=class extends Error{constructor(t,e){super(`${dt(t)} disallows tampering with ${e}.`),Object.assign(this,{owner:t,key:e})}get[Symbol.toStringTag](){return this.constructor.name}};var yt=r=>/(\w+)]/.exec(Object.prototype.toString.call(r))[1],S=class extends Error{constructor(t,e){super(`${yt(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,l=["string","symbol"])=>!o(c)&&!!l.find(u=>u===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 mt=["number","boolean","bigint","string","symbol"],f=class r extends a{constructor(t,e,s=globalThis,o={}){let n=r.determineInput(t),{key:i,extension:c,valid:l}=n;if(c=e||c,!l)throw new S(s,i);let u=Object.getOwnPropertyDescriptor(s,i);if(u&&(Reflect.has(u,"writable")&&!u.writable||Reflect.has(u,"configurable")&&!u.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~mt.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:X}=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=X(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=X(r);return r instanceof Function&&t=="GeneratorFunction"}}),Z=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 _=new a(Map.prototype,{getKey(r,t=!0){for(let[e,s]of this)return t&&r===s&&!t&&r==s?e:null}});var tt=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:et}=p.patches,v=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(!et(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 et(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 rt=new a(String,{isString(r){return r&&(typeof r=="string"||r instanceof String)?r.length>0:!1}});var P=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 st=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:$}=v.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 f(E);var{isClass:bt,isFunction:D}=T.patches,gt=Symbol.for("nodejs.util.inspect.custom"),nt=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=bt(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(l){return o(l,r)},...n},[Symbol.toStringTag]:{value:c.name,...n},[Symbol.species]:{get(){return c},...n},[gt]:{...n,value(l,u,h){return h(this[Symbol.toPrimitive](),{...u,depth:l})}}}),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 l of this){let u=l?.deref();if(u){let h=t.call(e,u,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(l=>this.#e(l)?l:Object(l))).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 f(F);var ot=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 f(A),M=new f(b);var{isObject:wt,isNullDefined:St,isValidKey:xt}=p.patches,{isRegistered:Et}=P.patches,{isValidReference:it}=ot.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=xt(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||!wt(n)||!Et(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(St(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,l=o===void 0,u=c;for(let[h,J]of this){let[,j]=[0,1],g=t.call(e,[h,J],h,this);it(g[j])||it(Object(g[j]))&&(c=!0,l&&!u&&(u=!0,g[j]=Object(g[j]))),n.push(g)}return s?new r(n).objectifying(u):n}*[Symbol.iterator](){for(let[t,e]of this.entries())yield[t,e]}get[Symbol.toStringTag](){return this.constructor.name}},K=new f(G);var B=class r extends Promise{#t=null;#e=null;#r=null;value=null;reason=null;#s=!1;constructor(t){let e=t&&typeof t=="object"?t:{};if(e?.resolve&&e?.reject)throw new TypeError("resolve and reject options cannot be simultaneously provided");let s,o;super((n,i)=>{s=n,o=i,e?.executor&&typeof e?.executor=="function"&&e?.executor(n,i)}),this.#r=n=>(e?.doNotTrackAnswers!==!0&&(this.value=n),this.#s=!0,s(n)),this.#e=async n=>(e?.doNotTrackAnswers!==!0&&(this.reason=n),this.#s=!0,o(n)),this.#t=this,e?.resolve?this.#r(e?.resolve):e?.reject&&this.#e(e?.reject)}get settled(){return this.#s}get promise(){return this.#t}resolve(t){return this.#r(t)}reject(t){return this.#e(t)}static get[Symbol.species](){return class extends r{constructor(e){super({executor:e})}}}},W=new f(B);var Y=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]"}},L=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},U=new f(Y),q=new f(L);var z=[[Object,p],[Function,T],[Reflect,v],[String,rt],[Symbol,P]],H=[[Object.prototype,Q],[Function.prototype,Z],[Array.prototype,st],[Map.prototype,_],[Set.prototype,tt]],R=new Map([...z,...H]),O={global:nt,[U.key]:U,[q.key]:q,[W.key]:W,[I.key]:I,[C.key]:C,[M.key]:M,[K.key]:K,[V.key]:V},y={};Object.assign(y,{enableAll(){y.enablePatches(),y.enableExtensions()},enablePatches(){R.forEach(r=>{r.apply()})},enableStaticPatches(r=t=>!0){z.filter(r).forEach(t=>t.apply())},enableInstancePatches(r=t=>!0){H.filter(r).forEach(t=>t.apply())},enableExtensions(){Object.values(O).forEach(r=>{r.apply()})},disableAll(){y.disablePatches(),y.disableExtensions()},disablePatches(){R.forEach(r=>{r.revert()})},disableStaticPatches(r=t=>!0){z.filter(r).forEach(t=>t.revert())},disableInstancePatches(r=t=>!0){H.filter(r).forEach(t=>t.revert())},disableExtensions(){Object.values(O).forEach(r=>{r.revert()})}});var ct=[...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),{}),At={...y,extensions:O,patches:R,all:ct},Rt=At;return ht(Ot);})();
4
- //# sourceMappingURL=basic-extensions.bundle.1.8.0.js.map