promidas 2.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 (295) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +179 -0
  3. package/dist/builder.d.ts +158 -0
  4. package/dist/builder.d.ts.map +1 -0
  5. package/dist/builder.js +255 -0
  6. package/dist/builder.js.map +1 -0
  7. package/dist/factory.d.ts +154 -0
  8. package/dist/factory.d.ts.map +1 -0
  9. package/dist/factory.js +243 -0
  10. package/dist/factory.js.map +1 -0
  11. package/dist/fetcher/client/config.d.ts +140 -0
  12. package/dist/fetcher/client/config.d.ts.map +1 -0
  13. package/dist/fetcher/client/config.js +2 -0
  14. package/dist/fetcher/client/config.js.map +1 -0
  15. package/dist/fetcher/client/fetch-with-progress.d.ts +156 -0
  16. package/dist/fetcher/client/fetch-with-progress.d.ts.map +1 -0
  17. package/dist/fetcher/client/fetch-with-progress.js +313 -0
  18. package/dist/fetcher/client/fetch-with-progress.js.map +1 -0
  19. package/dist/fetcher/client/fetch-with-timeout.d.ts +6 -0
  20. package/dist/fetcher/client/fetch-with-timeout.d.ts.map +1 -0
  21. package/dist/fetcher/client/fetch-with-timeout.js +48 -0
  22. package/dist/fetcher/client/fetch-with-timeout.js.map +1 -0
  23. package/dist/fetcher/client/protopedia-api-custom-client.d.ts +141 -0
  24. package/dist/fetcher/client/protopedia-api-custom-client.d.ts.map +1 -0
  25. package/dist/fetcher/client/protopedia-api-custom-client.js +268 -0
  26. package/dist/fetcher/client/protopedia-api-custom-client.js.map +1 -0
  27. package/dist/fetcher/client/select-custom-fetch.d.ts +58 -0
  28. package/dist/fetcher/client/select-custom-fetch.d.ts.map +1 -0
  29. package/dist/fetcher/client/select-custom-fetch.js +58 -0
  30. package/dist/fetcher/client/select-custom-fetch.js.map +1 -0
  31. package/dist/fetcher/errors/fetcher-error.d.ts +10 -0
  32. package/dist/fetcher/errors/fetcher-error.d.ts.map +1 -0
  33. package/dist/fetcher/errors/fetcher-error.js +15 -0
  34. package/dist/fetcher/errors/fetcher-error.js.map +1 -0
  35. package/dist/fetcher/index.d.ts +73 -0
  36. package/dist/fetcher/index.d.ts.map +1 -0
  37. package/dist/fetcher/index.js +70 -0
  38. package/dist/fetcher/index.js.map +1 -0
  39. package/dist/fetcher/types/index.d.ts +9 -0
  40. package/dist/fetcher/types/index.d.ts.map +1 -0
  41. package/dist/fetcher/types/index.js +7 -0
  42. package/dist/fetcher/types/index.js.map +1 -0
  43. package/dist/fetcher/types/progress-event.types.d.ts +221 -0
  44. package/dist/fetcher/types/progress-event.types.d.ts.map +1 -0
  45. package/dist/fetcher/types/progress-event.types.js +10 -0
  46. package/dist/fetcher/types/progress-event.types.js.map +1 -0
  47. package/dist/fetcher/types/prototype-api.types.d.ts +106 -0
  48. package/dist/fetcher/types/prototype-api.types.d.ts.map +1 -0
  49. package/dist/fetcher/types/prototype-api.types.js +2 -0
  50. package/dist/fetcher/types/prototype-api.types.js.map +1 -0
  51. package/dist/fetcher/types/result.types.d.ts +75 -0
  52. package/dist/fetcher/types/result.types.d.ts.map +1 -0
  53. package/dist/fetcher/types/result.types.js +2 -0
  54. package/dist/fetcher/types/result.types.js.map +1 -0
  55. package/dist/fetcher/utils/create-client-fetch.d.ts +63 -0
  56. package/dist/fetcher/utils/create-client-fetch.d.ts.map +1 -0
  57. package/dist/fetcher/utils/create-client-fetch.js +89 -0
  58. package/dist/fetcher/utils/create-client-fetch.js.map +1 -0
  59. package/dist/fetcher/utils/create-fetch-with-stripped-headers.d.ts +6 -0
  60. package/dist/fetcher/utils/create-fetch-with-stripped-headers.d.ts.map +1 -0
  61. package/dist/fetcher/utils/create-fetch-with-stripped-headers.js +40 -0
  62. package/dist/fetcher/utils/create-fetch-with-stripped-headers.js.map +1 -0
  63. package/dist/fetcher/utils/errors/handler.d.ts +58 -0
  64. package/dist/fetcher/utils/errors/handler.d.ts.map +1 -0
  65. package/dist/fetcher/utils/errors/handler.js +243 -0
  66. package/dist/fetcher/utils/errors/handler.js.map +1 -0
  67. package/dist/fetcher/utils/errors/messages.d.ts +75 -0
  68. package/dist/fetcher/utils/errors/messages.d.ts.map +1 -0
  69. package/dist/fetcher/utils/errors/messages.js +88 -0
  70. package/dist/fetcher/utils/errors/messages.js.map +1 -0
  71. package/dist/fetcher/utils/index.d.ts +13 -0
  72. package/dist/fetcher/utils/index.d.ts.map +1 -0
  73. package/dist/fetcher/utils/index.js +12 -0
  74. package/dist/fetcher/utils/index.js.map +1 -0
  75. package/dist/fetcher/utils/log-timestamp-normalization-warnings.d.ts +10 -0
  76. package/dist/fetcher/utils/log-timestamp-normalization-warnings.d.ts.map +1 -0
  77. package/dist/fetcher/utils/log-timestamp-normalization-warnings.js +32 -0
  78. package/dist/fetcher/utils/log-timestamp-normalization-warnings.js.map +1 -0
  79. package/dist/fetcher/utils/normalize-protopedia-timestamp.d.ts +59 -0
  80. package/dist/fetcher/utils/normalize-protopedia-timestamp.d.ts.map +1 -0
  81. package/dist/fetcher/utils/normalize-protopedia-timestamp.js +81 -0
  82. package/dist/fetcher/utils/normalize-protopedia-timestamp.js.map +1 -0
  83. package/dist/fetcher/utils/normalize-prototype.d.ts +56 -0
  84. package/dist/fetcher/utils/normalize-prototype.d.ts.map +1 -0
  85. package/dist/fetcher/utils/normalize-prototype.js +113 -0
  86. package/dist/fetcher/utils/normalize-prototype.js.map +1 -0
  87. package/dist/fetcher/utils/sanitize-options.d.ts +14 -0
  88. package/dist/fetcher/utils/sanitize-options.d.ts.map +1 -0
  89. package/dist/fetcher/utils/sanitize-options.js +16 -0
  90. package/dist/fetcher/utils/sanitize-options.js.map +1 -0
  91. package/dist/fetcher/utils/string-parsers.d.ts +45 -0
  92. package/dist/fetcher/utils/string-parsers.d.ts.map +1 -0
  93. package/dist/fetcher/utils/string-parsers.js +53 -0
  94. package/dist/fetcher/utils/string-parsers.js.map +1 -0
  95. package/dist/index.d.ts +66 -0
  96. package/dist/index.d.ts.map +1 -0
  97. package/dist/index.js +70 -0
  98. package/dist/index.js.map +1 -0
  99. package/dist/logger/console-logger.d.ts +74 -0
  100. package/dist/logger/console-logger.d.ts.map +1 -0
  101. package/dist/logger/console-logger.js +113 -0
  102. package/dist/logger/console-logger.js.map +1 -0
  103. package/dist/logger/factory.d.ts +88 -0
  104. package/dist/logger/factory.d.ts.map +1 -0
  105. package/dist/logger/factory.js +94 -0
  106. package/dist/logger/factory.js.map +1 -0
  107. package/dist/logger/index.d.ts +42 -0
  108. package/dist/logger/index.d.ts.map +1 -0
  109. package/dist/logger/index.js +41 -0
  110. package/dist/logger/index.js.map +1 -0
  111. package/dist/logger/logger.types.d.ts +49 -0
  112. package/dist/logger/logger.types.d.ts.map +1 -0
  113. package/dist/logger/logger.types.js +2 -0
  114. package/dist/logger/logger.types.js.map +1 -0
  115. package/dist/repository/errors/validation-error.d.ts +24 -0
  116. package/dist/repository/errors/validation-error.d.ts.map +1 -0
  117. package/dist/repository/errors/validation-error.js +26 -0
  118. package/dist/repository/errors/validation-error.js.map +1 -0
  119. package/dist/repository/index.d.ts +122 -0
  120. package/dist/repository/index.d.ts.map +1 -0
  121. package/dist/repository/index.js +44 -0
  122. package/dist/repository/index.js.map +1 -0
  123. package/dist/repository/protopedia-in-memory-repository.d.ts +560 -0
  124. package/dist/repository/protopedia-in-memory-repository.d.ts.map +1 -0
  125. package/dist/repository/protopedia-in-memory-repository.js +929 -0
  126. package/dist/repository/protopedia-in-memory-repository.js.map +1 -0
  127. package/dist/repository/schemas/index.d.ts +9 -0
  128. package/dist/repository/schemas/index.d.ts.map +1 -0
  129. package/dist/repository/schemas/index.js +11 -0
  130. package/dist/repository/schemas/index.js.map +1 -0
  131. package/dist/repository/schemas/params.d.ts +44 -0
  132. package/dist/repository/schemas/params.d.ts.map +1 -0
  133. package/dist/repository/schemas/params.js +44 -0
  134. package/dist/repository/schemas/params.js.map +1 -0
  135. package/dist/repository/schemas/serializable-snapshot.d.ts +33 -0
  136. package/dist/repository/schemas/serializable-snapshot.d.ts.map +1 -0
  137. package/dist/repository/schemas/serializable-snapshot.js +45 -0
  138. package/dist/repository/schemas/serializable-snapshot.js.map +1 -0
  139. package/dist/repository/types/analysis.types.d.ts +89 -0
  140. package/dist/repository/types/analysis.types.d.ts.map +1 -0
  141. package/dist/repository/types/analysis.types.js +2 -0
  142. package/dist/repository/types/analysis.types.js.map +1 -0
  143. package/dist/repository/types/index.d.ts +12 -0
  144. package/dist/repository/types/index.d.ts.map +1 -0
  145. package/dist/repository/types/index.js +7 -0
  146. package/dist/repository/types/index.js.map +1 -0
  147. package/dist/repository/types/repository-events.types.d.ts +110 -0
  148. package/dist/repository/types/repository-events.types.d.ts.map +1 -0
  149. package/dist/repository/types/repository-events.types.js +2 -0
  150. package/dist/repository/types/repository-events.types.js.map +1 -0
  151. package/dist/repository/types/repository.types.d.ts +330 -0
  152. package/dist/repository/types/repository.types.d.ts.map +1 -0
  153. package/dist/repository/types/repository.types.js +2 -0
  154. package/dist/repository/types/repository.types.js.map +1 -0
  155. package/dist/repository/types/result.types.d.ts +55 -0
  156. package/dist/repository/types/result.types.d.ts.map +1 -0
  157. package/dist/repository/types/result.types.js +2 -0
  158. package/dist/repository/types/result.types.js.map +1 -0
  159. package/dist/repository/types/serialization.types.d.ts +61 -0
  160. package/dist/repository/types/serialization.types.d.ts.map +1 -0
  161. package/dist/repository/types/serialization.types.js +2 -0
  162. package/dist/repository/types/serialization.types.js.map +1 -0
  163. package/dist/repository/types/snapshot-operation.types.d.ts +140 -0
  164. package/dist/repository/types/snapshot-operation.types.d.ts.map +1 -0
  165. package/dist/repository/types/snapshot-operation.types.js +2 -0
  166. package/dist/repository/types/snapshot-operation.types.js.map +1 -0
  167. package/dist/repository/utils/convert-fetch-result.d.ts +46 -0
  168. package/dist/repository/utils/convert-fetch-result.d.ts.map +1 -0
  169. package/dist/repository/utils/convert-fetch-result.js +59 -0
  170. package/dist/repository/utils/convert-fetch-result.js.map +1 -0
  171. package/dist/repository/utils/convert-store-result.d.ts +36 -0
  172. package/dist/repository/utils/convert-store-result.d.ts.map +1 -0
  173. package/dist/repository/utils/convert-store-result.js +36 -0
  174. package/dist/repository/utils/convert-store-result.js.map +1 -0
  175. package/dist/repository/utils/emit-repository-event-safely.d.ts +5 -0
  176. package/dist/repository/utils/emit-repository-event-safely.d.ts.map +1 -0
  177. package/dist/repository/utils/emit-repository-event-safely.js +17 -0
  178. package/dist/repository/utils/emit-repository-event-safely.js.map +1 -0
  179. package/dist/repository/utils/index.d.ts +3 -0
  180. package/dist/repository/utils/index.d.ts.map +1 -0
  181. package/dist/repository/utils/index.js +3 -0
  182. package/dist/repository/utils/index.js.map +1 -0
  183. package/dist/repository/validation/index.d.ts +9 -0
  184. package/dist/repository/validation/index.d.ts.map +1 -0
  185. package/dist/repository/validation/index.js +10 -0
  186. package/dist/repository/validation/index.js.map +1 -0
  187. package/dist/repository/validation/params-validators.d.ts +46 -0
  188. package/dist/repository/validation/params-validators.d.ts.map +1 -0
  189. package/dist/repository/validation/params-validators.js +68 -0
  190. package/dist/repository/validation/params-validators.js.map +1 -0
  191. package/dist/repository/validation/serializable-snapshot.d.ts +47 -0
  192. package/dist/repository/validation/serializable-snapshot.d.ts.map +1 -0
  193. package/dist/repository/validation/serializable-snapshot.js +104 -0
  194. package/dist/repository/validation/serializable-snapshot.js.map +1 -0
  195. package/dist/schemas/index.d.ts +8 -0
  196. package/dist/schemas/index.d.ts.map +1 -0
  197. package/dist/schemas/index.js +8 -0
  198. package/dist/schemas/index.js.map +1 -0
  199. package/dist/schemas/normalized-prototype.d.ts +56 -0
  200. package/dist/schemas/normalized-prototype.d.ts.map +1 -0
  201. package/dist/schemas/normalized-prototype.js +123 -0
  202. package/dist/schemas/normalized-prototype.js.map +1 -0
  203. package/dist/store/errors/store-error.d.ts +148 -0
  204. package/dist/store/errors/store-error.d.ts.map +1 -0
  205. package/dist/store/errors/store-error.js +156 -0
  206. package/dist/store/errors/store-error.js.map +1 -0
  207. package/dist/store/index.d.ts +84 -0
  208. package/dist/store/index.d.ts.map +1 -0
  209. package/dist/store/index.js +83 -0
  210. package/dist/store/index.js.map +1 -0
  211. package/dist/store/store.d.ts +295 -0
  212. package/dist/store/store.d.ts.map +1 -0
  213. package/dist/store/store.js +411 -0
  214. package/dist/store/store.js.map +1 -0
  215. package/dist/store/types/index.d.ts +2 -0
  216. package/dist/store/types/index.d.ts.map +1 -0
  217. package/dist/store/types/index.js +2 -0
  218. package/dist/store/types/index.js.map +1 -0
  219. package/dist/store/types/result.types.d.ts +67 -0
  220. package/dist/store/types/result.types.d.ts.map +1 -0
  221. package/dist/store/types/result.types.js +2 -0
  222. package/dist/store/types/result.types.js.map +1 -0
  223. package/dist/types/codes.d.ts +44 -0
  224. package/dist/types/codes.d.ts.map +1 -0
  225. package/dist/types/codes.js +9 -0
  226. package/dist/types/codes.js.map +1 -0
  227. package/dist/types/index.d.ts +61 -0
  228. package/dist/types/index.d.ts.map +1 -0
  229. package/dist/types/index.js +60 -0
  230. package/dist/types/index.js.map +1 -0
  231. package/dist/types/normalized-prototype.d.ts +95 -0
  232. package/dist/types/normalized-prototype.d.ts.map +1 -0
  233. package/dist/types/normalized-prototype.js +2 -0
  234. package/dist/types/normalized-prototype.js.map +1 -0
  235. package/dist/utils/converters/index.d.ts +15 -0
  236. package/dist/utils/converters/index.d.ts.map +1 -0
  237. package/dist/utils/converters/index.js +15 -0
  238. package/dist/utils/converters/index.js.map +1 -0
  239. package/dist/utils/converters/license-type.d.ts +23 -0
  240. package/dist/utils/converters/license-type.d.ts.map +1 -0
  241. package/dist/utils/converters/license-type.js +38 -0
  242. package/dist/utils/converters/license-type.js.map +1 -0
  243. package/dist/utils/converters/release-flag.d.ts +24 -0
  244. package/dist/utils/converters/release-flag.d.ts.map +1 -0
  245. package/dist/utils/converters/release-flag.js +40 -0
  246. package/dist/utils/converters/release-flag.js.map +1 -0
  247. package/dist/utils/converters/status.d.ts +23 -0
  248. package/dist/utils/converters/status.d.ts.map +1 -0
  249. package/dist/utils/converters/status.js +40 -0
  250. package/dist/utils/converters/status.js.map +1 -0
  251. package/dist/utils/converters/thanks-flag.d.ts +25 -0
  252. package/dist/utils/converters/thanks-flag.d.ts.map +1 -0
  253. package/dist/utils/converters/thanks-flag.js +41 -0
  254. package/dist/utils/converters/thanks-flag.js.map +1 -0
  255. package/dist/utils/deep-merge.d.ts +38 -0
  256. package/dist/utils/deep-merge.d.ts.map +1 -0
  257. package/dist/utils/deep-merge.js +85 -0
  258. package/dist/utils/deep-merge.js.map +1 -0
  259. package/dist/utils/index.d.ts +80 -0
  260. package/dist/utils/index.d.ts.map +1 -0
  261. package/dist/utils/index.js +85 -0
  262. package/dist/utils/index.js.map +1 -0
  263. package/dist/utils/logger-utils.d.ts +100 -0
  264. package/dist/utils/logger-utils.d.ts.map +1 -0
  265. package/dist/utils/logger-utils.js +265 -0
  266. package/dist/utils/logger-utils.js.map +1 -0
  267. package/dist/utils/time/constants.d.ts +14 -0
  268. package/dist/utils/time/constants.d.ts.map +1 -0
  269. package/dist/utils/time/constants.js +14 -0
  270. package/dist/utils/time/constants.js.map +1 -0
  271. package/dist/utils/time/index.d.ts +28 -0
  272. package/dist/utils/time/index.d.ts.map +1 -0
  273. package/dist/utils/time/index.js +28 -0
  274. package/dist/utils/time/index.js.map +1 -0
  275. package/dist/utils/time/parser.d.ts +91 -0
  276. package/dist/utils/time/parser.d.ts.map +1 -0
  277. package/dist/utils/time/parser.js +143 -0
  278. package/dist/utils/time/parser.js.map +1 -0
  279. package/dist/utils/validation/index.d.ts +8 -0
  280. package/dist/utils/validation/index.d.ts.map +1 -0
  281. package/dist/utils/validation/index.js +7 -0
  282. package/dist/utils/validation/index.js.map +1 -0
  283. package/dist/utils/validation/normalized-prototype.d.ts +64 -0
  284. package/dist/utils/validation/normalized-prototype.d.ts.map +1 -0
  285. package/dist/utils/validation/normalized-prototype.js +97 -0
  286. package/dist/utils/validation/normalized-prototype.js.map +1 -0
  287. package/dist/utils/validation/types.d.ts +62 -0
  288. package/dist/utils/validation/types.d.ts.map +1 -0
  289. package/dist/utils/validation/types.js +8 -0
  290. package/dist/utils/validation/types.js.map +1 -0
  291. package/dist/version.d.ts +6 -0
  292. package/dist/version.d.ts.map +1 -0
  293. package/dist/version.js +6 -0
  294. package/dist/version.js.map +1 -0
  295. package/package.json +138 -0
