quickbase-js 0.1.0-beta.7

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 (123) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/LICENSE +21 -0
  3. package/README.md +204 -0
  4. package/build-common.js +131 -0
  5. package/build-esm.js +71 -0
  6. package/build-umd.js +69 -0
  7. package/dist/esm/quickbase.d.ts +7594 -0
  8. package/dist/esm/quickbase.js +9752 -0
  9. package/dist/esm/quickbase.js.map +1 -0
  10. package/dist/esm/quickbase.min.js +2 -0
  11. package/dist/esm/quickbase.min.js.map +1 -0
  12. package/dist/umd/quickbase.umd.js +10502 -0
  13. package/dist/umd/quickbase.umd.js.map +1 -0
  14. package/dist/umd/quickbase.umd.min.js +2 -0
  15. package/dist/umd/quickbase.umd.min.js.map +1 -0
  16. package/examples/quicbase-jsCDN.html +36 -0
  17. package/examples/react.js +48 -0
  18. package/examples/vanillajs.html +47 -0
  19. package/notes.txt +158 -0
  20. package/open-api/fix-spec-main.ts +96 -0
  21. package/open-api/generate-unified-interface.ts +277 -0
  22. package/open-api/output/override-report.json +58 -0
  23. package/open-api/output/quickbase-fixed.json +10610 -0
  24. package/open-api/regenerate-client.ts +116 -0
  25. package/open-api/schema/enhance-general.ts +100 -0
  26. package/open-api/schema/fix-arrays.ts +69 -0
  27. package/open-api/schema/tags/apps.ts +90 -0
  28. package/open-api/schema/tags/fields.ts +156 -0
  29. package/open-api/schema/tags/groups.ts +51 -0
  30. package/open-api/schema/tags/index.ts +68 -0
  31. package/open-api/schema/tags/records.ts +115 -0
  32. package/open-api/schema/tags/tables.ts +211 -0
  33. package/open-api/schema/tags/users.ts +47 -0
  34. package/open-api/types/spec.ts +41 -0
  35. package/open-api/utils/infer-schema.ts +40 -0
  36. package/open-api/utils/naming.ts +10 -0
  37. package/package.json +91 -0
  38. package/playwright.config.ts +37 -0
  39. package/rollup.config.js +114 -0
  40. package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +46878 -0
  41. package/specs/split/apps.json +1315 -0
  42. package/specs/split/auth.json +191 -0
  43. package/specs/split/fields.json +3869 -0
  44. package/specs/split/records.json +754 -0
  45. package/specs/split/reports.json +619 -0
  46. package/specs/split/tables.json +1605 -0
  47. package/src/generated-unified/QuickbaseClient.ts +359 -0
  48. package/src/generated-unified/missing-types-report.json +3 -0
  49. package/src/index.ts +1 -0
  50. package/src/quickbaseClient.ts +402 -0
  51. package/src/tokenCache.ts +51 -0
  52. package/src/utils.ts +7 -0
  53. package/test-esm.js +1 -0
  54. package/test-results.json +2050 -0
  55. package/test-umd.js +1 -0
  56. package/test.ts +1 -0
  57. package/tests/playwright/qb/auth/cacheSwitching.test.ts +159 -0
  58. package/tests/playwright/qb/auth/fetchTempToken401.test.ts +219 -0
  59. package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +162 -0
  60. package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +153 -0
  61. package/tests/playwright/qb/auth/getTempToken.test.ts +152 -0
  62. package/tests/playwright/qb/auth/tokenPrefetch.test.ts +179 -0
  63. package/tests/playwright/qb/auth/tokenRenewal.test.ts +133 -0
  64. package/tests/setup.ts +51 -0
  65. package/tests/vitest/qb/apps/copyApp.test.ts +76 -0
  66. package/tests/vitest/qb/apps/createApp.test.ts +64 -0
  67. package/tests/vitest/qb/apps/deleteApp.test.ts +76 -0
  68. package/tests/vitest/qb/apps/getApp.test.ts +40 -0
  69. package/tests/vitest/qb/fields/createField.test.ts +78 -0
  70. package/tests/vitest/qb/fields/deleteFields.test.ts +89 -0
  71. package/tests/vitest/qb/fields/getField.test.ts +85 -0
  72. package/tests/vitest/qb/fields/getFieldUsage.test.ts +174 -0
  73. package/tests/vitest/qb/fields/getFields.test.ts +232 -0
  74. package/tests/vitest/qb/fields/getFieldsUsage.test.ts +77 -0
  75. package/tests/vitest/qb/index.ts +28 -0
  76. package/tests/vitest/qb/records/deleteRecords.test.ts +110 -0
  77. package/tests/vitest/qb/records/runQuery.test.ts +146 -0
  78. package/tests/vitest/qb/records/upsert.test.ts +102 -0
  79. package/tests/vitest/qb/tables/createTable.test.ts +55 -0
  80. package/tests/vitest/qb/tables/deleteTable.test.ts +50 -0
  81. package/tests/vitest/qb/tables/getAppTables.test.ts +46 -0
  82. package/tests/vitest/qb/tables/getRelationships.test.ts +80 -0
  83. package/tests/vitest/qb/tables/getTable.test.ts +26 -0
  84. package/tests/vitest/qb/tables/updateTable.test.ts +48 -0
  85. package/tests/vitest/unit/apps/copyApp.test.ts +488 -0
  86. package/tests/vitest/unit/apps/createApp.test.ts +186 -0
  87. package/tests/vitest/unit/apps/deleteApp.test.ts +216 -0
  88. package/tests/vitest/unit/apps/getApp.test.ts +128 -0
  89. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +82 -0
  90. package/tests/vitest/unit/auth/getTempToken.test.ts +95 -0
  91. package/tests/vitest/unit/auth/retryOn401.test.ts +116 -0
  92. package/tests/vitest/unit/auth/two401s.test.ts +86 -0
  93. package/tests/vitest/unit/fields/createField.test.ts +391 -0
  94. package/tests/vitest/unit/fields/deleteFields.test.ts +141 -0
  95. package/tests/vitest/unit/fields/getField.test.ts +189 -0
  96. package/tests/vitest/unit/fields/getFieldUsage.test.ts +147 -0
  97. package/tests/vitest/unit/fields/getFields.test.ts +122 -0
  98. package/tests/vitest/unit/fields/getFieldsUsage.test.ts +160 -0
  99. package/tests/vitest/unit/index.ts +33 -0
  100. package/tests/vitest/unit/records/deleteRecords.test.ts +112 -0
  101. package/tests/vitest/unit/records/runQuery.test.ts +102 -0
  102. package/tests/vitest/unit/records/upsert.test.ts +234 -0
  103. package/tests/vitest/unit/tables/createTable.test.ts +70 -0
  104. package/tests/vitest/unit/tables/deleteTable.test.ts +77 -0
  105. package/tests/vitest/unit/tables/getAppTables.test.ts +85 -0
  106. package/tests/vitest/unit/tables/getRelationships.test.ts +259 -0
  107. package/tests/vitest/unit/tables/getTable.test.ts +233 -0
  108. package/tests/vitest/unit/tables/updateTable.test.ts +80 -0
  109. package/tests/vitest/unit/umd.test.ts +8 -0
  110. package/text.txt +104 -0
  111. package/tools/generate-types.ts +29 -0
  112. package/tools/log-gen.ts +231 -0
  113. package/tools/log-gen.yaml +3826 -0
  114. package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
  115. package/tools/openapi-schema-validator.ts +38 -0
  116. package/tools/spec-analyzer.ts +163 -0
  117. package/tools/split-spec.ts +148 -0
  118. package/tools/test-import.ts +3 -0
  119. package/tools/validate-spec.ts +40 -0
  120. package/tsconfig.build.json +17 -0
  121. package/tsconfig.json +29 -0
  122. package/versionrc.json +9 -0
  123. package/vitest.config.ts +27 -0
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from "child_process";
3
+ import { existsSync } from "fs";
4
+ import { join } from "path";
5
+ import { fileURLToPath } from "url";
6
+ import fetch from "node-fetch";
7
+ import readline from "readline";
8
+
9
+ const CURRENT_JAR_VERSION = "7.12.0";
10
+ const MAVEN_METADATA_URL =
11
+ "https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/maven-metadata.xml";
12
+ const CODEGEN_DIR = join(fileURLToPath(import.meta.url), ".."); // open-api/
13
+ const JARS_DIR = join(CODEGEN_DIR, "..", "tools", "openapi-jars"); // Updated to tools/openapi-jars/
14
+ const SPEC_INPUT = join(CODEGEN_DIR, "output", "quickbase-fixed.json"); // Relative to open-api/
15
+ const OUTPUT_DIR = join(CODEGEN_DIR, "..", "src", "generated"); // Up to root, then into src/generated/
16
+
17
+ async function getLatestVersion(): Promise<string> {
18
+ const response = await fetch(MAVEN_METADATA_URL);
19
+ if (!response.ok)
20
+ throw new Error(`Failed to fetch Maven metadata: ${response.statusText}`);
21
+ const text = await response.text();
22
+ const match = text.match(/<latest>(.*?)<\/latest>/);
23
+ if (!match)
24
+ throw new Error("Couldn’t parse latest version from Maven metadata");
25
+ return match[1];
26
+ }
27
+
28
+ async function checkAndPromptForUpdate(messages: string[]): Promise<string> {
29
+ const latestVersion = await getLatestVersion();
30
+ if (latestVersion === CURRENT_JAR_VERSION) {
31
+ messages.push(`Current version (${CURRENT_JAR_VERSION}) is the latest.`);
32
+ return CURRENT_JAR_VERSION;
33
+ }
34
+
35
+ messages.push(
36
+ `Newer version available: ${latestVersion} (current: ${CURRENT_JAR_VERSION})`
37
+ );
38
+ const rl = readline.createInterface({
39
+ input: process.stdin,
40
+ output: process.stdout,
41
+ });
42
+
43
+ return new Promise((resolve) => {
44
+ const prompt = "Do you want to update to the latest version? (y/n): ";
45
+ messages.push(prompt);
46
+ rl.question(prompt, (answer) => {
47
+ rl.close();
48
+ if (answer.toLowerCase() === "y" || answer.toLowerCase() === "yes") {
49
+ messages.push(`Switching to version ${latestVersion}...`);
50
+ resolve(latestVersion);
51
+ } else {
52
+ messages.push(`Sticking with version ${CURRENT_JAR_VERSION}.`);
53
+ resolve(CURRENT_JAR_VERSION);
54
+ }
55
+ });
56
+ });
57
+ }
58
+
59
+ async function ensureJarExists(
60
+ version: string,
61
+ messages: string[]
62
+ ): Promise<string> {
63
+ const jarPath = join(JARS_DIR, `openapi-generator-cli-${version}.jar`);
64
+ const jarUrl = `https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/${version}/openapi-generator-cli-${version}.jar`;
65
+
66
+ if (!existsSync(jarPath)) {
67
+ messages.push(`Downloading OpenAPI Generator CLI v${version}...`);
68
+ try {
69
+ execSync(`curl -L -o ${jarPath} ${jarUrl}`, { stdio: "inherit" });
70
+ messages.push(`Downloaded ${jarPath}`);
71
+ } catch (error) {
72
+ messages.push("Failed to download JAR.");
73
+ throw error;
74
+ }
75
+ } else {
76
+ messages.push(`Using existing ${jarPath}`);
77
+ }
78
+ return jarPath;
79
+ }
80
+
81
+ function regenerateClient(jarPath: string, messages: string[]) {
82
+ messages.push("Regenerating client from spec...");
83
+ const command = `java -jar ${jarPath} generate -i ${SPEC_INPUT} -g typescript-fetch -o ${OUTPUT_DIR} --additional-properties=generateAliasAsModel=true`;
84
+ try {
85
+ execSync(command, { stdio: "inherit" });
86
+ messages.push("Client regeneration complete.");
87
+ } catch (error) {
88
+ messages.push("Regeneration failed.");
89
+ throw error;
90
+ }
91
+ }
92
+
93
+ async function main() {
94
+ const messages: string[] = [];
95
+ try {
96
+ if (!existsSync(SPEC_INPUT)) {
97
+ console.error(
98
+ `Spec file ${SPEC_INPUT} does not exist. Run 'npm run fix-spec' first.`
99
+ );
100
+ process.exit(1);
101
+ }
102
+ const versionToUse = await checkAndPromptForUpdate(messages);
103
+ const jarPath = await ensureJarExists(versionToUse, messages);
104
+ regenerateClient(jarPath, messages);
105
+ } catch (error) {
106
+ console.error("Error occurred during process:", error);
107
+ } finally {
108
+ console.log("\n--- Key Messages ---");
109
+ messages.forEach((msg) => console.log(msg));
110
+ }
111
+ }
112
+
113
+ main().catch((error) => {
114
+ console.error("Error in regeneration process:", error);
115
+ process.exit(1);
116
+ });
@@ -0,0 +1,100 @@
1
+ // schema/enhance-general.ts
2
+ import { Operation, Parameter, Spec } from "../types/spec.ts";
3
+ import { inferSchema } from "../utils/infer-schema.ts";
4
+
5
+ export function enhanceGeneral(spec: Spec): void {
6
+ spec.definitions = spec.definitions || {};
7
+
8
+ if (!spec.definitions["Record"]) {
9
+ spec.definitions["Record"] = {
10
+ type: "object",
11
+ additionalProperties: {
12
+ type: "object",
13
+ properties: { value: { type: "string" } },
14
+ required: ["value"],
15
+ },
16
+ description: "A generic QuickBase record with field ID-value pairs",
17
+ };
18
+ console.log("Added Record to definitions");
19
+ }
20
+
21
+ if (!spec.definitions["Permission"]) {
22
+ spec.definitions["Permission"] = {
23
+ type: "object",
24
+ properties: {
25
+ role: { type: "string", description: "The role name" },
26
+ permissionType: {
27
+ type: "string",
28
+ description: "Permission type (e.g., View, Modify)",
29
+ },
30
+ roleId: { type: "integer", description: "The role identifier" },
31
+ },
32
+ required: ["role", "permissionType", "roleId"],
33
+ description: "A single permission entry for a field",
34
+ };
35
+ console.log("Added Permission to definitions");
36
+ }
37
+
38
+ for (const pathKey in spec.paths) {
39
+ for (const method in spec.paths[pathKey]) {
40
+ const operation: Operation = spec.paths[pathKey][method];
41
+ const opId =
42
+ operation.operationId || `${method}${pathKey.replace(/\W/g, "")}`;
43
+
44
+ if (operation.parameters) {
45
+ operation.parameters.forEach((param: Parameter) => {
46
+ if (param.in !== "body" && !param.type && !param.schema) {
47
+ param.type = param.name.includes("Id") ? "string" : "string";
48
+ console.log(
49
+ `Set default type 'string' for ${pathKey}(${method}).${param.name}`
50
+ );
51
+ }
52
+ });
53
+ }
54
+
55
+ if (operation.responses) {
56
+ for (const status in operation.responses) {
57
+ const response = operation.responses[status];
58
+ if (response.schema) {
59
+ const cleanStatus = status.replace("/", "_");
60
+ const responseName = `${opId}${cleanStatus}Response`;
61
+ if (!spec.definitions[responseName]) {
62
+ console.log(
63
+ `Adding ${responseName} to definitions for ${pathKey}(${method})`
64
+ );
65
+ if (!response.schema.type && response["x-amf-mediaType"]) {
66
+ const mediaType = response["x-amf-mediaType"];
67
+ if (mediaType === "application/octet-stream") {
68
+ response.schema = {
69
+ type: "object",
70
+ properties: { data: { type: "string", format: "binary" } },
71
+ description:
72
+ response.schema?.description || "Binary file content",
73
+ };
74
+ } else if (mediaType === "application/x-yaml") {
75
+ response.schema = {
76
+ type: "object",
77
+ properties: { content: { type: "string", format: "yaml" } },
78
+ description: "YAML-formatted data",
79
+ };
80
+ } else if (
81
+ mediaType === "application/json" &&
82
+ response.schema.example
83
+ ) {
84
+ response.schema = inferSchema(
85
+ response.schema.example,
86
+ responseName
87
+ );
88
+ response.schema.description =
89
+ response.description || `Response for ${opId}`;
90
+ }
91
+ }
92
+ spec.definitions[responseName] = response.schema;
93
+ }
94
+ response.schema = { $ref: `#/definitions/${responseName}` };
95
+ }
96
+ }
97
+ }
98
+ }
99
+ }
100
+ }
@@ -0,0 +1,69 @@
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
+ // Fixed: Changed param to response
41
+ const prop = response.schema.properties[propKey];
42
+ if (prop.type === "array" && !prop.items) {
43
+ console.log(
44
+ `Fixing nested array for ${pathKey}(${method}).responses.${status}.${propKey}`
45
+ );
46
+ prop.items = { type: "string" };
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ }
53
+ }
54
+
55
+ console.log("Fixing array schemas in definitions...");
56
+ const definitions = spec.definitions || {};
57
+ for (const defKey in definitions) {
58
+ const def = definitions[defKey];
59
+ if (def.properties) {
60
+ for (const propKey in def.properties) {
61
+ const prop = def.properties[propKey];
62
+ if (prop.type === "array" && !prop.items) {
63
+ console.log(`Fixing missing items in ${defKey}.${propKey}`);
64
+ prop.items = { type: "string" };
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }
@@ -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
+ }
@@ -0,0 +1,156 @@
1
+ // schema/tags/fields.ts
2
+ import { Operation, Parameter, Spec } from "../../types/spec.ts";
3
+ import { normalizeDefinitionName } from "../../utils/naming.ts";
4
+
5
+ export function enhanceFields(
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("Fields")) {
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 (method === "delete") {
32
+ properties = {
33
+ fieldIds: { type: "array", items: { type: "integer" } },
34
+ };
35
+ } else {
36
+ properties = {
37
+ label: { type: "string", description: "The label of the field" },
38
+ fieldType: {
39
+ type: "string",
40
+ description: "The type of the field",
41
+ enum: [
42
+ "text",
43
+ "text-multiple-choice",
44
+ "text-multi-line",
45
+ "rich-text",
46
+ "numeric",
47
+ "currency",
48
+ "percent",
49
+ "rating",
50
+ "date",
51
+ "date-time",
52
+ "time-of-day",
53
+ "duration",
54
+ "checkbox",
55
+ "user",
56
+ "multi-user",
57
+ "address",
58
+ "email",
59
+ "phone",
60
+ "url",
61
+ "file",
62
+ "record-id",
63
+ ],
64
+ },
65
+ fieldHelp: {
66
+ type: "string",
67
+ description: "Help text for the field",
68
+ nullable: true,
69
+ },
70
+ addToForms: {
71
+ type: "boolean",
72
+ description: "Whether to add the field to forms",
73
+ nullable: true,
74
+ },
75
+ permissions: {
76
+ anyOf: [
77
+ {
78
+ type: "array",
79
+ items: { $ref: "#/definitions/Permission" },
80
+ },
81
+ { type: "null" },
82
+ ],
83
+ description: "Custom permissions for the field",
84
+ },
85
+ required: {
86
+ type: "boolean",
87
+ description: "Whether the field is required",
88
+ nullable: true,
89
+ },
90
+ unique: {
91
+ type: "boolean",
92
+ description: "Whether the field must have unique values",
93
+ nullable: true,
94
+ },
95
+ noWrap: {
96
+ type: "boolean",
97
+ description: "Whether text wrapping is disabled",
98
+ nullable: true,
99
+ },
100
+ bold: {
101
+ type: "boolean",
102
+ description: "Whether the field is bolded",
103
+ nullable: true,
104
+ },
105
+ appearsByDefault: {
106
+ type: "boolean",
107
+ description: "Whether the field appears by default in reports",
108
+ nullable: true,
109
+ },
110
+ findEnabled: {
111
+ type: "boolean",
112
+ description: "Whether the field is searchable",
113
+ nullable: true,
114
+ },
115
+ doesDataCopy: {
116
+ type: "boolean",
117
+ description: "Whether the field copies data",
118
+ nullable: true,
119
+ },
120
+ audited: {
121
+ type: "boolean",
122
+ description: "Whether changes to the field are audited",
123
+ nullable: true,
124
+ },
125
+ };
126
+ }
127
+ spec.definitions[requestName] = {
128
+ type: "object",
129
+ properties,
130
+ required: Object.keys(properties).filter(
131
+ (key) =>
132
+ ![
133
+ "fieldHelp",
134
+ "addToForms",
135
+ "permissions",
136
+ "required",
137
+ "unique",
138
+ "noWrap",
139
+ "bold",
140
+ "appearsByDefault",
141
+ "findEnabled",
142
+ "doesDataCopy",
143
+ "audited",
144
+ ].includes(key)
145
+ ),
146
+ description: operation.summary || `Request body for ${opId}`,
147
+ };
148
+ }
149
+ param.schema = { $ref: `#/definitions/${requestName}` };
150
+ console.log(
151
+ `Ensured ${requestName} in definitions for ${pathKey}(${method})`
152
+ );
153
+ }
154
+ });
155
+ }
156
+ }
@@ -0,0 +1,51 @@
1
+ // schema/tags/groups.ts
2
+ import { Operation, Parameter, Spec } from "../../types/spec.ts";
3
+ import { normalizeDefinitionName } from "../../utils/naming.ts";
4
+
5
+ export function enhanceGroups(
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 (
14
+ operation.parameters &&
15
+ operation.tags?.includes("Groups") &&
16
+ operation.summary?.toLowerCase().includes("subgroup")
17
+ ) {
18
+ operation.parameters.forEach((param: Parameter) => {
19
+ if (param.in === "body") {
20
+ if (!param.schema) param.schema = {};
21
+ let requestName =
22
+ param.schema.$ref?.split("/").pop() || `${opId}Request`;
23
+ requestName = normalizeDefinitionName(requestName);
24
+
25
+ if (
26
+ !spec.definitions[requestName] ||
27
+ !spec.definitions[requestName].type ||
28
+ Object.keys(spec.definitions[requestName]?.properties || {})
29
+ .length === 0
30
+ ) {
31
+ console.log(
32
+ `Defining schema for ${requestName} in ${pathKey}(${method})`
33
+ );
34
+ const properties = {
35
+ groupIds: { type: "array", items: { type: "string" } },
36
+ };
37
+ spec.definitions[requestName] = {
38
+ type: "object",
39
+ properties,
40
+ required: Object.keys(properties),
41
+ description: operation.summary || `Request body for ${opId}`,
42
+ };
43
+ }
44
+ param.schema = { $ref: `#/definitions/${requestName}` };
45
+ console.log(
46
+ `Ensured ${requestName} in definitions for ${pathKey}(${method})`
47
+ );
48
+ }
49
+ });
50
+ }
51
+ }
@@ -0,0 +1,68 @@
1
+ // schema/tags/index.ts
2
+ import { Operation, Parameter, Spec } from "../../types/spec.ts";
3
+ import { normalizeDefinitionName } from "../../utils/naming.ts";
4
+ import { enhanceUsers } from "./users.ts";
5
+ import { enhanceGroups } from "./groups.ts";
6
+ import { enhanceRecords } from "./records.ts";
7
+ import { enhanceApps } from "./apps.ts";
8
+ import { enhanceFields } from "./fields.ts";
9
+ import { enhanceTables } from "./tables.ts";
10
+
11
+ export function enhanceTags(spec: Spec): void {
12
+ spec.definitions = spec.definitions || {};
13
+
14
+ for (const pathKey in spec.paths) {
15
+ for (const method in spec.paths[pathKey]) {
16
+ const operation: Operation = spec.paths[pathKey][method];
17
+ const opId =
18
+ operation.operationId || `${method}${pathKey.replace(/\W/g, "")}`;
19
+
20
+ // Handle array schemas
21
+ if (operation.parameters) {
22
+ operation.parameters.forEach((param: Parameter) => {
23
+ if (param.in === "body") {
24
+ if (!param.schema) param.schema = {};
25
+ let requestName =
26
+ param.schema.$ref?.split("/").pop() || `${opId}Request`;
27
+ requestName = normalizeDefinitionName(requestName);
28
+
29
+ if (spec.definitions[requestName]?.type === "array") {
30
+ console.log(
31
+ `Wrapping array schema for ${requestName} in ${pathKey}(${method})`
32
+ );
33
+ const arraySchema = spec.definitions[requestName];
34
+ let wrapperPropName = operation.tags?.includes("Users")
35
+ ? "userIds"
36
+ : "items";
37
+ if (
38
+ operation.tags?.includes("Groups") &&
39
+ operation.summary?.toLowerCase().includes("subgroup")
40
+ ) {
41
+ wrapperPropName = "groupIds";
42
+ }
43
+ spec.definitions[requestName] = {
44
+ type: "object",
45
+ properties: { [wrapperPropName]: arraySchema },
46
+ required: arraySchema.minItems > 0 ? [wrapperPropName] : [],
47
+ description:
48
+ arraySchema.description || `Request body for ${opId}`,
49
+ };
50
+ param.schema = { $ref: `#/definitions/${requestName}` };
51
+ console.log(
52
+ `Ensured ${requestName} in definitions for ${pathKey}(${method})`
53
+ );
54
+ }
55
+ }
56
+ });
57
+ }
58
+
59
+ // Apply tag-specific enhancements
60
+ enhanceUsers(spec, pathKey, method, operation);
61
+ enhanceGroups(spec, pathKey, method, operation);
62
+ enhanceRecords(spec, pathKey, method, operation);
63
+ enhanceApps(spec, pathKey, method, operation);
64
+ enhanceFields(spec, pathKey, method, operation);
65
+ enhanceTables(spec, pathKey, method, operation);
66
+ }
67
+ }
68
+ }