sproutboat 0.28.0 → 0.29.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 (36) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/SURFACE.md +3 -3
  3. package/THIRD_PARTY_NOTICES.md +9 -0
  4. package/package.json +6 -6
  5. package/src/build.ts +12 -2
  6. package/src/compile.ts +23 -1
  7. package/src/main.ts +13 -2
  8. package/src/native-restore-sources.ts +48 -0
  9. package/src/native-restore.ts +155 -0
  10. package/src/surface.ts +2 -2
  11. package/vendor/ltx-restore/LICENSE +202 -0
  12. package/vendor/ltx-restore/NOTICE +32 -0
  13. package/vendor/ltx-restore/crc64-native.ts.txt +7 -0
  14. package/vendor/ltx-restore/errors.ts.txt +74 -0
  15. package/vendor/ltx-restore/file-io.ts.txt +54 -0
  16. package/vendor/ltx-restore/ltx/byte-reader.ts.txt +46 -0
  17. package/vendor/ltx-restore/ltx/bytes.ts.txt +87 -0
  18. package/vendor/ltx-restore/ltx/checksum.ts.txt +46 -0
  19. package/vendor/ltx-restore/ltx/constants.ts.txt +71 -0
  20. package/vendor/ltx-restore/ltx/crc64.ts.txt +73 -0
  21. package/vendor/ltx-restore/ltx/decoder.ts.txt +285 -0
  22. package/vendor/ltx-restore/ltx/header.ts.txt +126 -0
  23. package/vendor/ltx-restore/ltx/lz4.ts.txt +260 -0
  24. package/vendor/ltx-restore/ltx/page-index.ts.txt +140 -0
  25. package/vendor/ltx-restore/ltx/page.ts.txt +80 -0
  26. package/vendor/ltx-restore/ltx/sink.ts.txt +33 -0
  27. package/vendor/ltx-restore/ltx/trailer.ts.txt +58 -0
  28. package/vendor/ltx-restore/ltx/types.ts.txt +152 -0
  29. package/vendor/ltx-restore/lz4js/README.md +39 -0
  30. package/vendor/ltx-restore/lz4js/lz4.js.txt +560 -0
  31. package/vendor/ltx-restore/lz4js/package.json +36 -0
  32. package/vendor/ltx-restore/lz4js/util.js.txt +54 -0
  33. package/vendor/ltx-restore/lz4js/xxh32.js.txt +102 -0
  34. package/vendor/ltx-restore/program.ts.txt +3 -0
  35. package/vendor/ltx-restore/restore-native.ts.txt +120 -0
  36. package/vendor/ltx-restore/restore.ts.txt +96 -0
