cojson 0.6.6 → 0.7.0-alpha.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/.eslintrc.cjs +1 -0
- package/.turbo/turbo-build.log +35 -0
- package/CHANGELOG.md +6 -0
- package/dist/coValue.js.map +1 -1
- package/dist/coValueCore.js.map +1 -1
- package/dist/coValues/account.js +5 -5
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +39 -58
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +20 -61
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +14 -64
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/group.js +57 -59
- package/dist/coValues/group.js.map +1 -1
- package/dist/coreToCoValue.js +17 -12
- package/dist/coreToCoValue.js.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/localNode.js +54 -38
- package/dist/localNode.js.map +1 -1
- package/dist/permissions.js +2 -2
- package/dist/permissions.js.map +1 -1
- package/dist/sync.js +3 -3
- package/dist/sync.js.map +1 -1
- package/dist/tests/testUtils.js +6 -11
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/typeUtils/expectGroup.js +2 -2
- package/dist/typeUtils/expectGroup.js.map +1 -1
- package/dist/typeUtils/isCoValue.js +8 -8
- package/dist/typeUtils/isCoValue.js.map +1 -1
- package/package.json +52 -53
- package/src/coValue.ts +21 -21
- package/src/coValueCore.ts +8 -8
- package/src/coValues/account.ts +14 -26
- package/src/coValues/coList.ts +58 -97
- package/src/coValues/coMap.ts +27 -129
- package/src/coValues/coStream.ts +31 -137
- package/src/coValues/group.ts +52 -46
- package/src/coreToCoValue.ts +16 -12
- package/src/index.ts +27 -36
- package/src/jsonValue.ts +1 -1
- package/src/localNode.ts +88 -75
- package/src/media.ts +4 -4
- package/src/permissions.ts +2 -2
- package/src/sync.ts +3 -3
- package/src/tests/account.test.ts +12 -12
- package/src/tests/coValue.test.ts +149 -182
- package/src/tests/coValueCore.test.ts +8 -3
- package/src/tests/crypto.test.ts +7 -0
- package/src/tests/group.test.ts +13 -6
- package/src/tests/permissions.test.ts +648 -840
- package/src/tests/sync.test.ts +44 -68
- package/src/tests/testUtils.ts +6 -11
- package/src/typeUtils/expectGroup.ts +4 -4
- package/src/typeUtils/isCoValue.ts +11 -11
package/src/coValue.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { JsonObject, JsonValue } from "./jsonValue.js";
|
|
2
2
|
import { RawCoID } from "./ids.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { RawCoMap } from "./coValues/coMap.js";
|
|
4
|
+
import { RawBinaryCoStream, RawCoStream } from "./coValues/coStream.js";
|
|
5
|
+
import { RawCoList } from "./coValues/coList.js";
|
|
6
6
|
import { CoValueCore } from "./coValueCore.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { RawGroup } from "./coValues/group.js";
|
|
8
|
+
import { RawAccount, Profile } from "./index.js";
|
|
9
9
|
|
|
10
|
-
export type CoID<T extends
|
|
10
|
+
export type CoID<T extends RawCoValue> = RawCoID & {
|
|
11
11
|
readonly __type: T;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export interface
|
|
14
|
+
export interface RawCoValue {
|
|
15
15
|
/** The `CoValue`'s (precisely typed) `CoID` */
|
|
16
16
|
id: CoID<this>;
|
|
17
17
|
core: CoValueCore;
|
|
@@ -20,7 +20,7 @@ export interface CoValue {
|
|
|
20
20
|
/** The `CoValue`'s (precisely typed) static metadata */
|
|
21
21
|
headerMeta: JsonObject | null;
|
|
22
22
|
/** The `Group` this `CoValue` belongs to (determining permissions) */
|
|
23
|
-
group:
|
|
23
|
+
group: RawGroup;
|
|
24
24
|
/** Returns an immutable JSON presentation of this `CoValue` */
|
|
25
25
|
toJSON(): JsonValue;
|
|
26
26
|
atTime(time: number): this;
|
|
@@ -34,35 +34,35 @@ export interface CoValue {
|
|
|
34
34
|
subscribe(listener: (coValue: this) => void): () => void;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export type
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
|
|
|
37
|
+
export type AnyRawCoValue =
|
|
38
|
+
| RawCoMap
|
|
39
|
+
| RawGroup
|
|
40
|
+
| RawAccount
|
|
41
41
|
| Profile
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
42
|
+
| RawCoList
|
|
43
|
+
| RawCoStream
|
|
44
|
+
| RawBinaryCoStream;
|
|
45
45
|
|
|
46
|
-
export function expectMap(content:
|
|
46
|
+
export function expectMap(content: RawCoValue): RawCoMap {
|
|
47
47
|
if (content.type !== "comap") {
|
|
48
48
|
throw new Error("Expected map");
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
return content as
|
|
51
|
+
return content as RawCoMap;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
export function expectList(content:
|
|
54
|
+
export function expectList(content: RawCoValue): RawCoList {
|
|
55
55
|
if (content.type !== "colist") {
|
|
56
56
|
throw new Error("Expected list");
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
return content as
|
|
59
|
+
return content as RawCoList;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
export function expectStream(content:
|
|
62
|
+
export function expectStream(content: RawCoValue): RawCoStream {
|
|
63
63
|
if (content.type !== "costream") {
|
|
64
64
|
throw new Error("Expected stream");
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
return content as
|
|
67
|
+
return content as RawCoStream;
|
|
68
68
|
}
|
package/src/coValueCore.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyRawCoValue, RawCoValue } from "./coValue.js";
|
|
2
2
|
import {
|
|
3
3
|
Encrypted,
|
|
4
4
|
Hash,
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
determineValidTransactions,
|
|
24
24
|
isKeyForKeyField,
|
|
25
25
|
} from "./permissions.js";
|
|
26
|
-
import {
|
|
26
|
+
import { RawGroup } from "./coValues/group.js";
|
|
27
27
|
import { LocalNode } from "./localNode.js";
|
|
28
28
|
import { CoValueKnownState, NewContentMessage } from "./sync.js";
|
|
29
29
|
import { AgentID, RawCoID, SessionID, TransactionID } from "./ids.js";
|
|
@@ -37,7 +37,7 @@ import { accountOrAgentIDfromSessionID } from "./typeUtils/accountOrAgentIDfromS
|
|
|
37
37
|
export const MAX_RECOMMENDED_TX_SIZE = 100 * 1024;
|
|
38
38
|
|
|
39
39
|
export type CoValueHeader = {
|
|
40
|
-
type:
|
|
40
|
+
type: AnyRawCoValue["type"];
|
|
41
41
|
ruleset: RulesetDef;
|
|
42
42
|
meta: JsonObject | null;
|
|
43
43
|
createdAt: `2${string}` | null;
|
|
@@ -95,8 +95,8 @@ export class CoValueCore {
|
|
|
95
95
|
node: LocalNode;
|
|
96
96
|
header: CoValueHeader;
|
|
97
97
|
_sessionLogs: Map<SessionID, SessionLog>;
|
|
98
|
-
_cachedContent?:
|
|
99
|
-
listeners: Set<(content?:
|
|
98
|
+
_cachedContent?: RawCoValue;
|
|
99
|
+
listeners: Set<(content?: RawCoValue) => void> = new Set();
|
|
100
100
|
_decryptionCache: {
|
|
101
101
|
[key: Encrypted<JsonValue[], JsonValue>]: JsonValue[] | undefined;
|
|
102
102
|
} = {};
|
|
@@ -409,7 +409,7 @@ export class CoValueCore {
|
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
411
|
|
|
412
|
-
subscribe(listener: (content?:
|
|
412
|
+
subscribe(listener: (content?: RawCoValue) => void): () => void {
|
|
413
413
|
this.listeners.add(listener);
|
|
414
414
|
listener(this.getCurrentContent());
|
|
415
415
|
|
|
@@ -533,7 +533,7 @@ export class CoValueCore {
|
|
|
533
533
|
return success;
|
|
534
534
|
}
|
|
535
535
|
|
|
536
|
-
getCurrentContent(options?: { ignorePrivateTransactions: true }):
|
|
536
|
+
getCurrentContent(options?: { ignorePrivateTransactions: true }): RawCoValue {
|
|
537
537
|
if (!options?.ignorePrivateTransactions && this._cachedContent) {
|
|
538
538
|
return this._cachedContent;
|
|
539
539
|
}
|
|
@@ -741,7 +741,7 @@ export class CoValueCore {
|
|
|
741
741
|
}
|
|
742
742
|
}
|
|
743
743
|
|
|
744
|
-
getGroup():
|
|
744
|
+
getGroup(): RawGroup {
|
|
745
745
|
if (this.header.ruleset.type !== "ownedByGroup") {
|
|
746
746
|
throw new Error("Only values owned by groups have groups");
|
|
747
747
|
}
|
package/src/coValues/account.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CoValueCore, CoValueHeader } from "../coValueCore.js";
|
|
2
|
-
import { CoID,
|
|
2
|
+
import { CoID, RawCoValue } from "../coValue.js";
|
|
3
3
|
import {
|
|
4
4
|
AgentSecret,
|
|
5
5
|
SealerID,
|
|
@@ -13,8 +13,8 @@ import {
|
|
|
13
13
|
getAgentSignerSecret,
|
|
14
14
|
} from "../crypto.js";
|
|
15
15
|
import { AgentID } from "../ids.js";
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
16
|
+
import { RawCoMap } from "./coMap.js";
|
|
17
|
+
import { RawGroup, InviteSecret } from "./group.js";
|
|
18
18
|
import { LocalNode } from "../index.js";
|
|
19
19
|
|
|
20
20
|
export function accountHeaderForInitialAgentSecret(
|
|
@@ -32,11 +32,9 @@ export function accountHeaderForInitialAgentSecret(
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export class
|
|
36
|
-
P extends Profile = Profile,
|
|
37
|
-
R extends CoMap = CoMap,
|
|
35
|
+
export class RawAccount<
|
|
38
36
|
Meta extends AccountMeta = AccountMeta
|
|
39
|
-
> extends
|
|
37
|
+
> extends RawGroup<Meta> {
|
|
40
38
|
currentAgentID(): AgentID {
|
|
41
39
|
const agents = this.keys().filter((k): k is AgentID =>
|
|
42
40
|
k.startsWith("sealer_")
|
|
@@ -64,12 +62,8 @@ export interface ControlledAccountOrAgent {
|
|
|
64
62
|
}
|
|
65
63
|
|
|
66
64
|
/** @hidden */
|
|
67
|
-
export class
|
|
68
|
-
|
|
69
|
-
R extends CoMap = CoMap,
|
|
70
|
-
Meta extends AccountMeta = AccountMeta
|
|
71
|
-
>
|
|
72
|
-
extends Account<P, R, Meta>
|
|
65
|
+
export class RawControlledAccount<Meta extends AccountMeta = AccountMeta>
|
|
66
|
+
extends RawAccount<Meta>
|
|
73
67
|
implements ControlledAccountOrAgent
|
|
74
68
|
{
|
|
75
69
|
agentSecret: AgentSecret;
|
|
@@ -88,7 +82,7 @@ export class ControlledAccount<
|
|
|
88
82
|
return this.core.node.createGroup();
|
|
89
83
|
}
|
|
90
84
|
|
|
91
|
-
async acceptInvite<T extends
|
|
85
|
+
async acceptInvite<T extends RawCoValue>(
|
|
92
86
|
groupOrOwnedValueID: CoID<T>,
|
|
93
87
|
inviteSecret: InviteSecret
|
|
94
88
|
): Promise<void> {
|
|
@@ -117,9 +111,7 @@ export class ControlledAccount<
|
|
|
117
111
|
}
|
|
118
112
|
|
|
119
113
|
/** @hidden */
|
|
120
|
-
export class ControlledAgent
|
|
121
|
-
implements ControlledAccountOrAgent
|
|
122
|
-
{
|
|
114
|
+
export class ControlledAgent implements ControlledAccountOrAgent {
|
|
123
115
|
agentSecret: AgentSecret;
|
|
124
116
|
|
|
125
117
|
constructor(agentSecret: AgentSecret) {
|
|
@@ -152,7 +144,7 @@ export class ControlledAgent
|
|
|
152
144
|
}
|
|
153
145
|
|
|
154
146
|
export type AccountMeta = { type: "account" };
|
|
155
|
-
export type AccountID = CoID<
|
|
147
|
+
export type AccountID = CoID<RawAccount>;
|
|
156
148
|
|
|
157
149
|
export type ProfileShape = {
|
|
158
150
|
name: string;
|
|
@@ -162,14 +154,10 @@ export type ProfileMeta = { type: "profile" };
|
|
|
162
154
|
export class Profile<
|
|
163
155
|
Shape extends ProfileShape = ProfileShape,
|
|
164
156
|
Meta extends ProfileMeta = ProfileMeta
|
|
165
|
-
> extends
|
|
157
|
+
> extends RawCoMap<Shape, Meta> {}
|
|
166
158
|
|
|
167
|
-
export type
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
Meta extends AccountMeta = AccountMeta
|
|
171
|
-
> = (
|
|
172
|
-
account: ControlledAccount<P, R, Meta>,
|
|
173
|
-
profile: P,
|
|
159
|
+
export type RawAccountMigration<Meta extends AccountMeta = AccountMeta> = (
|
|
160
|
+
account: RawControlledAccount<Meta>,
|
|
161
|
+
profile: RawCoMap,
|
|
174
162
|
localNode: LocalNode
|
|
175
163
|
) => void | Promise<void>;
|
package/src/coValues/coList.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { JsonObject, JsonValue } from "../jsonValue.js";
|
|
2
|
-
import { CoID,
|
|
2
|
+
import { CoID, RawCoValue } from "../coValue.js";
|
|
3
3
|
import { isCoValue } from "../typeUtils/isCoValue.js";
|
|
4
4
|
import { CoValueCore } from "../coValueCore.js";
|
|
5
5
|
import { accountOrAgentIDfromSessionID } from "../typeUtils/accountOrAgentIDfromSessionID.js";
|
|
6
6
|
import { AgentID, SessionID, TransactionID } from "../ids.js";
|
|
7
7
|
import { AccountID } from "./account.js";
|
|
8
|
-
import {
|
|
8
|
+
import { RawGroup } from "./group.js";
|
|
9
9
|
|
|
10
10
|
type OpID = TransactionID & { changeIdx: number };
|
|
11
11
|
|
|
@@ -41,10 +41,10 @@ type DeletionEntry = {
|
|
|
41
41
|
deletionID: OpID;
|
|
42
42
|
} & DeletionOpPayload;
|
|
43
43
|
|
|
44
|
-
export class
|
|
44
|
+
export class RawCoListView<
|
|
45
45
|
Item extends JsonValue = JsonValue,
|
|
46
|
-
Meta extends JsonObject | null = null
|
|
47
|
-
> implements
|
|
46
|
+
Meta extends JsonObject | null = null,
|
|
47
|
+
> implements RawCoValue
|
|
48
48
|
{
|
|
49
49
|
/** @category 6. Meta */
|
|
50
50
|
id: CoID<this>;
|
|
@@ -209,7 +209,7 @@ export class CoListView<
|
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
/** @category 6. Meta */
|
|
212
|
-
get group():
|
|
212
|
+
get group(): RawGroup {
|
|
213
213
|
return this.core.getGroup();
|
|
214
214
|
}
|
|
215
215
|
|
|
@@ -306,7 +306,9 @@ export class CoListView<
|
|
|
306
306
|
opID,
|
|
307
307
|
});
|
|
308
308
|
}
|
|
309
|
-
|
|
309
|
+
// traverse successors in reverse for correct insertion behavior
|
|
310
|
+
for (let i = entry.successors.length - 1; i >= 0; i--) {
|
|
311
|
+
const successor = entry.successors[i]!;
|
|
310
312
|
this.fillArrayFromOpID(successor, arr);
|
|
311
313
|
}
|
|
312
314
|
}
|
|
@@ -393,14 +395,14 @@ export class CoListView<
|
|
|
393
395
|
}
|
|
394
396
|
}
|
|
395
397
|
|
|
396
|
-
export class
|
|
398
|
+
export class RawCoList<
|
|
397
399
|
Item extends JsonValue = JsonValue,
|
|
398
|
-
Meta extends JsonObject | null = JsonObject | null
|
|
400
|
+
Meta extends JsonObject | null = JsonObject | null,
|
|
399
401
|
>
|
|
400
|
-
extends
|
|
401
|
-
implements
|
|
402
|
+
extends RawCoListView<Item, Meta>
|
|
403
|
+
implements RawCoValue
|
|
402
404
|
{
|
|
403
|
-
/**
|
|
405
|
+
/** Appends `item` after the item currently at index `after`.
|
|
404
406
|
*
|
|
405
407
|
* If `privacy` is `"private"` **(default)**, `item` is encrypted in the transaction, only readable by other members of the group this `CoList` belongs to. Not even sync servers can see the content in plaintext.
|
|
406
408
|
*
|
|
@@ -412,7 +414,7 @@ export class CoList<
|
|
|
412
414
|
item: Item,
|
|
413
415
|
after?: number,
|
|
414
416
|
privacy: "private" | "trusting" = "private"
|
|
415
|
-
)
|
|
417
|
+
) {
|
|
416
418
|
const entries = this.entries();
|
|
417
419
|
after =
|
|
418
420
|
after === undefined
|
|
@@ -444,11 +446,17 @@ export class CoList<
|
|
|
444
446
|
privacy
|
|
445
447
|
);
|
|
446
448
|
|
|
447
|
-
|
|
449
|
+
const listAfter = new RawCoList(this.core) as this;
|
|
450
|
+
|
|
451
|
+
this.afterStart = listAfter.afterStart;
|
|
452
|
+
this.beforeEnd = listAfter.beforeEnd;
|
|
453
|
+
this.insertions = listAfter.insertions;
|
|
454
|
+
this.deletionsByInsertion = listAfter.deletionsByInsertion;
|
|
455
|
+
this._cachedEntries = undefined;
|
|
448
456
|
}
|
|
449
457
|
|
|
450
458
|
/**
|
|
451
|
-
*
|
|
459
|
+
* Prepends `item` before the item currently at index `before`.
|
|
452
460
|
*
|
|
453
461
|
* If `privacy` is `"private"` **(default)**, `item` is encrypted in the transaction, only readable by other members of the group this `CoList` belongs to. Not even sync servers can see the content in plaintext.
|
|
454
462
|
*
|
|
@@ -460,7 +468,7 @@ export class CoList<
|
|
|
460
468
|
item: Item,
|
|
461
469
|
before?: number,
|
|
462
470
|
privacy: "private" | "trusting" = "private"
|
|
463
|
-
)
|
|
471
|
+
) {
|
|
464
472
|
const entries = this.entries();
|
|
465
473
|
before = before === undefined ? 0 : before;
|
|
466
474
|
let opIDAfter;
|
|
@@ -491,10 +499,16 @@ export class CoList<
|
|
|
491
499
|
privacy
|
|
492
500
|
);
|
|
493
501
|
|
|
494
|
-
|
|
502
|
+
const listAfter = new RawCoList(this.core) as this;
|
|
503
|
+
|
|
504
|
+
this.afterStart = listAfter.afterStart;
|
|
505
|
+
this.beforeEnd = listAfter.beforeEnd;
|
|
506
|
+
this.insertions = listAfter.insertions;
|
|
507
|
+
this.deletionsByInsertion = listAfter.deletionsByInsertion;
|
|
508
|
+
this._cachedEntries = undefined;
|
|
495
509
|
}
|
|
496
510
|
|
|
497
|
-
/**
|
|
511
|
+
/** Deletes the item at index `at`.
|
|
498
512
|
*
|
|
499
513
|
* If `privacy` is `"private"` **(default)**, the fact of this deletion is encrypted in the transaction, only readable by other members of the group this `CoList` belongs to. Not even sync servers can see the content in plaintext.
|
|
500
514
|
*
|
|
@@ -502,7 +516,7 @@ export class CoList<
|
|
|
502
516
|
*
|
|
503
517
|
* @category 2. Editing
|
|
504
518
|
**/
|
|
505
|
-
delete(at: number, privacy: "private" | "trusting" = "private")
|
|
519
|
+
delete(at: number, privacy: "private" | "trusting" = "private") {
|
|
506
520
|
const entries = this.entries();
|
|
507
521
|
const entry = entries[at];
|
|
508
522
|
if (!entry) {
|
|
@@ -518,48 +532,8 @@ export class CoList<
|
|
|
518
532
|
privacy
|
|
519
533
|
);
|
|
520
534
|
|
|
521
|
-
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
/** @category 2. Editing */
|
|
525
|
-
mutate(mutator: (mutable: MutableCoList<Item, Meta>) => void): this {
|
|
526
|
-
const mutable = new MutableCoList<Item, Meta>(this.core);
|
|
527
|
-
mutator(mutable);
|
|
528
|
-
return new CoList(this.core) as this;
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
/** @deprecated Use `mutate` instead. */
|
|
532
|
-
edit(mutator: (mutable: MutableCoList<Item, Meta>) => void): this {
|
|
533
|
-
return this.mutate(mutator);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
535
|
+
const listAfter = new RawCoList(this.core) as this;
|
|
536
536
|
|
|
537
|
-
export class MutableCoList<
|
|
538
|
-
Item extends JsonValue = JsonValue,
|
|
539
|
-
Meta extends JsonObject | null = JsonObject | null
|
|
540
|
-
>
|
|
541
|
-
extends CoListView<Item, Meta>
|
|
542
|
-
implements CoValue
|
|
543
|
-
{
|
|
544
|
-
/** Appends `item` after the item currently at index `after`.
|
|
545
|
-
*
|
|
546
|
-
* If `privacy` is `"private"` **(default)**, `item` is encrypted in the transaction, only readable by other members of the group this `CoList` belongs to. Not even sync servers can see the content in plaintext.
|
|
547
|
-
*
|
|
548
|
-
* If `privacy` is `"trusting"`, `item` is stored in plaintext in the transaction, visible to everyone who gets a hold of it, including sync servers.
|
|
549
|
-
*
|
|
550
|
-
* @category 2. Mutating
|
|
551
|
-
**/
|
|
552
|
-
append(
|
|
553
|
-
item: Item,
|
|
554
|
-
after?: number,
|
|
555
|
-
privacy: "private" | "trusting" = "private"
|
|
556
|
-
): void {
|
|
557
|
-
const listAfter = CoList.prototype.append.call(
|
|
558
|
-
this,
|
|
559
|
-
item,
|
|
560
|
-
after,
|
|
561
|
-
privacy
|
|
562
|
-
) as CoList<Item, Meta>;
|
|
563
537
|
this.afterStart = listAfter.afterStart;
|
|
564
538
|
this.beforeEnd = listAfter.beforeEnd;
|
|
565
539
|
this.insertions = listAfter.insertions;
|
|
@@ -567,46 +541,33 @@ export class MutableCoList<
|
|
|
567
541
|
this._cachedEntries = undefined;
|
|
568
542
|
}
|
|
569
543
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
*
|
|
574
|
-
* If `privacy` is `"trusting"`, `item` is stored in plaintext in the transaction, visible to everyone who gets a hold of it, including sync servers.
|
|
575
|
-
*
|
|
576
|
-
* * @category 2. Mutating
|
|
577
|
-
**/
|
|
578
|
-
prepend(
|
|
579
|
-
item: Item,
|
|
580
|
-
before?: number,
|
|
544
|
+
replace(
|
|
545
|
+
at: number,
|
|
546
|
+
newItem: Item,
|
|
581
547
|
privacy: "private" | "trusting" = "private"
|
|
582
|
-
)
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
) as CoList<Item, Meta>;
|
|
589
|
-
this.afterStart = listAfter.afterStart;
|
|
590
|
-
this.beforeEnd = listAfter.beforeEnd;
|
|
591
|
-
this.insertions = listAfter.insertions;
|
|
592
|
-
this.deletionsByInsertion = listAfter.deletionsByInsertion;
|
|
593
|
-
this._cachedEntries = undefined;
|
|
594
|
-
}
|
|
548
|
+
) {
|
|
549
|
+
const entries = this.entries();
|
|
550
|
+
const entry = entries[at];
|
|
551
|
+
if (!entry) {
|
|
552
|
+
throw new Error("Invalid index " + at);
|
|
553
|
+
}
|
|
595
554
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
555
|
+
this.core.makeTransaction(
|
|
556
|
+
[
|
|
557
|
+
{
|
|
558
|
+
op: "app",
|
|
559
|
+
value: isCoValue(newItem) ? newItem.id : newItem,
|
|
560
|
+
after: entry.opID,
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
op: "del",
|
|
564
|
+
insertion: entry.opID,
|
|
565
|
+
},
|
|
566
|
+
],
|
|
608
567
|
privacy
|
|
609
|
-
)
|
|
568
|
+
);
|
|
569
|
+
const listAfter = new RawCoList(this.core) as this;
|
|
570
|
+
|
|
610
571
|
this.afterStart = listAfter.afterStart;
|
|
611
572
|
this.beforeEnd = listAfter.beforeEnd;
|
|
612
573
|
this.insertions = listAfter.insertions;
|