supabase-typed-query 0.13.0 → 1.1.0
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/README.md +54 -1
- package/dist/index.js +314 -312
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +315 -310
- package/dist/index.mjs.map +1 -1
- package/dist/src/entity/PartitionedViewEntity.d.ts +30 -0
- package/dist/src/entity/PartitionedViewEntity.d.ts.map +1 -0
- package/dist/src/entity/ViewEntity.d.ts +27 -0
- package/dist/src/entity/ViewEntity.d.ts.map +1 -0
- package/dist/src/entity/core.d.ts +21 -1
- package/dist/src/entity/core.d.ts.map +1 -1
- package/dist/src/entity/index.d.ts +4 -0
- package/dist/src/entity/index.d.ts.map +1 -1
- package/dist/src/entity/types.d.ts +47 -6
- package/dist/src/entity/types.d.ts.map +1 -1
- package/dist/src/index.d.ts +5 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/query/Query.d.ts +13 -13
- package/dist/src/query/Query.d.ts.map +1 -1
- package/dist/src/query/QueryBuilder.d.ts +3 -0
- package/dist/src/query/QueryBuilder.d.ts.map +1 -1
- package/dist/src/query/index.d.ts +19 -19
- package/dist/src/query/index.d.ts.map +1 -1
- package/dist/src/query/rpc.d.ts +7 -5
- package/dist/src/query/rpc.d.ts.map +1 -1
- package/dist/src/types.d.ts +21 -0
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -7,12 +7,13 @@ Type-safe query builder and entity pattern for Supabase with TypeScript.
|
|
|
7
7
|
- 🔒 **Full TypeScript type safety** - Leverage your database types for compile-time safety
|
|
8
8
|
- 🔗 **Chainable query API** - Build complex queries with OR conditions and functional operations
|
|
9
9
|
- 🎯 **Entity pattern** - Consistent CRUD operations across all tables
|
|
10
|
+
- 👁️ **View support** - Read-only ViewEntity for querying database views
|
|
10
11
|
- 🚀 **Functional programming** - Built with functype for robust error handling
|
|
11
12
|
- ⚡ **Zero runtime overhead** - All type checking happens at compile time
|
|
12
13
|
- 🔄 **Composable queries** - Mix and match conditions, filters, and transformations
|
|
13
14
|
- 🗑️ **Soft delete support** - Built-in soft delete filtering with per-query overrides
|
|
14
15
|
- 🏢 **Multi-tenancy ready** - Automatic partition key filtering for tenant isolation
|
|
15
|
-
- 🗄️ **Custom schema support** - Query tables in any PostgreSQL schema
|
|
16
|
+
- 🗄️ **Custom schema support** - Query tables and views in any PostgreSQL schema
|
|
16
17
|
|
|
17
18
|
## Installation
|
|
18
19
|
|
|
@@ -235,6 +236,42 @@ const results = await query(
|
|
|
235
236
|
|
|
236
237
|
When no schema is specified, queries use the default `public` schema via `client.from()`. When a schema is specified, queries use `client.schema(name).from(table)`.
|
|
237
238
|
|
|
239
|
+
### View Entities (Read-Only)
|
|
240
|
+
|
|
241
|
+
Database views in Supabase are read-only and only have a `Row` type (no `Insert` or `Update`). Use `ViewEntity` for type-safe querying of views:
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
import { ViewEntity, PartitionedViewEntity } from "supabase-typed-query"
|
|
245
|
+
|
|
246
|
+
// Create a read-only view entity
|
|
247
|
+
const AuthUsersView = ViewEntity(supabase, "auth_users_view", {
|
|
248
|
+
schema: "agent_gate", // Optional: defaults to "public"
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
// Query the view - only getItem and getItems are available
|
|
252
|
+
const user = await AuthUsersView.getItem({ id: "123" }).one()
|
|
253
|
+
const activeUsers = await AuthUsersView.getItems({
|
|
254
|
+
where: { is_active: true },
|
|
255
|
+
order: ["created_at", { ascending: false }],
|
|
256
|
+
}).many()
|
|
257
|
+
|
|
258
|
+
// For multi-tenant views, use PartitionedViewEntity
|
|
259
|
+
const TenantStatsView = PartitionedViewEntity(supabase, "tenant_stats_view", {
|
|
260
|
+
partitionField: "tenant_id",
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
// All queries require partition key
|
|
264
|
+
const stats = await TenantStatsView.getItems(tenantId, {
|
|
265
|
+
where: { period: "monthly" },
|
|
266
|
+
}).many()
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
**Key differences from Entity:**
|
|
270
|
+
|
|
271
|
+
- Only `getItem()` and `getItems()` methods (no write operations)
|
|
272
|
+
- No `softDelete` configuration (views are read-only snapshots)
|
|
273
|
+
- Uses `ViewNames` and `ViewRow` types instead of `TableNames` and `TableRow`
|
|
274
|
+
|
|
238
275
|
### Multi-Tenancy with Partition Keys
|
|
239
276
|
|
|
240
277
|
Use partition keys to automatically scope queries to a tenant or partition:
|
|
@@ -346,6 +383,22 @@ const posts = await query(supabase, "posts", {
|
|
|
346
383
|
- `softDelete: boolean` - (Required) When `true`, automatically excludes soft-deleted items
|
|
347
384
|
- `schema?: string` - (Optional) PostgreSQL schema to query from (defaults to `"public"`)
|
|
348
385
|
|
|
386
|
+
### ViewEntity Methods
|
|
387
|
+
|
|
388
|
+
- `getItem({ id, where?, is? })` - Get a single item by ID
|
|
389
|
+
- `getItems({ where?, is?, wherein?, order? })` - Get filtered items
|
|
390
|
+
|
|
391
|
+
> **Note:** ViewEntity only supports read operations. No `addItems`, `updateItem`, `deleteItem`, or soft delete methods.
|
|
392
|
+
|
|
393
|
+
### ViewEntity Configuration
|
|
394
|
+
|
|
395
|
+
- `schema?: string` - (Optional) PostgreSQL schema to query from (defaults to `"public"`)
|
|
396
|
+
|
|
397
|
+
### PartitionedViewEntity Configuration
|
|
398
|
+
|
|
399
|
+
- `partitionField: string` - (Required) Column name used for partition filtering (e.g., `"tenant_id"`)
|
|
400
|
+
- `schema?: string` - (Optional) PostgreSQL schema to query from (defaults to `"public"`)
|
|
401
|
+
|
|
349
402
|
## Requirements
|
|
350
403
|
|
|
351
404
|
- TypeScript 5.0+
|