@sanity-labs/client-fake-for-test 0.0.0 → 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/LICENSE +21 -0
- package/dist/index.cjs +435 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +226 -26
- package/dist/index.d.ts +226 -26
- package/dist/index.js +436 -66
- package/dist/index.js.map +1 -1
- package/package.json +9 -20
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export declare type Action = ReleaseAction | VersionAction;
|
|
2
|
+
|
|
3
|
+
export declare interface ActionResult {
|
|
4
|
+
transactionId: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
1
7
|
/**
|
|
2
8
|
* Apply an ordered list of patch ops to a document, returning the new doc.
|
|
3
9
|
*
|
|
@@ -16,6 +22,19 @@ export declare function applyPatchOps(
|
|
|
16
22
|
ops: PatchOp[],
|
|
17
23
|
): SanityDocument;
|
|
18
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Apply a perspective to a raw set of documents and return the view
|
|
27
|
+
* groq-js should evaluate against.
|
|
28
|
+
*
|
|
29
|
+
* For non-raw perspectives, each output document for a non-system id
|
|
30
|
+
* gets `_id` projected to its published id and `_originalId` carrying
|
|
31
|
+
* the source id (matching the wire shape of the real Content Lake).
|
|
32
|
+
*/
|
|
33
|
+
export declare function applyPerspective(
|
|
34
|
+
docs: readonly SanityDocument[],
|
|
35
|
+
perspective: Perspective,
|
|
36
|
+
): SanityDocument[];
|
|
37
|
+
|
|
19
38
|
export declare function createPatch(
|
|
20
39
|
documentId: string,
|
|
21
40
|
executor: PatchExecutor,
|
|
@@ -65,6 +84,13 @@ export declare interface CreateTestClientOptions {
|
|
|
65
84
|
* unconditionally — the legacy behavior.
|
|
66
85
|
*/
|
|
67
86
|
accessControl?: TestClientAccessControl;
|
|
87
|
+
/**
|
|
88
|
+
* Default perspective applied to reads. Per-fetch `options.perspective`
|
|
89
|
+
* overrides this. `withConfig({ perspective })` returns a sibling
|
|
90
|
+
* handle with a different default. Defaults to `"raw"` so existing
|
|
91
|
+
* tests stay green.
|
|
92
|
+
*/
|
|
93
|
+
perspective?: Perspective;
|
|
68
94
|
}
|
|
69
95
|
|
|
70
96
|
/**
|
|
@@ -102,6 +128,18 @@ export declare function defaultAclPath(
|
|
|
102
128
|
dataset: string,
|
|
103
129
|
): string;
|
|
104
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Document body accepted by `version.create` / `createVersion`. The id
|
|
133
|
+
* is derived from `releaseId + publishedId` so callers may omit `_id`
|
|
134
|
+
* here. `version.replace` requires `_id` since it identifies the doc
|
|
135
|
+
* to replace.
|
|
136
|
+
*/
|
|
137
|
+
export declare interface DocumentBody {
|
|
138
|
+
_id?: string;
|
|
139
|
+
_type: string;
|
|
140
|
+
[field: string]: unknown;
|
|
141
|
+
}
|
|
142
|
+
|
|
105
143
|
export declare type DocumentValuePermission = "create" | "read" | "update";
|
|
106
144
|
|
|
107
145
|
/**
|
|
@@ -125,11 +163,46 @@ export declare function evaluateWriteAccess(args: {
|
|
|
125
163
|
matchingGrants: number;
|
|
126
164
|
}>;
|
|
127
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Data-plane subset of `@sanity/client`'s surface, with multi-dataset support.
|
|
168
|
+
*
|
|
169
|
+
* One `createTestClient()` call creates a registry of stores keyed by
|
|
170
|
+
* `(projectId, dataset)`. The returned client points at one of them.
|
|
171
|
+
* `withConfig({ projectId, dataset })` returns a new handle into the same
|
|
172
|
+
* registry but pointing at a different store — useful for workflows where
|
|
173
|
+
* definitions live in one dataset and instances live in another.
|
|
174
|
+
*
|
|
175
|
+
* Two separate `createTestClient()` calls have separate registries, so
|
|
176
|
+
* tests stay isolated from each other.
|
|
177
|
+
*
|
|
178
|
+
* Methods not on the real client:
|
|
179
|
+
*
|
|
180
|
+
* - `seed`, `add`, `reset`, `snapshot`, `store` — bulk-load helpers,
|
|
181
|
+
* scoped to the current dataset.
|
|
182
|
+
* - `datasets()` — lists known dataset keys in this registry.
|
|
183
|
+
*
|
|
184
|
+
* Methods deliberately omitted:
|
|
185
|
+
*
|
|
186
|
+
* - Project / agent / asset / live / listen APIs.
|
|
187
|
+
*/
|
|
188
|
+
export declare interface FetchOptions {
|
|
189
|
+
/** Override the client's configured perspective for this read. */
|
|
190
|
+
perspective?: Perspective;
|
|
191
|
+
}
|
|
192
|
+
|
|
128
193
|
export declare interface Grant {
|
|
129
194
|
filter: string;
|
|
130
195
|
permissions: DocumentValuePermission[];
|
|
131
196
|
}
|
|
132
197
|
|
|
198
|
+
export declare const isDraftId: (id: string) => boolean;
|
|
199
|
+
|
|
200
|
+
export declare const isReleaseDocId: (id: string) => boolean;
|
|
201
|
+
|
|
202
|
+
export declare const isSystemId: (id: string) => boolean;
|
|
203
|
+
|
|
204
|
+
export declare const isVersionId: (id: string) => boolean;
|
|
205
|
+
|
|
133
206
|
export declare interface MutationOptions {
|
|
134
207
|
ifRevisionId?: string;
|
|
135
208
|
}
|
|
@@ -197,6 +270,107 @@ export declare type PatchOp =
|
|
|
197
270
|
items: unknown[];
|
|
198
271
|
};
|
|
199
272
|
|
|
273
|
+
export declare type Perspective = "raw" | "published" | "drafts" | string[];
|
|
274
|
+
|
|
275
|
+
/** Strip `drafts.` / `versions.<name>.` prefix to recover the published id. */
|
|
276
|
+
export declare function publishedIdOf(id: string): string;
|
|
277
|
+
|
|
278
|
+
export declare type ReleaseAction =
|
|
279
|
+
| {
|
|
280
|
+
actionType: "sanity.action.release.create";
|
|
281
|
+
releaseId: string;
|
|
282
|
+
metadata?: Partial<ReleaseMetadata>;
|
|
283
|
+
}
|
|
284
|
+
| {
|
|
285
|
+
actionType: "sanity.action.release.edit";
|
|
286
|
+
releaseId: string;
|
|
287
|
+
patch: {
|
|
288
|
+
set?: Record<string, unknown>;
|
|
289
|
+
unset?: string[];
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
| {
|
|
293
|
+
actionType: "sanity.action.release.schedule";
|
|
294
|
+
releaseId: string;
|
|
295
|
+
publishAt: string;
|
|
296
|
+
}
|
|
297
|
+
| {
|
|
298
|
+
actionType: "sanity.action.release.unschedule";
|
|
299
|
+
releaseId: string;
|
|
300
|
+
}
|
|
301
|
+
| {
|
|
302
|
+
actionType: "sanity.action.release.publish";
|
|
303
|
+
releaseId: string;
|
|
304
|
+
}
|
|
305
|
+
| {
|
|
306
|
+
actionType: "sanity.action.release.archive";
|
|
307
|
+
releaseId: string;
|
|
308
|
+
}
|
|
309
|
+
| {
|
|
310
|
+
actionType: "sanity.action.release.unarchive";
|
|
311
|
+
releaseId: string;
|
|
312
|
+
}
|
|
313
|
+
| {
|
|
314
|
+
actionType: "sanity.action.release.delete";
|
|
315
|
+
releaseId: string;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
export declare interface ReleaseDocument extends SanityDocument {
|
|
319
|
+
_type: "system.release";
|
|
320
|
+
name: string;
|
|
321
|
+
state: ReleaseState;
|
|
322
|
+
metadata: ReleaseMetadata;
|
|
323
|
+
publishAt?: string;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export declare interface ReleaseMetadata {
|
|
327
|
+
title?: string;
|
|
328
|
+
description?: string;
|
|
329
|
+
releaseType?: ReleaseType;
|
|
330
|
+
intendedPublishAt?: string;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** Extract the release name from a `versions.<name>.<id>` id, else undefined. */
|
|
334
|
+
export declare function releaseNameOf(id: string): string | undefined;
|
|
335
|
+
|
|
336
|
+
export declare interface ReleasesHandle {
|
|
337
|
+
create: (params: {
|
|
338
|
+
releaseId: string;
|
|
339
|
+
metadata?: Partial<ReleaseMetadata>;
|
|
340
|
+
}) => Promise<
|
|
341
|
+
ActionResult & {
|
|
342
|
+
releaseId: string;
|
|
343
|
+
metadata: ReleaseMetadata;
|
|
344
|
+
}
|
|
345
|
+
>;
|
|
346
|
+
edit: (params: {
|
|
347
|
+
releaseId: string;
|
|
348
|
+
patch: {
|
|
349
|
+
set?: Record<string, unknown>;
|
|
350
|
+
unset?: string[];
|
|
351
|
+
};
|
|
352
|
+
}) => Promise<ActionResult>;
|
|
353
|
+
get: (params: { releaseId: string }) => Promise<ReleaseDocument | undefined>;
|
|
354
|
+
fetchDocuments: (params: { releaseId: string }) => Promise<SanityDocument[]>;
|
|
355
|
+
schedule: (params: {
|
|
356
|
+
releaseId: string;
|
|
357
|
+
publishAt: string;
|
|
358
|
+
}) => Promise<ActionResult>;
|
|
359
|
+
unschedule: (params: { releaseId: string }) => Promise<ActionResult>;
|
|
360
|
+
publish: (params: { releaseId: string }) => Promise<ActionResult>;
|
|
361
|
+
archive: (params: { releaseId: string }) => Promise<ActionResult>;
|
|
362
|
+
unarchive: (params: { releaseId: string }) => Promise<ActionResult>;
|
|
363
|
+
delete: (params: { releaseId: string }) => Promise<ActionResult>;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export declare type ReleaseState =
|
|
367
|
+
| "active"
|
|
368
|
+
| "scheduled"
|
|
369
|
+
| "published"
|
|
370
|
+
| "archived";
|
|
371
|
+
|
|
372
|
+
export declare type ReleaseType = "asap" | "scheduled" | "undecided";
|
|
373
|
+
|
|
200
374
|
/** @public */
|
|
201
375
|
declare interface SanityDocument {
|
|
202
376
|
_id: string;
|
|
@@ -232,36 +406,20 @@ export declare interface SystemFields {
|
|
|
232
406
|
_updatedAt: string;
|
|
233
407
|
}
|
|
234
408
|
|
|
235
|
-
/**
|
|
236
|
-
* Data-plane subset of `@sanity/client`'s surface, with multi-dataset support.
|
|
237
|
-
*
|
|
238
|
-
* One `createTestClient()` call creates a registry of stores keyed by
|
|
239
|
-
* `(projectId, dataset)`. The returned client points at one of them.
|
|
240
|
-
* `withConfig({ projectId, dataset })` returns a new handle into the same
|
|
241
|
-
* registry but pointing at a different store — useful for workflows where
|
|
242
|
-
* definitions live in one dataset and instances live in another.
|
|
243
|
-
*
|
|
244
|
-
* Two separate `createTestClient()` calls have separate registries, so
|
|
245
|
-
* tests stay isolated from each other.
|
|
246
|
-
*
|
|
247
|
-
* Methods not on the real client:
|
|
248
|
-
*
|
|
249
|
-
* - `seed`, `add`, `reset`, `snapshot`, `store` — bulk-load helpers,
|
|
250
|
-
* scoped to the current dataset.
|
|
251
|
-
* - `datasets()` — lists known dataset keys in this registry.
|
|
252
|
-
*
|
|
253
|
-
* Methods deliberately omitted:
|
|
254
|
-
*
|
|
255
|
-
* - Project / agent / asset / live / listen APIs.
|
|
256
|
-
* - Perspective handling.
|
|
257
|
-
*/
|
|
258
409
|
export declare interface TestClient {
|
|
259
410
|
fetch: <T = unknown>(
|
|
260
411
|
query: string,
|
|
261
412
|
params?: Record<string, unknown>,
|
|
413
|
+
options?: FetchOptions,
|
|
262
414
|
) => Promise<T>;
|
|
263
|
-
getDocument: <T = SanityDocument>(
|
|
264
|
-
|
|
415
|
+
getDocument: <T = SanityDocument>(
|
|
416
|
+
id: string,
|
|
417
|
+
options?: FetchOptions,
|
|
418
|
+
) => Promise<T | null>;
|
|
419
|
+
getDocuments: <T = SanityDocument>(
|
|
420
|
+
ids: string[],
|
|
421
|
+
options?: FetchOptions,
|
|
422
|
+
) => Promise<(T | null)[]>;
|
|
265
423
|
/**
|
|
266
424
|
* Sanity-style HTTP request hook. Present iff the client was
|
|
267
425
|
* created with `accessControl`. The engine's access resolver pokes
|
|
@@ -300,10 +458,30 @@ export declare interface TestClient {
|
|
|
300
458
|
} | null>;
|
|
301
459
|
patch: (documentId: string) => PatchHandle;
|
|
302
460
|
transaction: () => TransactionHandle;
|
|
303
|
-
/**
|
|
461
|
+
/**
|
|
462
|
+
* Dispatch one or more release / version actions against the store.
|
|
463
|
+
* Returns a synthetic `transactionId`. Multi-action arrays are applied
|
|
464
|
+
* atomically — any failure rolls back the batch.
|
|
465
|
+
*/
|
|
466
|
+
action: (action: Action | Action[]) => Promise<ActionResult>;
|
|
467
|
+
/** Helpers mirroring `@sanity/client`'s `client.releases.*` surface. */
|
|
468
|
+
releases: ReleasesHandle;
|
|
469
|
+
/** Helper for `sanity.action.document.version.create`. */
|
|
470
|
+
createVersion: (params: {
|
|
471
|
+
releaseId: string;
|
|
472
|
+
publishedId: string;
|
|
473
|
+
document: DocumentBody;
|
|
474
|
+
}) => Promise<ActionResult>;
|
|
475
|
+
/** Helper for `sanity.action.document.version.unpublish`. */
|
|
476
|
+
unpublishVersion: (params: {
|
|
477
|
+
releaseId: string;
|
|
478
|
+
publishedId: string;
|
|
479
|
+
}) => Promise<ActionResult>;
|
|
480
|
+
/** Current `(projectId, dataset)` and active perspective. */
|
|
304
481
|
config: () => {
|
|
305
482
|
projectId: string;
|
|
306
483
|
dataset: string;
|
|
484
|
+
perspective: Perspective;
|
|
307
485
|
};
|
|
308
486
|
/**
|
|
309
487
|
* Return a new client handle pointing at a different `(projectId, dataset)`
|
|
@@ -315,6 +493,7 @@ export declare interface TestClient {
|
|
|
315
493
|
config: Partial<{
|
|
316
494
|
projectId: string;
|
|
317
495
|
dataset: string;
|
|
496
|
+
perspective: Perspective;
|
|
318
497
|
}>,
|
|
319
498
|
) => TestClient;
|
|
320
499
|
/** Replace the current dataset with the given documents. */
|
|
@@ -445,6 +624,27 @@ export declare type TxnMutation =
|
|
|
445
624
|
ifRev?: string;
|
|
446
625
|
};
|
|
447
626
|
|
|
627
|
+
export declare type VersionAction =
|
|
628
|
+
| {
|
|
629
|
+
actionType: "sanity.action.document.version.create";
|
|
630
|
+
publishedId: string;
|
|
631
|
+
document: DocumentBody;
|
|
632
|
+
releaseId?: string;
|
|
633
|
+
}
|
|
634
|
+
| {
|
|
635
|
+
actionType: "sanity.action.document.version.replace";
|
|
636
|
+
document: SanityDocumentLike;
|
|
637
|
+
}
|
|
638
|
+
| {
|
|
639
|
+
actionType: "sanity.action.document.version.discard";
|
|
640
|
+
versionId: string;
|
|
641
|
+
}
|
|
642
|
+
| {
|
|
643
|
+
actionType: "sanity.action.document.version.unpublish";
|
|
644
|
+
versionId: string;
|
|
645
|
+
publishedId: string;
|
|
646
|
+
};
|
|
647
|
+
|
|
448
648
|
/**
|
|
449
649
|
* Sanity-style 403 raised when a configured-grants check rejects a
|
|
450
650
|
* write. The thrown object carries the doc id, the attempted
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export declare type Action = ReleaseAction | VersionAction;
|
|
2
|
+
|
|
3
|
+
export declare interface ActionResult {
|
|
4
|
+
transactionId: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
1
7
|
/**
|
|
2
8
|
* Apply an ordered list of patch ops to a document, returning the new doc.
|
|
3
9
|
*
|
|
@@ -16,6 +22,19 @@ export declare function applyPatchOps(
|
|
|
16
22
|
ops: PatchOp[],
|
|
17
23
|
): SanityDocument;
|
|
18
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Apply a perspective to a raw set of documents and return the view
|
|
27
|
+
* groq-js should evaluate against.
|
|
28
|
+
*
|
|
29
|
+
* For non-raw perspectives, each output document for a non-system id
|
|
30
|
+
* gets `_id` projected to its published id and `_originalId` carrying
|
|
31
|
+
* the source id (matching the wire shape of the real Content Lake).
|
|
32
|
+
*/
|
|
33
|
+
export declare function applyPerspective(
|
|
34
|
+
docs: readonly SanityDocument[],
|
|
35
|
+
perspective: Perspective,
|
|
36
|
+
): SanityDocument[];
|
|
37
|
+
|
|
19
38
|
export declare function createPatch(
|
|
20
39
|
documentId: string,
|
|
21
40
|
executor: PatchExecutor,
|
|
@@ -65,6 +84,13 @@ export declare interface CreateTestClientOptions {
|
|
|
65
84
|
* unconditionally — the legacy behavior.
|
|
66
85
|
*/
|
|
67
86
|
accessControl?: TestClientAccessControl;
|
|
87
|
+
/**
|
|
88
|
+
* Default perspective applied to reads. Per-fetch `options.perspective`
|
|
89
|
+
* overrides this. `withConfig({ perspective })` returns a sibling
|
|
90
|
+
* handle with a different default. Defaults to `"raw"` so existing
|
|
91
|
+
* tests stay green.
|
|
92
|
+
*/
|
|
93
|
+
perspective?: Perspective;
|
|
68
94
|
}
|
|
69
95
|
|
|
70
96
|
/**
|
|
@@ -102,6 +128,18 @@ export declare function defaultAclPath(
|
|
|
102
128
|
dataset: string,
|
|
103
129
|
): string;
|
|
104
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Document body accepted by `version.create` / `createVersion`. The id
|
|
133
|
+
* is derived from `releaseId + publishedId` so callers may omit `_id`
|
|
134
|
+
* here. `version.replace` requires `_id` since it identifies the doc
|
|
135
|
+
* to replace.
|
|
136
|
+
*/
|
|
137
|
+
export declare interface DocumentBody {
|
|
138
|
+
_id?: string;
|
|
139
|
+
_type: string;
|
|
140
|
+
[field: string]: unknown;
|
|
141
|
+
}
|
|
142
|
+
|
|
105
143
|
export declare type DocumentValuePermission = "create" | "read" | "update";
|
|
106
144
|
|
|
107
145
|
/**
|
|
@@ -125,11 +163,46 @@ export declare function evaluateWriteAccess(args: {
|
|
|
125
163
|
matchingGrants: number;
|
|
126
164
|
}>;
|
|
127
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Data-plane subset of `@sanity/client`'s surface, with multi-dataset support.
|
|
168
|
+
*
|
|
169
|
+
* One `createTestClient()` call creates a registry of stores keyed by
|
|
170
|
+
* `(projectId, dataset)`. The returned client points at one of them.
|
|
171
|
+
* `withConfig({ projectId, dataset })` returns a new handle into the same
|
|
172
|
+
* registry but pointing at a different store — useful for workflows where
|
|
173
|
+
* definitions live in one dataset and instances live in another.
|
|
174
|
+
*
|
|
175
|
+
* Two separate `createTestClient()` calls have separate registries, so
|
|
176
|
+
* tests stay isolated from each other.
|
|
177
|
+
*
|
|
178
|
+
* Methods not on the real client:
|
|
179
|
+
*
|
|
180
|
+
* - `seed`, `add`, `reset`, `snapshot`, `store` — bulk-load helpers,
|
|
181
|
+
* scoped to the current dataset.
|
|
182
|
+
* - `datasets()` — lists known dataset keys in this registry.
|
|
183
|
+
*
|
|
184
|
+
* Methods deliberately omitted:
|
|
185
|
+
*
|
|
186
|
+
* - Project / agent / asset / live / listen APIs.
|
|
187
|
+
*/
|
|
188
|
+
export declare interface FetchOptions {
|
|
189
|
+
/** Override the client's configured perspective for this read. */
|
|
190
|
+
perspective?: Perspective;
|
|
191
|
+
}
|
|
192
|
+
|
|
128
193
|
export declare interface Grant {
|
|
129
194
|
filter: string;
|
|
130
195
|
permissions: DocumentValuePermission[];
|
|
131
196
|
}
|
|
132
197
|
|
|
198
|
+
export declare const isDraftId: (id: string) => boolean;
|
|
199
|
+
|
|
200
|
+
export declare const isReleaseDocId: (id: string) => boolean;
|
|
201
|
+
|
|
202
|
+
export declare const isSystemId: (id: string) => boolean;
|
|
203
|
+
|
|
204
|
+
export declare const isVersionId: (id: string) => boolean;
|
|
205
|
+
|
|
133
206
|
export declare interface MutationOptions {
|
|
134
207
|
ifRevisionId?: string;
|
|
135
208
|
}
|
|
@@ -197,6 +270,107 @@ export declare type PatchOp =
|
|
|
197
270
|
items: unknown[];
|
|
198
271
|
};
|
|
199
272
|
|
|
273
|
+
export declare type Perspective = "raw" | "published" | "drafts" | string[];
|
|
274
|
+
|
|
275
|
+
/** Strip `drafts.` / `versions.<name>.` prefix to recover the published id. */
|
|
276
|
+
export declare function publishedIdOf(id: string): string;
|
|
277
|
+
|
|
278
|
+
export declare type ReleaseAction =
|
|
279
|
+
| {
|
|
280
|
+
actionType: "sanity.action.release.create";
|
|
281
|
+
releaseId: string;
|
|
282
|
+
metadata?: Partial<ReleaseMetadata>;
|
|
283
|
+
}
|
|
284
|
+
| {
|
|
285
|
+
actionType: "sanity.action.release.edit";
|
|
286
|
+
releaseId: string;
|
|
287
|
+
patch: {
|
|
288
|
+
set?: Record<string, unknown>;
|
|
289
|
+
unset?: string[];
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
| {
|
|
293
|
+
actionType: "sanity.action.release.schedule";
|
|
294
|
+
releaseId: string;
|
|
295
|
+
publishAt: string;
|
|
296
|
+
}
|
|
297
|
+
| {
|
|
298
|
+
actionType: "sanity.action.release.unschedule";
|
|
299
|
+
releaseId: string;
|
|
300
|
+
}
|
|
301
|
+
| {
|
|
302
|
+
actionType: "sanity.action.release.publish";
|
|
303
|
+
releaseId: string;
|
|
304
|
+
}
|
|
305
|
+
| {
|
|
306
|
+
actionType: "sanity.action.release.archive";
|
|
307
|
+
releaseId: string;
|
|
308
|
+
}
|
|
309
|
+
| {
|
|
310
|
+
actionType: "sanity.action.release.unarchive";
|
|
311
|
+
releaseId: string;
|
|
312
|
+
}
|
|
313
|
+
| {
|
|
314
|
+
actionType: "sanity.action.release.delete";
|
|
315
|
+
releaseId: string;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
export declare interface ReleaseDocument extends SanityDocument {
|
|
319
|
+
_type: "system.release";
|
|
320
|
+
name: string;
|
|
321
|
+
state: ReleaseState;
|
|
322
|
+
metadata: ReleaseMetadata;
|
|
323
|
+
publishAt?: string;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export declare interface ReleaseMetadata {
|
|
327
|
+
title?: string;
|
|
328
|
+
description?: string;
|
|
329
|
+
releaseType?: ReleaseType;
|
|
330
|
+
intendedPublishAt?: string;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** Extract the release name from a `versions.<name>.<id>` id, else undefined. */
|
|
334
|
+
export declare function releaseNameOf(id: string): string | undefined;
|
|
335
|
+
|
|
336
|
+
export declare interface ReleasesHandle {
|
|
337
|
+
create: (params: {
|
|
338
|
+
releaseId: string;
|
|
339
|
+
metadata?: Partial<ReleaseMetadata>;
|
|
340
|
+
}) => Promise<
|
|
341
|
+
ActionResult & {
|
|
342
|
+
releaseId: string;
|
|
343
|
+
metadata: ReleaseMetadata;
|
|
344
|
+
}
|
|
345
|
+
>;
|
|
346
|
+
edit: (params: {
|
|
347
|
+
releaseId: string;
|
|
348
|
+
patch: {
|
|
349
|
+
set?: Record<string, unknown>;
|
|
350
|
+
unset?: string[];
|
|
351
|
+
};
|
|
352
|
+
}) => Promise<ActionResult>;
|
|
353
|
+
get: (params: { releaseId: string }) => Promise<ReleaseDocument | undefined>;
|
|
354
|
+
fetchDocuments: (params: { releaseId: string }) => Promise<SanityDocument[]>;
|
|
355
|
+
schedule: (params: {
|
|
356
|
+
releaseId: string;
|
|
357
|
+
publishAt: string;
|
|
358
|
+
}) => Promise<ActionResult>;
|
|
359
|
+
unschedule: (params: { releaseId: string }) => Promise<ActionResult>;
|
|
360
|
+
publish: (params: { releaseId: string }) => Promise<ActionResult>;
|
|
361
|
+
archive: (params: { releaseId: string }) => Promise<ActionResult>;
|
|
362
|
+
unarchive: (params: { releaseId: string }) => Promise<ActionResult>;
|
|
363
|
+
delete: (params: { releaseId: string }) => Promise<ActionResult>;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export declare type ReleaseState =
|
|
367
|
+
| "active"
|
|
368
|
+
| "scheduled"
|
|
369
|
+
| "published"
|
|
370
|
+
| "archived";
|
|
371
|
+
|
|
372
|
+
export declare type ReleaseType = "asap" | "scheduled" | "undecided";
|
|
373
|
+
|
|
200
374
|
/** @public */
|
|
201
375
|
declare interface SanityDocument {
|
|
202
376
|
_id: string;
|
|
@@ -232,36 +406,20 @@ export declare interface SystemFields {
|
|
|
232
406
|
_updatedAt: string;
|
|
233
407
|
}
|
|
234
408
|
|
|
235
|
-
/**
|
|
236
|
-
* Data-plane subset of `@sanity/client`'s surface, with multi-dataset support.
|
|
237
|
-
*
|
|
238
|
-
* One `createTestClient()` call creates a registry of stores keyed by
|
|
239
|
-
* `(projectId, dataset)`. The returned client points at one of them.
|
|
240
|
-
* `withConfig({ projectId, dataset })` returns a new handle into the same
|
|
241
|
-
* registry but pointing at a different store — useful for workflows where
|
|
242
|
-
* definitions live in one dataset and instances live in another.
|
|
243
|
-
*
|
|
244
|
-
* Two separate `createTestClient()` calls have separate registries, so
|
|
245
|
-
* tests stay isolated from each other.
|
|
246
|
-
*
|
|
247
|
-
* Methods not on the real client:
|
|
248
|
-
*
|
|
249
|
-
* - `seed`, `add`, `reset`, `snapshot`, `store` — bulk-load helpers,
|
|
250
|
-
* scoped to the current dataset.
|
|
251
|
-
* - `datasets()` — lists known dataset keys in this registry.
|
|
252
|
-
*
|
|
253
|
-
* Methods deliberately omitted:
|
|
254
|
-
*
|
|
255
|
-
* - Project / agent / asset / live / listen APIs.
|
|
256
|
-
* - Perspective handling.
|
|
257
|
-
*/
|
|
258
409
|
export declare interface TestClient {
|
|
259
410
|
fetch: <T = unknown>(
|
|
260
411
|
query: string,
|
|
261
412
|
params?: Record<string, unknown>,
|
|
413
|
+
options?: FetchOptions,
|
|
262
414
|
) => Promise<T>;
|
|
263
|
-
getDocument: <T = SanityDocument>(
|
|
264
|
-
|
|
415
|
+
getDocument: <T = SanityDocument>(
|
|
416
|
+
id: string,
|
|
417
|
+
options?: FetchOptions,
|
|
418
|
+
) => Promise<T | null>;
|
|
419
|
+
getDocuments: <T = SanityDocument>(
|
|
420
|
+
ids: string[],
|
|
421
|
+
options?: FetchOptions,
|
|
422
|
+
) => Promise<(T | null)[]>;
|
|
265
423
|
/**
|
|
266
424
|
* Sanity-style HTTP request hook. Present iff the client was
|
|
267
425
|
* created with `accessControl`. The engine's access resolver pokes
|
|
@@ -300,10 +458,30 @@ export declare interface TestClient {
|
|
|
300
458
|
} | null>;
|
|
301
459
|
patch: (documentId: string) => PatchHandle;
|
|
302
460
|
transaction: () => TransactionHandle;
|
|
303
|
-
/**
|
|
461
|
+
/**
|
|
462
|
+
* Dispatch one or more release / version actions against the store.
|
|
463
|
+
* Returns a synthetic `transactionId`. Multi-action arrays are applied
|
|
464
|
+
* atomically — any failure rolls back the batch.
|
|
465
|
+
*/
|
|
466
|
+
action: (action: Action | Action[]) => Promise<ActionResult>;
|
|
467
|
+
/** Helpers mirroring `@sanity/client`'s `client.releases.*` surface. */
|
|
468
|
+
releases: ReleasesHandle;
|
|
469
|
+
/** Helper for `sanity.action.document.version.create`. */
|
|
470
|
+
createVersion: (params: {
|
|
471
|
+
releaseId: string;
|
|
472
|
+
publishedId: string;
|
|
473
|
+
document: DocumentBody;
|
|
474
|
+
}) => Promise<ActionResult>;
|
|
475
|
+
/** Helper for `sanity.action.document.version.unpublish`. */
|
|
476
|
+
unpublishVersion: (params: {
|
|
477
|
+
releaseId: string;
|
|
478
|
+
publishedId: string;
|
|
479
|
+
}) => Promise<ActionResult>;
|
|
480
|
+
/** Current `(projectId, dataset)` and active perspective. */
|
|
304
481
|
config: () => {
|
|
305
482
|
projectId: string;
|
|
306
483
|
dataset: string;
|
|
484
|
+
perspective: Perspective;
|
|
307
485
|
};
|
|
308
486
|
/**
|
|
309
487
|
* Return a new client handle pointing at a different `(projectId, dataset)`
|
|
@@ -315,6 +493,7 @@ export declare interface TestClient {
|
|
|
315
493
|
config: Partial<{
|
|
316
494
|
projectId: string;
|
|
317
495
|
dataset: string;
|
|
496
|
+
perspective: Perspective;
|
|
318
497
|
}>,
|
|
319
498
|
) => TestClient;
|
|
320
499
|
/** Replace the current dataset with the given documents. */
|
|
@@ -445,6 +624,27 @@ export declare type TxnMutation =
|
|
|
445
624
|
ifRev?: string;
|
|
446
625
|
};
|
|
447
626
|
|
|
627
|
+
export declare type VersionAction =
|
|
628
|
+
| {
|
|
629
|
+
actionType: "sanity.action.document.version.create";
|
|
630
|
+
publishedId: string;
|
|
631
|
+
document: DocumentBody;
|
|
632
|
+
releaseId?: string;
|
|
633
|
+
}
|
|
634
|
+
| {
|
|
635
|
+
actionType: "sanity.action.document.version.replace";
|
|
636
|
+
document: SanityDocumentLike;
|
|
637
|
+
}
|
|
638
|
+
| {
|
|
639
|
+
actionType: "sanity.action.document.version.discard";
|
|
640
|
+
versionId: string;
|
|
641
|
+
}
|
|
642
|
+
| {
|
|
643
|
+
actionType: "sanity.action.document.version.unpublish";
|
|
644
|
+
versionId: string;
|
|
645
|
+
publishedId: string;
|
|
646
|
+
};
|
|
647
|
+
|
|
448
648
|
/**
|
|
449
649
|
* Sanity-style 403 raised when a configured-grants check rejects a
|
|
450
650
|
* write. The thrown object carries the doc id, the attempted
|