@gokiteam/goki-dev-client 0.2.2 → 0.2.4

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/client.d.ts CHANGED
@@ -178,6 +178,14 @@ export declare class FirestoreClient {
178
178
  private client;
179
179
  constructor(client: AxiosInstance);
180
180
  private call;
181
+ /**
182
+ * Converts a plain JS value to a Firestore REST API typed value.
183
+ */
184
+ private toFirestoreValue;
185
+ /**
186
+ * Converts a plain JS object to Firestore REST API fields format.
187
+ */
188
+ private toFirestoreFields;
181
189
  /**
182
190
  * Parses a Firestore REST API typed value into a plain JS value.
183
191
  */
@@ -220,6 +228,30 @@ export declare class FirestoreClient {
220
228
  waitForCondition(params: Types.WaitForConditionRequest & {
221
229
  type: 'firestore';
222
230
  }): Promise<Types.WaitForConditionResponse>;
231
+ createDocument(params: Types.CreateDocumentRequest): Promise<{
232
+ document: Types.FirestoreDocument;
233
+ }>;
234
+ setDocument(params: Types.SetDocumentRequest): Promise<{
235
+ document: Types.FirestoreDocument;
236
+ }>;
237
+ updateDocument(params: Types.UpdateDocumentRequest): Promise<{
238
+ document: Types.FirestoreDocument;
239
+ }>;
240
+ deleteDocument(params: Types.DeleteDocumentRequest): Promise<void>;
241
+ clearCollection(params: Types.ClearCollectionRequest): Promise<{
242
+ deletedCount: number;
243
+ } & {
244
+ traceId: string;
245
+ }>;
246
+ createBatch(params: Types.CreateBatchRequest): Promise<Types.CreateBatchResponse>;
247
+ listCollections(params?: {
248
+ traceId?: string;
249
+ }): Promise<{
250
+ collections: string[];
251
+ total: number;
252
+ } & {
253
+ traceId: string;
254
+ }>;
223
255
  }
224
256
  export declare class MqttClient {
225
257
  private client;
package/dist/client.js CHANGED
@@ -233,6 +233,41 @@ class FirestoreClient {
233
233
  const response = await this.client.post(endpoint, data);
234
234
  return response.data;
235
235
  }
236
+ /**
237
+ * Converts a plain JS value to a Firestore REST API typed value.
238
+ */
239
+ toFirestoreValue(value) {
240
+ if (value === null || value === undefined)
241
+ return { nullValue: null };
242
+ if (typeof value === 'string')
243
+ return { stringValue: value };
244
+ if (typeof value === 'boolean')
245
+ return { booleanValue: value };
246
+ if (typeof value === 'number') {
247
+ if (Number.isInteger(value))
248
+ return { integerValue: String(value) };
249
+ return { doubleValue: value };
250
+ }
251
+ if (value instanceof Date)
252
+ return { timestampValue: value.toISOString() };
253
+ if (Array.isArray(value)) {
254
+ return { arrayValue: { values: value.map(v => this.toFirestoreValue(v)) } };
255
+ }
256
+ if (typeof value === 'object') {
257
+ return { mapValue: { fields: this.toFirestoreFields(value) } };
258
+ }
259
+ return { stringValue: String(value) };
260
+ }
261
+ /**
262
+ * Converts a plain JS object to Firestore REST API fields format.
263
+ */
264
+ toFirestoreFields(data) {
265
+ const fields = {};
266
+ for (const [key, value] of Object.entries(data)) {
267
+ fields[key] = this.toFirestoreValue(value);
268
+ }
269
+ return fields;
270
+ }
236
271
  /**
237
272
  * Parses a Firestore REST API typed value into a plain JS value.
238
273
  */
@@ -290,6 +325,9 @@ class FirestoreClient {
290
325
  documentId: params.documentId,
291
326
  traceId: params.traceId
292
327
  });
328
+ if (result.data.status === 'error') {
329
+ throw new Error(result.data.message || 'Firestore error');
330
+ }
293
331
  const rawDocument = result.data.document;
294
332
  return { document: this.parseRawDocument(rawDocument) };
295
333
  }
@@ -343,6 +381,69 @@ class FirestoreClient {
343
381
  const result = await this.call('/v1/firestore/documents/wait-for', params);
344
382
  return result.data;
345
383
  }
384
+ async createDocument(params) {
385
+ const result = await this.call('/v1/firestore/documents/create', {
386
+ collectionPath: params.collection,
387
+ documentId: params.documentId,
388
+ fields: this.toFirestoreFields(params.data),
389
+ traceId: params.traceId
390
+ });
391
+ return { document: this.parseRawDocument(result.data.document) };
392
+ }
393
+ async setDocument(params) {
394
+ const result = await this.call('/v1/firestore/documents/set', {
395
+ collectionPath: params.collection,
396
+ documentId: params.documentId,
397
+ fields: this.toFirestoreFields(params.data),
398
+ traceId: params.traceId
399
+ });
400
+ return { document: this.parseRawDocument(result.data.document) };
401
+ }
402
+ async updateDocument(params) {
403
+ const result = await this.call('/v1/firestore/documents/update', {
404
+ collectionPath: params.collection,
405
+ documentId: params.documentId,
406
+ fields: this.toFirestoreFields(params.data),
407
+ traceId: params.traceId
408
+ });
409
+ return { document: this.parseRawDocument(result.data.document) };
410
+ }
411
+ async deleteDocument(params) {
412
+ await this.call('/v1/firestore/documents/delete', {
413
+ collectionPath: params.collection,
414
+ documentId: params.documentId,
415
+ traceId: params.traceId
416
+ });
417
+ }
418
+ async clearCollection(params) {
419
+ const result = await this.call('/v1/firestore/collection/clear', {
420
+ collectionPath: params.collection,
421
+ traceId: params.traceId
422
+ });
423
+ return result.data;
424
+ }
425
+ async createBatch(params) {
426
+ const documents = params.documents.map(doc => ({
427
+ documentId: doc.id,
428
+ fields: this.toFirestoreFields(doc.data)
429
+ }));
430
+ const result = await this.call('/v1/firestore/documents/create-batch', {
431
+ collectionPath: params.collection,
432
+ documents,
433
+ traceId: params.traceId
434
+ });
435
+ return {
436
+ createdCount: result.data.createdCount,
437
+ failedIds: result.data.failedIds,
438
+ traceId: result.data.traceId
439
+ };
440
+ }
441
+ async listCollections(params = {}) {
442
+ const result = await this.call('/v1/firestore/collections/list', {
443
+ traceId: params.traceId
444
+ });
445
+ return result.data;
446
+ }
346
447
  }
347
448
  exports.FirestoreClient = FirestoreClient;
348
449
  // ============================================================================
package/dist/types.d.ts CHANGED
@@ -130,6 +130,47 @@ export interface DeleteBatchResponse {
130
130
  failedIds: string[];
131
131
  traceId: string;
132
132
  }
133
+ export interface CreateDocumentRequest {
134
+ collection: string;
135
+ documentId?: string;
136
+ data: Record<string, any>;
137
+ traceId?: string;
138
+ }
139
+ export interface SetDocumentRequest {
140
+ collection: string;
141
+ documentId: string;
142
+ data: Record<string, any>;
143
+ traceId?: string;
144
+ }
145
+ export interface UpdateDocumentRequest {
146
+ collection: string;
147
+ documentId: string;
148
+ data: Record<string, any>;
149
+ traceId?: string;
150
+ }
151
+ export interface DeleteDocumentRequest {
152
+ collection: string;
153
+ documentId: string;
154
+ traceId?: string;
155
+ }
156
+ export interface ClearCollectionRequest {
157
+ collection: string;
158
+ traceId?: string;
159
+ }
160
+ export interface CreateBatchDocument {
161
+ id?: string;
162
+ data: Record<string, any>;
163
+ }
164
+ export interface CreateBatchRequest {
165
+ collection: string;
166
+ documents: CreateBatchDocument[];
167
+ traceId?: string;
168
+ }
169
+ export interface CreateBatchResponse {
170
+ createdCount: number;
171
+ failedIds: string[];
172
+ traceId: string;
173
+ }
133
174
  export interface MqttClientInfo {
134
175
  clientId: string;
135
176
  connected: boolean;
@@ -318,6 +359,8 @@ export interface HttpTrafficWaitFilter {
318
359
  statusCode?: number;
319
360
  traceId?: string;
320
361
  pathContains?: string;
362
+ since?: string;
363
+ until?: string;
321
364
  }
322
365
  export interface HttpTrafficStats {
323
366
  total: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gokiteam/goki-dev-client",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Client SDK for Goki Developer Tools platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",