@symbo.ls/sync 2.29.57 → 2.29.59

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/cjs/index.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -31,23 +30,33 @@ var import_socket = require("socket.io-client");
31
30
  var import_utils = require("@domql/utils");
32
31
  var import_SyncNotifications = require("./SyncNotifications");
33
32
  var import_Inspect = require("./Inspect");
34
- const isLocalhost = import_utils.window && import_utils.window.location && import_utils.window.location.host.includes("local");
33
+ const isLocal = false;
35
34
  const deletePath = (obj, path) => {
36
- if (!obj || !Array.isArray(path)) return;
35
+ if (!obj || !Array.isArray(path)) {
36
+ return;
37
+ }
37
38
  path.reduce((acc, v, i, arr) => {
38
39
  if (acc && v in acc) {
39
- if (i !== arr.length - 1) return acc[v];
40
+ if (i !== arr.length - 1) {
41
+ return acc[v];
42
+ }
40
43
  delete acc[v];
41
44
  }
42
45
  return void 0;
43
46
  }, obj);
44
47
  };
45
48
  const setPath = (obj, path, value, createNestedObjects = false) => {
46
- if (!obj || !Array.isArray(path)) return;
49
+ if (!obj || !Array.isArray(path)) {
50
+ return;
51
+ }
47
52
  path.reduce((acc, v, i, arr) => {
48
- if (!acc) return void 0;
53
+ if (!acc) {
54
+ return void 0;
55
+ }
49
56
  if (i !== arr.length - 1) {
50
- if (!acc[v] && createNestedObjects) acc[v] = {};
57
+ if (!acc[v] && createNestedObjects) {
58
+ acc[v] = {};
59
+ }
51
60
  return acc[v];
52
61
  }
53
62
  acc[v] = value;
@@ -56,9 +65,13 @@ const setPath = (obj, path, value, createNestedObjects = false) => {
56
65
  };
57
66
  const applyOpsToCtx = (ctx, changes) => {
58
67
  const topLevelChanged = /* @__PURE__ */ new Set();
59
- if (!Array.isArray(changes)) return topLevelChanged;
68
+ if (!Array.isArray(changes)) {
69
+ return topLevelChanged;
70
+ }
60
71
  for (const [action, path, change] of changes) {
61
- if (!Array.isArray(path) || !path.length) continue;
72
+ if (!Array.isArray(path) || !path.length) {
73
+ continue;
74
+ }
62
75
  topLevelChanged.add(path[0]);
63
76
  switch (action) {
64
77
  case "delete":
@@ -76,28 +89,32 @@ const applyOpsToCtx = (ctx, changes) => {
76
89
  };
77
90
  const fetchServiceToken = async () => {
78
91
  try {
79
- const urlBase = "https://api.symbols.app";
92
+ const urlBase = isLocal ? "http://localhost:8080" : "https://api.symbols.app";
80
93
  const res = await import_utils.window.fetch(`${urlBase}/service-token`, {
81
94
  method: "GET"
82
95
  });
83
96
  let txt;
84
97
  try {
85
98
  const json = await res.clone().json();
86
- if (json && typeof json.token === "string") return json.token.trim();
99
+ if (json && typeof json.token === "string") {
100
+ return json.token.trim();
101
+ }
87
102
  txt = await res.text();
88
103
  } catch {
89
104
  txt = await res.text();
90
105
  }
91
- return (txt || "").replace(/\s+/g, "") || void 0;
106
+ return (txt || "").replace(/\s+/gu, "") || void 0;
92
107
  } catch (e) {
93
108
  console.error("[sync] Failed to fetch service-token", e);
94
- return void 0;
95
109
  }
96
110
  };
97
111
  const onSnapshot = (el, s, ctx) => (payload = {}) => {
98
112
  var _a;
99
- let { data, schema } = payload;
100
- if (!data) return;
113
+ let { data } = payload;
114
+ const { schema } = payload;
115
+ if (!data) {
116
+ return;
117
+ }
101
118
  data = el.call("deepDestringify", data, Array.isArray(data) ? [] : {});
102
119
  Object.entries(data).forEach(([key, val]) => {
103
120
  if (ctx[key] && typeof ctx[key] === "object") {
@@ -106,14 +123,18 @@ const onSnapshot = (el, s, ctx) => (payload = {}) => {
106
123
  ctx[key] = val;
107
124
  }
108
125
  });
109
- if (schema) ctx.schema = schema;
126
+ if (schema) {
127
+ ctx.schema = schema;
128
+ }
110
129
  const { pathname, search, hash } = ctx.window.location;
111
130
  (((_a = ctx.utils) == null ? void 0 : _a.router) || import_router.router)(pathname + search + hash, el, {});
112
131
  };
113
132
  const onOps = (el, s, ctx) => (payload = {}) => {
114
133
  var _a;
115
134
  let { changes } = payload;
116
- if (!changes || !Array.isArray(changes) || !changes.length) return;
135
+ if (!changes || !Array.isArray(changes) || !changes.length) {
136
+ return;
137
+ }
117
138
  changes = el.call(
118
139
  "deepDestringify",
119
140
  changes,
@@ -151,7 +172,7 @@ const connectToSocket = async (el, s, ctx) => {
151
172
  );
152
173
  return null;
153
174
  }
154
- const socketBaseUrl = "https://api.symbols.app";
175
+ const socketBaseUrl = isLocal ? "http://localhost:8080" : "https://api.symbols.app";
155
176
  const socket = (0, import_socket.io)(socketBaseUrl, {
156
177
  path: "/collab-socket",
157
178
  transports: ["websocket"],
@@ -167,7 +188,9 @@ const connectToSocket = async (el, s, ctx) => {
167
188
  });
168
189
  socket.on("connect", () => {
169
190
  var _a;
170
- if ((_a = ctx.editor) == null ? void 0 : _a.verbose) console.info("[sync] Connected to collab socket");
191
+ if ((_a = ctx.editor) == null ? void 0 : _a.verbose) {
192
+ console.info("[sync] Connected to collab socket");
193
+ }
171
194
  });
172
195
  socket.on("snapshot", onSnapshot(el, s, ctx));
173
196
  socket.on("ops", onOps(el, s, ctx));
@@ -179,8 +202,9 @@ const connectToSocket = async (el, s, ctx) => {
179
202
  });
180
203
  socket.on("disconnect", (reason) => {
181
204
  var _a;
182
- if ((_a = ctx.editor) == null ? void 0 : _a.verbose)
205
+ if ((_a = ctx.editor) == null ? void 0 : _a.verbose) {
183
206
  console.info("[sync] Disconnected from collab socket", reason);
207
+ }
184
208
  });
185
209
  return socket;
186
210
  };
package/dist/esm/index.js CHANGED
@@ -4,23 +4,33 @@ import { io } from "socket.io-client";
4
4
  import { window, overwriteShallow } from "@domql/utils";
5
5
  import { connectedToSymbols, Notifications } from "./SyncNotifications";
6
6
  import { Inspect } from "./Inspect";
7
- const isLocalhost = window && window.location && window.location.host.includes("local");
7
+ const isLocal = false;
8
8
  const deletePath = (obj, path) => {
9
- if (!obj || !Array.isArray(path)) return;
9
+ if (!obj || !Array.isArray(path)) {
10
+ return;
11
+ }
10
12
  path.reduce((acc, v, i, arr) => {
11
13
  if (acc && v in acc) {
12
- if (i !== arr.length - 1) return acc[v];
14
+ if (i !== arr.length - 1) {
15
+ return acc[v];
16
+ }
13
17
  delete acc[v];
14
18
  }
15
19
  return void 0;
16
20
  }, obj);
17
21
  };
18
22
  const setPath = (obj, path, value, createNestedObjects = false) => {
19
- if (!obj || !Array.isArray(path)) return;
23
+ if (!obj || !Array.isArray(path)) {
24
+ return;
25
+ }
20
26
  path.reduce((acc, v, i, arr) => {
21
- if (!acc) return void 0;
27
+ if (!acc) {
28
+ return void 0;
29
+ }
22
30
  if (i !== arr.length - 1) {
23
- if (!acc[v] && createNestedObjects) acc[v] = {};
31
+ if (!acc[v] && createNestedObjects) {
32
+ acc[v] = {};
33
+ }
24
34
  return acc[v];
25
35
  }
26
36
  acc[v] = value;
@@ -29,9 +39,13 @@ const setPath = (obj, path, value, createNestedObjects = false) => {
29
39
  };
30
40
  const applyOpsToCtx = (ctx, changes) => {
31
41
  const topLevelChanged = /* @__PURE__ */ new Set();
32
- if (!Array.isArray(changes)) return topLevelChanged;
42
+ if (!Array.isArray(changes)) {
43
+ return topLevelChanged;
44
+ }
33
45
  for (const [action, path, change] of changes) {
34
- if (!Array.isArray(path) || !path.length) continue;
46
+ if (!Array.isArray(path) || !path.length) {
47
+ continue;
48
+ }
35
49
  topLevelChanged.add(path[0]);
36
50
  switch (action) {
37
51
  case "delete":
@@ -49,28 +63,32 @@ const applyOpsToCtx = (ctx, changes) => {
49
63
  };
50
64
  const fetchServiceToken = async () => {
51
65
  try {
52
- const urlBase = "https://api.symbols.app";
66
+ const urlBase = isLocal ? "http://localhost:8080" : "https://api.symbols.app";
53
67
  const res = await window.fetch(`${urlBase}/service-token`, {
54
68
  method: "GET"
55
69
  });
56
70
  let txt;
57
71
  try {
58
72
  const json = await res.clone().json();
59
- if (json && typeof json.token === "string") return json.token.trim();
73
+ if (json && typeof json.token === "string") {
74
+ return json.token.trim();
75
+ }
60
76
  txt = await res.text();
61
77
  } catch (e) {
62
78
  txt = await res.text();
63
79
  }
64
- return (txt || "").replace(/\s+/g, "") || void 0;
80
+ return (txt || "").replace(/\s+/gu, "") || void 0;
65
81
  } catch (e) {
66
82
  console.error("[sync] Failed to fetch service-token", e);
67
- return void 0;
68
83
  }
69
84
  };
70
85
  const onSnapshot = (el, s, ctx) => (payload = {}) => {
71
86
  var _a;
72
- let { data, schema } = payload;
73
- if (!data) return;
87
+ let { data } = payload;
88
+ const { schema } = payload;
89
+ if (!data) {
90
+ return;
91
+ }
74
92
  data = el.call("deepDestringify", data, Array.isArray(data) ? [] : {});
75
93
  Object.entries(data).forEach(([key, val]) => {
76
94
  if (ctx[key] && typeof ctx[key] === "object") {
@@ -79,14 +97,18 @@ const onSnapshot = (el, s, ctx) => (payload = {}) => {
79
97
  ctx[key] = val;
80
98
  }
81
99
  });
82
- if (schema) ctx.schema = schema;
100
+ if (schema) {
101
+ ctx.schema = schema;
102
+ }
83
103
  const { pathname, search, hash } = ctx.window.location;
84
104
  (((_a = ctx.utils) == null ? void 0 : _a.router) || router)(pathname + search + hash, el, {});
85
105
  };
86
106
  const onOps = (el, s, ctx) => (payload = {}) => {
87
107
  var _a;
88
108
  let { changes } = payload;
89
- if (!changes || !Array.isArray(changes) || !changes.length) return;
109
+ if (!changes || !Array.isArray(changes) || !changes.length) {
110
+ return;
111
+ }
90
112
  changes = el.call(
91
113
  "deepDestringify",
92
114
  changes,
@@ -124,7 +146,7 @@ const connectToSocket = async (el, s, ctx) => {
124
146
  );
125
147
  return null;
126
148
  }
127
- const socketBaseUrl = "https://api.symbols.app";
149
+ const socketBaseUrl = isLocal ? "http://localhost:8080" : "https://api.symbols.app";
128
150
  const socket = io(socketBaseUrl, {
129
151
  path: "/collab-socket",
130
152
  transports: ["websocket"],
@@ -140,7 +162,9 @@ const connectToSocket = async (el, s, ctx) => {
140
162
  });
141
163
  socket.on("connect", () => {
142
164
  var _a;
143
- if ((_a = ctx.editor) == null ? void 0 : _a.verbose) console.info("[sync] Connected to collab socket");
165
+ if ((_a = ctx.editor) == null ? void 0 : _a.verbose) {
166
+ console.info("[sync] Connected to collab socket");
167
+ }
144
168
  });
145
169
  socket.on("snapshot", onSnapshot(el, s, ctx));
146
170
  socket.on("ops", onOps(el, s, ctx));
@@ -152,8 +176,9 @@ const connectToSocket = async (el, s, ctx) => {
152
176
  });
153
177
  socket.on("disconnect", (reason) => {
154
178
  var _a;
155
- if ((_a = ctx.editor) == null ? void 0 : _a.verbose)
179
+ if ((_a = ctx.editor) == null ? void 0 : _a.verbose) {
156
180
  console.info("[sync] Disconnected from collab socket", reason);
181
+ }
157
182
  });
158
183
  return socket;
159
184
  };
package/index.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  import { router } from '@domql/router'
4
2
  import { init } from '@symbo.ls/init'
5
3
  import { io } from 'socket.io-client'
@@ -8,41 +6,54 @@ import { connectedToSymbols, Notifications } from './SyncNotifications'
8
6
  import { Inspect } from './Inspect'
9
7
  export { Inspect, Notifications }
10
8
 
11
- const isLocalhost =
12
- window && window.location && window.location.host.includes('local')
9
+ const isLocal = process.env.NODE_ENV === 'local'
13
10
 
14
11
  // ---------------------------------------------
15
12
  // Utility helpers to apply ops
16
13
 
17
14
  const deletePath = (obj, path) => {
18
- if (!obj || !Array.isArray(path)) return
15
+ if (!obj || !Array.isArray(path)) {
16
+ return
17
+ }
19
18
  path.reduce((acc, v, i, arr) => {
20
19
  if (acc && v in acc) {
21
- if (i !== arr.length - 1) return acc[v]
20
+ if (i !== arr.length - 1) {
21
+ return acc[v]
22
+ }
22
23
  delete acc[v]
23
24
  }
24
- return undefined
25
+ return void 0
25
26
  }, obj)
26
27
  }
27
28
 
28
29
  const setPath = (obj, path, value, createNestedObjects = false) => {
29
- if (!obj || !Array.isArray(path)) return
30
+ if (!obj || !Array.isArray(path)) {
31
+ return
32
+ }
30
33
  path.reduce((acc, v, i, arr) => {
31
- if (!acc) return undefined
34
+ if (!acc) {
35
+ return void 0
36
+ }
32
37
  if (i !== arr.length - 1) {
33
- if (!acc[v] && createNestedObjects) acc[v] = {}
38
+ if (!acc[v] && createNestedObjects) {
39
+ acc[v] = {}
40
+ }
34
41
  return acc[v]
35
42
  }
36
43
  acc[v] = value
37
- return undefined
44
+ return void 0
38
45
  }, obj)
39
46
  }
40
47
 
41
48
  const applyOpsToCtx = (ctx, changes) => {
42
49
  const topLevelChanged = new Set()
43
- if (!Array.isArray(changes)) return topLevelChanged
50
+ if (!Array.isArray(changes)) {
51
+ return topLevelChanged
52
+ }
44
53
  for (const [action, path, change] of changes) {
45
- if (!Array.isArray(path) || !path.length) continue
54
+ if (!Array.isArray(path) || !path.length) {
55
+ continue
56
+ }
46
57
  topLevelChanged.add(path[0])
47
58
  switch (action) {
48
59
  case 'delete':
@@ -64,10 +75,9 @@ const applyOpsToCtx = (ctx, changes) => {
64
75
 
65
76
  const fetchServiceToken = async () => {
66
77
  try {
67
- // const urlBase = isLocalhost
68
- // ? 'http://localhost:8080'
69
- // : 'https://api.symbols.app'
70
- const urlBase = 'https://api.symbols.app'
78
+ const urlBase = isLocal
79
+ ? 'http://localhost:8080'
80
+ : 'https://api.symbols.app'
71
81
  const res = await window.fetch(`${urlBase}/service-token`, {
72
82
  method: 'GET'
73
83
  })
@@ -77,7 +87,9 @@ const fetchServiceToken = async () => {
77
87
  let txt
78
88
  try {
79
89
  const json = await res.clone().json()
80
- if (json && typeof json.token === 'string') return json.token.trim()
90
+ if (json && typeof json.token === 'string') {
91
+ return json.token.trim()
92
+ }
81
93
  // If json parsing succeeds but no token field, fall back to text below.
82
94
  txt = await res.text()
83
95
  } catch {
@@ -85,18 +97,20 @@ const fetchServiceToken = async () => {
85
97
  txt = await res.text()
86
98
  }
87
99
 
88
- return (txt || '').replace(/\s+/g, '') || undefined
100
+ return (txt || '').replace(/\s+/gu, '') || void 0
89
101
  } catch (e) {
90
102
  console.error('[sync] Failed to fetch service-token', e)
91
- return undefined
92
103
  }
93
104
  }
94
105
 
95
106
  const onSnapshot =
96
107
  (el, s, ctx) =>
97
108
  (payload = {}) => {
98
- let { data, schema } = payload
99
- if (!data) return
109
+ let { data } = payload
110
+ const { schema } = payload
111
+ if (!data) {
112
+ return
113
+ }
100
114
  data = el.call('deepDestringify', data, Array.isArray(data) ? [] : {})
101
115
 
102
116
  // Overwrite high-level objects shallowly so references are preserved
@@ -109,7 +123,9 @@ const onSnapshot =
109
123
  })
110
124
 
111
125
  // Optionally make schema available on ctx
112
- if (schema) ctx.schema = schema
126
+ if (schema) {
127
+ ctx.schema = schema
128
+ }
113
129
 
114
130
  // Trigger routing so UI reflects latest data
115
131
  const { pathname, search, hash } = ctx.window.location
@@ -120,7 +136,9 @@ const onOps =
120
136
  (el, s, ctx) =>
121
137
  (payload = {}) => {
122
138
  let { changes } = payload
123
- if (!changes || !Array.isArray(changes) || !changes.length) return
139
+ if (!changes || !Array.isArray(changes) || !changes.length) {
140
+ return
141
+ }
124
142
 
125
143
  changes = el.call(
126
144
  'deepDestringify',
@@ -169,10 +187,9 @@ export const connectToSocket = async (el, s, ctx) => {
169
187
  return null
170
188
  }
171
189
 
172
- const socketBaseUrl = 'https://api.symbols.app'
173
- // const socketBaseUrl = isLocalhost
174
- // ? 'http://localhost:8080'
175
- // : 'https://api.symbols.app'
190
+ const socketBaseUrl = isLocal
191
+ ? 'http://localhost:8080'
192
+ : 'https://api.symbols.app'
176
193
 
177
194
  const socket = io(socketBaseUrl, {
178
195
  path: '/collab-socket',
@@ -189,7 +206,9 @@ export const connectToSocket = async (el, s, ctx) => {
189
206
  })
190
207
 
191
208
  socket.on('connect', () => {
192
- if (ctx.editor?.verbose) console.info('[sync] Connected to collab socket')
209
+ if (ctx.editor?.verbose) {
210
+ console.info('[sync] Connected to collab socket')
211
+ }
193
212
  })
194
213
 
195
214
  socket.on('snapshot', onSnapshot(el, s, ctx))
@@ -202,8 +221,9 @@ export const connectToSocket = async (el, s, ctx) => {
202
221
  })
203
222
 
204
223
  socket.on('disconnect', (reason) => {
205
- if (ctx.editor?.verbose)
224
+ if (ctx.editor?.verbose) {
206
225
  console.info('[sync] Disconnected from collab socket', reason)
226
+ }
207
227
  })
208
228
 
209
229
  return socket
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@symbo.ls/sync",
3
- "version": "2.29.57",
3
+ "version": "2.29.59",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
- "gitHead": "e906d60cdc66f68af447a6c73ed09e71055cba02",
6
+ "gitHead": "1e603f4009489df16a52ebe50a8c91c32d855ba4",
7
7
  "files": [
8
8
  "*.js",
9
9
  "dist"
@@ -29,12 +29,12 @@
29
29
  "prepublish": "rimraf -I dist && npm run build && npm run copy:package:cjs"
30
30
  },
31
31
  "dependencies": {
32
- "@domql/router": "^2.29.57",
33
- "@domql/utils": "^2.29.57",
34
- "@symbo.ls/init": "^2.29.57",
35
- "@symbo.ls/scratch": "^2.29.57",
36
- "@symbo.ls/socket": "^2.29.57",
37
- "@symbo.ls/uikit": "^2.29.57",
32
+ "@domql/router": "^2.29.59",
33
+ "@domql/utils": "^2.29.59",
34
+ "@symbo.ls/init": "^2.29.59",
35
+ "@symbo.ls/scratch": "^2.29.59",
36
+ "@symbo.ls/socket": "^2.29.59",
37
+ "@symbo.ls/uikit": "^2.29.59",
38
38
  "socket.io-client": "^4.8.1"
39
39
  },
40
40
  "devDependencies": {