@jd-data-limited/easy-fm 3.2.8 → 4.0.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 (72) hide show
  1. package/README.md +36 -24
  2. package/package.json +12 -9
  3. package/src/FMError.js +2 -2
  4. package/src/FMError.ts +2 -2
  5. package/src/connection/FMHost.d.ts +2 -1
  6. package/src/connection/FMHost.js +1 -2
  7. package/src/connection/FMHost.ts +4 -4
  8. package/src/connection/HostBase.d.ts +1 -1
  9. package/src/connection/HostBase.js +1 -1
  10. package/src/connection/HostBase.ts +2 -4
  11. package/src/connection/database.d.ts +9 -8
  12. package/src/connection/database.js +6 -7
  13. package/src/connection/database.ts +14 -13
  14. package/src/connection/databaseBase.d.ts +4 -4
  15. package/src/connection/databaseBase.js +1 -1
  16. package/src/connection/databaseBase.ts +4 -6
  17. package/src/databaseStructure.d.ts +6 -0
  18. package/src/databaseStructure.js +4 -0
  19. package/src/databaseStructure.ts +12 -0
  20. package/src/index.d.ts +3 -6
  21. package/src/index.js +3 -5
  22. package/src/index.ts +4 -9
  23. package/src/layouts/layout.d.ts +3 -17
  24. package/src/layouts/layout.js +2 -20
  25. package/src/layouts/layout.ts +5 -27
  26. package/src/layouts/layoutBase.d.ts +3 -3
  27. package/src/layouts/layoutBase.js +1 -1
  28. package/src/layouts/layoutBase.ts +4 -5
  29. package/src/layouts/layoutInterface.d.ts +1 -1
  30. package/src/layouts/layoutInterface.js +1 -1
  31. package/src/layouts/layoutInterface.ts +2 -2
  32. package/src/layouts/layoutRecordManager.d.ts +5 -6
  33. package/src/layouts/layoutRecordManager.js +5 -9
  34. package/src/layouts/layoutRecordManager.ts +9 -14
  35. package/src/layouts/recordFieldsMap.d.ts +2 -2
  36. package/src/layouts/recordFieldsMap.js +1 -1
  37. package/src/layouts/recordFieldsMap.ts +3 -3
  38. package/src/records/field.d.ts +3 -23
  39. package/src/records/field.js +3 -152
  40. package/src/records/field.ts +4 -169
  41. package/src/records/fieldBase.d.ts +30 -0
  42. package/src/records/fieldBase.js +154 -0
  43. package/src/records/fieldBase.ts +174 -0
  44. package/src/records/getOperations/recordGetOperation.d.ts +47 -11
  45. package/src/records/getOperations/recordGetOperation.js +142 -31
  46. package/src/records/getOperations/recordGetOperation.ts +172 -30
  47. package/src/records/layoutRecord.d.ts +8 -7
  48. package/src/records/layoutRecord.js +4 -2
  49. package/src/records/layoutRecord.ts +19 -11
  50. package/src/records/portal.d.ts +6 -5
  51. package/src/records/portal.js +1 -1
  52. package/src/records/portal.ts +7 -7
  53. package/src/records/portalBase.d.ts +5 -4
  54. package/src/records/portalBase.js +1 -1
  55. package/src/records/portalBase.ts +6 -6
  56. package/src/records/portalRecord.d.ts +6 -6
  57. package/src/records/portalRecord.js +3 -2
  58. package/src/records/portalRecord.ts +5 -5
  59. package/src/records/recordBase.d.ts +7 -12
  60. package/src/records/recordBase.js +6 -10
  61. package/src/records/recordBase.ts +10 -15
  62. package/src/types.d.ts +18 -15
  63. package/src/types.js +7 -1
  64. package/src/types.ts +20 -16
  65. package/src/records/getOperations/find.d.ts +0 -15
  66. package/src/records/getOperations/find.js +0 -70
  67. package/src/records/getOperations/find.ts +0 -77
  68. package/src/records/getOperations/recordGetRange.d.ts +0 -13
  69. package/src/records/getOperations/recordGetRange.js +0 -77
  70. package/src/records/getOperations/recordGetRange.ts +0 -77
  71. package/src/records/portalRecordBase.d.ts +0 -4
  72. package/src/records/portalRecordBase.js +0 -6
