camelToSnake and snakeCamelMapper() drop the underscore when a digit precedes a camelCase boundary
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 85/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- postgresql, typescript
- 领域
- api
调研方向
问题出在 packages/typescript-client/src/column-mapper.ts 中的 camelToSnake,其边界正则 /([a-z_])([A-Z])/g 漏掉了数字到大写字母的转换。运行 issue 中的复现步骤,可以看到 sha256Hash 变成了 sha256hash。当 camelToSnake 返回 sha256_hash、oauth2_token、address1_line 和 v2_payload,并且 column-mapper 的测试覆盖了数字边界时,即为完成。
由索引模型根据 Issue 内容生成。
描述
Versions
- Client: typescript,
@electric-sql/client1.5.28 (also onmain3f9809fb0b, Node v26.13.0) - Electric: any (happens client-side before the request reaches Electric)
Bug description
snakeToCamel converts a column like sha256_hash into sha256Hash, and its doc comment states that the transform is round-trippable via camelToSnake. However, camelToSnake in packages/typescript-client/src/column-mapper.ts only inserts _ before an uppercase letter that follows [a-z_], so camelToSnake("sha256Hash") returns "sha256hash".
When ShapeStream or compileExpression uses snakeCamelMapper(), incoming rows are decoded with key sha256Hash, while columns, where, and subset expressions encode sha256Hash as sha256hash, sending a column name that does not exist in Postgres.
// repro.mjs
// npm i @electric-sql/[email protected] && node repro.mjs
import {
ShapeStream,
snakeCamelMapper,
snakeToCamel,
camelToSnake,
compileExpression,
} from "@electric-sql/client"
for (const col of ["sha256_hash", "oauth2_token", "address1_line", "v2_payload"]) {
const camel = snakeToCamel(col)
console.log(`${col} -> ${camel} -> ${camelToSnake(camel)}`)
}
console.log(
"compileExpression:",
compileExpression({ type: "ref", column: "sha256Hash" }, snakeCamelMapper().encode)
)
const fetchClient = async (url) => {
const u = new URL(url)
console.log("columns sent:", u.searchParams.get("columns"))
console.log("where sent:", u.searchParams.get("where"))
return new Response("[]", { status: 400 })
}
const stream = new ShapeStream({
url: "http://localhost:3000/v1/shape",
params: {
table: "files",
columns: ["id", "sha256Hash"],
where: "sha256Hash = $1",
params: ["abc"],
},
columnMapper: snakeCamelMapper(),
subscribe: false,
fetchClient,
onError: () => stream.unsubscribeAll(),
})
stream.subscribe(() => {})
Actual output:
sha256_hash -> sha256Hash -> sha256hash
oauth2_token -> oauth2Token -> oauth2token
address1_line -> address1Line -> address1line
v2_payload -> v2Payload -> v2payload
compileExpression: "sha256hash"
columns sent: "id","sha256hash"
where sent: sha256hash = $1
Expected behavior
camelToSnake should return sha256_hash, oauth2_token, address1_line, and v2_payload, compileExpression should return "sha256_hash", columns should be "id","sha256_hash", and where should be sha256_hash = $1. Changing the first boundary regex in camelToSnake from /([a-z_])([A-Z])/g to /([a-z0-9_])([A-Z])/g preserves the underscore after digits.
Credit: https://ucsbplse.github.io/
- 主要语言
- TypeScript
- 星标
- 10.4k
- 派生
- 399
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
electric-sql/electric 的其他 Issue
-
ShapeStream does not notify subscribers when it gives up on a non-Error value可能已有人在做 @Tyagiquamar 于 19 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
electric-sql/electric#4830 ·
-
@electric-sql/client throws SecurityError on import when the browser blocks site storage (typeof localStorage outside try)可能已有人在做 @mohanedmoh 于 37 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
electric-sql/electric#4826 · 1 条评论 ·
-
agents-chat-starter: spawn PUT goes to the durable-streams proxy, so no entity is created and agents never wake可能已有人在做 @adityavkk 于 133 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
electric-sql/electric#4687 ·
-
feature request triage
难度 2/5 1-3 小时 新手友好度 68/100
electric-sql/electric#4150 · 1 条评论 ·
-
ArrayDecoder doesn't handle escaped backslashes in quoted PostgreSQL array elements可能已有人在做 @cpruijsen 于 34 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
electric-sql/electric#3708 ·
查看 electric-sql/electric 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
open-webui/tether#52 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
voidzero-dev/void#835 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
AykutSarac/jsoncrack.com#616 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
melgarafael/DeskcommCRM#4679 ·
维护者通常 1 天内回复