{"version":3,"file":"index.modern.mjs","sources":["../src/manage/files/NaroFiler.ts","../src/core/Core.ts","../src/manage/paths/NaroPath.ts","../src/utils/IdGenerator.ts","../src/base/Naro.ts"],"sourcesContent":["import { decode, encode } from \"notepack.io\";\r\nimport jetpack from \"fs-jetpack\";\r\n\r\nexport class NaroFiler {\r\n  static ensureDirectory(path: string): void {\r\n    jetpack.dir(path);\r\n  }\r\n\r\n  static readBinaryFile(path: string): any[] {\r\n    const data = jetpack.read(path, \"buffer\");\r\n    return data ? decode(data) : [];\r\n  }\r\n\r\n  static writeBinaryFile(path: string, data: any[]): void {\r\n    return jetpack.write(path, encode(data));\r\n  }\r\n\r\n  static listDirectories(path: string): string[] {\r\n    const directory = jetpack.inspectTree(path);\r\n    if (!directory) return [];\r\n    return directory.children.filter((child) => child.type === \"dir\").map((child) => child.name);\r\n  }\r\n\r\n  static removeDirectory(path: string): void {\r\n    return jetpack.remove(path);\r\n  }\r\n}\r\n","import { NaroFiler } from \"../manage/files/NaroFiler\";\r\nimport jetpack from \"fs-jetpack\";\r\nimport _ from 'lodash';\r\n\r\nexport class Core {\r\n  private readonly rootPath: string;\r\n  private collections: { [key: string]: any } = {};\r\n  private logFileName: string = \"data.bin\";\r\n\r\n  constructor(rootPath: string) {\r\n    this.rootPath = rootPath;\r\n  }\r\n\r\n  initialize() {\r\n    NaroFiler.ensureDirectory(this.rootPath);\r\n    this.loadCollections();\r\n  }\r\n\r\n  getStructuredCollections() {\r\n    return this.collections;\r\n  }\r\n\r\n  loadCollections() {\r\n    const directories = NaroFiler.listDirectories(this.rootPath);\r\n    for (const folderName of directories) {\r\n      const folderPath = `${this.rootPath}/${folderName}`;\r\n      const dataPath = `${folderPath}/${this.logFileName}`;\r\n      jetpack.file(dataPath);\r\n      this.collections[folderName] = NaroFiler.readBinaryFile(dataPath);\r\n    }\r\n    return this.collections;\r\n  }\r\n\r\n  getCollection(name: string): any[] {\r\n    if (!this.collections[name]) return this.collections[name] = [];\r\n    return this.collections[name];\r\n  }\r\n\r\n  updateCollection(name: string, data: any[]): void {\r\n    this.collections[name] = _.cloneDeep(data);\r\n  }\r\n\r\n  writeCollections(): void {\r\n    Object.keys(this.collections).forEach((collectionName) => {\r\n      const collectionPath = `${this.rootPath}/${collectionName}/${this.logFileName}`;\r\n      NaroFiler.writeBinaryFile(collectionPath, this.collections[collectionName]);\r\n    });\r\n  }\r\n\r\n  writeCollection(path: string): void {\r\n    const collectionPath = `${this.rootPath}/${path}`;\r\n    NaroFiler.ensureDirectory(collectionPath);\r\n    const dataPath = `${collectionPath}/${this.logFileName}`;\r\n    NaroFiler.writeBinaryFile(dataPath, this.collections[path]);\r\n  }\r\n\r\n  removeCollection(path: string): void {\r\n    const collectionPath = `${this.rootPath}/${path}`;\r\n    NaroFiler.removeDirectory(collectionPath);\r\n    delete this.collections[path];\r\n  }\r\n}\r\n","export class NaroPath {\r\n  /**\r\n   * Validates a given path string and extracts its components.\r\n   *\r\n   * @param {string} path - The path string to validate. It should follow the format:\r\n   *                        'collectionName/id' or 'collectionName/id/subCollectionName/id'.\r\n   *\r\n   * @returns {Object} An object containing the extracted components of the path:\r\n   *                   - `collectionName` (string): The name of the collection.\r\n   *                   - `collectionId` (string): The ID of the collection.\r\n   *                   - `subCollectionName` (string | undefined): The name of the sub-collection (if present).\r\n   *                   - `subCollectionId` (string | undefined): The ID of the sub-collection (if present).\r\n   *\r\n   * @throws {Error} If the path contains invalid characters.\r\n   * @throws {Error} If the path ends with a '/'.\r\n   * @throws {Error} If the path is empty.\r\n   * @throws {Error} If the path format is invalid (e.g., too few or too many parts).\r\n   */\r\n  static validate(path: string): {\r\n    collectionName: string;\r\n    collectionId: string;\r\n    subCollectionName?: string;\r\n    subCollectionId?: string;\r\n  } {\r\n    const invalidChars = /[^a-zA-Z0-9/_-]/;\r\n    if (invalidChars.test(path) || path.includes('//')) throw new Error(\"Path contains invalid characters or consecutive slashes.\");\r\n    if (path.endsWith('/')) throw new Error(\"Path should not end with a '/'.\");\r\n    if (!path) throw new Error(\"Empty path provided.\");\r\n    const pathParts = path.split('/');\r\n    // if (pathParts.length < 1) throw new Error(\"Invalid path format. Ensure the path is in the format 'collectionName/id'.\");\r\n    if (pathParts.length > 4) throw new Error(\"Invalid path format. Ensure the path is in the format 'collectionName/id/subCollectionName/id'.\");\r\n\r\n    return {\r\n      collectionName: pathParts[0],\r\n      collectionId: pathParts[1],\r\n      subCollectionName: pathParts[2],\r\n      subCollectionId: pathParts[3]\r\n    };\r\n  }\r\n}\r\n","export class NaroId {\r\n    static generate() {\r\n        return Date.now().toString(36) + Math.random().toString(36).slice(2, 11);\r\n    }\r\n}\r\n","import _ from 'lodash';\r\nimport { Core } from \"../core/Core\";\r\nimport { NaroPath } from \"../manage/paths/NaroPath\";\r\nimport { NaroId } from \"../utils/IdGenerator\";\r\nimport { NaroDocument, Options, Query, DocData } from \"../types\";\r\nimport axios from \"redaxios\";\r\n\r\n/**\r\n * The Naro class provides methods to manage and manipulate collections\r\n * of documents stored in the root `./data` folder.\r\n *\r\n * @example\r\n * const db = new Naro(\"database-name\");\r\n *\r\n * // Use separate database names for production and development environments\r\n * const db = new Naro(process.env.NODE_ENV === \"production\" ? \"prod-database-name\" : \"dev-database-name\");\r\n */\r\nexport class Naro {\r\n  private readonly dbName!: string;\r\n  private readonly core!: Core;\r\n  private readonly host!: string;\r\n  private readonly orgId!: string;\r\n  private readonly projectId!: string;\r\n\r\n  constructor(dbName: string, options?: { URI?: string }) {\r\n    if (options?.URI) {\r\n      const [baseUrl, orgId, projectId] = options.URI.split(';');\r\n      this.host = baseUrl;\r\n      this.orgId = orgId;\r\n      this.projectId = projectId;\r\n      if (!this.host || !this.orgId || !this.projectId) throw new Error(\"Invalid URI format.\");\r\n      return;\r\n    }\r\n\r\n    if (dbName.includes('/')) throw new Error(\"dbName cannot contain '/'\");\r\n    this.dbName = dbName;\r\n    const rootPath = `${process.cwd()}/data/${this.dbName}`;\r\n    this.core = new Core(rootPath);\r\n    this.core.initialize();\r\n    this.registerProcessListeners();\r\n  }\r\n\r\n  private registerProcessListeners() {\r\n    const cleanUpAndExit = async (exitCode?: number) => {\r\n      this.core.writeCollections();\r\n      process.removeAllListeners('exit');\r\n      process.removeAllListeners('SIGINT');\r\n      process.removeAllListeners('SIGTERM');\r\n      if (exitCode !== undefined) process.exit(exitCode);\r\n    };\r\n\r\n    process.setMaxListeners(Infinity);\r\n    process.on('exit', cleanUpAndExit);\r\n    process.on('SIGINT', () => cleanUpAndExit(0));\r\n    process.on('SIGTERM', () => cleanUpAndExit(0));\r\n  }\r\n\r\n  /**\r\n   * Writes the current collections data to disk storage.\r\n   *\r\n   * @return {Promise<void>} A promise that resolves when the write operation completes successfully.\r\n   */\r\n  async writeToDisk(): Promise<void> {\r\n    this.core.writeCollections();\r\n  }\r\n\r\n  /**\r\n   * Adds a new document to the specified collection.\r\n   *\r\n   * @param {string} path - The name of the collection to add the data to.\r\n   * @param {DocData} data - The data to be added as a new document.\r\n   * @return {Promise<NaroDocument>} A promise that resolves to the newly added document.\r\n   *\r\n   * @example\r\n   * const db = new Naro(\"myDatabase\");\r\n   *\r\n   * const newUser = await db.add(\"users\", { name: \"John Doe\", age: 30 });\r\n   * console.log(newUser);\r\n   * // Output: { id: \"generated-id\", createdAt: 1696872345000, name: \"John Doe\", age: 30 }\r\n   */\r\n  async add(path: string, data: DocData): Promise<NaroDocument> {\r\n    const { collectionName } = NaroPath.validate(path);\r\n    if (this.host) return await this.serverRequest(\"add\", [path, data]);\r\n    const collection = this.core.getCollection(collectionName);\r\n    const id = NaroId.generate();\r\n    const source = { id, createdAt: Date.now(), path: `${collectionName}/${id}` };\r\n    const newItem: NaroDocument = Object.assign(data, source);\r\n    collection.push(newItem);\r\n    this.core.updateCollection(collectionName, collection);\r\n    return _.cloneDeep(newItem);\r\n  }\r\n\r\n  /**\r\n   * Makes an HTTP POST request to the server with the specified method and parameters.\r\n   *\r\n   * @param {string} method - The name of the method to be invoked on the server.\r\n   * @param {any[]} params - The array of parameters to be sent with the request.\r\n   * @return {Promise<any>} A promise that resolves with the server's response data or the error encountered during the request.\r\n   */\r\n  private async serverRequest(method: string, params: any[]): Promise<any> {\r\n    try {\r\n      const response = await axios.post(this.host, {\r\n        orgId: this.orgId,\r\n        projectId: this.projectId,\r\n        method,\r\n        params\r\n      });\r\n\r\n      return response.data;\r\n    } catch (error) {\r\n      return error;\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Overwrite a document in the specified collection using the provided data.\r\n   *\r\n   * @param {string} path - The name of the collection to set the data in.\r\n   * @param {DocData} data - The data to be set as a document.\r\n   * @return {Promise<NaroDocument>} A promise that resolves to the newly set document.\r\n   *\r\n   * @example\r\n   * const db = new Naro(\"myDatabase\");\r\n   *\r\n   * const updatedUser = await db.set(\"users\", { id: \"123\", createdAt: Date.now(), name: \"Jane Doe\", age: 28 });\r\n   * console.log(updatedUser);\r\n   * // Output: { id: \"123\", createdAt: 1696872345000, name: \"Jane Doe\", age: 28 }\r\n   */\r\n  async set(path: string, data: DocData): Promise<NaroDocument> {\r\n    const { collectionName, collectionId, subCollectionName, subCollectionId } = NaroPath.validate(path);\r\n    if (!collectionId) throw new Error(\"Collection ID is required\");\r\n    if (subCollectionName) throw new Error(\"Sub-collection is not supported in set method\");\r\n    if (subCollectionId) throw new Error(\"Sub-collection ID is not supported in set method\");\r\n    if (this.host) return await this.serverRequest(\"set\", [path, data]);\r\n    const collection = this.core.getCollection(collectionName);\r\n    const source = { path: `${collectionName}/${collectionId}`, createdAt: Date.now(), id: collectionId };\r\n    const newItem: NaroDocument = Object.assign(data, source);\r\n    const existingIndex = _.findIndex(collection, (item) => item.id === collectionId);\r\n    existingIndex !== -1 ? collection[existingIndex] = newItem : collection.push(newItem);\r\n    this.core.updateCollection(collectionName, collection);\r\n    return _.cloneDeep(newItem);\r\n  }\r\n\r\n  /**\r\n   * Retrieves all documents from a specified collection, optionally applying filters and limits,\r\n   * and populates specified fields with referenced documents from other collections.\r\n   *\r\n   * @param {string} path - The name of the collection to retrieve documents from.\r\n   * @param {Options} [options={}] - Options to filter and limit the retrieval of documents.\r\n   * @param {Query[]} [options.filters] - An array of filter conditions to apply to the documents.\r\n   * @param {number} [options.limit] - Maximum number of documents to retrieve.\r\n   * @param {string[]} [options.populate] - An array of fields to populate.\r\n   * @param {number} [options.offset] - Number of documents to skip before starting to collect the result set.\r\n   * @return {Promise<NaroDocument[]>} A promise that resolves to an array of documents matching the specified filters and limits, with populated fields.\r\n   * @throws {Error} If the specified collection or referenced collection does not exist.\r\n   *\r\n   * @example\r\n   * const users = await db.getAll(\"users\", {\r\n   *   filters: [{ field: \"age\", operator: \">=\", value: 18 }],\r\n   *   limit: 10,\r\n   *   populate: [\"profile\"]\r\n   * });\r\n   * console.log(users); // Logs up to 10 users aged 18 or older with populated \"profile\" field\r\n   */\r\n  async getAll(path: string, options: Options = {}): Promise<NaroDocument[]> {\r\n    const { collectionName } = NaroPath.validate(path);\r\n    if (this.host) return await this.serverRequest(\"getAll\", [path, options]);\r\n    const collection = _.cloneDeep(this.core.getCollection(collectionName));\r\n    const { filters, limit, populate, offset = 0 } = options;\r\n\r\n    let filteredCollection = collection;\r\n\r\n    filteredCollection = this.filterCollection(filteredCollection, filters || []);\r\n    filteredCollection = filteredCollection.slice(offset);\r\n    filteredCollection = this.limitDocuments(filteredCollection, limit);\r\n    filteredCollection = await this.populateCollection(filteredCollection, populate);\r\n\r\n    return filteredCollection;\r\n  }\r\n\r\n  /**\r\n   * Filters a collection of `NaroDocument` objects based on the specified query filters.\r\n   *\r\n   * @param {NaroDocument[]} docs - The array of `NaroDocument` objects to be filtered.\r\n   * @param {Query[]} filters - An array of query objects, each containing `field`, `operator`, and `value`,\r\n   *                             which define the filter criteria.\r\n   * @return {NaroDocument[]} A new array of `NaroDocument` objects that satisfy all the specified filters.\r\n   */\r\n  private filterCollection(docs: NaroDocument[], filters: Query[]): NaroDocument[] {\r\n    if (!filters.every(q => [\"==\", \"!=\", \"<\", \"<=\", \">\", \">=\"].includes(q.operator))) throw new Error(\"Invalid operator in filter\");\r\n    return docs.filter(doc =>\r\n      filters.every((q: Query) => {\r\n        const { field, operator, value } = q;\r\n        const docValue = doc[field];\r\n        switch (operator) {\r\n          case \"==\":\r\n            return docValue == value;\r\n          case \"!=\":\r\n            return docValue != value;\r\n          case \"<\":\r\n            return typeof docValue === \"number\" && typeof value === \"number\" && !Number.isNaN(docValue) && !Number.isNaN(value) && docValue < value;\r\n          case \"<=\":\r\n            return typeof docValue === \"number\" && typeof value === \"number\" && !Number.isNaN(docValue) && !Number.isNaN(value) && docValue <= value;\r\n          case \">\":\r\n            return typeof docValue === \"number\" && typeof value === \"number\" && !Number.isNaN(docValue) && !Number.isNaN(value) && docValue > value;\r\n          case \">=\":\r\n            return typeof docValue === \"number\" && typeof value === \"number\" && !Number.isNaN(docValue) && !Number.isNaN(value) && docValue >= value;\r\n        }\r\n      })\r\n    );\r\n  }\r\n\r\n  /**\r\n   * Populates the specified fields of a document with their corresponding referenced documents.\r\n   *\r\n   * @param {NaroDocument} doc - The document to be populated.\r\n   * @param {string[] | undefined} populateFields - An array of field names to populate, or undefined if no fields are specified.\r\n   * @return {Promise<NaroDocument>} A promise that resolves to the populated document.\r\n   *\r\n   * @example\r\n   * const db = new Naro(\"myDatabase\");\r\n   *\r\n   * const profile = await db.add(\"profiles\", { bio: \"Software Developer\", skills: [\"TypeScript\", \"Node.js\"] });\r\n   * const user = await db.add(\"users\", { name: \"John Doe\", profile: `profiles/${profile.id}` });\r\n   *\r\n   * const populatedUser = await db.populate(user, [\"profile\"]);\r\n   * console.log(populatedUser);\r\n   * // Output:\r\n   * // {\r\n   * //   id: \"generated-id\",\r\n   * //   createdAt: 1696872345000,\r\n   * //   name: \"John Doe\",\r\n   * //   profile: {\r\n   * //     id: \"generated-id\",\r\n   * //     createdAt: 1696872345000,\r\n   * //     bio: \"Software Developer\",\r\n   * //     skills: [\"TypeScript\", \"Node.js\"]\r\n   * //     path: \"profiles/generated-id\"\r\n   * //   },\r\n   * //     path: \"users/generated-id\"\r\n   * // }\r\n   */\r\n  async populate(doc: NaroDocument, populateFields: string[] | undefined): Promise<NaroDocument> {\r\n    if (!populateFields) return doc;\r\n    if (!populateFields.length) throw new Error(\"Populate fields cannot be an empty array\");\r\n    if (this.host) return await this.serverRequest(\"populate\", [doc, populateFields]);\r\n\r\n    await Promise.all(populateFields.map(async (field) => {\r\n      const refPath = doc[field];\r\n      if (typeof refPath === \"string\") {\r\n        const refDoc = await this.get(refPath);\r\n        if (refDoc) {\r\n          doc[field] = refDoc;\r\n        }\r\n      }\r\n    }));\r\n\r\n    return _.cloneDeep(doc);\r\n  }\r\n\r\n  /**\r\n   * Populates the specified fields within a collection of documents.\r\n   *\r\n   * @param {NaroDocument[]} docs - The collection of documents to be populated.\r\n   * @param {string[] | undefined} populateFields - The fields to populate within each document. If undefined or empty, no fields are populated.\r\n   * @return {Promise<NaroDocument[]>} A promise resolving to the collection of documents with the specified fields populated.\r\n   *\r\n   * @example\r\n   * const db = new Naro(\"myDatabase\");\r\n   *\r\n   * const profile = await db.add(\"profiles\", { bio: \"Engineer\", skills: [\"JavaScript\", \"TypeScript\"] });\r\n   * const user1 = await db.add(\"users\", { name: \"Alice\", profile: `profiles/${profile.id}` });\r\n   * const user2 = await db.add(\"users\", { name: \"Bob\", profile: `profiles/${profile.id}` });\r\n   *\r\n   * const populatedUsers = await db.populateCollection([user1, user2], [\"profile\"]);\r\n   * console.log(populatedUsers);\r\n   * // Output:\r\n   * // [\r\n   * //   {\r\n   * //     id: \"generated-id\",\r\n   * //     createdAt: 1696872345000,\r\n   * //     name: \"Alice\",\r\n   * //     profile: {\r\n   * //       id: \"generated-id\",\r\n   * //       createdAt: 1696872345000,\r\n   * //       bio: \"Engineer\",\r\n   * //       skills: [\"JavaScript\", \"TypeScript\"],\r\n   * //       path: \"profiles/generated-id\"\r\n   * //     }\r\n   * //     path: \"users/generated-id\"\r\n   * //   },\r\n   * //   {\r\n   * //     id: \"generated-id\",\r\n   * //     createdAt: 1696872345000,\r\n   * //     name: \"Bob\",\r\n   * //     profile: {\r\n   * //       id: \"generated-id\",\r\n   * //       createdAt: 1696872345000,\r\n   * //       bio: \"Engineer\",\r\n   * //       skills: [\"JavaScript\", \"TypeScript\"],\r\n   * //       path: \"profiles/generated-id\"\r\n   * //     },\r\n   * //     path: \"users/generated-id\"\r\n   * //   }\r\n   * // ]\r\n   */\r\n  async populateCollection(docs: NaroDocument[], populateFields: string[] | undefined): Promise<NaroDocument[]> {\r\n    if (!populateFields || populateFields.length === 0) return docs;\r\n    return Promise.all(docs.map(doc => this.populate(doc, populateFields)));\r\n  }\r\n\r\n  /**\r\n   * Limits the number of documents in a collection to the specified limit.\r\n   *\r\n   * @param {NaroDocument[]} collection - The collection of documents to limit.\r\n   * @param {number} [limit] - The maximum number of documents to include. If undefined, the entire collection is returned.\r\n   * @return {NaroDocument[]} A new array containing up to the specified number of documents.\r\n   *\r\n   * @example\r\n   * const documents = [\r\n   *   { id: \"1\", createdAt: 1696872345000, path: \"items/1\" },\r\n   *   { id: \"2\", createdAt: 1696872346000, path: \"items/2\" },\r\n   *   { id: \"3\", createdAt: 1696872347000, path: \"items/3\" }\r\n   * ];\r\n   *\r\n   * const limitedDocuments = limitDocuments(documents, 2);\r\n   * console.log(limitedDocuments);\r\n   * // Output:\r\n   * // [\r\n   * //   { id: \"1\", createdAt: 1696872345000, path: \"items/1\" },\r\n   * //   { id: \"2\", createdAt: 1696872346000, path: \"items/2\" }\r\n   * // ]\r\n   */\r\n  private limitDocuments(collection: NaroDocument[], limit?: number): NaroDocument[] {\r\n    if (limit === undefined) return collection;\r\n    return collection.slice(0, limit);\r\n  }\r\n\r\n  /**\r\n   * Retrieves a document from the given path.\r\n   *\r\n   * @param {string} path - The path of the document to retrieve.\r\n   * @return {Promise<NaroDocument | undefined>} A promise that resolves to the retrieved document\r\n   * or undefined if the document is not found.\r\n   *\r\n   * @example\r\n   * const db = new Naro(\"myDatabase\");\r\n   *\r\n   * const user = await db.get(\"users/123\");\r\n   * console.log(user);\r\n   * // Output: { id: \"123\", createdAt: 1696872345000, name: \"John Doe\", age: 30 } (if found)\r\n   */\r\n  async get(path: string): Promise<NaroDocument | undefined> {\r\n    const { collectionName, collectionId } = NaroPath.validate(path);\r\n    if (this.host) return await this.serverRequest(\"get\", [path]);\r\n    const collection = this.core.getCollection(collectionName);\r\n    return _.find(collection, (item: any) => item.id === collectionId) || undefined;\r\n  }\r\n\r\n  /**\r\n   * Updates a document within a specified collection.\r\n   *\r\n   * @param {string} path - The path to the document, which includes collection name and document ID.\r\n   * @param {any} data - The new data to merge with the existing document.\r\n   * @return {Promise<NaroDocument>} A promise that resolves to the updated document.\r\n   *\r\n   * @example\r\n   * const db = new Naro(\"myDatabase\");\r\n   *\r\n   * const initialUser = await db.add(\"users\", { name: \"John Doe\", age: 25 });\r\n   * const updatedUser = await db.update(`users/${initialUser.id}`, { age: 30 });\r\n   * console.log(updatedUser);\r\n   * // Output: { id: \"generated-id\", createdAt: 1696872345000, name: \"John Doe\", age: 30 }\r\n   */\r\n  async update(path: string, data: any): Promise<NaroDocument> {\r\n    const { collectionName, collectionId } = NaroPath.validate(path);\r\n    if (!collectionId) throw new Error(\"Collection ID is required\");\r\n    if (this.host) return await this.serverRequest(\"update\", [path, data]);\r\n    const collection = this.core.getCollection(collectionName);\r\n    const itemIndex = _.findIndex(collection, (item: any) => item.id === collectionId);\r\n    if (itemIndex === -1) throw new Error(\"Item not found\");\r\n    const existingDocument = collection[itemIndex];\r\n    const updateData = _.omit(data, [\"id\", \"path\", \"createdAt\"]);\r\n    collection[itemIndex] = { ...existingDocument, ...updateData };\r\n    this.core.updateCollection(collectionName, collection);\r\n    return collection[itemIndex];\r\n  }\r\n\r\n  /**\r\n   * Deletes an item from the specified collection based on the given path.\r\n   * If the ID does not exist, the method does nothing.\r\n   *\r\n   * @param {string} path - The path identifying the collection and the item to delete.\r\n   * @return {Promise<void>} A promise that resolves when the deletion is complete.\r\n   *\r\n   * @example\r\n   * const db = new Naro(\"myDatabase\");\r\n   *\r\n   * // Adding a new user\r\n   * const user = await db.add(\"users\", { name: \"Jane Doe\", age: 28 });\r\n   * console.log(await db.getAll(\"users\")); // Output: [{ id: \"generated-id\", name: \"Jane Doe\", age: 28, createdAt: 1696872345000 }]\r\n   *\r\n   * // Deleting the user\r\n   * await db.delete(`users/${user.id}`);\r\n   * console.log(await db.getAll(\"users\")); // Output: []\r\n   */\r\n  async delete(path: string): Promise<void> {\r\n    const { collectionName, collectionId } = NaroPath.validate(path);\r\n    if (!collectionId) throw new Error(\"Collection ID is required\");\r\n    if (this.host) return await this.serverRequest(\"delete\", [path]);\r\n    const collection = this.core.getCollection(collectionName);\r\n    const itemIndex = _.findIndex(collection, (item: any) => item.id === collectionId);\r\n    if (itemIndex === -1 || !collection[itemIndex]) return;\r\n    collection.splice(itemIndex, 1);\r\n    this.core.updateCollection(collectionName, collection);\r\n  }\r\n\r\n  /**\r\n   * Checks if a document exists in the specified collection based on the given path.\r\n   *\r\n   * @param {string} path - The path to the document, which includes the collection name and document ID.\r\n   *                        The path should follow the format: 'collectionName/id'.\r\n   * @return {Promise<boolean>} A promise that resolves to `true` if the document exists, or `false` otherwise.\r\n   *\r\n   * @example\r\n   * const db = new Naro(\"myDatabase\");\r\n   *\r\n   * const exists = await db.exists(\"users/123\");\r\n   * console.log(exists); // Output: true or false\r\n   */\r\n  async exists(path: string): Promise<boolean> {\r\n    const { collectionName, collectionId } = NaroPath.validate(path);\r\n    if (!collectionId) throw new Error(\"Collection ID is required\");\r\n    if (this.host) return await this.serverRequest(\"exists\", [path]);\r\n    const collection = this.core.getCollection(collectionName);\r\n    return _.some(collection, (item: any) => item.id === collectionId);\r\n  }\r\n\r\n  /**\r\n   * Counts the number of documents in a specified collection.\r\n   *\r\n   * @param {string} path - The name of the collection to count documents in.\r\n   * @return {Promise<number>} A promise that resolves to the number of documents in the collection.\r\n   *\r\n   * @example\r\n   * const db = new Naro(\"myDatabase\");\r\n   *\r\n   * const count = await db.count(\"users\");\r\n   * console.log(count); // Output: 5 (if there are 5 documents in the \"users\" collection)\r\n   */\r\n  async count(path: string): Promise<number> {\r\n    const { collectionName } = NaroPath.validate(path);\r\n    if (this.host) return await this.serverRequest(\"count\", [path]);\r\n    const collection = this.core.getCollection(collectionName);\r\n    return collection.length;\r\n  }\r\n\r\n  /**\r\n   * Deletes all documents in a specified collection.\r\n   *\r\n   * @param {string} path - The name of the collection to clear.\r\n   * @return {Promise<void>} A promise that resolves when the collection is cleared.\r\n   *\r\n   * @example\r\n   * const db = new Naro(\"myDatabase\");\r\n   *\r\n   * await db.clear(\"users\");\r\n   * console.log(await db.getAll(\"users\")); // Output: []\r\n   */\r\n  async clear(path: string): Promise<void> {\r\n    const { collectionName, collectionId } = NaroPath.validate(path);\r\n    if (collectionId) throw new Error(\"Collection ID detected. Use delete method instead.\");\r\n    if (this.host) return await this.serverRequest(\"clear\", [path]);\r\n    this.core.removeCollection(collectionName);\r\n  }\r\n\r\n  /**\r\n   * Retrieves all collections in the database as a structured object.\r\n   * Each key in the returned object represents a collection name,\r\n   * and the value is an array of documents within that collection.\r\n   *\r\n   * @return {Record<string, NaroDocument[]>} An object containing all collections\r\n   * and their respective documents.\r\n   */\r\n  async getStructuredCollections(): Promise<Record<string, NaroDocument[]>> {\r\n    if (this.host) return this.serverRequest(\"getStructuredCollections\", []);\r\n    return this.core.getStructuredCollections();\r\n  }\r\n}\r\n"],"names":["NaroFiler","ensureDirectory","path","jetpack","dir","readBinaryFile","data","read","decode","writeBinaryFile","write","encode","listDirectories","directory","inspectTree","children","filter","child","type","map","name","removeDirectory","remove","Core","rootPath","this","collections","logFileName","_proto","prototype","initialize","loadCollections","getStructuredCollections","_step","_iterator","_createForOfIteratorHelperLoose","done","folderName","value","dataPath","file","getCollection","updateCollection","_","cloneDeep","writeCollections","_this","Object","keys","forEach","collectionName","writeCollection","collectionPath","removeCollection","NaroPath","validate","test","includes","Error","endsWith","pathParts","split","length","collectionId","subCollectionName","subCollectionId","NaroId","generate","Date","now","toString","Math","random","slice","Naro","dbName","options","core","host","orgId","projectId","URI","_options$URI$split","process","cwd","registerProcessListeners","cleanUpAndExit","exitCode","removeAllListeners","undefined","exit","Promise","resolve","e","reject","setMaxListeners","Infinity","on","writeToDisk","add","_exit","_temp2","_result","collection","_this3","id","source","createdAt","newItem","assign","push","_temp","serverRequest","then","_await$_this3$serverR","method","params","_this4","axios","post","response","error","_catch","set","_exit2","_temp4","_result2","_this5","existingIndex","findIndex","item","_NaroPath$validate2","_temp3","_await$_this5$serverR","getAll","_exit3","_temp6","_result3","_this6","limit","populate","_options$offset","offset","filteredCollection","filterCollection","filters","limitDocuments","populateCollection","_this6$populateCollec","_temp5","_await$_this6$serverR","docs","every","q","operator","doc","docValue","field","Number","isNaN","populateFields","_temp8","_exit4","_result4","all","refPath","_temp9","_this7","get","refDoc","_temp7","_await$_this7$serverR","_this8","_temp1","_exit5","_result5","_this9","find","_NaroPath$validate4","_temp0","_await$_this9$serverR","update","_exit6","_temp11","_result6","_this0","itemIndex","existingDocument","updateData","omit","_extends","_NaroPath$validate5","_temp10","_await$_this0$serverR","_exit7","_temp13","_result7","_this1","splice","_NaroPath$validate6","_temp12","_await$_this1$serverR","exists","_exit8","_temp15","_result8","_this10","some","_NaroPath$validate7","_temp14","_await$_this10$server","count","_exit9","_temp17","_result9","_this11","_temp16","_await$_this11$server","clear","_temp19","_exit0","_result0","_this12","_NaroPath$validate9","_temp18","_await$_this12$server","_this13"],"mappings":"2bAGaA,mCAASA,IAAA,QAAAA,EACbC,gBAAP,SAAuBC,GACrBC,EAAQC,IAAIF,EACd,EAACF,EAEMK,eAAP,SAAsBH,GACpB,IAAMI,EAAOH,EAAQI,KAAKL,EAAM,UAChC,OAAOI,EAAOE,EAAOF,GAAQ,EAC/B,EAACN,EAEMS,gBAAP,SAAuBP,EAAcI,GACnC,OAAOH,EAAQO,MAAMR,EAAMS,EAAOL,GACpC,EAACN,EAEMY,gBAAP,SAAuBV,GACrB,IAAMW,EAAYV,E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