@geonosis/document 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/store.d.cts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
- import { g as DocumentHead, A as AnyDocumentEntity, c as DocumentBodyMigrations, h as DocumentInstance, a as ArchivePort, p as documentEntities, k as DocumentStatusMachine } from './ports-D0NtPwAO.cjs';
3
- import { EntityColumns, EntityName, FreezeRegister, TenantPolicyNames, SessionSettings, EntityMigration, DrizzleHandle, Projection, Query, EntityListing, EntityPage, EntityUndo, SessionSeam } from '@geonosis/db';
4
- export { ENTITY_PLACEHOLDERS as DOCUMENT_MIGRATION_PLACEHOLDERS } from '@geonosis/db';
2
+ import { f as DocumentHead, A as AnyDocumentEntity, b as DocumentBodyMigrations, g as DocumentInstance, o as documentEntities, j as DocumentStatusMachine } from './entities-DTNJMeVf.cjs';
3
+ import { A as ArchivePort, S as SchemaAdapter } from './ports-C_OfflMQ.cjs';
4
+ import { EntityColumns, EntityName, FreezeRegister, TenantPolicyNames, SessionSettings, EntityMigration, DrizzleHandle, Projection, Query, EntityListing, EntityPage, EntityUndo, AggregateRow, SessionSeam } from '@geonosis/db';
5
+ export { AggregateRow, ENTITY_PLACEHOLDERS as DOCUMENT_MIGRATION_PLACEHOLDERS } from '@geonosis/db';
5
6
 
6
7
  /** sha256 hex over the canonical JSON of `payload` — no whitespace, keys sorted recursively. */
7
8
  declare const hashOf: (payload: unknown) => string;
@@ -63,7 +64,8 @@ type DocumentStoreOptions<Map extends Readonly<Record<string, StorableDocumentEn
63
64
  seam: SessionSeam<Key, Handle>;
64
65
  table?: string;
65
66
  };
66
- type HeadColumn = HeadField | 'entity' | 'number';
67
+ /** What a head projection may carry: the business head, the entity, the number, and the record's clocks. */
68
+ type HeadColumn = HeadField | 'createdAt' | 'entity' | 'number' | 'updatedAt';
67
69
  type DocumentSortColumn = HeadField | 'createdAt' | 'number' | 'updatedAt';
68
70
  type HeadsOrder = {
69
71
  column: DocumentSortColumn | 'entity';
@@ -74,8 +76,10 @@ type HeadsWhere = Readonly<Partial<Record<HeadField | 'createdAt' | 'updatedAt',
74
76
  to: unknown;
75
77
  }>>>;
76
78
  type HeadRow<Columns extends readonly HeadColumn[]> = Pick<DocumentHead & {
79
+ createdAt: number;
77
80
  entity: string;
78
81
  number: string;
82
+ updatedAt: number;
79
83
  }, Columns[number]>;
