@mulmoclaude/core 3.12.0 → 3.13.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.
@@ -5,6 +5,7 @@ const require_relPath = require("./relPath-CTAjGdCL.cjs");
5
5
  const require_itemId = require("./itemId-Dzrr3vs5.cjs");
6
6
  const require_promptSafety = require("./promptSafety-CWqYq-NS.cjs");
7
7
  const require_discovery = require("./discovery-BsXiDZBR.cjs");
8
+ const require_templatePath = require("./templatePath-27vUZowm.cjs");
8
9
  const require_feeds_paths = require("./feeds/paths.cjs");
9
10
  const require_skill_bridge_index = require("./skill-bridge/index.cjs");
10
11
  let node_path = require("node:path");
@@ -85,6 +86,14 @@ var CollectionConfigZ = zod.z.object({
85
86
  * declaration with the role and no field is refused (`assigneeProblems`),
86
87
  * because that member would silently hold nothing. */
87
88
  assigneeField: zod.z.string().trim().min(1).optional(),
89
+ /** This collection is the public projection of `mirrorOf` — the other
90
+ * half of `public.submit[...].mirror`, declared here because the rules
91
+ * read it when the PROJECTION is written rather than when the record is.
92
+ *
93
+ * What it buys: `state` may be written by anybody, and only to the value
94
+ * the authority actually says, so a visitor who was refused a slot can
95
+ * repair the stale row that offered it to them. */
96
+ mirrorOf: NameZ.optional(),
88
97
  peerVisibility: zod.z.enum(["public", "hidden"]).optional(),
89
98
  revealGated: zod.z.boolean().optional(),
90
99
  gatedFrom: NameZ.optional(),
@@ -125,10 +134,38 @@ var WindowRefZ = zod.z.object({
125
134
  collection: NameZ,
126
135
  field: zod.z.string().trim().min(1)
127
136
  }).strict();
137
+ /** The closing bound's per-record twin, and it ships WITH `fromField` rather
138
+ * than as a symmetric extra: a booking desk that opens per slot and never
139
+ * closes is not a booking desk. Same shape, opposite comparison — and
140
+ * EXCLUSIVE where `fromField` is inclusive, so one slot's closing instant and
141
+ * the next one's opening instant may be the same number. */
128
142
  var WindowZ = zod.z.object({
129
143
  from: zod.z.iso.datetime().optional(),
130
144
  until: zod.z.iso.datetime().optional(),
131
- fromField: WindowRefZ.optional()
145
+ fromField: WindowRefZ.optional(),
146
+ untilField: WindowRefZ.optional()
147
+ }).strict();
148
+ /** Which record a `field` document id must name, and what state it must be in.
149
+ *
150
+ * `idFrom: "field"` alone only stops the same string being written twice —
151
+ * nothing stops a client bypassing the page and inventing a slot, so the
152
+ * rules check the referenced record themselves. `exists()` is a FLOOR: a
153
+ * cancelled slot and a slot nobody may book any more exist too, which is what
154
+ * `where` is for.
155
+ *
156
+ * Always the object form, never a bare collection name. Two shapes for one
157
+ * key is the kind of thing a generator gets right once and wrong afterwards,
158
+ * and the rules read `s.idIn.collection` either way. */
159
+ var IdInZ = zod.z.object({
160
+ collection: NameZ,
161
+ where: zod.z.object({
162
+ field: zod.z.string().trim().min(1),
163
+ equals: zod.z.union([
164
+ zod.z.string(),
165
+ zod.z.number(),
166
+ zod.z.boolean()
167
+ ])
168
+ }).strict().optional()
132
169
  }).strict();
133
170
  var ValidateZ = zod.z.object({
134
171
  required: zod.z.array(zod.z.string().trim().min(1)).optional(),
@@ -153,12 +190,31 @@ var SubmitZ = zod.z.object({
153
190
  emailField: zod.z.string().trim().min(1).optional(),
154
191
  createFields: zod.z.array(zod.z.string().trim().min(1)).min(1),
155
192
  initialStatus: zod.z.string().trim().min(1).optional(),
193
+ /** `field` is the mode that makes a CONTESTED resource exclusive: the
194
+ * booking's document id IS the slot's id, so the second person to want
195
+ * that slot is writing a document that already exists — an update, which
196
+ * the public submission path never allows. Firestore decides that
197
+ * atomically, so unlike a countable capacity (see `stampField`) this is
198
+ * first-come ENFORCED rather than first-come read off a rank. */
156
199
  idFrom: zod.z.enum([
157
200
  "auto",
158
201
  "auth.uid",
159
- "auth.uid+field"
202
+ "auth.uid+field",
203
+ "field"
160
204
  ]).optional(),
161
205
  idField: zod.z.string().trim().min(1).optional(),
206
+ /** Required by `idFrom: "field"` — see {@link IdInZ}. */
207
+ idIn: IdInZ.optional(),
208
+ /** The collection holding this record's PUBLIC PROJECTION, one row per
209
+ * contested thing, sharing its document id.
210
+ *
211
+ * A booking carries a name, an address and a phone number, and Firestore
212
+ * rules cannot hide a field, so the public page must not read bookings at
213
+ * all. It reads the projection instead, whose `state` is a copy of "does
214
+ * a booking with this id exist" — and the rules accept the two writes
215
+ * only as one batch, in both directions, so the copy cannot drift into
216
+ * advertising a slot that is gone. */
217
+ mirror: NameZ.optional(),
162
218
  validate: ValidateZ.optional(),
163
219
  window: WindowZ.optional(),
164
220
  /** A field the rules PIN to the server clock on create: the record must
@@ -190,6 +246,24 @@ var PublicZ = zod.z.object({
190
246
  * well as its own declaration. */
191
247
  enabled: zod.z.boolean().optional(),
192
248
  read: zod.z.array(NameZ).optional(),
249
+ /** The page the public sees, instead of the generated form.
250
+ *
251
+ * A form is enough to ANSWER something and not enough to CHOOSE from
252
+ * what is available — a stylist-by-hour grid is not the far end of a
253
+ * table. So the app may name one HTML file, which the host publishes to
254
+ * `config/view` and the public page renders in a sandboxed iframe.
255
+ *
256
+ * `submit` stays declared alongside: the view sends an INTENT, and the
257
+ * page it is embedded in performs the write against these rules.
258
+ *
259
+ * `collections` is declared rather than inferred from `read`. Inferring
260
+ * it produces the worst failure this feature has — the view renders, the
261
+ * data it wanted was never sent, and it draws an empty grid with no error
262
+ * anywhere. */
263
+ view: zod.z.object({
264
+ path: zod.z.string().trim().min(1),
265
+ collections: zod.z.array(NameZ).min(1)
266
+ }).strict().optional(),
193
267
  submit: zod.z.record(NameZ, SubmitZ).optional()
194
268
  }).strict();
195
269
  /** The URL name an app is handed out under: `https://<host>/{slug}`.
@@ -296,7 +370,8 @@ function windowMillis(window) {
296
370
  if (Object.values(out).some((value) => !Number.isFinite(value))) throw new Error(`publish: window bound is not a parseable timestamp (${JSON.stringify(window)})`);
297
371
  const projected = {
298
372
  ...out,
299
- ...window.fromField === void 0 ? {} : { fromField: window.fromField }
373
+ ...window.fromField === void 0 ? {} : { fromField: window.fromField },
374
+ ...window.untilField === void 0 ? {} : { untilField: window.untilField }
300
375
  };
301
376
  return Object.keys(projected).length > 0 ? projected : void 0;
302
377
  }
@@ -372,6 +447,7 @@ function projectApp(authored, schemas, stamp, existing) {
372
447
  enabled: authored.public?.enabled === true,
373
448
  read: authored.public?.read ?? [],
374
449
  submit,
450
+ ...authored.public?.view === void 0 ? {} : { view: { collections: authored.public.view.collections } },
375
451
  publishedAt: stamp.publishedAt
376
452
  };
377
453
  if (authored.name !== void 0) config.name = authored.name;
@@ -669,7 +745,7 @@ function ruleReadFields(submit) {
669
745
  field: submit.emailField,
670
746
  why: `public.submit.<cid>.emailField — the rules compare it to the submitter's verified address`
671
747
  });
672
- if (submit.idFrom === "auth.uid+field" && submit.idField !== void 0) fields.push({
748
+ if ((submit.idFrom === "auth.uid+field" || submit.idFrom === "field") && submit.idField !== void 0) fields.push({
673
749
  field: submit.idField,
674
750
  why: `public.submit.<cid>.idField — the rules rebuild the document id from it`
675
751
  });
@@ -692,10 +768,58 @@ function submitCoherenceProblems(app, cid, submit) {
692
768
  const collection = app.collections?.[cid];
693
769
  const problems = [...statusCoherenceProblems(cid, submit, collection), ...createFieldProblems(cid, submit)];
694
770
  if (submit.idFrom === "auth.uid+field" && submit.idField === void 0) problems.push(`public.submit.${cid}.idFrom is "auth.uid+field" but no idField is declared: the rules rebuild the document id from that field and refuse every create.`);
771
+ problems.push(...fieldIdProblems(cid, submit));
695
772
  if ((submit.selfUpdate !== void 0 || submit.selfTransitions !== void 0) && !collection?.statusField) problems.push(`public.submit.${cid}.selfUpdate / selfTransitions are declared per CURRENT STATUS, but collections.${cid} declares no statusField: the rules read the current status first and refuse every self-edit without it.`);
696
773
  if (submit.audience === "participant" && Object.keys(app.members).length === 0) problems.push(`public.submit.${cid}.audience is "participant" but the roster is empty: the rules resolve the submitter's role from members, so every submission is refused.`);
697
774
  return problems;
698
775
  }
776
+ /** `idFrom: "field"` makes the document id a CLAIM ABOUT ANOTHER RECORD, and
777
+ * the claim is only worth what is checked.
778
+ *
779
+ * `idIn` is required rather than optional, and that is the whole point of
780
+ * refusing here: without it the id is any string a stranger likes, so the app
781
+ * quietly accepts bookings for slots that do not exist. Nothing downstream
782
+ * ever notices — the booking is real, its slot is not — which is exactly the
783
+ * kind of hole a gate is for and a rule cannot state.
784
+ *
785
+ * `idIn` without the mode is refused for the opposite reason: the rules read
786
+ * it only in that branch, so an author who wrote it believes a check is
787
+ * running that is not. */
788
+ function fieldIdProblems(cid, submit) {
789
+ const problems = [];
790
+ if (submit.idFrom === "field") {
791
+ if (submit.idField === void 0) problems.push(`public.submit.${cid}.idFrom is "field" but no idField is declared: the rules take the document id from that field and refuse every create.`);
792
+ if (submit.idIn === void 0) problems.push(`public.submit.${cid}.idFrom is "field" but no idIn is declared: the document id is then any string a submitter chooses, so the app accepts records pointing at things that do not exist. Name the collection the id must be found in — and, when only some of those records may be claimed, the state they must be in: "idIn": { "collection": "slots", "where": { "field": "state", "equals": "open" } }.`);
793
+ } else if (submit.idIn !== void 0) {
794
+ const mode = submit.idFrom === void 0 ? "absent" : JSON.stringify(submit.idFrom);
795
+ problems.push(`public.submit.${cid}.idIn is declared but idFrom is ${mode}: the rules read idIn only for idFrom "field", so as written nothing checks the referenced record and the declaration promises a check it does not perform.`);
796
+ }
797
+ return problems;
798
+ }
799
+ /** Every `idIn` target, checked against the collections this repository has.
800
+ *
801
+ * Separate from {@link fieldIdProblems} for the reason the file is split at
802
+ * all: that one reads the declaration alone, this one needs to know what
803
+ * exists. */
804
+ function idTargetProblems(app, collections) {
805
+ const known = new Set(collections.map((collection) => collection.cid));
806
+ const names = known.size > 0 ? [...known].sort().join(", ") : "(none)";
807
+ return Object.entries(app.public?.submit ?? {}).flatMap(([cid, submit]) => idInTargetProblems(cid, submit, known, names));
808
+ }
809
+ /** Where a `field` id says its record must be found.
810
+ *
811
+ * A typo passes every other check: the rules look the record up in a
812
+ * collection that does not exist, the lookup can never succeed, and every
813
+ * submission is refused with no explanation anywhere. A collection pointing
814
+ * at ITSELF is worse than a typo — on a create the document being written
815
+ * does not exist yet, so it is a declaration that can never accept anything. */
816
+ function idInTargetProblems(cid, submit, known, names) {
817
+ const target = submit.idIn?.collection;
818
+ if (target === void 0) return [];
819
+ if (target === cid) return [`public.submit.${cid}.idIn.collection names '${cid}' itself: a create writes a document that does not exist yet, so the record can never be found and every submission is refused. Name the collection of the thing being claimed (the slots, the seats, the assets).`];
820
+ if (!known.has(target)) return [`public.submit.${cid}.idIn.collection names '${target}', which is not a shared collection in this repository. The rules look the record up there, so nothing can ever be submitted. Shared collections here: ${names}.`];
821
+ return [];
822
+ }
699
823
  /** The staged reveal reads its flag off the PARENT record, so the path to that
700
824
  * parent is not optional decoration — without it the gate never opens. */
701
825
  function gateCoherenceProblems(cid, collection) {
@@ -746,7 +870,10 @@ function publishProblems(app, collections, publisherEmail) {
746
870
  ...primaryKeyProblems(app, collections),
747
871
  ...assigneeProblems(app),
748
872
  ...stampProblems(app),
749
- ...windowRefProblems(app, collections)
873
+ ...windowRefProblems(app, collections),
874
+ ...idTargetProblems(app, collections),
875
+ ...mirrorProblems(app, collections),
876
+ ...publicViewProblems(app, collections)
750
877
  ];
751
878
  }
752
879
  /** A public submission must NOT be allowed to name its own primary key.
@@ -827,14 +954,74 @@ function stampProblems(app) {
827
954
  * good. */
828
955
  function windowRefProblems(app, collections) {
829
956
  const known = new Set(collections.map((collection) => collection.cid));
830
- return Object.entries(app.public?.submit ?? {}).flatMap(([cid, submit]) => {
831
- const ref = submit.window?.fromField;
832
- if (ref === void 0) return [];
833
- const problems = [];
834
- if (!known.has(ref.collection)) problems.push(`public.submit.${cid}.window.fromField.collection names '${ref.collection}', which is not a shared collection in this repository. The rules read the opening time off a record there, so nothing can ever be submitted. Shared collections here: ${known.size > 0 ? [...known].sort().join(", ") : "(none)"}.`);
835
- if (!submit.createFields.includes(ref.ref)) problems.push(`public.submit.${cid}.window.fromField.ref names '${ref.ref}', which is not in createFields. The rules take the target record's id from that field ON THE SUBMISSION — if the submitter never writes it, there is nothing to look up and every submission is refused.`);
836
- return problems;
837
- });
957
+ return Object.entries(app.public?.submit ?? {}).flatMap(([cid, submit]) => [...windowBoundProblems(cid, submit, known, "fromField", submit.window?.fromField, "opening"), ...windowBoundProblems(cid, submit, known, "untilField", submit.window?.untilField, "closing")]);
958
+ }
959
+ /** Both bounds, checked identically. `untilField` arrived with the booking
960
+ * desk and reads exactly like its twin, so a check that knew only about
961
+ * `fromField` would let the closing half through unchecked — and a closing
962
+ * bound that names nothing does not leave the door ajar, it refuses every
963
+ * submission with no explanation. */
964
+ function windowBoundProblems(cid, submit, known, key, ref, which) {
965
+ if (ref === void 0) return [];
966
+ const problems = [];
967
+ if (!known.has(ref.collection)) problems.push(`public.submit.${cid}.window.${key}.collection names '${ref.collection}', which is not a shared collection in this repository. The rules read the ${which} time off a record there, so nothing can ever be submitted. Shared collections here: ${known.size > 0 ? [...known].sort().join(", ") : "(none)"}.`);
968
+ if (!submit.createFields.includes(ref.ref)) problems.push(`public.submit.${cid}.window.${key}.ref names '${ref.ref}', which is not in createFields. The rules take the target record's id from that field ON THE SUBMISSION — if the submitter never writes it, there is nothing to look up and every submission is refused.`);
969
+ return problems;
970
+ }
971
+ /** The two halves of a mirror, checked as the pair they only work as.
972
+ *
973
+ * `mirror` on the submission and `mirrorOf` on the projection are separate
974
+ * keys in separate places, and each is inert without the other: a booking
975
+ * whose slot declares no `mirrorOf` can never be created (the rules demand a
976
+ * paired write that the projection's own rule will refuse), and a projection
977
+ * whose authority declares no `mirror` drifts unbounded because nothing makes
978
+ * the two move together. Both failures are silent, and one of them —
979
+ * advertising a slot somebody already holds — is the exact thing the mirror
980
+ * exists to prevent.
981
+ *
982
+ * Also refuses a collection mirroring ITSELF, which reads as a typo and
983
+ * behaves as an unwritable collection: every create would have to prove its
984
+ * own document is simultaneously taken and open. */
985
+ function mirrorProblems(app, collections) {
986
+ const known = new Set(collections.map((collection) => collection.cid));
987
+ const names = known.size > 0 ? [...known].sort().join(", ") : "(none)";
988
+ return [...Object.entries(app.public?.submit ?? {}).flatMap(([cid, submit]) => mirrorClaimProblems(app, cid, submit, known, names)), ...Object.entries(app.collections ?? {}).flatMap(([cid, collection]) => mirrorOfProblems(app, cid, collection, known, names))];
989
+ }
990
+ /** The submission side: `public.submit[cid].mirror`. */
991
+ function mirrorClaimProblems(app, cid, submit, known, names) {
992
+ const { mirror } = submit;
993
+ if (mirror === void 0) return [];
994
+ if (mirror === cid) return [`public.submit.${cid}.mirror names its own collection: the projection is a SEPARATE record, and as written no create can satisfy the rules.`];
995
+ if (!known.has(mirror)) return [`public.submit.${cid}.mirror names '${mirror}', which is not a shared collection in this repository. The rules require the projection to move in the same write, so every submission is refused. Shared collections here: ${names}.`];
996
+ if (app.collections?.[mirror]?.mirrorOf !== cid) return [`public.submit.${cid}.mirror names '${mirror}', but collections.${mirror} does not declare mirrorOf: "${cid}". The two halves only work as a pair — the submission side demands the projection move with it, and the projection side is what allows that move — so as written every submission is refused.`];
997
+ return [];
998
+ }
999
+ /** The projection side: `collections[cid].mirrorOf`. */
1000
+ function mirrorOfProblems(app, cid, collection, known, names) {
1001
+ const authority = collection.mirrorOf;
1002
+ if (authority === void 0) return [];
1003
+ if (!known.has(authority)) return [`collections.${cid}.mirrorOf names '${authority}', which is not a shared collection in this repository. Nothing can then be true of it, so the projection's state may never be written. Shared collections here: ${names}.`];
1004
+ if (app.public?.submit?.[authority]?.mirror !== cid) return [`collections.${cid}.mirrorOf names '${authority}', but public.submit.${authority} does not declare mirror: "${cid}". Only the pair keeps the projection honest: without the other half a record can be created without moving this one, and the public page goes on offering something that is already taken.`];
1005
+ return [];
1006
+ }
1007
+ /** What the public view is handed. Declared, never inferred — a view whose
1008
+ * datasets were guessed from `public.read` renders perfectly and draws an
1009
+ * empty grid, with nothing in the page, the rules or the log to say why. */
1010
+ function publicViewProblems(app, collections) {
1011
+ const view = app.public?.view;
1012
+ if (view === void 0) return [];
1013
+ const known = new Set(collections.map((collection) => collection.cid));
1014
+ const readable = new Set(app.public?.read ?? []);
1015
+ const problems = [];
1016
+ if (!require_templatePath.isSafeCustomViewPath(view.path) || view.path.split("/").length !== 2) problems.push(`public.view.path is '${view.path}': a published view is exactly one HTML file directly inside the collection's own views/ directory (e.g. views/booking.html) — no sub-directories, and no segments that climb out of it. The host reads this as a file to publish, and what it publishes is world-readable.`);
1017
+ for (const cid of view.collections) {
1018
+ if (!known.has(cid)) {
1019
+ problems.push(`public.view.collections names '${cid}', which is not a shared collection in this repository. Shared collections here: ${known.size > 0 ? [...known].sort().join(", ") : "(none)"}.`);
1020
+ continue;
1021
+ }
1022
+ if (!readable.has(cid)) problems.push(`public.view.collections names '${cid}', which is not in public.read: the page reads these with the VISITOR's permissions, so the rules refuse the read and the view draws an empty page. Nothing errors — this is the failure that looks like a working view with no data.`);
1023
+ }
1024
+ return problems;
838
1025
  }
839
1026
  /** What publish will actually promote, checked as the PAIR it becomes.
840
1027
  *
@@ -863,12 +1050,146 @@ function windowRefProblems(app, collections) {
863
1050
  function promotedRoleProblems(app, staged) {
864
1051
  const promoted = stagedRuleConfig(staged).collections ?? {};
865
1052
  const stagedCids = new Set(staged.map((entry) => entry.cid));
1053
+ return [
1054
+ ...promotedAssigneeProblems(app, promoted, stagedCids),
1055
+ ...promotedMirrorProblems(app, promoted, stagedCids),
1056
+ ...promotedRefFieldProblems(app, staged)
1057
+ ];
1058
+ }
1059
+ /** The FIELDS a rule reads off another record — `idIn.where.field` and the two
1060
+ * window bounds — checked against the schema publish is about to promote.
1061
+ *
1062
+ * These are checked here rather than in `publishProblems` because that gate
1063
+ * is given a cid and a primary key per collection and nothing else, on
1064
+ * purpose: it reads the DECLARATION. A field name can only be judged against
1065
+ * a schema, and the schema that matters is the STAGED one — the version
1066
+ * publish promotes — not whatever the working tree says now.
1067
+ *
1068
+ * What a typo costs: `where: { field: "staet" }` publishes cleanly, the
1069
+ * rules' comparison can never match, and every submission is denied with no
1070
+ * message. The author's own app looks broken with nothing to read.
1071
+ *
1072
+ * Only fields the schema DECLARES are accepted. A record may carry more than
1073
+ * its schema does, but a shared collection's records are written through it,
1074
+ * and "the field exists on some rows" is not something a gate can promise. */
1075
+ function promotedRefFieldProblems(app, staged) {
1076
+ const schemaOf = new Map(staged.map((entry) => [entry.cid, entry.doc.publishedSchema]));
1077
+ return Object.entries(app.public?.submit ?? {}).flatMap(([cid, submit]) => submitRefProblems(schemaOf, cid, submit));
1078
+ }
1079
+ function submitRefProblems(schemaOf, cid, submit) {
1080
+ return [
1081
+ ...idInRefProblems(schemaOf, cid, submit),
1082
+ ...boundRefProblems(schemaOf, cid, "fromField", submit.window?.fromField),
1083
+ ...boundRefProblems(schemaOf, cid, "untilField", submit.window?.untilField)
1084
+ ];
1085
+ }
1086
+ function idInRefProblems(schemaOf, cid, submit) {
1087
+ const where = submit.idIn?.where;
1088
+ if (where === void 0) return [];
1089
+ return [...refFieldProblem(schemaOf, cid, "idIn.where.field", submit.idIn?.collection, where.field), ...comparableProblem(schemaOf, cid, submit.idIn?.collection, where)];
1090
+ }
1091
+ function boundRefProblems(schemaOf, cid, key, ref) {
1092
+ if (ref === void 0) return [];
1093
+ return [...refFieldProblem(schemaOf, cid, `window.${key}.field`, ref.collection, ref.field), ...millisProblem(schemaOf, cid, `window.${key}.field`, ref)];
1094
+ }
1095
+ /** The field spec a reference points at, or undefined when there is nothing
1096
+ * staged to judge it against (the host refuses that separately, naming every
1097
+ * missing collection at once). */
1098
+ function referencedField(schemaOf, target, field) {
1099
+ if (target === void 0 || field === void 0) return void 0;
1100
+ return schemaOf.get(target)?.fields?.[field];
1101
+ }
1102
+ /** An enum's domain, or undefined for every other kind. Narrowed by the key
1103
+ * rather than asserted: `fields` is a discriminated union and only some of
1104
+ * its members carry `values`. */
1105
+ function enumValues(spec) {
1106
+ return spec.type === "enum" ? spec.values : void 0;
1107
+ }
1108
+ function refFieldProblem(schemaOf, cid, key, target, field) {
1109
+ if (target === void 0 || field === void 0) return [];
1110
+ const schema = schemaOf.get(target);
1111
+ if (schema === void 0 || referencedField(schemaOf, target, field) !== void 0) return [];
1112
+ const known = Object.keys(schema.fields ?? {}).sort().join(", ");
1113
+ return [`public.submit.${cid}.${key} names '${field}', which the STAGED schema of '${target}' — the one publish promotes — does not declare. The rules read that field off the record and compare it, so as written every submission is refused with nothing to explain it. Fields on '${target}': ${known.length > 0 ? known : "(none)"}.`];
1114
+ }
1115
+ /** A comparison the rules can never satisfy is as dead as a missing field, and
1116
+ * looks even more correct on the page: an `enum` whose domain does not contain
1117
+ * the value, or a boolean field compared with a string. */
1118
+ function comparableProblem(schemaOf, cid, target, where) {
1119
+ const spec = referencedField(schemaOf, target, where.field);
1120
+ if (spec === void 0) return [];
1121
+ const said = JSON.stringify(where.equals);
1122
+ const values = enumValues(spec);
1123
+ if (values !== void 0) {
1124
+ if (values.includes(String(where.equals))) return [];
1125
+ return [`public.submit.${cid}.idIn.where.equals is ${said}, which is not one of the values '${where.field}' can hold on '${String(target)}' (${values.join(", ") || "(none)"}). The comparison can never be true, so every submission is refused.`];
1126
+ }
1127
+ const wanted = spec.type === "number" ? "number" : spec.type === "boolean" ? "boolean" : "string";
1128
+ if (typeof where.equals === wanted) return [];
1129
+ return [`public.submit.${cid}.idIn.where.equals is ${said}, and '${where.field}' on '${String(target)}' is a ${spec.type} field. The rules compare the stored value with this one and never coerce, so the comparison can never be true and every submission is refused.`];
1130
+ }
1131
+ /** A per-record window bound is EPOCH MILLIS, because the rules have no date
1132
+ * arithmetic and do not coerce: they compare `request.time.toMillis()` with
1133
+ * whatever is stored. A `datetime` field holds an ISO string, which is a type
1134
+ * error that fails closed — the window never opens, and nothing says so. */
1135
+ function millisProblem(schemaOf, cid, key, ref) {
1136
+ const spec = referencedField(schemaOf, ref?.collection, ref?.field);
1137
+ if (spec === void 0 || spec.type === "number") return [];
1138
+ return [`public.submit.${cid}.${key} names '${String(ref?.field)}' on '${String(ref?.collection)}', which is a ${spec.type} field. A per-record bound is EPOCH MILLIS: the rules compare it with request.time.toMillis() and never coerce, so anything else is a type error that refuses every submission — the window simply never opens. Store the instant as a number.`];
1139
+ }
1140
+ function promotedAssigneeProblems(app, promoted, stagedCids) {
866
1141
  return Object.entries(app.members).flatMap(([email, roles]) => Object.entries(roles).flatMap(([cid, role]) => {
867
1142
  if (role !== "assignee" || cid === "*" || !stagedCids.has(cid)) return [];
868
1143
  if (promoted[cid]?.assigneeField !== void 0) return [];
869
1144
  return [`members["${email}"] holds "assignee" on '${cid}', and the STAGED version of '${cid}' — the one publish promotes — carries no assigneeField, even if app.json declares one now. Publish writes the roster from app.json and the collection configuration from the deploy, so that member would land with nothing to be compared against: refused every write, while the app keeps working for everybody else. Run deploy again, so the version being published is the one the declaration describes.`];
870
1145
  }));
871
1146
  }
1147
+ /** The mirror's other half, checked against what publish will actually
1148
+ * promote — the same trap as the assignee's field, reached by the same route.
1149
+ *
1150
+ * `mirror` is published from the MANIFEST (it lives in `public.submit`) while
1151
+ * `mirrorOf` is promoted from what DEPLOY staged. Add both halves to
1152
+ * `app.json` and publish without redeploying, and what lands is a submission
1153
+ * demanding a paired projection write beside a projection whose rule config
1154
+ * does not allow it: every booking is refused, and the declaration on disk
1155
+ * looks perfectly sound.
1156
+ *
1157
+ * Refused in the reverse direction too. Removing `mirrorOf` from a live app
1158
+ * and publishing without a deploy leaves the projection accepting nothing —
1159
+ * and removing it FROM the staged side while the submission still demands it
1160
+ * is the drift this pair exists to prevent. */
1161
+ function promotedMirrorProblems(app, promoted, stagedCids) {
1162
+ return [...addedMirrorProblems(app, promoted, stagedCids), ...strandedMirrorProblems(app, promoted)];
1163
+ }
1164
+ /** The manifest asks for a projection the promoted configuration will not
1165
+ * allow: every submission denied, and nothing on the page to say why. */
1166
+ function addedMirrorProblems(app, promoted, stagedCids) {
1167
+ return Object.entries(app.public?.submit ?? {}).flatMap(([cid, submit]) => {
1168
+ const { mirror } = submit;
1169
+ if (mirror === void 0 || !stagedCids.has(mirror)) return [];
1170
+ if (promoted[mirror]?.mirrorOf === cid) return [];
1171
+ return [`public.submit.${cid}.mirror names '${mirror}', and the STAGED version of '${mirror}' — the one publish promotes — does not declare mirrorOf: "${cid}", even if app.json declares it now. Publish writes the submission side from app.json and the collection side from the deploy, so what lands is a booking that must move its projection beside a projection that refuses to move: every submission is denied, with nothing on the page to say why. Run deploy again, so the version being published is the one the declaration describes.`];
1172
+ });
1173
+ }
1174
+ /** The other direction, and the DANGEROUS one.
1175
+ *
1176
+ * Take a live pair, delete BOTH halves from `app.json`, and publish without
1177
+ * redeploying. The submission side comes from the manifest, so nothing
1178
+ * requires the projection to move any more; the collection side comes from
1179
+ * staging, which still says `mirrorOf`, so the projection stays writable.
1180
+ * Bookings are then created while the public row goes on saying `open` — the
1181
+ * precise failure the pair exists to prevent, arrived at by removing it.
1182
+ *
1183
+ * Refused rather than tolerated because the app keeps WORKING: submissions
1184
+ * succeed. Only the public page is wrong, and only to the people reading it. */
1185
+ function strandedMirrorProblems(app, promoted) {
1186
+ return Object.entries(promoted).flatMap(([cid, config]) => {
1187
+ const authority = config.mirrorOf;
1188
+ if (authority === void 0) return [];
1189
+ if (app.public?.submit?.[authority]?.mirror === cid) return [];
1190
+ return [`the STAGED version of '${cid}' — the one publish promotes — declares mirrorOf: "${authority}", and app.json no longer declares public.submit.${authority}.mirror: "${cid}". What lands is a projection that is still writable beside submissions that no longer have to move it, so records can be created while '${cid}' goes on advertising them as available. Nothing fails: the app works and the public page lies. Run deploy again, so the version being published is the one the declaration describes.`];
1191
+ });
1192
+ }
872
1193
  //#endregion
873
1194
  //#region src/collection/server/skillAssets.ts
874
1195
  /** Read a collection's custom-view HTML, path-safely. `viewFile` is a
@@ -3264,4 +3585,4 @@ Object.defineProperty(exports, "validateRecordObject", {
3264
3585
  }
3265
3586
  });
3266
3587
 
3267
- //# sourceMappingURL=server-BIKy55wo.cjs.map
3588
+ //# sourceMappingURL=server-_g1rW-Uc.cjs.map