@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.
- package/package.json +16 -7
- package/src/FMError.d.ts +2 -2
- package/src/FMError.js +507 -508
- package/src/FMError.ts +510 -511
- package/src/connection/FMHost.d.ts +23 -5
- package/src/connection/FMHost.js +42 -26
- package/src/connection/FMHost.ts +63 -49
- package/src/connection/HostBase.d.ts +3 -3
- package/src/connection/HostBase.ts +5 -5
- package/src/connection/database.d.ts +53 -20
- package/src/connection/database.js +107 -90
- package/src/connection/database.ts +133 -121
- package/src/connection/databaseBase.d.ts +11 -7
- package/src/connection/databaseBase.ts +8 -8
- package/src/connection/generateAuthorizationHeaders.d.ts +1 -1
- package/src/connection/generateAuthorizationHeaders.js +10 -10
- package/src/connection/generateAuthorizationHeaders.ts +21 -21
- package/src/databaseStructure.d.ts +2 -4
- package/src/databaseStructure.ts +3 -5
- package/src/index.d.ts +17 -17
- package/src/index.js +13 -13
- package/src/index.ts +24 -24
- package/src/layouts/layout.d.ts +17 -6
- package/src/layouts/layout.js +19 -8
- package/src/layouts/layout.ts +33 -23
- package/src/layouts/layoutBase.d.ts +5 -5
- package/src/layouts/layoutBase.ts +6 -6
- package/src/layouts/layoutInterface.d.ts +3 -5
- package/src/layouts/layoutInterface.ts +4 -6
- package/src/layouts/layoutRecordManager.d.ts +29 -6
- package/src/layouts/layoutRecordManager.js +32 -9
- package/src/layouts/layoutRecordManager.ts +42 -19
- package/src/layouts/recordFieldsMap.d.ts +2 -4
- package/src/layouts/recordFieldsMap.ts +2 -4
- package/src/models/apiResults.d.ts +7 -13
- package/src/models/apiResults.ts +58 -58
- package/src/records/field.d.ts +39 -17
- package/src/records/field.js +248 -131
- package/src/records/field.ts +160 -82
- package/src/records/getOperations/recordGetOperation.d.ts +44 -24
- package/src/records/getOperations/recordGetOperation.js +88 -61
- package/src/records/getOperations/recordGetOperation.ts +128 -108
- package/src/records/layoutRecord.d.ts +28 -14
- package/src/records/layoutRecord.js +69 -60
- package/src/records/layoutRecord.ts +121 -119
- package/src/records/layoutRecordBase.d.ts +2 -2
- package/src/records/layoutRecordBase.ts +3 -3
- package/src/records/portal.d.ts +19 -5
- package/src/records/portal.js +19 -5
- package/src/records/portal.ts +28 -16
- package/src/records/portalBase.d.ts +5 -5
- package/src/records/portalBase.ts +6 -6
- package/src/records/portalRecord.d.ts +16 -8
- package/src/records/portalRecord.js +16 -6
- package/src/records/portalRecord.ts +29 -19
- package/src/records/recordBase.d.ts +18 -8
- package/src/records/recordBase.js +23 -16
- package/src/records/recordBase.ts +41 -37
- package/src/types.d.ts +23 -30
- package/src/types.js +0 -5
- package/src/types.ts +55 -64
- package/src/utils/query.d.ts +7 -7
- package/src/utils/query.js +10 -10
- package/src/utils/query.ts +19 -20
package/src/records/portal.d.ts
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
|
-
import { PortalRecord } from
|
|
2
|
-
import { RecordFieldsMap } from
|
|
3
|
-
import { PortalBase } from
|
|
4
|
-
import { LayoutRecord } from
|
|
1
|
+
import { PortalRecord } from './portalRecord.js';
|
|
2
|
+
import { type RecordFieldsMap } from '../layouts/recordFieldsMap.js';
|
|
3
|
+
import { type PortalBase } from './portalBase.js';
|
|
4
|
+
import { type LayoutRecord } from './layoutRecord.js';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a portal.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of RecordFieldsMap.
|
|
9
|
+
* @class
|
|
10
|
+
* @implements {PortalBase<T>}
|
|
11
|
+
*/
|
|
5
12
|
export declare class Portal<T extends RecordFieldsMap> implements PortalBase<T> {
|
|
6
13
|
readonly record: LayoutRecord<any>;
|
|
7
14
|
readonly name: string;
|
|
8
|
-
records: PortalRecord<T
|
|
15
|
+
records: Array<PortalRecord<T>>;
|
|
9
16
|
constructor(record: LayoutRecord<any>, name: string);
|
|
17
|
+
/**
|
|
18
|
+
* Add a new record to the portal
|
|
19
|
+
* @function create
|
|
20
|
+
* @async
|
|
21
|
+
* @summary Creates a new record.
|
|
22
|
+
* @returns {Promise<PortalRecord<T>>} A Promise that resolves to the newly created record.
|
|
23
|
+
*/
|
|
10
24
|
create(): Promise<PortalRecord<T>>;
|
|
11
25
|
}
|
package/src/records/portal.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Copyright (c) 2023-2024. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
|
-
import { PortalRecord } from
|
|
4
|
+
import { PortalRecord } from './portalRecord.js';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a portal.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of RecordFieldsMap.
|
|
9
|
+
* @class
|
|
10
|
+
* @implements {PortalBase<T>}
|
|
11
|
+
*/
|
|
5
12
|
export class Portal {
|
|
6
13
|
record;
|
|
7
14
|
name;
|
|
@@ -10,12 +17,19 @@ export class Portal {
|
|
|
10
17
|
this.record = record;
|
|
11
18
|
this.name = name;
|
|
12
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Add a new record to the portal
|
|
22
|
+
* @function create
|
|
23
|
+
* @async
|
|
24
|
+
* @summary Creates a new record.
|
|
25
|
+
* @returns {Promise<PortalRecord<T>>} A Promise that resolves to the newly created record.
|
|
26
|
+
*/
|
|
13
27
|
async create() {
|
|
14
|
-
|
|
15
|
-
for (
|
|
16
|
-
fields[_field.name] =
|
|
28
|
+
const fields = {};
|
|
29
|
+
for (const _field of (await this.record.layout.getLayoutMeta()).portalMetaData[this.name]) {
|
|
30
|
+
fields[_field.name] = '';
|
|
17
31
|
}
|
|
18
|
-
|
|
32
|
+
const record = new PortalRecord(this.record, this, -1, -1, fields);
|
|
19
33
|
this.records.push(record);
|
|
20
34
|
return record;
|
|
21
35
|
}
|
package/src/records/portal.ts
CHANGED
|
@@ -2,30 +2,42 @@
|
|
|
2
2
|
* Copyright (c) 2023-2024. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {PortalRecord} from
|
|
6
|
-
import {RecordFieldsMap} from
|
|
7
|
-
import {PortalBase} from
|
|
8
|
-
import {LayoutRecord} from
|
|
5
|
+
import {PortalRecord} from './portalRecord.js'
|
|
6
|
+
import {type RecordFieldsMap} from '../layouts/recordFieldsMap.js'
|
|
7
|
+
import {type PortalBase} from './portalBase.js'
|
|
8
|
+
import {type LayoutRecord} from './layoutRecord.js'
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Represents a portal.
|
|
12
|
+
*
|
|
13
|
+
* @template T - The type of RecordFieldsMap.
|
|
14
|
+
* @class
|
|
15
|
+
* @implements {PortalBase<T>}
|
|
16
|
+
*/
|
|
10
17
|
export class Portal<T extends RecordFieldsMap> implements PortalBase<T> {
|
|
11
|
-
readonly record: LayoutRecord<any
|
|
12
|
-
readonly name: string
|
|
13
|
-
public records: PortalRecord<T
|
|
18
|
+
readonly record: LayoutRecord<any>
|
|
19
|
+
readonly name: string
|
|
20
|
+
public records: Array<PortalRecord<T>> = []
|
|
14
21
|
|
|
15
|
-
constructor(record: LayoutRecord<any>, name: string) {
|
|
22
|
+
constructor (record: LayoutRecord<any>, name: string) {
|
|
16
23
|
this.record = record
|
|
17
24
|
this.name = name
|
|
18
25
|
}
|
|
19
26
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Add a new record to the portal
|
|
29
|
+
* @function create
|
|
30
|
+
* @async
|
|
31
|
+
* @summary Creates a new record.
|
|
32
|
+
* @returns {Promise<PortalRecord<T>>} A Promise that resolves to the newly created record.
|
|
33
|
+
*/
|
|
34
|
+
async create () {
|
|
35
|
+
const fields: Record<string, string> = {}
|
|
36
|
+
for (const _field of (await this.record.layout.getLayoutMeta()).portalMetaData[this.name]) {
|
|
37
|
+
fields[_field.name] = ''
|
|
26
38
|
}
|
|
27
|
-
|
|
39
|
+
const record = new PortalRecord<T>(this.record, this, -1, -1, fields)
|
|
28
40
|
this.records.push(record)
|
|
29
41
|
return record
|
|
30
42
|
}
|
|
31
|
-
}
|
|
43
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { RecordFieldsMap } from
|
|
2
|
-
import { RecordBase } from
|
|
3
|
-
import { LayoutRecord } from
|
|
4
|
-
import { LayoutInterface } from
|
|
1
|
+
import { type RecordFieldsMap } from '../layouts/recordFieldsMap.js';
|
|
2
|
+
import { type RecordBase } from './recordBase.js';
|
|
3
|
+
import { type LayoutRecord } from './layoutRecord.js';
|
|
4
|
+
import { type LayoutInterface } from '../layouts/layoutInterface.js';
|
|
5
5
|
export interface PortalBase<T extends RecordFieldsMap> {
|
|
6
6
|
readonly record: LayoutRecord<LayoutInterface>;
|
|
7
7
|
readonly name: string;
|
|
8
|
-
records: RecordBase<T
|
|
8
|
+
records: Array<RecordBase<T>>;
|
|
9
9
|
}
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
* Copyright (c) 2023-2024. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {RecordFieldsMap} from
|
|
6
|
-
import {RecordBase} from
|
|
7
|
-
import {LayoutRecord} from
|
|
8
|
-
import {LayoutInterface} from
|
|
5
|
+
import {type RecordFieldsMap} from '../layouts/recordFieldsMap.js'
|
|
6
|
+
import {type RecordBase} from './recordBase.js'
|
|
7
|
+
import {type LayoutRecord} from './layoutRecord.js'
|
|
8
|
+
import {type LayoutInterface} from '../layouts/layoutInterface.js'
|
|
9
9
|
|
|
10
10
|
export interface PortalBase<T extends RecordFieldsMap> {
|
|
11
11
|
readonly record: LayoutRecord<LayoutInterface>
|
|
12
12
|
readonly name: string
|
|
13
|
-
records: RecordBase<T
|
|
14
|
-
}
|
|
13
|
+
records: Array<RecordBase<T>>
|
|
14
|
+
}
|
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
import { RecordBase } from
|
|
2
|
-
import { extraBodyOptions, RecordTypes } from
|
|
3
|
-
import { RecordFieldsMap } from
|
|
4
|
-
import { PortalBase } from
|
|
5
|
-
import { Field, FieldValue } from
|
|
1
|
+
import { RecordBase } from './recordBase.js';
|
|
2
|
+
import { type extraBodyOptions, RecordTypes } from '../types.js';
|
|
3
|
+
import { type RecordFieldsMap } from '../layouts/recordFieldsMap.js';
|
|
4
|
+
import { type PortalBase } from './portalBase.js';
|
|
5
|
+
import { type Field, type FieldValue } from './field.js';
|
|
6
|
+
/**
|
|
7
|
+
* Represents a PortalRecord, which is a record in a portal within a parent record.
|
|
8
|
+
* @template T - The type of the record's field map.
|
|
9
|
+
*/
|
|
6
10
|
export declare class PortalRecord<T extends RecordFieldsMap> extends RecordBase<T> {
|
|
7
11
|
readonly portal: PortalBase<T>;
|
|
8
12
|
readonly type = RecordTypes.PORTAL;
|
|
9
13
|
constructor(record: RecordBase<any>, portal: PortalBase<any>, recordId: number, modId?: number, fieldData?: {});
|
|
10
14
|
_onSave(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Commits the parent record, and in turn this one.
|
|
17
|
+
*
|
|
18
|
+
* @param {extraBodyOptions} [extraBody={}] - The optional extra body options.
|
|
19
|
+
* @returns {Promise} - A promise that resolves when the record is committed.
|
|
20
|
+
*/
|
|
11
21
|
commit(extraBody?: extraBodyOptions): Promise<import("./layoutRecord.js").LayoutRecord<import("../index.js").LayoutInterface>>;
|
|
12
22
|
toObject(fieldFilter: (a: Field<FieldValue>) => boolean): {
|
|
13
23
|
modId?: string;
|
|
14
24
|
recordId?: string;
|
|
15
|
-
} &
|
|
16
|
-
[key: string]: string;
|
|
17
|
-
};
|
|
25
|
+
} & Record<string, string>;
|
|
18
26
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Copyright (c) 2023-2024. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
|
-
import { RecordBase } from
|
|
5
|
-
import { RecordTypes } from
|
|
4
|
+
import { RecordBase } from './recordBase.js';
|
|
5
|
+
import { RecordTypes } from '../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Represents a PortalRecord, which is a record in a portal within a parent record.
|
|
8
|
+
* @template T - The type of the record's field map.
|
|
9
|
+
*/
|
|
6
10
|
export class PortalRecord extends RecordBase {
|
|
7
11
|
portal;
|
|
8
12
|
type = RecordTypes.PORTAL;
|
|
@@ -14,15 +18,21 @@ export class PortalRecord extends RecordBase {
|
|
|
14
18
|
super._onSave();
|
|
15
19
|
this.portal.record._onSave();
|
|
16
20
|
}
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Commits the parent record, and in turn this one.
|
|
23
|
+
*
|
|
24
|
+
* @param {extraBodyOptions} [extraBody={}] - The optional extra body options.
|
|
25
|
+
* @returns {Promise} - A promise that resolves when the record is committed.
|
|
26
|
+
*/
|
|
27
|
+
async commit(extraBody = {}) {
|
|
28
|
+
return await this.portal.record.commit(extraBody);
|
|
19
29
|
}
|
|
20
30
|
toObject(fieldFilter) {
|
|
21
|
-
|
|
31
|
+
const res = {
|
|
22
32
|
recordId: this.recordId === -1 ? undefined : this.recordId.toString(),
|
|
23
33
|
modId: this.modId === -1 ? undefined : this.modId.toString()
|
|
24
34
|
};
|
|
25
|
-
for (
|
|
35
|
+
for (const field of this.fieldsArray.filter(a => fieldFilter(a)))
|
|
26
36
|
res[field.id] = field.value?.toString();
|
|
27
37
|
// console.log(res)
|
|
28
38
|
return res;
|
|
@@ -2,41 +2,51 @@
|
|
|
2
2
|
* Copyright (c) 2023-2024. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {RecordBase} from
|
|
6
|
-
import {extraBodyOptions, RecordTypes} from
|
|
5
|
+
import {RecordBase} from './recordBase.js'
|
|
6
|
+
import {type extraBodyOptions, RecordTypes} from '../types.js'
|
|
7
7
|
|
|
8
|
-
import {RecordFieldsMap} from
|
|
9
|
-
import {PortalBase} from
|
|
10
|
-
import {Field, FieldValue} from
|
|
8
|
+
import {type RecordFieldsMap} from '../layouts/recordFieldsMap.js'
|
|
9
|
+
import {type PortalBase} from './portalBase.js'
|
|
10
|
+
import {type Field, type FieldValue} from './field.js'
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Represents a PortalRecord, which is a record in a portal within a parent record.
|
|
14
|
+
* @template T - The type of the record's field map.
|
|
15
|
+
*/
|
|
12
16
|
export class PortalRecord<T extends RecordFieldsMap> extends RecordBase<T> {
|
|
13
|
-
readonly portal: PortalBase<T
|
|
17
|
+
readonly portal: PortalBase<T>
|
|
14
18
|
readonly type = RecordTypes.PORTAL
|
|
15
19
|
|
|
16
|
-
constructor(record: RecordBase<any>, portal: PortalBase<any>, recordId: number, modId = recordId, fieldData = {}) {
|
|
17
|
-
super(record.layout, recordId, modId, fieldData)
|
|
20
|
+
constructor (record: RecordBase<any>, portal: PortalBase<any>, recordId: number, modId = recordId, fieldData = {}) {
|
|
21
|
+
super(record.layout, recordId, modId, fieldData)
|
|
18
22
|
this.portal = portal
|
|
19
23
|
}
|
|
20
24
|
|
|
21
|
-
_onSave() {
|
|
22
|
-
super._onSave()
|
|
25
|
+
_onSave () {
|
|
26
|
+
super._onSave()
|
|
23
27
|
this.portal.record._onSave()
|
|
24
28
|
}
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Commits the parent record, and in turn this one.
|
|
32
|
+
*
|
|
33
|
+
* @param {extraBodyOptions} [extraBody={}] - The optional extra body options.
|
|
34
|
+
* @returns {Promise} - A promise that resolves when the record is committed.
|
|
35
|
+
*/
|
|
36
|
+
async commit (extraBody: extraBodyOptions = {}) {
|
|
37
|
+
return await this.portal.record.commit(extraBody)
|
|
28
38
|
}
|
|
29
39
|
|
|
30
|
-
toObject(fieldFilter: (a: Field<FieldValue>) => boolean): {
|
|
31
|
-
modId?: string
|
|
32
|
-
recordId?: string
|
|
33
|
-
} &
|
|
34
|
-
|
|
40
|
+
toObject (fieldFilter: (a: Field<FieldValue>) => boolean): {
|
|
41
|
+
modId?: string
|
|
42
|
+
recordId?: string
|
|
43
|
+
} & Record<string, string> {
|
|
44
|
+
const res: any = {
|
|
35
45
|
recordId: this.recordId === -1 ? undefined : this.recordId.toString(),
|
|
36
46
|
modId: this.modId === -1 ? undefined : this.modId.toString()
|
|
37
47
|
}
|
|
38
|
-
for (
|
|
48
|
+
for (const field of this.fieldsArray.filter(a => fieldFilter(a))) res[field.id] = field.value?.toString()
|
|
39
49
|
// console.log(res)
|
|
40
50
|
return res
|
|
41
51
|
}
|
|
42
|
-
}
|
|
52
|
+
}
|
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
/// <reference types="node"
|
|
2
|
-
import { EventEmitter } from
|
|
3
|
-
import { RecordTypes } from
|
|
4
|
-
import { RecordFieldsMap } from
|
|
5
|
-
import { LayoutBase } from
|
|
6
|
-
import { ApiFieldData } from
|
|
7
|
-
import { Field, FieldValue } from
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { RecordTypes } from '../types.js';
|
|
4
|
+
import { type RecordFieldsMap } from '../layouts/recordFieldsMap.js';
|
|
5
|
+
import { type LayoutBase } from '../layouts/layoutBase.js';
|
|
6
|
+
import { type ApiFieldData } from '../models/apiResults.js';
|
|
7
|
+
import { Field, type FieldValue } from './field.js';
|
|
8
8
|
export declare abstract class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
|
|
9
9
|
readonly layout: LayoutBase;
|
|
10
10
|
readonly type: RecordTypes;
|
|
11
11
|
recordId: number;
|
|
12
12
|
modId: number;
|
|
13
|
+
/**
|
|
14
|
+
* An object containing each field in this record.
|
|
15
|
+
*
|
|
16
|
+
* @template T - The type of the field.
|
|
17
|
+
*/
|
|
13
18
|
fields: T;
|
|
14
19
|
protected portalData: any[];
|
|
15
20
|
protected constructor(layout: LayoutBase, recordId: number, modId: number | undefined, fieldData: ApiFieldData);
|
|
16
21
|
get endpoint(): string;
|
|
22
|
+
/**
|
|
23
|
+
* A boolean indicating whether this record has been modified and should be committed
|
|
24
|
+
*
|
|
25
|
+
* @returns {boolean} A boolean value indicating whether any of the fields have been edited.
|
|
26
|
+
*/
|
|
17
27
|
get edited(): boolean;
|
|
18
|
-
get fieldsArray(): Field<FieldValue
|
|
28
|
+
get fieldsArray(): Array<Field<FieldValue>>;
|
|
19
29
|
protected processFieldData(fieldData: ApiFieldData): T;
|
|
20
30
|
_onSave(): void;
|
|
21
31
|
}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Copyright (c) 2023-2024. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
|
-
import { EventEmitter } from
|
|
5
|
-
import * as moment from
|
|
6
|
-
import { RecordTypes } from
|
|
7
|
-
import { Field } from
|
|
4
|
+
import { EventEmitter } from 'events';
|
|
5
|
+
import * as moment from 'moment';
|
|
6
|
+
import { RecordTypes } from '../types.js';
|
|
7
|
+
import { Field } from './field.js';
|
|
8
8
|
export class RecordBase extends EventEmitter {
|
|
9
9
|
layout;
|
|
10
10
|
type = RecordTypes.UNKNOWN;
|
|
11
11
|
recordId;
|
|
12
12
|
modId;
|
|
13
|
+
/**
|
|
14
|
+
* An object containing each field in this record.
|
|
15
|
+
*
|
|
16
|
+
* @template T - The type of the field.
|
|
17
|
+
*/
|
|
13
18
|
fields;
|
|
14
19
|
portalData = [];
|
|
15
20
|
constructor(layout, recordId, modId = recordId, fieldData) {
|
|
@@ -22,6 +27,11 @@ export class RecordBase extends EventEmitter {
|
|
|
22
27
|
get endpoint() {
|
|
23
28
|
return `${this.layout.endpoint}/records/${this.recordId}`;
|
|
24
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* A boolean indicating whether this record has been modified and should be committed
|
|
32
|
+
*
|
|
33
|
+
* @returns {boolean} A boolean value indicating whether any of the fields have been edited.
|
|
34
|
+
*/
|
|
25
35
|
get edited() {
|
|
26
36
|
return !!this.fieldsArray.find(i => i.edited);
|
|
27
37
|
}
|
|
@@ -29,12 +39,11 @@ export class RecordBase extends EventEmitter {
|
|
|
29
39
|
return Object.values(this.fields);
|
|
30
40
|
}
|
|
31
41
|
processFieldData(fieldData) {
|
|
32
|
-
|
|
33
|
-
for (
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
if (_field.metadata.result ===
|
|
37
|
-
// @ts-ignore
|
|
42
|
+
const fields = {};
|
|
43
|
+
for (const key of Object.keys(fieldData)) {
|
|
44
|
+
const _field = new Field(this, key, fieldData[key]);
|
|
45
|
+
if (fieldData[key]) {
|
|
46
|
+
if (_field.metadata.result === 'timeStamp') {
|
|
38
47
|
let date = moment.default(fieldData[key]);
|
|
39
48
|
date = date
|
|
40
49
|
.utcOffset(this.layout.database.host.timezoneOffsetFunc(date), true)
|
|
@@ -42,8 +51,7 @@ export class RecordBase extends EventEmitter {
|
|
|
42
51
|
_field.set(date);
|
|
43
52
|
_field.edited = false;
|
|
44
53
|
}
|
|
45
|
-
else if (_field.metadata.result ===
|
|
46
|
-
// @ts-ignore
|
|
54
|
+
else if (_field.metadata.result === 'time') {
|
|
47
55
|
let date = moment.default(fieldData[key]);
|
|
48
56
|
date = date
|
|
49
57
|
.utcOffset(this.layout.database.host.timezoneOffsetFunc(date), true)
|
|
@@ -51,8 +59,7 @@ export class RecordBase extends EventEmitter {
|
|
|
51
59
|
_field.set(date);
|
|
52
60
|
_field.edited = false;
|
|
53
61
|
}
|
|
54
|
-
else if (_field.metadata.result ===
|
|
55
|
-
// @ts-ignore
|
|
62
|
+
else if (_field.metadata.result === 'date') {
|
|
56
63
|
let date = moment.default(fieldData[key]);
|
|
57
64
|
date = date
|
|
58
65
|
.utcOffset(this.layout.database.host.timezoneOffsetFunc(date), true)
|
|
@@ -67,8 +74,8 @@ export class RecordBase extends EventEmitter {
|
|
|
67
74
|
return fields;
|
|
68
75
|
}
|
|
69
76
|
_onSave() {
|
|
70
|
-
this.emit(
|
|
71
|
-
for (
|
|
77
|
+
this.emit('saved');
|
|
78
|
+
for (const field of this.fieldsArray)
|
|
72
79
|
field.edited = false;
|
|
73
80
|
}
|
|
74
81
|
}
|
|
@@ -2,70 +2,74 @@
|
|
|
2
2
|
* Copyright (c) 2023-2024. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {EventEmitter} from
|
|
6
|
-
import * as moment from
|
|
7
|
-
import {Moment} from
|
|
8
|
-
import {RecordTypes} from
|
|
9
|
-
import {RecordFieldsMap} from
|
|
10
|
-
import {LayoutBase} from
|
|
11
|
-
import {ApiFieldData} from
|
|
12
|
-
import {Field, FieldValue} from
|
|
5
|
+
import {EventEmitter} from 'events'
|
|
6
|
+
import * as moment from 'moment'
|
|
7
|
+
import {type Moment} from 'moment'
|
|
8
|
+
import {RecordTypes} from '../types.js'
|
|
9
|
+
import {type RecordFieldsMap} from '../layouts/recordFieldsMap.js'
|
|
10
|
+
import {type LayoutBase} from '../layouts/layoutBase.js'
|
|
11
|
+
import {type ApiFieldData} from '../models/apiResults.js'
|
|
12
|
+
import {Field, type FieldValue} from './field.js'
|
|
13
13
|
|
|
14
14
|
export abstract class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
|
|
15
|
-
readonly layout: LayoutBase
|
|
16
|
-
readonly type: RecordTypes = RecordTypes.UNKNOWN
|
|
17
|
-
public recordId: number
|
|
18
|
-
modId: number
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
readonly layout: LayoutBase
|
|
16
|
+
readonly type: RecordTypes = RecordTypes.UNKNOWN
|
|
17
|
+
public recordId: number
|
|
18
|
+
modId: number
|
|
19
|
+
/**
|
|
20
|
+
* An object containing each field in this record.
|
|
21
|
+
*
|
|
22
|
+
* @template T - The type of the field.
|
|
23
|
+
*/
|
|
24
|
+
fields: T
|
|
25
|
+
protected portalData: any[] = []
|
|
21
26
|
|
|
22
|
-
protected constructor(layout: LayoutBase, recordId: number, modId = recordId, fieldData: ApiFieldData) {
|
|
23
|
-
super()
|
|
27
|
+
protected constructor (layout: LayoutBase, recordId: number, modId = recordId, fieldData: ApiFieldData) {
|
|
28
|
+
super()
|
|
24
29
|
this.layout = layout
|
|
25
30
|
this.recordId = recordId
|
|
26
31
|
this.modId = modId
|
|
27
32
|
this.fields = this.processFieldData(fieldData)
|
|
28
33
|
}
|
|
29
34
|
|
|
30
|
-
get endpoint(): string {
|
|
35
|
+
get endpoint (): string {
|
|
31
36
|
return `${this.layout.endpoint}/records/${this.recordId}`
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
/**
|
|
40
|
+
* A boolean indicating whether this record has been modified and should be committed
|
|
41
|
+
*
|
|
42
|
+
* @returns {boolean} A boolean value indicating whether any of the fields have been edited.
|
|
43
|
+
*/
|
|
44
|
+
get edited (): boolean {
|
|
35
45
|
return !!this.fieldsArray.find(i => i.edited)
|
|
36
46
|
}
|
|
37
47
|
|
|
38
|
-
get fieldsArray(): Field<FieldValue
|
|
48
|
+
get fieldsArray (): Array<Field<FieldValue>> {
|
|
39
49
|
return Object.values(this.fields)
|
|
40
50
|
}
|
|
41
51
|
|
|
42
|
-
protected processFieldData(fieldData: ApiFieldData) {
|
|
43
|
-
|
|
52
|
+
protected processFieldData (fieldData: ApiFieldData) {
|
|
53
|
+
const fields: RecordFieldsMap = {}
|
|
44
54
|
|
|
45
|
-
for (
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
if (_field.metadata.result ===
|
|
49
|
-
// @ts-ignore
|
|
55
|
+
for (const key of Object.keys(fieldData)) {
|
|
56
|
+
const _field = new Field<number | string | Moment>(this, key, fieldData[key])
|
|
57
|
+
if (fieldData[key]) {
|
|
58
|
+
if (_field.metadata.result === 'timeStamp') {
|
|
50
59
|
let date = moment.default(fieldData[key])
|
|
51
60
|
date = date
|
|
52
61
|
.utcOffset(this.layout.database.host.timezoneOffsetFunc(date), true)
|
|
53
62
|
.local()
|
|
54
63
|
_field.set(date)
|
|
55
64
|
_field.edited = false
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
else if (_field.metadata.result === "time") {
|
|
59
|
-
// @ts-ignore
|
|
65
|
+
} else if (_field.metadata.result === 'time') {
|
|
60
66
|
let date = moment.default(fieldData[key])
|
|
61
67
|
date = date
|
|
62
68
|
.utcOffset(this.layout.database.host.timezoneOffsetFunc(date), true)
|
|
63
69
|
.local()
|
|
64
70
|
_field.set(date)
|
|
65
71
|
_field.edited = false
|
|
66
|
-
}
|
|
67
|
-
else if (_field.metadata.result === "date") {
|
|
68
|
-
// @ts-ignore
|
|
72
|
+
} else if (_field.metadata.result === 'date') {
|
|
69
73
|
let date = moment.default(fieldData[key])
|
|
70
74
|
date = date
|
|
71
75
|
.utcOffset(this.layout.database.host.timezoneOffsetFunc(date), true)
|
|
@@ -80,8 +84,8 @@ export abstract class RecordBase<T extends RecordFieldsMap> extends EventEmitter
|
|
|
80
84
|
return fields as T
|
|
81
85
|
}
|
|
82
86
|
|
|
83
|
-
_onSave() {
|
|
84
|
-
this.emit(
|
|
85
|
-
for (
|
|
87
|
+
_onSave () {
|
|
88
|
+
this.emit('saved')
|
|
89
|
+
for (const field of this.fieldsArray) field.edited = false
|
|
86
90
|
}
|
|
87
|
-
}
|
|
91
|
+
}
|