@shaxpir/duiduidui-models 1.4.9 → 1.4.11
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/repo/ShareSync.d.ts +2 -0
- package/dist/repo/ShareSync.js +42 -39
- package/package.json +2 -2
package/dist/repo/ShareSync.d.ts
CHANGED
|
@@ -46,6 +46,8 @@ export declare class ShareSync {
|
|
|
46
46
|
private _durableStore;
|
|
47
47
|
private _storageFactory?;
|
|
48
48
|
constructor(encryption: Encryption, options: ShareSyncOptions);
|
|
49
|
+
private setupConnectionEvents;
|
|
50
|
+
private createConnectionWithDurableStore;
|
|
49
51
|
private initializeDurableStore;
|
|
50
52
|
isDebug(): boolean;
|
|
51
53
|
isOnline(): boolean;
|
package/dist/repo/ShareSync.js
CHANGED
|
@@ -38,7 +38,6 @@ 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"));
|
|
42
41
|
const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
|
|
43
42
|
const reconnecting_websocket_1 = __importDefault(require("reconnecting-websocket"));
|
|
44
43
|
const models_1 = require("../models");
|
|
@@ -111,62 +110,66 @@ class ShareSync {
|
|
|
111
110
|
updateSocketIsOpen();
|
|
112
111
|
shareSync._listener.onSocketEvent('error', event);
|
|
113
112
|
});
|
|
114
|
-
//
|
|
115
|
-
shareSync._connection = new client_1.Connection(shareSync._socket);
|
|
116
|
-
// Initialize DurableStore asynchronously if enabled
|
|
113
|
+
// Initialize DurableStore first if enabled, then create connection with it
|
|
117
114
|
if (shareSync._hasDurableStore) {
|
|
118
|
-
shareSync.initializeDurableStore(options).
|
|
115
|
+
shareSync.initializeDurableStore(options).then(() => {
|
|
116
|
+
// Create connection with DurableStore options
|
|
117
|
+
shareSync._connection = shareSync.createConnectionWithDurableStore(shareSync._socket, options);
|
|
118
|
+
shareSync.setupConnectionEvents(options);
|
|
119
|
+
}).catch((error) => {
|
|
119
120
|
console.error('Failed to initialize DurableStore:', error);
|
|
120
121
|
shareSync._opErrorCallback && shareSync._opErrorCallback(error);
|
|
121
122
|
});
|
|
122
123
|
}
|
|
123
|
-
else
|
|
124
|
-
//
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
124
|
+
else {
|
|
125
|
+
// Create the ShareDB connection from the socket (without DurableStore)
|
|
126
|
+
shareSync._connection = new client_1.Connection(shareSync._socket);
|
|
127
|
+
shareSync.setupConnectionEvents(options);
|
|
128
|
+
if (options.onReadyCallback) {
|
|
129
|
+
// If there is no DurableStore, then we can call the onReadyCallback now. However,
|
|
130
|
+
// we have to use setTimeout to invoke it, because the callback will probably want
|
|
131
|
+
// to retrieve the ShareSync instance from the factory, and because the constructor
|
|
132
|
+
// hasn't actually finished yet, the INSTANCE pointer hasn't quite been assigned yet.
|
|
133
|
+
setTimeout(options.onReadyCallback, 1);
|
|
134
|
+
}
|
|
129
135
|
}
|
|
130
|
-
|
|
136
|
+
}
|
|
137
|
+
setupConnectionEvents(options) {
|
|
138
|
+
this._connection.on('error', (err) => {
|
|
131
139
|
console.error(`ShareSync connection error: ${err}\n Error code: ${err.code}\n Error message: ${err.message}\n Error stack: ${err.stack}\n`);
|
|
132
140
|
});
|
|
133
141
|
// If the client provided a pingInterval option, then set up a periodic ping the
|
|
134
142
|
// connection alive. Clients who don't provide this option will send pings.
|
|
135
|
-
if (options.pingInterval && typeof (options.pingInterval) === 'number') {
|
|
136
|
-
setInterval(() => {
|
|
143
|
+
if (options && options.pingInterval && typeof (options.pingInterval) === 'number') {
|
|
144
|
+
setInterval(() => { this.ping(); }, options.pingInterval);
|
|
137
145
|
}
|
|
138
146
|
}
|
|
147
|
+
createConnectionWithDurableStore(socket, options) {
|
|
148
|
+
return new client_1.Connection(socket, {
|
|
149
|
+
durableStore: {
|
|
150
|
+
storage: this._storage,
|
|
151
|
+
debug: this._debug,
|
|
152
|
+
extVersionDecoder: (docData) => {
|
|
153
|
+
if (docData &&
|
|
154
|
+
docData.meta &&
|
|
155
|
+
docData.meta.updated_at &&
|
|
156
|
+
docData.meta.updated_at.utc_time) {
|
|
157
|
+
return docData.meta.updated_at.utc_time;
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
},
|
|
161
|
+
onReadyCallback: options.onReadyCallback
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
139
165
|
async initializeDurableStore(options) {
|
|
140
166
|
try {
|
|
141
167
|
// Create storage implementation if factory is provided
|
|
142
168
|
if (this._storageFactory) {
|
|
143
169
|
this._storage = await this._storageFactory();
|
|
144
170
|
}
|
|
145
|
-
|
|
146
|
-
|
|
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');
|
|
171
|
+
if (!this._storage) {
|
|
172
|
+
throw new Error('DurableStore enabled but no storage factory provided');
|
|
170
173
|
}
|
|
171
174
|
}
|
|
172
175
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shaxpir/duiduidui-models",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.11",
|
|
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": "^6.0.
|
|
19
|
+
"@shaxpir/sharedb": "^6.0.5",
|
|
20
20
|
"@shaxpir/shaxpir-common": "1.3.0",
|
|
21
21
|
"ot-json1": "1.0.1",
|
|
22
22
|
"ot-text-unicode": "4.0.0",
|