@catbee/utils 0.0.1
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/LICENSE +201 -0
- package/README.md +295 -0
- package/build/esm/config.d.ts +22 -0
- package/build/esm/config.js +21 -0
- package/build/esm/config.js.map +1 -0
- package/build/esm/index.d.ts +19 -0
- package/build/esm/index.js +19 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/types/api-response.d.ts +44 -0
- package/build/esm/types/api-response.js +2 -0
- package/build/esm/types/api-response.js.map +1 -0
- package/build/esm/utils/array.utils.d.ts +105 -0
- package/build/esm/utils/array.utils.js +232 -0
- package/build/esm/utils/array.utils.js.map +1 -0
- package/build/esm/utils/async.utils.d.ts +119 -0
- package/build/esm/utils/async.utils.js +474 -0
- package/build/esm/utils/async.utils.js.map +1 -0
- package/build/esm/utils/cache.utils.d.ts +90 -0
- package/build/esm/utils/cache.utils.js +294 -0
- package/build/esm/utils/cache.utils.js.map +1 -0
- package/build/esm/utils/context-store.utils.d.ts +85 -0
- package/build/esm/utils/context-store.utils.js +99 -0
- package/build/esm/utils/context-store.utils.js.map +1 -0
- package/build/esm/utils/crypto.utils.d.ts +58 -0
- package/build/esm/utils/crypto.utils.js +76 -0
- package/build/esm/utils/crypto.utils.js.map +1 -0
- package/build/esm/utils/dir.utils.d.ts +75 -0
- package/build/esm/utils/dir.utils.js +400 -0
- package/build/esm/utils/dir.utils.js.map +1 -0
- package/build/esm/utils/env.utils.d.ts +131 -0
- package/build/esm/utils/env.utils.js +218 -0
- package/build/esm/utils/env.utils.js.map +1 -0
- package/build/esm/utils/exception.utils.d.ts +114 -0
- package/build/esm/utils/exception.utils.js +217 -0
- package/build/esm/utils/exception.utils.js.map +1 -0
- package/build/esm/utils/fs.utils.d.ts +32 -0
- package/build/esm/utils/fs.utils.js +140 -0
- package/build/esm/utils/fs.utils.js.map +1 -0
- package/build/esm/utils/http-status-codes.d.ts +357 -0
- package/build/esm/utils/http-status-codes.js +358 -0
- package/build/esm/utils/http-status-codes.js.map +1 -0
- package/build/esm/utils/id.utils.d.ts +35 -0
- package/build/esm/utils/id.utils.js +55 -0
- package/build/esm/utils/id.utils.js.map +1 -0
- package/build/esm/utils/logger.utils.d.ts +15 -0
- package/build/esm/utils/logger.utils.js +59 -0
- package/build/esm/utils/logger.utils.js.map +1 -0
- package/build/esm/utils/obj.utils.d.ts +55 -0
- package/build/esm/utils/obj.utils.js +121 -0
- package/build/esm/utils/obj.utils.js.map +1 -0
- package/build/esm/utils/response.utils.d.ts +48 -0
- package/build/esm/utils/response.utils.js +80 -0
- package/build/esm/utils/response.utils.js.map +1 -0
- package/build/esm/utils/string.utils.d.ts +37 -0
- package/build/esm/utils/string.utils.js +56 -0
- package/build/esm/utils/string.utils.js.map +1 -0
- package/build/esm/utils/url.utils.d.ts +24 -0
- package/build/esm/utils/url.utils.js +73 -0
- package/build/esm/utils/url.utils.js.map +1 -0
- package/build/esm/utils/validate.utils.d.ts +60 -0
- package/build/esm/utils/validate.utils.js +121 -0
- package/build/esm/utils/validate.utils.js.map +1 -0
- package/build/esnext/config.d.ts +22 -0
- package/build/esnext/config.js +21 -0
- package/build/esnext/config.js.map +1 -0
- package/build/esnext/index.d.ts +19 -0
- package/build/esnext/index.js +19 -0
- package/build/esnext/index.js.map +1 -0
- package/build/esnext/types/api-response.d.ts +44 -0
- package/build/esnext/types/api-response.js +2 -0
- package/build/esnext/types/api-response.js.map +1 -0
- package/build/esnext/utils/array.utils.d.ts +105 -0
- package/build/esnext/utils/array.utils.js +203 -0
- package/build/esnext/utils/array.utils.js.map +1 -0
- package/build/esnext/utils/async.utils.d.ts +119 -0
- package/build/esnext/utils/async.utils.js +291 -0
- package/build/esnext/utils/async.utils.js.map +1 -0
- package/build/esnext/utils/cache.utils.d.ts +90 -0
- package/build/esnext/utils/cache.utils.js +142 -0
- package/build/esnext/utils/cache.utils.js.map +1 -0
- package/build/esnext/utils/context-store.utils.d.ts +85 -0
- package/build/esnext/utils/context-store.utils.js +95 -0
- package/build/esnext/utils/context-store.utils.js.map +1 -0
- package/build/esnext/utils/crypto.utils.d.ts +58 -0
- package/build/esnext/utils/crypto.utils.js +72 -0
- package/build/esnext/utils/crypto.utils.js.map +1 -0
- package/build/esnext/utils/dir.utils.d.ts +75 -0
- package/build/esnext/utils/dir.utils.js +150 -0
- package/build/esnext/utils/dir.utils.js.map +1 -0
- package/build/esnext/utils/env.utils.d.ts +131 -0
- package/build/esnext/utils/env.utils.js +211 -0
- package/build/esnext/utils/env.utils.js.map +1 -0
- package/build/esnext/utils/exception.utils.d.ts +114 -0
- package/build/esnext/utils/exception.utils.js +148 -0
- package/build/esnext/utils/exception.utils.js.map +1 -0
- package/build/esnext/utils/fs.utils.d.ts +32 -0
- package/build/esnext/utils/fs.utils.js +62 -0
- package/build/esnext/utils/fs.utils.js.map +1 -0
- package/build/esnext/utils/http-status-codes.d.ts +357 -0
- package/build/esnext/utils/http-status-codes.js +358 -0
- package/build/esnext/utils/http-status-codes.js.map +1 -0
- package/build/esnext/utils/id.utils.d.ts +35 -0
- package/build/esnext/utils/id.utils.js +53 -0
- package/build/esnext/utils/id.utils.js.map +1 -0
- package/build/esnext/utils/logger.utils.d.ts +15 -0
- package/build/esnext/utils/logger.utils.js +59 -0
- package/build/esnext/utils/logger.utils.js.map +1 -0
- package/build/esnext/utils/obj.utils.d.ts +55 -0
- package/build/esnext/utils/obj.utils.js +94 -0
- package/build/esnext/utils/obj.utils.js.map +1 -0
- package/build/esnext/utils/response.utils.d.ts +48 -0
- package/build/esnext/utils/response.utils.js +58 -0
- package/build/esnext/utils/response.utils.js.map +1 -0
- package/build/esnext/utils/string.utils.d.ts +37 -0
- package/build/esnext/utils/string.utils.js +46 -0
- package/build/esnext/utils/string.utils.js.map +1 -0
- package/build/esnext/utils/url.utils.d.ts +24 -0
- package/build/esnext/utils/url.utils.js +35 -0
- package/build/esnext/utils/url.utils.js.map +1 -0
- package/build/esnext/utils/validate.utils.d.ts +60 -0
- package/build/esnext/utils/validate.utils.js +105 -0
- package/build/esnext/utils/validate.utils.js.map +1 -0
- package/build/src/config.d.ts +22 -0
- package/build/src/config.js +24 -0
- package/build/src/config.js.map +1 -0
- package/build/src/index.d.ts +19 -0
- package/build/src/index.js +35 -0
- package/build/src/index.js.map +1 -0
- package/build/src/types/api-response.d.ts +44 -0
- package/build/src/types/api-response.js +3 -0
- package/build/src/types/api-response.js.map +1 -0
- package/build/src/utils/array.utils.d.ts +105 -0
- package/build/src/utils/array.utils.js +216 -0
- package/build/src/utils/array.utils.js.map +1 -0
- package/build/src/utils/async.utils.d.ts +119 -0
- package/build/src/utils/async.utils.js +304 -0
- package/build/src/utils/async.utils.js.map +1 -0
- package/build/src/utils/cache.utils.d.ts +90 -0
- package/build/src/utils/cache.utils.js +146 -0
- package/build/src/utils/cache.utils.js.map +1 -0
- package/build/src/utils/context-store.utils.d.ts +85 -0
- package/build/src/utils/context-store.utils.js +100 -0
- package/build/src/utils/context-store.utils.js.map +1 -0
- package/build/src/utils/crypto.utils.d.ts +58 -0
- package/build/src/utils/crypto.utils.js +82 -0
- package/build/src/utils/crypto.utils.js.map +1 -0
- package/build/src/utils/dir.utils.d.ts +75 -0
- package/build/src/utils/dir.utils.js +164 -0
- package/build/src/utils/dir.utils.js.map +1 -0
- package/build/src/utils/env.utils.d.ts +131 -0
- package/build/src/utils/env.utils.js +215 -0
- package/build/src/utils/env.utils.js.map +1 -0
- package/build/src/utils/exception.utils.d.ts +114 -0
- package/build/src/utils/exception.utils.js +162 -0
- package/build/src/utils/exception.utils.js.map +1 -0
- package/build/src/utils/fs.utils.d.ts +32 -0
- package/build/src/utils/fs.utils.js +71 -0
- package/build/src/utils/fs.utils.js.map +1 -0
- package/build/src/utils/http-status-codes.d.ts +357 -0
- package/build/src/utils/http-status-codes.js +361 -0
- package/build/src/utils/http-status-codes.js.map +1 -0
- package/build/src/utils/id.utils.d.ts +35 -0
- package/build/src/utils/id.utils.js +60 -0
- package/build/src/utils/id.utils.js.map +1 -0
- package/build/src/utils/logger.utils.d.ts +15 -0
- package/build/src/utils/logger.utils.js +96 -0
- package/build/src/utils/logger.utils.js.map +1 -0
- package/build/src/utils/obj.utils.d.ts +55 -0
- package/build/src/utils/obj.utils.js +103 -0
- package/build/src/utils/obj.utils.js.map +1 -0
- package/build/src/utils/response.utils.d.ts +48 -0
- package/build/src/utils/response.utils.js +63 -0
- package/build/src/utils/response.utils.js.map +1 -0
- package/build/src/utils/string.utils.d.ts +37 -0
- package/build/src/utils/string.utils.js +54 -0
- package/build/src/utils/string.utils.js.map +1 -0
- package/build/src/utils/url.utils.d.ts +24 -0
- package/build/src/utils/url.utils.js +39 -0
- package/build/src/utils/url.utils.js.map +1 -0
- package/build/src/utils/validate.utils.d.ts +60 -0
- package/build/src/utils/validate.utils.js +115 -0
- package/build/src/utils/validate.utils.js.map +1 -0
- package/package.json +80 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
# @catbee/utils
|
|
2
|
+
|
|
3
|
+
## 🧰 Utility Modules for Node.js
|
|
4
|
+
|
|
5
|
+
A modular, production-grade utility toolkit for Node.js and TypeScript, designed for robust, scalable applications (including Express-based services). All utilities are tree-shakable and can be imported independently.
|
|
6
|
+
|
|
7
|
+
   
