cojson 0.4.1 → 0.4.6
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/coValue.js +0 -9
- package/dist/coValue.js.map +1 -1
- package/dist/coValueCore.js +4 -34
- package/dist/coValueCore.js.map +1 -1
- package/dist/coValues/coList.js +2 -2
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +2 -2
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +2 -2
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/group.js.map +1 -1
- package/dist/coreToCoValue.js +37 -0
- package/dist/coreToCoValue.js.map +1 -0
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/isCoValue.js +10 -0
- package/dist/isCoValue.js.map +1 -0
- package/dist/localNode.js +1 -14
- package/dist/localNode.js.map +1 -1
- package/package.json +4 -4
- package/src/coValue.ts +11 -19
- package/src/coValueCore.ts +2 -25
- package/src/coValues/coList.ts +3 -2
- package/src/coValues/coMap.ts +3 -2
- package/src/coValues/coStream.ts +3 -4
- package/src/coValues/group.ts +4 -4
- package/src/coreToCoValue.ts +37 -0
- package/src/index.ts +16 -16
- package/src/isCoValue.ts +16 -0
- package/src/localNode.ts +6 -47
- package/src/tests/coValue.test.ts +5 -5
- package/src/tests/group.test.ts +1 -1
- package/dist/base64url.d.ts +0 -2
- package/dist/coValue.d.ts +0 -38
- package/dist/coValueCore.d.ts +0 -103
- package/dist/coValues/account.d.ts +0 -62
- package/dist/coValues/coList.d.ts +0 -179
- package/dist/coValues/coMap.d.ts +0 -149
- package/dist/coValues/coStream.d.ts +0 -123
- package/dist/coValues/group.d.ts +0 -111
- package/dist/crypto.d.ts +0 -120
- package/dist/ids.d.ts +0 -11
- package/dist/index.d.ts +0 -67
- package/dist/jsonStringify.d.ts +0 -6
- package/dist/jsonValue.d.ts +0 -7
- package/dist/localNode.d.ts +0 -101
- package/dist/media.d.ts +0 -7
- package/dist/permissions.d.ts +0 -20
- package/dist/queriedCoValues/queriedAccount.d.ts +0 -13
- package/dist/queriedCoValues/queriedAccount.js +0 -24
- package/dist/queriedCoValues/queriedAccount.js.map +0 -1
- package/dist/queriedCoValues/queriedCoList.d.ts +0 -66
- package/dist/queriedCoValues/queriedCoList.js +0 -116
- package/dist/queriedCoValues/queriedCoList.js.map +0 -1
- package/dist/queriedCoValues/queriedCoMap.d.ts +0 -40
- package/dist/queriedCoValues/queriedCoMap.js +0 -82
- package/dist/queriedCoValues/queriedCoMap.js.map +0 -1
- package/dist/queriedCoValues/queriedCoStream.d.ts +0 -36
- package/dist/queriedCoValues/queriedCoStream.js +0 -97
- package/dist/queriedCoValues/queriedCoStream.js.map +0 -1
- package/dist/queriedCoValues/queriedGroup.d.ts +0 -29
- package/dist/queriedCoValues/queriedGroup.js +0 -54
- package/dist/queriedCoValues/queriedGroup.js.map +0 -1
- package/dist/queries.d.ts +0 -62
- package/dist/queries.js +0 -142
- package/dist/queries.js.map +0 -1
- package/dist/streamUtils.d.ts +0 -8
- package/dist/sync.d.ts +0 -80
- package/dist/tests/testUtils.d.ts +0 -37
- package/src/queriedCoValues/queriedAccount.ts +0 -40
- package/src/queriedCoValues/queriedCoList.ts +0 -240
- package/src/queriedCoValues/queriedCoMap.ts +0 -168
- package/src/queriedCoValues/queriedCoStream.ts +0 -151
- package/src/queriedCoValues/queriedGroup.ts +0 -90
- package/src/queries.ts +0 -263
- package/src/tests/queries.test.ts +0 -398
package/src/coValue.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { JsonObject, JsonValue } from "./jsonValue.js";
|
|
2
2
|
import { RawCoID } from "./ids.js";
|
|
3
3
|
import { CoMap } from "./coValues/coMap.js";
|
|
4
|
-
import {
|
|
5
|
-
BinaryCoStream,
|
|
6
|
-
BinaryCoStreamMeta,
|
|
7
|
-
CoStream,
|
|
8
|
-
} from "./coValues/coStream.js";
|
|
4
|
+
import { BinaryCoStream, CoStream } from "./coValues/coStream.js";
|
|
9
5
|
import { CoList } from "./coValues/coList.js";
|
|
10
6
|
import { CoValueCore } from "./coValueCore.js";
|
|
11
7
|
import { Group } from "./coValues/group.js";
|
|
@@ -22,7 +18,7 @@ export interface CoValue {
|
|
|
22
18
|
/** Specifies which kind of `CoValue` this is */
|
|
23
19
|
type: string;
|
|
24
20
|
/** The `CoValue`'s (precisely typed) static metadata */
|
|
25
|
-
|
|
21
|
+
headerMeta: JsonObject | null;
|
|
26
22
|
/** The `Group` this `CoValue` belongs to (determining permissions) */
|
|
27
23
|
group: Group;
|
|
28
24
|
/** Returns an immutable JSON presentation of this `CoValue` */
|
|
@@ -38,7 +34,14 @@ export interface CoValue {
|
|
|
38
34
|
subscribe(listener: (coValue: this) => void): () => void;
|
|
39
35
|
}
|
|
40
36
|
|
|
41
|
-
export type AnyCoValue =
|
|
37
|
+
export type AnyCoValue =
|
|
38
|
+
| CoMap
|
|
39
|
+
| Group
|
|
40
|
+
| Account
|
|
41
|
+
| Profile
|
|
42
|
+
| CoList
|
|
43
|
+
| CoStream
|
|
44
|
+
| BinaryCoStream;
|
|
42
45
|
|
|
43
46
|
export function expectMap(content: CoValue): CoMap {
|
|
44
47
|
if (content.type !== "comap") {
|
|
@@ -62,15 +65,4 @@ export function expectStream(content: CoValue): CoStream {
|
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
return content as CoStream;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function isCoValue(
|
|
68
|
-
value: JsonValue | CoValue | undefined
|
|
69
|
-
): value is CoValue {
|
|
70
|
-
return (
|
|
71
|
-
value instanceof CoMap ||
|
|
72
|
-
value instanceof CoList ||
|
|
73
|
-
value instanceof CoStream ||
|
|
74
|
-
value instanceof BinaryCoStream
|
|
75
|
-
);
|
|
76
|
-
}
|
|
68
|
+
}
|
package/src/coValueCore.ts
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
isAccountID,
|
|
39
39
|
} from "./coValues/account.js";
|
|
40
40
|
import { Stringified, stableStringify } from "./jsonStringify.js";
|
|
41
|
+
import { coreToCoValue } from "./coreToCoValue.js";
|
|
41
42
|
|
|
42
43
|
export const MAX_RECOMMENDED_TX_SIZE = 100 * 1024;
|
|
43
44
|
|
|
@@ -517,31 +518,7 @@ export class CoValueCore {
|
|
|
517
518
|
return this._cachedContent;
|
|
518
519
|
}
|
|
519
520
|
|
|
520
|
-
|
|
521
|
-
if (this.header.type === "comap") {
|
|
522
|
-
if (this.header.ruleset.type === "group") {
|
|
523
|
-
if (
|
|
524
|
-
this.header.meta?.type === "account" &&
|
|
525
|
-
!options?.ignorePrivateTransactions
|
|
526
|
-
) {
|
|
527
|
-
newContent = new Account(this);
|
|
528
|
-
} else {
|
|
529
|
-
newContent = new Group(this, options);
|
|
530
|
-
}
|
|
531
|
-
} else {
|
|
532
|
-
newContent = new CoMap(this);
|
|
533
|
-
}
|
|
534
|
-
} else if (this.header.type === "colist") {
|
|
535
|
-
newContent = new CoList(this);
|
|
536
|
-
} else if (this.header.type === "costream") {
|
|
537
|
-
if (this.header.meta && this.header.meta.type === "binary") {
|
|
538
|
-
newContent = new BinaryCoStream(this);
|
|
539
|
-
} else {
|
|
540
|
-
newContent = new CoStream(this);
|
|
541
|
-
}
|
|
542
|
-
} else {
|
|
543
|
-
throw new Error(`Unknown coValue type ${this.header.type}`);
|
|
544
|
-
}
|
|
521
|
+
const newContent = coreToCoValue(this, options);
|
|
545
522
|
|
|
546
523
|
if (!options?.ignorePrivateTransactions) {
|
|
547
524
|
this._cachedContent = newContent;
|
package/src/coValues/coList.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { JsonObject, JsonValue } from "../jsonValue.js";
|
|
2
|
-
import { CoID, CoValue
|
|
2
|
+
import { CoID, CoValue } from "../coValue.js";
|
|
3
|
+
import { isCoValue } from "../isCoValue.js";
|
|
3
4
|
import { CoValueCore, accountOrAgentIDfromSessionID } from "../coValueCore.js";
|
|
4
5
|
import { AgentID, SessionID, TransactionID } from "../ids.js";
|
|
5
6
|
import { AccountID } from "./account.js";
|
|
@@ -197,7 +198,7 @@ export class CoListView<
|
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
/** @category 6. Meta */
|
|
200
|
-
get
|
|
201
|
+
get headerMeta(): Meta {
|
|
201
202
|
return this.core.header.meta as Meta;
|
|
202
203
|
}
|
|
203
204
|
|
package/src/coValues/coMap.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { JsonObject, JsonValue } from "../jsonValue.js";
|
|
2
2
|
import { AgentID, TransactionID } from "../ids.js";
|
|
3
|
-
import { CoID, CoValue
|
|
3
|
+
import { CoID, CoValue } from "../coValue.js";
|
|
4
|
+
import { isCoValue } from "../isCoValue.js";
|
|
4
5
|
import { CoValueCore, accountOrAgentIDfromSessionID } from "../coValueCore.js";
|
|
5
6
|
import { AccountID } from "./account.js";
|
|
6
7
|
import { parseJSON } from "../jsonStringify.js";
|
|
@@ -84,7 +85,7 @@ export class CoMapView<
|
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
/** @category 6. Meta */
|
|
87
|
-
get
|
|
88
|
+
get headerMeta(): Meta {
|
|
88
89
|
return this.core.header.meta as Meta;
|
|
89
90
|
}
|
|
90
91
|
|
package/src/coValues/coStream.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { JsonObject, JsonValue } from "../jsonValue.js";
|
|
2
|
-
import { CoValue, CoID
|
|
2
|
+
import { CoValue, CoID } from "../coValue.js";
|
|
3
|
+
import { isCoValue } from "../isCoValue.js";
|
|
3
4
|
import { CoValueCore, accountOrAgentIDfromSessionID } from "../coValueCore.js";
|
|
4
5
|
import { Group } from "./group.js";
|
|
5
6
|
import { AgentID, SessionID, TransactionID } from "../ids.js";
|
|
@@ -59,7 +60,7 @@ export class CoStreamView<
|
|
|
59
60
|
this.fillFromCoValue();
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
get
|
|
63
|
+
get headerMeta(): Meta {
|
|
63
64
|
return this.core.header.meta as Meta;
|
|
64
65
|
}
|
|
65
66
|
|
|
@@ -290,8 +291,6 @@ export class BinaryCoStreamView<
|
|
|
290
291
|
extends CoStreamView<BinaryStreamItem, Meta>
|
|
291
292
|
implements CoValue
|
|
292
293
|
{
|
|
293
|
-
id!: CoID<this>;
|
|
294
|
-
|
|
295
294
|
getBinaryChunks(
|
|
296
295
|
allowUnfinished?: boolean
|
|
297
296
|
):
|
package/src/coValues/group.ts
CHANGED
|
@@ -277,7 +277,7 @@ export class Group<
|
|
|
277
277
|
*/
|
|
278
278
|
createMap<M extends CoMap>(
|
|
279
279
|
init?: M["_shape"],
|
|
280
|
-
meta?: M["
|
|
280
|
+
meta?: M["headerMeta"],
|
|
281
281
|
initPrivacy: "trusting" | "private" = "private"
|
|
282
282
|
): M {
|
|
283
283
|
let map = this.core.node
|
|
@@ -309,7 +309,7 @@ export class Group<
|
|
|
309
309
|
*/
|
|
310
310
|
createList<L extends CoList>(
|
|
311
311
|
init?: L["_item"][],
|
|
312
|
-
meta?: L["
|
|
312
|
+
meta?: L["headerMeta"],
|
|
313
313
|
initPrivacy: "trusting" | "private" = "private"
|
|
314
314
|
): L {
|
|
315
315
|
let list = this.core.node
|
|
@@ -334,7 +334,7 @@ export class Group<
|
|
|
334
334
|
}
|
|
335
335
|
|
|
336
336
|
/** @category 3. Value creation */
|
|
337
|
-
createStream<C extends CoStream>(meta?: C["
|
|
337
|
+
createStream<C extends CoStream>(meta?: C["headerMeta"]): C {
|
|
338
338
|
return this.core.node
|
|
339
339
|
.createCoValue({
|
|
340
340
|
type: "costream",
|
|
@@ -350,7 +350,7 @@ export class Group<
|
|
|
350
350
|
|
|
351
351
|
/** @category 3. Value creation */
|
|
352
352
|
createBinaryStream<C extends BinaryCoStream>(
|
|
353
|
-
meta: C["
|
|
353
|
+
meta: C["headerMeta"] = { type: "binary" }
|
|
354
354
|
): C {
|
|
355
355
|
return this.core.node
|
|
356
356
|
.createCoValue({
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CoValueCore } from "./coValueCore.js";
|
|
2
|
+
import { Account } from "./coValues/account.js";
|
|
3
|
+
import { Group } from "./coValues/group.js";
|
|
4
|
+
import { CoMap } from "./coValues/coMap.js";
|
|
5
|
+
import { CoList } from "./coValues/coList.js";
|
|
6
|
+
import { CoStream } from "./coValues/coStream.js";
|
|
7
|
+
import { BinaryCoStream } from "./coValues/coStream.js";
|
|
8
|
+
|
|
9
|
+
export function coreToCoValue(
|
|
10
|
+
core: CoValueCore,
|
|
11
|
+
options?: { ignorePrivateTransactions: true }
|
|
12
|
+
) {
|
|
13
|
+
if (core.header.type === "comap") {
|
|
14
|
+
if (core.header.ruleset.type === "group") {
|
|
15
|
+
if (
|
|
16
|
+
core.header.meta?.type === "account" &&
|
|
17
|
+
!options?.ignorePrivateTransactions
|
|
18
|
+
) {
|
|
19
|
+
return new Account(core);
|
|
20
|
+
} else {
|
|
21
|
+
return new Group(core, options);
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
return new CoMap(core);
|
|
25
|
+
}
|
|
26
|
+
} else if (core.header.type === "colist") {
|
|
27
|
+
return new CoList(core);
|
|
28
|
+
} else if (core.header.type === "costream") {
|
|
29
|
+
if (core.header.meta && core.header.meta.type === "binary") {
|
|
30
|
+
return new BinaryCoStream(core);
|
|
31
|
+
} else {
|
|
32
|
+
return new CoStream(core);
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
throw new Error(`Unknown coValue type ${core.header.type}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
CoValueCore,
|
|
3
3
|
newRandomSessionID,
|
|
4
4
|
MAX_RECOMMENDED_TX_SIZE,
|
|
5
|
-
accountOrAgentIDfromSessionID
|
|
5
|
+
accountOrAgentIDfromSessionID,
|
|
6
6
|
} from "./coValueCore.js";
|
|
7
7
|
import { LocalNode } from "./localNode.js";
|
|
8
8
|
import type { CoValue } from "./coValue.js";
|
|
@@ -30,20 +30,16 @@ import {
|
|
|
30
30
|
AnonymousControlledAccount,
|
|
31
31
|
ControlledAccount,
|
|
32
32
|
} from "./coValues/account.js";
|
|
33
|
+
import type { Role } from "./permissions.js";
|
|
33
34
|
import { rawCoIDtoBytes, rawCoIDfromBytes } from "./ids.js";
|
|
34
35
|
import { Group, expectGroup, EVERYONE } from "./coValues/group.js";
|
|
36
|
+
import type { Everyone } from "./coValues/group.js";
|
|
35
37
|
import { base64URLtoBytes, bytesToBase64url } from "./base64url.js";
|
|
36
38
|
import { parseJSON } from "./jsonStringify.js";
|
|
37
39
|
import { Account, Profile, isAccountID } from "./coValues/account.js";
|
|
38
40
|
|
|
39
41
|
import type { SessionID, AgentID } from "./ids.js";
|
|
40
42
|
import type { CoID, AnyCoValue } from "./coValue.js";
|
|
41
|
-
import type { Queried, QueryExtension } from "./queries.js";
|
|
42
|
-
import type { QueriedCoStream } from "./queriedCoValues/queriedCoStream.js";
|
|
43
|
-
import type { QueriedCoList } from "./queriedCoValues/queriedCoList.js";
|
|
44
|
-
import type { QueriedCoMap } from "./queriedCoValues/queriedCoMap.js";
|
|
45
|
-
import { QueriedAccount } from "./queriedCoValues/queriedAccount.js";
|
|
46
|
-
import { QueriedGroup } from "./queriedCoValues/queriedGroup.js";
|
|
47
43
|
import type {
|
|
48
44
|
BinaryStreamInfo,
|
|
49
45
|
BinaryCoStreamMeta,
|
|
@@ -51,7 +47,12 @@ import type {
|
|
|
51
47
|
import type { JsonValue } from "./jsonValue.js";
|
|
52
48
|
import type { SyncMessage, Peer } from "./sync.js";
|
|
53
49
|
import type { AgentSecret } from "./crypto.js";
|
|
54
|
-
import type {
|
|
50
|
+
import type {
|
|
51
|
+
AccountID,
|
|
52
|
+
AccountMeta,
|
|
53
|
+
AccountMigration,
|
|
54
|
+
ProfileMeta,
|
|
55
|
+
} from "./coValues/account.js";
|
|
55
56
|
import type { InviteSecret } from "./coValues/group.js";
|
|
56
57
|
import type * as Media from "./media.js";
|
|
57
58
|
|
|
@@ -82,7 +83,9 @@ export const cojsonInternals = {
|
|
|
82
83
|
export {
|
|
83
84
|
LocalNode,
|
|
84
85
|
Group,
|
|
86
|
+
Role,
|
|
85
87
|
EVERYONE,
|
|
88
|
+
Everyone,
|
|
86
89
|
CoMap,
|
|
87
90
|
MutableCoMap,
|
|
88
91
|
CoList,
|
|
@@ -94,12 +97,6 @@ export {
|
|
|
94
97
|
CoValue,
|
|
95
98
|
CoID,
|
|
96
99
|
AnyCoValue,
|
|
97
|
-
Queried,
|
|
98
|
-
QueriedCoMap,
|
|
99
|
-
QueriedCoList,
|
|
100
|
-
QueriedCoStream,
|
|
101
|
-
QueriedGroup,
|
|
102
|
-
QueriedAccount,
|
|
103
100
|
Account,
|
|
104
101
|
AccountID,
|
|
105
102
|
AccountMeta,
|
|
@@ -113,7 +110,6 @@ export {
|
|
|
113
110
|
ControlledAccount,
|
|
114
111
|
cryptoReady as cojsonReady,
|
|
115
112
|
MAX_RECOMMENDED_TX_SIZE,
|
|
116
|
-
Value,
|
|
117
113
|
JsonValue,
|
|
118
114
|
Peer,
|
|
119
115
|
BinaryStreamInfo,
|
|
@@ -122,9 +118,12 @@ export {
|
|
|
122
118
|
AgentSecret,
|
|
123
119
|
InviteSecret,
|
|
124
120
|
SyncMessage,
|
|
125
|
-
QueryExtension,
|
|
126
121
|
};
|
|
127
122
|
|
|
123
|
+
export type {
|
|
124
|
+
Value,
|
|
125
|
+
}
|
|
126
|
+
|
|
128
127
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
129
128
|
export namespace CojsonInternalTypes {
|
|
130
129
|
export type CoValueKnownState = import("./sync.js").CoValueKnownState;
|
|
@@ -134,6 +133,7 @@ export namespace CojsonInternalTypes {
|
|
|
134
133
|
export type NewContentMessage = import("./sync.js").NewContentMessage;
|
|
135
134
|
export type CoValueHeader = import("./coValueCore.js").CoValueHeader;
|
|
136
135
|
export type Transaction = import("./coValueCore.js").Transaction;
|
|
136
|
+
export type TransactionID = import("./ids.js").TransactionID;
|
|
137
137
|
export type Signature = import("./crypto.js").Signature;
|
|
138
138
|
export type RawCoID = import("./ids.js").RawCoID;
|
|
139
139
|
export type ProfileShape = import("./coValues/account.js").ProfileShape;
|
package/src/isCoValue.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { JsonValue } from "./jsonValue.js";
|
|
2
|
+
import { CoMap } from "./coValues/coMap.js";
|
|
3
|
+
import { BinaryCoStream, CoStream } from "./coValues/coStream.js";
|
|
4
|
+
import { CoList } from "./coValues/coList.js";
|
|
5
|
+
import { CoValue } from "./coValue.js";
|
|
6
|
+
|
|
7
|
+
export function isCoValue(
|
|
8
|
+
value: JsonValue | CoValue | undefined
|
|
9
|
+
): value is CoValue {
|
|
10
|
+
return (
|
|
11
|
+
value instanceof CoMap ||
|
|
12
|
+
value instanceof CoList ||
|
|
13
|
+
value instanceof CoStream ||
|
|
14
|
+
value instanceof BinaryCoStream
|
|
15
|
+
);
|
|
16
|
+
}
|
package/src/localNode.ts
CHANGED
|
@@ -17,14 +17,12 @@ import {
|
|
|
17
17
|
import {
|
|
18
18
|
InviteSecret,
|
|
19
19
|
Group,
|
|
20
|
-
GroupShape,
|
|
21
20
|
expectGroup,
|
|
22
21
|
secretSeedFromInviteSecret,
|
|
23
22
|
} from "./coValues/group.js";
|
|
24
23
|
import { Peer, SyncManager } from "./sync.js";
|
|
25
24
|
import { AgentID, RawCoID, SessionID, isAgentID } from "./ids.js";
|
|
26
25
|
import { CoID } from "./coValue.js";
|
|
27
|
-
import { Queried, query } from "./queries.js";
|
|
28
26
|
import {
|
|
29
27
|
Account,
|
|
30
28
|
AccountMeta,
|
|
@@ -34,12 +32,10 @@ import {
|
|
|
34
32
|
AnonymousControlledAccount,
|
|
35
33
|
AccountID,
|
|
36
34
|
Profile,
|
|
37
|
-
isAccountID,
|
|
38
35
|
AccountMigration,
|
|
39
36
|
} from "./coValues/account.js";
|
|
40
37
|
import { CoMap } from "./coValues/coMap.js";
|
|
41
38
|
import { CoValue } from "./index.js";
|
|
42
|
-
import { QueriedAccount } from "./queriedCoValues/queriedAccount.js";
|
|
43
39
|
|
|
44
40
|
/** A `LocalNode` represents a local view of a set of loaded `CoValue`s, from the perspective of a particular account (or primitive cryptographic agent).
|
|
45
41
|
|
|
@@ -103,7 +99,8 @@ export class LocalNode {
|
|
|
103
99
|
newRandomSessionID(account.id)
|
|
104
100
|
);
|
|
105
101
|
|
|
106
|
-
const accountOnNodeWithAccount =
|
|
102
|
+
const accountOnNodeWithAccount =
|
|
103
|
+
nodeWithAccount.account as ControlledAccount<P, R, Meta>;
|
|
107
104
|
|
|
108
105
|
const profile = nodeWithAccount.expectProfileLoaded(
|
|
109
106
|
accountOnNodeWithAccount.id,
|
|
@@ -256,47 +253,6 @@ export class LocalNode {
|
|
|
256
253
|
};
|
|
257
254
|
}
|
|
258
255
|
|
|
259
|
-
/** @category 1. High-level */
|
|
260
|
-
|
|
261
|
-
query<T extends CoValue>(
|
|
262
|
-
id: CoID<T>,
|
|
263
|
-
callback: (update: Queried<T> | undefined) => void
|
|
264
|
-
): () => void;
|
|
265
|
-
query<
|
|
266
|
-
P extends Profile = Profile,
|
|
267
|
-
R extends CoMap = CoMap,
|
|
268
|
-
Meta extends AccountMeta = AccountMeta
|
|
269
|
-
>(
|
|
270
|
-
id: "me",
|
|
271
|
-
callback: (
|
|
272
|
-
update: QueriedAccount<Account<P, R, Meta>> | undefined
|
|
273
|
-
) => void
|
|
274
|
-
): () => void;
|
|
275
|
-
query(
|
|
276
|
-
id: CoID<CoValue> | "me",
|
|
277
|
-
callback: (
|
|
278
|
-
update: Queried<CoValue> | QueriedAccount | undefined
|
|
279
|
-
) => void
|
|
280
|
-
): () => void;
|
|
281
|
-
query(
|
|
282
|
-
id: CoID<CoValue> | "me",
|
|
283
|
-
callback: (
|
|
284
|
-
// TODO: sort this out
|
|
285
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
286
|
-
update: any
|
|
287
|
-
) => void
|
|
288
|
-
): () => void {
|
|
289
|
-
if (id === "me") {
|
|
290
|
-
const meId = this.account.id;
|
|
291
|
-
if (!isAccountID(meId)) {
|
|
292
|
-
throw new Error("Can only query 'me' for accounts");
|
|
293
|
-
}
|
|
294
|
-
return query(meId, this, callback);
|
|
295
|
-
} else {
|
|
296
|
-
return query(id, this, callback);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
256
|
/** @deprecated Use Account.acceptInvite instead */
|
|
301
257
|
async acceptInvite<T extends CoValue>(
|
|
302
258
|
groupOrOwnedValueID: CoID<T>,
|
|
@@ -601,7 +557,10 @@ export class LocalNode {
|
|
|
601
557
|
|
|
602
558
|
if (account instanceof ControlledAccount) {
|
|
603
559
|
// To make sure that when we edit the account, we're modifying the correct sessions
|
|
604
|
-
const accountInNode = new ControlledAccount(
|
|
560
|
+
const accountInNode = new ControlledAccount(
|
|
561
|
+
newNode.expectCoValueLoaded(account.id),
|
|
562
|
+
account.agentSecret
|
|
563
|
+
);
|
|
605
564
|
if (accountInNode.core.node !== newNode) {
|
|
606
565
|
throw new Error("Account's node is not the new node");
|
|
607
566
|
}
|
|
@@ -315,14 +315,14 @@ test("Empty BinaryCoStream works", () => {
|
|
|
315
315
|
|
|
316
316
|
if (
|
|
317
317
|
content.type !== "costream" ||
|
|
318
|
-
content.
|
|
318
|
+
content.headerMeta?.type !== "binary" ||
|
|
319
319
|
!(content instanceof BinaryCoStream)
|
|
320
320
|
) {
|
|
321
321
|
throw new Error("Expected binary stream");
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
expect(content.type).toEqual("costream");
|
|
325
|
-
expect(content.
|
|
325
|
+
expect(content.headerMeta.type).toEqual("binary");
|
|
326
326
|
expect(content.toJSON()).toEqual({});
|
|
327
327
|
expect(content.getBinaryChunks()).toEqual(undefined);
|
|
328
328
|
});
|
|
@@ -341,7 +341,7 @@ test("Can push into BinaryCoStream", () => {
|
|
|
341
341
|
|
|
342
342
|
if (
|
|
343
343
|
content.type !== "costream" ||
|
|
344
|
-
content.
|
|
344
|
+
content.headerMeta?.type !== "binary" ||
|
|
345
345
|
!(content instanceof BinaryCoStream)
|
|
346
346
|
) {
|
|
347
347
|
throw new Error("Expected binary stream");
|
|
@@ -398,7 +398,7 @@ test("When adding large transactions (small fraction of MAX_RECOMMENDED_TX_SIZE)
|
|
|
398
398
|
|
|
399
399
|
if (
|
|
400
400
|
content.type !== "costream" ||
|
|
401
|
-
content.
|
|
401
|
+
content.headerMeta?.type !== "binary" ||
|
|
402
402
|
!(content instanceof BinaryCoStream)
|
|
403
403
|
) {
|
|
404
404
|
throw new Error("Expected binary stream");
|
|
@@ -474,7 +474,7 @@ test("When adding large transactions (bigger than MAX_RECOMMENDED_TX_SIZE), we s
|
|
|
474
474
|
|
|
475
475
|
if (
|
|
476
476
|
content.type !== "costream" ||
|
|
477
|
-
content.
|
|
477
|
+
content.headerMeta?.type !== "binary" ||
|
|
478
478
|
!(content instanceof BinaryCoStream)
|
|
479
479
|
) {
|
|
480
480
|
throw new Error("Expected binary stream");
|
package/src/tests/group.test.ts
CHANGED
|
@@ -46,6 +46,6 @@ test("Can create a BinaryCoStream in a group", () => {
|
|
|
46
46
|
const stream = group.createBinaryStream();
|
|
47
47
|
|
|
48
48
|
expect(stream.core.getCurrentContent().type).toEqual("costream");
|
|
49
|
-
expect(stream.
|
|
49
|
+
expect(stream.headerMeta.type).toEqual("binary");
|
|
50
50
|
expect(stream instanceof BinaryCoStream).toEqual(true);
|
|
51
51
|
})
|
package/dist/base64url.d.ts
DELETED
package/dist/coValue.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { JsonObject, JsonValue } from "./jsonValue.js";
|
|
2
|
-
import { RawCoID } from "./ids.js";
|
|
3
|
-
import { CoMap } from "./coValues/coMap.js";
|
|
4
|
-
import { BinaryCoStream, CoStream } from "./coValues/coStream.js";
|
|
5
|
-
import { CoList } from "./coValues/coList.js";
|
|
6
|
-
import { CoValueCore } from "./coValueCore.js";
|
|
7
|
-
import { Group } from "./coValues/group.js";
|
|
8
|
-
import { Account, Profile } from "./index.js";
|
|
9
|
-
export type CoID<T extends CoValue> = RawCoID & {
|
|
10
|
-
readonly __type: T;
|
|
11
|
-
};
|
|
12
|
-
export interface CoValue {
|
|
13
|
-
/** The `CoValue`'s (precisely typed) `CoID` */
|
|
14
|
-
id: CoID<this>;
|
|
15
|
-
core: CoValueCore;
|
|
16
|
-
/** Specifies which kind of `CoValue` this is */
|
|
17
|
-
type: string;
|
|
18
|
-
/** The `CoValue`'s (precisely typed) static metadata */
|
|
19
|
-
meta: JsonObject | null;
|
|
20
|
-
/** The `Group` this `CoValue` belongs to (determining permissions) */
|
|
21
|
-
group: Group;
|
|
22
|
-
/** Returns an immutable JSON presentation of this `CoValue` */
|
|
23
|
-
toJSON(): JsonValue;
|
|
24
|
-
atTime(time: number): this;
|
|
25
|
-
/** Lets you subscribe to future updates to this CoValue (whether made locally or by other users).
|
|
26
|
-
*
|
|
27
|
-
* Takes a listener function that will be called with the current state for each update.
|
|
28
|
-
*
|
|
29
|
-
* Returns an unsubscribe function.
|
|
30
|
-
*
|
|
31
|
-
* Used internally by `useTelepathicData()` for reactive updates on changes to a `CoValue`. */
|
|
32
|
-
subscribe(listener: (coValue: this) => void): () => void;
|
|
33
|
-
}
|
|
34
|
-
export type AnyCoValue = CoMap | Group | Account | Profile | CoList | CoStream | BinaryCoStream;
|
|
35
|
-
export declare function expectMap(content: CoValue): CoMap;
|
|
36
|
-
export declare function expectList(content: CoValue): CoList;
|
|
37
|
-
export declare function expectStream(content: CoValue): CoStream;
|
|
38
|
-
export declare function isCoValue(value: JsonValue | CoValue | undefined): value is CoValue;
|
package/dist/coValueCore.d.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { AnyCoValue, CoValue } from "./coValue.js";
|
|
2
|
-
import { Encrypted, Hash, KeySecret, Signature, StreamingHash, KeyID } from "./crypto.js";
|
|
3
|
-
import { JsonObject, JsonValue } from "./jsonValue.js";
|
|
4
|
-
import { PermissionsDef as RulesetDef } from "./permissions.js";
|
|
5
|
-
import { Group } from "./coValues/group.js";
|
|
6
|
-
import { LocalNode } from "./localNode.js";
|
|
7
|
-
import { CoValueKnownState, NewContentMessage } from "./sync.js";
|
|
8
|
-
import { AgentID, RawCoID, SessionID, TransactionID } from "./ids.js";
|
|
9
|
-
import { AccountID, GeneralizedControlledAccount } from "./coValues/account.js";
|
|
10
|
-
import { Stringified } from "./jsonStringify.js";
|
|
11
|
-
export declare const MAX_RECOMMENDED_TX_SIZE: number;
|
|
12
|
-
export type CoValueHeader = {
|
|
13
|
-
type: AnyCoValue["type"];
|
|
14
|
-
ruleset: RulesetDef;
|
|
15
|
-
meta: JsonObject | null;
|
|
16
|
-
createdAt: `2${string}` | null;
|
|
17
|
-
uniqueness: `z${string}` | null;
|
|
18
|
-
};
|
|
19
|
-
export declare function idforHeader(header: CoValueHeader): RawCoID;
|
|
20
|
-
export declare function accountOrAgentIDfromSessionID(sessionID: SessionID): AccountID | AgentID;
|
|
21
|
-
export declare function newRandomSessionID(accountID: AccountID | AgentID): SessionID;
|
|
22
|
-
type SessionLog = {
|
|
23
|
-
transactions: Transaction[];
|
|
24
|
-
lastHash?: Hash;
|
|
25
|
-
streamingHash: StreamingHash;
|
|
26
|
-
signatureAfter: {
|
|
27
|
-
[txIdx: number]: Signature | undefined;
|
|
28
|
-
};
|
|
29
|
-
lastSignature: Signature;
|
|
30
|
-
};
|
|
31
|
-
export type PrivateTransaction = {
|
|
32
|
-
privacy: "private";
|
|
33
|
-
madeAt: number;
|
|
34
|
-
keyUsed: KeyID;
|
|
35
|
-
encryptedChanges: Encrypted<JsonValue[], {
|
|
36
|
-
in: RawCoID;
|
|
37
|
-
tx: TransactionID;
|
|
38
|
-
}>;
|
|
39
|
-
};
|
|
40
|
-
export type TrustingTransaction = {
|
|
41
|
-
privacy: "trusting";
|
|
42
|
-
madeAt: number;
|
|
43
|
-
changes: Stringified<JsonValue[]>;
|
|
44
|
-
};
|
|
45
|
-
export type Transaction = PrivateTransaction | TrustingTransaction;
|
|
46
|
-
export type DecryptedTransaction = {
|
|
47
|
-
txID: TransactionID;
|
|
48
|
-
changes: Stringified<JsonValue[]>;
|
|
49
|
-
madeAt: number;
|
|
50
|
-
};
|
|
51
|
-
export declare class CoValueCore {
|
|
52
|
-
id: RawCoID;
|
|
53
|
-
node: LocalNode;
|
|
54
|
-
header: CoValueHeader;
|
|
55
|
-
_sessions: {
|
|
56
|
-
[key: SessionID]: SessionLog;
|
|
57
|
-
};
|
|
58
|
-
_cachedContent?: CoValue;
|
|
59
|
-
listeners: Set<(content?: CoValue) => void>;
|
|
60
|
-
_decryptionCache: {
|
|
61
|
-
[key: Encrypted<JsonValue[], JsonValue>]: Stringified<JsonValue[]> | undefined;
|
|
62
|
-
};
|
|
63
|
-
constructor(header: CoValueHeader, node: LocalNode, internalInitSessions?: {
|
|
64
|
-
[key: SessionID]: SessionLog;
|
|
65
|
-
});
|
|
66
|
-
get sessions(): Readonly<{
|
|
67
|
-
[key: SessionID]: SessionLog;
|
|
68
|
-
}>;
|
|
69
|
-
testWithDifferentAccount(account: GeneralizedControlledAccount, currentSessionID: SessionID): CoValueCore;
|
|
70
|
-
knownState(): CoValueKnownState;
|
|
71
|
-
get meta(): JsonValue;
|
|
72
|
-
nextTransactionID(): TransactionID;
|
|
73
|
-
tryAddTransactions(sessionID: SessionID, newTransactions: Transaction[], givenExpectedNewHash: Hash | undefined, newSignature: Signature): boolean;
|
|
74
|
-
tryAddTransactionsAsync(sessionID: SessionID, newTransactions: Transaction[], givenExpectedNewHash: Hash | undefined, newSignature: Signature): Promise<boolean>;
|
|
75
|
-
private doAddTransactions;
|
|
76
|
-
subscribe(listener: (content?: CoValue) => void): () => void;
|
|
77
|
-
expectedNewHashAfter(sessionID: SessionID, newTransactions: Transaction[]): {
|
|
78
|
-
expectedNewHash: Hash;
|
|
79
|
-
newStreamingHash: StreamingHash;
|
|
80
|
-
};
|
|
81
|
-
expectedNewHashAfterAsync(sessionID: SessionID, newTransactions: Transaction[]): Promise<{
|
|
82
|
-
expectedNewHash: Hash;
|
|
83
|
-
newStreamingHash: StreamingHash;
|
|
84
|
-
}>;
|
|
85
|
-
makeTransaction(changes: JsonValue[], privacy: "private" | "trusting"): boolean;
|
|
86
|
-
getCurrentContent(options?: {
|
|
87
|
-
ignorePrivateTransactions: true;
|
|
88
|
-
}): CoValue;
|
|
89
|
-
getValidSortedTransactions(options?: {
|
|
90
|
-
ignorePrivateTransactions: true;
|
|
91
|
-
}): DecryptedTransaction[];
|
|
92
|
-
getCurrentReadKey(): {
|
|
93
|
-
secret: KeySecret | undefined;
|
|
94
|
-
id: KeyID;
|
|
95
|
-
};
|
|
96
|
-
getReadKey(keyID: KeyID): KeySecret | undefined;
|
|
97
|
-
getUncachedReadKey(keyID: KeyID): KeySecret | undefined;
|
|
98
|
-
getGroup(): Group;
|
|
99
|
-
getTx(txID: TransactionID): Transaction | undefined;
|
|
100
|
-
newContentSince(knownState: CoValueKnownState | undefined): NewContentMessage[] | undefined;
|
|
101
|
-
getDependedOnCoValues(): RawCoID[];
|
|
102
|
-
}
|
|
103
|
-
export {};
|