@geonosis/document 0.9.3 → 0.10.0

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 (79) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +78 -13
  3. package/dist/core/actor.d.cts +0 -1
  4. package/dist/core/actor.d.ts +0 -1
  5. package/dist/core/body-version.d.cts +0 -9
  6. package/dist/core/body-version.d.ts +0 -9
  7. package/dist/core/canonical.cjs +2 -3
  8. package/dist/core/canonical.d.cts +0 -4
  9. package/dist/core/canonical.d.ts +0 -4
  10. package/dist/core/canonical.js +2 -3
  11. package/dist/core/document.cjs +28 -25
  12. package/dist/core/document.d.cts +3 -22
  13. package/dist/core/document.d.ts +3 -22
  14. package/dist/core/document.js +28 -25
  15. package/dist/core/entities.d.cts +0 -19
  16. package/dist/core/entities.d.ts +0 -19
  17. package/dist/core/naming.d.cts +0 -5
  18. package/dist/core/naming.d.ts +0 -5
  19. package/dist/core/numbering.d.cts +0 -4
  20. package/dist/core/numbering.d.ts +0 -4
  21. package/dist/core/ports.d.cts +0 -6
  22. package/dist/core/ports.d.ts +0 -6
  23. package/dist/core/schema.cjs +44 -76
  24. package/dist/core/schema.d.cts +1 -13
  25. package/dist/core/schema.d.ts +1 -13
  26. package/dist/core/schema.js +44 -76
  27. package/dist/core/status.d.cts +0 -1
  28. package/dist/core/status.d.ts +0 -1
  29. package/dist/index.cjs +1 -0
  30. package/dist/index.d.cts +1 -1
  31. package/dist/index.d.ts +1 -1
  32. package/dist/index.js +2 -0
  33. package/dist/store/ddl.cjs +35 -38
  34. package/dist/store/ddl.d.cts +6 -6
  35. package/dist/store/ddl.d.ts +6 -6
  36. package/dist/store/ddl.js +37 -39
  37. package/dist/store/hash.d.cts +0 -1
  38. package/dist/store/hash.d.ts +0 -1
  39. package/dist/store/number-for.cjs +52 -0
  40. package/dist/store/number-for.d.cts +11 -0
  41. package/dist/store/number-for.d.ts +11 -0
  42. package/dist/store/number-for.js +12 -0
  43. package/dist/store/store.cjs +188 -162
  44. package/dist/store/store.d.cts +57 -16
  45. package/dist/store/store.d.ts +57 -16
  46. package/dist/store/store.js +190 -163
  47. package/dist/store.cjs +2 -0
  48. package/dist/store.d.cts +3 -2
  49. package/dist/store.d.ts +3 -2
  50. package/dist/store.js +2 -0
  51. package/dist/surface/table.cjs +129 -66
  52. package/dist/surface/table.d.cts +20 -28
  53. package/dist/surface/table.d.ts +20 -28
  54. package/dist/surface/table.js +132 -66
  55. package/dist/workflows/bindings.cjs +48 -0
  56. package/dist/workflows/bindings.d.cts +15 -0
  57. package/dist/workflows/bindings.d.ts +15 -0
  58. package/dist/workflows/bindings.js +10 -0
  59. package/dist/workflows/document-workflows.cjs +29 -40
  60. package/dist/workflows/document-workflows.d.cts +0 -12
  61. package/dist/workflows/document-workflows.d.ts +0 -12
  62. package/dist/workflows/document-workflows.js +29 -40
  63. package/dist/workflows/effects.d.cts +0 -12
  64. package/dist/workflows/effects.d.ts +0 -12
  65. package/dist/workflows/ports.d.cts +0 -17
  66. package/dist/workflows/ports.d.ts +0 -17
  67. package/dist/workflows/refusals.cjs +30 -0
  68. package/dist/workflows/refusals.d.cts +37 -9
  69. package/dist/workflows/refusals.d.ts +37 -9
  70. package/dist/workflows/refusals.js +30 -0
  71. package/dist/workflows/shared.cjs +93 -0
  72. package/dist/workflows/shared.d.cts +28 -0
  73. package/dist/workflows/shared.d.ts +28 -0
  74. package/dist/workflows/shared.js +60 -0
  75. package/dist/workflows.cjs +16 -1
  76. package/dist/workflows.d.cts +3 -1
  77. package/dist/workflows.d.ts +3 -1
  78. package/dist/workflows.js +31 -1
  79. package/package.json +4 -4
