@jd-data-limited/easy-fm 4.0.16 → 4.1.1

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 (64) hide show
  1. package/package.json +16 -7
  2. package/src/FMError.d.ts +2 -2
  3. package/src/FMError.js +507 -508
  4. package/src/FMError.ts +510 -511
  5. package/src/connection/FMHost.d.ts +23 -5
  6. package/src/connection/FMHost.js +42 -26
  7. package/src/connection/FMHost.ts +63 -49
  8. package/src/connection/HostBase.d.ts +3 -3
  9. package/src/connection/HostBase.ts +5 -5
  10. package/src/connection/database.d.ts +53 -20
  11. package/src/connection/database.js +107 -90
  12. package/src/connection/database.ts +133 -121
  13. package/src/connection/databaseBase.d.ts +11 -7
  14. package/src/connection/databaseBase.ts +8 -8
  15. package/src/connection/generateAuthorizationHeaders.d.ts +1 -1
  16. package/src/connection/generateAuthorizationHeaders.js +10 -10
  17. package/src/connection/generateAuthorizationHeaders.ts +21 -21
  18. package/src/databaseStructure.d.ts +2 -4
  19. package/src/databaseStructure.ts +3 -5
  20. package/src/index.d.ts +17 -17
  21. package/src/index.js +13 -13
  22. package/src/index.ts +24 -24
  23. package/src/layouts/layout.d.ts +17 -6
  24. package/src/layouts/layout.js +19 -8
  25. package/src/layouts/layout.ts +33 -23
  26. package/src/layouts/layoutBase.d.ts +5 -5
  27. package/src/layouts/layoutBase.ts +6 -6
  28. package/src/layouts/layoutInterface.d.ts +3 -5
  29. package/src/layouts/layoutInterface.ts +4 -6
  30. package/src/layouts/layoutRecordManager.d.ts +29 -6
  31. package/src/layouts/layoutRecordManager.js +32 -9
  32. package/src/layouts/layoutRecordManager.ts +42 -19
  33. package/src/layouts/recordFieldsMap.d.ts +2 -4
  34. package/src/layouts/recordFieldsMap.ts +2 -4
  35. package/src/models/apiResults.d.ts +7 -13
  36. package/src/models/apiResults.ts +58 -58
  37. package/src/records/field.d.ts +39 -17
  38. package/src/records/field.js +248 -131
  39. package/src/records/field.ts +160 -82
  40. package/src/records/getOperations/recordGetOperation.d.ts +44 -24
  41. package/src/records/getOperations/recordGetOperation.js +88 -61
  42. package/src/records/getOperations/recordGetOperation.ts +128 -108
  43. package/src/records/layoutRecord.d.ts +28 -14
  44. package/src/records/layoutRecord.js +69 -60
  45. package/src/records/layoutRecord.ts +121 -119
  46. package/src/records/layoutRecordBase.d.ts +2 -2
  47. package/src/records/layoutRecordBase.ts +3 -3
  48. package/src/records/portal.d.ts +19 -5
  49. package/src/records/portal.js +19 -5
  50. package/src/records/portal.ts +28 -16
  51. package/src/records/portalBase.d.ts +5 -5
  52. package/src/records/portalBase.ts +6 -6
  53. package/src/records/portalRecord.d.ts +16 -8
  54. package/src/records/portalRecord.js +16 -6
  55. package/src/records/portalRecord.ts +29 -19
  56. package/src/records/recordBase.d.ts +18 -8
  57. package/src/records/recordBase.js +23 -16
  58. package/src/records/recordBase.ts +41 -37
  59. package/src/types.d.ts +23 -30
  60. package/src/types.js +0 -5
  61. package/src/types.ts +55 -64
  62. package/src/utils/query.d.ts +7 -7
  63. package/src/utils/query.js +10 -10
  64. package/src/utils/query.ts +19 -20
