arkormx 0.2.10 → 1.0.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 CHANGED
@@ -69,6 +69,22 @@ const users = await User.query()
69
69
  .get();
70
70
  ```
71
71
 
72
+ ### Run a transaction
73
+
74
+ ```ts
75
+ await User.transaction(async () => {
76
+ await User.query().create({
77
+ name: 'Mia',
78
+ email: 'mia@example.com',
79
+ isActive: 1,
80
+ });
81
+
82
+ await User.query()
83
+ .where({ email: 'john@example.com' })
84
+ .updateFrom({ isActive: 1 });
85
+ });
86
+ ```
87
+
72
88
  ## Next steps
73
89
 
74
90
  - [Setup](https://arkormx.toneflix.net/guide/setup)
@@ -76,4 +92,5 @@ const users = await User.query()
76
92
  - [Typing](https://arkormx.dev/guide/typing)
77
93
  - [Models](https://arkormx.dev/guide/models)
78
94
  - [Query Builder](https://arkormx.dev/guide/query-builder)
95
+ - [Transactions](https://arkormx.dev/guide/transactions)
79
96
  - [Relationships](https://arkormx.dev/guide/relationships)
package/dist/cli.mjs CHANGED
@@ -6,6 +6,7 @@ import { str } from "@h3ravel/support";
6
6
  import path, { dirname as dirname$1, extname as extname$1, join as join$1, relative } from "path";
7
7
  import { copyFileSync, existsSync as existsSync$1, mkdirSync as mkdirSync$1, readFileSync as readFileSync$1, readdirSync as readdirSync$1, rmSync as rmSync$1, writeFileSync as writeFileSync$1 } from "fs";
8
8
  import { fileURLToPath, pathToFileURL } from "url";
9
+ import { AsyncLocalStorage } from "async_hooks";
9
10
  import { createRequire } from "module";
10
11
  import { Logger } from "@h3ravel/shared";
11
12
  import { Command, Kernel } from "@h3ravel/musket";
@@ -13,17 +14,43 @@ import { createHash } from "node:crypto";
13
14
  import { pathToFileURL as pathToFileURL$1 } from "node:url";
14
15
 
15
16
  //#region src/Exceptions/ArkormException.ts
16
- /**
17
- * The ArkormException class is a custom error type for handling
18
- * exceptions specific to the Arkormˣ.
19
- *
20
- * @author Legacy (3m1n3nc3)
21
- * @since 0.1.0
22
- */
23
17
  var ArkormException = class extends Error {
24
- constructor(message) {
25
- super(message);
18
+ code;
19
+ operation;
20
+ model;
21
+ delegate;
22
+ relation;
23
+ scope;
24
+ meta;
25
+ constructor(message, context = {}) {
26
+ super(message, context.cause === void 0 ? void 0 : { cause: context.cause });
26
27
  this.name = "ArkormException";
28
+ this.code = context.code;
29
+ this.operation = context.operation;
30
+ this.model = context.model;
31
+ this.delegate = context.delegate;
32
+ this.relation = context.relation;
33
+ this.scope = context.scope;
34
+ this.meta = context.meta;
35
+ }
36
+ getContext() {
37
+ return {
38
+ code: this.code,
39
+ operation: this.operation,
40
+ model: this.model,
41
+ delegate: this.delegate,
42
+ relation: this.relation,
43
+ scope: this.scope,
44
+ meta: this.meta,
45
+ cause: this.cause
46
+ };
47
+ }
48
+ toJSON() {
49
+ return {
50
+ name: this.name,
51
+ message: this.message,
52
+ ...this.getContext()
53
+ };
27
54
  }
28
55
  };
29
56
 
@@ -1135,6 +1162,8 @@ let runtimeConfigLoaded = false;
1135
1162
  let runtimeConfigLoadingPromise;
1136
1163
  let runtimeClientResolver;
1137
1164
  let runtimePaginationURLDriverFactory;
1165
+ let runtimePaginationCurrentPageResolver;
1166
+ const transactionClientStorage = new AsyncLocalStorage();
1138
1167
  const mergePathConfig = (paths) => {
1139
1168
  const defaults = baseConfig.paths ?? {};
1140
1169
  const current = userConfig.paths ?? {};
@@ -1175,6 +1204,7 @@ const configureArkormRuntime = (prisma, options = {}) => {
1175
1204
  Object.assign(userConfig, { ...nextConfig });
1176
1205
  runtimeClientResolver = prisma;
1177
1206
  runtimePaginationURLDriverFactory = nextConfig.pagination?.urlDriver;
1207
+ runtimePaginationCurrentPageResolver = nextConfig.pagination?.resolveCurrentPage;
1178
1208
  };
1179
1209
  /**
1180
1210
  * Resolve and apply the ArkORM configuration from an imported module.