@inflector/aura 0.1.15 → 0.1.16
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 +61 -10
- package/package.json +1 -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;AAKjE,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,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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,gBAuE7J;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
|
@@ -107,17 +107,68 @@ class RemoteTable {
|
|
|
107
107
|
params.push("where=" + JSON.stringify(where));
|
|
108
108
|
if (init)
|
|
109
109
|
params.push("init=true");
|
|
110
|
-
// Add token to query params for EventSource (doesn't support headers)
|
|
111
|
-
const token = getToken(this.WorkSpace);
|
|
112
|
-
if (token)
|
|
113
|
-
params.push("token=" + encodeURIComponent(token));
|
|
114
110
|
const query = params.length ? "?" + params.join("&") : "";
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
111
|
+
let abortController = new AbortController();
|
|
112
|
+
const tableName = this.Name;
|
|
113
|
+
const startStream = async () => {
|
|
114
|
+
try {
|
|
115
|
+
const response = await fetch(`${this.URL}/api/db/${this.WorkSpace}/${this.Name}${query}`, {
|
|
116
|
+
method: 'GET',
|
|
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
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
if (error.name !== 'AbortError') {
|
|
161
|
+
console.error('SSE stream error:', error);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
startStream();
|
|
166
|
+
return () => {
|
|
167
|
+
if (abortController) {
|
|
168
|
+
abortController.abort();
|
|
169
|
+
abortController = null;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
121
172
|
};
|
|
122
173
|
}
|
|
123
174
|
export const AuraDatabase = (url, workspace, tables) => {
|