Skip to content

Commit 16fab69

Browse files
authored
Merge pull request #1331 from remotestorage/feature/1251-sync
Type, document, and refactor Sync, port tests to Mocha
2 parents be39e4e + cc87edd commit 16fab69

31 files changed

+2586
-2097
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module.exports = {
9292
],
9393
"overrides": [
9494
{
95-
"files": ["*.test.ts"],
95+
"files": ["*.test.mjs"],
9696
"rules": {
9797
"max-statements": 0,
9898
"@typescript-eslint/no-empty-function": 0,

src/access.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ export class Access {
2222
rootPaths: string[];
2323
storageType: string;
2424

25-
// TODO create custom type for init function
26-
static _rs_init(): void {
27-
return;
28-
}
29-
3025
constructor() {
3126
this.reset();
3227
}
@@ -197,6 +192,10 @@ export class Access {
197192
setStorageType (type: string): void {
198193
this.storageType = type;
199194
}
195+
196+
static _rs_init(): void {
197+
return;
198+
}
200199
}
201200

202201
export default Access;

src/authorize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import type RemoteStorage from './remotestorage';
12
import log from './log';
2-
import RemoteStorage from './remotestorage';
33
import { localStorageAvailable, globalContext, toBase64 } from './util';
44
import UnauthorizedError from './unauthorized-error';
55
import { EventHandler } from './eventhandling';

src/baseclient.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import tv4 from 'tv4';
2+
import type RemoteStorage from './remotestorage';
23
import type { JsonSchemas } from './interfaces/json_schema';
34
import type { ChangeObj } from './interfaces/change_obj';
45
import type { QueuedRequestResponse } from './interfaces/queued_request_response';
@@ -7,7 +8,6 @@ import SchemaNotFound from './schema-not-found-error';
78
import EventHandling from './eventhandling';
89
import config from './config';
910
import { applyMixins, cleanPath, isFolder } from './util';
10-
import RemoteStorage from './remotestorage';
1111

1212
function getModuleNameFromBase(path: string): string {
1313
const parts = path.split('/');
@@ -147,8 +147,8 @@ function getModuleNameFromBase(path: string): string {
147147
* during sync.
148148
*
149149
* > [!NOTE]
150-
* > Automatically receiving remote changes depends on the {@link caching!Caching} settings
151-
* > for your module/paths.
150+
* > Automatically receiving remote changes depends on the
151+
* > {@link caching!Caching caching} settings for your module/paths.
152152
*
153153
* ### `window`
154154
*
@@ -180,13 +180,13 @@ function getModuleNameFromBase(path: string): string {
180180
* }
181181
* ```
182182
*
183-
* But when this change is pushed out by asynchronous synchronization, this change
184-
* may be rejected by the server, if the remote version has in the meantime changed
185-
* from `white` to for instance `red`; this will then lead to a change event with
186-
* origin `conflict` (usually a few seconds after the event with origin `window`,
187-
* if you have those activated). Note that since you already changed it from
188-
* `white` to `blue` in the local version a few seconds ago, `oldValue` is now
189-
* your local value of `blue`:
183+
* However, when this change is pushed out by the sync process, it will be
184+
* rejected by the server, if the remote version has changed in the meantime,
185+
* for example from `white` to `red`. This will lead to a change event with
186+
* origin `conflict`, usually a few seconds after the event with origin
187+
* `window`. Note that since you already changed it from `white` to `blue` in
188+
* the local version a few seconds ago, `oldValue` is now your local value of
189+
* `blue`:
190190
*
191191
* ```js
192192
* {
@@ -212,11 +212,6 @@ function getModuleNameFromBase(path: string): string {
212212
*
213213
* If there is an algorithm to merge the differences between local and remote
214214
* versions of the data, conflicts may be automatically resolved.
215-
* {@link storeObject} or {@link storeFile} must not be called synchronously from
216-
* the change event handler, nor by chaining Promises. {@link storeObject} or
217-
* {@link storeFile} must not be called until the next iteration of the JavaScript
218-
* Task Queue, using for example
219-
* [`setTimeout()`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout).
220215
*
221216
* If no algorithm exists, conflict resolution typically involves displaying local
222217
* and remote versions to the user, and having the user merge them, or choose
@@ -625,17 +620,16 @@ export class BaseClient {
625620
* @example
626621
* client.remove('path/to/object').then(() => console.log('item deleted'));
627622
*/
628-
// TODO add real return type
629623
// TODO Don't return the RemoteResponse directly, handle response properly
630-
remove (path: string): Promise<unknown> {
624+
async remove (path: string): Promise<QueuedRequestResponse> {
631625
if (typeof path !== 'string') {
632626
return Promise.reject('Argument \'path\' of baseClient.remove must be a string');
633627
}
634628
if (!this.storage.access.checkPathPermission(this.makePath(path), 'rw')) {
635629
console.warn('WARNING: Removing a document to which only read access (\'r\') was claimed');
636630
}
637631

638-
return this.storage.delete(this.makePath(path));
632+
return this.storage.delete(this.makePath(path), this.storage.connected);
639633
}
640634

641635
/**

0 commit comments

Comments
 (0)