@geonosis/document 0.9.3 → 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 +53 -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
@@ -0,0 +1,28 @@
1
+ import type { LinkVerifierPort } from '../core/ports.cjs';
2
+ export type DocumentSharedDoor = {
3
+ render: (params: {
4
+ ref: string;
5
+ }) => Promise<unknown>;
6
+ retired: (params: {
7
+ ref: string;
8
+ }) => Promise<boolean>;
9
+ };
10
+ export type DocumentSharedPorts<Ctx> = {
11
+ door: (ctx: Ctx, at: {
12
+ entity: string;
13
+ org: string;
14
+ }) => DocumentSharedDoor;
15
+ now?: () => number;
16
+ org?: (ctx: Ctx) => string | undefined;
17
+ verifier: LinkVerifierPort;
18
+ };
19
+ type SharedInput = {
20
+ token: string;
21
+ };
22
+ export declare const documentShared: <Name extends string, Ctx extends object>(registry: {
23
+ names: readonly Name[];
24
+ }, ports: DocumentSharedPorts<Ctx>) => import("@geonosis/workflows").Workflow<SharedInput, {
25
+ entity: Name;
26
+ view: unknown;
27
+ }, Ctx>;
28
+ export {};
@@ -0,0 +1,28 @@
1
+ import type { LinkVerifierPort } from '../core/ports.js';
2
+ export type DocumentSharedDoor = {
3
+ render: (params: {
4
+ ref: string;
5
+ }) => Promise<unknown>;
6
+ retired: (params: {
7
+ ref: string;
8
+ }) => Promise<boolean>;
9
+ };
10
+ export type DocumentSharedPorts<Ctx> = {
11
+ door: (ctx: Ctx, at: {
12
+ entity: string;
13
+ org: string;
14
+ }) => DocumentSharedDoor;
15
+ now?: () => number;
16
+ org?: (ctx: Ctx) => string | undefined;
17
+ verifier: LinkVerifierPort;
18
+ };
19
+ type SharedInput = {
20
+ token: string;
21
+ };
22
+ export declare const documentShared: <Name extends string, Ctx extends object>(registry: {
23
+ names: readonly Name[];
24
+ }, ports: DocumentSharedPorts<Ctx>) => import("@geonosis/workflows").Workflow<SharedInput, {
25
+ entity: Name;
26
+ view: unknown;
27
+ }, Ctx>;
28
+ export {};
@@ -0,0 +1,60 @@
1
+ // src/workflows/shared.ts
2
+ import { createWorkflow } from "@geonosis/workflows";
3
+ import { schemaOf } from "../core/schema.js";
4
+ import {
5
+ DocumentNotFound,
6
+ LinkExpired,
7
+ LinkInvalid,
8
+ LinkNotADocument,
9
+ LinkRetired,
10
+ LinkWrongOrg
11
+ } from "./refusals.js";
12
+ var inputSchema = schemaOf((input) => {
13
+ const token = typeof input === "object" && input !== null && "token" in input ? input.token : undefined;
14
+ return typeof token === "string" && token !== "" ? { value: { token } } : { issues: [{ message: "expected a token" }] };
15
+ });
16
+ var documentShared = (registry, ports) => createWorkflow("document.shared", async (input, ctx) => {
17
+ const claims = await ports.verifier.verify(input.token);
18
+ if (claims === null) {
19
+ throw new LinkInvalid({ message: "this link is not one this door signed, or was altered" });
20
+ }
21
+ const now = (ports.now ?? Date.now)();
22
+ if (claims.exp <= now) {
23
+ throw new LinkExpired({ expiredAt: claims.exp, message: "this link has expired" });
24
+ }
25
+ const scoped = ports.org?.(ctx);
26
+ if (scoped !== undefined && scoped !== claims.org) {
27
+ throw new LinkWrongOrg({
28
+ expected: scoped,
29
+ found: claims.org,
30
+ message: "this link was issued by another organisation"
31
+ });
32
+ }
33
+ const entity = registry.names.find((name) => name === claims.entity);
34
+ if (entity === undefined) {
35
+ throw new LinkNotADocument({
36
+ entity: claims.entity,
37
+ message: `this link points at a ${claims.entity}, which is not a document`
38
+ });
39
+ }
40
+ const door = ports.door(ctx, { entity, org: claims.org });
41
+ const view = await door.render({ ref: claims.ref });
42
+ if (view === null) {
43
+ if (await door.retired({ ref: claims.ref })) {
44
+ throw new LinkRetired({
45
+ entity,
46
+ message: "the document this link points at has been retired",
47
+ ref: claims.ref
48
+ });
49
+ }
50
+ throw new DocumentNotFound({
51
+ entity,
52
+ message: `no ${entity} is stored as ${claims.ref}`,
53
+ ref: claims.ref
54
+ });
55
+ }
56
+ return { entity, view };
57
+ }, { input: inputSchema });
58
+ export {
59
+ documentShared
60
+ };
@@ -47,15 +47,30 @@ __export(exports_workflows, {
47
47
  DocumentNotFound: () => import_refusals.DocumentNotFound,
48
48
  DocumentNotRemovable: () => import_refusals.DocumentNotRemovable,
49
49
  DocumentTaken: () => import_refusals.DocumentTaken,
50
+ LINK_EXPIRED_TAG: () => import_refusals.LINK_EXPIRED_TAG,
51
+ LINK_INVALID_TAG: () => import_refusals.LINK_INVALID_TAG,
52
+ LINK_NOT_A_DOCUMENT_TAG: () => import_refusals.LINK_NOT_A_DOCUMENT_TAG,
53
+ LINK_RETIRED_TAG: () => import_refusals.LINK_RETIRED_TAG,
54
+ LINK_WRONG_ORG_TAG: () => import_refusals.LINK_WRONG_ORG_TAG,
55
+ LinkExpired: () => import_refusals.LinkExpired,
56
+ LinkInvalid: () => import_refusals.LinkInvalid,
57
+ LinkNotADocument: () => import_refusals.LinkNotADocument,
58
+ LinkRetired: () => import_refusals.LinkRetired,
59
+ LinkWrongOrg: () => import_refusals.LinkWrongOrg,
50
60
  MAIL_UNDELIVERED_TAG: () => import_ports.MAIL_UNDELIVERED_TAG,
51
61
  MailUndelivered: () => import_ports.MailUndelivered,
52
62
  NUMBERING_REFUSED_TAG: () => import_refusals.NUMBERING_REFUSED_TAG,
53
63
  NumberingRefused: () => import_refusals.NumberingRefused,
54
64
  TRANSITION_REFUSED_TAG: () => import_refusals.TRANSITION_REFUSED_TAG,
55
65
  TransitionRefused: () => import_refusals.TransitionRefused,
56
- documentWorkflows: () => import_document_workflows.documentWorkflows
66
+ documentShared: () => import_shared.documentShared,
67
+ documentWorkflows: () => import_document_workflows.documentWorkflows,
68
+ runInline: () => import_bindings.runInline,
69
+ startRun: () => import_bindings.startRun
57
70
  });
