@sanity/schema 6.21.0-next.94 → 6.21.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.
@@ -204,10 +204,26 @@ export declare function resolveSearchConfigForBaseFieldPaths(type: any, maxDepth
204
204
  */
205
205
  export declare function resolveSearchConfig(type: any, maxDepth?: number): any;
206
206
  export declare const ALL_FIELDS_GROUP_NAME = "all-fields";
207
+ interface CreateSchemaFromManifestTypesOptions {
208
+ /**
209
+ * Clone manifest types before converting serialized validation rules.
210
+ *
211
+ * Set this to `false` only when the caller owns the input and accepts that it will be mutated.
212
+ * Defaults to `true`.
213
+ */
214
+ cloneTypes?: boolean;
215
+ /**
216
+ * Validate manifest types before compiling them.
217
+ *
218
+ * Set this to `false` only for manifests that have already passed schema validation.
219
+ * Defaults to `true`.
220
+ */
221
+ validate?: boolean;
222
+ }
207
223
  export declare function createSchemaFromManifestTypes(schemaDef: {
208
224
  name: string;
209
225
  types: unknown[];
210
- }): Schema$1;
226
+ }, options?: CreateSchemaFromManifestTypesOptions): Schema$1;
211
227
  interface MediaLibraryConfig {
212
228
  enabled?: boolean;
213
229
  libraryId?: string;
@@ -392,17 +408,17 @@ export declare const builtinTypes: ({
392
408
  type: string;
393
409
  title: string;
394
410
  readOnly: boolean;
411
+ fieldset?: undefined;
395
412
  validation?: undefined;
396
413
  hidden?: undefined;
397
- fieldset?: undefined;
398
414
  } | {
399
415
  name: string;
400
416
  type: string;
401
417
  title: string;
402
- validation?: undefined;
403
- hidden?: undefined;
404
418
  readOnly?: undefined;
405
419
  fieldset?: undefined;
420
+ validation?: undefined;
421
+ hidden?: undefined;
406
422
  } | {
407
423
  name: string;
408
424
  type: string;
@@ -417,8 +433,8 @@ export declare const builtinTypes: ({
417
433
  readOnly: boolean;
418
434
  hidden: boolean;
419
435
  fieldset: string;
420
- validation?: undefined;
421
436
  title?: undefined;
437
+ validation?: undefined;
422
438
  } | {
423
439
  name: string;
424
440
  type: string;
@@ -471,17 +487,17 @@ export declare const builtinTypes: ({
471
487
  type: string;
472
488
  title: string;
473
489
  readOnly: boolean;
490
+ fieldset?: undefined;
474
491
  validation?: undefined;
475
492
  hidden?: undefined;
476
- fieldset?: undefined;
477
493
  } | {
478
494
  name: string;
479
495
  type: string;
480
496
  title: string;
481
- validation?: undefined;
482
- hidden?: undefined;
483
497
  readOnly?: undefined;
484
498
  fieldset?: undefined;
499
+ validation?: undefined;
500
+ hidden?: undefined;
485
501
  } | {
486
502
  name: string;
487
503
  type: string;
@@ -491,21 +507,21 @@ export declare const builtinTypes: ({
491
507
  validation: (Rule: import("@sanity/types").Rule) => import("@sanity/types").Rule;
492
508
  hidden?: undefined;
493
509
  } | {
494
- validation?: undefined;
495
510
  name: string;
496
511
  type: string;
497
512
  readOnly: boolean;
498
513
  hidden: boolean;
499
514
  fieldset: string;
500
515
  title?: undefined;
501
- } | {
502
516
  validation?: undefined;
503
- hidden?: undefined;
517
+ } | {
504
518
  name: string;
505
519
  type: string;
506
520
  title: string;
507
521
  readOnly: boolean;
508
522
  fieldset: string;
523
+ validation?: undefined;
524
+ hidden?: undefined;
509
525
  })[];
510
526
  preview: {
511
527
  select: {
@@ -639,5 +655,5 @@ export declare class ValidationError extends Error {
639
655
  problems: SchemaValidationProblemGroup[];
640
656
  constructor(problems: SchemaValidationProblemGroup[]);
641
657
  }
642
- export type { CreateManifest, 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 };
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 };
643
659
  //# sourceMappingURL=_internal.d.ts.map
package/lib/_internal.js CHANGED
@@ -2,7 +2,6 @@ import { c as resolveSearchConfig, d as OWN_PROPS_NAME, f as Rule, l as resolveS
2
2
  import { SetBuilder, processSetSynchronization } from "@sanity/descriptors";
3
3
  import { isSpanSchemaType } from "@sanity/types";
4
4
  import { dequal } from "dequal/lite";
5
- import cloneDeep from "lodash-es/cloneDeep.js";
6
5
  import { HttpError, createRequester } from "get-it";
7
6
  import { retry } from "get-it/middleware";
8
7
  import "@sanity/generate-help-url";
@@ -2147,18 +2146,20 @@ const builtinSchema = Schema$1.compile({
2147
2146
  }), unavailableValidator = () => {
2148
2147
  throw Error("This validator is unavailable because it was reconstructed from a serialized schema manifest");
2149
2148
  };
2150
- function createSchemaFromManifestTypes(schemaDef) {
2151
- let problems = groupProblems(validateSchema(schemaDef.types, { parentTypes: builtinTypes }).getTypes()).filter((group) => group.problems.some((problem) => problem.severity === "error"));
2152
- if (problems.length > 0) throw new ValidationError(problems);
2149
+ function createSchemaFromManifestTypes(schemaDef, options = {}) {
2150
+ if (options.validate !== !1) {
2151
+ let problems = groupProblems(validateSchema(schemaDef.types, { parentTypes: builtinTypes }).getTypes()).filter((group) => group.problems.some((problem) => problem.severity === "error"));
2152
+ if (problems.length > 0) throw new ValidationError(problems);
2153
+ }
2153
2154
  return Schema$1.compile({
2154
2155
  name: schemaDef.name,
2155
- types: schemaDef.types.map(coerceType).filter(Boolean),
2156
+ types: schemaDef.types.map((type) => coerceType(type, options.cloneTypes !== !1)).filter(Boolean),
2156
2157
  parent: builtinSchema
2157
2158
  });
2158
2159
  }
2159
- function coerceType(obj) {
2160
+ function coerceType(obj, clone) {
2160
2161
  if (!isObject(obj)) return;
2161
- let typ = cloneDeep(obj);
2162
+ let typ = clone ? structuredClone(obj) : obj;
2162
2163
  return traverse(typ), typ;
2163
2164
  }
2164
2165
  function traverse(obj) {