@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,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
  }
@@ -3,108 +3,108 @@
3
3
  */
4
4
 
5
5
  export enum ApiFieldTypes {
6
- NORMAL = "normal",
7
- CALCULATION = "calculation",
8
- SUMMARY = "summary"
6
+ NORMAL = 'normal',
7
+ CALCULATION = 'calculation',
8
+ SUMMARY = 'summary'
9
9
  }
10
10
 
11
11
  export enum ApiFieldDisplayTypes {
12
- EDIT_TEXT = "editText",
13
- POPUP_LIST = "popupList",
14
- CHECKBOX = "checkBox",
15
- RADIO_BUTTONS = "radioButtons",
16
- SELECTION_LIST = "selectionList",
17
- CALENDAR = "calendar",
18
- SECURE_TEXT = "secureText"
12
+ EDIT_TEXT = 'editText',
13
+ POPUP_LIST = 'popupList',
14
+ CHECKBOX = 'checkBox',
15
+ RADIO_BUTTONS = 'radioButtons',
16
+ SELECTION_LIST = 'selectionList',
17
+ CALENDAR = 'calendar',
18
+ SECURE_TEXT = 'secureText'
19
19
  }
20
20
 
21
21
  export enum ApiFieldResultTypes {
22
- TEXT = "text",
23
- NUMBER = "number",
24
- DATE = "date",
25
- TIME = "time",
26
- TIMESTAMP = "timeStamp",
27
- CONTAINER = "container"
22
+ TEXT = 'text',
23
+ NUMBER = 'number',
24
+ DATE = 'date',
25
+ TIME = 'time',
26
+ TIMESTAMP = 'timeStamp',
27
+ CONTAINER = 'container'
28
28
  }
29
29
 
30
30
  export interface ApiMessage {
31
- code: string,
31
+ code: string
32
32
  message: string
33
33
  }
34
34
 
35
35
  export interface ApiResults<T = unknown> {
36
- response?: null | T & {scriptError? : string},
37
- messages: ApiMessage[],
36
+ response?: null | T & { scriptError?: string }
37
+ messages: ApiMessage[]
38
38
  httpStatus: number
39
39
  }
40
40
 
41
41
  export interface ApiLayout {
42
- name: string,
43
- isFolder?: boolean,
42
+ name: string
43
+ isFolder?: boolean
44
44
  folderLayoutNames?: ApiLayout[]
45
45
  }
46
46
 
47
47
  export interface ApiLayoutMetadata {
48
- fieldMetaData: ApiFieldMetadata[],
49
- portalMetaData: {[key: string]: ApiFieldMetadata[]},
48
+ fieldMetaData: ApiFieldMetadata[]
49
+ portalMetaData: Record<string, ApiFieldMetadata[]>
50
50
  valueLists: ApiValueList[]
51
51
  }
52
52
 
53
53
  export interface ApiFieldMetadata {
54
- name: string,
55
- type: ApiFieldTypes,
56
- displayType: ApiFieldDisplayTypes,
57
- result: ApiFieldResultTypes,
58
- global: boolean,
59
- autoEnter: boolean,
60
- fourDigitYear: boolean,
61
- maxRepeat: number,
62
- maxCharacters: number,
63
- notEmpty: boolean,
64
- numeric: boolean,
65
- repetitions: number,
66
- timeOfDay: boolean,
54
+ name: string
55
+ type: ApiFieldTypes
56
+ displayType: ApiFieldDisplayTypes
57
+ result: ApiFieldResultTypes
58
+ global: boolean
59
+ autoEnter: boolean
60
+ fourDigitYear: boolean
61
+ maxRepeat: number
62
+ maxCharacters: number
63
+ notEmpty: boolean
64
+ numeric: boolean
65
+ repetitions: number
66
+ timeOfDay: boolean
67
67
  valueList: string
68
68
  }
69
69
 
70
70
  export interface ApiValueList {
71
- name: string,
72
- type: string,
73
- values: {value: string, displayName: string}[]
71
+ name: string
72
+ type: string
73
+ values: Array<{ value: string, displayName: string }>
74
74
  }
75
75
 
76
76
  export interface ApiScriptResult {
77
- scriptError: string,
77
+ scriptError: string
78
78
  scriptResult?: string
79
79
  }
80
80
 
