@tailwindcss/oxide-wasm32-wasi 4.2.4 → 4.3.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.
Files changed (47) hide show
  1. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.js +854 -307
  2. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.d.ts +3 -2
  3. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.js +1 -1
  4. package/node_modules/@emnapi/core/dist/emnapi-core.d.mts +3 -2
  5. package/node_modules/@emnapi/core/dist/emnapi-core.d.ts +3 -2
  6. package/node_modules/@emnapi/core/dist/emnapi-core.esm-bundler.js +892 -313
  7. package/node_modules/@emnapi/core/dist/emnapi-core.js +904 -328
  8. package/node_modules/@emnapi/core/dist/emnapi-core.min.d.mts +3 -2
  9. package/node_modules/@emnapi/core/dist/emnapi-core.min.js +1 -1
  10. package/node_modules/@emnapi/core/dist/emnapi-core.min.mjs +1 -1
  11. package/node_modules/@emnapi/core/dist/emnapi-core.mjs +854 -307
  12. package/node_modules/@emnapi/core/package.json +2 -2
  13. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.js +32 -5
  14. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.d.ts +8 -2
  15. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.js +1 -1
  16. package/node_modules/@emnapi/runtime/dist/emnapi.d.mts +8 -2
  17. package/node_modules/@emnapi/runtime/dist/emnapi.d.ts +8 -2
  18. package/node_modules/@emnapi/runtime/dist/emnapi.esm-bundler.js +33 -5
  19. package/node_modules/@emnapi/runtime/dist/emnapi.iife.d.ts +8 -2
  20. package/node_modules/@emnapi/runtime/dist/emnapi.iife.js +33 -5
  21. package/node_modules/@emnapi/runtime/dist/emnapi.js +33 -5
  22. package/node_modules/@emnapi/runtime/dist/emnapi.min.d.mts +8 -2
  23. package/node_modules/@emnapi/runtime/dist/emnapi.min.js +1 -1
  24. package/node_modules/@emnapi/runtime/dist/emnapi.min.mjs +1 -1
  25. package/node_modules/@emnapi/runtime/dist/emnapi.mjs +32 -5
  26. package/node_modules/@emnapi/runtime/package.json +1 -1
  27. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.js +17 -20
  28. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.d.ts +2 -0
  29. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.js +1 -1
  30. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.mts +2 -0
  31. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +2 -0
  32. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.esm-bundler.js +17 -20
  33. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +17 -20
  34. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.d.mts +2 -0
  35. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.js +1 -1
  36. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.mjs +1 -1
  37. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.mjs +17 -20
  38. package/node_modules/@emnapi/wasi-threads/package.json +1 -1
  39. package/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +47 -12
  40. package/node_modules/@napi-rs/wasm-runtime/dist/fs.js +14310 -10201
  41. package/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +47 -12
  42. package/node_modules/@napi-rs/wasm-runtime/package.json +6 -4
  43. package/package.json +5 -5
  44. package/tailwindcss-oxide.wasi-browser.js +1 -0
  45. package/tailwindcss-oxide.wasi.cjs +1 -1
  46. package/tailwindcss-oxide.wasm32-wasi.wasm +0 -0
  47. package/wasi-worker-browser.mjs +4 -0
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emnapi/core",
3
- "version": "1.8.1",
3
+ "version": "1.10.0",
4
4
  "description": "emnapi core",
5
5
  "main": "index.js",
6
6
  "module": "./dist/emnapi-core.esm-bundler.js",
@@ -27,7 +27,7 @@
27
27
  }
28
28
  },
29
29
  "dependencies": {
30
- "@emnapi/wasi-threads": "1.1.0",
30
+ "@emnapi/wasi-threads": "1.2.1",
31
31
  "tslib": "^2.4.0"
32
32
  },
33
33
  "scripts": {
@@ -154,7 +154,7 @@ const _Buffer = typeof Buffer === 'function'
154
154
  catch (_) { }
155
155
  return undefined;
156
156
  })();
157
- const version = "1.8.1";
157
+ const version = "1.10.0";
158
158
  const NODE_API_SUPPORTED_VERSION_MIN = 1;
159
159
  const NODE_API_SUPPORTED_VERSION_MAX = 10;
160
160
  const NAPI_VERSION_EXPERIMENTAL = 2147483647;
@@ -702,7 +702,7 @@ class NodeEnv extends Env {
702
702
  console.warn(`${prefix}${type || 'Warning'}: ${warning}`);
703
703
  }
704
704
  };
705
- warn('Uncaught N-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168');
705
+ warn('Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168');
706
706
  return;
707
707
  }
708
708
  envObject.triggerFatalException(err);
@@ -1106,6 +1106,29 @@ class Store {
1106
1106
  }
1107
1107
  }
1108
1108
 
