mirror of
https://github.com/ente-io/ente.git
synced 2025-08-09 07:48:52 +00:00
nanoids
This commit is contained in:
parent
5cc8479354
commit
ce421eded4
@ -193,6 +193,9 @@ For more details, see [translations.md](translations.md).
|
||||
- [zod](https://github.com/colinhacks/zod) is used for runtime typechecking
|
||||
(e.g. verifying that API responses match the expected TypeScript shape).
|
||||
|
||||
- [nanoid](https://github.com/ai/nanoid) is used for generating unique
|
||||
identifiers.
|
||||
|
||||
- [debounce](https://github.com/sindresorhus/debounce) and its
|
||||
promise-supporting sibling
|
||||
[pDebounce](https://github.com/sindresorhus/p-debounce) are used for
|
||||
|
17
web/packages/base/id-worker.ts
Normal file
17
web/packages/base/id-worker.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { customAlphabet } from "nanoid/non-secure";
|
||||
import { alphabet } from "./id";
|
||||
|
||||
const nanoid = customAlphabet(alphabet, 22);
|
||||
|
||||
/**
|
||||
* This is a variant of the regular {@link newID} that can be used in web
|
||||
* workers.
|
||||
*
|
||||
* Web workers don't have access to a secure random generator, so we need to use
|
||||
* the non-secure variant.
|
||||
* https://github.com/ai/nanoid?tab=readme-ov-file#web-workers
|
||||
*
|
||||
* For many of our use cases, where we're not using these IDs for cryptographic
|
||||
* operations, this is okay. We also have an increased alphabet length.
|
||||
*/
|
||||
export const newNonSecureID = (prefix: string) => prefix + nanoid();
|
24
web/packages/base/id.ts
Normal file
24
web/packages/base/id.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { customAlphabet } from "nanoid";
|
||||
|
||||
/**
|
||||
* Remove _ and - from the default set to have better looking IDs that can also
|
||||
* be selected in the editor quickly ("-" prevents this), and which we can
|
||||
* prefix unambigously ("_" is used for that).
|
||||
*
|
||||
* To compensate, increase length from the default of 21 to 22.
|
||||
*
|
||||
* To play around with these, use https://zelark.github.io/nano-id-cc/
|
||||
*/
|
||||
export const alphabet =
|
||||
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
const nanoid = customAlphabet(alphabet, 22);
|
||||
|
||||
/**
|
||||
* Generate a new random identifier with the given prefix.
|
||||
*
|
||||
* Internally this uses [nanoids](https://github.com/ai/nanoid).
|
||||
*
|
||||
* See {@link newNonSecureID} for a variant that can be used in web workers.
|
||||
*/
|
||||
export const newID = (prefix: string) => prefix + nanoid();
|
@ -12,6 +12,7 @@
|
||||
"i18next": "^23.11",
|
||||
"i18next-resources-to-backend": "^1.2",
|
||||
"is-electron": "^2.2",
|
||||
"nanoid": "^5.0.7",
|
||||
"next": "^14.2",
|
||||
"react": "^18",
|
||||
"react-dom": "^18",
|
||||
|
@ -7,7 +7,9 @@ import type { FaceIndex } from "./face";
|
||||
* Each cluster has an id so that a Person (a set of clusters) can refer to it.
|
||||
*/
|
||||
export interface Cluster {
|
||||
/** A unique nanoid to identify this cluster. */
|
||||
/**
|
||||
* A randomly generated ID to uniquely identify this cluster.
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* An unordered set of ids of the faces that belong to the cluster.
|
||||
@ -31,7 +33,9 @@ export interface Cluster {
|
||||
* That is, it has the clusters embedded within itself.
|
||||
*/
|
||||
export interface Person {
|
||||
/** A unique nanoid to identify this person. */
|
||||
/**
|
||||
* A randomly generated ID to uniquely identify this person.
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* An optional name assigned by the user to this person.
|
||||
@ -67,5 +71,6 @@ export interface Person {
|
||||
*/
|
||||
export const clusterFaces = (faceIndices: FaceIndex[]) => {
|
||||
log.debug(() => ["Clustering", faceIndices]);
|
||||
const clusters: Cluster = []
|
||||
return undefined;
|
||||
};
|
||||
|
@ -3374,7 +3374,7 @@ libsodium-wrappers@0.7.9:
|
||||
dependencies:
|
||||
libsodium "^0.7.0"
|
||||
|
||||
libsodium@0.7.9, libsodium@^0.7.0:
|
||||
libsodium@^0.7.0:
|
||||
version "0.7.9"
|
||||
resolved "https://registry.yarnpkg.com/libsodium/-/libsodium-0.7.9.tgz#4bb7bcbf662ddd920d8795c227ae25bbbfa3821b"
|
||||
integrity sha512-gfeADtR4D/CM0oRUviKBViMGXZDgnFdMKMzHsvBdqLBHd9ySi6EtYnmuhHVDDYgYpAO8eU8hEY+F8vIUAPh08A==
|
||||
@ -3590,6 +3590,11 @@ nanoid@^3.3.6, nanoid@^3.3.7:
|
||||
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.7.tgz#d0c301a691bc8d54efa0a2226ccf3fe2fd656bd8"
|
||||
integrity sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==
|
||||
|
||||
nanoid@^5.0.7:
|
||||
version "5.0.7"
|
||||
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-5.0.7.tgz#6452e8c5a816861fd9d2b898399f7e5fd6944cc6"
|
||||
integrity sha512-oLxFY2gd2IqnjcYyOXD8XGCftpGtZP2AbHbOkthDkvRywH5ayNtPVy9YlOPcHckXzbLTCHpkb7FB+yuxKV13pQ==
|
||||
|
||||
natural-compare@^1.4.0:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
|
||||
|
Loading…
x
Reference in New Issue
Block a user