80
84
  type HeadsArgs<Columns extends readonly HeadColumn[] = readonly HeadColumn[]> = {
81
85
  columns: Columns;
@@ -89,11 +93,7 @@ type AggregateBy = HeadField | 'entity' | {
89
93
  of: 'dueDate' | 'issueDate';
90
94
  };
91
95
  type AggregateWhere = HeadsWhere;
92
- type AggregateRow = {
93
- by?: string;
94
- count?: number;
95
- sum?: string;
96
- };
96
+
97
97
  type AggregateArgs = {
98
98
  by?: AggregateBy;
99
99
  entities?: readonly string[];
@@ -225,6 +225,8 @@ type PendingCall = {
225
225
  * compiles (#325) but answers nothing, so a mounting adapter narrows before it reads.
226
226
  */
227
227
  type SurfaceCall = (handle: never, params: never) => Promise<unknown>;
228
+ /** The adapter as the surface first named it; the builders live in the core now. */
229
+ type SurfaceSchemaAdapter = SchemaAdapter;
228
230
  type SurfaceRow = {
229
231
  call: PendingCall | SurfaceCall;
230
232
  input: StandardSchemaV1;
@@ -234,16 +236,6 @@ type SurfaceRow = {
234
236
  scope: SurfaceScope;
235
237
  verb: SurfaceVerb;
236
238
  };
237
- /**
238
- * The three builders a validator library supplies so the table stays library-free (#383) while the
239
- * union/enum/object it derives are still real schemas of THAT library — the one place a consumer's
240
- * zod enters `@geonosis/document` is through this adapter, never a direct dependency.
241
- */
242
- type SurfaceSchemaAdapter = {
243
- enum: (values: readonly string[]) => StandardSchemaV1<unknown, string>;
244
- object: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1;
245
- union: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1;
246
- };
247
239
  /**
248
240
  * What the table needs off an entity beyond `documentEntities`'s own minimal bound — plus exactly
249
241
  * what `documentStore`'s own `StorableDocumentEntity` needs, so `Map` satisfies both at once and a
@@ -282,4 +274,4 @@ type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentE
282
274
  */
283
275
  declare const documentSurface: <Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle>(options: DocumentSurfaceOptions<Map, Key, Handle>) => SurfaceRow[];
284
276
 
285
- export { type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateRow, type AggregateWhere, type AppendOnlyTablesOptions, type CommitOutput, DEFAULT_DOCUMENT_TABLE, DEFAULT_REVISIONS_TABLE, DEFAULT_REVISION_KIND_COLUMN, type DocumentColumns, type DocumentKind, type DocumentMigrationsOptions, type DocumentPhysicalColumns, type DocumentRevisionsOptions, type DocumentSortColumn, type DocumentStore, type DocumentStoreOptions, type DocumentSurfaceOptions, HEAD_FIELDS, type HeadColumn, type HeadField, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type PendingCall, type ReinstateOutput, type RetireOutput, type SurfaceCall, type SurfaceRow, type SurfaceSchemaAdapter, type SurfaceScope, type SurfaceVerb, type VerifyResult, appendOnlyTables, documentMigrations, documentRoleStatements, documentStore, documentSurface, hashOf, physicalColumnsOf };
277
+ export { type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateWhere, type AppendOnlyTablesOptions, type CommitOutput, DEFAULT_DOCUMENT_TABLE, DEFAULT_REVISIONS_TABLE, DEFAULT_REVISION_KIND_COLUMN, type DocumentColumns, type DocumentKind, type DocumentMigrationsOptions, type DocumentPhysicalColumns, type DocumentRevisionsOptions, type DocumentSortColumn, type DocumentStore, type DocumentStoreOptions, type DocumentSurfaceOptions, HEAD_FIELDS, type HeadColumn, type HeadField, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type PendingCall, type ReinstateOutput, type RetireOutput, type SurfaceCall, type SurfaceRow, type SurfaceSchemaAdapter, type SurfaceScope, type SurfaceVerb, type VerifyResult, appendOnlyTables, documentMigrations, documentRoleStatements, documentStore, documentSurface, hashOf, physicalColumnsOf };
package/dist/store.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
- import { g as DocumentHead, A as AnyDocumentEntity, c as DocumentBodyMigrations, h as DocumentInstance, a as ArchivePort, p as documentEntities, k as DocumentStatusMachine } from './ports-D0NtPwAO.js';
3
- import { EntityColumns, EntityName, FreezeRegister, TenantPolicyNames, SessionSettings, EntityMigration, DrizzleHandle, Projection, Query, EntityListing, EntityPage, EntityUndo, SessionSeam } from '@geonosis/db';
4
- export { ENTITY_PLACEHOLDERS as DOCUMENT_MIGRATION_PLACEHOLDERS } from '@geonosis/db';
2
+ import { f as DocumentHead, A as AnyDocumentEntity, b as DocumentBodyMigrations, g as DocumentInstance, o as documentEntities, j as DocumentStatusMachine } from './entities-DTNJMeVf.js';
3
+ import { A as ArchivePort, S as SchemaAdapter } from './ports-C_OfflMQ.js';
4
+ import { EntityColumns, EntityName, FreezeRegister, TenantPolicyNames, SessionSettings, EntityMigration, DrizzleHandle, Projection, Query, EntityListing, EntityPage, EntityUndo, AggregateRow, SessionSeam } from '@geonosis/db';
5
+ export { AggregateRow, ENTITY_PLACEHOLDERS as DOCUMENT_MIGRATION_PLACEHOLDERS } from '@geonosis/db';
5
6
 
6
7
  /** sha256 hex over the canonical JSON of `payload` — no whitespace, keys sorted recursively. */
7
8
  declare const hashOf: (payload: unknown) => string;
@@ -63,7 +64,8 @@ type DocumentStoreOptions<Map extends Readonly<Record<string, StorableDocumentEn
63
64
  seam: SessionSeam<Key, Handle>;
64
65
  table?: string;
65
66
  };
66
- type HeadColumn = HeadField | 'entity' | 'number';
67
+ /** What a head projection may carry: the business head, the entity, the number, and the record's clocks. */
68
+ type HeadColumn = HeadField | 'createdAt' | 'entity' | 'number' | 'updatedAt';
67
69
  type DocumentSortColumn = HeadField | 'createdAt' | 'number' | 'updatedAt';
68
70
  type HeadsOrder = {
69
71
  column: DocumentSortColumn | 'entity';
@@ -74,8 +76,10 @@ type HeadsWhere = Readonly<Partial<Record<HeadField | 'createdAt' | 'updatedAt',
74
76
  to: unknown;
75
77
  }>>>;
76
78
  type HeadRow<Columns extends readonly HeadColumn[]> = Pick<DocumentHead & {
79
+ createdAt: number;
77
80
  entity: string;
78
81
  number: string;
82
+ updatedAt: number;
79
83
  }, Columns[number]>;
80
84
  type HeadsArgs<Columns extends readonly HeadColumn[] = readonly HeadColumn[]> = {
81
85
  columns: Columns;
@@ -89,11 +93,7 @@ type AggregateBy = HeadField | 'entity' | {
89
93
  of: 'dueDate' | 'issueDate';
90
94
  };
91
95
  type AggregateWhere = HeadsWhere;
92
- type AggregateRow = {
93
- by?: string;
94
- count?: number;
95
- sum?: string;
96
- };
96
+
97
97
  type AggregateArgs = {
98
98
  by?: AggregateBy;
99
99
  entities?: readonly string[];
@@ -225,6 +225,8 @@ type PendingCall = {
225
225
  * compiles (#325) but answers nothing, so a mounting adapter narrows before it reads.
226
226
  */
227
227
  type SurfaceCall = (handle: never, params: never) => Promise<unknown>;
228
+ /** The adapter as the surface first named it; the builders live in the core now. */
229
+ type SurfaceSchemaAdapter = SchemaAdapter;
228
230
  type SurfaceRow = {
229
231
  call: PendingCall | SurfaceCall;
230
232
  input: StandardSchemaV1;
@@ -234,16 +236,6 @@ type SurfaceRow = {
234
236
  scope: SurfaceScope;
235
237
  verb: SurfaceVerb;
236
238
  };
237
- /**
238
- * The three builders a validator library supplies so the table stays library-free (#383) while the
239
- * union/enum/object it derives are still real schemas of THAT library — the one place a consumer's
240
- * zod enters `@geonosis/document` is through this adapter, never a direct dependency.
241
- */
242
- type SurfaceSchemaAdapter = {
243
- enum: (values: readonly string[]) => StandardSchemaV1<unknown, string>;
244
- object: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1;
245
- union: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1;
246
- };
247
239
  /**
248
240
  * What the table needs off an entity beyond `documentEntities`'s own minimal bound — plus exactly
249
241
  * what `documentStore`'s own `StorableDocumentEntity` needs, so `Map` satisfies both at once and a
@@ -282,4 +274,4 @@ type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentE
282
274
  */
283
275
  declare const documentSurface: <Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle>(options: DocumentSurfaceOptions<Map, Key, Handle>) => SurfaceRow[];
284
276
 
285
- export { type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateRow, type AggregateWhere, type AppendOnlyTablesOptions, type CommitOutput, DEFAULT_DOCUMENT_TABLE, DEFAULT_REVISIONS_TABLE, DEFAULT_REVISION_KIND_COLUMN, type DocumentColumns, type DocumentKind, type DocumentMigrationsOptions, type DocumentPhysicalColumns, type DocumentRevisionsOptions, type DocumentSortColumn, type DocumentStore, type DocumentStoreOptions, type DocumentSurfaceOptions, HEAD_FIELDS, type HeadColumn, type HeadField, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type PendingCall, type ReinstateOutput, type RetireOutput, type SurfaceCall, type SurfaceRow, type SurfaceSchemaAdapter, type SurfaceScope, type SurfaceVerb, type VerifyResult, appendOnlyTables, documentMigrations, documentRoleStatements, documentStore, documentSurface, hashOf, physicalColumnsOf };
277
+ export { type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateWhere, type AppendOnlyTablesOptions, type CommitOutput, DEFAULT_DOCUMENT_TABLE, DEFAULT_REVISIONS_TABLE, DEFAULT_REVISION_KIND_COLUMN, type DocumentColumns, type DocumentKind, type DocumentMigrationsOptions, type DocumentPhysicalColumns, type DocumentRevisionsOptions, type DocumentSortColumn, type DocumentStore, type DocumentStoreOptions, type DocumentSurfaceOptions, HEAD_FIELDS, type HeadColumn, type HeadField, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type PendingCall, type ReinstateOutput, type RetireOutput, type SurfaceCall, type SurfaceRow, type SurfaceSchemaAdapter, type SurfaceScope, type SurfaceVerb, type VerifyResult, appendOnlyTables, documentMigrations, documentRoleStatements, documentStore, documentSurface, hashOf, physicalColumnsOf };
package/dist/store.js CHANGED
@@ -1,102 +1,29 @@
1
1
  import {
2
2
  Document,
3
- canTransition,
4
3
  canonicalOf,
5
4
  headFields,
6
5
  migrateBody,
7
- stampBody,
8
- systemActor
9
- } from "./chunk-WWP7MNI7.js";
6
+ stampBody
7
+ } from "./chunk-A6ZU4QU3.js";
8
+ import {
9
+ arrayOf,
10
+ booleanSchema,
11
+ canTransition,
12
+ literalOf,
13
+ merge,
14
+ nullable,
15
+ numberSchema,
16
+ optional,
17
+ stringSchema,
18
+ systemActor,
19
+ unknownSchema
20
+ } from "./chunk-NA3DLROL.js";
10
21
 
11
22
  // src/store/hash.ts
12
23
  import { createHash } from "crypto";
13
24
  var hashOf = (payload) => createHash("sha256").update(JSON.stringify(canonicalOf(payload))).digest("hex");
14
25
 
15
26
  // src/surface/table.ts
16
- var VENDOR = "geonosis-document-surface";
17
- var isString = (value) => typeof value === "string";
18
- var isNumber = (value) => typeof value === "number";
19
- var scalar = (test, message) => ({
20
- "~standard": {
21
- validate: (input) => test(input) ? { value: input } : { issues: [{ message }] },
22
- vendor: VENDOR,
23
- version: 1
24
- }
25
- });
26
- var stringSchema = scalar(isString, "expected a string");
27
- var numberSchema = scalar(isNumber, "expected a number");
28
- var booleanSchema = scalar(
29
- (value) => typeof value === "boolean",
30
- "expected a boolean"
31
- );
32
- var literalOf = (literal) => scalar(
33
- (value) => value === literal,
34
- `expected exactly ${JSON.stringify(literal)}`
35
- );
36
- var unknownSchema = {
37
- "~standard": { validate: (input) => ({ value: input }), vendor: VENDOR, version: 1 }
38
- };
39
- var syncResult = (schema, input) => {
40
- const result = schema["~standard"].validate(input);
41
- if (result instanceof Promise) {
42
- throw new Error(
43
- "a document surface schema validates synchronously; an async Standard Schema cannot back a row"
44
- );
45
- }
46
- return result;
47
- };
48
- var optional = (inner) => ({
49
- "~standard": {
50
- validate: (input) => input === void 0 ? { value: void 0 } : syncResult(inner, input),
51
- vendor: VENDOR,
52
- version: 1
53
- }
54
- });
55
- var nullable = (inner) => ({
56
- "~standard": {
57
- validate: (input) => input === null ? { value: null } : syncResult(inner, input),
58
- vendor: VENDOR,
59
- version: 1
60
- }
61
- });
62
- var arrayOf = (item) => ({
63
- "~standard": {
64
- validate: (input) => {
65
- if (!Array.isArray(input)) return { issues: [{ message: "expected an array" }] };
66
- const value = [];
67
- const issues = [];
68
- input.forEach((one, at) => {
69
- const result = syncResult(item, one);
70
- if (result.issues !== void 0) {
71
- issues.push(
72
- ...result.issues.map((issue) => ({ ...issue, path: [at, ...issue.path ?? []] }))
73
- );
74
- } else {
75
- value.push(result.value);
76
- }
77
- });
78
- return issues.length > 0 ? { issues } : { value };
79
- },
80
- vendor: VENDOR,
81
- version: 1
82
- }
83
- });
84
- var merge = (schemas) => ({
85
- "~standard": {
86
- validate: (input) => {
87
- let value = {};
88
- const issues = [];
89
- for (const schema of schemas) {
90
- const result = syncResult(schema, input);
91
- if (result.issues !== void 0) issues.push(...result.issues);
92
- else value = { ...value, ...result.value };
93
- }
94
- return issues.length > 0 ? { issues } : { value };
95
- },
96
- vendor: VENDOR,
97
- version: 1
98
- }
99
- });
100
27
  var doorFor = (store, name) => {
101
28
  const door = store[name];
102
29
  if (door === void 0) {