@@ -14,23 +14,43 @@ import {
14
14
  DEFAULT_REVISIONS_TABLE,
15
15
  documentTable,
16
16
  HEAD_FIELDS,
17
- physicalColumnsOf
17
+ physicalColumnsOf,
18
+ splitColumns
18
19
  } from "./ddl.js";
19
20
  import { hashOf } from "./hash.js";
20
- var DEFAULT_VERSION_COLUMN = "version";
21
21
  var UNDO_ACTOR = systemActor("document.undo");
22
- var nameOf = (value, fallback) => value === undefined ? fallback : typeof value === "string" ? value : value.name;
23
22
  var readBody = (entity, entityName, ref, stored) => {
24
23
  const migrated = migrateBody(entity, stored);
25
24
  const result = entity.body["~standard"].validate(migrated);
26
25
  if (result instanceof Promise) {
27
- throw new Error(`${entityName} ${ref}: this entity's body schema validates asynchronously, and a stored body can only be read synchronously here`);
26
+ throw new DbRefusal(`${entityName} ${ref}: this entity's body schema validates asynchronously, and a stored body can only be read synchronously here`, { code: "body-refused" });
28
27
  }
29
28
  if (result.issues !== undefined) {
30
- throw new Error(`${entityName} ${ref}'s stored body no longer satisfies its own schema after migration: ${result.issues.map((issue) => issue.message).join("; ")}`);
29
+ throw new DbRefusal(`${entityName} ${ref}'s stored body no longer satisfies its own schema after migration: ${result.issues.map((issue) => issue.message).join("; ")}`, { code: "body-refused" });
31
30
  }
32
31
  return result.value;
33
32
  };
