@geonosis/document 0.4.0 → 0.5.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 CHANGED
@@ -1,5 +1,33 @@
1
1
  # @geonosis/document
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - b0fde02: The store composes over drizzle (D-069): `documentStore`, `DocumentStore`, `DocumentStoreOptions`
8
+ and `documentSurface`/`DocumentSurfaceOptions` are typed over `Handle extends DrizzleHandle` — the
9
+ seam's handle is a drizzle database now, never the executor port. `documentTable(options)` builds
10
+ the document table as a drizzle table (the same shape `documentMigrations` renders) and the store
11
+ reads and writes through it; `DocumentStoreHandle` names the handle bound for a layer that may not
12
+ import `@geonosis/db`. drizzle-orm is an OPTIONAL peer of this package: the pure core (`Document`,
13
+ `documentEntities`, the body versioning) needs none of it, and the store reaches drizzle through
14
+ `@geonosis/db`, whose peer it already is. Doors, outputs and the migrations renderer are unchanged.
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [b0fde02]
19
+ - Updated dependencies [4a6deac]
20
+ - @geonosis/db@0.11.0
21
+
22
+ ## 0.4.1
23
+
24
+ ### Patch Changes
25
+
26
+ - cdc88fc: `documentStore<Map, Key, Handle = Executor>({ seam: SessionSeam<Key, Handle> })` — every door and
27
+ both undos are typed over the consumer's own handle, the way `defineEntity`, `defineLog` and
28
+ `projectionOf` already are; a seam opened over a drizzle database hands in without a cast (#433).
29
+ `DocumentStore` and `DocumentStoreOptions` gain the third type parameter.
30
+
3
31
  ## 0.4.0
4
32
 
5
33
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -749,6 +749,44 @@ var documentMigrations = (options) => {
749
749
  ...revisionsMigrations(options, physical)
750
750
  ];
751
751
  };
752
+ var TABLE_TYPE_OF = { decimal: "numeric" };
753
+ var documentTable = (options = {}) => {
754
+ const physical = physicalColumnsOf(options.columns);
755
+ const {
756
+ entity: _entity,
757
+ heads: _heads,
758
+ id,
759
+ revisionKind: _revisionKind,
760
+ total: _total,
761
+ version,
762
+ ...restColumns
763
+ } = options.columns ?? {};
764
+ const named = Object.fromEntries(
765
+ Object.entries(restColumns).map(([column, held]) => [column, nameOf(held, column)])
766
+ );
767
+ return (0, import_db.entityTable)({
768
+ columns: { ...named, version: nameOf(version, DEFAULT_VERSION_COLUMN) },
769
+ constants: [physical.entity],
770
+ extra: {
771
+ ...Object.fromEntries(
772
+ HEAD_FIELDS.map((field) => [
773
+ physical[field],
774
+ {
775
+ nullable: field !== "status",
776
+ type: TABLE_TYPE_OF[headFields[field]] ?? "text"
777
+ }
778
+ ])
779
+ ),
780
+ hash: "text",
781
+ lineage: "integer"
782
+ },
783
+ key: "number",
784
+ ...options.schema === void 0 ? {} : { schema: options.schema },
785
+ ...options.settings === void 0 ? {} : { settings: options.settings },
786
+ ...id === void 0 ? {} : { surrogate: nameOf(id.column, "id") },
787
+ table: options.table ?? DEFAULT_DOCUMENT_TABLE
788
+ });
789
+ };
752
790
 
753
791
  // src/store/store.ts
754
792
  var import_db2 = require("@geonosis/db");
