@rebasepro/server-mongo 0.17.3 → 0.18.1
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 +0 -1
- package/README.md +4 -0
- package/dist/MongoBootstrapper.d.ts +0 -1
- package/dist/auth/ensure-collections.d.ts +0 -1
- package/dist/auth/services.d.ts +0 -1
- package/dist/connection.d.ts +0 -1
- package/dist/db/MongoConditionBuilder.d.ts +0 -1
- package/dist/db/MongoDataService.d.ts +0 -1
- package/dist/db/securityRuleFilter.d.ts +0 -1
- package/dist/factory.d.ts +0 -1
- package/dist/history/ensure-history-collection.d.ts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.es.js +83 -79
- package/dist/index.es.js.map +1 -1
- package/dist/schema/plan-schema-change.d.ts +0 -1
- package/dist/services/MongoDriver.d.ts +0 -1
- package/dist/services/MongoHistoryService.d.ts +0 -1
- package/dist/services/MongoRealtimeService.d.ts +0 -1
- package/dist/websocket.d.ts +0 -1
- package/package.json +28 -24
- package/dist/MongoBootstrapper.d.ts.map +0 -1
- package/dist/auth/ensure-collections.d.ts.map +0 -1
- package/dist/auth/services.d.ts.map +0 -1
- package/dist/connection.d.ts.map +0 -1
- package/dist/db/MongoConditionBuilder.d.ts.map +0 -1
- package/dist/db/MongoDataService.d.ts.map +0 -1
- package/dist/db/securityRuleFilter.d.ts.map +0 -1
- package/dist/factory.d.ts.map +0 -1
- package/dist/history/ensure-history-collection.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/schema/plan-schema-change.d.ts.map +0 -1
- package/dist/services/MongoDriver.d.ts.map +0 -1
- package/dist/services/MongoHistoryService.d.ts.map +0 -1
- package/dist/services/MongoRealtimeService.d.ts.map +0 -1
- package/dist/websocket.d.ts.map +0 -1
- package/src/MongoBootstrapper.ts +0 -204
- package/src/auth/ensure-collections.ts +0 -153
- package/src/auth/services.ts +0 -866
- package/src/connection.ts +0 -60
- package/src/db/MongoConditionBuilder.ts +0 -348
- package/src/db/MongoDataService.ts +0 -412
- package/src/db/securityRuleFilter.ts +0 -398
- package/src/factory.ts +0 -331
- package/src/history/ensure-history-collection.ts +0 -22
- package/src/index.ts +0 -25
- package/src/schema/plan-schema-change.ts +0 -159
- package/src/services/MongoDriver.ts +0 -950
- package/src/services/MongoHistoryService.ts +0 -186
- package/src/services/MongoRealtimeService.ts +0 -592
- package/src/websocket.ts +0 -387
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -8,6 +8,10 @@ MongoDB database driver for Rebase.
|
|
|
8
8
|
pnpm add @rebasepro/server-mongo
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
ESM-only: `"type": "module"` with no CommonJS build, so it is loaded with
|
|
12
|
+
`import`. `require()` of it resolves only on Node 22.12+, which supports
|
|
13
|
+
`require(esm)`.
|
|
14
|
+
|
|
11
15
|
## What This Package Does
|
|
12
16
|
|
|
13
17
|
Implements the Rebase `BackendBootstrapper` and backend interfaces for MongoDB. Provides a complete data driver, change-stream-based realtime, snapshot history, auth repositories, and WebSocket support. Plug it into `@rebasepro/server` via `createMongoBootstrapper()`, or use the standalone `createMongoBackend()` factory for direct access.
|
package/dist/auth/services.d.ts
CHANGED
package/dist/connection.d.ts
CHANGED
|
@@ -62,4 +62,3 @@ export declare function assertSecurityRulesEnforceable(collection: CollectionCon
|
|
|
62
62
|
*/
|
|
63
63
|
export declare function buildMongoFilterFromSecurityRules<M extends Record<string, any>>(collection: CollectionConfig<M> | undefined, user: User | undefined, targetOperation: SecurityOperation): Filter<Document> | null;
|
|
64
64
|
export {};
|
|
65
|
-
//# sourceMappingURL=securityRuleFilter.d.ts.map
|
package/dist/factory.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MongoClient, ObjectId } from "mongodb";
|
|
2
2
|
import { ANONYMOUS_USER_ID, EntityReference, ListLimitError, getCollectionDataPath, isAnonymousUid, resolveClientListLimit } from "@rebasepro/types";
|
|
3
|
-
import { buildPropertyCallbacks, buildSdkData, checkOperation, normalizeDriverOrderBy, normalizeEmail, securityRuleToConditions, toFilterTuples, updateDateAutoValues } from "@rebasepro/common";
|
|
3
|
+
import { buildPropertyCallbacks, buildSdkData, callbackRefusal, checkOperation, normalizeDriverOrderBy, normalizeEmail, securityRuleToConditions, toCallbackError, toFilterTuples, updateDateAutoValues } from "@rebasepro/common";
|
|
4
4
|
import { ApiError, logger } from "@rebasepro/server";
|
|
5
5
|
import { mergeDeep } from "@rebasepro/utils";
|
|
6
6
|
//#region \0rolldown/runtime.js
|
|
@@ -1039,7 +1039,8 @@ function referencesField(expr) {
|
|
|
1039
1039
|
function userContext(user) {
|
|
1040
1040
|
return {
|
|
1041
1041
|
uid: user?.uid || ANONYMOUS_USER_ID,
|
|
1042
|
-
roles: user?.roles ?? []
|
|
1042
|
+
roles: user?.roles ?? [],
|
|
1043
|
+
isAnonymous: user?.isAnonymous === true
|
|
1043
1044
|
};
|
|
1044
1045
|
}
|
|
1045
1046
|
var COMPARE_TO_MONGO = {
|
|
@@ -1129,6 +1130,7 @@ function policyToMongoFilter(expr, user) {
|
|
|
1129
1130
|
case "rolesOverlap": return expr.roles.some((r) => r === "public" || ctx.roles.includes(r)) ? MATCH_ALL : MATCH_NONE;
|
|
1130
1131
|
case "rolesContain": return expr.roles.every((r) => r === "public" || ctx.roles.includes(r)) ? MATCH_ALL : MATCH_NONE;
|
|
1131
1132
|
case "authenticated": return !isAnonymousUid(ctx.uid) ? MATCH_ALL : MATCH_NONE;
|
|
1133
|
+
case "registered": return !isAnonymousUid(ctx.uid) && ctx.isAnonymous !== true ? MATCH_ALL : MATCH_NONE;
|
|
1132
1134
|
case "serverContext": return MATCH_NONE;
|
|
1133
1135
|
case "existsIn":
|
|
1134
1136
|
case "raw": return UNTRANSLATABLE;
|
|
@@ -1430,43 +1432,47 @@ var MongoDriver = class {
|
|
|
1430
1432
|
previousValuesForHistory = existingValues;
|
|
1431
1433
|
}
|
|
1432
1434
|
}
|
|
1433
|
-
|
|
1434
|
-
if (globalCallbacks?.beforeSave) {
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1435
|
+
try {
|
|
1436
|
+
if (globalCallbacks?.beforeSave || callbacks?.beforeSave || propertyCallbacks?.beforeSave) {
|
|
1437
|
+
if (globalCallbacks?.beforeSave) {
|
|
1438
|
+
const result = await globalCallbacks.beforeSave({
|
|
1439
|
+
collection: resolvedCollection,
|
|
1440
|
+
path,
|
|
1441
|
+
id,
|
|
1442
|
+
values: updatedValues,
|
|
1443
|
+
previousValues: previousValuesForHistory,
|
|
1444
|
+
status,
|
|
1445
|
+
context: contextForCallback
|
|
1446
|
+
});
|
|
1447
|
+
if (result) updatedValues = mergeDeep(updatedValues, result);
|
|
1448
|
+
}
|
|
1449
|
+
if (callbacks?.beforeSave) {
|
|
1450
|
+
const result = await callbacks.beforeSave({
|
|
1451
|
+
collection: resolvedCollection,
|
|
1452
|
+
path,
|
|
1453
|
+
id,
|
|
1454
|
+
values: updatedValues,
|
|
1455
|
+
previousValues: previousValuesForHistory,
|
|
1456
|
+
status,
|
|
1457
|
+
context: contextForCallback
|
|
1458
|
+
});
|
|
1459
|
+
if (result) updatedValues = mergeDeep(updatedValues, result);
|
|
1460
|
+
}
|
|
1461
|
+
if (propertyCallbacks?.beforeSave) {
|
|
1462
|
+
const result = await propertyCallbacks.beforeSave({
|
|
1463
|
+
collection: resolvedCollection,
|
|
1464
|
+
path,
|
|
1465
|
+
id,
|
|
1466
|
+
values: updatedValues,
|
|
1467
|
+
previousValues: previousValuesForHistory,
|
|
1468
|
+
status,
|
|
1469
|
+
context: contextForCallback
|
|
1470
|
+
});
|
|
1471
|
+
if (result) updatedValues = mergeDeep(updatedValues, result);
|
|
1472
|
+
}
|
|
1469
1473
|
}
|
|
1474
|
+
} catch (callbackError) {
|
|
1475
|
+
throw toCallbackError(callbackError, "beforeSave", path);
|
|
1470
1476
|
}
|
|
1471
1477
|
if (resolvedCollection?.properties) updatedValues = updateDateAutoValues({
|
|
1472
1478
|
inputValues: updatedValues,
|
|
@@ -1541,24 +1547,18 @@ var MongoDriver = class {
|
|
|
1541
1547
|
return savedRow;
|
|
1542
1548
|
} catch (error) {
|
|
1543
1549
|
if (callbacks?.afterSaveError || propertyCallbacks?.afterSaveError) {
|
|
1544
|
-
|
|
1550
|
+
const errorProps = {
|
|
1545
1551
|
collection: resolvedCollection,
|
|
1546
1552
|
path,
|
|
1547
|
-
id
|
|
1548
|
-
values: updatedValues,
|
|
1549
|
-
previousValues: void 0,
|
|
1550
|
-
status,
|
|
1551
|
-
context: contextForCallback
|
|
1552
|
-
});
|
|
1553
|
-
if (propertyCallbacks?.afterSaveError) await propertyCallbacks.afterSaveError({
|
|
1554
|
-
collection: resolvedCollection,
|
|
1555
|
-
path,
|
|
1556
|
-
id: id || "unknown",
|
|
1553
|
+
id,
|
|
1557
1554
|
values: updatedValues,
|
|
1558
1555
|
previousValues: void 0,
|
|
1559
1556
|
status,
|
|
1557
|
+
error,
|
|
1560
1558
|
context: contextForCallback
|
|
1561
|
-
}
|
|
1559
|
+
};
|
|
1560
|
+
if (callbacks?.afterSaveError) await callbacks.afterSaveError(errorProps);
|
|
1561
|
+
if (propertyCallbacks?.afterSaveError) await propertyCallbacks.afterSaveError(errorProps);
|
|
1562
1562
|
}
|
|
1563
1563
|
throw error;
|
|
1564
1564
|
}
|
|
@@ -1579,36 +1579,40 @@ var MongoDriver = class {
|
|
|
1579
1579
|
client: this.client,
|
|
1580
1580
|
storageSource: this.client?.storage
|
|
1581
1581
|
};
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
if (
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
if (
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
if (
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1582
|
+
try {
|
|
1583
|
+
if (globalCallbacks?.beforeDelete || callbacks?.beforeDelete || propertyCallbacks?.beforeDelete) {
|
|
1584
|
+
let preventDefault = false;
|
|
1585
|
+
if (globalCallbacks?.beforeDelete) {
|
|
1586
|
+
if (await globalCallbacks.beforeDelete({
|
|
1587
|
+
collection: resolvedCollection,
|
|
1588
|
+
path: row.path,
|
|
1589
|
+
id: row.id,
|
|
1590
|
+
row: callbackRow,
|
|
1591
|
+
context: contextForCallback
|
|
1592
|
+
}) === false) preventDefault = true;
|
|
1593
|
+
}
|
|
1594
|
+
if (callbacks?.beforeDelete) {
|
|
1595
|
+
if (await callbacks.beforeDelete({
|
|
1596
|
+
collection: resolvedCollection,
|
|
1597
|
+
path: row.path,
|
|
1598
|
+
id: row.id,
|
|
1599
|
+
row: callbackRow,
|
|
1600
|
+
context: contextForCallback
|
|
1601
|
+
}) === false) preventDefault = true;
|
|
1602
|
+
}
|
|
1603
|
+
if (propertyCallbacks?.beforeDelete) {
|
|
1604
|
+
if (await propertyCallbacks.beforeDelete({
|
|
1605
|
+
collection: resolvedCollection,
|
|
1606
|
+
path: row.path,
|
|
1607
|
+
id: row.id,
|
|
1608
|
+
row: callbackRow,
|
|
1609
|
+
context: contextForCallback
|
|
1610
|
+
}) === false) preventDefault = true;
|
|
1611
|
+
}
|
|
1612
|
+
if (preventDefault) throw callbackRefusal("beforeDelete", row.path);
|
|
1610
1613
|
}
|
|
1611
|
-
|
|
1614
|
+
} catch (callbackError) {
|
|
1615
|
+
throw toCallbackError(callbackError, "beforeDelete", row.path);
|
|
1612
1616
|
}
|
|
1613
1617
|
await this.dataService.delete(row.path, row.id);
|
|
1614
1618
|
if (globalCallbacks?.afterDelete || callbacks?.afterDelete || propertyCallbacks?.afterDelete) {
|