ankka 0.10.0 → 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.
Files changed (74) hide show
  1. package/dist/_proto/ankka/protocol/v1/agent_pb.d.ts +35 -0
  2. package/dist/_proto/ankka/protocol/v1/agent_pb.js +8 -1
  3. package/dist/_proto/ankka/protocol/v1/client_pb.d.ts +542 -2
  4. package/dist/_proto/ankka/protocol/v1/client_pb.js +107 -6
  5. package/dist/_proto/ankka/protocol/v1/discovery_pb.d.ts +330 -0
  6. package/dist/_proto/ankka/protocol/v1/discovery_pb.js +81 -16
  7. package/dist/_proto/ankka/protocol/v1/endpoint_pb.d.ts +184 -0
  8. package/dist/_proto/ankka/protocol/v1/endpoint_pb.js +26 -1
  9. package/dist/_proto/ankka/protocol/v1/view_pb.d.ts +63 -0
  10. package/dist/_proto/ankka/protocol/v1/view_pb.js +11 -1
  11. package/dist/_proto/ankka/protocol/v1/workflow_pb.d.ts +7 -0
  12. package/dist/_proto/ankka/protocol/v1/workflow_pb.js +1 -1
  13. package/dist/agent.d.ts +15 -1
  14. package/dist/agent.js +20 -0
  15. package/dist/approvals.d.ts +47 -0
  16. package/dist/approvals.js +57 -0
  17. package/dist/autonomous.d.ts +23 -1
  18. package/dist/autonomous.js +30 -1
  19. package/dist/client.d.ts +92 -4
  20. package/dist/client.js +262 -15
  21. package/dist/consumer.d.ts +24 -2
  22. package/dist/consumer.js +20 -0
  23. package/dist/context.d.ts +4 -0
  24. package/dist/contract.d.ts +36 -0
  25. package/dist/contract.js +58 -0
  26. package/dist/effects/keyed.d.ts +33 -0
  27. package/dist/effects/keyed.js +41 -0
  28. package/dist/endpoint.d.ts +10 -1
  29. package/dist/endpoint.js +20 -0
  30. package/dist/graph.d.ts +15 -1
  31. package/dist/graph.js +20 -0
  32. package/dist/handlers.d.ts +10 -2
  33. package/dist/handlers.js +6 -2
  34. package/dist/index.d.ts +12 -4
  35. package/dist/index.js +11 -3
  36. package/dist/keyedView.d.ts +56 -0
  37. package/dist/keyedView.js +67 -0
  38. package/dist/mcp.d.ts +57 -0
  39. package/dist/mcp.js +64 -0
  40. package/dist/routes.d.ts +23 -3
  41. package/dist/routes.js +16 -3
  42. package/dist/server/agent.js +12 -4
  43. package/dist/server/discovery.d.ts +12 -1
  44. package/dist/server/discovery.js +95 -1
  45. package/dist/server/http.d.ts +2 -1
  46. package/dist/server/http.js +78 -4
  47. package/dist/server/stateless.js +38 -0
  48. package/dist/server/workflow.js +5 -1
  49. package/dist/service.d.ts +40 -2
  50. package/dist/service.js +209 -14
  51. package/dist/services.d.ts +137 -0
  52. package/dist/services.js +259 -0
  53. package/dist/socket.d.ts +15 -0
  54. package/dist/socket.js +25 -0
  55. package/dist/spec.d.ts +1 -1
  56. package/dist/spec.js +87 -14
  57. package/dist/startFrom.d.ts +32 -0
  58. package/dist/startFrom.js +44 -0
  59. package/dist/testkit/index.d.ts +2 -2
  60. package/dist/testkit/index.js +1 -1
  61. package/dist/testkit/integration.js +5 -0
  62. package/dist/testkit/kinds.d.ts +43 -2
  63. package/dist/testkit/kinds.js +196 -26
  64. package/dist/testkit/unit.d.ts +14 -1
  65. package/dist/testkit/unit.js +40 -3
  66. package/dist/timedAction.d.ts +17 -2
  67. package/dist/timedAction.js +33 -1
  68. package/dist/version.d.ts +1 -1
  69. package/dist/version.js +1 -1
  70. package/dist/view.d.ts +32 -0
  71. package/dist/view.js +8 -0
  72. package/dist/workflow.d.ts +18 -1
  73. package/dist/workflow.js +39 -0
  74. package/package.json +3 -2
@@ -1,8 +1,9 @@
1
1
  import type { Shape } from "./codec.ts";
2
2
  import type { CommandContext } from "./context.ts";
3
3
  import type { HandlerTable } from "./handlers.ts";
