@dyrected/core 2.5.23 → 2.5.25
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/app-BibuoHQG.d.cts +1764 -0
- package/dist/app-BibuoHQG.d.ts +1764 -0
- package/dist/app-aW2FMuYM.d.cts +1759 -0
- package/dist/app-aW2FMuYM.d.ts +1759 -0
- package/dist/chunk-4EDMZAM5.js +2692 -0
- package/dist/chunk-FDQYPPG3.js +2698 -0
- package/dist/chunk-NKDX67AW.js +2698 -0
- package/dist/index.cjs +134 -45
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +1 -1
- package/dist/server.cjs +134 -45
- package/dist/server.d.cts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1195,7 +1195,7 @@ async function runCollectionHooks(hooks, args, options = {}) {
|
|
|
1195
1195
|
}
|
|
1196
1196
|
return currentPayload;
|
|
1197
1197
|
}
|
|
1198
|
-
async function executeFieldBeforeChange(fields, data, originalDoc, user) {
|
|
1198
|
+
async function executeFieldBeforeChange(fields, data, originalDoc, user, db) {
|
|
1199
1199
|
if (!data || typeof data !== "object") return data;
|
|
1200
1200
|
const result = { ...data };
|
|
1201
1201
|
for (const field of fields) {
|
|
@@ -1209,7 +1209,8 @@ async function executeFieldBeforeChange(fields, data, originalDoc, user) {
|
|
|
1209
1209
|
value: updatedValue,
|
|
1210
1210
|
originalDoc: originalDoc ?? void 0,
|
|
1211
1211
|
data: result,
|
|
1212
|
-
user
|
|
1212
|
+
user,
|
|
1213
|
+
db
|
|
1213
1214
|
});
|
|
1214
1215
|
}
|
|
1215
1216
|
result[field.name] = updatedValue;
|
|
@@ -1220,7 +1221,8 @@ async function executeFieldBeforeChange(fields, data, originalDoc, user) {
|
|
|
1220
1221
|
field.fields,
|
|
1221
1222
|
updatedValue,
|
|
1222
1223
|
origValue,
|
|
1223
|
-
user
|
|
1224
|
+
user,
|
|
1225
|
+
db
|
|
1224
1226
|
);
|
|
1225
1227
|
} else if (field.type === "array" && field.fields && Array.isArray(updatedValue)) {
|
|
1226
1228
|
const arrayResult = [];
|
|
@@ -1228,7 +1230,7 @@ async function executeFieldBeforeChange(fields, data, originalDoc, user) {
|
|
|
1228
1230
|
const item = updatedValue[i];
|
|
1229
1231
|
const origItem = Array.isArray(origValue) ? origValue[i] : null;
|
|
1230
1232
|
arrayResult.push(
|
|
1231
|
-
await executeFieldBeforeChange(field.fields, item, origItem, user)
|
|
1233
|
+
await executeFieldBeforeChange(field.fields, item, origItem, user, db)
|
|
1232
1234
|
);
|
|
1233
1235
|
}
|
|
1234
1236
|
result[field.name] = arrayResult;
|
|
@@ -1246,7 +1248,8 @@ async function executeFieldBeforeChange(fields, data, originalDoc, user) {
|
|
|
1246
1248
|
blockConfig.fields,
|
|
1247
1249
|
blockData,
|
|
1248
1250
|
origBlock,
|
|
1249
|
-
user
|
|
1251
|
+
user,
|
|
1252
|
+
db
|
|
1250
1253
|
)
|
|
1251
1254
|
);
|
|
1252
1255
|
} else {
|
|
@@ -1259,7 +1262,7 @@ async function executeFieldBeforeChange(fields, data, originalDoc, user) {
|
|
|
1259
1262
|
}
|
|
1260
1263
|
return result;
|
|
1261
1264
|
}
|
|
1262
|
-
async function executeFieldAfterRead(fields, doc, user) {
|
|
1265
|
+
async function executeFieldAfterRead(fields, doc, user, db) {
|
|
1263
1266
|
if (!doc || typeof doc !== "object") return doc;
|
|
1264
1267
|
const result = { ...doc };
|
|
1265
1268
|
for (const field of fields) {
|
|
@@ -1271,7 +1274,8 @@ async function executeFieldAfterRead(fields, doc, user) {
|
|
|
1271
1274
|
updatedValue = await hook({
|
|
1272
1275
|
value: updatedValue,
|
|
1273
1276
|
doc: result,
|
|
1274
|
-
user
|
|
1277
|
+
user,
|
|
1278
|
+
db
|
|
1275
1279
|
});
|
|
1276
1280
|
}
|
|
1277
1281
|
result[field.name] = updatedValue;
|
|
@@ -1281,7 +1285,8 @@ async function executeFieldAfterRead(fields, doc, user) {
|
|
|
1281
1285
|
result[field.name] = await executeFieldAfterRead(
|
|
1282
1286
|
field.fields,
|
|
1283
1287
|
updatedValue,
|
|
1284
|
-
user
|
|
1288
|
+
user,
|
|
1289
|
+
db
|
|
1285
1290
|
);
|
|
1286
1291
|
} else if (field.type === "array" && field.fields && Array.isArray(updatedValue)) {
|
|
1287
1292
|
const arrayResult = [];
|
|
@@ -1290,7 +1295,8 @@ async function executeFieldAfterRead(fields, doc, user) {
|
|
|
1290
1295
|
await executeFieldAfterRead(
|
|
1291
1296
|
field.fields,
|
|
1292
1297
|
item,
|
|
1293
|
-
user
|
|
1298
|
+
user,
|
|
1299
|
+
db
|
|
1294
1300
|
)
|
|
1295
1301
|
);
|
|
1296
1302
|
}
|
|
@@ -1307,7 +1313,8 @@ async function executeFieldAfterRead(fields, doc, user) {
|
|
|
1307
1313
|
await executeFieldAfterRead(
|
|
1308
1314
|
blockConfig.fields,
|
|
1309
1315
|
typedBlock,
|
|
1310
|
-
user
|
|
1316
|
+
user,
|
|
1317
|
+
db
|
|
1311
1318
|
)
|
|
1312
1319
|
);
|
|
1313
1320
|
} else {
|
|
@@ -1390,7 +1397,33 @@ var PopulationService = class {
|
|
|
1390
1397
|
}
|
|
1391
1398
|
const populatedDoc = { ...data };
|
|
1392
1399
|
for (const field of fields) {
|
|
1393
|
-
if (field.type === "join")
|
|
1400
|
+
if (field.type === "join" && field.collection && field.on && currentDepth === 0) {
|
|
1401
|
+
const targetCollection = this.collections.find((c) => c.slug === field.collection);
|
|
1402
|
+
if (targetCollection) {
|
|
1403
|
+
const docId = populatedDoc.id;
|
|
1404
|
+
if (docId) {
|
|
1405
|
+
const where = { [field.on]: { equals: docId } };
|
|
1406
|
+
const joinLimit = field.limit ?? 10;
|
|
1407
|
+
const result = await this.db.find({
|
|
1408
|
+
collection: field.collection,
|
|
1409
|
+
where,
|
|
1410
|
+
limit: joinLimit
|
|
1411
|
+
});
|
|
1412
|
+
const populatedDocs = await this.populate({
|
|
1413
|
+
data: result.docs.map((doc) => DefaultsService.apply(targetCollection.fields, doc)),
|
|
1414
|
+
fields: targetCollection.fields,
|
|
1415
|
+
currentDepth: 1,
|
|
1416
|
+
maxDepth
|
|
1417
|
+
});
|
|
1418
|
+
populatedDoc[field.name] = {
|
|
1419
|
+
docs: populatedDocs,
|
|
1420
|
+
hasNextPage: result.page * result.limit < result.total,
|
|
1421
|
+
totalDocs: result.total
|
|
1422
|
+
};
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
continue;
|
|
1426
|
+
}
|
|
1394
1427
|
if (field.type === "row" && field.fields) {
|
|
1395
1428
|
const rowPopulated = await this.populate({ data, fields: field.fields, currentDepth, maxDepth });
|
|
1396
1429
|
Object.assign(populatedDoc, rowPopulated);
|
|
@@ -1549,6 +1582,23 @@ async function verifyPassword(plain, stored) {
|
|
|
1549
1582
|
return (0, import_node_crypto.timingSafeEqual)(derivedKey, storedBuffer);
|
|
1550
1583
|
}
|
|
1551
1584
|
|
|
1585
|
+
// src/utils/readonly-db.ts
|
|
1586
|
+
var WRITE_METHODS = ["create", "update", "delete", "updateGlobal", "execute"];
|
|
1587
|
+
function createReadonlyDb(db) {
|
|
1588
|
+
return new Proxy(db, {
|
|
1589
|
+
get(target, prop) {
|
|
1590
|
+
if (WRITE_METHODS.includes(prop)) {
|
|
1591
|
+
return () => {
|
|
1592
|
+
throw new Error(
|
|
1593
|
+
`[dyrected] Write operation "${String(prop)}" is not allowed in this hook phase. Use afterChange/afterDelete hooks for write operations.`
|
|
1594
|
+
);
|
|
1595
|
+
};
|
|
1596
|
+
}
|
|
1597
|
+
return Reflect.get(target, prop);
|
|
1598
|
+
}
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1552
1602
|
// src/controllers/collection.controller.ts
|
|
1553
1603
|
var CollectionController = class {
|
|
1554
1604
|
collection;
|
|
@@ -1559,6 +1609,7 @@ var CollectionController = class {
|
|
|
1559
1609
|
const config = c.get("config");
|
|
1560
1610
|
const db = config.db;
|
|
1561
1611
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
1612
|
+
const readonlyDb = createReadonlyDb(db);
|
|
1562
1613
|
const limit = Number(c.req.query("limit")) || 10;
|
|
1563
1614
|
const page = Number(c.req.query("page")) || 1;
|
|
1564
1615
|
const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 2;
|
|
@@ -1575,7 +1626,8 @@ var CollectionController = class {
|
|
|
1575
1626
|
const beforeReadResult = await runCollectionHooks(this.collection.hooks?.beforeRead, {
|
|
1576
1627
|
req: c.req,
|
|
1577
1628
|
query: where,
|
|
1578
|
-
user
|
|
1629
|
+
user,
|
|
1630
|
+
db: readonlyDb
|
|
1579
1631
|
});
|
|
1580
1632
|
if (beforeReadResult !== void 0) {
|
|
1581
1633
|
where = beforeReadResult;
|
|
@@ -1606,9 +1658,10 @@ var CollectionController = class {
|
|
|
1606
1658
|
const docWithCollectionHooks = await runCollectionHooks(this.collection.hooks?.afterRead, {
|
|
1607
1659
|
doc,
|
|
1608
1660
|
req: c.req,
|
|
1609
|
-
user
|
|
1661
|
+
user,
|
|
1662
|
+
db: readonlyDb
|
|
1610
1663
|
});
|
|
1611
|
-
const docWithFieldHooks = await executeFieldAfterRead(this.collection.fields, docWithCollectionHooks, user);
|
|
1664
|
+
const docWithFieldHooks = await executeFieldAfterRead(this.collection.fields, docWithCollectionHooks, user, readonlyDb);
|
|
1612
1665
|
processedDocs.push(docWithFieldHooks);
|
|
1613
1666
|
}
|
|
1614
1667
|
result.docs = processedDocs;
|
|
@@ -1622,6 +1675,7 @@ var CollectionController = class {
|
|
|
1622
1675
|
const config = c.get("config");
|
|
1623
1676
|
const db = config.db;
|
|
1624
1677
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
1678
|
+
const readonlyDb = createReadonlyDb(db);
|
|
1625
1679
|
const id = c.req.param("id");
|
|
1626
1680
|
const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 10;
|
|
1627
1681
|
const user = c.get("user");
|
|
@@ -1632,9 +1686,10 @@ var CollectionController = class {
|
|
|
1632
1686
|
const docWithCollectionHooks = await runCollectionHooks(this.collection.hooks?.afterRead, {
|
|
1633
1687
|
doc: docWithDefaults,
|
|
1634
1688
|
req: c.req,
|
|
1635
|
-
user
|
|
1689
|
+
user,
|
|
1690
|
+
db: readonlyDb
|
|
1636
1691
|
});
|
|
1637
|
-
const docWithFieldHooks = await executeFieldAfterRead(this.collection.fields, docWithCollectionHooks, user);
|
|
1692
|
+
const docWithFieldHooks = await executeFieldAfterRead(this.collection.fields, docWithCollectionHooks, user, readonlyDb);
|
|
1638
1693
|
if (depth > 0 && docWithFieldHooks) {
|
|
1639
1694
|
const populationService = new PopulationService(db, config.collections);
|
|
1640
1695
|
const populatedDoc = await populationService.populate({
|
|
@@ -1651,6 +1706,7 @@ var CollectionController = class {
|
|
|
1651
1706
|
const config = c.get("config");
|
|
1652
1707
|
const db = config.db;
|
|
1653
1708
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
1709
|
+
const readonlyDb = createReadonlyDb(db);
|
|
1654
1710
|
const contentType = c.req.header("Content-Type") || "";
|
|
1655
1711
|
if (contentType.toLowerCase().includes("multipart/form-data")) {
|
|
1656
1712
|
return this.upload(c);
|
|
@@ -1668,12 +1724,13 @@ var CollectionController = class {
|
|
|
1668
1724
|
if (this.collection.auth && data.password) {
|
|
1669
1725
|
data.password = await hashPassword(data.password);
|
|
1670
1726
|
}
|
|
1671
|
-
data = await executeFieldBeforeChange(this.collection.fields, data, null, user);
|
|
1727
|
+
data = await executeFieldBeforeChange(this.collection.fields, data, null, user, readonlyDb);
|
|
1672
1728
|
data = await runCollectionHooks(this.collection.hooks?.beforeChange, {
|
|
1673
1729
|
data,
|
|
1674
1730
|
req: c.req,
|
|
1675
1731
|
user,
|
|
1676
|
-
operation: "create"
|
|
1732
|
+
operation: "create",
|
|
1733
|
+
db: readonlyDb
|
|
1677
1734
|
});
|
|
1678
1735
|
const doc = await db.create({ collection: this.collection.slug, data });
|
|
1679
1736
|
if (this.collection.audit && db) {
|
|
@@ -1690,20 +1747,25 @@ var CollectionController = class {
|
|
|
1690
1747
|
doc,
|
|
1691
1748
|
user,
|
|
1692
1749
|
req: c.req,
|
|
1693
|
-
operation: "create"
|
|
1750
|
+
operation: "create",
|
|
1751
|
+
db
|
|
1694
1752
|
}, { isolated: true });
|
|
1695
1753
|
const readDoc = await runCollectionHooks(this.collection.hooks?.afterRead, {
|
|
1696
1754
|
doc,
|
|
1697
1755
|
req: c.req,
|
|
1698
|
-
user
|
|
1756
|
+
user,
|
|
1757
|
+
db: readonlyDb
|
|
1699
1758
|
});
|
|
1700
|
-
const finalDoc = await executeFieldAfterRead(this.collection.fields, readDoc, user);
|
|
1759
|
+
const finalDoc = await executeFieldAfterRead(this.collection.fields, readDoc, user, readonlyDb);
|
|
1701
1760
|
return c.json(finalDoc, 201);
|
|
1702
1761
|
}
|
|
1703
1762
|
async upload(c) {
|
|
1704
1763
|
const config = c.get("config");
|
|
1705
1764
|
const storage = config.storage;
|
|
1706
1765
|
if (!storage) return c.json({ message: "Storage not configured" }, 500);
|
|
1766
|
+
const db = config.db;
|
|
1767
|
+
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
1768
|
+
const readonlyDb = createReadonlyDb(db);
|
|
1707
1769
|
const formData = await c.req.formData();
|
|
1708
1770
|
const file = formData.get("file");
|
|
1709
1771
|
if (!file) return c.json({ message: "No file uploaded" }, 400);
|
|
@@ -1733,14 +1795,15 @@ var CollectionController = class {
|
|
|
1733
1795
|
createdBy: user?.sub ?? null,
|
|
1734
1796
|
updatedBy: user?.sub ?? null
|
|
1735
1797
|
};
|
|
1736
|
-
data = await executeFieldBeforeChange(this.collection.fields, data, null, user);
|
|
1798
|
+
data = await executeFieldBeforeChange(this.collection.fields, data, null, user, readonlyDb);
|
|
1737
1799
|
data = await runCollectionHooks(this.collection.hooks?.beforeChange, {
|
|
1738
1800
|
data,
|
|
1739
1801
|
req: c.req,
|
|
1740
1802
|
user,
|
|
1741
|
-
operation: "create"
|
|
1803
|
+
operation: "create",
|
|
1804
|
+
db: readonlyDb
|
|
1742
1805
|
});
|
|
1743
|
-
const doc = await
|
|
1806
|
+
const doc = await db.create({
|
|
1744
1807
|
collection: this.collection.slug,
|
|
1745
1808
|
data
|
|
1746
1809
|
});
|
|
@@ -1748,20 +1811,23 @@ var CollectionController = class {
|
|
|
1748
1811
|
doc,
|
|
1749
1812
|
user,
|
|
1750
1813
|
req: c.req,
|
|
1751
|
-
operation: "create"
|
|
1814
|
+
operation: "create",
|
|
1815
|
+
db
|
|
1752
1816
|
}, { isolated: true });
|
|
1753
1817
|
const readDoc = await runCollectionHooks(this.collection.hooks?.afterRead, {
|
|
1754
1818
|
doc,
|
|
1755
1819
|
req: c.req,
|
|
1756
|
-
user
|
|
1820
|
+
user,
|
|
1821
|
+
db: readonlyDb
|
|
1757
1822
|
});
|
|
1758
|
-
const finalDoc = await executeFieldAfterRead(this.collection.fields, readDoc, user);
|
|
1823
|
+
const finalDoc = await executeFieldAfterRead(this.collection.fields, readDoc, user, readonlyDb);
|
|
1759
1824
|
return c.json(finalDoc, 201);
|
|
1760
1825
|
}
|
|
1761
1826
|
async update(c) {
|
|
1762
1827
|
const config = c.get("config");
|
|
1763
1828
|
const db = config.db;
|
|
1764
1829
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
1830
|
+
const readonlyDb = createReadonlyDb(db);
|
|
1765
1831
|
const id = c.req.param("id");
|
|
1766
1832
|
if (!id) return c.json({ message: "Missing ID" }, 400);
|
|
1767
1833
|
const body = await c.req.json();
|
|
@@ -1782,13 +1848,14 @@ var CollectionController = class {
|
|
|
1782
1848
|
if (this.collection.audit) {
|
|
1783
1849
|
before = originalDoc;
|
|
1784
1850
|
}
|
|
1785
|
-
data = await executeFieldBeforeChange(this.collection.fields, data, originalDoc, user);
|
|
1851
|
+
data = await executeFieldBeforeChange(this.collection.fields, data, originalDoc, user, readonlyDb);
|
|
1786
1852
|
data = await runCollectionHooks(this.collection.hooks?.beforeChange, {
|
|
1787
1853
|
data,
|
|
1788
1854
|
doc: originalDoc,
|
|
1789
1855
|
req: c.req,
|
|
1790
1856
|
user,
|
|
1791
|
-
operation: "update"
|
|
1857
|
+
operation: "update",
|
|
1858
|
+
db: readonlyDb
|
|
1792
1859
|
});
|
|
1793
1860
|
const doc = await db.update({ collection: this.collection.slug, id, data });
|
|
1794
1861
|
if (this.collection.audit && db) {
|
|
@@ -1806,14 +1873,16 @@ var CollectionController = class {
|
|
|
1806
1873
|
previousDoc: originalDoc,
|
|
1807
1874
|
user,
|
|
1808
1875
|
req: c.req,
|
|
1809
|
-
operation: "update"
|
|
1876
|
+
operation: "update",
|
|
1877
|
+
db
|
|
1810
1878
|
}, { isolated: true });
|
|
1811
1879
|
const readDoc = await runCollectionHooks(this.collection.hooks?.afterRead, {
|
|
1812
1880
|
doc,
|
|
1813
1881
|
req: c.req,
|
|
1814
|
-
user
|
|
1882
|
+
user,
|
|
1883
|
+
db: readonlyDb
|
|
1815
1884
|
});
|
|
1816
|
-
const finalDoc = await executeFieldAfterRead(this.collection.fields, readDoc, user);
|
|
1885
|
+
const finalDoc = await executeFieldAfterRead(this.collection.fields, readDoc, user, readonlyDb);
|
|
1817
1886
|
return c.json(finalDoc);
|
|
1818
1887
|
}
|
|
1819
1888
|
/**
|
|
@@ -1891,6 +1960,7 @@ var CollectionController = class {
|
|
|
1891
1960
|
const config = c.get("config");
|
|
1892
1961
|
const db = config.db;
|
|
1893
1962
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
1963
|
+
const readonlyDb = createReadonlyDb(db);
|
|
1894
1964
|
const id = c.req.param("id");
|
|
1895
1965
|
if (!id) return c.json({ message: "Missing ID" }, 400);
|
|
1896
1966
|
const user = c.get("user");
|
|
@@ -1904,7 +1974,8 @@ var CollectionController = class {
|
|
|
1904
1974
|
id,
|
|
1905
1975
|
doc,
|
|
1906
1976
|
user,
|
|
1907
|
-
req: c.req
|
|
1977
|
+
req: c.req,
|
|
1978
|
+
db: readonlyDb
|
|
1908
1979
|
});
|
|
1909
1980
|
await db.delete({ collection: this.collection.slug, id });
|
|
1910
1981
|
if (this.collection.audit && db) {
|
|
@@ -1921,7 +1992,8 @@ var CollectionController = class {
|
|
|
1921
1992
|
id,
|
|
1922
1993
|
doc,
|
|
1923
1994
|
user,
|
|
1924
|
-
req: c.req
|
|
1995
|
+
req: c.req,
|
|
1996
|
+
db
|
|
1925
1997
|
}, { isolated: true });
|
|
1926
1998
|
return c.json({ message: "Deleted" });
|
|
1927
1999
|
}
|
|
@@ -1929,6 +2001,7 @@ var CollectionController = class {
|
|
|
1929
2001
|
const config = c.get("config");
|
|
1930
2002
|
const db = config.db;
|
|
1931
2003
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
2004
|
+
const readonlyDb = createReadonlyDb(db);
|
|
1932
2005
|
const user = c.get("user");
|
|
1933
2006
|
let ids = [];
|
|
1934
2007
|
try {
|
|
@@ -1960,7 +2033,8 @@ var CollectionController = class {
|
|
|
1960
2033
|
id,
|
|
1961
2034
|
doc,
|
|
1962
2035
|
user,
|
|
1963
|
-
req: c.req
|
|
2036
|
+
req: c.req,
|
|
2037
|
+
db: readonlyDb
|
|
1964
2038
|
});
|
|
1965
2039
|
await db.delete({ collection: this.collection.slug, id });
|
|
1966
2040
|
deleted.push(id);
|
|
@@ -1978,7 +2052,8 @@ var CollectionController = class {
|
|
|
1978
2052
|
id,
|
|
1979
2053
|
doc,
|
|
1980
2054
|
user,
|
|
1981
|
-
req: c.req
|
|
2055
|
+
req: c.req,
|
|
2056
|
+
db
|
|
1982
2057
|
}, { isolated: true });
|
|
1983
2058
|
} catch (err) {
|
|
1984
2059
|
failed.push({ id, error: err?.message ?? "Unknown error" });
|
|
@@ -2023,13 +2098,15 @@ var GlobalController = class {
|
|
|
2023
2098
|
const config = c.get("config");
|
|
2024
2099
|
const db = config.db;
|
|
2025
2100
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
2101
|
+
const readonlyDb = createReadonlyDb(db);
|
|
2026
2102
|
const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 10;
|
|
2027
2103
|
const user = c.get("user");
|
|
2028
2104
|
let query = void 0;
|
|
2029
2105
|
const beforeReadResult = await runCollectionHooks(this.global.hooks?.beforeRead, {
|
|
2030
2106
|
req: c.req,
|
|
2031
2107
|
query,
|
|
2032
|
-
user
|
|
2108
|
+
user,
|
|
2109
|
+
db: readonlyDb
|
|
2033
2110
|
});
|
|
2034
2111
|
if (beforeReadResult !== void 0) {
|
|
2035
2112
|
query = beforeReadResult;
|
|
@@ -2045,9 +2122,10 @@ var GlobalController = class {
|
|
|
2045
2122
|
const docWithCollectionHooks = await runCollectionHooks(this.global.hooks?.afterRead, {
|
|
2046
2123
|
doc: dataWithDefaults,
|
|
2047
2124
|
req: c.req,
|
|
2048
|
-
user
|
|
2125
|
+
user,
|
|
2126
|
+
db: readonlyDb
|
|
2049
2127
|
});
|
|
2050
|
-
const docWithFieldHooks = await executeFieldAfterRead(this.global.fields, docWithCollectionHooks, user);
|
|
2128
|
+
const docWithFieldHooks = await executeFieldAfterRead(this.global.fields, docWithCollectionHooks, user, readonlyDb);
|
|
2051
2129
|
if (depth > 0 && docWithFieldHooks) {
|
|
2052
2130
|
const populationService = new PopulationService(db, config.collections);
|
|
2053
2131
|
const populatedData = await populationService.populate({
|
|
@@ -2061,18 +2139,21 @@ var GlobalController = class {
|
|
|
2061
2139
|
return c.json(docWithFieldHooks);
|
|
2062
2140
|
}
|
|
2063
2141
|
async update(c) {
|
|
2064
|
-
const
|
|
2142
|
+
const config = c.get("config");
|
|
2143
|
+
const db = config.db;
|
|
2065
2144
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
2145
|
+
const readonlyDb = createReadonlyDb(db);
|
|
2066
2146
|
const body = await c.req.json();
|
|
2067
2147
|
const user = c.get("user");
|
|
2068
2148
|
const originalDoc = await db.getGlobal({ slug: this.global.slug }) || {};
|
|
2069
|
-
let data = await executeFieldBeforeChange(this.global.fields, body, originalDoc, user);
|
|
2149
|
+
let data = await executeFieldBeforeChange(this.global.fields, body, originalDoc, user, readonlyDb);
|
|
2070
2150
|
data = await runCollectionHooks(this.global.hooks?.beforeChange, {
|
|
2071
2151
|
data,
|
|
2072
2152
|
doc: originalDoc,
|
|
2073
2153
|
req: c.req,
|
|
2074
2154
|
user,
|
|
2075
|
-
operation: "update"
|
|
2155
|
+
operation: "update",
|
|
2156
|
+
db: readonlyDb
|
|
2076
2157
|
});
|
|
2077
2158
|
const updated = await db.updateGlobal({ slug: this.global.slug, data });
|
|
2078
2159
|
await runCollectionHooks(this.global.hooks?.afterChange, {
|
|
@@ -2080,14 +2161,16 @@ var GlobalController = class {
|
|
|
2080
2161
|
previousDoc: originalDoc,
|
|
2081
2162
|
user,
|
|
2082
2163
|
req: c.req,
|
|
2083
|
-
operation: "update"
|
|
2164
|
+
operation: "update",
|
|
2165
|
+
db
|
|
2084
2166
|
}, { isolated: true });
|
|
2085
2167
|
const readDoc = await runCollectionHooks(this.global.hooks?.afterRead, {
|
|
2086
2168
|
doc: updated,
|
|
2087
2169
|
req: c.req,
|
|
2088
|
-
user
|
|
2170
|
+
user,
|
|
2171
|
+
db: readonlyDb
|
|
2089
2172
|
});
|
|
2090
|
-
const finalDoc = await executeFieldAfterRead(this.global.fields, readDoc, user);
|
|
2173
|
+
const finalDoc = await executeFieldAfterRead(this.global.fields, readDoc, user, readonlyDb);
|
|
2091
2174
|
return c.json(finalDoc);
|
|
2092
2175
|
}
|
|
2093
2176
|
async seed(c) {
|
|
@@ -3336,6 +3419,9 @@ function registerRoutes(app, config) {
|
|
|
3336
3419
|
hasMany: f.hasMany,
|
|
3337
3420
|
fields: f.fields,
|
|
3338
3421
|
blocks: f.blocks,
|
|
3422
|
+
collection: f.collection,
|
|
3423
|
+
on: f.on,
|
|
3424
|
+
limit: f.limit,
|
|
3339
3425
|
admin: f.admin,
|
|
3340
3426
|
access: {
|
|
3341
3427
|
read: await serializeAccess(f.access?.read),
|
|
@@ -3364,6 +3450,9 @@ function registerRoutes(app, config) {
|
|
|
3364
3450
|
hasMany: f.hasMany,
|
|
3365
3451
|
fields: f.fields,
|
|
3366
3452
|
blocks: f.blocks,
|
|
3453
|
+
collection: f.collection,
|
|
3454
|
+
on: f.on,
|
|
3455
|
+
limit: f.limit,
|
|
3367
3456
|
admin: f.admin,
|
|
3368
3457
|
access: {
|
|
3369
3458
|
read: await serializeAccess(f.access?.read),
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as DyrectedConfig, F as Field, C as CollectionConfig, P as Prettify, I as InferDocShape, S as SystemDocFields, A as AuthDocFields, U as UploadDocFields, G as GlobalConfig } from './app-
|
|
2
|
-
export { a as AccessFunction, b as AdminConfig, c as AuthenticatedUser, B as BaseDocument, d as Block, e as CollectionAfterChangeHook, f as CollectionAfterDeleteHook, g as CollectionAfterReadHook, h as CollectionBeforeChangeHook, i as CollectionBeforeDeleteHook, j as CollectionBeforeReadHook, k as DatabaseAdapter, l as DynamicOptionItem, m as DynamicOptionsConfig, n as DynamicOptionsResolver, o as DynamicOptionsResolverArgs, p as DyrectedContext, q as FieldAfterReadHook, r as FieldBeforeChangeHook, s as FieldHook, t as FieldType, u as FileData, v as GlobalAfterChangeHook, w as GlobalAfterReadHook, x as GlobalBeforeChangeHook, y as GlobalBeforeReadHook, H as HookFunction, z as HookRequestContext, E as ImageService, J as PaginatedResult, K as StorageAdapter, L as UploadConfig, M as createDyrectedApp } from './app-
|
|
1
|
+
import { D as DyrectedConfig, F as Field, C as CollectionConfig, P as Prettify, I as InferDocShape, S as SystemDocFields, A as AuthDocFields, U as UploadDocFields, G as GlobalConfig } from './app-BibuoHQG.cjs';
|
|
2
|
+
export { a as AccessFunction, b as AdminConfig, c as AuthenticatedUser, B as BaseDocument, d as Block, e as CollectionAfterChangeHook, f as CollectionAfterDeleteHook, g as CollectionAfterReadHook, h as CollectionBeforeChangeHook, i as CollectionBeforeDeleteHook, j as CollectionBeforeReadHook, k as DatabaseAdapter, l as DynamicOptionItem, m as DynamicOptionsConfig, n as DynamicOptionsResolver, o as DynamicOptionsResolverArgs, p as DyrectedContext, q as FieldAfterReadHook, r as FieldBeforeChangeHook, s as FieldHook, t as FieldType, u as FileData, v as GlobalAfterChangeHook, w as GlobalAfterReadHook, x as GlobalBeforeChangeHook, y as GlobalBeforeReadHook, H as HookFunction, z as HookRequestContext, E as ImageService, J as PaginatedResult, R as ReadonlyDatabaseAdapter, K as StorageAdapter, L as UploadConfig, M as createDyrectedApp } from './app-BibuoHQG.cjs';
|
|
3
3
|
import 'hono/types';
|
|
4
4
|
import 'hono';
|
|
5
5
|
|
|
@@ -102,6 +102,7 @@ declare function runCollectionHooks(hooks: AnyHookFn[] | undefined, args: {
|
|
|
102
102
|
doc?: unknown;
|
|
103
103
|
user?: unknown;
|
|
104
104
|
req?: unknown;
|
|
105
|
+
db?: unknown;
|
|
105
106
|
operation?: "create" | "update" | "delete";
|
|
106
107
|
[key: string]: unknown;
|
|
107
108
|
}, options?: {
|
|
@@ -113,14 +114,14 @@ declare function runCollectionHooks(hooks: AnyHookFn[] | undefined, args: {
|
|
|
113
114
|
* Traverses `array`, `object`, and `blocks` fields depth-first so that nested
|
|
114
115
|
* field hooks fire on every item automatically.
|
|
115
116
|
*/
|
|
116
|
-
declare function executeFieldBeforeChange(fields: Field[], data: Record<string, unknown>, originalDoc: Record<string, unknown> | null, user: unknown): Promise<Record<string, unknown>>;
|
|
117
|
+
declare function executeFieldBeforeChange(fields: Field[], data: Record<string, unknown>, originalDoc: Record<string, unknown> | null, user: unknown, db?: unknown): Promise<Record<string, unknown>>;
|
|
117
118
|
/**
|
|
118
119
|
* Execute field-level `afterRead` hooks recursively on a document.
|
|
119
120
|
*
|
|
120
121
|
* Traverses `array`, `object`, and `blocks` fields depth-first so that nested
|
|
121
122
|
* field hooks fire on every item automatically.
|
|
122
123
|
*/
|
|
123
|
-
declare function executeFieldAfterRead(fields: Field[], doc: Record<string, unknown>, user: unknown): Promise<Record<string, unknown>>;
|
|
124
|
+
declare function executeFieldAfterRead(fields: Field[], doc: Record<string, unknown>, user: unknown, db?: unknown): Promise<Record<string, unknown>>;
|
|
124
125
|
|
|
125
126
|
/**
|
|
126
127
|
* Define a collection. When called without an explicit type argument, TypeScript
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as DyrectedConfig, F as Field, C as CollectionConfig, P as Prettify, I as InferDocShape, S as SystemDocFields, A as AuthDocFields, U as UploadDocFields, G as GlobalConfig } from './app-
|
|
2
|
-
export { a as AccessFunction, b as AdminConfig, c as AuthenticatedUser, B as BaseDocument, d as Block, e as CollectionAfterChangeHook, f as CollectionAfterDeleteHook, g as CollectionAfterReadHook, h as CollectionBeforeChangeHook, i as CollectionBeforeDeleteHook, j as CollectionBeforeReadHook, k as DatabaseAdapter, l as DynamicOptionItem, m as DynamicOptionsConfig, n as DynamicOptionsResolver, o as DynamicOptionsResolverArgs, p as DyrectedContext, q as FieldAfterReadHook, r as FieldBeforeChangeHook, s as FieldHook, t as FieldType, u as FileData, v as GlobalAfterChangeHook, w as GlobalAfterReadHook, x as GlobalBeforeChangeHook, y as GlobalBeforeReadHook, H as HookFunction, z as HookRequestContext, E as ImageService, J as PaginatedResult, K as StorageAdapter, L as UploadConfig, M as createDyrectedApp } from './app-
|
|
1
|
+
import { D as DyrectedConfig, F as Field, C as CollectionConfig, P as Prettify, I as InferDocShape, S as SystemDocFields, A as AuthDocFields, U as UploadDocFields, G as GlobalConfig } from './app-BibuoHQG.js';
|
|
2
|
+
export { a as AccessFunction, b as AdminConfig, c as AuthenticatedUser, B as BaseDocument, d as Block, e as CollectionAfterChangeHook, f as CollectionAfterDeleteHook, g as CollectionAfterReadHook, h as CollectionBeforeChangeHook, i as CollectionBeforeDeleteHook, j as CollectionBeforeReadHook, k as DatabaseAdapter, l as DynamicOptionItem, m as DynamicOptionsConfig, n as DynamicOptionsResolver, o as DynamicOptionsResolverArgs, p as DyrectedContext, q as FieldAfterReadHook, r as FieldBeforeChangeHook, s as FieldHook, t as FieldType, u as FileData, v as GlobalAfterChangeHook, w as GlobalAfterReadHook, x as GlobalBeforeChangeHook, y as GlobalBeforeReadHook, H as HookFunction, z as HookRequestContext, E as ImageService, J as PaginatedResult, R as ReadonlyDatabaseAdapter, K as StorageAdapter, L as UploadConfig, M as createDyrectedApp } from './app-BibuoHQG.js';
|
|
3
3
|
import 'hono/types';
|
|
4
4
|
import 'hono';
|
|
5
5
|
|
|
@@ -102,6 +102,7 @@ declare function runCollectionHooks(hooks: AnyHookFn[] | undefined, args: {
|
|
|
102
102
|
doc?: unknown;
|
|
103
103
|
user?: unknown;
|
|
104
104
|
req?: unknown;
|
|
105
|
+
db?: unknown;
|
|
105
106
|
operation?: "create" | "update" | "delete";
|
|
106
107
|
[key: string]: unknown;
|
|
107
108
|
}, options?: {
|
|
@@ -113,14 +114,14 @@ declare function runCollectionHooks(hooks: AnyHookFn[] | undefined, args: {
|
|
|
113
114
|
* Traverses `array`, `object`, and `blocks` fields depth-first so that nested
|
|
114
115
|
* field hooks fire on every item automatically.
|
|
115
116
|
*/
|
|
116
|
-
declare function executeFieldBeforeChange(fields: Field[], data: Record<string, unknown>, originalDoc: Record<string, unknown> | null, user: unknown): Promise<Record<string, unknown>>;
|
|
117
|
+
declare function executeFieldBeforeChange(fields: Field[], data: Record<string, unknown>, originalDoc: Record<string, unknown> | null, user: unknown, db?: unknown): Promise<Record<string, unknown>>;
|
|
117
118
|
/**
|
|
118
119
|
* Execute field-level `afterRead` hooks recursively on a document.
|
|
119
120
|
*
|
|
120
121
|
* Traverses `array`, `object`, and `blocks` fields depth-first so that nested
|
|
121
122
|
* field hooks fire on every item automatically.
|
|
122
123
|
*/
|
|
123
|
-
declare function executeFieldAfterRead(fields: Field[], doc: Record<string, unknown>, user: unknown): Promise<Record<string, unknown>>;
|
|
124
|
+
declare function executeFieldAfterRead(fields: Field[], doc: Record<string, unknown>, user: unknown, db?: unknown): Promise<Record<string, unknown>>;
|
|
124
125
|
|
|
125
126
|
/**
|
|
126
127
|
* Define a collection. When called without an explicit type argument, TypeScript
|
package/dist/index.js
CHANGED