powersync 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/README.md +339 -0
  2. package/bin/dev.cmd +3 -0
  3. package/bin/dev.js +9 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +8 -0
  6. package/dist/commands/init.d.ts +7 -0
  7. package/dist/commands/init.js +49 -0
  8. package/dist/commands/instance/config.d.ts +6 -0
  9. package/dist/commands/instance/config.js +23 -0
  10. package/dist/commands/instance/create.d.ts +16 -0
  11. package/dist/commands/instance/create.js +163 -0
  12. package/dist/commands/instance/deploy.d.ts +15 -0
  13. package/dist/commands/instance/deploy.js +142 -0
  14. package/dist/commands/instance/destroy.d.ts +9 -0
  15. package/dist/commands/instance/destroy.js +42 -0
  16. package/dist/commands/instance/schema.d.ts +6 -0
  17. package/dist/commands/instance/schema.js +20 -0
  18. package/dist/commands/instance/set.d.ts +9 -0
  19. package/dist/commands/instance/set.js +31 -0
  20. package/dist/commands/instance/status.d.ts +6 -0
  21. package/dist/commands/instance/status.js +21 -0
  22. package/dist/commands/instance/stop.d.ts +9 -0
  23. package/dist/commands/instance/stop.js +42 -0
  24. package/dist/commands/instance/sync-rules/deploy.d.ts +10 -0
  25. package/dist/commands/instance/sync-rules/deploy.js +49 -0
  26. package/dist/commands/instance/sync-rules/generate-schema.d.ts +10 -0
  27. package/dist/commands/instance/sync-rules/generate-schema.js +55 -0
  28. package/dist/commands/instance/sync-rules/validate.d.ts +9 -0
  29. package/dist/commands/instance/sync-rules/validate.js +29 -0
  30. package/dist/commands/instances.d.ts +6 -0
  31. package/dist/commands/instances.js +20 -0
  32. package/dist/constants.d.ts +11 -0
  33. package/dist/constants.js +8 -0
  34. package/dist/index.d.ts +1 -0
  35. package/dist/index.js +1 -0
  36. package/dist/powersync-sdk/accounts/api.d.ts +717 -0
  37. package/dist/powersync-sdk/accounts/api.js +182 -0
  38. package/dist/powersync-sdk/accounts/client.d.ts +1096 -0
  39. package/dist/powersync-sdk/accounts/client.js +124 -0
  40. package/dist/powersync-sdk/accounts/codecs.d.ts +32 -0
  41. package/dist/powersync-sdk/accounts/codecs.js +93 -0
  42. package/dist/powersync-sdk/accounts/index.d.ts +4 -0
  43. package/dist/powersync-sdk/accounts/index.js +4 -0
  44. package/dist/powersync-sdk/accounts/models.d.ts +260 -0
  45. package/dist/powersync-sdk/accounts/models.js +96 -0
  46. package/dist/powersync-sdk/accounts/routes.d.ts +44 -0
  47. package/dist/powersync-sdk/accounts/routes.js +45 -0
  48. package/dist/powersync-sdk/accounts/source.d.ts +76 -0
  49. package/dist/powersync-sdk/accounts/source.js +32 -0
  50. package/dist/powersync-sdk/errors/errors.d.ts +62 -0
  51. package/dist/powersync-sdk/errors/errors.js +115 -0
  52. package/dist/powersync-sdk/errors/index.d.ts +2 -0
  53. package/dist/powersync-sdk/errors/index.js +2 -0
  54. package/dist/powersync-sdk/errors/utils.d.ts +4 -0
  55. package/dist/powersync-sdk/errors/utils.js +18 -0
  56. package/dist/powersync-sdk/fetch-clients/codecs.d.ts +4 -0
  57. package/dist/powersync-sdk/fetch-clients/codecs.js +34 -0
  58. package/dist/powersync-sdk/fetch-clients/decoders.d.ts +3 -0
  59. package/dist/powersync-sdk/fetch-clients/decoders.js +35 -0
  60. package/dist/powersync-sdk/fetch-clients/definitions.d.ts +97 -0
  61. package/dist/powersync-sdk/fetch-clients/definitions.js +22 -0
  62. package/dist/powersync-sdk/fetch-clients/errors.d.ts +7 -0
  63. package/dist/powersync-sdk/fetch-clients/errors.js +19 -0
  64. package/dist/powersync-sdk/fetch-clients/index.d.ts +5 -0
  65. package/dist/powersync-sdk/fetch-clients/index.js +5 -0
  66. package/dist/powersync-sdk/fetch-clients/node-client.d.ts +9 -0
  67. package/dist/powersync-sdk/fetch-clients/node-client.js +107 -0
  68. package/dist/powersync-sdk/fetch-clients/request.d.ts +11 -0
  69. package/dist/powersync-sdk/fetch-clients/request.js +138 -0
  70. package/dist/powersync-sdk/fetch-clients/streaming.d.ts +65 -0
  71. package/dist/powersync-sdk/fetch-clients/streaming.js +99 -0
  72. package/dist/powersync-sdk/fetch-clients/utils.d.ts +13 -0
  73. package/dist/powersync-sdk/fetch-clients/utils.js +43 -0
  74. package/dist/powersync-sdk/fetch-clients/web-client.d.ts +14 -0
  75. package/dist/powersync-sdk/fetch-clients/web-client.js +56 -0
  76. package/dist/powersync-sdk/json/index.d.ts +4 -0
  77. package/dist/powersync-sdk/json/index.js +3 -0
  78. package/dist/powersync-sdk/json/json.d.ts +5 -0
  79. package/dist/powersync-sdk/json/json.js +35 -0
  80. package/dist/powersync-sdk/json/json_container.d.ts +18 -0
  81. package/dist/powersync-sdk/json/json_container.js +28 -0
  82. package/dist/powersync-sdk/json/json_stringify.d.ts +36 -0
  83. package/dist/powersync-sdk/json/json_stringify.js +162 -0
  84. package/dist/powersync-sdk/powersync/client.d.ts +449 -0
  85. package/dist/powersync-sdk/powersync/client.js +53 -0
  86. package/dist/powersync-sdk/powersync/config/HostedConfig.d.ts +327 -0
  87. package/dist/powersync-sdk/powersync/config/HostedConfig.js +92 -0
  88. package/dist/powersync-sdk/powersync/config/PowerSyncConfig.d.ts +211 -0
  89. package/dist/powersync-sdk/powersync/config/PowerSyncConfig.js +97 -0
  90. package/dist/powersync-sdk/powersync/config/normalize.d.ts +32 -0
  91. package/dist/powersync-sdk/powersync/config/normalize.js +85 -0
  92. package/dist/powersync-sdk/powersync/definitions.d.ts +149 -0
  93. package/dist/powersync-sdk/powersync/definitions.js +97 -0
  94. package/dist/powersync-sdk/powersync/index.d.ts +8 -0
  95. package/dist/powersync-sdk/powersync/index.js +8 -0
  96. package/dist/powersync-sdk/powersync/internal_routes.d.ts +247 -0
  97. package/dist/powersync-sdk/powersync/internal_routes.js +69 -0
  98. package/dist/powersync-sdk/powersync/routes.d.ts +779 -0
  99. package/dist/powersync-sdk/powersync/routes.js +191 -0
  100. package/dist/powersync-sdk/sdk-clients/endpoints.d.ts +31 -0
  101. package/dist/powersync-sdk/sdk-clients/endpoints.js +48 -0
  102. package/dist/powersync-sdk/sdk-clients/index.d.ts +3 -0
  103. package/dist/powersync-sdk/sdk-clients/index.js +3 -0
  104. package/dist/powersync-sdk/sdk-clients/pagination.d.ts +14 -0
  105. package/dist/powersync-sdk/sdk-clients/pagination.js +21 -0
  106. package/dist/powersync-sdk/sdk-clients/sdk-client.d.ts +17 -0
  107. package/dist/powersync-sdk/sdk-clients/sdk-client.js +30 -0
  108. package/dist/powersync-sdk/streaming/bson/buffer-array.d.ts +31 -0
  109. package/dist/powersync-sdk/streaming/bson/buffer-array.js +79 -0
  110. package/dist/powersync-sdk/streaming/bson/constants.d.ts +2 -0
  111. package/dist/powersync-sdk/streaming/bson/constants.js +1 -0
  112. package/dist/powersync-sdk/streaming/bson/decoder.d.ts +10 -0
  113. package/dist/powersync-sdk/streaming/bson/decoder.js +62 -0
  114. package/dist/powersync-sdk/streaming/bson/encoder.d.ts +10 -0
  115. package/dist/powersync-sdk/streaming/bson/encoder.js +23 -0
  116. package/dist/powersync-sdk/streaming/bson/header.d.ts +11 -0
  117. package/dist/powersync-sdk/streaming/bson/header.js +52 -0
  118. package/dist/powersync-sdk/streaming/bson/index.d.ts +5 -0
  119. package/dist/powersync-sdk/streaming/bson/index.js +5 -0
  120. package/dist/powersync-sdk/streaming/core/backpressure.d.ts +15 -0
  121. package/dist/powersync-sdk/streaming/core/backpressure.js +34 -0
  122. package/dist/powersync-sdk/streaming/core/cross-stream.d.ts +6 -0
  123. package/dist/powersync-sdk/streaming/core/cross-stream.js +17 -0
  124. package/dist/powersync-sdk/streaming/core/index.d.ts +4 -0
  125. package/dist/powersync-sdk/streaming/core/index.js +4 -0
  126. package/dist/powersync-sdk/streaming/core/node-utils.d.ts +7 -0
  127. package/dist/powersync-sdk/streaming/core/node-utils.js +11 -0
  128. package/dist/powersync-sdk/streaming/core/transformers.d.ts +41 -0
  129. package/dist/powersync-sdk/streaming/core/transformers.js +70 -0
  130. package/dist/powersync-sdk/streaming/core/utils.d.ts +36 -0
  131. package/dist/powersync-sdk/streaming/core/utils.js +66 -0
  132. package/dist/powersync-sdk/streaming/index.d.ts +3 -0
  133. package/dist/powersync-sdk/streaming/index.js +3 -0
  134. package/dist/powersync-sdk/streaming/web.d.ts +4 -0
  135. package/dist/powersync-sdk/streaming/web.js +4 -0
  136. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binaryreader.d.ts +2 -0
  137. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binaryreader.js +36 -0
  138. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binarywriter.d.ts +2 -0
  139. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binarywriter.js +58 -0
  140. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometry.d.ts +18 -0
  141. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometry.js +348 -0
  142. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometrycollection.d.ts +11 -0
  143. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometrycollection.js +118 -0
  144. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/linestring.d.ts +11 -0
  145. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/linestring.js +131 -0
  146. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multilinestring.d.ts +11 -0
  147. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multilinestring.js +134 -0
  148. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipoint.d.ts +11 -0
  149. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipoint.js +122 -0
  150. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipolygon.d.ts +11 -0
  151. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipolygon.js +158 -0
  152. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/point.d.ts +14 -0
  153. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/point.js +165 -0
  154. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/polygon.d.ts +11 -0
  155. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/polygon.js +207 -0
  156. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/types.d.ts +30 -0
  157. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/types.js +29 -0
  158. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wktparser.d.ts +2 -0
  159. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wktparser.js +111 -0
  160. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wkx.d.ts +9 -0
  161. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wkx.js +9 -0
  162. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/zigzag.d.ts +5 -0
  163. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/zigzag.js +9 -0
  164. package/dist/powersync-sdk/sync-rules/DartSchemaGenerator.d.ts +12 -0
  165. package/dist/powersync-sdk/sync-rules/DartSchemaGenerator.js +35 -0
  166. package/dist/powersync-sdk/sync-rules/ExpressionType.d.ts +33 -0
  167. package/dist/powersync-sdk/sync-rules/ExpressionType.js +62 -0
  168. package/dist/powersync-sdk/sync-rules/IdSequence.d.ts +4 -0
  169. package/dist/powersync-sdk/sync-rules/IdSequence.js +7 -0
  170. package/dist/powersync-sdk/sync-rules/JsSchemaGenerator.d.ts +12 -0
  171. package/dist/powersync-sdk/sync-rules/JsSchemaGenerator.js +38 -0
  172. package/dist/powersync-sdk/sync-rules/SchemaGenerator.d.ts +14 -0
  173. package/dist/powersync-sdk/sync-rules/SchemaGenerator.js +24 -0
  174. package/dist/powersync-sdk/sync-rules/SourceTableInterface.d.ts +5 -0
  175. package/dist/powersync-sdk/sync-rules/SourceTableInterface.js +1 -0
  176. package/dist/powersync-sdk/sync-rules/SqlBucketDescriptor.d.ts +37 -0
  177. package/dist/powersync-sdk/sync-rules/SqlBucketDescriptor.js +116 -0
  178. package/dist/powersync-sdk/sync-rules/SqlDataQuery.d.ts +39 -0
  179. package/dist/powersync-sdk/sync-rules/SqlDataQuery.js +245 -0
  180. package/dist/powersync-sdk/sync-rules/SqlParameterQuery.d.ts +43 -0
  181. package/dist/powersync-sdk/sync-rules/SqlParameterQuery.js +254 -0
  182. package/dist/powersync-sdk/sync-rules/SqlSyncRules.d.ts +52 -0
  183. package/dist/powersync-sdk/sync-rules/SqlSyncRules.js +252 -0
  184. package/dist/powersync-sdk/sync-rules/StaticSchema.d.ts +26 -0
  185. package/dist/powersync-sdk/sync-rules/StaticSchema.js +71 -0
  186. package/dist/powersync-sdk/sync-rules/StaticSqlParameterQuery.d.ts +24 -0
  187. package/dist/powersync-sdk/sync-rules/StaticSqlParameterQuery.js +71 -0
  188. package/dist/powersync-sdk/sync-rules/TablePattern.d.ts +17 -0
  189. package/dist/powersync-sdk/sync-rules/TablePattern.js +56 -0
  190. package/dist/powersync-sdk/sync-rules/TableQuerySchema.d.ts +9 -0
  191. package/dist/powersync-sdk/sync-rules/TableQuerySchema.js +41 -0
  192. package/dist/powersync-sdk/sync-rules/errors.d.ts +22 -0
  193. package/dist/powersync-sdk/sync-rules/errors.js +60 -0
  194. package/dist/powersync-sdk/sync-rules/generators.d.ts +6 -0
  195. package/dist/powersync-sdk/sync-rules/generators.js +6 -0
  196. package/dist/powersync-sdk/sync-rules/index.d.ts +17 -0
  197. package/dist/powersync-sdk/sync-rules/index.js +17 -0
  198. package/dist/powersync-sdk/sync-rules/json_schema.d.ts +3 -0
  199. package/dist/powersync-sdk/sync-rules/json_schema.js +50 -0
  200. package/dist/powersync-sdk/sync-rules/sql_filters.d.ts +91 -0
  201. package/dist/powersync-sdk/sync-rules/sql_filters.js +491 -0
  202. package/dist/powersync-sdk/sync-rules/sql_functions.d.ts +53 -0
  203. package/dist/powersync-sdk/sync-rules/sql_functions.js +755 -0
  204. package/dist/powersync-sdk/sync-rules/sql_support.d.ts +22 -0
  205. package/dist/powersync-sdk/sync-rules/sql_support.js +208 -0
  206. package/dist/powersync-sdk/sync-rules/types.d.ts +174 -0
  207. package/dist/powersync-sdk/sync-rules/types.js +9 -0
  208. package/dist/powersync-sdk/sync-rules/utils.d.ts +45 -0
  209. package/dist/powersync-sdk/sync-rules/utils.js +163 -0
  210. package/dist/service/accounts.client.d.ts +26 -0
  211. package/dist/service/accounts.client.js +26 -0
  212. package/dist/service/powersync.client.d.ts +269 -0
  213. package/dist/service/powersync.client.js +135 -0
  214. package/dist/service/types.d.ts +69 -0
  215. package/dist/service/types.js +1 -0
  216. package/dist/service/utils.d.ts +5 -0
  217. package/dist/service/utils.js +7 -0
  218. package/dist/utils.d.ts +6 -0
  219. package/dist/utils.js +52 -0
  220. package/oclif.manifest.json +514 -0
  221. package/package.json +81 -0
@@ -0,0 +1,5 @@
1
+ export * from './buffer-array.js';
2
+ export * from './constants.js';
3
+ export * from './encoder.js';
4
+ export * from './decoder.js';
5
+ export * from './header.js';
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import * as stream from 'node:stream';
3
+ export type SimpleReadableLike = stream.Readable | stream.Transform;
4
+ /**
5
+ * This provides an abstraction for pushing data onto a Readable stream, returning a Promise that
6
+ * resolves once any present backpressure is drained.
7
+ *
8
+ * This is special as it can handle Transform streams in addition to normal Readables. Transform
9
+ * streams don't natively expose a method for hooking into the readable sides drain and causes
10
+ * problems when building inflating transforms.
11
+ *
12
+ * The comment at the top of the official node implementation provides more detailed information
13
+ * on the problem: https://github.com/nodejs/node/blob/master/lib/internal/streams/transform.js
14
+ */
15
+ export declare const push: (readable: SimpleReadableLike, data: any) => Promise<void>;
@@ -0,0 +1,34 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /* eslint-disable camelcase */
3
+ import * as stream from 'node:stream';
4
+ /**
5
+ * This provides an abstraction for pushing data onto a Readable stream, returning a Promise that
6
+ * resolves once any present backpressure is drained.
7
+ *
8
+ * This is special as it can handle Transform streams in addition to normal Readables. Transform
9
+ * streams don't natively expose a method for hooking into the readable sides drain and causes
10
+ * problems when building inflating transforms.
11
+ *
12
+ * The comment at the top of the official node implementation provides more detailed information
13
+ * on the problem: https://github.com/nodejs/node/blob/master/lib/internal/streams/transform.js
14
+ */
15
+ export const push = async (readable, data) => {
16
+ const can_continue = readable.push(data);
17
+ if (can_continue) {
18
+ return;
19
+ }
20
+ // We can't really support transform streams
21
+ if (readable instanceof stream.Transform) {
22
+ return;
23
+ }
24
+ return new Promise((resolve) => {
25
+ const errorHandler = () => {
26
+ resolve();
27
+ };
28
+ readable.once('error', errorHandler);
29
+ readable.once('drain', () => {
30
+ readable.removeListener('error', errorHandler);
31
+ resolve();
32
+ });
33
+ });
34
+ };
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type * as stream from 'node:stream/web';
3
+ declare let Readable: typeof stream.ReadableStream;
4
+ declare let Transform: typeof stream.TransformStream;
5
+ declare let ByteLengthStrategy: typeof stream.ByteLengthQueuingStrategy;
6
+ export { ByteLengthStrategy, Readable, Transform };
@@ -0,0 +1,17 @@
1
+ let Readable;
2
+ let Transform;
3
+ let ByteLengthStrategy;
4
+ if (typeof window === 'undefined') {
5
+ // eslint-disable-next-line unicorn/prefer-top-level-await
6
+ import('node:stream/web').then((webstream) => {
7
+ Readable = webstream.ReadableStream;
8
+ Transform = webstream.TransformStream;
9
+ ByteLengthStrategy = webstream.ByteLengthQueuingStrategy;
10
+ });
11
+ }
12
+ else {
13
+ Readable = ReadableStream;
14
+ Transform = TransformStream;
15
+ ByteLengthStrategy = ByteLengthQueuingStrategy;
16
+ }
17
+ export { ByteLengthStrategy, Readable, Transform };
@@ -0,0 +1,4 @@
1
+ export * from './backpressure.js';
2
+ export * from './transformers.js';
3
+ export * from './node-utils.js';
4
+ export * from './utils.js';
@@ -0,0 +1,4 @@
1
+ export * from './backpressure.js';
2
+ export * from './transformers.js';
3
+ export * from './node-utils.js';
4
+ export * from './utils.js';
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import * as stream from 'node:stream';
3
+ /**
4
+ * Returns a promise that resolves once the given stream finishes. If the stream emits an error then
5
+ * then promise will reject
6
+ */
7
+ export declare const wait: (stream: stream.Stream) => Promise<unknown>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Returns a promise that resolves once the given stream finishes. If the stream emits an error then
3
+ * then promise will reject
4
+ */
5
+ export const wait = (stream) => {
6
+ return new Promise((resolve, reject) => {
7
+ stream.on('error', reject);
8
+ stream.on('end', resolve);
9
+ stream.on('finish', resolve);
10
+ });
11
+ };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * A set of standard helpers for working with iterators.
3
+ *
4
+ * The majority of the utils included here can be removed if and when the tc39 iterator-helpers proposal lands:
5
+ * https://github.com/tc39/proposal-iterator-helpers
6
+ */
7
+ import { StreamLike } from './utils.js';
8
+ export type ExtractStreamElementType<T extends StreamLike<any>> = T extends Iterable<infer I> ? I : T extends AsyncIterable<infer I> ? I : never;
9
+ /**
10
+ * Takes n number of streams (or any AsyncIterators) and returns an AsyncGenerator that
11
+ * yields the concatenated output of all input streams
12
+ */
13
+ export declare function concat<S extends StreamLike<any>>(...sources: S[]): AsyncGenerator<ExtractStreamElementType<S>>;
14
+ /**
15
+ * Implements `Array.prototype.map` for iterables
16
+ */
17
+ export declare function map<I, O>(iterable: StreamLike<I>, transform: (element: I) => O | Promise<O>): AsyncGenerator<Awaited<O>, void, unknown>;
18
+ /**
19
+ * Implements `Array.prototype.filter` for iterables
20
+ */
21
+ export declare function filter<I>(iterable: StreamLike<I>, comparator: (element: I) => Promise<boolean> | boolean): AsyncGenerator<Awaited<I>, void, unknown>;
22
+ type ReducedValue<T> = {
23
+ __reduced: true;
24
+ value: T;
25
+ };
26
+ export declare const reduced: <T>(value: T) => {
27
+ __reduced: boolean;
28
+ value: T;
29
+ };
30
+ /**
31
+ * Implements `Array.prototype.reduce` for iterables.
32
+ *
33
+ * The reducer can return `reduced(accumulator)` to end execution early
34
+ */
35
+ export declare const reduce: <I, A>(iterable: StreamLike<I>, reducer: (accumulator: A, element: I) => A | ReducedValue<A> | Promise<A | ReducedValue<A>>, init: A) => Promise<A>;
36
+ /**
37
+ * Drain a given iterables contents into an array. This is kind of like `Array.from` except it works
38
+ * with AsyncIterables
39
+ */
40
+ export declare const drain: <T>(iterator: StreamLike<T>) => Promise<T[]>;
41
+ export {};
@@ -0,0 +1,70 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /**
3
+ * A set of standard helpers for working with iterators.
4
+ *
5
+ * The majority of the utils included here can be removed if and when the tc39 iterator-helpers proposal lands:
6
+ * https://github.com/tc39/proposal-iterator-helpers
7
+ */
8
+ /**
9
+ * Takes n number of streams (or any AsyncIterators) and returns an AsyncGenerator that
10
+ * yields the concatenated output of all input streams
11
+ */
12
+ export async function* concat(...sources) {
13
+ for (const source of sources) {
14
+ yield* source;
15
+ }
16
+ }
17
+ /**
18
+ * Implements `Array.prototype.map` for iterables
19
+ */
20
+ export async function* map(iterable, transform) {
21
+ for await (const element of iterable) {
22
+ yield await transform(element);
23
+ }
24
+ }
25
+ /**
26
+ * Implements `Array.prototype.filter` for iterables
27
+ */
28
+ export async function* filter(iterable, comparator) {
29
+ for await (const element of iterable) {
30
+ if (await comparator(element)) {
31
+ yield element;
32
+ }
33
+ }
34
+ }
35
+ export const reduced = (value) => {
36
+ return {
37
+ __reduced: true,
38
+ value
39
+ };
40
+ };
41
+ const isReducedValue = (value) => {
42
+ return '__reduced' in value && value.__reduced;
43
+ };
44
+ /**
45
+ * Implements `Array.prototype.reduce` for iterables.
46
+ *
47
+ * The reducer can return `reduced(accumulator)` to end execution early
48
+ */
49
+ export const reduce = async (iterable, reducer, init) => {
50
+ let accumulator = init;
51
+ for await (const element of iterable) {
52
+ const result = await reducer(accumulator, element);
53
+ if (isReducedValue(result)) {
54
+ return result.value;
55
+ }
56
+ accumulator = result;
57
+ }
58
+ return accumulator;
59
+ };
60
+ /**
61
+ * Drain a given iterables contents into an array. This is kind of like `Array.from` except it works
62
+ * with AsyncIterables
63
+ */
64
+ export const drain = async (iterator) => {
65
+ const data = [];
66
+ for await (const chunk of iterator) {
67
+ data.push(chunk);
68
+ }
69
+ return data;
70
+ };
@@ -0,0 +1,36 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type * as webstreams from 'node:stream/web';
3
+ export type StreamLike<T> = AsyncIterable<T> | Iterable<T>;
4
+ /**
5
+ * Construct an AsyncIterator from a given ReadableStream.
6
+ *
7
+ * This is only really intended to be used from browser runtimes or within code intended to
8
+ * be used cross-platform. This is because Node ReadableStreams already implement AsyncIterators
9
+ */
10
+ export declare function iterableFromReadable<T = any>(readable: ReadableStream<T> | webstreams.ReadableStream<T>): AsyncGenerator<Awaited<T>, void, unknown>;
11
+ /**
12
+ * Construct a ReadableStream from a given Iterable or AsyncIterable.
13
+ *
14
+ * If the given iterable is already a readable then this is a noop
15
+ */
16
+ export declare const readableFrom: <T = any>(iterable: StreamLike<T>, strategy?: QueuingStrategy<T | undefined> | undefined) => webstreams.ReadableStream<T>;
17
+ export type JSONSchema = {
18
+ [key: string]: any;
19
+ definitions?: Record<string, any>;
20
+ };
21
+ export type IValidationRight = {
22
+ valid: true;
23
+ };
24
+ export type ValidationLeft<T = string[]> = {
25
+ errors: T;
26
+ valid: false;
27
+ };
28
+ export type ValidationResponse<T, E = string[]> = IValidationRight | ValidationLeft<E>;
29
+ export type MicroValidator<T = any, E = string[]> = {
30
+ toJSONSchema?: () => JSONSchema;
31
+ validate: (data: T) => ValidationResponse<T, E>;
32
+ };
33
+ /**
34
+ * Yield a generator that validates data flowing through it
35
+ */
36
+ export declare function validateDataStream<T>(iterable: StreamLike<T>, validator: MicroValidator<T>): AsyncGenerator<Awaited<T>, void, unknown>;
@@ -0,0 +1,66 @@
1
+ import * as micro_errors from '../../errors/index.js';
2
+ import * as cross_stream from './cross-stream.js';
3
+ /**
4
+ * Construct an AsyncIterator from a given ReadableStream.
5
+ *
6
+ * This is only really intended to be used from browser runtimes or within code intended to
7
+ * be used cross-platform. This is because Node ReadableStreams already implement AsyncIterators
8
+ */
9
+ export async function* iterableFromReadable(readable) {
10
+ const reader = readable.getReader();
11
+ try {
12
+ while (true) {
13
+ const res = await reader.read();
14
+ if (res.done) {
15
+ return;
16
+ }
17
+ yield res.value;
18
+ }
19
+ }
20
+ finally {
21
+ reader.releaseLock();
22
+ }
23
+ }
24
+ /**
25
+ * Construct a ReadableStream from a given Iterable or AsyncIterable.
26
+ *
27
+ * If the given iterable is already a readable then this is a noop
28
+ */
29
+ export const readableFrom = (iterable, strategy) => {
30
+ if (iterable instanceof cross_stream.Readable) {
31
+ return iterable;
32
+ }
33
+ let resume;
34
+ return new cross_stream.Readable({
35
+ async pull() {
36
+ resume?.();
37
+ },
38
+ start(controller) {
39
+ void (async function () {
40
+ for await (const chunk of iterable) {
41
+ controller.enqueue(chunk);
42
+ if (controller.desiredSize != null && controller.desiredSize <= 0) {
43
+ await new Promise((resolve) => {
44
+ resume = resolve;
45
+ });
46
+ }
47
+ }
48
+ controller.close();
49
+ })().catch((error) => {
50
+ controller.error(error);
51
+ });
52
+ }
53
+ }, strategy);
54
+ };
55
+ /**
56
+ * Yield a generator that validates data flowing through it
57
+ */
58
+ export async function* validateDataStream(iterable, validator) {
59
+ for await (const chunk of iterable) {
60
+ const res = validator.validate(chunk);
61
+ if (!res.valid) {
62
+ throw new micro_errors.ValidationError(res.errors);
63
+ }
64
+ yield chunk;
65
+ }
66
+ }
@@ -0,0 +1,3 @@
1
+ export * as bson from './bson/index.js';
2
+ export * as compat from './core/cross-stream.js';
3
+ export * from './core/index.js';
@@ -0,0 +1,3 @@
1
+ export * as bson from './bson/index.js';
2
+ export * as compat from './core/cross-stream.js';
3
+ export * from './core/index.js';
@@ -0,0 +1,4 @@
1
+ export * as bson from './bson/index.js';
2
+ export * as compat from './core/cross-stream.js';
3
+ export * from './core/transformers.js';
4
+ export * from './core/utils.js';
@@ -0,0 +1,4 @@
1
+ export * as bson from './bson/index.js';
2
+ export * as compat from './core/cross-stream.js';
3
+ export * from './core/transformers.js';
4
+ export * from './core/utils.js';
@@ -0,0 +1,2 @@
1
+ export default BinaryReader;
2
+ declare function BinaryReader(buffer: any, isBigEndian: any): void;
@@ -0,0 +1,36 @@
1
+ /* eslint-disable no-bitwise */
2
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
3
+ // @ts-nocheck
4
+ export default BinaryReader;
5
+ function BinaryReader(buffer, isBigEndian) {
6
+ this.buffer = buffer;
7
+ this.position = 0;
8
+ this.isBigEndian = isBigEndian || false;
9
+ }
10
+ function _read(readLE, readBE, size) {
11
+ return function () {
12
+ const value = this.isBigEndian ? readBE.call(this.buffer, this.position) : readLE.call(this.buffer, this.position);
13
+ this.position += size;
14
+ return value;
15
+ };
16
+ }
17
+ BinaryReader.prototype.readUInt8 = _read(Buffer.prototype.readUInt8, Buffer.prototype.readUInt8, 1);
18
+ BinaryReader.prototype.readUInt16 = _read(Buffer.prototype.readUInt16LE, Buffer.prototype.readUInt16BE, 2);
19
+ BinaryReader.prototype.readUInt32 = _read(Buffer.prototype.readUInt32LE, Buffer.prototype.readUInt32BE, 4);
20
+ BinaryReader.prototype.readInt8 = _read(Buffer.prototype.readInt8, Buffer.prototype.readInt8, 1);
21
+ BinaryReader.prototype.readInt16 = _read(Buffer.prototype.readInt16LE, Buffer.prototype.readInt16BE, 2);
22
+ BinaryReader.prototype.readInt32 = _read(Buffer.prototype.readInt32LE, Buffer.prototype.readInt32BE, 4);
23
+ BinaryReader.prototype.readFloat = _read(Buffer.prototype.readFloatLE, Buffer.prototype.readFloatBE, 4);
24
+ BinaryReader.prototype.readDouble = _read(Buffer.prototype.readDoubleLE, Buffer.prototype.readDoubleBE, 8);
25
+ BinaryReader.prototype.readVarInt = function () {
26
+ let nextByte;
27
+ let result = 0;
28
+ let bytesRead = 0;
29
+ do {
30
+ nextByte = this.buffer[this.position + bytesRead];
31
+ result += (nextByte & 0x7f) << (7 * bytesRead);
32
+ bytesRead++;
33
+ } while (nextByte >= 0x80);
34
+ this.position += bytesRead;
35
+ return result;
36
+ };
@@ -0,0 +1,2 @@
1
+ export default BinaryWriter;
2
+ declare function BinaryWriter(size: any, allowResize: any): void;
@@ -0,0 +1,58 @@
1
+ /* eslint-disable no-bitwise */
2
+ /* eslint-disable new-cap */
3
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
4
+ // @ts-nocheck
5
+ export default BinaryWriter;
6
+ function BinaryWriter(size, allowResize) {
7
+ this.buffer = new Buffer.alloc(size);
8
+ this.position = 0;
9
+ this.allowResize = allowResize;
10
+ }
11
+ function _write(write, size) {
12
+ return function (value, noAssert) {
13
+ this.ensureSize(size);
14
+ write.call(this.buffer, value, this.position, noAssert);
15
+ this.position += size;
16
+ };
17
+ }
18
+ BinaryWriter.prototype.writeUInt8 = _write(Buffer.prototype.writeUInt8, 1);
19
+ BinaryWriter.prototype.writeUInt16LE = _write(Buffer.prototype.writeUInt16LE, 2);
20
+ BinaryWriter.prototype.writeUInt16BE = _write(Buffer.prototype.writeUInt16BE, 2);
21
+ BinaryWriter.prototype.writeUInt32LE = _write(Buffer.prototype.writeUInt32LE, 4);
22
+ BinaryWriter.prototype.writeUInt32BE = _write(Buffer.prototype.writeUInt32BE, 4);
23
+ BinaryWriter.prototype.writeInt8 = _write(Buffer.prototype.writeInt8, 1);
24
+ BinaryWriter.prototype.writeInt16LE = _write(Buffer.prototype.writeInt16LE, 2);
25
+ BinaryWriter.prototype.writeInt16BE = _write(Buffer.prototype.writeInt16BE, 2);
26
+ BinaryWriter.prototype.writeInt32LE = _write(Buffer.prototype.writeInt32LE, 4);
27
+ BinaryWriter.prototype.writeInt32BE = _write(Buffer.prototype.writeInt32BE, 4);
28
+ BinaryWriter.prototype.writeFloatLE = _write(Buffer.prototype.writeFloatLE, 4);
29
+ BinaryWriter.prototype.writeFloatBE = _write(Buffer.prototype.writeFloatBE, 4);
30
+ BinaryWriter.prototype.writeDoubleLE = _write(Buffer.prototype.writeDoubleLE, 8);
31
+ BinaryWriter.prototype.writeDoubleBE = _write(Buffer.prototype.writeDoubleBE, 8);
32
+ BinaryWriter.prototype.writeBuffer = function (buffer) {
33
+ this.ensureSize(buffer.length);
34
+ buffer.copy(this.buffer, this.position, 0, buffer.length);
35
+ this.position += buffer.length;
36
+ };
37
+ BinaryWriter.prototype.writeVarInt = function (value) {
38
+ let length = 1;
39
+ while ((value & 4294967168) !== 0) {
40
+ this.writeUInt8((value & 0x7f) | 0x80);
41
+ value >>>= 7;
42
+ length++;
43
+ }
44
+ this.writeUInt8(value & 0x7f);
45
+ return length;
46
+ };
47
+ BinaryWriter.prototype.ensureSize = function (size) {
48
+ if (this.buffer.length < this.position + size) {
49
+ if (this.allowResize) {
50
+ const tempBuffer = new Buffer.alloc(this.position + size);
51
+ this.buffer.copy(tempBuffer, 0, 0, this.buffer.length);
52
+ this.buffer = tempBuffer;
53
+ }
54
+ else {
55
+ throw new RangeError('index out of range');
56
+ }
57
+ }
58
+ };
@@ -0,0 +1,18 @@
1
+ export default Geometry;
2
+ declare function Geometry(): void;
3
+ declare namespace Geometry {
4
+ var parse: (value: any, options?: any) => any;
5
+ var _parseWkt: (value: any) => any;
6
+ var _parseWkb: (value: any, parentOptions: any) => any;
7
+ var parseTwkb: (value: any) => any;
8
+ var parseGeoJSON: (value: any) => any;
9
+ var _parseGeoJSON: (value: any, isSubGeometry: any) => any;
10
+ var getTwkbPrecision: (xyPrecision: any, zPrecision: any, mPrecision: any) => {
11
+ m: any;
12
+ mFactor: number;
13
+ xy: any;
14
+ xyFactor: number;
15
+ z: any;
16
+ zFactor: number;
17
+ };
18
+ }