@geonosis/document 0.3.0 → 0.4.1

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 CHANGED
@@ -1,5 +1,39 @@
1
1
  # @geonosis/document
2
2
 
3
+ ## 0.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - cdc88fc: `documentStore<Map, Key, Handle = Executor>({ seam: SessionSeam<Key, Handle> })` — every door and
8
+ both undos are typed over the consumer's own handle, the way `defineEntity`, `defineLog` and
9
+ `projectionOf` already are; a seam opened over a drizzle database hands in without a cast (#433).
10
+ `DocumentStore` and `DocumentStoreOptions` gain the third type parameter.
11
+
12
+ ## 0.4.0
13
+
14
+ ### Minor Changes
15
+
16
+ - 748795d: 0.4.0, read off the consumer's own callers (#427–#430). Head columns are snake by default
17
+ (`issue_date`, `due_date`, `external_ref`; `columns.heads` renames any, `physicalColumnsOf` is the
18
+ one map) — a rename done before anyone has data. Every entity's `list` sorts by `number`, `createdAt`
19
+ and `updatedAt` beside the head fields, and `documentMigrations` renders the two clock indexes per
20
+ entity. `heads` and `aggregate` narrow by ANY head field (equality, a set, or `{ from, to }` — the
21
+ tuple ranges are gone) plus `createdAt`/`updatedAt` ranges; `aggregate` groups by any head field;
22
+ `heads` answers `HeadRow<Columns>` typed off its `columns`. `freeze` and `names` pass through
23
+ `documentMigrations` to both tables' walls (#429). The shapes that
24
+ carry it: `HeadColumn` (off `HeadField`), `HeadsArgs<Columns>`, `HeadsWhere` (any head field, a set
25
+ or a range, plus the two clocks), `AggregateWhere` (the same), `AggregateBy` (any head field, `entity`,
26
+ or a date bucket), `HeadsOrder` (a clock or `number` beside the heads), `HeadRow<Columns>`,
27
+ `DocumentSortColumn`.
28
+
29
+ ### Patch Changes
30
+
31
+ - 8d82c01: `documentMigrations` renders `status` as `not null` and the six other head columns nullable, now that
32
+ the entity floor renders indexed columns `not null` by default; `0001_documents.sql` follows.
33
+ - Updated dependencies [e08161b]
34
+ - Updated dependencies [d470d30]
35
+ - @geonosis/db@0.10.0
36
+
3
37
  ## 0.3.0
4
38
 
5
39
  ### 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 `projectionMigrations`
110
- (the seven head columns typed off `FieldKind`, `lineage` carried, `hash`, the version column as the
111
- sequence) plus the `(entity, issueDate)` listing index, then `logMigrations` for the revisions
112
- table unless `revisions: false` — the same walls the floor renders for any log, with `revision_kind`
113
- constrained to `committed | retired | reinstated`. `appRole` is required whenever the log renders
114
- (the default): the name a consumer's application connects as, the same law as `@geonosis/db`'s own
115
- `appRoleStatements`. The log's own kind column is `columns.revisionKind`, `'revision_kind'` when
116
- unnamed — never `'kind'`, which is what these docs use for `columns.entity` (#407).
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
- columns plus `entity` and `number`, `entity` one kind or a set, `order` every column a page is
187
- ordered by (the tie-break included). `store.aggregate({ by?, entity?, entities?, measures, where? })`
188
- answers `count` and `sum:total` — `where` OPTIONAL (a plain count with no range is one row) —
189
- grouped by `'status' | 'entity' | { bucket: 'day' | 'week' | 'month', of: 'issueDate' }`. `count` is
190
- a number; `sum:total` is a DECIMAL STRING (`sum("total")::text`, `'0'` for an empty group) — money
191
- never crosses this door as a float either. Both are tenant-scoped by the seam and exclude retired
192
- rows.
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(HEAD_COLUMNS),
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(headsColumns),
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 = (totalColumn) => Object.entries(headFields).map(([key, kind]) => {
652
- const column = key === "total" ? totalColumn : key;
653
- const type = DDL_TYPE_OF[kind];
654
- return type === void 0 ? column : { column, type };
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 revisionsMigrations = (options, entityColumn, tenantColumn) => {
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: tenantColumn },
698
+ columns: { tenant: physical.tenant },
669
699
  extra: [{ column: revisionKindColumn, type: revisionKindType(revisionKindColumn) }],
670
- key: [entityColumn, "ref", { column: "lineage", type: "integer" }],
671
- ...options.schema === void 0 ? {} : { schema: options.schema },
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 entityColumn = options.columns?.entity ?? DEFAULT_ENTITY_COLUMN;
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: { [entityColumn]: "" },
699
- indexed: headIndexedColumns(totalColumn),
727
+ constants: { [physical.entity]: "" },
728
+ indexed: headIndexedColumns(physical),
700
729
  key: "number",
701
730
  order: [{ column: "number" }],
702
- ...options.schema === void 0 ? {} : { schema: options.schema },
731
+ ...walls(options),
703
732
  settings: options.settings,
704
- sortable: Object.keys(headFields).map((key) => key === "total" ? totalColumn : key),
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}_${entityColumn}_issueDate_idx`)} on ${quotedName(table)} (${quotedName(entityColumn)}, ${quotedName("issueDate")})`;
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, entityColumn, tenantColumn)
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 totalColumn = nameOf2(total, DEFAULT_TOTAL_COLUMN2);
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 === "entity" ? entityColumn : column === "total" ? totalColumn : column;
773
- const physicalHeads = HEAD_COLUMNS2.map(columnOf);
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: tenantColumn },
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, createdAtColumn],
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: HEAD_COLUMNS2,
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: HEAD_COLUMNS2,
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: projection.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(async (tx, params) => {
1236
- const { columns, entity, order, where } = params;
1237
- const rows = await readers.project(tx, {
1238
- ...tenanted(params[tenantKey]),
1239
- columns: columns.filter((column) => column !== "number").map(columnOf),
1240
- order: order.map((one) => ({
1241
- column: columnOf(one.column),
1242
- ...one.direction === void 0 ? {} : { direction: one.direction }
1243
- })),
1244
- where: {
1245
- ...entity === void 0 ? {} : { [entityColumn]: entity },
1246
- ...where?.status === void 0 ? {} : { status: where.status },
1247
- ...where?.createdAt === void 0 ? {} : { [createdAtColumn]: { from: where.createdAt[0], to: where.createdAt[1] } }
1248
- }
1249
- });
1250
- return rows.map(
1251
- (row) => Object.fromEntries(
1252
- columns.map((column) => [column, column === "number" ? row.key : row[columnOf(column)]])
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 === "entity" ? entityColumn : by === "status" ? "status" : { bucket: by.bucket, of: by.of }
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:${totalColumn}` : one
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?.status === void 0 ? {} : { status: where.status },
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