1109
+ const kMaxReasonableBytes = BigInt(1) << BigInt(60);
1110
+ const kMinReasonableBytes = -kMaxReasonableBytes;
1111
+ class ExternalMemory {
1112
+ constructor(onChange) {
1113
+ this.total = BigInt(0);
1114
+ this.onChange = onChange !== null && onChange !== void 0 ? onChange : null;
1115
+ }
1116
+ adjust(changeInBytes) {
1117
+ changeInBytes = BigInt(changeInBytes);
1118
+ if (!(kMinReasonableBytes <= changeInBytes && changeInBytes < kMaxReasonableBytes)) {
1119
+ throw new RangeError(`changeInBytes ${changeInBytes} is out of reasonable range`);
1120
+ }
1121
+ const old = this.total;
1122
+ this.total += changeInBytes;
1123
+ const amount = this.total;
1124
+ const onChange = this.onChange;
1125
+ if (changeInBytes) {
1126
+ onChange === null || onChange === void 0 ? void 0 : onChange(amount, old, changeInBytes);
1127
+ }
1128
+ return amount;
1129
+ }
1130
+ }
1131
+
1109
1132
  class CleanupHookCallback {
1110
1133
  constructor(envObject, fn, arg, order) {
1111
1134
  this.envObject = envObject;
@@ -1181,7 +1204,7 @@ class NodejsWaitingRequestCounter {
1181
1204
  }
1182
1205
  }
1183
1206
  class Context {
1184
- constructor() {
1207
+ constructor(options) {
1185
1208
  this._isStopping = false;
1186
1209
  this._canCallIntoJs = true;
1187
1210
  this._suppressDestroy = false;
@@ -1202,6 +1225,7 @@ class Context {
1202
1225
  MessageChannel: _MessageChannel
1203
1226
  };
1204
1227
  this.cleanupQueue = new CleanupQueue();
1228
+ this._externalMemory = new ExternalMemory(options === null || options === void 0 ? void 0 : options.onExternalMemoryChange);
1205
1229
  if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
1206
1230
  this.refCounter = new NodejsWaitingRequestCounter();
1207
1231
  process.once('beforeExit', () => {
@@ -1240,6 +1264,9 @@ class Context {
1240
1264
  createDeferred(value) {
1241
1265
  return Deferred.create(this, value);
1242
1266
  }
1267
+ adjustAmountOfExternalAllocatedMemory(changeInBytes) {
1268
+ return this._externalMemory.adjust(changeInBytes);
1269
+ }
1243
1270
  createEnv(filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
1244
1271
  return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
1245
1272
  }
@@ -1310,8 +1337,8 @@ class Context {
1310
1337
  }
1311
1338
  }
1312
1339
  let defaultContext;
1313
- function createContext() {
1314
- return new Context();
1340
+ function createContext(options) {
1341
+ return new Context(options);
1315
1342
  }
1316
1343
  function getDefaultContext() {
1317
1344
  if (!defaultContext) {
@@ -266,6 +266,7 @@ export declare class Context {
266
266
  handleStore: HandleStore;
267
267
  private readonly refCounter?;
268
268
  private readonly cleanupQueue;
269
+ private readonly _externalMemory;
269
270
  feature: {
270
271
  supportReflect: boolean;
271
272
  supportFinalizer: boolean;
@@ -280,7 +281,7 @@ export declare class Context {
280
281
  prototype: MessageChannel;
281
282
  } | undefined;
282
283
  };
283
- constructor();
284
+ constructor(options?: ContextOptions);
284
285
  /**
285
286
  * Suppress the destroy on `beforeExit` event in Node.js.
286
287
  * Call this method if you want to keep the context and
@@ -302,6 +303,7 @@ export declare class Context {
302
303
  createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference;
303
304
  createReferenceWithFinalizer(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
304
305
  createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
306
+ adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint;
305
307
  createEnv(filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any): Env;
306
308
  createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
307
309
  getCurrentScope(): HandleScope | null;
@@ -324,7 +326,11 @@ export declare class Context {
324
326
  destroy(): void;
325
327
  }
326
328
 
327
- export declare function createContext(): Context;
329
+ export declare interface ContextOptions {
330
+ onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any;
331
+ }
332
+
333
+ export declare function createContext(options?: ContextOptions): Context;
328
334
 
329
335
  export declare class Deferred<T = any> implements IStoreValue {
330
336
  static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred;
@@ -1 +1 @@
1
- const e=new WeakMap;function t(t){return e.has(t)}const i=(()=>{function t(t){Object.setPrototypeOf(this,null),e.set(this,t)}return t.prototype=null,t})();function s(i){if(!t(i))throw new TypeError("not external");return e.get(i)}const n=function(){let e;try{e=new Function}catch(e){return!1}return"function"==typeof e}(),r=function(){if("undefined"!=typeof globalThis)return globalThis;let e=function(){return this}();if(!e&&n)try{e=new Function("return this")()}catch(e){}if(!e){if("undefined"==typeof __webpack_public_path__&&"undefined"!=typeof global)return global;if("undefined"!=typeof window)return window;if("undefined"!=typeof self)return self}return e}();class o{constructor(){this._exception=void 0,this._caught=!1}isEmpty(){return!this._caught}hasCaught(){return this._caught}exception(){return this._exception}setError(e){this._caught=!0,this._exception=e}reset(){this._caught=!1,this._exception=void 0}extractException(){const e=this._exception;return this.reset(),e}}const a=function(){var e;try{return Boolean(null===(e=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===e?void 0:e.configurable)}catch(e){return!1}}(),l="object"==typeof Reflect,c="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,h=function(){try{const e=Symbol();new WeakRef(e),(new WeakMap).set(e,void 0)}catch(e){return!1}return!0}(),u="undefined"!=typeof BigInt;const p=function(){let e;return e="undefined"!=typeof __webpack_public_path__||"undefined"!=typeof __webpack_public_path__?"undefined"!=typeof __non_webpack_require__?__non_webpack_require__:void 0:"undefined"!=typeof require?require:void 0,e}(),f="function"==typeof MessageChannel?MessageChannel:function(){try{return p("worker_threads").MessageChannel}catch(e){}}(),d="function"==typeof setImmediate?setImmediate:function(e){if("function"!=typeof e)throw new TypeError('The "callback" argument must be of type function');if(f){let t=new f;t.port1.onmessage=function(){t.port1.onmessage=null,t=void 0,e()},t.port2.postMessage(null)}else setTimeout(e,0)},_="function"==typeof Buffer?Buffer:function(){try{return p("buffer").Buffer}catch(e){}}(),v="1.8.1",g=2147483647;class y{constructor(e,t){this.id=e,this.value=t}data(){return s(this.value)}isNumber(){return"number"==typeof this.value}isBigInt(){return"bigint"==typeof this.value}isString(){return"string"==typeof this.value}isFunction(){return"function"==typeof this.value}isExternal(){return t(this.value)}isObject(){return"object"==typeof this.value&&null!==this.value}isArray(){return Array.isArray(this.value)}isArrayBuffer(){return this.value instanceof ArrayBuffer}isTypedArray(){return ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)}isBuffer(e){return!!ArrayBuffer.isView(this.value)||(null!=e||(e=_),"function"==typeof e&&e.isBuffer(this.value))}isDataView(){return this.value instanceof DataView}isDate(){return this.value instanceof Date}isPromise(){return this.value instanceof Promise}isBoolean(){return"boolean"==typeof this.value}isUndefined(){return void 0===this.value}isSymbol(){return"symbol"==typeof this.value}isNull(){return null===this.value}dispose(){this.value=void 0}}class x extends y{constructor(e,t){super(e,t)}dispose(){}}class z{constructor(){this._values=[void 0,z.UNDEFINED,z.NULL,z.FALSE,z.TRUE,z.GLOBAL],this._next=z.MIN_ID}push(e){let t;const i=this._next,s=this._values;return i<s.length?(t=s[i],t.value=e):(t=new y(i,e),s[i]=t),this._next++,t}erase(e,t){this._next=e;const i=this._values;for(let s=e;s<t;++s)i[s].dispose()}get(e){return this._values[e]}swap(e,t){const i=this._values,s=i[e];i[e]=i[t],i[e].id=Number(e),i[t]=s,s.id=Number(t)}dispose(){this._values.length=z.MIN_ID,this._next=z.MIN_ID}}z.UNDEFINED=new x(1,void 0),z.NULL=new x(2,null),z.FALSE=new x(3,!1),z.TRUE=new x(4,!0),z.GLOBAL=new x(5,r),z.MIN_ID=6;class k{constructor(e,t,i,s,n=s){this.handleStore=e,this.id=t,this.parent=i,this.child=null,null!==i&&(i.child=this),this.start=s,this.end=n,this._escapeCalled=!1,this.callbackInfo={thiz:void 0,data:0,args:void 0,fn:void 0}}add(e){const t=this.handleStore.push(e);return this.end++,t}addExternal(e){return this.add(new i(e))}dispose(){this._escapeCalled&&(this._escapeCalled=!1),this.start!==this.end&&this.handleStore.erase(this.start,this.end)}escape(e){if(this._escapeCalled)return null;if(this._escapeCalled=!0,e<this.start||e>=this.end)return null;this.handleStore.swap(e,this.start);const t=this.handleStore.get(this.start);return this.start++,this.parent.end++,t}escapeCalled(){return this._escapeCalled}}class b{constructor(){this._rootScope=new k(null,0,null,1,z.MIN_ID),this.currentScope=this._rootScope,this._values=[void 0]}get(e){return this._values[e]}openScope(e){const t=this.currentScope;let i=t.child;if(null!==i)i.start=i.end=t.end;else{const s=t.id+1;i=new k(e,s,t,t.end),this._values[s]=i}return this.currentScope=i,i}closeScope(){const e=this.currentScope;this.currentScope=e.parent,e.dispose()}dispose(){this.currentScope=this._rootScope,this._values.length=1}}class w{constructor(){this._next=null,this._prev=null}dispose(){}finalize(){}link(e){this._prev=e,this._next=e._next,null!==this._next&&(this._next._prev=this),e._next=this}unlink(){null!==this._prev&&(this._prev._next=this._next),null!==this._next&&(this._next._prev=this._prev),this._prev=null,this._next=null}static finalizeAll(e){for(;null!==e._next;)e._next.finalize()}}class S{constructor(e,t=0,i=0,s=0){this.envObject=e,this._finalizeCallback=t,this._finalizeData=i,this._finalizeHint=s,this._makeDynCall_vppp=e.makeDynCall_vppp}callback(){return this._finalizeCallback}data(){return this._finalizeData}hint(){return this._finalizeHint}resetEnv(){this.envObject=void 0}resetFinalizer(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0}callFinalizer(){const e=this._finalizeCallback,t=this._finalizeData,i=this._finalizeHint;if(this.resetFinalizer(),!e)return;const s=Number(e);this.envObject?this.envObject.callFinalizer(s,t,i):this._makeDynCall_vppp(s)(0,t,i)}dispose(){this.envObject=void 0,this._makeDynCall_vppp=void 0}}class E extends w{static create(e,t,i,s){const n=new E(e,t,i,s);return n.link(e.finalizing_reflist),n}constructor(e,t,i,s){super(),this._finalizer=new S(e,t,i,s)}data(){return this._finalizer.data()}dispose(){this._finalizer&&(this.unlink(),this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),this._finalizer=void 0,super.dispose())}finalize(){let e;this.unlink();let t=!1;try{this._finalizer.callFinalizer()}catch(i){t=!0,e=i}if(this.dispose(),t)throw e}}function m(e,t){if(!e.terminatedOrTerminating())throw t}class C{constructor(e,t,i,s,n){this.ctx=e,this.moduleApiVersion=t,this.makeDynCall_vppp=i,this.makeDynCall_vp=s,this.abort=n,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new o,this.refs=1,this.reflist=new w,this.finalizing_reflist=new w,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this.inGcFinalizer=!1,this._bindingMap=new WeakMap,this.id=0}canCallIntoJs(){return!0}terminatedOrTerminating(){return!this.canCallIntoJs()}ref(){this.refs++}unref(){this.refs--,0===this.refs&&this.dispose()}ensureHandle(e){return this.ctx.ensureHandle(e)}ensureHandleId(e){return this.ensureHandle(e).id}clearLastError(){const e=this.lastError;return 0!==e.errorCode&&(e.errorCode=0),0!==e.engineErrorCode&&(e.engineErrorCode=0),0!==e.engineReserved&&(e.engineReserved=0),0}setLastError(e,t=0,i=0){const s=this.lastError;return s.errorCode!==e&&(s.errorCode=e),s.engineErrorCode!==t&&(s.engineErrorCode=t),s.engineReserved!==i&&(s.engineReserved=i),e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e,t=m){const i=this.openHandleScopes;this.clearLastError();const s=e(this);if(i!==this.openHandleScopes&&this.abort("open_handle_scopes != open_handle_scopes_before"),this.tryCatch.hasCaught()){t(this,this.tryCatch.extractException())}return s}invokeFinalizerFromGC(e){if(this.moduleApiVersion!==g)this.enqueueFinalizer(e);else{const t=this.inGcFinalizer;this.inGcFinalizer=!0;try{e.finalize()}finally{this.inGcFinalizer=t}}}checkGCAccess(){this.moduleApiVersion===g&&this.inGcFinalizer&&this.abort("Finalizer is calling a function that may affect GC state.\nThe finalizers are run directly from GC and must not affect GC state.\nUse `node_api_post_finalizer` from inside of the finalizer to work around this issue.\nIt schedules the call as a new task in the event loop.")}enqueueFinalizer(e){-1===this.pendingFinalizers.indexOf(e)&&this.pendingFinalizers.push(e)}dequeueFinalizer(e){const t=this.pendingFinalizers.indexOf(e);-1!==t&&this.pendingFinalizers.splice(t,1)}deleteMe(){w.finalizeAll(this.finalizing_reflist),w.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id)}dispose(){0!==this.id&&(this.deleteMe(),this.finalizing_reflist.dispose(),this.reflist.dispose(),this.id=0)}initObjectBinding(e){const t={wrapped:0,tag:null};return this._bindingMap.set(e,t),t}getObjectBinding(e){return this._bindingMap.has(e)?this._bindingMap.get(e):this.initObjectBinding(e)}setInstanceData(e,t,i){this.instanceData&&this.instanceData.dispose(),this.instanceData=E.create(this,t,e,i)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class F extends C{constructor(e,t,i,s,n,r,o){super(e,i,s,n,r),this.filename=t,this.nodeBinding=o,this.destructing=!1,this.finalizationScheduled=!1}deleteMe(){this.destructing=!0,this.drainFinalizerQueue(),super.deleteMe()}canCallIntoJs(){return super.canCallIntoJs()&&this.ctx.canCallIntoJs()}triggerFatalException(e){if(this.nodeBinding)this.nodeBinding.napi.fatalException(e);else{if("object"!=typeof process||null===process||"function"!=typeof process._fatalException)throw e;process._fatalException(e)||(console.error(e),process.exit(1))}}callbackIntoModule(e,t){return this.callIntoModule(t,(t,i)=>{if(t.terminatedOrTerminating())return;const s="object"==typeof process&&null!==process,n=!!s&&Boolean(process.execArgv&&-1!==process.execArgv.indexOf("--force-node-api-uncaught-exceptions-policy"));if(t.moduleApiVersion<10&&!n&&!e){return void(s&&"function"==typeof process.emitWarning?process.emitWarning:function(e,t,i){if(e instanceof Error)console.warn(e.toString());else{const s=i?`[${i}] `:"";console.warn(`${s}${t||"Warning"}: ${e}`)}})("Uncaught N-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.","DeprecationWarning","DEP0168")}t.triggerFatalException(i)})}callFinalizer(e,t,i){this.callFinalizerInternal(1,e,t,i)}callFinalizerInternal(e,t,i,s){const n=this.makeDynCall_vppp(t),r=this.id,o=this.ctx.openScope(this);try{this.callbackIntoModule(Boolean(e),()=>{n(r,i,s)})}finally{this.ctx.closeScope(this,o)}}enqueueFinalizer(e){super.enqueueFinalizer(e),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),d(()=>{this.finalizationScheduled=!1,this.unref(),this.drainFinalizerQueue()}))}drainFinalizerQueue(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}}}function I(e,t,i,s,n,r,o){(i="number"!=typeof i?8:i)<8?i=8:i>10&&i!==g&&function(e,t){throw new Error(`${e} requires Node-API version ${t}, but this version of Node.js only supports version 10 add-ons.`)}(t,i);const a=new F(e,t,i,s,n,r,o);return e.envStore.add(a),e.addCleanupHook(a,()=>{a.unref()},0),a}class O extends Error{constructor(e){super(e);const t=new.target,i=t.prototype;if(!(this instanceof O)){const e=Object.setPrototypeOf;"function"==typeof e?e.call(Object,this,i):this.__proto__=i,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,t)}}}Object.defineProperty(O.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});class D extends O{constructor(e,t){super(`${e}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${t?` ${t}`:""}`)}}Object.defineProperty(D.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});class R extends O{constructor(e,t){super(`${e}: The current runtime does not support "Buffer". Consider using buffer polyfill to make sure \`globalThis.Buffer\` is defined.${t?` ${t}`:""}`)}}Object.defineProperty(R.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});class N{constructor(e){this._value=e}deref(){return this._value}dispose(){this._value=void 0}}class H{constructor(e){this._ref=new N(e)}setWeak(e,t){if(!c||void 0===this._ref||this._ref instanceof WeakRef)return;const i=this._ref.deref();try{H._registry.register(i,this,this);const s=new WeakRef(i);this._ref.dispose(),this._ref=s,this._param=e,this._callback=t}catch(e){if("symbol"!=typeof i)throw e}}clearWeak(){if(c&&void 0!==this._ref&&this._ref instanceof WeakRef){try{H._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0;const e=this._ref.deref();this._ref=void 0===e?e:new N(e)}}reset(){if(c)try{H._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0,this._ref instanceof N&&this._ref.dispose(),this._ref=void 0}isEmpty(){return void 0===this._ref}deref(){if(void 0!==this._ref)return this._ref.deref()}}var A;H._registry=c?new FinalizationRegistry(e=>{e._ref=void 0;const t=e._callback,i=e._param;e._callback=void 0,e._param=void 0,"function"==typeof t&&t(i)}):void 0,exports.ReferenceOwnership=void 0,(A=exports.ReferenceOwnership||(exports.ReferenceOwnership={}))[A.kRuntime=0]="kRuntime",A[A.kUserland=1]="kUserland";class j extends w{static weakCallback(e){e.persistent.reset(),e.invokeFinalizerFromGC()}static create(e,t,i,s,n,r,o){const a=new j(e,t,i,s);return e.ctx.refStore.add(a),a.link(e.reflist),a}constructor(e,t,i,s){super(),this.envObject=e,this._refcount=i,this._ownership=s;const n=e.ctx.handleStore.get(t);var r;this.canBeWeak=(r=n).isObject()||r.isFunction()||r.isSymbol(),this.persistent=new H(n.value),this.id=0,0===i&&this._setWeak()}ref(){return this.persistent.isEmpty()?0:(1===++this._refcount&&this.canBeWeak&&this.persistent.clearWeak(),this._refcount)}unref(){return this.persistent.isEmpty()||0===this._refcount?0:(0===--this._refcount&&this._setWeak(),this._refcount)}get(e=this.envObject){if(this.persistent.isEmpty())return 0;const t=this.persistent.deref();return e.ensureHandle(t).id}resetFinalizer(){}data(){return 0}refcount(){return this._refcount}ownership(){return this._ownership}callUserFinalizer(){}invokeFinalizerFromGC(){this.finalize()}_setWeak(){this.canBeWeak?this.persistent.setWeak(this,j.weakCallback):this.persistent.reset()}finalize(){this.persistent.reset();const e=this._ownership===exports.ReferenceOwnership.kRuntime;this.unlink(),this.callUserFinalizer(),e&&this.dispose()}dispose(){0!==this.id&&(this.unlink(),this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),super.dispose(),this.envObject=void 0,this.id=0)}}class B extends j{static create(e,t,i,s,n){const r=new B(e,t,i,s,n);return e.ctx.refStore.add(r),r.link(e.reflist),r}constructor(e,t,i,s,n){super(e,t,i,s),this._data=n}data(){return this._data}}class T extends j{static create(e,t,i,s,n,r,o){const a=new T(e,t,i,s,n,r,o);return e.ctx.refStore.add(a),a.link(e.finalizing_reflist),a}constructor(e,t,i,s,n,r,o){super(e,t,i,s),this._finalizer=new S(e,n,r,o)}resetFinalizer(){this._finalizer.resetFinalizer()}data(){return this._finalizer.data()}callUserFinalizer(){this._finalizer.callFinalizer()}invokeFinalizerFromGC(){this._finalizer.envObject.invokeFinalizerFromGC(this)}dispose(){this._finalizer&&(this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),super.dispose(),this._finalizer=void 0)}}class W{static create(e,t){const i=new W(e,t);return e.deferredStore.add(i),i}constructor(e,t){this.id=0,this.ctx=e,this.value=t}resolve(e){this.value.resolve(e),this.dispose()}reject(e){this.value.reject(e),this.dispose()}dispose(){this.ctx.deferredStore.remove(this.id),this.id=0,this.value=null,this.ctx=null}}class M{constructor(){this._values=[void 0],this._values.length=4,this._size=1,this._freeList=[]}add(e){let t;if(this._freeList.length)t=this._freeList.shift();else{t=this._size,this._size++;const e=this._values.length;t>=e&&(this._values.length=e+(e>>1)+16)}e.id=t,this._values[t]=e}get(e){return this._values[e]}has(e){return void 0!==this._values[e]}remove(e){const t=this._values[e];t&&(t.id=0,this._values[e]=void 0,this._freeList.push(Number(e)))}dispose(){for(let e=1;e<this._size;++e){const t=this._values[e];null==t||t.dispose()}this._values=[void 0],this._size=1,this._freeList=[]}}class L{constructor(e,t,i,s){this.envObject=e,this.fn=t,this.arg=i,this.order=s}}class P{constructor(){this._cleanupHooks=[],this._cleanupHookCounter=0}empty(){return 0===this._cleanupHooks.length}add(e,t,i){if(this._cleanupHooks.filter(s=>s.envObject===e&&s.fn===t&&s.arg===i).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new L(e,t,i,this._cleanupHookCounter++))}remove(e,t,i){for(let s=0;s<this._cleanupHooks.length;++s){const n=this._cleanupHooks[s];if(n.envObject===e&&n.fn===t&&n.arg===i)return void this._cleanupHooks.splice(s,1)}}drain(){const e=this._cleanupHooks.slice();e.sort((e,t)=>t.order-e.order);for(let t=0;t<e.length;++t){const i=e[t];"number"==typeof i.fn?i.envObject.makeDynCall_vp(i.fn)(i.arg):i.fn(i.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(i),1)}}dispose(){this._cleanupHooks.length=0,this._cleanupHookCounter=0}}class U{constructor(){this.refHandle=(new f).port1,this.count=0}increase(){0===this.count&&this.refHandle.ref&&this.refHandle.ref(),this.count++}decrease(){0!==this.count&&(1===this.count&&this.refHandle.unref&&this.refHandle.unref(),this.count--)}}class V{constructor(){this._isStopping=!1,this._canCallIntoJs=!0,this._suppressDestroy=!1,this.envStore=new M,this.scopeStore=new b,this.refStore=new M,this.deferredStore=new M,this.handleStore=new z,this.feature={supportReflect:l,supportFinalizer:c,supportWeakSymbol:h,supportBigInt:u,supportNewFunction:n,canSetFunctionName:a,setImmediate:d,Buffer:_,MessageChannel:f},this.cleanupQueue=new P,"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new U,process.once("beforeExit",()=>{this._suppressDestroy||this.destroy()}))}suppressDestroy(){this._suppressDestroy=!0}getRuntimeVersions(){return{version:v,NODE_API_SUPPORTED_VERSION_MAX:10,NAPI_VERSION_EXPERIMENTAL:g,NODE_API_DEFAULT_MODULE_API_VERSION:8}}createNotSupportWeakRefError(e,t){return new D(e,t)}createNotSupportBufferError(e,t){return new R(e,t)}createReference(e,t,i,s){return j.create(e,t,i,s)}createReferenceWithData(e,t,i,s,n){return B.create(e,t,i,s,n)}createReferenceWithFinalizer(e,t,i,s,n=0,r=0,o=0){return T.create(e,t,i,s,n,r,o)}createDeferred(e){return W.create(this,e)}createEnv(e,t,i,s,n,r){return I(this,e,t,i,s,n,r)}createTrackedFinalizer(e,t,i,s){return E.create(e,t,i,s)}getCurrentScope(){return this.scopeStore.currentScope}addToCurrentScope(e){return this.scopeStore.currentScope.add(e)}openScope(e){const t=this.scopeStore.openScope(this.handleStore);return e&&e.openHandleScopes++,t}closeScope(e,t){e&&0===e.openHandleScopes||(this.scopeStore.closeScope(),e&&e.openHandleScopes--)}ensureHandle(e){switch(e){case void 0:return z.UNDEFINED;case null:return z.NULL;case!0:return z.TRUE;case!1:return z.FALSE;case r:return z.GLOBAL}return this.addToCurrentScope(e)}addCleanupHook(e,t,i){this.cleanupQueue.add(e,t,i)}removeCleanupHook(e,t,i){this.cleanupQueue.remove(e,t,i)}runCleanup(){for(;!this.cleanupQueue.empty();)this.cleanupQueue.drain()}increaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.increase()}decreaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.decrease()}setCanCallIntoJs(e){this._canCallIntoJs=e}setStopping(e){this._isStopping=e}canCallIntoJs(){return this._canCallIntoJs&&!this._isStopping}destroy(){this.setStopping(!0),this.setCanCallIntoJs(!1),this.runCleanup()}}let G;function q(){return new V}exports.ConstHandle=x,exports.Context=V,exports.Deferred=W,exports.EmnapiError=O,exports.Env=C,exports.External=i,exports.Finalizer=S,exports.Handle=y,exports.HandleScope=k,exports.HandleStore=z,exports.NAPI_VERSION_EXPERIMENTAL=g,exports.NODE_API_DEFAULT_MODULE_API_VERSION=8,exports.NODE_API_SUPPORTED_VERSION_MAX=10,exports.NODE_API_SUPPORTED_VERSION_MIN=1,exports.NodeEnv=F,exports.NotSupportBufferError=R,exports.NotSupportWeakRefError=D,exports.Persistent=H,exports.RefTracker=w,exports.Reference=j,exports.ReferenceWithData=B,exports.ReferenceWithFinalizer=T,exports.ScopeStore=b,exports.Store=M,exports.TrackedFinalizer=E,exports.TryCatch=o,exports.createContext=q,exports.getDefaultContext=function(){return G||(G=q()),G},exports.getExternalValue=s,exports.isExternal=t,exports.isReferenceType=function(e){return"object"==typeof e&&null!==e||"function"==typeof e},exports.version=v;
1
+ const e=new WeakMap;function t(t){return e.has(t)}const i=(()=>{function t(t){Object.setPrototypeOf(this,null),e.set(this,t)}return t.prototype=null,t})();function s(i){if(!t(i))throw new TypeError("not external");return e.get(i)}const n=function(){let e;try{e=new Function}catch(e){return!1}return"function"==typeof e}(),r=function(){if("undefined"!=typeof globalThis)return globalThis;let e=function(){return this}();if(!e&&n)try{e=new Function("return this")()}catch(e){}if(!e){if("undefined"==typeof __webpack_public_path__&&"undefined"!=typeof global)return global;if("undefined"!=typeof window)return window;if("undefined"!=typeof self)return self}return e}();class o{constructor(){this._exception=void 0,this._caught=!1}isEmpty(){return!this._caught}hasCaught(){return this._caught}exception(){return this._exception}setError(e){this._caught=!0,this._exception=e}reset(){this._caught=!1,this._exception=void 0}extractException(){const e=this._exception;return this.reset(),e}}const a=function(){var e;try{return Boolean(null===(e=Object.getOwnPropertyDescriptor(Function.prototype,"name"))||void 0===e?void 0:e.configurable)}catch(e){return!1}}(),l="object"==typeof Reflect,c="undefined"!=typeof FinalizationRegistry&&"undefined"!=typeof WeakRef,h=function(){try{const e=Symbol();new WeakRef(e),(new WeakMap).set(e,void 0)}catch(e){return!1}return!0}(),u="undefined"!=typeof BigInt;const p=function(){let e;return e="undefined"!=typeof __webpack_public_path__||"undefined"!=typeof __webpack_public_path__?"undefined"!=typeof __non_webpack_require__?__non_webpack_require__:void 0:"undefined"!=typeof require?require:void 0,e}(),f="function"==typeof MessageChannel?MessageChannel:function(){try{return p("worker_threads").MessageChannel}catch(e){}}(),d="function"==typeof setImmediate?setImmediate:function(e){if("function"!=typeof e)throw new TypeError('The "callback" argument must be of type function');if(f){let t=new f;t.port1.onmessage=function(){t.port1.onmessage=null,t=void 0,e()},t.port2.postMessage(null)}else setTimeout(e,0)},_="function"==typeof Buffer?Buffer:function(){try{return p("buffer").Buffer}catch(e){}}(),v="1.10.0",g=2147483647;class y{constructor(e,t){this.id=e,this.value=t}data(){return s(this.value)}isNumber(){return"number"==typeof this.value}isBigInt(){return"bigint"==typeof this.value}isString(){return"string"==typeof this.value}isFunction(){return"function"==typeof this.value}isExternal(){return t(this.value)}isObject(){return"object"==typeof this.value&&null!==this.value}isArray(){return Array.isArray(this.value)}isArrayBuffer(){return this.value instanceof ArrayBuffer}isTypedArray(){return ArrayBuffer.isView(this.value)&&!(this.value instanceof DataView)}isBuffer(e){return!!ArrayBuffer.isView(this.value)||(null!=e||(e=_),"function"==typeof e&&e.isBuffer(this.value))}isDataView(){return this.value instanceof DataView}isDate(){return this.value instanceof Date}isPromise(){return this.value instanceof Promise}isBoolean(){return"boolean"==typeof this.value}isUndefined(){return void 0===this.value}isSymbol(){return"symbol"==typeof this.value}isNull(){return null===this.value}dispose(){this.value=void 0}}class x extends y{constructor(e,t){super(e,t)}dispose(){}}class z{constructor(){this._values=[void 0,z.UNDEFINED,z.NULL,z.FALSE,z.TRUE,z.GLOBAL],this._next=z.MIN_ID}push(e){let t;const i=this._next,s=this._values;return i<s.length?(t=s[i],t.value=e):(t=new y(i,e),s[i]=t),this._next++,t}erase(e,t){this._next=e;const i=this._values;for(let s=e;s<t;++s)i[s].dispose()}get(e){return this._values[e]}swap(e,t){const i=this._values,s=i[e];i[e]=i[t],i[e].id=Number(e),i[t]=s,s.id=Number(t)}dispose(){this._values.length=z.MIN_ID,this._next=z.MIN_ID}}z.UNDEFINED=new x(1,void 0),z.NULL=new x(2,null),z.FALSE=new x(3,!1),z.TRUE=new x(4,!0),z.GLOBAL=new x(5,r),z.MIN_ID=6;class k{constructor(e,t,i,s,n=s){this.handleStore=e,this.id=t,this.parent=i,this.child=null,null!==i&&(i.child=this),this.start=s,this.end=n,this._escapeCalled=!1,this.callbackInfo={thiz:void 0,data:0,args:void 0,fn:void 0}}add(e){const t=this.handleStore.push(e);return this.end++,t}addExternal(e){return this.add(new i(e))}dispose(){this._escapeCalled&&(this._escapeCalled=!1),this.start!==this.end&&this.handleStore.erase(this.start,this.end)}escape(e){if(this._escapeCalled)return null;if(this._escapeCalled=!0,e<this.start||e>=this.end)return null;this.handleStore.swap(e,this.start);const t=this.handleStore.get(this.start);return this.start++,this.parent.end++,t}escapeCalled(){return this._escapeCalled}}class b{constructor(){this._rootScope=new k(null,0,null,1,z.MIN_ID),this.currentScope=this._rootScope,this._values=[void 0]}get(e){return this._values[e]}openScope(e){const t=this.currentScope;let i=t.child;if(null!==i)i.start=i.end=t.end;else{const s=t.id+1;i=new k(e,s,t,t.end),this._values[s]=i}return this.currentScope=i,i}closeScope(){const e=this.currentScope;this.currentScope=e.parent,e.dispose()}dispose(){this.currentScope=this._rootScope,this._values.length=1}}class w{constructor(){this._next=null,this._prev=null}dispose(){}finalize(){}link(e){this._prev=e,this._next=e._next,null!==this._next&&(this._next._prev=this),e._next=this}unlink(){null!==this._prev&&(this._prev._next=this._next),null!==this._next&&(this._next._prev=this._prev),this._prev=null,this._next=null}static finalizeAll(e){for(;null!==e._next;)e._next.finalize()}}class m{constructor(e,t=0,i=0,s=0){this.envObject=e,this._finalizeCallback=t,this._finalizeData=i,this._finalizeHint=s,this._makeDynCall_vppp=e.makeDynCall_vppp}callback(){return this._finalizeCallback}data(){return this._finalizeData}hint(){return this._finalizeHint}resetEnv(){this.envObject=void 0}resetFinalizer(){this._finalizeCallback=0,this._finalizeData=0,this._finalizeHint=0}callFinalizer(){const e=this._finalizeCallback,t=this._finalizeData,i=this._finalizeHint;if(this.resetFinalizer(),!e)return;const s=Number(e);this.envObject?this.envObject.callFinalizer(s,t,i):this._makeDynCall_vppp(s)(0,t,i)}dispose(){this.envObject=void 0,this._makeDynCall_vppp=void 0}}class E extends w{static create(e,t,i,s){const n=new E(e,t,i,s);return n.link(e.finalizing_reflist),n}constructor(e,t,i,s){super(),this._finalizer=new m(e,t,i,s)}data(){return this._finalizer.data()}dispose(){this._finalizer&&(this.unlink(),this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),this._finalizer=void 0,super.dispose())}finalize(){let e;this.unlink();let t=!1;try{this._finalizer.callFinalizer()}catch(i){t=!0,e=i}if(this.dispose(),t)throw e}}function S(e,t){if(!e.terminatedOrTerminating())throw t}class C{constructor(e,t,i,s,n){this.ctx=e,this.moduleApiVersion=t,this.makeDynCall_vppp=i,this.makeDynCall_vp=s,this.abort=n,this.openHandleScopes=0,this.instanceData=null,this.tryCatch=new o,this.refs=1,this.reflist=new w,this.finalizing_reflist=new w,this.pendingFinalizers=[],this.lastError={errorCode:0,engineErrorCode:0,engineReserved:0},this.inGcFinalizer=!1,this._bindingMap=new WeakMap,this.id=0}canCallIntoJs(){return!0}terminatedOrTerminating(){return!this.canCallIntoJs()}ref(){this.refs++}unref(){this.refs--,0===this.refs&&this.dispose()}ensureHandle(e){return this.ctx.ensureHandle(e)}ensureHandleId(e){return this.ensureHandle(e).id}clearLastError(){const e=this.lastError;return 0!==e.errorCode&&(e.errorCode=0),0!==e.engineErrorCode&&(e.engineErrorCode=0),0!==e.engineReserved&&(e.engineReserved=0),0}setLastError(e,t=0,i=0){const s=this.lastError;return s.errorCode!==e&&(s.errorCode=e),s.engineErrorCode!==t&&(s.engineErrorCode=t),s.engineReserved!==i&&(s.engineReserved=i),e}getReturnStatus(){return this.tryCatch.hasCaught()?this.setLastError(10):0}callIntoModule(e,t=S){const i=this.openHandleScopes;this.clearLastError();const s=e(this);if(i!==this.openHandleScopes&&this.abort("open_handle_scopes != open_handle_scopes_before"),this.tryCatch.hasCaught()){t(this,this.tryCatch.extractException())}return s}invokeFinalizerFromGC(e){if(this.moduleApiVersion!==g)this.enqueueFinalizer(e);else{const t=this.inGcFinalizer;this.inGcFinalizer=!0;try{e.finalize()}finally{this.inGcFinalizer=t}}}checkGCAccess(){this.moduleApiVersion===g&&this.inGcFinalizer&&this.abort("Finalizer is calling a function that may affect GC state.\nThe finalizers are run directly from GC and must not affect GC state.\nUse `node_api_post_finalizer` from inside of the finalizer to work around this issue.\nIt schedules the call as a new task in the event loop.")}enqueueFinalizer(e){-1===this.pendingFinalizers.indexOf(e)&&this.pendingFinalizers.push(e)}dequeueFinalizer(e){const t=this.pendingFinalizers.indexOf(e);-1!==t&&this.pendingFinalizers.splice(t,1)}deleteMe(){w.finalizeAll(this.finalizing_reflist),w.finalizeAll(this.reflist),this.tryCatch.extractException(),this.ctx.envStore.remove(this.id)}dispose(){0!==this.id&&(this.deleteMe(),this.finalizing_reflist.dispose(),this.reflist.dispose(),this.id=0)}initObjectBinding(e){const t={wrapped:0,tag:null};return this._bindingMap.set(e,t),t}getObjectBinding(e){return this._bindingMap.has(e)?this._bindingMap.get(e):this.initObjectBinding(e)}setInstanceData(e,t,i){this.instanceData&&this.instanceData.dispose(),this.instanceData=E.create(this,t,e,i)}getInstanceData(){return this.instanceData?this.instanceData.data():0}}class F extends C{constructor(e,t,i,s,n,r,o){super(e,i,s,n,r),this.filename=t,this.nodeBinding=o,this.destructing=!1,this.finalizationScheduled=!1}deleteMe(){this.destructing=!0,this.drainFinalizerQueue(),super.deleteMe()}canCallIntoJs(){return super.canCallIntoJs()&&this.ctx.canCallIntoJs()}triggerFatalException(e){if(this.nodeBinding)this.nodeBinding.napi.fatalException(e);else{if("object"!=typeof process||null===process||"function"!=typeof process._fatalException)throw e;process._fatalException(e)||(console.error(e),process.exit(1))}}callbackIntoModule(e,t){return this.callIntoModule(t,(t,i)=>{if(t.terminatedOrTerminating())return;const s="object"==typeof process&&null!==process,n=!!s&&Boolean(process.execArgv&&-1!==process.execArgv.indexOf("--force-node-api-uncaught-exceptions-policy"));if(t.moduleApiVersion<10&&!n&&!e){return void(s&&"function"==typeof process.emitWarning?process.emitWarning:function(e,t,i){if(e instanceof Error)console.warn(e.toString());else{const s=i?`[${i}] `:"";console.warn(`${s}${t||"Warning"}: ${e}`)}})("Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.","DeprecationWarning","DEP0168")}t.triggerFatalException(i)})}callFinalizer(e,t,i){this.callFinalizerInternal(1,e,t,i)}callFinalizerInternal(e,t,i,s){const n=this.makeDynCall_vppp(t),r=this.id,o=this.ctx.openScope(this);try{this.callbackIntoModule(Boolean(e),()=>{n(r,i,s)})}finally{this.ctx.closeScope(this,o)}}enqueueFinalizer(e){super.enqueueFinalizer(e),this.finalizationScheduled||this.destructing||(this.finalizationScheduled=!0,this.ref(),d(()=>{this.finalizationScheduled=!1,this.unref(),this.drainFinalizerQueue()}))}drainFinalizerQueue(){for(;this.pendingFinalizers.length>0;){this.pendingFinalizers.shift().finalize()}}}function I(e,t,i,s,n,r,o){(i="number"!=typeof i?8:i)<8?i=8:i>10&&i!==g&&function(e,t){throw new Error(`${e} requires Node-API version ${t}, but this version of Node.js only supports version 10 add-ons.`)}(t,i);const a=new F(e,t,i,s,n,r,o);return e.envStore.add(a),e.addCleanupHook(a,()=>{a.unref()},0),a}class O extends Error{constructor(e){super(e);const t=new.target,i=t.prototype;if(!(this instanceof O)){const e=Object.setPrototypeOf;"function"==typeof e?e.call(Object,this,i):this.__proto__=i,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,t)}}}Object.defineProperty(O.prototype,"name",{configurable:!0,writable:!0,value:"EmnapiError"});class D extends O{constructor(e,t){super(`${e}: The current runtime does not support "FinalizationRegistry" and "WeakRef".${t?` ${t}`:""}`)}}Object.defineProperty(D.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportWeakRefError"});class R extends O{constructor(e,t){super(`${e}: The current runtime does not support "Buffer". Consider using buffer polyfill to make sure \`globalThis.Buffer\` is defined.${t?` ${t}`:""}`)}}Object.defineProperty(R.prototype,"name",{configurable:!0,writable:!0,value:"NotSupportBufferError"});class N{constructor(e){this._value=e}deref(){return this._value}dispose(){this._value=void 0}}class A{constructor(e){this._ref=new N(e)}setWeak(e,t){if(!c||void 0===this._ref||this._ref instanceof WeakRef)return;const i=this._ref.deref();try{A._registry.register(i,this,this);const s=new WeakRef(i);this._ref.dispose(),this._ref=s,this._param=e,this._callback=t}catch(e){if("symbol"!=typeof i)throw e}}clearWeak(){if(c&&void 0!==this._ref&&this._ref instanceof WeakRef){try{A._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0;const e=this._ref.deref();this._ref=void 0===e?e:new N(e)}}reset(){if(c)try{A._registry.unregister(this)}catch(e){}this._param=void 0,this._callback=void 0,this._ref instanceof N&&this._ref.dispose(),this._ref=void 0}isEmpty(){return void 0===this._ref}deref(){if(void 0!==this._ref)return this._ref.deref()}}var H;A._registry=c?new FinalizationRegistry(e=>{e._ref=void 0;const t=e._callback,i=e._param;e._callback=void 0,e._param=void 0,"function"==typeof t&&t(i)}):void 0,exports.ReferenceOwnership=void 0,(H=exports.ReferenceOwnership||(exports.ReferenceOwnership={}))[H.kRuntime=0]="kRuntime",H[H.kUserland=1]="kUserland";class j extends w{static weakCallback(e){e.persistent.reset(),e.invokeFinalizerFromGC()}static create(e,t,i,s,n,r,o){const a=new j(e,t,i,s);return e.ctx.refStore.add(a),a.link(e.reflist),a}constructor(e,t,i,s){super(),this.envObject=e,this._refcount=i,this._ownership=s;const n=e.ctx.handleStore.get(t);var r;this.canBeWeak=(r=n).isObject()||r.isFunction()||r.isSymbol(),this.persistent=new A(n.value),this.id=0,0===i&&this._setWeak()}ref(){return this.persistent.isEmpty()?0:(1===++this._refcount&&this.canBeWeak&&this.persistent.clearWeak(),this._refcount)}unref(){return this.persistent.isEmpty()||0===this._refcount?0:(0===--this._refcount&&this._setWeak(),this._refcount)}get(e=this.envObject){if(this.persistent.isEmpty())return 0;const t=this.persistent.deref();return e.ensureHandle(t).id}resetFinalizer(){}data(){return 0}refcount(){return this._refcount}ownership(){return this._ownership}callUserFinalizer(){}invokeFinalizerFromGC(){this.finalize()}_setWeak(){this.canBeWeak?this.persistent.setWeak(this,j.weakCallback):this.persistent.reset()}finalize(){this.persistent.reset();const e=this._ownership===exports.ReferenceOwnership.kRuntime;this.unlink(),this.callUserFinalizer(),e&&this.dispose()}dispose(){0!==this.id&&(this.unlink(),this.persistent.reset(),this.envObject.ctx.refStore.remove(this.id),super.dispose(),this.envObject=void 0,this.id=0)}}class B extends j{static create(e,t,i,s,n){const r=new B(e,t,i,s,n);return e.ctx.refStore.add(r),r.link(e.reflist),r}constructor(e,t,i,s,n){super(e,t,i,s),this._data=n}data(){return this._data}}class M extends j{static create(e,t,i,s,n,r,o){const a=new M(e,t,i,s,n,r,o);return e.ctx.refStore.add(a),a.link(e.finalizing_reflist),a}constructor(e,t,i,s,n,r,o){super(e,t,i,s),this._finalizer=new m(e,n,r,o)}resetFinalizer(){this._finalizer.resetFinalizer()}data(){return this._finalizer.data()}callUserFinalizer(){this._finalizer.callFinalizer()}invokeFinalizerFromGC(){this._finalizer.envObject.invokeFinalizerFromGC(this)}dispose(){this._finalizer&&(this._finalizer.envObject.dequeueFinalizer(this),this._finalizer.dispose(),super.dispose(),this._finalizer=void 0)}}class T{static create(e,t){const i=new T(e,t);return e.deferredStore.add(i),i}constructor(e,t){this.id=0,this.ctx=e,this.value=t}resolve(e){this.value.resolve(e),this.dispose()}reject(e){this.value.reject(e),this.dispose()}dispose(){this.ctx.deferredStore.remove(this.id),this.id=0,this.value=null,this.ctx=null}}class W{constructor(){this._values=[void 0],this._values.length=4,this._size=1,this._freeList=[]}add(e){let t;if(this._freeList.length)t=this._freeList.shift();else{t=this._size,this._size++;const e=this._values.length;t>=e&&(this._values.length=e+(e>>1)+16)}e.id=t,this._values[t]=e}get(e){return this._values[e]}has(e){return void 0!==this._values[e]}remove(e){const t=this._values[e];t&&(t.id=0,this._values[e]=void 0,this._freeList.push(Number(e)))}dispose(){for(let e=1;e<this._size;++e){const t=this._values[e];null==t||t.dispose()}this._values=[void 0],this._size=1,this._freeList=[]}}const L=BigInt(1)<<BigInt(60),P=-L;class U{constructor(e){this.total=BigInt(0),this.onChange=null!=e?e:null}adjust(e){if(e=BigInt(e),!(P<=e&&e<L))throw new RangeError(`changeInBytes ${e} is out of reasonable range`);const t=this.total;this.total+=e;const i=this.total,s=this.onChange;return e&&(null==s||s(i,t,e)),i}}class V{constructor(e,t,i,s){this.envObject=e,this.fn=t,this.arg=i,this.order=s}}class G{constructor(){this._cleanupHooks=[],this._cleanupHookCounter=0}empty(){return 0===this._cleanupHooks.length}add(e,t,i){if(this._cleanupHooks.filter(s=>s.envObject===e&&s.fn===t&&s.arg===i).length>0)throw new Error("Can not add same fn and arg twice");this._cleanupHooks.push(new V(e,t,i,this._cleanupHookCounter++))}remove(e,t,i){for(let s=0;s<this._cleanupHooks.length;++s){const n=this._cleanupHooks[s];if(n.envObject===e&&n.fn===t&&n.arg===i)return void this._cleanupHooks.splice(s,1)}}drain(){const e=this._cleanupHooks.slice();e.sort((e,t)=>t.order-e.order);for(let t=0;t<e.length;++t){const i=e[t];"number"==typeof i.fn?i.envObject.makeDynCall_vp(i.fn)(i.arg):i.fn(i.arg),this._cleanupHooks.splice(this._cleanupHooks.indexOf(i),1)}}dispose(){this._cleanupHooks.length=0,this._cleanupHookCounter=0}}class q{constructor(){this.refHandle=(new f).port1,this.count=0}increase(){0===this.count&&this.refHandle.ref&&this.refHandle.ref(),this.count++}decrease(){0!==this.count&&(1===this.count&&this.refHandle.unref&&this.refHandle.unref(),this.count--)}}class ${constructor(e){this._isStopping=!1,this._canCallIntoJs=!0,this._suppressDestroy=!1,this.envStore=new W,this.scopeStore=new b,this.refStore=new W,this.deferredStore=new W,this.handleStore=new z,this.feature={supportReflect:l,supportFinalizer:c,supportWeakSymbol:h,supportBigInt:u,supportNewFunction:n,canSetFunctionName:a,setImmediate:d,Buffer:_,MessageChannel:f},this.cleanupQueue=new G,this._externalMemory=new U(null==e?void 0:e.onExternalMemoryChange),"object"==typeof process&&null!==process&&"function"==typeof process.once&&(this.refCounter=new q,process.once("beforeExit",()=>{this._suppressDestroy||this.destroy()}))}suppressDestroy(){this._suppressDestroy=!0}getRuntimeVersions(){return{version:v,NODE_API_SUPPORTED_VERSION_MAX:10,NAPI_VERSION_EXPERIMENTAL:g,NODE_API_DEFAULT_MODULE_API_VERSION:8}}createNotSupportWeakRefError(e,t){return new D(e,t)}createNotSupportBufferError(e,t){return new R(e,t)}createReference(e,t,i,s){return j.create(e,t,i,s)}createReferenceWithData(e,t,i,s,n){return B.create(e,t,i,s,n)}createReferenceWithFinalizer(e,t,i,s,n=0,r=0,o=0){return M.create(e,t,i,s,n,r,o)}createDeferred(e){return T.create(this,e)}adjustAmountOfExternalAllocatedMemory(e){return this._externalMemory.adjust(e)}createEnv(e,t,i,s,n,r){return I(this,e,t,i,s,n,r)}createTrackedFinalizer(e,t,i,s){return E.create(e,t,i,s)}getCurrentScope(){return this.scopeStore.currentScope}addToCurrentScope(e){return this.scopeStore.currentScope.add(e)}openScope(e){const t=this.scopeStore.openScope(this.handleStore);return e&&e.openHandleScopes++,t}closeScope(e,t){e&&0===e.openHandleScopes||(this.scopeStore.closeScope(),e&&e.openHandleScopes--)}ensureHandle(e){switch(e){case void 0:return z.UNDEFINED;case null:return z.NULL;case!0:return z.TRUE;case!1:return z.FALSE;case r:return z.GLOBAL}return this.addToCurrentScope(e)}addCleanupHook(e,t,i){this.cleanupQueue.add(e,t,i)}removeCleanupHook(e,t,i){this.cleanupQueue.remove(e,t,i)}runCleanup(){for(;!this.cleanupQueue.empty();)this.cleanupQueue.drain()}increaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.increase()}decreaseWaitingRequestCounter(){var e;null===(e=this.refCounter)||void 0===e||e.decrease()}setCanCallIntoJs(e){this._canCallIntoJs=e}setStopping(e){this._isStopping=e}canCallIntoJs(){return this._canCallIntoJs&&!this._isStopping}destroy(){this.setStopping(!0),this.setCanCallIntoJs(!1),this.runCleanup()}}let J;function Q(e){return new $(e)}exports.ConstHandle=x,exports.Context=$,exports.Deferred=T,exports.EmnapiError=O,exports.Env=C,exports.External=i,exports.Finalizer=m,exports.Handle=y,exports.HandleScope=k,exports.HandleStore=z,exports.NAPI_VERSION_EXPERIMENTAL=g,exports.NODE_API_DEFAULT_MODULE_API_VERSION=8,exports.NODE_API_SUPPORTED_VERSION_MAX=10,exports.NODE_API_SUPPORTED_VERSION_MIN=1,exports.NodeEnv=F,exports.NotSupportBufferError=R,exports.NotSupportWeakRefError=D,exports.Persistent=A,exports.RefTracker=w,exports.Reference=j,exports.ReferenceWithData=B,exports.ReferenceWithFinalizer=M,exports.ScopeStore=b,exports.Store=W,exports.TrackedFinalizer=E,exports.TryCatch=o,exports.createContext=Q,exports.getDefaultContext=function(){return J||(J=Q()),J},exports.getExternalValue=s,exports.isExternal=t,exports.isReferenceType=function(e){return"object"==typeof e&&null!==e||"function"==typeof e},exports.version=v;
@@ -266,6 +266,7 @@ export declare class Context {
266
266
  handleStore: HandleStore;
267
267
  private readonly refCounter?;
268
268
  private readonly cleanupQueue;
269
+ private readonly _externalMemory;
269
270
  feature: {
270
271
  supportReflect: boolean;
271
272
  supportFinalizer: boolean;
@@ -280,7 +281,7 @@ export declare class Context {
280
281
  prototype: MessageChannel;
281
282
  } | undefined;
282
283
  };
283
- constructor();
284
+ constructor(options?: ContextOptions);
284
285
  /**
285
286
  * Suppress the destroy on `beforeExit` event in Node.js.
286
287
  * Call this method if you want to keep the context and
@@ -302,6 +303,7 @@ export declare class Context {
302
303
  createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference;
303
304
  createReferenceWithFinalizer(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
304
305
  createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
306
+ adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint;
305
307
  createEnv(filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any): Env;
306
308
  createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
307
309
  getCurrentScope(): HandleScope | null;
@@ -324,7 +326,11 @@ export declare class Context {
324
326
  destroy(): void;
325
327
  }
326
328
 
327
- export declare function createContext(): Context;
329
+ export declare interface ContextOptions {
330
+ onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any;
331
+ }
332
+
333
+ export declare function createContext(options?: ContextOptions): Context;
328
334
 
329
335
  export declare class Deferred<T = any> implements IStoreValue {
330
336
  static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred;
@@ -266,6 +266,7 @@ export declare class Context {
266
266
  handleStore: HandleStore;
267
267
  private readonly refCounter?;
268
268
  private readonly cleanupQueue;
269
+ private readonly _externalMemory;
269
270
  feature: {
270
271
  supportReflect: boolean;
271
272
  supportFinalizer: boolean;
@@ -280,7 +281,7 @@ export declare class Context {
280
281
  prototype: MessageChannel;
281
282
  } | undefined;
282
283
  };
283
- constructor();
284
+ constructor(options?: ContextOptions);
284
285
  /**
285
286
  * Suppress the destroy on `beforeExit` event in Node.js.
286
287
  * Call this method if you want to keep the context and
@@ -302,6 +303,7 @@ export declare class Context {
302
303
  createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference;
303
304
  createReferenceWithFinalizer(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
304
305
  createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
306
+ adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint;
305
307
  createEnv(filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any): Env;
306
308
  createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
307
309
  getCurrentScope(): HandleScope | null;
@@ -324,7 +326,11 @@ export declare class Context {
324
326
  destroy(): void;
325
327
  }
326
328
 
327
- export declare function createContext(): Context;
329
+ export declare interface ContextOptions {
330
+ onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any;
331
+ }
332
+
333
+ export declare function createContext(options?: ContextOptions): Context;
328
334
 
329
335
  export declare class Deferred<T = any> implements IStoreValue {
330
336
  static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred;
@@ -162,7 +162,7 @@ var _Buffer = typeof Buffer === 'function'
162
162
  catch (_) { }
163
163
  return undefined;
164
164
  })();
165
- var version = "1.8.1";
165
+ var version = "1.10.0";
166
166
  var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */;
167
167
  var NODE_API_SUPPORTED_VERSION_MAX = 10 /* Version.NODE_API_SUPPORTED_VERSION_MAX */;
168
168
  var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */;
@@ -738,7 +738,7 @@ var NodeEnv = /*#__PURE__*/ (function (_super) {
738
738
  console.warn("".concat(prefix).concat(type || 'Warning', ": ").concat(warning));
739
739
  }
740
740
  };
741
- warn('Uncaught N-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168');
741
+ warn('Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168');
742
742
  return;
743
743
  }
744
744
  envObject.triggerFatalException(err);
@@ -1172,6 +1172,30 @@ var Store = /*#__PURE__*/ (function () {
1172
1172
  return Store;
1173
1173
  }());
1174
1174
 
1175
+ var kMaxReasonableBytes = BigInt(1) << BigInt(60);
1176
+ var kMinReasonableBytes = -kMaxReasonableBytes;
1177
+ var ExternalMemory = /*#__PURE__*/ (function () {
1178
+ function ExternalMemory(onChange) {
1179
+ this.total = BigInt(0);
1180
+ this.onChange = onChange !== null && onChange !== void 0 ? onChange : null;
1181
+ }
1182
+ ExternalMemory.prototype.adjust = function (changeInBytes) {
1183
+ changeInBytes = BigInt(changeInBytes);
1184
+ if (!(kMinReasonableBytes <= changeInBytes && changeInBytes < kMaxReasonableBytes)) {
1185
+ throw new RangeError("changeInBytes ".concat(changeInBytes, " is out of reasonable range"));
1186
+ }
1187
+ var old = this.total;
1188
+ this.total += changeInBytes;
1189
+ var amount = this.total;
1190
+ var onChange = this.onChange;
1191
+ if (changeInBytes) {
1192
+ onChange === null || onChange === void 0 ? void 0 : onChange(amount, old, changeInBytes);
1193
+ }
1194
+ return amount;
1195
+ };
1196
+ return ExternalMemory;
1197
+ }());
1198
+
1175
1199
  var CleanupHookCallback = /*#__PURE__*/ (function () {
1176
1200
  function CleanupHookCallback(envObject, fn, arg, order) {
1177
1201
  this.envObject = envObject;
@@ -1250,7 +1274,7 @@ var NodejsWaitingRequestCounter = /*#__PURE__*/ (function () {
1250
1274
  return NodejsWaitingRequestCounter;
1251
1275
  }());
1252
1276
  var Context = /*#__PURE__*/ (function () {
1253
- function Context() {
1277
+ function Context(options) {
1254
1278
  var _this = this;
1255
1279
  this._isStopping = false;
1256
1280
  this._canCallIntoJs = true;
@@ -1272,6 +1296,7 @@ var Context = /*#__PURE__*/ (function () {
1272
1296
  MessageChannel: _MessageChannel
1273
1297
  };
1274
1298
  this.cleanupQueue = new CleanupQueue();
1299
+ this._externalMemory = new ExternalMemory(options === null || options === void 0 ? void 0 : options.onExternalMemoryChange);
1275
1300
  if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
1276
1301
  this.refCounter = new NodejsWaitingRequestCounter();
1277
1302
  process.once('beforeExit', function () {
@@ -1322,6 +1347,9 @@ var Context = /*#__PURE__*/ (function () {
1322
1347
  Context.prototype.createDeferred = function (value) {
1323
1348
  return Deferred.create(this, value);
1324
1349
  };
1350
+ Context.prototype.adjustAmountOfExternalAllocatedMemory = function (changeInBytes) {
1351
+ return this._externalMemory.adjust(changeInBytes);
1352
+ };
1325
1353
  Context.prototype.createEnv = function (filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
1326
1354
  return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
1327
1355
  };
@@ -1397,8 +1425,8 @@ var Context = /*#__PURE__*/ (function () {
1397
1425
  return Context;
1398
1426
  }());
1399
1427
  var defaultContext;
1400
- function createContext() {
1401
- return new Context();
1428
+ function createContext(options) {
1429
+ return new Context(options);
1402
1430
  }
1403
1431
  function getDefaultContext() {
1404
1432
  if (!defaultContext) {
@@ -18,6 +18,7 @@ export class Context {
18
18
  handleStore: HandleStore;
19
19
  private readonly refCounter?;
20
20
  private readonly cleanupQueue;
21
+ private readonly _externalMemory;
21
22
  feature: {
22
23
  supportReflect: boolean;
23
24
  supportFinalizer: boolean;
@@ -32,7 +33,7 @@ export class Context {
32
33
  prototype: MessageChannel;
33
34
  } | undefined;
34
35
  };
35
- constructor();
36
+ constructor(options?: ContextOptions);
36
37
  /**
37
38
  * Suppress the destroy on `beforeExit` event in Node.js.
38
39
  * Call this method if you want to keep the context and
@@ -54,6 +55,7 @@ export class Context {
54
55
  createReferenceWithData(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, data: void_p): Reference;
55
56
  createReferenceWithFinalizer(envObject: Env, handle_id: napi_value, initialRefcount: uint32_t, ownership: ReferenceOwnership, finalize_callback?: napi_finalize, finalize_data?: void_p, finalize_hint?: void_p): Reference;
56
57
  createDeferred<T = any>(value: IDeferrdValue<T>): Deferred<T>;
58
+ adjustAmountOfExternalAllocatedMemory(changeInBytes: number | bigint): bigint;
57
59
  createEnv(filename: string, moduleApiVersion: number, makeDynCall_vppp: (cb: Ptr) => (a: Ptr, b: Ptr, c: Ptr) => void, makeDynCall_vp: (cb: Ptr) => (a: Ptr) => void, abort: (msg?: string) => never, nodeBinding?: any): Env;
58
60
  createTrackedFinalizer(envObject: Env, finalize_callback: napi_finalize, finalize_data: void_p, finalize_hint: void_p): TrackedFinalizer;
59
61
  getCurrentScope(): HandleScope | null;
@@ -76,7 +78,11 @@ export class Context {
76
78
  destroy(): void;
77
79
  }
78
80
 
79
- export function createContext(): Context;
81
+ export interface ContextOptions {
82
+ onExternalMemoryChange?: (current: bigint, old: bigint, delta: bigint) => any;
83
+ }
84
+
85
+ export function createContext(options?: ContextOptions): Context;
80
86
 
81
87
  export class Deferred<T = any> implements IStoreValue {
82
88
  static create<T = any>(ctx: Context, value: IDeferrdValue<T>): Deferred;
@@ -198,7 +198,7 @@ var emnapi = (function (exports) {
198
198
  catch (_) { }
199
199
  return undefined;
200
200
  })();
201
- var version = "1.8.1";
201
+ var version = "1.10.0";
202
202
  var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */;
203
203
  var NODE_API_SUPPORTED_VERSION_MAX = 10 /* Version.NODE_API_SUPPORTED_VERSION_MAX */;
204
204
  var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */;
@@ -774,7 +774,7 @@ var emnapi = (function (exports) {
774
774
  console.warn("".concat(prefix).concat(type || 'Warning', ": ").concat(warning));
775
775
  }
776
776
  };
777
- warn('Uncaught N-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168');
777
+ warn('Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168');
778
778
  return;
779
779
  }
780
780
  envObject.triggerFatalException(err);
@@ -1208,6 +1208,30 @@ var emnapi = (function (exports) {
1208
1208
  return Store;
1209
1209
  }());
1210
1210
 
1211
+ var kMaxReasonableBytes = BigInt(1) << BigInt(60);
1212
+ var kMinReasonableBytes = -kMaxReasonableBytes;
1213
+ var ExternalMemory = /*#__PURE__*/ (function () {
1214
+ function ExternalMemory(onChange) {
1215
+ this.total = BigInt(0);
1216
+ this.onChange = onChange !== null && onChange !== void 0 ? onChange : null;
1217
+ }
1218
+ ExternalMemory.prototype.adjust = function (changeInBytes) {
1219
+ changeInBytes = BigInt(changeInBytes);
1220
+ if (!(kMinReasonableBytes <= changeInBytes && changeInBytes < kMaxReasonableBytes)) {
1221
+ throw new RangeError("changeInBytes ".concat(changeInBytes, " is out of reasonable range"));
1222
+ }
1223
+ var old = this.total;
1224
+ this.total += changeInBytes;
1225
+ var amount = this.total;
1226
+ var onChange = this.onChange;
1227
+ if (changeInBytes) {
1228
+ onChange === null || onChange === void 0 ? void 0 : onChange(amount, old, changeInBytes);
1229
+ }
1230
+ return amount;
1231
+ };
1232
+ return ExternalMemory;
1233
+ }());
1234
+
1211
1235
  var CleanupHookCallback = /*#__PURE__*/ (function () {
1212
1236
  function CleanupHookCallback(envObject, fn, arg, order) {
1213
1237
  this.envObject = envObject;
@@ -1286,7 +1310,7 @@ var emnapi = (function (exports) {
1286
1310
  return NodejsWaitingRequestCounter;
1287
1311
  }());
1288
1312
  var Context = /*#__PURE__*/ (function () {
1289
- function Context() {
1313
+ function Context(options) {
1290
1314
  var _this = this;
1291
1315
  this._isStopping = false;
1292
1316
  this._canCallIntoJs = true;
@@ -1308,6 +1332,7 @@ var emnapi = (function (exports) {
1308
1332
  MessageChannel: _MessageChannel
1309
1333
  };
1310
1334
  this.cleanupQueue = new CleanupQueue();
1335
+ this._externalMemory = new ExternalMemory(options === null || options === void 0 ? void 0 : options.onExternalMemoryChange);
1311
1336
  if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
1312
1337
  this.refCounter = new NodejsWaitingRequestCounter();
1313
1338
  process.once('beforeExit', function () {
@@ -1358,6 +1383,9 @@ var emnapi = (function (exports) {
1358
1383
  Context.prototype.createDeferred = function (value) {
1359
1384
  return Deferred.create(this, value);
1360
1385
  };
1386
+ Context.prototype.adjustAmountOfExternalAllocatedMemory = function (changeInBytes) {
1387
+ return this._externalMemory.adjust(changeInBytes);
1388
+ };
1361
1389
  Context.prototype.createEnv = function (filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
1362
1390
  return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
1363
1391
  };
@@ -1433,8 +1461,8 @@ var emnapi = (function (exports) {
1433
1461
  return Context;
1434
1462
  }());
1435
1463
  var defaultContext;
1436
- function createContext() {
1437
- return new Context();
1464
+ function createContext(options) {
1465
+ return new Context(options);
1438
1466
  }
1439
1467
  function getDefaultContext() {
1440
1468
  if (!defaultContext) {
@@ -201,7 +201,7 @@
201
201
  catch (_) { }
202
202
  return undefined;
203
203
  })();
204
- var version = "1.8.1";
204
+ var version = "1.10.0";
205
205
  var NODE_API_SUPPORTED_VERSION_MIN = 1 /* Version.NODE_API_SUPPORTED_VERSION_MIN */;
206
206
  var NODE_API_SUPPORTED_VERSION_MAX = 10 /* Version.NODE_API_SUPPORTED_VERSION_MAX */;
207
207
  var NAPI_VERSION_EXPERIMENTAL = 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */;
@@ -777,7 +777,7 @@
777
777
  console.warn("".concat(prefix).concat(type || 'Warning', ": ").concat(warning));
778
778
  }
779
779
  };
780
- warn('Uncaught N-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168');
780
+ warn('Uncaught Node-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=true to handle those exceptions properly.', 'DeprecationWarning', 'DEP0168');
781
781
  return;
782
782
  }
783
783
  envObject.triggerFatalException(err);
@@ -1211,6 +1211,30 @@
1211
1211
  return Store;
1212
1212
  }());
1213
1213
 
1214
+ var kMaxReasonableBytes = BigInt(1) << BigInt(60);
1215
+ var kMinReasonableBytes = -kMaxReasonableBytes;
1216
+ var ExternalMemory = /*#__PURE__*/ (function () {
1217
+ function ExternalMemory(onChange) {
1218
+ this.total = BigInt(0);
1219
+ this.onChange = onChange !== null && onChange !== void 0 ? onChange : null;
1220
+ }
1221
+ ExternalMemory.prototype.adjust = function (changeInBytes) {
1222
+ changeInBytes = BigInt(changeInBytes);
1223
+ if (!(kMinReasonableBytes <= changeInBytes && changeInBytes < kMaxReasonableBytes)) {
1224
+ throw new RangeError("changeInBytes ".concat(changeInBytes, " is out of reasonable range"));
1225
+ }
1226
+ var old = this.total;
1227
+ this.total += changeInBytes;
1228
+ var amount = this.total;
1229
+ var onChange = this.onChange;
1230
+ if (changeInBytes) {
1231
+ onChange === null || onChange === void 0 ? void 0 : onChange(amount, old, changeInBytes);
1232
+ }
1233
+ return amount;
1234
+ };
1235
+ return ExternalMemory;
1236
+ }());
1237
+
1214
1238
  var CleanupHookCallback = /*#__PURE__*/ (function () {
1215
1239
  function CleanupHookCallback(envObject, fn, arg, order) {
1216
1240
  this.envObject = envObject;
@@ -1289,7 +1313,7 @@
1289
1313
  return NodejsWaitingRequestCounter;
1290
1314
  }());
1291
1315
  var Context = /*#__PURE__*/ (function () {
1292
- function Context() {
1316
+ function Context(options) {
1293
1317
  var _this = this;
1294
1318
  this._isStopping = false;
1295
1319
  this._canCallIntoJs = true;
@@ -1311,6 +1335,7 @@
1311
1335
  MessageChannel: _MessageChannel
1312
1336
  };
1313
1337
  this.cleanupQueue = new CleanupQueue();
1338
+ this._externalMemory = new ExternalMemory(options === null || options === void 0 ? void 0 : options.onExternalMemoryChange);
1314
1339
  if (typeof process === 'object' && process !== null && typeof process.once === 'function') {
1315
1340
  this.refCounter = new NodejsWaitingRequestCounter();
1316
1341
  process.once('beforeExit', function () {
@@ -1361,6 +1386,9 @@
1361
1386
  Context.prototype.createDeferred = function (value) {
1362
1387
  return Deferred.create(this, value);
1363
1388
  };
1389
+ Context.prototype.adjustAmountOfExternalAllocatedMemory = function (changeInBytes) {
1390
+ return this._externalMemory.adjust(changeInBytes);
1391
+ };
1364
1392
  Context.prototype.createEnv = function (filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding) {
1365
1393
  return newEnv(this, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding);
1366
1394
  };
@@ -1436,8 +1464,8 @@
1436
1464
  return Context;
1437
1465
  }());
1438
1466
  var defaultContext;
1439
- function createContext() {
1440
- return new Context();
1467
+ function createContext(options) {
1468
+ return new Context(options);
1441
1469
  }
1442
1470
  function getDefaultContext() {
1443
1471
  if (!defaultContext) {