jazz-tools 0.10.15 → 0.11.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.
Files changed (148) hide show
  1. package/.turbo/turbo-build.log +9 -5
  2. package/CHANGELOG.md +29 -0
  3. package/dist/auth/AuthSecretStorage.d.ts +25 -0
  4. package/dist/auth/AuthSecretStorage.d.ts.map +1 -0
  5. package/dist/auth/DemoAuth.d.ts +27 -0
  6. package/dist/auth/DemoAuth.d.ts.map +1 -0
  7. package/dist/auth/InMemoryKVStore.d.ts +9 -0
  8. package/dist/auth/InMemoryKVStore.d.ts.map +1 -0
  9. package/dist/auth/KvStoreContext.d.ts +17 -0
  10. package/dist/auth/KvStoreContext.d.ts.map +1 -0
  11. package/dist/auth/PassphraseAuth.d.ts +35 -0
  12. package/dist/auth/PassphraseAuth.d.ts.map +1 -0
  13. package/dist/{chunk-5USJBXLW.js → chunk-MVDJNBLV.js} +163 -70
  14. package/dist/chunk-MVDJNBLV.js.map +1 -0
  15. package/dist/coValues/account.d.ts +120 -0
  16. package/dist/coValues/account.d.ts.map +1 -0
  17. package/dist/coValues/coFeed.d.ts +361 -0
  18. package/dist/coValues/coFeed.d.ts.map +1 -0
  19. package/dist/coValues/coList.d.ts +222 -0
  20. package/dist/coValues/coList.d.ts.map +1 -0
  21. package/dist/coValues/coMap.d.ts +500 -0
  22. package/dist/coValues/coMap.d.ts.map +1 -0
  23. package/dist/coValues/coPlainText.d.ts +69 -0
  24. package/dist/coValues/coPlainText.d.ts.map +1 -0
  25. package/dist/coValues/coRichText.d.ts +259 -0
  26. package/dist/coValues/coRichText.d.ts.map +1 -0
  27. package/dist/coValues/deepLoading.d.ts +81 -0
  28. package/dist/coValues/deepLoading.d.ts.map +1 -0
  29. package/dist/coValues/extensions/imageDef.d.ts +17 -0
  30. package/dist/coValues/extensions/imageDef.d.ts.map +1 -0
  31. package/dist/coValues/group.d.ts +67 -0
  32. package/dist/coValues/group.d.ts.map +1 -0
  33. package/dist/coValues/inbox.d.ts +52 -0
  34. package/dist/coValues/inbox.d.ts.map +1 -0
  35. package/dist/coValues/interfaces.d.ts +97 -0
  36. package/dist/coValues/interfaces.d.ts.map +1 -0
  37. package/dist/coValues/profile.d.ts +28 -0
  38. package/dist/coValues/profile.d.ts.map +1 -0
  39. package/dist/coValues/registeredSchemas.d.ts +12 -0
  40. package/dist/coValues/registeredSchemas.d.ts.map +1 -0
  41. package/dist/coValues/schemaUnion.d.ts +79 -0
  42. package/dist/coValues/schemaUnion.d.ts.map +1 -0
  43. package/dist/exports.d.ts +27 -0
  44. package/dist/exports.d.ts.map +1 -0
  45. package/dist/implementation/ContextManager.d.ts +65 -0
  46. package/dist/implementation/ContextManager.d.ts.map +1 -0
  47. package/dist/implementation/activeAccountContext.d.ts +12 -0
  48. package/dist/implementation/activeAccountContext.d.ts.map +1 -0
  49. package/dist/implementation/anonymousJazzAgent.d.ts +7 -0
  50. package/dist/implementation/anonymousJazzAgent.d.ts.map +1 -0
  51. package/dist/implementation/createContext.d.ts +91 -0
  52. package/dist/implementation/createContext.d.ts.map +1 -0
  53. package/dist/implementation/devtoolsFormatters.d.ts +2 -0
  54. package/dist/implementation/devtoolsFormatters.d.ts.map +1 -0
  55. package/dist/implementation/errors.d.ts +2 -0
  56. package/dist/implementation/errors.d.ts.map +1 -0
  57. package/dist/implementation/inspect.d.ts +3 -0
  58. package/dist/implementation/inspect.d.ts.map +1 -0
  59. package/dist/implementation/invites.d.ts +23 -0
  60. package/dist/implementation/invites.d.ts.map +1 -0
  61. package/dist/implementation/refs.d.ts +21 -0
  62. package/dist/implementation/refs.d.ts.map +1 -0
  63. package/dist/implementation/schema.d.ts +72 -0
  64. package/dist/implementation/schema.d.ts.map +1 -0
  65. package/dist/implementation/subscriptionScope.d.ts +33 -0
  66. package/dist/implementation/subscriptionScope.d.ts.map +1 -0
  67. package/dist/implementation/symbols.d.ts +8 -0
  68. package/dist/implementation/symbols.d.ts.map +1 -0
  69. package/dist/index.d.ts +3 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +1 -1
  72. package/dist/internal.d.ts +12 -0
  73. package/dist/internal.d.ts.map +1 -0
  74. package/dist/lib/cache.d.ts +6 -0
  75. package/dist/lib/cache.d.ts.map +1 -0
  76. package/dist/lib/cache.test.d.ts +2 -0
  77. package/dist/lib/cache.test.d.ts.map +1 -0
  78. package/dist/testing.d.ts +41 -0
  79. package/dist/testing.d.ts.map +1 -0
  80. package/dist/testing.js +1 -1
  81. package/dist/tests/AuthSecretStorage.test.d.ts +2 -0
  82. package/dist/tests/AuthSecretStorage.test.d.ts.map +1 -0
  83. package/dist/tests/ContextManager.test.d.ts +2 -0
  84. package/dist/tests/ContextManager.test.d.ts.map +1 -0
  85. package/dist/tests/DemoAuth.test.d.ts +2 -0
  86. package/dist/tests/DemoAuth.test.d.ts.map +1 -0
  87. package/dist/tests/PassphraseAuth.test.d.ts +2 -0
  88. package/dist/tests/PassphraseAuth.test.d.ts.map +1 -0
  89. package/dist/tests/account.test.d.ts +2 -0
  90. package/dist/tests/account.test.d.ts.map +1 -0
  91. package/dist/tests/coFeed.test.d.ts +2 -0
  92. package/dist/tests/coFeed.test.d.ts.map +1 -0
  93. package/dist/tests/coList.test.d.ts +2 -0
  94. package/dist/tests/coList.test.d.ts.map +1 -0
  95. package/dist/tests/coMap.test.d.ts +2 -0
  96. package/dist/tests/coMap.test.d.ts.map +1 -0
  97. package/dist/tests/coPlainText.test.d.ts +2 -0
  98. package/dist/tests/coPlainText.test.d.ts.map +1 -0
  99. package/dist/tests/coRichText.test.d.ts +2 -0
  100. package/dist/tests/coRichText.test.d.ts.map +1 -0
  101. package/dist/tests/createContext.test.d.ts +2 -0
  102. package/dist/tests/createContext.test.d.ts.map +1 -0
  103. package/dist/tests/deepLoading.test.d.ts +2 -0
  104. package/dist/tests/deepLoading.test.d.ts.map +1 -0
  105. package/dist/tests/fixtures.d.ts +2 -0
  106. package/dist/tests/fixtures.d.ts.map +1 -0
  107. package/dist/tests/groupsAndAccounts.test.d.ts +2 -0
  108. package/dist/tests/groupsAndAccounts.test.d.ts.map +1 -0
  109. package/dist/tests/inbox.test.d.ts +2 -0
  110. package/dist/tests/inbox.test.d.ts.map +1 -0
  111. package/dist/tests/interfaces.test.d.ts +2 -0
  112. package/dist/tests/interfaces.test.d.ts.map +1 -0
  113. package/dist/tests/invites.test.d.ts +2 -0
  114. package/dist/tests/invites.test.d.ts.map +1 -0
  115. package/dist/tests/schema.test.d.ts +2 -0
  116. package/dist/tests/schema.test.d.ts.map +1 -0
  117. package/dist/tests/schemaUnion.test.d.ts +2 -0
  118. package/dist/tests/schemaUnion.test.d.ts.map +1 -0
  119. package/dist/tests/subscribe.test.d.ts +2 -0
  120. package/dist/tests/subscribe.test.d.ts.map +1 -0
  121. package/dist/tests/testing.test.d.ts +2 -0
  122. package/dist/tests/testing.test.d.ts.map +1 -0
  123. package/dist/tests/utils.d.ts +21 -0
  124. package/dist/tests/utils.d.ts.map +1 -0
  125. package/dist/types.d.ts +52 -0
  126. package/dist/types.d.ts.map +1 -0
  127. package/package.json +9 -7
  128. package/src/coValues/account.ts +69 -11
  129. package/src/coValues/coList.ts +14 -1
  130. package/src/coValues/coMap.ts +2 -2
  131. package/src/coValues/coRichText.ts +42 -17
  132. package/src/coValues/group.ts +76 -31
  133. package/src/coValues/inbox.ts +10 -0
  134. package/src/coValues/interfaces.ts +1 -1
  135. package/src/coValues/profile.ts +35 -2
  136. package/src/implementation/schema.ts +1 -3
  137. package/src/tests/AuthSecretStorage.test.ts +1 -2
  138. package/src/tests/PassphraseAuth.test.ts +3 -3
  139. package/src/tests/coList.test.ts +20 -0
  140. package/src/tests/coMap.test.ts +20 -21
  141. package/src/tests/deepLoading.test.ts +8 -17
  142. package/src/tests/groupsAndAccounts.test.ts +429 -89
  143. package/src/tests/inbox.test.ts +24 -0
  144. package/src/tests/schema.test.ts +45 -5
  145. package/src/tests/utils.ts +7 -3
  146. package/src/types.ts +6 -0
  147. package/tsconfig.json +4 -1
  148. package/dist/chunk-5USJBXLW.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
 