@@ -794,6 +832,11 @@ var documentStore = (options) => {
794
832
  const { archive, registry, schema, seam } = options;
795
833
  const tenantKey = seam.tenantKey;
796
834
  const placed = schema === void 0 ? {} : { schema };
835
+ const declared = documentTable({
836
+ ...options.columns === void 0 ? {} : { columns: options.columns },
837
+ ...placed,
838
+ table
839
+ });
797
840
  const revisionsTable = options.revisions === false ? void 0 : options.revisions?.table ?? DEFAULT_REVISIONS_TABLE;
798
841
  const tenanted = (tenantId) => ({ [tenantKey]: tenantId });
799
842
  const columnOf = (column) => column === "number" ? "number" : physical[column];
@@ -843,10 +886,9 @@ var documentStore = (options) => {
843
886
  item: (row) => row,
844
887
  key: { column: "number", param: "ref" },
845
888
  order: [{ column: "number" }],
846
- ...placed,
847
889
  seam,
848
890
  sortable: [...physicalHeads, entityColumn, "number", physical.createdAt, physical.updatedAt],
849
- table
891
+ table: declared
850
892
  });
851
893
  const entityStoreFor = (name) => {
852
894
  const definition = registry.named(name);
@@ -885,7 +927,7 @@ var documentStore = (options) => {
885
927
  ...placed,
886
928
  seam,
887
929
  sortable: [...physicalHeads, "number", physical.createdAt, physical.updatedAt],
888
- table
930
+ table: declared
889
931
  });
890
932
  const list = (handle, params) => projection.list(handle, {
891
933
  ...params,
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, FreezeRegister, TenantPolicyNames, SessionSettings, EntityMigration, Projection, Executor, Query, EntityListing, EntityPage, EntityUndo, SessionSeam } from '@geonosis/db';
3
+ import { EntityColumns, EntityName, FreezeRegister, TenantPolicyNames, SessionSettings, EntityMigration, DrizzleHandle, Projection, 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";
@@ -304,13 +304,13 @@ type StorableDocumentEntity = AnyDocumentEntity & {
304
304
  prepare: (body: never) => unknown;
305
305
  };
306
306
  type Registry$1<Map extends Readonly<Record<string, StorableDocumentEntity>>> = ReturnType<typeof documentEntities<Map>>;
307
- type DocumentStoreOptions<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string> = {
307
+ type DocumentStoreOptions<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
308
308
  archive?: ArchivePort;
309
309
  columns?: DocumentColumns;
310
310
  registry: Registry$1<Map>;
311
311
  revisions?: DocumentRevisionsOptions | false;
312
312
  schema?: string;
313
- seam: SessionSeam<Key, Executor>;
313
+ seam: SessionSeam<Key, Handle>;
314
314
  table?: string;
315
315
  };
316
316
  type HeadColumn = HeadField | 'entity' | 'number';
@@ -403,63 +403,63 @@ type VerifyResult = {
403
403
  ok: true;
404
404
  versions: number;
405
405
  };
406
- type DocumentEntityStore<Key extends string> = Pick<Projection<unknown, Item, Key, 'ref', Executor, string, string>, 'get' | 'listAll'> & {
406
+ type DocumentEntityStore<Key extends string, Handle extends DrizzleHandle> = Pick<Projection<unknown, Item, Key, 'ref', Handle, string, string>, 'get' | 'listAll'> & {
407
407
  asOf: Query<Readonly<Record<Key, string>> & {
408
408
  at: number;
409
409
  ref: string;
410
- }, Item | null, Executor>;
410
+ }, Item | null, Handle>;
411
411
  at: Query<Readonly<Record<Key, string>> & {
412
412
  ref: string;
413
413
  version: number;
414
- }, Item | null, Executor>;
414
+ }, Item | null, Handle>;
415
415
  commit: Query<Readonly<Record<Key, string>> & {
416
416
  actor: string;
417
417
  body: unknown;
418
418
  reason?: string;
419
419
  ref: string;
420
- }, CommitOutput, Executor>;
420
+ }, CommitOutput, Handle>;
421
421
  history: Query<Readonly<Record<Key, string>> & {
422
422
  lineage?: number;
423
423
  ref: string;
424
- }, HistoryEntry[], Executor>;
425
- list: Query<Readonly<Record<Key, string>> & EntityListing<DocumentSortColumn, HeadField>, EntityPage<Item>, Executor>;
424
+ }, HistoryEntry[], Handle>;
425
+ list: Query<Readonly<Record<Key, string>> & EntityListing<DocumentSortColumn, HeadField>, EntityPage<Item>, Handle>;
426
426
  reinstate: Query<Readonly<Record<Key, string>> & {
427
427
  actor: string;
428
428
  reason?: string;
429
429
  ref: string;
430
- }, ReinstateOutput, Executor>;
430
+ }, ReinstateOutput, Handle>;
431
431
  retire: Query<Readonly<Record<Key, string>> & {
432
432
  actor: string;
433
433
  reason?: string;
434
434
  ref: string;
435
- }, RetireOutput, Executor>;
435
+ }, RetireOutput, Handle>;
436
436
  succeed: Query<Readonly<Record<Key, string>> & {
437
437
  actor: string;
438
438
  body: unknown;
439
439
  reason?: string;
440
440
  ref: string;
441
- }, CommitOutput, Executor>;
441
+ }, CommitOutput, Handle>;
442
442
  undos: {
443
- commit: EntityUndo<CommitOutput, Executor>;
444
- retire: EntityUndo<RetireOutput, Executor>;
443
+ commit: EntityUndo<CommitOutput, Handle>;
444
+ retire: EntityUndo<RetireOutput, Handle>;
445
445
  };
