@zenith-open/zenithcms-db-mongodb 0.1.0 → 1.0.0-beta.2
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 +21 -0
- package/README.md +31 -0
- package/dist/MongooseAdapter.d.ts +8 -19
- package/dist/MongooseAdapter.js +254 -220
- package/dist/MongooseAdapter.js.map +1 -1
- package/dist/model-factory.js +3 -0
- package/dist/model-factory.js.map +1 -1
- package/package.json +26 -23
- package/eslint.config.mjs +0 -26
- package/src/MongooseAdapter.ts +0 -643
- package/src/index.ts +0 -2
- package/src/model-factory.ts +0 -179
- package/tsconfig.eslint.json +0 -8
- package/tsconfig.json +0 -11
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aman T Shekar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @zenith-open/zenithcms-db-mongodb
|
|
2
|
+
|
|
3
|
+
The officially supported MongoDB persistence adapter for Zenith CMS.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Zenith CMS decouples business logic from database interactions via the `DatabaseAdapter` interface. This package implements that interface using Mongoose, dynamically translating your `cms.config.ts` into native Mongoose Schemas.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @zenith-open/zenithcms-db-mongodb
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
When booting the `ZenithEngine`, pass an instance of the `MongooseAdapter`.
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { ZenithEngine } from '@zenith-open/zenithcms-core'
|
|
21
|
+
import { MongooseAdapter } from '@zenith-open/zenithcms-db-mongodb'
|
|
22
|
+
import config from './cms.config'
|
|
23
|
+
|
|
24
|
+
const engine = new ZenithEngine({
|
|
25
|
+
config,
|
|
26
|
+
adapter: new MongooseAdapter({ uri: process.env.MONGODB_URI }),
|
|
27
|
+
port: 3000
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
engine.start()
|
|
31
|
+
```
|
|
@@ -1,23 +1,4 @@
|
|
|
1
1
|
import { CollectionConfig, DatabaseAdapter, FindOptions, BaseOptions, AuditLogData, VersionData, WebhookDeliveryData, WebhookDeliveryRecord } from '@zenith-open/zenithcms-types';
|
|
2
|
-
export interface CacheLayer {
|
|
3
|
-
get<T>(key: string): Promise<T | undefined>;
|
|
4
|
-
set<T>(key: string, value: T, collection: string): Promise<void>;
|
|
5
|
-
invalidate(collection: string): Promise<void>;
|
|
6
|
-
}
|
|
7
|
-
export declare class LocalCacheLayer implements CacheLayer {
|
|
8
|
-
private cache;
|
|
9
|
-
constructor();
|
|
10
|
-
get<T>(key: string): Promise<T | undefined>;
|
|
11
|
-
set<T>(key: string, value: T, collection: string): Promise<void>;
|
|
12
|
-
invalidate(collection: string): Promise<void>;
|
|
13
|
-
}
|
|
14
|
-
export declare class RedisCacheLayer implements CacheLayer {
|
|
15
|
-
private redis;
|
|
16
|
-
constructor(redisUrl: string);
|
|
17
|
-
get<T>(key: string): Promise<T | undefined>;
|
|
18
|
-
set<T>(key: string, value: T, collection: string): Promise<void>;
|
|
19
|
-
invalidate(collection: string): Promise<void>;
|
|
20
|
-
}
|
|
21
2
|
/**
|
|
22
3
|
* Mongoose Database Adapter — Hardened Edition
|
|
23
4
|
* ──────────────────────────────────────────
|
|
@@ -29,7 +10,14 @@ export declare class MongooseAdapter implements DatabaseAdapter {
|
|
|
29
10
|
name: string;
|
|
30
11
|
private models;
|
|
31
12
|
private cache;
|
|
13
|
+
private consecutiveFailures;
|
|
14
|
+
private circuitBreakerCooldown;
|
|
15
|
+
private readonly CIRCUIT_BREAKER_THRESHOLD;
|
|
16
|
+
private readonly CIRCUIT_BREAKER_RESET_TIMEOUT_MS;
|
|
17
|
+
private _withCircuitBreaker;
|
|
32
18
|
constructor(uri: string);
|
|
19
|
+
getNativeClient<T = any>(): T;
|
|
20
|
+
executeRaw(query: string, params?: any[]): Promise<any>;
|
|
33
21
|
connect(): Promise<void>;
|
|
34
22
|
disconnect(): Promise<void>;
|
|
35
23
|
getHealth(): 'ok' | 'connecting' | 'disconnected' | 'error';
|
|
@@ -40,6 +28,7 @@ export declare class MongooseAdapter implements DatabaseAdapter {
|
|
|
40
28
|
private _getCacheKey;
|
|
41
29
|
find<T = unknown>(collection: string, query: Record<string, unknown>, options?: FindOptions): Promise<T[]>;
|
|
42
30
|
findOne<T = unknown>(collection: string, query: Record<string, unknown>, options?: FindOptions): Promise<T | null>;
|
|
31
|
+
findMany<T = unknown>(collection: string, ids: string[], options?: BaseOptions): Promise<T[]>;
|
|
43
32
|
private _invalidateCache;
|
|
44
33
|
create<T = unknown>(collection: string, data: Partial<T>, options?: BaseOptions): Promise<T>;
|
|
45
34
|
update<T = unknown>(collection: string, id: string, data: Partial<T>, options?: BaseOptions): Promise<T | null>;
|