@voltagent/internal 0.0.2 → 0.0.4
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/dev/index.d.mts +2 -0
- package/dist/dev/index.d.ts +2 -0
- package/dist/dev/index.js +6 -2
- package/dist/dev/index.js.map +1 -1
- package/dist/dev/index.mjs +6 -2
- package/dist/dev/index.mjs.map +1 -1
- package/dist/main/index.d.mts +69 -2
- package/dist/main/index.d.ts +69 -2
- package/dist/main/index.js +57 -5
- package/dist/main/index.js.map +1 -1
- package/dist/main/index.mjs +50 -4
- package/dist/main/index.mjs.map +1 -1
- package/dist/types/index.d.mts +29 -0
- package/dist/types/index.d.ts +29 -0
- package/dist/utils/index.d.mts +67 -2
- package/dist/utils/index.d.ts +67 -2
- package/dist/utils/index.js +57 -5
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +50 -4
- package/dist/utils/index.mjs.map +1 -1
- package/package.json +6 -4
package/dist/dev/index.d.mts
CHANGED
|
@@ -52,6 +52,7 @@ declare function createDevLogger(options?: DevLoggerOptions): {
|
|
|
52
52
|
* @param args - The arguments to log.
|
|
53
53
|
*/
|
|
54
54
|
error: (message?: any, ...args: any[]) => void;
|
|
55
|
+
debug: (_message?: any, ..._args: any[]) => void;
|
|
55
56
|
};
|
|
56
57
|
declare const _default: {
|
|
57
58
|
/**
|
|
@@ -96,6 +97,7 @@ declare const _default: {
|
|
|
96
97
|
* @param args - The arguments to log.
|
|
97
98
|
*/
|
|
98
99
|
error: (message?: any, ...args: any[]) => void;
|
|
100
|
+
debug: (_message?: any, ..._args: any[]) => void;
|
|
99
101
|
};
|
|
100
102
|
|
|
101
103
|
export { type DevLoggerOptions, createDevLogger, _default as devLogger };
|
package/dist/dev/index.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ declare function createDevLogger(options?: DevLoggerOptions): {
|
|
|
52
52
|
* @param args - The arguments to log.
|
|
53
53
|
*/
|
|
54
54
|
error: (message?: any, ...args: any[]) => void;
|
|
55
|
+
debug: (_message?: any, ..._args: any[]) => void;
|
|
55
56
|
};
|
|
56
57
|
declare const _default: {
|
|
57
58
|
/**
|
|
@@ -96,6 +97,7 @@ declare const _default: {
|
|
|
96
97
|
* @param args - The arguments to log.
|
|
97
98
|
*/
|
|
98
99
|
error: (message?: any, ...args: any[]) => void;
|
|
100
|
+
debug: (_message?: any, ..._args: any[]) => void;
|
|
99
101
|
};
|
|
100
102
|
|
|
101
103
|
export { type DevLoggerOptions, createDevLogger, _default as devLogger };
|
package/dist/dev/index.js
CHANGED
|
@@ -86,13 +86,17 @@ function createDevLogger(options) {
|
|
|
86
86
|
if (isDev()) {
|
|
87
87
|
console.error(formatLogPrefix("ERROR"), message, ...args);
|
|
88
88
|
}
|
|
89
|
-
}, "error")
|
|
89
|
+
}, "error"),
|
|
90
|
+
debug: /* @__PURE__ */ __name((_message, ..._args) => {
|
|
91
|
+
return;
|
|
92
|
+
}, "debug")
|
|
90
93
|
};
|
|
91
94
|
}
|
|
92
95
|
__name(createDevLogger, "createDevLogger");
|
|
93
96
|
var logger_default = createDevLogger();
|
|
94
97
|
function isDevNodeEnv() {
|
|
95
|
-
|
|
98
|
+
const nodeEnv = process.env.NODE_ENV;
|
|
99
|
+
return nodeEnv !== "production" && nodeEnv !== "test" && nodeEnv !== "ci";
|
|
96
100
|
}
|
|
97
101
|
__name(isDevNodeEnv, "isDevNodeEnv");
|
|
98
102
|
function formatLogPrefix(level) {
|
package/dist/dev/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/dev/index.ts","../../src/dev/logger.ts"],"sourcesContent":["export { createDevLogger, default as devLogger } from \"./logger\";\nexport type { DevLoggerOptions } from \"./logger\";\n","export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n
|
|
1
|
+
{"version":3,"sources":["../../src/dev/index.ts","../../src/dev/logger.ts"],"sourcesContent":["export { createDevLogger, default as devLogger } from \"./logger\";\nexport type { DevLoggerOptions } from \"./logger\";\n","export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n\n debug: (_message?: any, ..._args: any[]) => {\n // todo: implement debug logging with pino\n return;\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n const nodeEnv = process.env.NODE_ENV;\n return nodeEnv !== \"production\" && nodeEnv !== \"test\" && nodeEnv !== \"ci\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\" | \"DEBUG\"): string {\n return `[VoltAgent] [${timestamp()}] ${level}: `;\n}\n\nfunction timestamp(): string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AgB,UAAU,CAAC,KAAK,KAAK;AAC9C;AAFS;AAIT,SAAS,YAAoB;AAC3B,UAAO,oBAAI,KAAK,GAAE,YAAY,EAAE,QAAQ,KAAK,GAAG,EAAE,MAAM,GAAG,EAAE;AAC/D;AAFS;","names":[]}
|
package/dist/dev/index.mjs
CHANGED
|
@@ -61,13 +61,17 @@ function createDevLogger(options) {
|
|
|
61
61
|
if (isDev()) {
|
|
62
62
|
console.error(formatLogPrefix("ERROR"), message, ...args);
|
|
63
63
|
}
|
|
64
|
-
}, "error")
|
|
64
|
+
}, "error"),
|
|
65
|
+
debug: /* @__PURE__ */ __name((_message, ..._args) => {
|
|
66
|
+
return;
|
|
67
|
+
}, "debug")
|
|
65
68
|
};
|
|
66
69
|
}
|
|
67
70
|
__name(createDevLogger, "createDevLogger");
|
|
68
71
|
var logger_default = createDevLogger();
|
|
69
72
|
function isDevNodeEnv() {
|
|
70
|
-
|
|
73
|
+
const nodeEnv = process.env.NODE_ENV;
|
|
74
|
+
return nodeEnv !== "production" && nodeEnv !== "test" && nodeEnv !== "ci";
|
|
71
75
|
}
|
|
72
76
|
__name(isDevNodeEnv, "isDevNodeEnv");
|
|
73
77
|
function formatLogPrefix(level) {
|
package/dist/dev/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/dev/logger.ts"],"sourcesContent":["export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n
|
|
1
|
+
{"version":3,"sources":["../../src/dev/logger.ts"],"sourcesContent":["export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n\n debug: (_message?: any, ..._args: any[]) => {\n // todo: implement debug logging with pino\n return;\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n const nodeEnv = process.env.NODE_ENV;\n return nodeEnv !== \"production\" && nodeEnv !== \"test\" && nodeEnv !== \"ci\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\" | \"DEBUG\"): string {\n return `[VoltAgent] [${timestamp()}] ${level}: `;\n}\n\nfunction timestamp(): string {\n return new Date().toISOString().replace(\"T\", \" \").slice(0, -1);\n}\n"],"mappings":";;;;AAYO,SAAS,gBAAgB,SAA4B;AAC1D,QAAM,QACJ,QAAO,mCAAS,SAAQ,aAAa,QAAQ,MAAM,MAAG;AAd1D;AAc6D,oDAAS,QAAT,YAAgB,aAAa;AAAA;AAExF,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAcL,MAAM,wBA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 declare function createDevLogger(options?: DevLoggerOptions): {
|
|
|
52
54
|
* @param args - The arguments to log.
|
|
53
55
|
*/
|
|
54
56
|
error: (message?: any, ...args: any[]) => void;
|
|
57
|
+
debug: (_message?: any, ..._args: any[]) => void;
|
|
55
58
|
};
|
|
56
59
|
declare const _default: {
|
|
57
60
|
/**
|
|
@@ -96,6 +99,7 @@ declare const _default: {
|
|
|
96
99
|
* @param args - The arguments to log.
|
|
97
100
|
*/
|
|
98
101
|
error: (message?: any, ...args: any[]) => void;
|
|
102
|
+
debug: (_message?: any, ..._args: any[]) => void;
|
|
99
103
|
};
|
|
100
104
|
|
|
101
105
|
/**
|
|
@@ -130,8 +134,27 @@ declare function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T>
|
|
|
130
134
|
declare function convertResponseStreamToArray(response: Response): Promise<string[]>;
|
|
131
135
|
|
|
132
136
|
/**
|
|
133
|
-
*
|
|
137
|
+
* A plain object is an object that has no special properties or methods,
|
|
138
|
+
* and just has properties that are strings, numbers, or symbols.
|
|
139
|
+
*/
|
|
140
|
+
type PlainObject = Record<string | number | symbol, unknown>;
|
|
141
|
+
/**
|
|
142
|
+
* A nil value is a value that is not defined or is undefined.
|
|
143
|
+
*/
|
|
144
|
+
type Nil = null | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* A type that represents any async function.
|
|
147
|
+
*/
|
|
148
|
+
type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
|
|
149
|
+
/**
|
|
150
|
+
* A type that represents any synchronous function.
|
|
134
151
|
*/
|
|
152
|
+
type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
153
|
+
/**
|
|
154
|
+
* A type that represents any function.
|
|
155
|
+
*/
|
|
156
|
+
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
157
|
+
|
|
135
158
|
/**
|
|
136
159
|
* Deep clone an object using JSON serialization with fallback to shallow clone
|
|
137
160
|
*
|
|
@@ -139,5 +162,49 @@ declare function convertResponseStreamToArray(response: Response): Promise<strin
|
|
|
139
162
|
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
140
163
|
*/
|
|
141
164
|
declare function deepClone<T>(obj: T): T;
|
|
165
|
+
/**
|
|
166
|
+
* Check if an object has a key
|
|
167
|
+
*
|
|
168
|
+
* @param obj - The object to check
|
|
169
|
+
* @param key - The key to check
|
|
170
|
+
* @returns True if the object has the key, false otherwise
|
|
171
|
+
*/
|
|
172
|
+
declare function hasKey<T extends PlainObject, K extends string>(obj: T, key: K): obj is T & SetRequired<T, K>;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Check if a value is nil
|
|
176
|
+
*
|
|
177
|
+
* @param obj - The value to check
|
|
178
|
+
* @returns True if the value is nil, false otherwise
|
|
179
|
+
*/
|
|
180
|
+
declare function isNil(obj: unknown): obj is Nil;
|
|
181
|
+
/**
|
|
182
|
+
* Check if an object is a JS object
|
|
183
|
+
*
|
|
184
|
+
* @param obj - The object to check
|
|
185
|
+
* @returns True if the object is a JS object}
|
|
186
|
+
*/
|
|
187
|
+
declare function isObject<T extends object>(obj: unknown): obj is T;
|
|
188
|
+
/**
|
|
189
|
+
* Check if a value is a function
|
|
190
|
+
*
|
|
191
|
+
* @param obj - The value to check
|
|
192
|
+
* @returns True if the value is a function, false otherwise
|
|
193
|
+
*/
|
|
194
|
+
declare function isFunction<T extends AnyFunction>(obj: unknown): obj is T;
|
|
195
|
+
/**
|
|
196
|
+
* Check if an object is a plain object (i.e. a JS object but not including arrays or functions)
|
|
197
|
+
*
|
|
198
|
+
* @param obj - The object to check
|
|
199
|
+
* @returns True if the object is a plain object, false otherwise.
|
|
200
|
+
*/
|
|
201
|
+
declare function isPlainObject<T extends PlainObject>(obj: unknown): obj is T;
|
|
202
|
+
/**
|
|
203
|
+
* Check if an object is an empty object
|
|
204
|
+
*
|
|
205
|
+
* @param obj - The object to check
|
|
206
|
+
* @returns True if the object is an empty object, false otherwise
|
|
207
|
+
*/
|
|
208
|
+
declare function isEmptyObject(obj: unknown): obj is EmptyObject;
|
|
142
209
|
|
|
143
|
-
export { type DevLoggerOptions, convertArrayToAsyncIterable, convertArrayToReadableStream, convertAsyncIterableToArray, convertReadableStreamToArray, convertResponseStreamToArray, createDevLogger, deepClone, _default as devLogger };
|
|
210
|
+
export { type DevLoggerOptions, convertArrayToAsyncIterable, convertArrayToReadableStream, convertAsyncIterableToArray, convertReadableStreamToArray, convertResponseStreamToArray, createDevLogger, deepClone, _default as devLogger, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject };
|
package/dist/main/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SetRequired, EmptyObject } from 'type-fest';
|
|
2
|
+
|
|
1
3
|
interface DevLoggerOptions {
|
|
2
4
|
dev: boolean | (() => boolean);
|
|
3
5
|
}
|
|
@@ -52,6 +54,7 @@ declare function createDevLogger(options?: DevLoggerOptions): {
|
|
|
52
54
|
* @param args - The arguments to log.
|
|
53
55
|
*/
|
|
54
56
|
error: (message?: any, ...args: any[]) => void;
|
|
57
|
+
debug: (_message?: any, ..._args: any[]) => void;
|
|
55
58
|
};
|
|
56
59
|
declare const _default: {
|
|
57
60
|
/**
|
|
@@ -96,6 +99,7 @@ declare const _default: {
|
|
|
96
99
|
* @param args - The arguments to log.
|
|
97
100
|
*/
|
|
98
101
|
error: (message?: any, ...args: any[]) => void;
|
|
102
|
+
debug: (_message?: any, ..._args: any[]) => void;
|
|
99
103
|
};
|
|
100
104
|
|
|
101
105
|
/**
|
|
@@ -130,8 +134,27 @@ declare function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T>
|
|
|
130
134
|
declare function convertResponseStreamToArray(response: Response): Promise<string[]>;
|
|
131
135
|
|
|
132
136
|
/**
|
|
133
|
-
*
|
|
137
|
+
* A plain object is an object that has no special properties or methods,
|
|
138
|
+
* and just has properties that are strings, numbers, or symbols.
|
|
139
|
+
*/
|
|
140
|
+
type PlainObject = Record<string | number | symbol, unknown>;
|
|
141
|
+
/**
|
|
142
|
+
* A nil value is a value that is not defined or is undefined.
|
|
143
|
+
*/
|
|
144
|
+
type Nil = null | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* A type that represents any async function.
|
|
147
|
+
*/
|
|
148
|
+
type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
|
|
149
|
+
/**
|
|
150
|
+
* A type that represents any synchronous function.
|
|
134
151
|
*/
|
|
152
|
+
type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
153
|
+
/**
|
|
154
|
+
* A type that represents any function.
|
|
155
|
+
*/
|
|
156
|
+
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
157
|
+
|
|
135
158
|
/**
|
|
136
159
|
* Deep clone an object using JSON serialization with fallback to shallow clone
|
|
137
160
|
*
|
|
@@ -139,5 +162,49 @@ declare function convertResponseStreamToArray(response: Response): Promise<strin
|
|
|
139
162
|
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
140
163
|
*/
|
|
141
164
|
declare function deepClone<T>(obj: T): T;
|
|
165
|
+
/**
|
|
166
|
+
* Check if an object has a key
|
|
167
|
+
*
|
|
168
|
+
* @param obj - The object to check
|
|
169
|
+
* @param key - The key to check
|
|
170
|
+
* @returns True if the object has the key, false otherwise
|
|
171
|
+
*/
|
|
172
|
+
declare function hasKey<T extends PlainObject, K extends string>(obj: T, key: K): obj is T & SetRequired<T, K>;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Check if a value is nil
|
|
176
|
+
*
|
|
177
|
+
* @param obj - The value to check
|
|
178
|
+
* @returns True if the value is nil, false otherwise
|
|
179
|
+
*/
|
|
180
|
+
declare function isNil(obj: unknown): obj is Nil;
|
|
181
|
+
/**
|
|
182
|
+
* Check if an object is a JS object
|
|
183
|
+
*
|
|
184
|
+
* @param obj - The object to check
|
|
185
|
+
* @returns True if the object is a JS object}
|
|
186
|
+
*/
|
|
187
|
+
declare function isObject<T extends object>(obj: unknown): obj is T;
|
|
188
|
+
/**
|
|
189
|
+
* Check if a value is a function
|
|
190
|
+
*
|
|
191
|
+
* @param obj - The value to check
|
|
192
|
+
* @returns True if the value is a function, false otherwise
|
|
193
|
+
*/
|
|
194
|
+
declare function isFunction<T extends AnyFunction>(obj: unknown): obj is T;
|
|
195
|
+
/**
|
|
196
|
+
* Check if an object is a plain object (i.e. a JS object but not including arrays or functions)
|
|
197
|
+
*
|
|
198
|
+
* @param obj - The object to check
|
|
199
|
+
* @returns True if the object is a plain object, false otherwise.
|
|
200
|
+
*/
|
|
201
|
+
declare function isPlainObject<T extends PlainObject>(obj: unknown): obj is T;
|
|
202
|
+
/**
|
|
203
|
+
* Check if an object is an empty object
|
|
204
|
+
*
|
|
205
|
+
* @param obj - The object to check
|
|
206
|
+
* @returns True if the object is an empty object, false otherwise
|
|
207
|
+
*/
|
|
208
|
+
declare function isEmptyObject(obj: unknown): obj is EmptyObject;
|
|
142
209
|
|
|
143
|
-
export { type DevLoggerOptions, convertArrayToAsyncIterable, convertArrayToReadableStream, convertAsyncIterableToArray, convertReadableStreamToArray, convertResponseStreamToArray, createDevLogger, deepClone, _default as devLogger };
|
|
210
|
+
export { type DevLoggerOptions, convertArrayToAsyncIterable, convertArrayToReadableStream, convertAsyncIterableToArray, convertReadableStreamToArray, convertResponseStreamToArray, createDevLogger, deepClone, _default as devLogger, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject };
|
package/dist/main/index.js
CHANGED
|
@@ -79,7 +79,13 @@ __export(index_exports, {
|
|
|
79
79
|
convertResponseStreamToArray: () => convertResponseStreamToArray,
|
|
80
80
|
createDevLogger: () => createDevLogger,
|
|
81
81
|
deepClone: () => deepClone,
|
|
82
|
-
devLogger: () => logger_default
|
|
82
|
+
devLogger: () => logger_default,
|
|
83
|
+
hasKey: () => hasKey,
|
|
84
|
+
isEmptyObject: () => isEmptyObject,
|
|
85
|
+
isFunction: () => isFunction,
|
|
86
|
+
isNil: () => isNil,
|
|
87
|
+
isObject: () => isObject,
|
|
88
|
+
isPlainObject: () => isPlainObject
|
|
83
89
|
});
|
|
84
90
|
module.exports = __toCommonJS(index_exports);
|
|
85
91
|
|
|
@@ -143,13 +149,17 @@ function createDevLogger(options) {
|
|
|
143
149
|
if (isDev()) {
|
|
144
150
|
console.error(formatLogPrefix("ERROR"), message, ...args);
|
|
145
151
|
}
|
|
146
|
-
}, "error")
|
|
152
|
+
}, "error"),
|
|
153
|
+
debug: /* @__PURE__ */ __name((_message, ..._args) => {
|
|
154
|
+
return;
|
|
155
|
+
}, "debug")
|
|
147
156
|
};
|
|
148
157
|
}
|
|
149
158
|
__name(createDevLogger, "createDevLogger");
|
|
150
159
|
var logger_default = createDevLogger();
|
|
151
160
|
function isDevNodeEnv() {
|
|
152
|
-
|
|
161
|
+
const nodeEnv = process.env.NODE_ENV;
|
|
162
|
+
return nodeEnv !== "production" && nodeEnv !== "test" && nodeEnv !== "ci";
|
|
153
163
|
}
|
|
154
164
|
__name(isDevNodeEnv, "isDevNodeEnv");
|
|
155
165
|
function formatLogPrefix(level) {
|
|
@@ -230,7 +240,39 @@ function convertResponseStreamToArray(response) {
|
|
|
230
240
|
}
|
|
231
241
|
__name(convertResponseStreamToArray, "convertResponseStreamToArray");
|
|
232
242
|
|
|
233
|
-
// src/utils/
|
|
243
|
+
// src/utils/lang.ts
|
|
244
|
+
function isNil(obj) {
|
|
245
|
+
return obj === null || obj === void 0;
|
|
246
|
+
}
|
|
247
|
+
__name(isNil, "isNil");
|
|
248
|
+
function isObject(obj) {
|
|
249
|
+
return (typeof obj === "object" || typeof obj === "function") && !isNil(obj);
|
|
250
|
+
}
|
|
251
|
+
__name(isObject, "isObject");
|
|
252
|
+
function isFunction(obj) {
|
|
253
|
+
return typeof obj === "function";
|
|
254
|
+
}
|
|
255
|
+
__name(isFunction, "isFunction");
|
|
256
|
+
function isPlainObject(obj) {
|
|
257
|
+
if (!isObject(obj)) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
const prototype = Object.getPrototypeOf(obj);
|
|
261
|
+
return prototype === Object.prototype || prototype === null;
|
|
262
|
+
}
|
|
263
|
+
__name(isPlainObject, "isPlainObject");
|
|
264
|
+
function isEmptyObject(obj) {
|
|
265
|
+
if (!isObject(obj)) {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
__name(isEmptyObject, "isEmptyObject");
|
|
274
|
+
|
|
275
|
+
// src/utils/objects.ts
|
|
234
276
|
function deepClone(obj) {
|
|
235
277
|
try {
|
|
236
278
|
return JSON.parse(JSON.stringify(obj));
|
|
@@ -243,6 +285,10 @@ function deepClone(obj) {
|
|
|
243
285
|
}
|
|
244
286
|
}
|
|
245
287
|
__name(deepClone, "deepClone");
|
|
288
|
+
function hasKey(obj, key) {
|
|
289
|
+
return isObject(obj) && key in obj;
|
|
290
|
+
}
|
|
291
|
+
__name(hasKey, "hasKey");
|
|
246
292
|
// Annotate the CommonJS export names for ESM import in node:
|
|
247
293
|
0 && (module.exports = {
|
|
248
294
|
convertArrayToAsyncIterable,
|
|
@@ -252,6 +298,12 @@ __name(deepClone, "deepClone");
|
|
|
252
298
|
convertResponseStreamToArray,
|
|
253
299
|
createDevLogger,
|
|
254
300
|
deepClone,
|
|
255
|
-
devLogger
|
|
301
|
+
devLogger,
|
|
302
|
+
hasKey,
|
|
303
|
+
isEmptyObject,
|
|
304
|
+
isFunction,
|
|
305
|
+
isNil,
|
|
306
|
+
isObject,
|
|
307
|
+
isPlainObject
|
|
256
308
|
});
|
|
257
309
|
//# sourceMappingURL=index.js.map
|
package/dist/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/dev/logger.ts","../../src/test/conversions.ts","../../src/utils/object-utils.ts"],"sourcesContent":["export * from \"./dev\";\nexport * from \"./test\";\nexport * from \"./utils\";\n","export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n return process.env.NODE_ENV === \"development\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\"): string {\n return `[VoltAgent] [${timestamp()}] ${level}: `;\n}\n\nfunction timestamp(): string {\n return new Date().toISOString().replace(\"T\", \" \").slice(0, -1);\n}\n","/**\n * Convert a readable stream to an array\n * @param stream - The readable stream to convert\n * @returns The array of values\n */\nexport async function convertReadableStreamToArray<T>(stream: ReadableStream<T>): Promise<T[]> {\n const reader = stream.getReader();\n const result: T[] = [];\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n result.push(value);\n }\n\n return result;\n}\n\n/**\n * Convert an array to an async iterable\n * @param values - The array to convert\n * @returns The async iterable\n */\nexport function convertArrayToAsyncIterable<T>(values: T[]): AsyncIterable<T> {\n return {\n async *[Symbol.asyncIterator]() {\n for (const value of values) {\n yield value;\n }\n },\n };\n}\n\n/**\n * Convert an async iterable to an array\n * @param iterable - The async iterable to convert\n * @returns The array of values\n */\nexport async function convertAsyncIterableToArray<T>(iterable: AsyncIterable<T>): Promise<T[]> {\n const result: T[] = [];\n for await (const item of iterable) {\n result.push(item);\n }\n return result;\n}\n\n/**\n * Convert an array to a readable stream\n * @param values - The array to convert\n * @returns The readable stream\n */\nexport function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T> {\n return new ReadableStream({\n start(controller) {\n try {\n for (const value of values) {\n controller.enqueue(value);\n }\n } finally {\n controller.close();\n }\n },\n });\n}\n\n/**\n * Convert a response stream to an array\n * @param response - The response to convert\n * @returns The array of values\n */\nexport async function convertResponseStreamToArray(response: Response): Promise<string[]> {\n // biome-ignore lint/style/noNonNullAssertion: ignore this\n return convertReadableStreamToArray(response.body!.pipeThrough(new TextDecoderStream()));\n}\n","/**\n * Object manipulation utility functions\n */\n\nimport { devLogger } from \"../dev\";\n\n/**\n * Deep clone an object using JSON serialization with fallback to shallow clone\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object, or shallow copy if JSON serialization fails\n */\nexport function deepClone<T>(obj: T): T {\n try {\n return JSON.parse(JSON.stringify(obj));\n } catch (error) {\n devLogger.warn(\"Failed to deep clone object, using shallow clone:\", error);\n // Fallback to shallow cl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AAHsB;;;AC1Df,SAAS,UAAa,KAAW;AACtC,MAAI;AACF,WAAO,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;AAAA,EACvC,SAAS,OAAO;AACd,mBAAU,KAAK,qDAAqD,KAAK;AAEzE,QAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC3C,aAAO;AAAA,IACT;AACA,WAAO,mBAAK;AAAA,EACd;AACF;AAXgB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/dev/logger.ts","../../src/test/conversions.ts","../../src/utils/lang.ts","../../src/utils/objects.ts"],"sourcesContent":["export * from \"./dev\";\nexport * from \"./test\";\nexport * from \"./utils\";\n","export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n\n debug: (_message?: any, ..._args: any[]) => {\n // todo: implement debug logging with pino\n return;\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n const nodeEnv = process.env.NODE_ENV;\n return nodeEnv !== \"production\" && nodeEnv !== \"test\" && nodeEnv !== \"ci\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\" | \"DEBUG\"): string {\n return `[VoltAgent] [${timestamp()}] ${level}: `;\n}\n\nfunction timestamp(): string {\n return new Date().toISOString().replace(\"T\", \" \").slice(0, -1);\n}\n","/**\n * Convert a readable stream to an array\n * @param stream - The readable stream to convert\n * @returns The array of values\n */\nexport async function convertReadableStreamToArray<T>(stream: ReadableStream<T>): Promise<T[]> {\n const reader = stream.getReader();\n const result: T[] = [];\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n result.push(value);\n }\n\n return result;\n}\n\n/**\n * Convert an array to an async iterable\n * @param values - The array to convert\n * @returns The async iterable\n */\nexport function convertArrayToAsyncIterable<T>(values: T[]): AsyncIterable<T> {\n return {\n async *[Symbol.asyncIterator]() {\n for (const value of values) {\n yield value;\n }\n },\n };\n}\n\n/**\n * Convert an async iterable to an array\n * @param iterable - The async iterable to convert\n * @returns The array of values\n */\nexport async function convertAsyncIterableToArray<T>(iterable: AsyncIterable<T>): Promise<T[]> {\n const result: T[] = [];\n for await (const item of iterable) {\n result.push(item);\n }\n return result;\n}\n\n/**\n * Convert an array to a readable stream\n * @param values - The array to convert\n * @returns The readable stream\n */\nexport function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T> {\n return new ReadableStream({\n start(controller) {\n try {\n for (const value of values) {\n controller.enqueue(value);\n }\n } finally {\n controller.close();\n }\n },\n });\n}\n\n/**\n * Convert a response stream to an array\n * @param response - The response to convert\n * @returns The array of values\n */\nexport async function convertResponseStreamToArray(response: Response): Promise<string[]> {\n // biome-ignore lint/style/noNonNullAssertion: ignore this\n return convertReadableStreamToArray(response.body!.pipeThrough(new TextDecoderStream()));\n}\n","import type { EmptyObject } from \"type-fest\";\nimport type { AnyFunction, Nil, PlainObject } from \"../types\";\n\n/**\n * Check if a value is nil\n *\n * @param obj - The value to check\n * @returns True if the value is nil, false otherwise\n */\nexport function isNil(obj: unknown): obj is Nil {\n return obj === null || obj === undefined;\n}\n\n/**\n * Check if an object is a JS object\n *\n * @param obj - The object to check\n * @returns True if the object is a JS object}\n */\nexport function isObject<T extends object>(obj: unknown): obj is T {\n return (typeof obj === \"object\" || typeof obj === \"function\") && !isNil(obj);\n}\n\n/**\n * Check if a value is a function\n *\n * @param obj - The value to check\n * @returns True if the value is a function, false otherwise\n */\nexport function isFunction<T extends AnyFunction>(obj: unknown): obj is T {\n return typeof obj === \"function\";\n}\n\n/**\n * Check if an object is a plain object (i.e. a JS object but not including arrays or functions)\n *\n * @param obj - The object to check\n * @returns True if the object is a plain object, false otherwise.\n */\nexport function isPlainObject<T extends PlainObject>(obj: unknown): obj is T {\n if (!isObject(obj)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Check if an object is an empty object\n *\n * @param obj - The object to check\n * @returns True if the object is an empty object, false otherwise\n */\nexport function isEmptyObject(obj: unknown): obj is EmptyObject {\n if (!isObject(obj)) {\n return false;\n }\n\n // Check for own string and symbol properties (enumerable or not)\n if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {\n return false;\n }\n\n return true;\n}\n","import type { SetRequired } from \"type-fest\";\nimport { devLogger } from \"../dev\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object using JSON serialization with fallback to shallow clone\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object, or shallow copy if JSON serialization fails\n */\nexport function deepClone<T>(obj: T): T {\n try {\n return JSON.parse(JSON.stringify(obj));\n } catch (error) {\n devLogger.warn(\"Failed to deep clone object, using shallow clone:\", error);\n // Fallback to shallow clone for primitive types and simple objects\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n return { ...obj } as T;\n }\n}\n\n/**\n * Check if an object has a key\n *\n * @param obj - The object to check\n * @param key - The key to check\n * @returns True if the object has the key, false otherwise\n */\nexport function hasKey<T extends PlainObject, K extends string>(\n obj: T,\n key: K,\n): obj is T & SetRequired<T, K> {\n return isObject(obj) && key in obj;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYO,SAAS,gBAAgB,SAA4B;AAC1D,QAAM,QACJ,QAAO,mCAAS,SAAQ,aAAa,QAAQ,MAAM,MAAG;AAd1D;AAc6D,oDAAS,QAAT,YAAgB,aAAa;AAAA;AAExF,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAcL,MAAM,wBAAC,YAAkB,SAAgB;AACvC,UAAI,MAAM,GAAG;AACX,gBAAQ,KAAK,gBAAgB,MAAM,GAAG,SAAS,GAAG,IAAI;AAAA,MACxD;AAAA,IACF,GAJM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAkBN,MAAM,wBAAC,YAAkB,SAAgB;AACvC,UAAI,MAAM,GAAG;AACX,g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T,SAAS,UAAa,KAAW;AACtC,MAAI;AACF,WAAO,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;AAAA,EACvC,SAAS,OAAO;AACd,mBAAU,KAAK,qDAAqD,KAAK;AAEzE,QAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC3C,aAAO;AAAA,IACT;AACA,WAAO,mBAAK;AAAA,EACd;AACF;AAXgB;AAoBT,SAAS,OACd,KACA,KAC8B;AAC9B,SAAO,SAAS,GAAG,KAAK,OAAO;AACjC;AALgB;","names":[]}
|
package/dist/main/index.mjs
CHANGED
|
@@ -113,13 +113,17 @@ function createDevLogger(options) {
|
|
|
113
113
|
if (isDev()) {
|
|
114
114
|
console.error(formatLogPrefix("ERROR"), message, ...args);
|
|
115
115
|
}
|
|
116
|
-
}, "error")
|
|
116
|
+
}, "error"),
|
|
117
|
+
debug: /* @__PURE__ */ __name((_message, ..._args) => {
|
|
118
|
+
return;
|
|
119
|
+
}, "debug")
|
|
117
120
|
};
|
|
118
121
|
}
|
|
119
122
|
__name(createDevLogger, "createDevLogger");
|
|
120
123
|
var logger_default = createDevLogger();
|
|
121
124
|
function isDevNodeEnv() {
|
|
122
|
-
|
|
125
|
+
const nodeEnv = process.env.NODE_ENV;
|
|
126
|
+
return nodeEnv !== "production" && nodeEnv !== "test" && nodeEnv !== "ci";
|
|
123
127
|
}
|
|
124
128
|
__name(isDevNodeEnv, "isDevNodeEnv");
|
|
125
129
|
function formatLogPrefix(level) {
|
|
@@ -200,7 +204,39 @@ function convertResponseStreamToArray(response) {
|
|
|
200
204
|
}
|
|
201
205
|
__name(convertResponseStreamToArray, "convertResponseStreamToArray");
|
|
202
206
|
|
|
203
|
-
// src/utils/
|
|
207
|
+
// src/utils/lang.ts
|
|
208
|
+
function isNil(obj) {
|
|
209
|
+
return obj === null || obj === void 0;
|
|
210
|
+
}
|
|
211
|
+
__name(isNil, "isNil");
|
|
212
|
+
function isObject(obj) {
|
|
213
|
+
return (typeof obj === "object" || typeof obj === "function") && !isNil(obj);
|
|
214
|
+
}
|
|
215
|
+
__name(isObject, "isObject");
|
|
216
|
+
function isFunction(obj) {
|
|
217
|
+
return typeof obj === "function";
|
|
218
|
+
}
|
|
219
|
+
__name(isFunction, "isFunction");
|
|
220
|
+
function isPlainObject(obj) {
|
|
221
|
+
if (!isObject(obj)) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
const prototype = Object.getPrototypeOf(obj);
|
|
225
|
+
return prototype === Object.prototype || prototype === null;
|
|
226
|
+
}
|
|
227
|
+
__name(isPlainObject, "isPlainObject");
|
|
228
|
+
function isEmptyObject(obj) {
|
|
229
|
+
if (!isObject(obj)) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
__name(isEmptyObject, "isEmptyObject");
|
|
238
|
+
|
|
239
|
+
// src/utils/objects.ts
|
|
204
240
|
function deepClone(obj) {
|
|
205
241
|
try {
|
|
206
242
|
return JSON.parse(JSON.stringify(obj));
|
|
@@ -213,6 +249,10 @@ function deepClone(obj) {
|
|
|
213
249
|
}
|
|
214
250
|
}
|
|
215
251
|
__name(deepClone, "deepClone");
|
|
252
|
+
function hasKey(obj, key) {
|
|
253
|
+
return isObject(obj) && key in obj;
|
|
254
|
+
}
|
|
255
|
+
__name(hasKey, "hasKey");
|
|
216
256
|
export {
|
|
217
257
|
convertArrayToAsyncIterable,
|
|
218
258
|
convertArrayToReadableStream,
|
|
@@ -221,6 +261,12 @@ export {
|
|
|
221
261
|
convertResponseStreamToArray,
|
|
222
262
|
createDevLogger,
|
|
223
263
|
deepClone,
|
|
224
|
-
logger_default as devLogger
|
|
264
|
+
logger_default as devLogger,
|
|
265
|
+
hasKey,
|
|
266
|
+
isEmptyObject,
|
|
267
|
+
isFunction,
|
|
268
|
+
isNil,
|
|
269
|
+
isObject,
|
|
270
|
+
isPlainObject
|
|
225
271
|
};
|
|
226
272
|
//# sourceMappingURL=index.mjs.map
|
package/dist/main/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/dev/logger.ts","../../src/test/conversions.ts","../../src/utils/object-utils.ts"],"sourcesContent":["export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n return process.env.NODE_ENV === \"development\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\"): string {\n return `[VoltAgent] [${timestamp()}] ${level}: `;\n}\n\nfunction timestamp(): string {\n return new Date().toISOString().replace(\"T\", \" \").slice(0, -1);\n}\n","/**\n * Convert a readable stream to an array\n * @param stream - The readable stream to convert\n * @returns The array of values\n */\nexport async function convertReadableStreamToArray<T>(stream: ReadableStream<T>): Promise<T[]> {\n const reader = stream.getReader();\n const result: T[] = [];\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n result.push(value);\n }\n\n return result;\n}\n\n/**\n * Convert an array to an async iterable\n * @param values - The array to convert\n * @returns The async iterable\n */\nexport function convertArrayToAsyncIterable<T>(values: T[]): AsyncIterable<T> {\n return {\n async *[Symbol.asyncIterator]() {\n for (const value of values) {\n yield value;\n }\n },\n };\n}\n\n/**\n * Convert an async iterable to an array\n * @param iterable - The async iterable to convert\n * @returns The array of values\n */\nexport async function convertAsyncIterableToArray<T>(iterable: AsyncIterable<T>): Promise<T[]> {\n const result: T[] = [];\n for await (const item of iterable) {\n result.push(item);\n }\n return result;\n}\n\n/**\n * Convert an array to a readable stream\n * @param values - The array to convert\n * @returns The readable stream\n */\nexport function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T> {\n return new ReadableStream({\n start(controller) {\n try {\n for (const value of values) {\n controller.enqueue(value);\n }\n } finally {\n controller.close();\n }\n },\n });\n}\n\n/**\n * Convert a response stream to an array\n * @param response - The response to convert\n * @returns The array of values\n */\nexport async function convertResponseStreamToArray(response: Response): Promise<string[]> {\n // biome-ignore lint/style/noNonNullAssertion: ignore this\n return convertReadableStreamToArray(response.body!.pipeThrough(new TextDecoderStream()));\n}\n","/**\n * Object manipulation utility functions\n */\n\nimport { devLogger } from \"../dev\";\n\n/**\n * Deep clone an object using JSON serialization with fallback to shallow clone\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object, or shallow copy if JSON serialization fails\n */\nexport function deepClone<T>(obj: T): T {\n try {\n return JSON.parse(JSON.stringify(obj));\n } catch (error) {\n devLogger.warn(\"Failed to deep clone object, using shallow clone:\", error);\n // Fallback to shallow clone for primitive types and simple objects\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n return { ...obj } as T;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYO,SAAS,gBAAgB,SAA4B;AAC1D,QAAM,QACJ,QAAO,mCAAS,SAAQ,aAAa,QAAQ,MAAM,MAAG;AAd1D;AAc6D,oDAAS,QAAT,YAAgB,aAAa;AAAA;AAExF,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAcL,MAAM,wBAAC,YAAkB,SAAgB;AACvC,UAAI,MAAM,GAAG;AACX,gBAAQ,KAAK,gBAAgB,MAAM,GAAG,SAAS,GAAG,IAAI;AAAA,MACxD;AAAA,IACF,GAJM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAkBN,MAAM,wBAAC,YAAkB,SAAgB;AACvC,UAAI,MAAM,GAAG;AACX,gBAAQ,KAAK,gBAAgB,MAAM,GAAG,SAAS,GAAG,IAAI;AAAA,MACxD;AAAA,IACF,GAJM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAkBN,OAAO,wBAAC,YAAkB,SAAgB;AACxC,UAAI,MAAM,GAAG;AACX,gBAAQ,MAAM,gBAAgB,OAAO,GAAG,SAAS,GAAG,IAAI;AAAA,MAC1D;AAAA,IACF,GAJO;AAAA,EAKT;AACF;AA5DgB;A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AAmBhB,SAAsB,6BAA6B,UAAuC;AAAA;AAExF,WAAO,6BAA6B,SAAS,KAAM,YAAY,IAAI,kBAAkB,CAAC,CAAC;AAAA,EACzF;AAAA;AAHsB;;;AC1Df,SAAS,UAAa,KAAW;AACtC,MAAI;AACF,WAAO,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;AAAA,EACvC,SAAS,OAAO;AACd,mBAAU,KAAK,qDAAqD,KAAK;AAEzE,QAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC3C,aAAO;AAAA,IACT;AACA,WAAO,mBAAK;AAAA,EACd;AACF;AAXgB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/dev/logger.ts","../../src/test/conversions.ts","../../src/utils/lang.ts","../../src/utils/objects.ts"],"sourcesContent":["export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n\n debug: (_message?: any, ..._args: any[]) => {\n // todo: implement debug logging with pino\n return;\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n const nodeEnv = process.env.NODE_ENV;\n return nodeEnv !== \"production\" && nodeEnv !== \"test\" && nodeEnv !== \"ci\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\" | \"DEBUG\"): string {\n return `[VoltAgent] [${timestamp()}] ${level}: `;\n}\n\nfunction timestamp(): string {\n return new Date().toISOString().replace(\"T\", \" \").slice(0, -1);\n}\n","/**\n * Convert a readable stream to an array\n * @param stream - The readable stream to convert\n * @returns The array of values\n */\nexport async function convertReadableStreamToArray<T>(stream: ReadableStream<T>): Promise<T[]> {\n const reader = stream.getReader();\n const result: T[] = [];\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n result.push(value);\n }\n\n return result;\n}\n\n/**\n * Convert an array to an async iterable\n * @param values - The array to convert\n * @returns The async iterable\n */\nexport function convertArrayToAsyncIterable<T>(values: T[]): AsyncIterable<T> {\n return {\n async *[Symbol.asyncIterator]() {\n for (const value of values) {\n yield value;\n }\n },\n };\n}\n\n/**\n * Convert an async iterable to an array\n * @param iterable - The async iterable to convert\n * @returns The array of values\n */\nexport async function convertAsyncIterableToArray<T>(iterable: AsyncIterable<T>): Promise<T[]> {\n const result: T[] = [];\n for await (const item of iterable) {\n result.push(item);\n }\n return result;\n}\n\n/**\n * Convert an array to a readable stream\n * @param values - The array to convert\n * @returns The readable stream\n */\nexport function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T> {\n return new ReadableStream({\n start(controller) {\n try {\n for (const value of values) {\n controller.enqueue(value);\n }\n } finally {\n controller.close();\n }\n },\n });\n}\n\n/**\n * Convert a response stream to an array\n * @param response - The response to convert\n * @returns The array of values\n */\nexport async function convertResponseStreamToArray(response: Response): Promise<string[]> {\n // biome-ignore lint/style/noNonNullAssertion: ignore this\n return convertReadableStreamToArray(response.body!.pipeThrough(new TextDecoderStream()));\n}\n","import type { EmptyObject } from \"type-fest\";\nimport type { AnyFunction, Nil, PlainObject } from \"../types\";\n\n/**\n * Check if a value is nil\n *\n * @param obj - The value to check\n * @returns True if the value is nil, false otherwise\n */\nexport function isNil(obj: unknown): obj is Nil {\n return obj === null || obj === undefined;\n}\n\n/**\n * Check if an object is a JS object\n *\n * @param obj - The object to check\n * @returns True if the object is a JS object}\n */\nexport function isObject<T extends object>(obj: unknown): obj is T {\n return (typeof obj === \"object\" || typeof obj === \"function\") && !isNil(obj);\n}\n\n/**\n * Check if a value is a function\n *\n * @param obj - The value to check\n * @returns True if the value is a function, false otherwise\n */\nexport function isFunction<T extends AnyFunction>(obj: unknown): obj is T {\n return typeof obj === \"function\";\n}\n\n/**\n * Check if an object is a plain object (i.e. a JS object but not including arrays or functions)\n *\n * @param obj - The object to check\n * @returns True if the object is a plain object, false otherwise.\n */\nexport function isPlainObject<T extends PlainObject>(obj: unknown): obj is T {\n if (!isObject(obj)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Check if an object is an empty object\n *\n * @param obj - The object to check\n * @returns True if the object is an empty object, false otherwise\n */\nexport function isEmptyObject(obj: unknown): obj is EmptyObject {\n if (!isObject(obj)) {\n return false;\n }\n\n // Check for own string and symbol properties (enumerable or not)\n if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {\n return false;\n }\n\n return true;\n}\n","import type { SetRequired } from \"type-fest\";\nimport { devLogger } from \"../dev\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object using JSON serialization with fallback to shallow clone\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object, or shallow copy if JSON serialization fails\n */\nexport function deepClone<T>(obj: T): T {\n try {\n return JSON.parse(JSON.stringify(obj));\n } catch (error) {\n devLogger.warn(\"Failed to deep clone object, using shallow clone:\", error);\n // Fallback to shallow clone for primitive types and simple objects\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n return { ...obj } as T;\n }\n}\n\n/**\n * Check if an object has a key\n *\n * @param obj - The object to check\n * @param key - The key to check\n * @returns True if the object has the key, false otherwise\n */\nexport function hasKey<T extends PlainObject, K extends string>(\n obj: T,\n key: K,\n): obj is T & SetRequired<T, K> {\n return isObject(obj) && key in obj;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYO,SAAS,gBAAgB,SAA4B;AAC1D,QAAM,QACJ,QAAO,mCAAS,SAAQ,aAAa,QAAQ,MAAM,MAAG;AAd1D;AAc6D,oDAAS,QAAT,YAAgB,aAAa;AAAA;AAExF,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAcL,MAAM,wBAAC,YAAkB,SAAgB;AACvC,UAAI,MAAM,GAAG;AACX,gBAAQ,KAAK,gBAAgB,MAAM,GAAG,SAAS,GAAG,IAAI;AAAA,MACxD;AAAA,IACF,GAJM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAkBN,MAAM,wBAAC,YAAkB,SAAgB;AACvC,UAAI,MAAM,GAAG;AACX,gBAAQ,KAAK,gBAAgB,MAAM,GAAG,SAAS,GAAG,IAAI;AAAA,MACxD;AA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,GAAG,CAAC;AAAA,EACvC,SAAS,OAAO;AACd,mBAAU,KAAK,qDAAqD,KAAK;AAEzE,QAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC3C,aAAO;AAAA,IACT;AACA,WAAO,mBAAK;AAAA,EACd;AACF;AAXgB;AAoBT,SAAS,OACd,KACA,KAC8B;AAC9B,SAAO,SAAS,GAAG,KAAK,OAAO;AACjC;AALgB;","names":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This type is used to allow any type and bypass restrictions used in
|
|
3
|
+
* typechecking and linting. Provides a CLEAR warning this is NOT the desired
|
|
4
|
+
* behavior and is a dangerous practice.
|
|
5
|
+
*/
|
|
6
|
+
type DangerouslyAllowAny = any;
|
|
7
|
+
/**
|
|
8
|
+
* A plain object is an object that has no special properties or methods,
|
|
9
|
+
* and just has properties that are strings, numbers, or symbols.
|
|
10
|
+
*/
|
|
11
|
+
type PlainObject = Record<string | number | symbol, unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* A nil value is a value that is not defined or is undefined.
|
|
14
|
+
*/
|
|
15
|
+
type Nil = null | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* A type that represents any async function.
|
|
18
|
+
*/
|
|
19
|
+
type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* A type that represents any synchronous function.
|
|
22
|
+
*/
|
|
23
|
+
type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
24
|
+
/**
|
|
25
|
+
* A type that represents any function.
|
|
26
|
+
*/
|
|
27
|
+
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
28
|
+
|
|
29
|
+
export type { AnyAsyncFunction, AnyFunction, AnySyncFunction, DangerouslyAllowAny, Nil, PlainObject };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This type is used to allow any type and bypass restrictions used in
|
|
3
|
+
* typechecking and linting. Provides a CLEAR warning this is NOT the desired
|
|
4
|
+
* behavior and is a dangerous practice.
|
|
5
|
+
*/
|
|
6
|
+
type DangerouslyAllowAny = any;
|
|
7
|
+
/**
|
|
8
|
+
* A plain object is an object that has no special properties or methods,
|
|
9
|
+
* and just has properties that are strings, numbers, or symbols.
|
|
10
|
+
*/
|
|
11
|
+
type PlainObject = Record<string | number | symbol, unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* A nil value is a value that is not defined or is undefined.
|
|
14
|
+
*/
|
|
15
|
+
type Nil = null | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* A type that represents any async function.
|
|
18
|
+
*/
|
|
19
|
+
type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* A type that represents any synchronous function.
|
|
22
|
+
*/
|
|
23
|
+
type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
24
|
+
/**
|
|
25
|
+
* A type that represents any function.
|
|
26
|
+
*/
|
|
27
|
+
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
28
|
+
|
|
29
|
+
export type { AnyAsyncFunction, AnyFunction, AnySyncFunction, DangerouslyAllowAny, Nil, PlainObject };
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
|
+
import { SetRequired, EmptyObject } from 'type-fest';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A plain object is an object that has no special properties or methods,
|
|
5
|
+
* and just has properties that are strings, numbers, or symbols.
|
|
6
|
+
*/
|
|
7
|
+
type PlainObject = Record<string | number | symbol, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* A nil value is a value that is not defined or is undefined.
|
|
10
|
+
*/
|
|
11
|
+
type Nil = null | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* A type that represents any async function.
|
|
14
|
+
*/
|
|
15
|
+
type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
|
|
1
16
|
/**
|
|
2
|
-
*
|
|
17
|
+
* A type that represents any synchronous function.
|
|
3
18
|
*/
|
|
19
|
+
type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
20
|
+
/**
|
|
21
|
+
* A type that represents any function.
|
|
22
|
+
*/
|
|
23
|
+
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
24
|
+
|
|
4
25
|
/**
|
|
5
26
|
* Deep clone an object using JSON serialization with fallback to shallow clone
|
|
6
27
|
*
|
|
@@ -8,5 +29,49 @@
|
|
|
8
29
|
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
9
30
|
*/
|
|
10
31
|
declare function deepClone<T>(obj: T): T;
|
|
32
|
+
/**
|
|
33
|
+
* Check if an object has a key
|
|
34
|
+
*
|
|
35
|
+
* @param obj - The object to check
|
|
36
|
+
* @param key - The key to check
|
|
37
|
+
* @returns True if the object has the key, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
declare function hasKey<T extends PlainObject, K extends string>(obj: T, key: K): obj is T & SetRequired<T, K>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Check if a value is nil
|
|
43
|
+
*
|
|
44
|
+
* @param obj - The value to check
|
|
45
|
+
* @returns True if the value is nil, false otherwise
|
|
46
|
+
*/
|
|
47
|
+
declare function isNil(obj: unknown): obj is Nil;
|
|
48
|
+
/**
|
|
49
|
+
* Check if an object is a JS object
|
|
50
|
+
*
|
|
51
|
+
* @param obj - The object to check
|
|
52
|
+
* @returns True if the object is a JS object}
|
|
53
|
+
*/
|
|
54
|
+
declare function isObject<T extends object>(obj: unknown): obj is T;
|
|
55
|
+
/**
|
|
56
|
+
* Check if a value is a function
|
|
57
|
+
*
|
|
58
|
+
* @param obj - The value to check
|
|
59
|
+
* @returns True if the value is a function, false otherwise
|
|
60
|
+
*/
|
|
61
|
+
declare function isFunction<T extends AnyFunction>(obj: unknown): obj is T;
|
|
62
|
+
/**
|
|
63
|
+
* Check if an object is a plain object (i.e. a JS object but not including arrays or functions)
|
|
64
|
+
*
|
|
65
|
+
* @param obj - The object to check
|
|
66
|
+
* @returns True if the object is a plain object, false otherwise.
|
|
67
|
+
*/
|
|
68
|
+
declare function isPlainObject<T extends PlainObject>(obj: unknown): obj is T;
|
|
69
|
+
/**
|
|
70
|
+
* Check if an object is an empty object
|
|
71
|
+
*
|
|
72
|
+
* @param obj - The object to check
|
|
73
|
+
* @returns True if the object is an empty object, false otherwise
|
|
74
|
+
*/
|
|
75
|
+
declare function isEmptyObject(obj: unknown): obj is EmptyObject;
|
|
11
76
|
|
|
12
|
-
export { deepClone };
|
|
77
|
+
export { deepClone, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
|
+
import { SetRequired, EmptyObject } from 'type-fest';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A plain object is an object that has no special properties or methods,
|
|
5
|
+
* and just has properties that are strings, numbers, or symbols.
|
|
6
|
+
*/
|
|
7
|
+
type PlainObject = Record<string | number | symbol, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* A nil value is a value that is not defined or is undefined.
|
|
10
|
+
*/
|
|
11
|
+
type Nil = null | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* A type that represents any async function.
|
|
14
|
+
*/
|
|
15
|
+
type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
|
|
1
16
|
/**
|
|
2
|
-
*
|
|
17
|
+
* A type that represents any synchronous function.
|
|
3
18
|
*/
|
|
19
|
+
type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
20
|
+
/**
|
|
21
|
+
* A type that represents any function.
|
|
22
|
+
*/
|
|
23
|
+
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
24
|
+
|
|
4
25
|
/**
|
|
5
26
|
* Deep clone an object using JSON serialization with fallback to shallow clone
|
|
6
27
|
*
|
|
@@ -8,5 +29,49 @@
|
|
|
8
29
|
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
9
30
|
*/
|
|
10
31
|
declare function deepClone<T>(obj: T): T;
|
|
32
|
+
/**
|
|
33
|
+
* Check if an object has a key
|
|
34
|
+
*
|
|
35
|
+
* @param obj - The object to check
|
|
36
|
+
* @param key - The key to check
|
|
37
|
+
* @returns True if the object has the key, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
declare function hasKey<T extends PlainObject, K extends string>(obj: T, key: K): obj is T & SetRequired<T, K>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Check if a value is nil
|
|
43
|
+
*
|
|
44
|
+
* @param obj - The value to check
|
|
45
|
+
* @returns True if the value is nil, false otherwise
|
|
46
|
+
*/
|
|
47
|
+
declare function isNil(obj: unknown): obj is Nil;
|
|
48
|
+
/**
|
|
49
|
+
* Check if an object is a JS object
|
|
50
|
+
*
|
|
51
|
+
* @param obj - The object to check
|
|
52
|
+
* @returns True if the object is a JS object}
|
|
53
|
+
*/
|
|
54
|
+
declare function isObject<T extends object>(obj: unknown): obj is T;
|
|
55
|
+
/**
|
|
56
|
+
* Check if a value is a function
|
|
57
|
+
*
|
|
58
|
+
* @param obj - The value to check
|
|
59
|
+
* @returns True if the value is a function, false otherwise
|
|
60
|
+
*/
|
|
61
|
+
declare function isFunction<T extends AnyFunction>(obj: unknown): obj is T;
|
|
62
|
+
/**
|
|
63
|
+
* Check if an object is a plain object (i.e. a JS object but not including arrays or functions)
|
|
64
|
+
*
|
|
65
|
+
* @param obj - The object to check
|
|
66
|
+
* @returns True if the object is a plain object, false otherwise.
|
|
67
|
+
*/
|
|
68
|
+
declare function isPlainObject<T extends PlainObject>(obj: unknown): obj is T;
|
|
69
|
+
/**
|
|
70
|
+
* Check if an object is an empty object
|
|
71
|
+
*
|
|
72
|
+
* @param obj - The object to check
|
|
73
|
+
* @returns True if the object is an empty object, false otherwise
|
|
74
|
+
*/
|
|
75
|
+
declare function isEmptyObject(obj: unknown): obj is EmptyObject;
|
|
11
76
|
|
|
12
|
-
export { deepClone };
|
|
77
|
+
export { deepClone, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject };
|
package/dist/utils/index.js
CHANGED
|
@@ -35,7 +35,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
35
35
|
// src/utils/index.ts
|
|
36
36
|
var index_exports = {};
|
|
37
37
|
__export(index_exports, {
|
|
38
|
-
deepClone: () => deepClone
|
|
38
|
+
deepClone: () => deepClone,
|
|
39
|
+
hasKey: () => hasKey,
|
|
40
|
+
isEmptyObject: () => isEmptyObject,
|
|
41
|
+
isFunction: () => isFunction,
|
|
42
|
+
isNil: () => isNil,
|
|
43
|
+
isObject: () => isObject,
|
|
44
|
+
isPlainObject: () => isPlainObject
|
|
39
45
|
});
|
|
40
46
|
module.exports = __toCommonJS(index_exports);
|
|
41
47
|
|
|
@@ -99,13 +105,17 @@ function createDevLogger(options) {
|
|
|
99
105
|
if (isDev()) {
|
|
100
106
|
console.error(formatLogPrefix("ERROR"), message, ...args);
|
|
101
107
|
}
|
|
102
|
-
}, "error")
|
|
108
|
+
}, "error"),
|
|
109
|
+
debug: /* @__PURE__ */ __name((_message, ..._args) => {
|
|
110
|
+
return;
|
|
111
|
+
}, "debug")
|
|
103
112
|
};
|
|
104
113
|
}
|
|
105
114
|
__name(createDevLogger, "createDevLogger");
|
|
106
115
|
var logger_default = createDevLogger();
|
|
107
116
|
function isDevNodeEnv() {
|
|
108
|
-
|
|
117
|
+
const nodeEnv = process.env.NODE_ENV;
|
|
118
|
+
return nodeEnv !== "production" && nodeEnv !== "test" && nodeEnv !== "ci";
|
|
109
119
|
}
|
|
110
120
|
__name(isDevNodeEnv, "isDevNodeEnv");
|
|
111
121
|
function formatLogPrefix(level) {
|
|
@@ -117,7 +127,39 @@ function timestamp() {
|
|
|
117
127
|
}
|
|
118
128
|
__name(timestamp, "timestamp");
|
|
119
129
|
|
|
120
|
-
// src/utils/
|
|
130
|
+
// src/utils/lang.ts
|
|
131
|
+
function isNil(obj) {
|
|
132
|
+
return obj === null || obj === void 0;
|
|
133
|
+
}
|
|
134
|
+
__name(isNil, "isNil");
|
|
135
|
+
function isObject(obj) {
|
|
136
|
+
return (typeof obj === "object" || typeof obj === "function") && !isNil(obj);
|
|
137
|
+
}
|
|
138
|
+
__name(isObject, "isObject");
|
|
139
|
+
function isFunction(obj) {
|
|
140
|
+
return typeof obj === "function";
|
|
141
|
+
}
|
|
142
|
+
__name(isFunction, "isFunction");
|
|
143
|
+
function isPlainObject(obj) {
|
|
144
|
+
if (!isObject(obj)) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
const prototype = Object.getPrototypeOf(obj);
|
|
148
|
+
return prototype === Object.prototype || prototype === null;
|
|
149
|
+
}
|
|
150
|
+
__name(isPlainObject, "isPlainObject");
|
|
151
|
+
function isEmptyObject(obj) {
|
|
152
|
+
if (!isObject(obj)) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
__name(isEmptyObject, "isEmptyObject");
|
|
161
|
+
|
|
162
|
+
// src/utils/objects.ts
|
|
121
163
|
function deepClone(obj) {
|
|
122
164
|
try {
|
|
123
165
|
return JSON.parse(JSON.stringify(obj));
|
|
@@ -130,8 +172,18 @@ function deepClone(obj) {
|
|
|
130
172
|
}
|
|
131
173
|
}
|
|
132
174
|
__name(deepClone, "deepClone");
|
|
175
|
+
function hasKey(obj, key) {
|
|
176
|
+
return isObject(obj) && key in obj;
|
|
177
|
+
}
|
|
178
|
+
__name(hasKey, "hasKey");
|
|
133
179
|
// Annotate the CommonJS export names for ESM import in node:
|
|
134
180
|
0 && (module.exports = {
|
|
135
|
-
deepClone
|
|
181
|
+
deepClone,
|
|
182
|
+
hasKey,
|
|
183
|
+
isEmptyObject,
|
|
184
|
+
isFunction,
|
|
185
|
+
isNil,
|
|
186
|
+
isObject,
|
|
187
|
+
isPlainObject
|
|
136
188
|
});
|
|
137
189
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts","../../src/dev/logger.ts","../../src/utils/
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts","../../src/dev/logger.ts","../../src/utils/lang.ts","../../src/utils/objects.ts"],"sourcesContent":["export { deepClone, hasKey } from \"./objects\";\nexport { isNil, isObject, isEmptyObject, isFunction, isPlainObject } from \"./lang\";\n","export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n\n debug: (_message?: any, ..._args: any[]) => {\n // todo: implement debug logging with pino\n return;\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n const nodeEnv = process.env.NODE_ENV;\n return nodeEnv !== \"production\" && nodeEnv !== \"test\" && nodeEnv !== \"ci\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\" | \"DEBUG\"): string {\n return `[VoltAgent] [${timestamp()}] ${level}: `;\n}\n\nfunction timestamp(): string {\n return new Date().toISOString().replace(\"T\", \" \").slice(0, -1);\n}\n","import type { EmptyObject } from \"type-fest\";\nimport type { AnyFunction, Nil, PlainObject } from \"../types\";\n\n/**\n * Check if a value is nil\n *\n * @param obj - The value to check\n * @returns True if the value is nil, false otherwise\n */\nexport function isNil(obj: unknown): obj is Nil {\n return obj === null || obj === undefined;\n}\n\n/**\n * Check if an object is a JS object\n *\n * @param obj - The object to check\n * @returns True if the object is a JS object}\n */\nexport function isObject<T extends object>(obj: unknown): obj is T {\n return (typeof obj === \"object\" || typeof obj === \"function\") && !isNil(obj);\n}\n\n/**\n * Check if a value is a function\n *\n * @param obj - The value to check\n * @returns True if the value is a function, false otherwise\n */\nexport function isFunction<T extends AnyFunction>(obj: unknown): obj is T {\n return typeof obj === \"function\";\n}\n\n/**\n * Check if an object is a plain object (i.e. a JS object but not including arrays or functions)\n *\n * @param obj - The object to check\n * @returns True if the object is a plain object, false otherwise.\n */\nexport function isPlainObject<T extends PlainObject>(obj: unknown): obj is T {\n if (!isObject(obj)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Check if an object is an empty object\n *\n * @param obj - The object to check\n * @returns True if the object is an empty object, false otherwise\n */\nexport function isEmptyObject(obj: unknown): obj is EmptyObject {\n if (!isObject(obj)) {\n return false;\n }\n\n // Check for own string and symbol properties (enumerable or not)\n if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {\n return false;\n }\n\n return true;\n}\n","import type { SetRequired } from \"type-fest\";\nimport { devLogger } from \"../dev\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object using JSON serialization with fallback to shallow clone\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object, or shallow copy if JSON serialization fails\n */\nexport function deepClone<T>(obj: T): T {\n try {\n return JSON.parse(JSON.stringify(obj));\n } catch (error) {\n devLogger.warn(\"Failed to deep clone object, using shallow clone:\", error);\n // Fallback to shallow clone for primitive types and simple objects\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n return { ...obj } as T;\n }\n}\n\n/**\n * Check if an object has a key\n *\n * @param obj - The object to check\n * @param key - The key to check\n * @returns True if the object has the key, false otherwise\n */\nexport function hasKey<T extends PlainObject, K extends string>(\n obj: T,\n key: K,\n): obj is T & SetRequired<T, K> {\n return isObject(obj) && key in obj;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYO,SAAS,gBAAgB,SAA4B;AAC1D,QAAM,QACJ,QAAO,mCAAS,SAAQ,aAAa,QAAQ,MAAM,MAAG;AAd1D;AAc6D,oDAAS,QAAT,YAAgB,aAAa;AAAA;AAExF,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAcL,MAAM,wBAAC,YAAkB,SAAgB;AACvC,UAAI,MAAM,GAAG;AACX,gBAAQ,KAAK,gBAAgB,MAAM,GAAG,SAAS,GAA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SAAS,GAAG,GAAG;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,eAAe,GAAG;AAC3C,SAAO,cAAc,OAAO,aAAa,cAAc;AACzD;AAPgB;AAeT,SAAS,cAAc,KAAkC;AAC9D,MAAI,CAAC,SAAS,GAAG,GAAG;AAClB,WAAO;AAAA,EACT;AAGA,MAAI,OAAO,oBAAoB,GAAG,EAAE,SAAS,KAAK,OAAO,sBAAsB,GAAG,EAAE,SAAS,GAAG;AAC9F,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAXgB;;;AC3CT,SAAS,UAAa,KAAW;AACtC,MAAI;AACF,WAAO,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;AAAA,EACvC,SAAS,OAAO;AACd,mBAAU,KAAK,qDAAqD,KAAK;AAEzE,QAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC3C,aAAO;AAAA,IACT;AACA,WAAO,mBAAK;AAAA,EACd;AACF;AAXgB;AAoBT,SAAS,OACd,KACA,KAC8B;AAC9B,SAAO,SAAS,GAAG,KAAK,OAAO;AACjC;AALgB;","names":[]}
|
package/dist/utils/index.mjs
CHANGED
|
@@ -76,13 +76,17 @@ function createDevLogger(options) {
|
|
|
76
76
|
if (isDev()) {
|
|
77
77
|
console.error(formatLogPrefix("ERROR"), message, ...args);
|
|
78
78
|
}
|
|
79
|
-
}, "error")
|
|
79
|
+
}, "error"),
|
|
80
|
+
debug: /* @__PURE__ */ __name((_message, ..._args) => {
|
|
81
|
+
return;
|
|
82
|
+
}, "debug")
|
|
80
83
|
};
|
|
81
84
|
}
|
|
82
85
|
__name(createDevLogger, "createDevLogger");
|
|
83
86
|
var logger_default = createDevLogger();
|
|
84
87
|
function isDevNodeEnv() {
|
|
85
|
-
|
|
88
|
+
const nodeEnv = process.env.NODE_ENV;
|
|
89
|
+
return nodeEnv !== "production" && nodeEnv !== "test" && nodeEnv !== "ci";
|
|
86
90
|
}
|
|
87
91
|
__name(isDevNodeEnv, "isDevNodeEnv");
|
|
88
92
|
function formatLogPrefix(level) {
|
|
@@ -94,7 +98,39 @@ function timestamp() {
|
|
|
94
98
|
}
|
|
95
99
|
__name(timestamp, "timestamp");
|
|
96
100
|
|
|
97
|
-
// src/utils/
|
|
101
|
+
// src/utils/lang.ts
|
|
102
|
+
function isNil(obj) {
|
|
103
|
+
return obj === null || obj === void 0;
|
|
104
|
+
}
|
|
105
|
+
__name(isNil, "isNil");
|
|
106
|
+
function isObject(obj) {
|
|
107
|
+
return (typeof obj === "object" || typeof obj === "function") && !isNil(obj);
|
|
108
|
+
}
|
|
109
|
+
__name(isObject, "isObject");
|
|
110
|
+
function isFunction(obj) {
|
|
111
|
+
return typeof obj === "function";
|
|
112
|
+
}
|
|
113
|
+
__name(isFunction, "isFunction");
|
|
114
|
+
function isPlainObject(obj) {
|
|
115
|
+
if (!isObject(obj)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
const prototype = Object.getPrototypeOf(obj);
|
|
119
|
+
return prototype === Object.prototype || prototype === null;
|
|
120
|
+
}
|
|
121
|
+
__name(isPlainObject, "isPlainObject");
|
|
122
|
+
function isEmptyObject(obj) {
|
|
123
|
+
if (!isObject(obj)) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
__name(isEmptyObject, "isEmptyObject");
|
|
132
|
+
|
|
133
|
+
// src/utils/objects.ts
|
|
98
134
|
function deepClone(obj) {
|
|
99
135
|
try {
|
|
100
136
|
return JSON.parse(JSON.stringify(obj));
|
|
@@ -107,7 +143,17 @@ function deepClone(obj) {
|
|
|
107
143
|
}
|
|
108
144
|
}
|
|
109
145
|
__name(deepClone, "deepClone");
|
|
146
|
+
function hasKey(obj, key) {
|
|
147
|
+
return isObject(obj) && key in obj;
|
|
148
|
+
}
|
|
149
|
+
__name(hasKey, "hasKey");
|
|
110
150
|
export {
|
|
111
|
-
deepClone
|
|
151
|
+
deepClone,
|
|
152
|
+
hasKey,
|
|
153
|
+
isEmptyObject,
|
|
154
|
+
isFunction,
|
|
155
|
+
isNil,
|
|
156
|
+
isObject,
|
|
157
|
+
isPlainObject
|
|
112
158
|
};
|
|
113
159
|
//# sourceMappingURL=index.mjs.map
|
package/dist/utils/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/dev/logger.ts","../../src/utils/
|
|
1
|
+
{"version":3,"sources":["../../src/dev/logger.ts","../../src/utils/lang.ts","../../src/utils/objects.ts"],"sourcesContent":["export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n\n debug: (_message?: any, ..._args: any[]) => {\n // todo: implement debug logging with pino\n return;\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n const nodeEnv = process.env.NODE_ENV;\n return nodeEnv !== \"production\" && nodeEnv !== \"test\" && nodeEnv !== \"ci\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\" | \"DEBUG\"): string {\n return `[VoltAgent] [${timestamp()}] ${level}: `;\n}\n\nfunction timestamp(): string {\n return new Date().toISOString().replace(\"T\", \" \").slice(0, -1);\n}\n","import type { EmptyObject } from \"type-fest\";\nimport type { AnyFunction, Nil, PlainObject } from \"../types\";\n\n/**\n * Check if a value is nil\n *\n * @param obj - The value to check\n * @returns True if the value is nil, false otherwise\n */\nexport function isNil(obj: unknown): obj is Nil {\n return obj === null || obj === undefined;\n}\n\n/**\n * Check if an object is a JS object\n *\n * @param obj - The object to check\n * @returns True if the object is a JS object}\n */\nexport function isObject<T extends object>(obj: unknown): obj is T {\n return (typeof obj === \"object\" || typeof obj === \"function\") && !isNil(obj);\n}\n\n/**\n * Check if a value is a function\n *\n * @param obj - The value to check\n * @returns True if the value is a function, false otherwise\n */\nexport function isFunction<T extends AnyFunction>(obj: unknown): obj is T {\n return typeof obj === \"function\";\n}\n\n/**\n * Check if an object is a plain object (i.e. a JS object but not including arrays or functions)\n *\n * @param obj - The object to check\n * @returns True if the object is a plain object, false otherwise.\n */\nexport function isPlainObject<T extends PlainObject>(obj: unknown): obj is T {\n if (!isObject(obj)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Check if an object is an empty object\n *\n * @param obj - The object to check\n * @returns True if the object is an empty object, false otherwise\n */\nexport function isEmptyObject(obj: unknown): obj is EmptyObject {\n if (!isObject(obj)) {\n return false;\n }\n\n // Check for own string and symbol properties (enumerable or not)\n if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {\n return false;\n }\n\n return true;\n}\n","import type { SetRequired } from \"type-fest\";\nimport { devLogger } from \"../dev\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object using JSON serialization with fallback to shallow clone\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object, or shallow copy if JSON serialization fails\n */\nexport function deepClone<T>(obj: T): T {\n try {\n return JSON.parse(JSON.stringify(obj));\n } catch (error) {\n devLogger.warn(\"Failed to deep clone object, using shallow clone:\", error);\n // Fallback to shallow clone for primitive types and simple objects\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n return { ...obj } as T;\n }\n}\n\n/**\n * Check if an object has a key\n *\n * @param obj - The object to check\n * @param key - The key to check\n * @returns True if the object has the key, false otherwise\n */\nexport function hasKey<T extends PlainObject, K extends string>(\n obj: T,\n key: K,\n): obj is T & SetRequired<T, K> {\n return isObject(obj) && key in obj;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAYO,SAAS,gBAAgB,SAA4B;AAC1D,QAAM,QACJ,QAAO,mCAAS,SAAQ,aAAa,QAAQ,MAAM,MAAG;AAd1D;AAc6D,oDAAS,QAAT,YAAgB,aAAa;AAAA;AAExF,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAcL,MAAM,wBAAC,YAAkB,SAAgB;AACvC,UAAI,MAAM,GAAG;AACX,gBAAQ,KAAK,gBAAgB,MAAM,GAAG,SAAS,GAAG,IAAI;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AG,GAAG;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,eAAe,GAAG;AAC3C,SAAO,cAAc,OAAO,aAAa,cAAc;AACzD;AAPgB;AAeT,SAAS,cAAc,KAAkC;AAC9D,MAAI,CAAC,SAAS,GAAG,GAAG;AAClB,WAAO;AAAA,EACT;AAGA,MAAI,OAAO,oBAAoB,GAAG,EAAE,SAAS,KAAK,OAAO,sBAAsB,GAAG,EAAE,SAAS,GAAG;AAC9F,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAXgB;;;AC3CT,SAAS,UAAa,KAAW;AACtC,MAAI;AACF,WAAO,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;AAAA,EACvC,SAAS,OAAO;AACd,mBAAU,KAAK,qDAAqD,KAAK;AAEzE,QAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC3C,aAAO;AAAA,IACT;AACA,WAAO,mBAAK;AAAA,EACd;AACF;AAXgB;AAoBT,SAAS,OACd,KACA,KAC8B;AAC9B,SAAO,SAAS,GAAG,KAAK,OAAO;AACjC;AALgB;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltagent/internal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "VoltAgent internal - an internal set of tools for the VoltAgent packages",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"exports": {
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
"types": "./dist/utils/index.d.ts",
|
|
24
24
|
"import": "./dist/utils/index.mjs",
|
|
25
25
|
"require": "./dist/utils/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./types": {
|
|
28
|
+
"types": "./dist/types/index.d.ts"
|
|
26
29
|
}
|
|
27
30
|
},
|
|
28
31
|
"main": "dist/main/index.js",
|
|
@@ -33,12 +36,11 @@
|
|
|
33
36
|
"dev/dist/**/*",
|
|
34
37
|
"test/dist/**/*"
|
|
35
38
|
],
|
|
36
|
-
"dependencies": {
|
|
37
|
-
"@voltagent/core": "^0.1.44"
|
|
38
|
-
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node": "^24.0.3",
|
|
41
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
41
42
|
"tsup": "^8.5.0",
|
|
43
|
+
"type-fest": "^4.41.0",
|
|
42
44
|
"typescript": "^5.0.4",
|
|
43
45
|
"vitest": "^3.2.4"
|
|
44
46
|
},
|