mindoodb 0.1.2 → 0.1.4

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 (42) hide show
  1. package/README.md +1 -0
  2. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts +3 -2
  3. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts.map +1 -1
  4. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js +44 -9
  5. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js.map +1 -1
  6. package/dist/browser/index.mjs +5 -0
  7. package/dist/core/BaseMindooDB.d.ts +9 -0
  8. package/dist/core/BaseMindooDB.d.ts.map +1 -1
  9. package/dist/core/BaseMindooDB.js +18 -0
  10. package/dist/core/BaseMindooDB.js.map +1 -1
  11. package/dist/core/BaseMindooTenantDirectory.d.ts +4 -1
  12. package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -1
  13. package/dist/core/BaseMindooTenantDirectory.js +7 -3
  14. package/dist/core/BaseMindooTenantDirectory.js.map +1 -1
  15. package/dist/core/accesscontrol/evaluate.d.ts +7 -0
  16. package/dist/core/accesscontrol/evaluate.d.ts.map +1 -1
  17. package/dist/core/accesscontrol/evaluate.js +101 -0
  18. package/dist/core/accesscontrol/evaluate.js.map +1 -1
  19. package/dist/core/accesscontrol/types.d.ts +19 -3
  20. package/dist/core/accesscontrol/types.d.ts.map +1 -1
  21. package/dist/core/accesscontrol/types.js +29 -1
  22. package/dist/core/accesscontrol/types.js.map +1 -1
  23. package/dist/core/archive/documentArchive.d.ts +221 -0
  24. package/dist/core/archive/documentArchive.d.ts.map +1 -0
  25. package/dist/core/archive/documentArchive.js +559 -0
  26. package/dist/core/archive/documentArchive.js.map +1 -0
  27. package/dist/core/index.d.ts +1 -0
  28. package/dist/core/index.d.ts.map +1 -1
  29. package/dist/core/index.js +10 -3
  30. package/dist/core/index.js.map +1 -1
  31. package/dist/core/types.d.ts +26 -0
  32. package/dist/core/types.d.ts.map +1 -1
  33. package/dist/core/types.js.map +1 -1
  34. package/dist/server/DeviceDiscoveryService.d.ts +7 -1
  35. package/dist/server/DeviceDiscoveryService.d.ts.map +1 -1
  36. package/dist/server/DeviceDiscoveryService.js +68 -24
  37. package/dist/server/DeviceDiscoveryService.js.map +1 -1
  38. package/dist/server/peer/PeerReplicator.d.ts +2 -1
  39. package/dist/server/peer/PeerReplicator.d.ts.map +1 -1
  40. package/dist/server/peer/PeerReplicator.js +2 -1
  41. package/dist/server/peer/PeerReplicator.js.map +1 -1
  42. package/package.json +1 -1
