@jd-data-limited/easy-fm 1.2.0-alpha1 → 1.2.2-alpha3
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/index.js +42 -36
- package/index.ts +62 -52
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -284,7 +284,7 @@ class layoutRecordManager {
|
|
|
284
284
|
for (let _field of this.layout.metadata.fieldMetaData) {
|
|
285
285
|
fields[_field.name] = "";
|
|
286
286
|
}
|
|
287
|
-
resolve(new
|
|
287
|
+
resolve(new LayoutRecord(this, -1, 0, fields));
|
|
288
288
|
}).catch(e => {
|
|
289
289
|
reject(e);
|
|
290
290
|
});
|
|
@@ -295,7 +295,7 @@ class layoutRecordManager {
|
|
|
295
295
|
let record;
|
|
296
296
|
this.layout.getLayoutMeta()
|
|
297
297
|
.then(layout => {
|
|
298
|
-
record = new
|
|
298
|
+
record = new LayoutRecord(this.layout, recordId);
|
|
299
299
|
return record.get();
|
|
300
300
|
})
|
|
301
301
|
.then(() => {
|
|
@@ -313,21 +313,13 @@ class layoutRecordManager {
|
|
|
313
313
|
return new find(this.layout);
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
|
-
class
|
|
317
|
-
constructor(layout, recordId, modId = recordId
|
|
316
|
+
class RecordBase extends EventEmitter {
|
|
317
|
+
constructor(layout, recordId, modId = recordId) {
|
|
318
318
|
super();
|
|
319
|
+
this.portals = [];
|
|
319
320
|
this.layout = layout;
|
|
320
321
|
this.recordId = recordId;
|
|
321
322
|
this.modId = modId;
|
|
322
|
-
this.fields = this.processFieldData(fieldData);
|
|
323
|
-
this.portals = [];
|
|
324
|
-
if (portalData) {
|
|
325
|
-
this.processPortalData(portalData);
|
|
326
|
-
}
|
|
327
|
-
this.on("saved", () => {
|
|
328
|
-
for (let field of this.fields)
|
|
329
|
-
field.edited = false;
|
|
330
|
-
});
|
|
331
323
|
}
|
|
332
324
|
get endpoint() {
|
|
333
325
|
return `${this.layout.endpoint}/records/${this.recordId}`;
|
|
@@ -337,12 +329,14 @@ class record extends EventEmitter {
|
|
|
337
329
|
}
|
|
338
330
|
processPortalData(portalData) {
|
|
339
331
|
for (let item of Object.keys(portalData)) {
|
|
340
|
-
|
|
332
|
+
let _portal = new portal(this, item);
|
|
333
|
+
_portal.records = portalData[item].map(item => {
|
|
341
334
|
let fieldData = item;
|
|
342
335
|
delete fieldData.recordId;
|
|
343
336
|
delete fieldData.modId;
|
|
344
|
-
return new
|
|
345
|
-
})
|
|
337
|
+
return new PortalRecord(this, _portal, item.recordId, item.modId, fieldData);
|
|
338
|
+
});
|
|
339
|
+
this.portals.push(_portal);
|
|
346
340
|
}
|
|
347
341
|
}
|
|
348
342
|
processFieldData(fieldData) {
|
|
@@ -379,7 +373,7 @@ class record extends EventEmitter {
|
|
|
379
373
|
}
|
|
380
374
|
get() {
|
|
381
375
|
if (this.recordId === -1) {
|
|
382
|
-
throw "Cannot get this
|
|
376
|
+
throw "Cannot get this RecordBase until a commit() is done.";
|
|
383
377
|
}
|
|
384
378
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
385
379
|
if (!this.layout.metadata)
|
|
@@ -415,7 +409,7 @@ class record extends EventEmitter {
|
|
|
415
409
|
delete data.recordId;
|
|
416
410
|
delete data.modId;
|
|
417
411
|
if (this.recordId === -1) {
|
|
418
|
-
// This is a new
|
|
412
|
+
// This is a new LayoutRecord
|
|
419
413
|
extraBody.fieldData = data.fieldData;
|
|
420
414
|
this.layout.database.apiRequest(`${this.layout.endpoint}/records`, {
|
|
421
415
|
port: 443,
|
|
@@ -453,7 +447,7 @@ class record extends EventEmitter {
|
|
|
453
447
|
}
|
|
454
448
|
else if (res.messages[0].code === "0") {
|
|
455
449
|
this.modId = res.response.modId;
|
|
456
|
-
this.
|
|
450
|
+
this._onSave();
|
|
457
451
|
resolve(this);
|
|
458
452
|
}
|
|
459
453
|
else {
|
|
@@ -465,6 +459,11 @@ class record extends EventEmitter {
|
|
|
465
459
|
});
|
|
466
460
|
}));
|
|
467
461
|
}
|
|
462
|
+
_onSave() {
|
|
463
|
+
this.emit("saved");
|
|
464
|
+
for (let field of this.fields)
|
|
465
|
+
field.edited = false;
|
|
466
|
+
}
|
|
468
467
|
getField(field) {
|
|
469
468
|
return this.fields.find(_field => _field.id === field);
|
|
470
469
|
}
|
|
@@ -506,7 +505,7 @@ class record extends EventEmitter {
|
|
|
506
505
|
}
|
|
507
506
|
else if (res.messages[0].code === "0") {
|
|
508
507
|
let data = this.toObject((a) => true, (a) => true, (a) => false, (a) => false);
|
|
509
|
-
let _res = new
|
|
508
|
+
let _res = new LayoutRecord(this.layout, res.response.recordId, res.response.modId, data.fieldData, data.portalData);
|
|
510
509
|
this.emit("duplicated");
|
|
511
510
|
resolve(_res);
|
|
512
511
|
}
|
|
@@ -559,6 +558,16 @@ class record extends EventEmitter {
|
|
|
559
558
|
return obj;
|
|
560
559
|
}
|
|
561
560
|
}
|
|
561
|
+
class LayoutRecord extends RecordBase {
|
|
562
|
+
constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null) {
|
|
563
|
+
super(layout, recordId, modId);
|
|
564
|
+
this.fields = this.processFieldData(fieldData);
|
|
565
|
+
this.portals = [];
|
|
566
|
+
if (portalData) {
|
|
567
|
+
this.processPortalData(portalData);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
562
571
|
class field {
|
|
563
572
|
constructor(record, id, contents) {
|
|
564
573
|
this.record = record;
|
|
@@ -598,8 +607,8 @@ class field {
|
|
|
598
607
|
repetitionEnd: 1
|
|
599
608
|
};
|
|
600
609
|
}
|
|
601
|
-
if (this.record instanceof
|
|
602
|
-
return this.record.layout.metadata.portalMetaData.find(i => i.name === this.id) || {
|
|
610
|
+
if (this.record instanceof PortalRecord) {
|
|
611
|
+
return this.record.layout.metadata.portalMetaData[this.record.portal.name || "portal not attached"].find(i => i.name === this.id) || {
|
|
603
612
|
name: this.id.toString(),
|
|
604
613
|
type: 'normal',
|
|
605
614
|
displayType: 'editText',
|
|
@@ -672,23 +681,20 @@ class field {
|
|
|
672
681
|
}
|
|
673
682
|
}
|
|
674
683
|
class portal {
|
|
675
|
-
constructor(record, name
|
|
684
|
+
constructor(record, name) {
|
|
676
685
|
this.record = record;
|
|
677
686
|
this.name = name;
|
|
678
|
-
this.records = records;
|
|
679
|
-
for (let item of this.records)
|
|
680
|
-
item.attachPortal(this);
|
|
681
687
|
}
|
|
682
688
|
}
|
|
683
|
-
class
|
|
684
|
-
constructor(record, recordId, modId = recordId, fieldData = {}) {
|
|
685
|
-
super(record.layout, recordId, modId
|
|
686
|
-
record.on("saved", () => {
|
|
687
|
-
this.emit("saved");
|
|
688
|
-
});
|
|
689
|
-
}
|
|
690
|
-
attachPortal(portal) {
|
|
689
|
+
class PortalRecord extends RecordBase {
|
|
690
|
+
constructor(record, portal, recordId, modId = recordId, fieldData = {}) {
|
|
691
|
+
super(record.layout, recordId, modId);
|
|
691
692
|
this.portal = portal;
|
|
693
|
+
this.fields = this.processFieldData(fieldData);
|
|
694
|
+
}
|
|
695
|
+
_onSave() {
|
|
696
|
+
super._onSave();
|
|
697
|
+
this.portal.record._onSave();
|
|
692
698
|
}
|
|
693
699
|
commit(extraBody = { fieldData: undefined }) {
|
|
694
700
|
return this.portal.record.commit(extraBody);
|
|
@@ -781,7 +787,7 @@ class recordGetRange extends recordGetOperation {
|
|
|
781
787
|
if (!this.layout.metadata)
|
|
782
788
|
yield this.layout.getLayoutMeta();
|
|
783
789
|
let data = res.response.data.map(item => {
|
|
784
|
-
return new
|
|
790
|
+
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData);
|
|
785
791
|
});
|
|
786
792
|
resolve(data);
|
|
787
793
|
}
|
|
@@ -850,7 +856,7 @@ class find extends recordGetOperation {
|
|
|
850
856
|
if (!this.layout.metadata)
|
|
851
857
|
yield this.layout.getLayoutMeta();
|
|
852
858
|
let data = res.response.data.map(item => {
|
|
853
|
-
return new
|
|
859
|
+
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData);
|
|
854
860
|
});
|
|
855
861
|
resolve(data);
|
|
856
862
|
}
|
package/index.ts
CHANGED
|
@@ -338,14 +338,14 @@ class layout {
|
|
|
338
338
|
/**
|
|
339
339
|
* @deprecated use layout.records.create() instead
|
|
340
340
|
*/
|
|
341
|
-
createRecord(): Promise<
|
|
341
|
+
createRecord(): Promise<RecordBase | Error | void> {
|
|
342
342
|
return this.records.create()
|
|
343
343
|
}
|
|
344
344
|
|
|
345
345
|
/**
|
|
346
346
|
* @deprecated use layout.records.get() instead
|
|
347
347
|
*/
|
|
348
|
-
getRecord(recordId): Promise<
|
|
348
|
+
getRecord(recordId): Promise<RecordBase> {
|
|
349
349
|
return this.records.get(recordId)
|
|
350
350
|
}
|
|
351
351
|
|
|
@@ -401,7 +401,7 @@ class layoutRecordManager {
|
|
|
401
401
|
this.layout = layout
|
|
402
402
|
}
|
|
403
403
|
|
|
404
|
-
create(): Promise<
|
|
404
|
+
create(): Promise<RecordBase | Error | void> {
|
|
405
405
|
return new Promise((resolve, reject) => {
|
|
406
406
|
// Get the layout's metadata
|
|
407
407
|
this.layout.getLayoutMeta().then(layout => {
|
|
@@ -409,19 +409,19 @@ class layoutRecordManager {
|
|
|
409
409
|
for (let _field of this.layout.metadata.fieldMetaData) {
|
|
410
410
|
fields[_field.name] = ""
|
|
411
411
|
}
|
|
412
|
-
resolve(new
|
|
412
|
+
resolve(new LayoutRecord(this, -1, 0, fields))
|
|
413
413
|
}).catch(e => {
|
|
414
414
|
reject(e)
|
|
415
415
|
})
|
|
416
416
|
})
|
|
417
417
|
}
|
|
418
418
|
|
|
419
|
-
get(recordId): Promise<
|
|
419
|
+
get(recordId): Promise<RecordBase> {
|
|
420
420
|
return new Promise((resolve, reject) => {
|
|
421
421
|
let record
|
|
422
422
|
this.layout.getLayoutMeta()
|
|
423
423
|
.then(layout => {
|
|
424
|
-
record = new
|
|
424
|
+
record = new LayoutRecord(this.layout, recordId)
|
|
425
425
|
return record.get()
|
|
426
426
|
})
|
|
427
427
|
.then(() => {
|
|
@@ -442,27 +442,19 @@ class layoutRecordManager {
|
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
444
|
|
|
445
|
-
class
|
|
445
|
+
class RecordBase extends EventEmitter {
|
|
446
446
|
readonly layout: layout;
|
|
447
447
|
public recordId: number;
|
|
448
448
|
modId: number;
|
|
449
449
|
fields: field[];
|
|
450
|
-
|
|
451
|
-
|
|
450
|
+
portals: portal[] = [];
|
|
451
|
+
protected portalData: any[];
|
|
452
452
|
|
|
453
|
-
constructor(layout, recordId, modId = recordId
|
|
453
|
+
constructor(layout, recordId, modId = recordId) {
|
|
454
454
|
super();
|
|
455
455
|
this.layout = layout
|
|
456
456
|
this.recordId = recordId
|
|
457
457
|
this.modId = modId
|
|
458
|
-
this.fields = this.processFieldData(fieldData)
|
|
459
|
-
this.portals = []
|
|
460
|
-
if (portalData) {
|
|
461
|
-
this.processPortalData(portalData)
|
|
462
|
-
}
|
|
463
|
-
this.on("saved", () => {
|
|
464
|
-
for (let field of this.fields) field.edited = false
|
|
465
|
-
})
|
|
466
458
|
}
|
|
467
459
|
|
|
468
460
|
get endpoint(): string {
|
|
@@ -473,14 +465,16 @@ class record extends EventEmitter {
|
|
|
473
465
|
return !!this.fields.find(i => i.edited)
|
|
474
466
|
}
|
|
475
467
|
|
|
476
|
-
|
|
468
|
+
protected processPortalData(portalData): void {
|
|
477
469
|
for (let item of Object.keys(portalData)) {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
delete fieldData.
|
|
482
|
-
|
|
483
|
-
|
|
470
|
+
let _portal = new portal(this, item)
|
|
471
|
+
_portal.records = portalData[item].map(item => {
|
|
472
|
+
let fieldData = item;
|
|
473
|
+
delete fieldData.recordId;
|
|
474
|
+
delete fieldData.modId;
|
|
475
|
+
return new PortalRecord(this, _portal, item.recordId, item.modId, fieldData);
|
|
476
|
+
})
|
|
477
|
+
this.portals.push(_portal);
|
|
484
478
|
}
|
|
485
479
|
}
|
|
486
480
|
|
|
@@ -518,7 +512,7 @@ class record extends EventEmitter {
|
|
|
518
512
|
|
|
519
513
|
get() {
|
|
520
514
|
if (this.recordId === -1) {
|
|
521
|
-
throw "Cannot get this
|
|
515
|
+
throw "Cannot get this RecordBase until a commit() is done."
|
|
522
516
|
}
|
|
523
517
|
return new Promise(async (resolve, reject) => {
|
|
524
518
|
if (!this.layout.metadata) await this.layout.getLayoutMeta()
|
|
@@ -547,14 +541,14 @@ class record extends EventEmitter {
|
|
|
547
541
|
|
|
548
542
|
commit(extraBody = {
|
|
549
543
|
fieldData: undefined
|
|
550
|
-
}): Promise<
|
|
544
|
+
}): Promise<RecordBase | FMError> {
|
|
551
545
|
return new Promise(async (resolve, reject) => {
|
|
552
546
|
let data = this.toObject()
|
|
553
547
|
delete data.recordId
|
|
554
548
|
delete data.modId
|
|
555
549
|
|
|
556
550
|
if (this.recordId === -1) {
|
|
557
|
-
// This is a new
|
|
551
|
+
// This is a new LayoutRecord
|
|
558
552
|
extraBody.fieldData = data.fieldData
|
|
559
553
|
|
|
560
554
|
this.layout.database.apiRequest(`${this.layout.endpoint}/records`, {
|
|
@@ -591,7 +585,7 @@ class record extends EventEmitter {
|
|
|
591
585
|
reject(new FMError(res.response.scriptError, res.status, res))
|
|
592
586
|
} else if (res.messages[0].code === "0") {
|
|
593
587
|
this.modId = res.response.modId
|
|
594
|
-
this.
|
|
588
|
+
this._onSave()
|
|
595
589
|
resolve(this)
|
|
596
590
|
} else {
|
|
597
591
|
reject(new FMError(res.messages[0].code, res.status, res))
|
|
@@ -602,6 +596,11 @@ class record extends EventEmitter {
|
|
|
602
596
|
})
|
|
603
597
|
})
|
|
604
598
|
}
|
|
599
|
+
|
|
600
|
+
_onSave() {
|
|
601
|
+
this.emit("saved")
|
|
602
|
+
for (let field of this.fields) field.edited = false
|
|
603
|
+
}
|
|
605
604
|
|
|
606
605
|
getField(field) {
|
|
607
606
|
return this.fields.find(_field => _field.id === field)
|
|
@@ -633,7 +632,7 @@ class record extends EventEmitter {
|
|
|
633
632
|
})
|
|
634
633
|
}
|
|
635
634
|
|
|
636
|
-
duplicate(): Promise<
|
|
635
|
+
duplicate(): Promise<RecordBase> {
|
|
637
636
|
return new Promise(async (resolve, reject) => {
|
|
638
637
|
this.layout.database.apiRequest(this.endpoint, {
|
|
639
638
|
port: 443,
|
|
@@ -644,7 +643,7 @@ class record extends EventEmitter {
|
|
|
644
643
|
reject(new FMError(res.response.scriptError, res.status, res))
|
|
645
644
|
} else if (res.messages[0].code === "0") {
|
|
646
645
|
let data = this.toObject((a) => true, (a) => true, (a) => false, (a) => false)
|
|
647
|
-
let _res = new
|
|
646
|
+
let _res = new LayoutRecord(this.layout, res.response.recordId, res.response.modId, data.fieldData, data.portalData)
|
|
648
647
|
|
|
649
648
|
this.emit("duplicated")
|
|
650
649
|
resolve(_res)
|
|
@@ -706,9 +705,21 @@ class record extends EventEmitter {
|
|
|
706
705
|
return obj
|
|
707
706
|
}
|
|
708
707
|
}
|
|
708
|
+
class LayoutRecord extends RecordBase {
|
|
709
|
+
portals: portal[];
|
|
710
|
+
|
|
711
|
+
constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null) {
|
|
712
|
+
super(layout, recordId, modId);
|
|
713
|
+
this.fields = this.processFieldData(fieldData)
|
|
714
|
+
this.portals = []
|
|
715
|
+
if (portalData) {
|
|
716
|
+
this.processPortalData(portalData)
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
709
720
|
|
|
710
721
|
class field {
|
|
711
|
-
record:
|
|
722
|
+
record: RecordBase;
|
|
712
723
|
id: number;
|
|
713
724
|
private _value: string | number | Date;
|
|
714
725
|
edited: boolean;
|
|
@@ -754,8 +765,8 @@ class field {
|
|
|
754
765
|
repetitionEnd: 1
|
|
755
766
|
} as fieldMetaData
|
|
756
767
|
}
|
|
757
|
-
if (this.record instanceof
|
|
758
|
-
return this.record.layout.metadata.portalMetaData.find(i => i.name === this.id) as fieldMetaData || {
|
|
768
|
+
if (this.record instanceof PortalRecord) {
|
|
769
|
+
return this.record.layout.metadata.portalMetaData[this.record.portal.name || "portal not attached"].find(i => i.name === this.id) as fieldMetaData || {
|
|
759
770
|
name: this.id.toString(),
|
|
760
771
|
type: 'normal',
|
|
761
772
|
displayType: 'editText',
|
|
@@ -830,30 +841,29 @@ class field {
|
|
|
830
841
|
}
|
|
831
842
|
|
|
832
843
|
class portal {
|
|
833
|
-
readonly record:
|
|
844
|
+
readonly record: RecordBase;
|
|
834
845
|
readonly name: string;
|
|
835
|
-
public records:
|
|
846
|
+
public records: PortalRecord[];
|
|
836
847
|
|
|
837
|
-
constructor(record:
|
|
848
|
+
constructor(record: RecordBase, name: string) {
|
|
838
849
|
this.record = record
|
|
839
850
|
this.name = name
|
|
840
|
-
this.records = records
|
|
841
|
-
for (let item of this.records) item.attachPortal(this)
|
|
842
851
|
}
|
|
843
852
|
}
|
|
844
853
|
|
|
845
|
-
class
|
|
846
|
-
|
|
854
|
+
class PortalRecord extends RecordBase {
|
|
855
|
+
readonly portal: portal;
|
|
847
856
|
|
|
848
|
-
constructor(record, recordId, modId = recordId, fieldData = {}) {
|
|
849
|
-
super(record.layout, recordId, modId
|
|
850
|
-
record.on("saved", () => {
|
|
851
|
-
this.emit("saved")
|
|
852
|
-
})
|
|
853
|
-
}
|
|
857
|
+
constructor(record, portal, recordId, modId = recordId, fieldData = {}) {
|
|
858
|
+
super(record.layout, recordId, modId);
|
|
854
859
|
|
|
855
|
-
attachPortal(portal) {
|
|
856
860
|
this.portal = portal
|
|
861
|
+
this.fields = this.processFieldData(fieldData)
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
_onSave() {
|
|
865
|
+
super._onSave();
|
|
866
|
+
this.portal.record._onSave()
|
|
857
867
|
}
|
|
858
868
|
|
|
859
869
|
commit(extraBody = {fieldData: undefined}) {
|
|
@@ -936,7 +946,7 @@ class recordGetRange extends recordGetOperation {
|
|
|
936
946
|
return "?" + params.join("&")
|
|
937
947
|
}
|
|
938
948
|
|
|
939
|
-
run(): Promise<
|
|
949
|
+
run(): Promise<RecordBase[]> {
|
|
940
950
|
return new Promise((resolve, reject) => {
|
|
941
951
|
// console.log(this.#toObject())
|
|
942
952
|
this.layout.getLayoutMeta().then(() => {
|
|
@@ -950,7 +960,7 @@ class recordGetRange extends recordGetOperation {
|
|
|
950
960
|
// console.log("RESOLVING")
|
|
951
961
|
if (!this.layout.metadata) await this.layout.getLayoutMeta()
|
|
952
962
|
let data = res.response.data.map(item => {
|
|
953
|
-
return new
|
|
963
|
+
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData)
|
|
954
964
|
})
|
|
955
965
|
resolve(data)
|
|
956
966
|
} else {
|
|
@@ -1005,7 +1015,7 @@ class find extends recordGetOperation {
|
|
|
1005
1015
|
return this.run()
|
|
1006
1016
|
}
|
|
1007
1017
|
|
|
1008
|
-
run(): Promise<
|
|
1018
|
+
run(): Promise<RecordBase[]> {
|
|
1009
1019
|
return new Promise((resolve, reject) => {
|
|
1010
1020
|
// console.log(this.#toObject())
|
|
1011
1021
|
this.layout.getLayoutMeta()
|
|
@@ -1022,7 +1032,7 @@ class find extends recordGetOperation {
|
|
|
1022
1032
|
// console.log("RESOLVING")
|
|
1023
1033
|
if (!this.layout.metadata) await this.layout.getLayoutMeta()
|
|
1024
1034
|
let data = res.response.data.map(item => {
|
|
1025
|
-
return new
|
|
1035
|
+
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData)
|
|
1026
1036
|
})
|
|
1027
1037
|
resolve(data)
|
|
1028
1038
|
} else {
|