quickbase-js 0.1.0-beta.10
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/CHANGELOG.md +211 -0
- package/LICENSE +21 -0
- package/README.md +179 -0
- package/api-examples.md +49 -0
- package/build-common.js +131 -0
- package/build-esm.js +71 -0
- package/build-umd.js +69 -0
- package/dist/esm/quickbase.d.ts +8081 -0
- package/dist/esm/quickbase.js +7928 -0
- package/dist/esm/quickbase.js.map +1 -0
- package/dist/esm/quickbase.min.js +2 -0
- package/dist/esm/quickbase.min.js.map +1 -0
- package/dist/umd/quickbase.umd.js +8504 -0
- package/dist/umd/quickbase.umd.js.map +1 -0
- package/dist/umd/quickbase.umd.min.js +2 -0
- package/dist/umd/quickbase.umd.min.js.map +1 -0
- package/docs/.vitepress/cache/deps/@theme_index.js +275 -0
- package/docs/.vitepress/cache/deps/@theme_index.js.map +7 -0
- package/docs/.vitepress/cache/deps/_metadata.json +40 -0
- package/docs/.vitepress/cache/deps/chunk-5A67QEFC.js +12542 -0
- package/docs/.vitepress/cache/deps/chunk-5A67QEFC.js.map +7 -0
- package/docs/.vitepress/cache/deps/chunk-7D4P4MMP.js +9719 -0
- package/docs/.vitepress/cache/deps/chunk-7D4P4MMP.js.map +7 -0
- package/docs/.vitepress/cache/deps/package.json +3 -0
- package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +4504 -0
- package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
- package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +583 -0
- package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
- package/docs/.vitepress/cache/deps/vue.js +343 -0
- package/docs/.vitepress/cache/deps/vue.js.map +7 -0
- package/docs/.vitepress/config.mts +26 -0
- package/docs/api-examples.md +49 -0
- package/docs/index.md +59 -0
- package/docs/markdown-examples.md +85 -0
- package/docs-data/api-docs.json +4143 -0
- package/examples/quicbase-jsCDN.html +36 -0
- package/examples/react.js +48 -0
- package/examples/vanillajs.html +47 -0
- package/index.md +25 -0
- package/markdown-examples.md +85 -0
- package/open-api/fix-spec-main.ts +133 -0
- package/open-api/generate-unified-interface.ts +104 -0
- package/open-api/generateDocsJson.ts +24 -0
- package/open-api/output/quickbase-fixed.json +11191 -0
- package/open-api/post-process-generated.ts +226 -0
- package/open-api/regenerate-client.ts +117 -0
- package/open-api/schema/enhance-general.ts +111 -0
- package/open-api/schema/fix-arrays.ts +68 -0
- package/open-api/schema/tags/apps.ts +90 -0
- package/open-api/schema/tags/fields.ts +471 -0
- package/open-api/schema/tags/groups.ts +51 -0
- package/open-api/schema/tags/index.ts +66 -0
- package/open-api/schema/tags/records.ts +115 -0
- package/open-api/schema/tags/tables.ts +211 -0
- package/open-api/schema/tags/users.ts +47 -0
- package/open-api/types/spec.ts +42 -0
- package/open-api/utils/common.ts +29 -0
- package/open-api/utils/generateJsDoc.ts +74 -0
- package/open-api/utils/infer-schema.ts +40 -0
- package/open-api/utils/naming.ts +10 -0
- package/open-api/utils/sharedUtils.ts +352 -0
- package/package.json +96 -0
- package/playwright.config.ts +37 -0
- package/rollup.config.js +114 -0
- package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +46878 -0
- package/specs/split/apps.json +1315 -0
- package/specs/split/auth.json +191 -0
- package/specs/split/fields.json +3869 -0
- package/specs/split/records.json +754 -0
- package/specs/split/reports.json +619 -0
- package/specs/split/tables.json +1605 -0
- package/src/RateLimitError.ts +12 -0
- package/src/ThrottleBucket.ts +41 -0
- package/src/authorizationStrategy.ts +283 -0
- package/src/generated-unified/QuickbaseClient.ts +1135 -0
- package/src/generated-unified/missing-types-report.json +3 -0
- package/src/index.ts +1 -0
- package/src/invokeMethod.ts +245 -0
- package/src/quickbaseClient.ts +194 -0
- package/src/rateLimiter.ts +25 -0
- package/src/tokenCache.ts +35 -0
- package/src/utils.ts +50 -0
- package/tests/playwright/qb/auth/cacheSwitching.test.ts +159 -0
- package/tests/playwright/qb/auth/fetchTempToken401.test.ts +219 -0
- package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +162 -0
- package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +153 -0
- package/tests/playwright/qb/auth/getTempToken.test.ts +152 -0
- package/tests/playwright/qb/auth/tempTokenPrefetch.test.ts +179 -0
- package/tests/playwright/qb/auth/tempTokenRenewal.test.ts +133 -0
- package/tests/setup.ts +53 -0
- package/tests/vitest/qb/apps/copyApp.test.ts +76 -0
- package/tests/vitest/qb/apps/createApp.test.ts +64 -0
- package/tests/vitest/qb/apps/deleteApp.test.ts +76 -0
- package/tests/vitest/qb/apps/getApp.test.ts +44 -0
- package/tests/vitest/qb/apps/getAppEvents.test.ts +67 -0
- package/tests/vitest/qb/apps/updateApp.test.ts +58 -0
- package/tests/vitest/qb/auth/mockQuickbaseServer.ts +60 -0
- package/tests/vitest/qb/auth/retryUserToken401.test.ts +73 -0
- package/tests/vitest/qb/auth/ssoTokenIntegrationWithServer.test.ts +65 -0
- package/tests/vitest/qb/fields/createField.test.ts +77 -0
- package/tests/vitest/qb/fields/deleteFields.test.ts +83 -0
- package/tests/vitest/qb/fields/getField.test.ts +85 -0
- package/tests/vitest/qb/fields/getFieldUsage.test.ts +82 -0
- package/tests/vitest/qb/fields/getFields.test.ts +232 -0
- package/tests/vitest/qb/fields/getFieldsUsage.test.ts +77 -0
- package/tests/vitest/qb/fields/updateField.test.ts +93 -0
- package/tests/vitest/qb/formulas/runFormula.test.ts +96 -0
- package/tests/vitest/qb/index.ts +29 -0
- package/tests/vitest/qb/records/deleteRecords.test.ts +110 -0
- package/tests/vitest/qb/records/runQuery.test.ts +146 -0
- package/tests/vitest/qb/records/upsert.test.ts +102 -0
- package/tests/vitest/qb/tables/createRelationship.test.ts +102 -0
- package/tests/vitest/qb/tables/createTable.test.ts +55 -0
- package/tests/vitest/qb/tables/deleteRelationship.test.ts +143 -0
- package/tests/vitest/qb/tables/deleteTable.test.ts +50 -0
- package/tests/vitest/qb/tables/getAppTables.test.ts +46 -0
- package/tests/vitest/qb/tables/getRelationships.test.ts +80 -0
- package/tests/vitest/qb/tables/getTable.test.ts +26 -0
- package/tests/vitest/qb/tables/updateRelationship.test.ts +250 -0
- package/tests/vitest/qb/tables/updateTable.test.ts +48 -0
- package/tests/vitest/unit/ThrottleBucket.test.ts +95 -0
- package/tests/vitest/unit/apps/copyApp.test.ts +581 -0
- package/tests/vitest/unit/apps/createApp.test.ts +186 -0
- package/tests/vitest/unit/apps/deleteApp.test.ts +216 -0
- package/tests/vitest/unit/apps/getApp.test.ts +128 -0
- package/tests/vitest/unit/apps/getAppEvents.test.ts +193 -0
- package/tests/vitest/unit/apps/updateApp.test.ts +412 -0
- package/tests/vitest/unit/auth/fetchTempToken401.test.ts +63 -0
- package/tests/vitest/unit/auth/getTempToken.test.ts +119 -0
- package/tests/vitest/unit/auth/retryTempToken401.test.ts +95 -0
- package/tests/vitest/unit/auth/retryTempTokenMaxRetries.test.ts +206 -0
- package/tests/vitest/unit/auth/retryUserToken401.test.ts +69 -0
- package/tests/vitest/unit/auth/ssoTokenRefresh.test.ts +325 -0
- package/tests/vitest/unit/fields/createField.test.ts +451 -0
- package/tests/vitest/unit/fields/deleteFields.test.ts +141 -0
- package/tests/vitest/unit/fields/getField.test.ts +189 -0
- package/tests/vitest/unit/fields/getFieldUsage.test.ts +180 -0
- package/tests/vitest/unit/fields/getFields.test.ts +122 -0
- package/tests/vitest/unit/fields/getFieldsUsage.test.ts +160 -0
- package/tests/vitest/unit/fields/updateField.test.ts +285 -0
- package/tests/vitest/unit/formulas/runFormula.test.ts +205 -0
- package/tests/vitest/unit/index.ts +34 -0
- package/tests/vitest/unit/quickbaseClientHttpMethods.test.ts +139 -0
- package/tests/vitest/unit/rateLimit.test.ts +191 -0
- package/tests/vitest/unit/records/deleteRecords.test.ts +112 -0
- package/tests/vitest/unit/records/runQuery.test.ts +102 -0
- package/tests/vitest/unit/records/upsert.test.ts +234 -0
- package/tests/vitest/unit/tables/createRelationship.test.ts +212 -0
- package/tests/vitest/unit/tables/createTable.test.ts +70 -0
- package/tests/vitest/unit/tables/deleteRelationship.test.ts +97 -0
- package/tests/vitest/unit/tables/deleteTable.test.ts +77 -0
- package/tests/vitest/unit/tables/getAppTables.test.ts +85 -0
- package/tests/vitest/unit/tables/getRelationships.test.ts +259 -0
- package/tests/vitest/unit/tables/getTable.test.ts +233 -0
- package/tests/vitest/unit/tables/updateRelationship.test.ts +307 -0
- package/tests/vitest/unit/tables/updateTable.test.ts +80 -0
- package/tests/vitest/unit/tokenLifespan.test.ts +204 -0
- package/tests/vitest/unit/umd.test.ts +8 -0
- package/tools/log-gen.ts +251 -0
- package/tools/log-gen.yaml +4777 -0
- package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
- package/tsconfig.build.json +17 -0
- package/tsconfig.json +32 -0
- package/versionrc.json +9 -0
- package/vitest.config.ts +27 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
|
|
4
|
+
import { join, dirname } from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const GENERATED_DIR = join(__dirname, "..", "src", "generated");
|
|
9
|
+
const MODELS_DIR = join(GENERATED_DIR, "models");
|
|
10
|
+
const SPEC_FILE = join(__dirname, "output", "quickbase-fixed.json");
|
|
11
|
+
|
|
12
|
+
function toPascalCase(str: string): string {
|
|
13
|
+
return str.replace(/(^\w|_\w)/g, (match) =>
|
|
14
|
+
match.replace("_", "").toUpperCase()
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function ensureDir(dir: string) {
|
|
19
|
+
if (!existsSync(dir)) {
|
|
20
|
+
mkdirSync(dir, { recursive: true });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function mapOpenApiTypeToTs(openApiType: string): string {
|
|
25
|
+
switch (openApiType) {
|
|
26
|
+
case "integer":
|
|
27
|
+
case "number":
|
|
28
|
+
return "number";
|
|
29
|
+
case "string":
|
|
30
|
+
return "string";
|
|
31
|
+
case "boolean":
|
|
32
|
+
return "boolean";
|
|
33
|
+
case "object":
|
|
34
|
+
return "object";
|
|
35
|
+
default:
|
|
36
|
+
return "any";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function generateItemsInnerInterface(
|
|
41
|
+
itemSchema: any,
|
|
42
|
+
itemName: string
|
|
43
|
+
): string {
|
|
44
|
+
const properties = itemSchema?.properties || {};
|
|
45
|
+
const propsStr = Object.entries(properties)
|
|
46
|
+
.map(([key, prop]: [string, any]) => {
|
|
47
|
+
let type;
|
|
48
|
+
if (key === "permissions" && prop.type === "array") {
|
|
49
|
+
type = "Permission[]";
|
|
50
|
+
} else if (key === "properties" && prop.type === "object") {
|
|
51
|
+
type = "{ [key: string]: any }";
|
|
52
|
+
} else {
|
|
53
|
+
type = mapOpenApiTypeToTs(prop.type);
|
|
54
|
+
}
|
|
55
|
+
const isRequired = itemSchema.required?.includes(key);
|
|
56
|
+
const description = prop.description ? ` * ${prop.description}` : "";
|
|
57
|
+
return ` /**
|
|
58
|
+
${description}
|
|
59
|
+
* @type {${type}}
|
|
60
|
+
*/
|
|
61
|
+
${key}${isRequired ? "" : "?"}: ${type};`;
|
|
62
|
+
})
|
|
63
|
+
.join("\n");
|
|
64
|
+
|
|
65
|
+
const additionalProps =
|
|
66
|
+
itemSchema.additionalProperties === true
|
|
67
|
+
? ` /**
|
|
68
|
+
* Allows additional unspecified properties
|
|
69
|
+
* @type {any}
|
|
70
|
+
*/
|
|
71
|
+
[key: string]: any;`
|
|
72
|
+
: "";
|
|
73
|
+
|
|
74
|
+
return `
|
|
75
|
+
/* Auto-generated by post-process-generated.ts */
|
|
76
|
+
import { mapValues } from '../runtime';
|
|
77
|
+
import { Permission } from './Permission';
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Auto-generated model for ${itemName}
|
|
81
|
+
*/
|
|
82
|
+
export interface ${itemName} {
|
|
83
|
+
${propsStr}
|
|
84
|
+
${additionalProps}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function ${itemName}FromJSON(json: any): ${itemName} {
|
|
88
|
+
return json || {};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function ${itemName}ToJSON(value?: ${itemName} | null): any {
|
|
92
|
+
return value || {};
|
|
93
|
+
}
|
|
94
|
+
`.trim();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function postProcessGeneratedFiles() {
|
|
98
|
+
console.log("Starting post-processing...");
|
|
99
|
+
console.log("Spec file path:", SPEC_FILE);
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
if (!existsSync(SPEC_FILE)) {
|
|
103
|
+
console.error(
|
|
104
|
+
`Spec file ${SPEC_FILE} not found. Run 'npm run fix-spec' first.`
|
|
105
|
+
);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const spec = JSON.parse(readFileSync(SPEC_FILE, "utf8"));
|
|
110
|
+
console.log("Spec loaded successfully.");
|
|
111
|
+
|
|
112
|
+
const responseMap: Record<string, string> = {};
|
|
113
|
+
for (const pathKey in spec.paths) {
|
|
114
|
+
const pathObj = spec.paths[pathKey];
|
|
115
|
+
if (!pathObj || typeof pathObj !== "object") continue;
|
|
116
|
+
for (const method in pathObj) {
|
|
117
|
+
const operation = pathObj[method];
|
|
118
|
+
const opId =
|
|
119
|
+
operation.operationId || `${method}${pathKey.replace(/\W/g, "")}`;
|
|
120
|
+
const response = operation.responses?.["200"];
|
|
121
|
+
if (response && response.schema?.$ref) {
|
|
122
|
+
const refName = response.schema.$ref.split("/").pop() || "";
|
|
123
|
+
responseMap[opId] = refName;
|
|
124
|
+
console.log(`Mapped ${opId} to ${refName}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
for (const [opId, refName] of Object.entries(responseMap)) {
|
|
130
|
+
try {
|
|
131
|
+
const def = spec.definitions[refName];
|
|
132
|
+
if (!def) {
|
|
133
|
+
console.log(`Definition for ${refName} not found; skipping`);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const responseFile = join(MODELS_DIR, `${toPascalCase(refName)}.ts`);
|
|
138
|
+
|
|
139
|
+
if (def.type === "array") {
|
|
140
|
+
const itemRef = def.items?.$ref
|
|
141
|
+
? def.items.$ref.split("/").pop()
|
|
142
|
+
: `${toPascalCase(refName)}ItemsInner`;
|
|
143
|
+
const itemsFile = join(MODELS_DIR, `${itemRef}.ts`);
|
|
144
|
+
|
|
145
|
+
if (!existsSync(itemsFile)) {
|
|
146
|
+
console.log(`Creating missing ${itemRef}.ts`);
|
|
147
|
+
const content = def.items?.$ref
|
|
148
|
+
? `
|
|
149
|
+
/* Auto-generated by post-process-generated.ts */
|
|
150
|
+
import { mapValues } from '../runtime';
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Auto-generated model for ${itemRef}
|
|
154
|
+
*/
|
|
155
|
+
export interface ${itemRef} {
|
|
156
|
+
[key: string]: any; // Placeholder; refine as needed
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function ${itemRef}FromJSON(json: any): ${itemRef} {
|
|
160
|
+
return json || {};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function ${itemRef}ToJSON(value?: ${itemRef} | null): any {
|
|
164
|
+
return value || {};
|
|
165
|
+
}
|
|
166
|
+
`
|
|
167
|
+
: generateItemsInnerInterface(def.items || {}, itemRef);
|
|
168
|
+
ensureDir(MODELS_DIR);
|
|
169
|
+
writeFileSync(itemsFile, content.trim(), "utf8");
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (existsSync(responseFile)) {
|
|
173
|
+
console.log(`Rewriting ${refName}.ts as array`);
|
|
174
|
+
const content = `
|
|
175
|
+
/* Auto-generated by post-process-generated.ts */
|
|
176
|
+
import { ${itemRef}, ${itemRef}FromJSON, ${itemRef}ToJSON } from './${itemRef}';
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Response for ${opId}
|
|
180
|
+
*/
|
|
181
|
+
export type ${toPascalCase(refName)} = ${itemRef}[];
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Convert JSON to ${toPascalCase(refName)}
|
|
185
|
+
*/
|
|
186
|
+
export function ${toPascalCase(refName)}FromJSON(json: any): ${toPascalCase(
|
|
187
|
+
refName
|
|
188
|
+
)} {
|
|
189
|
+
if (!json) return [];
|
|
190
|
+
return json.map(${itemRef}FromJSON);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Convert ${toPascalCase(refName)} to JSON
|
|
195
|
+
*/
|
|
196
|
+
export function ${toPascalCase(refName)}ToJSON(value?: ${toPascalCase(
|
|
197
|
+
refName
|
|
198
|
+
)} | null): any {
|
|
199
|
+
if (!value) return [];
|
|
200
|
+
return value.map(${itemRef}ToJSON);
|
|
201
|
+
}
|
|
202
|
+
`;
|
|
203
|
+
writeFileSync(responseFile, content.trim(), "utf8");
|
|
204
|
+
}
|
|
205
|
+
} else if (def.type === "object") {
|
|
206
|
+
console.log(`Processing ${refName}.ts as object`);
|
|
207
|
+
const content = generateItemsInnerInterface(
|
|
208
|
+
def,
|
|
209
|
+
toPascalCase(refName)
|
|
210
|
+
);
|
|
211
|
+
ensureDir(MODELS_DIR);
|
|
212
|
+
writeFileSync(responseFile, content.trim(), "utf8");
|
|
213
|
+
}
|
|
214
|
+
} catch (error) {
|
|
215
|
+
console.error(`Error processing ${refName}:`, error);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
console.log("Post-processing complete.");
|
|
220
|
+
} catch (error) {
|
|
221
|
+
console.error("Error in post-processing:", error);
|
|
222
|
+
process.exit(1);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
postProcessGeneratedFiles();
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { execSync } from "child_process";
|
|
4
|
+
import { existsSync } from "fs";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
import fetch from "node-fetch";
|
|
8
|
+
import readline from "readline";
|
|
9
|
+
|
|
10
|
+
const CURRENT_JAR_VERSION = "7.12.0";
|
|
11
|
+
const MAVEN_METADATA_URL =
|
|
12
|
+
"https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/maven-metadata.xml";
|
|
13
|
+
const CODEGEN_DIR = join(fileURLToPath(import.meta.url), "..");
|
|
14
|
+
const JARS_DIR = join(CODEGEN_DIR, "..", "tools", "openapi-jars");
|
|
15
|
+
const SPEC_INPUT = join(CODEGEN_DIR, "output", "quickbase-fixed.json");
|
|
16
|
+
const OUTPUT_DIR = join(CODEGEN_DIR, "..", "src", "generated");
|
|
17
|
+
|
|
18
|
+
async function getLatestVersion(): Promise<string> {
|
|
19
|
+
const response = await fetch(MAVEN_METADATA_URL);
|
|
20
|
+
if (!response.ok)
|
|
21
|
+
throw new Error(`Failed to fetch Maven metadata: ${response.statusText}`);
|
|
22
|
+
const text = await response.text();
|
|
23
|
+
const match = text.match(/<latest>(.*?)<\/latest>/);
|
|
24
|
+
if (!match)
|
|
25
|
+
throw new Error("Couldn’t parse latest version from Maven metadata");
|
|
26
|
+
return match[1];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function checkAndPromptForUpdate(messages: string[]): Promise<string> {
|
|
30
|
+
const latestVersion = await getLatestVersion();
|
|
31
|
+
if (latestVersion === CURRENT_JAR_VERSION) {
|
|
32
|
+
messages.push(`Current version (${CURRENT_JAR_VERSION}) is the latest.`);
|
|
33
|
+
return CURRENT_JAR_VERSION;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
messages.push(
|
|
37
|
+
`Newer version available: ${latestVersion} (current: ${CURRENT_JAR_VERSION})`
|
|
38
|
+
);
|
|
39
|
+
const rl = readline.createInterface({
|
|
40
|
+
input: process.stdin,
|
|
41
|
+
output: process.stdout,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
const prompt = "Do you want to update to the latest version? (y/n): ";
|
|
46
|
+
messages.push(prompt);
|
|
47
|
+
rl.question(prompt, (answer) => {
|
|
48
|
+
rl.close();
|
|
49
|
+
if (answer.toLowerCase() === "y" || answer.toLowerCase() === "yes") {
|
|
50
|
+
messages.push(`Switching to version ${latestVersion}...`);
|
|
51
|
+
resolve(latestVersion);
|
|
52
|
+
} else {
|
|
53
|
+
messages.push(`Sticking with version ${CURRENT_JAR_VERSION}.`);
|
|
54
|
+
resolve(CURRENT_JAR_VERSION);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function ensureJarExists(
|
|
61
|
+
version: string,
|
|
62
|
+
messages: string[]
|
|
63
|
+
): Promise<string> {
|
|
64
|
+
const jarPath = join(JARS_DIR, `openapi-generator-cli-${version}.jar`);
|
|
65
|
+
const jarUrl = `https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/${version}/openapi-generator-cli-${version}.jar`;
|
|
66
|
+
|
|
67
|
+
if (!existsSync(jarPath)) {
|
|
68
|
+
messages.push(`Downloading OpenAPI Generator CLI v${version}...`);
|
|
69
|
+
try {
|
|
70
|
+
execSync(`curl -L -o ${jarPath} ${jarUrl}`, { stdio: "inherit" });
|
|
71
|
+
messages.push(`Downloaded ${jarPath}`);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
messages.push("Failed to download JAR.");
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
messages.push(`Using existing ${jarPath}`);
|
|
78
|
+
}
|
|
79
|
+
return jarPath;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function regenerateClient(jarPath: string, messages: string[]) {
|
|
83
|
+
messages.push("Regenerating client from spec...");
|
|
84
|
+
const command = `java -jar ${jarPath} generate -i ${SPEC_INPUT} -g typescript-fetch -o ${OUTPUT_DIR} --additional-properties=generateAliasAsModel=true,withInterfaces=true,supportsES6=true,modelPropertyNaming=original`;
|
|
85
|
+
try {
|
|
86
|
+
execSync(command, { stdio: "inherit" });
|
|
87
|
+
messages.push("Client regeneration complete.");
|
|
88
|
+
} catch (error) {
|
|
89
|
+
messages.push("Regeneration failed.");
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function main() {
|
|
95
|
+
const messages: string[] = [];
|
|
96
|
+
try {
|
|
97
|
+
if (!existsSync(SPEC_INPUT)) {
|
|
98
|
+
console.error(
|
|
99
|
+
`Spec file ${SPEC_INPUT} does not exist. Run 'npm run fix-spec' first.`
|
|
100
|
+
);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
const versionToUse = await checkAndPromptForUpdate(messages);
|
|
104
|
+
const jarPath = await ensureJarExists(versionToUse, messages);
|
|
105
|
+
regenerateClient(jarPath, messages);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error("Error occurred during process:", error);
|
|
108
|
+
} finally {
|
|
109
|
+
console.log("\n--- Key Messages ---");
|
|
110
|
+
messages.forEach((msg) => console.log(msg));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
main().catch((error) => {
|
|
115
|
+
console.error("Error in regeneration process:", error);
|
|
116
|
+
process.exit(1);
|
|
117
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Operation, Parameter, Spec } from "../types/spec.ts";
|
|
2
|
+
import { inferSchema } from "../utils/infer-schema.ts";
|
|
3
|
+
|
|
4
|
+
export function enhanceGeneral(spec: Spec): void {
|
|
5
|
+
spec.definitions = spec.definitions || {};
|
|
6
|
+
|
|
7
|
+
if (!spec.definitions["Record"]) {
|
|
8
|
+
spec.definitions["Record"] = {
|
|
9
|
+
type: "object",
|
|
10
|
+
additionalProperties: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: { value: { type: "string" } },
|
|
13
|
+
required: ["value"],
|
|
14
|
+
},
|
|
15
|
+
description: "A generic QuickBase record with field ID-value pairs",
|
|
16
|
+
};
|
|
17
|
+
console.log("Added Record to definitions");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!spec.definitions["Permission"]) {
|
|
21
|
+
spec.definitions["Permission"] = {
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: {
|
|
24
|
+
role: { type: "string", description: "The role name" },
|
|
25
|
+
permissionType: {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "Permission type (e.g., View, Modify)",
|
|
28
|
+
},
|
|
29
|
+
roleId: { type: "integer", description: "The role identifier" },
|
|
30
|
+
},
|
|
31
|
+
required: ["role", "permissionType", "roleId"],
|
|
32
|
+
description: "A single permission entry for a field",
|
|
33
|
+
};
|
|
34
|
+
console.log("Added Permission to definitions");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
for (const pathKey in spec.paths) {
|
|
38
|
+
for (const method in spec.paths[pathKey]) {
|
|
39
|
+
const operation: Operation = spec.paths[pathKey][method];
|
|
40
|
+
const opId =
|
|
41
|
+
operation.operationId || `${method}${pathKey.replace(/\W/g, "")}`;
|
|
42
|
+
|
|
43
|
+
if (operation.parameters) {
|
|
44
|
+
operation.parameters.forEach((param: Parameter) => {
|
|
45
|
+
if (param.in !== "body" && !param.type && !param.schema) {
|
|
46
|
+
param.type = param.name.includes("Id") ? "string" : "string";
|
|
47
|
+
console.log(
|
|
48
|
+
`Set default type 'string' for ${pathKey}(${method}).${param.name}`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (operation.responses) {
|
|
55
|
+
for (const status in operation.responses) {
|
|
56
|
+
const response = operation.responses[status];
|
|
57
|
+
if (response.schema) {
|
|
58
|
+
const cleanStatus = status.replace("/", "_");
|
|
59
|
+
const responseName = `${opId}${cleanStatus}Response`;
|
|
60
|
+
if (!spec.definitions[responseName]) {
|
|
61
|
+
console.log(
|
|
62
|
+
`Adding ${responseName} to definitions for ${pathKey}(${method})`
|
|
63
|
+
);
|
|
64
|
+
let schemaToUse = response.schema;
|
|
65
|
+
// Only infer from example if schema is truly empty
|
|
66
|
+
if (
|
|
67
|
+
!schemaToUse.type &&
|
|
68
|
+
!schemaToUse.items &&
|
|
69
|
+
!schemaToUse.properties
|
|
70
|
+
) {
|
|
71
|
+
if (response["x-amf-mediaType"]) {
|
|
72
|
+
const mediaType = response["x-amf-mediaType"];
|
|
73
|
+
if (mediaType === "application/octet-stream") {
|
|
74
|
+
schemaToUse = {
|
|
75
|
+
type: "object",
|
|
76
|
+
properties: {
|
|
77
|
+
data: { type: "string", format: "binary" },
|
|
78
|
+
},
|
|
79
|
+
description:
|
|
80
|
+
schemaToUse?.description || "Binary file content",
|
|
81
|
+
};
|
|
82
|
+
} else if (mediaType === "application/x-yaml") {
|
|
83
|
+
schemaToUse = {
|
|
84
|
+
type: "object",
|
|
85
|
+
properties: {
|
|
86
|
+
content: { type: "string", format: "yaml" },
|
|
87
|
+
},
|
|
88
|
+
description: "YAML-formatted data",
|
|
89
|
+
};
|
|
90
|
+
} else if (
|
|
91
|
+
mediaType === "application/json" &&
|
|
92
|
+
schemaToUse.example
|
|
93
|
+
) {
|
|
94
|
+
schemaToUse = inferSchema(
|
|
95
|
+
schemaToUse.example,
|
|
96
|
+
responseName
|
|
97
|
+
);
|
|
98
|
+
schemaToUse.description =
|
|
99
|
+
response.description || `Response for ${opId}`;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
spec.definitions[responseName] = schemaToUse;
|
|
104
|
+
}
|
|
105
|
+
response.schema = { $ref: `#/definitions/${responseName}` };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// schema/fix-arrays.ts
|
|
2
|
+
import { Parameter, Spec } from "../types/spec.ts";
|
|
3
|
+
|
|
4
|
+
export function fixArrays(spec: Spec): void {
|
|
5
|
+
for (const pathKey in spec.paths) {
|
|
6
|
+
for (const method in spec.paths[pathKey]) {
|
|
7
|
+
const operation = spec.paths[pathKey][method];
|
|
8
|
+
if (operation.parameters) {
|
|
9
|
+
operation.parameters.forEach((param: Parameter) => {
|
|
10
|
+
if (param.schema?.type === "array" && !param.schema.items) {
|
|
11
|
+
console.log(
|
|
12
|
+
`Fixing array schema for ${pathKey}(${method}).${param.name}`
|
|
13
|
+
);
|
|
14
|
+
param.schema.items = { type: "string" };
|
|
15
|
+
}
|
|
16
|
+
if (param.schema?.properties) {
|
|
17
|
+
for (const propKey in param.schema.properties) {
|
|
18
|
+
const prop = param.schema.properties[propKey];
|
|
19
|
+
if (prop.type === "array" && !prop.items) {
|
|
20
|
+
console.log(
|
|
21
|
+
`Fixing nested array for ${pathKey}(${method}).${param.name}.${propKey}`
|
|
22
|
+
);
|
|
23
|
+
prop.items = { type: "string" };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (operation.responses) {
|
|
30
|
+
for (const status in operation.responses) {
|
|
31
|
+
const response = operation.responses[status];
|
|
32
|
+
if (response.schema?.type === "array" && !response.schema.items) {
|
|
33
|
+
console.log(
|
|
34
|
+
`Fixing array schema for ${pathKey}(${method}).responses.${status}`
|
|
35
|
+
);
|
|
36
|
+
response.schema.items = { type: "string" };
|
|
37
|
+
}
|
|
38
|
+
if (response.schema?.properties) {
|
|
39
|
+
for (const propKey in response.schema.properties) {
|
|
40
|
+
const prop = response.schema.properties[propKey];
|
|
41
|
+
if (prop.type === "array" && !prop.items) {
|
|
42
|
+
console.log(
|
|
43
|
+
`Fixing nested array for ${pathKey}(${method}).responses.${status}.${propKey}`
|
|
44
|
+
);
|
|
45
|
+
prop.items = { type: "string" };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
console.log("Fixing array schemas in definitions...");
|
|
55
|
+
const definitions = spec.definitions || {};
|
|
56
|
+
for (const defKey in definitions) {
|
|
57
|
+
const def = definitions[defKey];
|
|
58
|
+
if (def.properties) {
|
|
59
|
+
for (const propKey in def.properties) {
|
|
60
|
+
const prop = def.properties[propKey];
|
|
61
|
+
if (prop.type === "array" && !prop.items) {
|
|
62
|
+
console.log(`Fixing missing items in ${defKey}.${propKey}`);
|
|
63
|
+
prop.items = { type: "string" };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// schema/tags/apps.ts
|
|
2
|
+
import { Operation, Parameter, Spec } from "../../types/spec.ts";
|
|
3
|
+
import { normalizeDefinitionName } from "../../utils/naming.ts";
|
|
4
|
+
|
|
5
|
+
export function enhanceApps(
|
|
6
|
+
spec: Spec,
|
|
7
|
+
pathKey: string,
|
|
8
|
+
method: string,
|
|
9
|
+
operation: Operation
|
|
10
|
+
): void {
|
|
11
|
+
const opId =
|
|
12
|
+
operation.operationId || `${method}${pathKey.replace(/\W/g, "")}`;
|
|
13
|
+
if (operation.parameters && operation.tags?.includes("Apps")) {
|
|
14
|
+
operation.parameters.forEach((param: Parameter) => {
|
|
15
|
+
if (param.in === "body") {
|
|
16
|
+
if (!param.schema) param.schema = {};
|
|
17
|
+
let requestName =
|
|
18
|
+
param.schema.$ref?.split("/").pop() || `${opId}Request`;
|
|
19
|
+
requestName = normalizeDefinitionName(requestName);
|
|
20
|
+
|
|
21
|
+
if (
|
|
22
|
+
!spec.definitions[requestName] ||
|
|
23
|
+
!spec.definitions[requestName].type ||
|
|
24
|
+
Object.keys(spec.definitions[requestName]?.properties || {})
|
|
25
|
+
.length === 0
|
|
26
|
+
) {
|
|
27
|
+
console.log(
|
|
28
|
+
`Defining schema for ${requestName} in ${pathKey}(${method})`
|
|
29
|
+
);
|
|
30
|
+
let properties;
|
|
31
|
+
if (pathKey.includes("/copy") && method === "post") {
|
|
32
|
+
properties = {
|
|
33
|
+
name: { type: "string", description: "The name of the new app." },
|
|
34
|
+
description: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "A description for the new app.",
|
|
37
|
+
},
|
|
38
|
+
properties: {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: {
|
|
41
|
+
keepData: {
|
|
42
|
+
type: "boolean",
|
|
43
|
+
description: "Whether to copy data.",
|
|
44
|
+
},
|
|
45
|
+
excludeFiles: {
|
|
46
|
+
type: "boolean",
|
|
47
|
+
description: "Whether to exclude files.",
|
|
48
|
+
},
|
|
49
|
+
usersAndRoles: {
|
|
50
|
+
type: "boolean",
|
|
51
|
+
description: "Whether to copy users and roles.",
|
|
52
|
+
},
|
|
53
|
+
assignUserToken: {
|
|
54
|
+
type: "boolean",
|
|
55
|
+
description: "Whether to assign the user token.",
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
description: "Options for customizing the app copy process.",
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
} else {
|
|
62
|
+
properties = {
|
|
63
|
+
name: { type: "string", description: "The name of the app." },
|
|
64
|
+
description: {
|
|
65
|
+
type: "string",
|
|
66
|
+
description: "A description for the app.",
|
|
67
|
+
},
|
|
68
|
+
assignToken: {
|
|
69
|
+
type: "boolean",
|
|
70
|
+
description: "Whether to assign the user token.",
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
spec.definitions[requestName] = {
|
|
75
|
+
type: "object",
|
|
76
|
+
properties,
|
|
77
|
+
required: Object.keys(properties).filter(
|
|
78
|
+
(key) => key !== "description" && key !== "properties"
|
|
79
|
+
),
|
|
80
|
+
description: operation.summary || `Request body for ${opId}`,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
param.schema = { $ref: `#/definitions/${requestName}` };
|
|
84
|
+
console.log(
|
|
85
|
+
`Ensured ${requestName} in definitions for ${pathKey}(${method})`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|