• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { paramMock } from "../utils"
17
18export function mockDistributedData() {
19  const SchemaClass = class Schema {
20    constructor() {
21      console.warn('Schema.constructor interface mocked in the Previewer. How this interface works on the' +
22        ' Previewer may be different from that on a real device.');
23      this.toJsonString = function (...args) {
24        console.warn("Schema.toJsonString interface mocked in the Previewer. How this interface works" +
25          " on the Previewer may be different from that on a real device.")
26        return paramMock.paramStringMock;
27      }
28    }
29  };
30
31  const FieldNodeClass = class FieldNode {
32    constructor(...args) {
33      console.warn('FieldNode.constructor interface mocked in the Previewer. How this interface works on the' +
34        ' Previewer may be different from that on a real device.');
35
36      this.appendChild = function (...args) {
37        console.warn("FieldNode.appendChild interface mocked in the Previewer. How this interface works" +
38          " on the Previewer may be different from that on a real device.")
39        return paramMock.paramBooleanMock;
40      };
41
42      this.toJson = function (...args) {
43        console.warn("FieldNode.toJson interface mocked in the Previewer. How this interface works" +
44          " on the Previewer may be different from that on a real device.")
45        return paramMock.paramStringMock;
46      };
47    }
48  };
49
50  const QueryClass = class Query {
51    constructor() {
52      console.warn('Query.constructor interface mocked in the Previewer. How this interface works on the' +
53        ' Previewer may be different from that on a real device.');
54      this.reset = function (...args) {
55        console.warn("Query.reset interface mocked in the Previewer. How this interface works" +
56          " on the Previewer may be different from that on a real device.")
57        return QueryClass;
58      };
59
60      this.equalTo = function (...args) {
61        console.warn("Query.equalTo interface mocked in the Previewer. How this interface works" +
62          " on the Previewer may be different from that on a real device.")
63        return QueryClass;
64      };
65
66      this.notEqualTo = function (...args) {
67        console.warn("Query.notEqualTo interface mocked in the Previewer. How this interface works" +
68          " on the Previewer may be different from that on a real device.")
69        return QueryClass;
70      };
71
72      this.greaterThan = function (...args) {
73        console.warn("Query.greaterThan interface mocked in the Previewer. How this interface works" +
74          " on the Previewer may be different from that on a real device.")
75        return QueryClass;
76      };
77
78      this.lessThan = function (...args) {
79        console.warn("Query.lessThan interface mocked in the Previewer. How this interface works" +
80          " on the Previewer may be different from that on a real device.")
81        return QueryClass;
82      };
83
84      this.greaterThanOrEqualTo = function (...args) {
85        console.warn("Query.greaterThanOrEqualTo interface mocked in the Previewer. How this interface works" +
86          " on the Previewer may be different from that on a real device.")
87        return QueryClass;
88      };
89
90      this.lessThanOrEqualTo = function (...args) {
91        console.warn("Query.lessThanOrEqualTo interface mocked in the Previewer. How this interface works" +
92          " on the Previewer may be different from that on a real device.")
93        return QueryClass;
94      };
95
96      this.isNull = function (...args) {
97        console.warn("Query.isNull interface mocked in the Previewer. How this interface works" +
98          " on the Previewer may be different from that on a real device.")
99        return QueryClass;
100      };
101
102      this.inNumber = function (...args) {
103        console.warn("Query.inNumber interface mocked in the Previewer. How this interface works" +
104          " on the Previewer may be different from that on a real device.")
105        return QueryClass;
106      };
107
108      this.inString = function (...args) {
109        console.warn("Query.inString interface mocked in the Previewer. How this interface works" +
110          " on the Previewer may be different from that on a real device.")
111        return QueryClass;
112      };
113
114      this.notInNumber = function (...args) {
115        console.warn("Query.notInNumber interface mocked in the Previewer. How this interface works" +
116          " on the Previewer may be different from that on a real device.")
117        return QueryClass;
118      };
119
120      this.notInString = function (...args) {
121        console.warn("Query.notInString interface mocked in the Previewer. How this interface works" +
122          " on the Previewer may be different from that on a real device.")
123        return QueryClass;
124      };
125
126      this.like = function (...args) {
127        console.warn("Query.like interface mocked in the Previewer. How this interface works" +
128          " on the Previewer may be different from that on a real device.")
129        return QueryClass;
130      };
131
132      this.unlike = function (...args) {
133        console.warn("Query.unlike interface mocked in the Previewer. How this interface works" +
134          " on the Previewer may be different from that on a real device.")
135        return QueryClass;
136      };
137
138      this.and = function (...args) {
139        console.warn("Query.and interface mocked in the Previewer. How this interface works" +
140          " on the Previewer may be different from that on a real device.")
141        return QueryClass;
142      };
143
144      this.or = function (...args) {
145        console.warn("Query.or interface mocked in the Previewer. How this interface works" +
146          " on the Previewer may be different from that on a real device.")
147        return QueryClass;
148      };
149
150      this.orderByAsc = function (...args) {
151        console.warn("Query.orderByAsc interface mocked in the Previewer. How this interface works" +
152          " on the Previewer may be different from that on a real device.")
153        return QueryClass;
154      };
155
156      this.orderByDesc = function (...args) {
157        console.warn("Query.orderByDesc interface mocked in the Previewer. How this interface works" +
158          " on the Previewer may be different from that on a real device.")
159        return QueryClass;
160      };
161
162      this.limit = function (...args) {
163        console.warn("Query.limit interface mocked in the Previewer. How this interface works" +
164          " on the Previewer may be different from that on a real device.")
165        return QueryClass;
166      };
167
168      this.isNotNull = function (...args) {
169        console.warn("Query.isNotNull interface mocked in the Previewer. How this interface works" +
170          " on the Previewer may be different from that on a real device.")
171        return QueryClass;
172      };
173
174      this.beginGroup = function (...args) {
175        console.warn("Query.beginGroup interface mocked in the Previewer. How this interface works" +
176          " on the Previewer may be different from that on a real device.")
177        return QueryClass;
178      };
179
180      this.endGroup = function (...args) {
181        console.warn("Query.endGroup interface mocked in the Previewer. How this interface works" +
182          " on the Previewer may be different from that on a real device.")
183        return QueryClass;
184      };
185
186      this.prefixKey = function (...args) {
187        console.warn("Query.prefixKey interface mocked in the Previewer. How this interface works" +
188          " on the Previewer may be different from that on a real device.")
189        return QueryClass;
190      };
191
192      this.setSuggestIndex = function (...args) {
193        console.warn("Query.setSuggestIndex interface mocked in the Previewer. How this interface works" +
194          " on the Previewer may be different from that on a real device.")
195        return QueryClass;
196      };
197
198      this.deviceId = function (...args) {
199        console.warn("Query.deviceId interface mocked in the Previewer. How this interface works" +
200          " on the Previewer may be different from that on a real device.")
201        return QueryClass;
202      };
203
204      this.getSqlLike = function (...args) {
205        console.warn("Query.getSqlLike interface mocked in the Previewer. How this interface works" +
206          " on the Previewer may be different from that on a real device.")
207        return QueryClass;
208      };
209    }
210  };
211
212  const distributedDataMock = {
213    Schema: SchemaClass,
214    Query: QueryClass,
215    FieldNode: FieldNodeClass,
216
217    KVStoreType: {
218      DEVICE_COLLABORATION: 0,
219      SINGLE_VERSION: 1,
220      MULTI_VERSION: 2,
221    },
222
223    SecurityLevel: {
224      NO_LEVEL: 0,
225      S0: 1,
226      S1: 2,
227      S2: 3,
228      S3: 5,
229      S4: 6,
230    },
231
232    SyncMode: {
233      PULL_ONLY: 0,
234      PUSH_ONLY: 1,
235      PUSH_PULL: 2,
236    },
237
238    SubscribeType: {
239      SUBSCRIBE_TYPE_LOCAL: 0,
240      SUBSCRIBE_TYPE_REMOTE: 1,
241      SUBSCRIBE_TYPE_ALL: 2,
242    },
243
244    createKVManager: function (...args) {
245      console.warn("distributedData.createKVManager interface mocked in the Previewer." +
246        " How this interface works on the Previewer may be different from that on a real device.")
247      const len = args.length
248      if (len > 0 && typeof args[len - 1] === 'function') {
249        args[len - 1].call(this, paramMock.businessErrorMock, KVManager);
250      } else {
251        return new Promise((resolve, reject) => {
252          resolve(KVManager);
253        })
254      }
255    }
256  };
257
258  const userTypeMock = {
259    SAME_USER_ID: "[PC Preview] unknown SAME_USER_ID"
260  };
261  const userInfoMock = {
262    userId: "[PC Preview] unknown userId",
263    userType: "[PC Preview] unknown userType"
264  };
265  const kvManagerConfigMock = {
266    userInfo: "[PC Preview] unknown userInfo",
267    bundleName: "[PC Preview] unknown bundleName"
268  };
269  const constantsMock = {
270    MAX_KEY_LENGTH: "[PC Preview] unknown MAX_KEY_LENGTH",
271    MAX_VALUE_LENGTH: "[PC Preview] unknown MAX_VALUE_LENGTH",
272    MAX_KEY_LENGTH_DEVICE: "[PC Preview] unknown MAX_KEY_LENGTH_DEVICE",
273    MAX_STORE_ID_LENGTH: "[PC Preview] unknown MAX_STORE_ID_LENGTH",
274    MAX_QUERY_LENGTH: "[PC Preview] unknown MAX_QUERY_LENGTH",
275    MAX_BATCH_SIZE: "[PC Preview] unknown MAX_BATCH_SIZE"
276  };
277  const schemaMock = {
278    root: "[PC Preview] unknown root",
279    indexes: "[PC Preview] unknown indexes",
280    mode: "[PC Preview] unknown mode",
281    skip: "[PC Preview] unknown skip"
282  };
283  const fieldnodeMock = {
284    default: "[PC Preview] unknown default",
285    nullable: "[PC Preview] unknown nullable",
286    type: "[PC Preview] unknown type"
287  };
288  const valueTypeMock = {
289    STRING: "[PC Preview] unknown STRING",
290    INTEGER: "[PC Preview] unknown INTEGER",
291    FLOAT: "[PC Preview] unknown FLOAT",
292    BYTE_ARRAY: "[PC Preview] unknown BYTE_ARRAY",
293    BOOLEAN: "[PC Preview] unknown BOOLEAN",
294    DOUBLE: "[PC Preview] unknown DOUBLE"
295  };
296  const valueMock = {
297    type: valueTypeMock.STRING,
298    value: "[PC Preview] unknown value"
299  };
300  const entryMock = {
301    key: "[PC Preview] unknown key",
302    value: valueMock
303  };
304  const changeNotificationMock = {
305    insertEntries: new Array(entryMock),
306    updateEntries: new Array(entryMock),
307    deleteEntries: new Array(entryMock),
308    deviceId: "[PC Preview] unknown deviceId"
309  };
310  const optionsMock = {
311    createIfMissing: "[PC Preview] unknown createIfMissing",
312    encrypt: "[PC Preview] unknown encrypt",
313    backup: "[PC Preview] unknown backup",
314    autoSync: "[PC Preview] unknown autoSync",
315    kvStoreType: "[PC Preview] unknown kvStoreType",
316    securityLevel: "[PC Preview] unknown securityLevel",
317    schema: "[PC Preview] unknown schema"
318  };
319
320  const KVStoreClass = class KVStore {
321    constructor() {
322      console.warn("KVStore.constructor interface mocked in the Previewer." +
323        " How this interface works on the Previewer may be different from that on a real device.")
324      this.put = function (...args) {
325        console.warn("KVStore.put interface mocked in the Previewer. How this interface works" +
326          " on the Previewer may be different from that on a real device.")
327        const len = args.length
328        if (typeof args[len - 1] === 'function') {
329          args[len - 1].call(this, paramMock.businessErrorMock);
330        } else {
331          return new Promise((resolve) => {
332            resolve()
333          })
334        }
335      };
336
337      this.delete = function (...args) {
338        console.warn("KVStore.delete interface mocked in the Previewer. How this interface works" +
339          " on the Previewer may be different from that on a real device.")
340        const len = args.length
341        if (typeof args[len - 1] === 'function') {
342          args[len - 1].call(this, paramMock.businessErrorMock)
343        } else {
344          return new Promise((resolve) => {
345            resolve()
346          })
347        }
348      };
349
350      this.setSyncRange = function (...args) {
351        console.warn("KVStore.setSyncRange interface mocked in the Previewer. How this interface works" +
352          " on the Previewer may be different from that on a real device.")
353        const len = args.length
354        if (typeof args[len - 1] === 'function') {
355          args[len - 1].call(this, paramMock.businessErrorMock)
356        } else {
357          return new Promise((resolve) => {
358            resolve()
359          })
360        }
361      };
362
363      this.on = function (...args) {
364        console.warn("KVStore.on interface mocked in the Previewer. How this interface works" +
365          " on the Previewer may be different from that on a real device.")
366        const len = args.length
367        if (typeof args[len - 1] === 'function') {
368          if (args[0] == 'dataChange') {
369            args[len - 1].call(this, paramMock.businessErrorMock, changeNotificationMock)
370          } else if (args[0] === 'syncComplete') {
371            var array = new Array([paramMock.paramStringMock, paramMock.paramNumberMock]);
372            args[len - 1].call(this, array);
373          }
374        }
375      };
376
377      this.off = function (...args) {
378        console.warn("KVStore.off interface mocked in the Previewer. How this interface works" +
379          " on the Previewer may be different from that on a real device.")
380        const len = args.length
381        if (typeof args[len - 1] === 'function') {
382          if (args[0] == 'dataChange') {
383            args[len - 1].call(this, paramMock.businessErrorMock, changeNotificationMock)
384          } else if (args[0] === 'syncComplete') {
385            var array = new Array([paramMock.paramStringMock, paramMock.paramNumberMock]);
386            args[len - 1].call(this, array);
387          }
388        }
389      };
390
391      this.putBatch = function (...args) {
392        console.warn("KVStore.putBatch interface mocked in the Previewer. How this interface works" +
393          " on the Previewer may be different from that on a real device.")
394        const len = args.length
395        if (typeof args[len - 1] === 'function') {
396          args[len - 1].call(this, paramMock.businessErrorMock)
397        } else {
398          return new Promise((resolve) => {
399            resolve()
400          })
401        }
402      };
403
404      this.deleteBatch = function (...args) {
405        console.warn("KVStore.deleteBatch interface mocked in the Previewer. How this interface works" +
406          " on the Previewer may be different from that on a real device.")
407        const len = args.length
408        if (typeof args[len - 1] === 'function') {
409          args[len - 1].call(this, paramMock.businessErrorMock)
410        } else {
411          return new Promise((resolve) => {
412            resolve()
413          })
414        }
415      };
416
417      this.startTransaction = function (...args) {
418        console.warn("KVStore.startTransaction interface mocked in the Previewer. How this interface works" +
419          " on the Previewer may be different from that on a real device.")
420        const len = args.length
421        if (typeof args[len - 1] === 'function') {
422          args[len - 1].call(this, paramMock.businessErrorMock)
423        } else {
424          return new Promise((resolve) => {
425            resolve()
426          })
427        }
428      };
429
430      this.commit = function (...args) {
431        console.warn("KVStore.commit interface mocked in the Previewer. How this interface works" +
432          " on the Previewer may be different from that on a real device.")
433        const len = args.length
434        if (typeof args[len - 1] === 'function') {
435          args[len - 1].call(this, paramMock.businessErrorMock)
436        } else {
437          return new Promise((resolve) => {
438            resolve()
439          })
440        }
441      };
442
443      this.rollback = function (...args) {
444        console.warn("KVStore.rollback interface mocked in the Previewer. How this interface works" +
445          " on the Previewer may be different from that on a real device.")
446        const len = args.length
447        if (typeof args[len - 1] === 'function') {
448          args[len - 1].call(this, paramMock.businessErrorMock)
449        } else {
450          return new Promise((resolve) => {
451            resolve()
452          })
453        }
454      };
455
456      this.enableSync = function (...args) {
457        console.warn("KVStore.enableSync interface mocked in the Previewer. How this interface works" +
458          " on the Previewer may be different from that on a real device.")
459        const len = args.length
460        if (typeof args[len - 1] === 'function') {
461          args[len - 1].call(this, paramMock.businessErrorMock)
462        } else {
463          return new Promise((resolve) => {
464            resolve()
465          })
466        }
467      };
468    }
469  };
470
471  const SingleKVStoreClass = class SingleKVStore extends KVStoreClass {
472    constructor() {
473      super();
474      console.warn("SingleKVStore.constructor interface mocked in the Previewer." +
475        " How this interface works on the Previewer may be different from that on a real device.")
476
477      this.put = function (...args) {
478        console.warn("SingleKVStore.put interface mocked in the Previewer." +
479          " How this interface works on the Previewer may be different from that on a real device.")
480        const len = args.length
481        if (len > 0 && typeof args[len - 1] === 'function') {
482          args[len - 1].call(this, paramMock.businessErrorMock);
483        } else {
484          return new Promise((resolve, reject) => {
485            resolve();
486          })
487        }
488      };
489
490      this.delete = function (...args) {
491        console.warn("SingleKVStore.delete interface mocked in the Previewer." +
492          " How this interface works on the Previewer may be different from that on a real device.")
493        const len = args.length
494        if (len > 0 && typeof args[len - 1] === 'function') {
495          args[len - 1].call(this, paramMock.businessErrorMock);
496        } else {
497          return new Promise((resolve, reject) => {
498            resolve();
499          })
500        }
501      };
502
503      this.on = function (...args) {
504        console.warn("SingleKVStore.on interface mocked in the Previewer." +
505          " How this interface works on the Previewer may be different from that on a real device.")
506        const len = args.length
507        if (typeof args[len - 1] === 'function') {
508          if (args[0] === 'dataChange') {
509            args[len - 1].call(this, changeNotificationMock);
510          } else if (args[0] === 'syncComplete') {
511            var array = new Array([paramMock.paramStringMock, paramMock.paramNumberMock]);
512            args[len - 1].call(this, array);
513          }
514        }
515      };
516
517      this.off = function (...args) {
518        console.warn("SingleKVStore.off interface mocked in the Previewer. How this interface works" +
519          " on the Previewer may be different from that on a real device.")
520        const len = args.length
521        var array = new Array([paramMock.paramStringMock, paramMock.paramNumberMock]);
522        if (typeof args[len - 1] === 'function') {
523          if (args[0] == 'syncComplete') {
524            args[len - 1].call(this, paramMock.businessErrorMock, array)
525          } else if (args[0] == 'dataChange') {
526            args[len - 1].call(this, paramMock.businessErrorMock, changeNotificationMock)
527          }
528        }
529      };
530
531      this.sync = function (...args) {
532        console.warn("SingleKVStore.sync interface mocked in the Previewer." +
533          " How this interface works on the Previewer may be different from that on a real device.")
534      };
535
536      this.get = function (...args) {
537        console.warn("SingleKVStore.get interface mocked in the Previewer. How this interface works" +
538          " on the Previewer may be different from that on a real device.")
539        const len = args.length
540        if (typeof args[len - 1] === 'function') {
541          args[len - 1].call(this, paramMock.businessErrorMock,
542            paramMock.paramBooleanMock | paramMock.paramStringMock | paramMock.paramNumberMock | paramMock.paramArrayMock)
543        } else {
544          return new Promise((resolve) => {
545            resolve(paramMock.paramBooleanMock | paramMock.paramStringMock | paramMock.paramNumberMock | paramMock.paramArrayMock)
546          })
547        }
548      };
549
550      this.getResultSet = function (...args) {
551        console.warn("SingleKVStore.getResultSet interface mocked in the Previewer. How this interface works" +
552          " on the Previewer may be different from that on a real device.")
553        const len = args.length
554        if (typeof args[len - 1] === 'function') {
555          args[len - 1].call(this, paramMock.businessErrorMock, KVStoreResultSet)
556        } else {
557          return new Promise((resolve) => {
558            resolve(KVStoreResultSet)
559          })
560        }
561      };
562
563      this.closeResultSet = function (...args) {
564        console.warn("SingleKVStore.closeResultSet interface mocked in the Previewer. How this interface works" +
565          " on the Previewer may be different from that on a real device.")
566        const len = args.length
567        if (typeof args[len - 1] === 'function') {
568          args[len - 1].call(this, paramMock.businessErrorMock)
569        } else {
570          return new Promise((resolve) => {
571            resolve()
572          })
573        }
574      };
575
576      this.getResultSize = function (...args) {
577        console.warn("SingleKVStore.getResultSize interface mocked in the Previewer. How this interface works" +
578          " on the Previewer may be different from that on a real device.")
579        const len = args.length
580        if (typeof args[len - 1] === 'function') {
581          args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
582        } else {
583          return new Promise((resolve) => {
584            resolve(paramMock.paramNumberMock)
585          })
586        }
587      };
588
589      this.getEntries = function (...args) {
590        console.warn("SingleKVStore.getEntries interface mocked in the Previewer. How this interface works" +
591          " on the Previewer may be different from that on a real device.")
592        const len = args.length
593        var array = new Array(entryMock)
594        if (typeof args[len - 1] === 'function') {
595          args[len - 1].call(this, paramMock.businessErrorMock, array)
596        } else {
597          return new Promise((resolve) => {
598            resolve(array)
599          })
600        }
601      };
602
603      this.removeDeviceData = function (...args) {
604        console.warn("SingleKVStore.removeDeviceData interface mocked in the Previewer. How this interface works" +
605          " on the Previewer may be different from that on a real device.")
606        const len = args.length
607        if (typeof args[len - 1] === 'function') {
608          args[len - 1].call(this, paramMock.businessErrorMock)
609        } else {
610          return new Promise((resolve) => {
611            resolve()
612          })
613        }
614      };
615
616      this.setSyncParam = function (...args) {
617        console.warn("SingleKVStore.setSyncParam interface mocked in the Previewer. How this interface works" +
618          " on the Previewer may be different from that on a real device.")
619        const len = args.length
620        if (typeof args[len - 1] === 'function') {
621          args[len - 1].call(this, paramMock.businessErrorMock)
622        } else {
623          return new Promise((resolve) => {
624            resolve()
625          })
626        }
627      };
628
629      this.getSecurityLevel = function (...args) {
630        console.warn("SingleKVStore.getSecurityLevel interface mocked in the Previewer. How this interface works" +
631          " on the Previewer may be different from that on a real device.")
632        const len = args.length
633        if (typeof args[len - 1] === 'function') {
634          args[len - 1].call(this, paramMock.businessErrorMock)
635        } else {
636          return new Promise((resolve) => {
637            resolve()
638          })
639        }
640      };
641    }
642  };
643
644  const DeviceKVStoreClass = class DeviceKVStore extends KVStoreClass {
645    constructor() {
646      super();
647      console.warn('DeviceKVStore.constructor interface mocked in the Previewer. How this interface works on the' +
648        ' Previewer may be different from that on a real device.');
649
650      this.get = function (...args) {
651        console.warn("DeviceKVStore.get interface mocked in the Previewer. How this interface works" +
652          " on the Previewer may be different from that on a real device.")
653        const len = args.length
654        if (typeof args[len - 1] === 'function') {
655          args[len - 1].call(this, paramMock.businessErrorMock,
656            paramMock.paramBooleanMock | paramMock.paramStringMock | paramMock.paramNumberMock | paramMock.paramArrayMock)
657        } else {
658          return new Promise((resolve) => {
659            resolve(paramMock.paramBooleanMock | paramMock.paramStringMock | paramMock.paramNumberMock | paramMock.paramArrayMock)
660          })
661        }
662      };
663
664      this.getEntries = function (...args) {
665        console.warn("DeviceKVStore.getEntries interface mocked in the Previewer. How this interface works" +
666          " on the Previewer may be different from that on a real device.")
667        const len = args.length
668        var array = new Array(entryMock)
669        if (typeof args[len - 1] === 'function') {
670          args[len - 1].call(this, paramMock.businessErrorMock, array)
671        } else {
672          return new Promise((resolve) => {
673            resolve(array)
674          })
675        }
676      };
677
678      this.getResultSet = function (...args) {
679        console.warn("DeviceKVStore.getResultSet interface mocked in the Previewer. How this interface works" +
680          " on the Previewer may be different from that on a real device.")
681        const len = args.length
682        if (typeof args[len - 1] === 'function') {
683          args[len - 1].call(this, paramMock.businessErrorMock, KVStoreResultSet)
684        } else {
685          return new Promise((resolve) => {
686            resolve(KVStoreResultSet)
687          })
688        }
689      };
690
691      this.closeResultSet = function (...args) {
692        console.warn("DeviceKVStore.closeResultSet interface mocked in the Previewer. How this interface works" +
693          " on the Previewer may be different from that on a real device.")
694        const len = args.length
695        if (typeof args[len - 1] === 'function') {
696          args[len - 1].call(this, paramMock.businessErrorMock)
697        } else {
698          return new Promise((resolve) => {
699            resolve()
700          })
701        }
702      };
703
704      this.getResultSize = function (...args) {
705        console.warn("DeviceKVStore.getResultSize interface mocked in the Previewer. How this interface works" +
706          " on the Previewer may be different from that on a real device.")
707        const len = args.length
708        if (typeof args[len - 1] === 'function') {
709          args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
710        } else {
711          return new Promise((resolve) => {
712            resolve(paramMock.paramNumberMock)
713          })
714        }
715      };
716
717      this.removeDeviceData = function (...args) {
718        console.warn("DeviceKVStore.removeDeviceData interface mocked in the Previewer. How this interface works" +
719          " on the Previewer may be different from that on a real device.")
720        const len = args.length
721        if (typeof args[len - 1] === 'function') {
722          args[len - 1].call(this, paramMock.businessErrorMock)
723        } else {
724          return new Promise((resolve) => {
725            resolve()
726          })
727        }
728      };
729
730      this.sync = function (...args) {
731        console.warn("DeviceKVStore.sync interface mocked in the Previewer. How this interface works" +
732          " on the Previewer may be different from that on a real device.")
733      };
734
735      this.on = function (...args) {
736        console.warn("DeviceKVStore.on interface mocked in the Previewer. How this interface works" +
737          " on the Previewer may be different from that on a real device.")
738        const len = args.length
739        var array = new Array([paramMock.paramStringMock, paramMock.paramNumberMock]);
740        if (typeof args[len - 1] === 'function') {
741          if (args[0] == 'syncComplete') {
742            args[len - 1].call(this, paramMock.businessErrorMock, array)
743          } else if (args[0] == 'dataChange') {
744            args[len - 1].call(this, paramMock.businessErrorMock, changeNotificationMock)
745          }
746        }
747      };
748
749      this.off = function (...args) {
750        console.warn("DeviceKVStore.off interface mocked in the Previewer. How this interface works" +
751          " on the Previewer may be different from that on a real device.")
752        const len = args.length
753        var array = new Array([paramMock.paramStringMock, paramMock.paramNumberMock]);
754        if (typeof args[len - 1] === 'function') {
755          if (args[0] == 'syncComplete') {
756            args[len - 1].call(this, paramMock.businessErrorMock, array)
757          } else if (args[0] == 'dataChange') {
758            args[len - 1].call(this, paramMock.businessErrorMock, changeNotificationMock)
759          }
760        }
761      };
762    }
763  };
764
765  const KVManager = {
766    getKVStore: function (...args) {
767      console.warn("KVManager.getKVStore interface mocked in the Previewer." +
768        " How this interface works on the Previewer may be different from that on a real device.")
769      const len = args.length
770      var singleKVStoreClass = new SingleKVStoreClass
771      var deviceKVStoreClass = new DeviceKVStoreClass
772      if (len > 0 && typeof args[len - 1] === 'function') {
773        console.warn("getKVStore kvStoreType = " + args[1].kvStoreType);
774        if (args[1].kvStoreType == distributedDataMock.KVStoreType.DEVICE_COLLABORATION) {
775          args[len - 1].call(this, paramMock.businessErrorMock, deviceKVStoreClass);
776        } else if (args[1].kvStoreType == distributedDataMock.KVStoreType.SINGLE_VERSION) {
777          args[len - 1].call(this, paramMock.businessErrorMock, singleKVStoreClass);
778        }
779      } else {
780        return new Promise((resolve) => {
781          if (args[1].kvStoreType == distributedDataMock.KVStoreType.DEVICE_COLLABORATION) {
782            resolve(deviceKVStoreClass);
783          } else if (args[1].kvStoreType == distributedDataMock.KVStoreType.SINGLE_VERSION) {
784            resolve(singleKVStoreClass);
785          }
786        })
787      }
788    },
789
790    closeKVStore: function (...args) {
791      console.warn("KVManager.closeKVStore interface mocked in the Previewer. How this interface works" +
792        " on the Previewer may be different from that on a real device.")
793      const len = args.length
794      if (typeof args[len - 1] === 'function') {
795        args[len - 1].call(this, paramMock.businessErrorMock)
796      } else {
797        return new Promise((resolve) => {
798          resolve()
799        })
800      }
801    },
802
803    deleteKVStore: function (...args) {
804      console.warn("KVManager.deleteKVStore interface mocked in the Previewer. How this interface works" +
805        " on the Previewer may be different from that on a real device.")
806      const len = args.length
807      if (typeof args[len - 1] === 'function') {
808        args[len - 1].call(this, paramMock.businessErrorMock)
809      } else {
810        return new Promise((resolve) => {
811          resolve()
812        })
813      }
814    },
815
816    getAllKVStoreId: function (...args) {
817      console.warn("KVManager.getAllKVStoreId interface mocked in the Previewer. How this interface works" +
818        " on the Previewer may be different from that on a real device.")
819      const len = args.length
820      var array = new Array(paramMock.paramStringMock)
821      if (typeof args[len - 1] === 'function') {
822        args[len - 1].call(this, paramMock.businessErrorMock, array)
823      } else {
824        return new Promise((resolve) => {
825          resolve(array)
826        })
827      }
828    },
829
830    on: function (...args) {
831      console.warn("KVManager.on interface mocked in the Previewer. How this interface works" +
832        " on the Previewer may be different from that on a real device.")
833      const len = args.length
834      if (typeof args[len - 1] === 'function') {
835        if (args[0] == 'distributedDataServiceDie') {
836          args[len - 1].call(this, paramMock.businessErrorMock)
837        }
838      }
839    },
840
841    off: function (...args) {
842      console.warn("KVManager.off interface mocked in the Previewer. How this interface works" +
843        " on the Previewer may be different from that on a real device.")
844      const len = args.length
845      if (typeof args[len - 1] === 'function') {
846        if (args[0] == 'distributedDataServiceDie') {
847          args[len - 1].call(this, paramMock.businessErrorMock)
848        }
849      }
850    }
851  };
852
853  const KVStoreResultSet = {
854    getCount: function (...args) {
855      console.warn("KVStoreResultSet.getCount interface mocked in the Previewer. How this interface works" +
856        " on the Previewer may be different from that on a real device.")
857      return paramMock.paramNumberMock;
858    },
859
860    getPosition: function (...args) {
861      console.warn("KVStoreResultSet.getPosition interface mocked in the Previewer. How this interface works" +
862        " on the Previewer may be different from that on a real device.")
863      return paramMock.paramNumberMock;
864    },
865
866    moveToFirst: function (...args) {
867      console.warn("KVStoreResultSet.moveToFirst interface mocked in the Previewer. How this interface works" +
868        " on the Previewer may be different from that on a real device.")
869      return paramMock.paramBooleanMock;
870    },
871
872    moveToLast: function (...args) {
873      console.warn("KVStoreResultSet.moveToLast interface mocked in the Previewer. How this interface works" +
874        " on the Previewer may be different from that on a real device.")
875      return paramMock.paramBooleanMock;
876    },
877
878    moveToNext: function (...args) {
879      console.warn("KVStoreResultSet.moveToNext interface mocked in the Previewer. How this interface works" +
880        " on the Previewer may be different from that on a real device.")
881      return paramMock.paramBooleanMock;
882    },
883
884    moveToPrevious: function (...args) {
885      console.warn("KVStoreResultSet.moveToPrevious interface mocked in the Previewer. How this interface works" +
886        " on the Previewer may be different from that on a real device.")
887      return paramMock.paramBooleanMock;
888    },
889    move: function (...args) {
890      console.warn("KVStoreResultSet.move interface mocked in the Previewer. How this interface works" +
891        " on the Previewer may be different from that on a real device.")
892      return paramMock.paramBooleanMock;
893    },
894
895    moveToPosition: function (...args) {
896      console.warn("KVStoreResultSet.moveToPosition interface mocked in the Previewer. How this interface works" +
897        " on the Previewer may be different from that on a real device.")
898      return paramMock.paramBooleanMock;
899    },
900
901    isFirst: function (...args) {
902      console.warn("KVStoreResultSet.isFirst interface mocked in the Previewer. How this interface works" +
903        " on the Previewer may be different from that on a real device.")
904      return paramMock.paramBooleanMock;
905    },
906
907    isLast: function (...args) {
908      console.warn("KVStoreResultSet.isLast interface mocked in the Previewer. How this interface works" +
909        " on the Previewer may be different from that on a real device.")
910      return paramMock.paramBooleanMock;
911    },
912    isBeforeFirst: function (...args) {
913      console.warn("KVStoreResultSet.isBeforeFirst interface mocked in the Previewer. How this interface works" +
914        " on the Previewer may be different from that on a real device.")
915      return paramMock.paramBooleanMock;
916    },
917
918    isAfterLast: function (...args) {
919      console.warn("KVStoreResultSet.isAfterLast interface mocked in the Previewer. How this interface works" +
920        " on the Previewer may be different from that on a real device.")
921      return paramMock.paramBooleanMock;
922    },
923
924    getEntry: function (...args) {
925      console.warn("KVStoreResultSet.getEntry interface mocked in the Previewer. How this interface works" +
926        " on the Previewer may be different from that on a real device.")
927      return entryMock;
928    }
929  };
930
931  return distributedDataMock;
932}