diff --git a/.changeset/five-toes-kneel.md b/.changeset/five-toes-kneel.md new file mode 100644 index 0000000..6e07e9f --- /dev/null +++ b/.changeset/five-toes-kneel.md @@ -0,0 +1,5 @@ +--- +"@proofgeist/fmdapi": minor +--- + +Support for write operations in FileMaker 2024 diff --git a/README.md b/README.md index a24af21..9acdd72 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,8 @@ const result = await client.list({ layout: "Contacts" }); A (nearly) identical client designed to be used with the [fm-webviewer-fetch](https://github.com/proofgeist/fm-webviewer-fetch) library when integrating within a FileMaker WebViewer instead of the browser. Using this client requires a bit extra configuration within your FileMaker file, but provides great developer experience, especially when using TypeScript and the codegen features. +(v3.5+) Support for write operations in FileMaker 2024 + Install the [fm-webviewer-fetch](https://github.com/proofgeist/fm-webviewer-fetch) library to your project: ```sh @@ -257,14 +259,15 @@ import { fileTokenStore } from "@proofgeist/fmdapi/dist/tokenStore/file.js"; // | valueLists | `strict` `allowEmpty` `ignore` | `ignore` | If `strict`, will add enum types based on the value list defined for the field. If `allowEmpty`, will append `""` to the value list. Otherwise, fields are typed as normal. | | strictNumbers | `boolean` | `false` | (v2.2.11+) If true, the zod schema will apply a transformer to force all number fields to be either `number` or `null`.
**WARNING:** If you are not using Zod or the auto-generated layout specific client, enabling this option may result in false types! | | generateClient | `boolean` | none | If present, override the `generateClient` option for this schema only. | - + #### Codegen CLI options -| Option | Default | Description | -| --- | --- | --- | -| --init | false | Run with this flag to add the config file to your project | -| --config | - | path to a non-default config file | -| --env-path | .env.local | path to your .env file | -| --skip-env-check | - | Ignore loading environment variables from a file. | + +| Option | Default | Description | +| ----------------- | ---------- | --------------------------------------------------------- | +| --init | false | Run with this flag to add the config file to your project | +| --config | - | path to a non-default config file | +| --env-path | .env.local | path to your .env file | +| --skip-env-check | - | Ignore loading environment variables from a file. | ## FAQ diff --git a/src/wv.ts b/src/wv.ts index 1310add..b560b72 100644 --- a/src/wv.ts +++ b/src/wv.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { z } from "zod"; import { CreateParams, @@ -60,7 +61,7 @@ function DataApi< async function request(params: { layout: string; body: object; - action?: "read" | "metaData"; + action?: "read" | "metaData" | "create" | "update" | "delete" | "duplicate"; }): Promise { const { action = "read", layout, body } = params; const { fmFetch } = await import("@proofgeist/fm-webviewer-fetch").catch( @@ -142,6 +143,7 @@ function DataApi< ? ListParams & Partial & FetchOptions : ListParams & WithLayout & FetchOptions ): Promise> { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { layout = options.layout, fetch, ...params } = args ?? {}; if (layout === undefined) throw new Error("Must specify layout"); @@ -197,8 +199,7 @@ function DataApi< } /** * Create a new record in a given layout - * @deprecated Not supported by Execute Data API script step - * @throws {Error} Always + * @since FileMaker 2024 */ async function create( args: Opts["layout"] extends string @@ -218,6 +219,7 @@ function DataApi< : GetArgs & WithLayout & FetchOptions ): Promise> { args.recordId = asNumber(args.recordId); + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { recordId, layout = options.layout, fetch, ...params } = args; if (!layout) throw new Error("Must specify layout"); const data = await request({ @@ -230,8 +232,7 @@ function DataApi< } /** * Update a single record by internal RecordId - * @deprecated Not supported by Execute Data API script step - * @throws {Error} Always + * @since FileMaker 2024 */ async function update( args: Opts["layout"] extends string @@ -241,12 +242,16 @@ function DataApi< args.recordId = asNumber(args.recordId); // eslint-disable-next-line @typescript-eslint/no-unused-vars const { recordId, fieldData, layout = options.layout, ...params } = args; - throw new Error("Not supported by Execute Data API script step"); + if (!layout) throw new Error("Must specify layout"); + return (await request({ + action: "update", + layout, + body: { recordId, fieldData, ...params }, + })) as UpdateResponse; } /** * Delete a single record by internal RecordId - * @deprecated Not supported by Execute Data API script step - * @throws {Error} Always + * @since FileMaker 2024 */ async function deleteRecord( args: Opts["layout"] extends string @@ -256,7 +261,12 @@ function DataApi< args.recordId = asNumber(args.recordId); // eslint-disable-next-line @typescript-eslint/no-unused-vars const { recordId, layout = options.layout, fetch, ...params } = args; - throw new Error("Not supported by Execute Data API script step"); + if (!layout) throw new Error("Must specify layout"); + return (await request({ + action: "update", + layout, + body: { recordId, ...params }, + })) as DeleteResponse; } /** @@ -288,7 +298,9 @@ function DataApi< query: queryInput, layout = options.layout, ignoreEmptyResult = false, + // eslint-disable-next-line @typescript-eslint/no-unused-vars timeout, + // eslint-disable-next-line @typescript-eslint/no-unused-vars fetch, ...params } = args; @@ -371,11 +383,11 @@ function DataApi< return { list, listAll, - // create, + create, get, - // update, - // delete: deleteRecord, - // metadata, + update, + delete: deleteRecord, + metadata, find, findOne, findFirst,