@netlify/plugin-nextjs 4.40.1 → 4.40.2
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/lib/helpers/edge.js +1 -0
- package/lib/templates/vendor.js +20 -0
- package/package.json +7 -4
- package/src/templates/edge/next-dev.js +3 -3
- package/src/templates/edge/shims.js +6 -6
- package/src/templates/edge-shared/next-utils.ts +3 -3
- package/src/templates/edge-shared/utils.ts +1 -1
- package/src/templates/vendor/deno.land/std@0.134.0/fmt/colors.ts +536 -0
- package/src/templates/vendor/deno.land/std@0.134.0/testing/_diff.ts +360 -0
- package/src/templates/vendor/deno.land/std@0.134.0/testing/asserts.ts +866 -0
- package/src/templates/vendor/deno.land/std@0.175.0/_util/asserts.ts +25 -0
- package/src/templates/vendor/deno.land/std@0.175.0/_util/os.ts +23 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/abortable.ts +149 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/deadline.ts +30 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/debounce.ts +79 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/deferred.ts +48 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/delay.ts +67 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/mod.ts +18 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/mux_async_iterator.ts +97 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/pool.ts +95 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/retry.ts +81 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/tee.ts +100 -0
- package/src/templates/vendor/deno.land/std@0.175.0/bytes/index_of_needle.ts +49 -0
- package/src/templates/vendor/deno.land/std@0.175.0/crypto/timing_safe_equal.ts +29 -0
- package/src/templates/vendor/deno.land/std@0.175.0/datetime/to_imf.ts +45 -0
- package/src/templates/vendor/deno.land/std@0.175.0/encoding/base64.ts +144 -0
- package/src/templates/vendor/deno.land/std@0.175.0/encoding/base64url.ts +70 -0
- package/src/templates/vendor/deno.land/std@0.175.0/flags/mod.ts +785 -0
- package/src/templates/vendor/deno.land/std@0.175.0/fmt/colors.ts +569 -0
- package/src/templates/vendor/deno.land/std@0.175.0/fmt/printf.ts +939 -0
- package/src/templates/vendor/deno.land/std@0.175.0/http/cookie.ts +403 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_core.ts +77 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_events.d.ts +848 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_events.mjs +1033 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_global.d.ts +66 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_next_tick.ts +173 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_process/exiting.ts +4 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_process/process.ts +131 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_process/stdio.mjs +7 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_process/streams.mjs +146 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_stream.d.ts +1488 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_stream.mjs +746 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_util/_util_callbackify.ts +129 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_utils.ts +206 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/assert.ts +940 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/assertion_error.ts +579 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/async_hooks.ts +331 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/buffer.ts +13 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/events.ts +14 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/buffer.d.ts +2074 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/buffer.mjs +2607 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/crypto/_keys.ts +16 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/crypto/constants.ts +5 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/error_codes.ts +7 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/errors.ts +2867 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/fixed_queue.ts +123 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/hide_stack_frames.ts +16 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/net.ts +95 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/normalize_encoding.mjs +72 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/options.ts +45 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/primordials.mjs +30 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/process/per_thread.mjs +272 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/readline/callbacks.mjs +137 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/readline/utils.mjs +580 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/destroy.mjs +320 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/end-of-stream.mjs +229 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/utils.mjs +242 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/comparisons.ts +669 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/debuglog.ts +118 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/inspect.mjs +2237 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/types.ts +113 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util.mjs +143 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/validators.mjs +317 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_libuv_winerror.ts +229 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_listen.ts +16 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_node.ts +18 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_timingSafeEqual.ts +12 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_utils.ts +86 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_winerror.ts +16873 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/ares.ts +66 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/async_wrap.ts +152 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/buffer.ts +130 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/cares_wrap.ts +541 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/config.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/connection_wrap.ts +80 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/constants.ts +900 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/contextify.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/credentials.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/crypto.ts +14 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/errors.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs_dir.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs_event_wrap.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/handle_wrap.ts +50 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/heap_utils.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/http_parser.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/icu.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/inspector.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/js_stream.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/messaging.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/mod.ts +108 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/module_wrap.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/native_module.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/natives.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/node_file.ts +84 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/node_options.ts +39 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/options.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/os.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/performance.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/pipe_wrap.ts +392 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/process_methods.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/report.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/serdes.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/signal_wrap.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/spawn_sync.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/stream_wrap.ts +354 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/string_decoder.ts +15 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/symbols.ts +27 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/task_queue.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tcp_wrap.ts +488 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/timers.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tls_wrap.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/trace_events.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tty_wrap.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/types.ts +186 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/udp_wrap.ts +496 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/url.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/util.ts +126 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/uv.ts +437 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/v8.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/worker.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/zlib.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/process.ts +705 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/stream.ts +37 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/string_decoder.ts +337 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/util/types.ts +4 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/util.ts +289 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/_constants.ts +49 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/_interface.ts +30 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/_util.ts +194 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/common.ts +40 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/glob.ts +418 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/mod.ts +53 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/posix.ts +487 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/separator.ts +7 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/win32.ts +962 -0
- package/src/templates/vendor/deno.land/std@0.175.0/streams/write_all.ts +64 -0
- package/src/templates/vendor/deno.land/std@0.175.0/testing/_diff.ts +440 -0
- package/src/templates/vendor/deno.land/std@0.175.0/testing/_format.ts +23 -0
- package/src/templates/vendor/deno.land/std@0.175.0/testing/asserts.ts +906 -0
- package/src/templates/vendor/deno.land/std@0.175.0/types.d.ts +89 -0
- package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts +133 -0
- package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/asyncify.js +112 -0
- package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.d.ts +88 -0
- package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.js +974 -0
- package/src/templates/vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts +621 -0
- package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/compiled/cookie.js +13 -0
- package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js +12 -0
- package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/response.js +5 -0
- package/src/templates/vendor/import_map.json +13 -0
- package/src/templates/vendor/raw.githubusercontent.com/worker-tools/resolvable-promise/master/index.ts +50 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
|
3
|
+
|
|
4
|
+
// This implementation is inspired by "workerd" AsyncLocalStorage implementation:
|
|
5
|
+
// https://github.com/cloudflare/workerd/blob/77fd0ed6ddba184414f0216508fc62b06e716cab/src/workerd/api/node/async-hooks.c++#L9
|
|
6
|
+
|
|
7
|
+
import { validateFunction } from "./internal/validators.mjs";
|
|
8
|
+
import { core } from "./_core.ts";
|
|
9
|
+
|
|
10
|
+
function assert(cond: boolean) {
|
|
11
|
+
if (!cond) throw new Error("Assertion failed");
|
|
12
|
+
}
|
|
13
|
+
const asyncContextStack: AsyncContextFrame[] = [];
|
|
14
|
+
|
|
15
|
+
function pushAsyncFrame(frame: AsyncContextFrame) {
|
|
16
|
+
asyncContextStack.push(frame);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function popAsyncFrame() {
|
|
20
|
+
assert(asyncContextStack.length > 0);
|
|
21
|
+
asyncContextStack.pop();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let rootAsyncFrame: AsyncContextFrame | undefined = undefined;
|
|
25
|
+
let promiseHooksSet = false;
|
|
26
|
+
|
|
27
|
+
const asyncContext = Symbol("asyncContext");
|
|
28
|
+
function isRejected(promise: Promise<unknown>) {
|
|
29
|
+
const [state] = core.getPromiseDetails(promise);
|
|
30
|
+
return state == 2;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function setPromiseHooks() {
|
|
34
|
+
if (promiseHooksSet) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
promiseHooksSet = true;
|
|
38
|
+
|
|
39
|
+
const init = (promise: Promise<unknown>) => {
|
|
40
|
+
const currentFrame = AsyncContextFrame.current();
|
|
41
|
+
if (!currentFrame.isRoot()) {
|
|
42
|
+
assert(AsyncContextFrame.tryGetContext(promise) == null);
|
|
43
|
+
AsyncContextFrame.attachContext(promise);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const before = (promise: Promise<unknown>) => {
|
|
47
|
+
const maybeFrame = AsyncContextFrame.tryGetContext(promise);
|
|
48
|
+
if (maybeFrame) {
|
|
49
|
+
pushAsyncFrame(maybeFrame);
|
|
50
|
+
} else {
|
|
51
|
+
pushAsyncFrame(AsyncContextFrame.getRootAsyncContext());
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const after = (promise: Promise<unknown>) => {
|
|
55
|
+
popAsyncFrame();
|
|
56
|
+
if (!isRejected(promise)) {
|
|
57
|
+
// @ts-ignore promise async context
|
|
58
|
+
delete promise[asyncContext];
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const resolve = (promise: Promise<unknown>) => {
|
|
62
|
+
const currentFrame = AsyncContextFrame.current();
|
|
63
|
+
if (
|
|
64
|
+
!currentFrame.isRoot() && isRejected(promise) &&
|
|
65
|
+
AsyncContextFrame.tryGetContext(promise) == null
|
|
66
|
+
) {
|
|
67
|
+
AsyncContextFrame.attachContext(promise);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
core.setPromiseHooks(init, before, after, resolve);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
class AsyncContextFrame {
|
|
75
|
+
storage: StorageEntry[];
|
|
76
|
+
constructor(
|
|
77
|
+
maybeParent?: AsyncContextFrame | null,
|
|
78
|
+
maybeStorageEntry?: StorageEntry | null,
|
|
79
|
+
isRoot = false,
|
|
80
|
+
) {
|
|
81
|
+
this.storage = [];
|
|
82
|
+
|
|
83
|
+
setPromiseHooks();
|
|
84
|
+
|
|
85
|
+
const propagate = (parent: AsyncContextFrame) => {
|
|
86
|
+
parent.storage = parent.storage.filter((entry) => !entry.key.isDead());
|
|
87
|
+
parent.storage.forEach((entry) => this.storage.push(entry));
|
|
88
|
+
|
|
89
|
+
if (maybeStorageEntry) {
|
|
90
|
+
const existingEntry = this.storage.find((entry) =>
|
|
91
|
+
entry.key === maybeStorageEntry.key
|
|
92
|
+
);
|
|
93
|
+
if (existingEntry) {
|
|
94
|
+
existingEntry.value = maybeStorageEntry.value;
|
|
95
|
+
} else {
|
|
96
|
+
this.storage.push(maybeStorageEntry);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
if (!isRoot) {
|
|
102
|
+
if (maybeParent) {
|
|
103
|
+
propagate(maybeParent);
|
|
104
|
+
} else {
|
|
105
|
+
propagate(AsyncContextFrame.current());
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static tryGetContext(promise: Promise<unknown>) {
|
|
111
|
+
// @ts-ignore promise async context
|
|
112
|
+
return promise[asyncContext];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
static attachContext(promise: Promise<unknown>) {
|
|
116
|
+
assert(!(asyncContext in promise));
|
|
117
|
+
// @ts-ignore promise async context
|
|
118
|
+
promise[asyncContext] = AsyncContextFrame.current();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static getRootAsyncContext() {
|
|
122
|
+
if (typeof rootAsyncFrame !== "undefined") {
|
|
123
|
+
return rootAsyncFrame;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
rootAsyncFrame = new AsyncContextFrame(null, null, true);
|
|
127
|
+
return rootAsyncFrame;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static current() {
|
|
131
|
+
if (asyncContextStack.length === 0) {
|
|
132
|
+
return AsyncContextFrame.getRootAsyncContext();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return asyncContextStack[asyncContextStack.length - 1];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
static create(
|
|
139
|
+
maybeParent?: AsyncContextFrame | null,
|
|
140
|
+
maybeStorageEntry?: StorageEntry | null,
|
|
141
|
+
) {
|
|
142
|
+
return new AsyncContextFrame(maybeParent, maybeStorageEntry);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
static wrap(
|
|
146
|
+
fn: () => unknown,
|
|
147
|
+
maybeFrame: AsyncContextFrame | undefined,
|
|
148
|
+
// deno-lint-ignore no-explicit-any
|
|
149
|
+
thisArg: any,
|
|
150
|
+
) {
|
|
151
|
+
// deno-lint-ignore no-explicit-any
|
|
152
|
+
return (...args: any) => {
|
|
153
|
+
const frame = maybeFrame || AsyncContextFrame.current();
|
|
154
|
+
Scope.enter(frame);
|
|
155
|
+
try {
|
|
156
|
+
return fn.apply(thisArg, args);
|
|
157
|
+
} finally {
|
|
158
|
+
Scope.exit();
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
get(key: StorageKey) {
|
|
164
|
+
assert(!key.isDead());
|
|
165
|
+
this.storage = this.storage.filter((entry) => !entry.key.isDead());
|
|
166
|
+
const entry = this.storage.find((entry) => entry.key === key);
|
|
167
|
+
if (entry) {
|
|
168
|
+
return entry.value;
|
|
169
|
+
}
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
isRoot() {
|
|
174
|
+
return AsyncContextFrame.getRootAsyncContext() == this;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export class AsyncResource {
|
|
179
|
+
frame: AsyncContextFrame;
|
|
180
|
+
type: string;
|
|
181
|
+
constructor(type: string) {
|
|
182
|
+
this.type = type;
|
|
183
|
+
this.frame = AsyncContextFrame.current();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
runInAsyncScope(
|
|
187
|
+
fn: (...args: unknown[]) => unknown,
|
|
188
|
+
thisArg: unknown,
|
|
189
|
+
...args: unknown[]
|
|
190
|
+
) {
|
|
191
|
+
Scope.enter(this.frame);
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
return fn.apply(thisArg, args);
|
|
195
|
+
} finally {
|
|
196
|
+
Scope.exit();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
bind(fn: (...args: unknown[]) => unknown, thisArg = this) {
|
|
201
|
+
validateFunction(fn, "fn");
|
|
202
|
+
const frame = AsyncContextFrame.current();
|
|
203
|
+
const bound = AsyncContextFrame.wrap(fn, frame, thisArg);
|
|
204
|
+
|
|
205
|
+
Object.defineProperties(bound, {
|
|
206
|
+
"length": {
|
|
207
|
+
configurable: true,
|
|
208
|
+
enumerable: false,
|
|
209
|
+
value: fn.length,
|
|
210
|
+
writable: false,
|
|
211
|
+
},
|
|
212
|
+
"asyncResource": {
|
|
213
|
+
configurable: true,
|
|
214
|
+
enumerable: true,
|
|
215
|
+
value: this,
|
|
216
|
+
writable: true,
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
return bound;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
static bind(
|
|
223
|
+
fn: (...args: unknown[]) => unknown,
|
|
224
|
+
type?: string,
|
|
225
|
+
thisArg?: AsyncResource,
|
|
226
|
+
) {
|
|
227
|
+
type = type || fn.name;
|
|
228
|
+
return (new AsyncResource(type || "AsyncResource")).bind(fn, thisArg);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
class Scope {
|
|
233
|
+
static enter(maybeFrame?: AsyncContextFrame) {
|
|
234
|
+
if (maybeFrame) {
|
|
235
|
+
pushAsyncFrame(maybeFrame);
|
|
236
|
+
} else {
|
|
237
|
+
pushAsyncFrame(AsyncContextFrame.getRootAsyncContext());
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
static exit() {
|
|
242
|
+
popAsyncFrame();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
class StorageEntry {
|
|
247
|
+
key: StorageKey;
|
|
248
|
+
value: unknown;
|
|
249
|
+
constructor(key: StorageKey, value: unknown) {
|
|
250
|
+
this.key = key;
|
|
251
|
+
this.value = value;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
class StorageKey {
|
|
256
|
+
#dead = false;
|
|
257
|
+
|
|
258
|
+
reset() {
|
|
259
|
+
this.#dead = true;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
isDead() {
|
|
263
|
+
return this.#dead;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const fnReg = new FinalizationRegistry((key: StorageKey) => {
|
|
268
|
+
key.reset();
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
export class AsyncLocalStorage {
|
|
272
|
+
#key;
|
|
273
|
+
|
|
274
|
+
constructor() {
|
|
275
|
+
this.#key = new StorageKey();
|
|
276
|
+
fnReg.register(this, this.#key);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// deno-lint-ignore no-explicit-any
|
|
280
|
+
run(store: any, callback: any, ...args: any[]): any {
|
|
281
|
+
const frame = AsyncContextFrame.create(
|
|
282
|
+
null,
|
|
283
|
+
new StorageEntry(this.#key, store),
|
|
284
|
+
);
|
|
285
|
+
Scope.enter(frame);
|
|
286
|
+
let res;
|
|
287
|
+
try {
|
|
288
|
+
res = callback(...args);
|
|
289
|
+
} finally {
|
|
290
|
+
Scope.exit();
|
|
291
|
+
}
|
|
292
|
+
return res;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// deno-lint-ignore no-explicit-any
|
|
296
|
+
exit(callback: (...args: unknown[]) => any, ...args: any[]): any {
|
|
297
|
+
return this.run(undefined, callback, args);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// deno-lint-ignore no-explicit-any
|
|
301
|
+
getStore(): any {
|
|
302
|
+
const currentFrame = AsyncContextFrame.current();
|
|
303
|
+
return currentFrame.get(this.#key);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export function executionAsyncId() {
|
|
308
|
+
return 1;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
class AsyncHook {
|
|
312
|
+
enable() {
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
disable() {
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export function createHook() {
|
|
320
|
+
return new AsyncHook();
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Placing all exports down here because the exported classes won't export
|
|
324
|
+
// otherwise.
|
|
325
|
+
export default {
|
|
326
|
+
// Embedder API
|
|
327
|
+
AsyncResource,
|
|
328
|
+
executionAsyncId,
|
|
329
|
+
createHook,
|
|
330
|
+
AsyncLocalStorage,
|
|
331
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// @deno-types="./internal/buffer.d.ts"
|
|
3
|
+
export {
|
|
4
|
+
atob,
|
|
5
|
+
Blob,
|
|
6
|
+
btoa,
|
|
7
|
+
Buffer,
|
|
8
|
+
constants,
|
|
9
|
+
default,
|
|
10
|
+
kMaxLength,
|
|
11
|
+
kStringMaxLength,
|
|
12
|
+
SlowBuffer,
|
|
13
|
+
} from "./internal/buffer.mjs";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// @deno-types="./_events.d.ts"
|
|
3
|
+
export {
|
|
4
|
+
captureRejectionSymbol,
|
|
5
|
+
default,
|
|
6
|
+
defaultMaxListeners,
|
|
7
|
+
errorMonitor,
|
|
8
|
+
EventEmitter,
|
|
9
|
+
getEventListeners,
|
|
10
|
+
listenerCount,
|
|
11
|
+
on,
|
|
12
|
+
once,
|
|
13
|
+
setMaxListeners,
|
|
14
|
+
} from "./_events.mjs";
|