@@ -1,54 +1,196 @@
1
1
  /*
2
- * Copyright (c) 2023. See LICENSE file for more information
2
+ * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
 
5
5
  import {LayoutInterface} from "../../layouts/layoutInterface.js";
6
- import {Portal} from "../portal.js";
7
- import {limitPortalsInterface} from "../../types.js";
6
+ import {ScriptRequestData} from "../../types.js";
8
7
  import {LayoutBase} from "../../layouts/layoutBase.js"
8
+ import {LayoutRecord} from "../layoutRecord.js";
9
+ import {ApiRecordResponseObj} from "../../models/apiResults.js";
10
+ import {FMError} from "../../FMError.js";
9
11
 
10
- export class RecordGetOperation<T extends LayoutInterface> {
12
+ export type SortOrder = "ascend" | "descend"
13
+ export type FindRequest = {
14
+ [key: string]: string,
15
+ omit?: "true" | "false"
16
+ }
17
+ export type PortalRequest = {
18
+ name: string,
19
+ }
20
+
21
+ type PortalData<T extends LayoutInterface> = {
22
+ [key in keyof T["portals"]]: {
23
+ limit: number,
24
+ offset: number
25
+ }
26
+ }
27
+ export type GetOperationOptions<T extends LayoutInterface> = {
28
+ portals: Partial<PortalData<T>>,
29
+ limit?: number,
30
+ offset?: number
31
+ }
32
+
33
+ export class RecordGetOperation<T extends LayoutInterface, OPTIONS extends GetOperationOptions<T>> {
11
34
  protected layout: LayoutBase
12
35
  protected limit: number = 100
13
- protected scripts: object
14
- protected sort: object[]
15
- protected limitPortals: limitPortalsInterface[] = []
16
- protected offset: number = 0
36
+ protected scriptData: ScriptRequestData = {}
37
+ protected sortData: { fieldName: string, sortOrder: SortOrder }[] = []
38
+ protected portals: Partial<PortalData<T>>
39
+ protected offset: number = 1
40
+ protected queries: FindRequest[] = []
17
41
 
18
- constructor(layout: LayoutBase) {
42
+ constructor(layout: LayoutBase, options: OPTIONS) {
19
43
  this.layout = layout
20
- this.scripts = {
21
- "script": null, // Runs after everything
22
- "script.prerequeset": null, // Runs before the request
23
- "script.presort": null // Runs before the sort
44
+ this.sortData = []
45
+ this.portals = options.portals
46
+ this.offset = options.offset || 1 // Offset refers to the starting record. offset 1 is the same as no offset.
47
+ this.limit = options.limit || 100
48
+ }
49
+
50
+ get isFindRequest() {
51
+ return this.queries.length !== 0
52
+ }
53
+
54
+ protected generateParamsBody(offset: number, limit: number) {
55
+ const params: {[key: string]: any} = {
56
+ limit: limit.toString(),
57
+ offset: offset.toString(),
24
58
  }
25
- this.sort = []
59
+ if (this.sortData.length !== 0) params.sort = JSON.stringify(this.sortData)
60
+
61
+
62
+ if (this.scriptData.after) params["script"] = this.scriptData.after.name
63
+ if (this.scriptData.after?.parameter) params["script.param"] = this.scriptData.after.parameter
64
+
65
+ if (this.scriptData.presort) params["script.presort"] = this.scriptData.after.name
66
+ if (this.scriptData.presort?.parameter) params["script.presort.param"] = this.scriptData.after.parameter
67
+
68
+ if (this.scriptData.prerequest) params["script.prerequest"] = this.scriptData.after.name
69
+ if (this.scriptData.prerequest?.parameter) params["script.prerequest.param"] = this.scriptData.after.parameter
70
+
71
+ if (this.queries.length !== 0) params["query"] = this.queries
72
+
73
+ let portals = Object.keys(this.portals)
74
+ params["portal"] = portals
75
+ for (let portal of portals) {
76
+ params[`offset.${portal}`] = this.portals[portal].offset
77
+ params[`limit.${portal}`] = this.portals[portal].limit
78
+ }
79
+
80
+ return params
26
81
  }
82
+ protected generateParamsURL(offset: number, limit: number) {
83
+ const params = new URLSearchParams({
84
+ _limit: limit.toString(),
85
+ _offset: offset.toString(),
86
+ })
87
+ if (this.sortData.length !== 0) params.set("_sort", JSON.stringify(this.sortData))
27
88
 
28
- /*
29
- addToPortalLimit() will adjust the results of the get request so that if a layout has multiple portals in it,
30
- only data from the specified ones will be read. This may help reduce load on your FileMaker API
31
- */
32
- addToPortalLimit(portal: Portal<any>, offset = 0, limit = 100) {
33
- if (offset < 0) throw "Portal offset cannot be less than 0"
34
- this.limitPortals.push({portalName: portal.name, offset, limit})
35
- return this
89
+ if (this.scriptData.after) params.set("script", this.scriptData.after.name)
90
+ if (this.scriptData.after?.parameter) params.set("script.param", this.scriptData.after.parameter)
91
+
92
+ if (this.scriptData.presort) params.set("script.presort", this.scriptData.after.name)
93
+ if (this.scriptData.presort?.parameter) params.set("script.presort.param", this.scriptData.after.parameter)
94
+
95
+ if (this.scriptData.prerequest) params.set("script.prerequest", this.scriptData.after.name)
96
+ if (this.scriptData.prerequest?.parameter) params.set("script.prerequest.param", this.scriptData.after.parameter)
97
+
98
+ let portals = Object.keys(this.portals)
99
+ for (let portal of portals) {
100
+ params.set(`_offset.${portal}`, this.portals[portal].limit.toString())
101
+ params.set(`_offset.${portal}`, this.portals[portal].offset.toString())
102
+ }
103
+ params.set('portal', JSON.stringify(portals))
104
+
105
+ return params
36
106
  }