@@ -1,12 +1,16 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import { HostBase } from "./HostBase.js";
3
- import { ApiResults } from "../models/apiResults.js";
4
- import { IncomingMessage } from "http";
1
+ import { type HostBase } from './HostBase.js';
2
+ import { type ApiResults } from '../models/apiResults.js';
3
+ import { RequestInfo, RequestInit, Response } from "node-fetch";
5
4
  export interface DatabaseBase {
6
5
  host: HostBase;
7
6
  readonly name: string;
8
7
  endpoint: string;
9
- apiRequestJSON<T = unknown>(url: string | Request, options?: RequestInit | undefined, autoRelogin?: boolean): Promise<ApiResults<T>>;
10
- apiRequestRaw(url: string | Request, options?: RequestInit | undefined): Promise<Response>;
11
- streamURL(url: string): Promise<IncomingMessage>;
8
+ token: string;
9
+ _apiRequestJSON: <T = unknown>(url: URL | RequestInfo, options?: RequestInit & {
10
+ headers?: Record<string, string>;
11
+ } | undefined, autoRelogin?: boolean) => Promise<ApiResults<T>>;
12
+ _apiRequestRaw: (url: URL | RequestInfo, options?: RequestInit & {
13
+ headers?: Record<string, string>;
14
+ useCookieJar?: boolean;
15
+ } | undefined) => Promise<Response>;
12
16
  }
@@ -2,18 +2,18 @@
2
2
  * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
 
5
- import {HostBase} from "./HostBase.js"
6
- import {ApiResults} from "../models/apiResults.js";
7
- import {IncomingMessage} from "http";
5
+ import {type HostBase} from './HostBase.js'
6
+ import {type ApiResults} from '../models/apiResults.js'
7
+ import {RequestInfo, RequestInit, Response} from "node-fetch";
8
8
 
9
9
  export interface DatabaseBase {
10
- host: HostBase,
10
+ host: HostBase
11
11
  readonly name: string
12
12
  endpoint: string
13
+ token: string
13
14
 
14
15
  // layouts: DatabaseStructure["layouts"]
15
16
 
16
- apiRequestJSON<T = unknown>(url: string | Request, options?: RequestInit | undefined, autoRelogin?: boolean): Promise<ApiResults<T>>
17
- apiRequestRaw(url: string | Request, options?: RequestInit | undefined): Promise<Response>
18
- streamURL(url: string): Promise<IncomingMessage>
19
- }
17
+ _apiRequestJSON: <T = unknown>(url: URL | RequestInfo, options?: RequestInit & { headers?: Record<string, string> } | undefined, autoRelogin?: boolean) => Promise<ApiResults<T>>
18
+ _apiRequestRaw: (url: URL | RequestInfo, options?: RequestInit & { headers?: Record<string, string>, useCookieJar?: boolean } | undefined) => Promise<Response>
19
+ }
@@ -1,2 +1,2 @@
1
- import { AuthorizationHeaders, AuthorizationHeadersOAuth, loginOptionsClaris, loginOptionsFileMaker, loginOptionsOAuth } from "../types.js";
1
+ import { type AuthorizationHeaders, type AuthorizationHeadersOAuth, type loginOptionsClaris, type loginOptionsFileMaker, type loginOptionsOAuth } from '../types.js';
2
2
  export declare function generateAuthorizationHeaders(credentials: loginOptionsOAuth | loginOptionsFileMaker | loginOptionsClaris): AuthorizationHeaders | AuthorizationHeadersOAuth;
@@ -3,21 +3,21 @@
3
3
  */
4
4
  export function generateAuthorizationHeaders(credentials) {
5
5
  switch (credentials.method) {
6
- case "filemaker":
6
+ case 'filemaker':
7
7
  return {
8
- "Content-Type": "application/json",
9
- "Authorization": "Basic " + Buffer.from(credentials.username + ":" + credentials.password).toString("base64")
8
+ 'Content-Type': 'application/json',
9
+ Authorization: 'Basic ' + Buffer.from((credentials).username + ':' + (credentials).password).toString('base64')
10
10
  };
11
- case "claris":
11
+ case 'claris':
12
12
  return {
13
- "Content-Type": "application/json",
14
- "Authorization": credentials.claris.fmid,
13
+ 'Content-Type': 'application/json',
14
+ Authorization: (credentials).claris.fmid
15
15
  };
16
- case "oauth":
16
+ case 'oauth':
17
17
  return {
18
- "Content-Type": "application/json",
19
- "X-FM-Data-OAuth-RequestId": credentials.oauth.requestId,
20
- "X-FM-Data-OAuth-Identifier": credentials.oauth.requestIdentifier
18
+ 'Content-Type': 'application/json',
19
+ 'X-FM-Data-OAuth-RequestId': (credentials).oauth.requestId,
20
+ 'X-FM-Data-OAuth-Identifier': (credentials).oauth.requestIdentifier
21
21
  };
22
22
  }
23
23
  }
@@ -3,30 +3,30 @@
3
3
  */
4
4
 
