@sanity/sdk 2.1.2 → 2.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/dist/index.d.ts +14 -2
- package/dist/index.js +32 -12
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/projects/projects.test.ts +36 -1
- package/src/projects/projects.ts +15 -3
- package/src/query/queryStore.test.ts +86 -0
- package/src/query/queryStore.ts +34 -7
- package/src/query/queryStoreConstants.ts +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -1796,9 +1796,21 @@ declare function resolveProjection<TProjection extends ValidProjection = ValidPr
|
|
|
1796
1796
|
/** @beta */
|
|
1797
1797
|
declare function resolveProjection<TData extends object>(instance: SanityInstance, options: ProjectionOptions): Promise<ProjectionValuePending<TData>>;
|
|
1798
1798
|
/** @public */
|
|
1799
|
-
declare const getProjectsState: BoundStoreAction<FetcherStoreState<[
|
|
1799
|
+
declare const getProjectsState: BoundStoreAction<FetcherStoreState<[options?: {
|
|
1800
|
+
organizationId?: string;
|
|
1801
|
+
includeMembers?: boolean;
|
|
1802
|
+
} | undefined], Omit<_sanity_client12.SanityProject, "members">[]>, [options?: {
|
|
1803
|
+
organizationId?: string;
|
|
1804
|
+
includeMembers?: boolean;
|
|
1805
|
+
} | undefined], StateSource<Omit<_sanity_client12.SanityProject, "members">[] | undefined>>;
|
|
1800
1806
|
/** @public */
|
|
1801
|
-
declare const resolveProjects: BoundStoreAction<FetcherStoreState<[
|
|
1807
|
+
declare const resolveProjects: BoundStoreAction<FetcherStoreState<[options?: {
|
|
1808
|
+
organizationId?: string;
|
|
1809
|
+
includeMembers?: boolean;
|
|
1810
|
+
} | undefined], Omit<_sanity_client12.SanityProject, "members">[]>, [options?: {
|
|
1811
|
+
organizationId?: string;
|
|
1812
|
+
includeMembers?: boolean;
|
|
1813
|
+
} | undefined], Promise<Omit<_sanity_client12.SanityProject, "members">[]>>;
|
|
1802
1814
|
/**
|
|
1803
1815
|
* @beta
|
|
1804
1816
|
*/
|
package/dist/index.js
CHANGED
|
@@ -4812,7 +4812,7 @@ const DEFAULT_PERSPECTIVE = "drafts", optionsCache = /* @__PURE__ */ new Map(),
|
|
|
4812
4812
|
}
|
|
4813
4813
|
)
|
|
4814
4814
|
})
|
|
4815
|
-
), QUERY_STATE_CLEAR_DELAY = 1e3, QUERY_STORE_API_VERSION = "v2025-05-06", setQueryError = (key, error) => (prev) => {
|
|
4815
|
+
), QUERY_STATE_CLEAR_DELAY = 1e3, QUERY_STORE_API_VERSION = "v2025-05-06", QUERY_STORE_DEFAULT_PERSPECTIVE = "drafts", setQueryError = (key, error) => (prev) => {
|
|
4816
4816
|
const prevQuery = prev.queries[key];
|
|
4817
4817
|
return prevQuery ? { ...prev, queries: { ...prev.queries, [key]: { ...prevQuery, error } } } : prev;
|
|
4818
4818
|
}, setQueryData = (key, result, syncTags) => (prev) => {
|
|
@@ -4835,7 +4835,16 @@ const DEFAULT_PERSPECTIVE = "drafts", optionsCache = /* @__PURE__ */ new Map(),
|
|
|
4835
4835
|
}, cancelQuery = (key) => (prev) => {
|
|
4836
4836
|
const prevQuery = prev.queries[key];
|
|
4837
4837
|
return !prevQuery || prevQuery.subscribers.length ? prev : { ...prev, queries: omit(prev.queries, key) };
|
|
4838
|
-
}, initializeQuery = (key) => (prev) => prev.queries[key] ? prev : { ...prev, queries: { ...prev.queries, [key]: { subscribers: [] } } }, EMPTY_ARRAY = [], getQueryKey = (options) => JSON.stringify(options), parseQueryKey = (key) => JSON.parse(key)
|
|
4838
|
+
}, initializeQuery = (key) => (prev) => prev.queries[key] ? prev : { ...prev, queries: { ...prev.queries, [key]: { subscribers: [] } } }, EMPTY_ARRAY = [], getQueryKey = (options) => JSON.stringify(options), parseQueryKey = (key) => JSON.parse(key);
|
|
4839
|
+
function normalizeOptionsWithPerspective(instance, options) {
|
|
4840
|
+
if (options.perspective !== void 0) return options;
|
|
4841
|
+
const instancePerspective = instance.config.perspective;
|
|
4842
|
+
return {
|
|
4843
|
+
...options,
|
|
4844
|
+
perspective: instancePerspective !== void 0 ? instancePerspective : QUERY_STORE_DEFAULT_PERSPECTIVE
|
|
4845
|
+
};
|
|
4846
|
+
}
|
|
4847
|
+
const queryStore = {
|
|
4839
4848
|
name: "QueryStore",
|
|
4840
4849
|
getInitialState: () => ({ queries: {} }),
|
|
4841
4850
|
initialize(context) {
|
|
@@ -4939,14 +4948,14 @@ function getQueryState(...args) {
|
|
|
4939
4948
|
const _getQueryState = bindActionByDataset(
|
|
4940
4949
|
queryStore,
|
|
4941
4950
|
createStateSourceAction({
|
|
4942
|
-
selector: ({ state }, options) => {
|
|
4951
|
+
selector: ({ state, instance }, options) => {
|
|
4943
4952
|
if (state.error) throw state.error;
|
|
4944
|
-
const key = getQueryKey(options), queryState = state.queries[key];
|
|
4953
|
+
const key = getQueryKey(normalizeOptionsWithPerspective(instance, options)), queryState = state.queries[key];
|
|
4945
4954
|
if (queryState?.error) throw queryState.error;
|
|
4946
4955
|
return queryState?.result;
|
|
4947
4956
|
},
|
|
4948
|
-
onSubscribe: ({ state }, options) => {
|
|
4949
|
-
const subscriptionId = insecureRandomId(), key = getQueryKey(options);
|
|
4957
|
+
onSubscribe: ({ state, instance }, options) => {
|
|
4958
|
+
const subscriptionId = insecureRandomId(), key = getQueryKey(normalizeOptionsWithPerspective(instance, options));
|
|
4950
4959
|
return state.set("addSubscriber", addSubscriber(key, subscriptionId)), () => {
|
|
4951
4960
|
setTimeout(
|
|
4952
4961
|
() => state.set("removeSubscriber", removeSubscriber(key, subscriptionId)),
|
|
@@ -4962,7 +4971,7 @@ function resolveQuery(...args) {
|
|
|
4962
4971
|
const _resolveQuery = bindActionByDataset(
|
|
4963
4972
|
queryStore,
|
|
4964
4973
|
({ state, instance }, { signal, ...options }) => {
|
|
4965
|
-
const { getCurrent } = getQueryState(instance,
|
|
4974
|
+
const normalized = normalizeOptionsWithPerspective(instance, options), { getCurrent } = getQueryState(instance, normalized), key = getQueryKey(normalized), aborted$ = signal ? new Observable((observer) => {
|
|
4966
4975
|
const cleanup = () => {
|
|
4967
4976
|
signal.removeEventListener("abort", listener);
|
|
4968
4977
|
}, listener = () => {
|
|
@@ -5418,12 +5427,23 @@ const _resolveProjection = bindActionByDataset(
|
|
|
5418
5427
|
)
|
|
5419
5428
|
), API_VERSION = "v2025-02-19", projects = createFetcherStore({
|
|
5420
5429
|
name: "Projects",
|
|
5421
|
-
getKey: () =>
|
|
5422
|
-
|
|
5430
|
+
getKey: (_instance, options) => {
|
|
5431
|
+
const orgKey = options?.organizationId ? `:org:${options.organizationId}` : "", membersKey = options?.includeMembers === !1 ? ":no-members" : "";
|
|
5432
|
+
return `projects${orgKey}${membersKey}`;
|
|
5433
|
+
},
|
|
5434
|
+
fetcher: (instance) => (options) => getClientState(instance, {
|
|
5423
5435
|
apiVersion: API_VERSION,
|
|
5424
|
-
scope: "global"
|
|
5436
|
+
scope: "global",
|
|
5437
|
+
requestTagPrefix: "sanity.sdk.projects"
|
|
5425
5438
|
}).observable.pipe(
|
|
5426
|
-
switchMap((client) =>
|
|
5439
|
+
switchMap((client) => {
|
|
5440
|
+
const organizationId = options?.organizationId;
|
|
5441
|
+
return client.observable.projects.list({
|
|
5442
|
+
// client method has a type that expects false | undefined
|
|
5443
|
+
includeMembers: options?.includeMembers ? void 0 : !1,
|
|
5444
|
+
organizationId
|
|
5445
|
+
});
|
|
5446
|
+
})
|
|
5427
5447
|
)
|
|
5428
5448
|
}), getProjectsState = projects.getState, resolveProjects = projects.resolveState, WILDCARD_TOKEN = "*", NEGATION_TOKEN = "-", TOKEN_REGEX = /(?:[^\s"]+|"[^"]*")+/g;
|
|
5429
5449
|
function isNegationToken(token) {
|
|
@@ -5501,7 +5521,7 @@ function validateFilter(filter2, index) {
|
|
|
5501
5521
|
`${filterContext}: when using wildcard '*', it must be the only type in the array`
|
|
5502
5522
|
);
|
|
5503
5523
|
}
|
|
5504
|
-
var version = "2.
|
|
5524
|
+
var version = "2.2.0";
|
|
5505
5525
|
const CORE_SDK_VERSION = getEnv("PKG_VERSION") || `${version}-development`;
|
|
5506
5526
|
export {
|
|
5507
5527
|
AuthStateType,
|