dexie-cloud-addon 4.0.0-beta.24 → 4.0.1-beta.27

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.
Files changed (40) hide show
  1. package/dist/modern/dexie-cloud-addon.js +42 -27
  2. package/dist/modern/dexie-cloud-addon.js.map +1 -1
  3. package/dist/modern/dexie-cloud-addon.min.js +1 -1
  4. package/dist/modern/dexie-cloud-addon.min.js.map +1 -1
  5. package/dist/modern/service-worker.js +41 -26
  6. package/dist/modern/service-worker.js.map +1 -1
  7. package/dist/modern/service-worker.min.js +1 -1
  8. package/dist/modern/service-worker.min.js.map +1 -1
  9. package/dist/module-es5/dexie-cloud-addon.js +41 -25
  10. package/dist/module-es5/dexie-cloud-addon.js.map +1 -1
  11. package/dist/module-es5/dexie-cloud-addon.min.js +1 -1
  12. package/dist/module-es5/dexie-cloud-addon.min.js.map +1 -1
  13. package/dist/types/DXCWebSocketStatus.d.ts +1 -1
  14. package/dist/types/DexieCloudTable.d.ts +18 -2
  15. package/dist/types/PermissionChecker.d.ts +1 -1
  16. package/dist/types/TSON.d.ts +1 -1
  17. package/dist/types/WSObservable.d.ts +2 -2
  18. package/dist/types/authentication/authenticate.d.ts +1 -1
  19. package/dist/types/db/DexieCloudDB.d.ts +1 -1
  20. package/dist/types/extend-dexie-interface.d.ts +5 -3
  21. package/dist/types/getInternalAccessControlObservable.d.ts +1 -1
  22. package/dist/types/getPermissionsLookupObservable.d.ts +2 -2
  23. package/dist/types/sync/getTablesToSyncify.d.ts +1 -1
  24. package/dist/types/sync/messagesFromServerQueue.d.ts +1 -1
  25. package/dist/types/types/DXCAlert.d.ts +1 -1
  26. package/dist/types/types/DXCInputField.d.ts +1 -1
  27. package/dist/types/types/DXCUserInteraction.d.ts +1 -1
  28. package/dist/types/types/SWSyncEvent.d.ts +1 -1
  29. package/dist/types/types/SyncState.d.ts +2 -2
  30. package/dist/umd/dexie-cloud-addon.js +40 -24
  31. package/dist/umd/dexie-cloud-addon.js.map +1 -1
  32. package/dist/umd/dexie-cloud-addon.min.js +1 -1
  33. package/dist/umd/dexie-cloud-addon.min.js.map +1 -1
  34. package/dist/umd/service-worker.js +40 -25
  35. package/dist/umd/service-worker.js.map +1 -1
  36. package/dist/umd/service-worker.min.js +1 -1
  37. package/dist/umd/service-worker.min.js.map +1 -1
  38. package/dist/umd-modern/dexie-cloud-addon.js +38 -23
  39. package/dist/umd-modern/dexie-cloud-addon.js.map +1 -1
  40. package/package.json +5 -6
@@ -1 +1 @@
1
- export declare type DXCWebSocketStatus = "not-started" | "connecting" | "connected" | "disconnected" | "error";
1
+ export type DXCWebSocketStatus = "not-started" | "connecting" | "connected" | "disconnected" | "error";
@@ -1,2 +1,18 @@
1
- import { Table } from 'dexie';
2
- export declare type DexieCloudTable<T = any, TKey = string> = Table<T, TKey, 'realmId' | 'owner'>;
1
+ import { EntityTable, InsertType } from 'dexie';
2
+ export interface DexieCloudEntity {
3
+ owner: string;
4
+ realmId: string;
5
+ }
6
+ /** Don't force the declaration of owner and realmId on every entity (some
7
+ * types may not be interested of these props if they are never going to be shared)
8
+ * Let the type system behave the same as the runtime and merge these props in automatically
9
+ * when declaring the table where the props aren't explicitely declared.
10
+ * User may also explicitely declare these props in order to manually set them when
11
+ * they are interested of taking control over access.
12
+ */
13
+ type WithDexieCloudProps<T> = T extends DexieCloudEntity ? T : T & DexieCloudEntity;
14
+ /** Syntactic sugar for declaring a synced table of arbritary entity.
15
+ *
16
+ */
17
+ export type DexieCloudTable<T = any, TKeyPropName extends keyof T = never> = EntityTable<WithDexieCloudProps<T>, TKeyPropName, InsertType<WithDexieCloudProps<T>, TKeyPropName | 'owner' | 'realmId'>>;
18
+ export {};
@@ -1,6 +1,6 @@
1
1
  import { KeyPaths } from 'dexie';
