jazz-tools 0.9.19 → 0.9.21
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 +6 -6
- package/CHANGELOG.md +12 -0
- package/dist/{chunk-LRDIS2Q2.js → chunk-OJIEP4WE.js} +41 -12
- package/dist/chunk-OJIEP4WE.js.map +1 -0
- package/dist/index.native.js +1 -1
- package/dist/index.web.js +1 -1
- package/dist/testing.js +1 -1
- package/package.json +1 -1
- package/src/coValues/account.ts +19 -8
- package/src/coValues/coFeed.ts +23 -0
- package/src/coValues/inbox.ts +2 -2
- package/src/implementation/schema.ts +4 -1
- package/src/implementation/symbols.ts +5 -3
- package/src/tests/account.test.ts +37 -2
- package/dist/chunk-LRDIS2Q2.js.map +0 -1
package/dist/index.native.js
CHANGED
package/dist/index.web.js
CHANGED
package/dist/testing.js
CHANGED
package/package.json
CHANGED
package/src/coValues/account.ts
CHANGED
@@ -73,7 +73,7 @@ export class Account extends CoValueBase implements CoValue {
|
|
73
73
|
return this as Account;
|
74
74
|
}
|
75
75
|
get _loadedAs(): Account | AnonymousJazzAgent {
|
76
|
-
if (this.
|
76
|
+
if (this.isLocalNodeOwner) return this;
|
77
77
|
|
78
78
|
const rawAccount = this._raw.core.node.account;
|
79
79
|
|
@@ -120,7 +120,17 @@ export class Account extends CoValueBase implements CoValue {
|
|
120
120
|
};
|
121
121
|
}
|
122
122
|
|
123
|
-
|
123
|
+
/**
|
124
|
+
* Whether this account is the currently active account.
|
125
|
+
*/
|
126
|
+
get isMe() {
|
127
|
+
return activeAccountContext.get().id === this.id;
|
128
|
+
}
|
129
|
+
|
130
|
+
/**
|
131
|
+
* Whether this account is the owner of the local node.
|
132
|
+
*/
|
133
|
+
isLocalNodeOwner: boolean;
|
124
134
|
sessionID: SessionID | undefined;
|
125
135
|
|
126
136
|
constructor(options: { fromRaw: RawAccount | RawControlledAccount }) {
|
@@ -128,7 +138,8 @@ export class Account extends CoValueBase implements CoValue {
|
|
128
138
|
if (!("fromRaw" in options)) {
|
129
139
|
throw new Error("Can only construct account from raw or with .create()");
|
130
140
|
}
|
131
|
-
this.
|
141
|
+
this.isLocalNodeOwner =
|
142
|
+
options.fromRaw.id == options.fromRaw.core.node.account.id;
|
132
143
|
|
133
144
|
Object.defineProperties(this, {
|
134
145
|
id: {
|
@@ -139,7 +150,7 @@ export class Account extends CoValueBase implements CoValue {
|
|
139
150
|
_type: { value: "Account", enumerable: false },
|
140
151
|
});
|
141
152
|
|
142
|
-
if (this.
|
153
|
+
if (this.isLocalNodeOwner) {
|
143
154
|
this.sessionID = options.fromRaw.core.node.currentSessionID;
|
144
155
|
}
|
145
156
|
|
@@ -147,7 +158,7 @@ export class Account extends CoValueBase implements CoValue {
|
|
147
158
|
}
|
148
159
|
|
149
160
|
myRole(): "admin" | undefined {
|
150
|
-
if (this.
|
161
|
+
if (this.isLocalNodeOwner) {
|
151
162
|
return "admin";
|
152
163
|
}
|
153
164
|
}
|
@@ -157,7 +168,7 @@ export class Account extends CoValueBase implements CoValue {
|
|
157
168
|
inviteSecret: InviteSecret,
|
158
169
|
coValueClass: CoValueClass<V>,
|
159
170
|
) {
|
160
|
-
if (!this.
|
171
|
+
if (!this.isLocalNodeOwner) {
|
161
172
|
throw new Error("Only a controlled account can accept invites");
|
162
173
|
}
|
163
174
|
|
@@ -433,11 +444,11 @@ export const AccountAndGroupProxyHandler: ProxyHandler<Account | Group> = {
|
|
433
444
|
|
434
445
|
/** @category Identity & Permissions */
|
435
446
|
export function isControlledAccount(account: Account): account is Account & {
|
436
|
-
|
447
|
+
isLocalNodeOwner: true;
|
437
448
|
sessionID: SessionID;
|
438
449
|
_raw: RawControlledAccount;
|
439
450
|
} {
|
440
|
-
return account.
|
451
|
+
return account.isLocalNodeOwner;
|
441
452
|
}
|
442
453
|
|
443
454
|
export type AccountClass<Acc extends Account> = CoValueClass<Acc> & {
|
package/src/coValues/coFeed.ts
CHANGED
@@ -708,6 +708,29 @@ export class FileStream extends CoValueBase implements CoValue {
|
|
708
708
|
});
|
709
709
|
}
|
710
710
|
|
711
|
+
/**
|
712
|
+
* Create a new empty `FileStream` instance.
|
713
|
+
*
|
714
|
+
* @param options - Configuration options for the new FileStream
|
715
|
+
* @param options.owner - The Account or Group that will own this FileStream and control access rights
|
716
|
+
*
|
717
|
+
* @example
|
718
|
+
* ```typescript
|
719
|
+
* // Create owned by an account
|
720
|
+
* const stream = FileStream.create({ owner: myAccount });
|
721
|
+
*
|
722
|
+
* // Create owned by a group
|
723
|
+
* const stream = FileStream.create({ owner: teamGroup });
|
724
|
+
*
|
725
|
+
* // Create with implicit owner
|
726
|
+
* const stream = FileStream.create(myAccount);
|
727
|
+
* ```
|
728
|
+
*
|
729
|
+
* @remarks
|
730
|
+
* For uploading an existing file or blob, use {@link FileStream.createFromBlob} instead.
|
731
|
+
*
|
732
|
+
* @category Creation
|
733
|
+
*/
|
711
734
|
static create<S extends FileStream>(
|
712
735
|
this: CoValueClass<S>,
|
713
736
|
options?: { owner?: Account | Group } | Account | Group,
|
package/src/coValues/inbox.ts
CHANGED
@@ -28,7 +28,7 @@ export type InboxRoot = RawCoMap<{
|
|
28
28
|
}>;
|
29
29
|
|
30
30
|
export function createInboxRoot(account: Account) {
|
31
|
-
if (!account.
|
31
|
+
if (!account.isLocalNodeOwner) {
|
32
32
|
throw new Error("Account is not controlled");
|
33
33
|
}
|
34
34
|
|
@@ -361,7 +361,7 @@ async function acceptInvite(invite: string, account?: Account) {
|
|
361
361
|
throw new Error("Invalid inbox ticket");
|
362
362
|
}
|
363
363
|
|
364
|
-
if (!account.
|
364
|
+
if (!account.isLocalNodeOwner) {
|
365
365
|
throw new Error("Account is not controlled");
|
366
366
|
}
|
367
367
|
|
@@ -5,6 +5,7 @@ import {
|
|
5
5
|
type CoValueClass,
|
6
6
|
CoValueFromRaw,
|
7
7
|
ItemsSym,
|
8
|
+
JazzToolsSymbol,
|
8
9
|
MembersSym,
|
9
10
|
SchemaInit,
|
10
11
|
isCoValueClass,
|
@@ -23,7 +24,9 @@ export type CoMarker = { readonly __co: unique symbol };
|
|
23
24
|
export type co<T> = T | (T & CoMarker);
|
24
25
|
export type IfCo<C, R> = C extends infer _A | infer B
|
25
26
|
? B extends CoMarker
|
26
|
-
? R
|
27
|
+
? R extends JazzToolsSymbol // Exclude symbol properties like co.items or co.members from the refs/init types
|
28
|
+
? never
|
29
|
+
: R
|
27
30
|
: never
|
28
31
|
: never;
|
29
32
|
export type UnCo<T> = T extends co<infer A> ? A : T;
|
@@ -1,8 +1,10 @@
|
|
1
|
-
export
|
1
|
+
export type JazzToolsSymbol = SchemaInit | ItemsSym | MembersSym;
|
2
|
+
|
3
|
+
export const SchemaInit = "$SchemaInit$";
|
2
4
|
export type SchemaInit = typeof SchemaInit;
|
3
5
|
|
4
|
-
export const ItemsSym =
|
6
|
+
export const ItemsSym = "$items$";
|
5
7
|
export type ItemsSym = typeof ItemsSym;
|
6
8
|
|
7
|
-
export const MembersSym =
|
9
|
+
export const MembersSym = "$members$";
|
8
10
|
export type MembersSym = typeof MembersSym;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { expect, test } from "vitest";
|
2
|
-
import { CoMap, co } from "../exports.js";
|
3
|
-
import { createJazzTestAccount } from "../testing.js";
|
2
|
+
import { Account, CoMap, co } from "../exports.js";
|
3
|
+
import { createJazzTestAccount, setActiveAccount } from "../testing.js";
|
4
4
|
import { setupTwoNodes } from "./utils.js";
|
5
5
|
|
6
6
|
test("waitForAllCoValuesSync should resolve when all the values are synced", async () => {
|
@@ -39,3 +39,38 @@ test("waitForSync should resolve when the value is uploaded", async () => {
|
|
39
39
|
|
40
40
|
expect(loadedAccount).not.toBe("unavailable");
|
41
41
|
});
|
42
|
+
|
43
|
+
test("isMe gets updated correctly when switching accounts", async () => {
|
44
|
+
const oldMe = await createJazzTestAccount({
|
45
|
+
isCurrentActiveAccount: true,
|
46
|
+
});
|
47
|
+
|
48
|
+
expect(oldMe.isMe).toBe(true);
|
49
|
+
|
50
|
+
const newMe = await createJazzTestAccount({
|
51
|
+
isCurrentActiveAccount: false,
|
52
|
+
});
|
53
|
+
|
54
|
+
expect(newMe.isMe).toBe(false);
|
55
|
+
expect(oldMe.isMe).toBe(true);
|
56
|
+
|
57
|
+
setActiveAccount(newMe);
|
58
|
+
|
59
|
+
expect(newMe.isMe).toBe(true);
|
60
|
+
expect(oldMe.isMe).toBe(false);
|
61
|
+
});
|
62
|
+
|
63
|
+
test("Me gets updated correctly when creating a new account as active", async () => {
|
64
|
+
const oldMe = await createJazzTestAccount({
|
65
|
+
isCurrentActiveAccount: true,
|
66
|
+
});
|
67
|
+
|
68
|
+
expect(oldMe.isMe).toBe(true);
|
69
|
+
|
70
|
+
const newMe = await createJazzTestAccount({
|
71
|
+
isCurrentActiveAccount: true,
|
72
|
+
});
|
73
|
+
|
74
|
+
expect(newMe.isMe).toBe(true);
|
75
|
+
expect(oldMe.isMe).toBe(false);
|
76
|
+
});
|