@afora/core 0.0.8 → 0.0.11

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 (226) hide show
  1. package/README.md +149 -23
  2. package/dist/adapters.d.ts +25 -0
  3. package/dist/adapters.js +32 -0
  4. package/dist/core/application/application.d.ts +30 -0
  5. package/dist/core/application/application.js +1291 -0
  6. package/dist/core/application/exceptions.d.ts +17 -0
  7. package/dist/core/application/exceptions.js +85 -0
  8. package/dist/core/application/migrate.d.ts +19 -0
  9. package/dist/core/application/migrate.js +67 -0
  10. package/dist/core/application/providers.js +108 -0
  11. package/dist/core/application/registry.js +23 -0
  12. package/dist/core/application/schema.d.ts +30 -0
  13. package/dist/core/application/schema.js +398 -0
  14. package/dist/core/application/start.js +162 -0
  15. package/dist/core/application/types/application.interface.d.ts +60 -3
  16. package/dist/core/auth/jwt.d.ts +30 -0
  17. package/dist/core/auth/jwt.js +200 -0
  18. package/dist/core/auth/types/jwt.interface.d.ts +74 -0
  19. package/dist/core/blueprint/blueprint-plugin.js +7 -0
  20. package/dist/core/blueprint/blueprint.js +146 -0
  21. package/dist/core/blueprint/callable.js +13 -0
  22. package/dist/core/blueprint/exceptions.d.ts +5 -0
  23. package/dist/core/blueprint/exceptions.js +20 -0
  24. package/dist/core/blueprint/is-blueprint.js +4 -0
  25. package/dist/core/blueprint/list.js +19 -0
  26. package/dist/core/blueprint/optional.d.ts +3 -1
  27. package/dist/core/blueprint/optional.js +69 -0
  28. package/dist/core/blueprint/record-field.js +14 -0
  29. package/dist/core/blueprint/slice.js +127 -0
  30. package/dist/core/blueprint/types/blueprint.interface.d.ts +95 -5
  31. package/dist/core/blueprint/variant.d.ts +32 -0
  32. package/dist/core/blueprint/variant.js +72 -0
  33. package/dist/core/command/command.js +428 -0
  34. package/dist/core/command/exceptions.js +30 -0
  35. package/dist/core/command/types/command.interface.d.ts +10 -1
  36. package/dist/core/entity/abstract-entity.d.ts +24 -0
  37. package/dist/core/entity/abstract-entity.js +181 -0
  38. package/dist/core/entity/entity.d.ts +1 -1
  39. package/dist/core/entity/entity.js +209 -0
  40. package/dist/core/entity/event.d.ts +39 -0
  41. package/dist/core/entity/event.js +80 -0
  42. package/dist/core/entity/exceptions.d.ts +9 -0
  43. package/dist/core/entity/exceptions.js +27 -0
  44. package/dist/core/entity/trust.d.ts +24 -0
  45. package/dist/core/entity/trust.js +7 -0
  46. package/dist/core/entity/types/entity.interface.d.ts +30 -0
  47. package/dist/core/entity/version.js +13 -0
  48. package/dist/core/environment/environment.d.ts +26 -3
  49. package/dist/core/environment/environment.js +71 -0
  50. package/dist/core/event-policy/event-policy.js +76 -0
  51. package/dist/core/event-policy/exceptions.js +12 -0
  52. package/dist/core/event-policy/publish.js +98 -0
  53. package/dist/core/event-policy/publishers.js +18 -0
  54. package/dist/core/event-policy/types/event-policy.interface.d.ts +8 -2
  55. package/dist/core/exception/enums/exception-layers.js +15 -0
  56. package/dist/core/exception/exception.d.ts +15 -0
  57. package/dist/core/exception/exception.js +128 -0
  58. package/dist/core/exception/exported.js +49 -0
  59. package/dist/core/exception/guard.d.ts +20 -1
  60. package/dist/core/exception/guard.js +16 -0
  61. package/dist/core/exception/types/exception.interface.d.ts +13 -0
  62. package/dist/core/json.js +19 -0
  63. package/dist/core/logger/exceptions.js +7 -0
  64. package/dist/core/logger/logger.d.ts +14 -1
  65. package/dist/core/logger/logger.js +178 -0
  66. package/dist/core/openapi/exceptions.js +7 -0
  67. package/dist/core/openapi/openapi.js +132 -0
  68. package/dist/core/openapi/types/openapi.interface.d.ts +7 -1
  69. package/dist/core/output/access.d.ts +16 -0
  70. package/dist/core/output/access.js +66 -0
  71. package/dist/core/output/coerce.js +38 -0
  72. package/dist/core/output/exceptions.d.ts +16 -0
  73. package/dist/core/output/exceptions.js +22 -0
  74. package/dist/core/output/http.d.ts +36 -0
  75. package/dist/core/output/http.js +351 -0
  76. package/dist/core/output/openapi-sink.d.ts +33 -4
  77. package/dist/core/output/openapi-sink.js +571 -0
  78. package/dist/core/output/output.js +192 -0
  79. package/dist/core/output/problem.js +30 -0
  80. package/dist/core/output/select.js +28 -0
  81. package/dist/core/output/stage.d.ts +7 -2
  82. package/dist/core/output/stage.js +111 -0
  83. package/dist/core/output/status.d.ts +1 -1
  84. package/dist/core/output/status.js +52 -0
  85. package/dist/core/output/types/http.interface.d.ts +134 -0
  86. package/dist/core/output/types/output.interface.d.ts +49 -5
  87. package/dist/core/parse/issue.d.ts +28 -3
  88. package/dist/core/parse/issue.js +31 -0
  89. package/dist/core/parse/parse.d.ts +16 -0
  90. package/dist/core/parse/parse.js +323 -0
  91. package/dist/core/parse/strip.js +48 -0
  92. package/dist/core/property/abstract-property.d.ts +9 -0
  93. package/dist/core/property/abstract-property.js +37 -0
  94. package/dist/core/property/define-property.d.ts +34 -6
  95. package/dist/core/property/define-property.js +209 -0
  96. package/dist/core/property/enums/property-states.js +8 -0
  97. package/dist/core/property/exceptions.js +12 -0
  98. package/dist/core/property/input.js +10 -0
  99. package/dist/core/property/is-property.js +3 -0
  100. package/dist/core/property/lineage.js +8 -0
  101. package/dist/core/property/property.d.ts +27 -0
  102. package/dist/core/property/property.js +46 -0
  103. package/dist/core/property/refine.js +103 -0
  104. package/dist/core/property/types/property-options.interface.d.ts +10 -0
  105. package/dist/core/property/types/property-type.interface.d.ts +4 -0
  106. package/dist/core/record/abstract-record.d.ts +8 -0
  107. package/dist/core/record/abstract-record.js +307 -0
  108. package/dist/core/record/exceptions.js +49 -0
  109. package/dist/core/record/marks.js +7 -0
  110. package/dist/core/record/mask.js +60 -0
  111. package/dist/core/record/name.js +23 -0
  112. package/dist/core/record/plugin-catalog.js +115 -0
  113. package/dist/core/record/plugin.js +198 -0
  114. package/dist/core/record/record.js +117 -0
  115. package/dist/core/record/types/record.interface.d.ts +17 -1
  116. package/dist/core/repository/cursor.js +83 -0
  117. package/dist/core/repository/exceptions.d.ts +13 -0
  118. package/dist/core/repository/exceptions.js +72 -0
  119. package/dist/core/repository/in-memory.d.ts +2 -2
  120. package/dist/core/repository/in-memory.js +196 -0
  121. package/dist/core/repository/migrate.d.ts +20 -0
  122. package/dist/core/repository/migrate.js +254 -0
  123. package/dist/core/repository/plan.js +27 -0
  124. package/dist/core/repository/provider.js +29 -0
  125. package/dist/core/repository/query.js +153 -0
  126. package/dist/core/repository/references.js +196 -0
  127. package/dist/core/repository/repository.d.ts +22 -2
  128. package/dist/core/repository/repository.js +720 -0
  129. package/dist/core/repository/state.d.ts +2 -0
  130. package/dist/core/repository/state.js +138 -0
  131. package/dist/core/repository/types/query.interface.d.ts +13 -0
  132. package/dist/core/repository/types/repository.interface.d.ts +50 -5
  133. package/dist/core/repository/types/schema.interface.d.ts +132 -0
  134. package/dist/core/repository/upcast.d.ts +64 -0
  135. package/dist/core/repository/upcast.js +179 -0
  136. package/dist/core/schema/schema.d.ts +37 -0
  137. package/dist/core/schema/schema.js +542 -0
  138. package/dist/core/standard/standard-schema.js +1 -0
  139. package/dist/core/standard/standard.js +23 -0
  140. package/dist/core/symbols/demo.d.ts +4 -0
  141. package/dist/core/symbols/demo.js +1 -0
  142. package/dist/core/symbols/kind.d.ts +1 -1
  143. package/dist/core/symbols/kind.js +1 -0
  144. package/dist/core/symbols/meta.js +1 -0
  145. package/dist/core/symbols/state.d.ts +5 -0
  146. package/dist/core/symbols/state.js +1 -0
  147. package/dist/core/tracing/exceptions.d.ts +4 -0
  148. package/dist/core/tracing/exceptions.js +7 -0
  149. package/dist/core/tracing/tracing.d.ts +72 -0
  150. package/dist/core/tracing/tracing.js +101 -0
  151. package/dist/core/use-case/access.d.ts +12 -0
  152. package/dist/core/use-case/access.js +56 -0
  153. package/dist/core/use-case/decorators.d.ts +40 -0
  154. package/dist/core/use-case/decorators.js +65 -0
  155. package/dist/core/use-case/exceptions.d.ts +5 -1
  156. package/dist/core/use-case/exceptions.js +48 -0
  157. package/dist/core/use-case/plugin-catalog.js +68 -0
  158. package/dist/core/use-case/plugin.js +133 -0
  159. package/dist/core/use-case/route.d.ts +18 -0
  160. package/dist/core/use-case/route.js +200 -0
  161. package/dist/core/use-case/scope.d.ts +5 -0
  162. package/dist/core/use-case/scope.js +4 -0
  163. package/dist/core/use-case/steps/describe.d.ts +5 -1
  164. package/dist/core/use-case/steps/describe.js +24 -0
  165. package/dist/core/use-case/steps/references.js +105 -0
  166. package/dist/core/use-case/steps/run.js +139 -0
  167. package/dist/core/use-case/steps/types/check.interface.d.ts +233 -0
  168. package/dist/core/use-case/steps/types/steps.interface.d.ts +8 -1
  169. package/dist/core/use-case/steps/validate.js +368 -0
  170. package/dist/core/use-case/target.js +100 -0
  171. package/dist/core/use-case/types/access.interface.d.ts +39 -0
  172. package/dist/core/use-case/types/route.interface.d.ts +86 -0
  173. package/dist/core/use-case/use-case.d.ts +127 -2
  174. package/dist/core/use-case/use-case.js +493 -0
  175. package/dist/experimental.d.ts +18 -1
  176. package/dist/experimental.js +18 -123
  177. package/dist/index.d.ts +49 -51
  178. package/dist/index.js +213 -443
  179. package/dist/std/blueprint-plugin.js +42 -0
  180. package/dist/std/blueprint.d.ts +21 -0
  181. package/dist/std/blueprint.js +3 -0
  182. package/dist/std/command.js +3 -0
  183. package/dist/std/entity.d.ts +20 -1
  184. package/dist/std/entity.js +30 -0
  185. package/dist/std/event-policies.js +3 -0
  186. package/dist/std/properties/contact.d.ts +3 -0
  187. package/dist/std/properties/contact.js +29 -0
  188. package/dist/std/properties/enum.js +26 -0
  189. package/dist/std/properties/exceptions.js +14 -0
  190. package/dist/std/properties/headless.js +45 -0
  191. package/dist/std/properties/identity.js +28 -0
  192. package/dist/std/properties/json.js +161 -0
  193. package/dist/std/properties/password.d.ts +0 -2
  194. package/dist/std/properties/password.js +79 -0
  195. package/dist/std/properties/primitives.d.ts +4 -0
  196. package/dist/std/properties/primitives.js +28 -0
  197. package/dist/std/properties/time.js +55 -0
  198. package/dist/std/record-plugins.d.ts +2 -2
  199. package/dist/std/record-plugins.js +73 -0
  200. package/dist/std/record.d.ts +20 -1
  201. package/dist/std/record.js +3 -0
  202. package/dist/std/resource.d.ts +31 -0
  203. package/dist/std/resource.js +39 -0
  204. package/dist/std/runtime.d.ts +6 -0
  205. package/dist/std/runtime.js +193 -0
  206. package/dist/std/stages.js +4 -0
  207. package/dist/std/use-cases/auth.d.ts +5 -1
  208. package/dist/std/use-cases/auth.js +193 -0
  209. package/dist/std/use-cases/crud.js +261 -0
  210. package/dist/std/use-cases/index.d.ts +1 -1
  211. package/dist/std/use-cases/index.js +12 -0
  212. package/dist/std/use-cases/lifecycle.js +97 -0
  213. package/dist/std/use-cases/shared.d.ts +2 -2
  214. package/dist/std/use-cases/shared.js +232 -0
  215. package/dist/std/use-cases/types.d.ts +102 -2
  216. package/dist/std/use-cases/types.js +0 -0
  217. package/dist/testing/http-provider-contract.d.ts +32 -0
  218. package/dist/testing/http-provider-contract.js +344 -0
  219. package/dist/testing/index.d.ts +2 -0
  220. package/dist/testing/index.js +3 -944
  221. package/dist/testing/memory-publisher.js +12 -0
  222. package/dist/testing/provider-contract.d.ts +26 -1
  223. package/dist/testing/provider-contract.js +1071 -0
  224. package/package.json +23 -3
  225. package/dist/index-qxfkyd6k.js +0 -1721
  226. package/dist/index-t5qwtyj5.js +0 -8194
