@travetto/context 3.0.0-rc.1 → 3.0.0-rc.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <!-- This file was generated by @travetto/doc and should not be modified directly -->
2
- <!-- Please modify https://github.com/travetto/travetto/tree/main/module/context/doc.ts and execute "npx trv doc" to rebuild -->
2
+ <!-- Please modify https://github.com/travetto/travetto/tree/main/module/context/DOC.ts and execute "npx trv doc" to rebuild -->
3
3
  # Async Context
4
4
  ## Async-aware state management, maintaining context across asynchronous calls.
5
5
 
File without changes
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/context",
3
- "displayName": "Async Context",
4
- "version": "3.0.0-rc.1",
3
+ "version": "3.0.0-rc.10",
5
4
  "description": "Async-aware state management, maintaining context across asynchronous calls.",
6
5
  "keywords": [
7
6
  "async-hooks",
@@ -17,17 +16,28 @@
17
16
  "name": "Travetto Framework"
18
17
  },
19
18
  "files": [
20
- "index.ts",
19
+ "__index__.ts",
21
20
  "src",
22
- "test-support"
21
+ "support"
23
22
  ],
24
- "main": "index.ts",
23
+ "main": "__index__.ts",
25
24
  "repository": {
26
25
  "url": "https://github.com/travetto/travetto.git",
27
26
  "directory": "module/context"
28
27
  },
29
28
  "dependencies": {
30
- "@travetto/di": "^3.0.0-rc.1"
29
+ "@travetto/di": "^3.0.0-rc.10"
30
+ },
31
+ "peerDependencies": {
32
+ "@travetto/test": "^3.0.0-rc.11"
33
+ },
34
+ "peerDependenciesMeta": {
35
+ "@travetto/test": {
36
+ "optional": true
37
+ }
38
+ },
39
+ "travetto": {
40
+ "displayName": "Async Context"
31
41
  },
32
42
  "publishConfig": {
33
43
  "access": "public"
package/src/decorator.ts CHANGED
@@ -12,8 +12,7 @@ export function WithAsyncContext<T extends { context: AsyncContext }>(data?: Rec
12
12
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
13
13
  const og = descriptor.value! as (this: T, ...args: unknown[]) => Promise<V>;
14
14
  descriptor.value = function (this: T, ...args: unknown[]): Promise<V> {
15
- return (this.context.run(og.bind(this, ...args),
16
- data ? JSON.parse(JSON.stringify(data)) : {}));
15
+ return this.context.run(og.bind(this, ...args), structuredClone(data ?? {}));
17
16
  };
18
17
 
19
18
  Object.defineProperty(descriptor.value, 'name', { value: og.name });
package/src/service.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as asyncHooks from 'async_hooks';
1
+ import asyncHooks from 'async_hooks';
2
2
 
3
3
  import { Injectable } from '@travetto/di';
4
4
  import { AppError } from '@travetto/base';
@@ -67,7 +67,7 @@ export class AsyncContext {
67
67
  /**
68
68
  * Run an async function and ensure the context is available during execution
69
69
  */
70
- async run<T = unknown>(fn: () => Promise<T>, init: Ctx = {}): Promise<T> {
70
+ async run<T = unknown>(fn: () => Promise<T> | T, init: Ctx = {}): Promise<T> {
71
71
  if (this.alStorage.getStore()) {
72
72
  init = { ...this.#store(), ...init };
73
73
  }
@@ -1,8 +1,9 @@
1
1
  import { DependencyRegistry } from '@travetto/di';
2
2
  import { Class } from '@travetto/base';
3
+ import { RootRegistry } from '@travetto/registry';
3
4
  import { SuiteRegistry } from '@travetto/test';
4
5
 
5
- import { AsyncContext } from '../src/service';
6
+ import { AsyncContext } from '../../src/service';
6
7
 
7
8
  const Init = Symbol();
8
9
 
@@ -14,7 +15,7 @@ export function WithSuiteContext(data: Record<string, unknown> = {}) {
14
15
  return (target: Class): void => {
15
16
  function wrapped(ctx: AsyncContext, og: Function) {
16
17
  return function (this: unknown) {
17
- return ctx.run(og.bind(this), JSON.parse(JSON.stringify(data)));
18
+ return ctx.run(og.bind(this), structuredClone(data));
18
19
  };
19
20
  }
20
21
 
@@ -22,6 +23,7 @@ export function WithSuiteContext(data: Record<string, unknown> = {}) {
22
23
  async function (this: { [Init]?: boolean } & Record<string, Function>) {
23
24
  if (!this[Init]) {
24
25
  this[Init] = true;
26
+ await RootRegistry.init();
25
27
  const ctx = await DependencyRegistry.getInstance(AsyncContext);
26
28
  for (const t of SuiteRegistry.get(target).tests) {
27
29
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions