@emmett-community/emmett-google-firestore 0.1.0 → 0.2.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/README.md +16 -30
- package/dist/index.d.mts +120 -4
- package/dist/index.d.ts +120 -4
- package/package.json +9 -17
- package/dist/testing/index.d.mts +0 -115
- package/dist/testing/index.d.ts +0 -115
- package/dist/testing/index.js +0 -296
- package/dist/testing/index.js.map +0 -1
- package/dist/testing/index.mjs +0 -289
- package/dist/testing/index.mjs.map +0 -1
- package/dist/types-CHnx_sMk.d.mts +0 -122
- package/dist/types-CHnx_sMk.d.ts +0 -122
package/README.md
CHANGED
|
@@ -234,38 +234,17 @@ const state = await eventStore.aggregateStream(
|
|
|
234
234
|
|
|
235
235
|
## Testing
|
|
236
236
|
|
|
237
|
-
### Testing Utilities
|
|
238
|
-
|
|
239
|
-
The package includes utilities to make testing easier:
|
|
240
|
-
|
|
241
|
-
```typescript
|
|
242
|
-
import {
|
|
243
|
-
setupFirestoreTests,
|
|
244
|
-
getTestFirestore,
|
|
245
|
-
clearFirestore,
|
|
246
|
-
} from '@emmett-community/emmett-google-firestore/testing';
|
|
247
|
-
|
|
248
|
-
describe('My Tests', () => {
|
|
249
|
-
const { firestore, eventStore, cleanup, clearData } = setupFirestoreTests();
|
|
250
|
-
|
|
251
|
-
afterAll(cleanup);
|
|
252
|
-
beforeEach(clearData);
|
|
253
|
-
|
|
254
|
-
it('should work', async () => {
|
|
255
|
-
await eventStore.appendToStream('test-stream', [/* events */]);
|
|
256
|
-
// ... assertions
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
```
|
|
260
|
-
|
|
261
237
|
### Running Tests
|
|
262
238
|
|
|
263
239
|
```bash
|
|
264
240
|
# Unit tests
|
|
265
241
|
npm run test:unit
|
|
266
242
|
|
|
267
|
-
# Integration tests (
|
|
268
|
-
npm run test:
|
|
243
|
+
# Integration tests (in-memory)
|
|
244
|
+
npm run test:int
|
|
245
|
+
|
|
246
|
+
# E2E tests (Firestore Emulator via Testcontainers, requires Docker)
|
|
247
|
+
npm run test:e2e
|
|
269
248
|
|
|
270
249
|
# All tests
|
|
271
250
|
npm test
|
|
@@ -274,9 +253,17 @@ npm test
|
|
|
274
253
|
npm run test:coverage
|
|
275
254
|
```
|
|
276
255
|
|
|
256
|
+
Test files live in `test/` and are selected by filename suffix:
|
|
257
|
+
|
|
258
|
+
- `*.unit.spec.ts` (unit tests, pure logic)
|
|
259
|
+
- `*.int.spec.ts` (integration tests, in-memory Firestore)
|
|
260
|
+
- `*.e2e.spec.ts` (E2E tests, Firestore emulator via Testcontainers)
|
|
261
|
+
|
|
262
|
+
Support fixtures live under `test/support` (including Firebase emulator configs in `test/support/firebase`).
|
|
263
|
+
|
|
277
264
|
### Using Firestore Emulator
|
|
278
265
|
|
|
279
|
-
For local development and testing:
|
|
266
|
+
For local development and manual testing:
|
|
280
267
|
|
|
281
268
|
```bash
|
|
282
269
|
# Install Firebase CLI
|
|
@@ -284,9 +271,6 @@ npm install -g firebase-tools
|
|
|
284
271
|
|
|
285
272
|
# Start emulator
|
|
286
273
|
firebase emulators:start --only firestore
|
|
287
|
-
|
|
288
|
-
# Or use the provided script
|
|
289
|
-
./scripts/start-emulator.sh
|
|
290
274
|
```
|
|
291
275
|
|
|
292
276
|
Set environment variables:
|
|
@@ -296,6 +280,8 @@ export FIRESTORE_PROJECT_ID=test-project
|
|
|
296
280
|
export FIRESTORE_EMULATOR_HOST=localhost:8080
|
|
297
281
|
```
|
|
298
282
|
|
|
283
|
+
E2E tests start the emulator automatically via Testcontainers.
|
|
284
|
+
|
|
299
285
|
## Examples
|
|
300
286
|
|
|
301
287
|
### Complete Shopping Cart Example
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,125 @@
|
|
|
1
1
|
import { Firestore, Timestamp } from '@google-cloud/firestore';
|
|
2
|
-
import {
|
|
3
|
-
export { A as AppendToStreamOptions, d as AppendToStreamResult, C as CollectionConfig, e as EventDocument, f as ExpectedVersionConflictError, b as FirestoreReadEvent, c as FirestoreReadEventMetadata, R as ReadStreamOptions, S as StreamMetadata } from './types-CHnx_sMk.mjs';
|
|
4
|
-
import { STREAM_DOES_NOT_EXIST } from '@event-driven-io/emmett';
|
|
2
|
+
import { Event, ReadEvent, ReadEventMetadataWithGlobalPosition, ExpectedStreamVersion as ExpectedStreamVersion$1, STREAM_DOES_NOT_EXIST } from '@event-driven-io/emmett';
|
|
5
3
|
export { NO_CONCURRENCY_CHECK, STREAM_DOES_NOT_EXIST, STREAM_EXISTS } from '@event-driven-io/emmett';
|
|
6
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Expected version for stream operations
|
|
7
|
+
* Uses Emmett's standard version constants for full compatibility
|
|
8
|
+
* - number | bigint: Expect specific version
|
|
9
|
+
* - STREAM_DOES_NOT_EXIST: Stream must not exist
|
|
10
|
+
* - STREAM_EXISTS: Stream must exist (any version)
|
|
11
|
+
* - NO_CONCURRENCY_CHECK: No version check
|
|
12
|
+
*/
|
|
13
|
+
type ExpectedStreamVersion = ExpectedStreamVersion$1<bigint>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Options for appending events to a stream
|
|
17
|
+
*/
|
|
18
|
+
interface AppendToStreamOptions {
|
|
19
|
+
expectedStreamVersion?: ExpectedStreamVersion;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Result of appending events to a stream
|
|
23
|
+
*/
|
|
24
|
+
interface AppendToStreamResult {
|
|
25
|
+
nextExpectedStreamVersion: bigint;
|
|
26
|
+
createdNewStream: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Options for reading events from a stream
|
|
30
|
+
*/
|
|
31
|
+
interface ReadStreamOptions {
|
|
32
|
+
from?: bigint;
|
|
33
|
+
to?: bigint;
|
|
34
|
+
maxCount?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Metadata stored in Firestore stream document
|
|
38
|
+
*/
|
|
39
|
+
interface StreamMetadata {
|
|
40
|
+
version: number;
|
|
41
|
+
createdAt: Timestamp;
|
|
42
|
+
updatedAt: Timestamp;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Event document structure in Firestore
|
|
46
|
+
*/
|
|
47
|
+
interface EventDocument {
|
|
48
|
+
type: string;
|
|
49
|
+
data: Record<string, unknown>;
|
|
50
|
+
metadata?: Record<string, unknown>;
|
|
51
|
+
timestamp: Timestamp;
|
|
52
|
+
globalPosition: number;
|
|
53
|
+
streamVersion: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Firestore-specific read event metadata
|
|
57
|
+
*/
|
|
58
|
+
interface FirestoreReadEventMetadata extends ReadEventMetadataWithGlobalPosition {
|
|
59
|
+
streamName: string;
|
|
60
|
+
streamVersion: bigint;
|
|
61
|
+
timestamp: Date;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Firestore read event
|
|
65
|
+
*/
|
|
66
|
+
type FirestoreReadEvent<EventType extends Event = Event> = ReadEvent<EventType, FirestoreReadEventMetadata>;
|
|
67
|
+
/**
|
|
68
|
+
* Collection configuration for Firestore event store
|
|
69
|
+
*/
|
|
70
|
+
interface CollectionConfig {
|
|
71
|
+
streams: string;
|
|
72
|
+
counters: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Firestore event store options
|
|
76
|
+
*/
|
|
77
|
+
interface FirestoreEventStoreOptions {
|
|
78
|
+
collections?: Partial<CollectionConfig>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Firestore event store interface
|
|
82
|
+
*/
|
|
83
|
+
interface FirestoreEventStore {
|
|
84
|
+
/**
|
|
85
|
+
* The underlying Firestore instance
|
|
86
|
+
*/
|
|
87
|
+
readonly firestore: Firestore;
|
|
88
|
+
/**
|
|
89
|
+
* Collection names configuration
|
|
90
|
+
*/
|
|
91
|
+
readonly collections: CollectionConfig;
|
|
92
|
+
/**
|
|
93
|
+
* Read events from a stream
|
|
94
|
+
*/
|
|
95
|
+
readStream<EventType extends Event>(streamName: string, options?: ReadStreamOptions): Promise<FirestoreReadEvent<EventType>[]>;
|
|
96
|
+
/**
|
|
97
|
+
* Aggregate stream by applying events to state
|
|
98
|
+
*/
|
|
99
|
+
aggregateStream<State, EventType extends Event>(streamName: string, options: {
|
|
100
|
+
evolve: (state: State, event: FirestoreReadEvent<EventType>) => State;
|
|
101
|
+
initialState: () => State;
|
|
102
|
+
read?: ReadStreamOptions;
|
|
103
|
+
}): Promise<{
|
|
104
|
+
state: State;
|
|
105
|
+
currentStreamVersion: bigint;
|
|
106
|
+
streamExists: boolean;
|
|
107
|
+
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Append events to a stream
|
|
110
|
+
*/
|
|
111
|
+
appendToStream<EventType extends Event>(streamName: string, events: EventType[], options?: AppendToStreamOptions): Promise<AppendToStreamResult>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Error thrown when expected version doesn't match current version
|
|
115
|
+
*/
|
|
116
|
+
declare class ExpectedVersionConflictError extends Error {
|
|
117
|
+
readonly streamName: string;
|
|
118
|
+
readonly expected: ExpectedStreamVersion;
|
|
119
|
+
readonly actual: bigint | typeof STREAM_DOES_NOT_EXIST;
|
|
120
|
+
constructor(streamName: string, expected: ExpectedStreamVersion, actual: bigint | typeof STREAM_DOES_NOT_EXIST);
|
|
121
|
+
}
|
|
122
|
+
|
|
7
123
|
/**
|
|
8
124
|
* Factory function to create a Firestore event store
|
|
9
125
|
*
|
|
@@ -82,4 +198,4 @@ declare function getCurrentStreamVersion(streamExists: boolean, version?: number
|
|
|
82
198
|
*/
|
|
83
199
|
declare function calculateNextVersion(currentVersion: bigint | typeof STREAM_DOES_NOT_EXIST, eventCount: number): bigint;
|
|
84
200
|
|
|
85
|
-
export { ExpectedStreamVersion, FirestoreEventStore, FirestoreEventStoreOptions, assertExpectedVersionMatchesCurrent, calculateNextVersion, getCurrentStreamVersion, getFirestoreEventStore, padVersion, parseStreamName, timestampToDate };
|
|
201
|
+
export { type AppendToStreamOptions, type AppendToStreamResult, type CollectionConfig, type EventDocument, type ExpectedStreamVersion, ExpectedVersionConflictError, type FirestoreEventStore, type FirestoreEventStoreOptions, type FirestoreReadEvent, type FirestoreReadEventMetadata, type ReadStreamOptions, type StreamMetadata, assertExpectedVersionMatchesCurrent, calculateNextVersion, getCurrentStreamVersion, getFirestoreEventStore, padVersion, parseStreamName, timestampToDate };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,125 @@
|
|
|
1
1
|
import { Firestore, Timestamp } from '@google-cloud/firestore';
|
|
2
|
-
import {
|
|
3
|
-
export { A as AppendToStreamOptions, d as AppendToStreamResult, C as CollectionConfig, e as EventDocument, f as ExpectedVersionConflictError, b as FirestoreReadEvent, c as FirestoreReadEventMetadata, R as ReadStreamOptions, S as StreamMetadata } from './types-CHnx_sMk.js';
|
|
4
|
-
import { STREAM_DOES_NOT_EXIST } from '@event-driven-io/emmett';
|
|
2
|
+
import { Event, ReadEvent, ReadEventMetadataWithGlobalPosition, ExpectedStreamVersion as ExpectedStreamVersion$1, STREAM_DOES_NOT_EXIST } from '@event-driven-io/emmett';
|
|
5
3
|
export { NO_CONCURRENCY_CHECK, STREAM_DOES_NOT_EXIST, STREAM_EXISTS } from '@event-driven-io/emmett';
|
|
6
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Expected version for stream operations
|
|
7
|
+
* Uses Emmett's standard version constants for full compatibility
|
|
8
|
+
* - number | bigint: Expect specific version
|
|
9
|
+
* - STREAM_DOES_NOT_EXIST: Stream must not exist
|
|
10
|
+
* - STREAM_EXISTS: Stream must exist (any version)
|
|
11
|
+
* - NO_CONCURRENCY_CHECK: No version check
|
|
12
|
+
*/
|
|
13
|
+
type ExpectedStreamVersion = ExpectedStreamVersion$1<bigint>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Options for appending events to a stream
|
|
17
|
+
*/
|
|
18
|
+
interface AppendToStreamOptions {
|
|
19
|
+
expectedStreamVersion?: ExpectedStreamVersion;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Result of appending events to a stream
|
|
23
|
+
*/
|
|
24
|
+
interface AppendToStreamResult {
|
|
25
|
+
nextExpectedStreamVersion: bigint;
|
|
26
|
+
createdNewStream: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Options for reading events from a stream
|
|
30
|
+
*/
|
|
31
|
+
interface ReadStreamOptions {
|
|
32
|
+
from?: bigint;
|
|
33
|
+
to?: bigint;
|
|
34
|
+
maxCount?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Metadata stored in Firestore stream document
|
|
38
|
+
*/
|
|
39
|
+
interface StreamMetadata {
|
|
40
|
+
version: number;
|
|
41
|
+
createdAt: Timestamp;
|
|
42
|
+
updatedAt: Timestamp;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Event document structure in Firestore
|
|
46
|
+
*/
|
|
47
|
+
interface EventDocument {
|
|
48
|
+
type: string;
|
|
49
|
+
data: Record<string, unknown>;
|
|
50
|
+
metadata?: Record<string, unknown>;
|
|
51
|
+
timestamp: Timestamp;
|
|
52
|
+
globalPosition: number;
|
|
53
|
+
streamVersion: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Firestore-specific read event metadata
|
|
57
|
+
*/
|
|
58
|
+
interface FirestoreReadEventMetadata extends ReadEventMetadataWithGlobalPosition {
|
|
59
|
+
streamName: string;
|
|
60
|
+
streamVersion: bigint;
|
|
61
|
+
timestamp: Date;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Firestore read event
|
|
65
|
+
*/
|
|
66
|
+
type FirestoreReadEvent<EventType extends Event = Event> = ReadEvent<EventType, FirestoreReadEventMetadata>;
|
|
67
|
+
/**
|
|
68
|
+
* Collection configuration for Firestore event store
|
|
69
|
+
*/
|
|
70
|
+
interface CollectionConfig {
|
|
71
|
+
streams: string;
|
|
72
|
+
counters: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Firestore event store options
|
|
76
|
+
*/
|
|
77
|
+
interface FirestoreEventStoreOptions {
|
|
78
|
+
collections?: Partial<CollectionConfig>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Firestore event store interface
|
|
82
|
+
*/
|
|
83
|
+
interface FirestoreEventStore {
|
|
84
|
+
/**
|
|
85
|
+
* The underlying Firestore instance
|
|
86
|
+
*/
|
|
87
|
+
readonly firestore: Firestore;
|
|
88
|
+
/**
|
|
89
|
+
* Collection names configuration
|
|
90
|
+
*/
|
|
91
|
+
readonly collections: CollectionConfig;
|
|
92
|
+
/**
|
|
93
|
+
* Read events from a stream
|
|
94
|
+
*/
|
|
95
|
+
readStream<EventType extends Event>(streamName: string, options?: ReadStreamOptions): Promise<FirestoreReadEvent<EventType>[]>;
|
|
96
|
+
/**
|
|
97
|
+
* Aggregate stream by applying events to state
|
|
98
|
+
*/
|
|
99
|
+
aggregateStream<State, EventType extends Event>(streamName: string, options: {
|
|
100
|
+
evolve: (state: State, event: FirestoreReadEvent<EventType>) => State;
|
|
101
|
+
initialState: () => State;
|
|
102
|
+
read?: ReadStreamOptions;
|
|
103
|
+
}): Promise<{
|
|
104
|
+
state: State;
|
|
105
|
+
currentStreamVersion: bigint;
|
|
106
|
+
streamExists: boolean;
|
|
107
|
+
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Append events to a stream
|
|
110
|
+
*/
|
|
111
|
+
appendToStream<EventType extends Event>(streamName: string, events: EventType[], options?: AppendToStreamOptions): Promise<AppendToStreamResult>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Error thrown when expected version doesn't match current version
|
|
115
|
+
*/
|
|
116
|
+
declare class ExpectedVersionConflictError extends Error {
|
|
117
|
+
readonly streamName: string;
|
|
118
|
+
readonly expected: ExpectedStreamVersion;
|
|
119
|
+
readonly actual: bigint | typeof STREAM_DOES_NOT_EXIST;
|
|
120
|
+
constructor(streamName: string, expected: ExpectedStreamVersion, actual: bigint | typeof STREAM_DOES_NOT_EXIST);
|
|
121
|
+
}
|
|
122
|
+
|
|
7
123
|
/**
|
|
8
124
|
* Factory function to create a Firestore event store
|
|
9
125
|
*
|
|
@@ -82,4 +198,4 @@ declare function getCurrentStreamVersion(streamExists: boolean, version?: number
|
|
|
82
198
|
*/
|
|
83
199
|
declare function calculateNextVersion(currentVersion: bigint | typeof STREAM_DOES_NOT_EXIST, eventCount: number): bigint;
|
|
84
200
|
|
|
85
|
-
export { ExpectedStreamVersion, FirestoreEventStore, FirestoreEventStoreOptions, assertExpectedVersionMatchesCurrent, calculateNextVersion, getCurrentStreamVersion, getFirestoreEventStore, padVersion, parseStreamName, timestampToDate };
|
|
201
|
+
export { type AppendToStreamOptions, type AppendToStreamResult, type CollectionConfig, type EventDocument, type ExpectedStreamVersion, ExpectedVersionConflictError, type FirestoreEventStore, type FirestoreEventStoreOptions, type FirestoreReadEvent, type FirestoreReadEventMetadata, type ReadStreamOptions, type StreamMetadata, assertExpectedVersionMatchesCurrent, calculateNextVersion, getCurrentStreamVersion, getFirestoreEventStore, padVersion, parseStreamName, timestampToDate };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emmett-community/emmett-google-firestore",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Google Firestore event store implementation for Emmett",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -15,16 +15,6 @@
|
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"default": "./dist/index.js"
|
|
17
17
|
}
|
|
18
|
-
},
|
|
19
|
-
"./testing": {
|
|
20
|
-
"import": {
|
|
21
|
-
"types": "./dist/testing/index.d.mts",
|
|
22
|
-
"default": "./dist/testing/index.mjs"
|
|
23
|
-
},
|
|
24
|
-
"require": {
|
|
25
|
-
"types": "./dist/testing/index.d.ts",
|
|
26
|
-
"default": "./dist/testing/index.js"
|
|
27
|
-
}
|
|
28
18
|
}
|
|
29
19
|
},
|
|
30
20
|
"files": [
|
|
@@ -33,12 +23,13 @@
|
|
|
33
23
|
"scripts": {
|
|
34
24
|
"build": "tsup",
|
|
35
25
|
"build:ts": "tsc --noEmit",
|
|
36
|
-
"test": "
|
|
37
|
-
"test:unit": "jest
|
|
38
|
-
"test:
|
|
39
|
-
"test:
|
|
40
|
-
"test:
|
|
41
|
-
"test:
|
|
26
|
+
"test": "npm run test:unit && npm run test:int && npm run test:e2e",
|
|
27
|
+
"test:unit": "jest --testMatch \"**/*.unit.spec.ts\" --watchman=false",
|
|
28
|
+
"test:int": "jest --testMatch \"**/*.int.spec.ts\" --watchman=false",
|
|
29
|
+
"test:integration": "npm run test:int",
|
|
30
|
+
"test:e2e": "jest --testMatch \"**/*.e2e.spec.ts\" --watchman=false",
|
|
31
|
+
"test:watch": "jest --watch --watchman=false",
|
|
32
|
+
"test:coverage": "jest --coverage --watchman=false",
|
|
42
33
|
"lint": "eslint . --ext .ts",
|
|
43
34
|
"lint:fix": "eslint . --ext .ts --fix",
|
|
44
35
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
@@ -86,6 +77,7 @@
|
|
|
86
77
|
"prettier": "^3.4.2",
|
|
87
78
|
"ts-jest": "^29.2.5",
|
|
88
79
|
"ts-node": "^10.9.2",
|
|
80
|
+
"testcontainers": "^10.28.0",
|
|
89
81
|
"tsup": "^8.3.5",
|
|
90
82
|
"typescript": "^5.7.2"
|
|
91
83
|
},
|
package/dist/testing/index.d.mts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { Firestore } from '@google-cloud/firestore';
|
|
2
|
-
import { a as FirestoreEventStore } from '../types-CHnx_sMk.mjs';
|
|
3
|
-
import '@event-driven-io/emmett';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Testing utilities for Firestore Event Store
|
|
7
|
-
*
|
|
8
|
-
* These utilities help set up and manage the Firestore Emulator
|
|
9
|
-
* for testing purposes.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Configuration for Firestore test environment
|
|
14
|
-
*/
|
|
15
|
-
interface FirestoreTestConfig {
|
|
16
|
-
projectId?: string;
|
|
17
|
-
host?: string;
|
|
18
|
-
ssl?: boolean;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Get a Firestore instance configured for the emulator
|
|
22
|
-
*
|
|
23
|
-
* @param config - Optional configuration override
|
|
24
|
-
* @returns Configured Firestore instance
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* const firestore = getTestFirestore();
|
|
29
|
-
* // Use firestore for testing
|
|
30
|
-
* await firestore.terminate();
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
declare function getTestFirestore(config?: FirestoreTestConfig): Firestore;
|
|
34
|
-
/**
|
|
35
|
-
* Get a test event store instance connected to the emulator
|
|
36
|
-
*
|
|
37
|
-
* @param config - Optional configuration override
|
|
38
|
-
* @returns FirestoreEventStore instance for testing
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```typescript
|
|
42
|
-
* const eventStore = getTestEventStore();
|
|
43
|
-
* // Use eventStore for testing
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
declare function getTestEventStore(config?: FirestoreTestConfig): FirestoreEventStore;
|
|
47
|
-
/**
|
|
48
|
-
* Clear all data from a Firestore instance
|
|
49
|
-
* Useful for cleaning up between tests
|
|
50
|
-
*
|
|
51
|
-
* @param firestore - Firestore instance to clear
|
|
52
|
-
* @param batchSize - Number of documents to delete per batch
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* beforeEach(async () => {
|
|
57
|
-
* await clearFirestore(firestore);
|
|
58
|
-
* });
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
declare function clearFirestore(firestore: Firestore, batchSize?: number): Promise<void>;
|
|
62
|
-
/**
|
|
63
|
-
* Delete a specific collection from Firestore
|
|
64
|
-
*
|
|
65
|
-
* @param firestore - Firestore instance
|
|
66
|
-
* @param collectionPath - Path to the collection to delete
|
|
67
|
-
* @param batchSize - Number of documents to delete per batch
|
|
68
|
-
*/
|
|
69
|
-
declare function deleteCollection(firestore: Firestore, collectionPath: string, batchSize?: number): Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Wait for the Firestore emulator to be ready
|
|
72
|
-
*
|
|
73
|
-
* @param host - Emulator host (default: localhost:8080)
|
|
74
|
-
* @param timeout - Maximum time to wait in milliseconds (default: 30000)
|
|
75
|
-
* @param interval - Check interval in milliseconds (default: 100)
|
|
76
|
-
* @returns Promise that resolves when emulator is ready
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```typescript
|
|
80
|
-
* await waitForEmulator();
|
|
81
|
-
* // Emulator is ready
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
declare function waitForEmulator(host?: string, timeout?: number, interval?: number): Promise<void>;
|
|
85
|
-
/**
|
|
86
|
-
* Setup function for Jest/Vitest tests with Firestore emulator
|
|
87
|
-
*
|
|
88
|
-
* @returns Object with firestore instance and cleanup function
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* describe('My Tests', () => {
|
|
93
|
-
* const { firestore, cleanup } = setupFirestoreTests();
|
|
94
|
-
*
|
|
95
|
-
* afterAll(cleanup);
|
|
96
|
-
*
|
|
97
|
-
* beforeEach(async () => {
|
|
98
|
-
* await clearFirestore(firestore);
|
|
99
|
-
* });
|
|
100
|
-
*
|
|
101
|
-
* it('should work', async () => {
|
|
102
|
-
* const eventStore = getFirestoreEventStore(firestore);
|
|
103
|
-
* // ... test code
|
|
104
|
-
* });
|
|
105
|
-
* });
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
declare function setupFirestoreTests(config?: FirestoreTestConfig): {
|
|
109
|
-
firestore: Firestore;
|
|
110
|
-
eventStore: FirestoreEventStore;
|
|
111
|
-
cleanup: () => Promise<void>;
|
|
112
|
-
clearData: () => Promise<void>;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export { type FirestoreTestConfig, clearFirestore, deleteCollection, getTestEventStore, getTestFirestore, setupFirestoreTests, waitForEmulator };
|
package/dist/testing/index.d.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { Firestore } from '@google-cloud/firestore';
|
|
2
|
-
import { a as FirestoreEventStore } from '../types-CHnx_sMk.js';
|
|
3
|
-
import '@event-driven-io/emmett';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Testing utilities for Firestore Event Store
|
|
7
|
-
*
|
|
8
|
-
* These utilities help set up and manage the Firestore Emulator
|
|
9
|
-
* for testing purposes.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Configuration for Firestore test environment
|
|
14
|
-
*/
|
|
15
|
-
interface FirestoreTestConfig {
|
|
16
|
-
projectId?: string;
|
|
17
|
-
host?: string;
|
|
18
|
-
ssl?: boolean;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Get a Firestore instance configured for the emulator
|
|
22
|
-
*
|
|
23
|
-
* @param config - Optional configuration override
|
|
24
|
-
* @returns Configured Firestore instance
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* const firestore = getTestFirestore();
|
|
29
|
-
* // Use firestore for testing
|
|
30
|
-
* await firestore.terminate();
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
declare function getTestFirestore(config?: FirestoreTestConfig): Firestore;
|
|
34
|
-
/**
|
|
35
|
-
* Get a test event store instance connected to the emulator
|
|
36
|
-
*
|
|
37
|
-
* @param config - Optional configuration override
|
|
38
|
-
* @returns FirestoreEventStore instance for testing
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```typescript
|
|
42
|
-
* const eventStore = getTestEventStore();
|
|
43
|
-
* // Use eventStore for testing
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
declare function getTestEventStore(config?: FirestoreTestConfig): FirestoreEventStore;
|
|
47
|
-
/**
|
|
48
|
-
* Clear all data from a Firestore instance
|
|
49
|
-
* Useful for cleaning up between tests
|
|
50
|
-
*
|
|
51
|
-
* @param firestore - Firestore instance to clear
|
|
52
|
-
* @param batchSize - Number of documents to delete per batch
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* beforeEach(async () => {
|
|
57
|
-
* await clearFirestore(firestore);
|
|
58
|
-
* });
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
declare function clearFirestore(firestore: Firestore, batchSize?: number): Promise<void>;
|
|
62
|
-
/**
|
|
63
|
-
* Delete a specific collection from Firestore
|
|
64
|
-
*
|
|
65
|
-
* @param firestore - Firestore instance
|
|
66
|
-
* @param collectionPath - Path to the collection to delete
|
|
67
|
-
* @param batchSize - Number of documents to delete per batch
|
|
68
|
-
*/
|
|
69
|
-
declare function deleteCollection(firestore: Firestore, collectionPath: string, batchSize?: number): Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Wait for the Firestore emulator to be ready
|
|
72
|
-
*
|
|
73
|
-
* @param host - Emulator host (default: localhost:8080)
|
|
74
|
-
* @param timeout - Maximum time to wait in milliseconds (default: 30000)
|
|
75
|
-
* @param interval - Check interval in milliseconds (default: 100)
|
|
76
|
-
* @returns Promise that resolves when emulator is ready
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```typescript
|
|
80
|
-
* await waitForEmulator();
|
|
81
|
-
* // Emulator is ready
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
declare function waitForEmulator(host?: string, timeout?: number, interval?: number): Promise<void>;
|
|
85
|
-
/**
|
|
86
|
-
* Setup function for Jest/Vitest tests with Firestore emulator
|
|
87
|
-
*
|
|
88
|
-
* @returns Object with firestore instance and cleanup function
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* describe('My Tests', () => {
|
|
93
|
-
* const { firestore, cleanup } = setupFirestoreTests();
|
|
94
|
-
*
|
|
95
|
-
* afterAll(cleanup);
|
|
96
|
-
*
|
|
97
|
-
* beforeEach(async () => {
|
|
98
|
-
* await clearFirestore(firestore);
|
|
99
|
-
* });
|
|
100
|
-
*
|
|
101
|
-
* it('should work', async () => {
|
|
102
|
-
* const eventStore = getFirestoreEventStore(firestore);
|
|
103
|
-
* // ... test code
|
|
104
|
-
* });
|
|
105
|
-
* });
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
declare function setupFirestoreTests(config?: FirestoreTestConfig): {
|
|
109
|
-
firestore: Firestore;
|
|
110
|
-
eventStore: FirestoreEventStore;
|
|
111
|
-
cleanup: () => Promise<void>;
|
|
112
|
-
clearData: () => Promise<void>;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export { type FirestoreTestConfig, clearFirestore, deleteCollection, getTestEventStore, getTestFirestore, setupFirestoreTests, waitForEmulator };
|