@jd-data-limited/easy-fm 3.2.8 → 4.0.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/README.md +36 -24
- package/package.json +12 -9
- package/src/FMError.js +2 -2
- package/src/FMError.ts +2 -2
- package/src/connection/FMHost.d.ts +2 -1
- package/src/connection/FMHost.js +1 -2
- package/src/connection/FMHost.ts +4 -4
- package/src/connection/HostBase.d.ts +1 -1
- package/src/connection/HostBase.js +1 -1
- package/src/connection/HostBase.ts +2 -4
- package/src/connection/database.d.ts +10 -10
- package/src/connection/database.js +6 -17
- package/src/connection/database.ts +17 -27
- package/src/connection/databaseBase.d.ts +4 -4
- package/src/connection/databaseBase.js +1 -1
- package/src/connection/databaseBase.ts +4 -6
- package/src/databaseStructure.d.ts +6 -0
- package/src/databaseStructure.js +4 -0
- package/src/databaseStructure.ts +12 -0
- package/src/index.d.ts +3 -6
- package/src/index.js +3 -5
- package/src/index.ts +4 -9
- package/src/layouts/layout.d.ts +3 -17
- package/src/layouts/layout.js +2 -20
- package/src/layouts/layout.ts +5 -27
- package/src/layouts/layoutBase.d.ts +4 -4
- package/src/layouts/layoutBase.js +1 -1
- package/src/layouts/layoutBase.ts +5 -6
- package/src/layouts/layoutInterface.d.ts +1 -1
- package/src/layouts/layoutInterface.js +1 -1
- package/src/layouts/layoutInterface.ts +2 -2
- package/src/layouts/layoutRecordManager.d.ts +5 -6
- package/src/layouts/layoutRecordManager.js +5 -9
- package/src/layouts/layoutRecordManager.ts +12 -16
- package/src/layouts/recordFieldsMap.d.ts +2 -2
- package/src/layouts/recordFieldsMap.js +1 -1
- package/src/layouts/recordFieldsMap.ts +3 -3
- package/src/models/apiResults.d.ts +3 -3
- package/src/models/apiResults.js +1 -1
- package/src/models/apiResults.ts +2 -4
- package/src/records/field.d.ts +3 -23
- package/src/records/field.js +3 -152
- package/src/records/field.ts +4 -169
- package/src/records/fieldBase.d.ts +30 -0
- package/src/records/fieldBase.js +154 -0
- package/src/records/fieldBase.ts +174 -0
- package/src/records/getOperations/recordGetOperation.d.ts +47 -11
- package/src/records/getOperations/recordGetOperation.js +142 -31
- package/src/records/getOperations/recordGetOperation.ts +172 -30
- package/src/records/layoutRecord.d.ts +14 -11
- package/src/records/layoutRecord.js +7 -8
- package/src/records/layoutRecord.ts +32 -22
- package/src/records/portal.d.ts +6 -5
- package/src/records/portal.js +1 -1
- package/src/records/portal.ts +10 -8
- package/src/records/portalBase.d.ts +5 -4
- package/src/records/portalBase.js +1 -1
- package/src/records/portalBase.ts +6 -6
- package/src/records/portalRecord.d.ts +12 -8
- package/src/records/portalRecord.js +6 -8
- package/src/records/portalRecord.ts +17 -16
- package/src/records/recordBase.d.ts +11 -15
- package/src/records/recordBase.js +9 -13
- package/src/records/recordBase.ts +17 -25
- package/src/types.d.ts +18 -15
- package/src/types.js +7 -1
- package/src/types.ts +20 -16
- package/src/records/getOperations/find.d.ts +0 -15
- package/src/records/getOperations/find.js +0 -70
- package/src/records/getOperations/find.ts +0 -77
- package/src/records/getOperations/recordGetRange.d.ts +0 -13
- package/src/records/getOperations/recordGetRange.js +0 -77
- package/src/records/getOperations/recordGetRange.ts +0 -77
- package/src/records/portalRecordBase.d.ts +0 -4
- package/src/records/portalRecordBase.js +0 -6
package/src/layouts/layout.js
CHANGED
|
@@ -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
|
import { LayoutRecordManager } from "./layoutRecordManager.js";
|
|
5
5
|
import { FMError } from "../FMError.js";
|
|
6
6
|
export class Layout {
|
|
7
7
|
database;
|
|
8
|
-
records = new LayoutRecordManager(this);
|
|
9
8
|
name;
|
|
9
|
+
records = new LayoutRecordManager(this);
|
|
10
10
|
metadata;
|
|
11
11
|
constructor(database, name) {
|
|
12
12
|
this.database = database;
|
|
@@ -15,24 +15,6 @@ export class Layout {
|
|
|
15
15
|
get endpoint() {
|
|
16
16
|
return `${this.database.endpoint}/layouts/${this.name}`;
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated use layout.records.create() instead
|
|
20
|
-
*/
|
|
21
|
-
createRecord() {
|
|
22
|
-
return this.records.create();
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @deprecated use layout.records.get() instead
|
|
26
|
-
*/
|
|
27
|
-
getRecord(recordId) {
|
|
28
|
-
return this.records.get(recordId);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @deprecated use layout.records.find() instead
|
|
32
|
-
*/
|
|
33
|
-
newFind() {
|
|
34
|
-
return this.records.find();
|
|
35
|
-
}
|
|
36
18
|
async runScript(script) {
|
|
37
19
|
let url = `${this.endpoint}/script/${encodeURIComponent(script.name)}`;
|
|
38
20
|
if (script.parameter)
|
package/src/layouts/layout.ts
CHANGED
|
@@ -1,21 +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 {LayoutRecordManager} from "./layoutRecordManager.js";
|
|
6
|
-
import {LayoutRecord} from "../records/layoutRecord.js";
|
|
7
6
|
import {Script, ScriptResult} from "../types.js";
|
|
8
7
|
import {LayoutInterface} from "./layoutInterface.js";
|
|
9
|
-
import {Find} from "../records/getOperations/find.js";
|
|
10
8
|
import {FMError} from "../FMError.js";
|
|
11
9
|
import {LayoutBase} from "./layoutBase.js"
|
|
12
|
-
import {DatabaseBase} from "../connection/databaseBase";
|
|
13
|
-
import {ApiLayoutMetadata, ApiScriptResult} from "../models/apiResults";
|
|
10
|
+
import {DatabaseBase} from "../connection/databaseBase.js";
|
|
11
|
+
import {ApiLayoutMetadata, ApiScriptResult} from "../models/apiResults.js";
|
|
14
12
|
|
|
15
13
|
export class Layout<T extends LayoutInterface> implements LayoutBase {
|
|
16
14
|
readonly database: DatabaseBase;
|
|
17
|
-
readonly records = new LayoutRecordManager<T>(this)
|
|
18
15
|
readonly name: string;
|
|
16
|
+
readonly records = new LayoutRecordManager<T>(this)
|
|
19
17
|
metadata: ApiLayoutMetadata;
|
|
20
18
|
|
|
21
19
|
constructor(database: DatabaseBase, name: string) {
|
|
@@ -23,31 +21,11 @@ export class Layout<T extends LayoutInterface> implements LayoutBase {
|
|
|
23
21
|
this.name = name
|
|
24
22
|
}
|
|
25
23
|
|
|
24
|
+
|
|
26
25
|
get endpoint() {
|
|
27
26
|
return `${this.database.endpoint}/layouts/${this.name}`
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
/**
|
|
31
|
-
* @deprecated use layout.records.create() instead
|
|
32
|
-
*/
|
|
33
|
-
createRecord(): Promise<LayoutRecord<T["fields"], T["portals"]>> {
|
|
34
|
-
return this.records.create()
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @deprecated use layout.records.get() instead
|
|
39
|
-
*/
|
|
40
|
-
getRecord(recordId): Promise<LayoutRecord<T["fields"], T["portals"]>> {
|
|
41
|
-
return this.records.get(recordId)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @deprecated use layout.records.find() instead
|
|
46
|
-
*/
|
|
47
|
-
newFind(): Find<T> {
|
|
48
|
-
return this.records.find()
|
|
49
|
-
}
|
|
50
|
-
|
|
51
29
|
async runScript(script: Script): Promise<ScriptResult> {
|
|
52
30
|
let url = `${this.endpoint}/script/${encodeURIComponent(script.name)}`
|
|
53
31
|
if (script.parameter) url += "?script.param=" + encodeURIComponent(script.parameter)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Script, ScriptResult } from "../types";
|
|
2
|
-
import { DatabaseBase } from "../connection/databaseBase";
|
|
3
|
-
import { ApiLayoutMetadata } from "../models/apiResults";
|
|
1
|
+
import { Script, ScriptResult } from "../types.js";
|
|
2
|
+
import { DatabaseBase } from "../connection/databaseBase.js";
|
|
3
|
+
import { ApiLayoutMetadata } from "../models/apiResults.js";
|
|
4
4
|
export interface LayoutBase {
|
|
5
5
|
readonly name: string;
|
|
6
|
-
metadata:
|
|
6
|
+
metadata: ApiLayoutMetadata | null;
|
|
7
7
|
endpoint: string;
|
|
8
8
|
runScript(script: Script): Promise<ScriptResult>;
|
|
9
9
|
getLayoutMeta(): Promise<ApiLayoutMetadata>;
|
|
@@ -1,15 +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 {Script, ScriptResult} from "../types";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {ApiLayoutMetadata} from "../models/apiResults";
|
|
5
|
+
import {Script, ScriptResult} from "../types.js";
|
|
6
|
+
import {DatabaseBase} from "../connection/databaseBase.js";
|
|
7
|
+
import {ApiLayoutMetadata} from "../models/apiResults.js";
|
|
9
8
|
|
|
10
9
|
export interface LayoutBase {
|
|
11
10
|
readonly name: string
|
|
12
|
-
metadata:
|
|
11
|
+
metadata: ApiLayoutMetadata | null
|
|
13
12
|
endpoint: string
|
|
14
13
|
runScript(script: Script): Promise<ScriptResult>
|
|
15
14
|
getLayoutMeta(): Promise<ApiLayoutMetadata>
|
|
@@ -1,9 +1,9 @@
|
|
|
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 {Portal} from "../records/portal.js";
|
|
6
|
-
import {RecordFieldsMap} from "./recordFieldsMap";
|
|
6
|
+
import {RecordFieldsMap} from "./recordFieldsMap.js";
|
|
7
7
|
|
|
8
8
|
export interface LayoutInterface {
|
|
9
9
|
fields: RecordFieldsMap,
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { LayoutRecord } from "../records/layoutRecord.js";
|
|
2
2
|
import { LayoutInterface } from "./layoutInterface.js";
|
|
3
|
-
import { RecordGetRange } from "../records/getOperations/recordGetRange.js";
|
|
4
|
-
import { Find } from "../records/getOperations/find.js";
|
|
5
3
|
import { LayoutBase } from "./layoutBase.js";
|
|
4
|
+
import { GetOperationOptions, RecordGetOperation } from "../records/getOperations/recordGetOperation.js";
|
|
5
|
+
import { RecordFetchOptions } from "../types.js";
|
|
6
6
|
export declare class LayoutRecordManager<T extends LayoutInterface> {
|
|
7
7
|
readonly layout: LayoutBase;
|
|
8
8
|
constructor(layout: LayoutBase);
|
|
9
|
-
create(): Promise<LayoutRecord<T
|
|
10
|
-
get(recordId: number): Promise<LayoutRecord<T
|
|
11
|
-
|
|
12
|
-
find(start?: number, limit?: number): Find<T>;
|
|
9
|
+
create<OPTIONS extends RecordFetchOptions>(options: OPTIONS): Promise<LayoutRecord<T, OPTIONS["portals"][number]>>;
|
|
10
|
+
get(recordId: number): Promise<LayoutRecord<T>>;
|
|
11
|
+
list<OPTIONS extends GetOperationOptions<T>>(options: OPTIONS): RecordGetOperation<T, OPTIONS>;
|
|
13
12
|
}
|
|
@@ -1,15 +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
|
import { LayoutRecord } from "../records/layoutRecord.js";
|
|
5
|
-
import {
|
|
6
|
-
import { Find } from "../records/getOperations/find.js";
|
|
5
|
+
import { RecordGetOperation } from "../records/getOperations/recordGetOperation.js";
|
|
7
6
|
export class LayoutRecordManager {
|
|
8
7
|
layout;
|
|
9
8
|
constructor(layout) {
|
|
10
9
|
this.layout = layout;
|
|
11
10
|
}
|
|
12
|
-
async create() {
|
|
11
|
+
async create(options) {
|
|
13
12
|
await this.layout.getLayoutMeta();
|
|
14
13
|
let fields = {};
|
|
15
14
|
for (let _field of this.layout.metadata.fieldMetaData) {
|
|
@@ -26,10 +25,7 @@ export class LayoutRecordManager {
|
|
|
26
25
|
await record.get();
|
|
27
26
|
return record;
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
return new
|
|
31
|
-
}
|
|
32
|
-
find(start = 0, limit = 100) {
|
|
33
|
-
return new Find(this.layout, start, limit);
|
|
28
|
+
list(options) {
|
|
29
|
+
return new RecordGetOperation(this.layout, options);
|
|
34
30
|
}
|
|
35
31
|
}
|
|
@@ -1,43 +1,39 @@
|
|
|
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 {LayoutRecord} from "../records/layoutRecord.js";
|
|
6
6
|
import {LayoutInterface} from "./layoutInterface.js";
|
|
7
|
-
import {RecordGetRange} from "../records/getOperations/recordGetRange.js";
|
|
8
|
-
import {Find} from "../records/getOperations/find.js";
|
|
9
7
|
import {LayoutBase} from "./layoutBase.js"
|
|
8
|
+
import {GetOperationOptions, RecordGetOperation} from "../records/getOperations/recordGetOperation.js";
|
|
9
|
+
import {RecordFetchOptions} from "../types.js";
|
|
10
|
+
import {ApiFieldData} from "../models/apiResults.js";
|
|
10
11
|
|
|
11
12
|
export class LayoutRecordManager<T extends LayoutInterface> {
|
|
12
|
-
readonly layout: LayoutBase
|
|
13
|
-
|
|
13
|
+
readonly layout: LayoutBase;
|
|
14
14
|
constructor(layout: LayoutBase) {
|
|
15
15
|
this.layout = layout
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
async create(): Promise<LayoutRecord<T
|
|
18
|
+
async create<OPTIONS extends RecordFetchOptions>(options: OPTIONS): Promise<LayoutRecord<T, OPTIONS["portals"][number]>> {
|
|
19
19
|
await this.layout.getLayoutMeta()
|
|
20
|
-
let fields = {}
|
|
20
|
+
let fields: ApiFieldData = {}
|
|
21
21
|
for (let _field of this.layout.metadata.fieldMetaData) {
|
|
22
22
|
fields[_field.name] = ""
|
|
23
23
|
}
|
|
24
|
-
let portals = {}
|
|
24
|
+
let portals: {[key: string]: []} = {}
|
|
25
25
|
for (let _portal of Object.keys(this.layout.metadata.portalMetaData)) portals[_portal] = []
|
|
26
26
|
return new LayoutRecord(this.layout, -1, 0, fields, portals)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
async get(recordId: number): Promise<LayoutRecord<T
|
|
29
|
+
async get(recordId: number): Promise<LayoutRecord<T>> {
|
|
30
30
|
await this.layout.getLayoutMeta()
|
|
31
|
-
let record = new LayoutRecord(this.layout, recordId)
|
|
31
|
+
let record = new LayoutRecord<T>(this.layout, recordId)
|
|
32
32
|
await record.get()
|
|
33
33
|
return record
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
return new
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
find(start = 0, limit = 100): Find<T> {
|
|
41
|
-
return new Find<T>(this.layout, start, limit)
|
|
36
|
+
list<OPTIONS extends GetOperationOptions<T>>(options: OPTIONS) {
|
|
37
|
+
return new RecordGetOperation<T, OPTIONS>(this.layout, options)
|
|
42
38
|
}
|
|
43
39
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
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 {
|
|
5
|
+
import {FieldBase, FieldValue} from "../records/fieldBase.js";
|
|
6
6
|
|
|
7
7
|
export interface RecordFieldsMap {
|
|
8
|
-
[fieldName: string]:
|
|
8
|
+
[fieldName: string]: FieldBase<FieldValue>
|
|
9
9
|
}
|
|
@@ -75,9 +75,9 @@ export interface ApiRecordResponseObj {
|
|
|
75
75
|
data: ApiRowDataDef[];
|
|
76
76
|
dataInfo: ApiResultSetObj;
|
|
77
77
|
}
|
|
78
|
-
export
|
|
79
|
-
[key: string]: string;
|
|
80
|
-
}
|
|
78
|
+
export type ApiFieldData = {
|
|
79
|
+
[key: string]: string | number;
|
|
80
|
+
};
|
|
81
81
|
export interface ApiPortalData {
|
|
82
82
|
[key: string]: ApiFieldData[];
|
|
83
83
|
}
|
package/src/models/apiResults.js
CHANGED
package/src/models/apiResults.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
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 * as stream from "stream";
|
|
6
|
-
|
|
7
5
|
export enum ApiFieldTypes {
|
|
8
6
|
NORMAL = "normal",
|
|
9
7
|
CALCULATION = "calculation",
|
|
@@ -85,7 +83,7 @@ export interface ApiRecordResponseObj {
|
|
|
85
83
|
dataInfo: ApiResultSetObj
|
|
86
84
|
}
|
|
87
85
|
|
|
88
|
-
export
|
|
86
|
+
export type ApiFieldData = {[key: string]: string | number}
|
|
89
87
|
|
|
90
88
|
export interface ApiPortalData {[key: string]: ApiFieldData[]}
|
|
91
89
|
|
package/src/records/field.d.ts
CHANGED
|
@@ -1,25 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import * as http from "http";
|
|
5
|
-
import { ContainerBufferResult, DOWNLOAD_MODES } from "../types.js";
|
|
6
|
-
import { ApiFieldMetadata } from "../models/apiResults.js";
|
|
7
|
-
export type FieldValue = string | number | Date | Container;
|
|
8
|
-
export type Container = null;
|
|
9
|
-
export declare class Field<T extends FieldValue> {
|
|
1
|
+
import { RecordBase } from "./recordBase";
|
|
2
|
+
import { FieldBase, FieldValue } from "./fieldBase";
|
|
3
|
+
export declare class Field<T extends FieldValue> extends FieldBase<T> {
|
|
10
4
|
record: RecordBase<any>;
|
|
11
|
-
id: string;
|
|
12
|
-
protected _value: T;
|
|
13
|
-
edited: boolean;
|
|
14
|
-
constructor(record: any, id: any, contents: any);
|
|
15
|
-
set(content: string | number | Date | undefined | null): void;
|
|
16
|
-
get metadata(): ApiFieldMetadata;
|
|
17
|
-
get value(): T;
|
|
18
|
-
set value(value: T);
|
|
19
|
-
get string(): string;
|
|
20
|
-
get date(): Date;
|
|
21
|
-
get number(): number;
|
|
22
|
-
upload(buffer: Buffer, filename: string, mime: string): Promise<void>;
|
|
23
|
-
download(mode: DOWNLOAD_MODES.Stream): Promise<http.IncomingMessage>;
|
|
24
|
-
download(mode: DOWNLOAD_MODES.Buffer): Promise<ContainerBufferResult>;
|
|
25
5
|
}
|
package/src/records/field.js
CHANGED
|
@@ -1,156 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) 2024. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { DOWNLOAD_MODES } from "../types.js";
|
|
7
|
-
import { ApiFieldDisplayTypes, ApiFieldResultTypes, ApiFieldTypes } from "../models/apiResults.js";
|
|
8
|
-
export class Field {
|
|
4
|
+
import { FieldBase } from "./fieldBase";
|
|
5
|
+
export class Field extends FieldBase {
|
|
9
6
|
record;
|
|
10
|
-
id;
|
|
11
|
-
_value;
|
|
12
|
-
edited;
|
|
13
|
-
constructor(record, id, contents) {
|
|
14
|
-
this.record = record;
|
|
15
|
-
this.id = id;
|
|
16
|
-
this._value = contents;
|
|
17
|
-
this.edited = false;
|
|
18
|
-
}
|
|
19
|
-
set(content) {
|
|
20
|
-
if (this.metadata.result === "container")
|
|
21
|
-
throw "Cannot set container value using set(). Use upload() instead.";
|
|
22
|
-
if ((this.metadata.result === "timeStamp" ||
|
|
23
|
-
this.metadata.result === "date" ||
|
|
24
|
-
this.metadata.result === "time")
|
|
25
|
-
&& !(content instanceof Date) && !!content) {
|
|
26
|
-
throw "Value was not an instance of Date: " + content;
|
|
27
|
-
}
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
if (!content)
|
|
30
|
-
this._value = "";
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
else
|
|
33
|
-
this._value = content;
|
|
34
|
-
this.edited = true;
|
|
35
|
-
}
|
|
36
|
-
get metadata() {
|
|
37
|
-
if (!this.record.layout.metadata) {
|
|
38
|
-
// Default to a regular text field
|
|
39
|
-
return {
|
|
40
|
-
name: this.id.toString(),
|
|
41
|
-
type: ApiFieldTypes.NORMAL,
|
|
42
|
-
displayType: ApiFieldDisplayTypes.EDIT_TEXT,
|
|
43
|
-
result: ApiFieldResultTypes.TEXT,
|
|
44
|
-
global: false,
|
|
45
|
-
autoEnter: true,
|
|
46
|
-
fourDigitYear: false,
|
|
47
|
-
maxRepeat: 1,
|
|
48
|
-
maxCharacters: 0,
|
|
49
|
-
notEmpty: false,
|
|
50
|
-
numeric: false,
|
|
51
|
-
timeOfDay: false,
|
|
52
|
-
repetitions: 1,
|
|
53
|
-
valueList: ""
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
if (this.record.type === RecordTypes.PORTAL) {
|
|
57
|
-
// @ts-ignore
|
|
58
|
-
return this.record.layout.metadata.portalMetaData[this.record.portal.name || "portal not attached"].find(i => i.name === this.id) || {
|
|
59
|
-
name: this.id.toString(),
|
|
60
|
-
type: 'normal',
|
|
61
|
-
displayType: 'editText',
|
|
62
|
-
result: 'text',
|
|
63
|
-
global: false,
|
|
64
|
-
autoEnter: true,
|
|
65
|
-
fourDigitYear: false,
|
|
66
|
-
maxRepeat: 1,
|
|
67
|
-
maxCharacters: 0,
|
|
68
|
-
notEmpty: false,
|
|
69
|
-
numeric: false,
|
|
70
|
-
timeOfDay: false,
|
|
71
|
-
repetitionStart: 1,
|
|
72
|
-
repetitionEnd: 1
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
return this.record.layout.metadata.fieldMetaData.find(i => i.name === this.id) || {
|
|
77
|
-
name: this.id.toString(),
|
|
78
|
-
type: ApiFieldTypes.NORMAL,
|
|
79
|
-
displayType: ApiFieldDisplayTypes.EDIT_TEXT,
|
|
80
|
-
result: ApiFieldResultTypes.TEXT,
|
|
81
|
-
global: false,
|
|
82
|
-
autoEnter: true,
|
|
83
|
-
fourDigitYear: false,
|
|
84
|
-
maxRepeat: 1,
|
|
85
|
-
maxCharacters: 0,
|
|
86
|
-
notEmpty: false,
|
|
87
|
-
numeric: false,
|
|
88
|
-
timeOfDay: false,
|
|
89
|
-
repetitions: 1,
|
|
90
|
-
valueList: ""
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
get value() {
|
|
95
|
-
// if (this.metadata.result === "container") throw "Use await field.stream() to get the contents of a container field, instead of field.value"
|
|
96
|
-
return this._value;
|
|
97
|
-
}
|
|
98
|
-
set value(value) {
|
|
99
|
-
this._value = value;
|
|
100
|
-
}
|
|
101
|
-
get string() {
|
|
102
|
-
if (typeof this._value === "string") {
|
|
103
|
-
return this._value;
|
|
104
|
-
}
|
|
105
|
-
throw "Field value is not a string";
|
|
106
|
-
}
|
|
107
|
-
get date() {
|
|
108
|
-
if (this._value instanceof Date) {
|
|
109
|
-
return this._value;
|
|
110
|
-
}
|
|
111
|
-
throw "Field value is not a date";
|
|
112
|
-
}
|
|
113
|
-
get number() {
|
|
114
|
-
if (typeof this._value === "number") {
|
|
115
|
-
return this._value;
|
|
116
|
-
}
|
|
117
|
-
throw "Field value is not a number";
|
|
118
|
-
}
|
|
119
|
-
async upload(buffer, filename, mime) {
|
|
120
|
-
let trace = new Error();
|
|
121
|
-
if (this.metadata.result !== "container")
|
|
122
|
-
throw "Cannot upload a file to the field; " + this.id + " (not a container field)";
|
|
123
|
-
let form = new FormData();
|
|
124
|
-
form.append("upload", new File([buffer], filename, { type: mime }));
|
|
125
|
-
await this.record.layout.database.apiRequest(`${this.record.endpoint}/containers/${this.id}/1`, {
|
|
126
|
-
method: "POST",
|
|
127
|
-
// @ts-ignore
|
|
128
|
-
headers: { "Authorization": "Bearer " + this.record.layout.database.token },
|
|
129
|
-
body: form
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
async download(mode = DOWNLOAD_MODES.Stream) {
|
|
133
|
-
if (this.metadata.result !== ApiFieldResultTypes.CONTAINER)
|
|
134
|
-
throw new Error("Cannot perform download() on a non-container field");
|
|
135
|
-
let stream = await this.record.layout.database.streamURL(this.string);
|
|
136
|
-
if (mode === DOWNLOAD_MODES.Stream) {
|
|
137
|
-
return stream;
|
|
138
|
-
}
|
|
139
|
-
let body = [];
|
|
140
|
-
return new Promise((resolve, reject) => {
|
|
141
|
-
stream.on("data", chunk => {
|
|
142
|
-
body.push(chunk);
|
|
143
|
-
});
|
|
144
|
-
stream.on("error", (e) => {
|
|
145
|
-
reject(e);
|
|
146
|
-
});
|
|
147
|
-
stream.on("end", () => {
|
|
148
|
-
resolve({
|
|
149
|
-
buffer: Buffer.concat(body),
|
|
150
|
-
mime: stream.headers["content-type"],
|
|
151
|
-
request: stream
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
7
|
}
|