5
5
  import {
6
- AuthorizationHeaders,
7
- AuthorizationHeadersOAuth,
8
- loginOptionsClaris,
9
- loginOptionsFileMaker,
10
- loginOptionsOAuth
11
- } from "../types.js";
6
+ type AuthorizationHeaders,
7
+ type AuthorizationHeadersOAuth,
8
+ type loginOptionsClaris,
9
+ type loginOptionsFileMaker,
10
+ type loginOptionsOAuth
11
+ } from '../types.js'
12
12
 
13
- export function generateAuthorizationHeaders(credentials: loginOptionsOAuth | loginOptionsFileMaker | loginOptionsClaris): AuthorizationHeaders | AuthorizationHeadersOAuth {
13
+ export function generateAuthorizationHeaders (credentials: loginOptionsOAuth | loginOptionsFileMaker | loginOptionsClaris): AuthorizationHeaders | AuthorizationHeadersOAuth {
14
14
  switch (credentials.method) {
15
- case "filemaker":
15
+ case 'filemaker':
16
16
  return {
17
- "Content-Type": "application/json",
18
- "Authorization": "Basic " + Buffer.from((<loginOptionsFileMaker>credentials).username + ":" + (<loginOptionsFileMaker>credentials).password).toString("base64")
19
- } as AuthorizationHeaders
20
- case "claris":
17
+ 'Content-Type': 'application/json',
18
+ Authorization: 'Basic ' + Buffer.from((credentials).username + ':' + (credentials).password).toString('base64')
19
+ } satisfies AuthorizationHeaders
20
+ case 'claris':
21
21
  return {
22
- "Content-Type": "application/json",
23
- "Authorization": (<loginOptionsClaris>credentials).claris.fmid,
24
- } as AuthorizationHeaders
25
- case "oauth":
22
+ 'Content-Type': 'application/json',
23
+ Authorization: (credentials).claris.fmid
24
+ } satisfies AuthorizationHeaders
25
+ case 'oauth':
26
26
  return {
27
- "Content-Type": "application/json",
28
- "X-FM-Data-OAuth-RequestId": (<loginOptionsOAuth>credentials).oauth.requestId,
29
- "X-FM-Data-OAuth-Identifier": (<loginOptionsOAuth>credentials).oauth.requestIdentifier
30
- } as AuthorizationHeadersOAuth
27
+ 'Content-Type': 'application/json',
28
+ 'X-FM-Data-OAuth-RequestId': (credentials).oauth.requestId,
29
+ 'X-FM-Data-OAuth-Identifier': (credentials).oauth.requestIdentifier
30
+ } satisfies AuthorizationHeadersOAuth
31
31
  }
32
- }
32
+ }
@@ -1,6 +1,4 @@
1
- import { LayoutInterface } from "./layouts/layoutInterface.js";
1
+ import { type LayoutInterface } from './layouts/layoutInterface.js';
2
2
  export interface DatabaseStructure {
3
- layouts: {
4
- [key: string]: LayoutInterface;
5
- };
3
+ layouts: Record<string, LayoutInterface>;
6
4
  }
@@ -3,10 +3,8 @@
3
3
  */
4
4
 
5
5
  // import * as btoa from "btoa";
6
- import {LayoutInterface} from "./layouts/layoutInterface.js";
6
+ import {type LayoutInterface} from './layouts/layoutInterface.js'
7
7
 
