@sanity/sdk 1.0.0 → 2.0.1
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 +1 -1
- package/dist/index.d.ts +60 -2
- package/dist/index.js +98 -207
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
- package/src/_exports/index.ts +10 -1
- package/src/auth/authStore.ts +45 -0
- package/src/comlink/types.ts +18 -0
- package/src/document/documentStore.test.ts +2 -2
- package/src/document/documentStore.ts +2 -1
- package/src/document/patchOperations.test.ts +6 -6
- package/src/document/patchOperations.ts +123 -102
- package/src/document/processActions.ts +2 -6
- package/src/document/processMutations.ts +2 -2
- package/src/preview/previewQuery.test.ts +3 -3
- package/src/preview/previewQuery.ts +2 -2
- package/src/preview/previewStore.ts +1 -1
- package/src/projection/projectionQuery.test.ts +6 -6
- package/src/projection/projectionQuery.ts +2 -2
- package/src/projection/subscribeToStateAndFetchBatches.test.ts +2 -2
- package/src/releases/getPerspectiveState.test.ts +2 -1
- package/src/releases/getPerspectiveState.ts +2 -1
- package/src/releases/releasesStore.test.ts +2 -2
- package/src/releases/releasesStore.ts +12 -2
- package/src/auth/Auth Guide.md +0 -165
- package/src/document/diffPatch.test.ts +0 -335
- package/src/document/diffPatch.ts +0 -288
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<a href="https://sanity.io">
|
|
3
|
-
<img src="https://cdn.sanity.io/images/3do82whm/next/
|
|
3
|
+
<img src="https://cdn.sanity.io/images/3do82whm/next/d6cf401d52c33b7a5a354a14ab7de94dea2f0c02-192x192.svg" />
|
|
4
4
|
</a>
|
|
5
5
|
<h1 align="center">Sanity App SDK (Core)</h1>
|
|
6
6
|
</p>
|
package/dist/index.d.ts
CHANGED
|
@@ -1207,6 +1207,16 @@ export declare const getFavoritesState: BoundStoreAction<
|
|
|
1207
1207
|
StateSource_2<FavoriteStatusResponse | undefined>
|
|
1208
1208
|
>
|
|
1209
1209
|
|
|
1210
|
+
/**
|
|
1211
|
+
* Returns a state source indicating if the SDK is running within a dashboard context.
|
|
1212
|
+
* @public
|
|
1213
|
+
*/
|
|
1214
|
+
export declare const getIsInDashboardState: BoundStoreAction<
|
|
1215
|
+
AuthStoreState,
|
|
1216
|
+
[],
|
|
1217
|
+
StateSource_2<boolean>
|
|
1218
|
+
>
|
|
1219
|
+
|
|
1210
1220
|
/**
|
|
1211
1221
|
* @public
|
|
1212
1222
|
*/
|
|
@@ -1248,6 +1258,18 @@ export declare const getOrCreateController: BoundStoreAction_2<
|
|
|
1248
1258
|
Controller
|
|
1249
1259
|
>
|
|
1250
1260
|
|
|
1261
|
+
/**
|
|
1262
|
+
* Retrieve or create a node to be used for communication between
|
|
1263
|
+
* an application and the controller -- specifically, a node should
|
|
1264
|
+
* be created within a frame / window to communicate with the controller.
|
|
1265
|
+
* @public
|
|
1266
|
+
*/
|
|
1267
|
+
export declare const getOrCreateNode: BoundStoreAction_2<
|
|
1268
|
+
ComlinkNodeState,
|
|
1269
|
+
[options: NodeInput],
|
|
1270
|
+
Node_2<Message, Message>
|
|
1271
|
+
>
|
|
1272
|
+
|
|
1251
1273
|
/** @beta */
|
|
1252
1274
|
export declare const getPermissionsState: BoundStoreAction<
|
|
1253
1275
|
DocumentStoreState,
|
|
@@ -1632,6 +1654,18 @@ declare interface NegNode extends BaseNode {
|
|
|
1632
1654
|
base: ExprNode
|
|
1633
1655
|
}
|
|
1634
1656
|
|
|
1657
|
+
/**
|
|
1658
|
+
* Message from Parent (dashboard) to SDK (iframe) with the new token
|
|
1659
|
+
* @internal
|
|
1660
|
+
*/
|
|
1661
|
+
export declare type NewTokenResponseMessage = {
|
|
1662
|
+
type: 'dashboard/v1/auth/tokens/create'
|
|
1663
|
+
payload: {
|
|
1664
|
+
token: string | null
|
|
1665
|
+
error?: string
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1635
1669
|
/**
|
|
1636
1670
|
* Individual node with its relevant options
|
|
1637
1671
|
* @public
|
|
@@ -1882,7 +1916,7 @@ export declare interface PreviewValue {
|
|
|
1882
1916
|
/**
|
|
1883
1917
|
* The status of the document.
|
|
1884
1918
|
*/
|
|
1885
|
-
|
|
1919
|
+
_status?: {
|
|
1886
1920
|
/** The date of the last published edit */
|
|
1887
1921
|
lastEditedPublishedAt?: string
|
|
1888
1922
|
/** The date of the last draft edit */
|
|
@@ -2002,17 +2036,25 @@ export declare const releaseChannel: BoundStoreAction_2<
|
|
|
2002
2036
|
export declare type ReleaseDocument = SanityDocument & {
|
|
2003
2037
|
name: string
|
|
2004
2038
|
publishAt?: string
|
|
2039
|
+
state: 'active' | 'scheduled'
|
|
2005
2040
|
metadata: {
|
|
2006
2041
|
title: string
|
|
2007
2042
|
releaseType: 'asap' | 'scheduled' | 'undecided'
|
|
2008
2043
|
intendedPublishAt?: string
|
|
2044
|
+
description?: string
|
|
2009
2045
|
}
|
|
2010
2046
|
}
|
|
2011
2047
|
|
|
2048
|
+
/**
|
|
2049
|
+
* Signals to the store that the consumer has stopped using the node
|
|
2050
|
+
* @public
|
|
2051
|
+
*/
|
|
2052
|
+
export declare const releaseNode: BoundStoreAction_2<ComlinkNodeState, [name: string], void>
|
|
2053
|
+
|
|
2012
2054
|
/**
|
|
2013
2055
|
* @public
|
|
2014
2056
|
*/
|
|
2015
|
-
declare type ReleasePerspective = {
|
|
2057
|
+
export declare type ReleasePerspective = {
|
|
2016
2058
|
releaseName: string
|
|
2017
2059
|
excludedPerspectives?: StackablePerspective[]
|
|
2018
2060
|
}
|
|
@@ -2022,6 +2064,15 @@ declare interface ReleasesStoreState {
|
|
|
2022
2064
|
error?: unknown
|
|
2023
2065
|
}
|
|
2024
2066
|
|
|
2067
|
+
/**
|
|
2068
|
+
* Message from SDK (iframe) to Parent (dashboard) to request a new token
|
|
2069
|
+
* @internal
|
|
2070
|
+
*/
|
|
2071
|
+
export declare type RequestNewTokenMessage = {
|
|
2072
|
+
type: 'dashboard/v1/auth/tokens/create'
|
|
2073
|
+
payload?: undefined
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2025
2076
|
/** @public */
|
|
2026
2077
|
export declare const resolveDatasets: BoundStoreAction<
|
|
2027
2078
|
FetcherStoreState_2<[options?: ProjectHandle<string> | undefined], DatasetsResponse>,
|
|
@@ -2351,6 +2402,13 @@ declare interface SelectorNode extends BaseNode {
|
|
|
2351
2402
|
type: 'Selector'
|
|
2352
2403
|
}
|
|
2353
2404
|
|
|
2405
|
+
/**
|
|
2406
|
+
* Action to explicitly set the authentication token.
|
|
2407
|
+
* Used internally by the Comlink token refresh.
|
|
2408
|
+
* @internal
|
|
2409
|
+
*/
|
|
2410
|
+
export declare const setAuthToken: BoundStoreAction<AuthStoreState, [token: string | null], void>
|
|
2411
|
+
|
|
2354
2412
|
declare interface SharedListener {
|
|
2355
2413
|
events: Observable<ListenEvent<SanityDocument_3>>
|
|
2356
2414
|
dispose: () => void
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,8 @@ import { createController, createNode } from "@sanity/comlink";
|
|
|
8
8
|
import { createSelector } from "reselect";
|
|
9
9
|
import { SanityEncoder } from "@sanity/mutate";
|
|
10
10
|
import { getPublishedId as getPublishedId$1 } from "@sanity/client/csm";
|
|
11
|
-
import {
|
|
11
|
+
import { diffValue } from "@sanity/diff-patch";
|
|
12
|
+
import { applyPatches, parsePatch } from "@sanity/diff-match-patch";
|
|
12
13
|
import { isKeySegment, isKeyedObject } from "@sanity/types";
|
|
13
14
|
import { createDocumentLoaderFromClient } from "@sanity/mutate/_unstable_store";
|
|
14
15
|
import { SDK_CHANNEL_NAME, SDK_NODE_NAME } from "@sanity/message-protocol";
|
|
@@ -487,7 +488,28 @@ const authStore = {
|
|
|
487
488
|
), getDashboardOrganizationId$1 = bindActionGlobally(
|
|
488
489
|
authStore,
|
|
489
490
|
createStateSourceAction(({ state: { dashboardContext } }) => dashboardContext?.orgId)
|
|
490
|
-
)
|
|
491
|
+
), getIsInDashboardState = bindActionGlobally(
|
|
492
|
+
authStore,
|
|
493
|
+
createStateSourceAction(
|
|
494
|
+
({ state: { dashboardContext } }) => (
|
|
495
|
+
// Check if dashboardContext exists and is not empty
|
|
496
|
+
!!dashboardContext && Object.keys(dashboardContext).length > 0
|
|
497
|
+
)
|
|
498
|
+
)
|
|
499
|
+
), setAuthToken = bindActionGlobally(authStore, ({ state }, token) => {
|
|
500
|
+
const currentAuthState = state.get().authState;
|
|
501
|
+
token ? (currentAuthState.type !== AuthStateType.LOGGED_IN || currentAuthState.token !== token) && state.set("setToken", {
|
|
502
|
+
authState: {
|
|
503
|
+
type: AuthStateType.LOGGED_IN,
|
|
504
|
+
token,
|
|
505
|
+
// Keep existing user or set to null? Setting to null forces refetch.
|
|
506
|
+
// Keep existing user to avoid unnecessary refetches if user data is still valid.
|
|
507
|
+
currentUser: currentAuthState.type === AuthStateType.LOGGED_IN ? currentAuthState.currentUser : null
|
|
508
|
+
}
|
|
509
|
+
}) : currentAuthState.type !== AuthStateType.LOGGED_OUT && state.set("setToken", {
|
|
510
|
+
authState: { type: AuthStateType.LOGGED_OUT, isDestroyingSession: !1 }
|
|
511
|
+
});
|
|
512
|
+
});
|
|
491
513
|
function compareProjectOrganization(projectId, projectOrganizationId, currentDashboardOrgId) {
|
|
492
514
|
return projectOrganizationId !== currentDashboardOrgId ? {
|
|
493
515
|
error: `Project ${projectId} belongs to Organization ${projectOrganizationId ?? "unknown"}, but the Dashboard has Organization ${currentDashboardOrgId} selected`
|
|
@@ -1127,16 +1149,13 @@ function matchRecursive(value, path, currentPath) {
|
|
|
1127
1149
|
if (!Array.isArray(value))
|
|
1128
1150
|
return [];
|
|
1129
1151
|
const [start, end] = head, startIndex = start === "" ? 0 : start, endIndex = end === "" ? value.length : end;
|
|
1130
|
-
|
|
1131
|
-
for (let i2 = startIndex; i2 < endIndex; i2++)
|
|
1132
|
-
results = results.concat(matchRecursive(value[i2], rest, [...currentPath, i2]));
|
|
1133
|
-
return results;
|
|
1152
|
+
return value.slice(startIndex, endIndex).flatMap((item, i2) => matchRecursive(item, rest, [...currentPath, i2 + startIndex]));
|
|
1134
1153
|
}
|
|
1135
|
-
const arrIndex = getIndexForKey(value,
|
|
1154
|
+
const keyed = head, arrIndex = getIndexForKey(value, keyed._key);
|
|
1136
1155
|
if (arrIndex === void 0 || !Array.isArray(value))
|
|
1137
1156
|
return [];
|
|
1138
1157
|
const nextVal = value[arrIndex];
|
|
1139
|
-
return matchRecursive(nextVal, rest, [...currentPath,
|
|
1158
|
+
return matchRecursive(nextVal, rest, [...currentPath, { _key: keyed._key }]);
|
|
1140
1159
|
}
|
|
1141
1160
|
function generateArrayKey(length = 12) {
|
|
1142
1161
|
const numBytes = Math.ceil(length / 2), bytes = crypto.getRandomValues(new Uint8Array(numBytes));
|
|
@@ -1176,69 +1195,65 @@ function setIfMissing(input, pathExpressionValues) {
|
|
|
1176
1195
|
return ensureArrayKeysDeep(result);
|
|
1177
1196
|
}
|
|
1178
1197
|
function unset(input, pathExpressions) {
|
|
1179
|
-
const result = pathExpressions.flatMap((pathExpression) => jsonMatch(input, pathExpression)).reduce((acc, { path }) => unsetDeep(acc, path), input);
|
|
1198
|
+
const result = pathExpressions.flatMap((pathExpression) => jsonMatch(input, pathExpression)).reverse().reduce((acc, { path }) => unsetDeep(acc, path), input);
|
|
1180
1199
|
return ensureArrayKeysDeep(result);
|
|
1181
1200
|
}
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
case "after":
|
|
1193
|
-
return index < 0 ? -1 : index;
|
|
1194
|
-
default:
|
|
1195
|
-
return index < 0 ? parentLength + index : index;
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
const grouped = /* @__PURE__ */ new Map();
|
|
1199
|
-
jsonMatch(input, pathExpression).map(({ path }) => {
|
|
1200
|
-
const segment = path[path.length - 1];
|
|
1201
|
-
let index;
|
|
1202
|
-
if (isKeySegment(segment) ? index = getIndexForKey(input, segment._key) : typeof segment == "number" && (index = segment), typeof index != "number") return null;
|
|
1203
|
-
const parentPath = path.slice(0, path.length - 1), parent = getDeep(input, parentPath);
|
|
1204
|
-
if (!Array.isArray(parent)) return null;
|
|
1205
|
-
const normalizedIndex = normalizeIndex(index, parent.length);
|
|
1206
|
-
return { parent, parentPath, normalizedIndex };
|
|
1207
|
-
}).filter(isNonNullable).forEach(({ parent, parentPath, normalizedIndex }) => {
|
|
1208
|
-
grouped.has(parent) ? grouped.get(parent).indexes.push(normalizedIndex) : grouped.set(parent, { array: parent, pathToArray: parentPath, indexes: [normalizedIndex] });
|
|
1209
|
-
});
|
|
1210
|
-
const result = Array.from(grouped.values()).map((entry) => ({
|
|
1211
|
-
...entry,
|
|
1212
|
-
indexes: entry.indexes.sort((a2, b2) => a2 - b2)
|
|
1213
|
-
})).reduce((acc, { array, indexes, pathToArray }) => {
|
|
1201
|
+
function insert(input, { items, ...insertPatch }) {
|
|
1202
|
+
let operation, pathExpression;
|
|
1203
|
+
if ("before" in insertPatch ? (operation = "before", pathExpression = insertPatch.before) : "after" in insertPatch ? (operation = "after", pathExpression = insertPatch.after) : "replace" in insertPatch && (operation = "replace", pathExpression = insertPatch.replace), !operation || typeof pathExpression != "string") return input;
|
|
1204
|
+
const parsedPath = parsePath(pathExpression);
|
|
1205
|
+
if (!parsedPath.length) return input;
|
|
1206
|
+
const arrayPath = stringifyPath(parsedPath.slice(0, -1)), positionPath = stringifyPath(parsedPath.slice(-1)), arrayMatches = jsonMatch(input, arrayPath);
|
|
1207
|
+
let result = input;
|
|
1208
|
+
for (const { path, value } of arrayMatches) {
|
|
1209
|
+
if (!Array.isArray(value)) continue;
|
|
1210
|
+
let arr = value;
|
|
1214
1211
|
switch (operation) {
|
|
1212
|
+
case "replace": {
|
|
1213
|
+
const indexesToRemove = /* @__PURE__ */ new Set();
|
|
1214
|
+
let position = 1 / 0;
|
|
1215
|
+
for (const itemMatch of jsonMatch(arr, positionPath)) {
|
|
1216
|
+
if (itemMatch.path.length !== 1) continue;
|
|
1217
|
+
const [segment] = itemMatch.path;
|
|
1218
|
+
if (typeof segment == "string") continue;
|
|
1219
|
+
let index;
|
|
1220
|
+
typeof segment == "number" && (index = segment), typeof index == "number" && index < 0 && (index = arr.length + index), isKeySegment(segment) && (index = getIndexForKey(arr, segment._key)), typeof index == "number" && (index < 0 && (index = arr.length + index), indexesToRemove.add(index), index < position && (position = index));
|
|
1221
|
+
}
|
|
1222
|
+
if (position === 1 / 0) continue;
|
|
1223
|
+
arr = arr.map((item, index) => ({ item, index })).filter(({ index }) => !indexesToRemove.has(index)).map(({ item }) => item), arr = [...arr.slice(0, position), ...items, ...arr.slice(position, arr.length)];
|
|
1224
|
+
break;
|
|
1225
|
+
}
|
|
1215
1226
|
case "before": {
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1227
|
+
let position = 1 / 0;
|
|
1228
|
+
for (const itemMatch of jsonMatch(arr, positionPath)) {
|
|
1229
|
+
if (itemMatch.path.length !== 1) continue;
|
|
1230
|
+
const [segment] = itemMatch.path;
|
|
1231
|
+
if (typeof segment == "string") continue;
|
|
1232
|
+
let index;
|
|
1233
|
+
typeof segment == "number" && (index = segment), typeof index == "number" && index < 0 && (index = arr.length + index), isKeySegment(segment) && (index = getIndexForKey(arr, segment._key)), typeof index == "number" && (index < 0 && (index = arr.length - index), index < position && (position = index));
|
|
1234
|
+
}
|
|
1235
|
+
if (position === 1 / 0) continue;
|
|
1236
|
+
arr = [...arr.slice(0, position), ...items, ...arr.slice(position, arr.length)];
|
|
1237
|
+
break;
|
|
1222
1238
|
}
|
|
1223
1239
|
case "after": {
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
...array.slice(0, firstIndex),
|
|
1236
|
-
...items,
|
|
1237
|
-
...array.slice(firstIndex).filter((_2, idx) => !indexSet.has(idx + firstIndex))
|
|
1238
|
-
]);
|
|
1240
|
+
let position = -1 / 0;
|
|
1241
|
+
for (const itemMatch of jsonMatch(arr, positionPath)) {
|
|
1242
|
+
if (itemMatch.path.length !== 1) continue;
|
|
1243
|
+
const [segment] = itemMatch.path;
|
|
1244
|
+
if (typeof segment == "string") continue;
|
|
1245
|
+
let index;
|
|
1246
|
+
typeof segment == "number" && (index = segment), typeof index == "number" && index < 0 && (index = arr.length + index), isKeySegment(segment) && (index = getIndexForKey(arr, segment._key)), typeof index == "number" && index > position && (position = index);
|
|
1247
|
+
}
|
|
1248
|
+
if (position === -1 / 0) continue;
|
|
1249
|
+
arr = [...arr.slice(0, position + 1), ...items, ...arr.slice(position + 1, arr.length)];
|
|
1250
|
+
break;
|
|
1239
1251
|
}
|
|
1252
|
+
default:
|
|
1253
|
+
continue;
|
|
1240
1254
|
}
|
|
1241
|
-
|
|
1255
|
+
result = setDeep(result, path, arr);
|
|
1256
|
+
}
|
|
1242
1257
|
return ensureArrayKeysDeep(result);
|
|
1243
1258
|
}
|
|
1244
1259
|
function inc(input, pathExpressionValues) {
|
|
@@ -1282,9 +1297,6 @@ function ifRevisionID(input, revisionId) {
|
|
|
1282
1297
|
);
|
|
1283
1298
|
return input;
|
|
1284
1299
|
}
|
|
1285
|
-
function isNonNullable(t2) {
|
|
1286
|
-
return t2 != null;
|
|
1287
|
-
}
|
|
1288
1300
|
const indexCache = /* @__PURE__ */ new WeakMap();
|
|
1289
1301
|
function getIndexForKey(input, key) {
|
|
1290
1302
|
if (!Array.isArray(input)) return;
|
|
@@ -1293,15 +1305,6 @@ function getIndexForKey(input, key) {
|
|
|
1293
1305
|
const lookup = input.reduce((acc, next, index) => (typeof next?._key == "string" && (acc[next._key] = index), acc), {});
|
|
1294
1306
|
return indexCache.set(input, lookup), lookup[key];
|
|
1295
1307
|
}
|
|
1296
|
-
function getDeep(input, path) {
|
|
1297
|
-
const [currentSegment, ...restOfPath] = path;
|
|
1298
|
-
if (currentSegment === void 0) return input;
|
|
1299
|
-
if (typeof input != "object" || input === null) return;
|
|
1300
|
-
let key;
|
|
1301
|
-
if (isKeySegment(currentSegment) ? key = getIndexForKey(input, currentSegment._key) : (typeof currentSegment == "string" || typeof currentSegment == "number") && (key = currentSegment), key === void 0) return;
|
|
1302
|
-
const nestedInput = typeof key == "number" && Array.isArray(input) ? input.at(key) : input[key];
|
|
1303
|
-
return getDeep(nestedInput, restOfPath);
|
|
1304
|
-
}
|
|
1305
1308
|
function setDeep(input, path, value) {
|
|
1306
1309
|
const [currentSegment, ...restOfPath] = path;
|
|
1307
1310
|
if (currentSegment === void 0) return value;
|
|
@@ -3262,125 +3265,6 @@ function Ae(e3, t2 = {}) {
|
|
|
3262
3265
|
if (r2.type === "error") throw new _e(r2.position);
|
|
3263
3266
|
return new K(e3, r2.marks, t2).process(me);
|
|
3264
3267
|
}
|
|
3265
|
-
const isRecord = (value) => typeof value == "object" && !!value && !Array.isArray(value), ignoredKeys = ["_id", "_type", "_createdAt", "_updatedAt", "_rev"];
|
|
3266
|
-
function diffPatch(before, after) {
|
|
3267
|
-
return diffRecursive(before, after, []);
|
|
3268
|
-
}
|
|
3269
|
-
function diffRecursive(before, after, path) {
|
|
3270
|
-
if (before === after) return [];
|
|
3271
|
-
const patches = [], pathStr = stringifyPath(path);
|
|
3272
|
-
if (before === null || after === null)
|
|
3273
|
-
return before !== after && patches.push({ set: { [pathStr]: after } }), patches;
|
|
3274
|
-
if (typeof before != typeof after || Array.isArray(before) !== Array.isArray(after))
|
|
3275
|
-
return patches.push({ set: { [pathStr]: after } }), patches;
|
|
3276
|
-
if (typeof before == "string" && typeof after == "string") {
|
|
3277
|
-
const dmpPatches = makePatches(before, after), patchStr = stringifyPatches(dmpPatches);
|
|
3278
|
-
return patches.push({ diffMatchPatch: { [pathStr]: patchStr } }), patches;
|
|
3279
|
-
}
|
|
3280
|
-
if (typeof before == "number" && typeof after == "number")
|
|
3281
|
-
return patches.push({ set: { [pathStr]: after } }), patches;
|
|
3282
|
-
if (typeof before != "object")
|
|
3283
|
-
return before !== after && patches.push({ set: { [pathStr]: after } }), patches;
|
|
3284
|
-
if (Array.isArray(before) && Array.isArray(after))
|
|
3285
|
-
return patches.push(...diffArray(before, after, path)), patches;
|
|
3286
|
-
if (!isRecord(after) || !isRecord(before)) return patches;
|
|
3287
|
-
const beforeKeys = Object.keys(before).filter((k2) => !ignoredKeys.includes(k2)), afterKeys = Object.keys(after).filter((k2) => !ignoredKeys.includes(k2)), allKeys = /* @__PURE__ */ new Set([...beforeKeys, ...afterKeys]);
|
|
3288
|
-
for (const key of allKeys) {
|
|
3289
|
-
const subPath = [...path, key];
|
|
3290
|
-
key in after ? key in before ? patches.push(...diffRecursive(before[key], after[key], subPath)) : patches.push({ set: { [stringifyPath(subPath)]: after[key] } }) : patches.push({ unset: [stringifyPath(subPath)] });
|
|
3291
|
-
}
|
|
3292
|
-
return patches;
|
|
3293
|
-
}
|
|
3294
|
-
function diffArray(beforeArr, afterArr, path) {
|
|
3295
|
-
const pathStr = stringifyPath(path), isKeyedArray = (arr) => arr.every((item) => isKeyedObject(item));
|
|
3296
|
-
if (isKeyedArray(beforeArr) && isKeyedArray(afterArr)) {
|
|
3297
|
-
if (beforeArr.length === 0 && afterArr.length > 0)
|
|
3298
|
-
return [
|
|
3299
|
-
{
|
|
3300
|
-
insert: {
|
|
3301
|
-
before: stringifyPath([...path, 0]),
|
|
3302
|
-
items: afterArr
|
|
3303
|
-
}
|
|
3304
|
-
}
|
|
3305
|
-
];
|
|
3306
|
-
const unsetPatches = [], diffPatches = [], insertPatches = [], beforeMap = /* @__PURE__ */ new Map();
|
|
3307
|
-
beforeArr.forEach((item, index) => {
|
|
3308
|
-
beforeMap.set(item._key, { item, index });
|
|
3309
|
-
});
|
|
3310
|
-
const afterMap = /* @__PURE__ */ new Map();
|
|
3311
|
-
afterArr.forEach((item, index) => {
|
|
3312
|
-
afterMap.set(item._key, { item, index });
|
|
3313
|
-
});
|
|
3314
|
-
for (const [key] of beforeMap.entries())
|
|
3315
|
-
afterMap.has(key) || unsetPatches.push({ unset: [stringifyPath([...path, { _key: key }])] });
|
|
3316
|
-
for (const [key, { item: afterItem }] of afterMap.entries())
|
|
3317
|
-
beforeMap.has(key) && diffPatches.push(
|
|
3318
|
-
...diffRecursive(beforeMap.get(key).item, afterItem, [...path, { _key: key }])
|
|
3319
|
-
);
|
|
3320
|
-
let newItemsGroup = [], insertPosition = null;
|
|
3321
|
-
for (let i2 = 0; i2 < afterArr.length; i2++) {
|
|
3322
|
-
const item = afterArr[i2];
|
|
3323
|
-
if (beforeMap.has(item._key))
|
|
3324
|
-
newItemsGroup.length > 0 && insertPosition && (insertPosition.op === "before" ? insertPatches.push({
|
|
3325
|
-
insert: {
|
|
3326
|
-
before: stringifyPath([...path, { _key: insertPosition.refKey }]),
|
|
3327
|
-
items: newItemsGroup
|
|
3328
|
-
}
|
|
3329
|
-
}) : insertPatches.push({
|
|
3330
|
-
insert: {
|
|
3331
|
-
after: stringifyPath([...path, { _key: insertPosition.refKey }]),
|
|
3332
|
-
items: newItemsGroup
|
|
3333
|
-
}
|
|
3334
|
-
}), newItemsGroup = [], insertPosition = null);
|
|
3335
|
-
else {
|
|
3336
|
-
if (newItemsGroup.length === 0)
|
|
3337
|
-
if (i2 === 0) {
|
|
3338
|
-
let j2 = i2;
|
|
3339
|
-
for (; j2 < afterArr.length && !beforeMap.has(afterArr[j2]._key); )
|
|
3340
|
-
j2++;
|
|
3341
|
-
j2 < afterArr.length ? insertPosition = { op: "before", refKey: afterArr[j2]._key } : beforeArr.length > 0 && (insertPosition = { op: "after", refKey: beforeArr[beforeArr.length - 1]._key });
|
|
3342
|
-
} else {
|
|
3343
|
-
let j2 = i2 - 1;
|
|
3344
|
-
for (; j2 >= 0 && !beforeMap.has(afterArr[j2]._key); )
|
|
3345
|
-
j2--;
|
|
3346
|
-
if (j2 >= 0)
|
|
3347
|
-
insertPosition = { op: "after", refKey: afterArr[j2]._key };
|
|
3348
|
-
else {
|
|
3349
|
-
let k2 = i2;
|
|
3350
|
-
for (; k2 < afterArr.length && !beforeMap.has(afterArr[k2]._key); )
|
|
3351
|
-
k2++;
|
|
3352
|
-
k2 < afterArr.length && (insertPosition = { op: "before", refKey: afterArr[k2]._key });
|
|
3353
|
-
}
|
|
3354
|
-
}
|
|
3355
|
-
newItemsGroup.push(item);
|
|
3356
|
-
}
|
|
3357
|
-
}
|
|
3358
|
-
return newItemsGroup.length > 0 && insertPosition && (insertPosition.op === "after" ? insertPatches.push({
|
|
3359
|
-
insert: {
|
|
3360
|
-
after: stringifyPath([...path, { _key: insertPosition.refKey }]),
|
|
3361
|
-
items: newItemsGroup
|
|
3362
|
-
}
|
|
3363
|
-
}) : insertPatches.push({
|
|
3364
|
-
insert: {
|
|
3365
|
-
before: stringifyPath([...path, { _key: insertPosition.refKey }]),
|
|
3366
|
-
items: newItemsGroup
|
|
3367
|
-
}
|
|
3368
|
-
})), afterArr.every((item) => !beforeMap.has(item._key)) ? [...insertPatches, ...unsetPatches, ...diffPatches] : [...unsetPatches, ...diffPatches, ...insertPatches];
|
|
3369
|
-
} else {
|
|
3370
|
-
const patches = [], minLength = Math.min(beforeArr.length, afterArr.length);
|
|
3371
|
-
for (let i2 = 0; i2 < minLength; i2++)
|
|
3372
|
-
patches.push(...diffRecursive(beforeArr[i2], afterArr[i2], [...path, i2]));
|
|
3373
|
-
for (let i2 = afterArr.length; i2 < beforeArr.length; i2++)
|
|
3374
|
-
patches.push({ unset: [stringifyPath([...path, i2])] });
|
|
3375
|
-
if (afterArr.length > beforeArr.length) {
|
|
3376
|
-
const newItems = afterArr.slice(beforeArr.length);
|
|
3377
|
-
beforeArr.length > 0 ? patches.push({
|
|
3378
|
-
insert: { after: stringifyPath([...path, beforeArr.length - 1]), items: newItems }
|
|
3379
|
-
}) : patches.push({ set: { [pathStr]: afterArr } });
|
|
3380
|
-
}
|
|
3381
|
-
return patches;
|
|
3382
|
-
}
|
|
3383
|
-
}
|
|
3384
3268
|
class MultiKeyWeakMap {
|
|
3385
3269
|
// The root of our nested WeakMap structure.
|
|
3386
3270
|
#rootMap = /* @__PURE__ */ new WeakMap();
|
|
@@ -3677,7 +3561,7 @@ function processActions({
|
|
|
3677
3561
|
mutations: baseMutations,
|
|
3678
3562
|
timestamp
|
|
3679
3563
|
});
|
|
3680
|
-
const baseAfter = base[draftId], patches =
|
|
3564
|
+
const baseAfter = base[draftId], patches = diffValue(baseBefore, baseAfter), workingMutations = [];
|
|
3681
3565
|
if (!working[draftId] && working[publishedId]) {
|
|
3682
3566
|
const newDraftFromPublished = { ...working[publishedId], _id: draftId };
|
|
3683
3567
|
if (!checkGrant(grants.create, newDraftFromPublished))
|
|
@@ -4220,9 +4104,10 @@ const _getDocumentState = bindActionByDataset(
|
|
|
4220
4104
|
selector: ({ state: { error, documentStates } }, options) => {
|
|
4221
4105
|
const { documentId, path } = options;
|
|
4222
4106
|
if (error) throw error;
|
|
4223
|
-
const draftId = getDraftId(documentId), publishedId = getPublishedId$1(documentId), draft = documentStates[draftId]?.local, published = documentStates[publishedId]?.local
|
|
4224
|
-
if (
|
|
4225
|
-
|
|
4107
|
+
const draftId = getDraftId(documentId), publishedId = getPublishedId$1(documentId), draft = documentStates[draftId]?.local, published = documentStates[publishedId]?.local;
|
|
4108
|
+
if (draft === void 0 || published === void 0) return;
|
|
4109
|
+
const document = draft ?? published;
|
|
4110
|
+
return path ? jsonMatch(document, path).at(0)?.value : document;
|
|
4226
4111
|
},
|
|
4227
4112
|
onSubscribe: (context, options) => manageSubscriberIds(context, options.documentId)
|
|
4228
4113
|
})
|
|
@@ -4555,7 +4440,7 @@ function sortReleases(releases = []) {
|
|
|
4555
4440
|
return a2.metadata.releaseType === "asap" && b2.metadata.releaseType !== "asap" ? 1 : a2.metadata.releaseType !== "asap" && b2.metadata.releaseType === "asap" ? -1 : a2.metadata.releaseType === "asap" && b2.metadata.releaseType === "asap" ? new Date(b2._createdAt).getTime() - new Date(a2._createdAt).getTime() : 0;
|
|
4556
4441
|
});
|
|
4557
4442
|
}
|
|
4558
|
-
const releasesStore = {
|
|
4443
|
+
const ARCHIVED_RELEASE_STATES = ["archived", "published"], releasesStore = {
|
|
4559
4444
|
name: "Releases",
|
|
4560
4445
|
getInitialState: () => ({
|
|
4561
4446
|
activeReleases: void 0
|
|
@@ -4569,7 +4454,7 @@ const releasesStore = {
|
|
|
4569
4454
|
createStateSourceAction({
|
|
4570
4455
|
selector: ({ state }) => state.activeReleases
|
|
4571
4456
|
})
|
|
4572
|
-
), RELEASES_QUERY =
|
|
4457
|
+
), RELEASES_QUERY = "releases::all()", QUERY_PARAMS = {}, subscribeToReleases = ({ instance, state }) => getClientState(instance, {
|
|
4573
4458
|
apiVersion: "2025-04-10",
|
|
4574
4459
|
perspective: "raw"
|
|
4575
4460
|
}).observable.pipe(
|
|
@@ -4591,7 +4476,9 @@ const releasesStore = {
|
|
|
4591
4476
|
)
|
|
4592
4477
|
).subscribe({
|
|
4593
4478
|
next: (releases) => {
|
|
4594
|
-
state.set("setActiveReleases", {
|
|
4479
|
+
state.set("setActiveReleases", {
|
|
4480
|
+
activeReleases: sortReleases(releases ?? []).filter((release) => !ARCHIVED_RELEASE_STATES.includes(release.state)).reverse()
|
|
4481
|
+
});
|
|
4595
4482
|
}
|
|
4596
4483
|
});
|
|
4597
4484
|
function isReleasePerspective(perspective) {
|
|
@@ -4617,7 +4504,7 @@ const DEFAULT_PERSPECTIVE = "drafts", optionsCache = /* @__PURE__ */ new Map(),
|
|
|
4617
4504
|
const perspective = memoizedOptions?.perspective ?? instancePerspective ?? DEFAULT_PERSPECTIVE;
|
|
4618
4505
|
if (!isReleasePerspective(perspective)) return perspective;
|
|
4619
4506
|
if (!activeReleases || activeReleases.length === 0) return;
|
|
4620
|
-
const releaseNames = activeReleases.map((release) => release.name), index = releaseNames.findIndex((name) => name === perspective.releaseName);
|
|
4507
|
+
const releaseNames = sortReleases(activeReleases).map((release) => release.name), index = releaseNames.findIndex((name) => name === perspective.releaseName);
|
|
4621
4508
|
if (index < 0)
|
|
4622
4509
|
throw new Error(`Release "${perspective.releaseName}" not found in active releases`);
|
|
4623
4510
|
return ["drafts", ...releaseNames.slice(0, index + 1)].filter(
|
|
@@ -4876,11 +4763,11 @@ function processPreviewQuery({
|
|
|
4876
4763
|
title: String(title || `${result._type}: ${result._id}`),
|
|
4877
4764
|
subtitle: subtitle || void 0,
|
|
4878
4765
|
media: normalizeMedia(result.media, projectId, dataset)
|
|
4879
|
-
},
|
|
4766
|
+
}, _status = {
|
|
4880
4767
|
...draftResult?._updatedAt && { lastEditedDraftAt: draftResult._updatedAt },
|
|
4881
4768
|
...publishedResult?._updatedAt && { lastEditedPublishedAt: publishedResult._updatedAt }
|
|
4882
4769
|
};
|
|
4883
|
-
return [id, { data: { ...preview,
|
|
4770
|
+
return [id, { data: { ...preview, _status }, isPending: !1 }];
|
|
4884
4771
|
} catch (e3) {
|
|
4885
4772
|
return console.warn(e3), [id, STABLE_ERROR_PREVIEW];
|
|
4886
4773
|
}
|
|
@@ -5037,12 +4924,12 @@ function processProjectionQuery({ ids, results }) {
|
|
|
5037
4924
|
finalValues[originalId][hash] = { data: null, isPending: !1 };
|
|
5038
4925
|
continue;
|
|
5039
4926
|
}
|
|
5040
|
-
const
|
|
4927
|
+
const _status = {
|
|
5041
4928
|
...draft?._updatedAt && { lastEditedDraftAt: draft._updatedAt },
|
|
5042
4929
|
...published?._updatedAt && { lastEditedPublishedAt: published._updatedAt }
|
|
5043
4930
|
};
|
|
5044
4931
|
finalValues[originalId][hash] = {
|
|
5045
|
-
data: { ...projectionResultData,
|
|
4932
|
+
data: { ...projectionResultData, _status },
|
|
5046
4933
|
isPending: !1
|
|
5047
4934
|
};
|
|
5048
4935
|
}
|
|
@@ -5405,7 +5292,7 @@ function createGroqSearchFilter(query) {
|
|
|
5405
5292
|
`${finalIncrementalToken}${WILDCARD_TOKEN}`
|
|
5406
5293
|
), `[@] match text::query("${processedTokens.join(" ").replace(/"/g, '\\"')}")`;
|
|
5407
5294
|
}
|
|
5408
|
-
var version = "
|
|
5295
|
+
var version = "2.0.1";
|
|
5409
5296
|
const CORE_SDK_VERSION = getEnv("PKG_VERSION") || `${version}-development`;
|
|
5410
5297
|
export {
|
|
5411
5298
|
AuthStateType,
|
|
@@ -5432,10 +5319,12 @@ export {
|
|
|
5432
5319
|
getDocumentState,
|
|
5433
5320
|
getDocumentSyncStatus,
|
|
5434
5321
|
getFavoritesState,
|
|
5322
|
+
getIsInDashboardState,
|
|
5435
5323
|
getLoginUrlState,
|
|
5436
5324
|
getNodeState,
|
|
5437
5325
|
getOrCreateChannel,
|
|
5438
5326
|
getOrCreateController,
|
|
5327
|
+
getOrCreateNode,
|
|
5439
5328
|
getPermissionsState,
|
|
5440
5329
|
getPerspectiveState,
|
|
5441
5330
|
getPreviewState,
|
|
@@ -5456,6 +5345,7 @@ export {
|
|
|
5456
5345
|
parseUsersKey,
|
|
5457
5346
|
publishDocument,
|
|
5458
5347
|
releaseChannel,
|
|
5348
|
+
releaseNode,
|
|
5459
5349
|
resolveDatasets,
|
|
5460
5350
|
resolveDocument,
|
|
5461
5351
|
resolveFavoritesState,
|
|
@@ -5466,6 +5356,7 @@ export {
|
|
|
5466
5356
|
resolveProjects,
|
|
5467
5357
|
resolveQuery,
|
|
5468
5358
|
resolveUsers,
|
|
5359
|
+
setAuthToken,
|
|
5469
5360
|
subscribeDocumentEvents,
|
|
5470
5361
|
unpublishDocument
|
|
5471
5362
|
};
|