@jd-data-limited/easy-fm 4.0.14 → 4.1.0

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 (65) hide show
  1. package/package.json +12 -6
  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/bin/cli.js +7 -5
  6. package/src/bin/generateTypes.js +215 -121
  7. package/src/connection/FMHost.d.ts +28 -6
  8. package/src/connection/FMHost.js +52 -25
  9. package/src/connection/FMHost.ts +75 -43
  10. package/src/connection/HostBase.d.ts +7 -3
  11. package/src/connection/HostBase.ts +8 -4
  12. package/src/connection/database.d.ts +50 -17
  13. package/src/connection/database.js +94 -66
  14. package/src/connection/database.ts +125 -105
  15. package/src/connection/databaseBase.d.ts +11 -6
  16. package/src/connection/databaseBase.ts +9 -8
  17. package/src/connection/generateAuthorizationHeaders.d.ts +1 -1
  18. package/src/connection/generateAuthorizationHeaders.js +10 -10
  19. package/src/connection/generateAuthorizationHeaders.ts +21 -21
  20. package/src/databaseStructure.d.ts +2 -4
  21. package/src/databaseStructure.ts +3 -5
  22. package/src/index.d.ts +17 -17
  23. package/src/index.js +14 -14
  24. package/src/index.ts +28 -25
  25. package/src/layouts/layout.d.ts +17 -6
  26. package/src/layouts/layout.js +19 -8
  27. package/src/layouts/layout.ts +33 -23
  28. package/src/layouts/layoutBase.d.ts +5 -5
  29. package/src/layouts/layoutBase.ts +6 -6
  30. package/src/layouts/layoutInterface.d.ts +3 -5
  31. package/src/layouts/layoutInterface.ts +4 -6
  32. package/src/layouts/layoutRecordManager.d.ts +29 -6
  33. package/src/layouts/layoutRecordManager.js +32 -9
  34. package/src/layouts/layoutRecordManager.ts +42 -19
  35. package/src/layouts/recordFieldsMap.d.ts +2 -4
  36. package/src/layouts/recordFieldsMap.ts +2 -4
  37. package/src/models/apiResults.d.ts +7 -13
  38. package/src/models/apiResults.ts +58 -58
  39. package/src/records/field.d.ts +42 -12
  40. package/src/records/field.js +69 -59
  41. package/src/records/field.ts +102 -81
  42. package/src/records/getOperations/recordGetOperation.d.ts +44 -24
  43. package/src/records/getOperations/recordGetOperation.js +89 -58
  44. package/src/records/getOperations/recordGetOperation.ts +137 -108
  45. package/src/records/layoutRecord.d.ts +28 -14
  46. package/src/records/layoutRecord.js +75 -65
  47. package/src/records/layoutRecord.ts +126 -123
  48. package/src/records/layoutRecordBase.d.ts +2 -2
  49. package/src/records/layoutRecordBase.ts +3 -3
  50. package/src/records/portal.d.ts +19 -5
  51. package/src/records/portal.js +19 -5
  52. package/src/records/portal.ts +28 -16
  53. package/src/records/portalBase.d.ts +5 -5
  54. package/src/records/portalBase.ts +6 -6
  55. package/src/records/portalRecord.d.ts +16 -8
  56. package/src/records/portalRecord.js +16 -6
  57. package/src/records/portalRecord.ts +29 -19
  58. package/src/records/recordBase.d.ts +17 -7
  59. package/src/records/recordBase.js +32 -22
  60. package/src/records/recordBase.ts +50 -43
  61. package/src/types.d.ts +21 -24
  62. package/src/types.ts +55 -59
  63. package/src/utils/query.d.ts +12 -5
  64. package/src/utils/query.js +28 -9
  65. package/src/utils/query.ts +40 -15
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 {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,18 +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
- queryEscape
44
- }
43
+ queryEscape,
44
+ asDate,
45
+ asTime,
46
+ asTimestamp
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
  }
