metal-orm 1.0.35 → 1.0.37

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 CHANGED
@@ -51,6 +51,7 @@ Full docs live in the `docs/` folder:
51
51
  - [Multi-Dialect Support](https://github.com/celsowm/metal-orm/blob/main/docs/multi-dialect-support.md)
52
52
  - [Schema Generation (DDL)](https://github.com/celsowm/metal-orm/blob/main/docs/schema-generation.md)
53
53
  - [API Reference](https://github.com/celsowm/metal-orm/blob/main/docs/api-reference.md)
54
+ - [DB ➜ TS Type Mapping](https://github.com/celsowm/metal-orm/blob/main/docs/db-to-ts-types.md)
54
55
 
55
56
  ---
56
57
 
@@ -60,6 +61,7 @@ Full docs live in the `docs/` folder:
60
61
  ### Level 1 – Query builder & hydration
61
62
 
62
63
  - **Declarative schema definition** with `defineTable`, `col.*`, and typed relations.
64
+ - **Typed temporal columns**: `col.date()` / `col.datetime()` / `col.timestamp()` default to `string` but accept a generic when your driver returns `Date` (e.g. `col.date<Date>()`).
63
65
  - **Fluent query builder** over a real SQL AST
64
66
  (`SelectQueryBuilder`, `InsertQueryBuilder`, `UpdateQueryBuilder`, `DeleteQueryBuilder`).
65
67
  - **Advanced SQL**: CTEs, aggregates, window functions, subqueries, JSON, CASE, EXISTS.
@@ -82,6 +84,7 @@ On top of the query builder, MetalORM ships a focused runtime managed by `Orm` a
82
84
 
83
85
  - **Entities inferred from your `TableDef`s** (no separate mapping file).
84
86
  - **Lazy, batched relations**: `user.posts.load()`, `user.roles.syncByIds([...])`, etc.
87
+ - **Scoped transactions**: `session.transaction(async s => { ... })` wraps `begin/commit/rollback` on the existing executor; `Orm.transaction` remains available when you want a fresh transactional executor per call.
85
88
  - **Identity map**: the same row becomes the same entity instance within a session (see the [Identity map pattern](https://en.wikipedia.org/wiki/Identity_map_pattern)).
86
89
  - **Unit of Work (`OrmSession`)** tracking New/Dirty/Removed entities and relation changes, inspired by the classic [Unit of Work pattern](https://en.wikipedia.org/wiki/Unit_of_work).
87
90
  - **Graph persistence**: mutate a whole object graph and flush once with `session.commit()`.
package/dist/index.cjs CHANGED
@@ -7613,20 +7613,41 @@ var OrmSession = class {
7613
7613
  async flush() {
7614
7614
  await this.unitOfWork.flush();
7615
7615
  }
7616
+ async flushWithHooks() {
7617
+ for (const interceptor of this.interceptors) {
7618
+ await interceptor.beforeFlush?.(this);
7619
+ }
7620
+ await this.unitOfWork.flush();
7621
+ await this.relationChanges.process();
7622
+ await this.unitOfWork.flush();
7623
+ for (const interceptor of this.interceptors) {
7624
+ await interceptor.afterFlush?.(this);
7625
+ }
7626
+ }
7616
7627
  async commit() {
7617
7628
  await runInTransaction(this.executor, async () => {
7618
- for (const interceptor of this.interceptors) {
7619
- await interceptor.beforeFlush?.(this);
7620
- }
7621
- await this.unitOfWork.flush();
7622
- await this.relationChanges.process();
7623
- await this.unitOfWork.flush();
7624
- for (const interceptor of this.interceptors) {
7625
- await interceptor.afterFlush?.(this);
7626
- }
7629
+ await this.flushWithHooks();
7627
7630
  });
7628
7631
  await this.domainEvents.dispatch(this.unitOfWork.getTracked(), this);
7629
7632
  }
7633
+ async transaction(fn4) {
7634
+ if (!this.executor.beginTransaction) {
7635
+ const result = await fn4(this);
7636
+ await this.commit();
7637
+ return result;
7638
+ }
7639
+ await this.executor.beginTransaction();
7640
+ try {
7641
+ const result = await fn4(this);
7642
+ await this.flushWithHooks();
7643
+ await this.executor.commitTransaction?.();
7644
+ await this.domainEvents.dispatch(this.unitOfWork.getTracked(), this);
7645
+ return result;
7646
+ } catch (err) {
7647
+ await this.rollback();
7648
+ throw err;
7649
+ }
7650
+ }
7630
7651
  async rollback() {
7631
7652
  await this.executor.rollbackTransaction?.();
7632
7653
  this.unitOfWork.reset();
@@ -7781,6 +7802,7 @@ var normalizeColumnInput = (input) => {
7781
7802
  args: asOptions.args ?? asDefinition.args,
7782
7803
  notNull: asOptions.notNull ?? asDefinition.notNull,
7783
7804
  primary: asOptions.primary ?? asDefinition.primary,
7805
+ tsType: asDefinition.tsType ?? asOptions.tsType,
7784
7806
  unique: asDefinition.unique,
7785
7807
  default: asDefinition.default,
7786
7808
  autoIncrement: asDefinition.autoIncrement,