@major-tech/resource-client 0.2.38 → 0.2.40
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/bin/generate-clients.mjs +17 -20
- package/package.json +1 -1
package/bin/generate-clients.mjs
CHANGED
|
@@ -98,6 +98,7 @@ export const ${data.clientName} = ${data.clientName}Singleton.getInstance();
|
|
|
98
98
|
* Client template for tool mode
|
|
99
99
|
*/
|
|
100
100
|
function clientTemplateTool(data) {
|
|
101
|
+
const factoryName = 'create' + data.clientName.charAt(0).toUpperCase() + data.clientName.slice(1);
|
|
101
102
|
return `import { ${data.clientClass} } from '@major-tech/resource-client';
|
|
102
103
|
|
|
103
104
|
/**
|
|
@@ -110,28 +111,20 @@ function clientTemplateTool(data) {
|
|
|
110
111
|
* DO NOT EDIT - Auto-generated by @major-tech/resource-client (tool mode)
|
|
111
112
|
*/
|
|
112
113
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
class ${data.clientName}Singleton {
|
|
118
|
-
private static instance: ${data.clientClass} | null = null;
|
|
119
|
-
|
|
120
|
-
static getInstance(): ${data.clientClass} {
|
|
121
|
-
if (!${data.clientName}Singleton.instance) {
|
|
122
|
-
${data.clientName}Singleton.instance = new ${data.clientClass}({
|
|
123
|
-
baseUrl: BASE_URL,
|
|
124
|
-
majorJwtToken: MAJOR_JWT_TOKEN,
|
|
125
|
-
toolId: TOOL_ID,
|
|
126
|
-
resourceId: '${data.resourceId}',
|
|
127
|
-
fetch: (...args) => fetch(...args),
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
return ${data.clientName}Singleton.instance;
|
|
131
|
-
}
|
|
114
|
+
interface ToolContext {
|
|
115
|
+
resourceApiUrl: string;
|
|
116
|
+
majorJwtToken: string;
|
|
132
117
|
}
|
|
133
118
|
|
|
134
|
-
export
|
|
119
|
+
export function ${factoryName}(context: ToolContext): ${data.clientClass} {
|
|
120
|
+
return new ${data.clientClass}({
|
|
121
|
+
baseUrl: context.resourceApiUrl,
|
|
122
|
+
majorJwtToken: context.majorJwtToken,
|
|
123
|
+
toolId: '${data.toolId}',
|
|
124
|
+
resourceId: '${data.resourceId}',
|
|
125
|
+
fetch: (...args: Parameters<typeof fetch>) => fetch(...args),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
135
128
|
`;
|
|
136
129
|
}
|
|
137
130
|
|
|
@@ -260,6 +253,10 @@ function generateIndexFile(resources) {
|
|
|
260
253
|
const exports = resources.map(resource => {
|
|
261
254
|
const clientName = toCamelCase(resource.name) + 'Client';
|
|
262
255
|
const fileName = toCamelCase(resource.name);
|
|
256
|
+
if (resource.mode === 'tool') {
|
|
257
|
+
const factoryName = 'create' + clientName.charAt(0).toUpperCase() + clientName.slice(1);
|
|
258
|
+
return `export { ${factoryName} } from './${fileName}';`;
|
|
259
|
+
}
|
|
263
260
|
return `export { ${clientName} } from './${fileName}';`;
|
|
264
261
|
});
|
|
265
262
|
|
package/package.json
CHANGED