@fluxbase/sdk 0.0.1-rc.31 → 0.0.1-rc.32

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/index.d.cts CHANGED
@@ -4255,6 +4255,9 @@ declare class QueryBuilder<T = unknown> implements PromiseLike<PostgrestResponse
4255
4255
  private singleRow;
4256
4256
  private maybeSingleRow;
4257
4257
  private groupByColumns?;
4258
+ private operationType;
4259
+ private insertData?;
4260
+ private updateData?;
4258
4261
  constructor(fetch: FluxbaseFetch, table: string);
4259
4262
  /**
4260
4263
  * Select columns to return
@@ -4266,7 +4269,7 @@ declare class QueryBuilder<T = unknown> implements PromiseLike<PostgrestResponse
4266
4269
  /**
4267
4270
  * Insert a single row or multiple rows
4268
4271
  */
4269
- insert(data: Partial<T> | Array<Partial<T>>): Promise<PostgrestResponse<T>>;
4272
+ insert(data: Partial<T> | Array<Partial<T>>): this;
4270
4273
  /**
4271
4274
  * Upsert (insert or update) rows (Supabase-compatible)
4272
4275
  * @param data - Row(s) to upsert
@@ -4276,11 +4279,11 @@ declare class QueryBuilder<T = unknown> implements PromiseLike<PostgrestResponse
4276
4279
  /**
4277
4280
  * Update rows matching the filters
4278
4281
  */
4279
- update(data: Partial<T>): Promise<PostgrestResponse<T>>;
4282
+ update(data: Partial<T>): this;
4280
4283
  /**
4281
4284
  * Delete rows matching the filters
4282
4285
  */
4283
- delete(): Promise<PostgrestResponse<null>>;
4286
+ delete(): this;
4284
4287
  /**
4285
4288
  * Equal to
4286
4289
  */
@@ -4559,7 +4562,7 @@ declare class QueryBuilder<T = unknown> implements PromiseLike<PostgrestResponse
4559
4562
  * { name: 'Alice', email: 'alice@example.com' },
4560
4563
  * { name: 'Bob', email: 'bob@example.com' },
4561
4564
  * { name: 'Charlie', email: 'charlie@example.com' }
4562
- * ]).execute()
4565
+ * ])
4563
4566
  * ```
4564
4567
  *
4565
4568
  * @category Batch Operations
@@ -4580,13 +4583,11 @@ declare class QueryBuilder<T = unknown> implements PromiseLike<PostgrestResponse
4580
4583
  * const { data } = await client.from('products')
4581
4584
  * .eq('category', 'electronics')
4582
4585
  * .updateMany({ discount: 10, updated_at: new Date() })
4583
- * .execute()
4584
4586
  *
4585
4587
  * // Mark all pending orders as processing
4586
4588
  * const { data } = await client.from('orders')
4587
4589
  * .eq('status', 'pending')
4588
4590
  * .updateMany({ status: 'processing' })
4589
- * .execute()
4590
4591
  * ```
4591
4592
  *
4592
4593
  * @category Batch Operations
@@ -4606,13 +4607,11 @@ declare class QueryBuilder<T = unknown> implements PromiseLike<PostgrestResponse
4606
4607
  * await client.from('users')
4607
4608
  * .eq('active', false)
4608
4609
  * .deleteMany()
4609
- * .execute()
4610
4610
  *
4611
4611
  * // Delete old logs
4612
4612
  * await client.from('logs')
4613
4613
  * .lt('created_at', '2024-01-01')
4614
4614
  * .deleteMany()
4615
- * .execute()
4616
4615
  * ```
4617
4616
  *
4618
4617
  * @category Batch Operations
package/dist/index.d.ts CHANGED
@@ -4255,6 +4255,9 @@ declare class QueryBuilder<T = unknown> implements PromiseLike<PostgrestResponse
4255
4255
  private singleRow;
4256
4256
  private maybeSingleRow;
4257
4257
  private groupByColumns?;
4258
+ private operationType;
4259
+ private insertData?;
4260
+ private updateData?;
4258
4261
  constructor(fetch: FluxbaseFetch, table: string);
4259
4262
  /**
4260
4263
  * Select columns to return
@@ -4266,7 +4269,7 @@ declare class QueryBuilder<T = unknown> implements PromiseLike<PostgrestResponse
4266
4269
  /**
4267
4270
  * Insert a single row or multiple rows
4268
4271
  */
4269
- insert(data: Partial<T> | Array<Partial<T>>): Promise<PostgrestResponse<T>>;
4272
+ insert(data: Partial<T> | Array<Partial<T>>): this;
4270
4273
  /**
4271
4274
  * Upsert (insert or update) rows (Supabase-compatible)
4272
4275
  * @param data - Row(s) to upsert
@@ -4276,11 +4279,11 @@ declare class QueryBuilder<T = unknown> implements PromiseLike<PostgrestResponse
4276
4279
  /**
4277
4280
  * Update rows matching the filters
4278
4281
  */
4279
- update(data: Partial<T>): Promise<PostgrestResponse<T>>;
4282
+ update(data: Partial<T>): this;
4280
4283
  /**
4281
4284
  * Delete rows matching the filters
4282
4285
  */
4283
- delete(): Promise<PostgrestResponse<null>>;
4286
+ delete(): this;
4284
4287
  /**
4285
4288
  * Equal to
4286
4289
  */
@@ -4559,7 +4562,7 @@ declare class QueryBuilder<T = unknown> implements PromiseLike<PostgrestResponse
4559
4562
  * { name: 'Alice', email: 'alice@example.com' },
4560
4563
  * { name: 'Bob', email: 'bob@example.com' },
4561
4564
  * { name: 'Charlie', email: 'charlie@example.com' }
4562
- * ]).execute()
4565
+ * ])
4563
4566
  * ```
