@appsemble/node-utils 0.28.9 → 0.28.10
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/package.json +3 -3
- package/server/controllers/resources.js +34 -23
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.28.10)
|
|
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.28.
|
|
29
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.28.10/LICENSE.md) ©
|
|
30
30
|
[Appsemble](https://appsemble.com)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/node-utils",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.10",
|
|
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.28.
|
|
42
|
-
"@appsemble/utils": "0.28.
|
|
41
|
+
"@appsemble/types": "0.28.10",
|
|
42
|
+
"@appsemble/utils": "0.28.10",
|
|
43
43
|
"@formatjs/fast-memoize": "^2.0.0",
|
|
44
44
|
"@fortawesome/fontawesome-free": "^6.0.0",
|
|
45
45
|
"@koa/cors": "^4.0.0",
|
|
@@ -355,36 +355,47 @@ export function createSeedResource(options) {
|
|
|
355
355
|
ctx.body = Array.isArray(processedBody) ? createdResources : createdResources[0];
|
|
356
356
|
};
|
|
357
357
|
}
|
|
358
|
+
async function deleteResourcesRecursively(type, app, options, context) {
|
|
359
|
+
const { deleteAppResource, getAppResources } = options;
|
|
360
|
+
const referencingResources = Object.entries(app.definition.resources).filter(([, resourceDefinition]) => {
|
|
361
|
+
var _a;
|
|
362
|
+
return Object.values((_a = resourceDefinition.references) !== null && _a !== void 0 ? _a : {}).find((resourceReference) => resourceReference.resource === type);
|
|
363
|
+
});
|
|
364
|
+
for (const [referencingResourceType] of referencingResources) {
|
|
365
|
+
await deleteResourcesRecursively(referencingResourceType, app, options, context);
|
|
366
|
+
}
|
|
367
|
+
const resourcesToDeleteFindOptions = {
|
|
368
|
+
where: {
|
|
369
|
+
type,
|
|
370
|
+
AppId: app.id,
|
|
371
|
+
or: [{ seed: true }, { ephemeral: true }],
|
|
372
|
+
},
|
|
373
|
+
};
|
|
374
|
+
const resourcesToDelete = await getAppResources({
|
|
375
|
+
app,
|
|
376
|
+
findOptions: resourcesToDeleteFindOptions,
|
|
377
|
+
type,
|
|
378
|
+
context,
|
|
379
|
+
});
|
|
380
|
+
for (const resourceToDelete of resourcesToDelete) {
|
|
381
|
+
await deleteAppResource({
|
|
382
|
+
app,
|
|
383
|
+
context,
|
|
384
|
+
options,
|
|
385
|
+
id: resourceToDelete.id,
|
|
386
|
+
type,
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
}
|
|
358
390
|
export function createDeleteSeedResources(options) {
|
|
359
391
|
return async (ctx) => {
|
|
360
392
|
var _a;
|
|
361
393
|
const { pathParams: { appId }, } = ctx;
|
|
362
|
-
const {
|
|
394
|
+
const { getApp } = options;
|
|
363
395
|
const app = await getApp({ context: ctx, query: { where: { id: appId } } });
|
|
364
396
|
assertKoaError(!app, ctx, 404, 'App not found');
|
|
365
397
|
for (const resourceType of Object.keys((_a = app.definition.resources) !== null && _a !== void 0 ? _a : {})) {
|
|
366
|
-
|
|
367
|
-
where: {
|
|
368
|
-
type: resourceType,
|
|
369
|
-
AppId: appId,
|
|
370
|
-
or: [{ seed: true }, { ephemeral: true }],
|
|
371
|
-
},
|
|
372
|
-
};
|
|
373
|
-
const resourcesToDelete = await getAppResources({
|
|
374
|
-
app,
|
|
375
|
-
findOptions: resourcesToDeleteFindOptions,
|
|
376
|
-
type: resourceType,
|
|
377
|
-
context: ctx,
|
|
378
|
-
});
|
|
379
|
-
for (const resourceToDelete of resourcesToDelete) {
|
|
380
|
-
await deleteAppResource({
|
|
381
|
-
app,
|
|
382
|
-
context: ctx,
|
|
383
|
-
options,
|
|
384
|
-
id: resourceToDelete.id,
|
|
385
|
-
type: resourceType,
|
|
386
|
-
});
|
|
387
|
-
}
|
|
398
|
+
await deleteResourcesRecursively(resourceType, app, options, ctx);
|
|
388
399
|
}
|
|
389
400
|
};
|
|
390
401
|
}
|