@s2-dev/streamstore 0.3.2 → 0.3.8
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/endpoints.d.ts +67 -0
- package/endpoints.d.ts.map +1 -0
- package/endpoints.js +126 -0
- package/endpoints.js.map +1 -0
- package/index.extras.d.ts +23 -15
- package/index.extras.d.ts.map +1 -1
- package/index.extras.js +140 -67
- package/index.extras.js.map +1 -1
- package/jsr.json +1 -1
- package/lib/config.d.ts +3 -3
- package/lib/config.js +3 -3
- package/package.json +2 -1
- package/src/endpoints.ts +159 -0
- package/src/index.extras.ts +157 -81
- package/src/lib/config.ts +3 -3
package/endpoints.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
type Authority = string;
|
|
2
|
+
type BasinName = string;
|
|
3
|
+
/**
|
|
4
|
+
* S2 cloud environment to connect with.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum S2Cloud {
|
|
7
|
+
/** S2 running on AWS */
|
|
8
|
+
Aws = "aws"
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Endpoint for connecting to an S2 basin.
|
|
12
|
+
*/
|
|
13
|
+
export declare enum BasinEndpointKind {
|
|
14
|
+
ParentZone = "ParentZone",
|
|
15
|
+
Direct = "Direct"
|
|
16
|
+
}
|
|
17
|
+
export type BasinEndpoint = {
|
|
18
|
+
kind: BasinEndpointKind.ParentZone;
|
|
19
|
+
authority: Authority;
|
|
20
|
+
} | {
|
|
21
|
+
kind: BasinEndpointKind.Direct;
|
|
22
|
+
authority: Authority;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Endpoints for the S2 environment.
|
|
26
|
+
*
|
|
27
|
+
* You can find the S2 endpoints in our [documentation](https://s2.dev/docs/interface/endpoints)
|
|
28
|
+
*/
|
|
29
|
+
export declare class S2Endpoints {
|
|
30
|
+
/** Used by `AccountService` requests */
|
|
31
|
+
account: Authority;
|
|
32
|
+
/** Used by `BasinService` and `StreamService` requests */
|
|
33
|
+
basin: BasinEndpoint;
|
|
34
|
+
constructor(account: Authority, basin: BasinEndpoint);
|
|
35
|
+
/**
|
|
36
|
+
* Get S2 endpoints for the specified cloud.
|
|
37
|
+
*/
|
|
38
|
+
static forCloud(cloud: S2Cloud): S2Endpoints;
|
|
39
|
+
/**
|
|
40
|
+
* Get S2 endpoints for the specified cell.
|
|
41
|
+
*/
|
|
42
|
+
static forCell(cloud: S2Cloud, cellId: string): S2Endpoints;
|
|
43
|
+
/**
|
|
44
|
+
* Get S2 endpoints from environment variables.
|
|
45
|
+
*
|
|
46
|
+
* The following environment variables are used:
|
|
47
|
+
* - `S2_CLOUD`: Valid S2 cloud name. Defaults to AWS.
|
|
48
|
+
* - `S2_ACCOUNT_ENDPOINT`: Overrides the account endpoint.
|
|
49
|
+
* - `S2_BASIN_ENDPOINT`: Overrides the basin endpoint. The prefix `"{basin}."` indicates the
|
|
50
|
+
* basin endpoint is `ParentZone` else `Direct`.
|
|
51
|
+
*/
|
|
52
|
+
static fromEnv(): S2Endpoints;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Client kind for different S2 services
|
|
56
|
+
*/
|
|
57
|
+
export type ClientKind = {
|
|
58
|
+
kind: 'Account';
|
|
59
|
+
} | {
|
|
60
|
+
kind: 'Basin';
|
|
61
|
+
basin: BasinName;
|
|
62
|
+
};
|
|
63
|
+
export declare const ClientKind: {
|
|
64
|
+
toAuthority(kind: ClientKind, endpoints: S2Endpoints): Authority;
|
|
65
|
+
};
|
|
66
|
+
export {};
|
|
67
|
+
//# sourceMappingURL=endpoints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoints.d.ts","sourceRoot":"","sources":["src/endpoints.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG,MAAM,CAAC;AAGxB,KAAK,SAAS,GAAG,MAAM,CAAC;AAExB;;GAEG;AACH,oBAAY,OAAO;IACf,wBAAwB;IACxB,GAAG,QAAQ;CACd;AAED;;GAEG;AACH,oBAAY,iBAAiB;IACzB,UAAU,eAAe;IACzB,MAAM,WAAW;CACpB;AAED,MAAM,MAAM,aAAa,GAAG;IACxB,IAAI,EAAE,iBAAiB,CAAC,UAAU,CAAC;IACnC,SAAS,EAAE,SAAS,CAAC;CACxB,GAAG;IACA,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC;IAC/B,SAAS,EAAE,SAAS,CAAC;CACxB,CAAC;AASF;;;;GAIG;AACH,qBAAa,WAAW;IACpB,wCAAwC;IACjC,OAAO,EAAE,SAAS,CAAC;IAC1B,0DAA0D;IACnD,KAAK,EAAE,aAAa,CAAC;gBAEhB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa;IAKpD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW;IAW5C;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW;IAW3D;;;;;;;;OAQG;IACH,MAAM,CAAC,OAAO,IAAI,WAAW;CA8ChC;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAChB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAE1C,eAAO,MAAM,UAAU;sBACD,UAAU,aAAa,WAAW,GAAG,SAAS;CAanE,CAAC"}
|
package/endpoints.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientKind = exports.S2Endpoints = exports.BasinEndpointKind = exports.S2Cloud = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* S2 cloud environment to connect with.
|
|
6
|
+
*/
|
|
7
|
+
var S2Cloud;
|
|
8
|
+
(function (S2Cloud) {
|
|
9
|
+
/** S2 running on AWS */
|
|
10
|
+
S2Cloud["Aws"] = "aws";
|
|
11
|
+
})(S2Cloud || (exports.S2Cloud = S2Cloud = {}));
|
|
12
|
+
/**
|
|
13
|
+
* Endpoint for connecting to an S2 basin.
|
|
14
|
+
*/
|
|
15
|
+
var BasinEndpointKind;
|
|
16
|
+
(function (BasinEndpointKind) {
|
|
17
|
+
BasinEndpointKind["ParentZone"] = "ParentZone";
|
|
18
|
+
BasinEndpointKind["Direct"] = "Direct";
|
|
19
|
+
})(BasinEndpointKind || (exports.BasinEndpointKind = BasinEndpointKind = {}));
|
|
20
|
+
class S2EndpointError extends Error {
|
|
21
|
+
constructor(message) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = 'S2EndpointError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Endpoints for the S2 environment.
|
|
28
|
+
*
|
|
29
|
+
* You can find the S2 endpoints in our [documentation](https://s2.dev/docs/interface/endpoints)
|
|
30
|
+
*/
|
|
31
|
+
class S2Endpoints {
|
|
32
|
+
constructor(account, basin) {
|
|
33
|
+
this.account = account;
|
|
34
|
+
this.basin = basin;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get S2 endpoints for the specified cloud.
|
|
38
|
+
*/
|
|
39
|
+
static forCloud(cloud) {
|
|
40
|
+
const authority = `${cloud}.s2.dev`;
|
|
41
|
+
return new S2Endpoints(authority, {
|
|
42
|
+
kind: BasinEndpointKind.ParentZone,
|
|
43
|
+
authority: `b.${cloud}.s2.dev`
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get S2 endpoints for the specified cell.
|
|
48
|
+
*/
|
|
49
|
+
static forCell(cloud, cellId) {
|
|
50
|
+
const cellEndpoint = `${cellId}.o.${cloud}.s2.dev`;
|
|
51
|
+
return new S2Endpoints(cellEndpoint, {
|
|
52
|
+
kind: BasinEndpointKind.Direct,
|
|
53
|
+
authority: cellEndpoint
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get S2 endpoints from environment variables.
|
|
58
|
+
*
|
|
59
|
+
* The following environment variables are used:
|
|
60
|
+
* - `S2_CLOUD`: Valid S2 cloud name. Defaults to AWS.
|
|
61
|
+
* - `S2_ACCOUNT_ENDPOINT`: Overrides the account endpoint.
|
|
62
|
+
* - `S2_BASIN_ENDPOINT`: Overrides the basin endpoint. The prefix `"{basin}."` indicates the
|
|
63
|
+
* basin endpoint is `ParentZone` else `Direct`.
|
|
64
|
+
*/
|
|
65
|
+
static fromEnv() {
|
|
66
|
+
let cloud;
|
|
67
|
+
try {
|
|
68
|
+
const cloudEnv = process.env['S2_CLOUD'] || S2Cloud.Aws;
|
|
69
|
+
if (Object.values(S2Cloud).includes(cloudEnv)) {
|
|
70
|
+
cloud = cloudEnv;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw new S2EndpointError(`Invalid S2_CLOUD: ${cloudEnv}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
const error = err;
|
|
78
|
+
throw new S2EndpointError(`Invalid S2_CLOUD: ${error.message}`);
|
|
79
|
+
}
|
|
80
|
+
const endpoints = S2Endpoints.forCloud(cloud);
|
|
81
|
+
const accountEndpoint = process.env['S2_ACCOUNT_ENDPOINT'];
|
|
82
|
+
if (accountEndpoint !== undefined) {
|
|
83
|
+
if (typeof accountEndpoint !== 'string') {
|
|
84
|
+
throw new S2EndpointError('Invalid S2_ACCOUNT_ENDPOINT: not string');
|
|
85
|
+
}
|
|
86
|
+
endpoints.account = accountEndpoint;
|
|
87
|
+
}
|
|
88
|
+
const basinEndpoint = process.env['S2_BASIN_ENDPOINT'];
|
|
89
|
+
if (basinEndpoint !== undefined) {
|
|
90
|
+
if (typeof basinEndpoint !== 'string') {
|
|
91
|
+
throw new S2EndpointError('Invalid S2_BASIN_ENDPOINT: not string');
|
|
92
|
+
}
|
|
93
|
+
if (basinEndpoint.startsWith('{basin}.')) {
|
|
94
|
+
const parentZone = basinEndpoint.substring(7);
|
|
95
|
+
endpoints.basin = {
|
|
96
|
+
kind: BasinEndpointKind.ParentZone,
|
|
97
|
+
authority: parentZone
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
endpoints.basin = {
|
|
102
|
+
kind: BasinEndpointKind.Direct,
|
|
103
|
+
authority: basinEndpoint
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return endpoints;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.S2Endpoints = S2Endpoints;
|
|
111
|
+
exports.ClientKind = {
|
|
112
|
+
toAuthority(kind, endpoints) {
|
|
113
|
+
switch (kind.kind) {
|
|
114
|
+
case 'Account':
|
|
115
|
+
return endpoints.account;
|
|
116
|
+
case 'Basin':
|
|
117
|
+
switch (endpoints.basin.kind) {
|
|
118
|
+
case BasinEndpointKind.ParentZone:
|
|
119
|
+
return `${kind.basin}.${endpoints.basin.authority}`;
|
|
120
|
+
case BasinEndpointKind.Direct:
|
|
121
|
+
return endpoints.basin.authority;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
//# sourceMappingURL=endpoints.js.map
|
package/endpoints.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoints.js","sourceRoot":"","sources":["src/endpoints.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACH,IAAY,OAGX;AAHD,WAAY,OAAO;IACf,wBAAwB;IACxB,sBAAW,CAAA;AACf,CAAC,EAHW,OAAO,uBAAP,OAAO,QAGlB;AAED;;GAEG;AACH,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IACzB,8CAAyB,CAAA;IACzB,sCAAiB,CAAA;AACrB,CAAC,EAHW,iBAAiB,iCAAjB,iBAAiB,QAG5B;AAUD,MAAM,eAAgB,SAAQ,KAAK;I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,KAAK,SAAS;gBACV,OAAO,SAAS,CAAC,OAAO,CAAC;YAC7B,KAAK,OAAO;gBACR,QAAQ,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;oBAC3B,KAAK,iBAAiB,CAAC,UAAU;wBAC7B,OAAO,GAAG,IAAI,CAAC,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;oBACxD,KAAK,iBAAiB,CAAC,MAAM;wBACzB,OAAO,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC;gBACzC,CAAC;QACT,CAAC;IACL,CAAC;CACJ,CAAC"}
|
package/index.extras.d.ts
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
import { AppendOutput, BasinConfig, BasinInfo, CheckTailResponse, CreateBasinRequest, CreateStreamRequest, Output, ReadResponse, StreamConfig, StreamInfo } from "./models/components";
|
|
2
2
|
import { ListBasinsRequest, ListBasinsResponse, ListStreamsRequest, ListStreamsResponse, ReadRequest as ReadRequestInner, AppendRequest as AppendRequestInner } from "./models/operations";
|
|
3
3
|
import { PageIterator } from "./types";
|
|
4
|
-
import {
|
|
4
|
+
import { S2Endpoints } from "./endpoints";
|
|
5
5
|
export type ReadRequest = Omit<ReadRequestInner, "stream">;
|
|
6
6
|
export type AppendRequest = Omit<AppendRequestInner, "stream">;
|
|
7
7
|
export type { GetBasinConfigRequest, ListBasinsRequest, ListBasinsResponse, ListStreamsRequest, ListStreamsResponse, ReconfigureBasinRequest, } from "./models/operations";
|
|
8
8
|
export type { BasinConfig, BasinInfo, CheckTailResponse, CreateBasinRequest, CreateStreamRequest, Output, ReadResponse, StreamConfig, StreamInfo, } from "./models/components";
|
|
9
|
-
export
|
|
9
|
+
export * from "./endpoints";
|
|
10
|
+
export type S2ClientConfig = {
|
|
11
|
+
authToken?: string;
|
|
12
|
+
requestTimeout?: number;
|
|
13
|
+
endpoints?: S2Endpoints;
|
|
14
|
+
};
|
|
10
15
|
export declare class S2Client {
|
|
11
|
-
private
|
|
16
|
+
private config;
|
|
12
17
|
private _account?;
|
|
13
18
|
get account(): S2Account;
|
|
14
19
|
private _basin?;
|
|
15
20
|
basin(basinName: string): S2Basin;
|
|
16
|
-
constructor(
|
|
21
|
+
constructor(config?: S2ClientConfig);
|
|
17
22
|
}
|
|
18
23
|
declare class S2Account {
|
|
19
24
|
private _account;
|
|
20
|
-
private
|
|
21
|
-
private
|
|
22
|
-
constructor(
|
|
25
|
+
private config;
|
|
26
|
+
private readonly accountURLSuffx;
|
|
27
|
+
constructor(config: S2ClientConfig);
|
|
28
|
+
get URL(): string | undefined;
|
|
23
29
|
basin(basinName: string): S2Basin;
|
|
24
30
|
listBasins(request?: ListBasinsRequest): Promise<PageIterator<ListBasinsResponse, {
|
|
25
31
|
cursor: string;
|
|
@@ -32,12 +38,12 @@ declare class S2Account {
|
|
|
32
38
|
declare class S2Basin {
|
|
33
39
|
private _basin;
|
|
34
40
|
private _stream;
|
|
35
|
-
private requestOptions;
|
|
36
41
|
private basinName;
|
|
37
|
-
private
|
|
42
|
+
private config;
|
|
43
|
+
private clientKind;
|
|
38
44
|
private readonly basinURLSuffx;
|
|
39
|
-
private get
|
|
40
|
-
constructor(
|
|
45
|
+
private get URL();
|
|
46
|
+
constructor(basinName: string, config: S2ClientConfig);
|
|
41
47
|
stream(streamName: string): Stream;
|
|
42
48
|
listStreams(request: ListStreamsRequest): Promise<PageIterator<ListStreamsResponse, {
|
|
43
49
|
cursor: string;
|
|
@@ -49,14 +55,16 @@ declare class S2Basin {
|
|
|
49
55
|
}
|
|
50
56
|
declare class Stream {
|
|
51
57
|
private _stream;
|
|
52
|
-
private basinName;
|
|
53
58
|
private streamName;
|
|
59
|
+
private config;
|
|
60
|
+
private clientKind;
|
|
54
61
|
private readonly basinURLSuffx;
|
|
55
62
|
private get basinURL();
|
|
56
|
-
constructor(basinName: string, streamName: string,
|
|
63
|
+
constructor(basinName: string, streamName: string, config: S2ClientConfig);
|
|
57
64
|
checkTail(): Promise<CheckTailResponse | undefined>;
|
|
58
|
-
readStream(request: ReadRequest): Promise<EventStream<ReadResponse> | undefined>;
|
|
59
|
-
read(request: ReadRequest): Promise<Output | undefined>;
|
|
60
65
|
append(request: AppendRequest): Promise<AppendOutput | undefined>;
|
|
66
|
+
read(request: ReadRequest): Promise<Output | undefined>;
|
|
67
|
+
readStream(request: ReadRequest): AsyncGenerator<ReadResponse, void, undefined>;
|
|
61
68
|
}
|
|
69
|
+
export declare function genS2RequestToken(): string;
|
|
62
70
|
//# sourceMappingURL=index.extras.d.ts.map
|
package/index.extras.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.extras.d.ts","sourceRoot":"","sources":["src/index.extras.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.extras.d.ts","sourceRoot":"","sources":["src/index.extras.ts"],"names":[],"mappings":"AACA,OAAO,EACH,YAAY,EACZ,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,MAAM,EACN,YAAY,EAIZ,YAAY,EACZ,UAAU,EACb,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAEH,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EAInB,WAAW,IAAI,gBAAgB,EAC/B,aAAa,IAAI,kBAAkB,EACtC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AASvC,OAAO,EAAuB,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/D,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;AAC3D,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;AAC/D,YAAY,EACR,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,GAC1B,MAAM,qBAAqB,CAAC;AA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AAO,KAAK,QAAQ,GAEnB;gBAEW,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc;IAUnE,SAAS,IAAI,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAMnD,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IAMjE,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAMtD,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,YAAY,EAAE,IAAI,EAAE,SAAS,CAAC;CAyDzF;AAcD,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C"}
|
package/index.extras.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
exports.S2Client = void 0;
|
|
4
18
|
exports.genS2RequestToken = genS2RequestToken;
|
|
@@ -9,49 +23,49 @@ const basin_1 = require("./sdk/basin");
|
|
|
9
23
|
const account_1 = require("./sdk/account");
|
|
10
24
|
const uuid_1 = require("uuid");
|
|
11
25
|
const basinDeleteStream_1 = require("./funcs/basinDeleteStream");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
26
|
+
const endpoints_1 = require("./endpoints");
|
|
27
|
+
__exportStar(require("./endpoints"), exports);
|
|
28
|
+
const defaultS2ClientConfig = {
|
|
29
|
+
requestTimeout: 3000,
|
|
30
|
+
endpoints: endpoints_1.S2Endpoints.forCloud(endpoints_1.S2Cloud.Aws),
|
|
31
|
+
};
|
|
15
32
|
class S2Client {
|
|
16
33
|
get account() {
|
|
17
|
-
return (this._account ?? (this._account = new S2Account(this.
|
|
34
|
+
return (this._account ?? (this._account = new S2Account(this.config)));
|
|
18
35
|
}
|
|
19
36
|
basin(basinName) {
|
|
20
|
-
return (this._basin ?? (this._basin = new S2Basin(this.
|
|
37
|
+
return (this._basin ?? (this._basin = new S2Basin(basinName, this.config)));
|
|
21
38
|
}
|
|
22
|
-
constructor(
|
|
23
|
-
this.
|
|
39
|
+
constructor(config) {
|
|
40
|
+
this.config = { ...defaultS2ClientConfig, ...config };
|
|
24
41
|
}
|
|
25
42
|
}
|
|
26
43
|
exports.S2Client = S2Client;
|
|
27
44
|
class S2Account {
|
|
28
|
-
constructor(
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
timeoutMs:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
retryConnectionErrors: true,
|
|
42
|
-
},
|
|
43
|
-
retryCodes: ["500", "503", "504"],
|
|
44
|
-
};
|
|
45
|
+
constructor(config) {
|
|
46
|
+
this.accountURLSuffx = "/v1alpha";
|
|
47
|
+
this._account = new account_1.Account({
|
|
48
|
+
...(config.authToken !== undefined && { bearerAuth: config.authToken }),
|
|
49
|
+
...(config.requestTimeout !== undefined && { timeoutMs: config.requestTimeout })
|
|
50
|
+
});
|
|
51
|
+
this.config = config;
|
|
52
|
+
}
|
|
53
|
+
get URL() {
|
|
54
|
+
if (!this.config.endpoints)
|
|
55
|
+
return undefined;
|
|
56
|
+
return `https://${endpoints_1.ClientKind.toAuthority({ kind: "Account" }, this.config.endpoints)}${this.accountURLSuffx}`;
|
|
45
57
|
}
|
|
46
58
|
basin(basinName) {
|
|
47
|
-
return new S2Basin(this.
|
|
59
|
+
return new S2Basin(basinName, this.config);
|
|
48
60
|
}
|
|
49
61
|
async listBasins(request) {
|
|
50
|
-
|
|
62
|
+
const url = this.URL;
|
|
63
|
+
return this._account.listBasins(request ?? {}, url ? { serverURL: url } : {});
|
|
51
64
|
}
|
|
52
65
|
async getBasinConfig(basin) {
|
|
53
66
|
const _request = { basin };
|
|
54
|
-
|
|
67
|
+
const url = this.URL;
|
|
68
|
+
return (await this._account.getBasinConfig(_request, url ? { serverURL: url } : {})).basinConfig;
|
|
55
69
|
}
|
|
56
70
|
async createBasin(basin, request) {
|
|
57
71
|
const _request = {
|
|
@@ -59,10 +73,12 @@ class S2Account {
|
|
|
59
73
|
s2RequestToken: genS2RequestToken(),
|
|
60
74
|
createBasinRequest: request ?? {},
|
|
61
75
|
};
|
|
62
|
-
|
|
76
|
+
const url = this.URL;
|
|
77
|
+
return (await this._account.createBasin(_request, url ? { serverURL: url } : {})).basinInfo;
|
|
63
78
|
}
|
|
64
79
|
async deleteBasin(basin, if_exists) {
|
|
65
|
-
const
|
|
80
|
+
const url = this.URL;
|
|
81
|
+
const response = await (0, accountDeleteBasin_1.accountDeleteBasin)(this._account, { basin }, url ? { serverURL: url } : {});
|
|
66
82
|
if (if_exists && response.error instanceof errors_1.NotFoundError)
|
|
67
83
|
return;
|
|
68
84
|
if (response.error)
|
|
@@ -70,42 +86,33 @@ class S2Account {
|
|
|
70
86
|
return;
|
|
71
87
|
}
|
|
72
88
|
async reconfigureBasin(basin, config) {
|
|
89
|
+
const url = this.URL;
|
|
73
90
|
const _request = { basin, basinConfig: config };
|
|
74
|
-
return (await this._account.reconfigureBasin(_request,
|
|
91
|
+
return (await this._account.reconfigureBasin(_request, url ? { serverURL: url } : {})).basinConfig;
|
|
75
92
|
}
|
|
76
93
|
}
|
|
77
94
|
class S2Basin {
|
|
78
|
-
get
|
|
79
|
-
return `https://${this.
|
|
80
|
-
}
|
|
81
|
-
constructor(
|
|
82
|
-
this.basinURLSuffx = "
|
|
83
|
-
this._basin = new basin_1.Basin({
|
|
84
|
-
|
|
95
|
+
get URL() {
|
|
96
|
+
return `https://${endpoints_1.ClientKind.toAuthority(this.clientKind, this.config.endpoints ?? endpoints_1.S2Endpoints.forCloud(endpoints_1.S2Cloud.Aws))}${this.basinURLSuffx}`;
|
|
97
|
+
}
|
|
98
|
+
constructor(basinName, config) {
|
|
99
|
+
this.basinURLSuffx = "/v1alpha";
|
|
100
|
+
this._basin = new basin_1.Basin({
|
|
101
|
+
...(config.authToken !== undefined && { bearerAuth: config.authToken }),
|
|
102
|
+
...(config.requestTimeout !== undefined && { timeoutMs: config.requestTimeout })
|
|
103
|
+
});
|
|
104
|
+
this.config = config;
|
|
105
|
+
this.clientKind = { kind: "Basin", basin: basinName };
|
|
85
106
|
this.basinName = basinName;
|
|
86
|
-
this.requestOptions = {
|
|
87
|
-
timeoutMs: 3000,
|
|
88
|
-
retries: {
|
|
89
|
-
strategy: "backoff",
|
|
90
|
-
backoff: {
|
|
91
|
-
initialInterval: 100,
|
|
92
|
-
maxInterval: 3000,
|
|
93
|
-
exponent: 2,
|
|
94
|
-
maxElapsedTime: 6000,
|
|
95
|
-
},
|
|
96
|
-
retryConnectionErrors: true,
|
|
97
|
-
},
|
|
98
|
-
retryCodes: ["500", "503", "504"],
|
|
99
|
-
};
|
|
100
107
|
}
|
|
101
108
|
stream(streamName) {
|
|
102
|
-
return (this._stream ?? (this._stream = new Stream(this.basinName, streamName, this.
|
|
109
|
+
return (this._stream ?? (this._stream = new Stream(this.basinName, streamName, this.config)));
|
|
103
110
|
}
|
|
104
111
|
async listStreams(request) {
|
|
105
|
-
return this._basin.listStreams(request, { serverURL: this.
|
|
112
|
+
return this._basin.listStreams(request, { serverURL: this.URL });
|
|
106
113
|
}
|
|
107
114
|
async getStreamConfig(stream) {
|
|
108
|
-
return (await this._basin.getStreamConfig({ stream }, { serverURL: this.
|
|
115
|
+
return (await this._basin.getStreamConfig({ stream }, { serverURL: this.URL })).streamConfig;
|
|
109
116
|
}
|
|
110
117
|
async createStream(stream, request) {
|
|
111
118
|
const _request = {
|
|
@@ -113,12 +120,11 @@ class S2Basin {
|
|
|
113
120
|
s2RequestToken: genS2RequestToken(),
|
|
114
121
|
createStreamRequest: request ?? {},
|
|
115
122
|
};
|
|
116
|
-
return (await this._basin.createStream(_request, { serverURL: this.
|
|
123
|
+
return (await this._basin.createStream(_request, { serverURL: this.URL })).streamInfo;
|
|
117
124
|
}
|
|
118
125
|
async deleteStream(stream, if_exists) {
|
|
119
126
|
const response = await (0, basinDeleteStream_1.basinDeleteStream)(this._basin, { stream }, {
|
|
120
|
-
serverURL: this.
|
|
121
|
-
...this.requestOptions,
|
|
127
|
+
serverURL: this.URL,
|
|
122
128
|
});
|
|
123
129
|
if (if_exists && response instanceof errors_1.NotFoundError)
|
|
124
130
|
return;
|
|
@@ -127,30 +133,97 @@ class S2Basin {
|
|
|
127
133
|
return;
|
|
128
134
|
}
|
|
129
135
|
async reconfigureStream(stream, config) {
|
|
130
|
-
return (await this._basin.reconfigureStream({ stream, streamConfig: config }, { serverURL: this.
|
|
136
|
+
return (await this._basin.reconfigureStream({ stream, streamConfig: config }, { serverURL: this.URL })).streamConfig;
|
|
131
137
|
}
|
|
132
138
|
}
|
|
133
139
|
class Stream {
|
|
134
140
|
get basinURL() {
|
|
135
|
-
return `https://${this.
|
|
141
|
+
return `https://${endpoints_1.ClientKind.toAuthority(this.clientKind, this.config.endpoints ?? endpoints_1.S2Endpoints.forCloud(endpoints_1.S2Cloud.Aws))}${this.basinURLSuffx}`;
|
|
136
142
|
}
|
|
137
|
-
constructor(basinName, streamName,
|
|
138
|
-
this.basinURLSuffx = "
|
|
139
|
-
this.
|
|
143
|
+
constructor(basinName, streamName, config) {
|
|
144
|
+
this.basinURLSuffx = "/v1alpha";
|
|
145
|
+
this.config = config;
|
|
146
|
+
this.clientKind = { kind: "Basin", basin: basinName };
|
|
140
147
|
this.streamName = streamName;
|
|
141
|
-
this._stream = new stream_1.Stream({
|
|
148
|
+
this._stream = new stream_1.Stream({
|
|
149
|
+
...(config.authToken !== undefined && { bearerAuth: config.authToken }),
|
|
150
|
+
...(config.requestTimeout !== undefined && { timeoutMs: config.requestTimeout })
|
|
151
|
+
});
|
|
142
152
|
}
|
|
143
153
|
async checkTail() {
|
|
144
154
|
return (await this._stream.checkTail({ stream: this.streamName }, { serverURL: this.basinURL })).checkTailResponse;
|
|
145
155
|
}
|
|
146
|
-
async
|
|
147
|
-
return (await this._stream.
|
|
156
|
+
async append(request) {
|
|
157
|
+
return (await this._stream.append({ ...request, stream: this.streamName }, { serverURL: this.basinURL })).appendOutput;
|
|
148
158
|
}
|
|
149
159
|
async read(request) {
|
|
150
160
|
return (await this._stream.read({ ...request, stream: this.streamName }, { serverURL: this.basinURL })).output;
|
|
151
161
|
}
|
|
152
|
-
async
|
|
153
|
-
|
|
162
|
+
async *readStream(request) {
|
|
163
|
+
let currentRequest = { ...request };
|
|
164
|
+
let backoffMs = 100;
|
|
165
|
+
const maxBackoffMs = 5000;
|
|
166
|
+
const maxRetries = 5;
|
|
167
|
+
let retryCount = 0;
|
|
168
|
+
while (true) {
|
|
169
|
+
let stream;
|
|
170
|
+
try {
|
|
171
|
+
const response = await this._stream.read({ ...currentRequest, stream: this.streamName }, {
|
|
172
|
+
serverURL: this.basinURL,
|
|
173
|
+
timeoutMs: -1, // disable only for streaming
|
|
174
|
+
acceptHeaderOverride: stream_1.ReadAcceptEnum.textEventStream
|
|
175
|
+
});
|
|
176
|
+
stream = response.readResponse;
|
|
177
|
+
if (!stream)
|
|
178
|
+
return;
|
|
179
|
+
for await (const event of stream) {
|
|
180
|
+
yield event;
|
|
181
|
+
if (event.event === 'message') {
|
|
182
|
+
const output = event;
|
|
183
|
+
if ('batch' in output.data) {
|
|
184
|
+
const batch = output.data.batch;
|
|
185
|
+
if (batch.records && batch.records.length > 0) {
|
|
186
|
+
const lastRecord = batch.records[batch.records.length - 1];
|
|
187
|
+
if (lastRecord) {
|
|
188
|
+
currentRequest = { ...currentRequest, startSeqNum: lastRecord.seqNum + 1 };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (currentRequest.limit) {
|
|
192
|
+
if (currentRequest.limit.count != null) {
|
|
193
|
+
currentRequest.limit.count = Math.max(0, currentRequest.limit.count - batch.records.length);
|
|
194
|
+
}
|
|
195
|
+
if (currentRequest.limit.bytes != null) {
|
|
196
|
+
currentRequest.limit.bytes = Math.max(0, currentRequest.limit.bytes - meteredBatch(batch));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
if (error instanceof errors_1.ErrorResponse || error instanceof errors_1.NotFoundError)
|
|
206
|
+
return;
|
|
207
|
+
if (retryCount >= maxRetries) {
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
retryCount++;
|
|
211
|
+
await new Promise(resolve => setTimeout(resolve, backoffMs));
|
|
212
|
+
backoffMs = Math.min(backoffMs * 2, maxBackoffMs);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
154
215
|
}
|
|
155
216
|
}
|
|
217
|
+
function meteredRecord(batch) {
|
|
218
|
+
const fixed = 8 + (2 * batch.headers.length);
|
|
219
|
+
const headerSize = batch.headers.reduce((acc, header) => acc + header.name.length + header.value.length, 0);
|
|
220
|
+
const bodySize = batch.body.length;
|
|
221
|
+
return fixed + headerSize + bodySize;
|
|
222
|
+
}
|
|
223
|
+
function meteredBatch(batch) {
|
|
224
|
+
return batch.records.reduce((acc, record) => acc + meteredRecord(record), 0);
|
|
225
|
+
}
|
|
226
|
+
function genS2RequestToken() {
|
|
227
|
+
return (0, uuid_1.v4)().replace(/-/g, "");
|
|
228
|
+
}
|
|
156
229
|
//# sourceMappingURL=index.extras.js.map
|
package/index.extras.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.extras.js","sourceRoot":"","sources":["src/index.extras.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.extras.js","sourceRoot":"","sources":["src/index.extras.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAgVA,8CAEC;AAlVD,mEAAgE;AAgBhE,4CAA+D;AAe/D,yCAAqE;AACrE,uCAAkD;AAClD,2CAAwD;AAExD,+BAA0B;AAC1B,iEAA8D;AAE9D,2CAA+D;AAwB/D,8CAA4B;AAQ5B,MAAM,qBAAqB,GAAmB;IAC1C,cAAc,EAAE,IAAI;IACpB,SAAS,EAAE,uBAAW,CAAC,QAAQ,CAAC,mBAAO,CAAC,GAAG,CAAC;CAC/C,CAAC;AAEF,MAAa,QAAQ;IAGjB,IAAI,OAAO;QACP,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAb,IAAI,CAAC,QAAQ,GAAK,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,EAAC,CAAC;IAC1D,CAAC;IAGD,KAAK,CAAC,SAAiB;QACnB,OAAO,CAAC,IAAI,CAAC,MAAM,KAAX,IAAI,CAAC,MAAM,GAAK,IAAI,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,EAAC,CAAC;IACjE,CAAC;IAED,YAAY,MAAuB;QAC/B,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,qBAAqB,EAAE,GAAG,MAAM,EAAE,CAAC;IAC1D,CAAC;CACJ;AAfD,4BAeC;AAED,MAAM,SAAS;IAKX,YAAY,MAAsB;QAFjB,oBAAe,GAAG,UAAU,CAAC;QAG1C,IAAI,CAAC,QA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,CAAC,CAAC;YACtD,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AAED,SAAS,aAAa,CAAC,KAAsB;IACzC,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAC5G,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;IAEnC,OAAO,KAAK,GAAG,UAAU,GAAG,QAAQ,CAAC;AACzC,CAAC;AAED,SAAS,YAAY,CAAC,KAA2B;IAC7C,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,GAAG,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;AACjF,CAAC;AAED,SAAgB,iBAAiB;IAC7B,OAAO,IAAA,SAAE,GAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAClC,CAAC"}
|
package/jsr.json
CHANGED
package/lib/config.d.ts
CHANGED
|
@@ -27,8 +27,8 @@ export declare function serverURLFromOptions(options: SDKOptions): URL | null;
|
|
|
27
27
|
export declare const SDK_METADATA: {
|
|
28
28
|
readonly language: "typescript";
|
|
29
29
|
readonly openapiDocVersion: "1.0.0";
|
|
30
|
-
readonly sdkVersion: "0.3.
|
|
31
|
-
readonly genVersion: "2.
|
|
32
|
-
readonly userAgent: "speakeasy-sdk/typescript 0.3.
|
|
30
|
+
readonly sdkVersion: "0.3.8";
|
|
31
|
+
readonly genVersion: "2.506.0";
|
|
32
|
+
readonly userAgent: "speakeasy-sdk/typescript 0.3.8 2.506.0 1.0.0 @s2-dev/streamstore";
|
|
33
33
|
};
|
|
34
34
|
//# sourceMappingURL=config.d.ts.map
|
package/lib/config.js
CHANGED
|
@@ -28,8 +28,8 @@ function serverURLFromOptions(options) {
|
|
|
28
28
|
exports.SDK_METADATA = {
|
|
29
29
|
language: "typescript",
|
|
30
30
|
openapiDocVersion: "1.0.0",
|
|
31
|
-
sdkVersion: "0.3.
|
|
32
|
-
genVersion: "2.
|
|
33
|
-
userAgent: "speakeasy-sdk/typescript 0.3.
|
|
31
|
+
sdkVersion: "0.3.8",
|
|
32
|
+
genVersion: "2.506.0",
|
|
33
|
+
userAgent: "speakeasy-sdk/typescript 0.3.8 2.506.0 1.0.0 @s2-dev/streamstore",
|
|
34
34
|
};
|
|
35
35
|
//# sourceMappingURL=config.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@s2-dev/streamstore",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"author": "Speakeasy",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@eslint/js": "^9.19.0",
|
|
21
21
|
"@types/jsonpath": "^0.2.4",
|
|
22
|
+
"@types/node": "^22.13.1",
|
|
22
23
|
"@types/uuid": "^9.0.8",
|
|
23
24
|
"eslint": "^9.19.0",
|
|
24
25
|
"globals": "^15.14.0",
|
package/src/endpoints.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
type Authority = string;
|
|
2
|
+
|
|
3
|
+
// Basin Name
|
|
4
|
+
type BasinName = string;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* S2 cloud environment to connect with.
|
|
8
|
+
*/
|
|
9
|
+
export enum S2Cloud {
|
|
10
|
+
/** S2 running on AWS */
|
|
11
|
+
Aws = "aws"
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Endpoint for connecting to an S2 basin.
|
|
16
|
+
*/
|
|
17
|
+
export enum BasinEndpointKind {
|
|
18
|
+
ParentZone = "ParentZone",
|
|
19
|
+
Direct = "Direct"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type BasinEndpoint = {
|
|
23
|
+
kind: BasinEndpointKind.ParentZone;
|
|
24
|
+
authority: Authority;
|
|
25
|
+
} | {
|
|
26
|
+
kind: BasinEndpointKind.Direct;
|
|
27
|
+
authority: Authority;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
class S2EndpointError extends Error {
|
|
31
|
+
constructor(message: string) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = 'S2EndpointError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Endpoints for the S2 environment.
|
|
39
|
+
*
|
|
40
|
+
* You can find the S2 endpoints in our [documentation](https://s2.dev/docs/interface/endpoints)
|
|
41
|
+
*/
|
|
42
|
+
export class S2Endpoints {
|
|
43
|
+
/** Used by `AccountService` requests */
|
|
44
|
+
public account: Authority;
|
|
45
|
+
/** Used by `BasinService` and `StreamService` requests */
|
|
46
|
+
public basin: BasinEndpoint;
|
|
47
|
+
|
|
48
|
+
constructor(account: Authority, basin: BasinEndpoint) {
|
|
49
|
+
this.account = account;
|
|
50
|
+
this.basin = basin;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get S2 endpoints for the specified cloud.
|
|
55
|
+
*/
|
|
56
|
+
static forCloud(cloud: S2Cloud): S2Endpoints {
|
|
57
|
+
const authority = `${cloud}.s2.dev`;
|
|
58
|
+
return new S2Endpoints(
|
|
59
|
+
authority,
|
|
60
|
+
{
|
|
61
|
+
kind: BasinEndpointKind.ParentZone,
|
|
62
|
+
authority: `b.${cloud}.s2.dev`
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Get S2 endpoints for the specified cell.
|
|
69
|
+
*/
|
|
70
|
+
static forCell(cloud: S2Cloud, cellId: string): S2Endpoints {
|
|
71
|
+
const cellEndpoint = `${cellId}.o.${cloud}.s2.dev`;
|
|
72
|
+
return new S2Endpoints(
|
|
73
|
+
cellEndpoint,
|
|
74
|
+
{
|
|
75
|
+
kind: BasinEndpointKind.Direct,
|
|
76
|
+
authority: cellEndpoint
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Get S2 endpoints from environment variables.
|
|
83
|
+
*
|
|
84
|
+
* The following environment variables are used:
|
|
85
|
+
* - `S2_CLOUD`: Valid S2 cloud name. Defaults to AWS.
|
|
86
|
+
* - `S2_ACCOUNT_ENDPOINT`: Overrides the account endpoint.
|
|
87
|
+
* - `S2_BASIN_ENDPOINT`: Overrides the basin endpoint. The prefix `"{basin}."` indicates the
|
|
88
|
+
* basin endpoint is `ParentZone` else `Direct`.
|
|
89
|
+
*/
|
|
90
|
+
static fromEnv(): S2Endpoints {
|
|
91
|
+
let cloud: S2Cloud;
|
|
92
|
+
try {
|
|
93
|
+
const cloudEnv = process.env['S2_CLOUD'] || S2Cloud.Aws;
|
|
94
|
+
if (Object.values(S2Cloud).includes(cloudEnv as S2Cloud)) {
|
|
95
|
+
cloud = cloudEnv as S2Cloud;
|
|
96
|
+
} else {
|
|
97
|
+
throw new S2EndpointError(`Invalid S2_CLOUD: ${cloudEnv}`);
|
|
98
|
+
}
|
|
99
|
+
} catch (err) {
|
|
100
|
+
const error = err as Error;
|
|
101
|
+
throw new S2EndpointError(`Invalid S2_CLOUD: ${error.message}`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const endpoints = S2Endpoints.forCloud(cloud);
|
|
105
|
+
|
|
106
|
+
const accountEndpoint = process.env['S2_ACCOUNT_ENDPOINT'];
|
|
107
|
+
if (accountEndpoint !== undefined) {
|
|
108
|
+
if (typeof accountEndpoint !== 'string') {
|
|
109
|
+
throw new S2EndpointError('Invalid S2_ACCOUNT_ENDPOINT: not string');
|
|
110
|
+
}
|
|
111
|
+
endpoints.account = accountEndpoint;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const basinEndpoint = process.env['S2_BASIN_ENDPOINT'];
|
|
115
|
+
if (basinEndpoint !== undefined) {
|
|
116
|
+
if (typeof basinEndpoint !== 'string') {
|
|
117
|
+
throw new S2EndpointError('Invalid S2_BASIN_ENDPOINT: not string');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (basinEndpoint.startsWith('{basin}.')) {
|
|
121
|
+
const parentZone = basinEndpoint.substring(7);
|
|
122
|
+
endpoints.basin = {
|
|
123
|
+
kind: BasinEndpointKind.ParentZone,
|
|
124
|
+
authority: parentZone
|
|
125
|
+
};
|
|
126
|
+
} else {
|
|
127
|
+
endpoints.basin = {
|
|
128
|
+
kind: BasinEndpointKind.Direct,
|
|
129
|
+
authority: basinEndpoint
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return endpoints;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Client kind for different S2 services
|
|
140
|
+
*/
|
|
141
|
+
export type ClientKind =
|
|
142
|
+
| { kind: 'Account' }
|
|
143
|
+
| { kind: 'Basin'; basin: BasinName };
|
|
144
|
+
|
|
145
|
+
export const ClientKind = {
|
|
146
|
+
toAuthority(kind: ClientKind, endpoints: S2Endpoints): Authority {
|
|
147
|
+
switch (kind.kind) {
|
|
148
|
+
case 'Account':
|
|
149
|
+
return endpoints.account;
|
|
150
|
+
case 'Basin':
|
|
151
|
+
switch (endpoints.basin.kind) {
|
|
152
|
+
case BasinEndpointKind.ParentZone:
|
|
153
|
+
return `${kind.basin}.${endpoints.basin.authority}`;
|
|
154
|
+
case BasinEndpointKind.Direct:
|
|
155
|
+
return endpoints.basin.authority;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
package/src/index.extras.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { accountDeleteBasin } from "./funcs/accountDeleteBasin";
|
|
2
|
-
import { RequestOptions } from "./lib/sdks";
|
|
3
2
|
import {
|
|
4
3
|
AppendOutput,
|
|
5
4
|
BasinConfig,
|
|
@@ -9,10 +8,13 @@ import {
|
|
|
9
8
|
CreateStreamRequest,
|
|
10
9
|
Output,
|
|
11
10
|
ReadResponse,
|
|
11
|
+
ReadResponseOutput,
|
|
12
|
+
SequencedRecord,
|
|
13
|
+
SequencedRecordBatch,
|
|
12
14
|
StreamConfig,
|
|
13
15
|
StreamInfo,
|
|
14
16
|
} from "./models/components";
|
|
15
|
-
import { NotFoundError } from "./models/errors";
|
|
17
|
+
import { ErrorResponse, NotFoundError } from "./models/errors";
|
|
16
18
|
import {
|
|
17
19
|
GetBasinConfigRequest,
|
|
18
20
|
ListBasinsRequest,
|
|
@@ -34,6 +36,7 @@ import { Account as InnerAccount } from "./sdk/account";
|
|
|
34
36
|
import { v4 } from "uuid";
|
|
35
37
|
import { basinDeleteStream } from "./funcs/basinDeleteStream";
|
|
36
38
|
import { EventStream } from "./lib/event-streams";
|
|
39
|
+
import { ClientKind, S2Cloud, S2Endpoints } from "./endpoints";
|
|
37
40
|
|
|
38
41
|
export type ReadRequest = Omit<ReadRequestInner, "stream">;
|
|
39
42
|
export type AppendRequest = Omit<AppendRequestInner, "stream">;
|
|
@@ -57,64 +60,71 @@ export type {
|
|
|
57
60
|
StreamInfo,
|
|
58
61
|
} from "./models/components";
|
|
59
62
|
|
|
60
|
-
export
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
export * from "./endpoints";
|
|
64
|
+
|
|
65
|
+
export type S2ClientConfig = {
|
|
66
|
+
authToken?: string;
|
|
67
|
+
requestTimeout?: number;
|
|
68
|
+
endpoints?: S2Endpoints;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const defaultS2ClientConfig: S2ClientConfig = {
|
|
72
|
+
requestTimeout: 3000,
|
|
73
|
+
endpoints: S2Endpoints.forCloud(S2Cloud.Aws),
|
|
74
|
+
};
|
|
63
75
|
|
|
64
76
|
export class S2Client {
|
|
65
|
-
private
|
|
77
|
+
private config: S2ClientConfig;
|
|
66
78
|
private _account?: S2Account;
|
|
67
79
|
get account(): S2Account {
|
|
68
|
-
return (this._account ??= new S2Account(this.
|
|
80
|
+
return (this._account ??= new S2Account(this.config));
|
|
69
81
|
}
|
|
70
82
|
|
|
71
83
|
private _basin?: S2Basin;
|
|
72
84
|
basin(basinName: string): S2Basin {
|
|
73
|
-
return (this._basin ??= new S2Basin(this.
|
|
85
|
+
return (this._basin ??= new S2Basin(basinName, this.config));
|
|
74
86
|
}
|
|
75
87
|
|
|
76
|
-
constructor(
|
|
77
|
-
this.
|
|
88
|
+
constructor(config?: S2ClientConfig) {
|
|
89
|
+
this.config = { ...defaultS2ClientConfig, ...config };
|
|
78
90
|
}
|
|
79
91
|
}
|
|
80
92
|
|
|
81
93
|
class S2Account {
|
|
82
94
|
private _account: InnerAccount;
|
|
83
|
-
private
|
|
84
|
-
private
|
|
85
|
-
|
|
86
|
-
constructor(
|
|
87
|
-
this._account = new InnerAccount({
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
maxElapsedTime: 6000,
|
|
98
|
-
},
|
|
99
|
-
retryConnectionErrors: true,
|
|
100
|
-
},
|
|
101
|
-
retryCodes: ["500", "503", "504"],
|
|
102
|
-
};
|
|
95
|
+
private config: S2ClientConfig;
|
|
96
|
+
private readonly accountURLSuffx = "/v1alpha";
|
|
97
|
+
|
|
98
|
+
constructor(config: S2ClientConfig) {
|
|
99
|
+
this._account = new InnerAccount({
|
|
100
|
+
...(config.authToken !== undefined && { bearerAuth: config.authToken }),
|
|
101
|
+
...(config.requestTimeout !== undefined && { timeoutMs: config.requestTimeout })
|
|
102
|
+
});
|
|
103
|
+
this.config = config;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get URL(): string | undefined {
|
|
107
|
+
if (!this.config.endpoints) return undefined;
|
|
108
|
+
return `https://${ClientKind.toAuthority({ kind: "Account" }, this.config.endpoints)}${this.accountURLSuffx}`;
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
basin(basinName: string): S2Basin {
|
|
106
|
-
return new S2Basin(this.
|
|
112
|
+
return new S2Basin(basinName, this.config);
|
|
107
113
|
}
|
|
108
114
|
|
|
109
115
|
async listBasins(
|
|
110
116
|
request?: ListBasinsRequest
|
|
111
117
|
): Promise<PageIterator<ListBasinsResponse, { cursor: string }>> {
|
|
112
|
-
|
|
118
|
+
const url = this.URL;
|
|
119
|
+
return this._account.listBasins(request ?? {}, url ? { serverURL: url } : {});
|
|
113
120
|
}
|
|
114
121
|
|
|
115
122
|
async getBasinConfig(basin: string): Promise<BasinConfig | undefined> {
|
|
116
123
|
const _request: GetBasinConfigRequest = { basin };
|
|
117
|
-
|
|
124
|
+
const url = this.URL;
|
|
125
|
+
return (await this._account.getBasinConfig(_request
|
|
126
|
+
, url ? { serverURL: url } : {}
|
|
127
|
+
)).basinConfig;
|
|
118
128
|
}
|
|
119
129
|
|
|
120
130
|
async createBasin(basin: string, request?: CreateBasinRequest): Promise<BasinInfo | undefined> {
|
|
@@ -123,67 +133,64 @@ class S2Account {
|
|
|
123
133
|
s2RequestToken: genS2RequestToken(),
|
|
124
134
|
createBasinRequest: request ?? {},
|
|
125
135
|
};
|
|
126
|
-
|
|
136
|
+
const url = this.URL;
|
|
137
|
+
return (await this._account.createBasin(_request,
|
|
138
|
+
url ? { serverURL: url } : {}
|
|
139
|
+
)).basinInfo;
|
|
127
140
|
}
|
|
128
141
|
|
|
129
142
|
async deleteBasin(basin: string, if_exists?: boolean): Promise<void | undefined> {
|
|
130
|
-
const
|
|
143
|
+
const url = this.URL;
|
|
144
|
+
const response = await accountDeleteBasin(this._account, { basin }, url ? { serverURL: url } : {});
|
|
131
145
|
if (if_exists && response.error instanceof NotFoundError) return;
|
|
132
146
|
if (response.error) throw new Error(response.error.message);
|
|
133
147
|
return;
|
|
134
148
|
}
|
|
135
149
|
|
|
136
150
|
async reconfigureBasin(basin: string, config: BasinConfig): Promise<BasinConfig | undefined> {
|
|
151
|
+
const url = this.URL;
|
|
137
152
|
const _request: ReconfigureBasinRequest = { basin, basinConfig: config };
|
|
138
|
-
return (await this._account.reconfigureBasin(_request
|
|
153
|
+
return (await this._account.reconfigureBasin(_request
|
|
154
|
+
, url ? { serverURL: url } : {}
|
|
155
|
+
)).basinConfig;
|
|
139
156
|
}
|
|
140
157
|
}
|
|
141
158
|
|
|
142
159
|
class S2Basin {
|
|
143
160
|
private _basin: InnerBasin;
|
|
144
161
|
private _stream!: Stream;
|
|
145
|
-
private requestOptions: RequestOptions;
|
|
146
162
|
private basinName: string;
|
|
147
|
-
private
|
|
148
|
-
private
|
|
163
|
+
private config: S2ClientConfig;
|
|
164
|
+
private clientKind: ClientKind;
|
|
165
|
+
private readonly basinURLSuffx = "/v1alpha";
|
|
149
166
|
|
|
150
|
-
private get
|
|
151
|
-
return `https://${this.
|
|
167
|
+
private get URL(): string {
|
|
168
|
+
return `https://${ClientKind.toAuthority(this.clientKind, this.config.endpoints ?? S2Endpoints.forCloud(S2Cloud.Aws))}${this.basinURLSuffx}`;
|
|
152
169
|
}
|
|
153
170
|
|
|
154
|
-
constructor(
|
|
155
|
-
this._basin = new InnerBasin({
|
|
156
|
-
|
|
171
|
+
constructor(basinName: string, config: S2ClientConfig) {
|
|
172
|
+
this._basin = new InnerBasin({
|
|
173
|
+
...(config.authToken !== undefined && { bearerAuth: config.authToken }),
|
|
174
|
+
...(config.requestTimeout !== undefined && { timeoutMs: config.requestTimeout })
|
|
175
|
+
});
|
|
176
|
+
this.config = config;
|
|
177
|
+
this.clientKind = { kind: "Basin" as const, basin: basinName };
|
|
157
178
|
this.basinName = basinName;
|
|
158
|
-
this.requestOptions = {
|
|
159
|
-
timeoutMs: 3000,
|
|
160
|
-
retries: {
|
|
161
|
-
strategy: "backoff",
|
|
162
|
-
backoff: {
|
|
163
|
-
initialInterval: 100,
|
|
164
|
-
maxInterval: 3000,
|
|
165
|
-
exponent: 2,
|
|
166
|
-
maxElapsedTime: 6000,
|
|
167
|
-
},
|
|
168
|
-
retryConnectionErrors: true,
|
|
169
|
-
},
|
|
170
|
-
retryCodes: ["500", "503", "504"],
|
|
171
|
-
};
|
|
172
179
|
}
|
|
173
180
|
|
|
174
181
|
stream(streamName: string): Stream {
|
|
175
|
-
return (this._stream ??= new Stream(this.basinName, streamName, this.
|
|
182
|
+
return (this._stream ??= new Stream(this.basinName, streamName, this.config));
|
|
176
183
|
}
|
|
177
184
|
|
|
178
185
|
async listStreams(
|
|
179
186
|
request: ListStreamsRequest
|
|
180
187
|
): Promise<PageIterator<ListStreamsResponse, { cursor: string }>> {
|
|
181
|
-
return this._basin.listStreams(request, { serverURL: this.
|
|
188
|
+
return this._basin.listStreams(request, { serverURL: this.URL });
|
|
182
189
|
}
|
|
183
190
|
|
|
184
191
|
async getStreamConfig(stream: string): Promise<StreamConfig | undefined> {
|
|
185
192
|
return (
|
|
186
|
-
await this._basin.getStreamConfig({ stream }, { serverURL: this.
|
|
193
|
+
await this._basin.getStreamConfig({ stream }, { serverURL: this.URL })
|
|
187
194
|
).streamConfig;
|
|
188
195
|
}
|
|
189
196
|
|
|
@@ -194,14 +201,13 @@ class S2Basin {
|
|
|
194
201
|
createStreamRequest: request ?? {},
|
|
195
202
|
};
|
|
196
203
|
return (
|
|
197
|
-
await this._basin.createStream(_request, { serverURL: this.
|
|
204
|
+
await this._basin.createStream(_request, { serverURL: this.URL })
|
|
198
205
|
).streamInfo;
|
|
199
206
|
}
|
|
200
207
|
|
|
201
208
|
async deleteStream(stream: string, if_exists?: boolean): Promise<void | undefined> {
|
|
202
209
|
const response = await basinDeleteStream(this._basin, { stream }, {
|
|
203
|
-
serverURL: this.
|
|
204
|
-
...this.requestOptions,
|
|
210
|
+
serverURL: this.URL,
|
|
205
211
|
});
|
|
206
212
|
if (if_exists && response instanceof NotFoundError) return;
|
|
207
213
|
if (response.error) throw new Error(response.error.message);
|
|
@@ -212,7 +218,7 @@ class S2Basin {
|
|
|
212
218
|
return (
|
|
213
219
|
await this._basin.reconfigureStream(
|
|
214
220
|
{ stream, streamConfig: config },
|
|
215
|
-
{ serverURL: this.
|
|
221
|
+
{ serverURL: this.URL }
|
|
216
222
|
)
|
|
217
223
|
).streamConfig;
|
|
218
224
|
}
|
|
@@ -220,18 +226,23 @@ class S2Basin {
|
|
|
220
226
|
|
|
221
227
|
class Stream {
|
|
222
228
|
private _stream: InnerStream;
|
|
223
|
-
private basinName: string;
|
|
224
229
|
private streamName: string;
|
|
225
|
-
private
|
|
230
|
+
private config: S2ClientConfig;
|
|
231
|
+
private clientKind: ClientKind;
|
|
232
|
+
private readonly basinURLSuffx = "/v1alpha";
|
|
226
233
|
|
|
227
234
|
private get basinURL(): string {
|
|
228
|
-
return `https://${this.
|
|
235
|
+
return `https://${ClientKind.toAuthority(this.clientKind, this.config.endpoints ?? S2Endpoints.forCloud(S2Cloud.Aws))}${this.basinURLSuffx}`;
|
|
229
236
|
}
|
|
230
237
|
|
|
231
|
-
constructor(basinName: string, streamName: string,
|
|
232
|
-
this.
|
|
238
|
+
constructor(basinName: string, streamName: string, config: S2ClientConfig) {
|
|
239
|
+
this.config = config;
|
|
240
|
+
this.clientKind = { kind: "Basin" as const, basin: basinName };
|
|
233
241
|
this.streamName = streamName;
|
|
234
|
-
this._stream = new InnerStream({
|
|
242
|
+
this._stream = new InnerStream({
|
|
243
|
+
...(config.authToken !== undefined && { bearerAuth: config.authToken }),
|
|
244
|
+
...(config.requestTimeout !== undefined && { timeoutMs: config.requestTimeout })
|
|
245
|
+
});
|
|
235
246
|
}
|
|
236
247
|
|
|
237
248
|
async checkTail(): Promise<CheckTailResponse | undefined> {
|
|
@@ -240,13 +251,10 @@ class Stream {
|
|
|
240
251
|
).checkTailResponse;
|
|
241
252
|
}
|
|
242
253
|
|
|
243
|
-
async
|
|
254
|
+
async append(request: AppendRequest): Promise<AppendOutput | undefined> {
|
|
244
255
|
return (
|
|
245
|
-
await this._stream.
|
|
246
|
-
|
|
247
|
-
{ serverURL: this.basinURL, acceptHeaderOverride: ReadAcceptEnum.textEventStream }
|
|
248
|
-
)
|
|
249
|
-
).readResponse;
|
|
256
|
+
await this._stream.append({ ...request, stream: this.streamName }, { serverURL: this.basinURL })
|
|
257
|
+
).appendOutput;
|
|
250
258
|
}
|
|
251
259
|
|
|
252
260
|
async read(request: ReadRequest): Promise<Output | undefined> {
|
|
@@ -255,9 +263,77 @@ class Stream {
|
|
|
255
263
|
).output;
|
|
256
264
|
}
|
|
257
265
|
|
|
258
|
-
async
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
266
|
+
async *readStream(request: ReadRequest): AsyncGenerator<ReadResponse, void, undefined> {
|
|
267
|
+
let currentRequest: ReadRequest = { ...request };
|
|
268
|
+
let backoffMs = 100;
|
|
269
|
+
const maxBackoffMs = 5000;
|
|
270
|
+
const maxRetries = 5;
|
|
271
|
+
let retryCount = 0;
|
|
272
|
+
|
|
273
|
+
while (true) {
|
|
274
|
+
let stream: EventStream<ReadResponse> | undefined;
|
|
275
|
+
try {
|
|
276
|
+
const response = await this._stream.read(
|
|
277
|
+
{ ...currentRequest, stream: this.streamName },
|
|
278
|
+
{
|
|
279
|
+
serverURL: this.basinURL,
|
|
280
|
+
timeoutMs: -1, // disable only for streaming
|
|
281
|
+
acceptHeaderOverride: ReadAcceptEnum.textEventStream
|
|
282
|
+
}
|
|
283
|
+
);
|
|
284
|
+
stream = response.readResponse;
|
|
285
|
+
if (!stream) return;
|
|
286
|
+
|
|
287
|
+
for await (const event of stream) {
|
|
288
|
+
yield event;
|
|
289
|
+
|
|
290
|
+
if (event.event === 'message') {
|
|
291
|
+
const output = event as ReadResponseOutput;
|
|
292
|
+
if ('batch' in output.data) {
|
|
293
|
+
const batch = output.data.batch;
|
|
294
|
+
if (batch.records && batch.records.length > 0) {
|
|
295
|
+
const lastRecord = batch.records[batch.records.length - 1];
|
|
296
|
+
if (lastRecord) {
|
|
297
|
+
currentRequest = { ...currentRequest, startSeqNum: lastRecord.seqNum + 1 };
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (currentRequest.limit) {
|
|
301
|
+
if (currentRequest.limit.count != null) {
|
|
302
|
+
currentRequest.limit.count = Math.max(0, currentRequest.limit.count - batch.records.length);
|
|
303
|
+
}
|
|
304
|
+
if (currentRequest.limit.bytes != null) {
|
|
305
|
+
currentRequest.limit.bytes = Math.max(0, currentRequest.limit.bytes - meteredBatch(batch));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return;
|
|
312
|
+
} catch (error) {
|
|
313
|
+
if (error instanceof ErrorResponse || error instanceof NotFoundError) return;
|
|
314
|
+
if (retryCount >= maxRetries) {
|
|
315
|
+
throw error;
|
|
316
|
+
}
|
|
317
|
+
retryCount++;
|
|
318
|
+
await new Promise(resolve => setTimeout(resolve, backoffMs));
|
|
319
|
+
backoffMs = Math.min(backoffMs * 2, maxBackoffMs);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
262
322
|
}
|
|
263
323
|
}
|
|
324
|
+
|
|
325
|
+
function meteredRecord(batch: SequencedRecord): number {
|
|
326
|
+
const fixed = 8 + (2 * batch.headers.length);
|
|
327
|
+
const headerSize = batch.headers.reduce((acc, header) => acc + header.name.length + header.value.length, 0);
|
|
328
|
+
const bodySize = batch.body.length;
|
|
329
|
+
|
|
330
|
+
return fixed + headerSize + bodySize;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function meteredBatch(batch: SequencedRecordBatch): number {
|
|
334
|
+
return batch.records.reduce((acc, record) => acc + meteredRecord(record), 0);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export function genS2RequestToken(): string {
|
|
338
|
+
return v4().replace(/-/g, "");
|
|
339
|
+
}
|
package/src/lib/config.ts
CHANGED
|
@@ -54,7 +54,7 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
|
|
|
54
54
|
export const SDK_METADATA = {
|
|
55
55
|
language: "typescript",
|
|
56
56
|
openapiDocVersion: "1.0.0",
|
|
57
|
-
sdkVersion: "0.3.
|
|
58
|
-
genVersion: "2.
|
|
59
|
-
userAgent: "speakeasy-sdk/typescript 0.3.
|
|
57
|
+
sdkVersion: "0.3.8",
|
|
58
|
+
genVersion: "2.506.0",
|
|
59
|
+
userAgent: "speakeasy-sdk/typescript 0.3.8 2.506.0 1.0.0 @s2-dev/streamstore",
|
|
60
60
|
} as const;
|