@aurios/mizzle 1.1.2 → 1.1.4

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.
Files changed (116) hide show
  1. package/.turbo/turbo-build.log +37 -0
  2. package/LICENSE +21 -0
  3. package/README.md +166 -57
  4. package/dist/chunk-AQVECMXP.js +1 -0
  5. package/dist/chunk-DU7UPWBW.js +1 -0
  6. package/dist/chunk-GPYZK4WY.js +1 -0
  7. package/dist/chunk-NPPZW6VT.js +1 -0
  8. package/dist/chunk-TOYV2M4M.js +1 -0
  9. package/dist/chunk-UM3YF5EC.js +1 -0
  10. package/dist/columns.d.ts +1 -0
  11. package/dist/columns.js +1 -0
  12. package/dist/db-zHIHBm1E.d.ts +815 -0
  13. package/dist/db.d.ts +3 -0
  14. package/dist/db.js +1 -0
  15. package/dist/diff.d.ts +18 -0
  16. package/dist/diff.js +1 -0
  17. package/dist/index.d.ts +42 -0
  18. package/dist/index.js +1 -0
  19. package/dist/introspection.d.ts +7 -0
  20. package/dist/introspection.js +1 -0
  21. package/dist/operators-BVreW0ky.d.ts +719 -0
  22. package/dist/snapshot.d.ts +24 -0
  23. package/dist/snapshot.js +1 -0
  24. package/dist/table.d.ts +1 -0
  25. package/dist/table.js +1 -0
  26. package/dist/transaction-RE7LXTGV.js +1 -0
  27. package/package.json +82 -66
  28. package/src/builders/base.ts +53 -56
  29. package/src/builders/batch-get.ts +63 -58
  30. package/src/builders/batch-write.ts +81 -78
  31. package/src/builders/delete.ts +46 -53
  32. package/src/builders/insert.ts +158 -150
  33. package/src/builders/query-promise.ts +26 -35
  34. package/src/builders/relational-builder.ts +214 -191
  35. package/src/builders/select.ts +250 -237
  36. package/src/builders/transaction.ts +170 -152
  37. package/src/builders/update.ts +197 -192
  38. package/src/columns/binary-set.ts +29 -38
  39. package/src/columns/binary.ts +25 -35
  40. package/src/columns/boolean.ts +25 -30
  41. package/src/columns/date.ts +57 -64
  42. package/src/columns/index.ts +15 -15
  43. package/src/columns/json.ts +39 -48
  44. package/src/columns/list.ts +26 -36
  45. package/src/columns/map.ts +26 -34
  46. package/src/columns/number-set.ts +29 -38
  47. package/src/columns/number.ts +33 -40
  48. package/src/columns/string-set.ts +38 -47
  49. package/src/columns/string.ts +37 -49
  50. package/src/columns/uuid.ts +26 -33
  51. package/src/core/client.ts +9 -9
  52. package/src/core/column-builder.ts +194 -220
  53. package/src/core/column.ts +127 -135
  54. package/src/core/diff.ts +40 -34
  55. package/src/core/errors.ts +20 -17
  56. package/src/core/introspection.ts +62 -58
  57. package/src/core/operations.ts +17 -23
  58. package/src/core/parser.ts +82 -89
  59. package/src/core/relations.ts +164 -154
  60. package/src/core/retry.ts +52 -52
  61. package/src/core/snapshot.ts +131 -130
  62. package/src/core/strategies.ts +222 -218
  63. package/src/core/table.ts +189 -202
  64. package/src/core/validation.ts +52 -52
  65. package/src/db.ts +211 -209
  66. package/src/expressions/actions.ts +26 -26
  67. package/src/expressions/builder.ts +62 -54
  68. package/src/expressions/operators.ts +48 -48
  69. package/src/expressions/update-builder.ts +78 -76
  70. package/src/index.ts +1 -1
  71. package/src/indexes.ts +8 -8
  72. package/test/batch-resilience.test.ts +138 -0
  73. package/test/builders/delete.test.ts +100 -0
  74. package/test/builders/insert.test.ts +216 -0
  75. package/test/builders/relational-types.test.ts +55 -0
  76. package/test/builders/relational.integration.test.ts +291 -0
  77. package/test/builders/relational.test.ts +66 -0
  78. package/test/builders/select.test.ts +411 -0
  79. package/test/builders/transaction-errors.test.ts +46 -0
  80. package/test/builders/transaction-execution.test.ts +99 -0
  81. package/test/builders/transaction-proxy.test.ts +41 -0
  82. package/test/builders/update-expression.test.ts +106 -0
  83. package/test/builders/update.test.ts +179 -0
  84. package/test/core/diff.test.ts +152 -0
  85. package/test/core/expressions.test.ts +64 -0
  86. package/test/core/introspection.test.ts +47 -0
  87. package/test/core/parser.test.ts +69 -0
  88. package/test/core/snapshot-gen.test.ts +155 -0
  89. package/test/core/snapshot.test.ts +52 -0
  90. package/test/date-column.test.ts +159 -0
  91. package/test/fluent-writes.integration.test.ts +148 -0
  92. package/test/integration-retry.test.ts +77 -0
  93. package/test/integration.test.ts +105 -0
  94. package/test/item-size-error.test.ts +16 -0
  95. package/test/item-size-validation.test.ts +82 -0
  96. package/test/item-size.test.ts +47 -0
  97. package/test/iterator-pagination.integration.test.ts +132 -0
  98. package/test/jsdoc-builders.test.ts +55 -0
  99. package/test/jsdoc-schema.test.ts +107 -0
  100. package/test/json-column.test.ts +51 -0
  101. package/test/metadata.test.ts +54 -0
  102. package/test/mizzle-package.test.ts +20 -0
  103. package/test/relational-centralized.test.ts +83 -0
  104. package/test/relational-definition.test.ts +75 -0
  105. package/test/relational-init.test.ts +30 -0
  106. package/test/relational-proxy.test.ts +52 -0
  107. package/test/relations.test.ts +45 -0
  108. package/test/resilience-config.test.ts +34 -0
  109. package/test/retry-handler.test.ts +63 -0
  110. package/test/transaction.integration.test.ts +153 -0
  111. package/test/unified-select.integration.test.ts +153 -0
  112. package/test/unified-update.integration.test.ts +139 -0
  113. package/test/update.integration.test.ts +132 -0
  114. package/tsconfig.json +12 -8
  115. package/tsup.config.ts +11 -11
  116. package/vitest.config.ts +8 -0
