@volter/tabnode 0.5.27 → 0.5.29

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/dist/index.mjs CHANGED
@@ -6202,99 +6202,85 @@ const bufferBinding = {
6202
6202
  setBufferPrototype,
6203
6203
  createFromString
6204
6204
  };
6205
- class AsyncResource {
6206
- constructor(_type2, _options2) {
6207
- }
6208
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6209
- runInAsyncScope(fn, thisArg, ...args) {
6210
- return fn.apply(thisArg, args);
6211
- }
6212
- emitDestroy() {
6213
- return this;
6214
- }
6215
- asyncId() {
6216
- return 0;
6217
- }
6218
- triggerAsyncId() {
6219
- return 0;
6220
- }
6221
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6222
- static bind(fn, _type2) {
6223
- return fn;
6205
+ const ROOT_FRAME = /* @__PURE__ */ new Map();
6206
+ let currentFrame = ROOT_FRAME;
6207
+ const nativeQueueMicrotask = globalThis.queueMicrotask.bind(globalThis);
6208
+ let resetQueued = false;
6209
+ const resetFrame = () => {
6210
+ resetQueued = false;
6211
+ currentFrame = ROOT_FRAME;
6212
+ };
6213
+ const resumeFrame = (frame) => {
6214
+ if (frame === currentFrame) return;
6215
+ currentFrame = frame;
6216
+ if (!resetQueued) {
6217
+ resetQueued = true;
6218
+ nativeQueueMicrotask(resetFrame);
6219
+ }
6220
+ };
6221
+ const withFrame = (frame, callback) => {
6222
+ const previous = currentFrame;
6223
+ currentFrame = frame;
6224
+ try {
6225
+ return callback();
6226
+ } finally {
6227
+ currentFrame = previous;
6224
6228
  }
6225
- }
6226
- const __substrateAsyncLocalStorages = /* @__PURE__ */ new Set();
6229
+ };
6227
6230
  class AsyncLocalStorage {
6228
- constructor() {
6229
- __publicField(this, "store");
6230
- __substrateAsyncLocalStorages.add(this);
6231
- }
6232
6231
  static snapshot() {
6233
- const captured = /* @__PURE__ */ new Map();
6234
- for (const storage of __substrateAsyncLocalStorages) captured.set(storage, storage.store);
6235
- return (callback, ...args) => {
6236
- const previous = /* @__PURE__ */ new Map();
6237
- for (const [storage, store] of captured) {
6238
- previous.set(storage, storage.store);
6239
- storage.store = store;
6240
- }
6241
- try {
6242
- return callback(...args);
6243
- } finally {
6244
- for (const [storage, store] of previous) storage.store = store;
6245
- }
6246
- };
6232
+ const captured = currentFrame;
6233
+ return (callback, ...args) => withFrame(captured, () => callback(...args));
6247
6234
  }
6248
6235
  static bind(callback) {
6249
6236
  const snapshot = AsyncLocalStorage.snapshot();
6250
6237
  return (...args) => snapshot(callback, ...args);
6251
6238
  }
6252
6239
  disable() {
6240
+ if (!currentFrame.has(this)) return;
6241
+ const next = new Map(currentFrame);
6242
+ next.delete(this);
6243
+ currentFrame = next;
6253
6244
  }
6254
6245
  getStore() {
6255
- return this.store;
6246
+ return currentFrame.get(this);
6256
6247
  }
6257
- /**
6258
- * A store entered for an async callback used to be left the moment the
6259
- * callback returned its promise, so the first `await` inside a Server Action
6260
- * lost Next's request store and `cookies()` was "outside a request scope". A
6261
- * tab has no async_hooks and no AsyncContext, and an `await` of a native
6262
- * promise bypasses any `then` a patch could install, so the continuations
6263
- * cannot be followed. What can be done honestly is keep the store current
6264
- * until the callback's promise settles: exact for one run at a time, and
6265
- * last-entered-wins where two async runs overlap.
6266
- */
6267
6248
  run(store, callback, ...args) {
6268
- const prev = this.store;
6269
- this.store = store;
6270
- let result;
6271
- try {
6272
- result = callback(...args);
6273
- } catch (error) {
6274
- this.store = prev;
6275
- throw error;
6276
- }
6277
- if (result && typeof result.then === "function") {
6278
- const restore = () => {
6279
- if (this.store === store) this.store = prev;
6280
- };
6281
- result.then(restore, restore);
6282
- return result;
6283
- }
6284
- this.store = prev;
6285
- return result;
6249
+ const next = new Map(currentFrame);
6250
+ next.set(this, store);
6251
+ return withFrame(next, () => callback(...args));
6286
6252
  }
6287
6253
  exit(callback) {
6288
- const prev = this.store;
6289
- this.store = void 0;
6290
- try {
6291
- return callback();
6292
- } finally {
6293
- this.store = prev;
6294
- }
6254
+ const next = new Map(currentFrame);
6255
+ next.delete(this);
6256
+ return withFrame(next, callback);
6295
6257
  }
6296
6258
  enterWith(store) {
6297
- this.store = store;
6259
+ const next = new Map(currentFrame);
6260
+ next.set(this, store);
6261
+ currentFrame = next;
6262
+ }
6263
+ }
6264
+ class AsyncResource {
6265
+ constructor(_type2, _options2) {
6266
+ __publicField(this, "frame", currentFrame);
6267
+ }
6268
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6269
+ runInAsyncScope(fn, thisArg, ...args) {
6270
+ return withFrame(this.frame, () => fn.apply(thisArg, args));
6271
+ }
6272
+ emitDestroy() {
6273
+ return this;
6274
+ }
6275
+ asyncId() {
6276
+ return 0;
6277
+ }
6278
+ triggerAsyncId() {
6279
+ return 0;
6280
+ }
6281
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6282
+ static bind(fn, _type2) {
6283
+ return AsyncLocalStorage.bind(fn);
6298
6284
  }
6299
6285
  }
6300
6286
  forGuestRealm(() => {
@@ -6321,6 +6307,14 @@ forGuestRealm(() => {
6321
6307
  };
6322
6308
  takeFromHost(Promise.prototype, "then", carriedThen);
6323
6309
  takeFromHost(globalThis, "__substrateCarried", carried);
6310
+ takeFromHost(globalThis, "__substrateContext", () => currentFrame);
6311
+ takeFromHost(globalThis, "__substrateResume", (frame, value) => {
6312
+ resumeFrame(frame);
6313
+ return value;
6314
+ });
6315
+ takeFromHost(globalThis, "__substrateRestore", (frame) => {
6316
+ resumeFrame(frame);
6317
+ });
6324
6318
  });
6325
6319
  function createHook(_callbacks) {
6326
6320
  return {
@@ -29720,7 +29714,7 @@ Parser.acorn = {
29720
29714
  function parse3(input, options) {
29721
29715
  return Parser.parse(input, options);
29722
29716
  }
29723
- class Script {
29717
+ let Script$1 = class Script {
29724
29718
  constructor(code2, _options2) {
29725
29719
  __publicField(this, "code");
29726
29720
  this.code = code2;
@@ -29783,7 +29777,7 @@ class Script {
29783
29777
  createCachedData() {
29784
29778
  return Buffer.from("");
29785
29779
  }
29786
- }
29780
+ };
29787
29781
  function createContext(contextObject, _options2) {
29788
29782
  return contextObject || {};
29789
29783
  }
@@ -29794,7 +29788,7 @@ function runInThisContext(code, _options) {
29794
29788
  return eval(code);
29795
29789
  }
29796
29790
  function runInNewContext(code2, contextObject, _options2) {
29797
- const script = new Script(code2);
29791
+ const script = new Script$1(code2);
29798
29792
  return script.runInNewContext(contextObject);
29799
29793
  }
29800
29794
  function runInContext(code2, context2, _options2) {
@@ -29832,7 +29826,7 @@ class SyntheticModule extends Module {
29832
29826
  }
29833
29827
  }
29834
29828
  const vm = {
29835
- Script,
29829
+ Script: Script$1,
29836
29830
  createContext,
29837
29831
  isContext,
29838
29832
  runInThisContext,
@@ -29846,7 +29840,7 @@ const vm = {
29846
29840
  const vmShim = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
29847
29841
  __proto__: null,
29848
29842
  Module,
29849
- Script,
29843
+ Script: Script$1,
29850
29844
  SourceTextModule,
29851
29845
  SyntheticModule,
29852
29846
  compileFunction,
@@ -34343,7 +34337,24 @@ function readPackageJson(cwd) {
34343
34337
  }
34344
34338
  }
34345
34339
  async function handleNpmRun(args, ctx) {
34346
- const scriptName = args[0];
34340
+ let scriptName;
34341
+ let silent = false;
34342
+ let ifPresent = false;
34343
+ const passed = [];
34344
+ for (let index2 = 0; index2 < args.length; index2++) {
34345
+ const arg = args[index2];
34346
+ if (arg === "--") {
34347
+ if (scriptName !== void 0) passed.push(...args.slice(index2 + 1));
34348
+ break;
34349
+ }
34350
+ if (arg.startsWith("-") && arg !== "-") {
34351
+ if (arg === "--silent" || arg === "-s" || arg === "--quiet" || arg === "-q" || arg === "--loglevel=silent") silent = true;
34352
+ else if (arg === "--if-present") ifPresent = true;
34353
+ continue;
34354
+ }
34355
+ if (scriptName === void 0) scriptName = arg;
34356
+ else passed.push(arg);
34357
+ }
34347
34358
  if (!scriptName) {
34348
34359
  return listScripts(ctx);
34349
34360
  }
@@ -34353,6 +34364,7 @@ async function handleNpmRun(args, ctx) {
34353
34364
  const scripts = pkgJson.scripts || {};
34354
34365
  const scriptCommand = scripts[scriptName];
34355
34366
  if (!scriptCommand) {
34367
+ if (ifPresent) return { stdout: "", stderr: "", exitCode: 0 };
34356
34368
  const available = Object.keys(scripts);
34357
34369
  let msg2 = `npm ERR! Missing script: "${scriptName}"
34358
34370
  `;
@@ -34385,7 +34397,7 @@ async function handleNpmRun(args, ctx) {
34385
34397
  const label = `${pkgJson.name || ""}@${pkgJson.version || ""}`;
34386
34398
  const preScript = scripts[`pre${scriptName}`];
34387
34399
  if (preScript) {
34388
- allStderr += `
34400
+ if (!silent) allStderr += `
34389
34401
  > ${label} pre${scriptName}
34390
34402
  > ${preScript}
34391
34403
 
@@ -34397,12 +34409,13 @@ async function handleNpmRun(args, ctx) {
34397
34409
  return { stdout: allStdout, stderr: allStderr, exitCode: preResult.exitCode };
34398
34410
  }
34399
34411
  }
34400
- allStderr += `
34412
+ const command = passed.length > 0 ? `${scriptCommand} ${passed.map((arg) => /^[\w@%+=:,./-]+$/.test(arg) ? arg : `'${arg.replace(/'/g, `'\\''`)}'`).join(" ")}` : scriptCommand;
34413
+ if (!silent) allStderr += `
34401
34414
  > ${label} ${scriptName}
34402
- > ${scriptCommand}
34415
+ > ${command}
34403
34416
 
34404
34417
  `;
34405
- const mainResult = await ctx.exec(scriptCommand, { cwd: ctx.cwd, env: npmEnv });
34418
+ const mainResult = await ctx.exec(command, { cwd: ctx.cwd, env: npmEnv, ...typeof ctx.stdin === "string" ? { stdin: ctx.stdin } : {} });
34406
34419
  allStdout += mainResult.stdout;
34407
34420
  allStderr += mainResult.stderr;
34408
34421
  if (mainResult.exitCode !== 0) {
@@ -34410,7 +34423,7 @@ async function handleNpmRun(args, ctx) {
34410
34423
  }
34411
34424
  const postScript = scripts[`post${scriptName}`];
34412
34425
  if (postScript) {
34413
- allStderr += `
34426
+ if (!silent) allStderr += `
34414
34427
  > ${label} post${scriptName}
34415
34428
  > ${postScript}
34416
34429
 
@@ -37937,6 +37950,22 @@ function __substrateGuestConstructor(Constructor, process2) {
37937
37950
  return __substrateFunctionScope(__substrateGuestGlobal(process2), String(compiled));
37938
37951
  } });
37939
37952
  }
37953
+ const __substrateScriptScope = Function("__substrateScriptGlobals", "__substrateScriptSource", "with (__substrateScriptGlobals) { return eval(__substrateScriptSource); }");
37954
+ const __substrateGuestVms = /* @__PURE__ */ new WeakMap();
37955
+ function __substrateGuestVm(process2) {
37956
+ let vm2 = __substrateGuestVms.get(process2);
37957
+ if (vm2) return vm2;
37958
+ const run = (code2) => __substrateScriptScope(__substrateGuestGlobal(process2), String(code2));
37959
+ class Script2 extends Script$1 {
37960
+ runInThisContext(_options2) {
37961
+ return run(this.code);
37962
+ }
37963
+ }
37964
+ vm2 = { ...vmShim, Script: Script2, runInThisContext: (code2, _options2) => run(code2), default: void 0 };
37965
+ vm2.default = vm2;
37966
+ __substrateGuestVms.set(process2, vm2);
37967
+ return vm2;
37968
+ }
37940
37969
  function __substrateModuleTypes(code2, resolvedPath, format2, process2) {
37941
37970
  const typescript = format2 === void 0 ? /[.](?:ts|mts|cts)$/u.test(resolvedPath) && !resolvedPath.endsWith(".d.ts") : format2 === "typescript" || format2 === "commonjs-typescript" || format2 === "module-typescript";
37942
37971
  if (!typescript) return code2;
@@ -38149,6 +38178,72 @@ function collectDirectEval(node, replacements) {
38149
38178
  replacements.push([source.start, source.start, "__substrateEvalSource("]);
38150
38179
  replacements.push([source.end, source.end, ")"]);
38151
38180
  }
38181
+ const ASYNC_FRAME = "__substrateAsyncFrame";
38182
+ const FOLLOW_MARK = "/*substrate*/";
38183
+ const FOLLOW_TAKE = `const ${ASYNC_FRAME}=__substrateContext();`;
38184
+ const FOLLOW_RESTORE = `__substrateRestore(${ASYNC_FRAME});`;
38185
+ const FOLLOW_RESUME_FRAMED = `__substrateResume(${ASYNC_FRAME},`;
38186
+ const FOLLOW_RESUME_TAKEN = "__substrateResume(__substrateContext(),";
38187
+ function __substrateFollowAwaits(code2) {
38188
+ if (!/\bawait\b/.test(code2)) return code2;
38189
+ let ast;
38190
+ try {
38191
+ ast = parse3(code2, { ecmaVersion: "latest", sourceType: "script", allowReturnOutsideFunction: true, allowHashBang: true, allowAwaitOutsideFunction: true });
38192
+ } catch {
38193
+ return code2;
38194
+ }
38195
+ const edits = [];
38196
+ const insert = (at2, text) => {
38197
+ edits.push([at2, at2, text]);
38198
+ };
38199
+ const isFunction = (node) => node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
38200
+ const visit = (node, framed, parent) => {
38201
+ if (isFunction(node)) {
38202
+ framed = node.async && node.body.type === "BlockStatement";
38203
+ if (framed) {
38204
+ const directives = node.body.body.filter((statement) => statement.directive !== void 0);
38205
+ const at2 = directives.length ? directives[directives.length - 1].end : node.body.start + 1;
38206
+ insert(at2, FOLLOW_TAKE);
38207
+ }
38208
+ } else if (node.type === "AwaitExpression") {
38209
+ insert(node.start, framed ? FOLLOW_RESUME_FRAMED : FOLLOW_RESUME_TAKEN);
38210
+ insert(node.end, `${FOLLOW_MARK})`);
38211
+ } else if (framed && node.type === "CatchClause") {
38212
+ insert(node.body.start + 1, FOLLOW_RESTORE);
38213
+ } else if (framed && node.type === "TryStatement" && node.finalizer) {
38214
+ insert(node.finalizer.start + 1, FOLLOW_RESTORE);
38215
+ } else if (framed && node.type === "ForOfStatement" && node.await) {
38216
+ const whole = (parent == null ? void 0 : parent.type) === "LabeledStatement" ? parent : node;
38217
+ insert(whole.start, `{${FOLLOW_MARK}`);
38218
+ insert(whole.end, `;${FOLLOW_RESTORE}${FOLLOW_MARK}}`);
38219
+ if (node.body.type === "BlockStatement") insert(node.body.start + 1, FOLLOW_RESTORE);
38220
+ else {
38221
+ insert(node.body.start, `{${FOLLOW_MARK}${FOLLOW_RESTORE}`);
38222
+ insert(node.body.end, `${FOLLOW_MARK}}`);
38223
+ }
38224
+ }
38225
+ for (const key of Object.keys(node)) {
38226
+ if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "range") continue;
38227
+ const child = node[key];
38228
+ if (!child || typeof child !== "object") continue;
38229
+ if (Array.isArray(child)) {
38230
+ for (const item of child) if (item && typeof item.type === "string") visit(item, framed, node);
38231
+ } else if (typeof child.type === "string") visit(child, framed, node);
38232
+ }
38233
+ };
38234
+ visit(ast, false, void 0);
38235
+ return edits.length ? applyReplacements(code2, edits) : code2;
38236
+ }
38237
+ function __substrateUnfollowAwaits(source) {
38238
+ if (!source.includes("__substrate")) return source;
38239
+ return source.replaceAll(`;${FOLLOW_RESTORE}${FOLLOW_MARK}}`, "").replaceAll(`{${FOLLOW_MARK}${FOLLOW_RESTORE}`, "").replaceAll(`{${FOLLOW_MARK}`, "").replaceAll(`${FOLLOW_MARK}}`, "").replaceAll(`${FOLLOW_MARK})`, "").replaceAll(FOLLOW_TAKE, "").replaceAll(FOLLOW_RESTORE, "").replaceAll(FOLLOW_RESUME_FRAMED, "").replaceAll(FOLLOW_RESUME_TAKEN, "");
38240
+ }
38241
+ forGuestRealm(() => {
38242
+ const native = Function.prototype.toString;
38243
+ takeFromHost(Function.prototype, "toString", function toString2() {
38244
+ return __substrateUnfollowAwaits(native.call(this));
38245
+ });
38246
+ });
38152
38247
  function applyReplacements(code2, replacements) {
38153
38248
  replacements.sort((a, b) => b[0] - a[0] || b[1] - a[1]);
38154
38249
  let out = code2;
@@ -38170,12 +38265,12 @@ function __substratePrepareBody(rawCode, resolvedPath, format2, process2) {
38170
38265
  const lowered = transformEsmToCjs(code2, resolvedPath);
38171
38266
  code2 = lowered === code2 ? code2 : `${__substrateModuleMarker}"use strict";${lowered}`;
38172
38267
  } else {
38173
- code2 = transformDynamicImportsRegex(code2);
38268
+ code2 = __substrateRewriteDynamicImportsInScript(code2);
38174
38269
  }
38175
- return code2;
38270
+ return __substrateFollowAwaits(code2);
38176
38271
  }
38177
38272
  const PREPARED_MODULES_DIR = "/.tabnode/prepared";
38178
- const PREPARED_MODULES_FORMAT = "tabnode-prepared-1";
38273
+ const PREPARED_MODULES_FORMAT = "tabnode-prepared-2";
38179
38274
  function preparedModuleKey(rawCode, resolvedPath) {
38180
38275
  var _a2;
38181
38276
  const extension = (_a2 = /\.(js|cjs|mjs)$/u.exec(resolvedPath)) == null ? void 0 : _a2[1];
@@ -38320,6 +38415,17 @@ async function __substrateImportChain(hooks, id, parentURL, moduleRequire) {
38320
38415
  }));
38321
38416
  return doors.__loadFromURL(resolved.url, loaded2.format ?? resolved.format, loaded2.source ?? void 0);
38322
38417
  }
38418
+ function createImportMeta(moduleRequire, url2, dirname2, filename) {
38419
+ const resolve2 = (specifier, parent) => {
38420
+ const id = typeof specifier === "string" ? specifier : String(specifier);
38421
+ const base = parent === void 0 ? url2 : String(parent);
38422
+ if (id.startsWith("./") || id.startsWith("../") || id.startsWith("/")) return new URL(id, base).href;
38423
+ if (/^[a-zA-Z][a-zA-Z\d+.-]*:/.test(id)) return id.startsWith("node:") ? id : new URL(id).href;
38424
+ if (Object.prototype.hasOwnProperty.call(builtinModules, id)) return `node:${id}`;
38425
+ return "file://" + moduleRequire.resolve(id);
38426
+ };
38427
+ return { url: url2, dirname: dirname2, filename, resolve: resolve2 };
38428
+ }
38323
38429
  function createDynamicImport(moduleRequire, process2, parentURL) {
38324
38430
  return async (specifier) => {
38325
38431
  var _a2;
@@ -39288,7 +39394,7 @@ function createRequire(vfs2, fsShim, process2, currentDir, moduleCache, options,
39288
39394
  dirname2,
39289
39395
  process2,
39290
39396
  consoleWrapper,
39291
- { url: importMetaUrl, dirname: dirname2, filename: resolvedPath },
39397
+ createImportMeta(moduleRequire, importMetaUrl, dirname2, resolvedPath),
39292
39398
  dynamicImport,
39293
39399
  __substrateGuestGlobal,
39294
39400
  __substrateGuestConstructor
@@ -39391,6 +39497,9 @@ function createRequire(vfs2, fsShim, process2, currentDir, moduleCache, options,
39391
39497
  if (id === "module") {
39392
39498
  return __substrateModule();
39393
39499
  }
39500
+ if (id === "vm") {
39501
+ return __substrateGuestVm(process2);
39502
+ }
39394
39503
  if (id === "wasi") {
39395
39504
  return __substrateGuestWasi(fsShim, process2);
39396
39505
  }
@@ -39613,7 +39722,7 @@ class Runtime {
39613
39722
  const lowered = transformEsmToCjs(code2, filename);
39614
39723
  code2 = lowered === code2 ? code2 : `${__substrateModuleMarker}"use strict";${lowered}`;
39615
39724
  } else {
39616
- code2 = transformDynamicImportsRegex(code2);
39725
+ code2 = __substrateRewriteDynamicImportsInScript(code2);
39617
39726
  }
39618
39727
  try {
39619
39728
  const importMetaUrl = "file://" + filename;
@@ -39644,7 +39753,7 @@ class Runtime {
39644
39753
  dirname$1,
39645
39754
  this.process,
39646
39755
  consoleWrapper,
39647
- { url: importMetaUrl, dirname: dirname$1, filename },
39756
+ createImportMeta(require2, importMetaUrl, dirname$1, filename),
39648
39757
  dynamicImport,
39649
39758
  __substrateGuestGlobal,
39650
39759
  __substrateGuestConstructor
@@ -40120,7 +40229,7 @@ class WorkerRuntime {
40120
40229
  this.worker = new Worker(
40121
40230
  new URL(
40122
40231
  /* @vite-ignore */
40123
- "/assets/runtime-worker-DPvtXRd8.js",
40232
+ "/assets/runtime-worker-Dv_vTkXr.js",
40124
40233
  import.meta.url
40125
40234
  ),
40126
40235
  { type: "module" }
@@ -1,35 +1,26 @@
1
1
  /**
2
- * async_hooks shim - Async tracking is not available in browser
2
+ * async_hooks shim: AsyncLocalStorage and AsyncResource carry context the way
3
+ * Node's do; the hooks themselves are not available in a browser.
3
4
  */
4
- export declare class AsyncResource {
5
- constructor(_type: string, _options?: object);
6
- runInAsyncScope<T>(fn: (...args: any[]) => T, thisArg?: unknown, ...args: any[]): T;
7
- emitDestroy(): this;
8
- asyncId(): number;
9
- triggerAsyncId(): number;
10
- static bind<T extends (...args: any[]) => any>(fn: T, _type?: string): T;
11
- }
12
5
  export declare class AsyncLocalStorage<T> {
13
- private store;
14
- constructor();
15
6
  static snapshot(): (callback: (...args: unknown[]) => unknown, ...args: unknown[]) => unknown;
16
7
  static bind(callback: (...args: unknown[]) => unknown): (...args: unknown[]) => unknown;
17
8
  disable(): void;
18
9
  getStore(): T | undefined;
19
- /**
20
- * A store entered for an async callback used to be left the moment the
21
- * callback returned its promise, so the first `await` inside a Server Action
22
- * lost Next's request store and `cookies()` was "outside a request scope". A
23
- * tab has no async_hooks and no AsyncContext, and an `await` of a native
24
- * promise bypasses any `then` a patch could install, so the continuations
25
- * cannot be followed. What can be done honestly is keep the store current
26
- * until the callback's promise settles: exact for one run at a time, and
27
- * last-entered-wins where two async runs overlap.
28
- */
29
10
  run<R>(store: T, callback: (...args: unknown[]) => R, ...args: unknown[]): R;
30
11
  exit<R>(callback: () => R): R;
31
12
  enterWith(store: T): void;
32
13
  }
14
+ /** Runs its callbacks in the context it was made in, as Node's does. */
15
+ export declare class AsyncResource {
16
+ private readonly frame;
17
+ constructor(_type: string, _options?: object);
18
+ runInAsyncScope<T>(fn: (...args: any[]) => T, thisArg?: unknown, ...args: any[]): T;
19
+ emitDestroy(): this;
20
+ asyncId(): number;
21
+ triggerAsyncId(): number;
22
+ static bind<T extends (...args: any[]) => any>(fn: T, _type?: string): T;
23
+ }
33
24
  export interface AsyncHook {
34
25
  enable(): this;
35
26
  disable(): this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/tabnode",
3
- "version": "0.5.27",
3
+ "version": "0.5.29",
4
4
  "description": "Node's own library, in a browser tab.",
5
5
  "type": "module",
6
6
  "license": "MIT",