446
446
  verify: Query<Readonly<Record<Key, string>> & {
447
447
  lineage?: number;
448
448
  ref: string;
449
- }, VerifyResult, Executor>;
449
+ }, VerifyResult, Handle>;
450
450
  };
451
- type DocumentStore<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string> = {
452
- [Name in keyof Map & string]: DocumentEntityStore<Key>;
451
+ type DocumentStore<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
452
+ [Name in keyof Map & string]: DocumentEntityStore<Key, Handle>;
453
453
  } & {
454
- aggregate: Query<Readonly<Record<Key, string>> & AggregateArgs, AggregateRow[], Executor>;
455
- heads: <Columns extends readonly HeadColumn[]>(handle: Executor, params: Readonly<Record<Key, string>> & HeadsArgs<Columns>) => Promise<HeadRow<Columns>[]>;
454
+ aggregate: Query<Readonly<Record<Key, string>> & AggregateArgs, AggregateRow[], Handle>;
455
+ heads: <Columns extends readonly HeadColumn[]>(handle: Handle, params: Readonly<Record<Key, string>> & HeadsArgs<Columns>) => Promise<HeadRow<Columns>[]>;
456
456
  rebuild: Query<Readonly<Record<Key, string>> & {
457
457
  entity?: string;
458
458
  }, {
459
459
  rows: number;
460
- }, Executor>;
460
+ }, Handle>;
461
461
  };
462
- declare const documentStore: <Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string>(options: DocumentStoreOptions<Map, Key>) => DocumentStore<Map, Key>;
462
+ declare const documentStore: <Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle>(options: DocumentStoreOptions<Map, Key, Handle>) => DocumentStore<Map, Key, Handle>;
463
463
 
464
464
  type SurfaceVerb = 'query' | 'mutation';
465
465
  type SurfaceScope = 'org' | 'public' | 'token';
@@ -517,10 +517,10 @@ type SurfaceDocumentEntity = AnyDocumentEntity & {
517
517
  withStatus: (body: never, status: string, at: string) => unknown;
518
518
  };
519
519
  type Registry<Map extends Readonly<Record<string, SurfaceDocumentEntity>>> = ReturnType<typeof documentEntities<Map>>;
520
- type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string> = {
520
+ type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
521
521
  registry: Registry<Map>;
522
522
  schema: SurfaceSchemaAdapter;
523
- store: DocumentStore<Map, Key>;
523
+ store: DocumentStore<Map, Key, Handle>;
524
524
  };
525
525
  /**
526
526
  * `documentSurface({ registry, store, schema })`: the table every tRPC/REST/MCP mount is derived
@@ -530,6 +530,6 @@ type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentE
530
530
  * a `{ pending: 'T3', workflow }` in place of `call` — an adapter mounting the table refuses those
531
531
  * BY NAME, never with a stub answer.
532
532
  */
