camelToSnake and snakeCamelMapper() drop the underscore when a digit precedes a camelCase boundary
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 85/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- postgresql, typescript
- Lĩnh vực
- api
Hướng nghiên cứu
Lỗi nằm ở camelToSnake trong packages/typescript-client/src/column-mapper.ts, biểu thức chính quy xác định ranh giới /([a-z_])([A-Z])/g của nó bỏ sót các chuyển tiếp từ chữ số sang chữ hoa. Chạy repro trong issue để thấy sha256Hash thành sha256hash. Hoàn thành khi camelToSnake trả về sha256_hash, oauth2_token, address1_line và v2_payload, và các test của column-mapper bao phủ các ranh giới chữ số.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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/
- Ngôn ngữ chính
- TypeScript
- Star
- 10.4k
- Fork
- 399
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của electric-sql/electric
-
ShapeStream does not notify subscribers when it gives up on a non-Error valueCó thể đã có người làm @Tyagiquamar đã nhận 19 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
electric-sql/electric#4830 ·
-
@electric-sql/client throws SecurityError on import when the browser blocks site storage (typeof localStorage outside try)Có thể đã có người làm @mohanedmoh đã nhận 36 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
electric-sql/electric#4826 · 1 bình luận ·
-
agents-chat-starter: spawn PUT goes to the durable-streams proxy, so no entity is created and agents never wakeCó thể đã có người làm @adityavkk đã nhận 133 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
electric-sql/electric#4687 ·
-
Listen IP addressĐang mởfeature request triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
electric-sql/electric#4150 · 1 bình luận ·
-
ArrayDecoder doesn't handle escaped backslashes in quoted PostgreSQL array elementsCó thể đã có người làm @cpruijsen đã nhận 34 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
electric-sql/electric#3708 ·
Tất cả issue của electric-sql/electric
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
AykutSarac/jsoncrack.com#616 ·
-
nip27: long hashtag swallows the rest of the content, lone # gives an empty hashtagCó thể đã có người làm @bardrop đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
nbd-wtf/nostr-tools#578 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
backnotprop/plannotator#3427 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
microsoft/Power-CAT-Copilot-Studio-Kit#942 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG]: Duplicate preposition in heading and unformatted feedback text on Strengthen Argument pageĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
AOSSIE-Org/DebateAI#801 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày