sanity 5.17.0-next.21 → 5.17.0-next.23

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.
@@ -4701,6 +4701,17 @@ type SearchSort = {
4701
4701
  direction: SortDirection;
4702
4702
  field: string;
4703
4703
  mapWith?: string;
4704
+ /**
4705
+ * Controls whether null/undefined values appear first or last in the sort order.
4706
+ *
4707
+ * Defaults match PostgreSQL behavior:
4708
+ * - `'desc'` direction → nulls first
4709
+ * - `'asc'` direction → nulls last
4710
+ *
4711
+ * **Note:** Overriding the default may have performance implications for document types
4712
+ * with lots of documents.
4713
+ */
4714
+ nulls?: 'first' | 'last';
4704
4715
  };
4705
4716
  /**
4706
4717
  * Get all defined document types from the schema that are searchable
@@ -1,4 +1,4 @@
1
- var version = "5.17.0-next.21+404c4559e9";
1
+ var version = "5.17.0-next.23+3534755c28";
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.17.0-next.21+404c4559e9";
10
+ "5.17.0-next.23+3534755c28";
11
11
  } catch {
12
12
  }
13
13
  const SANITY_VERSION = buildVersion || `${version}-dev`;
package/lib/index.js CHANGED
@@ -18656,16 +18656,30 @@ function prefixLast(query) {
18656
18656
  const prefixedTokens = [...tokens];
18657
18657
  return prefixedTokens.splice(finalIncrementalTokenIndex, 1, `${finalIncrementalToken}*`), prefixedTokens.join(" ");
18658
18658
  }
18659
+ function getNullSortingPrefix(ordering) {
18660
+ const {
18661
+ direction,
18662
+ nulls,
18663
+ field
18664
+ } = ordering;
18665
+ if (!nulls) return;
18666
+ const dirLower = (direction || "asc").toLowerCase();
18667
+ if (dirLower === "desc" && nulls === "last" || dirLower === "asc" && nulls === "first")
18668
+ return nulls === "last" ? `select(defined(${field}) => 0, 1)` : `select(defined(${field}) => 1, 0)`;
18669
+ }
18670
+ function wrapFieldWithFn(ordering) {
18671
+ return ordering.mapWith ? `${ordering.mapWith}(${ordering.field})` : ordering.field;
18672
+ }
18673
+ function toOrderClause(orderBy2) {
18674
+ return (orderBy2 || []).flatMap((ordering) => {
18675
+ const nullPrefix = getNullSortingPrefix(ordering), fieldClause = [wrapFieldWithFn(ordering), (ordering.direction || "").toLowerCase()].map((str) => str.trim()).filter(Boolean).join(" ");
18676
+ return nullPrefix ? [nullPrefix, fieldClause] : [fieldClause];
18677
+ }).join(",");
18678
+ }
18659
18679
  const FINDABILITY_MVI$1 = 5, DEFAULT_LIMIT$1 = 1e3;
18660
18680
  function isSchemaType(maybeSchemaType) {
18661
18681
  return typeof maybeSchemaType < "u" && "name" in maybeSchemaType;
18662
18682
  }
18663
- function toOrderClause$1(orderBy2) {
18664
- function wrapFieldWithFn(ordering) {
18665
- return ordering.mapWith ? `${ordering.mapWith}(${ordering.field})` : ordering.field;
18666
- }
18667
- return (orderBy2 || []).map((ordering) => [wrapFieldWithFn(ordering), (ordering.direction || "").toLowerCase()].map((str) => str.trim()).filter(Boolean).join(" ")).join(",");
18668
- }
18669
18683
  function createSearchQuery$1(searchTerms, searchParams, {
18670
18684
  perspective,
18671
18685
  sort,
@@ -18709,7 +18723,7 @@ function createSearchQuery$1(searchTerms, searchParams, {
18709
18723
  cursor ?? []
18710
18724
  ].flat(), projection = sortOrder.map(({
18711
18725
  field
18712
- }) => field).concat("_type", "_id", "_originalId").join(", "), query = [`*[${filters.join(" && ")}]`, isScored ? ["|", `score(${score.join(", ")})`] : [], ["|", `order(${toOrderClause$1(sortOrder)})`], isScored ? "[_score > 0]" : [], "[0...$__limit]", `{${projection}}`].flat().join(" "), rawQuery = typeof searchParams == "string" ? searchParams : searchParams.query, finalParams = {
18726
+ }) => field).concat("_type", "_id", "_originalId").join(", "), query = [`*[${filters.join(" && ")}]`, isScored ? ["|", `score(${score.join(", ")})`] : [], ["|", `order(${toOrderClause(sortOrder)})`], isScored ? "[_score > 0]" : [], "[0...$__limit]", `{${projection}}`].flat().join(" "), rawQuery = typeof searchParams == "string" ? searchParams : searchParams.query, finalParams = {
18713
18727
  __types: searchTerms.types.map((type) => isSchemaType(type) ? type.name : type.type),
18714
18728
  // Overfetch by 1 to determine whether there is another page to fetch.
18715
18729
  __limit: (limit2 ?? DEFAULT_LIMIT$1) + 1,
@@ -18859,12 +18873,6 @@ function extractTermsFromQuery(query) {
18859
18873
  const quotedQueries = [], unquotedQuery = query.replace(/("[^"]*")/g, (match) => words(match).length > 1 ? (quotedQueries.push(match), "") : match), quotedTerms = quotedQueries.map((str) => trim(toLower(str))), remainingTerms = uniq(compact(tokenize(toLower(unquotedQuery))));
18860
18874
  return [...quotedTerms, ...remainingTerms];
18861
18875
  }
18862
- function toOrderClause(orderBy2) {
18863
- function wrapFieldWithFn(ordering) {
18864
- return ordering.mapWith ? `${ordering.mapWith}(${ordering.field})` : ordering.field;
18865
- }
18866
- return (orderBy2 || []).map((ordering) => [wrapFieldWithFn(ordering), (ordering.direction || "").toLowerCase()].map((str) => str.trim()).filter(Boolean).join(" ")).join(",");
18867
- }
18868
18876
  function createSearchQuery(searchTerms, searchOpts = {}) {
18869
18877
  const {
18870
18878
  filter: filter2,