@sanity/sdk 3.0.0-rc.1 → 3.0.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 +12 -0
- package/dist/_exports/_internal.d.ts +71 -3
- package/dist/_exports/_internal.d.ts.map +1 -1
- package/dist/_exports/_internal.js +332 -24
- package/dist/_exports/_internal.js.map +1 -1
- package/dist/_exports/agent.d.ts +65 -0
- package/dist/_exports/agent.d.ts.map +1 -0
- package/dist/_exports/agent.js +71 -0
- package/dist/_exports/agent.js.map +1 -0
- package/dist/_exports/comlink.d.ts +118 -0
- package/dist/_exports/comlink.d.ts.map +1 -0
- package/dist/_exports/comlink.js +69 -0
- package/dist/_exports/comlink.js.map +1 -0
- package/dist/authStore-C0o1NOxW.d.ts +3165 -0
- package/dist/authStore-C0o1NOxW.d.ts.map +1 -0
- package/dist/authStore-CtE9bLHW.js +754 -0
- package/dist/authStore-CtE9bLHW.js.map +1 -0
- package/dist/clientStore-BtE2-q2i.js +90 -0
- package/dist/clientStore-BtE2-q2i.js.map +1 -0
- package/dist/createSanityInstance-DUI1bGIg.d.ts +278 -0
- package/dist/createSanityInstance-DUI1bGIg.d.ts.map +1 -0
- package/dist/createStateSourceAction-BOKtqFNm.js +300 -0
- package/dist/createStateSourceAction-BOKtqFNm.js.map +1 -0
- package/dist/getEnv-D5RGkQLu.js +8 -0
- package/dist/getEnv-D5RGkQLu.js.map +1 -0
- package/dist/getNodeState-CR3__B2D.js +67 -0
- package/dist/getNodeState-CR3__B2D.js.map +1 -0
- package/dist/index.d.ts +3 -2335
- package/dist/index.js +4048 -3878
- package/dist/index.js.map +1 -1
- package/dist/logger-DAtJb5RQ.js +173 -0
- package/dist/logger-DAtJb5RQ.js.map +1 -0
- package/dist/object-CxXlSVg7.js +83 -0
- package/dist/object-CxXlSVg7.js.map +1 -0
- package/dist/queryStore-C7yMHPUI.js +1346 -0
- package/dist/queryStore-C7yMHPUI.js.map +1 -0
- package/dist/rolldown-runtime-vyAXikos.js +9 -0
- package/dist/setCleanupTimeout-BiM6q1KF.js +31 -0
- package/dist/setCleanupTimeout-BiM6q1KF.js.map +1 -0
- package/dist/telemetryManager-UIEiMtC0.js +127 -0
- package/dist/telemetryManager-UIEiMtC0.js.map +1 -0
- package/dist/version-D8RP_Q59.js +9 -0
- package/dist/version-D8RP_Q59.js.map +1 -0
- package/package.json +11 -17
- package/src/_exports/_internal.ts +1 -0
- package/src/_exports/agent.ts +19 -0
- package/src/_exports/comlink.ts +16 -0
- package/src/_exports/index.ts +45 -90
- package/src/applications/applications.test-d.ts +5 -0
- package/src/applications/applications.ts +5 -2
- package/src/auth/authMode.test.ts +0 -25
- package/src/auth/authMode.ts +3 -6
- package/src/auth/authStore.test.ts +1 -1
- package/src/auth/authStore.ts +0 -1
- package/src/comments/addonDatasetStore.test.ts +215 -0
- package/src/comments/addonDatasetStore.ts +249 -0
- package/src/comments/buildCommentThreads.test.ts +83 -0
- package/src/comments/buildCommentThreads.ts +54 -0
- package/src/comments/commentActions.test.ts +540 -0
- package/src/comments/commentActions.ts +555 -0
- package/src/comments/commentFieldPath.test.ts +40 -0
- package/src/comments/commentFieldPath.ts +44 -0
- package/src/comments/commentsConstants.ts +80 -0
- package/src/comments/commentsStore.test.ts +419 -0
- package/src/comments/commentsStore.ts +483 -0
- package/src/comments/normalizeComment.test.ts +116 -0
- package/src/comments/normalizeComment.ts +45 -0
- package/src/comments/observeComments.test.ts +193 -0
- package/src/comments/observeComments.ts +113 -0
- package/src/comments/reducers.test.ts +277 -0
- package/src/comments/reducers.ts +316 -0
- package/src/comments/types.ts +249 -0
- package/src/comments/weakenReferences.test.ts +47 -0
- package/src/comments/weakenReferences.ts +29 -0
- package/src/config/sanityConfig.ts +3 -75
- package/src/datasets/datasets.test.ts +44 -9
- package/src/datasets/datasets.ts +24 -23
- package/src/document/applyDocumentActions.test.ts +8 -12
- package/src/document/documentConstants.ts +17 -0
- package/src/document/documentStore.test.ts +173 -19
- package/src/document/documentStore.ts +36 -5
- package/src/document/patchOperations.test.ts +27 -0
- package/src/document/patchOperations.ts +10 -1
- package/src/document/permissions.test.ts +3 -1
- package/src/document/reducers.test.ts +357 -0
- package/src/document/reducers.ts +125 -27
- package/src/document/util.test.ts +46 -0
- package/src/document/util.ts +37 -1
- package/src/favorites/favorites.test.ts +64 -24
- package/src/favorites/favorites.ts +73 -22
- package/src/installations/installations.test-d.ts +5 -0
- package/src/installations/installations.ts +4 -0
- package/src/presence/bifurTransport.test.ts +155 -3
- package/src/presence/bifurTransport.ts +79 -12
- package/src/presence/paths.test.ts +70 -0
- package/src/presence/paths.ts +41 -0
- package/src/presence/presenceStore.test.ts +822 -2
- package/src/presence/presenceStore.ts +518 -102
- package/src/presence/types.ts +175 -3
- package/src/preview/types.ts +0 -25
- package/src/projection/projectionStore.test.ts +0 -8
- package/src/projection/types.ts +0 -8
- package/src/query/queryStore.ts +7 -6
- package/src/store/createActionBinder.test.ts +51 -29
- package/src/store/createActionBinder.ts +16 -62
- package/src/store/createSanityInstance.test.ts +0 -68
- package/src/store/createSanityInstance.ts +0 -63
- package/src/store/createStateSourceAction.ts +1 -1
- package/src/store/fetcherStore.test.ts +23 -1
- package/src/store/fetcherStore.ts +3 -3
- package/src/users/reducers.test.ts +0 -3
- package/dist/_chunks-dts/createGroqSearchFilter.d.ts +0 -1147
- package/dist/_chunks-dts/createGroqSearchFilter.d.ts.map +0 -1
- package/dist/_chunks-es/_internal.js +0 -134
- package/dist/_chunks-es/_internal.js.map +0 -1
- package/dist/_chunks-es/createGroqSearchFilter.js +0 -1864
- package/dist/_chunks-es/createGroqSearchFilter.js.map +0 -1
- package/dist/_chunks-es/telemetryManager.js +0 -93
- package/dist/_chunks-es/telemetryManager.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/src/applications/userApplications.test.ts +0 -126
- package/src/applications/userApplications.ts +0 -261
- package/src/preview/getPreviewState.test.ts +0 -137
- package/src/preview/getPreviewState.ts +0 -69
- package/src/preview/resolvePreview.test.ts +0 -64
- package/src/preview/resolvePreview.ts +0 -43
- package/src/utils/createFetcherStore.test.ts +0 -171
- package/src/utils/createFetcherStore.ts +0 -284
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { r as getClientState } from "../clientStore-BtE2-q2i.js";
|
|
2
|
+
import "@sanity/client";
|
|
3
|
+
import { from, switchMap } from "rxjs";
|
|
4
|
+
/**
|
|
5
|
+
* Generates a new document using the agent.
|
|
6
|
+
* @param instance - The Sanity instance.
|
|
7
|
+
* @param options - The options for the agent generate action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
|
|
8
|
+
* @returns An Observable emitting the result of the agent generate action.
|
|
9
|
+
* @alpha
|
|
10
|
+
*/
|
|
11
|
+
function agentGenerate(instance, options, resource) {
|
|
12
|
+
return getClientState(instance, {
|
|
13
|
+
apiVersion: "vX",
|
|
14
|
+
resource
|
|
15
|
+
}).observable.pipe(switchMap((client) => client.observable.agent.action.generate(options)));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Transforms a document using the agent.
|
|
19
|
+
* @param instance - The Sanity instance.
|
|
20
|
+
* @param options - The options for the agent transform action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
|
|
21
|
+
* @returns An Observable emitting the result of the agent transform action.
|
|
22
|
+
* @alpha
|
|
23
|
+
*/
|
|
24
|
+
function agentTransform(instance, options, resource) {
|
|
25
|
+
return getClientState(instance, {
|
|
26
|
+
apiVersion: "vX",
|
|
27
|
+
resource
|
|
28
|
+
}).observable.pipe(switchMap((client) => client.observable.agent.action.transform(options)));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Translates a document using the agent.
|
|
32
|
+
* @param instance - The Sanity instance.
|
|
33
|
+
* @param options - The options for the agent translate action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
|
|
34
|
+
* @returns An Observable emitting the result of the agent translate action.
|
|
35
|
+
* @alpha
|
|
36
|
+
*/
|
|
37
|
+
function agentTranslate(instance, options, resource) {
|
|
38
|
+
return getClientState(instance, {
|
|
39
|
+
apiVersion: "vX",
|
|
40
|
+
resource
|
|
41
|
+
}).observable.pipe(switchMap((client) => client.observable.agent.action.translate(options)));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Prompts the agent using the same instruction template format as the other actions, but returns text or json instead of acting on a document.
|
|
45
|
+
* @param instance - The Sanity instance.
|
|
46
|
+
* @param options - The options for the agent prompt action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
|
|
47
|
+
* @returns An Observable emitting the result of the agent prompt action.
|
|
48
|
+
* @alpha
|
|
49
|
+
*/
|
|
50
|
+
function agentPrompt(instance, options, resource) {
|
|
51
|
+
return getClientState(instance, {
|
|
52
|
+
apiVersion: "vX",
|
|
53
|
+
resource
|
|
54
|
+
}).observable.pipe(switchMap((client) => from(client.agent.action.prompt(options))));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Patches a document using the agent.
|
|
58
|
+
* @param instance - The Sanity instance.
|
|
59
|
+
* @param options - The options for the agent patch action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.
|
|
60
|
+
* @returns An Observable emitting the result of the agent patch action.
|
|
61
|
+
* @alpha
|
|
62
|
+
*/
|
|
63
|
+
function agentPatch(instance, options, resource) {
|
|
64
|
+
return getClientState(instance, {
|
|
65
|
+
apiVersion: "vX",
|
|
66
|
+
resource
|
|
67
|
+
}).observable.pipe(switchMap((client) => from(client.agent.action.patch(options))));
|
|
68
|
+
}
|
|
69
|
+
export { agentGenerate, agentPatch, agentPrompt, agentTransform, agentTranslate };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","names":[],"sources":["../../src/agent/agentActions.ts"],"sourcesContent":["import {type SanityClient} from '@sanity/client'\nimport {from, Observable, switchMap} from 'rxjs'\n\nimport {getClientState} from '../client/clientStore'\nimport {type DocumentResource} from '../config/sanityConfig'\nimport {type SanityInstance} from '../store/createSanityInstance'\n\nconst API_VERSION = 'vX'\n\n/** @alpha */\nexport type AgentGenerateOptions = Parameters<\n SanityClient['observable']['agent']['action']['generate']\n>[0]\n\n/** @alpha */\nexport type AgentTransformOptions = Parameters<\n SanityClient['observable']['agent']['action']['transform']\n>[0]\n\n/** @alpha */\nexport type AgentTranslateOptions = Parameters<\n SanityClient['observable']['agent']['action']['translate']\n>[0]\n\n/** @alpha */\nexport type AgentPromptOptions = Parameters<SanityClient['agent']['action']['prompt']>[0]\n\n/** @alpha */\nexport type AgentPatchOptions = Parameters<SanityClient['agent']['action']['patch']>[0]\n\n/** @alpha */\nexport type AgentGenerateResult = Awaited<\n ReturnType<SanityClient['observable']['agent']['action']['generate']>\n>\n\n/** @alpha */\nexport type AgentTransformResult = Awaited<\n ReturnType<SanityClient['observable']['agent']['action']['transform']>\n>\n\n/** @alpha */\nexport type AgentTranslateResult = Awaited<\n ReturnType<SanityClient['observable']['agent']['action']['translate']>\n>\n\n/** @alpha */\nexport type AgentPromptResult = Awaited<ReturnType<SanityClient['agent']['action']['prompt']>>\n\n/** @alpha */\nexport type AgentPatchResult = Awaited<ReturnType<SanityClient['agent']['action']['patch']>>\n\n/**\n * Generates a new document using the agent.\n * @param instance - The Sanity instance.\n * @param options - The options for the agent generate action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.\n * @returns An Observable emitting the result of the agent generate action.\n * @alpha\n */\nexport function agentGenerate(\n instance: SanityInstance,\n options: AgentGenerateOptions,\n resource?: DocumentResource,\n): AgentGenerateResult {\n return getClientState(instance, {apiVersion: API_VERSION, resource}).observable.pipe(\n switchMap((client) => client.observable.agent.action.generate(options)),\n )\n}\n\n/**\n * Transforms a document using the agent.\n * @param instance - The Sanity instance.\n * @param options - The options for the agent transform action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.\n * @returns An Observable emitting the result of the agent transform action.\n * @alpha\n */\nexport function agentTransform(\n instance: SanityInstance,\n options: AgentTransformOptions,\n resource?: DocumentResource,\n): AgentTransformResult {\n return getClientState(instance, {apiVersion: API_VERSION, resource}).observable.pipe(\n switchMap((client) => client.observable.agent.action.transform(options)),\n )\n}\n\n/**\n * Translates a document using the agent.\n * @param instance - The Sanity instance.\n * @param options - The options for the agent translate action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.\n * @returns An Observable emitting the result of the agent translate action.\n * @alpha\n */\nexport function agentTranslate(\n instance: SanityInstance,\n options: AgentTranslateOptions,\n resource?: DocumentResource,\n): AgentTranslateResult {\n return getClientState(instance, {apiVersion: API_VERSION, resource}).observable.pipe(\n switchMap((client) => client.observable.agent.action.translate(options)),\n )\n}\n\n/**\n * Prompts the agent using the same instruction template format as the other actions, but returns text or json instead of acting on a document.\n * @param instance - The Sanity instance.\n * @param options - The options for the agent prompt action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.\n * @returns An Observable emitting the result of the agent prompt action.\n * @alpha\n */\nexport function agentPrompt(\n instance: SanityInstance,\n options: AgentPromptOptions,\n resource?: DocumentResource,\n): Observable<AgentPromptResult> {\n return getClientState(instance, {apiVersion: API_VERSION, resource}).observable.pipe(\n switchMap((client) => from(client.agent.action.prompt(options))),\n )\n}\n\n/**\n * Patches a document using the agent.\n * @param instance - The Sanity instance.\n * @param options - The options for the agent patch action. See the [Agent Actions API](https://www.sanity.io/docs/agent-actions/introduction) for more details.\n * @returns An Observable emitting the result of the agent patch action.\n * @alpha\n */\nexport function agentPatch(\n instance: SanityInstance,\n options: AgentPatchOptions,\n resource?: DocumentResource,\n): Observable<AgentPatchResult> {\n return getClientState(instance, {apiVersion: API_VERSION, resource}).observable.pipe(\n switchMap((client) => from(client.agent.action.patch(options))),\n )\n}\n"],"mappings":";;;;;;;;;;AA0DA,SAAgB,cACd,UACA,SACA,UACqB;CACrB,OAAO,eAAe,UAAU;EAAC,YAAY;EAAa;CAAQ,CAAC,CAAC,CAAC,WAAW,KAC9E,WAAW,WAAW,OAAO,WAAW,MAAM,OAAO,SAAS,OAAO,CAAC,CACxE;AACF;;;;;;;;AASA,SAAgB,eACd,UACA,SACA,UACsB;CACtB,OAAO,eAAe,UAAU;EAAC,YAAY;EAAa;CAAQ,CAAC,CAAC,CAAC,WAAW,KAC9E,WAAW,WAAW,OAAO,WAAW,MAAM,OAAO,UAAU,OAAO,CAAC,CACzE;AACF;;;;;;;;AASA,SAAgB,eACd,UACA,SACA,UACsB;CACtB,OAAO,eAAe,UAAU;EAAC,YAAY;EAAa;CAAQ,CAAC,CAAC,CAAC,WAAW,KAC9E,WAAW,WAAW,OAAO,WAAW,MAAM,OAAO,UAAU,OAAO,CAAC,CACzE;AACF;;;;;;;;AASA,SAAgB,YACd,UACA,SACA,UAC+B;CAC/B,OAAO,eAAe,UAAU;EAAC,YAAY;EAAa;CAAQ,CAAC,CAAC,CAAC,WAAW,KAC9E,WAAW,WAAW,KAAK,OAAO,MAAM,OAAO,OAAO,OAAO,CAAC,CAAC,CACjE;AACF;;;;;;;;AASA,SAAgB,WACd,UACA,SACA,UAC8B;CAC9B,OAAO,eAAe,UAAU;EAAC,YAAY;EAAa;CAAQ,CAAC,CAAC,CAAC,WAAW,KAC9E,WAAW,WAAW,KAAK,OAAO,MAAM,OAAO,MAAM,OAAO,CAAC,CAAC,CAChE;AACF"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Ti as BoundStoreAction, wi as StateSource } from "../authStore-C0o1NOxW.js";
|
|
2
|
+
import { ChannelInput, ChannelInstance, Controller, Message, Node, NodeInput, Status } from "@sanity/comlink";
|
|
3
|
+
/**
|
|
4
|
+
* Message sent from a containing app to an iframe
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
type FrameMessage = Message;
|
|
8
|
+
/**
|
|
9
|
+
* Message sent from an iframe to a containing app
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
type WindowMessage = Message;
|
|
13
|
+
/**
|
|
14
|
+
* Message from SDK (iframe) to Parent (dashboard) to request a new token
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
type RequestNewTokenMessage = {
|
|
18
|
+
type: 'dashboard/v1/auth/tokens/create';
|
|
19
|
+
payload?: undefined;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Message from Parent (dashboard) to SDK (iframe) with the new token
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
type NewTokenResponseMessage = {
|
|
26
|
+
type: 'dashboard/v1/auth/tokens/create';
|
|
27
|
+
payload: {
|
|
28
|
+
token: string | null;
|
|
29
|
+
error?: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Individual channel with its relevant options
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
interface ChannelEntry {
|
|
37
|
+
channel: ChannelInstance<FrameMessage, WindowMessage>;
|
|
38
|
+
options: ChannelInput;
|
|
39
|
+
refCount: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Internal state tracking comlink connections
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
interface ComlinkControllerState {
|
|
46
|
+
controller: Controller | null;
|
|
47
|
+
controllerOrigin: string | null;
|
|
48
|
+
channels: Map<string, ChannelEntry>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Calls the destroy method on the controller and resets the controller state.
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
declare const destroyController: BoundStoreAction<ComlinkControllerState, [], void>;
|
|
55
|
+
/**
|
|
56
|
+
* Retrieve or create a channel to be used for communication between
|
|
57
|
+
* an application and the controller.
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
declare const getOrCreateChannel: BoundStoreAction<ComlinkControllerState, [options: ChannelInput], ChannelInstance<import("@sanity/comlink").Message, import("@sanity/comlink").Message>>;
|
|
61
|
+
/**
|
|
62
|
+
* Initializes or fetches a controller to handle communication
|
|
63
|
+
* between an application and iframes.
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
declare const getOrCreateController: BoundStoreAction<ComlinkControllerState, [targetOrigin: string], Controller>;
|
|
67
|
+
/**
|
|
68
|
+
* Signals to the store that the consumer has stopped using the channel
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
declare const releaseChannel: BoundStoreAction<ComlinkControllerState, [name: string], void>;
|
|
72
|
+
/**
|
|
73
|
+
* Individual node with its relevant options
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
interface NodeEntry {
|
|
77
|
+
node: Node<WindowMessage, FrameMessage>;
|
|
78
|
+
options: NodeInput;
|
|
79
|
+
status: Status;
|
|
80
|
+
statusUnsub?: () => void;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Internal state tracking comlink connections
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
interface ComlinkNodeState {
|
|
87
|
+
nodes: Map<string, NodeEntry>;
|
|
88
|
+
subscriptions: Map<string, Set<symbol>>;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Signals to the store that the consumer has stopped using the node
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
94
|
+
declare const releaseNode: BoundStoreAction<ComlinkNodeState, [name: string], void>;
|
|
95
|
+
/**
|
|
96
|
+
* Retrieve or create a node to be used for communication between
|
|
97
|
+
* an application and the controller -- specifically, a node should
|
|
98
|
+
* be created within a frame / window to communicate with the controller.
|
|
99
|
+
* @public
|
|
100
|
+
*/
|
|
101
|
+
declare const getOrCreateNode: BoundStoreAction<ComlinkNodeState, [options: NodeInput], Node<import("@sanity/comlink").Message, import("@sanity/comlink").Message>>;
|
|
102
|
+
/**
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
interface NodeState {
|
|
106
|
+
node: Node<WindowMessage, FrameMessage>;
|
|
107
|
+
status: Status | undefined;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Provides a subscribable state source for a node by name
|
|
111
|
+
* @param instance - The Sanity instance to get the node state for
|
|
112
|
+
* @param nodeInput - The configuration for the node to get the state for
|
|
113
|
+
* @returns A subscribable state source for the node
|
|
114
|
+
* @public
|
|
115
|
+
*/
|
|
116
|
+
declare const getNodeState: BoundStoreAction<ComlinkNodeState, [NodeInput], StateSource<NodeState | undefined>>;
|
|
117
|
+
export { type ComlinkControllerState, type ComlinkNodeState, type FrameMessage, type NewTokenResponseMessage, type NodeState, type RequestNewTokenMessage, type WindowMessage, destroyController, getNodeState, getOrCreateChannel, getOrCreateController, getOrCreateNode, releaseChannel, releaseNode };
|
|
118
|
+
//# sourceMappingURL=comlink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comlink.d.ts","names":[],"sources":["../../src/comlink/types.ts","../../src/comlink/controller/comlinkControllerStore.ts","../../src/comlink/node/comlinkNodeStore.ts","../../src/comlink/node/getNodeState.ts"],"mappings":";;;;;;KAMY,eAAe;;;;;KAMf,gBAAgB;;;;;KAMhB;EACV;EACA;;;;;;KAOU;EACV;EACA;IAAU;IAAsB;;;;;;;UCfjB;EACf,SAAS,gBAAgB,cAAc;EAEvC,SAAS;EAET;;;;;;UAOe;EACf,YAAY;EACZ;EACA,UAAU,YAAY;;;;;;cAyBX,mBAAiB,iBAAA;;;;;;cAUjB,oBAAkB,iBAAA,yBAAA,SAAA,eAAA,0CAAA,mCAAA;;;;;;cAUlB,uBAAqB,iBAAA,yBAAA,uBAAA;;;;;cASrB,gBAAc,iBAAA,yBAAA;;;;;UCvEV;EACf,MAAM,KAAK,eAAe;EAE1B,SAAS;EAET,QAAQ;EACR;;;;;;UAOe;EACf,OAAO,YAAY;EAEnB,eAAe,YAAY;;;;;;cAuBhB,aAAW,iBAAA,mBAAA;;;;;;;cAQX,iBAAe,iBAAA,mBAAA,SAAA,YAAA,+BAAA,mCAAA;;;;UCvCX;EACf,MAAM,KAAK,eAAe;EAC1B,QAAQ;;;;;;;;;cAaG,cAAY,iBAAA,mBAAA,YAAA,YAAA"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { a as defineStore, i as bindActionGlobally } from "../createStateSourceAction-BOKtqFNm.js";
|
|
2
|
+
import { t as isDeepEqual } from "../object-CxXlSVg7.js";
|
|
3
|
+
import { n as getOrCreateNode, r as releaseNode, t as getNodeState } from "../getNodeState-CR3__B2D.js";
|
|
4
|
+
import { createController } from "@sanity/comlink";
|
|
5
|
+
/**
|
|
6
|
+
* Calls the destroy method on the controller and resets the controller state.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
const destroyController$1 = ({ state }) => {
|
|
10
|
+
let { controller } = state.get();
|
|
11
|
+
controller && (controller.destroy(), state.set("destroyController", {
|
|
12
|
+
controller: null,
|
|
13
|
+
channels: /* @__PURE__ */ new Map()
|
|
14
|
+
}));
|
|
15
|
+
}, getOrCreateChannel$1 = ({ state }, options) => {
|
|
16
|
+
let controller = state.get().controller;
|
|
17
|
+
if (!controller) throw Error("Controller must be initialized before using or creating channels");
|
|
18
|
+
let channels = state.get().channels, existing = channels.get(options.name);
|
|
19
|
+
if (existing) {
|
|
20
|
+
if (!isDeepEqual(existing.options, options)) throw Error(`Channel "${options.name}" already exists with different options`);
|
|
21
|
+
return state.set("incrementChannelRefCount", { channels: new Map(channels).set(options.name, {
|
|
22
|
+
...existing,
|
|
23
|
+
refCount: existing.refCount + 1
|
|
24
|
+
}) }), existing.channel.start(), existing.channel;
|
|
25
|
+
}
|
|
26
|
+
let channel = controller.createChannel(options);
|
|
27
|
+
return channel.start(), state.set("createChannel", { channels: new Map(channels).set(options.name, {
|
|
28
|
+
channel,
|
|
29
|
+
options,
|
|
30
|
+
refCount: 1
|
|
31
|
+
}) }), channel;
|
|
32
|
+
}, getOrCreateController$1 = ({ state, instance }, targetOrigin) => {
|
|
33
|
+
let { controller, controllerOrigin } = state.get();
|
|
34
|
+
if (controller && controllerOrigin === targetOrigin) return controller;
|
|
35
|
+
controller && destroyController$1({
|
|
36
|
+
state,
|
|
37
|
+
instance,
|
|
38
|
+
key: void 0
|
|
39
|
+
});
|
|
40
|
+
let newController = createController({ targetOrigin });
|
|
41
|
+
return state.set("initializeController", {
|
|
42
|
+
controllerOrigin: targetOrigin,
|
|
43
|
+
controller: newController
|
|
44
|
+
}), newController;
|
|
45
|
+
}, releaseChannel$1 = ({ state }, name) => {
|
|
46
|
+
let channels = state.get().channels, channelEntry = channels.get(name);
|
|
47
|
+
if (channelEntry) {
|
|
48
|
+
let newRefCount = channelEntry.refCount === 0 ? 0 : channelEntry.refCount - 1;
|
|
49
|
+
newRefCount === 0 ? (channelEntry.channel.stop(), channels.delete(name), state.set("releaseChannel", { channels: new Map(channels) })) : state.set("releaseChannel", { channels: new Map(channels).set(name, {
|
|
50
|
+
...channelEntry,
|
|
51
|
+
refCount: newRefCount
|
|
52
|
+
}) });
|
|
53
|
+
}
|
|
54
|
+
}, comlinkControllerStore = defineStore({
|
|
55
|
+
name: "connectionStore",
|
|
56
|
+
getInitialState: () => ({
|
|
57
|
+
controller: null,
|
|
58
|
+
controllerOrigin: null,
|
|
59
|
+
channels: /* @__PURE__ */ new Map()
|
|
60
|
+
}),
|
|
61
|
+
initialize({ instance }) {
|
|
62
|
+
return () => {
|
|
63
|
+
destroyController(instance);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}), destroyController = bindActionGlobally(comlinkControllerStore, destroyController$1), getOrCreateChannel = bindActionGlobally(comlinkControllerStore, getOrCreateChannel$1), getOrCreateController = bindActionGlobally(comlinkControllerStore, getOrCreateController$1), releaseChannel = bindActionGlobally(comlinkControllerStore, releaseChannel$1);
|
|
67
|
+
export { destroyController, getNodeState, getOrCreateChannel, getOrCreateController, getOrCreateNode, releaseChannel, releaseNode };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=comlink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comlink.js","names":["destroyController","getOrCreateChannel","getOrCreateController","releaseChannel","unboundDestroyController","unboundGetOrCreateChannel","unboundGetOrCreateController","unboundReleaseChannel"],"sources":["../../src/comlink/controller/actions/destroyController.ts","../../src/comlink/controller/actions/getOrCreateChannel.ts","../../src/comlink/controller/actions/getOrCreateController.ts","../../src/comlink/controller/actions/releaseChannel.ts","../../src/comlink/controller/comlinkControllerStore.ts"],"sourcesContent":["import {type StoreContext} from '../../../store/defineStore'\nimport {type ComlinkControllerState} from '../comlinkControllerStore'\n\n/**\n * Calls the destroy method on the controller and resets the controller state.\n * @public\n */\nexport const destroyController = ({state}: StoreContext<ComlinkControllerState>): void => {\n const {controller} = state.get()\n\n if (controller) {\n controller.destroy()\n state.set('destroyController', {\n controller: null,\n channels: new Map(),\n })\n }\n}\n","import {type ChannelInput, type ChannelInstance} from '@sanity/comlink'\n\nimport {type StoreContext} from '../../../store/defineStore'\nimport {isDeepEqual} from '../../../utils/object'\nimport {type FrameMessage, type WindowMessage} from '../../types'\nimport {type ComlinkControllerState} from '../comlinkControllerStore'\n\n/**\n * Retrieve or create a channel to be used for communication between\n * an application and the controller.\n * @public\n */\nexport const getOrCreateChannel = (\n {state}: StoreContext<ComlinkControllerState>,\n options: ChannelInput,\n): ChannelInstance<FrameMessage, WindowMessage> => {\n const controller = state.get().controller\n\n if (!controller) {\n throw new Error('Controller must be initialized before using or creating channels')\n }\n\n const channels = state.get().channels\n const existing = channels.get(options.name)\n\n // limit channels to one per name\n if (existing) {\n if (!isDeepEqual(existing.options, options)) {\n throw new Error(`Channel \"${options.name}\" already exists with different options`)\n }\n\n state.set('incrementChannelRefCount', {\n channels: new Map(channels).set(options.name, {\n ...existing,\n refCount: existing.refCount + 1,\n }),\n })\n existing.channel.start()\n return existing.channel\n }\n\n const channel = controller.createChannel(options)\n channel.start()\n state.set('createChannel', {\n channels: new Map(channels).set(options.name, {\n channel,\n options,\n refCount: 1,\n }),\n })\n\n return channel\n}\n","import {type Controller, createController} from '@sanity/comlink'\n\nimport {type StoreContext} from '../../../store/defineStore'\nimport {type ComlinkControllerState} from '../comlinkControllerStore'\nimport {destroyController} from './destroyController'\n\n/**\n * Initializes or fetches a controller to handle communication\n * between an application and iframes.\n * @public\n */\nexport const getOrCreateController = (\n {state, instance}: StoreContext<ComlinkControllerState>,\n targetOrigin: string,\n): Controller => {\n const {controller, controllerOrigin} = state.get()\n if (controller && controllerOrigin === targetOrigin) {\n return controller\n }\n\n // if the target origin has changed, we'll create a new controller,\n // but need to clean up first\n if (controller) {\n destroyController({state, instance, key: undefined})\n }\n\n const newController = createController({targetOrigin})\n state.set('initializeController', {\n controllerOrigin: targetOrigin,\n controller: newController,\n })\n\n return newController\n}\n","import {type StoreContext} from '../../../store/defineStore'\nimport {type ComlinkControllerState} from '../comlinkControllerStore'\n\n/**\n * Signals to the store that the consumer has stopped using the channel\n * @public\n */\nexport const releaseChannel = (\n {state}: StoreContext<ComlinkControllerState>,\n name: string,\n): void => {\n const channels = state.get().channels\n const channelEntry = channels.get(name)\n\n if (channelEntry) {\n const newRefCount = channelEntry.refCount === 0 ? 0 : channelEntry.refCount - 1\n\n if (newRefCount === 0) {\n channelEntry.channel.stop()\n channels.delete(name)\n state.set('releaseChannel', {channels: new Map(channels)})\n } else {\n state.set('releaseChannel', {\n channels: new Map(channels).set(name, {\n ...channelEntry,\n refCount: newRefCount,\n }),\n })\n }\n }\n}\n","import {type ChannelInput, type ChannelInstance, type Controller} from '@sanity/comlink'\n\nimport {bindActionGlobally} from '../../store/createActionBinder'\nimport {defineStore} from '../../store/defineStore'\nimport {type FrameMessage, type WindowMessage} from '../types'\nimport {destroyController as unboundDestroyController} from './actions/destroyController'\nimport {getOrCreateChannel as unboundGetOrCreateChannel} from './actions/getOrCreateChannel'\nimport {getOrCreateController as unboundGetOrCreateController} from './actions/getOrCreateController'\nimport {releaseChannel as unboundReleaseChannel} from './actions/releaseChannel'\n\n/**\n * Individual channel with its relevant options\n * @public\n */\nexport interface ChannelEntry {\n channel: ChannelInstance<FrameMessage, WindowMessage>\n // we store options to ensure that channels remain as unique / consistent as possible\n options: ChannelInput\n // we store refCount to ensure channels remain open only as long as they are in use\n refCount: number\n}\n\n/**\n * Internal state tracking comlink connections\n * @public\n */\nexport interface ComlinkControllerState {\n controller: Controller | null\n controllerOrigin: string | null\n channels: Map<string, ChannelEntry>\n}\n\nexport const comlinkControllerStore = defineStore<ComlinkControllerState>({\n name: 'connectionStore',\n getInitialState: () => {\n const initialState = {\n controller: null,\n controllerOrigin: null,\n channels: new Map(),\n }\n return initialState\n },\n initialize({instance}) {\n return () => {\n // destroying controller also destroys channels\n destroyController(instance)\n }\n },\n})\n\n/**\n * Calls the destroy method on the controller and resets the controller state.\n * @public\n */\nexport const destroyController = bindActionGlobally(\n comlinkControllerStore,\n unboundDestroyController,\n)\n\n/**\n * Retrieve or create a channel to be used for communication between\n * an application and the controller.\n * @public\n */\nexport const getOrCreateChannel = bindActionGlobally(\n comlinkControllerStore,\n unboundGetOrCreateChannel,\n)\n\n/**\n * Initializes or fetches a controller to handle communication\n * between an application and iframes.\n * @public\n */\nexport const getOrCreateController = bindActionGlobally(\n comlinkControllerStore,\n unboundGetOrCreateController,\n)\n\n/**\n * Signals to the store that the consumer has stopped using the channel\n * @public\n */\nexport const releaseChannel = bindActionGlobally(comlinkControllerStore, unboundReleaseChannel)\n"],"mappings":";;;;;;;;AAOA,MAAaA,uBAAqB,EAAC,YAAuD;CACxF,IAAM,EAAC,eAAc,MAAM,IAAI;CAE/B,AAAI,eACF,WAAW,QAAQ,GACnB,MAAM,IAAI,qBAAqB;EAC7B,YAAY;EACZ,0BAAU,IAAI,IAAI;CACpB,CAAC;AAEL,GCLaC,wBACX,EAAC,SACD,YACiD;CACjD,IAAM,aAAa,MAAM,IAAI,CAAC,CAAC;CAE/B,IAAI,CAAC,YACH,MAAU,MAAM,kEAAkE;CAGpF,IAAM,WAAW,MAAM,IAAI,CAAC,CAAC,UACvB,WAAW,SAAS,IAAI,QAAQ,IAAI;CAG1C,IAAI,UAAU;EACZ,IAAI,CAAC,YAAY,SAAS,SAAS,OAAO,GACxC,MAAU,MAAM,YAAY,QAAQ,KAAK,wCAAwC;EAUnF,OAPA,MAAM,IAAI,4BAA4B,EACpC,UAAU,IAAI,IAAI,QAAQ,CAAC,CAAC,IAAI,QAAQ,MAAM;GAC5C,GAAG;GACH,UAAU,SAAS,WAAW;EAChC,CAAC,EACH,CAAC,GACD,SAAS,QAAQ,MAAM,GAChB,SAAS;CAClB;CAEA,IAAM,UAAU,WAAW,cAAc,OAAO;CAUhD,OATA,QAAQ,MAAM,GACd,MAAM,IAAI,iBAAiB,EACzB,UAAU,IAAI,IAAI,QAAQ,CAAC,CAAC,IAAI,QAAQ,MAAM;EAC5C;EACA;EACA,UAAU;CACZ,CAAC,EACH,CAAC,GAEM;AACT,GCzCaC,2BACX,EAAC,OAAO,YACR,iBACe;CACf,IAAM,EAAC,YAAY,qBAAoB,MAAM,IAAI;CACjD,IAAI,cAAc,qBAAqB,cACrC,OAAO;CAKT,AAAI,cACF,oBAAkB;EAAC;EAAO;EAAU,KAAK,KAAA;CAAS,CAAC;CAGrD,IAAM,gBAAgB,iBAAiB,EAAC,aAAY,CAAC;CAMrD,OALA,MAAM,IAAI,wBAAwB;EAChC,kBAAkB;EAClB,YAAY;CACd,CAAC,GAEM;AACT,GC1BaC,oBACX,EAAC,SACD,SACS;CACT,IAAM,WAAW,MAAM,IAAI,CAAC,CAAC,UACvB,eAAe,SAAS,IAAI,IAAI;CAEtC,IAAI,cAAc;EAChB,IAAM,cAAc,aAAa,aAAa,IAAI,IAAI,aAAa,WAAW;EAE9E,AAAI,gBAAgB,KAClB,aAAa,QAAQ,KAAK,GAC1B,SAAS,OAAO,IAAI,GACpB,MAAM,IAAI,kBAAkB,EAAC,UAAU,IAAI,IAAI,QAAQ,EAAC,CAAC,KAEzD,MAAM,IAAI,kBAAkB,EAC1B,UAAU,IAAI,IAAI,QAAQ,CAAC,CAAC,IAAI,MAAM;GACpC,GAAG;GACH,UAAU;EACZ,CAAC,EACH,CAAC;CAEL;AACF,GCEa,yBAAyB,YAAoC;CACxE,MAAM;CACN,wBAMS;EAJL,YAAY;EACZ,kBAAkB;EAClB,0BAAU,IAAI,IAAI;CAEF;CAEpB,WAAW,EAAC,YAAW;EACrB,aAAa;GAEX,kBAAkB,QAAQ;EAC5B;CACF;AACF,CAAC,GAMY,oBAAoB,mBAC/B,wBACAC,mBACF,GAOa,qBAAqB,mBAChC,wBACAC,oBACF,GAOa,wBAAwB,mBACnC,wBACAC,uBACF,GAMa,iBAAiB,mBAAmB,wBAAwBC,gBAAqB"}
|