@syncmatters/script-api 1.0.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 (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -0
  3. package/api.d.ts +24 -0
  4. package/index.d.ts +3 -0
  5. package/index.js +1 -0
  6. package/lib/coded-error.d.ts +7 -0
  7. package/lib/connection.d.ts +597 -0
  8. package/lib/context.d.ts +58 -0
  9. package/lib/environment.d.ts +4 -0
  10. package/lib/logger.d.ts +20 -0
  11. package/lib/script-error.d.ts +38 -0
  12. package/lib/sync-group.d.ts +85 -0
  13. package/lib/sync.d.ts +392 -0
  14. package/lib/utilities/csv-reader/csv-reader-csv-parse.d.ts +16 -0
  15. package/lib/utilities/csv-reader/csv-reader-fast-csv.d.ts +15 -0
  16. package/lib/utilities/csv-reader/csv-reader.d.ts +2 -0
  17. package/lib/utilities/csv-reader/index.d.ts +2 -0
  18. package/lib/utilities/csv-reader/types.d.ts +48 -0
  19. package/lib/utilities/csv-writer/csv-writer.d.ts +21 -0
  20. package/lib/utilities/date-utils/date-utils.d.ts +37 -0
  21. package/lib/utilities/file-provider/file-provider-buffer.d.ts +11 -0
  22. package/lib/utilities/file-provider/file-provider-disk.d.ts +12 -0
  23. package/lib/utilities/file-provider/file-provider-string.d.ts +11 -0
  24. package/lib/utilities/file-provider/file-provider.d.ts +21 -0
  25. package/lib/utilities/file-utils/file-utils.d.ts +8 -0
  26. package/lib/utilities/html-utils/html-utils.d.ts +1 -0
  27. package/lib/utilities/http-client/fetch-http-client.d.ts +7 -0
  28. package/lib/utilities/http-client/fetch-http-error.d.ts +14 -0
  29. package/lib/utilities/http-client/types.d.ts +62 -0
  30. package/lib/utilities/json-utils/index.d.ts +6 -0
  31. package/lib/utilities/json-utils/json-changed-checker.d.ts +15 -0
  32. package/lib/utilities/json-utils/json-hash.d.ts +4 -0
  33. package/lib/utilities/json-utils/json-values-reader.d.ts +13 -0
  34. package/lib/utilities/json-utils/json-values-types.d.ts +41 -0
  35. package/lib/utilities/json-utils/json-values-writer.d.ts +28 -0
  36. package/lib/utilities/json-utils/lossless-numbers.d.ts +6 -0
  37. package/lib/utilities/json-utils/paths.d.ts +8 -0
  38. package/lib/utilities/kv-store/better-sqlite3/kv-collection-better-sqlite3.d.ts +18 -0
  39. package/lib/utilities/kv-store/better-sqlite3/kv-iterator-better-sqlite3.d.ts +26 -0
  40. package/lib/utilities/kv-store/better-sqlite3/kv-store-better-sqlite3.d.ts +11 -0
  41. package/lib/utilities/kv-store/index.d.ts +4 -0
  42. package/lib/utilities/kv-store/kv-store-benchmark-helpers.d.ts +14 -0
  43. package/lib/utilities/kv-store/shadow/kv-store-shadow.d.ts +29 -0
  44. package/lib/utilities/kv-store/sqlite3/database-sqlite3.d.ts +16 -0
  45. package/lib/utilities/kv-store/sqlite3/kv-collection-sqlite3.d.ts +18 -0
  46. package/lib/utilities/kv-store/sqlite3/kv-iterator-sqlite3.d.ts +21 -0
  47. package/lib/utilities/kv-store/sqlite3/kv-store-sqlite3.d.ts +11 -0
  48. package/lib/utilities/kv-store/sqlite3/statement-sqlite3.d.ts +13 -0
  49. package/lib/utilities/kv-store/types.d.ts +20 -0
  50. package/lib/utilities/name-parser/name-parser.d.ts +6 -0
  51. package/lib/utilities/rate-limiter/rate-limiter-concurrent.d.ts +24 -0
  52. package/lib/utilities/rate-limiter/rate-limiter-rolling.d.ts +18 -0
  53. package/lib/utilities/rate-limiter/rate-limiter.d.ts +15 -0
  54. package/lib/utilities/type-utils/type-utils.d.ts +11 -0
  55. package/lib/utilities/upsert-flags/upsert-flags.d.ts +10 -0
  56. package/lib/utilities/utilities.d.ts +105 -0
  57. package/lib/utilities/www-utils/www-utils.d.ts +14 -0
  58. package/lib/utilities/xlsx-reader/xlsx-reader.d.ts +32 -0
  59. package/lib/utilities/xlsx-writer/xlsx-writer.d.ts +23 -0
  60. package/lib/utilities/xml-utils/xml-utils.d.ts +1 -0
  61. package/lib/utilities/zip-utils/zip-utils.d.ts +29 -0
  62. package/package.json +23 -0
  63. package/sdk-test/sdk-test.d.ts +451 -0
  64. package/sdk-test.d.ts +3 -0
@@ -0,0 +1,11 @@
1
+ import { FileProvider } from "./file-provider.js";
2
+ export declare class FileProviderBuffer implements FileProvider {
3
+ constructor(source: Buffer);
4
+ length(): Promise<number>;
5
+ stream(encoding?: "utf8" | "utf16le" | "ucs2" | "latin1"): Promise<NodeJS.ReadableStream>;
6
+ formDataValue(encoding?: "utf8" | "utf16le" | "ucs2" | "latin1"): Promise<unknown>;
7
+ blob(fileName?: string): Promise<Blob>;
8
+ save(path?: string): Promise<string>;
9
+ close(): Promise<void>;
10
+ toJSON(): string;
11
+ }
@@ -0,0 +1,12 @@
1
+ import { FileProvider } from "./file-provider.js";
2
+ export declare class FileProviderDisk implements FileProvider {
3
+ constructor(path: string, deleteOnClose?: boolean);
4
+ length(): Promise<number>;
5
+ stream(encoding?: "utf8" | "utf16le" | "ucs2" | "latin1"): Promise<NodeJS.ReadableStream>;
6
+ private _initStreamSync;
7
+ formDataValue(encoding?: "utf8" | "utf16le" | "ucs2" | "latin1"): Promise<unknown>;
8
+ blob(fileName?: string): Promise<Blob>;
9
+ save(path?: string): Promise<string>;
10
+ close(): Promise<void>;
11
+ toJSON(): string;
12
+ }
@@ -0,0 +1,11 @@
1
+ import { FileProvider } from "./file-provider.js";
2
+ export declare class FileProviderString implements FileProvider {
3
+ constructor(source: string);
4
+ length(): Promise<number>;
5
+ stream(encoding?: "utf8" | "utf16le" | "ucs2" | "latin1"): Promise<NodeJS.ReadableStream>;
6
+ formDataValue(encoding?: "utf8" | "utf16le" | "ucs2" | "latin1"): Promise<unknown>;
7
+ blob(fileName?: string): Promise<Blob>;
8
+ save(path?: string): Promise<string>;
9
+ close(): Promise<void>;
10
+ toJSON(): string;
11
+ }
@@ -0,0 +1,21 @@
1
+ export interface FileProvider {
2
+ length(): Promise<number>;
3
+ stream(encoding?: "utf8" | "utf16le" | "ucs2" | "latin1"): Promise<NodeJS.ReadableStream>;
4
+ close(): Promise<void>;
5
+ save(path?: string): Promise<string>;
6
+ formDataValue(encoding?: "utf8" | "utf16le" | "ucs2" | "latin1"): Promise<unknown>;
7
+ blob(fileName?: string): Promise<Blob>;
8
+ toJSON(): string;
9
+ }
10
+ export interface FileProviderOptions {
11
+ file?: {
12
+ path: string;
13
+ deleteOnClose?: boolean;
14
+ };
15
+ string?: string;
16
+ buffer?: Buffer;
17
+ }
18
+ export declare function fileProvider(options: FileProviderOptions): FileProvider;
19
+ export declare namespace fileProvider {
20
+ var isFileProvider: (value: unknown) => value is FileProvider;
21
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Creates a temporary directory; caller should delete the directory once complete.
3
+ */
4
+ export declare function tempDir(): Promise<string>;
5
+ /**
6
+ * Creates a unique temporary file name; caller should delete the file once complete.
7
+ */
8
+ export declare function tempFile(): Promise<string>;
@@ -0,0 +1 @@
1
+ export declare function htmlToText(html: string): string;
@@ -0,0 +1,7 @@
1
+ import { HttpClientOptions, HttpRequest, HttpClient } from "./types.js";
2
+ /** Implementation of the HttpClient interface that uses the fetch API */
3
+ export declare class FetchHttpClient implements HttpClient {
4
+ #private;
5
+ constructor(options?: HttpClientOptions);
6
+ execute(obj: HttpRequest): Promise<any>;
7
+ }
@@ -0,0 +1,14 @@
1
+ import { type HttpError as HttpErrorType } from "./types.js";
2
+ export declare class HttpError extends Error implements HttpErrorType {
3
+ code: string;
4
+ statusCode?: number;
5
+ url?: string;
6
+ cause?: Error;
7
+ responseHeaders?: {
8
+ [key: string]: string;
9
+ };
10
+ responseBodyString?: string;
11
+ responseBodyBuffer?: Buffer;
12
+ responseBodyJson?: unknown;
13
+ constructor(err: Error | string, statusCode: number | undefined);
14
+ }
@@ -0,0 +1,62 @@
1
+ import type { Buffer } from "node:buffer";
2
+ import { RateLimiter } from "../rate-limiter/rate-limiter.js";
3
+ export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
4
+ /**
5
+ * HttpError thrown by the HttpClient on non-2xx responses.
6
+ */
7
+ export interface HttpError extends Error {
8
+ /** the error name */
9
+ name: string;
10
+ /** the shaped error code, if available (e.g. HTTP errors become HTTP500, etc.) */
11
+ code: string;
12
+ /** the HTTP status number, if available */
13
+ statusCode?: number;
14
+ /** the original URL that the request was made to */
15
+ url?: string;
16
+ /** the original error that threw */
17
+ cause?: Error;
18
+ /** lowercase response headers map */
19
+ responseHeaders?: {
20
+ [key: string]: string;
21
+ };
22
+ /** the response body as a string, if available */
23
+ responseBodyString?: string;
24
+ /** the response body as a buffer, if available */
25
+ responseBodyBuffer?: Buffer;
26
+ /** the response body as a JSON object, if available */
27
+ responseBodyJson?: unknown;
28
+ }
29
+ /** HttpRequest defines the POST/GET/... request to be processed by an HttpClient. */
30
+ export interface HttpRequest {
31
+ method: HttpMethod;
32
+ url: string;
33
+ headers?: any;
34
+ body?: any;
35
+ limiterCost?: number;
36
+ fullResponse?: boolean;
37
+ fileResponse?: boolean;
38
+ }
39
+ /** HttpCanRetry is an optional interface allowing a connector to assess whether a retry is allowed */
40
+ export interface HttpCanRetry {
41
+ (err: HttpError, method: HttpMethod, url: string, httpCode: number, responseHeaders: {
42
+ [key: string]: string;
43
+ } | undefined): boolean | number;
44
+ }
45
+ /** HttpClientOptions allow customization of the HttpClient defaults. */
46
+ export interface HttpClientOptions {
47
+ defaultHeaders?: {
48
+ [key: string]: string;
49
+ };
50
+ timeoutMs?: number;
51
+ limiter?: RateLimiter;
52
+ maxRetry?: number;
53
+ retryBackoffMs?: number;
54
+ ca?: Buffer;
55
+ errMessageFormat?: "default" | "concise";
56
+ canRetry?: HttpCanRetry;
57
+ onError?: (err: HttpError, method: HttpMethod, url: string, httpCode: number, reqJson?: unknown) => void;
58
+ onSuccess?: (method: string, url: string, httpCode: number, reqJson?: unknown) => void;
59
+ }
60
+ export interface HttpClient {
61
+ execute: (request: HttpRequest) => Promise<any>;
62
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./lossless-numbers.js";
2
+ export * from "./json-values-types.js";
3
+ export * from "./json-values-reader.js";
4
+ export * from "./json-values-writer.js";
5
+ export * from "./json-changed-checker.js";
6
+ export * from "./paths.js";
@@ -0,0 +1,15 @@
1
+ import API from "../../../index.js";
2
+ export type JsonChangedCheckerFormat = "csv";
3
+ export interface JsonChangedCheckerOptions {
4
+ data: API.FileProvider;
5
+ format: JsonChangedCheckerFormat;
6
+ }
7
+ export declare function JsonChangedChecker(options: JsonChangedCheckerOptions): Promise<Checker>;
8
+ declare class Checker {
9
+ #private;
10
+ constructor(options: JsonChangedCheckerOptions);
11
+ _init(): Promise<void>;
12
+ hasChanged(id: string, json: unknown): Promise<boolean>;
13
+ data(): Promise<API.FileProvider | undefined>;
14
+ }
15
+ export {};
@@ -0,0 +1,4 @@
1
+ export declare function JsonHash(options: {
2
+ json: unknown;
3
+ csvMode: boolean;
4
+ }): string;
@@ -0,0 +1,13 @@
1
+ import { JsonValuePath } from "./json-values-types.js";
2
+ /** Efficiently read a set of property values from a JSON object */
3
+ export declare class JsonValuesReader {
4
+ #private;
5
+ constructor(options: {
6
+ paths: Array<JsonValuePath>;
7
+ dontThrowOnInvalidParent?: boolean;
8
+ });
9
+ /** Perform the read
10
+ * @param json - the JSON object to read from
11
+ */
12
+ execute(json: unknown): Array<unknown>;
13
+ }
@@ -0,0 +1,41 @@
1
+ /** JsonValuePath is the specification a path when traversing a JSON blob to get/set a value */
2
+ export type JsonValuePath = Array<JsonValuePathPart>;
3
+ /**
4
+ * JsonValuePathPart is the specification of one path part when traversing a JSON blob to get/set a value; a full
5
+ * path to a vlaue would consist of an array pf these path parts
6
+ */
7
+ export interface JsonValuePathPart {
8
+ /** name of the property on the parent object, or "[0-n]" if the property is an array */
9
+ path: string;
10
+ /** in the case of an array this specifies how to select the correct value from the array */
11
+ array?: {
12
+ /** select all values from the array */
13
+ selectAll?: boolean;
14
+ /** select value at a specific index */
15
+ index?: number;
16
+ /** sort the array before selecting the value at an index */
17
+ sort?: {
18
+ /** path to the property to be used when sorting the array */
19
+ path?: string[];
20
+ /** sort descending (default is ascending) */
21
+ desc?: boolean;
22
+ };
23
+ /** filters to use when identifying array element to get/set */
24
+ filters?: Array<{
25
+ /** reference to a property on the selected value to filter by */
26
+ path?: string[];
27
+ /** operator to use when checking if the value at the path meets filter */
28
+ operator?: "eq" | "geq" | "leq" | "empty" | "notempty" | "anyof";
29
+ /** string value to use in comparison of the operator is singular */
30
+ valueString?: string;
31
+ /** string values to use in comparison of the operator is multiple */
32
+ valuesString?: string[];
33
+ /** numeric value to use in comparison of the operator is singular */
34
+ valueNum?: number;
35
+ /** numeric values to use in comparison of the operator is multiple */
36
+ valuesNum?: number[];
37
+ /** boolean value to use in comparison of the operator is singular */
38
+ valueBool?: boolean;
39
+ }>;
40
+ };
41
+ }
@@ -0,0 +1,28 @@
1
+ import { JsonValuePath } from "./json-values-types.js";
2
+ export interface WriteBehaviour {
3
+ executeOn?: "add" | "update";
4
+ writeNulls?: boolean;
5
+ writeEmptyStrings?: boolean;
6
+ dontOverwrite?: boolean;
7
+ }
8
+ /**
9
+ * Efficiently write a set of values into a JSON object. Can handle nested objects, and at most a single array
10
+ * in the field path or at the leaf level.
11
+ *
12
+ * Note: array selectors / specifiers such as index: 0 and selectAll: true are not supported.
13
+ */
14
+ export declare class JsonValuesWriter {
15
+ #private;
16
+ constructor(options: {
17
+ fields: Array<{
18
+ path: JsonValuePath;
19
+ behaviour?: WriteBehaviour;
20
+ }>;
21
+ });
22
+ /** Perform the write
23
+ * @param output - the JSON object to write into
24
+ * @param newValues - the new values to be written to each field in the JSON output
25
+ * @param oldValues - the current values of each field to evaluate behaviors
26
+ */
27
+ execute(output: unknown, newValues: Array<unknown>, oldValues?: Array<unknown>, isUpdate?: boolean): void;
28
+ }
@@ -0,0 +1,6 @@
1
+ import { LosslessNumber } from "lossless-json";
2
+ export declare function stringToLosslessNumber(source?: string): LosslessNumber | null | undefined;
3
+ export declare function stringsToLosslessNumbers(source: unknown | undefined, paths: Array<Array<string>>): unknown;
4
+ export declare function stringsFromLosslessNumbers(source: unknown | undefined, paths: Array<string[]>): void;
5
+ export declare function parseWithLosslessNumbers(source: string): unknown;
6
+ export declare function stringifyWithLosslessNumbers(source: unknown): string | undefined;
@@ -0,0 +1,8 @@
1
+ import { JsonValuePath } from "./json-values-types.js";
2
+ import { ObjectField } from "../../connection.js";
3
+ /** Convert hierarchical connection object fields to period-separated field paths e.g. addresses.[0-n].street */
4
+ export declare function fieldsToFieldPaths(fields?: ObjectField[]): Map<string, ObjectField>;
5
+ /** Convert a period-separated field path to the the format used to get/set fields using JSON utils */
6
+ export declare function fieldPathToJsonValuePath(fieldPath: string, arrayRule?: "throw" | "first" | "all"): JsonValuePath;
7
+ /** Convert a list of period-separated field paths to the the format used to get/set fields using JSON utils */
8
+ export declare function fieldsPathToJsonValuePaths(fieldPaths: string[], arrayRule?: "throw" | "first" | "all"): JsonValuePath[];
@@ -0,0 +1,18 @@
1
+ import { KvIteratorSqlite3 } from "./kv-iterator-better-sqlite3.js";
2
+ import { KvCollection, KvStore } from "../types.js";
3
+ export declare class KvCollectionBetterSqlite3<T> implements KvCollection<T> {
4
+ #private;
5
+ name: string;
6
+ constructor(collInfo: {
7
+ store: KvStore;
8
+ name: string;
9
+ tableName: string;
10
+ fname: string;
11
+ });
12
+ close(): Promise<void>;
13
+ put(key: string | number, v: T): Promise<T | undefined>;
14
+ get(key: string | number): Promise<T | undefined>;
15
+ del(key: string | number): Promise<void>;
16
+ iterator(): KvIteratorSqlite3<T>;
17
+ init(): Promise<void>;
18
+ }
@@ -0,0 +1,26 @@
1
+ import { KvIterator } from "../types.js";
2
+ import BetterSqlite3 from "better-sqlite3";
3
+ type NativeDb = InstanceType<typeof BetterSqlite3>;
4
+ /** Narrow surface the iterator needs from its owning collection. */
5
+ export interface KvIteratorBacking {
6
+ getDb(): NativeDb | undefined;
7
+ getTableName(): string;
8
+ getRegisteredIterator(): {
9
+ close(): Promise<void>;
10
+ } | undefined;
11
+ registerIterator(iter: {
12
+ close(): Promise<void>;
13
+ }): void;
14
+ unregisterIterator(): void;
15
+ }
16
+ export declare class KvIteratorSqlite3<T> implements KvIterator<T> {
17
+ #private;
18
+ constructor(backing: KvIteratorBacking, checkInit: () => Promise<void>);
19
+ rows<U>(): AsyncIterableIterator<U>;
20
+ rowsWithKeys<U>(): AsyncIterableIterator<{
21
+ key: string | number;
22
+ data: U;
23
+ }>;
24
+ close(): Promise<void>;
25
+ }
26
+ export {};
@@ -0,0 +1,11 @@
1
+ import { KvCollection, KvStore } from "../types.js";
2
+ export interface KvStoreBetterSqlite3Args {
3
+ path: string;
4
+ }
5
+ export declare class KvStoreBetterSqlite3 implements KvStore {
6
+ #private;
7
+ constructor(options?: KvStoreBetterSqlite3Args);
8
+ open<T>(name: string): Promise<KvCollection<T>>;
9
+ close(name: string): Promise<void>;
10
+ exit(): Promise<void>;
11
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./types.js";
2
+ export { KvStoreSqlite3 } from "./sqlite3/kv-store-sqlite3.js";
3
+ export { KvStoreShadow } from "./shadow/kv-store-shadow.js";
4
+ export { KvStoreBetterSqlite3 } from "./better-sqlite3/kv-store-better-sqlite3.js";
@@ -0,0 +1,14 @@
1
+ import type { KvStore } from "./types.js";
2
+ export interface KvStoreBenchmarkResult {
3
+ implementation: string;
4
+ rowCount: number;
5
+ putsMs: number;
6
+ getsMs: number;
7
+ iterateMs: number;
8
+ }
9
+ /**
10
+ * Runs comparable put / get / full-scan iteration timings for a KvStore implementation.
11
+ * Uses a fresh temp directory per run.
12
+ */
13
+ export declare function runKvStoreBenchmark(implementation: string, createStore: (storeDir: string) => KvStore, rowCount: number): Promise<KvStoreBenchmarkResult>;
14
+ export declare function logKvStoreBenchmarkResult(r: KvStoreBenchmarkResult): void;
@@ -0,0 +1,29 @@
1
+ import type { KvCollection, KvIterator, KvStore } from "../types.js";
2
+ /** Deep equality for JSON-like values stored in KV collections. */
3
+ export declare function kvShadowValuesEqual(a: unknown, b: unknown): boolean;
4
+ export declare class KvStoreShadow implements KvStore {
5
+ #private;
6
+ constructor(primary: KvStore, secondary: KvStore);
7
+ open<T>(name: string): Promise<KvCollection<T>>;
8
+ close(name: string): Promise<void>;
9
+ exit(): Promise<void>;
10
+ }
11
+ export declare class KvCollectionShadow<T> implements KvCollection<T> {
12
+ #private;
13
+ constructor(primary: KvCollection<T>, secondary: KvCollection<T>);
14
+ close(): Promise<void>;
15
+ put(key: string | number, data: T): Promise<T | undefined>;
16
+ get(key: string | number): Promise<T | undefined>;
17
+ del(key: string | number): Promise<void>;
18
+ iterator(): KvIterator<T>;
19
+ }
20
+ export declare class KvIteratorShadow<T> implements KvIterator<T> {
21
+ #private;
22
+ constructor(primary: KvIterator<T>, secondary: KvIterator<T>);
23
+ rowsWithKeys(): AsyncIterableIterator<{
24
+ key: string | number;
25
+ data: T;
26
+ }>;
27
+ rows(): AsyncIterableIterator<T>;
28
+ close(): Promise<void>;
29
+ }
@@ -0,0 +1,16 @@
1
+ export declare class DatabaseSqite3 {
2
+ static get OPEN_READONLY(): number;
3
+ static get OPEN_READWRITE(): number;
4
+ static get OPEN_CREATE(): number;
5
+ static open(filename: string, mode?: number): Promise<any>;
6
+ private db;
7
+ open(filename: string, mode?: number): Promise<any>;
8
+ close(fn: any): Promise<any>;
9
+ run(...args: any[]): Promise<any>;
10
+ get(...args: any[]): Promise<any>;
11
+ all(...args: any[]): Promise<any>;
12
+ each(...args: any[]): Promise<any>;
13
+ exec(sql: string): Promise<any>;
14
+ transaction(fn: any): Promise<any>;
15
+ prepare(...args: any[]): Promise<any>;
16
+ }
@@ -0,0 +1,18 @@
1
+ import { KvIteratorSqlite3 } from "./kv-iterator-sqlite3.js";
2
+ import { KvCollection } from "../types.js";
3
+ export declare class KvCollectionSqlite3<T> implements KvCollection<T> {
4
+ name: string;
5
+ private isClosed;
6
+ private isInit;
7
+ private stmtIns;
8
+ private stmtUpd;
9
+ private stmtSel;
10
+ private stmtDel;
11
+ constructor(collInfo: any);
12
+ close(): Promise<void>;
13
+ put<T>(key: string | number, v: T): Promise<T | undefined>;
14
+ get<T>(key: string | number): Promise<T>;
15
+ del(key: string | number): Promise<void>;
16
+ iterator(): KvIteratorSqlite3<T>;
17
+ init(): Promise<void>;
18
+ }
@@ -0,0 +1,21 @@
1
+ import { KvIterator } from "../types.js";
2
+ export declare class KvIteratorSqlite3<T> implements KvIterator<T> {
3
+ private idx;
4
+ private current;
5
+ private ids;
6
+ private stmt;
7
+ private isClosed;
8
+ private _checkInit;
9
+ constructor(collInfo: any, checkInit: () => Promise<void>);
10
+ rows<T>(): AsyncIterableIterator<T>;
11
+ rowsWithKeys<T>(): AsyncIterableIterator<{
12
+ key: string | number;
13
+ data: T;
14
+ }>;
15
+ close(): Promise<void>;
16
+ private _init;
17
+ private _goToFirst;
18
+ private _goToNext;
19
+ private _getCurrentObject;
20
+ private _gotoIdx;
21
+ }
@@ -0,0 +1,11 @@
1
+ import { KvStore } from "../types.js";
2
+ import { KvCollectionSqlite3 } from "./kv-collection-sqlite3.js";
3
+ export interface KvStoreSqlite3Args {
4
+ path: string;
5
+ }
6
+ export declare class KvStoreSqlite3 implements KvStore {
7
+ constructor(options?: KvStoreSqlite3Args);
8
+ open<T>(name: string): Promise<KvCollectionSqlite3<unknown>>;
9
+ close(name: string): Promise<void>;
10
+ exit(): Promise<void>;
11
+ }
@@ -0,0 +1,13 @@
1
+ export declare class StatementSqlite3 {
2
+ lastID: any;
3
+ changes: any;
4
+ private statement;
5
+ constructor(statement: any);
6
+ bind(...args: any[]): Promise<unknown>;
7
+ reset(): Promise<unknown>;
8
+ finalize(): Promise<void>;
9
+ run(...args: any[]): Promise<unknown>;
10
+ get(...args: any[]): Promise<unknown>;
11
+ all(...args: any[]): Promise<unknown>;
12
+ each(...args: any[]): Promise<unknown>;
13
+ }
@@ -0,0 +1,20 @@
1
+ export interface KvStore {
2
+ open<T>(name: string): Promise<KvCollection<T>>;
3
+ close(name: string): Promise<void>;
4
+ exit(): Promise<void>;
5
+ }
6
+ export interface KvCollection<T> {
7
+ close(): Promise<void>;
8
+ put(key: string | number, data: T): Promise<T | undefined>;
9
+ get(key: string | number): Promise<T | undefined>;
10
+ del(key: string | number): Promise<void>;
11
+ iterator(): KvIterator<T>;
12
+ }
13
+ export interface KvIterator<T> {
14
+ rows(): AsyncIterableIterator<T>;
15
+ rowsWithKeys(): AsyncIterableIterator<{
16
+ key: string | number;
17
+ data: T;
18
+ }>;
19
+ close(): Promise<void>;
20
+ }
@@ -0,0 +1,6 @@
1
+ export declare function nameParser(name: string): {
2
+ title: string;
3
+ first: string;
4
+ middle: string;
5
+ last: string;
6
+ };
@@ -0,0 +1,24 @@
1
+ import { RateLimiter } from "./rate-limiter.js";
2
+ interface ExecutorSpec {
3
+ executor: () => Promise<any>;
4
+ resolve: (value: any) => void;
5
+ reject: (reason: any) => void;
6
+ offset: number;
7
+ cost: number;
8
+ }
9
+ /**
10
+ * RateLimiterConcurrent is a concurrent executions rate limiter.
11
+ */
12
+ export declare class RateLimiterConcurrent implements RateLimiter {
13
+ #private;
14
+ constructor(maxConcurrent: number);
15
+ /** @deprecated */
16
+ take(cost?: number): Promise<void>;
17
+ execute<T>(options: {
18
+ cost?: number;
19
+ exec: () => Promise<T>;
20
+ }): Promise<T>;
21
+ _processPendingGenerators(): void;
22
+ _handleGenerator(spec: ExecutorSpec): Promise<void>;
23
+ }
24
+ export {};
@@ -0,0 +1,18 @@
1
+ import { RateLimiter } from "./rate-limiter.js";
2
+ /**
3
+ * RateLimiterRolling is a rolling time window rate limiter. As the time of writing the rate limiters avaiable on npm
4
+ * did not did limit accurately, menaning that the remote APIs (like HubSpots) would periodically respond with HTTP 429
5
+ * errors.
6
+ */
7
+ export declare class RateLimiterRolling implements RateLimiter {
8
+ #private;
9
+ constructor(count: number, ms: number);
10
+ take(cost?: number): Promise<void>;
11
+ execute<T>(options: {
12
+ cost?: number;
13
+ exec: () => Promise<T>;
14
+ }): Promise<T>;
15
+ availableCount(): number;
16
+ private _startTimeout;
17
+ private _drainQueue;
18
+ }
@@ -0,0 +1,15 @@
1
+ /** RateLimiter allows resources (e.g. API calls) to be throttled to a specific rate. */
2
+ export interface RateLimiter {
3
+ /** @deprecated use execute() */
4
+ take(cost?: number): Promise<void>;
5
+ execute<T>(options: {
6
+ cost?: number;
7
+ exec: () => Promise<T>;
8
+ }): Promise<T>;
9
+ }
10
+ /** RateLimiterOptions is passed to the rate limiter constructor when creating a new limiter. */
11
+ export interface RateLimiterOptions {
12
+ type: "rolling" | "concurrent";
13
+ count?: number;
14
+ ms?: number;
15
+ }
@@ -0,0 +1,11 @@
1
+ export declare function isNullOrUndefined(value: any): boolean;
2
+ export declare function isNull(value: any): boolean;
3
+ export declare function isUndefined(value: any): boolean;
4
+ export declare function isString(value: any): value is string | String;
5
+ export declare function isNumber(value: any): value is number | Number;
6
+ export declare function isInteger(value: any): boolean;
7
+ export declare function isBoolean(value: any): value is boolean | Boolean;
8
+ export declare function isDate(value: any): value is Date;
9
+ export declare function isArray(value: any): value is any[];
10
+ export declare function isBuffer(value: any): value is Buffer<ArrayBufferLike>;
11
+ export declare function isFunction(value: any): boolean;
@@ -0,0 +1,10 @@
1
+ export interface UpsertFlags {
2
+ /**
3
+ * For upsert operations the caller will set a value if the caller knows whether the row already exists.
4
+ */
5
+ operation?: "add" | "update";
6
+ }
7
+ /** Stamp the upsert flags onto the row */
8
+ export declare function set(flags: UpsertFlags, row?: unknown): void;
9
+ /** Collect the upsert flags from the row */
10
+ export declare function get(row: unknown): UpsertFlags | undefined;