@@ -1,71 +1,64 @@
1
1
  import { DeleteCommand } from "@aws-sdk/lib-dynamodb";
2
- import { ENTITY_SYMBOLS } from "@mizzle/shared";
2
+ import { ENTITY_SYMBOLS } from "@repo/shared";
3
3
  import { Entity, type InferSelectModel } from "../core/table";
4
4
  import { BaseBuilder } from "./base";
5
5
  import { type IMizzleClient } from "../core/client";
6
6
  import { type Expression } from "../expressions/operators";
7
7
 
8
8
  export class DeleteBuilder<
9
- TEntity extends Entity,
10
- TResult = InferSelectModel<TEntity>,
9
+ TEntity extends Entity,
10
+ TResult = InferSelectModel<TEntity>,
11
11
  > extends BaseBuilder<TEntity, TResult> {
12
- static readonly [ENTITY_SYMBOLS.ENTITY_KIND]: string = "DeleteBuilder";
12
+ static readonly [ENTITY_SYMBOLS.ENTITY_KIND]: string = "DeleteBuilder";
13
13
 
14
- private _returnValues?: "NONE" | "ALL_OLD";
15
- private _keys: Record<string, unknown>;
14
+ private _returnValues?: "NONE" | "ALL_OLD";
15
+ private _keys: Record<string, unknown>;
16
16
 
17
- constructor(
18
- entity: TEntity,
19
- client: IMizzleClient,
20
- keys: Record<string, unknown>,
21
- ) {
22
- super(entity, client);
23
- this._keys = keys;
24
- }
17
+ constructor(entity: TEntity, client: IMizzleClient, keys: Record<string, unknown>) {
18
+ super(entity, client);
19
+ this._keys = keys;
20
+ }
25
21
 
26
- /**
27
- * Instructs Mizzle to return the deleted item after execution.
28
- *
29
- * @returns The current builder instance.
30
- */
31
- returning(): this {
32
- this._returnValues = "ALL_OLD";
33
- return this;
34
- }
22
+ /**
23
+ * Instructs Mizzle to return the deleted item after execution.
24
+ *
25
+ * @returns The current builder instance.
26
+ */
27
+ returning(): this {
28
+ this._returnValues = "ALL_OLD";
29
+ return this;
30
+ }
35
31
 
36
- /** @internal */
37
- get keys() {
38
- return this._keys;
39
- }
32
+ /** @internal */
33
+ get keys() {
34
+ return this._keys;
35
+ }
40
36
 
41
- /** @internal */
42
- public override resolveKeys(
43
- whereClause?: Expression,
44
- providedValues?: Record<string, unknown>,
45
- ) {
46
- return super.resolveKeys(whereClause, providedValues);
47
- }
37
+ /** @internal */
38
+ public override resolveKeys(whereClause?: Expression, providedValues?: Record<string, unknown>) {
39
+ return super.resolveKeys(whereClause, providedValues);
40
+ }
48
41
 
49
- /** @internal */
50
- public override createExpressionContext(prefix = "") {
51
- return super.createExpressionContext(prefix);
52
- }
42
+ /** @internal */
43
+ public override createExpressionContext(prefix = "") {
44
+ return super.createExpressionContext(prefix);
45
+ }
53
46
 
54
- /**
55
- * Executes the delete operation.
56
- *
57
- * @returns A promise that resolves to the deleted item if `.returning()` was called, otherwise undefined.
58
- */
59
- public override async execute(): Promise<TResult> {
60
- const resolution = this.resolveKeys(undefined, this._keys);
47
+ /**
48
+ * Executes the delete operation.
49
+ *
50
+ * @returns A promise that resolves to the deleted item if `.returning()` was called, otherwise undefined.
51
+ */
52
+ public override async execute(): Promise<TResult> {
53
+ const resolution = this.resolveKeys(undefined, this._keys);
61
54
 
62
- const command = new DeleteCommand({
63
- TableName: this.tableName,
64
- Key: resolution.keys,
65
- ReturnValues: this._returnValues,
66
- });
55
+ const command = new DeleteCommand({
56
+ TableName: this.tableName,
57
+ Key: resolution.keys,
58
+ ReturnValues: this._returnValues,
59
+ });
67
60
 
68
- const response = await this.client.send(command) as any;
69
- return response.Attributes as TResult;
70
- }
61
+ const response = (await this.client.send(command)) as any;
62
+ return response.Attributes as TResult;
63
+ }
71
64
  }
