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.
- package/LICENSE +21 -0
- package/README.md +179 -0
- package/dist/builder.d.ts +158 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +255 -0
- package/dist/builder.js.map +1 -0
- package/dist/factory.d.ts +154 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +243 -0
- package/dist/factory.js.map +1 -0
- package/dist/fetcher/client/config.d.ts +140 -0
- package/dist/fetcher/client/config.d.ts.map +1 -0
- package/dist/fetcher/client/config.js +2 -0
- package/dist/fetcher/client/config.js.map +1 -0
- package/dist/fetcher/client/fetch-with-progress.d.ts +156 -0
- package/dist/fetcher/client/fetch-with-progress.d.ts.map +1 -0
- package/dist/fetcher/client/fetch-with-progress.js +313 -0
- package/dist/fetcher/client/fetch-with-progress.js.map +1 -0
- package/dist/fetcher/client/fetch-with-timeout.d.ts +6 -0
- package/dist/fetcher/client/fetch-with-timeout.d.ts.map +1 -0
- package/dist/fetcher/client/fetch-with-timeout.js +48 -0
- package/dist/fetcher/client/fetch-with-timeout.js.map +1 -0
- package/dist/fetcher/client/protopedia-api-custom-client.d.ts +141 -0
- package/dist/fetcher/client/protopedia-api-custom-client.d.ts.map +1 -0
- package/dist/fetcher/client/protopedia-api-custom-client.js +268 -0
- package/dist/fetcher/client/protopedia-api-custom-client.js.map +1 -0
- package/dist/fetcher/client/select-custom-fetch.d.ts +58 -0
- package/dist/fetcher/client/select-custom-fetch.d.ts.map +1 -0
- package/dist/fetcher/client/select-custom-fetch.js +58 -0
- package/dist/fetcher/client/select-custom-fetch.js.map +1 -0
- package/dist/fetcher/errors/fetcher-error.d.ts +10 -0
- package/dist/fetcher/errors/fetcher-error.d.ts.map +1 -0
- package/dist/fetcher/errors/fetcher-error.js +15 -0
- package/dist/fetcher/errors/fetcher-error.js.map +1 -0
- package/dist/fetcher/index.d.ts +73 -0
- package/dist/fetcher/index.d.ts.map +1 -0
- package/dist/fetcher/index.js +70 -0
- package/dist/fetcher/index.js.map +1 -0
- package/dist/fetcher/types/index.d.ts +9 -0
- package/dist/fetcher/types/index.d.ts.map +1 -0
- package/dist/fetcher/types/index.js +7 -0
- package/dist/fetcher/types/index.js.map +1 -0
- package/dist/fetcher/types/progress-event.types.d.ts +221 -0
- package/dist/fetcher/types/progress-event.types.d.ts.map +1 -0
- package/dist/fetcher/types/progress-event.types.js +10 -0
- package/dist/fetcher/types/progress-event.types.js.map +1 -0
- package/dist/fetcher/types/prototype-api.types.d.ts +106 -0
- package/dist/fetcher/types/prototype-api.types.d.ts.map +1 -0
- package/dist/fetcher/types/prototype-api.types.js +2 -0
- package/dist/fetcher/types/prototype-api.types.js.map +1 -0
- package/dist/fetcher/types/result.types.d.ts +75 -0
- package/dist/fetcher/types/result.types.d.ts.map +1 -0
- package/dist/fetcher/types/result.types.js +2 -0
- package/dist/fetcher/types/result.types.js.map +1 -0
- package/dist/fetcher/utils/create-client-fetch.d.ts +63 -0
- package/dist/fetcher/utils/create-client-fetch.d.ts.map +1 -0
- package/dist/fetcher/utils/create-client-fetch.js +89 -0
- package/dist/fetcher/utils/create-client-fetch.js.map +1 -0
- package/dist/fetcher/utils/create-fetch-with-stripped-headers.d.ts +6 -0
- package/dist/fetcher/utils/create-fetch-with-stripped-headers.d.ts.map +1 -0
- package/dist/fetcher/utils/create-fetch-with-stripped-headers.js +40 -0
- package/dist/fetcher/utils/create-fetch-with-stripped-headers.js.map +1 -0
- package/dist/fetcher/utils/errors/handler.d.ts +58 -0
- package/dist/fetcher/utils/errors/handler.d.ts.map +1 -0
- package/dist/fetcher/utils/errors/handler.js +243 -0
- package/dist/fetcher/utils/errors/handler.js.map +1 -0
- package/dist/fetcher/utils/errors/messages.d.ts +75 -0
- package/dist/fetcher/utils/errors/messages.d.ts.map +1 -0
- package/dist/fetcher/utils/errors/messages.js +88 -0
- package/dist/fetcher/utils/errors/messages.js.map +1 -0
- package/dist/fetcher/utils/index.d.ts +13 -0
- package/dist/fetcher/utils/index.d.ts.map +1 -0
- package/dist/fetcher/utils/index.js +12 -0
- package/dist/fetcher/utils/index.js.map +1 -0
- package/dist/fetcher/utils/log-timestamp-normalization-warnings.d.ts +10 -0
- package/dist/fetcher/utils/log-timestamp-normalization-warnings.d.ts.map +1 -0
- package/dist/fetcher/utils/log-timestamp-normalization-warnings.js +32 -0
- package/dist/fetcher/utils/log-timestamp-normalization-warnings.js.map +1 -0
- package/dist/fetcher/utils/normalize-protopedia-timestamp.d.ts +59 -0
- package/dist/fetcher/utils/normalize-protopedia-timestamp.d.ts.map +1 -0
- package/dist/fetcher/utils/normalize-protopedia-timestamp.js +81 -0
- package/dist/fetcher/utils/normalize-protopedia-timestamp.js.map +1 -0
- package/dist/fetcher/utils/normalize-prototype.d.ts +56 -0
- package/dist/fetcher/utils/normalize-prototype.d.ts.map +1 -0
- package/dist/fetcher/utils/normalize-prototype.js +113 -0
- package/dist/fetcher/utils/normalize-prototype.js.map +1 -0
- package/dist/fetcher/utils/sanitize-options.d.ts +14 -0
- package/dist/fetcher/utils/sanitize-options.d.ts.map +1 -0
- package/dist/fetcher/utils/sanitize-options.js +16 -0
- package/dist/fetcher/utils/sanitize-options.js.map +1 -0
- package/dist/fetcher/utils/string-parsers.d.ts +45 -0
- package/dist/fetcher/utils/string-parsers.d.ts.map +1 -0
- package/dist/fetcher/utils/string-parsers.js +53 -0
- package/dist/fetcher/utils/string-parsers.js.map +1 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +70 -0
- package/dist/index.js.map +1 -0
- package/dist/logger/console-logger.d.ts +74 -0
- package/dist/logger/console-logger.d.ts.map +1 -0
- package/dist/logger/console-logger.js +113 -0
- package/dist/logger/console-logger.js.map +1 -0
- package/dist/logger/factory.d.ts +88 -0
- package/dist/logger/factory.d.ts.map +1 -0
- package/dist/logger/factory.js +94 -0
- package/dist/logger/factory.js.map +1 -0
- package/dist/logger/index.d.ts +42 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +41 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/logger/logger.types.d.ts +49 -0
- package/dist/logger/logger.types.d.ts.map +1 -0
- package/dist/logger/logger.types.js +2 -0
- package/dist/logger/logger.types.js.map +1 -0
- package/dist/repository/errors/validation-error.d.ts +24 -0
- package/dist/repository/errors/validation-error.d.ts.map +1 -0
- package/dist/repository/errors/validation-error.js +26 -0
- package/dist/repository/errors/validation-error.js.map +1 -0
- package/dist/repository/index.d.ts +122 -0
- package/dist/repository/index.d.ts.map +1 -0
- package/dist/repository/index.js +44 -0
- package/dist/repository/index.js.map +1 -0
- package/dist/repository/protopedia-in-memory-repository.d.ts +560 -0
- package/dist/repository/protopedia-in-memory-repository.d.ts.map +1 -0
- package/dist/repository/protopedia-in-memory-repository.js +929 -0
- package/dist/repository/protopedia-in-memory-repository.js.map +1 -0
- package/dist/repository/schemas/index.d.ts +9 -0
- package/dist/repository/schemas/index.d.ts.map +1 -0
- package/dist/repository/schemas/index.js +11 -0
- package/dist/repository/schemas/index.js.map +1 -0
- package/dist/repository/schemas/params.d.ts +44 -0
- package/dist/repository/schemas/params.d.ts.map +1 -0
- package/dist/repository/schemas/params.js +44 -0
- package/dist/repository/schemas/params.js.map +1 -0
- package/dist/repository/schemas/serializable-snapshot.d.ts +33 -0
- package/dist/repository/schemas/serializable-snapshot.d.ts.map +1 -0
- package/dist/repository/schemas/serializable-snapshot.js +45 -0
- package/dist/repository/schemas/serializable-snapshot.js.map +1 -0
- package/dist/repository/types/analysis.types.d.ts +89 -0
- package/dist/repository/types/analysis.types.d.ts.map +1 -0
- package/dist/repository/types/analysis.types.js +2 -0
- package/dist/repository/types/analysis.types.js.map +1 -0
- package/dist/repository/types/index.d.ts +12 -0
- package/dist/repository/types/index.d.ts.map +1 -0
- package/dist/repository/types/index.js +7 -0
- package/dist/repository/types/index.js.map +1 -0
- package/dist/repository/types/repository-events.types.d.ts +110 -0
- package/dist/repository/types/repository-events.types.d.ts.map +1 -0
- package/dist/repository/types/repository-events.types.js +2 -0
- package/dist/repository/types/repository-events.types.js.map +1 -0
- package/dist/repository/types/repository.types.d.ts +330 -0
- package/dist/repository/types/repository.types.d.ts.map +1 -0
- package/dist/repository/types/repository.types.js +2 -0
- package/dist/repository/types/repository.types.js.map +1 -0
- package/dist/repository/types/result.types.d.ts +55 -0
- package/dist/repository/types/result.types.d.ts.map +1 -0
- package/dist/repository/types/result.types.js +2 -0
- package/dist/repository/types/result.types.js.map +1 -0
- package/dist/repository/types/serialization.types.d.ts +61 -0
- package/dist/repository/types/serialization.types.d.ts.map +1 -0
- package/dist/repository/types/serialization.types.js +2 -0
- package/dist/repository/types/serialization.types.js.map +1 -0
- package/dist/repository/types/snapshot-operation.types.d.ts +140 -0
- package/dist/repository/types/snapshot-operation.types.d.ts.map +1 -0
- package/dist/repository/types/snapshot-operation.types.js +2 -0
- package/dist/repository/types/snapshot-operation.types.js.map +1 -0
- package/dist/repository/utils/convert-fetch-result.d.ts +46 -0
- package/dist/repository/utils/convert-fetch-result.d.ts.map +1 -0
- package/dist/repository/utils/convert-fetch-result.js +59 -0
- package/dist/repository/utils/convert-fetch-result.js.map +1 -0
- package/dist/repository/utils/convert-store-result.d.ts +36 -0
- package/dist/repository/utils/convert-store-result.d.ts.map +1 -0
- package/dist/repository/utils/convert-store-result.js +36 -0
- package/dist/repository/utils/convert-store-result.js.map +1 -0
- package/dist/repository/utils/emit-repository-event-safely.d.ts +5 -0
- package/dist/repository/utils/emit-repository-event-safely.d.ts.map +1 -0
- package/dist/repository/utils/emit-repository-event-safely.js +17 -0
- package/dist/repository/utils/emit-repository-event-safely.js.map +1 -0
- package/dist/repository/utils/index.d.ts +3 -0
- package/dist/repository/utils/index.d.ts.map +1 -0
- package/dist/repository/utils/index.js +3 -0
- package/dist/repository/utils/index.js.map +1 -0
- package/dist/repository/validation/index.d.ts +9 -0
- package/dist/repository/validation/index.d.ts.map +1 -0
- package/dist/repository/validation/index.js +10 -0
- package/dist/repository/validation/index.js.map +1 -0
- package/dist/repository/validation/params-validators.d.ts +46 -0
- package/dist/repository/validation/params-validators.d.ts.map +1 -0
- package/dist/repository/validation/params-validators.js +68 -0
- package/dist/repository/validation/params-validators.js.map +1 -0
- package/dist/repository/validation/serializable-snapshot.d.ts +47 -0
- package/dist/repository/validation/serializable-snapshot.d.ts.map +1 -0
- package/dist/repository/validation/serializable-snapshot.js +104 -0
- package/dist/repository/validation/serializable-snapshot.js.map +1 -0
- package/dist/schemas/index.d.ts +8 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +8 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/normalized-prototype.d.ts +56 -0
- package/dist/schemas/normalized-prototype.d.ts.map +1 -0
- package/dist/schemas/normalized-prototype.js +123 -0
- package/dist/schemas/normalized-prototype.js.map +1 -0
- package/dist/store/errors/store-error.d.ts +148 -0
- package/dist/store/errors/store-error.d.ts.map +1 -0
- package/dist/store/errors/store-error.js +156 -0
- package/dist/store/errors/store-error.js.map +1 -0
- package/dist/store/index.d.ts +84 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +83 -0
- package/dist/store/index.js.map +1 -0
- package/dist/store/store.d.ts +295 -0
- package/dist/store/store.d.ts.map +1 -0
- package/dist/store/store.js +411 -0
- package/dist/store/store.js.map +1 -0
- package/dist/store/types/index.d.ts +2 -0
- package/dist/store/types/index.d.ts.map +1 -0
- package/dist/store/types/index.js +2 -0
- package/dist/store/types/index.js.map +1 -0
- package/dist/store/types/result.types.d.ts +67 -0
- package/dist/store/types/result.types.d.ts.map +1 -0
- package/dist/store/types/result.types.js +2 -0
- package/dist/store/types/result.types.js.map +1 -0
- package/dist/types/codes.d.ts +44 -0
- package/dist/types/codes.d.ts.map +1 -0
- package/dist/types/codes.js +9 -0
- package/dist/types/codes.js.map +1 -0
- package/dist/types/index.d.ts +61 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +60 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/normalized-prototype.d.ts +95 -0
- package/dist/types/normalized-prototype.d.ts.map +1 -0
- package/dist/types/normalized-prototype.js +2 -0
- package/dist/types/normalized-prototype.js.map +1 -0
- package/dist/utils/converters/index.d.ts +15 -0
- package/dist/utils/converters/index.d.ts.map +1 -0
- package/dist/utils/converters/index.js +15 -0
- package/dist/utils/converters/index.js.map +1 -0
- package/dist/utils/converters/license-type.d.ts +23 -0
- package/dist/utils/converters/license-type.d.ts.map +1 -0
- package/dist/utils/converters/license-type.js +38 -0
- package/dist/utils/converters/license-type.js.map +1 -0
- package/dist/utils/converters/release-flag.d.ts +24 -0
- package/dist/utils/converters/release-flag.d.ts.map +1 -0
- package/dist/utils/converters/release-flag.js +40 -0
- package/dist/utils/converters/release-flag.js.map +1 -0
- package/dist/utils/converters/status.d.ts +23 -0
- package/dist/utils/converters/status.d.ts.map +1 -0
- package/dist/utils/converters/status.js +40 -0
- package/dist/utils/converters/status.js.map +1 -0
- package/dist/utils/converters/thanks-flag.d.ts +25 -0
- package/dist/utils/converters/thanks-flag.d.ts.map +1 -0
- package/dist/utils/converters/thanks-flag.js +41 -0
- package/dist/utils/converters/thanks-flag.js.map +1 -0
- package/dist/utils/deep-merge.d.ts +38 -0
- package/dist/utils/deep-merge.d.ts.map +1 -0
- package/dist/utils/deep-merge.js +85 -0
- package/dist/utils/deep-merge.js.map +1 -0
- package/dist/utils/index.d.ts +80 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +85 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger-utils.d.ts +100 -0
- package/dist/utils/logger-utils.d.ts.map +1 -0
- package/dist/utils/logger-utils.js +265 -0
- package/dist/utils/logger-utils.js.map +1 -0
- package/dist/utils/time/constants.d.ts +14 -0
- package/dist/utils/time/constants.d.ts.map +1 -0
- package/dist/utils/time/constants.js +14 -0
- package/dist/utils/time/constants.js.map +1 -0
- package/dist/utils/time/index.d.ts +28 -0
- package/dist/utils/time/index.d.ts.map +1 -0
- package/dist/utils/time/index.js +28 -0
- package/dist/utils/time/index.js.map +1 -0
- package/dist/utils/time/parser.d.ts +91 -0
- package/dist/utils/time/parser.d.ts.map +1 -0
- package/dist/utils/time/parser.js +143 -0
- package/dist/utils/time/parser.js.map +1 -0
- package/dist/utils/validation/index.d.ts +8 -0
- package/dist/utils/validation/index.d.ts.map +1 -0
- package/dist/utils/validation/index.js +7 -0
- package/dist/utils/validation/index.js.map +1 -0
- package/dist/utils/validation/normalized-prototype.d.ts +64 -0
- package/dist/utils/validation/normalized-prototype.d.ts.map +1 -0
- package/dist/utils/validation/normalized-prototype.js +97 -0
- package/dist/utils/validation/normalized-prototype.js.map +1 -0
- package/dist/utils/validation/types.d.ts +62 -0
- package/dist/utils/validation/types.d.ts.map +1 -0
- package/dist/utils/validation/types.js +8 -0
- package/dist/utils/validation/types.js.map +1 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/package.json +138 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 F88
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# PROMIDAS
|
|
2
|
+
|
|
3
|
+
[](https://github.com/F88/promidas/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/F88/promidas/actions/workflows/github-code-scanning/codeql)
|
|
5
|
+
[](https://github.com/F88/promidas/actions/workflows/publish-package-to-npmjs.yml)
|
|
6
|
+
[](https://codecov.io/github/F88/promidas)
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+
[](https://opensource.org/licenses/MIT)
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
[](https://deepwiki.com/F88/promidas)
|
|
13
|
+
[](https://codewiki.google/github.com/f88/promidas)
|
|
14
|
+
|
|
15
|
+
ProtoPedia Resource Organized Management In-memory Data Access Store
|
|
16
|
+
|
|
17
|
+
A toolset library for ProtoPedia providing independent store and fetcher components, and a high-level repository for easy data management.
|
|
18
|
+
|
|
19
|
+
## クイックスタート
|
|
20
|
+
|
|
21
|
+
**[📖 ドキュメントサイト](https://f88.github.io/promidas/)** - 使い方とサンプルコード
|
|
22
|
+
|
|
23
|
+
**[🛝 PROMIDAS Playground](https://f88.github.io/PROMIDAS-demo/)** - デモ
|
|
24
|
+
|
|
25
|
+
**初めての方へ:**
|
|
26
|
+
|
|
27
|
+
1. [スタートガイド](https://f88.github.io/promidas/getting-started.html) - インストールと最初の一歩
|
|
28
|
+
2. [ユースケース](https://f88.github.io/promidas/use-case/) - あなたの利用シーンを選ぶ
|
|
29
|
+
|
|
30
|
+
**今すぐ試す:**
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install promidas
|
|
34
|
+
export PROTOPEDIA_API_V2_TOKEN="your-token-here"
|
|
35
|
+
npx tsx scripts/try-protopedia-repository.ts
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Project Overview
|
|
41
|
+
|
|
42
|
+
This repository provides a modular toolset for managing ProtoPedia data, consisting of independent components and a high-level repository:
|
|
43
|
+
|
|
44
|
+
1. **`lib/types`** - Compile-time Type Definitions (`NormalizedPrototype`, `StatusCode`, etc.)
|
|
45
|
+
- Type-safe TypeScript definitions for ProtoPedia data structures
|
|
46
|
+
- Normalized representation with consistent handling of dates, arrays, and optional fields
|
|
47
|
+
- Shared across all layers: fetcher, store, repository, and validation utilities
|
|
48
|
+
- Foundation for compile-time type safety (complements runtime validation in lib/schemas)
|
|
49
|
+
- [📘 README](lib/types/README.md) | [Usage Guide](lib/types/docs/USAGE.md) | [Design Document](lib/types/docs/DESIGN.md)
|
|
50
|
+
|
|
51
|
+
2. **`lib/schemas`** - Runtime Validation Schemas (`normalizedPrototypeSchema`)
|
|
52
|
+
- Zod-based runtime validation for external data (API responses, snapshots, files)
|
|
53
|
+
- Complements compile-time types for complete type safety (TypeScript + runtime)
|
|
54
|
+
- Shared across fetcher, repository, and validation utilities
|
|
55
|
+
- Strict code value validation (e.g., status: 1|2|3|4, not just any number)
|
|
56
|
+
- [📘 README](lib/schemas/README.md) | [Usage Guide](lib/schemas/docs/USAGE.md) | [Design Document](lib/schemas/docs/DESIGN.md)
|
|
57
|
+
|
|
58
|
+
3. **`lib/utils`** - Utility Functions and Converters
|
|
59
|
+
- Type-safe converters for ProtoPedia data (status, license, flags)
|
|
60
|
+
- Timestamp parsers (ProtoPedia JST format and W3C-DTF)
|
|
61
|
+
- Shared type definitions and constants
|
|
62
|
+
- Independent utilities usable across all modules
|
|
63
|
+
- [📘 README](lib/utils/README.md) | [Usage Guide](lib/utils/docs/USAGE.md) | [Design Document](lib/utils/docs/DESIGN.md)
|
|
64
|
+
|
|
65
|
+
4. **`lib/store`** - Standalone In-memory Store (`PrototypeInMemoryStore`)
|
|
66
|
+
- Generic snapshot management with TTL support
|
|
67
|
+
- O(1) lookups by ID via internal index
|
|
68
|
+
- Independent of any specific API client
|
|
69
|
+
- [📘 README](lib/store/README.md) | [Usage Guide](lib/store/docs/USAGE.md) | [Design Document](lib/store/docs/DESIGN.md)
|
|
70
|
+
|
|
71
|
+
5. **`lib/fetcher`** - API Client Utilities (`ProtopediaApiCustomClient`)
|
|
72
|
+
- Utilities to fetch and normalize ProtoPedia prototypes
|
|
73
|
+
- Error handling and network helpers for `protopedia-api-v2-client`
|
|
74
|
+
- Supports custom logger configuration for unified diagnostic output
|
|
75
|
+
- Can be used independently to build custom data pipelines
|
|
76
|
+
- [📘 README](lib/fetcher/README.md) | [Usage Guide](lib/fetcher/docs/USAGE.md) | [Design Document](lib/fetcher/docs/DESIGN.md)
|
|
77
|
+
|
|
78
|
+
6. **`lib/logger`** - Logger Interface (`Logger`)
|
|
79
|
+
- Type-safe logging interface compatible with `protopedia-api-v2-client`
|
|
80
|
+
- Used internally by Store, Fetcher, and Repository
|
|
81
|
+
- Can be replaced with custom logger (e.g., Winston, Pino)
|
|
82
|
+
- No `level` property for SDK compatibility (level managed by factory functions)
|
|
83
|
+
- [📘 README](lib/logger/README.md) | [Usage Guide](lib/logger/docs/USAGE.md) | [Design Document](lib/logger/docs/DESIGN.md)
|
|
84
|
+
|
|
85
|
+
7. **`lib/repository`** - Ready-to-use Repository (`ProtopediaInMemoryRepository`)
|
|
86
|
+
- Integrates `lib/store` and `lib/fetcher` into a single easy-to-use package
|
|
87
|
+
- Best for most use cases requiring caching and automatic refreshing
|
|
88
|
+
- [📘 README](lib/repository/README.md) | [Usage Guide](lib/repository/docs/USAGE.md) | [Design Document](lib/repository/docs/DESIGN.md)
|
|
89
|
+
|
|
90
|
+
8. **High-Level APIs** - Factory Functions and Builder
|
|
91
|
+
- **Factory Functions** (`lib/factory.ts`): Pre-configured for common scenarios
|
|
92
|
+
- `createPromidasForLocal()` - Optimized for local/development (30min TTL, 90s timeout, verbose logging)
|
|
93
|
+
- `createPromidasForServer()` - Optimized for server/production (10min TTL, 30s timeout, minimal logging)
|
|
94
|
+
- **Builder Pattern** (`lib/builder.ts`): Step-by-step configuration for advanced use cases
|
|
95
|
+
- `PromidasRepositoryBuilder` - Fluent API for complex configurations
|
|
96
|
+
- Exported from main module: `import { createPromidasForLocal, PromidasRepositoryBuilder } from 'promidas'`
|
|
97
|
+
|
|
98
|
+
This project extracts and generalizes the data-fetching and in-memory data management capabilities originally implemented in [F88/mugen-protopedia](https://github.com/F88/mugen-protopedia/), providing them as a standalone, reusable library for various applications.
|
|
99
|
+
|
|
100
|
+
## ProtoPedia API Ver 2.0
|
|
101
|
+
|
|
102
|
+
This library uses ProtoPedia API Ver 2.0.
|
|
103
|
+
To use the API, you need an Access Token (Bearer Token).
|
|
104
|
+
|
|
105
|
+
Please refer to the API documentation for details:
|
|
106
|
+
[ProtoPedia API Ver 2.0 · Apiary](https://protopediav2.docs.apiary.io/)
|
|
107
|
+
|
|
108
|
+
## Fully Supported API Client
|
|
109
|
+
|
|
110
|
+
This library fully supports [protopedia-api-v2-client](https://www.npmjs.com/package/protopedia-api-v2-client) v3.0.0 and later.
|
|
111
|
+
|
|
112
|
+
For details on how to integrate with `protopedia-api-v2-client` and use custom fetchers (e.g. for Next.js), please refer to [`lib/fetcher/docs/USAGE.md`](lib/fetcher/docs/USAGE.md).
|
|
113
|
+
|
|
114
|
+
## Subpath Exports
|
|
115
|
+
|
|
116
|
+
Each module can be imported independently using subpath exports:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
// Type definitions
|
|
120
|
+
import type { NormalizedPrototype, StatusCode } from 'promidas/types';
|
|
121
|
+
|
|
122
|
+
// Runtime validation schemas
|
|
123
|
+
import { normalizedPrototypeSchema } from 'promidas/schemas';
|
|
124
|
+
|
|
125
|
+
// Utility functions
|
|
126
|
+
import {
|
|
127
|
+
parseProtoPediaTimestamp,
|
|
128
|
+
getPrototypeStatusLabel,
|
|
129
|
+
} from 'promidas/utils';
|
|
130
|
+
|
|
131
|
+
// Logger
|
|
132
|
+
import { createConsoleLogger, type Logger } from 'promidas/logger';
|
|
133
|
+
|
|
134
|
+
// API client and fetcher
|
|
135
|
+
import {
|
|
136
|
+
ProtopediaApiCustomClient,
|
|
137
|
+
normalizePrototype,
|
|
138
|
+
} from 'promidas/fetcher';
|
|
139
|
+
|
|
140
|
+
// In-memory store
|
|
141
|
+
import {
|
|
142
|
+
PrototypeInMemoryStore,
|
|
143
|
+
type NormalizedPrototype,
|
|
144
|
+
} from 'promidas/store';
|
|
145
|
+
|
|
146
|
+
// Repository implementation
|
|
147
|
+
import { ProtopediaInMemoryRepositoryImpl } from 'promidas/repository';
|
|
148
|
+
|
|
149
|
+
// Factory functions and Builder (main module)
|
|
150
|
+
import {
|
|
151
|
+
createPromidasForLocal,
|
|
152
|
+
createPromidasForServer,
|
|
153
|
+
PromidasRepositoryBuilder,
|
|
154
|
+
} from 'promidas';
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Available subpath exports:**
|
|
158
|
+
|
|
159
|
+
- `promidas` — High-level APIs: Factory functions and Builder (recommended)
|
|
160
|
+
- `promidas/types` — Type definitions
|
|
161
|
+
- `promidas/schemas` — Runtime validation schemas (Zod)
|
|
162
|
+
- `promidas/utils` — Utility functions and converters
|
|
163
|
+
- `promidas/logger` — Logger interface and implementations
|
|
164
|
+
- `promidas/fetcher` — API client and data fetching
|
|
165
|
+
- `promidas/store` — In-memory store
|
|
166
|
+
- `promidas/repository` — Repository implementation
|
|
167
|
+
|
|
168
|
+
## For Contributors
|
|
169
|
+
|
|
170
|
+
**Development:**
|
|
171
|
+
|
|
172
|
+
- [DEVELOPMENT.md](DEVELOPMENT.md) - Setup development environment and workflows
|
|
173
|
+
- [CONTRIBUTING.md](CONTRIBUTING.md) - Contribution guidelines
|
|
174
|
+
- [DOCUMENTATION.md](DOCUMENTATION.md) - Documentation standards and guidelines
|
|
175
|
+
- [RELEASE.md](RELEASE.md) - Release process and versioning
|
|
176
|
+
|
|
177
|
+
**Project History:**
|
|
178
|
+
|
|
179
|
+
- [CHANGELOG.md](CHANGELOG.md) - Version history and release notes
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builder for creating Promidas repository instances.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a fluent builder interface for constructing
|
|
5
|
+
* {@link ProtopediaInMemoryRepository} instances.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { ProtoPediaApiClientOptions } from 'protopedia-api-v2-client';
|
|
10
|
+
import { ProtopediaApiCustomClient, type ProtopediaApiCustomClientConfig } from './fetcher/index.js';
|
|
11
|
+
import type { ProtopediaInMemoryRepository, ProtopediaInMemoryRepositoryConfig, PrototypeAnalysisResult } from './repository/types/index.js';
|
|
12
|
+
import { type PrototypeInMemoryStats, type PrototypeInMemoryStoreConfig } from './store/index.js';
|
|
13
|
+
export type { PrototypeInMemoryStoreConfig, PrototypeInMemoryStats, ProtopediaApiCustomClient, ProtopediaApiCustomClientConfig, ProtoPediaApiClientOptions, ProtopediaInMemoryRepository, ProtopediaInMemoryRepositoryConfig, PrototypeAnalysisResult, };
|
|
14
|
+
/**
|
|
15
|
+
* A builder class for constructing {@link ProtopediaInMemoryRepository} instances.
|
|
16
|
+
*
|
|
17
|
+
* It allows for step-by-step configuration of Store, API Client, and Repository settings
|
|
18
|
+
* through a fluent interface.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* **Logger Configuration:**
|
|
22
|
+
* Each component (Store, API Client, Repository) receives an independent logger instance.
|
|
23
|
+
* - If you provide a custom logger, it will be used as-is
|
|
24
|
+
* - If you don't provide a logger, a new ConsoleLogger is created with the specified logLevel (default: 'info')
|
|
25
|
+
* - Each component can have different loggers and log levels for maximum flexibility
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // Basic usage with default settings (each component gets independent logger)
|
|
30
|
+
* const repo = new PromidasRepositoryBuilder().build();
|
|
31
|
+
*
|
|
32
|
+
* // Configure store settings
|
|
33
|
+
* const repo = new PromidasRepositoryBuilder()
|
|
34
|
+
* .setStoreConfig({ ttlMs: 60000 })
|
|
35
|
+
* .setApiClientConfig({
|
|
36
|
+
* protoPediaApiClientOptions: { token: 'my-token' }
|
|
37
|
+
* })
|
|
38
|
+
* .build();
|
|
39
|
+
*
|
|
40
|
+
* // Different log levels for each component
|
|
41
|
+
* const repo = new PromidasRepositoryBuilder()
|
|
42
|
+
* .setStoreConfig({ logLevel: 'error' })
|
|
43
|
+
* .setApiClientConfig({ logLevel: 'warn' })
|
|
44
|
+
* .setRepositoryConfig({ logLevel: 'debug' })
|
|
45
|
+
* .build();
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare class PromidasRepositoryBuilder {
|
|
49
|
+
#private;
|
|
50
|
+
/**
|
|
51
|
+
* Set configuration for the in-memory store.
|
|
52
|
+
*
|
|
53
|
+
* Multiple calls will merge configurations (later values override earlier ones).
|
|
54
|
+
* Configuration is deeply merged to prevent external mutations while preserving
|
|
55
|
+
* function references (e.g., logger methods).
|
|
56
|
+
*
|
|
57
|
+
* @param config - Store configuration (TTL, max size, logger, etc.)
|
|
58
|
+
*/
|
|
59
|
+
setStoreConfig(config: PrototypeInMemoryStoreConfig): this;
|
|
60
|
+
/**
|
|
61
|
+
* Set configuration for the ProtopediaApiCustomClient wrapper.
|
|
62
|
+
* Allows configuring the logger used by the client wrapper itself.
|
|
63
|
+
*
|
|
64
|
+
* Multiple calls will merge configurations (later values override earlier ones).
|
|
65
|
+
* Configuration is deeply merged to prevent external mutations while preserving
|
|
66
|
+
* function references (e.g., logger methods).
|
|
67
|
+
*
|
|
68
|
+
* @param config - Wrapper configuration (logger, logLevel)
|
|
69
|
+
*/
|
|
70
|
+
setApiClientConfig(config: ProtopediaApiCustomClientConfig): this;
|
|
71
|
+
/**
|
|
72
|
+
* Set configuration for the Repository itself.
|
|
73
|
+
*
|
|
74
|
+
* Multiple calls will merge configurations (later values override earlier ones).
|
|
75
|
+
* Configuration is deeply merged to prevent external mutations while preserving
|
|
76
|
+
* function references (e.g., logger methods).
|
|
77
|
+
*
|
|
78
|
+
* @param config - Repository configuration (logger, etc.)
|
|
79
|
+
*/
|
|
80
|
+
setRepositoryConfig(config: ProtopediaInMemoryRepositoryConfig): this;
|
|
81
|
+
/**
|
|
82
|
+
* Build and return a fully configured ProtopediaInMemoryRepository instance.
|
|
83
|
+
*
|
|
84
|
+
* This method creates new instances of dependencies (Store, API Client)
|
|
85
|
+
* based on the accumulated configuration.
|
|
86
|
+
*
|
|
87
|
+
* @remarks
|
|
88
|
+
* **Logger Creation:**
|
|
89
|
+
* When no explicit logger is provided in a component's configuration, Builder
|
|
90
|
+
* creates a new ConsoleLogger instance with the specified logLevel (default: 'info').
|
|
91
|
+
* Each component receives an independent logger instance unless you explicitly
|
|
92
|
+
* share a logger by passing the same logger instance to multiple configs.
|
|
93
|
+
*
|
|
94
|
+
* **Configuration Immutability:**
|
|
95
|
+
* Configurations are deep-merged to prevent external mutations from affecting
|
|
96
|
+
* the builder's internal state.
|
|
97
|
+
*
|
|
98
|
+
* **Failure Logging:**
|
|
99
|
+
* When construction fails, this method logs the failure via the repository
|
|
100
|
+
* logger (if `logger.error` is a function) and rethrows the original error.
|
|
101
|
+
*
|
|
102
|
+
* @returns A fully configured ProtopediaInMemoryRepository instance
|
|
103
|
+
* @throws {ConfigurationError} When store configuration is invalid
|
|
104
|
+
* @throws {DataSizeExceededError} When snapshot data exceeds size limit
|
|
105
|
+
* @throws {SizeEstimationError} When snapshot size estimation fails
|
|
106
|
+
* @throws {StoreError} When store initialization fails
|
|
107
|
+
* @throws {unknown} When API client or repository construction fails
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* // Build with default settings (each component gets independent logger with 'info' level)
|
|
112
|
+
* const repo = new PromidasRepositoryBuilder().build();
|
|
113
|
+
*
|
|
114
|
+
* // Build with different log levels
|
|
115
|
+
* const repo = new PromidasRepositoryBuilder()
|
|
116
|
+
* .setStoreConfig({ ttlMs: 60000, logLevel: 'warn' })
|
|
117
|
+
* .setRepositoryConfig({ logLevel: 'debug' })
|
|
118
|
+
* .build();
|
|
119
|
+
* // Result: Store gets ConsoleLogger('warn'), Repository gets ConsoleLogger('debug')
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
build(): ProtopediaInMemoryRepository;
|
|
123
|
+
/**
|
|
124
|
+
* Creates a PrototypeInMemoryStore instance with detailed error handling.
|
|
125
|
+
*
|
|
126
|
+
* @param config - Store configuration
|
|
127
|
+
* @param repositoryLogger - Logger instance for error reporting
|
|
128
|
+
* @returns Initialized store instance
|
|
129
|
+
* @throws {ConfigurationError} When store configuration is invalid
|
|
130
|
+
* @throws {DataSizeExceededError} When snapshot data exceeds size limit
|
|
131
|
+
* @throws {SizeEstimationError} When snapshot size estimation fails
|
|
132
|
+
* @throws {StoreError} When other store-related errors occur
|
|
133
|
+
* @throws {unknown} When the store constructor throws an unexpected error
|
|
134
|
+
*
|
|
135
|
+
* @remarks
|
|
136
|
+
* On failure, this method logs via the repository logger (if `logger.error`
|
|
137
|
+
* is a function) and rethrows the original error.
|
|
138
|
+
*
|
|
139
|
+
* @internal This method is private and intended for internal use and testing only
|
|
140
|
+
*/
|
|
141
|
+
private buildStore;
|
|
142
|
+
/**
|
|
143
|
+
* Creates a ProtopediaApiCustomClient instance with detailed error handling.
|
|
144
|
+
*
|
|
145
|
+
* @param config - API client configuration
|
|
146
|
+
* @param repositoryLogger - Logger instance for error reporting
|
|
147
|
+
* @returns Initialized API client instance
|
|
148
|
+
* @throws {unknown} When API client construction fails
|
|
149
|
+
*
|
|
150
|
+
* @remarks
|
|
151
|
+
* On failure, this method logs via the repository logger (if `logger.error`
|
|
152
|
+
* is a function) and rethrows the original error.
|
|
153
|
+
*
|
|
154
|
+
* @internal This method is private and intended for internal use and testing only
|
|
155
|
+
*/
|
|
156
|
+
private buildApiClient;
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../lib/builder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAG3E,OAAO,EACL,yBAAyB,EACzB,KAAK,+BAA+B,EACrC,MAAM,oBAAoB,CAAC;AAI5B,OAAO,KAAK,EACV,4BAA4B,EAC5B,kCAAkC,EAClC,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAML,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EAClC,MAAM,kBAAkB,CAAC;AAI1B,YAAY,EAEV,4BAA4B,EAC5B,sBAAsB,EAGtB,yBAAyB,EACzB,+BAA+B,EAE/B,0BAA0B,EAG1B,4BAA4B,EAC5B,kCAAkC,EAClC,uBAAuB,GACxB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,yBAAyB;;IAMpC;;;;;;;;OAQG;IACH,cAAc,CAAC,MAAM,EAAE,4BAA4B,GAAG,IAAI;IAK1D;;;;;;;;;OASG;IACH,kBAAkB,CAAC,MAAM,EAAE,+BAA+B,GAAG,IAAI;IAKjE;;;;;;;;OAQG;IACH,mBAAmB,CAAC,MAAM,EAAE,kCAAkC,GAAG,IAAI;IAKrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACH,KAAK,IAAI,4BAA4B;IA2DrC;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,CAAC,UAAU;IAiClB;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,cAAc;CAiBvB"}
|
package/dist/builder.js
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builder for creating Promidas repository instances.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a fluent builder interface for constructing
|
|
5
|
+
* {@link ProtopediaInMemoryRepository} instances.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
// Logger types
|
|
10
|
+
import { ProtopediaApiCustomClient, } from './fetcher/index.js';
|
|
11
|
+
import { ConsoleLogger } from './logger/console-logger.js';
|
|
12
|
+
import { ProtopediaInMemoryRepositoryImpl } from './repository/protopedia-in-memory-repository.js';
|
|
13
|
+
import { ConfigurationError, DataSizeExceededError, PrototypeInMemoryStore, SizeEstimationError, StoreError, } from './store/index.js';
|
|
14
|
+
import { deepMerge, sanitizeDataForLogging } from './utils/index.js';
|
|
15
|
+
/**
|
|
16
|
+
* A builder class for constructing {@link ProtopediaInMemoryRepository} instances.
|
|
17
|
+
*
|
|
18
|
+
* It allows for step-by-step configuration of Store, API Client, and Repository settings
|
|
19
|
+
* through a fluent interface.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* **Logger Configuration:**
|
|
23
|
+
* Each component (Store, API Client, Repository) receives an independent logger instance.
|
|
24
|
+
* - If you provide a custom logger, it will be used as-is
|
|
25
|
+
* - If you don't provide a logger, a new ConsoleLogger is created with the specified logLevel (default: 'info')
|
|
26
|
+
* - Each component can have different loggers and log levels for maximum flexibility
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // Basic usage with default settings (each component gets independent logger)
|
|
31
|
+
* const repo = new PromidasRepositoryBuilder().build();
|
|
32
|
+
*
|
|
33
|
+
* // Configure store settings
|
|
34
|
+
* const repo = new PromidasRepositoryBuilder()
|
|
35
|
+
* .setStoreConfig({ ttlMs: 60000 })
|
|
36
|
+
* .setApiClientConfig({
|
|
37
|
+
* protoPediaApiClientOptions: { token: 'my-token' }
|
|
38
|
+
* })
|
|
39
|
+
* .build();
|
|
40
|
+
*
|
|
41
|
+
* // Different log levels for each component
|
|
42
|
+
* const repo = new PromidasRepositoryBuilder()
|
|
43
|
+
* .setStoreConfig({ logLevel: 'error' })
|
|
44
|
+
* .setApiClientConfig({ logLevel: 'warn' })
|
|
45
|
+
* .setRepositoryConfig({ logLevel: 'debug' })
|
|
46
|
+
* .build();
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export class PromidasRepositoryBuilder {
|
|
50
|
+
// Configs
|
|
51
|
+
#storeConfig = {};
|
|
52
|
+
#apiClientConfig = {};
|
|
53
|
+
#repositoryConfig = {};
|
|
54
|
+
/**
|
|
55
|
+
* Set configuration for the in-memory store.
|
|
56
|
+
*
|
|
57
|
+
* Multiple calls will merge configurations (later values override earlier ones).
|
|
58
|
+
* Configuration is deeply merged to prevent external mutations while preserving
|
|
59
|
+
* function references (e.g., logger methods).
|
|
60
|
+
*
|
|
61
|
+
* @param config - Store configuration (TTL, max size, logger, etc.)
|
|
62
|
+
*/
|
|
63
|
+
setStoreConfig(config) {
|
|
64
|
+
this.#storeConfig = deepMerge(this.#storeConfig, config);
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Set configuration for the ProtopediaApiCustomClient wrapper.
|
|
69
|
+
* Allows configuring the logger used by the client wrapper itself.
|
|
70
|
+
*
|
|
71
|
+
* Multiple calls will merge configurations (later values override earlier ones).
|
|
72
|
+
* Configuration is deeply merged to prevent external mutations while preserving
|
|
73
|
+
* function references (e.g., logger methods).
|
|
74
|
+
*
|
|
75
|
+
* @param config - Wrapper configuration (logger, logLevel)
|
|
76
|
+
*/
|
|
77
|
+
setApiClientConfig(config) {
|
|
78
|
+
this.#apiClientConfig = deepMerge(this.#apiClientConfig, config);
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Set configuration for the Repository itself.
|
|
83
|
+
*
|
|
84
|
+
* Multiple calls will merge configurations (later values override earlier ones).
|
|
85
|
+
* Configuration is deeply merged to prevent external mutations while preserving
|
|
86
|
+
* function references (e.g., logger methods).
|
|
87
|
+
*
|
|
88
|
+
* @param config - Repository configuration (logger, etc.)
|
|
89
|
+
*/
|
|
90
|
+
setRepositoryConfig(config) {
|
|
91
|
+
this.#repositoryConfig = deepMerge(this.#repositoryConfig, config);
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Build and return a fully configured ProtopediaInMemoryRepository instance.
|
|
96
|
+
*
|
|
97
|
+
* This method creates new instances of dependencies (Store, API Client)
|
|
98
|
+
* based on the accumulated configuration.
|
|
99
|
+
*
|
|
100
|
+
* @remarks
|
|
101
|
+
* **Logger Creation:**
|
|
102
|
+
* When no explicit logger is provided in a component's configuration, Builder
|
|
103
|
+
* creates a new ConsoleLogger instance with the specified logLevel (default: 'info').
|
|
104
|
+
* Each component receives an independent logger instance unless you explicitly
|
|
105
|
+
* share a logger by passing the same logger instance to multiple configs.
|
|
106
|
+
*
|
|
107
|
+
* **Configuration Immutability:**
|
|
108
|
+
* Configurations are deep-merged to prevent external mutations from affecting
|
|
109
|
+
* the builder's internal state.
|
|
110
|
+
*
|
|
111
|
+
* **Failure Logging:**
|
|
112
|
+
* When construction fails, this method logs the failure via the repository
|
|
113
|
+
* logger (if `logger.error` is a function) and rethrows the original error.
|
|
114
|
+
*
|
|
115
|
+
* @returns A fully configured ProtopediaInMemoryRepository instance
|
|
116
|
+
* @throws {ConfigurationError} When store configuration is invalid
|
|
117
|
+
* @throws {DataSizeExceededError} When snapshot data exceeds size limit
|
|
118
|
+
* @throws {SizeEstimationError} When snapshot size estimation fails
|
|
119
|
+
* @throws {StoreError} When store initialization fails
|
|
120
|
+
* @throws {unknown} When API client or repository construction fails
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* // Build with default settings (each component gets independent logger with 'info' level)
|
|
125
|
+
* const repo = new PromidasRepositoryBuilder().build();
|
|
126
|
+
*
|
|
127
|
+
* // Build with different log levels
|
|
128
|
+
* const repo = new PromidasRepositoryBuilder()
|
|
129
|
+
* .setStoreConfig({ ttlMs: 60000, logLevel: 'warn' })
|
|
130
|
+
* .setRepositoryConfig({ logLevel: 'debug' })
|
|
131
|
+
* .build();
|
|
132
|
+
* // Result: Store gets ConsoleLogger('warn'), Repository gets ConsoleLogger('debug')
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
build() {
|
|
136
|
+
// Design Decision: Builder ensures logger instance exists
|
|
137
|
+
//
|
|
138
|
+
// Why Builder creates loggers instead of delegating to modules:
|
|
139
|
+
// 1. Responsibility clarity: Builder guarantees logger presence
|
|
140
|
+
// 2. Loose coupling: Reduces dependency on module's logger creation logic
|
|
141
|
+
// 3. Consistency: Uniform logger creation strategy across all components
|
|
142
|
+
//
|
|
143
|
+
// Alternative (simpler but more coupled):
|
|
144
|
+
// Just pass config as-is: new PrototypeInMemoryStore(this.#storeConfig)
|
|
145
|
+
// Modules would handle logger creation internally
|
|
146
|
+
// Trade-off: Tighter coupling to module implementation details
|
|
147
|
+
const storeConfig = {
|
|
148
|
+
...this.#storeConfig,
|
|
149
|
+
logger: this.#storeConfig.logger ??
|
|
150
|
+
new ConsoleLogger(this.#storeConfig.logLevel ?? 'info'),
|
|
151
|
+
};
|
|
152
|
+
const apiClientConfig = {
|
|
153
|
+
...this.#apiClientConfig,
|
|
154
|
+
logger: this.#apiClientConfig.logger ??
|
|
155
|
+
new ConsoleLogger(this.#apiClientConfig.logLevel ?? 'info'),
|
|
156
|
+
};
|
|
157
|
+
// Ensure logger exists before constructing repository config
|
|
158
|
+
const repositoryLogger = this.#repositoryConfig.logger ??
|
|
159
|
+
new ConsoleLogger(this.#repositoryConfig.logLevel ?? 'info');
|
|
160
|
+
const repositoryConfig = {
|
|
161
|
+
...this.#repositoryConfig,
|
|
162
|
+
logger: repositoryLogger,
|
|
163
|
+
};
|
|
164
|
+
// Build Store and API Client
|
|
165
|
+
const store = this.buildStore(storeConfig, repositoryLogger);
|
|
166
|
+
const apiClient = this.buildApiClient(apiClientConfig, repositoryLogger);
|
|
167
|
+
// Build Repository
|
|
168
|
+
try {
|
|
169
|
+
return new ProtopediaInMemoryRepositoryImpl({
|
|
170
|
+
store,
|
|
171
|
+
apiClient,
|
|
172
|
+
repositoryConfig,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
// Handle Repository construction errors
|
|
177
|
+
if (typeof repositoryLogger.error === 'function') {
|
|
178
|
+
repositoryLogger.error('Failed to create ProtopediaInMemoryRepositoryImpl', sanitizeDataForLogging({ error }));
|
|
179
|
+
}
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Creates a PrototypeInMemoryStore instance with detailed error handling.
|
|
185
|
+
*
|
|
186
|
+
* @param config - Store configuration
|
|
187
|
+
* @param repositoryLogger - Logger instance for error reporting
|
|
188
|
+
* @returns Initialized store instance
|
|
189
|
+
* @throws {ConfigurationError} When store configuration is invalid
|
|
190
|
+
* @throws {DataSizeExceededError} When snapshot data exceeds size limit
|
|
191
|
+
* @throws {SizeEstimationError} When snapshot size estimation fails
|
|
192
|
+
* @throws {StoreError} When other store-related errors occur
|
|
193
|
+
* @throws {unknown} When the store constructor throws an unexpected error
|
|
194
|
+
*
|
|
195
|
+
* @remarks
|
|
196
|
+
* On failure, this method logs via the repository logger (if `logger.error`
|
|
197
|
+
* is a function) and rethrows the original error.
|
|
198
|
+
*
|
|
199
|
+
* @internal This method is private and intended for internal use and testing only
|
|
200
|
+
*/
|
|
201
|
+
buildStore(config, repositoryLogger) {
|
|
202
|
+
try {
|
|
203
|
+
return new PrototypeInMemoryStore(config);
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
// Handle Store construction errors (e.g., ConfigurationError)
|
|
207
|
+
if (typeof repositoryLogger.error === 'function') {
|
|
208
|
+
// Build detailed error information based on error type
|
|
209
|
+
let errorDetails;
|
|
210
|
+
if (error instanceof StoreError) {
|
|
211
|
+
errorDetails = { error, dataState: error.dataState };
|
|
212
|
+
if (error instanceof DataSizeExceededError) {
|
|
213
|
+
errorDetails.dataSizeBytes = error.dataSizeBytes;
|
|
214
|
+
errorDetails.maxDataSizeBytes = error.maxDataSizeBytes;
|
|
215
|
+
}
|
|
216
|
+
else if (error instanceof SizeEstimationError) {
|
|
217
|
+
errorDetails.cause = error.cause;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
errorDetails = { error };
|
|
222
|
+
}
|
|
223
|
+
repositoryLogger.error('Failed to create PrototypeInMemoryStore', sanitizeDataForLogging(errorDetails));
|
|
224
|
+
}
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Creates a ProtopediaApiCustomClient instance with detailed error handling.
|
|
230
|
+
*
|
|
231
|
+
* @param config - API client configuration
|
|
232
|
+
* @param repositoryLogger - Logger instance for error reporting
|
|
233
|
+
* @returns Initialized API client instance
|
|
234
|
+
* @throws {unknown} When API client construction fails
|
|
235
|
+
*
|
|
236
|
+
* @remarks
|
|
237
|
+
* On failure, this method logs via the repository logger (if `logger.error`
|
|
238
|
+
* is a function) and rethrows the original error.
|
|
239
|
+
*
|
|
240
|
+
* @internal This method is private and intended for internal use and testing only
|
|
241
|
+
*/
|
|
242
|
+
buildApiClient(config, repositoryLogger) {
|
|
243
|
+
try {
|
|
244
|
+
return new ProtopediaApiCustomClient(config);
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
// Handle API client construction errors
|
|
248
|
+
if (typeof repositoryLogger.error === 'function') {
|
|
249
|
+
repositoryLogger.error('Failed to create ProtopediaApiCustomClient', sanitizeDataForLogging({ error }));
|
|
250
|
+
}
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../lib/builder.ts"],"names":[],"mappings":"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"}
|