@livestore/sync-s2 0.0.0-snapshot-446f5de211c4578498f20693bd2998869be3e796

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/LICENSE +201 -0
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/api-schema.d.ts +32 -0
  4. package/dist/api-schema.d.ts.map +1 -0
  5. package/dist/api-schema.js +17 -0
  6. package/dist/api-schema.js.map +1 -0
  7. package/dist/api-schema.test.d.ts +2 -0
  8. package/dist/api-schema.test.d.ts.map +1 -0
  9. package/dist/api-schema.test.js +20 -0
  10. package/dist/api-schema.test.js.map +1 -0
  11. package/dist/decode.d.ts +11 -0
  12. package/dist/decode.d.ts.map +1 -0
  13. package/dist/decode.js +19 -0
  14. package/dist/decode.js.map +1 -0
  15. package/dist/http-client-generated.d.ts +1477 -0
  16. package/dist/http-client-generated.d.ts.map +1 -0
  17. package/dist/http-client-generated.js +830 -0
  18. package/dist/http-client-generated.js.map +1 -0
  19. package/dist/make-s2-url.d.ts +7 -0
  20. package/dist/make-s2-url.d.ts.map +1 -0
  21. package/dist/make-s2-url.js +16 -0
  22. package/dist/make-s2-url.js.map +1 -0
  23. package/dist/mod.d.ts +8 -0
  24. package/dist/mod.d.ts.map +1 -0
  25. package/dist/mod.js +7 -0
  26. package/dist/mod.js.map +1 -0
  27. package/dist/s2-proxy-helpers.d.ts +61 -0
  28. package/dist/s2-proxy-helpers.d.ts.map +1 -0
  29. package/dist/s2-proxy-helpers.js +143 -0
  30. package/dist/s2-proxy-helpers.js.map +1 -0
  31. package/dist/sync-provider.d.ts +60 -0
  32. package/dist/sync-provider.d.ts.map +1 -0
  33. package/dist/sync-provider.js +154 -0
  34. package/dist/sync-provider.js.map +1 -0
  35. package/dist/types.d.ts +25 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +13 -0
  38. package/dist/types.js.map +1 -0
  39. package/package.json +29 -0
  40. package/src/api-schema.test.ts +21 -0
  41. package/src/api-schema.ts +24 -0
  42. package/src/decode.ts +28 -0
  43. package/src/http-client-generated.ts +1341 -0
  44. package/src/make-s2-url.ts +23 -0
  45. package/src/mod.ts +7 -0
  46. package/src/s2-proxy-helpers.ts +196 -0
  47. package/src/sync-provider.ts +267 -0
  48. package/src/types.ts +26 -0