8
8
  export interface DatabaseStructure {
9
- layouts: {
10
- [key: string]: LayoutInterface
11
- }
12
- }
9
+ layouts: Record<string, LayoutInterface>
10
+ }
package/src/index.d.ts CHANGED
@@ -1,18 +1,18 @@
1
- import FMHost from "./connection/FMHost.js";
2
- import { FMError } from "./FMError.js";
3
- import * as TYPES from "./types.js";
4
- import { PickPortals } from "./types.js";
5
- import { Database } from "./connection/database.js";
6
- import { Layout } from "./layouts/layout.js";
7
- import { RecordBase } from "./records/recordBase.js";
8
- import { LayoutRecord } from "./records/layoutRecord.js";
9
- import { LayoutInterface, PortalInterface } from "./layouts/layoutInterface.js";
10
- import { PortalRecord } from "./records/portalRecord.js";
11
- import { Portal } from "./records/portal.js";
12
- import { FindRequest, FindRequestRaw, RecordGetOperation } from "./records/getOperations/recordGetOperation.js";
13
- import { LayoutRecordManager } from "./layouts/layoutRecordManager.js";
14
- import { RecordFieldsMap } from "./layouts/recordFieldsMap.js";
15
- import { asDate, asTime, asTimestamp, query, queryEscape } from "./utils/query.js";
16
- import { Container, Field } from "./records/field.js";
1
+ import FMHost from './connection/FMHost.js';
2
+ import { FMError } from './FMError.js';
3
+ import * as TYPES from './types.js';
4
+ import { type PickPortals } from './types.js';
5
+ import { Database } from './connection/database.js';
6
+ import { Layout } from './layouts/layout.js';
7
+ import { RecordBase } from './records/recordBase.js';
8
+ import { LayoutRecord } from './records/layoutRecord.js';
9
+ import { type LayoutInterface, type PortalInterface } from './layouts/layoutInterface.js';
10
+ import { PortalRecord } from './records/portalRecord.js';
11
+ import { Portal } from './records/portal.js';
12
+ import { type FindRequest, type FindRequestRaw, RecordGetOperation } from './records/getOperations/recordGetOperation.js';
13
+ import { LayoutRecordManager } from './layouts/layoutRecordManager.js';
14
+ import { type RecordFieldsMap } from './layouts/recordFieldsMap.js';
15
+ import { asDate, asTime, asTimestamp, query, queryEscape } from './utils/query.js';
16
+ import { type Container, Field } from './records/field.js';
17
17
  export default FMHost;
