@cratis/chronicle.contracts 19.6.1 → 19.7.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.md +12 -222
- package/dist/cjs/generated/descriptorSet.js +1 -1
- package/dist/cjs/generated/descriptorSet.js.map +1 -1
- package/dist/cjs/generated/index.d.ts +2 -0
- package/dist/cjs/generated/index.d.ts.map +1 -1
- package/dist/cjs/generated/projections.d.ts +3 -0
- package/dist/cjs/generated/projections.d.ts.map +1 -1
- package/dist/cjs/generated/projections.js +28 -1
- package/dist/cjs/generated/projections.js.map +1 -1
- package/dist/cjs/generated/statistics.d.ts +94 -0
- package/dist/cjs/generated/statistics.d.ts.map +1 -0
- package/dist/cjs/generated/statistics.js +665 -0
- package/dist/cjs/generated/statistics.js.map +1 -0
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/generated/descriptorSet.js +1 -1
- package/dist/esm/generated/descriptorSet.js.map +1 -1
- package/dist/esm/generated/index.d.ts +2 -0
- package/dist/esm/generated/index.d.ts.map +1 -1
- package/dist/esm/generated/projections.d.ts +3 -0
- package/dist/esm/generated/projections.d.ts.map +1 -1
- package/dist/esm/generated/projections.js +28 -1
- package/dist/esm/generated/projections.js.map +1 -1
- package/dist/esm/generated/statistics.d.ts +94 -0
- package/dist/esm/generated/statistics.d.ts.map +1 -0
- package/dist/esm/generated/statistics.js +655 -0
- package/dist/esm/generated/statistics.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/generated/descriptorSet.js +1 -1
- package/dist/generated/descriptorSet.js.map +1 -1
- package/dist/generated/index.d.ts +2 -0
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/generated/index.js +1 -0
- package/dist/generated/index.js.map +1 -1
- package/dist/generated/projections.d.ts +3 -0
- package/dist/generated/projections.d.ts.map +1 -1
- package/dist/generated/projections.js +28 -1
- package/dist/generated/projections.js.map +1 -1
- package/dist/generated/statistics.d.ts +94 -0
- package/dist/generated/statistics.d.ts.map +1 -0
- package/dist/generated/statistics.js +653 -0
- package/dist/generated/statistics.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/generated/descriptorSet.ts +1 -1
- package/generated/index.ts +3 -0
- package/generated/projections.ts +30 -1
- package/generated/statistics.ts +791 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,239 +20,29 @@ yarn add @cratis/chronicle.contracts
|
|
|
20
20
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
|
-
This package
|
|
23
|
+
This package contains only the generated contracts: a `*Definition` for every Chronicle gRPC service and a TypeScript type for every message, produced by [ts-proto](https://github.com/stephenh/ts-proto) for [nice-grpc](https://github.com/deeplay-io/nice-grpc). It has no connection string parsing, authentication, or retry handling.
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
**Building an application?** Use the idiomatic TypeScript client, [`@cratis/chronicle`](https://www.npmjs.com/package/@cratis/chronicle), which is built on these contracts. Reach for this package only when you are building a client or tool of your own.
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
import { ChronicleConnection } from '@cratis/chronicle.contracts';
|
|
29
|
-
|
|
30
|
-
// Create a connection using a connection string
|
|
31
|
-
const connection = new ChronicleConnection({
|
|
32
|
-
connectionString: 'chronicle://localhost:35000'
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// Connect to Chronicle
|
|
36
|
-
await connection.connect();
|
|
37
|
-
|
|
38
|
-
// Use the services with full type safety, IDE completion, and async/await
|
|
39
|
-
const eventStores = await connection.eventStores.getEventStores({});
|
|
40
|
-
console.log('Event stores:', eventStores.items);
|
|
41
|
-
|
|
42
|
-
// Clean up
|
|
43
|
-
connection.dispose();
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### Promise-Based API
|
|
47
|
-
|
|
48
|
-
All unary RPC methods now return Promises directly, enabling ergonomic async/await:
|
|
49
|
-
|
|
50
|
-
```typescript
|
|
51
|
-
// Simple Promise-based call
|
|
52
|
-
const namespaces = await connection.namespaces.getNamespaces({
|
|
53
|
-
eventStore: 'mystore'
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// Error handling
|
|
57
|
-
try {
|
|
58
|
-
await connection.recommendations.perform({
|
|
59
|
-
/* command */
|
|
60
|
-
});
|
|
61
|
-
} catch (error) {
|
|
62
|
-
console.error('Recommendation failed:', error);
|
|
63
|
-
}
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Server Streaming
|
|
67
|
-
|
|
68
|
-
Server streaming methods return `AsyncIterable` for easy iteration:
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
|
-
// Stream event store subscriptions
|
|
72
|
-
for await (const subscription of connection.server.subscribeEvents({
|
|
73
|
-
/* options */
|
|
74
|
-
})) {
|
|
75
|
-
console.log('Event:', subscription);
|
|
76
|
-
}
|
|
77
|
-
```
|
|
27
|
+
### Calling a service
|
|
78
28
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
Chronicle supports connection strings similar to database connection strings, providing a consistent way to configure connections:
|
|
29
|
+
The following excerpt shows the shape of a call. It is not a complete program: a real Chronicle server serves TLS on port `35000` — with a self-signed certificate in development — and expects a bearer token on every call, so you supply channel credentials and call metadata that fit your server.
|
|
82
30
|
|
|
83
31
|
```typescript
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
connectionString: 'chronicle://localhost:35000'
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// With client credentials (username:password)
|
|
90
|
-
const connection = new ChronicleConnection({
|
|
91
|
-
connectionString: 'chronicle://myuser:mypassword@localhost:35000'
|
|
92
|
-
});
|
|
32
|
+
import { createChannel, createClient, ChannelCredentials } from 'nice-grpc';
|
|
33
|
+
import { EventStoresDefinition } from '@cratis/chronicle.contracts';
|
|
93
34
|
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
connectionString: 'chronicle://localhost:35000?apiKey=your-api-key-here'
|
|
97
|
-
});
|
|
35
|
+
const channel = createChannel('localhost:35000', ChannelCredentials.createSsl());
|
|
36
|
+
const eventStores = createClient(EventStoresDefinition, channel);
|
|
98
37
|
|
|
99
|
-
|
|
100
|
-
const connection = new ChronicleConnection({
|
|
101
|
-
connectionString: 'chronicle://localhost:35000?disableTls=true'
|
|
102
|
-
});
|
|
38
|
+
const response = await eventStores.allEventStores({});
|
|
103
39
|
```
|
|
104
40
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
For local development, use the built-in development connection with default credentials:
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
import { ChronicleConnectionString } from '@cratis/chronicle.contracts';
|
|
111
|
-
|
|
112
|
-
const connection = new ChronicleConnection({
|
|
113
|
-
connectionString: ChronicleConnectionString.Development
|
|
114
|
-
});
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
The development connection string uses:
|
|
118
|
-
- **Client ID**: `chronicle-dev-client`
|
|
119
|
-
- **Client Secret**: `chronicle-dev-secret`
|
|
120
|
-
- **Host**: `localhost:35000`
|
|
121
|
-
|
|
122
|
-
These are the default development credentials that Chronicle Kernel accepts when running in development mode.
|
|
123
|
-
|
|
124
|
-
### Working with Connection Strings
|
|
125
|
-
|
|
126
|
-
```typescript
|
|
127
|
-
import { ChronicleConnectionString } from '@cratis/chronicle.contracts';
|
|
128
|
-
|
|
129
|
-
// Parse a connection string
|
|
130
|
-
const connStr = new ChronicleConnectionString('chronicle://localhost:35000');
|
|
131
|
-
|
|
132
|
-
// Access connection details
|
|
133
|
-
console.log(connStr.serverAddress.host); // 'localhost'
|
|
134
|
-
console.log(connStr.serverAddress.port); // 35000
|
|
135
|
-
|
|
136
|
-
// Create new connection strings with modifications
|
|
137
|
-
const withCreds = connStr.withCredentials('myuser', 'mypassword');
|
|
138
|
-
const withApiKey = connStr.withApiKey('my-api-key');
|
|
139
|
-
|
|
140
|
-
// Convert to string
|
|
141
|
-
console.log(withCreds.toString()); // chronicle://myuser:mypassword@localhost:35000
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
### Authentication
|
|
145
|
-
|
|
146
|
-
Chronicle supports two authentication modes. When using Client Credentials, the TypeScript client automatically obtains a bearer token from the authentication authority using OAuth 2.0 client_credentials flow.
|
|
147
|
-
|
|
148
|
-
#### Client Credentials (OAuth2 client_credentials flow)
|
|
149
|
-
|
|
150
|
-
The client automatically obtains and refreshes bearer tokens from the Chronicle server (or a custom authority):
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
const connection = new ChronicleConnection({
|
|
154
|
-
connectionString: 'chronicle://client-id:client-secret@localhost:35000'
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
// With custom authority
|
|
158
|
-
const connection = new ChronicleConnection({
|
|
159
|
-
connectionString: 'chronicle://client-id:client-secret@localhost:35000',
|
|
160
|
-
authority: 'https://my-auth-server.com'
|
|
161
|
-
});
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
The token endpoint is served on the same port as gRPC (the single Chronicle port). The token is
|
|
165
|
-
automatically included as a Bearer token in the authorization header for all gRPC calls.
|
|
166
|
-
|
|
167
|
-
#### API Key
|
|
168
|
-
|
|
169
|
-
```typescript
|
|
170
|
-
const connection = new ChronicleConnection({
|
|
171
|
-
connectionString: 'chronicle://localhost:35000?apiKey=your-api-key'
|
|
172
|
-
});
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### Using Individual Services
|
|
176
|
-
|
|
177
|
-
You can also import and use services directly:
|
|
178
|
-
|
|
179
|
-
```typescript
|
|
180
|
-
import { EventStoresClient } from '@cratis/chronicle.contracts';
|
|
181
|
-
import * as grpc from '@grpc/grpc-js';
|
|
182
|
-
|
|
183
|
-
const client = new EventStoresClient(
|
|
184
|
-
'localhost:35000',
|
|
185
|
-
grpc.credentials.createInsecure()
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
const response = await client.GetEventStores({});
|
|
189
|
-
console.log('Event stores:', response.items);
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### Configuration Options
|
|
193
|
-
|
|
194
|
-
```typescript
|
|
195
|
-
const connection = new ChronicleConnection({
|
|
196
|
-
connectionString: 'chronicle://localhost:35000',
|
|
197
|
-
|
|
198
|
-
// Optional: Override credentials from connection string
|
|
199
|
-
credentials: grpc.credentials.createSsl(),
|
|
200
|
-
|
|
201
|
-
// Optional: connection timeout in ms
|
|
202
|
-
connectTimeout: 10000,
|
|
203
|
-
|
|
204
|
-
// Optional: message size limits
|
|
205
|
-
maxReceiveMessageSize: 1024 * 1024 * 10, // 10MB
|
|
206
|
-
maxSendMessageSize: 1024 * 1024 * 10, // 10MB
|
|
207
|
-
|
|
208
|
-
// Optional: for request tracking
|
|
209
|
-
correlationId: 'my-correlation-id',
|
|
210
|
-
|
|
211
|
-
// Optional: Custom authentication authority URL
|
|
212
|
-
// If not set, uses Chronicle server as the authority
|
|
213
|
-
authority: 'https://my-auth-server.com'
|
|
214
|
-
});
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
### Legacy Server Address
|
|
218
|
-
|
|
219
|
-
For backward compatibility, you can still use `serverAddress`:
|
|
220
|
-
|
|
221
|
-
```typescript
|
|
222
|
-
const connection = new ChronicleConnection({
|
|
223
|
-
serverAddress: 'localhost:35000'
|
|
224
|
-
});
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
### Available Services
|
|
228
|
-
|
|
229
|
-
The `ChronicleConnection` provides access to all Chronicle services:
|
|
230
|
-
|
|
231
|
-
- `eventStores` - Event store management
|
|
232
|
-
- `namespaces` - Namespace management
|
|
233
|
-
- `recommendations` - Recommendations
|
|
234
|
-
- `identities` - Identity management
|
|
235
|
-
- `eventSequences` - Event sequence operations
|
|
236
|
-
- `eventTypes` - Event type management
|
|
237
|
-
- `constraints` - Event constraints
|
|
238
|
-
- `observers` - Observer management
|
|
239
|
-
- `failedPartitions` - Failed partition handling
|
|
240
|
-
- `reactors` - Reactor management
|
|
241
|
-
- `reducers` - Reducer management
|
|
242
|
-
- `projections` - Projection management
|
|
243
|
-
- `readModels` - Read model operations
|
|
244
|
-
- `jobs` - Job management
|
|
245
|
-
- `eventSeeding` - Event seeding
|
|
246
|
-
- `server` - Server information
|
|
247
|
-
|
|
248
|
-
### Type Safety
|
|
41
|
+
Each rpc in the `.proto` files becomes a camel-cased method on its client (`AllEventStores` becomes `allEventStores`). Unary calls return a `Promise`; server-streaming calls return an `AsyncIterable`.
|
|
249
42
|
|
|
250
|
-
|
|
43
|
+
### Type safety
|
|
251
44
|
|
|
252
|
-
|
|
253
|
-
- **Compile-time type checking**
|
|
254
|
-
- **Auto-completion** for all methods and parameters
|
|
255
|
-
- **Type inference** for request and response objects
|
|
45
|
+
Every service client and message is typed from the proto definitions, including `int64`/`uint64` fields represented as `bigint`.
|
|
256
46
|
|
|
257
47
|
## License
|
|
258
48
|
|