rhine-var 0.5.0 → 0.5.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.
@@ -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,4BAAgC;AACnD,OAAO,EAAC,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAC,0BAA8B;AAC7E,OAAO,EAAC,kBAAkB,EAAC,0BAAqC;AAChE,OAAO,QAAQ,mBAA8B;AAC7C,OAAO,kBAAkB,wCAA4C;AAGrE,MAAM,CAAC,OAAO,OAAO,YAAY,CAAC,CAAC;IAGxB,MAAM,EAAE,MAAM;IACd,MAAM,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,IAAI;IAChD,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;gBAF7B,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,IAAW,EACvD,MAAM,GAAE,kBAAkB,CAAC,CAAC,CAAe;IAGpD,MAAM,IAAI,OAAO;IAIjB,IAAI,IAAI,QAAQ,CAAC,GAAG,CAAC;IAIrB,YAAY,IAAI,kBAAkB,GAAG,IAAI;IAKzC,WAAW,CAAC,QAAQ,EAAE,MAAM,IAAI;IAO1B,UAAU;IAOhB,IAAI,IAAI,CAAC;IAIT,UAAU,IAAI,CAAC;IAwCf,MAAM,CAAC,MAAM,SAAI;IAIjB,OAAO,CAAC,iBAAiB,CAAuB;IAChD,eAAe,CAAC,QAAQ,EAAE,cAAc;IAIxC,iBAAiB,CA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,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAO7D,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IAKpC,iBAAiB;IAIjB,OAAO,CAAC,IAAI;IAQZ,OAAO,CAAC,eAAe,CAAwB;IAC/C,aAAa,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAIpD,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;IAGzC,kBAAkB;IAIlB,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,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;IAGhE,OAAO,CAAC,OAAO;IA2Ff,OAAO,CAAC,SAAS;CAQlB;AAGD,eAAO,MAAM,+BAA+B,sBA0C1C,CAAA"}
@@ -287,6 +287,7 @@ exports.RHINE_VAR_PREDEFINED_PROPERTIES = new Set([
287
287
  'emit',
288
288
  'emitDeep',
289
289
  'observer',
290
+ 'syncedObserver',
290
291
  'observe',
291
292
  'unobserve',
292
293
  ]);
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "rhine-var",
3
- "version": "0.5.0",
3
+ "version": "0.5.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",
7
7
  "scripts": {
8
8
  "prepare": "ts-patch install -s",
9
- "install-next": "npm install --prefix ./test/debug/next-app",
10
- "link-next": "npm link && npm link rhine-var --prefix ./test/debug/next-app",
9
+ "install-next": "npm install --prefix playground/next-app",
10
+ "link-next": "npm link && npm link rhine-var --prefix playground/next-app",
11
11
  "server": "npm run start --prefix ./test/server",
12
12
  "watch": "tsc --watch",
13
- "next": "npm run dev --prefix ./test/debug/next-app",
13
+ "next": "npm run dev --prefix playground/next-app",
14
14
  "test": "echo \"Error: no test specified\" && exit 1",
15
15
  "build": "tsc",
16
16
  "publish": "npm publish"
@@ -0,0 +1,4 @@
1
+ /** @type {import('next').NextConfig} */
2
+ const nextConfig = {};
3
+
4
+ export default nextConfig;
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "rhine-var-test-next-app",
3
+ "scripts": {
4
+ "dev": "start http://localhost:6700 && next dev -p 6700"
5
+ },
6
+ "dependencies": {
7
+ "next": "14.2.7",
8
+ "react": "^18",
9
+ "react-dom": "^18"
10
+ },
11
+ "devDependencies": {
12
+ "@types/node": "^20",
13
+ "@types/react": "^18",
14
+ "@types/react-dom": "^18",
15
+ "typescript": "^5"
16
+ }
17
+ }
@@ -1,28 +0,0 @@
1
- import { Doc as YDoc, Map as YMap } from "yjs";
2
- import { WebsocketProvider } from "y-websocket";
3
- import { ConnectorStatus } from "./ConnectorStatus";
4
- import { Native } from "../native/Native";
5
- import { SyncedCallback } from "../event/Callback";
6
- export default class WebsocketRhineConnector {
7
- static STATE_KEY: string;
8
- yDoc: YDoc;
9
- yBaseMap: YMap<any>;
10
- url: string;
11
- clientId: number;
12
- synced: boolean;
13
- provider: WebsocketProvider | null;
14
- websocketStatus: ConnectorStatus;
15
- private syncedSubscribers;
16
- subscribeSynced(callback: SyncedCallback): () => void;
17
- unsubscribeSynced(callback: SyncedCallback): void;
18
- unsubscribeAllSynced(): void;
19
- emitSynced(synced: boolean): void;
20
- afterSynced(callback: () => void): void;
21
- waitSynced(): Promise<void>;
22
- constructor(url?: string);
23
- bind(defaultValue: Native, overwrite?: boolean): any;
24
- connect(url: string): Promise<void>;
25
- disconnect(): Promise<void>;
26
- }
27
- export declare function websocketRhineConnect(url: string): WebsocketRhineConnector;
28
- //# sourceMappingURL=WebsocketRhineConnector.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebsocketRhineConnector.d.ts","sourceRoot":"","sources":["../../../src/core/connector/WebsocketRhineConnector.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;AAErD,MAAM,CAAC,OAAO,OAAO,uBAAuB;IAE1C,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;IA4CnC,UAAU;CAYjB;AAGD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,2BAMhD"}
@@ -1,119 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.websocketRhineConnect = websocketRhineConnect;
4
- const yjs_1 = require("yjs");
5
- const y_websocket_1 = require("y-websocket");
6
- const ConnectorStatus_1 = require("./ConnectorStatus");
7
- const Logger_1 = require("../utils/Logger");
8
- class WebsocketRhineConnector {
9
- subscribeSynced(callback) {
10
- this.syncedSubscribers.push(callback);
11
- return () => this.unsubscribeSynced(callback);
12
- }
13
- unsubscribeSynced(callback) {
14
- this.syncedSubscribers = this.syncedSubscribers.filter(subscriber => subscriber !== callback);
15
- }
16
- unsubscribeAllSynced() {
17
- this.syncedSubscribers = [];
18
- }
19
- emitSynced(synced) {
20
- this.syncedSubscribers.forEach(subscriber => subscriber(synced));
21
- }
22
- afterSynced(callback) {
23
- if (this.synced) {
24
- callback();
25
- }
26
- else {
27
- const subscriber = (synced) => {
28
- if (synced) {
29
- this.unsubscribeSynced(subscriber);
30
- callback();
31
- }
32
- };
33
- this.subscribeSynced(subscriber);
34
- }
35
- }
36
- waitSynced() {
37
- return new Promise((resolve) => {
38
- this.afterSynced(resolve);
39
- });
40
- }
41
- constructor(url = '') {
42
- this.url = '';
43
- this.clientId = -1;
44
- this.synced = false;
45
- this.provider = null;
46
- this.websocketStatus = ConnectorStatus_1.ConnectorStatus.DISCONNECTED;
47
- this.syncedSubscribers = [];
48
- this.yDoc = new yjs_1.Doc();
49
- this.yBaseMap = this.yDoc.getMap();
50
- url && this.connect(url);
51
- }
52
- bind(defaultValue, overwrite = false) {
53
- if (this.synced) {
54
- if (!overwrite && this.yBaseMap.has(WebsocketRhineConnector.STATE_KEY)) {
55
- return this.yBaseMap.get(WebsocketRhineConnector.STATE_KEY);
56
- }
57
- this.yBaseMap.set(WebsocketRhineConnector.STATE_KEY, defaultValue);
58
- return defaultValue;
59
- }
60
- else {
61
- const tempMap = new yjs_1.Doc().getMap();
62
- tempMap.set(WebsocketRhineConnector.STATE_KEY, defaultValue);
63
- return defaultValue;
64
- }
65
- }
66
- async connect(url) {
67
- this.url = url;
68
- let li = this.url.lastIndexOf('/');
69
- if (li == -1 || li == this.url.length - 1 || !this.url.startsWith('ws')) {
70
- console.error('UnSupport URL for Connect Room');
71
- return;
72
- }
73
- return new Promise((resolve, reject) => {
74
- this.provider = new y_websocket_1.WebsocketProvider(this.url.slice(0, li), this.url.slice(li + 1), this.yDoc);
75
- this.provider.shouldConnect = true;
76
- this.provider.on('status', (event) => {
77
- this.websocketStatus = event.status;
78
- (0, Logger_1.log)('WebsocketRhineConnector.event status:', event.status);
79
- });
80
- this.provider.on('sync', (synced) => {
81
- (0, Logger_1.log)('WebsocketRhineConnector.event sync:', synced);
82
- if (synced) {
83
- this.synced = true;
84
- this.clientId = this.yDoc.clientID;
85
- this.emitSynced(synced);
86
- resolve();
87
- }
88
- });
89
- this.provider.on('connection-close', (e) => {
90
- this.websocketStatus = ConnectorStatus_1.ConnectorStatus.DISCONNECTED;
91
- (0, Logger_1.log)('WebsocketRhineConnector.event connection-close:', e);
92
- });
93
- this.provider.on('connection-error', (error) => {
94
- this.websocketStatus = ConnectorStatus_1.ConnectorStatus.DISCONNECTED;
95
- (0, Logger_1.log)('WebsocketRhineConnector.event connection-error:', error);
96
- });
97
- });
98
- }
99
- async disconnect() {
100
- throw new Error('Disconnecting and switching connections are not supported at the moment.');
101
- /*
102
- if (this.provider) {
103
- this.provider.disconnect()
104
- }
105
- this.provider = null
106
- this.synced = false
107
- this.websocketStatus = ConnectorStatus.DISCONNECTED
108
- */
109
- }
110
- }
111
- WebsocketRhineConnector.STATE_KEY = 'state';
112
- exports.default = WebsocketRhineConnector;
113
- function websocketRhineConnect(url) {
114
- const connector = new WebsocketRhineConnector();
115
- if (typeof window !== 'undefined') {
116
- connector.connect(url);
117
- }
118
- return connector;
119
- }