@warlock.js/cascade 5.19.1 → 5.20.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.
- package/CHANGELOG.md +6 -0
- package/cjs/index.cjs +78 -7
- package/cjs/index.cjs.map +1 -1
- package/esm/context/database-transaction-context.d.mts +10 -0
- package/esm/context/database-transaction-context.d.mts.map +1 -1
- package/esm/context/database-transaction-context.mjs +17 -0
- package/esm/context/database-transaction-context.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-driver.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-driver.mjs +13 -5
- package/esm/drivers/mongodb/mongodb-driver.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-driver.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-driver.mjs +8 -3
- package/esm/drivers/postgres/postgres-driver.mjs.map +1 -1
- package/esm/index.d.mts +2 -1
- package/esm/index.mjs +2 -1
- package/esm/migration/migration-runner.mjs +1 -1
- package/esm/transactions/after-commit.d.mts +24 -0
- package/esm/transactions/after-commit.d.mts.map +1 -0
- package/esm/transactions/after-commit.mjs +47 -0
- package/esm/transactions/after-commit.mjs.map +1 -0
- package/llms-full.txt +2783 -2766
- package/llms.txt +15 -15
- package/package.json +6 -6
- package/skills/aggregate-data/SKILL.md +165 -165
- package/skills/alter-migration/SKILL.md +531 -531
- package/skills/configure-delete-strategy/SKILL.md +130 -130
- package/skills/define-model/SKILL.md +205 -205
- package/skills/define-relations/SKILL.md +171 -171
- package/skills/index.md +23 -0
- package/skills/manage-data-sources/SKILL.md +140 -140
- package/skills/manage-transactions/SKILL.md +208 -191
- package/skills/paginate-results/SKILL.md +122 -122
- package/skills/perform-atomic-ops/SKILL.md +156 -156
- package/skills/query-data/SKILL.md +213 -213
- package/skills/run-cascade-cli/SKILL.md +125 -125
- package/skills/search-by-vector/SKILL.md +127 -127
- package/skills/subscribe-to-model-events/SKILL.md +148 -148
- package/skills/track-changes/SKILL.md +127 -127
- package/skills/write-migration/SKILL.md +206 -206
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { databaseTransactionContext } from "../context/database-transaction-context.mjs";
|
|
2
|
+
import { log } from "@warlock.js/logger";
|
|
3
|
+
|
|
4
|
+
//#region ../cascade/src/transactions/after-commit.ts
|
|
5
|
+
function reportFailure(error) {
|
|
6
|
+
log.error("database", "afterCommit", `[cascade] afterCommit callback failed: ${error}`);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Run a callback only once the current transaction has COMMITTED.
|
|
10
|
+
*
|
|
11
|
+
* Model events (`saved`, `created`, `updated`, `deleted`) fire INSIDE the
|
|
12
|
+
* transaction, before COMMIT. Anything that must observe committed data
|
|
13
|
+
* (cache invalidation, sitemap regeneration, webhooks) belongs here.
|
|
14
|
+
*
|
|
15
|
+
* - Inside a transaction: queued, run after the outermost COMMIT, in order,
|
|
16
|
+
* awaited one by one. Discarded on rollback or a failed COMMIT.
|
|
17
|
+
* - Outside a transaction: run on the next microtask (not awaited by the caller).
|
|
18
|
+
* - A callback that throws is logged; it never affects the transaction result
|
|
19
|
+
* or the remaining callbacks.
|
|
20
|
+
* - Callbacks run after the transaction context has exited, so any DB work
|
|
21
|
+
* they do is outside the finished transaction.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* Product.events().onSaved(() => afterCommit(() => regenerateSitemap()));
|
|
25
|
+
*/
|
|
26
|
+
function afterCommit(fn) {
|
|
27
|
+
if (databaseTransactionContext.hasActiveTransaction()) {
|
|
28
|
+
databaseTransactionContext.addAfterCommit(fn);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
Promise.resolve().then(fn).catch(reportFailure);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Run committed callbacks sequentially. Never throws.
|
|
35
|
+
* Drivers call this after a successful COMMIT and after the context exited.
|
|
36
|
+
*/
|
|
37
|
+
async function flushAfterCommit(callbacks) {
|
|
38
|
+
for (const callback of callbacks) try {
|
|
39
|
+
await callback();
|
|
40
|
+
} catch (error) {
|
|
41
|
+
reportFailure(error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { afterCommit, flushAfterCommit };
|
|
47
|
+
//# sourceMappingURL=after-commit.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"after-commit.mjs","names":[],"sources":["../../../../../../../cascade/src/transactions/after-commit.ts"],"sourcesContent":["import { log } from \"@warlock.js/logger\";\nimport { databaseTransactionContext } from \"../context/database-transaction-context\";\n\ntype AfterCommitCallback = () => void | Promise<void>;\n\nfunction reportFailure(error: unknown): void {\n log.error(\"database\", \"afterCommit\", `[cascade] afterCommit callback failed: ${error}`);\n}\n\n/**\n * Run a callback only once the current transaction has COMMITTED.\n *\n * Model events (`saved`, `created`, `updated`, `deleted`) fire INSIDE the\n * transaction, before COMMIT. Anything that must observe committed data\n * (cache invalidation, sitemap regeneration, webhooks) belongs here.\n *\n * - Inside a transaction: queued, run after the outermost COMMIT, in order,\n * awaited one by one. Discarded on rollback or a failed COMMIT.\n * - Outside a transaction: run on the next microtask (not awaited by the caller).\n * - A callback that throws is logged; it never affects the transaction result\n * or the remaining callbacks.\n * - Callbacks run after the transaction context has exited, so any DB work\n * they do is outside the finished transaction.\n *\n * @example\n * Product.events().onSaved(() => afterCommit(() => regenerateSitemap()));\n */\nexport function afterCommit(fn: AfterCommitCallback): void {\n if (databaseTransactionContext.hasActiveTransaction()) {\n databaseTransactionContext.addAfterCommit(fn);\n return;\n }\n\n Promise.resolve().then(fn).catch(reportFailure);\n}\n\n/**\n * Run committed callbacks sequentially. Never throws.\n * Drivers call this after a successful COMMIT and after the context exited.\n */\nexport async function flushAfterCommit(callbacks: AfterCommitCallback[]): Promise<void> {\n for (const callback of callbacks) {\n try {\n await callback();\n } catch (error) {\n reportFailure(error);\n }\n }\n}\n"],"mappings":";;;;AAKA,SAAS,cAAc,OAAsB;CAC3C,IAAI,MAAM,YAAY,eAAe,0CAA0C,OAAO;AACxF;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,YAAY,IAA+B;CACzD,IAAI,2BAA2B,qBAAqB,GAAG;EACrD,2BAA2B,eAAe,EAAE;EAC5C;CACF;CAEA,QAAQ,QAAQ,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,aAAa;AAChD;;;;;AAMA,eAAsB,iBAAiB,WAAiD;CACtF,KAAK,MAAM,YAAY,WACrB,IAAI;EACF,MAAM,SAAS;CACjB,SAAS,OAAO;EACd,cAAc,KAAK;CACrB;AAEJ"}
|