@zenith-open/zenithcms-types 0.1.0 → 1.0.0-beta.10
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 +41 -11
- package/dist/generated.d.ts +39 -19
- package/dist/index.d.ts +42 -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: ZenithQueryAST, options?: FindOptions): Promise<T[]>;
|
|
22
|
+
findOne<T = any>(collection: string, query: ZenithQueryAST, 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: ZenithQueryAST, data: any, options?: BaseOptions): Promise<number>;
|
|
22
27
|
delete(collection: string, id: string, options?: BaseOptions): Promise<boolean>;
|
|
23
|
-
deleteMany(collection: string, query:
|
|
24
|
-
count(collection: string, query:
|
|
25
|
-
aggregate<T =
|
|
28
|
+
deleteMany(collection: string, query: ZenithQueryAST, options?: BaseOptions): Promise<number>;
|
|
29
|
+
count(collection: string, query: ZenithQueryAST): 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: ZenithQueryAST, 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;
|
|
@@ -109,3 +115,27 @@ export interface WebhookDeliveryRecord {
|
|
|
109
115
|
responseStatus?: number;
|
|
110
116
|
timestamp: Date | string;
|
|
111
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* ZenithQueryAST Formal Specification
|
|
120
|
+
* ───────────────────────────────────
|
|
121
|
+
* Standardized cross-database query language.
|
|
122
|
+
* Currently mimics MongoDB syntax due to historical reasons,
|
|
123
|
+
* but formally documents it so adapters (e.g. Postgres) know exactly what to parse.
|
|
124
|
+
*/
|
|
125
|
+
export type ZenithQueryAST = {
|
|
126
|
+
$and?: ZenithQueryAST[];
|
|
127
|
+
$or?: ZenithQueryAST[];
|
|
128
|
+
[field: string]: any | {
|
|
129
|
+
$eq?: any;
|
|
130
|
+
$ne?: any;
|
|
131
|
+
$in?: any[];
|
|
132
|
+
$nin?: any[];
|
|
133
|
+
$gt?: number | Date | string;
|
|
134
|
+
$gte?: number | Date | string;
|
|
135
|
+
$lt?: number | Date | string;
|
|
136
|
+
$lte?: number | Date | string;
|
|
137
|
+
$exists?: boolean;
|
|
138
|
+
$regex?: string | RegExp;
|
|
139
|
+
$options?: string;
|
|
140
|
+
};
|
|
141
|
+
};
|
package/dist/generated.d.ts
CHANGED
|
@@ -4,11 +4,20 @@
|
|
|
4
4
|
* DO NOT MODIFY MANUALLY.
|
|
5
5
|
*/
|
|
6
6
|
export interface ZenithDocument {
|
|
7
|
-
|
|
7
|
+
id: string;
|
|
8
8
|
createdAt: string;
|
|
9
9
|
updatedAt: string;
|
|
10
10
|
status?: 'draft' | 'published' | 'archived' | string;
|
|
11
11
|
}
|
|
12
|
+
export interface ExternalUsers extends ZenithDocument {
|
|
13
|
+
name?: string;
|
|
14
|
+
email?: string;
|
|
15
|
+
phone?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface Media extends ZenithDocument {
|
|
18
|
+
alt: string;
|
|
19
|
+
url: string;
|
|
20
|
+
}
|
|
12
21
|
export interface Authors extends ZenithDocument {
|
|
13
22
|
name: string;
|
|
14
23
|
avatar?: {
|
|
@@ -19,17 +28,16 @@ export interface Authors extends ZenithDocument {
|
|
|
19
28
|
}
|
|
20
29
|
export interface Posts extends ZenithDocument {
|
|
21
30
|
title: string;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
alt?: string;
|
|
25
|
-
};
|
|
26
|
-
content?: string;
|
|
31
|
+
slug: string;
|
|
32
|
+
content: string;
|
|
27
33
|
publishedAt?: string | Date;
|
|
28
|
-
|
|
34
|
+
authors?: Users | null;
|
|
35
|
+
categories?: Categories | null;
|
|
36
|
+
status?: ('draft' | 'published');
|
|
29
37
|
}
|
|
30
38
|
export interface Categories extends ZenithDocument {
|
|
31
39
|
title: string;
|
|
32
|
-
|
|
40
|
+
description?: string;
|
|
33
41
|
}
|
|
34
42
|
export interface Products extends ZenithDocument {
|
|
35
43
|
name: string;
|
|
@@ -71,16 +79,25 @@ export interface Pages extends ZenithDocument {
|
|
|
71
79
|
blockType: 'undefined';
|
|
72
80
|
})[];
|
|
73
81
|
}
|
|
74
|
-
export interface
|
|
75
|
-
|
|
82
|
+
export interface ZRoles extends ZenithDocument {
|
|
83
|
+
roleName: string;
|
|
84
|
+
roleType: string;
|
|
85
|
+
description?: string;
|
|
86
|
+
isSystem: boolean;
|
|
87
|
+
permissions: Record<string, any>;
|
|
76
88
|
}
|
|
77
|
-
export interface
|
|
78
|
-
name
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
export interface ZApiKeys extends ZenithDocument {
|
|
90
|
+
name: string;
|
|
91
|
+
key: string;
|
|
92
|
+
role: string;
|
|
93
|
+
expiresAt?: string | Date;
|
|
94
|
+
revoked?: boolean;
|
|
95
|
+
lastUsed?: string | Date;
|
|
96
|
+
allowedCollections?: Record<string, any>;
|
|
97
|
+
}
|
|
98
|
+
export interface Users extends ZenithDocument {
|
|
99
|
+
name: string;
|
|
100
|
+
role: ('admin' | 'editor' | 'user');
|
|
84
101
|
}
|
|
85
102
|
export interface SiteSettings extends ZenithDocument {
|
|
86
103
|
siteName: string;
|
|
@@ -115,13 +132,16 @@ export interface SiteSettings extends ZenithDocument {
|
|
|
115
132
|
}[];
|
|
116
133
|
}
|
|
117
134
|
export interface ZenithCollections {
|
|
135
|
+
'external_users': ExternalUsers;
|
|
136
|
+
'media': Media;
|
|
118
137
|
'authors': Authors;
|
|
119
138
|
'posts': Posts;
|
|
120
139
|
'categories': Categories;
|
|
121
140
|
'products': Products;
|
|
122
141
|
'pages': Pages;
|
|
123
|
-
'
|
|
124
|
-
'
|
|
142
|
+
'z_roles': ZRoles;
|
|
143
|
+
'z_api_keys': ZApiKeys;
|
|
144
|
+
'users': Users;
|
|
125
145
|
'site-settings': SiteSettings;
|
|
126
146
|
}
|
|
127
147
|
/**
|
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;
|
|
@@ -181,6 +182,24 @@ export interface CollectionConfig {
|
|
|
181
182
|
plural: string;
|
|
182
183
|
};
|
|
183
184
|
fields: FieldConfig[];
|
|
185
|
+
federation?: {
|
|
186
|
+
enabled: boolean;
|
|
187
|
+
provider: 'rest' | 'graphql' | 'custom';
|
|
188
|
+
endpoint: string;
|
|
189
|
+
headers?: Record<string, string>;
|
|
190
|
+
methods?: {
|
|
191
|
+
find?: string;
|
|
192
|
+
findById?: string;
|
|
193
|
+
create?: string;
|
|
194
|
+
update?: string;
|
|
195
|
+
delete?: string;
|
|
196
|
+
};
|
|
197
|
+
mapping?: {
|
|
198
|
+
id?: string;
|
|
199
|
+
results?: string;
|
|
200
|
+
total?: string;
|
|
201
|
+
};
|
|
202
|
+
};
|
|
184
203
|
drafts?: boolean;
|
|
185
204
|
seo?: boolean;
|
|
186
205
|
timestamps?: boolean;
|
|
@@ -217,6 +236,11 @@ export interface CollectionConfig {
|
|
|
217
236
|
}) => unknown | Promise<unknown>;
|
|
218
237
|
afterError?: (error: Error, data: unknown, user: unknown) => void | Promise<void>;
|
|
219
238
|
};
|
|
239
|
+
endpoints?: Array<{
|
|
240
|
+
path: string;
|
|
241
|
+
method: 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
242
|
+
handler: (req: any, res: any, next: any) => void | Promise<void>;
|
|
243
|
+
}>;
|
|
220
244
|
access?: {
|
|
221
245
|
/** Return false to deny, or an object to merge as query constraints (Row-Level Security). */
|
|
222
246
|
read?: (user: unknown, context?: {
|
|
@@ -244,11 +268,6 @@ export interface CollectionConfig {
|
|
|
244
268
|
icon?: string;
|
|
245
269
|
previewUrl?: string | ((doc: unknown) => string);
|
|
246
270
|
};
|
|
247
|
-
endpoints?: {
|
|
248
|
-
path: string;
|
|
249
|
-
method: 'get' | 'post' | 'put' | 'delete' | 'patch';
|
|
250
|
-
handler: (req: unknown, res: unknown) => void | Promise<void>;
|
|
251
|
-
}[];
|
|
252
271
|
}
|
|
253
272
|
export type GlobalConfig = CollectionConfig;
|
|
254
273
|
export interface ZenithPlugin {
|
|
@@ -292,6 +311,19 @@ export interface ZenithPlugin {
|
|
|
292
311
|
* Called at engine bootstrap for each enabled plugin.
|
|
293
312
|
*/
|
|
294
313
|
apply: (config: CMSConfig, pluginConfig?: Record<string, unknown>) => CMSConfig | void;
|
|
314
|
+
/**
|
|
315
|
+
* Express sub-router for this plugin.
|
|
316
|
+
* It will be mounted automatically at `/api/v1/plugins/{plugin.id}`
|
|
317
|
+
*/
|
|
318
|
+
router?: (app: any) => void;
|
|
319
|
+
/** Custom collection-level hooks provided by this plugin */
|
|
320
|
+
hooks?: {
|
|
321
|
+
[collectionSlug: string]: CollectionConfig['hooks'];
|
|
322
|
+
};
|
|
323
|
+
/** Paths to custom React admin UI components (e.g. custom field UIs) */
|
|
324
|
+
adminComponents?: {
|
|
325
|
+
[fieldType: string]: string;
|
|
326
|
+
};
|
|
295
327
|
/** Called after all plugins are applied, before routes are mounted */
|
|
296
328
|
onInit?: (ctx: PluginContext) => void | Promise<void>;
|
|
297
329
|
/** Called after the engine is fully started and listening */
|
|
@@ -348,6 +380,11 @@ export interface CMSConfig {
|
|
|
348
380
|
cors?: {
|
|
349
381
|
origins: string[];
|
|
350
382
|
};
|
|
383
|
+
endpoints?: Array<{
|
|
384
|
+
path: string;
|
|
385
|
+
method: 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
386
|
+
handler: (req: any, res: any, next: any) => void | Promise<void>;
|
|
387
|
+
}>;
|
|
351
388
|
}
|
|
352
389
|
export * from './generated';
|
|
353
390
|
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;AAkZ3B,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.10",
|
|
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
|
-
|