dexie-cloud-common 1.0.17
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/dist/BaseRevisionMapEntry.d.ts +6 -0
- package/dist/BaseRevisionMapEntry.d.ts.map +1 -0
- package/dist/BaseRevisionMapEntry.js +1 -0
- package/dist/DBOperation.d.ts +58 -0
- package/dist/DBOperation.d.ts.map +1 -0
- package/dist/DBOperation.js +1 -0
- package/dist/DBOperationsSet.d.ts +6 -0
- package/dist/DBOperationsSet.d.ts.map +1 -0
- package/dist/DBOperationsSet.js +1 -0
- package/dist/DBPermissionSet.d.ts +8 -0
- package/dist/DBPermissionSet.d.ts.map +1 -0
- package/dist/DBPermissionSet.js +1 -0
- package/dist/DexieCloudSchema.d.ts +10 -0
- package/dist/DexieCloudSchema.d.ts.map +1 -0
- package/dist/DexieCloudSchema.js +1 -0
- package/dist/SyncRequest.d.ts +17 -0
- package/dist/SyncRequest.d.ts.map +1 -0
- package/dist/SyncRequest.js +1 -0
- package/dist/SyncResponse.d.ts +16 -0
- package/dist/SyncResponse.d.ts.map +1 -0
- package/dist/SyncResponse.js +1 -0
- package/dist/change-processing/DBKeyMutation.d.ts +15 -0
- package/dist/change-processing/DBKeyMutation.d.ts.map +1 -0
- package/dist/change-processing/DBKeyMutation.js +1 -0
- package/dist/change-processing/DBKeyMutationSet.d.ts +7 -0
- package/dist/change-processing/DBKeyMutationSet.d.ts.map +1 -0
- package/dist/change-processing/DBKeyMutationSet.js +1 -0
- package/dist/change-processing/applyOperation.d.ts +4 -0
- package/dist/change-processing/applyOperation.d.ts.map +1 -0
- package/dist/change-processing/applyOperation.js +57 -0
- package/dist/change-processing/applyOperations.d.ts +4 -0
- package/dist/change-processing/applyOperations.d.ts.map +1 -0
- package/dist/change-processing/applyOperations.js +8 -0
- package/dist/change-processing/subtractChanges.d.ts +4 -0
- package/dist/change-processing/subtractChanges.d.ts.map +1 -0
- package/dist/change-processing/subtractChanges.js +57 -0
- package/dist/change-processing/toDBOperationSet.d.ts +10 -0
- package/dist/change-processing/toDBOperationSet.d.ts.map +1 -0
- package/dist/change-processing/toDBOperationSet.js +63 -0
- package/dist/entities/DBRealm.d.ts +6 -0
- package/dist/entities/DBRealm.d.ts.map +1 -0
- package/dist/entities/DBRealm.js +1 -0
- package/dist/entities/DBRealmMember.d.ts +20 -0
- package/dist/entities/DBRealmMember.d.ts.map +1 -0
- package/dist/entities/DBRealmMember.js +1 -0
- package/dist/entities/DBRealmRole.d.ts +7 -0
- package/dist/entities/DBRealmRole.d.ts.map +1 -0
- package/dist/entities/DBRealmRole.js +1 -0
- package/dist/entities/DBSyncedObject.d.ts +5 -0
- package/dist/entities/DBSyncedObject.d.ts.map +1 -0
- package/dist/entities/DBSyncedObject.js +1 -0
- package/dist/getDbNameFromDbUrl.d.ts +2 -0
- package/dist/getDbNameFromDbUrl.d.ts.map +1 -0
- package/dist/getDbNameFromDbUrl.js +6 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/types.d.ts +91 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +68 -0
- package/dist/validation/isValidSyncableID.d.ts +14 -0
- package/dist/validation/isValidSyncableID.d.ts.map +1 -0
- package/dist/validation/isValidSyncableID.js +35 -0
- package/dist/validation/toStringTag.d.ts +2 -0
- package/dist/validation/toStringTag.d.ts.map +1 -0
- package/dist/validation/toStringTag.js +4 -0
- package/package.json +19 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseRevisionMapEntry.d.ts","sourceRoot":"","sources":["../src/BaseRevisionMapEntry.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,GAAG,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
declare const enum DBCoreRangeType {
|
|
2
|
+
Equal = 1,
|
|
3
|
+
Range = 2,
|
|
4
|
+
Any = 3,
|
|
5
|
+
Never = 4
|
|
6
|
+
}
|
|
7
|
+
/** This interface must be identical to the interface with same name in dexie.
|
|
8
|
+
* If DBCore ever gets moved out from dexie we could let it be referenced.
|
|
9
|
+
* We could also be dependent on dexie but it would be a pitty just for this reason.
|
|
10
|
+
*/
|
|
11
|
+
interface DBCoreKeyRange {
|
|
12
|
+
readonly type: DBCoreRangeType | number;
|
|
13
|
+
readonly lower: any;
|
|
14
|
+
readonly lowerOpen?: boolean;
|
|
15
|
+
readonly upper: any;
|
|
16
|
+
readonly upperOpen?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare type DBOperation = DBInsertOperation | DBUpsertOperation | DBUpdateOperation | DBModifyOperation | DBDeleteOperation;
|
|
19
|
+
export interface DBOperationCommon {
|
|
20
|
+
rev?: number;
|
|
21
|
+
ts?: number | null;
|
|
22
|
+
keys: any[];
|
|
23
|
+
txid?: string | null;
|
|
24
|
+
userId?: string | null;
|
|
25
|
+
}
|
|
26
|
+
export interface DBInsertOperation extends DBOperationCommon {
|
|
27
|
+
type: "insert";
|
|
28
|
+
values: any[];
|
|
29
|
+
}
|
|
30
|
+
export interface DBUpsertOperation extends DBOperationCommon {
|
|
31
|
+
type: "upsert";
|
|
32
|
+
values: any[];
|
|
33
|
+
}
|
|
34
|
+
export interface DBUpdateOperation extends DBOperationCommon {
|
|
35
|
+
type: "update";
|
|
36
|
+
changeSpecs: {
|
|
37
|
+
[keyPath: string]: any;
|
|
38
|
+
}[];
|
|
39
|
+
}
|
|
40
|
+
export interface DBModifyOperation extends DBOperationCommon {
|
|
41
|
+
type: "modify";
|
|
42
|
+
criteria: {
|
|
43
|
+
index: string | null;
|
|
44
|
+
range: DBCoreKeyRange;
|
|
45
|
+
};
|
|
46
|
+
changeSpec: {
|
|
47
|
+
[keyPath: string]: any;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export interface DBDeleteOperation extends DBOperationCommon {
|
|
51
|
+
type: "delete";
|
|
52
|
+
criteria?: {
|
|
53
|
+
index: string | null;
|
|
54
|
+
range: DBCoreKeyRange;
|
|
55
|
+
} | false;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=DBOperation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DBOperation.d.ts","sourceRoot":"","sources":["../src/DBOperation.ts"],"names":[],"mappings":"AAAA,mBAAW,eAAe;IACxB,KAAK,IAAI;IACT,KAAK,IAAI;IACT,GAAG,IAAI;IACP,KAAK,IAAI;CACV;AAED;;;EAGE;AACF,UAAU,cAAc;IACtB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC;IACpB,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC;IACpB,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,oBAAY,WAAW,GACnB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,CAAC;AAEtB,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AACD,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,GAAG,EAAE,CAAC;CACf;AAED,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,GAAG,EAAE,CAAC;CACf;AAED,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,IAAI,EAAE,QAAQ,CAAC;IACf,WAAW,EAAE;QAAE,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,EAAE,CAAC;CAC3C;AAED,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,EAAE;QACR,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,KAAK,EAAE,cAAc,CAAC;KACvB,CAAC;IACF,UAAU,EAAE;QAAE,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;CACxC;AAGD,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,CAAC,EACL;QACE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,KAAK,EAAE,cAAc,CAAC;KACvB,GACD,KAAK,CAAC;CACX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DBOperationsSet.d.ts","sourceRoot":"","sources":["../src/DBOperationsSet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,oBAAY,eAAe,GAAG,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,WAAW,EAAE,CAAA;CAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DBPermissionSet.d.ts","sourceRoot":"","sources":["../src/DBPermissionSet.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,CAAC;IACrB,MAAM,CAAC,EACH,GAAG,GACH;QACE,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,GAAG,CAAC;KACrC,CAAC;IACN,MAAM,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DexieCloudSchema.d.ts","sourceRoot":"","sources":["../src/DexieCloudSchema.ts"],"names":[],"mappings":"AAAA,oBAAY,gBAAgB,GAAG;IAC7B,CAAC,SAAS,EAAE,MAAM,GAAG;QACnB,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseRevisionMapEntry } from './BaseRevisionMapEntry.js';
|
|
2
|
+
import { DBOperationsSet } from './DBOperationsSet.js';
|
|
3
|
+
import { DexieCloudSchema } from './DexieCloudSchema.js';
|
|
4
|
+
export interface SyncRequest {
|
|
5
|
+
v?: number;
|
|
6
|
+
dbID?: string;
|
|
7
|
+
clientIdentity?: string;
|
|
8
|
+
schema: DexieCloudSchema;
|
|
9
|
+
lastPull?: {
|
|
10
|
+
serverRevision: string | bigint;
|
|
11
|
+
realms: string[];
|
|
12
|
+
inviteRealms: string[];
|
|
13
|
+
};
|
|
14
|
+
baseRevs: BaseRevisionMapEntry[];
|
|
15
|
+
changes: DBOperationsSet;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=SyncRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncRequest.d.ts","sourceRoot":"","sources":["../src/SyncRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,WAAW,WAAW;IAC1B,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,gBAAgB,CAAC;IACzB,QAAQ,CAAC,EAAE;QACT,cAAc,EAAE,MAAM,GAAG,MAAM,CAAC;QAChC,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,YAAY,EAAE,MAAM,EAAE,CAAC;KACxB,CAAC;IACF,QAAQ,EAAE,oBAAoB,EAAE,CAAC;IACjC,OAAO,EAAE,eAAe,CAAC;CAE1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DBOperationsSet } from './DBOperationsSet.js';
|
|
2
|
+
import { DexieCloudSchema } from './DexieCloudSchema.js';
|
|
3
|
+
export interface SyncResponse {
|
|
4
|
+
serverRevision: string | bigint;
|
|
5
|
+
dbId: string;
|
|
6
|
+
realms: string[];
|
|
7
|
+
inviteRealms: string[];
|
|
8
|
+
schema: DexieCloudSchema;
|
|
9
|
+
changes: DBOperationsSet;
|
|
10
|
+
rejections: {
|
|
11
|
+
name: string;
|
|
12
|
+
message: string;
|
|
13
|
+
txid: string;
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=SyncResponse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncResponse.d.ts","sourceRoot":"","sources":["../src/SyncResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,EAAE,gBAAgB,CAAC;IACzB,OAAO,EAAE,eAAe,CAAC;IACzB,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAE/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare type DBKeyMutation = DBKeyUpsert | DBKeyUpdate | DBKeyDelete;
|
|
2
|
+
export interface DBKeyUpsert {
|
|
3
|
+
type: "ups";
|
|
4
|
+
val: any;
|
|
5
|
+
}
|
|
6
|
+
export interface DBKeyUpdate {
|
|
7
|
+
type: "upd";
|
|
8
|
+
mod: {
|
|
9
|
+
[keyPath: string]: any;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface DBKeyDelete {
|
|
13
|
+
type: "del";
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=DBKeyMutation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DBKeyMutation.d.ts","sourceRoot":"","sources":["../../src/change-processing/DBKeyMutation.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa,GACrB,WAAW,GACX,WAAW,GACX,WAAW,CAAC;AAEhB,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,GAAG,CAAC;CACV;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE;QAAE,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;CACjC;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,KAAK,CAAC;CACb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DBKeyMutationSet.d.ts","sourceRoot":"","sources":["../../src/change-processing/DBKeyMutationSet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,oBAAY,gBAAgB,GAAG;IAC7B,CAAC,SAAS,EAAE,MAAM,GAAG;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAA;KAAE,CAAC;CACvD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyOperation.d.ts","sourceRoot":"","sources":["../../src/change-processing/applyOperation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,WAAW,oBAuDhB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { setByKeyPath } from "../utils.js";
|
|
2
|
+
export function applyOperation(target, table, op) {
|
|
3
|
+
const tbl = target[table] || (target[table] = {});
|
|
4
|
+
switch (op.type) {
|
|
5
|
+
case "insert":
|
|
6
|
+
// TODO: Don't treat insert and upsert the same?
|
|
7
|
+
case "upsert":
|
|
8
|
+
op.keys.forEach((key, idx) => {
|
|
9
|
+
tbl[key] = {
|
|
10
|
+
type: "ups",
|
|
11
|
+
val: op.values[idx],
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
break;
|
|
15
|
+
case "update":
|
|
16
|
+
case "modify": {
|
|
17
|
+
op.keys.forEach((key, idx) => {
|
|
18
|
+
const changeSpec = op.type === "update"
|
|
19
|
+
? op.changeSpecs[idx]
|
|
20
|
+
: op.changeSpec;
|
|
21
|
+
const entry = tbl[key];
|
|
22
|
+
if (!entry) {
|
|
23
|
+
tbl[key] = {
|
|
24
|
+
type: "upd",
|
|
25
|
+
mod: changeSpec,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
switch (entry.type) {
|
|
30
|
+
case "ups":
|
|
31
|
+
// Adjust the existing upsert with additional updates
|
|
32
|
+
for (const [propPath, value] of Object.entries(changeSpec)) {
|
|
33
|
+
setByKeyPath(entry.val, propPath, value);
|
|
34
|
+
}
|
|
35
|
+
break;
|
|
36
|
+
case "del":
|
|
37
|
+
// No action.
|
|
38
|
+
break;
|
|
39
|
+
case "upd":
|
|
40
|
+
// Adjust existing update with additional updates
|
|
41
|
+
Object.assign(entry.mod, changeSpec); // May work for deep props as well - new keys is added later, right? Does the prop order persist along TSON and all? But it will not be 100% when combined with some server code (seach for "address.city": "Stockholm" comment)
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case "delete":
|
|
49
|
+
op.keys.forEach((key) => {
|
|
50
|
+
tbl[key] = {
|
|
51
|
+
type: "del",
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
return target;
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyOperations.d.ts","sourceRoot":"","sources":["../../src/change-processing/applyOperations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,wBAAgB,eAAe,CAAC,MAAM,EAAE,gBAAgB,EAAE,GAAG,EAAE,eAAe,QAM7E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subtractChanges.d.ts","sourceRoot":"","sources":["../../src/change-processing/subtractChanges.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,gBAAgB,EAAE,oBAAoB;AAC9C,iBAAiB,EAAE,gBAAgB,QAqDpC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { setByKeyPath } from '../utils.js';
|
|
2
|
+
export function subtractChanges(target, // Server change set
|
|
3
|
+
changesToSubtract // additional mutations on client during syncWithServer()
|
|
4
|
+
) {
|
|
5
|
+
var _a, _b, _c;
|
|
6
|
+
for (const [table, mutationSet] of Object.entries(changesToSubtract)) {
|
|
7
|
+
for (const [key, mut] of Object.entries(mutationSet)) {
|
|
8
|
+
switch (mut.type) {
|
|
9
|
+
case 'ups':
|
|
10
|
+
{
|
|
11
|
+
const targetMut = (_a = target[table]) === null || _a === void 0 ? void 0 : _a[key];
|
|
12
|
+
if (targetMut) {
|
|
13
|
+
switch (targetMut.type) {
|
|
14
|
+
case 'ups':
|
|
15
|
+
delete target[table][key];
|
|
16
|
+
break;
|
|
17
|
+
case 'del':
|
|
18
|
+
// Leave delete operation.
|
|
19
|
+
// (Don't resurrect objects unintenionally (using tx(get, put) pattern locally))
|
|
20
|
+
break;
|
|
21
|
+
case 'upd':
|
|
22
|
+
delete target[table][key];
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
break;
|
|
28
|
+
case 'del':
|
|
29
|
+
(_b = target[table]) === null || _b === void 0 ? true : delete _b[key];
|
|
30
|
+
break;
|
|
31
|
+
case 'upd': {
|
|
32
|
+
const targetMut = (_c = target[table]) === null || _c === void 0 ? void 0 : _c[key];
|
|
33
|
+
if (targetMut) {
|
|
34
|
+
switch (targetMut.type) {
|
|
35
|
+
case 'ups':
|
|
36
|
+
// Adjust the server upsert with locally updated values.
|
|
37
|
+
for (const [propPath, value] of Object.entries(mut.mod)) {
|
|
38
|
+
setByKeyPath(targetMut.val, propPath, value);
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
case 'del':
|
|
42
|
+
// Leave delete.
|
|
43
|
+
break;
|
|
44
|
+
case 'upd':
|
|
45
|
+
// Remove the local update props from the server update mutation.
|
|
46
|
+
for (const propPath of Object.keys(mut.mod)) {
|
|
47
|
+
delete targetMut.mod[propPath];
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DBOperationsSet } from "../DBOperationsSet.js";
|
|
2
|
+
import { DBKeyMutationSet } from "./DBKeyMutationSet.js";
|
|
3
|
+
/** Convert a DBKeyMutationSet (which is an internal format capable of looking up changes per ID)
|
|
4
|
+
* ...into a DBOperationsSet (which is more optimal for performing DB operations into DB (bulkAdd() etc))
|
|
5
|
+
*
|
|
6
|
+
* @param inSet
|
|
7
|
+
* @returns DBOperationsSet representing inSet
|
|
8
|
+
*/
|
|
9
|
+
export declare function toDBOperationSet(inSet: DBKeyMutationSet): DBOperationsSet;
|
|
10
|
+
//# sourceMappingURL=toDBOperationSet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toDBOperationSet.d.ts","sourceRoot":"","sources":["../../src/change-processing/toDBOperationSet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,GAAG,eAAe,CA6DzE"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { randomString } from "../utils.js";
|
|
2
|
+
/** Convert a DBKeyMutationSet (which is an internal format capable of looking up changes per ID)
|
|
3
|
+
* ...into a DBOperationsSet (which is more optimal for performing DB operations into DB (bulkAdd() etc))
|
|
4
|
+
*
|
|
5
|
+
* @param inSet
|
|
6
|
+
* @returns DBOperationsSet representing inSet
|
|
7
|
+
*/
|
|
8
|
+
export function toDBOperationSet(inSet) {
|
|
9
|
+
// Fictive transaction:
|
|
10
|
+
const txid = randomString(16);
|
|
11
|
+
// Convert data into a temporary map to collect mutations of same table and type
|
|
12
|
+
const map = {};
|
|
13
|
+
for (const [table, ops] of Object.entries(inSet)) {
|
|
14
|
+
for (const [key, op] of Object.entries(ops)) {
|
|
15
|
+
const mapEntry = map[table] || (map[table] = {});
|
|
16
|
+
const ops = mapEntry[op.type] || (mapEntry[op.type] = []);
|
|
17
|
+
ops.push(Object.assign({ key }, op)); // DBKeyMutation doesn't contain key, so we need to bring it in.
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// Start computing the resulting format:
|
|
21
|
+
const result = [];
|
|
22
|
+
for (const [table, ops] of Object.entries(map)) {
|
|
23
|
+
const resultEntry = {
|
|
24
|
+
table,
|
|
25
|
+
muts: [],
|
|
26
|
+
};
|
|
27
|
+
for (const [optype, muts] of Object.entries(ops)) {
|
|
28
|
+
switch (optype) {
|
|
29
|
+
case "ups": {
|
|
30
|
+
const op = {
|
|
31
|
+
type: "upsert",
|
|
32
|
+
keys: muts.map(mut => mut.key),
|
|
33
|
+
values: muts.map(mut => mut.val),
|
|
34
|
+
txid
|
|
35
|
+
};
|
|
36
|
+
resultEntry.muts.push(op);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case "upd": {
|
|
40
|
+
const op = {
|
|
41
|
+
type: "update",
|
|
42
|
+
keys: muts.map(mut => mut.key),
|
|
43
|
+
changeSpecs: muts.map(mut => mut.mod),
|
|
44
|
+
txid
|
|
45
|
+
};
|
|
46
|
+
resultEntry.muts.push(op);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case "del": {
|
|
50
|
+
const op = {
|
|
51
|
+
type: "delete",
|
|
52
|
+
keys: muts.map(mut => mut.key),
|
|
53
|
+
txid,
|
|
54
|
+
};
|
|
55
|
+
resultEntry.muts.push(op);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
result.push(resultEntry);
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DBRealm.d.ts","sourceRoot":"","sources":["../../src/entities/DBRealm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,WAAW,OAAQ,SAAQ,cAAc;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DBPermissionSet } from '../DBPermissionSet.js';
|
|
2
|
+
import { DBSyncedObject } from './DBSyncedObject.js';
|
|
3
|
+
export interface DBRealmMember extends DBSyncedObject {
|
|
4
|
+
id?: string;
|
|
5
|
+
userId?: string;
|
|
6
|
+
email?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
invite?: boolean;
|
|
9
|
+
invitedDate?: Date;
|
|
10
|
+
invitedBy?: {
|
|
11
|
+
name: string;
|
|
12
|
+
email: string;
|
|
13
|
+
userId: string;
|
|
14
|
+
};
|
|
15
|
+
accepted?: Date;
|
|
16
|
+
rejected?: Date;
|
|
17
|
+
roles?: string[];
|
|
18
|
+
permissions?: DBPermissionSet;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=DBRealmMember.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DBRealmMember.d.ts","sourceRoot":"","sources":["../../src/entities/DBRealmMember.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,WAAW,aAAc,SAAQ,cAAc;IACnD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,IAAI,CAAC;IACnB,SAAS,CAAC,EAAE;QACV,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAA;IACD,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DBRealmRole.d.ts","sourceRoot":"","sources":["../../src/entities/DBRealmRole.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,WAAW,WAAY,SAAQ,cAAc;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,eAAe,CAAC;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DBSyncedObject.d.ts","sourceRoot":"","sources":["../../src/entities/DBSyncedObject.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDbNameFromDbUrl.d.ts","sourceRoot":"","sources":["../src/getDbNameFromDbUrl.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,UAMd"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./BaseRevisionMapEntry.js";
|
|
3
|
+
export * from "./SyncRequest.js";
|
|
4
|
+
export * from "./SyncResponse.js";
|
|
5
|
+
export * from "./utils.js";
|
|
6
|
+
export * from "./DexieCloudSchema.js";
|
|
7
|
+
export * from "./DBOperationsSet.js";
|
|
8
|
+
export * from "./DBOperation.js";
|
|
9
|
+
export * from "./validation/isValidSyncableID.js";
|
|
10
|
+
export * from "./change-processing/applyOperation.js";
|
|
11
|
+
export * from "./change-processing/applyOperations.js";
|
|
12
|
+
export * from "./change-processing/DBKeyMutation.js";
|
|
13
|
+
export * from "./change-processing/DBKeyMutationSet.js";
|
|
14
|
+
export * from "./change-processing/subtractChanges.js";
|
|
15
|
+
export * from "./change-processing/toDBOperationSet.js";
|
|
16
|
+
export * from "./DBPermissionSet.js";
|
|
17
|
+
export * from "./entities/DBRealm.js";
|
|
18
|
+
export * from "./entities/DBRealmMember.js";
|
|
19
|
+
export * from "./entities/DBRealmRole.js";
|
|
20
|
+
export * from "./entities/DBSyncedObject.js";
|
|
21
|
+
export * from "./getDbNameFromDbUrl.js";
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,2BAA2B,CAAA;AACzC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mCAAmC,CAAA;AACjD,cAAc,uCAAuC,CAAA;AACrD,cAAc,wCAAwC,CAAA;AACtD,cAAc,sCAAsC,CAAA;AACpD,cAAc,yCAAyC,CAAA;AACvD,cAAc,wCAAwC,CAAA;AACtD,cAAc,yCAAyC,CAAA;AACvD,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./BaseRevisionMapEntry.js";
|
|
3
|
+
export * from "./SyncRequest.js";
|
|
4
|
+
export * from "./SyncResponse.js";
|
|
5
|
+
export * from "./utils.js";
|
|
6
|
+
export * from "./DexieCloudSchema.js";
|
|
7
|
+
export * from "./DBOperationsSet.js";
|
|
8
|
+
export * from "./DBOperation.js";
|
|
9
|
+
export * from "./validation/isValidSyncableID.js";
|
|
10
|
+
export * from "./change-processing/applyOperation.js";
|
|
11
|
+
export * from "./change-processing/applyOperations.js";
|
|
12
|
+
export * from "./change-processing/DBKeyMutation.js";
|
|
13
|
+
export * from "./change-processing/DBKeyMutationSet.js";
|
|
14
|
+
export * from "./change-processing/subtractChanges.js";
|
|
15
|
+
export * from "./change-processing/toDBOperationSet.js";
|
|
16
|
+
export * from "./DBPermissionSet.js";
|
|
17
|
+
export * from "./entities/DBRealm.js";
|
|
18
|
+
export * from "./entities/DBRealmMember.js";
|
|
19
|
+
export * from "./entities/DBRealmRole.js";
|
|
20
|
+
export * from "./entities/DBSyncedObject.js";
|
|
21
|
+
export * from "./getDbNameFromDbUrl.js";
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export declare type TokenRequest = OTPTokenRequest | ClientCredentialsTokenRequest | RefreshTokenRequest | DemoTokenRequest;
|
|
2
|
+
export interface OTPTokenRequest {
|
|
3
|
+
grant_type: 'otp';
|
|
4
|
+
public_key?: string;
|
|
5
|
+
email: string;
|
|
6
|
+
scopes: string[];
|
|
7
|
+
otp_id?: string;
|
|
8
|
+
otp?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ClientCredentialsTokenRequest {
|
|
11
|
+
grant_type: 'client_credentials';
|
|
12
|
+
client_id: string;
|
|
13
|
+
client_secret: string;
|
|
14
|
+
public_key?: string;
|
|
15
|
+
scopes: string[];
|
|
16
|
+
claims?: {
|
|
17
|
+
sub: string;
|
|
18
|
+
email?: string;
|
|
19
|
+
email_verified?: string;
|
|
20
|
+
[customClaim: string]: any;
|
|
21
|
+
};
|
|
22
|
+
expires_in?: string;
|
|
23
|
+
not_before?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface RefreshTokenRequest {
|
|
26
|
+
grant_type: 'refresh_token';
|
|
27
|
+
scopes: string[];
|
|
28
|
+
public_key?: string;
|
|
29
|
+
refresh_token: string;
|
|
30
|
+
time_stamp: number;
|
|
31
|
+
signing_algorithm: string;
|
|
32
|
+
signature: string;
|
|
33
|
+
}
|
|
34
|
+
export interface DemoTokenRequest {
|
|
35
|
+
grant_type: 'demo';
|
|
36
|
+
scopes: ['ACCESS_DB'];
|
|
37
|
+
demo_user: string;
|
|
38
|
+
public_key?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface TokenFinalResponse {
|
|
41
|
+
type: 'tokens';
|
|
42
|
+
claims: {
|
|
43
|
+
sub: string;
|
|
44
|
+
[claimName: string]: any;
|
|
45
|
+
};
|
|
46
|
+
accessToken: string;
|
|
47
|
+
accessTokenExpiration: number;
|
|
48
|
+
refreshToken?: string;
|
|
49
|
+
refreshTokenExpiration?: number | null;
|
|
50
|
+
alerts?: {
|
|
51
|
+
type: 'warning' | 'info';
|
|
52
|
+
messageCode: string;
|
|
53
|
+
message: string;
|
|
54
|
+
messageParams?: {
|
|
55
|
+
[param: string]: string;
|
|
56
|
+
};
|
|
57
|
+
}[];
|
|
58
|
+
}
|
|
59
|
+
export interface TokenOtpSentResponse {
|
|
60
|
+
type: 'otp-sent';
|
|
61
|
+
otp_id: string;
|
|
62
|
+
}
|
|
63
|
+
/** Can be returned when grant_type="refresh_token" if the given time_stamp differs too much
|
|
64
|
+
* from server time. Will happen if the client's clock differs too much from the server.
|
|
65
|
+
* Client should then retry the token request using grant_type="refresh_token" again but
|
|
66
|
+
* regenerate the signature from (server_time + refresh_token).
|
|
67
|
+
*/
|
|
68
|
+
export interface TokenResponseInvalidTimestamp {
|
|
69
|
+
type: 'invalid-timestamp';
|
|
70
|
+
server_time: number;
|
|
71
|
+
message: string;
|
|
72
|
+
}
|
|
73
|
+
export declare type TokenResponse = TokenFinalResponse | TokenOtpSentResponse | TokenResponseInvalidTimestamp;
|
|
74
|
+
export interface CreateDbResponse {
|
|
75
|
+
url: string;
|
|
76
|
+
clientId: string;
|
|
77
|
+
clientSecret: string;
|
|
78
|
+
}
|
|
79
|
+
export interface WhitelistRequest {
|
|
80
|
+
origin?: string;
|
|
81
|
+
delete?: boolean;
|
|
82
|
+
}
|
|
83
|
+
export declare type WhitelistResponse = number | string[];
|
|
84
|
+
export declare type ClientsResponse = DXCClient[];
|
|
85
|
+
export interface DXCClient {
|
|
86
|
+
id: string;
|
|
87
|
+
email: string;
|
|
88
|
+
emailVerified: boolean;
|
|
89
|
+
scopes: string[];
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"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"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function assert(b: boolean): asserts b is true;
|
|
2
|
+
declare type SetByKeyPathTarget = {
|
|
3
|
+
[keyPath: string]: SetByKeyPathTarget;
|
|
4
|
+
} | SetByKeyPathTarget[];
|
|
5
|
+
export declare function setByKeyPath(obj: SetByKeyPathTarget, keyPath: string | ArrayLike<string>, value: any): void;
|
|
6
|
+
export declare const randomString: (bytes: number) => string;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,IAAI,IAAI,CAEpD;AAED,aAAK,kBAAkB,GACnB;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAAA;CAAE,GACzC,kBAAkB,EAAE,CAAC;AAEzB,wBAAgB,YAAY,CAC1B,GAAG,EAAE,kBAAkB,EACvB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,EACnC,KAAK,EAAE,GAAG,QAwCX;AAED,eAAO,MAAM,YAAY,UAAyC,MAAM,WAUvE,CAAA"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { randomFillSync } from "universal-imports";
|
|
2
|
+
export function assert(b) {
|
|
3
|
+
if (!b)
|
|
4
|
+
throw new Error('Assertion Failed');
|
|
5
|
+
}
|
|
6
|
+
export function setByKeyPath(obj, keyPath, value) {
|
|
7
|
+
if (!obj || keyPath === undefined)
|
|
8
|
+
return;
|
|
9
|
+
if ('isFrozen' in Object && Object.isFrozen(obj))
|
|
10
|
+
return;
|
|
11
|
+
if (typeof keyPath !== 'string' && 'length' in keyPath) {
|
|
12
|
+
assert(typeof value !== 'string' && 'length' in value);
|
|
13
|
+
for (var i = 0, l = keyPath.length; i < l; ++i) {
|
|
14
|
+
setByKeyPath(obj, keyPath[i], value[i]);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
var period = keyPath.indexOf('.');
|
|
19
|
+
if (period !== -1) {
|
|
20
|
+
var currentKeyPath = keyPath.substr(0, period);
|
|
21
|
+
var remainingKeyPath = keyPath.substr(period + 1);
|
|
22
|
+
if (remainingKeyPath === '')
|
|
23
|
+
if (value === undefined) {
|
|
24
|
+
if (Array.isArray(obj)) {
|
|
25
|
+
if (!isNaN(parseInt(currentKeyPath)))
|
|
26
|
+
obj.splice(parseInt(currentKeyPath), 1);
|
|
27
|
+
}
|
|
28
|
+
else
|
|
29
|
+
delete obj[currentKeyPath];
|
|
30
|
+
// @ts-ignore: even if currentKeyPath would be numeric string and obj would be array - it works.
|
|
31
|
+
}
|
|
32
|
+
else
|
|
33
|
+
obj[currentKeyPath] = value;
|
|
34
|
+
else {
|
|
35
|
+
//@ts-ignore: even if currentKeyPath would be numeric string and obj would be array - it works.
|
|
36
|
+
var innerObj = obj[currentKeyPath];
|
|
37
|
+
//@ts-ignore: even if currentKeyPath would be numeric string and obj would be array - it works.
|
|
38
|
+
if (!innerObj)
|
|
39
|
+
innerObj = obj[currentKeyPath] = {};
|
|
40
|
+
setByKeyPath(innerObj, remainingKeyPath, value);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
if (value === undefined) {
|
|
45
|
+
if (Array.isArray(obj) && !isNaN(parseInt(keyPath)))
|
|
46
|
+
// @ts-ignore: even if currentKeyPath would be numeric string and obj would be array - it works.
|
|
47
|
+
obj.splice(keyPath, 1);
|
|
48
|
+
//@ts-ignore: even if currentKeyPath would be numeric string and obj would be array - it works.
|
|
49
|
+
else
|
|
50
|
+
delete obj[keyPath];
|
|
51
|
+
//@ts-ignore: even if currentKeyPath would be numeric string and obj would be array - it works.
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
obj[keyPath] = value;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export const randomString = typeof self === 'undefined' ? (bytes) => {
|
|
59
|
+
// Node
|
|
60
|
+
const buf = Buffer.alloc(bytes);
|
|
61
|
+
randomFillSync(buf);
|
|
62
|
+
return buf.toString("base64");
|
|
63
|
+
} : (bytes) => {
|
|
64
|
+
// Web
|
|
65
|
+
const buf = new Uint8Array(bytes);
|
|
66
|
+
crypto.getRandomValues(buf);
|
|
67
|
+
return btoa(String.fromCharCode.apply(null, buf));
|
|
68
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Verifies that given primary key is valid.
|
|
2
|
+
* The reason we narrow validity for valid keys are twofold:
|
|
3
|
+
* 1: Make sure to only support types that can be used as an object index in DBKeyMutationSet.
|
|
4
|
+
* For example, ArrayBuffer cannot be used (gives "object ArrayBuffer") but Uint8Array can be
|
|
5
|
+
* used (gives comma-delimited list of included bytes).
|
|
6
|
+
* 2: Avoid using plain numbers and Dates as keys when they are synced, as they are not globally unique.
|
|
7
|
+
* 3: Since we store the key as a VARCHAR server side in current version, try not promote types that stringifies to become very long server side.
|
|
8
|
+
*
|
|
9
|
+
* @param id
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare function isValidSyncableID(id: any): boolean;
|
|
13
|
+
export declare function isValidAtID(id: any, idPrefix?: string): id is string;
|
|
14
|
+
//# sourceMappingURL=isValidSyncableID.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidSyncableID.d.ts","sourceRoot":"","sources":["../../src/validation/isValidSyncableID.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,GAAG,WAMxC;AAaD,wBAAgB,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,EAAE,IAAI,MAAM,CAEpE"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const validIDTypes = {
|
|
2
|
+
Uint8Array,
|
|
3
|
+
};
|
|
4
|
+
/** Verifies that given primary key is valid.
|
|
5
|
+
* The reason we narrow validity for valid keys are twofold:
|
|
6
|
+
* 1: Make sure to only support types that can be used as an object index in DBKeyMutationSet.
|
|
7
|
+
* For example, ArrayBuffer cannot be used (gives "object ArrayBuffer") but Uint8Array can be
|
|
8
|
+
* used (gives comma-delimited list of included bytes).
|
|
9
|
+
* 2: Avoid using plain numbers and Dates as keys when they are synced, as they are not globally unique.
|
|
10
|
+
* 3: Since we store the key as a VARCHAR server side in current version, try not promote types that stringifies to become very long server side.
|
|
11
|
+
*
|
|
12
|
+
* @param id
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export function isValidSyncableID(id) {
|
|
16
|
+
if (typeof id === "string")
|
|
17
|
+
return true;
|
|
18
|
+
//if (validIDTypes[toStringTag(id)]) return true;
|
|
19
|
+
//if (Array.isArray(id)) return id.every((part) => isValidSyncableID(part));
|
|
20
|
+
if (Array.isArray(id) && id.some(key => isValidSyncableID(key)) && id.every(isValidSyncableIDPart))
|
|
21
|
+
return true;
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
/** Verifies that given key part is valid.
|
|
25
|
+
* 1: Make sure that arrays of this types are stringified correclty and works with DBKeyMutationSet.
|
|
26
|
+
* For example, ArrayBuffer cannot be used (gives "object ArrayBuffer") but Uint8Array can be
|
|
27
|
+
* used (gives comma-delimited list of included bytes).
|
|
28
|
+
* 2: Since we store the key as a VARCHAR server side in current version, try not promote types that stringifies to become very long server side.
|
|
29
|
+
*/
|
|
30
|
+
function isValidSyncableIDPart(part) {
|
|
31
|
+
return typeof part === "string" || typeof part === "number" || Array.isArray(part) && part.every(isValidSyncableIDPart);
|
|
32
|
+
}
|
|
33
|
+
export function isValidAtID(id, idPrefix) {
|
|
34
|
+
return !idPrefix || (typeof id === "string" && id.startsWith(idPrefix));
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toStringTag.d.ts","sourceRoot":"","sources":["../../src/validation/toStringTag.ts"],"names":[],"mappings":"AACA,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,UAEpC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dexie-cloud-common",
|
|
3
|
+
"version": "1.0.17",
|
|
4
|
+
"description": "Library for shared code between dexie-cloud-addon, dexie-cloud (CLI) and dexie-cloud-server",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"exports": "./dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"prepare": "tsc",
|
|
12
|
+
"tsver": "tsc --version"
|
|
13
|
+
},
|
|
14
|
+
"author": "David Fahlander",
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"universal-imports": "^1.0.1"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": ["es2020", "dom"],
|
|
4
|
+
"moduleResolution": "node",
|
|
5
|
+
"target": "es2017",
|
|
6
|
+
"module": "esnext",
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"rootDir": "src",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"noImplicitAny": false,
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"declarationMap": true,
|
|
13
|
+
"allowSyntheticDefaultImports": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["./src"]
|
|
16
|
+
}
|