@geonosis/document 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +78 -13
  3. package/dist/core/actor.d.cts +0 -1
  4. package/dist/core/actor.d.ts +0 -1
  5. package/dist/core/body-version.d.cts +0 -9
  6. package/dist/core/body-version.d.ts +0 -9
  7. package/dist/core/canonical.cjs +2 -3
  8. package/dist/core/canonical.d.cts +0 -4
  9. package/dist/core/canonical.d.ts +0 -4
  10. package/dist/core/canonical.js +2 -3
  11. package/dist/core/document.cjs +28 -25
  12. package/dist/core/document.d.cts +3 -22
  13. package/dist/core/document.d.ts +3 -22
  14. package/dist/core/document.js +28 -25
  15. package/dist/core/entities.d.cts +0 -19
  16. package/dist/core/entities.d.ts +0 -19
  17. package/dist/core/naming.d.cts +0 -5
  18. package/dist/core/naming.d.ts +0 -5
  19. package/dist/core/numbering.d.cts +0 -4
  20. package/dist/core/numbering.d.ts +0 -4
  21. package/dist/core/ports.d.cts +0 -6
  22. package/dist/core/ports.d.ts +0 -6
  23. package/dist/core/schema.cjs +44 -76
  24. package/dist/core/schema.d.cts +1 -13
  25. package/dist/core/schema.d.ts +1 -13
  26. package/dist/core/schema.js +44 -76
  27. package/dist/core/status.d.cts +0 -1
  28. package/dist/core/status.d.ts +0 -1
  29. package/dist/index.cjs +1 -0
  30. package/dist/index.d.cts +1 -1
  31. package/dist/index.d.ts +1 -1
  32. package/dist/index.js +2 -0
  33. package/dist/store/ddl.cjs +35 -38
  34. package/dist/store/ddl.d.cts +6 -6
  35. package/dist/store/ddl.d.ts +6 -6
  36. package/dist/store/ddl.js +37 -39
  37. package/dist/store/hash.d.cts +0 -1
  38. package/dist/store/hash.d.ts +0 -1
  39. package/dist/store/number-for.cjs +52 -0
  40. package/dist/store/number-for.d.cts +11 -0
  41. package/dist/store/number-for.d.ts +11 -0
  42. package/dist/store/number-for.js +12 -0
  43. package/dist/store/store.cjs +188 -162
  44. package/dist/store/store.d.cts +57 -16
  45. package/dist/store/store.d.ts +57 -16
  46. package/dist/store/store.js +190 -163
  47. package/dist/store.cjs +2 -0
  48. package/dist/store.d.cts +3 -2
  49. package/dist/store.d.ts +3 -2
  50. package/dist/store.js +2 -0
  51. package/dist/surface/table.cjs +129 -66
  52. package/dist/surface/table.d.cts +20 -28
  53. package/dist/surface/table.d.ts +20 -28
  54. package/dist/surface/table.js +132 -66
  55. package/dist/workflows/bindings.cjs +48 -0
  56. package/dist/workflows/bindings.d.cts +15 -0
  57. package/dist/workflows/bindings.d.ts +15 -0
  58. package/dist/workflows/bindings.js +10 -0
  59. package/dist/workflows/document-workflows.cjs +29 -40
  60. package/dist/workflows/document-workflows.d.cts +0 -12
  61. package/dist/workflows/document-workflows.d.ts +0 -12
  62. package/dist/workflows/document-workflows.js +29 -40
  63. package/dist/workflows/effects.d.cts +0 -12
  64. package/dist/workflows/effects.d.ts +0 -12
  65. package/dist/workflows/ports.d.cts +0 -17
  66. package/dist/workflows/ports.d.ts +0 -17
  67. package/dist/workflows/refusals.cjs +30 -0
  68. package/dist/workflows/refusals.d.cts +37 -9
  69. package/dist/workflows/refusals.d.ts +37 -9
  70. package/dist/workflows/refusals.js +30 -0
  71. package/dist/workflows/shared.cjs +93 -0
  72. package/dist/workflows/shared.d.cts +28 -0
  73. package/dist/workflows/shared.d.ts +28 -0
  74. package/dist/workflows/shared.js +60 -0
  75. package/dist/workflows.cjs +16 -1
  76. package/dist/workflows.d.cts +3 -1
  77. package/dist/workflows.d.ts +3 -1
  78. package/dist/workflows.js +31 -1
  79. package/package.json +4 -4
@@ -1,26 +1,47 @@
1
- import { type AggregateRow, type DrizzleHandle, type EntityListing, type EntityPage, type EntityUndo, type Projection, type Query, type SessionSeam } from '@geonosis/db';
1
+ import { type AggregateRow, type DrizzleHandle, type EntityListing, type EntityPage, type EntityUndo, type Projection, type Query, type RowDoors, type SessionSeam } from '@geonosis/db';
2
2
  import { type DocumentBodyMigrations } from '../core/body-version.cjs';
3
- import { type DocumentHead, type DocumentInstance } from '../core/document.cjs';
3
+ import { type DocumentHead, type DocumentInstance, type InstanceOf, type ViewOf } from '../core/document.cjs';
4
4
  import { type AnyDocumentEntity, documentEntities } from '../core/entities.cjs';
5
5
  import type { ArchivePort } from '../core/ports.cjs';
6
- import { type DocumentColumns, type DocumentRevisionsOptions, type HeadField } from './ddl.cjs';
6
+ import { type DocumentColumns, type DocumentRevisionsOptions, type HeadField, REVISION_KINDS } from './ddl.cjs';
7
7
  type StorableDocumentEntity = AnyDocumentEntity & {
8
8
  bodyVersion?: number;
9
9
  headOf: (body: never) => DocumentHead;
10
10
  migrations?: DocumentBodyMigrations<Record<string, unknown>>;
11
11
  prepare: (body: never) => unknown;
12
+ searchText: (body: never) => {
13
+ body: string;
14
+ };
12
15
  };
13
16
  type Registry<Map extends Readonly<Record<string, StorableDocumentEntity>>> = ReturnType<typeof documentEntities<Map>>;
17
+ export type DocumentSearchPort<Handle extends DrizzleHandle = DrizzleHandle> = {
18
+ index: (handle: Handle, input: {
19
+ entity: string;
20
+ head: DocumentHead;
21
+ ref: string;
22
+ text: {
23
+ body: string;
24
+ };
25
+ }) => Promise<void>;
26
+ remove: (handle: Handle, input: {
27
+ entity: string;
28
+ ref: string;
29
+ }) => Promise<void>;
30
+ };
31
+ export type DocumentViews<Map extends Readonly<Record<string, StorableDocumentEntity>>, Handle extends DrizzleHandle = DrizzleHandle> = {
32
+ [Name in keyof Map & string]?: (handle: Handle, instance: InstanceOf<Map[Name]>) => Promise<ViewOf<Map[Name]>>;
33
+ };
14
34
  export type DocumentStoreOptions<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
15
35
  archive?: ArchivePort;
16
36
  columns?: DocumentColumns;
17
37
  registry: Registry<Map>;
18
38
  revisions?: DocumentRevisionsOptions | false;
19
39
  schema?: string;
40
+ search?: DocumentSearchPort<Handle>;
20
41
  seam: SessionSeam<Key, Handle>;
21
42
  table?: string;
43
+ views?: DocumentViews<Map, Handle>;
22
44
  };
23
- /** What a head projection may carry: the business head, the entity, the number, and the record's clocks. */
24
45
  export type HeadColumn = HeadField | 'createdAt' | 'entity' | 'number' | 'updatedAt';
25
46
  export type DocumentSortColumn = HeadField | 'createdAt' | 'number' | 'updatedAt';
26
47
  export type HeadsOrder = {
@@ -31,13 +52,14 @@ export type HeadsWhere = Readonly<Partial<Record<HeadField | 'createdAt' | 'upda
31
52
  from: unknown;
32
53
  to: unknown;
33
54
  }>>>;