4564
4567
  *
4565
4568
  * @category Batch Operations
@@ -4580,13 +4583,11 @@ declare class QueryBuilder<T = unknown> implements PromiseLike<PostgrestResponse
4580
4583
  * const { data } = await client.from('products')
4581
4584
  * .eq('category', 'electronics')
4582
4585
  * .updateMany({ discount: 10, updated_at: new Date() })
4583
- * .execute()
4584
4586
  *
4585
4587
  * // Mark all pending orders as processing
4586
4588
  * const { data } = await client.from('orders')
4587
4589
  * .eq('status', 'pending')
4588
4590
  * .updateMany({ status: 'processing' })
4589
- * .execute()
4590
4591
  * ```
4591
4592
  *
4592
4593
  * @category Batch Operations
@@ -4606,13 +4607,11 @@ declare class QueryBuilder<T = unknown> implements PromiseLike<PostgrestResponse
4606
4607
  * await client.from('users')
4607
4608
  * .eq('active', false)
4608
4609
  * .deleteMany()
4609
- * .execute()
4610
4610
  *
4611
4611
  * // Delete old logs
4612
4612
  * await client.from('logs')
4613
4613
  * .lt('created_at', '2024-01-01')
4614
4614
  * .deleteMany()
4615
- * .execute()
4616
4615
  * ```
4617
4616
  *
4618
4617
  * @category Batch Operations
package/dist/index.js CHANGED
@@ -3964,6 +3964,7 @@ var QueryBuilder = class {
3964
3964
  this.orderBys = [];
3965
3965
  this.singleRow = false;
3966
3966
  this.maybeSingleRow = false;
3967
+ this.operationType = "select";
3967
3968
  this.fetch = fetch2;
3968
3969
  this.table = table;
3969
3970
  }
