@geonosis/document 0.1.0 → 0.2.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 +119 -0
- package/README.md +144 -23
- package/dist/index.cjs +1206 -32
- package/dist/index.d.cts +387 -73
- package/dist/index.d.ts +387 -73
- package/dist/index.js +1199 -31
- package/migrations/0001_documents.sql +56 -0
- package/migrations/0002_documents_policies.sql +15 -0
- package/migrations/0003_document_revisions.sql +17 -0
- package/migrations/0004_document_revisions_policies.sql +23 -0
- package/package.json +6 -7
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
create table if not exists "documents" (
|
|
2
|
+
"tenant_id" text not null default current_setting('{{tenantSetting}}', true),
|
|
3
|
+
"entity" text not null,
|
|
4
|
+
"number" text not null,
|
|
5
|
+
"body" jsonb not null,
|
|
6
|
+
"created_at" bigint not null,
|
|
7
|
+
"updated_at" bigint not null,
|
|
8
|
+
"retired_at" bigint,
|
|
9
|
+
"version" integer not null default 1,
|
|
10
|
+
"status" text,
|
|
11
|
+
"issueDate" text,
|
|
12
|
+
"dueDate" text,
|
|
13
|
+
"counterparty" text,
|
|
14
|
+
"externalRef" text,
|
|
15
|
+
"revision" text,
|
|
16
|
+
"total" numeric,
|
|
17
|
+
constraint "documents_pkey" primary key ("tenant_id", "entity", "number")
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
21
|
+
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
22
|
+
create index if not exists "documents_listing_idx" on "documents" ("tenant_id", "number" asc);
|
|
23
|
+
|
|
24
|
+
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
25
|
+
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
26
|
+
create index if not exists "documents_by_status_idx" on "documents" ("tenant_id", "status" asc, "number" asc);
|
|
27
|
+
|
|
28
|
+
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
29
|
+
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
30
|
+
create index if not exists "documents_by_issueDate_idx" on "documents" ("tenant_id", "issueDate" asc, "number" asc);
|
|
31
|
+
|
|
32
|
+
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
33
|
+
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
34
|
+
create index if not exists "documents_by_dueDate_idx" on "documents" ("tenant_id", "dueDate" asc, "number" asc);
|
|
35
|
+
|
|
36
|
+
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
37
|
+
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
38
|
+
create index if not exists "documents_by_counterparty_idx" on "documents" ("tenant_id", "counterparty" asc, "number" asc);
|
|
39
|
+
|
|
40
|
+
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
41
|
+
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
42
|
+
create index if not exists "documents_by_externalRef_idx" on "documents" ("tenant_id", "externalRef" asc, "number" asc);
|
|
43
|
+
|
|
44
|
+
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
45
|
+
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
46
|
+
create index if not exists "documents_by_revision_idx" on "documents" ("tenant_id", "revision" asc, "number" asc);
|
|
47
|
+
|
|
48
|
+
-- The migrator applies this file inside a transaction, which is also why CONCURRENTLY is not available here; the index is created in the same migration as its table, over no rows. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
49
|
+
-- squawk-ignore require-concurrent-index-creation, require-lock-timeout, require-statement-timeout
|
|
50
|
+
create index if not exists "documents_by_total_idx" on "documents" ("tenant_id", "total" asc, "number" asc);
|
|
51
|
+
|
|
52
|
+
create index if not exists "documents_entity_issueDate_idx" on "documents" ("entity", "issueDate");
|
|
53
|
+
|
|
54
|
+
alter table "documents" add column if not exists "lineage" integer not null default 1;
|
|
55
|
+
|
|
56
|
+
alter table "documents" add column if not exists "hash" text;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- This file is applied inside a transaction and every statement in it is idempotent, so a run that fails part way through leaves nothing behind and a rerun is a no-op. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
2
|
+
-- squawk-ignore prefer-robust-stmts, require-lock-timeout, require-statement-timeout
|
|
3
|
+
alter table "documents" enable row level security;
|
|
4
|
+
|
|
5
|
+
-- This file is applied inside a transaction and every statement in it is idempotent, so a run that fails part way through leaves nothing behind and a rerun is a no-op.
|
|
6
|
+
-- squawk-ignore prefer-robust-stmts
|
|
7
|
+
alter table "documents" force row level security;
|
|
8
|
+
|
|
9
|
+
drop policy if exists "tenant_isolation" on "documents";
|
|
10
|
+
|
|
11
|
+
create policy "tenant_isolation" on "documents" as permissive for all using ("tenant_id" = (select current_setting('{{tenantSetting}}', true))) with check ("tenant_id" = (select current_setting('{{tenantSetting}}', true)));
|
|
12
|
+
|
|
13
|
+
drop policy if exists "ops_maintenance" on "documents";
|
|
14
|
+
|
|
15
|
+
create policy "ops_maintenance" on "documents" as permissive for all using ((select current_setting('{{opsSetting}}', true)) = 'on') with check ((select current_setting('{{opsSetting}}', true)) = 'on');
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
create table if not exists "document_revisions" (
|
|
2
|
+
"tenant_id" text not null default current_setting('{{tenantSetting}}', true),
|
|
3
|
+
"entity" text not null,
|
|
4
|
+
"ref" text not null,
|
|
5
|
+
"lineage" integer not null,
|
|
6
|
+
"version" integer not null,
|
|
7
|
+
"revision_kind" text not null,
|
|
8
|
+
"body" jsonb not null,
|
|
9
|
+
"actor" text not null,
|
|
10
|
+
"reason" text,
|
|
11
|
+
"at" bigint not null default (extract(epoch from clock_timestamp()) * 1000)::bigint,
|
|
12
|
+
"prev_hash" text,
|
|
13
|
+
"hash" text not null,
|
|
14
|
+
"compensation_of" integer,
|
|
15
|
+
constraint "document_revisions_pkey" primary key ("tenant_id", "entity", "ref", "lineage", "version"),
|
|
16
|
+
constraint "document_revisions_revision_kind_check" check ("revision_kind" in ('committed', 'retired', 'reinstated'))
|
|
17
|
+
);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
-- This file is applied inside a transaction and every statement in it is idempotent, so a run that fails part way through leaves nothing behind and a rerun is a no-op. lock_timeout and statement_timeout are one deployment’s numbers, and a value written into shipped DDL imposes that deployment’s budget on every consumer: set them in the session that migrates.
|
|
2
|
+
-- squawk-ignore prefer-robust-stmts, require-lock-timeout, require-statement-timeout
|
|
3
|
+
alter table "document_revisions" enable row level security;
|
|
4
|
+
|
|
5
|
+
-- This file is applied inside a transaction and every statement in it is idempotent, so a run that fails part way through leaves nothing behind and a rerun is a no-op.
|
|
6
|
+
-- squawk-ignore prefer-robust-stmts
|
|
7
|
+
alter table "document_revisions" force row level security;
|
|
8
|
+
|
|
9
|
+
drop policy if exists "tenant_isolation" on "document_revisions";
|
|
10
|
+
|
|
11
|
+
create policy "tenant_isolation" on "document_revisions" as permissive for all using ("tenant_id" = (select current_setting('{{tenantSetting}}', true))) with check ("tenant_id" = (select current_setting('{{tenantSetting}}', true)));
|
|
12
|
+
|
|
13
|
+
drop policy if exists "ops_maintenance" on "document_revisions";
|
|
14
|
+
|
|
15
|
+
create policy "ops_maintenance" on "document_revisions" as permissive for all using ((select current_setting('{{opsSetting}}', true)) = 'on') with check ((select current_setting('{{opsSetting}}', true)) = 'on');
|
|
16
|
+
|
|
17
|
+
create or replace function "document_revisions_immutable"() returns trigger language plpgsql as $$ begin raise exception 'this table is append-only: % is not permitted', tg_op; end; $$;
|
|
18
|
+
|
|
19
|
+
drop trigger if exists "document_revisions_no_update_or_delete" on "document_revisions";
|
|
20
|
+
|
|
21
|
+
create trigger "document_revisions_no_update_or_delete" before update or delete on "document_revisions" for each row execute function "document_revisions_immutable"();
|
|
22
|
+
|
|
23
|
+
do $$ begin if exists (select from pg_roles where rolname = '{{appRole}}') then execute 'revoke update, delete on "document_revisions" from ' || quote_ident('{{appRole}}'); end if; end $$;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geonosis/document",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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": [
|
|
@@ -38,15 +38,14 @@
|
|
|
38
38
|
"migrations"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
+
"@standard-schema/spec": "^1.1.0",
|
|
41
42
|
"@geonosis/conformance": "^0.3.0",
|
|
42
|
-
"@geonosis/
|
|
43
|
-
"@geonosis/workflows": "^0.4.0",
|
|
44
|
-
"@geonosis/db": "^0.7.0"
|
|
45
|
-
},
|
|
46
|
-
"peerDependencies": {
|
|
47
|
-
"zod": ">=4.5.2"
|
|
43
|
+
"@geonosis/db": "^0.8.0"
|
|
48
44
|
},
|
|
49
45
|
"devDependencies": {
|
|
46
|
+
"embedded-postgres-17": "npm:embedded-postgres@17.10.0-beta.17",
|
|
47
|
+
"embedded-postgres-18": "npm:embedded-postgres@18.4.0-beta.17",
|
|
48
|
+
"pg": "^8.16.3",
|
|
50
49
|
"zod": "^4.5.2"
|
|
51
50
|
},
|
|
52
51
|
"engines": {
|