@lunora/hyperdrive 1.0.0-alpha.22 → 1.0.0-alpha.220
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.md +6 -0
- package/README.md +77 -16
- package/dist/global.d.mts +236 -49
- package/dist/global.d.ts +236 -49
- package/dist/global.mjs +1 -9
- package/dist/index.d.mts +135 -182
- package/dist/index.d.ts +135 -182
- package/dist/index.mjs +1 -2
- package/dist/packem_shared/buildMysqlExec-PqvV5h4p.mjs +1 -0
- package/dist/packem_shared/createHyperdrive-DWZZ_3e2.mjs +1 -0
- package/dist/packem_shared/createPgVectorIndex-B2Wbzqns.mjs +1 -0
- package/dist/packem_shared/mysql-params-D4Ijlvo5.mjs +1 -0
- package/dist/packem_shared/mysqlDialect-BS1Sz60B.mjs +1 -0
- package/dist/packem_shared/projectSourceRow-DN8ywPRl.mjs +1 -0
- package/dist/packem_shared/types.d-Zm06MRhL.d.mts +170 -0
- package/dist/packem_shared/types.d-Zm06MRhL.d.ts +170 -0
- package/package.json +6 -4
- package/dist/packem_shared/buildMysqlExec-DBbCjyq3.mjs +0 -23
- package/dist/packem_shared/createHyperdrive-DD8GoDZo.mjs +0 -36
- package/dist/packem_shared/mysqlDialect-oNhZ58s8.mjs +0 -102
- package/dist/packem_shared/projectSourceRow-DtKuMRIm.mjs +0 -10
package/dist/global.d.ts
CHANGED
|
@@ -1,47 +1,169 @@
|
|
|
1
|
-
import { DatabaseWriterLike } from '@lunora/do';
|
|
2
|
-
import { SqlExec, SqlDialect, SqlCtxDbOptions } from '@lunora/sql-store';
|
|
3
|
-
/** Minimal row-returning client (e.g. `@lunora/hyperdrive`'s `fromPostgresJs`/`fromNodePg` result). */
|
|
4
|
-
interface RowClient {
|
|
5
|
-
query: <Row = Record<string, unknown>>(text: string, params?: ReadonlyArray<unknown>) => Promise<Row[]>;
|
|
6
|
-
}
|
|
7
|
-
/** Minimal `mysql2/promise` connection/pool surface — `execute` resolves to `[rows | ResultSetHeader, fields]`. */
|
|
8
|
-
interface Mysql2Execute {
|
|
9
|
-
execute: (text: string, params?: ReadonlyArray<unknown>) => Promise<[unknown, unknown]>;
|
|
10
|
-
}
|
|
11
1
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
2
|
+
* `@lunora/hyperdrive/global` — a Postgres/MySQL database reached through
|
|
3
|
+
* Cloudflare Hyperdrive (PlanetScale, Neon, RDS, …) as a **first-class,
|
|
4
|
+
* reactive** `.global()` storage backend for Lunora, alongside D1.
|
|
5
|
+
*
|
|
6
|
+
* Unlike the package's `ctx.sql` surface (an action-only, non-reactive escape
|
|
7
|
+
* hatch for an external DB), this makes Lunora the **owner** of the schema:
|
|
8
|
+
* `.global()` tables get a real column-per-field layout and all writes route
|
|
9
|
+
* through the shared store core (`createSqlCtxDb` from `@lunora/sql-store`) with
|
|
10
|
+
* a Postgres or MySQL {@link postgresDialect}/{@link mysqlDialect} and a
|
|
11
|
+
* Hyperdrive-backed {@link SqlExec}. The returned `DatabaseWriterLike` is
|
|
12
|
+
* injected as `globalDb` into `createShardCtxDb`, whose broadcast hook drives
|
|
13
|
+
* live queries — so subscriptions stay reactive with zero extra wiring,
|
|
14
|
+
* identical to D1.
|
|
15
|
+
*
|
|
16
|
+
* Drivers (`postgres`/`pg`/`mysql2`) are optional peer deps — bring your own,
|
|
17
|
+
* constructed from the `HYPERDRIVE` binding's connection string. The binding is
|
|
18
|
+
* reachable from inside the Durable Object that hosts the writer; cache the
|
|
19
|
+
* driver on the DO instance and rebuild it lazily after hibernation.
|
|
20
|
+
*
|
|
21
|
+
* **MySQL connections must enable `CLIENT_FOUND_ROWS`** (mysql2:
|
|
22
|
+
* `createPool({ flags: ["FOUND_ROWS"] })`) so the affected-rows OCC guard sees
|
|
23
|
+
* matched (not changed) rows — see {@link buildMysqlExec}.
|
|
24
|
+
*
|
|
25
|
+
* **The Hyperdrive config must have query caching disabled**
|
|
26
|
+
* (`wrangler hyperdrive create … --caching-disabled`). Hyperdrive caches reads by
|
|
27
|
+
* default and a write does not invalidate them, so OCC re-reads, change-log polls
|
|
28
|
+
* and live-query re-runs would read rows up to `max_age + stale_while_revalidate`
|
|
29
|
+
* old.
|
|
30
|
+
*/
|
|
31
|
+
import { SchemaLike, ImportConflictMode, CdcChange, DatabaseWriterLike } from '@lunora/shard-engine';
|
|
32
|
+
import { SqlExec, SqlDialect, SqlCtxDbOptions, FacetGlobalColumnOptions, GlobalFacetResult, GlobalTableInfo, ReadGlobalTablePageOptions, GlobalTablePage, ExportRow, ImportResult } from '@lunora/sql-store';
|
|
33
|
+
import { M as Mysql2Like, S as SqlClient } from "./packem_shared/types.d-Zm06MRhL.js";
|
|
34
|
+
import { VectorMetric, VectorizeIndexLike } from '@lunora/platform';
|
|
35
|
+
/**
|
|
36
|
+
* Minimal row-returning client (e.g. `@lunora/hyperdrive`'s `fromPostgresJs`/`fromNodePg`
|
|
37
|
+
* result). Aliases {@link SqlClient} — the exec-facing name is kept so call sites read
|
|
38
|
+
* intent, but the shape is the single source of truth in `./types` (no drift).
|
|
39
|
+
*/
|
|
40
|
+
type RowClient = SqlClient;
|
|
41
|
+
/**
|
|
42
|
+
* Minimal `mysql2/promise` connection/pool surface — `query` resolves to
|
|
43
|
+
* `[rows | ResultSetHeader, fields]`. Aliases {@link Mysql2Like} so the /global
|
|
44
|
+
* entry's driver surface can never drift from the main entry's, widened with the
|
|
45
|
+
* (optional, structural) shape {@link assertFoundRows}'s `CLIENT_FOUND_ROWS`
|
|
46
|
+
* probe reads.
|
|
47
|
+
*
|
|
48
|
+
* A real `mysql2/promise` connection/pool exposes the merged client-flags
|
|
49
|
+
* bitmask synchronously, but at two different depths depending on which one it
|
|
50
|
+
* is, and NEITHER is in `mysql2`'s own `.d.ts` — its `Pool extends Connection`
|
|
51
|
+
* signature claims a top-level `config`, but at runtime a `mysql2/promise`
|
|
52
|
+
* `Pool` has none; the real value lives one level down, on the core pool it
|
|
53
|
+
* wraps:
|
|
54
|
+
*
|
|
55
|
+
* - a single `Connection`/`PoolConnection` → `connection.config.clientFlags`
|
|
56
|
+
* - a `Pool` (the `createPool({ flags: ["FOUND_ROWS"] })` example above) →
|
|
57
|
+
* `pool.pool.config.connectionConfig.clientFlags`
|
|
58
|
+
*
|
|
59
|
+
* Because those paths are undocumented driver internals, `global-dialect.test.ts`
|
|
60
|
+
* pins them against a REAL `mysql2` pool (built without connecting) rather than
|
|
61
|
+
* only against hand-written doubles — if a `mysql2` release relocates them, the
|
|
62
|
+
* probe would otherwise degrade silently to the warn branch and the OCC guard
|
|
63
|
+
* would go unchecked.
|
|
64
|
+
*
|
|
65
|
+
* The probe fields are typed `unknown` publicly: the paths are not in `mysql2`'s
|
|
66
|
+
* typings, so spelling them out made a real `createPool(...)` fail to type-check
|
|
67
|
+
* (TS2345, weak-type mismatch on `config`). {@link readMysqlClientFlags} reads
|
|
68
|
+
* them through the internal `FlagProbeShape` instead, and a minimal test double
|
|
69
|
+
* (only `query`) resolves to "undeterminable" rather than a `TypeError`.
|
|
70
|
+
*/
|
|
71
|
+
type Mysql2Client = Mysql2Like & {
|
|
72
|
+
config?: unknown;
|
|
73
|
+
pool?: unknown;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Wrap a Postgres row-client (from `@lunora/hyperdrive`'s `fromPostgresJs` /
|
|
77
|
+
* `fromNodePg`) as a {@link SqlExec}. The core already renders `$N` placeholders
|
|
78
|
+
* for Postgres, so `all`/`run` forward verbatim. Postgres uses `RETURNING` for
|
|
79
|
+
* OCC (read via `all`), so `run` reports no affected-row count.
|
|
80
|
+
*
|
|
81
|
+
* `batch` dispatches every statement concurrently (`Promise.all`) over `client`
|
|
82
|
+
* rather than awaiting each `query` call in turn — `RowClient` only exposes a
|
|
83
|
+
* single-statement `query`, so there is no wire-level multi-statement command
|
|
84
|
+
* to reach for. When `client` is backed by a pool (the common production
|
|
85
|
+
* shape), this genuinely spreads the statements across multiple physical
|
|
86
|
+
* connections instead of serializing one full round trip at a time; against a
|
|
87
|
+
* single connection it still removes the sequential *await*, though the
|
|
88
|
+
* underlying driver may itself queue the sends. Either way it stays
|
|
89
|
+
* non-atomic, at-least-once, and unordered between elements, same as the
|
|
90
|
+
* sequential fallback minus the ordering — safe only for statements whose
|
|
91
|
+
* effects don't depend on each other, which is what every current caller
|
|
92
|
+
* batches (distinct-keyed companion rows).
|
|
93
|
+
*/
|
|
17
94
|
declare const buildPgExec: (client: RowClient) => SqlExec;
|
|
18
95
|
/**
|
|
19
|
-
* Wrap a `mysql2/promise` connection/pool as a {@link SqlExec}. The core already
|
|
20
|
-
* renders backtick identifiers and `?` placeholders for MySQL, so `all`/`run`
|
|
21
|
-
* forward verbatim. MySQL has no `RETURNING`, so `run` surfaces `affectedRows`
|
|
22
|
-
* for the store's affected-rows OCC guard.
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
96
|
+
* Wrap a `mysql2/promise` connection/pool as a {@link SqlExec}. The core already
|
|
97
|
+
* renders backtick identifiers and `?` placeholders for MySQL, so `all`/`run`
|
|
98
|
+
* forward verbatim. MySQL has no `RETURNING`, so `run` surfaces `affectedRows`
|
|
99
|
+
* for the store's affected-rows OCC guard.
|
|
100
|
+
*
|
|
101
|
+
* Statements go over as text with client-side escaping, so the server must not
|
|
102
|
+
* run with `NO_BACKSLASH_ESCAPES` (see {@link Mysql2Like}).
|
|
103
|
+
*
|
|
104
|
+
* **The connection MUST be created with the `CLIENT_FOUND_ROWS` flag**
|
|
105
|
+
* (mysql2: `createPool({ flags: ["FOUND_ROWS"] })`). Without it, `affectedRows`
|
|
106
|
+
* counts *changed* rows, so an idempotent `patch`/`replace` that re-writes the
|
|
107
|
+
* same values reports 0 and the OCC guard raises a spurious conflict. Verified
|
|
108
|
+
* once here at construction — see {@link assertFoundRows} — never per statement.
|
|
109
|
+
*
|
|
110
|
+
* `batch` dispatches every statement concurrently (`Promise.all`), same
|
|
111
|
+
* rationale as {@link buildPgExec}'s `batch` — `Mysql2Like` only exposes a
|
|
112
|
+
* single-statement `query`, so this is "spread across a pool's connections"
|
|
113
|
+
* rather than one wire-level multi-statement command; still non-atomic,
|
|
114
|
+
* at-least-once, and unordered between elements, safe only for statements
|
|
115
|
+
* with no cross-effect (what every current caller batches).
|
|
116
|
+
*/
|
|
117
|
+
declare const buildMysqlExec: (connection: Mysql2Client) => SqlExec;
|
|
30
118
|
/**
|
|
31
|
-
* **Postgres** dialect. Differs from SQLite only in column types
|
|
32
|
-
* (`DOUBLE PRECISION`/`BYTEA`/`BIGSERIAL`), the `information_schema` catalog
|
|
33
|
-
* probe, and unique-violation detection (SQLSTATE `23505`).
|
|
34
|
-
*/
|
|
119
|
+
* **Postgres** dialect. Differs from SQLite only in column types
|
|
120
|
+
* (`DOUBLE PRECISION`/`BYTEA`/`BIGSERIAL`), the `information_schema` catalog
|
|
121
|
+
* probe, and unique-violation detection (SQLSTATE `23505`).
|
|
122
|
+
*/
|
|
35
123
|
declare const postgresDialect: SqlDialect;
|
|
36
124
|
/**
|
|
37
|
-
* **MySQL** dialect. Diverges in: **no `RETURNING`** (the store's OCC falls back
|
|
38
|
-
* to affected-rows — which requires the connection's `CLIENT_FOUND_ROWS` flag so
|
|
39
|
-
* a no-op update still reports a matched row, see `buildMysqlExec`); bounded
|
|
40
|
-
* `VARCHAR` keys (TEXT can't be a primary key / unindexed); a TEXT/BLOB index key
|
|
41
|
-
* prefix; and `ER_DUP_ENTRY` (errno 1062) unique violations. (Drizzle's MySQL
|
|
42
|
-
* dialect supplies the backtick identifiers + `ON DUPLICATE KEY` upserts.)
|
|
43
|
-
*/
|
|
125
|
+
* **MySQL** dialect. Diverges in: **no `RETURNING`** (the store's OCC falls back
|
|
126
|
+
* to affected-rows — which requires the connection's `CLIENT_FOUND_ROWS` flag so
|
|
127
|
+
* a no-op update still reports a matched row, see `buildMysqlExec`); bounded
|
|
128
|
+
* `VARCHAR` keys (TEXT can't be a primary key / unindexed); a TEXT/BLOB index key
|
|
129
|
+
* prefix; and `ER_DUP_ENTRY` (errno 1062) unique violations. (Drizzle's MySQL
|
|
130
|
+
* dialect supplies the backtick identifiers + `ON DUPLICATE KEY` upserts.)
|
|
131
|
+
*/
|
|
44
132
|
declare const mysqlDialect: SqlDialect;
|
|
133
|
+
/** Options for {@link createPgVectorIndex}. */
|
|
134
|
+
interface PgVectorIndexOptions {
|
|
135
|
+
/** Postgres client — the same `SqlClient` the Hyperdrive global store takes. */
|
|
136
|
+
client: SqlClient;
|
|
137
|
+
/**
|
|
138
|
+
* Vector width. Must match the embedder's output and the `dimensions` on the
|
|
139
|
+
* schema's `.vectorize(...)`; Postgres enforces it per row, so a mismatch
|
|
140
|
+
* surfaces as a write error rather than silently bad neighbours.
|
|
141
|
+
*/
|
|
142
|
+
dimensions: number;
|
|
143
|
+
/** Distance metric. Defaults to `"cosine"`, matching the common embedding case. */
|
|
144
|
+
metric?: VectorMetric;
|
|
145
|
+
/**
|
|
146
|
+
* Names the backing table (`__vec_<name>`), derived rather than configurable —
|
|
147
|
+
* a second name for one index is a way to lose data, not a feature.
|
|
148
|
+
*
|
|
149
|
+
* This is NOT required to equal the key in the shard's `vectors` map, and often
|
|
150
|
+
* cannot: that key mirrors the schema's `.vectorize({ index })`, which may carry
|
|
151
|
+
* hyphens (`"docs-body"`), while this must be a bare SQL identifier. Keep it
|
|
152
|
+
* stable — changing it points the index at a different, empty table.
|
|
153
|
+
*/
|
|
154
|
+
name: string;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Build a `pgvector`-backed vector index that satisfies {@link VectorizeIndexLike}.
|
|
158
|
+
*
|
|
159
|
+
* Requires the `vector` extension to be installable by the connecting role
|
|
160
|
+
* (`CREATE EXTENSION IF NOT EXISTS vector`). On a managed Postgres where the
|
|
161
|
+
* role cannot create extensions, install it once out-of-band; the statement is
|
|
162
|
+
* then a no-op.
|
|
163
|
+
* @param options See {@link PgVectorIndexOptions}.
|
|
164
|
+
* @returns An index object the shard's `vectors` map accepts as-is.
|
|
165
|
+
*/
|
|
166
|
+
declare const createPgVectorIndex: (options: PgVectorIndexOptions) => VectorizeIndexLike;
|
|
45
167
|
/** Which engine a Hyperdrive-backed `.global()` store targets. */
|
|
46
168
|
type HyperdriveEngine = "mysql" | "postgres";
|
|
47
169
|
/** Options for {@link createHyperdriveGlobalCtxDb}: the store options minus `exec`/`dialect`, plus the engine and a built `SqlExec`. */
|
|
@@ -52,18 +174,83 @@ interface CreateHyperdriveGlobalCtxDbOptions extends Omit<SqlCtxDbOptions, "dial
|
|
|
52
174
|
exec: SqlExec;
|
|
53
175
|
}
|
|
54
176
|
/**
|
|
55
|
-
* Build a reactive `.global()` writer backed by a Hyperdrive-reachable
|
|
56
|
-
* Postgres/MySQL database. Pass a built {@link SqlExec} (via {@link buildPgExec}/
|
|
57
|
-
* {@link buildMysqlExec}) and the matching `engine`; everything else mirrors the
|
|
58
|
-
* D1 store options.
|
|
59
|
-
*/
|
|
60
|
-
declare const createHyperdriveGlobalCtxDb: ({
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
177
|
+
* Build a reactive `.global()` writer backed by a Hyperdrive-reachable
|
|
178
|
+
* Postgres/MySQL database. Pass a built {@link SqlExec} (via {@link buildPgExec}/
|
|
179
|
+
* {@link buildMysqlExec}) and the matching `engine`; everything else mirrors the
|
|
180
|
+
* D1 store options.
|
|
181
|
+
*/
|
|
182
|
+
declare const createHyperdriveGlobalCtxDb: ({ engine, exec, ...rest }: CreateHyperdriveGlobalCtxDbOptions) => DatabaseWriterLike;
|
|
183
|
+
/** Options for {@link exportHyperdriveGlobalRows}. */
|
|
184
|
+
interface ExportHyperdriveGlobalRowsOptions {
|
|
185
|
+
engine: HyperdriveEngine;
|
|
186
|
+
exec: SqlExec;
|
|
187
|
+
schema: SchemaLike;
|
|
188
|
+
/** Table allowlist; empty or absent exports every `.global()` table. */
|
|
189
|
+
tables?: ReadonlyArray<string>;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The admin export's global plane on Hyperdrive: yield every requested
|
|
193
|
+
* `.global()` table's rows, keyset-paged. Provisions the schema's tables first,
|
|
194
|
+
* so a table that was never written exports as empty instead of failing.
|
|
195
|
+
*/
|
|
196
|
+
declare const exportHyperdriveGlobalRows: ({ engine, exec, schema, tables }: ExportHyperdriveGlobalRowsOptions) => AsyncGenerator<ExportRow, void, undefined>;
|
|
197
|
+
/** Options for {@link importHyperdriveGlobalRows}. */
|
|
198
|
+
interface ImportHyperdriveGlobalRowsOptions {
|
|
199
|
+
/** Append each insert to the global CDC log, like any other write — the app's own `cdc` setting. */
|
|
200
|
+
cdc: boolean;
|
|
201
|
+
/** Validate and report shape errors only; nothing is probed or written. */
|
|
202
|
+
dryRun?: boolean;
|
|
203
|
+
engine: HyperdriveEngine;
|
|
204
|
+
exec: SqlExec;
|
|
205
|
+
/** `"replace"` overwrites a row whose `_id` already exists; `"skip"` (the default) counts it as a conflict. */
|
|
206
|
+
onConflict?: ImportConflictMode;
|
|
207
|
+
rows: ReadonlyArray<ExportRow>;
|
|
208
|
+
schema: SchemaLike;
|
|
209
|
+
startLine?: number;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* The admin import's global plane on Hyperdrive: insert snapshot rows through
|
|
213
|
+
* the same store core `.global()` writes use. A row whose `_id` already exists
|
|
214
|
+
* is a conflict left unchanged, unless `onConflict` is `"replace"`.
|
|
215
|
+
*/
|
|
216
|
+
declare const importHyperdriveGlobalRows: ({ cdc, dryRun, engine, exec, onConflict, rows, schema, startLine }: ImportHyperdriveGlobalRowsOptions) => Promise<ImportResult>;
|
|
65
217
|
/** Convenience: a **Postgres** `.global()` writer from a row-client (postgres.js/pg over Hyperdrive). */
|
|
66
218
|
declare const createPostgresGlobalCtxDb: (client: RowClient, options: Omit<CreateHyperdriveGlobalCtxDbOptions, "engine" | "exec">) => DatabaseWriterLike;
|
|
67
219
|
/** Convenience: a **MySQL** `.global()` writer from a `mysql2/promise` connection/pool (created with `flags: ["FOUND_ROWS"]`). */
|
|
68
|
-
declare const createMysqlGlobalCtxDb: (connection:
|
|
69
|
-
|
|
220
|
+
declare const createMysqlGlobalCtxDb: (connection: Mysql2Client, options: Omit<CreateHyperdriveGlobalCtxDbOptions, "engine" | "exec">) => DatabaseWriterLike;
|
|
221
|
+
/** The studio's global data browser over a Hyperdrive database — every table in the connection's schema, internal ones hidden. */
|
|
222
|
+
interface HyperdriveGlobalIntrospector {
|
|
223
|
+
facetColumn: (options: FacetGlobalColumnOptions) => Promise<GlobalFacetResult>;
|
|
224
|
+
listTables: () => Promise<GlobalTableInfo[]>;
|
|
225
|
+
readTablePage: (options: ReadGlobalTablePageOptions) => Promise<GlobalTablePage>;
|
|
226
|
+
}
|
|
227
|
+
/** Build the studio's global-browser introspector for a Hyperdrive `.global()` store. */
|
|
228
|
+
declare const createHyperdriveGlobalIntrospector: (engine: HyperdriveEngine, exec: SqlExec, schema: SchemaLike) => HyperdriveGlobalIntrospector;
|
|
229
|
+
/**
|
|
230
|
+
* The admin CDC sync's global plane on Hyperdrive: a page of the global
|
|
231
|
+
* `__cdc_log` past `sinceSeq`. The log only exists once a CDC-enabled writer has
|
|
232
|
+
* run, so its absence is "nothing has changed yet" — an empty page that leaves
|
|
233
|
+
* the cursor where it was — not an error.
|
|
234
|
+
*/
|
|
235
|
+
declare const readHyperdriveGlobalCdc: (engine: HyperdriveEngine, exec: SqlExec, request: {
|
|
236
|
+
limit?: number;
|
|
237
|
+
now?: number;
|
|
238
|
+
sinceSeq: number;
|
|
239
|
+
}) => Promise<{
|
|
240
|
+
changes: CdcChange[];
|
|
241
|
+
cursor: number;
|
|
242
|
+
}>;
|
|
243
|
+
/**
|
|
244
|
+
* The admin point-in-time apply's global plane on Hyperdrive: replay CDC changes
|
|
245
|
+
* in order through the store core (insert, falling back to replace). The writer
|
|
246
|
+
* carries the app's `cdc` setting so the replay appends to the global changelog
|
|
247
|
+
* like any other write. Returns the number replayed.
|
|
248
|
+
*/
|
|
249
|
+
declare const applyHyperdriveGlobalCdc: (options: {
|
|
250
|
+
cdc: boolean;
|
|
251
|
+
changes: ReadonlyArray<CdcChange>;
|
|
252
|
+
engine: HyperdriveEngine;
|
|
253
|
+
exec: SqlExec;
|
|
254
|
+
schema: SchemaLike;
|
|
255
|
+
}) => Promise<number>;
|
|
256
|
+
export { CreateHyperdriveGlobalCtxDbOptions, ExportHyperdriveGlobalRowsOptions, HyperdriveEngine, HyperdriveGlobalIntrospector, ImportHyperdriveGlobalRowsOptions, type Mysql2Client, type PgVectorIndexOptions, type RowClient, applyHyperdriveGlobalCdc, buildMysqlExec, buildPgExec, createHyperdriveGlobalCtxDb, createHyperdriveGlobalIntrospector, createMysqlGlobalCtxDb, createPgVectorIndex, createPostgresGlobalCtxDb, exportHyperdriveGlobalRows, importHyperdriveGlobalRows, mysqlDialect, postgresDialect, readHyperdriveGlobalCdc };
|
package/dist/global.mjs
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { postgresDialect, mysqlDialect } from './packem_shared/mysqlDialect-oNhZ58s8.mjs';
|
|
3
|
-
import { buildMysqlExec, buildPgExec } from './packem_shared/buildMysqlExec-DBbCjyq3.mjs';
|
|
4
|
-
|
|
5
|
-
const createHyperdriveGlobalCtxDb = ({ engine, exec, ...rest }) => createSqlCtxDb({ ...rest, dialect: engine === "postgres" ? postgresDialect : mysqlDialect, exec });
|
|
6
|
-
const createPostgresGlobalCtxDb = (client, options) => createHyperdriveGlobalCtxDb({ ...options, engine: "postgres", exec: buildPgExec(client) });
|
|
7
|
-
const createMysqlGlobalCtxDb = (connection, options) => createHyperdriveGlobalCtxDb({ ...options, engine: "mysql", exec: buildMysqlExec(connection) });
|
|
8
|
-
|
|
9
|
-
export { buildMysqlExec, buildPgExec, createHyperdriveGlobalCtxDb, createMysqlGlobalCtxDb, createPostgresGlobalCtxDb, mysqlDialect, postgresDialect };
|
|
1
|
+
import{applyCdcChanges as d,CDC_LOG_TABLE as b}from"@lunora/shard-engine";import{createSqlCtxDb as p,readSqlGlobalTablePage as g,listSqlGlobalTables as m,facetSqlGlobalColumn as y,exportSqlGlobalRows as C,importSqlGlobalRows as G,readSqlCdcChanges as x}from"@lunora/sql-store";import{postgresDialect as q,mysqlDialect as u}from"./packem_shared/mysqlDialect-BS1Sz60B.mjs";import{buildMysqlExec as f,buildPgExec as v}from"./packem_shared/buildMysqlExec-PqvV5h4p.mjs";import{createPgVectorIndex as A}from"./packem_shared/createPgVectorIndex-B2Wbzqns.mjs";const o=e=>e==="postgres"?q:u,c=({engine:e,exec:l,...r})=>p({...r,dialect:o(e),exec:l}),H=({engine:e,exec:l,schema:r,tables:t})=>C(l,r,o(e),t===void 0?{}:{tables:t}),P=({cdc:e,dryRun:l,engine:r,exec:t,onConflict:a,rows:s,schema:n,startLine:i})=>G(c({cdc:e,engine:r,exec:t,schema:n}),n,o(r),{dryRun:l===!0,exec:t,onConflict:a??"skip",rows:s,...i===void 0?{}:{startLine:i}}),R=(e,l)=>c({...l,engine:"postgres",exec:v(e)}),T=(e,l)=>c({...l,engine:"mysql",exec:f(e)}),E=(e,l,r)=>{const t=o(e);return{facetColumn:a=>y(l,r,t,a),listTables:()=>m(l,r,t),readTablePage:a=>g(l,r,t,a)}},I=async(e,l,r)=>{const t=o(e),{params:a,sql:s}=t.render(t.tableExists(b));return(await l.all(s,a)).length===0?{changes:[],cursor:r.sinceSeq}:x(l,r,t)},M=async e=>(await d(c({cdc:e.cdc,engine:e.engine,exec:e.exec,schema:e.schema}),e.changes),e.changes.length);export{M as applyHyperdriveGlobalCdc,f as buildMysqlExec,v as buildPgExec,c as createHyperdriveGlobalCtxDb,E as createHyperdriveGlobalIntrospector,T as createMysqlGlobalCtxDb,A as createPgVectorIndex,R as createPostgresGlobalCtxDb,H as exportHyperdriveGlobalRows,P as importHyperdriveGlobalRows,u as mysqlDialect,q as postgresDialect,I as readHyperdriveGlobalCdc};
|