drizzle-sybase 4.0.0 → 5.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.
Files changed (88) hide show
  1. package/README.md +264 -7
  2. package/THIRD_PARTY_NOTICES.md +25 -0
  3. package/dist/bulk.d.ts +164 -0
  4. package/dist/bulk.d.ts.map +1 -0
  5. package/dist/bulk.js +1135 -0
  6. package/dist/bulk.js.map +1 -0
  7. package/dist/checks.d.ts +15 -0
  8. package/dist/checks.d.ts.map +1 -0
  9. package/dist/checks.js +19 -0
  10. package/dist/checks.js.map +1 -0
  11. package/dist/codecs.d.ts +1 -1
  12. package/dist/codecs.d.ts.map +1 -1
  13. package/dist/codecs.js +10 -2
  14. package/dist/codecs.js.map +1 -1
  15. package/dist/columns/index.d.ts +9 -1
  16. package/dist/columns/index.d.ts.map +1 -1
  17. package/dist/columns/index.js +5 -5
  18. package/dist/columns/index.js.map +1 -1
  19. package/dist/connection.d.ts +75 -12
  20. package/dist/connection.d.ts.map +1 -1
  21. package/dist/connection.js +216 -43
  22. package/dist/connection.js.map +1 -1
  23. package/dist/db.d.ts +51 -26
  24. package/dist/db.d.ts.map +1 -1
  25. package/dist/db.js +56 -2
  26. package/dist/db.js.map +1 -1
  27. package/dist/dialect.d.ts +4 -2
  28. package/dist/dialect.d.ts.map +1 -1
  29. package/dist/dialect.js +41 -15
  30. package/dist/dialect.js.map +1 -1
  31. package/dist/errors.d.ts +82 -1
  32. package/dist/errors.d.ts.map +1 -1
  33. package/dist/errors.js +90 -4
  34. package/dist/errors.js.map +1 -1
  35. package/dist/index.d.ts +5 -3
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +1 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist/introspect/codegen.d.ts.map +1 -1
  40. package/dist/introspect/codegen.js +22 -12
  41. package/dist/introspect/codegen.js.map +1 -1
  42. package/dist/introspect/fetch.d.ts.map +1 -1
  43. package/dist/introspect/fetch.js +24 -8
  44. package/dist/introspect/fetch.js.map +1 -1
  45. package/dist/introspect/types.d.ts +5 -0
  46. package/dist/introspect/types.d.ts.map +1 -1
  47. package/dist/native/index.d.ts +97 -9
  48. package/dist/native/index.d.ts.map +1 -1
  49. package/dist/native/index.js +17 -0
  50. package/dist/native/index.js.map +1 -1
  51. package/dist/native/sybase_native.darwin-arm64.node +0 -0
  52. package/dist/native/sybase_native.darwin-x64.node +0 -0
  53. package/dist/native/sybase_native.linux-arm64.node +0 -0
  54. package/dist/native/sybase_native.linux-x64.node +0 -0
  55. package/dist/native/sybase_native.win32-x64.node +0 -0
  56. package/dist/pool.d.ts +24 -2
  57. package/dist/pool.d.ts.map +1 -1
  58. package/dist/pool.js +117 -37
  59. package/dist/pool.js.map +1 -1
  60. package/dist/query-builders/insert.d.ts.map +1 -1
  61. package/dist/query-builders/insert.js +5 -0
  62. package/dist/query-builders/insert.js.map +1 -1
  63. package/dist/query-builders/select.d.ts +5 -0
  64. package/dist/query-builders/select.d.ts.map +1 -1
  65. package/dist/query-builders/select.js +16 -0
  66. package/dist/query-builders/select.js.map +1 -1
  67. package/dist/result.d.ts +20 -7
  68. package/dist/result.d.ts.map +1 -1
  69. package/dist/result.js +35 -17
  70. package/dist/result.js.map +1 -1
  71. package/dist/session.d.ts +25 -2
  72. package/dist/session.d.ts.map +1 -1
  73. package/dist/session.js +134 -11
  74. package/dist/session.js.map +1 -1
  75. package/dist/table.d.ts.map +1 -1
  76. package/dist/table.js +5 -2
  77. package/dist/table.js.map +1 -1
  78. package/licenses/FreeTDS-COPYING_LIB.txt +481 -0
  79. package/package.json +8 -4
  80. package/patches/freetds-1.5.17-sybase-bulk.patch +592 -0
  81. package/scripts/build-native.ts +34 -0
  82. package/scripts/build-win.ps1 +49 -8
  83. package/scripts/build.sh +101 -30
  84. package/scripts/smoke-native.ts +67 -0
  85. package/scripts/smoke-package.sh +79 -0
  86. package/scripts/verify-published.ts +29 -5
  87. package/src/native/binding.c +3325 -322
  88. package/vendor/freetds-1.5.17.tar.gz +0 -0
