@tinyshed/tinystore 0.1.0-rc.4 → 0.1.0-rc.6
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 +37 -37
- package/bin/tinystore.js +12 -1
- package/dist/backup.d.ts +33 -0
- package/dist/backup.js +49 -0
- package/dist/blobs.d.ts +160 -79
- package/dist/blobs.js +510 -217
- package/dist/channels.d.ts +90 -0
- package/dist/channels.js +291 -0
- package/dist/clock.js +3 -3
- package/dist/config.d.ts +209 -86
- package/dist/config.js +581 -538
- package/dist/connection.d.ts +64 -2
- package/dist/connection.js +201 -16
- package/dist/console.d.ts +27 -3
- package/dist/console.js +165 -12
- package/dist/dotenv.d.ts +7 -0
- package/dist/dotenv.js +79 -0
- package/dist/errors.d.ts +61 -1
- package/dist/errors.js +81 -1
- package/dist/handles.d.ts +44 -2
- package/dist/handles.js +81 -2
- package/dist/index.d.ts +17 -11
- package/dist/index.js +5 -3
- package/dist/instruments.d.ts +177 -0
- package/dist/instruments.js +819 -0
- package/dist/jobs.d.ts +335 -239
- package/dist/jobs.js +716 -536
- package/dist/json.d.ts +2 -0
- package/dist/json.js +122 -0
- package/dist/kv.d.ts +130 -243
- package/dist/kv.js +273 -640
- package/dist/limits.d.ts +80 -0
- package/dist/limits.js +139 -0
- package/dist/locks.d.ts +62 -0
- package/dist/locks.js +237 -0
- package/dist/logger.d.ts +45 -9
- package/dist/logger.js +150 -38
- package/dist/metrics.d.ts +210 -209
- package/dist/metrics.js +319 -556
- package/dist/once.d.ts +19 -18
- package/dist/once.js +74 -63
- package/dist/query.d.ts +181 -0
- package/dist/query.js +788 -0
- package/dist/records.d.ts +241 -150
- package/dist/records.js +507 -291
- package/dist/runtime/addon.d.ts +14 -0
- package/dist/runtime/addon.js +69 -0
- package/dist/runtime/bun.js +5 -7
- package/dist/runtime/node.js +5 -7
- package/dist/runtime/pipe.d.ts +17 -0
- package/dist/runtime/pipe.js +133 -0
- package/dist/runtime/shared.d.ts +6 -0
- package/dist/runtime/shared.js +19 -0
- package/dist/runtime.d.ts +5 -2
- package/dist/search.d.ts +189 -0
- package/dist/search.js +281 -0
- package/dist/session.d.ts +31 -3
- package/dist/session.js +153 -41
- package/dist/sql.d.ts +228 -78
- package/dist/sql.js +745 -240
- package/dist/store.d.ts +244 -24
- package/dist/store.js +270 -67
- package/dist/time.d.ts +5 -1
- package/dist/time.js +22 -2
- package/dist/tx.d.ts +61 -0
- package/dist/tx.js +314 -0
- package/dist/wire/codec.d.ts +23 -7
- package/dist/wire/codec.js +56 -35
- package/dist/wire/frame.d.ts +2 -0
- package/dist/wire/frame.js +31 -14
- package/dist/wire/messages.d.ts +259 -0
- package/dist/wire/messages.js +22 -0
- package/dist/wire/msgpack.d.ts +49 -1
- package/dist/wire/msgpack.js +293 -56
- package/dist/wire/protocol.d.ts +2683 -0
- package/dist/wire/protocol.js +10846 -0
- package/package.json +39 -38
- package/src/backup.ts +81 -0
- package/src/blobs.ts +678 -301
- package/src/channels.ts +377 -0
- package/src/clock.ts +4 -4
- package/src/config.ts +902 -612
- package/src/connection.ts +279 -21
- package/src/console.ts +180 -12
- package/src/dotenv.ts +82 -0
- package/src/errors.ts +105 -0
- package/src/handles.ts +157 -8
- package/src/index.ts +158 -52
- package/src/instruments.ts +1042 -0
- package/src/jobs.ts +1017 -733
- package/src/json.ts +133 -0
- package/src/kv.ts +424 -847
- package/src/limits.ts +202 -0
- package/src/locks.ts +320 -0
- package/src/logger.ts +209 -40
- package/src/metrics.ts +557 -752
- package/src/once.ts +86 -83
- package/src/query.ts +1005 -0
- package/src/records.ts +795 -418
- package/src/runtime/addon.ts +99 -0
- package/src/runtime/bun.ts +5 -7
- package/src/runtime/node.ts +5 -7
- package/src/runtime/pipe.ts +178 -0
- package/src/runtime/shared.ts +20 -0
- package/src/runtime.ts +5 -2
- package/src/search.ts +480 -0
- package/src/session.ts +187 -41
- package/src/sql.ts +993 -306
- package/src/store.ts +473 -78
- package/src/time.ts +48 -3
- package/src/tx.ts +426 -0
- package/src/wire/codec.ts +78 -37
- package/src/wire/frame.ts +44 -14
- package/src/wire/messages.ts +25 -0
- package/src/wire/msgpack.ts +327 -56
- package/src/wire/protocol.ts +11709 -0
- package/dist/limiter.d.ts +0 -45
- package/dist/limiter.js +0 -68
- package/dist/quota.d.ts +0 -44
- package/dist/quota.js +0 -98
- package/src/limiter.ts +0 -99
- package/src/quota.ts +0 -137
package/package.json
CHANGED
|
@@ -1,40 +1,41 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
2
|
+
"name": "@tinyshed/tinystore",
|
|
3
|
+
"version": "0.1.0-rc.6",
|
|
4
|
+
"description": "TinyStore for Bun and Node: kv, jobs, blobs, SQL, records and metrics in one directory, served by a sidecar",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/tinyshed/tinystore.git",
|
|
9
|
+
"directory": "sdk/js"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"engines": {
|
|
13
|
+
"bun": ">=1.4",
|
|
14
|
+
"node": ">=22"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"bun": "./src/index.ts",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"bin": {
|
|
24
|
+
"tinystore": "bin/tinystore.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"src",
|
|
28
|
+
"dist",
|
|
29
|
+
"bin",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"optionalDependencies": {
|
|
33
|
+
"@tinyshed/tinystore-linux-x64": "0.1.0-rc.6",
|
|
34
|
+
"@tinyshed/tinystore-linux-arm64": "0.1.0-rc.6",
|
|
35
|
+
"@tinyshed/tinystore-linux-x64-musl": "0.1.0-rc.6",
|
|
36
|
+
"@tinyshed/tinystore-linux-arm64-musl": "0.1.0-rc.6",
|
|
37
|
+
"@tinyshed/tinystore-darwin-arm64": "0.1.0-rc.6",
|
|
38
|
+
"@tinyshed/tinystore-darwin-x64": "0.1.0-rc.6",
|
|
39
|
+
"@tinyshed/tinystore-win32-x64": "0.1.0-rc.6"
|
|
40
|
+
}
|
|
40
41
|
}
|
package/src/backup.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// A backup of the whole store, as docs/guides/backup/README.md has it: one zip of every
|
|
2
|
+
// engine that the server writes while the store keeps working and sends in
|
|
3
|
+
// pieces, written beside the name the program gives and renamed once whole,
|
|
4
|
+
// so that a backup that fails leaves no zip.
|
|
5
|
+
|
|
6
|
+
import { open, rename, rm } from 'node:fs/promises'
|
|
7
|
+
|
|
8
|
+
import type { Link } from './connection.ts'
|
|
9
|
+
import { BackupPiece, BackupWrite, BackupWritten, methods } from './wire/protocol.ts'
|
|
10
|
+
|
|
11
|
+
/** What a backup takes beside every engine's files. */
|
|
12
|
+
export interface BackupOptions {
|
|
13
|
+
/**
|
|
14
|
+
* files of the program's it includes, by their paths inside the store's
|
|
15
|
+
* directory, such as 'secret.key', which a restore puts back where they
|
|
16
|
+
* were: a backup holds none unless named
|
|
17
|
+
*/
|
|
18
|
+
include?: readonly string[]
|
|
19
|
+
/**
|
|
20
|
+
* includes the store's encryption key, as it is, which a backup leaves
|
|
21
|
+
* out otherwise: the zip is not encrypted, so a backup with the key opens
|
|
22
|
+
* every value it holds
|
|
23
|
+
*/
|
|
24
|
+
includeEncryptionKey?: boolean
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** What a backup holds. */
|
|
28
|
+
export interface Backup {
|
|
29
|
+
/** the files, the engines' and those it was told to take */
|
|
30
|
+
files: number
|
|
31
|
+
/** their bytes, the zip's own fields aside */
|
|
32
|
+
bytes: number
|
|
33
|
+
/**
|
|
34
|
+
* the store seals values with an encryption key the backup does not
|
|
35
|
+
* hold: they open with that key alone, kept apart
|
|
36
|
+
*/
|
|
37
|
+
keyLeftOut: boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const nothing = new Uint8Array()
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Writes a backup of the store `link` reaches to `path`, beside it first:
|
|
44
|
+
* a connection lost on the way makes it again from its start.
|
|
45
|
+
*/
|
|
46
|
+
export async function backup(link: Link, path: string, options: BackupOptions): Promise<Backup> {
|
|
47
|
+
const partial = `${path}.${process.pid}.part`
|
|
48
|
+
const asked = BackupWrite.encode({
|
|
49
|
+
include: [...(options.include ?? [])],
|
|
50
|
+
includeEncryptionKey: options.includeEncryptionKey === true,
|
|
51
|
+
})
|
|
52
|
+
try {
|
|
53
|
+
const backed = await link.run('read', async connection => {
|
|
54
|
+
const file = await open(partial, 'w')
|
|
55
|
+
try {
|
|
56
|
+
const stream = await connection.session.open(methods['backup.write'], asked, true)
|
|
57
|
+
await stream.next()
|
|
58
|
+
for (;;) {
|
|
59
|
+
const event = await stream.next()
|
|
60
|
+
if (event.end) {
|
|
61
|
+
await file.sync()
|
|
62
|
+
return BackupWritten.decode(event.body)
|
|
63
|
+
}
|
|
64
|
+
stream.consumed(event.body.length)
|
|
65
|
+
await file.write(BackupPiece.decode(event.body).bytes ?? nothing)
|
|
66
|
+
}
|
|
67
|
+
} finally {
|
|
68
|
+
await file.close()
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
await rename(partial, path)
|
|
72
|
+
return {
|
|
73
|
+
files: Number(backed.files ?? 0),
|
|
74
|
+
bytes: Number(backed.bytes ?? 0),
|
|
75
|
+
keyLeftOut: backed.keyLeftOut === true,
|
|
76
|
+
}
|
|
77
|
+
} catch (err) {
|
|
78
|
+
await rm(partial, { force: true })
|
|
79
|
+
throw err
|
|
80
|
+
}
|
|
81
|
+
}
|