@appweaver/client 1.0.23 → 1.0.25

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.
Files changed (117) hide show
  1. package/cjs/package.json +3 -0
  2. package/{weaver-client.js → cjs/weaver-client.js} +1 -1
  3. package/esm/angular/index.d.ts +1 -0
  4. package/esm/angular/index.js +1 -0
  5. package/esm/clients/angular-client.d.ts +26 -0
  6. package/esm/clients/angular-client.js +53 -0
  7. package/esm/clients/base-client-interface.d.ts +86 -0
  8. package/esm/clients/base-client-interface.js +1 -0
  9. package/esm/clients/base-client.d.ts +216 -0
  10. package/esm/clients/base-client.js +242 -0
  11. package/esm/clients/fetch-client.d.ts +6 -0
  12. package/esm/clients/fetch-client.js +6 -0
  13. package/esm/clients/index.d.ts +4 -0
  14. package/esm/clients/index.js +4 -0
  15. package/esm/clients/modules/account-client.d.ts +69 -0
  16. package/esm/clients/modules/account-client.js +107 -0
  17. package/esm/clients/modules/auth-client.d.ts +56 -0
  18. package/esm/clients/modules/auth-client.js +74 -0
  19. package/esm/clients/modules/base-module.d.ts +17 -0
  20. package/esm/clients/modules/base-module.js +49 -0
  21. package/esm/clients/modules/files-client.d.ts +27 -0
  22. package/esm/clients/modules/files-client.js +42 -0
  23. package/esm/clients/modules/health-client.d.ts +25 -0
  24. package/esm/clients/modules/health-client.js +30 -0
  25. package/esm/clients/modules/index.d.ts +6 -0
  26. package/esm/clients/modules/index.js +6 -0
  27. package/esm/clients/modules/resource-client.d.ts +90 -0
  28. package/esm/clients/modules/resource-client.js +173 -0
  29. package/esm/clients/responses/file-data-response.d.ts +78 -0
  30. package/esm/clients/responses/file-data-response.js +105 -0
  31. package/esm/clients/responses/index.d.ts +1 -0
  32. package/esm/clients/responses/index.js +1 -0
  33. package/esm/commands/generate-command.d.ts +3 -0
  34. package/esm/commands/generate-command.js +122 -0
  35. package/esm/commands/index.d.ts +1 -0
  36. package/esm/commands/index.js +1 -0
  37. package/esm/constants.d.ts +67 -0
  38. package/esm/constants.js +94 -0
  39. package/esm/errors/client-error.d.ts +6 -0
  40. package/esm/errors/client-error.js +11 -0
  41. package/esm/errors/index.d.ts +1 -0
  42. package/esm/errors/index.js +1 -0
  43. package/esm/generators/generate-client.d.ts +16 -0
  44. package/esm/generators/generate-client.js +399 -0
  45. package/esm/generators/generate-types.d.ts +9 -0
  46. package/esm/generators/generate-types.js +486 -0
  47. package/esm/generators/index.d.ts +2 -0
  48. package/esm/generators/index.js +2 -0
  49. package/esm/index.d.ts +2 -0
  50. package/esm/index.js +2 -0
  51. package/esm/package.json +3 -0
  52. package/esm/types/index.d.ts +1 -0
  53. package/esm/types/index.js +1 -0
  54. package/esm/types/routes.d.ts +15 -0
  55. package/esm/types/routes.js +1 -0
  56. package/esm/utils/index.d.ts +1 -0
  57. package/esm/utils/index.js +1 -0
  58. package/esm/utils/schema-util.d.ts +3 -0
  59. package/esm/utils/schema-util.js +39 -0
  60. package/package.json +29 -5
  61. /package/{angular → cjs/angular}/index.d.ts +0 -0
  62. /package/{angular → cjs/angular}/index.js +0 -0
  63. /package/{clients → cjs/clients}/angular-client.d.ts +0 -0
  64. /package/{clients → cjs/clients}/angular-client.js +0 -0
  65. /package/{clients → cjs/clients}/base-client-interface.d.ts +0 -0
  66. /package/{clients → cjs/clients}/base-client-interface.js +0 -0
  67. /package/{clients → cjs/clients}/base-client.d.ts +0 -0
  68. /package/{clients → cjs/clients}/base-client.js +0 -0
  69. /package/{clients → cjs/clients}/fetch-client.d.ts +0 -0
  70. /package/{clients → cjs/clients}/fetch-client.js +0 -0
  71. /package/{clients → cjs/clients}/index.d.ts +0 -0
  72. /package/{clients → cjs/clients}/index.js +0 -0
  73. /package/{clients → cjs/clients}/modules/account-client.d.ts +0 -0
  74. /package/{clients → cjs/clients}/modules/account-client.js +0 -0
  75. /package/{clients → cjs/clients}/modules/auth-client.d.ts +0 -0
  76. /package/{clients → cjs/clients}/modules/auth-client.js +0 -0
  77. /package/{clients → cjs/clients}/modules/base-module.d.ts +0 -0
  78. /package/{clients → cjs/clients}/modules/base-module.js +0 -0
  79. /package/{clients → cjs/clients}/modules/files-client.d.ts +0 -0
  80. /package/{clients → cjs/clients}/modules/files-client.js +0 -0
  81. /package/{clients → cjs/clients}/modules/health-client.d.ts +0 -0
  82. /package/{clients → cjs/clients}/modules/health-client.js +0 -0
  83. /package/{clients → cjs/clients}/modules/index.d.ts +0 -0
  84. /package/{clients → cjs/clients}/modules/index.js +0 -0
  85. /package/{clients → cjs/clients}/modules/resource-client.d.ts +0 -0
  86. /package/{clients → cjs/clients}/modules/resource-client.js +0 -0
  87. /package/{clients → cjs/clients}/responses/file-data-response.d.ts +0 -0
  88. /package/{clients → cjs/clients}/responses/file-data-response.js +0 -0
  89. /package/{clients → cjs/clients}/responses/index.d.ts +0 -0
  90. /package/{clients → cjs/clients}/responses/index.js +0 -0
  91. /package/{commands → cjs/commands}/generate-command.d.ts +0 -0
  92. /package/{commands → cjs/commands}/generate-command.js +0 -0
  93. /package/{commands → cjs/commands}/index.d.ts +0 -0
  94. /package/{commands → cjs/commands}/index.js +0 -0
  95. /package/{constants.d.ts → cjs/constants.d.ts} +0 -0
  96. /package/{constants.js → cjs/constants.js} +0 -0
  97. /package/{errors → cjs/errors}/client-error.d.ts +0 -0
  98. /package/{errors → cjs/errors}/client-error.js +0 -0
  99. /package/{errors → cjs/errors}/index.d.ts +0 -0
  100. /package/{errors → cjs/errors}/index.js +0 -0
  101. /package/{generators → cjs/generators}/generate-client.d.ts +0 -0
  102. /package/{generators → cjs/generators}/generate-client.js +0 -0
  103. /package/{generators → cjs/generators}/generate-types.d.ts +0 -0
  104. /package/{generators → cjs/generators}/generate-types.js +0 -0
  105. /package/{generators → cjs/generators}/index.d.ts +0 -0
  106. /package/{generators → cjs/generators}/index.js +0 -0
  107. /package/{index.d.ts → cjs/index.d.ts} +0 -0
  108. /package/{index.js → cjs/index.js} +0 -0
  109. /package/{types → cjs/types}/index.d.ts +0 -0
  110. /package/{types → cjs/types}/index.js +0 -0
  111. /package/{types → cjs/types}/routes.d.ts +0 -0
  112. /package/{types → cjs/types}/routes.js +0 -0
  113. /package/{utils → cjs/utils}/index.d.ts +0 -0
  114. /package/{utils → cjs/utils}/index.js +0 -0
  115. /package/{utils → cjs/utils}/schema-util.d.ts +0 -0
  116. /package/{utils → cjs/utils}/schema-util.js +0 -0
  117. /package/{weaver-client.d.ts → cjs/weaver-client.d.ts} +0 -0
