@aiquants/mssql 0.1.2 → 0.2.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 +81 -6
- package/dist/drizzle.d.mts +5 -0
- package/dist/drizzle.d.ts +5 -0
- package/dist/drizzle.js +1 -0
- package/dist/drizzle.mjs +1 -0
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/json-list-HgwvRzAE.d.mts +3 -0
- package/dist/json-list-HgwvRzAE.d.ts +3 -0
- package/package.json +24 -6
package/README.md
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
# @aiquants/mssql
|
|
2
2
|
|
|
3
|
-
What SQL Server refuses, and how to stay inside it. Domain-free
|
|
3
|
+
What SQL Server refuses, and how to stay inside it. Domain-free; the main entry is dependency-free.
|
|
4
4
|
|
|
5
|
-
SQL Server
|
|
5
|
+
SQL Server が**拒むもの**と、その内側に留まる方法。ドメインに縛られず、本体の入口は依存を持ちません。
|
|
6
6
|
|
|
7
7
|
| 何を答えるか | 入口 |
|
|
8
8
|
| :--- | :--- |
|
|
9
9
|
| 失敗した作業単位を、もう一度実行してよいか | `runWithTransactionRetry` / `isDeadlockVictim` / `isRolledBackByServer` |
|
|
10
|
+
| 失敗が、SQL Server のどの番号の失敗か (包み直しの奥まで) | `sqlErrorOf` (`SqlServerMessage`) |
|
|
10
11
|
| 1 文に何件まで載せられるか | `chunkByParameters` / `chunkSizeForParameters` / `chunk` |
|
|
12
|
+
| 長さの決まらない並びを、1 つのパラメータで `IN` に渡すには | `inJsonList` / `notInJsonList` (`@aiquants/mssql/drizzle`) / `jsonListText` |
|
|
11
13
|
| 返ってきた日時は、どの瞬間か | `toInstant` |
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
いずれも**ドライバが押し付けてくる事実**であり、呼び出し側のドメインには属しません。写しを各所に
|
|
14
16
|
置くと、片方だけ直る事故が起きます。
|
|
15
17
|
|
|
16
18
|
---
|
|
@@ -42,7 +44,7 @@ SQL Server のトランザクションを、失敗がデッドロックであっ
|
|
|
42
44
|
|
|
43
45
|
| 失敗 | 再実行 | 根拠 |
|
|
44
46
|
| :--- | :--- | :--- |
|
|
45
|
-
| `
|
|
47
|
+
| `sqlErrorOf(error, [1205]) !== null` (デッドロックの犠牲: 番号 `1205` と文面を持つ段) | **する** | 必ず巻き戻され、やり直せば通りうる |
|
|
46
48
|
| `code === "EABORT"` (サーバが巻き戻した) | しない | 巻き戻ったことしか示さない。原因が決定的なら永久に同じ |
|
|
47
49
|
| `ETIMEOUT` (要求の時限切れ) | しない | 文がサーバ側でまだ走っていることがある |
|
|
48
50
|
| 接続断 (`ECONNCLOSED` / `ESOCKET`) | しない | コミットの成否を持ち帰れない |
|
|
@@ -91,8 +93,11 @@ await runWithTransactionRetry(
|
|
|
91
93
|
pnpm add @aiquants/mssql
|
|
92
94
|
```
|
|
93
95
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
本体の入口 (`@aiquants/mssql`) は依存を持ちません。`mssql` / `tedious` / ORM のいずれにも `import` を持たず、
|
|
97
|
+
ドライバのエラーが一様に載せる `code`・`number`・`message` と、原因の連なり (`cause`) だけを見ます (duck typing)。
|
|
98
|
+
|
|
99
|
+
`@aiquants/mssql/drizzle` だけが drizzle-orm を `import` します。drizzle-orm は任意の peer
|
|
100
|
+
(`>=1.0.0-beta.4 <2.0.0`) なので、この入口を使う時だけ入れてください。
|
|
96
101
|
|
|
97
102
|
## Contract
|
|
98
103
|
|
|
@@ -133,6 +138,39 @@ import { isDeadlockVictim, isRolledBackByServer } from "@aiquants/mssql"
|
|
|
133
138
|
|
|
134
139
|
---
|
|
135
140
|
|
|
141
|
+
## SQL Server のエラー番号を読む
|
|
142
|
+
|
|
143
|
+
一意違反 (`2601` / `2627`) や制約違反 (`547`) を応答へ写すとき、番号は ORM やアプリの包み直しで
|
|
144
|
+
`cause` の奥へ沈みます。走査を呼び出し側で写して持たないでください。深さを変えた日に「再実行される
|
|
145
|
+
失敗」と「番号で見分ける失敗」とで届く深さが黙って食い違います。`isDeadlockVictim` と同じ走査を
|
|
146
|
+
`sqlErrorOf` がそのまま公開しています。
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import { type SqlServerMessage, sqlErrorOf } from "@aiquants/mssql"
|
|
150
|
+
|
|
151
|
+
const violation: SqlServerMessage | null = sqlErrorOf(error, [2601, 2627]) // { number, message }
|
|
152
|
+
if (violation === null) throw error
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
| 規則 | 内容 |
|
|
156
|
+
| :--- | :--- |
|
|
157
|
+
| 辿る順と深さ | 失敗そのものから `cause` を浅い順に最大 5 段。循環する `cause` もそこで止まる |
|
|
158
|
+
| 返す段 | `numbers` のいずれかを持つ**最も浅い**段。`numbers` の並びは関係しない |
|
|
159
|
+
| SQL Server の失敗と認める段 | `number` が正の整数で `message` が文字列の段だけ。`NaN`・`0`・負数・文字列の番号や、文面の無い段は一致しない |
|
|
160
|
+
| 止まる所 | オブジェクトでない値 (`null`・`undefined`・関数・文字列など) に着いたら、それを段と認めず、その先も探さない |
|
|
161
|
+
| 戻り値 | 段そのもの (ドライバの `Error`) ではなく、番号と文面だけを写した `SqlServerMessage` (`{ number, message }`)。どの段にも無ければ `null` |
|
|
162
|
+
|
|
163
|
+
`isDeadlockVictim(error)` は `sqlErrorOf(error, [1205]) !== null` そのものです。文面の無い段は、
|
|
164
|
+
`1205` を持っていてもデッドロックの犠牲とは認めません。
|
|
165
|
+
|
|
166
|
+
> [!IMPORTANT]
|
|
167
|
+
> **サーバが既に巻き戻したトランザクションの失敗には、番号が残りません。** ORM がそれを原因の無い
|
|
168
|
+
> `EABORT` へ置き換えるため (上の「ORM は原因を破壊します」)、`db.transaction(...)` の失敗へ直接当てると
|
|
169
|
+
> `null` が返ります。番号を読むなら、`capture` で包んだ `runWithTransactionRetry` が送出した失敗に当てて
|
|
170
|
+
> ください。諦めるときは `EABORT` ではなく、押さえた原本が送出されます。
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
136
174
|
## パラメータ上限
|
|
137
175
|
|
|
138
176
|
> [!CAUTION]
|
|
@@ -161,6 +199,43 @@ const size = Math.min(MAX_IN_LIST, chunkSizeForParameters(1, RESERVED_PARAMETERS
|
|
|
161
199
|
> 変わってもそこだけ追従しません。引き算は `chunkSizeForParameters` に任せ、文ごとの事情は
|
|
162
200
|
> `reservedParameters` として渡してください。
|
|
163
201
|
|
|
202
|
+
### 長さの決まらない `IN` の並び
|
|
203
|
+
|
|
204
|
+
`inArray(column, ids)` は値ごとにパラメータを 1 つ束ねます。並びの長さがデータと共に伸びる所では、
|
|
205
|
+
件数が上限を跨いだ日に**実行される前に**拒否されます。`IN` / `NOT IN` の並びは、長さを問わず JSON の
|
|
206
|
+
配列 1 つにして `OPENJSON` で読み返してください。パラメータは常に 1 つです。
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import { inJsonList, notInJsonList } from "@aiquants/mssql/drizzle"
|
|
210
|
+
|
|
211
|
+
// [documents].[id] in (select [value] from openjson(@par0))
|
|
212
|
+
const rows = await db.select().from(documents).where(inJsonList(documents.id, ids))
|
|
213
|
+
|
|
214
|
+
// [documents].[status] not in (select [value] from openjson(@par0))
|
|
215
|
+
const open = await db.select().from(documents).where(notInJsonList(documents.status, closedStatuses))
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
| 入口 | 描く SQL・返すもの | 依存 |
|
|
219
|
+
| :--- | :--- | :--- |
|
|
220
|
+
| `inJsonList(column, values)` | `<column> in (select [value] from openjson(@p))` | drizzle-orm (任意の peer) |
|
|
221
|
+
| `notInJsonList(column, values)` | `<column> not in (select [value] from openjson(@p))` | drizzle-orm (任意の peer) |
|
|
222
|
+
| `jsonListText(values)` | `@p` に束ねる JSON の配列の文字 (ORM を通さない文で使う) | なし |
|
|
223
|
+
|
|
224
|
+
- 値は字・有限の数・真偽です。null・undefined・`NaN`・`Infinity`・配列の空き・ほかの型は `TypeError` で
|
|
225
|
+
拒みます。`JSON.stringify` はこれらを黙って null に書き、`NOT IN` の並びの null はどの行も選ばなく
|
|
226
|
+
するからです。
|
|
227
|
+
- 値は渡された順のまま書き、並べ替えも重なりの除去もしません。空の並びの `IN` は、どの行も選びません。
|
|
228
|
+
- 列が null の行は、並びが空でなければ `NOT IN` でも選ばれません (`NOT IN` の三値論理)。
|
|
229
|
+
- `[value]` は既定の照合順序の `nvarchar(max)` で、比べはデータ型の優先順位に従います。数・日付・
|
|
230
|
+
`uniqueidentifier` の列では `[value]` の側が列の型に変わり、索引の seek を保ちます。
|
|
231
|
+
- 値から索引で辿れない列 (索引の無い列・`OR` で繋いだ列) では、SQL Server は外側の行ごとに配列を読み
|
|
232
|
+
直します。費用は「並びの長さ × 外側の行数」で伸びるので、長い並びでは実行計画を確かめてください。
|
|
233
|
+
|
|
234
|
+
`chunk` / `chunkByParameters` は、次の 2 つに使い続けます。
|
|
235
|
+
|
|
236
|
+
- 1 行に複数の値を束ねる `VALUES` (`insert ... values`)。
|
|
237
|
+
- 1 文で触れる行の数を抑えたい書き込み (錠の昇格を避けるため)。
|
|
238
|
+
|
|
164
239
|
---
|
|
165
240
|
|
|
166
241
|
## 日時の読み取り
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SQLWrapper, SQL } from "drizzle-orm";
|
|
2
|
+
import { J as JsonListValue } from "./json-list-HgwvRzAE.mjs";
|
|
3
|
+
declare function inJsonList(column: SQLWrapper, values: readonly JsonListValue[]): SQL;
|
|
4
|
+
declare function notInJsonList(column: SQLWrapper, values: readonly JsonListValue[]): SQL;
|
|
5
|
+
export { inJsonList, notInJsonList };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SQLWrapper, SQL } from "drizzle-orm";
|
|
2
|
+
import { J as JsonListValue } from "./json-list-HgwvRzAE.js";
|
|
3
|
+
declare function inJsonList(column: SQLWrapper, values: readonly JsonListValue[]): SQL;
|
|
4
|
+
declare function notInJsonList(column: SQLWrapper, values: readonly JsonListValue[]): SQL;
|
|
5
|
+
export { inJsonList, notInJsonList };
|
package/dist/drizzle.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var l=(n,e)=>{for(var t in e)i(n,t,{get:e[t],enumerable:!0})},L=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of a(e))!f.call(n,o)&&o!==t&&i(n,o,{get:()=>e[o],enumerable:!(r=p(e,o))||r.enumerable});return n};var y=n=>L(i({},"__esModule",{value:!0}),n);var d={};l(d,{inJsonList:()=>b,notInJsonList:()=>c});module.exports=y(d);var u=require("drizzle-orm");function s(n){for(let[e,t]of n.entries())if(!(typeof t=="string"||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t)))throw new TypeError(`[@aiquants/mssql] jsonListText: values[${e}] must be a string, a finite number or a boolean, received ${m(t)}`);return JSON.stringify(n)}function m(n){return n===null?"null":typeof n=="number"?String(n):typeof n}function b(n,e){return u.sql`${n} in (select [value] from openjson(${s(e)}))`}function c(n,e){return u.sql`${n} not in (select [value] from openjson(${s(e)}))`}0&&(module.exports={inJsonList,notInJsonList});
|
package/dist/drizzle.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{sql as r}from"drizzle-orm";function o(n){for(let[e,t]of n.entries())if(!(typeof t=="string"||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t)))throw new TypeError(`[@aiquants/mssql] jsonListText: values[${e}] must be a string, a finite number or a boolean, received ${i(t)}`);return JSON.stringify(n)}function i(n){return n===null?"null":typeof n=="number"?String(n):typeof n}function f(n,e){return r`${n} in (select [value] from openjson(${o(e)}))`}function l(n,e){return r`${n} not in (select [value] from openjson(${o(e)}))`}export{f as inJsonList,l as notInJsonList};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { J as JsonListValue, j as jsonListText } from "./json-list-HgwvRzAE.mjs";
|
|
1
2
|
declare const MAX_PARAMETERS = 2100;
|
|
2
3
|
declare const RESERVED_PARAMETERS = 100;
|
|
3
4
|
declare const MAX_IN_LIST = 500;
|
|
@@ -17,8 +18,13 @@ type TransactionRetryOptions = {
|
|
|
17
18
|
readonly delay?: (attempt: number) => Promise<void>;
|
|
18
19
|
readonly onRetry?: (info: TransactionRetryInfo) => void;
|
|
19
20
|
};
|
|
21
|
+
type SqlServerMessage = {
|
|
22
|
+
readonly number: number;
|
|
23
|
+
readonly message: string;
|
|
24
|
+
};
|
|
25
|
+
declare function sqlErrorOf(error: unknown, numbers: readonly number[]): SqlServerMessage | null;
|
|
20
26
|
declare function isDeadlockVictim(error: unknown): boolean;
|
|
21
27
|
declare function isRolledBackByServer(error: unknown): boolean;
|
|
22
28
|
declare function runWithTransactionRetry<T>(work: (capture: CaptureCause) => Promise<T>, options?: TransactionRetryOptions): Promise<T>;
|
|
23
29
|
declare function toInstant(value: string | Date): Date;
|
|
24
|
-
export { type CaptureCause, DEFAULT_TRANSACTION_ATTEMPTS, MAX_IN_LIST, MAX_PARAMETERS, RESERVED_PARAMETERS, type TransactionRetryInfo, type TransactionRetryOptions, chunk, chunkByParameters, chunkSizeForParameters, isDeadlockVictim, isRolledBackByServer, runWithTransactionRetry, toInstant };
|
|
30
|
+
export { type CaptureCause, DEFAULT_TRANSACTION_ATTEMPTS, MAX_IN_LIST, MAX_PARAMETERS, RESERVED_PARAMETERS, type SqlServerMessage, type TransactionRetryInfo, type TransactionRetryOptions, chunk, chunkByParameters, chunkSizeForParameters, isDeadlockVictim, isRolledBackByServer, runWithTransactionRetry, sqlErrorOf, toInstant };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { J as JsonListValue, j as jsonListText } from "./json-list-HgwvRzAE.js";
|
|
1
2
|
declare const MAX_PARAMETERS = 2100;
|
|
2
3
|
declare const RESERVED_PARAMETERS = 100;
|
|
3
4
|
declare const MAX_IN_LIST = 500;
|
|
@@ -17,8 +18,13 @@ type TransactionRetryOptions = {
|
|
|
17
18
|
readonly delay?: (attempt: number) => Promise<void>;
|
|
18
19
|
readonly onRetry?: (info: TransactionRetryInfo) => void;
|
|
19
20
|
};
|
|
21
|
+
type SqlServerMessage = {
|
|
22
|
+
readonly number: number;
|
|
23
|
+
readonly message: string;
|
|
24
|
+
};
|
|
25
|
+
declare function sqlErrorOf(error: unknown, numbers: readonly number[]): SqlServerMessage | null;
|
|
20
26
|
declare function isDeadlockVictim(error: unknown): boolean;
|
|
21
27
|
declare function isRolledBackByServer(error: unknown): boolean;
|
|
22
28
|
declare function runWithTransactionRetry<T>(work: (capture: CaptureCause) => Promise<T>, options?: TransactionRetryOptions): Promise<T>;
|
|
23
29
|
declare function toInstant(value: string | Date): Date;
|
|
24
|
-
export { type CaptureCause, DEFAULT_TRANSACTION_ATTEMPTS, MAX_IN_LIST, MAX_PARAMETERS, RESERVED_PARAMETERS, type TransactionRetryInfo, type TransactionRetryOptions, chunk, chunkByParameters, chunkSizeForParameters, isDeadlockVictim, isRolledBackByServer, runWithTransactionRetry, toInstant };
|
|
30
|
+
export { type CaptureCause, DEFAULT_TRANSACTION_ATTEMPTS, MAX_IN_LIST, MAX_PARAMETERS, RESERVED_PARAMETERS, type SqlServerMessage, type TransactionRetryInfo, type TransactionRetryOptions, chunk, chunkByParameters, chunkSizeForParameters, isDeadlockVictim, isRolledBackByServer, runWithTransactionRetry, sqlErrorOf, toInstant };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var c=Object.defineProperty;var
|
|
1
|
+
"use strict";var c=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var R=(e,n)=>{for(var t in n)c(e,t,{get:n[t],enumerable:!0})},w=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of b(n))!A.call(e,o)&&o!==t&&c(e,o,{get:()=>n[o],enumerable:!(r=E(n,o))||r.enumerable});return e};var S=e=>w(c({},"__esModule",{value:!0}),e);var L={};R(L,{DEFAULT_TRANSACTION_ATTEMPTS:()=>B,MAX_IN_LIST:()=>O,MAX_PARAMETERS:()=>q,RESERVED_PARAMETERS:()=>P,chunk:()=>l,chunkByParameters:()=>h,chunkSizeForParameters:()=>f,isDeadlockVictim:()=>m,isRolledBackByServer:()=>y,jsonListText:()=>g,runWithTransactionRetry:()=>D,sqlErrorOf:()=>p,toInstant:()=>C});module.exports=S(L);function g(e){for(let[n,t]of e.entries())if(!(typeof t=="string"||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t)))throw new TypeError(`[@aiquants/mssql] jsonListText: values[${n}] must be a string, a finite number or a boolean, received ${_(t)}`);return JSON.stringify(e)}function _(e){return e===null?"null":typeof e=="number"?String(e):typeof e}var q=2100,P=100,O=500;function l(e,n=500){if(!Number.isInteger(n)||n<=0)throw new TypeError(`[@aiquants/mssql] chunk size must be a positive integer, received ${String(n)}`);let t=[];for(let r=0;r<e.length;r+=n)t.push(e.slice(r,r+n));return t}function h(e,n,t=100){return l(e,f(n,t))}function f(e,n=100){if(!Number.isInteger(e)||e<=0)throw new TypeError(`[@aiquants/mssql] parametersPerItem must be a positive integer, received ${String(e)}`);if(!Number.isInteger(n)||n<0)throw new TypeError(`[@aiquants/mssql] reservedParameters must be a non-negative integer, received ${String(n)}`);let t=2100-n,r=Math.floor(t/e);if(r<1)throw new TypeError(`[@aiquants/mssql] a single item binds ${e} parameters, which exceeds the ${t} available in one statement`);return r}var B=3;var k="EABORT";function*d(e){let n=e;for(let t=0;t<5&&typeof n=="object"&&n!==null;t+=1){let r=n;yield r,n=r.cause}}function p(e,n){for(let t of d(e)){let{number:r,message:o}=t;if(typeof r=="number"&&Number.isInteger(r)&&r>0&&typeof o=="string"&&n.includes(r))return{number:r,message:o}}return null}function m(e){return p(e,[1205])!==null}function y(e){for(let n of d(e))if(n.code===k)return!0;return!1}var x=globalThis.setTimeout;function M(e){let t=50*2**(e-1)*(.75+Math.random()*.5);return new Promise(r=>x(r,Math.round(t)))}async function D(e,n){let t=n?.attempts??3,r=n?.delay??M;for(let o=1;;o+=1){let i,u=!1,T=async s=>{try{return await s()}catch(a){throw i=a,u=!0,a}};try{return await e(T)}catch(s){let a=u?i:void 0;if(o<t&&m(u?i:s)){n?.onRetry?.({attempt:o,attempts:t,error:s,cause:a}),await r(o);continue}throw u&&y(s)?i:s}}}function C(e){return e instanceof Date?e:new Date(/(?:Z|[+-]\d{2}:?\d{2})$/.test(e)?e:`${e.replace(" ","T")}Z`)}0&&(module.exports={DEFAULT_TRANSACTION_ATTEMPTS,MAX_IN_LIST,MAX_PARAMETERS,RESERVED_PARAMETERS,chunk,chunkByParameters,chunkSizeForParameters,isDeadlockVictim,isRolledBackByServer,jsonListText,runWithTransactionRetry,sqlErrorOf,toInstant});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
function R(e){for(let[n,t]of e.entries())if(!(typeof t=="string"||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t)))throw new TypeError(`[@aiquants/mssql] jsonListText: values[${n}] must be a string, a finite number or a boolean, received ${f(t)}`);return JSON.stringify(e)}function f(e){return e===null?"null":typeof e=="number"?String(e):typeof e}var S=2100,g=100,_=500;function d(e,n=500){if(!Number.isInteger(n)||n<=0)throw new TypeError(`[@aiquants/mssql] chunk size must be a positive integer, received ${String(n)}`);let t=[];for(let r=0;r<e.length;r+=n)t.push(e.slice(r,r+n));return t}function h(e,n,t=100){return d(e,p(n,t))}function p(e,n=100){if(!Number.isInteger(e)||e<=0)throw new TypeError(`[@aiquants/mssql] parametersPerItem must be a positive integer, received ${String(e)}`);if(!Number.isInteger(n)||n<0)throw new TypeError(`[@aiquants/mssql] reservedParameters must be a non-negative integer, received ${String(n)}`);let t=2100-n,r=Math.floor(t/e);if(r<1)throw new TypeError(`[@aiquants/mssql] a single item binds ${e} parameters, which exceeds the ${t} available in one statement`);return r}var x=3;var m="EABORT";function*c(e){let n=e;for(let t=0;t<5&&typeof n=="object"&&n!==null;t+=1){let r=n;yield r,n=r.cause}}function y(e,n){for(let t of c(e)){let{number:r,message:o}=t;if(typeof r=="number"&&Number.isInteger(r)&&r>0&&typeof o=="string"&&n.includes(r))return{number:r,message:o}}return null}function T(e){return y(e,[1205])!==null}function E(e){for(let n of c(e))if(n.code===m)return!0;return!1}var b=globalThis.setTimeout;function A(e){let t=50*2**(e-1)*(.75+Math.random()*.5);return new Promise(r=>b(r,Math.round(t)))}async function M(e,n){let t=n?.attempts??3,r=n?.delay??A;for(let o=1;;o+=1){let i,u=!1,l=async s=>{try{return await s()}catch(a){throw i=a,u=!0,a}};try{return await e(l)}catch(s){let a=u?i:void 0;if(o<t&&T(u?i:s)){n?.onRetry?.({attempt:o,attempts:t,error:s,cause:a}),await r(o);continue}throw u&&E(s)?i:s}}}function C(e){return e instanceof Date?e:new Date(/(?:Z|[+-]\d{2}:?\d{2})$/.test(e)?e:`${e.replace(" ","T")}Z`)}export{x as DEFAULT_TRANSACTION_ATTEMPTS,_ as MAX_IN_LIST,S as MAX_PARAMETERS,g as RESERVED_PARAMETERS,d as chunk,h as chunkByParameters,p as chunkSizeForParameters,T as isDeadlockVictim,E as isRolledBackByServer,R as jsonListText,M as runWithTransactionRetry,y as sqlErrorOf,C as toInstant};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiquants/mssql",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "What SQL Server refuses, and how to stay inside it: retry a transaction only when it was the deadlock victim (keeping the cause the ORM destroys), split statements to fit the 2100-parameter limit, and read offset-less timestamps as UTC.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "What SQL Server refuses, and how to stay inside it: retry a transaction only when it was the deadlock victim (keeping the cause the ORM destroys), read the SQL Server error number through wrapped causes, split statements to fit the 2100-parameter limit, bind an IN list of any length as one OPENJSON parameter, and read offset-less timestamps as UTC. The main entry has no dependencies; the ./drizzle entry takes drizzle-orm as an optional peer.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"import": "./dist/index.mjs",
|
|
13
13
|
"require": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./drizzle": {
|
|
16
|
+
"types": "./dist/drizzle.d.ts",
|
|
17
|
+
"import": "./dist/drizzle.mjs",
|
|
18
|
+
"require": "./dist/drizzle.js"
|
|
14
19
|
}
|
|
15
20
|
},
|
|
16
21
|
"files": [
|
|
@@ -24,6 +29,8 @@
|
|
|
24
29
|
"transaction",
|
|
25
30
|
"deadlock",
|
|
26
31
|
"retry",
|
|
32
|
+
"openjson",
|
|
33
|
+
"drizzle-orm",
|
|
27
34
|
"typescript"
|
|
28
35
|
],
|
|
29
36
|
"author": {
|
|
@@ -32,11 +39,20 @@
|
|
|
32
39
|
},
|
|
33
40
|
"license": "MIT",
|
|
34
41
|
"devDependencies": {
|
|
42
|
+
"drizzle-orm": "1.0.0-rc.4",
|
|
35
43
|
"rimraf": "^6.1.2",
|
|
36
44
|
"tsup": "^8.5.1",
|
|
37
45
|
"typescript": "^5.9.3",
|
|
38
46
|
"vitest": "^4.1.8"
|
|
39
47
|
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"drizzle-orm": ">=1.0.0-beta.4 <2.0.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"drizzle-orm": {
|
|
53
|
+
"optional": true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
40
56
|
"engines": {
|
|
41
57
|
"node": ">=18.0.0",
|
|
42
58
|
"pnpm": ">=8.0.0"
|
|
@@ -45,14 +61,16 @@
|
|
|
45
61
|
"access": "public"
|
|
46
62
|
},
|
|
47
63
|
"scripts": {
|
|
48
|
-
"build": "
|
|
64
|
+
"build": "pnpm -w run workspace:build \"$PNPM_SCRIPT_SRC_DIR\"",
|
|
65
|
+
"prebuild:self": "pnpm -w run workspace:sync \"$PNPM_SCRIPT_SRC_DIR\"",
|
|
66
|
+
"build:self": "tsup && node ../../.config/scripts/strip-dts-comments.mjs dist",
|
|
49
67
|
"build:watch": "tsup --watch",
|
|
50
68
|
"dev": "tsup --watch",
|
|
51
69
|
"typecheck": "tsc --noEmit",
|
|
52
70
|
"clean": "rimraf dist",
|
|
53
|
-
"publish:patch": "pnpm run typecheck && pnpm run --if-present test && pnpm version patch --no-git-tag-version --no-git-checks && pnpm publish --no-git-checks",
|
|
54
|
-
"publish:minor": "pnpm run typecheck && pnpm run --if-present test && pnpm version minor --no-git-tag-version --no-git-checks && pnpm publish --no-git-checks",
|
|
55
|
-
"publish:major": "pnpm run typecheck && pnpm run --if-present test && pnpm version major --no-git-tag-version --no-git-checks && pnpm publish --no-git-checks",
|
|
71
|
+
"publish:patch": "pnpm run typecheck && pnpm run --if-present test && pnpm run build && node ../../.config/scripts/check-publish-leaks.mjs && pnpm version patch --no-git-tag-version --no-git-checks && pnpm publish --no-git-checks",
|
|
72
|
+
"publish:minor": "pnpm run typecheck && pnpm run --if-present test && pnpm run build && node ../../.config/scripts/check-publish-leaks.mjs && pnpm version minor --no-git-tag-version --no-git-checks && pnpm publish --no-git-checks",
|
|
73
|
+
"publish:major": "pnpm run typecheck && pnpm run --if-present test && pnpm run build && node ../../.config/scripts/check-publish-leaks.mjs && pnpm version major --no-git-tag-version --no-git-checks && pnpm publish --no-git-checks",
|
|
56
74
|
"lint": "biome lint src/",
|
|
57
75
|
"check": "biome check src/",
|
|
58
76
|
"check:fix": "biome check --write src/",
|