58
71
  module.exports = __toCommonJS(exports_workflows);
72
+ var import_bindings = require("./workflows/bindings.cjs");
73
+ var import_shared = require("./workflows/shared.cjs");
59
74
  var import_document_workflows = require("./workflows/document-workflows.cjs");
60
75
  var import_ports = require("./workflows/ports.cjs");
61
76
  var import_refusals = require("./workflows/refusals.cjs");
@@ -1,4 +1,6 @@
1
+ export { runInline, startRun, type DurableLauncher, type SurfaceWorkflows, type Workflow, type WorkflowRuntime } from './workflows/bindings.cjs';
2
+ export { documentShared, type DocumentSharedDoor, type DocumentSharedPorts } from './workflows/shared.cjs';
1
3
  export { documentWorkflows, type DocumentWorkflowOptions, type DocumentWorkflows, type WorkflowDocumentEntity } from './workflows/document-workflows.cjs';
2
4
  export type { DocumentConversion, DocumentEffects, DocumentFact, Written } from './workflows/effects.cjs';
3
5
  export { type DocumentDoorPort, type DocumentWorkflowPorts, MAIL_UNDELIVERED_TAG, MailUndelivered } from './workflows/ports.cjs';
4
- export { CONVERSION_REFUSED_TAG, ConversionRefused, DOCUMENT_NOT_FOUND_TAG, DOCUMENT_NOT_REMOVABLE_TAG, DOCUMENT_TAKEN_TAG, DocumentNotFound, DocumentNotRemovable, type DocumentRefusal, DocumentTaken, NUMBERING_REFUSED_TAG, NumberingRefused, TRANSITION_REFUSED_TAG, TransitionRefused } from './workflows/refusals.cjs';
6
+ export { CONVERSION_REFUSED_TAG, ConversionRefused, DOCUMENT_NOT_FOUND_TAG, DOCUMENT_NOT_REMOVABLE_TAG, DOCUMENT_TAKEN_TAG, DocumentNotFound, DocumentNotRemovable, type DocumentRefusal, DocumentTaken, LINK_EXPIRED_TAG, LINK_INVALID_TAG, LINK_NOT_A_DOCUMENT_TAG, LINK_RETIRED_TAG, LINK_WRONG_ORG_TAG, LinkExpired, LinkInvalid, LinkNotADocument, LinkRetired, LinkWrongOrg, NUMBERING_REFUSED_TAG, NumberingRefused, TRANSITION_REFUSED_TAG, TransitionRefused } from './workflows/refusals.cjs';
@@ -1,4 +1,6 @@
1
+ export { runInline, startRun, type DurableLauncher, type SurfaceWorkflows, type Workflow, type WorkflowRuntime } from './workflows/bindings.js';
2
+ export { documentShared, type DocumentSharedDoor, type DocumentSharedPorts } from './workflows/shared.js';
1
3
  export { documentWorkflows, type DocumentWorkflowOptions, type DocumentWorkflows, type WorkflowDocumentEntity } from './workflows/document-workflows.js';
