@dads-framework/postgres-access 0.1.0 → 0.3.0
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/BENCHMARK.md +94 -8
- package/README.md +195 -69
- package/dist/compile-access-policy.d.ts +2 -1
- package/dist/compile-access-policy.d.ts.map +1 -1
- package/dist/compile-access-policy.js +9 -2
- package/dist/compile-access-policy.js.map +1 -1
- package/dist/drizzle-executor.d.ts +2 -2
- package/dist/drizzle-executor.d.ts.map +1 -1
- package/dist/drizzle-executor.js.map +1 -1
- package/dist/drizzle-structural.d.ts +23 -0
- package/dist/drizzle-structural.d.ts.map +1 -0
- package/dist/drizzle-structural.js +22 -0
- package/dist/drizzle-structural.js.map +1 -0
- package/dist/drizzle.d.ts +4 -0
- package/dist/drizzle.d.ts.map +1 -0
- package/dist/drizzle.js +4 -0
- package/dist/drizzle.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/lookup-primary-pool.d.ts +2 -3
- package/dist/lookup-primary-pool.d.ts.map +1 -1
- package/dist/lookup-primary-pool.js +2 -1
- package/dist/lookup-primary-pool.js.map +1 -1
- package/dist/lower-permissions.d.ts.map +1 -1
- package/dist/lower-permissions.js +37 -12
- package/dist/lower-permissions.js.map +1 -1
- package/dist/policy/column-relations.d.ts +34 -0
- package/dist/policy/column-relations.d.ts.map +1 -0
- package/dist/policy/column-relations.js +127 -0
- package/dist/policy/column-relations.js.map +1 -0
- package/dist/policy/compile-filter.d.ts +41 -0
- package/dist/policy/compile-filter.d.ts.map +1 -0
- package/dist/policy/compile-filter.js +127 -0
- package/dist/policy/compile-filter.js.map +1 -0
- package/dist/policy/compile-forward-policy.d.ts +20 -0
- package/dist/policy/compile-forward-policy.d.ts.map +1 -0
- package/dist/policy/compile-forward-policy.js +129 -0
- package/dist/policy/compile-forward-policy.js.map +1 -0
- package/dist/policy/compile-linear-batch.d.ts +1 -0
- package/dist/policy/compile-linear-batch.d.ts.map +1 -1
- package/dist/policy/compile-linear-batch.js +3 -6
- package/dist/policy/compile-linear-batch.js.map +1 -1
- package/dist/policy/compile-linear-check.d.ts.map +1 -1
- package/dist/policy/compile-linear-check.js +53 -9
- package/dist/policy/compile-linear-check.js.map +1 -1
- package/dist/policy/compile-postgres-policy.d.ts +9 -4
- package/dist/policy/compile-postgres-policy.d.ts.map +1 -1
- package/dist/policy/compile-postgres-policy.js +91 -118
- package/dist/policy/compile-postgres-policy.js.map +1 -1
- package/dist/policy/compile-recursive-policy.d.ts +53 -0
- package/dist/policy/compile-recursive-policy.d.ts.map +1 -0
- package/dist/policy/compile-recursive-policy.js +231 -0
- package/dist/policy/compile-recursive-policy.js.map +1 -0
- package/dist/policy/compile-recursive-subjects.d.ts +27 -0
- package/dist/policy/compile-recursive-subjects.d.ts.map +1 -0
- package/dist/policy/compile-recursive-subjects.js +180 -0
- package/dist/policy/compile-recursive-subjects.js.map +1 -0
- package/dist/policy/compile-reverse-policy.d.ts +12 -2
- package/dist/policy/compile-reverse-policy.d.ts.map +1 -1
- package/dist/policy/compile-reverse-policy.js +168 -39
- package/dist/policy/compile-reverse-policy.js.map +1 -1
- package/dist/policy/compile-shared-point-check.d.ts.map +1 -1
- package/dist/policy/compile-shared-point-check.js +165 -13
- package/dist/policy/compile-shared-point-check.js.map +1 -1
- package/dist/policy/compile-subject-lookup.d.ts +8 -0
- package/dist/policy/compile-subject-lookup.d.ts.map +1 -0
- package/dist/policy/compile-subject-lookup.js +254 -0
- package/dist/policy/compile-subject-lookup.js.map +1 -0
- package/dist/policy/permission-cycles.d.ts +27 -0
- package/dist/policy/permission-cycles.d.ts.map +1 -0
- package/dist/policy/permission-cycles.js +181 -0
- package/dist/policy/permission-cycles.js.map +1 -0
- package/dist/policy/policy-model.d.ts +24 -0
- package/dist/policy/policy-model.d.ts.map +1 -1
- package/dist/policy/policy-sql.d.ts +39 -5
- package/dist/policy/policy-sql.d.ts.map +1 -1
- package/dist/policy/policy-sql.js +189 -15
- package/dist/policy/policy-sql.js.map +1 -1
- package/dist/policy/resolve-filter.d.ts +25 -0
- package/dist/policy/resolve-filter.d.ts.map +1 -0
- package/dist/policy/resolve-filter.js +156 -0
- package/dist/policy/resolve-filter.js.map +1 -0
- package/dist/policy/tarjan-scc.d.ts +3 -0
- package/dist/policy/tarjan-scc.d.ts.map +1 -0
- package/dist/policy/tarjan-scc.js +58 -0
- package/dist/policy/tarjan-scc.js.map +1 -0
- package/dist/postgres-access.tsbuildinfo +1 -1
- package/dist/postgres-authorization.d.ts +17 -17
- package/dist/postgres-authorization.d.ts.map +1 -1
- package/dist/postgres-authorization.js +67 -29
- package/dist/postgres-authorization.js.map +1 -1
- package/dist/postgres-options.d.ts +25 -0
- package/dist/postgres-options.d.ts.map +1 -0
- package/dist/postgres-options.js +36 -0
- package/dist/postgres-options.js.map +1 -0
- package/dist/postgres-response.d.ts +5 -0
- package/dist/postgres-response.d.ts.map +1 -1
- package/dist/postgres-response.js +42 -0
- package/dist/postgres-response.js.map +1 -1
- package/dist/postgres-tuples.d.ts.map +1 -1
- package/dist/postgres-tuples.js +64 -7
- package/dist/postgres-tuples.js.map +1 -1
- package/dist/postgres-types.d.ts +11 -0
- package/dist/postgres-types.d.ts.map +1 -1
- package/dist/protected-authorization-scope.d.ts +6 -8
- package/dist/protected-authorization-scope.d.ts.map +1 -1
- package/dist/protected-authorization-scope.js +13 -8
- package/dist/protected-authorization-scope.js.map +1 -1
- package/dist/relationship-schema.d.ts +9 -0
- package/dist/relationship-schema.d.ts.map +1 -1
- package/dist/relationship-schema.js +24 -2
- package/dist/relationship-schema.js.map +1 -1
- package/dist/testing.d.ts +20 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +88 -0
- package/dist/testing.js.map +1 -0
- package/dist/transactional-access-changes.d.ts +3 -3
- package/dist/transactional-access-changes.d.ts.map +1 -1
- package/dist/transactional-access-changes.js +5 -3
- package/dist/transactional-access-changes.js.map +1 -1
- package/dist/with-protected-drizzle-transaction.d.ts +18 -0
- package/dist/with-protected-drizzle-transaction.d.ts.map +1 -0
- package/dist/with-protected-drizzle-transaction.js +52 -0
- package/dist/with-protected-drizzle-transaction.js.map +1 -0
- package/dist/with-protected-pg-transaction.d.ts +29 -0
- package/dist/with-protected-pg-transaction.d.ts.map +1 -0
- package/dist/with-protected-pg-transaction.js +110 -0
- package/dist/with-protected-pg-transaction.js.map +1 -0
- package/dist/with-protected-postgres-transaction.d.ts +6 -21
- package/dist/with-protected-postgres-transaction.d.ts.map +1 -1
- package/dist/with-protected-postgres-transaction.js +4 -45
- package/dist/with-protected-postgres-transaction.js.map +1 -1
- package/package.json +26 -4
|
@@ -1,47 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/** Run one protected write with authorization and application data on the same client. */
|
|
6
|
-
export async function withProtectedPostgresTransaction(options, work) {
|
|
7
|
-
try {
|
|
8
|
-
assertProtectedAuthorizationCanJoin(options.authorization, options.transaction);
|
|
9
|
-
if (options.transaction !== undefined) {
|
|
10
|
-
return await runProtectedWork(options.transaction, options.authorization, work);
|
|
11
|
-
}
|
|
12
|
-
if (is(options.database, PgTransaction)) {
|
|
13
|
-
throw new Error("Pass an existing Postgres transaction as transaction");
|
|
14
|
-
}
|
|
15
|
-
let started = false;
|
|
16
|
-
return await options.database.transaction((tx) => {
|
|
17
|
-
if (started)
|
|
18
|
-
throw new Error("Protected Postgres callbacks cannot be replayed");
|
|
19
|
-
started = true;
|
|
20
|
-
return runProtectedWork(tx, options.authorization, work);
|
|
21
|
-
}, { isolationLevel: "serializable" });
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
const conflict = readPostgresSerializationConflict(error);
|
|
25
|
-
if (conflict !== undefined)
|
|
26
|
-
throw conflict;
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async function runProtectedWork(tx, authorization, work) {
|
|
31
|
-
if (!is(tx, PgTransaction)) {
|
|
32
|
-
throw new Error("Protected Postgres writes require a Drizzle transaction");
|
|
33
|
-
}
|
|
34
|
-
// A SELECT takes the transaction snapshot, so isolation cannot later be lowered.
|
|
35
|
-
const isolation = await tx.execute(sql `select current_setting('transaction_isolation') as isolation`);
|
|
36
|
-
if (isolation.rows[0]?.isolation !== "serializable") {
|
|
37
|
-
throw new Error("Protected Postgres writes require serializable isolation");
|
|
38
|
-
}
|
|
39
|
-
const scope = openProtectedAuthorization(authorization, tx);
|
|
40
|
-
try {
|
|
41
|
-
return await work({ tx, authorization: scope.authorization });
|
|
42
|
-
}
|
|
43
|
-
finally {
|
|
44
|
-
scope.close();
|
|
45
|
-
}
|
|
1
|
+
import { withProtectedPgTransaction, } from "./with-protected-pg-transaction.js";
|
|
2
|
+
/** Run one protected write on a plain `pg.Pool` with `BEGIN ISOLATION LEVEL SERIALIZABLE`. */
|
|
3
|
+
export function withProtectedPostgresTransaction(options, work) {
|
|
4
|
+
return withProtectedPgTransaction(options, work);
|
|
46
5
|
}
|
|
47
6
|
//# sourceMappingURL=with-protected-postgres-transaction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-protected-postgres-transaction.js","sourceRoot":"","sources":["../src/with-protected-postgres-transaction.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"with-protected-postgres-transaction.js","sourceRoot":"","sources":["../src/with-protected-postgres-transaction.ts"],"names":[],"mappings":"AACA,OAAO,EACL,0BAA0B,GAG3B,MAAM,oCAAoC,CAAC;AAU5C,8FAA8F;AAC9F,MAAM,UAAU,gCAAgC,CAI9C,OAAoD,EACpD,IAA0E;IAE1E,OAAO,0BAA0B,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACnD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dads-framework/postgres-access",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22"
|
|
@@ -9,6 +9,14 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./drizzle": {
|
|
14
|
+
"types": "./dist/drizzle.d.ts",
|
|
15
|
+
"default": "./dist/drizzle.js"
|
|
16
|
+
},
|
|
17
|
+
"./testing": {
|
|
18
|
+
"types": "./dist/testing.d.ts",
|
|
19
|
+
"default": "./dist/testing.js"
|
|
12
20
|
}
|
|
13
21
|
},
|
|
14
22
|
"files": [
|
|
@@ -17,12 +25,26 @@
|
|
|
17
25
|
"BENCHMARK.md"
|
|
18
26
|
],
|
|
19
27
|
"dependencies": {
|
|
20
|
-
"@dads-framework/access": "0.
|
|
21
|
-
|
|
28
|
+
"@dads-framework/access": "0.3.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@dads-framework/postgres": "0.3.0",
|
|
22
32
|
"drizzle-orm": "^0.45.2"
|
|
23
33
|
},
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"@dads-framework/postgres": {
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
38
|
+
"drizzle-orm": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
},
|
|
24
42
|
"devDependencies": {
|
|
25
|
-
"@dads-framework/
|
|
43
|
+
"@dads-framework/postgres": "0.3.0",
|
|
44
|
+
"@dads-framework/spicedb-access": "0.3.0",
|
|
45
|
+
"@types/pg": "^8.20.0",
|
|
46
|
+
"drizzle-orm": "^0.45.2",
|
|
47
|
+
"pg": "^8.21.0",
|
|
26
48
|
"vitest": "~4.1.0",
|
|
27
49
|
"zod": "^4.4.3"
|
|
28
50
|
},
|