Skip to content

Commit f3fa14e

Browse files
authored
fix execute script (#61)
2 parents 865e618 + a29ca94 commit f3fa14e

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

.changeset/old-pots-lose.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@proofkit/fmdapi": patch
3+
---
4+
5+
Update executeScript method to infer layout name from client

packages/fmdapi/src/adapters/core.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import type {
1111
Query,
1212
UpdateParams,
1313
UpdateResponse,
14+
ScriptParams,
15+
ScriptResponse,
1416
} from "../client-types.js";
1517

1618
export type BaseRequest = {
@@ -44,7 +46,10 @@ export type ContainerUploadOptions = BaseRequest & {
4446
modId?: number;
4547
};
4648
};
47-
49+
export type ExecuteScriptOptions = BaseRequest & {
50+
script: string;
51+
scriptParam?: string;
52+
};
4853
export type LayoutMetadataOptions = BaseRequest;
4954

5055
export interface Adapter {
@@ -59,4 +64,6 @@ export interface Adapter {
5964
layoutMetadata: (
6065
opts: LayoutMetadataOptions,
6166
) => Promise<LayoutMetadataResponse>;
67+
68+
executeScript: (opts: ExecuteScriptOptions) => Promise<ScriptResponse>;
6269
}

packages/fmdapi/src/adapters/fetch-base.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
ContainerUploadOptions,
1818
CreateOptions,
1919
DeleteOptions,
20+
ExecuteScriptOptions,
2021
FindOptions,
2122
GetOptions,
2223
LayoutMetadataOptions,
@@ -28,11 +29,6 @@ import type {
2829
GetTokenArguments,
2930
} from "./fetch-base-types.js";
3031

31-
export type ExecuteScriptOptions = BaseRequest & {
32-
script: string;
33-
scriptParam?: string;
34-
};
35-
3632
export class BaseFetchAdapter implements Adapter {
3733
protected server: string;
3834
protected db: string;

packages/fmdapi/src/client.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Adapter } from "./adapters/core.js";
1+
import type { Adapter, ExecuteScriptOptions } from "./adapters/core.js";
22
import type {
33
CreateParams,
44
CreateResponse,
@@ -80,6 +80,7 @@ function DataApi<
8080
update,
8181
layoutMetadata,
8282
containerUpload,
83+
executeScript,
8384
...otherMethods
8485
} = options.adapter;
8586

@@ -126,6 +127,8 @@ function DataApi<
126127
timeout?: number;
127128
};
128129

130+
type ExecuteScriptArgs = Omit<ExecuteScriptOptions, "layout">;
131+
129132
/**
130133
* List all records from a given layout, no find criteria applied.
131134
*/
@@ -516,6 +519,13 @@ function DataApi<
516519
return result;
517520
}
518521

522+
async function _executeScript(args: ExecuteScriptArgs & FetchOptions) {
523+
return await executeScript({
524+
...args,
525+
layout,
526+
});
527+
}
528+
519529
return {
520530
...otherMethods,
521531
layout: options.layout as Opts["layout"],
@@ -532,6 +542,7 @@ function DataApi<
532542
findAll,
533543
layoutMetadata: _layoutMetadata,
534544
containerUpload: _containerUpload,
545+
executeScript: _executeScript,
535546
};
536547
}
537548

packages/fmdapi/tests/client-methods.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ describe("other methods", () => {
319319
const resp = await client.executeScript({
320320
script: "script",
321321
scriptParam: param,
322-
layout: client.layout,
323322
});
324323

325324
expect(resp.scriptResult).toBe("result");

0 commit comments

Comments
 (0)