@@ -0,0 +1,830 @@
1
+ // Generated via forked version of https://github.com/tim-smart/openapi-gen
2
+ // in order to workaround https://github.com/tim-smart/openapi-gen/issues/75
3
+ // Further adjustments:
4
+ // 1) Use Effect imports from @livestore/utils/effect
5
+ // 2) Fixed CreateOrReconfigureBasinRequest to not be self-referencing
6
+ import { Data, Effect, HttpClientError, HttpClientRequest, HttpClientResponse, Schema as S, } from '@livestore/utils/effect';
7
+ export class ListAccessTokensParams extends S.Struct({
8
+ prefix: S.optionalWith(S.String, { nullable: true, default: () => '' }),
9
+ start_after: S.optionalWith(S.String, { nullable: true, default: () => '' }),
10
+ limit: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(0), S.lessThanOrEqualTo(1000)), {
11
+ nullable: true,
12
+ default: () => 1000,
13
+ }),
14
+ }) {
15
+ }
16
+ export class ResourceSet extends S.Union(
17
+ /**
18
+ * Match only the resource with this exact name.
19
+ * Use an empty string to match no resources.
20
+ */
21
+ S.Struct({
22
+ /**
23
+ * Match only the resource with this exact name.
24
+ * Use an empty string to match no resources.
25
+ */
26
+ exact: S.String,
27
+ }),
28
+ /**
29
+ * Match all resources that start with this prefix.
30
+ * Use an empty string to match all resource.
31
+ */
32
+ S.Struct({
33
+ /**
34
+ * Match all resources that start with this prefix.
35
+ * Use an empty string to match all resource.
36
+ */
37
+ prefix: S.String,
38
+ })) {
39
+ }
40
+ export class ReadWritePermissions extends S.Class('ReadWritePermissions')({
41
+ /**
42
+ * Read permission.
43
+ */
44
+ read: S.optionalWith(S.Boolean, { nullable: true, default: () => false }),
45
+ /**
46
+ * Write permission.
47
+ */
48
+ write: S.optionalWith(S.Boolean, { nullable: true, default: () => false }),
49
+ }) {
50
+ }
51
+ export class PermittedOperationGroups extends S.Class('PermittedOperationGroups')({
52
+ account: S.optionalWith(ReadWritePermissions, { nullable: true }),
53
+ basin: S.optionalWith(ReadWritePermissions, { nullable: true }),
54
+ stream: S.optionalWith(ReadWritePermissions, { nullable: true }),
55
+ }) {
56
+ }
57
+ export class Operation extends S.Literal('list-basins', 'create-basin', 'delete-basin', 'reconfigure-basin', 'get-basin-config', 'issue-access-token', 'revoke-access-token', 'list-access-tokens', 'list-streams', 'create-stream', 'delete-stream', 'get-stream-config', 'reconfigure-stream', 'check-tail', 'append', 'read', 'trim', 'fence', 'account-metrics', 'basin-metrics', 'stream-metrics') {
58
+ }
59
+ export class AccessTokenScope extends S.Class('AccessTokenScope')({
60
+ access_tokens: S.optionalWith(ResourceSet, { nullable: true }),
61
+ basins: S.optionalWith(ResourceSet, { nullable: true }),
62
+ op_groups: S.optionalWith(PermittedOperationGroups, { nullable: true }),
63
+ /**
64
+ * Operations allowed for the token.
65
+ * A union of allowed operations and groups is used as an effective set of allowed operations.
66
+ */
67
+ ops: S.optionalWith(S.Array(Operation), { nullable: true }),
68
+ streams: S.optionalWith(ResourceSet, { nullable: true }),
69
+ }) {
70
+ }
71
+ export class AccessTokenInfo extends S.Class('AccessTokenInfo')({
72
+ /**
73
+ * Namespace streams based on the configured stream-level scope, which must be a prefix.
74
+ * Stream name arguments will be automatically prefixed, and the prefix will be stripped when listing streams.
75
+ */
76
+ auto_prefix_streams: S.optionalWith(S.Boolean, { nullable: true, default: () => false }),
77
+ /**
78
+ * Expiration time in ISO 8601 format.
79
+ * If not set, the expiration will be set to that of the requestor's token.
80
+ */
81
+ expires_at: S.optionalWith(S.String, { nullable: true }),
82
+ /**
83
+ * Access token ID.
84
+ * It must be unique to the account and between 1 and 96 bytes in length.
85
+ */
86
+ id: S.String,
87
+ /**
88
+ * Access token scope.
89
+ */
90
+ scope: AccessTokenScope,
91
+ }) {
92
+ }
93
+ export class ListAccessTokensResponse extends S.Class('ListAccessTokensResponse')({
94
+ /**
95
+ * Matching access tokens.
96
+ */
97
+ access_tokens: S.Array(AccessTokenInfo).pipe(S.maxItems(1000)),
98
+ /**
99
+ * Indicates that there are more access tokens that match the criteria.
100
+ */
101
+ has_more: S.Boolean,
102
+ }) {
103
+ }
104
+ export class ErrorResponse extends S.Class('ErrorResponse')({
105
+ code: S.optionalWith(S.String, { nullable: true }),
106
+ message: S.String,
107
+ }) {
108
+ }
109
+ export class IssueAccessTokenResponse extends S.Class('IssueAccessTokenResponse')({
110
+ /**
111
+ * Created access token.
112
+ */
113
+ access_token: S.String,
114
+ }) {
115
+ }
116
+ export class ListBasinsParams extends S.Struct({
117
+ prefix: S.optionalWith(S.String, { nullable: true, default: () => '' }),
118
+ start_after: S.optionalWith(S.String, { nullable: true, default: () => '' }),
119
+ limit: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(0), S.lessThanOrEqualTo(1000)), {
120
+ nullable: true,
121
+ default: () => 1000,
122
+ }),
123
+ }) {
124
+ }
125
+ export class BasinScope extends S.Literal('aws:us-east-1') {
126
+ }
127
+ export class BasinState extends S.Literal('active', 'creating', 'deleting') {
128
+ }
129
+ export class BasinInfo extends S.Class('BasinInfo')({
130
+ /**
131
+ * Basin name.
132
+ */
133
+ name: S.String,
134
+ /**
135
+ * Basin scope.
136
+ */
137
+ scope: BasinScope,
138
+ /**
139
+ * Basin state.
140
+ */
141
+ state: BasinState,
142
+ }) {
143
+ }
144
+ export class ListBasinsResponse extends S.Class('ListBasinsResponse')({
145
+ /**
146
+ * Matching basins.
147
+ */
148
+ basins: S.Array(BasinInfo).pipe(S.maxItems(1000)),
149
+ /**
150
+ * Indicates that there are more basins that match the criteria.
151
+ */
152
+ has_more: S.Boolean,
153
+ }) {
154
+ }
155
+ export class DeleteOnEmptyConfig extends S.Class('DeleteOnEmptyConfig')({
156
+ /**
157
+ * Minimum age in seconds before an empty stream can be deleted.
158
+ * Set to 0 (default) to disable delete-on-empty (don't delete automatically).
159
+ */
160
+ min_age_secs: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(0)), { nullable: true }),
161
+ }) {
162
+ }
163
+ export class InfiniteRetention extends S.Record({ key: S.String, value: S.Unknown }) {
164
+ }
165
+ export class RetentionPolicy extends S.Union(
166
+ /**
167
+ * Age in seconds for automatic trimming of records older than this threshold.
168
+ * This must be set to a value greater than 0 seconds.
169
+ * (While S2 is in public preview, this is capped at 28 days. Let us know if you'd like the cap removed.)
170
+ */
171
+ S.Struct({
172
+ /**
173
+ * Age in seconds for automatic trimming of records older than this threshold.
174
+ * This must be set to a value greater than 0 seconds.
175
+ * (While S2 is in public preview, this is capped at 28 days. Let us know if you'd like the cap removed.)
176
+ */
177
+ age: S.Int.pipe(S.greaterThanOrEqualTo(0)),
178
+ }),
179
+ /**
180
+ * Retain records unless explicitly trimmed.
181
+ */
182
+ S.Struct({
183
+ /**
184
+ * Retain records unless explicitly trimmed.
185
+ */
186
+ infinite: InfiniteRetention,
187
+ })) {
188
+ }
189
+ export class StorageClass extends S.Literal('standard', 'express') {
190
+ }
191
+ export class TimestampingMode extends S.Literal('client-prefer', 'client-require', 'arrival') {
192
+ }
193
+ export class TimestampingConfig extends S.Class('TimestampingConfig')({
194
+ mode: S.optionalWith(TimestampingMode, { nullable: true }),
195
+ /**
196
+ * Allow client-specified timestamps to exceed the arrival time.
197
+ * If this is `false` or not set, client timestamps will be capped at the arrival time.
198
+ */
199
+ uncapped: S.optionalWith(S.Boolean, { nullable: true }),
200
+ }) {
201
+ }
202
+ export class StreamConfig extends S.Class('StreamConfig')({
203
+ delete_on_empty: S.optionalWith(DeleteOnEmptyConfig, { nullable: true }),
204
+ retention_policy: S.optionalWith(RetentionPolicy, { nullable: true }),
205
+ storage_class: S.optionalWith(StorageClass, { nullable: true }),
206
+ timestamping: S.optionalWith(TimestampingConfig, { nullable: true }),
207
+ }) {
208
+ }
209
+ export class BasinConfig extends S.Class('BasinConfig')({
210
+ /**
211
+ * Create stream on append if it doesn't exist, using the default stream configuration.
212
+ */
213
+ create_stream_on_append: S.optionalWith(S.Boolean, { nullable: true }),
214
+ /**
215
+ * Create stream on read if it doesn't exist, using the default stream configuration.
216
+ */
217
+ create_stream_on_read: S.optionalWith(S.Boolean, { nullable: true }),
218
+ default_stream_config: S.optionalWith(StreamConfig, { nullable: true }),
219
+ }) {
220
+ }
221
+ export class CreateBasinRequest extends S.Class('CreateBasinRequest')({
222
+ /**
223
+ * Basin name which must be globally unique.
224
+ * It can be between 8 and 48 characters in length, and comprise lowercase letters, numbers and hyphens.
225
+ * It cannot begin or end with a hyphen.
226
+ */
227
+ basin: S.String,
228
+ config: S.optionalWith(BasinConfig, { nullable: true }),
229
+ /**
230
+ * Basin scope.
231
+ */
232
+ scope: S.optionalWith(BasinScope, { nullable: true, default: () => 'aws:us-east-1' }),
233
+ }) {
234
+ }
235
+ export class CreateOrReconfigureBasinParams extends S.Struct({
236
+ 's2-request-token': S.optionalWith(S.String, { nullable: true }),
237
+ }) {
238
+ }
239
+ export class CreateOrReconfigureBasinRequest extends S.Union(S.Null) {
240
+ }
241
+ // export class CreateOrReconfigureBasinRequest extends S.Union(S.Null, CreateOrReconfigureBasinRequest) {}
242
+ export class DeleteOnEmptyReconfiguration extends S.Class('DeleteOnEmptyReconfiguration')({
243
+ /**
244
+ * Minimum age in seconds before an empty stream can be deleted.
245
+ * Set to 0 to disable delete-on-empty (don't delete automatically).
246
+ */
247
+ min_age_secs: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(0)), { nullable: true }),
248
+ }) {
249
+ }
250
+ export class TimestampingReconfiguration extends S.Class('TimestampingReconfiguration')({
251
+ mode: S.optionalWith(TimestampingMode, { nullable: true }),
252
+ /**
253
+ * Allow client-specified timestamps to exceed the arrival time.
254
+ */
255
+ uncapped: S.optionalWith(S.Boolean, { nullable: true }),
256
+ }) {
257
+ }
258
+ export class StreamReconfiguration extends S.Class('StreamReconfiguration')({
259
+ delete_on_empty: S.optionalWith(DeleteOnEmptyReconfiguration, { nullable: true }),
260
+ retention_policy: S.optionalWith(RetentionPolicy, { nullable: true }),
261
+ storage_class: S.optionalWith(StorageClass, { nullable: true }),
262
+ timestamping: S.optionalWith(TimestampingReconfiguration, { nullable: true }),
263
+ }) {
264
+ }
265
+ export class BasinReconfiguration extends S.Class('BasinReconfiguration')({
266
+ /**
267
+ * Create a stream on append.
268
+ */
269
+ create_stream_on_append: S.optionalWith(S.Boolean, { nullable: true }),
270
+ /**
271
+ * Create a stream on read.
272
+ */
273
+ create_stream_on_read: S.optionalWith(S.Boolean, { nullable: true }),
274
+ default_stream_config: S.optionalWith(StreamReconfiguration, { nullable: true }),
275
+ }) {
276
+ }
277
+ export class AccountMetricSet extends S.Literal('active-basins', 'account-ops') {
278
+ }
279
+ export class TimeseriesInterval extends S.Literal('minute', 'hour', 'day') {
280
+ }
281
+ export class AccountMetricsParams extends S.Struct({
282
+ set: AccountMetricSet,
283
+ start: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(0)), { nullable: true }),
284
+ end: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(0)), { nullable: true }),
285
+ interval: S.optionalWith(TimeseriesInterval, { nullable: true }),
286
+ }) {
287
+ }
288
+ export class MetricUnit extends S.Literal('bytes', 'operations') {
289
+ }
290
+ export class Scalar extends S.Class('Scalar')({
291
+ /**
292
+ * Metric name.
293
+ */
294
+ name: S.String,
295
+ /**
296
+ * Unit of the metric.
297
+ */
298
+ unit: MetricUnit,
299
+ /**
300
+ * Metric value.
301
+ */
302
+ value: S.Number,
303
+ }) {
304
+ }
305
+ export class Accumulation extends S.Class('Accumulation')({
306
+ /**
307
+ * The duration of bucket for the accumulation.
308
+ */
309
+ bucket_length: TimeseriesInterval,
310
+ /**
311
+ * Timeseries name.
312
+ */
313
+ name: S.String,
314
+ /**
315
+ * Unit of the metric.
316
+ */
317
+ unit: MetricUnit,
318
+ }) {
319
+ }
320
+ export class Gauge extends S.Class('Gauge')({
321
+ /**
322
+ * Timeseries name.
323
+ */
324
+ name: S.String,
325
+ /**
326
+ * Unit of the metric.
327
+ */
328
+ unit: MetricUnit,
329
+ }) {
330
+ }
331
+ export class Label extends S.Class('Label')({
332
+ /**
333
+ * Label name.
334
+ */
335
+ name: S.String,
336
+ /**
337
+ * Label values.
338
+ */
339
+ values: S.Array(S.String),
340
+ }) {
341
+ }
342
+ export class Metric extends S.Union(
343
+ /**
344
+ * Single named value.
345
+ */
346
+ S.Struct({
347
+ /**
348
+ * Single named value.
349
+ */
350
+ scalar: Scalar,
351
+ }),
352
+ /**
353
+ * Named series of `(timestamp, value)` points representing an accumulation over a specified
354
+ * bucket.
355
+ */
356
+ S.Struct({
357
+ /**
358
+ * Named series of `(timestamp, value)` points representing an accumulation over a specified
359
+ * bucket.
360
+ */
361
+ accumulation: Accumulation,
362
+ }),
363
+ /**
364
+ * Named series of `(timestamp, value)` points each representing an instantaneous value.
365
+ */
366
+ S.Struct({
367
+ /**
368
+ * Named series of `(timestamp, value)` points each representing an instantaneous value.
369
+ */
370
+ gauge: Gauge,
371
+ }),
372
+ /**
373
+ * Set of string labels.
374
+ */
375
+ S.Struct({
376
+ /**
377
+ * Set of string labels.
378
+ */
379
+ label: Label,
380
+ })) {
381
+ }
382
+ export class MetricSetResponse extends S.Class('MetricSetResponse')({
383
+ /**
384
+ * Metrics comprising the set.
385
+ */
386
+ values: S.Array(Metric),
387
+ }) {
388
+ }
389
+ export class BasinMetricSet extends S.Literal('storage', 'append-ops', 'read-ops', 'read-throughput', 'append-throughput', 'basin-ops') {
390
+ }
391
+ export class BasinMetricsParams extends S.Struct({
392
+ set: BasinMetricSet,
393
+ start: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(0)), { nullable: true }),
394
+ end: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(0)), { nullable: true }),
395
+ interval: S.optionalWith(TimeseriesInterval, { nullable: true }),
396
+ }) {
397
+ }
398
+ export class StreamMetricSet extends S.Literal('storage') {
399
+ }
400
+ export class StreamMetricsParams extends S.Struct({
401
+ set: StreamMetricSet,
402
+ start: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(0)), { nullable: true }),
403
+ end: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(0)), { nullable: true }),
404
+ interval: S.optionalWith(TimeseriesInterval, { nullable: true }),
405
+ }) {
406
+ }
407
+ export class ListStreamsParams extends S.Struct({
408
+ prefix: S.optionalWith(S.String, { nullable: true, default: () => '' }),
409
+ start_after: S.optionalWith(S.String, { nullable: true, default: () => '' }),
410
+ limit: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(0), S.lessThanOrEqualTo(1000)), {
411
+ nullable: true,
412
+ default: () => 1000,
413
+ }),
414
+ }) {
415
+ }
416
+ export class StreamInfo extends S.Class('StreamInfo')({
417
+ /**
418
+ * Creation time in ISO 8601 format.
419
+ */
420
+ created_at: S.String,
421
+ /**
422
+ * Deletion time in ISO 8601 format, if the stream is being deleted.
423
+ */
424
+ deleted_at: S.optionalWith(S.String, { nullable: true }),
425
+ /**
426
+ * Stream name.
427
+ */
428
+ name: S.String,
429
+ }) {
430
+ }
431
+ export class ListStreamsResponse extends S.Class('ListStreamsResponse')({
432
+ /**
433
+ * Indicates that there are more results that match the criteria.
434
+ */
435
+ has_more: S.Boolean,
436
+ /**
437
+ * Matching streams.
438
+ */
439
+ streams: S.Array(StreamInfo).pipe(S.maxItems(1000)),
440
+ }) {
441
+ }
442
+ export class CreateStreamRequest extends S.Class('CreateStreamRequest')({
443
+ config: S.optionalWith(StreamConfig, { nullable: true }),
444
+ /**
445
+ * Stream name that is unique to the basin.
446
+ * It can be between 1 and 512 bytes in length.
447
+ */
448
+ stream: S.String,
449
+ }) {
450
+ }
451
+ export class CreateOrReconfigureStreamParams extends S.Struct({
452
+ 's2-request-token': S.optionalWith(S.String, { nullable: true }),
453
+ }) {
454
+ }
455
+ export class CreateOrReconfigureStreamRequest extends S.Union(S.Null, StreamConfig) {
456
+ }
457
+ export class S2Format extends S.Literal('raw', 'base64') {
458
+ }
459
+ export class U64 extends S.Int.pipe(S.greaterThanOrEqualTo(0)) {
460
+ }
461
+ export class ReadParams extends S.Struct({
462
+ 's2-format': S.optionalWith(S2Format, { nullable: true }),
463
+ seq_num: S.optionalWith(U64, { nullable: true }),
464
+ timestamp: S.optionalWith(U64, { nullable: true }),
465
+ tail_offset: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(0)), { nullable: true }),
466
+ count: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(0)), { nullable: true }),
467
+ bytes: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(0)), { nullable: true }),
468
+ until: S.optionalWith(U64, { nullable: true }),
469
+ clamp: S.optionalWith(S.Boolean, { nullable: true }),
470
+ }) {
471
+ }
472
+ /**
473
+ * Headers add structured information to a record as name-value pairs.
474
+ *
475
+ * The name cannot be empty, with the exception of an S2 command record.
476
+ */
477
+ export class Header extends S.NonEmptyArray(S.String).pipe(S.minItems(2), S.maxItems(2)) {
478
+ }
479
+ /**
480
+ * Record that is durably sequenced on a stream.
481
+ */
482
+ export class SequencedRecord extends S.Class('SequencedRecord')({
483
+ /**
484
+ * Body of the record.
485
+ */
486
+ body: S.optionalWith(S.String, { nullable: true }),
487
+ /**
488
+ * Series of name-value pairs for this record.
489
+ */
490
+ headers: S.optionalWith(S.Array(Header), { nullable: true }),
491
+ /**
492
+ * Sequence number assigned by the service.
493
+ */
494
+ seq_num: U64,
495
+ /**
496
+ * Timestamp for this record.
497
+ */
498
+ timestamp: U64,
499
+ }) {
500
+ }
501
+ /**
502
+ * Position of a record in a stream.
503
+ */
504
+ export class StreamPosition extends S.Class('StreamPosition')({
505
+ /**
506
+ * Sequence number assigned by the service.
507
+ */
508
+ seq_num: S.Int.pipe(S.greaterThanOrEqualTo(0)),
509
+ /**
510
+ * Timestamp, which may be client-specified or assigned by the service.
511
+ * If it is assigned by the service, it will represent milliseconds since Unix epoch.
512
+ */
513
+ timestamp: S.Int.pipe(S.greaterThanOrEqualTo(0)),
514
+ }) {
515
+ }
516
+ export class ReadBatch extends S.Class('ReadBatch')({
517
+ /**
518
+ * Records that are durably sequenced on the stream, retrieved based on the requested criteria.
519
+ * This can only be empty in response to a regular (non-SSE) read, if the request cannot be satisfied without violating an explicit limit.
520
+ */
521
+ records: S.Array(SequencedRecord),
522
+ tail: S.optionalWith(StreamPosition, { nullable: true }),
523
+ }) {
524
+ }
525
+ export class TailResponse extends S.Class('TailResponse')({
526
+ /**
527
+ * Sequence number that will be assigned to the next record on the stream, and timestamp of the last record.
528
+ */
529
+ tail: StreamPosition,
530
+ }) {
531
+ }
532
+ export class AppendParams extends S.Struct({
533
+ 's2-format': S.optionalWith(S2Format, { nullable: true }),
534
+ }) {
535
+ }
536
+ /**
537
+ * Record to be appended to a stream.
538
+ */
539
+ export class AppendRecord extends S.Class('AppendRecord')({
540
+ /**
541
+ * Body of the record.
542
+ */
543
+ body: S.optionalWith(S.String, { nullable: true }),
544
+ /**
545
+ * Series of name-value pairs for this record.
546
+ */
547
+ headers: S.optionalWith(S.Array(Header), { nullable: true }),
548
+ timestamp: S.optionalWith(U64, { nullable: true }),
549
+ }) {
550
+ }
551
+ /**
552
+ * Payload of an `append` request.
553
+ */
554
+ export class AppendInput extends S.Class('AppendInput')({
555
+ /**
556
+ * Enforce a fencing token, which starts out as an empty string that can be overridden by a `fence` command record.
557
+ */
558
+ fencing_token: S.optionalWith(S.String, { nullable: true }),
559
+ match_seq_num: S.optionalWith(U64, { nullable: true }),
560
+ /**
561
+ * Batch of records to append atomically, which must contain at least one record, and no more than 1000.
562
+ * The total size of a batch of records may not exceed 1 MiB of metered bytes.
563
+ */
564
+ records: S.Array(AppendRecord),
565
+ }) {
566
+ }
567
+ /**
568
+ * Success response to an `append` request.
569
+ */
570
+ export class AppendAck extends S.Class('AppendAck')({
571
+ /**
572
+ * Sequence number of the last record that was appended `+ 1`, and timestamp of the last record that was appended.
573
+ * The difference between `end.seq_num` and `start.seq_num` will be the number of records appended.
574
+ */
575
+ end: StreamPosition,
576
+ /**
577
+ * Sequence number and timestamp of the first record that was appended.
578
+ */
579
+ start: StreamPosition,
580
+ /**
581
+ * Sequence number that will be assigned to the next record on the stream, and timestamp of the last record on the stream.
582
+ * This can be greater than the `end` position in case of concurrent appends.
583
+ */
584
+ tail: StreamPosition,
585
+ }) {
586
+ }
587
+ /**
588
+ * Aborted due to a failed condition.
589
+ */
590
+ export class AppendConditionFailed extends S.Union(
591
+ /**
592
+ * Fencing token did not match.
593
+ * The expected fencing token is returned.
594
+ */
595
+ S.Struct({
596
+ /**
597
+ * Fencing token did not match.
598
+ * The expected fencing token is returned.
599
+ */
600
+ fencing_token_mismatch: S.String,
601
+ }),
602
+ /**
603
+ * Sequence number did not match the tail of the stream.
604
+ * The expected next sequence number is returned.
605
+ */
606
+ S.Struct({
607
+ /**
608
+ * Sequence number did not match the tail of the stream.
609
+ * The expected next sequence number is returned.
610
+ */
611
+ seq_num_mismatch: S.Int.pipe(S.greaterThanOrEqualTo(0)),
612
+ })) {
613
+ }
614
+ export const make = (httpClient, options = {}) => {
615
+ const unexpectedStatus = (response) => Effect.flatMap(Effect.orElseSucceed(response.json, () => 'Unexpected status code'), (description) => Effect.fail(new HttpClientError.ResponseError({
616
+ request: response.request,
617
+ response,
618
+ reason: 'StatusCode',
619
+ description: typeof description === 'string' ? description : JSON.stringify(description),
620
+ })));
621
+ const withResponse = options.transformClient
622
+ ? (f) => (request) => Effect.flatMap(Effect.flatMap(options.transformClient(httpClient), (client) => client.execute(request)), f)
623
+ : (f) => (request) => Effect.flatMap(httpClient.execute(request), f);
624
+ const decodeSuccess = (schema) => (response) => HttpClientResponse.schemaBodyJson(schema)(response);
625
+ const decodeError = (tag, schema) => (response) => Effect.flatMap(HttpClientResponse.schemaBodyJson(schema)(response), (cause) => Effect.fail(ClientError(tag, cause, response)));
626
+ return {
627
+ httpClient,
628
+ listAccessTokens: (options) => HttpClientRequest.get(`/access-tokens`).pipe(HttpClientRequest.setUrlParams({
629
+ prefix: options?.prefix,
630
+ start_after: options?.start_after,
631
+ limit: options?.limit,
632
+ }), withResponse(HttpClientResponse.matchStatus({
633
+ '2xx': decodeSuccess(ListAccessTokensResponse),
634
+ '400': decodeError('ErrorResponse', ErrorResponse),
635
+ '403': decodeError('ErrorResponse', ErrorResponse),
636
+ orElse: unexpectedStatus,
637
+ }))),
638
+ issueAccessToken: (options) => HttpClientRequest.post(`/access-tokens`).pipe(HttpClientRequest.bodyUnsafeJson(options), withResponse(HttpClientResponse.matchStatus({
639
+ '2xx': decodeSuccess(IssueAccessTokenResponse),
640
+ '400': decodeError('ErrorResponse', ErrorResponse),
641
+ '403': decodeError('ErrorResponse', ErrorResponse),
642
+ '409': decodeError('ErrorResponse', ErrorResponse),
643
+ orElse: unexpectedStatus,
644
+ }))),
645
+ revokeAccessToken: (id) => HttpClientRequest.del(`/access-tokens/${id}`).pipe(withResponse(HttpClientResponse.matchStatus({
646
+ '400': decodeError('ErrorResponse', ErrorResponse),
647
+ '403': decodeError('ErrorResponse', ErrorResponse),
648
+ '200': () => Effect.void,
649
+ orElse: unexpectedStatus,
650
+ }))),
651
+ listBasins: (options) => HttpClientRequest.get(`/basins`).pipe(HttpClientRequest.setUrlParams({
652
+ prefix: options?.prefix,
653
+ start_after: options?.start_after,
654
+ limit: options?.limit,
655
+ }), withResponse(HttpClientResponse.matchStatus({
656
+ '2xx': decodeSuccess(ListBasinsResponse),
657
+ '400': decodeError('ErrorResponse', ErrorResponse),
658
+ '403': decodeError('ErrorResponse', ErrorResponse),
659
+ orElse: unexpectedStatus,
660
+ }))),
661
+ createBasin: (options) => HttpClientRequest.post(`/basins`).pipe(HttpClientRequest.bodyUnsafeJson(options), withResponse(HttpClientResponse.matchStatus({
662
+ '200': decodeSuccess(BasinInfo),
663
+ '201': decodeSuccess(BasinInfo),
664
+ '400': decodeError('ErrorResponse', ErrorResponse),
665
+ '401': decodeError('ErrorResponse', ErrorResponse),
666
+ '403': decodeError('ErrorResponse', ErrorResponse),
667
+ '409': decodeError('ErrorResponse', ErrorResponse),
668
+ orElse: unexpectedStatus,
669
+ }))),
670
+ getBasinConfig: (basin) => HttpClientRequest.get(`/basins/${basin}`).pipe(withResponse(HttpClientResponse.matchStatus({
671
+ '2xx': decodeSuccess(BasinConfig),
672
+ '400': decodeError('ErrorResponse', ErrorResponse),
673
+ '403': decodeError('ErrorResponse', ErrorResponse),
674
+ '404': decodeError('ErrorResponse', ErrorResponse),
675
+ orElse: unexpectedStatus,
676
+ }))),
677
+ createOrReconfigureBasin: (basin, options) => HttpClientRequest.put(`/basins/${basin}`).pipe(HttpClientRequest.setHeaders({ 's2-request-token': options.params?.['s2-request-token'] ?? undefined }), HttpClientRequest.bodyUnsafeJson(options.payload), withResponse(HttpClientResponse.matchStatus({
678
+ '200': decodeSuccess(BasinInfo),
679
+ '201': decodeSuccess(BasinInfo),
680
+ '400': decodeError('ErrorResponse', ErrorResponse),
681
+ '204': () => Effect.void,
682
+ orElse: unexpectedStatus,
683
+ }))),
684
+ deleteBasin: (basin) => HttpClientRequest.del(`/basins/${basin}`).pipe(withResponse(HttpClientResponse.matchStatus({
685
+ '400': decodeError('ErrorResponse', ErrorResponse),
686
+ '401': decodeError('ErrorResponse', ErrorResponse),
687
+ '403': decodeError('ErrorResponse', ErrorResponse),
688
+ '404': decodeError('ErrorResponse', ErrorResponse),
689
+ '202': () => Effect.void,
690
+ orElse: unexpectedStatus,
691
+ }))),
692
+ reconfigureBasin: (basin, options) => HttpClientRequest.patch(`/basins/${basin}`).pipe(HttpClientRequest.bodyUnsafeJson(options), withResponse(HttpClientResponse.matchStatus({
693
+ '2xx': decodeSuccess(BasinConfig),
694
+ '400': decodeError('ErrorResponse', ErrorResponse),
695
+ '403': decodeError('ErrorResponse', ErrorResponse),
696
+ '404': decodeError('ErrorResponse', ErrorResponse),
697
+ orElse: unexpectedStatus,
698
+ }))),
699
+ accountMetrics: (options) => HttpClientRequest.get(`/metrics`).pipe(HttpClientRequest.setUrlParams({
700
+ set: options?.set,
701
+ start: options?.start,
702
+ end: options?.end,
703
+ interval: options?.interval,
704
+ }), withResponse(HttpClientResponse.matchStatus({
705
+ '2xx': decodeSuccess(MetricSetResponse),
706
+ '400': decodeError('ErrorResponse', ErrorResponse),
707
+ '403': decodeError('ErrorResponse', ErrorResponse),
708
+ orElse: unexpectedStatus,
709
+ }))),
710
+ basinMetrics: (basin, options) => HttpClientRequest.get(`/metrics/${basin}`).pipe(HttpClientRequest.setUrlParams({
711
+ set: options?.set,
712
+ start: options?.start,
713
+ end: options?.end,
714
+ interval: options?.interval,
715
+ }), withResponse(HttpClientResponse.matchStatus({
716
+ '2xx': decodeSuccess(MetricSetResponse),
717
+ '400': decodeError('ErrorResponse', ErrorResponse),
718
+ '403': decodeError('ErrorResponse', ErrorResponse),
719
+ orElse: unexpectedStatus,
720
+ }))),
721
+ streamMetrics: (basin, stream, options) => HttpClientRequest.get(`/metrics/${basin}/${stream}`).pipe(HttpClientRequest.setUrlParams({
722
+ set: options?.set,
723
+ start: options?.start,
724
+ end: options?.end,
725
+ interval: options?.interval,
726
+ }), withResponse(HttpClientResponse.matchStatus({
727
+ '2xx': decodeSuccess(MetricSetResponse),
728
+ '400': decodeError('ErrorResponse', ErrorResponse),
729
+ '403': decodeError('ErrorResponse', ErrorResponse),
730
+ orElse: unexpectedStatus,
731
+ }))),
732
+ listStreams: (options) => HttpClientRequest.get(`/streams`).pipe(HttpClientRequest.setUrlParams({
733
+ prefix: options?.prefix,
734
+ start_after: options?.start_after,
735
+ limit: options?.limit,
736
+ }), withResponse(HttpClientResponse.matchStatus({
737
+ '2xx': decodeSuccess(ListStreamsResponse),
738
+ '400': decodeError('ErrorResponse', ErrorResponse),
739
+ '403': decodeError('ErrorResponse', ErrorResponse),
740
+ '404': decodeError('ErrorResponse', ErrorResponse),
741
+ orElse: unexpectedStatus,
742
+ }))),
743
+ createStream: (options) => HttpClientRequest.post(`/streams`).pipe(HttpClientRequest.bodyUnsafeJson(options), withResponse(HttpClientResponse.matchStatus({
744
+ '2xx': decodeSuccess(StreamInfo),
745
+ '400': decodeError('ErrorResponse', ErrorResponse),
746
+ '403': decodeError('ErrorResponse', ErrorResponse),
747
+ '404': decodeError('ErrorResponse', ErrorResponse),
748
+ '409': decodeError('ErrorResponse', ErrorResponse),
749
+ orElse: unexpectedStatus,
750
+ }))),
751
+ getStreamConfig: (stream) => HttpClientRequest.get(`/streams/${stream}`).pipe(withResponse(HttpClientResponse.matchStatus({
752
+ '2xx': decodeSuccess(StreamConfig),
753
+ '400': decodeError('ErrorResponse', ErrorResponse),
754
+ '403': decodeError('ErrorResponse', ErrorResponse),
755
+ '404': decodeError('ErrorResponse', ErrorResponse),
756
+ '409': decodeError('ErrorResponse', ErrorResponse),
757
+ orElse: unexpectedStatus,
758
+ }))),
759
+ createOrReconfigureStream: (stream, options) => HttpClientRequest.put(`/streams/${stream}`).pipe(HttpClientRequest.setHeaders({ 's2-request-token': options.params?.['s2-request-token'] ?? undefined }), HttpClientRequest.bodyUnsafeJson(options.payload), withResponse(HttpClientResponse.matchStatus({
760
+ '2xx': decodeSuccess(StreamInfo),
761
+ '400': decodeError('ErrorResponse', ErrorResponse),
762
+ '403': decodeError('ErrorResponse', ErrorResponse),
763
+ '404': decodeError('ErrorResponse', ErrorResponse),
764
+ '409': decodeError('ErrorResponse', ErrorResponse),
765
+ '204': () => Effect.void,
766
+ orElse: unexpectedStatus,
767
+ }))),
768
+ deleteStream: (stream) => HttpClientRequest.del(`/streams/${stream}`).pipe(withResponse(HttpClientResponse.matchStatus({
769
+ '400': decodeError('ErrorResponse', ErrorResponse),
770
+ '403': decodeError('ErrorResponse', ErrorResponse),
771
+ '404': decodeError('ErrorResponse', ErrorResponse),
772
+ '202': () => Effect.void,
773
+ orElse: unexpectedStatus,
774
+ }))),
775
+ reconfigureStream: (stream, options) => HttpClientRequest.patch(`/streams/${stream}`).pipe(HttpClientRequest.bodyUnsafeJson(options), withResponse(HttpClientResponse.matchStatus({
776
+ '2xx': decodeSuccess(StreamConfig),
777
+ '400': decodeError('ErrorResponse', ErrorResponse),
778
+ '403': decodeError('ErrorResponse', ErrorResponse),
779
+ '404': decodeError('ErrorResponse', ErrorResponse),
780
+ '409': decodeError('ErrorResponse', ErrorResponse),
781
+ orElse: unexpectedStatus,
782
+ }))),
783
+ read: (stream, options) => HttpClientRequest.get(`/streams/${stream}/records`).pipe(HttpClientRequest.setUrlParams({
784
+ seq_num: options?.seq_num,
785
+ timestamp: options?.timestamp,
786
+ tail_offset: options?.tail_offset,
787
+ count: options?.count,
788
+ bytes: options?.bytes,
789
+ until: options?.until,
790
+ clamp: options?.clamp,
791
+ }), HttpClientRequest.setHeaders({ 's2-format': options?.['s2-format'] ?? undefined }), withResponse(HttpClientResponse.matchStatus({
792
+ '2xx': decodeSuccess(ReadBatch),
793
+ '400': decodeError('ErrorResponse', ErrorResponse),
794
+ '401': decodeError('ErrorResponse', ErrorResponse),
795
+ '404': decodeError('ErrorResponse', ErrorResponse),
796
+ '409': decodeError('ErrorResponse', ErrorResponse),
797
+ '416': decodeError('TailResponse', TailResponse),
798
+ '500': decodeError('ErrorResponse', ErrorResponse),
799
+ orElse: unexpectedStatus,
800
+ }))),
801
+ append: (stream, options) => HttpClientRequest.post(`/streams/${stream}/records`).pipe(HttpClientRequest.setHeaders({ 's2-format': options.params?.['s2-format'] ?? undefined }), HttpClientRequest.bodyUnsafeJson(options.payload), withResponse(HttpClientResponse.matchStatus({
802
+ '2xx': decodeSuccess(AppendAck),
803
+ '400': decodeError('ErrorResponse', ErrorResponse),
804
+ '401': decodeError('ErrorResponse', ErrorResponse),
805
+ '404': decodeError('ErrorResponse', ErrorResponse),
806
+ '409': decodeError('ErrorResponse', ErrorResponse),
807
+ '412': decodeError('AppendConditionFailed', AppendConditionFailed),
808
+ '500': decodeError('ErrorResponse', ErrorResponse),
809
+ orElse: unexpectedStatus,
810
+ }))),
811
+ checkTail: (stream) => HttpClientRequest.get(`/streams/${stream}/records/tail`).pipe(withResponse(HttpClientResponse.matchStatus({
812
+ '2xx': decodeSuccess(TailResponse),
813
+ '400': decodeError('ErrorResponse', ErrorResponse),
814
+ '401': decodeError('ErrorResponse', ErrorResponse),
815
+ '404': decodeError('ErrorResponse', ErrorResponse),
816
+ '409': decodeError('ErrorResponse', ErrorResponse),
817
+ '500': decodeError('ErrorResponse', ErrorResponse),
818
+ orElse: unexpectedStatus,
819
+ }))),
820
+ };
821
+ };
822
+ class ClientErrorImpl extends Data.Error {
823
+ }
824
+ export const ClientError = (tag, cause, response) => new ClientErrorImpl({
825
+ _tag: tag,
826
+ cause,
827
+ response,
828
+ request: response.request,
829
+ });
830
+ //# sourceMappingURL=http-client-generated.js.map