supalite 0.7.6 → 0.8.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/CHANGELOG.md +8 -0
- package/README.ko.md +6 -5
- package/README.md +6 -5
- package/SPEC.md +3 -2
- package/dist/postgres-client.js +18 -1
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.8.0] - 2026-01-19
|
|
4
|
+
|
|
5
|
+
### ✨ Added
|
|
6
|
+
- `bigintTransform: 'number-or-string'` 옵션을 추가했습니다. 안전 범위는 `Number`, 그 외는 문자열을 반환합니다.
|
|
7
|
+
|
|
8
|
+
### 🔧 Changed
|
|
9
|
+
- `bigintTransform` 기본값을 `'number-or-string'`으로 변경했습니다. (Supabase 기본값과의 호환을 높이기 위함)
|
|
10
|
+
|
|
3
11
|
## [0.7.2] - 2026-01-17
|
|
4
12
|
|
|
5
13
|
### ✨ Added
|
package/README.ko.md
CHANGED
|
@@ -204,7 +204,7 @@ const client = new SupaLitePG<Database>({
|
|
|
204
204
|
database: 'testdb',
|
|
205
205
|
port: 5432,
|
|
206
206
|
ssl: false,
|
|
207
|
-
// bigintTransform: 'string', //
|
|
207
|
+
// bigintTransform: 'number-or-string', // 안전 범위는 Number, 그 외는 문자열 (기본값: 'number-or-string')
|
|
208
208
|
// verbose: true // 상세 로그 출력
|
|
209
209
|
});
|
|
210
210
|
|
|
@@ -299,7 +299,7 @@ const client = new SupaLitePG<Database>({
|
|
|
299
299
|
database: 'testdb',
|
|
300
300
|
port: 5432,
|
|
301
301
|
ssl: false,
|
|
302
|
-
// bigintTransform: 'string', //
|
|
302
|
+
// bigintTransform: 'number-or-string', // 안전 범위는 Number, 그 외는 문자열 (기본값: 'number-or-string')
|
|
303
303
|
// verbose: true // 상세 로그 출력
|
|
304
304
|
});
|
|
305
305
|
```
|
|
@@ -1083,14 +1083,15 @@ DB_SSL=true
|
|
|
1083
1083
|
- `ssl?: boolean`: SSL 연결 사용 여부 (기본값: `false`, 환경 변수: `DB_SSL`).
|
|
1084
1084
|
- `schema?: string`: 기본 스키마 (기본값: `'public'`).
|
|
1085
1085
|
- `verbose?: boolean`: 상세 로그 출력 여부 (기본값: `false`, 환경 변수: `SUPALITE_VERBOSE`).
|
|
1086
|
-
- `bigintTransform?: 'bigint' | 'string' | 'number'`:
|
|
1086
|
+
- `bigintTransform?: 'bigint' | 'string' | 'number' | 'number-or-string'`:
|
|
1087
1087
|
- 데이터베이스의 `BIGINT` 타입을 어떻게 변환할지 지정합니다.
|
|
1088
|
-
- `'bigint'
|
|
1088
|
+
- `'bigint'`: JavaScript의 네이티브 `BigInt` 객체로 변환합니다. 이 라이브러리의 `Json` 타입은 `bigint`를 포함할 수 있도록 정의되어 있으나, 표준 `JSON.stringify()` 함수는 `BigInt`를 직접 처리하지 못하므로 `TypeError`가 발생할 수 있습니다. `BigInt` 값을 JSON으로 직렬화하려면 사용자 정의 replacer 함수를 사용하거나 사전에 문자열 등으로 변환해야 합니다. JSON/JSONB 입력에서는 `BigInt`를 문자열로 직렬화합니다.
|
|
1089
1089
|
- `'string'`: 문자열로 변환합니다. JSON 직렬화에 안전하며, `BigInt`의 전체 정밀도를 유지합니다.
|
|
1090
1090
|
- `'number'`: JavaScript의 `Number` 타입으로 변환합니다. 값이 `Number.MAX_SAFE_INTEGER` (또는 `Number.MIN_SAFE_INTEGER`)를 초과하면 정밀도 손실이 발생할 수 있습니다. 이 경우 `verbose: true` 설정 시 경고 로그가 출력됩니다. JSON 직렬화에는 안전합니다.
|
|
1091
|
+
- `'number-or-string'` (기본값): 안전 정수 범위면 `Number`로, 범위를 벗어나면 문자열로 반환해 정밀도를 보존합니다.
|
|
1091
1092
|
|
|
1092
1093
|
### Json 타입과 BigInt
|
|
1093
|
-
라이브러리의 내부 `Json` 타입 정의는 `bigint`를 포함하여 TypeScript 코드 내에서 `BigInt` 값을 명시적으로 다룰 수 있도록 합니다. JSON/JSONB 컬럼에 INSERT/UPDATE 할 때는 배열/객체를 stringify하며, 이 과정에서 `BigInt` 값은 문자열로 변환되어 직렬화됩니다. 숫자 JSON이 필요하면 `BigInt`를 `Number`로 변환해 전달하세요(정밀도 주의). 표준 `JSON.stringify()`는 여전히 `BigInt`를 직접 처리하지 못하므로, 사용자 코드에서 직접 직렬화할 때는 replacer가 필요합니다. `bigintTransform` 옵션을 `'string'` 또는 `'number'`로 설정하면 데이터베이스 조회 시점부터 JSON 직렬화에 안전한 형태로 `BIGINT` 값을 받을 수 있습니다.
|
|
1094
|
+
라이브러리의 내부 `Json` 타입 정의는 `bigint`를 포함하여 TypeScript 코드 내에서 `BigInt` 값을 명시적으로 다룰 수 있도록 합니다. JSON/JSONB 컬럼에 INSERT/UPDATE 할 때는 배열/객체를 stringify하며, 이 과정에서 `BigInt` 값은 문자열로 변환되어 직렬화됩니다. 숫자 JSON이 필요하면 `BigInt`를 `Number`로 변환해 전달하세요(정밀도 주의). 표준 `JSON.stringify()`는 여전히 `BigInt`를 직접 처리하지 못하므로, 사용자 코드에서 직접 직렬화할 때는 replacer가 필요합니다. `bigintTransform` 옵션을 `'string'`, `'number'`, 또는 `'number-or-string'`로 설정하면 데이터베이스 조회 시점부터 JSON 직렬화에 안전한 형태로 `BIGINT` 값을 받을 수 있습니다.
|
|
1094
1095
|
|
|
1095
1096
|
## 응답 형식
|
|
1096
1097
|
|
package/README.md
CHANGED
|
@@ -205,7 +205,7 @@ const client = new SupaLitePG<Database>({
|
|
|
205
205
|
database: 'testdb',
|
|
206
206
|
port: 5432,
|
|
207
207
|
ssl: false,
|
|
208
|
-
// bigintTransform: 'string', //
|
|
208
|
+
// bigintTransform: 'number-or-string', // numbers when safe, strings otherwise (default: 'number-or-string')
|
|
209
209
|
// verbose: true // verbose logging
|
|
210
210
|
});
|
|
211
211
|
|
|
@@ -299,7 +299,7 @@ const client = new SupaLitePG<Database>({
|
|
|
299
299
|
database: 'testdb',
|
|
300
300
|
port: 5432,
|
|
301
301
|
ssl: false,
|
|
302
|
-
// bigintTransform: 'string',
|
|
302
|
+
// bigintTransform: 'number-or-string', // default: 'number-or-string'
|
|
303
303
|
// verbose: true
|
|
304
304
|
});
|
|
305
305
|
```
|
|
@@ -1079,13 +1079,14 @@ DB_SSL=true
|
|
|
1079
1079
|
- `ssl?: boolean`: SSL (default: `false`, env: `DB_SSL`)
|
|
1080
1080
|
- `schema?: string`: default schema (default: `public`)
|
|
1081
1081
|
- `verbose?: boolean`: verbose logging (default: `false`, env: `SUPALITE_VERBOSE`)
|
|
1082
|
-
- `bigintTransform?: 'bigint' | 'string' | 'number'`:
|
|
1083
|
-
- `'bigint'
|
|
1082
|
+
- `bigintTransform?: 'bigint' | 'string' | 'number' | 'number-or-string'`:
|
|
1083
|
+
- `'bigint'`: uses native `BigInt`
|
|
1084
1084
|
- `'string'`: returns string values (safe for JSON)
|
|
1085
1085
|
- `'number'`: returns `Number` (may lose precision, warns if unsafe)
|
|
1086
|
+
- `'number-or-string'` (default): returns `Number` when safe; otherwise keeps the string to preserve precision
|
|
1086
1087
|
|
|
1087
1088
|
### Json type and BigInt
|
|
1088
|
-
The internal `Json` type includes `bigint` to allow explicit BigInt usage in TypeScript. When inserting or updating JSON/JSONB columns, SupaLite stringifies arrays/objects and converts any BigInt values to strings to avoid `JSON.stringify()` errors. If you need numeric JSON values, convert BigInt to `Number` yourself (mind precision). Standard `JSON.stringify()` still cannot handle native `BigInt` in userland; use a custom replacer if you serialize objects yourself.
|
|
1089
|
+
The internal `Json` type includes `bigint` to allow explicit BigInt usage in TypeScript. When inserting or updating JSON/JSONB columns, SupaLite stringifies arrays/objects and converts any BigInt values to strings to avoid `JSON.stringify()` errors. If you need numeric JSON values, convert BigInt to `Number` yourself (mind precision). Standard `JSON.stringify()` still cannot handle native `BigInt` in userland; use a custom replacer if you serialize objects yourself. For JSON-safe query results without precision loss, use `bigintTransform: 'number-or-string'` so only safe values become numbers.
|
|
1089
1090
|
|
|
1090
1091
|
## Response format
|
|
1091
1092
|
|
package/SPEC.md
CHANGED
|
@@ -15,7 +15,7 @@ SupaLite is a lightweight TypeScript PostgreSQL client that mirrors a subset of
|
|
|
15
15
|
- Accepts either `connectionString` or discrete connection params.
|
|
16
16
|
- Optional `pool` lets callers inject an existing `pg` Pool (SupaLite does not create or close the pool).
|
|
17
17
|
- Env vars supported: `DB_CONNECTION`, `DB_USER`, `DB_HOST`, `DB_NAME`, `DB_PASS`, `DB_PORT`, `DB_SSL`.
|
|
18
|
-
- `bigintTransform`: `'bigint' | 'string' | 'number'` controls how BIGINT values are parsed.
|
|
18
|
+
- `bigintTransform`: `'bigint' | 'string' | 'number' | 'number-or-string'` controls how BIGINT values are parsed.
|
|
19
19
|
- `verbose`: logs SQL, values, and warnings for risky bigint-to-number conversions.
|
|
20
20
|
|
|
21
21
|
### 2.2 QueryBuilder
|
|
@@ -121,10 +121,11 @@ Notes:
|
|
|
121
121
|
- Arrays and plain objects are `JSON.stringify`'d, with BigInt values converted to strings.
|
|
122
122
|
- Dates and primitives are passed through.
|
|
123
123
|
- Native arrays (e.g. `text[]`) are passed through as JavaScript arrays.
|
|
124
|
-
- BIGINT parsing:
|
|
124
|
+
- BIGINT parsing (default: 'number-or-string'):
|
|
125
125
|
- `'bigint'`: `BigInt` values.
|
|
126
126
|
- `'string'`: string values.
|
|
127
127
|
- `'number'`: `Number` with precision warning if unsafe.
|
|
128
|
+
- `'number-or-string'`: `Number` when safe, otherwise string to preserve precision.
|
|
128
129
|
|
|
129
130
|
## 6. Transactions
|
|
130
131
|
- `begin`, `commit`, `rollback`, and `transaction` are implemented on `SupaLitePG`.
|
package/dist/postgres-client.js
CHANGED
|
@@ -8,6 +8,8 @@ const errors_1 = require("./errors");
|
|
|
8
8
|
const dotenv_1 = require("dotenv");
|
|
9
9
|
// .env 파일 로드
|
|
10
10
|
(0, dotenv_1.config)();
|
|
11
|
+
const MAX_SAFE_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
|
|
12
|
+
const MIN_SAFE_BIGINT = BigInt(Number.MIN_SAFE_INTEGER);
|
|
11
13
|
class RpcBuilder {
|
|
12
14
|
constructor(pool, schema, procedureName, params = {}) {
|
|
13
15
|
this.pool = pool;
|
|
@@ -174,7 +176,7 @@ class SupaLitePG {
|
|
|
174
176
|
this.verbose = false;
|
|
175
177
|
this.ownsPool = true;
|
|
176
178
|
this.verbose = config?.verbose || process.env.SUPALITE_VERBOSE === 'true' || false;
|
|
177
|
-
this.bigintTransform = config?.bigintTransform || '
|
|
179
|
+
this.bigintTransform = config?.bigintTransform || 'number-or-string'; // 기본값 'number-or-string'
|
|
178
180
|
if (this.verbose) {
|
|
179
181
|
console.log(`[SupaLite VERBOSE] BIGINT transform mode set to: '${this.bigintTransform}'`);
|
|
180
182
|
}
|
|
@@ -195,6 +197,21 @@ class SupaLitePG {
|
|
|
195
197
|
return num;
|
|
196
198
|
});
|
|
197
199
|
break;
|
|
200
|
+
case 'number-or-string':
|
|
201
|
+
pg_1.types.setTypeParser(20, (val) => {
|
|
202
|
+
if (val === null)
|
|
203
|
+
return null;
|
|
204
|
+
const bigValue = BigInt(val);
|
|
205
|
+
if (bigValue > MAX_SAFE_BIGINT || bigValue < MIN_SAFE_BIGINT) {
|
|
206
|
+
if (this.verbose) {
|
|
207
|
+
console.warn(`[SupaLite VERBOSE WARNING] BIGINT value ${val} exceeds safe integer range; ` +
|
|
208
|
+
'returning string to preserve precision.');
|
|
209
|
+
}
|
|
210
|
+
return val;
|
|
211
|
+
}
|
|
212
|
+
return Number(val);
|
|
213
|
+
});
|
|
214
|
+
break;
|
|
198
215
|
case 'bigint':
|
|
199
216
|
default: // 기본값 및 'bigint' 명시 시
|
|
200
217
|
pg_1.types.setTypeParser(20, (val) => val === null ? null : BigInt(val));
|
package/dist/types.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export type UpdateRow<T extends DatabaseSchema, S extends SchemaName<T>, K exten
|
|
|
45
45
|
updated_at?: string | null;
|
|
46
46
|
} : never;
|
|
47
47
|
export type EnumType<T extends DatabaseSchema, S extends SchemaName<T>, E extends keyof NonNullable<T[S]['Enums']>> = NonNullable<T[S]['Enums']>[E];
|
|
48
|
-
export type BigintTransformType = 'bigint' | 'string' | 'number';
|
|
48
|
+
export type BigintTransformType = 'bigint' | 'string' | 'number' | 'number-or-string';
|
|
49
49
|
export interface SupaliteConfig {
|
|
50
50
|
pool?: Pool;
|
|
51
51
|
connectionString?: string;
|