package/README.md CHANGED
@@ -1,6 +1,9 @@
1
- <h1 align="center">afora</h1>
2
-
3
- <p align="center"><strong>Model the domain. Keep the invariants.</strong><br>Domain modeling for TypeScript, built on TypeBox.</p>
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset=".github/assets/afora-banner-dark.png">
4
+ <img alt="afora — Model the domain. Keep the invariants." src=".github/assets/afora-banner-light.png" width="100%">
5
+ </picture>
6
+ </p>
4
7
 
5
8
  <p align="center">
6
9
  <a href="https://www.npmjs.com/package/@afora/core"><img alt="npm" src="https://img.shields.io/npm/v/@afora/core?color=cb3837&logo=npm"></a>
@@ -20,9 +23,34 @@
20
23
  <a href="https://github.com/afora-framework/core/discussions">Discussions</a>
21
24
  </p>
22
25
 
23
- Domain modeling on [TypeBox](https://github.com/sinclairzx81/typebox): entities with invariants, sensitive data masking and exceptions that know their layer, usable by any [Standard Schema](https://standardschema.dev) consumer.
26
+ **A backend an agent can write without breaking its guarantees.** With afora the whole application is data: an `afora.json` declares the entities, repositories, use cases, commands and HTTP API, [`@afora/codegen`](packages/codegen/README.md) turns it into TypeScript you review and commit, [`@afora/mcp`](packages/mcp/README.md) lets an agent write it, and `extractSpec(app)` gives the spec back from code written by hand. Whoever writes the spec or the code, the runtime keeps the invariants: sensitive fields are masked, undeclared keys are rejected, unique keys are enforced and business errors become problem+json with the right status.
27
+
28
+ ### 30 seconds: from afora.json to a running API
29
+
30
+ ```bash
31
+ bun add @afora/core @afora/hono hono typebox && bun add -d @afora/codegen
32
+ bunx afora-codegen generate afora.json --stages ./stages.ts # writes src/domain/*.ts
33
+ bun src/server.ts
34
+ ```
35
+
36
+ With the [quick start's `afora.json`](#the-same-app-as-an-aforajson) and three small files written by hand (the hashing function, the `hono` stage catalog and the server, shown there), that is the whole API: a `User` with a masked password and a unique email, a use case written as steps, problem+json errors and an OpenAPI document. The same app written by hand in TypeScript is the [quick start](#quick-start), and the [afora.json guide](docs/afora-json.md) covers the whole spec.
37
+
38
+ ## Why afora
39
+
40
+ An HTTP backend written by an agent (or in a hurry) tends to break the same few guarantees. In afora each one is a mechanism of the runtime, not a convention the code has to remember:
41
+
42
+ | What usually breaks | What afora does |
43
+ | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
44
+ | A password hash or token ends up in a response | A property declared `sensitive` (`Password`) is masked by `toJSON()` at any depth, so no serializer can leak it ([records](docs/records.md)). |
45
+ | Extra fields in a request body are accepted | Records reject undeclared keys at any depth (issue code `undeclared_key`), and the HTTP sink answers 400 ([Standard Schema](docs/standard-schema.md)). |
46
+ | A business error is returned as a 500 | Exceptions know their layer; an output maps them to problem+json with a status (404, 409, 401, 422 for the errors a use case declares) and hides the detail of a real 500 ([outputs](docs/outputs.md)). |
47
+ | A duplicate email is written twice | `unique` keys are enforced by the repository and its provider, and a violation is a 409 ([repositories](docs/repositories.md)). |
48
+
49
+ [`examples/agent-built`](examples/agent-built/README.md) checks these four invariants on the running API of a ticketing backend built only through the MCP server, and of a Hono + Zod baseline written from the same brief. In the committed run both hold all four, but the afora one wrote no code for any of them: the spec declares the fields and errors, and the runtime does the rest. Scripted runs that measure how often each approach holds them across independent agent runs are in the example, waiting to be run with an API key.
24
50
 
25
- afora is not a general-purpose validator. It is for code that models a domain, and it plugs into the validators your framework already accepts.
51
+ afora is not a general-purpose validator. It models a domain on [TypeBox](https://github.com/sinclairzx81/typebox), and every field plugs into the validators your framework already accepts through [Standard Schema](https://standardschema.dev).
52
+
53
+ ## Features
26
54
 
27
55
  - **Records with invariants.** Properties (`Email`, `Slug`, `Password`, your own) validate and normalize every value; blueprints compose them; a record (`class User extends recordOf(...)`) holds the handled value and rejects undeclared keys at any depth.
28
56
  - **Sensitive data masking.** A property declared `sensitive` (`Password`) is masked by `toJSON()` at any depth, so `JSON.stringify(user)` cannot leak it.
@@ -31,9 +59,11 @@ afora is not a general-purpose validator. It is for code that models a domain, a
31
59
  - **Exceptions that know their layer.** Each error carries a layer (`Property`, `Record`, `UseCase`, `Output`...) and a `trace` that grows as it goes up.
32
60
  - **Standard Schema V1 on every field.** Properties, blueprints, lists and record classes work as is in Hono, tRPC and TanStack Form, and `safeParse` never throws for an invalid value.
33
61
  - **Commands and outputs.** `commandOf` groups use cases behind one execution boundary (context, transactions, event policies); `outputOf` turns commands into operations and pipes them to a sink: an HTTP API with `@afora/hono`, WebSocket messages with `@afora/ws`, an OpenAPI 3.1 document, or MCP tools, with problem+json errors and masked responses.
62
+ - **Routes and access on the use case.** A use case says where it is served (`route`, or `@Route("GET", "/posts/{slug}")`) and who may call it (`access`, or `@Access({ scopes: [...] })`), next to its input; the blueprint stays the only description of the input, and every server and transport enforces the access before the use case runs. `resourceOf(Posts, { path: "/posts" })` is a whole CRUD. See the [tutorial](docs/tutorial.md).
63
+ - **Any server.** The same output runs on [Hono](packages/hono/README.md), [Fastify](packages/fastify/README.md), [Express](packages/express/README.md) or [Elysia](packages/elysia/README.md), with that server's own middlewares: they share one compiled route table and one contract test suite ([HTTP providers](docs/providers.md)).
34
64
  - **Standard use cases.** `commandOf({ useCases: (ctx) => ({ create: ctx.create(Posts), publish: ctx.publish(Posts) }) })` picks ready-made use cases that follow the repository and its entity: the actions it declares, its record plugins and the properties of its keys ([docs](docs/std-use-cases.md)).
35
65
  - **The whole application in JSON.** An `afora.json` generates the code (`@afora/codegen`), use cases included, as data (steps), and `extractSpec(app)` gives back the `afora.json` of an application written by hand.
36
- - **Repositories on any store.** A provider contract with typed queries, soft deletion and transactions, a runner-agnostic kit to test one (`@afora/core/testing`), in memory by default and on Drizzle ORM with `@afora/drizzle`.
66
+ - **Repositories on any store.** A provider contract with typed queries, soft deletion and transactions, a runner-agnostic kit to test one (`@afora/core/testing`), in memory by default, on Drizzle ORM with `@afora/drizzle` and on DynamoDB with `@afora/dynamodb`.
37
67
 
38
68
  ## Install
39
69
 
@@ -45,6 +75,7 @@ Requirements: [Bun](https://bun.sh) >= 1.4.4 or Node.js >= 22. TypeBox (`typebox
45
75
 
46
76
  `Password` hashes with argon2id: with `Bun.password` on Bun, with native `node:crypto` argon2 on a Node that has it (24.7+), and otherwise it throws `PasswordHasherRequired` until you call `configure({ hasher })`. `Id.generate()` makes a portable, monotonic UUID v7 on any runtime. afora imports no `node:crypto` (or `Buffer`) at load, so it loads in browsers and Workers; the native hasher is looked up on first use through `process.getBuiltinModule` (Node 22.3+). The native hasher derives argon2 version 19 only; a hash of another version throws `UnsupportedPasswordHash` (verify it with `Bun.password`, or `configure({ hasher })`).
47
77
 
78
+ <!-- docs:code skip: myArgon2 and myUuidV7 stand for your own libraries -->
48
79
  ```ts
49
80
  import { configure, type PasswordHasher } from "@afora/core";
50
81
 
@@ -58,7 +89,7 @@ configure({ hasher, idGenerator: () => myUuidV7() }); // both optional; `resetRu
58
89
 
59
90
  ## Quick start
60
91
 
61
- A `User` entity with a sensitive key and a unique key, a repository, a use case written as steps, a command that wraps it in a transaction, and an output that serves the command as an HTTP API with an OpenAPI document. Install what it uses:
92
+ A `User` entity with a sensitive key and a unique key, a repository, a use case written as steps that says where it is served, a command that wraps it in a transaction, and an output that serves the command as an HTTP API with an OpenAPI document. Install what it uses:
62
93
 
63
94
  ```bash
64
95
  bun add @afora/core @afora/hono hono typebox
@@ -106,9 +137,10 @@ async function hashPassword(plain: string) {
106
137
  return (await Password.hash(plain)).value;
107
138
  }
108
139
 
109
- // Use case: the steps are data, so they can also live in an afora.json
140
+ // Use case: the steps and the route are data, so they can also live in an afora.json
110
141
  class Register extends useCaseOf({
111
142
  name: "Register",
143
+ route: { method: "post", path: "/users", status: 201 }, // where it is served
112
144
  blueprint: blueprintOf((ctx) => ({
113
145
  name: ctx.text,
114
146
  email: ctx.email,
@@ -117,6 +149,7 @@ class Register extends useCaseOf({
117
149
  response: blueprintOf(() => ({ user: User })),
118
150
  dependencies: { users: Users },
119
151
  errors: [UserAlreadyExists],
152
+ strictSteps: true, // TypeScript checks every reference, arg and the return
120
153
  steps: [
121
154
  { find: "users.findByEmail", args: ["$input.email"], as: "existing" },
122
155
  { ensure: "absent", value: "$existing", error: UserAlreadyExists },
@@ -167,8 +200,8 @@ if (import.meta.main) Bun.serve({ fetch: api.fetch });
167
200
  What it does:
168
201
 
169
202
  ```
170
- POST /api/accounts/register { "name": "Ana", "email": " Ana@Example.COM ", "plainPassword": "Str0ng!Pass" }
171
- -> 200 { "user": { "id": "...", "name": "Ana", "email": "ana@example.com", "password": "********", ... } }
203
+ POST /api/users { "name": "Ana", "email": " Ana@Example.COM ", "plainPassword": "Str0ng!Pass" }
204
+ -> 201 { "user": { "id": "...", "name": "Ana", "email": "ana@example.com", "password": "********", ... } }
172
205
 
173
206
  the same email again
174
207
  -> 409 application/problem+json { "title": "UserAlreadyExists", "layer": "use-case", ... }
@@ -206,6 +239,7 @@ Everything above, except the hashing function, is data, so it can be written as
206
239
  },
207
240
  "useCases": {
208
241
  "Register": {
242
+ "route": { "method": "post", "path": "/users", "status": 201 },
209
243
  "input": {
210
244
  "fields": {
211
245
  "name": "text",
@@ -283,19 +317,31 @@ export async function hashPassword(plain: string) {
283
317
  }
284
318
  ```
285
319
 
286
- Then generate, telling codegen where the `hono` stage comes from, and serve the application:
320
+ Then generate, telling codegen where the `hono` stage comes from in `stages.ts`:
321
+
322
+ ```ts
323
+ export { stages } from "@afora/hono";
324
+ ```
287
325
 
288
326
  ```bash
289
327
  bun add -d @afora/codegen
290
- bunx afora-codegen generate afora.json --stages @afora/hono # writes src/domain/*.ts
328
+ bunx afora-codegen generate afora.json --stages ./stages.ts # writes src/domain/*.ts
291
329
  ```
292
330
 
331
+ and serve the application from `src/server.ts` (`bun src/server.ts`):
332
+
333
+ <!-- docs:code skip: src/server.ts of examples/interop/from-json; ./domain is what afora-codegen generates from the afora.json above -->
293
334
  ```ts
294
- import { App } from "./src/domain";
335
+ import { App } from "./domain/index.ts";
336
+
337
+ await App.start();
338
+ export const api = App.outputs.Api.build();
295
339
 
296
- Bun.serve({ fetch: App.outputs.Api.build().fetch });
340
+ if (import.meta.main) Bun.serve({ fetch: api.fetch });
297
341
  ```
298
342
 
343
+ These three files are `examples/interop/from-json`, which `bun run test:interop` generates and serves.
344
+
299
345
  `generate` writes one file per kind (`entities.ts`, `repositories.ts`, `use-cases.ts`, `commands.ts`, `outputs.ts`...), an `application.ts` and an `index.ts`, each starting with a banner saying not to edit it. `afora-codegen extract` goes the other way and gives the `afora.json` of an `Application`. The guide is in [docs/afora-json.md](docs/afora-json.md).
300
346
 
301
347
  ## What you get
@@ -307,6 +353,7 @@ Each concept has a page in [docs/](docs/README.md), in the order they build on o
307
353
  - [Records](docs/records.md): a class that holds the handled value, masks sensitive keys and generates `change.<key>`; plugins; experimental slicing.
308
354
  - [Entities](docs/entities.md): a record with identity, timestamps, `destroy()` and domain events.
309
355
  - [Repositories](docs/repositories.md): typed async methods for an entity, queries, soft deletion, providers, transactions and relations.
356
+ - [Schema evolution](docs/schema-evolution.md): `fill`, `renamedFrom`, `schemaVersion` with `upgrade` steps and `previousNames`, so old rows are still read; `app.migrate` to rewrite them, and a schema lock checked in CI and on `start`.
310
357
  - [Use cases](docs/use-cases.md): the Command pattern with method injection, written as code or as steps.
311
358
  - [Commands](docs/commands.md): use cases under operation names, with a context, a transaction and an event policy.
312
359
  - [Outputs](docs/outputs.md): commands through stages into a sink, such as an HTTP API or an OpenAPI document.
@@ -327,22 +374,97 @@ Every field (a property, blueprint, list or record class) implements Standard Sc
327
374
  | [`@afora/codegen`](packages/codegen/README.md) | Generates afora code from an `afora.json`, and extracts the `afora.json` of an `Application` back. |
328
375
  | [`@afora/mcp`](packages/mcp/README.md) | An MCP server that lets an agent build a domain with `@afora/codegen`. |
329
376
  | [`@afora/hono`](packages/hono/README.md) | A `hono` sink for outputs: serves the operations as a Hono app, with problem+json errors, masked responses, signed webhooks and an optional OpenAPI document. |
377
+ | [`@afora/fastify`](packages/fastify/README.md) | A `fastify` sink: the same operations, options and behavior on Fastify. |
378
+ | [`@afora/express`](packages/express/README.md) | An `express` sink: the same on Express 5. |
379
+ | [`@afora/elysia`](packages/elysia/README.md) | An `elysia` sink: the same on Elysia. |
330
380
  | [`@afora/ws`](packages/ws/README.md) | A `websocket` sink: operations over JSON messages on any runtime, with topic subscriptions that `publishEvents` feeds with domain events. |
331
381
  | [`@afora/drizzle`](packages/drizzle/README.md) | A repository provider on Drizzle ORM (SQLite and Postgres) that passes the provider contract kit. |
382
+ | [`@afora/dynamodb`](packages/dynamodb/README.md) | A repository provider on one DynamoDB table (single-table layout, unique keys as marker items) that passes the provider contract kit on DynamoDB Local. |
383
+ | [`@afora/otel`](packages/otel/README.md) | OpenTelemetry tracing: `otelTracer()` gives an application a span per command, use case and repository call, with no value in any span. |
332
384
 
333
385
  ## Example
334
386
 
335
387
  `examples/blog` is a blog (users with the `authenticatable` plugin, posts with soft deletion, every use case a [standard one](docs/std-use-cases.md), a Hono API on Drizzle and SQLite) whose whole `src/domain` is generated from one `afora.json` by `@afora/codegen`. Only the database, the schema, the provider (made from a `Database` environment with `providerFrom` when the server calls `App.start()`, and named `database` in the `providers` of the spec) and the server are hand-written. Its tests check that the committed code is what the spec generates, drive the API end to end and extract the spec back from the application: `bun run test:blog`.
336
388
 
337
- ## Performance
389
+ `examples/agent-built` is an event ticketing API (organizers, events with a capacity, tickets) built only through the `@afora/mcp` tools from a written brief, with the tool calls committed and replayed byte for byte, and an evaluation of four invariants on its running API and on a Hono + Zod baseline: `bun run test:agent-built`. See [its write-up](examples/agent-built/README.md).
338
390
 
339
- `bun run bench` compares afora with TypeBox (compiled), Zod 4, Valibot and ArkType on the same data, on Bun and on Node; the results are in `bench/RESULTS.md`. Absolute numbers depend on the machine, so read the ratios. On the measured machine (Apple M2):
340
-
341
- - **Valid input.** afora is about 1.8x to 2.5x slower than Valibot and about 1.1x to 2.1x slower than Zod 4 (flat and nested objects, Bun and Node). It is faster than ArkType in these cases, where ArkType's morphs move it to a slower path.
342
- - **Invalid input.** This is still where afora is weakest, but much closer than before. Flat objects are about 5x slower than Valibot and 3.7x slower than Zod 4 on Bun, and about 4.4x and 3.6x on Node; nested objects are about 2.9x and 2.1x on Bun, and about 3.1x on Node. It is faster than ArkType here. Most of what remains is TypeBox's own error collection, which runs once for each failing property; the `cause` exception of an issue is built only when it is read.
343
- - **Floor.** Compiled TypeBox, which only checks and does not transform, is about 9x to 27x faster than afora on valid input. afora builds on it.
391
+ ## Performance
344
392
 
345
- What afora does that the fast rows do not all do: a handler pipeline per property (`preHandle`, schema check, `afterHandle`), preceded by a shape check so handlers only see the right types; objects walked key by key instead of one compiled function; frozen results; every issue with `code`, `path` and `source`; and, for `Record.safeParse` and `new Record`, creating the instance. If you validate untrusted bulk data in a hot path and need none of that, use a validator built for it, and use afora at the domain boundary, where the cost per entity is small next to I/O.
393
+ `bun run bench` times afora next to TypeBox (compiled), Ajv, Typia, Zod 4, Valibot, ArkType, Effect Schema, Yup and Joi on seven scenarios (a flat object, a nested one, the body of an API request, a list of 1,000 items, a union, six levels of nesting, and a flat object with nothing to transform), with valid and invalid input, on Bun and on Node. Every library declares the same rules, rejects undeclared keys and collects every error, and is checked before it is timed; each row is timed by a process of its own, after a warm-up, in three rounds. The tables are in [`bench/RESULTS.md`](bench/RESULTS.md) and the method in [`bench/README.md`](bench/README.md). Absolute numbers depend on the machine, so read the ratios.
394
+
395
+ <!-- bench:start -->
396
+
397
+ ![Validations per second on the body of an API request, Node v24.22.2](bench/results/chart.svg)
398
+
399
+ Time of each library as a multiple of afora `blueprint.safeParse` on the same case: above 1.00x it is slower than afora, below it is faster. TypeBox, Ajv and Typia only check, they do not transform. afora 0.0.9, Bun 1.4.4, Node v22.23.4 and Node v24.22.2, AMD EPYC 7763 64-Core Processor; generated from `bench/results/latest.json`.
400
+
401
+ | Node 24 | afora | TypeBox | Ajv | Typia | Zod | Valibot | ArkType | Effect Schema | Yup | Joi |
402
+ | -------------------------------------------------------- | -------: | ------: | ----: | ----: | ----: | ------: | ------: | ------------: | -----: | -----: |
403
+ | Small flat object, valid | 579.5 ns | 0.14x | 0.15x | 0.16x | 1.31x | 2.04x | 10.08x | 2.51x | 10.37x | 7.56x |
404
+ | Small flat object, invalid | 1017 ns | 7.65x | 0.12x | 0.63x | 2.53x | 2.22x | 23.82x | 3.43x | 61.39x | 6.48x |
405
+ | Nested user (address, 5 tags max, 10 addresses), valid | 4379 ns | 0.11x | 0.17x | 0.12x | 1.15x | 1.11x | 12.53x | 3.06x | 18.70x | 5.62x |
406
+ | Nested user (address, 5 tags max, 10 addresses), invalid | 5556 ns | 8.41x | 0.18x | 0.76x | 1.53x | 1.17x | 21.08x | 3.17x | 37.22x | 6.04x |
407
+ | API request body (an order with 5 items), valid | 5174 ns | 0.30x | 0.32x | 0.21x | 1.09x | 1.10x | 8.72x | 2.11x | 16.09x | 5.05x |
408
+ | API request body (an order with 5 items), invalid | 6434 ns | 4.79x | 0.16x | 0.85x | 1.75x | 1.12x | 15.93x | 2.53x | 33.94x | 5.43x |
409
+ | List of 1,000 items, valid | 339.2 µs | 0.05x | 0.08x | 0.05x | 0.62x | 2.45x | 17.10x | 3.03x | 21.78x | 6.44x |
410
+ | List of 1,000 items, invalid | 358.9 µs | 15.45x | 0.09x | 0.14x | 0.62x | 2.41x | 21.12x | 2.94x | 22.68x | 6.37x |
411
+ | Union of 4 variants (12 events), valid | 1068 ns | 0.51x | 0.66x | 0.52x | 4.52x | 16.14x | 1.87x | 13.23x | 94.83x | 93.28x |
412
+ | Union of 4 variants (12 events), invalid | 5145 ns | 11.93x | 0.17x | 0.65x | 1.49x | 3.92x | 6.74x | 3.25x | 32.25x | 36.19x |
413
+ | 6 levels of nesting, valid | 1609 ns | 0.06x | 0.09x | 0.07x | 0.80x | 1.27x | 13.88x | 3.68x | 17.45x | 5.29x |
414
+ | 6 levels of nesting, invalid | 2018 ns | 18.04x | 0.11x | 1.47x | 1.73x | 1.67x | 24.36x | 4.52x | 50.40x | 7.09x |
415
+ | Small flat object, checks only, valid | 430.2 ns | 0.20x | 0.20x | 0.21x | 0.79x | 2.16x | 0.40x | 2.05x | 12.75x | 9.22x |
416
+ | Small flat object, checks only, invalid | 934.7 ns | 8.47x | 0.13x | 0.68x | 2.32x | 2.59x | 19.81x | 3.18x | 65.32x | 6.90x |
417
+
418
+ | Bun | afora | TypeBox | Ajv | Typia | Zod | Valibot | ArkType | Effect Schema | Yup | Joi |
419
+ | -------------------------------------------------------- | -------: | ------: | ----: | ----: | ----: | ------: | ------: | ------------: | -----: | -----: |
420
+ | Small flat object, valid | 400.9 ns | 0.15x | 0.17x | 0.16x | 1.63x | 0.86x | 9.95x | 2.29x | 18.78x | 9.88x |
421
+ | Small flat object, invalid | 861.0 ns | 6.52x | 0.18x | 1.00x | 1.38x | 0.87x | 14.29x | 2.23x | 39.21x | 7.40x |
422
+ | Nested user (address, 5 tags max, 10 addresses), valid | 4965 ns | 0.06x | 0.10x | 0.04x | 1.06x | 0.48x | 5.57x | 1.79x | 20.03x | 4.31x |
423
+ | Nested user (address, 5 tags max, 10 addresses), invalid | 4125 ns | 7.60x | 0.17x | 0.89x | 1.58x | 0.92x | 14.61x | 2.76x | 41.12x | 7.68x |
424
+ | API request body (an order with 5 items), valid | 4326 ns | 0.22x | 0.23x | 0.27x | 1.27x | 0.69x | 5.31x | 1.83x | 23.20x | 5.40x |
425
+ | API request body (an order with 5 items), invalid | 4504 ns | 4.89x | 0.16x | 0.93x | 1.93x | 0.95x | 12.21x | 2.29x | 39.23x | 8.54x |
426
+ | List of 1,000 items, valid | 292.5 µs | 0.02x | 0.07x | 0.02x | 1.23x | 0.52x | 8.46x | 1.92x | 31.44x | 5.54x |
427
+ | List of 1,000 items, invalid | 180.8 µs | 19.55x | 0.12x | 0.38x | 2.07x | 0.88x | 21.94x | 3.18x | 52.78x | 9.34x |
428
+ | Union of 4 variants (12 events), valid | 2231 ns | 0.15x | 0.22x | 0.25x | 2.45x | 2.95x | 0.43x | 3.36x | 53.20x | 37.54x |
429
+ | Union of 4 variants (12 events), invalid | 3665 ns | 12.15x | 0.16x | 0.84x | 1.99x | 2.21x | 4.48x | 2.53x | 41.04x | 44.78x |
430
+ | 6 levels of nesting, valid | 903.4 ns | 0.03x | 0.11x | 0.06x | 2.05x | 1.42x | 13.08x | 3.43x | 41.87x | 8.52x |
431
+ | 6 levels of nesting, invalid | 1547 ns | 16.33x | 0.10x | 1.29x | 1.80x | 1.53x | 18.79x | 3.06x | 54.03x | 8.16x |
432
+ | Small flat object, checks only, valid | 224.4 ns | 0.28x | 0.30x | 0.28x | 1.86x | 0.88x | 0.32x | 1.99x | 29.54x | 13.13x |
433
+ | Small flat object, checks only, invalid | 824.2 ns | 6.87x | 0.19x | 1.05x | 1.29x | 0.80x | 10.67x | 1.82x | 37.79x | 6.91x |
434
+
435
+ | Node 22 | afora | TypeBox | Ajv | Typia | Zod | Valibot | ArkType | Effect Schema | Yup | Joi |
436
+ | -------------------------------------------------------- | -------: | ------: | ----: | ----: | ----: | ------: | ------: | ------------: | ------: | ------: |
437
+ | Small flat object, valid | 570.7 ns | 0.15x | 0.14x | 0.16x | 1.29x | 1.05x | 9.74x | 2.50x | 10.93x | 7.53x |
438
+ | Small flat object, invalid | 951.7 ns | 8.05x | 0.13x | 0.61x | 2.63x | 0.99x | 25.38x | 3.59x | 117.28x | 6.52x |
439
+ | Nested user (address, 5 tags max, 10 addresses), valid | 4313 ns | 0.11x | 0.18x | 0.11x | 1.14x | 1.06x | 12.83x | 2.70x | 21.85x | 5.47x |
440
+ | Nested user (address, 5 tags max, 10 addresses), invalid | 5472 ns | 8.29x | 0.18x | 0.75x | 1.63x | 1.16x | 20.80x | 3.07x | 57.50x | 5.97x |
441
+ | API request body (an order with 5 items), valid | 4984 ns | 0.28x | 0.35x | 0.20x | 1.14x | 1.10x | 9.27x | 2.20x | 19.37x | 5.38x |
442
+ | API request body (an order with 5 items), invalid | 6311 ns | 4.83x | 0.19x | 0.81x | 1.88x | 1.13x | 15.79x | 2.54x | 52.78x | 5.44x |
443
+ | List of 1,000 items, valid | 346.1 µs | 0.04x | 0.09x | 0.05x | 0.64x | 1.11x | 16.95x | 2.89x | 28.12x | 6.32x |
444
+ | List of 1,000 items, invalid | 347.0 µs | 15.48x | 0.10x | 0.15x | 0.66x | 1.06x | 21.82x | 2.87x | 30.03x | 6.29x |
445
+ | Union of 4 variants (12 events), valid | 969.6 ns | 0.53x | 0.77x | 0.61x | 4.86x | 9.94x | 2.46x | 13.66x | 125.51x | 105.95x |
446
+ | Union of 4 variants (12 events), invalid | 4865 ns | 12.44x | 0.18x | 0.68x | 1.68x | 2.33x | 7.17x | 3.24x | 44.16x | 37.49x |
447
+ | 6 levels of nesting, valid | 1454 ns | 0.06x | 0.10x | 0.07x | 0.86x | 1.34x | 15.58x | 3.86x | 23.21x | 5.99x |
448
+ | 6 levels of nesting, invalid | 1862 ns | 19.39x | 0.11x | 1.63x | 1.91x | 1.79x | 26.89x | 4.77x | 88.54x | 7.14x |
449
+ | Small flat object, checks only, valid | 399.9 ns | 0.21x | 0.21x | 0.23x | 0.81x | 1.02x | 0.51x | 2.03x | 14.22x | 9.91x |
450
+ | Small flat object, checks only, invalid | 892.3 ns | 8.72x | 0.14x | 0.70x | 2.40x | 0.98x | 21.21x | 3.29x | 119.51x | 6.98x |
451
+
452
+ <!-- bench:end -->
453
+
454
+ What the table says, for `blueprint.safeParse`, on a GitHub runner (AMD EPYC, Linux, Bun 1.4.4 and Node 24). The table is of afora at commit `8c4395e`; what changed after it is said where it applies.
455
+
456
+ - **Against Zod 4.** On Bun, faster in 12 of the 14 cases, by 1.05x to 2.25x; Zod 4 is ahead on the valid nested object (7%). On Node, faster in 9 of the 14, by 1.2x to 3.9x; Zod 4 is ahead on the list of 1,000 items (1.4x to 1.5x), on the valid deep object (1.3x) and on the valid flat object with nothing to transform (1.2x). The invalid union is told apart below.
457
+ - **Against Valibot.** On Node afora is faster in 13 of the 14 cases, by 1.02x to 2.9x outside the valid union (14.5x). On Bun it is the other way: Valibot is ahead in 11 of them, within 15% on small objects and by 1.5x to 2.4x on the valid nested object, the valid API body and the valid list, and afora is ahead on the valid union (2x) and the deep object (1.5x to 1.6x).
458
+ - **Against Effect Schema, Joi and Yup.** Faster in every case but the invalid union: 1.35x to 5.4x Effect Schema, 3.8x to 15x Joi and 12x to 75x Yup, and more than that on the valid union (up to 13x, 94x and 91x).
459
+ - **Against ArkType.** Faster wherever a value is transformed or rejected, by 4.7x to 28x, because its morphs and its errors take a slower path. With nothing to transform and a valid value, ArkType is 2.3x to 3x faster than afora, and 3.8x on the valid union on Bun.
460
+ - **An invalid union.** In the table it takes about 10x the time of Zod 4: TypeBox `Errors` reported every variant of the union for each rejected value. Since then a property whose schema is a discriminated union tells a rejected value by the variant it names, without `Errors`, and takes about 0.5x the time of Zod 4 on Bun (measured on an Apple M2; the table follows at the next measurement). Valid values of the same union are 1.8x to 3.9x faster than Zod 4.
461
+ - **Floor.** The checkers that compile and do not transform (TypeBox, Ajv, Typia) are 3x to 9x faster than afora on a valid small object, and 10x to 70x on the larger ones. afora builds on TypeBox. On invalid input afora is 5x to 24x faster than TypeBox `Errors` (outside the union), and Ajv stays 5x to 11x ahead.
462
+ - **Records and entities.** `Record.safeParse`, which also creates the instance, takes 1.0x to 2.1x the time of `blueprint.safeParse` on Bun and up to 4x on Node. `Entity.safeParse` also makes an id and the time stamps, which on a small object is most of its time: 5x to 13x `blueprint.safeParse` on the flat object in the table, 1.0x to 4.7x on the larger ones; since then it takes about three quarters of that on a small object, for not checking again the id and the date it has just made. `new Record(value)` throws on invalid input, which costs an exception with its trace (2x to 6x `blueprint.safeParse` on Bun, 2.5x to 13x on Node); use `safeParse` where invalid input is expected.
463
+ - **Bundle and cold start.** afora is a framework with one entry point: validating one object bundles to 100 kB gzipped (Zod 4: 24 kB, Valibot: 1.7 kB) and takes 40 ms to load, build and run once in a new Node process (85 ms on Bun; Zod 4: 7 to 8 ms).
464
+
465
+ What afora does that the fast rows do not all do: a pipeline per property (`preHandle`, schema check, `afterHandle`), where a property with a handler has the shape of the value checked first, so handlers only see the right types; objects walked key by key instead of one compiled function; frozen results; every issue with `code`, `path` and `source`; and, for `Record.safeParse` and `new Record`, creating the instance. If you validate bulk data in a hot path and need none of that, a compiled checker alone is an order of magnitude faster.
466
+
467
+ CI keeps it there: `bun run bench:guard` times `blueprint.safeParse` and Zod 4 `safeParse` on the fourteen cases and fails when afora is over the limit of a case as a multiple of Zod 4 (1.15x unless `bench/guard.limits.ts` states another, with the reason).
346
468
 
347
469
  ## Comparison
348
470
 
@@ -378,8 +500,9 @@ bun run test:type-perf # build, then budget the editor cost per edit and snapsho
378
500
  bun run test:api # build, then snapshot the public surface (exports and declarations) and the afora.json schema
379
501
  bun run test:interop # Hono, tRPC and TanStack Form tests (examples/interop), including the quick start
380
502
  bun run test:blog # the generated blog (examples/blog): drift, API and extraction
503
+ bun run test:agent-built # the agent-built example (examples/agent-built): drift, replay, API and the invariant evaluation
381
504
  bun run smoke # build, then run the package on plain Node
382
- bun run bench # benchmark against TypeBox, Zod, Valibot and ArkType
505
+ bun run bench # benchmark against TypeBox, Ajv, Typia, Zod, Valibot, ArkType, Effect Schema, Yup and Joi
383
506
  bun run lint # biome lint
384
507
  bun run knip # unused files, exports and dependencies
385
508
  bun run fmt # biome format + fix
@@ -387,9 +510,12 @@ bun run build # build dist/ (ESM + .d.ts)
387
510
  bun run test:codegen # tests of packages/codegen
388
511
  bun run test:mcp # tests of packages/mcp
389
512
  bun run test:hono # tests of packages/hono
513
+ bun run test:fastify # tests of packages/fastify (also test:express, test:elysia)
390
514
  bun run test:ws # tests of packages/ws
391
515
  bun run test:drizzle # tests of packages/drizzle (SQLite and PGlite)
392
- bun run build:packages # build the core, then packages/codegen, packages/mcp, packages/hono, packages/ws and packages/drizzle
516
+ bun run test:dynamodb # tests of packages/dynamodb (DynamoDB Local, with DYNAMODB_ENDPOINT)
517
+ bun run test:otel # tests of packages/otel
518
+ bun run build:packages # build the core, then packages/codegen, packages/mcp, packages/hono, packages/fastify, packages/express, packages/elysia, packages/ws, packages/drizzle, packages/dynamodb and packages/otel
393
519
  ```
394
520
 
395
521
  ## Versioning
@@ -0,0 +1,25 @@
1
+ /**
2
+ * `@afora/core/adapters`: the plumbing for authors of sinks, providers and
3
+ * code generators (`@afora/hono`, `@afora/drizzle`, `@afora/codegen`...).
4
+ * Part of the compatibility policy in `VERSIONING.md`, like the main entry.
5
+ * Application code needs only `@afora/core`. See `docs/api-tiers.md`.
6
+ */
7
+ export { diffSchemas, schemaLockOf, schemaLockProblemsOf, } from "./core/application/schema.js";
8
+ export type { ApplicationDescription, CommandDescription, ExceptionDescription, FieldDescription, FieldsDescription, LogDescription, OutputDescription, PropertyDescription, PropertyLineageDescription, PropertyReference, ProviderReference, RecordDescription, UseCaseDependencyDescription, UseCaseDescription, } from "./core/application/types/application.interface.js";
9
+ export { ENTITY_IDENTITY_KEYS, RESERVED_ENTITY_KEYS, } from "./core/entity/abstract-entity.js";
10
+ export type { EventPolicyDescription } from "./core/event-policy/types/event-policy.interface.js";
11
+ export { coerceTextValues } from "./core/output/coerce.js";
12
+ export { compileRoutes, HTTP_OPTION_KEYS, httpOptionsIssue, } from "./core/output/http.js";
13
+ export { type OperationRoute, operationRoutes, ROUTE_OPTION_KEYS, requestIdHeaderOf, routeOptionsIssue, } from "./core/output/openapi-sink.js";
14
+ export { outputValueOf, PROBLEM_MEDIA_TYPE, problemOf, } from "./core/output/problem.js";
15
+ export { sinkOf, stageCatalogOf, stageKindOf } from "./core/output/stage.js";
16
+ export { statusOf } from "./core/output/status.js";
17
+ export type { Authenticator, AuthRequest, CompiledRoute, CompileRoutesSettings, HttpOptions, HttpRequest, HttpResult, RouteTable, } from "./core/output/types/http.interface.js";
18
+ export type { OperationDescriptor, Problem, ProblemOptions, SinkFactory, SinkSettings, SinkStage, StageDescription, } from "./core/output/types/output.interface.js";
19
+ export { RESERVED_RECORD_KEYS } from "./core/record/abstract-record.js";
20
+ export { SCHEMA_VERSION_KEY } from "./core/repository/state.js";
21
+ export type { ProviderCapabilities, ProviderDescription, ProviderQuery, } from "./core/repository/types/query.interface.js";
22
+ export type { IRepositoryProvider, ProviderIncrementOptions, ProviderKeyset, ProviderMigrationResult, ProviderUpdateOptions, RepositoryContext, RepositoryData, RepositorySchema, } from "./core/repository/types/repository.interface.js";
23
+ export type { SchemaChange, SchemaChangeClass, SchemaChangeKind, SchemaLock, SchemaLockEntity, SchemaLockField, SchemaPlan, } from "./core/repository/types/schema.interface.js";
24
+ export { Demo } from "./core/symbols/demo.js";
25
+ export { Kind } from "./core/symbols/kind.js";
@@ -0,0 +1,32 @@
1
+ export {
2
+ diffSchemas,
3
+ schemaLockOf,
4
+ schemaLockProblemsOf
5
+ } from "./core/application/schema.js";
6
+ export {
7
+ ENTITY_IDENTITY_KEYS,
8
+ RESERVED_ENTITY_KEYS
9
+ } from "./core/entity/abstract-entity.js";
10
+ export { coerceTextValues } from "./core/output/coerce.js";
11
+ export {
12
+ compileRoutes,
13
+ HTTP_OPTION_KEYS,
14
+ httpOptionsIssue
15
+ } from "./core/output/http.js";
16
+ export {
17
+ operationRoutes,
18
+ ROUTE_OPTION_KEYS,
19
+ requestIdHeaderOf,
20
+ routeOptionsIssue
21
+ } from "./core/output/openapi-sink.js";
22
+ export {
23
+ outputValueOf,
24
+ PROBLEM_MEDIA_TYPE,
25
+ problemOf
26
+ } from "./core/output/problem.js";
27
+ export { sinkOf, stageCatalogOf, stageKindOf } from "./core/output/stage.js";
28
+ export { statusOf } from "./core/output/status.js";
29
+ export { RESERVED_RECORD_KEYS } from "./core/record/abstract-record.js";
30
+ export { SCHEMA_VERSION_KEY } from "./core/repository/state.js";
31
+ export { Demo } from "./core/symbols/demo.js";
32
+ export { Kind } from "./core/symbols/kind.js";
@@ -15,6 +15,36 @@ export declare function isApplication(value: unknown): value is AnyApplication;
15
15
  * under one name (or one object under two names) throw `ApplicationConflict`.
16
16
  * `describe()` gives the graph. With a `provider` (or that of the last
17
17
  * application extended that has one), `repositories` are bound to it.
18
+ *
19
+ * @throws {@link DuplicateApplicationDeclaration} when one object is registered under two names.
20
+ * @throws {@link ApplicationConflict} when extended applications register different objects under one name.
21
+ * @throws {@link InvalidApplicationDeclaration} when a declaration is not of the kind its collection holds.
22
+ * @throws {@link UnregisteredApplicationReference} when a registered declaration holds one that is not registered.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import {
27
+ * applicationOf,
28
+ * blueprintOf,
29
+ * entityOf,
30
+ * inMemoryProvider,
31
+ * repositoryOf,
32
+ * } from "@afora/core";
33
+ *
34
+ * class User extends entityOf(blueprintOf((ctx) => ({ name: ctx.string }))) {}
35
+ * const Users = repositoryOf({ entity: User, actions: ["create"] });
36
+ *
37
+ * const Blog = applicationOf({
38
+ * name: "blog",
39
+ * entities: { User },
40
+ * repositories: { Users },
41
+ * provider: inMemoryProvider(), // the default of its repositories
42
+ * });
43
+ *
44
+ * await Blog.start();
45
+ * await Blog.repositories.Users.create({ name: "Ana" });
46
+ * await Blog.stop();
47
+ * ```
18
48
  */
19
49
  export declare function applicationOf<const Name extends string, const Extended extends readonly AnyApplication[] = readonly [], const Properties extends ApplicationCollections["properties"] = Record<never, never>, const Blueprints extends ApplicationCollections["blueprints"] = Record<never, never>, const Records extends ApplicationCollections["records"] = Record<never, never>, const Entities extends ApplicationCollections["entities"] = Record<never, never>, const Environments extends ApplicationCollections["environments"] = Record<never, never>, const Repositories extends ApplicationCollections["repositories"] = Record<never, never>, const UseCases extends ApplicationCollections["useCases"] = Record<never, never>, const Commands extends ApplicationCollections["commands"] = Record<never, never>, const Outputs extends ApplicationCollections["outputs"] = Record<never, never>, const Exceptions extends ApplicationCollections["exceptions"] = Record<never, never>>(settings: ApplicationSettings<Name, Extended, {
20
50
  properties: Properties;