@unional/async-context 9.0.14 → 9.0.15
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/cjs/AsyncContext.d.ts +13 -10
- package/cjs/AsyncContext.d.ts.map +1 -1
- package/cjs/AsyncContext.js +61 -64
- package/cjs/AsyncContext.js.map +1 -1
- package/cjs/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/assertClassBrand.js +7 -0
- package/cjs/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/checkPrivateRedeclaration.js +6 -0
- package/cjs/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldGet2.js +7 -0
- package/cjs/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldInitSpec.js +7 -0
- package/cjs/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldSet2.js +7 -0
- package/cjs/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateMethodInitSpec.js +7 -0
- package/cjs/errors.d.ts +8 -5
- package/cjs/errors.d.ts.map +1 -1
- package/cjs/errors.js +15 -15
- package/cjs/errors.js.map +1 -1
- package/cjs/index.d.ts +3 -3
- package/cjs/index.js +6 -19
- package/esm/AsyncContext.d.ts +13 -10
- package/esm/AsyncContext.d.ts.map +1 -1
- package/esm/AsyncContext.js +61 -60
- package/esm/AsyncContext.js.map +1 -1
- package/esm/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/assertClassBrand.js +7 -0
- package/esm/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/checkPrivateRedeclaration.js +6 -0
- package/esm/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldGet2.js +7 -0
- package/esm/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldInitSpec.js +7 -0
- package/esm/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldSet2.js +7 -0
- package/esm/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateMethodInitSpec.js +7 -0
- package/esm/errors.d.ts +8 -5
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js +15 -11
- package/esm/errors.js.map +1 -1
- package/esm/index.d.ts +3 -3
- package/esm/index.js +3 -3
- package/package.json +7 -20
- package/cjs/index.d.ts.map +0 -1
- package/cjs/index.js.map +0 -1
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js.map +0 -1
package/cjs/AsyncContext.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { LeftJoin } from "type-plus";
|
|
2
|
+
//#region ts/AsyncContext.d.ts
|
|
3
|
+
declare class AsyncContext<Init extends Record<string | symbol, any>, Context extends Record<string | symbol, any> = Init> {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(init?: Init | Promise<Init> | AsyncContext.Initializer<Init>);
|
|
6
|
+
initialize<I extends Init = Init>(init: I | Promise<I> | AsyncContext.Initializer<I>): AsyncContext<I>;
|
|
7
|
+
extend<CurrentContext extends Record<string | symbol, any> = Context, AdditionalContext extends Record<string | symbol, any> = Record<string | symbol, any>>(context: AdditionalContext | Promise<AdditionalContext> | AsyncContext.Transformer<Context, AdditionalContext>): AsyncContext<Init, LeftJoin<CurrentContext, AdditionalContext>>;
|
|
8
|
+
get<C = Context>(): Promise<C>;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
declare namespace AsyncContext {
|
|
11
|
+
type Initializer<Init> = () => Init | Promise<Init>;
|
|
12
|
+
type Transformer<CurrentContext, AdditionalContext> = (context: CurrentContext) => AdditionalContext | Promise<AdditionalContext>;
|
|
12
13
|
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { AsyncContext };
|
|
13
16
|
//# sourceMappingURL=AsyncContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncContext.d.ts","
|
|
1
|
+
{"version":3,"file":"AsyncContext.d.ts","names":[],"sources":["../ts/AsyncContext.ts"],"mappings":";;cAGa,aACZ,aAAa,8BACb,gBAAgB,+BAA+B;;EAO/C,YAAY,OAAO,OAAO,QAAQ,QAAQ,aAAa,YAAY;EAGnE,WAAW,UAAU,OAAO,MAAM,MAAM,IAAI,QAAQ,KAAK,aAAa,YAAY,KAAK,aAAa;EAOpG,OACC,uBAAuB,+BAA+B,SACtD,0BAA0B,+BAA+B,8BAEzD,SAAS,oBAAoB,QAAQ,qBAAqB,aAAa,YAAY,SAAS,qBAC1F,aAAa,MAAM,SAAS,gBAAgB;EAgBzC,IAAI,IAAI,YAAY,QAAQ;;kBASlB;OACJ,YAAY,cAAc,OAAO,QAAQ;OACzC,YAAY,gBAAgB,sBACvC,SAAS,mBACL,oBAAoB,QAAQ"}
|
package/cjs/AsyncContext.js
CHANGED
|
@@ -1,73 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
const require_errors = require("./errors.js");
|
|
2
|
+
const require_classPrivateMethodInitSpec = require("./_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateMethodInitSpec.js");
|
|
3
|
+
const require_classPrivateFieldInitSpec = require("./_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldInitSpec.js");
|
|
4
|
+
const require_assertClassBrand = require("./_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/assertClassBrand.js");
|
|
5
|
+
const require_classPrivateFieldSet2 = require("./_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldSet2.js");
|
|
6
|
+
const require_classPrivateFieldGet2 = require("./_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldGet2.js");
|
|
7
|
+
//#region ts/AsyncContext.ts
|
|
8
|
+
var _resolving = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
var _resolvers = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
var _transforming = /* @__PURE__ */ new WeakMap();
|
|
11
|
+
var _init = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
var _original = /* @__PURE__ */ new WeakMap();
|
|
13
|
+
var _AsyncContext_brand = /* @__PURE__ */ new WeakSet();
|
|
14
|
+
var AsyncContext = class AsyncContext {
|
|
15
|
+
constructor(init) {
|
|
16
|
+
require_classPrivateMethodInitSpec.default(this, _AsyncContext_brand);
|
|
17
|
+
require_classPrivateFieldInitSpec.default(this, _resolving, void 0);
|
|
18
|
+
require_classPrivateFieldInitSpec.default(this, _resolvers, []);
|
|
19
|
+
require_classPrivateFieldInitSpec.default(this, _transforming, false);
|
|
20
|
+
require_classPrivateFieldInitSpec.default(this, _init, void 0);
|
|
21
|
+
require_classPrivateFieldInitSpec.default(this, _original, void 0);
|
|
22
|
+
require_classPrivateFieldSet2.default(_init, this, init);
|
|
23
|
+
}
|
|
24
|
+
initialize(init) {
|
|
25
|
+
if (require_classPrivateFieldGet2.default(_init, this)) throw new require_errors.ContextAlreadyInitialized({ ssf: this.initialize });
|
|
26
|
+
require_classPrivateFieldSet2.default(_init, this, init);
|
|
27
|
+
if (require_classPrivateFieldGet2.default(_resolvers, this).length > 0) require_classPrivateFieldGet2.default(_resolvers, this).forEach((r) => void r(require_assertClassBrand.default(_AsyncContext_brand, this, _buildContext).call(this)));
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
extend(context) {
|
|
31
|
+
const newctx = new AsyncContext(async () => {
|
|
32
|
+
try {
|
|
33
|
+
const value = await this.get();
|
|
34
|
+
require_classPrivateFieldSet2.default(_transforming, newctx, true);
|
|
35
|
+
const newValue = await (isTransformer(context) ? context(value) : context);
|
|
36
|
+
return {
|
|
37
|
+
...value,
|
|
38
|
+
...newValue
|
|
39
|
+
};
|
|
40
|
+
} finally {
|
|
41
|
+
require_classPrivateFieldSet2.default(_transforming, newctx, false);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const ctx = require_classPrivateFieldGet2.default(_original, this) ?? this;
|
|
45
|
+
require_classPrivateFieldSet2.default(_original, newctx, ctx);
|
|
46
|
+
newctx.initialize = newctx.initialize.bind(ctx);
|
|
47
|
+
return newctx;
|
|
48
|
+
}
|
|
49
|
+
async get() {
|
|
50
|
+
if (require_classPrivateFieldGet2.default(_transforming, this)) throw new require_errors.BlockingGetDetected({ ssf: this.get });
|
|
51
|
+
if (require_classPrivateFieldGet2.default(_resolving, this)) return require_classPrivateFieldGet2.default(_resolving, this);
|
|
52
|
+
return require_classPrivateFieldSet2.default(_resolving, this, require_classPrivateFieldGet2.default(_init, this) ? require_assertClassBrand.default(_AsyncContext_brand, this, _buildContext).call(this) : new Promise((a) => require_classPrivateFieldGet2.default(_resolvers, this).push(a)));
|
|
53
|
+
}
|
|
7
54
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _AsyncContext_instances, _AsyncContext_resolving, _AsyncContext_resolvers, _AsyncContext_transforming, _AsyncContext_init, _AsyncContext_original, _AsyncContext_buildContext;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.AsyncContext = void 0;
|
|
16
|
-
const errors_js_1 = require("./errors.js");
|
|
17
|
-
class AsyncContext {
|
|
18
|
-
constructor(init) {
|
|
19
|
-
_AsyncContext_instances.add(this);
|
|
20
|
-
_AsyncContext_resolving.set(this, void 0);
|
|
21
|
-
_AsyncContext_resolvers.set(this, []);
|
|
22
|
-
_AsyncContext_transforming.set(this, false);
|
|
23
|
-
_AsyncContext_init.set(this, void 0);
|
|
24
|
-
_AsyncContext_original.set(this, void 0);
|
|
25
|
-
__classPrivateFieldSet(this, _AsyncContext_init, init, "f");
|
|
26
|
-
}
|
|
27
|
-
initialize(init) {
|
|
28
|
-
if (__classPrivateFieldGet(this, _AsyncContext_init, "f"))
|
|
29
|
-
throw new errors_js_1.ContextAlreadyInitialized({ ssf: this.initialize });
|
|
30
|
-
__classPrivateFieldSet(this, _AsyncContext_init, init, "f");
|
|
31
|
-
if (__classPrivateFieldGet(this, _AsyncContext_resolvers, "f").length > 0)
|
|
32
|
-
__classPrivateFieldGet(this, _AsyncContext_resolvers, "f").forEach((r) => void r(__classPrivateFieldGet(this, _AsyncContext_instances, "m", _AsyncContext_buildContext).call(this)));
|
|
33
|
-
return this;
|
|
34
|
-
}
|
|
35
|
-
extend(context) {
|
|
36
|
-
const newctx = new AsyncContext(async () => {
|
|
37
|
-
try {
|
|
38
|
-
const value = await this.get();
|
|
39
|
-
__classPrivateFieldSet(newctx, _AsyncContext_transforming, true, "f");
|
|
40
|
-
const newValue = await (isTransformer(context) ? context(value) : context);
|
|
41
|
-
return { ...value, ...newValue };
|
|
42
|
-
}
|
|
43
|
-
finally {
|
|
44
|
-
__classPrivateFieldSet(newctx, _AsyncContext_transforming, false, "f");
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
const ctx = __classPrivateFieldGet(this, _AsyncContext_original, "f") ?? this;
|
|
48
|
-
__classPrivateFieldSet(newctx, _AsyncContext_original, ctx, "f");
|
|
49
|
-
newctx.initialize = newctx.initialize.bind(ctx);
|
|
50
|
-
return newctx;
|
|
51
|
-
}
|
|
52
|
-
async get() {
|
|
53
|
-
if (__classPrivateFieldGet(this, _AsyncContext_transforming, "f"))
|
|
54
|
-
throw new errors_js_1.BlockingGetDetected({ ssf: this.get });
|
|
55
|
-
if (__classPrivateFieldGet(this, _AsyncContext_resolving, "f"))
|
|
56
|
-
return __classPrivateFieldGet(this, _AsyncContext_resolving, "f");
|
|
57
|
-
return (__classPrivateFieldSet(this, _AsyncContext_resolving, __classPrivateFieldGet(this, _AsyncContext_init, "f") ? __classPrivateFieldGet(this, _AsyncContext_instances, "m", _AsyncContext_buildContext).call(this) : new Promise((a) => __classPrivateFieldGet(this, _AsyncContext_resolvers, "f").push(a)), "f"));
|
|
58
|
-
}
|
|
55
|
+
async function _buildContext() {
|
|
56
|
+
return resolveInit(require_classPrivateFieldGet2.default(_init, this));
|
|
59
57
|
}
|
|
60
|
-
exports.AsyncContext = AsyncContext;
|
|
61
|
-
_AsyncContext_resolving = new WeakMap(), _AsyncContext_resolvers = new WeakMap(), _AsyncContext_transforming = new WeakMap(), _AsyncContext_init = new WeakMap(), _AsyncContext_original = new WeakMap(), _AsyncContext_instances = new WeakSet(), _AsyncContext_buildContext = async function _AsyncContext_buildContext() {
|
|
62
|
-
return resolveInit(__classPrivateFieldGet(this, _AsyncContext_init, "f"));
|
|
63
|
-
};
|
|
64
58
|
async function resolveInit(init) {
|
|
65
|
-
|
|
59
|
+
return isInitializer(init) ? init() : init;
|
|
66
60
|
}
|
|
67
61
|
function isTransformer(context) {
|
|
68
|
-
|
|
62
|
+
return typeof context === "function";
|
|
69
63
|
}
|
|
70
64
|
function isInitializer(context) {
|
|
71
|
-
|
|
65
|
+
return typeof context === "function";
|
|
72
66
|
}
|
|
67
|
+
//#endregion
|
|
68
|
+
exports.AsyncContext = AsyncContext;
|
|
69
|
+
|
|
73
70
|
//# sourceMappingURL=AsyncContext.js.map
|
package/cjs/AsyncContext.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncContext.js","
|
|
1
|
+
{"version":3,"file":"AsyncContext.js","names":["ContextAlreadyInitialized","BlockingGetDetected"],"sources":["../ts/AsyncContext.ts"],"sourcesContent":["import type { LeftJoin } from 'type-plus'\nimport { BlockingGetDetected, ContextAlreadyInitialized } from './errors.js'\n\nexport class AsyncContext<\n\tInit extends Record<string | symbol, any>,\n\tContext extends Record<string | symbol, any> = Init,\n> {\n\t#resolving: Promise<any> | undefined\n\t#resolvers: Array<(value: Promise<Context>) => void> = []\n\t#transforming = false\n\t#init: Init | Promise<Init> | AsyncContext.Initializer<Init> | undefined\n\t#original: AsyncContext<any, any> | undefined\n\tconstructor(init?: Init | Promise<Init> | AsyncContext.Initializer<Init>) {\n\t\tthis.#init = init\n\t}\n\tinitialize<I extends Init = Init>(init: I | Promise<I> | AsyncContext.Initializer<I>): AsyncContext<I> {\n\t\tif (this.#init) throw new ContextAlreadyInitialized({ ssf: this.initialize })\n\t\tthis.#init = init\n\n\t\tif (this.#resolvers.length > 0) this.#resolvers.forEach((r) => void r(this.#buildContext()))\n\t\treturn this as any as AsyncContext<I>\n\t}\n\textend<\n\t\tCurrentContext extends Record<string | symbol, any> = Context,\n\t\tAdditionalContext extends Record<string | symbol, any> = Record<string | symbol, any>,\n\t>(\n\t\tcontext: AdditionalContext | Promise<AdditionalContext> | AsyncContext.Transformer<Context, AdditionalContext>,\n\t): AsyncContext<Init, LeftJoin<CurrentContext, AdditionalContext>> {\n\t\tconst newctx = new AsyncContext(async () => {\n\t\t\ttry {\n\t\t\t\tconst value = await this.get()\n\t\t\t\tnewctx.#transforming = true\n\t\t\t\tconst newValue = await (isTransformer<any, any>(context) ? context(value) : context)\n\t\t\t\treturn { ...value, ...newValue }\n\t\t\t} finally {\n\t\t\t\tnewctx.#transforming = false\n\t\t\t}\n\t\t})\n\t\tconst ctx = this.#original ?? this\n\t\tnewctx.#original = ctx\n\t\tnewctx.initialize = newctx.initialize.bind(ctx)\n\t\treturn newctx\n\t}\n\tasync get<C = Context>(): Promise<C> {\n\t\tif (this.#transforming) throw new BlockingGetDetected({ ssf: this.get })\n\t\tif (this.#resolving) return this.#resolving\n\t\treturn (this.#resolving = this.#init ? this.#buildContext() : new Promise<any>((a) => this.#resolvers.push(a)))\n\t}\n\tasync #buildContext(): Promise<Context> {\n\t\treturn resolveInit(this.#init!) as any as Promise<Context>\n\t}\n}\nexport namespace AsyncContext {\n\texport type Initializer<Init> = () => Init | Promise<Init>\n\texport type Transformer<CurrentContext, AdditionalContext> = (\n\t\tcontext: CurrentContext,\n\t) => AdditionalContext | Promise<AdditionalContext>\n}\n\nasync function resolveInit<Init extends Record<string | symbol, any>>(\n\tinit: Init | Promise<Init> | AsyncContext.Initializer<Init>,\n): Promise<Init> {\n\treturn isInitializer<Init>(init) ? init() : init\n}\n\nfunction isTransformer<CurrentContext, AdditionalContext>(\n\tcontext: unknown,\n): context is AsyncContext.Transformer<CurrentContext, AdditionalContext> {\n\treturn typeof context === 'function'\n}\n\nfunction isInitializer<T>(context: unknown): context is AsyncContext.Initializer<T> {\n\treturn typeof context === 'function'\n}\n"],"mappings":";;;;;;;;;;;;;AAGA,IAAa,eAAb,MAAa,aAGX;CAMD,YAAY,MAA8D;;;EAJnB,kCAAA,QAAA,MAAA,YAAA,CAAC,CAAA;EACxC,kCAAA,QAAA,MAAA,eAAA,KAAA;;;EAIf,8BAAA,QAAA,OAAA,MAAa,IAAA;CACd;CACA,WAAkC,MAAqE;EACtG,IAAA,8BAAA,QAAA,OAAI,IAAA,GAAY,MAAM,IAAIA,eAAAA,0BAA0B,EAAE,KAAK,KAAK,WAAW,CAAC;EAC5E,8BAAA,QAAA,OAAA,MAAa,IAAA;EAEb,IAAA,8BAAA,QAAA,YAAI,IAAA,CAAA,CAAgB,SAAS,GAAG,8BAAA,QAAA,YAAA,IAAA,CAAA,CAAgB,SAAS,MAAM,KAAK,EAAA,yBAAA,QAAA,qBAAE,MAAA,aAAA,CAAA,CAAA,KAAA,IAAmB,CAAC,CAAC;EAC3F,OAAO;CACR;CACA,OAIC,SACkE;EAClE,MAAM,SAAS,IAAI,aAAa,YAAY;GAC3C,IAAI;IACH,MAAM,QAAQ,MAAM,KAAK,IAAI;IAC7B,8BAAA,QAAA,eAAA,QAAuB,IAAA;IACvB,MAAM,WAAW,OAAO,cAAwB,OAAO,IAAI,QAAQ,KAAK,IAAI;IAC5E,OAAO;KAAE,GAAG;KAAO,GAAG;IAAS;GAChC,UAAU;IACT,8BAAA,QAAA,eAAA,QAAuB,KAAA;GACxB;EACD,CAAC;EACD,MAAM,MAAA,8BAAA,QAAA,WAAM,IAAA,KAAkB;EAC9B,8BAAA,QAAA,WAAA,QAAmB,GAAA;EACnB,OAAO,aAAa,OAAO,WAAW,KAAK,GAAG;EAC9C,OAAO;CACR;CACA,MAAM,MAA+B;EACpC,IAAA,8BAAA,QAAA,eAAI,IAAA,GAAoB,MAAM,IAAIC,eAAAA,oBAAoB,EAAE,KAAK,KAAK,IAAI,CAAC;EACvE,IAAA,8BAAA,QAAA,YAAI,IAAA,GAAiB,OAAA,8BAAA,QAAA,YAAO,IAAA;EAC5B,OAAA,8BAAA,QAAA,YAAQ,MAAA,8BAAA,QAAA,OAAkB,IAAA,IAAA,yBAAA,QAAA,qBAAa,MAAA,aAAA,CAAA,CAAA,KAAA,IAAmB,IAAI,IAAI,SAAc,MAAA,8BAAA,QAAA,YAAM,IAAA,CAAA,CAAgB,KAAK,CAAC,CAAC,CAAA;CAC9G;AAID;AAHC,eAAA,gBAAwC;CACvC,OAAO,YAAA,8BAAA,QAAA,OAAY,IAAA,CAAW;AAC/B;AASD,eAAe,YACd,MACgB;CAChB,OAAO,cAAoB,IAAI,IAAI,KAAK,IAAI;AAC7C;AAEA,SAAS,cACR,SACyE;CACzE,OAAO,OAAO,YAAY;AAC3B;AAEA,SAAS,cAAiB,SAA0D;CACnF,OAAO,OAAO,YAAY;AAC3B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/assertClassBrand.js
|
|
2
|
+
function _assertClassBrand(e, t, n) {
|
|
3
|
+
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
4
|
+
throw new TypeError("Private element is not present on this object");
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
exports.default = _assertClassBrand;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/checkPrivateRedeclaration.js
|
|
2
|
+
function _checkPrivateRedeclaration(e, t) {
|
|
3
|
+
if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
4
|
+
}
|
|
5
|
+
//#endregion
|
|
6
|
+
exports.default = _checkPrivateRedeclaration;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const require_assertClassBrand = require("./assertClassBrand.js");
|
|
2
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/classPrivateFieldGet2.js
|
|
3
|
+
function _classPrivateFieldGet2(s, a) {
|
|
4
|
+
return s.get(require_assertClassBrand.default(s, a));
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
exports.default = _classPrivateFieldGet2;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const require_checkPrivateRedeclaration = require("./checkPrivateRedeclaration.js");
|
|
2
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/classPrivateFieldInitSpec.js
|
|
3
|
+
function _classPrivateFieldInitSpec(e, t, a) {
|
|
4
|
+
require_checkPrivateRedeclaration.default(e, t), t.set(e, a);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
exports.default = _classPrivateFieldInitSpec;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const require_assertClassBrand = require("./assertClassBrand.js");
|
|
2
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/classPrivateFieldSet2.js
|
|
3
|
+
function _classPrivateFieldSet2(s, a, r) {
|
|
4
|
+
return s.set(require_assertClassBrand.default(s, a), r), r;
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
exports.default = _classPrivateFieldSet2;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const require_checkPrivateRedeclaration = require("./checkPrivateRedeclaration.js");
|
|
2
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/classPrivateMethodInitSpec.js
|
|
3
|
+
function _classPrivateMethodInitSpec(e, a) {
|
|
4
|
+
require_checkPrivateRedeclaration.default(e, a), a.add(e);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
exports.default = _classPrivateMethodInitSpec;
|
package/cjs/errors.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { ModuleError } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ModuleError } from "iso-error";
|
|
2
|
+
//#region ts/errors.d.ts
|
|
3
|
+
declare class ContextAlreadyInitialized extends ModuleError {
|
|
4
|
+
constructor(options?: ModuleError.Options);
|
|
4
5
|
}
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
declare class BlockingGetDetected extends ModuleError {
|
|
7
|
+
constructor(options?: ModuleError.Options);
|
|
7
8
|
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { BlockingGetDetected, ContextAlreadyInitialized };
|
|
8
11
|
//# sourceMappingURL=errors.d.ts.map
|
package/cjs/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","
|
|
1
|
+
{"version":3,"file":"errors.d.ts","names":[],"sources":["../ts/errors.ts"],"mappings":";;cAEa,kCAAkC;EAC9C,YAAY,UAAU,YAAY;;cAKtB,4BAA4B;EACxC,YAAY,UAAU,YAAY"}
|
package/cjs/errors.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
let iso_error = require("iso-error");
|
|
2
|
+
//#region ts/errors.ts
|
|
3
|
+
var ContextAlreadyInitialized = class extends iso_error.ModuleError {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
super("@unional/async-context", "context can only be initialized once.", options);
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
var BlockingGetDetected = class extends iso_error.ModuleError {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super("@unional/async-context", "a blocking get() detected. Are you calling it within extend()?", options);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
16
14
|
exports.BlockingGetDetected = BlockingGetDetected;
|
|
15
|
+
exports.ContextAlreadyInitialized = ContextAlreadyInitialized;
|
|
16
|
+
|
|
17
17
|
//# sourceMappingURL=errors.js.map
|
package/cjs/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","
|
|
1
|
+
{"version":3,"file":"errors.js","names":["ModuleError"],"sources":["../ts/errors.ts"],"sourcesContent":["import { ModuleError } from 'iso-error'\n\nexport class ContextAlreadyInitialized extends ModuleError {\n\tconstructor(options?: ModuleError.Options) {\n\t\tsuper('@unional/async-context', 'context can only be initialized once.', options)\n\t}\n}\n\nexport class BlockingGetDetected extends ModuleError {\n\tconstructor(options?: ModuleError.Options) {\n\t\tsuper('@unional/async-context', 'a blocking get() detected. Are you calling it within extend()?', options)\n\t}\n}\n"],"mappings":";;AAEA,IAAa,4BAAb,cAA+CA,UAAAA,YAAY;CAC1D,YAAY,SAA+B;EAC1C,MAAM,0BAA0B,yCAAyC,OAAO;CACjF;AACD;AAEA,IAAa,sBAAb,cAAyCA,UAAAA,YAAY;CACpD,YAAY,SAA+B;EAC1C,MAAM,0BAA0B,kEAAkE,OAAO;CAC1G;AACD"}
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { AsyncContext } from "./AsyncContext.js";
|
|
2
|
+
import { BlockingGetDetected, ContextAlreadyInitialized } from "./errors.js";
|
|
3
|
+
export { AsyncContext, BlockingGetDetected, ContextAlreadyInitialized };
|
package/cjs/index.js
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./AsyncContext.js"), exports);
|
|
18
|
-
__exportStar(require("./errors.js"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_errors = require("./errors.js");
|
|
3
|
+
const require_AsyncContext = require("./AsyncContext.js");
|
|
4
|
+
exports.AsyncContext = require_AsyncContext.AsyncContext;
|
|
5
|
+
exports.BlockingGetDetected = require_errors.BlockingGetDetected;
|
|
6
|
+
exports.ContextAlreadyInitialized = require_errors.ContextAlreadyInitialized;
|
package/esm/AsyncContext.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { LeftJoin } from "type-plus";
|
|
2
|
+
//#region ts/AsyncContext.d.ts
|
|
3
|
+
declare class AsyncContext<Init extends Record<string | symbol, any>, Context extends Record<string | symbol, any> = Init> {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(init?: Init | Promise<Init> | AsyncContext.Initializer<Init>);
|
|
6
|
+
initialize<I extends Init = Init>(init: I | Promise<I> | AsyncContext.Initializer<I>): AsyncContext<I>;
|
|
7
|
+
extend<CurrentContext extends Record<string | symbol, any> = Context, AdditionalContext extends Record<string | symbol, any> = Record<string | symbol, any>>(context: AdditionalContext | Promise<AdditionalContext> | AsyncContext.Transformer<Context, AdditionalContext>): AsyncContext<Init, LeftJoin<CurrentContext, AdditionalContext>>;
|
|
8
|
+
get<C = Context>(): Promise<C>;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
declare namespace AsyncContext {
|
|
11
|
+
type Initializer<Init> = () => Init | Promise<Init>;
|
|
12
|
+
type Transformer<CurrentContext, AdditionalContext> = (context: CurrentContext) => AdditionalContext | Promise<AdditionalContext>;
|
|
12
13
|
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { AsyncContext };
|
|
13
16
|
//# sourceMappingURL=AsyncContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncContext.d.ts","
|
|
1
|
+
{"version":3,"file":"AsyncContext.d.ts","names":[],"sources":["../ts/AsyncContext.ts"],"mappings":";;cAGa,aACZ,aAAa,8BACb,gBAAgB,+BAA+B;;EAO/C,YAAY,OAAO,OAAO,QAAQ,QAAQ,aAAa,YAAY;EAGnE,WAAW,UAAU,OAAO,MAAM,MAAM,IAAI,QAAQ,KAAK,aAAa,YAAY,KAAK,aAAa;EAOpG,OACC,uBAAuB,+BAA+B,SACtD,0BAA0B,+BAA+B,8BAEzD,SAAS,oBAAoB,QAAQ,qBAAqB,aAAa,YAAY,SAAS,qBAC1F,aAAa,MAAM,SAAS,gBAAgB;EAgBzC,IAAI,IAAI,YAAY,QAAQ;;kBASlB;OACJ,YAAY,cAAc,OAAO,QAAQ;OACzC,YAAY,gBAAgB,sBACvC,SAAS,mBACL,oBAAoB,QAAQ"}
|
package/esm/AsyncContext.js
CHANGED
|
@@ -1,69 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { BlockingGetDetected, ContextAlreadyInitialized } from "./errors.js";
|
|
2
|
+
import _classPrivateMethodInitSpec from "./_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateMethodInitSpec.js";
|
|
3
|
+
import _classPrivateFieldInitSpec from "./_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldInitSpec.js";
|
|
4
|
+
import _assertClassBrand from "./_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/assertClassBrand.js";
|
|
5
|
+
import _classPrivateFieldSet2 from "./_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldSet2.js";
|
|
6
|
+
import _classPrivateFieldGet2 from "./_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldGet2.js";
|
|
7
|
+
//#region ts/AsyncContext.ts
|
|
8
|
+
var _resolving = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
var _resolvers = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
var _transforming = /* @__PURE__ */ new WeakMap();
|
|
11
|
+
var _init = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
var _original = /* @__PURE__ */ new WeakMap();
|
|
13
|
+
var _AsyncContext_brand = /* @__PURE__ */ new WeakSet();
|
|
14
|
+
var AsyncContext = class AsyncContext {
|
|
15
|
+
constructor(init) {
|
|
16
|
+
_classPrivateMethodInitSpec(this, _AsyncContext_brand);
|
|
17
|
+
_classPrivateFieldInitSpec(this, _resolving, void 0);
|
|
18
|
+
_classPrivateFieldInitSpec(this, _resolvers, []);
|
|
19
|
+
_classPrivateFieldInitSpec(this, _transforming, false);
|
|
20
|
+
_classPrivateFieldInitSpec(this, _init, void 0);
|
|
21
|
+
_classPrivateFieldInitSpec(this, _original, void 0);
|
|
22
|
+
_classPrivateFieldSet2(_init, this, init);
|
|
23
|
+
}
|
|
24
|
+
initialize(init) {
|
|
25
|
+
if (_classPrivateFieldGet2(_init, this)) throw new ContextAlreadyInitialized({ ssf: this.initialize });
|
|
26
|
+
_classPrivateFieldSet2(_init, this, init);
|
|
27
|
+
if (_classPrivateFieldGet2(_resolvers, this).length > 0) _classPrivateFieldGet2(_resolvers, this).forEach((r) => void r(_assertClassBrand(_AsyncContext_brand, this, _buildContext).call(this)));
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
extend(context) {
|
|
31
|
+
const newctx = new AsyncContext(async () => {
|
|
32
|
+
try {
|
|
33
|
+
const value = await this.get();
|
|
34
|
+
_classPrivateFieldSet2(_transforming, newctx, true);
|
|
35
|
+
const newValue = await (isTransformer(context) ? context(value) : context);
|
|
36
|
+
return {
|
|
37
|
+
...value,
|
|
38
|
+
...newValue
|
|
39
|
+
};
|
|
40
|
+
} finally {
|
|
41
|
+
_classPrivateFieldSet2(_transforming, newctx, false);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const ctx = _classPrivateFieldGet2(_original, this) ?? this;
|
|
45
|
+
_classPrivateFieldSet2(_original, newctx, ctx);
|
|
46
|
+
newctx.initialize = newctx.initialize.bind(ctx);
|
|
47
|
+
return newctx;
|
|
48
|
+
}
|
|
49
|
+
async get() {
|
|
50
|
+
if (_classPrivateFieldGet2(_transforming, this)) throw new BlockingGetDetected({ ssf: this.get });
|
|
51
|
+
if (_classPrivateFieldGet2(_resolving, this)) return _classPrivateFieldGet2(_resolving, this);
|
|
52
|
+
return _classPrivateFieldSet2(_resolving, this, _classPrivateFieldGet2(_init, this) ? _assertClassBrand(_AsyncContext_brand, this, _buildContext).call(this) : new Promise((a) => _classPrivateFieldGet2(_resolvers, this).push(a)));
|
|
53
|
+
}
|
|
6
54
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _AsyncContext_instances, _AsyncContext_resolving, _AsyncContext_resolvers, _AsyncContext_transforming, _AsyncContext_init, _AsyncContext_original, _AsyncContext_buildContext;
|
|
13
|
-
import { BlockingGetDetected, ContextAlreadyInitialized } from './errors.js';
|
|
14
|
-
export class AsyncContext {
|
|
15
|
-
constructor(init) {
|
|
16
|
-
_AsyncContext_instances.add(this);
|
|
17
|
-
_AsyncContext_resolving.set(this, void 0);
|
|
18
|
-
_AsyncContext_resolvers.set(this, []);
|
|
19
|
-
_AsyncContext_transforming.set(this, false);
|
|
20
|
-
_AsyncContext_init.set(this, void 0);
|
|
21
|
-
_AsyncContext_original.set(this, void 0);
|
|
22
|
-
__classPrivateFieldSet(this, _AsyncContext_init, init, "f");
|
|
23
|
-
}
|
|
24
|
-
initialize(init) {
|
|
25
|
-
if (__classPrivateFieldGet(this, _AsyncContext_init, "f"))
|
|
26
|
-
throw new ContextAlreadyInitialized({ ssf: this.initialize });
|
|
27
|
-
__classPrivateFieldSet(this, _AsyncContext_init, init, "f");
|
|
28
|
-
if (__classPrivateFieldGet(this, _AsyncContext_resolvers, "f").length > 0)
|
|
29
|
-
__classPrivateFieldGet(this, _AsyncContext_resolvers, "f").forEach((r) => void r(__classPrivateFieldGet(this, _AsyncContext_instances, "m", _AsyncContext_buildContext).call(this)));
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
extend(context) {
|
|
33
|
-
const newctx = new AsyncContext(async () => {
|
|
34
|
-
try {
|
|
35
|
-
const value = await this.get();
|
|
36
|
-
__classPrivateFieldSet(newctx, _AsyncContext_transforming, true, "f");
|
|
37
|
-
const newValue = await (isTransformer(context) ? context(value) : context);
|
|
38
|
-
return { ...value, ...newValue };
|
|
39
|
-
}
|
|
40
|
-
finally {
|
|
41
|
-
__classPrivateFieldSet(newctx, _AsyncContext_transforming, false, "f");
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
const ctx = __classPrivateFieldGet(this, _AsyncContext_original, "f") ?? this;
|
|
45
|
-
__classPrivateFieldSet(newctx, _AsyncContext_original, ctx, "f");
|
|
46
|
-
newctx.initialize = newctx.initialize.bind(ctx);
|
|
47
|
-
return newctx;
|
|
48
|
-
}
|
|
49
|
-
async get() {
|
|
50
|
-
if (__classPrivateFieldGet(this, _AsyncContext_transforming, "f"))
|
|
51
|
-
throw new BlockingGetDetected({ ssf: this.get });
|
|
52
|
-
if (__classPrivateFieldGet(this, _AsyncContext_resolving, "f"))
|
|
53
|
-
return __classPrivateFieldGet(this, _AsyncContext_resolving, "f");
|
|
54
|
-
return (__classPrivateFieldSet(this, _AsyncContext_resolving, __classPrivateFieldGet(this, _AsyncContext_init, "f") ? __classPrivateFieldGet(this, _AsyncContext_instances, "m", _AsyncContext_buildContext).call(this) : new Promise((a) => __classPrivateFieldGet(this, _AsyncContext_resolvers, "f").push(a)), "f"));
|
|
55
|
-
}
|
|
55
|
+
async function _buildContext() {
|
|
56
|
+
return resolveInit(_classPrivateFieldGet2(_init, this));
|
|
56
57
|
}
|
|
57
|
-
_AsyncContext_resolving = new WeakMap(), _AsyncContext_resolvers = new WeakMap(), _AsyncContext_transforming = new WeakMap(), _AsyncContext_init = new WeakMap(), _AsyncContext_original = new WeakMap(), _AsyncContext_instances = new WeakSet(), _AsyncContext_buildContext = async function _AsyncContext_buildContext() {
|
|
58
|
-
return resolveInit(__classPrivateFieldGet(this, _AsyncContext_init, "f"));
|
|
59
|
-
};
|
|
60
58
|
async function resolveInit(init) {
|
|
61
|
-
|
|
59
|
+
return isInitializer(init) ? init() : init;
|
|
62
60
|
}
|
|
63
61
|
function isTransformer(context) {
|
|
64
|
-
|
|
62
|
+
return typeof context === "function";
|
|
65
63
|
}
|
|
66
64
|
function isInitializer(context) {
|
|
67
|
-
|
|
65
|
+
return typeof context === "function";
|
|
68
66
|
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { AsyncContext };
|
|
69
|
+
|
|
69
70
|
//# sourceMappingURL=AsyncContext.js.map
|
package/esm/AsyncContext.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncContext.js","
|
|
1
|
+
{"version":3,"file":"AsyncContext.js","names":[],"sources":["../ts/AsyncContext.ts"],"sourcesContent":["import type { LeftJoin } from 'type-plus'\nimport { BlockingGetDetected, ContextAlreadyInitialized } from './errors.js'\n\nexport class AsyncContext<\n\tInit extends Record<string | symbol, any>,\n\tContext extends Record<string | symbol, any> = Init,\n> {\n\t#resolving: Promise<any> | undefined\n\t#resolvers: Array<(value: Promise<Context>) => void> = []\n\t#transforming = false\n\t#init: Init | Promise<Init> | AsyncContext.Initializer<Init> | undefined\n\t#original: AsyncContext<any, any> | undefined\n\tconstructor(init?: Init | Promise<Init> | AsyncContext.Initializer<Init>) {\n\t\tthis.#init = init\n\t}\n\tinitialize<I extends Init = Init>(init: I | Promise<I> | AsyncContext.Initializer<I>): AsyncContext<I> {\n\t\tif (this.#init) throw new ContextAlreadyInitialized({ ssf: this.initialize })\n\t\tthis.#init = init\n\n\t\tif (this.#resolvers.length > 0) this.#resolvers.forEach((r) => void r(this.#buildContext()))\n\t\treturn this as any as AsyncContext<I>\n\t}\n\textend<\n\t\tCurrentContext extends Record<string | symbol, any> = Context,\n\t\tAdditionalContext extends Record<string | symbol, any> = Record<string | symbol, any>,\n\t>(\n\t\tcontext: AdditionalContext | Promise<AdditionalContext> | AsyncContext.Transformer<Context, AdditionalContext>,\n\t): AsyncContext<Init, LeftJoin<CurrentContext, AdditionalContext>> {\n\t\tconst newctx = new AsyncContext(async () => {\n\t\t\ttry {\n\t\t\t\tconst value = await this.get()\n\t\t\t\tnewctx.#transforming = true\n\t\t\t\tconst newValue = await (isTransformer<any, any>(context) ? context(value) : context)\n\t\t\t\treturn { ...value, ...newValue }\n\t\t\t} finally {\n\t\t\t\tnewctx.#transforming = false\n\t\t\t}\n\t\t})\n\t\tconst ctx = this.#original ?? this\n\t\tnewctx.#original = ctx\n\t\tnewctx.initialize = newctx.initialize.bind(ctx)\n\t\treturn newctx\n\t}\n\tasync get<C = Context>(): Promise<C> {\n\t\tif (this.#transforming) throw new BlockingGetDetected({ ssf: this.get })\n\t\tif (this.#resolving) return this.#resolving\n\t\treturn (this.#resolving = this.#init ? this.#buildContext() : new Promise<any>((a) => this.#resolvers.push(a)))\n\t}\n\tasync #buildContext(): Promise<Context> {\n\t\treturn resolveInit(this.#init!) as any as Promise<Context>\n\t}\n}\nexport namespace AsyncContext {\n\texport type Initializer<Init> = () => Init | Promise<Init>\n\texport type Transformer<CurrentContext, AdditionalContext> = (\n\t\tcontext: CurrentContext,\n\t) => AdditionalContext | Promise<AdditionalContext>\n}\n\nasync function resolveInit<Init extends Record<string | symbol, any>>(\n\tinit: Init | Promise<Init> | AsyncContext.Initializer<Init>,\n): Promise<Init> {\n\treturn isInitializer<Init>(init) ? init() : init\n}\n\nfunction isTransformer<CurrentContext, AdditionalContext>(\n\tcontext: unknown,\n): context is AsyncContext.Transformer<CurrentContext, AdditionalContext> {\n\treturn typeof context === 'function'\n}\n\nfunction isInitializer<T>(context: unknown): context is AsyncContext.Initializer<T> {\n\treturn typeof context === 'function'\n}\n"],"mappings":";;;;;;;;;;;;;AAGA,IAAa,eAAb,MAAa,aAGX;CAMD,YAAY,MAA8D;;;EAJnB,2BAAA,MAAA,YAAA,CAAC,CAAA;EACxC,2BAAA,MAAA,eAAA,KAAA;;;EAIf,uBAAA,OAAA,MAAa,IAAA;CACd;CACA,WAAkC,MAAqE;EACtG,IAAA,uBAAA,OAAI,IAAA,GAAY,MAAM,IAAI,0BAA0B,EAAE,KAAK,KAAK,WAAW,CAAC;EAC5E,uBAAA,OAAA,MAAa,IAAA;EAEb,IAAA,uBAAA,YAAI,IAAA,CAAA,CAAgB,SAAS,GAAG,uBAAA,YAAA,IAAA,CAAA,CAAgB,SAAS,MAAM,KAAK,EAAA,kBAAA,qBAAE,MAAA,aAAA,CAAA,CAAA,KAAA,IAAmB,CAAC,CAAC;EAC3F,OAAO;CACR;CACA,OAIC,SACkE;EAClE,MAAM,SAAS,IAAI,aAAa,YAAY;GAC3C,IAAI;IACH,MAAM,QAAQ,MAAM,KAAK,IAAI;IAC7B,uBAAA,eAAA,QAAuB,IAAA;IACvB,MAAM,WAAW,OAAO,cAAwB,OAAO,IAAI,QAAQ,KAAK,IAAI;IAC5E,OAAO;KAAE,GAAG;KAAO,GAAG;IAAS;GAChC,UAAU;IACT,uBAAA,eAAA,QAAuB,KAAA;GACxB;EACD,CAAC;EACD,MAAM,MAAA,uBAAA,WAAM,IAAA,KAAkB;EAC9B,uBAAA,WAAA,QAAmB,GAAA;EACnB,OAAO,aAAa,OAAO,WAAW,KAAK,GAAG;EAC9C,OAAO;CACR;CACA,MAAM,MAA+B;EACpC,IAAA,uBAAA,eAAI,IAAA,GAAoB,MAAM,IAAI,oBAAoB,EAAE,KAAK,KAAK,IAAI,CAAC;EACvE,IAAA,uBAAA,YAAI,IAAA,GAAiB,OAAA,uBAAA,YAAO,IAAA;EAC5B,OAAA,uBAAA,YAAQ,MAAA,uBAAA,OAAkB,IAAA,IAAA,kBAAA,qBAAa,MAAA,aAAA,CAAA,CAAA,KAAA,IAAmB,IAAI,IAAI,SAAc,MAAA,uBAAA,YAAM,IAAA,CAAA,CAAgB,KAAK,CAAC,CAAC,CAAA;CAC9G;AAID;AAHC,eAAA,gBAAwC;CACvC,OAAO,YAAA,uBAAA,OAAY,IAAA,CAAW;AAC/B;AASD,eAAe,YACd,MACgB;CAChB,OAAO,cAAoB,IAAI,IAAI,KAAK,IAAI;AAC7C;AAEA,SAAS,cACR,SACyE;CACzE,OAAO,OAAO,YAAY;AAC3B;AAEA,SAAS,cAAiB,SAA0D;CACnF,OAAO,OAAO,YAAY;AAC3B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/assertClassBrand.js
|
|
2
|
+
function _assertClassBrand(e, t, n) {
|
|
3
|
+
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
4
|
+
throw new TypeError("Private element is not present on this object");
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _assertClassBrand as default };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/checkPrivateRedeclaration.js
|
|
2
|
+
function _checkPrivateRedeclaration(e, t) {
|
|
3
|
+
if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
4
|
+
}
|
|
5
|
+
//#endregion
|
|
6
|
+
export { _checkPrivateRedeclaration as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import _assertClassBrand from "./assertClassBrand.js";
|
|
2
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/classPrivateFieldGet2.js
|
|
3
|
+
function _classPrivateFieldGet2(s, a) {
|
|
4
|
+
return s.get(_assertClassBrand(s, a));
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _classPrivateFieldGet2 as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import _checkPrivateRedeclaration from "./checkPrivateRedeclaration.js";
|
|
2
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/classPrivateFieldInitSpec.js
|
|
3
|
+
function _classPrivateFieldInitSpec(e, t, a) {
|
|
4
|
+
_checkPrivateRedeclaration(e, t), t.set(e, a);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _classPrivateFieldInitSpec as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import _assertClassBrand from "./assertClassBrand.js";
|
|
2
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/classPrivateFieldSet2.js
|
|
3
|
+
function _classPrivateFieldSet2(s, a, r) {
|
|
4
|
+
return s.set(_assertClassBrand(s, a), r), r;
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _classPrivateFieldSet2 as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import _checkPrivateRedeclaration from "./checkPrivateRedeclaration.js";
|
|
2
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/classPrivateMethodInitSpec.js
|
|
3
|
+
function _classPrivateMethodInitSpec(e, a) {
|
|
4
|
+
_checkPrivateRedeclaration(e, a), a.add(e);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _classPrivateMethodInitSpec as default };
|
package/esm/errors.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { ModuleError } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ModuleError } from "iso-error";
|
|
2
|
+
//#region ts/errors.d.ts
|
|
3
|
+
declare class ContextAlreadyInitialized extends ModuleError {
|
|
4
|
+
constructor(options?: ModuleError.Options);
|
|
4
5
|
}
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
declare class BlockingGetDetected extends ModuleError {
|
|
7
|
+
constructor(options?: ModuleError.Options);
|
|
7
8
|
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { BlockingGetDetected, ContextAlreadyInitialized };
|
|
8
11
|
//# sourceMappingURL=errors.d.ts.map
|
package/esm/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","
|
|
1
|
+
{"version":3,"file":"errors.d.ts","names":[],"sources":["../ts/errors.ts"],"mappings":";;cAEa,kCAAkC;EAC9C,YAAY,UAAU,YAAY;;cAKtB,4BAA4B;EACxC,YAAY,UAAU,YAAY"}
|
package/esm/errors.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { ModuleError } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
1
|
+
import { ModuleError } from "iso-error";
|
|
2
|
+
//#region ts/errors.ts
|
|
3
|
+
var ContextAlreadyInitialized = class extends ModuleError {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
super("@unional/async-context", "context can only be initialized once.", options);
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
var BlockingGetDetected = class extends ModuleError {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super("@unional/async-context", "a blocking get() detected. Are you calling it within extend()?", options);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { BlockingGetDetected, ContextAlreadyInitialized };
|
|
15
|
+
|
|
12
16
|
//# sourceMappingURL=errors.js.map
|
package/esm/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../ts/errors.ts"],"sourcesContent":["import { ModuleError } from 'iso-error'\n\nexport class ContextAlreadyInitialized extends ModuleError {\n\tconstructor(options?: ModuleError.Options) {\n\t\tsuper('@unional/async-context', 'context can only be initialized once.', options)\n\t}\n}\n\nexport class BlockingGetDetected extends ModuleError {\n\tconstructor(options?: ModuleError.Options) {\n\t\tsuper('@unional/async-context', 'a blocking get() detected. Are you calling it within extend()?', options)\n\t}\n}\n"],"mappings":";;AAEA,IAAa,4BAAb,cAA+C,YAAY;CAC1D,YAAY,SAA+B;EAC1C,MAAM,0BAA0B,yCAAyC,OAAO;CACjF;AACD;AAEA,IAAa,sBAAb,cAAyC,YAAY;CACpD,YAAY,SAA+B;EAC1C,MAAM,0BAA0B,kEAAkE,OAAO;CAC1G;AACD"}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { AsyncContext } from "./AsyncContext.js";
|
|
2
|
+
import { BlockingGetDetected, ContextAlreadyInitialized } from "./errors.js";
|
|
3
|
+
export { AsyncContext, BlockingGetDetected, ContextAlreadyInitialized };
|
package/esm/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { BlockingGetDetected, ContextAlreadyInitialized } from "./errors.js";
|
|
2
|
+
import { AsyncContext } from "./AsyncContext.js";
|
|
3
|
+
export { AsyncContext, BlockingGetDetected, ContextAlreadyInitialized };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unional/async-context",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.15",
|
|
4
4
|
"description": "Asynchronous context for functional style programming",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"async",
|
|
@@ -53,16 +53,13 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@repobuddy/typescript": "^2.0.0",
|
|
56
|
-
"@size-limit/preset-small-lib": "^13.0.0",
|
|
57
56
|
"@types/setimmediate": "^1.0.2",
|
|
58
|
-
"@vitest/coverage-v8": "^4.
|
|
57
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
59
58
|
"assertron": "^11.0.1",
|
|
60
|
-
"npm-run-all2": "^9.0.0",
|
|
61
|
-
"repobuddy": "^1.0.2",
|
|
62
59
|
"rimraf": "^6.0.0",
|
|
63
60
|
"setimmediate": "^1.0.5",
|
|
64
|
-
"
|
|
65
|
-
"vitest": "^4.
|
|
61
|
+
"tsdown": "^0.22.14",
|
|
62
|
+
"vitest": "^4.1.11"
|
|
66
63
|
},
|
|
67
64
|
"engines": {
|
|
68
65
|
"node": ">= 14.16"
|
|
@@ -70,24 +67,14 @@
|
|
|
70
67
|
"publishConfig": {
|
|
71
68
|
"access": "public"
|
|
72
69
|
},
|
|
73
|
-
"size-limit": [
|
|
74
|
-
{
|
|
75
|
-
"path": "./cjs/index.js"
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
"path": "./esm/index.js"
|
|
79
|
-
}
|
|
80
|
-
],
|
|
81
70
|
"scripts": {
|
|
82
|
-
"build": "
|
|
83
|
-
"build:cjs": "buddy ts build cjs",
|
|
84
|
-
"build:esm": "tsc",
|
|
71
|
+
"build": "tsdown",
|
|
85
72
|
"clean": "rimraf cjs esm coverage *.tsbuildinfo",
|
|
86
73
|
"coverage": "vitest run --coverage",
|
|
87
74
|
"lint": "biome check .",
|
|
88
75
|
"nuke": "pnpm clean && rimraf node_modules",
|
|
89
|
-
"size": "size-limit",
|
|
90
76
|
"test": "vitest run",
|
|
91
|
-
"
|
|
77
|
+
"typecheck": "tsc",
|
|
78
|
+
"verify": "pnpm run lint && pnpm run typecheck && pnpm run build && pnpm run coverage"
|
|
92
79
|
}
|
|
93
80
|
}
|
package/cjs/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA"}
|
package/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,8CAA2B"}
|
package/esm/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA"}
|
package/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA"}
|