@graphprotocol/grc-20 0.2.0 → 0.2.2
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/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/src/core/account.js +2 -2
- package/dist/src/core/account.js.map +1 -1
- package/dist/src/core/base58.test.js +1 -1
- package/dist/src/core/base58.test.js.map +1 -1
- package/dist/src/core/blocks/data.js +2 -2
- package/dist/src/core/blocks/data.js.map +1 -1
- package/dist/src/core/blocks/text.js +2 -2
- package/dist/src/core/blocks/text.js.map +1 -1
- package/dist/src/core/image.js +2 -2
- package/dist/src/core/image.js.map +1 -1
- package/dist/src/core/relation.d.ts +4 -4
- package/dist/src/core/relation.d.ts.map +1 -1
- package/dist/src/core/relation.js +2 -2
- package/dist/src/core/relation.js.map +1 -1
- package/dist/src/core/triple.d.ts +4 -4
- package/dist/src/core/triple.d.ts.map +1 -1
- package/dist/src/id.d.ts +2 -2
- package/dist/src/id.d.ts.map +1 -1
- package/dist/src/id.js +3 -3
- package/dist/src/id.js.map +1 -1
- package/dist/src/id.test.js +2 -2
- package/dist/src/id.test.js.map +1 -1
- package/dist/src/ipfs.d.ts +34 -0
- package/dist/src/ipfs.d.ts.map +1 -0
- package/dist/src/ipfs.js +59 -0
- package/dist/src/ipfs.js.map +1 -0
- package/dist/src/proto/edit.d.ts +3 -3
- package/dist/src/proto/edit.d.ts.map +1 -1
- package/dist/src/proto/edit.js +2 -2
- package/dist/src/proto/edit.js.map +1 -1
- package/package.json +11 -10
- package/dist/error.d.ts +0 -2
- package/dist/error.d.ts.map +0 -1
- package/dist/error.js +0 -8
- package/dist/error.js.map +0 -1
- package/dist/example.d.ts +0 -2
- package/dist/example.d.ts.map +0 -1
- package/dist/example.js +0 -27
- package/dist/example.js.map +0 -1
- package/dist/run.d.ts +0 -2
- package/dist/run.d.ts.map +0 -1
- package/dist/run.js +0 -4
- package/dist/run.js.map +0 -1
- package/dist/src/base58.d.ts +0 -36
- package/dist/src/base58.d.ts.map +0 -1
- package/dist/src/base58.js +0 -62
- package/dist/src/base58.js.map +0 -1
- package/dist/src/base58.test.d.ts +0 -2
- package/dist/src/base58.test.d.ts.map +0 -1
- package/dist/src/base58.test.js +0 -2
- package/dist/src/base58.test.js.map +0 -1
- package/dist/src/core/ids/generate.d.ts +0 -2
- package/dist/src/core/ids/generate.d.ts.map +0 -1
- package/dist/src/core/ids/generate.js +0 -4
- package/dist/src/core/ids/generate.js.map +0 -1
- package/dist/src/core/position-strings/cursors.d.ts +0 -56
- package/dist/src/core/position-strings/cursors.d.ts.map +0 -1
- package/dist/src/core/position-strings/cursors.js +0 -69
- package/dist/src/core/position-strings/cursors.js.map +0 -1
- package/dist/src/core/position-strings/find-position.d.ts +0 -24
- package/dist/src/core/position-strings/find-position.d.ts.map +0 -1
- package/dist/src/core/position-strings/find-position.js +0 -38
- package/dist/src/core/position-strings/find-position.js.map +0 -1
- package/dist/src/core/position-strings/ids.d.ts +0 -37
- package/dist/src/core/position-strings/ids.d.ts.map +0 -1
- package/dist/src/core/position-strings/ids.js +0 -79
- package/dist/src/core/position-strings/ids.js.map +0 -1
- package/dist/src/core/position-strings/index.d.ts +0 -5
- package/dist/src/core/position-strings/index.d.ts.map +0 -1
- package/dist/src/core/position-strings/index.js +0 -6
- package/dist/src/core/position-strings/index.js.map +0 -1
- package/dist/src/core/position-strings/position-source.d.ts +0 -128
- package/dist/src/core/position-strings/position-source.d.ts.map +0 -1
- package/dist/src/core/position-strings/position-source.js +0 -314
- package/dist/src/core/position-strings/position-source.js.map +0 -1
- package/dist/src/core/position-strings/test/cursors.test.d.ts +0 -2
- package/dist/src/core/position-strings/test/cursors.test.d.ts.map +0 -1
- package/dist/src/core/position-strings/test/cursors.test.js +0 -104
- package/dist/src/core/position-strings/test/cursors.test.js.map +0 -1
- package/dist/src/core/position-strings/test/find-position.test.d.ts +0 -2
- package/dist/src/core/position-strings/test/find-position.test.d.ts.map +0 -1
- package/dist/src/core/position-strings/test/find-position.test.js +0 -48
- package/dist/src/core/position-strings/test/find-position.test.js.map +0 -1
- package/dist/src/core/position-strings/test/fuzz.test.d.ts +0 -2
- package/dist/src/core/position-strings/test/fuzz.test.d.ts.map +0 -1
- package/dist/src/core/position-strings/test/fuzz.test.js +0 -78
- package/dist/src/core/position-strings/test/fuzz.test.js.map +0 -1
- package/dist/src/core/position-strings/test/ids.test.d.ts +0 -2
- package/dist/src/core/position-strings/test/ids.test.d.ts.map +0 -1
- package/dist/src/core/position-strings/test/ids.test.js +0 -17
- package/dist/src/core/position-strings/test/ids.test.js.map +0 -1
- package/dist/src/core/position-strings/test/manual.test.d.ts +0 -2
- package/dist/src/core/position-strings/test/manual.test.d.ts.map +0 -1
- package/dist/src/core/position-strings/test/manual.test.js +0 -307
- package/dist/src/core/position-strings/test/manual.test.js.map +0 -1
- package/dist/src/core/position-strings/test/util.d.ts +0 -6
- package/dist/src/core/position-strings/test/util.d.ts.map +0 -1
- package/dist/src/core/position-strings/test/util.js +0 -26
- package/dist/src/core/position-strings/test/util.js.map +0 -1
- package/dist/src/core/position-strings/util.d.ts +0 -8
- package/dist/src/core/position-strings/util.d.ts.map +0 -1
- package/dist/src/core/position-strings/util.js +0 -26
- package/dist/src/core/position-strings/util.js.map +0 -1
- package/dist/src/proto/create-edit-proposal.d.ts +0 -9
- package/dist/src/proto/create-edit-proposal.d.ts.map +0 -1
- package/dist/src/proto/create-edit-proposal.js +0 -54
- package/dist/src/proto/create-edit-proposal.js.map +0 -1
- package/dist/src/proto/create-edit-proposal.test.d.ts +0 -2
- package/dist/src/proto/create-edit-proposal.test.d.ts.map +0 -1
- package/dist/src/proto/create-edit-proposal.test.js +0 -140
- package/dist/src/proto/create-edit-proposal.test.js.map +0 -1
- package/dist/src/proto/create-membership-proposal.d.ts +0 -7
- package/dist/src/proto/create-membership-proposal.d.ts.map +0 -1
- package/dist/src/proto/create-membership-proposal.js +0 -26
- package/dist/src/proto/create-membership-proposal.js.map +0 -1
- package/dist/src/proto/create-subspace-proposal.d.ts +0 -7
- package/dist/src/proto/create-subspace-proposal.d.ts.map +0 -1
- package/dist/src/proto/create-subspace-proposal.js +0 -12
- package/dist/src/proto/create-subspace-proposal.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/src/base58.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export type Base58 = string;
|
|
2
|
-
/**
|
|
3
|
-
* Base58 encodes the given string value.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* import { v4 as uuidv4 } from "uuid";
|
|
8
|
-
*
|
|
9
|
-
* const uuid = uuidv4(); // 92539817-7989-4083-ab80-e9c2b2b66669
|
|
10
|
-
* const dashesRemoved = uuid.replaceAll(/-/g, ""); // 9253981779894083ab80e9c2b2b66669
|
|
11
|
-
* const encoded = encodeBase58(dashesRemoved)
|
|
12
|
-
* console.log(encoded) // K51CbDqxW35osbjPo5ZF77
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @param val string to encode as base58
|
|
16
|
-
* @returns the base58 encoded string
|
|
17
|
-
*/
|
|
18
|
-
export declare function encodeBase58(val: string): Base58;
|
|
19
|
-
export type UUID = string;
|
|
20
|
-
/**
|
|
21
|
-
* Expand the base58 encoded UUID back to its original UUID format
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* const uuid = 92539817-7989-4083-ab80-e9c2b2b66669;
|
|
26
|
-
* const encoded = encodeBase58(dashesRemoved); // K51CbDqxW35osbjPo5ZF77
|
|
27
|
-
* const decoded = decodeBase58ToUUID(encoded); // 92539817-7989-4083-ab80-e9c2b2b66669
|
|
28
|
-
*
|
|
29
|
-
* expect(decoded).toEqual(uuid);
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @param encoded base58 encoded UUID
|
|
33
|
-
* @returns the expanded UUID from the base58 encoded value
|
|
34
|
-
*/
|
|
35
|
-
export declare function decodeBase58ToUUID(encoded: string): UUID;
|
|
36
|
-
//# sourceMappingURL=base58.d.ts.map
|
package/dist/src/base58.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base58.d.ts","sourceRoot":"","sources":["../../src/base58.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAE5B;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAgBhD;AAED,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC;AAE1B;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAkBxD"}
|
package/dist/src/base58.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
const BASE58_ALLOWED_CHARS = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
2
|
-
/**
|
|
3
|
-
* Base58 encodes the given string value.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* import { v4 as uuidv4 } from "uuid";
|
|
8
|
-
*
|
|
9
|
-
* const uuid = uuidv4(); // 92539817-7989-4083-ab80-e9c2b2b66669
|
|
10
|
-
* const dashesRemoved = uuid.replaceAll(/-/g, ""); // 9253981779894083ab80e9c2b2b66669
|
|
11
|
-
* const encoded = encodeBase58(dashesRemoved)
|
|
12
|
-
* console.log(encoded) // K51CbDqxW35osbjPo5ZF77
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @param val string to encode as base58
|
|
16
|
-
* @returns the base58 encoded string
|
|
17
|
-
*/
|
|
18
|
-
export function encodeBase58(val) {
|
|
19
|
-
const hex = BigInt(`0x${val}`);
|
|
20
|
-
let remainder = hex;
|
|
21
|
-
const result = []; // Use an array to store encoded characters
|
|
22
|
-
while (remainder > 0n) {
|
|
23
|
-
const mod = remainder % 58n;
|
|
24
|
-
const base58CharAtMod = BASE58_ALLOWED_CHARS[Number(mod)];
|
|
25
|
-
if (base58CharAtMod) {
|
|
26
|
-
result.push(base58CharAtMod);
|
|
27
|
-
}
|
|
28
|
-
remainder = remainder / 58n;
|
|
29
|
-
}
|
|
30
|
-
// Reverse and join the array to get the final Base58 encoded string
|
|
31
|
-
return result.reverse().join('');
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Expand the base58 encoded UUID back to its original UUID format
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts
|
|
38
|
-
* const uuid = 92539817-7989-4083-ab80-e9c2b2b66669;
|
|
39
|
-
* const encoded = encodeBase58(dashesRemoved); // K51CbDqxW35osbjPo5ZF77
|
|
40
|
-
* const decoded = decodeBase58ToUUID(encoded); // 92539817-7989-4083-ab80-e9c2b2b66669
|
|
41
|
-
*
|
|
42
|
-
* expect(decoded).toEqual(uuid);
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* @param encoded base58 encoded UUID
|
|
46
|
-
* @returns the expanded UUID from the base58 encoded value
|
|
47
|
-
*/
|
|
48
|
-
export function decodeBase58ToUUID(encoded) {
|
|
49
|
-
let decoded = 0n;
|
|
50
|
-
for (const char of encoded) {
|
|
51
|
-
const index = BASE58_ALLOWED_CHARS.indexOf(char);
|
|
52
|
-
if (index === -1) {
|
|
53
|
-
throw new Error('Invalid Base58 character');
|
|
54
|
-
}
|
|
55
|
-
decoded = decoded * 58n + BigInt(index);
|
|
56
|
-
}
|
|
57
|
-
// Convert the bigint to a hex string, padded to 32 characters
|
|
58
|
-
let hexStr = decoded.toString(16);
|
|
59
|
-
hexStr = hexStr.padStart(32, '0'); // Ensure it is 32 characters
|
|
60
|
-
return [hexStr.slice(0, 8), hexStr.slice(8, 12), hexStr.slice(12, 16), hexStr.slice(16, 20), hexStr.slice(20)].join('-');
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=base58.js.map
|
package/dist/src/base58.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base58.js","sourceRoot":"","sources":["../../src/base58.ts"],"names":[],"mappings":"AAAA,MAAM,oBAAoB,GAAG,4DAA4D,CAAC;AAI1F;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;IAC/B,IAAI,SAAS,GAAG,GAAG,CAAC;IACpB,MAAM,MAAM,GAAa,EAAE,CAAC,CAAC,2CAA2C;IAExE,OAAO,SAAS,GAAG,EAAE,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,SAAS,GAAG,GAAG,CAAC;QAC5B,MAAM,eAAe,GAAG,oBAAoB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1D,IAAI,eAAe,EAAE,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAC/B,CAAC;QACD,SAAS,GAAG,SAAS,GAAG,GAAG,CAAC;IAC9B,CAAC;IAED,oEAAoE;IACpE,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACnC,CAAC;AAID;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,IAAI,OAAO,GAAG,EAAE,CAAC;IAEjB,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,oBAAoB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACjD,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,GAAG,OAAO,GAAG,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED,8DAA8D;IAC9D,IAAI,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAClC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,6BAA6B;IAEhE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CACjH,GAAG,CACJ,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base58.test.d.ts","sourceRoot":"","sources":["../../src/base58.test.ts"],"names":[],"mappings":""}
|
package/dist/src/base58.test.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base58.test.js","sourceRoot":"","sources":["../../src/base58.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../../src/core/ids/generate.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../../src/core/ids/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;AACjC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utilities for working with cursors in a collaborative list
|
|
3
|
-
* or text string.
|
|
4
|
-
*
|
|
5
|
-
* A *cursor* points to a particular spot in a list, in between
|
|
6
|
-
* two list elements (or text characters). This class handles
|
|
7
|
-
* cursors for lists that use our position strings.
|
|
8
|
-
*
|
|
9
|
-
* A cursor is represented as a string.
|
|
10
|
-
* Specifically, it is the position of the element
|
|
11
|
-
* to its left, or `PositionSource.FIRST` if it is at the beginning
|
|
12
|
-
* of the list. If that position is later deleted, the cursor stays the
|
|
13
|
-
* same, but its index shifts to next element on its left.
|
|
14
|
-
*
|
|
15
|
-
* You can use cursor strings as ordinary cursors, selection endpoints,
|
|
16
|
-
* range endpoints for a comment or formatting span, etc.
|
|
17
|
-
*/
|
|
18
|
-
export declare class Cursors {
|
|
19
|
-
private constructor();
|
|
20
|
-
/**
|
|
21
|
-
* Returns the cursor at `index` within the given list of positions. Invert with `Cursors.toIndex`.
|
|
22
|
-
*
|
|
23
|
-
* That is, the cursor is between the list elements at `index - 1` and `index`.
|
|
24
|
-
*
|
|
25
|
-
* If this method is inconvenient (e.g., the positions are in a database
|
|
26
|
-
* instead of an array), you can instead run the following algorithm yourself:
|
|
27
|
-
* - If `index` is 0, return `PositionSource.FIRST = ""`.
|
|
28
|
-
* - Else return `positions[index - 1]`.
|
|
29
|
-
*
|
|
30
|
-
* @param positions The target list's positions, in lexicographic order.
|
|
31
|
-
* There should be no duplicate positions.
|
|
32
|
-
*/
|
|
33
|
-
static fromIndex(index: number, positions: ArrayLike<string>): string;
|
|
34
|
-
/**
|
|
35
|
-
* Returns the current index of `cursor` within the given list of
|
|
36
|
-
* positions. Inverse of `Cursors.fromIndex`.
|
|
37
|
-
*
|
|
38
|
-
* That is, the cursor is between the list elements at `index - 1` and `index`.
|
|
39
|
-
*
|
|
40
|
-
* If this method is inconvenient (e.g., the positions are in a database
|
|
41
|
-
* instead of an array), you can instead compute
|
|
42
|
-
* `index` by finding the number of positions less than
|
|
43
|
-
* or equal to `position`.
|
|
44
|
-
* For example, in SQL, use:
|
|
45
|
-
* ```sql
|
|
46
|
-
* SELECT COUNT(*) FROM table WHERE position <= $position
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* See also: `findPosition`.
|
|
50
|
-
*
|
|
51
|
-
* @param positions The target list's positions, in lexicographic order.
|
|
52
|
-
* There should be no duplicate positions.
|
|
53
|
-
*/
|
|
54
|
-
static toIndex(cursor: string, positions: ArrayLike<string>): number;
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=cursors.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cursors.d.ts","sourceRoot":"","sources":["../../../../src/core/position-strings/cursors.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,OAAO;IAClB,OAAO;IAIP;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM;IAKrE;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM;CAMrE"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { findPosition } from './find-position.js';
|
|
2
|
-
import { PositionSource } from './position-source.js';
|
|
3
|
-
import { precond } from './util.js';
|
|
4
|
-
/**
|
|
5
|
-
* Utilities for working with cursors in a collaborative list
|
|
6
|
-
* or text string.
|
|
7
|
-
*
|
|
8
|
-
* A *cursor* points to a particular spot in a list, in between
|
|
9
|
-
* two list elements (or text characters). This class handles
|
|
10
|
-
* cursors for lists that use our position strings.
|
|
11
|
-
*
|
|
12
|
-
* A cursor is represented as a string.
|
|
13
|
-
* Specifically, it is the position of the element
|
|
14
|
-
* to its left, or `PositionSource.FIRST` if it is at the beginning
|
|
15
|
-
* of the list. If that position is later deleted, the cursor stays the
|
|
16
|
-
* same, but its index shifts to next element on its left.
|
|
17
|
-
*
|
|
18
|
-
* You can use cursor strings as ordinary cursors, selection endpoints,
|
|
19
|
-
* range endpoints for a comment or formatting span, etc.
|
|
20
|
-
*/
|
|
21
|
-
export class Cursors {
|
|
22
|
-
constructor() {
|
|
23
|
-
// Not instantiable.
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Returns the cursor at `index` within the given list of positions. Invert with `Cursors.toIndex`.
|
|
27
|
-
*
|
|
28
|
-
* That is, the cursor is between the list elements at `index - 1` and `index`.
|
|
29
|
-
*
|
|
30
|
-
* If this method is inconvenient (e.g., the positions are in a database
|
|
31
|
-
* instead of an array), you can instead run the following algorithm yourself:
|
|
32
|
-
* - If `index` is 0, return `PositionSource.FIRST = ""`.
|
|
33
|
-
* - Else return `positions[index - 1]`.
|
|
34
|
-
*
|
|
35
|
-
* @param positions The target list's positions, in lexicographic order.
|
|
36
|
-
* There should be no duplicate positions.
|
|
37
|
-
*/
|
|
38
|
-
static fromIndex(index, positions) {
|
|
39
|
-
precond(index >= 0 && index <= positions.length, 'Index out of bounds:', index, positions.length);
|
|
40
|
-
return index === 0 ? PositionSource.FIRST : positions[index - 1];
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Returns the current index of `cursor` within the given list of
|
|
44
|
-
* positions. Inverse of `Cursors.fromIndex`.
|
|
45
|
-
*
|
|
46
|
-
* That is, the cursor is between the list elements at `index - 1` and `index`.
|
|
47
|
-
*
|
|
48
|
-
* If this method is inconvenient (e.g., the positions are in a database
|
|
49
|
-
* instead of an array), you can instead compute
|
|
50
|
-
* `index` by finding the number of positions less than
|
|
51
|
-
* or equal to `position`.
|
|
52
|
-
* For example, in SQL, use:
|
|
53
|
-
* ```sql
|
|
54
|
-
* SELECT COUNT(*) FROM table WHERE position <= $position
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* See also: `findPosition`.
|
|
58
|
-
*
|
|
59
|
-
* @param positions The target list's positions, in lexicographic order.
|
|
60
|
-
* There should be no duplicate positions.
|
|
61
|
-
*/
|
|
62
|
-
static toIndex(cursor, positions) {
|
|
63
|
-
const { index, isPresent } = findPosition(cursor, positions);
|
|
64
|
-
// findPosition gives < elements, but we want <= elements.
|
|
65
|
-
// So if there's an == element, add 1.
|
|
66
|
-
return isPresent ? index + 1 : index;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=cursors.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cursors.js","sourceRoot":"","sources":["../../../../src/core/position-strings/cursors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,OAAO;IAClB;QACE,oBAAoB;IACtB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,SAAS,CAAC,KAAa,EAAE,SAA4B;QAC1D,OAAO,CAAC,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,SAAS,CAAC,MAAM,EAAE,sBAAsB,EAAE,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QAClG,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAE,SAAS,CAAC,KAAK,GAAG,CAAC,CAAY,CAAC;IAC/E,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,OAAO,CAAC,MAAc,EAAE,SAA4B;QACzD,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAC7D,0DAA0D;QAC1D,sCAAsC;QACtC,OAAO,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns `{ index, isPresent }`, where:
|
|
3
|
-
* - `index` is the current index of `position` in `positions`,
|
|
4
|
-
* or where it would be if added.
|
|
5
|
-
* - `isPresent` is true if `position` is present in `positions`.
|
|
6
|
-
*
|
|
7
|
-
* If this method is inconvenient (e.g., the positions are in a database
|
|
8
|
-
* instead of an array), you can instead compute
|
|
9
|
-
* `index` by finding the number of positions less than `position`.
|
|
10
|
-
* For example, in SQL, use:
|
|
11
|
-
* ```sql
|
|
12
|
-
* SELECT COUNT(*) FROM table WHERE position < $position
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* See also: `Cursors.toIndex`.
|
|
16
|
-
*
|
|
17
|
-
* @param positions The target list's positions, in lexicographic order.
|
|
18
|
-
* There should be no duplicate positions.
|
|
19
|
-
*/
|
|
20
|
-
export declare function findPosition(position: string, positions: ArrayLike<string>): {
|
|
21
|
-
index: number;
|
|
22
|
-
isPresent: boolean;
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=find-position.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"find-position.d.ts","sourceRoot":"","sources":["../../../../src/core/position-strings/find-position.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAqBlH"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { assert } from './util.js';
|
|
2
|
-
/**
|
|
3
|
-
* Returns `{ index, isPresent }`, where:
|
|
4
|
-
* - `index` is the current index of `position` in `positions`,
|
|
5
|
-
* or where it would be if added.
|
|
6
|
-
* - `isPresent` is true if `position` is present in `positions`.
|
|
7
|
-
*
|
|
8
|
-
* If this method is inconvenient (e.g., the positions are in a database
|
|
9
|
-
* instead of an array), you can instead compute
|
|
10
|
-
* `index` by finding the number of positions less than `position`.
|
|
11
|
-
* For example, in SQL, use:
|
|
12
|
-
* ```sql
|
|
13
|
-
* SELECT COUNT(*) FROM table WHERE position < $position
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* See also: `Cursors.toIndex`.
|
|
17
|
-
*
|
|
18
|
-
* @param positions The target list's positions, in lexicographic order.
|
|
19
|
-
* There should be no duplicate positions.
|
|
20
|
-
*/
|
|
21
|
-
export function findPosition(position, positions) {
|
|
22
|
-
// Binary search: index is the "rank" of position, computed using
|
|
23
|
-
// https://en.wikipedia.org/wiki/Binary_search_algorithm#Procedure_for_finding_the_leftmost_element
|
|
24
|
-
let L = 0;
|
|
25
|
-
let R = positions.length;
|
|
26
|
-
while (L < R) {
|
|
27
|
-
const m = Math.floor((L + R) / 2);
|
|
28
|
-
const left = positions[m];
|
|
29
|
-
if (left < position)
|
|
30
|
-
L = m + 1;
|
|
31
|
-
else
|
|
32
|
-
R = m;
|
|
33
|
-
}
|
|
34
|
-
const left = positions[L - 1];
|
|
35
|
-
assert((L === 0 || left < position) && (L === positions.length || left >= position), 'Bad binary search (positions out of order?):', position, L);
|
|
36
|
-
return { index: L, isPresent: left === position };
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=find-position.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"find-position.js","sourceRoot":"","sources":["../../../../src/core/position-strings/find-position.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,SAA4B;IACzE,iEAAiE;IACjE,mGAAmG;IACnG,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC;IACzB,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACb,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAClC,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAW,CAAC;QACpC,IAAI,IAAI,GAAG,QAAQ;YAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;;YAC1B,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAED,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,GAAG,CAAC,CAAW,CAAC;IAExC,MAAM,CACJ,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,SAAS,CAAC,MAAM,IAAI,IAAI,IAAI,QAAQ,CAAC,EAC5E,8CAA8C,EAC9C,QAAQ,EACR,CAAC,CACF,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;AACpD,CAAC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utitilies for generating `PositionSource` IDs
|
|
3
|
-
* (the `options.ID` constructor argument).
|
|
4
|
-
*/
|
|
5
|
-
export declare class IDs {
|
|
6
|
-
private constructor();
|
|
7
|
-
/**
|
|
8
|
-
* Default characters used in IDs: alphanumeric chars.
|
|
9
|
-
*/
|
|
10
|
-
static readonly DEFAULT_CHARS: string;
|
|
11
|
-
/**
|
|
12
|
-
* The default length of an ID, in characters.
|
|
13
|
-
*/
|
|
14
|
-
static readonly DEFAULT_LENGTH: number;
|
|
15
|
-
/**
|
|
16
|
-
* Returns a cryptographically random ID made of alphanumeric characters.
|
|
17
|
-
*
|
|
18
|
-
* @param options.length The length of the ID, in characters.
|
|
19
|
-
* Default: `IDs.DEFAULT_LENGTH`.
|
|
20
|
-
* @param options.chars The characters to draw from. Default: `IDs.DEFAULT_CHARS`.
|
|
21
|
-
*
|
|
22
|
-
* If specified, only the first 256 elements are used, and you achieve
|
|
23
|
-
* about `log_2(chars.length)` bits of entropy per `length`.
|
|
24
|
-
*/
|
|
25
|
-
static random(options?: {
|
|
26
|
-
length?: number;
|
|
27
|
-
chars?: string;
|
|
28
|
-
}): string;
|
|
29
|
-
/**
|
|
30
|
-
* Throws an error if `ID` does not satisfy the
|
|
31
|
-
* following requirements from `PositionSource`'s constructor:
|
|
32
|
-
* - It does not contain `','` or `'.'`.
|
|
33
|
-
* - The first character is lexicographically less than `'~'` (code point 126).
|
|
34
|
-
*/
|
|
35
|
-
static validate(ID: string): void;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=ids.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../../../src/core/position-strings/ids.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,qBAAa,GAAG;IACd,OAAO;IAIP;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAoE;IAUzG;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAK;IAE3C;;;;;;;;;OASG;IACH,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM;IA+BpE;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;CAKlC"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import * as crypto from 'crypto';
|
|
2
|
-
import { LastInternal, precond } from './util.js';
|
|
3
|
-
/**
|
|
4
|
-
* Utitilies for generating `PositionSource` IDs
|
|
5
|
-
* (the `options.ID` constructor argument).
|
|
6
|
-
*/
|
|
7
|
-
export class IDs {
|
|
8
|
-
constructor() {
|
|
9
|
-
// Not instantiable.
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Default characters used in IDs: alphanumeric chars.
|
|
13
|
-
*/
|
|
14
|
-
static DEFAULT_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
15
|
-
// Rationale for value 8:
|
|
16
|
-
// Each character of the ID gives us ~6 bits of entropy,
|
|
17
|
-
// for a total of ~48 bits. This gives a < 1%
|
|
18
|
-
// probability that two connected `PositionSource`s
|
|
19
|
-
// will ever choose the same IDs, even if we
|
|
20
|
-
// consider the total probability across 100,000,000
|
|
21
|
-
// documents with 1,000 IDs each
|
|
22
|
-
// (= 10 users x 100 days x 1 ID/user/day).
|
|
23
|
-
/**
|
|
24
|
-
* The default length of an ID, in characters.
|
|
25
|
-
*/
|
|
26
|
-
static DEFAULT_LENGTH = 8;
|
|
27
|
-
/**
|
|
28
|
-
* Returns a cryptographically random ID made of alphanumeric characters.
|
|
29
|
-
*
|
|
30
|
-
* @param options.length The length of the ID, in characters.
|
|
31
|
-
* Default: `IDs.DEFAULT_LENGTH`.
|
|
32
|
-
* @param options.chars The characters to draw from. Default: `IDs.DEFAULT_CHARS`.
|
|
33
|
-
*
|
|
34
|
-
* If specified, only the first 256 elements are used, and you achieve
|
|
35
|
-
* about `log_2(chars.length)` bits of entropy per `length`.
|
|
36
|
-
*/
|
|
37
|
-
static random(options) {
|
|
38
|
-
const length = options?.length ?? this.DEFAULT_LENGTH;
|
|
39
|
-
const chars = options?.chars ?? this.DEFAULT_CHARS;
|
|
40
|
-
const arr = new Array(length);
|
|
41
|
-
let randomValues = new Uint8Array(length);
|
|
42
|
-
if (typeof window === 'undefined') {
|
|
43
|
-
// Use Node crypto library.
|
|
44
|
-
// We use eval("require") to prevent Webpack from attempting
|
|
45
|
-
// to bundle the crypto module and complaining.
|
|
46
|
-
// In theory we should also be able to do this by
|
|
47
|
-
// adding "browser": {"crypto": false} to package.json,
|
|
48
|
-
// but that is not working, and besides, every user
|
|
49
|
-
// of this package would have to remember to do so.
|
|
50
|
-
// See https://github.com/webpack/webpack/issues/8826
|
|
51
|
-
const cryptoReal = crypto;
|
|
52
|
-
const randomBuffer = cryptoReal.randomBytes(length);
|
|
53
|
-
randomValues = new Uint8Array(randomBuffer);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
// Use browser crypto library.
|
|
57
|
-
window.crypto.getRandomValues(randomValues);
|
|
58
|
-
}
|
|
59
|
-
for (let i = 0; i < length; i++) {
|
|
60
|
-
// This will be biased if chars.length does not divide 256,
|
|
61
|
-
// but it will still give at least floor(log_2(chars.length))
|
|
62
|
-
// bits of entropy.
|
|
63
|
-
arr[i] = chars[randomValues[i] % chars.length];
|
|
64
|
-
}
|
|
65
|
-
return arr.join('');
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Throws an error if `ID` does not satisfy the
|
|
69
|
-
* following requirements from `PositionSource`'s constructor:
|
|
70
|
-
* - It does not contain `','` or `'.'`.
|
|
71
|
-
* - The first character is lexicographically less than `'~'` (code point 126).
|
|
72
|
-
*/
|
|
73
|
-
static validate(ID) {
|
|
74
|
-
precond(ID < LastInternal, 'ID must be less than', LastInternal, ':', ID);
|
|
75
|
-
precond(!ID.includes(','), "ID must not contain ',':", ID);
|
|
76
|
-
precond(!ID.includes('.'), "ID must not contain '.':", ID);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=ids.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../../../../src/core/position-strings/ids.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAElD;;;GAGG;AACH,MAAM,OAAO,GAAG;IACd;QACE,oBAAoB;IACtB,CAAC;IAED;;OAEG;IACH,MAAM,CAAU,aAAa,GAAW,gEAAgE,CAAC;IAEzG,yBAAyB;IACzB,wDAAwD;IACxD,+CAA+C;IAC/C,mDAAmD;IACnD,4CAA4C;IAC5C,oDAAoD;IACpD,gCAAgC;IAChC,2CAA2C;IAC3C;;OAEG;IACH,MAAM,CAAU,cAAc,GAAW,CAAC,CAAC;IAE3C;;;;;;;;;OASG;IACH,MAAM,CAAC,MAAM,CAAC,OAA6C;QACzD,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,IAAI,CAAC,cAAc,CAAC;QACtD,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC;QAEnD,MAAM,GAAG,GAAG,IAAI,KAAK,CAAS,MAAM,CAAC,CAAC;QACtC,IAAI,YAAY,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAClC,2BAA2B;YAC3B,4DAA4D;YAC5D,+CAA+C;YAC/C,iDAAiD;YACjD,uDAAuD;YACvD,mDAAmD;YACnD,mDAAmD;YACnD,qDAAqD;YACrD,MAAM,UAAU,GAAG,MAAM,CAAC;YAC1B,MAAM,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YACpD,YAAY,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,8BAA8B;YAC9B,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;QAC9C,CAAC;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAChC,2DAA2D;YAC3D,6DAA6D;YAC7D,mBAAmB;YACnB,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAE,YAAY,CAAC,CAAC,CAAY,GAAG,KAAK,CAAC,MAAM,CAAW,CAAC;QACvE,CAAC;QACD,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,EAAU;QACxB,OAAO,CAAC,EAAE,GAAG,YAAY,EAAE,sBAAsB,EAAE,YAAY,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QAC1E,OAAO,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,0BAA0B,EAAE,EAAE,CAAC,CAAC;QAC3D,OAAO,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,0BAA0B,EAAE,EAAE,CAAC,CAAC;IAC7D,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/position-strings/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/position-strings/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,6BAA6B"}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A source of lexicographically-ordered "position strings" for
|
|
3
|
-
* collaborative lists and text.
|
|
4
|
-
*
|
|
5
|
-
* In a collaborative list (or text string), you need a way to refer
|
|
6
|
-
* to "positions" within that list that:
|
|
7
|
-
* 1. Point to a specific list element (or text character).
|
|
8
|
-
* 2. Are global (all users agree on them) and immutable (they do not
|
|
9
|
-
* change over time).
|
|
10
|
-
* 3. Can be sorted.
|
|
11
|
-
* 4. Are unique, even if different users concurrently create positions
|
|
12
|
-
* at the same place.
|
|
13
|
-
*
|
|
14
|
-
* `PositionSource` gives you such positions, in the form
|
|
15
|
-
* of lexicographically-ordered strings. Specifically, `createBetween`
|
|
16
|
-
* returns a new "position string" in between two existing position strings.
|
|
17
|
-
*
|
|
18
|
-
* These strings have the bonus properties:
|
|
19
|
-
* - 5. (Non-Interleaving) If two `PositionSource`s concurrently create a (forward or backward)
|
|
20
|
-
* sequence of positions at the same place,
|
|
21
|
-
* their sequences will not be interleaved.
|
|
22
|
-
* For example, if
|
|
23
|
-
* Alice types "Hello" while Bob types "World" at the same place,
|
|
24
|
-
* and they each use a `PositionSource` to create a position for each
|
|
25
|
-
* character, then
|
|
26
|
-
* the resulting order will be "HelloWorld" or "WorldHello", not
|
|
27
|
-
* "HWeolrllod".
|
|
28
|
-
* - 6. If a `PositionSource` creates positions in a forward (increasing)
|
|
29
|
-
* sequence, their lengths as strings will only grow logarithmically,
|
|
30
|
-
* not linearly.
|
|
31
|
-
*
|
|
32
|
-
* Position strings are printable ASCII. Specifically, they
|
|
33
|
-
* contain alphanumeric characters, `','`, and `'.'`.
|
|
34
|
-
* Also, the special string `PositionSource.LAST` is `'~'`.
|
|
35
|
-
*
|
|
36
|
-
* Further reading:
|
|
37
|
-
* - [Fractional indexing](https://www.figma.com/blog/realtime-editing-of-ordered-sequences/#fractional-indexing),
|
|
38
|
-
* a related scheme that satisfies 1-3 but not 4-6.
|
|
39
|
-
* - [List CRDTs](https://mattweidner.com/2022/10/21/basic-list-crdt.html)
|
|
40
|
-
* and how they map to position strings. `PositionSource` uses an optimized
|
|
41
|
-
* variant of that link's string implementation.
|
|
42
|
-
* - [Paper about interleaving](https://www.repository.cam.ac.uk/handle/1810/290391)
|
|
43
|
-
* in collaborative text editors.
|
|
44
|
-
*/
|
|
45
|
-
export declare class PositionSource {
|
|
46
|
-
/**
|
|
47
|
-
* A string that is less than all positions.
|
|
48
|
-
*
|
|
49
|
-
* Value: `""`.
|
|
50
|
-
*/
|
|
51
|
-
static readonly FIRST: string;
|
|
52
|
-
/**
|
|
53
|
-
* A string that is greater than all positions.
|
|
54
|
-
*
|
|
55
|
-
* Value: `"~"`.
|
|
56
|
-
*/
|
|
57
|
-
static readonly LAST: string;
|
|
58
|
-
/**
|
|
59
|
-
* The unique ID for this `PositionSource`.
|
|
60
|
-
*/
|
|
61
|
-
readonly ID: string;
|
|
62
|
-
/**
|
|
63
|
-
* Our waypoints' long name: `,${ID}.`.
|
|
64
|
-
*/
|
|
65
|
-
private readonly longName;
|
|
66
|
-
/**
|
|
67
|
-
* Variant of longName used for a position's first ID: `${ID}.`.
|
|
68
|
-
* (Otherwise every position would start with a redundant ','.)
|
|
69
|
-
*/
|
|
70
|
-
private readonly firstName;
|
|
71
|
-
/**
|
|
72
|
-
* For each waypoint that we created, maps a prefix (see getPrefix)
|
|
73
|
-
* for that waypoint to its last (most recent) valueSeq.
|
|
74
|
-
* We always store the right-side version (odd valueSeq).
|
|
75
|
-
*/
|
|
76
|
-
private lastValueSeqs;
|
|
77
|
-
/**
|
|
78
|
-
* Constructs a new `PositionSource`.
|
|
79
|
-
*
|
|
80
|
-
* It is okay to share a single `PositionSource` between
|
|
81
|
-
* all documents (lists/text strings) in the same JavaScript runtime.
|
|
82
|
-
*
|
|
83
|
-
* For efficiency (shorter position strings),
|
|
84
|
-
* within each JavaScript runtime, you should not use
|
|
85
|
-
* more than one `PositionSource` for the same document.
|
|
86
|
-
* An exception is if multiple logical users share the same runtime;
|
|
87
|
-
* we then recommend one `PositionSource` per user.
|
|
88
|
-
*
|
|
89
|
-
* @param options.ID A unique ID for this `PositionSource`. Defaults to
|
|
90
|
-
* `IDs.random()`.
|
|
91
|
-
*
|
|
92
|
-
* If provided, `options.ID` must satisfy:
|
|
93
|
-
* - It is unique across the entire collaborative application, i.e.,
|
|
94
|
-
* all `PositionSource`s whose positions may be compared to ours. This
|
|
95
|
-
* includes past `PositionSource`s, even if they correspond to the same
|
|
96
|
-
* user/device.
|
|
97
|
-
* - It does not contain `','` or `'.'`.
|
|
98
|
-
* - The first character is lexicographically less than `'~'` (code point 126).
|
|
99
|
-
*
|
|
100
|
-
* If `options.ID` contains non-alphanumeric characters, then created
|
|
101
|
-
* positions will contain those characters in addition to
|
|
102
|
-
* alphanumeric characters, `','`, and `'.'`.
|
|
103
|
-
*/
|
|
104
|
-
constructor(options?: {
|
|
105
|
-
ID?: string;
|
|
106
|
-
});
|
|
107
|
-
/**
|
|
108
|
-
* Returns a new position between `left` and `right`
|
|
109
|
-
* (`left < new < right`).
|
|
110
|
-
*
|
|
111
|
-
* The new position is unique across the entire collaborative application,
|
|
112
|
-
* even in the face of concurrent calls to this method on other
|
|
113
|
-
* `PositionSource`s.
|
|
114
|
-
*
|
|
115
|
-
* @param left Defaults to `PositionSource.FIRST` (insert at the beginning).
|
|
116
|
-
*
|
|
117
|
-
* @param right Defaults to `PositionSource.LAST` (insert at the end).
|
|
118
|
-
*/
|
|
119
|
-
createBetween(left?: string, right?: string): string;
|
|
120
|
-
/**
|
|
121
|
-
* Appends a wayoint to the given ancestor (= prefix adjusted for
|
|
122
|
-
* side), returning a unique new position using that waypoint.
|
|
123
|
-
*
|
|
124
|
-
* lastValueSeqs is also updated as needed for the waypoint.
|
|
125
|
-
*/
|
|
126
|
-
private appendWaypoint;
|
|
127
|
-
}
|
|
128
|
-
//# sourceMappingURL=position-source.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"position-source.d.ts","sourceRoot":"","sources":["../../../../src/core/position-strings/position-source.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,qBAAa,cAAc;IACzB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAM;IACnC;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAgB;IAE5C;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IAEnC;;;;OAIG;IACH,OAAO,CAAC,aAAa,CAA6B;IAElD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;gBACS,OAAO,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE;IASrC;;;;;;;;;;;OAWG;IACH,aAAa,CAAC,IAAI,GAAE,MAA6B,EAAE,KAAK,GAAE,MAA4B,GAAG,MAAM;IA+C/F;;;;;OAKG;IACH,OAAO,CAAC,cAAc;CA2BvB"}
|