@b9g/zen 0.1.1 → 0.1.2
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/CHANGELOG.md +17 -0
- package/README.md +146 -52
- package/{chunk-CHF7L5PC.js → chunk-ARUUB3H4.js} +1 -1
- package/{chunk-XHXMCOSW.js → chunk-BEX6VPES.js} +16 -0
- package/{chunk-W7JTNEM4.js → chunk-NBXBBEMA.js} +1 -1
- package/{ddl-2A2UFUR3.js → ddl-OT6HPLQY.js} +2 -2
- package/package.json +10 -1
- package/src/bun.js +4 -4
- package/src/mysql.js +3 -3
- package/src/postgres.js +3 -3
- package/src/sqlite.js +3 -3
- package/src/zen.d.ts +6 -7
- package/src/zen.js +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.1.2] - 2025-12-22
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- New type exports: `PartialTable`, `DerivedTable`, `SetValues`, `FieldDBMeta`, `ReferenceInfo`, `CompoundReference`, `TaggedQuery`, `SQLDialect`, `isTable`
|
|
13
|
+
- Views documentation section in README
|
|
14
|
+
- `EnsureError` and `SchemaDriftError` documented in error types
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Reorganized `zen.ts` exports into logical groups
|
|
19
|
+
- README Types section now accurately reflects actual exports (removed non-existent `SQLFragment`, `DDLFragment`, `DBExpression`)
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- `isTable` type guard now exported (was missing)
|
|
24
|
+
|
|
8
25
|
## [0.1.1] - 2025-12-21
|
|
9
26
|
|
|
10
27
|
### Added
|
package/README.md
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
# ZenDB
|
|
2
|
-
The simple database client.
|
|
3
2
|
|
|
4
|
-
Define tables. Write SQL. Get objects.
|
|
3
|
+
The simple database client. Define tables. Write SQL. Get objects.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
[Website](https://zendb.org) · [GitHub](https://github.com/bikeshaving/zen) · [npm](https://www.npmjs.com/package/@b9g/zen)
|
|
7
6
|
|
|
8
7
|
## Installation
|
|
9
8
|
|
|
@@ -58,7 +57,7 @@ const Posts = table("posts", {
|
|
|
58
57
|
id: z.string().uuid().db.primary().db.auto(),
|
|
59
58
|
authorId: z.string().uuid().db.references(Users, "author"),
|
|
60
59
|
title: z.string(),
|
|
61
|
-
published: z.boolean().
|
|
60
|
+
published: z.boolean().db.inserted(() => false),
|
|
62
61
|
});
|
|
63
62
|
|
|
64
63
|
// 2. Create database with migrations
|
|
@@ -111,6 +110,32 @@ const post = await db.get(Posts, posts[0].id);
|
|
|
111
110
|
await db.update(Users, {name: "Alice Smith"}, user.id);
|
|
112
111
|
```
|
|
113
112
|
|
|
113
|
+
## Why Zen?
|
|
114
|
+
|
|
115
|
+
Zen is the missing link between SQL and typed data. By writing tables with Zod schema, you get idempotent migration helpers, typed CRUD, normalized object references, and many features other database clients cannot provide.
|
|
116
|
+
|
|
117
|
+
### What Zen is not:
|
|
118
|
+
- **Zen is not a query builder** — Rather than using a fluent query builder interface (`.where().orderBy().limit()`), Zen uses explicit SQL tagged template functions instead
|
|
119
|
+
```
|
|
120
|
+
db.get(Posts)`
|
|
121
|
+
WHERE ${Posts.cols.published} = ${true}
|
|
122
|
+
ORDER BY ${Posts.cols.publishDate}
|
|
123
|
+
DESC LIMIT 20
|
|
124
|
+
```.
|
|
125
|
+
- **Zen is not an ORM** — Tables are not classes, they are Zod-powered singletons which provide schema-aware SQL-fragment helpers. These tables can be passed to CRUD helpers to validate writes, generate DDL, and normalize joined data into an object graph.
|
|
126
|
+
- **Zen is not a startup** — Zen is an open-source library, not a venture-backed SaaS. There will never be a managed “ZenDB” instance or a “Zen Studio.” The library is a thin wrapper around Zod and JavaScript SQL drivers, with a focus on runtime abstractions rather than complicated tooling.
|
|
127
|
+
|
|
128
|
+
### Safety
|
|
129
|
+
|
|
130
|
+
- **No lazy loading** — Related data comes from your JOINs
|
|
131
|
+
- **No ORM identity map** — Normalization is per-query, not session-wide
|
|
132
|
+
- **No down migrations** — Forward-only versioning (1 → 2 → 3)
|
|
133
|
+
- **No destructive helpers** — No `dropColumn()`, `dropTable()`, `renameColumn()`
|
|
134
|
+
- **No automatic migrations** — Schema changes are explicit in upgrade events
|
|
135
|
+
|
|
136
|
+
Migrations are **additive and idempotent** by design. Use `ensureColumn()`, `ensureIndex()`, `copyColumn()` for safe schema evolution. Breaking changes require multi-step migrations. Rollbacks are new forward migrations.
|
|
137
|
+
|
|
138
|
+
|
|
114
139
|
## Table Definitions
|
|
115
140
|
|
|
116
141
|
```typescript
|
|
@@ -121,7 +146,7 @@ const Users = table("users", {
|
|
|
121
146
|
id: z.string().uuid().db.primary().db.auto(),
|
|
122
147
|
email: z.string().email().db.unique(),
|
|
123
148
|
name: z.string().max(100),
|
|
124
|
-
role: z.enum(["user", "admin"]).
|
|
149
|
+
role: z.enum(["user", "admin"]).db.inserted(() => "user"),
|
|
125
150
|
createdAt: z.date().db.auto(),
|
|
126
151
|
});
|
|
127
152
|
|
|
@@ -130,10 +155,23 @@ const Posts = table("posts", {
|
|
|
130
155
|
title: z.string(),
|
|
131
156
|
content: z.string().optional(),
|
|
132
157
|
authorId: z.string().uuid().db.references(Users, "author", {onDelete: "cascade"}),
|
|
133
|
-
published: z.boolean().
|
|
158
|
+
published: z.boolean().db.inserted(() => false),
|
|
134
159
|
});
|
|
135
160
|
```
|
|
136
161
|
|
|
162
|
+
**Zod to Database Behavior:**
|
|
163
|
+
|
|
164
|
+
| Zod Method | Effect |
|
|
165
|
+
|------------|--------|
|
|
166
|
+
| `.optional()` | Column allows `NULL`; field omittable on insert |
|
|
167
|
+
| `.nullable()` | Column allows `NULL`; must explicitly pass `null` or value |
|
|
168
|
+
| `.string().max(n)` | `VARCHAR(n)` in DDL (if n ≤ 255) |
|
|
169
|
+
| `.string().uuid()` | Used by `.db.auto()` to generate UUIDs |
|
|
170
|
+
| `.number().int()` | `INTEGER` column type |
|
|
171
|
+
| `.date()` | `TIMESTAMPTZ` / `DATETIME` / `TEXT` depending on dialect |
|
|
172
|
+
| `.object()` / `.array()` | Stored as JSON, auto-encoded/decoded |
|
|
173
|
+
| `.default()` | **Throws error** — use `.db.inserted()` instead |
|
|
174
|
+
|
|
137
175
|
**The `.db` namespace:**
|
|
138
176
|
|
|
139
177
|
The `.db` property is available on all Zod types imported from `@b9g/zen`. It provides database-specific modifiers:
|
|
@@ -274,6 +312,28 @@ const Posts = table("posts", {
|
|
|
274
312
|
});
|
|
275
313
|
```
|
|
276
314
|
|
|
315
|
+
**Compound foreign keys** for composite primary keys:
|
|
316
|
+
```typescript
|
|
317
|
+
const OrderProducts = table("order_products", {
|
|
318
|
+
orderId: z.string().uuid(),
|
|
319
|
+
productId: z.string().uuid(),
|
|
320
|
+
// ... compound primary key
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
const OrderItems = table("order_items", {
|
|
324
|
+
id: z.string().uuid().db.primary(),
|
|
325
|
+
orderId: z.string().uuid(),
|
|
326
|
+
productId: z.string().uuid(),
|
|
327
|
+
quantity: z.number(),
|
|
328
|
+
}, {
|
|
329
|
+
references: [{
|
|
330
|
+
fields: ["orderId", "productId"],
|
|
331
|
+
table: OrderProducts,
|
|
332
|
+
as: "orderProduct",
|
|
333
|
+
}],
|
|
334
|
+
});
|
|
335
|
+
```
|
|
336
|
+
|
|
277
337
|
**Derived properties** for client-side transformations:
|
|
278
338
|
```typescript
|
|
279
339
|
const Posts = table("posts", {
|
|
@@ -286,27 +346,33 @@ const Posts = table("posts", {
|
|
|
286
346
|
derive: {
|
|
287
347
|
// Pure functions only (no I/O, no side effects)
|
|
288
348
|
titleUpper: (post) => post.title.toUpperCase(),
|
|
289
|
-
|
|
349
|
+
// Traverse relationships (requires JOIN in query)
|
|
350
|
+
tags: (post) => post.postTags?.map(pt => pt.tag?.name) ?? [],
|
|
290
351
|
}
|
|
291
352
|
});
|
|
292
353
|
|
|
293
|
-
|
|
354
|
+
type Post = Row<typeof Posts>;
|
|
355
|
+
// Post includes: id, title, authorId, titleUpper, tags
|
|
356
|
+
|
|
357
|
+
const posts = await db.all([Posts, Users, PostTags, Tags])`
|
|
294
358
|
JOIN "users" ON ${Users.on(Posts)}
|
|
359
|
+
LEFT JOIN "post_tags" ON ${PostTags.cols.postId} = ${Posts.cols.id}
|
|
360
|
+
LEFT JOIN "tags" ON ${Tags.on(PostTags)}
|
|
295
361
|
`;
|
|
296
362
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
post.
|
|
300
|
-
Object.keys(post); // ["id", "title", "authorId", "author"] (no
|
|
301
|
-
JSON.stringify(post); //
|
|
363
|
+
const post = posts[0];
|
|
364
|
+
post.titleUpper; // "HELLO WORLD" — typed as string
|
|
365
|
+
post.tags; // ["javascript", "typescript"] — traverses relationships
|
|
366
|
+
Object.keys(post); // ["id", "title", "authorId", "author"] (no derived props)
|
|
367
|
+
JSON.stringify(post); // Excludes derived properties (non-enumerable)
|
|
302
368
|
```
|
|
303
369
|
|
|
304
370
|
Derived properties:
|
|
305
371
|
- Are lazy getters (computed on access, not stored)
|
|
306
372
|
- Are non-enumerable (hidden from `Object.keys()` and `JSON.stringify()`)
|
|
307
373
|
- Must be pure functions (no I/O, no database queries)
|
|
308
|
-
-
|
|
309
|
-
- Are
|
|
374
|
+
- Can traverse resolved relationships from the same query
|
|
375
|
+
- Are fully typed via `Row<T>` inference
|
|
310
376
|
|
|
311
377
|
**Partial selects** with `pick()`:
|
|
312
378
|
```typescript
|
|
@@ -319,6 +385,55 @@ const posts = await db.all([Posts, UserSummary])`
|
|
|
319
385
|
|
|
320
386
|
**Table identity**: A table definition is a singleton value which is passed to database methods for validation, normalization, schema management, and convenient CRUD operations. It is not a class.
|
|
321
387
|
|
|
388
|
+
## Views
|
|
389
|
+
|
|
390
|
+
Views are read-only projections of tables with predefined WHERE clauses:
|
|
391
|
+
|
|
392
|
+
```typescript
|
|
393
|
+
import {z, table, view} from "@b9g/zen";
|
|
394
|
+
|
|
395
|
+
const Users = table("users", {
|
|
396
|
+
id: z.string().db.primary(),
|
|
397
|
+
name: z.string(),
|
|
398
|
+
role: z.enum(["user", "admin"]),
|
|
399
|
+
deletedAt: z.date().nullable().db.softDelete(),
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
// Define views with explicit names
|
|
403
|
+
const ActiveUsers = view("active_users", Users)`
|
|
404
|
+
WHERE ${Users.cols.deletedAt} IS NULL
|
|
405
|
+
`;
|
|
406
|
+
|
|
407
|
+
const AdminUsers = view("admin_users", Users)`
|
|
408
|
+
WHERE ${Users.cols.role} = ${"admin"}
|
|
409
|
+
`;
|
|
410
|
+
|
|
411
|
+
// Query from views (same API as tables)
|
|
412
|
+
const admins = await db.all(AdminUsers)``;
|
|
413
|
+
const admin = await db.get(AdminUsers, "u1");
|
|
414
|
+
|
|
415
|
+
// Views are read-only — mutations throw errors
|
|
416
|
+
await db.insert(AdminUsers, {...}); // ✗ Error
|
|
417
|
+
await db.update(AdminUsers, {...}); // ✗ Error
|
|
418
|
+
await db.delete(AdminUsers, "u1"); // ✗ Error
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
**Auto-generated `.active` view:** Tables with a `.db.softDelete()` field automatically get an `.active` view:
|
|
422
|
+
|
|
423
|
+
```typescript
|
|
424
|
+
// Equivalent to: view("users_active", Users)`WHERE deletedAt IS NULL`
|
|
425
|
+
const activeUsers = await db.all(Users.active)``;
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
**Views preserve table relationships:** Views inherit references from their base table, so JOINs work identically:
|
|
429
|
+
|
|
430
|
+
```typescript
|
|
431
|
+
const posts = await db.all([Posts, AdminUsers])`
|
|
432
|
+
JOIN "admin_users" ON ${AdminUsers.on(Posts)}
|
|
433
|
+
`;
|
|
434
|
+
posts[0].author?.role; // "admin"
|
|
435
|
+
```
|
|
436
|
+
|
|
322
437
|
## Queries
|
|
323
438
|
|
|
324
439
|
Tagged templates with automatic parameterization:
|
|
@@ -492,7 +607,7 @@ zen provides idempotent helpers that encourage safe, additive-only migrations:
|
|
|
492
607
|
const Posts = table("posts", {
|
|
493
608
|
id: z.string().db.primary(),
|
|
494
609
|
title: z.string(),
|
|
495
|
-
views: z.number().
|
|
610
|
+
views: z.number().db.inserted(() => 0), // NEW - add to schema
|
|
496
611
|
});
|
|
497
612
|
|
|
498
613
|
if (e.oldVersion < 2) {
|
|
@@ -734,6 +849,8 @@ interface Driver {
|
|
|
734
849
|
|
|
735
850
|
**Migration locking**: If the driver provides `withMigrationLock()`, migrations run atomically (PostgreSQL uses advisory locks, MySQL uses `GET_LOCK`, SQLite uses exclusive transactions).
|
|
736
851
|
|
|
852
|
+
**Connection pooling**: Handled by the underlying driver. `postgres.js` and `mysql2` pool automatically; `better-sqlite3` uses a single connection (SQLite is single-writer anyway).
|
|
853
|
+
|
|
737
854
|
## Error Handling
|
|
738
855
|
|
|
739
856
|
All errors extend `DatabaseError` with typed error codes:
|
|
@@ -783,6 +900,8 @@ await db.transaction(async (tx) => {
|
|
|
783
900
|
- `AlreadyExistsError` — Unique constraint violated (tableName, field, value)
|
|
784
901
|
- `QueryError` — SQL execution failed (sql)
|
|
785
902
|
- `MigrationError` / `MigrationLockError` — Migration failures (fromVersion, toVersion)
|
|
903
|
+
- `EnsureError` — Schema ensure operation failed (operation, table, step)
|
|
904
|
+
- `SchemaDriftError` — Existing schema doesn't match definition (table, drift)
|
|
786
905
|
- `ConnectionError` / `TransactionError` — Connection/transaction issues
|
|
787
906
|
|
|
788
907
|
## Debugging
|
|
@@ -853,9 +972,11 @@ import {
|
|
|
853
972
|
// Zod (extended with .db namespace)
|
|
854
973
|
z, // Re-exported Zod with .db already available
|
|
855
974
|
|
|
856
|
-
// Table definition
|
|
975
|
+
// Table and view definition
|
|
857
976
|
table, // Create a table definition from Zod schema
|
|
977
|
+
view, // Create a read-only view from a table
|
|
858
978
|
isTable, // Type guard for Table objects
|
|
979
|
+
isView, // Type guard for View objects
|
|
859
980
|
extendZod, // Extend a separate Zod instance (advanced)
|
|
860
981
|
|
|
861
982
|
// Database
|
|
@@ -863,13 +984,12 @@ import {
|
|
|
863
984
|
Transaction, // Transaction context (passed to transaction callbacks)
|
|
864
985
|
DatabaseUpgradeEvent, // Event object for "upgradeneeded" handler
|
|
865
986
|
|
|
866
|
-
//
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
//
|
|
871
|
-
|
|
872
|
-
getDBMeta, // Get database metadata from a Zod schema
|
|
987
|
+
// SQL builtins (for .db.inserted() / .db.updated())
|
|
988
|
+
NOW, // CURRENT_TIMESTAMP alias
|
|
989
|
+
TODAY, // CURRENT_DATE alias
|
|
990
|
+
CURRENT_TIMESTAMP, // SQL CURRENT_TIMESTAMP
|
|
991
|
+
CURRENT_DATE, // SQL CURRENT_DATE
|
|
992
|
+
CURRENT_TIME, // SQL CURRENT_TIME
|
|
873
993
|
|
|
874
994
|
// Errors
|
|
875
995
|
DatabaseError, // Base error class
|
|
@@ -912,19 +1032,15 @@ import type {
|
|
|
912
1032
|
|
|
913
1033
|
// Fragment types
|
|
914
1034
|
SetValues, // Values accepted by Table.set()
|
|
915
|
-
|
|
916
|
-
DDLFragment, // DDL fragment object
|
|
1035
|
+
SQLTemplate, // SQL template object (return type of set(), on(), etc.)
|
|
917
1036
|
SQLDialect, // "sqlite" | "postgresql" | "mysql"
|
|
918
1037
|
|
|
919
1038
|
// Driver types
|
|
920
1039
|
Driver, // Driver interface for adapters
|
|
921
1040
|
TaggedQuery, // Tagged template query function
|
|
922
1041
|
|
|
923
|
-
// Expression types
|
|
924
|
-
DBExpression, // Runtime database expression
|
|
925
|
-
|
|
926
1042
|
// Error types
|
|
927
|
-
DatabaseErrorCode,
|
|
1043
|
+
DatabaseErrorCode, // Error code string literals
|
|
928
1044
|
} from "@b9g/zen";
|
|
929
1045
|
```
|
|
930
1046
|
|
|
@@ -1040,25 +1156,3 @@ import PostgresDriver from "@b9g/zen/postgres";
|
|
|
1040
1156
|
// MySQL (mysql2)
|
|
1041
1157
|
import MySQLDriver from "@b9g/zen/mysql";
|
|
1042
1158
|
```
|
|
1043
|
-
|
|
1044
|
-
## What This Library Does Not Do
|
|
1045
|
-
|
|
1046
|
-
**Query Generation:**
|
|
1047
|
-
- **No model classes** — Tables are plain definitions, not class instances
|
|
1048
|
-
- **No hidden JOINs** — You write all SQL explicitly
|
|
1049
|
-
- **No implicit query building** — No `.where().orderBy().limit()` chains
|
|
1050
|
-
- **No lazy loading** — Related data comes from your JOINs
|
|
1051
|
-
- **No ORM identity map** — Normalization is per-query, not session-wide
|
|
1052
|
-
|
|
1053
|
-
**Migrations:**
|
|
1054
|
-
- **No down migrations** — Forward-only, monotonic versioning (1 → 2 → 3)
|
|
1055
|
-
- **No destructive helpers** — No `dropColumn()`, `dropTable()`, `renameColumn()` methods
|
|
1056
|
-
- **No automatic migrations** — DDL must be written explicitly in upgrade events
|
|
1057
|
-
- **No migration files** — Event handlers replace traditional migration folders
|
|
1058
|
-
- **No branching versions** — Linear version history only
|
|
1059
|
-
|
|
1060
|
-
**Safety Philosophy:**
|
|
1061
|
-
- Migrations are **additive and idempotent** by design
|
|
1062
|
-
- Use `ensureColumn()`, `ensureIndex()`, `copyColumn()` for safe schema changes
|
|
1063
|
-
- Breaking changes require multi-step migrations (add, migrate data, deprecate)
|
|
1064
|
-
- Version numbers never decrease — rollbacks are new forward migrations
|
|
@@ -665,6 +665,9 @@ function extendZod(zodModule) {
|
|
|
665
665
|
extendZod(z);
|
|
666
666
|
var TABLE_MARKER = Symbol.for("@b9g/zen:table");
|
|
667
667
|
var TABLE_META = Symbol.for("@b9g/zen:table-meta");
|
|
668
|
+
function isTable(value) {
|
|
669
|
+
return value !== null && typeof value === "object" && TABLE_MARKER in value && value[TABLE_MARKER] === true;
|
|
670
|
+
}
|
|
668
671
|
function getTableMeta(table2) {
|
|
669
672
|
return table2[TABLE_META];
|
|
670
673
|
}
|
|
@@ -1474,6 +1477,18 @@ function decodeData(table2, data, driver) {
|
|
|
1474
1477
|
decoded[key] = value;
|
|
1475
1478
|
}
|
|
1476
1479
|
}
|
|
1480
|
+
const derive = getTableMeta(table2).derive;
|
|
1481
|
+
if (derive) {
|
|
1482
|
+
for (const [propName, deriveFn] of Object.entries(derive)) {
|
|
1483
|
+
Object.defineProperty(decoded, propName, {
|
|
1484
|
+
get() {
|
|
1485
|
+
return deriveFn(this);
|
|
1486
|
+
},
|
|
1487
|
+
enumerable: false,
|
|
1488
|
+
configurable: true
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1477
1492
|
return decoded;
|
|
1478
1493
|
}
|
|
1479
1494
|
|
|
@@ -1508,6 +1523,7 @@ export {
|
|
|
1508
1523
|
makeTemplate,
|
|
1509
1524
|
validateWithStandardSchema,
|
|
1510
1525
|
extendZod,
|
|
1526
|
+
isTable,
|
|
1511
1527
|
getTableMeta,
|
|
1512
1528
|
isView,
|
|
1513
1529
|
getViewMeta,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b9g/zen",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "The simple database client. Define tables. Write SQL. Get objects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"database",
|
|
@@ -12,7 +12,16 @@
|
|
|
12
12
|
"postgres",
|
|
13
13
|
"mysql"
|
|
14
14
|
],
|
|
15
|
+
"author": "Brian Kim <briankimdev@gmail.com>",
|
|
15
16
|
"license": "MIT",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/bikeshaving/zen.git"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/bikeshaving/zen/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://zendb.org",
|
|
16
25
|
"dependencies": {
|
|
17
26
|
"zod": "^4.0.0"
|
|
18
27
|
},
|
package/src/bun.js
CHANGED
|
@@ -3,15 +3,15 @@ import {
|
|
|
3
3
|
placeholder,
|
|
4
4
|
quoteIdent,
|
|
5
5
|
renderDDL
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-NBXBBEMA.js";
|
|
7
7
|
import {
|
|
8
8
|
generateDDL,
|
|
9
9
|
generateViewDDL
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-ARUUB3H4.js";
|
|
11
11
|
import {
|
|
12
12
|
getTableMeta,
|
|
13
13
|
resolveSQLBuiltin
|
|
14
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-BEX6VPES.js";
|
|
15
15
|
|
|
16
16
|
// src/bun.ts
|
|
17
17
|
import { SQL } from "bun";
|
|
@@ -742,7 +742,7 @@ var BunDriver = class {
|
|
|
742
742
|
return applied;
|
|
743
743
|
}
|
|
744
744
|
async #addColumn(table, fieldName) {
|
|
745
|
-
const { generateColumnDDL } = await import("../ddl-
|
|
745
|
+
const { generateColumnDDL } = await import("../ddl-OT6HPLQY.js");
|
|
746
746
|
const zodType = table.schema.shape[fieldName];
|
|
747
747
|
const fieldMeta = table.meta.fields[fieldName] || {};
|
|
748
748
|
const colTemplate = generateColumnDDL(
|
package/src/mysql.js
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
import {
|
|
3
3
|
quoteIdent,
|
|
4
4
|
renderDDL
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-NBXBBEMA.js";
|
|
6
6
|
import {
|
|
7
7
|
generateColumnDDL,
|
|
8
8
|
generateDDL,
|
|
9
9
|
generateViewDDL
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-ARUUB3H4.js";
|
|
11
11
|
import {
|
|
12
12
|
ConstraintPreflightError,
|
|
13
13
|
EnsureError,
|
|
14
14
|
SchemaDriftError,
|
|
15
15
|
getTableMeta,
|
|
16
16
|
resolveSQLBuiltin
|
|
17
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-BEX6VPES.js";
|
|
18
18
|
|
|
19
19
|
// src/mysql.ts
|
|
20
20
|
import {
|
package/src/postgres.js
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
import {
|
|
3
3
|
quoteIdent,
|
|
4
4
|
renderDDL
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-NBXBBEMA.js";
|
|
6
6
|
import {
|
|
7
7
|
generateColumnDDL,
|
|
8
8
|
generateDDL,
|
|
9
9
|
generateViewDDL
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-ARUUB3H4.js";
|
|
11
11
|
import {
|
|
12
12
|
ConstraintPreflightError,
|
|
13
13
|
EnsureError,
|
|
14
14
|
SchemaDriftError,
|
|
15
15
|
getTableMeta,
|
|
16
16
|
resolveSQLBuiltin
|
|
17
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-BEX6VPES.js";
|
|
18
18
|
|
|
19
19
|
// src/postgres.ts
|
|
20
20
|
import {
|
package/src/sqlite.js
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
import {
|
|
3
3
|
quoteIdent,
|
|
4
4
|
renderDDL
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-NBXBBEMA.js";
|
|
6
6
|
import {
|
|
7
7
|
generateColumnDDL,
|
|
8
8
|
generateDDL,
|
|
9
9
|
generateViewDDL
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-ARUUB3H4.js";
|
|
11
11
|
import {
|
|
12
12
|
ConstraintPreflightError,
|
|
13
13
|
EnsureError,
|
|
14
14
|
SchemaDriftError,
|
|
15
15
|
getTableMeta,
|
|
16
16
|
resolveSQLBuiltin
|
|
17
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-BEX6VPES.js";
|
|
18
18
|
|
|
19
19
|
// src/sqlite.ts
|
|
20
20
|
import {
|
package/src/zen.d.ts
CHANGED
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { z as zod } from "zod";
|
|
7
7
|
export { zod as z };
|
|
8
|
-
export { table, view, type Table, type View, type Queryable, type TableOptions, type Row, type Insert, type Update, type FieldMeta, type FieldType, type Relation,
|
|
9
|
-
export { Database, Transaction, DatabaseUpgradeEvent, type Driver, } from "./impl/database.js";
|
|
10
|
-
export {
|
|
11
|
-
export { ident, isSQLIdentifier, } from "./impl/template.js";
|
|
12
|
-
export { type
|
|
13
|
-
export { type
|
|
14
|
-
export { DatabaseError, ValidationError, TableDefinitionError, MigrationError, MigrationLockError, QueryError, NotFoundError, AlreadyExistsError, ConstraintViolationError, ConnectionError, TransactionError, EnsureError, SchemaDriftError, ConstraintPreflightError, isDatabaseError, hasErrorCode, type DatabaseErrorCode, type EnsureOperation, } from "./impl/errors.js";
|
|
8
|
+
export { table, view, extendZod, isTable, isView, getViewMeta, type Table, type PartialTable, type DerivedTable, type View, type Queryable, type TableOptions, type Row, type Insert, type Update, type SetValues, type FieldMeta, type FieldType, type FieldDBMeta, type Relation, type ReferenceInfo, type CompoundReference, type ViewMeta, } from "./impl/table.js";
|
|
9
|
+
export { Database, Transaction, DatabaseUpgradeEvent, type Driver, type TaggedQuery, type EnsureResult, } from "./impl/database.js";
|
|
10
|
+
export { NOW, TODAY, CURRENT_TIMESTAMP, CURRENT_DATE, CURRENT_TIME, isSQLBuiltin, } from "./impl/database.js";
|
|
11
|
+
export { ident, isSQLIdentifier, type SQLTemplate, isSQLTemplate, } from "./impl/template.js";
|
|
12
|
+
export { type SQLDialect } from "./impl/sql.js";
|
|
13
|
+
export { DatabaseError, isDatabaseError, hasErrorCode, ValidationError, TableDefinitionError, QueryError, NotFoundError, AlreadyExistsError, ConstraintViolationError, MigrationError, MigrationLockError, EnsureError, SchemaDriftError, ConstraintPreflightError, ConnectionError, TransactionError, type DatabaseErrorCode, type EnsureOperation, } from "./impl/errors.js";
|
package/src/zen.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="./zen.d.ts" />
|
|
2
|
-
import "../chunk-
|
|
2
|
+
import "../chunk-NBXBBEMA.js";
|
|
3
3
|
import {
|
|
4
4
|
AlreadyExistsError,
|
|
5
5
|
CURRENT_DATE,
|
|
@@ -32,13 +32,14 @@ import {
|
|
|
32
32
|
isSQLBuiltin,
|
|
33
33
|
isSQLIdentifier,
|
|
34
34
|
isSQLTemplate,
|
|
35
|
+
isTable,
|
|
35
36
|
isView,
|
|
36
37
|
makeTemplate,
|
|
37
38
|
resolveSQLBuiltin,
|
|
38
39
|
table,
|
|
39
40
|
validateWithStandardSchema,
|
|
40
41
|
view
|
|
41
|
-
} from "../chunk-
|
|
42
|
+
} from "../chunk-BEX6VPES.js";
|
|
42
43
|
|
|
43
44
|
// src/zen.ts
|
|
44
45
|
import { z as zod } from "zod";
|
|
@@ -2270,6 +2271,7 @@ export {
|
|
|
2270
2271
|
Transaction,
|
|
2271
2272
|
TransactionError,
|
|
2272
2273
|
ValidationError,
|
|
2274
|
+
extendZod,
|
|
2273
2275
|
getViewMeta,
|
|
2274
2276
|
hasErrorCode,
|
|
2275
2277
|
ident,
|
|
@@ -2277,6 +2279,7 @@ export {
|
|
|
2277
2279
|
isSQLBuiltin,
|
|
2278
2280
|
isSQLIdentifier,
|
|
2279
2281
|
isSQLTemplate,
|
|
2282
|
+
isTable,
|
|
2280
2283
|
isView,
|
|
2281
2284
|
table,
|
|
2282
2285
|
view,
|