Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@prisma/extension-accelerate

Package Overview
Dependencies
Maintainers
2
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prisma/extension-accelerate - npm Package Compare versions

Comparing version 0.0.0-experimental-b1c4b75 to 0.0.0-experimental-c1e4c49

dist/cjs/node-fetch.d.ts

118

dist/cjs/index.d.ts

@@ -1,37 +0,95 @@

import { Prisma } from "@prisma/client";
import type { Types } from "@prisma/client/runtime";
/// <reference lib="dom" />
import PrismaDefault, { type Prisma } from "@prisma/client/scripts/default-index.js";
import type { Types } from "@prisma/client/runtime/library.js";
export interface PrismaCacheStrategy {
/** TODO */
/**
* Specifies the caching parameters for Accelerate.
*
* `cacheStrategy` only applies when used with an Accelerate connection string.
*/
readonly cacheStrategy?: {
/** TODO */
/**
* `swr` is short for Stale-While-Revalidate.
*
* `swr` defines the number of seconds that Accelerate may serve _stale_ cache data.
* _Stale_ data is a cache hit, but the cache will be refreshed in the background by Accelerate.
* The Prisma operation will not be blocked while data is refreshed.
*
* Use `swr` to reduce the latency of accessing the data while still maintaining
* a more up-to-date value in the Accelerate cache.
* `swr` without `ttl` will not reduce database load since Accelerate will
* run the query in the background.
*
* `swr` can be combined with `ttl`.
* `swr` applies **after** `ttl` has expired.
* The total number of seconds data will be cached is `ttl + swr`.
*
* `swr` only applies when used with an Accelerate connection string.
*/
readonly swr?: number;
/**
* `ttl` is short for Time-to-Live.
*
* `ttl` defines the number of seconds that Accelerate may serve _fresh_ cache data.
* _Fresh_ data is a cache hit and will not execute the query against the database.
*
* Use `ttl` to reduce database load and latency for data that does not
* require frequent updates.
* `ttl` without `swr` will incur a blocking database query for the first
* request after `ttl` expires.
*
* It's recommended to combine `ttl` and `swr` to maintain low latency while
* Accelerate refreshes cached data in the background.
* `swr` applies **after** `ttl` has expired.
* The total number of seconds data will be cached is `ttl + swr`.
*
* `ttl` only applies when used with an Accelerate connection string.
*/
readonly ttl?: number;
};
}
declare const _default: (client: any) => import(".prisma/client").PrismaClient<any, any, any, {
result: {} & Record<string, {}>;
model: {} & Record<string, {}> & Record<string, {
aggregate: () => <T, A>(this: T, args: Prisma.Exact<A, Types.Public.Args<T, "aggregate"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T, A, "aggregate">>;
count: () => <T_1, A_1>(this: T_1, args: Prisma.Exact<A_1, Types.Public.Args<T_1, "count"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_1, A_1, "count">>;
findFirst: () => <T_2, A_2>(this: T_2, args: Prisma.Exact<A_2, Types.Public.Args<T_2, "findFirst"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_2, A_2, "findFirst">>;
findFirstOrThrow: () => <T_3, A_3>(this: T_3, args: Prisma.Exact<A_3, Types.Public.Args<T_3, "findFirstOrThrow"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_3, A_3, "findFirstOrThrow">>;
findMany: () => <T_4, A_4>(this: T_4, args: Prisma.Exact<A_4, Types.Public.Args<T_4, "findMany"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_4, A_4, "findMany">>;
findUnique: () => <T_5, A_5>(this: T_5, args: Prisma.Exact<A_5, Types.Public.Args<T_5, "findUnique"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_5, A_5, "findUnique">>;
findUniqueOrThrow: () => <T_6, A_6>(this: T_6, args: Prisma.Exact<A_6, Types.Public.Args<T_6, "findUniqueOrThrow"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_6, A_6, "findUniqueOrThrow">>;
groupBy: () => <T_7, A_7>(this: T_7, args: Prisma.Exact<A_7, Types.Public.Args<T_7, "groupBy"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_7, A_7, "groupBy">>;
}> & {
$allModels: {
aggregate: () => <T, A>(this: T, args: Prisma.Exact<A, Types.Public.Args<T, "aggregate"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T, A, "aggregate">>;
count: () => <T_1, A_1>(this: T_1, args: Prisma.Exact<A_1, Types.Public.Args<T_1, "count"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_1, A_1, "count">>;
findFirst: () => <T_2, A_2>(this: T_2, args: Prisma.Exact<A_2, Types.Public.Args<T_2, "findFirst"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_2, A_2, "findFirst">>;
findFirstOrThrow: () => <T_3, A_3>(this: T_3, args: Prisma.Exact<A_3, Types.Public.Args<T_3, "findFirstOrThrow"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_3, A_3, "findFirstOrThrow">>;
findMany: () => <T_4, A_4>(this: T_4, args: Prisma.Exact<A_4, Types.Public.Args<T_4, "findMany"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_4, A_4, "findMany">>;
findUnique: () => <T_5, A_5>(this: T_5, args: Prisma.Exact<A_5, Types.Public.Args<T_5, "findUnique"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_5, A_5, "findUnique">>;
findUniqueOrThrow: () => <T_6, A_6>(this: T_6, args: Prisma.Exact<A_6, Types.Public.Args<T_6, "findUniqueOrThrow"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_6, A_6, "findUniqueOrThrow">>;
groupBy: () => <T_7, A_7>(this: T_7, args: Prisma.Exact<A_7, Types.Public.Args<T_7, "groupBy"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_7, A_7, "groupBy">>;
};
interface AccelerateInfo {
/**
* The cache status of the response.
* * `ttl` indicates a cache hit within the `ttl` duration and no database query was executed
* * `swr` indicates a cache hit within the `swr` duration and the data is being refreshed by Accelerate in the background
* * `miss` indicates that both `ttl` and `swr` have expired and the database query was executed by the request
* * `none` indicates that no cache strategy was specified and the database query was executed by the request
*/
cacheStatus: "ttl" | "swr" | "miss" | "none";
/**
* The date the response was last refreshed.
*/
lastModified: Date;
/**
* The datacenter region that received the request.
*/
region: string;
/**
* Unique identifier of the request. Useful for troubleshooting.
*/
requestId: string;
/**
* The unique signature of the Prisma operation.
*/
signature: string;
}
interface AcceleratePromise<T> extends Prisma.PrismaPromise<T> {
withAccelerateInfo(): Prisma.PrismaPromise<{
data: T;
info: AccelerateInfo | null;
}>;
}
export declare function withAccelerate(): (client: any) => PrismaDefault.PrismaClientExtends<Types.Extensions.InternalArgs<{}, {
$allModels: {
aggregate<T, A>(this: T, args: Prisma.Exact<A, Prisma.Args<T, "aggregate"> & PrismaCacheStrategy>): AcceleratePromise<Prisma.Result<T, A, "aggregate">>;
count<T_1, A_1>(this: T_1, args?: Prisma.Exact<A_1, Prisma.Args<T_1, "count"> & PrismaCacheStrategy> | undefined): AcceleratePromise<Prisma.Result<T_1, A_1, "count">>;
findFirst<T_2, A_2>(this: T_2, args?: Prisma.Exact<A_2, Prisma.Args<T_2, "findFirst"> & PrismaCacheStrategy> | undefined): AcceleratePromise<Prisma.Result<T_2, A_2, "findFirst"> | null>;
findFirstOrThrow<T_3, A_3>(this: T_3, args?: Prisma.Exact<A_3, Prisma.Args<T_3, "findFirstOrThrow"> & PrismaCacheStrategy> | undefined): AcceleratePromise<Prisma.Result<T_3, A_3, "findFirstOrThrow">>;
findMany<T_4, A_4>(this: T_4, args?: Prisma.Exact<A_4, Prisma.Args<T_4, "findMany"> & PrismaCacheStrategy> | undefined): AcceleratePromise<Prisma.Result<T_4, A_4, "findMany">>;
findUnique<T_5, A_5>(this: T_5, args: Prisma.Exact<A_5, Prisma.Args<T_5, "findUnique"> & PrismaCacheStrategy>): AcceleratePromise<Prisma.Result<T_5, A_5, "findUnique"> | null>;
findUniqueOrThrow<T_6, A_6>(this: T_6, args: Prisma.Exact<A_6, Prisma.Args<T_6, "findUniqueOrThrow"> & PrismaCacheStrategy>): AcceleratePromise<Prisma.Result<T_6, A_6, "findUniqueOrThrow">>;
groupBy<T_7, A_7>(this: T_7, args: Prisma.Exact<A_7, Prisma.Args<T_7, "groupBy"> & PrismaCacheStrategy>): AcceleratePromise<Prisma.Result<T_7, A_7, "groupBy">>;
};
client: {};
query: {};
}>;
export default _default;
}, {}, {}> & Types.Extensions.InternalArgs<{}, {}, {}, {}> & Types.Extensions.DefaultArgs>;
export {};
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const client_1 = require("@prisma/client");
exports.withAccelerate = void 0;
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/// <reference lib="dom" />
// importing default is needed for ESM compatibility
// default-index is a CJS file, so named exports are not resolved
// the types create a separate resolution issue, so they are still imported by name
const default_index_js_1 = __importDefault(require("@prisma/client/scripts/default-index.js"));
const EXTENSION_NAME = "@prisma/extension-accelerate";
exports.default = client_1.Prisma.defineExtension((client) => {
const xclient = client.$extends({
name: EXTENSION_NAME,
query: {
$allModels: {
// TODO: these functions are repetitive. Is there a type we can use to generic this?
aggregate(params) {
const { args } = params;
const { cacheStrategy, ...rest } = args;
const { __internalParams, query } = params;
__internalParams.headers = {
...__internalParams.headers,
"cache-control": cacheStrategy
? `max-age=${cacheStrategy.ttl};stale-while-revalidate=${cacheStrategy.swr}`
: `no-cache`,
};
return query(rest, __internalParams);
function makeWithCacheHeaders() {
let machineHint = undefined;
async function getFetcher() {
if (typeof globalThis?.fetch === "function") {
return globalThis.fetch;
}
else {
const { fetch } = await Promise.resolve().then(() => __importStar(require("./node-fetch.js")));
return fetch;
}
}
return async (params) => {
const { args } = params;
const { cacheStrategy, __accelerateInfo = false, ...rest } = args;
let info = null;
const { __internalParams, query } = params;
__internalParams.customDataProxyFetch = () => {
return async (url, options) => {
const cacheControl = new Array();
if (typeof cacheStrategy?.ttl === "number") {
cacheControl.push(`max-age=${cacheStrategy.ttl}`);
}
if (typeof cacheStrategy?.swr === "number") {
cacheControl.push(`stale-while-revalidate=${cacheStrategy.swr}`);
}
options.headers = {
...options.headers,
"cache-control": cacheControl.length > 0 ? cacheControl.join(",") : `no-cache`,
};
if (machineHint) {
options.headers["accelerate-query-engine-jwt"] = machineHint;
}
const fetch = await getFetcher();
const response = await fetch(url, options);
info = {
cacheStatus: response.headers.get("accelerate-cache-status"),
lastModified: new Date(response.headers.get("last-modified") ?? ""),
region: response.headers.get("cf-ray")?.split("-")[1] ?? "unspecified",
requestId: response.headers.get("cf-ray") ?? "unspecified",
signature: response.headers.get("accelerate-signature") ?? "unspecified",
};
machineHint =
response.headers.get("accelerate-query-engine-jwt") ?? undefined;
return response;
};
};
if (__accelerateInfo) {
const data = await query(rest, __internalParams);
return { data, info };
}
else {
return query(rest, __internalParams);
}
};
}
function withAccelerate() {
return default_index_js_1.default.Prisma.defineExtension((client) => {
const withCacheHeaders = makeWithCacheHeaders();
const xclient = client.$extends({
name: EXTENSION_NAME,
query: {
$allModels: {
// also apply withCacheHeaders to mutations for machine hint benefit
$allOperations: withCacheHeaders,
},
count(params) {
const { args } = params;
const { cacheStrategy, ...rest } = args;
const { __internalParams, query } = params;
__internalParams.headers = {
...__internalParams.headers,
"cache-control": cacheStrategy
? `max-age=${cacheStrategy.ttl};stale-while-revalidate=${cacheStrategy.swr}`
: `no-cache`,
};
return query(rest, __internalParams);
},
findFirst(params) {
const { args } = params;
const { cacheStrategy, ...rest } = args;
const { __internalParams, query } = params;
__internalParams.headers = {
...__internalParams.headers,
"cache-control": cacheStrategy
? `max-age=${cacheStrategy.ttl};stale-while-revalidate=${cacheStrategy.swr}`
: `no-cache`,
};
return query(rest, __internalParams);
},
findFirstOrThrow(params) {
const { args } = params;
const { cacheStrategy, ...rest } = args;
const { __internalParams, query } = params;
__internalParams.headers = {
...__internalParams.headers,
"cache-control": cacheStrategy
? `max-age=${cacheStrategy.ttl};stale-while-revalidate=${cacheStrategy.swr}`
: `no-cache`,
};
return query(rest, __internalParams);
},
findMany(params) {
const { args } = params;
const { cacheStrategy, ...rest } = args;
const { __internalParams, query } = params;
__internalParams.headers = {
...__internalParams.headers,
"cache-control": cacheStrategy
? `max-age=${cacheStrategy.ttl};stale-while-revalidate=${cacheStrategy.swr}`
: `no-cache`,
};
return query(rest, __internalParams);
},
findUnique(params) {
const { args } = params;
const { cacheStrategy, ...rest } = args;
const { __internalParams, query } = params;
__internalParams.headers = {
...__internalParams.headers,
"cache-control": cacheStrategy
? `max-age=${cacheStrategy.ttl};stale-while-revalidate=${cacheStrategy.swr}`
: `no-cache`,
};
return query(rest, __internalParams);
},
findUniqueOrThrow(params) {
const { args } = params;
const { cacheStrategy, ...rest } = args;
const { __internalParams, query } = params;
__internalParams.headers = {
...__internalParams.headers,
"cache-control": cacheStrategy
? `max-age=${cacheStrategy.ttl};stale-while-revalidate=${cacheStrategy.swr}`
: `no-cache`,
};
return query(rest, __internalParams);
},
groupBy(params) {
const { args } = params;
const { cacheStrategy, ...rest } = args;
const { __internalParams, query } = params;
__internalParams.headers = {
...__internalParams.headers,
"cache-control": cacheStrategy
? `max-age=${cacheStrategy.ttl};stale-while-revalidate=${cacheStrategy.swr}`
: `no-cache`,
};
return query(rest, __internalParams);
},
},
},
});
return xclient.$extends({
name: EXTENSION_NAME,
model: {
$allModels: {
// TODO: these functions are repetitive. Is there a type we can use to generic this?
// TODO: can we define these in a map that ensures query and model overrides stay in sync/
aggregate(args) {
const ctx = client_1.Prisma.getExtensionContext(this);
return xclient[ctx.name].aggregate(args);
});
return xclient.$extends({
name: EXTENSION_NAME,
model: {
$allModels: {
// TODO: these functions are repetitive. Is there a type we can use to generic this?
// TODO: can we define these in a map that ensures query and model overrides stay in sync/
aggregate(args) {
const ctx = default_index_js_1.default.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].aggregate(args), {
withAccelerateInfo() {
return xclient[ctx.name].aggregate({
...args,
__accelerateInfo: true,
});
},
});
},
count(args) {
const ctx = default_index_js_1.default.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].count(args), {
withAccelerateInfo() {
return xclient[ctx.name].count({
...args,
__accelerateInfo: true,
});
},
});
},
findFirst(args) {
const ctx = default_index_js_1.default.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findFirst(args), {
withAccelerateInfo() {
return xclient[ctx.name].findFirst({
...args,
__accelerateInfo: true,
});
},
});
},
findFirstOrThrow(args) {
const ctx = default_index_js_1.default.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findFirstOrThrow(args), {
withAccelerateInfo() {
return xclient[ctx.name].findFirstOrThrow({
...args,
__accelerateInfo: true,
});
},
});
},
findMany(args) {
const ctx = default_index_js_1.default.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findMany(args), {
withAccelerateInfo() {
return xclient[ctx.name].findMany({
...args,
__accelerateInfo: true,
});
},
});
},
findUnique(args) {
const ctx = default_index_js_1.default.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findUnique(args), {
withAccelerateInfo() {
return xclient[ctx.name].findUnique({
...args,
__accelerateInfo: true,
});
},
});
},
findUniqueOrThrow(args) {
const ctx = default_index_js_1.default.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findUniqueOrThrow(args), {
withAccelerateInfo() {
return xclient[ctx.name].findUniqueOrThrow({
...args,
__accelerateInfo: true,
});
},
});
},
groupBy(args) {
const ctx = default_index_js_1.default.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].groupBy(args), {
withAccelerateInfo() {
return xclient[ctx.name].groupBy({
...args,
__accelerateInfo: true,
});
},
});
},
},
count(args) {
const ctx = client_1.Prisma.getExtensionContext(this);
return xclient[ctx.name].count(args);
},
findFirst(args) {
const ctx = client_1.Prisma.getExtensionContext(this);
return xclient[ctx.name].findFirst(args);
},
findFirstOrThrow(args) {
const ctx = client_1.Prisma.getExtensionContext(this);
return xclient[ctx.name].findFirstOrThrow(args);
},
findMany(args) {
const ctx = client_1.Prisma.getExtensionContext(this);
return xclient[ctx.name].findMany(args);
},
findUnique(args) {
const ctx = client_1.Prisma.getExtensionContext(this);
return xclient[ctx.name].findUnique(args);
},
findUniqueOrThrow(args) {
const ctx = client_1.Prisma.getExtensionContext(this);
return xclient[ctx.name].findUniqueOrThrow(args);
},
groupBy(args) {
const ctx = client_1.Prisma.getExtensionContext(this);
return xclient[ctx.name].groupBy(args);
},
},
},
});
});
});
}
exports.withAccelerate = withAccelerate;

@@ -1,37 +0,95 @@

import { Prisma } from "@prisma/client";
import type { Types } from "@prisma/client/runtime";
/// <reference lib="dom" />
import PrismaDefault, { type Prisma } from "@prisma/client/scripts/default-index.js";
import type { Types } from "@prisma/client/runtime/library.js";
export interface PrismaCacheStrategy {
/** TODO */
/**
* Specifies the caching parameters for Accelerate.
*
* `cacheStrategy` only applies when used with an Accelerate connection string.
*/
readonly cacheStrategy?: {
/** TODO */
/**
* `swr` is short for Stale-While-Revalidate.
*
* `swr` defines the number of seconds that Accelerate may serve _stale_ cache data.
* _Stale_ data is a cache hit, but the cache will be refreshed in the background by Accelerate.
* The Prisma operation will not be blocked while data is refreshed.
*
* Use `swr` to reduce the latency of accessing the data while still maintaining
* a more up-to-date value in the Accelerate cache.
* `swr` without `ttl` will not reduce database load since Accelerate will
* run the query in the background.
*
* `swr` can be combined with `ttl`.
* `swr` applies **after** `ttl` has expired.
* The total number of seconds data will be cached is `ttl + swr`.
*
* `swr` only applies when used with an Accelerate connection string.
*/
readonly swr?: number;
/**
* `ttl` is short for Time-to-Live.
*
* `ttl` defines the number of seconds that Accelerate may serve _fresh_ cache data.
* _Fresh_ data is a cache hit and will not execute the query against the database.
*
* Use `ttl` to reduce database load and latency for data that does not
* require frequent updates.
* `ttl` without `swr` will incur a blocking database query for the first
* request after `ttl` expires.
*
* It's recommended to combine `ttl` and `swr` to maintain low latency while
* Accelerate refreshes cached data in the background.
* `swr` applies **after** `ttl` has expired.
* The total number of seconds data will be cached is `ttl + swr`.
*
* `ttl` only applies when used with an Accelerate connection string.
*/
readonly ttl?: number;
};
}
declare const _default: (client: any) => import(".prisma/client").PrismaClient<any, any, any, {
result: {} & Record<string, {}>;
model: {} & Record<string, {}> & Record<string, {
aggregate: () => <T, A>(this: T, args: Prisma.Exact<A, Types.Public.Args<T, "aggregate"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T, A, "aggregate">>;
count: () => <T_1, A_1>(this: T_1, args: Prisma.Exact<A_1, Types.Public.Args<T_1, "count"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_1, A_1, "count">>;
findFirst: () => <T_2, A_2>(this: T_2, args: Prisma.Exact<A_2, Types.Public.Args<T_2, "findFirst"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_2, A_2, "findFirst">>;
findFirstOrThrow: () => <T_3, A_3>(this: T_3, args: Prisma.Exact<A_3, Types.Public.Args<T_3, "findFirstOrThrow"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_3, A_3, "findFirstOrThrow">>;
findMany: () => <T_4, A_4>(this: T_4, args: Prisma.Exact<A_4, Types.Public.Args<T_4, "findMany"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_4, A_4, "findMany">>;
findUnique: () => <T_5, A_5>(this: T_5, args: Prisma.Exact<A_5, Types.Public.Args<T_5, "findUnique"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_5, A_5, "findUnique">>;
findUniqueOrThrow: () => <T_6, A_6>(this: T_6, args: Prisma.Exact<A_6, Types.Public.Args<T_6, "findUniqueOrThrow"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_6, A_6, "findUniqueOrThrow">>;
groupBy: () => <T_7, A_7>(this: T_7, args: Prisma.Exact<A_7, Types.Public.Args<T_7, "groupBy"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_7, A_7, "groupBy">>;
}> & {
$allModels: {
aggregate: () => <T, A>(this: T, args: Prisma.Exact<A, Types.Public.Args<T, "aggregate"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T, A, "aggregate">>;
count: () => <T_1, A_1>(this: T_1, args: Prisma.Exact<A_1, Types.Public.Args<T_1, "count"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_1, A_1, "count">>;
findFirst: () => <T_2, A_2>(this: T_2, args: Prisma.Exact<A_2, Types.Public.Args<T_2, "findFirst"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_2, A_2, "findFirst">>;
findFirstOrThrow: () => <T_3, A_3>(this: T_3, args: Prisma.Exact<A_3, Types.Public.Args<T_3, "findFirstOrThrow"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_3, A_3, "findFirstOrThrow">>;
findMany: () => <T_4, A_4>(this: T_4, args: Prisma.Exact<A_4, Types.Public.Args<T_4, "findMany"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_4, A_4, "findMany">>;
findUnique: () => <T_5, A_5>(this: T_5, args: Prisma.Exact<A_5, Types.Public.Args<T_5, "findUnique"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_5, A_5, "findUnique">>;
findUniqueOrThrow: () => <T_6, A_6>(this: T_6, args: Prisma.Exact<A_6, Types.Public.Args<T_6, "findUniqueOrThrow"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_6, A_6, "findUniqueOrThrow">>;
groupBy: () => <T_7, A_7>(this: T_7, args: Prisma.Exact<A_7, Types.Public.Args<T_7, "groupBy"> & PrismaCacheStrategy>) => Promise<Types.Public.Result<T_7, A_7, "groupBy">>;
};
interface AccelerateInfo {
/**
* The cache status of the response.
* * `ttl` indicates a cache hit within the `ttl` duration and no database query was executed
* * `swr` indicates a cache hit within the `swr` duration and the data is being refreshed by Accelerate in the background
* * `miss` indicates that both `ttl` and `swr` have expired and the database query was executed by the request
* * `none` indicates that no cache strategy was specified and the database query was executed by the request
*/
cacheStatus: "ttl" | "swr" | "miss" | "none";
/**
* The date the response was last refreshed.
*/
lastModified: Date;
/**
* The datacenter region that received the request.
*/
region: string;
/**
* Unique identifier of the request. Useful for troubleshooting.
*/
requestId: string;
/**
* The unique signature of the Prisma operation.
*/
signature: string;
}
interface AcceleratePromise<T> extends Prisma.PrismaPromise<T> {
withAccelerateInfo(): Prisma.PrismaPromise<{
data: T;
info: AccelerateInfo | null;
}>;
}
export declare function withAccelerate(): (client: any) => PrismaDefault.PrismaClientExtends<Types.Extensions.InternalArgs<{}, {
$allModels: {
aggregate<T, A>(this: T, args: Prisma.Exact<A, Prisma.Args<T, "aggregate"> & PrismaCacheStrategy>): AcceleratePromise<Prisma.Result<T, A, "aggregate">>;
count<T_1, A_1>(this: T_1, args?: Prisma.Exact<A_1, Prisma.Args<T_1, "count"> & PrismaCacheStrategy>): AcceleratePromise<Prisma.Result<T_1, A_1, "count">>;
findFirst<T_2, A_2>(this: T_2, args?: Prisma.Exact<A_2, Prisma.Args<T_2, "findFirst"> & PrismaCacheStrategy>): AcceleratePromise<Prisma.Result<T_2, A_2, "findFirst">>;
findFirstOrThrow<T_3, A_3>(this: T_3, args?: Prisma.Exact<A_3, Prisma.Args<T_3, "findFirstOrThrow"> & PrismaCacheStrategy>): AcceleratePromise<Prisma.Result<T_3, A_3, "findFirstOrThrow">>;
findMany<T_4, A_4>(this: T_4, args?: Prisma.Exact<A_4, Prisma.Args<T_4, "findMany"> & PrismaCacheStrategy>): AcceleratePromise<Prisma.Result<T_4, A_4, "findMany">>;
findUnique<T_5, A_5>(this: T_5, args: Prisma.Exact<A_5, Prisma.Args<T_5, "findUnique"> & PrismaCacheStrategy>): AcceleratePromise<Prisma.Result<T_5, A_5, "findUnique">>;
findUniqueOrThrow<T_6, A_6>(this: T_6, args: Prisma.Exact<A_6, Prisma.Args<T_6, "findUniqueOrThrow"> & PrismaCacheStrategy>): AcceleratePromise<Prisma.Result<T_6, A_6, "findUniqueOrThrow">>;
groupBy<T_7, A_7>(this: T_7, args: Prisma.Exact<A_7, Prisma.Args<T_7, "groupBy"> & PrismaCacheStrategy>): AcceleratePromise<Prisma.Result<T_7, A_7, "groupBy">>;
};
client: {};
query: {};
}>;
export default _default;
}, {}, {}> & Types.Extensions.InternalArgs<{}, {}, {}, {}> & Types.Extensions.DefaultArgs>;
export {};

@@ -1,147 +0,173 @@

var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/// <reference lib="dom" />
// importing default is needed for ESM compatibility
// default-index is a CJS file, so named exports are not resolved
// the types create a separate resolution issue, so they are still imported by name
import PrismaDefault, {} from "@prisma/client/scripts/default-index.js";
const EXTENSION_NAME = "@prisma/extension-accelerate";
function makeWithCacheHeaders() {
let machineHint = undefined;
async function getFetcher() {
if (typeof globalThis?.fetch === "function") {
return globalThis.fetch;
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
else {
const { fetch } = await import("./node-fetch.js");
return fetch;
}
return t;
};
import { Prisma } from "@prisma/client";
var EXTENSION_NAME = "@prisma/extension-accelerate";
export default Prisma.defineExtension(function (client) {
var xclient = client.$extends({
name: EXTENSION_NAME,
query: {
$allModels: {
// TODO: these functions are repetitive. Is there a type we can use to generic this?
aggregate: function (params) {
var args = params.args;
var _a = args, cacheStrategy = _a.cacheStrategy, rest = __rest(_a, ["cacheStrategy"]);
var _b = params, __internalParams = _b.__internalParams, query = _b.query;
__internalParams.headers = __assign(__assign({}, __internalParams.headers), { "cache-control": cacheStrategy
? "max-age=".concat(cacheStrategy.ttl, ";stale-while-revalidate=").concat(cacheStrategy.swr)
: "no-cache" });
return query(rest, __internalParams);
},
count: function (params) {
var args = params.args;
var _a = args, cacheStrategy = _a.cacheStrategy, rest = __rest(_a, ["cacheStrategy"]);
var _b = params, __internalParams = _b.__internalParams, query = _b.query;
__internalParams.headers = __assign(__assign({}, __internalParams.headers), { "cache-control": cacheStrategy
? "max-age=".concat(cacheStrategy.ttl, ";stale-while-revalidate=").concat(cacheStrategy.swr)
: "no-cache" });
return query(rest, __internalParams);
},
findFirst: function (params) {
var args = params.args;
var _a = args, cacheStrategy = _a.cacheStrategy, rest = __rest(_a, ["cacheStrategy"]);
var _b = params, __internalParams = _b.__internalParams, query = _b.query;
__internalParams.headers = __assign(__assign({}, __internalParams.headers), { "cache-control": cacheStrategy
? "max-age=".concat(cacheStrategy.ttl, ";stale-while-revalidate=").concat(cacheStrategy.swr)
: "no-cache" });
return query(rest, __internalParams);
},
findFirstOrThrow: function (params) {
var args = params.args;
var _a = args, cacheStrategy = _a.cacheStrategy, rest = __rest(_a, ["cacheStrategy"]);
var _b = params, __internalParams = _b.__internalParams, query = _b.query;
__internalParams.headers = __assign(__assign({}, __internalParams.headers), { "cache-control": cacheStrategy
? "max-age=".concat(cacheStrategy.ttl, ";stale-while-revalidate=").concat(cacheStrategy.swr)
: "no-cache" });
return query(rest, __internalParams);
},
findMany: function (params) {
var args = params.args;
var _a = args, cacheStrategy = _a.cacheStrategy, rest = __rest(_a, ["cacheStrategy"]);
var _b = params, __internalParams = _b.__internalParams, query = _b.query;
__internalParams.headers = __assign(__assign({}, __internalParams.headers), { "cache-control": cacheStrategy
? "max-age=".concat(cacheStrategy.ttl, ";stale-while-revalidate=").concat(cacheStrategy.swr)
: "no-cache" });
return query(rest, __internalParams);
},
findUnique: function (params) {
var args = params.args;
var _a = args, cacheStrategy = _a.cacheStrategy, rest = __rest(_a, ["cacheStrategy"]);
var _b = params, __internalParams = _b.__internalParams, query = _b.query;
__internalParams.headers = __assign(__assign({}, __internalParams.headers), { "cache-control": cacheStrategy
? "max-age=".concat(cacheStrategy.ttl, ";stale-while-revalidate=").concat(cacheStrategy.swr)
: "no-cache" });
return query(rest, __internalParams);
},
findUniqueOrThrow: function (params) {
var args = params.args;
var _a = args, cacheStrategy = _a.cacheStrategy, rest = __rest(_a, ["cacheStrategy"]);
var _b = params, __internalParams = _b.__internalParams, query = _b.query;
__internalParams.headers = __assign(__assign({}, __internalParams.headers), { "cache-control": cacheStrategy
? "max-age=".concat(cacheStrategy.ttl, ";stale-while-revalidate=").concat(cacheStrategy.swr)
: "no-cache" });
return query(rest, __internalParams);
},
groupBy: function (params) {
var args = params.args;
var _a = args, cacheStrategy = _a.cacheStrategy, rest = __rest(_a, ["cacheStrategy"]);
var _b = params, __internalParams = _b.__internalParams, query = _b.query;
__internalParams.headers = __assign(__assign({}, __internalParams.headers), { "cache-control": cacheStrategy
? "max-age=".concat(cacheStrategy.ttl, ";stale-while-revalidate=").concat(cacheStrategy.swr)
: "no-cache" });
return query(rest, __internalParams);
}
return async (params) => {
const { args } = params;
const { cacheStrategy, __accelerateInfo = false, ...rest } = args;
let info = null;
const { __internalParams, query } = params;
__internalParams.customDataProxyFetch = () => {
return async (url, options) => {
const cacheControl = new Array();
if (typeof cacheStrategy?.ttl === "number") {
cacheControl.push(`max-age=${cacheStrategy.ttl}`);
}
}
if (typeof cacheStrategy?.swr === "number") {
cacheControl.push(`stale-while-revalidate=${cacheStrategy.swr}`);
}
options.headers = {
...options.headers,
"cache-control": cacheControl.length > 0 ? cacheControl.join(",") : `no-cache`,
};
if (machineHint) {
options.headers["accelerate-query-engine-jwt"] = machineHint;
}
const fetch = await getFetcher();
const response = await fetch(url, options);
info = {
cacheStatus: response.headers.get("accelerate-cache-status"),
lastModified: new Date(response.headers.get("last-modified") ?? ""),
region: response.headers.get("cf-ray")?.split("-")[1] ?? "unspecified",
requestId: response.headers.get("cf-ray") ?? "unspecified",
signature: response.headers.get("accelerate-signature") ?? "unspecified",
};
machineHint =
response.headers.get("accelerate-query-engine-jwt") ?? undefined;
return response;
};
};
if (__accelerateInfo) {
const data = await query(rest, __internalParams);
return { data, info };
}
});
return xclient.$extends({
name: EXTENSION_NAME,
model: {
$allModels: {
// TODO: these functions are repetitive. Is there a type we can use to generic this?
// TODO: can we define these in a map that ensures query and model overrides stay in sync/
aggregate: function (args) {
var ctx = Prisma.getExtensionContext(this);
return xclient[ctx.name].aggregate(args);
else {
return query(rest, __internalParams);
}
};
}
export function withAccelerate() {
return PrismaDefault.Prisma.defineExtension((client) => {
const withCacheHeaders = makeWithCacheHeaders();
const xclient = client.$extends({
name: EXTENSION_NAME,
query: {
$allModels: {
// also apply withCacheHeaders to mutations for machine hint benefit
$allOperations: withCacheHeaders,
},
count: function (args) {
var ctx = Prisma.getExtensionContext(this);
return xclient[ctx.name].count(args);
},
});
return xclient.$extends({
name: EXTENSION_NAME,
model: {
$allModels: {
// TODO: these functions are repetitive. Is there a type we can use to generic this?
// TODO: can we define these in a map that ensures query and model overrides stay in sync/
aggregate(args) {
const ctx = PrismaDefault.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].aggregate(args), {
withAccelerateInfo() {
return xclient[ctx.name].aggregate({
...args,
__accelerateInfo: true,
});
},
});
},
count(args) {
const ctx = PrismaDefault.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].count(args), {
withAccelerateInfo() {
return xclient[ctx.name].count({
...args,
__accelerateInfo: true,
});
},
});
},
findFirst(args) {
const ctx = PrismaDefault.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findFirst(args), {
withAccelerateInfo() {
return xclient[ctx.name].findFirst({
...args,
__accelerateInfo: true,
});
},
});
},
findFirstOrThrow(args) {
const ctx = PrismaDefault.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findFirstOrThrow(args), {
withAccelerateInfo() {
return xclient[ctx.name].findFirstOrThrow({
...args,
__accelerateInfo: true,
});
},
});
},
findMany(args) {
const ctx = PrismaDefault.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findMany(args), {
withAccelerateInfo() {
return xclient[ctx.name].findMany({
...args,
__accelerateInfo: true,
});
},
});
},
findUnique(args) {
const ctx = PrismaDefault.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findUnique(args), {
withAccelerateInfo() {
return xclient[ctx.name].findUnique({
...args,
__accelerateInfo: true,
});
},
});
},
findUniqueOrThrow(args) {
const ctx = PrismaDefault.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findUniqueOrThrow(args), {
withAccelerateInfo() {
return xclient[ctx.name].findUniqueOrThrow({
...args,
__accelerateInfo: true,
});
},
});
},
groupBy(args) {
const ctx = PrismaDefault.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].groupBy(args), {
withAccelerateInfo() {
return xclient[ctx.name].groupBy({
...args,
__accelerateInfo: true,
});
},
});
},
},
findFirst: function (args) {
var ctx = Prisma.getExtensionContext(this);
return xclient[ctx.name].findFirst(args);
},
findFirstOrThrow: function (args) {
var ctx = Prisma.getExtensionContext(this);
return xclient[ctx.name].findFirstOrThrow(args);
},
findMany: function (args) {
var ctx = Prisma.getExtensionContext(this);
return xclient[ctx.name].findMany(args);
},
findUnique: function (args) {
var ctx = Prisma.getExtensionContext(this);
return xclient[ctx.name].findUnique(args);
},
findUniqueOrThrow: function (args) {
var ctx = Prisma.getExtensionContext(this);
return xclient[ctx.name].findUniqueOrThrow(args);
},
groupBy: function (args) {
var ctx = Prisma.getExtensionContext(this);
return xclient[ctx.name].groupBy(args);
}
}
}
},
});
});
});
}
{
"name": "@prisma/extension-accelerate",
"type": "module",
"version": "0.0.0-experimental-b1c4b75",
"version": "0.0.0-experimental-c1e4c49",
"description": "Prisma Client extension for Accelerate",

@@ -19,2 +19,3 @@ "sideEffects": false,

"lint:check": "eslint src/** --max-warnings 0",
"test": "node --test --loader dotenv/config --loader ts-node/esm test/*.test.ts",
"types:check": "tsc --noEmit"

@@ -26,17 +27,21 @@ },

"devDependencies": {
"@prisma/client": "4.9.0-integration-feat-client-ext-generic-type-api.11",
"@tsconfig/esm": "^1.0.2",
"@prisma/client": "^5.0.0",
"@tsconfig/esm": "^1.0.4",
"@tsconfig/node14": "^1.0.3",
"@tsconfig/node18-strictest-esm": "^1.0.1",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.1",
"eslint": "^8.30.0",
"prettier": "2.8.1",
"prisma": "4.9.0-integration-feat-client-ext-generic-type-api.11",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"dotenv": "^16.3.1",
"eslint": "^8.44.0",
"prettier": "2.8.8",
"prisma": "^5.0.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
"typescript": "^5.1.6"
},
"peerDependencies": {
"@prisma/client": "4.9.0-integration-feat-client-ext-generic-type-api.11"
"@prisma/client": ">=5.0.0"
},
"engines": {
"node": ">=16"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc