@cyberskill/shared 3.2.0 → 3.3.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.
- package/dist/config/commitlint/index.js +8 -9
- package/dist/config/commitlint/index.js.map +1 -1
- package/dist/config/config.type.js +8 -5
- package/dist/config/config.type.js.map +1 -1
- package/dist/config/config.util.js +33 -42
- package/dist/config/config.util.js.map +1 -1
- package/dist/config/env/env.constant.js +6 -5
- package/dist/config/env/env.constant.js.map +1 -1
- package/dist/config/env/env.util.js +26 -27
- package/dist/config/env/env.util.js.map +1 -1
- package/dist/config/env/index.js +2 -7
- package/dist/config/eslint/index.js +23 -19
- package/dist/config/eslint/index.js.map +1 -1
- package/dist/config/graphql-codegen/graphql-codegen.util.js +30 -38
- package/dist/config/graphql-codegen/graphql-codegen.util.js.map +1 -1
- package/dist/config/graphql-codegen/index.js +2 -5
- package/dist/config/index.js +3 -7
- package/dist/config/lint-staged/index.js +8 -7
- package/dist/config/lint-staged/index.js.map +1 -1
- package/dist/config/storybook/index.js +2 -6
- package/dist/config/storybook/storybook.main.js +19 -18
- package/dist/config/storybook/storybook.main.js.map +1 -1
- package/dist/config/storybook/storybook.preview.js +31 -37
- package/dist/config/storybook/storybook.preview.js.map +1 -1
- package/dist/config/vitest/index.js +3 -7
- package/dist/config/vitest/vitest.e2e.js +14 -17
- package/dist/config/vitest/vitest.e2e.js.map +1 -1
- package/dist/config/vitest/vitest.unit.js +31 -32
- package/dist/config/vitest/vitest.unit.js.map +1 -1
- package/dist/constant/common.js +6 -5
- package/dist/constant/common.js.map +1 -1
- package/dist/constant/index.js +3 -7
- package/dist/constant/response-status.d.ts +186 -186
- package/dist/constant/response-status.js +254 -253
- package/dist/constant/response-status.js.map +1 -1
- package/dist/node/apollo-server/apollo-server.util.js +27 -29
- package/dist/node/apollo-server/apollo-server.util.js.map +1 -1
- package/dist/node/apollo-server/index.js +2 -7
- package/dist/node/cli/index.js +112 -113
- package/dist/node/cli/index.js.map +1 -1
- package/dist/node/command/command.type.js +8 -5
- package/dist/node/command/command.type.js.map +1 -1
- package/dist/node/command/command.util.js +136 -149
- package/dist/node/command/command.util.js.map +1 -1
- package/dist/node/command/index.js +3 -12
- package/dist/node/express/express.type.d.ts +11 -0
- package/dist/node/express/express.type.js +2 -0
- package/dist/node/express/express.util.js +74 -65
- package/dist/node/express/express.util.js.map +1 -1
- package/dist/node/express/index.js +3 -14
- package/dist/node/fs/fs.util.js +27 -51
- package/dist/node/fs/fs.util.js.map +1 -1
- package/dist/node/fs/index.js +2 -19
- package/dist/node/log/index.js +2 -8
- package/dist/node/log/log.type.js +8 -5
- package/dist/node/log/log.type.js.map +1 -1
- package/dist/node/log/log.util.js +51 -68
- package/dist/node/log/log.util.js.map +1 -1
- package/dist/node/mongo/index.js +8 -26
- package/dist/node/mongo/mongo.constant.js +6 -6
- package/dist/node/mongo/mongo.constant.js.map +1 -1
- package/dist/node/mongo/mongo.controller.mongoose.d.ts +6 -1
- package/dist/node/mongo/mongo.controller.mongoose.js +333 -467
- package/dist/node/mongo/mongo.controller.mongoose.js.map +1 -1
- package/dist/node/mongo/mongo.controller.native.js +153 -212
- package/dist/node/mongo/mongo.controller.native.js.map +1 -1
- package/dist/node/mongo/mongo.dynamic-populate.js +164 -192
- package/dist/node/mongo/mongo.dynamic-populate.js.map +1 -1
- package/dist/node/mongo/mongo.populate.js +229 -262
- package/dist/node/mongo/mongo.populate.js.map +1 -1
- package/dist/node/mongo/mongo.type.js +8 -17
- package/dist/node/mongo/mongo.type.js.map +1 -1
- package/dist/node/mongo/mongo.util.js +134 -293
- package/dist/node/mongo/mongo.util.js.map +1 -1
- package/dist/node/package/index.js +3 -11
- package/dist/node/package/package.type.js +8 -5
- package/dist/node/package/package.type.js.map +1 -1
- package/dist/node/package/package.util.js +216 -225
- package/dist/node/package/package.util.js.map +1 -1
- package/dist/node/path/index.js +3 -58
- package/dist/node/path/path.constant.js +211 -298
- package/dist/node/path/path.constant.js.map +1 -1
- package/dist/node/path/path.util.js +13 -16
- package/dist/node/path/path.util.js.map +1 -1
- package/dist/node/storage/index.js +3 -10
- package/dist/node/storage/storage.constant.js +6 -8
- package/dist/node/storage/storage.constant.js.map +1 -1
- package/dist/node/storage/storage.util.js +127 -178
- package/dist/node/storage/storage.util.js.map +1 -1
- package/dist/node/upload/index.js +4 -16
- package/dist/node/upload/upload.constant.js +58 -32
- package/dist/node/upload/upload.constant.js.map +1 -1
- package/dist/node/upload/upload.type.js +8 -5
- package/dist/node/upload/upload.type.js.map +1 -1
- package/dist/node/upload/upload.util.js +125 -137
- package/dist/node/upload/upload.util.js.map +1 -1
- package/dist/node/ws/index.js +2 -6
- package/dist/node/ws/ws.type.d.ts +7 -8
- package/dist/node/ws/ws.util.js +46 -44
- package/dist/node/ws/ws.util.js.map +1 -1
- package/dist/node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.0_@types_nod_53aa4254f295b3c40bb8f17b6ab226b5/node_modules/vitest/dist/config.js +8 -0
- package/dist/node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.0_@types_nod_53aa4254f295b3c40bb8f17b6ab226b5/node_modules/vitest/dist/config.js.map +1 -0
- package/dist/react/apollo-client/apollo-client.component.js +16 -18
- package/dist/react/apollo-client/apollo-client.component.js.map +1 -1
- package/dist/react/apollo-client/apollo-client.constant.js +6 -5
- package/dist/react/apollo-client/apollo-client.constant.js.map +1 -1
- package/dist/react/apollo-client/apollo-client.context.js +10 -13
- package/dist/react/apollo-client/apollo-client.context.js.map +1 -1
- package/dist/react/apollo-client/apollo-client.module.scss.js +8 -7
- package/dist/react/apollo-client/apollo-client.module.scss.js.map +1 -1
- package/dist/react/apollo-client/apollo-client.util.js +57 -75
- package/dist/react/apollo-client/apollo-client.util.js.map +1 -1
- package/dist/react/apollo-client/index.js +7 -30
- package/dist/react/apollo-client/links/index.js +2 -5
- package/dist/react/apollo-client/links/upload.js +63 -107
- package/dist/react/apollo-client/links/upload.js.map +1 -1
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.js +14 -16
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.js.map +1 -1
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.rsc.js +8 -7
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.rsc.js.map +1 -1
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.js +14 -14
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.js.map +1 -1
- package/dist/react/apollo-client-nextjs/index.js +3 -7
- package/dist/react/apollo-error/apollo-error.component.js +57 -69
- package/dist/react/apollo-error/apollo-error.component.js.map +1 -1
- package/dist/react/apollo-error/apollo-error.context.js +7 -6
- package/dist/react/apollo-error/apollo-error.context.js.map +1 -1
- package/dist/react/apollo-error/apollo-error.hook.js +10 -10
- package/dist/react/apollo-error/apollo-error.hook.js.map +1 -1
- package/dist/react/apollo-error/apollo-error.module.scss.js +15 -11
- package/dist/react/apollo-error/apollo-error.module.scss.js.map +1 -1
- package/dist/react/apollo-error/apollo-error.provider.js +31 -25
- package/dist/react/apollo-error/apollo-error.provider.js.map +1 -1
- package/dist/react/apollo-error/apollo-error.util.js +14 -16
- package/dist/react/apollo-error/apollo-error.util.js.map +1 -1
- package/dist/react/apollo-error/index.js +5 -15
- package/dist/react/i18next/i18next.hook.js +7 -6
- package/dist/react/i18next/i18next.hook.js.map +1 -1
- package/dist/react/i18next/i18next.util.js +9 -8
- package/dist/react/i18next/i18next.util.js.map +1 -1
- package/dist/react/i18next/index.js +3 -7
- package/dist/react/loading/index.js +3 -9
- package/dist/react/loading/loading.component.js +47 -48
- package/dist/react/loading/loading.component.js.map +1 -1
- package/dist/react/loading/loading.context.js +7 -6
- package/dist/react/loading/loading.context.js.map +1 -1
- package/dist/react/loading/loading.hook.js +11 -11
- package/dist/react/loading/loading.hook.js.map +1 -1
- package/dist/react/loading/loading.module.scss.js +18 -15
- package/dist/react/loading/loading.module.scss.js.map +1 -1
- package/dist/react/loading/loading.provider.js +26 -18
- package/dist/react/loading/loading.provider.js.map +1 -1
- package/dist/react/log/index.js +2 -6
- package/dist/react/log/log.util.d.ts +8 -0
- package/dist/react/log/log.util.js +33 -29
- package/dist/react/log/log.util.js.map +1 -1
- package/dist/react/next-intl/index.js +6 -14
- package/dist/react/next-intl/next-intl.constant.js +16 -15
- package/dist/react/next-intl/next-intl.constant.js.map +1 -1
- package/dist/react/next-intl/next-intl.context.js +7 -6
- package/dist/react/next-intl/next-intl.context.js.map +1 -1
- package/dist/react/next-intl/next-intl.hoc.js +20 -23
- package/dist/react/next-intl/next-intl.hoc.js.map +1 -1
- package/dist/react/next-intl/next-intl.hook.js +13 -14
- package/dist/react/next-intl/next-intl.hook.js.map +1 -1
- package/dist/react/next-intl/next-intl.provider.js +28 -23
- package/dist/react/next-intl/next-intl.provider.js.map +1 -1
- package/dist/react/storage/index.js +3 -7
- package/dist/react/storage/storage.hook.js +61 -58
- package/dist/react/storage/storage.hook.js.map +1 -1
- package/dist/react/storage/storage.util.js +36 -68
- package/dist/react/storage/storage.util.js.map +1 -1
- package/dist/react/toast/index.js +2 -6
- package/dist/react/userback/index.js +2 -5
- package/dist/react/userback/userback.component.js +27 -27
- package/dist/react/userback/userback.component.js.map +1 -1
- package/dist/style.css +2 -1
- package/dist/typescript/common.type.js +8 -5
- package/dist/typescript/common.type.js.map +1 -1
- package/dist/typescript/index.js +2 -5
- package/dist/util/common/common.util.js +119 -48
- package/dist/util/common/common.util.js.map +1 -1
- package/dist/util/common/index.js +2 -9
- package/dist/util/index.js +6 -27
- package/dist/util/object/index.d.ts +3 -0
- package/dist/util/object/index.js +2 -10
- package/dist/util/object/object.util.js +94 -128
- package/dist/util/object/object.util.js.map +1 -1
- package/dist/util/serializer/index.js +2 -5
- package/dist/util/serializer/serializer.util.js +73 -78
- package/dist/util/serializer/serializer.util.js.map +1 -1
- package/dist/util/string/index.d.ts +3 -0
- package/dist/util/string/index.js +2 -10
- package/dist/util/string/string.util.js +59 -71
- package/dist/util/string/string.util.js.map +1 -1
- package/dist/util/validate/index.d.ts +3 -0
- package/dist/util/validate/index.js +2 -5
- package/dist/util/validate/validate.util.js +13 -39
- package/dist/util/validate/validate.util.js.map +1 -1
- package/package.json +29 -27
- package/dist/config/env/index.js.map +0 -1
- package/dist/config/graphql-codegen/index.js.map +0 -1
- package/dist/config/index.js.map +0 -1
- package/dist/config/storybook/index.js.map +0 -1
- package/dist/config/vitest/index.js.map +0 -1
- package/dist/constant/index.js.map +0 -1
- package/dist/node/apollo-server/index.js.map +0 -1
- package/dist/node/command/index.js.map +0 -1
- package/dist/node/express/index.js.map +0 -1
- package/dist/node/fs/index.js.map +0 -1
- package/dist/node/log/index.js.map +0 -1
- package/dist/node/mongo/index.js.map +0 -1
- package/dist/node/package/index.js.map +0 -1
- package/dist/node/path/index.js.map +0 -1
- package/dist/node/storage/index.js.map +0 -1
- package/dist/node/upload/index.js.map +0 -1
- package/dist/node/ws/index.js.map +0 -1
- package/dist/node_modules/.pnpm/vitest@4.0.18_@types_node@25.3.5_jiti@2.6.1_jsdom@28.1.0_@noble_hashes@1.8.0__sass@1.97.3_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/dist/config.js +0 -7
- package/dist/node_modules/.pnpm/vitest@4.0.18_@types_node@25.3.5_jiti@2.6.1_jsdom@28.1.0_@noble_hashes@1.8.0__sass@1.97.3_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/dist/config.js.map +0 -1
- package/dist/react/apollo-client/index.js.map +0 -1
- package/dist/react/apollo-client/links/index.js.map +0 -1
- package/dist/react/apollo-client-nextjs/index.js.map +0 -1
- package/dist/react/apollo-error/index.js.map +0 -1
- package/dist/react/i18next/index.js.map +0 -1
- package/dist/react/loading/index.js.map +0 -1
- package/dist/react/log/index.js.map +0 -1
- package/dist/react/next-intl/index.js.map +0 -1
- package/dist/react/storage/index.js.map +0 -1
- package/dist/react/toast/index.js.map +0 -1
- package/dist/react/userback/index.js.map +0 -1
- package/dist/typescript/index.js.map +0 -1
- package/dist/util/common/index.js.map +0 -1
- package/dist/util/index.js.map +0 -1
- package/dist/util/object/index.js.map +0 -1
- package/dist/util/serializer/index.js.map +0 -1
- package/dist/util/string/index.js.map +0 -1
- package/dist/util/validate/index.js.map +0 -1
|
@@ -1,468 +1,334 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
* This method generates multiple slug variations and finds the first available one.
|
|
331
|
-
*
|
|
332
|
-
* @param options - Configuration for slug generation including slug, field, and filter.
|
|
333
|
-
* @param options.slug - The base slug string to make unique.
|
|
334
|
-
* @param options.field - The field name for object-based slug checking.
|
|
335
|
-
* @param options.isObject - Whether the slug is stored as an object with nested fields.
|
|
336
|
-
* @param options.haveHistory - Whether to check historical slug fields for uniqueness.
|
|
337
|
-
* @param options.filter - Additional filter conditions to apply when checking slug existence.
|
|
338
|
-
* @returns A promise that resolves to a unique slug string.
|
|
339
|
-
*/
|
|
340
|
-
async createUniqueSlug({ slug: r, field: e, isObject: s, haveHistory: t, filter: a }) {
|
|
341
|
-
if (!r || typeof r != "string")
|
|
342
|
-
throw new Error("Invalid slug provided: must be a non-empty string");
|
|
343
|
-
const c = p(r);
|
|
344
|
-
if (!await this.model.exists(
|
|
345
|
-
this.createSlugQuery({ slug: c, field: e, isObject: s, haveHistory: t, filter: a })
|
|
346
|
-
))
|
|
347
|
-
return c;
|
|
348
|
-
for (let l = 1; l <= S; l++) {
|
|
349
|
-
const m = `${c}-${l}`;
|
|
350
|
-
if (!await this.model.exists(
|
|
351
|
-
this.createSlugQuery({ slug: m, field: e, isObject: s, haveHistory: t, filter: a })
|
|
352
|
-
))
|
|
353
|
-
return m;
|
|
354
|
-
}
|
|
355
|
-
const i = Date.now(), o = V(6);
|
|
356
|
-
return `${c}-${i}-${o}`;
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* Creates a slug for a document field.
|
|
360
|
-
* This method handles both simple string fields and object fields with nested slug generation.
|
|
361
|
-
*
|
|
362
|
-
* @param options - Configuration for slug creation including field, source document, and filter.
|
|
363
|
-
* @param options.field - The field name to create a slug for.
|
|
364
|
-
* @param options.from - The source document containing the field value.
|
|
365
|
-
* @param options.haveHistory - Whether to check historical slug fields for uniqueness.
|
|
366
|
-
* @param options.filter - Additional filter conditions to apply when checking slug existence.
|
|
367
|
-
* @returns A promise that resolves to a standardized response with the created slug(s).
|
|
368
|
-
*/
|
|
369
|
-
async createSlug({ field: r, from: e, filter: s, haveHistory: t }) {
|
|
370
|
-
try {
|
|
371
|
-
const a = e[r];
|
|
372
|
-
return O(a) ? { success: !0, result: Object.fromEntries(
|
|
373
|
-
await Promise.all(
|
|
374
|
-
Object.entries(a).map(async ([o, l]) => {
|
|
375
|
-
const m = await this.createUniqueSlug({
|
|
376
|
-
slug: l,
|
|
377
|
-
field: o,
|
|
378
|
-
isObject: !0,
|
|
379
|
-
haveHistory: t,
|
|
380
|
-
filter: s
|
|
381
|
-
});
|
|
382
|
-
return [o, m];
|
|
383
|
-
})
|
|
384
|
-
)
|
|
385
|
-
) } : { success: !0, result: await this.createUniqueSlug({
|
|
386
|
-
slug: a,
|
|
387
|
-
field: r,
|
|
388
|
-
isObject: !1,
|
|
389
|
-
haveHistory: t,
|
|
390
|
-
filter: s
|
|
391
|
-
}) };
|
|
392
|
-
} catch (a) {
|
|
393
|
-
return u(a);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
/**
|
|
397
|
-
* Checks if a slug already exists in the collection.
|
|
398
|
-
* This method verifies slug existence in both current and historical slug fields.
|
|
399
|
-
*
|
|
400
|
-
* @param options - Configuration for slug checking including slug, field, source document, and filter.
|
|
401
|
-
* @param options.slug - The slug string to check for existence.
|
|
402
|
-
* @param options.field - The field name for object-based slug checking.
|
|
403
|
-
* @param options.from - The source document containing the field value.
|
|
404
|
-
* @param options.haveHistory - Whether to check historical slug fields for existence.
|
|
405
|
-
* @param options.filter - Additional filter conditions to apply to the query.
|
|
406
|
-
* @returns A promise that resolves to a standardized response indicating whether the slug exists.
|
|
407
|
-
*/
|
|
408
|
-
async checkSlug({ slug: r, field: e, from: s, filter: t, haveHistory: a }) {
|
|
409
|
-
try {
|
|
410
|
-
const c = s[e];
|
|
411
|
-
if (O(c)) {
|
|
412
|
-
const m = Object.values(c).map((h) => p(h));
|
|
413
|
-
return (await Promise.all(
|
|
414
|
-
m.map(
|
|
415
|
-
(h) => this.model.exists(this.createSlugQuery({
|
|
416
|
-
slug: h,
|
|
417
|
-
field: e,
|
|
418
|
-
isObject: !0,
|
|
419
|
-
haveHistory: a,
|
|
420
|
-
filter: t
|
|
421
|
-
}))
|
|
422
|
-
)
|
|
423
|
-
)).some((h) => h) ? { success: !0, result: !0 } : { success: !0, result: !1 };
|
|
424
|
-
}
|
|
425
|
-
const i = p(r);
|
|
426
|
-
return { success: !0, result: await this.model.exists(this.createSlugQuery({
|
|
427
|
-
slug: i,
|
|
428
|
-
field: e,
|
|
429
|
-
isObject: !1,
|
|
430
|
-
filter: t
|
|
431
|
-
})) !== null };
|
|
432
|
-
} catch (c) {
|
|
433
|
-
return u(c);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Performs aggregation operations on the collection.
|
|
438
|
-
*
|
|
439
|
-
* @param pipeline - The aggregation pipeline stages to execute.
|
|
440
|
-
* @returns A promise that resolves to a standardized response with the aggregation results.
|
|
441
|
-
*/
|
|
442
|
-
async aggregate(r) {
|
|
443
|
-
try {
|
|
444
|
-
return { success: !0, result: await this.model.aggregate(r) };
|
|
445
|
-
} catch (e) {
|
|
446
|
-
return u(e);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Retrieves distinct values for the specified key from the collection.
|
|
451
|
-
*
|
|
452
|
-
* @param key - The field for which to return distinct values.
|
|
453
|
-
* @param filter - The filter query to apply (optional).
|
|
454
|
-
* @param options - Additional options for the distinct operation (optional).
|
|
455
|
-
* @returns A promise that resolves to a standardized response with the array of distinct values.
|
|
456
|
-
*/
|
|
457
|
-
async distinct(r, e = {}, s = {}) {
|
|
458
|
-
try {
|
|
459
|
-
return { success: !0, result: await this.model.distinct(r, e, s) };
|
|
460
|
-
} catch (t) {
|
|
461
|
-
return u(t);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
export {
|
|
466
|
-
R as MongooseController
|
|
1
|
+
import { normalizeMongoFilter as e } from "../../util/object/object.util.js";
|
|
2
|
+
import { generateRandomString as t, generateShortId as n, generateSlug as r } from "../../util/string/string.util.js";
|
|
3
|
+
import { RESPONSE_STATUS as i } from "../../constant/response-status.js";
|
|
4
|
+
import { catchError as a } from "../log/log.util.js";
|
|
5
|
+
import "./mongo.constant.js";
|
|
6
|
+
import { filterDynamicVirtualsFromPopulate as o, isObject as s, populateDynamicVirtuals as c } from "./mongo.dynamic-populate.js";
|
|
7
|
+
//#region src/node/mongo/mongo.controller.mongoose.ts
|
|
8
|
+
var l = class {
|
|
9
|
+
defaultLimit;
|
|
10
|
+
constructor(e, t) {
|
|
11
|
+
this.model = e, this.defaultLimit = t?.defaultLimit ?? 1e4;
|
|
12
|
+
}
|
|
13
|
+
getModelName() {
|
|
14
|
+
return this.model.modelName;
|
|
15
|
+
}
|
|
16
|
+
getDynamicVirtuals() {
|
|
17
|
+
let e = this.model;
|
|
18
|
+
if (e._virtualConfigs) {
|
|
19
|
+
let t = e._virtualConfigs.filter((e) => typeof e.options?.ref == "function");
|
|
20
|
+
if (t.length > 0) return t;
|
|
21
|
+
}
|
|
22
|
+
return this.model.schema.statics._dynamicVirtuals;
|
|
23
|
+
}
|
|
24
|
+
async populateDynamicVirtualsForDocument(e, t) {
|
|
25
|
+
let n = this.getDynamicVirtuals();
|
|
26
|
+
if (n && n.length > 0) {
|
|
27
|
+
let r = await c(this.model.base, [e], n, t, void 0, this.model);
|
|
28
|
+
return r && r[0] ? r[0] : e;
|
|
29
|
+
}
|
|
30
|
+
return e;
|
|
31
|
+
}
|
|
32
|
+
async populateDynamicVirtualsForDocuments(e, t) {
|
|
33
|
+
let n = this.getDynamicVirtuals();
|
|
34
|
+
return n && n.length > 0 && e.length > 0 ? await c(this.model.base, e, n, t, void 0, this.model) : e;
|
|
35
|
+
}
|
|
36
|
+
async findOne(t = {}, n = {}, r = {}, s) {
|
|
37
|
+
try {
|
|
38
|
+
let a = e(t), c = this.model.findOne(a, n, r).maxTimeMS(3e4).lean(), l = o(s, this.getDynamicVirtuals());
|
|
39
|
+
l && c.populate(l);
|
|
40
|
+
let u = await c.exec();
|
|
41
|
+
if (!u) return {
|
|
42
|
+
success: !1,
|
|
43
|
+
message: `No ${this.getModelName()} found.`,
|
|
44
|
+
code: i.NOT_FOUND.CODE
|
|
45
|
+
};
|
|
46
|
+
let d = await this.populateDynamicVirtualsForDocument(u, s);
|
|
47
|
+
return {
|
|
48
|
+
success: !0,
|
|
49
|
+
result: d?.toObject?.() ?? d
|
|
50
|
+
};
|
|
51
|
+
} catch (e) {
|
|
52
|
+
return a(e);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async findAll(t = {}, n = {}, r = {}, i) {
|
|
56
|
+
try {
|
|
57
|
+
let a = e(t), s = this.model.find(a, n, r).maxTimeMS(3e4).lean();
|
|
58
|
+
r.limit || s.limit(this.defaultLimit);
|
|
59
|
+
let c = o(i, this.getDynamicVirtuals());
|
|
60
|
+
c && s.populate(c);
|
|
61
|
+
let l = await s.exec();
|
|
62
|
+
return {
|
|
63
|
+
success: !0,
|
|
64
|
+
result: (await this.populateDynamicVirtualsForDocuments(l, i)).map((e) => e?.toObject?.() ?? e)
|
|
65
|
+
};
|
|
66
|
+
} catch (e) {
|
|
67
|
+
return a(e);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async findPaging(t = {}, n = {}) {
|
|
71
|
+
try {
|
|
72
|
+
let r = e(t), i = this.getDynamicVirtuals(), a = { ...n };
|
|
73
|
+
n.populate && (a.populate = o(n.populate, i));
|
|
74
|
+
let s = await this.model.paginate(r, a);
|
|
75
|
+
if (i && i.length > 0) {
|
|
76
|
+
let e = await this.populateDynamicVirtualsForDocuments(s.docs, n.populate);
|
|
77
|
+
return {
|
|
78
|
+
success: !0,
|
|
79
|
+
result: {
|
|
80
|
+
...s,
|
|
81
|
+
docs: e.map((e) => e?.toObject?.() ?? e)
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
success: !0,
|
|
87
|
+
result: {
|
|
88
|
+
...s,
|
|
89
|
+
docs: s.docs.map((e) => e?.toObject?.() ?? e)
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
} catch (e) {
|
|
93
|
+
return a(e);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async findPagingAggregate(e, t = {}) {
|
|
97
|
+
try {
|
|
98
|
+
let n = this.getDynamicVirtuals(), r = { ...t };
|
|
99
|
+
t.populate && (r.populate = o(t.populate, n));
|
|
100
|
+
let i = await this.model.aggregatePaginate(this.model.aggregate(e), r), a = await this.populateDynamicVirtualsForDocuments(i.docs, t.populate);
|
|
101
|
+
return {
|
|
102
|
+
success: !0,
|
|
103
|
+
result: {
|
|
104
|
+
...i,
|
|
105
|
+
docs: a.map((e) => e?.toObject?.() ?? e)
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
} catch (e) {
|
|
109
|
+
return a(e);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async count(t = {}) {
|
|
113
|
+
try {
|
|
114
|
+
let n = e(t);
|
|
115
|
+
return {
|
|
116
|
+
success: !0,
|
|
117
|
+
result: await this.model.countDocuments(n)
|
|
118
|
+
};
|
|
119
|
+
} catch (e) {
|
|
120
|
+
return a(e);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async createOne(e) {
|
|
124
|
+
try {
|
|
125
|
+
let t = await this.model.create(e);
|
|
126
|
+
return {
|
|
127
|
+
success: !0,
|
|
128
|
+
result: t?.toObject?.() ?? t
|
|
129
|
+
};
|
|
130
|
+
} catch (e) {
|
|
131
|
+
return a(e);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async createMany(e, t = {}) {
|
|
135
|
+
try {
|
|
136
|
+
return {
|
|
137
|
+
success: !0,
|
|
138
|
+
result: (await this.model.insertMany(e, t)).map((e) => e?.toObject?.() ?? e)
|
|
139
|
+
};
|
|
140
|
+
} catch (e) {
|
|
141
|
+
return a(e);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async updateOne(t = {}, n = {}, r = {}) {
|
|
145
|
+
try {
|
|
146
|
+
let a = e(t), o = await this.model.findOneAndUpdate(a, n, {
|
|
147
|
+
new: !0,
|
|
148
|
+
...r
|
|
149
|
+
}).exec();
|
|
150
|
+
return o ? {
|
|
151
|
+
success: !0,
|
|
152
|
+
result: o?.toObject?.() ?? o
|
|
153
|
+
} : {
|
|
154
|
+
success: !1,
|
|
155
|
+
message: `Failed to update ${this.getModelName()}.`,
|
|
156
|
+
code: i.NOT_FOUND.CODE
|
|
157
|
+
};
|
|
158
|
+
} catch (e) {
|
|
159
|
+
return a(e);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async updateMany(t = {}, n = {}, r = {}) {
|
|
163
|
+
try {
|
|
164
|
+
let i = e(t);
|
|
165
|
+
return {
|
|
166
|
+
success: !0,
|
|
167
|
+
result: await this.model.updateMany(i, n, r).exec()
|
|
168
|
+
};
|
|
169
|
+
} catch (e) {
|
|
170
|
+
return a(e);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async deleteOne(t = {}, n = {}) {
|
|
174
|
+
try {
|
|
175
|
+
let r = e(t), a = await this.model.findOneAndDelete(r, n).exec();
|
|
176
|
+
return a ? {
|
|
177
|
+
success: !0,
|
|
178
|
+
result: a?.toObject?.() ?? a
|
|
179
|
+
} : {
|
|
180
|
+
success: !1,
|
|
181
|
+
message: `No ${this.getModelName()} found to delete.`,
|
|
182
|
+
code: i.NOT_FOUND.CODE
|
|
183
|
+
};
|
|
184
|
+
} catch (e) {
|
|
185
|
+
return a(e);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async deleteMany(t = {}, n = {}) {
|
|
189
|
+
try {
|
|
190
|
+
let r = e(t), a = await this.model.deleteMany(r, n).exec();
|
|
191
|
+
return a.deletedCount === 0 ? {
|
|
192
|
+
success: !1,
|
|
193
|
+
message: "No documents found to delete.",
|
|
194
|
+
code: i.NOT_FOUND.CODE
|
|
195
|
+
} : {
|
|
196
|
+
success: !0,
|
|
197
|
+
result: a
|
|
198
|
+
};
|
|
199
|
+
} catch (e) {
|
|
200
|
+
return a(e);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async createShortId(e, t = 4) {
|
|
204
|
+
try {
|
|
205
|
+
let r = Array.from({ length: 10 }, (r, i) => n(e, i + t)), a = (await Promise.all(r.map((e) => this.model.exists({ shortId: e })))).findIndex((e) => !e);
|
|
206
|
+
if (a !== -1) {
|
|
207
|
+
let e = r[a];
|
|
208
|
+
if (e) return {
|
|
209
|
+
success: !0,
|
|
210
|
+
result: e
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
success: !1,
|
|
215
|
+
message: "Failed to create a unique shortId",
|
|
216
|
+
code: i.INTERNAL_SERVER_ERROR.CODE
|
|
217
|
+
};
|
|
218
|
+
} catch (e) {
|
|
219
|
+
return a(e);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
createSlugQuery({ slug: e, field: t, isObject: n, haveHistory: r = !1, filter: i }) {
|
|
223
|
+
let a = { ...i ?? {} };
|
|
224
|
+
return n ? {
|
|
225
|
+
...a,
|
|
226
|
+
$or: [{ [`slug.${t}`]: e }, ...r ? [{ slugHistory: { $elemMatch: { [`slug.${t}`]: e } } }] : []]
|
|
227
|
+
} : {
|
|
228
|
+
...a,
|
|
229
|
+
$or: [{ slug: e }, ...r ? [{ slugHistory: e }] : []]
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
async createUniqueSlug({ slug: e, field: n, isObject: i, haveHistory: a, filter: o }) {
|
|
233
|
+
if (!e || typeof e != "string") throw Error("Invalid slug provided: must be a non-empty string");
|
|
234
|
+
let s = r(e);
|
|
235
|
+
if (!await this.model.exists(this.createSlugQuery({
|
|
236
|
+
slug: s,
|
|
237
|
+
field: n,
|
|
238
|
+
isObject: i,
|
|
239
|
+
haveHistory: a,
|
|
240
|
+
filter: o
|
|
241
|
+
}))) return s;
|
|
242
|
+
let c = Array.from({ length: 100 }, (e, t) => `${s}-${t + 1}`), l = c.map((e) => this.createSlugQuery({
|
|
243
|
+
slug: e,
|
|
244
|
+
field: n,
|
|
245
|
+
isObject: i,
|
|
246
|
+
haveHistory: a,
|
|
247
|
+
filter: o
|
|
248
|
+
})), u = i ? `slug.${n}` : "slug", d = await this.model.find({ $or: l.map((e) => e.$or).flat() }).select(u).lean(), f = new Set(d.map((e) => i ? e?.slug?.[n] : e?.slug));
|
|
249
|
+
return c.find((e) => !f.has(e)) || `${s}-${Date.now()}-${t(6)}`;
|
|
250
|
+
}
|
|
251
|
+
async createSlug({ field: e, from: t, filter: n, haveHistory: r }) {
|
|
252
|
+
try {
|
|
253
|
+
let i = t[e];
|
|
254
|
+
return s(i) ? {
|
|
255
|
+
success: !0,
|
|
256
|
+
result: Object.fromEntries(await Promise.all(Object.entries(i).map(async ([e, t]) => [e, await this.createUniqueSlug({
|
|
257
|
+
slug: t,
|
|
258
|
+
field: e,
|
|
259
|
+
isObject: !0,
|
|
260
|
+
haveHistory: r,
|
|
261
|
+
filter: n
|
|
262
|
+
})])))
|
|
263
|
+
} : {
|
|
264
|
+
success: !0,
|
|
265
|
+
result: await this.createUniqueSlug({
|
|
266
|
+
slug: i,
|
|
267
|
+
field: e,
|
|
268
|
+
isObject: !1,
|
|
269
|
+
haveHistory: r,
|
|
270
|
+
filter: n
|
|
271
|
+
})
|
|
272
|
+
};
|
|
273
|
+
} catch (e) {
|
|
274
|
+
return a(e);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
async checkSlug({ slug: e, field: t, from: n, filter: i, haveHistory: o }) {
|
|
278
|
+
try {
|
|
279
|
+
let a = n[t];
|
|
280
|
+
if (s(a)) {
|
|
281
|
+
let e = Object.values(a).map((e) => r(e));
|
|
282
|
+
return (await Promise.all(e.map((e) => this.model.exists(this.createSlugQuery({
|
|
283
|
+
slug: e,
|
|
284
|
+
field: t,
|
|
285
|
+
isObject: !0,
|
|
286
|
+
haveHistory: o,
|
|
287
|
+
filter: i
|
|
288
|
+
}))))).some((e) => e) ? {
|
|
289
|
+
success: !0,
|
|
290
|
+
result: !0
|
|
291
|
+
} : {
|
|
292
|
+
success: !0,
|
|
293
|
+
result: !1
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
let c = r(e);
|
|
297
|
+
return {
|
|
298
|
+
success: !0,
|
|
299
|
+
result: await this.model.exists(this.createSlugQuery({
|
|
300
|
+
slug: c,
|
|
301
|
+
field: t,
|
|
302
|
+
isObject: !1,
|
|
303
|
+
filter: i
|
|
304
|
+
})) !== null
|
|
305
|
+
};
|
|
306
|
+
} catch (e) {
|
|
307
|
+
return a(e);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
async aggregate(e) {
|
|
311
|
+
try {
|
|
312
|
+
return {
|
|
313
|
+
success: !0,
|
|
314
|
+
result: await this.model.aggregate(e)
|
|
315
|
+
};
|
|
316
|
+
} catch (e) {
|
|
317
|
+
return a(e);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
async distinct(e, t = {}, n = {}) {
|
|
321
|
+
try {
|
|
322
|
+
return {
|
|
323
|
+
success: !0,
|
|
324
|
+
result: await this.model.distinct(e, t, n)
|
|
325
|
+
};
|
|
326
|
+
} catch (e) {
|
|
327
|
+
return a(e);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
467
330
|
};
|
|
468
|
-
//#
|
|
331
|
+
//#endregion
|
|
332
|
+
export { l as MongooseController };
|
|
333
|
+
|
|
334
|
+
//# sourceMappingURL=mongo.controller.mongoose.js.map
|