@@ -1,5 +1,5 @@
1
1
  import { PutCommand } from "@aws-sdk/lib-dynamodb";
2
- import { ENTITY_SYMBOLS, TABLE_SYMBOLS } from "@mizzle/shared";
2
+ import { ENTITY_SYMBOLS, TABLE_SYMBOLS } from "@repo/shared";
3
3
  import { Entity, type InferInsertModel } from "../core/table";
4
4
  import { BaseBuilder } from "./base";
5
5
  import { Column } from "../core/column";
@@ -9,176 +9,184 @@ import { calculateItemSize } from "../core/validation";
9
9
  import { ItemSizeExceededError } from "../core/errors";
10
10
 
11
11
  export class InsertBuilder<TEntity extends Entity> {
12
- static readonly [ENTITY_SYMBOLS.ENTITY_KIND]: string = "InsertBuilder";
13
-
14
- constructor(
15
- private entity: TEntity,
16
- private client: IMizzleClient,
17
- ) { }
18
-
19
- /**
20
- * Sets the values to be inserted into the database.
21
- *
22
- * @example
23
- * ```ts
24
- * await db.insert(users).values({ id: "1", name: "Alice" }).execute();
25
- * ```
26
- *
27
- * @param values The object containing the attributes to insert.
28
- * @returns An InsertBase instance for further chaining.
29
- */
30
- values(values: InferInsertModel<TEntity>): InsertBase<TEntity> {
31
- return new InsertBase(this.entity, this.client, values);
32
- }
12
+ static readonly [ENTITY_SYMBOLS.ENTITY_KIND]: string = "InsertBuilder";
13
+
14
+ constructor(
15
+ private entity: TEntity,
16
+ private client: IMizzleClient,
17
+ ) {}
18
+
19
+ /**
20
+ * Sets the values to be inserted into the database.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * await db.insert(users).values({ id: "1", name: "Alice" }).execute();
25
+ * ```
26
+ *
27
+ * @param values The object containing the attributes to insert.
28
+ * @returns An InsertBase instance for further chaining.
29
+ */
30
+ values(values: InferInsertModel<TEntity>): InsertBase<TEntity> {
31
+ return new InsertBase(this.entity, this.client, values);
32
+ }
33
33
  }
