foldkit-guard 0.5.0 → 0.7.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.
Files changed (37) hide show
  1. package/README.md +218 -44
  2. package/dist/agent.d.mts +1 -1
  3. package/dist/agent.mjs +1 -1
  4. package/dist/{attach-CRCF5XHS.mjs → attach-CEGlbWu5.mjs} +17 -2
  5. package/dist/attach-CEGlbWu5.mjs.map +1 -0
  6. package/dist/{attach-BnP9_Uca.d.mts → attach-DPgyv78F.d.mts} +87 -8
  7. package/dist/attach-DPgyv78F.d.mts.map +1 -0
  8. package/dist/{condition-Bl1UgEpM.mjs → condition-dNSbUHzE.mjs} +102 -10
  9. package/dist/condition-dNSbUHzE.mjs.map +1 -0
  10. package/dist/drizzle.d.mts +6 -4
  11. package/dist/drizzle.d.mts.map +1 -1
  12. package/dist/drizzle.mjs +18 -8
  13. package/dist/drizzle.mjs.map +1 -1
  14. package/dist/index.d.mts +1 -1
  15. package/dist/index.mjs +34 -17
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/may-DprCmMgK.mjs +200 -0
  18. package/dist/may-DprCmMgK.mjs.map +1 -0
  19. package/dist/{me-BYpuVqJE.mjs → me-C-gX1paZ.mjs} +3 -3
  20. package/dist/{me-BYpuVqJE.mjs.map → me-C-gX1paZ.mjs.map} +1 -1
  21. package/dist/media.d.mts +1 -1
  22. package/dist/{placed-BvdNmZJu.mjs → placed-CGyo-NRR.mjs} +2 -2
  23. package/dist/{placed-BvdNmZJu.mjs.map → placed-CGyo-NRR.mjs.map} +1 -1
  24. package/dist/server.d.mts +50 -17
  25. package/dist/server.d.mts.map +1 -1
  26. package/dist/server.mjs +326 -155
  27. package/dist/server.mjs.map +1 -1
  28. package/dist/sync.d.mts +5 -3
  29. package/dist/sync.d.mts.map +1 -1
  30. package/dist/sync.mjs +18 -8
  31. package/dist/sync.mjs.map +1 -1
  32. package/package.json +18 -17
  33. package/dist/attach-BnP9_Uca.d.mts.map +0 -1
  34. package/dist/attach-CRCF5XHS.mjs.map +0 -1
  35. package/dist/condition-Bl1UgEpM.mjs.map +0 -1
  36. package/dist/may-DzCAt_5M.mjs +0 -75
  37. package/dist/may-DzCAt_5M.mjs.map +0 -1
package/dist/server.d.mts CHANGED
@@ -1,8 +1,29 @@
1
- import { S as Policy, k as MeEntity, l as InteractionKey } from "./attach-BnP9_Uca.mjs";
1
+ import { S as Policy, k as MeEntity, l as InteractionKey } from "./attach-DPgyv78F.mjs";
2
2
  import { Effect, Option } from "effect";
3
3
  import { AnyEntity, AnyQuery } from "foldkit-entity";
4
+ import { Diagnostic, MutationDescriptor, RemoteForbidden, ReportDiagnostic } from "foldkit-remote";
4
5
  import { EntitySource, EntityWriter, MemoryReadable, MutationOutcome, MutationRefused, MutationSource, ReadPlan, RemoteServerError, ServerDefinition } from "foldkit-remote-server";
