@geonosis/document 0.4.1 → 0.6.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.
package/dist/index.js CHANGED
@@ -1,164 +1,18 @@
1
- // src/core/body-version.ts
2
- var BODY_VERSION_KEY = "_v";
3
- var versionOf = (body) => {
4
- const stamped = body[BODY_VERSION_KEY];
5
- return typeof stamped === "number" && Number.isInteger(stamped) ? stamped : 1;
6
- };
7
- var migrateBody = (definition, stored) => {
8
- if (stored === null || typeof stored !== "object" || Array.isArray(stored)) return stored;
9
- const target = definition.bodyVersion ?? 1;
10
- const steps = definition.migrations ?? {};
11
- let body = stored;
12
- for (let version = versionOf(body); version < target; version += 1) {
13
- const step = steps[version];
14
- if (step === void 0) break;
15
- body = step(body);
16
- }
17
- const { [BODY_VERSION_KEY]: _stamp, ...withoutStamp } = body;
18
- return withoutStamp;
19
- };
20
- var stampBody = (definition, body) => ({
21
- ...body,
22
- [BODY_VERSION_KEY]: definition.bodyVersion ?? 1
23
- });
24
- var documentBodyVersioning = (definition) => ({
25
- migrate: (stored) => migrateBody(definition, stored),
26
- stamp: (body) => stampBody(definition, body)
27
- });
28
-
29
- // src/core/document.ts
30
- var fieldPatterns = {
31
- calendarDate: /^\d{4}-\d{2}-\d{2}$/,
32
- decimal: /^-?\d+(?:\.\d+)?$/
33
- };
34
- var FIELD_CHECKS = {
35
- calendarDate: {
36
- message: "a calendar date is `YYYY-MM-DD`, never prose",
37
- test: (value) => typeof value === "string" && fieldPatterns.calendarDate.test(value)
38
- },
39
- decimal: {
40
- message: "an amount is a decimal string, never a float",
41
- test: (value) => typeof value === "string" && fieldPatterns.decimal.test(value)
42
- },
43
- int: {
44
- message: "an integer",
45
- test: (value) => typeof value === "number" && Number.isInteger(value)
46
- },
47
- positiveInt: {
48
- message: "a positive integer",
49
- test: (value) => typeof value === "number" && Number.isInteger(value) && value > 0
50
- },
51
- text: { message: "a string", test: (value) => typeof value === "string" }
52
- };
53
- var validatorOf = (fields, options) => {
54
- const nullable2 = options?.nullable ?? false;
55
- return {
56
- "~standard": {
57
- validate: (input) => {
58
- if (input === null || typeof input !== "object") {
59
- return { issues: [{ message: "expected an object" }] };
60
- }
61
- const record = input;
62
- const issues = [];
63
- const value = {};
64
- for (const [key, kind] of Object.entries(fields)) {
65
- const held = record[key];
66
- value[key] = held;
67
- if (nullable2 && held === null) continue;
68
- if (!FIELD_CHECKS[kind].test(held)) {
69
- issues.push({ message: FIELD_CHECKS[kind].message, path: [{ key }] });
70
- }
71
- }
72
- return issues.length > 0 ? { issues } : { value };
73
- },
74
- vendor: "geonosis-document",
75
- version: 1
76
- }
77
- };
78
- };
79
- var parseWith = (schema, input) => {
80
- const result = schema["~standard"].validate(input);
81
- if (result instanceof Promise) {
82
- throw new Error(
83
- "Document.head and Document.record parse synchronously; an async Standard Schema cannot back them"
84
- );
85
- }
86
- if (result.issues !== void 0) {
87
- throw new Error(result.issues.map((issue) => issue.message).join("; "));
88
- }
89
- return result.value;
90
- };
91
- var headFields = {
92
- status: "text",
93
- issueDate: "calendarDate",
94
- dueDate: "calendarDate",
95
- counterparty: "text",
96
- externalRef: "text",
97
- revision: "text",
98
- total: "decimal"
99
- };
100
- var recordFields = {
101
- version: "positiveInt",
102
- createdAt: "int",
103
- updatedAt: "int"
104
- };
105
- var headValidator = validatorOf(headFields, { nullable: true });
106
- var recordValidator = validatorOf(recordFields);
107
- var Document = {
108
- head: headValidator,
109
- headFields,
110
- record: recordValidator,
111
- recordFields,
112
- extend: (definition) => ({
113
- ...definition,
114
- headOf: (body) => parseWith(headValidator, definition.headOf(body)),
115
- is: (document) => document.entity === definition.name,
116
- view: definition.view ?? definition.body
117
- })
118
- };
119
-
120
- // src/core/entities.ts
121
- var documentEntities = (map) => {
122
- for (const [key, entity] of Object.entries(map)) {
123
- if (entity.name !== key) {
124
- throw new Error(
125
- `documentEntities was handed "${key}" for an entity whose own name is "${entity.name}": the map's key is what a row's \`entity\` column carries, and a mismatch here is a row nothing can find again`
126
- );
127
- }
128
- }
129
- const names = Object.keys(map);
130
- const values = Object.values(map);
131
- const fold = (pick) => values.map(pick);
132
- const distinctBy = (pick) => [
133
- ...new Set(fold(pick))
134
- ];
135
- return {
136
- bodies: distinctBy((entity) => entity.body),
137
- cards: distinctBy((entity) => entity.card.schema),
138
- entities: map,
139
- fold,
140
- instance: (name, parts) => ({ ...parts, entity: name, body: parts.body }),
141
- named: (name) => map[name],
142
- names,
143
- views: distinctBy((entity) => entity.view)
144
- };
145
- };
146
-
147
- // src/core/actor.ts
148
- var SYSTEM_PREFIX = "system:";
149
- var systemActor = (name) => `${SYSTEM_PREFIX}${name}`;
150
- var isSystemActor = (actor) => actor.startsWith(SYSTEM_PREFIX);
151
-
152
- // src/core/hash.ts
153
- import { createHash } from "crypto";
154
- var canonicalOf = (input) => {
155
- if (input === null || typeof input !== "object") return input;
156
- if (Array.isArray(input)) return input.map(canonicalOf);
157
- return Object.fromEntries(
158
- Object.entries(input).toSorted(([a], [b]) => a.localeCompare(b)).map(([key, held]) => [key, canonicalOf(held)])
159
- );
160
- };
161
- var hashOf = (payload) => createHash("sha256").update(JSON.stringify(canonicalOf(payload))).digest("hex");
1
+ import {
2
+ BODY_VERSION_KEY,
3
+ Document,
4
+ canTransition,
5
+ canonicalOf,
6
+ documentBodyVersioning,
7
+ documentEntities,
8
+ fieldPatterns,
9
+ isSystemActor,
10
+ isTerminalStatus,
11
+ migrateBody,
12
+ stampBody,
13
+ systemActor,
14
+ validatorOf
15
+ } from "./chunk-WWP7MNI7.js";
162
16
 
163
17
  // src/core/naming.ts
164
18
  var camelOf = (name) => name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
@@ -173,1164 +27,18 @@ var documentIdentifiers = (name) => {
173
27
  path: `/${name}s`
174
28
  };
175
29
  };
176
-
177
- // src/core/status.ts
178
- var canTransition = (machine, from, to) => machine.transitions[from].includes(to);
179
- var isTerminalStatus = (machine, status) => machine.transitions[status].length === 0;
180
-
181
- // src/surface/table.ts
182
- var VENDOR = "geonosis-document-surface";
183
- var isString = (value) => typeof value === "string";
184
- var isNumber = (value) => typeof value === "number";
185
- var scalar = (test, message) => ({
186
- "~standard": {
187
- validate: (input) => test(input) ? { value: input } : { issues: [{ message }] },
188
- vendor: VENDOR,
189
- version: 1
190
- }
191
- });
192
- var stringSchema = scalar(isString, "expected a string");
193
- var numberSchema = scalar(isNumber, "expected a number");
194
- var booleanSchema = scalar(
195
- (value) => typeof value === "boolean",
196
- "expected a boolean"
197
- );
198
- var literalOf = (literal) => scalar(
199
- (value) => value === literal,
200
- `expected exactly ${JSON.stringify(literal)}`
201
- );
202
- var unknownSchema = {
203
- "~standard": { validate: (input) => ({ value: input }), vendor: VENDOR, version: 1 }
204
- };
205
- var syncResult = (schema, input) => {
206
- const result = schema["~standard"].validate(input);
207
- if (result instanceof Promise) {
208
- throw new Error(
209
- "a document surface schema validates synchronously; an async Standard Schema cannot back a row"
210
- );
211
- }
212
- return result;
213
- };
214
- var optional = (inner) => ({
215
- "~standard": {
216
- validate: (input) => input === void 0 ? { value: void 0 } : syncResult(inner, input),
217
- vendor: VENDOR,
218
- version: 1
219
- }
220
- });
221
- var nullable = (inner) => ({
222
- "~standard": {
223
- validate: (input) => input === null ? { value: null } : syncResult(inner, input),
224
- vendor: VENDOR,
225
- version: 1
226
- }
227
- });
228
- var arrayOf = (item) => ({
229
- "~standard": {
230
- validate: (input) => {
231
- if (!Array.isArray(input)) return { issues: [{ message: "expected an array" }] };
232
- const value = [];
233
- const issues = [];
234
- input.forEach((one, at) => {
235
- const result = syncResult(item, one);
236
- if (result.issues !== void 0) {
237
- issues.push(
238
- ...result.issues.map((issue) => ({ ...issue, path: [at, ...issue.path ?? []] }))
239
- );
240
- } else {
241
- value.push(result.value);
242
- }
243
- });
244
- return issues.length > 0 ? { issues } : { value };
245
- },
246
- vendor: VENDOR,
247
- version: 1
248
- }
249
- });
250
- var merge = (schemas) => ({
251
- "~standard": {
252
- validate: (input) => {
253
- let value = {};
254
- const issues = [];
255
- for (const schema of schemas) {
256
- const result = syncResult(schema, input);
257
- if (result.issues !== void 0) issues.push(...result.issues);
258
- else value = { ...value, ...result.value };
259
- }
260
- return issues.length > 0 ? { issues } : { value };
261
- },
262
- vendor: VENDOR,
263
- version: 1
264
- }
265
- });
266
- var doorFor = (store, name) => {
267
- const door = store[name];
268
- if (door === void 0) {
269
- throw new Error(
270
- `"${name}" names no store this table's registry can find \u2014 the table and the store must share one registry`
271
- );
272
- }
273
- return door;
274
- };
275
- var HEAD_COLUMNS = Object.keys(Document.headFields);
276
- var SORT_COLUMNS = [...HEAD_COLUMNS, "number", "createdAt", "updatedAt"];
277
- var rowsFor = (definition, store, schema) => {
278
- const { name } = definition;
279
- const door = doorFor(store, name);
280
- const basePath = `/${definition.basePath}`;
281
- const instanceSchema = merge([
282
- Document.head,
283
- Document.record,
284
- schema.object({ body: definition.view, entity: schema.enum([name]), number: stringSchema })
285
- ]);
286
- const commitOutput = schema.union([
287
- schema.object({
288
- committed: literalOf(false),
289
- lineage: numberSchema,
290
- ref: stringSchema,
291
- version: numberSchema
292
- }),
293
- schema.object({
294
- archived: optional(booleanSchema),
295
- committed: literalOf(true),
296
- hash: stringSchema,
297
- lineage: numberSchema,
298
- previous: nullable(schema.object({ hash: stringSchema, version: numberSchema })),
299
- ref: stringSchema,
300
- version: numberSchema
301
- })
302
- ]);
303
- const retireLikeOutput = schema.object({
304
- hash: stringSchema,
305
- lineage: numberSchema,
306
- ref: stringSchema,
307
- version: numberSchema
308
- });
309
- const verifyOutput = schema.union([
310
- schema.object({ ok: literalOf(true), versions: numberSchema }),
311
- schema.object({
312
- brokenAt: numberSchema,
313
- expected: stringSchema,
314
- found: stringSchema,
315
- ok: literalOf(false)
316
- })
317
- ]);
318
- const historyOutput = arrayOf(
319
- schema.object({
320
- actor: stringSchema,
321
- at: numberSchema,
322
- body: unknownSchema,
323
- hash: stringSchema,
324
- kind: schema.enum(["committed", "retired", "reinstated"]),
325
- reason: nullable(stringSchema),
326
- version: numberSchema
327
- })
328
- );
329
- const listInput = schema.object({
330
- cursor: optional(nullable(stringSchema)),
331
- filter: optional(
332
- schema.object(
333
- Object.fromEntries(HEAD_COLUMNS.map((column) => [column, optional(stringSchema)]))
334
- )
335
- ),
336
- limit: optional(numberSchema),
337
- order: optional(
338
- schema.object({
339
- column: schema.enum(SORT_COLUMNS),
340
- direction: optional(schema.enum(["asc", "desc"]))
341
- })
342
- )
343
- });
344
- const listOutput = schema.object({
345
- items: arrayOf(merge([instanceSchema, schema.object({ card: definition.card.schema })])),
346
- nextCursor: nullable(stringSchema)
347
- });
348
- const ackOutput = schema.object({ ref: stringSchema });
349
- return [
350
- {
351
- call: (handle, params) => door.get(handle, params),
352
- input: schema.object({ ref: stringSchema }),
353
- name: `${name}.get`,
354
- output: nullable(instanceSchema),
355
- path: `${basePath}/:ref`,
356
- scope: "org",
357
- verb: "query"
358
- },
359
- {
360
- call: async (handle, params) => {
361
- const page = await door.list(handle, params);
362
- return {
363
- items: page.items.map((item) => ({
364
- ...item,
365
- card: definition.card.of(item, { counterpartyName: "" })
366
- })),
367
- nextCursor: page.nextCursor
368
- };
369
- },
370
- input: listInput,
371
- name: `${name}.list`,
372
- output: listOutput,
373
- path: basePath,
374
- scope: "org",
375
- verb: "query"
376
- },
377
- {
378
- call: (handle, params) => door.history(handle, params),
379
- input: schema.object({ lineage: optional(numberSchema), ref: stringSchema }),
380
- name: `${name}.history`,
381
- output: historyOutput,
382
- path: `${basePath}/:ref/history`,
383
- scope: "org",
384
- verb: "query"
385
- },
386
- {
387
- call: (handle, params) => door.verify(handle, params),
388
- input: schema.object({ lineage: optional(numberSchema), ref: stringSchema }),
389
- name: `${name}.verify`,
390
- output: verifyOutput,
391
- path: `${basePath}/:ref/verify`,
392
- scope: "org",
393
- verb: "query"
394
- },
395
- {
396
- call: (handle, params) => door.commit(handle, params),
397
- input: schema.object({
398
- actor: stringSchema,
399
- body: definition.body,
400
- reason: optional(stringSchema),
401
- ref: stringSchema
402
- }),
403
- name: `${name}.commit`,
404
- output: commitOutput,
405
- path: basePath,
406
- scope: "org",
407
- verb: "mutation"
408
- },
409
- {
410
- call: (handle, params) => door.retire(handle, params),
411
- input: schema.object({
412
- actor: stringSchema,
413
- reason: optional(stringSchema),
414
- ref: stringSchema
415
- }),
416
- name: `${name}.retire`,
417
- output: retireLikeOutput,
418
- path: `${basePath}/:ref/retire`,
419
- scope: "org",
420
- verb: "mutation"
421
- },
422
- {
423
- call: (handle, params) => door.reinstate(handle, params),
424
- input: schema.object({
425
- actor: stringSchema,
426
- reason: optional(stringSchema),
427
- ref: stringSchema
428
- }),
429
- name: `${name}.reinstate`,
430
- output: retireLikeOutput,
431
- path: `${basePath}/:ref/reinstate`,
432
- scope: "org",
433
- verb: "mutation"
434
- },
435
- {
436
- call: async (handle, params) => {
437
- const asked = params;
438
- const current = await door.get(handle, params);
439
- if (current === null) {
440
- throw new Error(`"${asked.ref}" (${name}) has no document to set a status on`);
441
- }
442
- const from = definition.statusOf(current.body);
443
- if (!canTransition(definition.statuses, from, asked.status)) {
444
- throw new Error(
445
- `"${name}" cannot move "${asked.ref}" from "${from}" to "${asked.status}": the status machine declares no such transition`
446
- );
447
- }
448
- const body = definition.withStatus(
449
- current.body,
450
- asked.status,
451
- (/* @__PURE__ */ new Date()).toISOString()
452
- );
453
- return door.commit(handle, { ...asked, body });
454
- },
455
- input: schema.object({
456
- actor: stringSchema,
457
- reason: optional(stringSchema),
458
- ref: stringSchema,
459
- status: schema.enum(definition.statuses.statuses)
460
- }),
461
- name: `${name}.setStatus`,
462
- output: commitOutput,
463
- path: `${basePath}/:ref/status`,
464
- scope: "org",
465
- verb: "mutation"
466
- },
467
- {
468
- call: { pending: "T3", workflow: `${name}.create` },
469
- input: schema.object({ draft: definition.draft }),
470
- name: `${name}.create`,
471
- output: commitOutput,
472
- path: basePath,
473
- scope: "org",
474
- verb: "mutation"
475
- },
476
- {
477
- call: { pending: "T3", workflow: `${name}.send` },
478
- input: schema.object({ ref: stringSchema }),
479
- name: `${name}.send`,
480
- output: ackOutput,
481
- path: `${basePath}/:ref/send`,
482
- scope: "org",
483
- verb: "mutation"
484
- },
485
- {
486
- call: { pending: "T3", workflow: `${name}.duplicate` },
487
- input: schema.object({ ref: stringSchema }),
488
- name: `${name}.duplicate`,
489
- output: commitOutput,
490
- path: `${basePath}/:ref/duplicate`,
491
- scope: "org",
492
- verb: "mutation"
493
- },
494
- {
495
- call: { pending: "T3", workflow: `${name}.runStarted` },
496
- input: schema.object({ ref: stringSchema }),
497
- name: `${name}.runStarted`,
498
- output: ackOutput,
499
- path: `${basePath}/:ref/run-started`,
500
- scope: "org",
501
- verb: "mutation"
502
- }
503
- ];
504
- };
505
- var documentSurface = (options) => {
506
- const { registry, schema, store } = options;
507
- const headsColumns = [...HEAD_COLUMNS, "entity", "number"];
508
- const headsInput = schema.object({
509
- columns: arrayOf(schema.enum(headsColumns)),
510
- entity: optional(schema.union([stringSchema, arrayOf(stringSchema)])),
511
- order: arrayOf(
512
- schema.object({
513
- column: schema.enum([...SORT_COLUMNS, "entity"]),
514
- direction: optional(schema.enum(["asc", "desc"]))
515
- })
516
- ),
517
- where: optional(unknownSchema)
518
- });
519
- const aggregateInput = schema.object({
520
- by: optional(unknownSchema),
521
- entities: optional(arrayOf(stringSchema)),
522
- entity: optional(stringSchema),
523
- measures: arrayOf(schema.enum(["count", "sum:total"])),
524
- where: optional(unknownSchema)
525
- });
526
- const aggregateOutput = arrayOf(
527
- schema.object({
528
- by: optional(stringSchema),
529
- count: optional(numberSchema),
530
- sum: optional(stringSchema)
531
- })
532
- );
533
- const sharedOutput = schema.union(
534
- registry.fold(
535
- (entity) => schema.object({ entity: schema.enum([entity.name]), view: entity.view })
536
- )
537
- );
538
- return [
539
- ...registry.fold((entity) => rowsFor(entity, store, schema)).flat(),
540
- {
541
- call: (handle, params) => store.heads(handle, params),
542
- input: headsInput,
543
- name: "heads",
544
- output: arrayOf(unknownSchema),
545
- path: "/documents/heads",
546
- scope: "org",
547
- verb: "query"
548
- },
549
- {
550
- call: (handle, params) => store.aggregate(handle, params),
551
- input: aggregateInput,
552
- name: "aggregate",
553
- output: aggregateOutput,
554
- path: "/documents/aggregate",
555
- scope: "org",
556
- verb: "query"
557
- },
558
- {
559
- call: { pending: "T3", workflow: "document.shared" },
560
- input: schema.object({ token: stringSchema }),
561
- name: "shared",
562
- output: sharedOutput,
563
- path: "/documents/shared",
564
- scope: "token",
565
- verb: "query"
566
- }
567
- ];
568
- };
569
-
570
- // src/store/ddl.ts
571
- import {
572
- DbRefusal,
573
- ENTITY_PLACEHOLDERS,
574
- logMigrations,
575
- projectionMigrations
576
- } from "@geonosis/db";
577
- var DEFAULT_DOCUMENT_TABLE = "documents";
578
- var DEFAULT_ENTITY_COLUMN = "entity";
579
- var DEFAULT_VERSION_COLUMN = "version";
580
- var DEFAULT_TENANT_COLUMN = "tenant_id";
581
- var DEFAULT_CREATED_AT_COLUMN = "created_at";
582
- var DEFAULT_UPDATED_AT_COLUMN = "updated_at";
583
- var DEFAULT_REVISIONS_TABLE = "document_revisions";
584
- var DEFAULT_REVISION_KIND_COLUMN = "revision_kind";
585
- var REVISION_KINDS = ["committed", "retired", "reinstated"];
586
- var HEAD_FIELDS = Object.keys(headFields);
587
- var snakeOf = (field) => field.replaceAll(/[A-Z]/g, (upper) => `_${upper.toLowerCase()}`);
588
- var nameOf = (value, fallback) => value === void 0 ? fallback : typeof value === "string" ? value : value.name;
589
- var physicalColumnsOf = (columns) => {
590
- const heads = Object.fromEntries(
591
- HEAD_FIELDS.map((field) => [
592
- field,
593
- nameOf(
594
- columns?.heads?.[field] ?? (field === "total" ? columns?.total : void 0),
595
- snakeOf(field)
596
- )
597
- ])
598
- );
599
- return {
600
- ...heads,
601
- createdAt: nameOf(columns?.createdAt, DEFAULT_CREATED_AT_COLUMN),
602
- entity: columns?.entity ?? DEFAULT_ENTITY_COLUMN,
603
- tenant: nameOf(columns?.tenant, DEFAULT_TENANT_COLUMN),
604
- updatedAt: nameOf(columns?.updatedAt, DEFAULT_UPDATED_AT_COLUMN)
605
- };
606
- };
607
- var appendOnlyTables = (options = {}) => {
608
- if (options.revisions === false) return [];
609
- return [options.revisions?.table ?? options.table ?? DEFAULT_REVISIONS_TABLE];
610
- };
611
- var quotedName = (name) => `"${name}"`;
612
- var literalName = (value) => `'${value.replaceAll("'", "''")}'`;
613
- var documentRoleStatements = (appRole, options = {}) => {
614
- if (typeof appRole !== "string" || appRole === "") {
615
- throw new DbRefusal(
616
- "documentRoleStatements needs an `appRole` \u2014 the name a consumer\u2019s application connects as belongs to whoever runs the database, and one baked in here would be another repo\u2019s"
617
- );
618
- }
619
- const role = quotedName(appRole);
620
- const on = (table) => options.schema === void 0 ? quotedName(table) : `${quotedName(options.schema)}.${quotedName(table)}`;
621
- return appendOnlyTables(options).flatMap((table) => [
622
- `revoke update, delete on ${on(table)} from ${role}`,
623
- `grant select, insert on ${on(table)} to ${role}`
624
- ]);
625
- };
626
- var DDL_TYPE_OF = { decimal: "numeric" };
627
- var headIndexedColumns = (physical) => HEAD_FIELDS.map((field) => {
628
- const type = DDL_TYPE_OF[headFields[field]];
629
- return {
630
- column: physical[field],
631
- nullable: field !== "status",
632
- ...type === void 0 ? {} : { type }
633
- };
634
- });
635
- var revisionKindType = (column) => `text check (${quotedName(column)} in (${REVISION_KINDS.map(literalName).join(", ")}))`;
636
- var walls = (options) => ({
637
- ...options.freeze === void 0 ? {} : { freeze: options.freeze },
638
- ...options.names === void 0 ? {} : { names: options.names },
639
- ...options.schema === void 0 ? {} : { schema: options.schema }
640
- });
641
- var revisionsMigrations = (options, physical) => {
642
- if (options.revisions === false) return [];
643
- if (typeof options.appRole !== "string" || options.appRole === "") {
644
- throw new DbRefusal(
645
- "documentMigrations needs an `appRole` to render the log\u2019s wall \u2014 the role a consumer\u2019s application connects as belongs to whoever runs the database, and one baked in here would be another repo\u2019s. Pass it, or opt out of the log entirely with `revisions: false`"
646
- );
647
- }
648
- const revisionKindColumn = options.columns?.revisionKind ?? DEFAULT_REVISION_KIND_COLUMN;
649
- const table = options.revisions?.table ?? DEFAULT_REVISIONS_TABLE;
650
- const [tableMigration, policies] = logMigrations({
651
- appRole: options.appRole,
652
- columns: { tenant: physical.tenant },
653
- extra: [{ column: revisionKindColumn, type: revisionKindType(revisionKindColumn) }],
654
- key: [physical.entity, "ref", { column: "lineage", type: "integer" }],
655
- ...walls(options),
656
- settings: options.settings,
657
- table
658
- });
659
- if (tableMigration === void 0 || policies === void 0) {
660
- throw new Error("logMigrations answered with fewer than the two migrations a log renders");
661
- }
662
- return [
663
- { ...tableMigration, name: `0003_${table}.sql` },
664
- { ...policies, name: `0004_${table}_policies.sql` }
665
- ];
666
- };
667
- var documentMigrations = (options) => {
668
- const table = options.table ?? DEFAULT_DOCUMENT_TABLE;
669
- const physical = physicalColumnsOf(options.columns);
670
- const {
671
- entity: _entity,
672
- heads: _heads,
673
- revisionKind: _revisionKind,
674
- total: _total,
675
- version,
676
- ...restColumns
677
- } = options.columns ?? {};
678
- const [tableMigration, ...rest] = projectionMigrations({
679
- carried: [{ column: "lineage", type: "integer not null default 1" }],
680
- columns: { ...restColumns, sequence: version ?? DEFAULT_VERSION_COLUMN },
681
- constants: { [physical.entity]: "" },
682
- indexed: headIndexedColumns(physical),
683
- key: "number",
684
- order: [{ column: "number" }],
685
- ...walls(options),
686
- settings: options.settings,
687
- sortable: [
688
- ...HEAD_FIELDS.map((field) => physical[field]),
689
- physical.createdAt,
690
- physical.updatedAt
691
- ],
692
- table
693
- });
694
- if (tableMigration === void 0) {
695
- throw new Error(
696
- "projectionMigrations answered with no table migration to append the listing index to"
697
- );
698
- }
699
- const listingIndex = `create index if not exists ${quotedName(`${table}_${physical.entity}_${physical.issueDate}_idx`)} on ${quotedName(table)} (${quotedName(physical.entity)}, ${quotedName(physical.issueDate)})`;
700
- return [
701
- { ...tableMigration, statements: [...tableMigration.statements, listingIndex] },
702
- ...rest,
703
- ...revisionsMigrations(options, physical)
704
- ];
705
- };
706
-
707
- // src/store/store.ts
708
- import {
709
- DbRefusal as DbRefusal2,
710
- defineEntity,
711
- defineLog,
712
- projectionOf
713
- } from "@geonosis/db";
714
- var DEFAULT_VERSION_COLUMN2 = "version";
715
- var UNDO_ACTOR = systemActor("document.undo");
716
- var nameOf2 = (value, fallback) => value === void 0 ? fallback : typeof value === "string" ? value : value.name;
717
- var readBody = (entity, entityName, ref, stored) => {
718
- const migrated = migrateBody(entity, stored);
719
- const result = entity.body["~standard"].validate(migrated);
720
- if (result instanceof Promise) {
721
- throw new Error(
722
- `${entityName} ${ref}: this entity's body schema validates asynchronously, and a stored body can only be read synchronously here`
723
- );
724
- }
725
- if (result.issues !== void 0) {
726
- throw new Error(
727
- `${entityName} ${ref}'s stored body no longer satisfies its own schema after migration: ${result.issues.map((issue) => issue.message).join("; ")}`
728
- );
729
- }
730
- return result.value;
731
- };
732
- var headFrom = (found) => found === void 0 ? void 0 : {
733
- body: found.body,
734
- hash: found.hash,
735
- lineage: Number(found.carried.lineage ?? 1),
736
- retiredAt: found.retiredAt,
737
- version: found.sequence
738
- };
739
- var documentStore = (options) => {
740
- const table = options.table ?? DEFAULT_DOCUMENT_TABLE;
741
- const revisionKindColumn = options.columns?.revisionKind ?? DEFAULT_REVISION_KIND_COLUMN;
742
- const physical = physicalColumnsOf(options.columns);
743
- const {
744
- entity: _entity,
745
- heads: _heads,
746
- revisionKind: _revisionKind,
747
- total: _total,
748
- version,
749
- ...entityColumns
750
- } = options.columns ?? {};
751
- const versionColumn = nameOf2(version, DEFAULT_VERSION_COLUMN2);
752
- const entityColumn = physical.entity;
753
- const { archive, registry, schema, seam } = options;
754
- const tenantKey = seam.tenantKey;
755
- const placed = schema === void 0 ? {} : { schema };
756
- const revisionsTable = options.revisions === false ? void 0 : options.revisions?.table ?? DEFAULT_REVISIONS_TABLE;
757
- const tenanted = (tenantId) => ({ [tenantKey]: tenantId });
758
- const columnOf = (column) => column === "number" ? "number" : physical[column];
759
- const physicalHeads = HEAD_FIELDS.map(columnOf);
760
- const narrowed = (where) => Object.fromEntries(
761
- Object.entries(where ?? {}).map(([column, held]) => [
762
- columnOf(column),
763
- held
764
- ])
765
- );
766
- const revisions = revisionsTable === void 0 ? void 0 : defineLog({
767
- columns: { tenant: physical.tenant },
768
- extra: [{ column: revisionKindColumn, param: "kind" }],
769
- hash: (row) => hashOf({
770
- actor: row.actor,
771
- at: row.at,
772
- body: row.body,
773
- entity: row.entity,
774
- kind: row.kind,
775
- lineage: row.lineage,
776
- prevHash: row.prevHash,
777
- reason: row.reason,
778
- ref: row.ref,
779
- tenant: row.tenant,
780
- version: row.sequence
781
- }),
782
- key: [
783
- { column: entityColumn, param: "entity" },
784
- { column: "ref", param: "ref" },
785
- { column: "lineage", param: "lineage" }
786
- ],
787
- ...placed,
788
- seam,
789
- table: revisionsTable
790
- });
791
- const needsLog = () => {
792
- if (revisions === void 0) {
793
- throw new DbRefusal2(
794
- "this store has no log \u2014 `documentStore({ revisions: false })` opted out of the append-only record entirely, and the write model has no other door"
795
- );
796
- }
797
- return revisions;
798
- };
799
- const readers = defineEntity({
800
- columns: { ...entityColumns, version: versionColumn },
801
- filterable: [...physicalHeads, entityColumn, physical.createdAt, physical.updatedAt],
802
- item: (row) => row,
803
- key: { column: "number", param: "ref" },
804
- order: [{ column: "number" }],
805
- ...placed,
806
- seam,
807
- sortable: [...physicalHeads, entityColumn, "number", physical.createdAt, physical.updatedAt],
808
- table
809
- });
810
- const entityStoreFor = (name) => {
811
- const definition = registry.named(name);
812
- const item = (row) => {
813
- const body = readBody(definition, name, row.key, row.body);
814
- const head = definition.headOf(body);
815
- return registry.instance(name, {
816
- ...head,
817
- body,
818
- createdAt: row.createdAt,
819
- number: row.key,
820
- updatedAt: row.updatedAt,
821
- version: row.version ?? 1
822
- });
823
- };
824
- const instanceFromRevision = (ref, row) => {
825
- const body = readBody(definition, name, ref, row.body);
826
- const head = definition.headOf(body);
827
- return registry.instance(name, {
828
- ...head,
829
- body,
830
- createdAt: row.at,
831
- number: ref,
832
- updatedAt: row.at,
833
- version: row.sequence
834
- });
835
- };
836
- const projection = projectionOf({
837
- carried: ["lineage"],
838
- columns: { ...entityColumns, hash: "hash", sequence: versionColumn },
839
- constants: { [entityColumn]: name },
840
- filterable: physicalHeads,
841
- item,
842
- key: { column: "number", param: "ref" },
843
- order: [{ column: "number" }],
844
- ...placed,
845
- seam,
846
- sortable: [...physicalHeads, "number", physical.createdAt, physical.updatedAt],
847
- table
848
- });
849
- const list = (handle, params) => projection.list(handle, {
850
- ...params,
851
- ...params.filter === void 0 ? {} : { filter: narrowed(params.filter) },
852
- ...params.order === void 0 ? {} : {
853
- order: {
854
- column: columnOf(params.order.column),
855
- ...params.order.direction === void 0 ? {} : { direction: params.order.direction }
856
- }
857
- }
858
- });
859
- const locked = async (tx, params) => headFrom(await projection.lockLatest(tx, params));
860
- const currentLineageOf = async (tx, params) => headFrom(await projection.head(tx, params))?.lineage ?? 1;
861
- const stream = (params, lineage) => ({
862
- ...tenanted(params[tenantKey]),
863
- entity: name,
864
- lineage,
865
- ref: params.ref
866
- });
867
- const headColumnsOf = (body) => Object.fromEntries(
868
- Object.entries(definition.headOf(body)).map(([key, held]) => [
869
- columnOf(key),
870
- held
871
- ])
872
- );
873
- const storedHead = (ref, body) => headColumnsOf(readBody(definition, name, ref, body));
874
- const append = async (tx, write) => {
875
- const log = needsLog();
876
- const params = {
877
- ...tenanted(write.tenantId),
878
- actor: write.actor,
879
- body: write.body,
880
- entity: name,
881
- kind: write.kind,
882
- lineage: write.lineage,
883
- ref: write.ref,
884
- ...write.reason === null ? {} : { reason: write.reason }
885
- };
886
- const out = write.compensationOf === null ? await log.append(tx, params) : await log.appendCompensation(tx, { ...params, compensationOf: write.compensationOf });
887
- return { at: out.at, hash: out.hash, prevHash: out.prevHash, version: out.sequence };
888
- };
889
- const project = async (tx, write) => projection.write(tx, {
890
- ...tenanted(write.tenantId),
891
- at: write.at,
892
- body: write.body,
893
- carried: { lineage: write.lineage },
894
- derived: write.head,
895
- hash: write.hash,
896
- ref: write.ref,
897
- retiredAt: write.retiredAt,
898
- sequence: write.version
899
- });
900
- const commitTx = seam.scoped(
901
- async (tx, params) => {
902
- const tenantId = params[tenantKey];
903
- const prepared = definition.prepare(params.body);
904
- const stamped = stampBody(definition, prepared);
905
- const existing = await locked(tx, params);
906
- if (existing !== void 0 && existing.retiredAt !== null) {
907
- throw new DbRefusal2(
908
- `"${params.ref}" (${name}) is retired: commit refuses a retired document \u2014 succeed opens a new lineage for it`
909
- );
910
- }
911
- const changed = existing === void 0 || JSON.stringify(canonicalOf(existing.body)) !== JSON.stringify(canonicalOf(stamped));
912
- if (existing !== void 0 && !changed) {
913
- return {
914
- committed: false,
915
- lineage: existing.lineage,
916
- ref: params.ref,
917
- version: existing.version
918
- };
919
- }
920
- const lineage = existing?.lineage ?? 1;
921
- const reason = params.reason ?? null;
922
- const appended = await append(tx, {
923
- actor: params.actor,
924
- body: stamped,
925
- compensationOf: null,
926
- kind: "committed",
927
- lineage,
928
- reason,
929
- ref: params.ref,
930
- tenantId
931
- });
932
- await project(tx, {
933
- at: appended.at,
934
- body: stamped,
935
- hash: appended.hash,
936
- head: headColumnsOf(prepared),
937
- lineage,
938
- ref: params.ref,
939
- retiredAt: null,
940
- tenantId,
941
- version: appended.version
942
- });
943
- return {
944
- archivable: {
945
- actor: params.actor,
946
- at: appended.at,
947
- body: stamped,
948
- prevHash: appended.prevHash,
949
- reason
950
- },
951
- committed: true,
952
- hash: appended.hash,
953
- lineage,
954
- previous: existing === void 0 ? null : { hash: existing.hash, version: existing.version },
955
- ref: params.ref,
956
- version: appended.version
957
- };
958
- }
959
- );
960
- const commit = async (handle, params) => {
961
- const { archivable, ...answer } = await commitTx(handle, params);
962
- if (archive === void 0 || !answer.committed || archivable === void 0) return answer;
963
- const key = `${params[tenantKey]}/${name}/${answer.lineage}/${answer.version}.json`;
964
- const payload = {
965
- actor: archivable.actor,
966
- at: archivable.at,
967
- body: archivable.body,
968
- entity: name,
969
- hash: answer.hash,
970
- kind: "committed",
971
- lineage: answer.lineage,
972
- prevHash: archivable.prevHash,
973
- ref: params.ref,
974
- reason: archivable.reason,
975
- tenant: params[tenantKey],
976
- version: answer.version
977
- };
978
- try {
979
- await archive.put(key, new TextEncoder().encode(JSON.stringify(payload)), {
980
- hash: answer.hash,
981
- immutable: true
982
- });
983
- return { ...answer, archived: true };
984
- } catch {
985
- return { ...answer, archived: false };
986
- }
987
- };
988
- const retire = seam.scoped(
989
- async (tx, params) => {
990
- const tenantId = params[tenantKey];
991
- const existing = await locked(tx, params);
992
- if (existing === void 0) {
993
- throw new DbRefusal2(`"${params.ref}" (${name}) has no document to retire`);
994
- }
995
- if (existing.retiredAt !== null) {
996
- throw new DbRefusal2(`"${params.ref}" (${name}) is already retired`);
997
- }
998
- const appended = await append(tx, {
999
- actor: params.actor,
1000
- body: existing.body,
1001
- compensationOf: null,
1002
- kind: "retired",
1003
- lineage: existing.lineage,
1004
- reason: params.reason ?? null,
1005
- ref: params.ref,
1006
- tenantId
1007
- });
1008
- await project(tx, {
1009
- at: appended.at,
1010
- body: existing.body,
1011
- hash: appended.hash,
1012
- head: storedHead(params.ref, existing.body),
1013
- lineage: existing.lineage,
1014
- ref: params.ref,
1015
- retiredAt: appended.at,
1016
- tenantId,
1017
- version: appended.version
1018
- });
1019
- return {
1020
- hash: appended.hash,
1021
- lineage: existing.lineage,
1022
- ref: params.ref,
1023
- version: appended.version
1024
- };
1025
- }
1026
- );
1027
- const succeed = seam.scoped(
1028
- async (tx, params) => {
1029
- const tenantId = params[tenantKey];
1030
- const existing = await locked(tx, params);
1031
- if (existing === void 0 || existing.retiredAt === null) {
1032
- throw new DbRefusal2(
1033
- `"${params.ref}" (${name}) is not retired: succeed opens a new lineage only for a retired document \u2014 commit is the door for a live one`
1034
- );
1035
- }
1036
- const prepared = definition.prepare(params.body);
1037
- const stamped = stampBody(definition, prepared);
1038
- const lineage = existing.lineage + 1;
1039
- const appended = await append(tx, {
1040
- actor: params.actor,
1041
- body: stamped,
1042
- compensationOf: null,
1043
- kind: "committed",
1044
- lineage,
1045
- reason: params.reason ?? null,
1046
- ref: params.ref,
1047
- tenantId
1048
- });
1049
- await project(tx, {
1050
- at: appended.at,
1051
- body: stamped,
1052
- hash: appended.hash,
1053
- head: headColumnsOf(prepared),
1054
- lineage,
1055
- ref: params.ref,
1056
- retiredAt: null,
1057
- tenantId,
1058
- version: appended.version
1059
- });
1060
- return {
1061
- committed: true,
1062
- hash: appended.hash,
1063
- lineage,
1064
- previous: null,
1065
- ref: params.ref,
1066
- version: appended.version
1067
- };
1068
- }
1069
- );
1070
- const reinstate = seam.scoped(
1071
- async (tx, params) => {
1072
- const tenantId = params[tenantKey];
1073
- const existing = await locked(tx, params);
1074
- if (existing === void 0 || existing.retiredAt === null) {
1075
- throw new DbRefusal2(`"${params.ref}" (${name}) is not retired: nothing to reinstate`);
1076
- }
1077
- const appended = await append(tx, {
1078
- actor: params.actor,
1079
- body: existing.body,
1080
- compensationOf: null,
1081
- kind: "reinstated",
1082
- lineage: existing.lineage,
1083
- reason: params.reason ?? null,
1084
- ref: params.ref,
1085
- tenantId
1086
- });
1087
- await project(tx, {
1088
- at: appended.at,
1089
- body: existing.body,
1090
- hash: appended.hash,
1091
- head: storedHead(params.ref, existing.body),
1092
- lineage: existing.lineage,
1093
- ref: params.ref,
1094
- retiredAt: null,
1095
- tenantId,
1096
- version: appended.version
1097
- });
1098
- return {
1099
- hash: appended.hash,
1100
- lineage: existing.lineage,
1101
- ref: params.ref,
1102
- version: appended.version
1103
- };
1104
- }
1105
- );
1106
- const at = seam.scoped(
1107
- async (tx, params) => {
1108
- const lineage = await currentLineageOf(tx, params);
1109
- const row = await needsLog().at(tx, {
1110
- ...stream(params, lineage),
1111
- sequence: params.version
1112
- });
1113
- return row === null ? null : instanceFromRevision(params.ref, row);
1114
- }
1115
- );
1116
- const asOf = seam.scoped(
1117
- async (tx, params) => {
1118
- const lineage = await currentLineageOf(tx, params);
1119
- const row = await needsLog().asOf(tx, { ...stream(params, lineage), at: params.at });
1120
- return row === null ? null : instanceFromRevision(params.ref, row);
1121
- }
1122
- );
1123
- const history = seam.scoped(
1124
- async (tx, params) => {
1125
- const lineage = params.lineage ?? await currentLineageOf(tx, params);
1126
- const rows = await needsLog().history(tx, stream(params, lineage));
1127
- return rows.map((row) => ({
1128
- actor: row.actor,
1129
- at: row.at,
1130
- body: readBody(definition, name, `${params.ref} version ${row.sequence}`, row.body),
1131
- hash: row.hash,
1132
- kind: row.kind,
1133
- reason: row.reason,
1134
- version: row.sequence
1135
- }));
1136
- }
1137
- );
1138
- const verify = seam.scoped(
1139
- async (tx, params) => {
1140
- const lineage = params.lineage ?? await currentLineageOf(tx, params);
1141
- return needsLog().verify(tx, stream(params, lineage));
1142
- }
1143
- );
1144
- const compensate = async (scoped, tenantId, output, kind, body, retired) => {
1145
- const appended = await append(scoped, {
1146
- actor: UNDO_ACTOR,
1147
- body,
1148
- compensationOf: output.version,
1149
- kind,
1150
- lineage: output.lineage,
1151
- reason: `undo of v${output.version}`,
1152
- ref: output.ref,
1153
- tenantId
1154
- });
1155
- await project(scoped, {
1156
- at: appended.at,
1157
- body,
1158
- hash: appended.hash,
1159
- head: storedHead(output.ref, body),
1160
- lineage: output.lineage,
1161
- ref: output.ref,
1162
- retiredAt: retired ? appended.at : null,
1163
- tenantId,
1164
- version: appended.version
1165
- });
1166
- };
1167
- const lockedForUndo = async (scoped, tenantId, output) => {
1168
- const existing = await locked(scoped, { ...tenanted(tenantId), ref: output.ref });
1169
- if (existing === void 0) {
1170
- throw new DbRefusal2(
1171
- `"${output.ref}" (${name}) has nothing to undo \u2014 the row v${output.version} wrote is gone`
1172
- );
1173
- }
1174
- return existing;
1175
- };
1176
- const undos = {
1177
- commit: (tx, { output, tenantId }) => seam.inTenant(tx, tenantId, async (scoped) => {
1178
- if (!output.committed) return;
1179
- const existing = await lockedForUndo(scoped, tenantId, output);
1180
- if (output.previous === null) {
1181
- await compensate(scoped, tenantId, output, "retired", existing.body, true);
1182
- return;
1183
- }
1184
- const prior = await needsLog().at(scoped, {
1185
- ...stream({ ...tenanted(tenantId), ref: output.ref }, output.lineage),
1186
- sequence: output.previous.version
1187
- });
1188
- if (prior === null) {
1189
- throw new DbRefusal2(
1190
- `"${output.ref}" (${name}) version ${output.previous.version} is gone \u2014 cannot undo v${output.version} without it`
1191
- );
1192
- }
1193
- await compensate(scoped, tenantId, output, "committed", prior.body, false);
1194
- }),
1195
- retire: (tx, { output, tenantId }) => seam.inTenant(tx, tenantId, async (scoped) => {
1196
- const existing = await lockedForUndo(scoped, tenantId, output);
1197
- await compensate(scoped, tenantId, output, "reinstated", existing.body, false);
1198
- })
1199
- };
1200
- const restore = async (tx, row, createdAt) => {
1201
- const ref = String(row.ref);
1202
- await project(tx, {
1203
- at: createdAt,
1204
- body: row.body,
1205
- hash: row.hash,
1206
- head: storedHead(ref, row.body),
1207
- lineage: Number(row.lineage),
1208
- ref,
1209
- retiredAt: row.kind === "retired" ? row.at : null,
1210
- tenantId: row.tenant,
1211
- version: row.sequence
1212
- });
1213
- };
1214
- return {
1215
- door: {
1216
- asOf,
1217
- at,
1218
- commit,
1219
- get: projection.get,
1220
- history,
1221
- list,
1222
- listAll: projection.listAll,
1223
- reinstate,
1224
- retire,
1225
- succeed,
1226
- undos,
1227
- verify
1228
- },
1229
- restore
1230
- };
1231
- };
1232
- const built = registry.names.map((name) => [name, entityStoreFor(name)]);
1233
- const rawEntities = Object.fromEntries(built.map(([name, one]) => [name, one.door]));
1234
- const restorers = Object.fromEntries(
1235
- built.map(([name, one]) => [name, one.restore])
1236
- );
1237
- const heads = seam.scoped(
1238
- async (tx, params) => {
1239
- const { columns, entity, order, where } = params;
1240
- const rows = await readers.project(tx, {
1241
- ...tenanted(params[tenantKey]),
1242
- columns: columns.filter((column) => column !== "number").map(columnOf),
1243
- order: order.map((one) => ({
1244
- column: columnOf(one.column),
1245
- ...one.direction === void 0 ? {} : { direction: one.direction }
1246
- })),
1247
- where: {
1248
- ...entity === void 0 ? {} : { [entityColumn]: entity },
1249
- ...narrowed(where)
1250
- }
1251
- });
1252
- return rows.map(
1253
- (row) => Object.fromEntries(
1254
- columns.map((column) => [column, column === "number" ? row.key : row[columnOf(column)]])
1255
- )
1256
- );
1257
- }
1258
- );
1259
- const aggregate = seam.scoped(
1260
- (tx, params) => {
1261
- const { by, entities, entity, measures, where } = params;
1262
- return readers.aggregate(tx, {
1263
- ...tenanted(params[tenantKey]),
1264
- ...by === void 0 ? {} : {
1265
- by: typeof by === "string" ? columnOf(by) : { bucket: by.bucket, of: columnOf(by.of) }
1266
- },
1267
- measures: measures.map(
1268
- (one) => one === "sum:total" ? `sum:${physical.total}` : one
1269
- ),
1270
- where: {
1271
- ...entity === void 0 ? {} : { [entityColumn]: entity },
1272
- ...entities === void 0 ? {} : { [entityColumn]: entities },
1273
- ...narrowed(where)
1274
- }
1275
- });
1276
- }
1277
- );
1278
- const rebuild = seam.scoped(
1279
- async (tx, params) => {
1280
- const log = needsLog();
1281
- const tenant = tenanted(params[tenantKey]);
1282
- const latest = /* @__PURE__ */ new Map();
1283
- for (const row of await log.latestPerStream(tx, tenant)) {
1284
- if (params.entity !== void 0 && row.entity !== params.entity) continue;
1285
- const address = `${String(row.entity)} ${String(row.ref)}`;
1286
- const held = latest.get(address);
1287
- if (held === void 0 || Number(row.lineage) > Number(held.lineage)) {
1288
- latest.set(address, row);
1289
- }
1290
- }
1291
- let rows = 0;
1292
- for (const row of latest.values()) {
1293
- const restore = restorers[String(row.entity)];
1294
- if (restore === void 0) continue;
1295
- const first = await log.at(tx, {
1296
- ...tenant,
1297
- entity: row.entity,
1298
- lineage: row.lineage,
1299
- ref: row.ref,
1300
- sequence: 1
1301
- });
1302
- await restore(tx, row, first?.at ?? row.at);
1303
- rows += 1;
1304
- }
1305
- return { rows };
1306
- }
1307
- );
1308
- return { ...rawEntities, aggregate, heads, rebuild };
1309
- };
1310
30
  export {
1311
31
  BODY_VERSION_KEY,
1312
- DEFAULT_DOCUMENT_TABLE,
1313
- DEFAULT_REVISIONS_TABLE,
1314
- DEFAULT_REVISION_KIND_COLUMN,
1315
- ENTITY_PLACEHOLDERS as DOCUMENT_MIGRATION_PLACEHOLDERS,
1316
32
  Document,
1317
- HEAD_FIELDS,
1318
- appendOnlyTables,
1319
33
  canTransition,
1320
34
  canonicalOf,
1321
35
  documentBodyVersioning,
1322
36
  documentEntities,
1323
37
  documentIdentifiers,
1324
- documentMigrations,
1325
- documentRoleStatements,
1326
- documentStore,
1327
- documentSurface,
1328
38
  fieldPatterns,
1329
- hashOf,
1330
39
  isSystemActor,
1331
40
  isTerminalStatus,
1332
41
  migrateBody,
1333
- physicalColumnsOf,
1334
42
  stampBody,
1335
43
  systemActor,
1336
44
  validatorOf