@slango/mangusta 2.1.40 → 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.
Files changed (79) hide show
  1. package/dist/helpers.d.ts +5 -0
  2. package/dist/helpers.d.ts.map +1 -0
  3. package/dist/helpers.js +9 -0
  4. package/dist/helpers.js.map +1 -0
  5. package/dist/middleware/compactId.d.ts +13 -0
  6. package/dist/middleware/compactId.d.ts.map +1 -0
  7. package/dist/middleware/compactId.js +16 -0
  8. package/dist/middleware/compactId.js.map +1 -0
  9. package/dist/middleware/email.d.ts +18 -0
  10. package/dist/middleware/email.d.ts.map +1 -0
  11. package/dist/middleware/email.js +17 -0
  12. package/dist/middleware/email.js.map +1 -0
  13. package/dist/middleware/owner.d.ts +14 -0
  14. package/dist/middleware/owner.d.ts.map +1 -0
  15. package/dist/middleware/owner.js +14 -0
  16. package/dist/middleware/owner.js.map +1 -0
  17. package/dist/middleware/password.d.ts +18 -0
  18. package/dist/middleware/password.d.ts.map +1 -0
  19. package/dist/middleware/password.js +29 -0
  20. package/dist/middleware/password.js.map +1 -0
  21. package/dist/middleware/reactions.d.ts +43 -0
  22. package/dist/middleware/reactions.d.ts.map +1 -0
  23. package/dist/middleware/reactions.js +190 -0
  24. package/dist/middleware/reactions.js.map +1 -0
  25. package/dist/middleware/tags.d.ts +13 -0
  26. package/dist/middleware/tags.d.ts.map +1 -0
  27. package/dist/middleware/tags.js +26 -0
  28. package/dist/middleware/tags.js.map +1 -0
  29. package/dist/middleware/timestamps.d.ts +20 -0
  30. package/dist/middleware/timestamps.d.ts.map +1 -0
  31. package/dist/middleware/timestamps.js +42 -0
  32. package/dist/middleware/timestamps.js.map +1 -0
  33. package/dist/test-utils/globalSetup.d.ts +4 -0
  34. package/dist/test-utils/globalSetup.d.ts.map +1 -0
  35. package/dist/test-utils/globalSetup.js +15 -0
  36. package/dist/test-utils/globalSetup.js.map +1 -0
  37. package/dist/test-utils/model.d.ts +13 -0
  38. package/dist/test-utils/model.d.ts.map +1 -0
  39. package/dist/test-utils/model.js +11 -0
  40. package/dist/test-utils/model.js.map +1 -0
  41. package/dist/test-utils/mongooseTestEnvironment.d.ts +6 -0
  42. package/dist/test-utils/mongooseTestEnvironment.d.ts.map +1 -0
  43. package/dist/test-utils/mongooseTestEnvironment.js +40 -0
  44. package/dist/test-utils/mongooseTestEnvironment.js.map +1 -0
  45. package/dist/test-utils/testMongoUri.d.ts +4 -0
  46. package/dist/test-utils/testMongoUri.d.ts.map +1 -0
  47. package/dist/test-utils/testMongoUri.js +14 -0
  48. package/dist/test-utils/testMongoUri.js.map +1 -0
  49. package/{src/types.ts → dist/types.d.ts} +1 -2
  50. package/dist/types.d.ts.map +1 -0
  51. package/dist/types.js +2 -0
  52. package/dist/types.js.map +1 -0
  53. package/package.json +7 -4
  54. package/CHANGELOG.md +0 -374
  55. package/eslint.config.js +0 -1
  56. package/lint-staged.config.js +0 -1
  57. package/src/helpers.ts +0 -14
  58. package/src/middleware/compactId.spec.ts +0 -88
  59. package/src/middleware/compactId.ts +0 -42
  60. package/src/middleware/email.spec.ts +0 -86
  61. package/src/middleware/email.ts +0 -49
  62. package/src/middleware/owner.spec.ts +0 -77
  63. package/src/middleware/owner.ts +0 -39
  64. package/src/middleware/password.spec.ts +0 -83
  65. package/src/middleware/password.ts +0 -77
  66. package/src/middleware/reactions.spec.ts +0 -200
  67. package/src/middleware/reactions.ts +0 -371
  68. package/src/middleware/tags.spec.ts +0 -103
  69. package/src/middleware/tags.ts +0 -54
  70. package/src/middleware/timestamps.spec.ts +0 -69
  71. package/src/middleware/timestamps.ts +0 -92
  72. package/src/test-utils/globalSetup.ts +0 -22
  73. package/src/test-utils/model.ts +0 -29
  74. package/src/test-utils/mongooseTestEnvironment.ts +0 -54
  75. package/src/test-utils/testMongoUri.ts +0 -52
  76. package/src/test-utils/vitest.d.ts +0 -7
  77. package/tsconfig.build.json +0 -10
  78. package/tsconfig.json +0 -9
  79. package/vitest.config.js +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/test-utils/model.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,WAAW,2BAA2B,CAAC,GAAG,SAAS,QAAQ,EAAE,OAAO;IACxE,WAAW,CAAC,EAAE,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;IAChC,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,eAAO,MAAM,qBAAqB,GAAI,GAAG,SAAS,QAAQ,EAAE,OAAO,EAAE,oDAKlE,2BAA2B,CAAC,GAAG,EAAE,OAAO,CAAC,KAAG;IAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAA;CAYtF,CAAC"}
