@unional/async-context 9.0.13 → 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.
Files changed (41) hide show
  1. package/README.md +2 -2
  2. package/cjs/AsyncContext.d.ts +13 -10
  3. package/cjs/AsyncContext.d.ts.map +1 -1
  4. package/cjs/AsyncContext.js +61 -66
  5. package/cjs/AsyncContext.js.map +1 -1
  6. package/cjs/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/assertClassBrand.js +7 -0
  7. package/cjs/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/checkPrivateRedeclaration.js +6 -0
  8. package/cjs/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldGet2.js +7 -0
  9. package/cjs/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldInitSpec.js +7 -0
  10. package/cjs/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldSet2.js +7 -0
  11. package/cjs/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateMethodInitSpec.js +7 -0
  12. package/cjs/errors.d.ts +8 -5
  13. package/cjs/errors.d.ts.map +1 -1
  14. package/cjs/errors.js +15 -15
  15. package/cjs/errors.js.map +1 -1
  16. package/cjs/index.d.ts +3 -3
  17. package/cjs/index.js +6 -19
  18. package/cjs/package.json +2 -2
  19. package/esm/AsyncContext.d.ts +13 -10
  20. package/esm/AsyncContext.d.ts.map +1 -1
  21. package/esm/AsyncContext.js +61 -62
  22. package/esm/AsyncContext.js.map +1 -1
  23. package/esm/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/assertClassBrand.js +7 -0
  24. package/esm/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/checkPrivateRedeclaration.js +6 -0
  25. package/esm/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldGet2.js +7 -0
  26. package/esm/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldInitSpec.js +7 -0
  27. package/esm/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateFieldSet2.js +7 -0
  28. package/esm/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/classPrivateMethodInitSpec.js +7 -0
  29. package/esm/errors.d.ts +8 -5
  30. package/esm/errors.d.ts.map +1 -1
  31. package/esm/errors.js +15 -11
  32. package/esm/errors.js.map +1 -1
  33. package/esm/index.d.ts +3 -3
  34. package/esm/index.js +3 -3
  35. package/package.json +16 -37
  36. package/ts/AsyncContext.ts +9 -16
  37. package/ts/errors.ts +1 -5
  38. package/cjs/index.d.ts.map +0 -1
  39. package/cjs/index.js.map +0 -1
  40. package/esm/index.d.ts.map +0 -1
  41. package/esm/index.js.map +0 -1
package/README.md CHANGED
@@ -210,8 +210,8 @@ configure({ ... })
210
210
 
211
211
  [bundlephobia-image]: https://img.shields.io/bundlephobia/minzip/@unional/async-context.svg
212
212
  [bundlephobia-url]: https://bundlephobia.com/result?p=@unional/async-context
213
- [codecov-image]: https://codecov.io/gh/unional/async-fp/branch/main/graph/badge.svg
214
- [codecov-url]: https://codecov.io/gh/unional/async-fp
213
+ [codecov-image]: https://codecov.io/gh/cyberuni/async-fp/branch/main/graph/badge.svg
214
+ [codecov-url]: https://codecov.io/gh/cyberuni/async-fp
215
215
  [downloads-image]: https://img.shields.io/npm/dm/@unional/async-context.svg?style=flat
216
216
  [downloads-url]: https://npmjs.org/package/@unional/async-context
217
217
  [introduction_video]: https://youtu.be/9EnrSJdvP48
