@shaxpir/duiduidui-models 1.4.8 → 1.4.9
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/index.js +0 -1
- package/dist/repo/ShareSync.d.ts +6 -0
- package/dist/repo/ShareSync.js +52 -37
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -15,7 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
/// <reference path="../decs.d.ts" />
|
|
19
18
|
__exportStar(require("./models"), exports);
|
|
20
19
|
__exportStar(require("./repo"), exports);
|
|
21
20
|
__exportStar(require("./util"), exports);
|
package/dist/repo/ShareSync.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface ShareSyncOptions {
|
|
|
21
21
|
pingInterval?: number;
|
|
22
22
|
encryptionKey?: string;
|
|
23
23
|
webSocketConstructor?: any;
|
|
24
|
+
enableDurableStore?: boolean;
|
|
25
|
+
storageFactory?: () => Promise<any>;
|
|
24
26
|
}
|
|
25
27
|
export declare class ShareSyncFactory {
|
|
26
28
|
private static INSTANCE;
|
|
@@ -40,7 +42,11 @@ export declare class ShareSync {
|
|
|
40
42
|
private _socket;
|
|
41
43
|
private _connection;
|
|
42
44
|
private _listener;
|
|
45
|
+
private _storage;
|
|
46
|
+
private _durableStore;
|
|
47
|
+
private _storageFactory?;
|
|
43
48
|
constructor(encryption: Encryption, options: ShareSyncOptions);
|
|
49
|
+
private initializeDurableStore;
|
|
44
50
|
isDebug(): boolean;
|
|
45
51
|
isOnline(): boolean;
|
|
46
52
|
ping(): void;
|
package/dist/repo/ShareSync.js
CHANGED
|
@@ -38,6 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.ShareSync = exports.ShareSyncFactory = exports.ShareSyncDisposalStrategy = void 0;
|
|
40
40
|
const client_1 = __importStar(require("@shaxpir/sharedb/lib/client"));
|
|
41
|
+
const durable_store_1 = __importDefault(require("@shaxpir/sharedb/lib/client/durable-store"));
|
|
41
42
|
const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
|
|
42
43
|
const reconnecting_websocket_1 = __importDefault(require("reconnecting-websocket"));
|
|
43
44
|
const models_1 = require("../models");
|
|
@@ -78,9 +79,10 @@ class ShareSync {
|
|
|
78
79
|
shareSync._debug = options.debug;
|
|
79
80
|
shareSync._disposalStrategy = options.disposalStrategy;
|
|
80
81
|
shareSync._opErrorCallback = options.opErrorCallback;
|
|
81
|
-
shareSync._hasDurableStore = options.namespace && options.namespace.length > 0;
|
|
82
|
+
shareSync._hasDurableStore = options.enableDurableStore === true && options.namespace && options.namespace.length > 0;
|
|
82
83
|
shareSync._useDurableStoreEncryption = options.encryptionKey && options.encryptionKey.length > 0;
|
|
83
84
|
shareSync._durableStoreEncryptionKey = options.encryptionKey;
|
|
85
|
+
shareSync._storageFactory = options.storageFactory;
|
|
84
86
|
// Create and configure the socket.
|
|
85
87
|
if (options.webSocketConstructor) {
|
|
86
88
|
shareSync._socket = new reconnecting_websocket_1.default(options.urlProvider, [], { WebSocket: options.webSocketConstructor });
|
|
@@ -109,39 +111,21 @@ class ShareSync {
|
|
|
109
111
|
updateSocketIsOpen();
|
|
110
112
|
shareSync._listener.onSocketEvent('error', event);
|
|
111
113
|
});
|
|
112
|
-
// Create the ShareDB connection from the socket
|
|
114
|
+
// Create the ShareDB connection from the socket (without DurableStore initially)
|
|
115
|
+
shareSync._connection = new client_1.Connection(shareSync._socket);
|
|
116
|
+
// Initialize DurableStore asynchronously if enabled
|
|
113
117
|
if (shareSync._hasDurableStore) {
|
|
114
|
-
shareSync.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
debug: options.debug,
|
|
118
|
-
useEncryption: shareSync._useDurableStoreEncryption,
|
|
119
|
-
encryptionCallback: (plaintext) => {
|
|
120
|
-
return encryption.encrypt(plaintext, shareSync._durableStoreEncryptionKey);
|
|
121
|
-
},
|
|
122
|
-
decryptionCallback: (cyphertext) => {
|
|
123
|
-
return encryption.decrypt(cyphertext, shareSync._durableStoreEncryptionKey);
|
|
124
|
-
},
|
|
125
|
-
onReadyCallback: options.onReadyCallback,
|
|
126
|
-
opErrorCallback: options.opErrorCallback,
|
|
127
|
-
// Use the 'docData.meta.updated_at.utc_time' field (which is universal to all Model subclasses) as the 'version'
|
|
128
|
-
// identifier that we use when determining if the doc in the DurableStore is up-to-date. This field won't yet
|
|
129
|
-
// exist when the doc is newly created (since the 'doc.data' will be undefined), so in that case, we'll return
|
|
130
|
-
// null as the version string, which will work correctly with the versioning semantics of the DurableStore.
|
|
131
|
-
extVersionDecoder: (docData) => {
|
|
132
|
-
if (docData &&
|
|
133
|
-
docData.meta &&
|
|
134
|
-
docData.meta.updated_at &&
|
|
135
|
-
docData.meta.updated_at.utc_time) {
|
|
136
|
-
return docData.meta.updated_at.utc_time;
|
|
137
|
-
}
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
118
|
+
shareSync.initializeDurableStore(options).catch((error) => {
|
|
119
|
+
console.error('Failed to initialize DurableStore:', error);
|
|
120
|
+
shareSync._opErrorCallback && shareSync._opErrorCallback(error);
|
|
141
121
|
});
|
|
142
122
|
}
|
|
143
|
-
else {
|
|
144
|
-
|
|
123
|
+
else if (options.onReadyCallback) {
|
|
124
|
+
// If there is no DurableStore, then we can call the onReadyCallback now. However,
|
|
125
|
+
// we have to use setTimeout to invoke it, because the callback will probably want
|
|
126
|
+
// to retrieve the ShareSync instance from the factory, and because the constructor
|
|
127
|
+
// hasn't actually finished yet, the INSTANCE pointer hasn't quite been assigned yet.
|
|
128
|
+
setTimeout(options.onReadyCallback, 1);
|
|
145
129
|
}
|
|
146
130
|
shareSync._connection.on('error', (err) => {
|
|
147
131
|
console.error(`ShareSync connection error: ${err}\n Error code: ${err.code}\n Error message: ${err.message}\n Error stack: ${err.stack}\n`);
|
|
@@ -151,12 +135,43 @@ class ShareSync {
|
|
|
151
135
|
if (options.pingInterval && typeof (options.pingInterval) === 'number') {
|
|
152
136
|
setInterval(() => { shareSync.ping(); }, options.pingInterval);
|
|
153
137
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
|
|
138
|
+
}
|
|
139
|
+
async initializeDurableStore(options) {
|
|
140
|
+
try {
|
|
141
|
+
// Create storage implementation if factory is provided
|
|
142
|
+
if (this._storageFactory) {
|
|
143
|
+
this._storage = await this._storageFactory();
|
|
144
|
+
}
|
|
145
|
+
// Create DurableStore with the storage
|
|
146
|
+
if (this._storage) {
|
|
147
|
+
this._durableStore = new durable_store_1.default(this._storage, {
|
|
148
|
+
debug: this._debug,
|
|
149
|
+
// Version decoder for determining document freshness
|
|
150
|
+
// Uses the 'docData.meta.updated_at.utc_time' field (universal to all Model subclasses)
|
|
151
|
+
extVersionDecoder: (docData) => {
|
|
152
|
+
if (docData &&
|
|
153
|
+
docData.meta &&
|
|
154
|
+
docData.meta.updated_at &&
|
|
155
|
+
docData.meta.updated_at.utc_time) {
|
|
156
|
+
return docData.meta.updated_at.utc_time;
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
// Attach DurableStore to connection
|
|
162
|
+
this._connection.useDurableStore(this._durableStore);
|
|
163
|
+
// Call ready callback once DurableStore is initialized
|
|
164
|
+
if (options.onReadyCallback) {
|
|
165
|
+
options.onReadyCallback();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
console.warn('DurableStore enabled but no storage factory provided');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
console.error('Failed to initialize DurableStore:', error);
|
|
174
|
+
throw error;
|
|
160
175
|
}
|
|
161
176
|
}
|
|
162
177
|
isDebug() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shaxpir/duiduidui-models",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.9",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/shaxpir/duiduidui-models"
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dist/"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@shaxpir/sharedb": "^
|
|
19
|
+
"@shaxpir/sharedb": "^6.0.3",
|
|
20
20
|
"@shaxpir/shaxpir-common": "1.3.0",
|
|
21
21
|
"ot-json1": "1.0.1",
|
|
22
22
|
"ot-text-unicode": "4.0.0",
|