@tailor-platform/sdk 1.17.1 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/{application-BMDE8KqK.mjs → application-A6PZjujv.mjs} +192 -1673
  3. package/dist/application-A6PZjujv.mjs.map +1 -0
  4. package/dist/application-nPS5veK6.mjs +9 -0
  5. package/dist/brand-BZJCv6UY.mjs +28 -0
  6. package/dist/brand-BZJCv6UY.mjs.map +1 -0
  7. package/dist/cli/index.mjs +40 -20
  8. package/dist/cli/index.mjs.map +1 -1
  9. package/dist/cli/lib.d.mts +16 -33
  10. package/dist/cli/lib.mjs +12 -5
  11. package/dist/cli/lib.mjs.map +1 -1
  12. package/dist/configure/index.d.mts +4 -4
  13. package/dist/configure/index.mjs +10 -19
  14. package/dist/configure/index.mjs.map +1 -1
  15. package/dist/enum-constants-CGVvu3dd.mjs +115 -0
  16. package/dist/enum-constants-CGVvu3dd.mjs.map +1 -0
  17. package/dist/file-utils-GX_tGWl4.mjs +139 -0
  18. package/dist/file-utils-GX_tGWl4.mjs.map +1 -0
  19. package/dist/index-B6pvy1MK.d.mts +20 -0
  20. package/dist/index-B91ZpOcd.d.mts +18 -0
  21. package/dist/index-CPzbMghQ.d.mts +18 -0
  22. package/dist/{index-CVcYqZSf.d.mts → index-ClLZCbcm.d.mts} +18 -5
  23. package/dist/index-DDqKNFh4.d.mts +18 -0
  24. package/dist/interceptor-D8MeZOxX.mjs +33 -0
  25. package/dist/interceptor-D8MeZOxX.mjs.map +1 -0
  26. package/dist/{jiti-BrELlEYT.mjs → jiti-DfS9jItj.mjs} +2 -2
  27. package/dist/{jiti-BrELlEYT.mjs.map → jiti-DfS9jItj.mjs.map} +1 -1
  28. package/dist/{job-CULA2Pvf.mjs → job-2Q82qQ6N.mjs} +27 -5
  29. package/dist/job-2Q82qQ6N.mjs.map +1 -0
  30. package/dist/kysely-type-Cpq5TNGY.mjs +260 -0
  31. package/dist/kysely-type-Cpq5TNGY.mjs.map +1 -0
  32. package/dist/package-json-DUY2kB6z.mjs +17 -0
  33. package/dist/package-json-DUY2kB6z.mjs.map +1 -0
  34. package/dist/package-json-Dd1AnA5F.mjs +3 -0
  35. package/dist/plugin/builtin/enum-constants/index.d.mts +4 -0
  36. package/dist/plugin/builtin/enum-constants/index.mjs +3 -0
  37. package/dist/plugin/builtin/file-utils/index.d.mts +4 -0
  38. package/dist/plugin/builtin/file-utils/index.mjs +3 -0
  39. package/dist/plugin/builtin/kysely-type/index.d.mts +4 -0
  40. package/dist/plugin/builtin/kysely-type/index.mjs +3 -0
  41. package/dist/plugin/builtin/seed/index.d.mts +4 -0
  42. package/dist/plugin/builtin/seed/index.mjs +3 -0
  43. package/dist/plugin/index.d.mts +3 -3
  44. package/dist/plugin/index.mjs +11 -11
  45. package/dist/plugin/index.mjs.map +1 -1
  46. package/dist/{schema-R5TxC5Pn.mjs → schema-D5Cpd8fQ.mjs} +48 -5
  47. package/dist/schema-D5Cpd8fQ.mjs.map +1 -0
  48. package/dist/seed-CeUEANfQ.mjs +1050 -0
  49. package/dist/seed-CeUEANfQ.mjs.map +1 -0
  50. package/dist/{src-DMROgdcL.mjs → src-Bb1UVstT.mjs} +2 -2
  51. package/dist/{src-DMROgdcL.mjs.map → src-Bb1UVstT.mjs.map} +1 -1
  52. package/dist/telemetry-9A1BZqbl.mjs +3 -0
  53. package/dist/telemetry-rFq0QdvJ.mjs +84 -0
  54. package/dist/telemetry-rFq0QdvJ.mjs.map +1 -0
  55. package/dist/types-CJF3Y1x8.d.mts +158 -0
  56. package/dist/{types-CZZBCaxB.d.mts → types-CblXasFV.d.mts} +1405 -1045
  57. package/dist/{types-b-ig8nW_.mjs → types-ClK_HJ0G.mjs} +1 -1
  58. package/dist/{types-b-ig8nW_.mjs.map → types-ClK_HJ0G.mjs.map} +1 -1
  59. package/dist/{update-CUBVjZbL.mjs → update-Cr5c7h1r.mjs} +485 -244
  60. package/dist/update-Cr5c7h1r.mjs.map +1 -0
  61. package/dist/utils/test/index.d.mts +4 -4
  62. package/dist/utils/test/index.mjs +3 -2
  63. package/dist/utils/test/index.mjs.map +1 -1
  64. package/docs/cli/application.md +106 -14
  65. package/docs/cli/auth.md +92 -12
  66. package/docs/cli/completion.md +18 -2
  67. package/docs/cli/executor.md +122 -14
  68. package/docs/cli/function.md +32 -4
  69. package/docs/cli/secret.md +134 -18
  70. package/docs/cli/staticwebsite.md +60 -8
  71. package/docs/cli/tailordb.md +148 -20
  72. package/docs/cli/user.md +154 -22
  73. package/docs/cli/workflow.md +100 -12
  74. package/docs/cli/workspace.md +274 -38
  75. package/docs/generator/custom.md +2 -2
  76. package/docs/plugin/custom.md +270 -163
  77. package/docs/plugin/index.md +48 -2
  78. package/package.json +28 -2
  79. package/dist/application-BMDE8KqK.mjs.map +0 -1
  80. package/dist/application-Dni_W16P.mjs +0 -4
  81. package/dist/job-CULA2Pvf.mjs.map +0 -1
  82. package/dist/schema-R5TxC5Pn.mjs.map +0 -1
  83. package/dist/types-DthzUFfx.d.mts +0 -372
  84. package/dist/update-CUBVjZbL.mjs.map +0 -1
  85. /package/dist/{chunk-GMkBE123.mjs → chunk-CqAI0b6X.mjs} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed-CeUEANfQ.mjs","names":[],"sources":["../src/plugin/builtin/seed/idp-user-processor.ts","../src/plugin/builtin/seed/lines-db-processor.ts","../src/plugin/builtin/seed/seed-type-processor.ts","../src/plugin/builtin/seed/index.ts"],"sourcesContent":["import ml from \"multiline-ts\";\nimport type { GeneratorAuthInput } from \"@/parser/plugin-config/generation-types\";\n\nexport interface IdpUserMetadata {\n name: \"_User\";\n dependencies: string[];\n dataFile: string;\n idpNamespace: string;\n schema: {\n usernameField: string;\n userTypeName: string;\n };\n}\n\n/**\n * Processes auth configuration to generate IdP user seed metadata\n * @param auth - Auth configuration from generator\n * @returns IdP user metadata or undefined if not applicable\n */\nexport function processIdpUser(auth: GeneratorAuthInput): IdpUserMetadata | undefined {\n // Only process if idProvider is BuiltInIdP and userProfile is defined\n if (auth.idProvider?.kind !== \"BuiltInIdP\" || !auth.userProfile) {\n return undefined;\n }\n\n const { typeName, usernameField } = auth.userProfile;\n\n return {\n name: \"_User\",\n dependencies: [typeName],\n dataFile: \"data/_User.jsonl\",\n idpNamespace: auth.idProvider.namespace,\n schema: {\n usernameField,\n userTypeName: typeName,\n },\n };\n}\n\n/**\n * Generates the server-side IDP seed script code for testExecScript execution.\n * Uses the global tailor.idp.Client - no bundling required.\n * @param idpNamespace - The IDP namespace name\n * @returns Script code string\n */\nexport function generateIdpSeedScriptCode(idpNamespace: string): string {\n return ml /* ts */ `\n export async function main(input) {\n const client = new tailor.idp.Client({ namespace: \"${idpNamespace}\" });\n const errors = [];\n let processed = 0;\n\n for (let i = 0; i < input.users.length; i++) {\n try {\n await client.createUser(input.users[i]);\n processed++;\n console.log(\\`[_User] \\${i + 1}/\\${input.users.length}: \\${input.users[i].name}\\`);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n errors.push(\\`Row \\${i} (\\${input.users[i].name}): \\${message}\\`);\n console.error(\\`[_User] Row \\${i} failed: \\${message}\\`);\n }\n }\n\n return {\n success: errors.length === 0,\n processed,\n errors,\n };\n }\n `;\n}\n\n/**\n * Generates the server-side IDP truncation script code for testExecScript execution.\n * Lists all users with pagination and deletes each one.\n * @param idpNamespace - The IDP namespace name\n * @returns Script code string\n */\nexport function generateIdpTruncateScriptCode(idpNamespace: string): string {\n return ml /* ts */ `\n export async function main() {\n const client = new tailor.idp.Client({ namespace: \"${idpNamespace}\" });\n const errors = [];\n let deleted = 0;\n\n // List all users with pagination\n let nextToken = undefined;\n const allUsers = [];\n do {\n const response = await client.users(nextToken ? { nextToken } : undefined);\n allUsers.push(...(response.users || []));\n nextToken = response.nextToken;\n } while (nextToken);\n\n console.log(\\`Found \\${allUsers.length} IDP users to delete\\`);\n\n for (const user of allUsers) {\n try {\n await client.deleteUser(user.id);\n deleted++;\n console.log(\\`[_User] Deleted \\${deleted}/\\${allUsers.length}: \\${user.name}\\`);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n errors.push(\\`User \\${user.id} (\\${user.name}): \\${message}\\`);\n console.error(\\`[_User] Delete failed for \\${user.name}: \\${message}\\`);\n }\n }\n\n return {\n success: errors.length === 0,\n deleted,\n total: allUsers.length,\n errors,\n };\n }\n `;\n}\n\n/**\n * Generates the schema file content for IdP users with foreign key\n * @param usernameField - Username field name\n * @param userTypeName - TailorDB user type name\n * @returns Schema file contents\n */\nexport function generateIdpUserSchemaFile(usernameField: string, userTypeName: string): string {\n return ml /* ts */ `\n import { t } from \"@tailor-platform/sdk\";\n import { createStandardSchema } from \"@tailor-platform/sdk/test\";\n import { defineSchema } from \"@toiroakr/lines-db\";\n\n const schemaType = t.object({\n name: t.string(),\n password: t.string(),\n });\n\n // Simple identity hook for _User (no TailorDB backing type)\n const hook = <T>(data: unknown) => data as T;\n\n export const schema = defineSchema(\n createStandardSchema(schemaType, hook),\n {\n primaryKey: \"name\",\n indexes: [\n { name: \"_user_name_unique_idx\", columns: [\"name\"], unique: true },\n ],\n foreignKeys: [\n {\n column: \"name\",\n references: {\n table: \"${userTypeName}\",\n column: \"${usernameField}\",\n },\n },\n ],\n }\n );\n\n `;\n}\n","import ml from \"multiline-ts\";\nimport {\n isPluginGeneratedType,\n type PluginGeneratedTypeSource,\n type TailorDBType,\n type TypeSourceInfoEntry,\n} from \"@/parser/service/tailordb/types\";\nimport type { LinesDbMetadata } from \"./types\";\nimport type { ForeignKeyDefinition, IndexDefinition } from \"@toiroakr/lines-db\";\n\n/**\n * Processes TailorDB types to generate lines-db metadata\n * @param type - Parsed TailorDB type\n * @param source - Source file info\n * @returns Generated lines-db metadata\n */\nexport function processLinesDb(type: TailorDBType, source: TypeSourceInfoEntry): LinesDbMetadata {\n if (isPluginGeneratedType(source)) {\n // Plugin-generated type\n return processLinesDbForPluginType(type, source);\n }\n\n // User-defined type\n if (!source.filePath) {\n throw new Error(`Missing source info for type ${type.name}`);\n }\n if (!source.exportName) {\n throw new Error(`Missing export name for type ${type.name}`);\n }\n\n const { optionalFields, omitFields, indexes, foreignKeys } = extractFieldMetadata(type);\n\n return {\n typeName: type.name,\n exportName: source.exportName,\n importPath: source.filePath,\n optionalFields,\n omitFields,\n foreignKeys,\n indexes,\n };\n}\n\n/**\n * Process lines-db metadata for plugin-generated types\n * @param type - Parsed TailorDB type\n * @param source - Plugin-generated type source info\n * @returns Generated lines-db metadata with plugin source\n */\nfunction processLinesDbForPluginType(\n type: TailorDBType,\n source: PluginGeneratedTypeSource,\n): LinesDbMetadata {\n const { optionalFields, omitFields, indexes, foreignKeys } = extractFieldMetadata(type);\n\n return {\n typeName: type.name,\n exportName: source.exportName,\n importPath: \"\",\n optionalFields,\n omitFields,\n foreignKeys,\n indexes,\n pluginSource: source,\n };\n}\n\n/**\n * Extract field metadata from TailorDB type\n * @param type - Parsed TailorDB type\n * @returns Field metadata including optional fields, omit fields, indexes, and foreign keys\n */\nfunction extractFieldMetadata(type: TailorDBType): {\n optionalFields: string[];\n omitFields: string[];\n indexes: IndexDefinition[];\n foreignKeys: ForeignKeyDefinition[];\n} {\n const optionalFields = [\"id\"]; // id is always optional\n const omitFields: string[] = [];\n const indexes: IndexDefinition[] = [];\n const foreignKeys: ForeignKeyDefinition[] = [];\n\n // Find fields with hooks.create or serial\n for (const [fieldName, field] of Object.entries(type.fields)) {\n if (field.config.hooks?.create) {\n optionalFields.push(fieldName);\n }\n // Serial fields are auto-generated, so they should be optional in seed data\n if (field.config.serial) {\n omitFields.push(fieldName);\n }\n if (field.config.unique) {\n indexes.push({\n name: `${type.name.toLowerCase()}_${fieldName}_unique_idx`,\n columns: [fieldName],\n unique: true,\n });\n }\n }\n\n // Extract indexes\n if (type.indexes) {\n for (const [indexName, indexDef] of Object.entries(type.indexes)) {\n indexes.push({\n name: indexName,\n columns: indexDef.fields,\n unique: indexDef.unique,\n });\n }\n }\n\n // Extract foreign keys from relations\n for (const [fieldName, field] of Object.entries(type.fields)) {\n if (field.relation) {\n foreignKeys.push({\n column: fieldName,\n references: {\n table: field.relation.targetType,\n column: field.relation.key,\n },\n });\n }\n }\n\n return { optionalFields, omitFields, indexes, foreignKeys };\n}\n\n/**\n * Generate schema options code for lines-db\n * @param foreignKeys - Foreign key definitions\n * @param indexes - Index definitions\n * @returns Schema options code string\n */\nfunction generateSchemaOptions(\n foreignKeys: ForeignKeyDefinition[],\n indexes: IndexDefinition[],\n): string {\n const schemaOptions: string[] = [];\n\n if (foreignKeys.length > 0) {\n schemaOptions.push(`foreignKeys: [`);\n foreignKeys.forEach((fk) => {\n schemaOptions.push(` ${JSON.stringify(fk)},`);\n });\n schemaOptions.push(`],`);\n }\n\n if (indexes.length > 0) {\n schemaOptions.push(`indexes: [`);\n indexes.forEach((index) => {\n schemaOptions.push(` ${JSON.stringify(index)},`);\n });\n schemaOptions.push(\"],\");\n }\n\n return schemaOptions.length > 0\n ? [\"\\n {\", ...schemaOptions.map((option) => ` ${option}`), \" }\"].join(\"\\n\")\n : \"\";\n}\n\n/**\n * Generates the schema file content for lines-db (for user-defined types with import)\n * @param metadata - lines-db metadata\n * @param importPath - Import path for the TailorDB type\n * @returns Schema file contents\n */\nexport function generateLinesDbSchemaFile(metadata: LinesDbMetadata, importPath: string): string {\n const { exportName, optionalFields, omitFields, foreignKeys, indexes } = metadata;\n\n const schemaTypeCode = ml /* ts */ `\n const schemaType = t.object({\n ...${exportName}.pickFields(${JSON.stringify(optionalFields)}, { optional: true }),\n ...${exportName}.omitFields(${JSON.stringify([...optionalFields, ...omitFields])}),\n });\n `;\n\n const schemaOptionsCode = generateSchemaOptions(foreignKeys, indexes);\n\n return ml /* ts */ `\n import { t } from \"@tailor-platform/sdk\";\n import { createTailorDBHook, createStandardSchema } from \"@tailor-platform/sdk/test\";\n import { defineSchema } from \"@toiroakr/lines-db\";\n import { ${exportName} } from \"${importPath}\";\n\n ${schemaTypeCode}\n\n const hook = createTailorDBHook(${exportName});\n\n export const schema = defineSchema(\n createStandardSchema(schemaType, hook),${schemaOptionsCode}\n );\n\n `;\n}\n\n/**\n * Parameters for generating plugin-type schema file\n */\nexport interface PluginSchemaParams {\n /** Relative path from schema output to tailor.config.ts */\n configImportPath: string;\n /** Relative import path to the original type file (for type-attached plugins) */\n originalImportPath?: string;\n}\n\n/**\n * Generates the schema file content using getGeneratedType API\n * (for plugin-generated types)\n * @param metadata - lines-db metadata (must have pluginSource)\n * @param params - Plugin import paths\n * @returns Schema file contents\n */\nexport function generateLinesDbSchemaFileWithPluginAPI(\n metadata: LinesDbMetadata,\n params: PluginSchemaParams,\n): string {\n const { typeName, exportName, optionalFields, omitFields, foreignKeys, indexes, pluginSource } =\n metadata;\n\n if (!pluginSource) {\n throw new Error(`pluginSource is required for plugin-generated type \"${typeName}\"`);\n }\n\n const { configImportPath, originalImportPath } = params;\n\n const schemaTypeCode = ml /* ts */ `\n const schemaType = t.object({\n ...${exportName}.pickFields(${JSON.stringify(optionalFields)}, { optional: true }),\n ...${exportName}.omitFields(${JSON.stringify([...optionalFields, ...omitFields])}),\n });\n `;\n\n const schemaOptionsCode = generateSchemaOptions(foreignKeys, indexes);\n\n // Type-attached plugin (e.g., changeset): import original type and use getGeneratedType(configPath, pluginId, type, kind)\n if (pluginSource.originalExportName && originalImportPath && pluginSource.generatedTypeKind) {\n return ml /* ts */ `\n import { join } from \"node:path\";\n import { t } from \"@tailor-platform/sdk\";\n import { getGeneratedType } from \"@tailor-platform/sdk/plugin\";\n import { createTailorDBHook, createStandardSchema } from \"@tailor-platform/sdk/test\";\n import { defineSchema } from \"@toiroakr/lines-db\";\n import { ${pluginSource.originalExportName} } from \"${originalImportPath}\";\n\n const configPath = join(import.meta.dirname, \"${configImportPath}\");\n const ${exportName} = await getGeneratedType(configPath, \"${pluginSource.pluginId}\", ${pluginSource.originalExportName}, \"${pluginSource.generatedTypeKind}\");\n\n ${schemaTypeCode}\n\n const hook = createTailorDBHook(${exportName});\n\n export const schema = defineSchema(\n createStandardSchema(schemaType, hook),${schemaOptionsCode}\n );\n\n `;\n }\n\n // Namespace plugin (e.g., audit-log): use getGeneratedType(configPath, pluginId, null, kind)\n // For namespace plugins, generatedTypeKind is required\n if (!pluginSource.generatedTypeKind) {\n throw new Error(\n `Namespace plugin \"${pluginSource.pluginId}\" must provide generatedTypeKind for type \"${typeName}\"`,\n );\n }\n\n return ml /* ts */ `\n import { join } from \"node:path\";\n import { t } from \"@tailor-platform/sdk\";\n import { getGeneratedType } from \"@tailor-platform/sdk/plugin\";\n import { createTailorDBHook, createStandardSchema } from \"@tailor-platform/sdk/test\";\n import { defineSchema } from \"@toiroakr/lines-db\";\n\n const configPath = join(import.meta.dirname, \"${configImportPath}\");\n const ${exportName} = await getGeneratedType(configPath, \"${pluginSource.pluginId}\", null, \"${pluginSource.generatedTypeKind}\");\n\n ${schemaTypeCode}\n\n const hook = createTailorDBHook(${exportName});\n\n export const schema = defineSchema(\n createStandardSchema(schemaType, hook),${schemaOptionsCode}\n );\n\n `;\n}\n","import type { SeedTypeInfo } from \"./types\";\nimport type { TailorDBType } from \"@/parser/service/tailordb/types\";\n\n/**\n * Processes TailorDB types to extract seed type information\n * @param type - Parsed TailorDB type\n * @param namespace - Namespace of the type\n * @returns Seed type information\n */\nexport function processSeedTypeInfo(type: TailorDBType, namespace: string): SeedTypeInfo {\n // Extract dependencies from relations (including keyOnly which only sets foreignKeyType)\n const dependencies = Array.from(\n Object.values(type.fields).reduce<Set<string>>((set, field) => {\n const targetType = field.relation?.targetType ?? field.config.foreignKeyType;\n if (targetType && targetType !== type.name) {\n set.add(targetType);\n }\n return set;\n }, new Set<string>()),\n );\n\n return {\n name: type.name,\n namespace,\n dependencies,\n dataFile: `data/${type.name}.jsonl`,\n };\n}\n","import ml from \"multiline-ts\";\nimport * as path from \"pathe\";\nimport {\n processIdpUser,\n generateIdpUserSchemaFile,\n generateIdpSeedScriptCode,\n generateIdpTruncateScriptCode,\n} from \"./idp-user-processor\";\nimport {\n processLinesDb,\n generateLinesDbSchemaFile,\n generateLinesDbSchemaFileWithPluginAPI,\n type PluginSchemaParams,\n} from \"./lines-db-processor\";\nimport { processSeedTypeInfo } from \"./seed-type-processor\";\nimport type {\n GeneratorResult,\n TailorDBReadyContext,\n} from \"@/parser/plugin-config/generation-types\";\nimport type { Plugin } from \"@/parser/plugin-config/types\";\n\nexport const SeedGeneratorID = \"@tailor-platform/seed\";\n\ntype SeedPluginOptions = {\n distPath: string;\n machineUserName?: string;\n};\n\ntype NamespaceConfig = {\n namespace: string;\n types: string[];\n dependencies: Record<string, string[]>;\n};\n\n/**\n * Generate the IdP user seed function code using tailor.idp.Client via testExecScript\n * @param hasIdpUser - Whether IdP user is included\n * @param idpNamespace - The IDP namespace name\n * @returns JavaScript code for IdP user seeding function\n */\nfunction generateIdpUserSeedFunction(hasIdpUser: boolean, idpNamespace: string | null): string {\n if (!hasIdpUser || !idpNamespace) return \"\";\n\n const scriptCode = generateIdpSeedScriptCode(idpNamespace);\n\n return ml`\n // Seed _User via tailor.idp.Client (server-side)\n const seedIdpUser = async () => {\n console.log(styleText(\"cyan\", \" Seeding _User via tailor.idp.Client...\"));\n const dataDir = join(configDir, \"data\");\n const data = loadSeedData(dataDir, [\"_User\"]);\n const rows = data[\"_User\"] || [];\n if (rows.length === 0) {\n console.log(styleText(\"dim\", \" No _User data to seed\"));\n return { success: true };\n }\n console.log(styleText(\"dim\", \\` Processing \\${rows.length} _User records...\\`));\n\n const idpSeedCode = \\/* js *\\/\\`${scriptCode.replace(/`/g, \"\\\\`\").replace(/\\$/g, \"\\\\$\")}\\`;\n\n const result = await executeScript({\n client: operatorClient,\n workspaceId,\n name: \"seed-idp-user.ts\",\n code: idpSeedCode,\n arg: JSON.stringify({ users: rows }),\n invoker: {\n namespace: authNamespace,\n machineUserName,\n },\n });\n\n if (result.logs) {\n for (const line of result.logs.split(\"\\\\n\").filter(Boolean)) {\n console.log(styleText(\"dim\", \\` \\${line}\\`));\n }\n }\n\n if (result.success) {\n let parsed;\n try {\n parsed = JSON.parse(result.result || \"{}\");\n } catch (e) {\n console.error(styleText(\"red\", \\` ✗ Failed to parse seed result: \\${e.message}\\`));\n return { success: false };\n }\n\n if (parsed.processed) {\n console.log(styleText(\"green\", \\` ✓ _User: \\${parsed.processed} rows processed\\`));\n }\n\n if (!parsed.success) {\n const errors = Array.isArray(parsed.errors) ? parsed.errors : [];\n for (const err of errors) {\n console.error(styleText(\"red\", \\` ✗ \\${err}\\`));\n }\n return { success: false };\n }\n\n return { success: true };\n } else {\n console.error(styleText(\"red\", \\` ✗ Seed failed: \\${result.error}\\`));\n return { success: false };\n }\n };\n `;\n}\n\n/**\n * Generate the IdP user seed call code\n * @param hasIdpUser - Whether IdP user is included\n * @returns JavaScript code for calling IdP user seeding\n */\nfunction generateIdpUserSeedCall(hasIdpUser: boolean): string {\n if (!hasIdpUser) return \"\";\n\n return ml`\n // Seed _User if included and not skipped\n const shouldSeedUser = !skipIdp && (!entitiesToProcess || entitiesToProcess.includes(\"_User\"));\n if (hasIdpUser && shouldSeedUser) {\n const result = await seedIdpUser();\n if (!result.success) {\n allSuccess = false;\n }\n }\n `;\n}\n\n/**\n * Generate the IdP user truncation function code using tailor.idp.Client via testExecScript\n * @param hasIdpUser - Whether IdP user is included\n * @param idpNamespace - The IDP namespace name\n * @returns JavaScript code for IdP user truncation function\n */\nfunction generateIdpUserTruncateFunction(hasIdpUser: boolean, idpNamespace: string | null): string {\n if (!hasIdpUser || !idpNamespace) return \"\";\n\n const scriptCode = generateIdpTruncateScriptCode(idpNamespace);\n\n return ml`\n // Truncate _User via tailor.idp.Client (server-side)\n const truncateIdpUser = async () => {\n console.log(styleText(\"cyan\", \"Truncating _User via tailor.idp.Client...\"));\n\n const idpTruncateCode = \\/* js *\\/\\`${scriptCode.replace(/`/g, \"\\\\`\").replace(/\\$/g, \"\\\\$\")}\\`;\n\n const result = await executeScript({\n client: operatorClient,\n workspaceId,\n name: \"truncate-idp-user.ts\",\n code: idpTruncateCode,\n arg: JSON.stringify({}),\n invoker: {\n namespace: authNamespace,\n machineUserName,\n },\n });\n\n if (result.logs) {\n for (const line of result.logs.split(\"\\\\n\").filter(Boolean)) {\n console.log(styleText(\"dim\", \\` \\${line}\\`));\n }\n }\n\n if (result.success) {\n let parsed;\n try {\n parsed = JSON.parse(result.result || \"{}\");\n } catch (e) {\n console.error(styleText(\"red\", \\` ✗ Failed to parse truncation result: \\${e.message}\\`));\n return { success: false };\n }\n\n if (parsed.deleted !== undefined) {\n console.log(styleText(\"green\", \\` ✓ _User: \\${parsed.deleted} users deleted\\`));\n }\n\n if (!parsed.success) {\n const errors = Array.isArray(parsed.errors) ? parsed.errors : [];\n for (const err of errors) {\n console.error(styleText(\"red\", \\` ✗ \\${err}\\`));\n }\n return { success: false };\n }\n\n return { success: true };\n } else {\n console.error(styleText(\"red\", \\` ✗ Truncation failed: \\${result.error}\\`));\n return { success: false };\n }\n };\n `;\n}\n\n/**\n * Generate the IdP user truncation call code within the truncate block\n * @param hasIdpUser - Whether IdP user is included\n * @returns JavaScript code for calling IdP user truncation\n */\nfunction generateIdpUserTruncateCall(hasIdpUser: boolean): string {\n if (!hasIdpUser) return \"\";\n\n return ml`\n // Truncate _User if applicable\n const shouldTruncateUser = !skipIdp && !hasNamespace && (!hasTypes || entitiesToProcess.includes(\"_User\"));\n if (hasIdpUser && shouldTruncateUser) {\n const truncResult = await truncateIdpUser();\n if (!truncResult.success) {\n console.error(styleText(\"red\", \"IDP user truncation failed.\"));\n process.exit(1);\n }\n }\n `;\n}\n\n/**\n * Generates the exec.mjs script content using testExecScript API for TailorDB types\n * and tailor.idp.Client for _User (IdP managed)\n * @param defaultMachineUserName - Default machine user name from generator config (can be overridden at runtime)\n * @param relativeConfigPath - Config path relative to exec script\n * @param namespaceConfigs - Namespace configurations with types and dependencies\n * @param hasIdpUser - Whether _User is included\n * @param idpNamespace - The IDP namespace name, or null if not applicable\n * @returns exec.mjs file contents\n */\nfunction generateExecScript(\n defaultMachineUserName: string | undefined,\n relativeConfigPath: string,\n namespaceConfigs: NamespaceConfig[],\n hasIdpUser: boolean,\n idpNamespace: string | null,\n): string {\n // Generate namespaceEntities object\n const namespaceEntitiesEntries = namespaceConfigs\n .map(({ namespace, types }) => {\n const entitiesFormatted = types.map((e) => ` \"${e}\",`).join(\"\\n\");\n return ` \"${namespace}\": [\\n${entitiesFormatted}\\n ]`;\n })\n .join(\",\\n\");\n\n // Generate dependency map for each namespace\n const namespaceDepsEntries = namespaceConfigs\n .map(({ namespace, dependencies }) => {\n const depsObj = Object.entries(dependencies)\n .map(([type, deps]) => ` \"${type}\": [${deps.map((d) => `\"${d}\"`).join(\", \")}]`)\n .join(\",\\n\");\n return ` \"${namespace}\": {\\n${depsObj}\\n }`;\n })\n .join(\",\\n\");\n\n return ml /* js */ `\n import { readFileSync } from \"node:fs\";\n import { join } from \"node:path\";\n import { parseArgs, styleText } from \"node:util\";\n import { createInterface } from \"node:readline\";\n import {\n show,\n truncate,\n bundleSeedScript,\n chunkSeedData,\n executeScript,\n initOperatorClient,\n loadAccessToken,\n loadWorkspaceId,\n } from \"@tailor-platform/sdk/cli\";\n\n // Parse command-line arguments\n const { values, positionals } = parseArgs({\n options: {\n \"machine-user\": { type: \"string\", short: \"m\" },\n namespace: { type: \"string\", short: \"n\" },\n \"skip-idp\": { type: \"boolean\", default: false },\n truncate: { type: \"boolean\", default: false },\n yes: { type: \"boolean\", default: false },\n profile: { type: \"string\", short: \"p\" },\n help: { type: \"boolean\", short: \"h\", default: false },\n },\n allowPositionals: true,\n });\n\n if (values.help) {\n console.log(\\`\n Usage: node exec.mjs [options] [types...]\n\n Options:\n -m, --machine-user <name> Machine user name for authentication (required if not configured)\n -n, --namespace <ns> Process all types in specified namespace (excludes _User)\n --skip-idp Skip IdP user (_User) entity\n --truncate Truncate tables before seeding\n --yes Skip confirmation prompts (for truncate)\n -p, --profile <name> Workspace profile name\n -h, --help Show help\n\n Examples:\n node exec.mjs -m admin # Process all types with machine user\n node exec.mjs --namespace <namespace> # Process tailordb namespace only (no _User)\n node exec.mjs User Order # Process specific types only\n node exec.mjs --skip-idp # Process all except _User\n node exec.mjs --truncate # Truncate all tables, then seed all\n node exec.mjs --truncate --yes # Truncate all tables without confirmation, then seed all\n node exec.mjs --truncate --namespace <namespace> # Truncate tailordb, then seed tailordb\n node exec.mjs --truncate User Order # Truncate User and Order, then seed them\n \\`);\n process.exit(0);\n }\n\n // Helper function to prompt for y/n confirmation\n const promptConfirmation = (question) => {\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n return new Promise((resolve) => {\n rl.question(styleText(\"yellow\", question), (answer) => {\n rl.close();\n resolve(answer.toLowerCase().trim());\n });\n });\n };\n\n const configDir = import.meta.dirname;\n const configPath = join(configDir, \"${relativeConfigPath}\");\n\n // Determine machine user name (CLI argument takes precedence over config default)\n const defaultMachineUser = ${defaultMachineUserName ? `\"${defaultMachineUserName}\"` : \"undefined\"};\n const machineUserName = values[\"machine-user\"] || defaultMachineUser;\n\n if (!machineUserName) {\n console.error(styleText(\"red\", \"Error: Machine user name is required.\"));\n console.error(styleText(\"yellow\", \"Specify --machine-user <name> or configure machineUserName in generator options.\"));\n process.exit(1);\n }\n\n // Entity configuration\n const namespaceEntities = {\n${namespaceEntitiesEntries}\n };\n const namespaceDeps = {\n${namespaceDepsEntries}\n };\n const entities = Object.values(namespaceEntities).flat();\n const hasIdpUser = ${String(hasIdpUser)};\n\n // Determine which entities to process\n let entitiesToProcess = null;\n\n const hasNamespace = !!values.namespace;\n const hasTypes = positionals.length > 0;\n const skipIdp = values[\"skip-idp\"];\n\n // Validate mutually exclusive options\n const optionCount = [hasNamespace, hasTypes].filter(Boolean).length;\n if (optionCount > 1) {\n console.error(styleText(\"red\", \"Error: Options --namespace and type names are mutually exclusive.\"));\n process.exit(1);\n }\n\n // --skip-idp and --namespace are redundant (namespace already excludes _User)\n if (skipIdp && hasNamespace) {\n console.warn(styleText(\"yellow\", \"Warning: --skip-idp is redundant with --namespace (namespace filtering already excludes _User).\"));\n }\n\n // Filter by namespace (automatically excludes _User as it has no namespace)\n if (hasNamespace) {\n const namespace = values.namespace;\n entitiesToProcess = namespaceEntities[namespace];\n\n if (!entitiesToProcess || entitiesToProcess.length === 0) {\n console.error(styleText(\"red\", \\`Error: No entities found in namespace \"\\${namespace}\"\\`));\n console.error(styleText(\"yellow\", \\`Available namespaces: \\${Object.keys(namespaceEntities).join(\", \")}\\`));\n process.exit(1);\n }\n\n console.log(styleText(\"cyan\", \\`Filtering by namespace: \\${namespace}\\`));\n console.log(styleText(\"dim\", \\`Entities: \\${entitiesToProcess.join(\", \")}\\`));\n }\n\n // Filter by specific types\n if (hasTypes) {\n const requestedTypes = positionals;\n const notFoundTypes = [];\n const allTypes = hasIdpUser ? [...entities, \"_User\"] : entities;\n\n entitiesToProcess = requestedTypes.filter((type) => {\n if (!allTypes.includes(type)) {\n notFoundTypes.push(type);\n return false;\n }\n return true;\n });\n\n if (notFoundTypes.length > 0) {\n console.error(styleText(\"red\", \\`Error: The following types were not found: \\${notFoundTypes.join(\", \")}\\`));\n console.error(styleText(\"yellow\", \\`Available types: \\${allTypes.join(\", \")}\\`));\n process.exit(1);\n }\n\n console.log(styleText(\"cyan\", \\`Filtering by types: \\${entitiesToProcess.join(\", \")}\\`));\n }\n\n // Apply --skip-idp filter\n if (skipIdp) {\n if (entitiesToProcess) {\n entitiesToProcess = entitiesToProcess.filter((entity) => entity !== \"_User\");\n } else {\n entitiesToProcess = entities.filter((entity) => entity !== \"_User\");\n }\n }\n\n // Get application info\n const appInfo = await show({ configPath, profile: values.profile });\n const authNamespace = appInfo.auth;\n\n // Initialize operator client (once for all namespaces)\n const accessToken = await loadAccessToken({ profile: values.profile, useProfile: true });\n const workspaceId = await loadWorkspaceId({ profile: values.profile });\n const operatorClient = await initOperatorClient(accessToken);\n\n ${generateIdpUserTruncateFunction(hasIdpUser, idpNamespace)}\n\n // Truncate tables if requested\n if (values.truncate) {\n const answer = values.yes ? \"y\" : await promptConfirmation(\"Are you sure you want to truncate? (y/n): \");\n if (answer !== \"y\") {\n console.log(styleText(\"yellow\", \"Truncate cancelled.\"));\n process.exit(0);\n }\n\n console.log(styleText(\"cyan\", \"Truncating tables...\"));\n\n try {\n if (hasNamespace) {\n await truncate({\n configPath,\n profile: values.profile,\n namespace: values.namespace,\n });\n } else if (hasTypes) {\n const typesToTruncate = entitiesToProcess.filter((t) => t !== \"_User\");\n if (typesToTruncate.length > 0) {\n await truncate({\n configPath,\n profile: values.profile,\n types: typesToTruncate,\n });\n } else {\n console.log(styleText(\"dim\", \"No TailorDB types to truncate (only _User was specified).\"));\n }\n } else {\n await truncate({\n configPath,\n profile: values.profile,\n all: true,\n });\n }\n } catch (error) {\n console.error(styleText(\"red\", \\`Truncate failed: \\${error.message}\\`));\n process.exit(1);\n }\n\n ${generateIdpUserTruncateCall(hasIdpUser)}\n\n console.log(styleText(\"green\", \"Truncate completed.\"));\n }\n\n console.log(styleText(\"cyan\", \"\\\\nStarting seed data generation...\"));\n if (skipIdp) {\n console.log(styleText(\"dim\", \\` Skipping IdP user (_User)\\`));\n }\n\n // Load seed data from JSONL files\n const loadSeedData = (dataDir, typeNames) => {\n const data = {};\n for (const typeName of typeNames) {\n const jsonlPath = join(dataDir, \\`\\${typeName}.jsonl\\`);\n try {\n const content = readFileSync(jsonlPath, \"utf-8\").trim();\n if (content) {\n data[typeName] = content.split(\"\\\\n\").map((line) => JSON.parse(line));\n } else {\n data[typeName] = [];\n }\n } catch (error) {\n if (error.code === \"ENOENT\") {\n data[typeName] = [];\n } else {\n throw error;\n }\n }\n }\n return data;\n };\n\n // Topological sort for dependency order\n const topologicalSort = (types, deps) => {\n const visited = new Set();\n const result = [];\n\n const visit = (type) => {\n if (visited.has(type)) return;\n visited.add(type);\n const typeDeps = deps[type] || [];\n for (const dep of typeDeps) {\n if (types.includes(dep)) {\n visit(dep);\n }\n }\n result.push(type);\n };\n\n for (const type of types) {\n visit(type);\n }\n return result;\n };\n\n // Seed TailorDB types via testExecScript\n const seedViaTestExecScript = async (namespace, typesToSeed, deps) => {\n const dataDir = join(configDir, \"data\");\n const sortedTypes = topologicalSort(typesToSeed, deps);\n const data = loadSeedData(dataDir, sortedTypes);\n\n // Skip if no data\n const typesWithData = sortedTypes.filter((t) => data[t] && data[t].length > 0);\n if (typesWithData.length === 0) {\n console.log(styleText(\"dim\", \\` [\\${namespace}] No data to seed\\`));\n return { success: true, processed: {} };\n }\n\n console.log(styleText(\"cyan\", \\` [\\${namespace}] Seeding \\${typesWithData.length} types via Kysely batch insert...\\`));\n\n // Bundle seed script\n const bundled = await bundleSeedScript(namespace, typesWithData);\n\n // Chunk seed data to fit within gRPC message size limits\n const chunks = chunkSeedData({\n data,\n order: sortedTypes,\n codeByteSize: new TextEncoder().encode(bundled.bundledCode).length,\n });\n\n if (chunks.length === 0) {\n console.log(styleText(\"dim\", \\` [\\${namespace}] No data to seed\\`));\n return { success: true, processed: {} };\n }\n\n if (chunks.length > 1) {\n console.log(styleText(\"dim\", \\` Split into \\${chunks.length} chunks\\`));\n }\n\n const allProcessed = {};\n let hasError = false;\n const allErrors = [];\n\n for (const chunk of chunks) {\n if (chunks.length > 1) {\n console.log(styleText(\"dim\", \\` Chunk \\${chunk.index + 1}/\\${chunk.total}: \\${chunk.order.join(\", \")}\\`));\n }\n\n // Execute seed script for this chunk\n const result = await executeScript({\n client: operatorClient,\n workspaceId,\n name: \\`seed-\\${namespace}.ts\\`,\n code: bundled.bundledCode,\n arg: JSON.stringify({ data: chunk.data, order: chunk.order }),\n invoker: {\n namespace: authNamespace,\n machineUserName,\n },\n });\n\n // Parse result and display logs\n if (result.logs) {\n for (const line of result.logs.split(\"\\\\n\").filter(Boolean)) {\n console.log(styleText(\"dim\", \\` \\${line}\\`));\n }\n }\n\n if (result.success) {\n let parsed;\n try {\n const parsedResult = JSON.parse(result.result || \"{}\");\n parsed = parsedResult && typeof parsedResult === \"object\" ? parsedResult : {};\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n console.error(styleText(\"red\", \\` ✗ Failed to parse seed result: \\${message}\\`));\n hasError = true;\n allErrors.push(message);\n continue;\n }\n\n const processed = parsed.processed || {};\n for (const [type, count] of Object.entries(processed)) {\n allProcessed[type] = (allProcessed[type] || 0) + count;\n console.log(styleText(\"green\", \\` ✓ \\${type}: \\${count} rows inserted\\`));\n }\n\n if (!parsed.success) {\n const errors = Array.isArray(parsed.errors) ? parsed.errors : [];\n const errorMessage =\n errors.length > 0 ? errors.join(\"\\\\n \") : \"Seed script reported failure\";\n console.error(styleText(\"red\", \\` ✗ Seed failed:\\\\n \\${errorMessage}\\`));\n hasError = true;\n allErrors.push(errorMessage);\n }\n } else {\n console.error(styleText(\"red\", \\` ✗ Seed failed: \\${result.error}\\`));\n hasError = true;\n allErrors.push(result.error);\n }\n }\n\n if (hasError) {\n return { success: false, error: allErrors.join(\"\\\\n\") };\n }\n return { success: true, processed: allProcessed };\n };\n\n ${generateIdpUserSeedFunction(hasIdpUser, idpNamespace)}\n\n // Main execution\n try {\n let allSuccess = true;\n\n // Determine which namespaces and types to process\n const namespacesToProcess = hasNamespace\n ? [values.namespace]\n : Object.keys(namespaceEntities);\n\n for (const namespace of namespacesToProcess) {\n const nsTypes = namespaceEntities[namespace] || [];\n const nsDeps = namespaceDeps[namespace] || {};\n\n // Filter types if specific types requested\n let typesToSeed = entitiesToProcess\n ? nsTypes.filter((t) => entitiesToProcess.includes(t))\n : nsTypes;\n\n if (typesToSeed.length === 0) continue;\n\n const result = await seedViaTestExecScript(namespace, typesToSeed, nsDeps);\n if (!result.success) {\n allSuccess = false;\n }\n }\n\n ${generateIdpUserSeedCall(hasIdpUser)}\n\n if (allSuccess) {\n console.log(styleText(\"green\", \"\\\\n✓ Seed data generation completed successfully\"));\n } else {\n console.error(styleText(\"red\", \"\\\\n✗ Seed data generation completed with errors\"));\n process.exit(1);\n }\n } catch (error) {\n console.error(styleText(\"red\", \\`\\\\n✗ Seed data generation failed: \\${error.message}\\`));\n process.exit(1);\n }\n\n `;\n}\n\n/**\n * Plugin that generates seed data files with Kysely batch insert and tailor.idp.Client for _User.\n * @param options - Plugin options\n * @param options.distPath - Output directory path for generated seed files\n * @param options.machineUserName - Default machine user name for authentication\n * @returns Plugin instance with onTailorDBReady hook\n */\nexport function seedPlugin(options: SeedPluginOptions): Plugin<unknown, SeedPluginOptions> {\n return {\n id: SeedGeneratorID,\n description: \"Generates seed data files (Kysely batch insert + tailor.idp.Client for _User)\",\n pluginConfig: options,\n\n async onTailorDBReady(ctx: TailorDBReadyContext<SeedPluginOptions>): Promise<GeneratorResult> {\n const files: GeneratorResult[\"files\"] = [];\n const namespaceConfigs: NamespaceConfig[] = [];\n\n for (const ns of ctx.tailordb) {\n const types: string[] = [];\n const dependencies: Record<string, string[]> = {};\n\n for (const [typeName, type] of Object.entries(ns.types)) {\n const source = ns.sourceInfo.get(typeName)!;\n const typeInfo = processSeedTypeInfo(type, ns.namespace);\n const linesDb = processLinesDb(type, source);\n\n types.push(typeInfo.name);\n dependencies[typeInfo.name] = typeInfo.dependencies;\n\n // Generate empty JSONL data file\n files.push({\n path: path.join(ctx.pluginConfig.distPath, typeInfo.dataFile),\n content: \"\",\n skipIfExists: true,\n });\n\n const schemaOutputPath = path.join(\n ctx.pluginConfig.distPath,\n \"data\",\n `${linesDb.typeName}.schema.ts`,\n );\n\n // Plugin-generated type: use getGeneratedType API\n if (linesDb.pluginSource && linesDb.pluginSource.pluginImportPath) {\n // Build original type import path\n let originalImportPath: string | undefined;\n if (linesDb.pluginSource.originalFilePath && linesDb.pluginSource.originalExportName) {\n const relativePath = path.relative(\n path.dirname(schemaOutputPath),\n linesDb.pluginSource.originalFilePath,\n );\n originalImportPath = relativePath.replace(/\\.ts$/, \"\").startsWith(\".\")\n ? relativePath.replace(/\\.ts$/, \"\")\n : `./${relativePath.replace(/\\.ts$/, \"\")}`;\n }\n\n // Compute relative path from schema output to config file\n const configImportPath = path.relative(path.dirname(schemaOutputPath), ctx.configPath);\n\n const params: PluginSchemaParams = {\n configImportPath,\n originalImportPath,\n };\n\n const schemaContent = generateLinesDbSchemaFileWithPluginAPI(linesDb, params);\n\n files.push({\n path: schemaOutputPath,\n content: schemaContent,\n });\n } else {\n // User-defined type: import from source file\n const relativePath = path.relative(path.dirname(schemaOutputPath), linesDb.importPath);\n const typeImportPath = relativePath.replace(/\\.ts$/, \"\").startsWith(\".\")\n ? relativePath.replace(/\\.ts$/, \"\")\n : `./${relativePath.replace(/\\.ts$/, \"\")}`;\n const schemaContent = generateLinesDbSchemaFile(linesDb, typeImportPath);\n\n files.push({\n path: schemaOutputPath,\n content: schemaContent,\n });\n }\n }\n\n namespaceConfigs.push({\n namespace: ns.namespace,\n types,\n dependencies,\n });\n }\n\n // Process IdP user if configured\n const idpUser = ctx.auth ? processIdpUser(ctx.auth) : null;\n const hasIdpUser = idpUser !== null;\n\n if (idpUser) {\n // Generate empty JSONL data file\n files.push({\n path: path.join(ctx.pluginConfig.distPath, idpUser.dataFile),\n content: \"\",\n skipIfExists: true,\n });\n\n // Generate schema file with foreign key\n files.push({\n path: path.join(ctx.pluginConfig.distPath, \"data\", `${idpUser.name}.schema.ts`),\n content: generateIdpUserSchemaFile(\n idpUser.schema.usernameField,\n idpUser.schema.userTypeName,\n ),\n });\n }\n\n // Generate exec.mjs (machineUserName can be provided at runtime if not configured)\n const relativeConfigPath = path.relative(ctx.pluginConfig.distPath, ctx.configPath);\n files.push({\n path: path.join(ctx.pluginConfig.distPath, \"exec.mjs\"),\n content: generateExecScript(\n ctx.pluginConfig.machineUserName,\n relativeConfigPath,\n namespaceConfigs,\n hasIdpUser,\n idpUser?.idpNamespace ?? null,\n ),\n });\n\n return { files };\n },\n };\n}\n"],"mappings":";;;;;;;;;;AAmBA,SAAgB,eAAe,MAAuD;AAEpF,KAAI,KAAK,YAAY,SAAS,gBAAgB,CAAC,KAAK,YAClD;CAGF,MAAM,EAAE,UAAU,kBAAkB,KAAK;AAE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C8B;AAExE,YAAM,KAAK;OACT,MAAM;OACN,SAAS;OACV,CAAC;;;AAIN,qBAAiB,KAAK;KACpB,WAAW,GAAG;KACd;KACA;KACD,CAAC;;GAIJ,MAAM,UAAU,IAAI,OAAO,eAAe,IAAI,KAAK,GAAG;GACtD,MAAM,aAAa,YAAY;AAE/B,OAAI,SAAS;AAEX,UAAM,KAAK;KACT,MAAM,KAAK,KAAK,IAAI,aAAa,UAAU,QAAQ,SAAS;KAC5D,SAAS;KACT,cAAc;KACf,CAAC;AAGF,UAAM,KAAK;KACT,MAAM,KAAK,KAAK,IAAI,aAAa,UAAU,QAAQ,GAAG,QAAQ,KAAK,YAAY;KAC/E,SAAS,0BACP,QAAQ,OAAO,eACf,QAAQ,OAAO,aAChB;KACF,CAAC;;GAIJ,MAAM,qBAAqB,KAAK,SAAS,IAAI,aAAa,UAAU,IAAI,WAAW;AACnF,SAAM,KAAK;IACT,MAAM,KAAK,KAAK,IAAI,aAAa,UAAU,WAAW;IACtD,SAAS,mBACP,IAAI,aAAa,iBACjB,oBACA,kBACA,YACA,SAAS,gBAAgB,KAC1B;IACF,CAAC;AAEF,UAAO,EAAE,OAAO;;EAEnB"}
