foldkit-guard 0.10.0 → 0.12.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 (36) hide show
  1. package/README.md +157 -85
  2. package/dist/agent.d.mts +9 -6
  3. package/dist/agent.d.mts.map +1 -1
  4. package/dist/agent.mjs +21 -13
  5. package/dist/agent.mjs.map +1 -1
  6. package/dist/{attach-CJl-GtbN.d.mts → attach-CER19mzk.d.mts} +46 -9
  7. package/dist/attach-CER19mzk.d.mts.map +1 -0
  8. package/dist/{attach-CEGlbWu5.mjs → attach-DlrBpxOl.mjs} +33 -3
  9. package/dist/attach-DlrBpxOl.mjs.map +1 -0
  10. package/dist/{condition-dNSbUHzE.mjs → condition-VNIr9gDe.mjs} +2 -4
  11. package/dist/condition-VNIr9gDe.mjs.map +1 -0
  12. package/dist/drizzle.d.mts +1 -1
  13. package/dist/drizzle.mjs +7 -4
  14. package/dist/drizzle.mjs.map +1 -1
  15. package/dist/index.d.mts +1 -1
  16. package/dist/index.mjs +4 -4
  17. package/dist/{may-DprCmMgK.mjs → may-Bd6O91A-.mjs} +62 -20
  18. package/dist/may-Bd6O91A-.mjs.map +1 -0
  19. package/dist/{me-C-gX1paZ.mjs → me-Bv7I0EcH.mjs} +3 -3
  20. package/dist/{me-C-gX1paZ.mjs.map → me-Bv7I0EcH.mjs.map} +1 -1
  21. package/dist/media.d.mts +1 -1
  22. package/dist/{placed-CGyo-NRR.mjs → placed-Dt05PaWi.mjs} +2 -2
  23. package/dist/{placed-CGyo-NRR.mjs.map → placed-Dt05PaWi.mjs.map} +1 -1
  24. package/dist/server.d.mts +9 -2
  25. package/dist/server.d.mts.map +1 -1
  26. package/dist/server.mjs +96 -73
  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 +10 -6
  31. package/dist/sync.mjs.map +1 -1
  32. package/package.json +16 -16
  33. package/dist/attach-CEGlbWu5.mjs.map +0 -1
  34. package/dist/attach-CJl-GtbN.d.mts.map +0 -1
  35. package/dist/condition-dNSbUHzE.mjs.map +0 -1
  36. package/dist/may-DprCmMgK.mjs.map +0 -1
package/dist/server.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as Policy, k as MeEntity, l as InteractionKey } from "./attach-CJl-GtbN.mjs";
1
+ import { S as Policy, k as MeEntity, l as InteractionKey } from "./attach-CER19mzk.mjs";
2
2
  import { Effect, Option } from "effect";
3
3
  import { AnyEntity, AnyQuery } from "foldkit-entity";
4
4
  import { Diagnostic, MutationDescriptor, RemoteForbidden, ReportDiagnostic } from "foldkit-remote";
