@dnax/core 0.53.0 → 0.54.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/app/ctrl.ts +1 -1
- package/app/hono.ts +4 -5
- package/driver/mongo/rest.ts +180 -87
- package/lib/asyncLocalStorage.ts +5 -1
- package/package.json +1 -1
package/app/ctrl.ts
CHANGED
package/app/hono.ts
CHANGED
|
@@ -295,6 +295,10 @@ function HonoInstance(): typeof app {
|
|
|
295
295
|
}
|
|
296
296
|
const service = getService(name, c.var["tenant-id"]);
|
|
297
297
|
const col = getCollection(collection, c.var["tenant-id"]);
|
|
298
|
+
// Controlle action
|
|
299
|
+
if (!getAction(action)) {
|
|
300
|
+
throw new ContextError(`Action ${action} not found`, 400);
|
|
301
|
+
}
|
|
298
302
|
|
|
299
303
|
useCache = stringToBoolean(useCache, false);
|
|
300
304
|
if (body?.useCache) useCache = stringToBoolean(body.useCache, false);
|
|
@@ -304,11 +308,6 @@ function HonoInstance(): typeof app {
|
|
|
304
308
|
c: c,
|
|
305
309
|
});
|
|
306
310
|
|
|
307
|
-
// Controlle action
|
|
308
|
-
if (!getAction(action)) {
|
|
309
|
-
throw new ContextError(`Action ${action} not found`, 400);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
311
|
if (action == "execToolkit") {
|
|
313
312
|
let tookit = toolkit;
|
|
314
313
|
|
package/driver/mongo/rest.ts
CHANGED
|
@@ -4,7 +4,13 @@ import { getCollection, getKeyFields } from "../../lib/collection";
|
|
|
4
4
|
import { getTenant } from "../../lib/tenant";
|
|
5
5
|
import type { Actions, Collection, Tenant } from "./../../types/index";
|
|
6
6
|
import { isArray, omit } from "radash";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
ChangeStream,
|
|
9
|
+
ClientSession,
|
|
10
|
+
MongoClient,
|
|
11
|
+
ObjectId,
|
|
12
|
+
type FilterOperations,
|
|
13
|
+
} from "mongodb";
|
|
8
14
|
import { contextError, fn, toJson, dotJson, getEntryBykeys } from "../../utils";
|
|
9
15
|
import v, { type Schema } from "joi";
|
|
10
16
|
import type { Context } from "hono";
|
|
@@ -114,7 +120,32 @@ class useRest {
|
|
|
114
120
|
save: async (activityInput) => {
|
|
115
121
|
return await restActivity.save(this.#tenant, activityInput);
|
|
116
122
|
},
|
|
117
|
-
list: async (
|
|
123
|
+
list: async (
|
|
124
|
+
activityFilter
|
|
125
|
+
): Promise<
|
|
126
|
+
{
|
|
127
|
+
[key: string]: any;
|
|
128
|
+
collection: string;
|
|
129
|
+
action: string;
|
|
130
|
+
transaction: boolean;
|
|
131
|
+
internal: boolean;
|
|
132
|
+
ip: string;
|
|
133
|
+
auth: boolean;
|
|
134
|
+
role: string;
|
|
135
|
+
user: string;
|
|
136
|
+
state: any;
|
|
137
|
+
createdAt: string;
|
|
138
|
+
updatedAt: string;
|
|
139
|
+
_id: string;
|
|
140
|
+
data: {
|
|
141
|
+
ids?: string[];
|
|
142
|
+
data?: any;
|
|
143
|
+
id?: string;
|
|
144
|
+
update?: updateParams;
|
|
145
|
+
filter?: any;
|
|
146
|
+
};
|
|
147
|
+
}[]
|
|
148
|
+
> => {
|
|
118
149
|
return await restActivity
|
|
119
150
|
.list(this.#tenant, activityFilter || {})
|
|
120
151
|
.then((e) => e)
|
|
@@ -378,18 +409,6 @@ class useRest {
|
|
|
378
409
|
}),
|
|
379
410
|
});
|
|
380
411
|
}
|
|
381
|
-
restActivity.save(this.#tenant, {
|
|
382
|
-
collection: collection,
|
|
383
|
-
data: {
|
|
384
|
-
input: data,
|
|
385
|
-
},
|
|
386
|
-
transaction: this.#session ? true : false,
|
|
387
|
-
action: "insertOne",
|
|
388
|
-
user:
|
|
389
|
-
sessionStorage()?.get()?.state?.user ||
|
|
390
|
-
sessionStorage()?.get()?.state?.by ||
|
|
391
|
-
null,
|
|
392
|
-
});
|
|
393
412
|
|
|
394
413
|
try {
|
|
395
414
|
col?.cache?.watch({
|
|
@@ -412,6 +431,23 @@ class useRest {
|
|
|
412
431
|
.addDocuments([toJson(data)])
|
|
413
432
|
.catch();
|
|
414
433
|
}
|
|
434
|
+
|
|
435
|
+
// if action done
|
|
436
|
+
restActivity.save(this.#tenant, {
|
|
437
|
+
collection: collection,
|
|
438
|
+
data: {
|
|
439
|
+
data: data,
|
|
440
|
+
id: data?._id,
|
|
441
|
+
},
|
|
442
|
+
transaction: this.#session ? true : false,
|
|
443
|
+
action: "insertOne",
|
|
444
|
+
internal: sessionStorage()?.get() ? false : true,
|
|
445
|
+
ip: sessionStorage()?.get()?._v?.ip,
|
|
446
|
+
auth: sessionStorage()?.get()?.isAuth,
|
|
447
|
+
role: sessionStorage()?.get()?.role!,
|
|
448
|
+
user: sessionStorage()?.get()?.state?.user,
|
|
449
|
+
state: sessionStorage()?.get()?.state,
|
|
450
|
+
});
|
|
415
451
|
return resolve(toJson(data));
|
|
416
452
|
} catch (err) {
|
|
417
453
|
return reject(err);
|
|
@@ -520,18 +556,7 @@ class useRest {
|
|
|
520
556
|
}),
|
|
521
557
|
});
|
|
522
558
|
}
|
|
523
|
-
|
|
524
|
-
collection: collection,
|
|
525
|
-
data: {
|
|
526
|
-
input: toJson(data),
|
|
527
|
-
},
|
|
528
|
-
action: "insertMany",
|
|
529
|
-
transaction: this.#session ? true : false,
|
|
530
|
-
user:
|
|
531
|
-
sessionStorage()?.get().state?.user ||
|
|
532
|
-
sessionStorage()?.get().state?.by ||
|
|
533
|
-
null,
|
|
534
|
-
});
|
|
559
|
+
|
|
535
560
|
try {
|
|
536
561
|
col?.cache?.watch({
|
|
537
562
|
action: "insertMany",
|
|
@@ -551,6 +576,22 @@ class useRest {
|
|
|
551
576
|
.addDocuments(toJson(data))
|
|
552
577
|
.catch();
|
|
553
578
|
}
|
|
579
|
+
// if insertMany done
|
|
580
|
+
restActivity.save(this.#tenant, {
|
|
581
|
+
collection: collection,
|
|
582
|
+
data: {
|
|
583
|
+
data: toJson(data),
|
|
584
|
+
ids: data?.map((e) => e?._id),
|
|
585
|
+
},
|
|
586
|
+
action: "insertMany",
|
|
587
|
+
transaction: this.#session ? true : false,
|
|
588
|
+
internal: sessionStorage()?.get() ? false : true,
|
|
589
|
+
ip: sessionStorage()?.get()?._v?.ip,
|
|
590
|
+
auth: sessionStorage()?.get()?.isAuth,
|
|
591
|
+
role: sessionStorage()?.get()?.role!,
|
|
592
|
+
user: sessionStorage()?.get()?.state?.user,
|
|
593
|
+
state: sessionStorage()?.get()?.state,
|
|
594
|
+
});
|
|
554
595
|
return resolve(toJson(data));
|
|
555
596
|
} catch (err) {
|
|
556
597
|
reject(err);
|
|
@@ -1137,20 +1178,6 @@ class useRest {
|
|
|
1137
1178
|
});
|
|
1138
1179
|
}
|
|
1139
1180
|
|
|
1140
|
-
restActivity.save(this.#tenant, {
|
|
1141
|
-
collection: collection,
|
|
1142
|
-
data: {
|
|
1143
|
-
input: update,
|
|
1144
|
-
id: id,
|
|
1145
|
-
ids: [id],
|
|
1146
|
-
},
|
|
1147
|
-
transaction: this.#session ? true : false,
|
|
1148
|
-
action: "updateOne",
|
|
1149
|
-
user:
|
|
1150
|
-
sessionStorage().get().state?.user ||
|
|
1151
|
-
sessionStorage().get().state?.by ||
|
|
1152
|
-
null,
|
|
1153
|
-
});
|
|
1154
1181
|
try {
|
|
1155
1182
|
col?.cache?.watch({
|
|
1156
1183
|
action: "insertMany",
|
|
@@ -1170,6 +1197,23 @@ class useRest {
|
|
|
1170
1197
|
.updateDocuments([{ ...toJson(result?.doc || {}) }])
|
|
1171
1198
|
.catch();
|
|
1172
1199
|
}
|
|
1200
|
+
// if updateOne done
|
|
1201
|
+
restActivity.save(this.#tenant, {
|
|
1202
|
+
collection: collection,
|
|
1203
|
+
data: {
|
|
1204
|
+
update: update,
|
|
1205
|
+
id: id,
|
|
1206
|
+
ids: [id],
|
|
1207
|
+
},
|
|
1208
|
+
transaction: this.#session ? true : false,
|
|
1209
|
+
action: "updateOne",
|
|
1210
|
+
internal: sessionStorage()?.get() ? false : true,
|
|
1211
|
+
ip: sessionStorage()?.get()?._v?.ip,
|
|
1212
|
+
auth: sessionStorage()?.get()?.isAuth,
|
|
1213
|
+
role: sessionStorage()?.get()?.role!,
|
|
1214
|
+
user: sessionStorage()?.get()?.state?.user,
|
|
1215
|
+
state: sessionStorage()?.get()?.state,
|
|
1216
|
+
});
|
|
1173
1217
|
return resolve(toJson(result?.doc || {}));
|
|
1174
1218
|
} catch (err) {
|
|
1175
1219
|
return reject(err);
|
|
@@ -1252,6 +1296,22 @@ class useRest {
|
|
|
1252
1296
|
}
|
|
1253
1297
|
``;
|
|
1254
1298
|
|
|
1299
|
+
restActivity.save(this.#tenant, {
|
|
1300
|
+
collection: collection,
|
|
1301
|
+
data: {
|
|
1302
|
+
update: update,
|
|
1303
|
+
filter: filter,
|
|
1304
|
+
},
|
|
1305
|
+
transaction: this.#session ? true : false,
|
|
1306
|
+
action: "findAndUpdate",
|
|
1307
|
+
internal: sessionStorage()?.get() ? false : true,
|
|
1308
|
+
ip: sessionStorage()?.get()?._v?.ip,
|
|
1309
|
+
auth: sessionStorage()?.get()?.isAuth,
|
|
1310
|
+
role: sessionStorage()?.get()?.role!,
|
|
1311
|
+
user: sessionStorage()?.get()?.state?.user,
|
|
1312
|
+
state: sessionStorage()?.get()?.state,
|
|
1313
|
+
});
|
|
1314
|
+
|
|
1255
1315
|
return resolve({
|
|
1256
1316
|
docs: result.docs,
|
|
1257
1317
|
matchedCount: up_?.matchedCount || 0,
|
|
@@ -1336,6 +1396,22 @@ class useRest {
|
|
|
1336
1396
|
])
|
|
1337
1397
|
.catch();
|
|
1338
1398
|
}
|
|
1399
|
+
// if findOneAndUpdate
|
|
1400
|
+
restActivity.save(this.#tenant, {
|
|
1401
|
+
collection: collection,
|
|
1402
|
+
data: {
|
|
1403
|
+
update: update,
|
|
1404
|
+
filter: filter,
|
|
1405
|
+
},
|
|
1406
|
+
transaction: this.#session ? true : false,
|
|
1407
|
+
action: "findOneAndUpdate",
|
|
1408
|
+
internal: sessionStorage()?.get() ? false : true,
|
|
1409
|
+
ip: sessionStorage()?.get()?._v?.ip,
|
|
1410
|
+
auth: sessionStorage()?.get()?.isAuth,
|
|
1411
|
+
role: sessionStorage()?.get()?.role!,
|
|
1412
|
+
user: sessionStorage()?.get()?.state?.user,
|
|
1413
|
+
state: sessionStorage()?.get()?.state,
|
|
1414
|
+
});
|
|
1339
1415
|
return resolve(result.doc);
|
|
1340
1416
|
} catch (err) {
|
|
1341
1417
|
return reject(err);
|
|
@@ -1532,20 +1608,7 @@ class useRest {
|
|
|
1532
1608
|
}),
|
|
1533
1609
|
});
|
|
1534
1610
|
}
|
|
1535
|
-
|
|
1536
|
-
collection: collection,
|
|
1537
|
-
data: {
|
|
1538
|
-
input: update,
|
|
1539
|
-
ids: ids,
|
|
1540
|
-
},
|
|
1541
|
-
action: "updateMany",
|
|
1542
|
-
transaction: this.#session ? true : false,
|
|
1543
|
-
internal: sessionStorage()?.get() ? false : true,
|
|
1544
|
-
user:
|
|
1545
|
-
sessionStorage().get().state?.user ||
|
|
1546
|
-
sessionStorage().get().state?.by ||
|
|
1547
|
-
null,
|
|
1548
|
-
});
|
|
1611
|
+
|
|
1549
1612
|
try {
|
|
1550
1613
|
col?.cache?.watch({
|
|
1551
1614
|
action: "updateMany",
|
|
@@ -1565,6 +1628,22 @@ class useRest {
|
|
|
1565
1628
|
.updateDocuments(result.docs)
|
|
1566
1629
|
.catch();
|
|
1567
1630
|
}
|
|
1631
|
+
// if updateMany done
|
|
1632
|
+
restActivity.save(this.#tenant, {
|
|
1633
|
+
collection: collection,
|
|
1634
|
+
data: {
|
|
1635
|
+
update: update,
|
|
1636
|
+
ids: ids,
|
|
1637
|
+
},
|
|
1638
|
+
action: "updateMany",
|
|
1639
|
+
transaction: this.#session ? true : false,
|
|
1640
|
+
internal: sessionStorage()?.get() ? false : true,
|
|
1641
|
+
ip: sessionStorage()?.get()?._v?.ip,
|
|
1642
|
+
auth: sessionStorage()?.get()?.isAuth,
|
|
1643
|
+
role: sessionStorage()?.get()?.role!,
|
|
1644
|
+
user: sessionStorage()?.get()?.state?.user,
|
|
1645
|
+
state: sessionStorage()?.get()?.state,
|
|
1646
|
+
});
|
|
1568
1647
|
return resolve(result.docs);
|
|
1569
1648
|
} else {
|
|
1570
1649
|
throw new contextError("List of id required", 400);
|
|
@@ -1666,20 +1745,7 @@ class useRest {
|
|
|
1666
1745
|
}),
|
|
1667
1746
|
});
|
|
1668
1747
|
}
|
|
1669
|
-
|
|
1670
|
-
collection: collection,
|
|
1671
|
-
data: {
|
|
1672
|
-
input: doc,
|
|
1673
|
-
id: id,
|
|
1674
|
-
ids: [id],
|
|
1675
|
-
},
|
|
1676
|
-
transaction: this.#session ? true : false,
|
|
1677
|
-
action: "deleteOne",
|
|
1678
|
-
user:
|
|
1679
|
-
sessionStorage().get().state?.user ||
|
|
1680
|
-
sessionStorage().get().state?.by ||
|
|
1681
|
-
null,
|
|
1682
|
-
});
|
|
1748
|
+
|
|
1683
1749
|
try {
|
|
1684
1750
|
col?.cache?.watch({
|
|
1685
1751
|
action: "deleteOne",
|
|
@@ -1691,7 +1757,7 @@ class useRest {
|
|
|
1691
1757
|
});
|
|
1692
1758
|
} catch (err) {}
|
|
1693
1759
|
if (
|
|
1694
|
-
this.#tenant
|
|
1760
|
+
this.#tenant?.searchEngine?.meilisearch?.enabled &&
|
|
1695
1761
|
col?.searchEngine?.meilisearch?.dispatchAction == "auto"
|
|
1696
1762
|
) {
|
|
1697
1763
|
this.meilisearch.client
|
|
@@ -1699,6 +1765,24 @@ class useRest {
|
|
|
1699
1765
|
.deleteDocument(id)
|
|
1700
1766
|
.catch();
|
|
1701
1767
|
}
|
|
1768
|
+
|
|
1769
|
+
// if deleteOne done
|
|
1770
|
+
restActivity.save(this.#tenant, {
|
|
1771
|
+
collection: collection,
|
|
1772
|
+
data: {
|
|
1773
|
+
data: doc,
|
|
1774
|
+
id: id,
|
|
1775
|
+
},
|
|
1776
|
+
transaction: this.#session ? true : false,
|
|
1777
|
+
action: "deleteOne",
|
|
1778
|
+
internal: sessionStorage()?.get() ? false : true,
|
|
1779
|
+
ip: sessionStorage()?.get()?._v?.ip,
|
|
1780
|
+
auth: sessionStorage()?.get()?.isAuth,
|
|
1781
|
+
role: sessionStorage()?.get()?.role!,
|
|
1782
|
+
user: sessionStorage()?.get()?.state?.user,
|
|
1783
|
+
state: sessionStorage()?.get()?.state,
|
|
1784
|
+
});
|
|
1785
|
+
|
|
1702
1786
|
return resolve(doc);
|
|
1703
1787
|
} catch (err) {
|
|
1704
1788
|
return resolve(err);
|
|
@@ -1801,19 +1885,6 @@ class useRest {
|
|
|
1801
1885
|
});
|
|
1802
1886
|
}
|
|
1803
1887
|
|
|
1804
|
-
restActivity.save(this.#tenant, {
|
|
1805
|
-
collection: collection,
|
|
1806
|
-
data: {
|
|
1807
|
-
input: null,
|
|
1808
|
-
ids: ids,
|
|
1809
|
-
},
|
|
1810
|
-
transaction: this.#session ? true : false,
|
|
1811
|
-
action: "deleteMany",
|
|
1812
|
-
user:
|
|
1813
|
-
sessionStorage().get().state?.user ||
|
|
1814
|
-
sessionStorage().get().state?.by ||
|
|
1815
|
-
null,
|
|
1816
|
-
});
|
|
1817
1888
|
try {
|
|
1818
1889
|
col?.cache?.watch({
|
|
1819
1890
|
action: "deleteMany",
|
|
@@ -1825,7 +1896,7 @@ class useRest {
|
|
|
1825
1896
|
});
|
|
1826
1897
|
} catch (err) {}
|
|
1827
1898
|
if (
|
|
1828
|
-
this.#tenant
|
|
1899
|
+
this.#tenant?.searchEngine?.meilisearch?.enabled &&
|
|
1829
1900
|
col?.searchEngine?.meilisearch?.dispatchAction == "auto"
|
|
1830
1901
|
) {
|
|
1831
1902
|
this.meilisearch.client
|
|
@@ -1833,6 +1904,22 @@ class useRest {
|
|
|
1833
1904
|
.deleteDocuments(deletedIds)
|
|
1834
1905
|
.catch();
|
|
1835
1906
|
}
|
|
1907
|
+
// if deleteMany done
|
|
1908
|
+
restActivity.save(this.#tenant, {
|
|
1909
|
+
collection: collection,
|
|
1910
|
+
data: {
|
|
1911
|
+
input: null,
|
|
1912
|
+
ids: ids,
|
|
1913
|
+
},
|
|
1914
|
+
transaction: this.#session ? true : false,
|
|
1915
|
+
action: "deleteMany",
|
|
1916
|
+
internal: sessionStorage()?.get() ? false : true,
|
|
1917
|
+
ip: sessionStorage()?.get()?._v?.ip,
|
|
1918
|
+
auth: sessionStorage()?.get()?.isAuth,
|
|
1919
|
+
role: sessionStorage()?.get()?.role!,
|
|
1920
|
+
user: sessionStorage()?.get()?.state?.user,
|
|
1921
|
+
state: sessionStorage()?.get()?.state,
|
|
1922
|
+
});
|
|
1836
1923
|
return resolve(deletedIds);
|
|
1837
1924
|
} catch (err) {
|
|
1838
1925
|
return reject(err);
|
|
@@ -1853,10 +1940,12 @@ class useRest {
|
|
|
1853
1940
|
collection: Collection,
|
|
1854
1941
|
data: {},
|
|
1855
1942
|
action: "dropCollection",
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1943
|
+
internal: sessionStorage()?.get() ? false : true,
|
|
1944
|
+
ip: sessionStorage()?.get()?._v?.ip,
|
|
1945
|
+
auth: sessionStorage()?.get()?.isAuth,
|
|
1946
|
+
role: sessionStorage()?.get()?.role!,
|
|
1947
|
+
user: sessionStorage()?.get()?.state?.user,
|
|
1948
|
+
state: sessionStorage()?.get()?.state,
|
|
1860
1949
|
});
|
|
1861
1950
|
return resolve(r);
|
|
1862
1951
|
} catch (err) {
|
|
@@ -1947,6 +2036,8 @@ const restActivity = {
|
|
|
1947
2036
|
user?: object;
|
|
1948
2037
|
transaction?: boolean;
|
|
1949
2038
|
auth?: boolean;
|
|
2039
|
+
state?: object;
|
|
2040
|
+
role?: string;
|
|
1950
2041
|
}
|
|
1951
2042
|
) => {
|
|
1952
2043
|
return await tenant.database.db
|
|
@@ -1962,6 +2053,8 @@ const restActivity = {
|
|
|
1962
2053
|
createdAt: moment().format(),
|
|
1963
2054
|
updatedAt: moment().format(),
|
|
1964
2055
|
user: activity?.user,
|
|
2056
|
+
state: activity?.state,
|
|
2057
|
+
role: activity?.role,
|
|
1965
2058
|
transaction: activity?.transaction ?? false,
|
|
1966
2059
|
})
|
|
1967
2060
|
)
|
package/lib/asyncLocalStorage.ts
CHANGED
|
@@ -22,11 +22,15 @@ function isSetAsyncLocalStorage() {
|
|
|
22
22
|
}
|
|
23
23
|
const sessionStorage = () => ({
|
|
24
24
|
get(): {
|
|
25
|
-
state:
|
|
25
|
+
state: {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
user: any;
|
|
28
|
+
};
|
|
26
29
|
_v: {
|
|
27
30
|
isAuth: boolean;
|
|
28
31
|
reqAt?: string;
|
|
29
32
|
setAt?: string;
|
|
33
|
+
ip?: string;
|
|
30
34
|
};
|
|
31
35
|
role: string | null | undefined;
|
|
32
36
|
token?: string;
|