@porulle/core 0.34.0 → 0.35.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/dist/kernel/database/adapter.d.ts.map +1 -1
- package/dist/kernel/database/adapter.js +23 -1
- package/dist/kernel/hooks/deferred.d.ts +4 -0
- package/dist/kernel/hooks/deferred.d.ts.map +1 -0
- package/dist/kernel/hooks/deferred.js +44 -0
- package/dist/kernel/hooks/executor.d.ts +1 -1
- package/dist/kernel/hooks/executor.d.ts.map +1 -1
- package/dist/kernel/hooks/executor.js +50 -16
- package/dist/kernel/hooks/registry.d.ts +8 -0
- package/dist/kernel/hooks/registry.d.ts.map +1 -1
- package/dist/kernel/hooks/registry.js +34 -0
- package/dist/kernel/plugin/manifest.d.ts +9 -0
- package/dist/kernel/plugin/manifest.d.ts.map +1 -1
- package/dist/kernel/plugin/manifest.js +5 -0
- package/dist/modules/catalog/entity-service.js +7 -7
- package/dist/modules/customers/service.js +4 -4
- package/dist/modules/fulfillment/service.js +2 -2
- package/dist/modules/inventory/service.d.ts.map +1 -1
- package/dist/modules/inventory/service.js +1 -1
- package/dist/modules/orders/service.d.ts.map +1 -1
- package/dist/modules/orders/service.js +3 -3
- package/dist/modules/promotions/service.js +3 -3
- package/dist/runtime/kernel-register-hooks.js +1 -1
- package/dist/runtime/kernel.d.ts.map +1 -1
- package/dist/runtime/kernel.js +10 -2
- package/dist/test-utils/create-pglite-adapter.d.ts +5 -1
- package/dist/test-utils/create-pglite-adapter.d.ts.map +1 -1
- package/dist/test-utils/create-pglite-adapter.js +15 -11
- package/package.json +1 -1
- package/src/kernel/database/adapter.ts +24 -1
- package/src/kernel/hooks/deferred.ts +53 -0
- package/src/kernel/hooks/executor.ts +48 -11
- package/src/kernel/hooks/registry.ts +39 -0
- package/src/kernel/plugin/manifest.ts +13 -0
- package/src/modules/catalog/entity-service.ts +7 -7
- package/src/modules/customers/service.ts +4 -4
- package/src/modules/fulfillment/service.ts +2 -2
- package/src/modules/inventory/service.ts +1 -0
- package/src/modules/orders/service.ts +3 -1
- package/src/modules/promotions/service.ts +3 -3
- package/src/runtime/kernel-register-hooks.ts +1 -1
- package/src/runtime/kernel.ts +9 -2
- package/src/test-utils/create-pglite-adapter.ts +20 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/kernel/database/adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/kernel/database/adapter.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe,CAAC,SAAS,GAAG,OAAO,EAAE,YAAY,GAAG,OAAO;IAC1E,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,EAAE,SAAS,CAAC;IACd,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,YAAY,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACjE;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,8BAA8B;IAC7C,OAAO,EAAE,eAAe,CAAC;CAC1B;AASD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAMpC;AAwDD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,8BAA8B,GAAG,eAAe,CAY/F"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withDeferredHooks } from "../hooks/deferred.js";
|
|
1
2
|
/**
|
|
2
3
|
* Marker used to retrieve the raw, un-normalized driver from a wrapped db.
|
|
3
4
|
* Tools that drive the driver directly (drizzle-kit's `pushSchema`, which
|
|
@@ -45,6 +46,24 @@ function normalizeExecuteShape(db) {
|
|
|
45
46
|
return result;
|
|
46
47
|
};
|
|
47
48
|
}
|
|
49
|
+
if (prop === "transaction") {
|
|
50
|
+
const orig = Reflect.get(target, prop, target);
|
|
51
|
+
if (typeof orig !== "function")
|
|
52
|
+
return orig;
|
|
53
|
+
// The OTHER half of the after-commit drain, and the one the card this shipped for
|
|
54
|
+
// actually needs. `createDatabaseConnection().transaction` covers core services and REST
|
|
55
|
+
// routes, but a plugin does not get the adapter — it is handed this db HANDLE as
|
|
56
|
+
// `ctx.db` (TaskContext.db is a DrizzleDatabase) and calls `ctx.db.transaction(...)`.
|
|
57
|
+
// `plugin-channel-connector` constructs its service with no transaction argument in
|
|
58
|
+
// production and therefore imports every product through exactly this path, so without
|
|
59
|
+
// the wrapper here the fix would be green in every suite (they inject the adapter's
|
|
60
|
+
// transaction explicitly) and inert on the deployed import.
|
|
61
|
+
//
|
|
62
|
+
// Double-wrapping is safe: `withDeferredHooks` joins an existing store and drains only at
|
|
63
|
+
// the outermost boundary, so adapter.transaction -> db.transaction nests without draining
|
|
64
|
+
// twice.
|
|
65
|
+
return (fn) => withDeferredHooks(() => orig.call(target, fn));
|
|
66
|
+
}
|
|
48
67
|
const value = Reflect.get(target, prop, target);
|
|
49
68
|
// Bind methods to the real instance so drizzle's internals (incl. any
|
|
50
69
|
// private fields) are never accessed through the proxy.
|
|
@@ -58,7 +77,10 @@ export function createDatabaseConnection(input) {
|
|
|
58
77
|
provider: adapter.provider,
|
|
59
78
|
db: normalizeExecuteShape(adapter.db),
|
|
60
79
|
transaction(fn) {
|
|
61
|
-
return
|
|
80
|
+
return withDeferredHooks(() =>
|
|
81
|
+
// adapter.transaction resolving IS the commit, so draining after it
|
|
82
|
+
// resolves is draining after commit.
|
|
83
|
+
adapter.transaction((tx) => fn(normalizeExecuteShape(tx))));
|
|
62
84
|
},
|
|
63
85
|
};
|
|
64
86
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deferred.d.ts","sourceRoot":"","sources":["../../../src/kernel/hooks/deferred.ts"],"names":[],"mappings":"AAQA,wBAAgB,mBAAmB,IAAI,OAAO,CAE7C;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAKpE;AAcD,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAqB3E"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
const deferredStorage = new AsyncLocalStorage();
|
|
3
|
+
export function isInsideTransaction() {
|
|
4
|
+
return deferredStorage.getStore() != null;
|
|
5
|
+
}
|
|
6
|
+
export function deferAfterCommit(thunk) {
|
|
7
|
+
const pending = deferredStorage.getStore();
|
|
8
|
+
if (!pending)
|
|
9
|
+
return false;
|
|
10
|
+
pending.deferred.push(thunk);
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
async function drainDeferred(pending) {
|
|
14
|
+
// `for...of` over a live array on purpose: a deferred hook that defers another one is drained
|
|
15
|
+
// in the same pass rather than being dropped.
|
|
16
|
+
for (const thunk of pending.deferred) {
|
|
17
|
+
try {
|
|
18
|
+
await thunk();
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// Each thunk logs its own hook failure (see runAfterHooks); swallow so siblings still run.
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function withDeferredHooks(fn) {
|
|
26
|
+
const existing = deferredStorage.getStore();
|
|
27
|
+
if (existing) {
|
|
28
|
+
return fn();
|
|
29
|
+
}
|
|
30
|
+
const pending = { deferred: [] };
|
|
31
|
+
// A throw propagates without reaching the drain: a rolled-back transaction discards its deferred
|
|
32
|
+
// hooks rather than announcing a write that never happened. Stated rather than implied.
|
|
33
|
+
const result = await deferredStorage.run(pending, fn);
|
|
34
|
+
// AWAITED, never `void`. `adapter.transaction` resolving IS the commit, so the hooks below run
|
|
35
|
+
// after commit — and they must still run INSIDE the invocation that started them. The Workers
|
|
36
|
+
// runtime discards a promise that is neither awaited nor handed to `waitUntil` once the
|
|
37
|
+
// invocation ends, which this codebase has already paid for once: a fire-and-forget queue nudge
|
|
38
|
+
// wrote 104 outbox rows and sent ZERO messages on the deployed Worker while every Node test
|
|
39
|
+
// passed. Detaching this drain would do the same to every webhook and search-index update in the
|
|
40
|
+
// product. "After commit" is the requirement; "after the service method returns" is not, and is
|
|
41
|
+
// what tempts you to detach it.
|
|
42
|
+
await drainDeferred(pending);
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
@@ -9,5 +9,5 @@ export interface HookReport {
|
|
|
9
9
|
}
|
|
10
10
|
export declare function mergeHookReports(a: HookReport, b: HookReport): HookReport;
|
|
11
11
|
export declare function runBeforeHooks<T>(hooks: BeforeHook<T>[], data: T, operation: HookOperation, context: HookContext): Promise<T>;
|
|
12
|
-
export declare function runAfterHooks<T>(hooks: AfterHook<T>[], originalData: T | null, committedResult: T, operation: HookOperation, context: HookContext): Promise<HookReport>;
|
|
12
|
+
export declare function runAfterHooks<T>(hooks: AfterHook<T>[], originalData: T | null, committedResult: T, operation: HookOperation, context: HookContext, runsInTransaction?: (hook: AfterHook<T>) => boolean): Promise<HookReport>;
|
|
13
13
|
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/kernel/hooks/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/kernel/hooks/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGpF,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,UAAU,CAKzE;AAqCD,wBAAsB,cAAc,CAAC,CAAC,EACpC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,EACtB,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,CAAC,CAAC,CAmBZ;AAED,wBAAsB,aAAa,CAAC,CAAC,EACnC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,EACrB,YAAY,EAAE,CAAC,GAAG,IAAI,EACtB,eAAe,EAAE,CAAC,EAClB,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,WAAW,EACpB,iBAAiB,GAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,OAAqB,GAC/D,OAAO,CAAC,UAAU,CAAC,CA6DrB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { deferAfterCommit } from "./deferred.js";
|
|
1
2
|
export function mergeHookReports(a, b) {
|
|
2
3
|
return {
|
|
3
4
|
errors: [...a.errors, ...b.errors],
|
|
@@ -47,27 +48,60 @@ export async function runBeforeHooks(hooks, data, operation, context) {
|
|
|
47
48
|
}
|
|
48
49
|
return current;
|
|
49
50
|
}
|
|
50
|
-
export async function runAfterHooks(hooks, originalData, committedResult, operation, context) {
|
|
51
|
+
export async function runAfterHooks(hooks, originalData, committedResult, operation, context, runsInTransaction = () => false) {
|
|
51
52
|
const errors = [];
|
|
52
53
|
for (const hook of hooks) {
|
|
53
54
|
const hookName = hook.name || "(anonymous afterHook)";
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
context
|
|
60
|
-
|
|
55
|
+
const runHook = () => withTimeout(hook({
|
|
56
|
+
data: originalData,
|
|
57
|
+
result: committedResult,
|
|
58
|
+
operation,
|
|
59
|
+
context: runsInTransaction(hook)
|
|
60
|
+
? context
|
|
61
|
+
: { ...context, tx: null },
|
|
62
|
+
}), HOOK_TIMEOUT_MS, hookName);
|
|
63
|
+
if (runsInTransaction(hook)) {
|
|
64
|
+
try {
|
|
65
|
+
await runHook();
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
errors.push({
|
|
69
|
+
hookName,
|
|
70
|
+
message: error instanceof Error ? error.message : String(error),
|
|
71
|
+
});
|
|
72
|
+
context.logger.error(`After-hook "${hookName}" failed`, {
|
|
73
|
+
error,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
continue;
|
|
61
77
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
const deferred = deferAfterCommit(async () => {
|
|
79
|
+
try {
|
|
80
|
+
await runHook();
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
context.logger.error(`After-commit hook "${hookName}" failed`, {
|
|
84
|
+
error,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
if (!deferred) {
|
|
89
|
+
try {
|
|
90
|
+
await runHook();
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
errors.push({
|
|
94
|
+
hookName,
|
|
95
|
+
message: error instanceof Error ? error.message : String(error),
|
|
96
|
+
});
|
|
97
|
+
context.logger.error(`After-hook "${hookName}" failed`, {
|
|
98
|
+
error,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
70
101
|
}
|
|
71
102
|
}
|
|
103
|
+
// After-commit hook failures are logged when the transaction drains; they
|
|
104
|
+
// cannot appear here because deferred hooks run after commit, once the
|
|
105
|
+
// service method has already returned its Result.
|
|
72
106
|
return { errors, hasErrors: errors.length > 0 };
|
|
73
107
|
}
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
export type HookHandler = (...args: never[]) => unknown;
|
|
2
|
+
/** Declare that this handler must run inside the writing transaction. Called by the manifest merge. */
|
|
3
|
+
export declare function markHookInTransaction(handler: unknown): void;
|
|
4
|
+
/** Whether a plugin asked for this handler to run in-transaction. Read by the kernel at boot. */
|
|
5
|
+
export declare function isHookMarkedInTransaction(handler: unknown): boolean;
|
|
2
6
|
export declare class HookRegistry {
|
|
3
7
|
private registry;
|
|
8
|
+
private inTransactionHandlers;
|
|
4
9
|
private logger?;
|
|
5
10
|
registerConfigHooks(hookName: string, handlers: HookHandler[]): void;
|
|
6
11
|
append(hookName: string, handler: HookHandler): void;
|
|
12
|
+
appendInTransaction(hookName: string, handler: HookHandler): void;
|
|
7
13
|
prepend(hookName: string, handler: HookHandler): void;
|
|
14
|
+
prependInTransaction(hookName: string, handler: HookHandler): void;
|
|
15
|
+
runsInTransaction(handler: HookHandler): boolean;
|
|
8
16
|
resolve(hookName: string): HookHandler[];
|
|
9
17
|
/**
|
|
10
18
|
* Emit a plugin event to all registered listeners.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/kernel/hooks/registry.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/kernel/hooks/registry.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;AAgBxD,uGAAuG;AACvG,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAE5D;AAED,iGAAiG;AACjG,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAEnE;AAQD,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,qBAAqB,CAA8B;IAC3D,OAAO,CAAC,MAAM,CAAC,CAAiE;IAEhF,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,IAAI;IAKpE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI;IAKpD,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI;IAKjE,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI;IAKrD,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI;IAKlE,iBAAiB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO;IAIhD,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,EAAE;IAMxC;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,GAAG,IAAI;IAIjF,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAcxD,OAAO,CAAC,WAAW;CASpB"}
|
|
@@ -1,5 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handlers a PLUGIN asked to run inside the writing transaction.
|
|
3
|
+
*
|
|
4
|
+
* Module-level rather than per-registry because a plugin's declaration and its registration are
|
|
5
|
+
* separated by the manifest merge: `manifest.hooks()` returns `{ key, handler, inTransaction }`
|
|
6
|
+
* records, which are flattened into `config.hooks` as a bare `key -> handler[]` map long before any
|
|
7
|
+
* HookRegistry exists. Marking the function itself is the only channel that survives that.
|
|
8
|
+
*
|
|
9
|
+
* Shipped in 0.35.1 because 0.35.0 made after-commit the default with no way for a plugin to opt
|
|
10
|
+
* out, which silently moved `loom_projection_pending` — a transactional outbox whose whole point is
|
|
11
|
+
* committing with the write it records — to after the commit.
|
|
12
|
+
*/
|
|
13
|
+
const pluginInTransactionHandlers = new WeakSet();
|
|
14
|
+
/** Declare that this handler must run inside the writing transaction. Called by the manifest merge. */
|
|
15
|
+
export function markHookInTransaction(handler) {
|
|
16
|
+
if (typeof handler === "function")
|
|
17
|
+
pluginInTransactionHandlers.add(handler);
|
|
18
|
+
}
|
|
19
|
+
/** Whether a plugin asked for this handler to run in-transaction. Read by the kernel at boot. */
|
|
20
|
+
export function isHookMarkedInTransaction(handler) {
|
|
21
|
+
return typeof handler === "function" && pluginInTransactionHandlers.has(handler);
|
|
22
|
+
}
|
|
1
23
|
export class HookRegistry {
|
|
2
24
|
registry = new Map();
|
|
25
|
+
inTransactionHandlers = new WeakSet();
|
|
3
26
|
logger;
|
|
4
27
|
registerConfigHooks(hookName, handlers) {
|
|
5
28
|
this.ensureEntry(hookName);
|
|
@@ -9,10 +32,21 @@ export class HookRegistry {
|
|
|
9
32
|
this.ensureEntry(hookName);
|
|
10
33
|
this.registry.get(hookName).appended.push(handler);
|
|
11
34
|
}
|
|
35
|
+
appendInTransaction(hookName, handler) {
|
|
36
|
+
this.inTransactionHandlers.add(handler);
|
|
37
|
+
this.append(hookName, handler);
|
|
38
|
+
}
|
|
12
39
|
prepend(hookName, handler) {
|
|
13
40
|
this.ensureEntry(hookName);
|
|
14
41
|
this.registry.get(hookName).prepended.push(handler);
|
|
15
42
|
}
|
|
43
|
+
prependInTransaction(hookName, handler) {
|
|
44
|
+
this.inTransactionHandlers.add(handler);
|
|
45
|
+
this.prepend(hookName, handler);
|
|
46
|
+
}
|
|
47
|
+
runsInTransaction(handler) {
|
|
48
|
+
return this.inTransactionHandlers.has(handler);
|
|
49
|
+
}
|
|
16
50
|
resolve(hookName) {
|
|
17
51
|
const entry = this.registry.get(hookName);
|
|
18
52
|
if (!entry)
|
|
@@ -28,6 +28,15 @@ export type PluginRouteRegistration = {
|
|
|
28
28
|
export interface PluginHookRegistration {
|
|
29
29
|
key: string;
|
|
30
30
|
handler: (...args: unknown[]) => unknown;
|
|
31
|
+
/**
|
|
32
|
+
* Run this hook INSIDE the writing transaction instead of after it commits.
|
|
33
|
+
*
|
|
34
|
+
* The default is after-commit and is correct for anything with an external effect — a webhook, a
|
|
35
|
+
* search-index write, an email — none of which may announce a write that can still roll back.
|
|
36
|
+
* Set this only for an OUTBOX WRITER: a hook whose own write must commit or roll back together
|
|
37
|
+
* with the row it records. `loom_projection_pending` is the case this exists for.
|
|
38
|
+
*/
|
|
39
|
+
inTransaction?: boolean;
|
|
31
40
|
}
|
|
32
41
|
export interface PluginContext {
|
|
33
42
|
config: CommerceConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../../src/kernel/plugin/manifest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../../src/kernel/plugin/manifest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAS5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIvD,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IA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AsB,GAC/B,cAAc,CAmLhB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { markHookInTransaction } from "../hooks/registry.js";
|
|
1
2
|
import { resolveOrgIdForCommerce } from "../../auth/org.js";
|
|
2
3
|
import { isRoutePermissionGuard, markRoutePermissionGuard } from "../../interfaces/rest/utils.js";
|
|
3
4
|
import { createScopedDb } from "../database/scoped-db.js";
|
|
@@ -141,6 +142,10 @@ export function defineCommercePlugin(manifest) {
|
|
|
141
142
|
...(result.hooks ?? {}),
|
|
142
143
|
};
|
|
143
144
|
for (const reg of registrations) {
|
|
145
|
+
// The marker rides on the function because this map is a bare key -> handler[] and cannot
|
|
146
|
+
// carry it; the kernel reads it back when it registers these at boot.
|
|
147
|
+
if (reg.inTransaction)
|
|
148
|
+
markHookInTransaction(reg.handler);
|
|
144
149
|
hookMap[reg.key] = [...(hookMap[reg.key] ?? []), reg.handler];
|
|
145
150
|
}
|
|
146
151
|
result = { ...result, hooks: hookMap };
|
|
@@ -224,7 +224,7 @@ export class EntityService {
|
|
|
224
224
|
return Err(new CommerceConflictError(`Entity with slug ${input.slug} already exists.`));
|
|
225
225
|
const beforeHooks = this.deps.hooks.resolve("catalog.beforeCreate");
|
|
226
226
|
const afterHooks = this.deps.hooks.resolve("catalog.afterCreate");
|
|
227
|
-
const context =
|
|
227
|
+
const context = catalogHookContext(this.deps, actor, ctx, "create");
|
|
228
228
|
const processedInput = await runBeforeHooks(beforeHooks, input, "create", context);
|
|
229
229
|
if (processedInput.sourceStoreId != null)
|
|
230
230
|
assertPermission(actor, "catalog:sync");
|
|
@@ -238,7 +238,7 @@ export class EntityService {
|
|
|
238
238
|
await this.repo.createAttribute({ entityId: entity.id, locale: processedInput.attributes.locale ?? "en", title: processedInput.attributes.title, subtitle: processedInput.attributes.subtitle, description: processedInput.attributes.description, richDescription: processedInput.attributes.richDescription, seoTitle: processedInput.attributes.seoTitle, seoDescription: processedInput.attributes.seoDescription }, ctx);
|
|
239
239
|
}
|
|
240
240
|
await this.writeCustomFields(entity.id, customFieldsResult.value, ctx);
|
|
241
|
-
const hookReport = await runAfterHooks(afterHooks, null, entity, "create", context);
|
|
241
|
+
const hookReport = await runAfterHooks(afterHooks, null, entity, "create", context, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
242
242
|
const hydrated = await this.hydrateEntity(entity, undefined, ctx);
|
|
243
243
|
return Ok(hydrated, hookReport.hasErrors ? { hookErrors: hookReport.errors } : undefined);
|
|
244
244
|
}
|
|
@@ -266,7 +266,7 @@ export class EntityService {
|
|
|
266
266
|
if (!updated)
|
|
267
267
|
return Err(new CommerceNotFoundError("Entity not found."));
|
|
268
268
|
await this.writeCustomFields(existing.id, customFieldsResult.value, txCtx, true);
|
|
269
|
-
const hookReport = await runAfterHooks(afterHooks, existing, updated, "update", context);
|
|
269
|
+
const hookReport = await runAfterHooks(afterHooks, existing, updated, "update", context, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
270
270
|
const hydrated = await this.hydrateEntity(updated, undefined, txCtx);
|
|
271
271
|
return Ok(hydrated, hookReport.hasErrors ? { hookErrors: hookReport.errors } : undefined);
|
|
272
272
|
}
|
|
@@ -328,7 +328,7 @@ export class EntityService {
|
|
|
328
328
|
}
|
|
329
329
|
const result = await this.hydrateEntity(entity, processed.options ?? options, ctx);
|
|
330
330
|
const entityAfterHooks = this.deps.hooks.resolve(`catalog.${entity.type}.afterRead`);
|
|
331
|
-
const report = mergeHookReports(await runAfterHooks(globalAfterHooks, null, result, "read", context), await runAfterHooks(entityAfterHooks, null, result, "read", context));
|
|
331
|
+
const report = mergeHookReports(await runAfterHooks(globalAfterHooks, null, result, "read", context, (hook) => this.deps.hooks.runsInTransaction(hook)), await runAfterHooks(entityAfterHooks, null, result, "read", context, (hook) => this.deps.hooks.runsInTransaction(hook)));
|
|
332
332
|
return Ok(result, report.hasErrors ? { hookErrors: report.errors } : undefined);
|
|
333
333
|
}
|
|
334
334
|
/**
|
|
@@ -380,7 +380,7 @@ export class EntityService {
|
|
|
380
380
|
}
|
|
381
381
|
const result = await this.hydrateEntity(entity, processed.options ?? options, ctx);
|
|
382
382
|
const entityAfterHooks = this.deps.hooks.resolve(`catalog.${entity.type}.afterRead`);
|
|
383
|
-
const report = mergeHookReports(await runAfterHooks(globalAfterHooks, null, result, "read", context), await runAfterHooks(entityAfterHooks, null, result, "read", context));
|
|
383
|
+
const report = mergeHookReports(await runAfterHooks(globalAfterHooks, null, result, "read", context, (hook) => this.deps.hooks.runsInTransaction(hook)), await runAfterHooks(entityAfterHooks, null, result, "read", context, (hook) => this.deps.hooks.runsInTransaction(hook)));
|
|
384
384
|
return Ok(result, report.hasErrors ? { hookErrors: report.errors } : undefined);
|
|
385
385
|
}
|
|
386
386
|
async list(params, actor, ctx) {
|
|
@@ -457,7 +457,7 @@ export class EntityService {
|
|
|
457
457
|
const result = { items: hydratedItems, pagination: paged.pagination };
|
|
458
458
|
const listTypeFilter = processed.filter?.type;
|
|
459
459
|
const entityAfterHooks = listTypeFilter ? this.deps.hooks.resolve(`catalog.${listTypeFilter}.afterList`) : [];
|
|
460
|
-
const report = mergeHookReports(await runAfterHooks(globalAfterHooks, null, result, "list", context), await runAfterHooks(entityAfterHooks, null, result, "list", context));
|
|
460
|
+
const report = mergeHookReports(await runAfterHooks(globalAfterHooks, null, result, "list", context, (hook) => this.deps.hooks.runsInTransaction(hook)), await runAfterHooks(entityAfterHooks, null, result, "list", context, (hook) => this.deps.hooks.runsInTransaction(hook)));
|
|
461
461
|
return Ok(result, report.hasErrors ? { hookErrors: report.errors } : undefined);
|
|
462
462
|
}
|
|
463
463
|
async changeStatus(id, status, actor, ctx) {
|
|
@@ -530,7 +530,7 @@ export class EntityService {
|
|
|
530
530
|
const afterHooks = this.deps.hooks.resolve("catalog.afterUpdate");
|
|
531
531
|
const context = catalogHookContext(this.deps, actor, ctx, "update");
|
|
532
532
|
context.context.changedFieldPaths = changedFieldPaths;
|
|
533
|
-
await runAfterHooks(afterHooks, entity, entity, "update", context);
|
|
533
|
+
await runAfterHooks(afterHooks, entity, entity, "update", context, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
534
534
|
}
|
|
535
535
|
return Ok(undefined);
|
|
536
536
|
}
|
|
@@ -54,7 +54,7 @@ export class CustomerService {
|
|
|
54
54
|
}, ctx);
|
|
55
55
|
const afterHooks = this.deps.hooks.resolve("customers.afterCreate");
|
|
56
56
|
const hctx = hookContext(actor ?? null, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null);
|
|
57
|
-
await runAfterHooks(afterHooks, null, customer, "create", hctx);
|
|
57
|
+
await runAfterHooks(afterHooks, null, customer, "create", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
58
58
|
return Ok(customer);
|
|
59
59
|
}
|
|
60
60
|
// ─── Customer interactions (clienteling notes / visits / calls) ──────────
|
|
@@ -138,7 +138,7 @@ export class CustomerService {
|
|
|
138
138
|
}, ctx);
|
|
139
139
|
const afterHooks = this.deps.hooks.resolve("customers.afterCreate");
|
|
140
140
|
const hctx = hookContext(actor, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null);
|
|
141
|
-
await runAfterHooks(afterHooks, null, customer, "create", hctx);
|
|
141
|
+
await runAfterHooks(afterHooks, null, customer, "create", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
142
142
|
return customer;
|
|
143
143
|
}
|
|
144
144
|
async list(actor, ctx) {
|
|
@@ -187,7 +187,7 @@ export class CustomerService {
|
|
|
187
187
|
return Err(new CommerceNotFoundError("Customer not found."));
|
|
188
188
|
const afterHooks = this.deps.hooks.resolve("customers.afterUpdate");
|
|
189
189
|
const hctx = hookContext(actor ?? ctx?.actor ?? null, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null);
|
|
190
|
-
await runAfterHooks(afterHooks, existing, updated, "update", hctx);
|
|
190
|
+
await runAfterHooks(afterHooks, existing, updated, "update", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
191
191
|
return Ok(updated);
|
|
192
192
|
}
|
|
193
193
|
async updateByUserId(userId, updates, actor, ctx) {
|
|
@@ -200,7 +200,7 @@ export class CustomerService {
|
|
|
200
200
|
}
|
|
201
201
|
const afterHooks = this.deps.hooks.resolve("customers.afterUpdate");
|
|
202
202
|
const hctx = hookContext(resolvedActor, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null);
|
|
203
|
-
await runAfterHooks(afterHooks, customer, updated, "update", hctx);
|
|
203
|
+
await runAfterHooks(afterHooks, customer, updated, "update", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
204
204
|
return Ok(updated);
|
|
205
205
|
}
|
|
206
206
|
async getAddresses(userId, actor, ctx) {
|
|
@@ -188,7 +188,7 @@ export class FulfillmentService {
|
|
|
188
188
|
database: { db: this.deps.database.db },
|
|
189
189
|
commerceConfig: this.deps.config,
|
|
190
190
|
});
|
|
191
|
-
await runAfterHooks(afterHooks, null, record, "create", hookCtx);
|
|
191
|
+
await runAfterHooks(afterHooks, null, record, "create", hookCtx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
192
192
|
// Create a fulfillment line item linking this fulfillment to the order line item
|
|
193
193
|
for (const li of record.lineItems) {
|
|
194
194
|
await this.deps.repository.createLineItem({
|
|
@@ -288,7 +288,7 @@ export class FulfillmentService {
|
|
|
288
288
|
database: { db: this.deps.database.db },
|
|
289
289
|
commerceConfig: this.deps.config,
|
|
290
290
|
});
|
|
291
|
-
await runAfterHooks(afterHooks, null, record, "create", hookCtx);
|
|
291
|
+
await runAfterHooks(afterHooks, null, record, "create", hookCtx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
292
292
|
return Ok(record);
|
|
293
293
|
}
|
|
294
294
|
async getByOrderId(orderId, ctx) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/modules/inventory/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACj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QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,EACD,GAAG,CAAC,EAAE,SAAS,GACd,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IA+ClB,WAAW,CACf,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,EAClB,GAAG,CAAC,EAAE,SAAS,GACd,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;CA2BnC"}
|
|
@@ -240,7 +240,7 @@ export class InventoryService {
|
|
|
240
240
|
commerceConfig: this.deps.config,
|
|
241
241
|
});
|
|
242
242
|
const afterHooks = this.deps.hooks.resolve("inventory.afterAdjust");
|
|
243
|
-
await runAfterHooks(afterHooks, null, level, "update", hookCtx);
|
|
243
|
+
await runAfterHooks(afterHooks, null, level, "update", hookCtx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
244
244
|
return Ok({ level, before, after, delta, movementId: movement.id });
|
|
245
245
|
};
|
|
246
246
|
return this.withTransaction(ctx, async (tx) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/modules/orders/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAkB5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,eAAe,EACrB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAG9D,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAEL,KAAK,SAAS,EACf,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,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
|
|
377
377
|
const hydrated = await this.hydrateOrder(order, ctx);
|
|
378
|
-
const report = await runAfterHooks(afterHooks, null, hydrated, "create", hookCtx);
|
|
378
|
+
const report = await runAfterHooks(afterHooks, null, hydrated, "create", hookCtx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
379
379
|
return Ok(hydrated, report.hasErrors ? { hookErrors: report.errors } : undefined);
|
|
380
380
|
}
|
|
381
381
|
async getById(id, actor, ctx, guestCredential) {
|
|
@@ -405,7 +405,7 @@ export class OrderService {
|
|
|
405
405
|
const afterGetHooks = this.deps.hooks.resolve("orders.afterGet");
|
|
406
406
|
if (afterGetHooks.length > 0) {
|
|
407
407
|
const hookCtx = context(actor, this.deps.services, this.deps.database, this.deps.config, ctx?.tx);
|
|
408
|
-
await runAfterHooks(afterGetHooks, null, hydrated, "read", hookCtx);
|
|
408
|
+
await runAfterHooks(afterGetHooks, null, hydrated, "read", hookCtx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
409
409
|
}
|
|
410
410
|
return Ok(hydrated);
|
|
411
411
|
}
|
|
@@ -675,7 +675,7 @@ export class OrderService {
|
|
|
675
675
|
// Audit logging is automatic via the audit hooks registered at kernel
|
|
676
676
|
// boot — no manual audit.record() call needed here.
|
|
677
677
|
const hydrated = await this.hydrateOrder(cas, ctx);
|
|
678
|
-
const report = await runAfterHooks(afterHooks, null, hydrated, "statusChange", hookCtx);
|
|
678
|
+
const report = await runAfterHooks(afterHooks, null, hydrated, "statusChange", hookCtx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
679
679
|
return Ok(hydrated, report.hasErrors ? { hookErrors: report.errors } : undefined);
|
|
680
680
|
}
|
|
681
681
|
async cancel(orderId, actor, reason = "cancelled_by_user", ctx) {
|
|
@@ -117,7 +117,7 @@ export class PromotionService {
|
|
|
117
117
|
}, ctx);
|
|
118
118
|
const afterHooks = this.deps.hooks.resolve("promotions.afterCreate");
|
|
119
119
|
const hctx = hookContext(actor ?? ctx?.actor ?? null, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null);
|
|
120
|
-
await runAfterHooks(afterHooks, null, promotion, "create", hctx);
|
|
120
|
+
await runAfterHooks(afterHooks, null, promotion, "create", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
121
121
|
return Ok(promotion);
|
|
122
122
|
}
|
|
123
123
|
async deactivate(orgId, id, ctx) {
|
|
@@ -132,7 +132,7 @@ export class PromotionService {
|
|
|
132
132
|
const afterHooks = this.deps.hooks.resolve("promotions.afterUpdate");
|
|
133
133
|
// Actor-less by design; resolves to the deployment's declared organization.
|
|
134
134
|
const hctx = hookContext(null, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null);
|
|
135
|
-
await runAfterHooks(afterHooks, promotion, updated, "update", hctx);
|
|
135
|
+
await runAfterHooks(afterHooks, promotion, updated, "update", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
136
136
|
return Ok(updated);
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
@@ -201,7 +201,7 @@ export class PromotionService {
|
|
|
201
201
|
}
|
|
202
202
|
const afterHooks = this.deps.hooks.resolve("promotions.afterUpdate");
|
|
203
203
|
const hctx = hookContext(actor ?? ctx?.actor ?? null, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null);
|
|
204
|
-
await runAfterHooks(afterHooks, existing, updated, "update", hctx);
|
|
204
|
+
await runAfterHooks(afterHooks, existing, updated, "update", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
205
205
|
return Ok(updated);
|
|
206
206
|
}
|
|
207
207
|
async list(filter, actor, ctx) {
|
|
@@ -41,6 +41,6 @@ export function registerConfiguredKernelHooks(config, hooks) {
|
|
|
41
41
|
hooks.append("catalog.afterCreate", syncToSearchIndex);
|
|
42
42
|
hooks.append("catalog.afterUpdate", syncToSearchIndex);
|
|
43
43
|
for (const [key, handler] of Object.entries(auditHooks)) {
|
|
44
|
-
hooks.
|
|
44
|
+
hooks.appendInTransaction(key, handler);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../../src/runtime/kernel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAqBzD,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,sBAAsB,EAC5B,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EAAE,MAAM,EAAE,sBAAsB,EAAE,CAAC;AAC/C,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAClB,8BAA8B,GAC/B,MAAM,qBAAqB,CAAC;AAE7B,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../../src/runtime/kernel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAqBzD,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,sBAAsB,EAC5B,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EAAE,MAAM,EAAE,sBAAsB,EAAE,CAAC;AAC/C,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAClB,8BAA8B,GAC/B,MAAM,qBAAqB,CAAC;AAE7B,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAiJ3D"}
|
package/dist/runtime/kernel.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HookRegistry } from "../kernel/hooks/registry.js";
|
|
1
|
+
import { HookRegistry, isHookMarkedInTransaction } from "../kernel/hooks/registry.js";
|
|
2
2
|
import { createDatabaseConnection } from "../kernel/database/adapter.js";
|
|
3
3
|
import { topoSortModules } from "../kernel/module/index.js";
|
|
4
4
|
import { WebhookDeliveryWorker } from "../modules/webhooks/worker.js";
|
|
@@ -115,7 +115,15 @@ export function createKernel(config) {
|
|
|
115
115
|
};
|
|
116
116
|
for (const [key, handlers] of Object.entries(config.hooks ?? {})) {
|
|
117
117
|
for (const handler of handlers) {
|
|
118
|
-
|
|
118
|
+
// A plugin that declared `inTransaction` gets appendInTransaction, so its hook runs inside
|
|
119
|
+
// the writing transaction rather than in the after-commit drain. Everything else defaults to
|
|
120
|
+
// after-commit, which is what 0.35.0 established.
|
|
121
|
+
if (isHookMarkedInTransaction(handler)) {
|
|
122
|
+
hooks.appendInTransaction(key, handler);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
hooks.append(key, handler);
|
|
126
|
+
}
|
|
119
127
|
}
|
|
120
128
|
}
|
|
121
129
|
for (const model of config.analytics?.models ?? []) {
|