@jd-data-limited/easy-fm 3.1.5 → 3.1.7
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 +85 -18
- package/package.json +1 -1
- package/src/connection/FMHost.d.ts +4 -3
- package/src/connection/FMHost.ts +5 -4
- package/src/connection/HostBase.d.ts +8 -0
- package/src/connection/HostBase.js +4 -0
- package/src/connection/HostBase.ts +15 -0
- package/src/connection/database.d.ts +9 -7
- package/src/connection/database.ts +13 -8
- package/src/connection/databaseBase.d.ts +8 -0
- package/src/connection/databaseBase.js +4 -0
- package/src/connection/databaseBase.ts +17 -0
- package/src/index.d.ts +3 -1
- package/src/index.ts +3 -1
- package/src/layouts/layout.d.ts +8 -7
- package/src/layouts/layout.ts +8 -7
- package/src/layouts/layoutBase.d.ts +11 -0
- package/src/layouts/layoutBase.js +4 -0
- package/src/layouts/layoutBase.ts +16 -0
- package/src/layouts/layoutInterface.d.ts +1 -6
- package/src/layouts/layoutInterface.ts +1 -7
- package/src/layouts/layoutRecordManager.d.ts +3 -3
- package/src/layouts/layoutRecordManager.ts +3 -3
- package/src/layouts/recordFieldsMap.d.ts +4 -0
- package/src/layouts/recordFieldsMap.js +4 -0
- package/src/layouts/recordFieldsMap.ts +9 -0
- package/src/records/field.d.ts +2 -1
- package/src/records/field.js +5 -2
- package/src/records/field.ts +8 -4
- package/src/records/getOperations/find.d.ts +2 -2
- package/src/records/getOperations/find.js +3 -3
- package/src/records/getOperations/find.ts +5 -5
- package/src/records/getOperations/recordGetOperation.d.ts +3 -3
- package/src/records/getOperations/recordGetOperation.js +1 -1
- package/src/records/getOperations/recordGetOperation.ts +4 -4
- package/src/records/getOperations/recordGetRange.js +3 -3
- package/src/records/getOperations/recordGetRange.ts +3 -3
- package/src/records/layoutRecord.d.ts +4 -2
- package/src/records/layoutRecord.js +2 -0
- package/src/records/layoutRecord.ts +6 -3
- package/src/records/layoutRecordBase.d.ts +5 -0
- package/src/records/layoutRecordBase.js +4 -0
- package/src/records/layoutRecordBase.ts +10 -0
- package/src/records/portal.d.ts +4 -3
- package/src/records/portal.ts +5 -3
- package/src/records/portalBase.d.ts +8 -0
- package/src/records/portalBase.js +4 -0
- package/src/records/portalBase.ts +14 -0
- package/src/records/portalRecord.d.ts +6 -5
- package/src/records/portalRecord.js +2 -1
- package/src/records/portalRecord.ts +6 -4
- package/src/records/portalRecordBase.d.ts +4 -0
- package/src/records/portalRecordBase.js +6 -0
- package/src/records/recordBase.d.ts +9 -3
- package/src/records/recordBase.js +8 -4
- package/src/records/recordBase.ts +10 -7
- package/src/types.d.ts +7 -2
- package/src/types.ts +8 -3
- package/test.d.ts +2 -1
- package/test.js +27 -1
- package/test.ts +33 -0
- package/test2.d.ts +1 -0
- package/test2.js +15 -0
- package/tsconfig.json +2 -1
package/src/records/field.ts
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {RecordBase} from "./recordBase.js";
|
|
5
|
+
import {RecordBase, RecordTypes} from "./recordBase.js";
|
|
6
6
|
import fetch, {File, FormData} from "node-fetch";
|
|
7
7
|
import * as http from "http";
|
|
8
8
|
import {ContainerBufferResult, DOWNLOAD_MODES, FieldMetaData} from "../types.js";
|
|
9
|
-
import {PortalRecord} from "./portalRecord.js";
|
|
10
|
-
import {FieldValue} from "../layouts/layoutInterface.js";
|
|
11
9
|
import {FMError} from "../FMError.js";
|
|
12
10
|
|
|
11
|
+
export type FieldValue = string | number | Date | Container
|
|
12
|
+
export type Container = null
|
|
13
|
+
|
|
13
14
|
export class Field<T extends FieldValue> {
|
|
14
15
|
record: RecordBase<any>;
|
|
15
16
|
id: string;
|
|
@@ -60,7 +61,8 @@ export class Field<T extends FieldValue> {
|
|
|
60
61
|
repetitionEnd: 1
|
|
61
62
|
} as FieldMetaData
|
|
62
63
|
}
|
|
63
|
-
if (this.record
|
|
64
|
+
if (this.record.type === RecordTypes.PORTAL) {
|
|
65
|
+
// @ts-ignore
|
|
64
66
|
return this.record.layout.metadata.portalMetaData[this.record.portal.name || "portal not attached"].find(i => i.name === this.id) as FieldMetaData || {
|
|
65
67
|
name: this.id.toString(),
|
|
66
68
|
type: 'normal',
|
|
@@ -137,6 +139,7 @@ export class Field<T extends FieldValue> {
|
|
|
137
139
|
|
|
138
140
|
let _fetch = await fetch(`${this.record.endpoint}/containers/${this.id}/1`, {
|
|
139
141
|
method: "POST",
|
|
142
|
+
// @ts-ignore
|
|
140
143
|
headers: {"Authorization": "Bearer " + this.record.layout.database.token},
|
|
141
144
|
body: form
|
|
142
145
|
}).then(res => res.json())
|
|
@@ -159,6 +162,7 @@ export class Field<T extends FieldValue> {
|
|
|
159
162
|
download(mode: DOWNLOAD_MODES.Buffer): Promise<ContainerBufferResult>
|
|
160
163
|
download(mode: DOWNLOAD_MODES = DOWNLOAD_MODES.Stream): Promise<http.IncomingMessage | ContainerBufferResult> {
|
|
161
164
|
return new Promise((resolve, reject) => {
|
|
165
|
+
// @ts-ignore
|
|
162
166
|
this.record.layout.database.streamContainer(this, this._value)
|
|
163
167
|
.then(stream => {
|
|
164
168
|
if (mode === DOWNLOAD_MODES.Stream) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { RecordGetOperation } from "./recordGetOperation.js";
|
|
2
2
|
import { LayoutRecord } from "../layoutRecord.js";
|
|
3
3
|
import { LayoutInterface } from "../../layouts/layoutInterface";
|
|
4
|
-
import {
|
|
4
|
+
import { LayoutBase } from "../../layouts/layoutBase.js";
|
|
5
5
|
export declare class Find<T extends LayoutInterface> extends RecordGetOperation<T> {
|
|
6
6
|
protected queries: object[];
|
|
7
|
-
constructor(layout:
|
|
7
|
+
constructor(layout: LayoutBase, start?: number, limit?: number);
|
|
8
8
|
private toObject;
|
|
9
9
|
addRequests(...requests: any[]): this;
|
|
10
10
|
/**
|
|
@@ -36,10 +36,10 @@ export class Find extends RecordGetOperation {
|
|
|
36
36
|
if (this.offset !== 0)
|
|
37
37
|
out["offset"] = this.offset;
|
|
38
38
|
if (this.limitPortals.length > 0) {
|
|
39
|
-
out["portal"] = this.limitPortals.map(p => p.
|
|
39
|
+
out["portal"] = this.limitPortals.map(p => p.portalName);
|
|
40
40
|
for (let item of this.limitPortals) {
|
|
41
|
-
out["offset." + item.
|
|
42
|
-
out["limit." + item.
|
|
41
|
+
out["offset." + item.portalName.replace(/[^0-9A-z]/g, "")] = item.offset;
|
|
42
|
+
out["limit." + item.portalName.replace(/[^0-9A-z]/g, "")] = item.limit;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
return out;
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
import {RecordGetOperation} from "./recordGetOperation.js";
|
|
6
6
|
import {LayoutRecord} from "../layoutRecord.js";
|
|
7
7
|
import {LayoutInterface} from "../../layouts/layoutInterface";
|
|
8
|
-
import {
|
|
8
|
+
import {LayoutBase} from "../../layouts/layoutBase.js";
|
|
9
9
|
import {FMError} from "../../FMError.js";
|
|
10
10
|
|
|
11
11
|
export class Find<T extends LayoutInterface> extends RecordGetOperation<T> {
|
|
12
12
|
protected queries: object[]
|
|
13
13
|
|
|
14
|
-
constructor(layout:
|
|
14
|
+
constructor(layout: LayoutBase, start = 0, limit = 100) {
|
|
15
15
|
super(layout)
|
|
16
16
|
this.setOffset(start)
|
|
17
17
|
this.setLimit(limit)
|
|
@@ -32,10 +32,10 @@ export class Find<T extends LayoutInterface> extends RecordGetOperation<T> {
|
|
|
32
32
|
if (this.limit !== 100) out["limit"] = this.limit
|
|
33
33
|
if (this.offset !== 0) out["offset"] = this.offset
|
|
34
34
|
if (this.limitPortals.length > 0) {
|
|
35
|
-
out["portal"] = this.limitPortals.map(p => p.
|
|
35
|
+
out["portal"] = this.limitPortals.map(p => p.portalName)
|
|
36
36
|
for (let item of this.limitPortals) {
|
|
37
|
-
out["offset." + item.
|
|
38
|
-
out["limit." + item.
|
|
37
|
+
out["offset." + item.portalName.replace(/[^0-9A-z]/g, "")] = item.offset
|
|
38
|
+
out["limit." + item.portalName.replace(/[^0-9A-z]/g, "")] = item.limit
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { LayoutInterface } from "../../layouts/layoutInterface.js";
|
|
2
|
-
import { Layout } from "../../layouts/layout.js";
|
|
3
2
|
import { Portal } from "../portal.js";
|
|
4
3
|
import { limitPortalsInterface } from "../../types.js";
|
|
4
|
+
import { LayoutBase } from "../../layouts/layoutBase.js";
|
|
5
5
|
export declare class RecordGetOperation<T extends LayoutInterface> {
|
|
6
|
-
protected layout:
|
|
6
|
+
protected layout: LayoutBase;
|
|
7
7
|
protected limit: number;
|
|
8
8
|
protected scripts: object;
|
|
9
9
|
protected sort: object[];
|
|
10
10
|
protected limitPortals: limitPortalsInterface[];
|
|
11
11
|
protected offset: number;
|
|
12
|
-
constructor(layout:
|
|
12
|
+
constructor(layout: LayoutBase);
|
|
13
13
|
addToPortalLimit(portal: Portal<any>, offset?: number, limit?: number): this;
|
|
14
14
|
setLimit(limit: number): this;
|
|
15
15
|
addSort(fieldName: any, sortOrder: any): this;
|
|
@@ -21,7 +21,7 @@ export class RecordGetOperation {
|
|
|
21
21
|
addToPortalLimit(portal, offset = 0, limit = 100) {
|
|
22
22
|
if (offset < 0)
|
|
23
23
|
throw "Portal offset cannot be less than 0";
|
|
24
|
-
this.limitPortals.push({ portal, offset, limit });
|
|
24
|
+
this.limitPortals.push({ portalName: portal.name, offset, limit });
|
|
25
25
|
return this;
|
|
26
26
|
}
|
|
27
27
|
setLimit(limit) {
|
|
@@ -3,19 +3,19 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import {LayoutInterface} from "../../layouts/layoutInterface.js";
|
|
6
|
-
import {Layout} from "../../layouts/layout.js";
|
|
7
6
|
import {Portal} from "../portal.js";
|
|
8
7
|
import {limitPortalsInterface} from "../../types.js";
|
|
8
|
+
import {LayoutBase} from "../../layouts/layoutBase.js"
|
|
9
9
|
|
|
10
10
|
export class RecordGetOperation<T extends LayoutInterface> {
|
|
11
|
-
protected layout:
|
|
11
|
+
protected layout: LayoutBase
|
|
12
12
|
protected limit: number = 100
|
|
13
13
|
protected scripts: object
|
|
14
14
|
protected sort: object[]
|
|
15
15
|
protected limitPortals: limitPortalsInterface[] = []
|
|
16
16
|
protected offset: number = 0
|
|
17
17
|
|
|
18
|
-
constructor(layout:
|
|
18
|
+
constructor(layout: LayoutBase) {
|
|
19
19
|
this.layout = layout
|
|
20
20
|
this.scripts = {
|
|
21
21
|
"script": null, // Runs after everything
|
|
@@ -31,7 +31,7 @@ export class RecordGetOperation<T extends LayoutInterface> {
|
|
|
31
31
|
*/
|
|
32
32
|
addToPortalLimit(portal: Portal<any>, offset = 0, limit = 100) {
|
|
33
33
|
if (offset < 0) throw "Portal offset cannot be less than 0"
|
|
34
|
-
this.limitPortals.push({portal, offset, limit})
|
|
34
|
+
this.limitPortals.push({portalName: portal.name, offset, limit})
|
|
35
35
|
return this
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -28,12 +28,12 @@ export class RecordGetRange extends RecordGetOperation {
|
|
|
28
28
|
if (this.sort.length > 0)
|
|
29
29
|
params.push("_sort=" + encodeURI(JSON.stringify(this.sort)));
|
|
30
30
|
if (this.limitPortals.length > 0) {
|
|
31
|
-
params.push("portal=" + encodeURI(JSON.stringify(this.limitPortals.map(p => p.
|
|
31
|
+
params.push("portal=" + encodeURI(JSON.stringify(this.limitPortals.map(p => p.portalName))));
|
|
32
32
|
for (let item of this.limitPortals) {
|
|
33
33
|
if (item.offset !== 0)
|
|
34
|
-
params.push("_offset." + item.
|
|
34
|
+
params.push("_offset." + item.portalName.replace(/[^0-9A-z]/g, "") + "=" + item.offset);
|
|
35
35
|
if (item.limit !== 100)
|
|
36
|
-
params.push("_limit." + item.
|
|
36
|
+
params.push("_limit." + item.portalName.replace(/[^0-9A-z]/g, "") + "=" + item.limit);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
if (extraBody.scripts) {
|
|
@@ -21,10 +21,10 @@ export class RecordGetRange<T extends LayoutInterface> extends RecordGetOperatio
|
|
|
21
21
|
if (this.offset !== 0) params.push("_offset=" + this.offset)
|
|
22
22
|
if (this.sort.length > 0) params.push("_sort=" + encodeURI(JSON.stringify(this.sort)))
|
|
23
23
|
if (this.limitPortals.length > 0) {
|
|
24
|
-
params.push("portal=" + encodeURI(JSON.stringify(this.limitPortals.map(p => p.
|
|
24
|
+
params.push("portal=" + encodeURI(JSON.stringify(this.limitPortals.map(p => p.portalName))))
|
|
25
25
|
for (let item of this.limitPortals) {
|
|
26
|
-
if (item.offset !== 0) params.push("_offset." + item.
|
|
27
|
-
if (item.limit !== 100) params.push("_limit." + item.
|
|
26
|
+
if (item.offset !== 0) params.push("_offset." + item.portalName.replace(/[^0-9A-z]/g, "") + "=" + item.offset)
|
|
27
|
+
if (item.limit !== 100) params.push("_limit." + item.portalName.replace(/[^0-9A-z]/g, "") + "=" + item.limit)
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
if (extraBody.scripts) {
|
|
@@ -1,8 +1,10 @@
|
|
|
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
|
|
5
|
-
|
|
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 {
|
|
6
8
|
portals: P;
|
|
7
9
|
constructor(layout: any, recordId: any, modId?: any, fieldData?: {}, portalData?: any);
|
|
8
10
|
get portalsArray(): Portal<any>[];
|
|
@@ -17,6 +17,8 @@ import { FMError } from "../FMError.js";
|
|
|
17
17
|
export class LayoutRecord extends RecordBase {
|
|
18
18
|
constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null) {
|
|
19
19
|
super(layout, recordId, modId);
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
this.portals = {};
|
|
20
22
|
this.processFieldData(fieldData);
|
|
21
23
|
if (portalData) {
|
|
22
24
|
this.processPortalData(portalData);
|
|
@@ -6,11 +6,14 @@ 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
|
|
9
|
+
import {PortalInterface} from "../layouts/layoutInterface.js";
|
|
10
10
|
import {FMError} from "../FMError.js";
|
|
11
|
+
import {RecordFieldsMap} from "../layouts/recordFieldsMap";
|
|
12
|
+
import {LayoutRecordBase} from "./layoutRecordBase";
|
|
11
13
|
|
|
12
|
-
export class LayoutRecord<T extends RecordFieldsMap, P extends PortalInterface> extends RecordBase<T> {
|
|
13
|
-
|
|
14
|
+
export class LayoutRecord<T extends RecordFieldsMap, P extends PortalInterface> extends RecordBase<T> implements LayoutRecordBase {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
portals: P = {}
|
|
14
17
|
|
|
15
18
|
constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null) {
|
|
16
19
|
super(layout, recordId, modId);
|
package/src/records/portal.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { LayoutRecord } from "./layoutRecord.js";
|
|
2
1
|
import { PortalRecord } from "./portalRecord.js";
|
|
3
|
-
import { RecordFieldsMap } from "../layouts/
|
|
4
|
-
|
|
2
|
+
import { RecordFieldsMap } from "../layouts/recordFieldsMap";
|
|
3
|
+
import { PortalBase } from "./portalBase";
|
|
4
|
+
import { LayoutRecord } from "./layoutRecord";
|
|
5
|
+
export declare class Portal<T extends RecordFieldsMap> implements PortalBase<T> {
|
|
5
6
|
readonly record: LayoutRecord<any, any>;
|
|
6
7
|
readonly name: string;
|
|
7
8
|
records: PortalRecord<T>[];
|
package/src/records/portal.ts
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {LayoutRecord} from "./layoutRecord.js";
|
|
6
5
|
import {PortalRecord} from "./portalRecord.js";
|
|
7
|
-
import {
|
|
6
|
+
import {RecordFieldsMap} from "../layouts/recordFieldsMap";
|
|
7
|
+
import {PortalBase} from "./portalBase";
|
|
8
|
+
import {LayoutRecordBase} from "./layoutRecordBase";
|
|
9
|
+
import {LayoutRecord} from "./layoutRecord";
|
|
8
10
|
|
|
9
|
-
export class Portal<T extends RecordFieldsMap> {
|
|
11
|
+
export class Portal<T extends RecordFieldsMap> implements PortalBase<T> {
|
|
10
12
|
readonly record: LayoutRecord<any, any>;
|
|
11
13
|
readonly name: string;
|
|
12
14
|
public records: PortalRecord<T>[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RecordFieldsMap } from "../layouts/recordFieldsMap";
|
|
2
|
+
import { RecordBase } from "./recordBase";
|
|
3
|
+
import { LayoutRecord } from "./layoutRecord";
|
|
4
|
+
export interface PortalBase<T extends RecordFieldsMap> {
|
|
5
|
+
readonly record: LayoutRecord<any, any>;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
records: RecordBase<T>[];
|
|
8
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {RecordFieldsMap} from "../layouts/recordFieldsMap";
|
|
6
|
+
import {LayoutRecordBase} from "./layoutRecordBase";
|
|
7
|
+
import {RecordBase} from "./recordBase";
|
|
8
|
+
import {LayoutRecord} from "./layoutRecord";
|
|
9
|
+
|
|
10
|
+
export interface PortalBase<T extends RecordFieldsMap> {
|
|
11
|
+
readonly record: LayoutRecord<any, any>
|
|
12
|
+
readonly name: string
|
|
13
|
+
records: RecordBase<T>[]
|
|
14
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { RecordBase } from "./recordBase.js";
|
|
1
|
+
import { RecordBase, RecordTypes } from "./recordBase.js";
|
|
2
2
|
import { extraBodyOptions } from "../types.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { RecordFieldsMap } from "../layouts/recordFieldsMap";
|
|
4
|
+
import { PortalBase } from "./portalBase";
|
|
5
5
|
export declare class PortalRecord<T extends RecordFieldsMap> extends RecordBase<T> {
|
|
6
|
-
readonly portal:
|
|
6
|
+
readonly portal: PortalBase<T>;
|
|
7
|
+
readonly type = RecordTypes.PORTAL;
|
|
7
8
|
constructor(record: any, portal: any, recordId: any, modId?: any, fieldData?: {});
|
|
8
9
|
_onSave(): void;
|
|
9
10
|
commit(extraBody?: extraBodyOptions): Promise<import("./layoutRecord.js").LayoutRecord<any, any>>;
|
|
10
11
|
toObject(fieldFilter: any): any;
|
|
11
|
-
getField(field: any): import("./field.js").Field<import("
|
|
12
|
+
getField(field: any): import("./field.js").Field<import("./field.js").FieldValue>;
|
|
12
13
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
|
-
import { RecordBase } from "./recordBase.js";
|
|
4
|
+
import { RecordBase, RecordTypes } from "./recordBase.js";
|
|
5
5
|
export class PortalRecord extends RecordBase {
|
|
6
6
|
constructor(record, portal, recordId, modId = recordId, fieldData = {}) {
|
|
7
7
|
super(record.layout, recordId, modId);
|
|
8
|
+
this.type = RecordTypes.PORTAL;
|
|
8
9
|
this.portal = portal;
|
|
9
10
|
this.processFieldData(fieldData);
|
|
10
11
|
}
|
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {RecordBase} from "./recordBase.js";
|
|
5
|
+
import {RecordBase, RecordTypes} from "./recordBase.js";
|
|
6
6
|
import {extraBodyOptions, recordObject} from "../types.js";
|
|
7
|
-
|
|
8
|
-
import {RecordFieldsMap} from "../layouts/
|
|
7
|
+
|
|
8
|
+
import {RecordFieldsMap} from "../layouts/recordFieldsMap";
|
|
9
|
+
import {PortalBase} from "./portalBase";
|
|
9
10
|
|
|
10
11
|
export class PortalRecord<T extends RecordFieldsMap> extends RecordBase<T> {
|
|
11
|
-
readonly portal:
|
|
12
|
+
readonly portal: PortalBase<T>;
|
|
13
|
+
readonly type = RecordTypes.PORTAL
|
|
12
14
|
|
|
13
15
|
constructor(record, portal, recordId, modId = recordId, fieldData = {}) {
|
|
14
16
|
super(record.layout, recordId, modId);
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { EventEmitter } from "events";
|
|
2
3
|
import { Field } from "./field.js";
|
|
3
4
|
import { Layout } from "../layouts/layout.js";
|
|
4
|
-
import { RecordFieldsMap } from "../layouts/layoutInterface.js";
|
|
5
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
|
+
}
|
|
6
12
|
export declare class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
|
|
7
13
|
readonly layout: Layout<any>;
|
|
14
|
+
readonly type: RecordTypes;
|
|
8
15
|
recordId: number;
|
|
9
16
|
modId: number;
|
|
10
17
|
fields: T;
|
|
@@ -12,9 +19,8 @@ export declare class RecordBase<T extends RecordFieldsMap> extends EventEmitter
|
|
|
12
19
|
constructor(layout: any, recordId: any, modId?: any);
|
|
13
20
|
get endpoint(): string;
|
|
14
21
|
get edited(): boolean;
|
|
15
|
-
get fieldsArray(): Field<import("
|
|
22
|
+
get fieldsArray(): Field<import("./field.js").FieldValue>[];
|
|
16
23
|
protected processFieldData(fieldData: any): T;
|
|
17
24
|
_onSave(): void;
|
|
18
|
-
getField(field: any): Field<import("../layouts/layoutInterface.js").FieldValue>;
|
|
19
25
|
toObject(filter?: (a: any) => any, portalFilter?: (a: any) => any, portalRowFilter?: (a: any) => any, portalFieldFilter?: (a: any) => any): recordObject;
|
|
20
26
|
}
|
|
@@ -2,11 +2,18 @@
|
|
|
2
2
|
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
4
|
import { EventEmitter } from "events";
|
|
5
|
-
import * as moment from "moment
|
|
5
|
+
import * as moment from "moment";
|
|
6
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 = {}));
|
|
7
13
|
export class RecordBase extends EventEmitter {
|
|
8
14
|
constructor(layout, recordId, modId = recordId) {
|
|
9
15
|
super();
|
|
16
|
+
this.type = RecordTypes.UNKNOWN;
|
|
10
17
|
this.layout = layout;
|
|
11
18
|
this.recordId = recordId;
|
|
12
19
|
this.modId = modId;
|
|
@@ -60,9 +67,6 @@ export class RecordBase extends EventEmitter {
|
|
|
60
67
|
for (let field of this.fieldsArray)
|
|
61
68
|
field.edited = false;
|
|
62
69
|
}
|
|
63
|
-
getField(field) {
|
|
64
|
-
return this.fieldsArray.find(_field => _field.id === field);
|
|
65
|
-
}
|
|
66
70
|
toObject(filter = (a) => a.edited, portalFilter = (a) => a.records.find(record => record.edited), portalRowFilter = (a) => a.edited, portalFieldFilter = (a) => a.edited) {
|
|
67
71
|
let fields_processed = {};
|
|
68
72
|
for (let field of this.fieldsArray.filter(field => filter(field))) {
|
|
@@ -3,17 +3,24 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import {EventEmitter} from "events";
|
|
6
|
-
import * as moment from "moment
|
|
6
|
+
import * as moment from "moment";
|
|
7
7
|
import {Field} from "./field.js";
|
|
8
8
|
import {Layout} from "../layouts/layout.js";
|
|
9
|
-
import {RecordFieldsMap} from "../layouts/layoutInterface.js";
|
|
10
9
|
import {recordObject} from "../types.js";
|
|
10
|
+
import {RecordFieldsMap} from "../layouts/recordFieldsMap";
|
|
11
|
+
|
|
12
|
+
export enum RecordTypes {
|
|
13
|
+
UNKNOWN,
|
|
14
|
+
LAYOUT,
|
|
15
|
+
PORTAL
|
|
16
|
+
}
|
|
11
17
|
|
|
12
18
|
export class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
|
|
13
19
|
readonly layout: Layout<any>;
|
|
20
|
+
readonly type: RecordTypes = RecordTypes.UNKNOWN;
|
|
14
21
|
public recordId: number;
|
|
15
22
|
modId: number;
|
|
16
|
-
fields: T
|
|
23
|
+
fields: T;
|
|
17
24
|
protected portalData: any[];
|
|
18
25
|
|
|
19
26
|
constructor(layout, recordId, modId = recordId) {
|
|
@@ -78,10 +85,6 @@ export class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
|
|
|
78
85
|
for (let field of this.fieldsArray) field.edited = false
|
|
79
86
|
}
|
|
80
87
|
|
|
81
|
-
getField(field) {
|
|
82
|
-
return this.fieldsArray.find(_field => _field.id === field)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
88
|
toObject(filter = (a) => a.edited,
|
|
86
89
|
portalFilter = (a) => a.records.find(record => record.edited),
|
|
87
90
|
portalRowFilter = (a) => a.edited,
|
package/src/types.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import * as http from "http";
|
|
4
|
-
import { Portal } from "./records/portal.js";
|
|
5
4
|
import { FMError } from "./FMError.js";
|
|
5
|
+
import { LayoutInterface } from "./layouts/layoutInterface";
|
|
6
|
+
export interface DatabaseStructure {
|
|
7
|
+
layouts: {
|
|
8
|
+
[key: string]: LayoutInterface;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
6
11
|
export interface databaseOptionsBase {
|
|
7
12
|
database: string;
|
|
8
13
|
credentials: loginOptionsOAuth | loginOptionsFileMaker | loginOptionsClaris | loginOptionsToken;
|
|
@@ -35,7 +40,7 @@ export interface loginOptionsClaris {
|
|
|
35
40
|
};
|
|
36
41
|
}
|
|
37
42
|
export interface limitPortalsInterface {
|
|
38
|
-
|
|
43
|
+
portalName: string;
|
|
39
44
|
offset: number;
|
|
40
45
|
limit: number;
|
|
41
46
|
}
|
package/src/types.ts
CHANGED
|
@@ -4,12 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
// const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
|
6
6
|
// @ts-ignore
|
|
7
|
-
import * as moment from "moment"
|
|
8
7
|
import * as http from "http";
|
|
9
|
-
import {Portal} from "./records/portal.js";
|
|
10
8
|
import {FMError} from "./FMError.js";
|
|
9
|
+
import {LayoutInterface} from "./layouts/layoutInterface";
|
|
11
10
|
|
|
12
11
|
// import * as btoa from "btoa";
|
|
12
|
+
export interface DatabaseStructure {
|
|
13
|
+
layouts: {
|
|
14
|
+
[key: string]: LayoutInterface
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
13
18
|
export interface databaseOptionsBase {
|
|
14
19
|
database: string
|
|
15
20
|
credentials: loginOptionsOAuth | loginOptionsFileMaker | loginOptionsClaris | loginOptionsToken,
|
|
@@ -48,7 +53,7 @@ export interface loginOptionsClaris {
|
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
export interface limitPortalsInterface {
|
|
51
|
-
|
|
56
|
+
portalName: string,
|
|
52
57
|
offset: number,
|
|
53
58
|
limit: number
|
|
54
59
|
}
|
package/test.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import FMHost from "./src/index.js";
|
|
2
|
+
export default FMHost;
|
package/test.js
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
import FMHost from "./src/index.js";
|
|
14
|
+
export default FMHost;
|
|
15
|
+
const host = new FMHost("https://lab.farmmedix.com");
|
|
16
|
+
const database = host.database({
|
|
17
|
+
database: "Snapshot_2.fmp12",
|
|
18
|
+
credentials: {
|
|
19
|
+
method: "filemaker",
|
|
20
|
+
username: "Developer",
|
|
21
|
+
password: "1df e53 0tx"
|
|
22
|
+
},
|
|
23
|
+
externalSources: []
|
|
24
|
+
});
|
|
25
|
+
database.login()
|
|
26
|
+
.then(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const layout = database.getLayout("RoleInfo");
|
|
28
|
+
const records = yield layout.records.range().fetch();
|
|
29
|
+
console.log(records[0]);
|
|
30
|
+
}));
|
package/test.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import FMHost, {Field, Layout} from "./src/index.js";
|
|
6
|
+
export default FMHost
|
|
7
|
+
|
|
8
|
+
const host = new FMHost("https://lab.farmmedix.com")
|
|
9
|
+
const database = host.database<{
|
|
10
|
+
layouts: {
|
|
11
|
+
RoleInfo: {
|
|
12
|
+
fields: {
|
|
13
|
+
field1: Field<string>
|
|
14
|
+
},
|
|
15
|
+
portals: {}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}>({
|
|
19
|
+
database: "Snapshot_2.fmp12",
|
|
20
|
+
credentials: {
|
|
21
|
+
method: "filemaker",
|
|
22
|
+
username: "Developer",
|
|
23
|
+
password: "1df e53 0tx"
|
|
24
|
+
},
|
|
25
|
+
externalSources: []
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
database.login()
|
|
29
|
+
.then(async () => {
|
|
30
|
+
const layout = database.getLayout("RoleInfo")
|
|
31
|
+
const records = await layout.records.range().fetch()
|
|
32
|
+
console.log(records[0])
|
|
33
|
+
})
|
package/test2.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|