rmapi-js 5.0.0 → 6.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/README.md +32 -90
- package/dist/index.d.ts +101 -514
- package/dist/index.js +159 -706
- package/dist/rmapi-js.esm.min.js +1 -1
- package/package.json +14 -15
- package/dist/index.spec.d.ts +0 -1
- package/dist/index.spec.js +0 -800
- package/dist/test-utils.d.ts +0 -22
- package/dist/test-utils.js +0 -71
- package/dist/utils.d.ts +0 -6
- package/dist/utils.js +0 -22
- package/dist/utils.spec.d.ts +0 -1
- package/dist/utils.spec.js +0 -21
- package/dist/validate.d.ts +0 -3
- package/dist/validate.js +0 -8
- package/dist/validate.spec.d.ts +0 -1
- package/dist/validate.spec.js +0 -15
package/dist/test-utils.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { FetchLike, HeadersLike, RequestInitLike, ResponseLike } from ".";
|
|
2
|
-
export declare function resolveTo<T>(val: T): [Promise<T>, () => void];
|
|
3
|
-
export declare class MockResponse implements ResponseLike {
|
|
4
|
-
private readonly content;
|
|
5
|
-
readonly status: number;
|
|
6
|
-
readonly statusText: string;
|
|
7
|
-
readonly mapHeaders: Record<string, string>;
|
|
8
|
-
constructor(content?: string, status?: number, statusText?: string, mapHeaders?: Record<string, string>);
|
|
9
|
-
get ok(): boolean;
|
|
10
|
-
get headers(): HeadersLike;
|
|
11
|
-
text(): Promise<string>;
|
|
12
|
-
arrayBuffer(): Promise<ArrayBuffer>;
|
|
13
|
-
}
|
|
14
|
-
export interface LoggedRequest extends RequestInitLike {
|
|
15
|
-
url: string;
|
|
16
|
-
bodyText: string | undefined;
|
|
17
|
-
}
|
|
18
|
-
export interface MockFetch extends FetchLike {
|
|
19
|
-
pastRequests: LoggedRequest[];
|
|
20
|
-
}
|
|
21
|
-
export type Awaitable<T> = T | Promise<T>;
|
|
22
|
-
export declare function createMockFetch(...nextResponses: Awaitable<MockResponse>[]): MockFetch;
|
package/dist/test-utils.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
export function resolveTo(val) {
|
|
2
|
-
let res;
|
|
3
|
-
const prom = new Promise((resolve) => {
|
|
4
|
-
res = resolve;
|
|
5
|
-
});
|
|
6
|
-
return [prom, () => res(val)];
|
|
7
|
-
}
|
|
8
|
-
export class MockResponse {
|
|
9
|
-
content;
|
|
10
|
-
status;
|
|
11
|
-
statusText;
|
|
12
|
-
mapHeaders;
|
|
13
|
-
constructor(content = "", status = 200, statusText = "", mapHeaders = {}) {
|
|
14
|
-
this.content = content;
|
|
15
|
-
this.status = status;
|
|
16
|
-
this.statusText = statusText;
|
|
17
|
-
this.mapHeaders = mapHeaders;
|
|
18
|
-
}
|
|
19
|
-
get ok() {
|
|
20
|
-
return 200 <= this.status && this.status < 300;
|
|
21
|
-
}
|
|
22
|
-
get headers() {
|
|
23
|
-
const { mapHeaders } = this;
|
|
24
|
-
return {
|
|
25
|
-
get(key) {
|
|
26
|
-
return mapHeaders[key] ?? null;
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
text() {
|
|
31
|
-
return Promise.resolve(this.content);
|
|
32
|
-
}
|
|
33
|
-
arrayBuffer() {
|
|
34
|
-
const enc = new TextEncoder();
|
|
35
|
-
const encoded = enc.encode(this.content).buffer;
|
|
36
|
-
return Promise.resolve(encoded);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const dec = new TextDecoder();
|
|
40
|
-
function extractBodyText(body) {
|
|
41
|
-
if (body === undefined) {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
else if (typeof body === "string") {
|
|
45
|
-
return body;
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
return dec.decode(body);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
export function createMockFetch(...nextResponses) {
|
|
52
|
-
void nextResponses.reverse();
|
|
53
|
-
const pastRequests = [];
|
|
54
|
-
const mockFetch = async (url, options) => {
|
|
55
|
-
pastRequests.push({
|
|
56
|
-
url,
|
|
57
|
-
bodyText: extractBodyText(options?.body),
|
|
58
|
-
...options,
|
|
59
|
-
});
|
|
60
|
-
const res = nextResponses.pop();
|
|
61
|
-
/* istanbul ignore else */
|
|
62
|
-
if (res) {
|
|
63
|
-
return await res;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
throw new Error("didn't set next response");
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
mockFetch.pastRequests = pastRequests;
|
|
70
|
-
return mockFetch;
|
|
71
|
-
}
|
package/dist/utils.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/** convert a buffer to hex */
|
|
2
|
-
export declare function toHex(buffer: Uint8Array): string;
|
|
3
|
-
/** convert a hex string to a buffer */
|
|
4
|
-
export declare function fromHex(hex: string): Uint8Array;
|
|
5
|
-
/** concat buffers */
|
|
6
|
-
export declare function concatBuffers(buffers: Uint8Array[]): Uint8Array;
|
package/dist/utils.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/** convert a buffer to hex */
|
|
2
|
-
export function toHex(buffer) {
|
|
3
|
-
return [...buffer].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
4
|
-
}
|
|
5
|
-
/** convert a hex string to a buffer */
|
|
6
|
-
export function fromHex(hex) {
|
|
7
|
-
return new Uint8Array((hex.match(/../g) ?? []).map((h) => parseInt(h, 16)));
|
|
8
|
-
}
|
|
9
|
-
/** concat buffers */
|
|
10
|
-
export function concatBuffers(buffers) {
|
|
11
|
-
let length = 0;
|
|
12
|
-
for (const buff of buffers) {
|
|
13
|
-
length += buff.length;
|
|
14
|
-
}
|
|
15
|
-
const result = new Uint8Array(length);
|
|
16
|
-
let offset = 0;
|
|
17
|
-
for (const buff of buffers) {
|
|
18
|
-
result.set(buff, offset);
|
|
19
|
-
offset += buff.length;
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}
|
package/dist/utils.spec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/utils.spec.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test";
|
|
2
|
-
import { concatBuffers, fromHex, toHex } from "./utils";
|
|
3
|
-
test("toHex()", () => {
|
|
4
|
-
const buff = new Uint8Array([0, 255, 15, 240, 154]);
|
|
5
|
-
const hex = toHex(buff);
|
|
6
|
-
expect(hex).toBe("00ff0ff09a");
|
|
7
|
-
expect(toHex(new Uint8Array(0))).toBe("");
|
|
8
|
-
});
|
|
9
|
-
test("fromHex()", () => {
|
|
10
|
-
const hex = "00ff0ff09a";
|
|
11
|
-
const buff = fromHex(hex);
|
|
12
|
-
expect([...buff]).toEqual([0, 255, 15, 240, 154]);
|
|
13
|
-
expect([...fromHex("")]).toEqual([]);
|
|
14
|
-
});
|
|
15
|
-
test("concatBuffers()", () => {
|
|
16
|
-
const a = new Uint8Array([0, 1, 2]);
|
|
17
|
-
const b = new Uint8Array([3]);
|
|
18
|
-
const c = new Uint8Array([4, 5]);
|
|
19
|
-
const joined = concatBuffers([a, b, c]);
|
|
20
|
-
expect([...joined]).toEqual([0, 1, 2, 3, 4, 5]);
|
|
21
|
-
});
|
package/dist/validate.d.ts
DELETED
package/dist/validate.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { validate as jtdValidate } from "jtd";
|
|
2
|
-
export function validate(schema, obj, verify = true) {
|
|
3
|
-
const errors = verify ? jtdValidate(schema, obj) : [];
|
|
4
|
-
if (errors.length) {
|
|
5
|
-
// TODO better errors
|
|
6
|
-
throw new Error(`couldn't validate schema: ${JSON.stringify(obj)} didn't match schema ${JSON.stringify(schema)}`);
|
|
7
|
-
}
|
|
8
|
-
}
|
package/dist/validate.spec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/validate.spec.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test";
|
|
2
|
-
import { validate } from "./validate";
|
|
3
|
-
const uploadEntrySchema = {
|
|
4
|
-
properties: {
|
|
5
|
-
docID: { type: "string" },
|
|
6
|
-
hash: { type: "string" },
|
|
7
|
-
},
|
|
8
|
-
};
|
|
9
|
-
test("validate()", () => {
|
|
10
|
-
const accurate = { docID: "", hash: "" };
|
|
11
|
-
expect(() => validate(uploadEntrySchema, accurate)).not.toThrow();
|
|
12
|
-
const innaccurate = { docID: "" };
|
|
13
|
-
expect(() => validate(uploadEntrySchema, innaccurate)).toThrow();
|
|
14
|
-
expect(() => validate(uploadEntrySchema, innaccurate, false)).not.toThrow();
|
|
15
|
-
});
|