@nifrajs/core 1.9.1 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/dist/assurance.d.ts +18 -0
  2. package/dist/assurance.d.ts.map +1 -1
  3. package/dist/assurance.js +28 -1
  4. package/dist/assurance.js.map +1 -1
  5. package/dist/budget.d.ts +91 -0
  6. package/dist/budget.d.ts.map +1 -0
  7. package/dist/budget.js +172 -0
  8. package/dist/budget.js.map +1 -0
  9. package/dist/capabilities.d.ts +146 -0
  10. package/dist/capabilities.d.ts.map +1 -0
  11. package/dist/capabilities.js +283 -0
  12. package/dist/capabilities.js.map +1 -0
  13. package/dist/classification.d.ts +39 -0
  14. package/dist/classification.d.ts.map +1 -0
  15. package/dist/classification.js +153 -0
  16. package/dist/classification.js.map +1 -0
  17. package/dist/errors.d.ts +1 -1
  18. package/dist/errors.d.ts.map +1 -1
  19. package/dist/errors.js.map +1 -1
  20. package/dist/idempotency.d.ts +137 -0
  21. package/dist/idempotency.d.ts.map +1 -0
  22. package/dist/idempotency.js +306 -0
  23. package/dist/idempotency.js.map +1 -0
  24. package/dist/index.d.ts +8 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +8 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/internal/capability-runtime.d.ts +16 -0
  29. package/dist/internal/capability-runtime.d.ts.map +1 -0
  30. package/dist/internal/capability-runtime.js +27 -0
  31. package/dist/internal/capability-runtime.js.map +1 -0
  32. package/dist/internal/route-assurance.d.ts +1 -0
  33. package/dist/internal/route-assurance.d.ts.map +1 -1
  34. package/dist/internal/route-assurance.js +1 -0
  35. package/dist/internal/route-assurance.js.map +1 -1
  36. package/dist/invariants.d.ts +66 -0
  37. package/dist/invariants.d.ts.map +1 -0
  38. package/dist/invariants.js +483 -0
  39. package/dist/invariants.js.map +1 -0
  40. package/dist/ledger.d.ts +154 -0
  41. package/dist/ledger.d.ts.map +1 -0
  42. package/dist/ledger.js +271 -0
  43. package/dist/ledger.js.map +1 -0
  44. package/dist/manifest.d.ts +81 -0
  45. package/dist/manifest.d.ts.map +1 -0
  46. package/dist/manifest.js +394 -0
  47. package/dist/manifest.js.map +1 -0
  48. package/dist/mount.d.ts +18 -0
  49. package/dist/mount.d.ts.map +1 -0
  50. package/dist/mount.js +11 -0
  51. package/dist/mount.js.map +1 -0
  52. package/dist/reflection.d.ts +4 -0
  53. package/dist/reflection.d.ts.map +1 -1
  54. package/dist/reflection.js +9 -0
  55. package/dist/reflection.js.map +1 -1
  56. package/dist/server/context.d.ts +50 -1
  57. package/dist/server/context.d.ts.map +1 -1
  58. package/dist/server/contract.d.ts +8 -1
  59. package/dist/server/contract.d.ts.map +1 -1
  60. package/dist/server/contract.js +11 -1
  61. package/dist/server/contract.js.map +1 -1
  62. package/dist/server/server.d.ts +56 -2
  63. package/dist/server/server.d.ts.map +1 -1
  64. package/dist/server/server.js +294 -17
  65. package/dist/server/server.js.map +1 -1
  66. package/package.json +36 -4
  67. package/src/assurance.ts +48 -1
  68. package/src/budget.ts +267 -0
  69. package/src/capabilities.ts +486 -0
  70. package/src/classification.ts +189 -0
  71. package/src/errors.ts +2 -0
  72. package/src/idempotency.ts +420 -0
  73. package/src/index.ts +8 -1
  74. package/src/internal/capability-runtime.ts +49 -0
  75. package/src/internal/route-assurance.ts +1 -0
  76. package/src/invariants.ts +600 -0
  77. package/src/ledger.ts +430 -0
  78. package/src/manifest.ts +543 -0
  79. package/src/mount.ts +24 -0
  80. package/src/reflection.ts +18 -0
  81. package/src/server/context.ts +54 -1
  82. package/src/server/contract.ts +19 -2
  83. package/src/server/server.ts +463 -26
@@ -1,7 +1,9 @@
1
+ import type { DataClassification } from "../classification.ts"
1
2
  import { RouteConfigError } from "../errors.ts"
3
+ import { normalizeRouteCapabilities } from "../internal/capability-runtime.ts"
2
4
  import { METHODS, type Method } from "../router/router.ts"
3
5
  import type { InferOutput, StandardSchemaV1 } from "../schema/standard.ts"
4
- import type { Context, Params, RouteSchema } from "./context.ts"
6
+ import type { Context, IdempotencyConfig, Params, RouteSchema } from "./context.ts"
5
7
  import type { OutputOf } from "./registry.ts"
6
8
  import { Server } from "./server.ts"
7
9
 
@@ -27,6 +29,12 @@ export interface OperationDef {
27
29
  readonly body?: StandardSchemaV1
28
30
  readonly query?: StandardSchemaV1
29
31
  readonly response?: StandardSchemaV1
32
+ /** Declared effect tokens, carried into route reflection and capability assurance. */
33
+ readonly capabilities?: readonly string[]
34
+ /** Dedupe retries of this operation on an `Idempotency-Key` header (see {@link RouteSchema.idempotency}). */
35
+ readonly idempotency?: IdempotencyConfig
36
+ /** Highest data-sensitivity the response carries (see {@link RouteSchema.classification}). */
37
+ readonly classification?: DataClassification
30
38
  /** Short summary (OpenAPI `summary`). */
31
39
  readonly summary?: string
32
40
  /** Longer description (OpenAPI `description`, CommonMark). */
@@ -167,6 +175,7 @@ export function defineContract<const C extends ContractShape>(contract: C): C {
167
175
  if (seen.has(key)) {
168
176
  throw new RouteConfigError("DUPLICATE_ROUTE", `duplicate operation route: ${key}`)
169
177
  }
178
+ normalizeRouteCapabilities(op.capabilities)
170
179
  seen.add(key)
171
180
  }
172
181
  return contract
@@ -219,11 +228,19 @@ export function implement<const C extends ContractShape, H extends HandlersFor<C
219
228
  // once here at bind time, not per request — it just carries a reference to the op's existing schema.
220
229
  // A response-less op still yields `undefined`, byte-identical to before.
221
230
  const schema: RouteSchema | undefined =
222
- op.body !== undefined || op.query !== undefined || op.response !== undefined
231
+ op.body !== undefined ||
232
+ op.query !== undefined ||
233
+ op.response !== undefined ||
234
+ op.capabilities !== undefined ||
235
+ op.idempotency !== undefined ||
236
+ op.classification !== undefined
223
237
  ? {
224
238
  ...(op.body !== undefined ? { body: op.body } : {}),
225
239
  ...(op.query !== undefined ? { query: op.query } : {}),
226
240
  ...(op.response !== undefined ? { response: op.response } : {}),
241
+ ...(op.capabilities !== undefined ? { capabilities: op.capabilities } : {}),
242
+ ...(op.idempotency !== undefined ? { idempotency: op.idempotency } : {}),
243
+ ...(op.classification !== undefined ? { classification: op.classification } : {}),
227
244
  }
228
245
  : undefined
229
246
  app.register(