@travetto/model-sql 7.0.0-rc.1 → 7.0.0-rc.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-sql",
3
- "version": "7.0.0-rc.1",
3
+ "version": "7.0.0-rc.2",
4
4
  "description": "SQL backing for the travetto model module, with real-time modeling support for SQL schemas.",
5
5
  "keywords": [
6
6
  "sql",
@@ -27,14 +27,14 @@
27
27
  "directory": "module/model-sql"
28
28
  },
29
29
  "dependencies": {
30
- "@travetto/cli": "^7.0.0-rc.1",
31
- "@travetto/config": "^7.0.0-rc.1",
32
- "@travetto/context": "^7.0.0-rc.1",
33
- "@travetto/model": "^7.0.0-rc.1",
34
- "@travetto/model-query": "^7.0.0-rc.1"
30
+ "@travetto/cli": "^7.0.0-rc.2",
31
+ "@travetto/config": "^7.0.0-rc.2",
32
+ "@travetto/context": "^7.0.0-rc.2",
33
+ "@travetto/model": "^7.0.0-rc.2",
34
+ "@travetto/model-query": "^7.0.0-rc.2"
35
35
  },
36
36
  "peerDependencies": {
37
- "@travetto/test": "^7.0.0-rc.1"
37
+ "@travetto/test": "^7.0.0-rc.2"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "@travetto/test": {
@@ -71,23 +71,23 @@ export abstract class Connection<C = unknown> {
71
71
  /**
72
72
  * Run operation with active connection
73
73
  * @param context
74
- * @param op
74
+ * @param operation
75
75
  * @param args
76
76
  */
77
- async runWithActive<R>(op: () => Promise<R>): Promise<R> {
77
+ async runWithActive<R>(operation: () => Promise<R>): Promise<R> {
78
78
  if (this.active) {
79
- return op();
79
+ return operation();
80
80
  }
81
81
 
82
82
  return this.context.run(async () => {
83
- let conn;
83
+ let connection;
84
84
  try {
85
- conn = await this.acquire();
86
- this.#active.set(conn);
87
- return await op();
85
+ connection = await this.acquire();
86
+ this.#active.set(connection);
87
+ return await operation();
88
88
  } finally {
89
- if (conn) {
90
- this.release(conn);
89
+ if (connection) {
90
+ this.release(connection);
91
91
  }
92
92
  }
93
93
  });
@@ -96,19 +96,19 @@ export abstract class Connection<C = unknown> {
96
96
  /**
97
97
  * Iterate with active connection
98
98
  * @param context
99
- * @param op
99
+ * @param operation
100
100
  * @param args
101
101
  */
102
- async * iterateWithActive<R>(op: () => AsyncIterable<R>): AsyncIterable<R> {
102
+ async * iterateWithActive<R>(operation: () => AsyncIterable<R>): AsyncIterable<R> {
103
103
  if (this.active) {
104
- yield* op();
104
+ yield* operation();
105
105
  }
106
106
 
107
107
  const self = castTo<Connection>(this);
108
108
  yield* this.context.iterate(async function* () {
109
109
  try {
110
110
  self.#active.set(await self.acquire());
111
- yield* op();
111
+ yield* operation();
112
112
  } finally {
113
113
  if (self.active) {
114
114
  self.release(self.active);
@@ -120,26 +120,26 @@ export abstract class Connection<C = unknown> {
120
120
  /**
121
121
  * Run a function within a valid sql transaction. Relies on @travetto/context.
122
122
  */
123
- async runWithTransaction<R>(mode: TransactionType, op: () => Promise<R>): Promise<R> {
123
+ async runWithTransaction<R>(mode: TransactionType, operation: () => Promise<R>): Promise<R> {
124
124
  if (this.activeTx) {
125
125
  if (mode === 'isolated' || mode === 'force') {
126
126
  const txId = mode === 'isolated' ? `tx${Util.uuid()}` : undefined;
127
127
  try {
128
128
  await this.startTx(this.active!, txId);
129
- const res = await op();
129
+ const result = await operation();
130
130
  await this.commitTx(this.active!, txId);
131
- return res;
132
- } catch (err) {
131
+ return result;
132
+ } catch (error) {
133
133
  try { await this.rollbackTx(this.active!, txId); } catch { }
134
- throw err;
134
+ throw error;
135
135
  }
136
136
  } else {
137
- return await op();
137
+ return await operation();
138
138
  }
139
139
  } else {
140
140
  return this.runWithActive(() => {
141
141
  this.#activeTx.set(true);
142
- return this.runWithTransaction('force', op);
142
+ return this.runWithTransaction('force', operation);
143
143
  });
144
144
  }
145
145
  }
@@ -147,42 +147,42 @@ export abstract class Connection<C = unknown> {
147
147
  /**
148
148
  * Start a transaction
149
149
  */
150
- async startTx(conn: C, transactionId?: string): Promise<void> {
150
+ async startTx(connection: C, transactionId?: string): Promise<void> {
151
151
  if (transactionId) {
152
152
  if (this.nestedTransactions) {
153
- await this.execute(conn, this.transactionDialect.beginNested, [transactionId]);
153
+ await this.execute(connection, this.transactionDialect.beginNested, [transactionId]);
154
154
  }
155
155
  } else {
156
156
  if (this.isolatedTransactions) {
157
- await this.execute(conn, this.transactionDialect.isolate);
157
+ await this.execute(connection, this.transactionDialect.isolate);
158
158
  }
159
- await this.execute(conn, this.transactionDialect.begin);
159
+ await this.execute(connection, this.transactionDialect.begin);
160
160
  }
161
161
  }
162
162
 
163
163
  /**
164
164
  * Commit active transaction
165
165
  */
166
- async commitTx(conn: C, transactionId?: string): Promise<void> {
166
+ async commitTx(connection: C, transactionId?: string): Promise<void> {
167
167
  if (transactionId) {
168
168
  if (this.nestedTransactions) {
169
- await this.execute(conn, this.transactionDialect.commitNested, [transactionId]);
169
+ await this.execute(connection, this.transactionDialect.commitNested, [transactionId]);
170
170
  }
171
171
  } else {
172
- await this.execute(conn, this.transactionDialect.commit);
172
+ await this.execute(connection, this.transactionDialect.commit);
173
173
  }
174
174
  }
175
175
 
176
176
  /**
177
177
  * Rollback active transaction
178
178
  */
179
- async rollbackTx(conn: C, transactionId?: string): Promise<void> {
179
+ async rollbackTx(connection: C, transactionId?: string): Promise<void> {
180
180
  if (transactionId) {
181
181
  if (this.isolatedTransactions) {
182
- await this.execute(conn, this.transactionDialect.rollbackNested, [transactionId]);
182
+ await this.execute(connection, this.transactionDialect.rollbackNested, [transactionId]);
183
183
  }
184
184
  } else {
185
- await this.execute(conn, this.transactionDialect.rollback);
185
+ await this.execute(connection, this.transactionDialect.rollback);
186
186
  }
187
187
  }
188
188
  }
@@ -1,11 +1,11 @@
1
- import { AsyncItrMethodDescriptor, AsyncMethodDescriptor } from '@travetto/runtime';
1
+ import { AsyncIterableMethodDescriptor, AsyncMethodDescriptor } from '@travetto/runtime';
2
2
  import { Connection, TransactionType } from './base.ts';
3
3
 
4
4
  /**
5
5
  * Indicating something is aware of connections
6
6
  */
7
7
  export interface ConnectionAware<C = unknown> {
8
- conn: Connection<C>;
8
+ connection: Connection<C>;
9
9
  }
10
10
 
11
11
  /**
@@ -13,12 +13,12 @@ export interface ConnectionAware<C = unknown> {
13
13
  * @kind decorator
14
14
  */
15
15
  export function Connected() {
16
- return function <T extends { conn?: Connection }>(
17
- target: T, prop: string | symbol, desc: AsyncMethodDescriptor<T>
16
+ return function <T extends { connection?: Connection }>(
17
+ target: T, property: string, descriptor: AsyncMethodDescriptor<T>
18
18
  ): void {
19
- const og = desc.value!;
20
- desc.value = function (...args: unknown[]): ReturnType<typeof og> {
21
- return this.conn!.runWithActive(() => og.call(this, ...args));
19
+ const handle = descriptor.value!;
20
+ descriptor.value = function (...args: unknown[]): ReturnType<typeof handle> {
21
+ return this.connection!.runWithActive(() => handle.call(this, ...args));
22
22
  };
23
23
  };
24
24
  }
@@ -28,12 +28,12 @@ export function Connected() {
28
28
  * @kind decorator
29
29
  */
30
30
  export function ConnectedIterator() {
31
- return function <T extends { conn?: Connection }>(
32
- target: T, prop: string | symbol, desc: AsyncItrMethodDescriptor<T>
31
+ return function <T extends { connection?: Connection }>(
32
+ target: T, property: string, descriptor: AsyncIterableMethodDescriptor<T>
33
33
  ): void {
34
- const og = desc.value!;
35
- desc.value = async function* (...args: unknown[]): ReturnType<typeof og> {
36
- yield* this.conn!.iterateWithActive(() => og.call(this, ...args));
34
+ const handle = descriptor.value!;
35
+ descriptor.value = async function* (...args: unknown[]): ReturnType<typeof handle> {
36
+ yield* this.connection!.iterateWithActive(() => handle.call(this, ...args));
37
37
  };
38
38
  };
39
39
  }
@@ -43,12 +43,12 @@ export function ConnectedIterator() {
43
43
  * @kind decorator
44
44
  */
45
45
  export function Transactional(mode: TransactionType = 'required') {
46
- return function <T extends { conn?: Connection }>(
47
- target: unknown, prop: string | symbol, desc: AsyncMethodDescriptor<T>
46
+ return function <T extends { connection?: Connection }>(
47
+ target: unknown, property: string, descriptor: AsyncMethodDescriptor<T>
48
48
  ): void {
49
- const og = desc.value!;
50
- desc.value = function (...args: unknown[]): ReturnType<typeof og> {
51
- return this.conn!.runWithTransaction(mode, () => og.call(this, ...args));
49
+ const handle = descriptor.value!;
50
+ descriptor.value = function (...args: unknown[]): ReturnType<typeof handle> {
51
+ return this.connection!.runWithTransaction(mode, () => handle.call(this, ...args));
52
52
  };
53
53
  };
54
54
  }