18
- export { FMError, TYPES, Database, Layout, RecordBase, LayoutRecord, LayoutInterface, RecordFieldsMap, PortalInterface, PortalRecord, Portal, Field, RecordGetOperation, LayoutRecordManager, Container, PickPortals, FindRequestRaw, FindRequest, query, queryEscape, asDate, asTime, asTimestamp };
18
+ export { FMError, TYPES, Database, Layout, RecordBase, LayoutRecord, type LayoutInterface, type RecordFieldsMap, type PortalInterface, PortalRecord, Portal, Field, RecordGetOperation, LayoutRecordManager, type Container, type PickPortals, type FindRequestRaw, type FindRequest, query, queryEscape, asDate, asTime, asTimestamp };
package/src/index.js CHANGED
@@ -1,18 +1,18 @@
1
1
  /*
2
2
  * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
- import FMHost from "./connection/FMHost.js";
5
- import { FMError } from "./FMError.js";
6
- import * as TYPES from "./types.js";
7
- import { Database } from "./connection/database.js";
8
- import { Layout } from "./layouts/layout.js";
9
- import { RecordBase } from "./records/recordBase.js";
10
- import { LayoutRecord } from "./records/layoutRecord.js";
11
- import { PortalRecord } from "./records/portalRecord.js";
12
- import { Portal } from "./records/portal.js";
13
- import { RecordGetOperation } from "./records/getOperations/recordGetOperation.js";
14
- import { LayoutRecordManager } from "./layouts/layoutRecordManager.js";
15
- import { asDate, asTime, asTimestamp, query, queryEscape } from "./utils/query.js";
16
- import { Field } from "./records/field.js";
4
+ import FMHost from './connection/FMHost.js';
5
+ import { FMError } from './FMError.js';
6
+ import * as TYPES from './types.js';
7
+ import { Database } from './connection/database.js';
8
+ import { Layout } from './layouts/layout.js';
9
+ import { RecordBase } from './records/recordBase.js';
10
+ import { LayoutRecord } from './records/layoutRecord.js';
11
+ import { PortalRecord } from './records/portalRecord.js';
12
+ import { Portal } from './records/portal.js';
13
+ import { RecordGetOperation } from './records/getOperations/recordGetOperation.js';
14
+ import { LayoutRecordManager } from './layouts/layoutRecordManager.js';
15
+ import { asDate, asTime, asTimestamp, query, queryEscape } from './utils/query.js';
16
+ import { Field } from './records/field.js';
17
17
  export default FMHost;
18
18
  export { FMError, TYPES, Database, Layout, RecordBase, LayoutRecord, PortalRecord, Portal, Field, RecordGetOperation, LayoutRecordManager, query, queryEscape, asDate, asTime, asTimestamp };
package/src/index.ts CHANGED
@@ -2,22 +2,22 @@
2
2
  * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
 
5
- import FMHost from "./connection/FMHost.js";
6
- import {FMError} from "./FMError.js";
7
- import * as TYPES from "./types.js"
8
- import {PickPortals} from "./types.js"
9
- import {Database} from "./connection/database.js";
10
- import {Layout} from "./layouts/layout.js";
11
- import {RecordBase} from "./records/recordBase.js";
12
- import {LayoutRecord} from "./records/layoutRecord.js";
13
- import {LayoutInterface, PortalInterface} from "./layouts/layoutInterface.js";
14
- import {PortalRecord} from "./records/portalRecord.js";
15
- import {Portal} from "./records/portal.js";
16
- import {FindRequest, FindRequestRaw, RecordGetOperation} from "./records/getOperations/recordGetOperation.js";
17
- import {LayoutRecordManager} from "./layouts/layoutRecordManager.js";
18
- import {RecordFieldsMap} from "./layouts/recordFieldsMap.js";
19
- import {asDate, asTime, asTimestamp, query, queryEscape} from "./utils/query.js";
20
- import {Container, Field} from "./records/field.js";
5
+ import FMHost from './connection/FMHost.js'
6
+ import {FMError} from './FMError.js'
7
+ import * as TYPES from './types.js'
8
+ import {type PickPortals} from './types.js'
9
+ import {Database} from './connection/database.js'
10
+ import {Layout} from './layouts/layout.js'
11
+ import {RecordBase} from './records/recordBase.js'
12
+ import {LayoutRecord} from './records/layoutRecord.js'
13
+ import {type LayoutInterface, type PortalInterface} from './layouts/layoutInterface.js'
14
+ import {PortalRecord} from './records/portalRecord.js'
15
+ import {Portal} from './records/portal.js'
16
+ import {type FindRequest, type FindRequestRaw, RecordGetOperation} from './records/getOperations/recordGetOperation.js'
17
+ import {LayoutRecordManager} from './layouts/layoutRecordManager.js'
18
+ import {type RecordFieldsMap} from './layouts/recordFieldsMap.js'
19
+ import {asDate, asTime, asTimestamp, query, queryEscape} from './utils/query.js'
20
+ import {type Container, Field} from './records/field.js'
21
21
 
22
22
  export default FMHost
23
23
  export {
@@ -27,21 +27,21 @@ export {
27
27
  Layout,
28
28
  RecordBase,
29
29
  LayoutRecord,
30
- LayoutInterface,
31
- RecordFieldsMap,
32
- PortalInterface,
30
+ type LayoutInterface,
31
+ type RecordFieldsMap,
32
+ type PortalInterface,
33
33
  PortalRecord,
34
34
  Portal,
35
35
  Field,
36
36
  RecordGetOperation,
37
37
  LayoutRecordManager,
38
- Container,
39
- PickPortals,
40
- FindRequestRaw,
41
- FindRequest,
38
+ type Container,
39
+ type PickPortals,
40
+ type FindRequestRaw,
41
+ type FindRequest,
42
42
  query,
43
43
  queryEscape,
44
44
  asDate,
45
45
  asTime,
46
46
  asTimestamp
47
- }
47
+ }
@@ -1,9 +1,9 @@
1
- import { LayoutRecordManager } from "./layoutRecordManager.js";
2
- import { Script, ScriptResult } from "../types.js";
3
- import { LayoutInterface } from "./layoutInterface.js";
4
- import { LayoutBase } from "./layoutBase.js";
5
- import { DatabaseBase } from "../connection/databaseBase.js";
6
- import { ApiLayoutMetadata } from "../models/apiResults.js";
1
+ import { LayoutRecordManager } from './layoutRecordManager.js';
2
+ import { type Script, type ScriptResult } from '../types.js';
3
+ import { type LayoutInterface } from './layoutInterface.js';
4
+ import { type LayoutBase } from './layoutBase.js';
5
+ import { type DatabaseBase } from '../connection/databaseBase.js';
6
+ import { type ApiLayoutMetadata } from '../models/apiResults.js';
7
7
  export declare class Layout<T extends LayoutInterface> implements LayoutBase {
8
8
  readonly database: DatabaseBase;
9
9
  readonly name: string;
@@ -11,6 +11,17 @@ export declare class Layout<T extends LayoutInterface> implements LayoutBase {
11
11
  metadata: ApiLayoutMetadata | null;
12
12
  constructor(database: DatabaseBase, name: string);
13
13
  get endpoint(): string;
14
+ /**
15
+ * Executes a FileMaker script on this layout asynchronously and returns the result.
16
+ * @param {Script} script - The script to be executed.
17
+ * @returns {Promise<ScriptResult>} - A promise that resolves to the script result or rejects with an error.
18
+ */
14
19
  runScript(script: Script): Promise<ScriptResult>;