|
|
8
|
+
|
|
9
|
+
## 📦 Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm i @catbee/utils
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## ⚡ Quick Start
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { chunk, sleep, getLogger, uuid, isEmail } from "@catbee/utils";
|
|
19
|
+
|
|
20
|
+
// Chunk an array
|
|
21
|
+
const result = chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
|
|
22
|
+
|
|
23
|
+
// Sleep for 1 second
|
|
24
|
+
await sleep(1000);
|
|
25
|
+
|
|
26
|
+
// Log with context
|
|
27
|
+
getLogger().info("App started");
|
|
28
|
+
|
|
29
|
+
// Generate a secure UUID
|
|
30
|
+
console.log(uuid()); // e.g. 2a563ec1-caf6-4fe2-b60c-9cf7fb1bdb7f
|
|
31
|
+
|
|
32
|
+
// Basic validation
|
|
33
|
+
console.log(isEmail("user@example.com")); // true
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 📦 Modules Overview
|
|
38
|
+
|
|
39
|
+
- [**Array Utilities**](#-array-utilities)
|
|
40
|
+
- [**Async Utilities**](#-async-utilities)
|
|
41
|
+
- [**Cache Utilities**](#-cache-utilities)
|
|
42
|
+
- [**Context Store**](#-context-store)
|
|
43
|
+
- [**Crypto Utilities**](#-crypto-utilities)
|
|
44
|
+
- [**Directory Utilities**](#-directory-utilities)
|
|
45
|
+
- [**Environment Utilities**](#-environment-utilities)
|
|
46
|
+
- [**Exception Utilities**](#-exception-utilities)
|
|
47
|
+
- [**File System Utilities**](#-file-system-utilities)
|
|
48
|
+
- [**HTTP Status Codes**](#-http-status-codes)
|
|
49
|
+
- [**ID Utilities**](#-id-utilities)
|
|
50
|
+
- [**Logger Utilities**](#-logger-utility)
|
|
51
|
+
- [**Object Utilities**](#-object-utilities)
|
|
52
|
+
- [**Response Utilities**](#-response-utilities)
|
|
53
|
+
- [**String Utilities**](#-string-utilities)
|
|
54
|
+
- [**URL Utilities**](#-url-utilities)
|
|
55
|
+
- [**Validate Utilities**](#-validate-utilities)
|
|
56
|
+
|
|
57
|
+
## 📦 Array Utilities
|
|
58
|
+
|
|
59
|
+
- `chunk<T>(arr: T[], size: number): T[][]` – Split array into chunks.
|
|
60
|
+
- `unique<T>(array: T[]): T[]` – Remove duplicates.
|
|
61
|
+
- `flattenDeep<T>(array: any[]): T[]` – Deep flatten nested arrays.
|
|
62
|
+
- `random<T>(array: T[]): T | undefined` – Random element.
|
|
63
|
+
- `groupBy<T, K>(array: T[], keyFn: (item: T) => K): Record<K, T[]>` – Group by key.
|
|
64
|
+
- `shuffle<T>(array: T[]): T[]` – Fisher-Yates shuffle.
|
|
65
|
+
- `difference<T>(a: T[], b: T[]): T[]` – Elements in `a` not in `b`.
|
|
66
|
+
- `intersect<T>(a: T[], b: T[]): T[]` – Intersection.
|
|
67
|
+
- `mergeSort<T extends object>(array: T[], key: string, direction = 'asc'): T[]` – Merge sort by nested key.
|
|
68
|
+
|
|
69
|
+
## ⏳ Async Utilities
|
|
70
|
+
|
|
71
|
+
- `sleep(ms: number): Promise<void>`
|
|
72
|
+
- `debounce<T>(fn: T, wait: number): T & { cancel(): void; flush(): void }`
|
|
73
|
+
- `throttle<T>(fn: T, wait: number, options?): T`
|
|
74
|
+
- `retry<T>(fn: () => Promise<T>, retries?: number): Promise<T>`
|
|
75
|
+
- `withTimeout<T>(promise: Promise<T>, ms: number): Promise<T>`
|
|
76
|
+
- `runInBatches<T>(tasks: (() => Promise<T>)[], batchSize: number): Promise<T[]>`
|
|
77
|
+
- `singletonAsync<TArgs, TResult>(fn: (...args: TArgs) => Promise<TResult>): (...args: TArgs) => Promise<TResult>`
|
|
78
|
+
- `settleAll<T>(tasks: (() => Promise<T>)[]): Promise<SettledResult<T>[]>`
|
|
79
|
+
- `createTaskQueue(limit: number)`
|
|
80
|
+
- `runInSeries<T>(tasks: (() => Promise<T>)[]): Promise<T[]>`
|
|
81
|
+
|
|
82
|
+
## 🗃️ Cache Utilities
|
|
83
|
+
|
|
84
|
+
- `TTLCache<K, V>(ttl: number)` – In-memory TTL cache with `.set`, `.get`, `.has`, `.delete`, `.clear`.
|
|
85
|
+
|
|
86
|
+
You can use it like:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
const cache = new TTLCache<string, number>(3600_000);
|
|
90
|
+
cache.set("foo", 42);
|
|
91
|
+
cache.get("foo"); // 42
|
|
92
|
+
cache.has("foo"); // true
|
|
93
|
+
cache.cleanup(); // cleans expired
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## 🧩 Context Store
|
|
97
|
+
|
|
98
|
+
- `ContextStore` – Per-request context using AsyncLocalStorage.
|
|
99
|
+
|
|
100
|
+
**Static Methods:**
|
|
101
|
+
- `getInstance(): AsyncLocalStorage<Store>` – Get the AsyncLocalStorage instance.
|
|
102
|
+
- `getAll(): Store | undefined` – Get the current context store.
|
|
103
|
+
- `run(store: Store, callback: () => void): void` – Run a callback within a context.
|
|
104
|
+
- `set<K extends keyof Store>(key: K, value: Store[K]): void` – Set a value in the context.
|
|
105
|
+
- `get<K extends keyof Store>(key: K): Store[K] | undefined` – Get a value from the context.
|
|
106
|
+
|
|
107
|
+
- `StoreKeys` – Common context keys.
|
|
108
|
+
- `getRequestId(): string | undefined` – Get the current request ID from context.
|
|
109
|
+
|
|
110
|
+
### Example (Express middleware usage):
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
// ✅ Recommended: Unified middleware to initialize context and logger
|
|
114
|
+
import { ContextStore, StoreKeys, getLogger } from "@catbee/utils";
|
|
115
|
+
import crypto from "crypto";
|
|
116
|
+
|
|
117
|
+
export function setupRequestContext(req: Request, res: Response, next: NextFunction): void {
|
|
118
|
+
const requestId = req.headers["x-request-id"]?.toString() || crypto.randomUUID();
|
|
119
|
+
|
|
120
|
+
ContextStore.run({ [StoreKeys.REQUEST_ID]: requestId }, () => {
|
|
121
|
+
const logger = getLogger().child({ reqId: requestId });
|
|
122
|
+
ContextStore.set(StoreKeys.LOGGER, logger);
|
|
123
|
+
logger.info("Request context initialized");
|
|
124
|
+
next();
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// In your app entry point
|
|
129
|
+
app.use(setupRequestContext);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
👇 Alternatively, split it into two separate middlewares:
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
// First: Initialize context with request ID
|
|
136
|
+
app.use((req, res, next) => {
|
|
137
|
+
const requestId = req.headers["x-request-id"] || crypto.randomUUID();
|
|
138
|
+
ContextStore.run({ [StoreKeys.REQUEST_ID]: requestId }, () => next());
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Second: Inject logger into the context
|
|
142
|
+
app.use((req, res, next) => {
|
|
143
|
+
const logger = getLogger().child({ reqId: req.headers["x-request-id"] });
|
|
144
|
+
ContextStore.set(StoreKeys.LOGGER, logger);
|
|
145
|
+
logger.info("Request started");
|
|
146
|
+
next();
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## 🔐 Crypto Utilities
|
|
151
|
+
|
|
152
|
+
- `hmac(algorithm: string, input: string, secret: string): string`
|
|
153
|
+
- `hash(algorithm: string, input: string): string`
|
|
154
|
+
- `sha256Hmac(input: string, secret: string): string`
|
|
155
|
+
- `sha1(input: string): string`
|
|
156
|
+
- `sha256(input: string): string`
|
|
157
|
+
- `md5(input: string): string`
|
|
158
|
+
- `randomString(): string`
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
## 📂 Directory Utilities
|
|
162
|
+
|
|
163
|
+
- `ensureDir(dirPath: string): Promise<void>`
|
|
164
|
+
- `listFiles(dirPath: string, options?): Promise<string[]>`
|
|
165
|
+
- `deleteDirRecursive(dirPath: string): Promise<void>`
|
|
166
|
+
- `isDirectory(path: string): Promise<boolean>`
|
|
167
|
+
- `copyDir(src: string, dest: string): Promise<void>`
|
|
168
|
+
- `moveDir(src: string, dest: string): Promise<void>`
|
|
169
|
+
- `emptyDir(dirPath: string): Promise<void>`
|
|
170
|
+
- `getDirSize(dirPath: string): Promise<number>`
|
|
171
|
+
- `watchDir(dirPath: string, cb: (event, filename) => void)`
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
## 🌱 Environment Utilities
|
|
175
|
+
|
|
176
|
+
- `Environment` enum – (`DEVELOPMENT`, `PRODUCTION`, `STAGING`, `TESTING`)
|
|
177
|
+
- `Env` class – Environment variable helpers.
|
|
178
|
+
|
|
179
|
+
**Static Methods:**
|
|
180
|
+
- `isDev(): boolean` – Is NODE_ENV development?
|
|
181
|
+
- `set(key: string, value: string): void` – Set an environment variable.
|
|
182
|
+
- `getAll(): object` – Get all environment variables.
|
|
183
|
+
- `get(key: string, defaultValue?: string): string | undefined` – Get an environment variable.
|
|
184
|
+
- `getRequired(key: string): string` – Get a required environment variable.
|
|
185
|
+
- `getNumber(key: string, defaultValue: number): number` – Get a number environment variable.
|
|
186
|
+
- `getNumberRequired(key: string): number` – Get a required number environment variable.
|
|
187
|
+
- `getBoolean(key: string, defaultValue = false): boolean` – Get a boolean environment variable.
|
|
188
|
+
- `getBooleanRequired(key: string): boolean` – Get a required boolean environment variable.
|
|
189
|
+
- `getJSON<T extends object = object>(key: string, defaultValue: T): T` – Parse a JSON object from an environment variable.
|
|
190
|
+
- `getArray<T = string>(key: string, defaultValue: T[] = [], splitter = ','): string[] | T[]` – Parse a comma-separated string as an array.
|
|
191
|
+
- `getEnum<T extends string>(key: string, allowedValues: T[], defaultValue?: T): T` – Get and validate an enum-like environment variable.
|
|
192
|
+
- `has(key: string): boolean` – Check if an environment variable exists.
|
|
193
|
+
- `delete(key: string): void` – Delete an environment variable (useful in tests).
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
## 🚨 Exception Utilities
|
|
197
|
+
|
|
198
|
+
- `HttpError`, `InternalServerErrorException`, `UnauthorizedException`, `BadRequestException`, `NotFoundException`, `ForbiddenException`, `ConflictException`, `BadGatewayException`, `TooManyRequestsException`, `ServiceUnavailableException`, `GatewayTimeoutException` – All extend `ErrorResponse`.
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
## 📁 File System Utilities
|
|
202
|
+
|
|
203
|
+
- `fileExists(path: string): Promise<boolean>`
|
|
204
|
+
- `readJsonFile<T>(path: string): Promise<T | null>`
|
|
205
|
+
- `writeJsonFile(path: string, data: any): Promise<void>`
|
|
206
|
+
- `deleteFileIfExists(path: string): Promise<boolean>`
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
## 📊 HTTP Status Codes
|
|
210
|
+
|
|
211
|
+
A typed object with all HTTP status codes and their standard messages.
|
|
212
|
+
|
|
213
|
+
- `HttpStatusCodes.OK === 200`
|
|
214
|
+
- `HttpStatusCodes.NOT_FOUND === 404`
|
|
215
|
+
- ...and so on.
|
|
216
|
+
|
|
217
|
+
You can use it like:
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
import { HttpStatusCodes } from "@catbee/utils";
|
|
221
|
+
|
|
222
|
+
res.status(HttpStatusCodes.BAD_REQUEST).send("Invalid payload");
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## 🆔 ID Utilities
|
|
226
|
+
|
|
227
|
+
Helpers for generating unique and random identifiers, covering popular formats for distributed systems and secure tokens.
|
|
228
|
+
|
|
229
|
+
- `uuid(): string` — Generate a UUID v4 string (RFC 4122).
|
|
230
|
+
- `ulidString(): string` — Generate a ULID (Universally Unique Lexicographically Sortable Identifier).
|
|
231
|
+
- `nanoId(size?: number): string` — Generate a nanoid string.
|
|
232
|
+
- `randomHex(byteLength?: number): string` — Generate a cryptographically strong random hex string of given length in bytes.
|
|
233
|
+
- `randomInt(min: number, max: number): number` — Generate a secure random integer between min and max, inclusive.
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
## 📄 Logger Utilities
|
|
237
|
+
|
|
238
|
+
- `getLogger(): Logger` – Context-aware logger (uses `pino`).
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
## 🧩 Object Utilities
|
|
242
|
+
|
|
243
|
+
- `isObjEmpty(obj: Record<any, any>): boolean`
|
|
244
|
+
- `pick<T, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>`
|
|
245
|
+
- `omit<T, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>`
|
|
246
|
+
- `deepObjMerge<T>(a: T, b: Partial<T>): T`
|
|
247
|
+
- `flattenObject<T>(obj: T): Record<string, any>`
|
|
248
|
+
- `getValueByPath<T>(obj: T, path: string)`
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
## 📝 Response Utilities
|
|
252
|
+
|
|
253
|
+
- `SuccessResponse<T>` – Standard API success wrapper.
|
|
254
|
+
- `ErrorResponse` – Standard API error wrapper.
|
|
255
|
+
- Types: `ApiResponse<T>`, `Pagination<T>`, `PaginationResponse<T>`
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
## 🧵 String Utilities
|
|
259
|
+
|
|
260
|
+
- `capitalize(str: string): string`
|
|
261
|
+
- `toKebabCase(str: string): string`
|
|
262
|
+
- `toCamelCase(str: string): string`
|
|
263
|
+
- `slugify(str: string): string`
|
|
264
|
+
- `truncate(str: string, len: number): string`
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
## 🌐 URL Utilities
|
|
268
|
+
|
|
269
|
+
- `appendQueryParams(url: string, params: object): string`
|
|
270
|
+
- `parseQueryString(query: string): Record<string, string>`
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
## ✅ Validate Utilities
|
|
274
|
+
A comprehensive suite of string/format validators for safe input and API checks.
|
|
275
|
+
|
|
276
|
+
- `isEmail(str: string): boolean` — Validate basic email address.
|
|
277
|
+
- `isUUID(str: string): boolean` — Validate string as UUID (v1–v5).
|
|
278
|
+
- `isURL(str: string): boolean` — Check if string is a valid URL.
|
|
279
|
+
- `isPhone(str: string): boolean` — Validate (international/E164/local) phone number.
|
|
280
|
+
- `isAlphanumeric(str: string): boolean` — Check for letters/numbers only.
|
|
281
|
+
- `isNumeric(strOrNum: string | number)`: boolean — Check safely parsable numeric value.
|
|
282
|
+
- `isHexColor(str: string): boolean` — Validate hex color (#RGB or #RRGGBB).
|
|
283
|
+
- `isISODate(str: string): boolean` — Validate ISO 8601 date string.
|
|
284
|
+
|
|
285
|
+
## 🏁 Usage
|
|
286
|
+
|
|
287
|
+
Import only what you need:
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
import { chunk, sleep, TTLCache, getLogger } from "@catbee/utils";
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## 📜 License
|
|
294
|
+
|
|
295
|
+
MIT © catbee-technologies
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type LogLevel = "fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent";
|
|
2
|
+
/**
|
|
3
|
+
* Application runtime configuration loaded from environment variables.
|
|
4
|
+
*/
|
|
5
|
+
export declare const Config: {
|
|
6
|
+
Logger: {
|
|
7
|
+
/**
|
|
8
|
+
* Logging level (e.g., 'info', 'debug', 'warn', 'error').
|
|
9
|
+
*/
|
|
10
|
+
level: LogLevel;
|
|
11
|
+
/**
|
|
12
|
+
* Name of the logger instance (defaults to npm package name).
|
|
13
|
+
*/
|
|
14
|
+
name: string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Whether to use ISO 8601 timestamps in logs.
|
|
17
|
+
*/
|
|
18
|
+
isoTimestamp: boolean;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Env } from "./utils/env.utils";
|
|
2
|
+
/**
|
|
3
|
+
* Application runtime configuration loaded from environment variables.
|
|
4
|
+
*/
|
|
5
|
+
export var Config = {
|
|
6
|
+
Logger: {
|
|
7
|
+
/**
|
|
8
|
+
* Logging level (e.g., 'info', 'debug', 'warn', 'error').
|
|
9
|
+
*/
|
|
10
|
+
level: Env.get("LOGGER_LEVEL", "info"),
|
|
11
|
+
/**
|
|
12
|
+
* Name of the logger instance (defaults to npm package name).
|
|
13
|
+
*/
|
|
14
|
+
name: Env.get("LOGGER_NAME", Env.get("npm_package_name", "@catbee/utils")),
|
|
15
|
+
/**
|
|
16
|
+
* Whether to use ISO 8601 timestamps in logs.
|
|
17
|
+
*/
|
|
18
|
+
isoTimestamp: Env.getBoolean("LOGGER_ISO_TIMESTAMP", false),
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAWxC;;GAEG;AACH,MAAM,CAAC,IAAM,MAAM,GAAG;IACpB,MAAM,EAAE;QACN;;WAEG;QACH,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,MAAM,CAAa;QAElD;;WAEG;QACH,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,GAAG,CAAC,GAAG,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;QAE1E;;WAEG;QACH,YAAY,EAAE,GAAG,CAAC,UAAU,CAAC,sBAAsB,EAAE,KAAK,CAAC;KAC5D;CACF,CAAC","sourcesContent":["import { Env } from \"./utils/env.utils\";\n\ntype LogLevel =\n | \"fatal\"\n | \"error\"\n | \"warn\"\n | \"info\"\n | \"debug\"\n | \"trace\"\n | \"silent\";\n\n/**\n * Application runtime configuration loaded from environment variables.\n */\nexport const Config = {\n Logger: {\n /**\n * Logging level (e.g., 'info', 'debug', 'warn', 'error').\n */\n level: Env.get(\"LOGGER_LEVEL\", \"info\") as LogLevel,\n\n /**\n * Name of the logger instance (defaults to npm package name).\n */\n name: Env.get(\"LOGGER_NAME\", Env.get(\"npm_package_name\", \"@catbee/utils\")),\n\n /**\n * Whether to use ISO 8601 timestamps in logs.\n */\n isoTimestamp: Env.getBoolean(\"LOGGER_ISO_TIMESTAMP\", false),\n },\n};\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from "./utils/array.utils";
|
|
2
|
+
export * from "./utils/async.utils";
|
|
3
|
+
export * from "./utils/cache.utils";
|
|
4
|
+
export * from "./utils/context-store.utils";
|
|
5
|
+
export * from "./utils/crypto.utils";
|
|
6
|
+
export * from "./utils/dir.utils";
|
|
7
|
+
export * from "./utils/env.utils";
|
|
8
|
+
export * from "./utils/exception.utils";
|
|
9
|
+
export * from "./utils/fs.utils";
|
|
10
|
+
export * from "./utils/http-status-codes";
|
|
11
|
+
export * from "./utils/id.utils";
|
|
12
|
+
export * from "./utils/logger.utils";
|
|
13
|
+
export * from "./utils/obj.utils";
|
|
14
|
+
export * from "./utils/response.utils";
|
|
15
|
+
export * from "./utils/string.utils";
|
|
16
|
+
export * from "./utils/url.utils";
|
|
17
|
+
export * from "./utils/validate.utils";
|
|
18
|
+
export * from "./types/api-response";
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from "./utils/array.utils";
|
|
2
|
+
export * from "./utils/async.utils";
|
|
3
|
+
export * from "./utils/cache.utils";
|
|
4
|
+
export * from "./utils/context-store.utils";
|
|
5
|
+
export * from "./utils/crypto.utils";
|
|
6
|
+
export * from "./utils/dir.utils";
|
|
7
|
+
export * from "./utils/env.utils";
|
|
8
|
+
export * from "./utils/exception.utils";
|
|
9
|
+
export * from "./utils/fs.utils";
|
|
10
|
+
export * from "./utils/http-status-codes";
|
|
11
|
+
export * from "./utils/id.utils";
|
|
12
|
+
export * from "./utils/logger.utils";
|
|
13
|
+
export * from "./utils/obj.utils";
|
|
14
|
+
export * from "./utils/response.utils";
|
|
15
|
+
export * from "./utils/string.utils";
|
|
16
|
+
export * from "./utils/url.utils";
|
|
17
|
+
export * from "./utils/validate.utils";
|
|
18
|
+
export * from "./types/api-response";
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,sBAAsB,CAAC","sourcesContent":["export * from \"./utils/array.utils\";\nexport * from \"./utils/async.utils\";\nexport * from \"./utils/cache.utils\";\nexport * from \"./utils/context-store.utils\";\nexport * from \"./utils/crypto.utils\";\nexport * from \"./utils/dir.utils\";\nexport * from \"./utils/env.utils\";\nexport * from \"./utils/exception.utils\";\nexport * from \"./utils/fs.utils\";\nexport * from \"./utils/http-status-codes\";\nexport * from \"./utils/id.utils\";\nexport * from \"./utils/logger.utils\";\nexport * from \"./utils/obj.utils\";\nexport * from \"./utils/response.utils\";\nexport * from \"./utils/string.utils\";\nexport * from \"./utils/url.utils\";\nexport * from \"./utils/validate.utils\";\n\nexport * from \"./types/api-response\";\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic API response format.
|
|
3
|
+
* Used to wrap any successful or failed response from the server.
|
|
4
|
+
*/
|
|
5
|
+
export interface ApiResponse<T = any> {
|
|
6
|
+
/** Payload returned from the API. Can be any shape depending on the endpoint. */
|
|
7
|
+
data: T | null;
|
|
8
|
+
/** Indicates whether an error occurred (true = error, false = success). */
|
|
9
|
+
error: boolean;
|
|
10
|
+
/** Human-readable message to describe the result or error. */
|
|
11
|
+
message: string;
|
|
12
|
+
/** Unique request ID for traceability in logs (e.g., from a middleware). */
|
|
13
|
+
requestId: string;
|
|
14
|
+
/** ISO timestamp when the response was generated. */
|
|
15
|
+
timestamp: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generic pagination structure used for paged lists (e.g., /users?page=1).
|
|
19
|
+
*/
|
|
20
|
+
export interface Pagination<T = any> {
|
|
21
|
+
/** List of records for the current page. */
|
|
22
|
+
content: T[];
|
|
23
|
+
/** Metadata about the pagination state. */
|
|
24
|
+
pagination: {
|
|
25
|
+
/** Total number of records across all pages. */
|
|
26
|
+
totalRecords: number;
|
|
27
|
+
/** Total number of pages available. */
|
|
28
|
+
totalPages: number;
|
|
29
|
+
/** Current page number (1-based index). */
|
|
30
|
+
page: number;
|
|
31
|
+
/** Number of records per page. */
|
|
32
|
+
limit: number;
|
|
33
|
+
/** Field by which the data is sorted. */
|
|
34
|
+
sortBy: string;
|
|
35
|
+
/** Sort order: ascending or descending. */
|
|
36
|
+
sortOrder: "asc" | "desc";
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Alias for paginated API response.
|
|
41
|
+
* Allows semantic naming like `PaginationResponse<User>` or `PaginationResponse<Post>`.
|
|
42
|
+
*/
|
|
43
|
+
export type PaginationResponse<T = any> = Pagination<T>;
|
|
44
|
+
//# sourceMappingURL=api-response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-response.js","sourceRoot":"","sources":["../../../src/types/api-response.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Generic API response format.\n * Used to wrap any successful or failed response from the server.\n */\nexport interface ApiResponse<T = any> {\n /** Payload returned from the API. Can be any shape depending on the endpoint. */\n data: T | null;\n\n /** Indicates whether an error occurred (true = error, false = success). */\n error: boolean;\n\n /** Human-readable message to describe the result or error. */\n message: string;\n\n /** Unique request ID for traceability in logs (e.g., from a middleware). */\n requestId: string;\n\n /** ISO timestamp when the response was generated. */\n timestamp: string;\n}\n\n/**\n * Generic pagination structure used for paged lists (e.g., /users?page=1).\n */\nexport interface Pagination<T = any> {\n /** List of records for the current page. */\n content: T[];\n\n /** Metadata about the pagination state. */\n pagination: {\n /** Total number of records across all pages. */\n totalRecords: number;\n\n /** Total number of pages available. */\n totalPages: number;\n\n /** Current page number (1-based index). */\n page: number;\n\n /** Number of records per page. */\n limit: number;\n\n /** Field by which the data is sorted. */\n sortBy: string;\n\n /** Sort order: ascending or descending. */\n sortOrder: \"asc\" | \"desc\";\n };\n}\n\n/**\n * Alias for paginated API response.\n * Allows semantic naming like `PaginationResponse<User>` or `PaginationResponse<Post>`.\n */\nexport type PaginationResponse<T = any> = Pagination<T>;\n"]}
|