@catbee/utils 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -4
- package/build/esm/config.d.ts +1 -5
- package/build/esm/config.js +6 -10
- package/build/esm/config.js.map +1 -1
- package/build/esm/index.d.ts +20 -19
- package/build/esm/index.js +20 -19
- package/build/esm/index.js.map +1 -1
- package/build/esm/types/api-response.d.ts +2 -2
- package/build/esm/types/api-response.js.map +1 -1
- package/build/esm/utils/array.utils.d.ts +1 -1
- package/build/esm/utils/array.utils.js +17 -27
- package/build/esm/utils/array.utils.js.map +1 -1
- package/build/esm/utils/async.utils.d.ts +1 -5
- package/build/esm/utils/async.utils.js +17 -20
- package/build/esm/utils/async.utils.js.map +1 -1
- package/build/esm/utils/cache.utils.js +2 -2
- package/build/esm/utils/cache.utils.js.map +1 -1
- package/build/esm/utils/context-store.utils.d.ts +1 -1
- package/build/esm/utils/context-store.utils.js +8 -8
- package/build/esm/utils/context-store.utils.js.map +1 -1
- package/build/esm/utils/crypto.utils.d.ts +2 -2
- package/build/esm/utils/crypto.utils.js +37 -45
- package/build/esm/utils/crypto.utils.js.map +1 -1
- package/build/esm/utils/decorators.utils.d.ts +2 -18
- package/build/esm/utils/decorators.utils.js +31 -31
- package/build/esm/utils/decorators.utils.js.map +1 -1
- package/build/esm/utils/dir.utils.d.ts +4 -4
- package/build/esm/utils/dir.utils.js +18 -20
- package/build/esm/utils/dir.utils.js.map +1 -1
- package/build/esm/utils/env.utils.js +22 -26
- package/build/esm/utils/env.utils.js.map +1 -1
- package/build/esm/utils/exception.utils.d.ts +1 -1
- package/build/esm/utils/exception.utils.js +26 -29
- package/build/esm/utils/exception.utils.js.map +1 -1
- package/build/esm/utils/fs.utils.d.ts +3 -3
- package/build/esm/utils/fs.utils.js +19 -23
- package/build/esm/utils/fs.utils.js.map +1 -1
- package/build/esm/utils/http-status-codes.js.map +1 -1
- package/build/esm/utils/id.utils.js +8 -8
- package/build/esm/utils/id.utils.js.map +1 -1
- package/build/esm/utils/logger.utils.d.ts +13 -4
- package/build/esm/utils/logger.utils.js +16 -18
- package/build/esm/utils/logger.utils.js.map +1 -1
- package/build/esm/utils/middleware.utils.d.ts +15 -26
- package/build/esm/utils/middleware.utils.js +80 -59
- package/build/esm/utils/middleware.utils.js.map +1 -1
- package/build/esm/utils/obj.utils.js +16 -27
- package/build/esm/utils/obj.utils.js.map +1 -1
- package/build/esm/utils/response.utils.d.ts +2 -2
- package/build/esm/utils/response.utils.js +11 -11
- package/build/esm/utils/response.utils.js.map +1 -1
- package/build/esm/utils/string.utils.js +17 -17
- package/build/esm/utils/string.utils.js.map +1 -1
- package/build/esm/utils/url.utils.js +20 -22
- package/build/esm/utils/url.utils.js.map +1 -1
- package/build/esm/utils/validate.utils.js +11 -15
- package/build/esm/utils/validate.utils.js.map +1 -1
- package/build/esnext/config.d.ts +1 -5
- package/build/esnext/config.js +6 -10
- package/build/esnext/config.js.map +1 -1
- package/build/esnext/index.d.ts +20 -19
- package/build/esnext/index.js +20 -19
- package/build/esnext/index.js.map +1 -1
- package/build/esnext/types/api-response.d.ts +2 -2
- package/build/esnext/types/api-response.js.map +1 -1
- package/build/esnext/utils/array.utils.d.ts +1 -1
- package/build/esnext/utils/array.utils.js +23 -31
- package/build/esnext/utils/array.utils.js.map +1 -1
- package/build/esnext/utils/async.utils.d.ts +1 -5
- package/build/esnext/utils/async.utils.js +22 -22
- package/build/esnext/utils/async.utils.js.map +1 -1
- package/build/esnext/utils/cache.utils.js +3 -3
- package/build/esnext/utils/cache.utils.js.map +1 -1
- package/build/esnext/utils/context-store.utils.d.ts +1 -1
- package/build/esnext/utils/context-store.utils.js +10 -10
- package/build/esnext/utils/context-store.utils.js.map +1 -1
- package/build/esnext/utils/crypto.utils.d.ts +2 -2
- package/build/esnext/utils/crypto.utils.js +37 -47
- package/build/esnext/utils/crypto.utils.js.map +1 -1
- package/build/esnext/utils/decorators.utils.d.ts +2 -18
- package/build/esnext/utils/decorators.utils.js +33 -33
- package/build/esnext/utils/decorators.utils.js.map +1 -1
- package/build/esnext/utils/dir.utils.d.ts +4 -4
- package/build/esnext/utils/dir.utils.js +22 -24
- package/build/esnext/utils/dir.utils.js.map +1 -1
- package/build/esnext/utils/env.utils.js +24 -26
- package/build/esnext/utils/env.utils.js.map +1 -1
- package/build/esnext/utils/exception.utils.d.ts +1 -1
- package/build/esnext/utils/exception.utils.js +26 -29
- package/build/esnext/utils/exception.utils.js.map +1 -1
- package/build/esnext/utils/fs.utils.d.ts +3 -3
- package/build/esnext/utils/fs.utils.js +21 -25
- package/build/esnext/utils/fs.utils.js.map +1 -1
- package/build/esnext/utils/http-status-codes.js.map +1 -1
- package/build/esnext/utils/id.utils.js +8 -8
- package/build/esnext/utils/id.utils.js.map +1 -1
- package/build/esnext/utils/logger.utils.d.ts +13 -4
- package/build/esnext/utils/logger.utils.js +16 -18
- package/build/esnext/utils/logger.utils.js.map +1 -1
- package/build/esnext/utils/middleware.utils.d.ts +15 -26
- package/build/esnext/utils/middleware.utils.js +78 -59
- package/build/esnext/utils/middleware.utils.js.map +1 -1
- package/build/esnext/utils/obj.utils.js +17 -26
- package/build/esnext/utils/obj.utils.js.map +1 -1
- package/build/esnext/utils/response.utils.d.ts +2 -2
- package/build/esnext/utils/response.utils.js +11 -11
- package/build/esnext/utils/response.utils.js.map +1 -1
- package/build/esnext/utils/string.utils.js +17 -17
- package/build/esnext/utils/string.utils.js.map +1 -1
- package/build/esnext/utils/url.utils.js +21 -23
- package/build/esnext/utils/url.utils.js.map +1 -1
- package/build/esnext/utils/validate.utils.js +14 -16
- package/build/esnext/utils/validate.utils.js.map +1 -1
- package/build/src/config.d.ts +1 -5
- package/build/src/config.js +5 -9
- package/build/src/config.js.map +1 -1
- package/build/src/index.d.ts +20 -19
- package/build/src/index.js +1 -0
- package/build/src/index.js.map +1 -1
- package/build/src/types/api-response.d.ts +2 -2
- package/build/src/types/api-response.js.map +1 -1
- package/build/src/utils/array.utils.d.ts +1 -1
- package/build/src/utils/array.utils.js +22 -30
- package/build/src/utils/array.utils.js.map +1 -1
- package/build/src/utils/async.utils.d.ts +1 -5
- package/build/src/utils/async.utils.js +22 -22
- package/build/src/utils/async.utils.js.map +1 -1
- package/build/src/utils/cache.utils.js +2 -2
- package/build/src/utils/cache.utils.js.map +1 -1
- package/build/src/utils/context-store.utils.d.ts +1 -1
- package/build/src/utils/context-store.utils.js +9 -9
- package/build/src/utils/context-store.utils.js.map +1 -1
- package/build/src/utils/crypto.utils.d.ts +2 -2
- package/build/src/utils/crypto.utils.js +35 -45
- package/build/src/utils/crypto.utils.js.map +1 -1
- package/build/src/utils/decorators.utils.d.ts +2 -18
- package/build/src/utils/decorators.utils.js +32 -32
- package/build/src/utils/decorators.utils.js.map +1 -1
- package/build/src/utils/dir.utils.d.ts +4 -4
- package/build/src/utils/dir.utils.js +16 -18
- package/build/src/utils/dir.utils.js.map +1 -1
- package/build/src/utils/env.utils.js +22 -24
- package/build/src/utils/env.utils.js.map +1 -1
- package/build/src/utils/exception.utils.d.ts +1 -1
- package/build/src/utils/exception.utils.js +23 -26
- package/build/src/utils/exception.utils.js.map +1 -1
- package/build/src/utils/fs.utils.d.ts +3 -3
- package/build/src/utils/fs.utils.js +15 -19
- package/build/src/utils/fs.utils.js.map +1 -1
- package/build/src/utils/http-status-codes.js.map +1 -1
- package/build/src/utils/id.utils.js +7 -7
- package/build/src/utils/id.utils.js.map +1 -1
- package/build/src/utils/logger.utils.d.ts +13 -4
- package/build/src/utils/logger.utils.js +13 -15
- package/build/src/utils/logger.utils.js.map +1 -1
- package/build/src/utils/middleware.utils.d.ts +15 -26
- package/build/src/utils/middleware.utils.js +72 -52
- package/build/src/utils/middleware.utils.js.map +1 -1
- package/build/src/utils/obj.utils.js +17 -26
- package/build/src/utils/obj.utils.js.map +1 -1
- package/build/src/utils/response.utils.d.ts +2 -2
- package/build/src/utils/response.utils.js +9 -9
- package/build/src/utils/response.utils.js.map +1 -1
- package/build/src/utils/string.utils.js +17 -17
- package/build/src/utils/string.utils.js.map +1 -1
- package/build/src/utils/url.utils.js +20 -22
- package/build/src/utils/url.utils.js.map +1 -1
- package/build/src/utils/validate.utils.js +14 -16
- package/build/src/utils/validate.utils.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.utils.js","sourceRoot":"","sources":["../../../src/utils/crypto.utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EACL,UAAU,EACV,UAAU,EAEV,UAAU,EACV,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,MAAM,EACN,eAAe,GAEhB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAgBjC;;;;;;;;GAQG;AACH,MAAM,UAAU,IAAI,CAClB,SAAiB,EACjB,KAAa,EACb,MAAc,EACd,QAAsC;IAAtC,yBAAA,EAAA,gBAAsC;IAEtC,OAAO,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACtE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,IAAI,CAClB,SAAiB,EACjB,KAAa,EACb,QAAsC;IAAtC,yBAAA,EAAA,gBAAsC;IAEtC,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,MAAc;IACtD,OAAO,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,IAAI,CAClB,KAAa,EACb,QAAsC;IAAtC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WAAW,CAAC,CAAC;QAC1E,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,iBAAiB,CAAC;YAAE,OAAO,IAAI,CAAC;QAE5D,iBAAiB;QACjB,IAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACzE,IAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAEvC,mBAAmB;QACnB,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;YAC/D,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import {\n createHmac,\n createHash,\n BinaryToTextEncoding,\n randomUUID,\n randomBytes,\n createCipheriv,\n createDecipheriv,\n scrypt,\n timingSafeEqual,\n CipherGCMTypes,\n} from \"crypto\";\nimport { promisify } from \"util\";\n\nexport type BufferEncoding =\n | \"ascii\"\n | \"utf8\"\n | \"utf-8\"\n | \"utf16le\"\n | \"utf-16le\"\n | \"ucs2\"\n | \"ucs-2\"\n | \"base64\"\n | \"base64url\"\n | \"latin1\"\n | \"binary\"\n | \"hex\";\n\n/**\n * Generates an HMAC digest using the specified algorithm and secret key.\n *\n * @param {string} algorithm - The hashing algorithm (e.g., 'sha256', 'sha1').\n * @param {string} input - The string to hash.\n * @param {string} secret - The secret key for HMAC.\n * @param {BinaryToTextEncoding} [encoding='hex'] - Output encoding ('hex', 'base64', etc).\n * @returns {string} HMAC digest as a string.\n */\nexport function hmac(\n algorithm: string,\n input: string,\n secret: string,\n encoding: BinaryToTextEncoding = \"hex\",\n): string {\n return createHmac(algorithm, secret).update(input).digest(encoding);\n}\n\n/**\n * Generates a hash digest using the specified algorithm.\n *\n * @param {string} algorithm - The hashing algorithm (e.g., 'sha256', 'md5').\n * @param {string} input - The string to hash.\n * @param {BinaryToTextEncoding} [encoding='hex'] - Output encoding ('hex', 'base64', etc).\n * @returns {string} Hash digest as a string.\n */\nexport function hash(\n algorithm: string,\n input: string,\n encoding: BinaryToTextEncoding = \"hex\",\n): string {\n return createHash(algorithm).update(input).digest(encoding);\n}\n\n/**\n * Generates an HMAC-SHA256 digest.\n *\n * @param {string} input - The string to hash.\n * @param {string} secret - The secret key.\n * @returns {string} SHA-256 HMAC digest as a string.\n */\nexport function sha256Hmac(input: string, secret: string): string {\n return hmac(\"sha256\", input, secret);\n}\n\n/**\n * Generates a SHA1 hash digest.\n *\n * @param {string} input - The string to hash.\n * @param {BinaryToTextEncoding} [encoding='hex'] - Output encoding.\n * @returns {string} SHA-1 hash as a string.\n */\nexport function sha1(\n input: string,\n encoding: BinaryToTextEncoding = \"hex\",\n): string {\n return hash(\"sha1\", input, encoding);\n}\n\n/**\n * Generates a SHA256 hash digest.\n *\n * @param {string} input - The string to hash.\n * @param {BinaryToTextEncoding} [encoding='hex'] - Output encoding.\n * @returns {string} SHA-256 hash as a string.\n */\nexport function sha256(\n input: string,\n encoding: BinaryToTextEncoding = \"hex\",\n): string {\n return hash(\"sha256\", input, encoding);\n}\n\n/**\n * Generates an MD5 hash digest.\n *\n * @param {string} input - The string to hash.\n * @returns {string} MD5 hash as a string.\n */\nexport function md5(input: string): string {\n return hash(\"md5\", input);\n}\n\n/**\n * Generates a cryptographically strong random string by hashing a random UUID with SHA-256.\n *\n * @returns {string} Random string hashed with SHA-256 (hex encoding).\n */\nexport function randomString(): string {\n return sha256(randomUUID());\n}\n\n/**\n * Generates a secure random buffer of specified byte length.\n *\n * @param {number} [byteLength=32] - Number of random bytes to generate.\n * @returns {Buffer} Buffer containing random bytes.\n */\nexport function generateRandomBytes(byteLength: number = 32): Buffer {\n return randomBytes(byteLength);\n}\n\n/**\n * Generates a secure random string of specified byte length with specified encoding.\n *\n * @param {number} [byteLength=32] - Number of random bytes to generate.\n * @param {BinaryToTextEncoding} [encoding='hex'] - Output encoding.\n * @returns {string} Random string in specified encoding.\n */\nexport function generateRandomBytesAsString(\n byteLength: number = 32,\n encoding: BinaryToTextEncoding = \"hex\",\n): string {\n return randomBytes(byteLength).toString(encoding);\n}\n\n/**\n * Generates a secure API key with a specified format.\n *\n * @param {string} [prefix=''] - Optional prefix for the key.\n * @param {number} [byteLength=24] - Number of random bytes to generate.\n * @returns {string} Formatted API key.\n */\nexport function generateApiKey(\n prefix: string = \"\",\n byteLength: number = 24,\n): string {\n const randomString = generateRandomBytesAsString(byteLength, \"base64\");\n const key = randomString\n .replace(/[+/=]/g, \"\") // Remove non-URL-safe characters\n .substring(0, 32); // Limit length\n\n return prefix ? `${prefix}_${key}` : key;\n}\n\n/**\n * Compares two strings, arrays, or buffers in constant time to prevent timing attacks.\n *\n * @param {string | Buffer | Uint8Array} a - First value to compare\n * @param {string | Buffer | Uint8Array} b - Second value to compare\n * @returns {boolean} True if values are equal\n */\nexport function safeCompare(\n a: string | Buffer | Uint8Array,\n b: string | Buffer | Uint8Array,\n): boolean {\n if (typeof a === \"string\" && typeof b === \"string\") {\n // Convert strings to buffers\n const bufA = Buffer.from(a);\n const bufB = Buffer.from(b);\n\n // Compare lengths first (not constant time, but prevents timing attack on contents)\n if (bufA.length !== bufB.length) return false;\n\n return timingSafeEqual(bufA, bufB);\n } else if (\n (a instanceof Buffer || a instanceof Uint8Array) &&\n (b instanceof Buffer || b instanceof Uint8Array)\n ) {\n // Compare lengths first\n if (a.length !== b.length) return false;\n\n return timingSafeEqual(\n a instanceof Buffer ? a : Buffer.from(a),\n b instanceof Buffer ? b : Buffer.from(b),\n );\n }\n\n throw new Error(\n \"Cannot compare: inputs must be strings, Buffers, or Uint8Arrays\",\n );\n}\n\n/**\n * Interface for encryption options\n */\nexport interface EncryptionOptions {\n /** Algorithm to use (default: aes-256-gcm) */\n algorithm?: CipherGCMTypes;\n /** Input encoding for plaintext if string (default: utf8) */\n inputEncoding?: BufferEncoding;\n /** Output encoding for ciphertext (default: hex) */\n outputEncoding?: BinaryToTextEncoding;\n}\n\n/**\n * Interface for decryption options\n */\nexport interface DecryptionOptions {\n /** Algorithm to use (default: aes-256-gcm) */\n algorithm?: CipherGCMTypes;\n /** Input encoding for ciphertext if string (default: hex) */\n inputEncoding?: BinaryToTextEncoding;\n /** Output encoding for plaintext (default: utf8) */\n outputEncoding?: BufferEncoding;\n}\n\n/**\n * Result of encryption operation including all data needed for decryption\n */\nexport interface EncryptionResult {\n /** Encrypted data (string or Buffer based on options) */\n ciphertext: string | Buffer;\n /** Initialization vector */\n iv: Buffer;\n /** Authentication tag (for GCM mode) */\n authTag?: Buffer;\n /** Algorithm used */\n algorithm: string;\n}\n\n// Promisified version of scrypt for key derivation\nconst scryptAsync = promisify<string | Buffer, string | Buffer, number, Buffer>(\n scrypt,\n);\n\n/**\n * Encrypts data using a symmetric key with secure defaults (AES-256-GCM).\n *\n * @param {string | Buffer} data - Data to encrypt\n * @param {string | Buffer} key - Encryption key or passphrase\n * @param {EncryptionOptions} [options] - Encryption options\n * @returns {Promise<EncryptionResult>} Encrypted data with metadata\n */\nexport async function encrypt(\n data: string | Buffer,\n key: string | Buffer,\n options: EncryptionOptions = {},\n): Promise<EncryptionResult> {\n const algorithm = options.algorithm || \"aes-256-gcm\";\n const inputEncoding = options.inputEncoding || \"utf8\";\n const outputEncoding = options.outputEncoding || \"hex\";\n\n // Generate a random IV\n const iv = randomBytes(16);\n\n // Derive key using scrypt if key is a string (passphrase)\n const derivedKey =\n typeof key === \"string\" ? await scryptAsync(key, iv.slice(0, 8), 32) : key;\n\n // Create cipher\n const cipher = createCipheriv(algorithm, derivedKey, iv);\n\n // Encrypt the data\n let ciphertext: string | Buffer;\n\n if (typeof data === \"string\") {\n ciphertext = cipher.update(\n data,\n inputEncoding,\n outputEncoding as BufferEncoding,\n );\n ciphertext += cipher.final(outputEncoding as BufferEncoding);\n } else {\n const encrypted = Buffer.concat([cipher.update(data), cipher.final()]);\n ciphertext = outputEncoding\n ? encrypted.toString(outputEncoding)\n : encrypted;\n }\n\n // Get authentication tag if using GCM mode\n const authTag = algorithm.includes(\"gcm\")\n ? (cipher as any).getAuthTag()\n : undefined;\n\n return {\n ciphertext,\n iv,\n authTag,\n algorithm,\n };\n}\n\n/**\n * Decrypts data that was encrypted with the encrypt function.\n *\n * @param {EncryptionResult} encryptedData - The encrypted data and metadata\n * @param {string | Buffer} key - Decryption key or passphrase\n * @param {DecryptionOptions} [options] - Decryption options\n * @returns {Promise<string | Buffer>} Decrypted data\n */\nexport async function decrypt(\n encryptedData: EncryptionResult,\n key: string | Buffer,\n options: DecryptionOptions = {},\n): Promise<string | Buffer> {\n const algorithm =\n options.algorithm || encryptedData.algorithm || \"aes-256-gcm\";\n const inputEncoding = options.inputEncoding || \"hex\";\n const outputEncoding = options.outputEncoding || \"utf8\";\n\n // Derive key using scrypt if key is a string (passphrase)\n const derivedKey =\n typeof key === \"string\"\n ? await scryptAsync(key, encryptedData.iv.slice(0, 8), 32)\n : key;\n\n // Create decipher\n const decipher = createDecipheriv(algorithm, derivedKey, encryptedData.iv);\n\n // Set auth tag if using GCM mode\n if (encryptedData.authTag && algorithm.includes(\"gcm\")) {\n (decipher as any).setAuthTag(encryptedData.authTag);\n }\n\n // Decrypt the data\n let decrypted: string | Buffer;\n\n if (typeof encryptedData.ciphertext === \"string\") {\n decrypted = decipher.update(\n encryptedData.ciphertext,\n inputEncoding as BufferEncoding,\n outputEncoding,\n );\n decrypted += decipher.final(outputEncoding);\n } else {\n const result = Buffer.concat([\n decipher.update(encryptedData.ciphertext),\n decipher.final(),\n ]);\n decrypted = outputEncoding ? result.toString(outputEncoding) : result;\n }\n\n return decrypted;\n}\n\n/**\n * Creates a signed token with an expiration time and payload.\n *\n * @param {object} payload - Data to include in the token\n * @param {string} secret - Secret key for signing\n * @param {number} [expiresInSeconds=3600] - Token expiration in seconds\n * @returns {string} Signed token string\n */\nexport function createSignedToken(\n payload: Record<string, any>,\n secret: string,\n expiresInSeconds: number = 3600,\n): string {\n // Create payload with expiration\n const tokenPayload = {\n ...payload,\n exp: Math.floor(Date.now() / 1000) + expiresInSeconds,\n };\n\n // Convert to string\n const payloadStr = JSON.stringify(tokenPayload);\n\n // Base64 encode the payload\n const base64Payload = Buffer.from(payloadStr).toString(\"base64url\");\n\n // Create signature\n const signature = hmac(\"sha256\", base64Payload, secret, \"base64url\");\n\n // Combine payload and signature\n return `${base64Payload}.${signature}`;\n}\n\n/**\n * Verifies and decodes a signed token.\n *\n * @param {string} token - The token to verify\n * @param {string} secret - Secret key for verification\n * @returns {object | null} Decoded payload if valid, null if invalid\n */\nexport function verifySignedToken(\n token: string,\n secret: string,\n): Record<string, any> | null {\n try {\n // Split token into parts\n const [payloadB64, signature] = token.split(\".\");\n\n if (!payloadB64 || !signature) return null;\n\n // Verify signature\n const expectedSignature = hmac(\"sha256\", payloadB64, secret, \"base64url\");\n if (!safeCompare(signature, expectedSignature)) return null;\n\n // Decode payload\n const payloadStr = Buffer.from(payloadB64, \"base64url\").toString(\"utf8\");\n const payload = JSON.parse(payloadStr);\n\n // Check expiration\n if (payload.exp && payload.exp < Math.floor(Date.now() / 1000)) {\n return null;\n }\n\n return payload;\n } catch {\n return null;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"crypto.utils.js","sourceRoot":"","sources":["../../../src/utils/crypto.utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EACL,UAAU,EACV,UAAU,EAEV,UAAU,EACV,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,MAAM,EACN,eAAe,EAEhB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAgBjC;;;;;;;;GAQG;AACH,MAAM,UAAU,IAAI,CAAC,SA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":["import {\n createHmac,\n createHash,\n BinaryToTextEncoding,\n randomUUID,\n randomBytes,\n createCipheriv,\n createDecipheriv,\n scrypt,\n timingSafeEqual,\n CipherGCMTypes\n} from 'crypto';\nimport { promisify } from 'util';\n\nexport type BufferEncoding =\n | 'ascii'\n | 'utf8'\n | 'utf-8'\n | 'utf16le'\n | 'utf-16le'\n | 'ucs2'\n | 'ucs-2'\n | 'base64'\n | 'base64url'\n | 'latin1'\n | 'binary'\n | 'hex';\n\n/**\n * Generates an HMAC digest using the specified algorithm and secret key.\n *\n * @param {string} algorithm - The hashing algorithm (e.g., 'sha256', 'sha1').\n * @param {string} input - The string to hash.\n * @param {string} secret - The secret key for HMAC.\n * @param {BinaryToTextEncoding} [encoding='hex'] - Output encoding ('hex', 'base64', etc).\n * @returns {string} HMAC digest as a string.\n */\nexport function hmac(algorithm: string, input: string, secret: string, encoding: BinaryToTextEncoding = 'hex'): string {\n return createHmac(algorithm, secret).update(input).digest(encoding);\n}\n\n/**\n * Generates a hash digest using the specified algorithm.\n *\n * @param {string} algorithm - The hashing algorithm (e.g., 'sha256', 'md5').\n * @param {string} input - The string to hash.\n * @param {BinaryToTextEncoding} [encoding='hex'] - Output encoding ('hex', 'base64', etc).\n * @returns {string} Hash digest as a string.\n */\nexport function hash(algorithm: string, input: string, encoding: BinaryToTextEncoding = 'hex'): string {\n return createHash(algorithm).update(input).digest(encoding);\n}\n\n/**\n * Generates an HMAC-SHA256 digest.\n *\n * @param {string} input - The string to hash.\n * @param {string} secret - The secret key.\n * @returns {string} SHA-256 HMAC digest as a string.\n */\nexport function sha256Hmac(input: string, secret: string): string {\n return hmac('sha256', input, secret);\n}\n\n/**\n * Generates a SHA1 hash digest.\n *\n * @param {string} input - The string to hash.\n * @param {BinaryToTextEncoding} [encoding='hex'] - Output encoding.\n * @returns {string} SHA-1 hash as a string.\n */\nexport function sha1(input: string, encoding: BinaryToTextEncoding = 'hex'): string {\n return hash('sha1', input, encoding);\n}\n\n/**\n * Generates a SHA256 hash digest.\n *\n * @param {string} input - The string to hash.\n * @param {BinaryToTextEncoding} [encoding='hex'] - Output encoding.\n * @returns {string} SHA-256 hash as a string.\n */\nexport function sha256(input: string, encoding: BinaryToTextEncoding = 'hex'): string {\n return hash('sha256', input, encoding);\n}\n\n/**\n * Generates an MD5 hash digest.\n *\n * @param {string} input - The string to hash.\n * @returns {string} MD5 hash as a string.\n */\nexport function md5(input: string): string {\n return hash('md5', input);\n}\n\n/**\n * Generates a cryptographically strong random string by hashing a random UUID with SHA-256.\n *\n * @returns {string} Random string hashed with SHA-256 (hex encoding).\n */\nexport function randomString(): string {\n return sha256(randomUUID());\n}\n\n/**\n * Generates a secure random buffer of specified byte length.\n *\n * @param {number} [byteLength=32] - Number of random bytes to generate.\n * @returns {Buffer} Buffer containing random bytes.\n */\nexport function generateRandomBytes(byteLength: number = 32): Buffer {\n return randomBytes(byteLength);\n}\n\n/**\n * Generates a secure random string of specified byte length with specified encoding.\n *\n * @param {number} [byteLength=32] - Number of random bytes to generate.\n * @param {BinaryToTextEncoding} [encoding='hex'] - Output encoding.\n * @returns {string} Random string in specified encoding.\n */\nexport function generateRandomBytesAsString(byteLength: number = 32, encoding: BinaryToTextEncoding = 'hex'): string {\n return randomBytes(byteLength).toString(encoding);\n}\n\n/**\n * Generates a secure API key with a specified format.\n *\n * @param {string} [prefix=''] - Optional prefix for the key.\n * @param {number} [byteLength=24] - Number of random bytes to generate.\n * @returns {string} Formatted API key.\n */\nexport function generateApiKey(prefix: string = '', byteLength: number = 24): string {\n const randomString = generateRandomBytesAsString(byteLength, 'base64');\n const key = randomString\n .replace(/[+/=]/g, '') // Remove non-URL-safe characters\n .substring(0, 32); // Limit length\n\n return prefix ? `${prefix}_${key}` : key;\n}\n\n/**\n * Compares two strings, arrays, or buffers in constant time to prevent timing attacks.\n *\n * @param {string | Buffer | Uint8Array} a - First value to compare\n * @param {string | Buffer | Uint8Array} b - Second value to compare\n * @returns {boolean} True if values are equal\n */\nexport function safeCompare(a: string | Buffer | Uint8Array, b: string | Buffer | Uint8Array): boolean {\n if (typeof a === 'string' && typeof b === 'string') {\n // Convert strings to buffers\n const bufA = Buffer.from(a);\n const bufB = Buffer.from(b);\n\n // Compare lengths first (not constant time, but prevents timing attack on contents)\n if (bufA.length !== bufB.length) return false;\n\n return timingSafeEqual(bufA, bufB);\n } else if ((a instanceof Buffer || a instanceof Uint8Array) && (b instanceof Buffer || b instanceof Uint8Array)) {\n // Compare lengths first\n if (a.length !== b.length) return false;\n\n return timingSafeEqual(a instanceof Buffer ? a : Buffer.from(a), b instanceof Buffer ? b : Buffer.from(b));\n }\n\n throw new Error('Cannot compare: inputs must be strings, Buffers, or Uint8Arrays');\n}\n\n/**\n * Interface for encryption options\n */\nexport interface EncryptionOptions {\n /** Algorithm to use (default: aes-256-gcm) */\n algorithm?: CipherGCMTypes;\n /** Input encoding for plaintext if string (default: utf8) */\n inputEncoding?: BufferEncoding;\n /** Output encoding for ciphertext (default: hex) */\n outputEncoding?: BinaryToTextEncoding;\n}\n\n/**\n * Interface for decryption options\n */\nexport interface DecryptionOptions {\n /** Algorithm to use (default: aes-256-gcm) */\n algorithm?: CipherGCMTypes;\n /** Input encoding for ciphertext if string (default: hex) */\n inputEncoding?: BinaryToTextEncoding;\n /** Output encoding for plaintext (default: utf8) */\n outputEncoding?: BufferEncoding;\n}\n\n/**\n * Result of encryption operation including all data needed for decryption\n */\nexport interface EncryptionResult {\n /** Encrypted data (string or Buffer based on options) */\n ciphertext: string | Buffer;\n /** Initialization vector */\n iv: Buffer;\n /** Authentication tag (for GCM mode) */\n authTag?: Buffer;\n /** Algorithm used */\n algorithm: string;\n}\n\n// Promisified version of scrypt for key derivation\nconst scryptAsync = promisify<string | Buffer, string | Buffer, number, Buffer>(scrypt);\n\n/**\n * Encrypts data using a symmetric key with secure defaults (AES-256-GCM).\n *\n * @param {string | Buffer} data - Data to encrypt\n * @param {string | Buffer} key - Encryption key or passphrase\n * @param {EncryptionOptions} [options] - Encryption options\n * @returns {Promise<EncryptionResult>} Encrypted data with metadata\n */\nexport async function encrypt(\n data: string | Buffer,\n key: string | Buffer,\n options: EncryptionOptions = {}\n): Promise<EncryptionResult> {\n const algorithm = options.algorithm || 'aes-256-gcm';\n const inputEncoding = options.inputEncoding || 'utf8';\n const outputEncoding = options.outputEncoding || 'hex';\n\n // Generate a random IV\n const iv = randomBytes(16);\n\n // Derive key using scrypt if key is a string (passphrase)\n const derivedKey = typeof key === 'string' ? await scryptAsync(key, iv.slice(0, 8), 32) : key;\n\n // Create cipher\n const cipher = createCipheriv(algorithm, derivedKey, iv);\n\n // Encrypt the data\n let ciphertext: string | Buffer;\n\n if (typeof data === 'string') {\n ciphertext = cipher.update(data, inputEncoding, outputEncoding as BufferEncoding);\n ciphertext += cipher.final(outputEncoding as BufferEncoding);\n } else {\n const encrypted = Buffer.concat([cipher.update(data), cipher.final()]);\n ciphertext = outputEncoding ? encrypted.toString(outputEncoding) : encrypted;\n }\n\n // Get authentication tag if using GCM mode\n const authTag = algorithm.includes('gcm') ? (cipher as any).getAuthTag() : undefined;\n\n return {\n ciphertext,\n iv,\n authTag,\n algorithm\n };\n}\n\n/**\n * Decrypts data that was encrypted with the encrypt function.\n *\n * @param {EncryptionResult} encryptedData - The encrypted data and metadata\n * @param {string | Buffer} key - Decryption key or passphrase\n * @param {DecryptionOptions} [options] - Decryption options\n * @returns {Promise<string | Buffer>} Decrypted data\n */\nexport async function decrypt(\n encryptedData: EncryptionResult,\n key: string | Buffer,\n options: DecryptionOptions = {}\n): Promise<string | Buffer> {\n const algorithm = options.algorithm || encryptedData.algorithm || 'aes-256-gcm';\n const inputEncoding = options.inputEncoding || 'hex';\n const outputEncoding = options.outputEncoding || 'utf8';\n\n // Derive key using scrypt if key is a string (passphrase)\n const derivedKey = typeof key === 'string' ? await scryptAsync(key, encryptedData.iv.slice(0, 8), 32) : key;\n\n // Create decipher\n const decipher = createDecipheriv(algorithm, derivedKey, encryptedData.iv);\n\n // Set auth tag if using GCM mode\n if (encryptedData.authTag && algorithm.includes('gcm')) {\n (decipher as any).setAuthTag(encryptedData.authTag);\n }\n\n // Decrypt the data\n let decrypted: string | Buffer;\n\n if (typeof encryptedData.ciphertext === 'string') {\n decrypted = decipher.update(encryptedData.ciphertext, inputEncoding as BufferEncoding, outputEncoding);\n decrypted += decipher.final(outputEncoding);\n } else {\n const result = Buffer.concat([decipher.update(encryptedData.ciphertext), decipher.final()]);\n decrypted = outputEncoding ? result.toString(outputEncoding) : result;\n }\n\n return decrypted;\n}\n\n/**\n * Creates a signed token with an expiration time and payload.\n *\n * @param {object} payload - Data to include in the token\n * @param {string} secret - Secret key for signing\n * @param {number} [expiresInSeconds=3600] - Token expiration in seconds\n * @returns {string} Signed token string\n */\nexport function createSignedToken(\n payload: Record<string, any>,\n secret: string,\n expiresInSeconds: number = 3600\n): string {\n // Create payload with expiration\n const tokenPayload = {\n ...payload,\n exp: Math.floor(Date.now() / 1000) + expiresInSeconds\n };\n\n // Convert to string\n const payloadStr = JSON.stringify(tokenPayload);\n\n // Base64 encode the payload\n const base64Payload = Buffer.from(payloadStr).toString('base64url');\n\n // Create signature\n const signature = hmac('sha256', base64Payload, secret, 'base64url');\n\n // Combine payload and signature\n return `${base64Payload}.${signature}`;\n}\n\n/**\n * Verifies and decodes a signed token.\n *\n * @param {string} token - The token to verify\n * @param {string} secret - Secret key for verification\n * @returns {object | null} Decoded payload if valid, null if invalid\n */\nexport function verifySignedToken(token: string, secret: string): Record<string, any> | null {\n try {\n // Split token into parts\n const [payloadB64, signature] = token.split('.');\n\n if (!payloadB64 || !signature) return null;\n\n // Verify signature\n const expectedSignature = hmac('sha256', payloadB64, secret, 'base64url');\n if (!safeCompare(signature, expectedSignature)) return null;\n\n // Decode payload\n const payloadStr = Buffer.from(payloadB64, 'base64url').toString('utf8');\n const payload = JSON.parse(payloadStr);\n\n // Check expiration\n if (payload.exp && payload.exp < Math.floor(Date.now() / 1000)) {\n return null;\n }\n\n return payload;\n } catch {\n return null;\n }\n}\n"]}
|
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
query: any;
|
|
4
|
-
params: any;
|
|
5
|
-
body?: any;
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
}
|
|
8
|
-
export interface Response {
|
|
9
|
-
json: (body: any) => void;
|
|
10
|
-
headersSent: boolean;
|
|
11
|
-
[key: string]: any;
|
|
12
|
-
}
|
|
13
|
-
export type NextFunction = (err?: any) => void;
|
|
14
|
-
export type RequestHandler = (req: Request, res: Response, next: NextFunction) => any;
|
|
15
|
-
export interface Router {
|
|
16
|
-
[method: string]: (path: string, ...handlers: RequestHandler[]) => void;
|
|
17
|
-
}
|
|
18
|
-
export type HttpMethod = "get" | "post" | "put" | "patch" | "delete" | "options" | "head" | "trace" | "connect";
|
|
1
|
+
import type { RequestHandler, Router } from 'express';
|
|
2
|
+
import 'reflect-metadata';
|
|
19
3
|
export declare const Get: (path: string) => MethodDecorator;
|
|
20
4
|
export declare const Post: (path: string) => MethodDecorator;
|
|
21
5
|
export declare const Put: (path: string) => MethodDecorator;
|
|
@@ -71,11 +71,11 @@ var __values = (this && this.__values) || function(o) {
|
|
|
71
71
|
};
|
|
72
72
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
73
73
|
};
|
|
74
|
-
import
|
|
74
|
+
import 'reflect-metadata';
|
|
75
75
|
// --- End sample Express interfaces ---
|
|
76
|
-
var ROUTES_KEY = Symbol(
|
|
77
|
-
var MIDDLEWARE_KEY = Symbol(
|
|
78
|
-
var PARAMS_KEY = Symbol(
|
|
76
|
+
var ROUTES_KEY = Symbol('routes');
|
|
77
|
+
var MIDDLEWARE_KEY = Symbol('middlewares');
|
|
78
|
+
var PARAMS_KEY = Symbol('params');
|
|
79
79
|
// ---- Route Decorators ----
|
|
80
80
|
function createRouteDecorator(method) {
|
|
81
81
|
return function (path) {
|
|
@@ -84,25 +84,25 @@ function createRouteDecorator(method) {
|
|
|
84
84
|
routes.push({
|
|
85
85
|
path: path,
|
|
86
86
|
method: method,
|
|
87
|
-
handlerName: propertyKey
|
|
87
|
+
handlerName: propertyKey
|
|
88
88
|
});
|
|
89
89
|
Reflect.defineMetadata(ROUTES_KEY, routes, target.constructor);
|
|
90
90
|
};
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
export var Get = createRouteDecorator(
|
|
94
|
-
export var Post = createRouteDecorator(
|
|
95
|
-
export var Put = createRouteDecorator(
|
|
96
|
-
export var Patch = createRouteDecorator(
|
|
97
|
-
export var Delete = createRouteDecorator(
|
|
98
|
-
export var Options = createRouteDecorator(
|
|
99
|
-
export var Head = createRouteDecorator(
|
|
100
|
-
export var Trace = createRouteDecorator(
|
|
101
|
-
export var Connect = createRouteDecorator(
|
|
93
|
+
export var Get = createRouteDecorator('get');
|
|
94
|
+
export var Post = createRouteDecorator('post');
|
|
95
|
+
export var Put = createRouteDecorator('put');
|
|
96
|
+
export var Patch = createRouteDecorator('patch');
|
|
97
|
+
export var Delete = createRouteDecorator('delete');
|
|
98
|
+
export var Options = createRouteDecorator('options');
|
|
99
|
+
export var Head = createRouteDecorator('head');
|
|
100
|
+
export var Trace = createRouteDecorator('trace');
|
|
101
|
+
export var Connect = createRouteDecorator('connect');
|
|
102
102
|
// ---- Controller Decorator ----
|
|
103
103
|
export function Controller(basePath) {
|
|
104
104
|
return function (target) {
|
|
105
|
-
Reflect.defineMetadata(
|
|
105
|
+
Reflect.defineMetadata('basePath', basePath, target);
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
108
|
// ---- Middleware Decorator ----
|
|
@@ -128,20 +128,20 @@ function createParamDecorator(type, key) {
|
|
|
128
128
|
};
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
|
-
export var Query = createParamDecorator(
|
|
132
|
-
export var Param = createParamDecorator(
|
|
133
|
-
export var Body = createParamDecorator(
|
|
134
|
-
export var Req = createParamDecorator(
|
|
135
|
-
export var Res = createParamDecorator(
|
|
131
|
+
export var Query = createParamDecorator('query');
|
|
132
|
+
export var Param = createParamDecorator('param');
|
|
133
|
+
export var Body = createParamDecorator('body');
|
|
134
|
+
export var Req = createParamDecorator('req');
|
|
135
|
+
export var Res = createParamDecorator('res');
|
|
136
136
|
// Custom HTTP status code decorator
|
|
137
|
-
var HTTP_CODE_KEY = Symbol(
|
|
137
|
+
var HTTP_CODE_KEY = Symbol('httpCode');
|
|
138
138
|
export function HttpCode(status) {
|
|
139
139
|
return function (target, propertyKey, descriptor) {
|
|
140
140
|
Reflect.defineMetadata(HTTP_CODE_KEY, status, target, propertyKey);
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
143
|
// Custom header decorator
|
|
144
|
-
var HEADER_KEY = Symbol(
|
|
144
|
+
var HEADER_KEY = Symbol('headers');
|
|
145
145
|
export function Header(name, value) {
|
|
146
146
|
return function (target, propertyKey, descriptor) {
|
|
147
147
|
var headers = Reflect.getMetadata(HEADER_KEY, target, propertyKey) || {};
|
|
@@ -150,8 +150,8 @@ export function Header(name, value) {
|
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
152
|
// Before/After hooks (not Express middleware, but can be used for logging, etc.)
|
|
153
|
-
var BEFORE_KEY = Symbol(
|
|
154
|
-
var AFTER_KEY = Symbol(
|
|
153
|
+
var BEFORE_KEY = Symbol('before');
|
|
154
|
+
var AFTER_KEY = Symbol('after');
|
|
155
155
|
export function Before(fn) {
|
|
156
156
|
return function (target, propertyKey, descriptor) {
|
|
157
157
|
var hooks = Reflect.getMetadata(BEFORE_KEY, target, propertyKey) || [];
|
|
@@ -171,7 +171,7 @@ export function registerControllers(router, controllers) {
|
|
|
171
171
|
var _this = this;
|
|
172
172
|
controllers.forEach(function (ControllerClass) {
|
|
173
173
|
var instance = new ControllerClass();
|
|
174
|
-
var basePath = Reflect.getMetadata(
|
|
174
|
+
var basePath = Reflect.getMetadata('basePath', ControllerClass) || '';
|
|
175
175
|
var routes = Reflect.getMetadata(ROUTES_KEY, ControllerClass) || [];
|
|
176
176
|
routes.forEach(function (_a) {
|
|
177
177
|
var _b;
|
|
@@ -223,19 +223,19 @@ export function registerControllers(router, controllers) {
|
|
|
223
223
|
var _b;
|
|
224
224
|
var index = _a.index, type = _a.type, key = _a.key;
|
|
225
225
|
switch (type) {
|
|
226
|
-
case
|
|
226
|
+
case 'query':
|
|
227
227
|
args_1[index] = key ? req.query[key] : req.query;
|
|
228
228
|
break;
|
|
229
|
-
case
|
|
229
|
+
case 'param':
|
|
230
230
|
args_1[index] = key ? req.params[key] : req.params;
|
|
231
231
|
break;
|
|
232
|
-
case
|
|
232
|
+
case 'body':
|
|
233
233
|
args_1[index] = key ? (_b = req.body) === null || _b === void 0 ? void 0 : _b[key] : req.body;
|
|
234
234
|
break;
|
|
235
|
-
case
|
|
235
|
+
case 'req':
|
|
236
236
|
args_1[index] = req;
|
|
237
237
|
break;
|
|
238
|
-
case
|
|
238
|
+
case 'res':
|
|
239
239
|
args_1[index] = res;
|
|
240
240
|
break;
|
|
241
241
|
}
|
|
@@ -252,7 +252,7 @@ export function registerControllers(router, controllers) {
|
|
|
252
252
|
_l.label = 11;
|
|
253
253
|
case 11:
|
|
254
254
|
awaited = _a;
|
|
255
|
-
if (!res.headersSent && typeof awaited !==
|
|
255
|
+
if (!res.headersSent && typeof awaited !== 'undefined') {
|
|
256
256
|
if (httpCode)
|
|
257
257
|
(_j = res.status) === null || _j === void 0 ? void 0 : _j.call(res, httpCode);
|
|
258
258
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.utils.js","sourceRoot":"","sources":["../../../src/utils/decorators.utils.ts"],"names":[],"mappings":"AAAA,sDAAsD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEtD,OAAO,kBAAkB,CAAC;AAuB1B,wCAAwC;AAExC,IAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AACpC,IAAM,cAAc,GAAG,MAAM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A,KAAC,MAAc,CAAA,CAAC,MAAM,CAAC,wCAAC,QAAQ,GAAG,IAAI,UAAK,WAAW,YAAE,OAAO,WAAE;QACpE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\nimport \"reflect-metadata\";\n\n// --- Sample Express interfaces for type safety ---\nexport interface Request {\n query: any;\n params: any;\n body?: any;\n [key: string]: any;\n}\nexport interface Response {\n json: (body: any) => void;\n headersSent: boolean;\n [key: string]: any;\n}\nexport type NextFunction = (err?: any) => void;\nexport type RequestHandler = (\n req: Request,\n res: Response,\n next: NextFunction,\n) => any;\nexport interface Router {\n [method: string]: (path: string, ...handlers: RequestHandler[]) => void;\n}\n// --- End sample Express interfaces ---\n\nconst ROUTES_KEY = Symbol(\"routes\");\nconst MIDDLEWARE_KEY = Symbol(\"middlewares\");\nconst PARAMS_KEY = Symbol(\"params\");\n\nexport type HttpMethod =\n | \"get\"\n | \"post\"\n | \"put\"\n | \"patch\"\n | \"delete\"\n | \"options\"\n | \"head\"\n | \"trace\"\n | \"connect\";\n\ninterface RouteDefinition {\n path: string;\n method: HttpMethod;\n handlerName: string;\n}\n\ninterface ParamDefinition {\n index: number;\n type: \"query\" | \"param\" | \"body\" | \"req\" | \"res\";\n key?: string;\n}\n\n// ---- Route Decorators ----\nfunction createRouteDecorator(method: HttpMethod) {\n return (path: string): MethodDecorator => {\n return (target, propertyKey, descriptor) => {\n const routes: RouteDefinition[] =\n Reflect.getMetadata(ROUTES_KEY, target.constructor) || [];\n routes.push({\n path,\n method,\n handlerName: propertyKey as string,\n });\n Reflect.defineMetadata(ROUTES_KEY, routes, target.constructor);\n };\n };\n}\n\nexport const Get = createRouteDecorator(\"get\");\nexport const Post = createRouteDecorator(\"post\");\nexport const Put = createRouteDecorator(\"put\");\nexport const Patch = createRouteDecorator(\"patch\");\nexport const Delete = createRouteDecorator(\"delete\");\nexport const Options = createRouteDecorator(\"options\");\nexport const Head = createRouteDecorator(\"head\");\nexport const Trace = createRouteDecorator(\"trace\");\nexport const Connect = createRouteDecorator(\"connect\");\n\n// ---- Controller Decorator ----\nexport function Controller(basePath: string): ClassDecorator {\n return (target) => {\n Reflect.defineMetadata(\"basePath\", basePath, target);\n };\n}\n\n// ---- Middleware Decorator ----\nexport function Use(...middlewares: RequestHandler[]): MethodDecorator {\n return (target, propertyKey, descriptor) => {\n const existing: RequestHandler[] =\n Reflect.getMetadata(MIDDLEWARE_KEY, target, propertyKey as string) || [];\n Reflect.defineMetadata(\n MIDDLEWARE_KEY,\n [...existing, ...middlewares],\n target,\n propertyKey as string,\n );\n };\n}\n\n// ---- Parameter Decorators ----\nfunction createParamDecorator(type: ParamDefinition[\"type\"], key?: string) {\n return (paramKey?: string): ParameterDecorator => {\n return (target, propertyKey, parameterIndex) => {\n const params: ParamDefinition[] =\n Reflect.getMetadata(PARAMS_KEY, target, propertyKey as string) || [];\n // Ensure parameters are ordered by index\n params.push({ index: parameterIndex, type, key: paramKey || key });\n params.sort((a, b) => a.index - b.index);\n Reflect.defineMetadata(PARAMS_KEY, params, target, propertyKey as string);\n };\n };\n}\n\nexport const Query = createParamDecorator(\"query\");\nexport const Param = createParamDecorator(\"param\");\nexport const Body = createParamDecorator(\"body\");\nexport const Req = createParamDecorator(\"req\");\nexport const Res = createParamDecorator(\"res\");\n\n// Custom HTTP status code decorator\nconst HTTP_CODE_KEY = Symbol(\"httpCode\");\nexport function HttpCode(status: number): MethodDecorator {\n return (target, propertyKey, descriptor) => {\n Reflect.defineMetadata(\n HTTP_CODE_KEY,\n status,\n target,\n propertyKey as string,\n );\n };\n}\n\n// Custom header decorator\nconst HEADER_KEY = Symbol(\"headers\");\nexport function Header(name: string, value: string): MethodDecorator {\n return (target, propertyKey, descriptor) => {\n const headers: Record<string, string> =\n Reflect.getMetadata(HEADER_KEY, target, propertyKey as string) || {};\n headers[name] = value;\n Reflect.defineMetadata(HEADER_KEY, headers, target, propertyKey as string);\n };\n}\n\n// Before/After hooks (not Express middleware, but can be used for logging, etc.)\nconst BEFORE_KEY = Symbol(\"before\");\nconst AFTER_KEY = Symbol(\"after\");\nexport function Before(fn: Function): MethodDecorator {\n return (target, propertyKey, descriptor) => {\n const hooks: Function[] =\n Reflect.getMetadata(BEFORE_KEY, target, propertyKey as string) || [];\n hooks.push(fn);\n Reflect.defineMetadata(BEFORE_KEY, hooks, target, propertyKey as string);\n };\n}\nexport function After(fn: Function): MethodDecorator {\n return (target, propertyKey, descriptor) => {\n const hooks: Function[] =\n Reflect.getMetadata(AFTER_KEY, target, propertyKey as string) || [];\n hooks.push(fn);\n Reflect.defineMetadata(AFTER_KEY, hooks, target, propertyKey as string);\n };\n}\n\n// ---- Register Controllers ----\nexport function registerControllers(router: Router, controllers: any[]) {\n controllers.forEach((ControllerClass) => {\n const instance = new ControllerClass();\n const basePath: string =\n Reflect.getMetadata(\"basePath\", ControllerClass) || \"\";\n const routes: RouteDefinition[] =\n Reflect.getMetadata(ROUTES_KEY, ControllerClass) || [];\n\n routes.forEach(({ path, method, handlerName }) => {\n const middlewares: RequestHandler[] =\n Reflect.getMetadata(MIDDLEWARE_KEY, instance, handlerName) || [];\n const params: ParamDefinition[] =\n Reflect.getMetadata(PARAMS_KEY, instance, handlerName) || [];\n\n const httpCode: number | undefined = Reflect.getMetadata(\n HTTP_CODE_KEY,\n instance,\n handlerName,\n );\n const headers: Record<string, string> =\n Reflect.getMetadata(HEADER_KEY, instance, handlerName) || {};\n const beforeHooks: Function[] =\n Reflect.getMetadata(BEFORE_KEY, instance, handlerName) || [];\n const afterHooks: Function[] =\n Reflect.getMetadata(AFTER_KEY, instance, handlerName) || [];\n\n const handler: RequestHandler = async (req, res, next) => {\n try {\n for (const fn of beforeHooks) await fn(req, res);\n const args: any[] = [];\n if (params.length) {\n params.forEach(({ index, type, key }) => {\n switch (type) {\n case \"query\":\n args[index] = key ? req.query[key] : req.query;\n break;\n case \"param\":\n args[index] = key ? req.params[key] : req.params;\n break;\n case \"body\":\n args[index] = key ? req.body?.[key] : req.body;\n break;\n case \"req\":\n args[index] = req;\n break;\n case \"res\":\n args[index] = res;\n break;\n }\n });\n }\n const result = (instance as any)[handlerName](...args);\n // Support both sync and async handlers\n const awaited = result instanceof Promise ? await result : result;\n if (!res.headersSent && typeof awaited !== \"undefined\") {\n if (httpCode) res.status?.(httpCode);\n for (const [k, v] of Object.entries(headers)) res.set?.(k, v);\n res.json(awaited);\n }\n for (const fn of afterHooks) await fn(req, res, awaited);\n } catch (err) {\n next(err);\n }\n };\n\n (router as any)[method](basePath + path, ...middlewares, handler);\n });\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"decorators.utils.js","sourceRoot":"","sources":["../../../src/utils/decorators.utils.ts"],"names":[],"mappings":"AAAA,sDAAsD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGtD,OAAO,kBAAkB,CAAC;AAE1B,wCAAwC;AAExC,IAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AACpC,IAAM,cAAc,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AAC7C,IAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AAgBpC,6BAA6B;AAC7B,SAAS,oBAAoB,CAAC,MAAkB;IAC9C,OAAO,UAAC,IAAY;QAClB,OAAO,UAAC,MAAM,EAAE,WAAW,EAAE,UAAU;YACrC,IAAM,MAAM,GAAsB,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;YAC5F,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,MAAA;gBACJ,MAAM,QAAA;gBACN,WAAW,EAAE,WAAqB;aACnC,CAAC,CAAC;YACH,OAAO,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;QACjE,CAAC,CAAC;IAC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,KAAA,SAAY,CAAA;;;4BAAG,KAAA,MAAM,CAAA;;;4BAA3D,OAAO,KAAoD;4BACjE,IAAI,CAAC,GAAG,CAAC,WAAW,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;gCACvD,IAAI,QAAQ;oCAAE,MAAA,GAAG,CAAC,MAAM,oDAAG,QAAQ,CAAC,CAAC;;oCACrC,KAAqB,KAAA,SAAA,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;wCAAjC,KAAA,mBAAM,EAAL,CAAC,QAAA,EAAE,CAAC,QAAA;wCAA8B,MAAA,GAAG,CAAC,GAAG,oDAAG,CAAC,EAAE,CAAC,CAAC,CAAC;qCAAA;;;;;;;;;gCAC9D,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;4BACpB,CAAC;;;;4BACgB,eAAA,SAAA,UAAU,CAAA;;;;4BAAhB,EAAE;4BAAgB,qBAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAA;;4BAA3B,SAA2B,CAAC;;;;;;;;;;;;;;;;;;;4BAEzD,IAAI,CAAC,KAAG,CAAC,CAAC;;;;;iBAEb,CAAC;YAEF,CAAA,KAAC,MAAc,CAAA,CAAC,MAAM,CAAC,wCAAC,QAAQ,GAAG,IAAI,UAAK,WAAW,YAAE,OAAO,WAAE;QACpE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\nimport type { RequestHandler, Router } from 'express';\nimport 'reflect-metadata';\n\n// --- End sample Express interfaces ---\n\nconst ROUTES_KEY = Symbol('routes');\nconst MIDDLEWARE_KEY = Symbol('middlewares');\nconst PARAMS_KEY = Symbol('params');\n\ntype HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'head' | 'trace' | 'connect';\n\ninterface RouteDefinition {\n path: string;\n method: HttpMethod;\n handlerName: string;\n}\n\ninterface ParamDefinition {\n index: number;\n type: 'query' | 'param' | 'body' | 'req' | 'res';\n key?: string;\n}\n\n// ---- Route Decorators ----\nfunction createRouteDecorator(method: HttpMethod) {\n return (path: string): MethodDecorator => {\n return (target, propertyKey, descriptor) => {\n const routes: RouteDefinition[] = Reflect.getMetadata(ROUTES_KEY, target.constructor) || [];\n routes.push({\n path,\n method,\n handlerName: propertyKey as string\n });\n Reflect.defineMetadata(ROUTES_KEY, routes, target.constructor);\n };\n };\n}\n\nexport const Get = createRouteDecorator('get');\nexport const Post = createRouteDecorator('post');\nexport const Put = createRouteDecorator('put');\nexport const Patch = createRouteDecorator('patch');\nexport const Delete = createRouteDecorator('delete');\nexport const Options = createRouteDecorator('options');\nexport const Head = createRouteDecorator('head');\nexport const Trace = createRouteDecorator('trace');\nexport const Connect = createRouteDecorator('connect');\n\n// ---- Controller Decorator ----\nexport function Controller(basePath: string): ClassDecorator {\n return target => {\n Reflect.defineMetadata('basePath', basePath, target);\n };\n}\n\n// ---- Middleware Decorator ----\nexport function Use(...middlewares: RequestHandler[]): MethodDecorator {\n return (target, propertyKey, descriptor) => {\n const existing: RequestHandler[] = Reflect.getMetadata(MIDDLEWARE_KEY, target, propertyKey as string) || [];\n Reflect.defineMetadata(MIDDLEWARE_KEY, [...existing, ...middlewares], target, propertyKey as string);\n };\n}\n\n// ---- Parameter Decorators ----\nfunction createParamDecorator(type: ParamDefinition['type'], key?: string) {\n return (paramKey?: string): ParameterDecorator => {\n return (target, propertyKey, parameterIndex) => {\n const params: ParamDefinition[] = Reflect.getMetadata(PARAMS_KEY, target, propertyKey as string) || [];\n // Ensure parameters are ordered by index\n params.push({ index: parameterIndex, type, key: paramKey || key });\n params.sort((a, b) => a.index - b.index);\n Reflect.defineMetadata(PARAMS_KEY, params, target, propertyKey as string);\n };\n };\n}\n\nexport const Query = createParamDecorator('query');\nexport const Param = createParamDecorator('param');\nexport const Body = createParamDecorator('body');\nexport const Req = createParamDecorator('req');\nexport const Res = createParamDecorator('res');\n\n// Custom HTTP status code decorator\nconst HTTP_CODE_KEY = Symbol('httpCode');\nexport function HttpCode(status: number): MethodDecorator {\n return (target, propertyKey, descriptor) => {\n Reflect.defineMetadata(HTTP_CODE_KEY, status, target, propertyKey as string);\n };\n}\n\n// Custom header decorator\nconst HEADER_KEY = Symbol('headers');\nexport function Header(name: string, value: string): MethodDecorator {\n return (target, propertyKey, descriptor) => {\n const headers: Record<string, string> = Reflect.getMetadata(HEADER_KEY, target, propertyKey as string) || {};\n headers[name] = value;\n Reflect.defineMetadata(HEADER_KEY, headers, target, propertyKey as string);\n };\n}\n\n// Before/After hooks (not Express middleware, but can be used for logging, etc.)\nconst BEFORE_KEY = Symbol('before');\nconst AFTER_KEY = Symbol('after');\nexport function Before(fn: Function): MethodDecorator {\n return (target, propertyKey, descriptor) => {\n const hooks: Function[] = Reflect.getMetadata(BEFORE_KEY, target, propertyKey as string) || [];\n hooks.push(fn);\n Reflect.defineMetadata(BEFORE_KEY, hooks, target, propertyKey as string);\n };\n}\nexport function After(fn: Function): MethodDecorator {\n return (target, propertyKey, descriptor) => {\n const hooks: Function[] = Reflect.getMetadata(AFTER_KEY, target, propertyKey as string) || [];\n hooks.push(fn);\n Reflect.defineMetadata(AFTER_KEY, hooks, target, propertyKey as string);\n };\n}\n\n// ---- Register Controllers ----\nexport function registerControllers(router: Router, controllers: any[]) {\n controllers.forEach(ControllerClass => {\n const instance = new ControllerClass();\n const basePath: string = Reflect.getMetadata('basePath', ControllerClass) || '';\n const routes: RouteDefinition[] = Reflect.getMetadata(ROUTES_KEY, ControllerClass) || [];\n\n routes.forEach(({ path, method, handlerName }) => {\n const middlewares: RequestHandler[] = Reflect.getMetadata(MIDDLEWARE_KEY, instance, handlerName) || [];\n const params: ParamDefinition[] = Reflect.getMetadata(PARAMS_KEY, instance, handlerName) || [];\n\n const httpCode: number | undefined = Reflect.getMetadata(HTTP_CODE_KEY, instance, handlerName);\n const headers: Record<string, string> = Reflect.getMetadata(HEADER_KEY, instance, handlerName) || {};\n const beforeHooks: Function[] = Reflect.getMetadata(BEFORE_KEY, instance, handlerName) || [];\n const afterHooks: Function[] = Reflect.getMetadata(AFTER_KEY, instance, handlerName) || [];\n\n const handler: RequestHandler = async (req, res, next) => {\n try {\n for (const fn of beforeHooks) await fn(req, res);\n const args: any[] = [];\n if (params.length) {\n params.forEach(({ index, type, key }) => {\n switch (type) {\n case 'query':\n args[index] = key ? req.query[key] : req.query;\n break;\n case 'param':\n args[index] = key ? req.params[key] : req.params;\n break;\n case 'body':\n args[index] = key ? req.body?.[key] : req.body;\n break;\n case 'req':\n args[index] = req;\n break;\n case 'res':\n args[index] = res;\n break;\n }\n });\n }\n const result = (instance as any)[handlerName](...args);\n // Support both sync and async handlers\n const awaited = result instanceof Promise ? await result : result;\n if (!res.headersSent && typeof awaited !== 'undefined') {\n if (httpCode) res.status?.(httpCode);\n for (const [k, v] of Object.entries(headers)) res.set?.(k, v);\n res.json(awaited);\n }\n for (const fn of afterHooks) await fn(req, res, awaited);\n } catch (err) {\n next(err);\n }\n };\n\n (router as any)[method](basePath + path, ...middlewares, handler);\n });\n });\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import fs from
|
|
1
|
+
import fs from 'fs';
|
|
2
2
|
/**
|
|
3
3
|
* Ensures that a directory exists, creating parent directories if needed (like `mkdir -p`).
|
|
4
4
|
*
|
|
@@ -72,7 +72,7 @@ export declare function getDirSize(dirPath: string): Promise<number>;
|
|
|
72
72
|
* @param {(eventType: "rename" | "change", filename: string | null) => void} callback - Callback for each change event.
|
|
73
73
|
* @returns {() => void} A function to stop watching the directory.
|
|
74
74
|
*/
|
|
75
|
-
export declare function watchDir(dirPath: string, callback: (eventType:
|
|
75
|
+
export declare function watchDir(dirPath: string, callback: (eventType: 'rename' | 'change', filename: string | null) => void): () => void;
|
|
76
76
|
/**
|
|
77
77
|
* Finds files matching a glob pattern.
|
|
78
78
|
*
|
|
@@ -161,7 +161,7 @@ export declare function findInDir(dirPath: string, predicate: (path: string, sta
|
|
|
161
161
|
* @returns {Promise<() => void>} A function to stop watching the directory.
|
|
162
162
|
* @throws {Error} If directory cannot be watched.
|
|
163
163
|
*/
|
|
164
|
-
export declare function watchDirRecursive(dirPath: string, callback: (eventType:
|
|
164
|
+
export declare function watchDirRecursive(dirPath: string, callback: (eventType: 'rename' | 'change', filename: string) => void, includeSubdirs?: boolean): Promise<() => void>;
|
|
165
165
|
/**
|
|
166
166
|
* Gets detailed directory statistics including file count, directory count, and size.
|
|
167
167
|
*
|
|
@@ -191,6 +191,6 @@ export declare function walkDir(dirPath: string, options: {
|
|
|
191
191
|
isDirectory: boolean;
|
|
192
192
|
stats: fs.Stats;
|
|
193
193
|
}) => boolean | void | Promise<boolean | void>;
|
|
194
|
-
traversalOrder?:
|
|
194
|
+
traversalOrder?: 'pre' | 'post';
|
|
195
195
|
}): Promise<void>;
|
|
196
196
|
//# sourceMappingURL=dir.utils.d.ts.map
|
|
@@ -81,12 +81,12 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
81
81
|
}
|
|
82
82
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
83
83
|
};
|
|
84
|
-
import os from
|
|
85
|
-
import fs from
|
|
86
|
-
import fsp from
|
|
87
|
-
import path from
|
|
88
|
-
import { glob } from
|
|
89
|
-
import { randomBytes } from
|
|
84
|
+
import os from 'os';
|
|
85
|
+
import fs from 'fs';
|
|
86
|
+
import fsp from 'fs/promises';
|
|
87
|
+
import path from 'path';
|
|
88
|
+
import { glob } from 'glob';
|
|
89
|
+
import { randomBytes } from 'crypto';
|
|
90
90
|
/**
|
|
91
91
|
* Ensures that a directory exists, creating parent directories if needed (like `mkdir -p`).
|
|
92
92
|
*
|
|
@@ -449,9 +449,7 @@ export function getSubdirectories(dirPath_1) {
|
|
|
449
449
|
case 0: return [4 /*yield*/, fsp.readdir(dirPath, { withFileTypes: true })];
|
|
450
450
|
case 1:
|
|
451
451
|
entries = _a.sent();
|
|
452
|
-
dirs = entries
|
|
453
|
-
.filter(function (entry) { return entry.isDirectory(); })
|
|
454
|
-
.map(function (entry) { return path.join(dirPath, entry.name); });
|
|
452
|
+
dirs = entries.filter(function (entry) { return entry.isDirectory(); }).map(function (entry) { return path.join(dirPath, entry.name); });
|
|
455
453
|
if (!(recursive && dirs.length > 0)) return [3 /*break*/, 3];
|
|
456
454
|
return [4 /*yield*/, Promise.all(dirs.map(function (dir) { return getSubdirectories(dir, true); }))];
|
|
457
455
|
case 2:
|
|
@@ -490,7 +488,7 @@ export function ensureEmptyDir(dirPath) {
|
|
|
490
488
|
case 5:
|
|
491
489
|
error_1 = _a.sent();
|
|
492
490
|
// Ignore if file doesn't exist
|
|
493
|
-
if (error_1.code !==
|
|
491
|
+
if (error_1.code !== 'ENOENT') {
|
|
494
492
|
throw error_1;
|
|
495
493
|
}
|
|
496
494
|
return [3 /*break*/, 6];
|
|
@@ -521,9 +519,9 @@ export function createTempDir() {
|
|
|
521
519
|
return __generator(this, function (_a) {
|
|
522
520
|
switch (_a.label) {
|
|
523
521
|
case 0:
|
|
524
|
-
prefix = options.prefix ||
|
|
522
|
+
prefix = options.prefix || 'tmp-';
|
|
525
523
|
parentDir = options.parentDir || os.tmpdir();
|
|
526
|
-
dirName = "".concat(prefix).concat(randomBytes(6).toString(
|
|
524
|
+
dirName = "".concat(prefix).concat(randomBytes(6).toString('hex'));
|
|
527
525
|
tempDirPath = path.join(parentDir, dirName);
|
|
528
526
|
return [4 /*yield*/, ensureDir(tempDirPath)];
|
|
529
527
|
case 1:
|
|
@@ -546,7 +544,7 @@ export function createTempDir() {
|
|
|
546
544
|
});
|
|
547
545
|
}); };
|
|
548
546
|
if (options.cleanup) {
|
|
549
|
-
process.once(
|
|
547
|
+
process.once('exit', function () {
|
|
550
548
|
try {
|
|
551
549
|
fs.rmSync(tempDirPath, { recursive: true, force: true });
|
|
552
550
|
}
|
|
@@ -555,7 +553,7 @@ export function createTempDir() {
|
|
|
555
553
|
}
|
|
556
554
|
});
|
|
557
555
|
// Handle signals for better cleanup
|
|
558
|
-
[
|
|
556
|
+
['SIGINT', 'SIGTERM', 'SIGUSR1', 'SIGUSR2'].forEach(function (signal) {
|
|
559
557
|
process.once(signal, function () {
|
|
560
558
|
cleanup().then(function () { return process.exit(); });
|
|
561
559
|
});
|
|
@@ -740,7 +738,7 @@ export function watchDirRecursive(dirPath_1, callback_1) {
|
|
|
740
738
|
var relativePath = path.relative(normalizedBasePath, fullPath);
|
|
741
739
|
callback(eventType, relativePath);
|
|
742
740
|
// If a new directory is created, we should watch it
|
|
743
|
-
if (eventType ===
|
|
741
|
+
if (eventType === 'rename' && includeSubdirs) {
|
|
744
742
|
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
745
743
|
var _a;
|
|
746
744
|
return __generator(this, function (_b) {
|
|
@@ -889,7 +887,7 @@ export function walkDir(dirPath, options) {
|
|
|
889
887
|
return __generator(this, function (_b) {
|
|
890
888
|
switch (_b.label) {
|
|
891
889
|
case 0:
|
|
892
|
-
traversalOrder = options.traversalOrder ||
|
|
890
|
+
traversalOrder = options.traversalOrder || 'pre';
|
|
893
891
|
return [4 /*yield*/, fsp.readdir(dirPath, { withFileTypes: true })];
|
|
894
892
|
case 1:
|
|
895
893
|
entries = _b.sent();
|
|
@@ -909,10 +907,10 @@ export function walkDir(dirPath, options) {
|
|
|
909
907
|
path: entryPath,
|
|
910
908
|
name: entry.name,
|
|
911
909
|
isDirectory: entry.isDirectory(),
|
|
912
|
-
stats: stats
|
|
910
|
+
stats: stats
|
|
913
911
|
};
|
|
914
912
|
if (!entry.isDirectory()) return [3 /*break*/, 12];
|
|
915
|
-
if (!(traversalOrder ===
|
|
913
|
+
if (!(traversalOrder === 'pre')) return [3 /*break*/, 8];
|
|
916
914
|
return [4 /*yield*/, options.visitorFn(entryInfo)];
|
|
917
915
|
case 5:
|
|
918
916
|
shouldContinue = _b.sent();
|
|
@@ -955,7 +953,7 @@ export function walkDir(dirPath, options) {
|
|
|
955
953
|
finally { if (e_8) throw e_8.error; }
|
|
956
954
|
return [7 /*endfinally*/];
|
|
957
955
|
case 18:
|
|
958
|
-
if (!(traversalOrder ===
|
|
956
|
+
if (!(traversalOrder === 'post')) return [3 /*break*/, 21];
|
|
959
957
|
return [4 /*yield*/, fsp.stat(dirPath)];
|
|
960
958
|
case 19:
|
|
961
959
|
stats = _b.sent();
|
|
@@ -963,7 +961,7 @@ export function walkDir(dirPath, options) {
|
|
|
963
961
|
path: dirPath,
|
|
964
962
|
name: path.basename(dirPath),
|
|
965
963
|
isDirectory: true,
|
|
966
|
-
stats: stats
|
|
964
|
+
stats: stats
|
|
967
965
|
};
|
|
968
966
|
return [4 /*yield*/, options.visitorFn(entryInfo)];
|
|
969
967
|
case 20:
|