2
- > jazz-tools@0.10.15 build /home/runner/_work/jazz/jazz/packages/jazz-tools
3
- > tsup
2
+ > jazz-tools@0.11.2 build /home/runner/_work/jazz/jazz/packages/jazz-tools
3
+ > tsup && pnpm types
4
4
 
5
5
  CLI Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
6
6
  CLI Using tsconfig: tsconfig.json
@@ -10,9 +10,13 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  ESM dist/index.js 1.50 KB
13
+ ESM dist/chunk-MVDJNBLV.js 119.45 KB
13
14
  ESM dist/testing.js 6.18 KB
14
- ESM dist/chunk-5USJBXLW.js 116.50 KB
15
15
  ESM dist/index.js.map 259.00 B
16
+ ESM dist/chunk-MVDJNBLV.js.map 284.49 KB
16
17
  ESM dist/testing.js.map 12.24 KB
17
- ESM dist/chunk-5USJBXLW.js.map 277.65 KB
18
- ESM ⚡️ Build success in 59ms
18
+ ESM ⚡️ Build success in 43ms
19
+
20
+ > jazz-tools@0.11.2 types /home/runner/_work/jazz/jazz/packages/jazz-tools
21
+ > tsc --outDir dist
22
+
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.11.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 6892dc6: Adds `applyDiff` to `CoList`
8
+
9
+ ## 0.11.0
10
+
11
+ ### Minor Changes
12
+
13
+ - b9d194a: Make members return inherited members
14
+ Added getRoleOf method to Account and Group
15
+ Added canRead, canWrite, canAdmin methods to Account so simplify permissions checks
16
+ - 34cbdc3: Added revokeExtend method to Group
17
+ - f039e8f: Remove co.members and use RegisteredAccount and the configured AccountSchema to setup the members Account class. Remove everyone from Group.members results
18
+ - e22de9f: Fix profile migrations
19
+
20
+ ### Patch Changes
21
+
22
+ - 6a96d8b: Add getParentGroups API to Group
23
+ - a35249a: Fix CoMap.toJSON() with encoded fields
24
+ - a4713df: Moving to the d.ts files for the exported type definitions
25
+ - Updated dependencies [b9d194a]
26
+ - Updated dependencies [a4713df]
27
+ - Updated dependencies [e22de9f]
28
+ - Updated dependencies [34cbdc3]
29
+ - Updated dependencies [0f67e0a]
30
+ - cojson@0.11.0
31
+
3
32
  ## 0.10.15