@@ -0,0 +1,221 @@
1
+ /**
2
+ * Document archives: a portable, file-based copy of chosen documents with their
3
+ * complete revision history, their attachment chunks and who wrote what when.
4
+ *
5
+ * The use case is support. A document got into a bad state on a customer's
6
+ * devices; the customer exports it, a developer imports it into a fresh
7
+ * database of their own and replays, inspects or repairs the history there.
8
+ *
9
+ * Format (version 1, `content: "plain"`). The archive is a flat map of paths to
10
+ * bytes, laid out like the on-disk store so it can be read by eye once zipped:
11
+ *
12
+ * ```
13
+ * manifest.json format, source, exporter, documents, file hashes
14
+ * manifest.sig exporter's Ed25519 signature over manifest.json (base64)
15
+ * authors.json signing public key -> user name, as the source directory knew it
16
+ * documents/<docId>/document.json per-document summary (heads, counts)
17
+ * documents/<docId>/history.json entry ids in causal order
18
+ * documents/<docId>/entries/<entryId>.json entry metadata, signatures as base64
19
+ * documents/<docId>/changes/<entryId>.bin decrypted payload (Automerge change/snapshot bytes)
20
+ * documents/<docId>/attachments/<attachmentId>/entries/<chunkId>.json
21
+ * documents/<docId>/attachments/<attachmentId>/chunks/<chunkId>.bin decrypted chunk bytes
22
+ * ```
23
+ *
24
+ * "plain" means the payloads are decrypted: the archive is only as safe as the
25
+ * container it travels in. Zipping and encrypting the container is up to the
26
+ * caller (Haven protects it with a password).
27
+ *
28
+ * Signatures only verify in the system they were made in, so an import cannot
29
+ * keep them. It works like a replay copy (`copy/copyDocument.ts`): every entry
30
+ * keeps its id, dependencies and Automerge bytes, is encrypted with the target's
31
+ * key and signed by the importing user, and carries a provenance record with
32
+ * the original entry's signed projection and signature. `verifyEntryProvenance`
33
+ * then still proves who wrote each revision originally.
34
+ *
35
+ * @module
36
+ */
37
+ import { type EntryProvenance } from "../crypto/EntrySignature";
38
+ import type { CopyEngineHost } from "../copy/host";
39
+ import { type StoreEntryAttachmentRef, type StoreEntryType } from "../types";
40
+ /** Value of `manifest.format`. */
41
+ export declare const DOCUMENT_ARCHIVE_FORMAT = "mindoodb-document-archive";
42
+ /** Highest archive format version this code reads and the one it writes. */
43
+ export declare const DOCUMENT_ARCHIVE_VERSION = 1;
44
+ /** Suggested file extension of a zipped archive. */
45
+ export declare const DOCUMENT_ARCHIVE_EXTENSION = ".mdbdocs";
46
+ /** An archive as a map of relative paths to file contents. */
47
+ export type DocumentArchiveFiles = Record<string, Uint8Array>;
48
+ /** One entry's metadata as stored in the archive (binary fields as base64). */
49
+ export interface DocumentArchiveEntryRecord {
50
+ entryType: StoreEntryType;
51
+ id: string;
52
+ docId: string;
53
+ dependencyIds: string[];
54
+ createdAt: number;
55
+ createdByPublicKey: string;
56
+ decryptionKeyId: string;
57
+ contentHash: string;
58
+ signature: string;
59
+ metadataSignature?: string;
60
+ provenance?: EntryProvenance;
61
+ snapshotHeadHashes?: string[];
62
+ snapshotHeadEntryIds?: string[];
63
+ attachmentId?: string;
64
+ attachmentIds?: string[];
65
+ attachmentRefs?: StoreEntryAttachmentRef[];
66
+ originalSize: number;
67
+ encryptedSize: number;
68
+ entryVersion?: number;
69
+ receiptOrder?: number;
70
+ receivedAt?: number;
71
+ receivedByPublicKey?: string;
72
+ receivedDateSignature?: string;
73
+ receiptScheme?: string;
74
+ }
75
+ /** Per-document summary in the manifest and in `document.json`. */
76
+ export interface DocumentArchiveDocumentSummary {
77
+ docId: string;
78
+ /** Revision entries (create, change, delete, undelete, snapshot). */
79
+ entryCount: number;
80
+ /** Attachment chunk entries. */
81
+ chunkCount: number;
82
+ /** Distinct attachments the chunks belong to. */
83
+ attachmentCount: number;
84
+ /** Entry ids no other entry depends on: the document's current heads. */
85
+ headEntryIds: string[];
86
+ /** Oldest and newest `createdAt` of the revision entries. */
87
+ firstCreatedAt: number;
88
+ lastCreatedAt: number;
89
+ /** Whether the latest revision is a deletion. */
90
+ deleted: boolean;
91
+ }
92
+ /** Contents of `manifest.json`. */
93
+ export interface DocumentArchiveManifest {
94
+ format: typeof DOCUMENT_ARCHIVE_FORMAT;
95
+ version: number;
96
+ content: "plain";
97
+ /** ISO time of the export. */
98
+ createdAt: string;
99
+ source: {
100
+ tenantId: string;
101
+ dbId: string;
102
+ /** Free text the caller supplies, e.g. "Local" or a server URL. */
103
+ location?: string;
104
+ /** Free text the caller supplies, e.g. the tenant's display name. */
105
+ tenantLabel?: string;
106
+ };
107
+ exportedBy: {
108
+ signingPublicKey: string;
109
+ username?: string;
110
+ };
111
+ /** Free text, e.g. what went wrong. */
112
+ note?: string;
113
+ documents: DocumentArchiveDocumentSummary[];
114
+ /** SHA-256 (hex) of every other file in the archive. */
115
+ files: Record<string, string>;
116
+ }
117
+ /** One line of `authors.json`. */
118
+ export interface DocumentArchiveAuthor {
119
+ signingPublicKey: string;
120
+ /** Null when the source directory did not know the key. */
121
+ username: string | null;
122
+ entryCount: number;
123
+ }
124
+ /** A parsed and integrity-checked archive. */
125
+ export interface DocumentArchive {
126
+ manifest: DocumentArchiveManifest;
127
+ authors: DocumentArchiveAuthor[];
128
+ documents: DocumentArchiveDocument[];
129
+ /** What could be established about the exporter's manifest signature. */
130
+ exporterSignature: "verified" | "invalid" | "missing";
131
+ }
132
+ /** One document of a parsed archive. */
133
+ export interface DocumentArchiveDocument {
134
+ summary: DocumentArchiveDocumentSummary;
135
+ /** Revision entries in causal order. */
136
+ entries: Array<{
137
+ record: DocumentArchiveEntryRecord;
138
+ payload: Uint8Array;
139
+ }>;
140
+ /** Attachment chunks, in dependency order per attachment. */
141
+ chunks: Array<{
142
+ record: DocumentArchiveEntryRecord;
143
+ payload: Uint8Array;
144
+ }>;
145
+ }
146
+ /** Options for {@link exportDocumentArchive}. */
147
+ export interface ExportDocumentArchiveOptions {
148
+ /** Shown in the manifest as `source.location`. */
149
+ location?: string;
150
+ /** Shown in the manifest as `source.tenantLabel`. */
151
+ tenantLabel?: string;
152
+ /** Free text stored in the manifest. */
153
+ note?: string;
154
+ signal?: AbortSignal;
155
+ }
156
+ /** Options for {@link importDocumentArchive}. */
157
+ export interface ImportDocumentArchiveOptions {
158
+ /**
159
+ * Key to encrypt the imported entries with. Defaults to the entry's original
160
+ * key id when importing into the source tenant and to `"default"` otherwise.
161
+ */
162
+ decryptionKeyId?: string;
163
+ /** Only import these documents of the archive. Defaults to all of them. */
164
+ docIds?: string[];
165
+ /** Skip the write-access precheck (admin tooling only). */
166
+ bypassAccessControlPrecheck?: boolean;
167
+ signal?: AbortSignal;
168
+ }
169
+ /** Result of {@link importDocumentArchive}. */
170
+ export interface ImportDocumentArchiveResult {
171
+ importedDocIds: string[];
172
+ importedEntries: number;
173
+ importedChunks: number;
174
+ }
175
+ /** What {@link checkDocumentArchiveImport} found in the target database. */
176
+ export interface DocumentArchiveImportCheck {
177
+ /** Archived documents whose id already exists in the target. */
178
+ existingDocIds: string[];
179
+ /** Archived documents that do not exist in the target yet. */
180
+ newDocIds: string[];
181
+ }
182
+ /** Thrown when an archive is malformed, from an unknown version or tampered with. */
183
+ export declare class DocumentArchiveFormatError extends Error {
184
+ constructor(message: string);
185
+ }
186
+ /** Thrown when an import would write into documents that already exist. */
187
+ export declare class DocumentArchiveConflictError extends Error {
188
+ readonly existingDocIds: string[];
189
+ constructor(existingDocIds: string[]);
190
+ }
191
+ /**
192
+ * Write the chosen documents of a database into a plain archive.
193
+ *
194
+ * @param source The database to export from.
195
+ * @param docIds The documents to export. Unknown ids are an error.
196
+ */
197
+ export declare function exportDocumentArchive(source: CopyEngineHost, docIds: string[], options?: ExportDocumentArchiveOptions): Promise<DocumentArchiveFiles>;
198
+ /**
199
+ * Parse an archive and check its integrity: format and version, the SHA-256 of
200
+ * every file named in the manifest, and that no unlisted file is present.
201
+ *
202
+ * The exporter's manifest signature is checked against the key the manifest
203
+ * itself names. That proves the manifest was not edited after the export; it
204
+ * does not prove who the key belongs to (the importing tenant usually does not
205
+ * know the exporter).
206
+ */
207
+ export declare function readDocumentArchive(files: DocumentArchiveFiles, subtle: SubtleCrypto): Promise<DocumentArchive>;
208
+ /** Which of the archive's documents already exist in the target database. */
209
+ export declare function checkDocumentArchiveImport(target: CopyEngineHost, archive: DocumentArchive): Promise<DocumentArchiveImportCheck>;
210
+ /**
211
+ * Import an archive into a database that does not contain any of its
212
+ * documents yet.
213
+ *
214
+ * Entry ids, dependencies and the Automerge bytes stay as they were, so the
215
+ * document's revision graph is the same as in the source. Every entry is
216
+ * encrypted with the target's key, signed by the importing user and gets a
217
+ * provenance record naming the original author. Timestamps are rewritten to
218
+ * import time (keeping their order), exactly like a replay copy.
219
+ */
220
+ export declare function importDocumentArchive(target: CopyEngineHost, archive: DocumentArchive, options?: ImportDocumentArchiveOptions): Promise<ImportDocumentArchiveResult>;
221
+ //# sourceMappingURL=documentArchive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentArchive.d.ts","sourceRoot":"","sources":["../../../src/core/archive/documentArchive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAGH,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAOnD,OAAO,EAGL,KAAK,uBAAuB,EAE5B,KAAK,cAAc,EACpB,MAAM,UAAU,CAAC;AAElB,kCAAkC;AAClC,eAAO,MAAM,uBAAuB,8BAA8B,CAAC;AACnE,4EAA4E;AAC5E,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,oDAAoD;AACpD,eAAO,MAAM,0BAA0B,aAAa,CAAC;AAErD,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