@geonosis/document 0.3.0 → 0.4.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/CHANGELOG.md +25 -0
- package/README.md +23 -15
- package/dist/index.cjs +111 -67
- package/dist/index.d.cts +33 -22
- package/dist/index.d.ts +33 -22
- package/dist/index.js +109 -67
- package/migrations/0001_documents.sql +21 -13
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @geonosis/document
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 748795d: 0.4.0, read off the consumer's own callers (#427–#430). Head columns are snake by default
|
|
8
|
+
(`issue_date`, `due_date`, `external_ref`; `columns.heads` renames any, `physicalColumnsOf` is the
|
|
9
|
+
one map) — a rename done before anyone has data. Every entity's `list` sorts by `number`, `createdAt`
|
|
10
|
+
and `updatedAt` beside the head fields, and `documentMigrations` renders the two clock indexes per
|
|
11
|
+
entity. `heads` and `aggregate` narrow by ANY head field (equality, a set, or `{ from, to }` — the
|
|
12
|
+
tuple ranges are gone) plus `createdAt`/`updatedAt` ranges; `aggregate` groups by any head field;
|
|
13
|
+
`heads` answers `HeadRow<Columns>` typed off its `columns`. `freeze` and `names` pass through
|
|
14
|
+
`documentMigrations` to both tables' walls (#429). The shapes that
|
|
15
|
+
carry it: `HeadColumn` (off `HeadField`), `HeadsArgs<Columns>`, `HeadsWhere` (any head field, a set
|
|
16
|
+
or a range, plus the two clocks), `AggregateWhere` (the same), `AggregateBy` (any head field, `entity`,
|
|
17
|
+
or a date bucket), `HeadsOrder` (a clock or `number` beside the heads), `HeadRow<Columns>`,
|
|
18
|
+
`DocumentSortColumn`.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 8d82c01: `documentMigrations` renders `status` as `not null` and the six other head columns nullable, now that
|
|
23
|
+
the entity floor renders indexed columns `not null` by default; `0001_documents.sql` follows.
|
|
24
|
+
- Updated dependencies [e08161b]
|
|
25
|
+
- Updated dependencies [d470d30]
|
|
26
|
+
- @geonosis/db@0.10.0
|
|
27
|
+
|
|
3
28
|
## 0.3.0
|
|
4
29
|
|
|
5
30
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -106,14 +106,19 @@ columns are the seven head columns, the entity column and `created_at`. Every wr
|
|
|
106
106
|
on the current lineage; `rebuild` folds `latestPerStream` to the highest lineage per `(entity, ref)`
|
|
107
107
|
and writes it back.
|
|
108
108
|
|
|
109
|
-
`documentMigrations({ table?, schema?, columns?, revisions?, appRole })` is
|
|
110
|
-
(the seven head columns typed off `FieldKind`, `
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
`
|
|
116
|
-
|
|
109
|
+
`documentMigrations({ table?, schema?, columns?, revisions?, appRole, freeze?, names? })` is
|
|
110
|
+
`projectionMigrations` (the seven head columns typed off `FieldKind`, `status` not null and the rest
|
|
111
|
+
nullable, `lineage` carried, `hash`, the version column as the sequence, one index per head field
|
|
112
|
+
and per clock under `(tenant, entity, …)`) plus the `(entity, issue_date)` listing index, then
|
|
113
|
+
`logMigrations` for the revisions table unless `revisions: false` — the same walls the floor renders
|
|
114
|
+
for any log, with `revision_kind` constrained to `committed | retired | reinstated`, and `freeze`/
|
|
115
|
+
`names` passed to both. Head columns are snake by default (`issue_date`, `due_date`,
|
|
116
|
+
`external_ref`); `columns.heads` renames any of them, `columns.total` is the same for `total`.
|
|
117
|
+
`physicalColumnsOf(columns)` is the one map from a head field to its column, exported. `appRole` is
|
|
118
|
+
required whenever the log renders (the default): the name a consumer's application connects as, the
|
|
119
|
+
same law as `@geonosis/db`'s own `appRoleStatements`. The log's own kind column is
|
|
120
|
+
`columns.revisionKind`, `'revision_kind'` when unnamed — never `'kind'`, which is what these docs
|
|
121
|
+
use for `columns.entity` (#407).
|
|
117
122
|
|
|
118
123
|
## Writes
|
|
119
124
|
|
|
@@ -183,13 +188,16 @@ version of its latest lineage, per `(entity, ref)`, and answers how many rows it
|
|
|
183
188
|
consumer's repair tool, and the exam's own way of proving the projection is truly DERIVED.
|
|
184
189
|
|
|
185
190
|
`store.heads({ columns, entity?, order, where? })` is a PROJECTION, never an aggregate: the head
|
|
186
|
-
|
|
187
|
-
ordered by (the tie-break included
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
fields plus `entity` and `number`, typed off `columns` (`HeadRow<Columns>` — no cast), `entity` one
|
|
192
|
+
kind or a set, `order` every column a page is ordered by (the tie-break included; the two clocks
|
|
193
|
+
sort too), `where` any head field as equality, a set, or `{ from, to }`, plus `createdAt`/`updatedAt`
|
|
194
|
+
ranges. `store.aggregate({ by?, entity?, entities?, measures, where? })` answers `count` and
|
|
195
|
+
`sum:total` — `where` the same shape, OPTIONAL — grouped by any head field, `'entity'`, or `{ bucket:
|
|
196
|
+
'day' | 'week' | 'month', of: 'issueDate' | 'dueDate' }`. `count` is a number; `sum:total` is a
|
|
197
|
+
DECIMAL STRING (`'0'` for an empty group) — money never crosses this door as a float either. Both
|
|
198
|
+
are tenant-scoped by the seam and exclude retired rows. `store.<entity>.list` sorts by any head
|
|
199
|
+
field, `number`, `createdAt` or `updatedAt`, and narrows by any head field — logical names in, the
|
|
200
|
+
physical columns underneath.
|
|
193
201
|
|
|
194
202
|
## Surfaces
|
|
195
203
|
|
package/dist/index.cjs
CHANGED
|
@@ -26,6 +26,7 @@ __export(index_exports, {
|
|
|
26
26
|
DEFAULT_REVISION_KIND_COLUMN: () => DEFAULT_REVISION_KIND_COLUMN,
|
|
27
27
|
DOCUMENT_MIGRATION_PLACEHOLDERS: () => import_db.ENTITY_PLACEHOLDERS,
|
|
28
28
|
Document: () => Document,
|
|
29
|
+
HEAD_FIELDS: () => HEAD_FIELDS,
|
|
29
30
|
appendOnlyTables: () => appendOnlyTables,
|
|
30
31
|
canTransition: () => canTransition,
|
|
31
32
|
canonicalOf: () => canonicalOf,
|
|
@@ -41,6 +42,7 @@ __export(index_exports, {
|
|
|
41
42
|
isSystemActor: () => isSystemActor,
|
|
42
43
|
isTerminalStatus: () => isTerminalStatus,
|
|
43
44
|
migrateBody: () => migrateBody,
|
|
45
|
+
physicalColumnsOf: () => physicalColumnsOf,
|
|
44
46
|
stampBody: () => stampBody,
|
|
45
47
|
systemActor: () => systemActor,
|
|
46
48
|
validatorOf: () => validatorOf
|
|
@@ -322,6 +324,7 @@ var doorFor = (store, name) => {
|
|
|
322
324
|
return door;
|
|
323
325
|
};
|
|
324
326
|
var HEAD_COLUMNS = Object.keys(Document.headFields);
|
|
327
|
+
var SORT_COLUMNS = [...HEAD_COLUMNS, "number", "createdAt", "updatedAt"];
|
|
325
328
|
var rowsFor = (definition, store, schema) => {
|
|
326
329
|
const { name } = definition;
|
|
327
330
|
const door = doorFor(store, name);
|
|
@@ -384,7 +387,7 @@ var rowsFor = (definition, store, schema) => {
|
|
|
384
387
|
limit: optional(numberSchema),
|
|
385
388
|
order: optional(
|
|
386
389
|
schema.object({
|
|
387
|
-
column: schema.enum(
|
|
390
|
+
column: schema.enum(SORT_COLUMNS),
|
|
388
391
|
direction: optional(schema.enum(["asc", "desc"]))
|
|
389
392
|
})
|
|
390
393
|
)
|
|
@@ -558,13 +561,11 @@ var documentSurface = (options) => {
|
|
|
558
561
|
entity: optional(schema.union([stringSchema, arrayOf(stringSchema)])),
|
|
559
562
|
order: arrayOf(
|
|
560
563
|
schema.object({
|
|
561
|
-
column: schema.enum(
|
|
564
|
+
column: schema.enum([...SORT_COLUMNS, "entity"]),
|
|
562
565
|
direction: optional(schema.enum(["asc", "desc"]))
|
|
563
566
|
})
|
|
564
567
|
),
|
|
565
|
-
where: optional(
|
|
566
|
-
schema.object({ createdAt: optional(arrayOf(numberSchema)), status: optional(stringSchema) })
|
|
567
|
-
)
|
|
568
|
+
where: optional(unknownSchema)
|
|
568
569
|
});
|
|
569
570
|
const aggregateInput = schema.object({
|
|
570
571
|
by: optional(unknownSchema),
|
|
@@ -622,12 +623,33 @@ var import_db = require("@geonosis/db");
|
|
|
622
623
|
var DEFAULT_DOCUMENT_TABLE = "documents";
|
|
623
624
|
var DEFAULT_ENTITY_COLUMN = "entity";
|
|
624
625
|
var DEFAULT_VERSION_COLUMN = "version";
|
|
625
|
-
var DEFAULT_TOTAL_COLUMN = "total";
|
|
626
626
|
var DEFAULT_TENANT_COLUMN = "tenant_id";
|
|
627
|
+
var DEFAULT_CREATED_AT_COLUMN = "created_at";
|
|
628
|
+
var DEFAULT_UPDATED_AT_COLUMN = "updated_at";
|
|
627
629
|
var DEFAULT_REVISIONS_TABLE = "document_revisions";
|
|
628
630
|
var DEFAULT_REVISION_KIND_COLUMN = "revision_kind";
|
|
629
631
|
var REVISION_KINDS = ["committed", "retired", "reinstated"];
|
|
632
|
+
var HEAD_FIELDS = Object.keys(headFields);
|
|
633
|
+
var snakeOf = (field) => field.replaceAll(/[A-Z]/g, (upper) => `_${upper.toLowerCase()}`);
|
|
630
634
|
var nameOf = (value, fallback) => value === void 0 ? fallback : typeof value === "string" ? value : value.name;
|
|
635
|
+
var physicalColumnsOf = (columns) => {
|
|
636
|
+
const heads = Object.fromEntries(
|
|
637
|
+
HEAD_FIELDS.map((field) => [
|
|
638
|
+
field,
|
|
639
|
+
nameOf(
|
|
640
|
+
columns?.heads?.[field] ?? (field === "total" ? columns?.total : void 0),
|
|
641
|
+
snakeOf(field)
|
|
642
|
+
)
|
|
643
|
+
])
|
|
644
|
+
);
|
|
645
|
+
return {
|
|
646
|
+
...heads,
|
|
647
|
+
createdAt: nameOf(columns?.createdAt, DEFAULT_CREATED_AT_COLUMN),
|
|
648
|
+
entity: columns?.entity ?? DEFAULT_ENTITY_COLUMN,
|
|
649
|
+
tenant: nameOf(columns?.tenant, DEFAULT_TENANT_COLUMN),
|
|
650
|
+
updatedAt: nameOf(columns?.updatedAt, DEFAULT_UPDATED_AT_COLUMN)
|
|
651
|
+
};
|
|
652
|
+
};
|
|
631
653
|
var appendOnlyTables = (options = {}) => {
|
|
632
654
|
if (options.revisions === false) return [];
|
|
633
655
|
return [options.revisions?.table ?? options.table ?? DEFAULT_REVISIONS_TABLE];
|
|
@@ -648,13 +670,21 @@ var documentRoleStatements = (appRole, options = {}) => {
|
|
|
648
670
|
]);
|
|
649
671
|
};
|
|
650
672
|
var DDL_TYPE_OF = { decimal: "numeric" };
|
|
651
|
-
var headIndexedColumns = (
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
|
|
673
|
+
var headIndexedColumns = (physical) => HEAD_FIELDS.map((field) => {
|
|
674
|
+
const type = DDL_TYPE_OF[headFields[field]];
|
|
675
|
+
return {
|
|
676
|
+
column: physical[field],
|
|
677
|
+
nullable: field !== "status",
|
|
678
|
+
...type === void 0 ? {} : { type }
|
|
679
|
+
};
|
|
655
680
|
});
|
|
656
681
|
var revisionKindType = (column) => `text check (${quotedName(column)} in (${REVISION_KINDS.map(literalName).join(", ")}))`;
|
|
657
|
-
var
|
|
682
|
+
var walls = (options) => ({
|
|
683
|
+
...options.freeze === void 0 ? {} : { freeze: options.freeze },
|
|
684
|
+
...options.names === void 0 ? {} : { names: options.names },
|
|
685
|
+
...options.schema === void 0 ? {} : { schema: options.schema }
|
|
686
|
+
});
|
|
687
|
+
var revisionsMigrations = (options, physical) => {
|
|
658
688
|
if (options.revisions === false) return [];
|
|
659
689
|
if (typeof options.appRole !== "string" || options.appRole === "") {
|
|
660
690
|
throw new import_db.DbRefusal(
|
|
@@ -665,10 +695,10 @@ var revisionsMigrations = (options, entityColumn, tenantColumn) => {
|
|
|
665
695
|
const table = options.revisions?.table ?? DEFAULT_REVISIONS_TABLE;
|
|
666
696
|
const [tableMigration, policies] = (0, import_db.logMigrations)({
|
|
667
697
|
appRole: options.appRole,
|
|
668
|
-
columns: { tenant:
|
|
698
|
+
columns: { tenant: physical.tenant },
|
|
669
699
|
extra: [{ column: revisionKindColumn, type: revisionKindType(revisionKindColumn) }],
|
|
670
|
-
key: [
|
|
671
|
-
...options
|
|
700
|
+
key: [physical.entity, "ref", { column: "lineage", type: "integer" }],
|
|
701
|
+
...walls(options),
|
|
672
702
|
settings: options.settings,
|
|
673
703
|
table
|
|
674
704
|
});
|
|
@@ -682,11 +712,10 @@ var revisionsMigrations = (options, entityColumn, tenantColumn) => {
|
|
|
682
712
|
};
|
|
683
713
|
var documentMigrations = (options) => {
|
|
684
714
|
const table = options.table ?? DEFAULT_DOCUMENT_TABLE;
|
|
685
|
-
const
|
|
686
|
-
const totalColumn = nameOf(options.columns?.total, DEFAULT_TOTAL_COLUMN);
|
|
687
|
-
const tenantColumn = nameOf(options.columns?.tenant, DEFAULT_TENANT_COLUMN);
|
|
715
|
+
const physical = physicalColumnsOf(options.columns);
|
|
688
716
|
const {
|
|
689
717
|
entity: _entity,
|
|
718
|
+
heads: _heads,
|
|
690
719
|
revisionKind: _revisionKind,
|
|
691
720
|
total: _total,
|
|
692
721
|
version,
|
|
@@ -695,13 +724,17 @@ var documentMigrations = (options) => {
|
|
|
695
724
|
const [tableMigration, ...rest] = (0, import_db.projectionMigrations)({
|
|
696
725
|
carried: [{ column: "lineage", type: "integer not null default 1" }],
|
|
697
726
|
columns: { ...restColumns, sequence: version ?? DEFAULT_VERSION_COLUMN },
|
|
698
|
-
constants: { [
|
|
699
|
-
indexed: headIndexedColumns(
|
|
727
|
+
constants: { [physical.entity]: "" },
|
|
728
|
+
indexed: headIndexedColumns(physical),
|
|
700
729
|
key: "number",
|
|
701
730
|
order: [{ column: "number" }],
|
|
702
|
-
...options
|
|
731
|
+
...walls(options),
|
|
703
732
|
settings: options.settings,
|
|
704
|
-
sortable:
|
|
733
|
+
sortable: [
|
|
734
|
+
...HEAD_FIELDS.map((field) => physical[field]),
|
|
735
|
+
physical.createdAt,
|
|
736
|
+
physical.updatedAt
|
|
737
|
+
],
|
|
705
738
|
table
|
|
706
739
|
});
|
|
707
740
|
if (tableMigration === void 0) {
|
|
@@ -709,21 +742,17 @@ var documentMigrations = (options) => {
|
|
|
709
742
|
"projectionMigrations answered with no table migration to append the listing index to"
|
|
710
743
|
);
|
|
711
744
|
}
|
|
712
|
-
const listingIndex = `create index if not exists ${quotedName(`${table}_${
|
|
745
|
+
const listingIndex = `create index if not exists ${quotedName(`${table}_${physical.entity}_${physical.issueDate}_idx`)} on ${quotedName(table)} (${quotedName(physical.entity)}, ${quotedName(physical.issueDate)})`;
|
|
713
746
|
return [
|
|
714
747
|
{ ...tableMigration, statements: [...tableMigration.statements, listingIndex] },
|
|
715
748
|
...rest,
|
|
716
|
-
...revisionsMigrations(options,
|
|
749
|
+
...revisionsMigrations(options, physical)
|
|
717
750
|
];
|
|
718
751
|
};
|
|
719
752
|
|
|
720
753
|
// src/store/store.ts
|
|
721
754
|
var import_db2 = require("@geonosis/db");
|
|
722
|
-
var DEFAULT_ENTITY_COLUMN2 = "entity";
|
|
723
755
|
var DEFAULT_VERSION_COLUMN2 = "version";
|
|
724
|
-
var DEFAULT_TOTAL_COLUMN2 = "total";
|
|
725
|
-
var DEFAULT_TENANT_COLUMN2 = "tenant_id";
|
|
726
|
-
var DEFAULT_CREATED_AT_COLUMN = "created_at";
|
|
727
756
|
var UNDO_ACTOR = systemActor("document.undo");
|
|
728
757
|
var nameOf2 = (value, fallback) => value === void 0 ? fallback : typeof value === "string" ? value : value.name;
|
|
729
758
|
var readBody = (entity, entityName, ref, stored) => {
|
|
@@ -741,7 +770,6 @@ var readBody = (entity, entityName, ref, stored) => {
|
|
|
741
770
|
}
|
|
742
771
|
return result.value;
|
|
743
772
|
};
|
|
744
|
-
var HEAD_COLUMNS2 = Object.keys(headFields);
|
|
745
773
|
var headFrom = (found) => found === void 0 ? void 0 : {
|
|
746
774
|
body: found.body,
|
|
747
775
|
hash: found.hash,
|
|
@@ -751,28 +779,33 @@ var headFrom = (found) => found === void 0 ? void 0 : {
|
|
|
751
779
|
};
|
|
752
780
|
var documentStore = (options) => {
|
|
753
781
|
const table = options.table ?? DEFAULT_DOCUMENT_TABLE;
|
|
754
|
-
const entityColumn = options.columns?.entity ?? DEFAULT_ENTITY_COLUMN2;
|
|
755
782
|
const revisionKindColumn = options.columns?.revisionKind ?? DEFAULT_REVISION_KIND_COLUMN;
|
|
783
|
+
const physical = physicalColumnsOf(options.columns);
|
|
756
784
|
const {
|
|
757
785
|
entity: _entity,
|
|
786
|
+
heads: _heads,
|
|
758
787
|
revisionKind: _revisionKind,
|
|
759
|
-
total,
|
|
788
|
+
total: _total,
|
|
760
789
|
version,
|
|
761
790
|
...entityColumns
|
|
762
791
|
} = options.columns ?? {};
|
|
763
792
|
const versionColumn = nameOf2(version, DEFAULT_VERSION_COLUMN2);
|
|
764
|
-
const
|
|
765
|
-
const tenantColumn = nameOf2(entityColumns.tenant, DEFAULT_TENANT_COLUMN2);
|
|
766
|
-
const createdAtColumn = nameOf2(entityColumns.createdAt, DEFAULT_CREATED_AT_COLUMN);
|
|
793
|
+
const entityColumn = physical.entity;
|
|
767
794
|
const { archive, registry, schema, seam } = options;
|
|
768
795
|
const tenantKey = seam.tenantKey;
|
|
769
796
|
const placed = schema === void 0 ? {} : { schema };
|
|
770
797
|
const revisionsTable = options.revisions === false ? void 0 : options.revisions?.table ?? DEFAULT_REVISIONS_TABLE;
|
|
771
798
|
const tenanted = (tenantId) => ({ [tenantKey]: tenantId });
|
|
772
|
-
const columnOf = (column) => column === "
|
|
773
|
-
const physicalHeads =
|
|
799
|
+
const columnOf = (column) => column === "number" ? "number" : physical[column];
|
|
800
|
+
const physicalHeads = HEAD_FIELDS.map(columnOf);
|
|
801
|
+
const narrowed = (where) => Object.fromEntries(
|
|
802
|
+
Object.entries(where ?? {}).map(([column, held]) => [
|
|
803
|
+
columnOf(column),
|
|
804
|
+
held
|
|
805
|
+
])
|
|
806
|
+
);
|
|
774
807
|
const revisions = revisionsTable === void 0 ? void 0 : (0, import_db2.defineLog)({
|
|
775
|
-
columns: { tenant:
|
|
808
|
+
columns: { tenant: physical.tenant },
|
|
776
809
|
extra: [{ column: revisionKindColumn, param: "kind" }],
|
|
777
810
|
hash: (row) => hashOf({
|
|
778
811
|
actor: row.actor,
|
|
@@ -806,13 +839,13 @@ var documentStore = (options) => {
|
|
|
806
839
|
};
|
|
807
840
|
const readers = (0, import_db2.defineEntity)({
|
|
808
841
|
columns: { ...entityColumns, version: versionColumn },
|
|
809
|
-
filterable: [...physicalHeads, entityColumn,
|
|
842
|
+
filterable: [...physicalHeads, entityColumn, physical.createdAt, physical.updatedAt],
|
|
810
843
|
item: (row) => row,
|
|
811
844
|
key: { column: "number", param: "ref" },
|
|
812
845
|
order: [{ column: "number" }],
|
|
813
846
|
...placed,
|
|
814
847
|
seam,
|
|
815
|
-
sortable: [...physicalHeads, entityColumn, "number"],
|
|
848
|
+
sortable: [...physicalHeads, entityColumn, "number", physical.createdAt, physical.updatedAt],
|
|
816
849
|
table
|
|
817
850
|
});
|
|
818
851
|
const entityStoreFor = (name) => {
|
|
@@ -845,15 +878,25 @@ var documentStore = (options) => {
|
|
|
845
878
|
carried: ["lineage"],
|
|
846
879
|
columns: { ...entityColumns, hash: "hash", sequence: versionColumn },
|
|
847
880
|
constants: { [entityColumn]: name },
|
|
848
|
-
filterable:
|
|
881
|
+
filterable: physicalHeads,
|
|
849
882
|
item,
|
|
850
883
|
key: { column: "number", param: "ref" },
|
|
851
884
|
order: [{ column: "number" }],
|
|
852
885
|
...placed,
|
|
853
886
|
seam,
|
|
854
|
-
sortable:
|
|
887
|
+
sortable: [...physicalHeads, "number", physical.createdAt, physical.updatedAt],
|
|
855
888
|
table
|
|
856
889
|
});
|
|
890
|
+
const list = (handle, params) => projection.list(handle, {
|
|
891
|
+
...params,
|
|
892
|
+
...params.filter === void 0 ? {} : { filter: narrowed(params.filter) },
|
|
893
|
+
...params.order === void 0 ? {} : {
|
|
894
|
+
order: {
|
|
895
|
+
column: columnOf(params.order.column),
|
|
896
|
+
...params.order.direction === void 0 ? {} : { direction: params.order.direction }
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
});
|
|
857
900
|
const locked = async (tx, params) => headFrom(await projection.lockLatest(tx, params));
|
|
858
901
|
const currentLineageOf = async (tx, params) => headFrom(await projection.head(tx, params))?.lineage ?? 1;
|
|
859
902
|
const stream = (params, lineage) => ({
|
|
@@ -1216,7 +1259,7 @@ var documentStore = (options) => {
|
|
|
1216
1259
|
commit,
|
|
1217
1260
|
get: projection.get,
|
|
1218
1261
|
history,
|
|
1219
|
-
list
|
|
1262
|
+
list,
|
|
1220
1263
|
listAll: projection.listAll,
|
|
1221
1264
|
reinstate,
|
|
1222
1265
|
retire,
|
|
@@ -1232,44 +1275,43 @@ var documentStore = (options) => {
|
|
|
1232
1275
|
const restorers = Object.fromEntries(
|
|
1233
1276
|
built.map(([name, one]) => [name, one.restore])
|
|
1234
1277
|
);
|
|
1235
|
-
const heads = seam.scoped(
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1278
|
+
const heads = seam.scoped(
|
|
1279
|
+
async (tx, params) => {
|
|
1280
|
+
const { columns, entity, order, where } = params;
|
|
1281
|
+
const rows = await readers.project(tx, {
|
|
1282
|
+
...tenanted(params[tenantKey]),
|
|
1283
|
+
columns: columns.filter((column) => column !== "number").map(columnOf),
|
|
1284
|
+
order: order.map((one) => ({
|
|
1285
|
+
column: columnOf(one.column),
|
|
1286
|
+
...one.direction === void 0 ? {} : { direction: one.direction }
|
|
1287
|
+
})),
|
|
1288
|
+
where: {
|
|
1289
|
+
...entity === void 0 ? {} : { [entityColumn]: entity },
|
|
1290
|
+
...narrowed(where)
|
|
1291
|
+
}
|
|
1292
|
+
});
|
|
1293
|
+
return rows.map(
|
|
1294
|
+
(row) => Object.fromEntries(
|
|
1295
|
+
columns.map((column) => [column, column === "number" ? row.key : row[columnOf(column)]])
|
|
1296
|
+
)
|
|
1297
|
+
);
|
|
1298
|
+
}
|
|
1299
|
+
);
|
|
1256
1300
|
const aggregate = seam.scoped(
|
|
1257
1301
|
(tx, params) => {
|
|
1258
1302
|
const { by, entities, entity, measures, where } = params;
|
|
1259
1303
|
return readers.aggregate(tx, {
|
|
1260
1304
|
...tenanted(params[tenantKey]),
|
|
1261
1305
|
...by === void 0 ? {} : {
|
|
1262
|
-
by: by === "
|
|
1306
|
+
by: typeof by === "string" ? columnOf(by) : { bucket: by.bucket, of: columnOf(by.of) }
|
|
1263
1307
|
},
|
|
1264
1308
|
measures: measures.map(
|
|
1265
|
-
(one) => one === "sum:total" ? `sum:${
|
|
1309
|
+
(one) => one === "sum:total" ? `sum:${physical.total}` : one
|
|
1266
1310
|
),
|
|
1267
1311
|
where: {
|
|
1268
1312
|
...entity === void 0 ? {} : { [entityColumn]: entity },
|
|
1269
1313
|
...entities === void 0 ? {} : { [entityColumn]: entities },
|
|
1270
|
-
...where
|
|
1271
|
-
...where !== void 0 && "issueDate" in where ? { issueDate: { from: where.issueDate[0], to: where.issueDate[1] } } : {},
|
|
1272
|
-
...where !== void 0 && "createdAt" in where ? { [createdAtColumn]: { from: where.createdAt[0], to: where.createdAt[1] } } : {}
|
|
1314
|
+
...narrowed(where)
|
|
1273
1315
|
}
|
|
1274
1316
|
});
|
|
1275
1317
|
}
|
|
@@ -1314,6 +1356,7 @@ var documentStore = (options) => {
|
|
|
1314
1356
|
DEFAULT_REVISION_KIND_COLUMN,
|
|
1315
1357
|
DOCUMENT_MIGRATION_PLACEHOLDERS,
|
|
1316
1358
|
Document,
|
|
1359
|
+
HEAD_FIELDS,
|
|
1317
1360
|
appendOnlyTables,
|
|
1318
1361
|
canTransition,
|
|
1319
1362
|
canonicalOf,
|
|
@@ -1329,6 +1372,7 @@ var documentStore = (options) => {
|
|
|
1329
1372
|
isSystemActor,
|
|
1330
1373
|
isTerminalStatus,
|
|
1331
1374
|
migrateBody,
|
|
1375
|
+
physicalColumnsOf,
|
|
1332
1376
|
stampBody,
|
|
1333
1377
|
systemActor,
|
|
1334
1378
|
validatorOf
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
export { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
|
-
import { EntityColumns, EntityName, SessionSettings, EntityMigration, Projection, Executor, Query, EntityUndo, SessionSeam } from '@geonosis/db';
|
|
3
|
+
import { EntityColumns, EntityName, FreezeRegister, TenantPolicyNames, SessionSettings, EntityMigration, Projection, Executor, Query, EntityListing, EntityPage, EntityUndo, SessionSeam } from '@geonosis/db';
|
|
4
4
|
export { ENTITY_PLACEHOLDERS as DOCUMENT_MIGRATION_PLACEHOLDERS } from '@geonosis/db';
|
|
5
5
|
|
|
6
6
|
declare const BODY_VERSION_KEY = "_v";
|
|
@@ -259,17 +259,29 @@ type LinkVerifierPort = {
|
|
|
259
259
|
declare const DEFAULT_DOCUMENT_TABLE = "documents";
|
|
260
260
|
declare const DEFAULT_REVISIONS_TABLE = "document_revisions";
|
|
261
261
|
declare const DEFAULT_REVISION_KIND_COLUMN = "revision_kind";
|
|
262
|
+
type HeadField = keyof DocumentHead;
|
|
263
|
+
declare const HEAD_FIELDS: HeadField[];
|
|
262
264
|
type DocumentColumns = EntityColumns & {
|
|
263
265
|
entity?: string;
|
|
266
|
+
heads?: Partial<Record<HeadField, EntityName>>;
|
|
264
267
|
revisionKind?: string;
|
|
265
268
|
total?: EntityName;
|
|
266
269
|
};
|
|
270
|
+
type DocumentPhysicalColumns = Readonly<Record<HeadField, string>> & {
|
|
271
|
+
createdAt: string;
|
|
272
|
+
entity: string;
|
|
273
|
+
tenant: string;
|
|
274
|
+
updatedAt: string;
|
|
275
|
+
};
|
|
276
|
+
declare const physicalColumnsOf: (columns: DocumentColumns | undefined) => DocumentPhysicalColumns;
|
|
267
277
|
type DocumentRevisionsOptions = {
|
|
268
278
|
table?: string;
|
|
269
279
|
};
|
|
270
280
|
type DocumentMigrationsOptions = {
|
|
271
281
|
appRole?: string;
|
|
272
282
|
columns?: DocumentColumns;
|
|
283
|
+
freeze?: FreezeRegister;
|
|
284
|
+
names?: TenantPolicyNames;
|
|
273
285
|
revisions?: DocumentRevisionsOptions | false;
|
|
274
286
|
schema?: string;
|
|
275
287
|
settings: SessionSettings;
|
|
@@ -301,33 +313,32 @@ type DocumentStoreOptions<Map extends Readonly<Record<string, StorableDocumentEn
|
|
|
301
313
|
seam: SessionSeam<Key, Executor>;
|
|
302
314
|
table?: string;
|
|
303
315
|
};
|
|
304
|
-
type HeadColumn =
|
|
316
|
+
type HeadColumn = HeadField | 'entity' | 'number';
|
|
317
|
+
type DocumentSortColumn = HeadField | 'createdAt' | 'number' | 'updatedAt';
|
|
305
318
|
type HeadsOrder = {
|
|
306
|
-
column:
|
|
319
|
+
column: DocumentSortColumn | 'entity';
|
|
307
320
|
direction?: 'asc' | 'desc';
|
|
308
321
|
};
|
|
309
|
-
type HeadsWhere = {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
type
|
|
314
|
-
|
|
322
|
+
type HeadsWhere = Readonly<Partial<Record<HeadField | 'createdAt' | 'updatedAt', unknown | readonly unknown[] | {
|
|
323
|
+
from: unknown;
|
|
324
|
+
to: unknown;
|
|
325
|
+
}>>>;
|
|
326
|
+
type HeadRow<Columns extends readonly HeadColumn[]> = Pick<DocumentHead & {
|
|
327
|
+
entity: string;
|
|
328
|
+
number: string;
|
|
329
|
+
}, Columns[number]>;
|
|
330
|
+
type HeadsArgs<Columns extends readonly HeadColumn[] = readonly HeadColumn[]> = {
|
|
331
|
+
columns: Columns;
|
|
315
332
|
entity?: string | readonly string[];
|
|
316
333
|
order: readonly HeadsOrder[];
|
|
317
334
|
where?: HeadsWhere;
|
|
318
335
|
};
|
|
319
336
|
type AggregateMeasure = 'count' | 'sum:total';
|
|
320
|
-
type AggregateBy =
|
|
337
|
+
type AggregateBy = HeadField | 'entity' | {
|
|
321
338
|
bucket: 'day' | 'month' | 'week';
|
|
322
|
-
of: 'issueDate';
|
|
339
|
+
of: 'dueDate' | 'issueDate';
|
|
323
340
|
};
|
|
324
|
-
type AggregateWhere =
|
|
325
|
-
status?: string;
|
|
326
|
-
} & ({
|
|
327
|
-
createdAt: readonly [number, number];
|
|
328
|
-
} | {
|
|
329
|
-
issueDate: readonly [string, string];
|
|
330
|
-
} | Record<string, never>);
|
|
341
|
+
type AggregateWhere = HeadsWhere;
|
|
331
342
|
type AggregateRow = {
|
|
332
343
|
by?: string;
|
|
333
344
|
count?: number;
|
|
@@ -340,7 +351,6 @@ type AggregateArgs = {
|
|
|
340
351
|
measures: readonly AggregateMeasure[];
|
|
341
352
|
where?: AggregateWhere;
|
|
342
353
|
};
|
|
343
|
-
type SortableHeadColumn = keyof DocumentHead;
|
|
344
354
|
type Item = DocumentInstance<string, unknown>;
|
|
345
355
|
type DocumentKind = 'committed' | 'reinstated' | 'retired';
|
|
346
356
|
type CommitOutput = {
|
|
@@ -393,7 +403,7 @@ type VerifyResult = {
|
|
|
393
403
|
ok: true;
|
|
394
404
|
versions: number;
|
|
395
405
|
};
|
|
396
|
-
type DocumentEntityStore<Key extends string> = Pick<Projection<unknown, Item, Key, 'ref', Executor,
|
|
406
|
+
type DocumentEntityStore<Key extends string> = Pick<Projection<unknown, Item, Key, 'ref', Executor, string, string>, 'get' | 'listAll'> & {
|
|
397
407
|
asOf: Query<Readonly<Record<Key, string>> & {
|
|
398
408
|
at: number;
|
|
399
409
|
ref: string;
|
|
@@ -412,6 +422,7 @@ type DocumentEntityStore<Key extends string> = Pick<Projection<unknown, Item, Ke
|
|
|
412
422
|
lineage?: number;
|
|
413
423
|
ref: string;
|
|
414
424
|
}, HistoryEntry[], Executor>;
|
|
425
|
+
list: Query<Readonly<Record<Key, string>> & EntityListing<DocumentSortColumn, HeadField>, EntityPage<Item>, Executor>;
|
|
415
426
|
reinstate: Query<Readonly<Record<Key, string>> & {
|
|
416
427
|
actor: string;
|
|
417
428
|
reason?: string;
|
|
@@ -441,7 +452,7 @@ type DocumentStore<Map extends Readonly<Record<string, StorableDocumentEntity>>,
|
|
|
441
452
|
[Name in keyof Map & string]: DocumentEntityStore<Key>;
|
|
442
453
|
} & {
|
|
443
454
|
aggregate: Query<Readonly<Record<Key, string>> & AggregateArgs, AggregateRow[], Executor>;
|
|
444
|
-
heads:
|
|
455
|
+
heads: <Columns extends readonly HeadColumn[]>(handle: Executor, params: Readonly<Record<Key, string>> & HeadsArgs<Columns>) => Promise<HeadRow<Columns>[]>;
|
|
445
456
|
rebuild: Query<Readonly<Record<Key, string>> & {
|
|
446
457
|
entity?: string;
|
|
447
458
|
}, {
|
|
@@ -521,4 +532,4 @@ type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentE
|
|
|
521
532
|
*/
|
|
522
533
|
declare const documentSurface: <Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string>(options: DocumentSurfaceOptions<Map, Key>) => SurfaceRow[];
|
|
523
534
|
|
|
524
|
-
export { type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateRow, type AggregateWhere, type AnyDocumentEntity, type AppendOnlyTablesOptions, type ArchivePort, BODY_VERSION_KEY, type BodyOf, type CardOf, type CommitOutput, DEFAULT_DOCUMENT_TABLE, DEFAULT_REVISIONS_TABLE, DEFAULT_REVISION_KIND_COLUMN, Document, type DocumentBodyMigrations, type DocumentBodyVersion, type DocumentColumns, type DocumentDefinition, type DocumentEntity, type DocumentHead, type DocumentInstance, type DocumentKind, type DocumentMigrationsOptions, type DocumentNumbering, type DocumentRecord, type DocumentRevisionsOptions, type DocumentStatusMachine, type DocumentStore, type DocumentStoreOptions, type DocumentSurfaceOptions, type DraftOf, type FieldKind, type HeadColumn, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type IncomingOf, type InstanceOf, type LinkVerifierPort, type NameOf, type PendingCall, type ReinstateOutput, type RetireOutput, type StatusOf, type SurfaceCall, type SurfaceRow, type SurfaceSchemaAdapter, type SurfaceScope, type SurfaceVerb, type TimestampPort, type VerifyResult, type ViewOf, appendOnlyTables, canTransition, canonicalOf, documentBodyVersioning, documentEntities, documentIdentifiers, documentMigrations, documentRoleStatements, documentStore, documentSurface, fieldPatterns, hashOf, isSystemActor, isTerminalStatus, migrateBody, stampBody, systemActor, validatorOf };
|
|
535
|
+
export { type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateRow, type AggregateWhere, type AnyDocumentEntity, type AppendOnlyTablesOptions, type ArchivePort, BODY_VERSION_KEY, type BodyOf, type CardOf, type CommitOutput, DEFAULT_DOCUMENT_TABLE, DEFAULT_REVISIONS_TABLE, DEFAULT_REVISION_KIND_COLUMN, Document, type DocumentBodyMigrations, type DocumentBodyVersion, type DocumentColumns, type DocumentDefinition, type DocumentEntity, type DocumentHead, type DocumentInstance, type DocumentKind, type DocumentMigrationsOptions, type DocumentNumbering, type DocumentPhysicalColumns, type DocumentRecord, type DocumentRevisionsOptions, type DocumentSortColumn, type DocumentStatusMachine, type DocumentStore, type DocumentStoreOptions, type DocumentSurfaceOptions, type DraftOf, type FieldKind, HEAD_FIELDS, type HeadColumn, type HeadField, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type IncomingOf, type InstanceOf, type LinkVerifierPort, type NameOf, type PendingCall, type ReinstateOutput, type RetireOutput, type StatusOf, type SurfaceCall, type SurfaceRow, type SurfaceSchemaAdapter, type SurfaceScope, type SurfaceVerb, type TimestampPort, type VerifyResult, type ViewOf, appendOnlyTables, canTransition, canonicalOf, documentBodyVersioning, documentEntities, documentIdentifiers, documentMigrations, documentRoleStatements, documentStore, documentSurface, fieldPatterns, hashOf, isSystemActor, isTerminalStatus, migrateBody, physicalColumnsOf, stampBody, systemActor, validatorOf };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
export { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
|
-
import { EntityColumns, EntityName, SessionSettings, EntityMigration, Projection, Executor, Query, EntityUndo, SessionSeam } from '@geonosis/db';
|
|
3
|
+
import { EntityColumns, EntityName, FreezeRegister, TenantPolicyNames, SessionSettings, EntityMigration, Projection, Executor, Query, EntityListing, EntityPage, EntityUndo, SessionSeam } from '@geonosis/db';
|
|
4
4
|
export { ENTITY_PLACEHOLDERS as DOCUMENT_MIGRATION_PLACEHOLDERS } from '@geonosis/db';
|
|
5
5
|
|
|
6
6
|
declare const BODY_VERSION_KEY = "_v";
|
|
@@ -259,17 +259,29 @@ type LinkVerifierPort = {
|
|
|
259
259
|
declare const DEFAULT_DOCUMENT_TABLE = "documents";
|
|
260
260
|
declare const DEFAULT_REVISIONS_TABLE = "document_revisions";
|
|
261
261
|
declare const DEFAULT_REVISION_KIND_COLUMN = "revision_kind";
|
|
262
|
+
type HeadField = keyof DocumentHead;
|
|
263
|
+
declare const HEAD_FIELDS: HeadField[];
|
|
262
264
|
type DocumentColumns = EntityColumns & {
|
|
263
265
|
entity?: string;
|
|
266
|
+
heads?: Partial<Record<HeadField, EntityName>>;
|
|
264
267
|
revisionKind?: string;
|
|
265
268
|
total?: EntityName;
|
|
266
269
|
};
|
|
270
|
+
type DocumentPhysicalColumns = Readonly<Record<HeadField, string>> & {
|
|
271
|
+
createdAt: string;
|
|
272
|
+
entity: string;
|
|
273
|
+
tenant: string;
|
|
274
|
+
updatedAt: string;
|
|
275
|
+
};
|
|
276
|
+
declare const physicalColumnsOf: (columns: DocumentColumns | undefined) => DocumentPhysicalColumns;
|
|
267
277
|
type DocumentRevisionsOptions = {
|
|
268
278
|
table?: string;
|
|
269
279
|
};
|
|
270
280
|
type DocumentMigrationsOptions = {
|
|
271
281
|
appRole?: string;
|
|
272
282
|
columns?: DocumentColumns;
|
|
283
|
+
freeze?: FreezeRegister;
|
|
284
|
+
names?: TenantPolicyNames;
|
|
273
285
|
revisions?: DocumentRevisionsOptions | false;
|
|
274
286
|
schema?: string;
|
|
275
287
|
settings: SessionSettings;
|
|
@@ -301,33 +313,32 @@ type DocumentStoreOptions<Map extends Readonly<Record<string, StorableDocumentEn
|
|
|
301
313
|
seam: SessionSeam<Key, Executor>;
|
|
302
314
|
table?: string;
|
|
303
315
|
};
|
|
304
|
-
type HeadColumn =
|
|
316
|
+
type HeadColumn = HeadField | 'entity' | 'number';
|
|
317
|
+
type DocumentSortColumn = HeadField | 'createdAt' | 'number' | 'updatedAt';
|
|
305
318
|
type HeadsOrder = {
|
|
306
|
-
column:
|
|
319
|
+
column: DocumentSortColumn | 'entity';
|
|
307
320
|
direction?: 'asc' | 'desc';
|
|
308
321
|
};
|
|
309
|
-
type HeadsWhere = {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
type
|
|
314
|
-
|
|
322
|
+
type HeadsWhere = Readonly<Partial<Record<HeadField | 'createdAt' | 'updatedAt', unknown | readonly unknown[] | {
|
|
323
|
+
from: unknown;
|
|
324
|
+
to: unknown;
|
|
325
|
+
}>>>;
|
|
326
|
+
type HeadRow<Columns extends readonly HeadColumn[]> = Pick<DocumentHead & {
|
|
327
|
+
entity: string;
|
|
328
|
+
number: string;
|
|
329
|
+
}, Columns[number]>;
|
|
330
|
+
type HeadsArgs<Columns extends readonly HeadColumn[] = readonly HeadColumn[]> = {
|
|
331
|
+
columns: Columns;
|
|
315
332
|
entity?: string | readonly string[];
|
|
316
333
|
order: readonly HeadsOrder[];
|
|
317
334
|
where?: HeadsWhere;
|
|
318
335
|
};
|
|
319
336
|
type AggregateMeasure = 'count' | 'sum:total';
|
|
320
|
-
type AggregateBy =
|
|
337
|
+
type AggregateBy = HeadField | 'entity' | {
|
|
321
338
|
bucket: 'day' | 'month' | 'week';
|
|
322
|
-
of: 'issueDate';
|
|
339
|
+
of: 'dueDate' | 'issueDate';
|
|
323
340
|
};
|
|
324
|
-
type AggregateWhere =
|
|
325
|
-
status?: string;
|
|
326
|
-
} & ({
|
|
327
|
-
createdAt: readonly [number, number];
|
|
328
|
-
} | {
|
|
329
|
-
issueDate: readonly [string, string];
|
|
330
|
-
} | Record<string, never>);
|
|
341
|
+
type AggregateWhere = HeadsWhere;
|
|
331
342
|
type AggregateRow = {
|
|
332
343
|
by?: string;
|
|
333
344
|
count?: number;
|
|
@@ -340,7 +351,6 @@ type AggregateArgs = {
|
|
|
340
351
|
measures: readonly AggregateMeasure[];
|
|
341
352
|
where?: AggregateWhere;
|
|
342
353
|
};
|
|
343
|
-
type SortableHeadColumn = keyof DocumentHead;
|
|
344
354
|
type Item = DocumentInstance<string, unknown>;
|
|
345
355
|
type DocumentKind = 'committed' | 'reinstated' | 'retired';
|
|
346
356
|
type CommitOutput = {
|
|
@@ -393,7 +403,7 @@ type VerifyResult = {
|
|
|
393
403
|
ok: true;
|
|
394
404
|
versions: number;
|
|
395
405
|
};
|
|
396
|
-
type DocumentEntityStore<Key extends string> = Pick<Projection<unknown, Item, Key, 'ref', Executor,
|
|
406
|
+
type DocumentEntityStore<Key extends string> = Pick<Projection<unknown, Item, Key, 'ref', Executor, string, string>, 'get' | 'listAll'> & {
|
|
397
407
|
asOf: Query<Readonly<Record<Key, string>> & {
|
|
398
408
|
at: number;
|
|
399
409
|
ref: string;
|
|
@@ -412,6 +422,7 @@ type DocumentEntityStore<Key extends string> = Pick<Projection<unknown, Item, Ke
|
|
|
412
422
|
lineage?: number;
|
|
413
423
|
ref: string;
|
|
414
424
|
}, HistoryEntry[], Executor>;
|
|
425
|
+
list: Query<Readonly<Record<Key, string>> & EntityListing<DocumentSortColumn, HeadField>, EntityPage<Item>, Executor>;
|
|
415
426
|
reinstate: Query<Readonly<Record<Key, string>> & {
|
|
416
427
|
actor: string;
|
|
417
428
|
reason?: string;
|
|
@@ -441,7 +452,7 @@ type DocumentStore<Map extends Readonly<Record<string, StorableDocumentEntity>>,
|
|
|
441
452
|
[Name in keyof Map & string]: DocumentEntityStore<Key>;
|
|
442
453
|
} & {
|
|
443
454
|
aggregate: Query<Readonly<Record<Key, string>> & AggregateArgs, AggregateRow[], Executor>;
|
|
444
|
-
heads:
|
|
455
|
+
heads: <Columns extends readonly HeadColumn[]>(handle: Executor, params: Readonly<Record<Key, string>> & HeadsArgs<Columns>) => Promise<HeadRow<Columns>[]>;
|
|
445
456
|
rebuild: Query<Readonly<Record<Key, string>> & {
|
|
446
457
|
entity?: string;
|
|
447
458
|
}, {
|
|
@@ -521,4 +532,4 @@ type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentE
|
|
|
521
532
|
*/
|
|
522
533
|
declare const documentSurface: <Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string>(options: DocumentSurfaceOptions<Map, Key>) => SurfaceRow[];
|
|
523
534
|
|
|
524
|
-
export { type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateRow, type AggregateWhere, type AnyDocumentEntity, type AppendOnlyTablesOptions, type ArchivePort, BODY_VERSION_KEY, type BodyOf, type CardOf, type CommitOutput, DEFAULT_DOCUMENT_TABLE, DEFAULT_REVISIONS_TABLE, DEFAULT_REVISION_KIND_COLUMN, Document, type DocumentBodyMigrations, type DocumentBodyVersion, type DocumentColumns, type DocumentDefinition, type DocumentEntity, type DocumentHead, type DocumentInstance, type DocumentKind, type DocumentMigrationsOptions, type DocumentNumbering, type DocumentRecord, type DocumentRevisionsOptions, type DocumentStatusMachine, type DocumentStore, type DocumentStoreOptions, type DocumentSurfaceOptions, type DraftOf, type FieldKind, type HeadColumn, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type IncomingOf, type InstanceOf, type LinkVerifierPort, type NameOf, type PendingCall, type ReinstateOutput, type RetireOutput, type StatusOf, type SurfaceCall, type SurfaceRow, type SurfaceSchemaAdapter, type SurfaceScope, type SurfaceVerb, type TimestampPort, type VerifyResult, type ViewOf, appendOnlyTables, canTransition, canonicalOf, documentBodyVersioning, documentEntities, documentIdentifiers, documentMigrations, documentRoleStatements, documentStore, documentSurface, fieldPatterns, hashOf, isSystemActor, isTerminalStatus, migrateBody, stampBody, systemActor, validatorOf };
|
|
535
|
+
export { type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateRow, type AggregateWhere, type AnyDocumentEntity, type AppendOnlyTablesOptions, type ArchivePort, BODY_VERSION_KEY, type BodyOf, type CardOf, type CommitOutput, DEFAULT_DOCUMENT_TABLE, DEFAULT_REVISIONS_TABLE, DEFAULT_REVISION_KIND_COLUMN, Document, type DocumentBodyMigrations, type DocumentBodyVersion, type DocumentColumns, type DocumentDefinition, type DocumentEntity, type DocumentHead, type DocumentInstance, type DocumentKind, type DocumentMigrationsOptions, type DocumentNumbering, type DocumentPhysicalColumns, type DocumentRecord, type DocumentRevisionsOptions, type DocumentSortColumn, type DocumentStatusMachine, type DocumentStore, type DocumentStoreOptions, type DocumentSurfaceOptions, type DraftOf, type FieldKind, HEAD_FIELDS, type HeadColumn, type HeadField, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type IncomingOf, type InstanceOf, type LinkVerifierPort, type NameOf, type PendingCall, type ReinstateOutput, type RetireOutput, type StatusOf, type SurfaceCall, type SurfaceRow, type SurfaceSchemaAdapter, type SurfaceScope, type SurfaceVerb, type TimestampPort, type VerifyResult, type ViewOf, appendOnlyTables, canTransition, canonicalOf, documentBodyVersioning, documentEntities, documentIdentifiers, documentMigrations, documentRoleStatements, documentStore, documentSurface, fieldPatterns, hashOf, isSystemActor, isTerminalStatus, migrateBody, physicalColumnsOf, stampBody, systemActor, validatorOf };
|
package/dist/index.js
CHANGED
|
@@ -273,6 +273,7 @@ var doorFor = (store, name) => {
|
|
|
273
273
|
return door;
|
|
274
274
|
};
|
|
275
275
|
var HEAD_COLUMNS = Object.keys(Document.headFields);
|
|
276
|
+
var SORT_COLUMNS = [...HEAD_COLUMNS, "number", "createdAt", "updatedAt"];
|
|
276
277
|
var rowsFor = (definition, store, schema) => {
|
|
277
278
|
const { name } = definition;
|
|
278
279
|
const door = doorFor(store, name);
|
|
@@ -335,7 +336,7 @@ var rowsFor = (definition, store, schema) => {
|
|
|
335
336
|
limit: optional(numberSchema),
|
|
336
337
|
order: optional(
|
|
337
338
|
schema.object({
|
|
338
|
-
column: schema.enum(
|
|
339
|
+
column: schema.enum(SORT_COLUMNS),
|
|
339
340
|
direction: optional(schema.enum(["asc", "desc"]))
|
|
340
341
|
})
|
|
341
342
|
)
|
|
@@ -509,13 +510,11 @@ var documentSurface = (options) => {
|
|
|
509
510
|
entity: optional(schema.union([stringSchema, arrayOf(stringSchema)])),
|
|
510
511
|
order: arrayOf(
|
|
511
512
|
schema.object({
|
|
512
|
-
column: schema.enum(
|
|
513
|
+
column: schema.enum([...SORT_COLUMNS, "entity"]),
|
|
513
514
|
direction: optional(schema.enum(["asc", "desc"]))
|
|
514
515
|
})
|
|
515
516
|
),
|
|
516
|
-
where: optional(
|
|
517
|
-
schema.object({ createdAt: optional(arrayOf(numberSchema)), status: optional(stringSchema) })
|
|
518
|
-
)
|
|
517
|
+
where: optional(unknownSchema)
|
|
519
518
|
});
|
|
520
519
|
const aggregateInput = schema.object({
|
|
521
520
|
by: optional(unknownSchema),
|
|
@@ -578,12 +577,33 @@ import {
|
|
|
578
577
|
var DEFAULT_DOCUMENT_TABLE = "documents";
|
|
579
578
|
var DEFAULT_ENTITY_COLUMN = "entity";
|
|
580
579
|
var DEFAULT_VERSION_COLUMN = "version";
|
|
581
|
-
var DEFAULT_TOTAL_COLUMN = "total";
|
|
582
580
|
var DEFAULT_TENANT_COLUMN = "tenant_id";
|
|
581
|
+
var DEFAULT_CREATED_AT_COLUMN = "created_at";
|
|
582
|
+
var DEFAULT_UPDATED_AT_COLUMN = "updated_at";
|
|
583
583
|
var DEFAULT_REVISIONS_TABLE = "document_revisions";
|
|
584
584
|
var DEFAULT_REVISION_KIND_COLUMN = "revision_kind";
|
|
585
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()}`);
|
|
586
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
|
+
};
|
|
587
607
|
var appendOnlyTables = (options = {}) => {
|
|
588
608
|
if (options.revisions === false) return [];
|
|
589
609
|
return [options.revisions?.table ?? options.table ?? DEFAULT_REVISIONS_TABLE];
|
|
@@ -604,13 +624,21 @@ var documentRoleStatements = (appRole, options = {}) => {
|
|
|
604
624
|
]);
|
|
605
625
|
};
|
|
606
626
|
var DDL_TYPE_OF = { decimal: "numeric" };
|
|
607
|
-
var headIndexedColumns = (
|
|
608
|
-
const
|
|
609
|
-
|
|
610
|
-
|
|
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
|
+
};
|
|
611
634
|
});
|
|
612
635
|
var revisionKindType = (column) => `text check (${quotedName(column)} in (${REVISION_KINDS.map(literalName).join(", ")}))`;
|
|
613
|
-
var
|
|
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) => {
|
|
614
642
|
if (options.revisions === false) return [];
|
|
615
643
|
if (typeof options.appRole !== "string" || options.appRole === "") {
|
|
616
644
|
throw new DbRefusal(
|
|
@@ -621,10 +649,10 @@ var revisionsMigrations = (options, entityColumn, tenantColumn) => {
|
|
|
621
649
|
const table = options.revisions?.table ?? DEFAULT_REVISIONS_TABLE;
|
|
622
650
|
const [tableMigration, policies] = logMigrations({
|
|
623
651
|
appRole: options.appRole,
|
|
624
|
-
columns: { tenant:
|
|
652
|
+
columns: { tenant: physical.tenant },
|
|
625
653
|
extra: [{ column: revisionKindColumn, type: revisionKindType(revisionKindColumn) }],
|
|
626
|
-
key: [
|
|
627
|
-
...options
|
|
654
|
+
key: [physical.entity, "ref", { column: "lineage", type: "integer" }],
|
|
655
|
+
...walls(options),
|
|
628
656
|
settings: options.settings,
|
|
629
657
|
table
|
|
630
658
|
});
|
|
@@ -638,11 +666,10 @@ var revisionsMigrations = (options, entityColumn, tenantColumn) => {
|
|
|
638
666
|
};
|
|
639
667
|
var documentMigrations = (options) => {
|
|
640
668
|
const table = options.table ?? DEFAULT_DOCUMENT_TABLE;
|
|
641
|
-
const
|
|
642
|
-
const totalColumn = nameOf(options.columns?.total, DEFAULT_TOTAL_COLUMN);
|
|
643
|
-
const tenantColumn = nameOf(options.columns?.tenant, DEFAULT_TENANT_COLUMN);
|
|
669
|
+
const physical = physicalColumnsOf(options.columns);
|
|
644
670
|
const {
|
|
645
671
|
entity: _entity,
|
|
672
|
+
heads: _heads,
|
|
646
673
|
revisionKind: _revisionKind,
|
|
647
674
|
total: _total,
|
|
648
675
|
version,
|
|
@@ -651,13 +678,17 @@ var documentMigrations = (options) => {
|
|
|
651
678
|
const [tableMigration, ...rest] = projectionMigrations({
|
|
652
679
|
carried: [{ column: "lineage", type: "integer not null default 1" }],
|
|
653
680
|
columns: { ...restColumns, sequence: version ?? DEFAULT_VERSION_COLUMN },
|
|
654
|
-
constants: { [
|
|
655
|
-
indexed: headIndexedColumns(
|
|
681
|
+
constants: { [physical.entity]: "" },
|
|
682
|
+
indexed: headIndexedColumns(physical),
|
|
656
683
|
key: "number",
|
|
657
684
|
order: [{ column: "number" }],
|
|
658
|
-
...options
|
|
685
|
+
...walls(options),
|
|
659
686
|
settings: options.settings,
|
|
660
|
-
sortable:
|
|
687
|
+
sortable: [
|
|
688
|
+
...HEAD_FIELDS.map((field) => physical[field]),
|
|
689
|
+
physical.createdAt,
|
|
690
|
+
physical.updatedAt
|
|
691
|
+
],
|
|
661
692
|
table
|
|
662
693
|
});
|
|
663
694
|
if (tableMigration === void 0) {
|
|
@@ -665,11 +696,11 @@ var documentMigrations = (options) => {
|
|
|
665
696
|
"projectionMigrations answered with no table migration to append the listing index to"
|
|
666
697
|
);
|
|
667
698
|
}
|
|
668
|
-
const listingIndex = `create index if not exists ${quotedName(`${table}_${
|
|
699
|
+
const listingIndex = `create index if not exists ${quotedName(`${table}_${physical.entity}_${physical.issueDate}_idx`)} on ${quotedName(table)} (${quotedName(physical.entity)}, ${quotedName(physical.issueDate)})`;
|
|
669
700
|
return [
|
|
670
701
|
{ ...tableMigration, statements: [...tableMigration.statements, listingIndex] },
|
|
671
702
|
...rest,
|
|
672
|
-
...revisionsMigrations(options,
|
|
703
|
+
...revisionsMigrations(options, physical)
|
|
673
704
|
];
|
|
674
705
|
};
|
|
675
706
|
|
|
@@ -680,11 +711,7 @@ import {
|
|
|
680
711
|
defineLog,
|
|
681
712
|
projectionOf
|
|
682
713
|
} from "@geonosis/db";
|
|
683
|
-
var DEFAULT_ENTITY_COLUMN2 = "entity";
|
|
684
714
|
var DEFAULT_VERSION_COLUMN2 = "version";
|
|
685
|
-
var DEFAULT_TOTAL_COLUMN2 = "total";
|
|
686
|
-
var DEFAULT_TENANT_COLUMN2 = "tenant_id";
|
|
687
|
-
var DEFAULT_CREATED_AT_COLUMN = "created_at";
|
|
688
715
|
var UNDO_ACTOR = systemActor("document.undo");
|
|
689
716
|
var nameOf2 = (value, fallback) => value === void 0 ? fallback : typeof value === "string" ? value : value.name;
|
|
690
717
|
var readBody = (entity, entityName, ref, stored) => {
|
|
@@ -702,7 +729,6 @@ var readBody = (entity, entityName, ref, stored) => {
|
|
|
702
729
|
}
|
|
703
730
|
return result.value;
|
|
704
731
|
};
|
|
705
|
-
var HEAD_COLUMNS2 = Object.keys(headFields);
|
|
706
732
|
var headFrom = (found) => found === void 0 ? void 0 : {
|
|
707
733
|
body: found.body,
|
|
708
734
|
hash: found.hash,
|
|
@@ -712,28 +738,33 @@ var headFrom = (found) => found === void 0 ? void 0 : {
|
|
|
712
738
|
};
|
|
713
739
|
var documentStore = (options) => {
|
|
714
740
|
const table = options.table ?? DEFAULT_DOCUMENT_TABLE;
|
|
715
|
-
const entityColumn = options.columns?.entity ?? DEFAULT_ENTITY_COLUMN2;
|
|
716
741
|
const revisionKindColumn = options.columns?.revisionKind ?? DEFAULT_REVISION_KIND_COLUMN;
|
|
742
|
+
const physical = physicalColumnsOf(options.columns);
|
|
717
743
|
const {
|
|
718
744
|
entity: _entity,
|
|
745
|
+
heads: _heads,
|
|
719
746
|
revisionKind: _revisionKind,
|
|
720
|
-
total,
|
|
747
|
+
total: _total,
|
|
721
748
|
version,
|
|
722
749
|
...entityColumns
|
|
723
750
|
} = options.columns ?? {};
|
|
724
751
|
const versionColumn = nameOf2(version, DEFAULT_VERSION_COLUMN2);
|
|
725
|
-
const
|
|
726
|
-
const tenantColumn = nameOf2(entityColumns.tenant, DEFAULT_TENANT_COLUMN2);
|
|
727
|
-
const createdAtColumn = nameOf2(entityColumns.createdAt, DEFAULT_CREATED_AT_COLUMN);
|
|
752
|
+
const entityColumn = physical.entity;
|
|
728
753
|
const { archive, registry, schema, seam } = options;
|
|
729
754
|
const tenantKey = seam.tenantKey;
|
|
730
755
|
const placed = schema === void 0 ? {} : { schema };
|
|
731
756
|
const revisionsTable = options.revisions === false ? void 0 : options.revisions?.table ?? DEFAULT_REVISIONS_TABLE;
|
|
732
757
|
const tenanted = (tenantId) => ({ [tenantKey]: tenantId });
|
|
733
|
-
const columnOf = (column) => column === "
|
|
734
|
-
const physicalHeads =
|
|
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
|
+
);
|
|
735
766
|
const revisions = revisionsTable === void 0 ? void 0 : defineLog({
|
|
736
|
-
columns: { tenant:
|
|
767
|
+
columns: { tenant: physical.tenant },
|
|
737
768
|
extra: [{ column: revisionKindColumn, param: "kind" }],
|
|
738
769
|
hash: (row) => hashOf({
|
|
739
770
|
actor: row.actor,
|
|
@@ -767,13 +798,13 @@ var documentStore = (options) => {
|
|
|
767
798
|
};
|
|
768
799
|
const readers = defineEntity({
|
|
769
800
|
columns: { ...entityColumns, version: versionColumn },
|
|
770
|
-
filterable: [...physicalHeads, entityColumn,
|
|
801
|
+
filterable: [...physicalHeads, entityColumn, physical.createdAt, physical.updatedAt],
|
|
771
802
|
item: (row) => row,
|
|
772
803
|
key: { column: "number", param: "ref" },
|
|
773
804
|
order: [{ column: "number" }],
|
|
774
805
|
...placed,
|
|
775
806
|
seam,
|
|
776
|
-
sortable: [...physicalHeads, entityColumn, "number"],
|
|
807
|
+
sortable: [...physicalHeads, entityColumn, "number", physical.createdAt, physical.updatedAt],
|
|
777
808
|
table
|
|
778
809
|
});
|
|
779
810
|
const entityStoreFor = (name) => {
|
|
@@ -806,15 +837,25 @@ var documentStore = (options) => {
|
|
|
806
837
|
carried: ["lineage"],
|
|
807
838
|
columns: { ...entityColumns, hash: "hash", sequence: versionColumn },
|
|
808
839
|
constants: { [entityColumn]: name },
|
|
809
|
-
filterable:
|
|
840
|
+
filterable: physicalHeads,
|
|
810
841
|
item,
|
|
811
842
|
key: { column: "number", param: "ref" },
|
|
812
843
|
order: [{ column: "number" }],
|
|
813
844
|
...placed,
|
|
814
845
|
seam,
|
|
815
|
-
sortable:
|
|
846
|
+
sortable: [...physicalHeads, "number", physical.createdAt, physical.updatedAt],
|
|
816
847
|
table
|
|
817
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
|
+
});
|
|
818
859
|
const locked = async (tx, params) => headFrom(await projection.lockLatest(tx, params));
|
|
819
860
|
const currentLineageOf = async (tx, params) => headFrom(await projection.head(tx, params))?.lineage ?? 1;
|
|
820
861
|
const stream = (params, lineage) => ({
|
|
@@ -1177,7 +1218,7 @@ var documentStore = (options) => {
|
|
|
1177
1218
|
commit,
|
|
1178
1219
|
get: projection.get,
|
|
1179
1220
|
history,
|
|
1180
|
-
list
|
|
1221
|
+
list,
|
|
1181
1222
|
listAll: projection.listAll,
|
|
1182
1223
|
reinstate,
|
|
1183
1224
|
retire,
|
|
@@ -1193,44 +1234,43 @@ var documentStore = (options) => {
|
|
|
1193
1234
|
const restorers = Object.fromEntries(
|
|
1194
1235
|
built.map(([name, one]) => [name, one.restore])
|
|
1195
1236
|
);
|
|
1196
|
-
const heads = seam.scoped(
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
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
|
+
);
|
|
1217
1259
|
const aggregate = seam.scoped(
|
|
1218
1260
|
(tx, params) => {
|
|
1219
1261
|
const { by, entities, entity, measures, where } = params;
|
|
1220
1262
|
return readers.aggregate(tx, {
|
|
1221
1263
|
...tenanted(params[tenantKey]),
|
|
1222
1264
|
...by === void 0 ? {} : {
|
|
1223
|
-
by: by === "
|
|
1265
|
+
by: typeof by === "string" ? columnOf(by) : { bucket: by.bucket, of: columnOf(by.of) }
|
|
1224
1266
|
},
|
|
1225
1267
|
measures: measures.map(
|
|
1226
|
-
(one) => one === "sum:total" ? `sum:${
|
|
1268
|
+
(one) => one === "sum:total" ? `sum:${physical.total}` : one
|
|
1227
1269
|
),
|
|
1228
1270
|
where: {
|
|
1229
1271
|
...entity === void 0 ? {} : { [entityColumn]: entity },
|
|
1230
1272
|
...entities === void 0 ? {} : { [entityColumn]: entities },
|
|
1231
|
-
...where
|
|
1232
|
-
...where !== void 0 && "issueDate" in where ? { issueDate: { from: where.issueDate[0], to: where.issueDate[1] } } : {},
|
|
1233
|
-
...where !== void 0 && "createdAt" in where ? { [createdAtColumn]: { from: where.createdAt[0], to: where.createdAt[1] } } : {}
|
|
1273
|
+
...narrowed(where)
|
|
1234
1274
|
}
|
|
1235
1275
|
});
|
|
1236
1276
|
}
|
|
@@ -1274,6 +1314,7 @@ export {
|
|
|
1274
1314
|
DEFAULT_REVISION_KIND_COLUMN,
|
|
1275
1315
|
ENTITY_PLACEHOLDERS as DOCUMENT_MIGRATION_PLACEHOLDERS,
|
|
1276
1316
|
Document,
|
|
1317
|
+
HEAD_FIELDS,
|
|
1277
1318
|
appendOnlyTables,
|
|
1278
1319
|
canTransition,
|
|
1279
1320
|
canonicalOf,
|
|
@@ -1289,6 +1330,7 @@ export {
|
|
|
1289
1330
|
isSystemActor,
|
|
1290
1331
|
isTerminalStatus,
|
|
1291
1332
|
migrateBody,
|
|
1333
|
+
physicalColumnsOf,
|
|
1292
1334
|
stampBody,
|
|
1293
1335
|
systemActor,
|
|
1294
1336
|
validatorOf
|
|
@@ -7,11 +7,11 @@ create table if not exists "documents" (
|
|
|
7
7
|
"updated_at" bigint not null,
|
|
8
8
|
"retired_at" bigint,
|
|
9
9
|
"version" integer not null default 1,
|
|
10
|
-
"status" text,
|
|
11
|
-
"
|
|
12
|
-
"
|
|
10
|
+
"status" text not null,
|
|
11
|
+
"issue_date" text,
|
|
12
|
+
"due_date" text,
|
|
13
13
|
"counterparty" text,
|
|
14
|
-
"
|
|
14
|
+
"external_ref" text,
|
|
15
15
|
"revision" text,
|
|
16
16
|
"total" numeric,
|
|
17
17
|
constraint "documents_pkey" primary key ("tenant_id", "entity", "number")
|
|
@@ -19,38 +19,46 @@ create table if not exists "documents" (
|
|
|
19
19
|
|
|
20
20
|
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
21
21
|
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
22
|
-
create index if not exists "documents_listing_idx" on "documents" ("tenant_id", "number" asc);
|
|
22
|
+
create index if not exists "documents_listing_idx" on "documents" ("tenant_id", "entity", "number" asc);
|
|
23
23
|
|
|
24
24
|
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
25
25
|
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
26
|
-
create index if not exists "documents_by_status_idx" on "documents" ("tenant_id", "status" asc, "number" asc);
|
|
26
|
+
create index if not exists "documents_by_status_idx" on "documents" ("tenant_id", "entity", "status" asc, "number" asc);
|
|
27
27
|
|
|
28
28
|
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
29
29
|
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
30
|
-
create index if not exists "
|
|
30
|
+
create index if not exists "documents_by_issue_date_idx" on "documents" ("tenant_id", "entity", "issue_date" asc, "number" asc);
|
|
31
31
|
|
|
32
32
|
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
33
33
|
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
34
|
-
create index if not exists "
|
|
34
|
+
create index if not exists "documents_by_due_date_idx" on "documents" ("tenant_id", "entity", "due_date" asc, "number" asc);
|
|
35
35
|
|
|
36
36
|
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
37
37
|
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
38
|
-
create index if not exists "documents_by_counterparty_idx" on "documents" ("tenant_id", "counterparty" asc, "number" asc);
|
|
38
|
+
create index if not exists "documents_by_counterparty_idx" on "documents" ("tenant_id", "entity", "counterparty" asc, "number" asc);
|
|
39
39
|
|
|
40
40
|
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
41
41
|
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
42
|
-
create index if not exists "
|
|
42
|
+
create index if not exists "documents_by_external_ref_idx" on "documents" ("tenant_id", "entity", "external_ref" asc, "number" asc);
|
|
43
43
|
|
|
44
44
|
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
45
45
|
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
46
|
-
create index if not exists "documents_by_revision_idx" on "documents" ("tenant_id", "revision" asc, "number" asc);
|
|
46
|
+
create index if not exists "documents_by_revision_idx" on "documents" ("tenant_id", "entity", "revision" asc, "number" asc);
|
|
47
47
|
|
|
48
48
|
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
49
49
|
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
50
|
-
create index if not exists "documents_by_total_idx" on "documents" ("tenant_id", "total" asc, "number" asc);
|
|
50
|
+
create index if not exists "documents_by_total_idx" on "documents" ("tenant_id", "entity", "total" asc, "number" asc);
|
|
51
|
+
|
|
52
|
+
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
53
|
+
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
54
|
+
create index if not exists "documents_by_created_at_idx" on "documents" ("tenant_id", "entity", "created_at" asc, "number" asc);
|
|
55
|
+
|
|
56
|
+
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
57
|
+
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
58
|
+
create index if not exists "documents_by_updated_at_idx" on "documents" ("tenant_id", "entity", "updated_at" asc, "number" asc);
|
|
51
59
|
|
|
52
60
|
alter table "documents" add column if not exists "hash" text;
|
|
53
61
|
|
|
54
62
|
alter table "documents" add column if not exists "lineage" integer not null default 1;
|
|
55
63
|
|
|
56
|
-
create index if not exists "
|
|
64
|
+
create index if not exists "documents_entity_issue_date_idx" on "documents" ("entity", "issue_date");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geonosis/document",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"types": "./dist/index.d.ts",
|
|
5
5
|
"description": "The abstract Document: an entity-first base every kind of paper-trail record extends, a derived entity registry whose name union keeps every consumer map total, and per-entity body versioning — engine-free, SQL-free, the pure core the store, the workflows and the wire contract build on.",
|
|
6
6
|
"keywords": [
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@standard-schema/spec": "^1.1.0",
|
|
42
|
-
"@geonosis/db": "^0.
|
|
42
|
+
"@geonosis/db": "^0.10.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"embedded-postgres-17": "npm:embedded-postgres@17.10.0-beta.17",
|