@lunora/hyperdrive 1.0.0-alpha.40 → 1.0.0-alpha.41

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/dist/global.mjs CHANGED
@@ -1,9 +1 @@
1
- import { createSqlCtxDb } from '@lunora/sql-store';
2
- import { postgresDialect, mysqlDialect } from './packem_shared/mysqlDialect-BHz03Grz.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{createSqlCtxDb as o}from"@lunora/sql-store";import{postgresDialect as c,mysqlDialect as s}from"./packem_shared/mysqlDialect-Cgs6NC98.mjs";import{buildMysqlExec as i,buildPgExec as x}from"./packem_shared/buildMysqlExec-uTTy5Tv3.mjs";const r=({engine:e,exec:t,...l})=>o({...l,dialect:e==="postgres"?c:s,exec:t}),m=(e,t)=>r({...t,engine:"postgres",exec:x(e)}),p=(e,t)=>r({...t,engine:"mysql",exec:i(e)});export{i as buildMysqlExec,x as buildPgExec,r as createHyperdriveGlobalCtxDb,p as createMysqlGlobalCtxDb,m as createPostgresGlobalCtxDb,s as mysqlDialect,c as postgresDialect};
package/dist/index.mjs CHANGED
@@ -1,2 +1 @@
1
- export { createHyperdrive, fromMysql2, fromNodePg, fromPostgresJs } from './packem_shared/createHyperdrive-DD8GoDZo.mjs';
2
- export { projectSourceRow, pullSourceRows } from './packem_shared/projectSourceRow-DtKuMRIm.mjs';
1
+ import{createHyperdrive as e,fromMysql2 as f,fromNodePg as m,fromPostgresJs as p}from"./packem_shared/createHyperdrive-DCe1WINF.mjs";import{projectSourceRow as t,pullSourceRows as c}from"./packem_shared/projectSourceRow-BjF0PLdx.mjs";export{e as createHyperdrive,f as fromMysql2,m as fromNodePg,p as fromPostgresJs,t as projectSourceRow,c as pullSourceRows};
@@ -0,0 +1 @@
1
+ const s=c=>({all:(e,t)=>c.query(e,t),run:async(e,t)=>(await c.query(e,t),{rowsAffected:0})}),n=c=>({all:async(e,t)=>{const[a]=await c.execute(e,t);return a},run:async(e,t)=>{const[a]=await c.execute(e,t);return{rowsAffected:a.affectedRows??0}}});export{n as buildMysqlExec,s as buildPgExec};
@@ -0,0 +1 @@
1
+ const o=e=>({config:{database:e.database,host:e.host,password:e.password,port:e.port,user:e.user},connectionString:e.connectionString}),t=e=>({query:async(r,s=[])=>await e.unsafe(r,s)}),n=e=>({query:async(r,s=[])=>(await e.query(r,s)).rows}),c=e=>({query:async(r,s=[])=>{const[a]=await e.execute(r,s);return Array.isArray(a)?a:[]}});export{o as createHyperdrive,c as fromMysql2,n as fromNodePg,t as fromPostgresJs};
@@ -0,0 +1 @@
1
+ import{sqliteEncode as n,sqliteDecode as r}from"@lunora/sql-store";import{sql as s}from"drizzle-orm";const o=/duplicate key value violates unique constraint/iu,a=e=>{switch(e){case"array":case"object":case"record":return"JSON";case"bigint":return"VARCHAR(64)";case"boolean":return"TINYINT";case"bytes":return"LONGBLOB";case"date":case"number":case"timestamp":return"DOUBLE";default:return"LONGTEXT"}},c=/TEXT|BLOB/u,m={companionTypes:{autoincrementPrimaryKey:"BIGSERIAL PRIMARY KEY",integer:"INTEGER",key:"TEXT",real:"DOUBLE PRECISION",text:"TEXT"},columnType:e=>{switch(e){case"boolean":return"INTEGER";case"bytes":return"BYTEA";case"date":case"number":case"timestamp":return"DOUBLE PRECISION";default:return"TEXT"}},decode:(e,t)=>r(e,t),encode:e=>n(e),frameworkColumns:()=>[{name:"id",type:"TEXT PRIMARY KEY"},{name:"_creationTime",type:"DOUBLE PRECISION NOT NULL"}],isUniqueViolation:e=>{const{code:t}=e;return t==="23505"||e instanceof Error&&o.test(e.message)},name:"postgres",supportsReturning:!0,tableExists:e=>s`SELECT table_name FROM information_schema.tables WHERE table_schema = ANY (current_schemas(false)) AND table_name = ${e}`},u={affectedRows:e=>e.rowsAffected,companionTypes:{autoincrementPrimaryKey:"BIGINT AUTO_INCREMENT PRIMARY KEY",integer:"INTEGER",key:"VARCHAR(768)",real:"DOUBLE",text:"LONGTEXT"},columnType:e=>a(e),decode:(e,t)=>r(e,t),encode:e=>n(e),frameworkColumns:()=>[{name:"id",type:"VARCHAR(768) PRIMARY KEY"},{name:"_creationTime",type:"DOUBLE NOT NULL"}],indexKeyPrefix:e=>c.test(a(e))?191:void 0,isUniqueViolation:e=>{const t=e;return t.errno===1062||t.code==="ER_DUP_ENTRY"},name:"mysql",supportsReturning:!1,tableExists:e=>s`SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = ${e}`};export{u as mysqlDialect,m as postgresDialect};
@@ -0,0 +1 @@
1
+ import{liftSourceId as m}from"@lunora/do";const s=(o,r={})=>m(o,r),i=async(o,r)=>{const{idColumn:a,map:e,params:p,query:t}=r;return(await o.query(t,p)).map(u=>s(u,{idColumn:a,map:e}))};export{s as projectSourceRow,i as pullSourceRows};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/hyperdrive",
3
- "version": "1.0.0-alpha.40",
3
+ "version": "1.0.0-alpha.41",
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",
@@ -50,9 +50,9 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@lunora/do": "1.0.0-alpha.44",
53
+ "@lunora/do": "1.0.0-alpha.45",
54
54
  "@lunora/errors": "1.0.0-alpha.8",
