@gokiteam/goki-dev-client 0.2.2 → 0.2.3

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
  */
@@ -343,6 +378,69 @@ class FirestoreClient {
343
378
  const result = await this.call('/v1/firestore/documents/wait-for', params);
344
379
  return result.data;
345
380
  }
381
+ async createDocument(params) {
382
+ const result = await this.call('/v1/firestore/documents/create', {
383
+ collectionPath: params.collection,
384
+ documentId: params.documentId,
385
+ fields: this.toFirestoreFields(params.data),
386
+ traceId: params.traceId
387
+ });
388
+ return { document: this.parseRawDocument(result.data.document) };
389
+ }
390
+ async setDocument(params) {
391
+ const result = await this.call('/v1/firestore/documents/set', {
392
+ collectionPath: params.collection,
393
+ documentId: params.documentId,
394
+ fields: this.toFirestoreFields(params.data),
395
+ traceId: params.traceId
396
+ });
397
+ return { document: this.parseRawDocument(result.data.document) };
398
+ }
399
+ async updateDocument(params) {
400
+ const result = await this.call('/v1/firestore/documents/update', {
401
+ collectionPath: params.collection,
402
+ documentId: params.documentId,
403
+ fields: this.toFirestoreFields(params.data),
404
+ traceId: params.traceId
405
+ });
406
+ return { document: this.parseRawDocument(result.data.document) };
407
+ }
408
+ async deleteDocument(params) {
409
+ await this.call('/v1/firestore/documents/delete', {
410
+ collectionPath: params.collection,
411
+ documentId: params.documentId,
412
+ traceId: params.traceId
413
+ });
414
+ }
415
+ async clearCollection(params) {
416
+ const result = await this.call('/v1/firestore/collection/clear', {
417
+ collectionPath: params.collection,
418
+ traceId: params.traceId
419
+ });
420
+ return result.data;
421
+ }
422
+ async createBatch(params) {
423
+ const documents = params.documents.map(doc => ({
424
+ documentId: doc.id,
425
+ fields: this.toFirestoreFields(doc.data)
426
+ }));
427
+ const result = await this.call('/v1/firestore/documents/create-batch', {
428
+ collectionPath: params.collection,
429
+ documents,
430
+ traceId: params.traceId
431
+ });
432
+ return {
433
+ createdCount: result.data.createdCount,
434
+ failedIds: result.data.failedIds,
435
+ traceId: result.data.traceId
436
+ };
437
+ }
438
+ async listCollections(params = {}) {
439
+ const result = await this.call('/v1/firestore/collections/list', {
440
+ traceId: params.traceId
441
+ });
442
+ return result.data;
443
+ }
346
444
  }
347
445
  exports.FirestoreClient = FirestoreClient;
348
446
  // ============================================================================
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;
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.3",
4
4
  "description": "Client SDK for Goki Developer Tools platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",