firebase / firebase/firebase-admin-node

[FR] Algorithm for unique ID generation

Đang mở
#2,698 6 bình luận 0 reaction 0 người được giao Xem trên GitHub
api: firestore type: feature request
Ngôn ngữ chính
TypeScript
Star
1.7k
Fork
419
Merge trung bình
3 ngày 10 giờ
Pull request đã merge (30 ngày)
16

Mô tả

**Is your feature request related to a problem? Please describe.**
When there is a time we rely on firebase to generate unique ID for firestore or authentication, sometimes we don't want complete random ID. There should be some option to control the ID generation algorithm

I wish I could generate ID that can be always sorted. At least incremental or any monotonic function should be allow to prepend to the generated ID, such as base64 encoded unix timestamp

Additionally it should allow specifying the length of id, and the allowed encode character such as, is it case-sensitive, only numeric or alphanumeric, is it allow symbol, so on. So we have

**Describe the solution you'd like**
For authentication, maybe it could have option at the firebase console to specify the detailed algorithm as checkbox/radio

For firestore. Actually I wish I could have ability to do servervalue string formatting. So I could have firestore server generate any field, include ID, with the string I want

For this particular case I think we should have

```js
db.collection("users").add({ // Should allow push new document with __name__ as id
"__name__": ServerValue.calculate("string(request.time.toMillis(),16).reverse() + hashing.crc32(request.path).toHexString()"), // use firebase rule syntax for server generate value
data : "anydata"
});
```

The above example generate reverse hex string from time and hash of the path. This function guaranteed incremental from server timestamp but also seemingly random at start and the end

(Also I want to request that `string()` function in firebase rule system should have base argument for int value, and also reverse function)

**Describe alternatives you've considered**

There is a request to allow set custom ID in `beforeUserCreated` as requested in https://github.com/firebase/firebase-tools/issues/5675

Same go for firestore blocking function https://github.com/firebase/firebase-admin-node/issues/2077

**Additional context**
Is it possible to have firebase server issue request in github too?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu với ví dụ thêm của Firestore và xem xét các yêu cầu được liên kết về ID tùy chỉnh trong beforeUserCreated và các hàm blocking của Firestore. Làm rõ phạm vi bao gồm Authentication, Firestore hay cả hai, sau đó xác định trước khi triển khai các tiêu chí chấp nhận cho ID có thứ tự, các quy tắc về độ dài và ký tự, cũng như các trường do máy chủ tạo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
firebase, nodejs, typescript
Lĩnh vực
authentication, backend-api-design, databases
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
22/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.