@nwire/forge 0.9.1 → 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 (291) hide show
  1. package/README.md +133 -155
  2. package/dist/foundation.d.ts +0 -13
  3. package/dist/foundation.js +2 -13
  4. package/dist/framework-events.d.ts +51 -54
  5. package/dist/framework-events.js +18 -65
  6. package/dist/{cli-runner.d.ts → helpers/cli-runner.d.ts} +2 -3
  7. package/dist/{cli-runner.js → helpers/cli-runner.js} +11 -27
  8. package/dist/{public-marker.d.ts → helpers/public-marker.d.ts} +0 -1
  9. package/dist/{public-marker.js → helpers/public-marker.js} +0 -1
  10. package/dist/{response.d.ts → helpers/response.d.ts} +0 -1
  11. package/dist/{response.js → helpers/response.js} +0 -1
  12. package/dist/helpers/retry-helpers.d.ts +22 -0
  13. package/dist/helpers/retry-helpers.js +43 -0
  14. package/dist/{validate.d.ts → helpers/validate.d.ts} +0 -1
  15. package/dist/{validate.js → helpers/validate.js} +0 -1
  16. package/dist/index.d.ts +42 -48
  17. package/dist/index.js +47 -55
  18. package/dist/{event-message.d.ts → messages/event-message.d.ts} +0 -1
  19. package/dist/{event-message.js → messages/event-message.js} +0 -1
  20. package/dist/{dev-logger.d.ts → observability/dev-logger.d.ts} +2 -2
  21. package/dist/{dev-logger.js → observability/dev-logger.js} +0 -30
  22. package/dist/{define-action.d.ts → primitives/define-action.d.ts} +0 -1
  23. package/dist/{define-action.js → primitives/define-action.js} +0 -1
  24. package/dist/{define-actor.d.ts → primitives/define-actor.d.ts} +0 -1
  25. package/dist/{define-actor.js → primitives/define-actor.js} +0 -1
  26. package/dist/{define-cron.d.ts → primitives/define-cron.d.ts} +0 -1
  27. package/dist/{define-cron.js → primitives/define-cron.js} +0 -1
  28. package/dist/{define-error.d.ts → primitives/define-error.d.ts} +0 -1
  29. package/dist/{define-error.js → primitives/define-error.js} +0 -1
  30. package/dist/{define-external-call.d.ts → primitives/define-external-call.d.ts} +0 -1
  31. package/dist/{define-external-call.js → primitives/define-external-call.js} +0 -1
  32. package/dist/{define-handler.d.ts → primitives/define-handler.d.ts} +29 -2
  33. package/dist/{define-handler.js → primitives/define-handler.js} +13 -2
  34. package/dist/{define-inbound-webhook.d.ts → primitives/define-inbound-webhook.d.ts} +1 -2
  35. package/dist/{define-inbound-webhook.js → primitives/define-inbound-webhook.js} +1 -2
  36. package/dist/{define-inbox.d.ts → primitives/define-inbox.d.ts} +0 -1
  37. package/dist/{define-inbox.js → primitives/define-inbox.js} +0 -1
  38. package/dist/{define-outbox.d.ts → primitives/define-outbox.d.ts} +0 -1
  39. package/dist/{define-outbox.js → primitives/define-outbox.js} +0 -1
  40. package/dist/{define-projection.d.ts → primitives/define-projection.d.ts} +0 -1
  41. package/dist/{define-projection.js → primitives/define-projection.js} +0 -1
  42. package/dist/{define-query.d.ts → primitives/define-query.d.ts} +1 -2
  43. package/dist/{define-query.js → primitives/define-query.js} +1 -2
  44. package/dist/{define-schema.d.ts → primitives/define-schema.d.ts} +1 -2
  45. package/dist/{define-schema.js → primitives/define-schema.js} +1 -2
  46. package/dist/{define-upcaster.d.ts → primitives/define-upcaster.d.ts} +0 -1
  47. package/dist/{define-upcaster.js → primitives/define-upcaster.js} +0 -1
  48. package/dist/{define-workflow.d.ts → primitives/define-workflow.d.ts} +2 -3
  49. package/dist/{define-workflow.js → primitives/define-workflow.js} +2 -3
  50. package/dist/runtime/create-forge-app.d.ts +64 -0
  51. package/dist/runtime/create-forge-app.js +78 -0
  52. package/dist/runtime/forge-dispatcher.d.ts +148 -0
  53. package/dist/{runtime.js → runtime/forge-dispatcher.js} +242 -571
  54. package/dist/runtime/forge-plugin.d.ts +59 -0
  55. package/dist/runtime/forge-plugin.js +121 -0
  56. package/dist/runtime/forge-types.d.ts +204 -0
  57. package/dist/runtime/forge-types.js +5 -0
  58. package/dist/{actor-store.d.ts → stores/actor-store.d.ts} +1 -2
  59. package/dist/{actor-store.js → stores/actor-store.js} +0 -1
  60. package/dist/{idempotency-store.d.ts → stores/idempotency-store.d.ts} +0 -1
  61. package/dist/{idempotency-store.js → stores/idempotency-store.js} +0 -1
  62. package/dist/{projection-store.d.ts → stores/projection-store.d.ts} +0 -1
  63. package/dist/{projection-store.js → stores/projection-store.js} +0 -1
  64. package/dist/{workflow-timer-store.d.ts → stores/workflow-timer-store.d.ts} +0 -1
  65. package/dist/{workflow-timer-store.js → stores/workflow-timer-store.js} +0 -1
  66. package/package.json +11 -11
  67. package/dist/__tests__/action-hooks.test.d.ts +0 -8
  68. package/dist/__tests__/action-hooks.test.d.ts.map +0 -1
  69. package/dist/__tests__/action-hooks.test.js +0 -95
  70. package/dist/__tests__/action-hooks.test.js.map +0 -1
  71. package/dist/__tests__/actor-methods.test.d.ts +0 -9
  72. package/dist/__tests__/actor-methods.test.d.ts.map +0 -1
  73. package/dist/__tests__/actor-methods.test.js +0 -210
  74. package/dist/__tests__/actor-methods.test.js.map +0 -1
  75. package/dist/__tests__/actor-schema-bound.test.d.ts +0 -6
  76. package/dist/__tests__/actor-schema-bound.test.d.ts.map +0 -1
  77. package/dist/__tests__/actor-schema-bound.test.js +0 -112
  78. package/dist/__tests__/actor-schema-bound.test.js.map +0 -1
  79. package/dist/__tests__/actor-workflow-hooks.test.d.ts +0 -8
  80. package/dist/__tests__/actor-workflow-hooks.test.d.ts.map +0 -1
  81. package/dist/__tests__/actor-workflow-hooks.test.js +0 -106
  82. package/dist/__tests__/actor-workflow-hooks.test.js.map +0 -1
  83. package/dist/__tests__/app-capabilities.test.d.ts +0 -19
  84. package/dist/__tests__/app-capabilities.test.d.ts.map +0 -1
  85. package/dist/__tests__/app-capabilities.test.js +0 -57
  86. package/dist/__tests__/app-capabilities.test.js.map +0 -1
  87. package/dist/__tests__/cli-runner.test.d.ts +0 -6
  88. package/dist/__tests__/cli-runner.test.d.ts.map +0 -1
  89. package/dist/__tests__/cli-runner.test.js +0 -158
  90. package/dist/__tests__/cli-runner.test.js.map +0 -1
  91. package/dist/__tests__/create-app.test.d.ts +0 -18
  92. package/dist/__tests__/create-app.test.d.ts.map +0 -1
  93. package/dist/__tests__/create-app.test.js +0 -189
  94. package/dist/__tests__/create-app.test.js.map +0 -1
  95. package/dist/__tests__/cross-service-bus.test.d.ts +0 -8
  96. package/dist/__tests__/cross-service-bus.test.d.ts.map +0 -1
  97. package/dist/__tests__/cross-service-bus.test.js +0 -139
  98. package/dist/__tests__/cross-service-bus.test.js.map +0 -1
  99. package/dist/__tests__/define-schema.test.d.ts +0 -5
  100. package/dist/__tests__/define-schema.test.d.ts.map +0 -1
  101. package/dist/__tests__/define-schema.test.js +0 -83
  102. package/dist/__tests__/define-schema.test.js.map +0 -1
  103. package/dist/__tests__/dev-logger.test.d.ts +0 -9
  104. package/dist/__tests__/dev-logger.test.d.ts.map +0 -1
  105. package/dist/__tests__/dev-logger.test.js +0 -126
  106. package/dist/__tests__/dev-logger.test.js.map +0 -1
  107. package/dist/__tests__/external-call.test.d.ts +0 -14
  108. package/dist/__tests__/external-call.test.d.ts.map +0 -1
  109. package/dist/__tests__/external-call.test.js +0 -99
  110. package/dist/__tests__/external-call.test.js.map +0 -1
  111. package/dist/__tests__/framework-events.test.d.ts +0 -13
  112. package/dist/__tests__/framework-events.test.d.ts.map +0 -1
  113. package/dist/__tests__/framework-events.test.js +0 -204
  114. package/dist/__tests__/framework-events.test.js.map +0 -1
  115. package/dist/__tests__/inline-handler.test.d.ts +0 -8
  116. package/dist/__tests__/inline-handler.test.d.ts.map +0 -1
  117. package/dist/__tests__/inline-handler.test.js +0 -101
  118. package/dist/__tests__/inline-handler.test.js.map +0 -1
  119. package/dist/__tests__/lifecycle-logging.test.d.ts +0 -12
  120. package/dist/__tests__/lifecycle-logging.test.d.ts.map +0 -1
  121. package/dist/__tests__/lifecycle-logging.test.js +0 -114
  122. package/dist/__tests__/lifecycle-logging.test.js.map +0 -1
  123. package/dist/__tests__/middleware.test.d.ts +0 -7
  124. package/dist/__tests__/middleware.test.d.ts.map +0 -1
  125. package/dist/__tests__/middleware.test.js +0 -109
  126. package/dist/__tests__/middleware.test.js.map +0 -1
  127. package/dist/__tests__/module-needs.test.d.ts +0 -10
  128. package/dist/__tests__/module-needs.test.d.ts.map +0 -1
  129. package/dist/__tests__/module-needs.test.js +0 -77
  130. package/dist/__tests__/module-needs.test.js.map +0 -1
  131. package/dist/__tests__/module-topo-sort.test.d.ts +0 -15
  132. package/dist/__tests__/module-topo-sort.test.d.ts.map +0 -1
  133. package/dist/__tests__/module-topo-sort.test.js +0 -105
  134. package/dist/__tests__/module-topo-sort.test.js.map +0 -1
  135. package/dist/__tests__/multi-tenancy.test.d.ts +0 -10
  136. package/dist/__tests__/multi-tenancy.test.d.ts.map +0 -1
  137. package/dist/__tests__/multi-tenancy.test.js +0 -122
  138. package/dist/__tests__/multi-tenancy.test.js.map +0 -1
  139. package/dist/__tests__/needs-topology.test.d.ts +0 -11
  140. package/dist/__tests__/needs-topology.test.d.ts.map +0 -1
  141. package/dist/__tests__/needs-topology.test.js +0 -82
  142. package/dist/__tests__/needs-topology.test.js.map +0 -1
  143. package/dist/__tests__/plugin-app-narrow.test.d.ts +0 -12
  144. package/dist/__tests__/plugin-app-narrow.test.d.ts.map +0 -1
  145. package/dist/__tests__/plugin-app-narrow.test.js +0 -77
  146. package/dist/__tests__/plugin-app-narrow.test.js.map +0 -1
  147. package/dist/__tests__/plugin-closure.test.d.ts +0 -15
  148. package/dist/__tests__/plugin-closure.test.d.ts.map +0 -1
  149. package/dist/__tests__/plugin-closure.test.js +0 -140
  150. package/dist/__tests__/plugin-closure.test.js.map +0 -1
  151. package/dist/__tests__/plugin-stress.test.d.ts +0 -21
  152. package/dist/__tests__/plugin-stress.test.d.ts.map +0 -1
  153. package/dist/__tests__/plugin-stress.test.js +0 -203
  154. package/dist/__tests__/plugin-stress.test.js.map +0 -1
  155. package/dist/__tests__/plugin.test.d.ts +0 -10
  156. package/dist/__tests__/plugin.test.d.ts.map +0 -1
  157. package/dist/__tests__/plugin.test.js +0 -225
  158. package/dist/__tests__/plugin.test.js.map +0 -1
  159. package/dist/__tests__/primitives.test.d.ts +0 -9
  160. package/dist/__tests__/primitives.test.d.ts.map +0 -1
  161. package/dist/__tests__/primitives.test.js +0 -434
  162. package/dist/__tests__/primitives.test.js.map +0 -1
  163. package/dist/__tests__/production-readiness.test.d.ts +0 -22
  164. package/dist/__tests__/production-readiness.test.d.ts.map +0 -1
  165. package/dist/__tests__/production-readiness.test.js +0 -196
  166. package/dist/__tests__/production-readiness.test.js.map +0 -1
  167. package/dist/__tests__/provider.test.d.ts +0 -6
  168. package/dist/__tests__/provider.test.d.ts.map +0 -1
  169. package/dist/__tests__/provider.test.js +0 -122
  170. package/dist/__tests__/provider.test.js.map +0 -1
  171. package/dist/__tests__/public-marker.test.d.ts +0 -7
  172. package/dist/__tests__/public-marker.test.d.ts.map +0 -1
  173. package/dist/__tests__/public-marker.test.js +0 -58
  174. package/dist/__tests__/public-marker.test.js.map +0 -1
  175. package/dist/__tests__/retry-dlq.test.d.ts +0 -6
  176. package/dist/__tests__/retry-dlq.test.d.ts.map +0 -1
  177. package/dist/__tests__/retry-dlq.test.js +0 -68
  178. package/dist/__tests__/retry-dlq.test.js.map +0 -1
  179. package/dist/__tests__/validate.test.d.ts +0 -5
  180. package/dist/__tests__/validate.test.d.ts.map +0 -1
  181. package/dist/__tests__/validate.test.js +0 -53
  182. package/dist/__tests__/validate.test.js.map +0 -1
  183. package/dist/__tests__/workflow-saga.test.d.ts +0 -7
  184. package/dist/__tests__/workflow-saga.test.d.ts.map +0 -1
  185. package/dist/__tests__/workflow-saga.test.js +0 -265
  186. package/dist/__tests__/workflow-saga.test.js.map +0 -1
  187. package/dist/actor-store.d.ts.map +0 -1
  188. package/dist/actor-store.js.map +0 -1
  189. package/dist/cli-runner.d.ts.map +0 -1
  190. package/dist/cli-runner.js.map +0 -1
  191. package/dist/create-app.d.ts +0 -146
  192. package/dist/create-app.d.ts.map +0 -1
  193. package/dist/create-app.js +0 -703
  194. package/dist/create-app.js.map +0 -1
  195. package/dist/define-action.d.ts.map +0 -1
  196. package/dist/define-action.js.map +0 -1
  197. package/dist/define-actor.d.ts.map +0 -1
  198. package/dist/define-actor.js.map +0 -1
  199. package/dist/define-app.d.ts +0 -104
  200. package/dist/define-app.d.ts.map +0 -1
  201. package/dist/define-app.js +0 -49
  202. package/dist/define-app.js.map +0 -1
  203. package/dist/define-cron.d.ts.map +0 -1
  204. package/dist/define-cron.js.map +0 -1
  205. package/dist/define-error.d.ts.map +0 -1
  206. package/dist/define-error.js.map +0 -1
  207. package/dist/define-external-call.d.ts.map +0 -1
  208. package/dist/define-external-call.js.map +0 -1
  209. package/dist/define-handler.d.ts.map +0 -1
  210. package/dist/define-handler.js.map +0 -1
  211. package/dist/define-inbound-webhook.d.ts.map +0 -1
  212. package/dist/define-inbound-webhook.js.map +0 -1
  213. package/dist/define-inbox.d.ts.map +0 -1
  214. package/dist/define-inbox.js.map +0 -1
  215. package/dist/define-initializer.d.ts +0 -54
  216. package/dist/define-initializer.d.ts.map +0 -1
  217. package/dist/define-initializer.js +0 -38
  218. package/dist/define-initializer.js.map +0 -1
  219. package/dist/define-middleware.d.ts +0 -8
  220. package/dist/define-middleware.d.ts.map +0 -1
  221. package/dist/define-middleware.js +0 -8
  222. package/dist/define-middleware.js.map +0 -1
  223. package/dist/define-model.d.ts +0 -10
  224. package/dist/define-model.d.ts.map +0 -1
  225. package/dist/define-model.js +0 -13
  226. package/dist/define-model.js.map +0 -1
  227. package/dist/define-module.d.ts +0 -160
  228. package/dist/define-module.d.ts.map +0 -1
  229. package/dist/define-module.js +0 -63
  230. package/dist/define-module.js.map +0 -1
  231. package/dist/define-outbox.d.ts.map +0 -1
  232. package/dist/define-outbox.js.map +0 -1
  233. package/dist/define-plugin.d.ts +0 -195
  234. package/dist/define-plugin.d.ts.map +0 -1
  235. package/dist/define-plugin.js +0 -220
  236. package/dist/define-plugin.js.map +0 -1
  237. package/dist/define-projection.d.ts.map +0 -1
  238. package/dist/define-projection.js.map +0 -1
  239. package/dist/define-provider.d.ts +0 -49
  240. package/dist/define-provider.d.ts.map +0 -1
  241. package/dist/define-provider.js +0 -45
  242. package/dist/define-provider.js.map +0 -1
  243. package/dist/define-query.d.ts.map +0 -1
  244. package/dist/define-query.js.map +0 -1
  245. package/dist/define-resolver.d.ts +0 -111
  246. package/dist/define-resolver.d.ts.map +0 -1
  247. package/dist/define-resolver.js +0 -146
  248. package/dist/define-resolver.js.map +0 -1
  249. package/dist/define-schema.d.ts.map +0 -1
  250. package/dist/define-schema.js.map +0 -1
  251. package/dist/define-upcaster.d.ts.map +0 -1
  252. package/dist/define-upcaster.js.map +0 -1
  253. package/dist/define-workflow.d.ts.map +0 -1
  254. package/dist/define-workflow.js.map +0 -1
  255. package/dist/dev-logger.d.ts.map +0 -1
  256. package/dist/dev-logger.js.map +0 -1
  257. package/dist/event-message.d.ts.map +0 -1
  258. package/dist/event-message.js.map +0 -1
  259. package/dist/foundation.d.ts.map +0 -1
  260. package/dist/foundation.js.map +0 -1
  261. package/dist/framework-event-bus.d.ts +0 -13
  262. package/dist/framework-event-bus.d.ts.map +0 -1
  263. package/dist/framework-event-bus.js +0 -13
  264. package/dist/framework-event-bus.js.map +0 -1
  265. package/dist/framework-events.d.ts.map +0 -1
  266. package/dist/framework-events.js.map +0 -1
  267. package/dist/idempotency-store.d.ts.map +0 -1
  268. package/dist/idempotency-store.js.map +0 -1
  269. package/dist/index.d.ts.map +0 -1
  270. package/dist/index.js.map +0 -1
  271. package/dist/module-surface.d.ts +0 -47
  272. package/dist/module-surface.d.ts.map +0 -1
  273. package/dist/module-surface.js +0 -65
  274. package/dist/module-surface.js.map +0 -1
  275. package/dist/projection-store.d.ts.map +0 -1
  276. package/dist/projection-store.js.map +0 -1
  277. package/dist/public-marker.d.ts.map +0 -1
  278. package/dist/public-marker.js.map +0 -1
  279. package/dist/response.d.ts.map +0 -1
  280. package/dist/response.js.map +0 -1
  281. package/dist/runtime.d.ts +0 -621
  282. package/dist/runtime.d.ts.map +0 -1
  283. package/dist/runtime.js.map +0 -1
  284. package/dist/validate.d.ts.map +0 -1
  285. package/dist/validate.js.map +0 -1
  286. package/dist/when.d.ts +0 -101
  287. package/dist/when.d.ts.map +0 -1
  288. package/dist/when.js +0 -57
  289. package/dist/when.js.map +0 -1
  290. package/dist/workflow-timer-store.d.ts.map +0 -1
  291. package/dist/workflow-timer-store.js.map +0 -1
