@jd-data-limited/easy-fm 4.0.8 → 4.0.10
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 +1 -1
- package/src/index.d.ts +2 -2
- package/src/index.ts +2 -1
- package/src/records/fieldBase.d.ts +3 -3
- package/src/records/fieldBase.js +3 -3
- package/src/records/fieldBase.ts +5 -5
- package/src/records/getOperations/recordGetOperation.d.ts +5 -4
- package/src/records/getOperations/recordGetOperation.js +8 -6
- package/src/records/getOperations/recordGetOperation.ts +8 -7
- package/src/types.d.ts +1 -1
- package/src/types.js +5 -5
- package/src/types.ts +1 -1
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -10,9 +10,9 @@ import { LayoutInterface, PortalInterface } from "./layouts/layoutInterface.js";
|
|
|
10
10
|
import { PortalRecord } from "./records/portalRecord.js";
|
|
11
11
|
import { Portal } from "./records/portal.js";
|
|
12
12
|
import { Container, FieldBase } from "./records/fieldBase.js";
|
|
13
|
-
import { RecordGetOperation } from "./records/getOperations/recordGetOperation.js";
|
|
13
|
+
import { FindRequest, RecordGetOperation } from "./records/getOperations/recordGetOperation.js";
|
|
14
14
|
import { LayoutRecordManager } from "./layouts/layoutRecordManager.js";
|
|
15
15
|
import { RecordFieldsMap } from "./layouts/recordFieldsMap.js";
|
|
16
16
|
import { query, queryEscape } from "./utils/query.js";
|
|
17
17
|
export default FMHost;
|
|
18
|
-
export { FMError, TYPES, Database, Layout, RecordBase, LayoutRecord, LayoutInterface, RecordFieldsMap, PortalInterface, PortalRecord, Portal, FieldBase, RecordGetOperation, LayoutRecordManager, Container, PickPortals, query, queryEscape };
|
|
18
|
+
export { FMError, TYPES, Database, Layout, RecordBase, LayoutRecord, LayoutInterface, RecordFieldsMap, PortalInterface, PortalRecord, Portal, FieldBase, RecordGetOperation, LayoutRecordManager, Container, PickPortals, FindRequest, query, queryEscape };
|
package/src/index.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {LayoutInterface, PortalInterface} from "./layouts/layoutInterface.js";
|
|
|
14
14
|
import {PortalRecord} from "./records/portalRecord.js";
|
|
15
15
|
import {Portal} from "./records/portal.js";
|
|
16
16
|
import {Container, FieldBase} from "./records/fieldBase.js";
|
|
17
|
-
import {RecordGetOperation} from "./records/getOperations/recordGetOperation.js";
|
|
17
|
+
import {FindRequest, RecordGetOperation} from "./records/getOperations/recordGetOperation.js";
|
|
18
18
|
import {LayoutRecordManager} from "./layouts/layoutRecordManager.js";
|
|
19
19
|
import {RecordFieldsMap} from "./layouts/recordFieldsMap.js";
|
|
20
20
|
import {query, queryEscape} from "./utils/query.js";
|
|
@@ -37,6 +37,7 @@ export {
|
|
|
37
37
|
LayoutRecordManager,
|
|
38
38
|
Container,
|
|
39
39
|
PickPortals,
|
|
40
|
+
FindRequest,
|
|
40
41
|
query,
|
|
41
42
|
queryEscape
|
|
42
43
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
3
|
import * as http from "http";
|
|
4
|
-
import { ContainerBufferResult,
|
|
4
|
+
import { ContainerBufferResult, DownloadModes, RecordTypes } from "../types.js";
|
|
5
5
|
import { ApiFieldMetadata } from "../models/apiResults.js";
|
|
6
6
|
import { LayoutBase } from "../layouts/layoutBase.js";
|
|
7
7
|
export type FieldValue = string | number | Date | Container;
|
|
@@ -25,6 +25,6 @@ export declare class FieldBase<T extends FieldValue> {
|
|
|
25
25
|
get date(): Date;
|
|
26
26
|
get number(): number;
|
|
27
27
|
upload(buffer: Buffer, filename: string, mime: string): Promise<void>;
|
|
28
|
-
download(mode:
|
|
29
|
-
download(mode:
|
|
28
|
+
download(mode: DownloadModes.Stream): Promise<http.IncomingMessage>;
|
|
29
|
+
download(mode: DownloadModes.Buffer): Promise<ContainerBufferResult>;
|
|
30
30
|
}
|
package/src/records/fieldBase.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Copyright (c) 2023-2024. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { DownloadModes, RecordTypes } from "../types.js";
|
|
5
5
|
import { ApiFieldDisplayTypes, ApiFieldResultTypes, ApiFieldTypes } from "../models/apiResults.js";
|
|
6
6
|
export class FieldBase {
|
|
7
7
|
parent;
|
|
@@ -128,11 +128,11 @@ export class FieldBase {
|
|
|
128
128
|
if (!res.ok)
|
|
129
129
|
throw new Error(`Upload failed with HTTP error: ${res.status} (${res.statusText})`);
|
|
130
130
|
}
|
|
131
|
-
async download(mode =
|
|
131
|
+
async download(mode = DownloadModes.Stream) {
|
|
132
132
|
if (this.metadata.result !== ApiFieldResultTypes.CONTAINER)
|
|
133
133
|
throw new Error("Cannot perform download() on a non-container field");
|
|
134
134
|
let stream = await this.parent.layout.database.streamURL(this.string);
|
|
135
|
-
if (mode ===
|
|
135
|
+
if (mode === DownloadModes.Stream) {
|
|
136
136
|
return stream;
|
|
137
137
|
}
|
|
138
138
|
let body = [];
|
package/src/records/fieldBase.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import * as http from "http";
|
|
6
|
-
import {ContainerBufferResult,
|
|
6
|
+
import {ContainerBufferResult, DownloadModes, FieldMetaData, RecordTypes} from "../types.js";
|
|
7
7
|
import {ApiFieldDisplayTypes, ApiFieldMetadata, ApiFieldResultTypes, ApiFieldTypes} from "../models/apiResults.js";
|
|
8
8
|
import {LayoutBase} from "../layouts/layoutBase.js";
|
|
9
9
|
|
|
@@ -144,13 +144,13 @@ export class FieldBase<T extends FieldValue> {
|
|
|
144
144
|
if (!res.ok) throw new Error(`Upload failed with HTTP error: ${res.status} (${res.statusText})`)
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
download(mode:
|
|
148
|
-
download(mode:
|
|
149
|
-
async download(mode:
|
|
147
|
+
download(mode: DownloadModes.Stream): Promise<http.IncomingMessage>
|
|
148
|
+
download(mode: DownloadModes.Buffer): Promise<ContainerBufferResult>
|
|
149
|
+
async download(mode: DownloadModes = DownloadModes.Stream): Promise<http.IncomingMessage | ContainerBufferResult> {
|
|
150
150
|
if (this.metadata.result !== ApiFieldResultTypes.CONTAINER) throw new Error("Cannot perform download() on a non-container field")
|
|
151
151
|
|
|
152
152
|
let stream = await this.parent.layout.database.streamURL(this.string)
|
|
153
|
-
if (mode ===
|
|
153
|
+
if (mode === DownloadModes.Stream) {
|
|
154
154
|
return stream
|
|
155
155
|
}
|
|
156
156
|
|
|
@@ -6,8 +6,6 @@ import { Query } from "../../utils/query.js";
|
|
|
6
6
|
export type SortOrder = "ascend" | "descend";
|
|
7
7
|
export type FindRequest = {
|
|
8
8
|
[key: string]: Query;
|
|
9
|
-
} & {
|
|
10
|
-
omit?: "true" | "false";
|
|
11
9
|
};
|
|
12
10
|
export type PortalRequest = {
|
|
13
11
|
name: string;
|
|
@@ -33,7 +31,10 @@ export declare class RecordGetOperation<T extends LayoutInterface, OPTIONS exten
|
|
|
33
31
|
}[];
|
|
34
32
|
protected portals: Partial<PortalData<T>>;
|
|
35
33
|
protected offset: number;
|
|
36
|
-
protected queries:
|
|
34
|
+
protected queries: {
|
|
35
|
+
req: FindRequest;
|
|
36
|
+
omit: boolean;
|
|
37
|
+
}[];
|
|
37
38
|
constructor(layout: LayoutBase, options: OPTIONS);
|
|
38
39
|
get isFindRequest(): boolean;
|
|
39
40
|
private formatQueries;
|
|
@@ -43,7 +44,7 @@ export declare class RecordGetOperation<T extends LayoutInterface, OPTIONS exten
|
|
|
43
44
|
protected generateParamsURL(offset: number, limit: number): URLSearchParams;
|
|
44
45
|
scripts(scripts: ScriptRequestData): this;
|
|
45
46
|
sort(fieldName: string, sortOrder: SortOrder): this;
|
|
46
|
-
addRequest(query: FindRequest): this;
|
|
47
|
+
addRequest(query: FindRequest, omit?: boolean): this;
|
|
47
48
|
fetch(): Promise<LayoutRecord<PickPortals<T, keyof OPTIONS["portals"]>>[]>;
|
|
48
49
|
private performFind;
|
|
49
50
|
[Symbol.asyncIterator](): {
|
|
@@ -25,13 +25,15 @@ export class RecordGetOperation {
|
|
|
25
25
|
formatQueries() {
|
|
26
26
|
return this.queries.map(query => {
|
|
27
27
|
let out = {};
|
|
28
|
-
for (let key of Object.keys(query)) {
|
|
29
|
-
if (query[key][FindRequestSymbol])
|
|
30
|
-
out[key] = query[key][FindRequestSymbol];
|
|
28
|
+
for (let key of Object.keys(query.req)) {
|
|
29
|
+
if (query.req[key][FindRequestSymbol])
|
|
30
|
+
out[key] = query.req[key][FindRequestSymbol];
|
|
31
31
|
else {
|
|
32
|
-
out[key] = query[key];
|
|
32
|
+
out[key] = query.req[key];
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
if (query.omit)
|
|
36
|
+
out.omit = "true";
|
|
35
37
|
return out;
|
|
36
38
|
});
|
|
37
39
|
}
|
|
@@ -99,8 +101,8 @@ export class RecordGetOperation {
|
|
|
99
101
|
this.sortData.push({ fieldName, sortOrder });
|
|
100
102
|
return this;
|
|
101
103
|
}
|
|
102
|
-
addRequest(query) {
|
|
103
|
-
this.queries.push(query);
|
|
104
|
+
addRequest(query, omit = false) {
|
|
105
|
+
this.queries.push({ req: query, omit });
|
|
104
106
|
return this;
|
|
105
107
|
}
|
|
106
108
|
fetch() {
|
|
@@ -13,7 +13,7 @@ import {FindRequestSymbol, Query} from "../../utils/query.js";
|
|
|
13
13
|
export type SortOrder = "ascend" | "descend"
|
|
14
14
|
export type FindRequest = {
|
|
15
15
|
[key: string]: Query
|
|
16
|
-
}
|
|
16
|
+
}
|
|
17
17
|
|
|
18
18
|
export type PortalRequest = {
|
|
19
19
|
name: string,
|
|
@@ -38,7 +38,7 @@ export class RecordGetOperation<T extends LayoutInterface, OPTIONS extends GetOp
|
|
|
38
38
|
protected sortData: { fieldName: string, sortOrder: SortOrder }[] = []
|
|
39
39
|
protected portals: Partial<PortalData<T>>
|
|
40
40
|
protected offset: number = 1
|
|
41
|
-
protected queries: FindRequest[] = []
|
|
41
|
+
protected queries: {req: FindRequest, omit: boolean}[] = []
|
|
42
42
|
|
|
43
43
|
constructor(layout: LayoutBase, options: OPTIONS) {
|
|
44
44
|
this.layout = layout
|
|
@@ -55,10 +55,11 @@ export class RecordGetOperation<T extends LayoutInterface, OPTIONS extends GetOp
|
|
|
55
55
|
private formatQueries() {
|
|
56
56
|
return this.queries.map(query => {
|
|
57
57
|
let out: any = {}
|
|
58
|
-
for (let key of Object.keys(query)) {
|
|
59
|
-
if (query[key][FindRequestSymbol]) out[key] = query[key][FindRequestSymbol]
|
|
60
|
-
else {out[key] = query[key]}
|
|
58
|
+
for (let key of Object.keys(query.req)) {
|
|
59
|
+
if (query.req[key][FindRequestSymbol]) out[key] = query.req[key][FindRequestSymbol]
|
|
60
|
+
else {out[key] = query.req[key]}
|
|
61
61
|
}
|
|
62
|
+
if (query.omit) out.omit = "true"
|
|
62
63
|
return out
|
|
63
64
|
})
|
|
64
65
|
}
|
|
@@ -127,8 +128,8 @@ export class RecordGetOperation<T extends LayoutInterface, OPTIONS extends GetOp
|
|
|
127
128
|
return this
|
|
128
129
|
}
|
|
129
130
|
|
|
130
|
-
addRequest(query: FindRequest) {
|
|
131
|
-
this.queries.push(query)
|
|
131
|
+
addRequest(query: FindRequest, omit = false) {
|
|
132
|
+
this.queries.push({req: query, omit})
|
|
132
133
|
return this
|
|
133
134
|
}
|
|
134
135
|
|
package/src/types.d.ts
CHANGED
package/src/types.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Copyright (c) 2022-2024. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
|
-
export var
|
|
5
|
-
(function (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
})(
|
|
4
|
+
export var DownloadModes;
|
|
5
|
+
(function (DownloadModes) {
|
|
6
|
+
DownloadModes[DownloadModes["Stream"] = 0] = "Stream";
|
|
7
|
+
DownloadModes[DownloadModes["Buffer"] = 1] = "Buffer";
|
|
8
|
+
})(DownloadModes || (DownloadModes = {}));
|
|
9
9
|
export var RecordTypes;
|
|
10
10
|
(function (RecordTypes) {
|
|
11
11
|
RecordTypes[RecordTypes["UNKNOWN"] = 0] = "UNKNOWN";
|