@sanity/schema 6.22.0-next.30 → 6.22.0-next.37
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/lib/_internal.d.ts +37 -26
- package/lib/_internal.js +52 -16
- package/lib/_internal.js.map +1 -1
- package/package.json +3 -3
package/lib/_internal.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as SchemaValidationResult, i as ProblemPathTypeSegment, l as Schema$1, n as ProblemPathPropertySegment, o as TypeWithProblems, r as ProblemPathSegment, s as _FIXME_, t as ProblemPath } from "./typedefs-LNWlFyVi.js";
|
|
2
|
-
import { SetSynchronization, SynchronizationRequest, SynchronizationResult } from "@sanity/descriptors";
|
|
2
|
+
import { Encoded, SetSynchronization, SynchronizationRequest, SynchronizationResult } from "@sanity/descriptors";
|
|
3
3
|
import { CustomValidator, MediaValidator, SanityDocumentLike, Schema, SchemaType, SchemaTypeDefinition, SchemaValidationProblem, SchemaValidationProblemGroup } from "@sanity/types";
|
|
4
4
|
import { RequestOptions } from "get-it";
|
|
5
5
|
import { SchemaType as SchemaType$1 } from "groq-js";
|
|
@@ -78,11 +78,11 @@ interface UploadSchemaPhase {
|
|
|
78
78
|
* - `claim` — the claim request (permanent or temporary).
|
|
79
79
|
* - `synchronize` — one synchronize iteration (see `iteration`).
|
|
80
80
|
* - `commit` — the commit request that pins a permanent claim. Emitted by
|
|
81
|
-
* the `commit()` thunk returned from
|
|
82
|
-
*
|
|
83
|
-
* - `total` — the whole
|
|
84
|
-
*
|
|
85
|
-
*
|
|
81
|
+
* the `commit()` thunk returned from a prepare function, or inline by an
|
|
82
|
+
* upload function. Never emitted for a temporary claim.
|
|
83
|
+
* - `total` — the whole upload call; emitted last, on success only.
|
|
84
|
+
* Prepare functions do not emit `total` (a standalone caller can time the
|
|
85
|
+
* awaited promise itself).
|
|
86
86
|
*/
|
|
87
87
|
phase: 'convert' | 'claim' | 'synchronize' | 'commit' | 'total';
|
|
88
88
|
/** Elapsed wall-clock time for this phase, in seconds. */
|
|
@@ -167,13 +167,18 @@ interface PreparedSchemaUpload {
|
|
|
167
167
|
*/
|
|
168
168
|
commit?: () => Promise<void>;
|
|
169
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* A pre-encoded schema descriptor graph ready for synchronization.
|
|
172
|
+
*
|
|
173
|
+
* @internal
|
|
174
|
+
*/
|
|
175
|
+
interface EncodedSchemaDescriptor {
|
|
176
|
+
descriptorId: string;
|
|
177
|
+
descriptors: Readonly<Record<string, Encoded<string>>>;
|
|
178
|
+
}
|
|
170
179
|
/**
|
|
171
180
|
* Convert a Sanity schema to a descriptor set, claim its id, and synchronize
|
|
172
|
-
* until complete — but do **not** commit.
|
|
173
|
-
* `commit()` thunk finalizes the claim when the caller is ready (e.g. after a
|
|
174
|
-
* dependent write succeeds); for a temporary claim no thunk is returned. This is
|
|
175
|
-
* the building block `uploadSchema` is built on, exposed for callers that need
|
|
176
|
-
* to control the claim/commit lifecycle.
|
|
181
|
+
* until complete — but do **not** commit.
|
|
177
182
|
*
|
|
178
183
|
* @internal
|
|
179
184
|
*/
|
|
@@ -191,6 +196,12 @@ export declare function prepareSchemaUpload(schema: Schema, options: PrepareSche
|
|
|
191
196
|
* @internal
|
|
192
197
|
*/
|
|
193
198
|
export declare function uploadSchema(schema: Schema, options: UploadSchemaOptions): Promise<string>;
|
|
199
|
+
/**
|
|
200
|
+
* Upload and permanently claim a pre-encoded schema descriptor graph.
|
|
201
|
+
*
|
|
202
|
+
* @internal
|
|
203
|
+
*/
|
|
204
|
+
export declare function uploadEncodedSchema(encoded: EncodedSchemaDescriptor, options: UploadSchemaOptions): Promise<string>;
|
|
194
205
|
export declare const isActionEnabled: (schemaType: SchemaType, action: string) => boolean;
|
|
195
206
|
type ValidationCallback = CustomValidator | MediaValidator;
|
|
196
207
|
/** @internal */
|
|
@@ -408,17 +419,17 @@ export declare const builtinTypes: ({
|
|
|
408
419
|
type: string;
|
|
409
420
|
title: string;
|
|
410
421
|
readOnly: boolean;
|
|
422
|
+
fieldset?: undefined;
|
|
411
423
|
validation?: undefined;
|
|
412
424
|
hidden?: undefined;
|
|
413
|
-
fieldset?: undefined;
|
|
414
425
|
} | {
|
|
415
426
|
name: string;
|
|
416
427
|
type: string;
|
|
417
428
|
title: string;
|
|
429
|
+
readOnly?: undefined;
|
|
430
|
+
fieldset?: undefined;
|
|
418
431
|
validation?: undefined;
|
|
419
432
|
hidden?: undefined;
|
|
420
|
-
fieldset?: undefined;
|
|
421
|
-
readOnly?: undefined;
|
|
422
433
|
} | {
|
|
423
434
|
name: string;
|
|
424
435
|
type: string;
|
|
@@ -433,8 +444,8 @@ export declare const builtinTypes: ({
|
|
|
433
444
|
readOnly: boolean;
|
|
434
445
|
hidden: boolean;
|
|
435
446
|
fieldset: string;
|
|
436
|
-
validation?: undefined;
|
|
437
447
|
title?: undefined;
|
|
448
|
+
validation?: undefined;
|
|
438
449
|
} | {
|
|
439
450
|
name: string;
|
|
440
451
|
type: string;
|
|
@@ -487,17 +498,17 @@ export declare const builtinTypes: ({
|
|
|
487
498
|
type: string;
|
|
488
499
|
title: string;
|
|
489
500
|
readOnly: boolean;
|
|
501
|
+
fieldset?: undefined;
|
|
490
502
|
validation?: undefined;
|
|
491
503
|
hidden?: undefined;
|
|
492
|
-
fieldset?: undefined;
|
|
493
504
|
} | {
|
|
494
505
|
name: string;
|
|
495
506
|
type: string;
|
|
496
507
|
title: string;
|
|
508
|
+
readOnly?: undefined;
|
|
509
|
+
fieldset?: undefined;
|
|
497
510
|
validation?: undefined;
|
|
498
511
|
hidden?: undefined;
|
|
499
|
-
fieldset?: undefined;
|
|
500
|
-
readOnly?: undefined;
|
|
501
512
|
} | {
|
|
502
513
|
name: string;
|
|
503
514
|
type: string;
|
|
@@ -507,21 +518,21 @@ export declare const builtinTypes: ({
|
|
|
507
518
|
validation: (Rule: import("@sanity/types").Rule) => import("@sanity/types").Rule;
|
|
508
519
|
hidden?: undefined;
|
|
509
520
|
} | {
|
|
510
|
-
validation?: undefined;
|
|
511
521
|
name: string;
|
|
512
522
|
type: string;
|
|
513
523
|
readOnly: boolean;
|
|
514
524
|
hidden: boolean;
|
|
515
525
|
fieldset: string;
|
|
516
526
|
title?: undefined;
|
|
517
|
-
} | {
|
|
518
527
|
validation?: undefined;
|
|
519
|
-
|
|
528
|
+
} | {
|
|
520
529
|
name: string;
|
|
521
530
|
type: string;
|
|
522
531
|
title: string;
|
|
523
532
|
readOnly: boolean;
|
|
524
533
|
fieldset: string;
|
|
534
|
+
validation?: undefined;
|
|
535
|
+
hidden?: undefined;
|
|
525
536
|
})[];
|
|
526
537
|
preview: {
|
|
527
538
|
select: {
|
|
@@ -571,17 +582,17 @@ export declare const builtinTypes: ({
|
|
|
571
582
|
};
|
|
572
583
|
}[];
|
|
573
584
|
fields: ({
|
|
574
|
-
name: string;
|
|
575
|
-
type: string;
|
|
576
|
-
fieldset?: undefined;
|
|
577
585
|
title?: undefined;
|
|
578
586
|
readOnly?: undefined;
|
|
587
|
+
fieldset?: undefined;
|
|
588
|
+
name: string;
|
|
589
|
+
type: string;
|
|
579
590
|
} | {
|
|
591
|
+
readOnly?: undefined;
|
|
580
592
|
name: string;
|
|
581
593
|
title: string;
|
|
582
594
|
type: string;
|
|
583
595
|
fieldset: string;
|
|
584
|
-
readOnly?: undefined;
|
|
585
596
|
} | {
|
|
586
597
|
fieldset?: undefined;
|
|
587
598
|
name: string;
|
|
@@ -655,5 +666,5 @@ export declare class ValidationError extends Error {
|
|
|
655
666
|
problems: SchemaValidationProblemGroup[];
|
|
656
667
|
constructor(problems: SchemaValidationProblemGroup[]);
|
|
657
668
|
}
|
|
658
|
-
export type { CreateManifest, CreateSchemaFromManifestTypesOptions, CreateWorkspaceManifest, DefaultWorkspaceSchemaId, DescriptorRequester, _FIXME_ as FIXME, IconResolver, ManifestSchemaType, ManifestWorkspaceFile, ParsedWorkspaceSchemaId, PrepareSchemaUploadOptions, PreparedSchemaUpload, SchemaValidationResult as Problem, SchemaValidationResult as ValidationResult, ProblemPath, ProblemPathPropertySegment, ProblemPathSegment, ProblemPathTypeSegment, SchemaSynchronizationRequest, SchemaSynchronizationResult, StoredWorkspaceSchema, TypeWithProblems, UploadSchemaOptions, UploadSchemaPhase, WorkspaceSchemaId };
|
|
669
|
+
export type { CreateManifest, CreateSchemaFromManifestTypesOptions, CreateWorkspaceManifest, DefaultWorkspaceSchemaId, DescriptorRequester, EncodedSchemaDescriptor, _FIXME_ as FIXME, IconResolver, ManifestSchemaType, ManifestWorkspaceFile, ParsedWorkspaceSchemaId, PrepareSchemaUploadOptions, PreparedSchemaUpload, SchemaValidationResult as Problem, SchemaValidationResult as ValidationResult, ProblemPath, ProblemPathPropertySegment, ProblemPathSegment, ProblemPathTypeSegment, SchemaSynchronizationRequest, SchemaSynchronizationResult, StoredWorkspaceSchema, TypeWithProblems, UploadSchemaOptions, UploadSchemaPhase, WorkspaceSchemaId };
|
|
659
670
|
//# sourceMappingURL=_internal.d.ts.map
|
package/lib/_internal.js
CHANGED
|
@@ -709,17 +709,8 @@ function makeEmit(onPhaseComplete) {
|
|
|
709
709
|
} catch {}
|
|
710
710
|
};
|
|
711
711
|
}
|
|
712
|
-
/**
|
|
713
|
-
|
|
714
|
-
* until complete — but do **not** commit. For a permanent claim, the returned
|
|
715
|
-
* `commit()` thunk finalizes the claim when the caller is ready (e.g. after a
|
|
716
|
-
* dependent write succeeds); for a temporary claim no thunk is returned. This is
|
|
717
|
-
* the building block `uploadSchema` is built on, exposed for callers that need
|
|
718
|
-
* to control the claim/commit lifecycle.
|
|
719
|
-
*
|
|
720
|
-
* @internal
|
|
721
|
-
*/
|
|
722
|
-
async function prepareSchemaUpload(schema, options) {
|
|
712
|
+
/** Claim and synchronize a prepared descriptor source without committing it. */
|
|
713
|
+
async function prepareDescriptorUpload(source, options) {
|
|
723
714
|
let requester = resolveRequester(options), apiVersion = options.apiVersion ?? "v2025-06-01", maxSyncIterations = options.maxSyncIterations ?? 5;
|
|
724
715
|
if (!Number.isInteger(maxSyncIterations) || maxSyncIterations < 0) throw Error("uploadSchema: `maxSyncIterations` must be a non-negative integer");
|
|
725
716
|
let { contextKey } = options, permanent = options.claim === "permanent", headers = mergeHeaders(options.token, options.headers);
|
|
@@ -732,9 +723,7 @@ async function prepareSchemaUpload(schema, options) {
|
|
|
732
723
|
function url(path) {
|
|
733
724
|
return `/${apiVersion}/descriptors/${path}`;
|
|
734
725
|
}
|
|
735
|
-
let emit = makeEmit(options.onPhaseComplete),
|
|
736
|
-
emit("convert", startedConvert);
|
|
737
|
-
let startedClaim = performance.now(), claimResponse = await request({
|
|
726
|
+
let emit = makeEmit(options.onPhaseComplete), { descriptorId } = source, startedClaim = performance.now(), claimResponse = await request({
|
|
738
727
|
url: url("claim"),
|
|
739
728
|
method: "POST",
|
|
740
729
|
body: {
|
|
@@ -748,7 +737,7 @@ async function prepareSchemaUpload(schema, options) {
|
|
|
748
737
|
if (permanent && (commitId = claimResponse.commitId, !commitId)) throw Error("uploadSchema: claim response is missing `commitId` for the permanent claim");
|
|
749
738
|
let syncResult = claimResponse.synchronization;
|
|
750
739
|
for (let i = 0; i <= maxSyncIterations; i++) {
|
|
751
|
-
let syncRequest =
|
|
740
|
+
let syncRequest = source.nextSynchronizationRequest(syncResult);
|
|
752
741
|
if (syncRequest === null) return {
|
|
753
742
|
descriptorId,
|
|
754
743
|
commit: permanent ? async () => {
|
|
@@ -774,6 +763,41 @@ async function prepareSchemaUpload(schema, options) {
|
|
|
774
763
|
throw Error(`Schema synchronization didn't succeed in ${maxSyncIterations} iterations`);
|
|
775
764
|
}
|
|
776
765
|
/**
|
|
766
|
+
* Convert a Sanity schema to a descriptor set, claim its id, and synchronize
|
|
767
|
+
* until complete — but do **not** commit.
|
|
768
|
+
*
|
|
769
|
+
* @internal
|
|
770
|
+
*/
|
|
771
|
+
async function prepareSchemaUpload(schema, options) {
|
|
772
|
+
let emit = makeEmit(options.onPhaseComplete), startedConvert = performance.now(), sync = await sharedConverter.get(schema);
|
|
773
|
+
return emit("convert", startedConvert), prepareDescriptorUpload({
|
|
774
|
+
descriptorId: sync.set.id,
|
|
775
|
+
nextSynchronizationRequest: (result) => processSchemaSynchronization(sync, result)
|
|
776
|
+
}, options);
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Synchronize a pre-encoded schema descriptor graph without recompiling it.
|
|
780
|
+
*
|
|
781
|
+
* @internal
|
|
782
|
+
*/
|
|
783
|
+
async function prepareEncodedSchemaUpload(encoded, options) {
|
|
784
|
+
return prepareDescriptorUpload({
|
|
785
|
+
descriptorId: encoded.descriptorId,
|
|
786
|
+
nextSynchronizationRequest: (result) => {
|
|
787
|
+
if (result.type === "complete") return null;
|
|
788
|
+
let descriptors = result.missingIds.map((id) => {
|
|
789
|
+
let descriptor = encoded.descriptors[id];
|
|
790
|
+
if (!descriptor) throw Error(`uploadSchema: synchronization requested unknown descriptor ${id}`);
|
|
791
|
+
return descriptor;
|
|
792
|
+
});
|
|
793
|
+
return {
|
|
794
|
+
id: encoded.descriptorId,
|
|
795
|
+
descriptors
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
}, options);
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
777
801
|
* Convert a Sanity schema to a descriptor set and upload it permanently:
|
|
778
802
|
* permanently claim the id, run the synchronization loop until complete, then
|
|
779
803
|
* commit the claim to pin the descriptor. Returns the content-addressed
|
|
@@ -792,6 +816,18 @@ async function uploadSchema(schema, options) {
|
|
|
792
816
|
});
|
|
793
817
|
return await commit(), emit("total", startedTotal), descriptorId;
|
|
794
818
|
}
|
|
819
|
+
/**
|
|
820
|
+
* Upload and permanently claim a pre-encoded schema descriptor graph.
|
|
821
|
+
*
|
|
822
|
+
* @internal
|
|
823
|
+
*/
|
|
824
|
+
async function uploadEncodedSchema(encoded, options) {
|
|
825
|
+
let startedTotal = performance.now(), emit = makeEmit(options.onPhaseComplete), { descriptorId, commit } = await prepareEncodedSchemaUpload(encoded, {
|
|
826
|
+
...options,
|
|
827
|
+
claim: "permanent"
|
|
828
|
+
});
|
|
829
|
+
return await commit(), emit("total", startedTotal), descriptorId;
|
|
830
|
+
}
|
|
795
831
|
const ACTIONS_FLAG = "__experimental_actions", DEFAULT_ACTIONS = [
|
|
796
832
|
"create",
|
|
797
833
|
"update",
|
|
@@ -3105,6 +3141,6 @@ function validateMediaLibraryAssetAspect(maybeAspect) {
|
|
|
3105
3141
|
}).getTypes()).map((group) => group.problems.filter(({ severity }) => severity === "error")).filter((problems) => problems.length);
|
|
3106
3142
|
return [errors.length === 0, errors];
|
|
3107
3143
|
}
|
|
3108
|
-
export { ALL_FIELDS_GROUP_NAME, DEFAULT_MAX_FIELD_DEPTH, DescriptorConverter, ValidationError, builtinTypes, createSchemaFromManifestTypes, createStoredWorkspaceSchemaPayload, extractCreateWorkspaceManifest, extractManifestSchemaTypes, extractSchema, getWorkspaceSchemaId, groupProblems, isActionEnabled, isInternalValidator, markInternalValidator, parseWorkspaceSchemaId, prepareSchemaUpload, processSchemaSynchronization, resolveSearchConfig, resolveSearchConfigForBaseFieldPaths, uploadSchema, validForNamesChars, validForNamesPattern, validateMediaLibraryAssetAspect, validateSchema };
|
|
3144
|
+
export { ALL_FIELDS_GROUP_NAME, DEFAULT_MAX_FIELD_DEPTH, DescriptorConverter, ValidationError, builtinTypes, createSchemaFromManifestTypes, createStoredWorkspaceSchemaPayload, extractCreateWorkspaceManifest, extractManifestSchemaTypes, extractSchema, getWorkspaceSchemaId, groupProblems, isActionEnabled, isInternalValidator, markInternalValidator, parseWorkspaceSchemaId, prepareSchemaUpload, processSchemaSynchronization, resolveSearchConfig, resolveSearchConfigForBaseFieldPaths, uploadEncodedSchema, uploadSchema, validForNamesChars, validForNamesPattern, validateMediaLibraryAssetAspect, validateSchema };
|
|
3109
3145
|
|
|
3110
3146
|
//# sourceMappingURL=_internal.js.map
|