powersync 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -14
- package/dist/commands/init.d.ts +0 -1
- package/dist/commands/init.js +9 -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 +3 -3
- 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,191 +0,0 @@
|
|
|
1
|
-
/* eslint-disable unicorn/consistent-destructuring */
|
|
2
|
-
/* eslint-disable camelcase */
|
|
3
|
-
import * as t from 'ts-codec';
|
|
4
|
-
import { hostedPostgresConnection, powerSyncHostedConfig } from './config/HostedConfig.js';
|
|
5
|
-
import { InstanceId } from './definitions.js';
|
|
6
|
-
import * as internal_routes from './internal_routes.js';
|
|
7
|
-
// Manage instances
|
|
8
|
-
export var GENERAL_ROUTES;
|
|
9
|
-
(function (GENERAL_ROUTES) {
|
|
10
|
-
/** GET */
|
|
11
|
-
GENERAL_ROUTES["LIST_REGIONS"] = "/api/v1/regions";
|
|
12
|
-
})(GENERAL_ROUTES || (GENERAL_ROUTES = {}));
|
|
13
|
-
export var MANAGE_ROUTES;
|
|
14
|
-
(function (MANAGE_ROUTES) {
|
|
15
|
-
MANAGE_ROUTES["CONFIG"] = "/api/v1/instances/config";
|
|
16
|
-
MANAGE_ROUTES["CREATE"] = "/api/v1/instances/create";
|
|
17
|
-
MANAGE_ROUTES["DEACTIVATE"] = "/api/v1/instances/deactivate";
|
|
18
|
-
MANAGE_ROUTES["DEPLOY"] = "/api/v1/instances/deploy";
|
|
19
|
-
MANAGE_ROUTES["DESTROY"] = "/api/v1/instances/destroy";
|
|
20
|
-
MANAGE_ROUTES["DIAGNOSTICS"] = "/api/v1/instances/diagnostics";
|
|
21
|
-
MANAGE_ROUTES["LIST"] = "/api/v1/instances/list";
|
|
22
|
-
MANAGE_ROUTES["STATUS"] = "/api/v1/instances/status";
|
|
23
|
-
})(MANAGE_ROUTES || (MANAGE_ROUTES = {}));
|
|
24
|
-
// POST /api/v1/instances/list
|
|
25
|
-
export const ListInstancesRequest = t.object({
|
|
26
|
-
app_id: t.string,
|
|
27
|
-
org_id: t.string
|
|
28
|
-
});
|
|
29
|
-
export const ListInstancesResponse = t.object({
|
|
30
|
-
instances: t.array(t.object({
|
|
31
|
-
id: t.string,
|
|
32
|
-
name: t.string
|
|
33
|
-
}))
|
|
34
|
-
});
|
|
35
|
-
// POST /api/v1/instances/create
|
|
36
|
-
export const CreateInstanceRequest = t.object({
|
|
37
|
-
app_id: t.string,
|
|
38
|
-
name: t.string,
|
|
39
|
-
org_id: t.string
|
|
40
|
-
});
|
|
41
|
-
export const CreateInstanceResponse = t.object({
|
|
42
|
-
id: t.string
|
|
43
|
-
});
|
|
44
|
-
// POST /api/instances/deploy
|
|
45
|
-
export const DeployInstanceRequest = InstanceId.and(t.object({
|
|
46
|
-
config: powerSyncHostedConfig,
|
|
47
|
-
name: t.string.optional(),
|
|
48
|
-
sync_rules: t.string.optional()
|
|
49
|
-
}));
|
|
50
|
-
export const DeployInstanceResponse = t.object({
|
|
51
|
-
id: t.string,
|
|
52
|
-
operation_id: t.string
|
|
53
|
-
});
|
|
54
|
-
// POST /api/v1/instances/config
|
|
55
|
-
export const InstanceConfigRequest = InstanceId;
|
|
56
|
-
export const InstanceConfigResponse = t.object({
|
|
57
|
-
config: powerSyncHostedConfig.optional(),
|
|
58
|
-
id: t.string,
|
|
59
|
-
name: t.string,
|
|
60
|
-
sync_rules: t.string.optional()
|
|
61
|
-
});
|
|
62
|
-
// POST /api/v1/instances/status
|
|
63
|
-
// Get provisioning status. Once provisioned, other requests can be used for additional
|
|
64
|
-
// diagnostics.
|
|
65
|
-
export const InstanceStatusRequest = InstanceId;
|
|
66
|
-
export const InstanceStatusResponse = t.object({
|
|
67
|
-
id: t.string,
|
|
68
|
-
instance_url: t.string.optional(),
|
|
69
|
-
operations: t.array(t.object({
|
|
70
|
-
created_at: t.string,
|
|
71
|
-
finished_at: t.string.optional(),
|
|
72
|
-
id: t.string,
|
|
73
|
-
started_at: t.string.optional(),
|
|
74
|
-
status: t.literal('pending').or(t.literal('running')).or(t.literal('failed')).or(t.literal('completed')),
|
|
75
|
-
type: t.literal('up').or(t.literal('down'))
|
|
76
|
-
})),
|
|
77
|
-
/** True if provisioned at least once, and should therefore be running. */
|
|
78
|
-
provisioned: t.boolean
|
|
79
|
-
});
|
|
80
|
-
// POST /api/v1/instances/destroy
|
|
81
|
-
export const DestroyInstanceRequest = InstanceId;
|
|
82
|
-
export const DestroyInstanceResponse = t.object({
|
|
83
|
-
id: t.string,
|
|
84
|
-
operation_id: t.string.optional()
|
|
85
|
-
});
|
|
86
|
-
// POST /api/v1/instances/deactivate
|
|
87
|
-
export const DeactivateInstanceRequest = InstanceId;
|
|
88
|
-
export const DeactivateInstanceResponse = t.object({
|
|
89
|
-
id: t.string,
|
|
90
|
-
operation_id: t.string.optional()
|
|
91
|
-
});
|
|
92
|
-
// Debug tools
|
|
93
|
-
export var DEV_ROUTES;
|
|
94
|
-
(function (DEV_ROUTES) {
|
|
95
|
-
DEV_ROUTES["DEMO_CREDENTIALS"] = "/api/v1/instances/demo-credentials";
|
|
96
|
-
DEV_ROUTES["EXECUTE_SQL"] = "/api/v1/instances/dev/execute-sql";
|
|
97
|
-
DEV_ROUTES["GET_SCHEMA"] = "/api/v1/instances/dev/schema";
|
|
98
|
-
DEV_ROUTES["REPROCESS_SYNC_RULES"] = "/api/v1/instances/dev/reprocess-sync-rules";
|
|
99
|
-
DEV_ROUTES["TEST_CONNECTION"] = "/api/v1/connections/test";
|
|
100
|
-
DEV_ROUTES["VALIDATE_SYNC_RULES"] = "/api/v1/instances/dev/validate-sync-rules";
|
|
101
|
-
})(DEV_ROUTES || (DEV_ROUTES = {}));
|
|
102
|
-
// POST /api/v1/instances/demo-credentials
|
|
103
|
-
// Get demo credentials if available.
|
|
104
|
-
export const DemoCredentialsRequest = InstanceId.and(internal_routes.DemoCredentialsRequest);
|
|
105
|
-
export const { DemoCredentialsResponse } = internal_routes;
|
|
106
|
-
// POST /api/v1/connections/test
|
|
107
|
-
// Test a connection without deploying
|
|
108
|
-
export const TestPostgresConnectionRequest = t.object({
|
|
109
|
-
app_id: t.string,
|
|
110
|
-
connection: hostedPostgresConnection,
|
|
111
|
-
id: t.string.optional(),
|
|
112
|
-
org_id: t.string
|
|
113
|
-
});
|
|
114
|
-
export const TestPostgresConnectionResponse = t.object({
|
|
115
|
-
/**
|
|
116
|
-
* Indicates potential configuration issues.
|
|
117
|
-
*
|
|
118
|
-
* Only present if the connection succeeded.
|
|
119
|
-
*/
|
|
120
|
-
configuration: t
|
|
121
|
-
.object({
|
|
122
|
-
/** True if publication is configured correctly. */
|
|
123
|
-
publication_valid: t.boolean.optional(),
|
|
124
|
-
/** If false, check the fields below. */
|
|
125
|
-
success: t.boolean,
|
|
126
|
-
/** True if no issues detected. */
|
|
127
|
-
wal_valid: t.boolean.optional()
|
|
128
|
-
})
|
|
129
|
-
.optional(),
|
|
130
|
-
connection: t.object({
|
|
131
|
-
/** Only set if reachable and tls_valid */
|
|
132
|
-
authenticated: t.boolean.optional(),
|
|
133
|
-
/** Can open a TCP connection. */
|
|
134
|
-
reachable: t.boolean,
|
|
135
|
-
/** If false, check the fields below. */
|
|
136
|
-
success: t.boolean,
|
|
137
|
-
/** If TLS connection failed, use this CA list. */
|
|
138
|
-
suggested_cacert: t.string.optional(),
|
|
139
|
-
/** verify-full or verify-ca */
|
|
140
|
-
suggested_sslmode: t.string.optional(),
|
|
141
|
-
/**
|
|
142
|
-
* Did TLS connection work? Only set if reachable.
|
|
143
|
-
*/
|
|
144
|
-
tls_valid: t.boolean.optional()
|
|
145
|
-
}),
|
|
146
|
-
/**
|
|
147
|
-
* A human-readable error message, always set if success = false.
|
|
148
|
-
*
|
|
149
|
-
* Use as a fallback if the specific reason is not clear from other response fields.
|
|
150
|
-
*/
|
|
151
|
-
error: t.string.optional(),
|
|
152
|
-
/** If false, check the fields below. */
|
|
153
|
-
success: t.boolean
|
|
154
|
-
});
|
|
155
|
-
// POST /api/instances/dev/schema
|
|
156
|
-
// Only works if the instance is already provisioned.
|
|
157
|
-
export const GetSchemaRequest = InstanceId;
|
|
158
|
-
export const { GetSchemaResponse } = internal_routes;
|
|
159
|
-
// POST /api/v1/instances/dev/execute-sql
|
|
160
|
-
// Only works if the instance is already provisioned.
|
|
161
|
-
export const ExecuteSqlRequest = InstanceId.and(internal_routes.ExecuteSqlRequest);
|
|
162
|
-
export const { ExecuteSqlResponse } = internal_routes;
|
|
163
|
-
// POST /api/v1/instances/dev/validate-sync-rules
|
|
164
|
-
// Only works if the instance is already provisioned.
|
|
165
|
-
export const ValidateSyncRulesRequest = InstanceId.and(internal_routes.ValidateRequest);
|
|
166
|
-
export const ValidateSyncRulesResponse = internal_routes.ValidateResponse;
|
|
167
|
-
// POST /api/v1/instances/dev/reprocess-sync-rules
|
|
168
|
-
// Only works if the instance is already provisioned.
|
|
169
|
-
export const ReprocessSyncRulesRequest = InstanceId.and(internal_routes.ReprocessRequest);
|
|
170
|
-
export const ReprocessSyncRulesResponse = internal_routes.ReprocessResponse;
|
|
171
|
-
// POST /api/v1/instances/diagnostics
|
|
172
|
-
// Get instance diagnostics once provisioned.
|
|
173
|
-
export const InstanceDiagnosticsRequest = InstanceId.and(internal_routes.DiagnosticsRequest);
|
|
174
|
-
export const InstanceDiagnosticsResponse = internal_routes.DiagnosticsResponse;
|
|
175
|
-
// GET /api/v1/regions
|
|
176
|
-
// Returns list of regions to whitelist on the database.
|
|
177
|
-
export const ListRegionsRequest = t.object({});
|
|
178
|
-
/**
|
|
179
|
-
* For IP whitelisting, we recommend just including IPs from all regions.
|
|
180
|
-
*
|
|
181
|
-
* An additional "dev" region is included, with IPs used for development purposes,
|
|
182
|
-
* e.g. "test connection".
|
|
183
|
-
*/
|
|
184
|
-
export const ListRegionsResponse = t.object({
|
|
185
|
-
regions: t.array(t.object({
|
|
186
|
-
/** false for "dev" region */
|
|
187
|
-
deployable: t.boolean,
|
|
188
|
-
ips: t.array(t.string),
|
|
189
|
-
name: t.string
|
|
190
|
-
}))
|
|
191
|
-
});
|
|
@@ -1,31 +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 { CommonRequestParams, ExtractNativeResponse, ExtractNetworkResponseFromNetworkClient, METHOD, NetworkClient, StringMethod } from '../fetch-clients/definitions.js';
|
|
5
|
-
import { StreamPayload } from '../fetch-clients/streaming.js';
|
|
6
|
-
export type CreateEndpointOptions<C extends NetworkClient> = CommonRequestParams & {
|
|
7
|
-
client: C;
|
|
8
|
-
endpoint: string;
|
|
9
|
-
method?: METHOD | StringMethod;
|
|
10
|
-
path: string;
|
|
11
|
-
/**
|
|
12
|
-
* Specifying this will override any params given when executing this endpoint
|
|
13
|
-
*/
|
|
14
|
-
payload?: any;
|
|
15
|
-
retryable?: boolean;
|
|
16
|
-
};
|
|
17
|
-
export type RawRequestFunction<I, C extends NetworkClient> = (payload: I, options?: CommonRequestParams) => Promise<ExtractNetworkResponseFromNetworkClient<C>>;
|
|
18
|
-
export type StreamedEndpoint<I, O, C extends NetworkClient> = {
|
|
19
|
-
(payload: I, options?: CommonRequestParams): Promise<AsyncIterable<O> & {
|
|
20
|
-
decode: () => Promise<stream.ReadableStream<O>>;
|
|
21
|
-
response: ExtractNativeResponse<C>;
|
|
22
|
-
stream: () => Promise<stream.ReadableStream<Buffer>>;
|
|
23
|
-
}>;
|
|
24
|
-
request: RawRequestFunction<I, C>;
|
|
25
|
-
};
|
|
26
|
-
export type Endpoint<I, O, C extends NetworkClient> = {
|
|
27
|
-
(payload: I, options?: CommonRequestParams): Promise<O>;
|
|
28
|
-
request: RawRequestFunction<I, C>;
|
|
29
|
-
streamed: StreamedEndpoint<I, O, C>;
|
|
30
|
-
};
|
|
31
|
-
export declare const createEndpoint: <I extends void | {} | StreamPayload<any, any, any>, O, C extends NetworkClient = NetworkClient>(options: CreateEndpointOptions<C> | ((payload: I) => CreateEndpointOptions<C>)) => Endpoint<I, O, C>;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { METHOD } from '../fetch-clients/definitions.js';
|
|
2
|
-
import { join } from '../fetch-clients/utils.js';
|
|
3
|
-
import * as micro_streaming from '../streaming/index.js';
|
|
4
|
-
export const createEndpoint = (options) => {
|
|
5
|
-
const request = async (payload, override) => {
|
|
6
|
-
const request_options = typeof options === 'function' ? options(payload) : options;
|
|
7
|
-
const method = request_options.method || METHOD.POST;
|
|
8
|
-
let body = request_options.payload || payload;
|
|
9
|
-
/*
|
|
10
|
-
In some cases we want the payload so we can dynamically construct a GET URL (`options` is a function),
|
|
11
|
-
but don't want it automatically added to the body of the GET request
|
|
12
|
-
*/
|
|
13
|
-
if (method === METHOD.GET) {
|
|
14
|
-
body = null;
|
|
15
|
-
}
|
|
16
|
-
return await request_options.client.request(join(request_options.endpoint, request_options.path), {
|
|
17
|
-
method,
|
|
18
|
-
...request_options,
|
|
19
|
-
body,
|
|
20
|
-
...override
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
const defaultRequestFunction = async (params, override) => {
|
|
24
|
-
const res = await request(params, override);
|
|
25
|
-
return res.decode();
|
|
26
|
-
};
|
|
27
|
-
const streamedRequestFunction = async (params, override) => {
|
|
28
|
-
const res = await request(params, override);
|
|
29
|
-
const decode = async () => {
|
|
30
|
-
const stream = await res.stream();
|
|
31
|
-
return stream.pipeThrough(micro_streaming.bson.createBSONStreamDecoder());
|
|
32
|
-
};
|
|
33
|
-
return {
|
|
34
|
-
async *[Symbol.asyncIterator]() {
|
|
35
|
-
yield* micro_streaming.iterableFromReadable(await decode());
|
|
36
|
-
},
|
|
37
|
-
decode,
|
|
38
|
-
response: res.response,
|
|
39
|
-
stream: res.stream
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
return Object.assign(defaultRequestFunction, {
|
|
43
|
-
request: request,
|
|
44
|
-
streamed: Object.assign(streamedRequestFunction, {
|
|
45
|
-
request: request
|
|
46
|
-
})
|
|
47
|
-
});
|
|
48
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export type PaginationParams = {
|
|
2
|
-
cursor?: string;
|
|
3
|
-
limit?: number;
|
|
4
|
-
};
|
|
5
|
-
export type PaginationResponse = {
|
|
6
|
-
count: number;
|
|
7
|
-
cursor?: string;
|
|
8
|
-
more: boolean;
|
|
9
|
-
total: number;
|
|
10
|
-
};
|
|
11
|
-
export declare const paginate: <I extends PaginationParams, O extends PaginationResponse>(endpoint: (params: I) => Promise<O>) => (params: I) => AsyncGenerator<O, void, unknown>;
|
|
12
|
-
export declare const createPaginatedEndpoint: <I extends PaginationParams, O extends PaginationResponse>(endpoint: (params: I) => Promise<O>) => ((params: I) => Promise<O>) & {
|
|
13
|
-
paginate: (params: I) => AsyncGenerator<O, void, unknown>;
|
|
14
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export const paginate = (endpoint) => {
|
|
2
|
-
return async function* (params) {
|
|
3
|
-
let more = true;
|
|
4
|
-
let { cursor } = params;
|
|
5
|
-
while (more) {
|
|
6
|
-
const res = await endpoint({
|
|
7
|
-
...params,
|
|
8
|
-
cursor,
|
|
9
|
-
limit: params.limit || 50
|
|
10
|
-
});
|
|
11
|
-
yield res;
|
|
12
|
-
more = res.more;
|
|
13
|
-
cursor = res.cursor;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export const createPaginatedEndpoint = (endpoint) => {
|
|
18
|
-
return Object.assign(endpoint, {
|
|
19
|
-
paginate: paginate(endpoint)
|
|
20
|
-
});
|
|
21
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { NetworkClient } from '../fetch-clients/definitions.js';
|
|
2
|
-
import { StreamPayload } from '../fetch-clients/streaming.js';
|
|
3
|
-
import * as endpoints from './endpoints.js';
|
|
4
|
-
export declare class CoreSDKClient<C extends NetworkClient> {
|
|
5
|
-
readonly client: C;
|
|
6
|
-
readonly endpoint: string;
|
|
7
|
-
constructor(client: C, endpoint: string);
|
|
8
|
-
}
|
|
9
|
-
export type SDKClientOptions<C> = {
|
|
10
|
-
client: C;
|
|
11
|
-
endpoint: string;
|
|
12
|
-
};
|
|
13
|
-
export type PartialEndpoint<C extends NetworkClient> = Omit<endpoints.CreateEndpointOptions<C>, 'client' | 'endpoint'>;
|
|
14
|
-
export declare class SDKClient<C extends NetworkClient> extends CoreSDKClient<C> {
|
|
15
|
-
createEndpoint: <I extends void | {} | StreamPayload<any, any, any>, O>(params: PartialEndpoint<C> | ((payload: I) => PartialEndpoint<C>)) => endpoints.Endpoint<I, O, C>;
|
|
16
|
-
constructor(options: SDKClientOptions<C>);
|
|
17
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
-
/* eslint-disable camelcase */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
/* eslint-disable no-useless-constructor */
|
|
5
|
-
import * as endpoints from './endpoints.js';
|
|
6
|
-
export class CoreSDKClient {
|
|
7
|
-
client;
|
|
8
|
-
endpoint;
|
|
9
|
-
constructor(client, endpoint
|
|
10
|
-
// eslint-disable-next-line prettier/prettier
|
|
11
|
-
) {
|
|
12
|
-
this.client = client;
|
|
13
|
-
this.endpoint = endpoint;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export class SDKClient extends CoreSDKClient {
|
|
17
|
-
createEndpoint = (params) => {
|
|
18
|
-
return endpoints.createEndpoint((payload) => {
|
|
19
|
-
const resolved_params = typeof params === 'function' ? params(payload) : params;
|
|
20
|
-
return {
|
|
21
|
-
client: this.client,
|
|
22
|
-
endpoint: this.endpoint,
|
|
23
|
-
...resolved_params
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
constructor(options) {
|
|
28
|
-
super(options.client, options.endpoint);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/**
|
|
3
|
-
* Read a given `size` number of bytes from a give array of `chunks` as a Buffer. The returned Buffer could be
|
|
4
|
-
* larger than the requested size. If the chunks array contains less than the requested size then null is
|
|
5
|
-
* returned
|
|
6
|
-
*/
|
|
7
|
-
export declare const readBufferFromChunks: (chunks: Buffer[], size: number) => {
|
|
8
|
-
buffer: Buffer;
|
|
9
|
-
chunks_read: number;
|
|
10
|
-
} | null;
|
|
11
|
-
/**
|
|
12
|
-
* Read exactly `size` bytes from a given array of `chunks`, modifying the passed array to remove what
|
|
13
|
-
* was read.
|
|
14
|
-
*
|
|
15
|
-
* If more than `size` is read from the chunks array then the remainder is unshifted back onto the array
|
|
16
|
-
*/
|
|
17
|
-
export declare const readBufferFromChunksAndModify: (chunks: Buffer[], size: number) => Buffer | null;
|
|
18
|
-
/**
|
|
19
|
-
* Creates a abstraction on top of a compressed set of Buffer chunks that keeps track of the
|
|
20
|
-
* entire byte size of the chunks array.
|
|
21
|
-
*
|
|
22
|
-
* Offers methods to get the byte size, peak at a given amount of data and destructively read
|
|
23
|
-
* a given amount of data
|
|
24
|
-
*/
|
|
25
|
-
export declare const createReadableBufferArray: () => {
|
|
26
|
-
peek(size: number): Buffer | null;
|
|
27
|
-
push(...new_chunks: Array<Buffer | Uint8Array>): void;
|
|
28
|
-
read(size: number): Buffer | null;
|
|
29
|
-
size(): number;
|
|
30
|
-
};
|
|
31
|
-
export type ReadableBufferArray = ReturnType<typeof createReadableBufferArray>;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/* eslint-disable camelcase */
|
|
2
|
-
/**
|
|
3
|
-
* Read a given `size` number of bytes from a give array of `chunks` as a Buffer. The returned Buffer could be
|
|
4
|
-
* larger than the requested size. If the chunks array contains less than the requested size then null is
|
|
5
|
-
* returned
|
|
6
|
-
*/
|
|
7
|
-
export const readBufferFromChunks = (chunks, size) => {
|
|
8
|
-
const batch = [];
|
|
9
|
-
let current_size = 0;
|
|
10
|
-
for (const chunk of chunks) {
|
|
11
|
-
batch.push(chunk);
|
|
12
|
-
current_size += chunk.length;
|
|
13
|
-
if (current_size >= size) {
|
|
14
|
-
return {
|
|
15
|
-
buffer: Buffer.concat(batch),
|
|
16
|
-
chunks_read: batch.length
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return null;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Read exactly `size` bytes from a given array of `chunks`, modifying the passed array to remove what
|
|
24
|
-
* was read.
|
|
25
|
-
*
|
|
26
|
-
* If more than `size` is read from the chunks array then the remainder is unshifted back onto the array
|
|
27
|
-
*/
|
|
28
|
-
export const readBufferFromChunksAndModify = (chunks, size) => {
|
|
29
|
-
const res = readBufferFromChunks(chunks, size);
|
|
30
|
-
if (!res) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
if (res.buffer.length > size) {
|
|
34
|
-
chunks.splice(0, res.chunks_read, res.buffer.slice(size));
|
|
35
|
-
return res.buffer.slice(0, size);
|
|
36
|
-
}
|
|
37
|
-
chunks.splice(0, res.chunks_read);
|
|
38
|
-
return res.buffer;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Creates a abstraction on top of a compressed set of Buffer chunks that keeps track of the
|
|
42
|
-
* entire byte size of the chunks array.
|
|
43
|
-
*
|
|
44
|
-
* Offers methods to get the byte size, peak at a given amount of data and destructively read
|
|
45
|
-
* a given amount of data
|
|
46
|
-
*/
|
|
47
|
-
export const createReadableBufferArray = () => {
|
|
48
|
-
const chunks = [];
|
|
49
|
-
let current_size = 0;
|
|
50
|
-
return {
|
|
51
|
-
peek(size) {
|
|
52
|
-
if (current_size < size) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
const res = readBufferFromChunks(chunks, 4);
|
|
56
|
-
if (!res) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
return res.buffer;
|
|
60
|
-
},
|
|
61
|
-
push(...new_chunks) {
|
|
62
|
-
const normalized_chunks = new_chunks.map((chunk) => (Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)));
|
|
63
|
-
chunks.push(...normalized_chunks);
|
|
64
|
-
current_size = new_chunks.reduce((size, chunk) => {
|
|
65
|
-
return size + chunk.length;
|
|
66
|
-
}, current_size);
|
|
67
|
-
},
|
|
68
|
-
read(size) {
|
|
69
|
-
const buffer = readBufferFromChunksAndModify(chunks, size);
|
|
70
|
-
if (buffer) {
|
|
71
|
-
current_size -= size;
|
|
72
|
-
}
|
|
73
|
-
return buffer;
|
|
74
|
-
},
|
|
75
|
-
size() {
|
|
76
|
-
return current_size;
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const TERMINATOR = Buffer.from([0x00, 0x00, 0x00, 0x00]);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
import * as bson from 'bson';
|
|
4
|
-
export type BSONStreamDecoderParams<T> = {
|
|
5
|
-
deserialize_options?: bson.DeserializeOptions;
|
|
6
|
-
readableStrategy?: QueuingStrategy<T | undefined>;
|
|
7
|
-
require_terminator?: boolean;
|
|
8
|
-
writableStrategy?: QueuingStrategy<Buffer | undefined>;
|
|
9
|
-
};
|
|
10
|
-
export declare const createBSONStreamDecoder: <T = any>(params?: BSONStreamDecoderParams<T> | undefined) => import("stream/web").TransformStream<Buffer, T>;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/* eslint-disable camelcase */
|
|
3
|
-
import * as bson from 'bson';
|
|
4
|
-
import * as stream from '../core/cross-stream.js';
|
|
5
|
-
import * as buffer_array from './buffer-array.js';
|
|
6
|
-
import * as constants from './constants.js';
|
|
7
|
-
export const createBSONStreamDecoder = (params) => {
|
|
8
|
-
const buffer = buffer_array.createReadableBufferArray();
|
|
9
|
-
let frame_size = null;
|
|
10
|
-
function* decodeFrames() {
|
|
11
|
-
while (true) {
|
|
12
|
-
if (frame_size === null) {
|
|
13
|
-
frame_size = buffer.peek(4)?.readInt32LE(0) || null;
|
|
14
|
-
}
|
|
15
|
-
if (frame_size === null) {
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
if (buffer.size() < frame_size) {
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
const frame = buffer.read(frame_size);
|
|
22
|
-
if (!frame) {
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
frame_size = null;
|
|
26
|
-
yield bson.deserialize(frame, {
|
|
27
|
-
promoteBuffers: true,
|
|
28
|
-
validation: {
|
|
29
|
-
utf8: false
|
|
30
|
-
},
|
|
31
|
-
...params?.deserialize_options
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
let writableStrategy = params?.writableStrategy;
|
|
36
|
-
if (!writableStrategy) {
|
|
37
|
-
writableStrategy = new stream.ByteLengthStrategy({
|
|
38
|
-
highWaterMark: 1024 * 16
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return new stream.Transform({
|
|
42
|
-
flush(controller) {
|
|
43
|
-
for (const frame of decodeFrames()) {
|
|
44
|
-
controller.enqueue(frame);
|
|
45
|
-
}
|
|
46
|
-
const tail = buffer.peek(4);
|
|
47
|
-
if (tail && Buffer.compare(constants.TERMINATOR, tail) === 0) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (params?.require_terminator === false) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
throw new Error('stream did not complete successfully');
|
|
54
|
-
},
|
|
55
|
-
transform(chunk, controller) {
|
|
56
|
-
buffer.push(chunk);
|
|
57
|
-
for (const frame of decodeFrames()) {
|
|
58
|
-
controller.enqueue(frame);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}, writableStrategy, params?.readableStrategy);
|
|
62
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
import * as bson from 'bson';
|
|
4
|
-
export type BSONStreamEncoderParams<T> = {
|
|
5
|
-
readableStrategy?: QueuingStrategy<Buffer | undefined>;
|
|
6
|
-
sendTerminatorOnEnd?: boolean;
|
|
7
|
-
serialize_options?: bson.SerializeOptions;
|
|
8
|
-
writableStrategy?: QueuingStrategy<T | undefined>;
|
|
9
|
-
};
|
|
10
|
-
export declare const createBSONStreamEncoder: <T extends {} = any>(params?: BSONStreamEncoderParams<T> | undefined) => import("stream/web").TransformStream<T, Buffer>;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
import * as bson from 'bson';
|
|
4
|
-
import * as stream from '../core/cross-stream.js';
|
|
5
|
-
import * as constants from './constants.js';
|
|
6
|
-
export const createBSONStreamEncoder = (params) => {
|
|
7
|
-
let readableStrategy = params?.readableStrategy;
|
|
8
|
-
if (!readableStrategy) {
|
|
9
|
-
readableStrategy = new stream.ByteLengthStrategy({
|
|
10
|
-
highWaterMark: 1024 * 16
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
return new stream.Transform({
|
|
14
|
-
flush(controller) {
|
|
15
|
-
if (params?.sendTerminatorOnEnd ?? true) {
|
|
16
|
-
controller.enqueue(constants.TERMINATOR);
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
transform(chunk, controller) {
|
|
20
|
-
controller.enqueue(Buffer.from(bson.serialize(chunk, params?.serialize_options)));
|
|
21
|
-
}
|
|
22
|
-
}, params?.writableStrategy, readableStrategy);
|
|
23
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import * as bson from 'bson';
|
|
3
|
-
export type DecodedResponse<T> = {
|
|
4
|
-
header: T;
|
|
5
|
-
stream: AsyncIterable<Buffer>;
|
|
6
|
-
};
|
|
7
|
-
export type ExtractHeaderParams = {
|
|
8
|
-
deserialize_options?: bson.DeserializeOptions;
|
|
9
|
-
};
|
|
10
|
-
export declare const extractHeaderFromStream: <T = any>(input_stream: AsyncIterable<Buffer>, params?: ExtractHeaderParams) => Promise<DecodedResponse<T>>;
|
|
11
|
-
export declare function prependHeaderToStream(header: any, input_stream: AsyncIterable<Buffer> | Iterable<Buffer>): AsyncGenerator<Buffer, void, undefined>;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-constant-condition */
|
|
2
|
-
/* eslint-disable no-await-in-loop */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
/* eslint-disable camelcase */
|
|
5
|
-
import * as bson from 'bson';
|
|
6
|
-
import * as buffer_array from './buffer-array.js';
|
|
7
|
-
export const extractHeaderFromStream = async (input_stream, params) => {
|
|
8
|
-
const iterator = input_stream[Symbol.asyncIterator]();
|
|
9
|
-
const buffer = buffer_array.createReadableBufferArray();
|
|
10
|
-
let frame_size = null;
|
|
11
|
-
async function* resplice(data, iterator) {
|
|
12
|
-
if (data) {
|
|
13
|
-
yield data;
|
|
14
|
-
}
|
|
15
|
-
while (true) {
|
|
16
|
-
const next = await iterator.next();
|
|
17
|
-
if (next.done) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
yield next.value;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
while (true) {
|
|
24
|
-
const chunk = await iterator.next();
|
|
25
|
-
if (chunk.done) {
|
|
26
|
-
throw new Error('Stream did not complete successfully');
|
|
27
|
-
}
|
|
28
|
-
buffer.push(chunk.value);
|
|
29
|
-
if (frame_size === null) {
|
|
30
|
-
frame_size = buffer.peek(4)?.readInt32LE(0) || null;
|
|
31
|
-
}
|
|
32
|
-
if (frame_size === null) {
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
const frame = buffer.read(frame_size);
|
|
36
|
-
if (!frame) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
const header = bson.deserialize(frame, {
|
|
40
|
-
promoteBuffers: true,
|
|
41
|
-
...params?.deserialize_options
|
|
42
|
-
});
|
|
43
|
-
return {
|
|
44
|
-
header: header,
|
|
45
|
-
stream: resplice(buffer.read(buffer.size()), iterator)
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
export async function* prependHeaderToStream(header, input_stream) {
|
|
50
|
-
yield bson.serialize(header);
|
|
51
|
-
yield* input_stream;
|
|
52
|
-
}
|