20
+ /**
21
+ * Retrieves the layout metadata
22
+ *
23
+ * @returns {Promise<ApiLayoutMetadata>} The layout metadata.
24
+ * @throws {FMError} If an error occurs during the API request.
25
+ */
15
26
  getLayoutMeta(): Promise<ApiLayoutMetadata>;
16
27
  }
@@ -1,8 +1,8 @@
1
1
  /*
2
2
  * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
- import { LayoutRecordManager } from "./layoutRecordManager.js";
5
- import { FMError } from "../FMError.js";
4
+ import { LayoutRecordManager } from './layoutRecordManager.js';
5
+ import { FMError } from '../FMError.js';
6
6
  export class Layout {
7
7
  database;
8
8
  name;
@@ -15,15 +15,20 @@ export class Layout {
15
15
  get endpoint() {
16
16
  return `${this.database.endpoint}/layouts/${this.name}`;
17
17
  }
18
+ /**
19
+ * Executes a FileMaker script on this layout asynchronously and returns the result.
20
+ * @param {Script} script - The script to be executed.
21
+ * @returns {Promise<ScriptResult>} - A promise that resolves to the script result or rejects with an error.
22
+ */
18
23
  async runScript(script) {
19
24
  let url = `${this.endpoint}/script/${encodeURIComponent(script.name)}`;
20
25
  if (script.parameter)
21
- url += "?script.param=" + encodeURIComponent(script.parameter);
22
- let res = await this.database.apiRequestJSON(url, {
23
- method: "GET"
26
+ url += '?script.param=' + encodeURIComponent(script.parameter);
27
+ const res = await this.database._apiRequestJSON(url, {
28
+ method: 'GET'
24
29
  });
25
- if (res.response && res.messages[0].code === "0") {
26
- let error = parseInt(res.response.scriptError);
30
+ if (res.response && res.messages[0].code === '0') {
31
+ const error = parseInt(res.response.scriptError);
27
32
  return {
28
33
  scriptError: error ? new FMError(error, 200, res) : undefined,
29
34
  scriptResult: res.response.scriptResult
@@ -33,11 +38,17 @@ export class Layout {
33
38
  throw new FMError(res.messages[0].code, res.httpStatus, res);
34
39
  }
35
40
  }
41
+ /**
42
+ * Retrieves the layout metadata
43
+ *
44
+ * @returns {Promise<ApiLayoutMetadata>} The layout metadata.
45
+ * @throws {FMError} If an error occurs during the API request.
46
+ */
36
47
  async getLayoutMeta() {
37
48
  if (this.metadata) {
38
49
  return this.metadata;
39
50
  }
40
- let res = await this.database.apiRequestJSON(this.endpoint);
51
+ const res = await this.database._apiRequestJSON(this.endpoint);
41
52
  if (!res.response)
42
53
  throw new FMError(res.messages[0].code, res.httpStatus, res);
43
54
  this.metadata = res.response;
@@ -2,55 +2,65 @@
2
2
  * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
 
5
- import {LayoutRecordManager} from "./layoutRecordManager.js";
6
- import {Script, ScriptResult} from "../types.js";
7
- import {LayoutInterface} from "./layoutInterface.js";
8
- import {FMError} from "../FMError.js";
9
- import {LayoutBase} from "./layoutBase.js"
10
- import {DatabaseBase} from "../connection/databaseBase.js";
11
- import {ApiLayoutMetadata, ApiScriptResult} from "../models/apiResults.js";
5
+ import {LayoutRecordManager} from './layoutRecordManager.js'
6
+ import {type Script, type ScriptResult} from '../types.js'
7
+ import {type LayoutInterface} from './layoutInterface.js'
8
+ import {FMError} from '../FMError.js'
9
+ import {type LayoutBase} from './layoutBase.js'
10
+ import {type DatabaseBase} from '../connection/databaseBase.js'
11
+ import {type ApiLayoutMetadata, type ApiScriptResult} from '../models/apiResults.js'
12
12
 
13
13
  export class Layout<T extends LayoutInterface> implements LayoutBase {
14
- readonly database: DatabaseBase;
15
- readonly name: string;
14
+ readonly database: DatabaseBase
15
+ readonly name: string
16
16
  readonly records = new LayoutRecordManager<T>(this)
17
- metadata: ApiLayoutMetadata | null = null;
17
+ metadata: ApiLayoutMetadata | null = null
18
18
 
19
- constructor(database: DatabaseBase, name: string) {
19
+ constructor (database: DatabaseBase, name: string) {
20
20
  this.database = database
21
21
  this.name = name
22
22
  }
23
23
 
24
-
25
- get endpoint() {
24
+ get endpoint () {
26
25
  return `${this.database.endpoint}/layouts/${this.name}`
27
26
  }
28
27
 
29
- async runScript(script: Script): Promise<ScriptResult> {
28
+ /**
29
+ * Executes a FileMaker script on this layout asynchronously and returns the result.
30
+ * @param {Script} script - The script to be executed.
31
+ * @returns {Promise<ScriptResult>} - A promise that resolves to the script result or rejects with an error.
32
+ */
33
+ async runScript (script: Script): Promise<ScriptResult> {
30
34
  let url = `${this.endpoint}/script/${encodeURIComponent(script.name)}`
31
- if (script.parameter) url += "?script.param=" + encodeURIComponent(script.parameter)
32
- let res = await this.database.apiRequestJSON<ApiScriptResult>(url, {
33
- method: "GET"
35
+ if (script.parameter) url += '?script.param=' + encodeURIComponent(script.parameter)
36
+ const res = await this.database._apiRequestJSON<ApiScriptResult>(url, {
37
+ method: 'GET'
34
38
  })
35
- if (res.response && res.messages[0].code === "0") {
36
- let error = parseInt(res.response.scriptError)
39
+ if (res.response && res.messages[0].code === '0') {
40
+ const error = parseInt(res.response.scriptError)
37
41
  return {
38
42
  scriptError: error ? new FMError(error, 200, res) : undefined,
39
43
  scriptResult: res.response.scriptResult
40
44
  }
41
45
  } else {
42
- throw new FMError(res.messages[0].code, res.httpStatus, res);
46
+ throw new FMError(res.messages[0].code, res.httpStatus, res)
43
47
  }
44
48
  }
45
49
 
46
- public async getLayoutMeta(): Promise<ApiLayoutMetadata> {
50
+ /**
51
+ * Retrieves the layout metadata
52
+ *
53
+ * @returns {Promise<ApiLayoutMetadata>} The layout metadata.
54
+ * @throws {FMError} If an error occurs during the API request.
55
+ */
56
+ public async getLayoutMeta (): Promise<ApiLayoutMetadata> {
47
57
  if (this.metadata) {
48
58
  return this.metadata
49
59
  }
50
60
 
51
- let res = await this.database.apiRequestJSON<ApiLayoutMetadata>(this.endpoint)
61
+ const res = await this.database._apiRequestJSON<ApiLayoutMetadata>(this.endpoint)
52
62
  if (!res.response) throw new FMError(res.messages[0].code, res.httpStatus, res)
53
63
  this.metadata = res.response
54
64
  return this.metadata
55
65
  }
56
- }
66
+ }
@@ -1,11 +1,11 @@
1
- import { Script, ScriptResult } from "../types.js";
2
- import { DatabaseBase } from "../connection/databaseBase.js";
3
- import { ApiLayoutMetadata } from "../models/apiResults.js";
1
+ import { type Script, type ScriptResult } from '../types.js';
2
+ import { type DatabaseBase } from '../connection/databaseBase.js';
3
+ import { type ApiLayoutMetadata } from '../models/apiResults.js';
4
4
  export interface LayoutBase {
5
5
  readonly name: string;
6
6
  metadata: ApiLayoutMetadata | null;
7
7
  endpoint: string;
8
- runScript(script: Script): Promise<ScriptResult>;
9
- getLayoutMeta(): Promise<ApiLayoutMetadata>;
8
+ runScript: (script: Script) => Promise<ScriptResult>;
9
+ getLayoutMeta: () => Promise<ApiLayoutMetadata>;
10
10
  database: DatabaseBase;
11
11
  }
@@ -2,15 +2,15 @@
2
2
  * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
 
5
- import {Script, ScriptResult} from "../types.js";
6
- import {DatabaseBase} from "../connection/databaseBase.js";
7
- import {ApiLayoutMetadata} from "../models/apiResults.js";
5
+ import {type Script, type ScriptResult} from '../types.js'
6
+ import {type DatabaseBase} from '../connection/databaseBase.js'
7
+ import {type ApiLayoutMetadata} from '../models/apiResults.js'
8
8
 
9
9
  export interface LayoutBase {
10
10
  readonly name: string
11
11
  metadata: ApiLayoutMetadata | null
12
12
  endpoint: string
13
- runScript(script: Script): Promise<ScriptResult>
14
- getLayoutMeta(): Promise<ApiLayoutMetadata>
13
+ runScript: (script: Script) => Promise<ScriptResult>
14
+ getLayoutMeta: () => Promise<ApiLayoutMetadata>
15
15
  database: DatabaseBase
16
- }
16
+ }
@@ -1,9 +1,7 @@
1
- import { Portal } from "../records/portal.js";
2
- import { RecordFieldsMap } from "./recordFieldsMap.js";
1
+ import { type Portal } from '../records/portal.js';
2
+ import { type RecordFieldsMap } from './recordFieldsMap.js';
3
3
  export interface LayoutInterface {
4
4
  fields: RecordFieldsMap;
5
5
  portals: PortalInterface;
6
6
  }
7
- export interface PortalInterface {
8
- [key: string | number | symbol]: Portal<RecordFieldsMap>;
9
- }
7
+ export type PortalInterface = Record<string | number | symbol, Portal<RecordFieldsMap>>;
@@ -2,14 +2,12 @@
2
2
  * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
 
5
- import {Portal} from "../records/portal.js";
6
- import {RecordFieldsMap} from "./recordFieldsMap.js";
5
+ import {type Portal} from '../records/portal.js'
6
+ import {type RecordFieldsMap} from './recordFieldsMap.js'
7
7
 
8
8
  export interface LayoutInterface {
9
- fields: RecordFieldsMap,
9
+ fields: RecordFieldsMap
10
10
  portals: PortalInterface
11
11
  }
12
12
 
13
- export interface PortalInterface {
14
- [key: string | number | symbol]: Portal<RecordFieldsMap>
15
- }
13
+ export type PortalInterface = Record<string | number | symbol, Portal<RecordFieldsMap>>
@@ -1,12 +1,35 @@
1
- import { LayoutRecord } from "../records/layoutRecord.js";
2
- import { LayoutInterface } from "./layoutInterface.js";
3
- import { LayoutBase } from "./layoutBase.js";
4
- import { GetOperationOptions, RecordGetOperation } from "../records/getOperations/recordGetOperation.js";
5
- import { PickPortals, RecordFetchOptions } from "../types.js";
1
+ import { LayoutRecord } from '../records/layoutRecord.js';
2
+ import { type LayoutInterface } from './layoutInterface.js';
3
+ import { type LayoutBase } from './layoutBase.js';
4
+ import { type GetOperationOptions, RecordGetOperation } from '../records/getOperations/recordGetOperation.js';
5
+ import { type PickPortals, type RecordFetchOptions } from '../types.js';
6
+ /**
7
+ * Manager class for handling layout records.
8
+ */
6
9
  export declare class LayoutRecordManager<T extends LayoutInterface> {
7
10
  readonly layout: LayoutBase;
8
11
  constructor(layout: LayoutBase);
9
- create<OPTIONS extends RecordFetchOptions>(options: OPTIONS): Promise<LayoutRecord<PickPortals<T, OPTIONS["portals"][number]>>>;
12
+ /**
13
+ * Creates a new layout record with the provided options.
14
+ *
15
+ * @param {OPTIONS} options - The options for creating the layout record.
16
+ * @return {Promise<LayoutRecord<PickPortals<T, OPTIONS['portals'][number]>>>}
17
+ * The newly created layout record.
18
+ */
19
+ create<OPTIONS extends RecordFetchOptions>(options: OPTIONS): Promise<LayoutRecord<PickPortals<T, OPTIONS['portals'][number]>>>;
20
+ /**
21
+ * Retrieves a layout record based on the given recordId.
22
+ *
23
+ * @param {number} recordId - The identifier of the record to retrieve.
24
+ *
25
+ * @returns {Promise<LayoutRecord<PickPortals<T, never>>>} - A Promise that resolves with the retrieved layout record.
26
+ */
10
27
  get(recordId: number): Promise<LayoutRecord<PickPortals<T, never>>>;
28
+ /**
29
+ * Creates a new instance of RecordGetOperation with the given options.
30
+ *
31
+ * @param {Array} options - An array of options for the operation.
32
+ * @return {RecordGetOperation} - A new instance of RecordGetOperation.
33
+ */
11
34
  list<OPTIONS extends GetOperationOptions<T>>(options: OPTIONS): RecordGetOperation<T, OPTIONS>;
12
35
  }