rhine-var 0.5.2 → 0.6.2
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/README.md +22 -6
- package/README_zh.md +20 -5
- package/dist/config/config.d.ts +8 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +19 -0
- package/dist/core/connector/SyncHandshakeCheck.d.ts +5 -0
- package/dist/core/connector/SyncHandshakeCheck.d.ts.map +1 -0
- package/dist/core/connector/SyncHandshakeCheck.js +42 -0
- package/dist/core/connector/WebsocketConnector.d.ts.map +1 -1
- package/dist/core/connector/WebsocketConnector.js +14 -6
- package/dist/core/proxy/Proxy.d.ts +1 -1
- package/dist/core/proxy/Proxy.d.ts.map +1 -1
- package/dist/core/proxy/Proxy.js +7 -7
- package/dist/core/proxy/RhineVarItem.d.ts.map +1 -1
- package/dist/core/proxy/RhineVarItem.js +12 -10
- package/dist/core/utils/DataUtils.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/utils/logger.d.ts +3 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +16 -0
- package/package.json +1 -1
- package/playground/next-app/public/favicon.ico +0 -0
- package/dist/core/utils/Logger.d.ts +0 -2
- package/dist/core/utils/Logger.d.ts.map +0 -1
- package/dist/core/utils/Logger.js +0 -9
package/README.md
CHANGED
|
@@ -152,22 +152,38 @@ Note: The returned snapshot is read-only. Please do not perform any operations o
|
|
|
152
152
|
|
|
153
153
|
## Server
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
## Server
|
|
156
|
+
|
|
157
|
+
We provide a public server on the internet for testing and trying out RHINE-VAR. You can connect to it via `wss://rvp.rhineai.com/<room-id>`.
|
|
156
158
|
|
|
157
|
-
|
|
159
|
+
Note that this server does not guarantee security or performance and will impose certain restrictions on users and IPs with large-scale usage.
|
|
158
160
|
|
|
159
161
|
<br/>
|
|
160
162
|
|
|
161
|
-
We provide a
|
|
163
|
+
We also provide a basic server example that you can deploy yourself. For more details, see: https://github.com/RhineAI-Lab/rhine-var-server
|
|
164
|
+
|
|
162
165
|
```
|
|
163
|
-
git clone https://github.com/RhineAI-Lab/rhine-var.git
|
|
164
|
-
cd test/server
|
|
166
|
+
git clone https://github.com/RhineAI-Lab/rhine-var-server.git
|
|
165
167
|
yarn install
|
|
166
168
|
yarn start
|
|
167
169
|
```
|
|
168
170
|
It will run on `Port 6600`, and you can connect to it via `ws://localhost:6600/<room-id>`. `<room-id>` can be any text, with each room ID corresponding to a `RhineVariable`.
|
|
169
171
|
|
|
170
|
-
|
|
172
|
+
<br/>
|
|
173
|
+
|
|
174
|
+
The server is currently fully compatible with all Yjs WebSocket servers.
|
|
175
|
+
|
|
176
|
+
In the future, more communication protocols will be supported. You can also develop your own `Connector` object to adapt to your custom communication protocol.
|
|
177
|
+
|
|
178
|
+
For more information on server development, refer to: [https://docs.yjs.dev/ecosystem/connection-provider/y-websocket](https://docs.yjs.dev/ecosystem/connection-provider/y-websocket)
|
|
179
|
+
|
|
180
|
+
When using your own server, disable RhineVar's default handshake verification unless your server supports it.
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import {enableRhineVarSyncHandshakeCheck} from 'rhine-var'
|
|
184
|
+
|
|
185
|
+
enableRhineVarSyncHandshakeCheck(false)
|
|
186
|
+
```
|
|
171
187
|
|
|
172
188
|
<br/>
|
|
173
189
|
|
package/README_zh.md
CHANGED
|
@@ -167,23 +167,38 @@ function Counter() {
|
|
|
167
167
|
|
|
168
168
|
## Server
|
|
169
169
|
|
|
170
|
-
我们提供了一个位于公网的公共服务器,可以用于试用和测试 RHINE-VAR。你可以通过 `wss://
|
|
170
|
+
我们提供了一个位于公网的公共服务器,可以用于试用和测试 RHINE-VAR。你可以通过 `wss://rvp.rhineai.com/<room-id>` 连接它。
|
|
171
171
|
|
|
172
|
-
|
|
172
|
+
注意,该服务器无法保证安全和性能,并会对大规模使用的用户和IP做出一定限制。
|
|
173
173
|
|
|
174
174
|
<br/>
|
|
175
175
|
|
|
176
|
-
|
|
176
|
+
我们提供了一个基本的服务器例子,您可以自己部署,详情请见: https://github.com/RhineAI-Lab/rhine-var-server
|
|
177
|
+
|
|
177
178
|
```
|
|
178
|
-
git clone https://github.com/RhineAI-Lab/rhine-var.git
|
|
179
|
-
cd test/server
|
|
179
|
+
git clone https://github.com/RhineAI-Lab/rhine-var-server.git
|
|
180
180
|
yarn install
|
|
181
181
|
yarn start
|
|
182
182
|
```
|
|
183
|
+
|
|
183
184
|
默认运行在 `端口 6600`, 你可以通过连接 `ws://localhost:6600/<room-id>` 连接它,`<room-id>` 可以是任意文本,一个房间号对应一个 `RhineVar 对象`。
|
|
184
185
|
|
|
186
|
+
<br/>
|
|
187
|
+
|
|
188
|
+
服务端目前完全兼容所有的 Yjs 的 Websocket 服务器。
|
|
189
|
+
|
|
190
|
+
将来会支持更多通信协议,现在您也可以自己开发 `Connector` 对象,以适配自己的通信协议。
|
|
191
|
+
|
|
185
192
|
更多服务端开发信息请参考: [https://docs.yjs.dev/ecosystem/connection-provider/y-websocket](https://docs.yjs.dev/ecosystem/connection-provider/y-websocket)
|
|
186
193
|
|
|
194
|
+
当你使用自己开发的服务器时,请关闭 RhineVar 默认的二次握手校验连接,除非你的服务器支持了他。
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
import {enableRhineVarSyncHandshakeCheck} from 'rhine-var'
|
|
198
|
+
|
|
199
|
+
enableRhineVarSyncHandshakeCheck(false)
|
|
200
|
+
```
|
|
201
|
+
|
|
187
202
|
<br/>
|
|
188
203
|
|
|
189
204
|
## Develop
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export default class RhineVarConfig {
|
|
2
|
+
static ENABLE_LOG: boolean;
|
|
3
|
+
static ENABLE_SYNC_HANDSHAKE_CHECK: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function enableRhineVarLog(value: boolean): void;
|
|
6
|
+
export declare function enableRhineVarSyncHandshakeCheck(value: boolean): void;
|
|
7
|
+
export declare function getRhineVarConfig(): typeof RhineVarConfig;
|
|
8
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,OAAO,OAAO,cAAc;IAEjC,MAAM,CAAC,UAAU,UAAQ;IACzB,MAAM,CAAC,2BAA2B,UAAO;CAE1C;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,QAE/C;AAED,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,OAAO,QAE9D;AAED,wBAAgB,iBAAiB,0BAEhC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enableRhineVarLog = enableRhineVarLog;
|
|
4
|
+
exports.enableRhineVarSyncHandshakeCheck = enableRhineVarSyncHandshakeCheck;
|
|
5
|
+
exports.getRhineVarConfig = getRhineVarConfig;
|
|
6
|
+
class RhineVarConfig {
|
|
7
|
+
}
|
|
8
|
+
RhineVarConfig.ENABLE_LOG = false;
|
|
9
|
+
RhineVarConfig.ENABLE_SYNC_HANDSHAKE_CHECK = true;
|
|
10
|
+
exports.default = RhineVarConfig;
|
|
11
|
+
function enableRhineVarLog(value) {
|
|
12
|
+
RhineVarConfig.ENABLE_LOG = Boolean(value);
|
|
13
|
+
}
|
|
14
|
+
function enableRhineVarSyncHandshakeCheck(value) {
|
|
15
|
+
RhineVarConfig.ENABLE_SYNC_HANDSHAKE_CHECK = Boolean(value);
|
|
16
|
+
}
|
|
17
|
+
function getRhineVarConfig() {
|
|
18
|
+
return RhineVarConfig;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncHandshakeCheck.d.ts","sourceRoot":"","sources":["../../../src/core/connector/SyncHandshakeCheck.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,IAAI,IAAI,EAAC,MAAM,KAAK,CAAC;AAGhC,MAAM,CAAC,OAAO,OAAO,kBAAkB;IAErC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC;CAoC/B"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const logger_1 = require("../../utils/logger");
|
|
4
|
+
class SyncHandshakeCheck {
|
|
5
|
+
static wait(baseMap) {
|
|
6
|
+
return new Promise((resolve) => {
|
|
7
|
+
const waitSync = (syncMap) => {
|
|
8
|
+
syncMap.set('role', 'client');
|
|
9
|
+
syncMap.set('timestamp', Date.now());
|
|
10
|
+
(0, logger_1.log)('Sync handshake start', syncMap.toJSON());
|
|
11
|
+
setTimeout(() => {
|
|
12
|
+
const syncObserver = () => {
|
|
13
|
+
var _a;
|
|
14
|
+
if (syncMap.get('role') === 'server') {
|
|
15
|
+
(0, logger_1.log)('Sync handshake successfully', syncMap.toJSON());
|
|
16
|
+
syncMap.unobserve(syncObserver);
|
|
17
|
+
(0, logger_1.log)('Sync State:', (_a = baseMap.get('state')) === null || _a === void 0 ? void 0 : _a.toJSON());
|
|
18
|
+
resolve();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
syncMap.observe(syncObserver);
|
|
22
|
+
syncObserver();
|
|
23
|
+
}, 1);
|
|
24
|
+
};
|
|
25
|
+
if (baseMap.has('sync')) {
|
|
26
|
+
waitSync(baseMap.get('sync'));
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
(0, logger_1.log)('Sync handshake waiting...');
|
|
30
|
+
const mapObserver = () => {
|
|
31
|
+
console.log(baseMap.toJSON());
|
|
32
|
+
if (baseMap.has('sync')) {
|
|
33
|
+
baseMap.unobserve(mapObserver);
|
|
34
|
+
waitSync(baseMap.get('sync'));
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
baseMap.observe(mapObserver);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.default = SyncHandshakeCheck;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebsocketConnector.d.ts","sourceRoot":"","sources":["../../../src/core/connector/WebsocketConnector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,IAAI,IAAI,EAAE,GAAG,IAAI,IAAI,EAAC,MAAM,KAAK,CAAC;AAC7C,OAAO,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAC,eAAe,EAAC,0BAAyC;AAEjE,OAAO,EAAC,MAAM,EAAC,yBAA6B;AAC5C,OAAO,EAAC,cAAc,EAAC,0BAA8B;
|
|
1
|
+
{"version":3,"file":"WebsocketConnector.d.ts","sourceRoot":"","sources":["../../../src/core/connector/WebsocketConnector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,IAAI,IAAI,EAAE,GAAG,IAAI,IAAI,EAAC,MAAM,KAAK,CAAC;AAC7C,OAAO,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAC,eAAe,EAAC,0BAAyC;AAEjE,OAAO,EAAC,MAAM,EAAC,yBAA6B;AAC5C,OAAO,EAAC,cAAc,EAAC,0BAA8B;AAIrD,MAAM,CAAC,OAAO,OAAO,kBAAkB;IAErC,MAAM,CAAC,SAAS,SAAU;IAE1B,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IACnB,GAAG,EAAE,MAAM,CAAK;IAEhB,QAAQ,SAAK;IACb,MAAM,UAAQ;IAEd,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAO;IACzC,eAAe,EAAE,eAAe,CAA+B;IAG/D,OAAO,CAAC,iBAAiB,CAAuB;IAChD,eAAe,CAAC,QAAQ,EAAE,cAAc;IAIxC,iBAAiB,CAAC,QAAQ,EAAE,cAAc;IAG1C,oBAAoB;IAGpB,UAAU,CAAC,MAAM,EAAE,OAAO;IAI1B,WAAW,CAAC,QAAQ,EAAE,MAAM,IAAI;IAahC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;gBAOf,GAAG,SAAK;IAMpB,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,GAAE,OAAe;IAc/C,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA+CnC,UAAU;CAYjB;AAGD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,sBAMhD"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.websocketRhineConnect = websocketRhineConnect;
|
|
4
7
|
const yjs_1 = require("yjs");
|
|
5
8
|
const y_websocket_1 = require("y-websocket");
|
|
6
9
|
const ConnectorStatus_1 = require("./ConnectorStatus");
|
|
7
|
-
const
|
|
10
|
+
const logger_1 = require("../../utils/logger");
|
|
11
|
+
const config_1 = __importDefault(require("../../config/config"));
|
|
12
|
+
const SyncHandshakeCheck_1 = __importDefault(require("./SyncHandshakeCheck"));
|
|
8
13
|
class WebsocketConnector {
|
|
9
14
|
subscribeSynced(callback) {
|
|
10
15
|
this.syncedSubscribers.push(callback);
|
|
@@ -75,11 +80,14 @@ class WebsocketConnector {
|
|
|
75
80
|
this.provider.shouldConnect = true;
|
|
76
81
|
this.provider.on('status', (event) => {
|
|
77
82
|
this.websocketStatus = event.status;
|
|
78
|
-
(0,
|
|
83
|
+
(0, logger_1.log)('WebsocketRhineConnector.event status:', event.status);
|
|
79
84
|
});
|
|
80
|
-
this.provider.on('sync', (synced) => {
|
|
81
|
-
(0, Logger_1.log)('WebsocketRhineConnector.event sync:', synced);
|
|
85
|
+
this.provider.on('sync', async (synced) => {
|
|
82
86
|
if (synced) {
|
|
87
|
+
if (config_1.default.ENABLE_SYNC_HANDSHAKE_CHECK) {
|
|
88
|
+
await SyncHandshakeCheck_1.default.wait(this.yBaseMap);
|
|
89
|
+
}
|
|
90
|
+
(0, logger_1.log)('WebsocketRhineConnector.event sync:', synced);
|
|
83
91
|
this.synced = true;
|
|
84
92
|
this.clientId = this.yDoc.clientID;
|
|
85
93
|
this.emitSynced(synced);
|
|
@@ -88,11 +96,11 @@ class WebsocketConnector {
|
|
|
88
96
|
});
|
|
89
97
|
this.provider.on('connection-close', (e) => {
|
|
90
98
|
this.websocketStatus = ConnectorStatus_1.ConnectorStatus.DISCONNECTED;
|
|
91
|
-
(0,
|
|
99
|
+
(0, logger_1.log)('WebsocketRhineConnector.event connection-close:', e);
|
|
92
100
|
});
|
|
93
101
|
this.provider.on('connection-error', (error) => {
|
|
94
102
|
this.websocketStatus = ConnectorStatus_1.ConnectorStatus.DISCONNECTED;
|
|
95
|
-
(0,
|
|
103
|
+
(0, logger_1.log)('WebsocketRhineConnector.event connection-error:', error);
|
|
96
104
|
});
|
|
97
105
|
});
|
|
98
106
|
}
|
|
@@ -4,7 +4,7 @@ import { ProxiedRhineVar, ProxiedRhineVarItem } from "./ProxiedRhineVar";
|
|
|
4
4
|
import { Native } from "../native/Native";
|
|
5
5
|
import RhineVar from "./RhineVar";
|
|
6
6
|
export declare const PROTOCOL_LIST: string[];
|
|
7
|
-
export declare const DEFAULT_PUBLIC_URL = "wss://
|
|
7
|
+
export declare const DEFAULT_PUBLIC_URL = "wss://rvp.rhineai.com/";
|
|
8
8
|
export declare function rhineProxy<T extends object>(defaultValue: T | Native, connector: WebsocketConnector | string | number, overwrite?: boolean | number): ProxiedRhineVar<T>;
|
|
9
9
|
export declare function rhineProxyItem<T extends object>(data: T | Native, parent?: RhineVar<any> | RhineVarItem<any> | null): ProxiedRhineVarItem<T> | ProxiedRhineVar<T>;
|
|
10
10
|
//# sourceMappingURL=Proxy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Proxy.d.ts","sourceRoot":"","sources":["../../../src/core/proxy/Proxy.ts"],"names":[],"mappings":"AACA,OAAO,kBAA2C,wCAA4C;AAC9F,OAAO,YAA+C,uBAAkC;AAIxF,OAAO,EAAC,eAAe,EAAE,mBAAmB,EAAC,0BAAqC;AAClF,OAAO,EAAC,MAAM,EAAC,yBAA6B;
|
|
1
|
+
{"version":3,"file":"Proxy.d.ts","sourceRoot":"","sources":["../../../src/core/proxy/Proxy.ts"],"names":[],"mappings":"AACA,OAAO,kBAA2C,wCAA4C;AAC9F,OAAO,YAA+C,uBAAkC;AAIxF,OAAO,EAAC,eAAe,EAAE,mBAAmB,EAAC,0BAAqC;AAClF,OAAO,EAAC,MAAM,EAAC,yBAA6B;AAQ5C,OAAO,QAAQ,mBAA8B;AAG7C,eAAO,MAAM,aAAa,UAAsB,CAAA;AAChD,eAAO,MAAM,kBAAkB,2BAA2B,CAAA;AAG1D,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EACzC,YAAY,EAAE,CAAC,GAAG,MAAM,EACxB,SAAS,EAAE,kBAAkB,GAAG,MAAM,GAAG,MAAM,EAC/C,SAAS,GAAE,OAAO,GAAG,MAAc,GAClC,eAAe,CAAC,CAAC,CAAC,CA+CpB;AAGD,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAC7C,IAAI,EAAE,CAAC,GAAG,MAAM,EAChB,MAAM,GAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,IAAW,GACtD,mBAAmB,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CA2F7C"}
|
package/dist/core/proxy/Proxy.js
CHANGED
|
@@ -33,12 +33,12 @@ const yjs_1 = require("yjs");
|
|
|
33
33
|
const WebsocketConnector_1 = __importStar(require("../connector/WebsocketConnector"));
|
|
34
34
|
const RhineVarItem_1 = __importStar(require("./RhineVarItem"));
|
|
35
35
|
const DataUtils_1 = require("../utils/DataUtils");
|
|
36
|
-
const
|
|
36
|
+
const logger_1 = require("../../utils/logger");
|
|
37
37
|
const ConvertProperty_1 = require("../utils/ConvertProperty");
|
|
38
38
|
const NativeUtils_1 = require("../native/NativeUtils");
|
|
39
39
|
const RhineVar_1 = __importDefault(require("./RhineVar"));
|
|
40
40
|
exports.PROTOCOL_LIST = ['ws://', "wss://"];
|
|
41
|
-
exports.DEFAULT_PUBLIC_URL = 'wss://
|
|
41
|
+
exports.DEFAULT_PUBLIC_URL = 'wss://rvp.rhineai.com/';
|
|
42
42
|
function rhineProxy(defaultValue, connector, overwrite = false) {
|
|
43
43
|
let target = (0, DataUtils_1.ensureNative)(defaultValue);
|
|
44
44
|
if (connector) {
|
|
@@ -65,7 +65,7 @@ function rhineProxy(defaultValue, connector, overwrite = false) {
|
|
|
65
65
|
Reflect.get(object, 'unobserve').call(object);
|
|
66
66
|
object.native = syncedValue;
|
|
67
67
|
Reflect.get(object, 'observe').call(object);
|
|
68
|
-
(0,
|
|
68
|
+
(0, logger_1.log)('Proxy.synced: Update synced native');
|
|
69
69
|
syncedValue.forEach((value, key) => {
|
|
70
70
|
if ((0, NativeUtils_1.isNative)(value)) {
|
|
71
71
|
Reflect.set(object.origin, key, rhineProxyItem(value, object));
|
|
@@ -97,7 +97,7 @@ function rhineProxyItem(data, parent = null) {
|
|
|
97
97
|
}
|
|
98
98
|
});
|
|
99
99
|
const proxyGetOwnPropertyDescriptor = (proxy, p) => {
|
|
100
|
-
(0,
|
|
100
|
+
(0, logger_1.log)('Proxy.handler.getOwnPropertyDescriptor:', p, ' ', object);
|
|
101
101
|
if (p === Symbol.iterator) {
|
|
102
102
|
return {
|
|
103
103
|
value: function* () {
|
|
@@ -122,7 +122,7 @@ function rhineProxyItem(data, parent = null) {
|
|
|
122
122
|
get(proxy, p, receiver) {
|
|
123
123
|
if (RhineVarItem_1.RHINE_VAR_PREDEFINED_PROPERTIES.has(p))
|
|
124
124
|
return Reflect.get(object, p, receiver);
|
|
125
|
-
(0,
|
|
125
|
+
(0, logger_1.log)('Proxy.handler.get:', p, ' ', object, receiver);
|
|
126
126
|
if (p in object)
|
|
127
127
|
return Reflect.get(object, p, receiver);
|
|
128
128
|
const descriptor = proxyGetOwnPropertyDescriptor(proxy, p);
|
|
@@ -140,7 +140,7 @@ function rhineProxyItem(data, parent = null) {
|
|
|
140
140
|
set(proxy, p, value, receiver) {
|
|
141
141
|
if (RhineVarItem_1.RHINE_VAR_PREDEFINED_PROPERTIES.has(p))
|
|
142
142
|
return Reflect.set(object, p, value, receiver);
|
|
143
|
-
(0,
|
|
143
|
+
(0, logger_1.log)('Proxy.handler.set:', p, 'to', value, ' ', object, receiver);
|
|
144
144
|
value = (0, DataUtils_1.ensureRhineVar)(value, object);
|
|
145
145
|
let result = (0, NativeUtils_1.nativeSet)(object.native, p, value);
|
|
146
146
|
if (!result)
|
|
@@ -150,7 +150,7 @@ function rhineProxyItem(data, parent = null) {
|
|
|
150
150
|
deleteProperty(proxy, p) {
|
|
151
151
|
if (RhineVarItem_1.RHINE_VAR_PREDEFINED_PROPERTIES.has(p))
|
|
152
152
|
return false;
|
|
153
|
-
(0,
|
|
153
|
+
(0, logger_1.log)('Proxy.handler.deleteProperty:', p);
|
|
154
154
|
let result = (0, NativeUtils_1.nativeDelete)(object.native, p);
|
|
155
155
|
if (!result)
|
|
156
156
|
console.error('Failed to delete value');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RhineVarItem.d.ts","sourceRoot":"","sources":["../../../src/core/proxy/RhineVarItem.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,WAAW,EAAE,WAAW,EAAE,SAAS,EAAC,MAAM,KAAK,CAAC;AAItF,OAAO,EAAC,MAAM,EAAE,KAAK,EAAC,yBAA6B;AACnD,OAAO,EAAC,UAAU,EAAC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WAAW,EAAE,SAAS,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,EAAE,iBAAiB,EAAE,WAAW;IAejJ,OAAO,CAAC,QAAQ,CAA6E;IAC7F,OAAO,CAAC,cAAc,CAA0C;IAEhE,OAAO,CAAC,OAAO;IA+Ff,OAAO,CAAC,SAAS;CAQlB;AAGD,eAAO,MAAM,+BAA+B,sBA0C1C,CAAA"}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RHINE_VAR_PREDEFINED_PROPERTIES = void 0;
|
|
4
4
|
const yjs_1 = require("yjs");
|
|
5
5
|
const Proxy_1 = require("./Proxy");
|
|
6
|
-
const
|
|
6
|
+
const logger_1 = require("../../utils/logger");
|
|
7
7
|
const DataUtils_1 = require("../utils/DataUtils");
|
|
8
8
|
const ChangeType_1 = require("../event/ChangeType");
|
|
9
9
|
class RhineVarItem {
|
|
@@ -156,13 +156,15 @@ class RhineVarItem {
|
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
// 开始观察当前Native的内容变化
|
|
160
159
|
observe() {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
this.
|
|
164
|
-
|
|
165
|
-
|
|
160
|
+
const connector = this.getConnector();
|
|
161
|
+
if (connector) {
|
|
162
|
+
this.syncedObserver = (synced) => {
|
|
163
|
+
this.emitSynced(synced);
|
|
164
|
+
};
|
|
165
|
+
connector.subscribeSynced(this.syncedObserver);
|
|
166
|
+
this.emitSynced(connector.synced);
|
|
167
|
+
}
|
|
166
168
|
const target = this.native;
|
|
167
169
|
if (target instanceof yjs_1.Map) {
|
|
168
170
|
this.observer = (event, transaction) => {
|
|
@@ -187,7 +189,7 @@ class RhineVarItem {
|
|
|
187
189
|
Reflect.deleteProperty(this.origin, key);
|
|
188
190
|
}
|
|
189
191
|
const newValue = key in this ? Reflect.get(this, key) : value;
|
|
190
|
-
(0,
|
|
192
|
+
(0, logger_1.log)('Proxy.event: Map', action, key + ':', oldValue, '->', newValue);
|
|
191
193
|
this.emit(key, newValue, oldValue, action, event, transaction);
|
|
192
194
|
this.emitDeep([key], newValue, oldValue, action, event, transaction);
|
|
193
195
|
});
|
|
@@ -213,7 +215,7 @@ class RhineVarItem {
|
|
|
213
215
|
Reflect.set(this.origin, k - 1, value);
|
|
214
216
|
Reflect.deleteProperty(this.origin, k);
|
|
215
217
|
}
|
|
216
|
-
(0,
|
|
218
|
+
(0, logger_1.log)('Proxy.event: Array delete', i + ':', oldValue, '->', undefined);
|
|
217
219
|
this.emit(i, undefined, oldValue, ChangeType_1.ChangeType.Delete, event, transaction);
|
|
218
220
|
this.emitDeep([i], undefined, oldValue, ChangeType_1.ChangeType.Delete, event, transaction);
|
|
219
221
|
}
|
|
@@ -232,7 +234,7 @@ class RhineVarItem {
|
|
|
232
234
|
Reflect.set(this.origin, i, value);
|
|
233
235
|
}
|
|
234
236
|
const newValue = i in this ? Reflect.get(this, i) : target.get(i);
|
|
235
|
-
(0,
|
|
237
|
+
(0, logger_1.log)('Proxy.event: Array add', i, ':', undefined, '->', newValue);
|
|
236
238
|
this.emit(i, newValue, undefined, ChangeType_1.ChangeType.Add, event, transaction);
|
|
237
239
|
this.emitDeep([i], newValue, undefined, ChangeType_1.ChangeType.Add, event, transaction);
|
|
238
240
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataUtils.d.ts","sourceRoot":"","sources":["../../../src/core/utils/DataUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,iCAAqC;AAEhE,OAAO,YAAY,8BAAkC;AAErD,OAAO,EAAC,MAAM,EAAC,yBAA6B;
|
|
1
|
+
{"version":3,"file":"DataUtils.d.ts","sourceRoot":"","sources":["../../../src/core/utils/DataUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,iCAAqC;AAEhE,OAAO,YAAY,8BAAkC;AAErD,OAAO,EAAC,MAAM,EAAC,yBAA6B;AAE5C,wBAAgB,QAAQ,CAAC,KAAK,EAAE,GAAG,WAElC;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,GAAG,kBAEjC;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,GAAG,WAEzC;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,GAAG,GAAG,CAU3G;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,MAAM,GAAG,GAAG,CAWjF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ import WebsocketConnector from "./core/connector/WebsocketConnector";
|
|
|
5
5
|
import useRhine from "./react/hooks/useRhine";
|
|
6
6
|
import useSynced from "./react/hooks/useSynced";
|
|
7
7
|
import { Native, YPath } from "./core/native/Native";
|
|
8
|
-
|
|
8
|
+
import { getRhineVarConfig, enableRhineVarLog, enableRhineVarSyncHandshakeCheck } from "./config/config";
|
|
9
|
+
export { WebsocketConnector, rhineProxy, rhineProxyItem, RhineVarItem, StoredRhineVarItem, ProxiedRhineVarItem, RecursiveCrossRhineVarItem, StoredRhineVar, ProxiedRhineVar, RecursiveCrossRhineVar, YPath, Native, enableRhineVarLog, enableRhineVarSyncHandshakeCheck, getRhineVarConfig, useRhine, useSynced, };
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,cAAc,EAAC,2BAA2B;AAC9D,OAAO,YAAY,kCAAkC;AACrD,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,0BAA0B,EAC1B,cAAc,EACd,eAAe,EACf,sBAAsB,EACvB,qCAAqC;AACtC,OAAO,kBAAkB,4CAA4C;AACrE,OAAO,QAAQ,+BAA8B;AAC7C,OAAO,SAAS,gCAA+B;AAC/C,OAAO,EAAC,MAAM,EAAE,KAAK,EAAC,6BAA6B;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,cAAc,EAAC,2BAA2B;AAC9D,OAAO,YAAY,kCAAkC;AACrD,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,0BAA0B,EAC1B,cAAc,EACd,eAAe,EACf,sBAAsB,EACvB,qCAAqC;AACtC,OAAO,kBAAkB,4CAA4C;AACrE,OAAO,QAAQ,+BAA8B;AAC7C,OAAO,SAAS,gCAA+B;AAC/C,OAAO,EAAC,MAAM,EAAE,KAAK,EAAC,6BAA6B;AACnD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gCAAgC,EAAE,MAAM,iBAAiB,CAAC;AAEzG,OAAO,EACL,kBAAkB,EAClB,UAAU,EACV,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,0BAA0B,EAC1B,cAAc,EACd,eAAe,EACf,sBAAsB,EACtB,KAAK,EACL,MAAM,EACN,iBAAiB,EACjB,gCAAgC,EAChC,iBAAiB,EACjB,QAAQ,EACR,SAAS,GACV,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useSynced = exports.useRhine = exports.RhineVarItem = exports.rhineProxyItem = exports.rhineProxy = exports.WebsocketConnector = void 0;
|
|
6
|
+
exports.useSynced = exports.useRhine = exports.getRhineVarConfig = exports.enableRhineVarSyncHandshakeCheck = exports.enableRhineVarLog = exports.RhineVarItem = exports.rhineProxyItem = exports.rhineProxy = exports.WebsocketConnector = void 0;
|
|
7
7
|
const Proxy_1 = require("./core/proxy/Proxy");
|
|
8
8
|
Object.defineProperty(exports, "rhineProxy", { enumerable: true, get: function () { return Proxy_1.rhineProxy; } });
|
|
9
9
|
Object.defineProperty(exports, "rhineProxyItem", { enumerable: true, get: function () { return Proxy_1.rhineProxyItem; } });
|
|
@@ -15,3 +15,7 @@ const useRhine_1 = __importDefault(require("./react/hooks/useRhine"));
|
|
|
15
15
|
exports.useRhine = useRhine_1.default;
|
|
16
16
|
const useSynced_1 = __importDefault(require("./react/hooks/useSynced"));
|
|
17
17
|
exports.useSynced = useSynced_1.default;
|
|
18
|
+
const config_1 = require("./config/config");
|
|
19
|
+
Object.defineProperty(exports, "getRhineVarConfig", { enumerable: true, get: function () { return config_1.getRhineVarConfig; } });
|
|
20
|
+
Object.defineProperty(exports, "enableRhineVarLog", { enumerable: true, get: function () { return config_1.enableRhineVarLog; } });
|
|
21
|
+
Object.defineProperty(exports, "enableRhineVarSyncHandshakeCheck", { enumerable: true, get: function () { return config_1.enableRhineVarSyncHandshakeCheck; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAEA,wBAAgB,GAAG,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,QAIlC;AAED,wBAAgB,SAAS,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,QAExC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.log = log;
|
|
7
|
+
exports.nativeLog = nativeLog;
|
|
8
|
+
const config_1 = __importDefault(require("../config/config"));
|
|
9
|
+
function log(...items) {
|
|
10
|
+
if (config_1.default.ENABLE_LOG) {
|
|
11
|
+
nativeLog(...items);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function nativeLog(...items) {
|
|
15
|
+
console.log('%cRhineVar', 'color: #b6ff00', ...items);
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rhine-var",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Variables that support multi-user collaboration and persistence, making collaboration and variable operations as simple as possible, with strict and well-defined type hints.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../../src/core/utils/Logger.ts"],"names":[],"mappings":"AAGA,wBAAgB,GAAG,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,QAIlC"}
|