powersync 0.1.0 → 0.1.2
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 +14 -14
- package/dist/commands/init.d.ts +0 -1
- package/dist/commands/init.js +11 -8
- package/dist/commands/instance/sync-rules/generate-schema.js +6 -6
- package/dist/constants.d.ts +2 -5
- package/dist/constants.js +4 -2
- package/dist/service/accounts.client.js +11129 -25
- package/dist/service/powersync.client.js +37453 -113
- package/dist/service/types.js +1 -1
- package/dist/service/utils.js +6 -6
- package/dist/utils.js +5 -7
- package/oclif.manifest.json +1 -1
- package/package.json +28 -20
- package/dist/powersync-sdk/accounts/api.d.ts +0 -717
- package/dist/powersync-sdk/accounts/api.js +0 -182
- package/dist/powersync-sdk/accounts/client.d.ts +0 -1096
- package/dist/powersync-sdk/accounts/client.js +0 -124
- package/dist/powersync-sdk/accounts/codecs.d.ts +0 -32
- package/dist/powersync-sdk/accounts/codecs.js +0 -93
- package/dist/powersync-sdk/accounts/index.d.ts +0 -4
- package/dist/powersync-sdk/accounts/index.js +0 -4
- package/dist/powersync-sdk/accounts/models.d.ts +0 -260
- package/dist/powersync-sdk/accounts/models.js +0 -96
- package/dist/powersync-sdk/accounts/routes.d.ts +0 -44
- package/dist/powersync-sdk/accounts/routes.js +0 -45
- package/dist/powersync-sdk/accounts/source.d.ts +0 -76
- package/dist/powersync-sdk/accounts/source.js +0 -32
- package/dist/powersync-sdk/errors/errors.d.ts +0 -62
- package/dist/powersync-sdk/errors/errors.js +0 -115
- package/dist/powersync-sdk/errors/index.d.ts +0 -2
- package/dist/powersync-sdk/errors/index.js +0 -2
- package/dist/powersync-sdk/errors/utils.d.ts +0 -4
- package/dist/powersync-sdk/errors/utils.js +0 -18
- package/dist/powersync-sdk/fetch-clients/codecs.d.ts +0 -4
- package/dist/powersync-sdk/fetch-clients/codecs.js +0 -34
- package/dist/powersync-sdk/fetch-clients/decoders.d.ts +0 -3
- package/dist/powersync-sdk/fetch-clients/decoders.js +0 -35
- package/dist/powersync-sdk/fetch-clients/definitions.d.ts +0 -97
- package/dist/powersync-sdk/fetch-clients/definitions.js +0 -22
- package/dist/powersync-sdk/fetch-clients/errors.d.ts +0 -7
- package/dist/powersync-sdk/fetch-clients/errors.js +0 -19
- package/dist/powersync-sdk/fetch-clients/index.d.ts +0 -5
- package/dist/powersync-sdk/fetch-clients/index.js +0 -5
- package/dist/powersync-sdk/fetch-clients/node-client.d.ts +0 -9
- package/dist/powersync-sdk/fetch-clients/node-client.js +0 -107
- package/dist/powersync-sdk/fetch-clients/request.d.ts +0 -11
- package/dist/powersync-sdk/fetch-clients/request.js +0 -138
- package/dist/powersync-sdk/fetch-clients/streaming.d.ts +0 -65
- package/dist/powersync-sdk/fetch-clients/streaming.js +0 -99
- package/dist/powersync-sdk/fetch-clients/utils.d.ts +0 -13
- package/dist/powersync-sdk/fetch-clients/utils.js +0 -43
- package/dist/powersync-sdk/fetch-clients/web-client.d.ts +0 -14
- package/dist/powersync-sdk/fetch-clients/web-client.js +0 -56
- package/dist/powersync-sdk/json/index.d.ts +0 -4
- package/dist/powersync-sdk/json/index.js +0 -3
- package/dist/powersync-sdk/json/json.d.ts +0 -5
- package/dist/powersync-sdk/json/json.js +0 -35
- package/dist/powersync-sdk/json/json_container.d.ts +0 -18
- package/dist/powersync-sdk/json/json_container.js +0 -28
- package/dist/powersync-sdk/json/json_stringify.d.ts +0 -36
- package/dist/powersync-sdk/json/json_stringify.js +0 -162
- package/dist/powersync-sdk/powersync/client.d.ts +0 -449
- package/dist/powersync-sdk/powersync/client.js +0 -53
- package/dist/powersync-sdk/powersync/config/HostedConfig.d.ts +0 -327
- package/dist/powersync-sdk/powersync/config/HostedConfig.js +0 -92
- package/dist/powersync-sdk/powersync/config/PowerSyncConfig.d.ts +0 -211
- package/dist/powersync-sdk/powersync/config/PowerSyncConfig.js +0 -97
- package/dist/powersync-sdk/powersync/config/normalize.d.ts +0 -32
- package/dist/powersync-sdk/powersync/config/normalize.js +0 -85
- package/dist/powersync-sdk/powersync/definitions.d.ts +0 -149
- package/dist/powersync-sdk/powersync/definitions.js +0 -97
- package/dist/powersync-sdk/powersync/index.d.ts +0 -8
- package/dist/powersync-sdk/powersync/index.js +0 -8
- package/dist/powersync-sdk/powersync/internal_routes.d.ts +0 -247
- package/dist/powersync-sdk/powersync/internal_routes.js +0 -69
- package/dist/powersync-sdk/powersync/routes.d.ts +0 -779
- package/dist/powersync-sdk/powersync/routes.js +0 -191
- package/dist/powersync-sdk/sdk-clients/endpoints.d.ts +0 -31
- package/dist/powersync-sdk/sdk-clients/endpoints.js +0 -48
- package/dist/powersync-sdk/sdk-clients/index.d.ts +0 -3
- package/dist/powersync-sdk/sdk-clients/index.js +0 -3
- package/dist/powersync-sdk/sdk-clients/pagination.d.ts +0 -14
- package/dist/powersync-sdk/sdk-clients/pagination.js +0 -21
- package/dist/powersync-sdk/sdk-clients/sdk-client.d.ts +0 -17
- package/dist/powersync-sdk/sdk-clients/sdk-client.js +0 -30
- package/dist/powersync-sdk/streaming/bson/buffer-array.d.ts +0 -31
- package/dist/powersync-sdk/streaming/bson/buffer-array.js +0 -79
- package/dist/powersync-sdk/streaming/bson/constants.d.ts +0 -2
- package/dist/powersync-sdk/streaming/bson/constants.js +0 -1
- package/dist/powersync-sdk/streaming/bson/decoder.d.ts +0 -10
- package/dist/powersync-sdk/streaming/bson/decoder.js +0 -62
- package/dist/powersync-sdk/streaming/bson/encoder.d.ts +0 -10
- package/dist/powersync-sdk/streaming/bson/encoder.js +0 -23
- package/dist/powersync-sdk/streaming/bson/header.d.ts +0 -11
- package/dist/powersync-sdk/streaming/bson/header.js +0 -52
- package/dist/powersync-sdk/streaming/bson/index.d.ts +0 -5
- package/dist/powersync-sdk/streaming/bson/index.js +0 -5
- package/dist/powersync-sdk/streaming/core/backpressure.d.ts +0 -15
- package/dist/powersync-sdk/streaming/core/backpressure.js +0 -34
- package/dist/powersync-sdk/streaming/core/cross-stream.d.ts +0 -6
- package/dist/powersync-sdk/streaming/core/cross-stream.js +0 -17
- package/dist/powersync-sdk/streaming/core/index.d.ts +0 -4
- package/dist/powersync-sdk/streaming/core/index.js +0 -4
- package/dist/powersync-sdk/streaming/core/node-utils.d.ts +0 -7
- package/dist/powersync-sdk/streaming/core/node-utils.js +0 -11
- package/dist/powersync-sdk/streaming/core/transformers.d.ts +0 -41
- package/dist/powersync-sdk/streaming/core/transformers.js +0 -70
- package/dist/powersync-sdk/streaming/core/utils.d.ts +0 -36
- package/dist/powersync-sdk/streaming/core/utils.js +0 -66
- package/dist/powersync-sdk/streaming/index.d.ts +0 -3
- package/dist/powersync-sdk/streaming/index.js +0 -3
- package/dist/powersync-sdk/streaming/web.d.ts +0 -4
- package/dist/powersync-sdk/streaming/web.js +0 -4
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binaryreader.d.ts +0 -2
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binaryreader.js +0 -36
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binarywriter.d.ts +0 -2
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binarywriter.js +0 -58
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometry.d.ts +0 -18
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometry.js +0 -348
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometrycollection.d.ts +0 -11
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometrycollection.js +0 -118
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/linestring.d.ts +0 -11
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/linestring.js +0 -131
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multilinestring.d.ts +0 -11
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multilinestring.js +0 -134
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipoint.d.ts +0 -11
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipoint.js +0 -122
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipolygon.d.ts +0 -11
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipolygon.js +0 -158
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/point.d.ts +0 -14
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/point.js +0 -165
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/polygon.d.ts +0 -11
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/polygon.js +0 -207
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/types.d.ts +0 -30
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/types.js +0 -29
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wktparser.d.ts +0 -2
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wktparser.js +0 -111
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wkx.d.ts +0 -9
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wkx.js +0 -9
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/zigzag.d.ts +0 -5
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/zigzag.js +0 -9
- package/dist/powersync-sdk/sync-rules/DartSchemaGenerator.d.ts +0 -12
- package/dist/powersync-sdk/sync-rules/DartSchemaGenerator.js +0 -35
- package/dist/powersync-sdk/sync-rules/ExpressionType.d.ts +0 -33
- package/dist/powersync-sdk/sync-rules/ExpressionType.js +0 -62
- package/dist/powersync-sdk/sync-rules/IdSequence.d.ts +0 -4
- package/dist/powersync-sdk/sync-rules/IdSequence.js +0 -7
- package/dist/powersync-sdk/sync-rules/JsSchemaGenerator.d.ts +0 -12
- package/dist/powersync-sdk/sync-rules/JsSchemaGenerator.js +0 -38
- package/dist/powersync-sdk/sync-rules/SchemaGenerator.d.ts +0 -14
- package/dist/powersync-sdk/sync-rules/SchemaGenerator.js +0 -24
- package/dist/powersync-sdk/sync-rules/SourceTableInterface.d.ts +0 -5
- package/dist/powersync-sdk/sync-rules/SourceTableInterface.js +0 -1
- package/dist/powersync-sdk/sync-rules/SqlBucketDescriptor.d.ts +0 -37
- package/dist/powersync-sdk/sync-rules/SqlBucketDescriptor.js +0 -116
- package/dist/powersync-sdk/sync-rules/SqlDataQuery.d.ts +0 -39
- package/dist/powersync-sdk/sync-rules/SqlDataQuery.js +0 -245
- package/dist/powersync-sdk/sync-rules/SqlParameterQuery.d.ts +0 -43
- package/dist/powersync-sdk/sync-rules/SqlParameterQuery.js +0 -254
- package/dist/powersync-sdk/sync-rules/SqlSyncRules.d.ts +0 -52
- package/dist/powersync-sdk/sync-rules/SqlSyncRules.js +0 -252
- package/dist/powersync-sdk/sync-rules/StaticSchema.d.ts +0 -26
- package/dist/powersync-sdk/sync-rules/StaticSchema.js +0 -71
- package/dist/powersync-sdk/sync-rules/StaticSqlParameterQuery.d.ts +0 -24
- package/dist/powersync-sdk/sync-rules/StaticSqlParameterQuery.js +0 -71
- package/dist/powersync-sdk/sync-rules/TablePattern.d.ts +0 -17
- package/dist/powersync-sdk/sync-rules/TablePattern.js +0 -56
- package/dist/powersync-sdk/sync-rules/TableQuerySchema.d.ts +0 -9
- package/dist/powersync-sdk/sync-rules/TableQuerySchema.js +0 -41
- package/dist/powersync-sdk/sync-rules/errors.d.ts +0 -22
- package/dist/powersync-sdk/sync-rules/errors.js +0 -60
- package/dist/powersync-sdk/sync-rules/generators.d.ts +0 -6
- package/dist/powersync-sdk/sync-rules/generators.js +0 -6
- package/dist/powersync-sdk/sync-rules/index.d.ts +0 -17
- package/dist/powersync-sdk/sync-rules/index.js +0 -17
- package/dist/powersync-sdk/sync-rules/json_schema.d.ts +0 -3
- package/dist/powersync-sdk/sync-rules/json_schema.js +0 -50
- package/dist/powersync-sdk/sync-rules/sql_filters.d.ts +0 -91
- package/dist/powersync-sdk/sync-rules/sql_filters.js +0 -491
- package/dist/powersync-sdk/sync-rules/sql_functions.d.ts +0 -53
- package/dist/powersync-sdk/sync-rules/sql_functions.js +0 -755
- package/dist/powersync-sdk/sync-rules/sql_support.d.ts +0 -22
- package/dist/powersync-sdk/sync-rules/sql_support.js +0 -208
- package/dist/powersync-sdk/sync-rules/types.d.ts +0 -174
- package/dist/powersync-sdk/sync-rules/types.js +0 -9
- package/dist/powersync-sdk/sync-rules/utils.d.ts +0 -45
- package/dist/powersync-sdk/sync-rules/utils.js +0 -163
- package/dist/service/accounts.client.d.ts +0 -26
- package/dist/service/powersync.client.d.ts +0 -269
- package/dist/service/types.d.ts +0 -69
- package/dist/service/utils.d.ts +0 -5
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-promise-executor-return */
|
|
2
|
-
/* eslint-disable default-case-last */
|
|
3
|
-
/* eslint-disable eqeqeq */
|
|
4
|
-
/* eslint-disable no-eq-null */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
6
|
-
/* eslint-disable camelcase */
|
|
7
|
-
import HttpAgent from 'agentkeepalive';
|
|
8
|
-
import * as http from 'node:http';
|
|
9
|
-
import * as https from 'node:https';
|
|
10
|
-
import * as stream from 'node:stream';
|
|
11
|
-
import * as consumers from 'node:stream/consumers';
|
|
12
|
-
import { URL } from 'node:url';
|
|
13
|
-
import * as errors from './errors.js';
|
|
14
|
-
import * as requester from './request.js';
|
|
15
|
-
import * as streaming from './streaming.js';
|
|
16
|
-
import * as utils from './utils.js';
|
|
17
|
-
const default_agent_options = {
|
|
18
|
-
freeSocketTimeout: 30000, // free socket keepalive for 30 seconds
|
|
19
|
-
maxFreeSockets: 10,
|
|
20
|
-
maxSockets: 100,
|
|
21
|
-
timeout: 60000 // active socket keepalive for 60 seconds
|
|
22
|
-
};
|
|
23
|
-
export const createNodeNetworkClient = (options) => {
|
|
24
|
-
const agent_options = { ...default_agent_options };
|
|
25
|
-
if (options?.timeout != null) {
|
|
26
|
-
agent_options.timeout = options?.timeout;
|
|
27
|
-
}
|
|
28
|
-
const http_agent = new HttpAgent(agent_options);
|
|
29
|
-
const https_agent = new HttpAgent.HttpsAgent(agent_options);
|
|
30
|
-
return {
|
|
31
|
-
augment(augmented) {
|
|
32
|
-
return createNodeNetworkClient({ ...augmented, ...options });
|
|
33
|
-
},
|
|
34
|
-
request(url, params) {
|
|
35
|
-
const service = process.env.MICRO_SERVICE_NAME;
|
|
36
|
-
const user_agent = `Journey SDK (node-client${service ? `,${service}` : ''})`;
|
|
37
|
-
let headers = {};
|
|
38
|
-
if (params.body && streaming.isStreamedPayload(params.body)) {
|
|
39
|
-
headers = streaming.headersForStream(params.body);
|
|
40
|
-
}
|
|
41
|
-
return requester.request(url, {
|
|
42
|
-
...options,
|
|
43
|
-
...params,
|
|
44
|
-
headers: utils.constructHeaders([headers, params.headers, options?.headers]),
|
|
45
|
-
async request(raw_url, params) {
|
|
46
|
-
const url = new URL(raw_url);
|
|
47
|
-
let agent;
|
|
48
|
-
let client;
|
|
49
|
-
switch (url.protocol) {
|
|
50
|
-
default:
|
|
51
|
-
case 'http:': {
|
|
52
|
-
agent = http_agent;
|
|
53
|
-
client = http;
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
case 'https:': {
|
|
57
|
-
agent = https_agent;
|
|
58
|
-
client = https;
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return new Promise((resolve, reject) => {
|
|
63
|
-
let aborted = false;
|
|
64
|
-
const req = client.request(url, {
|
|
65
|
-
agent,
|
|
66
|
-
headers: params.headers,
|
|
67
|
-
method: params.method,
|
|
68
|
-
signal: params.signal
|
|
69
|
-
}, (res) => {
|
|
70
|
-
if (aborted) {
|
|
71
|
-
return res.destroy(new Error('Aborted'));
|
|
72
|
-
}
|
|
73
|
-
resolve({
|
|
74
|
-
async arrayBuffer() {
|
|
75
|
-
return consumers.arrayBuffer(res);
|
|
76
|
-
},
|
|
77
|
-
body: res,
|
|
78
|
-
headers: {
|
|
79
|
-
get: (key) => utils.getHeader(res.headers, key)
|
|
80
|
-
},
|
|
81
|
-
status: res.statusCode || 200,
|
|
82
|
-
async text() {
|
|
83
|
-
return consumers.text(res);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
params.signal.addEventListener('abort', () => {
|
|
88
|
-
req.destroy(new errors.TimeoutError());
|
|
89
|
-
aborted = true;
|
|
90
|
-
});
|
|
91
|
-
req.once('error', reject);
|
|
92
|
-
if (!params.body) {
|
|
93
|
-
return req.end();
|
|
94
|
-
}
|
|
95
|
-
if (Buffer.isBuffer(params.body) || typeof params.body === 'string') {
|
|
96
|
-
req.write(params.body);
|
|
97
|
-
return req.end();
|
|
98
|
-
}
|
|
99
|
-
// eslint-disable-next-line prettier/prettier
|
|
100
|
-
stream.pipeline(params.body, req, () => { });
|
|
101
|
-
});
|
|
102
|
-
},
|
|
103
|
-
user_agent: options?.user_agent || user_agent
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as defs from './definitions.js';
|
|
2
|
-
export type FetchParams = {
|
|
3
|
-
body?: any;
|
|
4
|
-
headers: defs.Headers;
|
|
5
|
-
method: string;
|
|
6
|
-
signal: AbortSignal;
|
|
7
|
-
};
|
|
8
|
-
export type CoreRequestParams<R extends defs.TResponse> = defs.RequestParams<R, any> & defs.NetworkClientParams<R> & {
|
|
9
|
-
request: (url: string, params: FetchParams) => Promise<R>;
|
|
10
|
-
};
|
|
11
|
-
export declare const request: <R extends defs.TResponse>(url: string, params: CoreRequestParams<R>, attempt?: number) => Promise<defs.NetworkResponse<R, any>>;
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/* eslint-disable prettier/prettier */
|
|
2
|
-
/* eslint-disable complexity */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
/* eslint-disable camelcase */
|
|
5
|
-
import * as micro_streaming from '../streaming/index.js';
|
|
6
|
-
import * as codecs from './codecs.js';
|
|
7
|
-
import * as decoders from './decoders.js';
|
|
8
|
-
import * as defs from './definitions.js';
|
|
9
|
-
import * as errors from './errors.js';
|
|
10
|
-
import * as streaming from './streaming.js';
|
|
11
|
-
const defaultRetryStrategy = (attempt) => {
|
|
12
|
-
return attempt * 200;
|
|
13
|
-
};
|
|
14
|
-
const createTimeout = (handler, timeout) => {
|
|
15
|
-
let t = setTimeout(handler, timeout);
|
|
16
|
-
let cleared = false;
|
|
17
|
-
return {
|
|
18
|
-
clear() {
|
|
19
|
-
if (cleared) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
clearTimeout(t);
|
|
23
|
-
cleared = true;
|
|
24
|
-
},
|
|
25
|
-
heartbeat() {
|
|
26
|
-
if (cleared) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
clearTimeout(t);
|
|
30
|
-
t = setTimeout(handler, timeout);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
export const request = async (url, params, attempt = 0) => {
|
|
35
|
-
let headers;
|
|
36
|
-
headers =
|
|
37
|
-
typeof params.headers === 'function'
|
|
38
|
-
? await params.headers()
|
|
39
|
-
: {
|
|
40
|
-
...params.headers
|
|
41
|
-
};
|
|
42
|
-
headers = {
|
|
43
|
-
[defs.Header.Accept]: '*/*',
|
|
44
|
-
...headers
|
|
45
|
-
};
|
|
46
|
-
if (params.user_agent) {
|
|
47
|
-
headers[defs.Header.UserAgent] = params.user_agent;
|
|
48
|
-
}
|
|
49
|
-
let body;
|
|
50
|
-
if (params.body) {
|
|
51
|
-
if (streaming.isStreamedPayload(params.body)) {
|
|
52
|
-
body = params.body.encode();
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
const content_type = headers[defs.Header.ContentType] || defs.ContentType.JSON;
|
|
56
|
-
headers[defs.Header.ContentType] = content_type;
|
|
57
|
-
const codec = params.codecs?.[content_type] || codecs.DEFAULT_CODECS[content_type];
|
|
58
|
-
if (codec) {
|
|
59
|
-
body = codec.encode(params.body);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
if (!Buffer.isBuffer(params.body) && typeof params.body !== 'string') {
|
|
63
|
-
throw new TypeError(`Unsupported body with type ${typeof params.body} and a Content-Type of ${content_type}. None of the configured codecs know how to convert the given body to a Buffer or string. Please provide a compatible codec`);
|
|
64
|
-
}
|
|
65
|
-
body = params.body;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const retryStrategy = params.retry_strategy || defaultRetryStrategy;
|
|
70
|
-
const abort_controller = new AbortController();
|
|
71
|
-
const timeout = params.timeout ?? 60000;
|
|
72
|
-
const read_timeout = params.read_timeout ?? 20000;
|
|
73
|
-
let request_timeout;
|
|
74
|
-
if (timeout > 0) {
|
|
75
|
-
request_timeout = createTimeout(() => {
|
|
76
|
-
abort_controller.abort();
|
|
77
|
-
}, timeout);
|
|
78
|
-
}
|
|
79
|
-
const decoder = params.decoder || decoders.decodeServiceResponse;
|
|
80
|
-
const max_attempts = (params.retry_attempts ?? 1) - 1;
|
|
81
|
-
try {
|
|
82
|
-
const res = await params.request(url, {
|
|
83
|
-
body,
|
|
84
|
-
headers,
|
|
85
|
-
method: params.method,
|
|
86
|
-
signal: abort_controller.signal
|
|
87
|
-
});
|
|
88
|
-
// We throw here for it to be handled by the retry logic
|
|
89
|
-
if (res.status >= 500 && params.retryable && attempt <= max_attempts) {
|
|
90
|
-
throw res;
|
|
91
|
-
}
|
|
92
|
-
request_timeout?.clear();
|
|
93
|
-
const request_metadata = {
|
|
94
|
-
method: params.method.toUpperCase(),
|
|
95
|
-
url
|
|
96
|
-
};
|
|
97
|
-
return {
|
|
98
|
-
decode: () => decoder(res, request_metadata),
|
|
99
|
-
response: res,
|
|
100
|
-
async stream() {
|
|
101
|
-
if (res.status >= 300) {
|
|
102
|
-
throw await decoder(res, request_metadata);
|
|
103
|
-
}
|
|
104
|
-
let stream_timeout;
|
|
105
|
-
return micro_streaming.readableFrom(res.body).pipeThrough(new micro_streaming.compat.Transform({
|
|
106
|
-
flush() {
|
|
107
|
-
stream_timeout?.clear();
|
|
108
|
-
},
|
|
109
|
-
start(controller) {
|
|
110
|
-
if (read_timeout <= 0) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
stream_timeout = createTimeout(() => {
|
|
114
|
-
controller.error(new errors.TimeoutError());
|
|
115
|
-
}, read_timeout);
|
|
116
|
-
},
|
|
117
|
-
transform(chunk, controller) {
|
|
118
|
-
stream_timeout?.heartbeat();
|
|
119
|
-
controller.enqueue(chunk);
|
|
120
|
-
}
|
|
121
|
-
}));
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
request_timeout?.clear();
|
|
127
|
-
if (!params.retryable || attempt > max_attempts) {
|
|
128
|
-
if (error.name === 'AbortError') {
|
|
129
|
-
throw new errors.TimeoutError();
|
|
130
|
-
}
|
|
131
|
-
throw error;
|
|
132
|
-
}
|
|
133
|
-
await new Promise((resolve) => {
|
|
134
|
-
setTimeout(resolve, retryStrategy(attempt));
|
|
135
|
-
});
|
|
136
|
-
return request(url, params, attempt + 1);
|
|
137
|
-
}
|
|
138
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
import type * as stream from 'node:stream/web';
|
|
4
|
-
import * as micro_streaming from '../streaming/index.js';
|
|
5
|
-
import * as defs from './definitions.js';
|
|
6
|
-
/**
|
|
7
|
-
* This is for web compatibility. Web based ReadableStreams are not iterable even though we type them as such
|
|
8
|
-
*/
|
|
9
|
-
export declare const ensureIterable: (iterable: micro_streaming.StreamLike<any> | stream.ReadableStream) => micro_streaming.StreamLike<any>;
|
|
10
|
-
export declare enum StreamType {
|
|
11
|
-
Bson = "bson",
|
|
12
|
-
Header = "header",
|
|
13
|
-
Raw = "raw"
|
|
14
|
-
}
|
|
15
|
-
export type StreamPayload<H, S, T extends StreamType> = {
|
|
16
|
-
encode: () => micro_streaming.StreamLike<Buffer>;
|
|
17
|
-
header: H;
|
|
18
|
-
setHeader: <M extends {}>(header: M) => StreamPayload<M, S, T>;
|
|
19
|
-
stream: micro_streaming.StreamLike<S>;
|
|
20
|
-
type: T;
|
|
21
|
-
};
|
|
22
|
-
export type TRawStream = StreamPayload<any, Buffer, StreamType.Raw>;
|
|
23
|
-
export type THeaderStream<H> = StreamPayload<H, Buffer, StreamType.Header>;
|
|
24
|
-
export type TBsonStream<H, S> = StreamPayload<H, S, StreamType.Bson>;
|
|
25
|
-
export declare class RawStream implements TRawStream {
|
|
26
|
-
encode: () => micro_streaming.StreamLike<Buffer>;
|
|
27
|
-
header: any;
|
|
28
|
-
setHeader: () => RawStream;
|
|
29
|
-
stream: micro_streaming.StreamLike<Buffer>;
|
|
30
|
-
type: StreamType.Raw;
|
|
31
|
-
constructor(stream: micro_streaming.StreamLike<Buffer>);
|
|
32
|
-
}
|
|
33
|
-
export declare class HeaderStream<H extends {}> implements THeaderStream<H> {
|
|
34
|
-
encode: () => AsyncGenerator<Buffer, void, undefined>;
|
|
35
|
-
header: H;
|
|
36
|
-
setHeader: <H_1 extends {}>(header: H_1) => HeaderStream<H_1>;
|
|
37
|
-
stream: micro_streaming.StreamLike<Buffer>;
|
|
38
|
-
type: StreamType.Header;
|
|
39
|
-
constructor(stream: micro_streaming.StreamLike<Buffer>, header: H);
|
|
40
|
-
}
|
|
41
|
-
export declare class BsonStream<H extends {}, S> implements TBsonStream<H, S> {
|
|
42
|
-
header: H;
|
|
43
|
-
setHeader: <H_1 extends {}>(header: H_1) => BsonStream<H_1, S>;
|
|
44
|
-
stream: micro_streaming.StreamLike<S>;
|
|
45
|
-
type: StreamType.Bson;
|
|
46
|
-
constructor(stream: micro_streaming.StreamLike<S>, header: H);
|
|
47
|
-
encode(): AsyncGenerator<Buffer, void, undefined>;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Utility type which to specify the most specific type of stream but offer a range of
|
|
51
|
-
* less specific fallback stream types.
|
|
52
|
-
*
|
|
53
|
-
* This would most likely be used in SDK client definitions to allow callers to passthrough
|
|
54
|
-
* already encoded streams
|
|
55
|
-
*/
|
|
56
|
-
export type Stream<H, I> = TBsonStream<H, I> | THeaderStream<H> | TRawStream;
|
|
57
|
-
export declare const isStreamedPayload: (payload: any) => payload is StreamPayload<any, any, any>;
|
|
58
|
-
export declare const isRawStream: (payload: any) => payload is TRawStream;
|
|
59
|
-
export declare const isHeaderStream: (payload: any) => payload is THeaderStream<any>;
|
|
60
|
-
export declare const isBsonStream: (payload: any) => payload is TBsonStream<any, any>;
|
|
61
|
-
export declare const headersForStream: (stream: StreamPayload<any, any, any>) => {
|
|
62
|
-
"Content-Type": defs.ContentType;
|
|
63
|
-
} | {
|
|
64
|
-
"Content-Type"?: undefined;
|
|
65
|
-
};
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/* eslint-disable camelcase */
|
|
2
|
-
import * as micro_streaming from '../streaming/index.js';
|
|
3
|
-
import * as defs from './definitions.js';
|
|
4
|
-
/**
|
|
5
|
-
* This is for web compatibility. Web based ReadableStreams are not iterable even though we type them as such
|
|
6
|
-
*/
|
|
7
|
-
export const ensureIterable = (iterable) => {
|
|
8
|
-
if (iterable instanceof micro_streaming.compat.Readable && !(Symbol.asyncIterator in iterable)) {
|
|
9
|
-
return micro_streaming.iterableFromReadable(iterable);
|
|
10
|
-
}
|
|
11
|
-
return iterable;
|
|
12
|
-
};
|
|
13
|
-
export var StreamType;
|
|
14
|
-
(function (StreamType) {
|
|
15
|
-
StreamType["Bson"] = "bson";
|
|
16
|
-
StreamType["Header"] = "header";
|
|
17
|
-
StreamType["Raw"] = "raw";
|
|
18
|
-
})(StreamType || (StreamType = {}));
|
|
19
|
-
export class RawStream {
|
|
20
|
-
encode = () => {
|
|
21
|
-
return this.stream;
|
|
22
|
-
};
|
|
23
|
-
header = undefined;
|
|
24
|
-
setHeader = () => {
|
|
25
|
-
return new RawStream(this.stream);
|
|
26
|
-
};
|
|
27
|
-
stream;
|
|
28
|
-
type = StreamType.Raw;
|
|
29
|
-
constructor(stream) {
|
|
30
|
-
this.stream = stream;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export class HeaderStream {
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
encode = () => {
|
|
36
|
-
return micro_streaming.bson.prependHeaderToStream(this.header, ensureIterable(this.stream));
|
|
37
|
-
};
|
|
38
|
-
header;
|
|
39
|
-
// @ts-ignore
|
|
40
|
-
setHeader = (header) => {
|
|
41
|
-
return new HeaderStream(this.stream, header);
|
|
42
|
-
};
|
|
43
|
-
stream;
|
|
44
|
-
type = StreamType.Header;
|
|
45
|
-
constructor(stream, header) {
|
|
46
|
-
this.stream = stream;
|
|
47
|
-
this.header = header;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export class BsonStream {
|
|
51
|
-
header;
|
|
52
|
-
// @ts-ignore
|
|
53
|
-
setHeader = (header) => {
|
|
54
|
-
return new BsonStream(this.stream, header);
|
|
55
|
-
};
|
|
56
|
-
stream;
|
|
57
|
-
type = StreamType.Bson;
|
|
58
|
-
constructor(stream, header) {
|
|
59
|
-
this.stream = stream;
|
|
60
|
-
this.header = header;
|
|
61
|
-
}
|
|
62
|
-
// @ts-ignore
|
|
63
|
-
encode() {
|
|
64
|
-
const encoded = micro_streaming
|
|
65
|
-
.readableFrom(this.stream)
|
|
66
|
-
// @ts-ignore
|
|
67
|
-
.pipeThrough(micro_streaming.bson.createBSONStreamEncoder());
|
|
68
|
-
return micro_streaming.bson.prependHeaderToStream(this.header, ensureIterable(encoded));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
export const isStreamedPayload = (payload) => {
|
|
72
|
-
return Object.values(StreamType).includes(payload?.type);
|
|
73
|
-
};
|
|
74
|
-
export const isRawStream = (payload) => {
|
|
75
|
-
return payload?.type === 'raw';
|
|
76
|
-
};
|
|
77
|
-
export const isHeaderStream = (payload) => {
|
|
78
|
-
return payload?.type === 'header';
|
|
79
|
-
};
|
|
80
|
-
export const isBsonStream = (payload) => {
|
|
81
|
-
return payload?.type === 'bson';
|
|
82
|
-
};
|
|
83
|
-
export const headersForStream = (stream) => {
|
|
84
|
-
switch (stream.type) {
|
|
85
|
-
case StreamType.Header: {
|
|
86
|
-
return {
|
|
87
|
-
[defs.Header.ContentType]: defs.ContentType.HeaderStream
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
case StreamType.Bson: {
|
|
91
|
-
return {
|
|
92
|
-
[defs.Header.ContentType]: defs.ContentType.BSONStream
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
default: {
|
|
96
|
-
return {};
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { HeaderCollector, Headers } from './definitions.js';
|
|
2
|
-
export declare const constructHeaders: (collectors: (HeaderCollector | Headers | undefined)[]) => (() => Promise<Headers>);
|
|
3
|
-
/**
|
|
4
|
-
* A small utility to get a key from a map in a case-insensitive way
|
|
5
|
-
*/
|
|
6
|
-
export declare const getHeader: (headers: Record<string, string>, key: string) => string;
|
|
7
|
-
/**
|
|
8
|
-
* A weak clone of path.join from node that will work in the browser too. Joins all given
|
|
9
|
-
* strings together with a '/' and then strips off duplicates.
|
|
10
|
-
*
|
|
11
|
-
* ["https://a/b/c/", "/d/e//f/"] => "https://a/b/c///d/e//f/" => "https://a/b/c/d/e/f/"
|
|
12
|
-
*/
|
|
13
|
-
export declare const join: (...parts: string[]) => string;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export const constructHeaders = (collectors) => {
|
|
2
|
-
return async () => {
|
|
3
|
-
let headers = {};
|
|
4
|
-
for (const collector of collectors) {
|
|
5
|
-
if (!collector) {
|
|
6
|
-
continue;
|
|
7
|
-
}
|
|
8
|
-
headers =
|
|
9
|
-
typeof collector === 'function'
|
|
10
|
-
? {
|
|
11
|
-
...headers,
|
|
12
|
-
...(await collector())
|
|
13
|
-
}
|
|
14
|
-
: {
|
|
15
|
-
...headers,
|
|
16
|
-
...collector
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
return headers;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* A small utility to get a key from a map in a case-insensitive way
|
|
24
|
-
*/
|
|
25
|
-
export const getHeader = (headers, key) => {
|
|
26
|
-
return Object.fromEntries(Object.entries(headers).map(([key, value]) => {
|
|
27
|
-
return [key.toLowerCase(), value];
|
|
28
|
-
}))[key.toLowerCase()];
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* A weak clone of path.join from node that will work in the browser too. Joins all given
|
|
32
|
-
* strings together with a '/' and then strips off duplicates.
|
|
33
|
-
*
|
|
34
|
-
* ["https://a/b/c/", "/d/e//f/"] => "https://a/b/c///d/e//f/" => "https://a/b/c/d/e/f/"
|
|
35
|
-
*/
|
|
36
|
-
export const join = (...parts) => {
|
|
37
|
-
const components = parts.join('/').split(/:\/\//);
|
|
38
|
-
const deduped = (components[1] || components[0]).replaceAll(/\/\/+/g, '/');
|
|
39
|
-
if (components[1]) {
|
|
40
|
-
return [components[0], deduped].join('://');
|
|
41
|
-
}
|
|
42
|
-
return deduped;
|
|
43
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as defs from './definitions.js';
|
|
2
|
-
export type WebRequestInput = ReadableStream | any;
|
|
3
|
-
export type WebNetworkResponse = defs.NetworkResponse<Response>;
|
|
4
|
-
export type WebNetworkClient = defs.NetworkClient<WebRequestInput, WebNetworkResponse>;
|
|
5
|
-
export declare function iterableFromReadable(readable: ReadableStream): AsyncGenerator<any, void, unknown>;
|
|
6
|
-
export type WebNetworkClientOptions = defs.NetworkClientParams<Response> & {
|
|
7
|
-
/**
|
|
8
|
-
* If true then streams will buffered into a UInt8Array before being sent over network
|
|
9
|
-
*
|
|
10
|
-
* @default true
|
|
11
|
-
*/
|
|
12
|
-
buffer_streams?: boolean;
|
|
13
|
-
};
|
|
14
|
-
export declare const createWebNetworkClient: (options?: WebNetworkClientOptions) => WebNetworkClient;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-await-in-loop */
|
|
2
|
-
/* eslint-disable camelcase */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
import * as micro_streaming from '../streaming/index.js';
|
|
5
|
-
import * as requester from './request.js';
|
|
6
|
-
import * as streaming from './streaming.js';
|
|
7
|
-
import * as utils from './utils.js';
|
|
8
|
-
export async function* iterableFromReadable(readable) {
|
|
9
|
-
const reader = readable.getReader();
|
|
10
|
-
try {
|
|
11
|
-
while (true) {
|
|
12
|
-
const { done, value } = await reader.read();
|
|
13
|
-
if (done) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
yield value;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
finally {
|
|
20
|
-
reader.releaseLock();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export const createWebNetworkClient = (options) => {
|
|
24
|
-
return {
|
|
25
|
-
augment(augmented) {
|
|
26
|
-
return createWebNetworkClient({ ...augmented, ...options });
|
|
27
|
-
},
|
|
28
|
-
async request(url, params) {
|
|
29
|
-
let headers = {};
|
|
30
|
-
let body;
|
|
31
|
-
if (params.body) {
|
|
32
|
-
if (streaming.isStreamedPayload(params.body)) {
|
|
33
|
-
body =
|
|
34
|
-
options?.buffer_streams ?? true
|
|
35
|
-
? Buffer.concat(await micro_streaming.drain(streaming.ensureIterable(params.body.encode())))
|
|
36
|
-
: new streaming.RawStream(micro_streaming.readableFrom(params.body.encode()));
|
|
37
|
-
headers = streaming.headersForStream(params.body);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
body = params.body;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return requester.request(url, {
|
|
44
|
-
...options,
|
|
45
|
-
...params,
|
|
46
|
-
body,
|
|
47
|
-
headers: utils.constructHeaders([headers, params.headers, options?.headers]),
|
|
48
|
-
async request(url, params) {
|
|
49
|
-
// eslint-disable-next-line no-return-await
|
|
50
|
-
return await fetch(url, params);
|
|
51
|
-
},
|
|
52
|
-
user_agent: options?.user_agent
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import * as json from 'lossless-json';
|
|
3
|
-
import { isInteger } from 'lossless-json';
|
|
4
|
-
import { JsonContainer } from './json_container.js';
|
|
5
|
-
import { stringify } from './json_stringify.js';
|
|
6
|
-
const numberParser = (value) => {
|
|
7
|
-
return isInteger(value) ? BigInt(value) : Number.parseFloat(value);
|
|
8
|
-
};
|
|
9
|
-
const numberStringifier = {
|
|
10
|
-
stringify(value) {
|
|
11
|
-
const text = value.toString();
|
|
12
|
-
if (isInteger(text)) {
|
|
13
|
-
// Used to preserve the "type".
|
|
14
|
-
return text + '.0';
|
|
15
|
-
}
|
|
16
|
-
return text;
|
|
17
|
-
},
|
|
18
|
-
test: (value) => typeof value === 'number'
|
|
19
|
-
};
|
|
20
|
-
// Avoid a parse + serialize round-trip for JSON data.
|
|
21
|
-
const jsonContainerStringifier = {
|
|
22
|
-
stringify(value) {
|
|
23
|
-
return value.toString();
|
|
24
|
-
},
|
|
25
|
-
test: (value) => value instanceof JsonContainer
|
|
26
|
-
};
|
|
27
|
-
const stringifiers = [numberStringifier, jsonContainerStringifier];
|
|
28
|
-
export const JSONBig = {
|
|
29
|
-
parse(text, reviver) {
|
|
30
|
-
return json.parse(text, reviver, numberParser);
|
|
31
|
-
},
|
|
32
|
-
stringify(value, replacer, space) {
|
|
33
|
-
return stringify(value, replacer, space, stringifiers);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Store a JSON text value. Used to mark the value as JSON-sourced, but only parse if really needed.
|
|
3
|
-
*/
|
|
4
|
-
export declare class JsonContainer {
|
|
5
|
-
readonly data: string;
|
|
6
|
-
constructor(data: string);
|
|
7
|
-
parsed(): unknown;
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @returns The parsed representation
|
|
11
|
-
*/
|
|
12
|
-
toJSON(): unknown;
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @returns The JSON representation
|
|
16
|
-
*/
|
|
17
|
-
toString(): string;
|
|
18
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/* eslint-disable unicorn/filename-case */
|
|
2
|
-
import { JSONBig } from './json.js';
|
|
3
|
-
/**
|
|
4
|
-
* Store a JSON text value. Used to mark the value as JSON-sourced, but only parse if really needed.
|
|
5
|
-
*/
|
|
6
|
-
export class JsonContainer {
|
|
7
|
-
data;
|
|
8
|
-
constructor(data) {
|
|
9
|
-
this.data = data;
|
|
10
|
-
}
|
|
11
|
-
parsed() {
|
|
12
|
-
return JSONBig.parse(this.data);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @returns The parsed representation
|
|
17
|
-
*/
|
|
18
|
-
toJSON() {
|
|
19
|
-
return this.parsed();
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
|
-
* @returns The JSON representation
|
|
24
|
-
*/
|
|
25
|
-
toString() {
|
|
26
|
-
return this.data;
|
|
27
|
-
}
|
|
28
|
-
}
|