Skip to content

[pull] main from prisma:main#224

Merged
pull[bot] merged 1 commit intocode:mainfrom
prisma:main
Mar 17, 2026
Merged

[pull] main from prisma:main#224
pull[bot] merged 1 commit intocode:mainfrom
prisma:main

Conversation

@pull
Copy link

@pull pull bot commented Mar 17, 2026

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

…us new Date() calls (#28724)

The Issue: The GeneratorRegistry.snapshot() method creates a snapshot of
all generators, including **NowGenerator**

```
class NowGenerator implements ValueGenerator {
  #now: Date = new Date()

  generate(): string {
    return this.#now.toISOString()
  }
}
```

The **NowGenerator** was initializing new Date() in its property
declaration, meaning it was called synchronously during every query
preparation, even if now() was not used.


The Fix: I modified  **NowGenerator** to be lazy. 

```
class NowGenerator implements ValueGenerator {
  #now: Date | undefined

  generate(): string {
    if (this.#now === undefined) {
      this.#now = new Date()
    }
    return this.#now.toISOString()
  }
}
```

The #now field is now initialized as undefined, and new Date() is only
called inside the **generate()**

```
class NanoIdGenerator implements ValueGenerator {
  generate(arg: unknown): string {
    if (typeof arg === 'number') {
      return nanoid(arg)
    } else if (arg === undefined) {
      return nanoid()
    } else {
      throw new Error('Invalid Nanoid generator arguments')
    }
  }
} 
```

method if it hasn't been initialized yet.

Fixes #28588

Co-authored-by: jacek-prisma <malec@prisma.io>
@pull pull bot locked and limited conversation to collaborators Mar 17, 2026
@pull pull bot added the ⤵️ pull label Mar 17, 2026
@pull pull bot merged commit 3f2438c into code:main Mar 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant