@comapeo/map-server 1.0.0-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +610 -0
- package/dist/context.d.ts +46 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +181 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +112 -0
- package/dist/lib/constants.d.ts +7 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +6 -0
- package/dist/lib/download-request.d.ts +17 -0
- package/dist/lib/download-request.d.ts.map +1 -0
- package/dist/lib/download-request.js +113 -0
- package/dist/lib/errors.d.ts +88 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +158 -0
- package/dist/lib/event-stream-response.d.ts +17 -0
- package/dist/lib/event-stream-response.d.ts.map +1 -0
- package/dist/lib/event-stream-response.js +39 -0
- package/dist/lib/event-target.d.ts +9 -0
- package/dist/lib/event-target.d.ts.map +1 -0
- package/dist/lib/event-target.js +4 -0
- package/dist/lib/fetch-api.d.ts +3 -0
- package/dist/lib/fetch-api.d.ts.map +1 -0
- package/dist/lib/fetch-api.js +16 -0
- package/dist/lib/map-share.d.ts +52 -0
- package/dist/lib/map-share.d.ts.map +1 -0
- package/dist/lib/map-share.js +142 -0
- package/dist/lib/secret-stream-fetch.d.ts +7 -0
- package/dist/lib/secret-stream-fetch.d.ts.map +1 -0
- package/dist/lib/secret-stream-fetch.js +34 -0
- package/dist/lib/self-evicting-map.d.ts +16 -0
- package/dist/lib/self-evicting-map.d.ts.map +1 -0
- package/dist/lib/self-evicting-map.js +29 -0
- package/dist/lib/state-update-event.d.ts +8 -0
- package/dist/lib/state-update-event.d.ts.map +1 -0
- package/dist/lib/state-update-event.js +10 -0
- package/dist/lib/utils.d.ts +32 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +96 -0
- package/dist/middlewares/localhost-only.d.ts +11 -0
- package/dist/middlewares/localhost-only.d.ts.map +1 -0
- package/dist/middlewares/localhost-only.js +10 -0
- package/dist/middlewares/parse-request.d.ts +11 -0
- package/dist/middlewares/parse-request.d.ts.map +1 -0
- package/dist/middlewares/parse-request.js +25 -0
- package/dist/routes/downloads.d.ts +15 -0
- package/dist/routes/downloads.d.ts.map +1 -0
- package/dist/routes/downloads.js +60 -0
- package/dist/routes/map-shares.d.ts +19 -0
- package/dist/routes/map-shares.d.ts.map +1 -0
- package/dist/routes/map-shares.js +192 -0
- package/dist/routes/maps.d.ts +6 -0
- package/dist/routes/maps.d.ts.map +1 -0
- package/dist/routes/maps.js +118 -0
- package/dist/routes/root.d.ts +6 -0
- package/dist/routes/root.d.ts.map +1 -0
- package/dist/routes/root.js +29 -0
- package/dist/types.d.ts +110 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +96 -0
- package/node_modules/@envelop/instrumentation/LICENSE +21 -0
- package/node_modules/@envelop/instrumentation/README.md +30 -0
- package/node_modules/@envelop/instrumentation/cjs/index.js +5 -0
- package/node_modules/@envelop/instrumentation/cjs/instrumentation.js +89 -0
- package/node_modules/@envelop/instrumentation/cjs/package.json +1 -0
- package/node_modules/@envelop/instrumentation/esm/index.js +2 -0
- package/node_modules/@envelop/instrumentation/esm/instrumentation.js +82 -0
- package/node_modules/@envelop/instrumentation/package.json +57 -0
- package/node_modules/@envelop/instrumentation/typings/index.d.cts +1 -0
- package/node_modules/@envelop/instrumentation/typings/index.d.ts +1 -0
- package/node_modules/@envelop/instrumentation/typings/instrumentation.d.cts +44 -0
- package/node_modules/@envelop/instrumentation/typings/instrumentation.d.ts +44 -0
- package/node_modules/@whatwg-node/disposablestack/cjs/AsyncDisposableStack.js +73 -0
- package/node_modules/@whatwg-node/disposablestack/cjs/DisposableStack.js +62 -0
- package/node_modules/@whatwg-node/disposablestack/cjs/SupressedError.js +16 -0
- package/node_modules/@whatwg-node/disposablestack/cjs/index.js +11 -0
- package/node_modules/@whatwg-node/disposablestack/cjs/package.json +1 -0
- package/node_modules/@whatwg-node/disposablestack/cjs/symbols.js +20 -0
- package/node_modules/@whatwg-node/disposablestack/cjs/utils.js +11 -0
- package/node_modules/@whatwg-node/disposablestack/esm/AsyncDisposableStack.js +69 -0
- package/node_modules/@whatwg-node/disposablestack/esm/DisposableStack.js +58 -0
- package/node_modules/@whatwg-node/disposablestack/esm/SupressedError.js +12 -0
- package/node_modules/@whatwg-node/disposablestack/esm/index.js +7 -0
- package/node_modules/@whatwg-node/disposablestack/esm/symbols.js +16 -0
- package/node_modules/@whatwg-node/disposablestack/esm/utils.js +7 -0
- package/node_modules/@whatwg-node/disposablestack/package.json +44 -0
- package/node_modules/@whatwg-node/disposablestack/typings/AsyncDisposableStack.d.cts +15 -0
- package/node_modules/@whatwg-node/disposablestack/typings/AsyncDisposableStack.d.ts +15 -0
- package/node_modules/@whatwg-node/disposablestack/typings/DisposableStack.d.cts +14 -0
- package/node_modules/@whatwg-node/disposablestack/typings/DisposableStack.d.ts +14 -0
- package/node_modules/@whatwg-node/disposablestack/typings/SupressedError.d.cts +5 -0
- package/node_modules/@whatwg-node/disposablestack/typings/SupressedError.d.ts +5 -0
- package/node_modules/@whatwg-node/disposablestack/typings/index.d.cts +4 -0
- package/node_modules/@whatwg-node/disposablestack/typings/index.d.ts +4 -0
- package/node_modules/@whatwg-node/disposablestack/typings/symbols.d.cts +5 -0
- package/node_modules/@whatwg-node/disposablestack/typings/symbols.d.ts +5 -0
- package/node_modules/@whatwg-node/disposablestack/typings/utils.d.cts +2 -0
- package/node_modules/@whatwg-node/disposablestack/typings/utils.d.ts +2 -0
- package/node_modules/@whatwg-node/promise-helpers/cjs/index.js +270 -0
- package/node_modules/@whatwg-node/promise-helpers/cjs/package.json +1 -0
- package/node_modules/@whatwg-node/promise-helpers/esm/index.js +257 -0
- package/node_modules/@whatwg-node/promise-helpers/package.json +43 -0
- package/node_modules/@whatwg-node/promise-helpers/typings/index.d.cts +31 -0
- package/node_modules/@whatwg-node/promise-helpers/typings/index.d.ts +31 -0
- package/node_modules/@whatwg-node/server/README.md +590 -0
- package/node_modules/@whatwg-node/server/cjs/createServerAdapter.js +368 -0
- package/node_modules/@whatwg-node/server/cjs/index.js +17 -0
- package/node_modules/@whatwg-node/server/cjs/package.json +1 -0
- package/node_modules/@whatwg-node/server/cjs/plugins/types.js +0 -0
- package/node_modules/@whatwg-node/server/cjs/plugins/useContentEncoding.js +73 -0
- package/node_modules/@whatwg-node/server/cjs/plugins/useCors.js +124 -0
- package/node_modules/@whatwg-node/server/cjs/plugins/useErrorHandling.js +52 -0
- package/node_modules/@whatwg-node/server/cjs/types.js +0 -0
- package/node_modules/@whatwg-node/server/cjs/utils.js +599 -0
- package/node_modules/@whatwg-node/server/cjs/uwebsockets.js +241 -0
- package/node_modules/@whatwg-node/server/esm/createServerAdapter.js +365 -0
- package/node_modules/@whatwg-node/server/esm/index.js +11 -0
- package/node_modules/@whatwg-node/server/esm/plugins/types.js +0 -0
- package/node_modules/@whatwg-node/server/esm/plugins/useContentEncoding.js +70 -0
- package/node_modules/@whatwg-node/server/esm/plugins/useCors.js +120 -0
- package/node_modules/@whatwg-node/server/esm/plugins/useErrorHandling.js +46 -0
- package/node_modules/@whatwg-node/server/esm/types.js +0 -0
- package/node_modules/@whatwg-node/server/esm/utils.js +588 -0
- package/node_modules/@whatwg-node/server/esm/uwebsockets.js +234 -0
- package/node_modules/@whatwg-node/server/package.json +46 -0
- package/node_modules/@whatwg-node/server/typings/createServerAdapter.d.cts +19 -0
- package/node_modules/@whatwg-node/server/typings/createServerAdapter.d.ts +19 -0
- package/node_modules/@whatwg-node/server/typings/index.d.cts +11 -0
- package/node_modules/@whatwg-node/server/typings/index.d.ts +11 -0
- package/node_modules/@whatwg-node/server/typings/plugins/types.d.cts +76 -0
- package/node_modules/@whatwg-node/server/typings/plugins/types.d.ts +76 -0
- package/node_modules/@whatwg-node/server/typings/plugins/useContentEncoding.d.cts +2 -0
- package/node_modules/@whatwg-node/server/typings/plugins/useContentEncoding.d.ts +2 -0
- package/node_modules/@whatwg-node/server/typings/plugins/useCors.d.cts +14 -0
- package/node_modules/@whatwg-node/server/typings/plugins/useCors.d.ts +14 -0
- package/node_modules/@whatwg-node/server/typings/plugins/useErrorHandling.d.cts +13 -0
- package/node_modules/@whatwg-node/server/typings/plugins/useErrorHandling.d.ts +13 -0
- package/node_modules/@whatwg-node/server/typings/types.d.cts +100 -0
- package/node_modules/@whatwg-node/server/typings/types.d.ts +100 -0
- package/node_modules/@whatwg-node/server/typings/utils.d.cts +42 -0
- package/node_modules/@whatwg-node/server/typings/utils.d.ts +42 -0
- package/node_modules/@whatwg-node/server/typings/uwebsockets.d.cts +32 -0
- package/node_modules/@whatwg-node/server/typings/uwebsockets.d.ts +32 -0
- package/node_modules/tslib/CopyrightNotice.txt +15 -0
- package/node_modules/tslib/LICENSE.txt +12 -0
- package/node_modules/tslib/README.md +164 -0
- package/node_modules/tslib/SECURITY.md +41 -0
- package/node_modules/tslib/modules/index.d.ts +38 -0
- package/node_modules/tslib/modules/index.js +70 -0
- package/node_modules/tslib/modules/package.json +3 -0
- package/node_modules/tslib/package.json +47 -0
- package/node_modules/tslib/tslib.d.ts +460 -0
- package/node_modules/tslib/tslib.es6.html +1 -0
- package/node_modules/tslib/tslib.es6.js +402 -0
- package/node_modules/tslib/tslib.es6.mjs +401 -0
- package/node_modules/tslib/tslib.html +1 -0
- package/node_modules/tslib/tslib.js +484 -0
- package/package.json +87 -0
- package/src/context.ts +203 -0
- package/src/index.ts +193 -0
- package/src/lib/constants.ts +6 -0
- package/src/lib/download-request.ts +142 -0
- package/src/lib/errors.ts +187 -0
- package/src/lib/event-stream-response.ts +57 -0
- package/src/lib/event-target.ts +11 -0
- package/src/lib/fetch-api.ts +18 -0
- package/src/lib/map-share.ts +185 -0
- package/src/lib/secret-stream-fetch.ts +42 -0
- package/src/lib/self-evicting-map.ts +35 -0
- package/src/lib/state-update-event.ts +14 -0
- package/src/lib/utils.ts +110 -0
- package/src/middlewares/localhost-only.ts +16 -0
- package/src/middlewares/parse-request.ts +34 -0
- package/src/routes/downloads.ts +92 -0
- package/src/routes/map-shares.ts +246 -0
- package/src/routes/maps.ts +146 -0
- package/src/routes/root.ts +37 -0
- package/src/types.ts +152 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PonyfillAsyncDisposableStack = void 0;
|
|
4
|
+
const promise_helpers_1 = require("@whatwg-node/promise-helpers");
|
|
5
|
+
const SupressedError_js_1 = require("./SupressedError.js");
|
|
6
|
+
const symbols_js_1 = require("./symbols.js");
|
|
7
|
+
const utils_js_1 = require("./utils.js");
|
|
8
|
+
const SuppressedError = globalThis.SuppressedError || SupressedError_js_1.PonyfillSuppressedError;
|
|
9
|
+
class PonyfillAsyncDisposableStack {
|
|
10
|
+
callbacks = [];
|
|
11
|
+
get disposed() {
|
|
12
|
+
return this.callbacks.length === 0;
|
|
13
|
+
}
|
|
14
|
+
use(value) {
|
|
15
|
+
if ((0, utils_js_1.isAsyncDisposable)(value)) {
|
|
16
|
+
this.callbacks.push(() => value[symbols_js_1.DisposableSymbols.asyncDispose]());
|
|
17
|
+
}
|
|
18
|
+
else if ((0, utils_js_1.isSyncDisposable)(value)) {
|
|
19
|
+
this.callbacks.push(() => value[symbols_js_1.DisposableSymbols.dispose]());
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
adopt(value, onDisposeAsync) {
|
|
24
|
+
if (onDisposeAsync) {
|
|
25
|
+
this.callbacks.push(() => onDisposeAsync(value));
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
defer(onDisposeAsync) {
|
|
30
|
+
if (onDisposeAsync) {
|
|
31
|
+
this.callbacks.push(onDisposeAsync);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
move() {
|
|
35
|
+
const stack = new PonyfillAsyncDisposableStack();
|
|
36
|
+
stack.callbacks = this.callbacks;
|
|
37
|
+
this.callbacks = [];
|
|
38
|
+
return stack;
|
|
39
|
+
}
|
|
40
|
+
disposeAsync() {
|
|
41
|
+
return this[symbols_js_1.DisposableSymbols.asyncDispose]();
|
|
42
|
+
}
|
|
43
|
+
_error;
|
|
44
|
+
_iterateCallbacks() {
|
|
45
|
+
const cb = this.callbacks.pop();
|
|
46
|
+
if (cb) {
|
|
47
|
+
return (0, promise_helpers_1.handleMaybePromise)(cb, () => this._iterateCallbacks(), error => {
|
|
48
|
+
this._error = this._error ? new SuppressedError(error, this._error) : error;
|
|
49
|
+
return this._iterateCallbacks();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
[symbols_js_1.DisposableSymbols.asyncDispose]() {
|
|
54
|
+
const res$ = this._iterateCallbacks();
|
|
55
|
+
if (res$?.then) {
|
|
56
|
+
return res$.then(() => {
|
|
57
|
+
if (this._error) {
|
|
58
|
+
const error = this._error;
|
|
59
|
+
this._error = undefined;
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (this._error) {
|
|
65
|
+
const error = this._error;
|
|
66
|
+
this._error = undefined;
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
[Symbol.toStringTag] = 'AsyncDisposableStack';
|
|
72
|
+
}
|
|
73
|
+
exports.PonyfillAsyncDisposableStack = PonyfillAsyncDisposableStack;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PonyfillDisposableStack = void 0;
|
|
4
|
+
const SupressedError_js_1 = require("./SupressedError.js");
|
|
5
|
+
const symbols_js_1 = require("./symbols.js");
|
|
6
|
+
const utils_js_1 = require("./utils.js");
|
|
7
|
+
const SuppressedError = globalThis.SuppressedError || SupressedError_js_1.PonyfillSuppressedError;
|
|
8
|
+
class PonyfillDisposableStack {
|
|
9
|
+
callbacks = [];
|
|
10
|
+
get disposed() {
|
|
11
|
+
return this.callbacks.length === 0;
|
|
12
|
+
}
|
|
13
|
+
use(value) {
|
|
14
|
+
if ((0, utils_js_1.isSyncDisposable)(value)) {
|
|
15
|
+
this.callbacks.push(() => value[symbols_js_1.DisposableSymbols.dispose]());
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
adopt(value, onDispose) {
|
|
20
|
+
if (onDispose) {
|
|
21
|
+
this.callbacks.push(() => onDispose(value));
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
defer(onDispose) {
|
|
26
|
+
if (onDispose) {
|
|
27
|
+
this.callbacks.push(onDispose);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
move() {
|
|
31
|
+
const stack = new PonyfillDisposableStack();
|
|
32
|
+
stack.callbacks = this.callbacks;
|
|
33
|
+
this.callbacks = [];
|
|
34
|
+
return stack;
|
|
35
|
+
}
|
|
36
|
+
dispose() {
|
|
37
|
+
return this[symbols_js_1.DisposableSymbols.dispose]();
|
|
38
|
+
}
|
|
39
|
+
_error;
|
|
40
|
+
_iterateCallbacks() {
|
|
41
|
+
const cb = this.callbacks.pop();
|
|
42
|
+
if (cb) {
|
|
43
|
+
try {
|
|
44
|
+
cb();
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
this._error = this._error ? new SuppressedError(error, this._error) : error;
|
|
48
|
+
}
|
|
49
|
+
return this._iterateCallbacks();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
[symbols_js_1.DisposableSymbols.dispose]() {
|
|
53
|
+
this._iterateCallbacks();
|
|
54
|
+
if (this._error) {
|
|
55
|
+
const error = this._error;
|
|
56
|
+
this._error = undefined;
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
[Symbol.toStringTag] = 'DisposableStack';
|
|
61
|
+
}
|
|
62
|
+
exports.PonyfillDisposableStack = PonyfillDisposableStack;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PonyfillSuppressedError = void 0;
|
|
4
|
+
class PonyfillSuppressedError extends Error {
|
|
5
|
+
error;
|
|
6
|
+
suppressed;
|
|
7
|
+
// eslint-disable-next-line n/handle-callback-err
|
|
8
|
+
constructor(error, suppressed, message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.error = error;
|
|
11
|
+
this.suppressed = suppressed;
|
|
12
|
+
this.name = 'SuppressedError';
|
|
13
|
+
Error.captureStackTrace(this, this.constructor);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.PonyfillSuppressedError = PonyfillSuppressedError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SuppressedError = exports.AsyncDisposableStack = exports.DisposableStack = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const AsyncDisposableStack_js_1 = require("./AsyncDisposableStack.js");
|
|
6
|
+
const DisposableStack_js_1 = require("./DisposableStack.js");
|
|
7
|
+
const SupressedError_js_1 = require("./SupressedError.js");
|
|
8
|
+
exports.DisposableStack = globalThis.DisposableStack || DisposableStack_js_1.PonyfillDisposableStack;
|
|
9
|
+
exports.AsyncDisposableStack = globalThis.AsyncDisposableStack || AsyncDisposableStack_js_1.PonyfillAsyncDisposableStack;
|
|
10
|
+
exports.SuppressedError = globalThis.SuppressedError || SupressedError_js_1.PonyfillSuppressedError;
|
|
11
|
+
tslib_1.__exportStar(require("./symbols.js"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DisposableSymbols = void 0;
|
|
4
|
+
exports.patchSymbols = patchSymbols;
|
|
5
|
+
exports.DisposableSymbols = {
|
|
6
|
+
get dispose() {
|
|
7
|
+
return Symbol.dispose || Symbol.for('dispose');
|
|
8
|
+
},
|
|
9
|
+
get asyncDispose() {
|
|
10
|
+
return Symbol.asyncDispose || Symbol.for('asyncDispose');
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
function patchSymbols() {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
15
|
+
// @ts-ignore - we ponyfill these symbols
|
|
16
|
+
Symbol.dispose ||= Symbol.for('dispose');
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
18
|
+
// @ts-ignore - we ponyfill these symbols
|
|
19
|
+
Symbol.asyncDispose ||= Symbol.for('asyncDispose');
|
|
20
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSyncDisposable = isSyncDisposable;
|
|
4
|
+
exports.isAsyncDisposable = isAsyncDisposable;
|
|
5
|
+
const symbols_js_1 = require("./symbols.js");
|
|
6
|
+
function isSyncDisposable(obj) {
|
|
7
|
+
return obj?.[symbols_js_1.DisposableSymbols.dispose] != null;
|
|
8
|
+
}
|
|
9
|
+
function isAsyncDisposable(obj) {
|
|
10
|
+
return obj?.[symbols_js_1.DisposableSymbols.asyncDispose] != null;
|
|
11
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
|
|
2
|
+
import { PonyfillSuppressedError } from './SupressedError.js';
|
|
3
|
+
import { DisposableSymbols } from './symbols.js';
|
|
4
|
+
import { isAsyncDisposable, isSyncDisposable } from './utils.js';
|
|
5
|
+
const SuppressedError = globalThis.SuppressedError || PonyfillSuppressedError;
|
|
6
|
+
export class PonyfillAsyncDisposableStack {
|
|
7
|
+
callbacks = [];
|
|
8
|
+
get disposed() {
|
|
9
|
+
return this.callbacks.length === 0;
|
|
10
|
+
}
|
|
11
|
+
use(value) {
|
|
12
|
+
if (isAsyncDisposable(value)) {
|
|
13
|
+
this.callbacks.push(() => value[DisposableSymbols.asyncDispose]());
|
|
14
|
+
}
|
|
15
|
+
else if (isSyncDisposable(value)) {
|
|
16
|
+
this.callbacks.push(() => value[DisposableSymbols.dispose]());
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
adopt(value, onDisposeAsync) {
|
|
21
|
+
if (onDisposeAsync) {
|
|
22
|
+
this.callbacks.push(() => onDisposeAsync(value));
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
defer(onDisposeAsync) {
|
|
27
|
+
if (onDisposeAsync) {
|
|
28
|
+
this.callbacks.push(onDisposeAsync);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
move() {
|
|
32
|
+
const stack = new PonyfillAsyncDisposableStack();
|
|
33
|
+
stack.callbacks = this.callbacks;
|
|
34
|
+
this.callbacks = [];
|
|
35
|
+
return stack;
|
|
36
|
+
}
|
|
37
|
+
disposeAsync() {
|
|
38
|
+
return this[DisposableSymbols.asyncDispose]();
|
|
39
|
+
}
|
|
40
|
+
_error;
|
|
41
|
+
_iterateCallbacks() {
|
|
42
|
+
const cb = this.callbacks.pop();
|
|
43
|
+
if (cb) {
|
|
44
|
+
return handleMaybePromise(cb, () => this._iterateCallbacks(), error => {
|
|
45
|
+
this._error = this._error ? new SuppressedError(error, this._error) : error;
|
|
46
|
+
return this._iterateCallbacks();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
[DisposableSymbols.asyncDispose]() {
|
|
51
|
+
const res$ = this._iterateCallbacks();
|
|
52
|
+
if (res$?.then) {
|
|
53
|
+
return res$.then(() => {
|
|
54
|
+
if (this._error) {
|
|
55
|
+
const error = this._error;
|
|
56
|
+
this._error = undefined;
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (this._error) {
|
|
62
|
+
const error = this._error;
|
|
63
|
+
this._error = undefined;
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
[Symbol.toStringTag] = 'AsyncDisposableStack';
|
|
69
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { PonyfillSuppressedError } from './SupressedError.js';
|
|
2
|
+
import { DisposableSymbols } from './symbols.js';
|
|
3
|
+
import { isSyncDisposable } from './utils.js';
|
|
4
|
+
const SuppressedError = globalThis.SuppressedError || PonyfillSuppressedError;
|
|
5
|
+
export class PonyfillDisposableStack {
|
|
6
|
+
callbacks = [];
|
|
7
|
+
get disposed() {
|
|
8
|
+
return this.callbacks.length === 0;
|
|
9
|
+
}
|
|
10
|
+
use(value) {
|
|
11
|
+
if (isSyncDisposable(value)) {
|
|
12
|
+
this.callbacks.push(() => value[DisposableSymbols.dispose]());
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
adopt(value, onDispose) {
|
|
17
|
+
if (onDispose) {
|
|
18
|
+
this.callbacks.push(() => onDispose(value));
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
defer(onDispose) {
|
|
23
|
+
if (onDispose) {
|
|
24
|
+
this.callbacks.push(onDispose);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
move() {
|
|
28
|
+
const stack = new PonyfillDisposableStack();
|
|
29
|
+
stack.callbacks = this.callbacks;
|
|
30
|
+
this.callbacks = [];
|
|
31
|
+
return stack;
|
|
32
|
+
}
|
|
33
|
+
dispose() {
|
|
34
|
+
return this[DisposableSymbols.dispose]();
|
|
35
|
+
}
|
|
36
|
+
_error;
|
|
37
|
+
_iterateCallbacks() {
|
|
38
|
+
const cb = this.callbacks.pop();
|
|
39
|
+
if (cb) {
|
|
40
|
+
try {
|
|
41
|
+
cb();
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
this._error = this._error ? new SuppressedError(error, this._error) : error;
|
|
45
|
+
}
|
|
46
|
+
return this._iterateCallbacks();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
[DisposableSymbols.dispose]() {
|
|
50
|
+
this._iterateCallbacks();
|
|
51
|
+
if (this._error) {
|
|
52
|
+
const error = this._error;
|
|
53
|
+
this._error = undefined;
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
[Symbol.toStringTag] = 'DisposableStack';
|
|
58
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class PonyfillSuppressedError extends Error {
|
|
2
|
+
error;
|
|
3
|
+
suppressed;
|
|
4
|
+
// eslint-disable-next-line n/handle-callback-err
|
|
5
|
+
constructor(error, suppressed, message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.error = error;
|
|
8
|
+
this.suppressed = suppressed;
|
|
9
|
+
this.name = 'SuppressedError';
|
|
10
|
+
Error.captureStackTrace(this, this.constructor);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PonyfillAsyncDisposableStack } from './AsyncDisposableStack.js';
|
|
2
|
+
import { PonyfillDisposableStack } from './DisposableStack.js';
|
|
3
|
+
import { PonyfillSuppressedError } from './SupressedError.js';
|
|
4
|
+
export const DisposableStack = globalThis.DisposableStack || PonyfillDisposableStack;
|
|
5
|
+
export const AsyncDisposableStack = globalThis.AsyncDisposableStack || PonyfillAsyncDisposableStack;
|
|
6
|
+
export const SuppressedError = globalThis.SuppressedError || PonyfillSuppressedError;
|
|
7
|
+
export * from './symbols.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const DisposableSymbols = {
|
|
2
|
+
get dispose() {
|
|
3
|
+
return Symbol.dispose || Symbol.for('dispose');
|
|
4
|
+
},
|
|
5
|
+
get asyncDispose() {
|
|
6
|
+
return Symbol.asyncDispose || Symbol.for('asyncDispose');
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
export function patchSymbols() {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
11
|
+
// @ts-ignore - we ponyfill these symbols
|
|
12
|
+
Symbol.dispose ||= Symbol.for('dispose');
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
14
|
+
// @ts-ignore - we ponyfill these symbols
|
|
15
|
+
Symbol.asyncDispose ||= Symbol.for('asyncDispose');
|
|
16
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@whatwg-node/disposablestack",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"description": "Cross Platform Smart DisposableStack API Ponyfill",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@whatwg-node/promise-helpers": "^1.0.0",
|
|
8
|
+
"tslib": "^2.6.3"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "ardatan/whatwg-node",
|
|
13
|
+
"directory": "packages/disposablestack"
|
|
14
|
+
},
|
|
15
|
+
"author": "Arda TANRIKULU <ardatanrikulu@gmail.com>",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18.0.0"
|
|
19
|
+
},
|
|
20
|
+
"main": "cjs/index.js",
|
|
21
|
+
"module": "esm/index.js",
|
|
22
|
+
"typings": "typings/index.d.ts",
|
|
23
|
+
"typescript": {
|
|
24
|
+
"definition": "typings/index.d.ts"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./typings/index.d.cts",
|
|
31
|
+
"default": "./cjs/index.js"
|
|
32
|
+
},
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./typings/index.d.ts",
|
|
35
|
+
"default": "./esm/index.js"
|
|
36
|
+
},
|
|
37
|
+
"default": {
|
|
38
|
+
"types": "./typings/index.d.ts",
|
|
39
|
+
"default": "./esm/index.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"./package.json": "./package.json"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type MaybePromiseLike } from '@whatwg-node/promise-helpers';
|
|
2
|
+
import { DisposableSymbols } from './symbols.cjs';
|
|
3
|
+
export declare class PonyfillAsyncDisposableStack implements AsyncDisposableStack {
|
|
4
|
+
private callbacks;
|
|
5
|
+
get disposed(): boolean;
|
|
6
|
+
use<T extends AsyncDisposable | Disposable | null | undefined>(value: T): T;
|
|
7
|
+
adopt<T>(value: T, onDisposeAsync: (value: T) => MaybePromiseLike<void>): T;
|
|
8
|
+
defer(onDisposeAsync: () => MaybePromiseLike<void>): void;
|
|
9
|
+
move(): AsyncDisposableStack;
|
|
10
|
+
disposeAsync(): Promise<void>;
|
|
11
|
+
private _error?;
|
|
12
|
+
private _iterateCallbacks;
|
|
13
|
+
[DisposableSymbols.asyncDispose](): Promise<void>;
|
|
14
|
+
readonly [Symbol.toStringTag]: string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type MaybePromiseLike } from '@whatwg-node/promise-helpers';
|
|
2
|
+
import { DisposableSymbols } from './symbols.js';
|
|
3
|
+
export declare class PonyfillAsyncDisposableStack implements AsyncDisposableStack {
|
|
4
|
+
private callbacks;
|
|
5
|
+
get disposed(): boolean;
|
|
6
|
+
use<T extends AsyncDisposable | Disposable | null | undefined>(value: T): T;
|
|
7
|
+
adopt<T>(value: T, onDisposeAsync: (value: T) => MaybePromiseLike<void>): T;
|
|
8
|
+
defer(onDisposeAsync: () => MaybePromiseLike<void>): void;
|
|
9
|
+
move(): AsyncDisposableStack;
|
|
10
|
+
disposeAsync(): Promise<void>;
|
|
11
|
+
private _error?;
|
|
12
|
+
private _iterateCallbacks;
|
|
13
|
+
[DisposableSymbols.asyncDispose](): Promise<void>;
|
|
14
|
+
readonly [Symbol.toStringTag]: string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DisposableSymbols } from './symbols.cjs';
|
|
2
|
+
export declare class PonyfillDisposableStack implements DisposableStack {
|
|
3
|
+
private callbacks;
|
|
4
|
+
get disposed(): boolean;
|
|
5
|
+
use<T extends Disposable | null | undefined>(value: T): T;
|
|
6
|
+
adopt<T>(value: T, onDispose: (value: T) => void): T;
|
|
7
|
+
defer(onDispose: () => void): void;
|
|
8
|
+
move(): DisposableStack;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
private _error?;
|
|
11
|
+
private _iterateCallbacks;
|
|
12
|
+
[DisposableSymbols.dispose](): void;
|
|
13
|
+
readonly [Symbol.toStringTag]: string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DisposableSymbols } from './symbols.js';
|
|
2
|
+
export declare class PonyfillDisposableStack implements DisposableStack {
|
|
3
|
+
private callbacks;
|
|
4
|
+
get disposed(): boolean;
|
|
5
|
+
use<T extends Disposable | null | undefined>(value: T): T;
|
|
6
|
+
adopt<T>(value: T, onDispose: (value: T) => void): T;
|
|
7
|
+
defer(onDispose: () => void): void;
|
|
8
|
+
move(): DisposableStack;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
private _error?;
|
|
11
|
+
private _iterateCallbacks;
|
|
12
|
+
[DisposableSymbols.dispose](): void;
|
|
13
|
+
readonly [Symbol.toStringTag]: string;
|
|
14
|
+
}
|