@rebasepro/server-mongo 0.0.1-canary.4829d6e
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 +22 -0
- package/README.md +86 -0
- package/dist/MongoBootstrapper.d.ts +18 -0
- package/dist/MongoBootstrapper.d.ts.map +1 -0
- package/dist/auth/ensure-collections.d.ts +3 -0
- package/dist/auth/ensure-collections.d.ts.map +1 -0
- package/dist/auth/services.d.ts +156 -0
- package/dist/auth/services.d.ts.map +1 -0
- package/dist/connection.d.ts +35 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/db/MongoConditionBuilder.d.ts +64 -0
- package/dist/db/MongoConditionBuilder.d.ts.map +1 -0
- package/dist/db/MongoDataService.d.ts +101 -0
- package/dist/db/MongoDataService.d.ts.map +1 -0
- package/dist/ensure-collections-Bkx_O5CQ.js +94 -0
- package/dist/ensure-collections-Bkx_O5CQ.js.map +1 -0
- package/dist/ensure-history-collection-yajOt2dv.js +21 -0
- package/dist/ensure-history-collection-yajOt2dv.js.map +1 -0
- package/dist/factory.d.ts +151 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/history/ensure-history-collection.d.ts +3 -0
- package/dist/history/ensure-history-collection.d.ts.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.es.js +2508 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +2925 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/services/MongoDriver.d.ts +125 -0
- package/dist/services/MongoDriver.d.ts.map +1 -0
- package/dist/services/MongoHistoryService.d.ts +37 -0
- package/dist/services/MongoHistoryService.d.ts.map +1 -0
- package/dist/services/MongoRealtimeService.d.ts +103 -0
- package/dist/services/MongoRealtimeService.d.ts.map +1 -0
- package/dist/websocket-DQlwCHFq.js +281 -0
- package/dist/websocket-DQlwCHFq.js.map +1 -0
- package/dist/websocket.d.ts +7 -0
- package/dist/websocket.d.ts.map +1 -0
- package/package.json +81 -0
- package/src/MongoBootstrapper.ts +196 -0
- package/src/auth/ensure-collections.ts +105 -0
- package/src/auth/services.ts +732 -0
- package/src/connection.ts +60 -0
- package/src/db/MongoConditionBuilder.ts +224 -0
- package/src/db/MongoDataService.ts +368 -0
- package/src/factory.ts +305 -0
- package/src/history/ensure-history-collection.ts +22 -0
- package/src/index.ts +25 -0
- package/src/services/MongoDriver.ts +1120 -0
- package/src/services/MongoHistoryService.ts +181 -0
- package/src/services/MongoRealtimeService.ts +446 -0
- package/src/websocket.ts +297 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { logger } from "@rebasepro/server";
|
|
2
|
+
//#region src/history/ensure-history-collection.ts
|
|
3
|
+
async function ensureHistoryCollectionExists(db) {
|
|
4
|
+
logger.info("🔍 Checking MongoDB history collection and indexes...");
|
|
5
|
+
try {
|
|
6
|
+
const history = db.collection("__rebase_history");
|
|
7
|
+
await history.createIndex({
|
|
8
|
+
entity_id: 1,
|
|
9
|
+
table_name: 1,
|
|
10
|
+
updated_at: -1
|
|
11
|
+
});
|
|
12
|
+
await history.createIndex({ updated_at: 1 });
|
|
13
|
+
logger.info("✅ MongoDB History collection ready");
|
|
14
|
+
} catch (error) {
|
|
15
|
+
logger.error("❌ Failed to set up MongoDB history collection", { error });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { ensureHistoryCollectionExists };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=ensure-history-collection-yajOt2dv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensure-history-collection-yajOt2dv.js","names":[],"sources":["../src/history/ensure-history-collection.ts"],"sourcesContent":["import { Db } from \"mongodb\";\nimport { logger } from \"@rebasepro/server\";\n\nexport async function ensureHistoryCollectionExists(db: Db): Promise<void> {\n logger.info(\"🔍 Checking MongoDB history collection and indexes...\");\n\n try {\n const history = db.collection(\"__rebase_history\");\n\n // Index for finding history entries for a specific row\n await history.createIndex({ entity_id: 1,\ntable_name: 1,\nupdated_at: -1 });\n\n // Index for pruning by date\n await history.createIndex({ updated_at: 1 });\n\n logger.info(\"✅ MongoDB History collection ready\");\n } catch (error) {\n logger.error(\"❌ Failed to set up MongoDB history collection\", { error: error });\n }\n}\n"],"mappings":";;AAGA,eAAsB,8BAA8B,IAAuB;CACvE,OAAO,KAAK,uDAAuD;CAEnE,IAAI;EACA,MAAM,UAAU,GAAG,WAAW,kBAAkB;EAGhD,MAAM,QAAQ,YAAY;GAAE,WAAW;GAC/C,YAAY;GACZ,YAAY;EAAG,CAAC;EAGR,MAAM,QAAQ,YAAY,EAAE,YAAY,EAAE,CAAC;EAE3C,OAAO,KAAK,oCAAoC;CACpD,SAAS,OAAO;EACZ,OAAO,MAAM,iDAAiD,EAAS,MAAM,CAAC;CAClF;AACJ"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MongoDB Backend Factory
|
|
3
|
+
*
|
|
4
|
+
* This module provides factory functions for creating MongoDB backend instances.
|
|
5
|
+
* It abstracts the creation of drivers, realtime services, and row services.
|
|
6
|
+
*/
|
|
7
|
+
import { Db, MongoClient } from "mongodb";
|
|
8
|
+
import { DataDriver, CollectionConfig } from "@rebasepro/types";
|
|
9
|
+
import { MongoDataService } from "./db/MongoDataService";
|
|
10
|
+
import { MongoRealtimeService } from "./services/MongoRealtimeService";
|
|
11
|
+
import { MongoDriver } from "./services/MongoDriver";
|
|
12
|
+
import { MongoHistoryService, HistoryRetentionConfig } from "./services/MongoHistoryService";
|
|
13
|
+
import { BackendConfig, BackendInstance, CollectionRegistryInterface, DataRepository, DatabaseAdmin } from "@rebasepro/types";
|
|
14
|
+
/**
|
|
15
|
+
* Configuration for creating a MongoDB backend.
|
|
16
|
+
*/
|
|
17
|
+
export interface MongoBackendConfig extends BackendConfig {
|
|
18
|
+
type: "mongodb";
|
|
19
|
+
/** MongoDB database instance */
|
|
20
|
+
connection: Db;
|
|
21
|
+
/** MongoDB client (for connection management) */
|
|
22
|
+
client: MongoClient;
|
|
23
|
+
/** Collections to register (optional, can be registered later) */
|
|
24
|
+
collections?: CollectionConfig[];
|
|
25
|
+
/** History retention configuration */
|
|
26
|
+
historyRetention?: Partial<HistoryRetentionConfig>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* MongoDB-specific backend instance with additional MongoDB types.
|
|
30
|
+
*/
|
|
31
|
+
export interface MongoBackendInstance extends BackendInstance {
|
|
32
|
+
/** The MongoDB database instance */
|
|
33
|
+
db: Db;
|
|
34
|
+
/** The MongoDB client */
|
|
35
|
+
client: MongoClient;
|
|
36
|
+
/** MongoDB DataDriver for use with Rebase */
|
|
37
|
+
driver: DataDriver;
|
|
38
|
+
/** Entity service for direct database operations */
|
|
39
|
+
dataService: MongoDataService;
|
|
40
|
+
/** Realtime service for subscriptions */
|
|
41
|
+
realtimeService: MongoRealtimeService;
|
|
42
|
+
/** Admin capabilities (DocumentAdmin + SchemaAdmin) */
|
|
43
|
+
admin: DatabaseAdmin;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Simple in-memory collection registry for MongoDB.
|
|
47
|
+
*/
|
|
48
|
+
export declare class MongoCollectionRegistry implements CollectionRegistryInterface {
|
|
49
|
+
private collections;
|
|
50
|
+
private _globalCallbacks?;
|
|
51
|
+
/**
|
|
52
|
+
* Register a collection
|
|
53
|
+
*/
|
|
54
|
+
register(collection: CollectionConfig): void;
|
|
55
|
+
/**
|
|
56
|
+
* Get a collection by its path
|
|
57
|
+
*/
|
|
58
|
+
getCollectionByPath(path: string): CollectionConfig | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Get all registered collections
|
|
61
|
+
*/
|
|
62
|
+
getCollections(): CollectionConfig[];
|
|
63
|
+
/**
|
|
64
|
+
* Get the currently registered global callbacks, if any.
|
|
65
|
+
*/
|
|
66
|
+
getGlobalCallbacks(): any | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Set global lifecycle callbacks that apply to every collection.
|
|
69
|
+
*/
|
|
70
|
+
setGlobalCallbacks(callbacks: any): void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create a complete MongoDB backend instance.
|
|
74
|
+
*
|
|
75
|
+
* This factory function creates all the necessary services for a MongoDB backend:
|
|
76
|
+
* - MongoDBConnection (database connection wrapper)
|
|
77
|
+
* - MongoDataService (implements DataRepository)
|
|
78
|
+
* - MongoRealtimeService (implements RealtimeProvider)
|
|
79
|
+
* - MongoCollectionRegistry (implements CollectionRegistryInterface)
|
|
80
|
+
* - MongoDriver (for Rebase integration)
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* import { createMongoBackend } from "@rebasepro/server-mongo";
|
|
85
|
+
*
|
|
86
|
+
* const client = new MongoClient("mongodb://localhost:27017");
|
|
87
|
+
* await client.connect();
|
|
88
|
+
* const db = client.db("my_database");
|
|
89
|
+
*
|
|
90
|
+
* const backend = createMongoBackend({
|
|
91
|
+
* type: "mongodb",
|
|
92
|
+
* connection: db,
|
|
93
|
+
* client: client,
|
|
94
|
+
* collections: myCollections
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* // Use the backend
|
|
98
|
+
* const rows = await backend.entityRepository.fetchCollection("users", {});
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function createMongoBackend(config: MongoBackendConfig): MongoBackendInstance;
|
|
102
|
+
/**
|
|
103
|
+
* Create a MongoDB DataDriver.
|
|
104
|
+
*
|
|
105
|
+
* This is a convenience function when you only need the DataDriver
|
|
106
|
+
* without the full backend instance.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* import { createMongoDelegate } from "@rebasepro/server-mongo";
|
|
111
|
+
*
|
|
112
|
+
* const delegate = createMongoDelegate(db);
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare function createMongoDelegate(db: Db, realtimeService?: MongoRealtimeService, historyService?: MongoHistoryService, registry?: CollectionRegistryInterface): MongoDriver;
|
|
116
|
+
/**
|
|
117
|
+
* Create a RealtimeService for MongoDB.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* import { createMongoRealtimeService } from "@rebasepro/server-mongo";
|
|
122
|
+
*
|
|
123
|
+
* const realtimeService = createMongoRealtimeService(db);
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare function createMongoRealtimeService(db: Db): MongoRealtimeService;
|
|
127
|
+
/**
|
|
128
|
+
* Create a MongoDB row repository.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* import { createMongoEntityRepository } from "@rebasepro/server-mongo";
|
|
133
|
+
*
|
|
134
|
+
* const repository = createMongoEntityRepository(db);
|
|
135
|
+
* const users = await repository.fetchCollection("users", {});
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export declare function createMongoEntityRepository(db: Db): DataRepository;
|
|
139
|
+
/**
|
|
140
|
+
* Check if a backend config is for MongoDB.
|
|
141
|
+
*/
|
|
142
|
+
export declare function isMongoBackendConfig(config: BackendConfig): config is MongoBackendConfig;
|
|
143
|
+
/**
|
|
144
|
+
* Check if a driver config is for MongoDB.
|
|
145
|
+
*/
|
|
146
|
+
export declare function isMongoDriverConfig(obj: unknown): obj is {
|
|
147
|
+
type: "mongodb";
|
|
148
|
+
connection: Db;
|
|
149
|
+
client: MongoClient;
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CA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S;IAI/D;;OAEG;IACH,cAAc,IAAI,gBAAgB,EAAE;IAIpC;;OAEG;IACH,kBAAkB,IAAI,GAAG,GAAG,SAAS;IAIrC;;OAEG;IACH,kBAAkB,CAAC,SAAS,EAAE,GAAG,GAAG,IAAI;CAG3C;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,oBAAoB,CAgGnF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAC/B,EAAE,EAAE,EAAE,EACN,eAAe,CAAC,EAAE,oBAAoB,EACtC,cAAc,CAAC,EAAE,mBAAmB,EACpC,QAAQ,CAAC,EAAE,2BAA2B,GACvC,WAAW,CAIb;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CAAC,EAAE,EAAE,EAAE,GAAG,oBAAoB,CAEvE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,EAAE,GAAG,cAAc,CAElE;AAMD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,IAAI,kBAAkB,CAIxF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,EAAE,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,CAOjH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensure-history-collection.d.ts","sourceRoot":"","sources":["../../src/history/ensure-history-collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAG7B,wBAAsB,6BAA6B,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBzE"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @rebasepro/server-mongo
|
|
3
|
+
*
|
|
4
|
+
* MongoDB backend implementation for Rebase
|
|
5
|
+
* This package provides a complete backend solution for Rebase applications
|
|
6
|
+
* using MongoDB as the database.
|
|
7
|
+
*
|
|
8
|
+
* The package implements the abstract interfaces from @rebasepro/server
|
|
9
|
+
* (DataRepository, RealtimeProvider, CollectionRegistryInterface, etc.)
|
|
10
|
+
*/
|
|
11
|
+
export * from "./connection";
|
|
12
|
+
export * from "./factory";
|
|
13
|
+
export * from "./db/MongoDataService";
|
|
14
|
+
export * from "./db/MongoConditionBuilder";
|
|
15
|
+
export * from "./services/MongoRealtimeService";
|
|
16
|
+
export * from "./services/MongoDriver";
|
|
17
|
+
export * from "./MongoBootstrapper";
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,cAAc,cAAc,CAAC;AAG7B,cAAc,WAAW,CAAC;AAG1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAG3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC"}
|