@@ -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';
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare function generateCommand(program: Command): void;
3
+ export declare function relativePathFrom(firstPath: string, otherPath: string): string;
@@ -0,0 +1,122 @@
1
+ import fs from 'node:fs';
2
+ import fsp from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import prettier from 'prettier';
5
+ import { InvalidArgumentError, InvalidOptionArgumentError } from 'commander';
6
+ import { generateClient, generateTypes } from '../generators/index.js';
7
+ import { readSchemaContent, toSchemaObject } from '../utils/index.js';
8
+ import { FRAMEWORKS } from '../constants.js';
9
+ export function generateCommand(program) {
10
+ program
11
+ .command('generate')
12
+ .alias('g')
13
+ .description('Generates types and client class.')
14
+ .argument('<schemaPath>', 'The path to the OpenAPI schema (file or URL)', parseSchema)
15
+ .option('--outputPath [path]', 'Output path for both generated types and client class.', './generated/client.ts')
16
+ .option('--typesPath [path]', 'Output path for generated types. (default: output path)')
17
+ .option('--clientPath [path]', 'Output path for generated client class. (default: output path)')
18
+ .option('--clientName [name]', 'Name for generated client class. (default: OpenAPI schema title)')
19
+ .option('--framework [name]', `The framework for generated client class (${FRAMEWORKS.join(', ')})`, parseFramework, 'fetch')
20
+ .option('--typesOnly', 'Generate TypeScript types only (without client class).')
21
+ .option('--clientOnly', 'Generate only client class (without TypeScript types).')
22
+ .option('--noTypes', 'Generate client class without TypeScript type support.')
23
+ .action(async (schemaPath, _, command) => {
24
+ const outputPath = command.getOptionValue('outputPath');
25
+ const typesPath = command.getOptionValue('typesPath') || outputPath;
26
+ const clientPath = command.getOptionValue('clientPath') || outputPath;
27
+ const clientName = command.getOptionValue('clientName');
28
+ const framework = command.getOptionValue('framework');
29
+ const typesOnly = command.getOptionValue('typesOnly');
30
+ const clientOnly = command.getOptionValue('clientOnly');
31
+ const noTypes = command.getOptionValue('noTypes');
32
+ const cwd = process.cwd();
33
+ const schemaContent = await readSchemaContent(schemaPath);
34
+ const schemaObject = await toSchemaObject(schemaContent);
35
+ if (!clientOnly && !noTypes) {
36
+ const typesContent = await generateTypes(schemaObject);
37
+ await formatAndWriteFile(typesPath, typesContent, typesOnly || typesPath !== clientPath);
38
+ console.log(`Generated types to ${path.relative(cwd, typesPath)}`);
39
+ }
40
+ if (!typesOnly) {
41
+ const typesImportPath = typesPath === clientPath
42
+ ? undefined
43
+ : relativePathFrom(clientPath, typesPath);
44
+ const clientContent = await generateClient(schemaObject, clientName, framework, typesImportPath, noTypes);
45
+ await formatAndWriteFile(clientPath, clientContent, true, typesPath === clientPath);
46
+ console.log(`Generated client to ${path.relative(cwd, clientPath)}`);
47
+ }
48
+ });
49
+ }
50
+ async function formatAndWriteFile(filePath, content, addGeneratedComment = true, appendIfExists = false) {
51
+ const dirPath = path.resolve(path.dirname(filePath));
52
+ const dirExists = await pathExists(dirPath);
53
+ if (!dirExists) {
54
+ await fsp.mkdir(dirPath, { recursive: true });
55
+ }
56
+ const prettierConfig = await prettier.resolveConfig(filePath);
57
+ let formattedContent = await prettier.format(content, {
58
+ ...(prettierConfig ?? { singleQuote: true, trailingComma: 'none' }),
59
+ filepath: filePath
60
+ });
61
+ const fileExists = await pathExists(filePath);
62
+ if (appendIfExists && fileExists) {
63
+ const existingContent = await fsp.readFile(filePath, 'utf8');
64
+ formattedContent = formattedContent + '\n' + existingContent;
65
+ }
66
+ if (addGeneratedComment) {
67
+ formattedContent =
68
+ '// Generated by Appweaver. Please do not edit this file manually.\n\n' +
69
+ formattedContent;
70
+ }
71
+ await fsp.writeFile(filePath, formattedContent, 'utf8');
72
+ }
73
+ async function pathExists(filePath) {
74
+ try {
75
+ await fsp.access(filePath, fsp.constants.F_OK);
76
+ return true;
77
+ }
78
+ catch (e) {
79
+ return false;
80
+ }
81
+ }
82
+ export function relativePathFrom(firstPath, otherPath) {
83
+ const firstDir = path.dirname(path.resolve(firstPath));
84
+ const otherAbs = path.resolve(otherPath);
85
+ let rel = path.relative(firstDir, otherAbs);
86
+ if (!rel.startsWith('.') && rel !== '') {
87
+ rel = `.${path.sep}${rel}`;
88
+ }
89
+ else if (rel === '') {
90
+ rel = '.';
91
+ }
92
+ if (rel.endsWith('.ts')) {
93
+ rel = rel.replace('.d.ts', '.ts').replace('.ts', '');
94
+ }
95
+ return rel.replace(/\\/g, '/');
96
+ }
97
+ function parseSchema(value) {
98
+ let schemaUrl;
99
+ try {
100
+ schemaUrl = new URL(value);
101
+ }
102
+ catch {
103
+ // Schema path is not in URL format
104
+ }
105
+ if (schemaUrl) {
106
+ if (!['http:', 'https:', 'file:'].includes(schemaUrl.protocol)) {
107
+ throw new InvalidArgumentError(`Unsupported schema URL protocol: ${schemaUrl.protocol}`);
108
+ }
109
+ return value;
110
+ }
111
+ if (!fs.existsSync(value)) {
112
+ throw new InvalidArgumentError(`Schema path "${value}" does not exist or is not a valid URL.`);
113
+ }
114
+ return value;
115
+ }
116
+ function parseFramework(value) {
117
+ const lowerFramework = value.toLowerCase();
118
+ if (!FRAMEWORKS.includes(lowerFramework)) {
119
+ throw new InvalidOptionArgumentError(`Must be one of following: ${FRAMEWORKS.join(', ')}.`);
120
+ }
121
+ return lowerFramework;
122
+ }
@@ -0,0 +1 @@
1
+ export * from './generate-command.js';
@@ -0,0 +1 @@
1
+ export * from './generate-command.js';
@@ -0,0 +1,67 @@
1
+ /** Supported frameworks for generating the client class. */
2
+ export declare const FRAMEWORKS: readonly ["fetch", "angular"];
3
+ /** Custom OpenAPI extension key used for extracting route prefixes and base paths to their resources. */
4
+ export declare const CONFIG_FIELD = "x-appweaver-config";
5
+ /** Custom OpenAPI extension key used for extracting resources names from schema CRUD objects. */
6
+ export declare const CONFIG_RESOURCE_FIELD = "x-appweaver-resource";
7
+ /** Suffix used when generating the TypeScript module type name for a resource. */
8
+ export declare const RESOURCE_MODULE_TYPE = "ResourceModuleType";
9
+ /** Maps CRUD operation names to HTTP methods used for matching OpenAPI paths to `ResourceClient` methods. */
10
+ export declare const RESOURCE_OPERATIONS: {
11
+ readonly find: "get";
12
+ readonly query: "post";
13
+ readonly aggregate: "post";
14
+ readonly create: "post";
15
+ readonly update: "put";
16
+ readonly delete: "delete";
17
+ readonly export: "post";
18
+ readonly uploadFiles: "post";
19
+ readonly deleteFiles: "post";
20
+ };
21
+ /** Expected type keys for a resource used for type inference. */
22
+ export declare const RESOURCE_TYPES: readonly ["single", "multiple", "create", "update", "queryRequest", "queryResponse", "aggregateRequest", "aggregateResponse", "exportRequest", "files", "fileUpload", "fileDelete"];
23
+ /** Type name used when generating the TypeScript module type for the auth module. */
24
+ export declare const AUTH_MODULE_TYPE = "AuthModuleType";
25
+ /** Maps auth operation names to HTTP methods used for matchingOpenAPI paths to `AuthClient` methods.
26
+ * The operation names are matching the real API paths (without a prefix and in camelCase format) from the OpenAPI. */
27
+ export declare const AUTH_OPERATIONS: {
28
+ readonly login: "post";
29
+ readonly logout: "post";
30
+ readonly refresh: "post";
31
+ readonly changePassword: "post";
32
+ readonly exchangeToken: "post";
33
+ readonly me: "get";
34
+ };
35
+ /** Expected type keys for the auth module used for type safety. */
36
+ export declare const AUTH_TYPES: readonly ["loginRequest", "authenticationResponse", "logoutResponse", "changePasswordRequest", "exchangeTokenRequest", "identity"];
37
+ /** Type name used when generating the TypeScript module type for the account module. */
38
+ export declare const ACCOUNT_MODULE_TYPE = "AccountModuleType";
39
+ /** Maps account operation names to HTTP methods used for matching OpenAPI paths to `AccountClient` methods.
40
+ * The operation names are matching the real API paths (without a prefix and in camelCase format) from the OpenAPI. */
41
+ export declare const ACCOUNT_OPERATIONS: {
42
+ readonly sendVerifyEmail: "post";
43
+ readonly verifyEmail: "post";
44
+ readonly verifyEmailRedirect: "get";
45
+ readonly sendResetPassword: "post";
46
+ readonly resetPassword: "post";
47
+ readonly send2FACode: "post";
48
+ readonly verify2FACode: "post";
49
+ };
50
+ /** Expected type keys for the account module which covers email verification, password reset, and 2FA req/resp. */
51
+ export declare const ACCOUNT_TYPES: readonly ["sendEmailVerificationRequest", "statusResponse", "emailVerificationRequest", "sendResetPasswordRequest", "resetPasswordRequest", "send2FACodeRequest", "send2FAResponse", "verify2FARequest", "verify2FAResponse"];
52
+ /** Type name used when generating the TypeScript module type for the health module. */
53
+ export declare const HEALTH_MODULE_TYPE = "HealthModuleType";
54
+ /** Maps health check operations to HTTP GET methods used for matching OpenAPI paths to `HealthClient` methods.
55
+ * The operation names are matching the real API paths (without a prefix and in camelCase format) from the OpenAPI. */
56
+ export declare const HEALTH_OPERATIONS: {
57
+ readonly check: "get";
58
+ readonly ready: "get";
59
+ };
60
+ /** Expected type keys for the health module used for `HealthClient` response typing. */
61
+ export declare const HEALTH_TYPES: readonly ["checkResponse", "readyResponse"];
62
+ /** Maps file-serving operations to HTTP GET methods used for identifying public and protected file endpoints.
63
+ * The operation names are matching the real API paths (without a prefix and in camelCase format) from the OpenAPI. */
64
+ export declare const FILE_OPERATIONS: {
65
+ readonly public: "get";
66
+ readonly protected: "get";
67
+ };
@@ -0,0 +1,94 @@
1
+ // CAUTION: The constants in this file should not be changed without good reason.
2
+ // They are typically only modified when changes occur in other Appweaver packages
3
+ // (such as core and common) to reflect new route paths or methods.
4
+ /** Supported frameworks for generating the client class. */
5
+ export const FRAMEWORKS = ['fetch', 'angular'];
6
+ /** Custom OpenAPI extension key used for extracting route prefixes and base paths to their resources. */
7
+ export const CONFIG_FIELD = 'x-appweaver-config';
8
+ /** Custom OpenAPI extension key used for extracting resources names from schema CRUD objects. */
9
+ export const CONFIG_RESOURCE_FIELD = 'x-appweaver-resource';
10
+ /** Suffix used when generating the TypeScript module type name for a resource. */
11
+ export const RESOURCE_MODULE_TYPE = 'ResourceModuleType';
12
+ /** Maps CRUD operation names to HTTP methods used for matching OpenAPI paths to `ResourceClient` methods. */
13
+ export const RESOURCE_OPERATIONS = {
14
+ find: 'get',
15
+ query: 'post',
16
+ aggregate: 'post',
17
+ create: 'post',
18
+ update: 'put',
19
+ delete: 'delete',
20
+ export: 'post',
21
+ uploadFiles: 'post',
22
+ deleteFiles: 'post'
23
+ };
24
+ /** Expected type keys for a resource used for type inference. */
25
+ export const RESOURCE_TYPES = [
26
+ 'single',
27
+ 'multiple',
28
+ 'create',
29
+ 'update',
30
+ 'queryRequest',
31
+ 'queryResponse',
32
+ 'aggregateRequest',
33
+ 'aggregateResponse',
34
+ 'exportRequest',
35
+ 'files',
36
+ 'fileUpload',
37
+ 'fileDelete'
38
+ ];
39
+ /** Type name used when generating the TypeScript module type for the auth module. */
40
+ export const AUTH_MODULE_TYPE = 'AuthModuleType';
41
+ /** Maps auth operation names to HTTP methods used for matchingOpenAPI paths to `AuthClient` methods.
42
+ * The operation names are matching the real API paths (without a prefix and in camelCase format) from the OpenAPI. */
43
+ export const AUTH_OPERATIONS = {
44
+ login: 'post',
45
+ logout: 'post',
46
+ refresh: 'post',
47
+ changePassword: 'post',
48
+ exchangeToken: 'post',
49
+ me: 'get'
50
+ };
51
+ /** Expected type keys for the auth module used for type safety. */
52
+ export const AUTH_TYPES = [
53
+ 'loginRequest',
54
+ 'authenticationResponse',
55
+ 'logoutResponse',
56
+ 'changePasswordRequest',
57
+ 'exchangeTokenRequest',
58
+ 'identity'
59
+ ];
60
+ /** Type name used when generating the TypeScript module type for the account module. */
61
+ export const ACCOUNT_MODULE_TYPE = 'AccountModuleType';
62
+ /** Maps account operation names to HTTP methods used for matching OpenAPI paths to `AccountClient` methods.
63
+ * The operation names are matching the real API paths (without a prefix and in camelCase format) from the OpenAPI. */
64
+ export const ACCOUNT_OPERATIONS = {
65
+ sendVerifyEmail: 'post',
66
+ verifyEmail: 'post',
67
+ verifyEmailRedirect: 'get',
68
+ sendResetPassword: 'post',
69
+ resetPassword: 'post',
70
+ send2FACode: 'post',
71
+ verify2FACode: 'post'
72
+ };
73
+ /** Expected type keys for the account module which covers email verification, password reset, and 2FA req/resp. */
74
+ export const ACCOUNT_TYPES = [
75
+ 'sendEmailVerificationRequest',
76
+ 'statusResponse',
77
+ 'emailVerificationRequest',
78
+ 'sendResetPasswordRequest',
79
+ 'resetPasswordRequest',
80
+ 'send2FACodeRequest',
81
+ 'send2FAResponse',
82
+ 'verify2FARequest',
83
+ 'verify2FAResponse'
84
+ ];
85
+ /** Type name used when generating the TypeScript module type for the health module. */
86
+ export const HEALTH_MODULE_TYPE = 'HealthModuleType';
87
+ /** Maps health check operations to HTTP GET methods used for matching OpenAPI paths to `HealthClient` methods.
88
+ * The operation names are matching the real API paths (without a prefix and in camelCase format) from the OpenAPI. */
89
+ export const HEALTH_OPERATIONS = { check: 'get', ready: 'get' };
90
+ /** Expected type keys for the health module used for `HealthClient` response typing. */
91
+ export const HEALTH_TYPES = ['checkResponse', 'readyResponse'];
92
+ /** Maps file-serving operations to HTTP GET methods used for identifying public and protected file endpoints.
93
+ * The operation names are matching the real API paths (without a prefix and in camelCase format) from the OpenAPI. */
94
+ export const FILE_OPERATIONS = { public: 'get', protected: 'get' };
@@ -0,0 +1,6 @@
1
+ export declare class ClientError extends Error {
2
+ errorCode: number;
3
+ response?: Response | undefined;
4
+ data?: any | undefined;
5
+ constructor(text: string, errorCode: number, response?: Response | undefined, data?: any | undefined);
6
+ }
@@ -0,0 +1,11 @@
1
+ export class ClientError extends Error {
2
+ errorCode;
3
+ response;
4
+ data;
5
+ constructor(text, errorCode, response, data) {
6
+ super(text);
7
+ this.errorCode = errorCode;
8
+ this.response = response;
9
+ this.data = data;
10
+ }
11
+ }