@xnetjs/data 0.0.2 → 0.1.0
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/README.md +112 -0
- package/dist/account-MWNCH4GJ.js +12 -0
- package/dist/account-ledger-R2GAFJL6.js +38 -0
- package/dist/auth/index.d.ts +420 -0
- package/dist/auth/index.js +102 -0
- package/dist/budget-NN7P35XP.js +12 -0
- package/dist/canvas-6WYBNH53.js +10 -0
- package/dist/channel-AT3LQF4A.js +12 -0
- package/dist/chat-message-DSVO72B3.js +10 -0
- package/dist/chunk-2ZNJWIQG.js +84 -0
- package/dist/chunk-3J3HILXO.js +46 -0
- package/dist/chunk-3RUDVTMH.js +5543 -0
- package/dist/chunk-4EYKGTSQ.js +49 -0
- package/dist/chunk-53F4PRNC.js +32 -0
- package/dist/chunk-5EXHNXPL.js +48 -0
- package/dist/{chunk-BQBPA5HS.js → chunk-5HC5NO57.js} +16 -2
- package/dist/chunk-6KLGA6IR.js +47 -0
- package/dist/chunk-6OMG4I7M.js +41 -0
- package/dist/chunk-7PDRDSFH.js +69 -0
- package/dist/chunk-BQLQSWKZ.js +232 -0
- package/dist/chunk-BY5O6LNC.js +380 -0
- package/dist/chunk-DCTRX6II.js +40 -0
- package/dist/{chunk-VYR5GPJP.js → chunk-DWEXKD6E.js} +9 -3
- package/dist/chunk-EBNMV2VO.js +896 -0
- package/dist/chunk-FVEACSKE.js +102 -0
- package/dist/chunk-GU6THOAB.js +45 -0
- package/dist/chunk-H4GA4BBK.js +75 -0
- package/dist/chunk-IJ44LR7N.js +76 -0
- package/dist/chunk-J4ANIXIV.js +402 -0
- package/dist/chunk-JDFNMFOZ.js +45 -0
- package/dist/chunk-K7DOZWWT.js +1811 -0
- package/dist/chunk-KQAT4XBL.js +49 -0
- package/dist/chunk-KQUALW4O.js +183 -0
- package/dist/chunk-LYSWLCOI.js +47 -0
- package/dist/chunk-MBTUO3ZL.js +65 -0
- package/dist/chunk-NI4FHG2K.js +52 -0
- package/dist/chunk-OCMSAKWV.js +78 -0
- package/dist/chunk-OGJCRNGE.js +57 -0
- package/dist/chunk-OPPHF3TF.js +143 -0
- package/dist/{chunk-IDMBCRUC.js → chunk-OSAWNZVM.js} +1 -1
- package/dist/chunk-PMUQACPY.js +33 -0
- package/dist/chunk-PNESGUH5.js +63 -0
- package/dist/chunk-Q3IEGH4B.js +51 -0
- package/dist/chunk-QJW5LDP4.js +52 -0
- package/dist/chunk-QWFTRZQT.js +142 -0
- package/dist/{chunk-SZC345Z2.js → chunk-RL64OJJ5.js} +1025 -1110
- package/dist/chunk-S5RP5RKY.js +416 -0
- package/dist/chunk-S6U6TCMN.js +722 -0
- package/dist/chunk-SVNGSZZA.js +69 -0
- package/dist/chunk-T5AZAOG5.js +54 -0
- package/dist/chunk-TCTZW4A6.js +42 -0
- package/dist/chunk-U64CW73O.js +109 -0
- package/dist/chunk-UDWKWTAX.js +6526 -0
- package/dist/chunk-UQM3G5A2.js +148 -0
- package/dist/chunk-VQ7JHB67.js +57 -0
- package/dist/chunk-W7EBL7ZU.js +73 -0
- package/dist/chunk-WEPK7SZF.js +65 -0
- package/dist/chunk-XHEA5UER.js +75 -0
- package/dist/chunk-XMSKJ5PV.js +66 -0
- package/dist/chunk-XROI44ZP.js +64 -0
- package/dist/chunk-Y3S5SRVM.js +45 -0
- package/dist/chunk-YEFKQYKA.js +43 -0
- package/dist/chunk-YSUIXD2Y.js +105 -0
- package/dist/chunk-ZCOFZY5M.js +70 -0
- package/dist/chunk-ZLU4Y3O2.js +50 -0
- package/dist/chunk-ZPZ7XDA6.js +54 -0
- package/dist/chunk-ZZ6TWKGS.js +40 -0
- package/dist/clone-C0Jhk2UN.d.ts +2205 -0
- package/dist/comment-QSWYAQVS.js +10 -0
- package/dist/crm-L5RYAAF3.js +68 -0
- package/dist/dashboard-JMKTTRA7.js +10 -0
- package/dist/database/index.d.ts +882 -0
- package/dist/database/index.js +523 -0
- package/dist/database-GIXSPZJW.js +10 -0
- package/dist/database-field-3EPAMZUR.js +10 -0
- package/dist/database-row-6Q6TRVE4.js +10 -0
- package/dist/database-select-option-BBBJFLLH.js +10 -0
- package/dist/database-view-5PLSOBI2.js +10 -0
- package/dist/experiment-DOVOZ34Y.js +10 -0
- package/dist/external-item-P2E5X7BZ.js +14 -0
- package/dist/external-reference-7BSFF6SA.js +8 -0
- package/dist/feed-2IXHHP6O.js +12 -0
- package/dist/feed-item-DPE6LN7I.js +12 -0
- package/dist/folder-6KM3KYD5.js +21 -0
- package/dist/game-5AK5XWBR.js +50 -0
- package/dist/grant-WTQSNT5A.js +8 -0
- package/dist/grant-expiration-cleaner-CY6BcmlR.d.ts +249 -0
- package/dist/import-batch-IXBJLQPJ.js +12 -0
- package/dist/inbox-state-E5NSVOGP.js +12 -0
- package/dist/index.d.ts +224 -4548
- package/dist/index.js +2252 -4754
- package/dist/map-RG5Y3CPC.js +10 -0
- package/dist/media-asset-QTCGLIZA.js +8 -0
- package/dist/memory-PNRTMBZO.js +12 -0
- package/dist/metric-65SVOX5C.js +10 -0
- package/dist/milestone-XEO6ZGDG.js +12 -0
- package/dist/moderation-FFHETMRB.js +30 -0
- package/dist/observation-2Y3QKUXM.js +10 -0
- package/dist/page-2V27JGKJ.js +10 -0
- package/dist/posting-GBOSZCMZ.js +12 -0
- package/dist/profile-BLLDWIDK.js +8 -0
- package/dist/project-CQL5LN26.js +10 -0
- package/dist/query-ast-C3m6kZYv.d.ts +226 -0
- package/dist/reaction-T2DTJBBV.js +10 -0
- package/dist/registry-DunPv__d.d.ts +99 -0
- package/dist/saved-view-4R2DBCL3.js +10 -0
- package/dist/schema/index.d.ts +6489 -0
- package/dist/schema/index.js +677 -0
- package/dist/schema-extension-LNRF2YRD.js +18 -0
- package/dist/space-IJU24PBH.js +42 -0
- package/dist/space-membership-DEUMM7NV.js +14 -0
- package/dist/store/index.d.ts +518 -0
- package/dist/store/index.js +135 -0
- package/dist/store-DtIDjk7c.d.ts +355 -0
- package/dist/sync/awareness.d.ts +69 -0
- package/dist/sync/awareness.js +20 -0
- package/dist/system-ILHCZOVO.js +38 -0
- package/dist/tag-SKCHM3U5.js +16 -0
- package/dist/task-7AOBP7WC.js +16 -0
- package/dist/task-view-NUGKELJP.js +10 -0
- package/dist/transaction-ZDSEGDIR.js +12 -0
- package/dist/transcription-PSCLDAGX.js +12 -0
- package/dist/types-S-BJAKyK.d.ts +1576 -0
- package/dist/updates.d.ts +44 -0
- package/dist/updates.js +16 -0
- package/dist/user-widget-RLY2N46A.js +8 -0
- package/dist/view-types-DSde-uT_.d.ts +316 -0
- package/package.json +32 -9
- package/dist/canvas-HSIKIQFK.js +0 -7
- package/dist/chunk-2L5ZUGG5.js +0 -53
- package/dist/chunk-4MTS5KAQ.js +0 -22
- package/dist/chunk-GZHARFKC.js +0 -25
- package/dist/chunk-WKIKJTI2.js +0 -45
- package/dist/comment-277JD7DV.js +0 -7
- package/dist/database-W3KEHLI3.js +0 -7
- package/dist/database-row-3O2QSNZN.js +0 -7
- package/dist/grant-QVZ454YC.js +0 -7
- package/dist/page-O4WTOIEO.js +0 -7
- package/dist/task-SEKAYJH7.js +0 -7
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/schema/extension.ts
|
|
2
|
+
var EXT_PREFIX = "ext:";
|
|
3
|
+
var AUTHORITY_PATTERN = /^[^/\s]+$/;
|
|
4
|
+
var FIELD_PATTERN = /^[^/\s]+$/;
|
|
5
|
+
function extKey(authority, field) {
|
|
6
|
+
if (!AUTHORITY_PATTERN.test(authority)) {
|
|
7
|
+
throw new Error(`Invalid extension authority: ${JSON.stringify(authority)}`);
|
|
8
|
+
}
|
|
9
|
+
if (!FIELD_PATTERN.test(field)) {
|
|
10
|
+
throw new Error(`Invalid extension field name: ${JSON.stringify(field)}`);
|
|
11
|
+
}
|
|
12
|
+
return `${EXT_PREFIX}${authority}/${field}`;
|
|
13
|
+
}
|
|
14
|
+
function isExtKey(key) {
|
|
15
|
+
return parseExtKey(key) !== null;
|
|
16
|
+
}
|
|
17
|
+
function parseExtKey(key) {
|
|
18
|
+
if (!key.startsWith(EXT_PREFIX)) return null;
|
|
19
|
+
const rest = key.slice(EXT_PREFIX.length);
|
|
20
|
+
const slash = rest.indexOf("/");
|
|
21
|
+
if (slash <= 0) return null;
|
|
22
|
+
const authority = rest.slice(0, slash);
|
|
23
|
+
const field = rest.slice(slash + 1);
|
|
24
|
+
if (!AUTHORITY_PATTERN.test(authority) || !FIELD_PATTERN.test(field)) return null;
|
|
25
|
+
return { authority, field };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
EXT_PREFIX,
|
|
30
|
+
extKey,
|
|
31
|
+
isExtKey,
|
|
32
|
+
parseExtKey
|
|
33
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
spaceCascadeAuthorization
|
|
3
|
+
} from "./chunk-OCMSAKWV.js";
|
|
4
|
+
import {
|
|
5
|
+
created,
|
|
6
|
+
createdBy,
|
|
7
|
+
date,
|
|
8
|
+
defineSchema,
|
|
9
|
+
json,
|
|
10
|
+
relation,
|
|
11
|
+
select,
|
|
12
|
+
text,
|
|
13
|
+
url
|
|
14
|
+
} from "./chunk-EBNMV2VO.js";
|
|
15
|
+
|
|
16
|
+
// src/schema/schemas/external-item.ts
|
|
17
|
+
var EXTERNAL_ITEM_SCHEMA_IRI = "xnet://xnet.fyi/ExternalItem@1.0.0";
|
|
18
|
+
var EXTERNAL_ITEM_SOURCES = [
|
|
19
|
+
{ id: "github", name: "GitHub" },
|
|
20
|
+
{ id: "notion", name: "Notion" },
|
|
21
|
+
{ id: "airtable", name: "Airtable" },
|
|
22
|
+
{ id: "linear", name: "Linear" },
|
|
23
|
+
{ id: "stripe", name: "Stripe" },
|
|
24
|
+
{ id: "sentry", name: "Sentry" },
|
|
25
|
+
{ id: "pagerduty", name: "PagerDuty" },
|
|
26
|
+
{ id: "other", name: "Other" }
|
|
27
|
+
];
|
|
28
|
+
var ExternalItemSchema = defineSchema({
|
|
29
|
+
name: "ExternalItem",
|
|
30
|
+
namespace: "xnet://xnet.fyi/",
|
|
31
|
+
properties: {
|
|
32
|
+
/** Originating service. */
|
|
33
|
+
source: select({ options: EXTERNAL_ITEM_SOURCES, required: true }),
|
|
34
|
+
/** Service-specific object kind, e.g. `issue`, `pull_request`, `page`, `record`. */
|
|
35
|
+
kind: text({ required: true, maxLength: 100 }),
|
|
36
|
+
/** Stable id in the source system, used to de-duplicate re-syncs. */
|
|
37
|
+
externalId: text({ required: true, maxLength: 500 }),
|
|
38
|
+
/** Display title. */
|
|
39
|
+
title: text({ required: true, maxLength: 1e3 }),
|
|
40
|
+
/** Canonical link back to the source object. */
|
|
41
|
+
url: url({}),
|
|
42
|
+
/** Body / description text. */
|
|
43
|
+
body: text({}),
|
|
44
|
+
/** Free-form status string from the source (e.g. `open`, `closed`, `done`). */
|
|
45
|
+
status: text({ maxLength: 100 }),
|
|
46
|
+
/** When the source object was last updated (Unix ms). */
|
|
47
|
+
updatedAt: date({ includeTime: true }),
|
|
48
|
+
/** The original payload, preserved for fidelity. */
|
|
49
|
+
raw: json({}),
|
|
50
|
+
/** The home Space — drives the authorization cascade. */
|
|
51
|
+
space: relation({ target: "xnet://xnet.fyi/Space@1.0.0" }),
|
|
52
|
+
createdAt: created(),
|
|
53
|
+
createdBy: createdBy()
|
|
54
|
+
},
|
|
55
|
+
document: void 0,
|
|
56
|
+
authorization: spaceCascadeAuthorization()
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
EXTERNAL_ITEM_SCHEMA_IRI,
|
|
61
|
+
EXTERNAL_ITEM_SOURCES,
|
|
62
|
+
ExternalItemSchema
|
|
63
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
spaceCascadeAuthorization
|
|
3
|
+
} from "./chunk-OCMSAKWV.js";
|
|
4
|
+
import {
|
|
5
|
+
checkbox,
|
|
6
|
+
created,
|
|
7
|
+
createdBy,
|
|
8
|
+
date,
|
|
9
|
+
defineSchema,
|
|
10
|
+
file,
|
|
11
|
+
json,
|
|
12
|
+
relation,
|
|
13
|
+
text
|
|
14
|
+
} from "./chunk-EBNMV2VO.js";
|
|
15
|
+
|
|
16
|
+
// src/schema/schemas/chat-message.ts
|
|
17
|
+
var ChatMessageSchema = defineSchema({
|
|
18
|
+
name: "ChatMessage",
|
|
19
|
+
namespace: "xnet://xnet.fyi/",
|
|
20
|
+
properties: {
|
|
21
|
+
/** The channel this message belongs to */
|
|
22
|
+
channel: relation({ target: "xnet://xnet.fyi/Channel@1.0.0", required: true }),
|
|
23
|
+
/** Message body in GitHub-flavored markdown */
|
|
24
|
+
content: text({ required: true, maxLength: 1e4 }),
|
|
25
|
+
/** Thread root message (flat threading, like Comment.inReplyTo) */
|
|
26
|
+
inReplyTo: relation({ target: "xnet://xnet.fyi/ChatMessage@1.0.0" }),
|
|
27
|
+
/** Optional file attachments */
|
|
28
|
+
attachments: file({ multiple: true }),
|
|
29
|
+
/** Structured mentions ({ dids, room? }) — populated by the composer */
|
|
30
|
+
mentions: json({}),
|
|
31
|
+
/** Whether the message has been edited */
|
|
32
|
+
edited: checkbox({ default: false }),
|
|
33
|
+
/** When the message was last edited */
|
|
34
|
+
editedAt: date({}),
|
|
35
|
+
/** Soft tombstone: content removed, message shell kept for thread shape */
|
|
36
|
+
redacted: checkbox({ default: false }),
|
|
37
|
+
/** Workspace-wide labels from inline #hashtag pills (exploration 0169) */
|
|
38
|
+
tags: relation({ target: "xnet://xnet.fyi/Tag@1.0.0", multiple: true }),
|
|
39
|
+
/** Node ids from the composer's [[ link picks (exploration 0170) */
|
|
40
|
+
links: relation({ multiple: true }),
|
|
41
|
+
createdAt: created(),
|
|
42
|
+
createdBy: createdBy()
|
|
43
|
+
},
|
|
44
|
+
document: void 0,
|
|
45
|
+
// Inherits access from its home Space (exploration 0181/0192).
|
|
46
|
+
authorization: spaceCascadeAuthorization("channel")
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
ChatMessageSchema
|
|
51
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
spaceCascadeAuthorization
|
|
3
|
+
} from "./chunk-OCMSAKWV.js";
|
|
4
|
+
import {
|
|
5
|
+
defineSchema,
|
|
6
|
+
json,
|
|
7
|
+
relation,
|
|
8
|
+
select,
|
|
9
|
+
text
|
|
10
|
+
} from "./chunk-EBNMV2VO.js";
|
|
11
|
+
|
|
12
|
+
// src/schema/schemas/dashboard.ts
|
|
13
|
+
var DashboardSchema = defineSchema({
|
|
14
|
+
name: "Dashboard",
|
|
15
|
+
namespace: "xnet://xnet.fyi/",
|
|
16
|
+
properties: {
|
|
17
|
+
/** Dashboard title */
|
|
18
|
+
title: text({ required: true, maxLength: 500 }),
|
|
19
|
+
/** Emoji or icon URL */
|
|
20
|
+
icon: text({}),
|
|
21
|
+
/** Dashboard variable scope (time range, custom vars) — whole-value LWW */
|
|
22
|
+
variables: json({}),
|
|
23
|
+
/** Widget instances placed on this dashboard — whole-list LWW */
|
|
24
|
+
widgets: json({}),
|
|
25
|
+
/** Per-breakpoint {x, y, w, h} layout maps — whole-value LWW */
|
|
26
|
+
layouts: json({}),
|
|
27
|
+
/** Canonical home; empty = Unfiled (exploration 0169) */
|
|
28
|
+
folder: relation({ target: "xnet://xnet.fyi/Folder@1.0.0" }),
|
|
29
|
+
/** Order among folder siblings — fractional index */
|
|
30
|
+
sortKey: text({ maxLength: 500 }),
|
|
31
|
+
/** Workspace-wide labels, referenced by id (exploration 0169) */
|
|
32
|
+
tags: relation({ target: "xnet://xnet.fyi/Tag@1.0.0", multiple: true }),
|
|
33
|
+
/** Canonical SECURITY home; empty = personal/private (exploration 0179) */
|
|
34
|
+
space: relation({ target: "xnet://xnet.fyi/Space@1.0.0" }),
|
|
35
|
+
/** Per-node visibility; `inherit` defers to the Space (exploration 0179) */
|
|
36
|
+
visibility: select({
|
|
37
|
+
options: [
|
|
38
|
+
{ id: "inherit", name: "Inherit", color: "gray" },
|
|
39
|
+
{ id: "private", name: "Private", color: "gray" },
|
|
40
|
+
{ id: "unlisted", name: "Unlisted", color: "yellow" },
|
|
41
|
+
{ id: "public", name: "Public", color: "green" }
|
|
42
|
+
],
|
|
43
|
+
default: "inherit"
|
|
44
|
+
})
|
|
45
|
+
},
|
|
46
|
+
// Inherits access from its home Space (exploration 0181/0192).
|
|
47
|
+
authorization: spaceCascadeAuthorization()
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export {
|
|
51
|
+
DashboardSchema
|
|
52
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// src/database/fractional-index.ts
|
|
2
|
+
var ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
3
|
+
var BASE = ALPHABET.length;
|
|
4
|
+
var START_KEY = "a0";
|
|
5
|
+
var MIDPOINT_CHAR = ALPHABET[Math.floor(BASE / 2)];
|
|
6
|
+
function generateSortKey(before, after) {
|
|
7
|
+
if (!before && !after) {
|
|
8
|
+
return START_KEY;
|
|
9
|
+
}
|
|
10
|
+
if (before && !after) {
|
|
11
|
+
return incrementKey(before);
|
|
12
|
+
}
|
|
13
|
+
if (!before && after) {
|
|
14
|
+
return prependKey(after);
|
|
15
|
+
}
|
|
16
|
+
return midpointKey(before, after);
|
|
17
|
+
}
|
|
18
|
+
function generateSortKeyWithJitter(before, after) {
|
|
19
|
+
const base = generateSortKey(before, after);
|
|
20
|
+
const jitter = ALPHABET[randomInt(BASE)] + ALPHABET[randomInt(BASE)];
|
|
21
|
+
return base + jitter;
|
|
22
|
+
}
|
|
23
|
+
function incrementKey(key) {
|
|
24
|
+
const chars = key.split("");
|
|
25
|
+
let i = chars.length - 1;
|
|
26
|
+
while (i >= 0) {
|
|
27
|
+
const idx = ALPHABET.indexOf(chars[i]);
|
|
28
|
+
if (idx < BASE - 1) {
|
|
29
|
+
chars[i] = ALPHABET[idx + 1];
|
|
30
|
+
return chars.join("");
|
|
31
|
+
}
|
|
32
|
+
chars[i] = ALPHABET[0];
|
|
33
|
+
i--;
|
|
34
|
+
}
|
|
35
|
+
return key + ALPHABET[0];
|
|
36
|
+
}
|
|
37
|
+
function prependKey(key) {
|
|
38
|
+
const chars = key.split("");
|
|
39
|
+
for (let i = 0; i < chars.length; i++) {
|
|
40
|
+
const idx = ALPHABET.indexOf(chars[i]);
|
|
41
|
+
if (idx > 0) {
|
|
42
|
+
chars[i] = ALPHABET[idx - 1];
|
|
43
|
+
return chars.slice(0, i + 1).join("") + ALPHABET[BASE - 1];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return ALPHABET[0] + key.slice(1) + MIDPOINT_CHAR;
|
|
47
|
+
}
|
|
48
|
+
function midpointKey(before, after) {
|
|
49
|
+
if (before >= after) {
|
|
50
|
+
throw new Error(`Invalid key order: "${before}" >= "${after}"`);
|
|
51
|
+
}
|
|
52
|
+
const maxLen = Math.max(before.length, after.length) + 1;
|
|
53
|
+
const paddedBefore = before.padEnd(maxLen, ALPHABET[0]);
|
|
54
|
+
const paddedAfter = after.padEnd(maxLen, ALPHABET[0]);
|
|
55
|
+
for (let i = 0; i < maxLen; i++) {
|
|
56
|
+
const beforeIdx = ALPHABET.indexOf(paddedBefore[i]);
|
|
57
|
+
const afterIdx = ALPHABET.indexOf(paddedAfter[i]);
|
|
58
|
+
if (beforeIdx === afterIdx) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (afterIdx - beforeIdx > 1) {
|
|
62
|
+
const midIdx = Math.floor((beforeIdx + afterIdx) / 2);
|
|
63
|
+
return paddedBefore.slice(0, i) + ALPHABET[midIdx];
|
|
64
|
+
}
|
|
65
|
+
for (let j = i + 1; j < maxLen; j++) {
|
|
66
|
+
const bIdx = ALPHABET.indexOf(paddedBefore[j]);
|
|
67
|
+
const aIdx = ALPHABET.indexOf(paddedAfter[j]);
|
|
68
|
+
if (aIdx > bIdx + 1) {
|
|
69
|
+
const midIdx = Math.floor((bIdx + aIdx) / 2);
|
|
70
|
+
return paddedBefore.slice(0, j) + ALPHABET[midIdx];
|
|
71
|
+
} else if (aIdx > bIdx) {
|
|
72
|
+
continue;
|
|
73
|
+
} else {
|
|
74
|
+
const midIdx = Math.floor((bIdx + BASE) / 2);
|
|
75
|
+
return paddedBefore.slice(0, j) + ALPHABET[midIdx];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return before + MIDPOINT_CHAR;
|
|
79
|
+
}
|
|
80
|
+
for (let i = before.length; i < after.length; i++) {
|
|
81
|
+
const afterIdx = ALPHABET.indexOf(after[i]);
|
|
82
|
+
if (afterIdx > 0) {
|
|
83
|
+
const midIdx = Math.floor(afterIdx / 2);
|
|
84
|
+
return before + ALPHABET[0].repeat(i - before.length) + ALPHABET[midIdx];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return before + MIDPOINT_CHAR;
|
|
88
|
+
}
|
|
89
|
+
function isValidSortKey(key) {
|
|
90
|
+
if (!key || key.length === 0) return false;
|
|
91
|
+
return key.split("").every((c) => ALPHABET.includes(c));
|
|
92
|
+
}
|
|
93
|
+
function compareSortKeys(a, b) {
|
|
94
|
+
if (a < b) return -1;
|
|
95
|
+
if (a > b) return 1;
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
function rebalanceSortKeys(rowIds) {
|
|
99
|
+
const result = /* @__PURE__ */ new Map();
|
|
100
|
+
if (rowIds.length === 0) {
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
for (let i = 0; i < rowIds.length; i++) {
|
|
104
|
+
const key = indexToKey(i, rowIds.length);
|
|
105
|
+
result.set(rowIds[i], key);
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
function indexToKey(index, total) {
|
|
110
|
+
const charCount = total <= BASE * BASE ? 2 : 3;
|
|
111
|
+
const range = Math.pow(BASE, charCount);
|
|
112
|
+
const step = Math.floor(range / (total + 1));
|
|
113
|
+
const value = step * (index + 1);
|
|
114
|
+
return valueToKey(value, charCount);
|
|
115
|
+
}
|
|
116
|
+
function valueToKey(value, length) {
|
|
117
|
+
let result = "";
|
|
118
|
+
let remaining = value;
|
|
119
|
+
for (let i = 0; i < length; i++) {
|
|
120
|
+
const idx = remaining % BASE;
|
|
121
|
+
result = ALPHABET[idx] + result;
|
|
122
|
+
remaining = Math.floor(remaining / BASE);
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
function randomInt(max) {
|
|
127
|
+
return Math.floor(Math.random() * max);
|
|
128
|
+
}
|
|
129
|
+
var MAX_KEY_LENGTH = 10;
|
|
130
|
+
function needsRebalancing(sortKeys) {
|
|
131
|
+
return sortKeys.some((key) => key.length > MAX_KEY_LENGTH);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export {
|
|
135
|
+
generateSortKey,
|
|
136
|
+
generateSortKeyWithJitter,
|
|
137
|
+
isValidSortKey,
|
|
138
|
+
compareSortKeys,
|
|
139
|
+
rebalanceSortKeys,
|
|
140
|
+
MAX_KEY_LENGTH,
|
|
141
|
+
needsRebalancing
|
|
142
|
+
};
|