prisma-sharding 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +237 -59
- package/dist/cli/migrate.js +327 -70
- package/dist/cli/studio.js +668 -59
- package/dist/cli/test.js +169 -59
- package/dist/cli/update.js +340 -75
- package/dist/cli/utils/command.js +232 -0
- package/dist/cli/utils/postgres.js +55 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +414 -90
- package/dist/index.mjs +414 -90
- package/package.json +4 -3
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/cli/utils/postgres.ts
|
|
21
|
+
var postgres_exports = {};
|
|
22
|
+
__export(postgres_exports, {
|
|
23
|
+
parsePostgresUrl: () => parsePostgresUrl,
|
|
24
|
+
postgresEndpoint: () => postgresEndpoint
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(postgres_exports);
|
|
27
|
+
var parsePostgresUrl = (url) => {
|
|
28
|
+
try {
|
|
29
|
+
const parsed = new URL(url);
|
|
30
|
+
if (parsed.protocol !== "postgresql:" && parsed.protocol !== "postgres:") {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const database = decodeURIComponent(parsed.pathname.replace(/^\/+/, ""));
|
|
34
|
+
const port = parsed.port ? Number(parsed.port) : 5432;
|
|
35
|
+
const queryHost = parsed.searchParams.get("host");
|
|
36
|
+
const host = parsed.hostname.replace(/^\[(.*)\]$/, "$1");
|
|
37
|
+
if (!database || !host || !Number.isInteger(port) || port <= 0 || port > 65535) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
host,
|
|
42
|
+
port,
|
|
43
|
+
database,
|
|
44
|
+
socketPath: queryHost?.startsWith("/") ? queryHost : void 0
|
|
45
|
+
};
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var postgresEndpoint = (info) => info.socketPath || `${info.host}:${info.port}`;
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
parsePostgresUrl,
|
|
54
|
+
postgresEndpoint
|
|
55
|
+
});
|
package/dist/index.d.mts
CHANGED
|
@@ -68,6 +68,10 @@ declare class PrismaSharding<TClient> {
|
|
|
68
68
|
getShardById(shardId: string): TClient;
|
|
69
69
|
getShardWithInfo(key: string): ShardResult<TClient>;
|
|
70
70
|
getRandomShard(): TClient;
|
|
71
|
+
/**
|
|
72
|
+
* Returns both the random shard client and its shardId.
|
|
73
|
+
* Used when the shardId must be stored on the user record for future routing.
|
|
74
|
+
*/
|
|
71
75
|
getRandomShardWithInfo(): ShardResult<TClient>;
|
|
72
76
|
findFirst<T>(finder: (client: TClient) => Promise<T | null>): Promise<FindFirstResult<T, TClient>>;
|
|
73
77
|
runOnAll<T>(operation: (client: TClient, shardId: string) => Promise<T>): Promise<T[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -68,6 +68,10 @@ declare class PrismaSharding<TClient> {
|
|
|
68
68
|
getShardById(shardId: string): TClient;
|
|
69
69
|
getShardWithInfo(key: string): ShardResult<TClient>;
|
|
70
70
|
getRandomShard(): TClient;
|
|
71
|
+
/**
|
|
72
|
+
* Returns both the random shard client and its shardId.
|
|
73
|
+
* Used when the shardId must be stored on the user record for future routing.
|
|
74
|
+
*/
|
|
71
75
|
getRandomShardWithInfo(): ShardResult<TClient>;
|
|
72
76
|
findFirst<T>(finder: (client: TClient) => Promise<T | null>): Promise<FindFirstResult<T, TClient>>;
|
|
73
77
|
runOnAll<T>(operation: (client: TClient, shardId: string) => Promise<T>): Promise<T[]>;
|