34
34
 
35
35
  interface MinimalPhysicalTable {
36
- [TABLE_SYMBOLS.INDEXES]?: Record<string, { config: { pk: string; sk?: string } }>;
36
+ [TABLE_SYMBOLS.INDEXES]?: Record<string, { config: { pk: string; sk?: string } }>;
37
37
  }
38
38
 
39
- export class InsertBase<
40
- TEntity extends Entity,
41
- TResult = undefined,
42
- > extends BaseBuilder<TEntity, TResult> {
43
- static readonly [ENTITY_SYMBOLS.ENTITY_KIND]: string = "InsertBase";
44
-
45
- private shouldReturnValues = false;
46
-
47
- constructor(
48
- entity: TEntity,
49
- client: IMizzleClient,
50
- private valuesData: InferInsertModel<TEntity>,
51
- ) {
52
- super(entity, client);
39
+ export class InsertBase<TEntity extends Entity, TResult = undefined> extends BaseBuilder<
40
+ TEntity,
41
+ TResult
42
+ > {
43
+ static readonly [ENTITY_SYMBOLS.ENTITY_KIND]: string = "InsertBase";
44
+
45
+ private shouldReturnValues = false;
46
+
47
+ constructor(
48
+ entity: TEntity,
49
+ client: IMizzleClient,
50
+ private valuesData: InferInsertModel<TEntity>,
51
+ ) {
52
+ super(entity, client);
53
+ }
54
+
55
+ /** @internal */
56
+ get values() {
57
+ return this.valuesData;
58
+ }
59
+
60
+ /**
61
+ * Instructs Mizzle to return the inserted item after execution.
62
+ *
63
+ * @returns The current builder instance with an updated result type.
64
+ */
65
+ returning(): InsertBase<TEntity, InferInsertModel<TEntity>> {
66
+ this.shouldReturnValues = true;
67
+ return this as unknown as InsertBase<TEntity, InferInsertModel<TEntity>>;
68
+ }
69
+
70
+ /** @internal */
71
+ buildItem(): Record<string, unknown> {
72
+ const itemToSave = this.processValues(this.valuesData);
73
+ const resolution = this.resolveKeys(undefined, itemToSave);
74
+
75
+ const finalItem: Record<string, unknown> = { ...itemToSave, ...resolution.keys };
76
+
77
+ // Also resolve GSI keys if they are defined in strategies but not in resolution.keys
78
+ const strategies = this.entity[ENTITY_SYMBOLS.ENTITY_STRATEGY] as unknown as Record<
79
+ string,
80
+ { pk: KeyStrategy; sk?: KeyStrategy }
81
+ >;
82
+ const physicalTable = this.entity[
83
+ ENTITY_SYMBOLS.PHYSICAL_TABLE
84
+ ] as unknown as MinimalPhysicalTable;
85
+ const indexes = physicalTable?.[TABLE_SYMBOLS.INDEXES] || {};
86
+
87
+ for (const [indexName, strategy] of Object.entries(strategies)) {
88
+ if (indexName === "pk" || indexName === "sk") continue;
89
+
90
+ const indexBuilder = indexes[indexName];
91
+ if (indexBuilder) {
92
+ if (strategy.pk && indexBuilder.config.pk) {
93
+ const pkValue = this.resolveStrategyValue(strategy.pk, itemToSave);
94
+ if (pkValue) finalItem[indexBuilder.config.pk] = pkValue;
95
+ }
96
+ if (strategy.sk && indexBuilder.config.sk) {
97
+ const skValue = this.resolveStrategyValue(strategy.sk, itemToSave);
98
+ if (skValue) finalItem[indexBuilder.config.sk] = skValue;
99
+ }
100
+ }
53
101
  }
54
102
 
55
- /** @internal */
56
- get values() {
57
- return this.valuesData;
103
+ return finalItem;
104
+ }
105
+
106
+ /**
107
+ * Executes the insert operation.
108
+ *
109
+ * @returns A promise that resolves to the inserted item if `.returning()` was called, otherwise undefined.
110
+ * @throws {ItemSizeExceededError} if the item exceeds 400KB.
111
+ */
112
+ override async execute(): Promise<TResult> {
113
+ const finalItem = this.buildItem();
114
+
115
+ // Size validation
116
+ const size = calculateItemSize(finalItem);
117
+ if (size > 400 * 1024) {
118
+ throw new ItemSizeExceededError(
119
+ `Item size of ${Math.round(size / 1024)}KB exceeds the 400KB limit.`,
120
+ );
58
121
  }
59
122
 
60
- /**
61
- * Instructs Mizzle to return the inserted item after execution.
62
- *
63
- * @returns The current builder instance with an updated result type.
64
- */
65
- returning(): InsertBase<TEntity, InferInsertModel<TEntity>> {
66
- this.shouldReturnValues = true;
67
- return this as unknown as InsertBase<TEntity, InferInsertModel<TEntity>>;
68
- }
123
+ const command = new PutCommand({
124
+ TableName: this.tableName,
125
+ Item: finalItem,
126
+ });
69
127
 
70
- /** @internal */
71
- buildItem(): Record<string, unknown> {
72
- const itemToSave = this.processValues(this.valuesData);
73
- const resolution = this.resolveKeys(undefined, itemToSave);
74
-
75
- const finalItem: Record<string, unknown> = { ...itemToSave, ...resolution.keys };
76
-
77
- // Also resolve GSI keys if they are defined in strategies but not in resolution.keys
78
- const strategies = this.entity[ENTITY_SYMBOLS.ENTITY_STRATEGY] as unknown as Record<string, { pk: KeyStrategy, sk?: KeyStrategy }>;
79
- const physicalTable = this.entity[ENTITY_SYMBOLS.PHYSICAL_TABLE] as unknown as MinimalPhysicalTable;
80
- const indexes = physicalTable?.[TABLE_SYMBOLS.INDEXES] || {};
81
-
82
- for (const [indexName, strategy] of Object.entries(strategies)) {
83
- if (indexName === "pk" || indexName === "sk") continue;
84
-
85
- const indexBuilder = indexes[indexName];
86
- if (indexBuilder) {
87
- if (strategy.pk && indexBuilder.config.pk) {
88
- const pkValue = this.resolveStrategyValue(strategy.pk, itemToSave);
89
- if (pkValue) finalItem[indexBuilder.config.pk] = pkValue;
90
- }
91
- if (strategy.sk && indexBuilder.config.sk) {
92
- const skValue = this.resolveStrategyValue(strategy.sk, itemToSave);
93
- if (skValue) finalItem[indexBuilder.config.sk] = skValue;
94
- }
95
- }
96
- }
128
+ await this.client.send(command);
129
+ if (this.shouldReturnValues) return finalItem as unknown as TResult;
97
130
 
98
- return finalItem;
131
+ return undefined as unknown as TResult;
132
+ }
133
+
134
+ private resolveStrategyValue(
135
+ strategy: KeyStrategy,
136
+ availableValues: Record<string, unknown>,
137
+ ): string | undefined {
138
+ if (strategy.type === "static") {
139
+ return strategy.segments[0] as string;
99
140
  }
100
141
 
101
- /**
102
- * Executes the insert operation.
103
- *
104
- * @returns A promise that resolves to the inserted item if `.returning()` was called, otherwise undefined.
105
- * @throws {ItemSizeExceededError} if the item exceeds 400KB.
106
- */
107
- override async execute(): Promise<TResult> {
108
- const finalItem = this.buildItem();
109
-
110
- // Size validation
111
- const size = calculateItemSize(finalItem);
112
- if (size > 400 * 1024) {
113
- throw new ItemSizeExceededError(`Item size of ${Math.round(size / 1024)}KB exceeds the 400KB limit.`);
114
- }
142
+ const resolvedParts: string[] = [];
115
143
 
116
- const command = new PutCommand({
117
- TableName: this.tableName,
118
- Item: finalItem,
119
- });
144
+ for (const segment of strategy.segments) {
145
+ if (typeof segment === "string") {
146
+ resolvedParts.push(segment);
147
+ } else {
148
+ const val = availableValues[segment.name];
149
+ if (val === undefined || val === null) return undefined;
150
+ resolvedParts.push(String(val));
151
+ }
152
+ }
120
153
 
121
- await this.client.send(command);
122
- if (this.shouldReturnValues) return finalItem as unknown as TResult;
154
+ if (strategy.type === "prefix") return resolvedParts.join("");
155
+ if (strategy.type === "composite") return resolvedParts.join(strategy.separator || "#");
156
+ return undefined;
157
+ }
123
158
 
124
- return undefined as unknown as TResult;
125
- }
159
+ private processValues(values: InferInsertModel<TEntity>): Record<string, unknown> {
160
+ const item: Record<string, unknown> = { ...(values as Record<string, unknown>) };
161
+ const columns = this.entity[ENTITY_SYMBOLS.COLUMNS] as Record<string, Column>;
126
162
 
127
- private resolveStrategyValue(strategy: KeyStrategy, availableValues: Record<string, unknown>): string | undefined {
128
- if (strategy.type === "static") {
129
- return strategy.segments[0] as string;
130
- }
163
+ for (const key in columns) {
164
+ const col = columns[key];
165
+ if (!col) continue;
131
166
 
132
- const resolvedParts: string[] = [];
167
+ const value = item[key];
133
168
 
134
- for (const segment of strategy.segments) {
135
- if (typeof segment === "string") {
136
- resolvedParts.push(segment);
137
- } else {
138
- const val = availableValues[segment.name];
139
- if (val === undefined || val === null) return undefined;
140
- resolvedParts.push(String(val));
141
- }
142
- }
169
+ if (value === undefined) {
170
+ if (col.default !== undefined) item[key] = col.default;
171
+ else if (col.defaultFn) item[key] = col.defaultFn();
172
+ }
143
173
 
144
- if (strategy.type === "prefix") return resolvedParts.join("");
145
- if (strategy.type === "composite") return resolvedParts.join(strategy.separator || "#");
146
- return undefined;
147
- }
174
+ const finalValue = item[key];
148
175
 
149
- private processValues(
150
- values: InferInsertModel<TEntity>,
151
- ): Record<string, unknown> {
152
- const item: Record<string, unknown> = { ...(values as Record<string, unknown>) };
153
- const columns = this.entity[ENTITY_SYMBOLS.COLUMNS] as Record<string, Column>;
154
-
155
- for (const key in columns) {
156
- const col = columns[key];
157
- if (!col) continue;
158
-
159
- const value = item[key];
160
-
161
- if (value === undefined) {
162
- if (col.default !== undefined) item[key] = col.default;
163
- else if (col.defaultFn) item[key] = col.defaultFn();
164
- }
165
-
166
- const finalValue = item[key];
167
-
168
- // Check if column has mapToDynamoValue method (it's on the Column class)
169
- if (col instanceof Column) {
170
- item[key] = col.mapToDynamoValue(finalValue);
171
- }
172
-
173
- if (["SS", "NS", "BS"].includes(col.columnType)) {
174
- if (Array.isArray(finalValue)) {
175
- const setVal = new Set(finalValue);
176
- item[key] = setVal;
177
- if (setVal.size === 0) delete item[key];
178
- }
179
- }
180
- }
176
+ // Check if column has mapToDynamoValue method (it's on the Column class)
177
+ if (col instanceof Column) {
178
+ item[key] = col.mapToDynamoValue(finalValue);
179
+ }
181
180
 
182
- return item;
181
+ if (["SS", "NS", "BS"].includes(col.columnType)) {
182
+ if (Array.isArray(finalValue)) {
183
+ const setVal = new Set(finalValue);
184
+ item[key] = setVal;
185
+ if (setVal.size === 0) delete item[key];
186
+ }
187
+ }
183
188
  }
189
+
190
+ return item;
191
+ }
184
192
  }
@@ -1,41 +1,32 @@
1
1
  export abstract class QueryPromise<T> implements Promise<T> {
2
- [Symbol.toStringTag] = "QueryPromise";
2
+ [Symbol.toStringTag] = "QueryPromise";
3
3
 
4
- catch<TResult = never>(
5
- onrejected?:
6
- | ((reason: unknown) => TResult | PromiseLike<TResult>)
7
- | null
8
- | undefined,
9
- ): Promise<T | TResult> {
10
- return this.then(undefined, onrejected);
11
- }
4
+ catch<TResult = never>(
5
+ onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null | undefined,
6
+ ): Promise<T | TResult> {
7
+ return this.then(undefined, onrejected);
8
+ }
12
9
 
13
- finally(onfinally?: (() => void) | null | undefined): Promise<T> {
14
- return this.then(
15
- (value) => {
16
- onfinally?.();
17
- return value;
18
- },
19
- (reason) => {
20
- onfinally?.();
21
- throw reason;
22
- },
23
- );
24
- }
10
+ finally(onfinally?: (() => void) | null | undefined): Promise<T> {
11
+ return this.then(
12
+ (value) => {
13
+ onfinally?.();
14
+ return value;
15
+ },
16
+ (reason) => {
17
+ onfinally?.();
18
+ throw reason;
19
+ },
20
+ );
21
+ }
25
22
 
26
- // oxlint-disable
27
- then<TResult1 = T, TResult2 = never>(
28
- onfulfilled?:
29
- | ((value: T) => TResult1 | PromiseLike<TResult1>)
30
- | null
31
- | undefined,
32
- onrejected?:
33
- | ((reason: unknown) => TResult2 | PromiseLike<TResult2>)
34
- | null
35
- | undefined,
36
- ): Promise<TResult1 | TResult2> {
37
- return this.execute().then(onfulfilled, onrejected);
38
- }
23
+ // oxlint-disable
24
+ then<TResult1 = T, TResult2 = never>(
25
+ onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined,
26
+ onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined,
27
+ ): Promise<TResult1 | TResult2> {
28
+ return this.execute().then(onfulfilled, onrejected);
29
+ }
39
30
 
40
- abstract execute(): Promise<T>;
31
+ abstract execute(): Promise<T>;
41
32
  }