Lot 1a : socle du domaine (événements, état, programme, profil) et outillage
Journal d'événements v1 et son repli, validation unique du programme, bibliothèque d'exercices reprise d'Atelier (textes seulement), programme de départ, tests node --test, règles d'architecture testées, vérification des types JSDoc par tsc --checkJs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c8959eb4f9
commit
29261d38eb
@@ -0,0 +1,27 @@
|
||||
// Identifiants. crypto.getRandomValues existe partout (navigateur, y compris en
|
||||
// http sur le réseau local, et Node), contrairement à crypto.randomUUID.
|
||||
|
||||
/** Identifiant aléatoire au format UUID v4. */
|
||||
export function randomId() {
|
||||
const b = crypto.getRandomValues(new Uint8Array(16));
|
||||
b[6] = (b[6] & 0x0f) | 0x40;
|
||||
b[8] = (b[8] & 0x3f) | 0x80;
|
||||
const h = [...b].map((x) => x.toString(16).padStart(2, "0")).join("");
|
||||
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifiant déterministe tiré d'un texte (FNV-1a 64 bits) : un même contenu
|
||||
* importé deux fois donne les mêmes événements, que la fusion par union
|
||||
* dédoublonne. Ce n'est pas une empreinte cryptographique.
|
||||
* @param {string} prefix
|
||||
* @param {string} text
|
||||
*/
|
||||
export function stableId(prefix, text) {
|
||||
let h = 0xcbf29ce484222325n;
|
||||
for (const byte of new TextEncoder().encode(text)) {
|
||||
h ^= BigInt(byte);
|
||||
h = (h * 0x100000001b3n) & 0xffffffffffffffffn;
|
||||
}
|
||||
return `${prefix}-${h.toString(16).padStart(16, "0")}`;
|
||||
}
|
||||
Reference in New Issue
Block a user