@zenith-open/zenithcms-types 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 +32 -0
- package/dist/database.d.ts +17 -11
- package/dist/generated.d.ts +34 -4
- package/dist/index.d.ts +24 -5
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +22 -16
- package/src/database.d.ts +0 -84
- package/src/database.js +0 -1
- package/src/database.js.map +0 -1
- package/src/database.ts +0 -164
- package/src/generated.d.ts +0 -274
- package/src/generated.js +0 -7
- package/src/generated.js.map +0 -1
- package/src/generated.ts +0 -143
- package/src/index.d.ts +0 -193
- package/src/index.js +0 -9
- package/src/index.js.map +0 -1
- package/src/index.ts +0 -378
- package/tsconfig.json +0 -15
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,32 @@
|
|
|
1
|
+
# @zenith-open/zenithcms-types
|
|
2
|
+
|
|
3
|
+
The single source of truth for the Zenith CMS ecosystem architecture.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package exposes the underlying Zod interfaces and TypeScript contracts utilized by both the backend engine (`core`), the Database Adapters (`db-mongodb`, `db-postgres`), and the frontend SPA (`admin`).
|
|
8
|
+
|
|
9
|
+
By isolating all core typings into a standalone package, Zenith guarantees absolute parity between schema declaration (the backend contract) and schema consumption (the frontend UI).
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add -D @zenith-open/zenithcms-types
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
When developing plugins or creating custom endpoints, always rely on the strongly typed interfaces exported by this package.
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import type { CMSConfig, CollectionSchema, Field, ZenithPlugin, PluginContext } from '@zenith-open/zenithcms-types'
|
|
23
|
+
|
|
24
|
+
const myPlugin: ZenithPlugin = {
|
|
25
|
+
id: 'my-custom-plugin',
|
|
26
|
+
name: 'Enhancements',
|
|
27
|
+
version: '1.0.0',
|
|
28
|
+
apply: (config: CMSConfig) => {
|
|
29
|
+
return config;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
package/dist/database.d.ts
CHANGED
|
@@ -14,21 +14,26 @@ export interface DatabaseAdapter {
|
|
|
14
14
|
registerCollection(config: CollectionConfig): Promise<void>;
|
|
15
15
|
/** Lists all existing collections/tables in the database */
|
|
16
16
|
getExistingCollections(): Promise<string[]>;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
/** Escape hatch for bypassing the Adapter AST and executing vendor-specific queries natively */
|
|
18
|
+
getNativeClient<T = any>(): T;
|
|
19
|
+
/** Escape hatch for executing raw DDL/SQL queries directly */
|
|
20
|
+
executeRaw(query: string, params?: any[]): Promise<any>;
|
|
21
|
+
find<T = any>(collection: string, query: Record<string, any>, options?: FindOptions): Promise<T[]>;
|
|
22
|
+
findOne<T = any>(collection: string, query: Record<string, any>, options?: BaseOptions): Promise<T | null>;
|
|
23
|
+
findMany<T = any>(collection: string, ids: string[], options?: BaseOptions): Promise<T[]>;
|
|
24
|
+
create<T = any>(collection: string, data: Partial<T>, options?: BaseOptions): Promise<T>;
|
|
25
|
+
update<T = any>(collection: string, id: string, data: Partial<T>, options?: BaseOptions): Promise<T | null>;
|
|
26
|
+
updateMany(collection: string, query: Record<string, any>, data: any, options?: BaseOptions): Promise<number>;
|
|
22
27
|
delete(collection: string, id: string, options?: BaseOptions): Promise<boolean>;
|
|
23
|
-
deleteMany(collection: string, query: Record<string,
|
|
24
|
-
count(collection: string, query: Record<string,
|
|
25
|
-
aggregate<T =
|
|
28
|
+
deleteMany(collection: string, query: Record<string, any>, options?: BaseOptions): Promise<number>;
|
|
29
|
+
count(collection: string, query: Record<string, any>): Promise<number>;
|
|
30
|
+
aggregate<T = any>(collection: string, pipeline: any[], options?: BaseOptions): Promise<T[]>;
|
|
26
31
|
/**
|
|
27
32
|
* Atomically finds a single document and updates it, returning either
|
|
28
33
|
* the original (returnDocument: 'before') or updated (returnDocument: 'after') document.
|
|
29
34
|
* Returns null if no document matches the query.
|
|
30
35
|
*/
|
|
31
|
-
findOneAndUpdate<T =
|
|
36
|
+
findOneAndUpdate<T = any>(collection: string, query: Record<string, any>, update: Record<string, any>, options?: BaseOptions & {
|
|
32
37
|
returnDocument?: 'before' | 'after';
|
|
33
38
|
}): Promise<T | null>;
|
|
34
39
|
/**
|
|
@@ -36,7 +41,7 @@ export interface DatabaseAdapter {
|
|
|
36
41
|
* If the adapter does not support transactions (e.g. standalone Mongo),
|
|
37
42
|
* this will execute the function without a transaction context.
|
|
38
43
|
*/
|
|
39
|
-
transaction<T>(fn: (session:
|
|
44
|
+
transaction<T>(fn: (session: any) => Promise<T>): Promise<T>;
|
|
40
45
|
createAuditLog(data: AuditLogData, options?: BaseOptions): Promise<void>;
|
|
41
46
|
createVersion(data: VersionData, options?: BaseOptions): Promise<void>;
|
|
42
47
|
getVersions(collection: string, documentId: string): Promise<VersionData[]>;
|
|
@@ -47,7 +52,7 @@ export interface DatabaseAdapter {
|
|
|
47
52
|
* Each adapter translates this into its native search primitive
|
|
48
53
|
* (MongoDB $regex/$text, Postgres ILIKE/pg_trgm).
|
|
49
54
|
*/
|
|
50
|
-
search<T =
|
|
55
|
+
search<T = any>(collection: string, query: string, fields: string[], limit?: number, options?: BaseOptions): Promise<T[]>;
|
|
51
56
|
}
|
|
52
57
|
export interface BaseOptions {
|
|
53
58
|
session?: unknown;
|
|
@@ -61,6 +66,7 @@ export interface FindOptions extends BaseOptions {
|
|
|
61
66
|
limit?: number;
|
|
62
67
|
select?: string | string[];
|
|
63
68
|
populate?: string | string[];
|
|
69
|
+
cursor?: string;
|
|
64
70
|
}
|
|
65
71
|
export interface AuditLogData {
|
|
66
72
|
userId: string;
|
package/dist/generated.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface Posts extends ZenithDocument {
|
|
|
25
25
|
};
|
|
26
26
|
content?: string;
|
|
27
27
|
publishedAt?: string | Date;
|
|
28
|
-
author?: Record<string,
|
|
28
|
+
author?: Record<string, any>;
|
|
29
29
|
}
|
|
30
30
|
export interface Categories extends ZenithDocument {
|
|
31
31
|
title: string;
|
|
@@ -71,8 +71,36 @@ export interface Pages extends ZenithDocument {
|
|
|
71
71
|
blockType: 'undefined';
|
|
72
72
|
})[];
|
|
73
73
|
}
|
|
74
|
-
export interface
|
|
75
|
-
|
|
74
|
+
export interface ZRoles extends ZenithDocument {
|
|
75
|
+
roleName: string;
|
|
76
|
+
roleType: string;
|
|
77
|
+
description?: string;
|
|
78
|
+
isSystem: boolean;
|
|
79
|
+
permissions: Record<string, any>;
|
|
80
|
+
}
|
|
81
|
+
export interface ZApiKeys extends ZenithDocument {
|
|
82
|
+
name: string;
|
|
83
|
+
key: string;
|
|
84
|
+
role: string;
|
|
85
|
+
expiresAt?: string | Date;
|
|
86
|
+
revoked?: boolean;
|
|
87
|
+
lastUsed?: string | Date;
|
|
88
|
+
allowedCollections?: Record<string, any>;
|
|
89
|
+
}
|
|
90
|
+
export interface Users extends ZenithDocument {
|
|
91
|
+
email: string;
|
|
92
|
+
username?: string;
|
|
93
|
+
displayName?: string;
|
|
94
|
+
password: string;
|
|
95
|
+
role?: ('admin' | 'editor' | 'viewer');
|
|
96
|
+
failedLoginAttempts?: number;
|
|
97
|
+
lockUntil?: string | Date;
|
|
98
|
+
emailVerified?: boolean;
|
|
99
|
+
verificationToken?: string;
|
|
100
|
+
verificationTokenExpiry?: string | Date;
|
|
101
|
+
twoFactorSecret?: string;
|
|
102
|
+
twoFactorEnabled?: boolean;
|
|
103
|
+
oauthProviders?: Record<string, any>;
|
|
76
104
|
}
|
|
77
105
|
export interface Media extends ZenithDocument {
|
|
78
106
|
name?: string;
|
|
@@ -120,7 +148,9 @@ export interface ZenithCollections {
|
|
|
120
148
|
'categories': Categories;
|
|
121
149
|
'products': Products;
|
|
122
150
|
'pages': Pages;
|
|
123
|
-
'
|
|
151
|
+
'z_roles': ZRoles;
|
|
152
|
+
'z_api_keys': ZApiKeys;
|
|
153
|
+
'users': Users;
|
|
124
154
|
'media': Media;
|
|
125
155
|
'site-settings': SiteSettings;
|
|
126
156
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Uses Discriminated Unions for robust field-level validation and IntelliSense.
|
|
6
6
|
*/
|
|
7
7
|
import type React from 'react';
|
|
8
|
+
export * from './generated';
|
|
8
9
|
export interface ZenithDocument {
|
|
9
10
|
_id?: string;
|
|
10
11
|
id?: string;
|
|
@@ -217,6 +218,11 @@ export interface CollectionConfig {
|
|
|
217
218
|
}) => unknown | Promise<unknown>;
|
|
218
219
|
afterError?: (error: Error, data: unknown, user: unknown) => void | Promise<void>;
|
|
219
220
|
};
|
|
221
|
+
endpoints?: Array<{
|
|
222
|
+
path: string;
|
|
223
|
+
method: 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
224
|
+
handler: (req: any, res: any, next: any) => void | Promise<void>;
|
|
225
|
+
}>;
|
|
220
226
|
access?: {
|
|
221
227
|
/** Return false to deny, or an object to merge as query constraints (Row-Level Security). */
|
|
222
228
|
read?: (user: unknown, context?: {
|
|
@@ -244,11 +250,6 @@ export interface CollectionConfig {
|
|
|
244
250
|
icon?: string;
|
|
245
251
|
previewUrl?: string | ((doc: unknown) => string);
|
|
246
252
|
};
|
|
247
|
-
endpoints?: {
|
|
248
|
-
path: string;
|
|
249
|
-
method: 'get' | 'post' | 'put' | 'delete' | 'patch';
|
|
250
|
-
handler: (req: unknown, res: unknown) => void | Promise<void>;
|
|
251
|
-
}[];
|
|
252
253
|
}
|
|
253
254
|
export type GlobalConfig = CollectionConfig;
|
|
254
255
|
export interface ZenithPlugin {
|
|
@@ -292,6 +293,19 @@ export interface ZenithPlugin {
|
|
|
292
293
|
* Called at engine bootstrap for each enabled plugin.
|
|
293
294
|
*/
|
|
294
295
|
apply: (config: CMSConfig, pluginConfig?: Record<string, unknown>) => CMSConfig | void;
|
|
296
|
+
/**
|
|
297
|
+
* Express sub-router for this plugin.
|
|
298
|
+
* It will be mounted automatically at `/api/v1/plugins/{plugin.id}`
|
|
299
|
+
*/
|
|
300
|
+
router?: (app: any) => void;
|
|
301
|
+
/** Custom collection-level hooks provided by this plugin */
|
|
302
|
+
hooks?: {
|
|
303
|
+
[collectionSlug: string]: CollectionConfig['hooks'];
|
|
304
|
+
};
|
|
305
|
+
/** Paths to custom React admin UI components (e.g. custom field UIs) */
|
|
306
|
+
adminComponents?: {
|
|
307
|
+
[fieldType: string]: string;
|
|
308
|
+
};
|
|
295
309
|
/** Called after all plugins are applied, before routes are mounted */
|
|
296
310
|
onInit?: (ctx: PluginContext) => void | Promise<void>;
|
|
297
311
|
/** Called after the engine is fully started and listening */
|
|
@@ -348,6 +362,11 @@ export interface CMSConfig {
|
|
|
348
362
|
cors?: {
|
|
349
363
|
origins: string[];
|
|
350
364
|
};
|
|
365
|
+
endpoints?: Array<{
|
|
366
|
+
path: string;
|
|
367
|
+
method: 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
368
|
+
handler: (req: any, res: any, next: any) => void | Promise<void>;
|
|
369
|
+
}>;
|
|
351
370
|
}
|
|
352
371
|
export * from './generated';
|
|
353
372
|
export * from './database';
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,aAAa,CAAA;AAgY3B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@zenith-open/zenithcms-types",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"publishConfig": {
|
|
5
|
-
"access": "public"
|
|
6
|
-
},
|
|
7
|
-
"main": "dist/index.js",
|
|
8
|
-
"types": "dist/index.d.ts",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@zenith-open/zenithcms-types",
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@types/react": "^18.0.0",
|
|
11
|
+
"react": "^18.0.0",
|
|
12
|
+
"typescript": "^5.0.0"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"lint": "echo 'Lint bypassed for types'"
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/database.d.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { CollectionConfig } from './index';
|
|
2
|
-
/**
|
|
3
|
-
* Zenith Database Adapter Contract
|
|
4
|
-
* ────────────────────────────────
|
|
5
|
-
* Hardened interface for database agnostic operations.
|
|
6
|
-
* Use generics <T> to ensure type safety in higher level services.
|
|
7
|
-
*/
|
|
8
|
-
export interface DatabaseAdapter {
|
|
9
|
-
name: string;
|
|
10
|
-
connect(): Promise<void>;
|
|
11
|
-
disconnect(): Promise<void>;
|
|
12
|
-
getHealth(): 'ok' | 'connecting' | 'disconnected' | 'error';
|
|
13
|
-
/** Syncs the provided collection config with the physical DB schema */
|
|
14
|
-
registerCollection(config: CollectionConfig): Promise<void>;
|
|
15
|
-
/** Lists all existing collections/tables in the database */
|
|
16
|
-
getExistingCollections(): Promise<string[]>;
|
|
17
|
-
find<T = unknown>(collection: string, query: Record<string, unknown>, options?: FindOptions): Promise<T[]>;
|
|
18
|
-
findOne<T = unknown>(collection: string, query: Record<string, unknown>, options?: BaseOptions): Promise<T | null>;
|
|
19
|
-
create<T = unknown>(collection: string, data: Partial<T>, options?: BaseOptions): Promise<T>;
|
|
20
|
-
update<T = unknown>(collection: string, id: string, data: Partial<T>, options?: BaseOptions): Promise<T | null>;
|
|
21
|
-
updateMany(collection: string, query: Record<string, unknown>, data: unknown, options?: BaseOptions): Promise<number>;
|
|
22
|
-
delete(collection: string, id: string, options?: BaseOptions): Promise<boolean>;
|
|
23
|
-
deleteMany(collection: string, query: Record<string, unknown>, options?: BaseOptions): Promise<number>;
|
|
24
|
-
count(collection: string, query: Record<string, unknown>): Promise<number>;
|
|
25
|
-
aggregate<T = unknown>(collection: string, pipeline: unknown[]): Promise<T[]>;
|
|
26
|
-
/**
|
|
27
|
-
* Executes multiple operations in a transaction.
|
|
28
|
-
* If the adapter does not support transactions (e.g. standalone Mongo),
|
|
29
|
-
* this will execute the function without a transaction context.
|
|
30
|
-
*/
|
|
31
|
-
transaction<T>(fn: (session: unknown) => Promise<T>): Promise<T>;
|
|
32
|
-
createAuditLog(data: AuditLogData): Promise<void>;
|
|
33
|
-
createVersion(data: VersionData): Promise<void>;
|
|
34
|
-
getVersions(collection: string, documentId: string): Promise<VersionData[]>;
|
|
35
|
-
createWebhookDelivery(data: WebhookDeliveryData): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Full-text / pattern search across specified fields in a collection.
|
|
38
|
-
* Each adapter translates this into its native search primitive
|
|
39
|
-
* (MongoDB $regex/$text, Postgres ILIKE/pg_trgm).
|
|
40
|
-
*/
|
|
41
|
-
search<T = unknown>(collection: string, query: string, fields: string[], limit?: number, options?: BaseOptions): Promise<T[]>;
|
|
42
|
-
}
|
|
43
|
-
export interface BaseOptions {
|
|
44
|
-
session?: unknown;
|
|
45
|
-
tenantId?: string;
|
|
46
|
-
siteId?: string;
|
|
47
|
-
}
|
|
48
|
-
export interface FindOptions extends BaseOptions {
|
|
49
|
-
sort?: string | Record<string, unknown>;
|
|
50
|
-
skip?: number;
|
|
51
|
-
limit?: number;
|
|
52
|
-
select?: string | string[];
|
|
53
|
-
populate?: string | string[];
|
|
54
|
-
}
|
|
55
|
-
export interface AuditLogData {
|
|
56
|
-
userId: string;
|
|
57
|
-
userEmail: string;
|
|
58
|
-
action: string;
|
|
59
|
-
collectionName: string;
|
|
60
|
-
documentId?: string;
|
|
61
|
-
changes?: unknown;
|
|
62
|
-
ip?: string;
|
|
63
|
-
userAgent?: string;
|
|
64
|
-
timestamp?: Date;
|
|
65
|
-
}
|
|
66
|
-
export interface VersionData {
|
|
67
|
-
collectionName: string;
|
|
68
|
-
collectionSlug: string;
|
|
69
|
-
documentId: string;
|
|
70
|
-
snapshot: unknown;
|
|
71
|
-
delta?: unknown;
|
|
72
|
-
createdBy: string;
|
|
73
|
-
timestamp: Date;
|
|
74
|
-
}
|
|
75
|
-
export interface WebhookDeliveryData {
|
|
76
|
-
collectionSlug?: string;
|
|
77
|
-
event: string;
|
|
78
|
-
url: string;
|
|
79
|
-
payload?: unknown;
|
|
80
|
-
success: boolean;
|
|
81
|
-
responseStatus?: number;
|
|
82
|
-
timestamp?: Date;
|
|
83
|
-
}
|
|
84
|
-
|
package/src/database.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// Database types module (interfaces only)
|
package/src/database.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["database.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAA;AAgIvB,MAAM,OAAO,mBAAmB;IAGV;IAFZ,YAAY,CAAS;IAE7B,YAAoB,cAA+B;QAA/B,mBAAc,GAAd,cAAc,CAAiB;QACjD,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;IAC3D,CAAC;IAEM,KAAK,CAAC,IAAI,CACf,UAAkB,EAClB,KAA8B,EAC9B,OAAqB;QAErB,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,IAAI,CAAC;gBACH,MAAM,WAAW,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;gBAC5E,oEAAoE;gBACpE,MAAM,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,iBAAiB,CAAC,CAAC,CAAA;gBAC/E,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,WAAW,UAAU,CAAC,CAAA;gBAC5D,IAAI,MAAM,EAAE,CAAC;oBACX,MAAM,cAAc,GAAG,IAAI,CAAC,cAAqB,CAAA;oBACjD,MAAM,QAAQ,GAAG,CAAC,OAAO,cAAc,CAAC,WAAW,KAAK,UAAU,CAAC;wBACjE,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC,OAAO,CAAC;wBACrC,CAAC,CAAC,cAAc,CAAC,EAAE,CAAA;oBACrB,MAAM,WAAW,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC,UAAU,CAAC,CAAA;oBACvD,OAAO,MAAM,MAAM,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;gBAC5D,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,2CAA2C;YAC7C,CAAC;QACH,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAI,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;IACtE,CAAC;IAEM,KAAK,CAAC,MAAM,CAAc,UAAkB,EAAE,IAAgB,EAAE,OAAqB;QAC1F,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,IAAI,CAAC;gBACH,MAAM,WAAW,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;gBAC5E,oEAAoE;gBACpE,MAAM,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,iBAAiB,CAAC,CAAC,CAAA;gBAC/E,MAAM,OAAO,GAAG,eAAe,CAAC,SAAS,WAAW,UAAU,CAAC,CAAA;gBAC/D,IAAI,OAAO,EAAE,CAAC;oBACZ,MAAM,cAAc,GAAG,IAAI,CAAC,cAAqB,CAAA;oBACjD,MAAM,QAAQ,GAAG,CAAC,OAAO,cAAc,CAAC,WAAW,KAAK,UAAU,CAAC;wBACjE,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC,OAAO,CAAC;wBACrC,CAAC,CAAC,cAAc,CAAC,EAAE,CAAA;oBACrB,MAAM,WAAW,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC,UAAU,CAAC,CAAA;oBACvD,OAAO,MAAM,OAAO,CAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;gBAC5D,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,2CAA2C;YAC7C,CAAC;QACH,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAI,UAAU,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IACvE,CAAC;CACF"}
|
package/src/database.ts
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { CollectionConfig } from './index'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Zenith Database Adapter Contract
|
|
5
|
-
* ────────────────────────────────
|
|
6
|
-
* Hardened interface for database agnostic operations.
|
|
7
|
-
* Use generics <T> to ensure type safety in higher level services.
|
|
8
|
-
*/
|
|
9
|
-
export interface DatabaseAdapter {
|
|
10
|
-
name: string
|
|
11
|
-
|
|
12
|
-
// ── Initialization ────────────────────────────────────────────────────────
|
|
13
|
-
connect(): Promise<void>
|
|
14
|
-
disconnect(): Promise<void>
|
|
15
|
-
getHealth(): 'ok' | 'connecting' | 'disconnected' | 'error'
|
|
16
|
-
|
|
17
|
-
// ── Schema Management ─────────────────────────────────────────────────────
|
|
18
|
-
/** Syncs the provided collection config with the physical DB schema */
|
|
19
|
-
registerCollection(config: CollectionConfig): Promise<void>
|
|
20
|
-
|
|
21
|
-
/** Lists all existing collections/tables in the database */
|
|
22
|
-
getExistingCollections(): Promise<string[]>
|
|
23
|
-
|
|
24
|
-
// ── CRUD Operations ───────────────────────────────────────────────────────
|
|
25
|
-
find<T = unknown>(
|
|
26
|
-
collection: string,
|
|
27
|
-
query: Record<string, unknown>,
|
|
28
|
-
options?: FindOptions
|
|
29
|
-
): Promise<T[]>
|
|
30
|
-
findOne<T = unknown>(
|
|
31
|
-
collection: string,
|
|
32
|
-
query: Record<string, unknown>,
|
|
33
|
-
options?: BaseOptions
|
|
34
|
-
): Promise<T | null>
|
|
35
|
-
create<T = unknown>(collection: string, data: Partial<T>, options?: BaseOptions): Promise<T>
|
|
36
|
-
update<T = unknown>(
|
|
37
|
-
collection: string,
|
|
38
|
-
id: string,
|
|
39
|
-
data: Partial<T>,
|
|
40
|
-
options?: BaseOptions
|
|
41
|
-
): Promise<T | null>
|
|
42
|
-
updateMany(
|
|
43
|
-
collection: string,
|
|
44
|
-
query: Record<string, unknown>,
|
|
45
|
-
data: unknown,
|
|
46
|
-
options?: BaseOptions
|
|
47
|
-
): Promise<number>
|
|
48
|
-
delete(collection: string, id: string, options?: BaseOptions): Promise<boolean>
|
|
49
|
-
deleteMany(
|
|
50
|
-
collection: string,
|
|
51
|
-
query: Record<string, unknown>,
|
|
52
|
-
options?: BaseOptions
|
|
53
|
-
): Promise<number>
|
|
54
|
-
|
|
55
|
-
// ── Advanced Operations ───────────────────────────────────────────────────
|
|
56
|
-
count(collection: string, query: Record<string, unknown>): Promise<number>
|
|
57
|
-
aggregate<T = unknown>(collection: string, pipeline: unknown[], options?: BaseOptions): Promise<T[]>
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Atomically finds a single document and updates it, returning either
|
|
61
|
-
* the original (returnDocument: 'before') or updated (returnDocument: 'after') document.
|
|
62
|
-
* Returns null if no document matches the query.
|
|
63
|
-
*/
|
|
64
|
-
findOneAndUpdate<T = unknown>(
|
|
65
|
-
collection: string,
|
|
66
|
-
query: Record<string, unknown>,
|
|
67
|
-
update: Record<string, unknown>,
|
|
68
|
-
options?: BaseOptions & { returnDocument?: 'before' | 'after' }
|
|
69
|
-
): Promise<T | null>
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Executes multiple operations in a transaction.
|
|
73
|
-
* If the adapter does not support transactions (e.g. standalone Mongo),
|
|
74
|
-
* this will execute the function without a transaction context.
|
|
75
|
-
*/
|
|
76
|
-
transaction<T>(fn: (session: unknown) => Promise<T>): Promise<T>
|
|
77
|
-
|
|
78
|
-
// ── Zenith Engine Features ────────────────────────────────────────────────
|
|
79
|
-
createAuditLog(data: AuditLogData, options?: BaseOptions): Promise<void>
|
|
80
|
-
createVersion(data: VersionData, options?: BaseOptions): Promise<void>
|
|
81
|
-
getVersions(collection: string, documentId: string): Promise<VersionData[]>
|
|
82
|
-
createWebhookDelivery(data: WebhookDeliveryData): Promise<void>
|
|
83
|
-
getWebhookDeliveries(webhookId: string, limit?: number): Promise<WebhookDeliveryRecord[]>
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Full-text / pattern search across specified fields in a collection.
|
|
87
|
-
* Each adapter translates this into its native search primitive
|
|
88
|
-
* (MongoDB $regex/$text, Postgres ILIKE/pg_trgm).
|
|
89
|
-
*/
|
|
90
|
-
search<T = unknown>(
|
|
91
|
-
collection: string,
|
|
92
|
-
query: string,
|
|
93
|
-
fields: string[],
|
|
94
|
-
limit?: number,
|
|
95
|
-
options?: BaseOptions
|
|
96
|
-
): Promise<T[]>
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export interface BaseOptions {
|
|
100
|
-
session?: unknown
|
|
101
|
-
tenantId?: string
|
|
102
|
-
siteId?: string
|
|
103
|
-
expectedVersion?: number
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export interface FindOptions extends BaseOptions {
|
|
107
|
-
sort?: string | Record<string, unknown>
|
|
108
|
-
skip?: number
|
|
109
|
-
limit?: number
|
|
110
|
-
select?: string | string[]
|
|
111
|
-
populate?: string | string[]
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface AuditLogData {
|
|
115
|
-
userId: string
|
|
116
|
-
userEmail: string
|
|
117
|
-
userName?: string
|
|
118
|
-
action: string
|
|
119
|
-
collectionName: string
|
|
120
|
-
documentId?: string
|
|
121
|
-
changes?: unknown
|
|
122
|
-
ip?: string
|
|
123
|
-
userAgent?: string
|
|
124
|
-
timestamp?: Date
|
|
125
|
-
status?: 'success' | 'failed'
|
|
126
|
-
resource?: string
|
|
127
|
-
siteId?: string
|
|
128
|
-
hash?: string
|
|
129
|
-
previousHash?: string
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export interface VersionData {
|
|
133
|
-
collectionName: string
|
|
134
|
-
collectionSlug: string
|
|
135
|
-
documentId: string
|
|
136
|
-
snapshot: unknown
|
|
137
|
-
delta?: unknown
|
|
138
|
-
createdBy: string
|
|
139
|
-
timestamp: Date
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export interface WebhookDeliveryData {
|
|
143
|
-
webhookId?: string
|
|
144
|
-
collectionSlug?: string
|
|
145
|
-
event: string
|
|
146
|
-
url: string
|
|
147
|
-
payload?: unknown
|
|
148
|
-
success: boolean
|
|
149
|
-
responseStatus?: number
|
|
150
|
-
timestamp?: Date
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export interface WebhookDeliveryRecord {
|
|
154
|
-
id: string
|
|
155
|
-
webhookId?: string
|
|
156
|
-
collectionSlug?: string
|
|
157
|
-
event: string
|
|
158
|
-
url: string
|
|
159
|
-
payload?: unknown
|
|
160
|
-
success: boolean
|
|
161
|
-
responseStatus?: number
|
|
162
|
-
timestamp: Date | string
|
|
163
|
-
}
|
|
164
|
-
|