@byline/core 0.9.3

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 (283) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +17 -0
  3. package/dist/@types/admin-types.d.ts +275 -0
  4. package/dist/@types/admin-types.d.ts.map +1 -0
  5. package/dist/@types/admin-types.js +18 -0
  6. package/dist/@types/admin-types.js.map +1 -0
  7. package/dist/@types/collection-types.d.ts +816 -0
  8. package/dist/@types/collection-types.d.ts.map +1 -0
  9. package/dist/@types/collection-types.js +217 -0
  10. package/dist/@types/collection-types.js.map +1 -0
  11. package/dist/@types/db-types.d.ts +463 -0
  12. package/dist/@types/db-types.d.ts.map +1 -0
  13. package/dist/@types/db-types.js +2 -0
  14. package/dist/@types/db-types.js.map +1 -0
  15. package/dist/@types/field-data-types.d.ts +147 -0
  16. package/dist/@types/field-data-types.d.ts.map +1 -0
  17. package/dist/@types/field-data-types.js +38 -0
  18. package/dist/@types/field-data-types.js.map +1 -0
  19. package/dist/@types/field-types.d.ts +579 -0
  20. package/dist/@types/field-types.d.ts.map +1 -0
  21. package/dist/@types/field-types.js +32 -0
  22. package/dist/@types/field-types.js.map +1 -0
  23. package/dist/@types/index.d.ts +18 -0
  24. package/dist/@types/index.d.ts.map +1 -0
  25. package/dist/@types/index.js +18 -0
  26. package/dist/@types/index.js.map +1 -0
  27. package/dist/@types/populate-types.d.ts +54 -0
  28. package/dist/@types/populate-types.d.ts.map +1 -0
  29. package/dist/@types/populate-types.js +9 -0
  30. package/dist/@types/populate-types.js.map +1 -0
  31. package/dist/@types/query-predicate.d.ts +74 -0
  32. package/dist/@types/query-predicate.d.ts.map +1 -0
  33. package/dist/@types/query-predicate.js +9 -0
  34. package/dist/@types/query-predicate.js.map +1 -0
  35. package/dist/@types/site-config.d.ts +212 -0
  36. package/dist/@types/site-config.d.ts.map +1 -0
  37. package/dist/@types/site-config.js +9 -0
  38. package/dist/@types/site-config.js.map +1 -0
  39. package/dist/@types/storage-types.d.ts +86 -0
  40. package/dist/@types/storage-types.d.ts.map +1 -0
  41. package/dist/@types/storage-types.js +9 -0
  42. package/dist/@types/storage-types.js.map +1 -0
  43. package/dist/@types/store-types.d.ts +134 -0
  44. package/dist/@types/store-types.d.ts.map +1 -0
  45. package/dist/@types/store-types.js +24 -0
  46. package/dist/@types/store-types.js.map +1 -0
  47. package/dist/@types/type-utils.d.ts +17 -0
  48. package/dist/@types/type-utils.d.ts.map +1 -0
  49. package/dist/@types/type-utils.js +9 -0
  50. package/dist/@types/type-utils.js.map +1 -0
  51. package/dist/auth/apply-before-read.d.ts +36 -0
  52. package/dist/auth/apply-before-read.d.ts.map +1 -0
  53. package/dist/auth/apply-before-read.js +68 -0
  54. package/dist/auth/apply-before-read.js.map +1 -0
  55. package/dist/auth/apply-before-read.test.node.d.ts +9 -0
  56. package/dist/auth/apply-before-read.test.node.d.ts.map +1 -0
  57. package/dist/auth/apply-before-read.test.node.js +144 -0
  58. package/dist/auth/apply-before-read.test.node.js.map +1 -0
  59. package/dist/auth/assert-actor-can-perform.d.ts +39 -0
  60. package/dist/auth/assert-actor-can-perform.d.ts.map +1 -0
  61. package/dist/auth/assert-actor-can-perform.js +64 -0
  62. package/dist/auth/assert-actor-can-perform.js.map +1 -0
  63. package/dist/auth/assert-actor-can-perform.test.node.d.ts +9 -0
  64. package/dist/auth/assert-actor-can-perform.test.node.d.ts.map +1 -0
  65. package/dist/auth/assert-actor-can-perform.test.node.js +119 -0
  66. package/dist/auth/assert-actor-can-perform.test.node.js.map +1 -0
  67. package/dist/auth/index.d.ts +11 -0
  68. package/dist/auth/index.d.ts.map +1 -0
  69. package/dist/auth/index.js +11 -0
  70. package/dist/auth/index.js.map +1 -0
  71. package/dist/auth/register-collection-abilities.d.ts +40 -0
  72. package/dist/auth/register-collection-abilities.d.ts.map +1 -0
  73. package/dist/auth/register-collection-abilities.js +87 -0
  74. package/dist/auth/register-collection-abilities.js.map +1 -0
  75. package/dist/auth/register-collection-abilities.test.node.d.ts +9 -0
  76. package/dist/auth/register-collection-abilities.test.node.d.ts.map +1 -0
  77. package/dist/auth/register-collection-abilities.test.node.js +124 -0
  78. package/dist/auth/register-collection-abilities.test.node.js.map +1 -0
  79. package/dist/config/config.d.ts +10 -0
  80. package/dist/config/config.d.ts.map +1 -0
  81. package/dist/config/config.js +108 -0
  82. package/dist/config/config.js.map +1 -0
  83. package/dist/config/routes.d.ts +16 -0
  84. package/dist/config/routes.d.ts.map +1 -0
  85. package/dist/config/routes.js +26 -0
  86. package/dist/config/routes.js.map +1 -0
  87. package/dist/config/validate-admin-configs.d.ts +33 -0
  88. package/dist/config/validate-admin-configs.d.ts.map +1 -0
  89. package/dist/config/validate-admin-configs.js +250 -0
  90. package/dist/config/validate-admin-configs.js.map +1 -0
  91. package/dist/config/validate-admin-configs.test.node.d.ts +9 -0
  92. package/dist/config/validate-admin-configs.test.node.d.ts.map +1 -0
  93. package/dist/config/validate-admin-configs.test.node.js +224 -0
  94. package/dist/config/validate-admin-configs.test.node.js.map +1 -0
  95. package/dist/config/validate-collections.d.ts +33 -0
  96. package/dist/config/validate-collections.d.ts.map +1 -0
  97. package/dist/config/validate-collections.js +70 -0
  98. package/dist/config/validate-collections.js.map +1 -0
  99. package/dist/config/validate-collections.test.node.d.ts +9 -0
  100. package/dist/config/validate-collections.test.node.d.ts.map +1 -0
  101. package/dist/config/validate-collections.test.node.js +149 -0
  102. package/dist/config/validate-collections.test.node.js.map +1 -0
  103. package/dist/core.d.ts +89 -0
  104. package/dist/core.d.ts.map +1 -0
  105. package/dist/core.js +99 -0
  106. package/dist/core.js.map +1 -0
  107. package/dist/defaults/default-values.d.ts +13 -0
  108. package/dist/defaults/default-values.d.ts.map +1 -0
  109. package/dist/defaults/default-values.js +60 -0
  110. package/dist/defaults/default-values.js.map +1 -0
  111. package/dist/index.d.ts +20 -0
  112. package/dist/index.d.ts.map +1 -0
  113. package/dist/index.js +36 -0
  114. package/dist/index.js.map +1 -0
  115. package/dist/lib/errors.d.ts +98 -0
  116. package/dist/lib/errors.d.ts.map +1 -0
  117. package/dist/lib/errors.js +134 -0
  118. package/dist/lib/errors.js.map +1 -0
  119. package/dist/lib/logger.d.ts +62 -0
  120. package/dist/lib/logger.d.ts.map +1 -0
  121. package/dist/lib/logger.js +120 -0
  122. package/dist/lib/logger.js.map +1 -0
  123. package/dist/lib/registry.d.ts +65 -0
  124. package/dist/lib/registry.d.ts.map +1 -0
  125. package/dist/lib/registry.js +133 -0
  126. package/dist/lib/registry.js.map +1 -0
  127. package/dist/logger/index.d.ts +3 -0
  128. package/dist/logger/index.d.ts.map +1 -0
  129. package/dist/logger/index.js +3 -0
  130. package/dist/logger/index.js.map +1 -0
  131. package/dist/patches/apply-patches.d.ts +21 -0
  132. package/dist/patches/apply-patches.d.ts.map +1 -0
  133. package/dist/patches/apply-patches.js +357 -0
  134. package/dist/patches/apply-patches.js.map +1 -0
  135. package/dist/patches/index.d.ts +3 -0
  136. package/dist/patches/index.d.ts.map +1 -0
  137. package/dist/patches/index.js +4 -0
  138. package/dist/patches/index.js.map +1 -0
  139. package/dist/patches/patch-types.d.ts +82 -0
  140. package/dist/patches/patch-types.d.ts.map +1 -0
  141. package/dist/patches/patch-types.js +3 -0
  142. package/dist/patches/patch-types.js.map +1 -0
  143. package/dist/patches/patch.test.node.d.ts +2 -0
  144. package/dist/patches/patch.test.node.d.ts.map +1 -0
  145. package/dist/patches/patch.test.node.js +193 -0
  146. package/dist/patches/patch.test.node.js.map +1 -0
  147. package/dist/query/parse-where.d.ts +100 -0
  148. package/dist/query/parse-where.d.ts.map +1 -0
  149. package/dist/query/parse-where.js +352 -0
  150. package/dist/query/parse-where.js.map +1 -0
  151. package/dist/query/parse-where.test.node.d.ts +9 -0
  152. package/dist/query/parse-where.test.node.d.ts.map +1 -0
  153. package/dist/query/parse-where.test.node.js +581 -0
  154. package/dist/query/parse-where.test.node.js.map +1 -0
  155. package/dist/schemas/zod/builder.d.ts +466 -0
  156. package/dist/schemas/zod/builder.d.ts.map +1 -0
  157. package/dist/schemas/zod/builder.js +276 -0
  158. package/dist/schemas/zod/builder.js.map +1 -0
  159. package/dist/schemas/zod/cache.d.ts +14 -0
  160. package/dist/schemas/zod/cache.d.ts.map +1 -0
  161. package/dist/schemas/zod/cache.js +40 -0
  162. package/dist/schemas/zod/cache.js.map +1 -0
  163. package/dist/schemas/zod/index.d.ts +4 -0
  164. package/dist/schemas/zod/index.d.ts.map +1 -0
  165. package/dist/schemas/zod/index.js +4 -0
  166. package/dist/schemas/zod/index.js.map +1 -0
  167. package/dist/schemas/zod/types.d.ts +13 -0
  168. package/dist/schemas/zod/types.d.ts.map +1 -0
  169. package/dist/schemas/zod/types.js +2 -0
  170. package/dist/schemas/zod/types.js.map +1 -0
  171. package/dist/services/collection-bootstrap.d.ts +46 -0
  172. package/dist/services/collection-bootstrap.d.ts.map +1 -0
  173. package/dist/services/collection-bootstrap.js +108 -0
  174. package/dist/services/collection-bootstrap.js.map +1 -0
  175. package/dist/services/collection-bootstrap.test.node.d.ts +9 -0
  176. package/dist/services/collection-bootstrap.test.node.d.ts.map +1 -0
  177. package/dist/services/collection-bootstrap.test.node.js +208 -0
  178. package/dist/services/collection-bootstrap.test.node.js.map +1 -0
  179. package/dist/services/document-lifecycle.d.ts +245 -0
  180. package/dist/services/document-lifecycle.d.ts.map +1 -0
  181. package/dist/services/document-lifecycle.js +481 -0
  182. package/dist/services/document-lifecycle.js.map +1 -0
  183. package/dist/services/document-lifecycle.test.node.d.ts +9 -0
  184. package/dist/services/document-lifecycle.test.node.d.ts.map +1 -0
  185. package/dist/services/document-lifecycle.test.node.js +781 -0
  186. package/dist/services/document-lifecycle.test.node.js.map +1 -0
  187. package/dist/services/document-read.d.ts +26 -0
  188. package/dist/services/document-read.d.ts.map +1 -0
  189. package/dist/services/document-read.js +60 -0
  190. package/dist/services/document-read.js.map +1 -0
  191. package/dist/services/field-upload.d.ts +100 -0
  192. package/dist/services/field-upload.d.ts.map +1 -0
  193. package/dist/services/field-upload.js +328 -0
  194. package/dist/services/field-upload.js.map +1 -0
  195. package/dist/services/field-upload.test.node.d.ts +9 -0
  196. package/dist/services/field-upload.test.node.d.ts.map +1 -0
  197. package/dist/services/field-upload.test.node.js +337 -0
  198. package/dist/services/field-upload.test.node.js.map +1 -0
  199. package/dist/services/index.d.ts +10 -0
  200. package/dist/services/index.d.ts.map +1 -0
  201. package/dist/services/index.js +11 -0
  202. package/dist/services/index.js.map +1 -0
  203. package/dist/services/populate.d.ts +299 -0
  204. package/dist/services/populate.d.ts.map +1 -0
  205. package/dist/services/populate.js +484 -0
  206. package/dist/services/populate.js.map +1 -0
  207. package/dist/services/populate.test.node.d.ts +9 -0
  208. package/dist/services/populate.test.node.d.ts.map +1 -0
  209. package/dist/services/populate.test.node.js +910 -0
  210. package/dist/services/populate.test.node.js.map +1 -0
  211. package/dist/services/relation-projection.d.ts +52 -0
  212. package/dist/services/relation-projection.d.ts.map +1 -0
  213. package/dist/services/relation-projection.js +81 -0
  214. package/dist/services/relation-projection.js.map +1 -0
  215. package/dist/services/richtext-populate.d.ts +87 -0
  216. package/dist/services/richtext-populate.d.ts.map +1 -0
  217. package/dist/services/richtext-populate.js +189 -0
  218. package/dist/services/richtext-populate.js.map +1 -0
  219. package/dist/services/richtext-populate.test.node.d.ts +9 -0
  220. package/dist/services/richtext-populate.test.node.d.ts.map +1 -0
  221. package/dist/services/richtext-populate.test.node.js +197 -0
  222. package/dist/services/richtext-populate.test.node.js.map +1 -0
  223. package/dist/storage/collection-fingerprint.d.ts +21 -0
  224. package/dist/storage/collection-fingerprint.d.ts.map +1 -0
  225. package/dist/storage/collection-fingerprint.js +172 -0
  226. package/dist/storage/collection-fingerprint.js.map +1 -0
  227. package/dist/storage/collection-fingerprint.test.node.d.ts +9 -0
  228. package/dist/storage/collection-fingerprint.test.node.d.ts.map +1 -0
  229. package/dist/storage/collection-fingerprint.test.node.js +256 -0
  230. package/dist/storage/collection-fingerprint.test.node.js.map +1 -0
  231. package/dist/storage/field-store-map.d.ts +59 -0
  232. package/dist/storage/field-store-map.d.ts.map +1 -0
  233. package/dist/storage/field-store-map.js +75 -0
  234. package/dist/storage/field-store-map.js.map +1 -0
  235. package/dist/storage/field-store-map.test.node.d.ts +9 -0
  236. package/dist/storage/field-store-map.test.node.d.ts.map +1 -0
  237. package/dist/storage/field-store-map.test.node.js +117 -0
  238. package/dist/storage/field-store-map.test.node.js.map +1 -0
  239. package/dist/storage/index.d.ts +10 -0
  240. package/dist/storage/index.d.ts.map +1 -0
  241. package/dist/storage/index.js +10 -0
  242. package/dist/storage/index.js.map +1 -0
  243. package/dist/utils/normalise-dates.d.ts +15 -0
  244. package/dist/utils/normalise-dates.d.ts.map +1 -0
  245. package/dist/utils/normalise-dates.js +22 -0
  246. package/dist/utils/normalise-dates.js.map +1 -0
  247. package/dist/utils/slugify.d.ts +56 -0
  248. package/dist/utils/slugify.d.ts.map +1 -0
  249. package/dist/utils/slugify.js +91 -0
  250. package/dist/utils/slugify.js.map +1 -0
  251. package/dist/utils/slugify.test.node.d.ts +9 -0
  252. package/dist/utils/slugify.test.node.d.ts.map +1 -0
  253. package/dist/utils/slugify.test.node.js +86 -0
  254. package/dist/utils/slugify.test.node.js.map +1 -0
  255. package/dist/utils/storage-utils.d.ts +36 -0
  256. package/dist/utils/storage-utils.d.ts.map +1 -0
  257. package/dist/utils/storage-utils.js +38 -0
  258. package/dist/utils/storage-utils.js.map +1 -0
  259. package/dist/utils/utils.general.d.ts +64 -0
  260. package/dist/utils/utils.general.d.ts.map +1 -0
  261. package/dist/utils/utils.general.js +219 -0
  262. package/dist/utils/utils.general.js.map +1 -0
  263. package/dist/validation/index.d.ts +9 -0
  264. package/dist/validation/index.d.ts.map +1 -0
  265. package/dist/validation/index.js +9 -0
  266. package/dist/validation/index.js.map +1 -0
  267. package/dist/validation/shared.d.ts +36 -0
  268. package/dist/validation/shared.d.ts.map +1 -0
  269. package/dist/validation/shared.js +42 -0
  270. package/dist/validation/shared.js.map +1 -0
  271. package/dist/workflow/index.d.ts +2 -0
  272. package/dist/workflow/index.d.ts.map +1 -0
  273. package/dist/workflow/index.js +3 -0
  274. package/dist/workflow/index.js.map +1 -0
  275. package/dist/workflow/workflow.d.ts +40 -0
  276. package/dist/workflow/workflow.d.ts.map +1 -0
  277. package/dist/workflow/workflow.js +96 -0
  278. package/dist/workflow/workflow.js.map +1 -0
  279. package/dist/workflow/workflow.test.node.d.ts +2 -0
  280. package/dist/workflow/workflow.test.node.d.ts.map +1 -0
  281. package/dist/workflow/workflow.test.node.js +198 -0
  282. package/dist/workflow/workflow.test.node.js.map +1 -0
  283. package/package.json +88 -0
