sanity 5.31.0 → 5.31.1

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.
@@ -1,4 +1,4 @@
1
- var version = "5.31.0";
1
+ var version = "5.31.1";
2
2
  let buildVersion;
3
3
  try {
4
4
  buildVersion = process.env.PKG_BUILD_VERSION;
@@ -7,7 +7,7 @@ try {
7
7
  try {
8
8
  buildVersion = buildVersion || // This is replaced by `@sanity/pkg-utils` at build time
9
9
  // and must always be references by its full static name, e.g. no optional chaining, no `if (process && process.env)` etc.
10
- "5.31.0";
10
+ "5.31.1";
11
11
  } catch {
12
12
  }
13
13
  const SANITY_VERSION = buildVersion || `${version}-dev`;
package/lib/index.js CHANGED
@@ -19100,7 +19100,7 @@ const CACHE$1 = /* @__PURE__ */ new WeakMap(), PREVIEW_FIELD_WEIGHT_MAP$1 = {
19100
19100
  title: 10,
19101
19101
  subtitle: 5,
19102
19102
  description: 1.5
19103
- }, DEFAULT_PREVIEW_SELECT_WEIGHT = 5, BASE_WEIGHTS$1 = {
19103
+ }, BASE_WEIGHTS$1 = {
19104
19104
  _id: {
19105
19105
  weight: 1,
19106
19106
  type: "string"
@@ -19164,47 +19164,7 @@ function getLeafWeights$1(schemaType, maxDepth, getWeight) {
19164
19164
  const getUserSetWeight$1 = (schemaType) => {
19165
19165
  const searchOptions = getTypeChain$1(schemaType).map((type) => type.options).find(isSearchConfiguration$1);
19166
19166
  return typeof searchOptions?.search?.weight == "number" ? searchOptions.search.weight : null;
19167
- }, getHiddenWeight$1 = (schemaType) => getTypeChain$1(schemaType).some((type) => type.hidden) ? 0 : null, getDefaultWeights$1 = (schemaType) => typeof (getUserSetWeight$1(schemaType) ?? getHiddenWeight$1(schemaType)) == "number" ? null : 1;
19168
- function findFieldType(type, fieldName) {
19169
- for (const chainType of getTypeChain$1(type))
19170
- if (chainType.jsonType === "object" && chainType.fields?.length) {
19171
- const field = chainType.fields.find(({
19172
- name
19173
- }) => name === fieldName);
19174
- if (field) return field.type;
19175
- }
19176
- }
19177
- function resolveLeafType(type, segments, depth, maxDepth) {
19178
- if (!type || depth > maxDepth) return null;
19179
- if (segments.length === 0)
19180
- return isPtField$1(type) ? "pt" : isSlugField$1(type) ? "slug" : isStringField$1(type) ? "string" : null;
19181
- const [head, ...rest] = segments, fieldType = findFieldType(type, head);
19182
- if (!fieldType) return null;
19183
- if (isReferenceSchemaType(fieldType) && "to" in fieldType) {
19184
- for (const target of fieldType.to) {
19185
- const leaf = resolveLeafType(target, rest, depth + 1, maxDepth);
19186
- if (leaf) return leaf;
19187
- }
19188
- return null;
19189
- }
19190
- return resolveLeafType(fieldType, rest, depth + 1, maxDepth);
19191
- }
19192
- function getPreviewSelectionPathWeights(schemaType, maxDepth, selectionKeysBySelectionPath, existingPaths) {
19193
- const weights = {};
19194
- for (const [path, previewKey] of Object.entries(selectionKeysBySelectionPath)) {
19195
- if (existingPaths.has(path) || path.includes("[]")) continue;
19196
- const leaf = resolveLeafType(schemaType, path.split("."), 0, maxDepth);
19197
- if (!leaf) continue;
19198
- const resolvedPath = leaf === "slug" && !path.endsWith(".current") ? `${path}.current` : path;
19199
- weights[resolvedPath] = {
19200
- path: resolvedPath,
19201
- weight: PREVIEW_FIELD_WEIGHT_MAP$1[previewKey] ?? DEFAULT_PREVIEW_SELECT_WEIGHT,
19202
- type: leaf === "pt" ? "pt" : "string"
19203
- };
19204
- }
19205
- return weights;
19206
- }
19207
- const getPreviewWeights$1 = (schemaType, maxDepth, isCrossDataset) => {
19167
+ }, getHiddenWeight$1 = (schemaType) => getTypeChain$1(schemaType).some((type) => type.hidden) ? 0 : null, getDefaultWeights$1 = (schemaType) => typeof (getUserSetWeight$1(schemaType) ?? getHiddenWeight$1(schemaType)) == "number" ? null : 1, getPreviewWeights$1 = (schemaType, maxDepth, isCrossDataset) => {
19208
19168
  const select2 = schemaType?.preview?.select;
19209
19169
  if (!select2) return null;
19210
19170
  const selectionKeysBySelectionPath = Object.fromEntries(Object.entries(select2).map(([selectionKey, selectionPath]) => [
@@ -19226,20 +19186,14 @@ const getPreviewWeights$1 = (schemaType, maxDepth, isCrossDataset) => {
19226
19186
  type,
19227
19187
  weight: PREVIEW_FIELD_WEIGHT_MAP$1[selectionKeysBySelectionPath[path]]
19228
19188
  }]));
19229
- if (isCrossDataset)
19230
- return Object.fromEntries(Object.entries(selectionKeysBySelectionPath).map(([path, previewFieldName]) => [path, {
19231
- path,
19232
- type: "string",
19233
- weight: PREVIEW_FIELD_WEIGHT_MAP$1[previewFieldName]
19234
- }]));
19235
- const previewSelectionPathWeights = isSchemaType$2(schemaType) ? getPreviewSelectionPathWeights(schemaType, maxDepth, selectionKeysBySelectionPath, new Set(Object.keys(defaultWeights))) : {}, previewWeightsFromLeafTraversal = getLeafWeights$1(schemaType, maxDepth, (type, path) => {
19189
+ return isCrossDataset ? Object.fromEntries(Object.entries(selectionKeysBySelectionPath).map(([path, previewFieldName]) => [path, {
19190
+ path,
19191
+ type: "string",
19192
+ weight: PREVIEW_FIELD_WEIGHT_MAP$1[previewFieldName]
19193
+ }])) : getLeafWeights$1(schemaType, maxDepth, (type, path) => {
19236
19194
  const nested = nestedWeightsBySelectionPath[getFullyQualifiedPath$1(type, path)];
19237
19195
  return nested ? nested.weight : null;
19238
19196
  });
19239
- return {
19240
- ...previewSelectionPathWeights,
19241
- ...previewWeightsFromLeafTraversal
19242
- };
19243
19197
  };
19244
19198
  function deriveSearchWeightsFromType({
19245
19199
  schemaType,
@@ -19356,20 +19310,14 @@ const getUserSetWeight = (schemaType) => {
19356
19310
  type,
19357
19311
  weight: PREVIEW_FIELD_WEIGHT_MAP[selectionKeysBySelectionPath[path]] ?? 0
19358
19312
  }]));
19359
- if (isCrossDataset)
19360
- return Object.fromEntries(Object.entries(selectionKeysBySelectionPath).map(([path, previewFieldName]) => [path, {
19361
- path,
19362
- type: "string",
19363
- weight: PREVIEW_FIELD_WEIGHT_MAP[previewFieldName] ?? 0
19364
- }]));
19365
- const previewSelectionPathWeights = isSchemaType$1(schemaType) ? getPreviewSelectionPathWeights(schemaType, maxDepth, selectionKeysBySelectionPath, new Set(Object.keys(defaultWeights))) : {}, previewWeightsFromLeafTraversal = getLeafWeights(schemaType, maxDepth, (type, path) => {
19313
+ return isCrossDataset ? Object.fromEntries(Object.entries(selectionKeysBySelectionPath).map(([path, previewFieldName]) => [path, {
19314
+ path,
19315
+ type: "string",
19316
+ weight: PREVIEW_FIELD_WEIGHT_MAP[previewFieldName] ?? 0
19317
+ }])) : getLeafWeights(schemaType, maxDepth, (type, path) => {
19366
19318
  const nested = nestedWeightsBySelectionPath[getFullyQualifiedPath(type, path)];
19367
19319
  return nested ? nested.weight : null;
19368
19320
  });
19369
- return {
19370
- ...previewSelectionPathWeights,
19371
- ...previewWeightsFromLeafTraversal
19372
- };
19373
19321
  };
19374
19322
  function deriveSearchWeightsFromType2024({
19375
19323
  schemaType,
@@ -19459,33 +19407,24 @@ function createSearchQuery$1(searchTerms, searchParams, {
19459
19407
  comments: comments2,
19460
19408
  filter: filter2
19461
19409
  } = {}) {
19462
- const flattenedSpecs = searchTerms.types.map((schemaType) => ({
19410
+ const flattenedSpecs = searchTerms.types.map((schemaType) => deriveSearchWeightsFromType2024({
19463
19411
  schemaType,
19464
- searchSpec: deriveSearchWeightsFromType2024({
19465
- schemaType,
19466
- maxDepth: maxDepth || DEFAULT_MAX_FIELD_DEPTH,
19467
- isCrossDataset,
19468
- processPaths: (paths) => paths.filter(({
19469
- weight
19470
- }) => weight !== 1)
19471
- })
19412
+ maxDepth: maxDepth || DEFAULT_MAX_FIELD_DEPTH,
19413
+ isCrossDataset,
19414
+ processPaths: (paths) => paths.filter(({
19415
+ weight
19416
+ }) => weight !== 1)
19472
19417
  })).filter(({
19473
- searchSpec
19474
- }) => searchSpec.paths.length !== 0).flatMap(({
19475
- schemaType,
19476
- searchSpec
19477
- }) => searchSpec.paths.map((path) => ({
19418
+ paths
19419
+ }) => paths.length !== 0).flatMap(({
19420
+ typeName,
19421
+ paths
19422
+ }) => paths.map((path) => ({
19478
19423
  ...path,
19479
- typeName: searchSpec.typeName,
19480
- schemaType
19481
- }))), groupedSpecs = groupBy(flattenedSpecs, (entry) => [entry.path, entry.weight].join(":")), baseMatch = "([@, _id] match text::query($__query) || references($__rawQuery))", score = Object.entries(groupedSpecs).flatMap(([, entries]) => {
19482
- if (entries.some(({
19483
- weight
19484
- }) => weight === 0))
19485
- return [];
19486
- const path = entries[0].path.includes("[]") ? entries[0].path : compileFieldPath(entries[0].schemaType, entries[0].path);
19487
- return `boost(_type in ${JSON.stringify(entries.map((entry) => entry.typeName))} && ${path} match text::query($__query), ${entries[0].weight})`;
19488
- }).concat(baseMatch), inputSortOrder = sort ?? [{
19424
+ typeName
19425
+ }))), groupedSpecs = groupBy(flattenedSpecs, (entry) => [entry.path, entry.weight].join(":")), baseMatch = "([@, _id] match text::query($__query) || references($__rawQuery))", score = Object.entries(groupedSpecs).flatMap(([, entries]) => entries.some(({
19426
+ weight
19427
+ }) => weight === 0) ? [] : `boost(_type in ${JSON.stringify(entries.map((entry) => entry.typeName))} && ${entries[0].path} match text::query($__query), ${entries[0].weight})`).concat(baseMatch), inputSortOrder = sort ?? [{
19489
19428
  field: "_score",
19490
19429
  direction: "desc"
19491
19430
  }], isScored = inputSortOrder.some(({
@@ -19651,13 +19590,10 @@ function stripWrappingQuotes(str) {
19651
19590
  }
19652
19591
  const FINDABILITY_MVI = 4, DEFAULT_LIMIT = 1e3, combinePaths = flow([flatten$1, union, compact]), pathWithMapper = ({
19653
19592
  mapWith,
19654
- path: rawPath
19655
- }, schemaType) => {
19656
- const path = !schemaType || rawPath.includes("[]") ? rawPath : compileFieldPath(schemaType, rawPath);
19657
- return mapWith ? `${mapWith}(${path})` : path;
19658
- };
19593
+ path
19594
+ }) => mapWith ? `${mapWith}(${path})` : path;
19659
19595
  function createConstraints(terms, specs) {
19660
- const combinedSearchPaths = combinePaths(specs.map((configForType) => (configForType.searchSpec.paths || []).map((opt) => pathWithMapper(opt, configForType.schemaType))));
19596
+ const combinedSearchPaths = combinePaths(specs.map((configForType) => (configForType.paths || []).map((opt) => pathWithMapper(opt))));
19661
19597
  return terms.map((_term, i) => combinedSearchPaths.map((joinedPath) => `${joinedPath} match $t${i}`)).filter((constraint) => constraint.length > 0).map((constraint) => `(${constraint.join(" || ")})`);
19662
19598
  }
19663
19599
  const SPECIAL_CHARS = /([^!@#$%^&*(),\\/?";:{}|[\]+<>\s-])+/g, STRIP_EDGE_CHARS = /(^[.]+)|([.]+$)/;
@@ -19679,23 +19615,17 @@ function createSearchQuery(searchTerms, searchOpts = {}) {
19679
19615
  sort,
19680
19616
  limit: limit2,
19681
19617
  comments: comments2
19682
- } = searchOpts, specs = searchTerms.types.map((schemaType) => ({
19618
+ } = searchOpts, specs = searchTerms.types.map((schemaType) => deriveSearchWeightsFromType({
19683
19619
  schemaType,
19684
- searchSpec: deriveSearchWeightsFromType({
19685
- schemaType,
19686
- maxDepth: maxDepth || DEFAULT_MAX_FIELD_DEPTH,
19687
- isCrossDataset
19688
- })
19620
+ maxDepth: maxDepth || DEFAULT_MAX_FIELD_DEPTH,
19621
+ isCrossDataset
19689
19622
  })).filter(({
19690
- searchSpec
19691
- }) => searchSpec.paths.length !== 0), terms = extractTermsFromQuery(searchTerms.query), filters = ["_type in $__types", ...createConstraints(terms, specs), filter2 ? `(${filter2})` : "", searchTerms.filter ? `(${searchTerms.filter})` : ""].filter(Boolean), selections = searchOpts.skipSortByScore ? [] : specs.map(({
19692
- searchSpec,
19693
- schemaType
19694
- }) => {
19695
- const constraint = `_type == "${searchSpec.typeName}" => `;
19623
+ paths
19624
+ }) => paths.length), terms = extractTermsFromQuery(searchTerms.query), filters = ["_type in $__types", ...createConstraints(terms, specs), filter2 ? `(${filter2})` : "", searchTerms.filter ? `(${searchTerms.filter})` : ""].filter(Boolean), selections = searchOpts.skipSortByScore ? [] : specs.map((spec) => {
19625
+ const constraint = `_type == "${spec.typeName}" => `;
19696
19626
  if (searchOpts.skipSortByScore)
19697
19627
  return;
19698
- const selection2 = `{ ${searchSpec.paths.map((cfg, i) => `"w${i}": ${pathWithMapper(cfg, schemaType)}`)} }`;
19628
+ const selection2 = `{ ${spec.paths.map((cfg, i) => `"w${i}": ${pathWithMapper(cfg)}`)} }`;
19699
19629
  return `${constraint}${selection2}`;
19700
19630
  }), inputSortOrder = sort || [{
19701
19631
  field: "_id",
@@ -19711,9 +19641,7 @@ function createSearchQuery(searchTerms, searchOpts = {}) {
19711
19641
  ${query}` : query,
19712
19642
  params: {
19713
19643
  ...toGroqParams(terms),
19714
- __types: specs.map(({
19715
- searchSpec
19716
- }) => searchSpec.typeName),
19644
+ __types: specs.map((spec) => spec.typeName),
19717
19645
  __limit: limit2 ?? DEFAULT_LIMIT,
19718
19646
  ...params
19719
19647
  },
@@ -19721,9 +19649,7 @@ ${query}` : query,
19721
19649
  tag,
19722
19650
  perspective
19723
19651
  },
19724
- searchSpec: specs.map(({
19725
- searchSpec
19726
- }) => searchSpec),
19652
+ searchSpec: specs,
19727
19653
  terms
19728
19654
  };
19729
19655
  }