@dxos/client-services 0.5.9-main.bf0ae3e → 0.5.9-main.bf3bb8f

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 (51) hide show
  1. package/dist/lib/browser/{chunk-4IR3JP4U.mjs → chunk-IUSAD4RP.mjs} +1405 -824
  2. package/dist/lib/browser/chunk-IUSAD4RP.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +13 -4
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +10 -3
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +1 -1
  8. package/dist/lib/node/{chunk-ZBIDLLZ4.cjs → chunk-5PALJZPW.cjs} +1534 -956
  9. package/dist/lib/node/chunk-5PALJZPW.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +53 -44
  11. package/dist/lib/node/index.cjs.map +1 -1
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +17 -10
  14. package/dist/lib/node/packlets/testing/index.cjs.map +1 -1
  15. package/dist/types/src/packlets/identity/contacts-service.d.ts +14 -0
  16. package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -0
  17. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  19. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  20. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  21. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +4 -1
  22. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  23. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +10 -1
  24. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  25. package/dist/types/src/packlets/spaces/data-space.d.ts +9 -9
  26. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  27. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts +23 -0
  28. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -0
  29. package/dist/types/src/packlets/spaces/spaces-service.d.ts +5 -2
  30. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  31. package/dist/types/src/packlets/storage/index.d.ts +1 -0
  32. package/dist/types/src/packlets/storage/index.d.ts.map +1 -1
  33. package/dist/types/src/packlets/storage/profile-archive.d.ts +14 -0
  34. package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -0
  35. package/dist/types/src/version.d.ts +1 -1
  36. package/package.json +36 -36
  37. package/src/packlets/identity/contacts-service.ts +85 -0
  38. package/src/packlets/identity/identity-service.ts +45 -13
  39. package/src/packlets/invitations/invitations-handler.ts +13 -5
  40. package/src/packlets/invitations/space-invitation-protocol.ts +11 -32
  41. package/src/packlets/services/service-host.ts +12 -4
  42. package/src/packlets/spaces/automerge-space-state.ts +11 -2
  43. package/src/packlets/spaces/data-space-manager.ts +90 -16
  44. package/src/packlets/spaces/data-space.ts +78 -148
  45. package/src/packlets/spaces/epoch-migrations.ts +154 -0
  46. package/src/packlets/spaces/spaces-service.ts +56 -4
  47. package/src/packlets/storage/index.ts +1 -0
  48. package/src/packlets/storage/profile-archive.ts +111 -0
  49. package/src/version.ts +1 -1
  50. package/dist/lib/browser/chunk-4IR3JP4U.mjs.map +0 -7
  51. package/dist/lib/node/chunk-ZBIDLLZ4.cjs.map +0 -7
@@ -0,0 +1,111 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { cbor } from '@dxos/automerge/automerge-repo';
6
+ import { invariant } from '@dxos/invariant';
7
+ import type { LevelDB } from '@dxos/kv-store';
8
+ import { log } from '@dxos/log';
9
+ import { ProfileArchiveEntryType, type ProfileArchive } from '@dxos/protocols';
10
+ import type { Storage } from '@dxos/random-access-storage';
11
+ import { arrayToBuffer } from '@dxos/util';
12
+
13
+ export const encodeProfileArchive = (profile: ProfileArchive): Uint8Array => cbor.encode(profile);
14
+
15
+ export const decodeProfileArchive = (data: Uint8Array): ProfileArchive => cbor.decode(data);
16
+
17
+ export const exportProfileData = async ({
18
+ storage,
19
+ level,
20
+ }: {
21
+ storage: Storage;
22
+ level: LevelDB;
23
+ }): Promise<ProfileArchive> => {
24
+ const archive: ProfileArchive = { storage: [], meta: { timestamp: new Date().toISOString() } };
25
+
26
+ {
27
+ const directory = await storage.createDirectory();
28
+ const files = await directory.list();
29
+
30
+ log.info('begin exporting files', { count: files.length });
31
+ for (const filename of files) {
32
+ const file = await directory.getOrCreateFile(filename);
33
+ const { size } = await file.stat();
34
+ const data = await file.read(0, size);
35
+ archive.storage.push({
36
+ type: ProfileArchiveEntryType.FILE,
37
+ key: filename,
38
+ value: data,
39
+ });
40
+ }
41
+ log.info('done exporting files', { count: files.length });
42
+ }
43
+
44
+ {
45
+ log.info('begin exporting kv pairs');
46
+ const iter = await level.iterator<Uint8Array, Uint8Array>({ keyEncoding: 'binary', valueEncoding: 'binary' });
47
+ let count = 0;
48
+ for await (const [key, value] of iter) {
49
+ archive.storage.push({
50
+ type: ProfileArchiveEntryType.KEY_VALUE,
51
+ key,
52
+ value,
53
+ });
54
+ count++;
55
+ }
56
+ log.info('done exporting kv pairs', { count });
57
+ }
58
+
59
+ return archive;
60
+ };
61
+
62
+ export const importProfileData = async (
63
+ {
64
+ storage,
65
+ level,
66
+ }: {
67
+ storage: Storage;
68
+ level: LevelDB;
69
+ },
70
+ archive: ProfileArchive,
71
+ ): Promise<void> => {
72
+ let batch = level.batch();
73
+
74
+ let count = 0;
75
+ for (const entry of archive.storage) {
76
+ switch (entry.type) {
77
+ case ProfileArchiveEntryType.FILE: {
78
+ const directory = await storage.createDirectory();
79
+ invariant(typeof entry.key === 'string', 'Invalid key type');
80
+ const file = await directory.getOrCreateFile(entry.key);
81
+ invariant(entry.value instanceof Uint8Array, 'Invalid value type');
82
+ await file.write(0, arrayToBuffer(entry.value));
83
+ await file.close();
84
+ break;
85
+ }
86
+ case ProfileArchiveEntryType.KEY_VALUE: {
87
+ invariant(entry.key instanceof Uint8Array, 'Invalid key type');
88
+ invariant(entry.value instanceof Uint8Array, 'Invalid value type');
89
+ batch.put(entry.key, entry.value, { keyEncoding: 'binary', valueEncoding: 'binary' });
90
+ break;
91
+ }
92
+ default:
93
+ throw new Error(`Invalid entry type: ${entry.type}`);
94
+ }
95
+
96
+ if (++count % 1000 === 0) {
97
+ // Apparently indexedDB can't handle big batches.
98
+ await batch.write();
99
+ batch = level.batch();
100
+
101
+ log.info('importing', {
102
+ count,
103
+ total: archive.storage.length,
104
+ progress: `${((count / archive.storage.length) * 100).toFixed()}%`,
105
+ });
106
+ }
107
+ }
108
+
109
+ log.info('committing changes..');
110
+ await batch.write();
111
+ };
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const DXOS_VERSION = "0.5.9-main.bf0ae3e";
1
+ export const DXOS_VERSION = "0.5.9-main.bf3bb8f";