@contrail/documents 2.2.1 → 2.3.0-alpha.8377be9
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/CHANGELOG.md +11 -0
- package/lib/sort-index.d.ts +1 -0
- package/lib/sort-index.js +15 -2
- package/lib/sort-order-errors.d.ts +1 -1
- package/lib/sort-order-errors.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,17 @@ All notable changes to `@contrail/documents` are documented here.
|
|
|
5
5
|
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
6
|
Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.3.0] - 2026-09-21
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `isValidSortIndex(sortIndex)` — whether a value is a key `fractional-indexing` could have produced, so every client writing a sort index is held to one definition of valid rather than each caller inventing its own. `fractional-indexing` keeps its `validateOrderKey` private, so the check asks the generator to mint a key after the candidate: that path validates its bound first and cannot fail for any other reason. The generator's own grammar check ignores the digit alphabet, and accepts `a0!` or `a0 `, so the candidate is screened against the exported `BASE_62_DIGITS` first. Costs ~130ns for a short key and ~350ns for a 387-character one.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- `allElementsHaveSortIndex` now requires each element's key to be valid, not merely a non-empty string. Callers that treat an unkeyed collection as needing fresh keys — board snapshot restore is the one today — now also re-key a collection whose keys are present but malformed, instead of restoring ordering that cannot sort.
|
|
17
|
+
- `SortOrderErrorMessage.SORT_INDEX_NOT_USABLE` describes the real rule ("sortIndex must be a valid fractional index") rather than "must be a non-empty string". The `SORT_INDEX_NOT_USABLE` code is unchanged.
|
|
18
|
+
|
|
8
19
|
## [2.2.1] - 2026-09-15
|
|
9
20
|
|
|
10
21
|
### Changed
|
package/lib/sort-index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DocumentElement } from './types';
|
|
2
|
+
export declare function isValidSortIndex(sortIndex: unknown): sortIndex is string;
|
|
2
3
|
export declare function allElementsHaveSortIndex(elements: unknown[]): boolean;
|
|
3
4
|
export declare function buildKeyBetween(a: string | null, b: string | null): string;
|
|
4
5
|
export declare function buildNKeysBetween(a: string | null, b: string | null, n: number): string[];
|
package/lib/sort-index.js
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidSortIndex = isValidSortIndex;
|
|
3
4
|
exports.allElementsHaveSortIndex = allElementsHaveSortIndex;
|
|
4
5
|
exports.buildKeyBetween = buildKeyBetween;
|
|
5
6
|
exports.buildNKeysBetween = buildNKeysBetween;
|
|
6
7
|
exports.compareSortIndex = compareSortIndex;
|
|
7
8
|
const fractional_indexing_1 = require("fractional-indexing");
|
|
9
|
+
const SORT_INDEX_DIGITS = new RegExp(`^[${fractional_indexing_1.BASE_62_DIGITS.replace(/[\\\]^-]/g, (digit) => `\\${digit}`)}]+$`);
|
|
10
|
+
function isValidSortIndex(sortIndex) {
|
|
11
|
+
if (typeof sortIndex !== 'string' || !SORT_INDEX_DIGITS.test(sortIndex)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
(0, fractional_indexing_1.generateKeyBetween)(sortIndex, null);
|
|
16
|
+
}
|
|
17
|
+
catch (_a) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
8
22
|
function allElementsHaveSortIndex(elements) {
|
|
9
|
-
return elements.every((element) =>
|
|
10
|
-
element.sortIndex.length > 0);
|
|
23
|
+
return elements.every((element) => isValidSortIndex(element.sortIndex));
|
|
11
24
|
}
|
|
12
25
|
function buildKeyBetween(a, b) {
|
|
13
26
|
return (0, fractional_indexing_1.generateKeyBetween)(a, b);
|
|
@@ -6,5 +6,5 @@ export declare enum SortOrderErrorCode {
|
|
|
6
6
|
export declare enum SortOrderErrorMessage {
|
|
7
7
|
SORT_MIGRATION_IN_PROGRESS = "Sort order is being migrated for this document; editing is briefly locked",
|
|
8
8
|
SORT_MODE_MISMATCH = "Ordering write does not match the document's sort mode",
|
|
9
|
-
SORT_INDEX_NOT_USABLE = "sortIndex must be a
|
|
9
|
+
SORT_INDEX_NOT_USABLE = "sortIndex must be a valid fractional index"
|
|
10
10
|
}
|
package/lib/sort-order-errors.js
CHANGED
|
@@ -11,5 +11,5 @@ var SortOrderErrorMessage;
|
|
|
11
11
|
(function (SortOrderErrorMessage) {
|
|
12
12
|
SortOrderErrorMessage["SORT_MIGRATION_IN_PROGRESS"] = "Sort order is being migrated for this document; editing is briefly locked";
|
|
13
13
|
SortOrderErrorMessage["SORT_MODE_MISMATCH"] = "Ordering write does not match the document's sort mode";
|
|
14
|
-
SortOrderErrorMessage["SORT_INDEX_NOT_USABLE"] = "sortIndex must be a
|
|
14
|
+
SortOrderErrorMessage["SORT_INDEX_NOT_USABLE"] = "sortIndex must be a valid fractional index";
|
|
15
15
|
})(SortOrderErrorMessage || (exports.SortOrderErrorMessage = SortOrderErrorMessage = {}));
|