@hybrd/utils 1.0.8 → 1.1.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 (42) hide show
  1. package/.cache/tsbuildinfo.json +1 -1
  2. package/.turbo/turbo-build.log +20 -2
  3. package/dist/index.cjs +261 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +152 -0
  6. package/dist/index.d.ts +152 -10
  7. package/dist/index.js +208 -9
  8. package/dist/index.js.map +1 -0
  9. package/package.json +31 -29
  10. package/tsconfig.json +8 -4
  11. package/tsup.config.ts +14 -0
  12. package/.turbo/turbo-lint$colon$fix.log +0 -6
  13. package/.turbo/turbo-lint.log +0 -6
  14. package/.turbo/turbo-typecheck.log +0 -5
  15. package/dist/index.d.ts.map +0 -1
  16. package/dist/lib/array.d.ts +0 -25
  17. package/dist/lib/array.d.ts.map +0 -1
  18. package/dist/lib/array.js +0 -32
  19. package/dist/lib/cloudflare.d.ts +0 -22
  20. package/dist/lib/cloudflare.d.ts.map +0 -1
  21. package/dist/lib/cloudflare.js +0 -53
  22. package/dist/lib/date.d.ts +0 -17
  23. package/dist/lib/date.d.ts.map +0 -1
  24. package/dist/lib/date.js +0 -37
  25. package/dist/lib/markdown.d.ts +0 -7
  26. package/dist/lib/markdown.d.ts.map +0 -1
  27. package/dist/lib/markdown.js +0 -11
  28. package/dist/lib/object.d.ts +0 -15
  29. package/dist/lib/object.d.ts.map +0 -1
  30. package/dist/lib/object.js +0 -42
  31. package/dist/lib/storage.d.ts +0 -24
  32. package/dist/lib/storage.d.ts.map +0 -1
  33. package/dist/lib/storage.js +0 -50
  34. package/dist/lib/string.d.ts +0 -11
  35. package/dist/lib/string.d.ts.map +0 -1
  36. package/dist/lib/string.js +0 -12
  37. package/dist/lib/urls.d.ts +0 -28
  38. package/dist/lib/urls.d.ts.map +0 -1
  39. package/dist/lib/urls.js +0 -36
  40. package/dist/lib/uuid.d.ts +0 -2
  41. package/dist/lib/uuid.d.ts.map +0 -1
  42. package/dist/lib/uuid.js +0 -6