@@ -3980,16 +3981,10 @@ var QueryBuilder = class {
3980
3981
  /**
3981
3982
  * Insert a single row or multiple rows
3982
3983
  */
3983
- async insert(data) {
3984
- const body = Array.isArray(data) ? data : data;
3985
- const response = await this.fetch.post(`/api/v1/tables/${this.table}`, body);
3986
- return {
3987
- data: response,
3988
- error: null,
3989
- count: Array.isArray(data) ? data.length : 1,
3990
- status: 201,
3991
- statusText: "Created"
3992
- };
3984
+ insert(data) {
3985
+ this.operationType = "insert";
3986
+ this.insertData = data;
3987
+ return this;
3993
3988
  }
3994
3989
  /**
3995
3990
  * Upsert (insert or update) rows (Supabase-compatible)
@@ -4026,32 +4021,17 @@ var QueryBuilder = class {
4026
4021
  /**
4027
4022
  * Update rows matching the filters
4028
4023
  */
4029
- async update(data) {
4030
- const queryString = this.buildQueryString();
4031
- const path = `/api/v1/tables/${this.table}${queryString}`;
4032
- const response = await this.fetch.patch(path, data);
4033
- return {
4034
- data: response,
4035
- error: null,
4036
- count: null,
4037
- status: 200,
4038
- statusText: "OK"
4039
- };
4024
+ update(data) {
4025
+ this.operationType = "update";
4026
+ this.updateData = data;
4027
+ return this;
4040
4028
  }
4041
4029
  /**
4042
4030
  * Delete rows matching the filters
4043
4031
  */
4044
- async delete() {
4045
- const queryString = this.buildQueryString();
4046
- const path = `/api/v1/tables/${this.table}${queryString}`;
4047
- await this.fetch.delete(path);
4048
- return {
4049
- data: null,
4050
- error: null,
4051
- count: null,
4052
- status: 204,
4053
- statusText: "No Content"
4054
- };
4032
+ delete() {
4033
+ this.operationType = "delete";
4034
+ return this;
4055
4035
  }
4056
4036
  /**
4057
4037
  * Equal to
@@ -4430,13 +4410,13 @@ var QueryBuilder = class {
4430
4410
  * { name: 'Alice', email: 'alice@example.com' },
4431
4411
  * { name: 'Bob', email: 'bob@example.com' },
4432
4412
  * { name: 'Charlie', email: 'charlie@example.com' }
4433
- * ]).execute()
4413
+ * ])
4434
4414
  * ```
4435
4415
  *
4436
4416
  * @category Batch Operations
4437
4417
  */
4438
4418
  async insertMany(rows) {
4439
- return this.insert(rows);
4419
+ return this.insert(rows).execute();
4440
4420
  }
4441
4421
  /**
4442
4422
  * Update multiple rows matching the filters (batch update)
@@ -4453,19 +4433,17 @@ var QueryBuilder = class {
4453
4433
  * const { data } = await client.from('products')
4454
4434
  * .eq('category', 'electronics')
4455
4435
  * .updateMany({ discount: 10, updated_at: new Date() })
4456
- * .execute()
4457
4436
  *
4458
4437
  * // Mark all pending orders as processing
4459
4438
  * const { data } = await client.from('orders')
4460
4439
  * .eq('status', 'pending')
4461
4440
  * .updateMany({ status: 'processing' })
4462
- * .execute()
4463
4441
  * ```
4464
4442
  *
4465
4443
  * @category Batch Operations
4466
4444
  */
4467
4445
  async updateMany(data) {
4468
- return this.update(data);
4446
+ return this.update(data).execute();
4469
4447
  }
4470
4448
  /**
4471
4449
  * Delete multiple rows matching the filters (batch delete)
@@ -4481,27 +4459,66 @@ var QueryBuilder = class {
4481
4459
  * await client.from('users')
4482
4460
  * .eq('active', false)
4483
4461
  * .deleteMany()
4484
- * .execute()
4485
4462
  *
4486
4463
  * // Delete old logs
4487
4464
  * await client.from('logs')
4488
4465
  * .lt('created_at', '2024-01-01')
4489
4466
  * .deleteMany()
4490
- * .execute()
4491
4467
  * ```
4492
4468
  *
4493
4469
  * @category Batch Operations
4494
4470
  */
4495
4471
  async deleteMany() {
4496
- return this.delete();
4472
+ return this.delete().execute();
4497
4473
  }
4498
4474
  /**
4499
4475
  * Execute the query and return results
4500
4476
  */
4501
4477
  async execute() {
4502
- const queryString = this.buildQueryString();
4503
- const path = `/api/v1/tables/${this.table}${queryString}`;
4504
4478
  try {
4479
+ if (this.operationType === "insert") {
4480
+ if (!this.insertData) {
4481
+ throw new Error("Insert data is required for insert operation");
4482
+ }
4483
+ const body = Array.isArray(this.insertData) ? this.insertData : this.insertData;
4484
+ const response = await this.fetch.post(`/api/v1/tables/${this.table}`, body);
4485
+ return {
4486
+ data: response,
4487
+ error: null,
4488
+ count: Array.isArray(this.insertData) ? this.insertData.length : 1,
4489
+ status: 201,
4490
+ statusText: "Created"
4491
+ };
4492
+ }
4493
+ if (this.operationType === "update") {
4494
+ if (!this.updateData) {
4495
+ throw new Error("Update data is required for update operation");
4496
+ }
4497
+ const queryString2 = this.buildQueryString();
4498
+ const path2 = `/api/v1/tables/${this.table}${queryString2}`;
4499
+ const response = await this.fetch.patch(path2, this.updateData);
4500
+ return {
4501
+ data: response,
4502
+ error: null,
4503
+ count: null,
4504
+ status: 200,
4505
+ statusText: "OK"
4506
+ };
4507
+ }
4508
+ if (this.operationType === "delete") {
4509
+ const queryString2 = this.buildQueryString();
4510
+ const path2 = `/api/v1/tables/${this.table}${queryString2}`;
4511
+ await this.fetch.delete(path2);
4512
+ return {
4513
+ data: null,
4514
+ error: null,
4515
+ count: null,
4516
+ status: 204,
4517
+ statusText: "No Content"
4518
+ };
4519
+ }
4520
+ const queryString = this.buildQueryString();
4521
+ const path = `/api/v1/tables/${this.table}${queryString}`;
4505
4522
  const data = await this.fetch.get(path);
4506
4523
  if (this.singleRow) {
4507
4524
  if (Array.isArray(data) && data.length === 0) {