2
2
  import { DBPermissionSet } from 'dexie-cloud-common';
3
- declare type TableName<T> = T extends {
3
+ type TableName<T> = T extends {
4
4
  table: () => infer TABLE;
5
5
  } ? TABLE extends string ? TABLE : string : string;
6
6
  export declare class PermissionChecker<T, TableNames extends string = TableName<T>> {
@@ -1,5 +1,5 @@
1
1
  export declare const hasBigIntSupport: boolean;
2
- export declare function compareBigInts(a: bigint | FakeBigInt | string, b: bigint | FakeBigInt | string): 1 | 0 | -1;
2
+ export declare function compareBigInts(a: bigint | FakeBigInt | string, b: bigint | FakeBigInt | string): 0 | 1 | -1;
3
3
  export declare class FakeBigInt {
4
4
  v: string;
5
5
  toString(): string;
@@ -1,12 +1,12 @@
1
1
  import { DBOperationsSet } from 'dexie-cloud-common';
2
2
  import { BehaviorSubject, Observable, Subscriber, Subscription } from 'rxjs';
3
3
  import { DXCWebSocketStatus } from './DXCWebSocketStatus';
4
- export declare type WSClientToServerMsg = ReadyForChangesMessage;
4
+ export type WSClientToServerMsg = ReadyForChangesMessage;
5
5
  export interface ReadyForChangesMessage {
6
6
  type: 'ready';
7
7
  rev: string;
8
8
  }
9
- export declare type WSConnectionMsg = RevisionChangedMessage | RealmAddedMessage | RealmAcceptedMessage | RealmRemovedMessage | RealmsChangedMessage | ChangesFromServerMessage | TokenExpiredMessage;
9
+ export type WSConnectionMsg = RevisionChangedMessage | RealmAddedMessage | RealmAcceptedMessage | RealmRemovedMessage | RealmsChangedMessage | ChangesFromServerMessage | TokenExpiredMessage;
10
10
  export interface ChangesFromServerMessage {
11
11
  type: 'changes';
12
12
  baseRev: string;
@@ -3,7 +3,7 @@ import { BehaviorSubject } from 'rxjs';
3
3
  import { DexieCloudDB } from '../db/DexieCloudDB';
4
4
  import { UserLogin } from '../db/entities/UserLogin';
5
5
  import { DXCUserInteraction } from '../types/DXCUserInteraction';
6
- export declare type FetchTokenCallback = (tokenParams: {
6
+ export type FetchTokenCallback = (tokenParams: {
7
7
  public_key: string;
8
8
  hints?: {
9
9
  userId?: string;
@@ -14,7 +14,7 @@ export interface SyncStateChangedEventData {
14
14
  error?: Error;
15
15
  progress?: number;
16
16
  }
17
- declare type SyncStateTable = Table<PersistedSyncState | DexieCloudSchema | DexieCloudOptions, 'syncState' | 'options' | 'schema'>;
17
+ type SyncStateTable = Table<PersistedSyncState | DexieCloudSchema | DexieCloudOptions, 'syncState' | 'options' | 'schema'>;
18
18
  export interface DexieCloudDBBase {
19
19
  readonly name: Dexie['name'];
20
20
  readonly close: Dexie['close'];
@@ -1,12 +1,13 @@
1
1
  import { DBRealm, DBRealmMember, DBRealmRole } from 'dexie-cloud-common';
2
2
  import { DexieCloudAPI } from './DexieCloudAPI';
3
3
  import { NewIdOptions } from './types/NewIdOptions';
4
+ type Optional<T, Props extends keyof T> = Omit<T, Props> & Partial<T>;
4
5
  declare module 'dexie' {
5
6
  interface Dexie {
6
7
  cloud: DexieCloudAPI;
7
- realms: Table<DBRealm, 'realmId', 'owner'>;
8
- members: Table<DBRealmMember, 'id', 'realmId' | 'owner'>;
9
- roles: Table<DBRealmRole, [string, string], 'owner'>;
8
+ realms: Table<DBRealm, string, Optional<DBRealm, 'realmId' | 'owner'>>;
9
+ members: Table<DBRealmMember, string, Optional<DBRealmMember, 'id' | 'owner'>>;
10
+ roles: Table<DBRealmRole, [string, string], Optional<DBRealmRole, 'owner'>>;
10
11
  }
11
12
  interface Table {
12
13
  newId(options: NewIdOptions): string;
@@ -19,3 +20,4 @@ declare module 'dexie' {
19
20
  };
20
21
  }
21
22
  }
23
+ export {};
@@ -1,6 +1,6 @@
1
1
  import Dexie from 'dexie';
2
2
  import { DBRealm, DBRealmMember } from 'dexie-cloud-common';
3
- export declare type InternalAccessControlData = {
3
+ export type InternalAccessControlData = {
4
4
  readonly selfMembers: DBRealmMember[];
5
5
  readonly realms: DBRealm[];
6
6
  readonly userId: string;
@@ -1,12 +1,12 @@
1
1
  import Dexie from 'dexie';
2
2
  import { DBPermissionSet, DBRealm } from 'dexie-cloud-common';
3
3
  import { Observable } from 'rxjs';
4
- export declare type PermissionsLookup = {
4
+ export type PermissionsLookup = {
5
5
  [realmId: string]: DBRealm & {
6
6
  permissions: DBPermissionSet;
7
7
  };
8
8
  };
9
- export declare type PermissionsLookupObservable = Observable<PermissionsLookup> & {
9
+ export type PermissionsLookupObservable = Observable<PermissionsLookup> & {
10
10
  getValue(): PermissionsLookup;
11
11
  };
12
12
  export declare const getPermissionsLookupObservable: (x: Dexie) => import("./mapValueObservable").ObservableWithCurrentValue<{
@@ -1,3 +1,3 @@
1
1
  import { DexieCloudDB } from "../db/DexieCloudDB";
2
2
  import { PersistedSyncState } from "../db/entities/PersistedSyncState";
3
- export declare function getTablesToSyncify(db: DexieCloudDB, syncState: PersistedSyncState | undefined): import("dexie").Table<import("../db/entities/EntityCommon").EntityCommon, import("dexie").IndexableType, void>[];
3
+ export declare function getTablesToSyncify(db: DexieCloudDB, syncState: PersistedSyncState | undefined): import("dexie").Table<import("../db/entities/EntityCommon").EntityCommon, import("dexie").IndexableType, import("../db/entities/EntityCommon").EntityCommon>[];
@@ -1,7 +1,7 @@
1
1
  import { BehaviorSubject } from 'rxjs';
2
2
  import { DexieCloudDB } from '../db/DexieCloudDB';
3
3
  import { WSConnectionMsg } from '../WSObservable';
4
- export declare type MessagesFromServerConsumer = ReturnType<typeof MessagesFromServerConsumer>;
4
+ export type MessagesFromServerConsumer = ReturnType<typeof MessagesFromServerConsumer>;
5
5
  export declare function MessagesFromServerConsumer(db: DexieCloudDB): {
6
6
  enqueue: (msg: WSConnectionMsg) => void;
7
7
  readyToServe: BehaviorSubject<boolean>;
@@ -1,4 +1,4 @@
1
- export declare type DXCAlert = DXCErrorAlert | DXCWarningAlert | DXCInfoAlert;
1
+ export type DXCAlert = DXCErrorAlert | DXCWarningAlert | DXCInfoAlert;
2
2
  export interface DXCErrorAlert {
3
3
  type: 'error';
4
4
  messageCode: 'INVALID_OTP' | 'INVALID_EMAIL' | 'LICENSE_LIMIT_REACHED' | 'GENERIC_ERROR';
@@ -1,4 +1,4 @@
1
- export declare type DXCInputField = DXCTextField | DXCPasswordField;
1
+ export type DXCInputField = DXCTextField | DXCPasswordField;
2
2
  export interface DXCTextField {
3
3
  type: 'text' | 'email' | 'otp';
4
4
  label?: string;
@@ -1,6 +1,6 @@
1
1
  import { DXCAlert } from './DXCAlert';
2
2
  import { DXCInputField } from './DXCInputField';
3
- export declare type DXCUserInteraction = DXCGenericUserInteraction | DXCEmailPrompt | DXCOTPPrompt | DXCMessageAlert;
3
+ export type DXCUserInteraction = DXCGenericUserInteraction | DXCEmailPrompt | DXCOTPPrompt | DXCMessageAlert;
4
4
  export interface DXCGenericUserInteraction<Type extends string = "generic", TFields extends {
5
5
  [name: string]: DXCInputField;
6
6
  } = any> {
@@ -1,4 +1,4 @@
1
- export declare type SyncEvent = Event & {
1
+ export type SyncEvent = Event & {
2
2
  tag: string;
3
3
  waitUntil(promise: Promise<any>): void;
4
4
  };
@@ -1,5 +1,5 @@
1
- export declare type SyncStatePhase = "initial" | "not-in-sync" | "pushing" | "pulling" | "in-sync" | 'error' | 'offline';
2
- export declare type SyncStatus = "not-started" | "connecting" | "connected" | "disconnected" | "error" | "offline";
1
+ export type SyncStatePhase = "initial" | "not-in-sync" | "pushing" | "pulling" | "in-sync" | 'error' | 'offline';
2
+ export type SyncStatus = "not-started" | "connecting" | "connected" | "disconnected" | "error" | "offline";
3
3
  export interface SyncState {
4
4
  status: SyncStatus;
5
5
  phase: SyncStatePhase;
@@ -108,7 +108,7 @@
108
108
  *
109
109
  * ==========================================================================
110
110
  *
111
- * Version 4.0.0-beta.24, Mon Oct 17 2022
111
+ * Version 4.0.1-beta.27, Mon Mar 06 2023
112
112
  *
113
113
  * https://dexie.org
114
114
  *
@@ -313,7 +313,7 @@
313
313
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
314
314
  }
315
315
  //@ts-check
316
- var randomFillSync = crypto.getRandomValues;
316
+ var randomFillSync = crypto.getRandomValues.bind(crypto);
317
317
  function assert(b) {
318
318
  if (!b)
319
319
  throw new Error('Assertion Failed');
@@ -374,17 +374,17 @@
374
374
  }
375
375
  }
376
376
  }
377
- var randomString$1 = typeof Buffer !== 'undefined' ? function (bytes) {
378
- // Node
379
- var buf = Buffer.alloc(bytes);
380
- randomFillSync(buf);
381
- return buf.toString("base64");
382
- } : function (bytes) {
377
+ var randomString$1 = typeof self !== 'undefined' && typeof crypto !== 'undefined' ? function (bytes) {
383
378
  // Web
384
379
  var buf = new Uint8Array(bytes);
385
380
  crypto.getRandomValues(buf);
386
381
  return btoa(String.fromCharCode.apply(null, buf));
387
- };
382
+ } : typeof Buffer !== 'undefined' ? function (bytes) {
383
+ // Node
384
+ var buf = Buffer.alloc(bytes);
385
+ randomFillSync(buf);
386
+ return buf.toString("base64");
387
+ } : function () { throw new Error("No implementation of randomString was found"); };
388
388
  /** Verifies that given primary key is valid.
389
389
  * The reason we narrow validity for valid keys are twofold:
390
390
  * 1: Make sure to only support types that can be used as an object index in DBKeyMutationSet.
@@ -3591,7 +3591,7 @@
3591
3591
  // serverRev.rev = bigIntDef.bigint.revive(server.rev)
3592
3592
  // else
3593
3593
  // serverRev.rev = new FakeBigInt(server.rev)
3594
- var hasBigIntSupport = typeof BigInt(0) === 'bigint';
3594
+ var hasBigIntSupport = typeof BigInt === 'function' && typeof BigInt(0) === 'bigint';
3595
3595
  var FakeBigInt = /** @class */ (function () {
3596
3596
  function FakeBigInt(value) {
3597
3597
  this.v = value;
@@ -4787,7 +4787,17 @@
4787
4787
  return db.$syncState.get('syncState');
4788
4788
  },
4789
4789
  getSchema: function () {
4790
- return db.$syncState.get('schema');
4790
+ return db.$syncState.get('schema').then(function (schema) {
4791
+ if (schema) {
4792
+ for (var _k = 0, _l = db.tables; _k < _l.length; _k++) {
4793
+ var table = _l[_k];
4794
+ if (table.schema.primKey && table.schema.primKey.keyPath && schema[table.name]) {
4795
+ schema[table.name].primaryKey = nameFromKeyPath(table.schema.primKey.keyPath);
4796
+ }
4797
+ }
4798
+ }
4799
+ return schema;
4800
+ });
4791
4801
  },
4792
4802
  getOptions: function () {
4793
4803
  return db.$syncState.get('options');
@@ -4805,6 +4815,11 @@
4805
4815
  }
4806
4816
  return db;
4807
4817
  }
4818
+ function nameFromKeyPath(keyPath) {
4819
+ return typeof keyPath === 'string' ?
4820
+ keyPath :
4821
+ keyPath ? ('[' + [].join.call(keyPath, '+') + ']') : "";
4822
+ }
4808
4823
  // @ts-ignore
4809
4824
  var isFirefox = typeof InstallTrigger !== 'undefined';
4810
4825
  var isSafari = typeof navigator !== 'undefined' &&
@@ -5052,7 +5067,7 @@
5052
5067
  // modify operations. Reason: Server may not have
5053
5068
  // the object. Object should be created on server only
5054
5069
  // if is being updated. An update operation won't create it
5055
- // so we must delete req.changeSpec to decrate operation to
5070
+ // so we must delete req.changeSpec to degrade operation to
5056
5071
  // an upsert operation with timestamp so that it will be created.
5057
5072
  // We must also degrade from consistent modify operations for the
5058
5073
  // same reason - object might be there on server. Must but put up instead.
@@ -5064,7 +5079,7 @@
5064
5079
  if (req.type === 'put') {
5065
5080
  delete req.criteria;
5066
5081
  delete req.changeSpec;
5067
- delete req.changeSpecs;
5082
+ delete req.updates;
5068
5083
  obj.$ts = Date.now();
5069
5084
  }
5070
5085
  }
@@ -5266,11 +5281,10 @@
5266
5281
  var hasFailures = res.numFailures, failures = res.failures;
5267
5282
  var keys = type === 'delete' ? req.keys : res.results;
5268
5283
  var values = 'values' in req ? req.values : [];
5269
- var changeSpecs = 'changeSpecs' in req ? req.changeSpecs : [];
5284
+ var updates = 'updates' in req && req.updates;
5270
5285
  if (hasFailures) {
5271
5286
  keys = keys.filter(function (_, idx) { return !failures[idx]; });
5272
5287
  values = values.filter(function (_, idx) { return !failures[idx]; });
5273
- changeSpecs = changeSpecs.filter(function (_, idx) { return !failures[idx]; });
5274
5288
  }
5275
5289
  var ts = Date.now();
5276
5290
  var mut = req.type === 'delete'
@@ -5302,13 +5316,13 @@
5302
5316
  txid: txid,
5303
5317
  userId: userId
5304
5318
  }
5305
- : req.changeSpecs
5319
+ : updates
5306
5320
  ? {
5307
5321
  // One changeSpec per key
5308
5322
  type: 'update',
5309
5323
  ts: ts,
5310
- keys: keys,
5311
- changeSpecs: changeSpecs,
5324
+ keys: updates.keys,
5325
+ changeSpecs: updates.changeSpecs,
5312
5326
  txid: txid,
5313
5327
  userId: userId
5314
5328
  }
@@ -6831,10 +6845,10 @@
6831
6845
  return o;
6832
6846
  }
6833
6847
  var getInvitesObservable = associate(function (db) {
6834
- var membersByEmail = getCurrentUserEmitter(db._novip).pipe(rxjs.switchMap(function (currentUser) { return Dexie.liveQuery(function () { return db.members.where({ email: currentUser.email || '' }).toArray(); }); }));
6848
+ var membersByEmail = getCurrentUserEmitter(db._novip).pipe(switchMap(function (currentUser) { return Dexie.liveQuery(function () { return db.members.where({ email: currentUser.email || '' }).toArray(); }); }));
6835
6849
  var permissions = getPermissionsLookupObservable(db._novip);
6836
6850
  var accessControl = getInternalAccessControlObservable(db._novip);
6837
- return createSharedValueObservable(rxjs.combineLatest([membersByEmail, accessControl, permissions]).pipe(rxjs.map(function (_k) {
6851
+ return createSharedValueObservable(rxjs.combineLatest([membersByEmail, accessControl, permissions]).pipe(map(function (_k) {
6838
6852
  var membersByEmail = _k[0], accessControl = _k[1], realmLookup = _k[2];
6839
6853
  var reducer = function (result, m) {
6840
6854
  var _k;
@@ -6922,7 +6936,7 @@
6922
6936
  currentUserEmitter.next(UNAUTHORIZED_USER);
6923
6937
  });
6924
6938
  dexie.cloud = {
6925
- version: '4.0.0-beta.24',
6939
+ version: '4.0.1-beta.27',
6926
6940
  options: Object.assign({}, DEFAULT_OPTIONS),
6927
6941
  schema: null,
6928
6942
  get currentUserId() {
@@ -7082,7 +7096,7 @@
7082
7096
  case 3:
7083
7097
  swRegistrations = _k;
7084
7098
  return [4 /*yield*/, db.transaction('rw', db.$syncState, function () { return __awaiter(_this_1, void 0, void 0, function () {
7085
- var _h, _j, _k, options, schema, _l, persistedOptions, persistedSchema, persistedSyncState, newPersistedSchema, _m, _o, _p, table, tblSchema, newTblSchema;
7099
+ var _h, _j, _k, options, schema, _l, persistedOptions, persistedSchema, persistedSyncState, newPersistedOptions, newPersistedSchema, _m, _o, _p, table, tblSchema, newTblSchema;
7086
7100
  return __generator$1(this, function (_q) {
7087
7101
  switch (_q.label) {
7088
7102
  case 0:
@@ -7105,7 +7119,9 @@
7105
7119
  // Update persisted options:
7106
7120
  if (!options)
7107
7121
  throw new Error("Internal error"); // options cannot be null if configuredProgramatically is set.
7108
- return [4 /*yield*/, db.$syncState.put(options, 'options')];
7122
+ newPersistedOptions = Object.assign({}, options);
7123
+ delete newPersistedOptions.fetchTokens;
7124
+ return [4 /*yield*/, db.$syncState.put(newPersistedOptions, 'options')];
7109
7125
  case 3:
7110
7126
  _q.sent();
7111
7127
  _q.label = 4;
@@ -7253,7 +7269,7 @@
7253
7269
  });
7254
7270
  }
7255
7271
  }
7256
- dexieCloud.version = '4.0.0-beta.24';
7272
+ dexieCloud.version = '4.0.1-beta.27';
7257
7273
  Dexie__default["default"].Cloud = dexieCloud;
7258
7274
 
7259
7275
  exports["default"] = dexieCloud;