55
- "@lunora/sql-store": "1.0.0-alpha.41",
55
+ "@lunora/sql-store": "1.0.0-alpha.42",
56
56
  "drizzle-orm": "^0.45.2"
57
57
  },
58
58
  "peerDependencies": {
@@ -1,23 +0,0 @@
1
- const buildPgExec = (client) => {
2
- return {
3
- all: (sql, params) => client.query(sql, params),
4
- run: async (sql, params) => {
5
- await client.query(sql, params);
6
- return { rowsAffected: 0 };
7
- }
8
- };
9
- };
10
- const buildMysqlExec = (connection) => {
11
- return {
12
- all: async (sql, params) => {
13
- const [rows] = await connection.execute(sql, params);
14
- return rows;
15
- },
16
- run: async (sql, params) => {
17
- const [result] = await connection.execute(sql, params);
18
- return { rowsAffected: result.affectedRows ?? 0 };
19
- }
20
- };
21
- };
22
-
23
- export { buildMysqlExec, buildPgExec };
@@ -1,36 +0,0 @@
1
- const createHyperdrive = (binding) => {
2
- const config = {
3
- database: binding.database,
4
- host: binding.host,
5
- password: binding.password,
6
- port: binding.port,
7
- user: binding.user
8
- };
9
- return { config, connectionString: binding.connectionString };
10
- };
11
- const fromPostgresJs = (client) => {
12
- return {
13
- query: async (text, params = []) => {
14
- const rows = await client.unsafe(text, params);
15
- return rows;
16
- }
17
- };
18
- };
19
- const fromNodePg = (client) => {
20
- return {
21
- query: async (text, params = []) => {
22
- const result = await client.query(text, params);
23
- return result.rows;
24
- }
25
- };
26
- };
27
- const fromMysql2 = (connection) => {
28
- return {
29
- query: async (text, params = []) => {
30
- const [rows] = await connection.execute(text, params);
31
- return Array.isArray(rows) ? rows : [];
32
- }
33
- };
34
- };
35
-
36
- export { createHyperdrive, fromMysql2, fromNodePg, fromPostgresJs };
@@ -1,112 +0,0 @@
1
- import { sqliteEncode, sqliteDecode } from '@lunora/sql-store';
2
- import { sql } from 'drizzle-orm';
3
-
4
- const PG_UNIQUE_VIOLATION_RE = /duplicate key value violates unique constraint/iu;
5
- const mysqlColumnType = (kind) => {
6
- switch (kind) {
7
- case "array":
8
- case "object":
9
- case "record": {
10
- return "JSON";
11
- }
12
- case "bigint": {
13
- return "VARCHAR(64)";
14
- }
15
- case "boolean": {
16
- return "TINYINT";
17
- }
18
- case "bytes": {
19
- return "LONGBLOB";
20
- }
21
- case "date":
22
- case "number":
23
- case "timestamp": {
24
- return "DOUBLE";
25
- }
26
- default: {
27
- return "LONGTEXT";
28
- }
29
- }
30
- };
31
- const MYSQL_PREFIX_INDEX_RE = /TEXT|BLOB/u;
32
- const postgresDialect = {
33
- companionTypes: {
34
- autoincrementPrimaryKey: "BIGSERIAL PRIMARY KEY",
35
- integer: "INTEGER",
36
- key: "TEXT",
37
- real: "DOUBLE PRECISION",
38
- text: "TEXT"
39
- },
40
- columnType: (kind) => {
41
- switch (kind) {
42
- case "boolean": {
43
- return "INTEGER";
44
- }
45
- case "bytes": {
46
- return "BYTEA";
47
- }
48
- case "date":
49
- case "number":
50
- case "timestamp": {
51
- return "DOUBLE PRECISION";
52
- }
53
- default: {
54
- return "TEXT";
55
- }
56
- }
57
- },
58
- decode: (value, kind) => sqliteDecode(value, kind),
59
- encode: (value) => sqliteEncode(value),
60
- frameworkColumns: () => [
61
- { name: "id", type: "TEXT PRIMARY KEY" },
62
- { name: "_creationTime", type: "DOUBLE PRECISION NOT NULL" }
63
- ],
64
- isUniqueViolation: (error) => {
65
- const { code } = error;
66
- return code === "23505" || error instanceof Error && PG_UNIQUE_VIOLATION_RE.test(error.message);
67
- },
68
- name: "postgres",
69
- supportsReturning: true,
70
- // Restrict to schemas on the effective search_path (excluding the implicit
71
- // pg_catalog with `false`) so an unqualified name resolves exactly as CREATE
72
- // TABLE / SELECT would. Without this filter the probe sees same-named tables in
73
- // OTHER schemas of the same database (a common multi-tenant/multi-env Hyperdrive
74
- // setup), reporting a companion table that does not exist on the search_path.
75
- tableExists: (table) => sql`SELECT table_name FROM information_schema.tables WHERE table_schema = ANY (current_schemas(false)) AND table_name = ${table}`
76
- };
77
- const mysqlDialect = {
78
- affectedRows: (result) => result.rowsAffected,
79
- companionTypes: {
80
- autoincrementPrimaryKey: "BIGINT AUTO_INCREMENT PRIMARY KEY",
81
- integer: "INTEGER",
82
- // VARCHAR so it can be a PRIMARY KEY and be fully indexed (TEXT cannot,
83
- // without a prefix length). 768 = InnoDB utf8mb4 single-column index limit.
84
- key: "VARCHAR(768)",
85
- real: "DOUBLE",
86
- // Unbounded post-image storage (CDC `doc`); never an index key, so no bound.
87
- text: "LONGTEXT"
88
- },
89
- columnType: (kind) => mysqlColumnType(kind),
90
- decode: (value, kind) => sqliteDecode(value, kind),
91
- encode: (value) => sqliteEncode(value),
92
- frameworkColumns: () => [
93
- { name: "id", type: "VARCHAR(768) PRIMARY KEY" },
94
- { name: "_creationTime", type: "DOUBLE NOT NULL" }
95
- ],
96
- // InnoDB can't index a TEXT/LONGTEXT/BLOB column without a key prefix. Bound it
97
- // to 191 chars (191 × 4 = 764 bytes under utf8mb4), matching the rank-companion
98
- // convention: a flat 768-char prefix is 3072 bytes — exactly InnoDB's whole-index
99
- // key limit — so ANY composite index containing a string field (e.g.
100
- // `.index("by_project", ["projectId", "seq"])`) would exceed 3072 and fail CREATE
101
- // INDEX with ER_TOO_LONG_KEY. 191 leaves room for several columns under the cap.
102
- indexKeyPrefix: (kind) => MYSQL_PREFIX_INDEX_RE.test(mysqlColumnType(kind)) ? 191 : void 0,
103
- isUniqueViolation: (error) => {
104
- const candidate = error;
105
- return candidate.errno === 1062 || candidate.code === "ER_DUP_ENTRY";
106
- },
107
- name: "mysql",
108
- supportsReturning: false,
109
- tableExists: (table) => sql`SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = ${table}`
110
- };
111
-
112
- export { mysqlDialect, postgresDialect };
@@ -1,10 +0,0 @@
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 };