cojson 0.7.34 → 0.7.35-unique.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/.turbo/turbo-build.log +7 -2
- package/.turbo/turbo-test.log +251 -318
- package/CHANGELOG.md +6 -0
- package/dist/coValueCore.js.map +1 -1
- package/dist/coValues/account.js +2 -2
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/group.js +8 -8
- package/dist/coValues/group.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/localNode.js +2 -2
- package/dist/localNode.js.map +1 -1
- package/dist/permissions.js.map +1 -1
- package/dist/tests/sync.test.js.map +1 -1
- package/dist/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
- package/dist/typeUtils/isAccountID.js.map +1 -1
- package/package.json +1 -1
- package/src/coValueCore.ts +7 -7
- package/src/coValues/account.ts +5 -5
- package/src/coValues/coList.ts +4 -4
- package/src/coValues/coMap.ts +3 -3
- package/src/coValues/coStream.ts +8 -8
- package/src/coValues/group.ts +15 -11
- package/src/ids.ts +2 -2
- package/src/index.ts +4 -2
- package/src/localNode.ts +12 -11
- package/src/permissions.ts +5 -5
- package/src/tests/sync.test.ts +3 -3
- package/src/typeUtils/accountOrAgentIDfromSessionID.ts +3 -3
- package/src/typeUtils/isAccountID.ts +2 -2
package/src/coValues/account.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CoValueCore, CoValueHeader } from "../coValueCore.js";
|
|
1
|
+
import { CoValueCore, CoValueHeader, CoValueUniqueness } from "../coValueCore.js";
|
|
2
2
|
import { CoID, RawCoValue } from "../coValue.js";
|
|
3
3
|
import {
|
|
4
4
|
AgentSecret,
|
|
@@ -63,7 +63,7 @@ export class RawAccount<
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export interface ControlledAccountOrAgent {
|
|
66
|
-
id:
|
|
66
|
+
id: RawAccountID | AgentID;
|
|
67
67
|
agentSecret: AgentSecret;
|
|
68
68
|
|
|
69
69
|
currentAgentID: () => Result<AgentID, InvalidAccountAgentIDError>;
|
|
@@ -92,8 +92,8 @@ export class RawControlledAccount<Meta extends AccountMeta = AccountMeta>
|
|
|
92
92
|
* Creates a new group (with the current account as the group's first admin).
|
|
93
93
|
* @category 1. High-level
|
|
94
94
|
*/
|
|
95
|
-
createGroup() {
|
|
96
|
-
return this.core.node.createGroup();
|
|
95
|
+
createGroup(uniqueness: CoValueUniqueness = this.core.crypto.createdNowUnique()) {
|
|
96
|
+
return this.core.node.createGroup(uniqueness);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
async acceptInvite<T extends RawCoValue>(
|
|
@@ -170,7 +170,7 @@ export class ControlledAgent implements ControlledAccountOrAgent {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
export type AccountMeta = { type: "account" };
|
|
173
|
-
export type
|
|
173
|
+
export type RawAccountID = CoID<RawAccount>;
|
|
174
174
|
|
|
175
175
|
export type ProfileShape = {
|
|
176
176
|
name: string;
|
package/src/coValues/coList.ts
CHANGED
|
@@ -4,7 +4,7 @@ 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
|
-
import {
|
|
7
|
+
import { RawAccountID } from "./account.js";
|
|
8
8
|
import { RawGroup } from "./group.js";
|
|
9
9
|
|
|
10
10
|
type OpID = TransactionID & { changeIdx: number };
|
|
@@ -325,7 +325,7 @@ export class RawCoListView<
|
|
|
325
325
|
/** @category 5. Edit history */
|
|
326
326
|
editAt(idx: number):
|
|
327
327
|
| {
|
|
328
|
-
by:
|
|
328
|
+
by: RawAccountID | AgentID;
|
|
329
329
|
tx: TransactionID;
|
|
330
330
|
at: Date;
|
|
331
331
|
value: Item;
|
|
@@ -351,13 +351,13 @@ export class RawCoListView<
|
|
|
351
351
|
|
|
352
352
|
/** @category 5. Edit history */
|
|
353
353
|
deletionEdits(): {
|
|
354
|
-
by:
|
|
354
|
+
by: RawAccountID | AgentID;
|
|
355
355
|
tx: TransactionID;
|
|
356
356
|
at: Date;
|
|
357
357
|
// TODO: add indices that are now before and after the deleted item
|
|
358
358
|
}[] {
|
|
359
359
|
const edits: {
|
|
360
|
-
by:
|
|
360
|
+
by: RawAccountID | AgentID;
|
|
361
361
|
tx: TransactionID;
|
|
362
362
|
at: Date;
|
|
363
363
|
}[] = [];
|
package/src/coValues/coMap.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { CoID, RawCoValue } from "../coValue.js";
|
|
|
4
4
|
import { isCoValue } from "../typeUtils/isCoValue.js";
|
|
5
5
|
import { CoValueCore } from "../coValueCore.js";
|
|
6
6
|
import { accountOrAgentIDfromSessionID } from "../typeUtils/accountOrAgentIDfromSessionID.js";
|
|
7
|
-
import {
|
|
7
|
+
import { RawAccountID } from "./account.js";
|
|
8
8
|
import type { RawGroup } from "./group.js";
|
|
9
9
|
|
|
10
10
|
type MapOp<K extends string, V extends JsonValue | undefined> = {
|
|
@@ -196,7 +196,7 @@ export class RawCoMapView<
|
|
|
196
196
|
n: number,
|
|
197
197
|
):
|
|
198
198
|
| {
|
|
199
|
-
by:
|
|
199
|
+
by: RawAccountID | AgentID;
|
|
200
200
|
tx: TransactionID;
|
|
201
201
|
at: Date;
|
|
202
202
|
value?: Shape[K];
|
|
@@ -226,7 +226,7 @@ export class RawCoMapView<
|
|
|
226
226
|
key: K,
|
|
227
227
|
):
|
|
228
228
|
| {
|
|
229
|
-
by:
|
|
229
|
+
by: RawAccountID | AgentID;
|
|
230
230
|
tx: TransactionID;
|
|
231
231
|
at: Date;
|
|
232
232
|
value?: Shape[K];
|
package/src/coValues/coStream.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { accountOrAgentIDfromSessionID } from "../typeUtils/accountOrAgentIDfrom
|
|
|
7
7
|
import { RawGroup } from "./group.js";
|
|
8
8
|
import { AgentID, SessionID, TransactionID } from "../ids.js";
|
|
9
9
|
import { base64URLtoBytes, bytesToBase64url } from "../base64url.js";
|
|
10
|
-
import {
|
|
10
|
+
import { RawAccountID } from "./account.js";
|
|
11
11
|
|
|
12
12
|
export type BinaryStreamInfo = {
|
|
13
13
|
mimeType: string;
|
|
@@ -111,7 +111,7 @@ export class RawCoStreamView<
|
|
|
111
111
|
return Object.keys(this.items) as SessionID[];
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
accounts(): Set<
|
|
114
|
+
accounts(): Set<RawAccountID> {
|
|
115
115
|
return new Set(
|
|
116
116
|
this.sessions()
|
|
117
117
|
.map(accountOrAgentIDfromSessionID)
|
|
@@ -124,7 +124,7 @@ export class RawCoStreamView<
|
|
|
124
124
|
n: number,
|
|
125
125
|
):
|
|
126
126
|
| {
|
|
127
|
-
by:
|
|
127
|
+
by: RawAccountID | AgentID;
|
|
128
128
|
tx: TransactionID;
|
|
129
129
|
at: Date;
|
|
130
130
|
value: Item;
|
|
@@ -146,7 +146,7 @@ export class RawCoStreamView<
|
|
|
146
146
|
|
|
147
147
|
lastItemIn(sessionID: SessionID):
|
|
148
148
|
| {
|
|
149
|
-
by:
|
|
149
|
+
by: RawAccountID | AgentID;
|
|
150
150
|
tx: TransactionID;
|
|
151
151
|
at: Date;
|
|
152
152
|
value: Item;
|
|
@@ -170,9 +170,9 @@ export class RawCoStreamView<
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
lastItemBy(account:
|
|
173
|
+
lastItemBy(account: RawAccountID | AgentID):
|
|
174
174
|
| {
|
|
175
|
-
by:
|
|
175
|
+
by: RawAccountID | AgentID;
|
|
176
176
|
tx: TransactionID;
|
|
177
177
|
at: Date;
|
|
178
178
|
value: Item;
|
|
@@ -180,7 +180,7 @@ export class RawCoStreamView<
|
|
|
180
180
|
| undefined {
|
|
181
181
|
let latestItem:
|
|
182
182
|
| {
|
|
183
|
-
by:
|
|
183
|
+
by: RawAccountID | AgentID;
|
|
184
184
|
tx: TransactionID;
|
|
185
185
|
at: Date;
|
|
186
186
|
value: Item;
|
|
@@ -205,7 +205,7 @@ export class RawCoStreamView<
|
|
|
205
205
|
return latestItem;
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
*itemsBy(account:
|
|
208
|
+
*itemsBy(account: RawAccountID | AgentID) {
|
|
209
209
|
// TODO: this can be made more lazy without a huge collect and sort
|
|
210
210
|
const items = [
|
|
211
211
|
...Object.keys(this.items).flatMap((sessionID) =>
|
package/src/coValues/group.ts
CHANGED
|
@@ -5,9 +5,10 @@ import { JsonObject } from "../jsonValue.js";
|
|
|
5
5
|
import { RawBinaryCoStream, RawCoStream } from "./coStream.js";
|
|
6
6
|
import { Encrypted, KeyID, KeySecret, Sealed } from "../crypto/crypto.js";
|
|
7
7
|
import { AgentID, isAgentID } from "../ids.js";
|
|
8
|
-
import { RawAccount,
|
|
8
|
+
import { RawAccount, RawAccountID, ControlledAccountOrAgent } from "./account.js";
|
|
9
9
|
import { Role } from "../permissions.js";
|
|
10
10
|
import { base58 } from "@scure/base";
|
|
11
|
+
import { CoValueUniqueness } from "../coValueCore.js";
|
|
11
12
|
|
|
12
13
|
export const EVERYONE = "everyone" as const;
|
|
13
14
|
export type Everyone = "everyone";
|
|
@@ -15,10 +16,10 @@ export type Everyone = "everyone";
|
|
|
15
16
|
export type GroupShape = {
|
|
16
17
|
profile: CoID<RawCoMap> | null;
|
|
17
18
|
root: CoID<RawCoMap> | null;
|
|
18
|
-
[key:
|
|
19
|
+
[key: RawAccountID | AgentID]: Role;
|
|
19
20
|
[EVERYONE]?: Role;
|
|
20
21
|
readKey?: KeyID;
|
|
21
|
-
[revelationFor: `${KeyID}_for_${
|
|
22
|
+
[revelationFor: `${KeyID}_for_${RawAccountID | AgentID}`]: Sealed<KeySecret>;
|
|
22
23
|
[revelationFor: `${KeyID}_for_${Everyone}`]: KeySecret;
|
|
23
24
|
[oldKeyForNewKey: `${KeyID}_for_${KeyID}`]: Encrypted<
|
|
24
25
|
KeySecret,
|
|
@@ -55,12 +56,12 @@ export class RawGroup<
|
|
|
55
56
|
*
|
|
56
57
|
* @category 1. Role reading
|
|
57
58
|
*/
|
|
58
|
-
roleOf(accountID:
|
|
59
|
+
roleOf(accountID: RawAccountID): Role | undefined {
|
|
59
60
|
return this.roleOfInternal(accountID);
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
/** @internal */
|
|
63
|
-
roleOfInternal(accountID:
|
|
64
|
+
roleOfInternal(accountID: RawAccountID | AgentID): Role | undefined {
|
|
64
65
|
return this.get(accountID);
|
|
65
66
|
}
|
|
66
67
|
|
|
@@ -156,7 +157,7 @@ export class RawGroup<
|
|
|
156
157
|
} else {
|
|
157
158
|
return false;
|
|
158
159
|
}
|
|
159
|
-
}) as (
|
|
160
|
+
}) as (RawAccountID | AgentID)[];
|
|
160
161
|
|
|
161
162
|
const maybeCurrentReadKey = this.core.getCurrentReadKey();
|
|
162
163
|
|
|
@@ -255,6 +256,7 @@ export class RawGroup<
|
|
|
255
256
|
init?: M["_shape"],
|
|
256
257
|
meta?: M["headerMeta"],
|
|
257
258
|
initPrivacy: "trusting" | "private" = "private",
|
|
259
|
+
uniqueness: CoValueUniqueness = this.core.crypto.createdNowUnique()
|
|
258
260
|
): M {
|
|
259
261
|
const map = this.core.node
|
|
260
262
|
.createCoValue({
|
|
@@ -264,7 +266,7 @@ export class RawGroup<
|
|
|
264
266
|
group: this.id,
|
|
265
267
|
},
|
|
266
268
|
meta: meta || null,
|
|
267
|
-
...
|
|
269
|
+
...uniqueness
|
|
268
270
|
})
|
|
269
271
|
.getCurrentContent() as M;
|
|
270
272
|
|
|
@@ -287,6 +289,7 @@ export class RawGroup<
|
|
|
287
289
|
init?: L["_item"][],
|
|
288
290
|
meta?: L["headerMeta"],
|
|
289
291
|
initPrivacy: "trusting" | "private" = "private",
|
|
292
|
+
uniqueness: CoValueUniqueness = this.core.crypto.createdNowUnique()
|
|
290
293
|
): L {
|
|
291
294
|
const list = this.core.node
|
|
292
295
|
.createCoValue({
|
|
@@ -296,7 +299,7 @@ export class RawGroup<
|
|
|
296
299
|
group: this.id,
|
|
297
300
|
},
|
|
298
301
|
meta: meta || null,
|
|
299
|
-
...
|
|
302
|
+
...uniqueness
|
|
300
303
|
})
|
|
301
304
|
.getCurrentContent() as L;
|
|
302
305
|
|
|
@@ -310,7 +313,7 @@ export class RawGroup<
|
|
|
310
313
|
}
|
|
311
314
|
|
|
312
315
|
/** @category 3. Value creation */
|
|
313
|
-
createStream<C extends RawCoStream>(meta?: C["headerMeta"]): C {
|
|
316
|
+
createStream<C extends RawCoStream>(meta?: C["headerMeta"], uniqueness: CoValueUniqueness = this.core.crypto.createdNowUnique()): C {
|
|
314
317
|
return this.core.node
|
|
315
318
|
.createCoValue({
|
|
316
319
|
type: "costream",
|
|
@@ -319,7 +322,7 @@ export class RawGroup<
|
|
|
319
322
|
group: this.id,
|
|
320
323
|
},
|
|
321
324
|
meta: meta || null,
|
|
322
|
-
...
|
|
325
|
+
...uniqueness
|
|
323
326
|
})
|
|
324
327
|
.getCurrentContent() as C;
|
|
325
328
|
}
|
|
@@ -327,6 +330,7 @@ export class RawGroup<
|
|
|
327
330
|
/** @category 3. Value creation */
|
|
328
331
|
createBinaryStream<C extends RawBinaryCoStream>(
|
|
329
332
|
meta: C["headerMeta"] = { type: "binary" },
|
|
333
|
+
uniqueness: CoValueUniqueness = this.core.crypto.createdNowUnique()
|
|
330
334
|
): C {
|
|
331
335
|
return this.core.node
|
|
332
336
|
.createCoValue({
|
|
@@ -336,7 +340,7 @@ export class RawGroup<
|
|
|
336
340
|
group: this.id,
|
|
337
341
|
},
|
|
338
342
|
meta: meta,
|
|
339
|
-
...
|
|
343
|
+
...uniqueness
|
|
340
344
|
})
|
|
341
345
|
.getCurrentContent() as C;
|
|
342
346
|
}
|
package/src/ids.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RawAccountID } from "./coValues/account.js";
|
|
2
2
|
import { base58 } from "@scure/base";
|
|
3
3
|
import { shortHashLength } from "./crypto/crypto.js";
|
|
4
4
|
|
|
@@ -28,4 +28,4 @@ export function isAgentID(id: string): id is AgentID {
|
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export type SessionID = `${
|
|
31
|
+
export type SessionID = `${RawAccountID | AgentID}_session_z${string}`;
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CoValueCore,
|
|
3
|
+
type CoValueUniqueness,
|
|
3
4
|
newRandomSessionID,
|
|
4
5
|
MAX_RECOMMENDED_TX_SIZE,
|
|
5
6
|
idforHeader,
|
|
@@ -50,7 +51,7 @@ import type {
|
|
|
50
51
|
import { DisconnectedError, PingTimeoutError } from "./sync.js";
|
|
51
52
|
import type { AgentSecret } from "./crypto/crypto.js";
|
|
52
53
|
import type {
|
|
53
|
-
|
|
54
|
+
RawAccountID,
|
|
54
55
|
AccountMeta,
|
|
55
56
|
RawAccountMigration,
|
|
56
57
|
} from "./coValues/account.js";
|
|
@@ -96,7 +97,7 @@ export {
|
|
|
96
97
|
CoID,
|
|
97
98
|
AnyRawCoValue,
|
|
98
99
|
RawAccount,
|
|
99
|
-
|
|
100
|
+
RawAccountID,
|
|
100
101
|
AccountMeta,
|
|
101
102
|
RawAccountMigration,
|
|
102
103
|
RawProfile as Profile,
|
|
@@ -130,6 +131,7 @@ export type {
|
|
|
130
131
|
OutgoingSyncQueue,
|
|
131
132
|
DisconnectedError,
|
|
132
133
|
PingTimeoutError,
|
|
134
|
+
CoValueUniqueness
|
|
133
135
|
};
|
|
134
136
|
|
|
135
137
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
package/src/localNode.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { AgentSecret, CryptoProvider } from "./crypto/crypto.js";
|
|
|
2
2
|
import {
|
|
3
3
|
CoValueCore,
|
|
4
4
|
CoValueHeader,
|
|
5
|
+
CoValueUniqueness,
|
|
5
6
|
newRandomSessionID,
|
|
6
7
|
} from "./coValueCore.js";
|
|
7
8
|
import {
|
|
@@ -19,7 +20,7 @@ import {
|
|
|
19
20
|
ControlledAccountOrAgent,
|
|
20
21
|
RawControlledAccount,
|
|
21
22
|
ControlledAgent,
|
|
22
|
-
|
|
23
|
+
RawAccountID,
|
|
23
24
|
RawProfile,
|
|
24
25
|
RawAccountMigration,
|
|
25
26
|
InvalidAccountAgentIDError,
|
|
@@ -81,7 +82,7 @@ export class LocalNode {
|
|
|
81
82
|
initialAgentSecret?: AgentSecret;
|
|
82
83
|
}): Promise<{
|
|
83
84
|
node: LocalNode;
|
|
84
|
-
accountID:
|
|
85
|
+
accountID: RawAccountID;
|
|
85
86
|
accountSecret: AgentSecret;
|
|
86
87
|
sessionID: SessionID;
|
|
87
88
|
}> {
|
|
@@ -173,7 +174,7 @@ export class LocalNode {
|
|
|
173
174
|
crypto,
|
|
174
175
|
migration,
|
|
175
176
|
}: {
|
|
176
|
-
accountID:
|
|
177
|
+
accountID: RawAccountID;
|
|
177
178
|
accountSecret: AgentSecret;
|
|
178
179
|
sessionID: SessionID | undefined;
|
|
179
180
|
peersToLoadFrom: Peer[];
|
|
@@ -470,7 +471,7 @@ export class LocalNode {
|
|
|
470
471
|
}
|
|
471
472
|
|
|
472
473
|
/** @internal */
|
|
473
|
-
expectProfileLoaded(id:
|
|
474
|
+
expectProfileLoaded(id: RawAccountID, expectation?: string): RawProfile {
|
|
474
475
|
const account = this.expectCoValueLoaded(id, expectation);
|
|
475
476
|
const profileID = expectGroup(account.getCurrentContent()).get(
|
|
476
477
|
"profile",
|
|
@@ -533,7 +534,7 @@ export class LocalNode {
|
|
|
533
534
|
|
|
534
535
|
/** @internal */
|
|
535
536
|
resolveAccountAgent(
|
|
536
|
-
id:
|
|
537
|
+
id: RawAccountID | AgentID,
|
|
537
538
|
expectation?: string,
|
|
538
539
|
): Result<AgentID, ResolveAccountAgentError> {
|
|
539
540
|
if (isAgentID(id)) {
|
|
@@ -560,7 +561,7 @@ export class LocalNode {
|
|
|
560
561
|
}
|
|
561
562
|
|
|
562
563
|
resolveAccountAgentAsync(
|
|
563
|
-
id:
|
|
564
|
+
id: RawAccountID | AgentID,
|
|
564
565
|
expectation?: string,
|
|
565
566
|
): ResultAsync<AgentID, ResolveAccountAgentError> {
|
|
566
567
|
if (isAgentID(id)) {
|
|
@@ -606,12 +607,12 @@ export class LocalNode {
|
|
|
606
607
|
/**
|
|
607
608
|
* @deprecated use Account.createGroup() instead
|
|
608
609
|
*/
|
|
609
|
-
createGroup(): RawGroup {
|
|
610
|
+
createGroup(uniqueness: CoValueUniqueness = this.crypto.createdNowUnique()): RawGroup {
|
|
610
611
|
const groupCoValue = this.createCoValue({
|
|
611
612
|
type: "comap",
|
|
612
613
|
ruleset: { type: "group", initialAdmin: this.account.id },
|
|
613
614
|
meta: null,
|
|
614
|
-
...
|
|
615
|
+
...uniqueness
|
|
615
616
|
});
|
|
616
617
|
|
|
617
618
|
const group = expectGroup(groupCoValue.getCurrentContent());
|
|
@@ -731,19 +732,19 @@ export type LoadCoValueCoreError = {
|
|
|
731
732
|
type: "ErrorLoadingCoValueCore";
|
|
732
733
|
error: unknown;
|
|
733
734
|
expectation?: string;
|
|
734
|
-
id:
|
|
735
|
+
id: RawAccountID;
|
|
735
736
|
};
|
|
736
737
|
|
|
737
738
|
export type AccountUnavailableFromAllPeersError = {
|
|
738
739
|
type: "AccountUnavailableFromAllPeers";
|
|
739
740
|
expectation?: string;
|
|
740
|
-
id:
|
|
741
|
+
id: RawAccountID;
|
|
741
742
|
};
|
|
742
743
|
|
|
743
744
|
export type UnexpectedlyNotAccountError = {
|
|
744
745
|
type: "UnexpectedlyNotAccount";
|
|
745
746
|
expectation?: string;
|
|
746
|
-
id:
|
|
747
|
+
id: RawAccountID;
|
|
747
748
|
};
|
|
748
749
|
|
|
749
750
|
export type ResolveAccountAgentError =
|
package/src/permissions.ts
CHANGED
|
@@ -5,13 +5,13 @@ import { KeyID } from "./crypto/crypto.js";
|
|
|
5
5
|
import { CoValueCore, Transaction } from "./coValueCore.js";
|
|
6
6
|
import { accountOrAgentIDfromSessionID } from "./typeUtils/accountOrAgentIDfromSessionID.js";
|
|
7
7
|
import { AgentID, RawCoID, SessionID, TransactionID } from "./ids.js";
|
|
8
|
-
import { RawAccount,
|
|
8
|
+
import { RawAccount, RawAccountID, RawProfile } from "./coValues/account.js";
|
|
9
9
|
import { parseJSON } from "./jsonStringify.js";
|
|
10
10
|
import { EVERYONE, Everyone } from "./coValues/group.js";
|
|
11
11
|
import { expectGroup } from "./typeUtils/expectGroup.js";
|
|
12
12
|
|
|
13
13
|
export type PermissionsDef =
|
|
14
|
-
| { type: "group"; initialAdmin:
|
|
14
|
+
| { type: "group"; initialAdmin: RawAccountID | AgentID }
|
|
15
15
|
| { type: "ownedByGroup"; group: RawCoID }
|
|
16
16
|
| { type: "unsafeAllowAll" };
|
|
17
17
|
|
|
@@ -53,7 +53,7 @@ export function determineValidTransactions(
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
const memberState: {
|
|
56
|
-
[agent:
|
|
56
|
+
[agent: RawAccountID | AgentID]: Role;
|
|
57
57
|
[EVERYONE]?: Role;
|
|
58
58
|
} = {};
|
|
59
59
|
|
|
@@ -99,7 +99,7 @@ export function determineValidTransactions(
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
const change = changes[0] as
|
|
102
|
-
| MapOpPayload<
|
|
102
|
+
| MapOpPayload<RawAccountID | AgentID | Everyone, Role>
|
|
103
103
|
| MapOpPayload<"readKey", JsonValue>
|
|
104
104
|
| MapOpPayload<"profile", CoID<RawProfile>>;
|
|
105
105
|
if (changes.length !== 1) {
|
|
@@ -303,7 +303,7 @@ export function isKeyForKeyField(co: string): co is `${KeyID}_for_${KeyID}` {
|
|
|
303
303
|
|
|
304
304
|
export function isKeyForAccountField(
|
|
305
305
|
co: string,
|
|
306
|
-
): co is `${KeyID}_for_${
|
|
306
|
+
): co is `${KeyID}_for_${RawAccountID | AgentID}` {
|
|
307
307
|
return (
|
|
308
308
|
(co.startsWith("key_") &&
|
|
309
309
|
(co.includes("_for_sealer") || co.includes("_for_co"))) ||
|
package/src/tests/sync.test.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { MapOpPayload } from "../coValues/coMap.js";
|
|
|
5
5
|
import { RawGroup } from "../coValues/group.js";
|
|
6
6
|
import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
|
|
7
7
|
import { connectedPeers, newQueuePair } from "../streamUtils.js";
|
|
8
|
-
import {
|
|
8
|
+
import { RawAccountID } from "../coValues/account.js";
|
|
9
9
|
import { stableStringify } from "../jsonStringify.js";
|
|
10
10
|
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
11
11
|
import { expectMap } from "../coValue.js";
|
|
@@ -1097,7 +1097,7 @@ function groupContentEx(group: RawGroup) {
|
|
|
1097
1097
|
};
|
|
1098
1098
|
}
|
|
1099
1099
|
|
|
1100
|
-
function _admContEx(adminID:
|
|
1100
|
+
function _admContEx(adminID: RawAccountID) {
|
|
1101
1101
|
return {
|
|
1102
1102
|
action: "content",
|
|
1103
1103
|
id: adminID,
|
|
@@ -1111,7 +1111,7 @@ function groupStateEx(group: RawGroup) {
|
|
|
1111
1111
|
};
|
|
1112
1112
|
}
|
|
1113
1113
|
|
|
1114
|
-
function _admStateEx(adminID:
|
|
1114
|
+
function _admStateEx(adminID: RawAccountID) {
|
|
1115
1115
|
return {
|
|
1116
1116
|
action: "known",
|
|
1117
1117
|
id: adminID,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AgentID, SessionID } from "../ids.js";
|
|
2
|
-
import {
|
|
2
|
+
import { RawAccountID } from "../coValues/account.js";
|
|
3
3
|
|
|
4
4
|
export function accountOrAgentIDfromSessionID(
|
|
5
5
|
sessionID: SessionID,
|
|
6
|
-
):
|
|
6
|
+
): RawAccountID | AgentID {
|
|
7
7
|
const until = sessionID.indexOf("_session");
|
|
8
|
-
return sessionID.slice(0, until) as
|
|
8
|
+
return sessionID.slice(0, until) as RawAccountID | AgentID;
|
|
9
9
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RawAccountID } from "../coValues/account.js";
|
|
2
2
|
import type { AgentID } from "../ids.js";
|
|
3
3
|
|
|
4
|
-
export function isAccountID(id:
|
|
4
|
+
export function isAccountID(id: RawAccountID | AgentID): id is RawAccountID {
|
|
5
5
|
return id.startsWith("co_");
|
|
6
6
|
}
|