1/*
2 * Copyright (c) 2023 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
16let relationalStore = requireNapi('data.relationalStore');
17let rpc = requireNapi('rpc');
18
19const TAG = 'cloudExtension';
20const INVALID_STATE = -1;
21const INVALID_STR = '';
22const MAX_SIZE = 4 * 1024 * 1024 * 1024 - 1;
23
24export let cloudExtension;
25(function (a) {
26    let f;
27    (function (f) {
28        f[f["NULL"] = 0] = "NULL";
29        f[f["NUMBER"] = 1] = "NUMBER";
30        f[f["REAL"] = 2] = "REAL";
31        f[f["TEXT"] = 3] = "TEXT";
32        f[f["BOOL"] = 4] = "BOOL";
33        f[f["BLOB"] = 5] = "BLOB";
34        f[f["ASSET"] = 6] = "ASSET";
35        f[f["ASSETS"] = 7] = "ASSETS";
36    })(f = a.FieldType || (a.FieldType = {}));
37    let g;
38    (function (g) {
39        g[g["SUCCESS"] = 0] = "SUCCESS";
40        g[g["UNKNOWN_ERROR"] = 1] = "UNKNOWN_ERROR";
41        g[g["NETWORK_ERROR"] = 2] = "NETWORK_ERROR";
42        g[g["CLOUD_DISABLED"] = 3] = "CLOUD_DISABLED";
43        g[g["LOCKED_BY_OTHERS"] = 4] = "LOCKED_BY_OTHERS";
44        g[g["RECORD_LIMIT_EXCEEDED"] = 5] = "RECORD_LIMIT_EXCEEDED";
45        g[g["NO_SPACE_FOR_ASSET"] = 6] = "NO_SPACE_FOR_ASSET";
46    })(g = a.ErrorCode || (a.ErrorCode = {}));
47    let h;
48    (function (h) {
49        h[h["ConnectShareCenter"] = 0] = "ConnectShareCenter";
50        h[h["ConnectAssetLoader"] = 1] = "ConnectAssetLoader";
51        h[h["ConnectDatabase"] = 2] = "ConnectDatabase";
52        h[h["GetAppBriefInfo"] = 3] = "GetAppBriefInfo";
53        h[h["GetServiceInfo"] = 4] = "GetServiceInfo";
54        h[h["GetAppSchema"] = 5] = "GetAppSchema";
55        h[h["Subscribe"] = 6] = "Subscribe";
56        h[h["Unsubscribe"] = 7] = "Unsubscribe";
57    })(h || (h = {}));
58    let i;
59    (function (i) {
60        i[i["Share"] = 0] = "Share";
61        i[i["Unshare"] = 1] = "Unshare";
62        i[i["Exit"] = 2] = "Exit";
63        i[i["ChangePrivilege"] = 3] = "ChangePrivilege";
64        i[i["QueryParticipants"] = 4] = "QueryParticipants";
65        i[i["QueryParticipantsByInvitation"] = 5] = "QueryParticipantsByInvitation";
66        i[i["ConfirmInvitation"] = 6] = "ConfirmInvitation";
67        i[i["ChangeConfirmation"] = 7] = "ChangeConfirmation";
68    })(i || (i = {}));
69    let j;
70    (function (j) {
71        j[j["GenerateIds"] = 0] = "GenerateIds";
72        j[j["Insert"] = 1] = "Insert";
73        j[j["Update"] = 2] = "Update";
74        j[j["Delete"] = 3] = "Delete";
75        j[j["Query"] = 4] = "Query";
76        j[j["Lock"] = 5] = "Lock";
77        j[j["Unlock"] = 6] = "Unlock";
78        j[j["Heartbeat"] = 7] = "Heartbeat";
79    })(j || (j = {}));
80    let k;
81    (function (k) {
82        k[k["Download"] = 0] = "Download";
83        k[k["Upload"] = 1] = "Upload";
84    })(k || (k = {}));
85
86    class l extends rpc.RemoteObject {
87        constructor(q, r) {
88            super(q);
89            this.cloudService = r;
90        }
91
92        async onRemoteMessageRequest(s, t, u, v) {
93            v.setWaitTime(1000);
94            let w = this.getDescriptor();
95            switch (s) {
96                case h.GetServiceInfo:
97                    let x = await this.cloudService.getServiceInfo();
98                    this.marshallingCloudInfo(u, x);
99                    return true;
100                case h.GetAppBriefInfo:
101                    let y = await this.cloudService.getAppBriefInfo();
102                    this.marshallingAppBriefInfo(u, y);
103                    return true;
104                case h.GetAppSchema:
105                    let z = t.readString();
106                    let a1 = await this.cloudService.getAppSchema(z);
107                    u.writeInt(a1.code);
108                    if (a1.code === a.ErrorCode.SUCCESS) {
109                        this.marshallingAppSchema(u, a1.value);
110                    }
111                    return true;
112                case h.Subscribe:
113                    let b1 = t.readLong();
114                    let c1 = this.unMarshallingSubInfo(t);
115                    let d1 = await this.cloudService.subscribe(c1, b1);
116                    u.writeInt(d1.code);
117                    if (d1.code === a.ErrorCode.SUCCESS) {
118                        this.marshallingSubscribeInfo(u, d1.value);
119                    }
120                    return true;
121                case h.Unsubscribe:
122                    let e1 = this.unMarshallingUnSubInfo(t);
123                    let f1 = await this.cloudService.unsubscribe(e1);
124                    u.writeInt(f1 > 0 ? a.ErrorCode.SUCCESS : a.ErrorCode.UNKNOWN_ERROR);
125                    return true;
126                case h.ConnectDatabase:
127                    let g1 = t.readString();
128                    let h1 = this.unMarshallingDatabase(t);
129                    let i1 = await this.cloudService.connectDB(g1, h1);
130                    u.writeRemoteObject(i1);
131                    return true;
132                case h.ConnectAssetLoader:
133                    let j1 = t.readString();
134                    let k1 = this.unMarshallingDatabase(t);
135                    let l1 = await this.cloudService.connectAssetLoader(j1, k1);
136                    u.writeRemoteObject(l1);
137                    return true;
138                case h.ConnectShareCenter:
139                    let m1 = t.readInt();
140                    let n1 = t.readString();
141                    let o1 = await this.cloudService.connectShareCenter(m1, n1);
142                    if (o1 == null) {
143                        return false;
144                    }
145                    u.writeRemoteObject(o1);
146                    return true;
147                default:
148                    return false;
149            }
150        }
151
152        marshallingCloudInfo(u, p1) {
153            u.writeBoolean(p1.enableCloud);
154            u.writeString(p1.id);
155            u.writeLong(p1.totalSpace);
156            u.writeLong(p1.remainingSpace);
157            u.writeInt(p1.user);
158        }
159
160        marshallingAppBriefInfo(u, q1) {
161            let r1 = Object.keys(q1);
162            u.writeInt(r1.length);
163            r1.forEach(s1 => {
164                u.writeString(s1);
165                let t1 = q1[s1];
166                u.writeString(t1.appId);
167                u.writeString(t1.bundleName);
168                u.writeInt(t1.cloudSwitch ? 1 : 0);
169                u.writeInt(t1.instanceId);
170            });
171        }
172
173        marshallingAppSchema(u, u1) {
174            u.writeInt(u1.version);
175            u.writeString(u1.bundleName);
176            u.writeInt(u1.databases.length);
177            u1.databases.forEach((h1) => {
178                u.writeString(h1.alias);
179                u.writeString(h1.name);
180                u.writeInt(h1.tables.length);
181                h1.tables.forEach((v1) => {
182                    u.writeString(v1.alias);
183                    u.writeString(v1.name);
184                    u.writeInt(v1.fields.length);
185                    v1.fields.forEach((w1) => {
186                        u.writeString(w1.alias);
187                        u.writeString(w1.colName);
188                        u.writeInt(w1.type);
189                        u.writeBoolean(w1.primary);
190                        u.writeBoolean(w1.nullable);
191                    });
192                });
193            });
194        }
195
196        marshallingSubscribeInfo(u, x1) {
197            u.writeLong(x1.expirationTime);
198            let r1 = Object.keys(x1.subscribe);
199            u.writeInt(r1.length);
200            r1.forEach(s1 => {
201                u.writeString(s1);
202                let y1 = x1.subscribe[s1];
203                u.writeInt(y1.length);
204                y1.forEach(h1 => {
205                    u.writeString(h1.databaseAlias);
206                    u.writeString(h1.id);
207                });
208            });
209        }
210
211        unMarshallingSubInfo(t) {
212            let z = t.readString();
213            let c1 = {};
214            let z1 = t.readInt();
215            c1[z] = [];
216            if (z1 < 0 || z1 > MAX_SIZE) {
217                return c1;
218            }
219            for (let a2 = 0; a2 < z1; a2++) {
220                c1[z].push(this.unMarshallingDatabase(t));
221            }
222            return c1;
223        }
224
225        unMarshallingUnSubInfo(t) {
226            let e1 = {};
227            let b2 = t.readInt();
228            if (b2 < 0 || b2 > MAX_SIZE) {
229                return e1;
230            }
231            for (let c2 = 0; c2 < b2; c2++) {
232                let d2 = t.readString();
233                e1[d2] = [];
234                let e2 = t.readInt();
235                if (e2 < 0 || e2 > MAX_SIZE) {
236                    continue;
237                }
238                for (let f2 = 0; f2 < e2; f2++) {
239                    e1[d2].push(t.readString());
240                }
241            }
242            return e1;
243        }
244
245        unMarshallingDatabase(t) {
246            let h1 = {
247                alias: '',
248                name: '',
249                tables: []
250            };
251            h1.name = t.readString();
252            h1.alias = t.readString();
253            h1.tables = [];
254            let g2 = t.readInt();
255            if (g2 < 0 || g2 > MAX_SIZE) {
256                return h1;
257            }
258            for (let c2 = 0; c2 < g2; c2++) {
259                let h2 = t.readString();
260                let i2 = t.readString();
261                let v1 = {
262                    alias: h2,
263                    name: i2,
264                    fields: []
265                };
266                h1.tables.push(v1);
267                let j2 = t.readInt();
268                if (j2 < 0 || j2 > MAX_SIZE) {
269                    continue;
270                }
271                for (let k2 = 0; k2 < j2; k2++) {
272                    let w1 = {
273                        alias: t.readString(),
274                        colName: t.readString(),
275                        type: t.readInt(),
276                        primary: t.readBoolean(),
277                        nullable: t.readBoolean()
278                    };
279                    h1.tables[c2].fields.push(w1);
280                }
281            }
282            return h1;
283        }
284    }
285
286    a.CloudServiceStub = l;
287
288    class m extends rpc.RemoteObject {
289        constructor(q, i1) {
290            super(q);
291            this.cloudDb = i1;
292        }
293
294        async onRemoteMessageRequest(s, t, u, v) {
295            if (this.cloudDb === undefined) {
296                return false;
297            }
298            let w = this.getDescriptor();
299            v.setWaitTime(1500);
300            switch (s) {
301                case j.GenerateIds:
302                    let l2 = t.readInt();
303                    let m2 = await this.cloudDb.generateId(l2);
304                    u.writeInt(m2.code);
305                    if (m2.code === 0) {
306                        u.writeInt(m2.value.length);
307                        m2.value.forEach(d3 => {
308                            u.writeString(d3);
309                        });
310                    }
311                    return true;
312                case j.Insert:
313                    let n2 = t.readString();
314                    let o2 = this.unMarshallingValuesBuckets(t);
315                    let p2 = this.unMarshallingValuesBuckets(t);
316                    if (o2.length === 0) {
317                        u.writeInt(0);
318                        return true;
319                    }
320                    try {
321                        let e3 = await this.cloudDb.insert(n2, o2, p2);
322                        this.marshallingResultValueBucket(u, e3);
323                    }
324                    catch (f3) {
325                        u.writeInt(g.UNKNOWN_ERROR);
326                    }
327                    return true;
328                case j.Update:
329                    let q2 = t.readString();
330                    let r2 = this.unMarshallingValuesBuckets(t);
331                    let s2 = this.unMarshallingValuesBuckets(t);
332                    try {
333                        let e3 = await this.cloudDb.update(q2, r2, s2);
334                        this.marshallingResultValueBucket(u, e3);
335                    }
336                    catch (f3) {
337                        u.writeInt(g.UNKNOWN_ERROR);
338                    }
339                    return true;
340                case j.Delete:
341                    let v1 = t.readString();
342                    let t2 = this.unMarshallingValuesBuckets(t);
343                    try {
344                        let e3 = await this.cloudDb.delete(v1, t2);
345                        this.marshallingResultValueBucket(u, e3);
346                    }
347                    catch (f3) {
348                        u.writeInt(g.UNKNOWN_ERROR);
349                    }
350                    return true;
351                case j.Query:
352                    let u2 = t.readString();
353                    let v2 = this.unMarshallingFiledArray(t);
354                    let w2 = t.readInt();
355                    let x2 = t.readString();
356                    if (x2 === '') {
357                        x2 = '0';
358                    }
359                    try {
360                        let g3 = await this.cloudDb.query(u2, v2, w2, x2);
361                        u.writeInt(g3.code);
362                        if (g3.code === 0) {
363                            this.marshallingCloudData(u, g3.value);
364                        }
365                    }
366                    catch (f3) {
367                        u.writeInt(g.UNKNOWN_ERROR);
368                    }
369                    return true;
370                case j.Lock:
371                    let y2 = await this.cloudDb.lock();
372                    u.writeInt(y2.code);
373                    if (y2.code === 0) {
374                        u.writeInt(y2.value.interval);
375                        u.writeInt(y2.value.lockId);
376                    }
377                    return true;
378                case j.Heartbeat:
379                    let z2 = t.readInt();
380                    let a3 = await this.cloudDb.heartbeat(z2);
381                    u.writeInt(a3.code);
382                    if (a3.code === 0) {
383                        u.writeInt(a3.value.interval);
384                        u.writeInt(a3.value.lockId);
385                    }
386                    return true;
387                case j.Unlock:
388                    let b3 = t.readInt();
389                    let c3 = await this.cloudDb.unlock(b3);
390                    u.writeInt(c3.code);
391                    if (a3.code === 0) {
392                        u.writeBoolean(c3.value);
393                    }
394                    return true;
395                default:
396                    break;
397            }
398            return false;
399        }
400
401        unMarshallingFiledArray(t) {
402            let v2 = [];
403            let h3 = t.readInt();
404            if (h3 < 0 || h3 > MAX_SIZE) {
405                return v2;
406            }
407            for (let f2 = 0; f2 < h3; f2++) {
408                v2.push(t.readString());
409            }
410            return v2;
411        }
412
413        marshallingCloudData(u, g3) {
414            u.writeString(g3.nextCursor);
415            u.writeBoolean(g3.hasMore);
416            this.marshallingValuesBuckets(u, g3.values);
417        }
418
419        marshallingResultValueBucket(u, i3) {
420            if (i3.length > MAX_SIZE) {
421                return;
422            }
423            u.writeInt(i3.length);
424            for (let f2 = 0; f2 < i3.length; f2++) {
425                u.writeInt(i3[f2].code);
426                if (i3[f2].value) {
427                    let j3 = i3[f2].value;
428                    this.marshallingValueBucket(u, j3);
429                }
430                else {
431                    u.writeInt(0);
432                }
433            }
434        }
435
436        marshallingValueBucket(u, k3) {
437            let r1 = Object.keys(k3);
438            u.writeInt(r1.length);
439            r1.forEach(s1 => {
440                u.writeString(s1);
441                let t1 = k3[s1];
442                if (t1 === undefined || t1 === null) {
443                    u.writeInt(f.NULL);
444                }
445                else {
446                    if (typeof t1 === 'number') {
447                        if (Number(t1).toString().indexOf('.') !== -1) {
448                            u.writeInt(f.REAL);
449                            u.writeFloat(t1);
450                        }
451                        else {
452                            u.writeInt(f.NUMBER);
453                            u.writeLong(t1);
454                        }
455                    }
456                    else if (typeof t1 === 'string') {
457                        u.writeInt(f.TEXT);
458                        u.writeString(t1);
459                    }
460                    else if (typeof t1 === 'boolean') {
461                        u.writeInt(f.BOOL);
462                        u.writeBoolean(t1);
463                    }
464                    else {
465                        if (t1 instanceof Array) {
466                            u.writeInt(f.ASSETS);
467                            u.writeInt(t1.length);
468                            t1.forEach((d3) => {
469                                u.writeString(d3.name);
470                                u.writeString(d3.uri);
471                                u.writeString(d3.path);
472                                u.writeString(d3.createTime);
473                                u.writeString(d3.modifyTime);
474                                u.writeString(d3.size);
475                                if (d3.status) {
476                                    u.writeInt(d3.status);
477                                }
478                                else {
479                                    u.writeInt(relationalStore.AssetStatus.ASSET_NORMAL);
480                                }
481                                u.writeString(d3.assetId);
482                                u.writeString(d3.hash);
483                            });
484                        }
485                        else if (t1 instanceof Uint8Array) {
486                            u.writeInt(f.BLOB);
487                            let l3 = [];
488                            for (let f2 = 0; f2 < t1.length; f2++) {
489                                l3.push(t1[f2]);
490                            }
491                            u.writeIntArray(l3);
492                        }
493                        else {
494                            u.writeInt(f.ASSET);
495                            u.writeString(t1.name);
496                            u.writeString(t1.uri);
497                            u.writeString(t1.path);
498                            u.writeString(t1.createTime);
499                            u.writeString(t1.modifyTime);
500                            u.writeString(t1.size);
501                            if (t1.status) {
502                                u.writeInt(t1.status);
503                            }
504                            else {
505                                u.writeInt(relationalStore.AssetStatus.ASSET_NORMAL);
506                            }
507                            u.writeString(t1.assetId);
508                            u.writeString(t1.hash);
509                        }
510                    }
511                }
512            });
513        }
514
515        marshallingValuesBuckets(u, m3) {
516            if (m3.length > MAX_SIZE) {
517                return;
518            }
519            u.writeInt(m3.length);
520            for (let f2 = 0; f2 < m3.length; f2++) {
521                this.marshallingValueBucket(u, m3[f2]);
522            }
523        }
524
525        unMarshallingValuesBuckets(t) {
526            let n3 = t.readInt();
527            let m3 = [];
528            if (n3 < 0 || n3 > MAX_SIZE) {
529                return m3;
530            }
531            for (let f2 = 0; f2 < n3; f2++) {
532                m3.push(this.unMarshallingValuesBucket(t));
533            }
534            return m3;
535        }
536
537        unMarshallingValuesBucket(t) {
538            let k3 = {};
539            let n3 = t.readInt();
540            if (n3 < 0 || n3 > MAX_SIZE) {
541                return k3;
542            }
543            for (let f2 = 0; f2 < n3; f2++) {
544                let s1 = t.readString();
545                let t1 = this.unMarshallingValueType(t);
546                k3[s1] = t1;
547            }
548            return k3;
549        }
550
551        unMarshallingValueType(t) {
552            let o3 = t.readInt();
553            switch (o3) {
554                case f.NULL: // null
555                    return null;
556                case f.NUMBER: // number
557                    return t.readLong();
558                case f.REAL: // number
559                    return t.readFloat();
560                case f.TEXT: // number
561                    return t.readString();
562                case f.BOOL: // boolean
563                    return t.readBoolean();
564                case f.BLOB: // Uint8Array
565                    return Uint8Array.from(t.readIntArray());
566                case f.ASSET: // Asset
567                    return {
568                        name: t.readString(),
569                        uri: t.readString(),
570                        path: t.readString(),
571                        createTime: t.readString(),
572                        modifyTime: t.readString(),
573                        size: t.readString(),
574                        status: t.readInt(),
575                        assetId: t.readString(),
576                        hash: t.readString(),
577                    };
578                case f.ASSETS: // Assets
579                    let p3 = t.readInt();
580                    let q3 = [];
581                    if (p3 < 0 || p3 > MAX_SIZE) {
582                        return q3;
583                    }
584                    for (let c2 = 0; c2 < p3; c2++) {
585                        q3.push({
586                            name: t.readString(),
587                            uri: t.readString(),
588                            path: t.readString(),
589                            createTime: t.readString(),
590                            modifyTime: t.readString(),
591                            size: t.readString(),
592                            status: t.readInt(),
593                            assetId: t.readString(),
594                            hash: t.readString(),
595                        });
596                    }
597                    return q3;
598            }
599            return null;
600        }
601    }
602
603    a.CloudDbStub = m;
604
605    class n extends rpc.RemoteObject {
606        constructor(q, l1) {
607            super(q);
608            this.assetLoader = l1;
609        }
610
611        async onRemoteMessageRequest(s, t, u, v) {
612            v.setWaitTime(500);
613            let w = this.getDescriptor();
614            let v1 = t.readString();
615            let r3 = t.readString();
616            let s3 = t.readString();
617            switch (s) {
618                case k.Download:
619                    let t3 = this.unmarshallingAssets(t);
620                    let q3 = await this.assetLoader.download(v1, r3, s3, t3);
621                    this.marshallingAssets(u, q3);
622                    return true;
623                case k.Upload:
624                    let u3 = this.unmarshallingAssets(t);
625                    let v3 = await this.assetLoader.upload(v1, r3, u3);
626                    this.marshallingAssets(u, v3);
627                    return true;
628            }
629            return false;
630        }
631
632        unmarshallingAssets(t) {
633            let h3 = t.readInt();
634            let w3 = [];
635            if (h3 < 0 || h3 > MAX_SIZE) {
636                return w3;
637            }
638            for (let f2 = 0; f2 < h3; f2++) {
639                w3.push({
640                    name: t.readString(),
641                    uri: t.readString(),
642                    path: t.readString(),
643                    createTime: t.readString(),
644                    modifyTime: t.readString(),
645                    size: t.readString(),
646                    status: t.readInt(),
647                    assetId: t.readString(),
648                    hash: t.readString()
649                });
650            }
651            return w3;
652        }
653
654        marshallingAssets(u, q3) {
655            u.writeInt(q3.length);
656            if (q3.length > MAX_SIZE) {
657                return;
658            }
659            for (let f2 = 0; f2 < q3.length; f2++) {
660                u.writeInt(q3[f2].code);
661                u.writeString(q3[f2].value.name);
662                u.writeString(q3[f2].value.uri);
663                u.writeString(q3[f2].value.path);
664                u.writeString(q3[f2].value.createTime);
665                u.writeString(q3[f2].value.modifyTime);
666                u.writeString(q3[f2].value.size);
667                u.writeInt(q3[f2].value.status);
668                u.writeString(q3[f2].value.assetId);
669                u.writeString(q3[f2].value.hash);
670            }
671        }
672    }
673
674    a.AssetLoaderStub = n;
675
676    class o extends rpc.RemoteObject {
677        constructor(q, x3) {
678            super(q);
679            this.shareCenter = x3;
680        }
681
682        async onRemoteMessageRequest(s, t, u, v) {
683            if (this.shareCenter == undefined) {
684                return false;
685            }
686            v.setWaitTime(1500);
687            switch (s) {
688                case i.Share:
689                    let y3 = t.readInt();
690                    let n1 = t.readString();
691                    let z3 = t.readString();
692                    let a4 = this.unMarshallingParticipants(t);
693                    let b4 = await this.shareCenter.share(y3, n1, z3, a4);
694                    this.marshallingResults(u, b4);
695                    return true;
696                case i.Unshare:
697                    let c4 = t.readInt();
698                    let d4 = t.readString();
699                    let e4 = t.readString();
700                    let f4 = this.unMarshallingParticipants(t);
701                    let g4 = await this.shareCenter.unshare(c4, d4, e4, f4);
702                    this.marshallingResults(u, g4);
703                    return true;
704                case i.Exit:
705                    let h4 = t.readInt();
706                    let i4 = t.readString();
707                    let j4 = t.readString();
708                    let k4 = await this.shareCenter.exit(h4, i4, j4);
709                    u.writeInt(k4.code);
710                    if (k4.description) {
711                        u.writeString(k4.description);
712                    }
713                    else {
714                        u.writeString(INVALID_STR);
715                    }
716                    return true;
717                case i.ChangePrivilege:
718                    let l4 = t.readInt();
719                    let m4 = t.readString();
720                    let n4 = t.readString();
721                    let o4 = this.unMarshallingParticipants(t);
722                    let p4 = await this.shareCenter.changePrivilege(l4, m4, n4, o4);
723                    this.marshallingResults(u, p4);
724                    return true;
725                case i.QueryParticipants:
726                    let q4 = t.readInt();
727                    let r4 = t.readString();
728                    let s4 = t.readString();
729                    let t4 = await this.shareCenter.queryParticipants(q4, r4, s4);
730                    this.marshallingResultsArray(u, t4);
731                    return true;
732                case i.QueryParticipantsByInvitation:
733                    let u4 = t.readInt();
734                    let v4 = t.readString();
735                    let w4 = t.readString();
736                    let x4 = await this.shareCenter.queryParticipantsByInvitation(u4, v4, w4);
737                    this.marshallingResultsArray(u, x4);
738                    return true;
739                case i.ConfirmInvitation:
740                    let y4 = t.readInt();
741                    let z4 = t.readString();
742                    let a5 = t.readString();
743                    let b5 = t.readInt();
744                    let c5 = await this.shareCenter.confirmInvitation(y4, z4, a5, b5);
745                    u.writeInt(c5.code);
746                    if (c5.description) {
747                        u.writeString(c5.description);
748                    }
749                    else {
750                        u.writeString(INVALID_STR);
751                    }
752                    if (c5.value) {
753                        u.writeString(c5.value);
754                    }
755                    else {
756                        u.writeString(INVALID_STR);
757                    }
758                    return true;
759                case i.ChangeConfirmation:
760                    let d5 = t.readInt();
761                    let e5 = t.readString();
762                    let f5 = t.readString();
763                    let g5 = t.readInt();
764                    let h5 = await this.shareCenter.changeConfirmation(d5, e5, f5, g5);
765                    u.writeInt(h5.code);
766                    if (h5.description) {
767                        u.writeString(h5.description);
768                    }
769                    else {
770                        u.writeString(INVALID_STR);
771                    }
772                    return true;
773                default:
774                    break;
775            }
776            return false;
777        }
778
779        unMarshallingParticipants(t) {
780            let i5 = [];
781            let h3 = t.readInt();
782            if (h3 < 0 || h3 > MAX_SIZE) {
783                return i5;
784            }
785            for (let f2 = 0; f2 < h3; f2++) {
786                i5.push(this.unMarshallingParticipant(t));
787            }
788            return i5;
789        }
790
791        unMarshallingParticipant(t) {
792            let j5 = t.readString();
793            let k5;
794            let l5 = t.readInt();
795            let m5 = t.readInt();
796            k5 = {
797                identity: j5,
798                role: l5 == INVALID_STATE ? undefined : l5,
799                state: m5 == INVALID_STATE ? undefined : m5,
800                privilege: this.unMarshallingPrivilege(t),
801                attachInfo: t.readString(),
802            };
803            return k5;
804        }
805
806        unMarshallingPrivilege(t) {
807            let n5;
808            n5 = {
809                writable: t.readBoolean(),
810                readable: t.readBoolean(),
811                creatable: t.readBoolean(),
812                deletable: t.readBoolean(),
813                shareable: t.readBoolean(),
814            };
815            return n5;
816        }
817
818        marshallingResultsArray(u, i3) {
819            u.writeInt(i3.code);
820            if (i3.description) {
821                u.writeString(i3.description);
822            }
823            else {
824                u.writeString(INVALID_STR);
825            }
826            if (i3.value) {
827                u.writeInt(i3.value.length);
828                i3.value.forEach(q3 => {
829                    this.marshallingParticipant(u, q3);
830                });
831            }
832        }
833
834        marshallingResults(u, i3) {
835            u.writeInt(i3.code);
836            if (i3.description) {
837                u.writeString(i3.description);
838            }
839            else {
840                u.writeString(INVALID_STR);
841            }
842            if (i3.value) {
843                u.writeInt(i3.value.length);
844                i3.value.forEach(q3 => {
845                    u.writeInt(q3.code);
846                    if (q3.description) {
847                        u.writeString(q3.description);
848                    }
849                    else {
850                        u.writeString(INVALID_STR);
851                    }
852                });
853            }
854        }
855
856        marshallingParticipant(u, k5) {
857            u.writeString(k5.identity);
858            if (typeof k5.role !== 'undefined') {
859                u.writeInt(k5.role);
860            }
861            else {
862                u.writeInt(-1);
863            }
864            if (typeof k5.state !== 'undefined') {
865                u.writeInt(k5.state);
866            }
867            else {
868                u.writeInt(-1);
869            }
870            if (k5.privilege) {
871                this.marshallingPrivilege(u, k5.privilege);
872            }
873            else {
874                u.writeBoolean(false);
875                u.writeBoolean(false);
876                u.writeBoolean(false);
877                u.writeBoolean(false);
878                u.writeBoolean(false);
879            }
880            if (k5.attachInfo) {
881                u.writeString(k5.attachInfo);
882            }
883            else {
884                u.writeString(INVALID_STR);
885            }
886        }
887
888        marshallingPrivilege(u, n5) {
889            u.writeBoolean(n5.writable);
890            u.writeBoolean(n5.readable);
891            u.writeBoolean(n5.creatable);
892            u.writeBoolean(n5.deletable);
893            u.writeBoolean(n5.shareable);
894        }
895    }
896
897    a.ShareCenterProxy = o;
898
899    async function b(o5) {
900        return new l("CloudServiceProxy", o5);
901    }
902
903    a.createCloudServiceStub = b;
904
905    async function c(i1) {
906        return new m("CloudDbProxy", i1);
907    }
908
909    a.createCloudDBStub = c;
910
911    async function d(l1) {
912        return new n("AssetLoaderProxy", l1);
913    }
914
915    a.createAssetLoaderStub = d;
916
917    async function e(x3) {
918        return new o('ShareCenterProxy', x3);
919    }
920
921    a.createShareServiceStub = e;
922})(cloudExtension || (cloudExtension = {}));
923
924export default {
925    cloudExtension,
926    FieldType: cloudExtension.FieldType,
927    ErrorCode: cloudExtension.ErrorCode,
928    createCloudServiceStub: cloudExtension.createCloudServiceStub,
929    createCloudDBStub: cloudExtension.createCloudDBStub,
930    createAssetLoaderStub: cloudExtension.createAssetLoaderStub,
931    createShareServiceStub: cloudExtension.createShareServiceStub,
932};