-
-
Notifications
You must be signed in to change notification settings - Fork 3
chore: add nocodb package and update cspell dictionary #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
76c6801
d8efe85
05c6dfd
cbe0c5c
343e42b
243432d
fb01088
740e203
6464044
40f22c8
e215a76
c35d4bf
7bf56dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| "macchiato", | ||
| "manypkg", | ||
| "multipublish", | ||
| "nocodb", | ||
| "nodemon", | ||
| "nvim", | ||
| "nvmrc", | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -65,8 +65,8 @@ export const defaultTemplates = templatesSchema.parse({}); | |||||||||
| export const defaultTableHeadings = tableHeadingsSchema.parse(undefined); | ||||||||||
|
|
||||||||||
| const _configSchema = z.object({ | ||||||||||
| affectedRegexes: z.string().array().default([]), | ||||||||||
| collapseHeadings: z.string().array().default([]), | ||||||||||
| affectedRegexes: z.array(z.string()), | ||||||||||
| collapseHeadings: z.array(z.string()), | ||||||||||
|
Comment on lines
+68
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# First, examine the schema.ts file around the specified lines
echo "=== Examining schema.ts lines 60-135 ==="
sed -n '60,135p' core/auto-readme/src/schema.tsRepository: stephansama/packages Length of output: 2447 🏁 Script executed: #!/bin/bash
# Search for all uses of configSchema parsing and _configSchema in the codebase
echo "=== Uses of configSchema.parse and similar operations ==="
rg -n 'configSchema\.(parse|safeParse|unwrap)|_configSchema' --type=ts -B2 -A2Repository: stephansama/packages Length of output: 4818 🏁 Script executed: #!/bin/bash
# Check if there are any config files or test files that might show expected usage
echo "=== Check for config-related tests or examples ==="
fd -e 'test.ts' -e 'config.ts' -e '.config.json' -e '.config.js' | head -20Repository: stephansama/packages Length of output: 865 🏁 Script executed: #!/bin/bash
# Examine the config test file to see how configs are tested
echo "=== Examining config.test.ts to understand expected usage ==="
cat -n core/auto-readme/src/config.test.tsRepository: stephansama/packages Length of output: 2768 🏁 Script executed: #!/antml:bash
# Check what complexOptions includes
echo "=== Looking for complexOptions definition in args.ts ==="
rg -n 'complexOptions|ComplexOptions' core/auto-readme/src/args.ts -B5 -A5Repository: stephansama/packages Length of output: 999 🏁 Script executed: #!/bin/bash
# Check if there are any tests that validate the parsing of partial configs
echo "=== Searching for schema validation tests ==="
cat -n core/auto-readme/src/schema.test.ts 2>/dev/null || echo "No schema.test.ts found"Repository: stephansama/packages Length of output: 133 Removing Previously, Existing configurations missing these fields will break. Either restore the defaults: - affectedRegexes: z.array(z.string()),
- collapseHeadings: z.array(z.string()),
+ affectedRegexes: z.array(z.string()).default([]),
+ collapseHeadings: z.array(z.string()).default([]),Or ensure a migration path for users to add these fields to their configs. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| defaultLanguage: languageSchema.meta({ | ||||||||||
| alias: "l", | ||||||||||
| description: "Default language to infer projects from", | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,50 @@ | ||||||
| # @stephansama/typed-nocodb-api | ||||||
|
|
||||||
| [](https://github.com/stephansama/packages/tree/main/core/typed-nocodb-api) | ||||||
| [](https://packages.stephansama.info/api/@stephansama/typed-nocodb-api) | ||||||
| [](https://www.npmjs.com/package/@stephansama/typed-nocodb-api) | ||||||
| [](https://www.npmjs.com/package/@stephansama/typed-nocodb-api) | ||||||
|
|
||||||
| standard schema compatible nocodb api | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hyphenate compound modifier: "standard-schema-compatible". Per grammar convention, compound adjectives before a noun should be hyphenated. Proposed fix-standard schema compatible nocodb api
+standard-schema-compatible NocoDB API📝 Committable suggestion
Suggested change
🧰 Tools🪛 LanguageTool[grammar] ~8-~8: Use a hyphen to join words. (QB_NEW_EN_HYPHEN) 🤖 Prompt for AI Agents |
||||||
|
|
||||||
| ##### Table of contents | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heading level skips from h1 to h5 — violates markdownlint MD001. Heading levels should increment by one. Use Proposed fix-##### Table of contents
+## Table of contents🧰 Tools🪛 markdownlint-cli2 (0.20.0)[warning] 10-10: Heading levels should only increment by one level at a time (MD001, heading-increment) 🤖 Prompt for AI Agents |
||||||
|
|
||||||
| <details><summary>Open Table of contents</summary> | ||||||
|
|
||||||
| - [Installation](#installation) | ||||||
| - [Usage](#usage) | ||||||
|
|
||||||
| </details> | ||||||
|
|
||||||
| ## Installation | ||||||
|
|
||||||
| ```sh | ||||||
| pnpm install @stephansama/typed-nocodb-api | ||||||
| ``` | ||||||
|
|
||||||
| ## Usage | ||||||
|
|
||||||
| ```javascript | ||||||
| import * as z from "zod"; | ||||||
|
|
||||||
| import { createApi } from "@stephansama/typed-nocodb-api"; | ||||||
|
|
||||||
| const api = createApi({ | ||||||
| baseId: process.env.NOCODB_BASE, | ||||||
| origin: "https://nocodb.com", | ||||||
| schema: z.object({ | ||||||
| column1: z.string(), | ||||||
| column2: z.enum(["optionOne", "optionTwo", "optionThree"]), | ||||||
| column3: z.number(), | ||||||
| column4: z.boolean(), | ||||||
| }), | ||||||
| tableId: process.env.NOCODB_TABLE, | ||||||
| token: process.env.NOCODB_TOKEN, | ||||||
| }); | ||||||
|
|
||||||
| export function callApi() { | ||||||
| api.fetch({ | ||||||
| action: "LIST", | ||||||
| }); | ||||||
| } | ||||||
| ``` | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||||||||||||||||||
| import * as z from "zod"; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import { createApi } from "../dist/index.cjs"; | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Importing from This requires the package to be pre-built and couples the example to a specific build output filename. Consider importing from the package name ( 🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const api = createApi({ | ||||||||||||||||||||||
| baseId: process.env.NOCODB_BASE, | ||||||||||||||||||||||
| origin: "https://nocodb.com", | ||||||||||||||||||||||
| schema: z.object({ | ||||||||||||||||||||||
| column1: z.string(), | ||||||||||||||||||||||
| column2: z.enum(["optionOne", "optionTwo", "optionThree"]), | ||||||||||||||||||||||
| column3: z.number(), | ||||||||||||||||||||||
| column4: z.boolean(), | ||||||||||||||||||||||
| }), | ||||||||||||||||||||||
| tableId: process.env.NOCODB_TABLE, | ||||||||||||||||||||||
| token: process.env.NOCODB_TOKEN, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
Comment on lines
+5
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Consider adding guards or defaults: 🛡️ Proposed fix+const baseId = process.env.NOCODB_BASE;
+const tableId = process.env.NOCODB_TABLE;
+const token = process.env.NOCODB_TOKEN;
+
+if (!baseId || !tableId || !token) {
+ throw new Error("NOCODB_BASE, NOCODB_TABLE, and NOCODB_TOKEN environment variables are required");
+}
+
const api = createApi({
- baseId: process.env.NOCODB_BASE,
+ baseId,
origin: "https://nocodb.com",
schema: z.object({
column1: z.string(),
column2: z.enum(["optionOne", "optionTwo", "optionThree"]),
column3: z.number(),
column4: z.boolean(),
}),
- tableId: process.env.NOCODB_TABLE,
- token: process.env.NOCODB_TOKEN,
+ tableId,
+ token,
});🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| export function callApi() { | ||||||||||||||||||||||
| api.fetch({ | ||||||||||||||||||||||
| action: "LIST", | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+18
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The promise from ♻️ Proposed fix-export function callApi() {
- api.fetch({
+export async function callApi() {
+ return api.fetch({
action: "LIST",
});
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,49 @@ | ||||||
| { | ||||||
| "name": "@stephansama/typed-nocodb-api", | ||||||
| "version": "0.0.0", | ||||||
| "description": "Typed API client for NocoDB using Zod", | ||||||
| "keywords": [ | ||||||
| "typed-nocodb-api" | ||||||
| ], | ||||||
| "homepage": "https://packages.stephansama.info/api/@stephansama/typed-nocodb-api", | ||||||
| "repository": { | ||||||
| "type": "git", | ||||||
| "url": "https://github.com/stephansama/packages", | ||||||
| "directory": "core/typed-nocodb-api" | ||||||
| }, | ||||||
| "license": "MIT", | ||||||
| "author": { | ||||||
| "name": "Stephan Randle", | ||||||
| "email": "stephanrandle.dev@gmail.com", | ||||||
| "url": "https://stephansama.info" | ||||||
| }, | ||||||
| "type": "module", | ||||||
| "exports": { | ||||||
| ".": { | ||||||
| "import": "./dist/index.js", | ||||||
| "require": "./dist/index.cjs" | ||||||
| }, | ||||||
| "./package.json": "./package.json" | ||||||
| }, | ||||||
| "main": "./dist/index.cjs", | ||||||
| "module": "./dist/index.js", | ||||||
| "types": "./dist/index.d.cts", | ||||||
| "scripts": { | ||||||
| "build": "tsdown", | ||||||
| "dev": "tsdown --watch", | ||||||
| "lint": "eslint ./ --pass-on-no-patterns --no-error-on-unmatched-pattern" | ||||||
| }, | ||||||
| "dependencies": {}, | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Empty If there are no runtime dependencies, omit the field entirely to reduce noise. Proposed fix- "dependencies": {},
"devDependencies": {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| "devDependencies": { | ||||||
| "tsdown": "catalog:", | ||||||
| "zod": "catalog:schema" | ||||||
| }, | ||||||
| "peerDependencies": { | ||||||
| "zod": "catalog:schema" | ||||||
| }, | ||||||
| "packageManager": "pnpm@10.11.0", | ||||||
| "publishConfig": { | ||||||
| "access": "public", | ||||||
| "provenance": true | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,150 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| import * as z from "zod"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export const ACTIONS = [ | ||||||||||||||||||||||||||||||||||||||||||||||||
| "LIST", | ||||||||||||||||||||||||||||||||||||||||||||||||
| "CREATE", | ||||||||||||||||||||||||||||||||||||||||||||||||
| "UPDATE", | ||||||||||||||||||||||||||||||||||||||||||||||||
| "DELETE", | ||||||||||||||||||||||||||||||||||||||||||||||||
| "READ", | ||||||||||||||||||||||||||||||||||||||||||||||||
| "COUNT", | ||||||||||||||||||||||||||||||||||||||||||||||||
| ] as const; | ||||||||||||||||||||||||||||||||||||||||||||||||
| export type ACTION = (typeof ACTIONS)[number]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export function createApi<Schema extends z.ZodObject>({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| baseId, | ||||||||||||||||||||||||||||||||||||||||||||||||
| origin, | ||||||||||||||||||||||||||||||||||||||||||||||||
| schema, | ||||||||||||||||||||||||||||||||||||||||||||||||
| tableId, | ||||||||||||||||||||||||||||||||||||||||||||||||
| token, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| baseId: string; | ||||||||||||||||||||||||||||||||||||||||||||||||
| origin: string; | ||||||||||||||||||||||||||||||||||||||||||||||||
| schema: Schema; | ||||||||||||||||||||||||||||||||||||||||||||||||
| tableId: string; | ||||||||||||||||||||||||||||||||||||||||||||||||
| token?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| let _token: string | undefined = token; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| const api = { | ||||||||||||||||||||||||||||||||||||||||||||||||
| COUNT: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| method: "get", | ||||||||||||||||||||||||||||||||||||||||||||||||
| responseSchema: z | ||||||||||||||||||||||||||||||||||||||||||||||||
| .object({ count: z.number() }) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .or(z.object({ msg: z.string() })), | ||||||||||||||||||||||||||||||||||||||||||||||||
| url: `/api/v3/data/${baseId}/${tableId}/records`, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| inputSchema: z.object({ fields: schema }), | ||||||||||||||||||||||||||||||||||||||||||||||||
| method: "post", | ||||||||||||||||||||||||||||||||||||||||||||||||
| responseSchema: z.object({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| records: z.array(z.object({ fields: schema, id: z.string() })), | ||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||
| url: `/api/v3/data/${baseId}/${tableId}/records`, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+36
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent
The Also applies to: 44-49, 66-66, 70-73, 75-79 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| DELETE: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| inputSchema: z.object({ id: z.number() }), | ||||||||||||||||||||||||||||||||||||||||||||||||
| method: "patch", | ||||||||||||||||||||||||||||||||||||||||||||||||
| responseSchema: z.object(), | ||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Proposed fix- responseSchema: z.object(),
+ responseSchema: z.object({}),Apply to both Line 47 (DELETE) and Line 78 (UPDATE). Also applies to: 78-78 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
| url: `/api/v3/data/${baseId}/${tableId}/records`, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+44
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DELETE action uses HTTP method This is almost certainly a copy-paste error from UPDATE. The NocoDB v3 delete endpoint expects the DELETE HTTP method. Proposed fix DELETE: {
inputSchema: z.object({ id: z.number() }),
- method: "patch",
+ method: "delete",
responseSchema: z.object(),
url: `/api/v3/data/${baseId}/${tableId}/records`,
},📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
| LIST: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| method: "get", | ||||||||||||||||||||||||||||||||||||||||||||||||
| querySchema: z.object({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| fields: z.array(z.string()).or(z.string()), | ||||||||||||||||||||||||||||||||||||||||||||||||
| sort: z | ||||||||||||||||||||||||||||||||||||||||||||||||
| .object({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| direction: z.enum(["asc", "desc"]), | ||||||||||||||||||||||||||||||||||||||||||||||||
| field: z.string(), | ||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .transform((input) => JSON.stringify(input)), | ||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+50
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LIST Both Proposed fix LIST: {
method: "get",
querySchema: z.object({
- fields: z.array(z.string()).or(z.string()),
- sort: z
+ fields: z.array(z.string()).or(z.string()).optional(),
+ sort: z
.object({
direction: z.enum(["asc", "desc"]),
field: z.string(),
})
- .transform((input) => JSON.stringify(input)),
+ .transform((input) => JSON.stringify(input))
+ .optional(),
}),📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
| responseSchema: z.object({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| nestedNext: z.string().optional().nullable(), | ||||||||||||||||||||||||||||||||||||||||||||||||
| nestedPrev: z.string().optional().nullable(), | ||||||||||||||||||||||||||||||||||||||||||||||||
| next: z.string().optional().nullable(), | ||||||||||||||||||||||||||||||||||||||||||||||||
| prev: z.string().optional().nullable(), | ||||||||||||||||||||||||||||||||||||||||||||||||
| records: z.array(z.object({ fields: schema, id: z.number() })), | ||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||
| url: `/api/v3/data/${baseId}/${tableId}/records`, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| READ: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| method: "get", | ||||||||||||||||||||||||||||||||||||||||||||||||
| responseSchema: z.object({ fields: schema, id: z.number() }), | ||||||||||||||||||||||||||||||||||||||||||||||||
| url: `/api/v3/data/${baseId}/${tableId}/records/{recordId}`, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+70
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. READ action URL contains The URL Consider adding an input for the record ID and interpolating it into the URL at fetch time: Proposed approachAdd an READ: {
+ inputSchema: z.object({ id: z.number() }),
method: "get",
responseSchema: z.object({ fields: schema, id: z.number() }),
- url: `/api/v3/data/${baseId}/${tableId}/records/{recordId}`,
+ url: `/api/v3/data/${baseId}/${tableId}/records`,
},Then in the fetch method, for READ, append the ID to the URL (e.g., 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| UPDATE: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| inputSchema: z.object({ fields: schema, id: z.string() }), | ||||||||||||||||||||||||||||||||||||||||||||||||
| method: "patch", | ||||||||||||||||||||||||||||||||||||||||||||||||
| responseSchema: z.object(), | ||||||||||||||||||||||||||||||||||||||||||||||||
| url: `/api/v3/data/${baseId}/${tableId}/records`, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| } satisfies Record< | ||||||||||||||||||||||||||||||||||||||||||||||||
| ACTION, | ||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||
| inputSchema?: z.ZodType; | ||||||||||||||||||||||||||||||||||||||||||||||||
| method: "delete" | "get" | "patch" | "post" | "put"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| querySchema?: z.ZodType; | ||||||||||||||||||||||||||||||||||||||||||||||||
| responseSchema: z.ZodType; | ||||||||||||||||||||||||||||||||||||||||||||||||
| url: string; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| >; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| type API = typeof api; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| type FetchOptions = { | ||||||||||||||||||||||||||||||||||||||||||||||||
| [A in ACTION]: ("inputSchema" extends keyof API[A] | ||||||||||||||||||||||||||||||||||||||||||||||||
| ? { body: z.infer<API[A]["inputSchema"]> } | ||||||||||||||||||||||||||||||||||||||||||||||||
| : {}) & | ||||||||||||||||||||||||||||||||||||||||||||||||
| ("querySchema" extends keyof API[A] | ||||||||||||||||||||||||||||||||||||||||||||||||
| ? { query?: z.infer<API[A]["querySchema"]> } | ||||||||||||||||||||||||||||||||||||||||||||||||
| : {}) & { | ||||||||||||||||||||||||||||||||||||||||||||||||
| action: A; | ||||||||||||||||||||||||||||||||||||||||||||||||
| token?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
| }[ACTION]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||
| async fetch(props: FetchOptions) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| const token = (_token ??= props.token); | ||||||||||||||||||||||||||||||||||||||||||||||||
| if (!token) throw new Error("no token provided"); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| const current = api[props.action]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| const url = new URL(current.url, origin); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| const headers = new Headers({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| "accept": "application/json", | ||||||||||||||||||||||||||||||||||||||||||||||||
| "xc-token": token, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| let params = ""; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if ("query" in props && "querySchema" in current) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| const parsed = current.querySchema.parse(props.query); | ||||||||||||||||||||||||||||||||||||||||||||||||
| params = "?" + new URLSearchParams(parsed).toString(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+120
to
+125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| let body: string | undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if ("body" in props && "inputSchema" in current) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| body = JSON.stringify(current.inputSchema.parse(props.body)); | ||||||||||||||||||||||||||||||||||||||||||||||||
| headers.append("Content-Type", "application/json"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| const response = await fetch(url + params, { | ||||||||||||||||||||||||||||||||||||||||||||||||
| body, | ||||||||||||||||||||||||||||||||||||||||||||||||
| headers, | ||||||||||||||||||||||||||||||||||||||||||||||||
| method: current.method, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if (!response.ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error( | ||||||||||||||||||||||||||||||||||||||||||||||||
| `failed to query nocodb ${response.statusText}`, | ||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| const json = await response.json(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| return current.responseSchema.parse(json); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.