@dxos/context 0.1.2 → 0.1.16
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/LICENSE +5 -18
- package/dist/lib/browser/index.mjs +96 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/node/index.cjs +123 -0
- package/dist/lib/node/index.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -0
- package/dist/{src → types/src}/context.d.ts +2 -5
- package/dist/types/src/context.d.ts.map +1 -0
- package/dist/{src → types/src}/context.test.d.ts +0 -0
- package/dist/{src → types/src}/context.test.d.ts.map +1 -1
- package/dist/{src → types/src}/index.d.ts +0 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/package.json +8 -7
- package/src/context.test.ts +24 -9
- package/src/context.ts +11 -14
- package/dist/src/context.d.ts.map +0 -1
- package/dist/src/context.js +0 -103
- package/dist/src/context.js.map +0 -1
- package/dist/src/context.test.js +0 -40
- package/dist/src/context.test.js.map +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -21
- package/dist/src/index.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
MIT License
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2022 DXOS
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
11
7
|
|
|
12
|
-
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// packages/common/context/src/context.ts
|
|
2
|
+
import { log } from "@dxos/log";
|
|
3
|
+
import { safeInstanceof } from "@dxos/util";
|
|
4
|
+
var __decorate = function(decorators, target, key, desc) {
|
|
5
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
7
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
+
else
|
|
9
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
10
|
+
if (d = decorators[i])
|
|
11
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
12
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13
|
+
};
|
|
14
|
+
var Context = class Context1 {
|
|
15
|
+
constructor({ onError = (error) => {
|
|
16
|
+
void this.dispose();
|
|
17
|
+
throw error;
|
|
18
|
+
} } = {}) {
|
|
19
|
+
this._disposeCallbacks = [];
|
|
20
|
+
this._isDisposed = false;
|
|
21
|
+
this._onError = onError;
|
|
22
|
+
}
|
|
23
|
+
get disposed() {
|
|
24
|
+
return this._isDisposed;
|
|
25
|
+
}
|
|
26
|
+
onDispose(callback) {
|
|
27
|
+
if (this._isDisposed) {
|
|
28
|
+
throw new Error("Context is already disposed");
|
|
29
|
+
}
|
|
30
|
+
this._disposeCallbacks.push(callback);
|
|
31
|
+
}
|
|
32
|
+
dispose() {
|
|
33
|
+
if (this._disposePromise) {
|
|
34
|
+
return this._disposePromise;
|
|
35
|
+
}
|
|
36
|
+
this._isDisposed = true;
|
|
37
|
+
const promises = [];
|
|
38
|
+
for (const callback of this._disposeCallbacks.reverse()) {
|
|
39
|
+
promises.push((async () => {
|
|
40
|
+
try {
|
|
41
|
+
await callback();
|
|
42
|
+
} catch (error) {
|
|
43
|
+
log.catch(error, {}, {
|
|
44
|
+
file: "/home/runner/work/dxos/dxos/packages/common/context/src/context.ts",
|
|
45
|
+
line: 72,
|
|
46
|
+
scope: this,
|
|
47
|
+
callSite: (f, a) => f(...a)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
})());
|
|
51
|
+
}
|
|
52
|
+
this._disposeCallbacks.length = 0;
|
|
53
|
+
return this._disposePromise = Promise.all(promises).then(() => {
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
raise(error) {
|
|
57
|
+
if (this._isDisposed) {
|
|
58
|
+
log.warn("Error in disposed context", error, {
|
|
59
|
+
file: "/home/runner/work/dxos/dxos/packages/common/context/src/context.ts",
|
|
60
|
+
line: 89,
|
|
61
|
+
scope: this,
|
|
62
|
+
callSite: (f, a) => f(...a)
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
this._onError(error);
|
|
68
|
+
} catch (err) {
|
|
69
|
+
void Promise.reject(err);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
derive({ onError }) {
|
|
73
|
+
const newCtx = new Context({
|
|
74
|
+
onError: async (error) => {
|
|
75
|
+
if (!onError) {
|
|
76
|
+
this.raise(error);
|
|
77
|
+
} else {
|
|
78
|
+
try {
|
|
79
|
+
await onError(error);
|
|
80
|
+
} catch (e) {
|
|
81
|
+
this.raise(error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
this.onDispose(() => newCtx.dispose());
|
|
87
|
+
return newCtx;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
Context = __decorate([
|
|
91
|
+
safeInstanceof("Context")
|
|
92
|
+
], Context);
|
|
93
|
+
export {
|
|
94
|
+
Context
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/home/runner/work/dxos/dxos/packages/common/context/src/context.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { log } from '@dxos/log';\nimport { safeInstanceof } from '@dxos/util';\n\nexport type ContextErrorHandler = (error: Error) => void;\n\nexport type DisposeCallback = () => void | Promise<void>;\n\nexport type CreateContextParams = {\n onError?: ContextErrorHandler;\n};\n\n@safeInstanceof('Context')\nexport class Context {\n private readonly _onError: ContextErrorHandler;\n private readonly _disposeCallbacks: DisposeCallback[] = [];\n private _isDisposed = false;\n private _disposePromise?: Promise<void>;\n\n constructor({\n onError = (error) => {\n void this.dispose();\n\n // Will generate an unhandled rejection.\n throw error;\n }\n }: CreateContextParams = {}) {\n this._onError = onError;\n }\n\n get disposed() {\n return this._isDisposed;\n }\n\n /**\n * Schedules a callback to run when the context is disposed.\n * May be async, in this case the disposer might choose to wait for all resource to released.\n * Throwing an error inside the callback will result in the error being logged, but not re-thrown.\n */\n onDispose(callback: DisposeCallback) {\n if (this._isDisposed) {\n throw new Error('Context is already disposed');\n }\n\n this._disposeCallbacks.push(callback);\n }\n\n /**\n * Runs all dispose callbacks.\n * Sync callbacks are run in the reverse order they were added.\n * Async callbacks are run in parallel.\n * This function never throws.\n * It is safe to ignore the returned promise if the caller does not wish to wait for callbacks to complete.\n * Disposing context means that onDispose will throw an error and any errors raised will be logged and not propagated.\n */\n dispose(): Promise<void> {\n if (this._disposePromise) {\n return this._disposePromise;\n }\n this._isDisposed = true;\n\n const promises = [];\n for (const callback of this._disposeCallbacks.reverse()) {\n promises.push(\n (async () => {\n try {\n await callback();\n } catch (error: any) {\n log.catch(error);\n }\n })()\n );\n }\n this._disposeCallbacks.length = 0;\n\n return (this._disposePromise = Promise.all(promises).then(() => {}));\n }\n\n /**\n * Raise the error inside the context.\n * The error will be propagated to the error handler.\n * IF the error handler is not set, the error will dispose the context and cause an unhandled rejection.\n */\n raise(error: Error): void {\n if (this._isDisposed) {\n log.warn('Error in disposed context', error);\n return;\n }\n\n try {\n this._onError(error);\n } catch (err) {\n // Generate an unhandled rejection and stop the error propagation.\n void Promise.reject(err);\n }\n }\n\n derive({ onError }: CreateContextParams): Context {\n const newCtx = new Context({\n onError: async (error) => {\n if (!onError) {\n this.raise(error);\n } else {\n try {\n await onError(error);\n } catch {\n this.raise(error);\n }\n }\n }\n });\n this.onDispose(() => newCtx.dispose());\n return newCtx;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,WAAW;AACpB,SAASC,sBAAsB;AAD/B,IAAA,aAAA,SAAA,YAAA,QAAA,KAAA,MAAA;;;;;;;;;;AAYA,IAAaC,UAAN,MAAA,SAAA;EAMLC,YAAY,EACVC,UAAU,CAACC,UAAU;AACnB,SAAK,KAAKC,QAAO;AAGjB,UAAMD;EACR,EAAC,IACsB,CAAC,GAAG;AAXZE,6BAAuC,CAAA;AAChDC,uBAAc;AAWpB,SAAKC,WAAWL;EAClB;EAEA,IAAIM,WAAW;AACb,WAAO,KAAKF;EACd;EAOAG,UAAUC,UAA2B;AACnC,QAAI,KAAKJ,aAAa;AACpB,YAAM,IAAIK,MAAM,6BAAA;IAClB;AAEA,SAAKN,kBAAkBO,KAAKF,QAAAA;EAC9B;EAUAN,UAAyB;AACvB,QAAI,KAAKS,iBAAiB;AACxB,aAAO,KAAKA;IACd;AACA,SAAKP,cAAc;AAEnB,UAAMQ,WAAW,CAAA;AACjB,eAAWJ,YAAY,KAAKL,kBAAkBU,QAAO,GAAI;AACvDD,eAASF,MACN,YAAY;AACX,YAAI;AACF,gBAAMF,SAAAA;QACR,SAASP,OAAP;AACAL,cAAIkB,MAAMb,OAAAA,CAAAA,GAAAA;;;;;;QACZ;MACF,GAAA,CAAA;IAEJ;AACA,SAAKE,kBAAkBY,SAAS;AAEhC,WAAQ,KAAKJ,kBAAkBK,QAAQC,IAAIL,QAAAA,EAAUM,KAAK,MAAM;IAAC,CAAA;EACnE;EAOAC,MAAMlB,OAAoB;AACxB,QAAI,KAAKG,aAAa;AACpBR,UAAIwB,KAAK,6BAA6BnB,OAAAA;;;;;;AACtC;IACF;AAEA,QAAI;AACF,WAAKI,SAASJ,KAAAA;IAChB,SAASoB,KAAP;AAEA,WAAKL,QAAQM,OAAOD,GAAAA;IACtB;EACF;EAEAE,OAAO,EAAEvB,QAAO,GAAkC;AAChD,UAAMwB,SAAS,IAAI1B,QAAQ;MACzBE,SAAS,OAAOC,UAAU;AACxB,YAAI,CAACD,SAAS;AACZ,eAAKmB,MAAMlB,KAAAA;QACb,OAAO;AACL,cAAI;AACF,kBAAMD,QAAQC,KAAAA;UAChB,SAAQ,GAAN;AACA,iBAAKkB,MAAMlB,KAAAA;UACb;QACF;MACF;IACF,CAAA;AACA,SAAKM,UAAU,MAAMiB,OAAOtB,QAAO,CAAA;AACnC,WAAOsB;EACT;AACF;AArGa1B,UAAAA,WAAAA;EADZD,eAAe,SAAA;GACHC,OAAAA;",
|
|
6
|
+
"names": ["log", "safeInstanceof", "Context", "constructor", "onError", "error", "dispose", "_disposeCallbacks", "_isDisposed", "_onError", "disposed", "onDispose", "callback", "Error", "push", "_disposePromise", "promises", "reverse", "catch", "length", "Promise", "all", "then", "raise", "warn", "err", "reject", "derive", "newCtx"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"packages/common/context/src/context.ts":{"bytes":11074,"imports":[]},"packages/common/context/src/index.ts":{"bytes":447,"imports":[{"path":"packages/common/context/src/context.ts","kind":"import-statement"}]}},"outputs":{"packages/common/context/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5050},"packages/common/context/dist/lib/browser/index.mjs":{"imports":[],"exports":["Context"],"entryPoint":"packages/common/context/src/index.ts","inputs":{"packages/common/context/src/context.ts":{"bytesInOutput":2570},"packages/common/context/src/index.ts":{"bytesInOutput":0}},"bytes":2669}}}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/common/context/src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
Context: () => Context
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// packages/common/context/src/context.ts
|
|
28
|
+
var import_log = require("@dxos/log");
|
|
29
|
+
var import_util = require("@dxos/util");
|
|
30
|
+
var __decorate = function(decorators, target, key, desc) {
|
|
31
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
32
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
33
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
34
|
+
else
|
|
35
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
36
|
+
if (d = decorators[i])
|
|
37
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
38
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
39
|
+
};
|
|
40
|
+
var Context = class Context1 {
|
|
41
|
+
constructor({ onError = (error) => {
|
|
42
|
+
void this.dispose();
|
|
43
|
+
throw error;
|
|
44
|
+
} } = {}) {
|
|
45
|
+
this._disposeCallbacks = [];
|
|
46
|
+
this._isDisposed = false;
|
|
47
|
+
this._onError = onError;
|
|
48
|
+
}
|
|
49
|
+
get disposed() {
|
|
50
|
+
return this._isDisposed;
|
|
51
|
+
}
|
|
52
|
+
onDispose(callback) {
|
|
53
|
+
if (this._isDisposed) {
|
|
54
|
+
throw new Error("Context is already disposed");
|
|
55
|
+
}
|
|
56
|
+
this._disposeCallbacks.push(callback);
|
|
57
|
+
}
|
|
58
|
+
dispose() {
|
|
59
|
+
if (this._disposePromise) {
|
|
60
|
+
return this._disposePromise;
|
|
61
|
+
}
|
|
62
|
+
this._isDisposed = true;
|
|
63
|
+
const promises = [];
|
|
64
|
+
for (const callback of this._disposeCallbacks.reverse()) {
|
|
65
|
+
promises.push((async () => {
|
|
66
|
+
try {
|
|
67
|
+
await callback();
|
|
68
|
+
} catch (error) {
|
|
69
|
+
import_log.log.catch(error, {}, {
|
|
70
|
+
file: "/home/runner/work/dxos/dxos/packages/common/context/src/context.ts",
|
|
71
|
+
line: 72,
|
|
72
|
+
scope: this,
|
|
73
|
+
callSite: (f, a) => f(...a)
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
})());
|
|
77
|
+
}
|
|
78
|
+
this._disposeCallbacks.length = 0;
|
|
79
|
+
return this._disposePromise = Promise.all(promises).then(() => {
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
raise(error) {
|
|
83
|
+
if (this._isDisposed) {
|
|
84
|
+
import_log.log.warn("Error in disposed context", error, {
|
|
85
|
+
file: "/home/runner/work/dxos/dxos/packages/common/context/src/context.ts",
|
|
86
|
+
line: 89,
|
|
87
|
+
scope: this,
|
|
88
|
+
callSite: (f, a) => f(...a)
|
|
89
|
+
});
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
this._onError(error);
|
|
94
|
+
} catch (err) {
|
|
95
|
+
void Promise.reject(err);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
derive({ onError }) {
|
|
99
|
+
const newCtx = new Context({
|
|
100
|
+
onError: async (error) => {
|
|
101
|
+
if (!onError) {
|
|
102
|
+
this.raise(error);
|
|
103
|
+
} else {
|
|
104
|
+
try {
|
|
105
|
+
await onError(error);
|
|
106
|
+
} catch (e) {
|
|
107
|
+
this.raise(error);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
this.onDispose(() => newCtx.dispose());
|
|
113
|
+
return newCtx;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
Context = __decorate([
|
|
117
|
+
(0, import_util.safeInstanceof)("Context")
|
|
118
|
+
], Context);
|
|
119
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
120
|
+
0 && (module.exports = {
|
|
121
|
+
Context
|
|
122
|
+
});
|
|
123
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/home/runner/work/dxos/dxos/packages/common/context/src/index.ts", "../../../src/home/runner/work/dxos/dxos/packages/common/context/src/context.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nexport * from './context';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { log } from '@dxos/log';\nimport { safeInstanceof } from '@dxos/util';\n\nexport type ContextErrorHandler = (error: Error) => void;\n\nexport type DisposeCallback = () => void | Promise<void>;\n\nexport type CreateContextParams = {\n onError?: ContextErrorHandler;\n};\n\n@safeInstanceof('Context')\nexport class Context {\n private readonly _onError: ContextErrorHandler;\n private readonly _disposeCallbacks: DisposeCallback[] = [];\n private _isDisposed = false;\n private _disposePromise?: Promise<void>;\n\n constructor({\n onError = (error) => {\n void this.dispose();\n\n // Will generate an unhandled rejection.\n throw error;\n }\n }: CreateContextParams = {}) {\n this._onError = onError;\n }\n\n get disposed() {\n return this._isDisposed;\n }\n\n /**\n * Schedules a callback to run when the context is disposed.\n * May be async, in this case the disposer might choose to wait for all resource to released.\n * Throwing an error inside the callback will result in the error being logged, but not re-thrown.\n */\n onDispose(callback: DisposeCallback) {\n if (this._isDisposed) {\n throw new Error('Context is already disposed');\n }\n\n this._disposeCallbacks.push(callback);\n }\n\n /**\n * Runs all dispose callbacks.\n * Sync callbacks are run in the reverse order they were added.\n * Async callbacks are run in parallel.\n * This function never throws.\n * It is safe to ignore the returned promise if the caller does not wish to wait for callbacks to complete.\n * Disposing context means that onDispose will throw an error and any errors raised will be logged and not propagated.\n */\n dispose(): Promise<void> {\n if (this._disposePromise) {\n return this._disposePromise;\n }\n this._isDisposed = true;\n\n const promises = [];\n for (const callback of this._disposeCallbacks.reverse()) {\n promises.push(\n (async () => {\n try {\n await callback();\n } catch (error: any) {\n log.catch(error);\n }\n })()\n );\n }\n this._disposeCallbacks.length = 0;\n\n return (this._disposePromise = Promise.all(promises).then(() => {}));\n }\n\n /**\n * Raise the error inside the context.\n * The error will be propagated to the error handler.\n * IF the error handler is not set, the error will dispose the context and cause an unhandled rejection.\n */\n raise(error: Error): void {\n if (this._isDisposed) {\n log.warn('Error in disposed context', error);\n return;\n }\n\n try {\n this._onError(error);\n } catch (err) {\n // Generate an unhandled rejection and stop the error propagation.\n void Promise.reject(err);\n }\n }\n\n derive({ onError }: CreateContextParams): Context {\n const newCtx = new Context({\n onError: async (error) => {\n if (!onError) {\n this.raise(error);\n } else {\n try {\n await onError(error);\n } catch {\n this.raise(error);\n }\n }\n }\n });\n this.onDispose(() => newCtx.dispose());\n return newCtx;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACIA,iBAAoB;AACpB,kBAA+B;AAD/B,IAAA,aAAA,SAAA,YAAA,QAAA,KAAA,MAAA;;;;;;;;;;AAYA,IAAaA,UAAN,MAAA,SAAA;EAMLC,YAAY,EACVC,UAAU,CAACC,UAAU;AACnB,SAAK,KAAKC,QAAO;AAGjB,UAAMD;EACR,EAAC,IACsB,CAAC,GAAG;AAXZE,6BAAuC,CAAA;AAChDC,uBAAc;AAWpB,SAAKC,WAAWL;EAClB;EAEA,IAAIM,WAAW;AACb,WAAO,KAAKF;EACd;EAOAG,UAAUC,UAA2B;AACnC,QAAI,KAAKJ,aAAa;AACpB,YAAM,IAAIK,MAAM,6BAAA;IAClB;AAEA,SAAKN,kBAAkBO,KAAKF,QAAAA;EAC9B;EAUAN,UAAyB;AACvB,QAAI,KAAKS,iBAAiB;AACxB,aAAO,KAAKA;IACd;AACA,SAAKP,cAAc;AAEnB,UAAMQ,WAAW,CAAA;AACjB,eAAWJ,YAAY,KAAKL,kBAAkBU,QAAO,GAAI;AACvDD,eAASF,MACN,YAAY;AACX,YAAI;AACF,gBAAMF,SAAAA;QACR,SAASP,OAAP;AACAa,yBAAIC,MAAMd,OAAAA,CAAAA,GAAAA;;;;;;QACZ;MACF,GAAA,CAAA;IAEJ;AACA,SAAKE,kBAAkBa,SAAS;AAEhC,WAAQ,KAAKL,kBAAkBM,QAAQC,IAAIN,QAAAA,EAAUO,KAAK,MAAM;IAAC,CAAA;EACnE;EAOAC,MAAMnB,OAAoB;AACxB,QAAI,KAAKG,aAAa;AACpBU,qBAAIO,KAAK,6BAA6BpB,OAAAA;;;;;;AACtC;IACF;AAEA,QAAI;AACF,WAAKI,SAASJ,KAAAA;IAChB,SAASqB,KAAP;AAEA,WAAKL,QAAQM,OAAOD,GAAAA;IACtB;EACF;EAEAE,OAAO,EAAExB,QAAO,GAAkC;AAChD,UAAMyB,SAAS,IAAI3B,QAAQ;MACzBE,SAAS,OAAOC,UAAU;AACxB,YAAI,CAACD,SAAS;AACZ,eAAKoB,MAAMnB,KAAAA;QACb,OAAO;AACL,cAAI;AACF,kBAAMD,QAAQC,KAAAA;UAChB,SAAQ,GAAN;AACA,iBAAKmB,MAAMnB,KAAAA;UACb;QACF;MACF;IACF,CAAA;AACA,SAAKM,UAAU,MAAMkB,OAAOvB,QAAO,CAAA;AACnC,WAAOuB;EACT;AACF;AArGa3B,UAAAA,WAAAA;MADZ4B,4BAAe,SAAA;GACH5B,OAAAA;",
|
|
6
|
+
"names": ["Context", "constructor", "onError", "error", "dispose", "_disposeCallbacks", "_isDisposed", "_onError", "disposed", "onDispose", "callback", "Error", "push", "_disposePromise", "promises", "reverse", "log", "catch", "length", "Promise", "all", "then", "raise", "warn", "err", "reject", "derive", "newCtx", "safeInstanceof"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"packages/common/context/src/context.ts":{"bytes":11074,"imports":[]},"packages/common/context/src/index.ts":{"bytes":447,"imports":[{"path":"packages/common/context/src/context.ts","kind":"import-statement"}]}},"outputs":{"packages/common/context/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5223},"packages/common/context/dist/lib/node/index.cjs":{"imports":[],"exports":[],"entryPoint":"packages/common/context/src/index.ts","inputs":{"packages/common/context/src/index.ts":{"bytesInOutput":119},"packages/common/context/src/context.ts":{"bytesInOutput":2611}},"bytes":3749}}}
|
|
@@ -4,15 +4,12 @@ export declare type CreateContextParams = {
|
|
|
4
4
|
onError?: ContextErrorHandler;
|
|
5
5
|
};
|
|
6
6
|
export declare class Context {
|
|
7
|
-
private readonly _isContext;
|
|
8
|
-
/**
|
|
9
|
-
* Checks if the object is a context. Not susceptible to prototype duplication that could happen during bundling.
|
|
10
|
-
*/
|
|
11
|
-
static isContext(value: unknown): value is Context;
|
|
12
7
|
private readonly _onError;
|
|
13
8
|
private readonly _disposeCallbacks;
|
|
14
9
|
private _isDisposed;
|
|
10
|
+
private _disposePromise?;
|
|
15
11
|
constructor({ onError }?: CreateContextParams);
|
|
12
|
+
get disposed(): boolean;
|
|
16
13
|
/**
|
|
17
14
|
* Schedules a callback to run when the context is disposed.
|
|
18
15
|
* May be async, in this case the disposer might choose to wait for all resource to released.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/context.ts"],"names":[],"mappings":"AAOA,oBAAY,mBAAmB,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;AAEzD,oBAAY,eAAe,GAAG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzD,oBAAY,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,mBAAmB,CAAC;CAC/B,CAAC;AAEF,qBACa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsB;IAC/C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAyB;IAC3D,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,eAAe,CAAC,CAAgB;gBAE5B,EACV,OAKC,EACF,GAAE,mBAAwB;IAI3B,IAAI,QAAQ,YAEX;IAED;;;;OAIG;IACH,SAAS,CAAC,QAAQ,EAAE,eAAe;IAQnC;;;;;;;OAOG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAuBxB;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAczB,MAAM,CAAC,EAAE,OAAO,EAAE,EAAE,mBAAmB,GAAG,OAAO;CAiBlD"}
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.test.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"context.test.d.ts","sourceRoot":"","sources":["../../../src/context.test.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/context",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "Async utils.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "DXOS.org",
|
|
9
|
-
"main": "dist/
|
|
10
|
-
"
|
|
9
|
+
"main": "dist/lib/node/index.cjs",
|
|
10
|
+
"browser": {
|
|
11
|
+
"./dist/lib/node/index.cjs": "./dist/lib/browser/index.mjs"
|
|
12
|
+
},
|
|
13
|
+
"types": "dist/types/src/index.d.ts",
|
|
11
14
|
"files": [
|
|
12
15
|
"dist",
|
|
13
16
|
"src"
|
|
14
17
|
],
|
|
15
18
|
"dependencies": {
|
|
16
|
-
"@dxos/log": "0.1.
|
|
19
|
+
"@dxos/log": "0.1.16",
|
|
20
|
+
"@dxos/util": "0.1.16"
|
|
17
21
|
},
|
|
18
22
|
"publishConfig": {
|
|
19
23
|
"access": "public"
|
|
20
|
-
},
|
|
21
|
-
"scripts": {
|
|
22
|
-
"check": "true"
|
|
23
24
|
}
|
|
24
25
|
}
|
package/src/context.test.ts
CHANGED
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import expect from 'expect';
|
|
6
6
|
|
|
7
|
+
import { describe, test } from '@dxos/test';
|
|
8
|
+
|
|
7
9
|
import { Context } from './context';
|
|
8
10
|
|
|
9
|
-
describe('Context',
|
|
10
|
-
|
|
11
|
+
describe('Context', () => {
|
|
12
|
+
test('dispose calls dispose hooks', () => {
|
|
11
13
|
const ctx = new Context();
|
|
12
14
|
|
|
13
15
|
let called = false;
|
|
@@ -19,11 +21,11 @@ describe('Context', function () {
|
|
|
19
21
|
expect(called).toBeTruthy();
|
|
20
22
|
});
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
test('dispose waits for async callbacks', () => {});
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
test('error in dispose callbacks are not propagated', () => {});
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
test('raised errors are propagated to the error handler', () => {
|
|
27
29
|
let error!: Error;
|
|
28
30
|
const ctx = new Context({
|
|
29
31
|
onError: (err) => {
|
|
@@ -35,12 +37,25 @@ describe('Context', function () {
|
|
|
35
37
|
expect(error.message).toEqual('test');
|
|
36
38
|
});
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
test('instanceof', () => {
|
|
39
41
|
const ctx = new Context();
|
|
40
|
-
expect(Context
|
|
42
|
+
expect(ctx instanceof Context).toBeTruthy();
|
|
43
|
+
|
|
44
|
+
expect({} instanceof Context).toBeFalsy();
|
|
41
45
|
|
|
42
|
-
expect(
|
|
46
|
+
expect((undefined as any) instanceof Context).toBeFalsy();
|
|
47
|
+
});
|
|
43
48
|
|
|
44
|
-
|
|
49
|
+
test('dispose is idempotent', () => {
|
|
50
|
+
const ctx = new Context();
|
|
51
|
+
|
|
52
|
+
let called = false;
|
|
53
|
+
ctx.onDispose(() => {
|
|
54
|
+
called = true;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
void ctx.dispose();
|
|
58
|
+
void ctx.dispose();
|
|
59
|
+
expect(called).toBeTruthy();
|
|
45
60
|
});
|
|
46
61
|
});
|
package/src/context.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { log } from '@dxos/log';
|
|
6
|
+
import { safeInstanceof } from '@dxos/util';
|
|
6
7
|
|
|
7
8
|
export type ContextErrorHandler = (error: Error) => void;
|
|
8
9
|
|
|
@@ -12,20 +13,12 @@ export type CreateContextParams = {
|
|
|
12
13
|
onError?: ContextErrorHandler;
|
|
13
14
|
};
|
|
14
15
|
|
|
16
|
+
@safeInstanceof('Context')
|
|
15
17
|
export class Context {
|
|
16
|
-
// Marker for the isContext method.
|
|
17
|
-
private readonly _isContext = true;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Checks if the object is a context. Not susceptible to prototype duplication that could happen during bundling.
|
|
21
|
-
*/
|
|
22
|
-
static isContext(value: unknown): value is Context {
|
|
23
|
-
return (value as Context)?._isContext === true;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
18
|
private readonly _onError: ContextErrorHandler;
|
|
27
19
|
private readonly _disposeCallbacks: DisposeCallback[] = [];
|
|
28
20
|
private _isDisposed = false;
|
|
21
|
+
private _disposePromise?: Promise<void>;
|
|
29
22
|
|
|
30
23
|
constructor({
|
|
31
24
|
onError = (error) => {
|
|
@@ -38,6 +31,10 @@ export class Context {
|
|
|
38
31
|
this._onError = onError;
|
|
39
32
|
}
|
|
40
33
|
|
|
34
|
+
get disposed() {
|
|
35
|
+
return this._isDisposed;
|
|
36
|
+
}
|
|
37
|
+
|
|
41
38
|
/**
|
|
42
39
|
* Schedules a callback to run when the context is disposed.
|
|
43
40
|
* May be async, in this case the disposer might choose to wait for all resource to released.
|
|
@@ -60,8 +57,8 @@ export class Context {
|
|
|
60
57
|
* Disposing context means that onDispose will throw an error and any errors raised will be logged and not propagated.
|
|
61
58
|
*/
|
|
62
59
|
dispose(): Promise<void> {
|
|
63
|
-
if (this.
|
|
64
|
-
|
|
60
|
+
if (this._disposePromise) {
|
|
61
|
+
return this._disposePromise;
|
|
65
62
|
}
|
|
66
63
|
this._isDisposed = true;
|
|
67
64
|
|
|
@@ -79,7 +76,7 @@ export class Context {
|
|
|
79
76
|
}
|
|
80
77
|
this._disposeCallbacks.length = 0;
|
|
81
78
|
|
|
82
|
-
return Promise.all(promises).then(() => {});
|
|
79
|
+
return (this._disposePromise = Promise.all(promises).then(() => {}));
|
|
83
80
|
}
|
|
84
81
|
|
|
85
82
|
/**
|
|
@@ -89,7 +86,7 @@ export class Context {
|
|
|
89
86
|
*/
|
|
90
87
|
raise(error: Error): void {
|
|
91
88
|
if (this._isDisposed) {
|
|
92
|
-
log.
|
|
89
|
+
log.warn('Error in disposed context', error);
|
|
93
90
|
return;
|
|
94
91
|
}
|
|
95
92
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AAMA,oBAAY,mBAAmB,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;AAEzD,oBAAY,eAAe,GAAG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzD,oBAAY,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,mBAAmB,CAAC;CAC/B,CAAC;AAEF,qBAAa,OAAO;IAElB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IAEnC;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO;IAIlD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsB;IAC/C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAyB;IAC3D,OAAO,CAAC,WAAW,CAAS;gBAEhB,EACV,OAKC,EACF,GAAE,mBAAwB;IAI3B;;;;OAIG;IACH,SAAS,CAAC,QAAQ,EAAE,eAAe;IAQnC;;;;;;;OAOG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAuBxB;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAczB,MAAM,CAAC,EAAE,OAAO,EAAE,EAAE,mBAAmB,GAAG,OAAO;CAiBlD"}
|
package/dist/src/context.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// Copyright 2022 DXOS.org
|
|
4
|
-
//
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Context = void 0;
|
|
7
|
-
const log_1 = require("@dxos/log");
|
|
8
|
-
class Context {
|
|
9
|
-
constructor({ onError = (error) => {
|
|
10
|
-
void this.dispose();
|
|
11
|
-
// Will generate an unhandled rejection.
|
|
12
|
-
throw error;
|
|
13
|
-
} } = {}) {
|
|
14
|
-
// Marker for the isContext method.
|
|
15
|
-
this._isContext = true;
|
|
16
|
-
this._disposeCallbacks = [];
|
|
17
|
-
this._isDisposed = false;
|
|
18
|
-
this._onError = onError;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Checks if the object is a context. Not susceptible to prototype duplication that could happen during bundling.
|
|
22
|
-
*/
|
|
23
|
-
static isContext(value) {
|
|
24
|
-
return (value === null || value === void 0 ? void 0 : value._isContext) === true;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Schedules a callback to run when the context is disposed.
|
|
28
|
-
* May be async, in this case the disposer might choose to wait for all resource to released.
|
|
29
|
-
* Throwing an error inside the callback will result in the error being logged, but not re-thrown.
|
|
30
|
-
*/
|
|
31
|
-
onDispose(callback) {
|
|
32
|
-
if (this._isDisposed) {
|
|
33
|
-
throw new Error('Context is already disposed');
|
|
34
|
-
}
|
|
35
|
-
this._disposeCallbacks.push(callback);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Runs all dispose callbacks.
|
|
39
|
-
* Sync callbacks are run in the reverse order they were added.
|
|
40
|
-
* Async callbacks are run in parallel.
|
|
41
|
-
* This function never throws.
|
|
42
|
-
* It is safe to ignore the returned promise if the caller does not wish to wait for callbacks to complete.
|
|
43
|
-
* Disposing context means that onDispose will throw an error and any errors raised will be logged and not propagated.
|
|
44
|
-
*/
|
|
45
|
-
dispose() {
|
|
46
|
-
if (this._isDisposed) {
|
|
47
|
-
throw new Error('Context is already disposed');
|
|
48
|
-
}
|
|
49
|
-
this._isDisposed = true;
|
|
50
|
-
const promises = [];
|
|
51
|
-
for (const callback of this._disposeCallbacks.reverse()) {
|
|
52
|
-
promises.push((async () => {
|
|
53
|
-
try {
|
|
54
|
-
await callback();
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
log_1.log.catch(error, {}, { file: "packages/common/context/src/context.ts", line: 75 });
|
|
58
|
-
}
|
|
59
|
-
})());
|
|
60
|
-
}
|
|
61
|
-
this._disposeCallbacks.length = 0;
|
|
62
|
-
return Promise.all(promises).then(() => { });
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Raise the error inside the context.
|
|
66
|
-
* The error will be propagated to the error handler.
|
|
67
|
-
* IF the error handler is not set, the error will dispose the context and cause an unhandled rejection.
|
|
68
|
-
*/
|
|
69
|
-
raise(error) {
|
|
70
|
-
if (this._isDisposed) {
|
|
71
|
-
log_1.log.error(`Error in disposed context: ${error}`, {}, { file: "packages/common/context/src/context.ts", line: 92 });
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
try {
|
|
75
|
-
this._onError(error);
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
// Generate an unhandled rejection and stop the error propagation.
|
|
79
|
-
void Promise.reject(err);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
derive({ onError }) {
|
|
83
|
-
const newCtx = new Context({
|
|
84
|
-
onError: async (error) => {
|
|
85
|
-
if (!onError) {
|
|
86
|
-
this.raise(error);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
try {
|
|
90
|
-
await onError(error);
|
|
91
|
-
}
|
|
92
|
-
catch (_a) {
|
|
93
|
-
this.raise(error);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
this.onDispose(() => newCtx.dispose());
|
|
99
|
-
return newCtx;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.Context = Context;
|
|
103
|
-
//# sourceMappingURL=context.js.map
|
package/dist/src/context.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;AAEF,mCAAgC;AAUhC,MAAa,OAAO;IAelB,YAAY,EACV,OAAO,GAAG,CAAC,KAAK,EAAE,EAAE;QAClB,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;QAEpB,wCAAwC;QACxC,MAAM,KAAK,CAAC;IACd,CAAC,KACsB,EAAE;QArB3B,mCAAmC;QAClB,eAAU,GAAG,IAAI,CAAC;QAUlB,sBAAiB,GAAsB,EAAE,CAAC;QACnD,gBAAW,GAAG,KAAK,CAAC;QAU1B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IApBD;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,KAAc;QAC7B,OAAO,CAAC,KAAiB,aAAjB,KAAK,uBAAL,KAAK,CAAc,UAAU,MAAK,IAAI,CAAC;IACjD,CAAC;IAiBD;;;;OAIG;IACH,SAAS,CAAC,QAAyB;QACjC,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;SAChD;QAED,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;;OAOG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;SAChD;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAExB,MAAM,QAAQ,GAAG,EAAE,CAAC;QACpB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,EAAE;YACvD,QAAQ,CAAC,IAAI,CACX,CAAC,KAAK,IAAI,EAAE;gBACV,IAAI;oBACF,MAAM,QAAQ,EAAE,CAAC;iBAClB;gBAAC,OAAO,KAAU,EAAE;oBACnB,SAAG,CAAC,KAAK,CAAC,KAAK,mEAAC,CAAC;iBAClB;YACH,CAAC,CAAC,EAAE,CACL,CAAC;SACH;QACD,IAAI,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC;QAElC,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAY;QAChB,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,SAAG,CAAC,KAAK,CAAC,8BAA8B,KAAK,EAAE,mEAAC,CAAC;YACjD,OAAO;SACR;QAED,IAAI;YACF,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;SACtB;QAAC,OAAO,GAAG,EAAE;YACZ,kEAAkE;YAClE,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;SAC1B;IACH,CAAC;IAED,MAAM,CAAC,EAAE,OAAO,EAAuB;QACrC,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC;YACzB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;gBACvB,IAAI,CAAC,OAAO,EAAE;oBACZ,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;iBACnB;qBAAM;oBACL,IAAI;wBACF,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC;qBACtB;oBAAC,WAAM;wBACN,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;qBACnB;iBACF;YACH,CAAC;SACF,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QACvC,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA1GD,0BA0GC"}
|
package/dist/src/context.test.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// Copyright 2022 DXOS.org
|
|
4
|
-
//
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const expect_1 = __importDefault(require("expect"));
|
|
10
|
-
const context_1 = require("./context");
|
|
11
|
-
describe('Context', function () {
|
|
12
|
-
it('dispose calls dispose hooks', function () {
|
|
13
|
-
const ctx = new context_1.Context();
|
|
14
|
-
let called = false;
|
|
15
|
-
ctx.onDispose(() => {
|
|
16
|
-
called = true;
|
|
17
|
-
});
|
|
18
|
-
void ctx.dispose();
|
|
19
|
-
(0, expect_1.default)(called).toBeTruthy();
|
|
20
|
-
});
|
|
21
|
-
it('dispose waits for async callbacks');
|
|
22
|
-
it('error in dispose callbacks are not propagated');
|
|
23
|
-
it('raised errors are propagated to the error handler', function () {
|
|
24
|
-
let error;
|
|
25
|
-
const ctx = new context_1.Context({
|
|
26
|
-
onError: (err) => {
|
|
27
|
-
error = err;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
ctx.raise(new Error('test'));
|
|
31
|
-
(0, expect_1.default)(error.message).toEqual('test');
|
|
32
|
-
});
|
|
33
|
-
it('isContext', function () {
|
|
34
|
-
const ctx = new context_1.Context();
|
|
35
|
-
(0, expect_1.default)(context_1.Context.isContext(ctx)).toBeTruthy();
|
|
36
|
-
(0, expect_1.default)(context_1.Context.isContext({})).toBeFalsy();
|
|
37
|
-
(0, expect_1.default)(context_1.Context.isContext(undefined)).toBeFalsy();
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
//# sourceMappingURL=context.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.test.js","sourceRoot":"","sources":["../../src/context.test.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;AAEF,oDAA4B;AAE5B,uCAAoC;AAEpC,QAAQ,CAAC,SAAS,EAAE;IAClB,EAAE,CAAC,6BAA6B,EAAE;QAChC,MAAM,GAAG,GAAG,IAAI,iBAAO,EAAE,CAAC;QAE1B,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE;YACjB,MAAM,GAAG,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC;QACnB,IAAA,gBAAM,EAAC,MAAM,CAAC,CAAC,UAAU,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,CAAC,CAAC;IAExC,EAAE,CAAC,+CAA+C,CAAC,CAAC;IAEpD,EAAE,CAAC,mDAAmD,EAAE;QACtD,IAAI,KAAa,CAAC;QAClB,MAAM,GAAG,GAAG,IAAI,iBAAO,CAAC;YACtB,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;gBACf,KAAK,GAAG,GAAG,CAAC;YACd,CAAC;SACF,CAAC,CAAC;QAEH,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QAC7B,IAAA,gBAAM,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,WAAW,EAAE;QACd,MAAM,GAAG,GAAG,IAAI,iBAAO,EAAE,CAAC;QAC1B,IAAA,gBAAM,EAAC,iBAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;QAE5C,IAAA,gBAAM,EAAC,iBAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;QAE1C,IAAA,gBAAM,EAAC,iBAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/src/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC"}
|
package/dist/src/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// Copyright 2022 DXOS.org
|
|
4
|
-
//
|
|
5
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
-
}
|
|
11
|
-
Object.defineProperty(o, k2, desc);
|
|
12
|
-
}) : (function(o, m, k, k2) {
|
|
13
|
-
if (k2 === undefined) k2 = k;
|
|
14
|
-
o[k2] = m[k];
|
|
15
|
-
}));
|
|
16
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
__exportStar(require("./context"), exports);
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;AAEF,4CAA0B"}
|