@powersync/service-core 0.0.0-dev-20241219091224 → 0.0.0-dev-20241219145106
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/CHANGELOG.md +6 -4
- package/dist/storage/bson.d.ts +24 -0
- package/dist/storage/bson.js +73 -0
- package/dist/storage/bson.js.map +1 -0
- package/dist/storage/storage-index.d.ts +1 -0
- package/dist/storage/storage-index.js +1 -0
- package/dist/storage/storage-index.js.map +1 -1
- package/package.json +5 -5
- package/src/storage/bson.ts +78 -0
- package/src/storage/storage-index.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @powersync/service-core
|
|
2
2
|
|
|
3
|
-
## 0.0.0-dev-
|
|
3
|
+
## 0.0.0-dev-20241219145106
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
|
|
11
11
|
- 697d44b: Updated ts-codec to 1.3.0 for better decode error responses
|
|
12
12
|
- Updated dependencies [697d44b]
|
|
13
|
+
- Updated dependencies [697d44b]
|
|
13
14
|
- Updated dependencies [a66be3b]
|
|
14
15
|
- Updated dependencies [697d44b]
|
|
15
|
-
- @powersync/lib-services-framework@0.0.0-dev-
|
|
16
|
-
- @powersync/service-sync-rules@0.0.0-dev-
|
|
17
|
-
- @powersync/service-
|
|
16
|
+
- @powersync/lib-services-framework@0.0.0-dev-20241219145106
|
|
17
|
+
- @powersync/service-sync-rules@0.0.0-dev-20241219145106
|
|
18
|
+
- @powersync/service-types@0.0.0-dev-20241219145106
|
|
19
|
+
- @powersync/service-rsocket-router@0.0.0-dev-20241219145106
|
|
18
20
|
|
|
19
21
|
## 0.12.2
|
|
20
22
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as bson from 'bson';
|
|
2
|
+
import { SqliteJsonValue } from '@powersync/service-sync-rules';
|
|
3
|
+
import { ReplicaId } from './BucketStorage.js';
|
|
4
|
+
export declare const BSON_DESERIALIZE_OPTIONS: bson.DeserializeOptions;
|
|
5
|
+
/**
|
|
6
|
+
* Lookup serialization must be number-agnostic. I.e. normalize numbers, instead of preserving numbers.
|
|
7
|
+
* @param lookup
|
|
8
|
+
*/
|
|
9
|
+
export declare const serializeLookupBuffer: (lookup: SqliteJsonValue[]) => Buffer;
|
|
10
|
+
export declare const serializeLookup: (lookup: SqliteJsonValue[]) => bson.Binary;
|
|
11
|
+
/**
|
|
12
|
+
* True if this is a bson.UUID.
|
|
13
|
+
*
|
|
14
|
+
* Works even with multiple copies of the bson package.
|
|
15
|
+
*/
|
|
16
|
+
export declare const isUUID: (value: any) => value is bson.UUID;
|
|
17
|
+
export declare const serializeReplicaId: (id: ReplicaId) => Buffer;
|
|
18
|
+
export declare const deserializeReplicaId: (id: Buffer) => ReplicaId;
|
|
19
|
+
export declare const deserializeBson: (buffer: Buffer) => bson.Document;
|
|
20
|
+
export declare const serializeBson: (document: any) => Buffer;
|
|
21
|
+
/**
|
|
22
|
+
* Returns true if two ReplicaId values are the same (serializes to the same BSON value).
|
|
23
|
+
*/
|
|
24
|
+
export declare const replicaIdEquals: (a: ReplicaId, b: ReplicaId) => boolean;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as bson from 'bson';
|
|
2
|
+
export const BSON_DESERIALIZE_OPTIONS = {
|
|
3
|
+
// use bigint instead of Long
|
|
4
|
+
useBigInt64: true
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Lookup serialization must be number-agnostic. I.e. normalize numbers, instead of preserving numbers.
|
|
8
|
+
* @param lookup
|
|
9
|
+
*/
|
|
10
|
+
export const serializeLookupBuffer = (lookup) => {
|
|
11
|
+
const normalized = lookup.map((value) => {
|
|
12
|
+
if (typeof value == 'number' && Number.isInteger(value)) {
|
|
13
|
+
return BigInt(value);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return bson.serialize({ l: normalized });
|
|
20
|
+
};
|
|
21
|
+
export const serializeLookup = (lookup) => {
|
|
22
|
+
return new bson.Binary(serializeLookupBuffer(lookup));
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* True if this is a bson.UUID.
|
|
26
|
+
*
|
|
27
|
+
* Works even with multiple copies of the bson package.
|
|
28
|
+
*/
|
|
29
|
+
export const isUUID = (value) => {
|
|
30
|
+
if (value == null || typeof value != 'object') {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const uuid = value;
|
|
34
|
+
return uuid._bsontype == 'Binary' && uuid.sub_type == bson.Binary.SUBTYPE_UUID;
|
|
35
|
+
};
|
|
36
|
+
export const serializeReplicaId = (id) => {
|
|
37
|
+
return bson.serialize({ id });
|
|
38
|
+
};
|
|
39
|
+
export const deserializeReplicaId = (id) => {
|
|
40
|
+
const deserialized = deserializeBson(id);
|
|
41
|
+
return deserialized.id;
|
|
42
|
+
};
|
|
43
|
+
export const deserializeBson = (buffer) => {
|
|
44
|
+
return bson.deserialize(buffer, BSON_DESERIALIZE_OPTIONS);
|
|
45
|
+
};
|
|
46
|
+
export const serializeBson = (document) => {
|
|
47
|
+
return bson.serialize(document);
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Returns true if two ReplicaId values are the same (serializes to the same BSON value).
|
|
51
|
+
*/
|
|
52
|
+
export const replicaIdEquals = (a, b) => {
|
|
53
|
+
if (a === b) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
else if (typeof a == 'string' && typeof b == 'string') {
|
|
57
|
+
return a == b;
|
|
58
|
+
}
|
|
59
|
+
else if (isUUID(a) && isUUID(b)) {
|
|
60
|
+
return a.equals(b);
|
|
61
|
+
}
|
|
62
|
+
else if (a == null && b == null) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
else if ((b == null && a != null) || (a == null && b != null)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// There are many possible primitive values, this covers them all
|
|
70
|
+
return serializeReplicaId(a).equals(serializeReplicaId(b));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=bson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bson.js","sourceRoot":"","sources":["../../src/storage/bson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAK7B,MAAM,CAAC,MAAM,wBAAwB,GAA4B;IAC/D,6BAA6B;IAC7B,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,MAAyB,EAAU,EAAE;IACzE,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACtC,IAAI,OAAO,KAAK,IAAI,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACxD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,CAAW,CAAC;AACrD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAyB,EAAE,EAAE;IAC3D,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC;AACxD,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAU,EAAsB,EAAE;IACvD,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MA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,CAAC,IAAI,IAAI,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;SAAM,IAAI,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE,CAAC;QAChE,OAAO,KAAK,CAAC;IACf,CAAC;SAAM,CAAC;QACN,iEAAiE;QACjE,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAA8B,CAAC,CAAC;IAC1F,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-index.js","sourceRoot":"","sources":["../../src/storage/storage-index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"storage-index.js","sourceRoot":"","sources":["../../src/storage/storage-index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC"}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.0.0-dev-
|
|
8
|
+
"version": "0.0.0-dev-20241219145106",
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"license": "FSL-1.1-Apache-2.0",
|
|
11
11
|
"type": "module",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"uuid": "^9.0.1",
|
|
33
33
|
"winston": "^3.13.0",
|
|
34
34
|
"yaml": "^2.3.2",
|
|
35
|
+
"@powersync/lib-services-framework": "0.0.0-dev-20241219145106",
|
|
35
36
|
"@powersync/service-jsonbig": "0.17.10",
|
|
36
|
-
"@powersync/
|
|
37
|
-
"@powersync/service-
|
|
38
|
-
"@powersync/service-
|
|
39
|
-
"@powersync/service-types": "0.5.0"
|
|
37
|
+
"@powersync/service-rsocket-router": "0.0.0-dev-20241219145106",
|
|
38
|
+
"@powersync/service-sync-rules": "0.0.0-dev-20241219145106",
|
|
39
|
+
"@powersync/service-types": "0.0.0-dev-20241219145106"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/async": "^3.2.24",
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as bson from 'bson';
|
|
2
|
+
|
|
3
|
+
import { SqliteJsonValue } from '@powersync/service-sync-rules';
|
|
4
|
+
import { ReplicaId } from './BucketStorage.js';
|
|
5
|
+
|
|
6
|
+
export const BSON_DESERIALIZE_OPTIONS: bson.DeserializeOptions = {
|
|
7
|
+
// use bigint instead of Long
|
|
8
|
+
useBigInt64: true
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Lookup serialization must be number-agnostic. I.e. normalize numbers, instead of preserving numbers.
|
|
13
|
+
* @param lookup
|
|
14
|
+
*/
|
|
15
|
+
export const serializeLookupBuffer = (lookup: SqliteJsonValue[]): Buffer => {
|
|
16
|
+
const normalized = lookup.map((value) => {
|
|
17
|
+
if (typeof value == 'number' && Number.isInteger(value)) {
|
|
18
|
+
return BigInt(value);
|
|
19
|
+
} else {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return bson.serialize({ l: normalized }) as Buffer;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const serializeLookup = (lookup: SqliteJsonValue[]) => {
|
|
27
|
+
return new bson.Binary(serializeLookupBuffer(lookup));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* True if this is a bson.UUID.
|
|
32
|
+
*
|
|
33
|
+
* Works even with multiple copies of the bson package.
|
|
34
|
+
*/
|
|
35
|
+
export const isUUID = (value: any): value is bson.UUID => {
|
|
36
|
+
if (value == null || typeof value != 'object') {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const uuid = value as bson.UUID;
|
|
40
|
+
return uuid._bsontype == 'Binary' && uuid.sub_type == bson.Binary.SUBTYPE_UUID;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const serializeReplicaId = (id: ReplicaId): Buffer => {
|
|
44
|
+
return bson.serialize({ id }) as Buffer;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const deserializeReplicaId = (id: Buffer): ReplicaId => {
|
|
48
|
+
const deserialized = deserializeBson(id);
|
|
49
|
+
return deserialized.id;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const deserializeBson = (buffer: Buffer) => {
|
|
53
|
+
return bson.deserialize(buffer, BSON_DESERIALIZE_OPTIONS);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const serializeBson = (document: any): Buffer => {
|
|
57
|
+
return bson.serialize(document) as Buffer;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Returns true if two ReplicaId values are the same (serializes to the same BSON value).
|
|
62
|
+
*/
|
|
63
|
+
export const replicaIdEquals = (a: ReplicaId, b: ReplicaId) => {
|
|
64
|
+
if (a === b) {
|
|
65
|
+
return true;
|
|
66
|
+
} else if (typeof a == 'string' && typeof b == 'string') {
|
|
67
|
+
return a == b;
|
|
68
|
+
} else if (isUUID(a) && isUUID(b)) {
|
|
69
|
+
return a.equals(b);
|
|
70
|
+
} else if (a == null && b == null) {
|
|
71
|
+
return true;
|
|
72
|
+
} else if ((b == null && a != null) || (a == null && b != null)) {
|
|
73
|
+
return false;
|
|
74
|
+
} else {
|
|
75
|
+
// There are many possible primitive values, this covers them all
|
|
76
|
+
return serializeReplicaId(a).equals(serializeReplicaId(b) as ArrayBuffer as Uint8Array);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './bson.js';
|
|
1
2
|
export * from './BucketStorage.js';
|
|
2
3
|
export * from './ChecksumCache.js';
|
|
3
4
|
export * from './ReplicationEventPayload.js';
|
|
@@ -6,4 +7,3 @@ export * from './SourceTable.js';
|
|
|
6
7
|
export * from './StorageEngine.js';
|
|
7
8
|
export * from './StorageProvider.js';
|
|
8
9
|
export * from './WriteCheckpointAPI.js';
|
|
9
|
-
|