Skip to content

Commit d3ac5e5

Browse files
committed
- remove invalid methods for List/Map types in Hive
1 parent a96cdfe commit d3ac5e5

File tree

6 files changed

+0
-241
lines changed

6 files changed

+0
-241
lines changed

backendless.d.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,6 @@ declare module Backendless {
414414

415415
get(indexFrom: number, indexTo: number): Promise<Array<JSONValue>>
416416

417-
set(values: Array<JSONValue>): Promise<number>;
418-
419-
set(value: JSONValue, index: number): Promise<void>;
420-
421417
insertBefore(valueToInsert: JSONValue, anchorValue: JSONValue): Promise<number>;
422418

423419
insertAfter(valueToInsert: JSONValue, anchorValue: JSONValue): Promise<number>;
@@ -477,8 +473,6 @@ declare module Backendless {
477473

478474
setWithOverwrite(key: string, value: JSONValue, overwrite?: boolean): Promise<boolean>;
479475

480-
add(data: object): Promise<number>;
481-
482476
increment(key: string, count?: number): Promise<number>;
483477

484478
decrement(key: string, count?: number): Promise<number>;

src/hive/stores/list.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,36 +40,6 @@ export class ListStore extends HiveStore {
4040
})
4141
}
4242

43-
set(value, index) {
44-
if (typeof index === 'undefined') {
45-
if (!value || !Array.isArray(value) || !value.length || !isHiveValueValid(value)) {
46-
throw new Error('Value must be provided and must be a list of valid JSON items.')
47-
}
48-
49-
return this.app.request
50-
.put({
51-
url : this.getBaseURL(),
52-
data: value
53-
})
54-
}
55-
56-
if (!isHiveValueValid(value)) {
57-
throw new Error('Value must be provided and must be one of types: string, number, boolean, object, array.')
58-
}
59-
60-
if (typeof index !== 'number' || isNaN(index)) {
61-
throw new Error('Index must be a number.')
62-
}
63-
64-
return this.app.request
65-
.put({
66-
url : `${this.getBaseURL()}/${index}`,
67-
data: {
68-
value
69-
}
70-
})
71-
}
72-
7343
length() {
7444
return this.app.request
7545
.get({

src/hive/stores/map.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,6 @@ export class MapStore extends HiveStore {
119119
})
120120
}
121121

122-
add(data) {
123-
if (!Utils.isObject(data)) {
124-
throw new Error('Payload must be an object.')
125-
}
126-
127-
if (!Object.keys(data).length) {
128-
throw new Error('Provided object must have at least 1 key.')
129-
}
130-
131-
return this.app.request
132-
.put({
133-
url: `${this.getBaseURL()}/add`,
134-
data,
135-
})
136-
}
137-
138122
increment(key, count) {
139123
if (!key || typeof key !== 'string') {
140124
throw new Error('Key must be provided and must be a string.')

test/tsd.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -836,18 +836,6 @@ function testHiveStores() {
836836
promiseJSONValueOrNull = Backendless.Hive(str).ListStore(str).get(num);
837837
promiseListOfJSONValue = Backendless.Hive(str).ListStore(str).get(num, num);
838838

839-
promiseNumber = Backendless.Hive(str).ListStore(str).set([str, str]);
840-
promiseNumber = Backendless.Hive(str).ListStore(str).set([num, str]);
841-
promiseNumber = Backendless.Hive(str).ListStore(str).set([bool, str]);
842-
promiseNumber = Backendless.Hive(str).ListStore(str).set([obj, str]);
843-
promiseNumber = Backendless.Hive(str).ListStore(str).set([strArr, str]);
844-
845-
promiseVoid = Backendless.Hive(str).ListStore(str).set(str, num);
846-
promiseVoid = Backendless.Hive(str).ListStore(str).set(num, num);
847-
promiseVoid = Backendless.Hive(str).ListStore(str).set(bool, num);
848-
promiseVoid = Backendless.Hive(str).ListStore(str).set(obj, num);
849-
promiseVoid = Backendless.Hive(str).ListStore(str).set(strArr, num);
850-
851839
promiseNumber = Backendless.Hive(str).ListStore(str).insertBefore(str, str);
852840
promiseNumber = Backendless.Hive(str).ListStore(str).insertBefore(num, num);
853841
promiseNumber = Backendless.Hive(str).ListStore(str).insertBefore(bool, bool);
@@ -956,8 +944,6 @@ function testHiveStores() {
956944

957945
promiseBoolean = Backendless.Hive(str).MapStore(str).setWithOverwrite(str, str, bool);
958946

959-
promiseNumber = Backendless.Hive(str).MapStore(str).add(obj);
960-
961947
promiseNumber = Backendless.Hive(str).MapStore(str).increment(str);
962948
promiseNumber = Backendless.Hive(str).MapStore(str).increment(str, num);
963949

test/unit/specs/hive/list.js

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -534,146 +534,6 @@ describe('Hive - List Store', function() {
534534
})
535535
})
536536

537-
describe('Set', async () => {
538-
it('success', async () => {
539-
const composeRequest = async value => {
540-
const request = prepareMockRequest(fakeResult)
541-
542-
const result = await store.set(value)
543-
544-
const payload = {
545-
method: 'PUT',
546-
path : `${APP_PATH}/hive/${hiveName}/list/${storeKey}`,
547-
body : value
548-
}
549-
550-
return { request, result, payload }
551-
}
552-
553-
const request1 = await composeRequest(['string'])
554-
const request2 = await composeRequest([''])
555-
const request3 = await composeRequest([false])
556-
const request4 = await composeRequest([true])
557-
const request5 = await composeRequest([[]])
558-
const request6 = await composeRequest([123])
559-
const request7 = await composeRequest([{ a: 1 }])
560-
561-
expect(request1.request).to.deep.include(request1.payload)
562-
expect(request2.request).to.deep.include(request2.payload)
563-
expect(request3.request).to.deep.include(request3.payload)
564-
expect(request4.request).to.deep.include(request4.payload)
565-
expect(request5.request).to.deep.include(request5.payload)
566-
expect(request6.request).to.deep.include(request6.payload)
567-
expect(request7.request).to.deep.include(request7.payload)
568-
569-
expect(request1.result).to.be.eql(fakeResult)
570-
expect(request2.result).to.be.eql(fakeResult)
571-
expect(request3.result).to.be.eql(fakeResult)
572-
expect(request4.result).to.be.eql(fakeResult)
573-
expect(request5.result).to.be.eql(fakeResult)
574-
expect(request6.result).to.be.eql(fakeResult)
575-
expect(request7.result).to.be.eql(fakeResult)
576-
})
577-
578-
it('success values with index', async () => {
579-
const composeRequest = async value => {
580-
const request = prepareMockRequest(fakeResult)
581-
582-
const result = await store.set(value, 0)
583-
584-
const payload = {
585-
method: 'PUT',
586-
path : `${APP_PATH}/hive/${hiveName}/list/${storeKey}/0`,
587-
body : {
588-
value: value
589-
}
590-
}
591-
592-
return { request, result, payload }
593-
}
594-
595-
const request1 = await composeRequest('string')
596-
const request2 = await composeRequest('')
597-
const request3 = await composeRequest(false)
598-
const request4 = await composeRequest(true)
599-
const request5 = await composeRequest([])
600-
const request6 = await composeRequest(123)
601-
const request7 = await composeRequest(0)
602-
const request8 = await composeRequest({ a: 1 })
603-
604-
expect(request1.request).to.deep.include(request1.payload)
605-
expect(request2.request).to.deep.include(request2.payload)
606-
expect(request3.request).to.deep.include(request3.payload)
607-
expect(request4.request).to.deep.include(request4.payload)
608-
expect(request5.request).to.deep.include(request5.payload)
609-
expect(request6.request).to.deep.include(request6.payload)
610-
expect(request7.request).to.deep.include(request7.payload)
611-
expect(request8.request).to.deep.include(request8.payload)
612-
613-
expect(request1.result).to.be.eql(fakeResult)
614-
expect(request2.result).to.be.eql(fakeResult)
615-
expect(request3.result).to.be.eql(fakeResult)
616-
expect(request4.result).to.be.eql(fakeResult)
617-
expect(request5.result).to.be.eql(fakeResult)
618-
expect(request6.result).to.be.eql(fakeResult)
619-
expect(request7.result).to.be.eql(fakeResult)
620-
expect(request8.result).to.be.eql(fakeResult)
621-
})
622-
623-
it('fails with invalid value', async () => {
624-
store = Backendless.Hive(hiveName).ListStore(storeKey)
625-
626-
const errorMsg = 'Value must be provided and must be a list of valid JSON items.'
627-
628-
await expect(() => store.set(undefined)).to.throw(errorMsg)
629-
await expect(() => store.set(null)).to.throw(errorMsg)
630-
await expect(() => store.set([])).to.throw(errorMsg)
631-
await expect(() => store.set('string')).to.throw(errorMsg)
632-
await expect(() => store.set('')).to.throw(errorMsg)
633-
await expect(() => store.set(0)).to.throw(errorMsg)
634-
await expect(() => store.set(false)).to.throw(errorMsg)
635-
await expect(() => store.set('')).to.throw(errorMsg)
636-
await expect(() => store.set(true)).to.throw(errorMsg)
637-
await expect(() => store.set(123)).to.throw(errorMsg)
638-
await expect(() => store.set(() => undefined)).to.throw(errorMsg)
639-
await expect(() => store.set({})).to.throw(errorMsg)
640-
await expect(() => store.set(Symbol('id'))).to.throw(errorMsg)
641-
await expect(() => store.set(10n)).to.throw(errorMsg)
642-
await expect(() => store.set([10n])).to.throw(errorMsg)
643-
})
644-
645-
it('fails with index', async () => {
646-
store = Backendless.Hive(hiveName).ListStore(storeKey)
647-
648-
const errorMsg = 'Value must be provided and must be one of types: string, number, boolean, object, array.'
649-
650-
await expect(() => store.set(undefined, 0)).to.throw(errorMsg)
651-
await expect(() => store.set(null, 0)).to.throw(errorMsg)
652-
await expect(() => store.set(() => true, 0)).to.throw(errorMsg)
653-
await expect(() => store.set(10n, 0)).to.throw(errorMsg)
654-
await expect(() => store.set(Symbol('id'), 0)).to.throw(errorMsg)
655-
await expect(() => store.set([10n], 0)).to.throw(errorMsg)
656-
})
657-
658-
it('fails with invalid index', async () => {
659-
store = Backendless.Hive(hiveName).ListStore(storeKey)
660-
661-
const errorMsg = 'Index must be a number.'
662-
663-
await expect(() => store.set('v', null)).to.throw(errorMsg)
664-
await expect(() => store.set('v', NaN)).to.throw(errorMsg)
665-
await expect(() => store.set('v', false)).to.throw(errorMsg)
666-
await expect(() => store.set('v', true)).to.throw(errorMsg)
667-
await expect(() => store.set('v', '')).to.throw(errorMsg)
668-
await expect(() => store.set('v', 'qwe')).to.throw(errorMsg)
669-
await expect(() => store.set('v', 10n)).to.throw(errorMsg)
670-
await expect(() => store.set('v', Symbol('id'))).to.throw(errorMsg)
671-
await expect(() => store.set('v', () => undefined)).to.throw(errorMsg)
672-
await expect(() => store.set('v', {})).to.throw(errorMsg)
673-
await expect(() => store.set('v', [])).to.throw(errorMsg)
674-
})
675-
})
676-
677537
describe('Length', async () => {
678538
it('success', async () => {
679539
const request = prepareMockRequest(fakeResult)

test/unit/specs/hive/map.js

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -875,41 +875,6 @@ describe('Hive - Map Store', function() {
875875
})
876876
})
877877

878-
describe('Add', async () => {
879-
it('success', async () => {
880-
const request = prepareMockRequest(fakeResult)
881-
882-
const result = await store.add({ foo: 123 })
883-
884-
expect(request).to.deep.include({
885-
method: 'PUT',
886-
path : `${APP_PATH}/hive/${hiveName}/map/${storeKey}/add`,
887-
})
888-
889-
expect(result).to.be.eql(fakeResult)
890-
})
891-
892-
it('fails when payload object is invalid', async () => {
893-
const errorMsg = 'Payload must be an object.'
894-
895-
await expect(() => store.add(null)).to.throw(errorMsg)
896-
await expect(() => store.add(NaN)).to.throw(errorMsg)
897-
await expect(() => store.add(false)).to.throw(errorMsg)
898-
await expect(() => store.add(true)).to.throw(errorMsg)
899-
await expect(() => store.add(0)).to.throw(errorMsg)
900-
await expect(() => store.add(123)).to.throw(errorMsg)
901-
await expect(() => store.add(() => undefined)).to.throw(errorMsg)
902-
await expect(() => store.add('')).to.throw(errorMsg)
903-
await expect(() => store.add('foo')).to.throw(errorMsg)
904-
})
905-
906-
it('fails when payload object ha invalid argument', async () => {
907-
const errorMsg = 'Provided object must have at least 1 key.'
908-
909-
await expect(() => store.add({})).to.throw(errorMsg)
910-
})
911-
})
912-
913878
describe('Increment', async () => {
914879
it('success', async () => {
915880
const request = prepareMockRequest(fakeResult)

0 commit comments

Comments
 (0)