@@ -1,13 +1,16 @@
1
- import type { LeftJoin } from 'type-plus';
2
- export declare class AsyncContext<Init extends Record<string | symbol, any>, Context extends Record<string | symbol, any> = Init> {
3
- #private;
4
- constructor(init?: Init | Promise<Init> | AsyncContext.Initializer<Init>);
5
- initialize<I extends Init = Init>(init: I | Promise<I> | AsyncContext.Initializer<I>): AsyncContext<I>;
6
- 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>>;
7
- get<C = Context>(): Promise<C>;
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
- export declare namespace AsyncContext {
10
- type Initializer<Init> = () => Init | Promise<Init>;
11
- type Transformer<CurrentContext, AdditionalContext> = (context: CurrentContext) => AdditionalContext | Promise<AdditionalContext>;
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","sourceRoot":"","sources":["../ts/AsyncContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAGzC,qBAAa,YAAY,CACxB,IAAI,SAAS,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EACzC,OAAO,SAAS,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;;gBAOvC,IAAI,CAAC,EAAE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AOpG,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"}
@@ -1,75 +1,70 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
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
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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 => 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")
58
- ? __classPrivateFieldGet(this, _AsyncContext_instances, "m", _AsyncContext_buildContext).call(this)
59
- : new Promise(a => __classPrivateFieldGet(this, _AsyncContext_resolvers, "f").push(a)), "f"));
60
- }
55
+ async function _buildContext() {
56
+ return resolveInit(require_classPrivateFieldGet2.default(_init, this));
61
57
  }
62
- exports.AsyncContext = AsyncContext;
63
- _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() {
64
- return resolveInit(__classPrivateFieldGet(this, _AsyncContext_init, "f"));
65
- };
66
58
  async function resolveInit(init) {
67
- return isInitializer(init) ? init() : init;
59
+ return isInitializer(init) ? init() : init;
68
60
  }
69
61
  function isTransformer(context) {
70
- return typeof context === 'function';
62
+ return typeof context === "function";
71
63
  }
72
64
  function isInitializer(context) {
73
- return typeof context === 'function';
65
+ return typeof context === "function";
74
66
  }
