{"version":3,"sources":["../../src/utils/lang.ts","../../src/utils/objects.ts","../../src/utils/async-iterable-stream.ts","../../src/utils/safe-stringify.ts"],"sourcesContent":["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 type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object (fallback to shallow clone for failures)\n */\nexport function deepClone<T>(obj: T): T {\n  try {\n    // Use structuredClone if available (Node.js 17+, modern browsers)\n    if (typeof structuredClone === \"function\") {\n      return structuredClone(obj);\n    }\n\n    throw new Error(\"structuredClone is not available\");\n  } catch (_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","import type { Merge } from \"type-fest\";\n\n/**\n * An async iterable stream that can be read from.\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = getStream();\n * for await (const chunk of stream) {\n *   console.log(chunk);\n * }\n * ```\n */\nexport type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;\n\n/**\n * Create an async iterable stream from a readable stream.\n *\n * This is useful for creating an async iterable stream from a readable stream.\n *\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({\n *   start(controller) {\n *     controller.enqueue(\"Hello\");\n *     controller.close();\n *   },\n * }));\n * ```\n * @param source The readable stream to create an async iterable stream from.\n * @returns The async iterable stream.\n */\nexport function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T> {\n  const stream = source.pipeThrough(new TransformStream<T, T>());\n\n  (stream as AsyncIterableStream<T>)[Symbol.asyncIterator] = () => {\n    const reader = stream.getReader();\n    return {\n      async next(): Promise<IteratorResult<T>> {\n        const { done, value } = await reader.read();\n        return done ? { done: true, value: undefined } : { done: false, value };\n      },\n    };\n  };\n\n  return stream as AsyncIterableStream<T>;\n}\n","import type { DangerouslyAllowAny } from \"../types\";\n\nexport type SafeStringifyOptions = {\n  /**\n   * The indentation to use for the output.\n   */\n  indentation?: string | number;\n};\n\n/**\n * Stringifies an object, handling circular references and ensuring the output is safe to use in a JSON string.\n * @param input - The object to stringify.\n * @param options.indentation - The indentation to use for the output.\n * @returns The stringified object.\n */\nexport function safeStringify(\n  input: DangerouslyAllowAny,\n  { indentation }: SafeStringifyOptions = {},\n) {\n  try {\n    const seen = new WeakSet();\n    return JSON.stringify(input, safeStringifyReplacer(seen), indentation);\n  } catch (error) {\n    return `SAFE_STRINGIFY_ERROR: Error stringifying object: ${error instanceof Error ? error.message : \"Unknown error\"}`;\n  }\n}\n\nfunction safeStringifyReplacer(seen: WeakSet<DangerouslyAllowAny>) {\n  const stack: DangerouslyAllowAny[] = [];\n  return function safeStringifyCircularReplacer(\n    this: DangerouslyAllowAny,\n    _key: string,\n    value: DangerouslyAllowAny,\n  ) {\n    if (stack.length === 0) {\n      stack.push(this);\n    } else {\n      const thisIndex = stack.indexOf(this);\n      if (thisIndex === -1) {\n        stack.push(this);\n      } else {\n        stack.splice(thisIndex + 1);\n      }\n    }\n\n    if (value && typeof value === \"object\") {\n      if (typeof value.toJSON === \"function\") {\n        // biome-ignore lint/style/noParameterAssign: needed to handle circular references\n        value = value.toJSON();\n      }\n\n      if (value && typeof value === \"object\") {\n        if (stack.includes(value)) {\n          return \"[Circular]\";\n        }\n\n        if (!seen.has(value)) {\n          seen.add(value);\n        }\n      } else {\n        return value;\n      }\n    }\n\n    return value;\n  };\n}\n"],"mappings":";;;;AASO,SAAS,MAAM,KAA0B;AAC9C,SAAO,QAAQ,QAAQ,QAAQ;AACjC;AAFgB;AAUT,SAAS,SAA2B,KAAwB;AACjE,UAAQ,OAAO,QAAQ,YAAY,OAAO,QAAQ,eAAe,CAAC,MAAM,GAAG;AAC7E;AAFgB;AAUT,SAAS,WAAkC,KAAwB;AACxE,SAAO,OAAO,QAAQ;AACxB;AAFgB;AAUT,SAAS,cAAqC,KAAwB;AAC3E,MAAI,CAAC,SAAS,GAAG,GAAG;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,eAAe,GAAG;AAC3C,SAAO,cAAc,OAAO,aAAa,cAAc;AACzD;AAPgB;AAeT,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