@@ -0,0 +1,152 @@
1
+ import { LTXFormatError } from '../errors.ts';
2
+ /**
3
+ * LTX shared types and small value helpers.
4
+ *
5
+ * 64-bit unsigned values (TXID, Checksum) are represented as `bigint` to keep
6
+ * exact semantics. Page numbers and file offsets/sizes fit within JS safe
7
+ * integers for any realistic database, so they are `number`.
8
+ */
9
+
10
+ export type TXID = bigint;
11
+ export type Checksum = bigint;
12
+
13
+ /** Pos is the transactional position of a database. */
14
+ export interface Pos {
15
+ txID: TXID;
16
+ postApplyChecksum: Checksum;
17
+ }
18
+
19
+ /** Formats a TXID as a fixed-width 16-char lowercase hex string. */
20
+ export function formatTXID(txID: bigint): string {
21
+ return txID.toString(16).padStart(16, '0');
22
+ }
23
+
24
+ /** Parses a 16-character hex string into a TXID. */
25
+ export function parseTXID(s: string): bigint {
26
+ if (s.length !== 16) {
27
+ throw new LTXFormatError(`invalid formatted transaction id length: ${JSON.stringify(s)}`);
28
+ }
29
+ if (!/^[0-9a-fA-F]{16}$/.test(s)) {
30
+ throw new LTXFormatError(`invalid transaction id format: ${JSON.stringify(s)}`);
31
+ }
32
+ return BigInt(`0x${s}`);
33
+ }
34
+
35
+ /** Formats a Checksum as a fixed-width 16-char lowercase hex string. */
36
+ export function formatChecksum(chk: bigint): string {
37
+ return chk.toString(16).padStart(16, '0');
38
+ }
39
+
40
+ /** Parses a 16-character hex string into a Checksum. */
41
+ export function parseChecksum(s: string): bigint {
42
+ if (s.length !== 16) {
43
+ throw new LTXFormatError(`invalid formatted checksum length: ${JSON.stringify(s)}`);
44
+ }
45
+ if (!/^[0-9a-fA-F]{16}$/.test(s)) {
46
+ throw new LTXFormatError(`invalid checksum format: ${JSON.stringify(s)}`);
47
+ }
48
+ return BigInt(`0x${s}`);
49
+ }
50
+
51
+ export function parsePos(s: string): Pos {
52
+ if (s.length !== 33) {
53
+ throw new LTXFormatError(`invalid formatted position length: ${JSON.stringify(s)}`);
54
+ }
55
+ return {
56
+ txID: parseTXID(s.slice(0, 16)),
57
+ postApplyChecksum: parseChecksum(s.slice(17)),
58
+ };
59
+ }
60
+
61
+ export function formatPos(p: Pos): string {
62
+ return `${formatTXID(p.txID)}/${formatChecksum(p.postApplyChecksum)}`;
63
+ }
64
+
65
+ export function isZeroPos(p: Pos): boolean {
66
+ return p.txID === 0n && p.postApplyChecksum === 0n;
67
+ }
68
+
69
+ /** Header flags. */
70
+ export interface Header {
71
+ version: number;
72
+ flags: number;
73
+ pageSize: number;
74
+ commit: number;
75
+ minTXID: TXID;
76
+ maxTXID: TXID;
77
+ timestamp: bigint; // milliseconds since Unix epoch
78
+ preApplyChecksum: Checksum;
79
+ walOffset: bigint;
80
+ walSize: bigint;
81
+ walSalt1: number;
82
+ walSalt2: number;
83
+ nodeID: bigint;
84
+ }
85
+
86
+ export function isSnapshot(h: Header): boolean {
87
+ return h.minTXID === 1n;
88
+ }
89
+
90
+ export function noChecksum(h: Header): boolean {
91
+ return (h.flags & HeaderFlagNoChecksumBit) !== 0;
92
+ }
93
+
94
+ const HeaderFlagNoChecksumBit = 0x00000002;
95
+
96
+ /** PageHeader represents the header for a single page in an LTX file. */
97
+ export interface PageHeader {
98
+ pgno: number; // uint32
99
+ flags: number; // uint16
100
+ }
101
+
102
+ export function isZeroPageHeader(h: PageHeader): boolean {
103
+ return h.pgno === 0 && h.flags === 0;
104
+ }
105
+
106
+ /** Trailer represents the ending frame of an LTX file. */
107
+ export interface Trailer {
108
+ postApplyChecksum: Checksum;
109
+ fileChecksum: Checksum;
110
+ }
111
+
112
+ /** PageIndexElem describes a single page entry in the file's page index. */
113
+ export interface PageIndexElem {
114
+ level: number;
115
+ minTXID: TXID;
116
+ maxTXID: TXID;
117
+ offset: number;
118
+ size: number;
119
+ }
120
+
121
+ export type PageIndex = Map<number, PageIndexElem>;
122
+
123
+ /** FileInfo represents file information about an LTX file. */
124
+ export interface FileInfo {
125
+ level: number;
126
+ minTXID: TXID;
127
+ maxTXID: TXID;
128
+ preApplyChecksum?: Checksum;
129
+ postApplyChecksum?: Checksum;
130
+ size: number;
131
+ createdAt: number; // ms since Unix epoch
132
+ checksum?: Checksum;
133
+ }
134
+
135
+ export function preApplyPos(info: FileInfo): Pos {
136
+ return {
137
+ txID: info.minTXID - 1n,
138
+ postApplyChecksum: info.preApplyChecksum ?? 0n,
139
+ };
140
+ }
141
+
142
+ export function postApplyPos(info: FileInfo): Pos {
143
+ return {
144
+ txID: info.maxTXID,
145
+ postApplyChecksum: info.postApplyChecksum ?? 0n,
146
+ };
147
+ }
148
+
149
+ /** IsContiguous reports whether a transaction range is contiguous with prevMaxTXID. */
150
+ export function isContiguous(prevMaxTXID: TXID, minTXID: TXID, maxTXID: TXID): boolean {
151
+ return minTXID <= prevMaxTXID + 1n && maxTXID > prevMaxTXID;
152
+ }
@@ -0,0 +1,39 @@
1
+ # Lz4.js [![NPM version](https://badge.fury.io/js/lz4js.svg)](https://www.npmjs.com/package/lz4js) [![Build Status](https://travis-ci.org/Benzinga/lz4js.svg?branch=master)](https://travis-ci.org/Benzinga/lz4js) [![codecov](https://codecov.io/gh/Benzinga/lz4js/branch/master/graph/badge.svg)](https://codecov.io/gh/Benzinga/lz4js)
2
+ Lz4.js is an implementation of Lz4 designed to be used in web browsers. It contains no dependencies on external libraries or Node.JS, though it is organized as a set of CommonJS modules. It is recommended to use Browserify or WebPack to bundle this for the web browser.
3
+
4
+ ## Installation
5
+ ```
6
+ npm install lz4js
7
+ ```
8
+
9
+ ## Usage
10
+ ```javascript
11
+ var lz4 = require("lz4js");
12
+ var fs = require("fs");
13
+
14
+ // Compress 128 bytes of zero.
15
+ var compressed = lz4.compress(new Array(128));
16
+
17
+ // Decompress.
18
+ var decompressed = lz4.decompress(compressed);
19
+
20
+ // Compress file.bin to file.lz4.
21
+ var data = fs.readFileSync("file.bin");
22
+ compressed = Buffer.from(lz4.compress(data));
23
+ fs.writeFileSync('file.lz4', compressed);
24
+ ```
25
+
26
+ > **Note**: The high-level `compress` and `decompress` functions deal with framed Lz4 data and do not support raw block data nor legacy Lz4 blocks.
27
+
28
+ ## API
29
+ The API accepts either `Array`s or `Uint8Array`s. Arrays are expected to be arrays of unsigned 8-bit values. The API will return `Uint8Array`s if the browser supports them, or `Array`s otherwise.
30
+
31
+ - `compress(buffer: Array, maxSize: Number): Array`
32
+
33
+ Compresses a buffer using Lz4. maxSize sets bounds on the output length; it is recommended to not specify this unless you know what you're doing.
34
+ Any unused buffer data will be sliced before the buffer is returned.
35
+
36
+ - `decompress(buffer: Array, maxSize: Number): Array`
37
+
38
+ Decompresses a buffer using Lz4. maxSize sets bounds on the output length; if you know the output length, this will reduce memory usage somewhat.
39
+ Any unused buffer data will be sliced before the buffer is returned.