@contrail/documents 1.14.0 → 1.15.0-alpha.4626e64
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 +6 -0
- package/lib/sort-index.d.ts +1 -0
- package/lib/sort-index.js +21 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ 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
|
+
## [1.15.0] - 2026-08-18
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `isValidSortIndex` — whether a value is a usable fractional-indexing key. `fractional-indexing` keeps its own `validateOrderKey` private, so callers that need to check a key before storing it had no way to do so beyond a non-empty-string test. A key that passes that test but breaks the grammar still sorts, so ordering looks fine; the failure surfaces later, when the next insert beside it calls `generateKeyBetween` and throws. One point is stricter than the library: every character must be in the base-62 digit set, since a key holding anything else can sort below the integer part it claims.
|
|
13
|
+
|
|
8
14
|
## [1.14.0] - 2026-07-29
|
|
9
15
|
|
|
10
16
|
### Added
|
package/lib/sort-index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DocumentElement } from './types';
|
|
2
2
|
export declare function allElementsHaveSortIndex(elements: unknown[]): boolean;
|
|
3
|
+
export declare function isValidSortIndex(sortIndex: unknown): sortIndex is string;
|
|
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[];
|
|
5
6
|
export declare function compareSortIndex(a: DocumentElement, b: DocumentElement): number;
|
package/lib/sort-index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.allElementsHaveSortIndex = allElementsHaveSortIndex;
|
|
4
|
+
exports.isValidSortIndex = isValidSortIndex;
|
|
4
5
|
exports.buildKeyBetween = buildKeyBetween;
|
|
5
6
|
exports.buildNKeysBetween = buildNKeysBetween;
|
|
6
7
|
exports.compareSortIndex = compareSortIndex;
|
|
@@ -9,6 +10,26 @@ function allElementsHaveSortIndex(elements) {
|
|
|
9
10
|
return elements.every((element) => typeof element.sortIndex === 'string' &&
|
|
10
11
|
element.sortIndex.length > 0);
|
|
11
12
|
}
|
|
13
|
+
const SMALLEST_INTEGER = 'A00000000000000000000000000';
|
|
14
|
+
function getIntegerPartLength(head) {
|
|
15
|
+
if (head >= 'a' && head <= 'z')
|
|
16
|
+
return head.charCodeAt(0) - 'a'.charCodeAt(0) + 2;
|
|
17
|
+
if (head >= 'A' && head <= 'Z')
|
|
18
|
+
return 'Z'.charCodeAt(0) - head.charCodeAt(0) + 2;
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
function isValidSortIndex(sortIndex) {
|
|
22
|
+
if (typeof sortIndex !== 'string' || sortIndex.length === 0)
|
|
23
|
+
return false;
|
|
24
|
+
if (sortIndex === SMALLEST_INTEGER)
|
|
25
|
+
return false;
|
|
26
|
+
if (![...sortIndex].every((character) => fractional_indexing_1.BASE_62_DIGITS.includes(character)))
|
|
27
|
+
return false;
|
|
28
|
+
const integerPartLength = getIntegerPartLength(sortIndex[0]);
|
|
29
|
+
if (integerPartLength === null || integerPartLength > sortIndex.length)
|
|
30
|
+
return false;
|
|
31
|
+
return !sortIndex.slice(integerPartLength).endsWith('0');
|
|
32
|
+
}
|
|
12
33
|
function buildKeyBetween(a, b) {
|
|
13
34
|
return (0, fractional_indexing_1.generateKeyBetween)(a, b);
|
|
14
35
|
}
|