@@ -1,30 +1,53 @@
1
1
  /*
2
2
  * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
- import { LayoutRecord } from "../records/layoutRecord.js";
5
- import { RecordGetOperation } from "../records/getOperations/recordGetOperation.js";
4
+ import { LayoutRecord } from '../records/layoutRecord.js';
5
+ import { RecordGetOperation } from '../records/getOperations/recordGetOperation.js';
6
+ /**
7
+ * Manager class for handling layout records.
8
+ */
6
9
  export class LayoutRecordManager {
7
10
  layout;
8
11
  constructor(layout) {
9
12
  this.layout = layout;
10
13
  }
14
+ /**
15
+ * Creates a new layout record with the provided options.
16
+ *
17
+ * @param {OPTIONS} options - The options for creating the layout record.
18
+ * @return {Promise<LayoutRecord<PickPortals<T, OPTIONS['portals'][number]>>>}
19
+ * The newly created layout record.
20
+ */
11
21
  async create(options) {
12
- let metadata = await this.layout.getLayoutMeta();
13
- let fields = {};
14
- for (let _field of metadata.fieldMetaData) {
15
- fields[_field.name] = "";
22
+ const metadata = await this.layout.getLayoutMeta();
23
+ const fields = {};
24
+ for (const _field of metadata.fieldMetaData) {
25
+ fields[_field.name] = '';
16
26
  }
17
- let portals = {};
18
- for (let _portal of Object.keys(metadata.portalMetaData))
27
+ const portals = {};
28
+ for (const _portal of Object.keys(metadata.portalMetaData))
19
29
  portals[_portal] = [];
20
30
  return new LayoutRecord(this.layout, -1, 0, fields, portals);
21
31
  }
32
+ /**
33
+ * Retrieves a layout record based on the given recordId.
34
+ *
35
+ * @param {number} recordId - The identifier of the record to retrieve.
36
+ *
37
+ * @returns {Promise<LayoutRecord<PickPortals<T, never>>>} - A Promise that resolves with the retrieved layout record.
38
+ */
22
39
  async get(recordId) {
23
40
  await this.layout.getLayoutMeta();
24
- let record = new LayoutRecord(this.layout, recordId);
41
+ const record = new LayoutRecord(this.layout, recordId);
25
42
  await record.get();
26
43
  return record;
27
44
  }
45
+ /**
46
+ * Creates a new instance of RecordGetOperation with the given options.
47
+ *
48
+ * @param {Array} options - An array of options for the operation.
49
+ * @return {RecordGetOperation} - A new instance of RecordGetOperation.
50
+ */
28
51
  list(options) {
29
52
  return new RecordGetOperation(this.layout, options);
30
53
  }
@@ -2,42 +2,65 @@
2
2
  * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
 
5
- import {LayoutRecord} from "../records/layoutRecord.js";
6
- import {LayoutInterface} from "./layoutInterface.js";
7
- import {LayoutBase} from "./layoutBase.js"
8
- import {GetOperationOptions, RecordGetOperation} from "../records/getOperations/recordGetOperation.js";
9
- import {PickPortals, RecordFetchOptions} from "../types.js";
10
- import {ApiFieldData} from "../models/apiResults.js";
5
+ import {LayoutRecord} from '../records/layoutRecord.js'
6
+ import {type LayoutInterface} from './layoutInterface.js'
7
+ import {type LayoutBase} from './layoutBase.js'
8
+ import {type GetOperationOptions, RecordGetOperation} from '../records/getOperations/recordGetOperation.js'
9
+ import {type PickPortals, type RecordFetchOptions} from '../types.js'
10
+ import {type ApiFieldData} from '../models/apiResults.js'
11
11
 
12
+ /**
13
+ * Manager class for handling layout records.
14
+ */
12
15
  export class LayoutRecordManager<T extends LayoutInterface> {
13
- readonly layout: LayoutBase;
14
- constructor(layout: LayoutBase) {
16
+ readonly layout: LayoutBase
17
+ constructor (layout: LayoutBase) {
15
18
  this.layout = layout
16
19
  }
17
20
 
21
+ /**
22
+ * Creates a new layout record with the provided options.
23
+ *
24
+ * @param {OPTIONS} options - The options for creating the layout record.
25
+ * @return {Promise<LayoutRecord<PickPortals<T, OPTIONS['portals'][number]>>>}
26
+ * The newly created layout record.
27
+ */
18
28
  async create<OPTIONS extends RecordFetchOptions>(options: OPTIONS): Promise<LayoutRecord<
19
- PickPortals<T, OPTIONS["portals"][number]>
29
+ PickPortals<T, OPTIONS['portals'][number]>
20
30
  >> {
21
- let metadata = await this.layout.getLayoutMeta()
22
- let fields: ApiFieldData = {}
23
- for (let _field of metadata.fieldMetaData) {
24
- fields[_field.name] = ""
31
+ const metadata = await this.layout.getLayoutMeta()
32
+ const fields: ApiFieldData = {}
33
+ for (const _field of metadata.fieldMetaData) {
34
+ fields[_field.name] = ''
25
35
  }
26
- let portals: {[key: string]: []} = {}
27
- for (let _portal of Object.keys(metadata.portalMetaData)) portals[_portal] = []
36
+ const portals: Record<string, []> = {}
37
+ for (const _portal of Object.keys(metadata.portalMetaData)) portals[_portal] = []
28
38
  return new LayoutRecord(this.layout, -1, 0, fields, portals)
29
39
  }
30
40
 
31
- async get(recordId: number): Promise<LayoutRecord<
32
- PickPortals<T, never>
41
+ /**
42
+ * Retrieves a layout record based on the given recordId.
43
+ *
44
+ * @param {number} recordId - The identifier of the record to retrieve.
45
+ *
46
+ * @returns {Promise<LayoutRecord<PickPortals<T, never>>>} - A Promise that resolves with the retrieved layout record.
47
+ */
48
+ async get (recordId: number): Promise<LayoutRecord<
49
+ PickPortals<T, never>
33
50
  >> {
34
51
  await this.layout.getLayoutMeta()
35
- let record = new LayoutRecord<PickPortals<T, never>>(this.layout, recordId)
52
+ const record = new LayoutRecord<PickPortals<T, never>>(this.layout, recordId)
36
53
  await record.get()
37
54
  return record
38
55
  }
39
56
 
57
+ /**
58
+ * Creates a new instance of RecordGetOperation with the given options.
59
+ *
60
+ * @param {Array} options - An array of options for the operation.
61
+ * @return {RecordGetOperation} - A new instance of RecordGetOperation.
62
+ */
40
63
  list<OPTIONS extends GetOperationOptions<T>>(options: OPTIONS) {
41
64
  return new RecordGetOperation<T, OPTIONS>(this.layout, options)
42
65
  }
43
- }
66
+ }
@@ -1,4 +1,2 @@
1
- import { Field, FieldValue } from "../records/field.js";
2
- export interface RecordFieldsMap {
3
- [fieldName: string]: Field<FieldValue>;
4
- }
1
+ import { type Field, type FieldValue } from '../records/field.js';
2
+ export type RecordFieldsMap = Record<string, Field<FieldValue>>;
@@ -2,8 +2,6 @@
2
2
  * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
 
5
- import {Field, FieldValue} from "../records/field.js";
5
+ import {type Field, type FieldValue} from '../records/field.js'
6
6
 
7
- export interface RecordFieldsMap {
8
- [fieldName: string]: Field<FieldValue>
9
- }
7
+ export type RecordFieldsMap = Record<string, Field<FieldValue>>
@@ -38,9 +38,7 @@ export interface ApiLayout {
38
38
  }
39
39
  export interface ApiLayoutMetadata {
40
40
  fieldMetaData: ApiFieldMetadata[];
41
- portalMetaData: {
42
- [key: string]: ApiFieldMetadata[];
43
- };
41
+ portalMetaData: Record<string, ApiFieldMetadata[]>;
44
42
  valueLists: ApiValueList[];
45
43
  }
46
44
  export interface ApiFieldMetadata {
@@ -62,10 +60,10 @@ export interface ApiFieldMetadata {
62
60
  export interface ApiValueList {
63
61
  name: string;
64
62
  type: string;
65
- values: {
63
+ values: Array<{
66
64
  value: string;
67
65
  displayName: string;
68
- }[];
66
+ }>;
69
67
  }
70
68
  export interface ApiScriptResult {
71
69
  scriptError: string;
@@ -75,12 +73,8 @@ export interface ApiRecordResponseObj {
75
73
  data: ApiRowDataDef[];
76
74
  dataInfo: ApiResultSetObj;
77
75
  }
78
- export type ApiFieldData = {
79
- [key: string]: string | number;
80
- };
81
- export interface ApiPortalData {
82
- [key: string]: ApiFieldData[];
83
- }
76
+ export type ApiFieldData = Record<string, string | number>;
77
+ export type ApiPortalData = Record<string, ApiFieldData[]>;
84
78
  export interface ApiResultSetObj {
85
79
  database: string;
86
80
  layout: string;
@@ -94,10 +88,10 @@ export interface ApiRowDataDef {
94
88
  portalData: ApiPortalData;
95
89
  modId: string;
96
90
  recordId: string;
97
- portalDataInfo?: {
91
+ portalDataInfo?: Array<{
98
92
  database: string;
99
93
  table: string;
100
94
  foundCount: number;
101
95
  returnedCount: number;
102
- }[];
96
+ }>;
103
97
  }