@dreaminhex/hexdb 2.4.1 → 2.4.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.
package/dist/index.d.ts CHANGED
@@ -43,6 +43,37 @@ export interface Query {
43
43
  /** Only these (dotted) fields. */
44
44
  fields?: string[];
45
45
  }
46
+ /** What `deleteWhere` did, or (dry run) would do. */
47
+ export interface DeleteSummary {
48
+ /** The delete batch, to restore it (none for a dry run). */
49
+ batch?: string;
50
+ dry_run: boolean;
51
+ matched: number;
52
+ /** Documents and files that go: the matches and what cascades from them. */
53
+ total: number;
54
+ deleted: Record<string, number>;
55
+ detached: Record<string, number>;
56
+ /** Dry runs: documents whose `on_delete: restrict` link would refuse the delete. */
57
+ blocked?: Record<string, {
58
+ count: number;
59
+ ids: string[];
60
+ }>;
61
+ sample?: string[];
62
+ }
63
+ /** One delete in the history. */
64
+ export interface DeleteBatch {
65
+ batch: string;
66
+ time: number;
67
+ at: string;
68
+ by: string;
69
+ kind: string;
70
+ tessellation: string;
71
+ counts: Record<string, number>;
72
+ trashed: boolean;
73
+ restored_at?: string;
74
+ purged_at?: string;
75
+ [field: string]: unknown;
76
+ }
46
77
  export interface QueryPage {
47
78
  documents: Document[];
48
79
  total: number;
@@ -131,6 +162,36 @@ export declare class HexDB {
131
162
  results: unknown[];
132
163
  writes: number;
133
164
  }>;
165
+ /** The delete history, newest first (your own deletes, or everyone's with the audit permission). */
166
+ deletes(query?: {
167
+ by?: string;
168
+ tessellation?: string;
169
+ kind?: string;
170
+ since?: number;
171
+ until?: number;
172
+ limit?: number;
173
+ offset?: number;
174
+ }): Promise<{
175
+ batches: DeleteBatch[];
176
+ total: number;
177
+ }>;
178
+ /** Put back everything a delete batch removed, in one step. */
179
+ restoreDeletes(batch: string, options?: {
180
+ skipExisting?: boolean;
181
+ }): Promise<{
182
+ batch: string;
183
+ restored: Record<string, number>;
184
+ skipped: {
185
+ tessellation: string;
186
+ id: string;
187
+ }[];
188
+ relinked: number;
189
+ }>;
190
+ /** Delete what a delete batch left in the trash, for good. */
191
+ purgeDeletes(batch: string): Promise<{
192
+ batch: string;
193
+ purged: number;
194
+ }>;
134
195
  /** Run a GraphQL query or mutation. Throws on GraphQL errors. */
135
196
  graphql<T = Record<string, unknown>>(query: string, variables?: Record<string, unknown>): Promise<T>;
136
197
  /**
@@ -186,11 +247,29 @@ export declare class Tessellation {
186
247
  replaced: number;
187
248
  ids: string[];
188
249
  }>;
189
- /** Merge `update` into every document matching `filter`. */
190
- updateWhere(filter: Record<string, unknown>, update: Record<string, unknown>): Promise<{
250
+ /**
251
+ * Merge `update` into every document matching `filter`. An empty filter
252
+ * (every document) is refused unless `options.all` is true.
253
+ */
254
+ updateWhere(filter: Record<string, unknown>, update: Record<string, unknown>, options?: {
255
+ all?: boolean;
256
+ }): Promise<{
191
257
  matched: number;
192
258
  modified: number;
193
259
  }>;
260
+ /**
261
+ * Delete every document matching `filter`, and what belongs to them through
262
+ * parent links, as one atomic delete batch that `db.restoreDeletes(batch)`
263
+ * puts back. An empty filter is refused unless `options.all` is true.
264
+ * `dryRun` only reports what would go; `expect` refuses (409 count_changed)
265
+ * unless exactly that many documents and files would go.
266
+ */
267
+ deleteWhere(filter: Record<string, unknown>, options?: {
268
+ all?: boolean;
269
+ dryRun?: boolean;
270
+ expect?: number;
271
+ idempotencyKey?: string;
272
+ }): Promise<DeleteSummary>;
194
273
  /**
195
274
  * The values behind vault tokens of tokenized fields (up to 1,000; needs the
196
275
  * `detokenize` permission; audited). One-way and unknown tokens map to null.
package/dist/index.js CHANGED
@@ -189,6 +189,22 @@ export class HexDB {
189
189
  transaction(operations, options = {}) {
190
190
  return this.request("POST", "/transactions", { operations }, idempotency(options.idempotencyKey));
191
191
  }
192
+ /** The delete history, newest first (your own deletes, or everyone's with the audit permission). */
193
+ deletes(query = {}) {
194
+ const params = new URLSearchParams();
195
+ for (const [key, value] of Object.entries(query))
196
+ if (value !== undefined)
197
+ params.set(key, String(value));
198
+ return this.request("GET", `/deletes?${params}`);
199
+ }
200
+ /** Put back everything a delete batch removed, in one step. */
201
+ restoreDeletes(batch, options = {}) {
202
+ return this.request("POST", `/deletes/${encodeURIComponent(batch)}/restore?skip_existing=${options.skipExisting ?? false}`);
203
+ }
204
+ /** Delete what a delete batch left in the trash, for good. */
205
+ purgeDeletes(batch) {
206
+ return this.request("DELETE", `/deletes/${encodeURIComponent(batch)}`);
207
+ }
192
208
  /** Run a GraphQL query or mutation. Throws on GraphQL errors. */
193
209
  async graphql(query, variables) {
194
210
  const result = await this.request("POST", "/graphql", { query, variables });
@@ -317,9 +333,23 @@ export class Tessellation {
317
333
  upsert(key, docs, options = {}) {
318
334
  return this.db.request("POST", `${this.path}/_upsert`, { key, documents: docs }, idempotency(options.idempotencyKey));
319
335
  }
320
- /** Merge `update` into every document matching `filter`. */
321
- updateWhere(filter, update) {
322
- return this.db.request("POST", `${this.path}/_update`, { filter, update });
336
+ /**
337
+ * Merge `update` into every document matching `filter`. An empty filter
338
+ * (every document) is refused unless `options.all` is true.
339
+ */
340
+ updateWhere(filter, update, options = {}) {
341
+ return this.db.request("POST", `${this.path}/_update`, { filter, update, all: options.all ?? false });
342
+ }
343
+ /**
344
+ * Delete every document matching `filter`, and what belongs to them through
345
+ * parent links, as one atomic delete batch that `db.restoreDeletes(batch)`
346
+ * puts back. An empty filter is refused unless `options.all` is true.
347
+ * `dryRun` only reports what would go; `expect` refuses (409 count_changed)
348
+ * unless exactly that many documents and files would go.
349
+ */
350
+ deleteWhere(filter, options = {}) {
351
+ const body = { filter, all: options.all ?? false, dry_run: options.dryRun ?? false, expect: options.expect };
352
+ return this.db.request("POST", `${this.path}/_delete`, body, idempotency(options.idempotencyKey));
323
353
  }
324
354
  /**
325
355
  * The values behind vault tokens of tokenized fields (up to 1,000; needs the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreaminhex/hexdb",
3
- "version": "2.4.1",
3
+ "version": "2.4.2",
4
4
  "description": "Client for HexDB, the hexagonal document database.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Dream In Hex",