@@ -0,0 +1,330 @@
1
+ /**
2
+ * Type definitions for the ProtoPedia in-memory repository interface.
3
+ *
4
+ * @module
5
+ */
6
+ import type { EventEmitter } from 'events';
7
+ import type { ListPrototypesParams } from 'protopedia-api-v2-client';
8
+ import type { DeepReadonly } from 'ts-essentials';
9
+ import type { Logger, LogLevel } from '../../logger/index.js';
10
+ import type { PrototypeInMemoryStats, PrototypeInMemoryStoreConfig } from '../../store/index.js';
11
+ import type { NormalizedPrototype } from '../../types/index.js';
12
+ import type { PrototypeAnalysisResult } from './analysis.types.js';
13
+ import type { SerializableSnapshot } from './serialization.types.js';
14
+ import type { SnapshotOperationResult } from './snapshot-operation.types.js';
15
+ /**
16
+ * Configuration options for the ProtoPedia in-memory repository.
17
+ */
18
+ export type ProtopediaInMemoryRepositoryConfig = {
19
+ /**
20
+ * Custom logger instance for repository operations.
21
+ *
22
+ * @remarks
23
+ * - If provided, the logger will be used as-is
24
+ * - If provided with logLevel, the level will be updated if logger is mutable
25
+ * - If not provided, creates a ConsoleLogger with the specified logLevel
26
+ *
27
+ * @default undefined (creates ConsoleLogger with 'info' level)
28
+ */
29
+ logger?: Logger;
30
+ /**
31
+ * Log level for creating a default ConsoleLogger.
32
+ *
33
+ * @remarks
34
+ * - Only used when `logger` is NOT provided
35
+ * - Creates a new ConsoleLogger with this level
36
+ * - If logger is provided and mutable, updates its level property
37
+ *
38
+ * @default 'info'
39
+ */
40
+ logLevel?: LogLevel;
41
+ /**
42
+ * Enable event notifications for snapshot operations.
43
+ *
44
+ * When enabled, the repository will create an EventEmitter instance and
45
+ * emit events during snapshot operations (snapshotStarted, snapshotCompleted, snapshotFailed).
46
+ *
47
+ * @remarks
48
+ * - Events are disabled by default to minimize overhead for CLI/script users
49
+ * - When enabled, access events via the `events` property
50
+ * - Always call `dispose()` to clean up event listeners when done
51
+ * - Designed primarily for WebApp/SPA scenarios
52
+ *
53
+ * @default false
54
+ *
55
+ * @see {@link RepositoryEvents} for available event types
56
+ * @see {@link https://github.com/F88/promidas/issues/19 | Issue #19: Event Notification System}
57
+ */
58
+ enableEvents?: boolean;
59
+ };
60
+ /**
61
+ * In-memory, snapshot-based repository for ProtoPedia prototypes.
62
+ *
63
+ * This repository hides HTTP and caching details behind a simple
64
+ * snapshot API:
65
+ *
66
+ * - `setupSnapshot` / `refreshSnapshot` populate or update the snapshot
67
+ * by calling the ProtoPedia API under the hood.
68
+ * - Read methods (`getPrototypeFromSnapshotById`,
69
+ * `getRandomPrototypeFromSnapshot`) access only the current in-memory
70
+ * snapshot and never perform HTTP calls.
71
+ * - `getStats` exposes enough information (size, cachedAt, isExpired) to
72
+ * implement TTL-based refresh strategies in the calling code.
73
+ */
74
+ export interface ProtopediaInMemoryRepository {
75
+ /**
76
+ * Event emitter for snapshot operation notifications.
77
+ *
78
+ * This property is only defined when `enableEvents: true` is set in the repository configuration.
79
+ * Use optional chaining (`events?.on(...)`) to safely access event methods.
80
+ *
81
+ * @remarks
82
+ * **Available Events:**
83
+ * - `snapshotStarted` - Emitted when setupSnapshot or refreshSnapshot begins
84
+ * - `snapshotCompleted` - Emitted when snapshot operation succeeds (includes stats)
85
+ * - `snapshotFailed` - Emitted when snapshot operation fails (includes error details)
86
+ *
87
+ * **Cleanup:**
88
+ * Always call `dispose()` to remove all event listeners and prevent memory leaks.
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * const repo = new PromidasRepositoryBuilder()
93
+ * .setRepositoryConfig({ enableEvents: true })
94
+ * .build();
95
+ *
96
+ * repo.events?.on('snapshotCompleted', (stats) => {
97
+ * console.log(`Updated: ${stats.size} prototypes`);
98
+ * });
99
+ *
100
+ * // Cleanup
101
+ * repo.dispose();
102
+ * ```
103
+ *
104
+ * @see {@link RepositoryEvents} for event type definitions
105
+ * @see {@link dispose} for cleanup method
106
+ */
107
+ readonly events?: EventEmitter;
108
+ /**
109
+ * Retrieve the configuration used to initialize the underlying store.
110
+ *
111
+ * Returns the TTL and maximum data size settings (logger is excluded).
112
+ */
113
+ getConfig(): Omit<Required<PrototypeInMemoryStoreConfig>, 'logger'>;
114
+ /**
115
+ * Stats for the current snapshot, including TTL-related information.
116
+ *
117
+ * Callers can use this to implement strategies such as:
118
+ * - refreshing when `isExpired` is true, or
119
+ * - refreshing when `cachedAt` is older than a given threshold.
120
+ *
121
+ * This method never throws due to ProtoPedia API failures; it only
122
+ * reports the current in-memory state.
123
+ */
124
+ getStats(): PrototypeInMemoryStats;
125
+ /**
126
+ * Fetch prototypes from ProtoPedia and populate the in-memory snapshot.
127
+ *
128
+ * Typical usage: call once on startup, or before the first read. The
129
+ * concrete fetch strategy (all vs partial, page size, filters, etc.) is
130
+ * an implementation detail of this repository.
131
+ *
132
+ * Returns a Result type indicating success with stats or failure with error details.
133
+ * In case of failure, any existing in-memory snapshot remains unchanged.
134
+ *
135
+ * @returns SnapshotOperationResult with ok: true and stats on success,
136
+ * or ok: false with error details on failure
137
+ */
138
+ setupSnapshot(params: ListPrototypesParams): Promise<SnapshotOperationResult>;
139
+ /**
140
+ * Refresh the snapshot using the same parameters as the last successful
141
+ * {@link ProtopediaInMemoryRepository.setupSnapshot | setupSnapshot} call.
142
+ *
143
+ * **Prerequisite**: `setupSnapshot()` must have been called successfully at least once.
144
+ * If called before `setupSnapshot()`, returns an error with code `REPOSITORY_INVALID_STATE`.
145
+ *
146
+ * Returns a Result type indicating success with stats or failure with error details.
147
+ * In case of failure, the current in-memory snapshot is preserved.
148
+ *
149
+ * @returns SnapshotOperationResult with ok: true and stats on success,
150
+ * or ok: false with error details on failure
151
+ */
152
+ refreshSnapshot(): Promise<SnapshotOperationResult>;
153
+ /**
154
+ * Analyze prototypes from the current snapshot to extract ID range.
155
+ *
156
+ * Returns the minimum and maximum prototype IDs from the current snapshot.
157
+ * This method does NOT perform HTTP calls.
158
+ *
159
+ * @returns {@link PrototypeAnalysisResult} containing min and max IDs, or null values if snapshot is empty
160
+ */
161
+ analyzePrototypes(): Promise<PrototypeAnalysisResult>;
162
+ /**
163
+ * Get all prototypes from the current in-memory snapshot.
164
+ *
165
+ * Returns all prototypes currently cached in the snapshot.
166
+ * The returned data is read-only and reflects the state at the time of the call.
167
+ *
168
+ * This method does NOT perform HTTP calls.
169
+ * It does not throw due to ProtoPedia API failures; it only reflects
170
+ * the current in-memory state of the snapshot.
171
+ *
172
+ * @returns Read-only array of all prototypes
173
+ */
174
+ getAllFromSnapshot(): Promise<readonly DeepReadonly<NormalizedPrototype>[]>;
175
+ /**
176
+ * Get all prototype IDs from the current in-memory snapshot.
177
+ *
178
+ * Returns an array of all prototype IDs currently cached in the snapshot.
179
+ * Useful for operations that only need IDs, such as:
180
+ * - Exporting available prototype IDs to clients
181
+ * - ID-based filtering or statistics
182
+ * - Checking if specific IDs exist without loading full objects
183
+ *
184
+ * This method does NOT perform HTTP calls.
185
+ * It does not throw due to ProtoPedia API failures; it only reflects
186
+ * the current in-memory state of the snapshot.
187
+ *
188
+ * @returns Read-only array of prototype IDs
189
+ */
190
+ getPrototypeIdsFromSnapshot(): Promise<readonly number[]>;
191
+ /**
192
+ * Get a prototype from the current in-memory snapshot by id.
193
+ *
194
+ * Returns the prototype when it exists in the snapshot, or null when
195
+ * the id is not present in the current snapshot.
196
+ *
197
+ * This method does NOT perform HTTP calls.
198
+ * It does not throw due to ProtoPedia API failures; it only reflects
199
+ * the current in-memory state of the snapshot.
200
+ */
201
+ getPrototypeFromSnapshotByPrototypeId(prototypeId: number): Promise<DeepReadonly<NormalizedPrototype> | null>;
202
+ /**
203
+ * Get a random prototype from the current in-memory snapshot.
204
+ *
205
+ * Returns a random prototype when the snapshot is not empty, or null
206
+ * when the snapshot is empty.
207
+ *
208
+ * This method does NOT perform HTTP calls.
209
+ * It does not throw due to ProtoPedia API failures; it only reflects
210
+ * the current in-memory state of the snapshot.
211
+ */
212
+ getRandomPrototypeFromSnapshot(): Promise<DeepReadonly<NormalizedPrototype> | null>;
213
+ /**
214
+ * Get random samples from the current in-memory snapshot.
215
+ *
216
+ * Returns up to `size` random prototypes without duplicates.
217
+ * If `size` exceeds the available data, returns all prototypes in random order.
218
+ * Returns an empty array when `size <= 0` or when the snapshot is empty.
219
+ *
220
+ * This method does NOT perform HTTP calls.
221
+ * It does not throw due to ProtoPedia API failures; it only reflects
222
+ * the current in-memory state of the snapshot.
223
+ *
224
+ * @param size - Maximum number of random samples to return
225
+ */
226
+ getRandomSampleFromSnapshot(size: number): Promise<readonly DeepReadonly<NormalizedPrototype>[]>;
227
+ /**
228
+ * Get current snapshot as a serializable object.
229
+ *
230
+ * Returns a plain JavaScript object containing all prototypes from the current
231
+ * snapshot along with metadata. The returned object can be passed to
232
+ * JSON.stringify() for persistence.
233
+ *
234
+ * This method does NOT perform file I/O or JSON.stringify().
235
+ * The caller is responsible for serialization and storage.
236
+ *
237
+ * This method does NOT perform HTTP calls.
238
+ * It only reflects the current in-memory state of the snapshot.
239
+ *
240
+ * @returns Serializable snapshot object with version, timestamp, and prototypes
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * // Export to file
245
+ * const snapshot = repo.getSerializableSnapshot();
246
+ * const json = JSON.stringify(snapshot, null, 2);
247
+ * await fs.writeFile('snapshot.json', json, 'utf-8');
248
+ *
249
+ * // Check content
250
+ * console.log(`Version: ${snapshot.version}`);
251
+ * console.log(`Serialized: ${snapshot.serializedAt}`);
252
+ * console.log(`Count: ${snapshot.prototypes.length}`);
253
+ * ```
254
+ *
255
+ * @see {@link setupSnapshotFromSerializedData} for importing serialized snapshots
256
+ * @see {@link SerializableSnapshot} for the data structure
257
+ */
258
+ getSerializableSnapshot(): SerializableSnapshot;
259
+ /**
260
+ * Setup snapshot from previously serialized data.
261
+ *
262
+ * Alternative to setupSnapshot(params) for offline/cached initialization.
263
+ * Validates the data structure and populates the in-memory store.
264
+ *
265
+ * This method does NOT perform file I/O or JSON.parse().
266
+ * The caller is responsible for loading and parsing the data.
267
+ *
268
+ * Returns a Result type indicating success with stats or failure with error details.
269
+ * Validation errors are returned as VALIDATION_ERROR type.
270
+ *
271
+ * @param data - Serializable snapshot object (previously exported)
272
+ * @returns SnapshotOperationResult with ok: true and stats on success,
273
+ * or ok: false with error details on validation/import failure
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * // Import from file
278
+ * const json = await fs.readFile('snapshot.json', 'utf-8');
279
+ * const data = JSON.parse(json);
280
+ * const result = repo.setupSnapshotFromSerializedData(data);
281
+ *
282
+ * if (result.ok) {
283
+ * console.log(`Loaded ${result.stats.size} prototypes`);
284
+ * } else {
285
+ * console.error(`Import failed: ${result.message}`);
286
+ * }
287
+ * ```
288
+ *
289
+ * @see {@link getSerializableSnapshot} for exporting snapshots
290
+ * @see {@link setupSnapshot} for API-based initialization
291
+ * @see {@link SerializableSnapshot} for the expected data structure
292
+ */
293
+ setupSnapshotFromSerializedData(data: SerializableSnapshot): SnapshotOperationResult;
294
+ /**
295
+ * Clean up event listeners and release resources.
296
+ *
297
+ * This method removes all event listeners from the internal EventEmitter.
298
+ * Always call this method in cleanup paths to prevent memory leaks.
299
+ *
300
+ * @remarks
301
+ * **When to call:**
302
+ * - Test cleanup (`afterEach` in test suites)
303
+ * - Component unmounting (React `useEffect` cleanup)
304
+ * - Before creating a new repository instance
305
+ * - When the repository is no longer needed
306
+ *
307
+ * **Safety:**
308
+ * - Safe to call even when events are disabled (`enableEvents: false`)
309
+ * - Safe to call multiple times
310
+ * - Does nothing if no event listeners exist
311
+ *
312
+ * @example
313
+ * ```typescript
314
+ * // In tests
315
+ * afterEach(() => {
316
+ * repo.dispose();
317
+ * });
318
+ *
319
+ * // In React components
320
+ * useEffect(() => {
321
+ * repo.events?.on('snapshotCompleted', handleComplete);
322
+ * return () => repo.dispose();
323
+ * }, []);
324
+ * ```
325
+ *
326
+ * @see {@link events} for event emitter property
327
+ */
328
+ dispose(): void;
329
+ }
330
+ //# sourceMappingURL=repository.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository.types.d.ts","sourceRoot":"","sources":["../../../lib/repository/types/repository.types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE3C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EACV,sBAAsB,EACtB,4BAA4B,EAC7B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEhE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAEnE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAE7E;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC;IAE/B;;;;OAIG;IACH,SAAS,IAAI,IAAI,CAAC,QAAQ,CAAC,4BAA4B,CAAC,EAAE,QAAQ,CAAC,CAAC;IAEpE;;;;;;;;;OASG;IACH,QAAQ,IAAI,sBAAsB,CAAC;IAEnC;;;;;;;;;;;;OAYG;IACH,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAE9E;;;;;;;;;;;;OAYG;IACH,eAAe,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAEpD;;;;;;;OAOG;IACH,iBAAiB,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAEtD;;;;;;;;;;;OAWG;IACH,kBAAkB,IAAI,OAAO,CAAC,SAAS,YAAY,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC;IAE5E;;;;;;;;;;;;;;OAcG;IACH,2BAA2B,IAAI,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;IAE1D;;;;;;;;;OASG;IACH,qCAAqC,CACnC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAAC,CAAC;IAErD;;;;;;;;;OASG;IACH,8BAA8B,IAAI,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAAC,CAAC;IAEpF;;;;;;;;;;;;OAYG;IACH,2BAA2B,CACzB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,SAAS,YAAY,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC;IAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,uBAAuB,IAAI,oBAAoB,CAAC;IAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,+BAA+B,CAC7B,IAAI,EAAE,oBAAoB,GACzB,uBAAuB,CAAC;IAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=repository.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository.types.js","sourceRoot":"","sources":["../../../lib/repository/types/repository.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Failure kinds specific to repository operations.
3
+ *
4
+ * - `validation`: Snapshot validation failed (Zod schema mismatch)
5
+ * - `invalid_state`: Operation cannot proceed due to invalid repository state
6
+ * - `size_estimation`: Size estimation for snapshot failed
7
+ * - `unknown`: Classification failed or unexpected error
8
+ */
9
+ export type RepositoryFailureKind = 'validation' | 'invalid_state' | 'size_estimation' | 'unknown';
10
+ /**
11
+ * Error codes for repository-originated failures.
12
+ *
13
+ * - `REPOSITORY_VALIDATION_ERROR`: Zod validation failed
14
+ * - `REPOSITORY_INVALID_STATE`: Operation cannot proceed (e.g., refresh without setup)
15
+ * - `REPOSITORY_SIZE_ESTIMATION_ERROR`: Size calculation failed
16
+ * - `REPOSITORY_UNKNOWN`: Unclassified error
17
+ */
18
+ export type RepositoryErrorCode = 'REPOSITORY_VALIDATION_ERROR' | 'REPOSITORY_INVALID_STATE' | 'REPOSITORY_SIZE_ESTIMATION_ERROR' | 'REPOSITORY_UNKNOWN';
19
+ /**
20
+ * Successful result from repository operations.
21
+ */
22
+ export type RepositorySuccess = {
23
+ /** Indicates successful operation. */
24
+ ok: true;
25
+ };
26
+ /**
27
+ * Failed result from repository operations.
28
+ *
29
+ * Contains repository-specific error information.
30
+ *
31
+ * @remarks
32
+ * This type represents failures that occur at the repository layer,
33
+ * distinct from failures originating in the fetcher or store layers.
34
+ */
35
+ export type RepositoryFailure = {
36
+ /** Indicates failed operation. */
37
+ ok: false;
38
+ /** Always repository-originated. */
39
+ origin: 'repository';
40
+ /** Coarse-grained classification of the failure cause. */
41
+ kind: RepositoryFailureKind;
42
+ /** Canonical error code from the repository. */
43
+ code: RepositoryErrorCode;
44
+ /** Human-readable error message. */
45
+ message: string;
46
+ /** Underlying cause of the error (optional). */
47
+ cause?: unknown;
48
+ };
49
+ /**
50
+ * Result from repository operations.
51
+ *
52
+ * Returns either success or failure with repository-specific error details.
53
+ */
54
+ export type RepositoryResult = RepositorySuccess | RepositoryFailure;
55
+ //# sourceMappingURL=result.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.types.d.ts","sourceRoot":"","sources":["../../../lib/repository/types/result.types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,qBAAqB,GAC7B,YAAY,GACZ,eAAe,GACf,iBAAiB,GACjB,SAAS,CAAC;AAEd;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,GAC3B,6BAA6B,GAC7B,0BAA0B,GAC1B,kCAAkC,GAClC,oBAAoB,CAAC;AAEzB;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,sCAAsC;IACtC,EAAE,EAAE,IAAI,CAAC;CACV,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,kCAAkC;IAClC,EAAE,EAAE,KAAK,CAAC;IACV,oCAAoC;IACpC,MAAM,EAAE,YAAY,CAAC;IACrB,0DAA0D;IAC1D,IAAI,EAAE,qBAAqB,CAAC;IAC5B,gDAAgD;IAChD,IAAI,EAAE,mBAAmB,CAAC;IAC1B,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,GAAG,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=result.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.types.js","sourceRoot":"","sources":["../../../lib/repository/types/result.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Type definitions for snapshot serialization and deserialization.
3
+ *
4
+ * This module defines types related to exporting and importing snapshots
5
+ * in serializable formats.
6
+ *
7
+ * @module
8
+ */
9
+ import type { NormalizedPrototype } from '../../types/index.js';
10
+ /**
11
+ * Serializable snapshot data structure for export/import.
12
+ *
13
+ * This type represents a snapshot that can be serialized to JSON and later
14
+ * restored. It contains all necessary data to reconstruct an in-memory snapshot
15
+ * without requiring API calls.
16
+ *
17
+ * @remarks
18
+ * **Use Cases:**
19
+ * - Offline usage - Load snapshot without network access
20
+ * - Faster startup - Skip API calls by loading cached snapshots
21
+ * - Test fixtures - Create consistent test data
22
+ * - Development - Work without hitting API rate limits
23
+ *
24
+ * **Format:**
25
+ * The structure is designed to be JSON-serializable. The caller is responsible
26
+ * for actual JSON.stringify() and file I/O operations.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * // Export
31
+ * const snapshot = await repo.getSerializableSnapshot();
32
+ * await fs.writeFile('snapshot.json', JSON.stringify(snapshot, null, 2));
33
+ *
34
+ * // Import
35
+ * const data = JSON.parse(await fs.readFile('snapshot.json', 'utf-8'));
36
+ * const result = repo.setupSnapshotFromSerializedData(data);
37
+ * ```
38
+ */
39
+ export type SerializableSnapshot = {
40
+ /**
41
+ * Snapshot format version for compatibility checks.
42
+ *
43
+ * Format: Semantic versioning (e.g., "1.0.0")
44
+ * Used to validate compatibility when deserializing.
45
+ */
46
+ version: string;
47
+ /**
48
+ * ISO-8601 UTC timestamp when the snapshot was serialized.
49
+ *
50
+ * Format: "YYYY-MM-DDTHH:mm:ss.sssZ"
51
+ * Useful for tracking snapshot age and debugging.
52
+ */
53
+ serializedAt: string;
54
+ /**
55
+ * Array of normalized prototypes.
56
+ *
57
+ * Contains all prototypes from the snapshot at the time of export.
58
+ */
59
+ prototypes: NormalizedPrototype[];
60
+ };
61
+ //# sourceMappingURL=serialization.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.types.d.ts","sourceRoot":"","sources":["../../../lib/repository/types/serialization.types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;OAKG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,UAAU,EAAE,mBAAmB,EAAE,CAAC;CACnC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=serialization.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.types.js","sourceRoot":"","sources":["../../../lib/repository/types/serialization.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,140 @@
1
+ import type { FetcherErrorCode, FetchFailureKind, FetchPrototypesFailure } from '../../fetcher/types/index.js';
2
+ import type { PrototypeInMemoryStats } from '../../store/index.js';
3
+ import type { SetFailure } from '../../store/types/index.js';
4
+ import type { RepositoryErrorCode, RepositoryFailureKind } from './result.types.js';
5
+ /**
6
+ * Successful response from setupSnapshot or refreshSnapshot operations.
7
+ *
8
+ * Contains statistics about the newly created or refreshed snapshot.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const result = await repo.setupSnapshot({ limit: 100 });
13
+ * if (result.ok) {
14
+ * console.log('Cached prototypes:', result.stats.size);
15
+ * console.log('Cached at:', result.stats.cachedAt);
16
+ * }
17
+ * ```
18
+ */
19
+ export type SnapshotOperationSuccess = {
20
+ /** Indicates successful operation. */
21
+ ok: true;
22
+ /** Statistics about the current snapshot after the operation. */
23
+ stats: PrototypeInMemoryStats;
24
+ };
25
+ /**
26
+ * Base type for all snapshot operation failures.
27
+ *
28
+ * Contains common fields shared by all failure types in the discriminated union.
29
+ */
30
+ export type SnapshotOperationFailureBase = {
31
+ /** Indicates failed operation. */
32
+ ok: false;
33
+ /** Origin layer where the failure occurred. */
34
+ origin: 'fetcher' | 'store' | 'repository' | 'unknown';
35
+ /** Human-readable error message. */
36
+ message: string;
37
+ };
38
+ /**
39
+ * Unknown/unexpected failure during snapshot operations.
40
+ *
41
+ * Fallback for errors that cannot be classified into fetcher or store failures.
42
+ */
43
+ export type UnknownSnapshotFailure = SnapshotOperationFailureBase & {
44
+ /** Indicates failure with unknown origin. */
45
+ origin: 'unknown';
46
+ };
47
+ /**
48
+ * Failure from the fetcher layer during snapshot operations.
49
+ *
50
+ * Includes detailed error information from network/HTTP operations.
51
+ */
52
+ export type FetcherSnapshotFailure = SnapshotOperationFailureBase & {
53
+ /** Indicates failure originated from fetcher layer. */
54
+ origin: 'fetcher';
55
+ /** Coarse-grained classification of the failure cause. */
56
+ kind: FetchFailureKind;
57
+ /** Canonical error code from the fetcher. */
58
+ code: FetcherErrorCode;
59
+ /** HTTP status code if applicable. */
60
+ status?: number;
61
+ /** Additional error details from request and response. */
62
+ details: FetchPrototypesFailure['details'];
63
+ };
64
+ /**
65
+ * Failure from the store layer during snapshot operations.
66
+ *
67
+ * Type alias for SetFailure when used in snapshot operation context.
68
+ * Occurs when snapshot data cannot be stored in memory due to size limits
69
+ * or serialization issues.
70
+ */
71
+ export type StoreSnapshotFailure = SetFailure;
72
+ /**
73
+ * Failure from the repository layer during snapshot operations.
74
+ *
75
+ * Occurs when input data validation fails during setupSnapshotFromSerializedData
76
+ * or when size estimation fails for snapshots.
77
+ * This indicates that the provided snapshot data does not conform to the
78
+ * expected schema (e.g., invalid version format, missing fields, incorrect types)
79
+ * or that size calculation encountered an error.
80
+ */
81
+ export type RepositorySnapshotFailure = SnapshotOperationFailureBase & {
82
+ /** Indicates failure originated from repository layer. */
83
+ origin: 'repository';
84
+ /** Coarse-grained classification of the failure cause. */
85
+ kind: RepositoryFailureKind;
86
+ /** Canonical error code from the repository. */
87
+ code: RepositoryErrorCode;
88
+ };
89
+ /**
90
+ * Failed response from setupSnapshot or refreshSnapshot operations.
91
+ *
92
+ * Discriminated union of all possible snapshot failure types.
93
+ * Use the 'origin' field to determine which specific failure type it is.
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * const result = await repo.setupSnapshot({ limit: 100 });
98
+ * if (!result.ok) {
99
+ * switch (result.origin) {
100
+ * case 'fetcher':
101
+ * console.error('Fetch failed:', result.kind, result.code);
102
+ * if (result.status === 401) {
103
+ * console.error('Authentication error');
104
+ * }
105
+ * break;
106
+ * case 'store':
107
+ * console.error('Store failed:', result.kind, result.code);
108
+ * break;
109
+ * case 'repository':
110
+ * console.error('Validation failed:', result.message);
111
+ * break;
112
+ * case 'unknown':
113
+ * console.error('Unknown error:', result.message);
114
+ * break;
115
+ * }
116
+ * }
117
+ * ```
118
+ */
119
+ export type SnapshotOperationFailure = FetcherSnapshotFailure | StoreSnapshotFailure | RepositorySnapshotFailure | UnknownSnapshotFailure;
120
+ /**
121
+ * Result type for setupSnapshot and refreshSnapshot operations.
122
+ *
123
+ * Discriminated union that allows type-safe error handling without exceptions.
124
+ * Follows the same pattern as the fetcher module's Result types.
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * const result = await repo.setupSnapshot({ limit: 100 });
129
+ *
130
+ * if (result.ok) {
131
+ * // TypeScript knows result has 'stats' property
132
+ * console.log('Success:', result.stats.size);
133
+ * } else {
134
+ * // TypeScript knows result has 'error', 'status', 'code' properties
135
+ * console.error('Failed:', result.error, result.status);
136
+ * }
137
+ * ```
138
+ */
139
+ export type SnapshotOperationResult = SnapshotOperationSuccess | SnapshotOperationFailure;
140
+ //# sourceMappingURL=snapshot-operation.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot-operation.types.d.ts","sourceRoot":"","sources":["../../../lib/repository/types/snapshot-operation.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,sCAAsC;IACtC,EAAE,EAAE,IAAI,CAAC;IACT,iEAAiE;IACjE,KAAK,EAAE,sBAAsB,CAAC;CAC/B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,kCAAkC;IAClC,EAAE,EAAE,KAAK,CAAC;IACV,+CAA+C;IAC/C,MAAM,EAAE,SAAS,GAAG,OAAO,GAAG,YAAY,GAAG,SAAS,CAAC;IACvD,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,4BAA4B,GAAG;IAClE,6CAA6C;IAC7C,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,4BAA4B,GAAG;IAClE,uDAAuD;IACvD,MAAM,EAAE,SAAS,CAAC;IAClB,0DAA0D;IAC1D,IAAI,EAAE,gBAAgB,CAAC;IACvB,6CAA6C;IAC7C,IAAI,EAAE,gBAAgB,CAAC;IACvB,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,OAAO,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;CAC5C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC;AAE9C;;;;;;;;GAQG;AACH,MAAM,MAAM,yBAAyB,GAAG,4BAA4B,GAAG;IACrE,0DAA0D;IAC1D,MAAM,EAAE,YAAY,CAAC;IACrB,0DAA0D;IAC1D,IAAI,EAAE,qBAAqB,CAAC;IAC5B,gDAAgD;IAChD,IAAI,EAAE,mBAAmB,CAAC;CAC3B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,MAAM,wBAAwB,GAChC,sBAAsB,GACtB,oBAAoB,GACpB,yBAAyB,GACzB,sBAAsB,CAAC;AAE3B;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,uBAAuB,GAC/B,wBAAwB,GACxB,wBAAwB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=snapshot-operation.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot-operation.types.js","sourceRoot":"","sources":["../../../lib/repository/types/snapshot-operation.types.ts"],"names":[],"mappings":""}