@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,81 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
|
|
3
|
+
export class RetryError extends Error {
|
|
4
|
+
constructor(cause: unknown, count: number) {
|
|
5
|
+
super(`Exceeded max retry count (${count})`);
|
|
6
|
+
this.name = "RetryError";
|
|
7
|
+
this.cause = cause;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface RetryOptions {
|
|
12
|
+
/** How much to backoff after each retry. This is `2` by default. */
|
|
13
|
+
multiplier?: number;
|
|
14
|
+
/** The maximum milliseconds between retries. This is `60000` by default. */
|
|
15
|
+
maxTimeout?: number;
|
|
16
|
+
/** The maximum amount of retries until failure. This is `5` by default. */
|
|
17
|
+
maxAttempts?: number;
|
|
18
|
+
/** The inital and minimum amount of milliseconds between retries. This is `1000` by default. */
|
|
19
|
+
minTimeout?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const defaultRetryOptions = {
|
|
23
|
+
multiplier: 2,
|
|
24
|
+
maxTimeout: 60000,
|
|
25
|
+
maxAttempts: 5,
|
|
26
|
+
minTimeout: 1000,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates a retry promise which resolves to the value of the input using exponential backoff.
|
|
31
|
+
* If the input promise throws, it will be retried `maxAttempts` number of times.
|
|
32
|
+
* It will retry the input every certain amount of milliseconds, starting at `minTimeout` and multiplying by the `multiplier` until it reaches the `maxTimeout`
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { retry } from "https://deno.land/std@$STD_VERSION/async/mod.ts";
|
|
37
|
+
* const req = async () => {
|
|
38
|
+
* // some function that throws sometimes
|
|
39
|
+
* };
|
|
40
|
+
*
|
|
41
|
+
* // Below resolves to the first non-error result of `req`
|
|
42
|
+
* const retryPromise = await retry(req, {
|
|
43
|
+
* multiplier: 2,
|
|
44
|
+
* maxTimeout: 60000,
|
|
45
|
+
* maxAttempts: 5,
|
|
46
|
+
* minTimeout: 100,
|
|
47
|
+
* });
|
|
48
|
+
```
|
|
49
|
+
*/
|
|
50
|
+
export async function retry<T>(
|
|
51
|
+
fn: (() => Promise<T>) | (() => T),
|
|
52
|
+
opts?: RetryOptions,
|
|
53
|
+
) {
|
|
54
|
+
const options: Required<RetryOptions> = {
|
|
55
|
+
...defaultRetryOptions,
|
|
56
|
+
...opts,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
if (options.maxTimeout >= 0 && options.minTimeout > options.maxTimeout) {
|
|
60
|
+
throw new RangeError("minTimeout is greater than maxTimeout");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let timeout = options.minTimeout;
|
|
64
|
+
let error: unknown;
|
|
65
|
+
|
|
66
|
+
for (let i = 0; i < options.maxAttempts; i++) {
|
|
67
|
+
try {
|
|
68
|
+
return await fn();
|
|
69
|
+
} catch (err) {
|
|
70
|
+
await new Promise((r) => setTimeout(r, timeout));
|
|
71
|
+
timeout *= options.multiplier;
|
|
72
|
+
timeout = Math.max(timeout, options.minTimeout);
|
|
73
|
+
if (options.maxTimeout >= 0) {
|
|
74
|
+
timeout = Math.min(timeout, options.maxTimeout);
|
|
75
|
+
}
|
|
76
|
+
error = err;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
throw new RetryError(error, options.maxAttempts);
|
|
81
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
|
|
4
|
+
// Utility for representing n-tuple
|
|
5
|
+
type Tuple<T, N extends number> = N extends N
|
|
6
|
+
? number extends N ? T[] : TupleOf<T, N, []>
|
|
7
|
+
: never;
|
|
8
|
+
type TupleOf<T, N extends number, R extends unknown[]> = R["length"] extends N
|
|
9
|
+
? R
|
|
10
|
+
: TupleOf<T, N, [T, ...R]>;
|
|
11
|
+
|
|
12
|
+
interface QueueNode<T> {
|
|
13
|
+
value: T;
|
|
14
|
+
next: QueueNode<T> | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class Queue<T> {
|
|
18
|
+
#source: AsyncIterator<T>;
|
|
19
|
+
#queue: QueueNode<T>;
|
|
20
|
+
head: QueueNode<T>;
|
|
21
|
+
|
|
22
|
+
done: boolean;
|
|
23
|
+
|
|
24
|
+
constructor(iterable: AsyncIterable<T>) {
|
|
25
|
+
this.#source = iterable[Symbol.asyncIterator]();
|
|
26
|
+
this.#queue = {
|
|
27
|
+
value: undefined!,
|
|
28
|
+
next: undefined,
|
|
29
|
+
};
|
|
30
|
+
this.head = this.#queue;
|
|
31
|
+
this.done = false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async next() {
|
|
35
|
+
const result = await this.#source.next();
|
|
36
|
+
if (!result.done) {
|
|
37
|
+
const nextNode: QueueNode<T> = {
|
|
38
|
+
value: result.value,
|
|
39
|
+
next: undefined,
|
|
40
|
+
};
|
|
41
|
+
this.#queue.next = nextNode;
|
|
42
|
+
this.#queue = nextNode;
|
|
43
|
+
} else {
|
|
44
|
+
this.done = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Branches the given async iterable into the n branches.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { tee } from "https://deno.land/std@$STD_VERSION/async/tee.ts";
|
|
55
|
+
*
|
|
56
|
+
* const gen = async function* gen() {
|
|
57
|
+
* yield 1;
|
|
58
|
+
* yield 2;
|
|
59
|
+
* yield 3;
|
|
60
|
+
* };
|
|
61
|
+
*
|
|
62
|
+
* const [branch1, branch2] = tee(gen());
|
|
63
|
+
*
|
|
64
|
+
* for await (const n of branch1) {
|
|
65
|
+
* console.log(n); // => 1, 2, 3
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* for await (const n of branch2) {
|
|
69
|
+
* console.log(n); // => 1, 2, 3
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export function tee<T, N extends number = 2>(
|
|
74
|
+
iterable: AsyncIterable<T>,
|
|
75
|
+
n: N = 2 as N,
|
|
76
|
+
): Tuple<AsyncIterable<T>, N> {
|
|
77
|
+
const queue = new Queue<T>(iterable);
|
|
78
|
+
|
|
79
|
+
async function* generator(): AsyncGenerator<T> {
|
|
80
|
+
let buffer = queue.head;
|
|
81
|
+
while (true) {
|
|
82
|
+
if (buffer.next) {
|
|
83
|
+
buffer = buffer.next;
|
|
84
|
+
yield buffer.value;
|
|
85
|
+
} else if (queue.done) {
|
|
86
|
+
return;
|
|
87
|
+
} else {
|
|
88
|
+
await queue.next();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const branches = Array.from({ length: n }).map(
|
|
94
|
+
() => generator(),
|
|
95
|
+
) as Tuple<
|
|
96
|
+
AsyncIterable<T>,
|
|
97
|
+
N
|
|
98
|
+
>;
|
|
99
|
+
return branches;
|
|
100
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
|
|
4
|
+
/** Returns the index of the first occurrence of the needle array in the source
|
|
5
|
+
* array, or -1 if it is not present.
|
|
6
|
+
*
|
|
7
|
+
* A start index can be specified as the third argument that begins the search
|
|
8
|
+
* at that given index. The start index defaults to the start of the array.
|
|
9
|
+
*
|
|
10
|
+
* The complexity of this function is O(source.lenth * needle.length).
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { indexOfNeedle } from "https://deno.land/std@$STD_VERSION/bytes/index_of_needle.ts";
|
|
14
|
+
* const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
|
|
15
|
+
* const needle = new Uint8Array([1, 2]);
|
|
16
|
+
* console.log(indexOfNeedle(source, needle)); // 1
|
|
17
|
+
* console.log(indexOfNeedle(source, needle, 2)); // 3
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function indexOfNeedle(
|
|
21
|
+
source: Uint8Array,
|
|
22
|
+
needle: Uint8Array,
|
|
23
|
+
start = 0,
|
|
24
|
+
): number {
|
|
25
|
+
if (start >= source.length) {
|
|
26
|
+
return -1;
|
|
27
|
+
}
|
|
28
|
+
if (start < 0) {
|
|
29
|
+
start = Math.max(0, source.length + start);
|
|
30
|
+
}
|
|
31
|
+
const s = needle[0];
|
|
32
|
+
for (let i = start; i < source.length; i++) {
|
|
33
|
+
if (source[i] !== s) continue;
|
|
34
|
+
const pin = i;
|
|
35
|
+
let matched = 1;
|
|
36
|
+
let j = i;
|
|
37
|
+
while (matched < needle.length) {
|
|
38
|
+
j++;
|
|
39
|
+
if (source[j] !== needle[j - pin]) {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
matched++;
|
|
43
|
+
}
|
|
44
|
+
if (matched === needle.length) {
|
|
45
|
+
return pin;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return -1;
|
|
49
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
|
|
3
|
+
import { assert } from "../_util/asserts.ts";
|
|
4
|
+
|
|
5
|
+
/** Compare to array buffers or data views in a way that timing based attacks
|
|
6
|
+
* cannot gain information about the platform. */
|
|
7
|
+
export function timingSafeEqual(
|
|
8
|
+
a: ArrayBufferView | ArrayBufferLike | DataView,
|
|
9
|
+
b: ArrayBufferView | ArrayBufferLike | DataView,
|
|
10
|
+
): boolean {
|
|
11
|
+
if (a.byteLength !== b.byteLength) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (!(a instanceof DataView)) {
|
|
15
|
+
a = new DataView(ArrayBuffer.isView(a) ? a.buffer : a);
|
|
16
|
+
}
|
|
17
|
+
if (!(b instanceof DataView)) {
|
|
18
|
+
b = new DataView(ArrayBuffer.isView(b) ? b.buffer : b);
|
|
19
|
+
}
|
|
20
|
+
assert(a instanceof DataView);
|
|
21
|
+
assert(b instanceof DataView);
|
|
22
|
+
const length = a.byteLength;
|
|
23
|
+
let out = 0;
|
|
24
|
+
let i = -1;
|
|
25
|
+
while (++i < length) {
|
|
26
|
+
out |= a.getUint8(i) ^ b.getUint8(i);
|
|
27
|
+
}
|
|
28
|
+
return out === 0;
|
|
29
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
/**
|
|
3
|
+
* Formats the given date to IMF date time format. (Reference:
|
|
4
|
+
* https://tools.ietf.org/html/rfc7231#section-7.1.1.1).
|
|
5
|
+
* IMF is the time format to use when generating times in HTTP
|
|
6
|
+
* headers. The time being formatted must be in UTC for Format to
|
|
7
|
+
* generate the correct format.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { toIMF } from "https://deno.land/std@$STD_VERSION/datetime/to_imf.ts";
|
|
12
|
+
*
|
|
13
|
+
* toIMF(new Date(0)); // => returns "Thu, 01 Jan 1970 00:00:00 GMT"
|
|
14
|
+
* ```
|
|
15
|
+
* @param date Date to parse
|
|
16
|
+
* @return IMF date formatted string
|
|
17
|
+
*/
|
|
18
|
+
export function toIMF(date: Date): string {
|
|
19
|
+
function dtPad(v: string, lPad = 2): string {
|
|
20
|
+
return v.padStart(lPad, "0");
|
|
21
|
+
}
|
|
22
|
+
const d = dtPad(date.getUTCDate().toString());
|
|
23
|
+
const h = dtPad(date.getUTCHours().toString());
|
|
24
|
+
const min = dtPad(date.getUTCMinutes().toString());
|
|
25
|
+
const s = dtPad(date.getUTCSeconds().toString());
|
|
26
|
+
const y = date.getUTCFullYear();
|
|
27
|
+
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
28
|
+
const months = [
|
|
29
|
+
"Jan",
|
|
30
|
+
"Feb",
|
|
31
|
+
"Mar",
|
|
32
|
+
"Apr",
|
|
33
|
+
"May",
|
|
34
|
+
"Jun",
|
|
35
|
+
"Jul",
|
|
36
|
+
"Aug",
|
|
37
|
+
"Sep",
|
|
38
|
+
"Oct",
|
|
39
|
+
"Nov",
|
|
40
|
+
"Dec",
|
|
41
|
+
];
|
|
42
|
+
return `${days[date.getUTCDay()]}, ${d} ${
|
|
43
|
+
months[date.getUTCMonth()]
|
|
44
|
+
} ${y} ${h}:${min}:${s} GMT`;
|
|
45
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* {@linkcode encode} and {@linkcode decode} for
|
|
5
|
+
* [base64](https://en.wikipedia.org/wiki/Base64) encoding.
|
|
6
|
+
*
|
|
7
|
+
* This module is browser compatible.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import {
|
|
12
|
+
* decode,
|
|
13
|
+
* encode,
|
|
14
|
+
* } from "https://deno.land/std@$STD_VERSION/encoding/base64.ts";
|
|
15
|
+
*
|
|
16
|
+
* const b64Repr = "Zm9vYg==";
|
|
17
|
+
*
|
|
18
|
+
* const binaryData = decode(b64Repr);
|
|
19
|
+
* console.log(binaryData);
|
|
20
|
+
* // => Uint8Array [ 102, 111, 111, 98 ]
|
|
21
|
+
*
|
|
22
|
+
* console.log(encode(binaryData));
|
|
23
|
+
* // => Zm9vYg==
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
const base64abc = [
|
|
30
|
+
"A",
|
|
31
|
+
"B",
|
|
32
|
+
"C",
|
|
33
|
+
"D",
|
|
34
|
+
"E",
|
|
35
|
+
"F",
|
|
36
|
+
"G",
|
|
37
|
+
"H",
|
|
38
|
+
"I",
|
|
39
|
+
"J",
|
|
40
|
+
"K",
|
|
41
|
+
"L",
|
|
42
|
+
"M",
|
|
43
|
+
"N",
|
|
44
|
+
"O",
|
|
45
|
+
"P",
|
|
46
|
+
"Q",
|
|
47
|
+
"R",
|
|
48
|
+
"S",
|
|
49
|
+
"T",
|
|
50
|
+
"U",
|
|
51
|
+
"V",
|
|
52
|
+
"W",
|
|
53
|
+
"X",
|
|
54
|
+
"Y",
|
|
55
|
+
"Z",
|
|
56
|
+
"a",
|
|
57
|
+
"b",
|
|
58
|
+
"c",
|
|
59
|
+
"d",
|
|
60
|
+
"e",
|
|
61
|
+
"f",
|
|
62
|
+
"g",
|
|
63
|
+
"h",
|
|
64
|
+
"i",
|
|
65
|
+
"j",
|
|
66
|
+
"k",
|
|
67
|
+
"l",
|
|
68
|
+
"m",
|
|
69
|
+
"n",
|
|
70
|
+
"o",
|
|
71
|
+
"p",
|
|
72
|
+
"q",
|
|
73
|
+
"r",
|
|
74
|
+
"s",
|
|
75
|
+
"t",
|
|
76
|
+
"u",
|
|
77
|
+
"v",
|
|
78
|
+
"w",
|
|
79
|
+
"x",
|
|
80
|
+
"y",
|
|
81
|
+
"z",
|
|
82
|
+
"0",
|
|
83
|
+
"1",
|
|
84
|
+
"2",
|
|
85
|
+
"3",
|
|
86
|
+
"4",
|
|
87
|
+
"5",
|
|
88
|
+
"6",
|
|
89
|
+
"7",
|
|
90
|
+
"8",
|
|
91
|
+
"9",
|
|
92
|
+
"+",
|
|
93
|
+
"/",
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
|
|
98
|
+
* Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation
|
|
99
|
+
* @param data
|
|
100
|
+
*/
|
|
101
|
+
export function encode(data: ArrayBuffer | string): string {
|
|
102
|
+
const uint8 = typeof data === "string"
|
|
103
|
+
? new TextEncoder().encode(data)
|
|
104
|
+
: data instanceof Uint8Array
|
|
105
|
+
? data
|
|
106
|
+
: new Uint8Array(data);
|
|
107
|
+
let result = "",
|
|
108
|
+
i;
|
|
109
|
+
const l = uint8.length;
|
|
110
|
+
for (i = 2; i < l; i += 3) {
|
|
111
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
112
|
+
result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
|
|
113
|
+
result += base64abc[((uint8[i - 1] & 0x0f) << 2) | (uint8[i] >> 6)];
|
|
114
|
+
result += base64abc[uint8[i] & 0x3f];
|
|
115
|
+
}
|
|
116
|
+
if (i === l + 1) {
|
|
117
|
+
// 1 octet yet to write
|
|
118
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
119
|
+
result += base64abc[(uint8[i - 2] & 0x03) << 4];
|
|
120
|
+
result += "==";
|
|
121
|
+
}
|
|
122
|
+
if (i === l) {
|
|
123
|
+
// 2 octets yet to write
|
|
124
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
125
|
+
result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
|
|
126
|
+
result += base64abc[(uint8[i - 1] & 0x0f) << 2];
|
|
127
|
+
result += "=";
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Decodes a given RFC4648 base64 encoded string
|
|
134
|
+
* @param b64
|
|
135
|
+
*/
|
|
136
|
+
export function decode(b64: string): Uint8Array {
|
|
137
|
+
const binString = atob(b64);
|
|
138
|
+
const size = binString.length;
|
|
139
|
+
const bytes = new Uint8Array(size);
|
|
140
|
+
for (let i = 0; i < size; i++) {
|
|
141
|
+
bytes[i] = binString.charCodeAt(i);
|
|
142
|
+
}
|
|
143
|
+
return bytes;
|
|
144
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* {@linkcode encode} and {@linkcode decode} for
|
|
5
|
+
* [base64 URL safe](https://en.wikipedia.org/wiki/Base64#URL_applications) encoding.
|
|
6
|
+
*
|
|
7
|
+
* This module is browser compatible.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import {
|
|
12
|
+
* decode,
|
|
13
|
+
* encode,
|
|
14
|
+
* } from "https://deno.land/std@$STD_VERSION/encoding/base64url.ts";
|
|
15
|
+
*
|
|
16
|
+
* const binary = new TextEncoder().encode("foobar");
|
|
17
|
+
* const encoded = encode(binary);
|
|
18
|
+
* console.log(encoded);
|
|
19
|
+
* // => "Zm9vYmFy"
|
|
20
|
+
*
|
|
21
|
+
* console.log(decode(encoded));
|
|
22
|
+
* // => Uint8Array(6) [ 102, 111, 111, 98, 97, 114 ]
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import * as base64 from "./base64.ts";
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
* Some variants allow or require omitting the padding '=' signs:
|
|
32
|
+
* https://en.wikipedia.org/wiki/Base64#The_URL_applications
|
|
33
|
+
* @param base64url
|
|
34
|
+
*/
|
|
35
|
+
function addPaddingToBase64url(base64url: string): string {
|
|
36
|
+
if (base64url.length % 4 === 2) return base64url + "==";
|
|
37
|
+
if (base64url.length % 4 === 3) return base64url + "=";
|
|
38
|
+
if (base64url.length % 4 === 1) {
|
|
39
|
+
throw new TypeError("Illegal base64url string!");
|
|
40
|
+
}
|
|
41
|
+
return base64url;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function convertBase64urlToBase64(b64url: string): string {
|
|
45
|
+
if (!/^[-_A-Z0-9]*?={0,2}$/i.test(b64url)) {
|
|
46
|
+
// Contains characters not part of base64url spec.
|
|
47
|
+
throw new TypeError("Failed to decode base64url: invalid character");
|
|
48
|
+
}
|
|
49
|
+
return addPaddingToBase64url(b64url).replace(/\-/g, "+").replace(/_/g, "/");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function convertBase64ToBase64url(b64: string): string {
|
|
53
|
+
return b64.replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Encodes a given ArrayBuffer or string into a base64url representation
|
|
58
|
+
* @param data
|
|
59
|
+
*/
|
|
60
|
+
export function encode(data: ArrayBuffer | string): string {
|
|
61
|
+
return convertBase64ToBase64url(base64.encode(data));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Converts given base64url encoded data back to original
|
|
66
|
+
* @param b64url
|
|
67
|
+
*/
|
|
68
|
+
export function decode(b64url: string): Uint8Array {
|
|
69
|
+
return base64.decode(convertBase64urlToBase64(b64url));
|
|
70
|
+
}
|