@@ -32,31 +32,68 @@ Write-Host "Root dir: $RootDir"
32
32
  # Step 1: Download and compile FreeTDS
33
33
  # ---------------------------------------------------------------------------
34
34
 
35
+ # SHA-256 of each FreeTDS release tarball (as in scripts/build.sh).
36
+ $FreeTdsSha256 = @{ "1.5.17" = "8d154ce458d1825a8625b0ef1c3288afecfc32b3a09015a5ece4fbdf8aafd144" }[$FreeTdsVersion]
37
+ if (-not $FreeTdsSha256) { throw "No known SHA-256 for FreeTDS $FreeTdsVersion: add it to scripts/build-win.ps1" }
38
+
39
+ # The same patches scripts/build.sh and the release workflow apply. They need
40
+ # GNU patch (it comes with Git for Windows: Git\usr\bin).
41
+ $Patches = @(Get-ChildItem -Path (Join-Path $RootDir "patches") -Filter "freetds-$FreeTdsVersion-*.patch" | Sort-Object Name)
42
+
43
+ # How FreeTDS is configured: used for the build and, with what else it depends
44
+ # on, for its identity — a build made from anything else is rebuilt.
45
+ $CmakeArgs = @(
46
+ "-G", "Visual Studio 17 2022", "-A", "x64",
47
+ "-DCMAKE_INSTALL_PREFIX=$DepsDir",
48
+ "-DCMAKE_POLICY_DEFAULT_CMP0091=NEW",
49
+ "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL",
50
+ "-DWITH_OPENSSL=OFF",
51
+ "-DENABLE_ODBC=OFF"
52
+ )
53
+ $CmakeVersion = (cmake --version | Select-Object -First 1)
54
+ $IdText = "$FreeTdsVersion $FreeTdsSha256 win32-x64 $($CmakeArgs -join ' ') $CmakeVersion`n" + (($Patches | ForEach-Object { Get-Content -Raw $_.FullName }) -join "")
55
+ $BuildId = [System.BitConverter]::ToString(
56
+ [System.Security.Cryptography.SHA256]::Create().ComputeHash([System.Text.Encoding]::UTF8.GetBytes($IdText))
57
+ ).Replace("-", "")
58
+ $IdFile = Join-Path $DepsDir ".build-id"
59
+
35
60
  $LibFile = Join-Path $DepsDir "lib\db-lib.lib"
61
+ if ((Test-Path $LibFile) -and (-not (Test-Path $IdFile) -or (Get-Content -Raw $IdFile).Trim() -ne $BuildId)) {
62
+ Write-Host "==> FreeTDS in $DepsDir was built for another version, configuration or patch set; rebuilding"
63
+ Remove-Item -Recurse -Force $DepsDir
64
+ }
36
65
  if (-not (Test-Path $LibFile)) {
37
66
  Write-Host "==> Downloading FreeTDS $FreeTdsVersion..."
38
67
  New-Item -ItemType Directory -Path $BuildDir -Force | Out-Null
39
68
  Set-Location $BuildDir
40
69
 
41
70
  $Tarball = "freetds-$FreeTdsVersion.tar.gz"
42
- if (-not (Test-Path $Tarball)) {
71
+ # The package's own copy when there (vendor/), else a download.
72
+ $Vendored = Join-Path $RootDir "vendor\$Tarball"
73
+ if (Test-Path $Vendored) {
74
+ Copy-Item $Vendored $Tarball -Force
75
+ } elseif (-not (Test-Path $Tarball)) {
43
76
  curl.exe -fsSL "https://www.freetds.org/files/stable/freetds-$FreeTdsVersion.tar.gz" -o $Tarball
44
77
  if ($LASTEXITCODE -ne 0) { throw "Failed to download FreeTDS" }
45
78
  }
79
+ if ((Get-FileHash -Algorithm SHA256 $Tarball).Hash.ToLower() -ne $FreeTdsSha256) {
80
+ throw "$BuildDir\$Tarball does not match its known SHA-256; refusing to build it"
81
+ }
46
82
 
47
83
  Write-Host "==> Extracting..."
84
+ if (Test-Path "freetds-$FreeTdsVersion") { Remove-Item -Recurse -Force "freetds-$FreeTdsVersion" }
48
85
  tar xzf $Tarball
49
86
  if ($LASTEXITCODE -ne 0) { throw "Failed to extract tarball" }
50
-
51
87
  Set-Location "freetds-$FreeTdsVersion"
52
88
 
89
+ foreach ($Patch in $Patches) {
90
+ Write-Host "==> Applying $($Patch.Name)"
91
+ patch -p1 --forward --quiet -i $Patch.FullName
92
+ if ($LASTEXITCODE -ne 0) { throw "Failed to apply $($Patch.Name) (GNU patch from Git for Windows is needed)" }
93
+ }
94
+
53
95
  Write-Host "==> Configuring FreeTDS (MSVC x64, /MD runtime)..."
54
- cmake -B build -G "Visual Studio 17 2022" -A x64 `
55
- -DCMAKE_INSTALL_PREFIX="$DepsDir" `
56
- -DCMAKE_POLICY_DEFAULT_CMP0091=NEW `
57
- -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL `
58
- -DWITH_OPENSSL=OFF `
59
- -DENABLE_ODBC=OFF
96
+ cmake -B build @CmakeArgs
60
97
  if ($LASTEXITCODE -ne 0) { throw "CMake configure failed" }
61
98
 
62
99
  Write-Host "==> Compiling..."
@@ -66,6 +103,7 @@ if (-not (Test-Path $LibFile)) {
66
103
  Write-Host "==> Installing to $DepsDir..."
67
104
  cmake --install build --config Release
68
105
  if ($LASTEXITCODE -ne 0) { throw "CMake install failed" }
106
+ Set-Content -Path $IdFile -Value $BuildId
69
107
 
70
108
  Set-Location $RootDir
71
109
  Write-Host "==> FreeTDS built successfully"
@@ -106,6 +144,9 @@ $Dest = Join-Path $DestDir $NodeFile
106
144
 
107
145
  New-Item -ItemType Directory -Path $DestDir -Force | Out-Null
108
146
  Copy-Item $Source $Dest -Force
147
+ # The installed package loads it from dist/native.
148
+ $DistDir = Join-Path $RootDir "dist\native"
149
+ if (Test-Path $DistDir) { Copy-Item $Source (Join-Path $DistDir $NodeFile) -Force }
109
150
 
110
151
  # Verify no dynamic dependency on sybdb.dll
111
152
  $Content = [System.IO.File]::ReadAllBytes($Dest)
package/scripts/build.sh CHANGED
@@ -8,9 +8,14 @@
8
8
  # - Node.js headers
9
9
  #
10
10
  # This script:
11
- # 1. Downloads & compiles FreeTDS as a static library
11
+ # 1. Takes the FreeTDS source — vendor/freetds-<version>.tar.gz when there (as
12
+ # in the published package), else downloaded — checks its SHA-256, applies
13
+ # patches/freetds-<version>-*.patch, and compiles it as a static library
12
14
  # 2. Builds the N-API addon linked against it
13
- # 3. Copies the result to the appropriate npm/ platform directory
15
+ # 3. Copies the result to src/native (and dist/native when it exists)
16
+ #
17
+ # bash scripts/build.sh # build
18
+ # bash scripts/build.sh --fetch-source # only put the checked source in vendor/
14
19
  #
15
20
  set -euo pipefail
16
21
 
@@ -42,49 +47,109 @@ echo "FreeTDS version: $FREETDS_VERSION"
42
47
  # Step 1: Download and compile FreeTDS as static library
43
48
  # ---------------------------------------------------------------------------
44
49
 
50
+ # SHA-256 of each FreeTDS release tarball this script builds (checked before it
51
+ # is extracted, also when cached). A version not listed here is refused.
52
+ case "$FREETDS_VERSION" in
53
+ 1.5.17) FREETDS_SHA256=8d154ce458d1825a8625b0ef1c3288afecfc32b3a09015a5ece4fbdf8aafd144 ;;
54
+ *) echo "No known SHA-256 for FreeTDS $FREETDS_VERSION: add it to scripts/build.sh" >&2; exit 1 ;;
55
+ esac
56
+
57
+ sha256() { (shasum -a 256 "$@" 2>/dev/null || sha256sum "$@") | cut -d' ' -f1; }
58
+
59
+ TARBALL="freetds-$FREETDS_VERSION.tar.gz"
60
+ VENDORED="$ROOT_DIR/vendor/$TARBALL"
61
+
62
+ # The FreeTDS release tarball, checked, at `$1`: the vendored copy, else a
63
+ # download. Nothing that does not match its known SHA-256 is ever used.
64
+ fetch_source() {
65
+ local dest="$1"
66
+ if [ -f "$VENDORED" ] && [ "$VENDORED" != "$dest" ]; then
67
+ cp "$VENDORED" "$dest"
68
+ elif [ ! -f "$dest" ]; then
69
+ curl -fsSL "https://www.freetds.org/files/stable/$TARBALL" -o "$dest"
70
+ fi
71
+ if [ "$(sha256 "$dest")" != "$FREETDS_SHA256" ]; then
72
+ echo "$dest does not match the known SHA-256 of $TARBALL; refusing to use it" >&2
73
+ exit 1
74
+ fi
75
+ }
76
+
77
+ if [ "${1:-}" = "--fetch-source" ]; then
78
+ mkdir -p "$ROOT_DIR/vendor"
79
+ fetch_source "$VENDORED"
80
+ echo "==> $VENDORED"
81
+ exit 0
82
+ fi
83
+
84
+ # Patches applied to FreeTDS (see each file's header); there may be none.
85
+ shopt -s nullglob
86
+ PATCHES=("$ROOT_DIR"/patches/freetds-"$FREETDS_VERSION"-*.patch)
87
+ shopt -u nullglob
88
+
89
+ # CFLAGS=-fPIC is required on Linux — static library objects must be
90
+ # position-independent to link into a shared object (.node addon).
91
+ # On macOS cross-compiling x64 from arm64, add -arch x86_64.
92
+ EXTRA_CFLAGS="-fPIC -O2"
93
+ CONFIGURE_ARGS=(
94
+ --prefix="$DEPS_DIR"
95
+ --enable-static
96
+ --disable-shared
97
+ --with-tdsver=5.0
98
+ --disable-odbc
99
+ --disable-apps
100
+ --disable-server
101
+ --disable-pool
102
+ --without-openssl
103
+ --quiet
104
+ )
105
+ if [ "$OS" = "darwin" ] && [ "$ARCH" = "x64" ] && [ "$(uname -m)" = "arm64" ]; then
106
+ EXTRA_CFLAGS="$EXTRA_CFLAGS -arch x86_64"
107
+ CONFIGURE_ARGS+=(--host=x86_64-apple-darwin)
108
+ fi
109
+
110
+ # What the FreeTDS build depends on: version, source, patches, target, flags,
111
+ # configure options and compiler — and what configure takes from the
112
+ # environment besides (CFLAGS is set here). A build made from anything else is
113
+ # rebuilt, so a stale or foreign libsybdb.a (another architecture's, say) is
114
+ # never linked.
115
+ BUILD_ID="$(
116
+ {
117
+ echo "$FREETDS_VERSION $FREETDS_SHA256 $PLATFORM $EXTRA_CFLAGS ${CONFIGURE_ARGS[*]}"
118
+ echo "CC=${CC-} CPP=${CPP-} CPPFLAGS=${CPPFLAGS-} LDFLAGS=${LDFLAGS-} LIBS=${LIBS-}"
119
+ "${CC:-cc}" --version 2>/dev/null | head -1 || true
120
+ if [ ${#PATCHES[@]} -gt 0 ]; then cat "${PATCHES[@]}"; fi
121
+ } | (shasum -a 256 2>/dev/null || sha256sum) | cut -d' ' -f1
122
+ )"
123
+ if [ -f "$DEPS_DIR/lib/libsybdb.a" ] && [ "$(cat "$DEPS_DIR/.build-id" 2>/dev/null)" != "$BUILD_ID" ]; then
124
+ echo "==> FreeTDS in $DEPS_DIR was built for another version, target or patch set; rebuilding"
125
+ rm -rf "$DEPS_DIR"
126
+ fi
127
+
45
128
  if [ ! -f "$DEPS_DIR/lib/libsybdb.a" ]; then
46
- echo "==> Downloading FreeTDS $FREETDS_VERSION..."
129
+ echo "==> FreeTDS $FREETDS_VERSION source..."
47
130
  mkdir -p "$BUILD_DIR"
48
131
  cd "$BUILD_DIR"
49
-
50
- TARBALL="freetds-$FREETDS_VERSION.tar.gz"
51
- if [ ! -f "$TARBALL" ]; then
52
- curl -fsSL "https://www.freetds.org/files/stable/freetds-$FREETDS_VERSION.tar.gz" -o "$TARBALL"
53
- fi
132
+ fetch_source "$BUILD_DIR/$TARBALL"
54
133
 
55
134
  echo "==> Extracting..."
135
+ rm -rf "freetds-$FREETDS_VERSION"
56
136
  tar xzf "$TARBALL"
57
137
  cd "freetds-$FREETDS_VERSION"
58
138
 
59
- echo "==> Configuring FreeTDS (static only)..."
60
- # CFLAGS=-fPIC is required on Linux — static library objects must be
61
- # position-independent to link into a shared object (.node addon).
62
- # On macOS cross-compiling x64 from arm64, add -arch x86_64.
63
- EXTRA_CFLAGS="-fPIC -O2"
64
- CONFIGURE_HOST=""
65
- if [ "$OS" = "darwin" ] && [ "$ARCH" = "x64" ] && [ "$(uname -m)" = "arm64" ]; then
66
- EXTRA_CFLAGS="$EXTRA_CFLAGS -arch x86_64"
67
- CONFIGURE_HOST="--host=x86_64-apple-darwin"
68
- fi
139
+ for PATCH in "${PATCHES[@]}"; do
140
+ echo "==> Applying $(basename "$PATCH")"
141
+ patch -p1 --forward --quiet < "$PATCH"
142
+ done
69
143
 
70
- CFLAGS="$EXTRA_CFLAGS" ./configure \
71
- --prefix="$DEPS_DIR" \
72
- --enable-static \
73
- --disable-shared \
74
- --with-tdsver=5.0 \
75
- --disable-odbc \
76
- --disable-apps \
77
- --disable-server \
78
- --disable-pool \
79
- --without-openssl \
80
- $CONFIGURE_HOST \
81
- --quiet
144
+ echo "==> Configuring FreeTDS (static only)..."
145
+ CFLAGS="$EXTRA_CFLAGS" ./configure "${CONFIGURE_ARGS[@]}"
82
146
 
83
147
  echo "==> Compiling..."
84
148
  make -j"$(nproc 2>/dev/null || sysctl -n hw.ncpu)" --quiet
85
149
 
86
150
  echo "==> Installing to $DEPS_DIR..."
87
151
  make install --quiet
152
+ echo "$BUILD_ID" > "$DEPS_DIR/.build-id"
88
153
 
89
154
  cd "$ROOT_DIR"
90
155
  echo "==> FreeTDS static library built successfully"
@@ -115,8 +180,14 @@ if [ "$OS" = "darwin" ]; then
115
180
  NODE_FILE="sybase_native.darwin-${ARCH}.node"
116
181
  fi
117
182
 
183
+ # Both places the loader may load it from: src/native in this repo, dist/native
184
+ # in the installed package (where src/ holds no loader).
118
185
  echo "==> Copying addon to src/native/${NODE_FILE}"
119
186
  cp "$ROOT_DIR/build/Release/sybase_native.node" "$ROOT_DIR/src/native/${NODE_FILE}"
187
+ if [ -d "$ROOT_DIR/dist/native" ]; then
188
+ echo "==> Copying addon to dist/native/${NODE_FILE}"
189
+ cp "$ROOT_DIR/build/Release/sybase_native.node" "$ROOT_DIR/dist/native/${NODE_FILE}"
190
+ fi
120
191
 
121
192
  echo ""
122
193
  echo "=== Build complete ==="
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Load a built addon and check it works: what CI runs on each platform's binary,
3
+ * under the Node.js it must run on, before it can be published.
4
+ *
5
+ * node scripts/smoke-native.ts build/Release/sybase_native.node
6
+ * node scripts/smoke-native.ts --package <dir> # an installed drizzle-sybase
7
+ *
8
+ * `dlopen` fails on a binary built for another platform, or needing a newer libc
9
+ * or runtime than this machine has; `getVersion` reaches into the statically
10
+ * linked FreeTDS; every function the JS layer calls must be exported.
11
+ */
12
+
13
+ import { execFileSync } from "child_process";
14
+ import { resolve } from "path";
15
+
16
+ const EXPORTS = [
17
+ "connect",
18
+ "query",
19
+ "bulkBegin",
20
+ "bulkSend",
21
+ "close",
22
+ "isAlive",
23
+ "serverCharset",
24
+ "getVersion"
25
+ ];
26
+
27
+ /** The binding's FreeTDS version and the functions it lacks, checked. */
28
+ const check = (version: string, missing: string[], from: string): void => {
29
+ if (!version.includes("FreeTDS")) {
30
+ throw new Error(`${from}: unexpected getVersion(): ${version}`);
31
+ }
32
+ if (missing.length > 0) {
33
+ throw new Error(`${from}: missing exports: ${missing.join(", ")}`);
34
+ }
35
+ console.log(
36
+ `${from}: OK on Node ${process.version} ${process.platform}-${process.arch}: ${version}`
37
+ );
38
+ };
39
+
40
+ const [mode, target] = process.argv.slice(2);
41
+ if (mode === "--package") {
42
+ // As an application in `dir` would: `import "drizzle-sybase"`, through the
43
+ // package's exports and its own loader. Run from there, so that it resolves.
44
+ const dir = resolve(target ?? ".");
45
+ const code =
46
+ 'const { getNative } = await import("drizzle-sybase"); const b = getNative();' +
47
+ `const missing = ${JSON.stringify(EXPORTS)}.filter(name => typeof b[name] !== "function");` +
48
+ "process.stdout.write(JSON.stringify({ version: String(b.getVersion()), missing }));";
49
+ const out = JSON.parse(
50
+ execFileSync(process.execPath, ["--input-type=module", "-e", code], {
51
+ cwd: dir,
52
+ encoding: "utf8"
53
+ })
54
+ ) as { version: string; missing: string[] };
55
+ check(out.version, out.missing, `drizzle-sybase installed in ${dir}`);
56
+ } else if (mode) {
57
+ const module = { exports: {} as Record<string, unknown> };
58
+ process.dlopen(module, resolve(mode));
59
+ const binding = module.exports;
60
+ check(
61
+ String((binding.getVersion as () => unknown)()),
62
+ EXPORTS.filter(name => typeof binding[name] !== "function"),
63
+ mode
64
+ );
65
+ } else {
66
+ throw new Error("usage: smoke-native.ts <addon.node> | --package <dir>");
67
+ }
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # Pack this package as it would be published, check what the tarball holds,
4
+ # install it into an empty project as an application would, and load it there:
5
+ # on Linux in AWS Lambda's Node.js 24 image (Amazon Linux 2023, glibc 2.34) for
6
+ # this machine's architecture, elsewhere with the Node.js running this script.
7
+ # Catches a tarball missing a binary, its loader or the material to rebuild it,
8
+ # and a Linux binary Lambda cannot load.
9
+ #
10
+ # bash scripts/smoke-package.sh
11
+ #
12
+ # Needs dist/ built with every platform's binary in dist/native, the FreeTDS
13
+ # source in vendor/ (scripts/build.sh --fetch-source), and Docker on Linux.
14
+ set -euo pipefail
15
+
16
+ ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
17
+ WORK="$(mktemp -d)"
18
+ trap 'rm -rf "$WORK"' EXIT
19
+
20
+ cd "$ROOT_DIR"
21
+ npm pack --pack-destination "$WORK" >/dev/null
22
+ TARBALL="$(ls "$WORK"/drizzle-sybase-*.tgz)"
23
+ mkdir "$WORK/unpacked"
24
+ tar -xzf "$TARBALL" -C "$WORK/unpacked"
25
+ PKG="$WORK/unpacked/package"
26
+
27
+ # Every binary, and not an empty placeholder.
28
+ for p in darwin-arm64 darwin-x64 linux-arm64 linux-x64 win32-x64; do
29
+ if [ ! -s "$PKG/dist/native/sybase_native.$p.node" ]; then
30
+ echo "The tarball has no binary for $p (or an empty one)" >&2
31
+ exit 1
32
+ fi
33
+ done
34
+
35
+ # What rebuilding the binaries against a modified FreeTDS takes (see
36
+ # THIRD_PARTY_NOTICES.md): its source, the patches, the addon's source and the
37
+ # build scripts — and the license and notices.
38
+ # shellcheck disable=SC2016 # the $ in the pattern is build.sh's own text
39
+ FREETDS_VERSION="$(sed -n 's/^FREETDS_VERSION="\${FREETDS_VERSION:-\(.*\)}"$/\1/p' scripts/build.sh)"
40
+ for f in "vendor/freetds-$FREETDS_VERSION.tar.gz" src/native/binding.c binding.gyp \
41
+ scripts/build.sh scripts/build-win.ps1 THIRD_PARTY_NOTICES.md licenses/FreeTDS-COPYING_LIB.txt \
42
+ LICENSE; do
43
+ if [ ! -s "$PKG/$f" ]; then
44
+ echo "The tarball is missing $f" >&2
45
+ exit 1
46
+ fi
47
+ done
48
+ for patch in patches/freetds-"$FREETDS_VERSION"-*.patch; do
49
+ if ! cmp -s "$patch" "$PKG/$patch"; then
50
+ echo "The tarball's $patch differs from the repository's" >&2
51
+ exit 1
52
+ fi
53
+ done
54
+ # Nothing that should never be published.
55
+ if (cd "$PKG" && find . -name '.env*' -o -name '*.pem' -o -name 'id_rsa*' | grep -q .); then
56
+ echo "The tarball holds files that must not be published:" >&2
57
+ (cd "$PKG" && find . -name '.env*' -o -name '*.pem' -o -name 'id_rsa*') >&2
58
+ exit 1
59
+ fi
60
+
61
+ DRIZZLE="$(node -p "require('./package.json').peerDependencies['drizzle-orm']")"
62
+ mkdir "$WORK/app"
63
+ cd "$WORK/app"
64
+ npm init -y >/dev/null
65
+ npm install --no-audit --no-fund "$TARBALL" "drizzle-orm@$DRIZZLE" >/dev/null
66
+ cp "$ROOT_DIR/scripts/smoke-native.ts" "$WORK/"
67
+
68
+ if [ "$(uname -s)" = "Linux" ]; then
69
+ case "$(uname -m)" in
70
+ x86_64 | amd64) DOCKER_PLATFORM=linux/amd64 ;;
71
+ arm64 | aarch64) DOCKER_PLATFORM=linux/arm64 ;;
72
+ *) echo "Unsupported architecture: $(uname -m)" >&2; exit 1 ;;
73
+ esac
74
+ docker run --rm --pull always --platform "$DOCKER_PLATFORM" --entrypoint node -v "$WORK:/w" -w /w/app \
75
+ public.ecr.aws/lambda/nodejs:24 \
76
+ /w/smoke-native.ts --package /w/app
77
+ else
78
+ node "$WORK/smoke-native.ts" --package "$WORK/app"
79
+ fi
@@ -59,6 +59,9 @@ const DEFAULT_REGISTRY = "https://registry.npmjs.org";
59
59
  const DEFAULT_ATTEMPTS = 60;
60
60
  const DEFAULT_INTERVAL_MS = 15_000;
61
61
 
62
+ /** Longest a single request to the registry may take: a hung one is a failed attempt. */
63
+ const REQUEST_TIMEOUT_MS = 30_000;
64
+
62
65
  export interface VerifyOptions {
63
66
  readonly registry?: string;
64
67
  readonly attempts?: number;
@@ -126,7 +129,8 @@ export async function verifyPublished(
126
129
  let response: Response;
127
130
  try {
128
131
  response = await fetch(url, {
129
- headers: { accept: "application/json", "cache-control": "no-cache" }
132
+ headers: { accept: "application/json", "cache-control": "no-cache" },
133
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
130
134
  });
131
135
  } catch (cause) {
132
136
  last = `request failed: ${cause instanceof Error ? cause.message : String(cause)}`;
@@ -166,7 +170,23 @@ export async function verifyPublished(
166
170
  continue;
167
171
  }
168
172
 
169
- const document = (await response.json()) as { version?: unknown; dist?: { tarball?: unknown } };
173
+ let document: { version?: unknown; dist?: { tarball?: unknown } };
174
+ try {
175
+ const parsed: unknown = await response.json();
176
+ // Valid JSON but no version document (`null`, a string, ...): as garbled.
177
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
178
+ throw new Error(`not a version document: ${JSON.stringify(parsed).slice(0, 80)}`);
179
+ }
180
+ document = parsed as typeof document;
181
+ } catch (cause) {
182
+ // A cut-off or garbled answer says nothing about the version: ask again.
183
+ last = `unreadable answer: ${cause instanceof Error ? cause.message : String(cause)}`;
184
+ log(` ${label}: ${last} (attempt ${attempt}/${attempts})`);
185
+ if (attempt < attempts) {
186
+ await sleep(intervalMs);
187
+ }
188
+ continue;
189
+ }
170
190
  if (document.version !== spec.version) {
171
191
  // The registry answered for a different version than the path asked for,
172
192
  // which would make every later assertion meaningless.
@@ -182,7 +202,10 @@ export async function verifyPublished(
182
202
  }
183
203
 
184
204
  // A version document naming a tarball nobody can fetch is not a release.
185
- const head = await fetch(tarball, { method: "HEAD" }).catch(() => undefined);
205
+ const head = await fetch(tarball, {
206
+ method: "HEAD",
207
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
208
+ }).catch(() => undefined);
186
209
  if (head === undefined || !head.ok) {
187
210
  last = `tarball not fetchable (${head === undefined ? "request failed" : `HTTP ${head.status}`})`;
188
211
  log(` ${label}: ${last} (attempt ${attempt}/${attempts})`);
@@ -192,7 +215,7 @@ export async function verifyPublished(
192
215
  continue;
193
216
  }
194
217
 
195
- log(`✓ ${label} is live and installable (attempt ${attempt}/${attempts})`);
218
+ log(`✓ ${label} is live and its tarball fetchable (attempt ${attempt}/${attempts})`);
196
219
  return { ok: true, attempts: attempt };
197
220
  }
198
221
 
@@ -228,7 +251,8 @@ export async function versionExists(
228
251
  const url = versionUrl(options.registry ?? DEFAULT_REGISTRY, spec);
229
252
  try {
230
253
  const response = await fetch(url, {
231
- headers: { accept: "application/json", "cache-control": "no-cache" }
254
+ headers: { accept: "application/json", "cache-control": "no-cache" },
255
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
232
256
  });
233
257
  if (response.status === 401 || response.status === 403) {
234
258
  return true;