@mongoosejs/studio 0.0.121 → 0.0.122

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.
@@ -114,8 +114,54 @@ if (window.MONGOOSE_STUDIO_CONFIG.isLambda) {
114
114
  getDocuments: function getDocuments(params) {
115
115
  return client.post('', { action: 'Model.getDocuments', ...params }).then(res => res.data);
116
116
  },
117
- getDocumentsStream: function getDocumentsStream(params) {
118
- return client.post('', { action: 'Model.getDocumentsStream', ...params }).then(res => res.data);
117
+ getDocumentsStream: async function* getDocumentsStream(params) {
118
+ const accessToken = window.localStorage.getItem('_mongooseStudioAccessToken') || null;
119
+ const url = window.MONGOOSE_STUDIO_CONFIG.baseURL + '?' + new URLSearchParams({ ...params, action: 'Model.getDocumentsStream' }).toString();
120
+
121
+ const response = await fetch(url, {
122
+ method: 'GET',
123
+ headers: {
124
+ Authorization: `${accessToken}`,
125
+ Accept: 'text/event-stream'
126
+ }
127
+ });
128
+
129
+ if (!response.ok) {
130
+ throw new Error(`HTTP error! Status: ${response.status}`);
131
+ }
132
+
133
+ const reader = response.body.getReader();
134
+ const decoder = new TextDecoder('utf-8');
135
+ let buffer = '';
136
+
137
+ while (true) {
138
+ const { done, value } = await reader.read();
139
+ if (done) break;
140
+ buffer += decoder.decode(value, { stream: true });
141
+
142
+ let eventEnd;
143
+ while ((eventEnd = buffer.indexOf('\n\n')) !== -1) {
144
+ const eventStr = buffer.slice(0, eventEnd);
145
+ buffer = buffer.slice(eventEnd + 2);
146
+
147
+ // Parse SSE event
148
+ const lines = eventStr.split('\n');
149
+ let data = '';
150
+ for (const line of lines) {
151
+ if (line.startsWith('data:')) {
152
+ data += line.slice(5).trim();
153
+ }
154
+ }
155
+ if (data) {
156
+ try {
157
+ yield JSON.parse(data);
158
+ } catch (err) {
159
+ // If not JSON, yield as string
160
+ yield data;
161
+ }
162
+ }
163
+ }
164
+ }
119
165
  },
120
166
  getIndexes: function getIndexes(params) {
121
167
  return client.post('', { action: 'Model.getIndexes', ...params }).then(res => res.data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mongoosejs/studio",
3
- "version": "0.0.121",
3
+ "version": "0.0.122",
4
4
  "description": "A sleek, powerful MongoDB UI with built-in dashboarding and auth, seamlessly integrated with your Express, Vercel, or Netlify app.",
5
5
  "homepage": "https://studio.mongoosejs.io/",
6
6
  "repository": {