@@ -0,0 +1,11 @@
1
+ import mongoose, { Schema } from 'mongoose';
2
+ export const createModelWithPlugin = ({ buildSchema, modelName, plugin, pluginOptions, }) => {
3
+ if (mongoose.models[modelName]) {
4
+ delete mongoose.models[modelName];
5
+ }
6
+ const schema = buildSchema ? buildSchema() : new Schema({});
7
+ schema.plugin(plugin, pluginOptions);
8
+ const modelInstance = mongoose.model(modelName, schema);
9
+ return { model: modelInstance, schema };
10
+ };
11
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/test-utils/model.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,EAAE,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAC;AAW7D,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAgC,EACnE,WAAW,EACX,SAAS,EACT,MAAM,EACN,aAAa,GAC6B,EAA8C,EAAE;IAC1F,IAAI,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;QAC/B,OAAO,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,CAAM,EAAE,CAAC,CAAC;IAEjE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAErC,MAAM,aAAa,GAAG,QAAQ,CAAC,KAAK,CAAM,SAAS,EAAE,MAAM,CAAC,CAAC;IAE7D,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;AAC1C,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ type SetupMongoTestEnvironmentOptions = {
2
+ preserveCollections?: string[];
3
+ };
4
+ export declare function setupMongoTestEnvironment({ preserveCollections, }?: SetupMongoTestEnvironmentOptions): void;
5
+ export {};
6
+ //# sourceMappingURL=mongooseTestEnvironment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongooseTestEnvironment.d.ts","sourceRoot":"","sources":["../../src/test-utils/mongooseTestEnvironment.ts"],"names":[],"mappings":"AAMA,KAAK,gCAAgC,GAAG;IACtC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;CAChC,CAAC;AAEF,wBAAgB,yBAAyB,CAAC,EACxC,mBAAwB,GACzB,GAAE,gCAAqC,QA2BvC"}
@@ -0,0 +1,40 @@
1
+ import { MongoMemoryServer } from 'mongodb-memory-server';
2
+ import mongoose from 'mongoose';
3
+ import { afterAll, afterEach, beforeAll } from 'vitest';
4
+ const ConnectionStates = mongoose.ConnectionStates;
5
+ export function setupMongoTestEnvironment({ preserveCollections = [], } = {}) {
6
+ let mongoServer;
7
+ beforeAll(async () => {
8
+ mongoServer = await MongoMemoryServer.create();
9
+ const uri = mongoServer.getUri();
10
+ process.env.MONGO_URI = uri;
11
+ await mongoose.connect(uri, { dbName: 'test-db' });
12
+ await waitForDatabaseConnection();
13
+ });
14
+ afterAll(async () => {
15
+ await mongoose.disconnect();
16
+ await mongoServer.stop();
17
+ });
18
+ afterEach(async () => {
19
+ if (mongoose.connection.db) {
20
+ const collections = await mongoose.connection.db.collections();
21
+ for (const collection of collections) {
22
+ if (!preserveCollections.includes(collection.collectionName)) {
23
+ await collection.deleteMany({});
24
+ }
25
+ }
26
+ }
27
+ });
28
+ }
29
+ async function waitForDatabaseConnection(maxRetries = 5, interval = 1000) {
30
+ let retries = 0;
31
+ while (mongoose.connection.readyState !== ConnectionStates.connected && retries < maxRetries) {
32
+ await new Promise((resolve) => setTimeout(resolve, interval));
33
+ retries++;
34
+ console.log(`Retrying database connection (${retries}/${maxRetries})...`);
35
+ }
36
+ if (mongoose.connection.readyState !== ConnectionStates.connected) {
37
+ throw new Error('Failed to connect to the database within the allowed retries.');
38
+ }
39
+ }
40
+ //# sourceMappingURL=mongooseTestEnvironment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongooseTestEnvironment.js","sourceRoot":"","sources":["../../src/test-utils/mongooseTestEnvironment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExD,MAAM,gBAAgB,GAAG,QAAQ,CAAC,gBAAgB,CAAC;AAMnD,MAAM,UAAU,yBAAyB,CAAC,EACxC,mBAAmB,GAAG,EAAE,MACY,EAAE;IACtC,IAAI,WAA8B,CAAC;IAEnC,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,WAAW,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,CAAC;QAC/C,MAAM,GAAG,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC;QACjC,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,GAAG,CAAC;QAC5B,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAEnD,MAAM,yBAAyB,EAAE,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,KAAK,IAAI,EAAE;QAClB,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC;QAC5B,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,IAAI,QAAQ,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC;YAC3B,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC;YAC/D,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;gBACrC,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;oBAC7D,MAAM,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;gBAClC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,yBAAyB,CAAC,UAAU,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI;IACtE,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,OAAO,QAAQ,CAAC,UAAU,CAAC,UAAU,KAAK,gBAAgB,CAAC,SAAS,IAAI,OAAO,GAAG,UAAU,EAAE,CAAC;QAC7F,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;QAC9D,OAAO,EAAE,CAAC;QACV,OAAO,CAAC,GAAG,CAAC,iCAAiC,OAAO,IAAI,UAAU,MAAM,CAAC,CAAC;IAC5E,CAAC;IAED,IAAI,QAAQ,CAAC,UAAU,CAAC,UAAU,KAAK,gBAAgB,CAAC,SAAS,EAAE,CAAC;QAClE,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;IACnF,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function setTestMongoUri(uri: string): void;
2
+ export declare function getTestMongoUri(): string;
3
+ export declare function clearTestMongoUri(): void;
4
+ //# sourceMappingURL=testMongoUri.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testMongoUri.d.ts","sourceRoot":"","sources":["../../src/test-utils/testMongoUri.ts"],"names":[],"mappings":"AAYA,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEjD;AAqBD,wBAAgB,eAAe,IAAI,MAAM,CAOxC;AAOD,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
@@ -0,0 +1,14 @@
1
+ let currentTestMongoUri = null;
2
+ export function setTestMongoUri(uri) {
3
+ currentTestMongoUri = uri;
4
+ }
5
+ export function getTestMongoUri() {
6
+ if (!currentTestMongoUri) {
7
+ throw new Error('Test MongoDB URI not available. Ensure setupMongoTestEnvironment() is called in beforeAll.');
8
+ }
9
+ return currentTestMongoUri;
10
+ }
11
+ export function clearTestMongoUri() {
12
+ currentTestMongoUri = null;
13
+ }
14
+ //# sourceMappingURL=testMongoUri.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testMongoUri.js","sourceRoot":"","sources":["../../src/test-utils/testMongoUri.ts"],"names":[],"mappings":"AAKA,IAAI,mBAAmB,GAAkB,IAAI,CAAC;AAO9C,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,mBAAmB,GAAG,GAAG,CAAC;AAC5B,CAAC;AAqBD,MAAM,UAAU,eAAe;IAC7B,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,4FAA4F,CAC7F,CAAC;IACJ,CAAC;IACD,OAAO,mBAAmB,CAAC;AAC7B,CAAC;AAOD,MAAM,UAAU,iBAAiB;IAC/B,mBAAmB,GAAG,IAAI,CAAC;AAC7B,CAAC"}
@@ -1,4 +1,3 @@
1
1
  import { Schema } from 'mongoose';