@@ -0,0 +1,98 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ *
8
+ * Structured error handling for Byline CMS.
9
+ *
10
+ * Follows the Modulus CoreError pattern: every error carries a machine-readable
11
+ * `code`, optional `details` (included in API responses), and optional `logExtra`
12
+ * (included only in logs). The `.log(logger)` method logs the error exactly once
13
+ * and then sets the log level to 'silent' to prevent double-logging up the stack.
14
+ *
15
+ * Errors are created via factory functions produced by `createErrorType()`:
16
+ *
17
+ * throw ERR_NOT_FOUND({
18
+ * message: 'document not found',
19
+ * details: { documentId },
20
+ * }).log(logger)
21
+ */
22
+ import type { BylineLogger, LogLevel, LogLevelWithSilent } from './logger.js';
23
+ export type ErrorReport = {
24
+ code: string;
25
+ message: string;
26
+ details?: Record<string, unknown>;
27
+ };
28
+ export type BylineErrorOptions = {
29
+ /** Short description of the error, for internal consumption. */
30
+ message: string;
31
+ /** Optional underlying cause (e.g. a 3rd-party error). */
32
+ cause?: unknown;
33
+ /** Details to be included in the error report (API responses) AND logs. */
34
+ details?: Record<string, unknown>;
35
+ /** If true, stack trace will be captured. */
36
+ captureStack?: boolean;
37
+ /** Log level for this error. Defaults to 'error'. */
38
+ logLevel?: LogLevelWithSilent;
39
+ /** Extra data to include only in logs (never in API responses). */
40
+ logExtra?: Record<string, unknown>;
41
+ };
42
+ export declare class BylineError extends Error {
43
+ /** Machine-readable error code (e.g. 'ERR_NOT_FOUND'). */
44
+ readonly code: string;
45
+ /** Additional details included in both error reports and logs. */
46
+ readonly details?: Record<string, unknown>;
47
+ /** Extra values included only when logging this error. */
48
+ readonly logExtra?: Record<string, unknown>;
49
+ /**
50
+ * Level at which this error should be logged when caught. Will always be
51
+ * 'silent' after `.log()` has been called.
52
+ */
53
+ private logLevel;
54
+ constructor(code: string, options: BylineErrorOptions, errorConstructor?: any);
55
+ /**
56
+ * Log this error via the given logger. Sets `logLevel` to 'silent' after
57
+ * the first call to prevent double-logging when the error is re-thrown.
58
+ *
59
+ * Returns `this` for chaining: `throw ERR_X({ ... }).log(logger)`
60
+ */
61
+ log(logger: BylineLogger): typeof this;
62
+ /**
63
+ * Serialize this error for API responses. Includes `code`, `message`,
64
+ * and `details` but deliberately excludes `logExtra`.
65
+ */
66
+ report(): ErrorReport;
67
+ }
68
+ /**
69
+ * Create a reusable error factory for a given error code and default log level.
70
+ *
71
+ * ```ts
72
+ * export const ERR_NOT_FOUND = createErrorType('ERR_NOT_FOUND', 'warn')
73
+ *
74
+ * throw ERR_NOT_FOUND({ message: 'document not found' }).log(logger)
75
+ * ```
76
+ */
77
+ export declare const createErrorType: (code: string, logLevel?: LogLevel) => (opts: BylineErrorOptions, errorConstructor?: any) => BylineError;
78
+ export declare const ErrorCodes: {
79
+ readonly UNHANDLED: "ERR_UNHANDLED";
80
+ readonly NOT_FOUND: "ERR_NOT_FOUND";
81
+ readonly CONFLICT: "ERR_CONFLICT";
82
+ readonly VALIDATION: "ERR_VALIDATION";
83
+ readonly INVALID_TRANSITION: "ERR_INVALID_TRANSITION";
84
+ readonly PATCH_FAILED: "ERR_PATCH_FAILED";
85
+ readonly DATABASE: "ERR_DATABASE";
86
+ readonly STORAGE: "ERR_STORAGE";
87
+ readonly READ_BUDGET_EXCEEDED: "ERR_READ_BUDGET_EXCEEDED";
88
+ };
89
+ export declare const ERR_UNHANDLED: (opts: BylineErrorOptions, errorConstructor?: any) => BylineError;
90
+ export declare const ERR_NOT_FOUND: (opts: BylineErrorOptions, errorConstructor?: any) => BylineError;
91
+ export declare const ERR_CONFLICT: (opts: BylineErrorOptions, errorConstructor?: any) => BylineError;
92
+ export declare const ERR_VALIDATION: (opts: BylineErrorOptions, errorConstructor?: any) => BylineError;
93
+ export declare const ERR_INVALID_TRANSITION: (opts: BylineErrorOptions, errorConstructor?: any) => BylineError;
94
+ export declare const ERR_PATCH_FAILED: (opts: BylineErrorOptions, errorConstructor?: any) => BylineError;
95
+ export declare const ERR_DATABASE: (opts: BylineErrorOptions, errorConstructor?: any) => BylineError;
96
+ export declare const ERR_STORAGE: (opts: BylineErrorOptions, errorConstructor?: any) => BylineError;
97
+ export declare const ERR_READ_BUDGET_EXCEEDED: (opts: BylineErrorOptions, errorConstructor?: any) => BylineError;
98
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAM7E,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAA;IACf,0DAA0D;IAC1D,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EA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SA7Bb,kBAAkB,qBAAqB,GAAG,gBA6B4B,CAAA;AAC5F,eAAO,MAAM,gBAAgB,SA9BP,kBAAkB,qBAAqB,GAAG,gBA8BQ,CAAA;AACxE,eAAO,MAAM,YAAY,SA/BH,kBAAkB,qBAAqB,GAAG,gBA+BA,CAAA;AAChE,eAAO,MAAM,WAAW,SAhCF,kBAAkB,qBAAqB,GAAG,gBAgCF,CAAA;AAC9D,eAAO,MAAM,wBAAwB,SAjCf,kBAAkB,qBAAqB,GAAG,gBAiCwB,CAAA"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ *
8
+ * Structured error handling for Byline CMS.
9
+ *
10
+ * Follows the Modulus CoreError pattern: every error carries a machine-readable
11
+ * `code`, optional `details` (included in API responses), and optional `logExtra`
12
+ * (included only in logs). The `.log(logger)` method logs the error exactly once
13
+ * and then sets the log level to 'silent' to prevent double-logging up the stack.
14
+ *
15
+ * Errors are created via factory functions produced by `createErrorType()`:
16
+ *
17
+ * throw ERR_NOT_FOUND({
18
+ * message: 'document not found',
19
+ * details: { documentId },
20
+ * }).log(logger)
21
+ */
22
+ // ---------------------------------------------------------------------------
23
+ // BylineError base class
24
+ // ---------------------------------------------------------------------------
25
+ export class BylineError extends Error {
26
+ /** Machine-readable error code (e.g. 'ERR_NOT_FOUND'). */
27
+ code;
28
+ /** Additional details included in both error reports and logs. */
29
+ details;
30
+ /** Extra values included only when logging this error. */
31
+ logExtra;
32
+ /**
33
+ * Level at which this error should be logged when caught. Will always be
34
+ * 'silent' after `.log()` has been called.
35
+ */
36
+ logLevel;
37
+ constructor(code, options, errorConstructor) {
38
+ const { message, cause, details, captureStack = false, logLevel = 'error', logExtra } = options;
39
+ // If Error.captureStackTrace is available, skip the default stack trace
40
+ // generation (which would happen during the call to super()), and then
41
+ // explicitly capture a stack trace _if_ captureStack is true _and_
42
+ // logLevel is not 'silent'.
43
+ if ('captureStackTrace' in Error) {
44
+ const { stackTraceLimit } = Error;
45
+ Error.stackTraceLimit = 0;
46
+ super(message, { cause });
47
+ Error.stackTraceLimit = stackTraceLimit;
48
+ if (captureStack && logLevel !== 'silent') {
49
+ Error.captureStackTrace(this, errorConstructor ?? this.constructor);
50
+ }
51
+ }
52
+ else {
53
+ super(message, { cause });
54
+ }
55
+ this.code = code;
56
+ this.details = details;
57
+ this.logExtra = logExtra;
58
+ this.logLevel = logLevel;
59
+ // Mark these properties as non-enumerable so Pino doesn't serialize them
60
+ // as part of the error object itself.
61
+ Object.defineProperties(this, {
62
+ details: { enumerable: false },
63
+ logLevel: { enumerable: false },
64
+ logExtra: { enumerable: false },
65
+ });
66
+ }
67
+ /**
68
+ * Log this error via the given logger. Sets `logLevel` to 'silent' after
69
+ * the first call to prevent double-logging when the error is re-thrown.
70
+ *
71
+ * Returns `this` for chaining: `throw ERR_X({ ... }).log(logger)`
72
+ */
73
+ log(logger) {
74
+ if (this.logLevel !== 'silent') {
75
+ logger.log(this.logLevel, { err: this, ...this.details, ...this.logExtra });
76
+ this.logLevel = 'silent';
77
+ }
78
+ return this;
79
+ }
80
+ /**
81
+ * Serialize this error for API responses. Includes `code`, `message`,
82
+ * and `details` but deliberately excludes `logExtra`.
83
+ */
84
+ report() {
85
+ return {
86
+ code: this.code,
87
+ message: this.message,
88
+ details: this.details,
89
+ };
90
+ }
91
+ }
92
+ // ---------------------------------------------------------------------------
93
+ // Factory
94
+ // ---------------------------------------------------------------------------
95
+ /**
96
+ * Create a reusable error factory for a given error code and default log level.
97
+ *
98
+ * ```ts
99
+ * export const ERR_NOT_FOUND = createErrorType('ERR_NOT_FOUND', 'warn')
100
+ *
101
+ * throw ERR_NOT_FOUND({ message: 'document not found' }).log(logger)
102
+ * ```
103
+ */
104
+ export const createErrorType = (code, logLevel = 'error') => {
105
+ const cons = (opts, errorConstructor) => new BylineError(code, { logLevel, ...opts }, errorConstructor ?? cons);
106
+ return cons;
107
+ };
108
+ // ---------------------------------------------------------------------------
109
+ // Error codes
110
+ // ---------------------------------------------------------------------------
111
+ export const ErrorCodes = {
112
+ UNHANDLED: 'ERR_UNHANDLED',
113
+ NOT_FOUND: 'ERR_NOT_FOUND',
114
+ CONFLICT: 'ERR_CONFLICT',
115
+ VALIDATION: 'ERR_VALIDATION',
116
+ INVALID_TRANSITION: 'ERR_INVALID_TRANSITION',
117
+ PATCH_FAILED: 'ERR_PATCH_FAILED',
118
+ DATABASE: 'ERR_DATABASE',
119
+ STORAGE: 'ERR_STORAGE',
120
+ READ_BUDGET_EXCEEDED: 'ERR_READ_BUDGET_EXCEEDED',
121
+ };
122
+ // ---------------------------------------------------------------------------
123
+ // Pre-instantiated factories
124
+ // ---------------------------------------------------------------------------
125
+ export const ERR_UNHANDLED = createErrorType(ErrorCodes.UNHANDLED);
126
+ export const ERR_NOT_FOUND = createErrorType(ErrorCodes.NOT_FOUND, 'warn');
127
+ export const ERR_CONFLICT = createErrorType(ErrorCodes.CONFLICT, 'warn');
128
+ export const ERR_VALIDATION = createErrorType(ErrorCodes.VALIDATION, 'warn');
129
+ export const ERR_INVALID_TRANSITION = createErrorType(ErrorCodes.INVALID_TRANSITION, 'warn');
130
+ export const ERR_PATCH_FAILED = createErrorType(ErrorCodes.PATCH_FAILED);
131
+ export const ERR_DATABASE = createErrorType(ErrorCodes.DATABASE);
132
+ export const ERR_STORAGE = createErrorType(ErrorCodes.STORAGE);
133
+ export const ERR_READ_BUDGET_EXCEEDED = createErrorType(ErrorCodes.READ_BUDGET_EXCEEDED);
134
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AA6BH,8EAA8E;AAC9E,yBAAyB;AACzB,8EAA8E;AAE9E,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AAc;IACxB,OAAO,EAAE,aAAa;IACtB,oBAAoB,EAAE,0BAA0B;CACxC,CAAA;AAEV,8EAA8E;AAC9E,6BAA6B;AAC7B,8EAA8E;AAE9E,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;AAClE,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;AAC1E,MAAM,CAAC,MAAM,YAAY,GAAG,eAAe,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;AACxE,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;AAC5E,MAAM,CAAC,MAAM,sBAAsB,GAAG,eAAe,CAAC,UAAU,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAA;AAC5F,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAC,UAAU,CAAC,YAAY,CAAC,CAAA;AACxE,MAAM,CAAC,MAAM,YAAY,GAAG,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;AAChE,MAAM,CAAC,MAAM,WAAW,GAAG,eAAe,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;AAC9D,MAAM,CAAC,MAAM,wBAAwB,GAAG,eAAe,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAA"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ *
8
+ * Structured logging for Byline CMS.
9
+ *
10
+ * ## Architecture
11
+ *
12
+ * This module defines two layers:
13
+ *
14
+ * 1. **Transport-agnostic interface** — `BylineLogger`, `LogLevel`, `LogData`,
15
+ * `LogContext`, `withLogContext`. These have zero dependency on any logging
16
+ * library. All consumer code (services, db adapters, route handlers, errors)
17
+ * depends only on this layer.
18
+ *
19
+ * 2. **Pino transport** — `createBylineLogger` + `BylineLoggerImpl`. This is
20
+ * the default implementation registered in the DI graph via `core.ts`. To
21
+ * swap transports (e.g. for Cloudflare Workers or edge runtimes), provide a
22
+ * different factory that produces a `BylineLogger` and register it in the
23
+ * Registry instead of `createBylineLogger`.
24
+ *
25
+ * Context propagation uses `AsyncLocalStorage` (Node/Bun/Deno/Workers) with a
26
+ * no-op fallback for environments that don't support it (browser bundles).
27
+ * When TC39 `AsyncContext` reaches Stage 3+, this can be swapped transparently.
28
+ *
29
+ * Primary access is via the typed Registry (see core.ts). A globalThis
30
+ * singleton (defineLogger / getLogger) provides an escape hatch for code
31
+ * outside the DI graph (e.g. API route handlers, db adapters).
32
+ */
33
+ import type { Logger as PinoLogger } from 'pino';
34
+ export interface LogContext {
35
+ domain?: string;
36
+ module?: string;
37
+ class?: string;
38
+ function?: string;
39
+ }
40
+ export declare const getLogContext: () => LogContext;
41
+ export declare const withLogContext: <T>(context: LogContext, fn: () => T) => T;
42
+ export type LogLevel = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
43
+ export type LogLevelWithSilent = LogLevel | 'silent';
44
+ export type LogData = Record<string, unknown>;
45
+ type LogFnArgs = [message: string, ...args: unknown[]] | [data: LogData, message?: string, ...args: unknown[]];
46
+ export interface BylineLogger {
47
+ log(level: LogLevel, ...args: LogFnArgs): void;
48
+ fatal(...args: LogFnArgs): void;
49
+ error(...args: LogFnArgs): void;
50
+ warn(...args: LogFnArgs): void;
51
+ info(...args: LogFnArgs): void;
52
+ debug(...args: LogFnArgs): void;
53
+ trace(...args: LogFnArgs): void;
54
+ silent(...args: LogFnArgs): void;
55
+ }
56
+ export declare const createBylineLogger: (deps: {
57
+ pinoLogger: PinoLogger;
58
+ }) => BylineLogger;
59
+ export declare function defineLogger(logger: BylineLogger): void;
60
+ export declare function getLogger(): BylineLogger;
61
+ export {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AAC,GAAG,IAAI,EAAE,SAAS,GAAG,IAAI,CAAA;IAC9B,IAAI,CAAC,GAAG,IAAI,EAAE,SAAS,GAAG,IAAI,CAAA;IAC9B,KAAK,CAAC,GAAG,IAAI,EAAE,SAAS,GAAG,IAAI,CAAA;IAC/B,KAAK,CAAC,GAAG,IAAI,EAAE,SAAS,GAAG,IAAI,CAAA;IAC/B,MAAM,CAAC,GAAG,IAAI,EAAE,SAAS,GAAG,IAAI,CAAA;CACjC;AAWD,eAAO,MAAM,kBAAkB,GAAI,MAAM;IAAE,UAAU,EAAE,UAAU,CAAA;CAAE,KAAG,YAErE,CAAA;AAyDD,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,QAEhD;AAED,wBAAgB,SAAS,IAAI,YAAY,CAQxC"}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ *
8
+ * Structured logging for Byline CMS.
9
+ *
10
+ * ## Architecture
11
+ *
12
+ * This module defines two layers:
13
+ *
14
+ * 1. **Transport-agnostic interface** — `BylineLogger`, `LogLevel`, `LogData`,
15
+ * `LogContext`, `withLogContext`. These have zero dependency on any logging
16
+ * library. All consumer code (services, db adapters, route handlers, errors)
17
+ * depends only on this layer.
18
+ *
19
+ * 2. **Pino transport** — `createBylineLogger` + `BylineLoggerImpl`. This is
20
+ * the default implementation registered in the DI graph via `core.ts`. To
21
+ * swap transports (e.g. for Cloudflare Workers or edge runtimes), provide a
22
+ * different factory that produces a `BylineLogger` and register it in the
23
+ * Registry instead of `createBylineLogger`.
24
+ *
25
+ * Context propagation uses `AsyncLocalStorage` (Node/Bun/Deno/Workers) with a
26
+ * no-op fallback for environments that don't support it (browser bundles).
27
+ * When TC39 `AsyncContext` reaches Stage 3+, this can be swapped transparently.
28
+ *
29
+ * Primary access is via the typed Registry (see core.ts). A globalThis
30
+ * singleton (defineLogger / getLogger) provides an escape hatch for code
31
+ * outside the DI graph (e.g. API route handlers, db adapters).
32
+ */
33
+ const noopStore = {
34
+ getStore: () => undefined,
35
+ run: (_store, fn) => fn(),
36
+ };
37
+ let logContextStore;
38
+ try {
39
+ const { AsyncLocalStorage } = await import('node:async_hooks');
40
+ logContextStore = new AsyncLocalStorage();
41
+ }
42
+ catch {
43
+ logContextStore = noopStore;
44
+ }
45
+ export const getLogContext = () => logContextStore.getStore() ?? {};
46
+ export const withLogContext = (context, fn) => {
47
+ return logContextStore.run({ ...getLogContext(), ...context }, fn);
48
+ };
49
+ // ---------------------------------------------------------------------------
50
+ // Pino transport (swappable — see module docblock)
51
+ //
52
+ // Everything below this line depends on pino. To use a different logging
53
+ // backend, replace `createBylineLogger` with a factory that accepts your
54
+ // transport and returns a `BylineLogger`. Register it in the DI graph
55
+ // (core.ts) instead of the default.
56
+ // ---------------------------------------------------------------------------
57
+ export const createBylineLogger = (deps) => {
58
+ return new BylineLoggerImpl(deps.pinoLogger);
59
+ };
60
+ class BylineLoggerImpl {
61
+ pinoLogger;
62
+ constructor(pinoLogger) {
63
+ this.pinoLogger = pinoLogger;
64
+ }
65
+ log(level, ...[first, second, ...rest]) {
66
+ if (typeof first === 'string') {
67
+ // args have shape [string, ...unknown[]]
68
+ this.pinoLogger[level](getLogContext(), first, second, ...rest);
69
+ }
70
+ else {
71
+ // Treat err field specially if present. Other values, if present, go
72
+ // into extra.
73
+ const { err, ...data } = first;
74
+ const extra = Object.keys(data).length > 0 ? data : undefined;
75
+ if (typeof second === 'string') {
76
+ // args have shape [LogData, string, ...unknown[]]
77
+ this.pinoLogger[level]({ ...getLogContext(), extra, err }, second, ...rest);
78
+ }
79
+ else {
80
+ // args have shape [LogData]
81
+ this.pinoLogger[level]({ ...getLogContext(), extra, err });
82
+ }
83
+ }
84
+ }
85
+ fatal(...args) {
86
+ this.log('fatal', ...args);
87
+ }
88
+ error(...args) {
89
+ this.log('error', ...args);
90
+ }
91
+ warn(...args) {
92
+ this.log('warn', ...args);
93
+ }
94
+ info(...args) {
95
+ this.log('info', ...args);
96
+ }
97
+ debug(...args) {
98
+ this.log('debug', ...args);
99
+ }
100
+ trace(...args) {
101
+ this.log('trace', ...args);
102
+ }
103
+ silent(..._args) { }
104
+ }
105
+ // ---------------------------------------------------------------------------
106
+ // Global escape hatch — same pattern as defineServerConfig / getServerConfig
107
+ // ---------------------------------------------------------------------------
108
+ const BYLINE_LOGGER = Symbol.for('__byline_logger__');
109
+ export function defineLogger(logger) {
110
+ ;
111
+ globalThis[BYLINE_LOGGER] = logger;
112
+ }
113
+ export function getLogger() {
114
+ const logger = globalThis[BYLINE_LOGGER];
115
+ if (logger == null) {
116
+ throw new Error('Byline logger has not been initialized. Ensure initBylineCore() has been called.');
117
+ }
118
+ return logger;
119
+ }
120
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AA2BH,MAAM,SAAS,GAA0B;IACvC,QAAQ,EAAE,GAAG,EAAE,CAAC,SAAS;IACzB,GAAG,EAAE,CAAI,MAAkB,EAAE,EAAW,EAAE,EAAE,CAAC,EAAE,EAAE;CAClD,CAAA;AAED,IAAI,eAAsC,CAAA;AAE1C,IAAI,CAAC;IACH,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAA;IAC9D,eAAe,GAAG,IAAI,iBAAiB,EAAc,CAAA;AACvD,CAAC;AAAC,MAAM,CAAC;IACP,eAAe,GAAG,SAAS,CAAA;AAC7B,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE,CAAC,eAAe,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAA;AACnE,MAAM,CAAC,MAAM,cAAc,GAAG,CA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,IAAI,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CACb,kFAAkF,CACnF,CAAA;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ *
8
+ * Typed dependency injection registry. Ported from the Modulus project
9
+ * (https://github.com/infonomic/modulus) with permission.
10
+ *
11
+ * Provides compile-time validation of dependency graphs via TypeScript
12
+ * conditional types. Services declare their dependencies via constructor
13
+ * or factory signatures; the registry validates that all requirements
14
+ * are satisfied before composition.
15
+ */
16
+ type Token = string | symbol;
17
+ type Normalize<T> = T extends object ? {
18
+ [P in keyof T]: T[P];
19
+ } : never;
20
+ type Extend<TSource extends object, TName extends Token, TValue> = Normalize<Omit<TSource, TName> & {
21
+ [K in TName]: TValue;
22
+ }>;
23
+ type IsNever<T> = [T] extends [never] ? true : false;
24
+ type IsMergeable<T1, T2> = {
25
+ [K in keyof T1 & keyof T2]: IsNever<T1[K] & T2[K]> extends true ? false : true;
26
+ } extends Record<keyof T1 & keyof T2, true> ? true : false;
27
+ type ValidateDeps<TRequires, TProvides, TName, TDeps> = TName extends keyof TRequires ? {
28
+ error: 'Name conflict with prior requirement';
29
+ name: TName;
30
+ requirements: TRequires;
31
+ } : TName extends keyof TProvides ? {
32
+ error: 'Duplicate provider name';
33
+ name: TName;
34
+ } : Pick<TProvides, keyof TProvides & keyof TDeps> extends Pick<TDeps, keyof TProvides & keyof TDeps> ? IsMergeable<Pick<Omit<TDeps, keyof TProvides>, Extract<keyof TRequires, keyof Omit<TDeps, keyof TProvides>>>, Pick<TRequires, Extract<keyof TRequires, keyof Omit<TDeps, keyof TProvides>>>> extends true ? true : {
35
+ error: 'Dependency type conflicts with required type';
36
+ deps: TDeps;
37
+ requirements: TRequires;
38
+ } : {
39
+ error: 'Dependency type conflicts with provided type';
40
+ deps: TDeps;
41
+ provides: TProvides;
42
+ };
43
+ export declare class Registry<TRequires extends Record<Token, unknown> = {}, TProvides extends Record<Token, unknown> = {}> {
44
+ private readonly providers;
45
+ addClass<Name extends Token, TClass extends new (deps: any) => any, TValidation extends ValidateDeps<TRequires, TProvides, Name, ConstructorParameters<TClass>[0]> = ValidateDeps<TRequires, TProvides, Name, ConstructorParameters<TClass>[0]>>(name: Name, value: TValidation extends true ? TClass : TValidation): Registry<Normalize<TRequires & Omit<ConstructorParameters<TClass>[0], keyof TProvides>>, Extend<TProvides, Name, InstanceType<TClass>>>;
46
+ addFactory<Name extends Token, TFactory extends (deps: any) => any, TValidation extends ValidateDeps<TRequires, TProvides, Name, Parameters<TFactory>[0]> = ValidateDeps<TRequires, TProvides, Name, Parameters<TFactory>[0]>>(name: Name, value: TValidation extends true ? TFactory : TValidation): Registry<Normalize<TRequires & Omit<Parameters<TFactory>[0], keyof TProvides>>, Extend<TProvides, Name, ReturnType<TFactory>>>;
47
+ addValue<Name extends Token, TValue, TValidation extends ValidateDeps<TRequires, TProvides, Name, {}> = ValidateDeps<TRequires, TProvides, Name, {}>>(name: Name, value: TValidation extends true ? TValue : TValidation): Registry<TRequires, Extend<TProvides, Name, TValue>>;
48
+ addNested<Name extends Token, TNested extends Registry<any, any>, TValidation extends ValidateDeps<TRequires, TProvides, Name, TNested extends Registry<infer TNestedRequired, any> ? TNestedRequired : never> = ValidateDeps<TRequires, TProvides, Name, TNested extends Registry<infer TNestedRequired, any> ? TNestedRequired : never>>(name: Name, nested: TValidation extends true ? TNested : TValidation): TNested extends Registry<infer TNestedRequires, infer TNestedProvides> ? Registry<Normalize<TRequires & Omit<TNestedRequires, keyof TProvides>>, Extend<TProvides, Name, TNestedProvides>> : never;
49
+ compose(requirements: TRequires): Normalize<TProvides>;
50
+ }
51
+ export declare class AsyncRegistry<TRequires extends Record<Token, unknown> = {}, TProvides extends Record<Token, unknown> = {}> {
52
+ private readonly providers;
53
+ addClass<Name extends Token, TClass extends new (deps: any) => any, TValidation extends ValidateDeps<TRequires, TProvides, Name, ConstructorParameters<TClass>[0]> = ValidateDeps<TRequires, TProvides, Name, ConstructorParameters<TClass>[0]>>(name: Name, value: TValidation extends true ? TClass : TValidation): AsyncRegistry<Normalize<TRequires & Omit<ConstructorParameters<TClass>[0], keyof TProvides>>, Extend<TProvides, Name, InstanceType<TClass>>>;
54
+ addAsyncClass<Name extends Token, TClass extends {
55
+ create(deps: any): Promise<any>;
56
+ }, TValidation extends ValidateDeps<TRequires, TProvides, Name, Parameters<TClass['create']>[0]> = ValidateDeps<TRequires, TProvides, Name, Parameters<TClass['create']>[0]>>(name: Name, value: TValidation extends true ? TClass : TValidation): AsyncRegistry<Normalize<TRequires & Omit<Parameters<TClass['create']>[0], keyof TProvides>>, Extend<TProvides, Name, Awaited<ReturnType<TClass['create']>>>>;
57
+ addFactory<Name extends Token, TFactory extends (deps: any) => any, TValidation extends ValidateDeps<TRequires, TProvides, Name, Parameters<TFactory>[0]> = ValidateDeps<TRequires, TProvides, Name, Parameters<TFactory>[0]>>(name: Name, value: TValidation extends true ? TFactory : TValidation): AsyncRegistry<Normalize<TRequires & Omit<Parameters<TFactory>[0], keyof TProvides>>, Extend<TProvides, Name, Awaited<ReturnType<TFactory>>>>;
58
+ addValue<Name extends Token, TValue, TValidation extends ValidateDeps<TRequires, TProvides, Name, {}> = ValidateDeps<TRequires, TProvides, Name, {}>>(name: Name, value: TValidation extends true ? TValue : TValidation): AsyncRegistry<TRequires, Extend<TProvides, Name, Awaited<TValue>>>;
59
+ addNested<Name extends Token, TNested extends Registry<any, any>, TValidation extends ValidateDeps<TRequires, TProvides, Name, TNested extends Registry<infer TNestedRequired, any> ? TNestedRequired : never> = ValidateDeps<TRequires, TProvides, Name, TNested extends Registry<infer TNestedRequired, any> ? TNestedRequired : never>>(name: Name, nested: TValidation extends true ? TNested : TValidation): TNested extends Registry<infer TNestedRequires, infer TNestedProvides> ? AsyncRegistry<Normalize<TRequires & Omit<TNestedRequires, keyof TProvides>>, Extend<TProvides, Name, TNestedProvides>> : never;
60
+ addNestedAsync<Name extends Token, TNested extends AsyncRegistry<any, any>, TValidation extends ValidateDeps<TRequires, TProvides, Name, TNested extends AsyncRegistry<infer TNestedRequired, any> ? TNestedRequired : never> = ValidateDeps<TRequires, TProvides, Name, TNested extends AsyncRegistry<infer TNestedRequired, any> ? TNestedRequired : never>>(name: Name, nested: TValidation extends true ? TNested : TValidation): TNested extends AsyncRegistry<infer TNestedRequires, infer TNestedProvides> ? AsyncRegistry<Normalize<TRequires & Omit<TNestedRequires, keyof TProvides>>, Extend<TProvides, Name, TNestedProvides>> : never;
61
+ compose(requirements: TRequires): Promise<Normalize<TProvides>>;
62
+ }
63
+ export type RegisteredServices<TRegistry extends Registry<any, any> | AsyncRegistry<any, any>> = TRegistry extends Registry<any, infer TProvided> ? TProvided : TRegistry extends AsyncRegistry<any, infer TProvided> ? Normalize<TProvided> : never;
64
+ export {};
65
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/lib/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,KAAK,KAAK,GAAG,MAAM,GAAG,MAAM,CAAA;AAE5B,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,KAAK,CAAA;AAEvE,KAAK,MAAM,CAAC,OAAO,SAAS,MAAM,EAAE,KAAK,SAAS,KAAK,EAAE,MAAM,IAAI,SAAS,CAC1E,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG;KACpB,CAAC,IAAI,KAAK,GAAG,MAAM;CACrB,CACF,CAAA;AAQD,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SA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