hexok 1.0.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 (201) hide show
  1. package/dist/app/api-use-case.d.ts +52 -0
  2. package/dist/app/api-use-case.d.ts.map +1 -0
  3. package/dist/app/api-use-case.js +59 -0
  4. package/dist/app/api-use-case.js.map +1 -0
  5. package/dist/app/callable-use-case.d.ts +34 -0
  6. package/dist/app/callable-use-case.d.ts.map +1 -0
  7. package/dist/app/callable-use-case.js +41 -0
  8. package/dist/app/callable-use-case.js.map +1 -0
  9. package/dist/app/contract.d.ts +46 -0
  10. package/dist/app/contract.d.ts.map +1 -0
  11. package/dist/app/contract.js +28 -0
  12. package/dist/app/contract.js.map +1 -0
  13. package/dist/app/error-factory.d.ts +9 -0
  14. package/dist/app/error-factory.d.ts.map +1 -0
  15. package/dist/app/error-factory.js +30 -0
  16. package/dist/app/error-factory.js.map +1 -0
  17. package/dist/app/event-channel.d.ts +133 -0
  18. package/dist/app/event-channel.d.ts.map +1 -0
  19. package/dist/app/event-channel.js +49 -0
  20. package/dist/app/event-channel.js.map +1 -0
  21. package/dist/app/event-use-case.d.ts +47 -0
  22. package/dist/app/event-use-case.d.ts.map +1 -0
  23. package/dist/app/event-use-case.js +54 -0
  24. package/dist/app/event-use-case.js.map +1 -0
  25. package/dist/app/execute-ctx.d.ts +92 -0
  26. package/dist/app/execute-ctx.d.ts.map +1 -0
  27. package/dist/app/execute-ctx.js +2 -0
  28. package/dist/app/execute-ctx.js.map +1 -0
  29. package/dist/app/external-use-case.d.ts +25 -0
  30. package/dist/app/external-use-case.d.ts.map +1 -0
  31. package/dist/app/external-use-case.js +25 -0
  32. package/dist/app/external-use-case.js.map +1 -0
  33. package/dist/app/index.d.ts +9 -0
  34. package/dist/app/index.d.ts.map +1 -0
  35. package/dist/app/index.js +8 -0
  36. package/dist/app/index.js.map +1 -0
  37. package/dist/app/internal-use-case.d.ts +26 -0
  38. package/dist/app/internal-use-case.d.ts.map +1 -0
  39. package/dist/app/internal-use-case.js +26 -0
  40. package/dist/app/internal-use-case.js.map +1 -0
  41. package/dist/app/nest.d.ts +9 -0
  42. package/dist/app/nest.d.ts.map +1 -0
  43. package/dist/app/nest.js +28 -0
  44. package/dist/app/nest.js.map +1 -0
  45. package/dist/app/types.d.ts +153 -0
  46. package/dist/app/types.d.ts.map +1 -0
  47. package/dist/app/types.js +17 -0
  48. package/dist/app/types.js.map +1 -0
  49. package/dist/core/coded-error.d.ts +24 -0
  50. package/dist/core/coded-error.d.ts.map +1 -0
  51. package/dist/core/coded-error.js +32 -0
  52. package/dist/core/coded-error.js.map +1 -0
  53. package/dist/core/error-map.d.ts +21 -0
  54. package/dist/core/error-map.d.ts.map +1 -0
  55. package/dist/core/error-map.js +5 -0
  56. package/dist/core/error-map.js.map +1 -0
  57. package/dist/core/index.d.ts +6 -0
  58. package/dist/core/index.d.ts.map +1 -0
  59. package/dist/core/index.js +5 -0
  60. package/dist/core/index.js.map +1 -0
  61. package/dist/core/result.d.ts +23 -0
  62. package/dist/core/result.d.ts.map +1 -0
  63. package/dist/core/result.js +11 -0
  64. package/dist/core/result.js.map +1 -0
  65. package/dist/core/schema.d.ts +19 -0
  66. package/dist/core/schema.d.ts.map +1 -0
  67. package/dist/core/schema.js +28 -0
  68. package/dist/core/schema.js.map +1 -0
  69. package/dist/core/standard-schema.d.ts +51 -0
  70. package/dist/core/standard-schema.d.ts.map +1 -0
  71. package/dist/core/standard-schema.js +2 -0
  72. package/dist/core/standard-schema.js.map +1 -0
  73. package/dist/domain/capabilities.d.ts +42 -0
  74. package/dist/domain/capabilities.d.ts.map +1 -0
  75. package/dist/domain/capabilities.js +2 -0
  76. package/dist/domain/capabilities.js.map +1 -0
  77. package/dist/domain/catalog.d.ts +46 -0
  78. package/dist/domain/catalog.d.ts.map +1 -0
  79. package/dist/domain/catalog.js +114 -0
  80. package/dist/domain/catalog.js.map +1 -0
  81. package/dist/domain/channel.d.ts +36 -0
  82. package/dist/domain/channel.d.ts.map +1 -0
  83. package/dist/domain/channel.js +2 -0
  84. package/dist/domain/channel.js.map +1 -0
  85. package/dist/domain/cow-draft.d.ts +10 -0
  86. package/dist/domain/cow-draft.d.ts.map +1 -0
  87. package/dist/domain/cow-draft.js +147 -0
  88. package/dist/domain/cow-draft.js.map +1 -0
  89. package/dist/domain/entity.d.ts +120 -0
  90. package/dist/domain/entity.d.ts.map +1 -0
  91. package/dist/domain/entity.js +263 -0
  92. package/dist/domain/entity.js.map +1 -0
  93. package/dist/domain/envelope.d.ts +59 -0
  94. package/dist/domain/envelope.d.ts.map +1 -0
  95. package/dist/domain/envelope.js +2 -0
  96. package/dist/domain/envelope.js.map +1 -0
  97. package/dist/domain/event.d.ts +44 -0
  98. package/dist/domain/event.d.ts.map +1 -0
  99. package/dist/domain/event.js +21 -0
  100. package/dist/domain/event.js.map +1 -0
  101. package/dist/domain/index.d.ts +8 -0
  102. package/dist/domain/index.d.ts.map +1 -0
  103. package/dist/domain/index.js +5 -0
  104. package/dist/domain/index.js.map +1 -0
  105. package/dist/domain/port.d.ts +45 -0
  106. package/dist/domain/port.d.ts.map +1 -0
  107. package/dist/domain/port.js +41 -0
  108. package/dist/domain/port.js.map +1 -0
  109. package/dist/infra/adapter.d.ts +22 -0
  110. package/dist/infra/adapter.d.ts.map +1 -0
  111. package/dist/infra/adapter.js +18 -0
  112. package/dist/infra/adapter.js.map +1 -0
  113. package/dist/infra/index.d.ts +3 -0
  114. package/dist/infra/index.d.ts.map +1 -0
  115. package/dist/infra/index.js +3 -0
  116. package/dist/infra/index.js.map +1 -0
  117. package/dist/infra/mapper.d.ts +48 -0
  118. package/dist/infra/mapper.d.ts.map +1 -0
  119. package/dist/infra/mapper.js +77 -0
  120. package/dist/infra/mapper.js.map +1 -0
  121. package/dist/runtime/app.d.ts +100 -0
  122. package/dist/runtime/app.d.ts.map +1 -0
  123. package/dist/runtime/app.js +292 -0
  124. package/dist/runtime/app.js.map +1 -0
  125. package/dist/runtime/channel.d.ts +34 -0
  126. package/dist/runtime/channel.d.ts.map +1 -0
  127. package/dist/runtime/channel.js +110 -0
  128. package/dist/runtime/channel.js.map +1 -0
  129. package/dist/runtime/client.d.ts +21 -0
  130. package/dist/runtime/client.d.ts.map +1 -0
  131. package/dist/runtime/client.js +2 -0
  132. package/dist/runtime/client.js.map +1 -0
  133. package/dist/runtime/completeness.d.ts +89 -0
  134. package/dist/runtime/completeness.d.ts.map +1 -0
  135. package/dist/runtime/completeness.js +2 -0
  136. package/dist/runtime/completeness.js.map +1 -0
  137. package/dist/runtime/envelope.d.ts +7 -0
  138. package/dist/runtime/envelope.d.ts.map +1 -0
  139. package/dist/runtime/envelope.js +69 -0
  140. package/dist/runtime/envelope.js.map +1 -0
  141. package/dist/runtime/events.d.ts +6 -0
  142. package/dist/runtime/events.d.ts.map +1 -0
  143. package/dist/runtime/events.js +48 -0
  144. package/dist/runtime/events.js.map +1 -0
  145. package/dist/runtime/http-status.d.ts +3 -0
  146. package/dist/runtime/http-status.d.ts.map +1 -0
  147. package/dist/runtime/http-status.js +11 -0
  148. package/dist/runtime/http-status.js.map +1 -0
  149. package/dist/runtime/http.d.ts +4 -0
  150. package/dist/runtime/http.d.ts.map +1 -0
  151. package/dist/runtime/http.js +58 -0
  152. package/dist/runtime/http.js.map +1 -0
  153. package/dist/runtime/index.d.ts +10 -0
  154. package/dist/runtime/index.d.ts.map +1 -0
  155. package/dist/runtime/index.js +6 -0
  156. package/dist/runtime/index.js.map +1 -0
  157. package/dist/runtime/interceptor.d.ts +61 -0
  158. package/dist/runtime/interceptor.d.ts.map +1 -0
  159. package/dist/runtime/interceptor.js +7 -0
  160. package/dist/runtime/interceptor.js.map +1 -0
  161. package/dist/runtime/invoke.d.ts +34 -0
  162. package/dist/runtime/invoke.d.ts.map +1 -0
  163. package/dist/runtime/invoke.js +235 -0
  164. package/dist/runtime/invoke.js.map +1 -0
  165. package/dist/runtime/middleware.d.ts +20 -0
  166. package/dist/runtime/middleware.d.ts.map +1 -0
  167. package/dist/runtime/middleware.js +2 -0
  168. package/dist/runtime/middleware.js.map +1 -0
  169. package/dist/runtime/rpc.d.ts +24 -0
  170. package/dist/runtime/rpc.d.ts.map +1 -0
  171. package/dist/runtime/rpc.js +16 -0
  172. package/dist/runtime/rpc.js.map +1 -0
  173. package/dist/testing/app-test.d.ts +77 -0
  174. package/dist/testing/app-test.d.ts.map +1 -0
  175. package/dist/testing/app-test.js +109 -0
  176. package/dist/testing/app-test.js.map +1 -0
  177. package/dist/testing/in-memory-broker.d.ts +18 -0
  178. package/dist/testing/in-memory-broker.d.ts.map +1 -0
  179. package/dist/testing/in-memory-broker.js +42 -0
  180. package/dist/testing/in-memory-broker.js.map +1 -0
  181. package/dist/testing/in-memory-bus.d.ts +19 -0
  182. package/dist/testing/in-memory-bus.d.ts.map +1 -0
  183. package/dist/testing/in-memory-bus.js +31 -0
  184. package/dist/testing/in-memory-bus.js.map +1 -0
  185. package/dist/testing/in-memory-channel.d.ts +32 -0
  186. package/dist/testing/in-memory-channel.d.ts.map +1 -0
  187. package/dist/testing/in-memory-channel.js +65 -0
  188. package/dist/testing/in-memory-channel.js.map +1 -0
  189. package/dist/testing/in-memory-queue.d.ts +24 -0
  190. package/dist/testing/in-memory-queue.d.ts.map +1 -0
  191. package/dist/testing/in-memory-queue.js +66 -0
  192. package/dist/testing/in-memory-queue.js.map +1 -0
  193. package/dist/testing/in-memory-repository.d.ts +44 -0
  194. package/dist/testing/in-memory-repository.d.ts.map +1 -0
  195. package/dist/testing/in-memory-repository.js +60 -0
  196. package/dist/testing/in-memory-repository.js.map +1 -0
  197. package/dist/testing/index.d.ts +6 -0
  198. package/dist/testing/index.d.ts.map +1 -0
  199. package/dist/testing/index.js +6 -0
  200. package/dist/testing/index.js.map +1 -0
  201. package/package.json +60 -0