2
-
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
2
  export type PluginFunction<Options = any> = (schema: Schema, options?: Options) => void;
3
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,MAAM,MAAM,cAAc,CAAC,OAAO,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slango/mangusta",
3
- "version": "2.1.40",
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",
@@ -41,9 +44,9 @@
41
44
  "mongoose": "9.7.4",
42
45
  "typescript": "6.0.3",
43
46
  "vitest": "^4.1.10",
44
- "@slango.configs/eslint": "1.2.32",
45
- "@slango.configs/vitest": "2.0.41",
46
- "@slango.configs/typescript": "2.0.9"
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",
package/CHANGELOG.md DELETED
@@ -1,374 +0,0 @@
1
- # @slango/mangusta
2
-
3
- ## 2.1.40
4
-
5
- ### Patch Changes
6
-
7
- - 7d321c6: Dependencies bump
8
-
9
- ## 2.1.39
10
-
11
- ### Patch Changes
12
-
13
- - 83f12c6: Dependencies bump
14
-
15
- ## 2.1.38
16
-
17
- ### Patch Changes
18
-
19
- - 463d9ce: Dependencies bump
20
-
21
- ## 2.1.37
22
-
23
- ### Patch Changes
24
-
25
- - 02b8cd1: Dependencies bump
26
-
27
- ## 2.1.36
28
-
29
- ### Patch Changes
30
-
31
- - f59dae8: Dependencies bump
32
-
33
- ## 2.1.35
34
-
35
- ### Patch Changes
36
-
37
- - a245367: Dependencies bump
38
-
39
- ## 2.1.34
40
-
41
- ### Patch Changes
42
-
43
- - 75b71f7: Dependencies bump
44
-
45
- ## 2.1.33
46
-
47
- ### Patch Changes
48
-
49
- - 7b9def8: Dependencies bump
50
-
51
- ## 2.1.32
52
-
53
- ### Patch Changes
54
-
55
- - dfd3015: Dependencies bump
56
-
57
- ## 2.1.31
58
-
59
- ### Patch Changes
60
-
61
- - 59effbe: Dependencies bump
62
-
63
- ## 2.1.30
64
-
65
- ### Patch Changes
66
-
67
- - 3e79aa6: Dependencies bump
68
-
69
- ## 2.1.29
70
-
71
- ### Patch Changes
72
-
73
- - cbb580d: Dependencies bump
74
-
75
- ## 2.1.28
76
-
77
- ### Patch Changes
78
-
79
- - 8eed7d3: Dependencies bump
80
-
81
- ## 2.1.27
82
-
83
- ### Patch Changes
84
-
85
- - 70230d2: Dependencies bump
86
-
87
- ## 2.1.26
88
-
89
- ### Patch Changes
90
-
91
- - f4e8645: Dependencies bump
92
-
93
- ## 2.1.25
94
-
95
- ### Patch Changes
96
-
97
- - e80d5ac: Dependencies bump
98
-
99
- ## 2.1.24
100
-
101
- ### Patch Changes
102
-
103
- - a692cf9: Dependencies bump
104
-
105
- ## 2.1.23
106
-
107
- ### Patch Changes
108
-
109
- - dca0a26: Dependencies bump
110
-
111
- ## 2.1.22
112
-
113
- ### Patch Changes
114
-
115
- - df2e3c2: Dependencies bump
116
-
117
- ## 2.1.21
118
-
119
- ### Patch Changes
120
-
121
- - 6ab8613: Dependencies bump
122
-
123
- ## 2.1.20
124
-
125
- ### Patch Changes
126
-
127
- - 07ec4aa: Dependencies bump
128
-
129
- ## 2.1.19
130
-
131
- ### Patch Changes
132
-
133
- - 57f6c46: Dependencies bump
134
-
135
- ## 2.1.18
136
-
137
- ### Patch Changes
138
-
139
- - 4ba0ccb: Dependencies bump
140
-
141
- ## 2.1.17
142
-
143
- ### Patch Changes
144
-
145
- - d57de48: Dependencies bump
146
-
147
- ## 2.1.16
148
-
149
- ### Patch Changes
150
-
151
- - 09ac7a7: Dependencies bump
152
-
153
- ## 2.1.15
154
-
155
- ### Patch Changes
156
-
157
- - ad32208: Dependencies bump
158
-
159
- ## 2.1.14
160
-
161
- ### Patch Changes
162
-
163
- - 35aaf02: Dependencies bump
164
-
165
- ## 2.1.13
166
-
167
- ### Patch Changes
168
-
169
- - fafa8e1: Dependencies bump
170
-
171
- ## 2.1.12
172
-
173
- ### Patch Changes
174
-
175
- - ec2131e: Dependencies bump
176
-
177
- ## 2.1.11
178
-
179
- ### Patch Changes
180
-
181
- - 1895011: Minor fix in reactions plugin
182
-
183
- ## 2.1.10
184
-
185
- ### Patch Changes
186
-
187
- - 4010cfc: Dependencies bump
188
-
189
- ## 2.1.9
190
-
191
- ### Patch Changes
192
-
193
- - 3ceebbb: Dependencies bump
194
-
195
- ## 2.1.8
196
-
197
- ### Patch Changes
198
-
199
- - 97f7d48: Dependencies bump
200
-
201
- ## 2.1.7
202
-
203
- ### Patch Changes
204
-
205
- - 2ab1c4d: Dependencies bump
206
-
207
- ## 2.1.6
208
-
209
- ### Patch Changes
210
-
211
- - 4e2e552: Dependencies bump
212
-
213
- ## 2.1.5
214
-
215
- ### Patch Changes
216
-
217
- - 837ccbc: Dependencies bump
218
-
219
- ## 2.1.4
220
-
221
- ### Patch Changes
222
-
223
- - bb51724: Dependencies bump
224
-
225
- ## 2.1.3
226
-
227
- ### Patch Changes
228
-
229
- - c035f46: Dependencies bump
230
-
231
- ## 2.1.2
232
-
233
- ### Patch Changes
234
-
235
- - f4f3cd3: Dependencies bump
236
-
237
- ## 2.1.1
238
-
239
- ### Patch Changes
240
-
241
- - 1a8ba94: Fixed issue with test-utils build
242
-
243
- ## 2.1.0
244
-
245
- ### Minor Changes
246
-
247
- - 3b574f4: mangusta now export mongoose test environment
248
-
249
- ## 2.0.2
250
-
251
- ### Patch Changes
252
-
253
- - b6cdd05: Dependencies bump
254
-
255
- ## 2.0.1
256
-
257
- ### Patch Changes
258
-
259
- - 86530f1: Dependencies bump
260
-
261
- ## 2.0.0
262
-
263
- ### Major Changes
264
-
265
- - 8519268: Mongoose bump (verison 9.0.0)
266
-
267
- ## 1.1.8
268
-
269
- ### Patch Changes
270
-
271
- - d3ad164: Dependencies bump
272
-
273
- ## 1.1.7
274
-
275
- ### Patch Changes
276
-
277
- - 187ea56: Dependencies bump
278
-
279
- ## 1.1.6
280
-
281
- ### Patch Changes
282
-
283
- - 5bcda82: Dependencies bump
284
-
285
- ## 1.1.5
286
-
287
- ### Patch Changes
288
-
289
- - 38b7f0d: Dependencies bump
290
-
291
- ## 1.1.4
292
-
293
- ### Patch Changes
294
-
295
- - 72ffa91: Dependnecies bump and eslint presets normalization
296
-
297
- ## 1.1.3
298
-
299
- ### Patch Changes
300
-
301
- - fb024e5: Dependencies bump
302
-
303
- ## 1.1.2
304
-
305
- ### Patch Changes
306
-
307
- - 7d6305d: Dependencies bump
308
-
309
- ## 1.1.1
310
-
311
- ### Patch Changes
312
-
313
- - 60f7e37: Dependencies bump
314
-
315
- ## 1.1.0
316
-
317
- ### Minor Changes
318
-
319
- - 9ef53b9: Reactions middleware
320
-
321
- ## 1.0.8
322
-
323
- ### Patch Changes
324
-
325
- - 71b046e: Dependencies bump
326
- - 71b046e: Dependencies bump
327
-
328
- ## 1.0.7
329
-
330
- ### Patch Changes
331
-
332
- - 87e2b79: Dependencies bump
333
-
334
- ## 1.0.6
335
-
336
- ### Patch Changes
337
-
338
- - c87dbe1: Dependencies bump
339
-
340
- ## 1.0.5
341
-
342
- ### Patch Changes
343
-
344
- - 4e1143b: Dependencies bump
345
-
346
- ## 1.0.4
347
-
348
- ### Patch Changes
349
-
350
- - 450ff4b: Dependencies bump
351
-
352
- ## 1.0.3
353
-
354
- ### Patch Changes
355
-
356
- - 076c4fd: Test coverage for password middleware
357
-
358
- ## 1.0.2
359
-
360
- ### Patch Changes
361
-
362
- - ca0d852: Timestamp middleware fix
363
-
364
- ## 1.0.1
365
-
366
- ### Patch Changes
367
-
368
- - 92fd426: Fixed issue with timestamps middleware that affected update field (wrong name of field and clash with creation)
369
-
370
- ## 1.0.0
371
-
372
- ### Major Changes
373
-
374
- - 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;