@appsemble/node-utils 0.28.11 → 0.28.13
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/resource.d.ts +7 -5
- package/resource.js +13 -7
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.13)
|
|
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.13/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.13",
|
|
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.13",
|
|
42
|
+
"@appsemble/utils": "0.28.13",
|
|
43
43
|
"@formatjs/fast-memoize": "^2.0.0",
|
|
44
44
|
"@fortawesome/fontawesome-free": "^6.0.0",
|
|
45
45
|
"@koa/cors": "^4.0.0",
|
package/resource.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type PreparedAsset } from '@appsemble/node-utils';
|
|
2
|
-
import { type App, type ResourceDefinition } from '@appsemble/types';
|
|
2
|
+
import { type App, type ResourceDefinition, type Resource as ResourceType } from '@appsemble/types';
|
|
3
3
|
import { type PreValidatePropertyFunction } from 'jsonschema';
|
|
4
|
-
import { type Context } from 'koa';
|
|
4
|
+
import { type Context, type DefaultContext, type DefaultState, type ParameterizedContext } from 'koa';
|
|
5
5
|
import { type File } from 'koas-body-parser';
|
|
6
|
+
export declare function stripResource({ $author, $created, $editor, $ephemeral, $seed, $updated, ...data }: ResourceType): Record<string, unknown>;
|
|
6
7
|
/**
|
|
7
8
|
* Get the resource definition of an app by name.
|
|
8
9
|
*
|
|
@@ -25,7 +26,7 @@ export declare function getResourceDefinition(app: App, resourceType: string, ct
|
|
|
25
26
|
* 2. A list of newly uploaded assets which should be linked to the resources.
|
|
26
27
|
* 3. preValidateProperty function used for reconstructing resources from a CSV file.
|
|
27
28
|
*/
|
|
28
|
-
export declare function extractResourceBody(ctx: Context): [Record<string, unknown> | Record<string, unknown>[], File[], PreValidatePropertyFunction];
|
|
29
|
+
export declare function extractResourceBody(ctx: Context | ParameterizedContext<DefaultState, DefaultContext, any>): [Record<string, unknown> | Record<string, unknown>[], File[], PreValidatePropertyFunction];
|
|
29
30
|
/**
|
|
30
31
|
* Process an incoming resource request body.
|
|
31
32
|
*
|
|
@@ -36,13 +37,14 @@ export declare function extractResourceBody(ctx: Context): [Record<string, unkno
|
|
|
36
37
|
* @param knownAssetIds A list of asset IDs that are already known to be linked to the resource.
|
|
37
38
|
* @param knownExpires A previously known expires value.
|
|
38
39
|
* @param knownAssetNameIds A list of asset ids with asset names that already exist.
|
|
40
|
+
* @param [isPatch] if the "PATCH" HTTP method is being used.
|
|
39
41
|
* @returns A tuple which consists of:
|
|
40
42
|
*
|
|
41
43
|
* 1. One or more resources processed from the request body.
|
|
42
44
|
* 2. A list of newly uploaded assets which should be linked to the resources.
|
|
43
45
|
* 3. Asset IDs from the `knownAssetIds` array which are no longer used.
|
|
44
46
|
*/
|
|
45
|
-
export declare function processResourceBody(ctx: Context, definition: ResourceDefinition, knownAssetIds?: string[], knownExpires?: Date, knownAssetNameIds?: {
|
|
47
|
+
export declare function processResourceBody(ctx: Context | ParameterizedContext<DefaultState, DefaultContext, any>, definition: ResourceDefinition, knownAssetIds?: string[], knownExpires?: Date, knownAssetNameIds?: {
|
|
46
48
|
id: string;
|
|
47
49
|
name: string;
|
|
48
|
-
}[]): [Record<string, unknown> | Record<string, unknown>[], PreparedAsset[], string[]];
|
|
50
|
+
}[], isPatch?: boolean): [Record<string, unknown> | Record<string, unknown>[], PreparedAsset[], string[]];
|
package/resource.js
CHANGED
|
@@ -5,7 +5,7 @@ import { ValidationError, Validator } from 'jsonschema';
|
|
|
5
5
|
import parseDuration from 'parse-duration';
|
|
6
6
|
import { preProcessCSV } from './csv.js';
|
|
7
7
|
import { throwKoaError } from './koa.js';
|
|
8
|
-
function stripResource({ $author, $created, $editor, $ephemeral, $updated, ...data }) {
|
|
8
|
+
export function stripResource({ $author, $created, $editor, $ephemeral, $seed, $updated, ...data }) {
|
|
9
9
|
return data;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
@@ -59,22 +59,27 @@ export function getResourceDefinition(app, resourceType, ctx, view) {
|
|
|
59
59
|
* 3. preValidateProperty function used for reconstructing resources from a CSV file.
|
|
60
60
|
*/
|
|
61
61
|
export function extractResourceBody(ctx) {
|
|
62
|
+
var _a, _b;
|
|
62
63
|
let body;
|
|
63
64
|
let assets;
|
|
64
65
|
let preValidateProperty;
|
|
65
|
-
if (ctx.is('multipart/form-data')) {
|
|
66
|
+
if (((_a = ctx === null || ctx === void 0 ? void 0 : ctx.request) === null || _a === void 0 ? void 0 : _a.body) && ctx.is('multipart/form-data')) {
|
|
66
67
|
({ assets = [], resource: body } = ctx.request.body);
|
|
67
68
|
if (Array.isArray(body) && body.length === 1) {
|
|
68
69
|
[body] = body;
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
|
-
else {
|
|
72
|
+
else if ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.request) === null || _b === void 0 ? void 0 : _b.body) {
|
|
72
73
|
if (ctx.is('text/csv')) {
|
|
73
74
|
preValidateProperty = preProcessCSV;
|
|
74
75
|
}
|
|
75
76
|
({ body } = ctx.request);
|
|
76
77
|
assets = [];
|
|
77
78
|
}
|
|
79
|
+
else {
|
|
80
|
+
({ body } = ctx);
|
|
81
|
+
assets = [];
|
|
82
|
+
}
|
|
78
83
|
return [
|
|
79
84
|
Array.isArray(body) ? body.map(stripResource) : stripResource(body),
|
|
80
85
|
assets,
|
|
@@ -91,14 +96,15 @@ export function extractResourceBody(ctx) {
|
|
|
91
96
|
* @param knownAssetIds A list of asset IDs that are already known to be linked to the resource.
|
|
92
97
|
* @param knownExpires A previously known expires value.
|
|
93
98
|
* @param knownAssetNameIds A list of asset ids with asset names that already exist.
|
|
99
|
+
* @param [isPatch] if the "PATCH" HTTP method is being used.
|
|
94
100
|
* @returns A tuple which consists of:
|
|
95
101
|
*
|
|
96
102
|
* 1. One or more resources processed from the request body.
|
|
97
103
|
* 2. A list of newly uploaded assets which should be linked to the resources.
|
|
98
104
|
* 3. Asset IDs from the `knownAssetIds` array which are no longer used.
|
|
99
105
|
*/
|
|
100
|
-
export function processResourceBody(ctx, definition, knownAssetIds = [], knownExpires, knownAssetNameIds = []) {
|
|
101
|
-
var _a;
|
|
106
|
+
export function processResourceBody(ctx, definition, knownAssetIds = [], knownExpires, knownAssetNameIds = [], isPatch = false) {
|
|
107
|
+
var _a, _b;
|
|
102
108
|
const [resource, assets, preValidateProperty] = extractResourceBody(ctx);
|
|
103
109
|
const validator = new Validator();
|
|
104
110
|
const assetIdMap = new Map();
|
|
@@ -131,7 +137,7 @@ export function processResourceBody(ctx, definition, knownAssetIds = [], knownEx
|
|
|
131
137
|
};
|
|
132
138
|
const patchedSchema = {
|
|
133
139
|
...definition.schema,
|
|
134
|
-
required: ctx.request.method === 'PATCH' ? [] : definition.schema.required,
|
|
140
|
+
required: ((_a = ctx.request) === null || _a === void 0 ? void 0 : _a.method) === 'PATCH' || isPatch ? [] : definition.schema.required,
|
|
135
141
|
properties: {
|
|
136
142
|
...definition.schema.properties,
|
|
137
143
|
id: { type: 'integer' },
|
|
@@ -146,7 +152,7 @@ export function processResourceBody(ctx, definition, knownAssetIds = [], knownEx
|
|
|
146
152
|
],
|
|
147
153
|
},
|
|
148
154
|
$clonable: { type: 'boolean' },
|
|
149
|
-
...Object.fromEntries(Object.values((
|
|
155
|
+
...Object.fromEntries(Object.values((_b = definition.references) !== null && _b !== void 0 ? _b : {}).map((reference) => [
|
|
150
156
|
`$${reference.resource}`,
|
|
151
157
|
{ type: 'integer' },
|
|
152
158
|
])),
|