@nexpress/core 0.3.1 → 0.3.3
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/auth.d.ts +2 -2
- package/dist/{chunk-UIQYA3Y7.js → chunk-2TOS5BYT.js} +2 -2
- package/dist/{chunk-HVHV3IHF.js → chunk-AOEN5EIX.js} +7 -4
- package/dist/chunk-AOEN5EIX.js.map +1 -0
- package/dist/{chunk-P5WGQRSG.js → chunk-EFZH6UPY.js} +5 -2
- package/dist/chunk-EFZH6UPY.js.map +1 -0
- package/dist/{chunk-HUESWYZJ.js → chunk-HYYMUVUK.js} +2 -2
- package/dist/{chunk-AEKO4MXK.js → chunk-LMPYQLMH.js} +17 -2
- package/dist/chunk-LMPYQLMH.js.map +1 -0
- package/dist/{chunk-6IEYOY2L.js → chunk-MXOHWU2P.js} +60 -17
- package/dist/chunk-MXOHWU2P.js.map +1 -0
- package/dist/{chunk-DKOCKZVG.js → chunk-WG3B2GNE.js} +6 -6
- package/dist/{chunk-56ZK5PWM.js → chunk-WOLMQGW7.js} +2 -2
- package/dist/community.d.ts +1 -1
- package/dist/community.js +4 -4
- package/dist/{config-44MFLLIX.js → config-CO6TXCA6.js} +5 -5
- package/dist/db-schema.d.ts +2 -2
- package/dist/db.d.ts +3 -3
- package/dist/db.js +1 -1
- package/dist/fields.d.ts +1 -1
- package/dist/fields.js +1 -1
- package/dist/{host-DKOWZWKA.js → host-HDRI7WIP.js} +3 -3
- package/dist/i18n.d.ts +1 -1
- package/dist/{index-C-jKU1St.d.ts → index-CPp-zGgL.d.ts} +2 -2
- package/dist/{index-BmR3Z8Y5.d.ts → index-DKoSaszT.d.ts} +1 -1
- package/dist/{index-Ca-WUDH5.d.ts → index-DymnczhP.d.ts} +1 -1
- package/dist/{index-lACZ9sON.d.ts → index-UZn29S3i.d.ts} +1 -1
- package/dist/index.d.ts +100 -12
- package/dist/index.js +14 -12
- package/dist/index.js.map +1 -1
- package/dist/jobs.d.ts +2 -2
- package/dist/jobs.js +1 -1
- package/dist/media.d.ts +2 -2
- package/dist/{scheduled-VEOGI5EW.js → scheduled-7MSJIJLE.js} +4 -4
- package/dist/seo.d.ts +16 -3
- package/dist/seo.js +3 -3
- package/dist/{types-BY1UmEiY.d.ts → types-D31ppGJw.d.ts} +45 -0
- package/package.json +1 -1
- package/dist/chunk-6IEYOY2L.js.map +0 -1
- package/dist/chunk-AEKO4MXK.js.map +0 -1
- package/dist/chunk-HVHV3IHF.js.map +0 -1
- package/dist/chunk-P5WGQRSG.js.map +0 -1
- /package/dist/{chunk-UIQYA3Y7.js.map → chunk-2TOS5BYT.js.map} +0 -0
- /package/dist/{chunk-HUESWYZJ.js.map → chunk-HYYMUVUK.js.map} +0 -0
- /package/dist/{chunk-DKOCKZVG.js.map → chunk-WG3B2GNE.js.map} +0 -0
- /package/dist/{chunk-56ZK5PWM.js.map → chunk-WOLMQGW7.js.map} +0 -0
- /package/dist/{config-44MFLLIX.js.map → config-CO6TXCA6.js.map} +0 -0
- /package/dist/{host-DKOWZWKA.js.map → host-HDRI7WIP.js.map} +0 -0
- /package/dist/{scheduled-VEOGI5EW.js.map → scheduled-7MSJIJLE.js.map} +0 -0
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "./chunk-2VZZ7M26.js";
|
|
8
8
|
import {
|
|
9
9
|
getCollectionZodSchema
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-EFZH6UPY.js";
|
|
11
11
|
import {
|
|
12
12
|
getI18nConfig
|
|
13
13
|
} from "./chunk-4ZLMEKFX.js";
|
|
@@ -56,6 +56,7 @@ import {
|
|
|
56
56
|
import { and, eq as eq2, gt, isNull, like, or } from "drizzle-orm";
|
|
57
57
|
|
|
58
58
|
// src/collections/pipeline.ts
|
|
59
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
59
60
|
import { randomUUID } from "crypto";
|
|
60
61
|
import { asc, count, desc, eq, inArray, sql as sql2 } from "drizzle-orm";
|
|
61
62
|
|
|
@@ -189,7 +190,36 @@ function actorPrincipal(actor) {
|
|
|
189
190
|
}
|
|
190
191
|
}
|
|
191
192
|
}
|
|
193
|
+
var deferredPostCommitStore = new AsyncLocalStorage();
|
|
194
|
+
async function withDeferredPostCommit(callback) {
|
|
195
|
+
const queue = [];
|
|
196
|
+
const result = await deferredPostCommitStore.run(queue, callback);
|
|
197
|
+
for (const hook of queue) {
|
|
198
|
+
try {
|
|
199
|
+
await hook.fn();
|
|
200
|
+
} catch (err) {
|
|
201
|
+
const { getLogger: getLogger2 } = await import("./logger-2WUTTELV.js");
|
|
202
|
+
getLogger2().error(
|
|
203
|
+
`deferred post-commit ${hook.label} failed \u2014 outer scope committed, follow-up skipped`,
|
|
204
|
+
{
|
|
205
|
+
collection: hook.context.collection,
|
|
206
|
+
documentId: hook.context.documentId,
|
|
207
|
+
operation: hook.context.operation,
|
|
208
|
+
label: hook.label,
|
|
209
|
+
error: err instanceof Error ? err.message : String(err),
|
|
210
|
+
stack: err instanceof Error ? err.stack : void 0
|
|
211
|
+
}
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
192
217
|
async function runPostCommit(label, context, fn) {
|
|
218
|
+
const queue = deferredPostCommitStore.getStore();
|
|
219
|
+
if (queue) {
|
|
220
|
+
queue.push({ label, context, fn });
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
193
223
|
try {
|
|
194
224
|
await fn();
|
|
195
225
|
} catch (err) {
|
|
@@ -411,9 +441,11 @@ async function initSaveContext(collection, docId, data, actor, options) {
|
|
|
411
441
|
const registration = getCollectionRegistration(collection);
|
|
412
442
|
const table = getCollectionTable(collection);
|
|
413
443
|
const db = getDb();
|
|
444
|
+
const outerTx = options?.tx;
|
|
414
445
|
const validatedData = toRecord(getCollectionZodSchema(config, data).parse(data));
|
|
415
446
|
const operation = docId ? "update" : "create";
|
|
416
|
-
const
|
|
447
|
+
const readHandle = outerTx ?? db;
|
|
448
|
+
const originalDoc = docId ? await getDocumentByIdInternal(readHandle, table, collection, docId) : null;
|
|
417
449
|
return {
|
|
418
450
|
collection,
|
|
419
451
|
docId,
|
|
@@ -424,6 +456,7 @@ async function initSaveContext(collection, docId, data, actor, options) {
|
|
|
424
456
|
registration,
|
|
425
457
|
table,
|
|
426
458
|
db,
|
|
459
|
+
outerTx,
|
|
427
460
|
operation,
|
|
428
461
|
originalDoc,
|
|
429
462
|
userForHooks: actorUserOrNull(actor),
|
|
@@ -575,7 +608,7 @@ async function persistDocumentTx(ctx) {
|
|
|
575
608
|
principal: ctx.principal
|
|
576
609
|
});
|
|
577
610
|
}
|
|
578
|
-
|
|
611
|
+
const persist = async (tx) => {
|
|
579
612
|
const persistedDoc = ctx.operation === "update" ? await updateMainDocument(
|
|
580
613
|
tx,
|
|
581
614
|
ctx.table,
|
|
@@ -626,7 +659,11 @@ async function persistDocumentTx(ctx) {
|
|
|
626
659
|
);
|
|
627
660
|
}
|
|
628
661
|
return persistedDoc;
|
|
629
|
-
}
|
|
662
|
+
};
|
|
663
|
+
if (ctx.outerTx) {
|
|
664
|
+
return persist(ctx.outerTx);
|
|
665
|
+
}
|
|
666
|
+
return ctx.db.transaction(persist);
|
|
630
667
|
}
|
|
631
668
|
async function firePostCommitHooks(ctx, savedDoc) {
|
|
632
669
|
const savedDocId = getRecordId(savedDoc);
|
|
@@ -772,8 +809,8 @@ function stableJson(value) {
|
|
|
772
809
|
return val;
|
|
773
810
|
});
|
|
774
811
|
}
|
|
775
|
-
async function deleteDocument(collection, docId, user) {
|
|
776
|
-
return deleteDocumentImpl(collection, docId, { kind: "staff", user });
|
|
812
|
+
async function deleteDocument(collection, docId, user, options) {
|
|
813
|
+
return deleteDocumentImpl(collection, docId, { kind: "staff", user }, options);
|
|
777
814
|
}
|
|
778
815
|
async function deleteMemberDocument(collection, docId, memberId) {
|
|
779
816
|
const table = getCollectionTable(collection);
|
|
@@ -866,12 +903,12 @@ async function promoteMemberDocument(collection, docId, staffUserId) {
|
|
|
866
903
|
});
|
|
867
904
|
return { doc: persistedDoc, operation: "update" };
|
|
868
905
|
}
|
|
869
|
-
async function deleteDocumentImpl(collection, docId, actor) {
|
|
906
|
+
async function deleteDocumentImpl(collection, docId, actor, options) {
|
|
870
907
|
const config = getCollectionConfig(collection);
|
|
871
908
|
const registration = getCollectionRegistration(collection);
|
|
872
909
|
const table = getCollectionTable(collection);
|
|
873
|
-
const
|
|
874
|
-
const originalDoc = await getDocumentByIdInternal(
|
|
910
|
+
const dbHandle = options?.tx ?? getDb();
|
|
911
|
+
const originalDoc = await getDocumentByIdInternal(dbHandle, table, collection, docId);
|
|
875
912
|
if (!originalDoc) {
|
|
876
913
|
throw new NpNotFoundError(collection, docId);
|
|
877
914
|
}
|
|
@@ -908,7 +945,7 @@ async function deleteDocumentImpl(collection, docId, actor) {
|
|
|
908
945
|
user: userForHooks,
|
|
909
946
|
principal
|
|
910
947
|
});
|
|
911
|
-
|
|
948
|
+
const cascade = async (tx) => {
|
|
912
949
|
await deleteChildTables(tx, registration.childTables, docId);
|
|
913
950
|
await deleteJoinTables(tx, registration.joinTables, docId);
|
|
914
951
|
await tx.delete(npMediaRefs).where(
|
|
@@ -938,7 +975,12 @@ async function deleteDocumentImpl(collection, docId, actor) {
|
|
|
938
975
|
sql2`${eq(getTableColumn(npReports, "targetType"), collection)} and ${eq(getTableColumn(npReports, "targetId"), docId)}`
|
|
939
976
|
);
|
|
940
977
|
await tx.delete(table).where(eq(getTableColumn(table, "id"), docId));
|
|
941
|
-
}
|
|
978
|
+
};
|
|
979
|
+
if (options?.tx) {
|
|
980
|
+
await cascade(options.tx);
|
|
981
|
+
} else {
|
|
982
|
+
await dbHandle.transaction(cascade);
|
|
983
|
+
}
|
|
942
984
|
const postCommitCtx = { collection, documentId: docId, operation: "delete" };
|
|
943
985
|
await runPostCommit(
|
|
944
986
|
"enqueue:content:afterDelete",
|
|
@@ -1794,7 +1836,7 @@ function createPluginRuntimeContext(options) {
|
|
|
1794
1836
|
return row.value;
|
|
1795
1837
|
},
|
|
1796
1838
|
async getPlugin() {
|
|
1797
|
-
const { getPluginConfig } = await import("./config-
|
|
1839
|
+
const { getPluginConfig } = await import("./config-CO6TXCA6.js");
|
|
1798
1840
|
const value = await getPluginConfig(pluginId);
|
|
1799
1841
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
1800
1842
|
return value;
|
|
@@ -1802,8 +1844,8 @@ function createPluginRuntimeContext(options) {
|
|
|
1802
1844
|
return {};
|
|
1803
1845
|
},
|
|
1804
1846
|
async setPlugin(data) {
|
|
1805
|
-
const { setPluginConfig } = await import("./config-
|
|
1806
|
-
const { getPluginRegistration: getPluginRegistration2 } = await import("./host-
|
|
1847
|
+
const { setPluginConfig } = await import("./config-CO6TXCA6.js");
|
|
1848
|
+
const { getPluginRegistration: getPluginRegistration2 } = await import("./host-HDRI7WIP.js");
|
|
1807
1849
|
const reg = getPluginRegistration2(pluginId);
|
|
1808
1850
|
if (reg?.configSchema) {
|
|
1809
1851
|
await setPluginConfig(pluginId, data, null);
|
|
@@ -2034,7 +2076,7 @@ function invalidatePluginEnabled(pluginId) {
|
|
|
2034
2076
|
var fetchOverride = null;
|
|
2035
2077
|
|
|
2036
2078
|
// src/plugins/compat.ts
|
|
2037
|
-
var FRAMEWORK_VERSION_FROM_PACKAGE = true ? "0.3.
|
|
2079
|
+
var FRAMEWORK_VERSION_FROM_PACKAGE = true ? "0.3.3" : "0.0.0-dev";
|
|
2038
2080
|
var frameworkVersion = FRAMEWORK_VERSION_FROM_PACKAGE;
|
|
2039
2081
|
function getFrameworkVersion() {
|
|
2040
2082
|
return frameworkVersion;
|
|
@@ -2184,7 +2226,7 @@ function insertSortedByPriority(list, entry) {
|
|
|
2184
2226
|
list.sort((a, b) => a.priority - b.priority);
|
|
2185
2227
|
}
|
|
2186
2228
|
async function loadPluginConfig(pluginId) {
|
|
2187
|
-
const { getPluginConfig } = await import("./config-
|
|
2229
|
+
const { getPluginConfig } = await import("./config-CO6TXCA6.js");
|
|
2188
2230
|
const value = await getPluginConfig(pluginId);
|
|
2189
2231
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
2190
2232
|
return value;
|
|
@@ -2684,6 +2726,7 @@ export {
|
|
|
2684
2726
|
getRegisteredPluginSchedules,
|
|
2685
2727
|
runPluginScheduledTask,
|
|
2686
2728
|
resetPlugins,
|
|
2729
|
+
withDeferredPostCommit,
|
|
2687
2730
|
saveDocument,
|
|
2688
2731
|
updateMemberDocument,
|
|
2689
2732
|
createMemberDocument,
|
|
@@ -2694,4 +2737,4 @@ export {
|
|
|
2694
2737
|
findDocuments,
|
|
2695
2738
|
getDocumentById
|
|
2696
2739
|
};
|
|
2697
|
-
//# sourceMappingURL=chunk-
|
|
2740
|
+
//# sourceMappingURL=chunk-MXOHWU2P.js.map
|