@@ -0,0 +1,21 @@
1
+ import type { StandardSchemaV1 } from './standard-schema.js';
2
+ /**
3
+ * Declared metadata for one error code. Keys of an `ErrorMap` **are** the error union.
4
+ *
5
+ * ```ts
6
+ * const errors = {
7
+ * NOT_FOUND: { message: 'Incident not found' },
8
+ * }
9
+ * ```
10
+ */
11
+ export interface ErrorDef {
12
+ /** Human message. Factories fall back to the code when omitted. */
13
+ message?: string;
14
+ /** Optional payload schema for `errors.CODE(data)`. */
15
+ data?: StandardSchemaV1;
16
+ }
17
+ /** `static errors` bag. Prefer `defineErrors({ ... })` so keys stay a finite union. */
18
+ export type ErrorMap = Record<string, ErrorDef>;
19
+ /** Infer error-code keys from an object literal. Use for `static readonly errors`. */
20
+ export declare function defineErrors<const M extends Record<string, ErrorDef>>(map: M): M;
21
+ //# sourceMappingURL=error-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-map.d.ts","sourceRoot":"","sources":["../../src/core/error-map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;;;;;;;GAQG;AACH,MAAM,WAAW,QAAQ;IACvB,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,IAAI,CAAC,EAAE,gBAAgB,CAAC;CACzB;AAED,uFAAuF;AACvF,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAEhD,sFAAsF;AACtF,wBAAgB,YAAY,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,EACnE,GAAG,EAAE,CAAC,GACL,CAAC,CAEH"}
@@ -0,0 +1,5 @@
1
+ /** Infer error-code keys from an object literal. Use for `static readonly errors`. */
2
+ export function defineErrors(map) {
3
+ return map;
4
+ }
5
+ //# sourceMappingURL=error-map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-map.js","sourceRoot":"","sources":["../../src/core/error-map.ts"],"names":[],"mappings":"AAqBA,sFAAsF;AACtF,MAAM,UAAU,YAAY,CAC1B,GAAM;IAEN,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { CodedError, validationError } from './coded-error.js';
2
+ export { defineErrors, type ErrorDef, type ErrorMap } from './error-map.js';
3
+ export { fail, ok, type Result } from './result.js';
4
+ export { type Infer, validate } from './schema.js';
5
+ export type { StandardSchemaV1 } from './standard-schema.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,KAAK,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACnD,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { CodedError, validationError } from './coded-error.js';
2
+ export { defineErrors } from './error-map.js';
3
+ export { fail, ok } from './result.js';
4
+ export { validate } from './schema.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAgC,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAE,EAAE,EAAe,MAAM,aAAa,CAAC;AACpD,OAAO,EAAc,QAAQ,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { StandardSchemaV1 } from './standard-schema.js';
2
+ /**
3
+ * Success-or-code result. `validate` returns this; use cases may `unwrap` it.
4
+ * Entity methods throw `CodedError` instead of returning a Result.
5
+ *
6
+ * ```ts
7
+ * const parsed = validate(schema, value)
8
+ * // Result<Output, 'VALIDATION'> — fail may include `issues`
9
+ * ```
10
+ */
11
+ export type Result<T, E extends string = string> = {
12
+ ok: true;
13
+ value: T;
14
+ } | {
15
+ ok: false;
16
+ code: E;
17
+ issues?: readonly StandardSchemaV1.Issue[];
18
+ };
19
+ /** Wrap a value. The error arm is `never` so unions collapse from `ok`/`fail` branches. */
20
+ export declare function ok<T>(value: T): Result<T, never>;
21
+ /** Wrap an error code. Pass `issues` from a Standard Schema fail so callers can show field errors. */
22
+ export declare function fail<E extends string>(code: E, issues?: readonly StandardSchemaV1.Issue[]): Result<never, E>;
23
+ //# sourceMappingURL=result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/core/result.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;;;;;;;GAQG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,IAC3C;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GACtB;IACE,EAAE,EAAE,KAAK,CAAC;IACV,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,CAAC,EAAE,SAAS,gBAAgB,CAAC,KAAK,EAAE,CAAC;CAC5C,CAAC;AAEN,2FAA2F;AAC3F,wBAAgB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAEhD;AAED,sGAAsG;AACtG,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,EACnC,IAAI,EAAE,CAAC,EACP,MAAM,CAAC,EAAE,SAAS,gBAAgB,CAAC,KAAK,EAAE,GACzC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAIlB"}
@@ -0,0 +1,11 @@
1
+ /** Wrap a value. The error arm is `never` so unions collapse from `ok`/`fail` branches. */
2
+ export function ok(value) {
3
+ return { ok: true, value };
4
+ }
5
+ /** Wrap an error code. Pass `issues` from a Standard Schema fail so callers can show field errors. */
6
+ export function fail(code, issues) {
7
+ return issues !== undefined
8
+ ? { ok: false, code, issues }
9
+ : { ok: false, code };
10
+ }
11
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/core/result.ts"],"names":[],"mappings":"AAmBA,2FAA2F;AAC3F,MAAM,UAAU,EAAE,CAAI,KAAQ;IAC5B,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAED,sGAAsG;AACtG,MAAM,UAAU,IAAI,CAClB,IAAO,EACP,MAA0C;IAE1C,OAAO,MAAM,KAAK,SAAS;QACzB,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE;QAC7B,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { type Result } from './result.js';
2
+ import type { StandardSchemaV1 } from './standard-schema.js';
3
+ /** Output type of a Standard Schema V1 schema. */
4
+ export type Infer<S extends StandardSchemaV1> = NonNullable<S['~standard']['types']>['output'];
5
+ /**
6
+ * Validate `value` with a Standard Schema. Sync only.
7
+ *
8
+ * Failures are `'VALIDATION'` plus Standard Schema `issues`. Entity
9
+ * `create` / `parse` / `set` / `validate()` throw that as `CodedError`.
10
+ * `restore` does not run the schema.
11
+ * Async schemas belong at the application edge and throw.
12
+ *
13
+ * ```ts
14
+ * const parsed = validate(Incident.schema, body)
15
+ * if (!parsed.ok) return parsed
16
+ * ```
17
+ */
18
+ export declare function validate<S extends StandardSchemaV1>(schema: S, value: unknown): Result<Infer<S>, 'VALIDATION'>;
19
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/core/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,kDAAkD;AAClD,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,gBAAgB,IAAI,WAAW,CACzD,CAAC,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CACxB,CAAC,QAAQ,CAAC,CAAC;AAEZ;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,gBAAgB,EACjD,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,OAAO,GACb,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAShC"}
@@ -0,0 +1,28 @@
1
+ import { fail, ok } from './result.js';
2
+ /**
3
+ * Validate `value` with a Standard Schema. Sync only.
4
+ *
5
+ * Failures are `'VALIDATION'` plus Standard Schema `issues`. Entity
6
+ * `create` / `parse` / `set` / `validate()` throw that as `CodedError`.
7
+ * `restore` does not run the schema.
8
+ * Async schemas belong at the application edge and throw.
9
+ *
10
+ * ```ts
11
+ * const parsed = validate(Incident.schema, body)
12
+ * if (!parsed.ok) return parsed
13
+ * ```
14
+ */
15
+ export function validate(schema, value) {
16
+ const result = schema['~standard'].validate(value);
17
+ if (isPromise(result)) {
18
+ throw new Error('hexok: async schemas belong at the application edge');
19
+ }
20
+ if (result.issues) {
21
+ return fail('VALIDATION', result.issues);
22
+ }
23
+ return ok(result.value);
24
+ }
25
+ function isPromise(value) {
26
+ return typeof value.then === 'function';
27
+ }
28
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/core/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,EAAE,EAAe,MAAM,aAAa,CAAC;AAQpD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,QAAQ,CACtB,MAAS,EACT,KAAc;IAEd,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACnD,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,EAAE,CAAC,MAAM,CAAC,KAAiB,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,SAAS,CAChB,KAE6C;IAE7C,OAAO,OAAQ,KAA0B,CAAC,IAAI,KAAK,UAAU,CAAC;AAChE,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Vendored Standard Schema V1. Copy of https://standardschema.dev
3
+ * so `hexok/core` has zero runtime dependencies.
4
+ */
5
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
6
+ /** Spec bag: version, vendor, validate, optional inferred types. */
7
+ readonly '~standard': StandardSchemaV1.Props<Input, Output>;
8
+ }
9
+ export declare namespace StandardSchemaV1 {
10
+ /** Version, vendor, `validate`, and optional input/output types. */
11
+ interface Props<Input = unknown, Output = Input> {
12
+ /** Spec version. Always `1`. */
13
+ readonly version: 1;
14
+ /** Schema library name, e.g. `'zod'`. */
15
+ readonly vendor: string;
16
+ /** Parse unknown input. Hexok `validate` rejects a returned Promise. */
17
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
18
+ /** Present so `Infer` can read input/output. */
19
+ readonly types?: Types<Input, Output> | undefined;
20
+ }
21
+ /** Success or failure from `~standard.validate`. Not hexok `Result`. */
22
+ type Result<Output> = SuccessResult<Output> | FailureResult;
23
+ /** Passed validation. `issues` is absent. */
24
+ interface SuccessResult<Output> {
25
+ readonly value: Output;
26
+ readonly issues?: undefined;
27
+ }
28
+ /** Failed validation. `issues` is always present. */
29
+ interface FailureResult {
30
+ readonly issues: ReadonlyArray<Issue>;
31
+ }
32
+ /** One validation problem. Hexok `validate` copies these onto the fail arm. */
33
+ interface Issue {
34
+ readonly message: string;
35
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
36
+ }
37
+ /** Path entry when the key is not a plain PropertyKey. */
38
+ interface PathSegment {
39
+ readonly key: PropertyKey;
40
+ }
41
+ /** Inferred input and output types carried on `~standard.types`. */
42
+ interface Types<Input = unknown, Output = Input> {
43
+ readonly input: Input;
44
+ readonly output: Output;
45
+ }
46
+ /** Input type of a Standard Schema. Prefer hexok `Infer` for output. */
47
+ type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
48
+ /** Output type of a Standard Schema. Same as hexok `Infer`. */
49
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
50
+ }
51
+ //# sourceMappingURL=standard-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard-schema.d.ts","sourceRoot":"","sources":["../../src/core/standard-schema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,gBAAgB,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;IAC/D,oEAAoE;IACpE,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;CAC7D;AAED,MAAM,CAAC,OAAO,WAAW,gBAAgB,CAAC;IACxC,oEAAoE;IACpE,UAAiB,KAAK,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;QACpD,gCAAgC;QAChC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QACpB,yCAAyC;QACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,wEAA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BAAgB,IAAI,WAAW,CACpE,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAC7B,CAAC,QAAQ,CAAC,CAAC;CACb"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=standard-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard-schema.js","sourceRoot":"","sources":["../../src/core/standard-schema.ts"],"names":[],"mappings":""}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Optional adapter capabilities. Intersect these with a port interface.
3
+ * Pass `{ transactional: true }` / `{ requestScoped: true }` to `Port.token`
4
+ * so `provide()` throws if the impl is missing `bindTo` / `fork`.
5
+ *
6
+ * ```ts
7
+ * class PgIncidentRepo implements IncidentRepository, Transactional<IncidentRepository> {
8
+ * bindTo(uow: UnitOfWork): IncidentRepository { return this }
9
+ * }
10
+ * ```
11
+ */
12
+ export interface UnitOfWork {
13
+ /** Register work to run after a successful commit. */
14
+ onCommit(fn: () => void | Promise<void>): void;
15
+ /** Register work to run after a rollback. */
16
+ onRollback(fn: () => void | Promise<void>): void;
17
+ }
18
+ /** Port capability: the adapter can bind itself to a unit of work. */
19
+ export interface Transactional<T = unknown> {
20
+ /** Return this port bound to `uow` (often `return this`). */
21
+ bindTo(uow: UnitOfWork): T;
22
+ }
23
+ /** Port capability: the adapter can fork a request-scoped instance. */
24
+ export interface RequestScoped<T = unknown> {
25
+ /** Return a new instance scoped to the current request. */
26
+ fork(): T;
27
+ }
28
+ /**
29
+ * Standard repository shape. Authors write their own port interface;
30
+ * this is the contract `InMemoryRepository` can fake.
31
+ */
32
+ export interface CrudRepository<E> {
33
+ /** Load one entity by id, or `null` if missing. */
34
+ get(id: string): Promise<E | null>;
35
+ /** Persist an entity. Adapters call `entity.commit()` after a successful write. */
36
+ save(entity: E): Promise<void>;
37
+ /** List all entities. Optional on the port. */
38
+ list?(): Promise<E[]>;
39
+ /** Delete by id. Optional on the port. */
40
+ delete?(id: string): Promise<void>;
41
+ }
42
+ //# sourceMappingURL=capabilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/domain/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,WAAW,UAAU;IACzB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC/C,6CAA6C;IAC7C,UAAU,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAClD;AAED,sEAAsE;AACtE,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,OAAO;IACxC,6DAA6D;IAC7D,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,CAAC,CAAC;CAC5B;AAED,uEAAuE;AACvE,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,OAAO;IACxC,2DAA2D;IAC3D,IAAI,IAAI,CAAC,CAAC;CACX;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,mDAAmD;IACnD,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACnC,mFAAmF;IACnF,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,+CAA+C;IAC/C,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IACtB,0CAA0C;IAC1C,MAAM,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=capabilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../src/domain/capabilities.ts"],"names":[],"mappings":""}
@@ -0,0 +1,46 @@
1
+ import type { CatalogKind } from './envelope.js';
2
+ import type { EventClass, EventWithCtx } from './event.js';
3
+ /**
4
+ * Registry of event classes. `kind` is `'bus'` (fan-out, fire-and-forget, no
5
+ * persistence) or `'queue'` (work queue: one consumer in a group, ack/nack).
6
+ * `.event()` accumulates each class on the covariant `Events` generic (empty is `never`).
7
+ * Use-case convention: `static publishes = [DomainEvents] as const`.
8
+ *
9
+ * ```ts
10
+ * const DomainEvents = new EventCatalog('domain', { kind: 'bus' })
11
+ * .event(IncidentClosed)
12
+ * DomainEvents.get(IncidentClosed)
13
+ * DomainEvents.incident.closed // when every segment is a JS identifier
14
+ * ```
15
+ */
16
+ export declare class EventCatalog<Key extends string = string, Kind extends CatalogKind = CatalogKind, out Events extends EventClass = never, out Ctx = undefined> {
17
+ #private;
18
+ /** Catalog name, copied onto envelopes and used in error messages. */
19
+ readonly key: Key;
20
+ /** `'bus'` (fan-out) or `'queue'` (work queue). Copied onto every envelope. */
21
+ readonly kind: Kind;
22
+ /** Create a named `'bus'` or `'queue'` catalog. Chain `.event(...)` then `.freeze()`. */
23
+ constructor(key: Key, options: {
24
+ kind: Kind;
25
+ });
26
+ /** Require `ctx: C` on every event in this catalog. Call before `.event()`. */
27
+ ctx<C>(): EventCatalog<Key, Kind, Events, C>;
28
+ /** True after `.ctx()` — every registered event must expose `ctx`. */
29
+ get hasCtx(): boolean;
30
+ /** Registered event classes, in registration order. */
31
+ list(): EventClass[];
32
+ /** Register an event class. Dotted keys become nested properties when each segment is a JS identifier. */
33
+ event<E extends EventClass>(eventClass: [Ctx] extends [undefined] ? E : EventWithCtx<E, Ctx>): EventCatalog<Key, Kind, Events | E, Ctx>;
34
+ /** Look up a registered class. Throws if it is not in this catalog. */
35
+ get<E extends EventClass>(eventClass: E): E;
36
+ /** Seal the catalog. Further `.event()` / `.ctx()` throw. */
37
+ freeze(): EventCatalog<Key, Kind, Events, Ctx>;
38
+ /** True after `.freeze()`. */
39
+ get frozen(): boolean;
40
+ private assertWritable;
41
+ }
42
+ /** Safe annotation / Map key. Bare `EventCatalog` is Events=never and rejects populated catalogs. */
43
+ export type AnyEventCatalog = EventCatalog<string, CatalogKind, EventClass, unknown>;
44
+ /** Event classes registered on `Cat`, or `never` when the catalog is empty. */
45
+ export type CatalogEvents<Cat> = Cat extends EventCatalog<infer _Key, infer _Kind, infer E extends EventClass, infer _Ctx> ? E : never;
46
+ //# sourceMappingURL=catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/domain/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI3D;;;;;;;;;;;;GAYG;AACH,qBAAa,YAAY,CACvB,GAAG,SAAS,MAAM,GAAG,MAAM,EAC3B,IAAI,SAAS,WAAW,GAAG,WAAW,EACtC,GAAG,CAAC,MAAM,SAAS,UAAU,GAAG,KAAK,EACrC,GAAG,CAAC,GAAG,GAAG,SAAS;;IAEnB,sEAAsE;IACtE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,+EAA+E;IAC/E,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAKpB,yFAAyF;gBAC7E,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE;IAK7C,+EAA+E;IAC/E,GAAG,CAAC,CAAC,KAAK,YAAY,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAc5C,sEAAsE;IACtE,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,uDAAuD;IACvD,IAAI,IAAI,UAAU,EAAE;IAIpB,0GAA0G;IAC1G,KAAK,CAAC,CAAC,SAAS,UAAU,EACxB,UAAU,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,CAAC,EAAE,GAAG,CAAC,GAC/D,YAAY,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,CAAC;IAkB3C,uEAAuE;IACvE,GAAG,CAAC,CAAC,SAAS,UAAU,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC;IAU3C,6DAA6D;IAC7D,MAAM,IAAI,YAAY,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC;IAO9C,8BAA8B;IAC9B,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,OAAO,CAAC,cAAc;CAKvB;AAED,qGAAqG;AACrG,MAAM,MAAM,eAAe,GAAG,YAAY,CACxC,MAAM,EACN,WAAW,EACX,UAAU,EACV,OAAO,CACR,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,aAAa,CAAC,GAAG,IAC3B,GAAG,SAAS,YAAY,CACtB,MAAM,IAAI,EACV,MAAM,KAAK,EACX,MAAM,CAAC,SAAS,UAAU,EAC1B,MAAM,IAAI,CACX,GACG,CAAC,GACD,KAAK,CAAC"}
@@ -0,0 +1,114 @@
1
+ const IDENT = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
2
+ /**
3
+ * Registry of event classes. `kind` is `'bus'` (fan-out, fire-and-forget, no
4
+ * persistence) or `'queue'` (work queue: one consumer in a group, ack/nack).
5
+ * `.event()` accumulates each class on the covariant `Events` generic (empty is `never`).
6
+ * Use-case convention: `static publishes = [DomainEvents] as const`.
7
+ *
8
+ * ```ts
9
+ * const DomainEvents = new EventCatalog('domain', { kind: 'bus' })
10
+ * .event(IncidentClosed)
11
+ * DomainEvents.get(IncidentClosed)
12
+ * DomainEvents.incident.closed // when every segment is a JS identifier
13
+ * ```
14
+ */
15
+ export class EventCatalog {
16
+ /** Catalog name, copied onto envelopes and used in error messages. */
17
+ key;
18
+ /** `'bus'` (fan-out) or `'queue'` (work queue). Copied onto every envelope. */
19
+ kind;
20
+ #events = new Map();
21
+ #frozen = false;
22
+ #hasCtx = false;
23
+ /** Create a named `'bus'` or `'queue'` catalog. Chain `.event(...)` then `.freeze()`. */
24
+ constructor(key, options) {
25
+ this.key = key;
26
+ this.kind = options.kind;
27
+ }
28
+ /** Require `ctx: C` on every event in this catalog. Call before `.event()`. */
29
+ ctx() {
30
+ this.assertWritable();
31
+ if (this.#hasCtx) {
32
+ throw new Error(`hexok: catalog "${this.key}" already has ctx`);
33
+ }
34
+ if (this.#events.size > 0) {
35
+ throw new Error(`hexok: catalog "${this.key}" ctx() must be called before .event()`);
36
+ }
37
+ this.#hasCtx = true;
38
+ return this;
39
+ }
40
+ /** True after `.ctx()` — every registered event must expose `ctx`. */
41
+ get hasCtx() {
42
+ return this.#hasCtx;
43
+ }
44
+ /** Registered event classes, in registration order. */
45
+ list() {
46
+ return [...this.#events.values()];
47
+ }
48
+ /** Register an event class. Dotted keys become nested properties when each segment is a JS identifier. */
49
+ event(eventClass) {
50
+ this.assertWritable();
51
+ const ctor = eventClass;
52
+ const eventKey = ctor.key;
53
+ if (this.#events.has(eventKey)) {
54
+ throw new Error(`hexok: duplicate event "${eventKey}" in catalog "${this.key}"`);
55
+ }
56
+ this.#events.set(eventKey, ctor);
57
+ nestIdentifierPath(this, eventKey, ctor);
58
+ return this;
59
+ }
60
+ /** Look up a registered class. Throws if it is not in this catalog. */
61
+ get(eventClass) {
62
+ const found = this.#events.get(eventClass.key);
63
+ if (!found) {
64
+ throw new Error(`hexok: event "${eventClass.key}" is not in catalog "${this.key}"`);
65
+ }
66
+ return found;
67
+ }
68
+ /** Seal the catalog. Further `.event()` / `.ctx()` throw. */
69
+ freeze() {
70
+ if (this.#frozen)
71
+ return this;
72
+ this.#frozen = true;
73
+ Object.freeze(this);
74
+ return this;
75
+ }
76
+ /** True after `.freeze()`. */
77
+ get frozen() {
78
+ return this.#frozen;
79
+ }
80
+ assertWritable() {
81
+ if (this.#frozen) {
82
+ throw new Error(`hexok: catalog "${this.key}" is frozen`);
83
+ }
84
+ }
85
+ }
86
+ function nestIdentifierPath(root, dotted, value) {
87
+ const parts = dotted.split('.');
88
+ if (parts.length === 0 || parts.some((part) => !IDENT.test(part))) {
89
+ return;
90
+ }
91
+ let cursor = root;
92
+ for (let i = 0; i < parts.length - 1; i++) {
93
+ const key = parts[i];
94
+ if (key === undefined)
95
+ return;
96
+ const existing = cursor[key];
97
+ if (existing === undefined) {
98
+ const next = Object.create(null);
99
+ cursor[key] = next;
100
+ cursor = next;
101
+ continue;
102
+ }
103
+ if (typeof existing === 'object' && existing !== null) {
104
+ cursor = existing;
105
+ continue;
106
+ }
107
+ return;
108
+ }
109
+ const last = parts[parts.length - 1];
110
+ if (last === undefined)
111
+ return;
112
+ cursor[last] = value;
113
+ }
114
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/domain/catalog.ts"],"names":[],"mappings":"AAGA,MAAM,KAAK,GAAG,4BAA4B,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,YAAY;IAMvB,sEAAsE;IAC7D,GAAG,CAAM;IAClB,+EAA+E;IACtE,IAAI,CAAO;IACpB,OAAO,GAAG,IAAI,GAAG,EAAsB,CAAC;IACxC,OAAO,GAAG,KAAK,CAAC;IAChB,OAAO,GAAG,KAAK,CAAC;IAEhB,yFAAyF;IACzF,YAAY,GAAQ,EAAE,OAAuB;QAC3C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,+EAA+E;IAC/E,GAAG;QACD,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,CAAC,GAAG,mBAAmB,CAAC,CAAC;QAClE,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;Y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AAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACtD,MAAM,GAAG,QAAmC,CAAC;YAC7C,SAAS;QACX,CAAC;QACD,OAAO;IACT,CAAC;IACD,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACrC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO;IAC/B,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;AACvB,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Byte sink for one connected client. WebSocket and SSE adapters wrap their
3
+ * native connection as this shape.
4
+ */
5
+ export type ChannelConnection = {
6
+ /** Write one frame to this client. */
7
+ send(data: string): void;
8
+ /** Disconnect this client. */
9
+ close(): void;
10
+ /** Subscribe to the native close. */
11
+ addEventListener(type: 'close', listener: () => void): void;
12
+ };
13
+ /**
14
+ * Local presence + send. Bound with `.route(Channel, adapter)`.
15
+ * Does not interpret routing hints or session claims.
16
+ */
17
+ export interface ChannelAdapter<Session = unknown> {
18
+ /** Bind a connected client into local presence. */
19
+ join(id: string, session: Session, connection: ChannelConnection): void;
20
+ /** Remove a client that left. */
21
+ leave(id: string): void;
22
+ /** Force-disconnect a client. */
23
+ eject(id: string): void;
24
+ /** Replace the session attached to a connected id. */
25
+ update(id: string, session: Session): void;
26
+ /** Snapshot of who is present. */
27
+ list(): ReadonlyArray<{
28
+ id: string;
29
+ session: Session;
30
+ }>;
31
+ /** Send a payload to one connected id. */
32
+ send(id: string, payload: string): void;
33
+ /** Tear down the adapter. Optional. */
34
+ stop?(): Promise<void>;
35
+ }
36
+ //# sourceMappingURL=channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/domain/channel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,sCAAsC;IACtC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,8BAA8B;IAC9B,KAAK,IAAI,IAAI,CAAC;IACd,qCAAqC;IACrC,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;CAC7D,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,cAAc,CAAC,OAAO,GAAG,OAAO;IAC/C,mDAAmD;IACnD,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACxE,iCAAiC;IACjC,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,iCAAiC;IACjC,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,sDAAsD;IACtD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3C,kCAAkC;IAClC,IAAI,IAAI,aAAa,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACxD,0CAA0C;IAC1C,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,uCAAuC;IACvC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel.js","sourceRoot":"","sources":["../../src/domain/channel.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
2
+ export declare function applyCowDraft<T extends object>(root: T, owned: WeakSet<object> | undefined, producer: (draft: T) => void): {
3
+ root: T;
4
+ owned: WeakSet<object> | undefined;
5
+ wrote: boolean;
6
+ };
7
+ export declare function frozenSnapshot<T>(value: T): T;
8
+ /** Unfrozen deep clone of plain objects, arrays, and `Date`. */
9
+ export declare function cloneValue<T>(value: T): T;
10
+ //# sourceMappingURL=cow-draft.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cow-draft.d.ts","sourceRoot":"","sources":["../../src/domain/cow-draft.ts"],"names":[],"mappings":"AAIA,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAKlC;AAMD,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAC5C,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,SAAS,EAClC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAC3B;IAAE,IAAI,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CA+FjE;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAE7C;AAED,gEAAgE;AAChE,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAEzC"}