@geonosis/document 0.9.3 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/README.md +78 -13
- package/dist/core/actor.d.cts +0 -1
- package/dist/core/actor.d.ts +0 -1
- package/dist/core/body-version.d.cts +0 -9
- package/dist/core/body-version.d.ts +0 -9
- package/dist/core/canonical.cjs +2 -3
- package/dist/core/canonical.d.cts +0 -4
- package/dist/core/canonical.d.ts +0 -4
- package/dist/core/canonical.js +2 -3
- package/dist/core/document.cjs +28 -25
- package/dist/core/document.d.cts +3 -22
- package/dist/core/document.d.ts +3 -22
- package/dist/core/document.js +28 -25
- package/dist/core/entities.d.cts +0 -19
- package/dist/core/entities.d.ts +0 -19
- package/dist/core/naming.d.cts +0 -5
- package/dist/core/naming.d.ts +0 -5
- package/dist/core/numbering.d.cts +0 -4
- package/dist/core/numbering.d.ts +0 -4
- package/dist/core/ports.d.cts +0 -6
- package/dist/core/ports.d.ts +0 -6
- package/dist/core/schema.cjs +44 -76
- package/dist/core/schema.d.cts +1 -13
- package/dist/core/schema.d.ts +1 -13
- package/dist/core/schema.js +44 -76
- package/dist/core/status.d.cts +0 -1
- package/dist/core/status.d.ts +0 -1
- 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/ddl.cjs +35 -38
- package/dist/store/ddl.d.cts +6 -6
- package/dist/store/ddl.d.ts +6 -6
- package/dist/store/ddl.js +37 -39
- package/dist/store/hash.d.cts +0 -1
- package/dist/store/hash.d.ts +0 -1
- package/dist/store/number-for.cjs +52 -0
- package/dist/store/number-for.d.cts +11 -0
- package/dist/store/number-for.d.ts +11 -0
- package/dist/store/number-for.js +12 -0
- package/dist/store/store.cjs +188 -162
- package/dist/store/store.d.cts +57 -16
- package/dist/store/store.d.ts +57 -16
- package/dist/store/store.js +190 -163
- package/dist/store.cjs +2 -0
- package/dist/store.d.cts +3 -2
- package/dist/store.d.ts +3 -2
- package/dist/store.js +2 -0
- package/dist/surface/table.cjs +129 -66
- package/dist/surface/table.d.cts +20 -28
- package/dist/surface/table.d.ts +20 -28
- package/dist/surface/table.js +132 -66
- package/dist/workflows/bindings.cjs +48 -0
- package/dist/workflows/bindings.d.cts +15 -0
- package/dist/workflows/bindings.d.ts +15 -0
- package/dist/workflows/bindings.js +10 -0
- package/dist/workflows/document-workflows.cjs +29 -40
- package/dist/workflows/document-workflows.d.cts +0 -12
- package/dist/workflows/document-workflows.d.ts +0 -12
- package/dist/workflows/document-workflows.js +29 -40
- package/dist/workflows/effects.d.cts +0 -12
- package/dist/workflows/effects.d.ts +0 -12
- package/dist/workflows/ports.d.cts +0 -17
- package/dist/workflows/ports.d.ts +0 -17
- package/dist/workflows/refusals.cjs +30 -0
- package/dist/workflows/refusals.d.cts +37 -9
- package/dist/workflows/refusals.d.ts +37 -9
- package/dist/workflows/refusals.js +30 -0
- package/dist/workflows/shared.cjs +93 -0
- package/dist/workflows/shared.d.cts +28 -0
- package/dist/workflows/shared.d.ts +28 -0
- package/dist/workflows/shared.js +60 -0
- package/dist/workflows.cjs +16 -1
- package/dist/workflows.d.cts +3 -1
- package/dist/workflows.d.ts +3 -1
- package/dist/workflows.js +31 -1
- package/package.json +4 -4
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, 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, 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';
|
|
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, 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, 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';
|
|
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
|
+
requiredHeadFields,
|
|
11
12
|
validatorOf
|
|
12
13
|
} from "./core/document.js";
|
|
13
14
|
import { documentEntities } from "./core/entities.js";
|
|
@@ -54,6 +55,7 @@ export {
|
|
|
54
55
|
objectOf,
|
|
55
56
|
optional,
|
|
56
57
|
positiveInt,
|
|
58
|
+
requiredHeadFields,
|
|
57
59
|
stampBody,
|
|
58
60
|
stringSchema,
|
|
59
61
|
systemActor,
|
package/dist/store/ddl.cjs
CHANGED
|
@@ -44,11 +44,13 @@ __export(exports_ddl, {
|
|
|
44
44
|
DEFAULT_REVISION_KIND_COLUMN: () => DEFAULT_REVISION_KIND_COLUMN,
|
|
45
45
|
DOCUMENT_MIGRATION_PLACEHOLDERS: () => import_db.ENTITY_PLACEHOLDERS,
|
|
46
46
|
HEAD_FIELDS: () => HEAD_FIELDS,
|
|
47
|
+
REVISION_KINDS: () => REVISION_KINDS,
|
|
47
48
|
appendOnlyTables: () => appendOnlyTables,
|
|
48
49
|
documentMigrations: () => documentMigrations,
|
|
49
50
|
documentRoleStatements: () => documentRoleStatements,
|
|
50
51
|
documentTable: () => documentTable,
|
|
51
|
-
physicalColumnsOf: () => physicalColumnsOf
|
|
52
|
+
physicalColumnsOf: () => physicalColumnsOf,
|
|
53
|
+
splitColumns: () => splitColumns
|
|
52
54
|
});
|
|
53
55
|
module.exports = __toCommonJS(exports_ddl);
|
|
54
56
|
var import_db = require("@geonosis/db");
|
|
@@ -78,34 +80,44 @@ var physicalColumnsOf = (columns) => {
|
|
|
78
80
|
updatedAt: nameOf(columns?.updatedAt, DEFAULT_UPDATED_AT_COLUMN)
|
|
79
81
|
};
|
|
80
82
|
};
|
|
83
|
+
var splitColumns = (columns) => {
|
|
84
|
+
const {
|
|
85
|
+
entity: _entity,
|
|
86
|
+
heads: _heads,
|
|
87
|
+
revisionKind: _revisionKind,
|
|
88
|
+
total: _total,
|
|
89
|
+
version,
|
|
90
|
+
...rest
|
|
91
|
+
} = columns ?? {};
|
|
92
|
+
return { rest, version: nameOf(version, DEFAULT_VERSION_COLUMN) };
|
|
93
|
+
};
|
|
81
94
|
var appendOnlyTables = (options = {}) => {
|
|
95
|
+
if (options.table !== undefined) {
|
|
96
|
+
throw new import_db.DbRefusal("`table` names the documents table everywhere else in this package, and the documents table is the one an application must update: name the log as `revisions: { table }`");
|
|
97
|
+
}
|
|
82
98
|
if (options.revisions === false)
|
|
83
99
|
return [];
|
|
84
|
-
return [options.revisions?.table ??
|
|
100
|
+
return [options.revisions?.table ?? DEFAULT_REVISIONS_TABLE];
|
|
85
101
|
};
|
|
86
|
-
var
|
|
87
|
-
var literalName = (value) => `'${value.replaceAll("'", "''")}'`;
|
|
102
|
+
var { quoted } = import_db.sqlFragments;
|
|
88
103
|
var documentRoleStatements = (appRole, options = {}) => {
|
|
89
104
|
if (typeof appRole !== "string" || appRole === "") {
|
|
90
105
|
throw new import_db.DbRefusal("documentRoleStatements needs an `appRole` — the name a consumer’s application connects as belongs to whoever runs the database, and one baked in here would be another repo’s");
|
|
91
106
|
}
|
|
92
|
-
const role =
|
|
93
|
-
const on = (table) => options.schema === undefined ?
|
|
107
|
+
const role = quoted(appRole);
|
|
108
|
+
const on = (table) => options.schema === undefined ? quoted(table) : `${quoted(options.schema)}.${quoted(table)}`;
|
|
94
109
|
return appendOnlyTables(options).flatMap((table) => [
|
|
95
110
|
`revoke update, delete on ${on(table)} from ${role}`,
|
|
96
111
|
`grant select, insert on ${on(table)} to ${role}`
|
|
97
112
|
]);
|
|
98
113
|
};
|
|
99
|
-
var
|
|
100
|
-
var headIndexedColumns = (physical) => HEAD_FIELDS.map((field) => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
};
|
|
107
|
-
});
|
|
108
|
-
var revisionKindType = (column) => `text check (${quotedName(column)} in (${REVISION_KINDS.map(literalName).join(", ")}))`;
|
|
114
|
+
var isNumeric = (field) => import_document.headFields[field] === "decimal";
|
|
115
|
+
var headIndexedColumns = (physical) => HEAD_FIELDS.map((field) => ({
|
|
116
|
+
column: physical[field],
|
|
117
|
+
nullable: field !== "status",
|
|
118
|
+
...isNumeric(field) ? { type: "numeric" } : {}
|
|
119
|
+
}));
|
|
120
|
+
var revisionKindType = (column) => `text check (${quoted(column)} in (${REVISION_KINDS.map((kind) => `'${kind}'`).join(", ")}))`;
|
|
109
121
|
var walls = (options) => ({
|
|
110
122
|
...options.freeze === undefined ? {} : { freeze: options.freeze },
|
|
111
123
|
...options.names === undefined ? {} : { names: options.names },
|
|
@@ -139,17 +151,10 @@ var revisionsMigrations = (options, physical) => {
|
|
|
139
151
|
var documentMigrations = (options) => {
|
|
140
152
|
const table = options.table ?? DEFAULT_DOCUMENT_TABLE;
|
|
141
153
|
const physical = physicalColumnsOf(options.columns);
|
|
142
|
-
const {
|
|
143
|
-
entity: _entity,
|
|
144
|
-
heads: _heads,
|
|
145
|
-
revisionKind: _revisionKind,
|
|
146
|
-
total: _total,
|
|
147
|
-
version,
|
|
148
|
-
...restColumns
|
|
149
|
-
} = options.columns ?? {};
|
|
154
|
+
const { rest: restColumns, version } = splitColumns(options.columns);
|
|
150
155
|
const [tableMigration, ...rest] = import_db.projectionMigrations({
|
|
151
156
|
carried: [{ column: "lineage", type: "integer not null default 1" }],
|
|
152
|
-
columns: { ...restColumns, sequence: version
|
|
157
|
+
columns: { ...restColumns, sequence: version },
|
|
153
158
|
constants: { [physical.entity]: "" },
|
|
154
159
|
indexed: headIndexedColumns(physical),
|
|
155
160
|
key: "number",
|
|
@@ -166,35 +171,27 @@ var documentMigrations = (options) => {
|
|
|
166
171
|
if (tableMigration === undefined) {
|
|
167
172
|
throw new Error("projectionMigrations answered with no table migration to append the listing index to");
|
|
168
173
|
}
|
|
169
|
-
const listingIndex = `create index if not exists ${
|
|
174
|
+
const listingIndex = `create index if not exists ${quoted(`${table}_${physical.entity}_${physical.issueDate}_idx`)} on ${quoted(table)} (${quoted(physical.entity)}, ${quoted(physical.issueDate)})`;
|
|
170
175
|
return [
|
|
171
176
|
{ ...tableMigration, statements: [...tableMigration.statements, listingIndex] },
|
|
172
177
|
...rest,
|
|
173
178
|
...revisionsMigrations(options, physical)
|
|
174
179
|
];
|
|
175
180
|
};
|
|
176
|
-
var TABLE_TYPE_OF = { decimal: "numeric" };
|
|
177
181
|
var documentTable = (options = {}) => {
|
|
178
182
|
const physical = physicalColumnsOf(options.columns);
|
|
179
|
-
const {
|
|
180
|
-
|
|
181
|
-
heads: _heads,
|
|
182
|
-
id,
|
|
183
|
-
revisionKind: _revisionKind,
|
|
184
|
-
total: _total,
|
|
185
|
-
version,
|
|
186
|
-
...restColumns
|
|
187
|
-
} = options.columns ?? {};
|
|
183
|
+
const { rest, version } = splitColumns(options.columns);
|
|
184
|
+
const { id, ...restColumns } = rest;
|
|
188
185
|
const named = Object.fromEntries(Object.entries(restColumns).map(([column, held]) => [column, nameOf(held, column)]));
|
|
189
186
|
return import_db.entityTable({
|
|
190
|
-
columns: { ...named, version
|
|
187
|
+
columns: { ...named, version },
|
|
191
188
|
constants: [physical.entity],
|
|
192
189
|
extra: {
|
|
193
190
|
...Object.fromEntries(HEAD_FIELDS.map((field) => [
|
|
194
191
|
physical[field],
|
|
195
192
|
{
|
|
196
193
|
nullable: field !== "status",
|
|
197
|
-
type:
|
|
194
|
+
type: isNumeric(field) ? "numeric" : "text"
|
|
198
195
|
}
|
|
199
196
|
])),
|
|
200
197
|
hash: "text",
|
package/dist/store/ddl.d.cts
CHANGED
|
@@ -5,6 +5,7 @@ export { ENTITY_PLACEHOLDERS as DOCUMENT_MIGRATION_PLACEHOLDERS };
|
|
|
5
5
|
export declare const DEFAULT_DOCUMENT_TABLE = "documents";
|
|
6
6
|
export declare const DEFAULT_REVISIONS_TABLE = "document_revisions";
|
|
7
7
|
export declare const DEFAULT_REVISION_KIND_COLUMN = "revision_kind";
|
|
8
|
+
export declare const REVISION_KINDS: readonly ['committed', 'retired', 'reinstated'];
|
|
8
9
|
export type HeadField = keyof DocumentHead;
|
|
9
10
|
export declare const HEAD_FIELDS: HeadField[];
|
|
10
11
|
export type DocumentColumns = EntityColumns & {
|
|
@@ -20,6 +21,10 @@ export type DocumentPhysicalColumns = Readonly<Record<HeadField, string>> & {
|
|
|
20
21
|
updatedAt: string;
|
|
21
22
|
};
|
|
22
23
|
export declare const physicalColumnsOf: (columns: DocumentColumns | undefined) => DocumentPhysicalColumns;
|
|
24
|
+
export declare const splitColumns: (columns: DocumentColumns | undefined) => {
|
|
25
|
+
rest: EntityColumns;
|
|
26
|
+
version: string;
|
|
27
|
+
};
|
|
23
28
|
export type DocumentRevisionsOptions = {
|
|
24
29
|
table?: string;
|
|
25
30
|
};
|
|
@@ -34,7 +39,7 @@ export type DocumentMigrationsOptions = {
|
|
|
34
39
|
table?: string;
|
|
35
40
|
};
|
|
36
41
|
export type AppendOnlyTablesOptions = {
|
|
37
|
-
table?:
|
|
42
|
+
table?: never;
|
|
38
43
|
revisions?: DocumentRevisionsOptions | false;
|
|
39
44
|
};
|
|
40
45
|
export declare const appendOnlyTables: (options?: AppendOnlyTablesOptions) => string[];
|
|
@@ -48,9 +53,4 @@ export type DocumentTableOptions = {
|
|
|
48
53
|
settings?: SessionSettings;
|
|
49
54
|
table?: string;
|
|
50
55
|
};
|
|
51
|
-
/**
|
|
52
|
-
* The document table as a drizzle table: the same shape `documentMigrations` renders, declared once
|
|
53
|
-
* so the store's reads and writes compose over it (D-069). A consumer with a table of their own
|
|
54
|
-
* hands that in instead.
|
|
55
|
-
*/
|
|
56
56
|
export declare const documentTable: (options?: DocumentTableOptions) => PgTable;
|
package/dist/store/ddl.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { ENTITY_PLACEHOLDERS as DOCUMENT_MIGRATION_PLACEHOLDERS };
|
|
|
5
5
|
export declare const DEFAULT_DOCUMENT_TABLE = "documents";
|
|
6
6
|
export declare const DEFAULT_REVISIONS_TABLE = "document_revisions";
|
|
7
7
|
export declare const DEFAULT_REVISION_KIND_COLUMN = "revision_kind";
|
|
8
|
+
export declare const REVISION_KINDS: readonly ['committed', 'retired', 'reinstated'];
|
|
8
9
|
export type HeadField = keyof DocumentHead;
|
|
9
10
|
export declare const HEAD_FIELDS: HeadField[];
|
|
10
11
|
export type DocumentColumns = EntityColumns & {
|
|
@@ -20,6 +21,10 @@ export type DocumentPhysicalColumns = Readonly<Record<HeadField, string>> & {
|
|
|
20
21
|
updatedAt: string;
|
|
21
22
|
};
|
|
22
23
|
export declare const physicalColumnsOf: (columns: DocumentColumns | undefined) => DocumentPhysicalColumns;
|
|
24
|
+
export declare const splitColumns: (columns: DocumentColumns | undefined) => {
|
|
25
|
+
rest: EntityColumns;
|
|
26
|
+
version: string;
|
|
27
|
+
};
|
|
23
28
|
export type DocumentRevisionsOptions = {
|
|
24
29
|
table?: string;
|
|
25
30
|
};
|
|
@@ -34,7 +39,7 @@ export type DocumentMigrationsOptions = {
|
|
|
34
39
|
table?: string;
|
|
35
40
|
};
|
|
36
41
|
export type AppendOnlyTablesOptions = {
|
|
37
|
-
table?:
|
|
42
|
+
table?: never;
|
|
38
43
|
revisions?: DocumentRevisionsOptions | false;
|
|
39
44
|
};
|
|
40
45
|
export declare const appendOnlyTables: (options?: AppendOnlyTablesOptions) => string[];
|
|
@@ -48,9 +53,4 @@ export type DocumentTableOptions = {
|
|
|
48
53
|
settings?: SessionSettings;
|
|
49
54
|
table?: string;
|
|
50
55
|
};
|
|
51
|
-
/**
|
|
52
|
-
* The document table as a drizzle table: the same shape `documentMigrations` renders, declared once
|
|
53
|
-
* so the store's reads and writes compose over it (D-069). A consumer with a table of their own
|
|
54
|
-
* hands that in instead.
|
|
55
|
-
*/
|
|
56
56
|
export declare const documentTable: (options?: DocumentTableOptions) => PgTable;
|
package/dist/store/ddl.js
CHANGED
|
@@ -4,7 +4,8 @@ import {
|
|
|
4
4
|
ENTITY_PLACEHOLDERS,
|
|
5
5
|
entityTable,
|
|
6
6
|
logMigrations,
|
|
7
|
-
projectionMigrations
|
|
7
|
+
projectionMigrations,
|
|
8
|
+
sqlFragments
|
|
8
9
|
} from "@geonosis/db";
|
|
9
10
|
import { headFields } from "../core/document.js";
|
|
10
11
|
var DEFAULT_DOCUMENT_TABLE = "documents";
|
|
@@ -32,34 +33,44 @@ var physicalColumnsOf = (columns) => {
|
|
|
32
33
|
updatedAt: nameOf(columns?.updatedAt, DEFAULT_UPDATED_AT_COLUMN)
|
|
33
34
|
};
|
|
34
35
|
};
|
|
36
|
+
var splitColumns = (columns) => {
|
|
37
|
+
const {
|
|
38
|
+
entity: _entity,
|
|
39
|
+
heads: _heads,
|
|
40
|
+
revisionKind: _revisionKind,
|
|
41
|
+
total: _total,
|
|
42
|
+
version,
|
|
43
|
+
...rest
|
|
44
|
+
} = columns ?? {};
|
|
45
|
+
return { rest, version: nameOf(version, DEFAULT_VERSION_COLUMN) };
|
|
46
|
+
};
|
|
35
47
|
var appendOnlyTables = (options = {}) => {
|
|
48
|
+
if (options.table !== undefined) {
|
|
49
|
+
throw new DbRefusal("`table` names the documents table everywhere else in this package, and the documents table is the one an application must update: name the log as `revisions: { table }`");
|
|
50
|
+
}
|
|
36
51
|
if (options.revisions === false)
|
|
37
52
|
return [];
|
|
38
|
-
return [options.revisions?.table ??
|
|
53
|
+
return [options.revisions?.table ?? DEFAULT_REVISIONS_TABLE];
|
|
39
54
|
};
|
|
40
|
-
var
|
|
41
|
-
var literalName = (value) => `'${value.replaceAll("'", "''")}'`;
|
|
55
|
+
var { quoted } = sqlFragments;
|
|
42
56
|
var documentRoleStatements = (appRole, options = {}) => {
|
|
43
57
|
if (typeof appRole !== "string" || appRole === "") {
|
|
44
58
|
throw new DbRefusal("documentRoleStatements needs an `appRole` — the name a consumer’s application connects as belongs to whoever runs the database, and one baked in here would be another repo’s");
|
|
45
59
|
}
|
|
46
|
-
const role =
|
|
47
|
-
const on = (table) => options.schema === undefined ?
|
|
60
|
+
const role = quoted(appRole);
|
|
61
|
+
const on = (table) => options.schema === undefined ? quoted(table) : `${quoted(options.schema)}.${quoted(table)}`;
|
|
48
62
|
return appendOnlyTables(options).flatMap((table) => [
|
|
49
63
|
`revoke update, delete on ${on(table)} from ${role}`,
|
|
50
64
|
`grant select, insert on ${on(table)} to ${role}`
|
|
51
65
|
]);
|
|
52
66
|
};
|
|
53
|
-
var
|
|
54
|
-
var headIndexedColumns = (physical) => HEAD_FIELDS.map((field) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
var revisionKindType = (column) => `text check (${quotedName(column)} in (${REVISION_KINDS.map(literalName).join(", ")}))`;
|
|
67
|
+
var isNumeric = (field) => headFields[field] === "decimal";
|
|
68
|
+
var headIndexedColumns = (physical) => HEAD_FIELDS.map((field) => ({
|
|
69
|
+
column: physical[field],
|
|
70
|
+
nullable: field !== "status",
|
|
71
|
+
...isNumeric(field) ? { type: "numeric" } : {}
|
|
72
|
+
}));
|
|
73
|
+
var revisionKindType = (column) => `text check (${quoted(column)} in (${REVISION_KINDS.map((kind) => `'${kind}'`).join(", ")}))`;
|
|
63
74
|
var walls = (options) => ({
|
|
64
75
|
...options.freeze === undefined ? {} : { freeze: options.freeze },
|
|
65
76
|
...options.names === undefined ? {} : { names: options.names },
|
|
@@ -93,17 +104,10 @@ var revisionsMigrations = (options, physical) => {
|
|
|
93
104
|
var documentMigrations = (options) => {
|
|
94
105
|
const table = options.table ?? DEFAULT_DOCUMENT_TABLE;
|
|
95
106
|
const physical = physicalColumnsOf(options.columns);
|
|
96
|
-
const {
|
|
97
|
-
entity: _entity,
|
|
98
|
-
heads: _heads,
|
|
99
|
-
revisionKind: _revisionKind,
|
|
100
|
-
total: _total,
|
|
101
|
-
version,
|
|
102
|
-
...restColumns
|
|
103
|
-
} = options.columns ?? {};
|
|
107
|
+
const { rest: restColumns, version } = splitColumns(options.columns);
|
|
104
108
|
const [tableMigration, ...rest] = projectionMigrations({
|
|
105
109
|
carried: [{ column: "lineage", type: "integer not null default 1" }],
|
|
106
|
-
columns: { ...restColumns, sequence: version
|
|
110
|
+
columns: { ...restColumns, sequence: version },
|
|
107
111
|
constants: { [physical.entity]: "" },
|
|
108
112
|
indexed: headIndexedColumns(physical),
|
|
109
113
|
key: "number",
|
|
@@ -120,35 +124,27 @@ var documentMigrations = (options) => {
|
|
|
120
124
|
if (tableMigration === undefined) {
|
|
121
125
|
throw new Error("projectionMigrations answered with no table migration to append the listing index to");
|
|
122
126
|
}
|
|
123
|
-
const listingIndex = `create index if not exists ${
|
|
127
|
+
const listingIndex = `create index if not exists ${quoted(`${table}_${physical.entity}_${physical.issueDate}_idx`)} on ${quoted(table)} (${quoted(physical.entity)}, ${quoted(physical.issueDate)})`;
|
|
124
128
|
return [
|
|
125
129
|
{ ...tableMigration, statements: [...tableMigration.statements, listingIndex] },
|
|
126
130
|
...rest,
|
|
127
131
|
...revisionsMigrations(options, physical)
|
|
128
132
|
];
|
|
129
133
|
};
|
|
130
|
-
var TABLE_TYPE_OF = { decimal: "numeric" };
|
|
131
134
|
var documentTable = (options = {}) => {
|
|
132
135
|
const physical = physicalColumnsOf(options.columns);
|
|
133
|
-
const {
|
|
134
|
-
|
|
135
|
-
heads: _heads,
|
|
136
|
-
id,
|
|
137
|
-
revisionKind: _revisionKind,
|
|
138
|
-
total: _total,
|
|
139
|
-
version,
|
|
140
|
-
...restColumns
|
|
141
|
-
} = options.columns ?? {};
|
|
136
|
+
const { rest, version } = splitColumns(options.columns);
|
|
137
|
+
const { id, ...restColumns } = rest;
|
|
142
138
|
const named = Object.fromEntries(Object.entries(restColumns).map(([column, held]) => [column, nameOf(held, column)]));
|
|
143
139
|
return entityTable({
|
|
144
|
-
columns: { ...named, version
|
|
140
|
+
columns: { ...named, version },
|
|
145
141
|
constants: [physical.entity],
|
|
146
142
|
extra: {
|
|
147
143
|
...Object.fromEntries(HEAD_FIELDS.map((field) => [
|
|
148
144
|
physical[field],
|
|
149
145
|
{
|
|
150
146
|
nullable: field !== "status",
|
|
151
|
-
type:
|
|
147
|
+
type: isNumeric(field) ? "numeric" : "text"
|
|
152
148
|
}
|
|
153
149
|
])),
|
|
154
150
|
hash: "text",
|
|
@@ -167,9 +163,11 @@ export {
|
|
|
167
163
|
DEFAULT_REVISION_KIND_COLUMN,
|
|
168
164
|
ENTITY_PLACEHOLDERS as DOCUMENT_MIGRATION_PLACEHOLDERS,
|
|
169
165
|
HEAD_FIELDS,
|
|
166
|
+
REVISION_KINDS,
|
|
170
167
|
appendOnlyTables,
|
|
171
168
|
documentMigrations,
|
|
172
169
|
documentRoleStatements,
|
|
173
170
|
documentTable,
|
|
174
|
-
physicalColumnsOf
|
|
171
|
+
physicalColumnsOf,
|
|
172
|
+
splitColumns
|
|
175
173
|
};
|
package/dist/store/hash.d.cts
CHANGED
package/dist/store/hash.d.ts
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, {
|
|
32
|
+
get: all[name],
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/store/number-for.ts
|
|
40
|
+
var exports_number_for = {};
|
|
41
|
+
__export(exports_number_for, {
|
|
42
|
+
numberFor: () => numberFor
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(exports_number_for);
|
|
45
|
+
var numberFor = (options) => async (ctx, key) => {
|
|
46
|
+
const { handle, tenantId } = options.scope(ctx);
|
|
47
|
+
const issued = await options.counter.next(handle, {
|
|
48
|
+
[options.seam.tenantKey]: tenantId,
|
|
49
|
+
key
|
|
50
|
+
});
|
|
51
|
+
return { number: issued.number };
|
|
52
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Counter, DrizzleHandle, SessionSeam } from '@geonosis/db';
|
|
2
|
+
export declare const numberFor: <Ctx, Key extends string, Handle extends DrizzleHandle>(options: {
|
|
3
|
+
counter: Counter<Key, Handle>;
|
|
4
|
+
scope: (ctx: Ctx) => {
|
|
5
|
+
handle: Handle;
|
|
6
|
+
tenantId: string;
|
|
7
|
+
};
|
|
8
|
+
seam: SessionSeam<Key, Handle>;
|
|
9
|
+
}) => (ctx: Ctx, key: string) => Promise<{
|
|
10
|
+
number: number;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Counter, DrizzleHandle, SessionSeam } from '@geonosis/db';
|
|
2
|
+
export declare const numberFor: <Ctx, Key extends string, Handle extends DrizzleHandle>(options: {
|
|
3
|
+
counter: Counter<Key, Handle>;
|
|
4
|
+
scope: (ctx: Ctx) => {
|
|
5
|
+
handle: Handle;
|
|
6
|
+
tenantId: string;
|
|
7
|
+
};
|
|
8
|
+
seam: SessionSeam<Key, Handle>;
|
|
9
|
+
}) => (ctx: Ctx, key: string) => Promise<{
|
|
10
|
+
number: number;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/store/number-for.ts
|
|
2
|
+
var numberFor = (options) => async (ctx, key) => {
|
|
3
|
+
const { handle, tenantId } = options.scope(ctx);
|
|
4
|
+
const issued = await options.counter.next(handle, {
|
|
5
|
+
[options.seam.tenantKey]: tenantId,
|
|
6
|
+
key
|
|
7
|
+
});
|
|
8
|
+
return { number: issued.number };
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
numberFor
|
|
12
|
+
};
|