@lunora/server 1.0.0-alpha.26 → 1.0.0-alpha.28

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/server",
3
- "version": "1.0.0-alpha.26",
3
+ "version": "1.0.0-alpha.28",
4
4
  "description": "Server primitives for Lunora: defineSchema, defineTable, query, mutation, and action",
5
5
  "keywords": [
6
6
  "backend",
@@ -62,11 +62,11 @@
62
62
  "access": "public"
63
63
  },
64
64
  "dependencies": {
65
- "@lunora/errors": "1.0.0-alpha.5",
66
- "@lunora/scheduler": "1.0.0-alpha.10",
67
- "@lunora/values": "1.0.0-alpha.8",
65
+ "@lunora/errors": "1.0.0-alpha.6",
66
+ "@lunora/scheduler": "1.0.0-alpha.11",
67
+ "@lunora/values": "1.0.0-alpha.9",
68
68
  "drizzle-orm": "^0.45.2",
69
- "hono": "^4.12.28"
69
+ "hono": "^4.12.30"
70
70
  },
71
71
  "engines": {
72
72
  "node": "^22.15.0 || >=24.11.0"
@@ -1,141 +0,0 @@
1
- import { WhereOf } from "../data-model.mjs";
2
- /** Structural mirror of `@lunora/do`'s `WhereInput`. */
3
- interface WhereInput {
4
- [field: string]: unknown;
5
- AND?: WhereInput[];
6
- NOT?: WhereInput;
7
- OR?: WhereInput[];
8
- }
9
- /** Operations a policy can gate. `read` covers `get`/`findMany`/`query`/`count`. */
10
- type PolicyOperation = "delete" | "insert" | "read" | "update";
11
- /**
12
- * A policy's `when` decision:
13
- *
14
- * - `WhereInput`: a row-shape predicate. On reads it is AND-merged into every
15
- * query against the table — the row is invisible unless it matches. On writes
16
- * it is evaluated against the candidate document (`insert`) or the pre-write
17
- * row (`update`/`delete`); a mismatch denies the write with
18
- * `LunoraError("FORBIDDEN")`. Same operator set as the SQL compiler
19
- * (`eq`/`ne`/`in`/`notIn`/`lt`/`lte`/`gt`/`gte`/`isNull`/`contains` +
20
- * `AND`/`OR`/`NOT`).
21
- * - `true`: unrestricted. On reads no predicate is merged; on writes the row is
22
- * allowed.
23
- * - `false`: deny. On reads the table is forced to match zero rows (a sentinel
24
- * predicate); on writes the operation throws `LunoraError("FORBIDDEN")`.
25
- *
26
- * Returning `undefined` opts this specific policy out (rare; useful when
27
- * branching on `ctx.auth.roles`).
28
- */
29
- type PolicyDecision = WhereInput | boolean | undefined;
30
- /**
31
- * Relation-aware twin of {@link PolicyDecision}, parameterized over the
32
- * generated `DataModel` (`DM`) + `Relations` (`REL`) maps and a table `T`. A
33
- * read policy may now return a Prisma-style relation predicate (the
34
- * `@lunora/do` pre-resolver resolves it via a semijoin), so the typed
35
- * authoring surface accepts `WhereOf<DM, REL, T>` — column predicates **and**
36
- * `is`/`isNot`/`some`/`none`/`every` over `T`'s declared relations — in
37
- * addition to the `boolean`/`undefined` decisions. Used by the project-bound
38
- * `definePolicy` from `createPolicyDsl`.
39
- */
40
- type PolicyDecisionOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = WhereOf<DM, REL, T> | boolean | undefined;
41
- /**
42
- * Relation-aware input for a project-bound `definePolicy` (see
43
- * `createPolicyDsl`). `table` is constrained to a real table name and
44
- * `when`'s return type is the table-specific {@link PolicyDecisionOf} — so an
45
- * unknown table, a stray column, or a relation predicate naming a relation the
46
- * table does not declare is a compile error rather than a silent runtime deny.
47
- */
48
- interface TypedDefinePolicyInput<DM, REL extends Record<keyof DM, object>, T extends keyof DM, Context = unknown, Identity = Record<string, unknown>> {
49
- on: PolicyOperation;
50
- table: T;
51
- when: (context: PolicyContext<Context, Identity>) => PolicyDecisionOf<DM, REL, T>;
52
- }
53
- /**
54
- * Context handed to a policy. `auth.roles` is the per-request role list,
55
- * sourced from the identity resolver (better-auth claims today). `auth.can`
56
- * answers whether any of those roles grants a permission (see
57
- * {@link Permission} / {@link RlsOptions}). `row` is present only on write
58
- * policies (`insert`/`update`/`delete`) — for `update` and `delete` it is the
59
- * pre-write row; for `insert` it is the candidate document. `ctx` is the full
60
- * procedure context the middleware closed over.
61
- */
62
- interface PolicyContext<Context = unknown, Identity = Record<string, unknown>> {
63
- readonly auth: {
64
- /**
65
- * `true` when any of the request's `roles` grants `permission` (passed
66
- * by {@link Permission} object or its `name`). Always `false` when no
67
- * roles were handed to the middleware (`rls(policies, { roles })`), or
68
- * when none of the request's roles lists the permission.
69
- */
70
- readonly can: (permission: Permission | string) => boolean;
71
- /**
72
- * The resolved identity, typed to the `Identity` type parameter bound on
73
- * `createPolicyDsl` — e.g. the app's `defineIdentity(...)` claim type via
74
- * the `InferIdentity` helper; otherwise the untyped claim bag.
75
- * `undefined`/`null` when the request is anonymous.
76
- */
77
- readonly identity?: Identity | null;
78
- readonly roles: ReadonlyArray<string>;
79
- readonly userId: null | string;
80
- };
81
- readonly ctx: Context;
82
- readonly row?: Record<string, unknown>;
83
- }
84
- /** A registered policy as stored in the policy table. */
85
- interface Policy<Context = unknown> {
86
- readonly on: PolicyOperation;
87
- readonly table: string;
88
- readonly when: (context: PolicyContext<Context>) => PolicyDecision;
89
- }
90
- /**
91
- * Input accepted by `definePolicy`. The branded result is the same
92
- * shape; we keep the input/output split so callers can read JSDoc on the
93
- * constructor without the type re-exposing `Policy` internals.
94
- */
95
- interface DefinePolicyInput<Context = unknown> {
96
- on: PolicyOperation;
97
- /** Logical table name the policy applies to. */
98
- table: string;
99
- /**
100
- * Decision function. Returning a `WhereInput` (read only) AND-merges the
101
- * predicate; `true` allows; `false` denies; `undefined` skips this policy.
102
- *
103
- * NOTE: `count()` is **unsupported** on a policy-restricted table — the
104
- * reader throws `LunoraError("COUNT_RLS_UNSUPPORTED")` (422). This mirrors
105
- * kitcn's documented behavior.
106
- */
107
- when: (context: PolicyContext<Context>) => PolicyDecision;
108
- }
109
- /**
110
- * A named, abstract capability a policy can check with `ctx.auth.can(...)`,
111
- * instead of branching on raw role strings. Declare one with
112
- * `definePermission`; grant it to a role via {@link Role.permissions};
113
- * register the roles with the middleware via {@link RlsOptions.roles}.
114
- */
115
- interface Permission {
116
- readonly description?: string;
117
- readonly name: string;
118
- }
119
- /**
120
- * A role declaration. Roles are string labels attached to the request's
121
- * identity (via better-auth claims today). `permissions` lists the
122
- * capabilities the role grants — at request time the middleware unions the
123
- * permissions of every role in `ctx.auth.roles` so a policy can ask
124
- * `ctx.auth.can(permission)` rather than enumerate roles.
125
- */
126
- interface Role {
127
- readonly description?: string;
128
- readonly name: string;
129
- /** Permissions this role grants — by {@link Permission} object or bare name. */
130
- readonly permissions?: ReadonlyArray<Permission | string>;
131
- }
132
- /**
133
- * Options for the `rls(policies, options)` middleware. `roles` registers the
134
- * role→permission grants that back `ctx.auth.can(...)`; a role not listed here
135
- * grants no permissions (so `can` is conservative — it fails closed for
136
- * unknown roles).
137
- */
138
- interface RlsOptions {
139
- readonly roles?: ReadonlyArray<Role>;
140
- }
141
- export { DefinePolicyInput as D, PolicyOperation as P, Role as R, TypedDefinePolicyInput as T, WhereInput as W, Policy as a, Permission as b, RlsOptions as c, PolicyContext as d, PolicyDecision as e, PolicyDecisionOf as f };
@@ -1,141 +0,0 @@
1
- import { WhereOf } from "../data-model.js";
2
- /** Structural mirror of `@lunora/do`'s `WhereInput`. */
3
- interface WhereInput {
4
- [field: string]: unknown;
5
- AND?: WhereInput[];
6
- NOT?: WhereInput;
7
- OR?: WhereInput[];
8
- }
9
- /** Operations a policy can gate. `read` covers `get`/`findMany`/`query`/`count`. */
10
- type PolicyOperation = "delete" | "insert" | "read" | "update";
11
- /**
12
- * A policy's `when` decision:
13
- *
14
- * - `WhereInput`: a row-shape predicate. On reads it is AND-merged into every
15
- * query against the table — the row is invisible unless it matches. On writes
16
- * it is evaluated against the candidate document (`insert`) or the pre-write
17
- * row (`update`/`delete`); a mismatch denies the write with
18
- * `LunoraError("FORBIDDEN")`. Same operator set as the SQL compiler
19
- * (`eq`/`ne`/`in`/`notIn`/`lt`/`lte`/`gt`/`gte`/`isNull`/`contains` +
20
- * `AND`/`OR`/`NOT`).
21
- * - `true`: unrestricted. On reads no predicate is merged; on writes the row is
22
- * allowed.
23
- * - `false`: deny. On reads the table is forced to match zero rows (a sentinel
24
- * predicate); on writes the operation throws `LunoraError("FORBIDDEN")`.
25
- *
26
- * Returning `undefined` opts this specific policy out (rare; useful when
27
- * branching on `ctx.auth.roles`).
28
- */
29
- type PolicyDecision = WhereInput | boolean | undefined;
30
- /**
31
- * Relation-aware twin of {@link PolicyDecision}, parameterized over the
32
- * generated `DataModel` (`DM`) + `Relations` (`REL`) maps and a table `T`. A
33
- * read policy may now return a Prisma-style relation predicate (the
34
- * `@lunora/do` pre-resolver resolves it via a semijoin), so the typed
35
- * authoring surface accepts `WhereOf&lt;DM, REL, T>` — column predicates **and**
36
- * `is`/`isNot`/`some`/`none`/`every` over `T`'s declared relations — in
37
- * addition to the `boolean`/`undefined` decisions. Used by the project-bound
38
- * `definePolicy` from `createPolicyDsl`.
39
- */
40
- type PolicyDecisionOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = WhereOf<DM, REL, T> | boolean | undefined;
41
- /**
42
- * Relation-aware input for a project-bound `definePolicy` (see
43
- * `createPolicyDsl`). `table` is constrained to a real table name and
44
- * `when`'s return type is the table-specific {@link PolicyDecisionOf} — so an
45
- * unknown table, a stray column, or a relation predicate naming a relation the
46
- * table does not declare is a compile error rather than a silent runtime deny.
47
- */
48
- interface TypedDefinePolicyInput<DM, REL extends Record<keyof DM, object>, T extends keyof DM, Context = unknown, Identity = Record<string, unknown>> {
49
- on: PolicyOperation;
50
- table: T;
51
- when: (context: PolicyContext<Context, Identity>) => PolicyDecisionOf<DM, REL, T>;
52
- }
53
- /**
54
- * Context handed to a policy. `auth.roles` is the per-request role list,
55
- * sourced from the identity resolver (better-auth claims today). `auth.can`
56
- * answers whether any of those roles grants a permission (see
57
- * {@link Permission} / {@link RlsOptions}). `row` is present only on write
58
- * policies (`insert`/`update`/`delete`) — for `update` and `delete` it is the
59
- * pre-write row; for `insert` it is the candidate document. `ctx` is the full
60
- * procedure context the middleware closed over.
61
- */
62
- interface PolicyContext<Context = unknown, Identity = Record<string, unknown>> {
63
- readonly auth: {
64
- /**
65
- * `true` when any of the request's `roles` grants `permission` (passed
66
- * by {@link Permission} object or its `name`). Always `false` when no
67
- * roles were handed to the middleware (`rls(policies, { roles })`), or
68
- * when none of the request's roles lists the permission.
69
- */
70
- readonly can: (permission: Permission | string) => boolean;
71
- /**
72
- * The resolved identity, typed to the `Identity` type parameter bound on
73
- * `createPolicyDsl` — e.g. the app's `defineIdentity(...)` claim type via
74
- * the `InferIdentity` helper; otherwise the untyped claim bag.
75
- * `undefined`/`null` when the request is anonymous.
76
- */
77
- readonly identity?: Identity | null;
78
- readonly roles: ReadonlyArray<string>;
79
- readonly userId: null | string;
80
- };
81
- readonly ctx: Context;
82
- readonly row?: Record<string, unknown>;
83
- }
84
- /** A registered policy as stored in the policy table. */
85
- interface Policy<Context = unknown> {
86
- readonly on: PolicyOperation;
87
- readonly table: string;
88
- readonly when: (context: PolicyContext<Context>) => PolicyDecision;
89
- }
90
- /**
91
- * Input accepted by `definePolicy`. The branded result is the same
92
- * shape; we keep the input/output split so callers can read JSDoc on the
93
- * constructor without the type re-exposing `Policy` internals.
94
- */
95
- interface DefinePolicyInput<Context = unknown> {
96
- on: PolicyOperation;
97
- /** Logical table name the policy applies to. */
98
- table: string;
99
- /**
100
- * Decision function. Returning a `WhereInput` (read only) AND-merges the
101
- * predicate; `true` allows; `false` denies; `undefined` skips this policy.
102
- *
103
- * NOTE: `count()` is **unsupported** on a policy-restricted table — the
104
- * reader throws `LunoraError("COUNT_RLS_UNSUPPORTED")` (422). This mirrors
105
- * kitcn's documented behavior.
106
- */
107
- when: (context: PolicyContext<Context>) => PolicyDecision;
108
- }
109
- /**
110
- * A named, abstract capability a policy can check with `ctx.auth.can(...)`,
111
- * instead of branching on raw role strings. Declare one with
112
- * `definePermission`; grant it to a role via {@link Role.permissions};
113
- * register the roles with the middleware via {@link RlsOptions.roles}.
114
- */
115
- interface Permission {
116
- readonly description?: string;
117
- readonly name: string;
118
- }
119
- /**
120
- * A role declaration. Roles are string labels attached to the request's
121
- * identity (via better-auth claims today). `permissions` lists the
122
- * capabilities the role grants — at request time the middleware unions the
123
- * permissions of every role in `ctx.auth.roles` so a policy can ask
124
- * `ctx.auth.can(permission)` rather than enumerate roles.
125
- */
126
- interface Role {
127
- readonly description?: string;
128
- readonly name: string;
129
- /** Permissions this role grants — by {@link Permission} object or bare name. */
130
- readonly permissions?: ReadonlyArray<Permission | string>;
131
- }
132
- /**
133
- * Options for the `rls(policies, options)` middleware. `roles` registers the
134
- * role→permission grants that back `ctx.auth.can(...)`; a role not listed here
135
- * grants no permissions (so `can` is conservative — it fails closed for
136
- * unknown roles).
137
- */
138
- interface RlsOptions {
139
- readonly roles?: ReadonlyArray<Role>;
140
- }
141
- export { DefinePolicyInput as D, PolicyOperation as P, Role as R, TypedDefinePolicyInput as T, WhereInput as W, Policy as a, Permission as b, RlsOptions as c, PolicyContext as d, PolicyDecision as e, PolicyDecisionOf as f };