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-d1bf086 to 0.0.0-experimental-d53976b

dist/cjs/index.d.ts

127

dist/cjs/index.js

@@ -13,5 +13,17 @@ "use strict";

const default_index_js_1 = __importDefault(require("@prisma/client/scripts/default-index.js"));
const semver_js_1 = require("./semver.js");
const user_agent_js_1 = require("./user-agent.js");
const EXTENSION_NAME = "@prisma/extension-accelerate";
function makeWithCacheHeaders() {
const userAgent = (0, user_agent_js_1.getUserAgent)();
let machineHint = undefined;
async function getFetcher() {
if (typeof globalThis?.fetch === "function") {
return globalThis.fetch;
}
else {
const { fetch } = await import("./node-fetch.js");
return fetch;
}
}
return async (params) => {

@@ -22,3 +34,3 @@ const { args } = params;

const { __internalParams, query } = params;
__internalParams.customDataProxyFetch = (fetch) => {
__internalParams.customDataProxyFetch = () => {
return async (url, options) => {

@@ -35,2 +47,3 @@ const cacheControl = new Array();

"cache-control": cacheControl.length > 0 ? cacheControl.join(",") : `no-cache`,
"user-agent": userAgent,
};

@@ -40,27 +53,13 @@ if (machineHint) {

}
const fetch = await getFetcher();
const response = await fetch(url, options);
// Response is not available in Node 16 and lower, so we need to detect it
if ("Response" in globalThis && response instanceof Response) {
// on non-Node runtimes, response will be a Response instance
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;
}
else if (typeof response === "object") {
// in Node, response will be an object
info = {
cacheStatus: response.headers["accelerate-cache-status"],
lastModified: new Date(response.headers["last-modified"]),
region: response.headers["cf-ray"]?.split("-")[1] ?? "unspecified",
requestId: response.headers["cf-ray"] ?? "unspecified",
signature: response.headers["accelerate-signature"] ?? "unspecified",
};
machineHint = response.headers["accelerate-query-engine-jwt"];
}
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;

@@ -79,2 +78,4 @@ };

function withAccelerate() {
// ctx.$parent was added in 5.1.0 to support iTx in extensions
const enableCtxParent = (0, semver_js_1.compareSemVer)("5.1.0", default_index_js_1.default.Prisma.prismaVersion.client) >= 0;
return default_index_js_1.default.Prisma.defineExtension((client) => {

@@ -86,10 +87,4 @@ const withCacheHeaders = makeWithCacheHeaders();

$allModels: {
aggregate: withCacheHeaders,
count: withCacheHeaders,
findFirst: withCacheHeaders,
findFirstOrThrow: withCacheHeaders,
findMany: withCacheHeaders,
findUnique: withCacheHeaders,
findUniqueOrThrow: withCacheHeaders,
groupBy: withCacheHeaders,
// also apply withCacheHeaders to mutations for machine hint benefit
$allOperations: withCacheHeaders,
},

@@ -106,5 +101,9 @@ },

const ctx = default_index_js_1.default.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].aggregate(args), {
const model = enableCtxParent
? ctx.$parent[ctx.$name]
: xclient[ctx.name];
const prismaPromise = model.aggregate(args);
return Object.assign(prismaPromise, {
withAccelerateInfo() {
return xclient[ctx.name].aggregate({
return model.aggregate({
...args,

@@ -118,5 +117,9 @@ __accelerateInfo: true,

const ctx = default_index_js_1.default.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].count(args), {
const model = enableCtxParent
? ctx.$parent[ctx.$name]
: xclient[ctx.name];
const prismaPromise = model.count(args);
return Object.assign(prismaPromise, {
withAccelerateInfo() {
return xclient[ctx.name].count({
return model.count({
...args,

@@ -130,5 +133,9 @@ __accelerateInfo: true,

const ctx = default_index_js_1.default.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findFirst(args), {
const model = enableCtxParent
? ctx.$parent[ctx.$name]
: xclient[ctx.name];
const prismaPromise = model.findFirst(args);
return Object.assign(prismaPromise, {
withAccelerateInfo() {
return xclient[ctx.name].findFirst({
return model.findFirst({
...args,

@@ -142,5 +149,9 @@ __accelerateInfo: true,

const ctx = default_index_js_1.default.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findFirstOrThrow(args), {
const model = enableCtxParent
? ctx.$parent[ctx.$name]
: xclient[ctx.name];
const prismaPromise = model.findFirstOrThrow(args);
return Object.assign(prismaPromise, {
withAccelerateInfo() {
return xclient[ctx.name].findFirstOrThrow({
return model.findFirstOrThrow({
...args,

@@ -154,5 +165,9 @@ __accelerateInfo: true,

const ctx = default_index_js_1.default.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findMany(args), {
const model = enableCtxParent
? ctx.$parent[ctx.$name]
: xclient[ctx.name];
const prismaPromise = model.findMany(args);
return Object.assign(prismaPromise, {
withAccelerateInfo() {
return xclient[ctx.name].findMany({
return model.findMany({
...args,

@@ -166,5 +181,9 @@ __accelerateInfo: true,

const ctx = default_index_js_1.default.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findUnique(args), {
const model = enableCtxParent
? ctx.$parent[ctx.$name]
: xclient[ctx.name];
const prismaPromise = model.findUnique(args);
return Object.assign(prismaPromise, {
withAccelerateInfo() {
return xclient[ctx.name].findUnique({
return model.findUnique({
...args,

@@ -178,5 +197,9 @@ __accelerateInfo: true,

const ctx = default_index_js_1.default.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findUniqueOrThrow(args), {
const model = enableCtxParent
? ctx.$parent[ctx.$name]
: xclient[ctx.name];
const prismaPromise = model.findUniqueOrThrow(args);
return Object.assign(prismaPromise, {
withAccelerateInfo() {
return xclient[ctx.name].findUniqueOrThrow({
return model.findUniqueOrThrow({
...args,

@@ -190,5 +213,9 @@ __accelerateInfo: true,

const ctx = default_index_js_1.default.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].groupBy(args), {
const model = enableCtxParent
? ctx.$parent[ctx.$name]
: xclient[ctx.name];
const prismaPromise = model.groupBy(args);
return Object.assign(prismaPromise, {
withAccelerateInfo() {
return xclient[ctx.name].groupBy({
return model.groupBy({
...args,

@@ -206,3 +233,1 @@ __accelerateInfo: true,

exports.withAccelerate = withAccelerate;
/** @deprecated The default export has been replaced by `withAccelerate`. */
exports.default = withAccelerate();

@@ -7,5 +7,17 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */

import PrismaDefault from "@prisma/client/scripts/default-index.js";
import { compareSemVer } from "./semver.js";
import { getUserAgent } from "./user-agent.js";
const EXTENSION_NAME = "@prisma/extension-accelerate";
function makeWithCacheHeaders() {
const userAgent = getUserAgent();
let machineHint = undefined;
async function getFetcher() {
if (typeof globalThis?.fetch === "function") {
return globalThis.fetch;
}
else {
const { fetch } = await import("./node-fetch.js");
return fetch;
}
}
return async (params) => {

@@ -16,3 +28,3 @@ const { args } = params;

const { __internalParams, query } = params;
__internalParams.customDataProxyFetch = (fetch) => {
__internalParams.customDataProxyFetch = () => {
return async (url, options) => {

@@ -29,2 +41,3 @@ const cacheControl = new Array();

"cache-control": cacheControl.length > 0 ? cacheControl.join(",") : `no-cache`,
"user-agent": userAgent,
};

@@ -34,27 +47,13 @@ if (machineHint) {

}
const fetch = await getFetcher();
const response = await fetch(url, options);
// Response is not available in Node 16 and lower, so we need to detect it
if ("Response" in globalThis && response instanceof Response) {
// on non-Node runtimes, response will be a Response instance
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;
}
else if (typeof response === "object") {
// in Node, response will be an object
info = {
cacheStatus: response.headers["accelerate-cache-status"],
lastModified: new Date(response.headers["last-modified"]),
region: response.headers["cf-ray"]?.split("-")[1] ?? "unspecified",
requestId: response.headers["cf-ray"] ?? "unspecified",
signature: response.headers["accelerate-signature"] ?? "unspecified",
};
machineHint = response.headers["accelerate-query-engine-jwt"];
}
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;

@@ -73,2 +72,4 @@ };

export function withAccelerate() {
// ctx.$parent was added in 5.1.0 to support iTx in extensions
const enableCtxParent = compareSemVer("5.1.0", PrismaDefault.Prisma.prismaVersion.client) >= 0;
return PrismaDefault.Prisma.defineExtension((client) => {

@@ -80,10 +81,4 @@ const withCacheHeaders = makeWithCacheHeaders();

$allModels: {
aggregate: withCacheHeaders,
count: withCacheHeaders,
findFirst: withCacheHeaders,
findFirstOrThrow: withCacheHeaders,
findMany: withCacheHeaders,
findUnique: withCacheHeaders,
findUniqueOrThrow: withCacheHeaders,
groupBy: withCacheHeaders,
// also apply withCacheHeaders to mutations for machine hint benefit
$allOperations: withCacheHeaders,
},

@@ -100,5 +95,9 @@ },

const ctx = PrismaDefault.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].aggregate(args), {
const model = enableCtxParent
? ctx.$parent[ctx.$name]
: xclient[ctx.name];
const prismaPromise = model.aggregate(args);
return Object.assign(prismaPromise, {
withAccelerateInfo() {
return xclient[ctx.name].aggregate({
return model.aggregate({
...args,

@@ -112,5 +111,9 @@ __accelerateInfo: true,

const ctx = PrismaDefault.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].count(args), {
const model = enableCtxParent
? ctx.$parent[ctx.$name]
: xclient[ctx.name];
const prismaPromise = model.count(args);
return Object.assign(prismaPromise, {
withAccelerateInfo() {
return xclient[ctx.name].count({
return model.count({
...args,

@@ -124,5 +127,9 @@ __accelerateInfo: true,

const ctx = PrismaDefault.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findFirst(args), {
const model = enableCtxParent
? ctx.$parent[ctx.$name]
: xclient[ctx.name];
const prismaPromise = model.findFirst(args);
return Object.assign(prismaPromise, {
withAccelerateInfo() {
return xclient[ctx.name].findFirst({
return model.findFirst({
...args,

@@ -136,5 +143,9 @@ __accelerateInfo: true,

const ctx = PrismaDefault.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findFirstOrThrow(args), {
const model = enableCtxParent
? ctx.$parent[ctx.$name]
: xclient[ctx.name];
const prismaPromise = model.findFirstOrThrow(args);
return Object.assign(prismaPromise, {
withAccelerateInfo() {
return xclient[ctx.name].findFirstOrThrow({
return model.findFirstOrThrow({
...args,

@@ -148,5 +159,9 @@ __accelerateInfo: true,

const ctx = PrismaDefault.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findMany(args), {
const model = enableCtxParent
? ctx.$parent[ctx.$name]
: xclient[ctx.name];
const prismaPromise = model.findMany(args);
return Object.assign(prismaPromise, {
withAccelerateInfo() {
return xclient[ctx.name].findMany({
return model.findMany({
...args,

@@ -160,5 +175,9 @@ __accelerateInfo: true,

const ctx = PrismaDefault.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findUnique(args), {
const model = enableCtxParent
? ctx.$parent[ctx.$name]
: xclient[ctx.name];
const prismaPromise = model.findUnique(args);
return Object.assign(prismaPromise, {
withAccelerateInfo() {
return xclient[ctx.name].findUnique({
return model.findUnique({
...args,

@@ -172,5 +191,9 @@ __accelerateInfo: true,

const ctx = PrismaDefault.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].findUniqueOrThrow(args), {
const model = enableCtxParent
? ctx.$parent[ctx.$name]
: xclient[ctx.name];
const prismaPromise = model.findUniqueOrThrow(args);
return Object.assign(prismaPromise, {
withAccelerateInfo() {
return xclient[ctx.name].findUniqueOrThrow({
return model.findUniqueOrThrow({
...args,

@@ -184,5 +207,9 @@ __accelerateInfo: true,

const ctx = PrismaDefault.Prisma.getExtensionContext(this);
return Object.assign(xclient[ctx.name].groupBy(args), {
const model = enableCtxParent
? ctx.$parent[ctx.$name]
: xclient[ctx.name];
const prismaPromise = model.groupBy(args);
return Object.assign(prismaPromise, {
withAccelerateInfo() {
return xclient[ctx.name].groupBy({
return model.groupBy({
...args,

@@ -199,3 +226,1 @@ __accelerateInfo: true,

}
/** @deprecated The default export has been replaced by `withAccelerate`. */
export default withAccelerate();
{
"name": "@prisma/extension-accelerate",
"type": "module",
"version": "0.0.0-experimental-d1bf086",
"version": "0.0.0-experimental-d53976b",
"description": "Prisma Client extension for Accelerate",

@@ -26,18 +26,21 @@ "sideEffects": false,

"devDependencies": {
"@prisma/client": "^4.16.0",
"@tsconfig/esm": "^1.0.2",
"@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",
"dotenv": "^16.0.3",
"eslint": "^8.30.0",
"prettier": "2.8.1",
"prisma": "^4.16.0",
"@prisma/client": "^5.2.0",
"@tsconfig/node-lts": "^18.12.4",
"@tsconfig/node16": "^16.1.1",
"@tsconfig/strictest": "^2.0.1",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.1",
"dotenv": "^16.3.1",
"eslint": "^8.47.0",
"prettier": "^3.0.2",
"prisma": "^5.2.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
"typescript": "^5.1.6"
},
"peerDependencies": {
"@prisma/client": ">=4.16.0"
"@prisma/client": ">=4.16.1"
},
"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