schematic-pg 0.1.8 → 0.1.11
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 +154 -1102
- package/dist/api/auth/jwt-crypto.d.ts +10 -0
- package/dist/api/auth/jwt-crypto.js +61 -0
- package/dist/api/auth/jwt-resolver.js +2 -27
- package/dist/api/auth/password/config.d.ts +32 -0
- package/dist/api/auth/password/config.js +35 -0
- package/dist/api/auth/password/errors.d.ts +8 -0
- package/dist/api/auth/password/errors.js +14 -0
- package/dist/api/auth/password/index.d.ts +3 -0
- package/dist/api/auth/password/index.js +3 -0
- package/dist/api/auth/password/password.d.ts +14 -0
- package/dist/api/auth/password/password.js +46 -0
- package/dist/api/auth/routes.d.ts +23 -0
- package/dist/api/auth/routes.js +118 -0
- package/dist/api/auth/token/config.d.ts +10 -0
- package/dist/api/auth/token/config.js +43 -0
- package/dist/api/auth/token/errors.d.ts +6 -0
- package/dist/api/auth/token/errors.js +12 -0
- package/dist/api/auth/token/index.d.ts +3 -0
- package/dist/api/auth/token/index.js +3 -0
- package/dist/api/auth/token/token.d.ts +11 -0
- package/dist/api/auth/token/token.js +31 -0
- package/dist/api/middleware/errors.js +11 -0
- package/dist/cli/init.js +3 -1
- package/dist/cli/templates/agents.md +290 -0
- package/dist/cli/templates.d.ts +5 -3
- package/dist/cli/templates.js +22 -6
- package/dist/cli/wait-for-database.js +1 -1
- package/dist/db/db-client-generator.js +20 -2
- package/dist/db/include/executor.d.ts +2 -2
- package/dist/db/include/executor.js +7 -7
- package/dist/db/include/json-agg.d.ts +2 -2
- package/dist/db/include/json-agg.js +4 -4
- package/dist/db/include/load.d.ts +3 -3
- package/dist/db/include/load.js +8 -8
- package/dist/db/index.d.ts +4 -0
- package/dist/db/index.js +2 -0
- package/dist/db/model-client.d.ts +2 -2
- package/dist/db/model-client.js +3 -3
- package/dist/db/queryable.d.ts +5 -0
- package/dist/db/queryable.js +1 -0
- package/dist/db/raw.d.ts +22 -0
- package/dist/db/raw.js +35 -0
- package/dist/db/transaction.d.ts +2 -0
- package/dist/db/transaction.js +24 -0
- package/dist/routes/auth.d.ts +3 -0
- package/dist/routes/auth.js +5 -0
- package/dist/types/generated-db.stub.d.ts +5 -1
- package/dist/types/generated-db.stub.js +8 -1
- package/package.json +5 -4
package/dist/db/raw.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { QueryResultRow } from 'pg';
|
|
2
|
+
import type { Queryable } from './queryable.js';
|
|
3
|
+
export interface RawClient {
|
|
4
|
+
/**
|
|
5
|
+
* Runs an arbitrary SQL query and returns the raw result rows.
|
|
6
|
+
*
|
|
7
|
+
* Rows are returned EXACTLY as `pg` produces them: `snake_case` column names
|
|
8
|
+
* and driver type coercion, with no `camelCase` mapping. Values MUST be passed
|
|
9
|
+
* through the positional `params` array (`$1`, `$2`, …) — never interpolate
|
|
10
|
+
* user input into the `sql` string.
|
|
11
|
+
*/
|
|
12
|
+
$queryRaw<T extends QueryResultRow = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Runs an arbitrary SQL statement and returns the number of affected rows.
|
|
15
|
+
*
|
|
16
|
+
* Values MUST be passed through the positional `params` array (`$1`, `$2`, …)
|
|
17
|
+
* — never interpolate user input into the `sql` string.
|
|
18
|
+
*/
|
|
19
|
+
$executeRaw(sql: string, params?: unknown[]): Promise<number>;
|
|
20
|
+
}
|
|
21
|
+
/** Builds the parameterized raw-query escape hatch bound to a single executor. */
|
|
22
|
+
export declare function createRawClient(executor: Queryable): RawClient;
|
package/dist/db/raw.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { mapPgError } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Label used when surfacing raw-query errors. A raw query has no single owning
|
|
4
|
+
* model, so error mapping runs without a `column -> field` translation map.
|
|
5
|
+
*/
|
|
6
|
+
const RAW_QUERY_LABEL = '$queryRaw';
|
|
7
|
+
const EMPTY_COLUMN_TO_FIELD = new Map();
|
|
8
|
+
const NO_PARAMS = [];
|
|
9
|
+
/** Maps a driver error to the project's typed `DatabaseError` subclasses. */
|
|
10
|
+
function wrapRawError(error) {
|
|
11
|
+
return mapPgError(error, RAW_QUERY_LABEL, EMPTY_COLUMN_TO_FIELD);
|
|
12
|
+
}
|
|
13
|
+
/** Builds the parameterized raw-query escape hatch bound to a single executor. */
|
|
14
|
+
export function createRawClient(executor) {
|
|
15
|
+
return {
|
|
16
|
+
async $queryRaw(sql, params = NO_PARAMS) {
|
|
17
|
+
try {
|
|
18
|
+
const result = await executor.query(sql, params);
|
|
19
|
+
return result.rows;
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
throw wrapRawError(error);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
async $executeRaw(sql, params = NO_PARAMS) {
|
|
26
|
+
try {
|
|
27
|
+
const result = await executor.query(sql, params);
|
|
28
|
+
return result.rowCount ?? 0;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
throw wrapRawError(error);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const BEGIN = 'BEGIN';
|
|
2
|
+
const COMMIT = 'COMMIT';
|
|
3
|
+
const ROLLBACK = 'ROLLBACK';
|
|
4
|
+
export async function runInTransaction(pool, fn) {
|
|
5
|
+
const client = await pool.connect();
|
|
6
|
+
try {
|
|
7
|
+
await client.query(BEGIN);
|
|
8
|
+
const result = await fn(client);
|
|
9
|
+
await client.query(COMMIT);
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
try {
|
|
14
|
+
await client.query(ROLLBACK);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// ignore rollback failure; surface the original error
|
|
18
|
+
}
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
client.release();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type { QueryResultRow } from 'pg';
|
|
2
|
+
export interface DbClient extends Record<string, unknown> {
|
|
3
|
+
$queryRaw<T extends QueryResultRow = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
4
|
+
$executeRaw(sql: string, params?: unknown[]): Promise<number>;
|
|
5
|
+
}
|
|
2
6
|
export declare function createDbClient(_pool: unknown): DbClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "schematic-pg",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "Single-file backend framework for PostgreSQL and Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/tawsbob/
|
|
12
|
+
"url": "git+https://github.com/tawsbob/schematic-pg.git"
|
|
13
13
|
},
|
|
14
14
|
"main": "./dist/index.js",
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
|
-
"build": "tsc -p tsconfig.build.json",
|
|
51
|
+
"build": "tsc -p tsconfig.build.json && mkdir -p dist/cli/templates && cp src/cli/templates/agents.md dist/cli/templates/",
|
|
52
52
|
"parse": "tsx src/schema-dsl/cli.ts",
|
|
53
53
|
"tokenize": "tsx src/schema-dsl/cli.ts --tokens",
|
|
54
54
|
"generate": "tsx src/cli.ts generate",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"build:lsp": "npm run build --workspace=@schematic-pg/schema-dsl-language-server",
|
|
66
66
|
"build:extension": "npm run vscode:prepublish --workspace=schematic-pg-schema-dsl-vscode && npm run package --workspace=schematic-pg-schema-dsl-vscode",
|
|
67
67
|
"test": "node --import tsx --test $(find src editors/language-server -path '*/__tests__/*.test.ts' ! -name '*.integration.test.ts')",
|
|
68
|
-
"test:integration": "npm run setup:env && docker compose up -d --wait && npm run generate:client && npm run generate:api && JWT_SECRET=integration-test-secret node --import tsx --test --test-concurrency=1 'src/**/__tests__/**/*.integration.test.ts'",
|
|
68
|
+
"test:integration": "npm run setup:env && docker compose up -d --wait && npm run generate:client && npm run generate:api && JWT_SECRET=integration-test-secret AUTH_PEPPER=integration-test-pepper node --import tsx --test --test-concurrency=1 'src/**/__tests__/**/*.integration.test.ts'",
|
|
69
69
|
"docker:up": "docker compose up -d",
|
|
70
70
|
"docker:down": "docker compose down",
|
|
71
71
|
"docker:logs": "docker compose logs -f postgres",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"@hono/node-server": "^2.0.6",
|
|
76
76
|
"@hono/zod-validator": "^0.8.0",
|
|
77
77
|
"@inquirer/prompts": "^8.5.2",
|
|
78
|
+
"argon2": "^0.44.0",
|
|
78
79
|
"hono": "^4.12.27",
|
|
79
80
|
"pg": "^8.22.0",
|
|
80
81
|
"tsx": "^4.19.4",
|