event-store-adapter-js 5.0.0 → 5.0.1

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/README.ja.md CHANGED
@@ -62,7 +62,7 @@ headがなければ `getLatestSnapshotById` は `undefined` を返します。he
62
62
 
63
63
  ## DynamoDB
64
64
 
65
- [DATABASE_SCHEMA.ja.md](docs/DATABASE_SCHEMA.ja.md) に従い、3表と履歴GSIを作成してからストアを生成します。ライブラリは3表の共通設定項目を作成・照合します。
65
+ [DATABASE_SCHEMA.ja.md](docs/DATABASE_SCHEMA.ja.md) に従い、3表と履歴GSIを作成してからストアを生成します。ライブラリは3表の共通設定項目を作成・照合します。3 つの表は同じリージョンに置き、書き込みもそのリージョンからだけ行ってください。グローバルテーブル(複数リージョンのレプリカ)は範囲外です。
66
66
 
67
67
  ```typescript
68
68
  const opened = await EventStore.createDynamoDB({
@@ -81,7 +81,7 @@ AWSクライアントは呼び出し側で管理します。snapshot書き込み
81
81
 
82
82
  既定の `PayloadSerializer.json()` はJSON値だけを扱います。任意の同期 `PayloadSerializer<P>` は `serialize(payload): Uint8Array` と `deserialize(bytes, manifest): P` を実装します。payloadだけを直列化し、クラスやbrandは `deserialize` で復元してください。実例の [domain serializer](../examples/src/domain/user-account-serializers.ts) を参照できます。
83
83
 
84
- storageを省略したMemory生成は独立します。共有する場合は `MemoryStorage.create()` の同じ値を複数のfactoryへ渡し、保持設定もstorageに指定します。
84
+ メモリの保存先は単一プロセスのメモリだけを使います。ファイルへの保存、再起動後の回復、プロセス間の共有はしません。storageを省略したMemory生成は独立します。共有する場合は `MemoryStorage.create()` の同じ値を複数のfactoryへ渡し、保持設定もstorageに指定します。
85
85
 
86
86
  ```typescript
87
87
  const storage = unwrap(MemoryStorage.create({ retention: { count: 3 } }));
package/README.md CHANGED
@@ -62,7 +62,7 @@ Both factories and all four operations return `Result`. DynamoDB creation is asy
62
62
 
63
63
  ## DynamoDB
64
64
 
65
- Create the three tables and history GSI described in [DATABASE_SCHEMA.md](docs/DATABASE_SCHEMA.md) before opening the store. The library creates or verifies their shared configuration items.
65
+ Create the three tables and history GSI described in [DATABASE_SCHEMA.md](docs/DATABASE_SCHEMA.md) before opening the store. The library creates or verifies their shared configuration items. Keep the three tables in one Region and write to them only from that Region. Global tables (multi-Region replicas) are not supported.
66
66
 
67
67
  ```typescript
68
68
  const opened = await EventStore.createDynamoDB({
@@ -81,7 +81,7 @@ The caller owns the AWS client. Snapshot retention runs after a successful snaps
81
81
 
82
82
  The default `PayloadSerializer.json()` handles JSON values only. A custom synchronous `PayloadSerializer<P>` implements `serialize(payload): Uint8Array` and `deserialize(bytes, manifest): P`. Serialize the payload alone and restore domain classes or brands in `deserialize`. See the [domain serializers](../examples/src/domain/user-account-serializers.ts) in the runnable examples.
83
83
 
84
- Memory creation without a storage uses isolated storage. To share records, pass the same value returned by `MemoryStorage.create()` to multiple factories. Configure retention on that storage:
84
+ The memory storage lives in a single process. It does not persist to files, survive restarts, or share data across processes. Memory creation without a storage uses isolated storage. To share records, pass the same value returned by `MemoryStorage.create()` to multiple factories. Configure retention on that storage:
85
85
 
86
86
  ```typescript
87
87
  const storage = unwrap(MemoryStorage.create({ retention: { count: 3 } }));
@@ -17,6 +17,13 @@ const event_store_input_validation_1 = require("./event-store-input-validation")
17
17
  const memory_storage_records_1 = require("./memory-storage-records");
18
18
  const seq_nr_validation_1 = require("./seq-nr-validation");
19
19
  const validated_event_store_1 = require("./validated-event-store");
20
+ const knownSettings = new Set([
21
+ "storage",
22
+ "eventSerializer",
23
+ "snapshotSerializer",
24
+ "onRetentionFailure",
25
+ "logger",
26
+ ]);
20
27
  /** 実Storageと保持処理に接続した4操作を返す内部入口。 */
21
28
  function createMemoryEventStoreInternal(input, hooks) {
22
29
  const settings = (0, event_store_input_validation_1.validateEventStoreInput)(input);
@@ -30,6 +37,19 @@ function createMemoryEventStoreInternal(input, hooks) {
30
37
  catch (cause) {
31
38
  return result_1.Result.err(event_store_error_1.EventStoreError.configuration("storage", "storage could not be read", cause));
32
39
  }
40
+ let unknownSetting;
41
+ try {
42
+ unknownSetting = Object.keys(input !== null && input !== void 0 ? input : {}).find((key) => !knownSettings.has(key));
43
+ }
44
+ catch (cause) {
45
+ return result_1.Result.err(event_store_error_1.EventStoreError.configuration("input", "input settings could not be read", cause));
46
+ }
47
+ if (unknownSetting !== undefined) {
48
+ return result_1.Result.err(event_store_error_1.EventStoreError.configuration(unknownSetting, "unsupported Memory setting; retention belongs to MemoryStorage.create"));
49
+ }
50
+ if (inputStorage !== undefined && !(0, memory_storage_records_1.isRegisteredMemoryStorage)(inputStorage)) {
51
+ return result_1.Result.err(event_store_error_1.EventStoreError.configuration("storage", "storage must be created by MemoryStorage.create"));
52
+ }
33
53
  const storage = inputStorage === undefined
34
54
  ? memory_storage_1.MemoryStorage.create()
35
55
  : result_1.Result.ok(inputStorage);
@@ -25,6 +25,7 @@ type AggregateRecords = Readonly<{
25
25
  history: readonly SnapshotEnvelope<Uint8Array>[];
26
26
  }>;
27
27
  export declare function createMemoryStorageRecords(configuration: Configuration): MemoryStorage;
28
+ export declare function isRegisteredMemoryStorage(storage: unknown): boolean;
28
29
  /** 検査済みのキーと開始番号で、同じ排他制御内に全件の独立した記録を確保する。 */
29
30
  export declare function readMemoryStorageEvents(storage: MemoryStorage, aggregateId: string, seqNr: number, beforeRead?: () => void | Promise<void>): Promise<Result<StoredEvent[], EventStoreError>>;
30
31
  /** 検査済みのキーで、同じ排他制御内にヘッド番号と独立したsnapshotを確保する。 */
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.createMemoryStorageRecords = createMemoryStorageRecords;
13
+ exports.isRegisteredMemoryStorage = isRegisteredMemoryStorage;
13
14
  exports.readMemoryStorageEvents = readMemoryStorageEvents;
14
15
  exports.readMemoryStorageLatestSnapshot = readMemoryStorageLatestSnapshot;
15
16
  exports.commitMemoryStorageRecords = commitMemoryStorageRecords;
@@ -30,6 +31,10 @@ function createMemoryStorageRecords(configuration) {
30
31
  });
31
32
  return storage;
32
33
  }
34
+ function isRegisteredMemoryStorage(storage) {
35
+ // WeakMap.has は、オブジェクト以外の値には false を返す。
36
+ return states.has(storage);
37
+ }
33
38
  function stateOf(storage) {
34
39
  const state = states.get(storage);
35
40
  if (state === undefined)
@@ -1,6 +1,6 @@
1
1
  # DynamoDBのテーブル構成
2
2
 
3
- 同一リージョンに独立した3表を作成します。表作成は呼び出し側が行い、`EventStore.createDynamoDB` が共通設定項目を照合します。表名と履歴index名は入力で指定します。
3
+ 同一リージョンに独立した3表を作成します。3 つの表は同じリージョンに置き、書き込みもそのリージョンからだけ行ってください。グローバルテーブル(複数リージョンのレプリカ)は範囲外です。表作成は呼び出し側が行い、`EventStore.createDynamoDB` が共通設定項目を照合します。表名と履歴index名は入力で指定します。
4
4
 
5
5
  | 表 | パーティションキー | ソートキー | Index / Streams |
6
6
  | --- | --- | --- | --- |
@@ -1,6 +1,6 @@
1
1
  # DynamoDB schema
2
2
 
3
- Use three distinct tables in one region. The caller creates them; `EventStore.createDynamoDB` verifies shared configuration records. Table names and the history index name come from its input.
3
+ Use three distinct tables in one region. Keep the three tables in one Region and write to them only from that Region. Global tables (multi-Region replicas) are not supported. The caller creates them; `EventStore.createDynamoDB` verifies shared configuration records. Table names and the history index name come from its input.
4
4
 
5
5
  | Table | Partition key | Sort key | Index / Streams |
6
6
  | --- | --- | --- | --- |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "event-store-adapter-js",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "This library is designed to turn DynamoDB into an Event Store for Event Sourcing.",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"