@ditojs/server 1.27.0 → 1.28.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/package.json +6 -6
- package/src/cli/db/listAssetConfig.js +1 -1
- package/src/models/Model.js +33 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ditojs/server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Dito.js Server – Dito.js is a declarative and modern web framework, based on Objection.js, Koa.js and Vue.js",
|
|
6
6
|
"repository": "https://github.com/ditojs/dito/tree/master/packages/server",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"node >= 18"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@ditojs/admin": "^1.
|
|
26
|
-
"@ditojs/build": "^1.
|
|
27
|
-
"@ditojs/router": "^1.
|
|
28
|
-
"@ditojs/utils": "^1.
|
|
25
|
+
"@ditojs/admin": "^1.28.0",
|
|
26
|
+
"@ditojs/build": "^1.28.0",
|
|
27
|
+
"@ditojs/router": "^1.28.0",
|
|
28
|
+
"@ditojs/utils": "^1.28.0",
|
|
29
29
|
"@koa/cors": "^4.0.0",
|
|
30
30
|
"@koa/multer": "^3.0.2",
|
|
31
31
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"typescript": "^4.9.5"
|
|
91
91
|
},
|
|
92
92
|
"types": "types",
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "9e43f6a450f6c38a5147502863d1f44738fcecef",
|
|
94
94
|
"scripts": {
|
|
95
95
|
"types": "tsc --noEmit ./src/index.d.ts"
|
|
96
96
|
},
|
package/src/models/Model.js
CHANGED
|
@@ -42,7 +42,7 @@ export class Model extends objection.Model {
|
|
|
42
42
|
const { hooks, assets } = this.definition
|
|
43
43
|
this._configureEmitter(hooks)
|
|
44
44
|
if (assets) {
|
|
45
|
-
this.
|
|
45
|
+
this._configureAssetsHooks(assets)
|
|
46
46
|
}
|
|
47
47
|
try {
|
|
48
48
|
for (const relation of Object.values(this.getRelations())) {
|
|
@@ -923,7 +923,7 @@ export class Model extends objection.Model {
|
|
|
923
923
|
|
|
924
924
|
// Assets handling
|
|
925
925
|
|
|
926
|
-
static
|
|
926
|
+
static _configureAssetsHooks(assets) {
|
|
927
927
|
const assetDataPaths = Object.keys(assets)
|
|
928
928
|
|
|
929
929
|
this.on([
|
|
@@ -931,34 +931,50 @@ export class Model extends objection.Model {
|
|
|
931
931
|
'before:update',
|
|
932
932
|
'before:delete'
|
|
933
933
|
], async ({ type, transaction, inputItems, asFindQuery }) => {
|
|
934
|
-
const
|
|
935
|
-
|
|
936
|
-
: inputItems
|
|
934
|
+
const isInsert = type === 'before:insert'
|
|
935
|
+
const isDelete = type === 'before:delete'
|
|
937
936
|
// Figure out which asset data paths where actually present in the
|
|
938
937
|
// submitted data, and only compare these. But when deleting, use all.
|
|
939
|
-
const dataPaths =
|
|
940
|
-
? assetDataPaths
|
|
941
|
-
|
|
938
|
+
const dataPaths = isDelete
|
|
939
|
+
? assetDataPaths
|
|
940
|
+
: assetDataPaths.filter(
|
|
941
|
+
dataPath => (
|
|
942
|
+
// Skip check for wildcard data-paths.
|
|
943
|
+
/^\*\*?/.test(dataPath) ||
|
|
944
|
+
// Only keep normal data paths that match present properties.
|
|
945
|
+
(parseDataPath(dataPath)[0] in inputItems[0])
|
|
946
|
+
)
|
|
942
947
|
)
|
|
943
|
-
: assetDataPaths
|
|
944
|
-
|
|
945
948
|
// `dataPaths` is empty in the case of an update/insert that does not
|
|
946
949
|
// affect the assets.
|
|
947
950
|
if (dataPaths.length === 0) return
|
|
948
951
|
|
|
952
|
+
const afterItems = isDelete
|
|
953
|
+
? []
|
|
954
|
+
: inputItems
|
|
949
955
|
// Load the model's asset files in their current state before the query is
|
|
950
|
-
// executed.
|
|
951
|
-
|
|
956
|
+
// executed. For deletes, load the data for all asset data-paths.
|
|
957
|
+
// Otherwise, only load the columns present in the input data.
|
|
958
|
+
const beforeItems = isInsert
|
|
952
959
|
? []
|
|
953
|
-
:
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
960
|
+
: isDelete
|
|
961
|
+
? await loadAssetDataPaths(asFindQuery(), dataPaths)
|
|
962
|
+
: await asFindQuery().select(
|
|
963
|
+
// Select all columns that are present in the data and not computed.
|
|
964
|
+
Object.keys(inputItems[0]).filter(key => {
|
|
965
|
+
const property = this.definition.properties[key]
|
|
966
|
+
return property && !property.computed
|
|
967
|
+
})
|
|
968
|
+
)
|
|
969
|
+
|
|
958
970
|
const afterFilesPerDataPath = getFilesPerAssetDataPath(
|
|
959
971
|
afterItems,
|
|
960
972
|
dataPaths
|
|
961
973
|
)
|
|
974
|
+
const beforeFilesPerDataPath = getFilesPerAssetDataPath(
|
|
975
|
+
beforeItems,
|
|
976
|
+
dataPaths
|
|
977
|
+
)
|
|
962
978
|
|
|
963
979
|
const importedFiles = []
|
|
964
980
|
const modifiedFiles = []
|