@appweaver/client 1.0.22 → 1.0.24
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/cjs/angular/index.d.ts +1 -0
- package/cjs/angular/index.js +17 -0
- package/{clients → cjs/clients}/angular-client.d.ts +7 -1
- package/{clients → cjs/clients}/base-client-interface.d.ts +18 -3
- package/{clients → cjs/clients}/index.d.ts +0 -1
- package/{clients → cjs/clients}/index.js +0 -1
- package/{generators → cjs/generators}/generate-client.js +2 -1
- package/cjs/package.json +3 -0
- package/{weaver-client.js → cjs/weaver-client.js} +1 -1
- package/esm/angular/index.d.ts +1 -0
- package/esm/angular/index.js +1 -0
- package/esm/clients/angular-client.d.ts +26 -0
- package/esm/clients/angular-client.js +53 -0
- package/esm/clients/base-client-interface.d.ts +86 -0
- package/esm/clients/base-client-interface.js +1 -0
- package/esm/clients/base-client.d.ts +216 -0
- package/esm/clients/base-client.js +242 -0
- package/esm/clients/fetch-client.d.ts +6 -0
- package/esm/clients/fetch-client.js +6 -0
- package/esm/clients/index.d.ts +4 -0
- package/esm/clients/index.js +4 -0
- package/esm/clients/modules/account-client.d.ts +69 -0
- package/esm/clients/modules/account-client.js +107 -0
- package/esm/clients/modules/auth-client.d.ts +56 -0
- package/esm/clients/modules/auth-client.js +74 -0
- package/esm/clients/modules/base-module.d.ts +17 -0
- package/esm/clients/modules/base-module.js +49 -0
- package/esm/clients/modules/files-client.d.ts +27 -0
- package/esm/clients/modules/files-client.js +42 -0
- package/esm/clients/modules/health-client.d.ts +25 -0
- package/esm/clients/modules/health-client.js +30 -0
- package/esm/clients/modules/index.d.ts +6 -0
- package/esm/clients/modules/index.js +6 -0
- package/esm/clients/modules/resource-client.d.ts +90 -0
- package/esm/clients/modules/resource-client.js +173 -0
- package/esm/clients/responses/file-data-response.d.ts +78 -0
- package/esm/clients/responses/file-data-response.js +105 -0
- package/esm/clients/responses/index.d.ts +1 -0
- package/esm/clients/responses/index.js +1 -0
- package/esm/commands/generate-command.d.ts +3 -0
- package/esm/commands/generate-command.js +122 -0
- package/esm/commands/index.d.ts +1 -0
- package/esm/commands/index.js +1 -0
- package/esm/constants.d.ts +67 -0
- package/esm/constants.js +94 -0
- package/esm/errors/client-error.d.ts +6 -0
- package/esm/errors/client-error.js +11 -0
- package/esm/errors/index.d.ts +1 -0
- package/esm/errors/index.js +1 -0
- package/esm/generators/generate-client.d.ts +16 -0
- package/esm/generators/generate-client.js +399 -0
- package/esm/generators/generate-types.d.ts +9 -0
- package/esm/generators/generate-types.js +486 -0
- package/esm/generators/index.d.ts +2 -0
- package/esm/generators/index.js +2 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.js +2 -0
- package/esm/package.json +3 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/routes.d.ts +15 -0
- package/esm/types/routes.js +1 -0
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.js +1 -0
- package/esm/utils/schema-util.d.ts +3 -0
- package/esm/utils/schema-util.js +39 -0
- package/package.json +39 -7
- /package/{clients → cjs/clients}/angular-client.js +0 -0
- /package/{clients → cjs/clients}/base-client-interface.js +0 -0
- /package/{clients → cjs/clients}/base-client.d.ts +0 -0
- /package/{clients → cjs/clients}/base-client.js +0 -0
- /package/{clients → cjs/clients}/fetch-client.d.ts +0 -0
- /package/{clients → cjs/clients}/fetch-client.js +0 -0
- /package/{clients → cjs/clients}/modules/account-client.d.ts +0 -0
- /package/{clients → cjs/clients}/modules/account-client.js +0 -0
- /package/{clients → cjs/clients}/modules/auth-client.d.ts +0 -0
- /package/{clients → cjs/clients}/modules/auth-client.js +0 -0
- /package/{clients → cjs/clients}/modules/base-module.d.ts +0 -0
- /package/{clients → cjs/clients}/modules/base-module.js +0 -0
- /package/{clients → cjs/clients}/modules/files-client.d.ts +0 -0
- /package/{clients → cjs/clients}/modules/files-client.js +0 -0
- /package/{clients → cjs/clients}/modules/health-client.d.ts +0 -0
- /package/{clients → cjs/clients}/modules/health-client.js +0 -0
- /package/{clients → cjs/clients}/modules/index.d.ts +0 -0
- /package/{clients → cjs/clients}/modules/index.js +0 -0
- /package/{clients → cjs/clients}/modules/resource-client.d.ts +0 -0
- /package/{clients → cjs/clients}/modules/resource-client.js +0 -0
- /package/{clients → cjs/clients}/responses/file-data-response.d.ts +0 -0
- /package/{clients → cjs/clients}/responses/file-data-response.js +0 -0
- /package/{clients → cjs/clients}/responses/index.d.ts +0 -0
- /package/{clients → cjs/clients}/responses/index.js +0 -0
- /package/{commands → cjs/commands}/generate-command.d.ts +0 -0
- /package/{commands → cjs/commands}/generate-command.js +0 -0
- /package/{commands → cjs/commands}/index.d.ts +0 -0
- /package/{commands → cjs/commands}/index.js +0 -0
- /package/{constants.d.ts → cjs/constants.d.ts} +0 -0
- /package/{constants.js → cjs/constants.js} +0 -0
- /package/{errors → cjs/errors}/client-error.d.ts +0 -0
- /package/{errors → cjs/errors}/client-error.js +0 -0
- /package/{errors → cjs/errors}/index.d.ts +0 -0
- /package/{errors → cjs/errors}/index.js +0 -0
- /package/{generators → cjs/generators}/generate-client.d.ts +0 -0
- /package/{generators → cjs/generators}/generate-types.d.ts +0 -0
- /package/{generators → cjs/generators}/generate-types.js +0 -0
- /package/{generators → cjs/generators}/index.d.ts +0 -0
- /package/{generators → cjs/generators}/index.js +0 -0
- /package/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/{index.js → cjs/index.js} +0 -0
- /package/{types → cjs/types}/index.d.ts +0 -0
- /package/{types → cjs/types}/index.js +0 -0
- /package/{types → cjs/types}/routes.d.ts +0 -0
- /package/{types → cjs/types}/routes.js +0 -0
- /package/{utils → cjs/utils}/index.d.ts +0 -0
- /package/{utils → cjs/utils}/index.js +0 -0
- /package/{utils → cjs/utils}/schema-util.d.ts +0 -0
- /package/{utils → cjs/utils}/schema-util.js +0 -0
- /package/{weaver-client.d.ts → cjs/weaver-client.d.ts} +0 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { BaseModule } from './base-module.js';
|
|
2
|
+
export class FilesClient extends BaseModule {
|
|
3
|
+
basePath;
|
|
4
|
+
constructor(client, basePath) {
|
|
5
|
+
super(client);
|
|
6
|
+
this.basePath = basePath;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Downloads a publicly accessible file by its path/name.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} fileName - The path or name of the file to retrieve from the public storage.
|
|
12
|
+
* @param {RequestOptions} options - Additional request options.
|
|
13
|
+
* @returns {@link FileDataResponse} containing the readable stream and file metadata.
|
|
14
|
+
*/
|
|
15
|
+
async public(fileName, options = {}) {
|
|
16
|
+
const { error, response } = await this.sendRequestRaw('get', `${this.basePath}/public/${fileName}`, {
|
|
17
|
+
...options,
|
|
18
|
+
parseAs: 'stream'
|
|
19
|
+
});
|
|
20
|
+
if (error) {
|
|
21
|
+
this.handleError(error, response);
|
|
22
|
+
}
|
|
23
|
+
return this.toFileResponse(response, fileName);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Downloads a protected file by its path/name. Requires the request to be authenticated.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} fileName - The path or name of the file to retrieve from the protected storage.
|
|
29
|
+
* @param {RequestOptions} options - Additional request options.
|
|
30
|
+
* @returns {@link FileDataResponse} containing the readable stream and file metadata.
|
|
31
|
+
*/
|
|
32
|
+
async protected(fileName, options = {}) {
|
|
33
|
+
const { error, response } = await this.sendRequestRaw('get', `${this.basePath}/protected/${fileName}`, {
|
|
34
|
+
...options,
|
|
35
|
+
parseAs: 'stream'
|
|
36
|
+
});
|
|
37
|
+
if (error) {
|
|
38
|
+
this.handleError(error, response);
|
|
39
|
+
}
|
|
40
|
+
return this.toFileResponse(response, fileName);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseModule, RequestOptions } from './base-module.js';
|
|
2
|
+
import { BaseClientInterface } from '../base-client-interface.js';
|
|
3
|
+
import { HEALTH_OPERATIONS, HEALTH_TYPES } from '../../constants.js';
|
|
4
|
+
export type HealthType = Record<(typeof HEALTH_TYPES)[number], unknown>;
|
|
5
|
+
export type HealthInterface = {
|
|
6
|
+
[K in keyof typeof HEALTH_OPERATIONS]: (...args: any[]) => Promise<any>;
|
|
7
|
+
};
|
|
8
|
+
export declare class HealthClient<Health extends HealthType> extends BaseModule implements HealthInterface {
|
|
9
|
+
readonly basePath: string;
|
|
10
|
+
constructor(client: BaseClientInterface, basePath: string);
|
|
11
|
+
/**
|
|
12
|
+
* Performs a basic health check against the server.
|
|
13
|
+
*
|
|
14
|
+
* @param {RequestOptions} options - Additional request options.
|
|
15
|
+
* @returns The health check response indicating overall server and it's services status.
|
|
16
|
+
*/
|
|
17
|
+
check(options?: RequestOptions): Promise<Health['checkResponse']>;
|
|
18
|
+
/**
|
|
19
|
+
* Checks whether the server is ready to accept traffic (e.g., database connected, migrations applied).
|
|
20
|
+
*
|
|
21
|
+
* @param {RequestOptions} options - Additional request options.
|
|
22
|
+
* @returns The readiness response indicating whether the server is fully operational.
|
|
23
|
+
*/
|
|
24
|
+
ready(options?: RequestOptions): Promise<Health['readyResponse']>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseModule } from './base-module.js';
|
|
2
|
+
export class HealthClient extends BaseModule {
|
|
3
|
+
basePath;
|
|
4
|
+
constructor(client, basePath) {
|
|
5
|
+
super(client);
|
|
6
|
+
this.basePath = basePath;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Performs a basic health check against the server.
|
|
10
|
+
*
|
|
11
|
+
* @param {RequestOptions} options - Additional request options.
|
|
12
|
+
* @returns The health check response indicating overall server and it's services status.
|
|
13
|
+
*/
|
|
14
|
+
async check(options = {}) {
|
|
15
|
+
const { data, error, response } = await this.sendRequestRaw('get', `${this.basePath}/check`, options);
|
|
16
|
+
if (error && response.status !== 503) {
|
|
17
|
+
this.handleError(error, response);
|
|
18
|
+
}
|
|
19
|
+
return data ?? error;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Checks whether the server is ready to accept traffic (e.g., database connected, migrations applied).
|
|
23
|
+
*
|
|
24
|
+
* @param {RequestOptions} options - Additional request options.
|
|
25
|
+
* @returns The readiness response indicating whether the server is fully operational.
|
|
26
|
+
*/
|
|
27
|
+
async ready(options = {}) {
|
|
28
|
+
return this.sendRequest('get', `${this.basePath}/ready`, options);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { BaseModule, RequestOptions } from './base-module.js';
|
|
2
|
+
import { BaseClientInterface } from '../base-client-interface.js';
|
|
3
|
+
import { FileDataResponse } from '../responses/index.js';
|
|
4
|
+
import { RESOURCE_OPERATIONS, RESOURCE_TYPES } from '../../constants.js';
|
|
5
|
+
export type ResourceType = Record<(typeof RESOURCE_TYPES)[number], unknown>;
|
|
6
|
+
export type ResourceInterface = {
|
|
7
|
+
[K in keyof typeof RESOURCE_OPERATIONS]: (...args: any[]) => Promise<any>;
|
|
8
|
+
};
|
|
9
|
+
export declare class ResourceClient<Resource extends ResourceType> extends BaseModule implements ResourceInterface {
|
|
10
|
+
readonly basePath: string;
|
|
11
|
+
constructor(client: BaseClientInterface, basePath: string);
|
|
12
|
+
/**
|
|
13
|
+
* Fetches a single resource by its numeric ID.
|
|
14
|
+
*
|
|
15
|
+
* @param {number} id - The ID of the resource to retrieve.
|
|
16
|
+
* @param {RequestOptions} options - Additional request options (headers, query params, etc.).
|
|
17
|
+
* @returns The resource record matching the given ID.
|
|
18
|
+
*/
|
|
19
|
+
find(id: number, options?: RequestOptions): Promise<Resource['single']>;
|
|
20
|
+
/**
|
|
21
|
+
* Executes a query against the resource collection.
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} request - The query payload (filters, sorting, pagination, etc.).
|
|
24
|
+
* @param {RequestOptions} options - Additional request options.
|
|
25
|
+
* @returns A paginated or filtered list of matching resource records.
|
|
26
|
+
*/
|
|
27
|
+
query(request: Resource['queryRequest'], options?: RequestOptions): Promise<Resource['queryResponse']>;
|
|
28
|
+
/**
|
|
29
|
+
* Runs an aggregation query (e.g., count, sum, avg) against the resource collection.
|
|
30
|
+
*
|
|
31
|
+
* @param {Object} request - The aggregation payload describing the desired computation.
|
|
32
|
+
* @param {RequestOptions} options - Additional request options.
|
|
33
|
+
* @returns The aggregated result for the given query.
|
|
34
|
+
*/
|
|
35
|
+
aggregate(request: Resource['aggregateRequest'], options?: RequestOptions): Promise<Resource['aggregateResponse']>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new resource record.
|
|
38
|
+
*
|
|
39
|
+
* @param {Object} resource - The data for the resource to create.
|
|
40
|
+
* @param {RequestOptions} options - Additional request options.
|
|
41
|
+
* @returns The newly created resource record.
|
|
42
|
+
*/
|
|
43
|
+
create(resource: Resource['create'], options?: RequestOptions): Promise<Resource['single']>;
|
|
44
|
+
/**
|
|
45
|
+
* Updates an existing resource record identified by `id`.
|
|
46
|
+
*
|
|
47
|
+
* @param {Object} resource - The updated field values including the mandatory `id`.
|
|
48
|
+
* @param {RequestOptions} options - Additional request options.
|
|
49
|
+
* @returns The updated resource record.
|
|
50
|
+
*/
|
|
51
|
+
update(resource: Resource['update'] & {
|
|
52
|
+
id: number;
|
|
53
|
+
}, options?: RequestOptions): Promise<Resource['single']>;
|
|
54
|
+
/**
|
|
55
|
+
* Deletes a resource record by its numeric ID.
|
|
56
|
+
*
|
|
57
|
+
* @param {number} id - The ID of the resource to delete.
|
|
58
|
+
* @param {RequestOptions} options - Additional request options.
|
|
59
|
+
* @returns The deleted resource record.
|
|
60
|
+
*/
|
|
61
|
+
delete(id: number, options?: RequestOptions): Promise<Resource['single']>;
|
|
62
|
+
/**
|
|
63
|
+
* Exports resource records as a file (e.g., CSV) and returns a streaming response.
|
|
64
|
+
*
|
|
65
|
+
* @param {Object} request - The export request payload (filters, format, etc.).
|
|
66
|
+
* @param {RequestOptions} options - Additional request options.
|
|
67
|
+
* @returns {@link FileDataResponse} containing the readable stream and file metadata.
|
|
68
|
+
*/
|
|
69
|
+
export(request: Resource['exportRequest'], options?: RequestOptions): Promise<FileDataResponse>;
|
|
70
|
+
/**
|
|
71
|
+
* Uploads one or more files to the resource record.
|
|
72
|
+
*
|
|
73
|
+
* Each entry in `files` maps a field name to a single `File` or an array of `File` objects.
|
|
74
|
+
*
|
|
75
|
+
* @param {number} id - The ID of the resource for which to upload files.
|
|
76
|
+
* @param {Object} files - A map of field names to the file(s) to upload.
|
|
77
|
+
* @param {RequestOptions} options - Additional request options.
|
|
78
|
+
* @returns The updated file metadata for the resource.
|
|
79
|
+
*/
|
|
80
|
+
uploadFiles(id: number, files: Resource['fileUpload'], options?: RequestOptions): Promise<Resource['files']>;
|
|
81
|
+
/**
|
|
82
|
+
* Removes specific files from the resource record.
|
|
83
|
+
*
|
|
84
|
+
* @param {number} id - The ID of the resource for which to delete files.
|
|
85
|
+
* @param {Object} files - The file deletion payload identifying which files to remove.
|
|
86
|
+
* @param {RequestOptions} options - Additional request options.
|
|
87
|
+
* @returns The updated file metadata for the resource after deletion.
|
|
88
|
+
*/
|
|
89
|
+
deleteFiles(id: number, files: Resource['fileDelete'], options?: RequestOptions): Promise<Resource['files']>;
|
|
90
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { BaseModule } from './base-module.js';
|
|
2
|
+
export class ResourceClient extends BaseModule {
|
|
3
|
+
basePath;
|
|
4
|
+
constructor(client, basePath) {
|
|
5
|
+
super(client);
|
|
6
|
+
this.basePath = basePath;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Fetches a single resource by its numeric ID.
|
|
10
|
+
*
|
|
11
|
+
* @param {number} id - The ID of the resource to retrieve.
|
|
12
|
+
* @param {RequestOptions} options - Additional request options (headers, query params, etc.).
|
|
13
|
+
* @returns The resource record matching the given ID.
|
|
14
|
+
*/
|
|
15
|
+
async find(id, options = {}) {
|
|
16
|
+
return this.sendRequest('get', `${this.basePath}/{id}`, {
|
|
17
|
+
...options,
|
|
18
|
+
params: {
|
|
19
|
+
...(options.params ?? {}),
|
|
20
|
+
path: {
|
|
21
|
+
id
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Executes a query against the resource collection.
|
|
28
|
+
*
|
|
29
|
+
* @param {Object} request - The query payload (filters, sorting, pagination, etc.).
|
|
30
|
+
* @param {RequestOptions} options - Additional request options.
|
|
31
|
+
* @returns A paginated or filtered list of matching resource records.
|
|
32
|
+
*/
|
|
33
|
+
async query(request, options = {}) {
|
|
34
|
+
return this.sendRequest('post', `${this.basePath}/query`, {
|
|
35
|
+
...options,
|
|
36
|
+
body: request
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Runs an aggregation query (e.g., count, sum, avg) against the resource collection.
|
|
41
|
+
*
|
|
42
|
+
* @param {Object} request - The aggregation payload describing the desired computation.
|
|
43
|
+
* @param {RequestOptions} options - Additional request options.
|
|
44
|
+
* @returns The aggregated result for the given query.
|
|
45
|
+
*/
|
|
46
|
+
async aggregate(request, options = {}) {
|
|
47
|
+
return this.sendRequest('post', `${this.basePath}/aggregate`, {
|
|
48
|
+
...options,
|
|
49
|
+
body: request
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates a new resource record.
|
|
54
|
+
*
|
|
55
|
+
* @param {Object} resource - The data for the resource to create.
|
|
56
|
+
* @param {RequestOptions} options - Additional request options.
|
|
57
|
+
* @returns The newly created resource record.
|
|
58
|
+
*/
|
|
59
|
+
async create(resource, options = {}) {
|
|
60
|
+
return this.sendRequest('post', `${this.basePath}`, {
|
|
61
|
+
...options,
|
|
62
|
+
body: resource
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Updates an existing resource record identified by `id`.
|
|
67
|
+
*
|
|
68
|
+
* @param {Object} resource - The updated field values including the mandatory `id`.
|
|
69
|
+
* @param {RequestOptions} options - Additional request options.
|
|
70
|
+
* @returns The updated resource record.
|
|
71
|
+
*/
|
|
72
|
+
async update(resource, options = {}) {
|
|
73
|
+
return this.sendRequest('put', `${this.basePath}/{id}`, {
|
|
74
|
+
...options,
|
|
75
|
+
params: {
|
|
76
|
+
...(options.params ?? {}),
|
|
77
|
+
path: {
|
|
78
|
+
id: resource['id']
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
body: resource
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Deletes a resource record by its numeric ID.
|
|
86
|
+
*
|
|
87
|
+
* @param {number} id - The ID of the resource to delete.
|
|
88
|
+
* @param {RequestOptions} options - Additional request options.
|
|
89
|
+
* @returns The deleted resource record.
|
|
90
|
+
*/
|
|
91
|
+
async delete(id, options = {}) {
|
|
92
|
+
return this.sendRequest('delete', `${this.basePath}/{id}`, {
|
|
93
|
+
...options,
|
|
94
|
+
params: {
|
|
95
|
+
...(options.params ?? {}),
|
|
96
|
+
path: {
|
|
97
|
+
id
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Exports resource records as a file (e.g., CSV) and returns a streaming response.
|
|
104
|
+
*
|
|
105
|
+
* @param {Object} request - The export request payload (filters, format, etc.).
|
|
106
|
+
* @param {RequestOptions} options - Additional request options.
|
|
107
|
+
* @returns {@link FileDataResponse} containing the readable stream and file metadata.
|
|
108
|
+
*/
|
|
109
|
+
async export(request, options = {}) {
|
|
110
|
+
const { error, response } = await this.sendRequestRaw('post', `${this.basePath}/export`, {
|
|
111
|
+
...options,
|
|
112
|
+
parseAs: 'stream',
|
|
113
|
+
body: request
|
|
114
|
+
});
|
|
115
|
+
if (error) {
|
|
116
|
+
this.handleError(error, response);
|
|
117
|
+
}
|
|
118
|
+
return this.toFileResponse(response);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Uploads one or more files to the resource record.
|
|
122
|
+
*
|
|
123
|
+
* Each entry in `files` maps a field name to a single `File` or an array of `File` objects.
|
|
124
|
+
*
|
|
125
|
+
* @param {number} id - The ID of the resource for which to upload files.
|
|
126
|
+
* @param {Object} files - A map of field names to the file(s) to upload.
|
|
127
|
+
* @param {RequestOptions} options - Additional request options.
|
|
128
|
+
* @returns The updated file metadata for the resource.
|
|
129
|
+
*/
|
|
130
|
+
async uploadFiles(id, files, options = {}) {
|
|
131
|
+
const formData = new FormData();
|
|
132
|
+
for (const [fieldName, fileData] of Object.entries(files)) {
|
|
133
|
+
if (Array.isArray(fileData)) {
|
|
134
|
+
for (const file of fileData) {
|
|
135
|
+
formData.append(fieldName, file);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
formData.append(fieldName, fileData);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return this.sendRequest('post', `${this.basePath}/{id}/files`, {
|
|
143
|
+
...options,
|
|
144
|
+
body: formData,
|
|
145
|
+
params: {
|
|
146
|
+
...(options.params ?? {}),
|
|
147
|
+
path: {
|
|
148
|
+
id
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Removes specific files from the resource record.
|
|
155
|
+
*
|
|
156
|
+
* @param {number} id - The ID of the resource for which to delete files.
|
|
157
|
+
* @param {Object} files - The file deletion payload identifying which files to remove.
|
|
158
|
+
* @param {RequestOptions} options - Additional request options.
|
|
159
|
+
* @returns The updated file metadata for the resource after deletion.
|
|
160
|
+
*/
|
|
161
|
+
async deleteFiles(id, files, options = {}) {
|
|
162
|
+
return this.sendRequest('post', `${this.basePath}/{id}/delete-files`, {
|
|
163
|
+
...options,
|
|
164
|
+
body: files,
|
|
165
|
+
params: {
|
|
166
|
+
...(options.params ?? {}),
|
|
167
|
+
path: {
|
|
168
|
+
id
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response object containing file data and metadata from a file download request.
|
|
3
|
+
* Provides helper methods to consume the stream as text, base64 data URL, or Buffer.
|
|
4
|
+
*/
|
|
5
|
+
export declare class FileDataResponse {
|
|
6
|
+
/** Readable stream of the file content. */
|
|
7
|
+
readonly stream: ReadableStream;
|
|
8
|
+
/** Name of the file extracted from the Content-Disposition header or provided default. */
|
|
9
|
+
readonly fileName: string;
|
|
10
|
+
/** MIME type of the file from the Content-Type header. */
|
|
11
|
+
readonly type: string;
|
|
12
|
+
/** Size of the file in bytes from the Content-Length header. */
|
|
13
|
+
readonly length: number;
|
|
14
|
+
/** Range information if the response is a partial content response (HTTP 206). */
|
|
15
|
+
readonly range?: FileContentRange;
|
|
16
|
+
/** Cache duration in seconds from the Cache-Control max-age directive. */
|
|
17
|
+
readonly maxAge?: number;
|
|
18
|
+
/** Expiration timestamp from Expires header. */
|
|
19
|
+
readonly expiresAt?: string;
|
|
20
|
+
private _buffer;
|
|
21
|
+
constructor(data: {
|
|
22
|
+
stream: ReadableStream;
|
|
23
|
+
fileName: string;
|
|
24
|
+
type: string;
|
|
25
|
+
length: number;
|
|
26
|
+
range?: FileContentRange;
|
|
27
|
+
maxAge?: number;
|
|
28
|
+
expiresAt?: string;
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* Reads and returns the content of the buffer as an ArrayBuffer.
|
|
32
|
+
*
|
|
33
|
+
* @return {Promise<ArrayBuffer>} A promise that resolves to an ArrayBuffer containing the data read from the buffer.
|
|
34
|
+
*/
|
|
35
|
+
buffer(): Promise<ArrayBuffer>;
|
|
36
|
+
/**
|
|
37
|
+
* Reads and returns the content of the buffer as a Blob object.
|
|
38
|
+
*
|
|
39
|
+
* The method reads an ArrayBuffer from an internal data source, then constructs,
|
|
40
|
+
* and returns a Blob object using the buffer's content and a specified MIME type.
|
|
41
|
+
*
|
|
42
|
+
* @return {Promise<Blob>} A promise that resolves to a Blob object containing the read data.
|
|
43
|
+
*/
|
|
44
|
+
blob(): Promise<Blob>;
|
|
45
|
+
/**
|
|
46
|
+
* Reads and decodes the content of the buffer into a string using the TextDecoder API.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} encoding - The character encoding to use for decoding. Defaults to 'utf-8'.
|
|
49
|
+
* @return {Promise<string>} A promise that resolves to the decoded string.
|
|
50
|
+
*/
|
|
51
|
+
text(encoding?: string): Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Reads and converts the buffer into a Base64-encoded data URL string.
|
|
54
|
+
*
|
|
55
|
+
* @return {Promise<string>} A promise that resolves to a Base64-encoded string
|
|
56
|
+
* representing the file, prefixed with the appropriate data MIME type.
|
|
57
|
+
*/
|
|
58
|
+
base64(): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Reads and concatenates data chunks from a readable stream into a single ArrayBuffer.
|
|
61
|
+
* If the buffer has already been read, it returns the cached ArrayBuffer.
|
|
62
|
+
*
|
|
63
|
+
* @return {Promise<ArrayBuffer>} A promise that resolves to the ArrayBuffer containing
|
|
64
|
+
* the concatenated data from the stream.
|
|
65
|
+
*/
|
|
66
|
+
private _readArrayBuffer;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Represents byte range information for partial content responses.
|
|
70
|
+
*/
|
|
71
|
+
export type FileContentRange = {
|
|
72
|
+
/** Starting byte position of the range (inclusive). */
|
|
73
|
+
start: number;
|
|
74
|
+
/** Ending byte position of the range (inclusive). */
|
|
75
|
+
end: number;
|
|
76
|
+
/** Total size of the complete file in bytes. */
|
|
77
|
+
total: number;
|
|
78
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response object containing file data and metadata from a file download request.
|
|
3
|
+
* Provides helper methods to consume the stream as text, base64 data URL, or Buffer.
|
|
4
|
+
*/
|
|
5
|
+
export class FileDataResponse {
|
|
6
|
+
/** Readable stream of the file content. */
|
|
7
|
+
stream;
|
|
8
|
+
/** Name of the file extracted from the Content-Disposition header or provided default. */
|
|
9
|
+
fileName;
|
|
10
|
+
/** MIME type of the file from the Content-Type header. */
|
|
11
|
+
type;
|
|
12
|
+
/** Size of the file in bytes from the Content-Length header. */
|
|
13
|
+
length;
|
|
14
|
+
/** Range information if the response is a partial content response (HTTP 206). */
|
|
15
|
+
range;
|
|
16
|
+
/** Cache duration in seconds from the Cache-Control max-age directive. */
|
|
17
|
+
maxAge;
|
|
18
|
+
/** Expiration timestamp from Expires header. */
|
|
19
|
+
expiresAt;
|
|
20
|
+
_buffer;
|
|
21
|
+
constructor(data) {
|
|
22
|
+
this.stream = data.stream;
|
|
23
|
+
this.fileName = data.fileName;
|
|
24
|
+
this.type = data.type;
|
|
25
|
+
this.length = data.length;
|
|
26
|
+
this.range = data.range;
|
|
27
|
+
this.maxAge = data.maxAge;
|
|
28
|
+
this.expiresAt = data.expiresAt;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Reads and returns the content of the buffer as an ArrayBuffer.
|
|
32
|
+
*
|
|
33
|
+
* @return {Promise<ArrayBuffer>} A promise that resolves to an ArrayBuffer containing the data read from the buffer.
|
|
34
|
+
*/
|
|
35
|
+
async buffer() {
|
|
36
|
+
return this._readArrayBuffer();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Reads and returns the content of the buffer as a Blob object.
|
|
40
|
+
*
|
|
41
|
+
* The method reads an ArrayBuffer from an internal data source, then constructs,
|
|
42
|
+
* and returns a Blob object using the buffer's content and a specified MIME type.
|
|
43
|
+
*
|
|
44
|
+
* @return {Promise<Blob>} A promise that resolves to a Blob object containing the read data.
|
|
45
|
+
*/
|
|
46
|
+
async blob() {
|
|
47
|
+
const buf = await this._readArrayBuffer();
|
|
48
|
+
return new Blob([buf], { type: this.type });
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Reads and decodes the content of the buffer into a string using the TextDecoder API.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} encoding - The character encoding to use for decoding. Defaults to 'utf-8'.
|
|
54
|
+
* @return {Promise<string>} A promise that resolves to the decoded string.
|
|
55
|
+
*/
|
|
56
|
+
async text(encoding = 'utf-8') {
|
|
57
|
+
const buf = await this._readArrayBuffer();
|
|
58
|
+
return new TextDecoder(encoding).decode(buf);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Reads and converts the buffer into a Base64-encoded data URL string.
|
|
62
|
+
*
|
|
63
|
+
* @return {Promise<string>} A promise that resolves to a Base64-encoded string
|
|
64
|
+
* representing the file, prefixed with the appropriate data MIME type.
|
|
65
|
+
*/
|
|
66
|
+
async base64() {
|
|
67
|
+
const buf = await this._readArrayBuffer();
|
|
68
|
+
const bytes = new Uint8Array(buf);
|
|
69
|
+
let binary = '';
|
|
70
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
71
|
+
binary += String.fromCharCode(bytes[i]);
|
|
72
|
+
}
|
|
73
|
+
const encoded = btoa(binary);
|
|
74
|
+
return `data:${this.type};base64,${encoded}`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Reads and concatenates data chunks from a readable stream into a single ArrayBuffer.
|
|
78
|
+
* If the buffer has already been read, it returns the cached ArrayBuffer.
|
|
79
|
+
*
|
|
80
|
+
* @return {Promise<ArrayBuffer>} A promise that resolves to the ArrayBuffer containing
|
|
81
|
+
* the concatenated data from the stream.
|
|
82
|
+
*/
|
|
83
|
+
async _readArrayBuffer() {
|
|
84
|
+
if (this._buffer !== undefined) {
|
|
85
|
+
return this._buffer;
|
|
86
|
+
}
|
|
87
|
+
const reader = this.stream.getReader();
|
|
88
|
+
const chunks = [];
|
|
89
|
+
while (true) {
|
|
90
|
+
const { done, value } = await reader.read();
|
|
91
|
+
if (done)
|
|
92
|
+
break;
|
|
93
|
+
chunks.push(value);
|
|
94
|
+
}
|
|
95
|
+
const totalLength = chunks.reduce((sum, c) => sum + c.byteLength, 0);
|
|
96
|
+
const result = new Uint8Array(totalLength);
|
|
97
|
+
let offset = 0;
|
|
98
|
+
for (const chunk of chunks) {
|
|
99
|
+
result.set(chunk, offset);
|
|
100
|
+
offset += chunk.byteLength;
|
|
101
|
+
}
|
|
102
|
+
this._buffer = result.buffer;
|
|
103
|
+
return this._buffer;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './file-data-response.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './file-data-response.js';
|