@slates/provider 1.0.0-rc.11 → 1.0.0-rc.12

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/dist/index.cjs CHANGED
@@ -126,7 +126,10 @@ var import_axios = require("axios");
126
126
 
127
127
  // src/context/hook.ts
128
128
  var import_async_hooks = require("async_hooks");
129
- var asyncLocalStorage = new import_async_hooks.AsyncLocalStorage();
129
+ var slateContextStorageKey = /* @__PURE__ */ Symbol.for("slates.provider.context.asyncLocalStorage");
130
+ var globalWithSlateContext = globalThis;
131
+ var asyncLocalStorage = globalWithSlateContext[slateContextStorageKey] ?? new import_async_hooks.AsyncLocalStorage();
132
+ globalWithSlateContext[slateContextStorageKey] = asyncLocalStorage;
130
133
  var runWithContext = (context, fn) => {
131
134
  return asyncLocalStorage.run(context, fn);
132
135
  };
package/dist/index.d.cts CHANGED
@@ -92,6 +92,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
92
92
  clientId: string;
93
93
  clientSecret: string;
94
94
  scopes: string[];
95
+ callbackParams?: Record<string, string>;
95
96
  callbackState: Record<string, any>;
96
97
  }) => Promise<{
97
98
  output: OutputType;
package/dist/index.d.ts CHANGED
@@ -92,6 +92,7 @@ type SlateAuthWithOauth<InputType extends {}, OutputType extends {
92
92
  clientId: string;
93
93
  clientSecret: string;
94
94
  scopes: string[];
95
+ callbackParams?: Record<string, string>;
95
96
  callbackState: Record<string, any>;
96
97
  }) => Promise<{
97
98
  output: OutputType;
@@ -55,7 +55,10 @@ import { isAxiosError } from "axios";
55
55
 
56
56
  // src/context/hook.ts
57
57
  import { AsyncLocalStorage } from "async_hooks";
58
- var asyncLocalStorage = new AsyncLocalStorage();
58
+ var slateContextStorageKey = /* @__PURE__ */ Symbol.for("slates.provider.context.asyncLocalStorage");
59
+ var globalWithSlateContext = globalThis;
60
+ var asyncLocalStorage = globalWithSlateContext[slateContextStorageKey] ?? new AsyncLocalStorage();
61
+ globalWithSlateContext[slateContextStorageKey] = asyncLocalStorage;
59
62
  var runWithContext = (context, fn) => {
60
63
  return asyncLocalStorage.run(context, fn);
61
64
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slates/provider",
3
- "version": "1.0.0-rc.11",
3
+ "version": "1.0.0-rc.12",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -42,4 +42,4 @@
42
42
  "typescript": "5.8.2",
43
43
  "vitest": "^3.1.2"
44
44
  }
45
- }
45
+ }
package/src/auth/types.ts CHANGED
@@ -50,6 +50,7 @@ export type SlateAuthWithOauth<
50
50
  clientId: string;
51
51
  clientSecret: string;
52
52
  scopes: string[];
53
+ callbackParams?: Record<string, string>;
53
54
  callbackState: Record<string, any>;
54
55
  }) => Promise<{
55
56
  output: OutputType;
@@ -0,0 +1,21 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { SlateContext } from './context';
3
+ import { runWithContext } from './hook';
4
+
5
+ describe('slate context hook', () => {
6
+ it('shares context storage across duplicate module instances', async () => {
7
+ // @ts-expect-error Vite treats the query as a distinct module instance.
8
+ let duplicateHook: typeof import('./hook') = await import('./hook?duplicate-instance');
9
+ let context = new SlateContext({}, {}, {}, {} as any, {
10
+ debug: () => {},
11
+ error: () => {},
12
+ info: () => {},
13
+ progress: () => {},
14
+ warn: () => {}
15
+ } as any);
16
+
17
+ let result = await runWithContext(context, async () => duplicateHook.getCurrentContext());
18
+
19
+ expect(result).toBe(context);
20
+ });
21
+ });
@@ -1,7 +1,16 @@
1
1
  import { AsyncLocalStorage } from 'async_hooks';
2
2
  import type { SlateContext } from './context';
3
3
 
4
- let asyncLocalStorage = new AsyncLocalStorage<SlateContext<any, any, any>>();
4
+ let slateContextStorageKey = Symbol.for('slates.provider.context.asyncLocalStorage');
5
+ let globalWithSlateContext = globalThis as typeof globalThis & {
6
+ [key: symbol]: AsyncLocalStorage<SlateContext<any, any, any>> | undefined;
7
+ };
8
+
9
+ let asyncLocalStorage =
10
+ globalWithSlateContext[slateContextStorageKey] ??
11
+ new AsyncLocalStorage<SlateContext<any, any, any>>();
12
+
13
+ globalWithSlateContext[slateContextStorageKey] = asyncLocalStorage;
5
14
 
6
15
  export let runWithContext = <
7
16
  ConfigType extends {},