@@ -49,7 +49,9 @@ export declare const GuardServer: {
49
49
  * `RemoteServer.memory`'s `readable` and `filter` for `entities`, the
50
50
  * Entities as `Guards.attach` returned them. A row's Read is decided per
51
51
  * stored row, an inherited Read by looking the related row up; an Entity
52
- * not listed is read by everyone.
52
+ * not listed is read by everyone. A Read rule that reads another row (a
53
+ * path, an exists) is refused here: each stored row is judged alone, and
54
+ * only a statement judges such a rule (`GuardDrizzle.visible`).
53
55
  */
54
56
  memory: <User>(policy: Policy<User>, entities: ReadonlyArray<AnyEntity>) => {
55
57
  readable: (principal: Option.Option<User>, row: (entity: string, id: string) => Option.Option<Readonly<Record<string, unknown>>>) => Effect.Effect<MemoryReadable>;
@@ -129,6 +131,11 @@ export declare const GuardServer: {
129
131
  * answer shows its writer only what they may see, a row it hid from them
130
132
  * as deleted.
131
133
  *
134
+ * A rule for `interaction` that reads another row (a path, an exists) is
135
+ * refused here, where the handler is made: this check reads one row and
136
+ * runs no statement. A declared write through `GuardServer.writer` is held
137
+ * to such a rule.
138
+ *
132
139
  * ```ts
133
140
  * GuardServer.mutation(ArchiveTodo, {
134
141
  * entity: Todo, policy: Policy, interaction: Archive.key,
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.mts","names":[],"sources":["../src/diagnostics.ts","../src/server.ts"],"mappings":";;;;;;;;;;UAciB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aAE/C,QAAQ;aACR,QAAQ,OAAO,MAAM;aACrB,8CAA8C;;;;;;aAM9C,OAAO,OAAO,mBAAmB,OAAO;;aAExC,QAAQ,aAAa,OAAO,OAAO,OAAO;;aAE1C,SAAS;KACnB,MACK;aACK,OAAO;aACP,WAAW,OAAO,OAAO;aACzB;aACA,KAAK,OAAO,OAAO,SAAS;QACjC,OAAO,OACX,gBAAgB,SAChB,oBAAoB,kBAAkB,iBACtC,QAED,eAAe,OAAO,OAAO,OAAO,IAAI,KAAK;;;;;;;;;;;;;;;;;;;;;EA2GhD,WAAW,MAAM,GAAC,QACR,OAAO,MAAM,IAAE;aAEZ,UAAU,cAAc;;aAExB;eACE;iBACE,SAAS;mBAEL;mBAA0B,OAAO;;;;aAIzC,QAAQ;;aAER,cAAc"}
package/dist/server.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { c as readRowsRuled, d as surfaceOf, i as attachedRules, l as readRuled, r as attached } from "./attach-CEGlbWu5.mjs";
2
- import { t as Condition } from "./condition-dNSbUHzE.mjs";
3
- import { a as mayRules, i as mayConditions, r as answerOf } from "./may-DprCmMgK.mjs";
4
- import "./me-C-gX1paZ.mjs";
5
- import { n as rowRules, r as writeRules, t as memberRules } from "./placed-CGyo-NRR.mjs";
1
+ import { d as readRowsRuled, f as readRuled, i as attachedRules, m as surfaceOf, o as enforced, u as reachingRules } from "./attach-DlrBpxOl.mjs";
2
+ import { t as Condition } from "./condition-VNIr9gDe.mjs";
3
+ import { a as mayRules, i as mayConditions, r as answerOf } from "./may-Bd6O91A-.mjs";
4
+ import "./me-Bv7I0EcH.mjs";
5
+ import { n as rowRules, r as writeRules, t as memberRules } from "./placed-Dt05PaWi.mjs";
6
6
  import { Effect, Match, Option, Schema, SchemaAST, identity } from "effect";
7
7
  import { Entity, Expr, Query, QueryEvaluateError, Write, dependenciesOf, supported } from "foldkit-entity";
8
8
  import { Diagnostics, RemoteForbidden } from "foldkit-remote";
@@ -101,7 +101,7 @@ const GuardServer = {
101
101
  * ```
102
102
  */
103
103
  me: (entity, policy) => {
104
- Option.map(attached(entity), ({ set }) => {
104
+ Option.map(enforced(entity), ({ set }) => {
105
105
  if (set !== policy.set) throw new Error(`[foldkit-guard] GuardServer.me: Me carries the guards of ${set}, not ${policy.set}`);
106
106
  });
107
107
  return {
@@ -130,59 +130,64 @@ const GuardServer = {
130
130
  * RemoteServer.entity(Todo, { read, filter: GuardServer.filter(Todo, Policy) })
131
131
  * ```
132
132
  */
133
- filter: (entity, policy) => memberRules.add((principal, fields) => Effect.map(Effect.all([policy.readMembers(entity, principal, fields), asksMay(entity, fields) ? Effect.map(mayOf(entity, policy, principal), Option.some) : Effect.succeed(Option.none())]), ([members, may]) => {
134
- if (members.length === 0 && Option.isNone(may)) return {
135
- fields,
136
- apply: noMembers
137
- };
138
- const input = policy.inputOf(principal);
139
- const decided = members.map((member) => ({
140
- ...member,
141
- redacted: Match.valueTags(member.deny, {
142
- Redact: (deny) => Option.some(Schema.encodeSync(entity.members[member.member].schema)(deny.value)),
143
- NotFound: () => Option.none(),
144
- Omit: () => Option.none(),
145
- Forbidden: () => Option.none(),
146
- Explain: () => Option.none()
147
- })
148
- }));
149
- return {
150
- fields: [.../* @__PURE__ */ new Set([
151
- ...fields,
152
- ...members.flatMap(({ condition }) => Condition.members(condition)),
153
- ...Option.match(may, {
154
- onNone: () => [],
155
- onSome: ({ fields }) => fields
133
+ filter: (entity, policy) => {
134
+ enforced(entity);
135
+ return memberRules.add((principal, fields) => Effect.map(Effect.all([policy.readMembers(entity, principal, fields), asksMay(entity, fields) ? Effect.map(mayOf(entity, policy, principal), Option.some) : Effect.succeed(Option.none())]), ([members, may]) => {
136
+ if (members.length === 0 && Option.isNone(may)) return {
137
+ fields,
138
+ apply: noMembers
139
+ };
140
+ const input = policy.inputOf(principal);
141
+ const decided = members.map((member) => ({
142
+ ...member,
143
+ redacted: Match.valueTags(member.deny, {
144
+ Redact: (deny) => Option.some(Schema.encodeSync(entity.members[member.member].schema)(deny.value)),
145
+ NotFound: () => Option.none(),
146
+ Omit: () => Option.none(),
147
+ Forbidden: () => Option.none(),
148
+ Explain: () => Option.none()
156
149
  })
157
- ])],
158
- apply: (record) => {
159
- const values = { ...record.values };
160
- for (const { member, condition, redacted } of decided) {
161
- if (Condition.holds(condition, record.values, input, () => false, policy.operators)) continue;
162
- Option.match(redacted, {
163
- onNone: () => {
164
- delete values[member];
165
- },
166
- onSome: (value) => {
167
- values[member] = value;
168
- }
150
+ }));
151
+ return {
152
+ fields: [.../* @__PURE__ */ new Set([
153
+ ...fields,
154
+ ...members.flatMap(({ condition }) => Condition.members(condition)),
155
+ ...Option.match(may, {
156
+ onNone: () => [],
157
+ onSome: ({ fields }) => fields
158
+ })
159
+ ])],
160
+ apply: (record) => {
161
+ const values = { ...record.values };
162
+ for (const { member, condition, redacted } of decided) {
163
+ if (Condition.holds(condition, record.values, input, () => false, policy.operators)) continue;
164
+ Option.match(redacted, {
165
+ onNone: () => {
166
+ delete values[member];
167
+ },
168
+ onSome: (value) => {
169
+ values[member] = value;
170
+ }
171
+ });
172
+ }
173
+ Option.map(may, ({ answer }) => {
174
+ values.may = answer(record.values);
169
175
  });
176
+ return {
177
+ ...record,
178
+ values
179
+ };
170
180
  }
171
- Option.map(may, ({ answer }) => {
172
- values.may = answer(record.values);
173
- });
174
- return {
175
- id: record.id,
176
- values
177
- };
178
- }
179
- };
180
- }), policy, [entity]),
181
+ };
182
+ }), policy, [entity]);
183
+ },
181
184
  /**
182
185
  * `RemoteServer.memory`'s `readable` and `filter` for `entities`, the
183
186
  * Entities as `Guards.attach` returned them. A row's Read is decided per
184
187
  * stored row, an inherited Read by looking the related row up; an Entity
185
- * not listed is read by everyone.
188
+ * not listed is read by everyone. A Read rule that reads another row (a
189
+ * path, an exists) is refused here: each stored row is judged alone, and
190
+ * only a statement judges such a rule (`GuardDrizzle.visible`).
186
191
  */
187
192
  memory: (policy, entities) => ({
188
193
  readable: rowRules.add((principal, row) => Effect.map(Effect.forEach(entities, (entity) => Effect.map(policy.readable(entity, principal), (condition) => [entity.name, condition])), (decided) => {
@@ -204,7 +209,7 @@ const GuardServer = {
204
209
  }), policy.operators);
205
210
  };
206
211
  return (entity, values) => holds(entity, values, /* @__PURE__ */ new Set());
207
- }), policy, entities),
212
+ }), policy, readingOneRow(entities)),
208
213
  filter: Object.fromEntries(entities.map((entity) => [entity.name, GuardServer.filter(entity, policy)]))
209
214
  }),
210
215
  /**
@@ -268,18 +273,12 @@ const GuardServer = {
268
273
  if (writer.entity !== entity.name) throw new Error(`[foldkit-guard] GuardServer.writer: ${entity.name}'s rules over a writer for ${writer.entity}`);
269
274
  const read = writer.read;
270
275
  if (read === void 0) throw new Error(`[foldkit-guard] GuardServer.writer: ${entity.name}'s writer reads no row as its writer may see it; bind it with a visible rule (GuardDrizzle.visible)`);
271
- const reaching = Option.match(attached(entity), {
276
+ const reaching = Option.match(enforced(entity), {
272
277
  onNone: () => [],
273
- onSome: ({ row }) => ["Update", "Delete"].flatMap((interaction) => (row[interaction]?.rules ?? []).flatMap(function names(rule) {
274
- return Match.valueTags(rule, {
275
- PrincipalGuard: () => [],
276
- RowGuard: (guard) => Query.dependencies(guard.query).reaches.length > 0 ? [guard.name] : [],
277
- All: ({ rules }) => rules.flatMap(names),
278
- Inherit: () => []
279
- });
280
- }))
278
+ onSome: (attachment) => [.../* @__PURE__ */ new Set([...reachingRules(attachment, "Update"), ...reachingRules(attachment, "Delete")])]
281
279
  });
282
280
  if (reaching.length > 0 && writer.requires !== true) throw new Error(`[foldkit-guard] GuardServer.writer: ${entity.name}'s ${reaching.join(", ")} reads another row, which only a writer judging rules in its statement can hold it to (foldkit-remote-drizzle's writer); this writer does not`);
281
+ (options.children ?? []).forEach(enforced);
283
282
  const judging = cascadeJudges(entity, options.children ?? []);
284
283
  if (judging.length > 0 && (writer.requires !== true || writer.cascades !== true)) throw new Error(`[foldkit-guard] GuardServer.writer: a delete of ${entity.name} takes ${judging.map((child) => child.name).join(", ")} rows under their own Delete rule, which only a writer judging rules in its statement and removing what cascades can hold it to (foldkit-remote-drizzle's writer); this writer does not`);
285
284
  const clearJudging = clearJudges(entity, options.children ?? []);
@@ -363,13 +362,11 @@ const GuardServer = {
363
362
  const loop = (left) => Effect.flatMap(attempt(), (outcome) => !missed(outcome) ? Effect.succeed(outcome) : left > 1 ? loop(left - 1) : Effect.fail(new RemoteServerError({ message: `${entity.name} ${id} changed while it was written` })));
364
363
  return loop(3);
365
364
  };
366
- const attachment = attached(entity);
365
+ const attachment = enforced(entity);
367
366
  const hiddenByBody = /* @__PURE__ */ new WeakMap();
368
- const unnamed = new Set(Option.match(attachment, {
369
- onNone: () => [],
370
- onSome: (ruled) => Entity.invariants(entity).filter((held) => [...held.before, ...held.after].some((key) => readRuled(ruled, key))).map((held) => held.id)
371
- }));
372
- const told = (error) => error instanceof RemoteInvalid && Option.exists(error.rule, (rule) => unnamed.has(rule)) ? RemoteServer.invalid("The row would be invalid") : error;
367
+ const readsRuled = (held) => Option.exists(attachment, (ruled) => [...held.before, ...held.after].some((key) => readRuled(ruled, key)));
368
+ const unnamed = new Set(Entity.invariants(entity).filter(readsRuled).map((held) => held.id));
369
+ const told = (ensures) => (error) => error instanceof RemoteInvalid && Option.exists(error.rule, (rule) => unnamed.has(rule) || ensures !== void 0 && rule === ensures.id && readsRuled(ensures)) ? RemoteServer.invalid("The row would be invalid") : error;
373
370
  /**
374
371
  * Fails a write whose `when` reads, whose `expect` names, or whose
375
372
  * computed assignment reads, a member with a Read rule: Unmet or written,
@@ -539,6 +536,7 @@ const GuardServer = {
539
536
  ...revision === void 0 ? {} : { pins: true },
540
537
  ...writer.ledger === true ? { ledger: true } : {},
541
538
  ...writer.invariants === true ? { invariants: true } : {},
539
+ ...writer.postconditions === true ? { postconditions: true } : {},
542
540
  ...writer.cascades === true ? { cascades: true } : {},
543
541
  ...writer.restricts === true ? { restricts: true } : {},
544
542
  ...writer.clears === true ? { clears: true } : {},
@@ -570,7 +568,7 @@ const GuardServer = {
570
568
  onSome: (held) => ({ requires: held })
571
569
  })
572
570
  });
573
- })))), told),
571
+ })))), told(context.ensures)),
574
572
  insert: (context) => answeredOr(context, identity, () => Effect.gen(function* () {
575
573
  const { principal, values, links } = context;
576
574
  const row = yield* policy.writable(entity, principal, "Create");
@@ -592,7 +590,7 @@ const GuardServer = {
592
590
  ...rule,
593
591
  condition: Condition.unsetting(rule.condition, unset)
594
592
  })), proposed, principal);
595
- return yield* Effect.mapError(writer.insert(context), told);
593
+ return yield* Effect.mapError(writer.insert(context), told(context.ensures));
596
594
  })),
597
595
  delete: (context) => Effect.andThen(discloses(context.expect, context.when), () => pinned(context.id, context.expect, DeleteOutcome.$is("Moved"), () => Effect.gen(function* () {
598
596
  const row = yield* policy.writable(entity, context.principal, "Delete");
@@ -652,6 +650,11 @@ const GuardServer = {
652
650
  * answer shows its writer only what they may see, a row it hid from them
653
651
  * as deleted.
654
652
  *
653
+ * A rule for `interaction` that reads another row (a path, an exists) is
654
+ * refused here, where the handler is made: this check reads one row and
655
+ * runs no statement. A declared write through `GuardServer.writer` is held
656
+ * to such a rule.
657
+ *
655
658
  * ```ts
656
659
  * GuardServer.mutation(ArchiveTodo, {
657
660
  * entity: Todo, policy: Policy, interaction: Archive.key,
@@ -661,6 +664,11 @@ const GuardServer = {
661
664
  */
662
665
  mutation: (mutation, guard, run) => {
663
666
  const { entity, policy, interaction, id, source } = guard;
667
+ const reaching = Option.match(enforced(entity), {
668
+ onNone: () => [],
669
+ onSome: (attachment) => reachingRules(attachment, interaction)
670
+ });
671
+ if (reaching.length > 0) throw new Error(`[foldkit-guard] GuardServer.mutation: ${mutation.name} is checked against ${entity.name}'s ${interaction} rule, whose ${reaching.join(", ")} reads another row (a path or an exists), which a handler's check over the one row it reads cannot judge; declare the write (Mutation.write) and land it through GuardServer.writer over a writer that judges rules in its statement (foldkit-remote-drizzle's writer), or check ${interaction} by a rule over the row alone`);
664
672
  if (!rowRules.has(source.visible, policy, entity)) throw new Error(`[foldkit-guard] GuardServer.mutation: ${mutation.name}'s Source does not apply ${entity.name}'s Read rules`);
665
673
  /**
666
674
  * The answer as its writer may now see it: each row of `entity` it carries
@@ -730,11 +738,11 @@ const GuardServer = {
730
738
  validate: (policy, config) => {
731
739
  const byName = new Map(config.entities.map((entity) => [entity.name, entity]));
732
740
  /** Whether a reached member has a Read rule; one of an Entity not validated has none checked. */
733
- const hidesFromReach = ({ entity, key }) => Option.exists(Option.flatMap(Option.fromUndefinedOr(byName.get(entity)), attached), (attachment) => readRuled(attachment, key));
741
+ const hidesFromReach = ({ entity, key }) => Option.exists(Option.flatMap(Option.fromUndefinedOr(byName.get(entity)), enforced), (attachment) => readRuled(attachment, key));
734
742
  /** Whether who may read the rows of `entity` depends on who is asking. */
735
- const rowsRuled = (entity) => Option.exists(Option.flatMap(Option.fromUndefinedOr(entity), attached), (attachment) => readRowsRuled(attachment));
743
+ const rowsRuled = (entity) => Option.exists(Option.flatMap(Option.fromUndefinedOr(entity), enforced), (attachment) => readRowsRuled(attachment));
736
744
  const undeclared = [...config.server.queries.keys()].filter((query) => !config.domain.registry.queries.has(query)).map((query) => `query ${query} is served, but the domain does not declare it`);
737
- const entityProblems = config.entities.flatMap((entity) => Option.match(attached(entity), {
745
+ const entityProblems = config.entities.flatMap((entity) => Option.match(enforced(entity), {
738
746
  onNone: () => [],
739
747
  onSome: (attachment) => {
740
748
  const name = entity.name;
@@ -837,6 +845,21 @@ const GuardServer = {
837
845
  }
838
846
  }
839
847
  };
848
+ /**
849
+ * `entities`, refused where one's Read rule reads another row: a memory
850
+ * server's `readable` judges each stored row alone and runs no statement, so
851
+ * such a rule would fail every read of the Entity.
852
+ */
853
+ const readingOneRow = (entities) => {
854
+ for (const entity of entities) {
855
+ const reaching = Option.match(enforced(entity), {
856
+ onNone: () => [],
857
+ onSome: (attachment) => reachingRules(attachment, "Read")
858
+ });
859
+ if (reaching.length > 0) throw new Error(`[foldkit-guard] GuardServer.memory: ${entity.name}'s Read rule's ${reaching.join(", ")} reads another row (a path or an exists), which a memory server, judging each stored row alone, cannot judge; serve ${entity.name} from a table whose statement judges it (GuardDrizzle.visible), or rule Read over the row alone`);
860
+ }
861
+ return entities;
862
+ };
840
863
  /** Whether a read asks for `may`, of an Entity that has it (`Guards.may`). */
841
864
  const asksMay = (entity, fields) => fields.includes("may") && Object.hasOwn(entity.derived, "may");
842
865
  /**