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