@inflector/aura 0.1.16 → 0.1.17
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/database.d.ts.map +1 -1
- package/dist/database.js +16 -55
- package/package.json +2 -1
package/dist/database.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAS,KAAK,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAS,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAMjE,cAAM,WAAW,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAQ;IACnB,OAAO,CAAC,IAAI,CAAQ;IACpB,OAAO,CAAC,SAAS,CAAQ;IAEzB,OAAO,CAAC,cAAc;gBAKV,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAMxD,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wvBAYF;IACD,MAAM;;ovBAYL;IACD,MAAM;;wvBAYL;IACD,GAAG,GAAI,QAAQ,QAAQ,CAAC,IAAI,CAAC,gvBAe5B;IACD,OAAO,GAAI,QAAQ,QAAQ,CAAC,IAAI,CAAC,EAAE,gvBAelC;IACD,MAAM,GAAI,QAAQ,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;;wvBAarC;IACD,KAAK;;4BAYJ;IACD,KAAK;;6BAYJ;IACD,SAAS,GAAI,UAAU,CAAC,CAAC,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,GAAG,GAAG,EAAE,CAAA;KAAE,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAA;KAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,EAAE,OAAO,OAAO,gBA+B7J;CACJ;AAED,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAAE,EACzE,KAAK,MAAM,EACX,WAAW,MAAM,EACjB,QAAQ,CAAC,QAEe,CAAC,kCAY5B,CAAA"}
|
package/dist/database.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createFluentBuilder } from "./fluent";
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
import { getToken } from "./auth";
|
|
4
|
+
import { SSE } from "sse.js";
|
|
4
5
|
class RemoteTable {
|
|
5
6
|
URL;
|
|
6
7
|
Name;
|
|
@@ -108,66 +109,26 @@ class RemoteTable {
|
|
|
108
109
|
if (init)
|
|
109
110
|
params.push("init=true");
|
|
110
111
|
const query = params.length ? "?" + params.join("&") : "";
|
|
111
|
-
let abortController = new AbortController();
|
|
112
112
|
const tableName = this.Name;
|
|
113
|
-
const
|
|
113
|
+
const url = `${this.URL}/api/db/${this.WorkSpace}/${this.Name}${query}`;
|
|
114
|
+
const source = new SSE(url, {
|
|
115
|
+
headers: this.getAuthHeaders(),
|
|
116
|
+
});
|
|
117
|
+
source.addEventListener(tableName, (event) => {
|
|
114
118
|
try {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
headers: {
|
|
118
|
-
...this.getAuthHeaders(),
|
|
119
|
-
'Accept': 'text/event-stream',
|
|
120
|
-
},
|
|
121
|
-
signal: abortController?.signal,
|
|
122
|
-
});
|
|
123
|
-
if (!response.ok || !response.body) {
|
|
124
|
-
throw new Error(`SSE connection failed: ${response.status}`);
|
|
125
|
-
}
|
|
126
|
-
const reader = response.body.getReader();
|
|
127
|
-
const decoder = new TextDecoder();
|
|
128
|
-
let buffer = '';
|
|
129
|
-
while (true) {
|
|
130
|
-
const { done, value } = await reader.read();
|
|
131
|
-
if (done)
|
|
132
|
-
break;
|
|
133
|
-
buffer += decoder.decode(value, { stream: true });
|
|
134
|
-
const lines = buffer.split('\n');
|
|
135
|
-
buffer = lines.pop() || '';
|
|
136
|
-
let currentEvent = '';
|
|
137
|
-
let currentData = '';
|
|
138
|
-
for (const line of lines) {
|
|
139
|
-
if (line.startsWith('event:')) {
|
|
140
|
-
currentEvent = line.slice(6).trim();
|
|
141
|
-
}
|
|
142
|
-
else if (line.startsWith('data:')) {
|
|
143
|
-
currentData = line.slice(5).trim();
|
|
144
|
-
}
|
|
145
|
-
else if (line === '' && currentEvent === tableName && currentData) {
|
|
146
|
-
try {
|
|
147
|
-
const { op, data } = JSON.parse(currentData);
|
|
148
|
-
callback({ action: op, data });
|
|
149
|
-
}
|
|
150
|
-
catch (e) {
|
|
151
|
-
// Ignore parse errors
|
|
152
|
-
}
|
|
153
|
-
currentEvent = '';
|
|
154
|
-
currentData = '';
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
119
|
+
const { op, data } = JSON.parse(event.data);
|
|
120
|
+
callback({ action: op, data });
|
|
158
121
|
}
|
|
159
|
-
catch (
|
|
160
|
-
|
|
161
|
-
console.error('SSE stream error:', error);
|
|
162
|
-
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
// Ignore parse errors
|
|
163
124
|
}
|
|
164
|
-
};
|
|
165
|
-
|
|
125
|
+
});
|
|
126
|
+
source.addEventListener('error', (error) => {
|
|
127
|
+
console.error('SSE stream error:', error);
|
|
128
|
+
});
|
|
129
|
+
source.stream();
|
|
166
130
|
return () => {
|
|
167
|
-
|
|
168
|
-
abortController.abort();
|
|
169
|
-
abortController = null;
|
|
170
|
-
}
|
|
131
|
+
source.close();
|
|
171
132
|
};
|
|
172
133
|
};
|
|
173
134
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inflector/aura",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"chalk": "^5.6.2",
|
|
43
43
|
"chokidar": "^5.0.0",
|
|
44
44
|
"eventsource": "^4.1.0",
|
|
45
|
+
"sse.js": "^2.7.2",
|
|
45
46
|
"tsx": "^4.20.4",
|
|
46
47
|
"zod": "^3.25.67"
|
|
47
48
|
}
|