@assistant-ui/store 0.1.6 → 0.2.0
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 +9 -10
- package/dist/AuiIf.d.ts +1 -1
- package/dist/AuiIf.d.ts.map +1 -1
- package/dist/AuiIf.js.map +1 -1
- package/dist/index.d.ts +3 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -10
- package/dist/index.js.map +1 -1
- package/dist/scope-registry-forward.d.ts +6 -0
- package/dist/scope-registry-forward.d.ts.map +1 -0
- package/dist/scope-registry-forward.js +2 -0
- package/dist/scope-registry-forward.js.map +1 -0
- package/dist/scope-registry.d.ts +17 -0
- package/dist/scope-registry.d.ts.map +1 -0
- package/dist/scope-registry.js +2 -0
- package/dist/scope-registry.js.map +1 -0
- package/dist/useAui.d.ts +3 -5
- package/dist/useAui.d.ts.map +1 -1
- package/dist/useAui.js +6 -11
- package/dist/useAui.js.map +1 -1
- package/dist/useAuiEvent.d.ts +1 -1
- package/dist/useAuiEvent.d.ts.map +1 -1
- package/dist/useAuiEvent.js +1 -1
- package/dist/useAuiEvent.js.map +1 -1
- package/dist/useAuiState.d.ts +1 -1
- package/dist/useAuiState.d.ts.map +1 -1
- package/dist/useAuiState.js +1 -1
- package/dist/useAuiState.js.map +1 -1
- package/dist/utils/react-assistant-context.d.ts +1 -1
- package/dist/utils/react-assistant-context.d.ts.map +1 -1
- package/dist/utils/react-assistant-context.js +1 -2
- package/dist/utils/react-assistant-context.js.map +1 -1
- package/package.json +10 -3
- package/src/{AuiIf.tsx → AuiIf.ts} +1 -1
- package/src/__tests__/hooks.test.tsx +126 -0
- package/src/index.ts +25 -32
- package/src/scope-registry-forward.ts +6 -0
- package/src/scope-registry.ts +15 -0
- package/src/{useAui.tsx → useAui.ts} +24 -27
- package/src/useAuiEvent.ts +2 -2
- package/src/{useAuiState.tsx → useAuiState.ts} +3 -3
- package/src/utils/react-assistant-context.tsx +7 -3
- package/dist/Derived.d.ts +0 -34
- package/dist/Derived.d.ts.map +0 -1
- package/dist/Derived.js +0 -24
- package/dist/Derived.js.map +0 -1
- package/dist/attachDefaultPeers.d.ts +0 -56
- package/dist/attachDefaultPeers.d.ts.map +0 -1
- package/dist/attachDefaultPeers.js +0 -51
- package/dist/attachDefaultPeers.js.map +0 -1
- package/dist/tapClientList.d.ts +0 -24
- package/dist/tapClientList.d.ts.map +0 -1
- package/dist/tapClientList.js +0 -68
- package/dist/tapClientList.js.map +0 -1
- package/dist/tapClientLookup.d.ts +0 -11
- package/dist/tapClientLookup.d.ts.map +0 -1
- package/dist/tapClientLookup.js +0 -42
- package/dist/tapClientLookup.js.map +0 -1
- package/dist/tapClientResource.d.ts +0 -28
- package/dist/tapClientResource.d.ts.map +0 -1
- package/dist/tapClientResource.js +0 -122
- package/dist/tapClientResource.js.map +0 -1
- package/dist/types/client.d.ts +0 -119
- package/dist/types/client.d.ts.map +0 -1
- package/dist/types/client.js +0 -2
- package/dist/types/client.js.map +0 -1
- package/dist/types/events.d.ts +0 -33
- package/dist/types/events.d.ts.map +0 -1
- package/dist/types/events.js +0 -8
- package/dist/types/events.js.map +0 -1
- package/dist/utils/BaseProxyHandler.d.ts +0 -23
- package/dist/utils/BaseProxyHandler.d.ts.map +0 -1
- package/dist/utils/BaseProxyHandler.js +0 -46
- package/dist/utils/BaseProxyHandler.js.map +0 -1
- package/dist/utils/NotificationManager.d.ts +0 -11
- package/dist/utils/NotificationManager.d.ts.map +0 -1
- package/dist/utils/NotificationManager.js +0 -84
- package/dist/utils/NotificationManager.js.map +0 -1
- package/dist/utils/proxied-assistant-state.d.ts +0 -8
- package/dist/utils/proxied-assistant-state.d.ts.map +0 -1
- package/dist/utils/proxied-assistant-state.js +0 -34
- package/dist/utils/proxied-assistant-state.js.map +0 -1
- package/dist/utils/splitClients.d.ts +0 -10
- package/dist/utils/splitClients.d.ts.map +0 -1
- package/dist/utils/splitClients.js +0 -83
- package/dist/utils/splitClients.js.map +0 -1
- package/dist/utils/tap-assistant-context.d.ts +0 -19
- package/dist/utils/tap-assistant-context.d.ts.map +0 -1
- package/dist/utils/tap-assistant-context.js +0 -23
- package/dist/utils/tap-assistant-context.js.map +0 -1
- package/dist/utils/tap-client-stack-context.d.ts +0 -23
- package/dist/utils/tap-client-stack-context.d.ts.map +0 -1
- package/dist/utils/tap-client-stack-context.js +0 -28
- package/dist/utils/tap-client-stack-context.js.map +0 -1
- package/dist/wrapperResource.d.ts +0 -3
- package/dist/wrapperResource.d.ts.map +0 -1
- package/dist/wrapperResource.js +0 -11
- package/dist/wrapperResource.js.map +0 -1
- package/src/Derived.ts +0 -46
- package/src/attachDefaultPeers.ts +0 -78
- package/src/tapClientList.ts +0 -118
- package/src/tapClientLookup.ts +0 -76
- package/src/tapClientResource.ts +0 -182
- package/src/types/client.ts +0 -186
- package/src/types/events.ts +0 -77
- package/src/utils/BaseProxyHandler.ts +0 -50
- package/src/utils/NotificationManager.ts +0 -114
- package/src/utils/proxied-assistant-state.tsx +0 -53
- package/src/utils/splitClients.ts +0 -130
- package/src/utils/tap-assistant-context.ts +0 -58
- package/src/utils/tap-client-stack-context.ts +0 -51
- package/src/wrapperResource.ts +0 -17
package/src/index.ts
CHANGED
|
@@ -1,37 +1,30 @@
|
|
|
1
|
-
//
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
export { useAuiEvent } from "./useAuiEvent";
|
|
5
|
-
|
|
6
|
-
// components
|
|
7
|
-
export { AuiIf } from "./AuiIf";
|
|
8
|
-
export { AuiProvider } from "./utils/react-assistant-context";
|
|
1
|
+
// Backwards-compatible ScopeRegistry augmentation target + forwarding to core
|
|
2
|
+
export type { ScopeRegistry } from "./scope-registry";
|
|
3
|
+
import "./scope-registry-forward";
|
|
9
4
|
|
|
10
|
-
//
|
|
11
|
-
export { Derived } from "./Derived";
|
|
12
|
-
export { attachDefaultPeers } from "./attachDefaultPeers";
|
|
13
|
-
|
|
14
|
-
// tap hooks
|
|
5
|
+
// Re-export framework-agnostic infrastructure from core
|
|
15
6
|
export {
|
|
7
|
+
Derived,
|
|
8
|
+
attachTransformScopes,
|
|
9
|
+
type ScopesConfig,
|
|
16
10
|
tapAssistantClientRef,
|
|
17
11
|
tapAssistantEmit,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
tapClientResource,
|
|
13
|
+
tapClientLookup,
|
|
14
|
+
tapClientList,
|
|
15
|
+
type ClientOutput,
|
|
16
|
+
type AssistantClient,
|
|
17
|
+
type AssistantState,
|
|
18
|
+
type AssistantEventName,
|
|
19
|
+
type AssistantEventCallback,
|
|
20
|
+
type AssistantEventPayload,
|
|
21
|
+
type AssistantEventSelector,
|
|
22
|
+
type AssistantEventScope,
|
|
23
|
+
} from "@assistant-ui/core/store";
|
|
22
24
|
|
|
23
|
-
//
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
} from "./types/client";
|
|
30
|
-
export type {
|
|
31
|
-
AssistantEventName,
|
|
32
|
-
AssistantEventCallback,
|
|
33
|
-
AssistantEventPayload,
|
|
34
|
-
AssistantEventSelector,
|
|
35
|
-
AssistantEventScope,
|
|
36
|
-
} from "./types/events";
|
|
37
|
-
export type { DefaultPeers } from "./attachDefaultPeers";
|
|
25
|
+
// React-specific (stay in store)
|
|
26
|
+
export { useAui } from "./useAui";
|
|
27
|
+
export { useAuiState } from "./useAuiState";
|
|
28
|
+
export { useAuiEvent } from "./useAuiEvent";
|
|
29
|
+
export { AuiIf } from "./AuiIf";
|
|
30
|
+
export { AuiProvider } from "./utils/react-assistant-context";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module augmentation interface for assistant-ui store type extensions.
|
|
3
|
+
*
|
|
4
|
+
* Users augment this interface to register custom scopes:
|
|
5
|
+
* ```typescript
|
|
6
|
+
* declare module "@assistant-ui/store" {
|
|
7
|
+
* interface ScopeRegistry {
|
|
8
|
+
* myScope: { methods: { getState: () => MyState } };
|
|
9
|
+
* }
|
|
10
|
+
* }
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Augmentations are automatically forwarded to `@assistant-ui/core/store`.
|
|
14
|
+
*/
|
|
15
|
+
export interface ScopeRegistry {}
|
|
@@ -6,12 +6,11 @@ import {
|
|
|
6
6
|
tapMemo,
|
|
7
7
|
tapResources,
|
|
8
8
|
tapEffectEvent,
|
|
9
|
-
tapInlineResource,
|
|
10
9
|
tapEffect,
|
|
11
10
|
tapRef,
|
|
12
11
|
tapResource,
|
|
13
12
|
withKey,
|
|
14
|
-
|
|
13
|
+
tapResourceRoot,
|
|
15
14
|
} from "@assistant-ui/tap";
|
|
16
15
|
import type {
|
|
17
16
|
AssistantClient,
|
|
@@ -19,34 +18,34 @@ import type {
|
|
|
19
18
|
ClientNames,
|
|
20
19
|
ClientElement,
|
|
21
20
|
ClientMeta,
|
|
22
|
-
} from "
|
|
23
|
-
import { Derived, DerivedElement } from "./Derived";
|
|
24
|
-
import {
|
|
25
|
-
useAssistantContextValue,
|
|
26
|
-
DefaultAssistantClient,
|
|
27
|
-
createRootAssistantClient,
|
|
28
|
-
} from "./utils/react-assistant-context";
|
|
29
|
-
import {
|
|
30
|
-
DerivedClients,
|
|
31
|
-
RootClients,
|
|
32
|
-
tapSplitClients,
|
|
33
|
-
} from "./utils/splitClients";
|
|
21
|
+
} from "@assistant-ui/core/store";
|
|
34
22
|
import {
|
|
23
|
+
Derived,
|
|
24
|
+
type DerivedElement,
|
|
25
|
+
type ScopesConfig,
|
|
35
26
|
normalizeEventSelector,
|
|
36
27
|
type AssistantEventName,
|
|
37
28
|
type AssistantEventCallback,
|
|
38
29
|
type AssistantEventSelector,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
import { withAssistantTapContextProvider } from "./utils/tap-assistant-context";
|
|
42
|
-
import { tapClientResource } from "./tapClientResource";
|
|
43
|
-
import { getClientIndex } from "./utils/tap-client-stack-context";
|
|
30
|
+
tapClientResource,
|
|
31
|
+
} from "@assistant-ui/core/store";
|
|
44
32
|
import {
|
|
33
|
+
NotificationManager,
|
|
34
|
+
withAssistantTapContextProvider,
|
|
35
|
+
getClientIndex,
|
|
45
36
|
PROXIED_ASSISTANT_STATE_SYMBOL,
|
|
46
37
|
createProxiedAssistantState,
|
|
47
|
-
|
|
38
|
+
type RootClients,
|
|
39
|
+
type DerivedClients,
|
|
40
|
+
tapSplitClients,
|
|
41
|
+
} from "@assistant-ui/core/store/internal";
|
|
42
|
+
import {
|
|
43
|
+
useAssistantContextValue,
|
|
44
|
+
DefaultAssistantClient,
|
|
45
|
+
createRootAssistantClient,
|
|
46
|
+
} from "./utils/react-assistant-context";
|
|
48
47
|
|
|
49
|
-
const tapShallowMemoArray = <T
|
|
48
|
+
const tapShallowMemoArray = <T>(array: readonly T[]) => {
|
|
50
49
|
// biome-ignore lint/correctness/useExhaustiveDependencies: shallow memo
|
|
51
50
|
return tapMemo(() => array, array);
|
|
52
51
|
};
|
|
@@ -81,7 +80,7 @@ const RootClientAccessorResource = resource(
|
|
|
81
80
|
clientRef: { parent: AssistantClient; current: AssistantClient | null };
|
|
82
81
|
name: K;
|
|
83
82
|
}): AssistantClientAccessor<K> => {
|
|
84
|
-
const store =
|
|
83
|
+
const store = tapResourceRoot(
|
|
85
84
|
RootClientResource({ element, emit: notifications.emit, clientRef }),
|
|
86
85
|
);
|
|
87
86
|
|
|
@@ -129,7 +128,7 @@ const RootClientsAccessorsResource = resource(
|
|
|
129
128
|
clients: RootClients;
|
|
130
129
|
clientRef: { parent: AssistantClient; current: AssistantClient | null };
|
|
131
130
|
}) => {
|
|
132
|
-
const notifications =
|
|
131
|
+
const notifications = tapResource(NotificationManager());
|
|
133
132
|
|
|
134
133
|
tapEffect(
|
|
135
134
|
() => clientRef.parent.subscribe(notifications.notifySubscribers),
|
|
@@ -318,7 +317,7 @@ export const AssistantClientResource = resource(
|
|
|
318
317
|
: NoOpRootClientsAccessorsResource(),
|
|
319
318
|
);
|
|
320
319
|
|
|
321
|
-
const derivedFields =
|
|
320
|
+
const derivedFields = tapResource(
|
|
322
321
|
DerivedClientsAccessorsResource({ clients: derivedClients, clientRef }),
|
|
323
322
|
);
|
|
324
323
|
|
|
@@ -355,9 +354,7 @@ export const AssistantClientResource = resource(
|
|
|
355
354
|
);
|
|
356
355
|
|
|
357
356
|
export namespace useAui {
|
|
358
|
-
export type Props =
|
|
359
|
-
[K in ClientNames]?: ClientElement<K> | DerivedElement<K>;
|
|
360
|
-
};
|
|
357
|
+
export type Props = ScopesConfig;
|
|
361
358
|
}
|
|
362
359
|
|
|
363
360
|
export function useAui(): AssistantClient;
|
package/src/useAuiEvent.ts
CHANGED
|
@@ -5,8 +5,8 @@ import type {
|
|
|
5
5
|
AssistantEventName,
|
|
6
6
|
AssistantEventCallback,
|
|
7
7
|
AssistantEventSelector,
|
|
8
|
-
} from "
|
|
9
|
-
import { normalizeEventSelector } from "
|
|
8
|
+
} from "@assistant-ui/core/store";
|
|
9
|
+
import { normalizeEventSelector } from "@assistant-ui/core/store";
|
|
10
10
|
|
|
11
11
|
export const useAuiEvent = <TEvent extends AssistantEventName>(
|
|
12
12
|
selector: AssistantEventSelector<TEvent>,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useSyncExternalStore, useDebugValue } from "react";
|
|
2
|
-
import type { AssistantState } from "
|
|
2
|
+
import type { AssistantState } from "@assistant-ui/core/store";
|
|
3
|
+
import { getProxiedAssistantState } from "@assistant-ui/core/store/internal";
|
|
3
4
|
import { useAui } from "./useAui";
|
|
4
|
-
import { getProxiedAssistantState } from "./utils/proxied-assistant-state";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Hook to access a slice of the assistant state with automatic subscription
|
|
@@ -18,7 +18,7 @@ import { getProxiedAssistantState } from "./utils/proxied-assistant-state";
|
|
|
18
18
|
* const bar = useAuiState((state) => state.foo.bar);
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
|
-
export const useAuiState = <T
|
|
21
|
+
export const useAuiState = <T>(selector: (state: AssistantState) => T): T => {
|
|
22
22
|
const aui = useAui();
|
|
23
23
|
const proxiedState = getProxiedAssistantState(aui);
|
|
24
24
|
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import React, { createContext, useContext } from "react";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
AssistantClient,
|
|
4
|
+
AssistantClientAccessor,
|
|
5
|
+
} from "@assistant-ui/core/store";
|
|
3
6
|
import {
|
|
4
7
|
createProxiedAssistantState,
|
|
5
8
|
PROXIED_ASSISTANT_STATE_SYMBOL,
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
BaseProxyHandler,
|
|
10
|
+
handleIntrospectionProp,
|
|
11
|
+
} from "@assistant-ui/core/store/internal";
|
|
8
12
|
|
|
9
13
|
const NO_OP_SUBSCRIBE = () => () => {};
|
|
10
14
|
|
package/dist/Derived.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ResourceElement } from "@assistant-ui/tap";
|
|
2
|
-
import type { AssistantClient, ClientNames, AssistantClientAccessor, ClientMeta } from "./types/client.js";
|
|
3
|
-
/**
|
|
4
|
-
* Creates a derived client field that references a client from a parent scope.
|
|
5
|
-
* The get callback always calls the most recent version (useEffectEvent pattern).
|
|
6
|
-
*
|
|
7
|
-
* IMPORTANT: The `get` callback must return a client that was created via
|
|
8
|
-
* `tapClientResource` (or `tapClientLookup`/`tapClientList` which use it internally).
|
|
9
|
-
* This is required for event scoping to work correctly.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* const aui = useAui({
|
|
14
|
-
* message: Derived({
|
|
15
|
-
* source: "thread",
|
|
16
|
-
* query: { index: 0 },
|
|
17
|
-
* get: (aui) => aui.thread().message({ index: 0 }),
|
|
18
|
-
* }),
|
|
19
|
-
* });
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare const Derived: <K extends ClientNames>(props: Derived.Props<K>) => ResourceElement<null, Derived.Props<K>>;
|
|
23
|
-
export type DerivedElement<K extends ClientNames> = ResourceElement<null, Derived.Props<K>>;
|
|
24
|
-
export declare namespace Derived {
|
|
25
|
-
/**
|
|
26
|
-
* Props passed to a derived client resource element.
|
|
27
|
-
*/
|
|
28
|
-
type Props<K extends ClientNames> = {
|
|
29
|
-
get: (client: AssistantClient) => ReturnType<AssistantClientAccessor<K>>;
|
|
30
|
-
} & (ClientMeta<K> | {
|
|
31
|
-
getMeta: (client: AssistantClient) => ClientMeta<K>;
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=Derived.d.ts.map
|
package/dist/Derived.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Derived.d.ts","sourceRoot":"","sources":["../src/Derived.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,uBAAuB,EACvB,UAAU,EACX,0BAAuB;AAExB;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,OAAO,GACjB,CAAC,SAAS,WAAW,qEAGvB,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,WAAW,IAAI,eAAe,CACjE,IAAI,EACJ,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CACjB,CAAC;AAEF,yBAAiB,OAAO,CAAC;IACvB;;OAEG;IACH,KAAY,KAAK,CAAC,CAAC,SAAS,WAAW,IAAI;QACzC,GAAG,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,UAAU,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC;KAC1E,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,UAAU,CAAC,CAAC,CAAC,CAAA;KAAE,CAAC,CAAC;CAC/E"}
|
package/dist/Derived.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { resource } from "@assistant-ui/tap";
|
|
2
|
-
/**
|
|
3
|
-
* Creates a derived client field that references a client from a parent scope.
|
|
4
|
-
* The get callback always calls the most recent version (useEffectEvent pattern).
|
|
5
|
-
*
|
|
6
|
-
* IMPORTANT: The `get` callback must return a client that was created via
|
|
7
|
-
* `tapClientResource` (or `tapClientLookup`/`tapClientList` which use it internally).
|
|
8
|
-
* This is required for event scoping to work correctly.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* const aui = useAui({
|
|
13
|
-
* message: Derived({
|
|
14
|
-
* source: "thread",
|
|
15
|
-
* query: { index: 0 },
|
|
16
|
-
* get: (aui) => aui.thread().message({ index: 0 }),
|
|
17
|
-
* }),
|
|
18
|
-
* });
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export const Derived = resource((_config) => {
|
|
22
|
-
return null;
|
|
23
|
-
});
|
|
24
|
-
//# sourceMappingURL=Derived.js.map
|
package/dist/Derived.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Derived.js","sourceRoot":"","sources":["../src/Derived.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAmB,MAAM,mBAAmB,CAAC;AAQ9D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAC7B,CAAwB,OAAyB,EAAQ,EAAE;IACzD,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { ResourceElement } from "@assistant-ui/tap";
|
|
2
|
-
import type { ClientElement, ClientNames } from "./types/client.js";
|
|
3
|
-
import type { DerivedElement } from "./Derived.js";
|
|
4
|
-
/**
|
|
5
|
-
* Symbol used to store default peer clients on a resource.
|
|
6
|
-
*/
|
|
7
|
-
declare const DEFAULT_PEERS: unique symbol;
|
|
8
|
-
/**
|
|
9
|
-
* Type for resources that have default peers attached.
|
|
10
|
-
*/
|
|
11
|
-
export type ResourceWithDefaultPeers = {
|
|
12
|
-
[DEFAULT_PEERS]?: DefaultPeers;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Default peers configuration - can be either root clients or derived clients.
|
|
16
|
-
*/
|
|
17
|
-
export type DefaultPeers = {
|
|
18
|
-
[K in ClientNames]?: ClientElement<K> | DerivedElement<K>;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Attaches default peer clients to a resource.
|
|
22
|
-
*
|
|
23
|
-
* Default peers are only applied if the scope doesn't exist:
|
|
24
|
-
* - Not defined in parent context
|
|
25
|
-
* - Not provided by user
|
|
26
|
-
* - Not already defined by a previous resource's default peers
|
|
27
|
-
*
|
|
28
|
-
* First definition wins - no overriding is permitted.
|
|
29
|
-
*
|
|
30
|
-
* @param resource - The resource to attach default peers to
|
|
31
|
-
* @param peers - The default peer clients to attach
|
|
32
|
-
* @throws Error if a peer key already exists in the resource's default peers
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* const ThreadListClient = resource(({ ... }) => { ... });
|
|
37
|
-
*
|
|
38
|
-
* attachDefaultPeers(ThreadListClient, {
|
|
39
|
-
* // Derived default peers
|
|
40
|
-
* thread: Derived({ source: "threads", query: { type: "main" }, get: ... }),
|
|
41
|
-
* threadListItem: Derived({ ... }),
|
|
42
|
-
* composer: Derived({ getMeta: ..., get: ... }),
|
|
43
|
-
*
|
|
44
|
-
* // Root default peers
|
|
45
|
-
* tools: Tools({}),
|
|
46
|
-
* modelContext: ModelContext({}),
|
|
47
|
-
* });
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
export declare function attachDefaultPeers<T extends (...args: any[]) => ResourceElement<any>>(resource: T, peers: DefaultPeers): void;
|
|
51
|
-
/**
|
|
52
|
-
* Gets the default peers attached to a resource, if any.
|
|
53
|
-
*/
|
|
54
|
-
export declare function getDefaultPeers<T extends (...args: any[]) => ResourceElement<any>>(resource: T): DefaultPeers | undefined;
|
|
55
|
-
export {};
|
|
56
|
-
//# sourceMappingURL=attachDefaultPeers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attachDefaultPeers.d.ts","sourceRoot":"","sources":["../src/attachDefaultPeers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,0BAAuB;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAkB;AAEhD;;GAEG;AACH,QAAA,MAAM,aAAa,eAAuC,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,CAAC,aAAa,CAAC,CAAC,EAAE,YAAY,CAAC;CAChC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;KACxB,CAAC,IAAI,WAAW,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC;CAC1D,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,kBAAkB,CAChC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,eAAe,CAAC,GAAG,CAAC,EAClD,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI,CAaxC;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,eAAe,CAAC,GAAG,CAAC,EAClD,QAAQ,EAAE,CAAC,GAAG,YAAY,GAAG,SAAS,CAEvC"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Symbol used to store default peer clients on a resource.
|
|
3
|
-
*/
|
|
4
|
-
const DEFAULT_PEERS = Symbol("assistant-ui.default-peers");
|
|
5
|
-
/**
|
|
6
|
-
* Attaches default peer clients to a resource.
|
|
7
|
-
*
|
|
8
|
-
* Default peers are only applied if the scope doesn't exist:
|
|
9
|
-
* - Not defined in parent context
|
|
10
|
-
* - Not provided by user
|
|
11
|
-
* - Not already defined by a previous resource's default peers
|
|
12
|
-
*
|
|
13
|
-
* First definition wins - no overriding is permitted.
|
|
14
|
-
*
|
|
15
|
-
* @param resource - The resource to attach default peers to
|
|
16
|
-
* @param peers - The default peer clients to attach
|
|
17
|
-
* @throws Error if a peer key already exists in the resource's default peers
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* const ThreadListClient = resource(({ ... }) => { ... });
|
|
22
|
-
*
|
|
23
|
-
* attachDefaultPeers(ThreadListClient, {
|
|
24
|
-
* // Derived default peers
|
|
25
|
-
* thread: Derived({ source: "threads", query: { type: "main" }, get: ... }),
|
|
26
|
-
* threadListItem: Derived({ ... }),
|
|
27
|
-
* composer: Derived({ getMeta: ..., get: ... }),
|
|
28
|
-
*
|
|
29
|
-
* // Root default peers
|
|
30
|
-
* tools: Tools({}),
|
|
31
|
-
* modelContext: ModelContext({}),
|
|
32
|
-
* });
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export function attachDefaultPeers(resource, peers) {
|
|
36
|
-
const resourceWithPeers = resource;
|
|
37
|
-
const existing = resourceWithPeers[DEFAULT_PEERS] ?? {};
|
|
38
|
-
for (const key of Object.keys(peers)) {
|
|
39
|
-
if (key in existing) {
|
|
40
|
-
throw new Error(`Default peer "${key}" is already attached to this resource`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
resourceWithPeers[DEFAULT_PEERS] = { ...existing, ...peers };
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Gets the default peers attached to a resource, if any.
|
|
47
|
-
*/
|
|
48
|
-
export function getDefaultPeers(resource) {
|
|
49
|
-
return resource[DEFAULT_PEERS];
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=attachDefaultPeers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attachDefaultPeers.js","sourceRoot":"","sources":["../src/attachDefaultPeers.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,aAAa,GAAG,MAAM,CAAC,4BAA4B,CAAC,CAAC;AAgB3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,kBAAkB,CAEhC,QAAW,EAAE,KAAmB;IAChC,MAAM,iBAAiB,GAAG,QAAwC,CAAC;IACnE,MAAM,QAAQ,GAAG,iBAAiB,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;IAExD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,IAAI,GAAG,IAAI,QAAQ,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CACb,iBAAiB,GAAG,wCAAwC,CAC7D,CAAC;QACJ,CAAC;IACH,CAAC;IAED,iBAAiB,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,KAAK,EAAE,CAAC;AAC/D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAE7B,QAAW;IACX,OAAQ,QAAyC,CAAC,aAAa,CAAC,CAAC;AACnE,CAAC"}
|
package/dist/tapClientList.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { ContravariantResource } from "@assistant-ui/tap";
|
|
2
|
-
import type { ClientMethods, ClientOutputOf } from "./types/client.js";
|
|
3
|
-
export declare const tapClientList: <TData, TState, TMethods extends ClientMethods>(props: tapClientList.Props<TData, TState, TMethods>) => {
|
|
4
|
-
state: TState[];
|
|
5
|
-
get: (lookup: {
|
|
6
|
-
index: number;
|
|
7
|
-
} | {
|
|
8
|
-
key: string;
|
|
9
|
-
}) => TMethods;
|
|
10
|
-
add: (initialData: TData) => void;
|
|
11
|
-
};
|
|
12
|
-
export declare namespace tapClientList {
|
|
13
|
-
type ResourceProps<TData> = {
|
|
14
|
-
key: string;
|
|
15
|
-
getInitialData: () => TData;
|
|
16
|
-
remove: () => void;
|
|
17
|
-
};
|
|
18
|
-
type Props<TData, TState, TMethods extends ClientMethods> = {
|
|
19
|
-
initialValues: TData[];
|
|
20
|
-
getKey: (data: TData) => string;
|
|
21
|
-
resource: ContravariantResource<ClientOutputOf<TState, TMethods>, ResourceProps<TData>>;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=tapClientList.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tapClientList.d.ts","sourceRoot":"","sources":["../src/tapClientList.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE/D,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,0BAAuB;AAuBpE,eAAO,MAAM,aAAa,GAAI,KAAK,EAAE,MAAM,EAAE,QAAQ,SAAS,aAAa,EACzE,OAAO,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,KAClD;IACD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,QAAQ,CAAC;IAC/D,GAAG,EAAE,CAAC,WAAW,EAAE,KAAK,KAAK,IAAI,CAAC;CAqEnC,CAAC;AAEF,yBAAiB,aAAa,CAAC;IAC7B,KAAY,aAAa,CAAC,KAAK,IAAI;QACjC,GAAG,EAAE,MAAM,CAAC;QACZ,cAAc,EAAE,MAAM,KAAK,CAAC;QAC5B,MAAM,EAAE,MAAM,IAAI,CAAC;KACpB,CAAC;IAEF,KAAY,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,SAAS,aAAa,IAAI;QACjE,aAAa,EAAE,KAAK,EAAE,CAAC;QACvB,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,MAAM,CAAC;QAChC,QAAQ,EAAE,qBAAqB,CAC7B,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,EAChC,aAAa,CAAC,KAAK,CAAC,CACrB,CAAC;KACH,CAAC;CACH"}
|
package/dist/tapClientList.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { tapConst, tapState, withKey } from "@assistant-ui/tap";
|
|
2
|
-
import { tapClientLookup } from "./tapClientLookup.js";
|
|
3
|
-
const createProps = (key, data, remove) => {
|
|
4
|
-
return {
|
|
5
|
-
key,
|
|
6
|
-
getInitialData: () => {
|
|
7
|
-
if (!data.hasData) {
|
|
8
|
-
throw new Error("getInitialData may only be called during initial render");
|
|
9
|
-
}
|
|
10
|
-
return data.data;
|
|
11
|
-
},
|
|
12
|
-
remove,
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export const tapClientList = (props) => {
|
|
16
|
-
const { initialValues, getKey, resource: Resource } = props;
|
|
17
|
-
const initialDataHandles = tapConst(() => [], []);
|
|
18
|
-
const [items, setItems] = tapState(() => {
|
|
19
|
-
const entries = [];
|
|
20
|
-
for (const data of initialValues) {
|
|
21
|
-
const key = getKey(data);
|
|
22
|
-
const handle = { data, hasData: true };
|
|
23
|
-
entries.push([
|
|
24
|
-
key,
|
|
25
|
-
createProps(key, handle, () => {
|
|
26
|
-
setItems((items) => {
|
|
27
|
-
const newItems = { ...items };
|
|
28
|
-
delete newItems[key];
|
|
29
|
-
return newItems;
|
|
30
|
-
});
|
|
31
|
-
}),
|
|
32
|
-
]);
|
|
33
|
-
initialDataHandles.push(handle);
|
|
34
|
-
}
|
|
35
|
-
return Object.fromEntries(entries);
|
|
36
|
-
});
|
|
37
|
-
const lookup = tapClientLookup(() => Object.values(items).map((props) => withKey(props.key, Resource(props))), [items, Resource]);
|
|
38
|
-
initialDataHandles.forEach((handle) => {
|
|
39
|
-
handle.data = undefined;
|
|
40
|
-
handle.hasData = false;
|
|
41
|
-
});
|
|
42
|
-
const add = (data) => {
|
|
43
|
-
const key = getKey(data);
|
|
44
|
-
setItems((items) => {
|
|
45
|
-
if (key in items) {
|
|
46
|
-
throw new Error(`Tried to add item with a key ${key} that already exists`);
|
|
47
|
-
}
|
|
48
|
-
const handle = { data, hasData: true };
|
|
49
|
-
initialDataHandles.push(handle);
|
|
50
|
-
return {
|
|
51
|
-
...items,
|
|
52
|
-
[key]: createProps(key, handle, () => {
|
|
53
|
-
setItems((items) => {
|
|
54
|
-
const newItems = { ...items };
|
|
55
|
-
delete newItems[key];
|
|
56
|
-
return newItems;
|
|
57
|
-
});
|
|
58
|
-
}),
|
|
59
|
-
};
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
return {
|
|
63
|
-
state: lookup.state,
|
|
64
|
-
get: lookup.get,
|
|
65
|
-
add,
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
//# sourceMappingURL=tapClientList.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tapClientList.js","sourceRoot":"","sources":["../src/tapClientList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EAAE,eAAe,EAAE,6BAA0B;AAKpD,MAAM,WAAW,GAAG,CAClB,GAAW,EACX,IAAuB,EACvB,MAAkB,EACkB,EAAE;IACtC,OAAO;QACL,GAAG;QACH,cAAc,EAAE,GAAG,EAAE;YACnB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBAClB,MAAM,IAAI,KAAK,CACb,yDAAyD,CAC1D,CAAC;YACJ,CAAC;YACD,OAAO,IAAI,CAAC,IAAK,CAAC;QACpB,CAAC;QACD,MAAM;KACP,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|
-
export declare function tapClientLookup<TState, TMethods extends ClientMethods>(getElements: () => readonly ResourceElement<ClientOutputOf<TState, TMethods>>[], getElementsDeps: readonly unknown[]): {
|
|
4
|
-
state: TState[];
|
|
5
|
-
get: (lookup: {
|
|
6
|
-
index: number;
|
|
7
|
-
} | {
|
|
8
|
-
key: string;
|
|
9
|
-
}) => TMethods;
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=tapClientLookup.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tapClientLookup.d.ts","sourceRoot":"","sources":["../src/tapClientLookup.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,0BAAuB;AAkBpE,wBAAgB,eAAe,CAAC,MAAM,EAAE,QAAQ,SAAS,aAAa,EACpE,WAAW,EAAE,MAAM,SAAS,eAAe,CACzC,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,CACjC,EAAE,EACH,eAAe,EAAE,SAAS,OAAO,EAAE,GAClC;IACD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,QAAQ,CAAC;CAChE,CA2CA"}
|
package/dist/tapClientLookup.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { tapInlineResource, tapMemo, tapResources, } from "@assistant-ui/tap";
|
|
2
|
-
import { ClientResource } from "./tapClientResource.js";
|
|
3
|
-
import { wrapperResource } from "./wrapperResource.js";
|
|
4
|
-
const ClientResourceWithKey = wrapperResource((el) => {
|
|
5
|
-
if (el.key === undefined) {
|
|
6
|
-
throw new Error("tapClientResource: Element has no key");
|
|
7
|
-
}
|
|
8
|
-
return tapInlineResource(ClientResource(el));
|
|
9
|
-
});
|
|
10
|
-
export function tapClientLookup(getElements, getElementsDeps) {
|
|
11
|
-
const resources = tapResources(() => getElements().map((el) => ClientResourceWithKey(el)),
|
|
12
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: getElementsDeps is passed through from caller
|
|
13
|
-
getElementsDeps);
|
|
14
|
-
const keys = tapMemo(() => Object.keys(resources), [resources]);
|
|
15
|
-
// For arrays, track element key -> index mapping
|
|
16
|
-
const keyToIndex = tapMemo(() => {
|
|
17
|
-
return resources.reduce((acc, resource, index) => {
|
|
18
|
-
acc[resource.key] = index;
|
|
19
|
-
return acc;
|
|
20
|
-
}, {});
|
|
21
|
-
}, [resources]);
|
|
22
|
-
const state = tapMemo(() => {
|
|
23
|
-
return resources.map((r) => r.state);
|
|
24
|
-
}, [resources]);
|
|
25
|
-
return {
|
|
26
|
-
state,
|
|
27
|
-
get: (lookup) => {
|
|
28
|
-
if ("index" in lookup) {
|
|
29
|
-
if (lookup.index < 0 || lookup.index >= keys.length) {
|
|
30
|
-
throw new Error(`tapClientLookup: Index ${lookup.index} out of bounds (length: ${keys.length})`);
|
|
31
|
-
}
|
|
32
|
-
return resources[lookup.index].methods;
|
|
33
|
-
}
|
|
34
|
-
const index = keyToIndex[lookup.key];
|
|
35
|
-
if (index === undefined) {
|
|
36
|
-
throw new Error(`tapClientLookup: Key "${lookup.key}" not found`);
|
|
37
|
-
}
|
|
38
|
-
return resources[index].methods;
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=tapClientLookup.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tapClientLookup.js","sourceRoot":"","sources":["../src/tapClientLookup.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,OAAO,EACP,YAAY,GAEb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,cAAc,EAAE,+BAA4B;AACrD,OAAO,EAAE,eAAe,EAAE,6BAA0B;AAEpD,MAAM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AAE,CAAC;gBACtB,IAAI,MAAM,CAAC,KAAK,GAAG,CAAC,IAAI,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;oBACpD,MAAM,IAAI,KAAK,CACb,0BAA0B,MAAM,CAAC,KAAK,2BAA2B,IAAI,CAAC,MAAM,GAAG,CAChF,CAAC;gBACJ,CAAC;gBACD,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,CAAE,CAAC,OAAO,CAAC;YAC1C,CAAC;YAED,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACrC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,yBAAyB,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC;YACpE,CAAC;YACD,OAAO,SAAS,CAAC,KAAK,CAAE,CAAC,OAAO,CAAC;QACnC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type ResourceElement } from "@assistant-ui/tap";
|
|
2
|
-
import type { ClientMethods, ClientOutputOf } from "./types/client.js";
|
|
3
|
-
export declare const getClientState: (client: ClientMethods) => unknown;
|
|
4
|
-
/**
|
|
5
|
-
* Resource that wraps a plain resource element to create a stable client proxy.
|
|
6
|
-
*
|
|
7
|
-
* Takes a ResourceElement that returns { state, methods } and
|
|
8
|
-
* wraps it to produce a stable client proxy. This adds the client to the
|
|
9
|
-
* client stack, enabling event scoping.
|
|
10
|
-
*
|
|
11
|
-
* Use this for 1:1 client mappings where you want event scoping to work correctly.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* const MessageResource = resource(({ messageId }: { messageId: string }) => {
|
|
16
|
-
* return tapInlineResource(
|
|
17
|
-
* tapClientResource(InnerMessageResource({ messageId }))
|
|
18
|
-
* );
|
|
19
|
-
* });
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare const ClientResource: <TState, TMethods extends ClientMethods>(props: ResourceElement<ClientOutputOf<TState, TMethods>>) => ResourceElement<ClientOutputOf<TState, TMethods> & {
|
|
23
|
-
key: string | number | undefined;
|
|
24
|
-
}, ResourceElement<ClientOutputOf<TState, TMethods>>>;
|
|
25
|
-
export declare const tapClientResource: <TState, TMethods extends ClientMethods>(element: ResourceElement<ClientOutputOf<TState, TMethods>>) => ClientOutputOf<TState, TMethods> & {
|
|
26
|
-
key: string | number | undefined;
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=tapClientResource.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tapClientResource.d.ts","sourceRoot":"","sources":["../src/tapClientResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EAGrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,0BAAuB;AAsBpE,eAAO,MAAM,cAAc,GAAI,QAAQ,aAAa,YASnD,CAAC;AAuFF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,cAAc,GACxB,MAAM,EAAE,QAAQ,SAAS,aAAa;SAGhC,MAAM,GAAG,MAAM,GAAG,SAAS;qDA2BnC,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,MAAM,EAAE,QAAQ,SAAS,aAAa,EACtE,SAAS,eAAe,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;SA9BnD,MAAM,GAAG,MAAM,GAAG,SAAS;CAiCnC,CAAC"}
|