@cyberskill/shared 3.12.0 → 3.13.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 (180) hide show
  1. package/dist/config/commitlint/index.d.ts +5 -1
  2. package/dist/{src/config → config}/config.type.d.ts +1 -1
  3. package/dist/{src/config → config}/config.util.d.ts +1 -1
  4. package/dist/config/env/index.d.ts +3 -1
  5. package/dist/config/eslint/index.d.ts +1198 -1
  6. package/dist/config/graphql-codegen/index.d.ts +2 -1
  7. package/dist/config/index.d.ts +2 -1
  8. package/dist/config/lint-staged/index.d.ts +5 -1
  9. package/dist/config/storybook/index.d.ts +2 -1
  10. package/dist/config/vitest/index.d.ts +3 -1
  11. package/dist/config/vitest/vitest.e2e.d.ts +20 -1
  12. package/dist/config/vitest/vitest.unit.d.ts +22 -1
  13. package/dist/constant/index.d.ts +5 -1
  14. package/dist/node/apollo-server/index.d.ts +2 -1
  15. package/dist/node/cli/index.d.ts +2 -1
  16. package/dist/node/command/index.d.ts +2 -1
  17. package/dist/node/express/index.d.ts +2 -1
  18. package/dist/node/fs/index.d.ts +2 -1
  19. package/dist/node/log/index.d.ts +2 -1
  20. package/dist/{src/node → node}/log/log.type.d.ts +2 -2
  21. package/dist/{src/node → node}/log/log.util.d.ts +1 -1
  22. package/dist/node/mongo/index.d.ts +6 -1
  23. package/dist/{src/node → node}/mongo/mongo.controller.helpers.d.ts +1 -1
  24. package/dist/{src/node → node}/mongo/mongo.controller.mongoose.d.ts +1 -1
  25. package/dist/{src/node → node}/mongo/mongo.controller.native.d.ts +1 -1
  26. package/dist/{src/node → node}/mongo/mongo.controller.type.d.ts +1 -1
  27. package/dist/node/package/index.d.ts +2 -1
  28. package/dist/{src/node → node}/package/package.util.d.ts +1 -1
  29. package/dist/node/path/index.d.ts +2 -1
  30. package/dist/node/storage/index.d.ts +3 -1
  31. package/dist/node/upload/index.d.ts +3 -1
  32. package/dist/{src/node → node}/upload/upload.util.d.ts +1 -1
  33. package/dist/node/upload/upload.util.js.map +1 -1
  34. package/dist/node/ws/index.d.ts +2 -1
  35. package/dist/{src/react → react}/apollo-client/apollo-client.type.d.ts +1 -1
  36. package/dist/react/apollo-client/index.d.ts +9 -1
  37. package/dist/react/apollo-client/links/index.d.ts +1 -1
  38. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.rsc.d.ts +16 -1
  39. package/dist/react/apollo-client-nextjs/index.d.ts +2 -1
  40. package/dist/react/apollo-error/index.d.ts +6 -1
  41. package/dist/react/i18next/index.d.ts +2 -1
  42. package/dist/react/loading/index.d.ts +5 -1
  43. package/dist/{src/react → react}/loading/loading.provider.d.ts +1 -1
  44. package/dist/react/log/index.d.ts +2 -1
  45. package/dist/react/log/log.type.d.ts +1 -0
  46. package/dist/{src/react → react}/log/log.util.d.ts +1 -1
  47. package/dist/react/next-intl/index.d.ts +6 -1
  48. package/dist/{src/react → react}/next-intl/next-intl.hoc.d.ts +1 -1
  49. package/dist/{src/react → react}/next-intl/next-intl.type.d.ts +1 -1
  50. package/dist/react/storage/index.d.ts +2 -1
  51. package/dist/{src/react → react}/storage/storage.hook.d.ts +1 -1
  52. package/dist/react/toast/index.d.ts +1 -1
  53. package/dist/react/userback/index.d.ts +2 -1
  54. package/dist/typescript/index.d.ts +5 -1
  55. package/dist/util/common/index.d.ts +5 -1
  56. package/dist/util/index.d.ts +9 -1
  57. package/dist/util/log/index.d.ts +2 -1
  58. package/dist/{src/util → util}/log/log.util.d.ts +1 -1
  59. package/dist/util/object/index.d.ts +4 -1
  60. package/dist/util/serializer/index.d.ts +2 -1
  61. package/dist/util/string/index.d.ts +5 -1
  62. package/dist/util/validate/index.d.ts +4 -1
  63. package/package.json +1 -1
  64. package/dist/src/config/commitlint/index.d.ts +0 -5
  65. package/dist/src/config/env/index.d.ts +0 -3
  66. package/dist/src/config/eslint/index.d.ts +0 -1198
  67. package/dist/src/config/graphql-codegen/index.d.ts +0 -2
  68. package/dist/src/config/index.d.ts +0 -2
  69. package/dist/src/config/lint-staged/index.d.ts +0 -5
  70. package/dist/src/config/storybook/index.d.ts +0 -2
  71. package/dist/src/config/vitest/index.d.ts +0 -3
  72. package/dist/src/config/vitest/vitest.e2e.d.ts +0 -20
  73. package/dist/src/config/vitest/vitest.unit.d.ts +0 -22
  74. package/dist/src/constant/index.d.ts +0 -5
  75. package/dist/src/node/apollo-server/index.d.ts +0 -2
  76. package/dist/src/node/cli/index.d.ts +0 -2
  77. package/dist/src/node/command/index.d.ts +0 -2
  78. package/dist/src/node/express/index.d.ts +0 -2
  79. package/dist/src/node/fs/index.d.ts +0 -2
  80. package/dist/src/node/log/index.d.ts +0 -2
  81. package/dist/src/node/mongo/index.d.ts +0 -6
  82. package/dist/src/node/package/index.d.ts +0 -2
  83. package/dist/src/node/path/index.d.ts +0 -2
  84. package/dist/src/node/storage/index.d.ts +0 -3
  85. package/dist/src/node/upload/index.d.ts +0 -3
  86. package/dist/src/node/ws/index.d.ts +0 -2
  87. package/dist/src/react/apollo-client/index.d.ts +0 -9
  88. package/dist/src/react/apollo-client/links/index.d.ts +0 -1
  89. package/dist/src/react/apollo-client-nextjs/apollo-client-nextjs.rsc.d.ts +0 -16
  90. package/dist/src/react/apollo-client-nextjs/index.d.ts +0 -2
  91. package/dist/src/react/apollo-error/index.d.ts +0 -6
  92. package/dist/src/react/i18next/index.d.ts +0 -2
  93. package/dist/src/react/loading/index.d.ts +0 -5
  94. package/dist/src/react/log/index.d.ts +0 -2
  95. package/dist/src/react/log/log.type.d.ts +0 -1
  96. package/dist/src/react/next-intl/index.d.ts +0 -6
  97. package/dist/src/react/storage/index.d.ts +0 -2
  98. package/dist/src/react/toast/index.d.ts +0 -1
  99. package/dist/src/react/userback/index.d.ts +0 -2
  100. package/dist/src/typescript/index.d.ts +0 -5
  101. package/dist/src/util/common/index.d.ts +0 -5
  102. package/dist/src/util/index.d.ts +0 -9
  103. package/dist/src/util/log/index.d.ts +0 -2
  104. package/dist/src/util/object/index.d.ts +0 -4
  105. package/dist/src/util/serializer/index.d.ts +0 -2
  106. package/dist/src/util/string/index.d.ts +0 -5
  107. package/dist/src/util/validate/index.d.ts +0 -4
  108. /package/dist/{src/config → config}/env/env.constant.d.ts +0 -0
  109. /package/dist/{src/config → config}/env/env.type.d.ts +0 -0
  110. /package/dist/{src/config → config}/env/env.util.d.ts +0 -0
  111. /package/dist/{src/config → config}/graphql-codegen/graphql-codegen.type.d.ts +0 -0
  112. /package/dist/{src/config → config}/graphql-codegen/graphql-codegen.util.d.ts +0 -0
  113. /package/dist/{src/config → config}/storybook/storybook.main.d.ts +0 -0
  114. /package/dist/{src/config → config}/storybook/storybook.preview.d.ts +0 -0
  115. /package/dist/{src/config → config}/vitest/vitest.unit.setup.d.ts +0 -0
  116. /package/dist/{src/constant → constant}/common.d.ts +0 -0
  117. /package/dist/{src/constant → constant}/response-status.d.ts +0 -0
  118. /package/dist/{src/node → node}/apollo-server/apollo-server.type.d.ts +0 -0
  119. /package/dist/{src/node → node}/apollo-server/apollo-server.util.d.ts +0 -0
  120. /package/dist/{src/node → node}/command/command.type.d.ts +0 -0
  121. /package/dist/{src/node → node}/command/command.util.d.ts +0 -0
  122. /package/dist/{src/node → node}/express/express.type.d.ts +0 -0
  123. /package/dist/{src/node → node}/express/express.util.d.ts +0 -0
  124. /package/dist/{src/node → node}/fs/fs.type.d.ts +0 -0
  125. /package/dist/{src/node → node}/fs/fs.util.d.ts +0 -0
  126. /package/dist/{src/node → node}/mongo/mongo.constant.d.ts +0 -0
  127. /package/dist/{src/node → node}/mongo/mongo.controller.d.ts +0 -0
  128. /package/dist/{src/node → node}/mongo/mongo.dynamic-populate.d.ts +0 -0
  129. /package/dist/{src/node → node}/mongo/mongo.internal-types.d.ts +0 -0
  130. /package/dist/{src/node → node}/mongo/mongo.populate.d.ts +0 -0
  131. /package/dist/{src/node → node}/mongo/mongo.type.d.ts +0 -0
  132. /package/dist/{src/node → node}/mongo/mongo.util.d.ts +0 -0
  133. /package/dist/{src/node → node}/package/package.type.d.ts +0 -0
  134. /package/dist/{src/node → node}/path/path.constant.d.ts +0 -0
  135. /package/dist/{src/node → node}/path/path.util.d.ts +0 -0
  136. /package/dist/{src/node → node}/storage/storage.constant.d.ts +0 -0
  137. /package/dist/{src/node → node}/storage/storage.type.d.ts +0 -0
  138. /package/dist/{src/node → node}/storage/storage.util.d.ts +0 -0
  139. /package/dist/{src/node → node}/upload/upload.constant.d.ts +0 -0
  140. /package/dist/{src/node → node}/upload/upload.type.d.ts +0 -0
  141. /package/dist/{src/node → node}/ws/ws.type.d.ts +0 -0
  142. /package/dist/{src/node → node}/ws/ws.util.d.ts +0 -0
  143. /package/dist/{src/react → react}/apollo-client/apollo-client.component.d.ts +0 -0
  144. /package/dist/{src/react → react}/apollo-client/apollo-client.constant.d.ts +0 -0
  145. /package/dist/{src/react → react}/apollo-client/apollo-client.context.d.ts +0 -0
  146. /package/dist/{src/react → react}/apollo-client/apollo-client.hook.d.ts +0 -0
  147. /package/dist/{src/react → react}/apollo-client/apollo-client.util.d.ts +0 -0
  148. /package/dist/{src/react → react}/apollo-client/links/upload.d.ts +0 -0
  149. /package/dist/{src/react → react}/apollo-client-nextjs/apollo-client-nextjs.component.d.ts +0 -0
  150. /package/dist/{src/react → react}/apollo-client-nextjs/apollo-client-nextjs.util.d.ts +0 -0
  151. /package/dist/{src/react → react}/apollo-error/apollo-error.component.d.ts +0 -0
  152. /package/dist/{src/react → react}/apollo-error/apollo-error.context.d.ts +0 -0
  153. /package/dist/{src/react → react}/apollo-error/apollo-error.hook.d.ts +0 -0
  154. /package/dist/{src/react → react}/apollo-error/apollo-error.provider.d.ts +0 -0
  155. /package/dist/{src/react → react}/apollo-error/apollo-error.type.d.ts +0 -0
  156. /package/dist/{src/react → react}/apollo-error/apollo-error.util.d.ts +0 -0
  157. /package/dist/{src/react → react}/i18next/i18next.hook.d.ts +0 -0
  158. /package/dist/{src/react → react}/i18next/i18next.util.d.ts +0 -0
  159. /package/dist/{src/react → react}/loading/loading.component.d.ts +0 -0
  160. /package/dist/{src/react → react}/loading/loading.context.d.ts +0 -0
  161. /package/dist/{src/react → react}/loading/loading.hook.d.ts +0 -0
  162. /package/dist/{src/react → react}/loading/loading.type.d.ts +0 -0
  163. /package/dist/{src/react → react}/next-intl/next-intl.constant.d.ts +0 -0
  164. /package/dist/{src/react → react}/next-intl/next-intl.context.d.ts +0 -0
  165. /package/dist/{src/react → react}/next-intl/next-intl.hook.d.ts +0 -0
  166. /package/dist/{src/react → react}/next-intl/next-intl.provider.d.ts +0 -0
  167. /package/dist/{src/react → react}/storage/storage.util.d.ts +0 -0
  168. /package/dist/{src/react → react}/userback/userback.component.d.ts +0 -0
  169. /package/dist/{src/react → react}/userback/userback.type.d.ts +0 -0
  170. /package/dist/{src/typescript → typescript}/common.type.d.ts +0 -0
  171. /package/dist/{src/typescript → typescript}/react.type.d.ts +0 -0
  172. /package/dist/{src/util → util}/common/common.type.d.ts +0 -0
  173. /package/dist/{src/util → util}/common/common.util.d.ts +0 -0
  174. /package/dist/{src/util → util}/log/log.type.d.ts +0 -0
  175. /package/dist/{src/util → util}/object/object.util.d.ts +0 -0
  176. /package/dist/{src/util → util}/serializer/serializer.type.d.ts +0 -0
  177. /package/dist/{src/util → util}/serializer/serializer.util.d.ts +0 -0
  178. /package/dist/{src/util → util}/string/string.type.d.ts +0 -0
  179. /package/dist/{src/util → util}/string/string.util.d.ts +0 -0
  180. /package/dist/{src/util → util}/validate/validate.util.d.ts +0 -0
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './graphql-codegen.type.js';
2
+ export * from './graphql-codegen.util.js';
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './config.type.js';
2
+ export * from './config.util.js';
@@ -1 +1,5 @@
1
- export {}
1
+ declare const _default: {
2
+ '*.ts': () => string;
3
+ '*': string[];
4
+ };
5
+ export default _default;
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './storybook.main.js';
2
+ export * from './storybook.preview.js';
@@ -1 +1,3 @@
1
- export {}
1
+ export * from './vitest.e2e.js';
2
+ export * from './vitest.unit.js';
3
+ export * from './vitest.unit.setup.js';
@@ -1 +1,20 @@
1
- export {}
1
+ import { UserConfig } from 'vite';
2
+ /**
3
+ * Creates a Vitest configuration for end-to-end testing with browser automation.
4
+ * This function generates a Vitest configuration specifically designed for E2E testing
5
+ * using Playwright with multiple browser instances. It includes React support and
6
+ * browser automation capabilities for comprehensive end-to-end testing.
7
+ *
8
+ * The configuration includes:
9
+ * - React SWC plugin for fast React compilation
10
+ * - Browser automation with Playwright provider
11
+ * - Multiple browser instances (Chromium, Firefox, WebKit)
12
+ * - E2E test file pattern matching
13
+ * - Configurable options merging
14
+ *
15
+ * @param options - Additional Vite configuration options to merge with the E2E config.
16
+ * @returns A Vitest configuration object optimized for end-to-end testing with browser automation.
17
+ */
18
+ export declare function vitestE2E(options: UserConfig): UserConfig;
19
+ declare const _default: UserConfig;
20
+ export default _default;
@@ -1 +1,22 @@
1
- export {}
1
+ import { UserConfig } from 'vite';
2
+ /**
3
+ * Creates a Vitest configuration for unit testing with React support.
4
+ * This function generates a Vitest configuration specifically designed for unit testing
5
+ * React components and JavaScript/TypeScript modules. It includes JSDOM environment
6
+ * for DOM simulation and comprehensive testing setup.
7
+ *
8
+ * The configuration includes:
9
+ * - React SWC plugin for fast React compilation
10
+ * - JSDOM environment for DOM simulation
11
+ * - Global test functions availability
12
+ * - VM threads pool for parallel test execution
13
+ * - Unit test file pattern matching
14
+ * - Setup files for testing library configuration
15
+ * - Configurable options merging
16
+ *
17
+ * @param options - Additional Vite configuration options to merge with the unit test config.
18
+ * @returns A Vitest configuration object optimized for unit testing with React and DOM support.
19
+ */
20
+ export declare function vitestUnit(options: UserConfig): UserConfig;
21
+ declare const _default: UserConfig;
22
+ export default _default;
@@ -1 +1,5 @@
1
- export {}
1
+ /**
2
+ * Re-exports all common constants for shared usage across the codebase.
3
+ */
4
+ export * from './common.js';
5
+ export * from './response-status.js';
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './apollo-server.type.js';
2
+ export * from './apollo-server.util.js';
@@ -1 +1,2 @@
1
- export {}
1
+ #!/usr/bin/env node
2
+ export {};
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './command.type.js';
2
+ export * from './command.util.js';
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './express.type.js';
2
+ export * from './express.util.js';
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './fs.type.js';
2
+ export * from './fs.util.js';
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './log.type.js';
2
+ export * from './log.util.js';
@@ -1,5 +1,5 @@
1
- import { I_Log as I_LogCommon } from '../../../typescript/index.js';
2
- export type { I_CatchErrorOptions } from '../../../util/log/index.js';
1
+ import { I_Log as I_LogCommon } from '../../typescript/index.js';
2
+ export type { I_CatchErrorOptions } from '../../util/log/index.js';
3
3
  /**
4
4
  * Enum representing the type of issues for logging and error handling.
5
5
  * - Error: Represents an error issue.
@@ -1,4 +1,4 @@
1
- import { I_Return } from '../../../typescript/index.js';
1
+ import { I_Return } from '../../typescript/index.js';
2
2
  import { I_CatchErrorOptions, I_Log, I_ThrowError } from './log.type.js';
3
3
  /**
4
4
  * Throws a standardized error with optional status information and type specification.
@@ -1 +1,6 @@
1
- export {}
1
+ export * from './mongo.constant.js';
2
+ export * from './mongo.controller.js';
3
+ export * from './mongo.dynamic-populate.js';
4
+ export * from './mongo.populate.js';
5
+ export * from './mongo.type.js';
6
+ export * from './mongo.util.js';
@@ -1,4 +1,4 @@
1
- import { I_Return } from '../../../typescript/index.js';
1
+ import { I_Return } from '../../typescript/index.js';
2
2
  /**
3
3
  * Shared helper functions for MongoDB controllers.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { I_Return } from '../../../typescript/index.js';
1
+ import { I_Return } from '../../typescript/index.js';
2
2
  import { C_Document, I_DeleteOptionsExtended, I_ExtendedModel, I_Input_CheckSlug, I_Input_CreateSlug, I_Input_GenerateSlug, I_PaginateOptionsWithPopulate, I_UpdateOptionsExtended, T_AggregatePaginateResult, T_DeleteResult, T_Input_Populate, T_InsertManyOptions, T_PaginateResult, T_PipelineStage, T_ProjectionType, T_QueryFilter, T_QueryOptions, T_UpdateQuery, T_UpdateResult } from './mongo.type.js';
3
3
  /**
4
4
  * Mongoose controller for database operations with advanced features.
@@ -1,4 +1,4 @@
1
- import { I_Return } from '../../../typescript/index.js';
1
+ import { I_Return } from '../../typescript/index.js';
2
2
  import { C_Db, C_Document, T_DeleteResult, T_Filter, T_UpdateResult, T_WithId } from './mongo.type.js';
3
3
  /**
4
4
  * MongoDB native driver controller for direct database operations.
@@ -1,4 +1,4 @@
1
- import { I_Return } from '../../../typescript/index.js';
1
+ import { I_Return } from '../../typescript/index.js';
2
2
  import { T_DeleteResult, T_UpdateResult, T_WithId } from './mongo.type.js';
3
3
  /**
4
4
  * Shared controller interface for MongoDB operations.
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './package.type.js';
2
+ export * from './package.util.js';
@@ -1,4 +1,4 @@
1
- import { I_Return } from '../../../typescript/index.js';
1
+ import { I_Return } from '../../typescript/index.js';
2
2
  import { I_PackageInfo, I_PackageInput } from './package.type.js';
3
3
  /**
4
4
  * Fetches the latest version of a package from the npm registry.
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './path.constant.js';
2
+ export * from './path.util.js';
@@ -1 +1,3 @@
1
- export {}
1
+ export * from './storage.constant.js';
2
+ export * from './storage.type.js';
3
+ export * from './storage.util.js';
@@ -1 +1,3 @@
1
- export {}
1
+ export * from './upload.constant.js';
2
+ export * from './upload.type.js';
3
+ export * from './upload.util.js';
@@ -1,5 +1,5 @@
1
1
  import { ReadableStream } from 'node:stream/web';
2
- import { I_Return } from '../../../typescript/index.js';
2
+ import { I_Return } from '../../typescript/index.js';
3
3
  import { I_UploadConfig, I_UploadFile, I_UploadFileData, I_UploadOptions, I_UploadValidationConfig, E_UploadType } from './upload.type.js';
4
4
  /**
5
5
  * Calculates the size of a file from a readable stream.
@@ -1 +1 @@
1
- {"version":3,"file":"upload.util.js","names":[],"sources":["../../../src/node/upload/upload.util.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\nimport nodePath from 'node:path';\nimport { Transform } from 'node:stream';\nimport { ReadableStream } from 'node:stream/web';\n\nimport type { I_Return } from '#typescript/index.js';\n\nimport { RESPONSE_STATUS } from '#constant/index.js';\n\nimport type { I_UploadConfig, I_UploadFile, I_UploadFileData, I_UploadOptions, I_UploadTypeConfig, I_UploadValidationConfig } from './upload.type.js';\n\nimport { createWriteStream, mkdirSync, pathExistsSync } from '../fs/index.js';\nimport { dirname } from '../path/index.js';\nimport { BYTES_PER_MB, DEFAULT_UPLOAD_CONFIG } from './upload.constant.js';\nimport { E_UploadType } from './upload.type.js';\n\n/**\n * Calculates the size of a file from a readable stream.\n * This function reads through the entire stream to determine the total byte size\n * by accumulating the length of each data chunk.\n *\n * @param stream - The readable stream to calculate the size for.\n * @returns A promise that resolves to the total size of the stream in bytes.\n */\nexport async function getFileSizeFromStream(stream: NodeJS.ReadableStream): Promise<number> {\n return new Promise((resolve, reject) => {\n let size = 0;\n stream.on('data', (chunk) => {\n size += chunk.length;\n });\n stream.on('end', () => resolve(size));\n stream.on('error', reject);\n });\n}\n\n/**\n * Extracts and validates file data from an upload file.\n * This function processes upload files by:\n * - Extracting file metadata and creating a readable stream\n * - Calculating the file size from the stream\n * - Validating file size and extension against upload configuration\n * - Returning a standardized response with success status and error codes\n * - Providing validated file data for further processing\n *\n * @param type - The type of upload being processed (IMAGE, VIDEO, DOCUMENT, OTHER).\n * @param file - The upload file object containing file metadata and stream creation method.\n * @param config - Optional upload configuration. If not provided, uses default configuration.\n * @returns A promise that resolves to a standardized response containing validated file data or error information.\n */\nexport async function getAndValidateFile(type: E_UploadType, file: I_UploadFile, config?: I_UploadConfig): Promise<I_Return<I_UploadFileData>> {\n const fileData = await (await file).file;\n const stream = fileData.createReadStream();\n // Stream is consumed here for validation; callers use createReadStream() again for the actual write.\n // This is intentional — createReadStream() is a factory that yields a new stream per call.\n const fileSize = await getFileSizeFromStream(stream);\n const uploadConfig = config ?? createUploadConfig();\n\n const validationResult = validateUpload(\n { filename: fileData.filename, fileSize },\n uploadConfig,\n type,\n );\n\n if (!validationResult.isValid) {\n return {\n success: false,\n message: validationResult.error || 'File validation failed',\n code: RESPONSE_STATUS.BAD_REQUEST.CODE,\n };\n }\n\n return {\n success: true,\n result: fileData,\n message: 'File validated successfully',\n };\n}\n\n/**\n * Creates a validated web-readable stream from an upload file with size validation.\n * This function processes file uploads for web environments by:\n * - Validating file data using getAndValidateFile function\n * - Creating a size validation transform stream to monitor upload progress\n * - Returning a web-compatible ReadableStream with real-time validation\n * - Providing standardized error responses for validation failures\n * - Wrapping the stream in a standardized response format\n *\n * @param type - The type of upload being processed (IMAGE, VIDEO, DOCUMENT, OTHER).\n * @param file - The upload file object containing file metadata and stream creation method.\n * @param config - Optional upload configuration. If not provided, uses default configuration.\n * @returns A promise that resolves to a standardized response containing either a web ReadableStream or error information.\n */\nexport async function getFileWebStream(type: E_UploadType, file: I_UploadFile, config?: I_UploadConfig): Promise<I_Return<ReadableStream<Uint8Array>>> {\n const uploadConfig = config ?? createUploadConfig();\n const typeConfig = uploadConfig[type];\n\n const fileData = await getAndValidateFile(type, file, config);\n\n if (!fileData.success) {\n return fileData;\n }\n\n const { createReadStream } = fileData.result;\n\n let remainingBytes = typeConfig.sizeLimit;\n\n const sizeValidationStream = new Transform({\n transform(chunk: Buffer, _enc: BufferEncoding, cb) {\n remainingBytes -= chunk.length;\n\n if (remainingBytes < 0) {\n cb(new Error(`File size exceeds limit of ${typeConfig.sizeLimit / BYTES_PER_MB}MB`));\n }\n else {\n cb(null, chunk);\n }\n },\n });\n const originalStream = createReadStream();\n const validatedStream = originalStream.pipe(sizeValidationStream);\n\n return {\n success: true,\n result: new ReadableStream<Uint8Array>({\n start(controller) {\n validatedStream.on('data', (chunk: Buffer | string) => {\n controller.enqueue(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);\n });\n validatedStream.on('end', () => controller.close());\n validatedStream.on('error', (err: unknown) => controller.error(err));\n },\n }),\n };\n}\n\n/**\n * Validates if a file has an allowed extension.\n * This function extracts the file extension from the filename and checks if it's\n * included in the list of allowed extensions (case-insensitive comparison).\n *\n * @param filename - The filename to check for valid extension.\n * @param allowedExtensions - An array of allowed file extensions (without dots).\n * @returns True if the file extension is allowed, false otherwise.\n */\nexport function validateFileExtension(filename: string, allowedExtensions: string[]): boolean {\n const lastDotIndex = filename.lastIndexOf('.');\n\n if (lastDotIndex === -1) {\n return false;\n }\n\n const extension = filename.substring(lastDotIndex + 1).toLowerCase();\n\n return allowedExtensions.includes(extension);\n}\n\n/**\n * Validates an upload against the specified configuration.\n * This function performs comprehensive validation including:\n * - File extension validation against allowed extensions\n * - File size validation against size limits\n * - Returns detailed error messages for validation failures\n *\n * @param config - The validation configuration including filename and optional file size.\n * @param uploadConfig - The upload configuration containing allowed extensions and size limits.\n * @param uploadType - The type of upload being validated.\n * @returns An object indicating validation success and optional error message.\n */\nexport function validateUpload(\n config: I_UploadValidationConfig,\n uploadConfig: I_UploadConfig,\n uploadType: E_UploadType,\n): { isValid: boolean; error?: string } {\n const { filename, fileSize } = config;\n const typeConfig: I_UploadTypeConfig = uploadConfig[uploadType];\n\n const { allowedExtensions, sizeLimit } = typeConfig;\n\n if (!validateFileExtension(filename, allowedExtensions)) {\n return {\n isValid: false,\n error: `File extension not allowed for ${uploadType.toLowerCase()} files. Allowed extensions: ${allowedExtensions.join(', ')}`,\n };\n }\n\n if (fileSize !== undefined && fileSize > sizeLimit) {\n const maxSizeMB = Math.round(sizeLimit / (1024 * 1024));\n\n return {\n isValid: false,\n error: `File size exceeds limit for ${uploadType.toLowerCase()} files. Maximum size: ${maxSizeMB}MB`,\n };\n }\n\n return { isValid: true };\n}\n\n/**\n * Creates a default upload configuration with predefined settings for different file types.\n * This function provides sensible defaults for image, video, document, and other file types,\n * including allowed extensions and size limits. The configuration can be customized with overrides.\n *\n * @param overrides - Optional configuration overrides to merge with the default configuration.\n * @returns A complete upload configuration object with defaults and any provided overrides.\n */\nexport function createUploadConfig(overrides?: Partial<I_UploadConfig>): I_UploadConfig {\n return { ...DEFAULT_UPLOAD_CONFIG, ...overrides };\n}\n\n/**\n * Uploads a file with comprehensive validation and error handling.\n * This function processes file uploads with the following features:\n * - Input validation for path and file parameters\n * - Configuration validation for all upload types\n * - File validation using getAndValidateFile function\n * - Automatic directory creation\n * - Stream-based file writing\n * - Comprehensive error handling with standardized response codes\n *\n * @param options - Upload configuration including file, path, type, and optional validation config.\n * @returns A promise that resolves to a standardized response with success status, message, file path, and response codes.\n */\nexport async function upload(options: I_UploadOptions): Promise<I_Return<string>> {\n const { path, file, config, type, baseDir } = options;\n\n if (!path || typeof path !== 'string') {\n return {\n success: false,\n message: 'Invalid path provided',\n code: RESPONSE_STATUS.BAD_REQUEST.CODE,\n };\n }\n\n // Security: Validate path is within allowed base directory to prevent path traversal.\n // When baseDir is provided, the resolved path must start with it.\n // When baseDir is not provided, reject any path containing \"..\" segments.\n const resolvedPath = nodePath.resolve(path);\n\n if (baseDir) {\n const resolvedBase = nodePath.resolve(baseDir) + nodePath.sep;\n if (!resolvedPath.startsWith(resolvedBase) && resolvedPath !== nodePath.resolve(baseDir)) {\n return {\n success: false,\n message: 'Path traversal detected: path resolves outside the allowed base directory',\n code: RESPONSE_STATUS.BAD_REQUEST.CODE,\n };\n }\n }\n else if (path.includes('..')) {\n return {\n success: false,\n message: 'Path traversal detected: \"..\" segments are not allowed',\n code: RESPONSE_STATUS.BAD_REQUEST.CODE,\n };\n }\n\n if (!file || typeof file !== 'object') {\n return {\n success: false,\n message: 'Invalid file provided',\n code: RESPONSE_STATUS.BAD_REQUEST.CODE,\n };\n }\n\n if (config) {\n const requiredTypes = [E_UploadType.IMAGE, E_UploadType.VIDEO, E_UploadType.DOCUMENT, E_UploadType.OTHER];\n\n for (const requiredType of requiredTypes) {\n if (!config[requiredType] || !Array.isArray(config[requiredType].allowedExtensions) || config[requiredType].allowedExtensions.length === 0) {\n return {\n success: false,\n message: `Invalid config for ${requiredType.toLowerCase()} files`,\n code: RESPONSE_STATUS.BAD_REQUEST.CODE,\n };\n }\n if (typeof config[requiredType].sizeLimit !== 'number' || config[requiredType].sizeLimit <= 0) {\n return {\n success: false,\n message: `Invalid size limit for ${requiredType.toLowerCase()} files`,\n code: RESPONSE_STATUS.BAD_REQUEST.CODE,\n };\n }\n }\n }\n\n try {\n const fileData = await getAndValidateFile(type, await file, config);\n\n if (!fileData.success) {\n return fileData;\n }\n\n const { createReadStream } = fileData.result;\n\n const dir = dirname(path);\n\n if (!pathExistsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n\n const writeStream = createReadStream();\n const out = createWriteStream(path);\n writeStream.pipe(out);\n\n await new Promise<void>((resolve, reject) => {\n out.on('finish', () => resolve());\n out.on('error', reject);\n writeStream.on('error', reject);\n });\n\n return {\n success: true,\n result: path,\n message: 'File uploaded successfully',\n code: RESPONSE_STATUS.OK.CODE,\n };\n }\n catch (error) {\n return {\n success: false,\n message: error instanceof Error ? error.message : 'File upload failed',\n code: RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE,\n };\n }\n}\n"],"mappings":";;;;;;;;;;AAwBA,eAAsB,EAAsB,GAAgD;AACxF,QAAO,IAAI,SAAS,GAAS,MAAW;EACpC,IAAI,IAAO;AAKX,EAJA,EAAO,GAAG,SAAS,MAAU;AACzB,QAAQ,EAAM;IAChB,EACF,EAAO,GAAG,aAAa,EAAQ,EAAK,CAAC,EACrC,EAAO,GAAG,SAAS,EAAO;GAC5B;;AAiBN,eAAsB,EAAmB,GAAoB,GAAoB,GAA8D;CAC3I,IAAM,IAAW,OAAO,MAAM,GAAM,MAI9B,IAAW,MAAM,EAHR,EAAS,kBAAkB,CAGU,EAC9C,IAAe,KAAU,GAAoB,EAE7C,IAAmB,EACrB;EAAE,UAAU,EAAS;EAAU;EAAU,EACzC,GACA,EACH;AAUD,QARK,EAAiB,UAQf;EACH,SAAS;EACT,QAAQ;EACR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gB,YAAY;IACrC;AAEL,OAAI,OAAO,EAAO,GAAc,aAAc,YAAY,EAAO,GAAc,aAAa,EACxF,QAAO;IACH,SAAS;IACT,SAAS,0BAA0B,EAAa,aAAa,CAAC;IAC9D,MAAM,EAAgB,YAAY;IACrC;;;AAKb,KAAI;EACA,IAAM,IAAW,MAAM,EAAmB,GAAM,MAAM,GAAM,EAAO;AAEnE,MAAI,CAAC,EAAS,QACV,QAAO;EAGX,IAAM,EAAE,wBAAqB,EAAS,QAEhC,IAAM,EAAQ,EAAK;AAEzB,EAAK,EAAe,EAAI,IACpB,EAAU,GAAK,EAAE,WAAW,IAAM,CAAC;EAGvC,IAAM,IAAc,GAAkB,EAChC,IAAM,EAAkB,EAAK;AASnC,SARA,EAAY,KAAK,EAAI,EAErB,MAAM,IAAI,SAAe,GAAS,MAAW;AAGzC,GAFA,EAAI,GAAG,gBAAgB,GAAS,CAAC,EACjC,EAAI,GAAG,SAAS,EAAO,EACvB,EAAY,GAAG,SAAS,EAAO;IACjC,EAEK;GACH,SAAS;GACT,QAAQ;GACR,SAAS;GACT,MAAM,EAAgB,GAAG;GAC5B;UAEE,GAAO;AACV,SAAO;GACH,SAAS;GACT,SAAS,aAAiB,QAAQ,EAAM,UAAU;GAClD,MAAM,EAAgB,sBAAsB;GAC/C"}
1
+ {"version":3,"file":"upload.util.js","names":[],"sources":["../../../src/node/upload/upload.util.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\nimport nodePath from 'node:path';\nimport { Transform } from 'node:stream';\nimport { ReadableStream } from 'node:stream/web';\n\nimport type { I_Return } from '#typescript/index.js';\n\nimport { RESPONSE_STATUS } from '#constant/index.js';\n\nimport type { I_UploadConfig, I_UploadFile, I_UploadFileData, I_UploadOptions, I_UploadTypeConfig, I_UploadValidationConfig } from './upload.type.js';\n\nimport { createWriteStream, mkdirSync, pathExistsSync } from '../fs/index.js';\nimport { dirname } from '../path/index.js';\nimport { BYTES_PER_MB, DEFAULT_UPLOAD_CONFIG } from './upload.constant.js';\nimport { E_UploadType } from './upload.type.js';\n\n/**\n * Calculates the size of a file from a readable stream.\n * This function reads through the entire stream to determine the total byte size\n * by accumulating the length of each data chunk.\n *\n * @param stream - The readable stream to calculate the size for.\n * @returns A promise that resolves to the total size of the stream in bytes.\n */\nexport async function getFileSizeFromStream(stream: NodeJS.ReadableStream): Promise<number> {\n return new Promise((resolve, reject) => {\n let size = 0;\n stream.on('data', (chunk) => {\n size += chunk.length;\n });\n stream.on('end', () => resolve(size));\n stream.on('error', reject);\n });\n}\n\n/**\n * Extracts and validates file data from an upload file.\n * This function processes upload files by:\n * - Extracting file metadata and creating a readable stream\n * - Calculating the file size from the stream\n * - Validating file size and extension against upload configuration\n * - Returning a standardized response with success status and error codes\n * - Providing validated file data for further processing\n *\n * @param type - The type of upload being processed (IMAGE, VIDEO, DOCUMENT, OTHER).\n * @param file - The upload file object containing file metadata and stream creation method.\n * @param config - Optional upload configuration. If not provided, uses default configuration.\n * @returns A promise that resolves to a standardized response containing validated file data or error information.\n */\nexport async function getAndValidateFile(type: E_UploadType, file: I_UploadFile, config?: I_UploadConfig): Promise<I_Return<I_UploadFileData>> {\n const fileData = await (await file).file;\n const stream = fileData.createReadStream();\n // Stream is consumed here for validation; callers use createReadStream() again for the actual write.\n // This is intentional — createReadStream() is a factory that yields a new stream per call.\n const fileSize = await getFileSizeFromStream(stream);\n const uploadConfig = config ?? createUploadConfig();\n\n const validationResult = validateUpload(\n { filename: fileData.filename, fileSize },\n uploadConfig,\n type,\n );\n\n if (!validationResult.isValid) {\n return {\n success: false,\n message: validationResult.error || 'File validation failed',\n code: RESPONSE_STATUS.BAD_REQUEST.CODE,\n };\n }\n\n return {\n success: true,\n result: fileData,\n message: 'File validated successfully',\n };\n}\n\n/**\n * Creates a validated web-readable stream from an upload file with size validation.\n * This function processes file uploads for web environments by:\n * - Validating file data using getAndValidateFile function\n * - Creating a size validation transform stream to monitor upload progress\n * - Returning a web-compatible ReadableStream with real-time validation\n * - Providing standardized error responses for validation failures\n * - Wrapping the stream in a standardized response format\n *\n * @param type - The type of upload being processed (IMAGE, VIDEO, DOCUMENT, OTHER).\n * @param file - The upload file object containing file metadata and stream creation method.\n * @param config - Optional upload configuration. If not provided, uses default configuration.\n * @returns A promise that resolves to a standardized response containing either a web ReadableStream or error information.\n */\nexport async function getFileWebStream(type: E_UploadType, file: I_UploadFile, config?: I_UploadConfig): Promise<I_Return<ReadableStream<Uint8Array>>> {\n const uploadConfig = config ?? createUploadConfig();\n const typeConfig = uploadConfig[type];\n\n const fileData = await getAndValidateFile(type, file, config);\n\n if (!fileData.success) {\n return fileData;\n }\n\n const { createReadStream } = fileData.result;\n\n let remainingBytes = typeConfig.sizeLimit;\n\n const sizeValidationStream = new Transform({\n transform(chunk: Buffer, _enc: BufferEncoding, cb) {\n remainingBytes -= chunk.length;\n\n if (remainingBytes < 0) {\n cb(new Error(`File size exceeds limit of ${typeConfig.sizeLimit / BYTES_PER_MB}MB`));\n }\n else {\n cb(null, chunk);\n }\n },\n });\n const originalStream = createReadStream();\n const validatedStream = originalStream.pipe(sizeValidationStream);\n\n return {\n success: true,\n result: new ReadableStream<Uint8Array>({\n start(controller) {\n validatedStream.on('data', (chunk: Buffer | string) => {\n controller.enqueue(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);\n });\n validatedStream.on('end', () => controller.close());\n validatedStream.on('error', (err: unknown) => controller.error(err));\n },\n }),\n };\n}\n\n/**\n * Validates if a file has an allowed extension.\n * This function extracts the file extension from the filename and checks if it's\n * included in the list of allowed extensions (case-insensitive comparison).\n *\n * @param filename - The filename to check for valid extension.\n * @param allowedExtensions - An array of allowed file extensions (without dots).\n * @returns True if the file extension is allowed, false otherwise.\n */\nexport function validateFileExtension(filename: string, allowedExtensions: string[]): boolean {\n const lastDotIndex = filename.lastIndexOf('.');\n\n if (lastDotIndex === -1) {\n return false;\n }\n\n const extension = filename.substring(lastDotIndex + 1).toLowerCase();\n\n return allowedExtensions.includes(extension);\n}\n\n/**\n * Validates an upload against the specified configuration.\n * This function performs comprehensive validation including:\n * - File extension validation against allowed extensions\n * - File size validation against size limits\n * - Returns detailed error messages for validation failures\n *\n * @param config - The validation configuration including filename and optional file size.\n * @param uploadConfig - The upload configuration containing allowed extensions and size limits.\n * @param uploadType - The type of upload being validated.\n * @returns An object indicating validation success and optional error message.\n */\nexport function validateUpload(\n config: I_UploadValidationConfig,\n uploadConfig: I_UploadConfig,\n uploadType: E_UploadType,\n): { isValid: boolean; error?: string } {\n const { filename, fileSize } = config;\n const typeConfig: I_UploadTypeConfig = uploadConfig[uploadType];\n\n const { allowedExtensions, sizeLimit } = typeConfig;\n\n if (!validateFileExtension(filename, allowedExtensions)) {\n return {\n isValid: false,\n error: `File extension not allowed for ${uploadType.toLowerCase()} files. Allowed extensions: ${allowedExtensions.join(', ')}`,\n };\n }\n\n if (fileSize !== undefined && fileSize > sizeLimit) {\n const maxSizeMB = Math.round(sizeLimit / (1024 * 1024));\n\n return {\n isValid: false,\n error: `File size exceeds limit for ${uploadType.toLowerCase()} files. Maximum size: ${maxSizeMB}MB`,\n };\n }\n\n return { isValid: true };\n}\n\n/**\n * Creates a default upload configuration with predefined settings for different file types.\n * This function provides sensible defaults for image, video, document, and other file types,\n * including allowed extensions and size limits. The configuration can be customized with overrides.\n *\n * @param overrides - Optional configuration overrides to merge with the default configuration.\n * @returns A complete upload configuration object with defaults and any provided overrides.\n */\nexport function createUploadConfig(overrides?: Partial<I_UploadConfig>): I_UploadConfig {\n return { ...DEFAULT_UPLOAD_CONFIG, ...overrides };\n}\n\n/**\n * Uploads a file with comprehensive validation and error handling.\n * This function processes file uploads with the following features:\n * - Input validation for path and file parameters\n * - Configuration validation for all upload types\n * - File validation using getAndValidateFile function\n * - Automatic directory creation\n * - Stream-based file writing\n * - Comprehensive error handling with standardized response codes\n *\n * @param options - Upload configuration including file, path, type, and optional validation config.\n * @returns A promise that resolves to a standardized response with success status, message, file path, and response codes.\n */\nexport async function upload(options: I_UploadOptions): Promise<I_Return<string>> {\n const { path, file, config, type, baseDir } = options;\n\n if (!path || typeof path !== 'string') {\n return {\n success: false,\n message: 'Invalid path provided',\n code: RESPONSE_STATUS.BAD_REQUEST.CODE,\n };\n }\n\n // Security: Validate path is within allowed base directory to prevent path traversal.\n // When baseDir is provided, the resolved path must start with it.\n // When baseDir is not provided, reject any path containing \"..\" segments.\n const resolvedPath = nodePath.resolve(path);\n\n if (baseDir) {\n const resolvedBase = nodePath.resolve(baseDir) + nodePath.sep;\n if (!resolvedPath.startsWith(resolvedBase) && resolvedPath !== nodePath.resolve(baseDir)) {\n return {\n success: false,\n message: 'Path traversal detected: path resolves outside the allowed base directory',\n code: RESPONSE_STATUS.BAD_REQUEST.CODE,\n };\n }\n }\n else if (path.includes('..')) {\n return {\n success: false,\n message: 'Path traversal detected: \"..\" segments are not allowed',\n code: RESPONSE_STATUS.BAD_REQUEST.CODE,\n };\n }\n\n if (!file || typeof file !== 'object') {\n return {\n success: false,\n message: 'Invalid file provided',\n code: RESPONSE_STATUS.BAD_REQUEST.CODE,\n };\n }\n\n if (config) {\n const requiredTypes = [E_UploadType.IMAGE, E_UploadType.VIDEO, E_UploadType.DOCUMENT, E_UploadType.OTHER];\n\n for (const requiredType of requiredTypes) {\n if (!config[requiredType] || !Array.isArray(config[requiredType].allowedExtensions) || config[requiredType].allowedExtensions.length === 0) {\n return {\n success: false,\n message: `Invalid config for ${requiredType.toLowerCase()} files`,\n code: RESPONSE_STATUS.BAD_REQUEST.CODE,\n };\n }\n if (typeof config[requiredType].sizeLimit !== 'number' || config[requiredType].sizeLimit <= 0) {\n return {\n success: false,\n message: `Invalid size limit for ${requiredType.toLowerCase()} files`,\n code: RESPONSE_STATUS.BAD_REQUEST.CODE,\n };\n }\n }\n }\n\n try {\n const fileData = await getAndValidateFile(type, await file, config);\n\n if (!fileData.success) {\n return fileData;\n }\n\n const { createReadStream } = fileData.result;\n\n const dir = dirname(path);\n\n if (!pathExistsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n\n const writeStream = createReadStream();\n const out = createWriteStream(path);\n writeStream.pipe(out);\n\n await new Promise<void>((resolve, reject) => {\n out.on('finish', () => resolve());\n out.on('error', reject);\n writeStream.on('error', reject);\n });\n\n return {\n success: true,\n result: path,\n message: 'File uploaded successfully',\n code: RESPONSE_STATUS.OK.CODE,\n };\n }\n catch (error) {\n return {\n success: false,\n message: error instanceof Error ? error.message : 'File upload failed',\n code: RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE,\n };\n }\n}\n"],"mappings":";;;;;;;;;;AAwBA,eAAsB,EAAsB,GAAgD;AACxF,QAAO,IAAI,SAAS,GAAS,MAAW;EACpC,IAAI,IAAO;AAKX,EAJA,EAAO,GAAG,SAAS,MAAU;AACzB,QAAQ,EAAM;IAChB,EACF,EAAO,GAAG,aAAa,EAAQ,EAAK,CAAC,EACrC,EAAO,GAAG,SAAS,EAAO;GAC5B;;AAiBN,eAAsB,EAAmB,GAAoB,GAAoB,GAA8D;CAC3I,IAAM,IAAW,OAAO,MAAM,GAAM,MAI9B,IAAW,MAAM,EAHR,EAAS,kBAAkB,CAGU,EAC9C,IAAe,KAAU,GAAoB,EAE7C,IAAmB,EACrB;EAAE,UAAU,EAAS;EAAU;EAAU,EACzC,GACA,EACH;AAUD,QARK,EAAiB,UAQf;EACH,SAAS;EACT,QAAQ;EACR,SAAS;EACZ,GAXU;EACH,SAAS;EACT,SAAS,EAAiB,SAAS;EACnC,MAAM,EAAgB,YAAY;EACrC;;AAwBT,eAAsB,EAAiB,GAAoB,GAAoB,GAAwE;CAEnJ,IAAM,KADe,KAAU,GAAoB,EACnB,IAE1B,IAAW,MAAM,EAAmB,GAAM,GAAM,EAAO;AAE7D,KAAI,CAAC,EAAS,QACV,QAAO;CAGX,IAAM,EAAE,wBAAqB,EAAS,QAElC,IAAiB,EAAW,WAE1B,IAAuB,IAAI,EAAU,EACvC,UAAU,GAAe,GAAsB,GAAI;AAG/C,EAFA,KAAkB,EAAM,QAEpB,IAAiB,IAC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AAM,IAAc,GAAkB,EAChC,IAAM,EAAkB,EAAK;AASnC,SARA,EAAY,KAAK,EAAI,EAErB,MAAM,IAAI,SAAe,GAAS,MAAW;AAGzC,GAFA,EAAI,GAAG,gBAAgB,GAAS,CAAC,EACjC,EAAI,GAAG,SAAS,EAAO,EACvB,EAAY,GAAG,SAAS,EAAO;IACjC,EAEK;GACH,SAAS;GACT,QAAQ;GACR,SAAS;GACT,MAAM,EAAgB,GAAG;GAC5B;UAEE,GAAO;AACV,SAAO;GACH,SAAS;GACT,SAAS,aAAiB,QAAQ,EAAM,UAAU;GAClD,MAAM,EAAgB,sBAAsB;GAC/C"}
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './ws.type.js';
2
+ export * from './ws.util.js';
@@ -1,7 +1,7 @@
1
1
  import { ApolloClient } from '@apollo/client';
2
2
  import { ApolloLink } from '@apollo/client/link';
3
3
  import { GraphQLError } from 'graphql';
4
- import { I_Children } from '../../../typescript/index.js';
4
+ import { I_Children } from '../../typescript/index.js';
5
5
  export interface I_ApolloOptions extends Omit<ApolloClient.Options, 'link' | 'cache'> {
6
6
  uri?: string;
7
7
  wsUrl?: string;
@@ -1 +1,9 @@
1
- export {}
1
+ export * from './apollo-client.component.js';
2
+ export * from './apollo-client.constant.js';
3
+ export * from './apollo-client.context.js';
4
+ export * from './apollo-client.hook.js';
5
+ export * from './apollo-client.type.js';
6
+ export * from './apollo-client.util.js';
7
+ export * from './links/index.js';
8
+ export { makeVar } from '@apollo/client/cache';
9
+ export { useApolloClient, useBackgroundQuery, useFragment, useLazyQuery, useLoadableQuery, useMutation, useQuery, useQueryRefHandlers, useReactiveVar, useReadQuery, useSubscription, useSuspenseFragment, useSuspenseQuery } from '@apollo/client/react';
@@ -1 +1 @@
1
- export {}
1
+ export * from './upload.js';
@@ -1 +1,16 @@
1
- export {}
1
+ import { I_ApolloOptions } from '../apollo-client/index.js';
2
+ /**
3
+ * Creates a registered Apollo Client factory for Next.js server components.
4
+ * This function creates a client factory that is registered with Next.js for
5
+ * proper server-side rendering support. The factory function ensures that
6
+ * each request gets its own Apollo Client instance, which is essential for
7
+ * SSR compatibility and preventing client state leakage between requests.
8
+ *
9
+ * @param options - Configuration options for the Apollo Client including URI, WebSocket URL, and custom links.
10
+ * @returns A registered Apollo Client factory function that can be used with Next.js server components.
11
+ */
12
+ export declare const makeClient: (options?: I_ApolloOptions) => {
13
+ getClient: () => import('@apollo/client-integration-nextjs').ApolloClient;
14
+ query: <TData = unknown, TVariables extends import('@apollo/client').OperationVariables = import('@apollo/client').OperationVariables>(options: import("@apollo/client").ApolloClient.QueryOptions<TData, TVariables>) => Promise<import("@apollo/client").ApolloClient.QueryResult<import('@apollo/client').MaybeMasked<TData>>>;
15
+ PreloadQuery: import('@apollo/client-integration-nextjs').PreloadQueryComponent;
16
+ };
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './apollo-client-nextjs.component.js';
2
+ export * from './apollo-client-nextjs.util.js';
@@ -1 +1,6 @@
1
- export {}
1
+ export * from './apollo-error.component.js';
2
+ export * from './apollo-error.context.js';
3
+ export * from './apollo-error.hook.js';
4
+ export * from './apollo-error.provider.js';
5
+ export * from './apollo-error.type.js';
6
+ export * from './apollo-error.util.js';
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './i18next.hook.js';
2
+ export * from './i18next.util.js';
@@ -1 +1,5 @@
1
- export {}
1
+ export * from './loading.component.js';
2
+ export * from './loading.context.js';
3
+ export * from './loading.hook.js';
4
+ export * from './loading.provider.js';
5
+ export * from './loading.type.js';
@@ -1,4 +1,4 @@
1
- import { I_Children } from '../../../typescript/index.js';
1
+ import { I_Children } from '../../typescript/index.js';
2
2
  import * as React from 'react';
3
3
  /**
4
4
  * Provider component that manages loading state and provides loading context.
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './log.type.js';
2
+ export * from './log.util.js';
@@ -0,0 +1 @@
1
+ export type { I_CatchErrorOptions } from '../../util/log/index.js';
@@ -1,4 +1,4 @@
1
- import { I_Log, I_Return } from '../../../typescript/index.js';
1
+ import { I_Log, I_Return } from '../../typescript/index.js';
2
2
  import { I_CatchErrorOptions } from './log.type.js';
3
3
  /**
4
4
  * Browser-compatible logging interface using consola.
@@ -1 +1,6 @@
1
- export {}
1
+ export * from './next-intl.constant.js';
2
+ export * from './next-intl.context.js';
3
+ export * from './next-intl.hoc.js';
4
+ export * from './next-intl.hook.js';
5
+ export * from './next-intl.provider.js';
6
+ export * from './next-intl.type.js';
@@ -1,5 +1,5 @@
1
1
  import { ComponentType } from 'react';
2
- import { I_Children } from '../../../typescript/index.js';
2
+ import { I_Children } from '../../typescript/index.js';
3
3
  import { I_NextIntlLanguage, T_NextIntlMessageList } from './next-intl.type.js';
4
4
  import * as React from 'react';
5
5
  /**
@@ -1,6 +1,6 @@
1
1
  import { Locale } from 'date-fns';
2
2
  import { AbstractIntlMessages, Timezone } from 'next-intl';
3
- import { I_Children } from '../../../typescript/index.js';
3
+ import { I_Children } from '../../typescript/index.js';
4
4
  export interface I_NextIntlLanguage {
5
5
  label: string;
6
6
  value: string;
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './storage.hook.js';
2
+ export * from './storage.util.js';
@@ -1,4 +1,4 @@
1
- import { I_Serializer } from '../../../util/serializer/index.js';
1
+ import { I_Serializer } from '../../util/serializer/index.js';
2
2
  /**
3
3
  * React hook that provides persistent storage functionality with automatic serialization.
4
4
  * This hook manages state that persists across browser sessions using localStorage,
@@ -1 +1 @@
1
- export {}
1
+ export { toast, Toaster } from 'react-hot-toast';
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './userback.component.js';
2
+ export * from './userback.type.js';
@@ -1 +1,5 @@
1
- export {}
1
+ /**
2
+ * Re-exports all common TypeScript types for shared usage across the codebase.
3
+ */
4
+ export * from './common.type.js';
5
+ export * from './react.type.js';
@@ -1 +1,5 @@
1
- export {}
1
+ /**
2
+ * Re-exports all common utility types for shared usage across the codebase.
3
+ */
4
+ export * from './common.type.js';
5
+ export * from './common.util.js';
@@ -1 +1,9 @@
1
- export {}
1
+ /**
2
+ * Re-exports all utility modules for shared usage across the codebase.
3
+ */
4
+ export * from './common/index.js';
5
+ export * from './log/index.js';
6
+ export * from './object/index.js';
7
+ export * from './serializer/index.js';
8
+ export * from './string/index.js';
9
+ export * from './validate/index.js';
@@ -1 +1,2 @@
1
- export {}
1
+ export type { I_CatchErrorOptions } from './log.type.js';
2
+ export { baseCatchError } from './log.util.js';
@@ -1,4 +1,4 @@
1
- import { I_Return } from '../../../typescript/index.js';
1
+ import { I_Return } from '../../typescript/index.js';
2
2
  import { I_CatchErrorOptions } from './log.type.js';
3
3
  /**
4
4
  * Core error-catching implementation shared between Node and React environments.
@@ -1 +1,4 @@
1
- export {}
1
+ /**
2
+ * Re-exports all object manipulation utilities.
3
+ */
4
+ export * from './object.util.js';
@@ -1 +1,2 @@
1
- export {}
1
+ export * from './serializer.type.js';
2
+ export * from './serializer.util.js';
@@ -1 +1,5 @@
1
- export {}
1
+ /**
2
+ * Re-exports all string manipulation utilities and types.
3
+ */
4
+ export * from './string.type.js';
5
+ export * from './string.util.js';
@@ -1 +1,4 @@
1
- export {}
1
+ /**
2
+ * Re-exports all validation utilities.
3
+ */
4
+ export * from './validate.util.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cyberskill/shared",
3
3
  "type": "module",
4
- "version": "3.12.0",
4
+ "version": "3.13.0",
5
5
  "description": "CyberSkill Shared",
6
6
  "author": "Stephen Cheng",
7
7
  "license": "MIT",
@@ -1,5 +0,0 @@
1
- declare const _default: {
2
- extends: string[];
3
- ignores: ((message: string) => boolean)[];
4
- };
5
- export default _default;
@@ -1,3 +0,0 @@
1
- export * from './env.constant.js';
2
- export * from './env.type.js';
3
- export * from './env.util.js';