@bob-kit/client 0.0.18 → 0.0.19
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/bob.wasm +0 -0
- package/dist/error.d.ts +5 -0
- package/dist/error.js +10 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +17 -14
- package/package.json +2 -2
- package/dist/install.d.ts +0 -1
- package/dist/install.js +0 -36
package/dist/bob.wasm
CHANGED
|
Binary file
|
package/dist/error.d.ts
ADDED
package/dist/error.js
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { BobQueryResult,
|
|
1
|
+
import type { BobQueryResult, Driver } from "@bob-kit/types";
|
|
2
2
|
type BobQueryParams = {
|
|
3
3
|
id?: string;
|
|
4
4
|
driver: Driver;
|
|
5
|
-
input:
|
|
5
|
+
input: string;
|
|
6
6
|
};
|
|
7
7
|
export declare const bobQuery: ({ id, driver: { cache }, input, }: BobQueryParams) => Promise<BobQueryResult>;
|
|
8
8
|
export default function bob(driver: Driver): {
|
|
9
|
-
query: <A, B = any>(input: TemplateStringsArray | string, ...parameters: B[]) => Promise<
|
|
10
|
-
cache: (id: string) => <A, B = any>(input: TemplateStringsArray | string, ...parameters: B[]) => Promise<
|
|
9
|
+
query: <A, B = any>(input: TemplateStringsArray | string, ...parameters: B[]) => Promise<A[]>;
|
|
10
|
+
cache: (id: string) => <A, B = any>(input: TemplateStringsArray | string, ...parameters: B[]) => Promise<A[]>;
|
|
11
11
|
factory: any;
|
|
12
12
|
};
|
|
13
13
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { BobError } from "./error";
|
|
1
2
|
import { WASM } from "./wasm.js";
|
|
3
|
+
import { BobErrors } from "@bob-kit/types/errors";
|
|
2
4
|
let bobInstance;
|
|
3
5
|
export const bobQuery = async ({ id, driver: { cache }, input, }) => {
|
|
4
|
-
const
|
|
5
|
-
const cacheKey = id ?? query;
|
|
6
|
+
const cacheKey = id ?? input;
|
|
6
7
|
if (cache) {
|
|
7
8
|
const cached = cache.get(cacheKey);
|
|
8
9
|
if (cached)
|
|
9
10
|
return cache.get(cacheKey);
|
|
10
11
|
}
|
|
11
|
-
const result = bobInstance.query(
|
|
12
|
+
const result = bobInstance.query(input);
|
|
12
13
|
if (cache) {
|
|
13
14
|
cache.set(cacheKey, result);
|
|
14
15
|
}
|
|
@@ -16,31 +17,33 @@ export const bobQuery = async ({ id, driver: { cache }, input, }) => {
|
|
|
16
17
|
};
|
|
17
18
|
export default function bob(driver) {
|
|
18
19
|
bobInstance = new WASM(driver.driver);
|
|
19
|
-
const execute = async (input, parameters = [], id) => {
|
|
20
|
-
const
|
|
20
|
+
const execute = async ({ input, parameters = [], id, }) => {
|
|
21
|
+
const query = typeof input === "string" ? input : input.join("?");
|
|
22
|
+
const { error, value } = await bobQuery({ input: query, driver, id });
|
|
21
23
|
if (error)
|
|
22
|
-
|
|
24
|
+
throw new BobError(error.name, error.message);
|
|
23
25
|
if (value?.tables) {
|
|
24
26
|
for (const table of value.tables) {
|
|
25
27
|
await driver.querier(table.trim());
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
if (value?.actions) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
if (value.actions.length > 1) {
|
|
32
|
+
throw new BobError(BobErrors.MultipleActions, "Multiple actions are not allowed");
|
|
33
|
+
}
|
|
34
|
+
if (value.actions.length === 1) {
|
|
35
|
+
return (await driver.querier(value.actions[0], ...parameters));
|
|
32
36
|
}
|
|
33
|
-
return { value: result };
|
|
34
37
|
}
|
|
35
|
-
return
|
|
38
|
+
return [];
|
|
36
39
|
};
|
|
37
40
|
return {
|
|
38
|
-
query: (input, ...parameters) => execute(input, parameters),
|
|
39
|
-
cache: (id) => (input, ...parameters) => execute(input, parameters, id),
|
|
41
|
+
query: (input, ...parameters) => execute({ input, parameters }),
|
|
42
|
+
cache: (id) => (input, ...parameters) => execute({ input, parameters, id }),
|
|
40
43
|
factory: new Proxy({}, {
|
|
41
44
|
get(_, id) {
|
|
42
45
|
return (input, ...parameters) => {
|
|
43
|
-
return execute(input, parameters, id);
|
|
46
|
+
return execute({ input, parameters, id });
|
|
44
47
|
};
|
|
45
48
|
},
|
|
46
49
|
}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bob-kit/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"description": "",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"typescript": "5.9.3"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@bob-kit/types": "^0.0.
|
|
31
|
+
"@bob-kit/types": "^0.0.6"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "tsc && tsc-alias",
|
package/dist/install.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/install.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
import { pipeline } from "stream";
|
|
4
|
-
import { promisify } from "util";
|
|
5
|
-
const streamPipeline = promisify(pipeline);
|
|
6
|
-
async function downloadFile(url, folder, filename) {
|
|
7
|
-
const res = await fetch(url);
|
|
8
|
-
if (!res.ok)
|
|
9
|
-
throw new Error(`Failed to fetch ${url}: ${res.statusText}`);
|
|
10
|
-
fs.mkdirSync(folder, { recursive: true });
|
|
11
|
-
const filePath = path.join(folder, filename);
|
|
12
|
-
const nodeStream = res.body;
|
|
13
|
-
await streamPipeline(nodeStream, fs.createWriteStream(filePath));
|
|
14
|
-
console.log(`Downloaded ${filename} to ${filePath}`);
|
|
15
|
-
}
|
|
16
|
-
async function getLatestRelease() {
|
|
17
|
-
const apiUrl = "https://api.github.com/repos/bob-object-builder/bob/releases/latest";
|
|
18
|
-
const res = await fetch(apiUrl);
|
|
19
|
-
if (!res.ok)
|
|
20
|
-
throw new Error(`Failed to fetch latest release: ${res.statusText}`);
|
|
21
|
-
return res.json();
|
|
22
|
-
}
|
|
23
|
-
(async () => {
|
|
24
|
-
try {
|
|
25
|
-
const fileName = "bob.wasm";
|
|
26
|
-
const downloadFolder = "dist";
|
|
27
|
-
const release = await getLatestRelease();
|
|
28
|
-
const asset = release.assets.find((a) => a.name === fileName);
|
|
29
|
-
if (!asset)
|
|
30
|
-
throw new Error(`${fileName} not found in latest release`);
|
|
31
|
-
await downloadFile(asset.browser_download_url, downloadFolder, fileName);
|
|
32
|
-
}
|
|
33
|
-
catch (err) {
|
|
34
|
-
console.error("Error:", err);
|
|
35
|
-
}
|
|
36
|
-
})();
|