@geonosis/document 0.10.1 → 0.11.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 +11 -0
- package/README.md +8 -1
- package/dist/core/document.cjs +28 -14
- package/dist/core/document.d.cts +6 -0
- package/dist/core/document.d.ts +6 -0
- package/dist/core/document.js +28 -14
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -0
- package/dist/store/store.cjs +26 -2
- package/dist/store/store.d.cts +12 -0
- package/dist/store/store.d.ts +12 -0
- package/dist/store/store.js +28 -2
- package/dist/store.d.cts +1 -1
- package/dist/store.d.ts +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @geonosis/document
|
|
2
2
|
|
|
3
|
+
## 0.11.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 2cc5f78: `store.headCensus({ entity? })` reads every stored head of the tenant and counts the rows the current `Document.head` refuses, by field and reason (an impossible date, a missing status), naming each row by entity and number (#131). It writes nothing. Run it against a database an older version wrote before deploying a version that reads it more strictly. `headRefusalsOf(head)` is the same judgement for one head: the validator and the census read one function, so they cannot disagree. `Document.requiredHeadFields` sits beside `Document.headFields`, so a fold reads both from one place; the top-level `requiredHeadFields` export stays. `DocumentStore` gains `headCensus` beside each entity's store.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [2cc5f78]
|
|
12
|
+
- @geonosis/workflows@0.10.0
|
|
13
|
+
|
|
3
14
|
## 0.10.1
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ are each bound to `StandardSchemaV1` alone (`@standard-schema/spec`, types only
|
|
|
15
15
|
hand-built `{ '~standard': { validate, vendor, version } }` object all satisfy it equally). Document
|
|
16
16
|
shouldn't know anything about schema; we extend, we do it.
|
|
17
17
|
|
|
18
|
-
`Document = { headFields, head, recordFields, record, extend }`. `headFields` is the declarative
|
|
18
|
+
`Document = { headFields, requiredHeadFields, head, recordFields, record, extend }`. `headFields` is the declarative
|
|
19
19
|
FIELD SPEC every document's indexed facts are named from — `{ status: 'text', issueDate:
|
|
20
20
|
'calendarDate', dueDate: 'calendarDate', counterparty: 'text', externalRef: 'text', revision:
|
|
21
21
|
'text', total: 'decimal' }`, every field nullable but the ones `requiredHeadFields` names — `status`,
|
|
@@ -239,6 +239,13 @@ declares no `view` of its own renders its body, and a store built for one that d
|
|
|
239
239
|
`purge` on the documents — in the shape `relocateTenant` from `@geonosis/db` moves a table by; a
|
|
240
240
|
log's rows are written byte for byte, so a moved lineage still `verify`s.
|
|
241
241
|
|
|
242
|
+
`store.headCensus({ entity? })` reads every stored head of the tenant and counts the rows the
|
|
243
|
+
current `Document.head` refuses, by field and reason (`status: missing`, or an `issueDate` that is
|
|
244
|
+
no calendar date), and names each one by entity and number; it writes nothing. A
|
|
245
|
+
database an older version wrote can hold heads a stricter read now refuses. Run the census against
|
|
246
|
+
it, from wherever that database is reachable, before deploying the version that reads it.
|
|
247
|
+
`headRefusalsOf(head)` is the same judgement for one head, the one `Document.head` makes.
|
|
248
|
+
|
|
242
249
|
`numberFor({ counter, scope, seam })` (`@geonosis/document/store`) is the workflows' `counter` port read
|
|
243
250
|
from a `defineCounter` table: `scope(ctx)` names the handle and the tenant of the run, and the number
|
|
244
251
|
is the counter's own `next` — one atomic statement, so racing creates are issued a number each.
|
package/dist/core/document.cjs
CHANGED
|
@@ -42,6 +42,7 @@ __export(exports_document, {
|
|
|
42
42
|
Document: () => Document,
|
|
43
43
|
fieldPatterns: () => fieldPatterns,
|
|
44
44
|
headFields: () => headFields,
|
|
45
|
+
headRefusalsOf: () => headRefusalsOf,
|
|
45
46
|
recordFields: () => recordFields,
|
|
46
47
|
requiredHeadFields: () => requiredHeadFields,
|
|
47
48
|
validatorOf: () => validatorOf
|
|
@@ -73,26 +74,34 @@ var FIELD_CHECKS = {
|
|
|
73
74
|
},
|
|
74
75
|
text: { message: "a string", test: (value) => typeof value === "string" }
|
|
75
76
|
};
|
|
77
|
+
var refusalsIn = (fields, options, record) => Object.entries(fields).flatMap(([key, kind]) => {
|
|
78
|
+
const held = record[key];
|
|
79
|
+
if (options.nullable && held === null && !options.required.includes(key))
|
|
80
|
+
return [];
|
|
81
|
+
return FIELD_CHECKS[kind].test(held) ? [] : [
|
|
82
|
+
{
|
|
83
|
+
field: key,
|
|
84
|
+
message: FIELD_CHECKS[kind].message,
|
|
85
|
+
missing: held === null || held === undefined
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
});
|
|
89
|
+
var isObject = (input) => input !== null && typeof input === "object";
|
|
76
90
|
var validatorOf = (fields, options) => {
|
|
77
91
|
const nullable = options?.nullable ?? false;
|
|
78
92
|
const required = options?.required ?? [];
|
|
79
93
|
return import_schema.schemaOf((input) => {
|
|
80
|
-
if (input
|
|
94
|
+
if (!isObject(input))
|
|
81
95
|
return { issues: [{ message: "expected an object" }] };
|
|
96
|
+
const refusals = refusalsIn(fields, { nullable, required }, input);
|
|
97
|
+
if (refusals.length > 0) {
|
|
98
|
+
return {
|
|
99
|
+
issues: refusals.map((one) => ({ message: one.message, path: [{ key: one.field }] }))
|
|
100
|
+
};
|
|
82
101
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
for (const [key, kind] of Object.entries(fields)) {
|
|
87
|
-
const held = record[key];
|
|
88
|
-
value[key] = held;
|
|
89
|
-
if (nullable && held === null && !required.includes(key))
|
|
90
|
-
continue;
|
|
91
|
-
if (!FIELD_CHECKS[kind].test(held)) {
|
|
92
|
-
issues.push({ message: FIELD_CHECKS[kind].message, path: [{ key }] });
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return issues.length > 0 ? { issues } : { value };
|
|
102
|
+
return {
|
|
103
|
+
value: Object.fromEntries(Object.keys(fields).map((key) => [key, input[key]]))
|
|
104
|
+
};
|
|
96
105
|
});
|
|
97
106
|
};
|
|
98
107
|
var parseWith = (schema, input) => {
|
|
@@ -124,10 +133,15 @@ var headValidator = validatorOf(headFields, {
|
|
|
124
133
|
nullable: true,
|
|
125
134
|
required: requiredHeadFields
|
|
126
135
|
});
|
|
136
|
+
var headRefusalsOf = (head) => isObject(head) ? refusalsIn(headFields, { nullable: true, required: requiredHeadFields }, head).map((one) => ({
|
|
137
|
+
field: one.field,
|
|
138
|
+
reason: one.missing ? "missing" : one.message
|
|
139
|
+
})) : [{ field: "head", reason: "expected an object" }];
|
|
127
140
|
var recordValidator = validatorOf(recordFields);
|
|
128
141
|
var Document = {
|
|
129
142
|
head: headValidator,
|
|
130
143
|
headFields,
|
|
144
|
+
requiredHeadFields,
|
|
131
145
|
record: recordValidator,
|
|
132
146
|
recordFields,
|
|
133
147
|
extend: (definition) => ({
|
package/dist/core/document.d.cts
CHANGED
|
@@ -37,6 +37,11 @@ export type DocumentRecord = {
|
|
|
37
37
|
createdAt: number;
|
|
38
38
|
updatedAt: number;
|
|
39
39
|
};
|
|
40
|
+
export type HeadRefusal = {
|
|
41
|
+
field: string;
|
|
42
|
+
reason: string;
|
|
43
|
+
};
|
|
44
|
+
export declare const headRefusalsOf: (head: unknown) => HeadRefusal[];
|
|
40
45
|
export type DocumentDefinition<Name extends string, BodySchema extends StandardSchemaV1, DraftSchema extends StandardSchemaV1, IncomingSchema extends StandardSchemaV1, Status extends string, CardSchema extends StandardSchemaV1, Path extends string, ViewSchema extends StandardSchemaV1 = BodySchema> = {
|
|
41
46
|
name: Name;
|
|
42
47
|
noun: string;
|
|
@@ -90,6 +95,7 @@ export declare const Document: {
|
|
|
90
95
|
readonly revision: 'text';
|
|
91
96
|
readonly total: 'decimal';
|
|
92
97
|
};
|
|
98
|
+
requiredHeadFields: readonly ["status"];
|
|
93
99
|
record: StandardSchemaV1<unknown, DocumentRecord>;
|
|
94
100
|
recordFields: {
|
|
95
101
|
readonly version: 'positiveInt';
|
package/dist/core/document.d.ts
CHANGED
|
@@ -37,6 +37,11 @@ export type DocumentRecord = {
|
|
|
37
37
|
createdAt: number;
|
|
38
38
|
updatedAt: number;
|
|
39
39
|
};
|
|
40
|
+
export type HeadRefusal = {
|
|
41
|
+
field: string;
|
|
42
|
+
reason: string;
|
|
43
|
+
};
|
|
44
|
+
export declare const headRefusalsOf: (head: unknown) => HeadRefusal[];
|
|
40
45
|
export type DocumentDefinition<Name extends string, BodySchema extends StandardSchemaV1, DraftSchema extends StandardSchemaV1, IncomingSchema extends StandardSchemaV1, Status extends string, CardSchema extends StandardSchemaV1, Path extends string, ViewSchema extends StandardSchemaV1 = BodySchema> = {
|
|
41
46
|
name: Name;
|
|
42
47
|
noun: string;
|
|
@@ -90,6 +95,7 @@ export declare const Document: {
|
|
|
90
95
|
readonly revision: 'text';
|
|
91
96
|
readonly total: 'decimal';
|
|
92
97
|
};
|
|
98
|
+
requiredHeadFields: readonly ["status"];
|
|
93
99
|
record: StandardSchemaV1<unknown, DocumentRecord>;
|
|
94
100
|
recordFields: {
|
|
95
101
|
readonly version: 'positiveInt';
|
package/dist/core/document.js
CHANGED
|
@@ -25,26 +25,34 @@ var FIELD_CHECKS = {
|
|
|
25
25
|
},
|
|
26
26
|
text: { message: "a string", test: (value) => typeof value === "string" }
|
|
27
27
|
};
|
|
28
|
+
var refusalsIn = (fields, options, record) => Object.entries(fields).flatMap(([key, kind]) => {
|
|
29
|
+
const held = record[key];
|
|
30
|
+
if (options.nullable && held === null && !options.required.includes(key))
|
|
31
|
+
return [];
|
|
32
|
+
return FIELD_CHECKS[kind].test(held) ? [] : [
|
|
33
|
+
{
|
|
34
|
+
field: key,
|
|
35
|
+
message: FIELD_CHECKS[kind].message,
|
|
36
|
+
missing: held === null || held === undefined
|
|
37
|
+
}
|
|
38
|
+
];
|
|
39
|
+
});
|
|
40
|
+
var isObject = (input) => input !== null && typeof input === "object";
|
|
28
41
|
var validatorOf = (fields, options) => {
|
|
29
42
|
const nullable = options?.nullable ?? false;
|
|
30
43
|
const required = options?.required ?? [];
|
|
31
44
|
return schemaOf((input) => {
|
|
32
|
-
if (input
|
|
45
|
+
if (!isObject(input))
|
|
33
46
|
return { issues: [{ message: "expected an object" }] };
|
|
47
|
+
const refusals = refusalsIn(fields, { nullable, required }, input);
|
|
48
|
+
if (refusals.length > 0) {
|
|
49
|
+
return {
|
|
50
|
+
issues: refusals.map((one) => ({ message: one.message, path: [{ key: one.field }] }))
|
|
51
|
+
};
|
|
34
52
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
for (const [key, kind] of Object.entries(fields)) {
|
|
39
|
-
const held = record[key];
|
|
40
|
-
value[key] = held;
|
|
41
|
-
if (nullable && held === null && !required.includes(key))
|
|
42
|
-
continue;
|
|
43
|
-
if (!FIELD_CHECKS[kind].test(held)) {
|
|
44
|
-
issues.push({ message: FIELD_CHECKS[kind].message, path: [{ key }] });
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return issues.length > 0 ? { issues } : { value };
|
|
53
|
+
return {
|
|
54
|
+
value: Object.fromEntries(Object.keys(fields).map((key) => [key, input[key]]))
|
|
55
|
+
};
|
|
48
56
|
});
|
|
49
57
|
};
|
|
50
58
|
var parseWith = (schema, input) => {
|
|
@@ -76,10 +84,15 @@ var headValidator = validatorOf(headFields, {
|
|
|
76
84
|
nullable: true,
|
|
77
85
|
required: requiredHeadFields
|
|
78
86
|
});
|
|
87
|
+
var headRefusalsOf = (head) => isObject(head) ? refusalsIn(headFields, { nullable: true, required: requiredHeadFields }, head).map((one) => ({
|
|
88
|
+
field: one.field,
|
|
89
|
+
reason: one.missing ? "missing" : one.message
|
|
90
|
+
})) : [{ field: "head", reason: "expected an object" }];
|
|
79
91
|
var recordValidator = validatorOf(recordFields);
|
|
80
92
|
var Document = {
|
|
81
93
|
head: headValidator,
|
|
82
94
|
headFields,
|
|
95
|
+
requiredHeadFields,
|
|
83
96
|
record: recordValidator,
|
|
84
97
|
recordFields,
|
|
85
98
|
extend: (definition) => ({
|
|
@@ -93,6 +106,7 @@ export {
|
|
|
93
106
|
Document,
|
|
94
107
|
fieldPatterns,
|
|
95
108
|
headFields,
|
|
109
|
+
headRefusalsOf,
|
|
96
110
|
recordFields,
|
|
97
111
|
requiredHeadFields,
|
|
98
112
|
validatorOf
|
package/dist/index.cjs
CHANGED
|
@@ -50,6 +50,7 @@ __export(exports_src, {
|
|
|
50
50
|
documentIdentifiers: () => import_naming.documentIdentifiers,
|
|
51
51
|
enumOf: () => import_schema.enumOf,
|
|
52
52
|
fieldPatterns: () => import_document.fieldPatterns,
|
|
53
|
+
headRefusalsOf: () => import_document.headRefusalsOf,
|
|
53
54
|
isSystemActor: () => import_actor.isSystemActor,
|
|
54
55
|
isTerminalStatus: () => import_status.isTerminalStatus,
|
|
55
56
|
literalOf: () => import_schema.literalOf,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { BODY_VERSION_KEY, documentBodyVersioning, migrateBody, stampBody, type DocumentBodyMigrations, type DocumentBodyVersion } from './core/body-version.cjs';
|
|
2
|
-
export { Document, fieldPatterns, requiredHeadFields, validatorOf, type BodyOf, type CardOf, type DocumentDefinition, type DocumentEntity, type DocumentHead, type DocumentInstance, type DocumentRecord, type DraftOf, type FieldKind, type IncomingOf, type InstanceOf, type NameOf, type StatusOf, type ViewOf } from './core/document.cjs';
|
|
2
|
+
export { Document, fieldPatterns, headRefusalsOf, requiredHeadFields, validatorOf, type BodyOf, type CardOf, type DocumentDefinition, type DocumentEntity, type DocumentHead, type DocumentInstance, type DocumentRecord, type DraftOf, type FieldKind, type HeadRefusal, type IncomingOf, type InstanceOf, type NameOf, type StatusOf, type ViewOf } from './core/document.cjs';
|
|
3
3
|
export { documentEntities, type AnyDocumentEntity } from './core/entities.cjs';
|
|
4
4
|
export { arrayOf, booleanSchema, enumOf, literalOf, merge, nonEmptyString, nullable, numberSchema, objectOf, optional, positiveInt, type SchemaAdapter, stringSchema, unknownSchema, validate } from './core/schema.cjs';
|
|
5
5
|
export { isSystemActor, systemActor } from './core/actor.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { BODY_VERSION_KEY, documentBodyVersioning, migrateBody, stampBody, type DocumentBodyMigrations, type DocumentBodyVersion } from './core/body-version.js';
|
|
2
|
-
export { Document, fieldPatterns, requiredHeadFields, validatorOf, type BodyOf, type CardOf, type DocumentDefinition, type DocumentEntity, type DocumentHead, type DocumentInstance, type DocumentRecord, type DraftOf, type FieldKind, type IncomingOf, type InstanceOf, type NameOf, type StatusOf, type ViewOf } from './core/document.js';
|
|
2
|
+
export { Document, fieldPatterns, headRefusalsOf, requiredHeadFields, validatorOf, type BodyOf, type CardOf, type DocumentDefinition, type DocumentEntity, type DocumentHead, type DocumentInstance, type DocumentRecord, type DraftOf, type FieldKind, type HeadRefusal, type IncomingOf, type InstanceOf, type NameOf, type StatusOf, type ViewOf } from './core/document.js';
|
|
3
3
|
export { documentEntities, type AnyDocumentEntity } from './core/entities.js';
|
|
4
4
|
export { arrayOf, booleanSchema, enumOf, literalOf, merge, nonEmptyString, nullable, numberSchema, objectOf, optional, positiveInt, type SchemaAdapter, stringSchema, unknownSchema, validate } from './core/schema.js';
|
|
5
5
|
export { isSystemActor, systemActor } from './core/actor.js';
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import {
|
|
9
9
|
Document,
|
|
10
10
|
fieldPatterns,
|
|
11
|
+
headRefusalsOf,
|
|
11
12
|
requiredHeadFields,
|
|
12
13
|
validatorOf
|
|
13
14
|
} from "./core/document.js";
|
|
@@ -44,6 +45,7 @@ export {
|
|
|
44
45
|
documentIdentifiers,
|
|
45
46
|
enumOf,
|
|
46
47
|
fieldPatterns,
|
|
48
|
+
headRefusalsOf,
|
|
47
49
|
isSystemActor,
|
|
48
50
|
isTerminalStatus,
|
|
49
51
|
literalOf,
|
package/dist/store/store.cjs
CHANGED
|
@@ -46,6 +46,7 @@ var import_db = require("@geonosis/db");
|
|
|
46
46
|
var import_actor = require("../core/actor.cjs");
|
|
47
47
|
var import_body_version = require("../core/body-version.cjs");
|
|
48
48
|
var import_canonical = require("../core/canonical.cjs");
|
|
49
|
+
var import_document = require("../core/document.cjs");
|
|
49
50
|
var import_ddl = require("./ddl.cjs");
|
|
50
51
|
var import_hash = require("./hash.cjs");
|
|
51
52
|
var UNDO_ACTOR = import_actor.systemActor("document.undo");
|
|
@@ -565,7 +566,7 @@ var documentStore = (options) => {
|
|
|
565
566
|
const built = registry.names.map((name) => [name, entityStoreFor(name)]);
|
|
566
567
|
const rawEntities = Object.fromEntries(built.map(([name, one]) => [name, one.door]));
|
|
567
568
|
const restorers = Object.fromEntries(built.map(([name, one]) => [name, one.restore]));
|
|
568
|
-
const
|
|
569
|
+
const headsIn = async (tx, params) => {
|
|
569
570
|
const { entity, order, where } = params;
|
|
570
571
|
const columns = params.columns === "all" ? ALL_HEAD_COLUMNS : params.columns;
|
|
571
572
|
const rows = await readers.project(tx, {
|
|
@@ -578,6 +579,29 @@ var documentStore = (options) => {
|
|
|
578
579
|
}
|
|
579
580
|
});
|
|
580
581
|
return rows.map((row) => Object.fromEntries(columns.map((column) => [column, column === "number" ? row.key : row[columnOf(column)]])));
|
|
582
|
+
};
|
|
583
|
+
const heads = seam.scoped(headsIn);
|
|
584
|
+
const headCensus = seam.scoped(async (tx, params) => {
|
|
585
|
+
const rows = await headsIn(tx, {
|
|
586
|
+
...params,
|
|
587
|
+
columns: "all",
|
|
588
|
+
order: [{ column: "entity" }, { column: "number" }]
|
|
589
|
+
});
|
|
590
|
+
const reasons = {};
|
|
591
|
+
const refused = [];
|
|
592
|
+
for (const row of rows) {
|
|
593
|
+
const found = import_document.headRefusalsOf(row).map((one) => `${one.field}: ${one.reason}`);
|
|
594
|
+
if (found.length === 0)
|
|
595
|
+
continue;
|
|
596
|
+
for (const reason of found)
|
|
597
|
+
reasons[reason] = (reasons[reason] ?? 0) + 1;
|
|
598
|
+
refused.push({
|
|
599
|
+
entity: String(row["entity"]),
|
|
600
|
+
number: String(row["number"]),
|
|
601
|
+
reasons: found
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
return { reasons, refused, rows: rows.length };
|
|
581
605
|
});
|
|
582
606
|
const aggregate = seam.scoped((tx, params) => {
|
|
583
607
|
const { by, entities, entity, measures, where } = params;
|
|
@@ -628,5 +652,5 @@ var documentStore = (options) => {
|
|
|
628
652
|
documents: readers,
|
|
629
653
|
...revisions === undefined ? {} : { revisions }
|
|
630
654
|
};
|
|
631
|
-
return { ...rawEntities, aggregate, heads, list: listEverywhere, rebuild, tables };
|
|
655
|
+
return { ...rawEntities, aggregate, headCensus, heads, list: listEverywhere, rebuild, tables };
|
|
632
656
|
};
|
package/dist/store/store.d.cts
CHANGED
|
@@ -65,6 +65,15 @@ export type HeadsArgs<Columns extends readonly HeadColumn[] | 'all' = readonly H
|
|
|
65
65
|
order: readonly HeadsOrder[];
|
|
66
66
|
where?: HeadsWhere;
|
|
67
67
|
};
|
|
68
|
+
export type HeadCensus = {
|
|
69
|
+
reasons: Readonly<Record<string, number>>;
|
|
70
|
+
refused: {
|
|
71
|
+
entity: string;
|
|
72
|
+
number: string;
|
|
73
|
+
reasons: string[];
|
|
74
|
+
}[];
|
|
75
|
+
rows: number;
|
|
76
|
+
};
|
|
68
77
|
export type AggregateMeasure = 'count' | 'sum:total';
|
|
69
78
|
export type AggregateBy = HeadField | 'entity' | {
|
|
70
79
|
bucket: 'day' | 'month' | 'week';
|
|
@@ -198,6 +207,9 @@ export type DocumentStore<Map extends Readonly<Record<string, StorableDocumentEn
|
|
|
198
207
|
} & {
|
|
199
208
|
aggregate: Query<Readonly<Record<Key, string>> & AggregateArgs, AggregateRow[], Handle>;
|
|
200
209
|
heads: <Columns extends readonly HeadColumn[] | 'all'>(handle: Handle, params: Readonly<Record<Key, string>> & HeadsArgs<Columns>) => Promise<HeadRow<Columns>[]>;
|
|
210
|
+
headCensus: Query<Readonly<Record<Key, string>> & {
|
|
211
|
+
entity?: string;
|
|
212
|
+
}, HeadCensus, Handle>;
|
|
201
213
|
list: DocumentList<Key, Handle>;
|
|
202
214
|
rebuild: Query<Readonly<Record<Key, string>> & {
|
|
203
215
|
entity?: string;
|
package/dist/store/store.d.ts
CHANGED
|
@@ -65,6 +65,15 @@ export type HeadsArgs<Columns extends readonly HeadColumn[] | 'all' = readonly H
|
|
|
65
65
|
order: readonly HeadsOrder[];
|
|
66
66
|
where?: HeadsWhere;
|
|
67
67
|
};
|
|
68
|
+
export type HeadCensus = {
|
|
69
|
+
reasons: Readonly<Record<string, number>>;
|
|
70
|
+
refused: {
|
|
71
|
+
entity: string;
|
|
72
|
+
number: string;
|
|
73
|
+
reasons: string[];
|
|
74
|
+
}[];
|
|
75
|
+
rows: number;
|
|
76
|
+
};
|
|
68
77
|
export type AggregateMeasure = 'count' | 'sum:total';
|
|
69
78
|
export type AggregateBy = HeadField | 'entity' | {
|
|
70
79
|
bucket: 'day' | 'month' | 'week';
|
|
@@ -198,6 +207,9 @@ export type DocumentStore<Map extends Readonly<Record<string, StorableDocumentEn
|
|
|
198
207
|
} & {
|
|
199
208
|
aggregate: Query<Readonly<Record<Key, string>> & AggregateArgs, AggregateRow[], Handle>;
|
|
200
209
|
heads: <Columns extends readonly HeadColumn[] | 'all'>(handle: Handle, params: Readonly<Record<Key, string>> & HeadsArgs<Columns>) => Promise<HeadRow<Columns>[]>;
|
|
210
|
+
headCensus: Query<Readonly<Record<Key, string>> & {
|
|
211
|
+
entity?: string;
|
|
212
|
+
}, HeadCensus, Handle>;
|
|
201
213
|
list: DocumentList<Key, Handle>;
|
|
202
214
|
rebuild: Query<Readonly<Record<Key, string>> & {
|
|
203
215
|
entity?: string;
|
package/dist/store/store.js
CHANGED
|
@@ -8,6 +8,9 @@ import {
|
|
|
8
8
|
import { systemActor } from "../core/actor.js";
|
|
9
9
|
import { migrateBody, stampBody } from "../core/body-version.js";
|
|
10
10
|
import { canonicalOf } from "../core/canonical.js";
|
|
11
|
+
import {
|
|
12
|
+
headRefusalsOf
|
|
13
|
+
} from "../core/document.js";
|
|
11
14
|
import {
|
|
12
15
|
DEFAULT_DOCUMENT_TABLE,
|
|
13
16
|
DEFAULT_REVISION_KIND_COLUMN,
|
|
@@ -535,7 +538,7 @@ var documentStore = (options) => {
|
|
|
535
538
|
const built = registry.names.map((name) => [name, entityStoreFor(name)]);
|
|
536
539
|
const rawEntities = Object.fromEntries(built.map(([name, one]) => [name, one.door]));
|
|
537
540
|
const restorers = Object.fromEntries(built.map(([name, one]) => [name, one.restore]));
|
|
538
|
-
const
|
|
541
|
+
const headsIn = async (tx, params) => {
|
|
539
542
|
const { entity, order, where } = params;
|
|
540
543
|
const columns = params.columns === "all" ? ALL_HEAD_COLUMNS : params.columns;
|
|
541
544
|
const rows = await readers.project(tx, {
|
|
@@ -548,6 +551,29 @@ var documentStore = (options) => {
|
|
|
548
551
|
}
|
|
549
552
|
});
|
|
550
553
|
return rows.map((row) => Object.fromEntries(columns.map((column) => [column, column === "number" ? row.key : row[columnOf(column)]])));
|
|
554
|
+
};
|
|
555
|
+
const heads = seam.scoped(headsIn);
|
|
556
|
+
const headCensus = seam.scoped(async (tx, params) => {
|
|
557
|
+
const rows = await headsIn(tx, {
|
|
558
|
+
...params,
|
|
559
|
+
columns: "all",
|
|
560
|
+
order: [{ column: "entity" }, { column: "number" }]
|
|
561
|
+
});
|
|
562
|
+
const reasons = {};
|
|
563
|
+
const refused = [];
|
|
564
|
+
for (const row of rows) {
|
|
565
|
+
const found = headRefusalsOf(row).map((one) => `${one.field}: ${one.reason}`);
|
|
566
|
+
if (found.length === 0)
|
|
567
|
+
continue;
|
|
568
|
+
for (const reason of found)
|
|
569
|
+
reasons[reason] = (reasons[reason] ?? 0) + 1;
|
|
570
|
+
refused.push({
|
|
571
|
+
entity: String(row["entity"]),
|
|
572
|
+
number: String(row["number"]),
|
|
573
|
+
reasons: found
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
return { reasons, refused, rows: rows.length };
|
|
551
577
|
});
|
|
552
578
|
const aggregate = seam.scoped((tx, params) => {
|
|
553
579
|
const { by, entities, entity, measures, where } = params;
|
|
@@ -598,7 +624,7 @@ var documentStore = (options) => {
|
|
|
598
624
|
documents: readers,
|
|
599
625
|
...revisions === undefined ? {} : { revisions }
|
|
600
626
|
};
|
|
601
|
-
return { ...rawEntities, aggregate, heads, list: listEverywhere, rebuild, tables };
|
|
627
|
+
return { ...rawEntities, aggregate, headCensus, heads, list: listEverywhere, rebuild, tables };
|
|
602
628
|
};
|
|
603
629
|
export {
|
|
604
630
|
documentStore
|
package/dist/store.d.cts
CHANGED
|
@@ -2,4 +2,4 @@ export { hashOf } from './store/hash.cjs';
|
|
|
2
2
|
export { documentSurface, type DocumentSurfaceOptions, type SurfaceResolve, type SurfaceCall, type SurfaceRow, type SurfaceScope, type SurfaceSchemaAdapter, type SurfaceVerb } from './surface/table.cjs';
|
|
3
3
|
export { appendOnlyTables, DEFAULT_DOCUMENT_TABLE, DEFAULT_REVISION_KIND_COLUMN, DEFAULT_REVISIONS_TABLE, DOCUMENT_MIGRATION_PLACEHOLDERS, documentMigrations, documentRoleStatements, HEAD_FIELDS, type AppendOnlyTablesOptions, type DocumentColumns, type DocumentMigrationsOptions, type DocumentPhysicalColumns, type DocumentRevisionsOptions, type HeadField, physicalColumnsOf } from './store/ddl.cjs';
|
|
4
4
|
export { numberFor } from './store/number-for.cjs';
|
|
5
|
-
export { documentStore, type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateRow, type AggregateWhere, type CommitOutput, type DocumentKind, type DocumentList, type DocumentListing, type DocumentSearchPort, type DocumentSortColumn, type DocumentStore, type DocumentStoreOptions, type DocumentTables, type DocumentViews, type HeadColumn, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type ReinstateOutput, type RetireOutput, type VerifyResult } from './store/store.cjs';
|
|
5
|
+
export { documentStore, type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateRow, type AggregateWhere, type CommitOutput, type DocumentKind, type DocumentList, type DocumentListing, type DocumentSearchPort, type DocumentSortColumn, type DocumentStore, type DocumentStoreOptions, type DocumentTables, type DocumentViews, type HeadCensus, type HeadColumn, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type ReinstateOutput, type RetireOutput, type VerifyResult } from './store/store.cjs';
|
package/dist/store.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { hashOf } from './store/hash.js';
|
|
|
2
2
|
export { documentSurface, type DocumentSurfaceOptions, type SurfaceResolve, type SurfaceCall, type SurfaceRow, type SurfaceScope, type SurfaceSchemaAdapter, type SurfaceVerb } from './surface/table.js';
|
|
3
3
|
export { appendOnlyTables, DEFAULT_DOCUMENT_TABLE, DEFAULT_REVISION_KIND_COLUMN, DEFAULT_REVISIONS_TABLE, DOCUMENT_MIGRATION_PLACEHOLDERS, documentMigrations, documentRoleStatements, HEAD_FIELDS, type AppendOnlyTablesOptions, type DocumentColumns, type DocumentMigrationsOptions, type DocumentPhysicalColumns, type DocumentRevisionsOptions, type HeadField, physicalColumnsOf } from './store/ddl.js';
|
|
4
4
|
export { numberFor } from './store/number-for.js';
|
|
5
|
-
export { documentStore, type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateRow, type AggregateWhere, type CommitOutput, type DocumentKind, type DocumentList, type DocumentListing, type DocumentSearchPort, type DocumentSortColumn, type DocumentStore, type DocumentStoreOptions, type DocumentTables, type DocumentViews, type HeadColumn, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type ReinstateOutput, type RetireOutput, type VerifyResult } from './store/store.js';
|
|
5
|
+
export { documentStore, type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateRow, type AggregateWhere, type CommitOutput, type DocumentKind, type DocumentList, type DocumentListing, type DocumentSearchPort, type DocumentSortColumn, type DocumentStore, type DocumentStoreOptions, type DocumentTables, type DocumentViews, type HeadCensus, type HeadColumn, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type ReinstateOutput, type RetireOutput, type VerifyResult } from './store/store.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geonosis/document",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.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": [
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@geonosis/db": "^0.15.1",
|
|
62
|
-
"@geonosis/workflows": "^0.
|
|
62
|
+
"@geonosis/workflows": "^0.10.0",
|
|
63
63
|
"@standard-schema/spec": "^1.1.0",
|
|
64
64
|
"better-result": "^3.0.1"
|
|
65
65
|
},
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"scripts": {
|
|
88
88
|
"build": "bun ../../tooling/build-step.ts bun ../../tooling/bundle.ts",
|
|
89
89
|
"typecheck": "tsc --noEmit",
|
|
90
|
-
"lint": "oxlint --config ../../.oxlintrc.json .",
|
|
90
|
+
"lint": "oxlint --report-unused-disable-directives-severity=error --config ../../.oxlintrc.json .",
|
|
91
91
|
"test:unit": "vitest run --project unit --root ../.. --passWithNoTests \"$PWD\"",
|
|
92
92
|
"test:bin": "vitest run --project bin --root ../.. --passWithNoTests \"$PWD\"",
|
|
93
93
|
"test:exam": "vitest run --project exam --root ../.. --passWithNoTests \"$PWD\""
|