@@ -1,4 +1,4 @@
1
- import { n as __esmMin } from "./chunk-GMkBE123.mjs";
1
+ import { n as __esmMin } from "./chunk-CqAI0b6X.mjs";
2
2
  import { fileURLToPath } from "node:url";
3
3
  import nativeFsp from "node:fs/promises";
4
4
  import path from "node:path";
@@ -1035,4 +1035,4 @@ var init_src = __esmMin((() => {
1035
1035
  //#endregion
1036
1036
  init_src();
1037
1037
  export { hfs };
1038
- //# sourceMappingURL=src-DMROgdcL.mjs.map
1038
+ //# sourceMappingURL=src-Bb1UVstT.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"src-DMROgdcL.mjs","names":["#baseImpl","#impl","#logs","#log","#assertImplMethod","#assertImplMethodAlt","#callImplMethodAlt","#callImplMethod","#callImplMethodWithoutLog","dirPath","entryFilter","directoryFilter","#check","#timeout","#maxDelay","#queue","#processQueue","#timerId","#fsp","#retrier"],"sources":["../../../node_modules/@humanfs/core/src/hfs.js","../../../node_modules/@humanfs/core/src/errors.js","../../../node_modules/@humanfs/core/src/index.js","../../../node_modules/@humanwhocodes/retry/dist/retrier.js","../../../node_modules/@humanfs/node/src/node-hfs.js","../../../node_modules/@humanfs/node/src/index.js"],"sourcesContent":["/**\n * @fileoverview The main file for the humanfs package.\n * @author Nicholas C. Zakas\n */\n\n/* global URL, TextDecoder, TextEncoder */\n\n//-----------------------------------------------------------------------------\n// Types\n//-----------------------------------------------------------------------------\n\n/** @typedef {import(\"@humanfs/types\").HfsImpl} HfsImpl */\n/** @typedef {import(\"@humanfs/types\").HfsDirectoryEntry} HfsDirectoryEntry */\n/** @typedef {import(\"@humanfs/types\").HfsWalkEntry} HfsWalkEntry */\n\n//-----------------------------------------------------------------------------\n// Helpers\n//-----------------------------------------------------------------------------\n\nconst decoder = new TextDecoder();\nconst encoder = new TextEncoder();\n\n/**\n * Error to represent when a method is missing on an impl.\n */\nexport class NoSuchMethodError extends Error {\n\t/**\n\t * Creates a new instance.\n\t * @param {string} methodName The name of the method that was missing.\n\t */\n\tconstructor(methodName) {\n\t\tsuper(`Method \"${methodName}\" does not exist on impl.`);\n\t}\n}\n\n/**\n * Error to represent when a method is not supported on an impl. This happens\n * when a method on `Hfs` is called with one name and the corresponding method\n * on the impl has a different name. (Example: `text()` and `bytes()`.)\n */\nexport class MethodNotSupportedError extends Error {\n\t/**\n\t * Creates a new instance.\n\t * @param {string} methodName The name of the method that was missing.\n\t */\n\tconstructor(methodName) {\n\t\tsuper(`Method \"${methodName}\" is not supported on this impl.`);\n\t}\n}\n\n/**\n * Error to represent when an impl is already set.\n */\nexport class ImplAlreadySetError extends Error {\n\t/**\n\t * Creates a new instance.\n\t */\n\tconstructor() {\n\t\tsuper(`Implementation already set.`);\n\t}\n}\n\n/**\n * Asserts that the given path is a valid file path.\n * @param {any} fileOrDirPath The path to check.\n * @returns {void}\n * @throws {TypeError} When the path is not a non-empty string.\n */\nfunction assertValidFileOrDirPath(fileOrDirPath) {\n\tif (\n\t\t!fileOrDirPath ||\n\t\t(!(fileOrDirPath instanceof URL) && typeof fileOrDirPath !== \"string\")\n\t) {\n\t\tthrow new TypeError(\"Path must be a non-empty string or URL.\");\n\t}\n}\n\n/**\n * Asserts that the given file contents are valid.\n * @param {any} contents The contents to check.\n * @returns {void}\n * @throws {TypeError} When the contents are not a string or ArrayBuffer.\n */\nfunction assertValidFileContents(contents) {\n\tif (\n\t\ttypeof contents !== \"string\" &&\n\t\t!(contents instanceof ArrayBuffer) &&\n\t\t!ArrayBuffer.isView(contents)\n\t) {\n\t\tthrow new TypeError(\n\t\t\t\"File contents must be a string, ArrayBuffer, or ArrayBuffer view.\",\n\t\t);\n\t}\n}\n\n/**\n * Converts the given contents to Uint8Array.\n * @param {any} contents The data to convert.\n * @returns {Uint8Array} The converted Uint8Array.\n * @throws {TypeError} When the contents are not a string or ArrayBuffer.\n */\nfunction toUint8Array(contents) {\n\tif (contents instanceof Uint8Array) {\n\t\treturn contents;\n\t}\n\n\tif (typeof contents === \"string\") {\n\t\treturn encoder.encode(contents);\n\t}\n\n\tif (contents instanceof ArrayBuffer) {\n\t\treturn new Uint8Array(contents);\n\t}\n\n\tif (ArrayBuffer.isView(contents)) {\n\t\tconst bytes = contents.buffer.slice(\n\t\t\tcontents.byteOffset,\n\t\t\tcontents.byteOffset + contents.byteLength,\n\t\t);\n\t\treturn new Uint8Array(bytes);\n\t}\n\tthrow new TypeError(\n\t\t\"Invalid contents type. Expected string or ArrayBuffer.\",\n\t);\n}\n\n//-----------------------------------------------------------------------------\n// Exports\n//-----------------------------------------------------------------------------\n\n/**\n * A class representing a log entry.\n */\nexport class LogEntry {\n\t/**\n\t * The type of log entry.\n\t * @type {string}\n\t */\n\ttype;\n\n\t/**\n\t * The data associated with the log entry.\n\t * @type {any}\n\t */\n\tdata;\n\n\t/**\n\t * The time at which the log entry was created.\n\t * @type {number}\n\t */\n\ttimestamp = Date.now();\n\n\t/**\n\t * Creates a new instance.\n\t * @param {string} type The type of log entry.\n\t * @param {any} [data] The data associated with the log entry.\n\t */\n\tconstructor(type, data) {\n\t\tthis.type = type;\n\t\tthis.data = data;\n\t}\n}\n\n/**\n * A class representing a file system utility library.\n * @implements {HfsImpl}\n */\nexport class Hfs {\n\t/**\n\t * The base implementation for this instance.\n\t * @type {HfsImpl}\n\t */\n\t#baseImpl;\n\n\t/**\n\t * The current implementation for this instance.\n\t * @type {HfsImpl}\n\t */\n\t#impl;\n\n\t/**\n\t * A map of log names to their corresponding entries.\n\t * @type {Map<string,Array<LogEntry>>}\n\t */\n\t#logs = new Map();\n\n\t/**\n\t * Creates a new instance.\n\t * @param {object} options The options for the instance.\n\t * @param {HfsImpl} options.impl The implementation to use.\n\t */\n\tconstructor({ impl }) {\n\t\tthis.#baseImpl = impl;\n\t\tthis.#impl = impl;\n\t}\n\n\t/**\n\t * Logs an entry onto all currently open logs.\n\t * @param {string} methodName The name of the method being called.\n\t * @param {...*} args The arguments to the method.\n\t * @returns {void}\n\t */\n\t#log(methodName, ...args) {\n\t\tfor (const logs of this.#logs.values()) {\n\t\t\tlogs.push(new LogEntry(\"call\", { methodName, args }));\n\t\t}\n\t}\n\n\t/**\n\t * Starts a new log with the given name.\n\t * @param {string} name The name of the log to start;\n\t * @returns {void}\n\t * @throws {Error} When the log already exists.\n\t * @throws {TypeError} When the name is not a non-empty string.\n\t */\n\tlogStart(name) {\n\t\tif (!name || typeof name !== \"string\") {\n\t\t\tthrow new TypeError(\"Log name must be a non-empty string.\");\n\t\t}\n\n\t\tif (this.#logs.has(name)) {\n\t\t\tthrow new Error(`Log \"${name}\" already exists.`);\n\t\t}\n\n\t\tthis.#logs.set(name, []);\n\t}\n\n\t/**\n\t * Ends a log with the given name and returns the entries.\n\t * @param {string} name The name of the log to end.\n\t * @returns {Array<LogEntry>} The entries in the log.\n\t * @throws {Error} When the log does not exist.\n\t */\n\tlogEnd(name) {\n\t\tif (this.#logs.has(name)) {\n\t\t\tconst logs = this.#logs.get(name);\n\t\t\tthis.#logs.delete(name);\n\t\t\treturn logs;\n\t\t}\n\n\t\tthrow new Error(`Log \"${name}\" does not exist.`);\n\t}\n\n\t/**\n\t * Determines if the current implementation is the base implementation.\n\t * @returns {boolean} True if the current implementation is the base implementation.\n\t */\n\tisBaseImpl() {\n\t\treturn this.#impl === this.#baseImpl;\n\t}\n\n\t/**\n\t * Sets the implementation for this instance.\n\t * @param {object} impl The implementation to use.\n\t * @returns {void}\n\t */\n\tsetImpl(impl) {\n\t\tthis.#log(\"implSet\", impl);\n\n\t\tif (this.#impl !== this.#baseImpl) {\n\t\t\tthrow new ImplAlreadySetError();\n\t\t}\n\n\t\tthis.#impl = impl;\n\t}\n\n\t/**\n\t * Resets the implementation for this instance back to its original.\n\t * @returns {void}\n\t */\n\tresetImpl() {\n\t\tthis.#log(\"implReset\");\n\t\tthis.#impl = this.#baseImpl;\n\t}\n\n\t/**\n\t * Asserts that the given method exists on the current implementation.\n\t * @param {string} methodName The name of the method to check.\n\t * @returns {void}\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t */\n\t#assertImplMethod(methodName) {\n\t\tif (typeof this.#impl[methodName] !== \"function\") {\n\t\t\tthrow new NoSuchMethodError(methodName);\n\t\t}\n\t}\n\n\t/**\n\t * Asserts that the given method exists on the current implementation, and if not,\n\t * throws an error with a different method name.\n\t * @param {string} methodName The name of the method to check.\n\t * @param {string} targetMethodName The name of the method that should be reported\n\t * as an error when methodName does not exist.\n\t * @returns {void}\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t */\n\t#assertImplMethodAlt(methodName, targetMethodName) {\n\t\tif (typeof this.#impl[methodName] !== \"function\") {\n\t\t\tthrow new MethodNotSupportedError(targetMethodName);\n\t\t}\n\t}\n\n\t/**\n\t * Calls the given method on the current implementation.\n\t * @param {string} methodName The name of the method to call.\n\t * @param {...any} args The arguments to the method.\n\t * @returns {any} The return value from the method.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t */\n\t#callImplMethod(methodName, ...args) {\n\t\tthis.#log(methodName, ...args);\n\t\tthis.#assertImplMethod(methodName);\n\t\treturn this.#impl[methodName](...args);\n\t}\n\n\t/**\n\t * Calls the given method on the current implementation and doesn't log the call.\n\t * @param {string} methodName The name of the method to call.\n\t * @param {...any} args The arguments to the method.\n\t * @returns {any} The return value from the method.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t */\n\t#callImplMethodWithoutLog(methodName, ...args) {\n\t\tthis.#assertImplMethod(methodName);\n\t\treturn this.#impl[methodName](...args);\n\t}\n\n\t/**\n\t * Calls the given method on the current implementation but logs a different method name.\n\t * @param {string} methodName The name of the method to call.\n\t * @param {string} targetMethodName The name of the method to log.\n\t * @param {...any} args The arguments to the method.\n\t * @returns {any} The return value from the method.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t */\n\t#callImplMethodAlt(methodName, targetMethodName, ...args) {\n\t\tthis.#log(targetMethodName, ...args);\n\t\tthis.#assertImplMethodAlt(methodName, targetMethodName);\n\t\treturn this.#impl[methodName](...args);\n\t}\n\n\t/**\n\t * Reads the given file and returns the contents as text. Assumes UTF-8 encoding.\n\t * @param {string|URL} filePath The file to read.\n\t * @returns {Promise<string|undefined>} The contents of the file.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the file path is not a non-empty string.\n\t */\n\tasync text(filePath) {\n\t\tassertValidFileOrDirPath(filePath);\n\n\t\tconst result = await this.#callImplMethodAlt(\"bytes\", \"text\", filePath);\n\t\treturn result ? decoder.decode(result) : undefined;\n\t}\n\n\t/**\n\t * Reads the given file and returns the contents as JSON. Assumes UTF-8 encoding.\n\t * @param {string|URL} filePath The file to read.\n\t * @returns {Promise<any|undefined>} The contents of the file as JSON.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {SyntaxError} When the file contents are not valid JSON.\n\t * @throws {TypeError} When the file path is not a non-empty string.\n\t */\n\tasync json(filePath) {\n\t\tassertValidFileOrDirPath(filePath);\n\n\t\tconst result = await this.#callImplMethodAlt(\"bytes\", \"json\", filePath);\n\t\treturn result ? JSON.parse(decoder.decode(result)) : undefined;\n\t}\n\n\t/**\n\t * Reads the given file and returns the contents as an ArrayBuffer.\n\t * @param {string|URL} filePath The file to read.\n\t * @returns {Promise<ArrayBuffer|undefined>} The contents of the file as an ArrayBuffer.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the file path is not a non-empty string.\n\t * @deprecated Use bytes() instead.\n\t */\n\tasync arrayBuffer(filePath) {\n\t\tassertValidFileOrDirPath(filePath);\n\n\t\tconst result = await this.#callImplMethodAlt(\n\t\t\t\"bytes\",\n\t\t\t\"arrayBuffer\",\n\t\t\tfilePath,\n\t\t);\n\t\treturn result?.buffer;\n\t}\n\n\t/**\n\t * Reads the given file and returns the contents as an Uint8Array.\n\t * @param {string|URL} filePath The file to read.\n\t * @returns {Promise<Uint8Array|undefined>} The contents of the file as an Uint8Array.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the file path is not a non-empty string.\n\t */\n\tasync bytes(filePath) {\n\t\tassertValidFileOrDirPath(filePath);\n\t\treturn this.#callImplMethod(\"bytes\", filePath);\n\t}\n\n\t/**\n\t * Writes the given data to the given file. Creates any necessary directories along the way.\n\t * If the data is a string, UTF-8 encoding is used.\n\t * @param {string|URL} filePath The file to write.\n\t * @param {string|ArrayBuffer|ArrayBufferView} contents The data to write.\n\t * @returns {Promise<void>} A promise that resolves when the file is written.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the file path is not a non-empty string.\n\t */\n\tasync write(filePath, contents) {\n\t\tassertValidFileOrDirPath(filePath);\n\t\tassertValidFileContents(contents);\n\t\tthis.#log(\"write\", filePath, contents);\n\n\t\tlet value = toUint8Array(contents);\n\t\treturn this.#callImplMethodWithoutLog(\"write\", filePath, value);\n\t}\n\n\t/**\n\t * Appends the given data to the given file. Creates any necessary directories along the way.\n\t * If the data is a string, UTF-8 encoding is used.\n\t * @param {string|URL} filePath The file to append to.\n\t * @param {string|ArrayBuffer|ArrayBufferView} contents The data to append.\n\t * @returns {Promise<void>} A promise that resolves when the file is appended to.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the file path is not a non-empty string.\n\t * @throws {TypeError} When the file contents are not a string or ArrayBuffer.\n\t * @throws {Error} When the file cannot be appended to.\n\t */\n\tasync append(filePath, contents) {\n\t\tassertValidFileOrDirPath(filePath);\n\t\tassertValidFileContents(contents);\n\t\tthis.#log(\"append\", filePath, contents);\n\n\t\tlet value = toUint8Array(contents);\n\t\treturn this.#callImplMethodWithoutLog(\"append\", filePath, value);\n\t}\n\n\t/**\n\t * Determines if the given file exists.\n\t * @param {string|URL} filePath The file to check.\n\t * @returns {Promise<boolean>} True if the file exists.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the file path is not a non-empty string.\n\t */\n\tasync isFile(filePath) {\n\t\tassertValidFileOrDirPath(filePath);\n\t\treturn this.#callImplMethod(\"isFile\", filePath);\n\t}\n\n\t/**\n\t * Determines if the given directory exists.\n\t * @param {string|URL} dirPath The directory to check.\n\t * @returns {Promise<boolean>} True if the directory exists.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the directory path is not a non-empty string.\n\t */\n\tasync isDirectory(dirPath) {\n\t\tassertValidFileOrDirPath(dirPath);\n\t\treturn this.#callImplMethod(\"isDirectory\", dirPath);\n\t}\n\n\t/**\n\t * Creates the given directory.\n\t * @param {string|URL} dirPath The directory to create.\n\t * @returns {Promise<void>} A promise that resolves when the directory is created.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the directory path is not a non-empty string.\n\t */\n\tasync createDirectory(dirPath) {\n\t\tassertValidFileOrDirPath(dirPath);\n\t\treturn this.#callImplMethod(\"createDirectory\", dirPath);\n\t}\n\n\t/**\n\t * Deletes the given file or empty directory.\n\t * @param {string|URL} filePath The file to delete.\n\t * @returns {Promise<boolean>} A promise that resolves when the file or\n\t * directory is deleted, true if the file or directory is deleted, false\n\t * if the file or directory does not exist.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the file path is not a non-empty string.\n\t */\n\tasync delete(filePath) {\n\t\tassertValidFileOrDirPath(filePath);\n\t\treturn this.#callImplMethod(\"delete\", filePath);\n\t}\n\n\t/**\n\t * Deletes the given file or directory recursively.\n\t * @param {string|URL} dirPath The directory to delete.\n\t * @returns {Promise<boolean>} A promise that resolves when the file or\n\t * directory is deleted, true if the file or directory is deleted, false\n\t * if the file or directory does not exist.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the directory path is not a non-empty string.\n\t */\n\tasync deleteAll(dirPath) {\n\t\tassertValidFileOrDirPath(dirPath);\n\t\treturn this.#callImplMethod(\"deleteAll\", dirPath);\n\t}\n\n\t/**\n\t * Returns a list of directory entries for the given path.\n\t * @param {string|URL} dirPath The path to the directory to read.\n\t * @returns {AsyncIterable<HfsDirectoryEntry>} A promise that resolves with the\n\t * directory entries.\n\t * @throws {TypeError} If the directory path is not a string or URL.\n\t * @throws {Error} If the directory cannot be read.\n\t */\n\tasync *list(dirPath) {\n\t\tassertValidFileOrDirPath(dirPath);\n\t\tyield* await this.#callImplMethod(\"list\", dirPath);\n\t}\n\n\t/**\n\t * Walks a directory using a depth-first traversal and returns the entries\n\t * from the traversal.\n\t * @param {string|URL} dirPath The path to the directory to walk.\n\t * @param {Object} [options] The options for the walk.\n\t * @param {(entry:HfsWalkEntry) => Promise<boolean>|boolean} [options.directoryFilter] A filter function to determine\n\t * \tif a directory's entries should be included in the walk.\n\t * @param {(entry:HfsWalkEntry) => Promise<boolean>|boolean} [options.entryFilter] A filter function to determine if\n\t * \tan entry should be included in the walk.\n\t * @returns {AsyncIterable<HfsWalkEntry>} A promise that resolves with the\n\t * \tdirectory entries.\n\t * @throws {TypeError} If the directory path is not a string or URL.\n\t * @throws {Error} If the directory cannot be read.\n\t */\n\tasync *walk(\n\t\tdirPath,\n\t\t{ directoryFilter = () => true, entryFilter = () => true } = {},\n\t) {\n\t\tassertValidFileOrDirPath(dirPath);\n\t\tthis.#log(\"walk\", dirPath, { directoryFilter, entryFilter });\n\n\t\t// inner function for recursion without additional logging\n\t\tconst walk = async function* (\n\t\t\tdirPath,\n\t\t\t{ directoryFilter, entryFilter, parentPath = \"\", depth = 1 },\n\t\t) {\n\t\t\tlet dirEntries;\n\n\t\t\ttry {\n\t\t\t\tdirEntries = await this.#callImplMethodWithoutLog(\n\t\t\t\t\t\"list\",\n\t\t\t\t\tdirPath,\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\t// if the directory does not exist then return an empty array\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// otherwise, rethrow the error\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tfor await (const listEntry of dirEntries) {\n\t\t\t\tconst walkEntry = {\n\t\t\t\t\tpath: listEntry.name,\n\t\t\t\t\tdepth,\n\t\t\t\t\t...listEntry,\n\t\t\t\t};\n\n\t\t\t\tif (parentPath) {\n\t\t\t\t\twalkEntry.path = `${parentPath}/${walkEntry.path}`;\n\t\t\t\t}\n\n\t\t\t\t// first emit the entry but only if the entry filter returns true\n\t\t\t\tlet shouldEmitEntry = entryFilter(walkEntry);\n\t\t\t\tif (shouldEmitEntry.then) {\n\t\t\t\t\tshouldEmitEntry = await shouldEmitEntry;\n\t\t\t\t}\n\n\t\t\t\tif (shouldEmitEntry) {\n\t\t\t\t\tyield walkEntry;\n\t\t\t\t}\n\n\t\t\t\t// if it's a directory then yield the entry and walk the directory\n\t\t\t\tif (listEntry.isDirectory) {\n\t\t\t\t\t// if the directory filter returns false, skip the directory\n\t\t\t\t\tlet shouldWalkDirectory = directoryFilter(walkEntry);\n\t\t\t\t\tif (shouldWalkDirectory.then) {\n\t\t\t\t\t\tshouldWalkDirectory = await shouldWalkDirectory;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!shouldWalkDirectory) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// make sure there's a trailing slash on the directory path before appending\n\t\t\t\t\tconst directoryPath =\n\t\t\t\t\t\tdirPath instanceof URL\n\t\t\t\t\t\t\t? new URL(\n\t\t\t\t\t\t\t\t\tlistEntry.name,\n\t\t\t\t\t\t\t\t\tdirPath.href.endsWith(\"/\")\n\t\t\t\t\t\t\t\t\t\t? dirPath.href\n\t\t\t\t\t\t\t\t\t\t: `${dirPath.href}/`,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: `${dirPath.endsWith(\"/\") ? dirPath : `${dirPath}/`}${listEntry.name}`;\n\n\t\t\t\t\tyield* walk(directoryPath, {\n\t\t\t\t\t\tdirectoryFilter,\n\t\t\t\t\t\tentryFilter,\n\t\t\t\t\t\tparentPath: walkEntry.path,\n\t\t\t\t\t\tdepth: depth + 1,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}.bind(this);\n\n\t\tyield* walk(dirPath, { directoryFilter, entryFilter });\n\t}\n\n\t/**\n\t * Returns the size of the given file.\n\t * @param {string|URL} filePath The path to the file to read.\n\t * @returns {Promise<number>} A promise that resolves with the size of the file.\n\t * @throws {TypeError} If the file path is not a string or URL.\n\t * @throws {Error} If the file cannot be read.\n\t */\n\tasync size(filePath) {\n\t\tassertValidFileOrDirPath(filePath);\n\t\treturn this.#callImplMethod(\"size\", filePath);\n\t}\n\n\t/**\n\t * Returns the last modified timestamp of the given file or directory.\n\t * @param {string|URL} fileOrDirPath The path to the file or directory.\n\t * @returns {Promise<Date|undefined>} A promise that resolves with the last modified date\n\t * or undefined if the file or directory does not exist.\n\t * @throws {TypeError} If the path is not a string or URL.\n\t */\n\tasync lastModified(fileOrDirPath) {\n\t\tassertValidFileOrDirPath(fileOrDirPath);\n\t\treturn this.#callImplMethod(\"lastModified\", fileOrDirPath);\n\t}\n\n\t/**\n\t * Copys a file from one location to another.\n\t * @param {string|URL} source The path to the file to copy.\n\t * @param {string|URL} destination The path to the new file.\n\t * @returns {Promise<void>} A promise that resolves when the file is copied.\n\t * @throws {TypeError} If the file path is not a string or URL.\n\t * @throws {Error} If the file cannot be copied.\n\t */\n\tasync copy(source, destination) {\n\t\tassertValidFileOrDirPath(source);\n\t\tassertValidFileOrDirPath(destination);\n\t\treturn this.#callImplMethod(\"copy\", source, destination);\n\t}\n\n\t/**\n\t * Copies a file or directory from one location to another.\n\t * @param {string|URL} source The path to the file or directory to copy.\n\t * @param {string|URL} destination The path to copy the file or directory to.\n\t * @returns {Promise<void>} A promise that resolves when the file or directory is\n\t * copied.\n\t * @throws {TypeError} If the directory path is not a string or URL.\n\t * @throws {Error} If the directory cannot be copied.\n\t */\n\tasync copyAll(source, destination) {\n\t\tassertValidFileOrDirPath(source);\n\t\tassertValidFileOrDirPath(destination);\n\t\treturn this.#callImplMethod(\"copyAll\", source, destination);\n\t}\n\n\t/**\n\t * Moves a file from the source path to the destination path.\n\t * @param {string|URL} source The location of the file to move.\n\t * @param {string|URL} destination The destination of the file to move.\n\t * @returns {Promise<void>} A promise that resolves when the move is complete.\n\t * @throws {TypeError} If the file or directory paths are not strings.\n\t * @throws {Error} If the file or directory cannot be moved.\n\t */\n\tasync move(source, destination) {\n\t\tassertValidFileOrDirPath(source);\n\t\tassertValidFileOrDirPath(destination);\n\t\treturn this.#callImplMethod(\"move\", source, destination);\n\t}\n\n\t/**\n\t * Moves a file or directory from one location to another.\n\t * @param {string|URL} source The path to the file or directory to move.\n\t * @param {string|URL} destination The path to move the file or directory to.\n\t * @returns {Promise<void>} A promise that resolves when the file or directory is\n\t * moved.\n\t * @throws {TypeError} If the source is not a string or URL.\n\t * @throws {TypeError} If the destination is not a string or URL.\n\t * @throws {Error} If the file or directory cannot be moved.\n\t */\n\tasync moveAll(source, destination) {\n\t\tassertValidFileOrDirPath(source);\n\t\tassertValidFileOrDirPath(destination);\n\t\treturn this.#callImplMethod(\"moveAll\", source, destination);\n\t}\n}\n","/**\n * @fileoverview Common error classes\n * @author Nicholas C. Zakas\n */\n\n/**\n * Error thrown when a file or directory is not found.\n */\nexport class NotFoundError extends Error {\n\t/**\n\t * Name of the error class.\n\t * @type {string}\n\t */\n\tname = \"NotFoundError\";\n\n\t/**\n\t * Error code.\n\t * @type {string}\n\t */\n\tcode = \"ENOENT\";\n\n\t/**\n\t * Creates a new instance.\n\t * @param {string} message The error message.\n\t */\n\tconstructor(message) {\n\t\tsuper(`ENOENT: No such file or directory, ${message}`);\n\t}\n}\n\n/**\n * Error thrown when an operation is not permitted.\n */\nexport class PermissionError extends Error {\n\t/**\n\t * Name of the error class.\n\t * @type {string}\n\t */\n\tname = \"PermissionError\";\n\n\t/**\n\t * Error code.\n\t * @type {string}\n\t */\n\tcode = \"EPERM\";\n\n\t/**\n\t * Creates a new instance.\n\t * @param {string} message The error message.\n\t */\n\tconstructor(message) {\n\t\tsuper(`EPERM: Operation not permitted, ${message}`);\n\t}\n}\n\n/**\n * Error thrown when an operation is not allowed on a directory.\n */\n\nexport class DirectoryError extends Error {\n\t/**\n\t * Name of the error class.\n\t * @type {string}\n\t */\n\tname = \"DirectoryError\";\n\n\t/**\n\t * Error code.\n\t * @type {string}\n\t */\n\tcode = \"EISDIR\";\n\n\t/**\n\t * Creates a new instance.\n\t * @param {string} message The error message.\n\t */\n\tconstructor(message) {\n\t\tsuper(`EISDIR: Illegal operation on a directory, ${message}`);\n\t}\n}\n\n/**\n * Error thrown when a directory is not empty.\n */\nexport class NotEmptyError extends Error {\n\t/**\n\t * Name of the error class.\n\t * @type {string}\n\t */\n\tname = \"NotEmptyError\";\n\n\t/**\n\t * Error code.\n\t * @type {string}\n\t */\n\tcode = \"ENOTEMPTY\";\n\n\t/**\n\t * Creates a new instance.\n\t * @param {string} message The error message.\n\t */\n\tconstructor(message) {\n\t\tsuper(`ENOTEMPTY: Directory not empty, ${message}`);\n\t}\n}\n","/**\n * @fileoverview API entrypoint for hfs/core\n * @author Nicholas C. Zakas\n */\n\nexport { Hfs } from \"./hfs.js\";\nexport { Path } from \"./path.js\";\nexport * from \"./errors.js\";\n","// @ts-self-types=\"./retrier.d.ts\"\n/**\n * @fileoverview A utility for retrying failed async method calls.\n */\n\n/* global setTimeout, clearTimeout */\n\n//-----------------------------------------------------------------------------\n// Constants\n//-----------------------------------------------------------------------------\n\nconst MAX_TASK_TIMEOUT = 60000;\nconst MAX_TASK_DELAY = 100;\n\n//-----------------------------------------------------------------------------\n// Helpers\n//-----------------------------------------------------------------------------\n\n/*\n * The following logic has been extracted from graceful-fs.\n *\n * The ISC License\n *\n * Copyright (c) 2011-2023 Isaac Z. Schlueter, Ben Noordhuis, and Contributors\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\n * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\n * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR\n * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Checks if it is time to retry a task based on the timestamp and last attempt time.\n * @param {RetryTask} task The task to check.\n * @param {number} maxDelay The maximum delay for the queue.\n * @returns {boolean} true if it is time to retry, false otherwise.\n */\nfunction isTimeToRetry(task, maxDelay) {\n const timeSinceLastAttempt = Date.now() - task.lastAttempt;\n const timeSinceStart = Math.max(task.lastAttempt - task.timestamp, 1);\n const desiredDelay = Math.min(timeSinceStart * 1.2, maxDelay);\n\n return timeSinceLastAttempt >= desiredDelay;\n}\n\n/**\n * Checks if it is time to bail out based on the given timestamp.\n * @param {RetryTask} task The task to check.\n * @param {number} timeout The timeout for the queue.\n * @returns {boolean} true if it is time to bail, false otherwise.\n */\nfunction isTimeToBail(task, timeout) {\n return task.age > timeout;\n}\n\n\n/**\n * A class to represent a task in the retry queue.\n */\nclass RetryTask {\n\n /**\n * The unique ID for the task.\n * @type {string}\n */\n id = Math.random().toString(36).slice(2);\n\n /**\n * The function to call.\n * @type {Function}\n */\n fn;\n\n /**\n * The error that was thrown.\n * @type {Error}\n */\n error;\n \n /**\n * The timestamp of the task.\n * @type {number}\n */\n timestamp = Date.now();\n\n /**\n * The timestamp of the last attempt.\n * @type {number}\n */\n lastAttempt = this.timestamp;\n\n /**\n * The resolve function for the promise.\n * @type {Function}\n */\n resolve;\n\n /**\n * The reject function for the promise.\n * @type {Function}\n */\n reject;\n\n /**\n * The AbortSignal to monitor for cancellation.\n * @type {AbortSignal|undefined}\n */\n signal;\n\n /**\n * Creates a new instance.\n * @param {Function} fn The function to call.\n * @param {Error} error The error that was thrown.\n * @param {Function} resolve The resolve function for the promise.\n * @param {Function} reject The reject function for the promise.\n * @param {AbortSignal|undefined} signal The AbortSignal to monitor for cancellation.\n */\n constructor(fn, error, resolve, reject, signal) {\n this.fn = fn;\n this.error = error;\n this.timestamp = Date.now();\n this.lastAttempt = Date.now();\n this.resolve = resolve;\n this.reject = reject;\n this.signal = signal;\n }\n \n /**\n * Gets the age of the task.\n * @returns {number} The age of the task in milliseconds.\n * @readonly\n */\n get age() {\n return Date.now() - this.timestamp;\n }\n}\n\n//-----------------------------------------------------------------------------\n// Exports\n//-----------------------------------------------------------------------------\n\n/**\n * A class that manages a queue of retry jobs.\n */\nclass Retrier {\n\n /**\n * Represents the queue for processing tasks.\n * @type {Array<RetryTask>}\n */\n #queue = [];\n\n /**\n * The timeout for the queue.\n * @type {number}\n */\n #timeout;\n\n /**\n * The maximum delay for the queue.\n * @type {number}\n */\n #maxDelay;\n\n /**\n * The setTimeout() timer ID.\n * @type {NodeJS.Timeout|undefined}\n */\n #timerId;\n\n /**\n * The function to call.\n * @type {Function}\n */\n #check;\n\n /**\n * Creates a new instance.\n * @param {Function} check The function to call.\n * @param {object} [options] The options for the instance.\n * @param {number} [options.timeout] The timeout for the queue.\n * @param {number} [options.maxDelay] The maximum delay for the queue.\n */\n constructor(check, { timeout = MAX_TASK_TIMEOUT, maxDelay = MAX_TASK_DELAY } = {}) {\n\n if (typeof check !== \"function\") {\n throw new Error(\"Missing function to check errors\");\n }\n\n this.#check = check;\n this.#timeout = timeout;\n this.#maxDelay = maxDelay;\n }\n\n /**\n * Adds a new retry job to the queue.\n * @param {Function} fn The function to call.\n * @param {object} [options] The options for the job.\n * @param {AbortSignal} [options.signal] The AbortSignal to monitor for cancellation.\n * @returns {Promise<any>} A promise that resolves when the queue is\n * processed.\n */\n retry(fn, { signal } = {}) {\n\n signal?.throwIfAborted();\n\n let result;\n\n try {\n result = fn();\n } catch (/** @type {any} */ error) {\n return Promise.reject(new Error(`Synchronous error: ${error.message}`, { cause: error }));\n }\n\n // if the result is not a promise then reject an error\n if (!result || typeof result.then !== \"function\") {\n return Promise.reject(new Error(\"Result is not a promise.\"));\n }\n\n // call the original function and catch any ENFILE or EMFILE errors\n // @ts-ignore because we know it's any\n return Promise.resolve(result).catch(error => {\n if (!this.#check(error)) {\n throw error;\n }\n\n return new Promise((resolve, reject) => {\n this.#queue.push(new RetryTask(fn, error, resolve, reject, signal));\n\n signal?.addEventListener(\"abort\", () => {\n reject(signal.reason);\n });\n\n this.#processQueue();\n });\n });\n }\n\n /**\n * Processes the queue.\n * @returns {void}\n */\n #processQueue() {\n // clear any timer because we're going to check right now\n clearTimeout(this.#timerId);\n this.#timerId = undefined;\n\n // if there's nothing in the queue, we're done\n const task = this.#queue.shift();\n if (!task) {\n return;\n }\n const processAgain = () => {\n this.#timerId = setTimeout(() => this.#processQueue(), 0);\n };\n\n // if it's time to bail, then bail\n if (isTimeToBail(task, this.#timeout)) {\n task.reject(task.error);\n processAgain();\n return;\n }\n\n // if it's not time to retry, then wait and try again\n if (!isTimeToRetry(task, this.#maxDelay)) {\n this.#queue.push(task);\n processAgain();\n return;\n }\n\n // otherwise, try again\n task.lastAttempt = Date.now();\n \n // Promise.resolve needed in case it's a thenable but not a Promise\n Promise.resolve(task.fn())\n // @ts-ignore because we know it's any\n .then(result => task.resolve(result))\n\n // @ts-ignore because we know it's any\n .catch(error => {\n if (!this.#check(error)) {\n task.reject(error);\n return;\n }\n\n // update the task timestamp and push to back of queue to try again\n task.lastAttempt = Date.now();\n this.#queue.push(task);\n\n })\n .finally(() => this.#processQueue());\n }\n}\n\nexport { Retrier };\n","/**\n * @fileoverview The main file for the hfs package.\n * @author Nicholas C. Zakas\n */\n/* global Buffer:readonly, URL */\n\n//-----------------------------------------------------------------------------\n// Types\n//-----------------------------------------------------------------------------\n\n/** @typedef {import(\"@humanfs/types\").HfsImpl} HfsImpl */\n/** @typedef {import(\"@humanfs/types\").HfsDirectoryEntry} HfsDirectoryEntry */\n/** @typedef {import(\"node:fs/promises\")} Fsp */\n/** @typedef {import(\"fs\").Dirent} Dirent */\n\n//-----------------------------------------------------------------------------\n// Imports\n//-----------------------------------------------------------------------------\n\nimport { Hfs } from \"@humanfs/core\";\nimport path from \"node:path\";\nimport { Retrier } from \"@humanwhocodes/retry\";\nimport nativeFsp from \"node:fs/promises\";\nimport { fileURLToPath } from \"node:url\";\n\n//-----------------------------------------------------------------------------\n// Constants\n//-----------------------------------------------------------------------------\n\nconst RETRY_ERROR_CODES = new Set([\"ENFILE\", \"EMFILE\"]);\n\n//-----------------------------------------------------------------------------\n// Helpers\n//-----------------------------------------------------------------------------\n\n/**\n * A class representing a directory entry.\n * @implements {HfsDirectoryEntry}\n */\nclass NodeHfsDirectoryEntry {\n\t/**\n\t * The name of the directory entry.\n\t * @type {string}\n\t */\n\tname;\n\n\t/**\n\t * True if the entry is a file.\n\t * @type {boolean}\n\t */\n\tisFile;\n\n\t/**\n\t * True if the entry is a directory.\n\t * @type {boolean}\n\t */\n\tisDirectory;\n\n\t/**\n\t * True if the entry is a symbolic link.\n\t * @type {boolean}\n\t */\n\tisSymlink;\n\n\t/**\n\t * Creates a new instance.\n\t * @param {Dirent} dirent The directory entry to wrap.\n\t */\n\tconstructor(dirent) {\n\t\tthis.name = dirent.name;\n\t\tthis.isFile = dirent.isFile();\n\t\tthis.isDirectory = dirent.isDirectory();\n\t\tthis.isSymlink = dirent.isSymbolicLink();\n\t}\n}\n\n//-----------------------------------------------------------------------------\n// Exports\n//-----------------------------------------------------------------------------\n\n/**\n * A class representing the Node.js implementation of Hfs.\n * @implements {HfsImpl}\n */\nexport class NodeHfsImpl {\n\t/**\n\t * The file system module to use.\n\t * @type {Fsp}\n\t */\n\t#fsp;\n\n\t/**\n\t * The retryer object used for retrying operations.\n\t * @type {Retrier}\n\t */\n\t#retrier;\n\n\t/**\n\t * Creates a new instance.\n\t * @param {object} [options] The options for the instance.\n\t * @param {Fsp} [options.fsp] The file system module to use.\n\t */\n\tconstructor({ fsp = nativeFsp } = {}) {\n\t\tthis.#fsp = fsp;\n\t\tthis.#retrier = new Retrier(error => RETRY_ERROR_CODES.has(error.code));\n\t}\n\n\t/**\n\t * Reads a file and returns the contents as an Uint8Array.\n\t * @param {string|URL} filePath The path to the file to read.\n\t * @returns {Promise<Uint8Array|undefined>} A promise that resolves with the contents\n\t * of the file or undefined if the file doesn't exist.\n\t * @throws {Error} If the file cannot be read.\n\t * @throws {TypeError} If the file path is not a string.\n\t */\n\tbytes(filePath) {\n\t\treturn this.#retrier\n\t\t\t.retry(() => this.#fsp.readFile(filePath))\n\t\t\t.then(buffer => new Uint8Array(buffer.buffer))\n\t\t\t.catch(error => {\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Writes a value to a file. If the value is a string, UTF-8 encoding is used.\n\t * @param {string|URL} filePath The path to the file to write.\n\t * @param {Uint8Array} contents The contents to write to the\n\t * file.\n\t * @returns {Promise<void>} A promise that resolves when the file is\n\t * written.\n\t * @throws {TypeError} If the file path is not a string.\n\t * @throws {Error} If the file cannot be written.\n\t */\n\tasync write(filePath, contents) {\n\t\tconst value = Buffer.from(contents);\n\n\t\treturn this.#retrier\n\t\t\t.retry(() => this.#fsp.writeFile(filePath, value))\n\t\t\t.catch(error => {\n\t\t\t\t// the directory may not exist, so create it\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\tconst dirPath = path.dirname(\n\t\t\t\t\t\tfilePath instanceof URL\n\t\t\t\t\t\t\t? fileURLToPath(filePath)\n\t\t\t\t\t\t\t: filePath,\n\t\t\t\t\t);\n\n\t\t\t\t\treturn this.#fsp\n\t\t\t\t\t\t.mkdir(dirPath, { recursive: true })\n\t\t\t\t\t\t.then(() => this.#fsp.writeFile(filePath, value));\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Appends a value to a file. If the value is a string, UTF-8 encoding is used.\n\t * @param {string|URL} filePath The path to the file to append to.\n\t * @param {Uint8Array} contents The contents to append to the\n\t * file.\n\t * @returns {Promise<void>} A promise that resolves when the file is\n\t * written.\n\t * @throws {TypeError} If the file path is not a string.\n\t * @throws {Error} If the file cannot be appended to.\n\t */\n\tasync append(filePath, contents) {\n\t\tconst value = Buffer.from(contents);\n\n\t\treturn this.#retrier\n\t\t\t.retry(() => this.#fsp.appendFile(filePath, value))\n\t\t\t.catch(error => {\n\t\t\t\t// the directory may not exist, so create it\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\tconst dirPath = path.dirname(\n\t\t\t\t\t\tfilePath instanceof URL\n\t\t\t\t\t\t\t? fileURLToPath(filePath)\n\t\t\t\t\t\t\t: filePath,\n\t\t\t\t\t);\n\n\t\t\t\t\treturn this.#fsp\n\t\t\t\t\t\t.mkdir(dirPath, { recursive: true })\n\t\t\t\t\t\t.then(() => this.#fsp.appendFile(filePath, value));\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Checks if a file exists.\n\t * @param {string|URL} filePath The path to the file to check.\n\t * @returns {Promise<boolean>} A promise that resolves with true if the\n\t * file exists or false if it does not.\n\t * @throws {Error} If the operation fails with a code other than ENOENT.\n\t */\n\tisFile(filePath) {\n\t\treturn this.#fsp\n\t\t\t.stat(filePath)\n\t\t\t.then(stat => stat.isFile())\n\t\t\t.catch(error => {\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Checks if a directory exists.\n\t * @param {string|URL} dirPath The path to the directory to check.\n\t * @returns {Promise<boolean>} A promise that resolves with true if the\n\t * directory exists or false if it does not.\n\t * @throws {Error} If the operation fails with a code other than ENOENT.\n\t */\n\tisDirectory(dirPath) {\n\t\treturn this.#fsp\n\t\t\t.stat(dirPath)\n\t\t\t.then(stat => stat.isDirectory())\n\t\t\t.catch(error => {\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Creates a directory recursively.\n\t * @param {string|URL} dirPath The path to the directory to create.\n\t * @returns {Promise<void>} A promise that resolves when the directory is\n\t * created.\n\t */\n\tasync createDirectory(dirPath) {\n\t\tawait this.#fsp.mkdir(dirPath, { recursive: true });\n\t}\n\n\t/**\n\t * Deletes a file or empty directory.\n\t * @param {string|URL} fileOrDirPath The path to the file or directory to\n\t * delete.\n\t * @returns {Promise<boolean>} A promise that resolves when the file or\n\t * directory is deleted, true if the file or directory is deleted, false\n\t * if the file or directory does not exist.\n\t * @throws {TypeError} If the file or directory path is not a string.\n\t * @throws {Error} If the file or directory cannot be deleted.\n\t */\n\tdelete(fileOrDirPath) {\n\t\treturn this.#fsp\n\t\t\t.rm(fileOrDirPath)\n\t\t\t.then(() => true)\n\t\t\t.catch(error => {\n\t\t\t\tif (error.code === \"ERR_FS_EISDIR\") {\n\t\t\t\t\treturn this.#fsp.rmdir(fileOrDirPath).then(() => true);\n\t\t\t\t}\n\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Deletes a file or directory recursively.\n\t * @param {string|URL} fileOrDirPath The path to the file or directory to\n\t * delete.\n\t * @returns {Promise<boolean>} A promise that resolves when the file or\n\t * directory is deleted, true if the file or directory is deleted, false\n\t * if the file or directory does not exist.\n\t * @throws {TypeError} If the file or directory path is not a string.\n\t * @throws {Error} If the file or directory cannot be deleted.\n\t */\n\tdeleteAll(fileOrDirPath) {\n\t\treturn this.#fsp\n\t\t\t.rm(fileOrDirPath, { recursive: true })\n\t\t\t.then(() => true)\n\t\t\t.catch(error => {\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Returns a list of directory entries for the given path.\n\t * @param {string|URL} dirPath The path to the directory to read.\n\t * @returns {AsyncIterable<HfsDirectoryEntry>} A promise that resolves with the\n\t * directory entries.\n\t * @throws {TypeError} If the directory path is not a string.\n\t * @throws {Error} If the directory cannot be read.\n\t */\n\tasync *list(dirPath) {\n\t\tconst entries = await this.#fsp.readdir(dirPath, {\n\t\t\twithFileTypes: true,\n\t\t});\n\n\t\tfor (const entry of entries) {\n\t\t\tyield new NodeHfsDirectoryEntry(entry);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the size of a file. This method handles ENOENT errors\n\t * and returns undefined in that case.\n\t * @param {string|URL} filePath The path to the file to read.\n\t * @returns {Promise<number|undefined>} A promise that resolves with the size of the\n\t * file in bytes or undefined if the file doesn't exist.\n\t */\n\tsize(filePath) {\n\t\treturn this.#fsp\n\t\t\t.stat(filePath)\n\t\t\t.then(stat => stat.size)\n\t\t\t.catch(error => {\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Returns the last modified date of a file or directory. This method handles ENOENT errors\n\t * and returns undefined in that case.\n\t * @param {string|URL} fileOrDirPath The path to the file to read.\n\t * @returns {Promise<Date|undefined>} A promise that resolves with the last modified\n\t * date of the file or directory, or undefined if the file doesn't exist.\n\t */\n\tlastModified(fileOrDirPath) {\n\t\treturn this.#fsp\n\t\t\t.stat(fileOrDirPath)\n\t\t\t.then(stat => stat.mtime)\n\t\t\t.catch(error => {\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Copies a file from one location to another.\n\t * @param {string|URL} source The path to the file to copy.\n\t * @param {string|URL} destination The path to copy the file to.\n\t * @returns {Promise<void>} A promise that resolves when the file is copied.\n\t * @throws {Error} If the source file does not exist.\n\t * @throws {Error} If the source file is a directory.\n\t * @throws {Error} If the destination file is a directory.\n\t */\n\tcopy(source, destination) {\n\t\treturn this.#fsp.copyFile(source, destination);\n\t}\n\n\t/**\n\t * Copies a file or directory from one location to another.\n\t * @param {string|URL} source The path to the file or directory to copy.\n\t * @param {string|URL} destination The path to copy the file or directory to.\n\t * @returns {Promise<void>} A promise that resolves when the file or directory is\n\t * copied.\n\t * @throws {Error} If the source file or directory does not exist.\n\t * @throws {Error} If the destination file or directory is a directory.\n\t */\n\tasync copyAll(source, destination) {\n\t\t// for files use copy() and exit\n\t\tif (await this.isFile(source)) {\n\t\t\treturn this.copy(source, destination);\n\t\t}\n\n\t\tconst sourceStr =\n\t\t\tsource instanceof URL ? fileURLToPath(source) : source;\n\n\t\tconst destinationStr =\n\t\t\tdestination instanceof URL\n\t\t\t\t? fileURLToPath(destination)\n\t\t\t\t: destination;\n\n\t\t// for directories, create the destination directory and copy each entry\n\t\tawait this.createDirectory(destination);\n\n\t\tfor await (const entry of this.list(source)) {\n\t\t\tconst fromEntryPath = path.join(sourceStr, entry.name);\n\t\t\tconst toEntryPath = path.join(destinationStr, entry.name);\n\n\t\t\tif (entry.isDirectory) {\n\t\t\t\tawait this.copyAll(fromEntryPath, toEntryPath);\n\t\t\t} else {\n\t\t\t\tawait this.copy(fromEntryPath, toEntryPath);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Moves a file from the source path to the destination path.\n\t * @param {string|URL} source The location of the file to move.\n\t * @param {string|URL} destination The destination of the file to move.\n\t * @returns {Promise<void>} A promise that resolves when the move is complete.\n\t * @throws {TypeError} If the file paths are not strings.\n\t * @throws {Error} If the file cannot be moved.\n\t */\n\tmove(source, destination) {\n\t\treturn this.#fsp.stat(source).then(stat => {\n\t\t\tif (stat.isDirectory()) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`EISDIR: illegal operation on a directory, move '${source}' -> '${destination}'`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn this.#fsp.rename(source, destination);\n\t\t});\n\t}\n\n\t/**\n\t * Moves a file or directory from the source path to the destination path.\n\t * @param {string|URL} source The location of the file or directory to move.\n\t * @param {string|URL} destination The destination of the file or directory to move.\n\t * @returns {Promise<void>} A promise that resolves when the move is complete.\n\t * @throws {TypeError} If the file paths are not strings.\n\t * @throws {Error} If the file or directory cannot be moved.\n\t */\n\tasync moveAll(source, destination) {\n\t\treturn this.#fsp.rename(source, destination);\n\t}\n}\n\n/**\n * A class representing a file system utility library.\n * @implements {HfsImpl}\n */\nexport class NodeHfs extends Hfs {\n\t/**\n\t * Creates a new instance.\n\t * @param {object} [options] The options for the instance.\n\t * @param {Fsp} [options.fsp] The file system module to use.\n\t */\n\tconstructor({ fsp } = {}) {\n\t\tsuper({ impl: new NodeHfsImpl({ fsp }) });\n\t}\n}\n\nexport const hfs = new NodeHfs();\n","/**\n * @fileoverview This file exports everything for this package.\n * @author Nicholas C. Zakas\n */\n\nexport * from \"./node-hfs.js\";\nexport { Hfs } from \"@humanfs/core\";\n"],"x_google_ignoreList":[0,1,2,3,4,5],"mappings":";;;;;;;;;;;;AAoEA,SAAS,yBAAyB,eAAe;AAChD,KACC,CAAC,iBACA,EAAE,yBAAyB,QAAQ,OAAO,kBAAkB,SAE7D,OAAM,IAAI,UAAU,0CAA0C;;;;;;;;AAUhE,SAAS,wBAAwB,UAAU;AAC1C,KACC,OAAO,aAAa,YACpB,EAAE,oBAAoB,gBACtB,CAAC,YAAY,OAAO,SAAS,CAE7B,OAAM,IAAI,UACT,oEACA;;;;;;;;AAUH,SAAS,aAAa,UAAU;AAC/B,KAAI,oBAAoB,WACvB,QAAO;AAGR,KAAI,OAAO,aAAa,SACvB,QAAO,QAAQ,OAAO,SAAS;AAGhC,KAAI,oBAAoB,YACvB,QAAO,IAAI,WAAW,SAAS;AAGhC,KAAI,YAAY,OAAO,SAAS,EAAE;EACjC,MAAM,QAAQ,SAAS,OAAO,MAC7B,SAAS,YACT,SAAS,aAAa,SAAS,WAC/B;AACD,SAAO,IAAI,WAAW,MAAM;;AAE7B,OAAM,IAAI,UACT,yDACA;;;;CAxGI,UAAU,IAAI,aAAa;CAC3B,UAAU,IAAI,aAAa;CAKpB,oBAAb,cAAuC,MAAM;;;;;EAK5C,YAAY,YAAY;AACvB,SAAM,WAAW,WAAW,2BAA2B;;;CAS5C,0BAAb,cAA6C,MAAM;;;;;EAKlD,YAAY,YAAY;AACvB,SAAM,WAAW,WAAW,kCAAkC;;;CAOnD,sBAAb,cAAyC,MAA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ACT,mDAAmD,OAAO,QAAQ,YAAY,GAC9E;AAGF,WAAO,MAAKA,IAAK,OAAO,QAAQ,YAAY;KAC3C;;;;;;;;;;EAWH,MAAM,QAAQ,QAAQ,aAAa;AAClC,UAAO,MAAKA,IAAK,OAAO,QAAQ,YAAY;;;CAQjC,UAAb,cAA6B,IAAI;;;;;;EAMhC,YAAY,EAAE,QAAQ,EAAE,EAAE;AACzB,SAAM,EAAE,MAAM,IAAI,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC;;;CAI9B,MAAM,IAAI,SAAS;;;;;;;aC7bI"}
1
+ {"version":3,"file":"src-Bb1UVstT.mjs","names":["#baseImpl","#impl","#logs","#log","#assertImplMethod","#assertImplMethodAlt","#callImplMethodAlt","#callImplMethod","#callImplMethodWithoutLog","dirPath","entryFilter","directoryFilter","#check","#timeout","#maxDelay","#queue","#processQueue","#timerId","#fsp","#retrier"],"sources":["../../../node_modules/@humanfs/core/src/hfs.js","../../../node_modules/@humanfs/core/src/errors.js","../../../node_modules/@humanfs/core/src/index.js","../../../node_modules/@humanwhocodes/retry/dist/retrier.js","../../../node_modules/@humanfs/node/src/node-hfs.js","../../../node_modules/@humanfs/node/src/index.js"],"sourcesContent":["/**\n * @fileoverview The main file for the humanfs package.\n * @author Nicholas C. Zakas\n */\n\n/* global URL, TextDecoder, TextEncoder */\n\n//-----------------------------------------------------------------------------\n// Types\n//-----------------------------------------------------------------------------\n\n/** @typedef {import(\"@humanfs/types\").HfsImpl} HfsImpl */\n/** @typedef {import(\"@humanfs/types\").HfsDirectoryEntry} HfsDirectoryEntry */\n/** @typedef {import(\"@humanfs/types\").HfsWalkEntry} HfsWalkEntry */\n\n//-----------------------------------------------------------------------------\n// Helpers\n//-----------------------------------------------------------------------------\n\nconst decoder = new TextDecoder();\nconst encoder = new TextEncoder();\n\n/**\n * Error to represent when a method is missing on an impl.\n */\nexport class NoSuchMethodError extends Error {\n\t/**\n\t * Creates a new instance.\n\t * @param {string} methodName The name of the method that was missing.\n\t */\n\tconstructor(methodName) {\n\t\tsuper(`Method \"${methodName}\" does not exist on impl.`);\n\t}\n}\n\n/**\n * Error to represent when a method is not supported on an impl. This happens\n * when a method on `Hfs` is called with one name and the corresponding method\n * on the impl has a different name. (Example: `text()` and `bytes()`.)\n */\nexport class MethodNotSupportedError extends Error {\n\t/**\n\t * Creates a new instance.\n\t * @param {string} methodName The name of the method that was missing.\n\t */\n\tconstructor(methodName) {\n\t\tsuper(`Method \"${methodName}\" is not supported on this impl.`);\n\t}\n}\n\n/**\n * Error to represent when an impl is already set.\n */\nexport class ImplAlreadySetError extends Error {\n\t/**\n\t * Creates a new instance.\n\t */\n\tconstructor() {\n\t\tsuper(`Implementation already set.`);\n\t}\n}\n\n/**\n * Asserts that the given path is a valid file path.\n * @param {any} fileOrDirPath The path to check.\n * @returns {void}\n * @throws {TypeError} When the path is not a non-empty string.\n */\nfunction assertValidFileOrDirPath(fileOrDirPath) {\n\tif (\n\t\t!fileOrDirPath ||\n\t\t(!(fileOrDirPath instanceof URL) && typeof fileOrDirPath !== \"string\")\n\t) {\n\t\tthrow new TypeError(\"Path must be a non-empty string or URL.\");\n\t}\n}\n\n/**\n * Asserts that the given file contents are valid.\n * @param {any} contents The contents to check.\n * @returns {void}\n * @throws {TypeError} When the contents are not a string or ArrayBuffer.\n */\nfunction assertValidFileContents(contents) {\n\tif (\n\t\ttypeof contents !== \"string\" &&\n\t\t!(contents instanceof ArrayBuffer) &&\n\t\t!ArrayBuffer.isView(contents)\n\t) {\n\t\tthrow new TypeError(\n\t\t\t\"File contents must be a string, ArrayBuffer, or ArrayBuffer view.\",\n\t\t);\n\t}\n}\n\n/**\n * Converts the given contents to Uint8Array.\n * @param {any} contents The data to convert.\n * @returns {Uint8Array} The converted Uint8Array.\n * @throws {TypeError} When the contents are not a string or ArrayBuffer.\n */\nfunction toUint8Array(contents) {\n\tif (contents instanceof Uint8Array) {\n\t\treturn contents;\n\t}\n\n\tif (typeof contents === \"string\") {\n\t\treturn encoder.encode(contents);\n\t}\n\n\tif (contents instanceof ArrayBuffer) {\n\t\treturn new Uint8Array(contents);\n\t}\n\n\tif (ArrayBuffer.isView(contents)) {\n\t\tconst bytes = contents.buffer.slice(\n\t\t\tcontents.byteOffset,\n\t\t\tcontents.byteOffset + contents.byteLength,\n\t\t);\n\t\treturn new Uint8Array(bytes);\n\t}\n\tthrow new TypeError(\n\t\t\"Invalid contents type. Expected string or ArrayBuffer.\",\n\t);\n}\n\n//-----------------------------------------------------------------------------\n// Exports\n//-----------------------------------------------------------------------------\n\n/**\n * A class representing a log entry.\n */\nexport class LogEntry {\n\t/**\n\t * The type of log entry.\n\t * @type {string}\n\t */\n\ttype;\n\n\t/**\n\t * The data associated with the log entry.\n\t * @type {any}\n\t */\n\tdata;\n\n\t/**\n\t * The time at which the log entry was created.\n\t * @type {number}\n\t */\n\ttimestamp = Date.now();\n\n\t/**\n\t * Creates a new instance.\n\t * @param {string} type The type of log entry.\n\t * @param {any} [data] The data associated with the log entry.\n\t */\n\tconstructor(type, data) {\n\t\tthis.type = type;\n\t\tthis.data = data;\n\t}\n}\n\n/**\n * A class representing a file system utility library.\n * @implements {HfsImpl}\n */\nexport class Hfs {\n\t/**\n\t * The base implementation for this instance.\n\t * @type {HfsImpl}\n\t */\n\t#baseImpl;\n\n\t/**\n\t * The current implementation for this instance.\n\t * @type {HfsImpl}\n\t */\n\t#impl;\n\n\t/**\n\t * A map of log names to their corresponding entries.\n\t * @type {Map<string,Array<LogEntry>>}\n\t */\n\t#logs = new Map();\n\n\t/**\n\t * Creates a new instance.\n\t * @param {object} options The options for the instance.\n\t * @param {HfsImpl} options.impl The implementation to use.\n\t */\n\tconstructor({ impl }) {\n\t\tthis.#baseImpl = impl;\n\t\tthis.#impl = impl;\n\t}\n\n\t/**\n\t * Logs an entry onto all currently open logs.\n\t * @param {string} methodName The name of the method being called.\n\t * @param {...*} args The arguments to the method.\n\t * @returns {void}\n\t */\n\t#log(methodName, ...args) {\n\t\tfor (const logs of this.#logs.values()) {\n\t\t\tlogs.push(new LogEntry(\"call\", { methodName, args }));\n\t\t}\n\t}\n\n\t/**\n\t * Starts a new log with the given name.\n\t * @param {string} name The name of the log to start;\n\t * @returns {void}\n\t * @throws {Error} When the log already exists.\n\t * @throws {TypeError} When the name is not a non-empty string.\n\t */\n\tlogStart(name) {\n\t\tif (!name || typeof name !== \"string\") {\n\t\t\tthrow new TypeError(\"Log name must be a non-empty string.\");\n\t\t}\n\n\t\tif (this.#logs.has(name)) {\n\t\t\tthrow new Error(`Log \"${name}\" already exists.`);\n\t\t}\n\n\t\tthis.#logs.set(name, []);\n\t}\n\n\t/**\n\t * Ends a log with the given name and returns the entries.\n\t * @param {string} name The name of the log to end.\n\t * @returns {Array<LogEntry>} The entries in the log.\n\t * @throws {Error} When the log does not exist.\n\t */\n\tlogEnd(name) {\n\t\tif (this.#logs.has(name)) {\n\t\t\tconst logs = this.#logs.get(name);\n\t\t\tthis.#logs.delete(name);\n\t\t\treturn logs;\n\t\t}\n\n\t\tthrow new Error(`Log \"${name}\" does not exist.`);\n\t}\n\n\t/**\n\t * Determines if the current implementation is the base implementation.\n\t * @returns {boolean} True if the current implementation is the base implementation.\n\t */\n\tisBaseImpl() {\n\t\treturn this.#impl === this.#baseImpl;\n\t}\n\n\t/**\n\t * Sets the implementation for this instance.\n\t * @param {object} impl The implementation to use.\n\t * @returns {void}\n\t */\n\tsetImpl(impl) {\n\t\tthis.#log(\"implSet\", impl);\n\n\t\tif (this.#impl !== this.#baseImpl) {\n\t\t\tthrow new ImplAlreadySetError();\n\t\t}\n\n\t\tthis.#impl = impl;\n\t}\n\n\t/**\n\t * Resets the implementation for this instance back to its original.\n\t * @returns {void}\n\t */\n\tresetImpl() {\n\t\tthis.#log(\"implReset\");\n\t\tthis.#impl = this.#baseImpl;\n\t}\n\n\t/**\n\t * Asserts that the given method exists on the current implementation.\n\t * @param {string} methodName The name of the method to check.\n\t * @returns {void}\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t */\n\t#assertImplMethod(methodName) {\n\t\tif (typeof this.#impl[methodName] !== \"function\") {\n\t\t\tthrow new NoSuchMethodError(methodName);\n\t\t}\n\t}\n\n\t/**\n\t * Asserts that the given method exists on the current implementation, and if not,\n\t * throws an error with a different method name.\n\t * @param {string} methodName The name of the method to check.\n\t * @param {string} targetMethodName The name of the method that should be reported\n\t * as an error when methodName does not exist.\n\t * @returns {void}\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t */\n\t#assertImplMethodAlt(methodName, targetMethodName) {\n\t\tif (typeof this.#impl[methodName] !== \"function\") {\n\t\t\tthrow new MethodNotSupportedError(targetMethodName);\n\t\t}\n\t}\n\n\t/**\n\t * Calls the given method on the current implementation.\n\t * @param {string} methodName The name of the method to call.\n\t * @param {...any} args The arguments to the method.\n\t * @returns {any} The return value from the method.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t */\n\t#callImplMethod(methodName, ...args) {\n\t\tthis.#log(methodName, ...args);\n\t\tthis.#assertImplMethod(methodName);\n\t\treturn this.#impl[methodName](...args);\n\t}\n\n\t/**\n\t * Calls the given method on the current implementation and doesn't log the call.\n\t * @param {string} methodName The name of the method to call.\n\t * @param {...any} args The arguments to the method.\n\t * @returns {any} The return value from the method.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t */\n\t#callImplMethodWithoutLog(methodName, ...args) {\n\t\tthis.#assertImplMethod(methodName);\n\t\treturn this.#impl[methodName](...args);\n\t}\n\n\t/**\n\t * Calls the given method on the current implementation but logs a different method name.\n\t * @param {string} methodName The name of the method to call.\n\t * @param {string} targetMethodName The name of the method to log.\n\t * @param {...any} args The arguments to the method.\n\t * @returns {any} The return value from the method.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t */\n\t#callImplMethodAlt(methodName, targetMethodName, ...args) {\n\t\tthis.#log(targetMethodName, ...args);\n\t\tthis.#assertImplMethodAlt(methodName, targetMethodName);\n\t\treturn this.#impl[methodName](...args);\n\t}\n\n\t/**\n\t * Reads the given file and returns the contents as text. Assumes UTF-8 encoding.\n\t * @param {string|URL} filePath The file to read.\n\t * @returns {Promise<string|undefined>} The contents of the file.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the file path is not a non-empty string.\n\t */\n\tasync text(filePath) {\n\t\tassertValidFileOrDirPath(filePath);\n\n\t\tconst result = await this.#callImplMethodAlt(\"bytes\", \"text\", filePath);\n\t\treturn result ? decoder.decode(result) : undefined;\n\t}\n\n\t/**\n\t * Reads the given file and returns the contents as JSON. Assumes UTF-8 encoding.\n\t * @param {string|URL} filePath The file to read.\n\t * @returns {Promise<any|undefined>} The contents of the file as JSON.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {SyntaxError} When the file contents are not valid JSON.\n\t * @throws {TypeError} When the file path is not a non-empty string.\n\t */\n\tasync json(filePath) {\n\t\tassertValidFileOrDirPath(filePath);\n\n\t\tconst result = await this.#callImplMethodAlt(\"bytes\", \"json\", filePath);\n\t\treturn result ? JSON.parse(decoder.decode(result)) : undefined;\n\t}\n\n\t/**\n\t * Reads the given file and returns the contents as an ArrayBuffer.\n\t * @param {string|URL} filePath The file to read.\n\t * @returns {Promise<ArrayBuffer|undefined>} The contents of the file as an ArrayBuffer.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the file path is not a non-empty string.\n\t * @deprecated Use bytes() instead.\n\t */\n\tasync arrayBuffer(filePath) {\n\t\tassertValidFileOrDirPath(filePath);\n\n\t\tconst result = await this.#callImplMethodAlt(\n\t\t\t\"bytes\",\n\t\t\t\"arrayBuffer\",\n\t\t\tfilePath,\n\t\t);\n\t\treturn result?.buffer;\n\t}\n\n\t/**\n\t * Reads the given file and returns the contents as an Uint8Array.\n\t * @param {string|URL} filePath The file to read.\n\t * @returns {Promise<Uint8Array|undefined>} The contents of the file as an Uint8Array.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the file path is not a non-empty string.\n\t */\n\tasync bytes(filePath) {\n\t\tassertValidFileOrDirPath(filePath);\n\t\treturn this.#callImplMethod(\"bytes\", filePath);\n\t}\n\n\t/**\n\t * Writes the given data to the given file. Creates any necessary directories along the way.\n\t * If the data is a string, UTF-8 encoding is used.\n\t * @param {string|URL} filePath The file to write.\n\t * @param {string|ArrayBuffer|ArrayBufferView} contents The data to write.\n\t * @returns {Promise<void>} A promise that resolves when the file is written.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the file path is not a non-empty string.\n\t */\n\tasync write(filePath, contents) {\n\t\tassertValidFileOrDirPath(filePath);\n\t\tassertValidFileContents(contents);\n\t\tthis.#log(\"write\", filePath, contents);\n\n\t\tlet value = toUint8Array(contents);\n\t\treturn this.#callImplMethodWithoutLog(\"write\", filePath, value);\n\t}\n\n\t/**\n\t * Appends the given data to the given file. Creates any necessary directories along the way.\n\t * If the data is a string, UTF-8 encoding is used.\n\t * @param {string|URL} filePath The file to append to.\n\t * @param {string|ArrayBuffer|ArrayBufferView} contents The data to append.\n\t * @returns {Promise<void>} A promise that resolves when the file is appended to.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the file path is not a non-empty string.\n\t * @throws {TypeError} When the file contents are not a string or ArrayBuffer.\n\t * @throws {Error} When the file cannot be appended to.\n\t */\n\tasync append(filePath, contents) {\n\t\tassertValidFileOrDirPath(filePath);\n\t\tassertValidFileContents(contents);\n\t\tthis.#log(\"append\", filePath, contents);\n\n\t\tlet value = toUint8Array(contents);\n\t\treturn this.#callImplMethodWithoutLog(\"append\", filePath, value);\n\t}\n\n\t/**\n\t * Determines if the given file exists.\n\t * @param {string|URL} filePath The file to check.\n\t * @returns {Promise<boolean>} True if the file exists.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the file path is not a non-empty string.\n\t */\n\tasync isFile(filePath) {\n\t\tassertValidFileOrDirPath(filePath);\n\t\treturn this.#callImplMethod(\"isFile\", filePath);\n\t}\n\n\t/**\n\t * Determines if the given directory exists.\n\t * @param {string|URL} dirPath The directory to check.\n\t * @returns {Promise<boolean>} True if the directory exists.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the directory path is not a non-empty string.\n\t */\n\tasync isDirectory(dirPath) {\n\t\tassertValidFileOrDirPath(dirPath);\n\t\treturn this.#callImplMethod(\"isDirectory\", dirPath);\n\t}\n\n\t/**\n\t * Creates the given directory.\n\t * @param {string|URL} dirPath The directory to create.\n\t * @returns {Promise<void>} A promise that resolves when the directory is created.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the directory path is not a non-empty string.\n\t */\n\tasync createDirectory(dirPath) {\n\t\tassertValidFileOrDirPath(dirPath);\n\t\treturn this.#callImplMethod(\"createDirectory\", dirPath);\n\t}\n\n\t/**\n\t * Deletes the given file or empty directory.\n\t * @param {string|URL} filePath The file to delete.\n\t * @returns {Promise<boolean>} A promise that resolves when the file or\n\t * directory is deleted, true if the file or directory is deleted, false\n\t * if the file or directory does not exist.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the file path is not a non-empty string.\n\t */\n\tasync delete(filePath) {\n\t\tassertValidFileOrDirPath(filePath);\n\t\treturn this.#callImplMethod(\"delete\", filePath);\n\t}\n\n\t/**\n\t * Deletes the given file or directory recursively.\n\t * @param {string|URL} dirPath The directory to delete.\n\t * @returns {Promise<boolean>} A promise that resolves when the file or\n\t * directory is deleted, true if the file or directory is deleted, false\n\t * if the file or directory does not exist.\n\t * @throws {NoSuchMethodError} When the method does not exist on the current implementation.\n\t * @throws {TypeError} When the directory path is not a non-empty string.\n\t */\n\tasync deleteAll(dirPath) {\n\t\tassertValidFileOrDirPath(dirPath);\n\t\treturn this.#callImplMethod(\"deleteAll\", dirPath);\n\t}\n\n\t/**\n\t * Returns a list of directory entries for the given path.\n\t * @param {string|URL} dirPath The path to the directory to read.\n\t * @returns {AsyncIterable<HfsDirectoryEntry>} A promise that resolves with the\n\t * directory entries.\n\t * @throws {TypeError} If the directory path is not a string or URL.\n\t * @throws {Error} If the directory cannot be read.\n\t */\n\tasync *list(dirPath) {\n\t\tassertValidFileOrDirPath(dirPath);\n\t\tyield* await this.#callImplMethod(\"list\", dirPath);\n\t}\n\n\t/**\n\t * Walks a directory using a depth-first traversal and returns the entries\n\t * from the traversal.\n\t * @param {string|URL} dirPath The path to the directory to walk.\n\t * @param {Object} [options] The options for the walk.\n\t * @param {(entry:HfsWalkEntry) => Promise<boolean>|boolean} [options.directoryFilter] A filter function to determine\n\t * \tif a directory's entries should be included in the walk.\n\t * @param {(entry:HfsWalkEntry) => Promise<boolean>|boolean} [options.entryFilter] A filter function to determine if\n\t * \tan entry should be included in the walk.\n\t * @returns {AsyncIterable<HfsWalkEntry>} A promise that resolves with the\n\t * \tdirectory entries.\n\t * @throws {TypeError} If the directory path is not a string or URL.\n\t * @throws {Error} If the directory cannot be read.\n\t */\n\tasync *walk(\n\t\tdirPath,\n\t\t{ directoryFilter = () => true, entryFilter = () => true } = {},\n\t) {\n\t\tassertValidFileOrDirPath(dirPath);\n\t\tthis.#log(\"walk\", dirPath, { directoryFilter, entryFilter });\n\n\t\t// inner function for recursion without additional logging\n\t\tconst walk = async function* (\n\t\t\tdirPath,\n\t\t\t{ directoryFilter, entryFilter, parentPath = \"\", depth = 1 },\n\t\t) {\n\t\t\tlet dirEntries;\n\n\t\t\ttry {\n\t\t\t\tdirEntries = await this.#callImplMethodWithoutLog(\n\t\t\t\t\t\"list\",\n\t\t\t\t\tdirPath,\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\t// if the directory does not exist then return an empty array\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// otherwise, rethrow the error\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tfor await (const listEntry of dirEntries) {\n\t\t\t\tconst walkEntry = {\n\t\t\t\t\tpath: listEntry.name,\n\t\t\t\t\tdepth,\n\t\t\t\t\t...listEntry,\n\t\t\t\t};\n\n\t\t\t\tif (parentPath) {\n\t\t\t\t\twalkEntry.path = `${parentPath}/${walkEntry.path}`;\n\t\t\t\t}\n\n\t\t\t\t// first emit the entry but only if the entry filter returns true\n\t\t\t\tlet shouldEmitEntry = entryFilter(walkEntry);\n\t\t\t\tif (shouldEmitEntry.then) {\n\t\t\t\t\tshouldEmitEntry = await shouldEmitEntry;\n\t\t\t\t}\n\n\t\t\t\tif (shouldEmitEntry) {\n\t\t\t\t\tyield walkEntry;\n\t\t\t\t}\n\n\t\t\t\t// if it's a directory then yield the entry and walk the directory\n\t\t\t\tif (listEntry.isDirectory) {\n\t\t\t\t\t// if the directory filter returns false, skip the directory\n\t\t\t\t\tlet shouldWalkDirectory = directoryFilter(walkEntry);\n\t\t\t\t\tif (shouldWalkDirectory.then) {\n\t\t\t\t\t\tshouldWalkDirectory = await shouldWalkDirectory;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!shouldWalkDirectory) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// make sure there's a trailing slash on the directory path before appending\n\t\t\t\t\tconst directoryPath =\n\t\t\t\t\t\tdirPath instanceof URL\n\t\t\t\t\t\t\t? new URL(\n\t\t\t\t\t\t\t\t\tlistEntry.name,\n\t\t\t\t\t\t\t\t\tdirPath.href.endsWith(\"/\")\n\t\t\t\t\t\t\t\t\t\t? dirPath.href\n\t\t\t\t\t\t\t\t\t\t: `${dirPath.href}/`,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: `${dirPath.endsWith(\"/\") ? dirPath : `${dirPath}/`}${listEntry.name}`;\n\n\t\t\t\t\tyield* walk(directoryPath, {\n\t\t\t\t\t\tdirectoryFilter,\n\t\t\t\t\t\tentryFilter,\n\t\t\t\t\t\tparentPath: walkEntry.path,\n\t\t\t\t\t\tdepth: depth + 1,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}.bind(this);\n\n\t\tyield* walk(dirPath, { directoryFilter, entryFilter });\n\t}\n\n\t/**\n\t * Returns the size of the given file.\n\t * @param {string|URL} filePath The path to the file to read.\n\t * @returns {Promise<number>} A promise that resolves with the size of the file.\n\t * @throws {TypeError} If the file path is not a string or URL.\n\t * @throws {Error} If the file cannot be read.\n\t */\n\tasync size(filePath) {\n\t\tassertValidFileOrDirPath(filePath);\n\t\treturn this.#callImplMethod(\"size\", filePath);\n\t}\n\n\t/**\n\t * Returns the last modified timestamp of the given file or directory.\n\t * @param {string|URL} fileOrDirPath The path to the file or directory.\n\t * @returns {Promise<Date|undefined>} A promise that resolves with the last modified date\n\t * or undefined if the file or directory does not exist.\n\t * @throws {TypeError} If the path is not a string or URL.\n\t */\n\tasync lastModified(fileOrDirPath) {\n\t\tassertValidFileOrDirPath(fileOrDirPath);\n\t\treturn this.#callImplMethod(\"lastModified\", fileOrDirPath);\n\t}\n\n\t/**\n\t * Copys a file from one location to another.\n\t * @param {string|URL} source The path to the file to copy.\n\t * @param {string|URL} destination The path to the new file.\n\t * @returns {Promise<void>} A promise that resolves when the file is copied.\n\t * @throws {TypeError} If the file path is not a string or URL.\n\t * @throws {Error} If the file cannot be copied.\n\t */\n\tasync copy(source, destination) {\n\t\tassertValidFileOrDirPath(source);\n\t\tassertValidFileOrDirPath(destination);\n\t\treturn this.#callImplMethod(\"copy\", source, destination);\n\t}\n\n\t/**\n\t * Copies a file or directory from one location to another.\n\t * @param {string|URL} source The path to the file or directory to copy.\n\t * @param {string|URL} destination The path to copy the file or directory to.\n\t * @returns {Promise<void>} A promise that resolves when the file or directory is\n\t * copied.\n\t * @throws {TypeError} If the directory path is not a string or URL.\n\t * @throws {Error} If the directory cannot be copied.\n\t */\n\tasync copyAll(source, destination) {\n\t\tassertValidFileOrDirPath(source);\n\t\tassertValidFileOrDirPath(destination);\n\t\treturn this.#callImplMethod(\"copyAll\", source, destination);\n\t}\n\n\t/**\n\t * Moves a file from the source path to the destination path.\n\t * @param {string|URL} source The location of the file to move.\n\t * @param {string|URL} destination The destination of the file to move.\n\t * @returns {Promise<void>} A promise that resolves when the move is complete.\n\t * @throws {TypeError} If the file or directory paths are not strings.\n\t * @throws {Error} If the file or directory cannot be moved.\n\t */\n\tasync move(source, destination) {\n\t\tassertValidFileOrDirPath(source);\n\t\tassertValidFileOrDirPath(destination);\n\t\treturn this.#callImplMethod(\"move\", source, destination);\n\t}\n\n\t/**\n\t * Moves a file or directory from one location to another.\n\t * @param {string|URL} source The path to the file or directory to move.\n\t * @param {string|URL} destination The path to move the file or directory to.\n\t * @returns {Promise<void>} A promise that resolves when the file or directory is\n\t * moved.\n\t * @throws {TypeError} If the source is not a string or URL.\n\t * @throws {TypeError} If the destination is not a string or URL.\n\t * @throws {Error} If the file or directory cannot be moved.\n\t */\n\tasync moveAll(source, destination) {\n\t\tassertValidFileOrDirPath(source);\n\t\tassertValidFileOrDirPath(destination);\n\t\treturn this.#callImplMethod(\"moveAll\", source, destination);\n\t}\n}\n","/**\n * @fileoverview Common error classes\n * @author Nicholas C. Zakas\n */\n\n/**\n * Error thrown when a file or directory is not found.\n */\nexport class NotFoundError extends Error {\n\t/**\n\t * Name of the error class.\n\t * @type {string}\n\t */\n\tname = \"NotFoundError\";\n\n\t/**\n\t * Error code.\n\t * @type {string}\n\t */\n\tcode = \"ENOENT\";\n\n\t/**\n\t * Creates a new instance.\n\t * @param {string} message The error message.\n\t */\n\tconstructor(message) {\n\t\tsuper(`ENOENT: No such file or directory, ${message}`);\n\t}\n}\n\n/**\n * Error thrown when an operation is not permitted.\n */\nexport class PermissionError extends Error {\n\t/**\n\t * Name of the error class.\n\t * @type {string}\n\t */\n\tname = \"PermissionError\";\n\n\t/**\n\t * Error code.\n\t * @type {string}\n\t */\n\tcode = \"EPERM\";\n\n\t/**\n\t * Creates a new instance.\n\t * @param {string} message The error message.\n\t */\n\tconstructor(message) {\n\t\tsuper(`EPERM: Operation not permitted, ${message}`);\n\t}\n}\n\n/**\n * Error thrown when an operation is not allowed on a directory.\n */\n\nexport class DirectoryError extends Error {\n\t/**\n\t * Name of the error class.\n\t * @type {string}\n\t */\n\tname = \"DirectoryError\";\n\n\t/**\n\t * Error code.\n\t * @type {string}\n\t */\n\tcode = \"EISDIR\";\n\n\t/**\n\t * Creates a new instance.\n\t * @param {string} message The error message.\n\t */\n\tconstructor(message) {\n\t\tsuper(`EISDIR: Illegal operation on a directory, ${message}`);\n\t}\n}\n\n/**\n * Error thrown when a directory is not empty.\n */\nexport class NotEmptyError extends Error {\n\t/**\n\t * Name of the error class.\n\t * @type {string}\n\t */\n\tname = \"NotEmptyError\";\n\n\t/**\n\t * Error code.\n\t * @type {string}\n\t */\n\tcode = \"ENOTEMPTY\";\n\n\t/**\n\t * Creates a new instance.\n\t * @param {string} message The error message.\n\t */\n\tconstructor(message) {\n\t\tsuper(`ENOTEMPTY: Directory not empty, ${message}`);\n\t}\n}\n","/**\n * @fileoverview API entrypoint for hfs/core\n * @author Nicholas C. Zakas\n */\n\nexport { Hfs } from \"./hfs.js\";\nexport { Path } from \"./path.js\";\nexport * from \"./errors.js\";\n","// @ts-self-types=\"./retrier.d.ts\"\n/**\n * @fileoverview A utility for retrying failed async method calls.\n */\n\n/* global setTimeout, clearTimeout */\n\n//-----------------------------------------------------------------------------\n// Constants\n//-----------------------------------------------------------------------------\n\nconst MAX_TASK_TIMEOUT = 60000;\nconst MAX_TASK_DELAY = 100;\n\n//-----------------------------------------------------------------------------\n// Helpers\n//-----------------------------------------------------------------------------\n\n/*\n * The following logic has been extracted from graceful-fs.\n *\n * The ISC License\n *\n * Copyright (c) 2011-2023 Isaac Z. Schlueter, Ben Noordhuis, and Contributors\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\n * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\n * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR\n * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Checks if it is time to retry a task based on the timestamp and last attempt time.\n * @param {RetryTask} task The task to check.\n * @param {number} maxDelay The maximum delay for the queue.\n * @returns {boolean} true if it is time to retry, false otherwise.\n */\nfunction isTimeToRetry(task, maxDelay) {\n const timeSinceLastAttempt = Date.now() - task.lastAttempt;\n const timeSinceStart = Math.max(task.lastAttempt - task.timestamp, 1);\n const desiredDelay = Math.min(timeSinceStart * 1.2, maxDelay);\n\n return timeSinceLastAttempt >= desiredDelay;\n}\n\n/**\n * Checks if it is time to bail out based on the given timestamp.\n * @param {RetryTask} task The task to check.\n * @param {number} timeout The timeout for the queue.\n * @returns {boolean} true if it is time to bail, false otherwise.\n */\nfunction isTimeToBail(task, timeout) {\n return task.age > timeout;\n}\n\n\n/**\n * A class to represent a task in the retry queue.\n */\nclass RetryTask {\n\n /**\n * The unique ID for the task.\n * @type {string}\n */\n id = Math.random().toString(36).slice(2);\n\n /**\n * The function to call.\n * @type {Function}\n */\n fn;\n\n /**\n * The error that was thrown.\n * @type {Error}\n */\n error;\n \n /**\n * The timestamp of the task.\n * @type {number}\n */\n timestamp = Date.now();\n\n /**\n * The timestamp of the last attempt.\n * @type {number}\n */\n lastAttempt = this.timestamp;\n\n /**\n * The resolve function for the promise.\n * @type {Function}\n */\n resolve;\n\n /**\n * The reject function for the promise.\n * @type {Function}\n */\n reject;\n\n /**\n * The AbortSignal to monitor for cancellation.\n * @type {AbortSignal|undefined}\n */\n signal;\n\n /**\n * Creates a new instance.\n * @param {Function} fn The function to call.\n * @param {Error} error The error that was thrown.\n * @param {Function} resolve The resolve function for the promise.\n * @param {Function} reject The reject function for the promise.\n * @param {AbortSignal|undefined} signal The AbortSignal to monitor for cancellation.\n */\n constructor(fn, error, resolve, reject, signal) {\n this.fn = fn;\n this.error = error;\n this.timestamp = Date.now();\n this.lastAttempt = Date.now();\n this.resolve = resolve;\n this.reject = reject;\n this.signal = signal;\n }\n \n /**\n * Gets the age of the task.\n * @returns {number} The age of the task in milliseconds.\n * @readonly\n */\n get age() {\n return Date.now() - this.timestamp;\n }\n}\n\n//-----------------------------------------------------------------------------\n// Exports\n//-----------------------------------------------------------------------------\n\n/**\n * A class that manages a queue of retry jobs.\n */\nclass Retrier {\n\n /**\n * Represents the queue for processing tasks.\n * @type {Array<RetryTask>}\n */\n #queue = [];\n\n /**\n * The timeout for the queue.\n * @type {number}\n */\n #timeout;\n\n /**\n * The maximum delay for the queue.\n * @type {number}\n */\n #maxDelay;\n\n /**\n * The setTimeout() timer ID.\n * @type {NodeJS.Timeout|undefined}\n */\n #timerId;\n\n /**\n * The function to call.\n * @type {Function}\n */\n #check;\n\n /**\n * Creates a new instance.\n * @param {Function} check The function to call.\n * @param {object} [options] The options for the instance.\n * @param {number} [options.timeout] The timeout for the queue.\n * @param {number} [options.maxDelay] The maximum delay for the queue.\n */\n constructor(check, { timeout = MAX_TASK_TIMEOUT, maxDelay = MAX_TASK_DELAY } = {}) {\n\n if (typeof check !== \"function\") {\n throw new Error(\"Missing function to check errors\");\n }\n\n this.#check = check;\n this.#timeout = timeout;\n this.#maxDelay = maxDelay;\n }\n\n /**\n * Adds a new retry job to the queue.\n * @param {Function} fn The function to call.\n * @param {object} [options] The options for the job.\n * @param {AbortSignal} [options.signal] The AbortSignal to monitor for cancellation.\n * @returns {Promise<any>} A promise that resolves when the queue is\n * processed.\n */\n retry(fn, { signal } = {}) {\n\n signal?.throwIfAborted();\n\n let result;\n\n try {\n result = fn();\n } catch (/** @type {any} */ error) {\n return Promise.reject(new Error(`Synchronous error: ${error.message}`, { cause: error }));\n }\n\n // if the result is not a promise then reject an error\n if (!result || typeof result.then !== \"function\") {\n return Promise.reject(new Error(\"Result is not a promise.\"));\n }\n\n // call the original function and catch any ENFILE or EMFILE errors\n // @ts-ignore because we know it's any\n return Promise.resolve(result).catch(error => {\n if (!this.#check(error)) {\n throw error;\n }\n\n return new Promise((resolve, reject) => {\n this.#queue.push(new RetryTask(fn, error, resolve, reject, signal));\n\n signal?.addEventListener(\"abort\", () => {\n reject(signal.reason);\n });\n\n this.#processQueue();\n });\n });\n }\n\n /**\n * Processes the queue.\n * @returns {void}\n */\n #processQueue() {\n // clear any timer because we're going to check right now\n clearTimeout(this.#timerId);\n this.#timerId = undefined;\n\n // if there's nothing in the queue, we're done\n const task = this.#queue.shift();\n if (!task) {\n return;\n }\n const processAgain = () => {\n this.#timerId = setTimeout(() => this.#processQueue(), 0);\n };\n\n // if it's time to bail, then bail\n if (isTimeToBail(task, this.#timeout)) {\n task.reject(task.error);\n processAgain();\n return;\n }\n\n // if it's not time to retry, then wait and try again\n if (!isTimeToRetry(task, this.#maxDelay)) {\n this.#queue.push(task);\n processAgain();\n return;\n }\n\n // otherwise, try again\n task.lastAttempt = Date.now();\n \n // Promise.resolve needed in case it's a thenable but not a Promise\n Promise.resolve(task.fn())\n // @ts-ignore because we know it's any\n .then(result => task.resolve(result))\n\n // @ts-ignore because we know it's any\n .catch(error => {\n if (!this.#check(error)) {\n task.reject(error);\n return;\n }\n\n // update the task timestamp and push to back of queue to try again\n task.lastAttempt = Date.now();\n this.#queue.push(task);\n\n })\n .finally(() => this.#processQueue());\n }\n}\n\nexport { Retrier };\n","/**\n * @fileoverview The main file for the hfs package.\n * @author Nicholas C. Zakas\n */\n/* global Buffer:readonly, URL */\n\n//-----------------------------------------------------------------------------\n// Types\n//-----------------------------------------------------------------------------\n\n/** @typedef {import(\"@humanfs/types\").HfsImpl} HfsImpl */\n/** @typedef {import(\"@humanfs/types\").HfsDirectoryEntry} HfsDirectoryEntry */\n/** @typedef {import(\"node:fs/promises\")} Fsp */\n/** @typedef {import(\"fs\").Dirent} Dirent */\n\n//-----------------------------------------------------------------------------\n// Imports\n//-----------------------------------------------------------------------------\n\nimport { Hfs } from \"@humanfs/core\";\nimport path from \"node:path\";\nimport { Retrier } from \"@humanwhocodes/retry\";\nimport nativeFsp from \"node:fs/promises\";\nimport { fileURLToPath } from \"node:url\";\n\n//-----------------------------------------------------------------------------\n// Constants\n//-----------------------------------------------------------------------------\n\nconst RETRY_ERROR_CODES = new Set([\"ENFILE\", \"EMFILE\"]);\n\n//-----------------------------------------------------------------------------\n// Helpers\n//-----------------------------------------------------------------------------\n\n/**\n * A class representing a directory entry.\n * @implements {HfsDirectoryEntry}\n */\nclass NodeHfsDirectoryEntry {\n\t/**\n\t * The name of the directory entry.\n\t * @type {string}\n\t */\n\tname;\n\n\t/**\n\t * True if the entry is a file.\n\t * @type {boolean}\n\t */\n\tisFile;\n\n\t/**\n\t * True if the entry is a directory.\n\t * @type {boolean}\n\t */\n\tisDirectory;\n\n\t/**\n\t * True if the entry is a symbolic link.\n\t * @type {boolean}\n\t */\n\tisSymlink;\n\n\t/**\n\t * Creates a new instance.\n\t * @param {Dirent} dirent The directory entry to wrap.\n\t */\n\tconstructor(dirent) {\n\t\tthis.name = dirent.name;\n\t\tthis.isFile = dirent.isFile();\n\t\tthis.isDirectory = dirent.isDirectory();\n\t\tthis.isSymlink = dirent.isSymbolicLink();\n\t}\n}\n\n//-----------------------------------------------------------------------------\n// Exports\n//-----------------------------------------------------------------------------\n\n/**\n * A class representing the Node.js implementation of Hfs.\n * @implements {HfsImpl}\n */\nexport class NodeHfsImpl {\n\t/**\n\t * The file system module to use.\n\t * @type {Fsp}\n\t */\n\t#fsp;\n\n\t/**\n\t * The retryer object used for retrying operations.\n\t * @type {Retrier}\n\t */\n\t#retrier;\n\n\t/**\n\t * Creates a new instance.\n\t * @param {object} [options] The options for the instance.\n\t * @param {Fsp} [options.fsp] The file system module to use.\n\t */\n\tconstructor({ fsp = nativeFsp } = {}) {\n\t\tthis.#fsp = fsp;\n\t\tthis.#retrier = new Retrier(error => RETRY_ERROR_CODES.has(error.code));\n\t}\n\n\t/**\n\t * Reads a file and returns the contents as an Uint8Array.\n\t * @param {string|URL} filePath The path to the file to read.\n\t * @returns {Promise<Uint8Array|undefined>} A promise that resolves with the contents\n\t * of the file or undefined if the file doesn't exist.\n\t * @throws {Error} If the file cannot be read.\n\t * @throws {TypeError} If the file path is not a string.\n\t */\n\tbytes(filePath) {\n\t\treturn this.#retrier\n\t\t\t.retry(() => this.#fsp.readFile(filePath))\n\t\t\t.then(buffer => new Uint8Array(buffer.buffer))\n\t\t\t.catch(error => {\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Writes a value to a file. If the value is a string, UTF-8 encoding is used.\n\t * @param {string|URL} filePath The path to the file to write.\n\t * @param {Uint8Array} contents The contents to write to the\n\t * file.\n\t * @returns {Promise<void>} A promise that resolves when the file is\n\t * written.\n\t * @throws {TypeError} If the file path is not a string.\n\t * @throws {Error} If the file cannot be written.\n\t */\n\tasync write(filePath, contents) {\n\t\tconst value = Buffer.from(contents);\n\n\t\treturn this.#retrier\n\t\t\t.retry(() => this.#fsp.writeFile(filePath, value))\n\t\t\t.catch(error => {\n\t\t\t\t// the directory may not exist, so create it\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\tconst dirPath = path.dirname(\n\t\t\t\t\t\tfilePath instanceof URL\n\t\t\t\t\t\t\t? fileURLToPath(filePath)\n\t\t\t\t\t\t\t: filePath,\n\t\t\t\t\t);\n\n\t\t\t\t\treturn this.#fsp\n\t\t\t\t\t\t.mkdir(dirPath, { recursive: true })\n\t\t\t\t\t\t.then(() => this.#fsp.writeFile(filePath, value));\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Appends a value to a file. If the value is a string, UTF-8 encoding is used.\n\t * @param {string|URL} filePath The path to the file to append to.\n\t * @param {Uint8Array} contents The contents to append to the\n\t * file.\n\t * @returns {Promise<void>} A promise that resolves when the file is\n\t * written.\n\t * @throws {TypeError} If the file path is not a string.\n\t * @throws {Error} If the file cannot be appended to.\n\t */\n\tasync append(filePath, contents) {\n\t\tconst value = Buffer.from(contents);\n\n\t\treturn this.#retrier\n\t\t\t.retry(() => this.#fsp.appendFile(filePath, value))\n\t\t\t.catch(error => {\n\t\t\t\t// the directory may not exist, so create it\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\tconst dirPath = path.dirname(\n\t\t\t\t\t\tfilePath instanceof URL\n\t\t\t\t\t\t\t? fileURLToPath(filePath)\n\t\t\t\t\t\t\t: filePath,\n\t\t\t\t\t);\n\n\t\t\t\t\treturn this.#fsp\n\t\t\t\t\t\t.mkdir(dirPath, { recursive: true })\n\t\t\t\t\t\t.then(() => this.#fsp.appendFile(filePath, value));\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Checks if a file exists.\n\t * @param {string|URL} filePath The path to the file to check.\n\t * @returns {Promise<boolean>} A promise that resolves with true if the\n\t * file exists or false if it does not.\n\t * @throws {Error} If the operation fails with a code other than ENOENT.\n\t */\n\tisFile(filePath) {\n\t\treturn this.#fsp\n\t\t\t.stat(filePath)\n\t\t\t.then(stat => stat.isFile())\n\t\t\t.catch(error => {\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Checks if a directory exists.\n\t * @param {string|URL} dirPath The path to the directory to check.\n\t * @returns {Promise<boolean>} A promise that resolves with true if the\n\t * directory exists or false if it does not.\n\t * @throws {Error} If the operation fails with a code other than ENOENT.\n\t */\n\tisDirectory(dirPath) {\n\t\treturn this.#fsp\n\t\t\t.stat(dirPath)\n\t\t\t.then(stat => stat.isDirectory())\n\t\t\t.catch(error => {\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Creates a directory recursively.\n\t * @param {string|URL} dirPath The path to the directory to create.\n\t * @returns {Promise<void>} A promise that resolves when the directory is\n\t * created.\n\t */\n\tasync createDirectory(dirPath) {\n\t\tawait this.#fsp.mkdir(dirPath, { recursive: true });\n\t}\n\n\t/**\n\t * Deletes a file or empty directory.\n\t * @param {string|URL} fileOrDirPath The path to the file or directory to\n\t * delete.\n\t * @returns {Promise<boolean>} A promise that resolves when the file or\n\t * directory is deleted, true if the file or directory is deleted, false\n\t * if the file or directory does not exist.\n\t * @throws {TypeError} If the file or directory path is not a string.\n\t * @throws {Error} If the file or directory cannot be deleted.\n\t */\n\tdelete(fileOrDirPath) {\n\t\treturn this.#fsp\n\t\t\t.rm(fileOrDirPath)\n\t\t\t.then(() => true)\n\t\t\t.catch(error => {\n\t\t\t\tif (error.code === \"ERR_FS_EISDIR\") {\n\t\t\t\t\treturn this.#fsp.rmdir(fileOrDirPath).then(() => true);\n\t\t\t\t}\n\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Deletes a file or directory recursively.\n\t * @param {string|URL} fileOrDirPath The path to the file or directory to\n\t * delete.\n\t * @returns {Promise<boolean>} A promise that resolves when the file or\n\t * directory is deleted, true if the file or directory is deleted, false\n\t * if the file or directory does not exist.\n\t * @throws {TypeError} If the file or directory path is not a string.\n\t * @throws {Error} If the file or directory cannot be deleted.\n\t */\n\tdeleteAll(fileOrDirPath) {\n\t\treturn this.#fsp\n\t\t\t.rm(fileOrDirPath, { recursive: true })\n\t\t\t.then(() => true)\n\t\t\t.catch(error => {\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Returns a list of directory entries for the given path.\n\t * @param {string|URL} dirPath The path to the directory to read.\n\t * @returns {AsyncIterable<HfsDirectoryEntry>} A promise that resolves with the\n\t * directory entries.\n\t * @throws {TypeError} If the directory path is not a string.\n\t * @throws {Error} If the directory cannot be read.\n\t */\n\tasync *list(dirPath) {\n\t\tconst entries = await this.#fsp.readdir(dirPath, {\n\t\t\twithFileTypes: true,\n\t\t});\n\n\t\tfor (const entry of entries) {\n\t\t\tyield new NodeHfsDirectoryEntry(entry);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the size of a file. This method handles ENOENT errors\n\t * and returns undefined in that case.\n\t * @param {string|URL} filePath The path to the file to read.\n\t * @returns {Promise<number|undefined>} A promise that resolves with the size of the\n\t * file in bytes or undefined if the file doesn't exist.\n\t */\n\tsize(filePath) {\n\t\treturn this.#fsp\n\t\t\t.stat(filePath)\n\t\t\t.then(stat => stat.size)\n\t\t\t.catch(error => {\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Returns the last modified date of a file or directory. This method handles ENOENT errors\n\t * and returns undefined in that case.\n\t * @param {string|URL} fileOrDirPath The path to the file to read.\n\t * @returns {Promise<Date|undefined>} A promise that resolves with the last modified\n\t * date of the file or directory, or undefined if the file doesn't exist.\n\t */\n\tlastModified(fileOrDirPath) {\n\t\treturn this.#fsp\n\t\t\t.stat(fileOrDirPath)\n\t\t\t.then(stat => stat.mtime)\n\t\t\t.catch(error => {\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\t/**\n\t * Copies a file from one location to another.\n\t * @param {string|URL} source The path to the file to copy.\n\t * @param {string|URL} destination The path to copy the file to.\n\t * @returns {Promise<void>} A promise that resolves when the file is copied.\n\t * @throws {Error} If the source file does not exist.\n\t * @throws {Error} If the source file is a directory.\n\t * @throws {Error} If the destination file is a directory.\n\t */\n\tcopy(source, destination) {\n\t\treturn this.#fsp.copyFile(source, destination);\n\t}\n\n\t/**\n\t * Copies a file or directory from one location to another.\n\t * @param {string|URL} source The path to the file or directory to copy.\n\t * @param {string|URL} destination The path to copy the file or directory to.\n\t * @returns {Promise<void>} A promise that resolves when the file or directory is\n\t * copied.\n\t * @throws {Error} If the source file or directory does not exist.\n\t * @throws {Error} If the destination file or directory is a directory.\n\t */\n\tasync copyAll(source, destination) {\n\t\t// for files use copy() and exit\n\t\tif (await this.isFile(source)) {\n\t\t\treturn this.copy(source, destination);\n\t\t}\n\n\t\tconst sourceStr =\n\t\t\tsource instanceof URL ? fileURLToPath(source) : source;\n\n\t\tconst destinationStr =\n\t\t\tdestination instanceof URL\n\t\t\t\t? fileURLToPath(destination)\n\t\t\t\t: destination;\n\n\t\t// for directories, create the destination directory and copy each entry\n\t\tawait this.createDirectory(destination);\n\n\t\tfor await (const entry of this.list(source)) {\n\t\t\tconst fromEntryPath = path.join(sourceStr, entry.name);\n\t\t\tconst toEntryPath = path.join(destinationStr, entry.name);\n\n\t\t\tif (entry.isDirectory) {\n\t\t\t\tawait this.copyAll(fromEntryPath, toEntryPath);\n\t\t\t} else {\n\t\t\t\tawait this.copy(fromEntryPath, toEntryPath);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Moves a file from the source path to the destination path.\n\t * @param {string|URL} source The location of the file to move.\n\t * @param {string|URL} destination The destination of the file to move.\n\t * @returns {Promise<void>} A promise that resolves when the move is complete.\n\t * @throws {TypeError} If the file paths are not strings.\n\t * @throws {Error} If the file cannot be moved.\n\t */\n\tmove(source, destination) {\n\t\treturn this.#fsp.stat(source).then(stat => {\n\t\t\tif (stat.isDirectory()) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`EISDIR: illegal operation on a directory, move '${source}' -> '${destination}'`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn this.#fsp.rename(source, destination);\n\t\t});\n\t}\n\n\t/**\n\t * Moves a file or directory from the source path to the destination path.\n\t * @param {string|URL} source The location of the file or directory to move.\n\t * @param {string|URL} destination The destination of the file or directory to move.\n\t * @returns {Promise<void>} A promise that resolves when the move is complete.\n\t * @throws {TypeError} If the file paths are not strings.\n\t * @throws {Error} If the file or directory cannot be moved.\n\t */\n\tasync moveAll(source, destination) {\n\t\treturn this.#fsp.rename(source, destination);\n\t}\n}\n\n/**\n * A class representing a file system utility library.\n * @implements {HfsImpl}\n */\nexport class NodeHfs extends Hfs {\n\t/**\n\t * Creates a new instance.\n\t * @param {object} [options] The options for the instance.\n\t * @param {Fsp} [options.fsp] The file system module to use.\n\t */\n\tconstructor({ fsp } = {}) {\n\t\tsuper({ impl: new NodeHfsImpl({ fsp }) });\n\t}\n}\n\nexport const hfs = new NodeHfs();\n","/**\n * @fileoverview This file exports everything for this package.\n * @author Nicholas C. Zakas\n */\n\nexport * from \"./node-hfs.js\";\nexport { Hfs } from \"@humanfs/core\";\n"],"x_google_ignoreList":[0,1,2,3,4,5],"mappings":";;;;;;;;;;;;AAoEA,SAAS,yBAAyB,eAAe;AAChD,KACC,CAAC,iBACA,EAAE,yBAAyB,QAAQ,OAAO,kBAAkB,SAE7D,OAAM,IAAI,UAAU,0CAA0C;;;;;;;;AAUhE,SAAS,wBAAwB,UAAU;AAC1C,KACC,OAAO,aAAa,YACpB,EAAE,oBAAoB,gBACtB,CAAC,YAAY,OAAO,SAAS,CAE7B,OAAM,IAAI,UACT,oEACA;;;;;;;;AAUH,SAAS,aAAa,UAAU;AAC/B,KAAI,oBAAoB,WACvB,QAAO;AAGR,KAAI,OAAO,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MAAM,YACL,kBAAkB,MAAM,cAAc,OAAO,GAAG;GAEjD,MAAM,iBACL,uBAAuB,MACpB,cAAc,YAAY,GAC1B;AAGJ,SAAM,KAAK,gBAAgB,YAAY;AAEvC,cAAW,MAAM,SAAS,KAAK,KAAK,OAAO,EAAE;IAC5C,MAAM,gBAAgB,KAAK,KAAK,WAAW,MAAM,KAAK;IACtD,MAAM,cAAc,KAAK,KAAK,gBAAgB,MAAM,KAAK;AAEzD,QAAI,MAAM,YACT,OAAM,KAAK,QAAQ,eAAe,YAAY;QAE9C,OAAM,KAAK,KAAK,eAAe,YAAY;;;;;;;;;;;EAa9C,KAAK,QAAQ,aAAa;AACzB,UAAO,MAAKA,IAAK,KAAK,OAAO,CAAC,MAAK,SAAQ;AAC1C,QAAI,KAAK,aAAa,CACrB,OAAM,IAAI,MACT,mDAAmD,OAAO,QAAQ,YAAY,GAC9E;AAGF,WAAO,MAAKA,IAAK,OAAO,QAAQ,YAAY;KAC3C;;;;;;;;;;EAWH,MAAM,QAAQ,QAAQ,aAAa;AAClC,UAAO,MAAKA,IAAK,OAAO,QAAQ,YAAY;;;CAQjC,UAAb,cAA6B,IAAI;;;;;;EAMhC,YAAY,EAAE,QAAQ,EAAE,EAAE;AACzB,SAAM,EAAE,MAAM,IAAI,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC;;;CAI9B,MAAM,IAAI,SAAS;;;;;;;aC7bI"}
@@ -0,0 +1,3 @@
1
+ import { n as shutdownTelemetry, r as withSpan, t as initTelemetry } from "./telemetry-rFq0QdvJ.mjs";
2
+
3
+ export { initTelemetry, shutdownTelemetry };
@@ -0,0 +1,84 @@
1
+ import { SpanStatusCode, trace } from "@opentelemetry/api";
2
+
3
+ //#region src/cli/telemetry/config.ts
4
+ /**
5
+ * Parse telemetry configuration from standard OpenTelemetry environment variables.
6
+ * Tracing is enabled when OTEL_EXPORTER_OTLP_ENDPOINT is set.
7
+ * @returns Telemetry configuration
8
+ */
9
+ function parseTelemetryConfig() {
10
+ const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? "";
11
+ return {
12
+ enabled: endpoint.length > 0,
13
+ endpoint
14
+ };
15
+ }
16
+
17
+ //#endregion
18
+ //#region src/cli/telemetry/index.ts
19
+ let _config;
20
+ let _initialized = false;
21
+ let _provider;
22
+ /**
23
+ * Initialize telemetry if OTEL_EXPORTER_OTLP_ENDPOINT is set.
24
+ * When disabled, this is a no-op with zero overhead beyond reading env vars.
25
+ * @returns Promise that resolves when initialization completes
26
+ */
27
+ async function initTelemetry() {
28
+ if (_initialized) return;
29
+ _initialized = true;
30
+ _config = parseTelemetryConfig();
31
+ if (!_config.enabled) return;
32
+ const [{ NodeTracerProvider, BatchSpanProcessor }, { OTLPTraceExporter }, { resourceFromAttributes }, { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION }, { readPackageJson }] = await Promise.all([
33
+ import("@opentelemetry/sdk-trace-node"),
34
+ import("@opentelemetry/exporter-trace-otlp-proto"),
35
+ import("@opentelemetry/resources"),
36
+ import("@opentelemetry/semantic-conventions"),
37
+ import("./package-json-Dd1AnA5F.mjs")
38
+ ]);
39
+ const version = (await readPackageJson()).version ?? "unknown";
40
+ _provider = new NodeTracerProvider({
41
+ resource: resourceFromAttributes({
42
+ [ATTR_SERVICE_NAME]: "tailor-sdk",
43
+ [ATTR_SERVICE_VERSION]: version
44
+ }),
45
+ spanProcessors: [new BatchSpanProcessor(new OTLPTraceExporter({ url: `${_config.endpoint}/v1/traces` }))]
46
+ });
47
+ _provider.register();
48
+ }
49
+ /**
50
+ * Shutdown the telemetry provider, flushing all pending spans.
51
+ * Must be called before process exit to ensure traces are exported.
52
+ * @returns Promise that resolves when shutdown completes
53
+ */
54
+ async function shutdownTelemetry() {
55
+ if (!_provider) return;
56
+ await _provider.shutdown();
57
+ }
58
+ /**
59
+ * Execute a function within a new span. Records exceptions and sets span status.
60
+ * When no TracerProvider is registered, the OTel API automatically provides
61
+ * noop spans with zero overhead.
62
+ * @param name - Span name
63
+ * @param fn - Function to execute within the span
64
+ * @returns Result of fn
65
+ */
66
+ async function withSpan(name, fn) {
67
+ return trace.getTracer("tailor-sdk").startActiveSpan(name, async (span) => {
68
+ try {
69
+ const result = await fn(span);
70
+ span.setStatus({ code: SpanStatusCode.OK });
71
+ return result;
72
+ } catch (error) {
73
+ span.setStatus({ code: SpanStatusCode.ERROR });
74
+ if (error instanceof Error) span.recordException(error);
75
+ throw error;
76
+ } finally {
77
+ span.end();
78
+ }
79
+ });
80
+ }
81
+
82
+ //#endregion
83
+ export { shutdownTelemetry as n, withSpan as r, initTelemetry as t };
84
+ //# sourceMappingURL=telemetry-rFq0QdvJ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry-rFq0QdvJ.mjs","names":[],"sources":["../src/cli/telemetry/config.ts","../src/cli/telemetry/index.ts"],"sourcesContent":["/**\n * Telemetry configuration parsed from standard OpenTelemetry environment variables.\n * Tracing is enabled when OTEL_EXPORTER_OTLP_ENDPOINT is set.\n */\nexport interface TelemetryConfig {\n readonly enabled: boolean;\n readonly endpoint: string;\n}\n\n/**\n * Parse telemetry configuration from standard OpenTelemetry environment variables.\n * Tracing is enabled when OTEL_EXPORTER_OTLP_ENDPOINT is set.\n * @returns Telemetry configuration\n */\nexport function parseTelemetryConfig(): TelemetryConfig {\n const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? \"\";\n const enabled = endpoint.length > 0;\n\n return {\n enabled,\n endpoint,\n };\n}\n","import { trace, SpanStatusCode, type Span } from \"@opentelemetry/api\";\nimport { parseTelemetryConfig, type TelemetryConfig } from \"./config\";\n\nlet _config: TelemetryConfig | undefined;\nlet _initialized = false;\nlet _provider: { register: () => void; shutdown: () => Promise<void> } | undefined;\n\n/**\n * Check whether telemetry is currently enabled.\n * @returns true if telemetry has been initialized and is enabled\n */\nexport function isTelemetryEnabled(): boolean {\n return _config?.enabled ?? false;\n}\n\n/**\n * Initialize telemetry if OTEL_EXPORTER_OTLP_ENDPOINT is set.\n * When disabled, this is a no-op with zero overhead beyond reading env vars.\n * @returns Promise that resolves when initialization completes\n */\nexport async function initTelemetry(): Promise<void> {\n if (_initialized) return;\n _initialized = true;\n\n _config = parseTelemetryConfig();\n if (!_config.enabled) return;\n\n // Dynamic imports - only loaded when tracing is enabled\n const [\n { NodeTracerProvider, BatchSpanProcessor },\n { OTLPTraceExporter },\n { resourceFromAttributes },\n { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION },\n { readPackageJson },\n ] = await Promise.all([\n import(\"@opentelemetry/sdk-trace-node\"),\n import(\"@opentelemetry/exporter-trace-otlp-proto\"),\n import(\"@opentelemetry/resources\"),\n import(\"@opentelemetry/semantic-conventions\"),\n import(\"../utils/package-json\"),\n ]);\n\n const packageJson = await readPackageJson();\n const version = packageJson.version ?? \"unknown\";\n\n const resource = resourceFromAttributes({\n [ATTR_SERVICE_NAME]: \"tailor-sdk\",\n [ATTR_SERVICE_VERSION]: version,\n });\n\n const exporter = new OTLPTraceExporter({\n url: `${_config.endpoint}/v1/traces`,\n });\n\n _provider = new NodeTracerProvider({\n resource,\n spanProcessors: [new BatchSpanProcessor(exporter)],\n });\n\n _provider.register();\n}\n\n/**\n * Shutdown the telemetry provider, flushing all pending spans.\n * Must be called before process exit to ensure traces are exported.\n * @returns Promise that resolves when shutdown completes\n */\nexport async function shutdownTelemetry(): Promise<void> {\n if (!_provider) return;\n await _provider.shutdown();\n}\n\n/**\n * Execute a function within a new span. Records exceptions and sets span status.\n * When no TracerProvider is registered, the OTel API automatically provides\n * noop spans with zero overhead.\n * @param name - Span name\n * @param fn - Function to execute within the span\n * @returns Result of fn\n */\nexport async function withSpan<T>(name: string, fn: (span: Span) => Promise<T>): Promise<T> {\n const tracer = trace.getTracer(\"tailor-sdk\");\n\n return tracer.startActiveSpan(name, async (span) => {\n try {\n const result = await fn(span);\n span.setStatus({ code: SpanStatusCode.OK });\n return result;\n } catch (error) {\n span.setStatus({ code: SpanStatusCode.ERROR });\n if (error instanceof Error) {\n span.recordException(error);\n }\n throw error;\n } finally {\n span.end();\n }\n });\n}\n"],"mappings":";;;;;;;;AAcA,SAAgB,uBAAwC;CACtD,MAAM,WAAW,QAAQ,IAAI,+BAA+B;AAG5D,QAAO;EACL,SAHc,SAAS,SAAS;EAIhC;EACD;;;;;AClBH,IAAI;AACJ,IAAI,eAAe;AACnB,IAAI;;;;;;AAeJ,eAAsB,gBAA+B;AACnD,KAAI,aAAc;AAClB,gBAAe;AAEf,WAAU,sBAAsB;AAChC,KAAI,CAAC,QAAQ,QAAS;CAGtB,MAAM,CACJ,EAAE,oBAAoB,sBACtB,EAAE,qBACF,EAAE,0BACF,EAAE,mBAAmB,wBACrB,EAAE,qBACA,MAAM,QAAQ,IAAI;EACpB,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO;EACR,CAAC;CAGF,MAAM,WADc,MAAM,iBAAiB,EACf,WAAW;AAWvC,aAAY,IAAI,mBAAmB;EACjC,UAVe,uBAAuB;IACrC,oBAAoB;IACpB,uBAAuB;GACzB,CAAC;EAQA,gBAAgB,CAAC,IAAI,mBANN,IAAI,kBAAkB,EACrC,KAAK,GAAG,QAAQ,SAAS,aAC1B,CAAC,CAIiD,CAAC;EACnD,CAAC;AAEF,WAAU,UAAU;;;;;;;AAQtB,eAAsB,oBAAmC;AACvD,KAAI,CAAC,UAAW;AAChB,OAAM,UAAU,UAAU;;;;;;;;;;AAW5B,eAAsB,SAAY,MAAc,IAA4C;AAG1F,QAFe,MAAM,UAAU,aAAa,CAE9B,gBAAgB,MAAM,OAAO,SAAS;AAClD,MAAI;GACF,MAAM,SAAS,MAAM,GAAG,KAAK;AAC7B,QAAK,UAAU,EAAE,MAAM,eAAe,IAAI,CAAC;AAC3C,UAAO;WACA,OAAO;AACd,QAAK,UAAU,EAAE,MAAM,eAAe,OAAO,CAAC;AAC9C,OAAI,iBAAiB,MACnB,MAAK,gBAAgB,MAAM;AAE7B,SAAM;YACE;AACR,QAAK,KA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