81
81
  export interface ApiRecordResponseObj {
82
- data: ApiRowDataDef[],
82
+ data: ApiRowDataDef[]
83
83
  dataInfo: ApiResultSetObj
84
84
  }
85
85
 
86
- export type ApiFieldData = {[key: string]: string | number}
86
+ export type ApiFieldData = Record<string, string | number>
87
87
 
88
- export interface ApiPortalData {[key: string]: ApiFieldData[]}
88
+ export type ApiPortalData = Record<string, ApiFieldData[]>
89
89
 
90
90
  export interface ApiResultSetObj {
91
- database: string,
92
- layout: string,
93
- table: string,
94
- totalRecordCount: number,
95
- foundCount: number,
91
+ database: string
92
+ layout: string
93
+ table: string
94
+ totalRecordCount: number
95
+ foundCount: number
96
96
  returnedCount: number
97
97
  }
98
98
 
99
99
  export interface ApiRowDataDef {
100
- fieldData: ApiFieldData,
101
- portalData: ApiPortalData,
102
- modId: string,
103
- recordId: string,
104
- portalDataInfo?: {
105
- database: string,
106
- table: string,
107
- foundCount: number,
100
+ fieldData: ApiFieldData
101
+ portalData: ApiPortalData
102
+ modId: string
103
+ recordId: string
104
+ portalDataInfo?: Array<{
105
+ database: string
106
+ table: string
107
+ foundCount: number
108
108
  returnedCount: number
109
- }[]
110
- }
109
+ }>
110
+ }
@@ -1,31 +1,53 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- import * as http from "http";
4
- import { ContainerBufferResult, DownloadModes, RecordTypes } from "../types.js";
5
- import { ApiFieldMetadata } from "../models/apiResults.js";
6
- import { LayoutBase } from "../layouts/layoutBase.js";
7
- import { Moment } from "moment";
1
+ /// <reference types="node" />
2
+ import { RecordTypes } from '../types.js';
3
+ import { type ApiFieldMetadata } from '../models/apiResults.js';
4
+ import { type LayoutBase } from '../layouts/layoutBase.js';
5
+ import { type Moment } from 'moment';
8
6
  export type FieldValue = string | number | Moment | Container;
9
7
  export type Container = null;
10
- export type Parentable = {
8
+ export interface Parentable {
11
9
  layout: LayoutBase;
12
10
  type: RecordTypes;
13
11
  endpoint: string;
14
- };
12
+ portal?: {
13
+ name: string;
14
+ };
15
+ }
16
+ /**
17
+ * A class representing a field in a record.
18
+ *
19
+ * @template T - The type of the field value.
20
+ */
15
21
  export declare class Field<T extends FieldValue> {
22
+ #private;
16
23
  parent: Parentable;
17
24
  id: string;
18
- protected _value: T;
25
+ protected _value: T | null;
19
26
  edited: boolean;
27
+ static firstContainerDownload: Promise<any> | null;
20
28
  constructor(record: Parentable, id: string, contents: T);
21
- set(content: T): void;
29
+ /**
30
+ * Sets the value of the field.
31
+ *
32
+ * @param {T | null} content - The new content value to be set. Can be either the type T or null.
33
+ * @throws {Error} Cannot set container value using set(). Use upload() instead, if the result is a 'container'.
34
+ */
35
+ set(content: T | null): void;
22
36
  get metadata(): ApiFieldMetadata;
23
- get value(): T;
37
+ get value(): T | null;
24
38
  set value(value: T);
25
39
  get string(): string;
26
- get date(): Date;
27
- get number(): number;
28
- upload(buffer: Buffer, filename: string, mime: string): Promise<void>;
29
- download(mode: DownloadModes.Stream): Promise<http.IncomingMessage>;
30
- download(mode: DownloadModes.Buffer): Promise<ContainerBufferResult>;
40
+ /**
41
+ * Uploads a file to the container field.
42
+ *
43
+ * @param {Buffer} file - The file content as a buffer.
44
+ *
45
+ * @throws {Error} - Cannot upload a file to the field if it's not a container field.
46
+ * @throws {Error} - Upload failed with HTTP error.
47
+ *
48
+ * @returns {Promise<void>} - A promise that resolves when the file is successfully uploaded.
49
+ */
50
+ upload(file: File): Promise<void>;
51
+ stream(): Promise<NodeJS.ReadableStream>;
52
+ arrayBuffer(): Promise<ArrayBuffer>;
31
53
  }