@lunora/hyperdrive 1.0.0-alpha.2 → 1.0.0-alpha.21
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/__assets__/package-og.svg +1 -1
- package/dist/global.mjs +2 -2
- package/dist/index.d.mts +47 -1
- package/dist/index.d.ts +47 -1
- package/dist/index.mjs +1 -0
- package/dist/packem_shared/projectSourceRow-DtKuMRIm.mjs +10 -0
- package/package.json +4 -4
- /package/dist/packem_shared/{buildPgExec-DBbCjyq3.mjs → buildMysqlExec-DBbCjyq3.mjs} +0 -0
- /package/dist/packem_shared/{postgresDialect-oNhZ58s8.mjs → mysqlDialect-oNhZ58s8.mjs} +0 -0
package/dist/global.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createSqlCtxDb } from '@lunora/sql-store';
|
|
2
|
-
import { postgresDialect, mysqlDialect } from './packem_shared/
|
|
3
|
-
import { buildMysqlExec, buildPgExec } from './packem_shared/
|
|
2
|
+
import { postgresDialect, mysqlDialect } from './packem_shared/mysqlDialect-oNhZ58s8.mjs';
|
|
3
|
+
import { buildMysqlExec, buildPgExec } from './packem_shared/buildMysqlExec-DBbCjyq3.mjs';
|
|
4
4
|
|
|
5
5
|
const createHyperdriveGlobalCtxDb = ({ engine, exec, ...rest }) => createSqlCtxDb({ ...rest, dialect: engine === "postgres" ? postgresDialect : mysqlDialect, exec });
|
|
6
6
|
const createPostgresGlobalCtxDb = (client, options) => createHyperdriveGlobalCtxDb({ ...options, engine: "postgres", exec: buildPgExec(client) });
|
package/dist/index.d.mts
CHANGED
|
@@ -71,6 +71,13 @@ interface HyperdriveConnection {
|
|
|
71
71
|
interface SqlClient {
|
|
72
72
|
/**
|
|
73
73
|
* Run a parameterised SQL statement and return the result rows.
|
|
74
|
+
*
|
|
75
|
+
* SECURITY: `text` is executed verbatim — the package never rewrites or
|
|
76
|
+
* escapes it. NEVER interpolate untrusted/user input into `text`; put every
|
|
77
|
+
* value in `params` and reference it with a positional placeholder (`$1`/`?`).
|
|
78
|
+
* Building `text` by string-concatenating request data is a SQL-injection
|
|
79
|
+
* sink against your own Postgres/MySQL. Identifiers (table/column names) can't
|
|
80
|
+
* be parameterised — allowlist them against a fixed set, don't interpolate.
|
|
74
81
|
* @param text SQL text with driver-native positional placeholders.
|
|
75
82
|
* @param params Bound parameter values, positionally matched to `text`.
|
|
76
83
|
* @returns The rows the statement produced (empty for non-`SELECT`s that
|
|
@@ -162,4 +169,43 @@ declare const fromNodePg: (client: NodePgLike) => SqlClient;
|
|
|
162
169
|
* contract the postgres.js / node-postgres adapters already honour.
|
|
163
170
|
*/
|
|
164
171
|
declare const fromMysql2: (connection: Mysql2Like) => SqlClient;
|
|
165
|
-
|
|
172
|
+
/** How an external row maps to a Lunora document. */
|
|
173
|
+
interface ProjectOptions {
|
|
174
|
+
/**
|
|
175
|
+
* Column whose value becomes the Lunora `_id` (stringified). Defaults to `"id"`.
|
|
176
|
+
* With no `map`, this column is dropped from the document body (it lives on as
|
|
177
|
+
* `_id`); with a `map`, the mapper owns the body and `_id` is added from here.
|
|
178
|
+
*/
|
|
179
|
+
idColumn?: string;
|
|
180
|
+
/**
|
|
181
|
+
* Transform an external row into the stored document body. Omit for the default:
|
|
182
|
+
* every selected column except `idColumn` is copied verbatim. The returned object
|
|
183
|
+
* must not include `_id` — it is set from `idColumn`.
|
|
184
|
+
*/
|
|
185
|
+
map?: (row: Record<string, unknown>) => Record<string, unknown>;
|
|
186
|
+
}
|
|
187
|
+
/** Options for {@link pullSourceRows}: the parameterised tenant query plus the row projection. */
|
|
188
|
+
interface PullSourceOptions extends ProjectOptions {
|
|
189
|
+
/** Bound parameter values, positionally matched to `query` (the tenant scope binds here). */
|
|
190
|
+
params?: ReadonlyArray<unknown>;
|
|
191
|
+
/** The full tenant-membership query with driver-native placeholders (`$1` / `?`). */
|
|
192
|
+
query: string;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Project one external row to a Lunora document: lift `idColumn` to a stringified
|
|
196
|
+
* `_id`, then either apply `map` or copy every other column verbatim. Throws when
|
|
197
|
+
* the id column is missing/nullish so a misconfigured query fails loudly rather than
|
|
198
|
+
* materializing rows under an `"undefined"` id.
|
|
199
|
+
*
|
|
200
|
+
* Delegates to `@lunora/do`'s `liftSourceId` — the single id-lift the declarative
|
|
201
|
+
* `.source()` poll loop also uses — so the manual bridge and the codegen path can
|
|
202
|
+
* never diverge in their missing-id handling.
|
|
203
|
+
*/
|
|
204
|
+
declare const projectSourceRow: (row: Record<string, unknown>, options?: ProjectOptions) => Record<string, unknown>;
|
|
205
|
+
/**
|
|
206
|
+
* Run a parameterised tenant query against Hyperdrive and project every row to a
|
|
207
|
+
* Lunora document ready to hand to `materializeExternalRows`. Call this inside an
|
|
208
|
+
* **action** (where `ctx.sql` lives); pass the result to a mutation for the write.
|
|
209
|
+
*/
|
|
210
|
+
declare const pullSourceRows: (sql: SqlClient, options: PullSourceOptions) => Promise<Record<string, unknown>[]>;
|
|
211
|
+
export { type HyperdriveConnection, type HyperdriveLike, type Mysql2Like, type NodePgLike, type PostgresJsLike, type ProjectOptions, type PullSourceOptions, type SqlClient, createHyperdrive, fromMysql2, fromNodePg, fromPostgresJs, projectSourceRow, pullSourceRows };
|
package/dist/index.d.ts
CHANGED
|
@@ -71,6 +71,13 @@ interface HyperdriveConnection {
|
|
|
71
71
|
interface SqlClient {
|
|
72
72
|
/**
|
|
73
73
|
* Run a parameterised SQL statement and return the result rows.
|
|
74
|
+
*
|
|
75
|
+
* SECURITY: `text` is executed verbatim — the package never rewrites or
|
|
76
|
+
* escapes it. NEVER interpolate untrusted/user input into `text`; put every
|
|
77
|
+
* value in `params` and reference it with a positional placeholder (`$1`/`?`).
|
|
78
|
+
* Building `text` by string-concatenating request data is a SQL-injection
|
|
79
|
+
* sink against your own Postgres/MySQL. Identifiers (table/column names) can't
|
|
80
|
+
* be parameterised — allowlist them against a fixed set, don't interpolate.
|
|
74
81
|
* @param text SQL text with driver-native positional placeholders.
|
|
75
82
|
* @param params Bound parameter values, positionally matched to `text`.
|
|
76
83
|
* @returns The rows the statement produced (empty for non-`SELECT`s that
|
|
@@ -162,4 +169,43 @@ declare const fromNodePg: (client: NodePgLike) => SqlClient;
|
|
|
162
169
|
* contract the postgres.js / node-postgres adapters already honour.
|
|
163
170
|
*/
|
|
164
171
|
declare const fromMysql2: (connection: Mysql2Like) => SqlClient;
|
|
165
|
-
|
|
172
|
+
/** How an external row maps to a Lunora document. */
|
|
173
|
+
interface ProjectOptions {
|
|
174
|
+
/**
|
|
175
|
+
* Column whose value becomes the Lunora `_id` (stringified). Defaults to `"id"`.
|
|
176
|
+
* With no `map`, this column is dropped from the document body (it lives on as
|
|
177
|
+
* `_id`); with a `map`, the mapper owns the body and `_id` is added from here.
|
|
178
|
+
*/
|
|
179
|
+
idColumn?: string;
|
|
180
|
+
/**
|
|
181
|
+
* Transform an external row into the stored document body. Omit for the default:
|
|
182
|
+
* every selected column except `idColumn` is copied verbatim. The returned object
|
|
183
|
+
* must not include `_id` — it is set from `idColumn`.
|
|
184
|
+
*/
|
|
185
|
+
map?: (row: Record<string, unknown>) => Record<string, unknown>;
|
|
186
|
+
}
|
|
187
|
+
/** Options for {@link pullSourceRows}: the parameterised tenant query plus the row projection. */
|
|
188
|
+
interface PullSourceOptions extends ProjectOptions {
|
|
189
|
+
/** Bound parameter values, positionally matched to `query` (the tenant scope binds here). */
|
|
190
|
+
params?: ReadonlyArray<unknown>;
|
|
191
|
+
/** The full tenant-membership query with driver-native placeholders (`$1` / `?`). */
|
|
192
|
+
query: string;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Project one external row to a Lunora document: lift `idColumn` to a stringified
|
|
196
|
+
* `_id`, then either apply `map` or copy every other column verbatim. Throws when
|
|
197
|
+
* the id column is missing/nullish so a misconfigured query fails loudly rather than
|
|
198
|
+
* materializing rows under an `"undefined"` id.
|
|
199
|
+
*
|
|
200
|
+
* Delegates to `@lunora/do`'s `liftSourceId` — the single id-lift the declarative
|
|
201
|
+
* `.source()` poll loop also uses — so the manual bridge and the codegen path can
|
|
202
|
+
* never diverge in their missing-id handling.
|
|
203
|
+
*/
|
|
204
|
+
declare const projectSourceRow: (row: Record<string, unknown>, options?: ProjectOptions) => Record<string, unknown>;
|
|
205
|
+
/**
|
|
206
|
+
* Run a parameterised tenant query against Hyperdrive and project every row to a
|
|
207
|
+
* Lunora document ready to hand to `materializeExternalRows`. Call this inside an
|
|
208
|
+
* **action** (where `ctx.sql` lives); pass the result to a mutation for the write.
|
|
209
|
+
*/
|
|
210
|
+
declare const pullSourceRows: (sql: SqlClient, options: PullSourceOptions) => Promise<Record<string, unknown>[]>;
|
|
211
|
+
export { type HyperdriveConnection, type HyperdriveLike, type Mysql2Like, type NodePgLike, type PostgresJsLike, type ProjectOptions, type PullSourceOptions, type SqlClient, createHyperdrive, fromMysql2, fromNodePg, fromPostgresJs, projectSourceRow, pullSourceRows };
|
package/dist/index.mjs
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { liftSourceId } from '@lunora/do';
|
|
2
|
+
|
|
3
|
+
const projectSourceRow = (row, options = {}) => liftSourceId(row, options);
|
|
4
|
+
const pullSourceRows = async (sql, options) => {
|
|
5
|
+
const { idColumn, map, params, query } = options;
|
|
6
|
+
const rows = await sql.query(query, params);
|
|
7
|
+
return rows.map((row) => projectSourceRow(row, { idColumn, map }));
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { projectSourceRow, pullSourceRows };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/hyperdrive",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.21",
|
|
4
4
|
"description": "Bring-your-own Postgres/MySQL for Lunora via Cloudflare Hyperdrive: a driver-agnostic, action-only ctx.sql",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"directory": "packages/hyperdrive"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
-
"dist",
|
|
28
|
+
"./dist",
|
|
29
29
|
"README.md",
|
|
30
30
|
"LICENSE.md",
|
|
31
31
|
"__assets__"
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@lunora/do": "1.0.0-alpha.
|
|
54
|
-
"@lunora/sql-store": "1.0.0-alpha.
|
|
53
|
+
"@lunora/do": "1.0.0-alpha.21",
|
|
54
|
+
"@lunora/sql-store": "1.0.0-alpha.21",
|
|
55
55
|
"drizzle-orm": "^0.45.2"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
File without changes
|
|
File without changes
|