@prisma/extension-accelerate
Advanced tools
Comparing version 0.0.0-experimental-da133af to 0.0.0-experimental-da4f4f5
@@ -8,2 +8,5 @@ /// <reference lib="dom" /> | ||
export type RequestResponse = { | ||
body?: { | ||
cancel(): Promise<void>; | ||
} | null; | ||
ok: boolean; | ||
@@ -10,0 +13,0 @@ url: string; |
"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 __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
@@ -30,5 +7,9 @@ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var _NodeHeaders_headers; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fetch = void 0; | ||
const node_https_1 = __importDefault(require("node:https")); | ||
/** | ||
@@ -46,6 +27,5 @@ * Imitates `fetch` via `https` to only suit our needs, it does nothing more. | ||
const { origin } = new URL(url); | ||
const https = await facadeImport("node:https"); | ||
return new Promise((resolve, reject) => { | ||
// we execute the https request and build a fetch response out of it | ||
const request = https.request(url, httpsOptions, (response) => { | ||
const request = node_https_1.default.request(url, httpsOptions, (response) => { | ||
const { statusCode = 200, headers: { location }, } = response; | ||
@@ -100,2 +80,7 @@ if (statusCode >= 301 && statusCode <= 399 && location) { | ||
return { | ||
body: { | ||
cancel() { | ||
return Promise.resolve(); | ||
}, | ||
}, | ||
text: () => Promise.resolve(Buffer.concat(incomingData).toString()), | ||
@@ -133,2 +118,5 @@ json: () => Promise.resolve(JSON.parse(Buffer.concat(incomingData).toString())), | ||
} | ||
getSetCookie() { | ||
throw new Error("Method not implemented."); | ||
} | ||
has(name) { | ||
@@ -147,5 +135,1 @@ return __classPrivateFieldGet(this, _NodeHeaders_headers, "f").has(name); | ||
_NodeHeaders_headers = new WeakMap(); | ||
/** This is needed to obfuscate the import from Cloudflare's bundling. */ | ||
function facadeImport(path) { | ||
return Promise.resolve(`${path}`).then(s => __importStar(require(s))); | ||
} |
@@ -8,2 +8,5 @@ /// <reference lib="dom" /> | ||
export type RequestResponse = { | ||
body?: { | ||
cancel(): Promise<void>; | ||
} | null; | ||
ok: boolean; | ||
@@ -10,0 +13,0 @@ url: string; |
@@ -0,1 +1,2 @@ | ||
import https from "node:https"; | ||
/** | ||
@@ -13,3 +14,2 @@ * Imitates `fetch` via `https` to only suit our needs, it does nothing more. | ||
const { origin } = new URL(url); | ||
const https = await facadeImport("node:https"); | ||
return new Promise((resolve, reject) => { | ||
@@ -66,2 +66,7 @@ // we execute the https request and build a fetch response out of it | ||
return { | ||
body: { | ||
cancel() { | ||
return Promise.resolve(); | ||
}, | ||
}, | ||
text: () => Promise.resolve(Buffer.concat(incomingData).toString()), | ||
@@ -99,2 +104,5 @@ json: () => Promise.resolve(JSON.parse(Buffer.concat(incomingData).toString())), | ||
} | ||
getSetCookie() { | ||
throw new Error("Method not implemented."); | ||
} | ||
has(name) { | ||
@@ -112,5 +120,1 @@ return this.#headers.has(name); | ||
} | ||
/** This is needed to obfuscate the import from Cloudflare's bundling. */ | ||
function facadeImport(path) { | ||
return import(path); | ||
} |
{ | ||
"name": "@prisma/extension-accelerate", | ||
"type": "module", | ||
"version": "0.0.0-experimental-da133af", | ||
"version": "0.0.0-experimental-da4f4f5", | ||
"description": "Prisma Client extension for Accelerate", | ||
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
"import": "./dist/esm/index.js", | ||
"require": "./dist/cjs/index.js" | ||
} | ||
"node": { | ||
"import": "./dist/esm/entry.node.js", | ||
"require": "./dist/cjs/entry.node.js" | ||
}, | ||
"import": "./dist/esm/entry.fetch.js", | ||
"require": "./dist/cjs/entry.fetch.js", | ||
"default": "./dist/esm/entry.fetch.js" | ||
}, | ||
"types": "./dist/cjs/index.d.ts", | ||
"types": "./dist/cjs/entry.node.d.ts", | ||
"scripts": { | ||
@@ -26,12 +29,12 @@ "build": "./scripts/build.sh", | ||
"devDependencies": { | ||
"@prisma/client": "^5.1.0", | ||
"@tsconfig/esm": "^1.0.4", | ||
"@tsconfig/node14": "^1.0.3", | ||
"@tsconfig/node18-strictest-esm": "^1.0.1", | ||
"@typescript-eslint/eslint-plugin": "^5.61.0", | ||
"@typescript-eslint/parser": "^5.61.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.44.0", | ||
"prettier": "2.8.8", | ||
"prisma": "^5.1.0", | ||
"eslint": "^8.47.0", | ||
"prettier": "^3.0.2", | ||
"prisma": "^5.2.0", | ||
"ts-node": "^10.9.1", | ||
@@ -41,3 +44,3 @@ "typescript": "^5.1.6" | ||
"peerDependencies": { | ||
"@prisma/client": ">=5.0.0" | ||
"@prisma/client": ">=4.16.1" | ||
}, | ||
@@ -44,0 +47,0 @@ "engines": { |
# Accelerate Prisma Client extension | ||
Prisma Client extension to enable _Accelerate_. | ||
This is the package for the [Prisma Client extension](https://www.prisma.io/docs/concepts/components/prisma-client/client-extensions?utm_source=github&utm_medium=accelerate-readme) that enables usage of Prisma Accelerate. | ||
[Prisma Accelerate](https://www.prisma.io/data-platform/accelerate?utm_source=github&utm_medium=accelerate-readme) provides an external connection pool and global caching layer that you can use to speed up your database queries. | ||
It is part of the [Prisma](https://www.prisma.io?utm_source=github&utm_medium=accelerate-readme) ecosystem, alongside other tools such as: | ||
- [Prisma ORM](https://github.com/prisma/prisma): Next-generation Node.js and TypeScript ORM, supporting PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, CockroachDB, and MongoDB. | ||
- [Prisma Pulse](https://www.prisma.io/data-platform/pulse?utm_source=github&utm_medium=accelerate-readme): Real-time database events with type-safe subscriptions. | ||
Prisma is leading Data DX, a philosophy that promotes simplicity in data-driven application development. Learn more on the [Data DX manifesto](https://www.datadx.io/?utm_source=github&utm_medium=accelerate-readme). | ||
## Getting started with Accelerate | ||
### Resources | ||
You can explore Accelerate with the following resources: | ||
- [Get started](https://www.prisma.io/docs/data-platform/accelerate/getting-started?utm_source=github&utm_medium=accelerate-readme) | ||
- [Documentation](https://www.prisma.io/docs/data-platform/accelerate/what-is-accelerate?utm_source=github&utm_medium=accelerate-readme) | ||
- [Prisma Data Platform](https://console.prisma.io/login?utm_source=github&utm_medium=accelerate-readme) | ||
- [Accelerate Speed Test](https://accelerate-speed-test.prisma.io/?utm_source=github&utm_medium=accelerate-readme) | ||
### Using Accelerate | ||
#### 1. Enable Accelerate | ||
Log into [Prisma Data Platform](https://console.prisma.io/login?utm_source=github&utm_medium=accelerate-readme) and enable Accelerate for your project. | ||
#### 2. Add Accelerate to your application | ||
Replace the database connection string with the Accelerate connection string you generated in Prisma Data Platform (assuming you store your database connection string in the `DATABASE_URL` in the `.env` file): | ||
```bash | ||
DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=__API_KEY__" | ||
``` | ||
To be able to seamlessly continue to use Prisma Migrate, you can set the `directUrl` property in your `datasource`: | ||
```prisma | ||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
directUrl = env("DIRECT_DATABASE_URL") | ||
} | ||
``` | ||
And then add the URL that connects directly to your database as the value for `DIRECT_DATABASE_URL` : | ||
```prisma | ||
DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=__API_KEY__" | ||
DIRECT_DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE" | ||
``` | ||
Finally, extend your Prisma Client instance with the Accelerate extension to enable Accelerate’s connection pool: | ||
```ts | ||
import { PrismaClient } from "@prisma/client/edge"; | ||
import { withAccelerate } from "@prisma/extension-accelerate"; | ||
const prisma = new PrismaClient().$extends(withAccelerate()); | ||
``` | ||
#### 3. Add caching to your Accelerate queries | ||
You can optionally configure caching on a per-query level using the `ttl` (Time-To-Live) and `swl` (Stale-While-Revalidate) options: | ||
```ts | ||
await prisma.user.findMany({ | ||
cacheStrategy: { | ||
ttl: 3_600, | ||
swr: 500, | ||
}, | ||
}); | ||
``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
72507
28
1326
77
1
8