@dads-framework/sqlite-access 0.0.0-stage → 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/LICENSE.md +21 -0
- package/README.md +133 -2
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- 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 +121 -0
- package/dist/policy/column-relations.js.map +1 -0
- package/dist/policy/compile-access-policy.d.ts +11 -0
- package/dist/policy/compile-access-policy.d.ts.map +1 -0
- package/dist/policy/compile-access-policy.js +184 -0
- package/dist/policy/compile-access-policy.js.map +1 -0
- package/dist/policy/compile-check-through.d.ts +8 -0
- package/dist/policy/compile-check-through.d.ts.map +1 -0
- package/dist/policy/compile-check-through.js +87 -0
- package/dist/policy/compile-check-through.js.map +1 -0
- package/dist/policy/compile-check.d.ts +19 -0
- package/dist/policy/compile-check.d.ts.map +1 -0
- package/dist/policy/compile-check.js +116 -0
- package/dist/policy/compile-check.js.map +1 -0
- package/dist/policy/compile-filter.d.ts +36 -0
- package/dist/policy/compile-filter.d.ts.map +1 -0
- package/dist/policy/compile-filter.js +117 -0
- package/dist/policy/compile-filter.js.map +1 -0
- package/dist/policy/compile-forward-scc.d.ts +36 -0
- package/dist/policy/compile-forward-scc.d.ts.map +1 -0
- package/dist/policy/compile-forward-scc.js +117 -0
- package/dist/policy/compile-forward-scc.js.map +1 -0
- package/dist/policy/compile-lookup-resources-scc.d.ts +17 -0
- package/dist/policy/compile-lookup-resources-scc.d.ts.map +1 -0
- package/dist/policy/compile-lookup-resources-scc.js +76 -0
- package/dist/policy/compile-lookup-resources-scc.js.map +1 -0
- package/dist/policy/compile-lookup-resources.d.ts +13 -0
- package/dist/policy/compile-lookup-resources.d.ts.map +1 -0
- package/dist/policy/compile-lookup-resources.js +184 -0
- package/dist/policy/compile-lookup-resources.js.map +1 -0
- package/dist/policy/compile-lookup-subjects.d.ts +8 -0
- package/dist/policy/compile-lookup-subjects.d.ts.map +1 -0
- package/dist/policy/compile-lookup-subjects.js +219 -0
- package/dist/policy/compile-lookup-subjects.js.map +1 -0
- package/dist/policy/compile-relation-membership.d.ts +10 -0
- package/dist/policy/compile-relation-membership.d.ts.map +1 -0
- package/dist/policy/compile-relation-membership.js +118 -0
- package/dist/policy/compile-relation-membership.js.map +1 -0
- package/dist/policy/cycle-analysis.d.ts +4 -0
- package/dist/policy/cycle-analysis.d.ts.map +1 -0
- package/dist/policy/cycle-analysis.js +247 -0
- package/dist/policy/cycle-analysis.js.map +1 -0
- package/dist/policy/policy-model.d.ts +119 -0
- package/dist/policy/policy-model.d.ts.map +1 -0
- package/dist/policy/policy-model.js +10 -0
- package/dist/policy/policy-model.js.map +1 -0
- package/dist/policy/policy-sql.d.ts +33 -0
- package/dist/policy/policy-sql.d.ts.map +1 -0
- package/dist/policy/policy-sql.js +88 -0
- package/dist/policy/policy-sql.js.map +1 -0
- package/dist/sqlite-access.tsbuildinfo +1 -0
- package/dist/sqlite-authorization.d.ts +48 -0
- package/dist/sqlite-authorization.d.ts.map +1 -0
- package/dist/sqlite-authorization.js +223 -0
- package/dist/sqlite-authorization.js.map +1 -0
- package/dist/sqlite-executor.d.ts +21 -0
- package/dist/sqlite-executor.d.ts.map +1 -0
- package/dist/sqlite-executor.js +35 -0
- package/dist/sqlite-executor.js.map +1 -0
- package/dist/sqlite-schema.d.ts +12 -0
- package/dist/sqlite-schema.d.ts.map +1 -0
- package/dist/sqlite-schema.js +52 -0
- package/dist/sqlite-schema.js.map +1 -0
- package/dist/sqlite-tuples.d.ts +15 -0
- package/dist/sqlite-tuples.d.ts.map +1 -0
- package/dist/sqlite-tuples.js +181 -0
- package/dist/sqlite-tuples.js.map +1 -0
- package/dist/sqlite-types.d.ts +16 -0
- package/dist/sqlite-types.d.ts.map +1 -0
- package/dist/sqlite-types.js +31 -0
- package/dist/sqlite-types.js.map +1 -0
- package/dist/sqlite-validation.d.ts +5 -0
- package/dist/sqlite-validation.d.ts.map +1 -0
- package/dist/sqlite-validation.js +29 -0
- package/dist/sqlite-validation.js.map +1 -0
- package/dist/testing.d.ts +40 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +119 -0
- package/dist/testing.js.map +1 -0
- package/dist/with-protected-sqlite-transaction.d.ts +18 -0
- package/dist/with-protected-sqlite-transaction.d.ts.map +1 -0
- package/dist/with-protected-sqlite-transaction.js +77 -0
- package/dist/with-protected-sqlite-transaction.js.map +1 -0
- package/package.json +40 -4
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bryton Cooper
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,134 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@dads-framework/sqlite-access`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Check permissions, list accessible resources, resolve transitive subjects, and commit relationship changes alongside business data in SQLite.
|
|
4
|
+
|
|
5
|
+
## Why SQLite
|
|
6
|
+
|
|
7
|
+
Sometimes the whole application fits on one machine or inside an embedded store, and adding a separate authorization cluster creates more moving parts than the product has. Keep relationship facts next to application rows, verify access inside the same `BEGIN IMMEDIATE` write transaction, and drop the outbox.
|
|
8
|
+
|
|
9
|
+
The adapter runs on Node.js built-in `node:sqlite` (`DatabaseSync`) with zero native addons. Callers can also wrap `better-sqlite3`, Drizzle SQLite, or libSQL behind the `SqliteExecutor` port.
|
|
10
|
+
|
|
11
|
+
## Try it
|
|
12
|
+
|
|
13
|
+
Use Node.js 22.5 or later. Install the packages and run the script against an in-memory SQLite database.
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @dads-framework/access @dads-framework/sqlite-access
|
|
17
|
+
npm install -D tsx
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Save as `check-sqlite-access.mts` and run `npx tsx check-sqlite-access.mts`.
|
|
21
|
+
|
|
22
|
+
<!-- dads:check-example -->
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { DatabaseSync } from "node:sqlite";
|
|
26
|
+
import { actor, compileAccess, resource } from "@dads-framework/access";
|
|
27
|
+
import { createAccessClient } from "@dads-framework/access/runtime";
|
|
28
|
+
import {
|
|
29
|
+
createNodeSqliteExecutor,
|
|
30
|
+
SqliteAuthorization,
|
|
31
|
+
sqliteRelationshipSchemaMigration,
|
|
32
|
+
withProtectedSqliteTransaction,
|
|
33
|
+
} from "@dads-framework/sqlite-access";
|
|
34
|
+
|
|
35
|
+
const user = actor("user");
|
|
36
|
+
const organization = resource("organization", {
|
|
37
|
+
roles: { admin: user, member: user },
|
|
38
|
+
can: ({ admin, member }) => ({
|
|
39
|
+
manage: admin,
|
|
40
|
+
view: [admin, member],
|
|
41
|
+
}),
|
|
42
|
+
children: {
|
|
43
|
+
task: {
|
|
44
|
+
inherit: "all",
|
|
45
|
+
roles: { assignee: user },
|
|
46
|
+
can: ({ assignee }) => ({ edit: assignee }),
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
const model = compileAccess([organization]);
|
|
51
|
+
|
|
52
|
+
const database = new DatabaseSync(":memory:");
|
|
53
|
+
try {
|
|
54
|
+
database.exec(sqliteRelationshipSchemaMigration.sql);
|
|
55
|
+
const executor = createNodeSqliteExecutor(database);
|
|
56
|
+
const authorization = new SqliteAuthorization({
|
|
57
|
+
model,
|
|
58
|
+
namespace: "app",
|
|
59
|
+
executor,
|
|
60
|
+
});
|
|
61
|
+
const access = createAccessClient(authorization);
|
|
62
|
+
|
|
63
|
+
console.log(
|
|
64
|
+
await access.can(user("alice"), organization.task("task-1").view),
|
|
65
|
+
);
|
|
66
|
+
await withProtectedSqliteTransaction(
|
|
67
|
+
{ executor, authorization },
|
|
68
|
+
async ({ authorization: scoped }) => {
|
|
69
|
+
const txAccess = createAccessClient(scoped);
|
|
70
|
+
await txAccess.add(user("alice"), organization("org-1").member);
|
|
71
|
+
await txAccess.add(
|
|
72
|
+
organization("org-1"),
|
|
73
|
+
organization.task("task-1").organization,
|
|
74
|
+
);
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
console.log(
|
|
78
|
+
await access.can(user("alice"), organization.task("task-1").view),
|
|
79
|
+
);
|
|
80
|
+
await access.remove(user("alice"), organization("org-1").member);
|
|
81
|
+
console.log(
|
|
82
|
+
await access.can(user("alice"), organization.task("task-1").view),
|
|
83
|
+
);
|
|
84
|
+
} finally {
|
|
85
|
+
database.close();
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The script prints `false`, `true`, and `false` as organization membership is granted and revoked while `task` inherits `view` from `organization`.
|
|
90
|
+
|
|
91
|
+
## Protected writes
|
|
92
|
+
|
|
93
|
+
Use `withProtectedSqliteTransaction({ executor, authorization, now }, work)` when an authorization check guards a write. The helper runs `BEGIN IMMEDIATE`, pins one `nowMs` snapshot for the transaction, and passes `{ executor, authorization }` bound to that transaction.
|
|
94
|
+
|
|
95
|
+
Check permissions again inside the callback (using `createAccessClient(authorization)` or `authorization.check(...)`) and perform both business table writes and relationship updates through the scoped handles. Both handles expire as soon as the callback returns or throws. On error, the helper rolls back both application rows and relationship changes.
|
|
96
|
+
|
|
97
|
+
## Use it
|
|
98
|
+
|
|
99
|
+
Apply `sqliteRelationshipSchemaMigration.sql` (or iterate `sqliteRelationshipSchemaMigration.statements`) during application startup or migrations. The schema creates `dad_authorization_relationship` along with its reverse subject lookup index and partial expiration index. Wrap `SqliteAuthorization` with `createAccessClient(authorization)` from `@dads-framework/access/runtime` for typed `add`, `remove`, `can`, `list`, `whoCan`, and `listDirect` calls.
|
|
100
|
+
|
|
101
|
+
To evolve stored relationships across model revisions, use `runSqliteAccessMigrations` and `assertAccessMigrationsUpToDate` from [`@dads-framework/spicedb-access/migration`](../spicedb-access/README.md).
|
|
102
|
+
|
|
103
|
+
`SqliteAuthorization` compiles `@dads-framework/access` models into parameterized SQLite queries covering:
|
|
104
|
+
|
|
105
|
+
- Direct relations, nested and cyclic `team#member` subject sets, and wildcards (`user:*`).
|
|
106
|
+
- Compiled SQL list filters (`compileFilter({ subject, permission, resourceType, idColumn, scopeColumns?, now? })`) returning `{ sql, values }` (`EXISTS` or `IN (WITH RECURSIVE ...)`) for single-query paginated and sorted SQLite `SELECT` statements. Pass `scopeColumns: "auto"` to derive parent FK mappings automatically from `columnRelations`.
|
|
107
|
+
- Column-backed relations (`columnRelations`): bind single-target FK relations directly to columns on SQLite application tables (`documents.org_id`, `folders.parent_id`, `documents.owner_id`) so authorization reads them directly with zero dual-writes (`NULL` means absent). `writeRelationships` and `deleteRelationships` refuse manual mutations on column-backed relations. Call `await authorization.verifyColumnRelations()` at startup to verify live columns and index presence, and generate reverse-lookup index DDL with `sqliteColumnRelationIndexSql(bindings)`.
|
|
108
|
+
- Expiring relationships (`expires_at` epoch milliseconds) evaluated consistently at a single timestamp across reads and updated via upsert.
|
|
109
|
+
- Polymorphic arrows across multiple direct target entity types (`parents: [organization, folder]`).
|
|
110
|
+
- Recursive monotonic arrows (nested folders with `recursive: true`) with cycle termination on cyclic graph data.
|
|
111
|
+
- Transitive `lookupSubjects` returning concrete subject IDs and `hasWildcard`.
|
|
112
|
+
- Intersection arrows (`every()` / `.all()`) requiring at least one active target and satisfaction across every active target.
|
|
113
|
+
|
|
114
|
+
## What it refuses to do
|
|
115
|
+
|
|
116
|
+
Compilation rejects missing relation or permission targets, empty expressions, local permission self-cycles, non-monotonic recursive cycles through `.unless()` or `every()`, and non-linear recursive intersections.
|
|
117
|
+
|
|
118
|
+
Permission checks, resource lookups, and `compileFilter` require a concrete subject (`id` cannot be empty or `*`, and `relation` must be omitted), and `compileFilter` rejects invalid `idColumn` identifiers. Relationship writes reject unknown relations, mismatched subject types, empty identifiers, and invalid `expiresAt` dates. Scoped transaction handles reject all calls after the transaction callback ends.
|
|
119
|
+
|
|
120
|
+
## Contract
|
|
121
|
+
|
|
122
|
+
`SqliteAuthorization` extends `Authorization` and implements `check`, `checkMany`, `checkEach`, `lookupResources`, `lookupSubjects`, `compileFilter`, `writeRelationships`, `deleteRelationships`, `relationshipExists`, `listDirectSubjects`, `applyChanges`, and `inTransaction`.
|
|
123
|
+
|
|
124
|
+
Unknown permission names return `false`, `[]`, or `{ subjects: [], hasWildcard: false }`. Successful writes and deletes return an empty consistency token because SQLite reads observe committed writes directly. Database connection lifecycle and migration execution remain application-owned.
|
|
125
|
+
|
|
126
|
+
## Testing (`@dads-framework/sqlite-access/testing`)
|
|
127
|
+
|
|
128
|
+
Use `createSqliteTestAuthorization(model)` to open a disposable `:memory:`
|
|
129
|
+
SQLite database with the relationship table, covering indexes, and a
|
|
130
|
+
`ControllableClock` already installed (`using testEnv = createSqliteTestAuthorization(model)`).
|
|
131
|
+
Pair it with `proveAccess(model, { authorization: testEnv.authorization, clock: testEnv.clock }, ...)`
|
|
132
|
+
from `@dads-framework/access/testing` and `proveSqliteFilterParity(...)` to
|
|
133
|
+
verify that `compileFilter` and `compileFilter({ scopeColumns })` select the
|
|
134
|
+
exact same rows as `lookupResources` for every subject.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { SqliteAuthorization, type SqliteAccessOptions, } from "./sqlite-authorization.js";
|
|
2
|
+
export { sqliteColumnRelationIndexSql, type SqliteColumnRelationBinding, type SqliteColumnRelationCheckResult, } from "./policy/column-relations.js";
|
|
3
|
+
export type { SqliteAccessFilter, SqliteFilterQuery, } from "./policy/compile-filter.js";
|
|
4
|
+
export { createNodeSqliteExecutor, type SqliteDatabaseLike, type SqliteExecutor, type SqliteStatement, } from "./sqlite-executor.js";
|
|
5
|
+
export { SQLITE_RELATIONSHIP_TABLE, sqliteRelationshipSchemaMigration, type SqliteSchemaMigration, } from "./sqlite-schema.js";
|
|
6
|
+
export { type SqliteQuery, type SqliteRow, type SqliteRunResult, type SqliteValue, } from "./sqlite-types.js";
|
|
7
|
+
export { withProtectedSqliteTransaction, type ProtectedSqliteTransaction, type ProtectedSqliteTransactionOptions, } from "./with-protected-sqlite-transaction.js";
|
|
8
|
+
export { compileAccessPolicy, type CompiledSqliteAccessPolicy, } from "./policy/compile-access-policy.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,KAAK,mBAAmB,GACzB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,4BAA4B,EAC5B,KAAK,2BAA2B,EAChC,KAAK,+BAA+B,GACrC,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACV,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,yBAAyB,EACzB,iCAAiC,EACjC,KAAK,qBAAqB,GAC3B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,WAAW,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,8BAA8B,EAC9B,KAAK,0BAA0B,EAC/B,KAAK,iCAAiC,GACvC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,mBAAmB,EACnB,KAAK,0BAA0B,GAChC,MAAM,mCAAmC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { SqliteAuthorization, } from "./sqlite-authorization.js";
|
|
2
|
+
export { sqliteColumnRelationIndexSql, } from "./policy/column-relations.js";
|
|
3
|
+
export { createNodeSqliteExecutor, } from "./sqlite-executor.js";
|
|
4
|
+
export { SQLITE_RELATIONSHIP_TABLE, sqliteRelationshipSchemaMigration, } from "./sqlite-schema.js";
|
|
5
|
+
export {} from "./sqlite-types.js";
|
|
6
|
+
export { withProtectedSqliteTransaction, } from "./with-protected-sqlite-transaction.js";
|
|
7
|
+
export { compileAccessPolicy, } from "./policy/compile-access-policy.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,GAEpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,4BAA4B,GAG7B,MAAM,8BAA8B,CAAC;AAKtC,OAAO,EACL,wBAAwB,GAIzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,yBAAyB,EACzB,iCAAiC,GAElC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAKN,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,8BAA8B,GAG/B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,mBAAmB,GAEpB,MAAM,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { RoleToken } from "@dads-framework/access";
|
|
2
|
+
import type { SqliteExecutor } from "../sqlite-executor.js";
|
|
3
|
+
import type { CompiledSqliteColumnRelation, SqliteAuthorizationModel } from "./policy-model.js";
|
|
4
|
+
/** Public binding declaring that a single-target FK relation lives directly on a SQLite application table. */
|
|
5
|
+
export type SqliteColumnRelationBinding = {
|
|
6
|
+
readonly role: RoleToken;
|
|
7
|
+
/** Unquoted SQLite table name (e.g. `"documents"`). */
|
|
8
|
+
readonly table: string;
|
|
9
|
+
/** Primary key column storing the resource ID (e.g. `"id"`). */
|
|
10
|
+
readonly idColumn: string;
|
|
11
|
+
/** Foreign-key column storing the target ID (e.g. `"org_id"`, `"parent_id"`, or `"owner_id"`). */
|
|
12
|
+
readonly targetIdColumn: string;
|
|
13
|
+
};
|
|
14
|
+
/** Verification status for one SQLite column-backed relation against the live schema. */
|
|
15
|
+
export type SqliteColumnRelationCheckResult = {
|
|
16
|
+
readonly entity: string;
|
|
17
|
+
readonly relation: string;
|
|
18
|
+
readonly table: string;
|
|
19
|
+
readonly idColumn: string;
|
|
20
|
+
readonly targetIdColumn: string;
|
|
21
|
+
readonly hasRecommendedIndex: boolean;
|
|
22
|
+
readonly recommendedIndexSql: string;
|
|
23
|
+
};
|
|
24
|
+
/** Validate and compile `columnRelations` bindings against the lowered SQLite model. */
|
|
25
|
+
export declare function compileSqliteColumnRelations(model: Pick<SqliteAuthorizationModel, "relations">, bindings: readonly SqliteColumnRelationBinding[] | undefined): readonly CompiledSqliteColumnRelation[];
|
|
26
|
+
/** Look up a column-backed relation binding by `(entity, relation)`. */
|
|
27
|
+
export declare function findSqliteColumnRelation(model: SqliteAuthorizationModel, entity: string, relation: string): CompiledSqliteColumnRelation | undefined;
|
|
28
|
+
/** Generate recommended `(targetIdColumn, idColumn)` reverse-lookup index DDL for SQLite column-backed relations. */
|
|
29
|
+
export declare function sqliteColumnRelationIndexSql(bindings: readonly SqliteColumnRelationBinding[]): readonly string[];
|
|
30
|
+
/** Auto-derive `scopeColumns` from `columnRelations` on `resourceType` matching `idColumn`'s table prefix. */
|
|
31
|
+
export declare function deriveAutoSqliteScopeColumns(model: SqliteAuthorizationModel, resourceType: string, idColumn: string): Readonly<Record<string, string>> | undefined;
|
|
32
|
+
/** Verify every SQLite column-backed table and column exists and report index status. */
|
|
33
|
+
export declare function verifySqliteColumnRelations(relations: readonly CompiledSqliteColumnRelation[], executor: SqliteExecutor): Promise<readonly SqliteColumnRelationCheckResult[]>;
|
|
34
|
+
//# sourceMappingURL=column-relations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-relations.d.ts","sourceRoot":"","sources":["../../src/policy/column-relations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EACV,4BAA4B,EAC5B,wBAAwB,EACzB,MAAM,mBAAmB,CAAC;AAK3B,8GAA8G;AAC9G,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,uDAAuD;IACvD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gEAAgE;IAChE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,kGAAkG;IAClG,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC,CAAC;AAEF,yFAAyF;AACzF,MAAM,MAAM,+BAA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QL_TABLE_IDENT = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
3
|
+
function assertSafeIdentifier(value, pattern, label) {
|
|
4
|
+
if (!pattern.test(value)) {
|
|
5
|
+
throw new Error(`Invalid SQLite columnRelation ${label} "${value}": must be an unquoted SQL identifier`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/** Validate and compile `columnRelations` bindings against the lowered SQLite model. */
|
|
9
|
+
export function compileSqliteColumnRelations(model, bindings) {
|
|
10
|
+
if (bindings === undefined || bindings.length === 0)
|
|
11
|
+
return [];
|
|
12
|
+
const seen = new Set();
|
|
13
|
+
const compiled = [];
|
|
14
|
+
for (const binding of bindings) {
|
|
15
|
+
compiled.push(compileSingleBinding(model, binding, seen));
|
|
16
|
+
}
|
|
17
|
+
return Object.freeze(compiled);
|
|
18
|
+
}
|
|
19
|
+
function compileSingleBinding(model, binding, seen) {
|
|
20
|
+
const entity = binding.role.entityWireName;
|
|
21
|
+
const relation = binding.role.roleName;
|
|
22
|
+
const key = `${entity}\u0000${relation}`;
|
|
23
|
+
if (seen.has(key)) {
|
|
24
|
+
throw new Error(`Duplicate SQLite columnRelation binding for ${entity}#${relation}`);
|
|
25
|
+
}
|
|
26
|
+
seen.add(key);
|
|
27
|
+
assertSafeIdentifier(binding.table, SQL_TABLE_IDENT, "table");
|
|
28
|
+
assertSafeIdentifier(binding.idColumn, SQL_COLUMN_IDENT, "idColumn");
|
|
29
|
+
assertSafeIdentifier(binding.targetIdColumn, SQL_COLUMN_IDENT, "targetIdColumn");
|
|
30
|
+
const relDef = model.relations.find((candidate) => candidate.entity === entity && candidate.wireName === relation);
|
|
31
|
+
if (relDef === undefined) {
|
|
32
|
+
throw new Error(`SQLite column relation ${entity}#${relation} does not exist in the compiled access model`);
|
|
33
|
+
}
|
|
34
|
+
const onlyTarget = relDef.targets.length === 1 ? relDef.targets[0] : undefined;
|
|
35
|
+
if (onlyTarget === undefined || onlyTarget.kind !== "entity") {
|
|
36
|
+
throw new Error(`SQLite column relation ${entity}#${relation} must declare exactly one direct entity target (no polymorphic, wildcard, or userset targets)`);
|
|
37
|
+
}
|
|
38
|
+
return Object.freeze({
|
|
39
|
+
entity,
|
|
40
|
+
relation,
|
|
41
|
+
targetEntity: onlyTarget.entity,
|
|
42
|
+
table: binding.table,
|
|
43
|
+
idColumn: binding.idColumn,
|
|
44
|
+
targetIdColumn: binding.targetIdColumn,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/** Look up a column-backed relation binding by `(entity, relation)`. */
|
|
48
|
+
export function findSqliteColumnRelation(model, entity, relation) {
|
|
49
|
+
return model.columnRelations?.find((entry) => entry.entity === entity && entry.relation === relation);
|
|
50
|
+
}
|
|
51
|
+
/** Generate recommended `(targetIdColumn, idColumn)` reverse-lookup index DDL for SQLite column-backed relations. */
|
|
52
|
+
export function sqliteColumnRelationIndexSql(bindings) {
|
|
53
|
+
return bindings.map((binding) => {
|
|
54
|
+
assertSafeIdentifier(binding.table, SQL_TABLE_IDENT, "table");
|
|
55
|
+
assertSafeIdentifier(binding.idColumn, SQL_COLUMN_IDENT, "idColumn");
|
|
56
|
+
assertSafeIdentifier(binding.targetIdColumn, SQL_COLUMN_IDENT, "targetIdColumn");
|
|
57
|
+
const indexName = `idx_dad_${binding.table}_${binding.targetIdColumn}_${binding.idColumn}`;
|
|
58
|
+
return `CREATE INDEX IF NOT EXISTS ${indexName} ON ${binding.table} (${binding.targetIdColumn}, ${binding.idColumn});`;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/** Auto-derive `scopeColumns` from `columnRelations` on `resourceType` matching `idColumn`'s table prefix. */
|
|
62
|
+
export function deriveAutoSqliteScopeColumns(model, resourceType, idColumn) {
|
|
63
|
+
const bindings = model.columnRelations?.filter((entry) => entry.entity === resourceType);
|
|
64
|
+
if (bindings === undefined || bindings.length === 0)
|
|
65
|
+
return undefined;
|
|
66
|
+
const dotIndex = idColumn.indexOf(".");
|
|
67
|
+
const prefix = dotIndex === -1 ? "" : `${idColumn.slice(0, dotIndex)}.`;
|
|
68
|
+
const derived = {};
|
|
69
|
+
for (const binding of bindings) {
|
|
70
|
+
derived[binding.relation] = `${prefix}${binding.targetIdColumn}`;
|
|
71
|
+
}
|
|
72
|
+
return derived;
|
|
73
|
+
}
|
|
74
|
+
function readText(row, key) {
|
|
75
|
+
const value = row[key];
|
|
76
|
+
return typeof value === "string" ? value : "";
|
|
77
|
+
}
|
|
78
|
+
/** Verify every SQLite column-backed table and column exists and report index status. */
|
|
79
|
+
export async function verifySqliteColumnRelations(relations, executor) {
|
|
80
|
+
const results = [];
|
|
81
|
+
for (const binding of relations) {
|
|
82
|
+
results.push(await verifyOneSqliteColumnRelation(binding, executor));
|
|
83
|
+
}
|
|
84
|
+
return results;
|
|
85
|
+
}
|
|
86
|
+
async function verifyOneSqliteColumnRelation(binding, executor) {
|
|
87
|
+
const tableRows = await executor.all(`PRAGMA table_info(${binding.table})`, []);
|
|
88
|
+
const columns = new Set(tableRows.map((row) => readText(row, "name")));
|
|
89
|
+
for (const required of [binding.idColumn, binding.targetIdColumn]) {
|
|
90
|
+
if (!columns.has(required)) {
|
|
91
|
+
throw new Error(`SQLite column relation ${binding.entity}#${binding.relation} expects column "${binding.table}.${required}", which does not exist`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const hasRecommendedIndex = await hasLeadingTargetIndex(binding, executor);
|
|
95
|
+
const indexName = `idx_dad_${binding.table}_${binding.targetIdColumn}_${binding.idColumn}`;
|
|
96
|
+
return {
|
|
97
|
+
entity: binding.entity,
|
|
98
|
+
relation: binding.relation,
|
|
99
|
+
table: binding.table,
|
|
100
|
+
idColumn: binding.idColumn,
|
|
101
|
+
targetIdColumn: binding.targetIdColumn,
|
|
102
|
+
hasRecommendedIndex,
|
|
103
|
+
recommendedIndexSql: `CREATE INDEX IF NOT EXISTS ${indexName} ON ${binding.table} (${binding.targetIdColumn}, ${binding.idColumn});`,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
async function hasLeadingTargetIndex(binding, executor) {
|
|
107
|
+
const indexes = await executor.all(`PRAGMA index_list(${binding.table})`, []);
|
|
108
|
+
for (const indexRow of indexes) {
|
|
109
|
+
const indexName = readText(indexRow, "name");
|
|
110
|
+
if (!SQL_COLUMN_IDENT.test(indexName))
|
|
111
|
+
continue;
|
|
112
|
+
const infoRows = await executor.all(`PRAGMA index_info(${indexName})`, []);
|
|
113
|
+
const firstCol = infoRows.find((row) => Number(row["seqno"]) === 0);
|
|
114
|
+
if (firstCol !== undefined &&
|
|
115
|
+
readText(firstCol, "name") === binding.targetIdColumn) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=column-relations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-relations.js","sourceRoot":"","sources":["../../src/policy/column-relations.ts"],"names":[],"mappings":"AAOA,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AACpD,MAAM,eAAe,GAAG,0BAA0B,CAAC;AAwBnD,SAAS,oBAAoB,CAC3B,KAAa,EACb,OAAe,EACf,KAAa;IAEb,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,iCAAiC,KAAK,KAAK,KAAK,uCAAuC,CACxF,CAAC;IACJ,CAAC;AACH,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,4BAA4B,CAC1C,KAAkD,EAClD,QAA4D;IAE5D,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAC/D,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,QAAQ,GAAmC,EAAE,CAAC;IACpD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,QAAQ,CAAC,IAAI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,CAAC,cAAc,KAAK,OAAO,CAAC,QAAQ,IAAI;KACrI,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,qBAAqB,CAClC,OAAqC,EACrC,QAAwB;IAExB,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,qBAAqB,OAAO,CAAC,KAAK,GAAG,EAAE,EAAE,CAAC,CAAC;IAC9E,KAAK,MAAM,QAAQ,IAAI,OAAO,EAAE,CAAC;QAC/B,MAAM,SAAS,GAAG,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC7C,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC;YAAE,SAAS;QAChD,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,qBAAqB,SAAS,GAAG,EAAE,EAAE,CAAC,CAAC;QAC3E,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QACpE,IACE,QAAQ,KAAK,SAAS;YACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,KAAK,OAAO,CAAC,cAAc,EACrD,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type AccessModel } from "@dads-framework/access";
|
|
2
|
+
import { type SqliteColumnRelationBinding } from "./column-relations.js";
|
|
3
|
+
import { type SqliteAuthorizationModel } from "./policy-model.js";
|
|
4
|
+
export type CompiledSqliteAccessPolicy = {
|
|
5
|
+
readonly model: SqliteAuthorizationModel;
|
|
6
|
+
/** The engine's permission name for an authored permission or direct relation. */
|
|
7
|
+
permissionName(entity: string, name: string): string | undefined;
|
|
8
|
+
};
|
|
9
|
+
/** Compile an `@dads-framework/access` model into the lowered SQLite authorization model. */
|
|
10
|
+
export declare function compileAccessPolicy(access: AccessModel, columnRelations?: readonly SqliteColumnRelationBinding[]): CompiledSqliteAccessPolicy;
|
|
11
|
+
//# sourceMappingURL=compile-access-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-access-policy.d.ts","sourceRoot":"","sources":["../../src/policy/compile-access-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAEL,KAAK,2BAA2B,EACjC,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAGL,KAAK,wBAAwB,EAI9B,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,0BAA0B,GAAG;IACvC,QAAQ,CAAC,KAAK,EAAE,wBAAwB,CAAC;IACzC,kFAAkF;IAClF,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAClE,CAAC;AAOF,6FAA6F;AAC7F,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,WAAW,EACnB,eAAe,CAAC,EAAE,SAAS,2BAA2B,EAAE,GACvD,0BAA0B,CAwC5B"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { emitAccessIr, } from "@dads-framework/access";
|
|
2
|
+
import { compileSqliteColumnRelations, } from "./column-relations.js";
|
|
3
|
+
import { analyzePermissionCycles } from "./cycle-analysis.js";
|
|
4
|
+
import { permissionKey, } from "./policy-model.js";
|
|
5
|
+
/** Compile an `@dads-framework/access` model into the lowered SQLite authorization model. */
|
|
6
|
+
export function compileAccessPolicy(access, columnRelations) {
|
|
7
|
+
const definitions = emitAccessIr(access);
|
|
8
|
+
const byName = new Map(definitions.map((entry) => [entry.wireName, entry]));
|
|
9
|
+
const generated = new Map(definitions.map((entry) => [entry.wireName, rolePermissions(entry)]));
|
|
10
|
+
const context = { byName, generated };
|
|
11
|
+
const permissions = definitions.flatMap((entry) => compileEntityPermissions(entry, context));
|
|
12
|
+
const permissionByKey = new Map(permissions.map((entry) => [
|
|
13
|
+
permissionKey(entry.entity, entry.wireName),
|
|
14
|
+
entry,
|
|
15
|
+
]));
|
|
16
|
+
const cyclicSccsByKey = analyzePermissionCycles(permissions);
|
|
17
|
+
const relations = definitions.flatMap(lowerRelations);
|
|
18
|
+
const compiledColumns = compileSqliteColumnRelations({ relations }, columnRelations);
|
|
19
|
+
const model = {
|
|
20
|
+
entities: definitions.map((entry, index) => ({
|
|
21
|
+
wireName: entry.wireName,
|
|
22
|
+
sourceName: `entity_${index}`,
|
|
23
|
+
})),
|
|
24
|
+
relations,
|
|
25
|
+
permissions,
|
|
26
|
+
permissionByKey,
|
|
27
|
+
cyclicSccsByKey,
|
|
28
|
+
...(compiledColumns.length === 0
|
|
29
|
+
? {}
|
|
30
|
+
: { columnRelations: compiledColumns }),
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
model,
|
|
34
|
+
permissionName: (entity, name) => resolvePermissionName(context, entity, name),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function resolvePermissionName(context, entity, name) {
|
|
38
|
+
const definition = context.byName.get(entity);
|
|
39
|
+
if (definition?.permissions.some((entry) => entry.name === name)) {
|
|
40
|
+
return name;
|
|
41
|
+
}
|
|
42
|
+
return context.generated.get(entity)?.get(name);
|
|
43
|
+
}
|
|
44
|
+
function lowerRelations(definition) {
|
|
45
|
+
return definition.roles.map((role, index) => ({
|
|
46
|
+
entity: definition.wireName,
|
|
47
|
+
sourceName: `relation_${index}`,
|
|
48
|
+
wireName: role.name,
|
|
49
|
+
targets: role.subjects.map((subject) => {
|
|
50
|
+
if (subject.kind === "userset") {
|
|
51
|
+
return {
|
|
52
|
+
kind: "subject-set",
|
|
53
|
+
entity: subject.wireName,
|
|
54
|
+
relation: subject.relation,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
kind: subject.kind === "type" ? "entity" : "wildcard",
|
|
59
|
+
entity: subject.wireName,
|
|
60
|
+
};
|
|
61
|
+
}),
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
function compileEntityPermissions(definition, context) {
|
|
65
|
+
const authored = lowerPermissions(definition, context);
|
|
66
|
+
const wrappers = context.generated.get(definition.wireName) ?? new Map();
|
|
67
|
+
const relationWrappers = [...wrappers].map(([relation, wireName], index) => ({
|
|
68
|
+
entity: definition.wireName,
|
|
69
|
+
sourceName: `relation_permission_${index}`,
|
|
70
|
+
wireName,
|
|
71
|
+
expression: { kind: "relation", relation },
|
|
72
|
+
}));
|
|
73
|
+
return [...authored, ...relationWrappers];
|
|
74
|
+
}
|
|
75
|
+
function lowerPermissions(definition, context) {
|
|
76
|
+
const byName = new Map(definition.permissions.map((entry) => [entry.name, entry.terms]));
|
|
77
|
+
const cached = new Map();
|
|
78
|
+
const visiting = new Set();
|
|
79
|
+
function resolve(name) {
|
|
80
|
+
const existing = cached.get(name);
|
|
81
|
+
if (existing !== undefined)
|
|
82
|
+
return existing;
|
|
83
|
+
if (visiting.has(name)) {
|
|
84
|
+
throw new Error(`Cyclic permission reference ${definition.wireName}#${name}`);
|
|
85
|
+
}
|
|
86
|
+
const terms = byName.get(name);
|
|
87
|
+
if (terms === undefined) {
|
|
88
|
+
throw new Error(`Unknown permission ${definition.wireName}#${name}`);
|
|
89
|
+
}
|
|
90
|
+
visiting.add(name);
|
|
91
|
+
const compiled = group("any-of", terms.map(lower));
|
|
92
|
+
visiting.delete(name);
|
|
93
|
+
cached.set(name, compiled);
|
|
94
|
+
return compiled;
|
|
95
|
+
}
|
|
96
|
+
function lower(term) {
|
|
97
|
+
if (term.kind === "permission")
|
|
98
|
+
return resolve(term.name);
|
|
99
|
+
if (term.kind === "through" || term.kind === "through-all") {
|
|
100
|
+
return lowerArrow(definition, context, term);
|
|
101
|
+
}
|
|
102
|
+
return lowerLocal(term, lower);
|
|
103
|
+
}
|
|
104
|
+
return definition.permissions.map(({ name }, index) => ({
|
|
105
|
+
entity: definition.wireName,
|
|
106
|
+
sourceName: `permission_${index}`,
|
|
107
|
+
wireName: name,
|
|
108
|
+
expression: resolve(name),
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
function lowerArrow(definition, context, term) {
|
|
112
|
+
const role = definition.roles.find(({ name }) => name === term.roleName);
|
|
113
|
+
if (role === undefined) {
|
|
114
|
+
throw new Error(`Unknown arrow relation ${definition.wireName}#${term.roleName}`);
|
|
115
|
+
}
|
|
116
|
+
const entityTargets = role.subjects.filter((subject) => subject.kind === "type");
|
|
117
|
+
if (entityTargets.length === 0) {
|
|
118
|
+
throw new Error(`SQLite arrow ${definition.wireName}#${term.roleName} requires at least one direct entity target`);
|
|
119
|
+
}
|
|
120
|
+
const targets = resolveArrowTargets(entityTargets, term.targetPermission, context);
|
|
121
|
+
if (targets.length === 0) {
|
|
122
|
+
throw new Error(`Unknown arrow target ${definition.wireName}#${term.roleName}->${term.targetPermission}`);
|
|
123
|
+
}
|
|
124
|
+
return { kind: term.kind, relation: term.roleName, targets };
|
|
125
|
+
}
|
|
126
|
+
function resolveArrowTargets(entityTargets, targetPermission, context) {
|
|
127
|
+
const seen = new Set();
|
|
128
|
+
const resolved = [];
|
|
129
|
+
for (const target of entityTargets) {
|
|
130
|
+
if (seen.has(target.wireName))
|
|
131
|
+
continue;
|
|
132
|
+
seen.add(target.wireName);
|
|
133
|
+
const permission = resolvePermissionName(context, target.wireName, targetPermission);
|
|
134
|
+
if (permission !== undefined) {
|
|
135
|
+
resolved.push({ entity: target.wireName, permission });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return resolved;
|
|
139
|
+
}
|
|
140
|
+
function lowerLocal(term, lower) {
|
|
141
|
+
switch (term.kind) {
|
|
142
|
+
case "role":
|
|
143
|
+
return { kind: "relation", relation: term.name };
|
|
144
|
+
case "or":
|
|
145
|
+
return group("any-of", term.terms.map(lower));
|
|
146
|
+
case "both":
|
|
147
|
+
return group("all-of", [lower(term.left), lower(term.right)]);
|
|
148
|
+
case "gated":
|
|
149
|
+
return group("all-of", [lower(term.term), lower(term.condition)]);
|
|
150
|
+
case "excluding":
|
|
151
|
+
return {
|
|
152
|
+
kind: "exclude",
|
|
153
|
+
include: lower(term.term),
|
|
154
|
+
exclude: lower(term.banned),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function group(kind, expressions) {
|
|
159
|
+
if (expressions.length === 0) {
|
|
160
|
+
throw new Error("SQLite authorization requires nonempty permission expressions");
|
|
161
|
+
}
|
|
162
|
+
const [only] = expressions;
|
|
163
|
+
return expressions.length === 1 && only !== undefined
|
|
164
|
+
? only
|
|
165
|
+
: { kind, expressions };
|
|
166
|
+
}
|
|
167
|
+
function rolePermissions(definition) {
|
|
168
|
+
const names = new Set([
|
|
169
|
+
...definition.roles.map((entry) => entry.name),
|
|
170
|
+
...definition.permissions.map((entry) => entry.name),
|
|
171
|
+
]);
|
|
172
|
+
const wrappers = new Map();
|
|
173
|
+
let suffix = 0;
|
|
174
|
+
for (const role of definition.roles) {
|
|
175
|
+
let generated;
|
|
176
|
+
do {
|
|
177
|
+
generated = `dads_relation_${suffix}`;
|
|
178
|
+
suffix += 1;
|
|
179
|
+
} while (names.has(generated));
|
|
180
|
+
wrappers.set(role.name, generated);
|
|
181
|
+
}
|
|
182
|
+
return wrappers;
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=compile-access-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-access-policy.js","sourceRoot":"","sources":["../../src/policy/compile-access-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GAIb,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,4BAA4B,GAE7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EACL,aAAa,GAMd,MAAM,mBAAmB,CAAC;AAa3B,6FAA6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AAS,CAAC,EAAE;QAC/B,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SqliteQuery } from "../sqlite-types.js";
|
|
2
|
+
import { type ForwardCompileContext, type ForwardPermissionCompiler, type SqlResource, type SqlSubject } from "./compile-forward-scc.js";
|
|
3
|
+
import type { SqliteArrowTarget } from "./policy-model.js";
|
|
4
|
+
/** Compile a forward `through` arrow predicate against either a column relation or the tuple table. */
|
|
5
|
+
export declare function compileSqliteThrough(context: ForwardCompileContext, subject: SqlSubject, resource: SqlResource, relation: string, targets: readonly SqliteArrowTarget[], compilePermission: ForwardPermissionCompiler): SqliteQuery;
|
|
6
|
+
/** Compile a forward `through-all` (`every()`) arrow predicate against a column relation or tuple table. */
|
|
7
|
+
export declare function compileSqliteThroughAll(context: ForwardCompileContext, subject: SqlSubject, resource: SqlResource, relation: string, targets: readonly SqliteArrowTarget[], compilePermission: ForwardPermissionCompiler): SqliteQuery;
|
|
8
|
+
//# sourceMappingURL=compile-check-through.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-check-through.d.ts","sourceRoot":"","sources":["../../src/policy/compile-check-through.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAIL,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAG3D,uGAAuG;AACvG,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,UAAU,EACnB,QAAQ,EAAE,WAAW,EACrB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,SAAS,iBAAiB,EAAE,EACrC,iBAAiB,EAAE,yBAAyB,GAC3C,WAAW,CA6Cb;AAED,4GAA4G;AAC5G,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,UAAU,EACnB,QAAQ,EAAE,WAAW,EACrB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,SAAS,iBAAiB,EAAE,EACrC,iBAAiB,EAAE,yBAAyB,GAC3C,WAAW,CAoEb"}
|