33
+ var refusesAsArchiveSegment = (segment) => segment === "" || segment === "." || segment === "..";
34
+ var archiveKeyPrefix = (tenant, entity, ref) => {
35
+ const refused = [tenant, entity].find((part) => part.split(/[/\\]/).some(refusesAsArchiveSegment)) ?? (refusesAsArchiveSegment(ref) ? ref : undefined);
36
+ if (refused !== undefined) {
37
+ throw new DbRefusal(`${JSON.stringify(refused)} cannot name an archive object: an empty, "." or ".." path segment lets a key reach another document's space`);
38
+ }
39
+ try {
40
+ return `${tenant}/${entity}/${encodeURIComponent(ref)}`;
41
+ } catch (cause) {
42
+ throw new DbRefusal(`the ref ${JSON.stringify(ref)} is not text an archive key can carry`, {
43
+ cause
44
+ });
45
+ }
46
+ };
47
+ var ALL_HEAD_COLUMNS = [
48
+ ...HEAD_FIELDS,
49
+ "createdAt",
50
+ "entity",
51
+ "number",
52
+ "updatedAt"
53
+ ];
34
54
  var headFrom = (found) => found === undefined ? undefined : {
35
55
  body: found.body,
36
56
  hash: found.hash,
@@ -42,17 +62,9 @@ var documentStore = (options) => {
42
62
  const table = options.table ?? DEFAULT_DOCUMENT_TABLE;
43
63
  const revisionKindColumn = options.columns?.revisionKind ?? DEFAULT_REVISION_KIND_COLUMN;
44
64
  const physical = physicalColumnsOf(options.columns);
45
- const {
46
- entity: _entity,
47
- heads: _heads,
48
- revisionKind: _revisionKind,
49
- total: _total,
50
- version,
51
- ...entityColumns
52
- } = options.columns ?? {};
53
- const versionColumn = nameOf(version, DEFAULT_VERSION_COLUMN);
65
+ const { rest: entityColumns, version: versionColumn } = splitColumns(options.columns);
54
66
  const entityColumn = physical.entity;
55
- const { archive, registry, schema, seam } = options;
67
+ const { archive, registry, schema, search, seam, views } = options;
56
68
  const tenantKey = seam.tenantKey;
57
69
  const placed = schema === undefined ? {} : { schema };
58
70
  const declared = documentTable({
@@ -64,6 +76,11 @@ var documentStore = (options) => {
64
76
  const tenanted = (tenantId) => ({ [tenantKey]: tenantId });
65
77
  const columnOf = (column) => column === "number" ? "number" : physical[column];
66
78
  const physicalHeads = HEAD_FIELDS.map(columnOf);
79
+ const headColumnsOf = (head) => Object.fromEntries(Object.entries(head).map(([key, held]) => [columnOf(key), held]));
80
+ const orderOf = (one) => ({
81
+ column: columnOf(one.column),
82
+ ...one.direction === undefined ? {} : { direction: one.direction }
83
+ });
67
84
  const narrowed = (where) => Object.fromEntries(Object.entries(where ?? {}).map(([column, held]) => [
68
85
  columnOf(column),
69
86
  held
@@ -109,32 +126,53 @@ var documentStore = (options) => {
109
126
  sortable: [...physicalHeads, entityColumn, "number", physical.createdAt, physical.updatedAt],
110
127
  table: declared
111
128
  });
129
+ const instanceFor = (name, stored, storedBody) => {
130
+ const definition = registry.named(name);
131
+ const body = readBody(definition, name, stored.number, storedBody);
132
+ return registry.instance(name, {
133
+ ...definition.headOf(body),
134
+ ...stored,
135
+ body
136
+ });
137
+ };
138
+ const itemFor = (name) => (row) => instanceFor(name, {
139
+ createdAt: row.createdAt,
140
+ number: row.key,
141
+ updatedAt: row.updatedAt,
142
+ version: row.version ?? 1
143
+ }, row.body);
144
+ const itemsByEntity = new Map(registry.names.map((name) => [String(name), itemFor(name)]));
145
+ const pager = defineEntity({
146
+ carried: [entityColumn],
147
+ columns: { ...entityColumns, version: versionColumn },
148
+ filterable: [...physicalHeads, entityColumn, physical.createdAt, physical.updatedAt],
149
+ item: (row) => {
150
+ const entityName = String(row.carried?.[entityColumn]);
151
+ const make = itemsByEntity.get(entityName);
152
+ if (make === undefined) {
153
+ throw new DbRefusal(`${JSON.stringify(entityName)} is stored as the entity of "${row.key}" and this store's registry holds no such entity: it holds ${registry.names.join(", ")}`);
154
+ }
155
+ return make(row);
156
+ },
157
+ key: { column: "number", param: "ref" },
158
+ order: [{ column: entityColumn }, { column: "number" }],
159
+ seam,
160
+ sortable: [...physicalHeads, entityColumn, "number", physical.createdAt, physical.updatedAt],
161
+ table: declared,
162
+ tiebreak: [entityColumn, "number"]
163
+ });
164
+ const listEverywhere = (handle, params) => pager.list(handle, {
165
+ ...params,
166
+ filter: {
167
+ ...narrowed(params.filter),
168
+ ...params.entities === undefined ? {} : { [entityColumn]: params.entities }
169
+ },
170
+ ...params.order === undefined ? {} : { order: orderOf(params.order) }
171
+ });
112
172
  const entityStoreFor = (name) => {
113
173
  const definition = registry.named(name);
114
- const item = (row) => {
115
- const body = readBody(definition, name, row.key, row.body);
116
- const head = definition.headOf(body);
117
- return registry.instance(name, {
118
- ...head,
119
- body,
120
- createdAt: row.createdAt,
121
- number: row.key,
122
- updatedAt: row.updatedAt,
123
- version: row.version ?? 1
124
- });
125
- };
126
- const instanceFromRevision = (ref, row) => {
127
- const body = readBody(definition, name, ref, row.body);
128
- const head = definition.headOf(body);
129
- return registry.instance(name, {
130
- ...head,
131
- body,
132
- createdAt: row.at,
133
- number: ref,
134
- updatedAt: row.at,
135
- version: row.sequence
136
- });
137
- };
174
+ const item = itemFor(name);
175
+ const instanceFromRevision = (ref, row) => instanceFor(name, { createdAt: row.at, number: ref, updatedAt: row.at, version: row.sequence }, row.body);
138
176
  const projection = projectionOf({
139
177
  carried: ["lineage"],
140
178
  columns: { ...entityColumns, hash: "hash", sequence: versionColumn },
@@ -151,12 +189,34 @@ var documentStore = (options) => {
151
189
  const list = (handle, params) => projection.list(handle, {
152
190
  ...params,
153
191
  ...params.filter === undefined ? {} : { filter: narrowed(params.filter) },
154
- ...params.order === undefined ? {} : {
155
- order: {
156
- column: columnOf(params.order.column),
157
- ...params.order.direction === undefined ? {} : { direction: params.order.direction }
158
- }
192
+ ...params.order === undefined ? {} : { order: orderOf(params.order) }
193
+ });
194
+ const count = (handle, params) => readers.count(handle, {
195
+ ...tenanted(params[tenantKey]),
196
+ filter: { ...narrowed(params.where), [entityColumn]: name }
197
+ });
198
+ const keys = async (handle, params) => {
199
+ const order = params.order ?? [];
200
+ const rows = await readers.project(handle, {
201
+ ...tenanted(params[tenantKey]),
202
+ columns: [],
203
+ order: [
204
+ ...order.map(orderOf),
205
+ ...order.some((one) => one.column === "number") ? [] : [{ column: "number" }]
206
+ ],
207
+ where: { ...narrowed(params.where), [entityColumn]: name }
208
+ });
209
+ return rows.map((row) => row.key);
210
+ };
211
+ const render = seam.scoped(async (tx, params) => {
212
+ const view = views?.[name];
213
+ if (view === undefined && definition.view !== definition.body) {
214
+ throw new DbRefusal(`"${name}" declares a view of its own and this store was given no \`views.${name}\` to render it with: \`render\` would answer the body where the view is the contract`);
159
215
  }
216
+ const found = await projection.get(tx, params);
217
+ if (found === null)
218
+ return null;
219
+ return view === undefined ? found.body : view(tx, found);
160
220
  });
161
221
  const locked = async (tx, params) => headFrom(await projection.lockLatest(tx, params));
162
222
  const currentLineageOf = async (tx, params) => headFrom(await projection.head(tx, params))?.lineage ?? 1;
@@ -166,13 +226,21 @@ var documentStore = (options) => {
166
226
  lineage,
167
227
  ref: params.ref
168
228
  });
169
- const headColumnsOf = (body) => Object.fromEntries(Object.entries(definition.headOf(body)).map(([key, held]) => [
170
- columnOf(key),
171
- held
172
- ]));
173
- const storedHead = (ref, body) => headColumnsOf(readBody(definition, name, ref, body));
174
- const append = async (tx, write) => {
229
+ const storedHead = (ref, body) => headColumnsOf(definition.headOf(readBody(definition, name, ref, body)));
230
+ const project = async (tx, write) => projection.write(tx, {
231
+ ...tenanted(write.tenantId),
232
+ at: write.at,
233
+ body: write.body,
234
+ carried: { lineage: write.lineage },
235
+ derived: write.head,
236
+ hash: write.hash,
237
+ ref: write.ref,
238
+ retiredAt: write.retiredAt,
239
+ sequence: write.version
240
+ });
241
+ const record = async (tx, write) => {
175
242
  const log = needsLog();
243
+ const head = definition.headOf(write.seen);
176
244
  const params = {
177
245
  ...tenanted(write.tenantId),
178
246
  actor: write.actor,
@@ -183,20 +251,34 @@ var documentStore = (options) => {
183
251
  ref: write.ref,
184
252
  ...write.reason === null ? {} : { reason: write.reason }
185
253
  };
186
- const out = write.compensationOf === null ? await log.append(tx, params) : await log.appendCompensation(tx, { ...params, compensationOf: write.compensationOf });
187
- return { at: out.at, hash: out.hash, prevHash: out.prevHash, version: out.sequence };
254
+ const out = write.compensationOf === undefined ? await log.append(tx, params) : await log.appendCompensation(tx, { ...params, compensationOf: write.compensationOf });
255
+ await project(tx, {
256
+ at: out.at,
257
+ body: write.body,
258
+ hash: out.hash,
259
+ head: headColumnsOf(head),
260
+ lineage: write.lineage,
261
+ ref: write.ref,
262
+ retiredAt: write.retired ? out.at : null,
263
+ tenantId: write.tenantId,
264
+ version: out.sequence
265
+ });
266
+ if (search !== undefined) {
267
+ await (write.kind === "retired" ? search.remove(tx, { entity: name, ref: write.ref }) : search.index(tx, {
268
+ entity: name,
269
+ head,
270
+ ref: write.ref,
271
+ text: definition.searchText(write.seen)
272
+ }));
273
+ }
274
+ return {
275
+ at: out.at,
276
+ hash: out.hash,
277
+ head,
278
+ prevHash: out.prevHash,
279
+ version: out.sequence
280
+ };
188
281
  };
189
- const project = async (tx, write) => projection.write(tx, {
190
- ...tenanted(write.tenantId),
191
- at: write.at,
192
- body: write.body,
193
- carried: { lineage: write.lineage },
194
- derived: write.head,
195
- hash: write.hash,
196
- ref: write.ref,
197
- retiredAt: write.retiredAt,
198
- sequence: write.version
199
- });
200
282
  const commitTx = seam.scoped(async (tx, params) => {
201
283
  const tenantId = params[tenantKey];
202
284
  const prepared = definition.prepare(params.body);
@@ -209,6 +291,7 @@ var documentStore = (options) => {
209
291
  if (existing !== undefined && !changed) {
210
292
  return {
211
293
  committed: false,
294
+ head: definition.headOf(prepared),
212
295
  lineage: existing.lineage,
213
296
  ref: params.ref,
214
297
  version: existing.version
@@ -216,27 +299,17 @@ var documentStore = (options) => {
216
299
  }
217
300
  const lineage = existing?.lineage ?? 1;
218
301
  const reason = params.reason ?? null;
219
- const appended = await append(tx, {
302
+ const appended = await record(tx, {
220
303
  actor: params.actor,
221
304
  body: stamped,
222
- compensationOf: null,
223
305
  kind: "committed",
224
306
  lineage,
225
307
  reason,
226
308
  ref: params.ref,
309
+ retired: false,
310
+ seen: prepared,
227
311
  tenantId
228
312
  });
229
- await project(tx, {
230
- at: appended.at,
231
- body: stamped,
232
- hash: appended.hash,
233
- head: headColumnsOf(prepared),
234
- lineage,
235
- ref: params.ref,
236
- retiredAt: null,
237
- tenantId,
238
- version: appended.version
239
- });
240
313
  return {
241
314
  archivable: {
242
315
  actor: params.actor,
@@ -247,6 +320,7 @@ var documentStore = (options) => {
247
320
  },
248
321
  committed: true,
249
322
  hash: appended.hash,
323
+ head: appended.head,
250
324
  lineage,
251
325
  previous: existing === undefined ? null : { hash: existing.hash, version: existing.version },
252
326
  ref: params.ref,
@@ -254,10 +328,11 @@ var documentStore = (options) => {
254
328
  };
255
329
  });
256
330
  const commit = async (handle, params) => {
331
+ const keyPrefix = archive === undefined ? undefined : archiveKeyPrefix(params[tenantKey], name, params.ref);
257
332
  const { archivable, ...answer } = await commitTx(handle, params);
258
333
  if (archive === undefined || !answer.committed || archivable === undefined)
259
334
  return answer;
260
- const key = `${params[tenantKey]}/${name}/${answer.lineage}/${answer.version}.json`;
335
+ const key = `${keyPrefix}/${answer.lineage}/${answer.version}.json`;
261
336
  const payload = {
262
337
  actor: archivable.actor,
263
338
  at: archivable.at,
@@ -282,43 +357,36 @@ var documentStore = (options) => {
282
357
  return { ...answer, archived: false };
283
358
  }
284
359
  };
285
- const retire = seam.scoped(async (tx, params) => {
286
- const tenantId = params[tenantKey];
287
- const existing = await locked(tx, params);
288
- if (existing === undefined) {
289
- throw new DbRefusal(`"${params.ref}" (${name}) has no document to retire`);
290
- }
291
- if (existing.retiredAt !== null) {
292
- throw new DbRefusal(`"${params.ref}" (${name}) is already retired`);
293
- }
294
- const appended = await append(tx, {
360
+ const flip = (kind, claim) => seam.scoped(async (tx, params) => {
361
+ const existing = claim(await locked(tx, params), params.ref);
362
+ const appended = await record(tx, {
295
363
  actor: params.actor,
296
364
  body: existing.body,
297
- compensationOf: null,
298
- kind: "retired",
365
+ kind,
299
366
  lineage: existing.lineage,
300
367
  reason: params.reason ?? null,
301
368
  ref: params.ref,
302
- tenantId
303
- });
304
- await project(tx, {
305
- at: appended.at,
306
- body: existing.body,
307
- hash: appended.hash,
308
- head: storedHead(params.ref, existing.body),
309
- lineage: existing.lineage,
310
- ref: params.ref,
311
- retiredAt: appended.at,
312
- tenantId,
313
- version: appended.version
369
+ retired: kind === "retired",
370
+ seen: readBody(definition, name, params.ref, existing.body),
371
+ tenantId: params[tenantKey]
314
372
  });
315
373
  return {
316
374
  hash: appended.hash,
375
+ head: appended.head,
317
376
  lineage: existing.lineage,
318
377
  ref: params.ref,
319
378
  version: appended.version
320
379
  };
321
380
  });
381
+ const retire = flip("retired", (existing, ref) => {
382
+ if (existing === undefined) {
383
+ throw new DbRefusal(`"${ref}" (${name}) has no document to retire`);
384
+ }
385
+ if (existing.retiredAt !== null) {
386
+ throw new DbRefusal(`"${ref}" (${name}) is already retired`);
387
+ }
388
+ return existing;
389
+ });
322
390
  const succeed = seam.scoped(async (tx, params) => {
323
391
  const tenantId = params[tenantKey];
324
392
  const existing = await locked(tx, params);
@@ -328,69 +396,32 @@ var documentStore = (options) => {
328
396
  const prepared = definition.prepare(params.body);
329
397
  const stamped = stampBody(definition, prepared);
330
398
  const lineage = existing.lineage + 1;
331
- const appended = await append(tx, {
399
+ const appended = await record(tx, {
332
400
  actor: params.actor,
333
401
  body: stamped,
334
- compensationOf: null,
335
402
  kind: "committed",
336
403
  lineage,
337
404
  reason: params.reason ?? null,
338
405
  ref: params.ref,
406
+ retired: false,
407
+ seen: prepared,
339
408
  tenantId
340
409
  });
341
- await project(tx, {
342
- at: appended.at,
343
- body: stamped,
344
- hash: appended.hash,
345
- head: headColumnsOf(prepared),
346
- lineage,
347
- ref: params.ref,
348
- retiredAt: null,
349
- tenantId,
350
- version: appended.version
351
- });
352
410
  return {
353
411
  committed: true,
354
412
  hash: appended.hash,
413
+ head: appended.head,
355
414
  lineage,
356
415
  previous: null,
357
416
  ref: params.ref,
358
417
  version: appended.version
359
418
  };
360
419
  });
361
- const reinstate = seam.scoped(async (tx, params) => {
362
- const tenantId = params[tenantKey];
363
- const existing = await locked(tx, params);
420
+ const reinstate = flip("reinstated", (existing, ref) => {
364
421
  if (existing === undefined || existing.retiredAt === null) {
365
- throw new DbRefusal(`"${params.ref}" (${name}) is not retired: nothing to reinstate`);
422
+ throw new DbRefusal(`"${ref}" (${name}) is not retired: nothing to reinstate`);
366
423
  }
367
- const appended = await append(tx, {
368
- actor: params.actor,
369
- body: existing.body,
370
- compensationOf: null,
371
- kind: "reinstated",
372
- lineage: existing.lineage,
373
- reason: params.reason ?? null,
374
- ref: params.ref,
375
- tenantId
376
- });
377
- await project(tx, {
378
- at: appended.at,
379
- body: existing.body,
380
- hash: appended.hash,
381
- head: storedHead(params.ref, existing.body),
382
- lineage: existing.lineage,
383
- ref: params.ref,
384
- retiredAt: null,
385
- tenantId,
386
- version: appended.version
387
- });
388
- return {
389
- hash: appended.hash,
390
- lineage: existing.lineage,
391
- ref: params.ref,
392
- version: appended.version
393
- };
424
+ return existing;
394
425
  });
395
426
  const at = seam.scoped(async (tx, params) => {
396
427
  const lineage = await currentLineageOf(tx, params);
@@ -423,7 +454,7 @@ var documentStore = (options) => {
423
454
  return needsLog().verify(tx, stream(params, lineage));
424
455
  });
425
456
  const compensate = async (scoped, tenantId, output, kind, body, retired) => {
426
- const appended = await append(scoped, {
457
+ await record(scoped, {
427
458
  actor: UNDO_ACTOR,
428
459
  body,
429
460
  compensationOf: output.version,
@@ -431,19 +462,10 @@ var documentStore = (options) => {
431
462
  lineage: output.lineage,
432
463
  reason: `undo of v${output.version}`,
433
464
  ref: output.ref,
465
+ retired,
466
+ seen: readBody(definition, name, output.ref, body),
434
467
  tenantId
435
468
  });
436
- await project(scoped, {
437
- at: appended.at,
438
- body,
439
- hash: appended.hash,
440
- head: storedHead(output.ref, body),
441
- lineage: output.lineage,
442
- ref: output.ref,
443
- retiredAt: retired ? appended.at : null,
444
- tenantId,
445
- version: appended.version
446
- });
447
469
  };
448
470
  const lockedForUndo = async (scoped, tenantId, output) => {
449
471
  const existing = await locked(scoped, { ...tenanted(tenantId), ref: output.ref });
@@ -494,11 +516,14 @@ var documentStore = (options) => {
494
516
  asOf,
495
517
  at,
496
518
  commit,
519
+ count,
497
520
  get: projection.get,
498
521
  history,
522
+ keys,
499
523
  list,
500
524
  listAll: projection.listAll,
501
525
  reinstate,
526
+ render,
502
527
  retire,
503
528
  succeed,
504
529
  undos,
@@ -511,14 +536,12 @@ var documentStore = (options) => {
511
536
  const rawEntities = Object.fromEntries(built.map(([name, one]) => [name, one.door]));
512
537
  const restorers = Object.fromEntries(built.map(([name, one]) => [name, one.restore]));
513
538
  const heads = seam.scoped(async (tx, params) => {
514
- const { columns, entity, order, where } = params;
539
+ const { entity, order, where } = params;
540
+ const columns = params.columns === "all" ? ALL_HEAD_COLUMNS : params.columns;
515
541
  const rows = await readers.project(tx, {
516
542
  ...tenanted(params[tenantKey]),
517
543
  columns: columns.filter((column) => column !== "number").map(columnOf),
518
- order: order.map((one) => ({
519
- column: columnOf(one.column),
520
- ...one.direction === undefined ? {} : { direction: one.direction }
521
- })),
544
+ order: order.map(orderOf),
522
545
  where: {
523
546
  ...entity === undefined ? {} : { [entityColumn]: entity },
524
547
  ...narrowed(where)
@@ -571,7 +594,11 @@ var documentStore = (options) => {
571
594
  }
572
595
  return { rows };
573
596
  });
574
- return { ...rawEntities, aggregate, heads, rebuild };
597
+ const tables = {
598
+ documents: readers,
599
+ ...revisions === undefined ? {} : { revisions }
600
+ };
601
+ return { ...rawEntities, aggregate, heads, list: listEverywhere, rebuild, tables };
575
602
  };
576
603
  export {
577
604
  documentStore
package/dist/store.cjs CHANGED
@@ -50,10 +50,12 @@ __export(exports_store, {
50
50
  documentStore: () => import_store.documentStore,
51
51
  documentSurface: () => import_table.documentSurface,
52
52
  hashOf: () => import_hash.hashOf,
53
+ numberFor: () => import_number_for.numberFor,
53
54
  physicalColumnsOf: () => import_ddl.physicalColumnsOf
54
55
  });
55
56
  module.exports = __toCommonJS(exports_store);
56
57
  var import_hash = require("./store/hash.cjs");
57
58
  var import_table = require("./surface/table.cjs");
58
59
  var import_ddl = require("./store/ddl.cjs");
60
+ var import_number_for = require("./store/number-for.cjs");
59
61
  var import_store = require("./store/store.cjs");
package/dist/store.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { hashOf } from './store/hash.cjs';
2
- export { documentSurface, type DocumentSurfaceOptions, type PendingCall, type SurfaceCall, type SurfaceRow, type SurfaceScope, type SurfaceSchemaAdapter, type SurfaceVerb } from './surface/table.cjs';
2
+ export { documentSurface, type DocumentSurfaceOptions, type SurfaceResolve, type SurfaceCall, type SurfaceRow, type SurfaceScope, type SurfaceSchemaAdapter, type SurfaceVerb } from './surface/table.cjs';
3
3
  export { appendOnlyTables, DEFAULT_DOCUMENT_TABLE, DEFAULT_REVISION_KIND_COLUMN, DEFAULT_REVISIONS_TABLE, DOCUMENT_MIGRATION_PLACEHOLDERS, documentMigrations, documentRoleStatements, HEAD_FIELDS, type AppendOnlyTablesOptions, type DocumentColumns, type DocumentMigrationsOptions, type DocumentPhysicalColumns, type DocumentRevisionsOptions, type HeadField, physicalColumnsOf } from './store/ddl.cjs';
4
- export { documentStore, type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateRow, type AggregateWhere, type CommitOutput, type DocumentKind, type DocumentSortColumn, type DocumentStore, type DocumentStoreOptions, type HeadColumn, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type ReinstateOutput, type RetireOutput, type VerifyResult } from './store/store.cjs';
4
+ export { numberFor } from './store/number-for.cjs';
5
+ export { documentStore, type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateRow, type AggregateWhere, type CommitOutput, type DocumentKind, type DocumentList, type DocumentListing, type DocumentSearchPort, type DocumentSortColumn, type DocumentStore, type DocumentStoreOptions, type DocumentTables, type DocumentViews, type HeadColumn, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type ReinstateOutput, type RetireOutput, type VerifyResult } from './store/store.cjs';
package/dist/store.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { hashOf } from './store/hash.js';
2
- export { documentSurface, type DocumentSurfaceOptions, type PendingCall, type SurfaceCall, type SurfaceRow, type SurfaceScope, type SurfaceSchemaAdapter, type SurfaceVerb } from './surface/table.js';
2
+ export { documentSurface, type DocumentSurfaceOptions, type SurfaceResolve, type SurfaceCall, type SurfaceRow, type SurfaceScope, type SurfaceSchemaAdapter, type SurfaceVerb } from './surface/table.js';
3
3
  export { appendOnlyTables, DEFAULT_DOCUMENT_TABLE, DEFAULT_REVISION_KIND_COLUMN, DEFAULT_REVISIONS_TABLE, DOCUMENT_MIGRATION_PLACEHOLDERS, documentMigrations, documentRoleStatements, HEAD_FIELDS, type AppendOnlyTablesOptions, type DocumentColumns, type DocumentMigrationsOptions, type DocumentPhysicalColumns, type DocumentRevisionsOptions, type HeadField, physicalColumnsOf } from './store/ddl.js';
4
- export { documentStore, type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateRow, type AggregateWhere, type CommitOutput, type DocumentKind, type DocumentSortColumn, type DocumentStore, type DocumentStoreOptions, type HeadColumn, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type ReinstateOutput, type RetireOutput, type VerifyResult } from './store/store.js';
4
+ export { numberFor } from './store/number-for.js';
5
+ export { documentStore, type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateRow, type AggregateWhere, type CommitOutput, type DocumentKind, type DocumentList, type DocumentListing, type DocumentSearchPort, type DocumentSortColumn, type DocumentStore, type DocumentStoreOptions, type DocumentTables, type DocumentViews, type HeadColumn, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type ReinstateOutput, type RetireOutput, type VerifyResult } from './store/store.js';
package/dist/store.js CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  HEAD_FIELDS,
15
15
  physicalColumnsOf
16
16
  } from "./store/ddl.js";
17
+ import { numberFor } from "./store/number-for.js";
17
18
  import {
18
19
  documentStore
19
20
  } from "./store/store.js";
@@ -29,5 +30,6 @@ export {
29
30
  documentStore,
30
31
  documentSurface,
31
32
  hashOf,
33
+ numberFor,
32
34
  physicalColumnsOf
33
35
  };