quickbase-js 1.0.1-beta.0
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 +7 -0
- package/LICENSE +21 -0
- package/README.md +102 -0
- package/build.js +66 -0
- package/dist/quickbaseClient.d.ts +3888 -0
- package/dist/quickbaseClient.js +5812 -0
- package/dist/quickbaseClient.js.map +1 -0
- package/examples/react.js +22 -0
- package/examples/vanillajs.html +23 -0
- package/logGen.yaml +1820 -0
- package/package.json +72 -0
- package/playwright.config.ts +37 -0
- package/rollup.config.js +70 -0
- package/src/code-generation/fix-spec-definitions.ts +136 -0
- package/src/code-generation/fix-spec-main.ts +176 -0
- package/src/code-generation/fix-spec-paths.ts +163 -0
- package/src/code-generation/generate-unified-interface.ts +152 -0
- package/src/code-generation/output/quickbase-fixed.json +8435 -0
- package/src/code-generation/regenerate-client.ts +110 -0
- package/src/generated-unified/QuickbaseClient.ts +59 -0
- package/src/index.ts +1 -0
- package/src/log-gen.ts +122 -0
- package/src/quickbaseClient.ts +320 -0
- package/src/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +46878 -0
- package/src/tokenCache.ts +51 -0
- package/src/utils.ts +5 -0
- package/test-artifacts/.last-run.json +4 -0
- package/test-artifacts/test-results.json +1801 -0
- package/test-results.json +2050 -0
- package/tests/playwright/qb/auth/cacheSwitching.test.ts +189 -0
- package/tests/playwright/qb/auth/fetchTempToken401.test.ts +217 -0
- package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +151 -0
- package/tests/playwright/qb/auth/getTempToken.test.ts +180 -0
- package/tests/playwright/qb/auth/tokenPrefetch.test.ts +192 -0
- package/tests/playwright/qb/auth/tokenRenewal.test.ts +110 -0
- package/tests/setup.ts +19 -0
- package/tests/vitest/qb/apps/getApp.test.ts +46 -0
- package/tests/vitest/qb/fields/getFields.test.ts +234 -0
- package/tests/vitest/qb/index.ts +4 -0
- package/tests/vitest/qb/tables/getAppTables.test.ts +67 -0
- package/tests/vitest/unit/apps/getApp.test.ts +81 -0
- package/tests/vitest/unit/auth/fetchTempToken401.test.ts +59 -0
- package/tests/vitest/unit/auth/getTempToken.test.ts +83 -0
- package/tests/vitest/unit/auth/retryOn401.test.ts +72 -0
- package/tests/vitest/unit/auth/two401s.test.ts +77 -0
- package/tests/vitest/unit/fields/getFields.test.ts +115 -0
- package/tests/vitest/unit/index.ts +4 -0
- package/tests/vitest/unit/tables/getAppTables.test.ts +72 -0
- package/text.txt +104 -0
- package/tsconfig.json +28 -0
- package/versionrc.json +9 -0
- package/vitest.config.ts +21 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// src/code-generation/generate-unified-interface.ts
|
|
2
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
|
|
3
|
+
import { join, dirname } from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import { simplifyName } from "../utils.ts";
|
|
6
|
+
import { OpenAPIV2 } from "openapi-types";
|
|
7
|
+
|
|
8
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const SPEC_FILE = join(__dirname, "output", "quickbase-fixed.json");
|
|
10
|
+
const OUTPUT_DIR = join(__dirname, "..", "generated-unified");
|
|
11
|
+
const OUTPUT_FILE = join(OUTPUT_DIR, "QuickbaseClient.ts");
|
|
12
|
+
|
|
13
|
+
function generateInterface() {
|
|
14
|
+
if (!existsSync(SPEC_FILE)) {
|
|
15
|
+
console.error(
|
|
16
|
+
`Spec file ${SPEC_FILE} not found. Run 'npm run fix-spec' first.`
|
|
17
|
+
);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
console.log("Generating unified QuickbaseClient interface...");
|
|
22
|
+
const spec = JSON.parse(
|
|
23
|
+
readFileSync(SPEC_FILE, "utf8")
|
|
24
|
+
) as OpenAPIV2.Document;
|
|
25
|
+
const { paths } = spec;
|
|
26
|
+
|
|
27
|
+
const modelImports = new Set<string>();
|
|
28
|
+
const methods: string[] = [];
|
|
29
|
+
|
|
30
|
+
for (const [path, methodsObj] of Object.entries(
|
|
31
|
+
paths as OpenAPIV2.PathsObject
|
|
32
|
+
)) {
|
|
33
|
+
if (!methodsObj) continue;
|
|
34
|
+
|
|
35
|
+
for (const [method, operation] of Object.entries(
|
|
36
|
+
methodsObj as OpenAPIV2.PathItemObject
|
|
37
|
+
)) {
|
|
38
|
+
const op = operation as OpenAPIV2.OperationObject | undefined;
|
|
39
|
+
if (!op || !op.operationId) continue;
|
|
40
|
+
|
|
41
|
+
const opId = op.operationId;
|
|
42
|
+
const params = (op.parameters || [])
|
|
43
|
+
.filter((p) => {
|
|
44
|
+
const param = p as OpenAPIV2.ParameterObject;
|
|
45
|
+
return !["QB-Realm-Hostname", "Authorization", "User-Agent"].includes(
|
|
46
|
+
param.name
|
|
47
|
+
);
|
|
48
|
+
})
|
|
49
|
+
.map((p) => {
|
|
50
|
+
const param = p as OpenAPIV2.ParameterObject;
|
|
51
|
+
let type = param.type
|
|
52
|
+
? mapOpenApiTypeToTs(param.type)
|
|
53
|
+
: param.schema
|
|
54
|
+
? mapRefToType(param.schema, modelImports)
|
|
55
|
+
: "any";
|
|
56
|
+
// Special handling for upsertRecords 'generated' parameter
|
|
57
|
+
if (opId === "upsertRecords" && param.name === "generated") {
|
|
58
|
+
type = "{ [key: string]: string }[]";
|
|
59
|
+
}
|
|
60
|
+
return `${param.name}${param.required ? "" : "?"}: ${type}`;
|
|
61
|
+
})
|
|
62
|
+
.join("; ");
|
|
63
|
+
|
|
64
|
+
// Handle responses, ensuring distinct types for 200 and 207
|
|
65
|
+
const successResponses = ["200", "207"]
|
|
66
|
+
.map((code) => ({
|
|
67
|
+
code,
|
|
68
|
+
response: op.responses?.[code] as
|
|
69
|
+
| OpenAPIV2.ResponseObject
|
|
70
|
+
| undefined,
|
|
71
|
+
}))
|
|
72
|
+
.filter(({ response }) => response?.schema);
|
|
73
|
+
const returnTypes = successResponses.map(({ response }) =>
|
|
74
|
+
mapRefToType(response!.schema, modelImports)
|
|
75
|
+
);
|
|
76
|
+
// Deduplicate return types and join with " | ", default to "void" if empty
|
|
77
|
+
const uniqueReturnTypes = [...new Set(returnTypes)];
|
|
78
|
+
const returnType =
|
|
79
|
+
uniqueReturnTypes.length > 0 ? uniqueReturnTypes.join(" | ") : "void";
|
|
80
|
+
|
|
81
|
+
methods.push(
|
|
82
|
+
` ${opId}: (params: { ${params} }) => Promise<${returnType}>;`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Generate import statements for all model types
|
|
88
|
+
const importStatement =
|
|
89
|
+
modelImports.size > 0
|
|
90
|
+
? `import { ${Array.from(modelImports)
|
|
91
|
+
.sort()
|
|
92
|
+
.join(", ")} } from "../generated/models";`
|
|
93
|
+
: "";
|
|
94
|
+
|
|
95
|
+
const interfaceContent = `// Generated on ${new Date().toISOString()}\n${importStatement}\n\nexport interface QuickbaseClient {\n${methods.join(
|
|
96
|
+
"\n"
|
|
97
|
+
)}\n}\n`;
|
|
98
|
+
|
|
99
|
+
if (!existsSync(OUTPUT_DIR)) {
|
|
100
|
+
mkdirSync(OUTPUT_DIR, { recursive: true });
|
|
101
|
+
}
|
|
102
|
+
writeFileSync(OUTPUT_FILE, interfaceContent, "utf8");
|
|
103
|
+
console.log(`Generated ${OUTPUT_FILE}`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function mapOpenApiTypeToTs(openApiType: string): string {
|
|
107
|
+
switch (openApiType.toLowerCase()) {
|
|
108
|
+
case "integer":
|
|
109
|
+
case "int":
|
|
110
|
+
return "number";
|
|
111
|
+
case "string":
|
|
112
|
+
return "string";
|
|
113
|
+
case "boolean":
|
|
114
|
+
return "boolean";
|
|
115
|
+
default:
|
|
116
|
+
return "any";
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function mapRefToType(
|
|
121
|
+
schema: OpenAPIV2.SchemaObject | OpenAPIV2.ReferenceObject,
|
|
122
|
+
modelImports: Set<string>
|
|
123
|
+
): string {
|
|
124
|
+
if ("$ref" in schema) {
|
|
125
|
+
const model = schema.$ref.split("/").pop()!;
|
|
126
|
+
modelImports.add(model);
|
|
127
|
+
return model;
|
|
128
|
+
}
|
|
129
|
+
if (schema.type === "array" && schema.items) {
|
|
130
|
+
const itemType =
|
|
131
|
+
"$ref" in schema.items
|
|
132
|
+
? schema.items.$ref.split("/").pop()!
|
|
133
|
+
: mapOpenApiTypeToTs(schema.items.type || "any");
|
|
134
|
+
if ("$ref" in schema.items) modelImports.add(itemType);
|
|
135
|
+
return `${itemType}[]`;
|
|
136
|
+
}
|
|
137
|
+
if (schema.type === "object" && schema.additionalProperties) {
|
|
138
|
+
const valueType = schema.additionalProperties.$ref
|
|
139
|
+
? schema.additionalProperties.$ref.split("/").pop()!
|
|
140
|
+
: mapOpenApiTypeToTs(schema.additionalProperties.type || "any");
|
|
141
|
+
if (schema.additionalProperties.$ref) modelImports.add(valueType);
|
|
142
|
+
return `{ [key: string]: ${valueType} }`;
|
|
143
|
+
}
|
|
144
|
+
return mapOpenApiTypeToTs(schema.type || "any");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
generateInterface();
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.error("Generation failed:", error);
|
|
151
|
+
process.exit(1);
|
|
152
|
+
}
|