@sanity/schema 6.21.0-next.93 → 6.21.0-next.98

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;
@@ -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) {