533
- declare const documentSurface: <Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string>(options: DocumentSurfaceOptions<Map, Key>) => SurfaceRow[];
533
+ declare const documentSurface: <Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle>(options: DocumentSurfaceOptions<Map, Key, Handle>) => SurfaceRow[];
534
534
 
535
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, FreezeRegister, TenantPolicyNames, SessionSettings, EntityMigration, Projection, Executor, Query, EntityListing, EntityPage, EntityUndo, SessionSeam } from '@geonosis/db';
3
+ import { EntityColumns, EntityName, FreezeRegister, TenantPolicyNames, SessionSettings, EntityMigration, DrizzleHandle, Projection, 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";
@@ -304,13 +304,13 @@ type StorableDocumentEntity = AnyDocumentEntity & {
304
304
  prepare: (body: never) => unknown;
305
305
  };
306
306
  type Registry$1<Map extends Readonly<Record<string, StorableDocumentEntity>>> = ReturnType<typeof documentEntities<Map>>;
307
- type DocumentStoreOptions<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string> = {
307
+ type DocumentStoreOptions<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
308
308
  archive?: ArchivePort;
309
309
  columns?: DocumentColumns;
310
310
  registry: Registry$1<Map>;
311
311
  revisions?: DocumentRevisionsOptions | false;
312
312
  schema?: string;
313
- seam: SessionSeam<Key, Executor>;
313
+ seam: SessionSeam<Key, Handle>;
314
314
  table?: string;
315
315
  };
316
316
  type HeadColumn = HeadField | 'entity' | 'number';
@@ -403,63 +403,63 @@ type VerifyResult = {
403
403
  ok: true;
404
404
  versions: number;
405
405
  };
406
- type DocumentEntityStore<Key extends string> = Pick<Projection<unknown, Item, Key, 'ref', Executor, string, string>, 'get' | 'listAll'> & {
406
+ type DocumentEntityStore<Key extends string, Handle extends DrizzleHandle> = Pick<Projection<unknown, Item, Key, 'ref', Handle, string, string>, 'get' | 'listAll'> & {
407
407
  asOf: Query<Readonly<Record<Key, string>> & {
408
408
  at: number;
409
409
  ref: string;
410
- }, Item | null, Executor>;
410
+ }, Item | null, Handle>;
411
411
  at: Query<Readonly<Record<Key, string>> & {
412
412
  ref: string;
413
413
  version: number;
414
- }, Item | null, Executor>;
414
+ }, Item | null, Handle>;
415
415
  commit: Query<Readonly<Record<Key, string>> & {
416
416
  actor: string;
417
417
  body: unknown;
418
418
  reason?: string;
419
419
  ref: string;
420
- }, CommitOutput, Executor>;
420
+ }, CommitOutput, Handle>;
421
421
  history: Query<Readonly<Record<Key, string>> & {
422
422
  lineage?: number;
423
423
  ref: string;
424
- }, HistoryEntry[], Executor>;
425
- list: Query<Readonly<Record<Key, string>> & EntityListing<DocumentSortColumn, HeadField>, EntityPage<Item>, Executor>;
424
+ }, HistoryEntry[], Handle>;
425
+ list: Query<Readonly<Record<Key, string>> & EntityListing<DocumentSortColumn, HeadField>, EntityPage<Item>, Handle>;
426
426
  reinstate: Query<Readonly<Record<Key, string>> & {
427
427
  actor: string;
428
428
  reason?: string;
429
429
  ref: string;
430
- }, ReinstateOutput, Executor>;
430
+ }, ReinstateOutput, Handle>;
431
431
  retire: Query<Readonly<Record<Key, string>> & {
432
432
  actor: string;
433
433
  reason?: string;
434
434
  ref: string;
435
- }, RetireOutput, Executor>;
435
+ }, RetireOutput, Handle>;
436
436
  succeed: Query<Readonly<Record<Key, string>> & {
437
437
  actor: string;
438
438
  body: unknown;
439
439
  reason?: string;
440
440
  ref: string;
441
- }, CommitOutput, Executor>;
441
+ }, CommitOutput, Handle>;
442
442
  undos: {
443
- commit: EntityUndo<CommitOutput, Executor>;
444
- retire: EntityUndo<RetireOutput, Executor>;
443
+ commit: EntityUndo<CommitOutput, Handle>;
444
+ retire: EntityUndo<RetireOutput, Handle>;
445
445
  };