@@ -1,160 +0,0 @@
1
- /**
2
- * `defineModule` — a bounded context as an explicit table of contents.
3
- *
4
- * export default defineModule('submissions', {
5
- * actions: [submitAnswer, flagForReview, gradeSubmission, autoGrade],
6
- * actors: [Submission],
7
- * projections: [SubmissionsByStudent],
8
- * queries: [submissionsByStudent, submissionById],
9
- * events: [AnswerSubmittedEvent, AnswerFlaggedForReviewEvent, ...],
10
- * handlers: [submitAnswerHandler, flagForReviewHandler, ...],
11
- * workflows: [autoGradeWorkflow, notifyOnFlaggedWorkflow]
12
- * })
13
- *
14
- * Modules own DOMAIN, not transport — route bindings live in the app layer
15
- * (transport interface builders) where they belong. Auto-discovery (file
16
- * globs, directory walks) is rejected: new team members read one file to
17
- * find every surface in the module. The module is what `createApp` registers
18
- * with the runtime.
19
- */
20
- import { type SourceLocation } from "@nwire/messages";
21
- import type { ActionDefinition } from "./define-action.js";
22
- import type { ActorDefinition } from "./define-actor.js";
23
- import type { HandlerDefinition } from "./define-handler.js";
24
- import type { ProjectionDefinition } from "./define-projection.js";
25
- import type { QueryDefinition } from "./define-query.js";
26
- import type { WorkflowDefinition } from "./define-workflow.js";
27
- import type { EventDefinition } from "@nwire/messages";
28
- import type { ExternalCallDefinition } from "./define-external-call.js";
29
- import type { InboundWebhookDefinition } from "./define-inbound-webhook.js";
30
- import type { OutboxDefinition } from "./define-outbox.js";
31
- import type { InboxDefinition } from "./define-inbox.js";
32
- import type { CronDefinition } from "./define-cron.js";
33
- import type { NwireInterface } from "@nwire/interface";
34
- /**
35
- * Cross-module dependencies declared by this module.
36
- *
37
- * The existing `events` and `actions` arrays on a manifest serve as the
38
- * module's implicit **provides** (what it owns + emits). `needs` declares
39
- * the inverse — what this module consumes from other modules.
40
- *
41
- * defineModule('mastery', {
42
- * events: [MasteryContributionRecordedEvent], // this module's provides
43
- * workflows: [updateOnGradedReaction], // listens to ...
44
- * needs: {
45
- * events: [SubmissionAutoGradedEvent, SubmissionManuallyGradedEvent]
46
- * }
47
- * })
48
- *
49
- * `createApp` validates the resulting dep graph at startup:
50
- * - every needed event must be in some OTHER module's `events` array,
51
- * - the producing event must be `visibility: 'public'` (the default),
52
- * - every needed action must be in some other module's `actions`,
53
- * - a module may not `need` what it itself provides (self-reference).
54
- *
55
- * Violations throw with a message that names the offending module + ref.
56
- * This catches typos and refactor breakage at boot, before the first
57
- * real dispatch, and makes the cross-module graph explicit for readers.
58
- */
59
- export interface ModuleNeeds {
60
- /**
61
- * Events this module subscribes to that are provided by another module in
62
- * the SAME app/service. Validated in-process at createApp.
63
- */
64
- readonly events?: readonly EventDefinition[];
65
- /**
66
- * Actions this module dispatches that are provided by another module in
67
- * the SAME app/service. Validated in-process at createApp.
68
- */
69
- readonly actions?: readonly ActionDefinition[];
70
- /**
71
- * Events this module subscribes to that originate in OTHER services (a
72
- * different `defineApp(...)` running in a different process). These flow
73
- * over the configured `EventBus` (`@nwire/bus`). createApp:
74
- * - rejects an externalEvent that ALSO appears in this app's provides
75
- * (you don't reach across the bus for your own publishes),
76
- * - auto-subscribes the bus to each external event name at boot,
77
- * - routes received bus messages to `runtime.applyExternalEvent`.
78
- *
79
- * If the app has no bus configured but a module declares externalEvents,
80
- * createApp throws — the dep is unsatisfiable.
81
- */
82
- readonly externalEvents?: readonly EventDefinition[];
83
- }
84
- /** A journey step a bounded context owns — Studio renders these as the
85
- * spine of its persona view. `id` ties back to action.journeyStep. */
86
- export interface JourneyStep {
87
- readonly id: string;
88
- readonly label: string;
89
- readonly description?: string;
90
- }
91
- export interface ModuleManifest {
92
- readonly actions?: readonly ActionDefinition[];
93
- readonly actors?: readonly ActorDefinition<any>[];
94
- readonly handlers?: readonly HandlerDefinition<any>[];
95
- readonly projections?: readonly ProjectionDefinition<any>[];
96
- readonly queries?: readonly QueryDefinition<any, any, any>[];
97
- readonly events?: readonly EventDefinition[];
98
- /**
99
- * Optional split of `events` into domain (BC-internal) + integration
100
- * (public bus contract). If both are provided, `events` is computed as
101
- * the union. If only `events` is provided, scope is inferred from
102
- * each event's `scope` / `visibility`.
103
- */
104
- readonly domainEvents?: readonly EventDefinition[];
105
- readonly integrationEvents?: readonly EventDefinition[];
106
- /**
107
- * Workflows — the unified primitive for event-driven side effects
108
- * (reactions, translators, sagas). One declaration, three sophistication
109
- * levels; the runtime picks fast-path dispatch vs full saga semantics
110
- * based on what each workflow declares.
111
- */
112
- readonly workflows?: readonly WorkflowDefinition[];
113
- readonly needs?: ModuleNeeds;
114
- readonly externalCalls?: readonly ExternalCallDefinition<any, any>[];
115
- readonly inboundWebhooks?: readonly InboundWebhookDefinition<any>[];
116
- readonly outboxes?: readonly OutboxDefinition[];
117
- readonly inboxes?: readonly InboxDefinition[];
118
- readonly crons?: readonly CronDefinition[];
119
- /**
120
- * Wires the module owns — transport interfaces (http / queue / mcp / …)
121
- * declared inside the module's own `__wires__/` folder. The fractal
122
- * "module ≅ small project" layout means a module can ship its own
123
- * transports for embedded / standalone runs; the parent app composes
124
- * them onto its endpoint at boot.
125
- *
126
- * Wires here are values produced by `http()` / `queue()` / `mcp()` /
127
- * etc. — they extend `InterfaceBuilder` and are servable by
128
- * `@nwire/endpoint`. The framework treats them as opaque at the module
129
- * layer; transports own the semantics.
130
- */
131
- readonly wires?: readonly NwireInterface[];
132
- /** Studio-aware: free-form description. */
133
- readonly description?: string;
134
- /** Studio-aware: owning team/people identifiers. */
135
- readonly owners?: readonly string[];
136
- /** Studio-aware: declared journey steps this BC owns. */
137
- readonly journey?: readonly JourneyStep[];
138
- }
139
- /**
140
- * Public surface of a module — the names of every item this module
141
- * exposed via `.public()` in its manifest. `createApp` validates cross-
142
- * module needs against these sets; runtime cross-module dispatch is
143
- * permitted only for names that appear here.
144
- */
145
- export interface ModulePublicSurface {
146
- readonly actions: ReadonlySet<string>;
147
- readonly events: ReadonlySet<string>;
148
- readonly queries: ReadonlySet<string>;
149
- readonly workflows: ReadonlySet<string>;
150
- }
151
- export interface ModuleDefinition {
152
- readonly $kind: "module";
153
- readonly name: string;
154
- readonly manifest: ModuleManifest;
155
- readonly publicSurface: ModulePublicSurface;
156
- /** Where the module was declared. Studio uses this for IDE-open links. */
157
- readonly $source?: SourceLocation;
158
- }
159
- export declare function defineModule(name: string, manifest: ModuleManifest): ModuleDefinition;
160
- //# sourceMappingURL=define-module.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"define-module.d.ts","sourceRoot":"","sources":["../src/define-module.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAyB,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,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IACtB,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,aAAa,EAAE,mBAAmB,CAAC;IAC5C,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC;CACnC;AAYD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,GAAG,gBAAgB,CAiCrF"}
@@ -1,63 +0,0 @@
1
- /**
2
- * `defineModule` — a bounded context as an explicit table of contents.
3
- *
4
- * export default defineModule('submissions', {
5
- * actions: [submitAnswer, flagForReview, gradeSubmission, autoGrade],
6
- * actors: [Submission],
7
- * projections: [SubmissionsByStudent],
8
- * queries: [submissionsByStudent, submissionById],
9
- * events: [AnswerSubmittedEvent, AnswerFlaggedForReviewEvent, ...],
10
- * handlers: [submitAnswerHandler, flagForReviewHandler, ...],
11
- * workflows: [autoGradeWorkflow, notifyOnFlaggedWorkflow]
12
- * })
13
- *
14
- * Modules own DOMAIN, not transport — route bindings live in the app layer
15
- * (transport interface builders) where they belong. Auto-discovery (file
16
- * globs, directory walks) is rejected: new team members read one file to
17
- * find every surface in the module. The module is what `createApp` registers
18
- * with the runtime.
19
- */
20
- import { captureSourceLocation } from "@nwire/messages";
21
- function namesOf(items) {
22
- const out = new Set();
23
- for (const it of items ?? []) {
24
- if (it.$public === true)
25
- out.add(it.name);
26
- }
27
- return out;
28
- }
29
- export function defineModule(name, manifest) {
30
- const $source = captureSourceLocation();
31
- // If the user split events into domainEvents + integrationEvents, auto-merge
32
- // into `events` so downstream registries find them. If the user provided
33
- // their own `events` too, prefer the explicit value.
34
- const split = [...(manifest.domainEvents ?? []), ...(manifest.integrationEvents ?? [])];
35
- const events = manifest.events ?? (split.length > 0 ? split : undefined);
36
- // The public surface is whatever was tagged `.public()` in this manifest.
37
- // Until the example codebase fully migrates, events with the older
38
- // `visibility: "public"` flag are also treated as part of the surface so
39
- // pre-existing modules keep working.
40
- const publicSurface = {
41
- actions: namesOf(manifest.actions),
42
- queries: namesOf(manifest.queries),
43
- workflows: namesOf(manifest.workflows),
44
- events: (() => {
45
- const s = namesOf(events);
46
- for (const e of events ?? []) {
47
- if (e.$public === true)
48
- s.add(e.name);
49
- else if (e.visibility === "public")
50
- s.add(e.name);
51
- }
52
- return s;
53
- })(),
54
- };
55
- return {
56
- $kind: "module",
57
- name,
58
- manifest: { ...manifest, events },
59
- publicSurface,
60
- $source,
61
- };
62
- }
63
- //# sourceMappingURL=define-module.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"define-module.js","sourceRoot":"","sources":["../src/define-module.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,qBAAqB,EAAuB,MAAM,iBAAiB,CAAC;AAwJ7E,SAAS,OAAO,CACd,KAA+B;IAE/B,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,KAAK,MAAM,EAAE,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC;QAC7B,IAAI,EAAE,CAAC,OAAO,KAAK,IAAI;YAAE,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,QAAwB;IACjE,MAAM,OAAO,GAAG,qBAAqB,EAAE,CAAC;IACxC,6EAA6E;IAC7E,yEAAyE;IACzE,qDAAqD;IACrD,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,YAAY,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC,CAAC;IACxF,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAEzE,0EAA0E;IAC1E,mEAA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AAE,MAAM,CAAC;IAClC,6CAA6C;IAC7C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,SAAS,eAAe,EAAE,CAAC;IAC/C,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,gBAAgB,CAU/D"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"define-outbox.js","sourceRoot":"","sources":["../src/define-outbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AA0BH,MAAM,UAAU,YAAY,CAAC,IAAgB;IAC3C,OAAO;QACL,KAAK,EAAE,QAAQ;QACf,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,eAAe,EAAE,IAAI,CAAC,eAAe,IAAI,IAAI;QAC7C,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,GAAG;QAC9B,IAAI,EAAE,IAAI,CAAC,IAAI;KAChB,CAAC;AACJ,CAAC"}
@@ -1,195 +0,0 @@
1
- /**
2
- * `definePlugin` — first-class extension primitive.
3
- *
4
- * Plugins extend the FRAMEWORK; modules provide DOMAIN. The distinction is
5
- * load-bearing — module code is "what the system does"; plugin code is
6
- * "what cuts across the system."
7
- *
8
- * Plugin examples (cross-cutting):
9
- * - Tracing: open a span around every dispatch (middleware).
10
- * - Audit log: persist {action, user, input, result} per dispatch.
11
- * - Authz: enforce per-action policy before dispatch.
12
- * - Rate-limiting: throttle dispatches by user / tenant / action.
13
- * - Observability: register Prometheus metrics, expose /metrics.
14
- *
15
- * Two authoring forms — pick whichever is clearer:
16
- *
17
- * 1. Closure form (recommended for most plugins):
18
- *
19
- * definePlugin("audit", ({ bind, on, after, middleware, boot }) => {
20
- * const log = bind("auditLog", () => new AuditLog())
21
- * after("post.publish", async ({ result }) => log.write(result))
22
- * middleware(async (next, action, input, ctx) => {
23
- * log.start(ctx.envelope.messageId, action.name)
24
- * try { return await next() }
25
- * finally { log.finish(ctx.envelope.messageId) }
26
- * })
27
- * boot(async () => log.connect())
28
- * })
29
- *
30
- * 2. Object form (kept for back-compat and explicit-lifecycle cases):
31
- *
32
- * definePlugin("audit", {
33
- * register: (container) => container.register("auditLog", ...),
34
- * boot: async (container) => { ... },
35
- * shutdown: async (container) => { ... },
36
- * middleware: [ ... ],
37
- * })
38
- *
39
- * The closure form's `on`/`before`/`after` subscribe to framework events
40
- * (see `framework-events.ts`) so plugins can react to lifecycle and
41
- * dispatch events the same way they'd react to a domain event — there is
42
- * no separate "hooks" system.
43
- *
44
- * Plugins are listed in `createApp({ plugins: [...] })`. Sequencing:
45
- * start: plugin register / setup (sync) → providers boot → plugin boot
46
- * stop: shutdown plugins in reverse → shutdown providers in reverse
47
- */
48
- import type { Container } from "@nwire/container";
49
- import { type SourceLocation } from "@nwire/messages";
50
- import type { DispatchMiddleware, Runtime } from "./runtime.js";
51
- import type { EventMessage } from "./event-message.js";
52
- import type { ActorDefinition } from "./define-actor.js";
53
- import type { MessageEnvelope } from "@nwire/envelope";
54
- import type { FrameworkEventDefinition } from "./framework-events.js";
55
- import type { FrameworkEventHandler } from "./framework-event-bus.js";
56
- import type { AppPluginDefinition } from "@nwire/app";
57
- /** Hook fired by the runtime after an actor transitions to a new state. */
58
- export type ActorTransitionHook = (actor: ActorDefinition, key: string, fromState: string, toState: string, event: EventMessage, envelope: MessageEnvelope) => Promise<void> | void;
59
- export interface PluginActorHooks {
60
- readonly afterTransition?: ActorTransitionHook;
61
- }
62
- /**
63
- * The builder passed to a closure-form plugin. Every method mutates the
64
- * world (container, runtime) immediately — there's no separate "apply"
65
- * step. Returning values from `bind` gives ergonomic access to the just-
66
- * registered binding (handy when the plugin's own subscriptions need it).
67
- */
68
- export interface PluginContext {
69
- readonly container: Container;
70
- readonly runtime: Runtime;
71
- readonly config: Record<string, any>;
72
- /**
73
- * Register a singleton on the container. The factory runs once, lazily,
74
- * the first time something resolves the name. Returns the binding name
75
- * so callers can immediately resolve if needed.
76
- */
77
- bind<T>(name: string, factory: () => T): string;
78
- /** Resolve a previously-bound value (provider or other plugin's bind). */
79
- resolve<T>(name: string): T;
80
- /**
81
- * Subscribe to ANY event — framework or domain. For framework events the
82
- * payload type is the event's `__payload` marker. For domain events use
83
- * `runtime.frameworkEvents` directly or rely on the workflow primitive.
84
- */
85
- on<TPayload>(event: FrameworkEventDefinition<TPayload>, handler: FrameworkEventHandler<TPayload>, priority?: number): void;
86
- /**
87
- * Sugar over `on(ActionDispatching, ...)` scoped to one action. Return
88
- * `false` to veto the dispatch (interceptable). Throw to fail.
89
- *
90
- * before("post.publish", async ({ ctx }) => {
91
- * if (!ctx.envelope.user) return false // reject anonymous
92
- * })
93
- */
94
- before(actionName: string, handler: (payload: {
95
- readonly action: import("./define-action.js").ActionDefinition;
96
- readonly input: unknown;
97
- readonly ctx: import("./define-handler.js").HandlerContext;
98
- }) => Promise<void | boolean> | void | boolean): void;
99
- /**
100
- * Sugar over `on(ActionCompleted, ...)` scoped to one action. Observable;
101
- * runs in parallel with other subscribers. Throws are logged, not fatal.
102
- */
103
- after(actionName: string, handler: (payload: {
104
- readonly action: import("./define-action.js").ActionDefinition;
105
- readonly input: unknown;
106
- readonly result: unknown;
107
- readonly durationMs: number;
108
- }) => Promise<void> | void): void;
109
- /** Add a dispatch middleware. Onion-style; first call is outermost. */
110
- middleware(mw: DispatchMiddleware): void;
111
- /** Hook actor transitions (every actor, every state change, every event). */
112
- actorHook(hook: ActorTransitionHook): void;
113
- /** Register an async boot callback — runs after all providers booted. */
114
- boot(fn: () => Promise<void> | void): void;
115
- /** Register an async shutdown callback — runs in REVERSE registration order. */
116
- shutdown(fn: () => Promise<void> | void): void;
117
- }
118
- /** The closure form's setup signature. */
119
- export type PluginSetup = (ctx: PluginContext) => void | Promise<void>;
120
- export interface PluginDefinition {
121
- readonly $kind: "plugin";
122
- readonly name: string;
123
- /**
124
- * Synchronous container registration — runs before any provider boot.
125
- * Use for value bindings the plugin will need later.
126
- */
127
- readonly register?: (container: Container) => void;
128
- /**
129
- * Closure-form setup. The framework runs this during plugin-register
130
- * with `{ container, runtime, config }` and the builder helpers. Only
131
- * set by the closure form; object-form plugins leave it undefined.
132
- */
133
- readonly setup?: PluginSetup;
134
- /**
135
- * Async startup. Runs AFTER providers have booted, BEFORE modules begin
136
- * receiving traffic. Use for any I/O the plugin needs (connect to OTEL
137
- * collector, prefetch policy, warm cache).
138
- */
139
- readonly boot?: (container: Container) => Promise<void> | void;
140
- /** Async teardown. Runs in reverse plugin order on app.stop(). */
141
- readonly shutdown?: (container: Container) => Promise<void> | void;
142
- /** Dispatch middlewares the plugin contributes. Runs onion-style. */
143
- readonly middleware?: readonly DispatchMiddleware[];
144
- /** Actor lifecycle hooks the plugin contributes. */
145
- readonly actorHooks?: PluginActorHooks;
146
- /** Call-site of `definePlugin(...)` — Studio + scan render this. */
147
- readonly $source?: SourceLocation;
148
- }
149
- export interface PluginOptions {
150
- readonly register?: (container: Container) => void;
151
- readonly boot?: (container: Container) => Promise<void> | void;
152
- readonly shutdown?: (container: Container) => Promise<void> | void;
153
- readonly middleware?: readonly DispatchMiddleware[];
154
- readonly actorHooks?: PluginActorHooks;
155
- }
156
- /**
157
- * Two callable shapes:
158
- *
159
- * definePlugin("name", (ctx) => { ... }) // closure form
160
- * definePlugin("name", { register, boot, ... }) // object form
161
- */
162
- export declare function definePlugin(name: string, setup: PluginSetup): PluginDefinition;
163
- export declare function definePlugin(name: string, options: PluginOptions): PluginDefinition;
164
- /**
165
- * Build a PluginContext bound to a specific container + runtime + config,
166
- * collecting boot/shutdown callbacks the closure registers. Used by
167
- * createApp's plugin-register loop. Returns the bound API + the lists of
168
- * boot/shutdown functions for createApp to wire into its lifecycle.
169
- */
170
- export declare function buildPluginContext(container: Container, runtime: Runtime, config: Record<string, any>, pluginName?: string): {
171
- readonly api: PluginContext;
172
- readonly boots: Array<() => Promise<void> | void>;
173
- readonly shutdowns: Array<() => Promise<void> | void>;
174
- };
175
- /**
176
- * Adapt a narrow `@nwire/app` plugin into the rich forge `PluginDefinition`
177
- * createApp expects. The narrow shape (provide / on / boot / shutdown) is a
178
- * strict subset of the rich shape, so the adaptation is straight forwarding:
179
- *
180
- * - `provide(name, lifecycle)` becomes a `bind` whose factory invokes the
181
- * lifecycle's `boot()` once, plus a shutdown step that runs
182
- * `lifecycle.shutdown(value)` against the resolved value if it was ever
183
- * materialized. Lazy resolution matches the rich `bind` contract — a
184
- * value nobody asks for is never booted (and therefore never torn down).
185
- * - `on(FrameworkEvent, handler, prio?)` maps 1:1 onto `runtime.onFramework`,
186
- * which is what the rich `api.on` already does internally.
187
- * - `boot(fn)` / `shutdown(fn)` map 1:1.
188
- *
189
- * The narrow plugin's `setup` may be async; we honor that by returning a
190
- * Promise from the rich setup. createApp's sync register loop rejects async
191
- * rich setups today, so app-plugin authors who need async work should put it
192
- * inside `api.boot(...)` — same rule as forge's closure form.
193
- */
194
- export declare function adaptAppPlugin(app: AppPluginDefinition): PluginDefinition;
195
- //# sourceMappingURL=define-plugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"define-plugin.d.ts","sourceRoot":"","sources":["../src/define-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;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AAC,UAAU,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACpD,QAAQ,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC;CACxC;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,gBAAgB,CAAC;AACjF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,gBAAgB,CAAC;AA2BrF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,EAEhB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,UAAU,GAAE,MAAoB,GAC/B;IACD,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAClD,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;CACvD,CAkFA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,mBAAmB,GAAG,gBAAgB,CAiDzE"}
@@ -1,220 +0,0 @@
1
- /**
2
- * `definePlugin` — first-class extension primitive.
3
- *
4
- * Plugins extend the FRAMEWORK; modules provide DOMAIN. The distinction is
5
- * load-bearing — module code is "what the system does"; plugin code is
6
- * "what cuts across the system."
7
- *
8
- * Plugin examples (cross-cutting):
9
- * - Tracing: open a span around every dispatch (middleware).
10
- * - Audit log: persist {action, user, input, result} per dispatch.
11
- * - Authz: enforce per-action policy before dispatch.
12
- * - Rate-limiting: throttle dispatches by user / tenant / action.
13
- * - Observability: register Prometheus metrics, expose /metrics.
14
- *
15
- * Two authoring forms — pick whichever is clearer:
16
- *
17
- * 1. Closure form (recommended for most plugins):
18
- *
19
- * definePlugin("audit", ({ bind, on, after, middleware, boot }) => {
20
- * const log = bind("auditLog", () => new AuditLog())
21
- * after("post.publish", async ({ result }) => log.write(result))
22
- * middleware(async (next, action, input, ctx) => {
23
- * log.start(ctx.envelope.messageId, action.name)
24
- * try { return await next() }
25
- * finally { log.finish(ctx.envelope.messageId) }
26
- * })
27
- * boot(async () => log.connect())
28
- * })
29
- *
30
- * 2. Object form (kept for back-compat and explicit-lifecycle cases):
31
- *
32
- * definePlugin("audit", {
33
- * register: (container) => container.register("auditLog", ...),
34
- * boot: async (container) => { ... },
35
- * shutdown: async (container) => { ... },
36
- * middleware: [ ... ],
37
- * })
38
- *
39
- * The closure form's `on`/`before`/`after` subscribe to framework events
40
- * (see `framework-events.ts`) so plugins can react to lifecycle and
41
- * dispatch events the same way they'd react to a domain event — there is
42
- * no separate "hooks" system.
43
- *
44
- * Plugins are listed in `createApp({ plugins: [...] })`. Sequencing:
45
- * start: plugin register / setup (sync) → providers boot → plugin boot
46
- * stop: shutdown plugins in reverse → shutdown providers in reverse
47
- */
48
- import { captureSourceLocation } from "@nwire/messages";
49
- export function definePlugin(name, setupOrOptions) {
50
- const $source = captureSourceLocation();
51
- if (typeof setupOrOptions === "function") {
52
- return {
53
- $kind: "plugin",
54
- name,
55
- setup: setupOrOptions,
56
- $source,
57
- };
58
- }
59
- const opts = setupOrOptions;
60
- return {
61
- $kind: "plugin",
62
- name,
63
- register: opts.register,
64
- boot: opts.boot,
65
- shutdown: opts.shutdown,
66
- middleware: opts.middleware,
67
- actorHooks: opts.actorHooks,
68
- $source,
69
- };
70
- }
71
- /**
72
- * Build a PluginContext bound to a specific container + runtime + config,
73
- * collecting boot/shutdown callbacks the closure registers. Used by
74
- * createApp's plugin-register loop. Returns the bound API + the lists of
75
- * boot/shutdown functions for createApp to wire into its lifecycle.
76
- */
77
- export function buildPluginContext(container, runtime,
78
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
79
- config, pluginName = "anonymous") {
80
- const boots = [];
81
- const shutdowns = [];
82
- const api = {
83
- container,
84
- runtime,
85
- config,
86
- bind(bindingName, factory) {
87
- let cached;
88
- let computed = false;
89
- container.register(bindingName, () => {
90
- if (!computed) {
91
- cached = factory();
92
- computed = true;
93
- }
94
- return cached;
95
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
- });
97
- return bindingName;
98
- },
99
- resolve(bindingName) {
100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
- return container.resolve(bindingName);
102
- },
103
- on(event, handler, priority) {
104
- runtime.onFramework(event, handler, priority);
105
- },
106
- before(actionName, handler) {
107
- // Register a chain step on the per-action `action.before:<name>`
108
- // hook. Each plugin's contribution gets its own named step so taps
109
- // emit a distinct `hook.step` record — the chain is now a first-
110
- // class observable surface (listHooks() / Studio / OTel see it).
111
- // Returning false from the handler sets the veto flag the runtime
112
- // checks immediately after the hook resolves.
113
- const stepName = `plugin#${pluginName ?? "?"}.before`;
114
- runtime.ensureActionBeforeHook(actionName).use(async (hctx, next) => {
115
- const decision = await handler({
116
- action: hctx.action,
117
- input: hctx.input,
118
- ctx: hctx.ctx,
119
- });
120
- if (decision === false) {
121
- hctx.vetoed = true;
122
- return; // skip `next()` — downstream steps shouldn't run on veto
123
- }
124
- await next();
125
- }, { name: stepName });
126
- },
127
- after(actionName, handler) {
128
- const stepName = `plugin#${pluginName ?? "?"}.after`;
129
- runtime.ensureActionAfterHook(actionName).use(async (hctx, next) => {
130
- await handler({
131
- action: hctx.action,
132
- input: hctx.input,
133
- result: hctx.result,
134
- durationMs: hctx.durationMs,
135
- });
136
- await next();
137
- }, { name: stepName });
138
- },
139
- middleware(mw) {
140
- runtime.use(mw);
141
- },
142
- actorHook(hook) {
143
- runtime.registerActorTransitionHook(hook);
144
- },
145
- boot(fn) {
146
- boots.push(fn);
147
- },
148
- shutdown(fn) {
149
- shutdowns.push(fn);
150
- },
151
- };
152
- return { api, boots, shutdowns };
153
- }
154
- /**
155
- * Adapt a narrow `@nwire/app` plugin into the rich forge `PluginDefinition`
156
- * createApp expects. The narrow shape (provide / on / boot / shutdown) is a
157
- * strict subset of the rich shape, so the adaptation is straight forwarding:
158
- *
159
- * - `provide(name, lifecycle)` becomes a `bind` whose factory invokes the
160
- * lifecycle's `boot()` once, plus a shutdown step that runs
161
- * `lifecycle.shutdown(value)` against the resolved value if it was ever
162
- * materialized. Lazy resolution matches the rich `bind` contract — a
163
- * value nobody asks for is never booted (and therefore never torn down).
164
- * - `on(FrameworkEvent, handler, prio?)` maps 1:1 onto `runtime.onFramework`,
165
- * which is what the rich `api.on` already does internally.
166
- * - `boot(fn)` / `shutdown(fn)` map 1:1.
167
- *
168
- * The narrow plugin's `setup` may be async; we honor that by returning a
169
- * Promise from the rich setup. createApp's sync register loop rejects async
170
- * rich setups today, so app-plugin authors who need async work should put it
171
- * inside `api.boot(...)` — same rule as forge's closure form.
172
- */
173
- export function adaptAppPlugin(app) {
174
- return {
175
- $kind: "plugin",
176
- name: app.name,
177
- $source: app.$source,
178
- setup(ctx) {
179
- // bus is exposed on the narrow context for advanced cases (the rich
180
- // `on` only covers framework events). runtime.frameworkEvents is the
181
- // same bus the rich api.on writes to, so passing it through is safe.
182
- const narrow = {
183
- container: ctx.container,
184
- bus: ctx.runtime.frameworkEvents,
185
- provide(name, lifecycle) {
186
- let booted = false;
187
- let value;
188
- ctx.bind(name, () => {
189
- // The narrow contract permits async boot; bind's factory is
190
- // sync. We synchronously kick the promise (if any) — consumers
191
- // resolving an async-provided binding get the Promise back,
192
- // mirroring what they'd get if they implemented `bind` directly.
193
- const result = lifecycle.boot();
194
- booted = true;
195
- value = result;
196
- return result;
197
- });
198
- if (lifecycle.shutdown) {
199
- ctx.shutdown(async () => {
200
- if (!booted)
201
- return;
202
- await lifecycle.shutdown(value);
203
- });
204
- }
205
- },
206
- on(event, handler, priority) {
207
- ctx.on(event, handler, priority);
208
- },
209
- boot(fn) {
210
- ctx.boot(fn);
211
- },
212
- shutdown(fn) {
213
- ctx.shutdown(fn);
214
- },
215
- };
216
- return app.setup(narrow);
217
- },
218
- };
219
- }
220
- //# sourceMappingURL=define-plugin.js.map