@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 CHANGED
@@ -1,9 +1,9 @@
1
- # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.29.7/config/assets/logo.svg) Appsemble Node Utilities
1
+ # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.29.9/config/assets/logo.svg) Appsemble Node Utilities
2
2
 
3
3
  > NodeJS utilities used by Appsemble internally.
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/@appsemble/node-utils)](https://www.npmjs.com/package/@appsemble/node-utils)
6
- [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.29.7/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.29.7)
6
+ [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.29.9/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.29.9)
7
7
  [![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](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.7/LICENSE.md) ©
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
@@ -35,7 +35,7 @@ export const preProcessCSV = (instance, key, schema, options, ctx) => {
35
35
  break;
36
36
  }
37
37
  case 'array': {
38
- const result = JSON.parse(value);
38
+ const result = JSON.parse(value || '[]');
39
39
  if (Array.isArray(result)) {
40
40
  parent[key] = result;
41
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appsemble/node-utils",
3
- "version": "0.29.7",
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.7",
42
- "@appsemble/utils": "0.29.7",
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 preparedAssets = assets.map(({ contents, filename, mime }, index) => {
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: ((_a = ctx.request) === null || _a === void 0 ? void 0 : _a.method) === 'PATCH' || isPatch ? [] : definition.schema.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
- ...Object.fromEntries(Object.values((_b = definition.references) !== null && _b !== void 0 ? _b : {}).map((reference) => [
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);