@aventoapp/framework 0.2.2 → 0.2.4
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/README.md +39 -2
- package/dist/server/index.js +1 -112
- package/dist/server/index.js.map +4 -4
- package/dist/server/mongo.js +109 -0
- package/dist/server/mongo.js.map +7 -0
- package/guard/no-framework-copy.js +471 -0
- package/moved.json +4 -0
- package/package.json +7 -8
- package/src/server/db/index.js +7 -7
- package/src/server/mongo.js +10 -0
package/README.md
CHANGED
|
@@ -8,12 +8,22 @@ npm i @aventoapp/framework
|
|
|
8
8
|
|
|
9
9
|
| Subpath | What it holds |
|
|
10
10
|
|---|---|
|
|
11
|
-
| `@aventoapp/framework/server` | Express middleware,
|
|
12
|
-
| `@aventoapp/framework/
|
|
11
|
+
| `@aventoapp/framework/server` | Express middleware, the Postgres client, workflow engine, services, and the server half of the offline kit (`applyFieldLWW`) |
|
|
12
|
+
| `@aventoapp/framework/server/mongo` | The MongoDB client (`MongoConnection`, `getMongoConnection`, `createMongoConnection`, `mongoose`). Install `mongoose` beside the framework to use it |
|
|
13
|
+
| `@aventoapp/framework/web` | React web modules. Install `@mui/material`, `@mui/icons-material`, `@emotion/react` and `@emotion/styled` beside the framework to use it |
|
|
13
14
|
| `@aventoapp/framework/shared` | Code shared by server and web |
|
|
14
15
|
| `@aventoapp/framework/offline` | The offline sync kit: read cache, write outbox, sync engine. No React, no DOM required |
|
|
15
16
|
| `@aventoapp/framework/native` | React Native modules |
|
|
16
17
|
|
|
18
|
+
Since 0.2.3 the framework does not install Mongoose, MUI or Emotion, and
|
|
19
|
+
`/server` does not load Mongoose: an app that never touches MongoDB or the
|
|
20
|
+
React web modules paid ~15 MB of heap and ~300 ms at boot, and 100+ MB of
|
|
21
|
+
packages, for them (bwoody77/vector#6334). They are not peer dependencies
|
|
22
|
+
either, optional or not: npm 11 still resolves an optional peer, so MUI's
|
|
23
|
+
Emotion would drag in React and break an install whose React does not match
|
|
24
|
+
this package's own `react` peer. An app that uses `/web` or `/server/mongo`
|
|
25
|
+
lists them in its own `package.json`.
|
|
26
|
+
|
|
17
27
|
## Offline sync kit
|
|
18
28
|
|
|
19
29
|
The kit lets a web or mobile client keep working with no signal. Reads come
|
|
@@ -279,3 +289,30 @@ If a tag push still starts no run, start it by hand on the tag:
|
|
|
279
289
|
A publish that fails with `OIDC token exchange error - package not found`
|
|
280
290
|
means the Trusted Publisher on npmjs.com does not match: user `bwoody77`,
|
|
281
291
|
repository `avento`, workflow `publish-framework.yml`, environment blank.
|
|
292
|
+
|
|
293
|
+
Then move every consumer onto the release (vector#6359). In 0.x a caret range
|
|
294
|
+
already admits later patches, so only the lockfile decides what installs:
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
# from the avento repo root, once the Publish framework run is green;
|
|
298
|
+
# each dir is a task-branch worktree of that repo
|
|
299
|
+
node scripts/bump-consumers.mjs --vector <dir> --avento-apps <dir> --cf <dir>
|
|
300
|
+
node scripts/bump-consumers.mjs --check # exits 0 once every main is on it
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
It stops, changing nothing, until npm has the version, raises each range to
|
|
304
|
+
`^X` and runs `npm install --package-lock-only`. It pushes nothing. Land Vector
|
|
305
|
+
through its merge train, then avento-apps, then cf.
|
|
306
|
+
|
|
307
|
+
## Moved modules stay moved
|
|
308
|
+
|
|
309
|
+
`moved.json` lists each module moved into the framework from Vector or
|
|
310
|
+
avento-apps: its `name`, `export`, `package` (the subpath that exports it),
|
|
311
|
+
`date`, `oldPaths` per app, and `sweep` when a one-line re-export is left at an
|
|
312
|
+
old path for a while. `@aventoapp/framework/guard` (`guard/no-framework-copy.js`)
|
|
313
|
+
is the check both apps run in their gates: it fails when an old path comes
|
|
314
|
+
back with code of its own, or when a body matching the export (comments and
|
|
315
|
+
whitespace aside) appears anywhere else in the app. The only thing an old path
|
|
316
|
+
may hold is `export { name } from '<package>';` with a comment naming its
|
|
317
|
+
sweep. A fix to a moved module is made here, published, and bumped into the
|
|
318
|
+
apps.
|
package/dist/server/index.js
CHANGED
|
@@ -1126,13 +1126,9 @@ function requireEntityRoleOr(entityType, getEntityId, ...globalRoles) {
|
|
|
1126
1126
|
// src/server/db/index.js
|
|
1127
1127
|
var db_exports = {};
|
|
1128
1128
|
__export(db_exports, {
|
|
1129
|
-
MongoConnection: () => MongoConnection,
|
|
1130
1129
|
PostgresConnection: () => PostgresConnection,
|
|
1131
|
-
createMongoConnection: () => createMongoConnection,
|
|
1132
1130
|
createPostgresConnection: () => createPostgresConnection,
|
|
1133
|
-
|
|
1134
|
-
getPostgresConnection: () => getPostgresConnection,
|
|
1135
|
-
mongoose: () => mongoose
|
|
1131
|
+
getPostgresConnection: () => getPostgresConnection
|
|
1136
1132
|
});
|
|
1137
1133
|
|
|
1138
1134
|
// src/server/db/postgres.js
|
|
@@ -1248,109 +1244,6 @@ function createPostgresConnection(config) {
|
|
|
1248
1244
|
return new PostgresConnection(config);
|
|
1249
1245
|
}
|
|
1250
1246
|
|
|
1251
|
-
// src/server/db/mongo.js
|
|
1252
|
-
import mongoose from "mongoose";
|
|
1253
|
-
var MongoConnection = class {
|
|
1254
|
-
constructor(config = {}) {
|
|
1255
|
-
this.config = {
|
|
1256
|
-
host: config.host || process.env.MONGO_HOST || "localhost",
|
|
1257
|
-
port: config.port || process.env.MONGO_PORT || 27017,
|
|
1258
|
-
database: config.database || process.env.MONGO_DB || "avento",
|
|
1259
|
-
user: config.user || process.env.MONGO_USER || "",
|
|
1260
|
-
password: config.password || process.env.MONGO_PASSWORD || "",
|
|
1261
|
-
options: config.options || {}
|
|
1262
|
-
};
|
|
1263
|
-
this.connection = null;
|
|
1264
|
-
}
|
|
1265
|
-
/**
|
|
1266
|
-
* Build MongoDB connection URI
|
|
1267
|
-
*/
|
|
1268
|
-
_buildUri() {
|
|
1269
|
-
const { host, port, database, user, password } = this.config;
|
|
1270
|
-
if (user && password) {
|
|
1271
|
-
return `mongodb://${encodeURIComponent(user)}:${encodeURIComponent(password)}@${host}:${port}/${database}`;
|
|
1272
|
-
}
|
|
1273
|
-
return `mongodb://${host}:${port}/${database}`;
|
|
1274
|
-
}
|
|
1275
|
-
/**
|
|
1276
|
-
* Connect to MongoDB
|
|
1277
|
-
*/
|
|
1278
|
-
async connect() {
|
|
1279
|
-
if (this.connection && this.connection.readyState === 1) {
|
|
1280
|
-
return this.connection;
|
|
1281
|
-
}
|
|
1282
|
-
const uri = this.config.uri || this._buildUri();
|
|
1283
|
-
const options = {
|
|
1284
|
-
maxPoolSize: 10,
|
|
1285
|
-
serverSelectionTimeoutMS: 5e3,
|
|
1286
|
-
socketTimeoutMS: 45e3,
|
|
1287
|
-
...this.config.options
|
|
1288
|
-
};
|
|
1289
|
-
try {
|
|
1290
|
-
this.connection = await mongoose.connect(uri, options);
|
|
1291
|
-
console.log(`[MongoDB] Connected to ${this.config.host}:${this.config.port}/${this.config.database}`);
|
|
1292
|
-
mongoose.connection.on("error", (err) => {
|
|
1293
|
-
console.error("[MongoDB] Connection error:", err);
|
|
1294
|
-
});
|
|
1295
|
-
mongoose.connection.on("disconnected", () => {
|
|
1296
|
-
console.log("[MongoDB] Disconnected");
|
|
1297
|
-
});
|
|
1298
|
-
return this.connection;
|
|
1299
|
-
} catch (err) {
|
|
1300
|
-
console.error("[MongoDB] Connection failed:", err.message);
|
|
1301
|
-
throw err;
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
/**
|
|
1305
|
-
* Get the Mongoose connection
|
|
1306
|
-
*/
|
|
1307
|
-
getConnection() {
|
|
1308
|
-
return mongoose.connection;
|
|
1309
|
-
}
|
|
1310
|
-
/**
|
|
1311
|
-
* Get or create a model (with tenant scoping support)
|
|
1312
|
-
* @param {string} name - Model name
|
|
1313
|
-
* @param {Object} schema - Mongoose schema definition
|
|
1314
|
-
* @param {Object} options - Schema options
|
|
1315
|
-
*/
|
|
1316
|
-
createModel(name, schemaDefinition, options = {}) {
|
|
1317
|
-
const tenantedSchema = {
|
|
1318
|
-
tenant_id: {
|
|
1319
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
1320
|
-
required: true,
|
|
1321
|
-
index: true
|
|
1322
|
-
},
|
|
1323
|
-
...schemaDefinition
|
|
1324
|
-
};
|
|
1325
|
-
const schema = new mongoose.Schema(tenantedSchema, {
|
|
1326
|
-
timestamps: { createdAt: "created_at", updatedAt: "updated_at" },
|
|
1327
|
-
...options
|
|
1328
|
-
});
|
|
1329
|
-
schema.index({ tenant_id: 1, created_at: -1 });
|
|
1330
|
-
return mongoose.model(name, schema);
|
|
1331
|
-
}
|
|
1332
|
-
/**
|
|
1333
|
-
* Disconnect from MongoDB
|
|
1334
|
-
*/
|
|
1335
|
-
async disconnect() {
|
|
1336
|
-
if (mongoose.connection.readyState !== 0) {
|
|
1337
|
-
await mongoose.disconnect();
|
|
1338
|
-
this.connection = null;
|
|
1339
|
-
console.log("[MongoDB] Disconnected");
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
};
|
|
1343
|
-
var defaultConnection2 = null;
|
|
1344
|
-
function getMongoConnection(config) {
|
|
1345
|
-
if (!defaultConnection2) {
|
|
1346
|
-
defaultConnection2 = new MongoConnection(config);
|
|
1347
|
-
}
|
|
1348
|
-
return defaultConnection2;
|
|
1349
|
-
}
|
|
1350
|
-
function createMongoConnection(config) {
|
|
1351
|
-
return new MongoConnection(config);
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
1247
|
// src/server/utils/index.js
|
|
1355
1248
|
var utils_exports = {};
|
|
1356
1249
|
__export(utils_exports, {
|
|
@@ -2830,7 +2723,6 @@ export {
|
|
|
2830
2723
|
EmailService,
|
|
2831
2724
|
EventBus,
|
|
2832
2725
|
MemoryCache,
|
|
2833
|
-
MongoConnection,
|
|
2834
2726
|
PostgresConnection,
|
|
2835
2727
|
QueryBuilder,
|
|
2836
2728
|
SmtpEmailService,
|
|
@@ -2851,7 +2743,6 @@ export {
|
|
|
2851
2743
|
createEmailService,
|
|
2852
2744
|
createForgotPasswordHandler,
|
|
2853
2745
|
createLoginHandler,
|
|
2854
|
-
createMongoConnection,
|
|
2855
2746
|
createPermissionChecker,
|
|
2856
2747
|
createPostgresConnection,
|
|
2857
2748
|
createQueryBuilder,
|
|
@@ -2874,7 +2765,6 @@ export {
|
|
|
2874
2765
|
generateToken,
|
|
2875
2766
|
generateTokenExpiry,
|
|
2876
2767
|
getCache,
|
|
2877
|
-
getMongoConnection,
|
|
2878
2768
|
getPostgresConnection,
|
|
2879
2769
|
getSqlPagination,
|
|
2880
2770
|
getTenantId,
|
|
@@ -2887,7 +2777,6 @@ export {
|
|
|
2887
2777
|
initAuth,
|
|
2888
2778
|
isValidUUID,
|
|
2889
2779
|
middleware_exports as middleware,
|
|
2890
|
-
mongoose,
|
|
2891
2780
|
mountGeneratedRoutes,
|
|
2892
2781
|
offline_exports as offline,
|
|
2893
2782
|
optionalAuth,
|