37
107
 
38
- setLimit(limit: number) {
39
- if (limit < 1) throw "Record limit too low"
40
- this.limit = limit
108
+ scripts(scripts: ScriptRequestData) {
109
+ this.scriptData = scripts;
41
110
  return this
42
111
  }
43
112
 
44
- addSort(fieldName, sortOrder) {
45
- this.sort.push({fieldName, sortOrder})
113
+ sort(fieldName: string, sortOrder: SortOrder) {
114
+ this.sortData.push({fieldName, sortOrder})
46
115
  return this
47
116
  }
48
117
 
49
- setOffset(offset: number) {
50
- if (offset < 0) throw "Record offset too low"
51
- this.offset = offset
118
+ addRequest(query: FindRequest) {
119
+ this.queries.push(query)
52
120
  return this
53
121
  }
122
+
123
+ fetch() {
124
+ return this.performFind(this.offset, this.limit)
125
+ }
126
+
127
+ private async performFind(offset: number, limit: number): Promise<LayoutRecord<T, keyof OPTIONS["portals"]>[]> {
128
+ let trace = new Error()
129
+ await this.layout.getLayoutMeta()
130
+
131
+ const is_find = this.isFindRequest
132
+ let endpoint = this.layout.endpoint + (is_find ? "/_find" : "/records")
133
+ if (!is_find) endpoint += "?" + new URLSearchParams(this.generateParamsURL(offset, limit)).toString()
134
+ const reqData = {
135
+ // port: 443,
136
+ method: is_find ? "POST" : "GET",
137
+ body: is_find ? JSON.stringify(this.generateParamsBody(offset, limit)) : undefined,
138
+ }
139
+
140
+ let res = await this.layout.database.apiRequest<ApiRecordResponseObj>(
141
+ endpoint,
142
+ reqData
143
+ )
144
+ if (res.messages[0].code === "0") {
145
+ // console.log("RESOLVING")
146
+ if (!this.layout.metadata) await this.layout.getLayoutMeta()
147
+ return res.response.data.map(item => {
148
+ return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData)
149
+ })
150
+ }
151
+ else if (res.messages[0].code == "401") {
152
+ // No records found, so return empty set
153
+ return []
154
+ }
155
+ else {
156
+ throw new FMError(res.messages[0].code, res.httpStatus, res, trace)
157
+ }
158
+ }
159
+
160
+ [Symbol.asyncIterator]() {
161
+ let nextOffset = this.offset
162
+ let startOffset: number = JSON.parse(JSON.stringify(this.offset))
163
+ let limit = this.limit
164
+
165
+ let exit_after_last_record = false
166
+ let records: LayoutRecord<T, keyof OPTIONS["portals"]>[] = []
167
+
168
+ const fetch = async () => {
169
+ const theoretical_limit = (limit - nextOffset) + startOffset
170
+ if (theoretical_limit === 0) {
171
+ exit_after_last_record = true
172
+ records = []
173
+ return
174
+ }
175
+ records = await this.performFind(nextOffset, theoretical_limit < 100 ? theoretical_limit : 100);
176
+ nextOffset += 100;
177
+ if (records.length < 100) exit_after_last_record = true
178
+ }
179
+
180
+ return {
181
+ next: async () => {
182
+ if (records.length === 0 && !exit_after_last_record) {
183
+ await fetch();
184
+ }
185
+
186
+ if (records.length === 0 && exit_after_last_record) {
187
+ return {done: true, value: undefined};
188
+ }
189
+ else {
190
+ const record = records.shift()
191
+ return {done: false, value: record};
192
+ }
193
+ }
194
+ };
195
+ }
54
196
  }
@@ -1,18 +1,19 @@
1
1
  import { extraBodyOptions, recordObject } from "../types.js";
2
2
  import { RecordBase } from "./recordBase.js";
3
3
  import { Portal } from "./portal.js";
4
- import { PortalInterface } from "../layouts/layoutInterface.js";
5
- import { RecordFieldsMap } from "../layouts/recordFieldsMap";
6
- import { LayoutRecordBase } from "./layoutRecordBase";
7
- export declare class LayoutRecord<T extends RecordFieldsMap, P extends PortalInterface> extends RecordBase<T> implements LayoutRecordBase {
8
- portals: P;
9
- constructor(layout: any, recordId: any, modId?: any, fieldData?: {}, portalData?: any);
4
+ import { LayoutInterface } from "../layouts/layoutInterface.js";
5
+ import { LayoutRecordBase } from "./layoutRecordBase.js";
6
+ import { LayoutBase } from "../layouts/layoutBase.js";
7
+ export declare class LayoutRecord<LAYOUT extends LayoutInterface, PORTALS_TO_INCLUDE = string> extends RecordBase<LAYOUT["fields"]> implements LayoutRecordBase {
8
+ portals: Pick<LAYOUT["portals"], PORTALS_TO_INCLUDE>;
9
+ private readonly portalsToInclude;
10
+ constructor(layout: LayoutBase, recordId: number | string, modId?: string | number, fieldData?: Record<string, string | number>, portalData?: any, portalsToInclude?: PORTALS_TO_INCLUDE[]);
10
11
  get portalsArray(): Portal<any>[];
11
12
  commit(extraBody?: extraBodyOptions): Promise<this>;
12
13
  protected processPortalData(portalData: any): void;
13
14
  get(): Promise<this>;
14
15
  getPortal(portal: any): Portal<any>;
15
- duplicate(): Promise<LayoutRecord<T, P>>;
16
+ duplicate(): Promise<LayoutRecord<LAYOUT>>;
16
17
  delete(): Promise<void>;
17
18
  toObject(filter?: (a: any) => any, portalFilter?: (a: any) => any, portalRowFilter?: (a: any) => any, portalFieldFilter?: (a: any) => any): recordObject;
18
19
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2023. See LICENSE file for more information
2
+ * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
  import { RecordBase } from "./recordBase.js";
5
5
  import { PortalRecord } from "./portalRecord.js";
@@ -8,9 +8,11 @@ import { FMError } from "../FMError.js";
8
8
  export class LayoutRecord extends RecordBase {
9
9
  // @ts-ignore
10
10
  portals = {};
11
- constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null) {
11
+ portalsToInclude;
12
+ constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null, portalsToInclude = []) {
12
13
  super(layout, recordId, modId);
13
14
  this.processFieldData(fieldData);
15
+ this.portalsToInclude = portalsToInclude;
14
16
  if (portalData) {
15
17
  this.processPortalData(portalData);
16
18
  }
@@ -1,24 +1,32 @@
1
1
  /*
2
- * Copyright (c) 2023. See LICENSE file for more information
2
+ * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
 
5
5
  import {extraBodyOptions, recordObject} from "../types.js";
6
6
  import {RecordBase} from "./recordBase.js";
7
7
  import {PortalRecord} from "./portalRecord.js";
8
8
  import {Portal} from "./portal.js";
9
- import {PortalInterface} from "../layouts/layoutInterface.js";
9
+ import {LayoutInterface} from "../layouts/layoutInterface.js";
10
10
  import {FMError} from "../FMError.js";
11
- import {RecordFieldsMap} from "../layouts/recordFieldsMap";
12
- import {LayoutRecordBase} from "./layoutRecordBase";
13
- import {ApiRecordResponseObj, ApiResultSetObj} from "../models/apiResults";
11
+ import {LayoutRecordBase} from "./layoutRecordBase.js";
12
+ import {ApiRecordResponseObj} from "../models/apiResults.js";
13
+ import {LayoutBase} from "../layouts/layoutBase.js"
14
14
 
15
- export class LayoutRecord<T extends RecordFieldsMap, P extends PortalInterface> extends RecordBase<T> implements LayoutRecordBase {
15
+ export class LayoutRecord<LAYOUT extends LayoutInterface, PORTALS_TO_INCLUDE = string> extends RecordBase<LAYOUT["fields"]> implements LayoutRecordBase {
16
16
  // @ts-ignore
17
- portals: P = {}
18
-
19
- constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null) {
17
+ portals: Pick<LAYOUT["portals"], PORTALS_TO_INCLUDE> = {}
18
+ private readonly portalsToInclude: PORTALS_TO_INCLUDE[]
19
+
20
+ constructor(
21
+ layout: LayoutBase,
22
+ recordId: number | string,
23
+ modId = recordId,
24
+ fieldData: Record<string, string | number> = {},
25
+ portalData = null, portalsToInclude: PORTALS_TO_INCLUDE[] = [])
26
+ {
20
27
  super(layout, recordId, modId);
21
28
  this.processFieldData(fieldData)
29
+ this.portalsToInclude = portalsToInclude
22
30
  if (portalData) {
23
31
  this.processPortalData(portalData)
24
32
  }
@@ -132,7 +140,7 @@ export class LayoutRecord<T extends RecordFieldsMap, P extends PortalInterface>
132
140
  return this.portalsArray.find(p => p.name === portal)
133
141
  }
134
142
 
135
- async duplicate(): Promise<LayoutRecord<T, P>> {
143
+ async duplicate(): Promise<LayoutRecord<LAYOUT>> {
136
144
  let trace = new Error()
137
145
  let res = await this.layout.database.apiRequest<{recordId: string, modId: string}>(this.endpoint, {
138
146
  port: 443,
@@ -143,7 +151,7 @@ export class LayoutRecord<T extends RecordFieldsMap, P extends PortalInterface>
143
151
  }
144
152
  else if (res.messages[0].code === "0") {
145
153
  let data = this.toObject((a) => true, (a) => true, (a) => false, (a) => false)
146
- let _res = new LayoutRecord<T, P>(this.layout, res.response.recordId, res.response.modId, data.fieldData, data.portalData)
154
+ let _res = new LayoutRecord<LAYOUT>(this.layout, res.response.recordId, res.response.modId, data.fieldData, data.portalData)
147
155
 
148
156
  this.emit("duplicated")
149
157
  return _res
@@ -1,11 +1,12 @@
1
1
  import { PortalRecord } from "./portalRecord.js";
2
- import { RecordFieldsMap } from "../layouts/recordFieldsMap";
3
- import { PortalBase } from "./portalBase";
4
- import { LayoutRecord } from "./layoutRecord";
2
+ import { RecordFieldsMap } from "../layouts/recordFieldsMap.js";
3
+ import { PortalBase } from "./portalBase.js";
4
+ import { LayoutRecord } from "./layoutRecord.js";
5
+ import { LayoutInterface } from "../layouts/layoutInterface.js";
5
6
  export declare class Portal<T extends RecordFieldsMap> implements PortalBase<T> {
6
- readonly record: LayoutRecord<any, any>;
7
+ readonly record: LayoutRecord<LayoutInterface>;
7
8
  readonly name: string;
8
9
  records: PortalRecord<T>[];
9
- constructor(record: LayoutRecord<any, any>, name: string);
10
+ constructor(record: LayoutRecord<LayoutInterface, any>, name: string);
10
11
  create(): PortalRecord<T>;
11
12
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2023. See LICENSE file for more information
2
+ * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
  import { PortalRecord } from "./portalRecord.js";
5
5
  export class Portal {
@@ -1,19 +1,19 @@
1
1
  /*
2
- * Copyright (c) 2023. See LICENSE file for more information
2
+ * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
 
5
5
  import {PortalRecord} from "./portalRecord.js";
6
- import {RecordFieldsMap} from "../layouts/recordFieldsMap";
7
- import {PortalBase} from "./portalBase";
8
- import {LayoutRecordBase} from "./layoutRecordBase";
9
- import {LayoutRecord} from "./layoutRecord";
6
+ import {RecordFieldsMap} from "../layouts/recordFieldsMap.js";
7
+ import {PortalBase} from "./portalBase.js";
8
+ import {LayoutRecord} from "./layoutRecord.js";
9
+ import {LayoutInterface} from "../layouts/layoutInterface.js";
10
10
 
11
11
  export class Portal<T extends RecordFieldsMap> implements PortalBase<T> {
12
- readonly record: LayoutRecord<any, any>;
12
+ readonly record: LayoutRecord<LayoutInterface>;
13
13
  readonly name: string;
14
14
  public records: PortalRecord<T>[];
15
15
 
16
- constructor(record: LayoutRecord<any, any>, name: string) {
16
+ constructor(record: LayoutRecord<LayoutInterface, any>, name: string) {
17
17
  this.record = record
18
18
  this.name = name
19
19
  }
@@ -1,8 +1,9 @@
1
- import { RecordFieldsMap } from "../layouts/recordFieldsMap";
2
- import { RecordBase } from "./recordBase";
3
- import { LayoutRecord } from "./layoutRecord";
1
+ import { RecordFieldsMap } from "../layouts/recordFieldsMap.js";
2
+ import { RecordBase } from "./recordBase.js";
3
+ import { LayoutRecord } from "./layoutRecord.js";
4
+ import { LayoutInterface } from "../layouts/layoutInterface.js";
4
5
  export interface PortalBase<T extends RecordFieldsMap> {
5
- readonly record: LayoutRecord<any, any>;
6
+ readonly record: LayoutRecord<LayoutInterface>;
6
7
  readonly name: string;
7
8
  records: RecordBase<T>[];
8
9
  }
@@ -1,4 +1,4 @@
1
1
  /*
2
- * Copyright (c) 2023. See LICENSE file for more information
2
+ * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
  export {};
@@ -1,14 +1,14 @@
1
1
  /*
2
- * Copyright (c) 2023. See LICENSE file for more information
2
+ * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
 
5
- import {RecordFieldsMap} from "../layouts/recordFieldsMap";
6
- import {LayoutRecordBase} from "./layoutRecordBase";
7
- import {RecordBase} from "./recordBase";
8
- import {LayoutRecord} from "./layoutRecord";
5
+ import {RecordFieldsMap} from "../layouts/recordFieldsMap.js";
6
+ import {RecordBase} from "./recordBase.js";
7
+ import {LayoutRecord} from "./layoutRecord.js";
8
+ import {LayoutInterface} from "../layouts/layoutInterface.js";
9
9
 
10
10
  export interface PortalBase<T extends RecordFieldsMap> {
11
- readonly record: LayoutRecord<any, any>
11
+ readonly record: LayoutRecord<LayoutInterface>
12
12
  readonly name: string
13
13
  records: RecordBase<T>[]
14
14
  }
@@ -1,13 +1,13 @@
1
- import { RecordBase, RecordTypes } from "./recordBase.js";
2
- import { extraBodyOptions } from "../types.js";
3
- import { RecordFieldsMap } from "../layouts/recordFieldsMap";
4
- import { PortalBase } from "./portalBase";
1
+ import { RecordBase } from "./recordBase.js";
2
+ import { extraBodyOptions, RecordTypes } from "../types.js";
3
+ import { RecordFieldsMap } from "../layouts/recordFieldsMap.js";
4
+ import { PortalBase } from "./portalBase.js";
5
5
  export declare class PortalRecord<T extends RecordFieldsMap> extends RecordBase<T> {
6
6
  readonly portal: PortalBase<T>;
7
7
  readonly type = RecordTypes.PORTAL;
8
8
  constructor(record: any, portal: any, recordId: any, modId?: any, fieldData?: {});
9
9
  _onSave(): void;
10
- commit(extraBody?: extraBodyOptions): Promise<import("./layoutRecord.js").LayoutRecord<any, any>>;
10
+ commit(extraBody?: extraBodyOptions): Promise<import("./layoutRecord.js").LayoutRecord<import("../index.js").LayoutInterface, string>>;
11
11
  toObject(fieldFilter: any): any;
12
- getField(field: any): import("./field.js").Field<import("./field.js").FieldValue>;
12
+ getField(field: any): import("./fieldBase.js").FieldBase<import("./fieldBase.js").FieldValue>;
13
13
  }
@@ -1,7 +1,8 @@
1
1
  /*
2
- * Copyright (c) 2023. See LICENSE file for more information
2
+ * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
- import { RecordBase, RecordTypes } from "./recordBase.js";
4
+ import { RecordBase } from "./recordBase.js";
5
+ import { RecordTypes } from "../types.js";
5
6
  export class PortalRecord extends RecordBase {
6
7
  portal;
7
8
  type = RecordTypes.PORTAL;
@@ -1,12 +1,12 @@
1
1
  /*
2
- * Copyright (c) 2023. See LICENSE file for more information
2
+ * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
 
5
- import {RecordBase, RecordTypes} from "./recordBase.js";
6
- import {extraBodyOptions, recordObject} from "../types.js";
5
+ import {RecordBase} from "./recordBase.js";
6
+ import {extraBodyOptions, recordObject, RecordTypes} from "../types.js";
7
7
 
8
- import {RecordFieldsMap} from "../layouts/recordFieldsMap";
9
- import {PortalBase} from "./portalBase";
8
+ import {RecordFieldsMap} from "../layouts/recordFieldsMap.js";
9
+ import {PortalBase} from "./portalBase.js";
10
10
 
11
11
  export class PortalRecord<T extends RecordFieldsMap> extends RecordBase<T> {
12
12
  readonly portal: PortalBase<T>;
@@ -1,16 +1,11 @@
1
- /// <reference types="node" />
1
+ /// <reference types="node" resolution-mode="require"/>
2
2
  import { EventEmitter } from "events";
3
- import { Field } from "./field.js";
4
- import { Layout } from "../layouts/layout.js";
5
- import { recordObject } from "../types.js";
6
- import { RecordFieldsMap } from "../layouts/recordFieldsMap";
7
- export declare enum RecordTypes {
8
- UNKNOWN = 0,
9
- LAYOUT = 1,
10
- PORTAL = 2
11
- }
3
+ import { FieldBase, FieldValue } from "./fieldBase.js";
4
+ import { recordObject, RecordTypes } from "../types.js";
5
+ import { RecordFieldsMap } from "../layouts/recordFieldsMap.js";
6
+ import { LayoutBase } from "../layouts/layoutBase.js";
12
7
  export declare class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
13
- readonly layout: Layout<any>;
8
+ readonly layout: LayoutBase;
14
9
  readonly type: RecordTypes;
15
10
  recordId: number;
16
11
  modId: number;
@@ -19,7 +14,7 @@ export declare class RecordBase<T extends RecordFieldsMap> extends EventEmitter
19
14
  constructor(layout: any, recordId: any, modId?: any);
20
15
  get endpoint(): string;
21
16
  get edited(): boolean;
22
- get fieldsArray(): Field<import("./field.js").FieldValue>[];
17
+ get fieldsArray(): FieldBase<FieldValue>[];
23
18
  protected processFieldData(fieldData: any): T;
24
19
  _onSave(): void;
25
20
  toObject(filter?: (a: any) => any, portalFilter?: (a: any) => any, portalRowFilter?: (a: any) => any, portalFieldFilter?: (a: any) => any): recordObject;
@@ -1,15 +1,10 @@
1
1
  /*
2
- * Copyright (c) 2023. See LICENSE file for more information
2
+ * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
  import { EventEmitter } from "events";
5
5
  import * as moment from "moment";
6
- import { Field } from "./field.js";
7
- export var RecordTypes;
8
- (function (RecordTypes) {
9
- RecordTypes[RecordTypes["UNKNOWN"] = 0] = "UNKNOWN";
10
- RecordTypes[RecordTypes["LAYOUT"] = 1] = "LAYOUT";
11
- RecordTypes[RecordTypes["PORTAL"] = 2] = "PORTAL";
12
- })(RecordTypes || (RecordTypes = {}));
6
+ import { FieldBase } from "./fieldBase.js";
7
+ import { RecordTypes } from "../types.js";
13
8
  export class RecordBase extends EventEmitter {
14
9
  layout;
15
10
  type = RecordTypes.UNKNOWN;
@@ -35,7 +30,7 @@ export class RecordBase extends EventEmitter {
35
30
  processFieldData(fieldData) {
36
31
  let fields = {};
37
32
  for (let key of Object.keys(fieldData)) {
38
- let _field = new Field(this, key, fieldData[key]);
33
+ let _field = new FieldBase(this, key, fieldData[key]);
39
34
  if (!!fieldData[key]) {
40
35
  if (_field.metadata.result === "timeStamp") {
41
36
  // @ts-ignore
@@ -74,7 +69,8 @@ export class RecordBase extends EventEmitter {
74
69
  }
75
70
  toObject(filter = (a) => a.edited, portalFilter = (a) => a.records.find(record => record.edited), portalRowFilter = (a) => a.edited, portalFieldFilter = (a) => a.edited) {
76
71
  let fields_processed = {};
77
- for (let field of this.fieldsArray.filter(field => filter(field))) {
72
+ let field;
73
+ for (field of this.fieldsArray.filter(field => filter(field))) {
78
74
  let value = field.value;
79
75
  if (value instanceof Date) {
80
76
  // @ts-ignore
@@ -1,22 +1,16 @@
1
1
  /*
2
- * Copyright (c) 2023. See LICENSE file for more information
2
+ * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
 
5
5
  import {EventEmitter} from "events";
6
6
  import * as moment from "moment";
7
- import {Field} from "./field.js";
8
- import {Layout} from "../layouts/layout.js";
9
- import {recordObject} from "../types.js";
10
- import {RecordFieldsMap} from "../layouts/recordFieldsMap";
11
-
12
- export enum RecordTypes {
13
- UNKNOWN,
14
- LAYOUT,
15
- PORTAL
16
- }
7
+ import {FieldBase, FieldValue} from "./fieldBase.js";
8
+ import {recordObject, RecordTypes} from "../types.js";
9
+ import {RecordFieldsMap} from "../layouts/recordFieldsMap.js";
10
+ import {LayoutBase} from "../layouts/layoutBase.js";
17
11
 
18
12
  export class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
19
- readonly layout: Layout<any>;
13
+ readonly layout: LayoutBase;
20
14
  readonly type: RecordTypes = RecordTypes.UNKNOWN;
21
15
  public recordId: number;
22
16
  modId: number;
@@ -38,7 +32,7 @@ export class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
38
32
  return !!this.fieldsArray.find(i => i.edited)
39
33
  }
40
34
 
41
- get fieldsArray() {
35
+ get fieldsArray(): FieldBase<FieldValue>[] {
42
36
  return Object.values(this.fields)
43
37
  }
44
38
 
@@ -46,7 +40,7 @@ export class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
46
40
  let fields: RecordFieldsMap = {}
47
41
 
48
42
  for (let key of Object.keys(fieldData)) {
49
- let _field = new Field(this, key, fieldData[key])
43
+ let _field = new FieldBase(this, key, fieldData[key])
50
44
  if (!!fieldData[key]) {
51
45
  if (_field.metadata.result === "timeStamp") {
52
46
  // @ts-ignore
@@ -91,7 +85,8 @@ export class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
91
85
  portalFieldFilter = (a) => a.edited
92
86
  ): recordObject {
93
87
  let fields_processed = {}
94
- for (let field of this.fieldsArray.filter(field => filter(field))) {
88
+ let field: FieldBase<FieldValue>
89
+ for (field of this.fieldsArray.filter(field => filter(field))) {
95
90
  let value = field.value
96
91
  if (value instanceof Date) {
97
92
  // @ts-ignore