@memberjunction/sqlglot-ts 5.46.0 → 5.47.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.
|
@@ -50,7 +50,19 @@ export declare class MJPostgresTranspiler {
|
|
|
50
50
|
private readonly dialectPath;
|
|
51
51
|
private readonly extraBitColumns;
|
|
52
52
|
private readonly timeoutMs;
|
|
53
|
+
/** Lazily-written temp file holding the bit-col registry JSON. `undefined` = not yet computed, `null` = none. */
|
|
54
|
+
private bitColsFile;
|
|
53
55
|
constructor(options?: MJPostgresTranspilerOptions);
|
|
56
|
+
/**
|
|
57
|
+
* Serialize the cross-file BIT registry to a temp file and hand the dialect its
|
|
58
|
+
* PATH (via `MJ_EXTRA_BIT_COLS_FILE`), never the JSON itself. The registry grows
|
|
59
|
+
* with the schema (every baseline's BIT columns); passed inline as the
|
|
60
|
+
* `MJ_EXTRA_BIT_COLS` env var it exceeds the OS single-arg/env limit (Linux
|
|
61
|
+
* `MAX_ARG_STRLEN`, 128 KB) once baselines accumulate, and `spawn` fails with
|
|
62
|
+
* `E2BIG`. A file path is a few bytes, so there is no ceiling. Written once and
|
|
63
|
+
* reused across calls; removed on process exit.
|
|
64
|
+
*/
|
|
65
|
+
private getBitColsFile;
|
|
54
66
|
/** Transpile T-SQL to PostgreSQL. Statements the dialect can't emit land in `unhandled`. */
|
|
55
67
|
transpile(tsql: string): Promise<MJPostgresTranspileResult>;
|
|
56
68
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MJPostgresTranspiler.d.ts","sourceRoot":"","sources":["../src/MJPostgresTranspiler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MJPostgresTranspiler.d.ts","sourceRoot":"","sources":["../src/MJPostgresTranspiler.ts"],"names":[],"mappings":"AAYA,gFAAgF;AAChF,MAAM,WAAW,oBAAoB;IACnC,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,mFAAmF;AACnF,MAAM,WAAW,yBAAyB;IACxC,mDAAmD;IACnD,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,uEAAuE;IACvE,SAAS,EAAE,oBAAoB,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,2BAA2B;IAC1C;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,2EAA2E;IAC3E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAkBD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAW;IAC3C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,iHAAiH;IACjH,OAAO,CAAC,WAAW,CAA4B;gBAEnC,OAAO,CAAC,EAAE,2BAA2B;IAOjD;;;;;;;;OAQG;IACH,OAAO,CAAC,cAAc;IAmBtB,4FAA4F;IACtF,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,CAAC;IASjE;;;;OAIG;IACG,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IASvD,2FAA2F;IACrF,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC,OAAO,CAAC,UAAU;CAuEnB"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
2
|
+
import { existsSync, writeFileSync, unlinkSync } from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import { fileURLToPath } from 'node:url';
|
|
5
6
|
const __filename = fileURLToPath(import.meta.url);
|
|
6
7
|
const __dirname = path.dirname(__filename);
|
|
8
|
+
/** Process-unique sequence for temp bit-column registry files (no Date/random needed). */
|
|
9
|
+
let bitColsFileSeq = 0;
|
|
7
10
|
/**
|
|
8
11
|
* Resolve the MJ dialect script path.
|
|
9
12
|
* When running from dist/ the path is ../src/python/mj_postgres.py
|
|
@@ -44,6 +47,35 @@ export class MJPostgresTranspiler {
|
|
|
44
47
|
this.extraBitColumns = options?.extraBitColumns ?? [];
|
|
45
48
|
this.timeoutMs = options?.timeoutMs ?? 120_000;
|
|
46
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Serialize the cross-file BIT registry to a temp file and hand the dialect its
|
|
52
|
+
* PATH (via `MJ_EXTRA_BIT_COLS_FILE`), never the JSON itself. The registry grows
|
|
53
|
+
* with the schema (every baseline's BIT columns); passed inline as the
|
|
54
|
+
* `MJ_EXTRA_BIT_COLS` env var it exceeds the OS single-arg/env limit (Linux
|
|
55
|
+
* `MAX_ARG_STRLEN`, 128 KB) once baselines accumulate, and `spawn` fails with
|
|
56
|
+
* `E2BIG`. A file path is a few bytes, so there is no ceiling. Written once and
|
|
57
|
+
* reused across calls; removed on process exit.
|
|
58
|
+
*/
|
|
59
|
+
getBitColsFile() {
|
|
60
|
+
if (this.bitColsFile !== undefined)
|
|
61
|
+
return this.bitColsFile;
|
|
62
|
+
if (this.extraBitColumns.length === 0) {
|
|
63
|
+
this.bitColsFile = null;
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const file = path.join(os.tmpdir(), `mj-extra-bitcols-${process.pid}-${bitColsFileSeq++}.json`);
|
|
67
|
+
writeFileSync(file, JSON.stringify(this.extraBitColumns), 'utf8');
|
|
68
|
+
process.once('exit', () => {
|
|
69
|
+
try {
|
|
70
|
+
unlinkSync(file);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
/* best-effort cleanup */
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
this.bitColsFile = file;
|
|
77
|
+
return file;
|
|
78
|
+
}
|
|
47
79
|
/** Transpile T-SQL to PostgreSQL. Statements the dialect can't emit land in `unhandled`. */
|
|
48
80
|
async transpile(tsql) {
|
|
49
81
|
const stdout = await this.runDialect([], tsql);
|
|
@@ -72,11 +104,14 @@ export class MJPostgresTranspiler {
|
|
|
72
104
|
}
|
|
73
105
|
runDialect(args, stdin) {
|
|
74
106
|
return new Promise((resolve, reject) => {
|
|
107
|
+
const bitColsFile = this.getBitColsFile();
|
|
75
108
|
const proc = spawn(this.pythonPath, [this.dialectPath, ...args], {
|
|
76
109
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
77
110
|
env: {
|
|
78
111
|
...process.env,
|
|
79
|
-
|
|
112
|
+
// Pass the registry by file path (see getBitColsFile) — never inline, to
|
|
113
|
+
// avoid `spawn E2BIG` when the registry outgrows the OS env-size limit.
|
|
114
|
+
...(bitColsFile ? { MJ_EXTRA_BIT_COLS_FILE: bitColsFile } : {}),
|
|
80
115
|
},
|
|
81
116
|
});
|
|
82
117
|
let stdout = '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MJPostgresTranspiler.js","sourceRoot":"","sources":["../src/MJPostgresTranspiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"MJPostgresTranspiler.js","sourceRoot":"","sources":["../src/MJPostgresTranspiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,UA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F,oBAAoB,IAAI,CAAC,UAAU,+BAA+B,CACrE,CACF,CAAC;oBACF,OAAO;gBACT,CAAC;gBACD,MAAM,CACJ,IAAI,KAAK,CACP,kDAAkD,IAAI,GAAG;oBACvD,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACtD,CACF,CAAC;YACJ,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACxB,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/sqlglot-ts",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.47.0",
|
|
4
4
|
"description": "TypeScript wrapper for Python's sqlglot SQL transpiler. Manages a local Python FastAPI microservice to provide deterministic SQL dialect conversion.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -1454,7 +1454,20 @@ def mj_transpile(sql: str, *, pretty: bool = True, identify: bool = True) -> dic
|
|
|
1454
1454
|
# coerce 1/0 → TRUE/FALSE in seed INSERTs that target core tables (e.g. User.IsActive).
|
|
1455
1455
|
global _BIT_COLS
|
|
1456
1456
|
_BIT_COLS = _collect_bit_columns(sql)
|
|
1457
|
-
|
|
1457
|
+
# Registry transport: prefer a file path (MJ_EXTRA_BIT_COLS_FILE) so a large
|
|
1458
|
+
# registry never has to ride an env var (which caps at ~128 KB and fails the
|
|
1459
|
+
# spawn with E2BIG). Fall back to the inline MJ_EXTRA_BIT_COLS env for callers
|
|
1460
|
+
# (and tests) that still set it directly.
|
|
1461
|
+
extra = None
|
|
1462
|
+
extra_file = _os.environ.get("MJ_EXTRA_BIT_COLS_FILE")
|
|
1463
|
+
if extra_file:
|
|
1464
|
+
try:
|
|
1465
|
+
with open(extra_file, "r", encoding="utf-8") as _f:
|
|
1466
|
+
extra = _f.read()
|
|
1467
|
+
except Exception: # noqa: BLE001
|
|
1468
|
+
extra = None
|
|
1469
|
+
if extra is None:
|
|
1470
|
+
extra = _os.environ.get("MJ_EXTRA_BIT_COLS")
|
|
1458
1471
|
if extra:
|
|
1459
1472
|
try:
|
|
1460
1473
|
_BIT_COLS |= {(t.lower(), c.lower()) for t, c in _json.loads(extra)}
|