4
- import type { ComponentClient } from "./client.ts";
4
+ import { type ComponentClient, type Secrets } from "./client.ts";
5
5
  import { StepEffects, WorkflowEffects, type WorkflowSettings } from "./effects/workflow.ts";
6
+ import { type Services } from "./services.ts";
6
7
  export declare abstract class Workflow<S> {
7
8
  #private;
8
9
  /** Inside a command handler. */
@@ -13,6 +14,22 @@ export declare abstract class Workflow<S> {
13
14
  get entityId(): string;
14
15
  get context(): CommandContext;
15
16
  get client(): ComponentClient;
17
+ /**
18
+ * The service's secret store, in a step. A command handler is refused: it would put a database read
19
+ * on the workflow's single-writer path, as an entity's would.
20
+ */
21
+ get secrets(): Secrets;
22
+ /** A unit test's store in place of the runtime's. */
23
+ set secrets(store: Secrets);
24
+ /**
25
+ * Other services, called as this one, in a step. A command handler is refused, as for the secret
26
+ * store: it would block the workflow's other commands behind another service.
27
+ */
28
+ get services(): Services;
29
+ /** A unit test's in place of the runtime's. */
30
+ set services(services: Services);
31
+ /** @internal The server marks a step's binding, which is how a step is told from a command. */
32
+ _enterStep(): void;
16
33
  /** @internal */
17
34
  get _kind(): "workflow";
18
35
  abstract emptyState(): S;
package/dist/workflow.js CHANGED
@@ -5,7 +5,10 @@
5
5
  //
6
6
  // static readonly steps = { reserve: step("reserve", (w: CheckoutWorkflow) => w.reserve()), charge: step("charge", s.int, (w, q) => w.charge(q)) }
7
7
  // static readonly settings = workflowSettings({ steps: { charge: { recovery: { maxRetries: 1, failoverTo: "compensate" } } } })
8
+ import { secretsFor } from "./client.js";
9
+ import { CommandError } from "./effects/common.js";
8
10
  import { StepEffects, WorkflowEffects } from "./effects/workflow.js";
11
+ import { servicesFor } from "./services.js";
9
12
  export class Workflow {
10
13
  /** Inside a command handler. */
11
14
  effects = new WorkflowEffects();
@@ -36,6 +39,41 @@ export class Workflow {
36
39
  throw new Error("client is only available inside a handler or a step");
37
40
  return this.#client;
38
41
  }
42
+ #inStep = false;
43
+ #secrets;
44
+ /**
45
+ * The service's secret store, in a step. A command handler is refused: it would put a database read
46
+ * on the workflow's single-writer path, as an entity's would.
47
+ */
48
+ get secrets() {
49
+ if (!this.#inStep) {
50
+ throw new CommandError({ message: "a workflow reads and keeps a service secret in a step, not in a command handler", code: "BAD_REQUEST" });
51
+ }
52
+ return this.#secrets ?? secretsFor(this.client);
53
+ }
54
+ /** A unit test's store in place of the runtime's. */
55
+ set secrets(store) {
56
+ this.#secrets = store;
57
+ }
58
+ #services;
59
+ /**
60
+ * Other services, called as this one, in a step. A command handler is refused, as for the secret
61
+ * store: it would block the workflow's other commands behind another service.
62
+ */
63
+ get services() {
64
+ if (!this.#inStep) {
65
+ throw new CommandError({ message: "a workflow calls another service in a step, not in a command handler", code: "BAD_REQUEST" });
66
+ }
67
+ return this.#services ?? servicesFor(this.client);
68
+ }
69
+ /** A unit test's in place of the runtime's. */
70
+ set services(services) {
71
+ this.#services = services;
72
+ }
73
+ /** @internal The server marks a step's binding, which is how a step is told from a command. */
74
+ _enterStep() {
75
+ this.#inStep = true;
76
+ }
39
77
  /** @internal */
40
78
  get _kind() {
41
79
  return "workflow";
@@ -57,5 +95,6 @@ export class Workflow {
57
95
  this.#context = undefined;
58
96
  this.#client = undefined;
59
97
  this.#bound = false;
98
+ this.#inStep = false;
60
99
  }
61
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ankka",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Build services on ankka in TypeScript: entities, views, workflows, agents and endpoints hosted by the ankka sidecar.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -50,7 +50,8 @@
50
50
  "dependencies": {
51
51
  "@bufbuild/protobuf": "^2.15.0",
52
52
  "@connectrpc/connect": "^2.2.0",
53
- "@connectrpc/connect-node": "^2.2.0"
53
+ "@connectrpc/connect-node": "^2.2.0",
54
+ "canonicalize": "^2.1.0"
54
55
  },
55
56
  "peerDependencies": {
56
57
  "@testcontainers/postgresql": "^12.1.0",