rmapi-js 10.2.0 → 11.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.
- package/dist/error.d.ts +14 -0
- package/dist/error.js +21 -0
- package/dist/index.js +0 -4
- package/dist/lru.d.ts +8 -0
- package/dist/lru.js +64 -0
- package/dist/raw.d.ts +0 -1
- package/dist/raw.js +0 -3
- package/dist/rmapi-js.esm.min.js +9 -10
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +10 -0
- package/package.json +11 -5
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** an error that results from a failed request */
|
|
2
|
+
export declare class ValidationError extends Error {
|
|
3
|
+
/** the response status number */
|
|
4
|
+
readonly field: string;
|
|
5
|
+
/** the response status text */
|
|
6
|
+
readonly regex: RegExp;
|
|
7
|
+
constructor(field: string, regex: RegExp, message: string);
|
|
8
|
+
}
|
|
9
|
+
/** an error that results while supplying a hash not found in the entries of the root hash */
|
|
10
|
+
export declare class HashNotFoundError extends Error {
|
|
11
|
+
/** the hash that couldn't be found */
|
|
12
|
+
readonly hash: string;
|
|
13
|
+
constructor(hash: string);
|
|
14
|
+
}
|
package/dist/error.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** an error that results from a failed request */
|
|
2
|
+
export class ValidationError extends Error {
|
|
3
|
+
/** the response status number */
|
|
4
|
+
field;
|
|
5
|
+
/** the response status text */
|
|
6
|
+
regex;
|
|
7
|
+
constructor(field, regex, message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.field = field;
|
|
10
|
+
this.regex = regex;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** an error that results while supplying a hash not found in the entries of the root hash */
|
|
14
|
+
export class HashNotFoundError extends Error {
|
|
15
|
+
/** the hash that couldn't be found */
|
|
16
|
+
hash;
|
|
17
|
+
constructor(hash) {
|
|
18
|
+
super(`'${hash}' not found in the root hash`);
|
|
19
|
+
this.hash = hash;
|
|
20
|
+
}
|
|
21
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -61,9 +61,6 @@ export { HashNotFoundError, ValidationError } from "./error.js";
|
|
|
61
61
|
const AUTH_HOST = "https://webapp-prod.cloud.remarkable.engineering";
|
|
62
62
|
const RAW_HOST = "https://eu.tectonic.remarkable.com";
|
|
63
63
|
const UPLOAD_HOST = "https://internal.cloud.remarkable.com";
|
|
64
|
-
// ------------ //
|
|
65
|
-
// Request Info //
|
|
66
|
-
// ------------ //
|
|
67
64
|
// The section has all the types that are stored in the remarkable cloud.
|
|
68
65
|
const idReg = /^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}||trash)$/;
|
|
69
66
|
/** An error that gets thrown when the backend while trying to update
|
|
@@ -339,7 +336,6 @@ class Remarkable {
|
|
|
339
336
|
const [[contentEntry, uploadContent], [metadataEntry, uploadMetadata], [pagedataEntry, uploadPagedata], [fileEntry, uploadFile], [rootHash, generation, schemaVersion],] = await Promise.all([
|
|
340
337
|
this.raw.putContent(`${id}.content`, content),
|
|
341
338
|
this.raw.putMetadata(`${id}.metadata`, metadata),
|
|
342
|
-
// eslint-disable-next-line spellcheck/spell-checker
|
|
343
339
|
this.raw.putText(`${id}.pagedata`, "\n"),
|
|
344
340
|
this.raw.putFile(`${id}.${fileType}`, buffer),
|
|
345
341
|
this.#getRootHash(refresh),
|
package/dist/lru.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class LruCache extends Map<string, string | null> {
|
|
2
|
+
#private;
|
|
3
|
+
constructor(maxSize: number, entries?: Iterable<[string, string | null]>);
|
|
4
|
+
get(key: string): string | null | undefined;
|
|
5
|
+
set(key: string, value: string | null): this;
|
|
6
|
+
delete(key: string): boolean;
|
|
7
|
+
clear(): void;
|
|
8
|
+
}
|
package/dist/lru.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export class LruCache extends Map {
|
|
2
|
+
#maxSize;
|
|
3
|
+
#currentSize = 0;
|
|
4
|
+
constructor(maxSize, entries = []) {
|
|
5
|
+
super();
|
|
6
|
+
this.#maxSize = maxSize;
|
|
7
|
+
for (const [key, value] of entries) {
|
|
8
|
+
this.set(key, value);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
get(key) {
|
|
12
|
+
const res = super.get(key);
|
|
13
|
+
if (res !== undefined) {
|
|
14
|
+
// update order so key is most recent
|
|
15
|
+
super.delete(key);
|
|
16
|
+
super.set(key, res);
|
|
17
|
+
}
|
|
18
|
+
return res;
|
|
19
|
+
}
|
|
20
|
+
set(key, value) {
|
|
21
|
+
const existing = super.get(key);
|
|
22
|
+
if (existing === undefined) {
|
|
23
|
+
this.#currentSize += key.length; // adding a new key
|
|
24
|
+
}
|
|
25
|
+
else if (existing !== null) {
|
|
26
|
+
this.#currentSize -= existing.length; // removing old value
|
|
27
|
+
}
|
|
28
|
+
if (value !== null) {
|
|
29
|
+
this.#currentSize += value.length;
|
|
30
|
+
}
|
|
31
|
+
// delete existing value
|
|
32
|
+
super.delete(key);
|
|
33
|
+
// evict down to desired size
|
|
34
|
+
let entry;
|
|
35
|
+
while (this.#currentSize > this.#maxSize &&
|
|
36
|
+
(entry = this.entries().next().value)) {
|
|
37
|
+
const [oldestKey, oldestValue] = entry;
|
|
38
|
+
super.delete(oldestKey);
|
|
39
|
+
this.#currentSize -= oldestKey.length;
|
|
40
|
+
if (oldestValue !== null) {
|
|
41
|
+
this.#currentSize -= oldestValue.length;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// finally insert new key and return
|
|
45
|
+
super.set(key, value);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
delete(key) {
|
|
49
|
+
const value = super.get(key);
|
|
50
|
+
if (value === undefined) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
super.delete(key);
|
|
54
|
+
if (value !== null) {
|
|
55
|
+
this.#currentSize -= value.length;
|
|
56
|
+
}
|
|
57
|
+
this.#currentSize -= key.length;
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
clear() {
|
|
61
|
+
super.clear();
|
|
62
|
+
this.#currentSize = 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
package/dist/raw.d.ts
CHANGED
package/dist/raw.js
CHANGED
|
@@ -2,7 +2,6 @@ import CRC32C from "crc-32/crc32c";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { ValidationError } from "./error.js";
|
|
4
4
|
import { concatArrays } from "./utils.js";
|
|
5
|
-
import "core-js/proposals/array-buffer-base64";
|
|
6
5
|
const hashReg = /^[0-9a-f]{64}$/;
|
|
7
6
|
const tag = z
|
|
8
7
|
.object({
|
|
@@ -127,7 +126,6 @@ const documentContentOptional = {
|
|
|
127
126
|
})
|
|
128
127
|
.passthrough()
|
|
129
128
|
.optional(),
|
|
130
|
-
// eslint-disable-next-line spellcheck/spell-checker
|
|
131
129
|
viewBackgroundFilter: z.enum(["off", "fullpage"]).optional(),
|
|
132
130
|
zoomMode: z
|
|
133
131
|
.enum(["bestFit", "customFit", "fitToHeight", "fitToWidth"])
|
|
@@ -380,7 +378,6 @@ export class RawRemarkable {
|
|
|
380
378
|
body: bytes,
|
|
381
379
|
headers: {
|
|
382
380
|
"rm-filename": fileName,
|
|
383
|
-
// eslint-disable-next-line spellcheck/spell-checker
|
|
384
381
|
"x-goog-hash": `crc32c=${crcHash}`,
|
|
385
382
|
},
|
|
386
383
|
});
|