67
+ //#endregion
68
+ exports.AsyncContext = AsyncContext;
69
+
75
70
  //# sourceMappingURL=AsyncContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AsyncContext.js","sourceRoot":"","sources":["../ts/AsyncContext.ts"],"names":[],"mappings":";;;;;;;;;;;;;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CAAA;QACtB,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC/C,OAAO,MAAM,CAAA;IACd,CAAC;IACD,KAAK,CAAC,GAAG;QACR,IAAI,uBAAA,IAAI,kCAAc;YAAE,MAAM,IAAI,+BAAmB,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QACxE,IAAI,uBAAA,IAAI,+BAAW;YAAE,OAAO,uBAAA,IAAI,+BAAW,CAAA;QAC3C,OAAO,CAAC,uBAAA,IAAI,2BAAc,uBAAA,IAAI,0BAAM;YACnC,CAAC,CAAC,uBAAA,IAAI,2DAAc,MAAlB,IAAI,CAAgB;YACtB,CAAC,CAAC,IAAI,OAAO,CAAM,CAAC,CAAC,EAAE,CAAC,uBAAA,IAAI,+BAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAA,CAAC,CAAA;IACnD,CAAC;CAID;AAvDD,oCAuDC;gRAHA,KAAK;IACJ,OAAO,WAAW,CAAC,uBAAA,IAAI,0BAAO,CAA4B,CAAA;AAC3D,CAAC;AASF,KAAK,UAAU,WAAW,CACzB,IAA2D;IAE3D,OAAO,aAAa,CAAO,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AACjD,CAAC;AAED,SAAS,aAAa,CACrB,OAAgB;IAEhB,OAAO,OAAO,OAAO,KAAK,UAAU,CAAA;AACrC,CAAC;AAED,SAAS,aAAa,CAAI,OAAgB;IACzC,OAAO,OAAO,OAAO,KAAK,UAAU,CAAA;AACrC,CAAC"}
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 'iso-error';
2
- export declare class ContextAlreadyInitialized extends ModuleError {
3
- constructor(options?: ModuleError.Options);
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
- export declare class BlockingGetDetected extends ModuleError {
6
- constructor(options?: ModuleError.Options);
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
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../ts/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvC,qBAAa,yBAA0B,SAAQ,WAAW;gBAC7C,OAAO,CAAC,EAAE,WAAW,CAAC,OAAO;CAGzC;AAED,qBAAa,mBAAoB,SAAQ,WAAW;gBACvC,OAAO,CAAC,EAAE,WAAW,CAAC,OAAO;CAOzC"}
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BlockingGetDetected = exports.ContextAlreadyInitialized = void 0;
4
- const iso_error_1 = require("iso-error");
5
- class ContextAlreadyInitialized extends iso_error_1.ModuleError {
6
- constructor(options) {
7
- super('@unional/async-context', 'context can only be initialized once.', options);
8
- }
9
- }
10
- exports.ContextAlreadyInitialized = ContextAlreadyInitialized;
11
- class BlockingGetDetected extends iso_error_1.ModuleError {
12
- constructor(options) {
13
- super('@unional/async-context', `a blocking get() detected. Are you calling it within extend()?`, options);
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","sourceRoot":"","sources":["../ts/errors.ts"],"names":[],"mappings":";;;AAAA,yCAAuC;AAEvC,MAAa,yBAA0B,SAAQ,uBAAW;IACzD,YAAY,OAA6B;QACxC,KAAK,CAAC,wBAAwB,EAAE,uCAAuC,EAAE,OAAO,CAAC,CAAA;IAClF,CAAC;CACD;AAJD,8DAIC;AAED,MAAa,mBAAoB,SAAQ,uBAAW;IACnD,YAAY,OAA6B;QACxC,KAAK,CACJ,wBAAwB,EACxB,gEAAgE,EAChE,OAAO,CACP,CAAA;IACF,CAAC;CACD;AARD,kDAQC"}
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
- export * from './AsyncContext.js';
2
- export * from './errors.js';
3
- //# sourceMappingURL=index.d.ts.map
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
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
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/cjs/package.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "type": "commonjs"
3
- }
2
+ "type": "commonjs"
3
+ }
@@ -1,13 +1,16 @@
1
- import type { LeftJoin } from 'type-plus';
2
- export declare class AsyncContext<Init extends Record<string | symbol, any>, Context extends Record<string | symbol, any> = Init> {
3
- #private;
4
- constructor(init?: Init | Promise<Init> | AsyncContext.Initializer<Init>);
5
- initialize<I extends Init = Init>(init: I | Promise<I> | AsyncContext.Initializer<I>): AsyncContext<I>;
6
- 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>>;
7
- get<C = Context>(): Promise<C>;
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
- export declare namespace AsyncContext {
10
- type Initializer<Init> = () => Init | Promise<Init>;
11
- type Transformer<CurrentContext, AdditionalContext> = (context: CurrentContext) => AdditionalContext | Promise<AdditionalContext>;
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","sourceRoot":"","sources":["../ts/AsyncContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAGzC,qBAAa,YAAY,CACxB,IAAI,SAA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ACb,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"}
@@ -1,71 +1,70 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
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
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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 => 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")
55
- ? __classPrivateFieldGet(this, _AsyncContext_instances, "m", _AsyncContext_buildContext).call(this)
56
- : new Promise(a => __classPrivateFieldGet(this, _AsyncContext_resolvers, "f").push(a)), "f"));
57
- }
55
+ async function _buildContext() {
56
+ return resolveInit(_classPrivateFieldGet2(_init, this));
58
57
  }
59
- _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() {
60
- return resolveInit(__classPrivateFieldGet(this, _AsyncContext_init, "f"));
61
- };
62
58
  async function resolveInit(init) {
63
- return isInitializer(init) ? init() : init;
59
+ return isInitializer(init) ? init() : init;
64
60
  }
65
61
  function isTransformer(context) {
66
- return typeof context === 'function';
62
+ return typeof context === "function";
67
63
  }
68
64
  function isInitializer(context) {
69
- return typeof context === 'function';
65
+ return typeof context === "function";
70
66
  }
67
+ //#endregion
68
+ export { AsyncContext };
69
+
71
70
  //# sourceMappingURL=AsyncContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AsyncContext.js","sourceRoot":"","sources":["../ts/AsyncContext.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,mBAAmB,EAAE,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AM,0BAAa,GAAG,MAAA,CAAA;QACtB,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC/C,OAAO,MAAM,CAAA;IACd,CAAC;IACD,KAAK,CAAC,GAAG;QACR,IAAI,uBAAA,IAAI,kCAAc;YAAE,MAAM,IAAI,mBAAmB,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QACxE,IAAI,uBAAA,IAAI,+BAAW;YAAE,OAAO,uBAAA,IAAI,+BAAW,CAAA;QAC3C,OAAO,CAAC,uBAAA,IAAI,2BAAc,uBAAA,IAAI,0BAAM;YACnC,CAAC,CAAC,uBAAA,IAAI,2DAAc,MAAlB,IAAI,CAAgB;YACtB,CAAC,CAAC,IAAI,OAAO,CAAM,CAAC,CAAC,EAAE,CAAC,uBAAA,IAAI,+BAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAA,CAAC,CAAA;IACnD,CAAC;CAID;gRAHA,KAAK;IACJ,OAAO,WAAW,CAAC,uBAAA,IAAI,0BAAO,CAA4B,CAAA;AAC3D,CAAC;AASF,KAAK,UAAU,WAAW,CACzB,IAA2D;IAE3D,OAAO,aAAa,CAAO,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AACjD,CAAC;AAED,SAAS,aAAa,CACrB,OAAgB;IAEhB,OAAO,OAAO,OAAO,KAAK,UAAU,CAAA;AACrC,CAAC;AAED,SAAS,aAAa,CAAI,OAAgB;IACzC,OAAO,OAAO,OAAO,KAAK,UAAU,CAAA;AACrC,CAAC"}
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 'iso-error';
2
- export declare class ContextAlreadyInitialized extends ModuleError {
3
- constructor(options?: ModuleError.Options);
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
- export declare class BlockingGetDetected extends ModuleError {
6
- constructor(options?: ModuleError.Options);
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
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../ts/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvC,qBAAa,yBAA0B,SAAQ,WAAW;gBAC7C,OAAO,CAAC,EAAE,WAAW,CAAC,OAAO;CAGzC;AAED,qBAAa,mBAAoB,SAAQ,WAAW;gBACvC,OAAO,CAAC,EAAE,WAAW,CAAC,OAAO;CAOzC"}
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 'iso-error';
2
- export class ContextAlreadyInitialized extends ModuleError {
3
- constructor(options) {
4
- super('@unional/async-context', 'context can only be initialized once.', options);
5
- }
6
- }
7
- export class BlockingGetDetected extends ModuleError {
8
- constructor(options) {
9
- super('@unional/async-context', `a blocking get() detected. Are you calling it within extend()?`, options);
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","sourceRoot":"","sources":["../ts/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvC,MAAM,OAAO,yBAA0B,SAAQ,WAAW;IACzD,YAAY,OAA6B;QACxC,KAAK,CAAC,wBAAwB,EAAE,uCAAuC,EAAE,OAAO,CAAC,CAAA;IAClF,CAAC;CACD;AAED,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IACnD,YAAY,OAA6B;QACxC,KAAK,CACJ,wBAAwB,EACxB,gEAAgE,EAChE,OAAO,CACP,CAAA;IACF,CAAC;CACD"}
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
- export * from './AsyncContext.js';
2
- export * from './errors.js';
3
- //# sourceMappingURL=index.d.ts.map
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
- export * from './AsyncContext.js';
2
- export * from './errors.js';
3
- //# sourceMappingURL=index.js.map
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.13",
3
+ "version": "9.0.15",
4
4
  "description": "Asynchronous context for functional style programming",
5
5
  "keywords": [
6
6
  "async",
@@ -9,13 +9,13 @@
9
9
  "functional",
10
10
  "typescript"
11
11
  ],
12
- "homepage": "https://github.com/unional/async-fp/tree/main/packages/async-context",
12
+ "homepage": "https://github.com/cyberuni/async-fp/tree/main/packages/async-context",
13
13
  "bugs": {
14
- "url": "https://github.com/unional/async-fp/issues"
14
+ "url": "https://github.com/cyberuni/async-fp/issues"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
18
- "url": "https://github.com/unional/async-fp.git",
18
+ "url": "https://github.com/cyberuni/async-fp.git",
19
19
  "directory": "packages/async-context"
20
20
  },
21
21
  "license": "MIT",
@@ -49,27 +49,17 @@
49
49
  ],
50
50
  "dependencies": {
51
51
  "iso-error": "^6.0.2",
52
- "type-plus": "^7.0.1"
52
+ "type-plus": "8.0.0-beta.8"
53
53
  },
54
54
  "devDependencies": {
55
- "@repobuddy/jest": "^3.2.0",
56
- "@repobuddy/typescript": "^1.2.0",
57
- "@size-limit/preset-small-lib": "^8.0.1",
55
+ "@repobuddy/typescript": "^2.0.0",
58
56
  "@types/setimmediate": "^1.0.2",
57
+ "@vitest/coverage-v8": "^4.1.11",
59
58
  "assertron": "^11.0.1",
60
- "cross-env": "^7.0.3",
61
- "depcheck": "^1.4.3",
62
- "jest": "^29.5.0",
63
- "jest-esm-transformer-2": "^1.0.0",
64
- "jest-watch-suspend": "^1.1.2",
65
- "jest-watch-toggle-config-2": "^2.1.0",
66
- "jest-watch-typeahead": "^2.2.2",
67
- "npm-run-all": "^4.1.5",
68
- "repobuddy": "^1.0.2",
69
- "rimraf": "^5.0.0",
59
+ "rimraf": "^6.0.0",
70
60
  "setimmediate": "^1.0.5",
71
- "size-limit": "^8.0.1",
72
- "ts-jest": "^29.1.0"
61
+ "tsdown": "^0.22.14",
62
+ "vitest": "^4.1.11"
73
63
  },
74
64
  "engines": {
75
65
  "node": ">= 14.16"
@@ -77,25 +67,14 @@
77
67
  "publishConfig": {
78
68
  "access": "public"
79
69
  },
80
- "size-limit": [
81
- {
82
- "path": "./cjs/index.js"
83
- },
84
- {
85
- "path": "./esm/index.js"
86
- }
87
- ],
88
70
  "scripts": {
89
- "build": "run-p build:cjs build:esm",
90
- "build:cjs": "buddy ts build cjs",
91
- "build:esm": "tsc",
71
+ "build": "tsdown",
92
72
  "clean": "rimraf cjs esm coverage *.tsbuildinfo",
93
- "coverage": "jest --coverage",
94
- "depcheck": "depcheck",
95
- "lint": "cross-env TIMING=1 eslint --ext=ts,js,cjs,mjs .",
73
+ "coverage": "vitest run --coverage",
74
+ "lint": "biome check .",
96
75
  "nuke": "pnpm clean && rimraf node_modules",
97
- "size": "size-limit",
98
- "test": "jest",
99
- "verify": "npm-run-all -p lint build coverage -p depcheck size"
76
+ "test": "vitest run",
77
+ "typecheck": "tsc",
78
+ "verify": "pnpm run lint && pnpm run typecheck && pnpm run build && pnpm run coverage"
100
79
  }
101
80
  }
@@ -3,7 +3,7 @@ import { BlockingGetDetected, ContextAlreadyInitialized } from './errors.js'
3
3
 
4
4
  export class AsyncContext<
5
5
  Init extends Record<string | symbol, any>,
6
- Context extends Record<string | symbol, any> = Init
6
+ Context extends Record<string | symbol, any> = Init,
7
7
  > {
8
8
  #resolving: Promise<any> | undefined
9
9
  #resolvers: Array<(value: Promise<Context>) => void> = []
@@ -13,23 +13,18 @@ export class AsyncContext<
13
13
  constructor(init?: Init | Promise<Init> | AsyncContext.Initializer<Init>) {
14
14
  this.#init = init
15
15
  }
16
- initialize<I extends Init = Init>(
17
- init: I | Promise<I> | AsyncContext.Initializer<I>
18
- ): AsyncContext<I> {
16
+ initialize<I extends Init = Init>(init: I | Promise<I> | AsyncContext.Initializer<I>): AsyncContext<I> {
19
17
  if (this.#init) throw new ContextAlreadyInitialized({ ssf: this.initialize })
20
18
  this.#init = init
21
19
 
22
- if (this.#resolvers.length > 0) this.#resolvers.forEach(r => r(this.#buildContext()))
20
+ if (this.#resolvers.length > 0) this.#resolvers.forEach((r) => void r(this.#buildContext()))
23
21
  return this as any as AsyncContext<I>
24
22
  }
25
23
  extend<
26
24
  CurrentContext extends Record<string | symbol, any> = Context,
27
- AdditionalContext extends Record<string | symbol, any> = Record<string | symbol, any>
25
+ AdditionalContext extends Record<string | symbol, any> = Record<string | symbol, any>,
28
26
  >(
29
- context:
30
- | AdditionalContext
31
- | Promise<AdditionalContext>
32
- | AsyncContext.Transformer<Context, AdditionalContext>
27
+ context: AdditionalContext | Promise<AdditionalContext> | AsyncContext.Transformer<Context, AdditionalContext>,
33
28
  ): AsyncContext<Init, LeftJoin<CurrentContext, AdditionalContext>> {
34
29
  const newctx = new AsyncContext(async () => {
35
30
  try {
@@ -49,9 +44,7 @@ export class AsyncContext<
49
44
  async get<C = Context>(): Promise<C> {
50
45
  if (this.#transforming) throw new BlockingGetDetected({ ssf: this.get })
51
46
  if (this.#resolving) return this.#resolving
52
- return (this.#resolving = this.#init
53
- ? this.#buildContext()
54
- : new Promise<any>(a => this.#resolvers.push(a)))
47
+ return (this.#resolving = this.#init ? this.#buildContext() : new Promise<any>((a) => this.#resolvers.push(a)))
55
48
  }
56
49
  async #buildContext(): Promise<Context> {
57
50
  return resolveInit(this.#init!) as any as Promise<Context>
@@ -60,18 +53,18 @@ export class AsyncContext<
60
53
  export namespace AsyncContext {
61
54
  export type Initializer<Init> = () => Init | Promise<Init>
62
55
  export type Transformer<CurrentContext, AdditionalContext> = (
63
- context: CurrentContext
56
+ context: CurrentContext,
64
57
  ) => AdditionalContext | Promise<AdditionalContext>
65
58
  }
66
59
 
67
60
  async function resolveInit<Init extends Record<string | symbol, any>>(
68
- init: Init | Promise<Init> | AsyncContext.Initializer<Init>
61
+ init: Init | Promise<Init> | AsyncContext.Initializer<Init>,
69
62
  ): Promise<Init> {
70
63
  return isInitializer<Init>(init) ? init() : init
71
64
  }
72
65
 
73
66
  function isTransformer<CurrentContext, AdditionalContext>(
74
- context: unknown
67
+ context: unknown,
75
68
  ): context is AsyncContext.Transformer<CurrentContext, AdditionalContext> {
76
69
  return typeof context === 'function'
77
70
  }
package/ts/errors.ts CHANGED
@@ -8,10 +8,6 @@ export class ContextAlreadyInitialized extends ModuleError {
8
8
 
9
9
  export class BlockingGetDetected extends ModuleError {
10
10
  constructor(options?: ModuleError.Options) {
11
- super(
12
- '@unional/async-context',
13
- `a blocking get() detected. Are you calling it within extend()?`,
14
- options
15
- )
11
+ super('@unional/async-context', 'a blocking get() detected. Are you calling it within extend()?', options)
16
12
  }
17
13
  }
@@ -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"}
@@ -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"}