Revert "refactor(base): use uuid package instead of inlined uuid7 in tests"

This reverts commit f819f633c9.
This commit is contained in:
Philipinho
2026-04-23 13:14:09 +01:00
parent 7192b4bacb
commit b2ed8f9936
7 changed files with 57 additions and 2 deletions
@@ -6,8 +6,8 @@ import { PostgresJSDialect } from 'kysely-postgres-js';
import * as postgres from 'postgres';
import { Injectable } from '@nestjs/common';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { randomBytes } from 'node:crypto';
import { generateJitteredKeyBetween } from 'fractional-indexing-jittered';
import { v7 as uuid7 } from 'uuid';
import { BaseRepo } from '@docmost/db/repos/base/base.repo';
import { BasePropertyRepo } from '@docmost/db/repos/base/base-property.repo';
import { BaseRowRepo } from '@docmost/db/repos/base/base-row.repo';
@@ -78,6 +78,33 @@ function normalizePostgresUrl(url: string): string {
const describeIntegration = INTEGRATION_DB_URL ? describe : describe.skip;
// Inline uuid7 so the spec file doesn't need to import the esm-only uuid
// package. Same pattern as seed-base.ts.
function uuid7(): string {
const now = BigInt(Date.now());
const bytes = randomBytes(16);
bytes[0] = Number((now >> 40n) & 0xffn);
bytes[1] = Number((now >> 32n) & 0xffn);
bytes[2] = Number((now >> 24n) & 0xffn);
bytes[3] = Number((now >> 16n) & 0xffn);
bytes[4] = Number((now >> 8n) & 0xffn);
bytes[5] = Number(now & 0xffn);
bytes[6] = (bytes[6] & 0x0f) | 0x70;
bytes[8] = (bytes[8] & 0x3f) | 0x80;
const hex = bytes.toString('hex');
return (
hex.slice(0, 8) +
'-' +
hex.slice(8, 12) +
'-' +
hex.slice(12, 16) +
'-' +
hex.slice(16, 20) +
'-' +
hex.slice(20, 32)
);
}
// Deterministic PRNG (mulberry32) for reproducible seeds across runs.
function makeRng(seed: number): () => number {
let s = seed >>> 0;
@@ -1,6 +1,34 @@
import type { Kysely } from 'kysely';
import { randomBytes } from 'node:crypto';
import { generateJitteredKeyBetween } from 'fractional-indexing-jittered';
import { v7 as uuid7 } from 'uuid';
// Minimal RFC 9562 uuid7. We inline instead of importing `uuid@13` because
// that package is ESM-only and this module is loaded by jest (CommonJS) in
// the integration spec.
function uuid7(): string {
const now = BigInt(Date.now());
const bytes = randomBytes(16);
bytes[0] = Number((now >> 40n) & 0xffn);
bytes[1] = Number((now >> 32n) & 0xffn);
bytes[2] = Number((now >> 24n) & 0xffn);
bytes[3] = Number((now >> 16n) & 0xffn);
bytes[4] = Number((now >> 8n) & 0xffn);
bytes[5] = Number(now & 0xffn);
bytes[6] = (bytes[6] & 0x0f) | 0x70; // version 7
bytes[8] = (bytes[8] & 0x3f) | 0x80; // variant
const hex = bytes.toString('hex');
return (
hex.slice(0, 8) +
'-' +
hex.slice(8, 12) +
'-' +
hex.slice(12, 16) +
'-' +
hex.slice(16, 20) +
'-' +
hex.slice(20, 32)
);
}
export type SeedBaseOptions = {
db: Kysely<any>;