@dittolive/ditto 1.1.0 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/types/ditto.d.ts CHANGED
@@ -68,6 +68,25 @@ declare type InitOptions = {
68
68
  */
69
69
  declare function init(options?: InitOptions): Promise<void>;
70
70
 
71
+ /** @internal */
72
+ declare class KeepAlive {
73
+ /** @internal */
74
+ get isActive(): boolean;
75
+ /** @internal */
76
+ constructor();
77
+ /** @internal */
78
+ retain(id: string): void;
79
+ /** @internal */
80
+ release(id: string): void;
81
+ /** @internal */
82
+ currentIDs(): string[];
83
+ /** @internal */
84
+ countForID(id: string): number | null;
85
+ private static finalizationRegistry;
86
+ private intervalID;
87
+ private countsByID;
88
+ }
89
+
71
90
  /**
72
91
  * Part of {@link TransportConfig} type, configuration for listening for TCP
73
92
  * connections.
@@ -315,6 +334,8 @@ interface IdentityManual {
315
334
  certificate: string;
316
335
  }
317
336
  /**
337
+ * Deprecated - use `IdentityOnlinePlaygroundV2` instead.
338
+ *
318
339
  * Test a Ditto Cloud app without authentication ("Playground mode"). This mode
319
340
  * offers no security and must only be used for development.
320
341
  */
@@ -327,6 +348,40 @@ interface IdentityOnlinePlayground {
327
348
  appID: string;
328
349
  /** If true, auto-configure sync with Ditto Cloud. Default is `true`. */
329
350
  enableDittoCloudSync?: boolean;
351
+ /**
352
+ * A custom Ditto Cloud URL.
353
+ * @internal
354
+ */
355
+ customDittoCloudURL?: string;
356
+ }
357
+ /**
358
+ * Test a Ditto Cloud app with weak shared token authentication ("Playground
359
+ * mode"). This mode is not secure and must only be used for development.
360
+ */
361
+ interface IdentityOnlinePlaygroundV2 {
362
+ type: 'onlinePlaygroundV2';
363
+ /**
364
+ * An ID identifying this app registration on the Ditto portal, which can be
365
+ * found at https://portal.ditto.live.
366
+ */
367
+ appID: string;
368
+ /**
369
+ * A shared token used to set up the OnlinePlayground session. This token is
370
+ * provided by the Ditto Portal when setting up the application.
371
+ */
372
+ token: string;
373
+ /** If true, auto-configure sync with Ditto Cloud. Default is `true`. */
374
+ enableDittoCloudSync?: boolean;
375
+ /**
376
+ * If specified, use a custom authentication service instead of Ditto Cloud.
377
+ * @internal
378
+ */
379
+ customAuthURL?: string;
380
+ /**
381
+ * A custom Ditto Cloud URL.
382
+ * @internal
383
+ */
384
+ customDittoCloudURL?: string;
330
385
  }
331
386
  /**
332
387
  * Deprecated - use `IdentityOnlineWithAuthentication` instead.
@@ -372,6 +427,11 @@ interface IdentityOnline {
372
427
  * If specified, use a custom authentication service instead of Ditto Cloud.
373
428
  */
374
429
  customAuthURL?: string;
430
+ /**
431
+ * A custom Ditto Cloud URL.
432
+ * @internal
433
+ */
434
+ customDittoCloudURL?: string;
375
435
  }
376
436
  /**
377
437
  * Run Ditto in secure production mode, logging on to Ditto Cloud or an
@@ -412,17 +472,21 @@ interface IdentityOnlineWithAuthentication {
412
472
  * If specified, use a custom authentication service instead of Ditto Cloud.
413
473
  */
414
474
  customAuthURL?: string;
475
+ /**
476
+ * A custom Ditto Cloud URL.
477
+ * @internal
478
+ */
479
+ customDittoCloudURL?: string;
415
480
  }
416
481
  /**
417
482
  * The various identity configurations that you can use when initializing a
418
483
  * `Ditto` instance.
419
484
  */