5
- import { MutationDescriptor, RemoteForbidden } from "foldkit-remote";
6
+ /**
7
+ * An operator refused to work out a value a guarded write computes (text
8
+ * holding NUL, an implementation that throws). The write was refused with a
9
+ * fixed message, since the operator's own may say anything.
10
+ */
11
+ interface ComputeRefused extends Diagnostic {
12
+ readonly _tag: 'ComputeRefused';
13
+ readonly entity: string;
14
+ /** The operator's own refusal. */
15
+ readonly error: Error;
16
+ }
17
+ /**
18
+ * Writes through a `GuardServer.writer` given no revision, where a change can
19
+ * come between the check and the write, which is then not seen.
20
+ */
21
+ interface UnpinnedWrites extends Diagnostic {
22
+ readonly _tag: 'UnpinnedWrites';
23
+ readonly mutations: ReadonlyArray<string>;
24
+ }
25
+ /** Every diagnostic `foldkit-guard` reports. */
26
+ type GuardDiagnostic = ComputeRefused | UnpinnedWrites;
6
27
  export declare const GuardServer: {
7
28
  /**
8
29
  * `Guards.me`'s Source: the one row, `me`, as the asker is, with `may`
@@ -41,19 +62,25 @@ export declare const GuardServer: {
41
62
  * `RemoteServer.write`. An update or a delete reads the row first under
42
63
  * the writer's own `read` (its Source's read rule): a row the writer may not
43
64
  * see is refused as one that is not there, and a delete of it changes
44
- * nothing. Then the row's rule for the command must hold over the row (an
45
- * update's over the row as it would be after it too, so a write cannot move
46
- * a row out of its writer's reach), each member it sets must allow setting
47
- * it, and each relation it points elsewhere must allow the unlink and the
48
- * link. A create's rules hold over the values it proposes, where a field the
65
+ * nothing. Then the row's rule for the command must hold over the row, each
66
+ * member it sets must allow setting it, and each relation it points
67
+ * elsewhere must allow the unlink and the link. An update's row rule holds
68
+ * over the row as it would be after it too, so a write cannot move a row out
69
+ * of its writer's reach. Each of its member and `Link` rules holds over the
70
+ * row after with that one change undone (that member's value, or where that
71
+ * relation pointed, as before): the change must be allowed given everything
72
+ * else the write does, so one write cannot set together what each change
73
+ * alone would be refused, while a rule reading its own member ("only while
74
+ * a draft") still allows the change. An increment or a computed assignment
75
+ * to a member is that member's own change. An `Unlink` rule holds over the
76
+ * row before alone. A create's rules hold over the values it proposes, where a field the
49
77
  * create leaves unset matches no guard, not even one for an empty value. A refusal is
50
78
  * `Forbidden`, with the sentence an `explain` gave; the write never runs.
51
79
  *
52
- * `presets` are fields a create takes from who is asking, never from the
53
- * client (`ownerId: user => user.id`): set before the rules are checked, so
54
- * a rule over them holds of the creator. A visitor has nothing to preset
55
- * from, and a create whose input sets a preset field is a mistake of the
56
- * server's, refused.
80
+ * What the Entity sets from the write's context (`Entity.sets`: who asks,
81
+ * when) reaches a create or an update already set by `RemoteServer.write`,
82
+ * so a rule over it holds of the creator. A member rule over such a member
83
+ * judges the server's value like any other: declare none there.
57
84
  *
58
85
  * `revision` names a field stored as a number, which the writer moves on by
59
86
  * one with each write it lands. An update or a delete then lands only on the
@@ -61,7 +88,8 @@ export declare const GuardServer: {
61
88
  * between the check and the write is never written over; it is decided
62
89
  * again against the row as it now is, up to three times. A change that does
63
90
  * not move the revision (a handler's, `applyEdits`', raw SQL) is not seen.
64
- * Without `revision`, none is, and `validate` warns. An input that expects a
91
+ * Without `revision`, none is, and `validate` warns of an update, or a delete
92
+ * of an Entity the server updates (an insert has no row). An input that expects a
65
93
  * revision the row read is not at is a `Conflict`, decided before any rule;
66
94
  * an input may expect only the field the writer pins.
67
95
  *
@@ -70,7 +98,6 @@ export declare const GuardServer: {
70
98
  * ```
71
99
  */
72
100
  writer: <E extends AnyEntity, User, R, RW>(entity: E, policy: Policy<User, R>, writer: EntityWriter<Option.Option<User>, RW>, options?: {
73
- readonly presets?: { readonly [K in keyof E['fields']]?: (user: User) => E['fields'][K]['schema']['Type']; };
74
101
  readonly revision?: keyof E['fields'] & string;
75
102
  }) => EntityWriter<Option.Option<User>, R | RW>;
76
103
  /**
@@ -120,11 +147,14 @@ export declare const GuardServer: {
120
147
  * `GuardServer.memory`), its Source applies its members' and relations'
121
148
  * (`GuardServer.filter`), and each declared write of it lands through
122
149
  * `GuardServer.writer`, all built from `policy`; and that no query's body
123
- * filters or orders by a member with a Read rule, which would answer for the
124
- * value it hides. A hand-written Source over a guarded Entity would serve
150
+ * filters or orders by a member with a Read rule, its own or one of a row it
151
+ * reaches through a path or an exists, which would answer for the value it
152
+ * hides. A hand-written Source over a guarded Entity would serve
125
153
  * every row, and a bare writer would take every write; this throws instead,
126
154
  * naming each. A handler (`RemoteServer.mutation`) writes what its code
127
- * writes, which no check at startup can read.
155
+ * writes, which no check at startup can read. A write a change can come
156
+ * between, through a writer given no revision, is not refused but reported:
157
+ * `UnpinnedWrites`, a warning, to `diagnostics`.
128
158
  *
129
159
  * ```ts
130
160
  * GuardServer.validate(Policy, { entities: [Todo, Project], domain: Data, server: Server })
@@ -142,6 +172,9 @@ export declare const GuardServer: {
142
172
  };
143
173
  };
144
174
  readonly server: ServerDefinition<any, any>;
175
+ /** Where the `UnpinnedWrites` warning goes; `Diagnostics.Reporter`'s default, the log, when not given. */
176
+ readonly diagnostics?: ReportDiagnostic | undefined;
145
177
  }) => void;
146
178
  };
179
+ export type { ComputeRefused, GuardDiagnostic, UnpinnedWrites };
147
180
  //# sourceMappingURL=server.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server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