446
446
  verify: Query<Readonly<Record<Key, string>> & {
447
447
  lineage?: number;
448
448
  ref: string;
449
- }, VerifyResult, Executor>;
449
+ }, VerifyResult, Handle>;
450
450
  };
451
- type DocumentStore<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string> = {
452
- [Name in keyof Map & string]: DocumentEntityStore<Key>;
451
+ type DocumentStore<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
452
+ [Name in keyof Map & string]: DocumentEntityStore<Key, Handle>;
453
453
  } & {
454
- aggregate: Query<Readonly<Record<Key, string>> & AggregateArgs, AggregateRow[], Executor>;
455
- heads: <Columns extends readonly HeadColumn[]>(handle: Executor, params: Readonly<Record<Key, string>> & HeadsArgs<Columns>) => Promise<HeadRow<Columns>[]>;
454
+ aggregate: Query<Readonly<Record<Key, string>> & AggregateArgs, AggregateRow[], Handle>;
455
+ heads: <Columns extends readonly HeadColumn[]>(handle: Handle, params: Readonly<Record<Key, string>> & HeadsArgs<Columns>) => Promise<HeadRow<Columns>[]>;
456
456
  rebuild: Query<Readonly<Record<Key, string>> & {
457
457
  entity?: string;
458
458
  }, {
459
459
  rows: number;
460
- }, Executor>;
460
+ }, Handle>;
461
461
  };
462
- declare const documentStore: <Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string>(options: DocumentStoreOptions<Map, Key>) => DocumentStore<Map, Key>;
462
+ declare const documentStore: <Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle>(options: DocumentStoreOptions<Map, Key, Handle>) => DocumentStore<Map, Key, Handle>;
463
463
 
464
464
  type SurfaceVerb = 'query' | 'mutation';
465
465
  type SurfaceScope = 'org' | 'public' | 'token';
@@ -517,10 +517,10 @@ type SurfaceDocumentEntity = AnyDocumentEntity & {
517
517
  withStatus: (body: never, status: string, at: string) => unknown;
518
518
  };
519
519
  type Registry<Map extends Readonly<Record<string, SurfaceDocumentEntity>>> = ReturnType<typeof documentEntities<Map>>;
520
- type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string> = {
520
+ type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
521
521
  registry: Registry<Map>;
522
522
  schema: SurfaceSchemaAdapter;
523
- store: DocumentStore<Map, Key>;
523
+ store: DocumentStore<Map, Key, Handle>;
524
524
  };
525
525
  /**
526
526
  * `documentSurface({ registry, store, schema })`: the table every tRPC/REST/MCP mount is derived
@@ -530,6 +530,6 @@ type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentE
530
530
  * a `{ pending: 'T3', workflow }` in place of `call` — an adapter mounting the table refuses those
531
531
  * BY NAME, never with a stub answer.
532
532
  */
533
- declare const documentSurface: <Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string>(options: DocumentSurfaceOptions<Map, Key>) => SurfaceRow[];
533
+ declare const documentSurface: <Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle>(options: DocumentSurfaceOptions<Map, Key, Handle>) => SurfaceRow[];
534
534
 
535
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
@@ -571,6 +571,7 @@ var documentSurface = (options) => {
571
571
  import {
572
572
  DbRefusal,
573
573
  ENTITY_PLACEHOLDERS,
574
+ entityTable,
574
575
  logMigrations,
575
576
  projectionMigrations
576
577
  } from "@geonosis/db";
@@ -703,6 +704,44 @@ var documentMigrations = (options) => {
703
704
  ...revisionsMigrations(options, physical)
704
705
  ];
705
706
  };
