@balena/pinejs 21.5.1-build-object-freeze-root-objects-266a461f8ffb383c7c5ae4290263f237d530e42d-1 → 21.6.0-build-add-actions-example-a346f3cb25b768b2b2bbd62bcbc85fbf35eb0908-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 +14 -6
- package/CHANGELOG.md +4 -3
- package/VERSION +1 -1
- package/out/config-loader/config-loader.js +7 -6
- package/out/config-loader/config-loader.js.map +1 -1
- package/out/config-loader/env.d.ts +3 -0
- package/out/config-loader/env.js +3 -0
- package/out/config-loader/env.js.map +1 -1
- package/out/sbvr-api/permissions.d.ts +2 -2
- package/out/sbvr-api/permissions.js +4 -4
- package/out/sbvr-api/permissions.js.map +1 -1
- package/out/server-glue/module.js +2 -0
- package/out/server-glue/module.js.map +1 -1
- package/out/webresource-handler/actions/beginUpload.d.ts +4 -0
- package/out/webresource-handler/actions/beginUpload.js +106 -0
- package/out/webresource-handler/actions/beginUpload.js.map +1 -0
- package/out/webresource-handler/actions/cancelUpload.d.ts +4 -0
- package/out/webresource-handler/actions/cancelUpload.js +61 -0
- package/out/webresource-handler/actions/cancelUpload.js.map +1 -0
- package/out/webresource-handler/actions/commitUpload.d.ts +4 -0
- package/out/webresource-handler/actions/commitUpload.js +88 -0
- package/out/webresource-handler/actions/commitUpload.js.map +1 -0
- package/out/webresource-handler/actions/index.d.ts +4 -0
- package/out/webresource-handler/actions/index.js +5 -0
- package/out/webresource-handler/actions/index.js.map +1 -0
- package/out/webresource-handler/index.d.ts +9 -0
- package/out/webresource-handler/index.js +29 -1
- package/out/webresource-handler/index.js.map +1 -1
- package/out/webresource-handler/multipartUpload.d.ts +4 -0
- package/out/webresource-handler/multipartUpload.js +14 -0
- package/out/webresource-handler/multipartUpload.js.map +1 -0
- package/out/webresource-handler/webresource.d.ts +42 -0
- package/out/webresource-handler/webresource.js +2 -0
- package/out/webresource-handler/webresource.js.map +1 -0
- package/out/webresource-handler/webresource.sbvr +60 -0
- package/package.json +5 -5
- package/src/config-loader/config-loader.ts +8 -8
- package/src/config-loader/env.ts +7 -0
- package/src/sbvr-api/permissions.ts +4 -4
- package/src/server-glue/module.ts +2 -0
- package/src/webresource-handler/actions/beginUpload.ts +165 -0
- package/src/webresource-handler/actions/cancelUpload.ts +95 -0
- package/src/webresource-handler/actions/commitUpload.ts +120 -0
- package/src/webresource-handler/actions/index.ts +5 -0
- package/src/webresource-handler/index.ts +46 -0
- package/src/webresource-handler/multipartUpload.ts +23 -0
- package/src/webresource-handler/webresource.sbvr +60 -0
- package/src/webresource-handler/webresource.ts +48 -0
@@ -0,0 +1,165 @@
|
|
1
|
+
import { api, type Response } from '../../sbvr-api/sbvr-utils.js';
|
2
|
+
import type { MultipartUploadHandler } from '../multipartUpload.js';
|
3
|
+
import { getMultipartUploadHandler } from '../multipartUpload.js';
|
4
|
+
import type { BeginMultipartUploadPayload } from '../index.js';
|
5
|
+
import { getWebResourceFields } from '../index.js';
|
6
|
+
import { BadRequestError, NotImplementedError } from '../../sbvr-api/errors.js';
|
7
|
+
import { permissions, sbvrUtils } from '../../server-glue/module.js';
|
8
|
+
import { randomUUID } from 'crypto';
|
9
|
+
import type { WebResourceType as WebResource } from '@balena/sbvr-types';
|
10
|
+
import type {
|
11
|
+
ODataActionArgs,
|
12
|
+
ODataActionRequest,
|
13
|
+
} from '../../sbvr-api/actions.js';
|
14
|
+
import { ajv } from '../../tasks/common.js';
|
15
|
+
import type { FromSchema } from 'json-schema-to-ts';
|
16
|
+
|
17
|
+
type FakeWebResourcePatch = {
|
18
|
+
[key: string]: Omit<WebResource, 'href'> & {
|
19
|
+
href: 'fake_patch';
|
20
|
+
};
|
21
|
+
};
|
22
|
+
|
23
|
+
const beginUploadPayloadSchema = {
|
24
|
+
type: 'object',
|
25
|
+
minProperties: 1,
|
26
|
+
maxProperties: 1,
|
27
|
+
additionalProperties: {
|
28
|
+
type: 'object',
|
29
|
+
properties: {
|
30
|
+
filename: { type: 'string' },
|
31
|
+
content_type: { type: 'string' },
|
32
|
+
size: { type: 'number' },
|
33
|
+
chunk_size: { type: 'number' },
|
34
|
+
},
|
35
|
+
required: ['filename', 'content_type', 'size'],
|
36
|
+
additionalProperties: false,
|
37
|
+
},
|
38
|
+
} as const;
|
39
|
+
|
40
|
+
const validateBeginUpload = ajv.compile<
|
41
|
+
FromSchema<typeof beginUploadPayloadSchema>
|
42
|
+
>(beginUploadPayloadSchema);
|
43
|
+
|
44
|
+
const beginUploadAction = async ({
|
45
|
+
request,
|
46
|
+
tx,
|
47
|
+
id,
|
48
|
+
req,
|
49
|
+
}: ODataActionArgs): Promise<Response> => {
|
50
|
+
if (typeof id !== 'number') {
|
51
|
+
throw new NotImplementedError(
|
52
|
+
'multipart upload do not yet support non-numeric ids',
|
53
|
+
);
|
54
|
+
}
|
55
|
+
|
56
|
+
const handler = getMultipartUploadHandler();
|
57
|
+
const { fieldName, beginUploadPayload } = parseBeginUpload(request, handler);
|
58
|
+
|
59
|
+
await runFakeDbPatch(request, {
|
60
|
+
[fieldName]: { ...beginUploadPayload, href: 'fake_patch' },
|
61
|
+
});
|
62
|
+
|
63
|
+
const { fileKey, uploadId, uploadParts } =
|
64
|
+
await handler.multipartUpload.begin(fieldName, beginUploadPayload);
|
65
|
+
const uuid = randomUUID();
|
66
|
+
await api.webresource.post({
|
67
|
+
resource: 'multipart_upload',
|
68
|
+
body: {
|
69
|
+
uuid,
|
70
|
+
resource_name: request.resourceName,
|
71
|
+
field_name: fieldName,
|
72
|
+
resource_id: id,
|
73
|
+
upload_id: uploadId,
|
74
|
+
file_key: fileKey,
|
75
|
+
status: 'pending',
|
76
|
+
...beginUploadPayload,
|
77
|
+
expiry_date: Date.now() + 7 * 24 * 60 * 60 * 1000, // 7 days in ms
|
78
|
+
is_created_by__actor: req.user?.actor,
|
79
|
+
},
|
80
|
+
passthrough: {
|
81
|
+
req: permissions.root,
|
82
|
+
tx,
|
83
|
+
},
|
84
|
+
});
|
85
|
+
|
86
|
+
return {
|
87
|
+
body: { [fieldName]: { uuid, uploadParts } },
|
88
|
+
statusCode: 200,
|
89
|
+
};
|
90
|
+
};
|
91
|
+
|
92
|
+
const parseBeginUpload = (
|
93
|
+
request: ODataActionRequest,
|
94
|
+
webResourceHandler: MultipartUploadHandler,
|
95
|
+
) => {
|
96
|
+
const { values } = request;
|
97
|
+
const isValid = validateBeginUpload(values);
|
98
|
+
if (!isValid) {
|
99
|
+
throw new BadRequestError('Invalid begin upload payload');
|
100
|
+
}
|
101
|
+
|
102
|
+
const fieldName = Object.keys(values)[0];
|
103
|
+
|
104
|
+
const webResourceFields = getWebResourceFields(request, false);
|
105
|
+
if (!webResourceFields.includes(fieldName)) {
|
106
|
+
throw new BadRequestError(
|
107
|
+
`The provided field '${fieldName}' is not a valid webresource`,
|
108
|
+
);
|
109
|
+
}
|
110
|
+
const beginUploadPayload = {
|
111
|
+
...values[fieldName],
|
112
|
+
chunk_size:
|
113
|
+
values[fieldName].chunk_size ??
|
114
|
+
webResourceHandler.multipartUpload.getDefaultPartSize(),
|
115
|
+
} satisfies BeginMultipartUploadPayload;
|
116
|
+
|
117
|
+
if (
|
118
|
+
beginUploadPayload.chunk_size <
|
119
|
+
webResourceHandler.multipartUpload.getMinimumPartSize()
|
120
|
+
) {
|
121
|
+
throw new BadRequestError('Chunk size is too small');
|
122
|
+
}
|
123
|
+
|
124
|
+
return {
|
125
|
+
beginUploadPayload,
|
126
|
+
fieldName,
|
127
|
+
};
|
128
|
+
};
|
129
|
+
|
130
|
+
// We want beginUpload to fail if the initial payload would already break any constraint/hooks/rule
|
131
|
+
// this serves as both an optimization and a better client experience as it avoids succeding a beginUpload
|
132
|
+
// (which could allow for potentially very large PartUploads) only for it to fail on commitUpload
|
133
|
+
// The current approach to try to achieve this behavior creates this fake database patch:
|
134
|
+
// It first tries to patch the file metadata (on a separate tx) to something similar to what it would look like
|
135
|
+
// and if it breaks any constraint, then it throws and fail to even start the upload
|
136
|
+
// Note that because the href is only generated at commitUpload time, we need to fake it for the time being
|
137
|
+
// This could potentially be a problem if an application code has a constraint on the href property
|
138
|
+
// However, because this is a internal (pine managed) property we assumed that application code won't do so
|
139
|
+
const runFakeDbPatch = async (
|
140
|
+
request: ODataActionRequest,
|
141
|
+
fakeDbPatch: FakeWebResourcePatch,
|
142
|
+
) => {
|
143
|
+
const fakeTx = await sbvrUtils.db.transaction();
|
144
|
+
try {
|
145
|
+
const newUrl = request.url
|
146
|
+
.slice(1)
|
147
|
+
.split('?', 1)[0]
|
148
|
+
.replace(/\/beginUpload$/, '');
|
149
|
+
|
150
|
+
await api[request.vocabulary].request({
|
151
|
+
method: 'PATCH',
|
152
|
+
url: newUrl,
|
153
|
+
body: fakeDbPatch,
|
154
|
+
// it needs root as otherwise it would always fail as non-root users
|
155
|
+
// are not allowed to directly patch webresource metadata, onnly upload files
|
156
|
+
passthrough: { tx: fakeTx, req: permissions.root },
|
157
|
+
});
|
158
|
+
} finally {
|
159
|
+
if (!fakeTx.isClosed()) {
|
160
|
+
await fakeTx.rollback();
|
161
|
+
}
|
162
|
+
}
|
163
|
+
};
|
164
|
+
|
165
|
+
export default beginUploadAction;
|
@@ -0,0 +1,95 @@
|
|
1
|
+
import type {
|
2
|
+
ODataActionArgs,
|
3
|
+
ODataActionRequest,
|
4
|
+
} from '../../sbvr-api/actions.js';
|
5
|
+
import type { Tx } from '../../database-layer/db.js';
|
6
|
+
import {
|
7
|
+
BadRequestError,
|
8
|
+
NotImplementedError,
|
9
|
+
UnauthorizedError,
|
10
|
+
} from '../../sbvr-api/errors.js';
|
11
|
+
import { api, type Response } from '../../sbvr-api/sbvr-utils.js';
|
12
|
+
import { permissions } from '../../server-glue/module.js';
|
13
|
+
import { getMultipartUploadHandler } from '../multipartUpload.js';
|
14
|
+
|
15
|
+
const cancelUploadAction = async ({
|
16
|
+
request,
|
17
|
+
tx,
|
18
|
+
id: resourceId,
|
19
|
+
}: ODataActionArgs): Promise<Response> => {
|
20
|
+
if (typeof resourceId !== 'number') {
|
21
|
+
throw new NotImplementedError(
|
22
|
+
'multipart upload do not yet support non-numeric ids',
|
23
|
+
);
|
24
|
+
}
|
25
|
+
const { id, fileKey, uploadId } = await getOngoingUpload(
|
26
|
+
request,
|
27
|
+
resourceId,
|
28
|
+
tx,
|
29
|
+
);
|
30
|
+
const handler = getMultipartUploadHandler();
|
31
|
+
|
32
|
+
await api.webresource.patch({
|
33
|
+
resource: 'multipart_upload',
|
34
|
+
body: {
|
35
|
+
status: 'cancelled',
|
36
|
+
},
|
37
|
+
id,
|
38
|
+
passthrough: {
|
39
|
+
tx: tx,
|
40
|
+
req: permissions.root,
|
41
|
+
},
|
42
|
+
});
|
43
|
+
|
44
|
+
// Note that different then beginUpload/commitUpload where we first do the action on the external service
|
45
|
+
// and then reflect it on the DB, for cancel upload it is the other way around
|
46
|
+
// as the worst case scenario is having a canceled upload which is marked on the DB as something else
|
47
|
+
await handler.multipartUpload.cancel({ fileKey, uploadId });
|
48
|
+
|
49
|
+
return {
|
50
|
+
statusCode: 204,
|
51
|
+
};
|
52
|
+
};
|
53
|
+
|
54
|
+
const getOngoingUpload = async (
|
55
|
+
request: ODataActionRequest,
|
56
|
+
affectedId: number,
|
57
|
+
tx: Tx,
|
58
|
+
) => {
|
59
|
+
const { uuid } = request.values;
|
60
|
+
if (uuid == null || typeof uuid !== 'string') {
|
61
|
+
throw new BadRequestError('Invalid uuid type');
|
62
|
+
}
|
63
|
+
|
64
|
+
const multipartUpload = await api.webresource.get({
|
65
|
+
resource: 'multipart_upload',
|
66
|
+
id: {
|
67
|
+
uuid,
|
68
|
+
},
|
69
|
+
options: {
|
70
|
+
$select: ['id', 'file_key', 'upload_id'],
|
71
|
+
$filter: {
|
72
|
+
status: 'pending',
|
73
|
+
expiry_date: { $gt: { $now: {} } },
|
74
|
+
resource_name: request.resourceName,
|
75
|
+
resource_id: affectedId,
|
76
|
+
},
|
77
|
+
},
|
78
|
+
passthrough: {
|
79
|
+
tx,
|
80
|
+
req: permissions.rootRead,
|
81
|
+
},
|
82
|
+
});
|
83
|
+
|
84
|
+
if (multipartUpload == null) {
|
85
|
+
throw new UnauthorizedError();
|
86
|
+
}
|
87
|
+
|
88
|
+
return {
|
89
|
+
id: multipartUpload.id,
|
90
|
+
fileKey: multipartUpload.file_key,
|
91
|
+
uploadId: multipartUpload.upload_id,
|
92
|
+
};
|
93
|
+
};
|
94
|
+
|
95
|
+
export default cancelUploadAction;
|
@@ -0,0 +1,120 @@
|
|
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
|
+
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
|
+
id: {
|
89
|
+
uuid,
|
90
|
+
},
|
91
|
+
options: {
|
92
|
+
$select: ['id', 'file_key', 'upload_id', 'field_name', 'filename'],
|
93
|
+
$filter: {
|
94
|
+
status: 'pending',
|
95
|
+
expiry_date: { $gt: { $now: {} } },
|
96
|
+
resource_name: request.resourceName,
|
97
|
+
resource_id: affectedId,
|
98
|
+
},
|
99
|
+
},
|
100
|
+
passthrough: {
|
101
|
+
tx,
|
102
|
+
req: permissions.rootRead,
|
103
|
+
},
|
104
|
+
});
|
105
|
+
|
106
|
+
if (multipartUpload == null) {
|
107
|
+
throw new UnauthorizedError();
|
108
|
+
}
|
109
|
+
|
110
|
+
return {
|
111
|
+
uuid,
|
112
|
+
providerCommitData,
|
113
|
+
fileKey: multipartUpload.file_key,
|
114
|
+
uploadId: multipartUpload.upload_id,
|
115
|
+
filename: multipartUpload.filename,
|
116
|
+
fieldName: multipartUpload.field_name,
|
117
|
+
};
|
118
|
+
};
|
119
|
+
|
120
|
+
export default commitUploadAction;
|
@@ -11,11 +11,17 @@ import {
|
|
11
11
|
odataNameToSqlName,
|
12
12
|
sqlNameToODataName,
|
13
13
|
} from '@balena/odata-to-abstract-sql';
|
14
|
+
import type { ConfigLoader } from '../server-glue/module.js';
|
14
15
|
import { errors, permissions } from '../server-glue/module.js';
|
15
16
|
import type { WebResourceType as WebResource } from '@balena/sbvr-types';
|
16
17
|
import { TypedError } from 'typed-error';
|
17
18
|
import type { Resolvable } from '../sbvr-api/common-types.js';
|
18
19
|
import { canExecuteTasks } from '../tasks/index.js';
|
20
|
+
import { importSBVR } from '../server-glue/sbvr-loader.js';
|
21
|
+
import type WebresourceModel from './webresource.js';
|
22
|
+
import { isMultipartUploadAvailable } from './multipartUpload.js';
|
23
|
+
import { addAction } from '../sbvr-api/actions.js';
|
24
|
+
import { beginUpload, commitUpload, cancelUpload } from './actions/index.js';
|
19
25
|
|
20
26
|
export * from './handlers/index.js';
|
21
27
|
|
@@ -352,6 +358,13 @@ const throwIfWebresourceNotInMultipart = (
|
|
352
358
|
{ req, request }: HookArgs,
|
353
359
|
) => {
|
354
360
|
if (
|
361
|
+
// root needs to be able to bypass the multipart check as
|
362
|
+
// it needs to pass the direct payload on multipart uploads (on storage provider)
|
363
|
+
req.user !== permissions.root.user &&
|
364
|
+
// This is checking for HTTP multipart form submission/request (e.g. send the actual file via the API)
|
365
|
+
// Not to confuse with multipart uploads
|
366
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/POST#multipart_form_submission
|
367
|
+
// See: https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpuoverview.html
|
355
368
|
!req.is?.('multipart') &&
|
356
369
|
webResourceFields.some((field) => request.values[field] != null)
|
357
370
|
) {
|
@@ -549,3 +562,36 @@ export const setupUploadHooks = (
|
|
549
562
|
getCreateWebResourceHooks(handler),
|
550
563
|
);
|
551
564
|
};
|
565
|
+
|
566
|
+
export const setupUploadActions = (vocab: string, resourceName: string) => {
|
567
|
+
const resource = sqlNameToODataName(resourceName);
|
568
|
+
if (isMultipartUploadAvailable(configuredWebResourceHandler)) {
|
569
|
+
addAction(vocab, resource, 'beginUpload', beginUpload);
|
570
|
+
addAction(vocab, resource, 'commitUpload', commitUpload);
|
571
|
+
addAction(vocab, resource, 'cancelUpload', cancelUpload);
|
572
|
+
}
|
573
|
+
};
|
574
|
+
|
575
|
+
const initSql = `
|
576
|
+
CREATE INDEX IF NOT EXISTS idx_multipart_upload_uuid ON "multipart upload" (uuid);
|
577
|
+
CREATE INDEX IF NOT EXISTS idx_multipart_upload_status ON "multipart upload" (status);
|
578
|
+
`;
|
579
|
+
|
580
|
+
const modelText = await importSBVR('./webresource.sbvr', import.meta);
|
581
|
+
|
582
|
+
declare module '../sbvr-api/sbvr-utils.js' {
|
583
|
+
export interface API {
|
584
|
+
webresource: PinejsClient<WebresourceModel>;
|
585
|
+
}
|
586
|
+
}
|
587
|
+
|
588
|
+
export const config: ConfigLoader.Config = {
|
589
|
+
models: [
|
590
|
+
{
|
591
|
+
modelName: 'webresource',
|
592
|
+
apiRoot: 'webresource',
|
593
|
+
modelText,
|
594
|
+
initSql,
|
595
|
+
},
|
596
|
+
],
|
597
|
+
};
|
@@ -0,0 +1,23 @@
|
|
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
|
+
};
|
@@ -0,0 +1,60 @@
|
|
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
|
@@ -0,0 +1,48 @@
|
|
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
|
+
}
|