🚀. Socket Launch Week Day 3:Socket Firewall Now Blocks Malicious VS Code and Open VSX Extensions.Learn more
Sign In

@prisma-next/utils

Package Overview
Dependencies
Maintainers
3
Versions
860
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prisma-next/utils

Shared utility functions for Prisma Next

Source
npmnpm
Version
0.13.0-dev.31
Version published
Weekly downloads
33K
-5.64%
Maintainers
3
Weekly downloads
 
Created
Source

@prisma-next/utils

Internal package. This package is an implementation detail of prisma-next and is published only to support its runtime. Its API is unstable and may change without notice. Do not depend on this package directly; install prisma-next instead.

Shared utility functions for Prisma Next.

Overview

This package provides general-purpose utility functions used across the Prisma Next codebase. These utilities are target-agnostic and have no dependencies on other Prisma Next packages.

Utilities

ifDefined(key, value)

Returns an object with the key/value if value is defined, otherwise an empty object. Use with spread to conditionally include optional properties while satisfying exactOptionalPropertyTypes.

import { ifDefined } from '@prisma-next/utils/defined';

// Instead of:
const obj = {
  required: 'value',
  ...(optional ? { optional } : {}),
};

// Use:
const obj = {
  required: 'value',
  ...ifDefined('optional', optional),
};

Why use this?

  • Explicit: You name exactly which properties are optional
  • Intentional: Won't accidentally strip other properties
  • Type-safe: Returns {} or { key: V } (without undefined)
  • exactOptionalPropertyTypes compatible: Properly handles TypeScript's strict optional property checking

Result<T, F>, ok(), notOk(), okVoid()

Generic Result type for representing success or failure outcomes. This is the standard way to return "expected failures" as values rather than throwing exceptions.

import { type Result, ok, notOk, okVoid } from '@prisma-next/utils/result';

// Success result with value
function divide(a: number, b: number): Result<number, string> {
  if (b === 0) {
    return notOk('Division by zero');
  }
  return ok(a / b);
}

// Using the result
const result = divide(10, 2);
if (result.ok) {
  console.log(result.value); // 5
} else {
  console.error(result.failure); // error message
}

// Void success for validation
function validate(value: unknown): Result<void, string> {
  if (!value) {
    return notOk('Value is required');
  }
  return okVoid();
}

Types:

  • Ok<T> - Success with value: { ok: true, value: T }
  • NotOk<F> - Failure with details: { ok: false, failure: F }
  • Result<T, F> - Discriminated union of Ok<T> | NotOk<F>

See docs/Error Handling.md for the full error taxonomy.

Package Location

This package is part of the framework domain, foundation layer:

  • Domain: framework (target-agnostic)
  • Layer: foundation
  • Path: packages/1-framework/0-foundation/utils

Dependencies

This package has no dependencies - it's part of the innermost core ring and provides foundational utilities.

FAQs

Package last updated on 15 Jun 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts