@pqe-pro/source-mysql 0.0.0-stage → 0.4.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/LICENSE +21 -0
- package/NOTICE.md +5 -0
- package/README.md +294 -2
- package/dependency-notices.json +65 -0
- package/dist/execution/infrastructure/mysql/connection.d.ts +27 -0
- package/dist/execution/infrastructure/mysql/connection.js +183 -0
- package/dist/execution/infrastructure/mysql/packet-budget.d.ts +9 -0
- package/dist/execution/infrastructure/mysql/packet-budget.js +69 -0
- package/dist/execution/infrastructure/mysql/source.d.ts +52 -0
- package/dist/execution/infrastructure/mysql/source.js +296 -0
- package/dist/exports/mysql.d.ts +2 -0
- package/dist/exports/mysql.js +1 -0
- package/npm-shrinkwrap.json +131 -0
- package/package.json +52 -4
- package/sbom.cdx.json +160 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vacho Aivazov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Notice
|
|
2
|
+
|
|
3
|
+
The Progressive Query Engine packages are released under the MIT License; see `LICENSE`.
|
|
4
|
+
|
|
5
|
+
Third-party runtime dependency licenses and notices are preserved in `dependency-notices.json`, and the runtime dependency inventory is in `sbom.cdx.json`. React is an optional host-provided peer of `@pqe-pro/react`. A dependency's license does not change the license of these packages.
|
package/README.md
CHANGED
|
@@ -1,3 +1,295 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Progressive Query Engine
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Progressive Query Engine (PQE) runs registered queries under strict deadlines and streams their results progressively as newline-delimited JSON (NDJSON) to a browser or React client. It never loses track of the physical work it starts: a timeout or a cancellation does not count as proof that a database statement or an HTTP call stopped.
|
|
4
|
+
|
|
5
|
+
A page often needs one required result quickly and several optional, slower ones, for example a product list from PostgreSQL and delivery terms from a slow HTTP provider. PQE answers with one `initial` event carrying the required page, at most one `patch` per optional group, then one `complete`. A stream that ends without `complete` is an interruption, never a short success.
|
|
6
|
+
|
|
7
|
+
Requirements: Node 22.12 or later, ESM only. Every package ships TypeScript declarations.
|
|
8
|
+
|
|
9
|
+
## Packages
|
|
10
|
+
|
|
11
|
+
Install only what a host needs. Sibling packages depend on each other with exact versions, so keep all `@pqe-pro/*` packages of one application on the same version.
|
|
12
|
+
|
|
13
|
+
| Package | Use it for |
|
|
14
|
+
| ------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------- |
|
|
15
|
+
| [`@pqe-pro/core`](https://www.npmjs.com/package/@pqe-pro/core) | The engine, query and contract definitions, the ports a host implements; `@pqe-pro/core/protocol`; `@pqe-pro/core/telemetry`. |
|
|
16
|
+
| [`@pqe-pro/node`](https://www.npmjs.com/package/@pqe-pro/node) | The Node HTTPS query server (NDJSON, JSON and enrichment routes), the NDJSON encoder and the monotonic clock. |
|
|
17
|
+
| [`@pqe-pro/oidc`](https://www.npmjs.com/package/@pqe-pro/oidc) | OIDC/JWT identity verification behind the engine's identity port. |
|
|
18
|
+
| [`@pqe-pro/source-postgres`](https://www.npmjs.com/package/@pqe-pro/source-postgres) | The PostgreSQL source adapter (PostgreSQL 17 or 18, `pg` driver). |
|
|
19
|
+
| [`@pqe-pro/source-http`](https://www.npmjs.com/package/@pqe-pro/source-http) | The bounded HTTP source adapter. |
|
|
20
|
+
| `@pqe-pro/source-grpc` | Bounded unary gRPC calls to Protobuf services over verified TLS. |
|
|
21
|
+
| `@pqe-pro/source-mysql` | MySQL 8.4 source with tenant-specific readers, bounded results and active cancellation. |
|
|
22
|
+
| [`@pqe-pro/coordination`](https://www.npmjs.com/package/@pqe-pro/coordination) | Coordination of capacity and authority between processes, with a PostgreSQL store, its ledger DDL and settlement probes. |
|
|
23
|
+
| [`@pqe-pro/browser`](https://www.npmjs.com/package/@pqe-pro/browser) | The browser query store and its fetch transport. No Node or server code. |
|
|
24
|
+
| [`@pqe-pro/react`](https://www.npmjs.com/package/@pqe-pro/react) | React hooks over the browser store. React 18.3 or 19 is a peer dependency. |
|
|
25
|
+
| `@pqe-pro/vue` | Vue 3 composables over the browser store. Vue 3.5.47 or later in the Vue 3 line is a peer dependency. |
|
|
26
|
+
| `@pqe-pro/angular` | Angular 22 signals and dependency injection over the browser query store. |
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
# A Node query server
|
|
30
|
+
npm install @pqe-pro/core @pqe-pro/node @pqe-pro/source-postgres zod
|
|
31
|
+
# A React client
|
|
32
|
+
npm install @pqe-pro/core @pqe-pro/browser @pqe-pro/react zod
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## A query
|
|
36
|
+
|
|
37
|
+
A query has a public contract, shared by server and client, and a server-side definition that owns authorization and data loading. Schemas are [Zod](https://zod.dev) schemas; every external value is validated before it is published.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
// contract.ts: shared by server and client
|
|
41
|
+
import { z } from "zod";
|
|
42
|
+
import { defineContract } from "@pqe-pro/core/protocol";
|
|
43
|
+
|
|
44
|
+
export const boardContract = defineContract({
|
|
45
|
+
id: "boards.items.v1",
|
|
46
|
+
input: z.strictObject({ board: z.string().min(1).max(64), size: z.number().int().min(1).max(50) }),
|
|
47
|
+
base: z.strictObject({ id: z.string(), title: z.string() }),
|
|
48
|
+
groups: { activity: z.strictObject({ count: z.number().int().nonnegative() }) },
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// server.ts
|
|
54
|
+
import { randomUUID } from "node:crypto";
|
|
55
|
+
import { readFileSync } from "node:fs";
|
|
56
|
+
import { z } from "zod";
|
|
57
|
+
import { defineQuery, QueryRegistry, GenericQueryEngine, referencePolicy } from "@pqe-pro/core";
|
|
58
|
+
import { ndjsonEncoder, systemClock, QueryServer } from "@pqe-pro/node";
|
|
59
|
+
import { HttpSource } from "@pqe-pro/source-http";
|
|
60
|
+
import { boardContract } from "./contract.ts";
|
|
61
|
+
|
|
62
|
+
// What the upstream service answers; every external value is validated.
|
|
63
|
+
const items = z.strictObject({ items: z.array(z.strictObject({ id: z.string(), title: z.string() })) });
|
|
64
|
+
const counts = z.strictObject({ counts: z.record(z.string(), z.number().int().nonnegative()) });
|
|
65
|
+
|
|
66
|
+
const query = defineQuery({
|
|
67
|
+
contract: boardContract,
|
|
68
|
+
policy: referencePolicy,
|
|
69
|
+
// What the trusted identity carries, and what authorization hands to the loaders.
|
|
70
|
+
identityContext: z.strictObject({ role: z.enum(["viewer", "editor"]) }),
|
|
71
|
+
authorizationOutput: z.strictObject({ board: z.string() }),
|
|
72
|
+
authorizationSources: [],
|
|
73
|
+
authorizationMaxBusinessCalls: 0,
|
|
74
|
+
async authorize(request, context) {
|
|
75
|
+
return { board: context.identity.context.role === "editor" ? request.input.board : "public" };
|
|
76
|
+
},
|
|
77
|
+
pageSize: (input) => input.size,
|
|
78
|
+
// The required part: answered in the `initial` event or not at all. Loaders reach data only
|
|
79
|
+
// through `context.call` on a registered source, which owns the physical request.
|
|
80
|
+
root: {
|
|
81
|
+
source: "catalog",
|
|
82
|
+
timeoutMs: 700,
|
|
83
|
+
maxBusinessCalls: 1,
|
|
84
|
+
async load(input, context) {
|
|
85
|
+
const page = await context.call("catalog", { kind: "items", board: context.authorized.board, size: input.size }, items);
|
|
86
|
+
return { items: page.items, pageInfo: { endCursor: null, hasNextPage: false } };
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
// An optional group: one `patch` per group, with a ready, unavailable or failed state per row.
|
|
90
|
+
groups: {
|
|
91
|
+
activity: {
|
|
92
|
+
source: "catalog",
|
|
93
|
+
timeoutMs: 900,
|
|
94
|
+
maxBatchSize: 50,
|
|
95
|
+
maxBusinessCalls: 1,
|
|
96
|
+
async load(args, context) {
|
|
97
|
+
const answer = await context.call("catalog", { kind: "activity", board: context.authorized.board, ids: args.ids }, counts);
|
|
98
|
+
return args.ids.map((id) => {
|
|
99
|
+
const count = answer.counts[id];
|
|
100
|
+
return count === undefined
|
|
101
|
+
? { id, result: { status: "unavailable" as const, reason: "not_found" as const } }
|
|
102
|
+
: { id, result: { status: "ready" as const, value: { count } } };
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// An upstream HTTPS JSON service; PostgresSource from @pqe-pro/source-postgres is the other adapter.
|
|
110
|
+
const catalog = new HttpSource(
|
|
111
|
+
{
|
|
112
|
+
id: "catalog",
|
|
113
|
+
generation: randomUUID(),
|
|
114
|
+
endpoint: "https://catalog.internal.example/catalog",
|
|
115
|
+
ca: readFileSync("catalog-ca.pem", "utf8"),
|
|
116
|
+
token: process.env.CATALOG_TOKEN ?? "",
|
|
117
|
+
capacityScope: "local_io",
|
|
118
|
+
capacity: 8,
|
|
119
|
+
rootReserve: 2,
|
|
120
|
+
maxQueuedTasks: 32,
|
|
121
|
+
maxDurationMs: 1000,
|
|
122
|
+
maxBodyBytes: 16384,
|
|
123
|
+
},
|
|
124
|
+
systemClock,
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const engine = new GenericQueryEngine({
|
|
128
|
+
registry: new QueryRegistry([query]),
|
|
129
|
+
clock: systemClock,
|
|
130
|
+
encoder: ndjsonEncoder(),
|
|
131
|
+
sources: [catalog],
|
|
132
|
+
// Trusted identity comes only from server-side authentication, for example OidcIdentityPort.
|
|
133
|
+
identity: {
|
|
134
|
+
sources: [],
|
|
135
|
+
maxBusinessCalls: 0,
|
|
136
|
+
async resolve() {
|
|
137
|
+
return { tenantId: "tenant", principalId: "user", authScopeVersion: "1", context: { role: "editor" } };
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
// Admission of physical operations; @pqe-pro/coordination provides one shared between processes.
|
|
141
|
+
authority: {
|
|
142
|
+
healthy: () => true,
|
|
143
|
+
async begin(context, sourceId) {
|
|
144
|
+
return { operationId: context.operationId, sourceId, generation: "local" };
|
|
145
|
+
},
|
|
146
|
+
async acquired() {},
|
|
147
|
+
async settle() {},
|
|
148
|
+
},
|
|
149
|
+
telemetry: { emit() {} },
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
await catalog.verify();
|
|
153
|
+
const server = new QueryServer(engine, {
|
|
154
|
+
tls: { cert: readFileSync("server.pem", "utf8"), key: readFileSync("server-key.pem", "utf8") },
|
|
155
|
+
drainMs: 2000,
|
|
156
|
+
hardCutoffMs: 5000,
|
|
157
|
+
});
|
|
158
|
+
await server.listen("127.0.0.1", 8443);
|
|
159
|
+
// POST /v1/query/ndjson streams events; POST /v1/query/json answers once; GET /health/ready.
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
A complete runnable version, with a small upstream service, a Node client and server-side rendering, is [examples/board](https://github.com/watscho/pqe-pro/tree/main/examples/board) in the repository.
|
|
163
|
+
|
|
164
|
+
## Metrics with OpenTelemetry
|
|
165
|
+
|
|
166
|
+
`BoundedTelemetry` from `@pqe-pro/core/telemetry` validates the engine's observations and keeps bounded aggregates for a Prometheus text endpoint. With an exporter it mirrors the same aggregates into your OpenTelemetry meter. The packages do not depend on OpenTelemetry: pass your own meter from `@opentelemetry/api` 1.7 or later.
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
// telemetry.ts
|
|
170
|
+
import { metrics } from "@opentelemetry/api";
|
|
171
|
+
import { BoundedTelemetry, openTelemetryMetrics } from "@pqe-pro/core/telemetry";
|
|
172
|
+
|
|
173
|
+
// Your OpenTelemetry SDK setup registers the global meter provider and its exporter.
|
|
174
|
+
export const telemetry = new BoundedTelemetry(["boards.items.v1"], {
|
|
175
|
+
exporter: openTelemetryMetrics(metrics.getMeter("pqe")),
|
|
176
|
+
});
|
|
177
|
+
// Pass `telemetry` as the engine's `telemetry` option, and
|
|
178
|
+
// `onTerminal: (record) => telemetry.terminal(record)` in the QueryServer options.
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Instruments are named like the Prometheus families without the suffix (`pqe_requests`, `pqe_phase` in seconds, `pqe_output` in bytes), and carry the same bounded attributes. Request, operation, tenant and principal identifiers never become attributes. An exporter that throws is counted by `telemetry.exportFailures()` and never affects a query.
|
|
182
|
+
|
|
183
|
+
## A React client
|
|
184
|
+
|
|
185
|
+
```tsx
|
|
186
|
+
// board.tsx
|
|
187
|
+
import { createPqeClient, type PqeClient } from "@pqe-pro/browser";
|
|
188
|
+
import { PqeProvider, useOwnedQuery, usePqeClient } from "@pqe-pro/react";
|
|
189
|
+
import { boardContract } from "./contract.ts";
|
|
190
|
+
|
|
191
|
+
export function createBoardClient() {
|
|
192
|
+
return createPqeClient({ endpoint: "/v1/query/ndjson", format: "ndjson" });
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function BoardApp({ client }: { client: PqeClient }) {
|
|
196
|
+
return <PqeProvider client={client}><Board /></PqeProvider>;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function Board() {
|
|
200
|
+
const client = usePqeClient();
|
|
201
|
+
const { store, snapshot } = useOwnedQuery(() =>
|
|
202
|
+
client.createStore({
|
|
203
|
+
contract: boardContract,
|
|
204
|
+
groups: ["activity"],
|
|
205
|
+
clientBudgetMs: 3000,
|
|
206
|
+
}),
|
|
207
|
+
);
|
|
208
|
+
return (
|
|
209
|
+
<section>
|
|
210
|
+
<button onClick={() => store.run({ board: "main", size: 20 })}>Load</button>
|
|
211
|
+
<p role="status">{snapshot.status}</p>
|
|
212
|
+
<ul>
|
|
213
|
+
{snapshot.execution.initial?.page.items.map((item) => (
|
|
214
|
+
<li key={item.id}>{item.title}</li>
|
|
215
|
+
))}
|
|
216
|
+
</ul>
|
|
217
|
+
</section>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Create one client for each mounted application or SSR request. The nearest `PqeProvider` supplies its transport configuration, and `client.createStore` creates a separate store for each query owner. `useOwnedQuery` releases the store's reads on unmount. Pass a server-rendered snapshot from `executeSsr` as `initialSnapshot` when creating the store in both renders to hydrate without a repeat request.
|
|
223
|
+
|
|
224
|
+
## A Vue client
|
|
225
|
+
|
|
226
|
+
Call `useOwnedQuery` in `setup()` to tie the store to the component. Its `snapshot` is a read-only shallow ref. For a store owned elsewhere, call `useQueryStore(store)` to subscribe without taking ownership.
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
// board-vue.ts
|
|
230
|
+
import type { PqeClient } from "@pqe-pro/browser";
|
|
231
|
+
import { PqeProvider, useOwnedQuery, usePqeClient } from "@pqe-pro/vue";
|
|
232
|
+
import { createSSRApp, defineComponent, h } from "vue";
|
|
233
|
+
import { boardContract } from "./contract.ts";
|
|
234
|
+
|
|
235
|
+
export const Board = defineComponent({
|
|
236
|
+
setup() {
|
|
237
|
+
const client = usePqeClient();
|
|
238
|
+
const { store, snapshot } = useOwnedQuery(() =>
|
|
239
|
+
client.createStore({
|
|
240
|
+
contract: boardContract,
|
|
241
|
+
groups: ["activity"],
|
|
242
|
+
clientBudgetMs: 3000,
|
|
243
|
+
}),
|
|
244
|
+
);
|
|
245
|
+
return () =>
|
|
246
|
+
h("button", {
|
|
247
|
+
onClick: () => {
|
|
248
|
+
void store.run({ board: "main", size: 20 }).settled;
|
|
249
|
+
},
|
|
250
|
+
}, snapshot.value.status);
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
export function createBoardApp(client: PqeClient) {
|
|
255
|
+
return createSSRApp({
|
|
256
|
+
render: () => h(PqeProvider, { client }, { default: () => h(Board) }),
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
For SSR, seed `client.createStore` with the same `initialSnapshot` in both renders and hydrate with Vue's `createSSRApp`. A request starts when the caller invokes `run`. Mount a fresh provider subtree when changing account or endpoint scope to dispose the previous stores.
|
|
262
|
+
|
|
263
|
+
## An Angular client
|
|
264
|
+
|
|
265
|
+
Use Angular 22.3.2 or later in the Angular 22 line and its supported Node and TypeScript versions. Call `providePqeClient` at app or component scope. In a component field initializer, use `injectOwnedQuery` to create a store or `injectQuerySignal` to subscribe to an existing one.
|
|
266
|
+
|
|
267
|
+
```ts
|
|
268
|
+
// board-angular.ts
|
|
269
|
+
import type { ApplicationConfig } from "@angular/core";
|
|
270
|
+
import { createPqeClient } from "@pqe-pro/browser";
|
|
271
|
+
import { injectOwnedQuery, injectPqeClient, providePqeClient } from "@pqe-pro/angular";
|
|
272
|
+
import { boardContract } from "./contract.ts";
|
|
273
|
+
|
|
274
|
+
export function createBoardConfig(): ApplicationConfig {
|
|
275
|
+
const client = createPqeClient({ endpoint: "/v1/query/ndjson", format: "ndjson" });
|
|
276
|
+
return { providers: [providePqeClient(client)] };
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function injectBoard(initialSnapshot?: unknown) {
|
|
280
|
+
const client = injectPqeClient();
|
|
281
|
+
return injectOwnedQuery(() =>
|
|
282
|
+
client.createStore({ contract: boardContract, groups: ["activity"], clientBudgetMs: 3000, initialSnapshot }),
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Read `snapshot()` from the component template. Pass the same `initialSnapshot` when rendering and hydrating. The first browser render reads it immediately. Subscriptions and store ownership begin after the first browser render, and destruction releases both.
|
|
288
|
+
|
|
289
|
+
## Stability
|
|
290
|
+
|
|
291
|
+
Version 0.x: the public API may change between minor versions until 1.0. Every release lists what changed in [CHANGELOG.md](https://github.com/watscho/pqe-pro/blob/main/CHANGELOG.md). The `./internal/*` subpaths exist only so that sibling `@pqe-pro` packages can share modules; they are not a public interface and may change in any release.
|
|
292
|
+
|
|
293
|
+
## More
|
|
294
|
+
|
|
295
|
+
Source, the behaviour specification, the domain documentation and the test suites are in the [GitHub repository](https://github.com/watscho/pqe-pro). Licence: MIT. Third-party notices: `NOTICE.md`, `dependency-notices.json` and `sbom.cdx.json` in each package.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"scope": "Runtime dependencies only",
|
|
3
|
+
"dependencies": [
|
|
4
|
+
{
|
|
5
|
+
"name": "aws-ssl-profiles",
|
|
6
|
+
"version": "1.1.2",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"notice": "Copyright (c) 2024 Andrey Sidorov, Douglas Wilson, Weslley Araújo and contributors.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "generate-function",
|
|
12
|
+
"version": "2.3.1",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"notice": "The MIT License (MIT)\n\nCopyright (c) 2014 Mathias Buus\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE."
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"name": "iconv-lite",
|
|
18
|
+
"version": "0.7.3",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"notice": "Copyright (c) 2011 Alexander Shtuchkin\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "is-property",
|
|
24
|
+
"version": "1.0.2",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"notice": "\nThe MIT License (MIT)\n\nCopyright (c) 2013 Mikola Lysenko\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name": "long",
|
|
30
|
+
"version": "5.3.2",
|
|
31
|
+
"license": "Apache-2.0",
|
|
32
|
+
"notice": "\n Apache License\n Version 2.0, January 2004\n http://www.apache.org/licenses/\n\n TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n 1. Definitions.\n\n \"License\" shall mean the terms and conditions for use, reproduction,\n and distribution as defined by Sections 1 through 9 of this document.\n\n \"Licensor\" shall mean the copyright owner or entity authorized by\n the copyright owner that is granting the License.\n\n \"Legal Entity\" shall mean the union of the acting entity and all\n other entities that control, are controlled by, or are under common\n control with that entity. For the purposes of this definition,\n \"control\" means (i) the power, direct or indirect, to cause the\n direction or management of such entity, whether by contract or\n otherwise, or (ii) ownership of fifty percent (50%) or more of the\n outstanding shares, or (iii) beneficial ownership of such entity.\n\n \"You\" (or \"Your\") shall mean an individual or Legal Entity\n exercising permissions granted by this License.\n\n \"Source\" form shall mean the preferred form for making modifications,\n including but not limited to software source code, documentation\n source, and configuration files.\n\n \"Object\" form shall mean any form resulting from mechanical\n transformation or translation of a Source form, including but\n not limited to compiled object code, generated documentation,\n and conversions to other media types.\n\n \"Work\" shall mean the work of authorship, whether in Source or\n Object form, made available under the License, as indicated by a\n copyright notice that is included in or attached to the work\n (an example is provided in the Appendix below).\n\n \"Derivative Works\" shall mean any work, whether in Source or Object\n form, that is based on (or derived from) the Work and for which the\n editorial revisions, annotations, elaborations, or other modifications\n represent, as a whole, an original work of authorship. For the purposes\n of this License, Derivative Works shall not include works that remain\n separable from, or merely link (or bind by name) to the interfaces of,\n the Work and Derivative Works thereof.\n\n \"Contribution\" shall mean any work of authorship, including\n the original version of the Work and any modifications or additions\n to that Work or Derivative Works thereof, that is intentionally\n submitted to Licensor for inclusion in the Work by the copyright owner\n or by an individual or Legal Entity authorized to submit on behalf of\n the copyright owner. For the purposes of this definition, \"submitted\"\n means any form of electronic, verbal, or written communication sent\n to the Licensor or its representatives, including but not limited to\n communication on electronic mailing lists, source code control systems,\n and issue tracking systems that are managed by, or on behalf of, the\n Licensor for the purpose of discussing and improving the Work, but\n excluding communication that is conspicuously marked or otherwise\n designated in writing by the copyright owner as \"Not a Contribution.\"\n\n \"Contributor\" shall mean Licensor and any individual or Legal Entity\n on behalf of whom a Contribution has been received by Licensor and\n subsequently incorporated within the Work.\n\n 2. Grant of Copyright License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n copyright license to reproduce, prepare Derivative Works of,\n publicly display, publicly perform, sublicense, and distribute the\n Work and such Derivative Works in Source or Object form.\n\n 3. Grant of Patent License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n (except as stated in this section) patent license to make, have made,\n use, offer to sell, sell, import, and otherwise transfer the Work,\n where such license applies only to those patent claims licensable\n by such Contributor that are necessarily infringed by their\n Contribution(s) alone or by combination of their Contribution(s)\n with the Work to which such Contribution(s) was submitted. If You\n institute patent litigation against any entity (including a\n cross-claim or counterclaim in a lawsuit) alleging that the Work\n or a Contribution incorporated within the Work constitutes direct\n or contributory patent infringement, then any patent licenses\n granted to You under this License for that Work shall terminate\n as of the date such litigation is filed.\n\n 4. Redistribution. You may reproduce and distribute copies of the\n Work or Derivative Works thereof in any medium, with or without\n modifications, and in Source or Object form, provided that You\n meet the following conditions:\n\n (a) You must give any other recipients of the Work or\n Derivative Works a copy of this License; and\n\n (b) You must cause any modified files to carry prominent notices\n stating that You changed the files; and\n\n (c) You must retain, in the Source form of any Derivative Works\n that You distribute, all copyright, patent, trademark, and\n attribution notices from the Source form of the Work,\n excluding those notices that do not pertain to any part of\n the Derivative Works; and\n\n (d) If the Work includes a \"NOTICE\" text file as part of its\n distribution, then any Derivative Works that You distribute must\n include a readable copy of the attribution notices contained\n within such NOTICE file, excluding those notices that do not\n pertain to any part of the Derivative Works, in at least one\n of the following places: within a NOTICE text file distributed\n as part of the Derivative Works; within the Source form or\n documentation, if provided along with the Derivative Works; or,\n within a display generated by the Derivative Works, if and\n wherever such third-party notices normally appear. The contents\n of the NOTICE file are for informational purposes only and\n do not modify the License. You may add Your own attribution\n notices within Derivative Works that You distribute, alongside\n or as an addendum to the NOTICE text from the Work, provided\n that such additional attribution notices cannot be construed\n as modifying the License.\n\n You may add Your own copyright statement to Your modifications and\n may provide additional or different license terms and conditions\n for use, reproduction, or distribution of Your modifications, or\n for any such Derivative Works as a whole, provided Your use,\n reproduction, and distribution of the Work otherwise complies with\n the conditions stated in this License.\n\n 5. Submission of Contributions. Unless You explicitly state otherwise,\n any Contribution intentionally submitted for inclusion in the Work\n by You to the Licensor shall be under the terms and conditions of\n this License, without any additional terms or conditions.\n Notwithstanding the above, nothing herein shall supersede or modify\n the terms of any separate license agreement you may have executed\n with Licensor regarding such Contributions.\n\n 6. Trademarks. This License does not grant permission to use the trade\n names, trademarks, service marks, or product names of the Licensor,\n except as required for reasonable and customary use in describing the\n origin of the Work and reproducing the content of the NOTICE file.\n\n 7. Disclaimer of Warranty. Unless required by applicable law or\n agreed to in writing, Licensor provides the Work (and each\n Contributor provides its Contributions) on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n implied, including, without limitation, any warranties or conditions\n of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n PARTICULAR PURPOSE. You are solely responsible for determining the\n appropriateness of using or redistributing the Work and assume any\n risks associated with Your exercise of permissions under this License.\n\n 8. Limitation of Liability. In no event and under no legal theory,\n whether in tort (including negligence), contract, or otherwise,\n unless required by applicable law (such as deliberate and grossly\n negligent acts) or agreed to in writing, shall any Contributor be\n liable to You for damages, including any direct, indirect, special,\n incidental, or consequential damages of any character arising as a\n result of this License or out of the use or inability to use the\n Work (including but not limited to damages for loss of goodwill,\n work stoppage, computer failure or malfunction, or any and all\n other commercial damages or losses), even if such Contributor\n has been advised of the possibility of such damages.\n\n 9. Accepting Warranty or Additional Liability. While redistributing\n the Work or Derivative Works thereof, You may choose to offer,\n and charge a fee for, acceptance of support, warranty, indemnity,\n or other liability obligations and/or rights consistent with this\n License. However, in accepting such obligations, You may act only\n on Your own behalf and on Your sole responsibility, not on behalf\n of any other Contributor, and only if You agree to indemnify,\n defend, and hold each Contributor harmless for any liability\n incurred by, or claims asserted against, such Contributor by reason\n of your accepting any such warranty or additional liability.\n\n END OF TERMS AND CONDITIONS\n\n APPENDIX: How to apply the Apache License to your work.\n\n To apply the Apache License to your work, attach the following\n boilerplate notice, with the fields enclosed by brackets \"[]\"\n replaced with your own identifying information. (Don't include\n the brackets!) The text should be enclosed in the appropriate\n comment syntax for the file format. We also recommend that a\n file or class name and description of purpose be included on the\n same \"printed page\" as the copyright notice for easier\n identification within third-party archives.\n\n Copyright [yyyy] [name of copyright owner]\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "lru.min",
|
|
36
|
+
"version": "1.1.5",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"notice": "MIT License\n\nCopyright (c) 2024-current Weslley Araújo (@wellwelwel)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"name": "mysql2",
|
|
42
|
+
"version": "3.26.1",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"notice": "Copyright (c) 2016 Andrey Sidorov (sidorares@yandex.ru) and contributors\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "safer-buffer",
|
|
48
|
+
"version": "2.1.2",
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"notice": "MIT License\n\nCopyright (c) 2018 Nikita Skovoroda <chalkerx@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"name": "sql-escaper",
|
|
54
|
+
"version": "1.10.3",
|
|
55
|
+
"license": "MIT",
|
|
56
|
+
"notice": "MIT License\n\nCopyright (c) 2026 Weslley Araújo, Andrey Sidorov, Douglas Wilson, and contributors.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"name": "zod",
|
|
60
|
+
"version": "4.6.7",
|
|
61
|
+
"license": "MIT",
|
|
62
|
+
"notice": "MIT License\n\nCopyright (c) 2025 Colin McDonnell\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SourceFailure } from "@pqe-pro/core/internal/execution/application/source-failure";
|
|
2
|
+
export type MysqlParameter = string | number | boolean | null;
|
|
3
|
+
/** Keep only a driver's SQL error code. Driver errors may include credentials and statement text. */
|
|
4
|
+
export declare class MysqlServerFailure extends SourceFailure {
|
|
5
|
+
readonly serverCode: string;
|
|
6
|
+
constructor(serverCode: string);
|
|
7
|
+
}
|
|
8
|
+
interface ConnectionOptions {
|
|
9
|
+
readonly host: string;
|
|
10
|
+
readonly port: number;
|
|
11
|
+
readonly ca: string;
|
|
12
|
+
readonly database: string;
|
|
13
|
+
readonly user: string;
|
|
14
|
+
readonly password: string;
|
|
15
|
+
readonly connectTimeout: number;
|
|
16
|
+
}
|
|
17
|
+
/** One direct TLS session, one outstanding exchange, and explicit ownership of the raw socket. */
|
|
18
|
+
export declare class MysqlConnection {
|
|
19
|
+
#private;
|
|
20
|
+
readonly ready: Promise<void>;
|
|
21
|
+
constructor({ ca, ...options }: ConnectionOptions);
|
|
22
|
+
get threadId(): number;
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
query(sql: string): Promise<unknown>;
|
|
25
|
+
select(sql: string, parameters: MysqlParameter[], consume: (row: unknown) => void): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { Socket, isIP } from "node:net";
|
|
3
|
+
import { createConnection } from "mysql2";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { SourceFailure } from "@pqe-pro/core/internal/execution/application/source-failure";
|
|
6
|
+
import { deferred } from "@pqe-pro/core/internal/execution/application/task-boundary";
|
|
7
|
+
import { MysqlPacketBudget } from "./packet-budget.js";
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
z.object({ version: z.literal("3.26.1") }).parse(require("mysql2/package.json"));
|
|
10
|
+
const exchangeBytes = 65536;
|
|
11
|
+
function packetParser(value) {
|
|
12
|
+
return (typeof value === "object" &&
|
|
13
|
+
value !== null &&
|
|
14
|
+
typeof Reflect.get(value, "execute") === "function" &&
|
|
15
|
+
typeof Reflect.get(value, "hasPendingData") === "function");
|
|
16
|
+
}
|
|
17
|
+
/** Keep only a driver's SQL error code. Driver errors may include credentials and statement text. */
|
|
18
|
+
export class MysqlServerFailure extends SourceFailure {
|
|
19
|
+
serverCode;
|
|
20
|
+
constructor(serverCode) {
|
|
21
|
+
super("server", "UPSTREAM_ERROR");
|
|
22
|
+
this.serverCode = serverCode;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function driverFailure(error) {
|
|
26
|
+
if (error instanceof SourceFailure) {
|
|
27
|
+
return error;
|
|
28
|
+
}
|
|
29
|
+
if (error instanceof Error) {
|
|
30
|
+
const code = Reflect.get(error, "code");
|
|
31
|
+
const sqlState = Reflect.get(error, "sqlState");
|
|
32
|
+
if (typeof sqlState === "string" && typeof code === "string" && /^ER_[A-Z0-9_]+$/u.test(code)) {
|
|
33
|
+
return new MysqlServerFailure(code);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return new SourceFailure("transport", "UPSTREAM_ERROR");
|
|
37
|
+
}
|
|
38
|
+
/** One direct TLS session, one outstanding exchange, and explicit ownership of the raw socket. */
|
|
39
|
+
export class MysqlConnection {
|
|
40
|
+
#socket = new Socket();
|
|
41
|
+
#closed = deferred();
|
|
42
|
+
#connection;
|
|
43
|
+
#budget;
|
|
44
|
+
#failure;
|
|
45
|
+
#closing = false;
|
|
46
|
+
#rejectPending;
|
|
47
|
+
ready;
|
|
48
|
+
constructor({ ca, ...options }) {
|
|
49
|
+
if (isIP(options.host)) {
|
|
50
|
+
throw new Error("MYSQL_TLS_DNS_NAME_REQUIRED");
|
|
51
|
+
}
|
|
52
|
+
this.#connection = createConnection({
|
|
53
|
+
...options,
|
|
54
|
+
stream: this.#socket,
|
|
55
|
+
ssl: {
|
|
56
|
+
ca,
|
|
57
|
+
rejectUnauthorized: true,
|
|
58
|
+
verifyIdentity: true,
|
|
59
|
+
minVersion: "TLSv1.2",
|
|
60
|
+
},
|
|
61
|
+
charset: "UTF8MB4_BIN",
|
|
62
|
+
compress: false,
|
|
63
|
+
multipleStatements: false,
|
|
64
|
+
flags: ["-LOCAL_FILES", "-MULTI_RESULTS", "-PS_MULTI_RESULTS"],
|
|
65
|
+
disableEval: true,
|
|
66
|
+
jsonStrings: true,
|
|
67
|
+
dateStrings: true,
|
|
68
|
+
supportBigNumbers: true,
|
|
69
|
+
bigNumberStrings: true,
|
|
70
|
+
});
|
|
71
|
+
const parser = Reflect.get(this.#connection, "packetParser");
|
|
72
|
+
if (!packetParser(parser)) {
|
|
73
|
+
this.#connection.destroy();
|
|
74
|
+
this.#socket.destroy();
|
|
75
|
+
throw new Error("UNSUPPORTED_MYSQL_DRIVER_INTERNALS");
|
|
76
|
+
}
|
|
77
|
+
this.#budget = new MysqlPacketBudget(exchangeBytes, (frame) => parser.execute(frame));
|
|
78
|
+
Reflect.set(this.#connection, "packetParser", {
|
|
79
|
+
execute: (chunk) => {
|
|
80
|
+
try {
|
|
81
|
+
this.#budget.push(chunk);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
// Leave the worker socket owned until the independent cleanup path cancels it.
|
|
85
|
+
this.#fail(driverFailure(error));
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
hasPendingData: () => this.#budget.hasPendingData() || parser.hasPendingData(),
|
|
89
|
+
});
|
|
90
|
+
this.#connection.on("error", (error) => this.#fail(driverFailure(error)));
|
|
91
|
+
this.#socket.once("close", () => {
|
|
92
|
+
this.#fail(new SourceFailure("transport", "UPSTREAM_ERROR"));
|
|
93
|
+
this.#closed.resolve(undefined);
|
|
94
|
+
});
|
|
95
|
+
this.ready = this.#exchange((complete) => {
|
|
96
|
+
this.#connection.connect((error) => complete(error, undefined));
|
|
97
|
+
this.#socket.connect(options.port, options.host);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
get threadId() {
|
|
101
|
+
return this.#connection.threadId;
|
|
102
|
+
}
|
|
103
|
+
close() {
|
|
104
|
+
if (!this.#closing) {
|
|
105
|
+
this.#closing = true;
|
|
106
|
+
this.#fail(new SourceFailure("transport", "UPSTREAM_ERROR"));
|
|
107
|
+
this.#connection.destroy();
|
|
108
|
+
this.#socket.destroy();
|
|
109
|
+
}
|
|
110
|
+
return this.#closed.promise;
|
|
111
|
+
}
|
|
112
|
+
query(sql) {
|
|
113
|
+
return this.#exchange((complete) => {
|
|
114
|
+
this.#connection.query(sql, (error, rows) => complete(error, rows));
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
select(sql, parameters, consume) {
|
|
118
|
+
return this.#exchange((complete) => {
|
|
119
|
+
let names;
|
|
120
|
+
const command = this.#connection.execute({ sql, rowsAsArray: true }, parameters);
|
|
121
|
+
// In event mode mysql2 does not append result rows to its internal result arrays.
|
|
122
|
+
command.on("fields", (fields, index) => {
|
|
123
|
+
if (index !== 0 || !fields?.length || names) {
|
|
124
|
+
this.#fail(new SourceFailure("invalid_response", "INVALID_RESULT"));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
names = fields.map((field) => field.name);
|
|
128
|
+
if (new Set(names).size !== names.length) {
|
|
129
|
+
this.#fail(new SourceFailure("invalid_response", "INVALID_RESULT"));
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
command.on("result", (row) => {
|
|
133
|
+
try {
|
|
134
|
+
if (!names || !Array.isArray(row) || row.length !== names.length) {
|
|
135
|
+
throw new SourceFailure("invalid_response", "INVALID_RESULT");
|
|
136
|
+
}
|
|
137
|
+
consume(Object.fromEntries(names.map((name, index) => [name, row[index]])));
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
this.#fail(driverFailure(error));
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
command.on("error", (error) => complete(error, undefined));
|
|
144
|
+
command.once("end", () => complete(null, undefined));
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
#fail(error) {
|
|
148
|
+
this.#failure ??= error;
|
|
149
|
+
this.#budget.discard();
|
|
150
|
+
const reject = this.#rejectPending;
|
|
151
|
+
this.#rejectPending = undefined;
|
|
152
|
+
reject?.(this.#failure);
|
|
153
|
+
}
|
|
154
|
+
#exchange(send) {
|
|
155
|
+
return new Promise((resolve, reject) => {
|
|
156
|
+
if (this.#failure || this.#rejectPending) {
|
|
157
|
+
reject(this.#failure ?? new SourceFailure("transport", "UPSTREAM_ERROR"));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
this.#budget.reset();
|
|
161
|
+
const failed = (error) => reject(error);
|
|
162
|
+
this.#rejectPending = failed;
|
|
163
|
+
const complete = (error, value) => {
|
|
164
|
+
if (this.#rejectPending !== failed) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
this.#rejectPending = undefined;
|
|
168
|
+
if (error) {
|
|
169
|
+
reject(driverFailure(error));
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
resolve(value);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
try {
|
|
176
|
+
send(complete);
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
complete(error, undefined);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Bound an uncompressed exchange before mysql2 retains, assembles or decodes any payload. */
|
|
2
|
+
export declare class MysqlPacketBudget {
|
|
3
|
+
#private;
|
|
4
|
+
constructor(maximum: number, forward: (frame: Buffer) => void);
|
|
5
|
+
hasPendingData(): boolean;
|
|
6
|
+
reset(): void;
|
|
7
|
+
discard(): void;
|
|
8
|
+
push(chunk: Buffer): void;
|
|
9
|
+
}
|