@@ -1,42 +0,0 @@
1
- /**
2
- * Stringifies all values in an object, including objects and null values.
3
- * If obj is undefined, returns an empty object.
4
- * @param obj - The object to stringify
5
- * @returns A new object with the same keys as obj, but with all values stringified
6
- */
7
- export function stringifyValues(obj) {
8
- const result = {};
9
- if (!obj) {
10
- return {};
11
- }
12
- for (const key in obj) {
13
- const value = obj[key];
14
- result[key] =
15
- value === null
16
- ? "null"
17
- : typeof value === "object"
18
- ? JSON.stringify(value)
19
- : String(value);
20
- }
21
- return result;
22
- }
23
- /**
24
- * Removes empty values (undefined, null, empty strings) from an object
25
- *
26
- * @param obj - The object to prune
27
- * @returns A new object with empty values removed
28
- */
29
- export function pruneEmpty(obj) {
30
- if (!obj) {
31
- return {};
32
- }
33
- return Object.entries(obj).reduce((acc, [key, value]) => {
34
- // Skip undefined, null, and empty strings
35
- if (value === undefined || value === null || value === "") {
36
- return acc;
37
- }
38
- // Avoid spread syntax on accumulator
39
- acc[key] = value;
40
- return acc;
41
- }, {});
42
- }
@@ -1,24 +0,0 @@
1
- export interface StorageAdapter {
2
- uploadFile(localPath: string, remotePath: string): Promise<void>;
3
- downloadFile(remotePath: string, localPath: string): Promise<void>;
4
- exists(remotePath: string): Promise<boolean>;
5
- delete(remotePath: string): Promise<void>;
6
- }
7
- export declare class R2StorageAdapter implements StorageAdapter {
8
- private bucket;
9
- constructor(bucket: any);
10
- uploadFile(localPath: string, remotePath: string): Promise<void>;
11
- downloadFile(remotePath: string, localPath: string): Promise<void>;
12
- exists(remotePath: string): Promise<boolean>;
13
- delete(remotePath: string): Promise<void>;
14
- }
15
- export declare class ExternalDatabaseAdapter implements StorageAdapter {
16
- private connectionString;
17
- constructor(connectionString: string);
18
- uploadFile(localPath: string, remotePath: string): Promise<void>;
19
- downloadFile(remotePath: string, localPath: string): Promise<void>;
20
- exists(remotePath: string): Promise<boolean>;
21
- delete(remotePath: string): Promise<void>;
22
- }
23
- export declare function createStorageAdapter(): StorageAdapter | null;
24
- //# sourceMappingURL=storage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/lib/storage.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAChE,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAClE,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5C,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC1C;AAED,qBAAa,gBAAiB,YAAW,cAAc;IACzC,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,GAAG;IAEzB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKhE,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOlE,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK5C,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGhD;AAED,qBAAa,uBAAwB,YAAW,cAAc;IAChD,OAAO,CAAC,gBAAgB;gBAAhB,gBAAgB,EAAE,MAAM;IAEtC,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhE,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlE,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI5C,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAEhD;AAED,wBAAgB,oBAAoB,IAAI,cAAc,GAAG,IAAI,CAU5D"}
@@ -1,50 +0,0 @@
1
- import fs from "node:fs/promises";
2
- export class R2StorageAdapter {
3
- bucket;
4
- constructor(bucket) {
5
- this.bucket = bucket;
6
- }
7
- async uploadFile(localPath, remotePath) {
8
- const fileData = await fs.readFile(localPath);
9
- await this.bucket.put(remotePath, fileData);
10
- }
11
- async downloadFile(remotePath, localPath) {
12
- const object = await this.bucket.get(remotePath);
13
- if (object) {
14
- await fs.writeFile(localPath, await object.arrayBuffer());
15
- }
16
- }
17
- async exists(remotePath) {
18
- const object = await this.bucket.head(remotePath);
19
- return object !== null;
20
- }
21
- async delete(remotePath) {
22
- await this.bucket.delete(remotePath);
23
- }
24
- }
25
- export class ExternalDatabaseAdapter {
26
- connectionString;
27
- constructor(connectionString) {
28
- this.connectionString = connectionString;
29
- }
30
- async uploadFile(localPath, remotePath) {
31
- throw new Error('External database storage not yet implemented');
32
- }
33
- async downloadFile(remotePath, localPath) {
34
- throw new Error('External database storage not yet implemented');
35
- }
36
- async exists(remotePath) {
37
- return false;
38
- }
39
- async delete(remotePath) {
40
- }
41
- }
42
- export function createStorageAdapter() {
43
- if (typeof globalThis !== 'undefined' && 'XMTP_STORAGE' in globalThis) {
44
- return new R2StorageAdapter(globalThis.XMTP_STORAGE);
45
- }
46
- if (typeof process !== 'undefined' && process.env?.DATABASE_URL) {
47
- return new ExternalDatabaseAdapter(process.env.DATABASE_URL);
48
- }
49
- return null;
50
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Truncates a given string to a specified length, adding an ellipsis if the
3
- * string is longer than the specified length.
4
- *
5
- * @param {string} str - The string to truncate.
6
- * @param {number} length - The maximum length of the resulting string.
7
- *
8
- * @returns {string} The truncated string.
9
- */
10
- export declare function truncate(str: string, length: number): string;
11
- //# sourceMappingURL=string.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/lib/string.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAEnD"}
@@ -1,12 +0,0 @@
1
- /**
2
- * Truncates a given string to a specified length, adding an ellipsis if the
3
- * string is longer than the specified length.
4
- *
5
- * @param {string} str - The string to truncate.
6
- * @param {number} length - The maximum length of the resulting string.
7
- *
8
- * @returns {string} The truncated string.
9
- */
10
- export function truncate(str, length) {
11
- return str.length > length ? `${str.slice(0, length)}...` : str;
12
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * Get the agent application URL for webhooks and callbacks
3
- *
4
- * This function constructs the URL for the main agent application, used primarily
5
- * for QStash webhooks and external callbacks. It supports multiple deployment
6
- * environments with fallback logic.
7
- *
8
- * @param path - Optional path to append to the base URL (leading slashes are normalized)
9
- * @returns The complete URL for the agent application
10
- *
11
- * @example
12
- * ```typescript
13
- * // Get base URL
14
- * getUrl() // "http://localhost:8454/"
15
- *
16
- * // Get URL with path
17
- * getUrl("/qstash/webhook") // "http://localhost:8454/qstash/webhook"
18
- * getUrl("api/health") // "http://localhost:8454/api/health"
19
- * ```
20
- *
21
- * @remarks
22
- * URL resolution priority:
23
- * 1. `AGENT_URL` environment variable (custom deployment)
24
- * 2. `RAILWAY_PUBLIC_DOMAIN` environment variable (Railway deployment)
25
- * 3. `http://localhost:8454/` (default)
26
- */
27
- export declare function getUrl(path?: string): string;
28
- //# sourceMappingURL=urls.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"urls.d.ts","sourceRoot":"","sources":["../../src/lib/urls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,MAAM,CAAC,IAAI,SAAK,UAY/B"}
package/dist/lib/urls.js DELETED
@@ -1,36 +0,0 @@
1
- /**
2
- * Get the agent application URL for webhooks and callbacks
3
- *
4
- * This function constructs the URL for the main agent application, used primarily
5
- * for QStash webhooks and external callbacks. It supports multiple deployment
6
- * environments with fallback logic.
7
- *
8
- * @param path - Optional path to append to the base URL (leading slashes are normalized)
9
- * @returns The complete URL for the agent application
10
- *
11
- * @example
12
- * ```typescript
13
- * // Get base URL
14
- * getUrl() // "http://localhost:8454/"
15
- *
16
- * // Get URL with path
17
- * getUrl("/qstash/webhook") // "http://localhost:8454/qstash/webhook"
18
- * getUrl("api/health") // "http://localhost:8454/api/health"
19
- * ```
20
- *
21
- * @remarks
22
- * URL resolution priority:
23
- * 1. `AGENT_URL` environment variable (custom deployment)
24
- * 2. `RAILWAY_PUBLIC_DOMAIN` environment variable (Railway deployment)
25
- * 3. `http://localhost:8454/` (default)
26
- */
27
- export function getUrl(path = "") {
28
- const trimmedPath = path.replace(/^\/+/, "");
29
- if (process.env.AGENT_URL) {
30
- return `https://${process.env.AGENT_URL}/${trimmedPath}`;
31
- }
32
- if (process.env.RAILWAY_PUBLIC_DOMAIN) {
33
- return `https://${process.env.RAILWAY_PUBLIC_DOMAIN}/${trimmedPath}`;
34
- }
35
- return `https://localhost:8454/${trimmedPath}`;
36
- }
@@ -1,2 +0,0 @@
1
- export declare function randomUUID(): string;
2
- //# sourceMappingURL=uuid.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../src/lib/uuid.ts"],"names":[],"mappings":"AAIA,wBAAgB,UAAU,IAAI,MAAM,CAEnC"}
package/dist/lib/uuid.js DELETED
@@ -1,6 +0,0 @@
1
- import { v4 as uuidv4 } from "uuid";
2
- // The node:crypto version is not supported in the browser.
3
- // Use the uuid package instead.
4
- export function randomUUID() {
5
- return uuidv4();
6
- }