4
33
 
5
34
  ### Patch Changes
@@ -0,0 +1,25 @@
1
+ import { AgentSecret } from "cojson";
2
+ import type { Account } from "../coValues/account.js";
3
+ import type { ID } from "../internal.js";
4
+ import { AuthCredentials } from "../types.js";
5
+ export type AuthSetPayload = {
6
+ accountID: ID<Account>;
7
+ secretSeed?: Uint8Array;
8
+ accountSecret: AgentSecret;
9
+ provider: "anonymous" | "clerk" | "demo" | "passkey" | "passphrase" | string;
10
+ };
11
+ export declare class AuthSecretStorage {
12
+ private listeners;
13
+ isAuthenticated: boolean;
14
+ constructor();
15
+ migrate(): Promise<void>;
16
+ get(): Promise<AuthCredentials | null>;
17
+ setWithoutNotify(payload: AuthSetPayload): Promise<void>;
18
+ set(payload: AuthSetPayload): Promise<void>;
19
+ getIsAuthenticated(data: AuthCredentials | null): boolean;
20
+ onUpdate(handler: (isAuthenticated: boolean) => void): () => void;
21
+ emitUpdate(data: AuthCredentials | null): void;
22
+ clearWithoutNotify(): Promise<void>;
23
+ clear(): Promise<void>;
24
+ }
25
+ //# sourceMappingURL=AuthSecretStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthSecretStorage.d.ts","sourceRoot":"","sources":["../../src/auth/AuthSecretStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAK9C,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;IACvB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,aAAa,EAAE,WAAW,CAAC;IAC3B,QAAQ,EAAE,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,YAAY,GAAG,MAAM,CAAC;CAC9E,CAAC;AAEF,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,SAAS,CAA0C;IACpD,eAAe,EAAE,OAAO,CAAC;;IAO1B,OAAO;IAoDP,GAAG,IAAI,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAsBtC,gBAAgB,CAAC,OAAO,EAAE,cAAc;IAexC,GAAG,CAAC,OAAO,EAAE,cAAc;IAKjC,kBAAkB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,GAAG,OAAO;IAKzD,QAAQ,CAAC,OAAO,EAAE,CAAC,eAAe,EAAE,OAAO,KAAK,IAAI;IAOpD,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI;IAWjC,kBAAkB;IAKlB,KAAK;CAIZ"}
@@ -0,0 +1,27 @@
1
+ import { AuthenticateAccountFunction } from "../types.js";
2
+ import { AuthSecretStorage } from "./AuthSecretStorage.js";
3
+ /**
4
+ * `DemoAuth` provides a `JazzAuth` object for demo authentication.
5
+ *
6
+ * Demo authentication is useful for quickly testing your app, as it allows you to create new accounts and log in as existing ones.
7
+ *
8
+ * ```
9
+ * import { DemoAuth } from "jazz-tools";
10
+ *
11
+ * const auth = new DemoAuth(jazzContext.authenticate, new AuthSecretStorage());
12
+ * ```
13
+ *
14
+ * @category Auth Providers
15
+ */
16
+ export declare class DemoAuth {
17
+ private authenticate;
18
+ private authSecretStorage;
19
+ constructor(authenticate: AuthenticateAccountFunction, authSecretStorage: AuthSecretStorage);
20
+ logIn: (username: string) => Promise<void>;
21
+ signUp: (username: string) => Promise<void>;
22
+ private addToExistingUsers;
23
+ private getExisitingUsersWithData;
24
+ getExistingUsers: () => Promise<string[]>;
25
+ }
26
+ export declare function encodeUsername(username: string): string;
27
+ //# sourceMappingURL=DemoAuth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DemoAuth.d.ts","sourceRoot":"","sources":["../../src/auth/DemoAuth.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAS3D;;;;;;;;;;;;GAYG;AACH,qBAAa,QAAQ;IAEjB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,iBAAiB;gBADjB,YAAY,EAAE,2BAA2B,EACzC,iBAAiB,EAAE,iBAAiB;IAG9C,KAAK,aAAoB,MAAM,mBAqB7B;IAEF,MAAM,aAAoB,MAAM,mBAkC9B;YAEY,kBAAkB;YAalB,yBAAyB;IAQvC,gBAAgB,0BAEd;CACH;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,UAK9C"}
@@ -0,0 +1,9 @@
1
+ import { KvStore } from "./KvStoreContext.js";
2
+ export declare class InMemoryKVStore implements KvStore {
3
+ private store;
4
+ get(key: string): Promise<string | null>;
5
+ set(key: string, value: string): Promise<void>;
6
+ delete(key: string): Promise<void>;
7
+ clearAll(): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=InMemoryKVStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryKVStore.d.ts","sourceRoot":"","sources":["../../src/auth/InMemoryKVStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,qBAAa,eAAgB,YAAW,OAAO;IAC7C,OAAO,CAAC,KAAK,CAA8B;IAErC,GAAG,CAAC,GAAG,EAAE,MAAM;IAQf,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAI9B,MAAM,CAAC,GAAG,EAAE,MAAM;IAIlB,QAAQ;CAGf"}
@@ -0,0 +1,17 @@
1
+ export interface KvStore {
2
+ get(key: string): Promise<string | null>;
3
+ set(key: string, value: string): Promise<void>;
4
+ delete(key: string): Promise<void>;
5
+ clearAll(): Promise<void>;
6
+ }
7
+ export declare class KvStoreContext {
8
+ private static instance;
9
+ private storageInstance;
10
+ private constructor();
11
+ static getInstance(): KvStoreContext;
12
+ isInitialized(): boolean;
13
+ initialize(store: KvStore): void;
14
+ getStorage(): KvStore;
15
+ }
16
+ export default KvStoreContext;
17
+ //# sourceMappingURL=KvStoreContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KvStoreContext.d.ts","sourceRoot":"","sources":["../../src/auth/KvStoreContext.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACzC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAiB;IACxC,OAAO,CAAC,eAAe,CAAwB;IAE/C,OAAO;WAEO,WAAW,IAAI,cAAc;IAOpC,aAAa,IAAI,OAAO;IAIxB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAMhC,UAAU,IAAI,OAAO;CAM7B;AAED,eAAe,cAAc,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { CryptoProvider } from "cojson";
2
+ import { Account } from "../coValues/account.js";
3
+ import type { ID } from "../internal.js";
4
+ import type { AuthenticateAccountFunction, RegisterAccountFunction } from "../types.js";
5
+ import { AuthSecretStorage } from "./AuthSecretStorage.js";
6
+ /**
7
+ * `PassphraseAuth` provides a `JazzAuth` object for passphrase authentication.
8
+ *
9
+ * ```ts
10
+ * import { PassphraseAuth } from "jazz-tools";
11
+ *
12
+ * const auth = new PassphraseAuth(crypto, jazzContext.authenticate, new AuthSecretStorage(), wordlist);
13
+ * ```
14
+ *
15
+ * @category Auth Providers
16
+ */
17
+ export declare class PassphraseAuth {
18
+ private crypto;
19
+ private authenticate;
20
+ private register;
21
+ private authSecretStorage;
22
+ wordlist: string[];
23
+ passphrase: string;
24
+ constructor(crypto: CryptoProvider, authenticate: AuthenticateAccountFunction, register: RegisterAccountFunction, authSecretStorage: AuthSecretStorage, wordlist: string[]);
25
+ logIn: (passphrase: string) => Promise<void>;
26
+ signUp: (name?: string) => Promise<string>;
27
+ registerNewAccount: (passphrase: string, name: string) => Promise<ID<Account>>;
28
+ getCurrentAccountPassphrase: () => Promise<string>;
29
+ generateRandomPassphrase: () => string;
30
+ loadCurrentAccountPassphrase: () => Promise<void>;
31
+ listeners: Set<() => void>;
32
+ subscribe: (callback: () => void) => () => void;
33
+ notify(): void;
34
+ }
35
+ //# sourceMappingURL=PassphraseAuth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PassphraseAuth.d.ts","sourceRoot":"","sources":["../../src/auth/PassphraseAuth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAmB,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,KAAK,EACV,2BAA2B,EAC3B,uBAAuB,EACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;;;;;;;;GAUG;AACH,qBAAa,cAAc;IAIvB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,iBAAiB;IAClB,QAAQ,EAAE,MAAM,EAAE;IAP3B,UAAU,EAAE,MAAM,CAAM;gBAGd,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,2BAA2B,EACzC,QAAQ,EAAE,uBAAuB,EACjC,iBAAiB,EAAE,iBAAiB,EACrC,QAAQ,EAAE,MAAM,EAAE;IAG3B,KAAK,eAAsB,MAAM,mBAgC/B;IAEF,MAAM,UAAiB,MAAM,qBAyB3B;IAEF,kBAAkB,eAAsB,MAAM,QAAQ,MAAM,0BAa1D;IAEF,2BAA2B,wBAQzB;IAEF,wBAAwB,eAEtB;IAEF,4BAA4B,sBAI1B;IAEF,SAAS,YAAiB,IAAI,EAAI;IAClC,SAAS,aAAc,MAAM,IAAI,gBAM/B;IAEF,MAAM;CAKP"}
@@ -46,7 +46,6 @@ var inspect = Symbol.for("nodejs.util.inspect.custom");
46
46
  // src/implementation/symbols.ts
47
47
  var SchemaInit = "$SchemaInit$";
48
48
  var ItemsSym = "$items$";
49
- var MembersSym = "$members$";
50
49
 
51
50
  // src/coValues/deepLoading.ts
52
51
  function fulfillsDepth(depth, value) {
@@ -319,7 +318,6 @@ var co = {
319
318
  },
320
319
  ref,
321
320
  items: ItemsSym,
322
- members: MembersSym,
323
321
  optional
324
322
  };
325
323
  function optionalRef(arg) {
@@ -1112,6 +1110,11 @@ var InboxSender = class _InboxSender {
1112
1110
  if (inboxOwnerProfileRaw === "unavailable") {
1113
1111
  throw new Error("Failed to load the inbox owner profile");
1114
1112
  }
1113
+ if (inboxOwnerProfileRaw.group.roleOf(currentAccount._raw.id) !== "reader" && inboxOwnerProfileRaw.group.roleOf(currentAccount._raw.id) !== "writer" && inboxOwnerProfileRaw.group.roleOf(currentAccount._raw.id) !== "admin") {
1114
+ throw new Error(
1115
+ "Insufficient permissions to access the inbox, make sure its user profile is publicly readable."
1116
+ );
1117
+ }
1115
1118
  const inboxInvite = inboxOwnerProfileRaw.get("inboxInvite");
1116
1119
  if (!inboxInvite) {
1117
1120
  throw new Error("The user has not set up their inbox");
@@ -1294,7 +1297,7 @@ var _CoMap = class _CoMap extends CoValueBase {
1294
1297
  const jsonedFields = this._raw.keys().map((key) => {
1295
1298
  const tKey = key;
1296
1299
  const descriptor = this._schema[tKey] || this._schema[ItemsSym];
1297
- if (descriptor == "json" || "encode" in descriptor) {
1300
+ if (descriptor == "json" || "encoded" in descriptor) {
1298
1301
  return [key, this._raw.get(key)];
1299
1302
  } else if (isRefEncoded(descriptor)) {
1300
1303
  if (seenAbove?.includes(this[tKey]?.id)) {
@@ -1578,6 +1581,23 @@ var Profile = class extends CoMap {
1578
1581
  this.inbox = co.optional.json();
1579
1582
  this.inboxInvite = co.optional.json();
1580
1583
  }
1584
+ get _owner() {
1585
+ return super._owner;
1586
+ }
1587
+ /**
1588
+ * Creates a new profile with the given initial values and owner.
1589
+ *
1590
+ * The owner (a Group) determines access rights to the Profile.
1591
+ *
1592
+ * @category Creation
1593
+ */
1594
+ static create(init, options) {
1595
+ const owner = options !== void 0 && "owner" in options ? options.owner : options;
1596
+ if (owner?._type === "Account") {
1597
+ throw new Error("Profiles should be owned by a group");
1598
+ }
1599
+ return super.create(init, options);
1600
+ }
1581
1601
  };
1582
1602
 
1583
1603
  // src/coValues/account.ts
@@ -1649,6 +1669,36 @@ var _Account = class _Account extends CoValueBase {
1649
1669
  return "admin";
1650
1670
  }
1651
1671
  }
1672
+ getRoleOf(member) {
1673
+ if (member === "me") {
1674
+ return this.isMe ? "admin" : void 0;
1675
+ }
1676
+ if (member === this.id) {
1677
+ return "admin";
1678
+ }
1679
+ return void 0;
1680
+ }
1681
+ getParentGroups() {
1682
+ return [];
1683
+ }
1684
+ get members() {
1685
+ const ref2 = new Ref(this.id, this._loadedAs, {
1686
+ ref: () => this.constructor,
1687
+ optional: false
1688
+ });
1689
+ return [{ id: this.id, role: "admin", ref: ref2, account: this }];
1690
+ }
1691
+ canRead(value) {
1692
+ const role = value._owner.getRoleOf(this.id);
1693
+ return role === "admin" || role === "writer" || role === "reader" || role === "writeOnly";
1694
+ }
1695
+ canWrite(value) {
1696
+ const role = value._owner.getRoleOf(this.id);
1697
+ return role === "admin" || role === "writer" || role === "writeOnly";
1698
+ }
1699
+ canAdmin(value) {
1700
+ return value._owner.getRoleOf(this.id) === "admin";
1701
+ }
1652
1702
  async acceptInvite(valueID, inviteSecret, coValueClass) {
1653
1703
  if (!this.isLocalNodeOwner) {
1654
1704
  throw new Error("Only a controlled account can accept invites");
@@ -1704,13 +1754,17 @@ var _Account = class _Account extends CoValueBase {
1704
1754
  return this.toJSON();
1705
1755
  }
1706
1756
  async applyMigration(creationProps) {
1707
- if (creationProps) {
1757
+ await this.migrate(creationProps);
1758
+ if (this.profile === void 0 && creationProps) {
1708
1759
  const profileGroup = RegisteredSchemas["Group"].create({ owner: this });
1709
- profileGroup.addMember("everyone", "reader");
1710
- this.profile = Profile.create(
1711
- { name: creationProps.name },
1712
- { owner: profileGroup }
1713
- );
1760
+ this.profile = Profile.create({ name: creationProps.name }, profileGroup);
1761
+ this.profile._owner.addMember("everyone", "reader");
1762
+ } else if (this.profile && creationProps) {
1763
+ if (this.profile._owner._type !== "Group") {
1764
+ throw new Error("Profile must be owned by a Group", {
1765
+ cause: `The profile of the account "${this.id}" was created with an Account as owner, which is not allowed.`
1766
+ });
1767
+ }
1714
1768
  }
1715
1769
  const node = this._raw.core.node;
1716
1770
  const profile = node.expectCoValueLoaded(this._raw.get("profile")).getCurrentContent();
@@ -1719,7 +1773,6 @@ var _Account = class _Account extends CoValueBase {
1719
1773
  profile.set("inbox", inboxRoot.id);
1720
1774
  profile.set("inboxInvite", inboxRoot.inviteLink);
1721
1775
  }
1722
- await this.migrate(creationProps);
1723
1776
  }
1724
1777
  // Placeholder method for subclasses to override
1725
1778
  migrate(creationProps) {
@@ -1791,7 +1844,7 @@ var AccountAndGroupProxyHandler = {
1791
1844
  }
1792
1845
  },
1793
1846
  set(target, key, value, receiver) {
1794
- if ((key === "profile" || key === "root" || key === MembersSym) && typeof value === "object" && SchemaInit in value) {
1847
+ if ((key === "profile" || key === "root") && typeof value === "object" && SchemaInit in value) {
1795
1848
  target.constructor._schema ||= {};
1796
1849
  target.constructor._schema[key] = value[SchemaInit];
1797
1850
  return true;
@@ -1816,7 +1869,7 @@ var AccountAndGroupProxyHandler = {
1816
1869
  }
1817
1870
  },
1818
1871
  defineProperty(target, key, descriptor) {
1819
- if ((key === "profile" || key === "root" || key === MembersSym) && typeof descriptor.value === "object" && SchemaInit in descriptor.value) {
1872
+ if ((key === "profile" || key === "root") && typeof descriptor.value === "object" && SchemaInit in descriptor.value) {
1820
1873
  target.constructor._schema ||= {};
1821
1874
  target.constructor._schema[key] = descriptor.value[SchemaInit];
1822
1875
  return true;
@@ -2370,6 +2423,7 @@ var FileStream = class extends CoValueBase {
2370
2423
 
2371
2424
  // src/coValues/coList.ts
2372
2425
  import { RawAccount as RawAccount5 } from "cojson";
2426
+ import { calcPatch } from "fast-myers-diff";
2373
2427
  var _CoList = class _CoList extends Array {
2374
2428
  /**
2375
2429
  * Declare a `CoList` by subclassing `CoList.Of(...)` and passing the item schema using `co`.
@@ -2534,12 +2588,20 @@ var _CoList = class _CoList extends Array {
2534
2588
  }
2535
2589
  let appendAfter = Math.max(start - 1, 0);
2536
2590
  for (const item of toRawItems(items, this._schema[ItemsSym])) {
2537
- console.log(this._raw.asArray(), appendAfter);
2538
2591
  this._raw.append(item, appendAfter);
2539
2592
  appendAfter++;
2540
2593
  }
2541
2594
  return deleted;
2542
2595
  }
2596
+ applyDiff(other) {
2597
+ const current = this._raw.asArray();
2598
+ const cmp = isRefEncoded(this._schema[ItemsSym]) ? (aIdx, bIdx) => current[aIdx].id === other[bIdx].id : void 0;
2599
+ for (const [from, to, insert] of [
2600
+ ...calcPatch(current, other, cmp)
2601
+ ].reverse()) {
2602
+ this.splice(from, to - from, ...insert);
2603
+ }
2604
+ }
2543
2605
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2544
2606
  toJSON(_key, seenAbove) {
2545
2607
  const itemDescriptor = this._schema[ItemsSym];
@@ -2753,31 +2815,58 @@ var _Group = class _Group extends CoValueBase {
2753
2815
  return this._raw.removeMember(member === "everyone" ? member : member._raw);
2754
2816
  }
2755
2817
  get members() {
2756
- return this._raw.keys().filter((key) => {
2757
- return key === "everyone" || key.startsWith("co_");
2758
- }).map((id) => {
2759
- const role = this._raw.get(id);
2760
- const accountID = id === "everyone" ? void 0 : id;
2761
- const ref2 = accountID && new Ref(
2762
- accountID,
2763
- this._loadedAs,
2764
- this._schema[MembersSym]
2765
- );
2766
- const accessRef = () => ref2?.accessFrom(this, "members." + id);
2767
- return {
2768
- id,
2769
- role,
2770
- ref: ref2,
2771
- get account() {
2772
- return accessRef();
2818
+ const members = [];
2819
+ const BaseAccountSchema = activeAccountContext.maybeGet()?.constructor || RegisteredSchemas["Account"];
2820
+ const refEncodedAccountSchema = {
2821
+ ref: () => BaseAccountSchema,
2822
+ optional: false
2823
+ };
2824
+ for (const accountID of this._raw.getAllMemberKeysSet()) {
2825
+ if (!isAccountID(accountID)) continue;
2826
+ const role = this._raw.roleOf(accountID);
2827
+ if (role === "admin" || role === "writer" || role === "reader" || role === "writeOnly") {
2828
+ const ref2 = new Ref(
2829
+ accountID,
2830
+ this._loadedAs,
2831
+ refEncodedAccountSchema
2832
+ );
2833
+ const accessRef = () => ref2.accessFrom(this, "members." + accountID);
2834
+ if (!ref2.syncLoad()) {
2835
+ console.warn("Account not loaded", accountID);
2773
2836
  }
2774
- };
2775
- });
2837
+ members.push({
2838
+ id: accountID,
2839
+ role,
2840
+ ref: ref2,
2841
+ get account() {
2842
+ return accessRef();
2843
+ }
2844
+ });
2845
+ }
2846
+ }
2847
+ return members;
2848
+ }
2849
+ getRoleOf(member) {
2850
+ if (member === "me") {
2851
+ return this._raw.roleOf(
2852
+ activeAccountContext.get().id
2853
+ );
2854
+ }
2855
+ return this._raw.roleOf(
2856
+ member === "everyone" ? member : member
2857
+ );
2858
+ }
2859
+ getParentGroups() {
2860
+ return this._raw.getParentGroups().map(({ group }) => _Group.fromRaw(group));
2776
2861
  }
2777
2862
  extend(parent, roleMapping) {
2778
2863
  this._raw.extend(parent._raw, roleMapping);
2779
2864
  return this;
2780
2865
  }
2866
+ async revokeExtend(parent) {
2867
+ await this._raw.revokeExtend(parent._raw);
2868
+ return this;
2869
+ }
2781
2870
  static load(id, asOrDepth, depth) {
2782
2871
  return loadCoValueWithoutMe(this, id, asOrDepth, depth);
2783
2872
  }
@@ -2810,11 +2899,7 @@ var _Group = class _Group extends CoValueBase {
2810
2899
  _Group.prototype._type = "Group";
2811
2900
  _Group._schema = {
2812
2901
  profile: "json",
2813
- root: "json",
2814
- [MembersSym]: {
2815
- ref: () => RegisteredSchemas["Account"],
2816
- optional: false
2817
- }
2902
+ root: "json"
2818
2903
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2819
2904
  };
2820
2905
  Object.defineProperty(_Group.prototype, "_schema", {
@@ -2822,6 +2907,9 @@ Object.defineProperty(_Group.prototype, "_schema", {
2822
2907
  });
2823
2908
  var Group = _Group;
2824
2909
  RegisteredSchemas["Group"] = Group;
2910
+ function isAccountID(id) {
2911
+ return id.startsWith("co_");
2912
+ }
2825
2913
 
2826
2914
  // src/coValues/coPlainText.ts
2827
2915
  import {
@@ -3293,40 +3381,45 @@ function splitNode(node, at) {
3293
3381
  ];
3294
3382
  }
3295
3383
  }
3296
- var Marks = {
3297
- Heading: class Heading extends Mark {
3298
- constructor() {
3299
- super(...arguments);
3300
- this.tag = co.literal("heading");
3301
- this.level = co.number;
3302
- }
3303
- },
3304
- Paragraph: class Paragraph extends Mark {
3305
- constructor() {
3306
- super(...arguments);
3307
- this.tag = co.literal("paragraph");
3308
- }
3309
- },
3310
- Link: class Link extends Mark {
3311
- constructor() {
3312
- super(...arguments);
3313
- this.tag = co.literal("link");
3314
- this.url = co.string;
3315
- }
3316
- },
3317
- Strong: class Strong extends Mark {
3318
- constructor() {
3319
- super(...arguments);
3320
- this.tag = co.literal("strong");
3321
- }
3322
- },
3323
- Em: class Italic extends Mark {
3324
- constructor() {
3325
- super(...arguments);
3326
- this.tag = co.literal("em");
3327
- }
3384
+ var Heading = class extends Mark {
3385
+ constructor() {
3386
+ super(...arguments);
3387
+ this.tag = co.literal("heading");
3388
+ this.level = co.number;
3389
+ }
3390
+ };
3391
+ var Paragraph = class extends Mark {
3392
+ constructor() {
3393
+ super(...arguments);
3394
+ this.tag = co.literal("paragraph");
3395
+ }
3396
+ };
3397
+ var Link = class extends Mark {
3398
+ constructor() {
3399
+ super(...arguments);
3400
+ this.tag = co.literal("link");
3401
+ this.url = co.string;
3328
3402
  }
3329
3403
  };
3404
+ var Strong = class extends Mark {
3405
+ constructor() {
3406
+ super(...arguments);
3407
+ this.tag = co.literal("strong");
3408
+ }
3409
+ };
3410
+ var Em = class extends Mark {
3411
+ constructor() {
3412
+ super(...arguments);
3413
+ this.tag = co.literal("em");
3414
+ }
3415
+ };
3416
+ var Marks = {
3417
+ Heading,
3418
+ Paragraph,
3419
+ Link,
3420
+ Strong,
3421
+ Em
3422
+ };
3330
3423
 
3331
3424
  // src/coValues/extensions/imageDef.ts
3332
3425
  var _a, _b;
@@ -4073,4 +4166,4 @@ export {
4073
4166
  consumeInviteLink
4074
4167
  };
4075
4168
  /* istanbul ignore file -- @preserve */
4076
- //# sourceMappingURL=chunk-5USJBXLW.js.map
4169
+ //# sourceMappingURL=chunk-MVDJNBLV.js.map