@appsemble/node-utils 0.29.7 → 0.29.9
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/README.md +3 -3
- package/csv.js +1 -1
- package/package.json +3 -3
- package/resource.js +33 -4
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#  Appsemble Node Utilities
|
|
2
2
|
|
|
3
3
|
> NodeJS utilities used by Appsemble internally.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@appsemble/node-utils)
|
|
6
|
-
[](https://gitlab.com/appsemble/appsemble/-/releases/0.29.9)
|
|
7
7
|
[](https://prettier.io)
|
|
8
8
|
|
|
9
9
|
## Table of Contents
|
|
@@ -26,5 +26,5 @@ compatibility is not guaranteed.
|
|
|
26
26
|
|
|
27
27
|
## License
|
|
28
28
|
|
|
29
|
-
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.29.
|
|
29
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.29.9/LICENSE.md) ©
|
|
30
30
|
[Appsemble](https://appsemble.com)
|
package/csv.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/node-utils",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.9",
|
|
4
4
|
"description": "NodeJS utilities used by Appsemble internally.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"test": "vitest"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@appsemble/types": "0.29.
|
|
42
|
-
"@appsemble/utils": "0.29.
|
|
41
|
+
"@appsemble/types": "0.29.9",
|
|
42
|
+
"@appsemble/utils": "0.29.9",
|
|
43
43
|
"@formatjs/fast-memoize": "^2.0.0",
|
|
44
44
|
"@fortawesome/fontawesome-free": "^6.0.0",
|
|
45
45
|
"@kubernetes/client-node": "0.21.0",
|
package/resource.js
CHANGED
|
@@ -104,18 +104,40 @@ export function extractResourceBody(ctx) {
|
|
|
104
104
|
* 3. Asset IDs from the `knownAssetIds` array which are no longer used.
|
|
105
105
|
*/
|
|
106
106
|
export function processResourceBody(ctx, definition, knownAssetIds = [], knownExpires, knownAssetNameIds = [], isPatch = false) {
|
|
107
|
-
var _a, _b;
|
|
107
|
+
var _a, _b, _c;
|
|
108
108
|
const [resource, assets, preValidateProperty] = extractResourceBody(ctx);
|
|
109
109
|
const validator = new Validator();
|
|
110
110
|
const assetIdMap = new Map();
|
|
111
111
|
const assetUsedMap = new Map();
|
|
112
112
|
const reusedAssets = new Set();
|
|
113
|
-
const
|
|
113
|
+
const thumbnailAssets = [];
|
|
114
|
+
const regularAssets = [];
|
|
115
|
+
const thumbnailAssetSuffix = '-thumbnail.png';
|
|
116
|
+
for (const asset of assets) {
|
|
117
|
+
if ((_a = asset.filename) === null || _a === void 0 ? void 0 : _a.endsWith(thumbnailAssetSuffix)) {
|
|
118
|
+
thumbnailAssets.push(asset);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
regularAssets.push(asset);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const preparedRegularAssets = regularAssets.map(({ contents, filename, mime }, index) => {
|
|
114
125
|
const id = randomUUID();
|
|
115
126
|
assetIdMap.set(index, id);
|
|
116
127
|
assetUsedMap.set(index, false);
|
|
117
128
|
return { data: contents, filename, id, mime };
|
|
118
129
|
});
|
|
130
|
+
const usedPreparedRegularAssets = [];
|
|
131
|
+
const preparedThumbnailAssets = thumbnailAssets.map(({ contents, filename, mime }, index) => {
|
|
132
|
+
const regularAsset = preparedRegularAssets.find((ra) => !usedPreparedRegularAssets.includes(ra.id) &&
|
|
133
|
+
ra.filename.startsWith(filename.replace(thumbnailAssetSuffix, '')));
|
|
134
|
+
const id = regularAsset ? `${regularAsset.id}-thumbnail` : randomUUID();
|
|
135
|
+
usedPreparedRegularAssets.push(regularAsset === null || regularAsset === void 0 ? void 0 : regularAsset.id);
|
|
136
|
+
assetIdMap.set(index + preparedRegularAssets.length, id);
|
|
137
|
+
assetUsedMap.set(index, false);
|
|
138
|
+
return { data: contents, filename, id, mime };
|
|
139
|
+
});
|
|
140
|
+
const preparedAssets = [...preparedRegularAssets, ...preparedThumbnailAssets];
|
|
119
141
|
validator.customFormats.binary = (input) => {
|
|
120
142
|
if (knownAssetIds.includes(input)) {
|
|
121
143
|
reusedAssets.add(input);
|
|
@@ -137,7 +159,7 @@ export function processResourceBody(ctx, definition, knownAssetIds = [], knownEx
|
|
|
137
159
|
};
|
|
138
160
|
const patchedSchema = {
|
|
139
161
|
...definition.schema,
|
|
140
|
-
required: ((
|
|
162
|
+
required: ((_b = ctx.request) === null || _b === void 0 ? void 0 : _b.method) === 'PATCH' || isPatch ? [] : definition.schema.required,
|
|
141
163
|
properties: {
|
|
142
164
|
...definition.schema.properties,
|
|
143
165
|
id: { type: 'integer' },
|
|
@@ -152,7 +174,11 @@ export function processResourceBody(ctx, definition, knownAssetIds = [], knownEx
|
|
|
152
174
|
],
|
|
153
175
|
},
|
|
154
176
|
$clonable: { type: 'boolean' },
|
|
155
|
-
|
|
177
|
+
$thumbnails: {
|
|
178
|
+
type: 'array',
|
|
179
|
+
items: { type: 'string', format: 'binary' },
|
|
180
|
+
},
|
|
181
|
+
...Object.fromEntries(Object.values((_c = definition.references) !== null && _c !== void 0 ? _c : {}).map((reference) => [
|
|
156
182
|
`$${reference.resource}`,
|
|
157
183
|
{ type: 'integer' },
|
|
158
184
|
])),
|
|
@@ -172,6 +198,9 @@ export function processResourceBody(ctx, definition, knownAssetIds = [], knownEx
|
|
|
172
198
|
else if (path.length === 1) {
|
|
173
199
|
propertyName = path[0];
|
|
174
200
|
}
|
|
201
|
+
if (propertyName === '$thumbnails') {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
175
204
|
if (propertyName === '$expires') {
|
|
176
205
|
if (value !== undefined) {
|
|
177
206
|
const date = parseISO(value);
|