@bob-kit/client 0.0.18 → 0.0.20

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 CHANGED
Binary file
@@ -0,0 +1,5 @@
1
+ import { BobErrors } from "@bob-kit/types/errors";
2
+ export declare class BobError extends Error {
3
+ readonly name: (typeof BobErrors)[keyof typeof BobErrors];
4
+ constructor(name: (typeof BobErrors)[keyof typeof BobErrors], message: string);
5
+ }
package/dist/error.js ADDED
@@ -0,0 +1,10 @@
1
+ export class BobError extends Error {
2
+ name;
3
+ constructor(name, message) {
4
+ super(message);
5
+ this.name = name;
6
+ if (Error.captureStackTrace) {
7
+ Error.captureStackTrace(this, BobError);
8
+ }
9
+ }
10
+ }
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { BobQueryResult, BobResult, Driver } from "@bob-kit/types";
1
+ import type { BobQueryResult, Driver } from "@bob-kit/types";
2
2
  type BobQueryParams = {
3
3
  id?: string;
4
4
  driver: Driver;
5
- input: TemplateStringsArray | string;
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<BobResult<A>>;
10
- cache: (id: string) => <A, B = any>(input: TemplateStringsArray | string, ...parameters: B[]) => Promise<BobResult<A>>;
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 query = typeof input === "string" ? input : input.join("?");
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(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 { error, value } = await bobQuery({ input, driver, id });
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
- return { error };
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
- const result = await Promise.all(value.actions.map((action) => driver.querier(action, ...parameters)));
30
- if (result.length === 1) {
31
- return { value: (result[0].length ? result[0] : undefined) };
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 { value: undefined };
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.18",
3
+ "version": "0.0.20",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "",
@@ -28,11 +28,10 @@
28
28
  "typescript": "5.9.3"
29
29
  },
30
30
  "dependencies": {
31
- "@bob-kit/types": "^0.0.5"
31
+ "@bob-kit/types": "^0.0.6"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "tsc && tsc-alias",
35
- "postinstall": "node dist/install.js",
36
35
  "test": "echo \"Error: no test specified\" && exit 1"
37
36
  }
38
37
  }
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
- })();