2
4
  export type { DocumentConversion, DocumentEffects, DocumentFact, Written } from './workflows/effects.js';
3
5
  export { type DocumentDoorPort, type DocumentWorkflowPorts, MAIL_UNDELIVERED_TAG, MailUndelivered } from './workflows/ports.js';
4
- export { CONVERSION_REFUSED_TAG, ConversionRefused, DOCUMENT_NOT_FOUND_TAG, DOCUMENT_NOT_REMOVABLE_TAG, DOCUMENT_TAKEN_TAG, DocumentNotFound, DocumentNotRemovable, type DocumentRefusal, DocumentTaken, NUMBERING_REFUSED_TAG, NumberingRefused, TRANSITION_REFUSED_TAG, TransitionRefused } from './workflows/refusals.js';
6
+ export { CONVERSION_REFUSED_TAG, ConversionRefused, DOCUMENT_NOT_FOUND_TAG, DOCUMENT_NOT_REMOVABLE_TAG, DOCUMENT_TAKEN_TAG, DocumentNotFound, DocumentNotRemovable, type DocumentRefusal, DocumentTaken, LINK_EXPIRED_TAG, LINK_INVALID_TAG, LINK_NOT_A_DOCUMENT_TAG, LINK_RETIRED_TAG, LINK_WRONG_ORG_TAG, LinkExpired, LinkInvalid, LinkNotADocument, LinkRetired, LinkWrongOrg, NUMBERING_REFUSED_TAG, NumberingRefused, TRANSITION_REFUSED_TAG, TransitionRefused } from './workflows/refusals.js';
package/dist/workflows.js CHANGED
@@ -1,4 +1,11 @@
1
1
  // src/workflows.ts
2
+ import {
3
+ runInline,
4
+ startRun
5
+ } from "./workflows/bindings.js";
6
+ import {
7
+ documentShared
8
+ } from "./workflows/shared.js";
2
9
  import {
3
10
  documentWorkflows
4
11
  } from "./workflows/document-workflows.js";
@@ -15,6 +22,16 @@ import {
15
22
  DocumentNotFound,
16
23
  DocumentNotRemovable,
17
24
  DocumentTaken,
25
+ LINK_EXPIRED_TAG,
26
+ LINK_INVALID_TAG,
27
+ LINK_NOT_A_DOCUMENT_TAG,
28
+ LINK_RETIRED_TAG,
29
+ LINK_WRONG_ORG_TAG,
30
+ LinkExpired,
31
+ LinkInvalid,
32
+ LinkNotADocument,
33
+ LinkRetired,
34
+ LinkWrongOrg,
18
35
  NUMBERING_REFUSED_TAG,
19
36
  NumberingRefused,
20
37
  TRANSITION_REFUSED_TAG,
@@ -29,11 +46,24 @@ export {
29
46
  DocumentNotFound,
30
47
  DocumentNotRemovable,
31
48
  DocumentTaken,
49
+ LINK_EXPIRED_TAG,
50
+ LINK_INVALID_TAG,
51
+ LINK_NOT_A_DOCUMENT_TAG,
52
+ LINK_RETIRED_TAG,
53
+ LINK_WRONG_ORG_TAG,
54
+ LinkExpired,
55
+ LinkInvalid,
56
+ LinkNotADocument,
57
+ LinkRetired,
58
+ LinkWrongOrg,
32
59
  MAIL_UNDELIVERED_TAG,
33
60
  MailUndelivered,
34
61
  NUMBERING_REFUSED_TAG,
35
62
  NumberingRefused,
36
63
  TRANSITION_REFUSED_TAG,
37
64
  TransitionRefused,
38
- documentWorkflows
65
+ documentShared,
66
+ documentWorkflows,
67
+ runInline,
68
+ startRun
39
69
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geonosis/document",
3
- "version": "0.9.3",
3
+ "version": "0.10.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": [
@@ -58,8 +58,8 @@
58
58
  "migrations"
59
59
  ],
60
60
  "dependencies": {
61
- "@geonosis/db": "^0.14.2",
62
- "@geonosis/workflows": "^0.7.0",
61
+ "@geonosis/db": "^0.15.0",
62
+ "@geonosis/workflows": "^0.8.0",
63
63
  "@standard-schema/spec": "^1.1.0",
64
64
  "better-result": "^3.0.1"
65
65
  },
@@ -75,7 +75,7 @@
75
75
  "drizzle-orm": "^0.45.3",
76
76
  "embedded-postgres-17": "npm:embedded-postgres@17.10.0-beta.17",
77
77
  "embedded-postgres-18": "npm:embedded-postgres@18.4.0-beta.17",
78
- "pg": "^8.23.0",
78
+ "pg": "^8.23.1",
79
79
  "zod": "^4.6.5"
80
80
  },
81
81
  "engines": {