@protobase/cli 0.22.10 → 0.22.12
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/dist/dev/run.js +4 -1
- package/dist/package.js +1 -1
- package/dist/project/background-gate.js +40 -0
- package/dist/project/pg-db.js +4 -2
- package/dist/serve/env.js +3 -0
- package/dist/serve/lifecycle.js +1 -1
- package/package.json +6 -6
package/dist/dev/run.js
CHANGED
|
@@ -63,7 +63,10 @@ const runDev = async (options, out) => {
|
|
|
63
63
|
root: appDir,
|
|
64
64
|
configFile: false,
|
|
65
65
|
...options.cacheDir && { cacheDir: options.cacheDir },
|
|
66
|
-
optimizeDeps: {
|
|
66
|
+
optimizeDeps: {
|
|
67
|
+
include: appDependencies,
|
|
68
|
+
exclude: ["@protobase/ui"]
|
|
69
|
+
},
|
|
67
70
|
server: {
|
|
68
71
|
port: options.port,
|
|
69
72
|
strictPort: true,
|
package/dist/package.js
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isBackgroundWork } from "@protobase/server";
|
|
2
|
+
//#region src/project/background-gate.ts
|
|
3
|
+
/**
|
|
4
|
+
* The pool as Kysely uses it, where background work (function calls and jobs) holds at most `slots` connections at
|
|
5
|
+
* once and waits for one of its own after that; page and API requests take any connection the pool has.
|
|
6
|
+
*/
|
|
7
|
+
const gateBackgroundWork = (pool, slots) => {
|
|
8
|
+
let used = 0;
|
|
9
|
+
const waiting = [];
|
|
10
|
+
const take = () => {
|
|
11
|
+
if (used < slots) return void used++;
|
|
12
|
+
return new Promise((resolve) => waiting.push(resolve));
|
|
13
|
+
};
|
|
14
|
+
const free = () => {
|
|
15
|
+
const next = waiting.shift();
|
|
16
|
+
if (next) return next();
|
|
17
|
+
used--;
|
|
18
|
+
};
|
|
19
|
+
const connectInBackground = async () => {
|
|
20
|
+
await take();
|
|
21
|
+
const client = await pool.connect().catch((error) => {
|
|
22
|
+
free();
|
|
23
|
+
throw error;
|
|
24
|
+
});
|
|
25
|
+
const release = client.release;
|
|
26
|
+
client.release = () => {
|
|
27
|
+
release.call(client);
|
|
28
|
+
free();
|
|
29
|
+
};
|
|
30
|
+
return client;
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
...pool.Client && { Client: pool.Client },
|
|
34
|
+
options: pool.options,
|
|
35
|
+
connect: () => isBackgroundWork() ? connectInBackground() : pool.connect(),
|
|
36
|
+
end: () => pool.end()
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
export { gateBackgroundWork };
|
package/dist/project/pg-db.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { gateBackgroundWork } from "./background-gate.js";
|
|
1
2
|
import { handleDroppedConnections } from "@protobase/server";
|
|
2
3
|
import { Kysely, PostgresDialect } from "kysely";
|
|
3
4
|
//#region src/project/pg-db.ts
|
|
4
5
|
const createPgDb = (pg, url, max = 10) => {
|
|
5
|
-
|
|
6
|
+
const pool = handleDroppedConnections(new pg.Pool({
|
|
6
7
|
connectionString: url,
|
|
7
8
|
max,
|
|
8
9
|
types: { getTypeParser: (oid, format) => oid === 1082 || oid === 1114 ? (value) => value : pg.types.getTypeParser(oid, format) }
|
|
9
|
-
}))
|
|
10
|
+
}));
|
|
11
|
+
return new Kysely({ dialect: new PostgresDialect({ pool: gateBackgroundWork(pool, Math.max(1, max - 1)) }) });
|
|
10
12
|
};
|
|
11
13
|
//#endregion
|
|
12
14
|
export { createPgDb };
|
package/dist/serve/env.js
CHANGED
|
@@ -11,9 +11,12 @@ const readServeEnv = (env) => {
|
|
|
11
11
|
if (!Number.isInteger(port) || port < 0 || port > 65535) throw new Error(`PORT must be a port number, not "${env.PORT}"`);
|
|
12
12
|
const minutes = env.PROTOBASE_FILES_CLEANUP_MINUTES ? Number(env.PROTOBASE_FILES_CLEANUP_MINUTES) : 60;
|
|
13
13
|
if (!Number.isInteger(minutes) || minutes < 0) throw new Error(`PROTOBASE_FILES_CLEANUP_MINUTES must be a whole number of minutes, not "${env.PROTOBASE_FILES_CLEANUP_MINUTES}"`);
|
|
14
|
+
const connections = env.PROTOBASE_DB_CONNECTIONS ? Number(env.PROTOBASE_DB_CONNECTIONS) : void 0;
|
|
15
|
+
if (connections !== void 0 && (!Number.isInteger(connections) || connections < 1)) throw new Error(`PROTOBASE_DB_CONNECTIONS must be a whole number of connections, at least 1, not "${env.PROTOBASE_DB_CONNECTIONS}"`);
|
|
14
16
|
return {
|
|
15
17
|
port,
|
|
16
18
|
databaseUrl: env.DATABASE_URL || void 0,
|
|
19
|
+
...connections && { dbConnections: connections },
|
|
17
20
|
requestLog: readBoolean(env, "REQUEST_LOG", false),
|
|
18
21
|
filesCleanupMinutes: minutes,
|
|
19
22
|
runJobs: readBoolean(env, "PROTOBASE_JOBS", true),
|
package/dist/serve/lifecycle.js
CHANGED
|
@@ -14,7 +14,7 @@ const listen = (server, port) => new Promise((resolve, reject) => {
|
|
|
14
14
|
});
|
|
15
15
|
});
|
|
16
16
|
const closeServer = (server) => new Promise((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));
|
|
17
|
-
const startServe = async ({ project, env, createDb = (url) => createPgDb(pg, url), site, ui, reporter }) => {
|
|
17
|
+
const startServe = async ({ project, env, createDb = (url) => createPgDb(pg, url, env.dbConnections), site, ui, reporter }) => {
|
|
18
18
|
if (!project.db && !env.databaseUrl) throw new Error("No database: set DATABASE_URL or export `db` from protobase.config.ts");
|
|
19
19
|
if (env.startupChecks && project.auth) await checkAuthSchema(project.auth);
|
|
20
20
|
const ownDb = project.db ? void 0 : createDb(env.databaseUrl);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.12",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@hono/node-server": "^2.1.3",
|
|
36
36
|
"@hono/vite-dev-server": "^0.26.1",
|
|
37
|
-
"@protobase/layout": "0.22.
|
|
38
|
-
"@protobase/query": "0.22.
|
|
39
|
-
"@protobase/schema": "0.22.
|
|
40
|
-
"@protobase/server": "0.22.
|
|
41
|
-
"@protobase/ui": "0.22.
|
|
37
|
+
"@protobase/layout": "0.22.12",
|
|
38
|
+
"@protobase/query": "0.22.12",
|
|
39
|
+
"@protobase/schema": "0.22.12",
|
|
40
|
+
"@protobase/server": "0.22.12",
|
|
41
|
+
"@protobase/ui": "0.22.12",
|
|
42
42
|
"@react-email/render": "^2.1.0",
|
|
43
43
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
44
44
|
"@tailwindcss/vite": "^4.3.3",
|