@tursodatabase/sync-common 0.2.0-pre.8 → 0.2.0-pre.9
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/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +1 -4
- package/dist/types.d.ts +116 -32
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { run, memoryIO, SyncEngineGuards } from "./run.js";
|
|
2
|
-
import {
|
|
2
|
+
import { DatabaseOpts, ProtocolIo, RunOpts, DatabaseRowMutation, DatabaseRowStatement, DatabaseRowTransformResult, DatabaseStats, DatabaseChangeType } from "./types.js";
|
|
3
3
|
export { run, memoryIO, SyncEngineGuards };
|
|
4
|
-
export type {
|
|
4
|
+
export type { DatabaseStats, DatabaseOpts, DatabaseChangeType, DatabaseRowMutation, DatabaseRowStatement, DatabaseRowTransformResult, ProtocolIo, RunOpts, };
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC1D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAExK,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAA;AAC1C,YAAY,EACR,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,0BAA0B,EAE1B,UAAU,EACV,OAAO,GACV,CAAA"}
|
package/dist/run.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../run.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,UAAU,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../run.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,UAAU,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAwF3D,wBAAgB,QAAQ,IAAI,UAAU,CAUrC;AAGD,wBAAsB,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAuBlG;AAED,qBAAa,gBAAgB;IACzB,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,EAAE,SAAS,CAAC;IACpB,cAAc,EAAE,SAAS,CAAC;;IAOpB,IAAI,CAAC,CAAC,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IAQzC,IAAI,CAAC,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC;IAY3B,KAAK,CAAC,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC;IAc5B,UAAU,CAAC,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC;CAc1C"}
|
package/dist/run.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { AsyncLock } from "@tursodatabase/database-common";
|
|
3
|
-
const GENERATOR_RESUME_IO = 0;
|
|
4
|
-
const GENERATOR_RESUME_DONE = 1;
|
|
5
3
|
function trackPromise(p) {
|
|
6
4
|
let status = { promise: null, finished: false };
|
|
7
5
|
status.promise = p.finally(() => status.finished = true);
|
|
@@ -15,7 +13,7 @@ async function process(opts, io, request) {
|
|
|
15
13
|
const completion = request.completion();
|
|
16
14
|
if (requestType.type == 'Http') {
|
|
17
15
|
try {
|
|
18
|
-
let headers = opts.headers;
|
|
16
|
+
let headers = typeof opts.headers === "function" ? opts.headers() : opts.headers;
|
|
19
17
|
if (requestType.headers != null && requestType.headers.length > 0) {
|
|
20
18
|
headers = { ...opts.headers };
|
|
21
19
|
for (let header of requestType.headers) {
|
|
@@ -122,7 +120,6 @@ export async function run(opts, io, engine, generator) {
|
|
|
122
120
|
await Promise.all([engine.ioLoopAsync(), tasksRace]);
|
|
123
121
|
tasks = tasks.filter(t => !t.finished);
|
|
124
122
|
}
|
|
125
|
-
return generator.take();
|
|
126
123
|
}
|
|
127
124
|
export class SyncEngineGuards {
|
|
128
125
|
waitLock;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,66 +1,150 @@
|
|
|
1
1
|
export declare const enum DatabaseChangeType {
|
|
2
|
-
Insert =
|
|
3
|
-
Update =
|
|
4
|
-
Delete =
|
|
2
|
+
Insert = "insert",
|
|
3
|
+
Update = "update",
|
|
4
|
+
Delete = "delete"
|
|
5
5
|
}
|
|
6
|
+
export interface DatabaseRowStatement {
|
|
7
|
+
/**
|
|
8
|
+
* SQL statements with positional placeholders (?)
|
|
9
|
+
*/
|
|
10
|
+
sql: string;
|
|
11
|
+
/**
|
|
12
|
+
* values to substitute placeholders
|
|
13
|
+
*/
|
|
14
|
+
values: Array<any>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* transformation result:
|
|
18
|
+
* - skip: ignore the mutation completely and do not apply it
|
|
19
|
+
* - rewrite: replace mutation with the provided statement
|
|
20
|
+
* - null: do not change mutation and keep it as is
|
|
21
|
+
*/
|
|
22
|
+
export type DatabaseRowTransformResult = {
|
|
23
|
+
operation: 'skip';
|
|
24
|
+
} | {
|
|
25
|
+
operation: 'rewrite';
|
|
26
|
+
stmt: DatabaseRowStatement;
|
|
27
|
+
} | null;
|
|
6
28
|
export interface DatabaseRowMutation {
|
|
29
|
+
/**
|
|
30
|
+
* unix seconds timestamp of the change
|
|
31
|
+
*/
|
|
7
32
|
changeTime: number;
|
|
33
|
+
/**
|
|
34
|
+
* table name of the change
|
|
35
|
+
*/
|
|
8
36
|
tableName: string;
|
|
37
|
+
/**
|
|
38
|
+
* rowid of the change
|
|
39
|
+
*/
|
|
9
40
|
id: number;
|
|
41
|
+
/**
|
|
42
|
+
* type of the change (insert/delete/update)
|
|
43
|
+
*/
|
|
10
44
|
changeType: DatabaseChangeType;
|
|
45
|
+
/**
|
|
46
|
+
* columns of the row before the change
|
|
47
|
+
*/
|
|
11
48
|
before?: Record<string, any>;
|
|
49
|
+
/**
|
|
50
|
+
* columns of the row after the change
|
|
51
|
+
*/
|
|
12
52
|
after?: Record<string, any>;
|
|
53
|
+
/**
|
|
54
|
+
* only updated columns of the row after the change
|
|
55
|
+
*/
|
|
13
56
|
updates?: Record<string, any>;
|
|
14
57
|
}
|
|
15
|
-
export type DatabaseRowTransformResult = {
|
|
16
|
-
operation: 'skip';
|
|
17
|
-
} | {
|
|
18
|
-
operation: 'rewrite';
|
|
19
|
-
stmt: DatabaseRowStatement;
|
|
20
|
-
} | null;
|
|
21
58
|
export type Transform = (arg: DatabaseRowMutation) => DatabaseRowTransformResult;
|
|
22
|
-
export interface
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
transform?: Transform;
|
|
29
|
-
}
|
|
30
|
-
export interface ProtocolIo {
|
|
31
|
-
read(path: string): Promise<Buffer | Uint8Array | null>;
|
|
32
|
-
write(path: string, content: Buffer | Uint8Array): Promise<void>;
|
|
33
|
-
}
|
|
34
|
-
export interface SyncOpts {
|
|
59
|
+
export interface DatabaseOpts {
|
|
60
|
+
/**
|
|
61
|
+
* local path where to store all synced database files (e.g. local.db)
|
|
62
|
+
* note, that synced database will write several files with that prefix
|
|
63
|
+
* (e.g. local.db-info, local.db-wal, etc)
|
|
64
|
+
* */
|
|
35
65
|
path: string;
|
|
66
|
+
/**
|
|
67
|
+
* optional url of the remote database (e.g. libsql://db-org.turso.io)
|
|
68
|
+
* (if omitted - local-only database will be created)
|
|
69
|
+
*/
|
|
70
|
+
url?: string;
|
|
71
|
+
/**
|
|
72
|
+
* auth token for the remote database
|
|
73
|
+
* (can be either static string or function which will provide short-lived credentials for every new request)
|
|
74
|
+
*/
|
|
75
|
+
authToken?: string | (() => string);
|
|
76
|
+
/**
|
|
77
|
+
* arbitrary client name which can be used to distinguish clients internally
|
|
78
|
+
* the library will gurantee uniquiness of the clientId by appending unique suffix to the clientName
|
|
79
|
+
*/
|
|
36
80
|
clientName?: string;
|
|
37
|
-
|
|
38
|
-
|
|
81
|
+
/**
|
|
82
|
+
* optional key if cloud database were encrypted by default
|
|
83
|
+
*/
|
|
39
84
|
encryptionKey?: string;
|
|
40
|
-
|
|
85
|
+
/**
|
|
86
|
+
* optional callback which will be called for every mutation before sending it to the remote
|
|
87
|
+
* this callback can transform the update in order to support complex conflict resolution strategy
|
|
88
|
+
*/
|
|
41
89
|
transform?: Transform;
|
|
90
|
+
/**
|
|
91
|
+
* optional long-polling timeout for pull operation
|
|
92
|
+
* if not set - no timeout is applied
|
|
93
|
+
*/
|
|
42
94
|
longPollTimeoutMs?: number;
|
|
43
|
-
|
|
95
|
+
/**
|
|
96
|
+
* optional parameter to enable internal logging for the database
|
|
97
|
+
*/
|
|
98
|
+
tracing?: 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
44
99
|
}
|
|
45
|
-
export interface
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
export interface SyncEngineStats {
|
|
100
|
+
export interface DatabaseStats {
|
|
101
|
+
/**
|
|
102
|
+
* amount of local changes not sent to the remote
|
|
103
|
+
*/
|
|
50
104
|
operations: number;
|
|
105
|
+
/**
|
|
106
|
+
* size of the main WAL file in bytes
|
|
107
|
+
*/
|
|
51
108
|
mainWal: number;
|
|
109
|
+
/**
|
|
110
|
+
* size of the revert WAL file in bytes
|
|
111
|
+
*/
|
|
52
112
|
revertWal: number;
|
|
113
|
+
/**
|
|
114
|
+
* unix timestamp of last successful pull time
|
|
115
|
+
*/
|
|
53
116
|
lastPullUnixTime: number;
|
|
117
|
+
/**
|
|
118
|
+
* unix timestamp of last successful push time
|
|
119
|
+
*/
|
|
54
120
|
lastPushUnixTime: number | null;
|
|
121
|
+
/**
|
|
122
|
+
* opaque revision of the changes pulled locally from remote
|
|
123
|
+
* (can be used as e-tag, but string must not be interpreted in any way and must be used as opaque value)
|
|
124
|
+
*/
|
|
55
125
|
revision: string | null;
|
|
56
126
|
}
|
|
127
|
+
export interface RunOpts {
|
|
128
|
+
preemptionMs: number;
|
|
129
|
+
url: string;
|
|
130
|
+
headers: {
|
|
131
|
+
[K: string]: string;
|
|
132
|
+
} | (() => {
|
|
133
|
+
[K: string]: string;
|
|
134
|
+
});
|
|
135
|
+
transform?: Transform;
|
|
136
|
+
}
|
|
137
|
+
export interface ProtocolIo {
|
|
138
|
+
read(path: string): Promise<Buffer | Uint8Array | null>;
|
|
139
|
+
write(path: string, content: Buffer | Uint8Array): Promise<void>;
|
|
140
|
+
}
|
|
57
141
|
export type GeneratorResponse = {
|
|
58
142
|
type: 'IO';
|
|
59
143
|
} | {
|
|
60
144
|
type: 'Done';
|
|
61
145
|
} | ({
|
|
62
146
|
type: 'SyncEngineStats';
|
|
63
|
-
} &
|
|
147
|
+
} & DatabaseStats) | {
|
|
64
148
|
type: 'SyncEngineChanges';
|
|
65
149
|
changes: any;
|
|
66
150
|
};
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,CAAC,KAAK,MAAM,kBAAkB;IACxC,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,CAAC,KAAK,MAAM,kBAAkB;IACxC,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;CACpB;AAED,MAAM,WAAW,oBAAoB;IACjC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;CACrB;AAGD;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,oBAAoB,CAAA;CAAE,GAAG,IAAI,CAAC;AAE7H,MAAM,WAAW,mBAAmB;IAChC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;IACV;;OAEG;IACH,UAAU,EAAE,kBAAkB,CAAA;IAC9B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAChC;AAED,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,mBAAmB,KAAK,0BAA0B,CAAC;AACjF,MAAM,WAAW,YAAY;IACzB;;;;SAIK;IACL,IAAI,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AU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpE;AACD,MAAM,MAAM,iBAAiB,GAAG;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,CAAC;IAAE,IAAI,EAAE,iBAAiB,CAAA;CAAE,GAAG,aAAa,CAAC,GAAG;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tursodatabase/sync-common",
|
|
3
|
-
"version": "0.2.0-pre.
|
|
3
|
+
"version": "0.2.0-pre.9",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/tursodatabase/turso"
|
|
@@ -23,6 +23,6 @@
|
|
|
23
23
|
"test": "echo 'no tests'"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@tursodatabase/database-common": "^0.2.0-pre.
|
|
26
|
+
"@tursodatabase/database-common": "^0.2.0-pre.9"
|
|
27
27
|
}
|
|
28
28
|
}
|