@slango/mangusta 2.1.39 → 2.1.41

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slango/mangusta",
3
- "version": "2.1.39",
3
+ "version": "2.1.41",
4
4
  "private": false,
5
5
  "description": "Mongoose middlewares and utilities",
6
6
  "repository": {
@@ -9,6 +9,9 @@
9
9
  "directory": "packages/mangusta"
10
10
  },
11
11
  "type": "module",
12
+ "files": [
13
+ "dist"
14
+ ],
12
15
  "exports": {
13
16
  "./*": {
14
17
  "import": "./dist/*.js",
@@ -37,13 +40,13 @@
37
40
  "@types/bcrypt": "6.0.0",
38
41
  "@vitest/coverage-v8": "4.1.10",
39
42
  "@vitest/ui": "4.1.10",
40
- "eslint": "10.6.0",
43
+ "eslint": "10.7.0",
41
44
  "mongoose": "9.7.4",
42
45
  "typescript": "6.0.3",
43
46
  "vitest": "^4.1.10",
44
- "@slango.configs/eslint": "1.2.31",
45
- "@slango.configs/typescript": "2.0.8",
46
- "@slango.configs/vitest": "2.0.40"
47
+ "@slango.configs/eslint": "1.2.33",
48
+ "@slango.configs/vitest": "2.0.42",
49
+ "@slango.configs/typescript": "2.0.10"
47
50
  },
48
51
  "scripts": {
49
52
  "build": "tsc -p tsconfig.build.json",
@@ -1 +0,0 @@
1
- $ tsc -p tsconfig.build.json
@@ -1 +0,0 @@
1
- $ eslint . --max-warnings 0
@@ -1,29 +0,0 @@
1
- $ vitest --run
2
-
3
-  RUN  v4.1.10 /home/runner/work/slango/slango/packages/mangusta
4
-
5
- stdout | src/middleware/tags.spec.ts
6
- Downloading MongoDB "8.2.6": 0% (0mb / 122.6mb)
7
-
8
- stdout | src/middleware/tags.spec.ts
9
- Downloading MongoDB "8.2.6": 82.1% (100.7mb / 122.6mb)
10
-
11
- stdout | src/middleware/tags.spec.ts
12
- Downloading MongoDB "8.2.6": 100% (122.6mb / 122.6mb)
13
-
14
- stdout | src/middleware/tags.spec.ts
15
- Downloading MongoDB "8.2.6": 100% (0mb / 0mb)
16
-
17
- ✓ src/middleware/tags.spec.ts (8 tests) 7270ms
18
- ✓ src/middleware/email.spec.ts (7 tests) 244ms
19
- ✓ src/middleware/owner.spec.ts (6 tests) 220ms
20
- ✓ src/middleware/password.spec.ts (4 tests) 937ms
21
- ✓ src/middleware/compactId.spec.ts (6 tests) 9737ms
22
- ✓ src/middleware/reactions.spec.ts (7 tests) 9767ms
23
- ✓ src/middleware/timestamps.spec.ts (3 tests) 242ms
24
-
25
-  Test Files  7 passed (7)
26
-  Tests  41 passed (41)
27
-  Start at  23:37:38
28
-  Duration  12.07s (transform 697ms, setup 0ms, import 4.26s, tests 28.42s, environment 1ms)
29
-
package/CHANGELOG.md DELETED
@@ -1,368 +0,0 @@
1
- # @slango/mangusta
2
-
3
- ## 2.1.39
4
-
5
- ### Patch Changes
6
-
7
- - 83f12c6: Dependencies bump
8
-
9
- ## 2.1.38
10
-
11
- ### Patch Changes
12
-
13
- - 463d9ce: Dependencies bump
14
-
15
- ## 2.1.37
16
-
17
- ### Patch Changes
18
-
19
- - 02b8cd1: Dependencies bump
20
-
21
- ## 2.1.36
22
-
23
- ### Patch Changes
24
-
25
- - f59dae8: Dependencies bump
26
-
27
- ## 2.1.35
28
-
29
- ### Patch Changes
30
-
31
- - a245367: Dependencies bump
32
-
33
- ## 2.1.34
34
-
35
- ### Patch Changes
36
-
37
- - 75b71f7: Dependencies bump
38
-
39
- ## 2.1.33
40
-
41
- ### Patch Changes
42
-
43
- - 7b9def8: Dependencies bump
44
-
45
- ## 2.1.32
46
-
47
- ### Patch Changes
48
-
49
- - dfd3015: Dependencies bump
50
-
51
- ## 2.1.31
52
-
53
- ### Patch Changes
54
-
55
- - 59effbe: Dependencies bump
56
-
57
- ## 2.1.30
58
-
59
- ### Patch Changes
60
-
61
- - 3e79aa6: Dependencies bump
62
-
63
- ## 2.1.29
64
-
65
- ### Patch Changes
66
-
67
- - cbb580d: Dependencies bump
68
-
69
- ## 2.1.28
70
-
71
- ### Patch Changes
72
-
73
- - 8eed7d3: Dependencies bump
74
-
75
- ## 2.1.27
76
-
77
- ### Patch Changes
78
-
79
- - 70230d2: Dependencies bump
80
-
81
- ## 2.1.26
82
-
83
- ### Patch Changes
84
-
85
- - f4e8645: Dependencies bump
86
-
87
- ## 2.1.25
88
-
89
- ### Patch Changes
90
-
91
- - e80d5ac: Dependencies bump
92
-
93
- ## 2.1.24
94
-
95
- ### Patch Changes
96
-
97
- - a692cf9: Dependencies bump
98
-
99
- ## 2.1.23
100
-
101
- ### Patch Changes
102
-
103
- - dca0a26: Dependencies bump
104
-
105
- ## 2.1.22
106
-
107
- ### Patch Changes
108
-
109
- - df2e3c2: Dependencies bump
110
-
111
- ## 2.1.21
112
-
113
- ### Patch Changes
114
-
115
- - 6ab8613: Dependencies bump
116
-
117
- ## 2.1.20
118
-
119
- ### Patch Changes
120
-
121
- - 07ec4aa: Dependencies bump
122
-
123
- ## 2.1.19
124
-
125
- ### Patch Changes
126
-
127
- - 57f6c46: Dependencies bump
128
-
129
- ## 2.1.18
130
-
131
- ### Patch Changes
132
-
133
- - 4ba0ccb: Dependencies bump
134
-
135
- ## 2.1.17
136
-
137
- ### Patch Changes
138
-
139
- - d57de48: Dependencies bump
140
-
141
- ## 2.1.16
142
-
143
- ### Patch Changes
144
-
145
- - 09ac7a7: Dependencies bump
146
-
147
- ## 2.1.15
148
-
149
- ### Patch Changes
150
-
151
- - ad32208: Dependencies bump
152
-
153
- ## 2.1.14
154
-
155
- ### Patch Changes
156
-
157
- - 35aaf02: Dependencies bump
158
-
159
- ## 2.1.13
160
-
161
- ### Patch Changes
162
-
163
- - fafa8e1: Dependencies bump
164
-
165
- ## 2.1.12
166
-
167
- ### Patch Changes
168
-
169
- - ec2131e: Dependencies bump
170
-
171
- ## 2.1.11
172
-
173
- ### Patch Changes
174
-
175
- - 1895011: Minor fix in reactions plugin
176
-
177
- ## 2.1.10
178
-
179
- ### Patch Changes
180
-
181
- - 4010cfc: Dependencies bump
182
-
183
- ## 2.1.9
184
-
185
- ### Patch Changes
186
-
187
- - 3ceebbb: Dependencies bump
188
-
189
- ## 2.1.8
190
-
191
- ### Patch Changes
192
-
193
- - 97f7d48: Dependencies bump
194
-
195
- ## 2.1.7
196
-
197
- ### Patch Changes
198
-
199
- - 2ab1c4d: Dependencies bump
200
-
201
- ## 2.1.6
202
-
203
- ### Patch Changes
204
-
205
- - 4e2e552: Dependencies bump
206
-
207
- ## 2.1.5
208
-
209
- ### Patch Changes
210
-
211
- - 837ccbc: Dependencies bump
212
-
213
- ## 2.1.4
214
-
215
- ### Patch Changes
216
-
217
- - bb51724: Dependencies bump
218
-
219
- ## 2.1.3
220
-
221
- ### Patch Changes
222
-
223
- - c035f46: Dependencies bump
224
-
225
- ## 2.1.2
226
-
227
- ### Patch Changes
228
-
229
- - f4f3cd3: Dependencies bump
230
-
231
- ## 2.1.1
232
-
233
- ### Patch Changes
234
-
235
- - 1a8ba94: Fixed issue with test-utils build
236
-
237
- ## 2.1.0
238
-
239
- ### Minor Changes
240
-
241
- - 3b574f4: mangusta now export mongoose test environment
242
-
243
- ## 2.0.2
244
-
245
- ### Patch Changes
246
-
247
- - b6cdd05: Dependencies bump
248
-
249
- ## 2.0.1
250
-
251
- ### Patch Changes
252
-
253
- - 86530f1: Dependencies bump
254
-
255
- ## 2.0.0
256
-
257
- ### Major Changes
258
-
259
- - 8519268: Mongoose bump (verison 9.0.0)
260
-
261
- ## 1.1.8
262
-
263
- ### Patch Changes
264
-
265
- - d3ad164: Dependencies bump
266
-
267
- ## 1.1.7
268
-
269
- ### Patch Changes
270
-
271
- - 187ea56: Dependencies bump
272
-
273
- ## 1.1.6
274
-
275
- ### Patch Changes
276
-
277
- - 5bcda82: Dependencies bump
278
-
279
- ## 1.1.5
280
-
281
- ### Patch Changes
282
-
283
- - 38b7f0d: Dependencies bump
284
-
285
- ## 1.1.4
286
-
287
- ### Patch Changes
288
-
289
- - 72ffa91: Dependnecies bump and eslint presets normalization
290
-
291
- ## 1.1.3
292
-
293
- ### Patch Changes
294
-
295
- - fb024e5: Dependencies bump
296
-
297
- ## 1.1.2
298
-
299
- ### Patch Changes
300
-
301
- - 7d6305d: Dependencies bump
302
-
303
- ## 1.1.1
304
-
305
- ### Patch Changes
306
-
307
- - 60f7e37: Dependencies bump
308
-
309
- ## 1.1.0
310
-
311
- ### Minor Changes
312
-
313
- - 9ef53b9: Reactions middleware
314
-
315
- ## 1.0.8
316
-
317
- ### Patch Changes
318
-
319
- - 71b046e: Dependencies bump
320
- - 71b046e: Dependencies bump
321
-
322
- ## 1.0.7
323
-
324
- ### Patch Changes
325
-
326
- - 87e2b79: Dependencies bump
327
-
328
- ## 1.0.6
329
-
330
- ### Patch Changes
331
-
332
- - c87dbe1: Dependencies bump
333
-
334
- ## 1.0.5
335
-
336
- ### Patch Changes
337
-
338
- - 4e1143b: Dependencies bump
339
-
340
- ## 1.0.4
341
-
342
- ### Patch Changes
343
-
344
- - 450ff4b: Dependencies bump
345
-
346
- ## 1.0.3
347
-
348
- ### Patch Changes
349
-
350
- - 076c4fd: Test coverage for password middleware
351
-
352
- ## 1.0.2
353
-
354
- ### Patch Changes
355
-
356
- - ca0d852: Timestamp middleware fix
357
-
358
- ## 1.0.1
359
-
360
- ### Patch Changes
361
-
362
- - 92fd426: Fixed issue with timestamps middleware that affected update field (wrong name of field and clash with creation)
363
-
364
- ## 1.0.0
365
-
366
- ### Major Changes
367
-
368
- - 6b65dde: First version (renamed from @slango/mongoose)
package/eslint.config.js DELETED
@@ -1 +0,0 @@
1
- export { default } from '@slango.configs/eslint/typescript.js';
@@ -1 +0,0 @@
1
- export { default } from '@slango.configs/lint-staged/typescript.js';
package/src/helpers.ts DELETED
@@ -1,14 +0,0 @@
1
- import { Types } from 'mongoose';
2
-
3
- export type Id = string | Types.ObjectId;
4
-
5
- export const toObjectId = (value: Id): Types.ObjectId => {
6
- if (value instanceof Types.ObjectId) {
7
- return value;
8
- }
9
-
10
- return new Types.ObjectId(value);
11
- };
12
-
13
- export const toStringId = (value: Id): string =>
14
- value instanceof Types.ObjectId ? value.toString() : value;
@@ -1,88 +0,0 @@
1
- import { Document } from 'mongoose';
2
- import { describe, expect, it } from 'vitest';
3
-
4
- import { createModelWithPlugin } from '../test-utils/model.js';
5
- import { setupMongoTestEnvironment } from '../test-utils/mongooseTestEnvironment.js';
6
- import { PluginFunction } from '../types.js';
7
- import compactIdMiddleware, { CompactIdMiddlewareOptions, WithCompactId } from './compactId.js';
8
-
9
- setupMongoTestEnvironment();
10
-
11
- type TestDoc<Field extends string = 'shortId'> = Document & WithCompactId<Field>;
12
-
13
- const createTestModel = <Field extends string = 'shortId'>(
14
- options?: CompactIdMiddlewareOptions<Field>,
15
- ) =>
16
- createModelWithPlugin<TestDoc<Field>, CompactIdMiddlewareOptions<Field>>({
17
- modelName: 'TestDoc',
18
- plugin: compactIdMiddleware as PluginFunction<CompactIdMiddlewareOptions<Field>>,
19
- pluginOptions: options,
20
- });
21
-
22
- describe('compactIdMiddleware', () => {
23
- it('should add a "shortId" field by default with correct options', async () => {
24
- const { model: TestModel } = createTestModel();
25
- const doc = new TestModel();
26
-
27
- await expect(doc.save()).resolves.not.toThrow();
28
- const savedDoc = await TestModel.findOne({ _id: doc._id });
29
- expect(savedDoc).toBeDefined();
30
- expect(savedDoc?.shortId).toBeDefined();
31
- expect(savedDoc?.shortId.length).toBe(9);
32
- });
33
-
34
- it('should generate a compactId of specified length', async () => {
35
- const { model: TestModel } = createTestModel({ length: 12 });
36
- const doc = new TestModel();
37
-
38
- await expect(doc.save()).resolves.not.toThrow();
39
- const savedDoc = await TestModel.findOne({ _id: doc._id });
40
- expect(savedDoc?.shortId).toHaveLength(12);
41
- });
42
-
43
- it('should allow configuring the field name', async () => {
44
- const { model: TestModel } = createTestModel<'customId'>({ field: 'customId' });
45
- const doc = new TestModel();
46
-
47
- await expect(doc.save()).resolves.not.toThrow();
48
- const savedDoc = await TestModel.findOne({ _id: doc._id });
49
- expect(savedDoc).toBeDefined();
50
- expect(savedDoc?.customId).toBeDefined();
51
- });
52
-
53
- it('should not generate "index" if not requested', () => {
54
- const { schema } = createTestModel({ index: false });
55
- const indexes = schema.indexes();
56
- const customIdIndex = indexes.find(([fields]) =>
57
- Object.prototype.hasOwnProperty.call(fields, 'shortId'),
58
- );
59
-
60
- expect(customIdIndex).toBeUndefined();
61
- });
62
-
63
- it('should apply "index" and not "unique" options to the field', () => {
64
- const { schema } = createTestModel({ index: true, unique: false });
65
- const indexes = schema.indexes();
66
- const customIdIndex = indexes.find(([fields]) =>
67
- Object.prototype.hasOwnProperty.call(fields, 'shortId'),
68
- );
69
-
70
- expect(customIdIndex).toBeDefined();
71
- expect(customIdIndex![0].shortId).toBe(1);
72
- const uniqueOption = customIdIndex?.[1]?.unique;
73
- expect(uniqueOption).toBe(false);
74
- });
75
-
76
- it('should apply "unique" and "unique" options to the field', () => {
77
- const { schema } = createTestModel({ index: true, unique: true });
78
- const indexes = schema.indexes();
79
- const customIdIndex = indexes.find(([fields]) =>
80
- Object.prototype.hasOwnProperty.call(fields, 'shortId'),
81
- );
82
-
83
- expect(customIdIndex).toBeDefined();
84
- expect(customIdIndex![0].shortId).toBe(1);
85
- const uniqueOption = customIdIndex?.[1]?.unique;
86
- expect(uniqueOption).toBe(true);
87
- });
88
- });
@@ -1,42 +0,0 @@
1
- import { Document, Model, Schema } from 'mongoose';
2
- import { nanoid } from 'nanoid';
3
-
4
- import { PluginFunction } from '../types.js';
5
-
6
- export interface CompactIdMiddlewareOptions<Field extends string = 'shortId'> {
7
- field?: Field;
8
- index?: boolean;
9
- length?: number;
10
- unique?: boolean;
11
- }
12
-
13
- export type WithCompactId<Field extends string = 'shortId'> = {
14
- [key in Field]: string;
15
- };
16
-
17
- const compactIdMiddleware: PluginFunction<CompactIdMiddlewareOptions> = <
18
- Field extends string = 'shortId',
19
- DocType extends Document & WithCompactId<Field> = Document & WithCompactId<Field>,
20
- >(
21
- schema: Schema<DocType, Model<DocType>>,
22
- {
23
- field = 'shortId' as Field,
24
- index = true,
25
- length = 9,
26
- unique = true,
27
- }: CompactIdMiddlewareOptions<Field> = {},
28
- ): void => {
29
- const fieldDescription = new Schema<WithCompactId<Field>>({
30
- [field]: {
31
- default: () => nanoid(length),
32
- index,
33
- required: true,
34
- unique: index && unique,
35
- type: String,
36
- },
37
- });
38
-
39
- schema.add(fieldDescription);
40
- };
41
-
42
- export default compactIdMiddleware;
@@ -1,86 +0,0 @@
1
- import mongoose, { Document, model, Schema } from 'mongoose';
2
- import { describe, expect, it } from 'vitest';
3
-
4
- import { setupMongoTestEnvironment } from '../test-utils/mongooseTestEnvironment.js';
5
- import emailMiddleware from './email.js';
6
-
7
- setupMongoTestEnvironment();
8
-
9
- interface TestUser extends Document {
10
- email: string;
11
- }
12
-
13
- const TestUserSchema = new Schema<TestUser>({});
14
- TestUserSchema.plugin(emailMiddleware);
15
-
16
- const TestUserModel = model<TestUser>('TestUser', TestUserSchema);
17
-
18
- const validEmail = 'valid.email@example.com';
19
- const invalidEmail = 'invalid-email';
20
- const customErrorMessage = 'Custom error message for invalid email';
21
-
22
- describe('emailMiddleware', () => {
23
- it('should allow saving a user with a valid email', async () => {
24
- const user = new TestUserModel({ email: validEmail });
25
-
26
- await expect(user.save()).resolves.not.toThrow();
27
- });
28
-
29
- it('should fail when saving a user with an invalid email', async () => {
30
- const user = new TestUserModel({ email: invalidEmail });
31
-
32
- await expect(user.save()).rejects.toThrowError(mongoose.Error.ValidationError);
33
- });
34
-
35
- it('should enforce uniqueness for email', async () => {
36
- await TestUserModel.init();
37
-
38
- const user1 = new TestUserModel({ email: validEmail });
39
- const user2 = new TestUserModel({ email: validEmail });
40
-
41
- await user1.save();
42
- await expect(user2.save()).rejects.toThrowError(Error);
43
- });
44
-
45
- it('should allow saving a user without an email if "required" is set to false', async () => {
46
- const OptionalEmailUserSchema = new Schema<TestUser>({});
47
- OptionalEmailUserSchema.plugin(emailMiddleware, { required: false });
48
- const OptionalEmailUserModel = model<TestUser>('OptionalEmailUser', OptionalEmailUserSchema);
49
-
50
- const user = new OptionalEmailUserModel({});
51
-
52
- await expect(user.save()).resolves.not.toThrow();
53
- });
54
-
55
- it('should display custom error message for invalid email', async () => {
56
- const CustomMessageSchema = new Schema<TestUser>({});
57
- CustomMessageSchema.plugin(emailMiddleware, { doesNotMatchMessage: customErrorMessage });
58
- const CustomMessageUserModel = model<TestUser>('CustomMessageUser', CustomMessageSchema);
59
-
60
- const user = new CustomMessageUserModel({ email: invalidEmail });
61
-
62
- await expect(user.save()).rejects.toThrowError(customErrorMessage);
63
- });
64
-
65
- it('should allow saving a user with a non-unique email if "unique" is set to false', async () => {
66
- const NonUniqueEmailSchema = new Schema<TestUser>({});
67
- NonUniqueEmailSchema.plugin(emailMiddleware, { unique: false });
68
- const NonUniqueEmailUserModel = model<TestUser>('NonUniqueEmailUser', NonUniqueEmailSchema);
69
-
70
- const user1 = new NonUniqueEmailUserModel({ email: validEmail });
71
- const user2 = new NonUniqueEmailUserModel({ email: validEmail });
72
-
73
- await expect(user1.save()).resolves.not.toThrow();
74
- await expect(user2.save()).resolves.not.toThrow(); // Should pass without unique constraint
75
- });
76
-
77
- it('should trim email addresses before saving', async () => {
78
- const user = new TestUserModel({ email: ` ${validEmail} ` });
79
-
80
- await user.save();
81
- const savedUser = await TestUserModel.findOne({ email: validEmail });
82
-
83
- expect(savedUser).toBeDefined();
84
- expect(savedUser?.email).toBe(validEmail);
85
- });
86
- });