420
- declare type Identity = IdentityDevelopment | IdentityOfflinePlayground | IdentitySharedKey | IdentityProduction | IdentityManual | IdentityOnlinePlayground | IdentityOnline | IdentityOnlineWithAuthentication;
485
+ declare type Identity = IdentityDevelopment | IdentityOfflinePlayground | IdentitySharedKey | IdentityProduction | IdentityManual | IdentityOnlinePlayground | IdentityOnlinePlaygroundV2 | IdentityOnline | IdentityOnlineWithAuthentication;
486
+ /** The list of identity types that require activation through an offlineLicenseToken */
487
+ declare const IdentityTypesRequiringOfflineLicenseToken: string[];
421
488
 
422
- /**
423
- * TODO: document.
424
- * @internal
425
- */
489
+ /** @internal */
426
490
  declare class Bridge<JSClass extends object, FFIType> {
427
491
  type: Function;
428
492
  release: (pointer: Pointer<FFIType>) => void;
@@ -431,18 +495,24 @@ declare class Bridge<JSClass extends object, FFIType> {
431
495
  * that is called whenever a registered object is garbage collected, passing
432
496
  * the associated `pointer` to it. The release function is then responsible
433
497
  * to free or drop the corresponding native object.
498
+ *
499
+ * @internal
434
500
  */
435
501
  constructor(type: Function, release: (pointer: Pointer<FFIType>) => void, options?: {});
436
502
  /**
437
503
  * Returns the FFI pointer for `object` if registered, otherwise returns
438
504
  * `undefined`. If `object` has been unregistered before, returns
439
505
  * `undefined`, too.
506
+ *
507
+ * @internal
440
508
  */
441
509
  pointerFor(object: JSClass): Pointer<FFIType> | undefined;
442
510
  /**
443
511
  * Convenience method, returns the object for the FFI `pointer` if registered,
444
512
  * otherwise returns `undefined`. If the object associated with the `pointer`
445
513
  * has been unregistered before, returns `undefined`, too.
514
+ *
515
+ * @internal
446
516
  */
447
517
  objectFor(pointer: Pointer<FFIType>): JSClass | undefined;
448
518
  /**
@@ -451,16 +521,20 @@ declare class Bridge<JSClass extends object, FFIType> {
451
521
  * returns after registering. If no `create` function is given, uses the
452
522
  * type of the bridge as a constructor and creates a new instance of it
453
523
  * without passing any parameters.
524
+ *
525
+ * @internal
454
526
  */
455
- bridge(pointer: Pointer<FFIType>, create?: () => JSClass, options?: {}): JSClass;
456
- /**
457
- * TODO: document.
458
- */
527
+ bridge(pointer: Pointer<FFIType>, objectOrCreate?: object | (() => JSClass), options?: {}): JSClass;
528
+ /** @internal */
459
529
  register(object: JSClass, pointer: Pointer<FFIType>): void;
460
- /**
461
- * TODO: document.
462
- */
530
+ /** @internal */
463
531
  unregister(object: JSClass): void;
532
+ /** @internal */
533
+ unregisterAll(): void;
534
+ /** @internal */
535
+ get count(): number;
536
+ /** @internal */
537
+ static readonly all: any[];
464
538
  private metaByAddrMap;
465
539
  private finalizationRegistry;
466
540
  private finalize;
@@ -715,6 +789,10 @@ declare class Document {
715
789
  * represents the passed in document(s).
716
790
  */
717
791
  static hashMnemonic(documentOrMany: DocumentLike | DocumentLike[]): string;
792
+ /**
793
+ * Support for JSON-stringifying a document directly.
794
+ */
795
+ toJSON(): DocumentValue;
718
796
  /** @internal */
719
797
  constructor();
720
798
  /** @internal */
@@ -789,6 +867,10 @@ declare class MutableDocument {
789
867
  * Increments the counter of `mutableDocument` at the given `keyPath`.
790
868
  */
791
869
  static incrementCounterAt(mutableDocument: MutableDocumentLike, keyPath: string, amount: number, skipValidation?: boolean): void;
870
+ /**
871
+ * Support for JSON-stringifying a mutable document directly.
872
+ */
873
+ toJSON(): DocumentValue;
792
874
  /** @internal */
793
875
  constructor();
794
876
  /** @internal */
@@ -1017,6 +1099,9 @@ declare class UpdateResultsMap {
1017
1099
  * {@link PendingCursorOperation} object. It handles the logic for calling the
1018
1100
  * event handler that is provided to `observe` calls.
1019
1101
  *
1102
+ * Ditto will prevent the process from exiting as long as there are
1103
+ * active live queries (not relevant when running in the browser).
1104
+ *
1020
1105
  * `LiveQuery` objects must be kept in scope for as long as you wish to have
1021
1106
  * your event handler be called when there is an update to a document matching
1022
1107
  * the query you provide. When you no longer want to receive updates about
@@ -1029,6 +1114,8 @@ declare class LiveQuery {
1029
1114
  readonly queryArgs: QueryArguments | null;
1030
1115
  /** The name of the collection that the live query is based on. */
1031
1116
  get collectionName(): string;
1117
+ /** Returns true if the receiver has been stopped. */
1118
+ get isStopped(): boolean;
1032
1119
  /**
1033
1120
  * Stop the live query from delivering updates.
1034
1121
  */
@@ -1686,8 +1773,8 @@ declare class Collection {
1686
1773
  * attachment into a document.
1687
1774
  *
1688
1775
  * ``` JavaScript
1689
- * const attachment = collection.newAttachment('/path/to/my/file.pdf')
1690
- * collection.insert({ _id: '123', attachment, other: 'some-string' })
1776
+ * const attachment = await collection.newAttachment('/path/to/my/file.pdf')
1777
+ * await collection.insert({ _id: '123', attachment, other: 'some-string' })
1691
1778
  * }
1692
1779
  * ```
1693
1780
  *
@@ -1698,7 +1785,7 @@ declare class Collection {
1698
1785
  */
1699
1786
  newAttachment(pathOrData: string | Uint8Array, metadata?: {
1700
1787
  [key: string]: string;
1701
- }): Attachment;
1788
+ }): Promise<Attachment>;
1702
1789
  /**
1703
1790
  * Trigger an attachment to be downloaded locally to the device and observe
1704
1791
  * its progress as it does so.
@@ -1930,14 +2017,14 @@ declare class Store {
1930
2017
  * Returns the names of all available collections in the store of the
1931
2018
  * related {@link Ditto} instance.
1932
2019
  */
1933
- collectionNames(): string[];
2020
+ collectionNames(): Promise<string[]>;
1934
2021
  /** @internal */
1935
2022
  constructor(ditto: Ditto);
1936
2023
  /**
1937
2024
  * Private method, used only by the Portal https://github.com/getditto/ditto/pull/3652
1938
2025
  * @internal
1939
2026
  */
1940
- registerLiveQueryWebhook(collectionName: string, query: string, url: string): DocumentIDValue;
2027
+ registerLiveQueryWebhook(collectionName: string, query: string, url: string): Promise<DocumentIDValue>;
1941
2028
  }
1942
2029
 
1943
2030
  /** @internal */
@@ -1950,8 +2037,8 @@ declare type ObserverOptions = {
1950
2037
  };
1951
2038
  /**
1952
2039
  * Generic observer handle returned by various observation APIs. The observation
1953
- * remains active until the {@link stop | stop()} method is called explicitly or the
1954
- * observer instance is garbage collected. Therefore, to keep the observation
2040
+ * remains active until the {@link stop | stop()} method is called explicitly or
2041
+ * the observer instance is garbage collected. Therefore, to keep the observation
1955
2042
  * alive, you have to keep a reference to the corresponding observer.
1956
2043
  */
1957
2044
  declare class Observer {
@@ -2033,9 +2120,9 @@ declare class Ditto {
2033
2120
  */
2034
2121
  readonly siteID: number | BigInt;
2035
2122
  /**
2036
- * Returns `true` if a license token has been set, otherwise returns `false`.
2123
+ * Returns `true` if an offline license token has been set, otherwise returns `false`.
2037
2124
  *
2038
- * @see {@link setLicenseToken | setLicenseToken()}
2125
+ * @see {@link setOfflineOnlyLicenseToken | setOfflineOnlyLicenseToken()}
2039
2126
  */
2040
2127
  readonly isActivated: boolean;
2041
2128
  /**
@@ -2057,7 +2144,9 @@ declare class Ditto {
2057
2144
  * using this to create a Ditto instance in the web browser will throw an
2058
2145
  * exception.
2059
2146
  *
2060
- * @param identity - Identity for the new Ditto instance.
2147
+ * @param identity - Identity for the new Ditto instance, defaults to
2148
+ * `offlinePlayground` with `appID` being the empty string `''`.
2149
+ *
2061
2150
  * @param path - On Node, `path` corresponds to a real directory
2062
2151
  * on the file system (intermediate directories are created if needed). In the
2063
2152
  * browser, `path` is used as an internal namespace into the backing storage
@@ -2067,19 +2156,39 @@ declare class Ditto {
2067
2156
  * @see {@link identity}
2068
2157
  * @see {@link path}
2069
2158
  */
2070
- constructor(identity: Identity, path?: string);
2159
+ constructor(identity?: Identity, path?: string);
2071
2160
  /**
2072
- * Activate a `Ditto` instance by setting a license token. You cannot sync
2073
- * with `Ditto` before you have activated it.
2161
+ * @deprecated use {@link setOfflineOnlyLicenseToken | setOfflineOnlyLicenseToken()} instead.
2162
+ * Activate a `Ditto` instance by setting an offline only license token. You cannot initiate sync
2163
+ * with `Ditto` before you have activated it. The offline license token is only valid for identities
2164
+ * of type `development`, `manual`, `offlinePlayground`, and `sharedKey`.
2074
2165
  *
2075
2166
  * @param licenseToken the license token to activate the `Ditto` instance
2076
- * with. You can find yours on the Ditto portal (https://portal.ditto.live).
2167
+ * with. You can find yours on the [Ditto portal](https://portal.ditto.live).
2168
+ */
2169
+ setAccessLicense(accessLicense: string): void;
2170
+ /**
2171
+ * Activate a `Ditto` instance by setting an offline only license token. You cannot initiate sync
2172
+ * with `Ditto` before you have activated it. The offline license token is only valid for identities
2173
+ * of type `development`, `manual`, `offlinePlayground`, and `sharedKey`.
2174
+ *
2175
+ * @deprecated use {@link setOfflineOnlyLicenseToken} for identities of type `development`, `manual`,
2176
+ * `offlinePlayground`, and `sharedKey`.
2177
+ *
2178
+ *
2179
+ * @param licenseToken the license token to activate the `Ditto` instance
2180
+ * with. You can find yours on the [Ditto portal](https://portal.ditto.live).
2077
2181
  */
2078
2182
  setLicenseToken(licenseToken: string): void;
2079
2183
  /**
2080
- * @deprecated use {@link setLicenseToken | setLicenseToken()} instead.
2184
+ * Activate a `Ditto` instance by setting an offline only license token. You cannot initiate sync
2185
+ * with `Ditto` before you have activated it. The offline license token is only valid for identities
2186
+ * of type `development`, `manual`, `offlinePlayground`, and `sharedKey`.
2187
+ *
2188
+ * @param licenseToken the license token to activate the `Ditto` instance
2189
+ * with. You can find yours on the [Ditto portal](https://portal.ditto.live).
2081
2190
  */
2082
- setAccessLicense(accessLicense: string): void;
2191
+ setOfflineOnlyLicenseToken(licenseToken: string): void;
2083
2192
  /**
2084
2193
  * Returns the current transport configuration, frozen. If you want to modify
2085
2194
  * the transport config, make a {@link TransportConfig.copy | copy} first. Or
@@ -2122,6 +2231,9 @@ declare class Ditto {
2122
2231
  * customized with `setTransportConfig()`. On the **Web**, only connecting via
2123
2232
  * Websockets is supported.
2124
2233
  *
2234
+ * Ditto will prevent the process from exiting until sync is stopped (not
2235
+ * relevant when running in the browser).
2236
+ *
2125
2237
  * @see {@link isSyncActive}
2126
2238
  * @see {@link stopSync | stopSync()}
2127
2239
  */
@@ -2139,6 +2251,9 @@ declare class Ditto {
2139
2251
  /**
2140
2252
  * Registers an observer for info about Ditto peers in range of this device.
2141
2253
  *
2254
+ * Ditto will prevent the process from exiting as long as there are active
2255
+ * peers observers (not relevant when running in the browser).
2256
+ *
2142
2257
  * @param callback called immediately with the current state of peers
2143
2258
  * in range and whenever that state changes. Then it will be invoked
2144
2259
  * repeatedly when Ditto devices come and go, or the active connections to
@@ -2148,6 +2263,9 @@ declare class Ditto {
2148
2263
  /**
2149
2264
  * Register observer for changes of underlying transport conditions.
2150
2265
  *
2266
+ * Ditto will prevent the process from exiting as long as there are active
2267
+ * transport conditions observers (not relevant when running in the browser).
2268
+ *
2151
2269
  * @param callback called when underlying transport conditions change with
2152
2270
  * the changed `condition` and it's `source`.
2153
2271
  */
@@ -2168,6 +2286,8 @@ declare class Ditto {
2168
2286
  * Only available in Node environments at the moment, no-op in the browser.
2169
2287
  */
2170
2288
  runGarbageCollection(): void;
2289
+ /** @internal */
2290
+ keepAlive: KeepAlive;
2171
2291
  private sync;
2172
2292
  private isWebValid;
2173
2293
  private isX509Valid;
@@ -2177,9 +2297,7 @@ declare class Ditto {
2177
2297
  private validateIdentity;
2178
2298
  private setSyncEnabled;
2179
2299
  }
2180
- /**
2181
- * @internal
2182
- */
2300
+ /** @internal */
2183
2301
  declare const dittoBridge: Bridge<Ditto, "CDitto_t">;
2184
2302
 
2185
2303
  /** @internal */
@@ -2187,7 +2305,11 @@ declare type ObserverToken = string;
2187
2305
  /** @internal */
2188
2306
  declare class ObserverManager {
2189
2307
  /** @internal */
2190
- constructor();
2308
+ readonly id: string;
2309
+ /** @internal */
2310
+ readonly keepAlive: KeepAlive | null;
2311
+ /** @internal */
2312
+ constructor(id: string, keepAlive?: KeepAlive | null);
2191
2313
  /** @internal */
2192
2314
  addObserver(callback: any): ObserverToken;
2193
2315
  /** @internal */
@@ -2322,11 +2444,14 @@ declare class Authenticator {
2322
2444
  logout(cleanupFn?: (Ditto: any) => void): Promise<void>;
2323
2445
  observeStatus(callback: (authenticationStatus: AuthenticationStatus) => void): Observer;
2324
2446
  /** @internal */
2325
- constructor();
2447
+ constructor(keepAlive: KeepAlive);
2326
2448
  /** @internal */
2327
2449
  '@ditto.authenticationExpiring': (number: any) => void;
2328
2450
  /** @internal */
2329
2451
  '@ditto.authClientValidityChanged': (isWebValid: boolean, isX509Valid: boolean) => void;
2452
+ /** @internal */
2453
+ protected keepAlive: KeepAlive;
2454
+ /** @internal */
2330
2455
  protected observerManager: ObserverManager;
2331
2456
  }
2332
2457
  /** @internal */
@@ -2337,7 +2462,7 @@ declare class OnlineAuthenticator extends Authenticator {
2337
2462
  readonly authClientPointer: Pointer<AuthClientType>;
2338
2463
  readonly authenticationHandler: AuthenticationHandler;
2339
2464
  private ditto;
2340
- constructor(authClientPointer: Pointer<AuthClientType>, ditto: Ditto, authenticationHandler: AuthenticationHandler);
2465
+ constructor(keepAlive: KeepAlive, authClientPointer: Pointer<AuthClientType>, ditto: Ditto, authenticationHandler: AuthenticationHandler);
2341
2466
  '@ditto.authenticationExpiring': (secondsRemaining: number) => void;
2342
2467
  '@ditto.authClientValidityChanged': (isWebValid: boolean, isX509Valid: boolean) => void;
2343
2468
  private updateAndNotify;
@@ -2350,7 +2475,6 @@ declare class NotAvailableAuthenticator extends Authenticator {
2350
2475
  loginWithUsernameAndPassword(username: string, password: string, provider: string): Promise<void>;
2351
2476
  logout(cleanupFn?: (Ditto: any) => void): Promise<void>;
2352
2477
  '@ditto.authenticationExpiring': (secondsRemaining: any) => never;
2353
- /** @internal */
2354
2478
  '@ditto.authClientValidityChanged': (isWebValid: boolean, isX509Valid: boolean) => void;
2355
2479
  }
2356
2480
 
@@ -2562,5 +2686,5 @@ declare class CBOR {
2562
2686
  static decode(data: Uint8Array): any;
2563
2687
  }
2564
2688
 
2565
- export { Attachment, AttachmentFetchEvent, AttachmentFetchEventCompleted, AttachmentFetchEventDeleted, AttachmentFetchEventProgress, AttachmentFetchEventType, AttachmentFetcher, AttachmentToken, AuthenticationHandler, AuthenticationStatus, Authenticator, CBOR, Collection, CollectionsEvent, CollectionsEventParams, ConditionSource, Counter, CustomLogCallback, Ditto, Document, DocumentIDValue, DocumentLike, DocumentPath, DocumentValue, Identity, IdentityDevelopment, IdentityManual, IdentityOfflinePlayground, IdentityOnline, IdentityOnlinePlayground, IdentityOnlineWithAuthentication, IdentityProduction, IdentitySharedKey, InitOptions, InsertOptions, LiveQuery, LiveQueryEvent, LiveQueryEventInitial, LiveQueryEventUpdate, LiveQueryEventUpdateParams, LiveQueryMove, LogLevel, Logger, MutableDocument, MutableDocumentLike, MutableDocumentPath, NotAvailableAuthenticator, Observer, ObserverOptions, OnlineAuthenticator, PendingCursorOperation, PendingIDSpecificOperation, PresenceConnectionType, QueryArguments, QueryObservationHandler, RemotePeer, SingleDocumentLiveQueryEvent, SingleObservationHandler, SortDirection, Store, Subscription, SubscriptionContextInfo, TransportCondition, TransportConfig, TransportConfigConnect, TransportConfigGlobal, TransportConfigLan, TransportConfigListen, TransportConfigListenHTTP, TransportConfigListenTCP, TransportConfigPeerToPeer, UpdateResult, UpdateResultType, UpdateResultsMap, UpsertOptions, Value, WebAssemblyModule, WriteStrategy, __log, attachmentBridge, dittoBridge, documentBridge, init, mutableDocumentBridge, validateDocumentIDCBOR, validateDocumentIDValue };
2689
+ export { Attachment, AttachmentFetchEvent, AttachmentFetchEventCompleted, AttachmentFetchEventDeleted, AttachmentFetchEventProgress, AttachmentFetchEventType, AttachmentFetcher, AttachmentToken, AuthenticationHandler, AuthenticationStatus, Authenticator, CBOR, Collection, CollectionsEvent, CollectionsEventParams, ConditionSource, Counter, CustomLogCallback, Ditto, Document, DocumentIDValue, DocumentLike, DocumentPath, DocumentValue, Identity, IdentityDevelopment, IdentityManual, IdentityOfflinePlayground, IdentityOnline, IdentityOnlinePlayground, IdentityOnlinePlaygroundV2, IdentityOnlineWithAuthentication, IdentityProduction, IdentitySharedKey, IdentityTypesRequiringOfflineLicenseToken, InitOptions, InsertOptions, KeepAlive, LiveQuery, LiveQueryEvent, LiveQueryEventInitial, LiveQueryEventUpdate, LiveQueryEventUpdateParams, LiveQueryMove, LogLevel, Logger, MutableDocument, MutableDocumentLike, MutableDocumentPath, NotAvailableAuthenticator, Observer, ObserverOptions, OnlineAuthenticator, PendingCursorOperation, PendingIDSpecificOperation, PresenceConnectionType, QueryArguments, QueryObservationHandler, RemotePeer, SingleDocumentLiveQueryEvent, SingleObservationHandler, SortDirection, Store, Subscription, SubscriptionContextInfo, TransportCondition, TransportConfig, TransportConfigConnect, TransportConfigGlobal, TransportConfigLan, TransportConfigListen, TransportConfigListenHTTP, TransportConfigListenTCP, TransportConfigPeerToPeer, UpdateResult, UpdateResultType, UpdateResultsMap, UpsertOptions, Value, WebAssemblyModule, WriteStrategy, __log, attachmentBridge, dittoBridge, documentBridge, init, mutableDocumentBridge, validateDocumentIDCBOR, validateDocumentIDValue };
2566
2690
  //# sourceMappingURL=ditto.d.ts.map