@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 +8 -5
- package/.turbo/turbo-build.log +0 -1
- package/.turbo/turbo-lint.log +0 -1
- package/.turbo/turbo-test.log +0 -29
- package/CHANGELOG.md +0 -368
- package/eslint.config.js +0 -1
- package/lint-staged.config.js +0 -1
- package/src/helpers.ts +0 -14
- package/src/middleware/compactId.spec.ts +0 -88
- package/src/middleware/compactId.ts +0 -42
- package/src/middleware/email.spec.ts +0 -86
- package/src/middleware/email.ts +0 -49
- package/src/middleware/owner.spec.ts +0 -77
- package/src/middleware/owner.ts +0 -39
- package/src/middleware/password.spec.ts +0 -83
- package/src/middleware/password.ts +0 -77
- package/src/middleware/reactions.spec.ts +0 -200
- package/src/middleware/reactions.ts +0 -371
- package/src/middleware/tags.spec.ts +0 -103
- package/src/middleware/tags.ts +0 -54
- package/src/middleware/timestamps.spec.ts +0 -69
- package/src/middleware/timestamps.ts +0 -92
- package/src/test-utils/globalSetup.ts +0 -22
- package/src/test-utils/model.ts +0 -29
- package/src/test-utils/mongooseTestEnvironment.ts +0 -54
- package/src/test-utils/testMongoUri.ts +0 -52
- package/src/test-utils/vitest.d.ts +0 -7
- package/src/types.ts +0 -4
- package/tsconfig.build.json +0 -10
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -9
- package/vitest.config.js +0 -1
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { TestProject } from 'vitest/node';
|
|
2
|
-
|
|
3
|
-
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
4
|
-
|
|
5
|
-
let mongoServer: MongoMemoryServer;
|
|
6
|
-
|
|
7
|
-
export async function setup(project: TestProject) {
|
|
8
|
-
mongoServer = await MongoMemoryServer.create();
|
|
9
|
-
const uri = mongoServer.getUri();
|
|
10
|
-
|
|
11
|
-
// Type assertion needed as vitest's ProvidedContext typing is complex
|
|
12
|
-
(project.provide as (key: string, value: string) => void)('MONGO_URI', uri);
|
|
13
|
-
|
|
14
|
-
console.log('[mangusta] MongoDB Memory Server started:', uri);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function teardown() {
|
|
18
|
-
if (mongoServer) {
|
|
19
|
-
await mongoServer.stop();
|
|
20
|
-
console.log('[mangusta] MongoDB Memory Server stopped');
|
|
21
|
-
}
|
|
22
|
-
}
|
package/src/test-utils/model.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import mongoose, { Document, Model, Schema } from 'mongoose';
|
|
2
|
-
|
|
3
|
-
import { PluginFunction } from '../types.js';
|
|
4
|
-
|
|
5
|
-
export interface CreateModelWithPluginParams<Doc extends Document, Options> {
|
|
6
|
-
buildSchema?: () => Schema<Doc>;
|
|
7
|
-
modelName: string;
|
|
8
|
-
plugin: PluginFunction<Options>;
|
|
9
|
-
pluginOptions?: Options;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const createModelWithPlugin = <Doc extends Document, Options>({
|
|
13
|
-
buildSchema,
|
|
14
|
-
modelName,
|
|
15
|
-
plugin,
|
|
16
|
-
pluginOptions,
|
|
17
|
-
}: CreateModelWithPluginParams<Doc, Options>): { model: Model<Doc>; schema: Schema<Doc> } => {
|
|
18
|
-
if (mongoose.models[modelName]) {
|
|
19
|
-
delete mongoose.models[modelName];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const schema = buildSchema ? buildSchema() : new Schema<Doc>({});
|
|
23
|
-
|
|
24
|
-
schema.plugin(plugin, pluginOptions);
|
|
25
|
-
|
|
26
|
-
const modelInstance = mongoose.model<Doc>(modelName, schema);
|
|
27
|
-
|
|
28
|
-
return { model: modelInstance, schema };
|
|
29
|
-
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
2
|
-
import mongoose from 'mongoose';
|
|
3
|
-
import { afterAll, afterEach, beforeAll } from 'vitest';
|
|
4
|
-
|
|
5
|
-
const ConnectionStates = mongoose.ConnectionStates;
|
|
6
|
-
|
|
7
|
-
type SetupMongoTestEnvironmentOptions = {
|
|
8
|
-
preserveCollections?: string[];
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export function setupMongoTestEnvironment({
|
|
12
|
-
preserveCollections = [],
|
|
13
|
-
}: SetupMongoTestEnvironmentOptions = {}) {
|
|
14
|
-
let mongoServer: MongoMemoryServer;
|
|
15
|
-
|
|
16
|
-
beforeAll(async () => {
|
|
17
|
-
mongoServer = await MongoMemoryServer.create();
|
|
18
|
-
const uri = mongoServer.getUri();
|
|
19
|
-
process.env.MONGO_URI = uri;
|
|
20
|
-
await mongoose.connect(uri, { dbName: 'test-db' });
|
|
21
|
-
|
|
22
|
-
await waitForDatabaseConnection();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
afterAll(async () => {
|
|
26
|
-
await mongoose.disconnect();
|
|
27
|
-
await mongoServer.stop();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
afterEach(async () => {
|
|
31
|
-
if (mongoose.connection.db) {
|
|
32
|
-
const collections = await mongoose.connection.db.collections();
|
|
33
|
-
for (const collection of collections) {
|
|
34
|
-
if (!preserveCollections.includes(collection.collectionName)) {
|
|
35
|
-
await collection.deleteMany({});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async function waitForDatabaseConnection(maxRetries = 5, interval = 1000) {
|
|
43
|
-
let retries = 0;
|
|
44
|
-
|
|
45
|
-
while (mongoose.connection.readyState !== ConnectionStates.connected && retries < maxRetries) {
|
|
46
|
-
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
47
|
-
retries++;
|
|
48
|
-
console.log(`Retrying database connection (${retries}/${maxRetries})...`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (mongoose.connection.readyState !== ConnectionStates.connected) {
|
|
52
|
-
throw new Error('Failed to connect to the database within the allowed retries.');
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module for managing the test MongoDB URI.
|
|
3
|
-
* This allows tests to access the current test database URI without relying on environment variables.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
let currentTestMongoUri: null | string = null;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Sets the current test MongoDB URI.
|
|
10
|
-
* Called internally by setupMongoTestEnvironment().
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
export function setTestMongoUri(uri: string): void {
|
|
14
|
-
currentTestMongoUri = uri;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Gets the current test MongoDB URI.
|
|
19
|
-
* Use this to configure frameworks (like NestJS) that need the database connection string.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* // In your test setup
|
|
24
|
-
* import { getTestMongoUri } from '@slango/mangusta/test-utils/testMongoUri';
|
|
25
|
-
*
|
|
26
|
-
* const moduleFixture = await Test.createTestingModule({
|
|
27
|
-
* imports: [AppModule],
|
|
28
|
-
* })
|
|
29
|
-
* .overrideProvider(DATABASE_URI)
|
|
30
|
-
* .useFactory({ factory: () => getTestMongoUri() })
|
|
31
|
-
* .compile();
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @throws Error if called before setupMongoTestEnvironment() has run
|
|
35
|
-
*/
|
|
36
|
-
export function getTestMongoUri(): string {
|
|
37
|
-
if (!currentTestMongoUri) {
|
|
38
|
-
throw new Error(
|
|
39
|
-
'Test MongoDB URI not available. Ensure setupMongoTestEnvironment() is called in beforeAll.',
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
return currentTestMongoUri;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Clears the current test MongoDB URI.
|
|
47
|
-
* Called internally by setupMongoTestEnvironment() in afterAll.
|
|
48
|
-
* @internal
|
|
49
|
-
*/
|
|
50
|
-
export function clearTestMongoUri(): void {
|
|
51
|
-
currentTestMongoUri = null;
|
|
52
|
-
}
|
package/src/types.ts
DELETED
package/tsconfig.build.json
DELETED