@balena/pinejs 21.4.0-build-add-actions-example-3b1330b7c91a500b24432e0b7cd8d509a8336ad9-1 → 21.4.0-build-add-odata-actions-8d4944e07924e5cf0a69183c18610e8fd2c41d3b-1
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/.pinejs-cache.json +1 -1
- package/.versionbot/CHANGELOG.yml +2 -18
- package/CHANGELOG.md +0 -2
- package/out/config-loader/config-loader.js +6 -7
- package/out/config-loader/config-loader.js.map +1 -1
- package/out/config-loader/env.d.ts +0 -4
- package/out/config-loader/env.js +0 -4
- package/out/config-loader/env.js.map +1 -1
- package/out/sbvr-api/actions.js +1 -1
- package/out/sbvr-api/actions.js.map +1 -1
- package/out/server-glue/module.js +0 -2
- package/out/server-glue/module.js.map +1 -1
- package/out/webresource-handler/index.d.ts +0 -9
- package/out/webresource-handler/index.js +1 -31
- package/out/webresource-handler/index.js.map +1 -1
- package/package.json +5 -5
- package/src/config-loader/config-loader.ts +8 -8
- package/src/config-loader/env.ts +0 -11
- package/src/sbvr-api/actions.ts +1 -1
- package/src/server-glue/module.ts +0 -2
- package/src/webresource-handler/index.ts +0 -54
- package/out/webresource-handler/actions/beginUpload.d.ts +0 -3
- package/out/webresource-handler/actions/beginUpload.js +0 -105
- package/out/webresource-handler/actions/beginUpload.js.map +0 -1
- package/out/webresource-handler/actions/canceUpload.d.ts +0 -3
- package/out/webresource-handler/actions/canceUpload.js +0 -58
- package/out/webresource-handler/actions/canceUpload.js.map +0 -1
- package/out/webresource-handler/actions/commitUpload.d.ts +0 -3
- package/out/webresource-handler/actions/commitUpload.js +0 -85
- package/out/webresource-handler/actions/commitUpload.js.map +0 -1
- package/out/webresource-handler/multipartUpload.d.ts +0 -4
- package/out/webresource-handler/multipartUpload.js +0 -14
- package/out/webresource-handler/multipartUpload.js.map +0 -1
- package/out/webresource-handler/webresource.d.ts +0 -42
- package/out/webresource-handler/webresource.js +0 -2
- package/out/webresource-handler/webresource.js.map +0 -1
- package/out/webresource-handler/webresource.sbvr +0 -60
- package/src/webresource-handler/actions/beginUpload.ts +0 -163
- package/src/webresource-handler/actions/canceUpload.ts +0 -92
- package/src/webresource-handler/actions/commitUpload.ts +0 -117
- package/src/webresource-handler/multipartUpload.ts +0 -23
- package/src/webresource-handler/webresource.sbvr +0 -60
- package/src/webresource-handler/webresource.ts +0 -48
@@ -1,117 +0,0 @@
|
|
1
|
-
import type { Tx } from '../../database-layer/db.js';
|
2
|
-
import type {
|
3
|
-
ODataActionArgs,
|
4
|
-
ODataActionRequest,
|
5
|
-
} from '../../sbvr-api/actions.js';
|
6
|
-
import {
|
7
|
-
BadRequestError,
|
8
|
-
NotImplementedError,
|
9
|
-
UnauthorizedError,
|
10
|
-
} from '../../sbvr-api/errors.js';
|
11
|
-
import type { Response } from '../../sbvr-api/sbvr-utils.js';
|
12
|
-
import { api } from '../../sbvr-api/sbvr-utils.js';
|
13
|
-
import { permissions } from '../../server-glue/module.js';
|
14
|
-
import { getMultipartUploadHandler } from '../multipartUpload.js';
|
15
|
-
|
16
|
-
export const commitUploadAction = async ({
|
17
|
-
request,
|
18
|
-
tx,
|
19
|
-
id,
|
20
|
-
api: applicationApi,
|
21
|
-
}: ODataActionArgs): Promise<Response> => {
|
22
|
-
if (typeof id !== 'number') {
|
23
|
-
throw new NotImplementedError(
|
24
|
-
'multipart upload do not yet support non-numeric ids',
|
25
|
-
);
|
26
|
-
}
|
27
|
-
|
28
|
-
const multipartUpload = await getOngoingUpload(request, id, tx);
|
29
|
-
const handler = getMultipartUploadHandler();
|
30
|
-
|
31
|
-
const webresource = await handler.multipartUpload.commit({
|
32
|
-
fileKey: multipartUpload.fileKey,
|
33
|
-
uploadId: multipartUpload.uploadId,
|
34
|
-
filename: multipartUpload.filename,
|
35
|
-
providerCommitData: multipartUpload.providerCommitData,
|
36
|
-
});
|
37
|
-
|
38
|
-
await Promise.all([
|
39
|
-
api.webresource.patch({
|
40
|
-
resource: 'multipart_upload',
|
41
|
-
body: {
|
42
|
-
status: 'completed',
|
43
|
-
},
|
44
|
-
options: {
|
45
|
-
$filter: {
|
46
|
-
uuid: multipartUpload.uuid,
|
47
|
-
},
|
48
|
-
},
|
49
|
-
passthrough: {
|
50
|
-
tx: tx,
|
51
|
-
req: permissions.root,
|
52
|
-
},
|
53
|
-
}),
|
54
|
-
applicationApi.patch({
|
55
|
-
resource: request.resourceName,
|
56
|
-
id,
|
57
|
-
body: {
|
58
|
-
[multipartUpload.fieldName]: webresource,
|
59
|
-
},
|
60
|
-
passthrough: {
|
61
|
-
tx: tx,
|
62
|
-
// Root is needed as, if you are not root, you are not allowed to directly modify the actual metadata
|
63
|
-
req: permissions.root,
|
64
|
-
},
|
65
|
-
}),
|
66
|
-
]);
|
67
|
-
|
68
|
-
const body = await handler.onPreRespond(webresource);
|
69
|
-
|
70
|
-
return {
|
71
|
-
body,
|
72
|
-
statusCode: 200,
|
73
|
-
};
|
74
|
-
};
|
75
|
-
|
76
|
-
const getOngoingUpload = async (
|
77
|
-
request: ODataActionRequest,
|
78
|
-
affectedId: number,
|
79
|
-
tx: Tx,
|
80
|
-
) => {
|
81
|
-
const { uuid, providerCommitData } = request.values;
|
82
|
-
if (uuid == null || typeof uuid !== 'string') {
|
83
|
-
throw new BadRequestError('Invalid uuid type');
|
84
|
-
}
|
85
|
-
|
86
|
-
const [multipartUpload] = await api.webresource.get({
|
87
|
-
resource: 'multipart_upload',
|
88
|
-
options: {
|
89
|
-
$select: ['id', 'file_key', 'upload_id', 'field_name', 'filename'],
|
90
|
-
$filter: {
|
91
|
-
// TODO: swap this into the ID to see if it works
|
92
|
-
uuid,
|
93
|
-
status: 'pending',
|
94
|
-
expiry_date: { $gt: { $now: {} } },
|
95
|
-
resource_name: request.resourceName,
|
96
|
-
resource_id: affectedId,
|
97
|
-
},
|
98
|
-
},
|
99
|
-
passthrough: {
|
100
|
-
tx,
|
101
|
-
req: permissions.rootRead,
|
102
|
-
},
|
103
|
-
});
|
104
|
-
|
105
|
-
if (multipartUpload == null) {
|
106
|
-
throw new UnauthorizedError();
|
107
|
-
}
|
108
|
-
|
109
|
-
return {
|
110
|
-
uuid,
|
111
|
-
providerCommitData,
|
112
|
-
fileKey: multipartUpload.file_key,
|
113
|
-
uploadId: multipartUpload.upload_id,
|
114
|
-
filename: multipartUpload.filename,
|
115
|
-
fieldName: multipartUpload.field_name,
|
116
|
-
};
|
117
|
-
};
|
@@ -1,23 +0,0 @@
|
|
1
|
-
import { webResource as webResourceEnv } from '../config-loader/env.js';
|
2
|
-
import { NotImplementedError } from '../sbvr-api/errors.js';
|
3
|
-
import type { WebResourceHandler } from './index.js';
|
4
|
-
import { getWebresourceHandler } from './index.js';
|
5
|
-
|
6
|
-
export type MultipartUploadHandler = WebResourceHandler &
|
7
|
-
Required<Pick<WebResourceHandler, 'multipartUpload'>>;
|
8
|
-
|
9
|
-
export const isMultipartUploadAvailable = (
|
10
|
-
handler: WebResourceHandler | undefined,
|
11
|
-
): handler is MultipartUploadHandler => {
|
12
|
-
return (
|
13
|
-
webResourceEnv.multipartUploadEnabled && handler?.multipartUpload != null
|
14
|
-
);
|
15
|
-
};
|
16
|
-
|
17
|
-
export const getMultipartUploadHandler = () => {
|
18
|
-
const handler = getWebresourceHandler();
|
19
|
-
if (!isMultipartUploadAvailable(handler)) {
|
20
|
-
throw new NotImplementedError('Multipart uploads not available');
|
21
|
-
}
|
22
|
-
return handler;
|
23
|
-
};
|
@@ -1,60 +0,0 @@
|
|
1
|
-
Vocabulary: webresource
|
2
|
-
|
3
|
-
Term: actor
|
4
|
-
Concept Type: Integer (Type)
|
5
|
-
Term: expiry date
|
6
|
-
Concept Type: Date Time (Type)
|
7
|
-
Term: uuid
|
8
|
-
Concept Type: Short Text (Type)
|
9
|
-
Term: resource name
|
10
|
-
Concept Type: Short Text (Type)
|
11
|
-
Term: field name
|
12
|
-
Concept Type: Short Text (Type)
|
13
|
-
Term: resource id
|
14
|
-
Concept Type: Integer (Type)
|
15
|
-
Term: upload id
|
16
|
-
Concept Type: Short Text (Type)
|
17
|
-
Term: file key
|
18
|
-
Concept Type: Short Text (Type)
|
19
|
-
Term: status
|
20
|
-
Concept Type: Short Text (Type)
|
21
|
-
Term: filename
|
22
|
-
Concept Type: Short Text (Type)
|
23
|
-
Term: content type
|
24
|
-
Concept Type: Short Text (Type)
|
25
|
-
Term: size
|
26
|
-
Concept Type: Big Integer (Type)
|
27
|
-
Term: chunk size
|
28
|
-
Concept Type: Integer (Type)
|
29
|
-
Term: valid until date
|
30
|
-
Concept Type: Date Time (Type)
|
31
|
-
|
32
|
-
Term: multipart upload
|
33
|
-
Fact type: multipart upload has uuid
|
34
|
-
Necessity: each multipart upload has exactly one uuid
|
35
|
-
Necessity: each uuid is of exactly one multipart upload
|
36
|
-
Fact type: multipart upload has resource name
|
37
|
-
Necessity: each multipart upload has exactly one resource name
|
38
|
-
Fact type: multipart upload has field name
|
39
|
-
Necessity: each multipart upload has exactly one field name
|
40
|
-
Fact type: multipart upload has resource id
|
41
|
-
Necessity: each multipart upload has exactly one resource id
|
42
|
-
Fact type: multipart upload has upload id
|
43
|
-
Necessity: each multipart upload has exactly one upload id
|
44
|
-
Fact type: multipart upload has file key
|
45
|
-
Necessity: each multipart upload has exactly one file key
|
46
|
-
Fact type: multipart upload has status
|
47
|
-
Necessity: each multipart upload has exactly one status
|
48
|
-
Definition: "pending" or "completed" or "cancelled"
|
49
|
-
Fact type: multipart upload has filename
|
50
|
-
Necessity: each multipart upload has exactly one filename
|
51
|
-
Fact type: multipart upload has content type
|
52
|
-
Necessity: each multipart upload has exactly one content type
|
53
|
-
Fact type: multipart upload has size
|
54
|
-
Necessity: each multipart upload has exactly one size
|
55
|
-
Fact type: multipart upload has chunk size
|
56
|
-
Necessity: each multipart upload has exactly one chunk size
|
57
|
-
Fact type: multipart upload has expiry date
|
58
|
-
Necessity: each multipart upload has exactly one expiry date
|
59
|
-
Fact type: multipart upload is created by actor
|
60
|
-
Necessity: each multipart upload is created by at most one actor
|
@@ -1,48 +0,0 @@
|
|
1
|
-
// These types were generated by @balena/abstract-sql-to-typescript v5.1.0
|
2
|
-
|
3
|
-
import type { Types } from '@balena/abstract-sql-to-typescript';
|
4
|
-
|
5
|
-
export interface MultipartUpload {
|
6
|
-
Read: {
|
7
|
-
created_at: Types['Date Time']['Read'];
|
8
|
-
modified_at: Types['Date Time']['Read'];
|
9
|
-
id: Types['Serial']['Read'];
|
10
|
-
uuid: Types['Short Text']['Read'];
|
11
|
-
resource_name: Types['Short Text']['Read'];
|
12
|
-
field_name: Types['Short Text']['Read'];
|
13
|
-
resource_id: Types['Integer']['Read'];
|
14
|
-
upload_id: Types['Short Text']['Read'];
|
15
|
-
file_key: Types['Short Text']['Read'];
|
16
|
-
status: 'pending' | 'completed' | 'cancelled';
|
17
|
-
filename: Types['Short Text']['Read'];
|
18
|
-
content_type: Types['Short Text']['Read'];
|
19
|
-
size: Types['Big Integer']['Read'];
|
20
|
-
chunk_size: Types['Integer']['Read'];
|
21
|
-
expiry_date: Types['Date Time']['Read'];
|
22
|
-
is_created_by__actor: Types['Integer']['Read'] | null;
|
23
|
-
};
|
24
|
-
Write: {
|
25
|
-
created_at: Types['Date Time']['Write'];
|
26
|
-
modified_at: Types['Date Time']['Write'];
|
27
|
-
id: Types['Serial']['Write'];
|
28
|
-
uuid: Types['Short Text']['Write'];
|
29
|
-
resource_name: Types['Short Text']['Write'];
|
30
|
-
field_name: Types['Short Text']['Write'];
|
31
|
-
resource_id: Types['Integer']['Write'];
|
32
|
-
upload_id: Types['Short Text']['Write'];
|
33
|
-
file_key: Types['Short Text']['Write'];
|
34
|
-
status: 'pending' | 'completed' | 'cancelled';
|
35
|
-
filename: Types['Short Text']['Write'];
|
36
|
-
content_type: Types['Short Text']['Write'];
|
37
|
-
size: Types['Big Integer']['Write'];
|
38
|
-
chunk_size: Types['Integer']['Write'];
|
39
|
-
expiry_date: Types['Date Time']['Write'];
|
40
|
-
is_created_by__actor: Types['Integer']['Write'] | null;
|
41
|
-
};
|
42
|
-
}
|
43
|
-
|
44
|
-
export default interface $Model {
|
45
|
-
multipart_upload: MultipartUpload;
|
46
|
-
|
47
|
-
|
48
|
-
}
|