707
+ var TABLE_TYPE_OF = { decimal: "numeric" };
708
+ var documentTable = (options = {}) => {
709
+ const physical = physicalColumnsOf(options.columns);
710
+ const {
711
+ entity: _entity,
712
+ heads: _heads,
713
+ id,
714
+ revisionKind: _revisionKind,
715
+ total: _total,
716
+ version,
717
+ ...restColumns
718
+ } = options.columns ?? {};
719
+ const named = Object.fromEntries(
720
+ Object.entries(restColumns).map(([column, held]) => [column, nameOf(held, column)])
721
+ );
722
+ return entityTable({
723
+ columns: { ...named, version: nameOf(version, DEFAULT_VERSION_COLUMN) },
724
+ constants: [physical.entity],
725
+ extra: {
726
+ ...Object.fromEntries(
727
+ HEAD_FIELDS.map((field) => [
728
+ physical[field],
729
+ {
730
+ nullable: field !== "status",
731
+ type: TABLE_TYPE_OF[headFields[field]] ?? "text"
732
+ }
733
+ ])
734
+ ),
735
+ hash: "text",
736
+ lineage: "integer"
737
+ },
738
+ key: "number",
739
+ ...options.schema === void 0 ? {} : { schema: options.schema },
740
+ ...options.settings === void 0 ? {} : { settings: options.settings },
741
+ ...id === void 0 ? {} : { surrogate: nameOf(id.column, "id") },
742
+ table: options.table ?? DEFAULT_DOCUMENT_TABLE
743
+ });
744
+ };
706
745
 
707
746
  // src/store/store.ts
708
747
  import {
@@ -753,6 +792,11 @@ var documentStore = (options) => {
753
792
  const { archive, registry, schema, seam } = options;
754
793
  const tenantKey = seam.tenantKey;
755
794
  const placed = schema === void 0 ? {} : { schema };
795
+ const declared = documentTable({
796
+ ...options.columns === void 0 ? {} : { columns: options.columns },
797
+ ...placed,
798
+ table
799
+ });
756
800
  const revisionsTable = options.revisions === false ? void 0 : options.revisions?.table ?? DEFAULT_REVISIONS_TABLE;
757
801
  const tenanted = (tenantId) => ({ [tenantKey]: tenantId });
758
802
  const columnOf = (column) => column === "number" ? "number" : physical[column];
@@ -802,10 +846,9 @@ var documentStore = (options) => {
802
846
  item: (row) => row,
803
847
  key: { column: "number", param: "ref" },
804
848
  order: [{ column: "number" }],
805
- ...placed,
806
849
  seam,
807
850
  sortable: [...physicalHeads, entityColumn, "number", physical.createdAt, physical.updatedAt],
808
- table
851
+ table: declared
809
852
  });
810
853
  const entityStoreFor = (name) => {
811
854
  const definition = registry.named(name);
@@ -844,7 +887,7 @@ var documentStore = (options) => {
844
887
  ...placed,
845
888
  seam,
846
889
  sortable: [...physicalHeads, "number", physical.createdAt, physical.updatedAt],
847
- table
890
+ table: declared
848
891
  });
849
892
  const list = (handle, params) => projection.list(handle, {
850
893
  ...params,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geonosis/document",
3
- "version": "0.4.0",
3
+ "version": "0.5.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,9 +39,18 @@
39
39
  ],
40
40
  "dependencies": {
41
41
  "@standard-schema/spec": "^1.1.0",
42
- "@geonosis/db": "^0.10.0"
42
+ "@geonosis/db": "^0.11.0"
43
+ },
44
+ "peerDependencies": {
45
+ "drizzle-orm": ">=0.45.0"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "drizzle-orm": {
49
+ "optional": true
50
+ }
43
51
  },
44
52
  "devDependencies": {
53
+ "drizzle-orm": "^0.45.2",
45
54
  "embedded-postgres-17": "npm:embedded-postgres@17.10.0-beta.17",
46
55
  "embedded-postgres-18": "npm:embedded-postgres@18.4.0-beta.17",
47
56
  "pg": "^8.16.3",