34
- export type HeadRow<Columns extends readonly HeadColumn[]> = Pick<DocumentHead & {
55
+ type FullHeadRow = DocumentHead & {
35
56
  createdAt: number;
36
57
  entity: string;
37
58
  number: string;
38
59
  updatedAt: number;
39
- }, Columns[number]>;
40
- export type HeadsArgs<Columns extends readonly HeadColumn[] = readonly HeadColumn[]> = {
60
+ };
61
+ export type HeadRow<Columns extends readonly HeadColumn[] | 'all'> = Columns extends 'all' ? FullHeadRow : Columns extends readonly HeadColumn[] ? Pick<FullHeadRow, Columns[number]> : never;
62
+ export type HeadsArgs<Columns extends readonly HeadColumn[] | 'all' = readonly HeadColumn[] | 'all'> = {
41
63
  columns: Columns;
42
64
  entity?: string | readonly string[];
43
65
  order: readonly HeadsOrder[];
@@ -58,11 +80,12 @@ export type AggregateArgs = {
58
80
  where?: AggregateWhere;
59
81
  };
60
82
  type Item = DocumentInstance<string, unknown>;
61
- export type DocumentKind = 'committed' | 'reinstated' | 'retired';
83
+ export type DocumentKind = (typeof REVISION_KINDS)[number];
62
84
  export type CommitOutput = {
63
85
  archived?: undefined;
64
86
  committed: false;
65
87
  hash?: undefined;
88
+ head: DocumentHead;
66
89
  lineage: number;
67
90
  previous?: undefined;
68
91
  ref: string;
@@ -71,6 +94,7 @@ export type CommitOutput = {
71
94
  archived?: boolean;
72
95
  committed: true;
73
96
  hash: string;
97
+ head: DocumentHead;
74
98
  lineage: number;
75
99
  previous: {
76
100
  hash: string;
@@ -81,16 +105,12 @@ export type CommitOutput = {
81
105
  };
82
106
  export type RetireOutput = {
83
107
  hash: string;
108
+ head: DocumentHead;
84
109
  lineage: number;
85
110
  ref: string;
86
111
  version: number;
87
112
  };
88
- export type ReinstateOutput = {
89
- hash: string;
90
- lineage: number;
91
- ref: string;
92
- version: number;
93
- };
113
+ export type ReinstateOutput = RetireOutput;
94
114
  export type HistoryEntry = {
95
115
  actor: string;
96
116
  at: number;
@@ -124,10 +144,17 @@ type DocumentEntityStore<Key extends string, Handle extends DrizzleHandle> = Pic
124
144
  reason?: string;
125
145
  ref: string;
126
146
  }, CommitOutput, Handle>;
147
+ count: Query<Readonly<Record<Key, string>> & {
148
+ where?: HeadsWhere;
149
+ }, number, Handle>;
127
150
  history: Query<Readonly<Record<Key, string>> & {
128
151
  lineage?: number;
129
152
  ref: string;
130
153
  }, HistoryEntry[], Handle>;
154
+ keys: Query<Readonly<Record<Key, string>> & {
155
+ order?: readonly HeadsOrder[];
156
+ where?: HeadsWhere;
157
+ }, string[], Handle>;
131
158
  list: Query<Readonly<Record<Key, string>> & EntityListing<DocumentSortColumn, HeadField>, EntityPage<Item>, Handle>;
132
159
  reinstate: Query<Readonly<Record<Key, string>> & {
133
160
  actor: string;
@@ -154,16 +181,30 @@ type DocumentEntityStore<Key extends string, Handle extends DrizzleHandle> = Pic
154
181
  ref: string;
155
182
  }, VerifyResult, Handle>;
156
183
  };
184
+ export type DocumentListing = EntityListing<DocumentSortColumn | 'entity', HeadField> & {
185
+ entities?: readonly string[];
186
+ };
187
+ export type DocumentList<Key extends string, Handle extends DrizzleHandle> = Query<Readonly<Record<Key, string>> & DocumentListing, EntityPage<Item>, Handle>;
188
+ export type DocumentTables<Key extends string, Handle extends DrizzleHandle> = {
189
+ documents: RowDoors<Key, Handle>;
190
+ revisions?: RowDoors<Key, Handle>;
191
+ };
157
192
  export type DocumentStore<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
158
- [Name in keyof Map & string]: DocumentEntityStore<Key, Handle>;
193
+ [Name in keyof Map & string]: DocumentEntityStore<Key, Handle> & {
194
+ render: Query<Readonly<Record<Key, string>> & {
195
+ ref: string;
196
+ }, ViewOf<Map[Name]> | null, Handle>;
197
+ };
159
198
  } & {
160
199
  aggregate: Query<Readonly<Record<Key, string>> & AggregateArgs, AggregateRow[], Handle>;
161
- heads: <Columns extends readonly HeadColumn[]>(handle: Handle, params: Readonly<Record<Key, string>> & HeadsArgs<Columns>) => Promise<HeadRow<Columns>[]>;
200
+ heads: <Columns extends readonly HeadColumn[] | 'all'>(handle: Handle, params: Readonly<Record<Key, string>> & HeadsArgs<Columns>) => Promise<HeadRow<Columns>[]>;
201
+ list: DocumentList<Key, Handle>;
162
202
  rebuild: Query<Readonly<Record<Key, string>> & {
163
203
  entity?: string;
164
204
  }, {
165
205
  rows: number;
166
206
  }, Handle>;
207
+ tables: DocumentTables<Key, Handle>;
167
208
  };
168
209
  export 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>;
169
210
  export type { DrizzleHandle as DocumentStoreHandle };
@@ -1,26 +1,47 @@
1
- import { type AggregateRow, type DrizzleHandle, type EntityListing, type EntityPage, type EntityUndo, type Projection, type Query, type SessionSeam } from '@geonosis/db';
1
+ import { type AggregateRow, type DrizzleHandle, type EntityListing, type EntityPage, type EntityUndo, type Projection, type Query, type RowDoors, type SessionSeam } from '@geonosis/db';
2
2
  import { type DocumentBodyMigrations } from '../core/body-version.js';
3
- import { type DocumentHead, type DocumentInstance } from '../core/document.js';
3
+ import { type DocumentHead, type DocumentInstance, type InstanceOf, type ViewOf } from '../core/document.js';
4
4
  import { type AnyDocumentEntity, documentEntities } from '../core/entities.js';
5
5
  import type { ArchivePort } from '../core/ports.js';
6
- import { type DocumentColumns, type DocumentRevisionsOptions, type HeadField } from './ddl.js';
6
+ import { type DocumentColumns, type DocumentRevisionsOptions, type HeadField, REVISION_KINDS } from './ddl.js';
7
7
  type StorableDocumentEntity = AnyDocumentEntity & {
8
8
  bodyVersion?: number;
9
9
  headOf: (body: never) => DocumentHead;
10
10
  migrations?: DocumentBodyMigrations<Record<string, unknown>>;
11
11
  prepare: (body: never) => unknown;
12
+ searchText: (body: never) => {
13
+ body: string;
14
+ };
12
15
  };
13
16
  type Registry<Map extends Readonly<Record<string, StorableDocumentEntity>>> = ReturnType<typeof documentEntities<Map>>;
17
+ export type DocumentSearchPort<Handle extends DrizzleHandle = DrizzleHandle> = {
18
+ index: (handle: Handle, input: {
19
+ entity: string;
20
+ head: DocumentHead;
21
+ ref: string;
22
+ text: {
23
+ body: string;
24
+ };
25
+ }) => Promise<void>;
26
+ remove: (handle: Handle, input: {
27
+ entity: string;
28
+ ref: string;
29
+ }) => Promise<void>;
30
+ };
31
+ export type DocumentViews<Map extends Readonly<Record<string, StorableDocumentEntity>>, Handle extends DrizzleHandle = DrizzleHandle> = {
32
+ [Name in keyof Map & string]?: (handle: Handle, instance: InstanceOf<Map[Name]>) => Promise<ViewOf<Map[Name]>>;
33
+ };
14
34
  export type DocumentStoreOptions<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
15
35
  archive?: ArchivePort;
16
36
  columns?: DocumentColumns;
17
37
  registry: Registry<Map>;
18
38
  revisions?: DocumentRevisionsOptions | false;
19
39
  schema?: string;
40
+ search?: DocumentSearchPort<Handle>;
20
41
  seam: SessionSeam<Key, Handle>;
21
42
  table?: string;
43
+ views?: DocumentViews<Map, Handle>;
22
44
  };
23
- /** What a head projection may carry: the business head, the entity, the number, and the record's clocks. */
24
45
  export type HeadColumn = HeadField | 'createdAt' | 'entity' | 'number' | 'updatedAt';
25
46
  export type DocumentSortColumn = HeadField | 'createdAt' | 'number' | 'updatedAt';
26
47
  export type HeadsOrder = {
@@ -31,13 +52,14 @@ export type HeadsWhere = Readonly<Partial<Record<HeadField | 'createdAt' | 'upda
31
52
  from: unknown;
32
53
  to: unknown;
33
54
  }>>>;
34
- export type HeadRow<Columns extends readonly HeadColumn[]> = Pick<DocumentHead & {
55
+ type FullHeadRow = DocumentHead & {
35
56
  createdAt: number;
36
57
  entity: string;
37
58
  number: string;
38
59
  updatedAt: number;
39
- }, Columns[number]>;
40
- export type HeadsArgs<Columns extends readonly HeadColumn[] = readonly HeadColumn[]> = {
60
+ };
61
+ export type HeadRow<Columns extends readonly HeadColumn[] | 'all'> = Columns extends 'all' ? FullHeadRow : Columns extends readonly HeadColumn[] ? Pick<FullHeadRow, Columns[number]> : never;
62
+ export type HeadsArgs<Columns extends readonly HeadColumn[] | 'all' = readonly HeadColumn[] | 'all'> = {
41
63
  columns: Columns;
42
64
  entity?: string | readonly string[];
43
65
  order: readonly HeadsOrder[];
@@ -58,11 +80,12 @@ export type AggregateArgs = {
58
80
  where?: AggregateWhere;
59
81
  };
60
82
  type Item = DocumentInstance<string, unknown>;
61
- export type DocumentKind = 'committed' | 'reinstated' | 'retired';
83
+ export type DocumentKind = (typeof REVISION_KINDS)[number];
62
84
  export type CommitOutput = {
63
85
  archived?: undefined;
64
86
  committed: false;
65
87
  hash?: undefined;
88
+ head: DocumentHead;
66
89
  lineage: number;
67
90
  previous?: undefined;
68
91
  ref: string;
@@ -71,6 +94,7 @@ export type CommitOutput = {
71
94
  archived?: boolean;
72
95
  committed: true;
73
96
  hash: string;
97
+ head: DocumentHead;
74
98
  lineage: number;
75
99
  previous: {
76
100
  hash: string;
@@ -81,16 +105,12 @@ export type CommitOutput = {
81
105
  };
82
106
  export type RetireOutput = {
83
107
  hash: string;
108
+ head: DocumentHead;
84
109
  lineage: number;
85
110
  ref: string;
86
111
  version: number;
87
112
  };
88
- export type ReinstateOutput = {
89
- hash: string;
90
- lineage: number;
91
- ref: string;
92
- version: number;
93
- };
113
+ export type ReinstateOutput = RetireOutput;
94
114
  export type HistoryEntry = {
95
115
  actor: string;
96
116
  at: number;
@@ -124,10 +144,17 @@ type DocumentEntityStore<Key extends string, Handle extends DrizzleHandle> = Pic
124
144
  reason?: string;
125
145
  ref: string;
126
146
  }, CommitOutput, Handle>;
147
+ count: Query<Readonly<Record<Key, string>> & {
148
+ where?: HeadsWhere;
149
+ }, number, Handle>;
127
150
  history: Query<Readonly<Record<Key, string>> & {
128
151
  lineage?: number;
129
152
  ref: string;
130
153
  }, HistoryEntry[], Handle>;
154
+ keys: Query<Readonly<Record<Key, string>> & {
155
+ order?: readonly HeadsOrder[];
156
+ where?: HeadsWhere;
157
+ }, string[], Handle>;
131
158
  list: Query<Readonly<Record<Key, string>> & EntityListing<DocumentSortColumn, HeadField>, EntityPage<Item>, Handle>;
132
159
  reinstate: Query<Readonly<Record<Key, string>> & {
133
160
  actor: string;
@@ -154,16 +181,30 @@ type DocumentEntityStore<Key extends string, Handle extends DrizzleHandle> = Pic
154
181
  ref: string;
155
182
  }, VerifyResult, Handle>;
156
183
  };
184
+ export type DocumentListing = EntityListing<DocumentSortColumn | 'entity', HeadField> & {
185
+ entities?: readonly string[];
186
+ };
187
+ export type DocumentList<Key extends string, Handle extends DrizzleHandle> = Query<Readonly<Record<Key, string>> & DocumentListing, EntityPage<Item>, Handle>;
188
+ export type DocumentTables<Key extends string, Handle extends DrizzleHandle> = {
189
+ documents: RowDoors<Key, Handle>;
190
+ revisions?: RowDoors<Key, Handle>;
191
+ };
157
192
  export type DocumentStore<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
158
- [Name in keyof Map & string]: DocumentEntityStore<Key, Handle>;
193
+ [Name in keyof Map & string]: DocumentEntityStore<Key, Handle> & {
194
+ render: Query<Readonly<Record<Key, string>> & {
195
+ ref: string;
196
+ }, ViewOf<Map[Name]> | null, Handle>;
197
+ };
159
198
  } & {
160
199
  aggregate: Query<Readonly<Record<Key, string>> & AggregateArgs, AggregateRow[], Handle>;
161
- heads: <Columns extends readonly HeadColumn[]>(handle: Handle, params: Readonly<Record<Key, string>> & HeadsArgs<Columns>) => Promise<HeadRow<Columns>[]>;
200
+ heads: <Columns extends readonly HeadColumn[] | 'all'>(handle: Handle, params: Readonly<Record<Key, string>> & HeadsArgs<Columns>) => Promise<HeadRow<Columns>[]>;
201
+ list: DocumentList<Key, Handle>;
162
202
  rebuild: Query<Readonly<Record<Key, string>> & {
163
203
  entity?: string;
164
204
  }, {
165
205
  rows: number;
166
206
  }, Handle>;
207
+ tables: DocumentTables<Key, Handle>;
167
208
  };
168
209
  export 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>;
169
210
  export type { DrizzleHandle as DocumentStoreHandle };