@easy-cms/drizzle 1.11.0 → 1.13.0

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.
Files changed (2) hide show
  1. package/dist/index.js +25 -9
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1271,12 +1271,20 @@ var DrizzleDatabase = class {
1271
1271
  });
1272
1272
  return result;
1273
1273
  }
1274
+ outbox = true;
1275
+ /** Writes the `outbox` row of a write, in its transaction. */
1276
+ async writeOutbox(tx, outbox, id) {
1277
+ if (!outbox) return;
1278
+ await insertDocument(tx, this.model(outbox.collection).root, outbox.data(id), false);
1279
+ }
1274
1280
  async create(args) {
1275
1281
  const model = this.model(args.collection);
1276
1282
  const id = await this.write(
1277
- () => this.db.transaction(
1278
- (tx) => insertDocument(tx, model.root, args.data, model.config.drafts === true)
1279
- )
1283
+ () => this.db.transaction(async (tx) => {
1284
+ const id2 = await insertDocument(tx, model.root, args.data, model.config.drafts === true);
1285
+ await this.writeOutbox(tx, args.outbox, id2);
1286
+ return id2;
1287
+ })
1280
1288
  );
1281
1289
  return await this.findById({ collection: args.collection, id });
1282
1290
  }
@@ -1284,16 +1292,18 @@ var DrizzleDatabase = class {
1284
1292
  const model = this.model(args.collection);
1285
1293
  const condition = args.where ? this.where(args.collection, args.where) : void 0;
1286
1294
  const written = await this.write(
1287
- () => this.db.transaction(
1288
- (tx) => replaceDocument(
1295
+ () => this.db.transaction(async (tx) => {
1296
+ const written2 = await replaceDocument(
1289
1297
  tx,
1290
1298
  model.root,
1291
1299
  args.id,
1292
1300
  args.data,
1293
1301
  model.config.drafts === true,
1294
1302
  condition
1295
- )
1296
- )
1303
+ );
1304
+ if (written2) await this.writeOutbox(tx, args.outbox, args.id);
1305
+ return written2;
1306
+ })
1297
1307
  );
1298
1308
  if (!written) return null;
1299
1309
  return await this.findById({ collection: args.collection, id: args.id });
@@ -1322,7 +1332,10 @@ var DrizzleDatabase = class {
1322
1332
  async delete(args) {
1323
1333
  const model = this.model(args.collection);
1324
1334
  await this.write(
1325
- () => this.db.transaction((tx) => deleteDocument(tx, model.root, args.id))
1335
+ () => this.db.transaction(async (tx) => {
1336
+ await deleteDocument(tx, model.root, args.id);
1337
+ await this.writeOutbox(tx, args.outbox, args.id);
1338
+ })
1326
1339
  );
1327
1340
  }
1328
1341
  async findGlobal(args) {
@@ -1345,7 +1358,10 @@ var DrizzleDatabase = class {
1345
1358
  updated_at: updatedAt
1346
1359
  };
1347
1360
  await this.write(
1348
- () => this.db.insert(table).values(values).onConflictDoUpdate({ target: table.slug, set: values })
1361
+ () => this.db.transaction(async (tx) => {
1362
+ await tx.insert(table).values(values).onConflictDoUpdate({ target: table.slug, set: values });
1363
+ await this.writeOutbox(tx, args.outbox, null);
1364
+ })
1349
1365
  );
1350
1366
  return await this.findGlobal({ slug: args.slug });
1351
1367
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/drizzle",
3
- "version": "1.11.0",
3
+ "version": "1.13.0",
4
4
  "description": "Shared Drizzle ORM layer for Easy CMS database adapters",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -23,10 +23,10 @@
23
23
  "drizzle-orm": "0.45.4"
24
24
  },
25
25
  "peerDependencies": {
26
- "@easy-cms/core": "^1.11.0"
26
+ "@easy-cms/core": "^1.13.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@easy-cms/core": "^1.11.0"
29
+ "@easy-cms/core": "^1.13.0"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"