@composable-os/cli 0.1.0-beta.10 → 0.1.0-beta.11
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/dist/{accounts-X4CKM3HL.js → accounts-UHYLCLEY.js} +10 -11
- package/dist/{blocks-YWDHEBOK.js → blocks-5IFU25J6.js} +2 -2
- package/dist/chunk-2IVEVPMY.js +669 -0
- package/dist/{chunk-QGGJ2G6Z.js → chunk-2TWV3SVB.js} +3 -3
- package/dist/chunk-2XC5JLBO.js +1931 -0
- package/dist/chunk-324WJXNP.js +320 -0
- package/dist/chunk-6ELZRNUU.js +116 -0
- package/dist/{chunk-YJJHF65I.js → chunk-6WGFA2IV.js} +58 -174
- package/dist/{chunk-A4NTSYWV.js → chunk-6XTU2MTP.js} +196 -10
- package/dist/{chunk-Q4N55M2Z.js → chunk-7D4GKZOX.js} +66 -3
- package/dist/{chunk-GYSGVT6R.js → chunk-7OGCMQXG.js} +9 -9
- package/dist/chunk-DHS2CV2M.js +139 -0
- package/dist/{chunk-LJFLENFC.js → chunk-E64SG24J.js} +1 -1
- package/dist/{chunk-Z3RMMB6S.js → chunk-FJIZGS5Q.js} +45 -15
- package/dist/chunk-K34UKWEI.js +298 -0
- package/dist/{chunk-LLULPZAJ.js → chunk-LAAL4YGR.js} +4 -4
- package/dist/{chunk-CP6BXI6F.js → chunk-LO6WGU5Y.js} +1338 -974
- package/dist/{chunk-Y7JZFSTQ.js → chunk-MBIKVRAC.js} +6 -6
- package/dist/{chunk-WC5LHBBA.js → chunk-P6UWZ6QQ.js} +1 -1
- package/dist/{chunk-6VXHPKGG.js → chunk-PDD2ETVF.js} +8 -8
- package/dist/{chunk-6UPUF4ML.js → chunk-UB4I2QKR.js} +1957 -380
- package/dist/{chunk-M7A6FR2Z.js → chunk-WHKJGF36.js} +154 -322
- package/dist/{chunk-VY64DMQO.js → chunk-XIDLW3EP.js} +190 -21
- package/dist/{chunk-IFG4FRW5.js → chunk-YFTLIEWU.js} +1 -1
- package/dist/{chunk-JJHHNV46.js → chunk-YNUZRTPH.js} +5 -50
- package/dist/{chunk-WO6D3XP3.js → chunk-ZAWES2UD.js} +31 -18
- package/dist/{chunk-K6T42YCH.js → chunk-ZZFWMVJO.js} +5 -5
- package/dist/{cli-2DFENR62.js → cli-5UNY5G5L.js} +22 -20
- package/dist/{cli-YIOVSKOD.js → cli-UYZMVQMR.js} +16 -13
- package/dist/cli.js +1 -1
- package/dist/{client-repo-PRU3VCQQ.js → client-repo-SE4EKG6W.js} +2 -2
- package/dist/create.js +1 -1
- package/dist/{fields-2NC7LSYE.js → fields-FTWWMD7N.js} +3 -3
- package/dist/grants-LOW6TSWD.js +32 -0
- package/dist/invoke-6KVT6WJI.js +41 -0
- package/dist/moves-E2HKYCTK.js +41 -0
- package/dist/{order-PUWD65BC.js → order-U4KZLLSJ.js} +2 -2
- package/dist/{person-WIQQ7ITU.js → person-UHLVBVLR.js} +9 -10
- package/dist/plan-on-sale-TJPFCNL7.js +26 -0
- package/dist/platform/migrations/0610_waitlists.sql +54 -0
- package/dist/platform/migrations/0630_subscription_changes.sql +122 -0
- package/dist/platform/migrations/0650_person_links.sql +90 -0
- package/dist/platform/migrations/0670_unmoved_guard.sql +52 -0
- package/dist/platform/migrations/0690_sellable_refund_due.sql +98 -0
- package/dist/platform/sdk/capacity.ts +102 -0
- package/dist/platform/sdk/contract.ts +25 -0
- package/dist/platform/sdk/manifest.ts +77 -1
- package/dist/platform/sdk/sellable.ts +251 -1
- package/dist/platform/sdk/states.ts +163 -49
- package/dist/{run-RT2HVWMK.js → run-7P4RQALH.js} +2 -2
- package/dist/{run-PZUCSDDL.js → run-PO3W5BFA.js} +1 -1
- package/dist/{run-Y7T4TVOL.js → run-ZCGFMEZF.js} +2 -2
- package/dist/src-CRO35DYY.js +46 -0
- package/dist/{src-XTOD7EXW.js → src-I3IJ4NKC.js} +8 -2
- package/dist/{visibility-DLGHU4YN.js → visibility-TVXZ67FD.js} +12 -4
- package/package.json +2 -2
- package/dist/chunk-6GDEDOV7.js +0 -157
- package/dist/chunk-O2UIZHND.js +0 -249
- package/dist/chunk-R4W5XAUD.js +0 -837
- package/dist/chunk-TQFGGSA4.js +0 -748
- package/dist/grants-QXMKYMGB.js +0 -32
- package/dist/invoke-I3NNNXVL.js +0 -39
- package/dist/plan-on-sale-NB774CQL.js +0 -26
- package/dist/src-GYS6NBQB.js +0 -44
|
@@ -20752,666 +20752,1068 @@ function safeDuration(duration3) {
|
|
|
20752
20752
|
}
|
|
20753
20753
|
}
|
|
20754
20754
|
|
|
20755
|
-
// ../sdk/src/
|
|
20756
|
-
var
|
|
20757
|
-
var CAPACITY_VALUES = ["held", "taken", "available"];
|
|
20755
|
+
// ../sdk/src/states.ts
|
|
20756
|
+
var MOVERS = ["staff", "customer", "host"];
|
|
20758
20757
|
var fieldName3 = external_exports.string().max(40);
|
|
20759
|
-
var
|
|
20760
|
-
|
|
20761
|
-
|
|
20762
|
-
|
|
20763
|
-
|
|
20764
|
-
|
|
20765
|
-
|
|
20766
|
-
|
|
20767
|
-
|
|
20768
|
-
|
|
20769
|
-
|
|
20770
|
-
|
|
20771
|
-
|
|
20772
|
-
|
|
20773
|
-
|
|
20774
|
-
|
|
20775
|
-
|
|
20776
|
-
|
|
20777
|
-
|
|
20778
|
-
|
|
20779
|
-
|
|
20780
|
-
|
|
20781
|
-
|
|
20782
|
-
|
|
20783
|
-
|
|
20784
|
-
|
|
20785
|
-
|
|
20786
|
-
|
|
20787
|
-
|
|
20788
|
-
|
|
20789
|
-
|
|
20790
|
-
|
|
20791
|
-
|
|
20792
|
-
|
|
20793
|
-
|
|
20794
|
-
|
|
20795
|
-
|
|
20796
|
-
|
|
20797
|
-
|
|
20798
|
-
|
|
20799
|
-
|
|
20800
|
-
|
|
20801
|
-
|
|
20802
|
-
|
|
20758
|
+
var stateValue2 = external_exports.string().min(1).max(100);
|
|
20759
|
+
var fieldPath = external_exports.string().min(1).max(122);
|
|
20760
|
+
var windowNumber = (number4) => external_exports.union([
|
|
20761
|
+
number4,
|
|
20762
|
+
fieldPath,
|
|
20763
|
+
external_exports.object({ field: fieldPath.optional(), setting: external_exports.string().min(1).max(40).optional() }).strict().refine((n) => n.field !== void 0 || n.setting !== void 0, "Name a field or a setting")
|
|
20764
|
+
]);
|
|
20765
|
+
var windowBoundSchema = external_exports.union([
|
|
20766
|
+
fieldPath,
|
|
20767
|
+
external_exports.object({
|
|
20768
|
+
at: fieldPath,
|
|
20769
|
+
daysBefore: windowNumber(external_exports.number().int().min(-366).max(366)).optional(),
|
|
20770
|
+
minutesBefore: windowNumber(external_exports.number().int().min(-527040).max(527040)).optional(),
|
|
20771
|
+
zone: fieldPath.optional()
|
|
20772
|
+
}).strict()
|
|
20773
|
+
]);
|
|
20774
|
+
var staffOnlyPaths = external_exports.union([fieldPath, external_exports.array(fieldPath).min(1).max(4)]);
|
|
20775
|
+
var moveWindow = external_exports.object({ from: windowBoundSchema.optional(), until: windowBoundSchema.optional() }).strict().refine((w) => w.from !== void 0 || w.until !== void 0, "A window needs from or until");
|
|
20776
|
+
var statesManifestSchema = external_exports.object({
|
|
20777
|
+
field: fieldName3,
|
|
20778
|
+
initial: stateValue2,
|
|
20779
|
+
moves: external_exports.array(
|
|
20780
|
+
external_exports.object({
|
|
20781
|
+
from: external_exports.union([stateValue2, external_exports.array(stateValue2).min(1).max(50)]),
|
|
20782
|
+
to: stateValue2,
|
|
20783
|
+
by: external_exports.array(external_exports.enum(MOVERS)).min(1).max(MOVERS.length),
|
|
20784
|
+
requires: external_exports.array(fieldName3).max(50).optional(),
|
|
20785
|
+
final: external_exports.boolean().optional(),
|
|
20786
|
+
window: moveWindow.optional(),
|
|
20787
|
+
staffOnly: staffOnlyPaths.optional(),
|
|
20788
|
+
tools: external_exports.array(external_exports.string().min(1).max(40)).min(1).max(10).optional(),
|
|
20789
|
+
bindsStaff: external_exports.boolean().optional()
|
|
20790
|
+
})
|
|
20791
|
+
).max(200),
|
|
20792
|
+
create: external_exports.object({
|
|
20793
|
+
in: external_exports.record(stateValue2, external_exports.array(external_exports.enum(MOVERS)).min(1).max(MOVERS.length)).refine((r) => Object.keys(r).length <= 20, "At most 20 states").optional(),
|
|
20794
|
+
window: moveWindow.optional(),
|
|
20795
|
+
staffOnly: staffOnlyPaths.optional(),
|
|
20796
|
+
closed: staffOnlyPaths.optional()
|
|
20797
|
+
}).strict().optional(),
|
|
20798
|
+
requests: external_exports.record(external_exports.string().regex(/^[a-z][a-z0-9_]{0,39}$/), external_exports.array(stateValue2).min(1).max(10)).refine((r) => Object.keys(r).length <= 10, "At most 10 requests").optional(),
|
|
20799
|
+
follows: external_exports.object({
|
|
20800
|
+
relation: fieldName3,
|
|
20801
|
+
when: external_exports.record(stateValue2, stateValue2).refine((r) => Object.keys(r).length >= 1 && Object.keys(r).length <= 10, "1 to 10 states"),
|
|
20802
|
+
from: external_exports.array(stateValue2).min(1).max(20)
|
|
20803
|
+
}).strict().optional(),
|
|
20804
|
+
after: external_exports.array(
|
|
20805
|
+
external_exports.object({
|
|
20806
|
+
from: external_exports.union([stateValue2, external_exports.array(stateValue2).min(1).max(20)]),
|
|
20807
|
+
to: stateValue2,
|
|
20808
|
+
at: fieldPath,
|
|
20809
|
+
minutesAfter: external_exports.number().int().min(0).max(10080).optional(),
|
|
20810
|
+
ifAnyIn: external_exports.array(stateValue2).min(1).max(20).optional()
|
|
20811
|
+
}).strict()
|
|
20812
|
+
).min(1).max(4).optional()
|
|
20813
|
+
});
|
|
20814
|
+
function staffOnlyPathsOf(value) {
|
|
20815
|
+
return value === void 0 ? [] : typeof value === "string" ? [value] : value;
|
|
20816
|
+
}
|
|
20817
|
+
function moveOrigins(move) {
|
|
20818
|
+
return typeof move.from === "string" ? [move.from] : move.from;
|
|
20819
|
+
}
|
|
20820
|
+
function checkObjectStates(m, name, object3, contract) {
|
|
20821
|
+
const states = object3.states;
|
|
20822
|
+
if (!states) return;
|
|
20823
|
+
const sp = `objects.${name}.states`;
|
|
20824
|
+
if (object3.stages) {
|
|
20825
|
+
contract(sp, "An object has one lifecycle: declare stages or states, not both");
|
|
20803
20826
|
}
|
|
20804
|
-
|
|
20805
|
-
|
|
20827
|
+
const fieldOf = (local) => Object.hasOwn(object3.fields, local) ? object3.fields[local] : void 0;
|
|
20828
|
+
const field = fieldOf(states.field);
|
|
20829
|
+
if (field?.type !== "select") {
|
|
20830
|
+
contract(`${sp}.field`, `"${states.field}" must be a select field of ${name}`);
|
|
20831
|
+
return;
|
|
20806
20832
|
}
|
|
20807
|
-
if (
|
|
20808
|
-
contract(`${
|
|
20833
|
+
if (field.readOnly) {
|
|
20834
|
+
contract(`${sp}.field`, "The state field cannot be read-only: the moves say who may change it");
|
|
20809
20835
|
}
|
|
20810
|
-
|
|
20811
|
-
var claimsManifestSchema = external_exports.object({
|
|
20812
|
-
on: fieldName3,
|
|
20813
|
-
held: external_exports.array(external_exports.string().min(1).max(100)).max(20).optional(),
|
|
20814
|
-
confirmed: external_exports.array(external_exports.string().min(1).max(100)).max(20).optional()
|
|
20815
|
-
}).strict();
|
|
20816
|
-
function checkObjectClaims(m, name, object3, contract) {
|
|
20817
|
-
const claims = object3.claims;
|
|
20818
|
-
if (!claims) return;
|
|
20819
|
-
const path2 = `objects.${name}.claims`;
|
|
20820
|
-
const on = Object.hasOwn(object3.fields, claims.on) ? object3.fields[claims.on] : void 0;
|
|
20821
|
-
const target = on?.type === "relation" && !on.many ? on.to : void 0;
|
|
20822
|
-
const local = target?.startsWith(`${m.id}.`) ? target.slice(m.id.length + 1) : void 0;
|
|
20823
|
-
const targetObject = local !== void 0 && Object.hasOwn(m.objects, local) ? m.objects[local] : void 0;
|
|
20824
|
-
if (!targetObject || local === name) {
|
|
20836
|
+
if (field.editableOptions) {
|
|
20825
20837
|
contract(
|
|
20826
|
-
`${
|
|
20827
|
-
|
|
20838
|
+
`${sp}.field`,
|
|
20839
|
+
"The state field cannot have editableOptions: states are fixed in the declaration"
|
|
20828
20840
|
);
|
|
20829
|
-
} else if (!targetObject.capacity) {
|
|
20830
|
-
contract(`${path2}.on`, `${target} must declare a capacity for its places to be claimed`);
|
|
20831
20841
|
}
|
|
20832
|
-
const
|
|
20833
|
-
const
|
|
20834
|
-
if (!
|
|
20835
|
-
contract(
|
|
20842
|
+
const values = new Set((field.options ?? []).map((o) => o.value));
|
|
20843
|
+
const isState = (value) => values.has(value);
|
|
20844
|
+
if (!isState(states.initial)) {
|
|
20845
|
+
contract(`${sp}.initial`, `"${states.initial}" is not an option of ${states.field}`);
|
|
20836
20846
|
}
|
|
20837
|
-
|
|
20838
|
-
|
|
20839
|
-
|
|
20840
|
-
|
|
20847
|
+
if (field.default !== void 0 && field.default !== states.initial) {
|
|
20848
|
+
contract(
|
|
20849
|
+
`${sp}.initial`,
|
|
20850
|
+
`${states.field}'s default must be the initial state "${states.initial}", or be left out`
|
|
20851
|
+
);
|
|
20841
20852
|
}
|
|
20842
|
-
const
|
|
20843
|
-
const
|
|
20844
|
-
|
|
20845
|
-
|
|
20846
|
-
|
|
20847
|
-
|
|
20848
|
-
if (
|
|
20849
|
-
|
|
20850
|
-
|
|
20853
|
+
const seen = /* @__PURE__ */ new Set();
|
|
20854
|
+
const finals = new Set(states.moves.filter((move) => move.final).map((move) => move.to));
|
|
20855
|
+
states.moves.forEach((move, i) => {
|
|
20856
|
+
const mp = `${sp}.moves.${i}`;
|
|
20857
|
+
if (!isState(move.to)) contract(`${mp}.to`, `"${move.to}" is not an option of ${states.field}`);
|
|
20858
|
+
if (new Set(move.by).size !== move.by.length) contract(`${mp}.by`, "List each mover once");
|
|
20859
|
+
if (finals.has(move.to) && !move.final) {
|
|
20860
|
+
contract(
|
|
20861
|
+
`${mp}.final`,
|
|
20862
|
+
`Another move into "${move.to}" is final; every move into a state must agree`
|
|
20863
|
+
);
|
|
20851
20864
|
}
|
|
20852
|
-
|
|
20853
|
-
|
|
20854
|
-
|
|
20855
|
-
|
|
20856
|
-
|
|
20865
|
+
if (move.final && move.to === states.initial) {
|
|
20866
|
+
contract(`${mp}.final`, "The initial state cannot be final");
|
|
20867
|
+
}
|
|
20868
|
+
for (const from of moveOrigins(move)) {
|
|
20869
|
+
if (!isState(from)) {
|
|
20870
|
+
contract(`${mp}.from`, `"${from}" is not an option of ${states.field}`);
|
|
20871
|
+
}
|
|
20872
|
+
if (from === move.to) contract(`${mp}.from`, `A move cannot go from "${from}" to itself`);
|
|
20873
|
+
if (finals.has(from)) {
|
|
20874
|
+
contract(`${mp}.from`, `"${from}" is final: nothing moves out of it`);
|
|
20875
|
+
}
|
|
20876
|
+
const key = JSON.stringify([from, move.to]);
|
|
20877
|
+
if (seen.has(key)) {
|
|
20878
|
+
contract(mp, `The move from "${from}" to "${move.to}" is declared twice`);
|
|
20879
|
+
}
|
|
20880
|
+
seen.add(key);
|
|
20881
|
+
}
|
|
20882
|
+
for (const local of move.requires ?? []) {
|
|
20883
|
+
const required2 = fieldOf(local);
|
|
20884
|
+
if (!required2 || required2.type === "formula" || local === states.field) {
|
|
20885
|
+
contract(
|
|
20886
|
+
`${mp}.requires`,
|
|
20887
|
+
`"${local}" must be a field of ${name} other than a formula or the state field`
|
|
20888
|
+
);
|
|
20889
|
+
} else if (required2.readOnly && move.by.some((mover) => mover !== "host")) {
|
|
20890
|
+
contract(
|
|
20891
|
+
`${mp}.requires`,
|
|
20892
|
+
`"${local}" is read-only, so only a move made by the host alone can require it`
|
|
20893
|
+
);
|
|
20894
|
+
}
|
|
20895
|
+
}
|
|
20896
|
+
});
|
|
20897
|
+
const { checkPath, checkWindow } = windowChecks(m, object3, name, contract);
|
|
20857
20898
|
states.moves.forEach((move, i) => {
|
|
20858
|
-
const
|
|
20859
|
-
if (
|
|
20899
|
+
const mp = `${sp}.moves.${i}`;
|
|
20900
|
+
if (move.staffOnly && !move.by.includes("customer")) {
|
|
20901
|
+
contract(mp, "staffOnly binds customers: the move must list customer in by");
|
|
20902
|
+
}
|
|
20903
|
+
if (move.window && !move.by.includes("customer") && !move.bindsStaff) {
|
|
20860
20904
|
contract(
|
|
20861
|
-
|
|
20862
|
-
|
|
20905
|
+
mp,
|
|
20906
|
+
"A window binds customers: the move must list customer in by, or bind staff (bindsStaff)"
|
|
20907
|
+
);
|
|
20908
|
+
}
|
|
20909
|
+
checkWindow(move.window, `${mp}.window`);
|
|
20910
|
+
for (const p of staffOnlyPathsOf(move.staffOnly)) checkPath(p, `${mp}.staffOnly`, "boolean");
|
|
20911
|
+
for (const tool of move.tools ?? []) {
|
|
20912
|
+
const spec = m.tools?.[tool];
|
|
20913
|
+
if (!spec) {
|
|
20914
|
+
contract(`${mp}.tools`, `"${tool}" is not a tool of this extension`);
|
|
20915
|
+
} else if (!spec.humanOnly && !spec.personApproves || !spec.permission) {
|
|
20916
|
+
contract(
|
|
20917
|
+
`${mp}.tools`,
|
|
20918
|
+
`"${tool}" must be humanOnly or personApproves and declare a permission: the move is a person's act with it`
|
|
20919
|
+
);
|
|
20920
|
+
}
|
|
20921
|
+
}
|
|
20922
|
+
if (move.bindsStaff && (!move.window || !move.by.includes("staff") && !move.tools)) {
|
|
20923
|
+
contract(`${mp}.bindsStaff`, "bindsStaff needs a window, and staff in by or named tools");
|
|
20924
|
+
}
|
|
20925
|
+
if (move.tools && move.by.includes("staff")) {
|
|
20926
|
+
contract(
|
|
20927
|
+
`${mp}.tools`,
|
|
20928
|
+
"A move named tools may make is not also open to all staff: drop staff from by"
|
|
20863
20929
|
);
|
|
20864
20930
|
}
|
|
20865
20931
|
});
|
|
20866
|
-
|
|
20867
|
-
|
|
20868
|
-
|
|
20869
|
-
|
|
20870
|
-
|
|
20871
|
-
|
|
20872
|
-
var DOCUMENT_MAX_LIST = 1e3;
|
|
20873
|
-
var DOCUMENT_MAX_TEXT = 2e4;
|
|
20874
|
-
var DOCUMENT_DEFAULT_TEXT = 1e3;
|
|
20875
|
-
var DOCUMENT_MAX_ISSUES = 20;
|
|
20876
|
-
var DOCUMENT_MAX_PATHS = 12;
|
|
20877
|
-
var ID_RE = /^[a-z][a-z0-9]{0,9}_[A-Za-z0-9]{1,60}$/;
|
|
20878
|
-
var KEY_RE = /^[a-z][a-zA-Z0-9]{0,39}$/;
|
|
20879
|
-
var OBJECT_RE = /^[a-z][a-z0-9]*(\.[a-z][a-z0-9]*)?$/;
|
|
20880
|
-
var CONTROL_RE = /[\u0000-\u0008\u000b-\u001f\u007f]/;
|
|
20881
|
-
var MARKUP_RE = /<[A-Za-z!/?]|&(?:#[0-9]+|#[xX][0-9A-Fa-f]+|[A-Za-z][A-Za-z0-9]*);/;
|
|
20882
|
-
var URL_TAIL = "[^\\s<>\"'`\\\\]*";
|
|
20883
|
-
var WEB_RE = new RegExp(
|
|
20884
|
-
`^https?://[A-Za-z0-9](?:[A-Za-z0-9.-]*[A-Za-z0-9])?(?::[0-9]{1,5})?(?:[/?#]${URL_TAIL})?$`,
|
|
20885
|
-
"i"
|
|
20886
|
-
);
|
|
20887
|
-
var MAILTO_RE = /^mailto:[^\s<>"'`\\:/][^\s<>"'`\\]*$/i;
|
|
20888
|
-
var TEL_RE = /^tel:[+0-9 ().-]{3,40}$/i;
|
|
20889
|
-
var PATH_RE = new RegExp(`^/(?![/\\\\])${URL_TAIL}$`);
|
|
20890
|
-
var ANCHOR_RE = /^#[A-Za-z0-9_-]{1,100}$/;
|
|
20891
|
-
function isDocumentHref(value, kind) {
|
|
20892
|
-
if (WEB_RE.test(value)) return true;
|
|
20893
|
-
if (kind === "web") return false;
|
|
20894
|
-
return MAILTO_RE.test(value) || TEL_RE.test(value) || PATH_RE.test(value) || ANCHOR_RE.test(value);
|
|
20895
|
-
}
|
|
20896
|
-
function hasMarkup(value) {
|
|
20897
|
-
return MARKUP_RE.test(value);
|
|
20898
|
-
}
|
|
20899
|
-
var isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20900
|
-
function documentBytes(value) {
|
|
20901
|
-
const text = JSON.stringify(value) ?? "";
|
|
20902
|
-
let bytes = 0;
|
|
20903
|
-
for (const char of text) {
|
|
20904
|
-
const code = char.codePointAt(0) ?? 0;
|
|
20905
|
-
bytes += code < 128 ? 1 : code < 2048 ? 2 : code < 65536 ? 3 : 4;
|
|
20906
|
-
}
|
|
20907
|
-
return bytes;
|
|
20908
|
-
}
|
|
20909
|
-
function checkDocumentSchema(schema, knownObjects) {
|
|
20910
|
-
const problems = [];
|
|
20911
|
-
const add = (path2, message) => {
|
|
20912
|
-
if (problems.length < 50) problems.push([path2, message]);
|
|
20913
|
-
};
|
|
20914
|
-
if (!isObject2(schema)) {
|
|
20915
|
-
add("", "A document schema is an object with a `root` object node");
|
|
20916
|
-
return problems;
|
|
20917
|
-
}
|
|
20918
|
-
for (const key of Object.keys(schema)) {
|
|
20919
|
-
if (key !== "root" && key !== "defs") add(key, `Unknown key "${key}" (root, defs)`);
|
|
20920
|
-
}
|
|
20921
|
-
const defs = isObject2(schema.defs) ? schema.defs : {};
|
|
20922
|
-
if (schema.defs !== void 0 && !isObject2(schema.defs)) add("defs", "defs is an object");
|
|
20923
|
-
for (const name of Object.keys(defs)) {
|
|
20924
|
-
if (!KEY_RE.test(name)) add(`defs.${name}`, "A definition's name is camelCase");
|
|
20925
|
-
}
|
|
20926
|
-
const node2 = (path2, value, depth, inFields) => {
|
|
20927
|
-
if (depth > DOCUMENT_MAX_DEPTH) {
|
|
20928
|
-
add(path2, `The schema nests deeper than ${DOCUMENT_MAX_DEPTH}`);
|
|
20929
|
-
return;
|
|
20930
|
-
}
|
|
20931
|
-
if (!isObject2(value)) {
|
|
20932
|
-
add(path2, "A node is an object with a `type`");
|
|
20933
|
-
return;
|
|
20932
|
+
if (states.create) {
|
|
20933
|
+
for (const state of Object.keys(states.create.in ?? {})) {
|
|
20934
|
+
if (!isState(state))
|
|
20935
|
+
contract(`${sp}.create.in`, `"${state}" is not an option of ${states.field}`);
|
|
20936
|
+
if (finals.has(state))
|
|
20937
|
+
contract(`${sp}.create.in`, `"${state}" is final: nothing is created in it`);
|
|
20934
20938
|
}
|
|
20935
|
-
|
|
20936
|
-
const
|
|
20937
|
-
|
|
20938
|
-
};
|
|
20939
|
-
if (value.optional !== void 0 && (typeof value.optional !== "boolean" || !inFields)) {
|
|
20940
|
-
add(`${path2}.optional`, "optional is true or false, on a field of an object");
|
|
20939
|
+
checkWindow(states.create.window, `${sp}.create.window`);
|
|
20940
|
+
for (const p of staffOnlyPathsOf(states.create.staffOnly)) {
|
|
20941
|
+
checkPath(p, `${sp}.create.staffOnly`, "boolean");
|
|
20941
20942
|
}
|
|
20942
|
-
|
|
20943
|
-
|
|
20943
|
+
for (const p of staffOnlyPathsOf(states.create.closed)) {
|
|
20944
|
+
checkPath(p, `${sp}.create.closed`, "boolean");
|
|
20944
20945
|
}
|
|
20945
|
-
|
|
20946
|
-
|
|
20947
|
-
|
|
20948
|
-
|
|
20949
|
-
|
|
20950
|
-
|
|
20951
|
-
|
|
20952
|
-
|
|
20953
|
-
|
|
20954
|
-
|
|
20955
|
-
|
|
20956
|
-
|
|
20957
|
-
|
|
20958
|
-
|
|
20959
|
-
|
|
20960
|
-
|
|
20961
|
-
|
|
20962
|
-
|
|
20946
|
+
}
|
|
20947
|
+
if (states.follows) {
|
|
20948
|
+
const fp = `${sp}.follows`;
|
|
20949
|
+
const f = states.follows;
|
|
20950
|
+
const rel = fieldOf(f.relation);
|
|
20951
|
+
const target = rel?.type === "relation" && !rel.many && rel.to?.startsWith(`${m.id}.`) ? m.objects[rel.to.slice(m.id.length + 1)] : void 0;
|
|
20952
|
+
if (!target?.states) {
|
|
20953
|
+
contract(
|
|
20954
|
+
`${fp}.relation`,
|
|
20955
|
+
`"${f.relation}" must be a relation (one record) of ${name} to another of this extension's objects that declares states`
|
|
20956
|
+
);
|
|
20957
|
+
} else {
|
|
20958
|
+
const pooled = Object.values(m.objects).some((other) => {
|
|
20959
|
+
const poolField = other.capacity?.pool;
|
|
20960
|
+
const relTo = poolField ? other.fields[poolField]?.to : void 0;
|
|
20961
|
+
return relTo === rel?.to || relTo === rel?.to?.slice(m.id.length + 1);
|
|
20962
|
+
});
|
|
20963
|
+
if (pooled) {
|
|
20964
|
+
contract(
|
|
20965
|
+
`${fp}.relation`,
|
|
20966
|
+
`${rel?.to ?? f.relation} is a pool other records draw places from: a cascade cannot follow it`
|
|
20967
|
+
);
|
|
20963
20968
|
}
|
|
20964
|
-
|
|
20965
|
-
|
|
20966
|
-
|
|
20967
|
-
|
|
20969
|
+
const parentStates = new Set(
|
|
20970
|
+
(target.fields[target.states.field]?.options ?? []).map((o) => o.value)
|
|
20971
|
+
);
|
|
20972
|
+
for (const [when, to] of Object.entries(f.when)) {
|
|
20973
|
+
if (!parentStates.has(when)) {
|
|
20974
|
+
contract(`${fp}.when`, `"${when}" is not a state of ${rel?.to ?? f.relation}`);
|
|
20968
20975
|
}
|
|
20969
|
-
const
|
|
20970
|
-
|
|
20971
|
-
|
|
20972
|
-
|
|
20973
|
-
|
|
20974
|
-
|
|
20975
|
-
|
|
20976
|
-
const of = resolve(value.of);
|
|
20977
|
-
const shapes = of?.type === "object" ? [of] : of?.type === "union" ? Object.values(of.variants ?? {}) : [];
|
|
20978
|
-
const keyNodes = shapes.map((shape) => resolve(shape.fields?.[String(value.unique)]));
|
|
20979
|
-
if (typeof value.unique !== "string" || !keyNodes.length || keyNodes.some((n) => !n || !["text", "number", "choice", "ref"].includes(n.type))) {
|
|
20980
|
-
add(
|
|
20981
|
-
`${path2}.unique`,
|
|
20982
|
-
"unique names a text, number, choice or ref key of the listed objects"
|
|
20983
|
-
);
|
|
20976
|
+
for (const from of f.from) {
|
|
20977
|
+
if (!isState(from))
|
|
20978
|
+
contract(`${fp}.from`, `"${from}" is not an option of ${states.field}`);
|
|
20979
|
+
else if (!states.moves.some(
|
|
20980
|
+
(move) => move.to === to && move.by.includes("host") && moveOrigins(move).includes(from)
|
|
20981
|
+
)) {
|
|
20982
|
+
contract(`${fp}.when`, `${name} needs a host move from "${from}" to "${to}"`);
|
|
20984
20983
|
}
|
|
20985
20984
|
}
|
|
20986
|
-
break;
|
|
20987
|
-
}
|
|
20988
|
-
case "text": {
|
|
20989
|
-
expect("max", "min", "multiline", "chars", "noMarkup", "href");
|
|
20990
|
-
if (value.noMarkup !== void 0 && typeof value.noMarkup !== "boolean") {
|
|
20991
|
-
add(`${path2}.noMarkup`, "noMarkup is true or false");
|
|
20992
|
-
}
|
|
20993
|
-
if (value.href !== void 0 && value.href !== "web" && value.href !== "link") {
|
|
20994
|
-
add(`${path2}.href`, "href is web or link");
|
|
20995
|
-
}
|
|
20996
|
-
const max = num("max", { int: true, min: 1, max: DOCUMENT_MAX_TEXT });
|
|
20997
|
-
const min = num("min", { int: true, min: 0 });
|
|
20998
|
-
if (min !== void 0 && (max ?? DOCUMENT_DEFAULT_TEXT) < min)
|
|
20999
|
-
add(`${path2}.min`, "min is above max");
|
|
21000
|
-
if (value.multiline !== void 0 && typeof value.multiline !== "boolean") {
|
|
21001
|
-
add(`${path2}.multiline`, "multiline is true or false");
|
|
21002
|
-
}
|
|
21003
|
-
if (value.chars !== void 0 && (typeof value.chars !== "string" || !value.chars.length || value.chars.length > 200)) {
|
|
21004
|
-
add(`${path2}.chars`, "chars is the allowed characters, 1 to 200 of them");
|
|
21005
|
-
}
|
|
21006
|
-
break;
|
|
21007
|
-
}
|
|
21008
|
-
case "number": {
|
|
21009
|
-
expect("min", "max", "integer", "step");
|
|
21010
|
-
const min = num("min");
|
|
21011
|
-
const max = num("max");
|
|
21012
|
-
if (min !== void 0 && max !== void 0 && min > max)
|
|
21013
|
-
add(`${path2}.min`, "min is above max");
|
|
21014
|
-
if (value.integer !== void 0 && typeof value.integer !== "boolean") {
|
|
21015
|
-
add(`${path2}.integer`, "integer is true or false");
|
|
21016
|
-
}
|
|
21017
|
-
const step = num("step");
|
|
21018
|
-
if (step !== void 0 && step <= 0) add(`${path2}.step`, "step is above 0");
|
|
21019
|
-
break;
|
|
21020
|
-
}
|
|
21021
|
-
case "boolean":
|
|
21022
|
-
break;
|
|
21023
|
-
case "choice": {
|
|
21024
|
-
expect("options");
|
|
21025
|
-
const options = value.options;
|
|
21026
|
-
if (!Array.isArray(options) || !options.length || options.length > 100 || options.some((o) => typeof o !== "string" || !o.length || o.length > 100)) {
|
|
21027
|
-
add(`${path2}.options`, "A choice lists 1 to 100 words");
|
|
21028
|
-
} else if (new Set(options).size !== options.length) {
|
|
21029
|
-
add(`${path2}.options`, "A choice lists each word once");
|
|
21030
|
-
}
|
|
21031
|
-
break;
|
|
21032
20985
|
}
|
|
21033
|
-
|
|
21034
|
-
|
|
21035
|
-
|
|
21036
|
-
|
|
21037
|
-
|
|
21038
|
-
|
|
21039
|
-
|
|
21040
|
-
|
|
21041
|
-
|
|
21042
|
-
|
|
21043
|
-
|
|
21044
|
-
|
|
21045
|
-
|
|
21046
|
-
|
|
20986
|
+
}
|
|
20987
|
+
}
|
|
20988
|
+
(states.after ?? []).forEach((rule, i) => {
|
|
20989
|
+
const tp = `${sp}.after.${i}`;
|
|
20990
|
+
if (!isState(rule.to)) contract(`${tp}.to`, `"${rule.to}" is not an option of ${states.field}`);
|
|
20991
|
+
for (const from of moveOrigins(rule)) {
|
|
20992
|
+
if (!isState(from)) {
|
|
20993
|
+
contract(`${tp}.from`, `"${from}" is not an option of ${states.field}`);
|
|
20994
|
+
} else if (!states.moves.some(
|
|
20995
|
+
(move) => move.to === rule.to && move.by.includes("host") && moveOrigins(move).includes(from)
|
|
20996
|
+
)) {
|
|
20997
|
+
contract(`${tp}.from`, `${name} needs a host move from "${from}" to "${rule.to}"`);
|
|
20998
|
+
}
|
|
20999
|
+
}
|
|
21000
|
+
const parts = rule.at.split(".");
|
|
21001
|
+
const at = parts.length <= 2 ? resolveFieldPath(m, object3, rule.at) : void 0;
|
|
21002
|
+
const via = parts.length === 2 ? fieldOf(parts[0]) : void 0;
|
|
21003
|
+
const ownTarget = via?.type === "relation" && !via.many && via.to?.startsWith(`${m.id}.`);
|
|
21004
|
+
if (at?.type !== "datetime" || at.many || parts.length === 2 && !ownTarget) {
|
|
21005
|
+
contract(
|
|
21006
|
+
`${tp}.at`,
|
|
21007
|
+
`"${rule.at}" must be a datetime field of ${name}, or <relation>.<field> on another of this extension's objects`
|
|
21008
|
+
);
|
|
21009
|
+
}
|
|
21010
|
+
if (rule.ifAnyIn) {
|
|
21011
|
+
if (parts.length !== 2) {
|
|
21012
|
+
contract(`${tp}.ifAnyIn`, "ifAnyIn needs at one relation away: the records it compares");
|
|
21047
21013
|
}
|
|
21048
|
-
|
|
21049
|
-
|
|
21050
|
-
|
|
21051
|
-
add(`${path2}.tag`, "A union's tag is a camelCase key");
|
|
21052
|
-
}
|
|
21053
|
-
if (!isObject2(value.variants) || !Object.keys(value.variants).length) {
|
|
21054
|
-
add(`${path2}.variants`, "A union has at least one variant");
|
|
21055
|
-
break;
|
|
21056
|
-
}
|
|
21057
|
-
for (const [name, variant] of Object.entries(value.variants)) {
|
|
21058
|
-
const vp = `${path2}.variants.${name}`;
|
|
21059
|
-
if (!name.length || name.length > 100) add(vp, "A variant's name is 1 to 100 characters");
|
|
21060
|
-
if (!isObject2(variant) || variant.type !== "object") {
|
|
21061
|
-
add(vp, "A variant is an object node");
|
|
21062
|
-
continue;
|
|
21063
|
-
}
|
|
21064
|
-
if (isObject2(variant.fields) && typeof value.tag === "string" && value.tag in variant.fields) {
|
|
21065
|
-
add(
|
|
21066
|
-
`${vp}.fields.${value.tag}`,
|
|
21067
|
-
"A variant does not declare its union's tag: the host does"
|
|
21068
|
-
);
|
|
21069
|
-
}
|
|
21070
|
-
node2(vp, variant, depth + 1, false);
|
|
21014
|
+
for (const state of rule.ifAnyIn) {
|
|
21015
|
+
if (!isState(state)) {
|
|
21016
|
+
contract(`${tp}.ifAnyIn`, `"${state}" is not an option of ${states.field}`);
|
|
21071
21017
|
}
|
|
21072
|
-
break;
|
|
21073
21018
|
}
|
|
21074
|
-
|
|
21075
|
-
|
|
21076
|
-
|
|
21077
|
-
|
|
21078
|
-
|
|
21079
|
-
|
|
21019
|
+
}
|
|
21020
|
+
});
|
|
21021
|
+
for (const [request, targets] of Object.entries(states.requests ?? {})) {
|
|
21022
|
+
const rp = `${sp}.requests.${request}`;
|
|
21023
|
+
if (isState(request)) contract(rp, `"${request}" is a state; a request needs its own name`);
|
|
21024
|
+
if (new Set(targets).size !== targets.length) contract(rp, "List each state once");
|
|
21025
|
+
for (const to of targets) {
|
|
21026
|
+
if (!isState(to)) contract(rp, `"${to}" is not an option of ${states.field}`);
|
|
21027
|
+
else if (!states.moves.some((move) => move.to === to)) {
|
|
21028
|
+
contract(rp, `No move goes to "${to}"`);
|
|
21080
21029
|
}
|
|
21081
|
-
default:
|
|
21082
|
-
add(
|
|
21083
|
-
`${path2}.type`,
|
|
21084
|
-
"type is one of object, array, text, number, boolean, choice, ref, union, use"
|
|
21085
|
-
);
|
|
21086
|
-
return;
|
|
21087
21030
|
}
|
|
21088
|
-
|
|
21089
|
-
|
|
21090
|
-
|
|
21031
|
+
}
|
|
21032
|
+
}
|
|
21033
|
+
function windowChecks(m, object3, name, contract) {
|
|
21034
|
+
const checkPath = (at, path2, type) => {
|
|
21035
|
+
const field = resolveFieldPath(m, object3, at);
|
|
21036
|
+
const formulaOk = type === "boolean" && field?.type === "formula";
|
|
21037
|
+
if (field?.type !== type && !formulaOk || field?.many) {
|
|
21038
|
+
contract(
|
|
21039
|
+
path2,
|
|
21040
|
+
`"${at}" must be a ${type} field of ${name}, or <relation>.<field> through up to two relations (one record each), every field on the way declared by this extension`
|
|
21041
|
+
);
|
|
21091
21042
|
}
|
|
21092
21043
|
};
|
|
21093
|
-
const
|
|
21094
|
-
if (
|
|
21095
|
-
|
|
21096
|
-
|
|
21097
|
-
|
|
21098
|
-
|
|
21099
|
-
|
|
21100
|
-
|
|
21101
|
-
|
|
21102
|
-
|
|
21103
|
-
}
|
|
21104
|
-
const priv = value.private;
|
|
21105
|
-
if (priv !== void 0 && priv !== true) {
|
|
21106
|
-
const unless = isObject2(priv) ? priv.unless : void 0;
|
|
21107
|
-
const flag = typeof unless === "string" ? value.fields[unless] : void 0;
|
|
21108
|
-
if (!isObject2(flag) || flag.type !== "boolean") {
|
|
21109
|
-
add(`${path2}.private`, "private is true, or { unless: <a boolean key of this object> }");
|
|
21044
|
+
const checkNumber = (value, path2) => {
|
|
21045
|
+
if (typeof value === "string") checkPath(value, path2, "number");
|
|
21046
|
+
else if (typeof value === "object") {
|
|
21047
|
+
if (value.field !== void 0) checkPath(value.field, `${path2}.field`, "number");
|
|
21048
|
+
if (value.setting !== void 0) {
|
|
21049
|
+
const settings = m.settings ?? {};
|
|
21050
|
+
const setting = Object.hasOwn(settings, value.setting) ? settings[value.setting] : void 0;
|
|
21051
|
+
if (setting?.type !== "number") {
|
|
21052
|
+
contract(`${path2}.setting`, `"${value.setting}" must be a number setting of ${m.id}`);
|
|
21053
|
+
}
|
|
21110
21054
|
}
|
|
21111
21055
|
}
|
|
21112
|
-
|
|
21113
|
-
|
|
21114
|
-
|
|
21115
|
-
|
|
21116
|
-
|
|
21117
|
-
|
|
21118
|
-
const flag = typeof unless === "string" ? fields[unless] : void 0;
|
|
21119
|
-
const badUnless = unless !== void 0 && (!isObject2(flag) || flag.type !== "boolean");
|
|
21120
|
-
const badKeys = keys2 !== void 0 && (!Array.isArray(keys2) || !keys2.length || keys2.some((k) => typeof k !== "string" || !Object.hasOwn(fields, k) || k === unless));
|
|
21121
|
-
const extra = shape ? Object.keys(shape).filter((k) => k !== "unless" && k !== "keys") : [];
|
|
21122
|
-
if (!shape || unless === void 0 && keys2 === void 0 || badUnless || badKeys || extra.length) {
|
|
21123
|
-
add(
|
|
21124
|
-
`${path2}.holders`,
|
|
21125
|
-
"holders is true, { unless: <a boolean key> } or { keys: [<keys of this object>], unless? }"
|
|
21126
|
-
);
|
|
21127
|
-
}
|
|
21056
|
+
};
|
|
21057
|
+
const checkBound = (bound, path2) => {
|
|
21058
|
+
const b = typeof bound === "string" ? { at: bound } : bound;
|
|
21059
|
+
checkPath(b.at, `${path2}.at`, "datetime");
|
|
21060
|
+
for (const key of ["daysBefore", "minutesBefore"]) {
|
|
21061
|
+
checkNumber(b[key], `${path2}.${key}`);
|
|
21128
21062
|
}
|
|
21063
|
+
if (b.zone !== void 0) checkPath(b.zone, `${path2}.zone`, "timezone");
|
|
21129
21064
|
};
|
|
21130
|
-
const
|
|
21131
|
-
|
|
21132
|
-
|
|
21133
|
-
|
|
21134
|
-
|
|
21135
|
-
seen.add(name);
|
|
21136
|
-
return resolve(defs[name], seen);
|
|
21065
|
+
const checkWindow = (window, path2) => {
|
|
21066
|
+
for (const end of ["from", "until"]) {
|
|
21067
|
+
const bound = window?.[end];
|
|
21068
|
+
if (bound !== void 0) checkBound(bound, `${path2}.${end}`);
|
|
21069
|
+
}
|
|
21137
21070
|
};
|
|
21138
|
-
|
|
21139
|
-
|
|
21140
|
-
|
|
21141
|
-
|
|
21142
|
-
|
|
21143
|
-
|
|
21144
|
-
|
|
21145
|
-
if (
|
|
21146
|
-
|
|
21071
|
+
return { checkPath, checkNumber, checkBound, checkWindow };
|
|
21072
|
+
}
|
|
21073
|
+
function resolveFieldPath(m, object3, path2) {
|
|
21074
|
+
const parts = path2.split(".");
|
|
21075
|
+
if (parts.length > 3) return void 0;
|
|
21076
|
+
const added = m.fields ?? {};
|
|
21077
|
+
const fieldsOn = (target) => {
|
|
21078
|
+
if (target === null) return object3.fields;
|
|
21079
|
+
if (target.startsWith(`${m.id}.`)) {
|
|
21080
|
+
const local = target.slice(m.id.length + 1);
|
|
21081
|
+
return Object.hasOwn(m.objects, local) ? m.objects[local]?.fields : void 0;
|
|
21082
|
+
}
|
|
21083
|
+
return Object.hasOwn(added, target) ? added[target] : void 0;
|
|
21084
|
+
};
|
|
21085
|
+
let on = null;
|
|
21086
|
+
for (const [i, part] of parts.entries()) {
|
|
21087
|
+
const fields = fieldsOn(on);
|
|
21088
|
+
const field = fields && Object.hasOwn(fields, part) ? fields[part] : void 0;
|
|
21089
|
+
if (!field) return void 0;
|
|
21090
|
+
if (i === parts.length - 1) return field;
|
|
21091
|
+
if (field.type !== "relation" || field.many || !field.to) return void 0;
|
|
21092
|
+
on = field.to.includes(".") ? field.to : `${m.id}.${field.to}`;
|
|
21147
21093
|
}
|
|
21148
|
-
return
|
|
21094
|
+
return void 0;
|
|
21149
21095
|
}
|
|
21150
|
-
|
|
21151
|
-
|
|
21152
|
-
|
|
21153
|
-
|
|
21096
|
+
|
|
21097
|
+
// ../sdk/src/capacity.ts
|
|
21098
|
+
var CAPACITY_SHOW = ["exact", "low", "availability"];
|
|
21099
|
+
var CAPACITY_VALUES = ["held", "taken", "available"];
|
|
21100
|
+
var fieldName4 = external_exports.string().max(40);
|
|
21101
|
+
var capacityManifestSchema = external_exports.object({
|
|
21102
|
+
places: fieldName4,
|
|
21103
|
+
pool: fieldName4.optional(),
|
|
21104
|
+
show: external_exports.enum(CAPACITY_SHOW).optional(),
|
|
21105
|
+
lowAt: external_exports.number().int().min(1).max(1e6).optional(),
|
|
21106
|
+
releaseOnRefund: external_exports.boolean().optional()
|
|
21107
|
+
}).strict();
|
|
21108
|
+
function checkObjectCapacity(m, name, object3, contract) {
|
|
21109
|
+
const capacity = object3.capacity;
|
|
21110
|
+
if (!capacity) return;
|
|
21111
|
+
const path2 = `objects.${name}.capacity`;
|
|
21112
|
+
const fieldOf = (local) => Object.hasOwn(object3.fields, local) ? object3.fields[local] : void 0;
|
|
21113
|
+
const places = fieldOf(capacity.places);
|
|
21114
|
+
if (places?.type !== "number" || places.many) {
|
|
21115
|
+
contract(`${path2}.places`, `"${capacity.places}" must be a number field of ${name}`);
|
|
21154
21116
|
}
|
|
21155
|
-
|
|
21156
|
-
|
|
21157
|
-
|
|
21158
|
-
|
|
21159
|
-
|
|
21160
|
-
|
|
21161
|
-
return `"${spec.path}" is in a part for holders only, which a column cannot keep from others`;
|
|
21117
|
+
for (const reserved of CAPACITY_VALUES) {
|
|
21118
|
+
if (Object.hasOwn(object3.fields, reserved)) {
|
|
21119
|
+
contract(
|
|
21120
|
+
`objects.${name}.fields.${reserved}`,
|
|
21121
|
+
`"${reserved}" is a value the host adds to an object with a capacity; rename the field`
|
|
21122
|
+
);
|
|
21162
21123
|
}
|
|
21163
|
-
current = at.fields[key];
|
|
21164
|
-
if (!current) return `"${spec.path}" is not in the schema (no "${key}")`;
|
|
21165
21124
|
}
|
|
21166
|
-
|
|
21167
|
-
|
|
21168
|
-
|
|
21125
|
+
if (capacity.pool !== void 0) {
|
|
21126
|
+
const pool = fieldOf(capacity.pool);
|
|
21127
|
+
const target = pool?.type === "relation" && !pool.many ? pool.to : void 0;
|
|
21128
|
+
const local = target?.startsWith(`${m.id}.`) ? target.slice(m.id.length + 1) : void 0;
|
|
21129
|
+
const targetObject = local !== void 0 && Object.hasOwn(m.objects, local) ? m.objects[local] : void 0;
|
|
21130
|
+
if (!targetObject) {
|
|
21131
|
+
contract(
|
|
21132
|
+
`${path2}.pool`,
|
|
21133
|
+
`"${capacity.pool}" must be a relation field (one record) to another of this extension's objects`
|
|
21134
|
+
);
|
|
21135
|
+
} else if (local === name) {
|
|
21136
|
+
contract(`${path2}.pool`, "An object cannot be its own pool");
|
|
21137
|
+
} else if (!targetObject.capacity) {
|
|
21138
|
+
contract(`${path2}.pool`, `The pool's object ${target} must declare a capacity`);
|
|
21139
|
+
} else if (targetObject.capacity.pool !== void 0) {
|
|
21140
|
+
contract(
|
|
21141
|
+
`${path2}.pool`,
|
|
21142
|
+
`The pool's object ${target} has a pool of its own; capacity has one level of pool`
|
|
21143
|
+
);
|
|
21144
|
+
}
|
|
21169
21145
|
}
|
|
21170
|
-
|
|
21171
|
-
|
|
21172
|
-
case "choice":
|
|
21173
|
-
return { type: "text" };
|
|
21174
|
-
case "number":
|
|
21175
|
-
return { type: "number" };
|
|
21176
|
-
case "boolean":
|
|
21177
|
-
return { type: "boolean" };
|
|
21178
|
-
case "ref":
|
|
21179
|
-
return { type: "id" };
|
|
21180
|
-
default:
|
|
21181
|
-
return `"${spec.path}" is not a text, number, boolean, choice or ref (use count for a list)`;
|
|
21146
|
+
if (capacity.lowAt !== void 0 && capacity.show !== "low") {
|
|
21147
|
+
contract(`${path2}.lowAt`, 'lowAt is the threshold of show: "low"');
|
|
21182
21148
|
}
|
|
21183
|
-
|
|
21184
|
-
|
|
21185
|
-
if (!path2.split(".").every((key) => KEY_RE.test(key)))
|
|
21186
|
-
throw new Error(`Bad document path ${path2}`);
|
|
21187
|
-
return `$.${path2}`;
|
|
21188
|
-
}
|
|
21189
|
-
function useOf(schema, node2) {
|
|
21190
|
-
let current = node2;
|
|
21191
|
-
for (let hops = 0; current?.type === "use" && hops < 20; hops += 1) {
|
|
21192
|
-
current = schema.defs?.[current.def];
|
|
21149
|
+
if (capacity.show === "low" && capacity.lowAt === void 0) {
|
|
21150
|
+
contract(`${path2}.lowAt`, 'show: "low" needs lowAt, the number at or below which it says so');
|
|
21193
21151
|
}
|
|
21194
|
-
return current?.type === "use" ? void 0 : current;
|
|
21195
21152
|
}
|
|
21196
|
-
|
|
21197
|
-
|
|
21198
|
-
|
|
21199
|
-
|
|
21200
|
-
|
|
21201
|
-
|
|
21202
|
-
|
|
21153
|
+
var waitlistManifestSchema = external_exports.object({
|
|
21154
|
+
state: external_exports.string().min(1).max(100),
|
|
21155
|
+
promote: external_exports.string().min(1).max(100),
|
|
21156
|
+
until: windowBoundSchema,
|
|
21157
|
+
promotedAt: fieldName4.optional(),
|
|
21158
|
+
passedOverAt: fieldName4.optional(),
|
|
21159
|
+
passedOverReason: fieldName4.optional()
|
|
21160
|
+
}).strict();
|
|
21161
|
+
var claimsManifestSchema = external_exports.object({
|
|
21162
|
+
on: fieldName4,
|
|
21163
|
+
held: external_exports.array(external_exports.string().min(1).max(100)).max(20).optional(),
|
|
21164
|
+
confirmed: external_exports.array(external_exports.string().min(1).max(100)).max(20).optional(),
|
|
21165
|
+
waitlist: waitlistManifestSchema.optional()
|
|
21166
|
+
}).strict();
|
|
21167
|
+
function checkObjectClaims(m, name, object3, contract) {
|
|
21168
|
+
const claims = object3.claims;
|
|
21169
|
+
if (!claims) return;
|
|
21170
|
+
const path2 = `objects.${name}.claims`;
|
|
21171
|
+
const on = Object.hasOwn(object3.fields, claims.on) ? object3.fields[claims.on] : void 0;
|
|
21172
|
+
const target = on?.type === "relation" && !on.many ? on.to : void 0;
|
|
21173
|
+
const local = target?.startsWith(`${m.id}.`) ? target.slice(m.id.length + 1) : void 0;
|
|
21174
|
+
const targetObject = local !== void 0 && Object.hasOwn(m.objects, local) ? m.objects[local] : void 0;
|
|
21175
|
+
if (!targetObject || local === name) {
|
|
21176
|
+
contract(
|
|
21177
|
+
`${path2}.on`,
|
|
21178
|
+
`"${claims.on}" must be a relation field (one record) to another of this extension's objects`
|
|
21179
|
+
);
|
|
21180
|
+
} else if (!targetObject.capacity) {
|
|
21181
|
+
contract(`${path2}.on`, `${target} must declare a capacity for its places to be claimed`);
|
|
21203
21182
|
}
|
|
21204
|
-
|
|
21205
|
-
|
|
21206
|
-
|
|
21207
|
-
|
|
21208
|
-
};
|
|
21183
|
+
const held = claims.held ?? [];
|
|
21184
|
+
const confirmed = claims.confirmed ?? [];
|
|
21185
|
+
if (!held.length && !confirmed.length) {
|
|
21186
|
+
contract(path2, "Name the states that hold a place (held) or take one (confirmed)");
|
|
21209
21187
|
}
|
|
21210
|
-
const
|
|
21211
|
-
|
|
21212
|
-
|
|
21213
|
-
|
|
21214
|
-
}
|
|
21215
|
-
const
|
|
21216
|
-
|
|
21217
|
-
|
|
21218
|
-
|
|
21219
|
-
|
|
21188
|
+
const states = object3.states;
|
|
21189
|
+
if (!states) {
|
|
21190
|
+
contract(path2, `${name} must declare states: its states hold and release the claim`);
|
|
21191
|
+
return;
|
|
21192
|
+
}
|
|
21193
|
+
const field = Object.hasOwn(object3.fields, states.field) ? object3.fields[states.field] : void 0;
|
|
21194
|
+
const values = new Set((field?.options ?? []).map((o) => o.value));
|
|
21195
|
+
for (const [key, list2] of [
|
|
21196
|
+
["held", held],
|
|
21197
|
+
["confirmed", confirmed]
|
|
21198
|
+
]) {
|
|
21199
|
+
if (new Set(list2).size !== list2.length) contract(`${path2}.${key}`, "List each state once");
|
|
21200
|
+
for (const state of list2) {
|
|
21201
|
+
if (!values.has(state)) contract(`${path2}.${key}`, `"${state}" is not a state of ${name}`);
|
|
21220
21202
|
}
|
|
21221
|
-
|
|
21222
|
-
|
|
21223
|
-
|
|
21224
|
-
|
|
21225
|
-
|
|
21226
|
-
|
|
21227
|
-
|
|
21228
|
-
|
|
21229
|
-
|
|
21230
|
-
|
|
21231
|
-
|
|
21232
|
-
|
|
21233
|
-
|
|
21234
|
-
|
|
21235
|
-
|
|
21236
|
-
|
|
21237
|
-
|
|
21238
|
-
|
|
21239
|
-
|
|
21240
|
-
|
|
21241
|
-
|
|
21242
|
-
|
|
21243
|
-
|
|
21244
|
-
|
|
21245
|
-
|
|
21246
|
-
|
|
21247
|
-
|
|
21248
|
-
|
|
21249
|
-
|
|
21250
|
-
|
|
21251
|
-
|
|
21252
|
-
|
|
21253
|
-
|
|
21254
|
-
|
|
21255
|
-
|
|
21256
|
-
|
|
21257
|
-
|
|
21258
|
-
|
|
21203
|
+
}
|
|
21204
|
+
const both = held.filter((state) => confirmed.includes(state));
|
|
21205
|
+
if (both.length) {
|
|
21206
|
+
contract(path2, `"${both[0]}" cannot both hold and take a place`);
|
|
21207
|
+
}
|
|
21208
|
+
states.moves.forEach((move, i) => {
|
|
21209
|
+
const from = typeof move.from === "string" ? [move.from] : move.from;
|
|
21210
|
+
if (held.includes(move.to) && from.some((state) => confirmed.includes(state))) {
|
|
21211
|
+
contract(
|
|
21212
|
+
`objects.${name}.states.moves.${i}`,
|
|
21213
|
+
`A move from a state that takes a place cannot go back to one that only holds it ("${move.to}")`
|
|
21214
|
+
);
|
|
21215
|
+
}
|
|
21216
|
+
});
|
|
21217
|
+
const waitlist = claims.waitlist;
|
|
21218
|
+
if (!waitlist) return;
|
|
21219
|
+
const wp = `${path2}.waitlist`;
|
|
21220
|
+
if (!values.has(waitlist.state)) {
|
|
21221
|
+
contract(`${wp}.state`, `"${waitlist.state}" is not a state of ${name}`);
|
|
21222
|
+
} else if (held.includes(waitlist.state) || confirmed.includes(waitlist.state)) {
|
|
21223
|
+
contract(`${wp}.state`, `"${waitlist.state}" waits: it can neither hold nor take a place`);
|
|
21224
|
+
} else if (states.moves.some((move) => move.final && move.to === waitlist.state)) {
|
|
21225
|
+
contract(`${wp}.state`, `"${waitlist.state}" is final: nobody waits in it`);
|
|
21226
|
+
} else if (states.initial !== waitlist.state && !Object.hasOwn(states.create?.in ?? {}, waitlist.state)) {
|
|
21227
|
+
contract(
|
|
21228
|
+
`${wp}.state`,
|
|
21229
|
+
`"${waitlist.state}" must be a state ${name} may be created in (states.create.in): a waiter joins by being made waiting`
|
|
21230
|
+
);
|
|
21231
|
+
}
|
|
21232
|
+
if (!confirmed.includes(waitlist.promote)) {
|
|
21233
|
+
contract(`${wp}.promote`, `"${waitlist.promote}" must be one of claims.confirmed`);
|
|
21234
|
+
}
|
|
21235
|
+
const promotions = states.moves.filter(
|
|
21236
|
+
(move) => move.to === waitlist.promote && moveOrigins(move).includes(waitlist.state)
|
|
21237
|
+
);
|
|
21238
|
+
if (!promotions.some((move) => move.by.includes("host"))) {
|
|
21239
|
+
contract(
|
|
21240
|
+
`${wp}.promote`,
|
|
21241
|
+
`Declare a move from "${waitlist.state}" to "${waitlist.promote}" by the host: promotion is the host's`
|
|
21242
|
+
);
|
|
21243
|
+
}
|
|
21244
|
+
promotions.forEach((move) => {
|
|
21245
|
+
if (move.by.includes("customer") && !move.window) {
|
|
21246
|
+
contract(
|
|
21247
|
+
`${wp}.promote`,
|
|
21248
|
+
`A customer's move from "${waitlist.state}" to "${waitlist.promote}" needs a window (the create's): it books them`
|
|
21249
|
+
);
|
|
21250
|
+
}
|
|
21251
|
+
});
|
|
21252
|
+
windowChecks(m, object3, name, contract).checkBound(waitlist.until, `${wp}.until`);
|
|
21253
|
+
for (const [key, type] of [
|
|
21254
|
+
["promotedAt", "datetime"],
|
|
21255
|
+
["passedOverAt", "datetime"],
|
|
21256
|
+
["passedOverReason", "text"]
|
|
21257
|
+
]) {
|
|
21258
|
+
const local2 = waitlist[key];
|
|
21259
|
+
if (local2 === void 0) continue;
|
|
21260
|
+
const field2 = Object.hasOwn(object3.fields, local2) ? object3.fields[local2] : void 0;
|
|
21261
|
+
if (field2?.type !== type || field2.many || !field2.readOnly) {
|
|
21262
|
+
contract(`${wp}.${key}`, `"${local2}" must be a read-only ${type} field of ${name}`);
|
|
21263
|
+
}
|
|
21264
|
+
}
|
|
21265
|
+
if (targetObject?.capacity?.pool !== void 0) {
|
|
21266
|
+
contract(`${wp}`, `A waitlist is on places with no pool; ${target} has one`);
|
|
21267
|
+
}
|
|
21268
|
+
}
|
|
21269
|
+
|
|
21270
|
+
// ../sdk/src/document.ts
|
|
21271
|
+
var DOCUMENT_MAX_BYTES = 524288;
|
|
21272
|
+
var DOCUMENT_DEFAULT_BYTES = 65536;
|
|
21273
|
+
var DOCUMENT_MAX_DEPTH = 24;
|
|
21274
|
+
var DOCUMENT_MAX_LIST = 1e3;
|
|
21275
|
+
var DOCUMENT_MAX_TEXT = 2e4;
|
|
21276
|
+
var DOCUMENT_DEFAULT_TEXT = 1e3;
|
|
21277
|
+
var DOCUMENT_MAX_ISSUES = 20;
|
|
21278
|
+
var DOCUMENT_MAX_PATHS = 12;
|
|
21279
|
+
var ID_RE = /^[a-z][a-z0-9]{0,9}_[A-Za-z0-9]{1,60}$/;
|
|
21280
|
+
var KEY_RE = /^[a-z][a-zA-Z0-9]{0,39}$/;
|
|
21281
|
+
var OBJECT_RE = /^[a-z][a-z0-9]*(\.[a-z][a-z0-9]*)?$/;
|
|
21282
|
+
var CONTROL_RE = /[\u0000-\u0008\u000b-\u001f\u007f]/;
|
|
21283
|
+
var MARKUP_RE = /<[A-Za-z!/?]|&(?:#[0-9]+|#[xX][0-9A-Fa-f]+|[A-Za-z][A-Za-z0-9]*);/;
|
|
21284
|
+
var URL_TAIL = "[^\\s<>\"'`\\\\]*";
|
|
21285
|
+
var WEB_RE = new RegExp(
|
|
21286
|
+
`^https?://[A-Za-z0-9](?:[A-Za-z0-9.-]*[A-Za-z0-9])?(?::[0-9]{1,5})?(?:[/?#]${URL_TAIL})?$`,
|
|
21287
|
+
"i"
|
|
21288
|
+
);
|
|
21289
|
+
var MAILTO_RE = /^mailto:[^\s<>"'`\\:/][^\s<>"'`\\]*$/i;
|
|
21290
|
+
var TEL_RE = /^tel:[+0-9 ().-]{3,40}$/i;
|
|
21291
|
+
var PATH_RE = new RegExp(`^/(?![/\\\\])${URL_TAIL}$`);
|
|
21292
|
+
var ANCHOR_RE = /^#[A-Za-z0-9_-]{1,100}$/;
|
|
21293
|
+
function isDocumentHref(value, kind) {
|
|
21294
|
+
if (WEB_RE.test(value)) return true;
|
|
21295
|
+
if (kind === "web") return false;
|
|
21296
|
+
return MAILTO_RE.test(value) || TEL_RE.test(value) || PATH_RE.test(value) || ANCHOR_RE.test(value);
|
|
21297
|
+
}
|
|
21298
|
+
function hasMarkup(value) {
|
|
21299
|
+
return MARKUP_RE.test(value);
|
|
21300
|
+
}
|
|
21301
|
+
var isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21302
|
+
function documentBytes(value) {
|
|
21303
|
+
const text = JSON.stringify(value) ?? "";
|
|
21304
|
+
let bytes = 0;
|
|
21305
|
+
for (const char of text) {
|
|
21306
|
+
const code = char.codePointAt(0) ?? 0;
|
|
21307
|
+
bytes += code < 128 ? 1 : code < 2048 ? 2 : code < 65536 ? 3 : 4;
|
|
21308
|
+
}
|
|
21309
|
+
return bytes;
|
|
21310
|
+
}
|
|
21311
|
+
function checkDocumentSchema(schema, knownObjects) {
|
|
21312
|
+
const problems = [];
|
|
21313
|
+
const add = (path2, message) => {
|
|
21314
|
+
if (problems.length < 50) problems.push([path2, message]);
|
|
21315
|
+
};
|
|
21316
|
+
if (!isObject2(schema)) {
|
|
21317
|
+
add("", "A document schema is an object with a `root` object node");
|
|
21318
|
+
return problems;
|
|
21319
|
+
}
|
|
21320
|
+
for (const key of Object.keys(schema)) {
|
|
21321
|
+
if (key !== "root" && key !== "defs") add(key, `Unknown key "${key}" (root, defs)`);
|
|
21322
|
+
}
|
|
21323
|
+
const defs = isObject2(schema.defs) ? schema.defs : {};
|
|
21324
|
+
if (schema.defs !== void 0 && !isObject2(schema.defs)) add("defs", "defs is an object");
|
|
21325
|
+
for (const name of Object.keys(defs)) {
|
|
21326
|
+
if (!KEY_RE.test(name)) add(`defs.${name}`, "A definition's name is camelCase");
|
|
21327
|
+
}
|
|
21328
|
+
const node2 = (path2, value, depth, inFields) => {
|
|
21329
|
+
if (depth > DOCUMENT_MAX_DEPTH) {
|
|
21330
|
+
add(path2, `The schema nests deeper than ${DOCUMENT_MAX_DEPTH}`);
|
|
21331
|
+
return;
|
|
21332
|
+
}
|
|
21333
|
+
if (!isObject2(value)) {
|
|
21334
|
+
add(path2, "A node is an object with a `type`");
|
|
21335
|
+
return;
|
|
21336
|
+
}
|
|
21337
|
+
const allowed = /* @__PURE__ */ new Set(["type", "description", "optional"]);
|
|
21338
|
+
const expect = (...keys) => {
|
|
21339
|
+
for (const key of keys) allowed.add(key);
|
|
21340
|
+
};
|
|
21341
|
+
if (value.optional !== void 0 && (typeof value.optional !== "boolean" || !inFields)) {
|
|
21342
|
+
add(`${path2}.optional`, "optional is true or false, on a field of an object");
|
|
21343
|
+
}
|
|
21344
|
+
if (value.description !== void 0 && typeof value.description !== "string") {
|
|
21345
|
+
add(`${path2}.description`, "description is text");
|
|
21346
|
+
}
|
|
21347
|
+
const num = (key, opts = {}) => {
|
|
21348
|
+
const v = value[key];
|
|
21349
|
+
if (v === void 0) return void 0;
|
|
21350
|
+
if (typeof v !== "number" || !Number.isFinite(v) || opts.int && !Number.isInteger(v)) {
|
|
21351
|
+
add(`${path2}.${key}`, `${key} is ${opts.int ? "a whole number" : "a number"}`);
|
|
21352
|
+
return void 0;
|
|
21353
|
+
}
|
|
21354
|
+
if (opts.min !== void 0 && v < opts.min)
|
|
21355
|
+
add(`${path2}.${key}`, `${key} is at least ${opts.min}`);
|
|
21356
|
+
if (opts.max !== void 0 && v > opts.max)
|
|
21357
|
+
add(`${path2}.${key}`, `${key} is at most ${opts.max}`);
|
|
21358
|
+
return v;
|
|
21359
|
+
};
|
|
21360
|
+
switch (value.type) {
|
|
21361
|
+
case "object": {
|
|
21362
|
+
expect("fields", "private", "holders");
|
|
21363
|
+
object3(path2, value, depth);
|
|
21364
|
+
break;
|
|
21365
|
+
}
|
|
21366
|
+
case "array": {
|
|
21367
|
+
expect("of", "max", "min", "unique", "uniqueAcross");
|
|
21368
|
+
if (value.uniqueAcross !== void 0 && (value.uniqueAcross !== true || !value.unique)) {
|
|
21369
|
+
add(`${path2}.uniqueAcross`, "uniqueAcross is true, beside unique");
|
|
21259
21370
|
}
|
|
21260
|
-
|
|
21261
|
-
|
|
21262
|
-
|
|
21263
|
-
|
|
21264
|
-
|
|
21265
|
-
|
|
21266
|
-
|
|
21267
|
-
|
|
21268
|
-
|
|
21269
|
-
|
|
21270
|
-
|
|
21271
|
-
|
|
21272
|
-
|
|
21273
|
-
|
|
21274
|
-
|
|
21275
|
-
);
|
|
21276
|
-
} else {
|
|
21277
|
-
seen.set(key, i);
|
|
21278
|
-
across?.set(key, [...path2, i].join("."));
|
|
21279
|
-
}
|
|
21371
|
+
const max = num("max", { int: true, min: 1, max: DOCUMENT_MAX_LIST });
|
|
21372
|
+
if (value.max === void 0) add(`${path2}.max`, "A list declares its most entries (max)");
|
|
21373
|
+
const min = num("min", { int: true, min: 0 });
|
|
21374
|
+
if (min !== void 0 && max !== void 0 && min > max)
|
|
21375
|
+
add(`${path2}.min`, "min is above max");
|
|
21376
|
+
node2(`${path2}.of`, value.of, depth + 1, false);
|
|
21377
|
+
if (value.unique !== void 0) {
|
|
21378
|
+
const of = resolve(value.of);
|
|
21379
|
+
const shapes = of?.type === "object" ? [of] : of?.type === "union" ? Object.values(of.variants ?? {}) : [];
|
|
21380
|
+
const keyNodes = shapes.map((shape) => resolve(shape.fields?.[String(value.unique)]));
|
|
21381
|
+
if (typeof value.unique !== "string" || !keyNodes.length || keyNodes.some((n) => !n || !["text", "number", "choice", "ref"].includes(n.type))) {
|
|
21382
|
+
add(
|
|
21383
|
+
`${path2}.unique`,
|
|
21384
|
+
"unique names a text, number, choice or ref key of the listed objects"
|
|
21385
|
+
);
|
|
21280
21386
|
}
|
|
21281
|
-
}
|
|
21282
|
-
|
|
21387
|
+
}
|
|
21388
|
+
break;
|
|
21283
21389
|
}
|
|
21284
21390
|
case "text": {
|
|
21285
|
-
|
|
21286
|
-
|
|
21287
|
-
|
|
21391
|
+
expect("max", "min", "multiline", "chars", "noMarkup", "href");
|
|
21392
|
+
if (value.noMarkup !== void 0 && typeof value.noMarkup !== "boolean") {
|
|
21393
|
+
add(`${path2}.noMarkup`, "noMarkup is true or false");
|
|
21288
21394
|
}
|
|
21289
|
-
|
|
21290
|
-
|
|
21291
|
-
if (node2.min !== void 0 && v.length < node2.min)
|
|
21292
|
-
fault(path2, `At least ${node2.min} characters`);
|
|
21293
|
-
if (CONTROL_RE.test(v)) fault(path2, "Control characters are not allowed");
|
|
21294
|
-
else if (!node2.multiline && /[\r\n]/.test(v)) fault(path2, "One line only");
|
|
21295
|
-
if (node2.chars) {
|
|
21296
|
-
const allowed = new Set(node2.chars);
|
|
21297
|
-
const bad = [...v].find((c) => !allowed.has(c));
|
|
21298
|
-
if (bad !== void 0) fault(path2, `"${bad}" is not allowed here (only ${node2.chars})`);
|
|
21395
|
+
if (value.href !== void 0 && value.href !== "web" && value.href !== "link") {
|
|
21396
|
+
add(`${path2}.href`, "href is web or link");
|
|
21299
21397
|
}
|
|
21300
|
-
|
|
21301
|
-
|
|
21398
|
+
const max = num("max", { int: true, min: 1, max: DOCUMENT_MAX_TEXT });
|
|
21399
|
+
const min = num("min", { int: true, min: 0 });
|
|
21400
|
+
if (min !== void 0 && (max ?? DOCUMENT_DEFAULT_TEXT) < min)
|
|
21401
|
+
add(`${path2}.min`, "min is above max");
|
|
21402
|
+
if (value.multiline !== void 0 && typeof value.multiline !== "boolean") {
|
|
21403
|
+
add(`${path2}.multiline`, "multiline is true or false");
|
|
21302
21404
|
}
|
|
21303
|
-
if (
|
|
21304
|
-
|
|
21305
|
-
path2,
|
|
21306
|
-
node2.href === "web" ? "Expected an http or https address" : "Expected an http, https, mailto or tel address, a path on the site or an anchor"
|
|
21307
|
-
);
|
|
21405
|
+
if (value.chars !== void 0 && (typeof value.chars !== "string" || !value.chars.length || value.chars.length > 200)) {
|
|
21406
|
+
add(`${path2}.chars`, "chars is the allowed characters, 1 to 200 of them");
|
|
21308
21407
|
}
|
|
21309
|
-
|
|
21408
|
+
break;
|
|
21310
21409
|
}
|
|
21311
21410
|
case "number": {
|
|
21312
|
-
|
|
21313
|
-
|
|
21314
|
-
|
|
21315
|
-
|
|
21316
|
-
|
|
21317
|
-
if (
|
|
21318
|
-
|
|
21319
|
-
if (node2.step !== void 0) {
|
|
21320
|
-
const steps = (v - (node2.min ?? 0)) / node2.step;
|
|
21321
|
-
if (Math.abs(steps - Math.round(steps)) > 1e-9) fault(path2, `In steps of ${node2.step}`);
|
|
21411
|
+
expect("min", "max", "integer", "step");
|
|
21412
|
+
const min = num("min");
|
|
21413
|
+
const max = num("max");
|
|
21414
|
+
if (min !== void 0 && max !== void 0 && min > max)
|
|
21415
|
+
add(`${path2}.min`, "min is above max");
|
|
21416
|
+
if (value.integer !== void 0 && typeof value.integer !== "boolean") {
|
|
21417
|
+
add(`${path2}.integer`, "integer is true or false");
|
|
21322
21418
|
}
|
|
21323
|
-
|
|
21419
|
+
const step = num("step");
|
|
21420
|
+
if (step !== void 0 && step <= 0) add(`${path2}.step`, "step is above 0");
|
|
21421
|
+
break;
|
|
21324
21422
|
}
|
|
21325
21423
|
case "boolean":
|
|
21326
|
-
|
|
21327
|
-
|
|
21328
|
-
|
|
21329
|
-
|
|
21330
|
-
|
|
21424
|
+
break;
|
|
21425
|
+
case "choice": {
|
|
21426
|
+
expect("options");
|
|
21427
|
+
const options = value.options;
|
|
21428
|
+
if (!Array.isArray(options) || !options.length || options.length > 100 || options.some((o) => typeof o !== "string" || !o.length || o.length > 100)) {
|
|
21429
|
+
add(`${path2}.options`, "A choice lists 1 to 100 words");
|
|
21430
|
+
} else if (new Set(options).size !== options.length) {
|
|
21431
|
+
add(`${path2}.options`, "A choice lists each word once");
|
|
21331
21432
|
}
|
|
21332
|
-
|
|
21333
|
-
|
|
21334
|
-
|
|
21335
|
-
|
|
21336
|
-
|
|
21337
|
-
|
|
21338
|
-
|
|
21339
|
-
|
|
21340
|
-
|
|
21433
|
+
break;
|
|
21434
|
+
}
|
|
21435
|
+
case "ref": {
|
|
21436
|
+
expect("to", "media");
|
|
21437
|
+
if (typeof value.to !== "string" || !OBJECT_RE.test(value.to)) {
|
|
21438
|
+
add(`${path2}.to`, "A ref names an object: `<extension>.<object>` or a core object");
|
|
21439
|
+
} else if (knownObjects && !knownObjects.has(value.to)) {
|
|
21440
|
+
add(`${path2}.to`, `Unknown object "${value.to}"`);
|
|
21441
|
+
}
|
|
21442
|
+
if (value.media !== void 0) {
|
|
21443
|
+
if (value.to !== "media") add(`${path2}.media`, "media is for a ref to media");
|
|
21444
|
+
else if (!["image", "video", "file"].includes(String(value.media))) {
|
|
21445
|
+
add(`${path2}.media`, "media is image, video or file");
|
|
21446
|
+
}
|
|
21447
|
+
}
|
|
21448
|
+
break;
|
|
21449
|
+
}
|
|
21450
|
+
case "union": {
|
|
21451
|
+
expect("tag", "variants");
|
|
21452
|
+
if (typeof value.tag !== "string" || !KEY_RE.test(value.tag)) {
|
|
21453
|
+
add(`${path2}.tag`, "A union's tag is a camelCase key");
|
|
21454
|
+
}
|
|
21455
|
+
if (!isObject2(value.variants) || !Object.keys(value.variants).length) {
|
|
21456
|
+
add(`${path2}.variants`, "A union has at least one variant");
|
|
21457
|
+
break;
|
|
21458
|
+
}
|
|
21459
|
+
for (const [name, variant] of Object.entries(value.variants)) {
|
|
21460
|
+
const vp = `${path2}.variants.${name}`;
|
|
21461
|
+
if (!name.length || name.length > 100) add(vp, "A variant's name is 1 to 100 characters");
|
|
21462
|
+
if (!isObject2(variant) || variant.type !== "object") {
|
|
21463
|
+
add(vp, "A variant is an object node");
|
|
21464
|
+
continue;
|
|
21465
|
+
}
|
|
21466
|
+
if (isObject2(variant.fields) && typeof value.tag === "string" && value.tag in variant.fields) {
|
|
21467
|
+
add(
|
|
21468
|
+
`${vp}.fields.${value.tag}`,
|
|
21469
|
+
"A variant does not declare its union's tag: the host does"
|
|
21470
|
+
);
|
|
21471
|
+
}
|
|
21472
|
+
node2(vp, variant, depth + 1, false);
|
|
21473
|
+
}
|
|
21474
|
+
break;
|
|
21475
|
+
}
|
|
21476
|
+
case "use": {
|
|
21477
|
+
expect("def");
|
|
21478
|
+
if (typeof value.def !== "string" || !Object.hasOwn(defs, value.def)) {
|
|
21479
|
+
add(`${path2}.def`, `"${String(value.def)}" is not one of the schema's defs`);
|
|
21480
|
+
}
|
|
21481
|
+
break;
|
|
21482
|
+
}
|
|
21483
|
+
default:
|
|
21484
|
+
add(
|
|
21485
|
+
`${path2}.type`,
|
|
21486
|
+
"type is one of object, array, text, number, boolean, choice, ref, union, use"
|
|
21487
|
+
);
|
|
21488
|
+
return;
|
|
21489
|
+
}
|
|
21490
|
+
for (const key of Object.keys(value)) {
|
|
21491
|
+
if (!allowed.has(key))
|
|
21492
|
+
add(`${path2}.${key}`, `Unknown key "${key}" on a ${String(value.type)} node`);
|
|
21493
|
+
}
|
|
21494
|
+
};
|
|
21495
|
+
const object3 = (path2, value, depth) => {
|
|
21496
|
+
if (!isObject2(value.fields)) {
|
|
21497
|
+
add(`${path2}.fields`, "An object node lists its fields");
|
|
21341
21498
|
return;
|
|
21342
21499
|
}
|
|
21343
|
-
|
|
21344
|
-
|
|
21345
|
-
|
|
21346
|
-
|
|
21500
|
+
const keys = Object.keys(value.fields);
|
|
21501
|
+
if (keys.length > 100) add(`${path2}.fields`, "An object has at most 100 fields");
|
|
21502
|
+
for (const key of keys) {
|
|
21503
|
+
if (!KEY_RE.test(key)) add(`${path2}.fields.${key}`, "A field's key is camelCase");
|
|
21504
|
+
node2(`${path2}.fields.${key}`, value.fields[key], depth + 1, true);
|
|
21505
|
+
}
|
|
21506
|
+
const priv = value.private;
|
|
21507
|
+
if (priv !== void 0 && priv !== true) {
|
|
21508
|
+
const unless = isObject2(priv) ? priv.unless : void 0;
|
|
21509
|
+
const flag = typeof unless === "string" ? value.fields[unless] : void 0;
|
|
21510
|
+
if (!isObject2(flag) || flag.type !== "boolean") {
|
|
21511
|
+
add(`${path2}.private`, "private is true, or { unless: <a boolean key of this object> }");
|
|
21347
21512
|
}
|
|
21348
21513
|
}
|
|
21349
|
-
|
|
21350
|
-
|
|
21351
|
-
|
|
21352
|
-
|
|
21514
|
+
const holders = value.holders;
|
|
21515
|
+
if (holders !== void 0 && holders !== true) {
|
|
21516
|
+
const fields = value.fields;
|
|
21517
|
+
const shape = isObject2(holders) ? holders : null;
|
|
21518
|
+
const unless = shape?.unless;
|
|
21519
|
+
const keys2 = shape?.keys;
|
|
21520
|
+
const flag = typeof unless === "string" ? fields[unless] : void 0;
|
|
21521
|
+
const badUnless = unless !== void 0 && (!isObject2(flag) || flag.type !== "boolean");
|
|
21522
|
+
const badKeys = keys2 !== void 0 && (!Array.isArray(keys2) || !keys2.length || keys2.some((k) => typeof k !== "string" || !Object.hasOwn(fields, k) || k === unless));
|
|
21523
|
+
const extra = shape ? Object.keys(shape).filter((k) => k !== "unless" && k !== "keys") : [];
|
|
21524
|
+
if (!shape || unless === void 0 && keys2 === void 0 || badUnless || badKeys || extra.length) {
|
|
21525
|
+
add(
|
|
21526
|
+
`${path2}.holders`,
|
|
21527
|
+
"holders is true, { unless: <a boolean key> } or { keys: [<keys of this object>], unless? }"
|
|
21528
|
+
);
|
|
21353
21529
|
}
|
|
21354
|
-
walk(child, v[key], [...path2, key], depth + 1);
|
|
21355
21530
|
}
|
|
21356
21531
|
};
|
|
21357
|
-
|
|
21358
|
-
|
|
21359
|
-
|
|
21360
|
-
|
|
21361
|
-
|
|
21532
|
+
const resolve = (value, seen = /* @__PURE__ */ new Set()) => {
|
|
21533
|
+
if (!isObject2(value)) return void 0;
|
|
21534
|
+
if (value.type !== "use") return value;
|
|
21535
|
+
const name = String(value.def);
|
|
21536
|
+
if (seen.has(name) || !Object.hasOwn(defs, name)) return void 0;
|
|
21537
|
+
seen.add(name);
|
|
21538
|
+
return resolve(defs[name], seen);
|
|
21539
|
+
};
|
|
21540
|
+
if (!isObject2(schema.root) || schema.root.type !== "object") {
|
|
21541
|
+
add("root", "root is an object node");
|
|
21542
|
+
} else {
|
|
21543
|
+
node2("root", schema.root, 0, false);
|
|
21544
|
+
}
|
|
21545
|
+
for (const [name, def] of Object.entries(defs)) node2(`defs.${name}`, def, 0, false);
|
|
21546
|
+
for (const name of Object.keys(defs)) {
|
|
21547
|
+
if (!resolve({ type: "use", def: name }))
|
|
21548
|
+
add(`defs.${name}`, "A definition must reach a node that is not `use`");
|
|
21549
|
+
}
|
|
21550
|
+
return problems;
|
|
21362
21551
|
}
|
|
21363
|
-
function
|
|
21364
|
-
const
|
|
21365
|
-
|
|
21366
|
-
|
|
21367
|
-
|
|
21552
|
+
function documentPathNode(schema, spec) {
|
|
21553
|
+
const keys = spec.path.split(".");
|
|
21554
|
+
if (!keys.length || keys.some((key) => !KEY_RE.test(key))) {
|
|
21555
|
+
return "A path is camelCase keys joined by dots, from the document's root";
|
|
21556
|
+
}
|
|
21557
|
+
let current = schema.root;
|
|
21558
|
+
for (const key of keys) {
|
|
21559
|
+
const at = useOf(schema, current);
|
|
21560
|
+
if (at?.type !== "object")
|
|
21561
|
+
return `"${spec.path}" passes through something that is not an object`;
|
|
21562
|
+
if (at.holders && (at.holders === true || !at.holders.keys || at.holders.keys.includes(key))) {
|
|
21563
|
+
return `"${spec.path}" is in a part for holders only, which a column cannot keep from others`;
|
|
21368
21564
|
}
|
|
21369
|
-
|
|
21370
|
-
|
|
21565
|
+
current = at.fields[key];
|
|
21566
|
+
if (!current) return `"${spec.path}" is not in the schema (no "${key}")`;
|
|
21567
|
+
}
|
|
21568
|
+
const end = useOf(schema, current);
|
|
21569
|
+
if (spec.count) {
|
|
21570
|
+
return end?.type === "array" ? { type: "number" } : `"${spec.path}" is not a list, so it has no count`;
|
|
21571
|
+
}
|
|
21572
|
+
switch (end?.type) {
|
|
21573
|
+
case "text":
|
|
21574
|
+
case "choice":
|
|
21575
|
+
return { type: "text" };
|
|
21576
|
+
case "number":
|
|
21577
|
+
return { type: "number" };
|
|
21578
|
+
case "boolean":
|
|
21579
|
+
return { type: "boolean" };
|
|
21580
|
+
case "ref":
|
|
21581
|
+
return { type: "id" };
|
|
21582
|
+
default:
|
|
21583
|
+
return `"${spec.path}" is not a text, number, boolean, choice or ref (use count for a list)`;
|
|
21584
|
+
}
|
|
21371
21585
|
}
|
|
21372
|
-
function
|
|
21373
|
-
|
|
21374
|
-
|
|
21375
|
-
|
|
21376
|
-
|
|
21377
|
-
|
|
21378
|
-
|
|
21379
|
-
for (
|
|
21380
|
-
|
|
21586
|
+
function documentJsonPath(path2) {
|
|
21587
|
+
if (!path2.split(".").every((key) => KEY_RE.test(key)))
|
|
21588
|
+
throw new Error(`Bad document path ${path2}`);
|
|
21589
|
+
return `$.${path2}`;
|
|
21590
|
+
}
|
|
21591
|
+
function useOf(schema, node2) {
|
|
21592
|
+
let current = node2;
|
|
21593
|
+
for (let hops = 0; current?.type === "use" && hops < 20; hops += 1) {
|
|
21594
|
+
current = schema.defs?.[current.def];
|
|
21381
21595
|
}
|
|
21382
|
-
return
|
|
21596
|
+
return current?.type === "use" ? void 0 : current;
|
|
21383
21597
|
}
|
|
21384
|
-
function
|
|
21385
|
-
const
|
|
21386
|
-
|
|
21387
|
-
|
|
21388
|
-
|
|
21389
|
-
|
|
21390
|
-
|
|
21598
|
+
function validateDocument(schema, value, options = {}) {
|
|
21599
|
+
const limit = Math.min(options.maxBytes ?? DOCUMENT_DEFAULT_BYTES, DOCUMENT_MAX_BYTES);
|
|
21600
|
+
let bytes;
|
|
21601
|
+
try {
|
|
21602
|
+
bytes = documentBytes(value);
|
|
21603
|
+
} catch {
|
|
21604
|
+
return { ok: false, issues: [{ path: [], message: "The document is not JSON" }] };
|
|
21605
|
+
}
|
|
21606
|
+
if (bytes > limit) {
|
|
21607
|
+
return {
|
|
21608
|
+
ok: false,
|
|
21609
|
+
issues: [{ path: [], message: `The document is ${bytes} bytes; at most ${limit}` }]
|
|
21610
|
+
};
|
|
21611
|
+
}
|
|
21612
|
+
const issues = [];
|
|
21613
|
+
const acrossLists = /* @__PURE__ */ new Map();
|
|
21614
|
+
const fault = (path2, message) => {
|
|
21615
|
+
if (issues.length < DOCUMENT_MAX_ISSUES) issues.push({ path: [...path2], message });
|
|
21616
|
+
};
|
|
21617
|
+
const walk = (node2, v, path2, depth) => {
|
|
21618
|
+
if (issues.length >= DOCUMENT_MAX_ISSUES) return;
|
|
21619
|
+
if (depth > DOCUMENT_MAX_DEPTH) {
|
|
21620
|
+
fault(path2, `Nested deeper than ${DOCUMENT_MAX_DEPTH}`);
|
|
21621
|
+
return;
|
|
21622
|
+
}
|
|
21623
|
+
switch (node2.type) {
|
|
21624
|
+
case "use": {
|
|
21625
|
+
const target = useOf(schema, node2);
|
|
21626
|
+
if (!target) fault(path2, `The schema's definition "${node2.def}" is missing`);
|
|
21627
|
+
else walk(target, v, path2, depth);
|
|
21628
|
+
return;
|
|
21629
|
+
}
|
|
21391
21630
|
case "object":
|
|
21631
|
+
objectValue(node2, v, path2, depth, null);
|
|
21632
|
+
return;
|
|
21392
21633
|
case "union": {
|
|
21393
|
-
if (!isObject2(v))
|
|
21394
|
-
|
|
21395
|
-
|
|
21396
|
-
if (shape.private) {
|
|
21397
|
-
const unless = shape.private === true ? null : shape.private.unless;
|
|
21398
|
-
if (!unless || v[unless] !== true) return { keep: false, value: null };
|
|
21634
|
+
if (!isObject2(v)) {
|
|
21635
|
+
fault(path2, `Expected an object with "${node2.tag}"`);
|
|
21636
|
+
return;
|
|
21399
21637
|
}
|
|
21400
|
-
|
|
21401
|
-
const
|
|
21402
|
-
if (
|
|
21403
|
-
|
|
21404
|
-
|
|
21405
|
-
if (!open2) {
|
|
21406
|
-
const keys = h === true ? void 0 : h.keys;
|
|
21407
|
-
if (!keys) return { keep: false, value: null };
|
|
21408
|
-
dropped = new Set(keys);
|
|
21409
|
-
}
|
|
21638
|
+
const tag = v[node2.tag];
|
|
21639
|
+
const variant = typeof tag === "string" && Object.hasOwn(node2.variants, tag) ? node2.variants[tag] : void 0;
|
|
21640
|
+
if (!variant) {
|
|
21641
|
+
fault([...path2, node2.tag], `Expected one of ${Object.keys(node2.variants).join(", ")}`);
|
|
21642
|
+
return;
|
|
21410
21643
|
}
|
|
21411
|
-
|
|
21412
|
-
|
|
21413
|
-
|
|
21414
|
-
|
|
21644
|
+
objectValue(variant, v, path2, depth, node2.tag);
|
|
21645
|
+
return;
|
|
21646
|
+
}
|
|
21647
|
+
case "array": {
|
|
21648
|
+
if (!Array.isArray(v)) {
|
|
21649
|
+
fault(path2, "Expected a list");
|
|
21650
|
+
return;
|
|
21651
|
+
}
|
|
21652
|
+
if (v.length > node2.max) fault(path2, `At most ${node2.max} entries (this has ${v.length})`);
|
|
21653
|
+
if (node2.min !== void 0 && v.length < node2.min) {
|
|
21654
|
+
fault(path2, `At least ${node2.min} ${node2.min === 1 ? "entry" : "entries"}`);
|
|
21655
|
+
}
|
|
21656
|
+
const seen = /* @__PURE__ */ new Map();
|
|
21657
|
+
let across = node2.uniqueAcross ? acrossLists.get(node2) : void 0;
|
|
21658
|
+
if (node2.uniqueAcross && !across) {
|
|
21659
|
+
across = /* @__PURE__ */ new Map();
|
|
21660
|
+
acrossLists.set(node2, across);
|
|
21661
|
+
}
|
|
21662
|
+
v.slice(0, node2.max).forEach((item, i) => {
|
|
21663
|
+
walk(node2.of, item, [...path2, i], depth + 1);
|
|
21664
|
+
if (node2.unique && isObject2(item) && item[node2.unique] !== void 0) {
|
|
21665
|
+
const key = JSON.stringify(item[node2.unique]);
|
|
21666
|
+
const first = seen.get(key);
|
|
21667
|
+
const elsewhere = across?.get(key);
|
|
21668
|
+
if (first !== void 0) {
|
|
21669
|
+
fault(
|
|
21670
|
+
[...path2, i, node2.unique],
|
|
21671
|
+
`${JSON.stringify(item[node2.unique])} is there twice (also entry ${first})`
|
|
21672
|
+
);
|
|
21673
|
+
} else if (elsewhere !== void 0) {
|
|
21674
|
+
fault(
|
|
21675
|
+
[...path2, i, node2.unique],
|
|
21676
|
+
`${JSON.stringify(item[node2.unique])} is used already (at ${elsewhere})`
|
|
21677
|
+
);
|
|
21678
|
+
} else {
|
|
21679
|
+
seen.set(key, i);
|
|
21680
|
+
across?.set(key, [...path2, i].join("."));
|
|
21681
|
+
}
|
|
21682
|
+
}
|
|
21683
|
+
});
|
|
21684
|
+
return;
|
|
21685
|
+
}
|
|
21686
|
+
case "text": {
|
|
21687
|
+
if (typeof v !== "string") {
|
|
21688
|
+
fault(path2, "Expected text");
|
|
21689
|
+
return;
|
|
21690
|
+
}
|
|
21691
|
+
const max = node2.max ?? DOCUMENT_DEFAULT_TEXT;
|
|
21692
|
+
if (v.length > max) fault(path2, `At most ${max} characters (this has ${v.length})`);
|
|
21693
|
+
if (node2.min !== void 0 && v.length < node2.min)
|
|
21694
|
+
fault(path2, `At least ${node2.min} characters`);
|
|
21695
|
+
if (CONTROL_RE.test(v)) fault(path2, "Control characters are not allowed");
|
|
21696
|
+
else if (!node2.multiline && /[\r\n]/.test(v)) fault(path2, "One line only");
|
|
21697
|
+
if (node2.chars) {
|
|
21698
|
+
const allowed = new Set(node2.chars);
|
|
21699
|
+
const bad = [...v].find((c) => !allowed.has(c));
|
|
21700
|
+
if (bad !== void 0) fault(path2, `"${bad}" is not allowed here (only ${node2.chars})`);
|
|
21701
|
+
}
|
|
21702
|
+
if (node2.noMarkup && MARKUP_RE.test(v)) {
|
|
21703
|
+
fault(path2, "Markup is not allowed: rich text is data, not HTML");
|
|
21704
|
+
}
|
|
21705
|
+
if (node2.href && !isDocumentHref(v, node2.href)) {
|
|
21706
|
+
fault(
|
|
21707
|
+
path2,
|
|
21708
|
+
node2.href === "web" ? "Expected an http or https address" : "Expected an http, https, mailto or tel address, a path on the site or an anchor"
|
|
21709
|
+
);
|
|
21710
|
+
}
|
|
21711
|
+
return;
|
|
21712
|
+
}
|
|
21713
|
+
case "number": {
|
|
21714
|
+
if (typeof v !== "number" || !Number.isFinite(v)) {
|
|
21715
|
+
fault(path2, "Expected a number");
|
|
21716
|
+
return;
|
|
21717
|
+
}
|
|
21718
|
+
if (node2.integer && !Number.isInteger(v)) fault(path2, "Expected a whole number");
|
|
21719
|
+
if (node2.min !== void 0 && v < node2.min) fault(path2, `At least ${node2.min}`);
|
|
21720
|
+
if (node2.max !== void 0 && v > node2.max) fault(path2, `At most ${node2.max}`);
|
|
21721
|
+
if (node2.step !== void 0) {
|
|
21722
|
+
const steps = (v - (node2.min ?? 0)) / node2.step;
|
|
21723
|
+
if (Math.abs(steps - Math.round(steps)) > 1e-9) fault(path2, `In steps of ${node2.step}`);
|
|
21724
|
+
}
|
|
21725
|
+
return;
|
|
21726
|
+
}
|
|
21727
|
+
case "boolean":
|
|
21728
|
+
if (typeof v !== "boolean") fault(path2, "Expected true or false");
|
|
21729
|
+
return;
|
|
21730
|
+
case "choice":
|
|
21731
|
+
if (typeof v !== "string" || !node2.options.includes(v)) {
|
|
21732
|
+
fault(path2, `Expected one of ${node2.options.join(", ")}`);
|
|
21733
|
+
}
|
|
21734
|
+
return;
|
|
21735
|
+
case "ref":
|
|
21736
|
+
if (typeof v !== "string" || !ID_RE.test(v)) fault(path2, `Expected the id of a ${node2.to}`);
|
|
21737
|
+
return;
|
|
21738
|
+
}
|
|
21739
|
+
};
|
|
21740
|
+
const objectValue = (node2, v, path2, depth, tag) => {
|
|
21741
|
+
if (!isObject2(v)) {
|
|
21742
|
+
fault(path2, "Expected an object");
|
|
21743
|
+
return;
|
|
21744
|
+
}
|
|
21745
|
+
for (const key of Object.keys(v)) {
|
|
21746
|
+
if (key === tag) continue;
|
|
21747
|
+
if (!Object.hasOwn(node2.fields, key)) {
|
|
21748
|
+
fault([...path2, key], `Unknown key "${key}"`);
|
|
21749
|
+
}
|
|
21750
|
+
}
|
|
21751
|
+
for (const [key, child] of Object.entries(node2.fields)) {
|
|
21752
|
+
if (!Object.hasOwn(v, key) || v[key] === void 0) {
|
|
21753
|
+
if (!child.optional) fault([...path2, key], "Required");
|
|
21754
|
+
continue;
|
|
21755
|
+
}
|
|
21756
|
+
walk(child, v[key], [...path2, key], depth + 1);
|
|
21757
|
+
}
|
|
21758
|
+
};
|
|
21759
|
+
walk(schema.root, value, [], 0);
|
|
21760
|
+
return issues.length ? { ok: false, issues } : { ok: true, value, bytes };
|
|
21761
|
+
}
|
|
21762
|
+
function formatDocumentIssue(issue2) {
|
|
21763
|
+
return issue2.path.length ? `${issue2.path.join(".")}: ${issue2.message}` : issue2.message;
|
|
21764
|
+
}
|
|
21765
|
+
function documentRefs(schema, value) {
|
|
21766
|
+
const refs = [];
|
|
21767
|
+
visit2(schema, value, (node2, v, path2) => {
|
|
21768
|
+
if (node2.type === "ref" && typeof v === "string") {
|
|
21769
|
+
refs.push({ to: node2.to, id: v, path: path2, ...node2.media ? { media: node2.media } : {} });
|
|
21770
|
+
}
|
|
21771
|
+
});
|
|
21772
|
+
return refs;
|
|
21773
|
+
}
|
|
21774
|
+
function documentMediaReach(schema, value, mediaObject = "media") {
|
|
21775
|
+
const ids = (v) => new Set(
|
|
21776
|
+
v === null || v === void 0 ? [] : documentRefs(schema, v).filter((r) => r.to === mediaObject).map((r) => r.id)
|
|
21777
|
+
);
|
|
21778
|
+
const everyone = ids(redactDocument(schema, value, { holder: false }));
|
|
21779
|
+
const holders = ids(redactDocument(schema, value, { holder: true }));
|
|
21780
|
+
const reach = /* @__PURE__ */ new Map();
|
|
21781
|
+
for (const id of ids(value)) {
|
|
21782
|
+
reach.set(id, everyone.has(id) ? "all" : holders.has(id) ? "holders" : "private");
|
|
21783
|
+
}
|
|
21784
|
+
return reach;
|
|
21785
|
+
}
|
|
21786
|
+
function redactDocument(schema, value, options = {}) {
|
|
21787
|
+
const holder = options.holder === true;
|
|
21788
|
+
if (value === null || value === void 0) return value ?? null;
|
|
21789
|
+
const strip = (node2, v, depth) => {
|
|
21790
|
+
const at = useOf(schema, node2);
|
|
21791
|
+
if (!at || depth > DOCUMENT_MAX_DEPTH) return { keep: false, value: null };
|
|
21792
|
+
switch (at.type) {
|
|
21793
|
+
case "object":
|
|
21794
|
+
case "union": {
|
|
21795
|
+
if (!isObject2(v)) return { keep: false, value: null };
|
|
21796
|
+
const shape = at.type === "object" ? at : at.variants[String(v[at.tag])];
|
|
21797
|
+
if (!shape) return { keep: false, value: null };
|
|
21798
|
+
if (shape.private) {
|
|
21799
|
+
const unless = shape.private === true ? null : shape.private.unless;
|
|
21800
|
+
if (!unless || v[unless] !== true) return { keep: false, value: null };
|
|
21801
|
+
}
|
|
21802
|
+
let dropped = null;
|
|
21803
|
+
const h = shape.holders;
|
|
21804
|
+
if (h && !holder) {
|
|
21805
|
+
const unless = h === true ? void 0 : h.unless;
|
|
21806
|
+
const open2 = unless !== void 0 && v[unless] === true;
|
|
21807
|
+
if (!open2) {
|
|
21808
|
+
const keys = h === true ? void 0 : h.keys;
|
|
21809
|
+
if (!keys) return { keep: false, value: null };
|
|
21810
|
+
dropped = new Set(keys);
|
|
21811
|
+
}
|
|
21812
|
+
}
|
|
21813
|
+
const out = {};
|
|
21814
|
+
if (at.type === "union") out[at.tag] = v[at.tag];
|
|
21815
|
+
for (const [key, child] of Object.entries(shape.fields)) {
|
|
21816
|
+
if (!Object.hasOwn(v, key) || dropped?.has(key)) continue;
|
|
21415
21817
|
const kept = strip(child, v[key], depth + 1);
|
|
21416
21818
|
if (kept.keep) out[key] = kept.value;
|
|
21417
21819
|
}
|
|
@@ -22504,30 +22906,30 @@ function checkFormula(expression, env, self) {
|
|
|
22504
22906
|
var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
22505
22907
|
var RECURRING_HORIZON_DAYS = 56;
|
|
22506
22908
|
var RECURRING_HORIZON_MAX = 366;
|
|
22507
|
-
var
|
|
22909
|
+
var fieldName5 = external_exports.string().max(40);
|
|
22508
22910
|
var recurringManifestSchema = external_exports.object({
|
|
22509
|
-
generates:
|
|
22510
|
-
link:
|
|
22911
|
+
generates: fieldName5,
|
|
22912
|
+
link: fieldName5,
|
|
22511
22913
|
rule: external_exports.object({
|
|
22512
|
-
weekdays:
|
|
22513
|
-
time:
|
|
22514
|
-
length:
|
|
22515
|
-
from:
|
|
22516
|
-
until:
|
|
22517
|
-
zone:
|
|
22914
|
+
weekdays: fieldName5,
|
|
22915
|
+
time: fieldName5,
|
|
22916
|
+
length: fieldName5.optional(),
|
|
22917
|
+
from: fieldName5,
|
|
22918
|
+
until: fieldName5.optional(),
|
|
22919
|
+
zone: fieldName5.optional()
|
|
22518
22920
|
}).strict(),
|
|
22519
22921
|
into: external_exports.object({
|
|
22520
|
-
starts:
|
|
22521
|
-
ends:
|
|
22522
|
-
zone:
|
|
22523
|
-
changed:
|
|
22922
|
+
starts: fieldName5,
|
|
22923
|
+
ends: fieldName5.optional(),
|
|
22924
|
+
zone: fieldName5.optional(),
|
|
22925
|
+
changed: fieldName5.optional()
|
|
22524
22926
|
}).strict(),
|
|
22525
|
-
copy: external_exports.record(
|
|
22927
|
+
copy: external_exports.record(fieldName5, fieldName5).refine((copy) => Object.keys(copy).length <= 20, "At most 20 copied fields").optional(),
|
|
22526
22928
|
cancel: external_exports.string().min(1).max(100),
|
|
22527
|
-
ended: external_exports.object({ field:
|
|
22528
|
-
closures: external_exports.object({ object:
|
|
22929
|
+
ended: external_exports.object({ field: fieldName5, in: external_exports.array(external_exports.string().min(1).max(100)).min(1).max(20) }).strict().optional(),
|
|
22930
|
+
closures: external_exports.object({ object: fieldName5, from: fieldName5, until: fieldName5 }).strict().optional(),
|
|
22529
22931
|
horizonDays: external_exports.number().int().min(1).max(RECURRING_HORIZON_MAX).optional(),
|
|
22530
|
-
horizonAtLeast: external_exports.object({ object:
|
|
22932
|
+
horizonAtLeast: external_exports.object({ object: fieldName5, field: fieldName5 }).strict().optional()
|
|
22531
22933
|
}).strict();
|
|
22532
22934
|
function checkObjectRecurring(m, name, object3, contract) {
|
|
22533
22935
|
const recurring = object3.recurring;
|
|
@@ -22646,386 +23048,109 @@ function checkObjectRecurring(m, name, object3, contract) {
|
|
|
22646
23048
|
const from = own2(object3, source);
|
|
22647
23049
|
if (!to || to.type === "formula" || into.has(target) || target === recurring.link) {
|
|
22648
23050
|
contract(
|
|
22649
|
-
`${path2}.copy.${target}`,
|
|
22650
|
-
`"${target}" must be a field of ${generatedName} the host does not already fill`
|
|
22651
|
-
);
|
|
22652
|
-
} else if (!from || from.type !== to.type || Boolean(from.many) !== Boolean(to.many) || from.to !== to.to) {
|
|
22653
|
-
contract(
|
|
22654
|
-
`${path2}.copy.${target}`,
|
|
22655
|
-
`"${source}" must be a field of ${name} of the same type as ${generatedName}.${target}`
|
|
22656
|
-
);
|
|
22657
|
-
}
|
|
22658
|
-
}
|
|
22659
|
-
const states = generated.states;
|
|
22660
|
-
if (!states) {
|
|
22661
|
-
contract(
|
|
22662
|
-
`${path2}.cancel`,
|
|
22663
|
-
`${generatedName} must declare states, with a host move into "${recurring.cancel}"`
|
|
22664
|
-
);
|
|
22665
|
-
} else {
|
|
22666
|
-
const field = own2(generated, states.field);
|
|
22667
|
-
if (!(field?.options ?? []).some((o) => o.value === recurring.cancel)) {
|
|
22668
|
-
contract(`${path2}.cancel`, `"${recurring.cancel}" is not a state of ${generatedName}`);
|
|
22669
|
-
} else if (!states.moves.some((move) => move.to === recurring.cancel && move.by.includes("host"))) {
|
|
22670
|
-
contract(
|
|
22671
|
-
`${path2}.cancel`,
|
|
22672
|
-
`${generatedName} needs a move into "${recurring.cancel}" that the host may make`
|
|
22673
|
-
);
|
|
22674
|
-
}
|
|
22675
|
-
}
|
|
22676
|
-
if (recurring.horizonAtLeast) {
|
|
22677
|
-
const h = recurring.horizonAtLeast;
|
|
22678
|
-
const added = h.object.includes(".") ? m.fields?.[h.object] : void 0;
|
|
22679
|
-
const target = added ? { fields: added } : Object.hasOwn(m.objects, h.object) ? m.objects[h.object] : void 0;
|
|
22680
|
-
if (!target) {
|
|
22681
|
-
contract(
|
|
22682
|
-
`${path2}.horizonAtLeast.object`,
|
|
22683
|
-
`"${h.object}" must be one of this extension's objects, or an object this extension adds fields to`
|
|
22684
|
-
);
|
|
22685
|
-
} else {
|
|
22686
|
-
expect(
|
|
22687
|
-
target,
|
|
22688
|
-
h.object,
|
|
22689
|
-
`${path2}.horizonAtLeast.field`,
|
|
22690
|
-
h.field,
|
|
22691
|
-
["number"],
|
|
22692
|
-
"a number field (days)"
|
|
22693
|
-
);
|
|
22694
|
-
}
|
|
22695
|
-
}
|
|
22696
|
-
if (recurring.closures) {
|
|
22697
|
-
const c = recurring.closures;
|
|
22698
|
-
const closure = Object.hasOwn(m.objects, c.object) ? m.objects[c.object] : void 0;
|
|
22699
|
-
if (!closure || c.object === name || c.object === generatedName) {
|
|
22700
|
-
contract(
|
|
22701
|
-
`${path2}.closures.object`,
|
|
22702
|
-
`"${c.object}" must be another of this extension's objects`
|
|
22703
|
-
);
|
|
22704
|
-
} else {
|
|
22705
|
-
expect(closure, c.object, `${path2}.closures.from`, c.from, ["date"], "a date field");
|
|
22706
|
-
expect(closure, c.object, `${path2}.closures.until`, c.until, ["date"], "a date field");
|
|
22707
|
-
}
|
|
22708
|
-
}
|
|
22709
|
-
}
|
|
22710
|
-
|
|
22711
|
-
// ../sdk/src/renamed.ts
|
|
22712
|
-
var OLD_PREFIX = "crm";
|
|
22713
|
-
var OPS_MODULE = "ops";
|
|
22714
|
-
var OLD_OPS_MODULE = OLD_PREFIX;
|
|
22715
|
-
var OPS_SPECIFIER = `codemode:${OPS_MODULE}`;
|
|
22716
|
-
var OLD_OPS_SPECIFIER = `codemode:${OLD_OPS_MODULE}`;
|
|
22717
|
-
var VIEW_PREFIX = "rec_";
|
|
22718
|
-
var OLD_VIEW_PREFIX = `${OLD_PREFIX}_`;
|
|
22719
|
-
var RENAMED_CORE_VIEWS = {
|
|
22720
|
-
people: "person",
|
|
22721
|
-
organisations: "organisation",
|
|
22722
|
-
affiliations: "affiliation",
|
|
22723
|
-
activities: "activity",
|
|
22724
|
-
activity_links: "activity_link",
|
|
22725
|
-
tasks: "task",
|
|
22726
|
-
task_links: "task_link",
|
|
22727
|
-
record_tags: "record_tag",
|
|
22728
|
-
users: "user",
|
|
22729
|
-
stage_history: "stage_history"
|
|
22730
|
-
};
|
|
22731
|
-
function renamedView(name) {
|
|
22732
|
-
const lower = name.toLowerCase();
|
|
22733
|
-
if (!lower.startsWith(OLD_VIEW_PREFIX)) return null;
|
|
22734
|
-
const suffix = lower.slice(OLD_VIEW_PREFIX.length);
|
|
22735
|
-
if (suffix.startsWith("x_")) return `${VIEW_PREFIX}${suffix}`;
|
|
22736
|
-
const core = RENAMED_CORE_VIEWS[suffix];
|
|
22737
|
-
return core ? `${VIEW_PREFIX}${core}` : null;
|
|
22738
|
-
}
|
|
22739
|
-
function renamedMessage(name) {
|
|
22740
|
-
if (name === OLD_OPS_SPECIFIER) {
|
|
22741
|
-
return `"${OLD_OPS_SPECIFIER}" was renamed: import { ${OPS_MODULE} } from "${OPS_SPECIFIER}" and call ${OPS_MODULE}.call(\u2026)`;
|
|
22742
|
-
}
|
|
22743
|
-
if (name === OLD_OPS_MODULE) {
|
|
22744
|
-
return `The "${OLD_OPS_MODULE}" module was renamed "${OPS_MODULE}": declare "${OPS_MODULE}" in permissions.modules and call ctx.${OPS_MODULE}`;
|
|
22745
|
-
}
|
|
22746
|
-
const view = renamedView(name);
|
|
22747
|
-
if (view) return `${name} was renamed ${view}; query the ${VIEW_PREFIX}* views`;
|
|
22748
|
-
if (name.toLowerCase().startsWith(OLD_VIEW_PREFIX)) {
|
|
22749
|
-
return `${name} is not a view: the ${OLD_VIEW_PREFIX}* views were renamed ${VIEW_PREFIX}*`;
|
|
22750
|
-
}
|
|
22751
|
-
return null;
|
|
22752
|
-
}
|
|
22753
|
-
|
|
22754
|
-
// ../sdk/src/states.ts
|
|
22755
|
-
var MOVERS = ["staff", "customer", "host"];
|
|
22756
|
-
var fieldName5 = external_exports.string().max(40);
|
|
22757
|
-
var stateValue2 = external_exports.string().min(1).max(100);
|
|
22758
|
-
var fieldPath = external_exports.string().min(1).max(122);
|
|
22759
|
-
var windowNumber = (number4) => external_exports.union([
|
|
22760
|
-
number4,
|
|
22761
|
-
fieldPath,
|
|
22762
|
-
external_exports.object({ field: fieldPath.optional(), setting: external_exports.string().min(1).max(40).optional() }).strict().refine((n) => n.field !== void 0 || n.setting !== void 0, "Name a field or a setting")
|
|
22763
|
-
]);
|
|
22764
|
-
var windowBound = external_exports.union([
|
|
22765
|
-
fieldPath,
|
|
22766
|
-
external_exports.object({
|
|
22767
|
-
at: fieldPath,
|
|
22768
|
-
daysBefore: windowNumber(external_exports.number().int().min(-366).max(366)).optional(),
|
|
22769
|
-
minutesBefore: windowNumber(external_exports.number().int().min(-527040).max(527040)).optional(),
|
|
22770
|
-
zone: fieldPath.optional()
|
|
22771
|
-
}).strict()
|
|
22772
|
-
]);
|
|
22773
|
-
var staffOnlyPaths = external_exports.union([fieldPath, external_exports.array(fieldPath).min(1).max(4)]);
|
|
22774
|
-
var moveWindow = external_exports.object({ from: windowBound.optional(), until: windowBound.optional() }).strict().refine((w) => w.from !== void 0 || w.until !== void 0, "A window needs from or until");
|
|
22775
|
-
var statesManifestSchema = external_exports.object({
|
|
22776
|
-
field: fieldName5,
|
|
22777
|
-
initial: stateValue2,
|
|
22778
|
-
moves: external_exports.array(
|
|
22779
|
-
external_exports.object({
|
|
22780
|
-
from: external_exports.union([stateValue2, external_exports.array(stateValue2).min(1).max(50)]),
|
|
22781
|
-
to: stateValue2,
|
|
22782
|
-
by: external_exports.array(external_exports.enum(MOVERS)).min(1).max(MOVERS.length),
|
|
22783
|
-
requires: external_exports.array(fieldName5).max(50).optional(),
|
|
22784
|
-
final: external_exports.boolean().optional(),
|
|
22785
|
-
window: moveWindow.optional(),
|
|
22786
|
-
staffOnly: staffOnlyPaths.optional(),
|
|
22787
|
-
tools: external_exports.array(external_exports.string().min(1).max(40)).min(1).max(10).optional(),
|
|
22788
|
-
bindsStaff: external_exports.boolean().optional()
|
|
22789
|
-
})
|
|
22790
|
-
).max(200),
|
|
22791
|
-
create: external_exports.object({
|
|
22792
|
-
in: external_exports.record(stateValue2, external_exports.array(external_exports.enum(MOVERS)).min(1).max(MOVERS.length)).refine((r) => Object.keys(r).length <= 20, "At most 20 states").optional(),
|
|
22793
|
-
window: moveWindow.optional(),
|
|
22794
|
-
staffOnly: staffOnlyPaths.optional(),
|
|
22795
|
-
closed: staffOnlyPaths.optional()
|
|
22796
|
-
}).strict().optional(),
|
|
22797
|
-
requests: external_exports.record(external_exports.string().regex(/^[a-z][a-z0-9_]{0,39}$/), external_exports.array(stateValue2).min(1).max(10)).refine((r) => Object.keys(r).length <= 10, "At most 10 requests").optional(),
|
|
22798
|
-
follows: external_exports.object({
|
|
22799
|
-
relation: fieldName5,
|
|
22800
|
-
when: external_exports.record(stateValue2, stateValue2).refine((r) => Object.keys(r).length >= 1 && Object.keys(r).length <= 10, "1 to 10 states"),
|
|
22801
|
-
from: external_exports.array(stateValue2).min(1).max(20)
|
|
22802
|
-
}).strict().optional()
|
|
22803
|
-
});
|
|
22804
|
-
function staffOnlyPathsOf(value) {
|
|
22805
|
-
return value === void 0 ? [] : typeof value === "string" ? [value] : value;
|
|
22806
|
-
}
|
|
22807
|
-
function moveOrigins(move) {
|
|
22808
|
-
return typeof move.from === "string" ? [move.from] : move.from;
|
|
22809
|
-
}
|
|
22810
|
-
function checkObjectStates(m, name, object3, contract) {
|
|
22811
|
-
const states = object3.states;
|
|
22812
|
-
if (!states) return;
|
|
22813
|
-
const sp = `objects.${name}.states`;
|
|
22814
|
-
if (object3.stages) {
|
|
22815
|
-
contract(sp, "An object has one lifecycle: declare stages or states, not both");
|
|
22816
|
-
}
|
|
22817
|
-
const fieldOf = (local) => Object.hasOwn(object3.fields, local) ? object3.fields[local] : void 0;
|
|
22818
|
-
const field = fieldOf(states.field);
|
|
22819
|
-
if (field?.type !== "select") {
|
|
22820
|
-
contract(`${sp}.field`, `"${states.field}" must be a select field of ${name}`);
|
|
22821
|
-
return;
|
|
22822
|
-
}
|
|
22823
|
-
if (field.readOnly) {
|
|
22824
|
-
contract(`${sp}.field`, "The state field cannot be read-only: the moves say who may change it");
|
|
22825
|
-
}
|
|
22826
|
-
if (field.editableOptions) {
|
|
22827
|
-
contract(
|
|
22828
|
-
`${sp}.field`,
|
|
22829
|
-
"The state field cannot have editableOptions: states are fixed in the declaration"
|
|
22830
|
-
);
|
|
22831
|
-
}
|
|
22832
|
-
const values = new Set((field.options ?? []).map((o) => o.value));
|
|
22833
|
-
const isState = (value) => values.has(value);
|
|
22834
|
-
if (!isState(states.initial)) {
|
|
22835
|
-
contract(`${sp}.initial`, `"${states.initial}" is not an option of ${states.field}`);
|
|
22836
|
-
}
|
|
22837
|
-
if (field.default !== void 0 && field.default !== states.initial) {
|
|
22838
|
-
contract(
|
|
22839
|
-
`${sp}.initial`,
|
|
22840
|
-
`${states.field}'s default must be the initial state "${states.initial}", or be left out`
|
|
22841
|
-
);
|
|
22842
|
-
}
|
|
22843
|
-
const seen = /* @__PURE__ */ new Set();
|
|
22844
|
-
const finals = new Set(states.moves.filter((move) => move.final).map((move) => move.to));
|
|
22845
|
-
states.moves.forEach((move, i) => {
|
|
22846
|
-
const mp = `${sp}.moves.${i}`;
|
|
22847
|
-
if (!isState(move.to)) contract(`${mp}.to`, `"${move.to}" is not an option of ${states.field}`);
|
|
22848
|
-
if (new Set(move.by).size !== move.by.length) contract(`${mp}.by`, "List each mover once");
|
|
22849
|
-
if (finals.has(move.to) && !move.final) {
|
|
22850
|
-
contract(
|
|
22851
|
-
`${mp}.final`,
|
|
22852
|
-
`Another move into "${move.to}" is final; every move into a state must agree`
|
|
22853
|
-
);
|
|
22854
|
-
}
|
|
22855
|
-
if (move.final && move.to === states.initial) {
|
|
22856
|
-
contract(`${mp}.final`, "The initial state cannot be final");
|
|
22857
|
-
}
|
|
22858
|
-
for (const from of moveOrigins(move)) {
|
|
22859
|
-
if (!isState(from)) {
|
|
22860
|
-
contract(`${mp}.from`, `"${from}" is not an option of ${states.field}`);
|
|
22861
|
-
}
|
|
22862
|
-
if (from === move.to) contract(`${mp}.from`, `A move cannot go from "${from}" to itself`);
|
|
22863
|
-
if (finals.has(from)) {
|
|
22864
|
-
contract(`${mp}.from`, `"${from}" is final: nothing moves out of it`);
|
|
22865
|
-
}
|
|
22866
|
-
const key = JSON.stringify([from, move.to]);
|
|
22867
|
-
if (seen.has(key)) {
|
|
22868
|
-
contract(mp, `The move from "${from}" to "${move.to}" is declared twice`);
|
|
22869
|
-
}
|
|
22870
|
-
seen.add(key);
|
|
22871
|
-
}
|
|
22872
|
-
for (const local of move.requires ?? []) {
|
|
22873
|
-
const required2 = fieldOf(local);
|
|
22874
|
-
if (!required2 || required2.type === "formula" || local === states.field) {
|
|
22875
|
-
contract(
|
|
22876
|
-
`${mp}.requires`,
|
|
22877
|
-
`"${local}" must be a field of ${name} other than a formula or the state field`
|
|
22878
|
-
);
|
|
22879
|
-
} else if (required2.readOnly && move.by.some((mover) => mover !== "host")) {
|
|
22880
|
-
contract(
|
|
22881
|
-
`${mp}.requires`,
|
|
22882
|
-
`"${local}" is read-only, so only a move made by the host alone can require it`
|
|
22883
|
-
);
|
|
22884
|
-
}
|
|
22885
|
-
}
|
|
22886
|
-
});
|
|
22887
|
-
const checkPath = (at, path2, type) => {
|
|
22888
|
-
const field2 = resolveFieldPath(m, object3, at);
|
|
22889
|
-
const formulaOk = type === "boolean" && field2?.type === "formula";
|
|
22890
|
-
if (field2?.type !== type && !formulaOk || field2?.many) {
|
|
22891
|
-
contract(
|
|
22892
|
-
path2,
|
|
22893
|
-
`"${at}" must be a ${type} field of ${name}, or <relation>.<field> through up to two relations (one record each), every field on the way declared by this extension`
|
|
22894
|
-
);
|
|
22895
|
-
}
|
|
22896
|
-
};
|
|
22897
|
-
const checkNumber = (value, path2) => {
|
|
22898
|
-
if (typeof value === "string") checkPath(value, path2, "number");
|
|
22899
|
-
else if (typeof value === "object") {
|
|
22900
|
-
if (value.field !== void 0) checkPath(value.field, `${path2}.field`, "number");
|
|
22901
|
-
if (value.setting !== void 0) {
|
|
22902
|
-
const settings = m.settings ?? {};
|
|
22903
|
-
const setting = Object.hasOwn(settings, value.setting) ? settings[value.setting] : void 0;
|
|
22904
|
-
if (setting?.type !== "number") {
|
|
22905
|
-
contract(`${path2}.setting`, `"${value.setting}" must be a number setting of ${m.id}`);
|
|
22906
|
-
}
|
|
22907
|
-
}
|
|
22908
|
-
}
|
|
22909
|
-
};
|
|
22910
|
-
const checkWindow = (window, path2) => {
|
|
22911
|
-
for (const end of ["from", "until"]) {
|
|
22912
|
-
const bound = window?.[end];
|
|
22913
|
-
if (bound === void 0) continue;
|
|
22914
|
-
const b = typeof bound === "string" ? { at: bound } : bound;
|
|
22915
|
-
checkPath(b.at, `${path2}.${end}.at`, "datetime");
|
|
22916
|
-
for (const key of ["daysBefore", "minutesBefore"]) {
|
|
22917
|
-
checkNumber(b[key], `${path2}.${end}.${key}`);
|
|
22918
|
-
}
|
|
22919
|
-
if (b.zone !== void 0) checkPath(b.zone, `${path2}.${end}.zone`, "timezone");
|
|
22920
|
-
}
|
|
22921
|
-
};
|
|
22922
|
-
states.moves.forEach((move, i) => {
|
|
22923
|
-
const mp = `${sp}.moves.${i}`;
|
|
22924
|
-
if ((move.window || move.staffOnly) && !move.by.includes("customer")) {
|
|
22925
|
-
contract(mp, "A window or staffOnly binds customers: the move must list customer in by");
|
|
22926
|
-
}
|
|
22927
|
-
checkWindow(move.window, `${mp}.window`);
|
|
22928
|
-
for (const p of staffOnlyPathsOf(move.staffOnly)) checkPath(p, `${mp}.staffOnly`, "boolean");
|
|
22929
|
-
for (const tool of move.tools ?? []) {
|
|
22930
|
-
const spec = m.tools?.[tool];
|
|
22931
|
-
if (!spec) {
|
|
22932
|
-
contract(`${mp}.tools`, `"${tool}" is not a tool of this extension`);
|
|
22933
|
-
} else if (!spec.humanOnly || !spec.permission) {
|
|
22934
|
-
contract(
|
|
22935
|
-
`${mp}.tools`,
|
|
22936
|
-
`"${tool}" must be humanOnly and declare a permission: the move is a person's act with it`
|
|
22937
|
-
);
|
|
22938
|
-
}
|
|
22939
|
-
}
|
|
22940
|
-
if (move.bindsStaff && (!move.window || !move.by.includes("staff"))) {
|
|
22941
|
-
contract(`${mp}.bindsStaff`, "bindsStaff needs a window and staff in by");
|
|
22942
|
-
}
|
|
22943
|
-
if (move.tools && move.by.includes("staff")) {
|
|
23051
|
+
`${path2}.copy.${target}`,
|
|
23052
|
+
`"${target}" must be a field of ${generatedName} the host does not already fill`
|
|
23053
|
+
);
|
|
23054
|
+
} else if (!from || from.type !== to.type || Boolean(from.many) !== Boolean(to.many) || from.to !== to.to) {
|
|
22944
23055
|
contract(
|
|
22945
|
-
`${
|
|
22946
|
-
"
|
|
23056
|
+
`${path2}.copy.${target}`,
|
|
23057
|
+
`"${source}" must be a field of ${name} of the same type as ${generatedName}.${target}`
|
|
22947
23058
|
);
|
|
22948
23059
|
}
|
|
22949
|
-
}
|
|
22950
|
-
|
|
22951
|
-
|
|
22952
|
-
|
|
22953
|
-
|
|
22954
|
-
|
|
22955
|
-
|
|
22956
|
-
|
|
22957
|
-
|
|
22958
|
-
|
|
22959
|
-
|
|
22960
|
-
}
|
|
22961
|
-
|
|
22962
|
-
|
|
23060
|
+
}
|
|
23061
|
+
const states = generated.states;
|
|
23062
|
+
if (!states) {
|
|
23063
|
+
contract(
|
|
23064
|
+
`${path2}.cancel`,
|
|
23065
|
+
`${generatedName} must declare states, with a host move into "${recurring.cancel}"`
|
|
23066
|
+
);
|
|
23067
|
+
} else {
|
|
23068
|
+
const field = own2(generated, states.field);
|
|
23069
|
+
if (!(field?.options ?? []).some((o) => o.value === recurring.cancel)) {
|
|
23070
|
+
contract(`${path2}.cancel`, `"${recurring.cancel}" is not a state of ${generatedName}`);
|
|
23071
|
+
} else if (!states.moves.some((move) => move.to === recurring.cancel && move.by.includes("host"))) {
|
|
23072
|
+
contract(
|
|
23073
|
+
`${path2}.cancel`,
|
|
23074
|
+
`${generatedName} needs a move into "${recurring.cancel}" that the host may make`
|
|
23075
|
+
);
|
|
22963
23076
|
}
|
|
22964
23077
|
}
|
|
22965
|
-
if (
|
|
22966
|
-
const
|
|
22967
|
-
const
|
|
22968
|
-
const
|
|
22969
|
-
|
|
22970
|
-
if (!target?.states) {
|
|
23078
|
+
if (recurring.horizonAtLeast) {
|
|
23079
|
+
const h = recurring.horizonAtLeast;
|
|
23080
|
+
const added = h.object.includes(".") ? m.fields?.[h.object] : void 0;
|
|
23081
|
+
const target = added ? { fields: added } : Object.hasOwn(m.objects, h.object) ? m.objects[h.object] : void 0;
|
|
23082
|
+
if (!target) {
|
|
22971
23083
|
contract(
|
|
22972
|
-
`${
|
|
22973
|
-
`"${
|
|
23084
|
+
`${path2}.horizonAtLeast.object`,
|
|
23085
|
+
`"${h.object}" must be one of this extension's objects, or an object this extension adds fields to`
|
|
22974
23086
|
);
|
|
22975
23087
|
} else {
|
|
22976
|
-
|
|
22977
|
-
|
|
23088
|
+
expect(
|
|
23089
|
+
target,
|
|
23090
|
+
h.object,
|
|
23091
|
+
`${path2}.horizonAtLeast.field`,
|
|
23092
|
+
h.field,
|
|
23093
|
+
["number"],
|
|
23094
|
+
"a number field (days)"
|
|
22978
23095
|
);
|
|
22979
|
-
for (const [when, to] of Object.entries(f.when)) {
|
|
22980
|
-
if (!parentStates.has(when)) {
|
|
22981
|
-
contract(`${fp}.when`, `"${when}" is not a state of ${rel?.to ?? f.relation}`);
|
|
22982
|
-
}
|
|
22983
|
-
for (const from of f.from) {
|
|
22984
|
-
if (!isState(from))
|
|
22985
|
-
contract(`${fp}.from`, `"${from}" is not an option of ${states.field}`);
|
|
22986
|
-
else if (!states.moves.some(
|
|
22987
|
-
(move) => move.to === to && move.by.includes("host") && moveOrigins(move).includes(from)
|
|
22988
|
-
)) {
|
|
22989
|
-
contract(`${fp}.when`, `${name} needs a host move from "${from}" to "${to}"`);
|
|
22990
|
-
}
|
|
22991
|
-
}
|
|
22992
|
-
}
|
|
22993
23096
|
}
|
|
22994
23097
|
}
|
|
22995
|
-
|
|
22996
|
-
const
|
|
22997
|
-
|
|
22998
|
-
if (
|
|
22999
|
-
|
|
23000
|
-
|
|
23001
|
-
|
|
23002
|
-
|
|
23003
|
-
|
|
23098
|
+
if (recurring.closures) {
|
|
23099
|
+
const c = recurring.closures;
|
|
23100
|
+
const closure = Object.hasOwn(m.objects, c.object) ? m.objects[c.object] : void 0;
|
|
23101
|
+
if (!closure || c.object === name || c.object === generatedName) {
|
|
23102
|
+
contract(
|
|
23103
|
+
`${path2}.closures.object`,
|
|
23104
|
+
`"${c.object}" must be another of this extension's objects`
|
|
23105
|
+
);
|
|
23106
|
+
} else {
|
|
23107
|
+
expect(closure, c.object, `${path2}.closures.from`, c.from, ["date"], "a date field");
|
|
23108
|
+
expect(closure, c.object, `${path2}.closures.until`, c.until, ["date"], "a date field");
|
|
23004
23109
|
}
|
|
23005
23110
|
}
|
|
23006
23111
|
}
|
|
23007
|
-
|
|
23008
|
-
|
|
23009
|
-
|
|
23010
|
-
|
|
23011
|
-
|
|
23012
|
-
|
|
23013
|
-
|
|
23014
|
-
|
|
23015
|
-
|
|
23016
|
-
|
|
23017
|
-
|
|
23018
|
-
|
|
23019
|
-
|
|
23020
|
-
|
|
23021
|
-
|
|
23022
|
-
|
|
23023
|
-
|
|
23024
|
-
|
|
23025
|
-
|
|
23026
|
-
|
|
23112
|
+
|
|
23113
|
+
// ../sdk/src/renamed.ts
|
|
23114
|
+
var OLD_PREFIX = "crm";
|
|
23115
|
+
var OPS_MODULE = "ops";
|
|
23116
|
+
var OLD_OPS_MODULE = OLD_PREFIX;
|
|
23117
|
+
var OPS_SPECIFIER = `codemode:${OPS_MODULE}`;
|
|
23118
|
+
var OLD_OPS_SPECIFIER = `codemode:${OLD_OPS_MODULE}`;
|
|
23119
|
+
var VIEW_PREFIX = "rec_";
|
|
23120
|
+
var OLD_VIEW_PREFIX = `${OLD_PREFIX}_`;
|
|
23121
|
+
var RENAMED_CORE_VIEWS = {
|
|
23122
|
+
people: "person",
|
|
23123
|
+
organisations: "organisation",
|
|
23124
|
+
affiliations: "affiliation",
|
|
23125
|
+
activities: "activity",
|
|
23126
|
+
activity_links: "activity_link",
|
|
23127
|
+
tasks: "task",
|
|
23128
|
+
task_links: "task_link",
|
|
23129
|
+
record_tags: "record_tag",
|
|
23130
|
+
users: "user",
|
|
23131
|
+
stage_history: "stage_history"
|
|
23132
|
+
};
|
|
23133
|
+
function renamedView(name) {
|
|
23134
|
+
const lower = name.toLowerCase();
|
|
23135
|
+
if (!lower.startsWith(OLD_VIEW_PREFIX)) return null;
|
|
23136
|
+
const suffix = lower.slice(OLD_VIEW_PREFIX.length);
|
|
23137
|
+
if (suffix.startsWith("x_")) return `${VIEW_PREFIX}${suffix}`;
|
|
23138
|
+
const core = RENAMED_CORE_VIEWS[suffix];
|
|
23139
|
+
return core ? `${VIEW_PREFIX}${core}` : null;
|
|
23140
|
+
}
|
|
23141
|
+
function renamedMessage(name) {
|
|
23142
|
+
if (name === OLD_OPS_SPECIFIER) {
|
|
23143
|
+
return `"${OLD_OPS_SPECIFIER}" was renamed: import { ${OPS_MODULE} } from "${OPS_SPECIFIER}" and call ${OPS_MODULE}.call(\u2026)`;
|
|
23027
23144
|
}
|
|
23028
|
-
|
|
23145
|
+
if (name === OLD_OPS_MODULE) {
|
|
23146
|
+
return `The "${OLD_OPS_MODULE}" module was renamed "${OPS_MODULE}": declare "${OPS_MODULE}" in permissions.modules and call ctx.${OPS_MODULE}`;
|
|
23147
|
+
}
|
|
23148
|
+
const view = renamedView(name);
|
|
23149
|
+
if (view) return `${name} was renamed ${view}; query the ${VIEW_PREFIX}* views`;
|
|
23150
|
+
if (name.toLowerCase().startsWith(OLD_VIEW_PREFIX)) {
|
|
23151
|
+
return `${name} is not a view: the ${OLD_VIEW_PREFIX}* views were renamed ${VIEW_PREFIX}*`;
|
|
23152
|
+
}
|
|
23153
|
+
return null;
|
|
23029
23154
|
}
|
|
23030
23155
|
|
|
23031
23156
|
// ../sdk/src/sellable.ts
|
|
@@ -23075,6 +23200,17 @@ var sellableManifestSchema = external_exports.object({
|
|
|
23075
23200
|
}).strict().optional()
|
|
23076
23201
|
}).strict().optional(),
|
|
23077
23202
|
onePerPerson: fieldName6.optional(),
|
|
23203
|
+
moves: external_exports.object({
|
|
23204
|
+
held: external_exports.string().min(1).max(100),
|
|
23205
|
+
paid: external_exports.string().min(1).max(100),
|
|
23206
|
+
expired: external_exports.string().min(1).max(100),
|
|
23207
|
+
refund: external_exports.array(external_exports.string().min(1).max(100)).max(20).optional(),
|
|
23208
|
+
price: external_exports.object({ field: external_exports.string().max(130).optional(), setting: fieldName6.optional() }).strict().optional(),
|
|
23209
|
+
title: external_exports.string().max(130).optional(),
|
|
23210
|
+
order: fieldName6.optional(),
|
|
23211
|
+
guest: external_exports.boolean().optional(),
|
|
23212
|
+
holdCap: external_exports.object({ setting: fieldName6 }).strict().optional()
|
|
23213
|
+
}).strict().optional(),
|
|
23078
23214
|
tax: external_exports.object({
|
|
23079
23215
|
code: external_exports.string().regex(TAX_CODE_PATTERN, "A product tax code: txcd_ and eight digits"),
|
|
23080
23216
|
place: external_exports.object({
|
|
@@ -23089,6 +23225,7 @@ var sellableManifestSchema = external_exports.object({
|
|
|
23089
23225
|
recurring: external_exports.object({
|
|
23090
23226
|
interval: external_exports.enum(["week", "month", "year"]),
|
|
23091
23227
|
trialDays: fieldName6.optional(),
|
|
23228
|
+
pause: external_exports.object({ minDays: fieldName6.optional(), maxDays: fieldName6.optional() }).strict().optional(),
|
|
23092
23229
|
grants: external_exports.object({
|
|
23093
23230
|
object: external_exports.string().max(40),
|
|
23094
23231
|
set: external_exports.record(fieldName6, recurringGrantSource),
|
|
@@ -23158,6 +23295,12 @@ function checkObjectSellable(m, name, object3, contract) {
|
|
|
23158
23295
|
if (trial !== void 0 && !single(trial, /* @__PURE__ */ new Set(["number"]))) {
|
|
23159
23296
|
contract(`${path2}.recurring.trialDays`, `"${trial}" must be a number field of ${name}`);
|
|
23160
23297
|
}
|
|
23298
|
+
for (const key of ["minDays", "maxDays"]) {
|
|
23299
|
+
const days = sellable.recurring.pause?.[key];
|
|
23300
|
+
if (days !== void 0 && !single(days, /* @__PURE__ */ new Set(["number"]))) {
|
|
23301
|
+
contract(`${path2}.recurring.pause.${key}`, `"${days}" must be a number field of ${name}`);
|
|
23302
|
+
}
|
|
23303
|
+
}
|
|
23161
23304
|
if (sellable.onePerPerson !== void 0) {
|
|
23162
23305
|
contract(
|
|
23163
23306
|
`${path2}.onePerPerson`,
|
|
@@ -23206,6 +23349,7 @@ function checkObjectSellable(m, name, object3, contract) {
|
|
|
23206
23349
|
}
|
|
23207
23350
|
}
|
|
23208
23351
|
if (sellable.grants) checkGrants(m, name, object3, sellable.grants, `${path2}.grants`, contract);
|
|
23352
|
+
if (sellable.moves) checkMoves(m, name, object3, sellable.moves, `${path2}.moves`, contract);
|
|
23209
23353
|
const place = sellable.tax?.place;
|
|
23210
23354
|
if (place) {
|
|
23211
23355
|
let holder = object3;
|
|
@@ -23236,6 +23380,159 @@ function checkObjectSellable(m, name, object3, contract) {
|
|
|
23236
23380
|
}
|
|
23237
23381
|
}
|
|
23238
23382
|
}
|
|
23383
|
+
function checkMoves(m, name, object3, moves, path2, contract) {
|
|
23384
|
+
const sellable = object3.sellable;
|
|
23385
|
+
for (const key of [
|
|
23386
|
+
"grants",
|
|
23387
|
+
"deposit",
|
|
23388
|
+
"recurring",
|
|
23389
|
+
"onePerPerson",
|
|
23390
|
+
"maxPerOrder",
|
|
23391
|
+
"saleWindow"
|
|
23392
|
+
]) {
|
|
23393
|
+
if (sellable[key] !== void 0) {
|
|
23394
|
+
contract(
|
|
23395
|
+
`objects.${name}.sellable.${key}`,
|
|
23396
|
+
`A record bought with moves is one record on one order: it has no ${key}`
|
|
23397
|
+
);
|
|
23398
|
+
}
|
|
23399
|
+
}
|
|
23400
|
+
const field = (local) => Object.hasOwn(object3.fields, local) ? object3.fields[local] : void 0;
|
|
23401
|
+
const price = field(sellable.price);
|
|
23402
|
+
if (price && !price.readOnly) {
|
|
23403
|
+
contract(
|
|
23404
|
+
`objects.${name}.fields.${sellable.price}`,
|
|
23405
|
+
`"${sellable.price}" holds what the host priced it at: make it readOnly`
|
|
23406
|
+
);
|
|
23407
|
+
}
|
|
23408
|
+
if (moves.order !== void 0) {
|
|
23409
|
+
const order = field(moves.order);
|
|
23410
|
+
if (order?.type !== "text" || order.many || !order.readOnly) {
|
|
23411
|
+
contract(`${path2}.order`, `"${moves.order}" must be a readOnly text field of ${name}`);
|
|
23412
|
+
}
|
|
23413
|
+
}
|
|
23414
|
+
if (moves.price) {
|
|
23415
|
+
if (moves.price.field === void 0 && moves.price.setting === void 0) {
|
|
23416
|
+
contract(`${path2}.price`, "price names a field, a setting or both");
|
|
23417
|
+
}
|
|
23418
|
+
if (moves.price.field !== void 0) {
|
|
23419
|
+
const at = resolveFieldPath(m, object3, moves.price.field);
|
|
23420
|
+
if (!at || at.many || at.type !== "number" && at.type !== "currency") {
|
|
23421
|
+
contract(
|
|
23422
|
+
`${path2}.price.field`,
|
|
23423
|
+
`"${moves.price.field}" must be a number field of ${name}, or <relation>.<field> through up to two relations, every field on the way declared by this extension`
|
|
23424
|
+
);
|
|
23425
|
+
}
|
|
23426
|
+
}
|
|
23427
|
+
if (moves.price.setting !== void 0) {
|
|
23428
|
+
const settings = m.settings ?? {};
|
|
23429
|
+
const setting = Object.hasOwn(settings, moves.price.setting) ? settings[moves.price.setting] : void 0;
|
|
23430
|
+
if (setting?.type !== "number") {
|
|
23431
|
+
contract(
|
|
23432
|
+
`${path2}.price.setting`,
|
|
23433
|
+
`"${moves.price.setting}" must be a number setting of ${m.id}`
|
|
23434
|
+
);
|
|
23435
|
+
}
|
|
23436
|
+
}
|
|
23437
|
+
}
|
|
23438
|
+
if (moves.title !== void 0) {
|
|
23439
|
+
const at = resolveFieldPath(m, object3, moves.title);
|
|
23440
|
+
if (!at || at.many || at.type !== "text") {
|
|
23441
|
+
contract(
|
|
23442
|
+
`${path2}.title`,
|
|
23443
|
+
`"${moves.title}" must be a text field of ${name}, or through up to two relations`
|
|
23444
|
+
);
|
|
23445
|
+
}
|
|
23446
|
+
}
|
|
23447
|
+
if (!object3.customer) contract(path2, `${name} must declare customer: whose record it is`);
|
|
23448
|
+
if (moves.guest && object3.customer) {
|
|
23449
|
+
const owner = field(object3.customer.field);
|
|
23450
|
+
if (owner?.required) {
|
|
23451
|
+
contract(
|
|
23452
|
+
`objects.${name}.fields.${object3.customer.field}`,
|
|
23453
|
+
`A guest's ${name} is held with no ${object3.customer.field} until it is paid: it cannot be required (the host keeps it set outside "${moves.held}")`
|
|
23454
|
+
);
|
|
23455
|
+
}
|
|
23456
|
+
}
|
|
23457
|
+
if (moves.holdCap) {
|
|
23458
|
+
const settings = m.settings ?? {};
|
|
23459
|
+
const setting = Object.hasOwn(settings, moves.holdCap.setting) ? settings[moves.holdCap.setting] : void 0;
|
|
23460
|
+
if (setting?.type !== "number") {
|
|
23461
|
+
contract(
|
|
23462
|
+
`${path2}.holdCap.setting`,
|
|
23463
|
+
`"${moves.holdCap.setting}" must be a number setting of ${m.id}`
|
|
23464
|
+
);
|
|
23465
|
+
}
|
|
23466
|
+
if (!moves.guest) contract(`${path2}.holdCap`, "holdCap limits guests' holds: declare guest");
|
|
23467
|
+
if (!object3.claims) contract(`${path2}.holdCap`, `${name} must claim places (claims)`);
|
|
23468
|
+
}
|
|
23469
|
+
const states = object3.states;
|
|
23470
|
+
if (!states) {
|
|
23471
|
+
contract(path2, `${name} must declare states: the order moves it`);
|
|
23472
|
+
return;
|
|
23473
|
+
}
|
|
23474
|
+
const values = new Set((object3.fields[states.field]?.options ?? []).map((o) => o.value));
|
|
23475
|
+
const finals = new Set(states.moves.filter((mv) => mv.final).map((mv) => mv.to));
|
|
23476
|
+
for (const key of ["held", "paid", "expired"]) {
|
|
23477
|
+
if (!values.has(moves[key])) {
|
|
23478
|
+
contract(`${path2}.${key}`, `"${moves[key]}" is not a state of ${name}`);
|
|
23479
|
+
}
|
|
23480
|
+
}
|
|
23481
|
+
if ((/* @__PURE__ */ new Set([moves.held, moves.paid, moves.expired])).size !== 3) {
|
|
23482
|
+
contract(path2, "held, paid and expired are three different states");
|
|
23483
|
+
}
|
|
23484
|
+
const creators = states.create?.in?.[moves.held] ?? [];
|
|
23485
|
+
if (!creators.includes("host")) {
|
|
23486
|
+
contract(
|
|
23487
|
+
`${path2}.held`,
|
|
23488
|
+
`states.create.in must let the host create ${name} in "${moves.held}"`
|
|
23489
|
+
);
|
|
23490
|
+
}
|
|
23491
|
+
if (creators.some((by) => by !== "host")) {
|
|
23492
|
+
contract(
|
|
23493
|
+
`${path2}.held`,
|
|
23494
|
+
`Only the host creates ${name} in "${moves.held}": anyone else would hold it with no order`
|
|
23495
|
+
);
|
|
23496
|
+
}
|
|
23497
|
+
const hostMove = (to) => states.moves.some(
|
|
23498
|
+
(mv) => mv.to === to && moveOrigins(mv).includes(moves.held) && mv.by.includes("host")
|
|
23499
|
+
);
|
|
23500
|
+
for (const key of ["paid", "expired"]) {
|
|
23501
|
+
if (!hostMove(moves[key])) {
|
|
23502
|
+
contract(
|
|
23503
|
+
`${path2}.${key}`,
|
|
23504
|
+
`${name} needs a move from "${moves.held}" to "${moves[key]}" the host may make`
|
|
23505
|
+
);
|
|
23506
|
+
}
|
|
23507
|
+
}
|
|
23508
|
+
if (!finals.has(moves.expired)) {
|
|
23509
|
+
contract(`${path2}.expired`, `"${moves.expired}" must be a final state of ${name}`);
|
|
23510
|
+
}
|
|
23511
|
+
for (const mv of states.moves) {
|
|
23512
|
+
if (!moveOrigins(mv).includes(moves.held)) continue;
|
|
23513
|
+
if (mv.by.some((by) => by !== "host")) {
|
|
23514
|
+
contract(
|
|
23515
|
+
`${path2}.held`,
|
|
23516
|
+
`Only the host moves ${name} out of "${moves.held}" (to "${mv.to}"): its order says where it goes`
|
|
23517
|
+
);
|
|
23518
|
+
}
|
|
23519
|
+
}
|
|
23520
|
+
for (const [i, state] of (moves.refund ?? []).entries()) {
|
|
23521
|
+
if (!values.has(state) || state === moves.held || state === moves.expired) {
|
|
23522
|
+
contract(
|
|
23523
|
+
`${path2}.refund.${i}`,
|
|
23524
|
+
`"${state}" must be a state of ${name} other than held and expired`
|
|
23525
|
+
);
|
|
23526
|
+
}
|
|
23527
|
+
}
|
|
23528
|
+
const allowance = object3.allowance;
|
|
23529
|
+
if (allowance && "spends" in allowance && !allowance.spends.waived) {
|
|
23530
|
+
contract(
|
|
23531
|
+
path2,
|
|
23532
|
+
`${name} spends uses: declare allowance.spends.waived, which the host sets on a record its order pays for`
|
|
23533
|
+
);
|
|
23534
|
+
}
|
|
23535
|
+
}
|
|
23239
23536
|
function checkGrants(m, name, item, grants, path2, contract) {
|
|
23240
23537
|
const local = grants.object.startsWith(`${m.id}.`) ? grants.object.slice(m.id.length + 1) : grants.object;
|
|
23241
23538
|
const granted = Object.hasOwn(m.objects, local) ? m.objects[local] : void 0;
|
|
@@ -23794,7 +24091,8 @@ var objectManifestSchema = external_exports.object({
|
|
|
23794
24091
|
read: external_exports.array(external_exports.string().max(40)).max(100),
|
|
23795
24092
|
write: external_exports.array(external_exports.string().max(40)).max(100),
|
|
23796
24093
|
requireAccess: external_exports.array(external_exports.string().max(40)).max(10).optional(),
|
|
23797
|
-
createOnly: external_exports.array(external_exports.string().max(40)).max(100).optional()
|
|
24094
|
+
createOnly: external_exports.array(external_exports.string().max(40)).max(100).optional(),
|
|
24095
|
+
guardians: external_exports.object({ write: external_exports.boolean().optional(), madeBy: external_exports.string().max(40).optional() }).strict().optional()
|
|
23798
24096
|
}).strict().optional(),
|
|
23799
24097
|
public: readDeclarationSchema.optional(),
|
|
23800
24098
|
signedIn: readDeclarationSchema.optional(),
|
|
@@ -23867,6 +24165,8 @@ var toolManifestSchema = external_exports.object({
|
|
|
23867
24165
|
permission: external_exports.string().max(80).optional(),
|
|
23868
24166
|
/** Only a person may call it (ADR 0512). */
|
|
23869
24167
|
humanOnly: external_exports.literal(true).optional(),
|
|
24168
|
+
/** A person approves anyone else's call (ADR 0552). */
|
|
24169
|
+
personApproves: external_exports.literal(true).optional(),
|
|
23870
24170
|
inputSchema: jsonSchemaObject,
|
|
23871
24171
|
outputSchema: jsonSchemaObject
|
|
23872
24172
|
});
|
|
@@ -23874,7 +24174,19 @@ var roleManifestSchema = external_exports.object({
|
|
|
23874
24174
|
label: external_exports.string().min(1).max(60),
|
|
23875
24175
|
description: external_exports.string().min(10).max(500),
|
|
23876
24176
|
permissions: external_exports.array(external_exports.string().max(80)).max(20).default([]),
|
|
23877
|
-
read: external_exports.array(external_exports.string().max(80)).max(20).default([])
|
|
24177
|
+
read: external_exports.array(external_exports.string().max(80)).max(20).default([]),
|
|
24178
|
+
/** Objects whose records the role reaches only on the organisation's local today (ADR 0553). */
|
|
24179
|
+
today: external_exports.record(
|
|
24180
|
+
external_exports.string().max(80),
|
|
24181
|
+
external_exports.union([
|
|
24182
|
+
external_exports.string().max(122),
|
|
24183
|
+
external_exports.object({
|
|
24184
|
+
at: external_exports.string().max(122),
|
|
24185
|
+
until: external_exports.string().max(122).optional(),
|
|
24186
|
+
zone: external_exports.string().max(122).optional()
|
|
24187
|
+
}).strict()
|
|
24188
|
+
])
|
|
24189
|
+
).optional()
|
|
23878
24190
|
});
|
|
23879
24191
|
var EXTENSION_PERMISSION_RE = /^([a-z][a-z0-9]{1,29}):([a-z][a-zA-Z0-9]{0,39})$/;
|
|
23880
24192
|
var viewManifestSchema = external_exports.object({
|
|
@@ -24095,6 +24407,7 @@ function toManifest(extension) {
|
|
|
24095
24407
|
...tool.audiences ? { audiences: [...tool.audiences] } : {},
|
|
24096
24408
|
...tool.permission ? { permission: tool.permission } : {},
|
|
24097
24409
|
...tool.humanOnly ? { humanOnly: true } : {},
|
|
24410
|
+
...tool.personApproves ? { personApproves: true } : {},
|
|
24098
24411
|
...tool.customerFields ? {
|
|
24099
24412
|
customerFields: Object.fromEntries(
|
|
24100
24413
|
Object.entries(tool.customerFields).map(([object3, fields]) => [
|
|
@@ -24133,7 +24446,8 @@ function toManifest(extension) {
|
|
|
24133
24446
|
label: role.label,
|
|
24134
24447
|
description: role.description,
|
|
24135
24448
|
permissions: [...role.permissions],
|
|
24136
|
-
read: [...role.read]
|
|
24449
|
+
read: [...role.read],
|
|
24450
|
+
...role.today ? { today: { ...role.today } } : {}
|
|
24137
24451
|
}
|
|
24138
24452
|
])
|
|
24139
24453
|
)
|
|
@@ -24652,6 +24966,21 @@ function validateManifest(input2, options = {}) {
|
|
|
24652
24966
|
}
|
|
24653
24967
|
}
|
|
24654
24968
|
}
|
|
24969
|
+
for (const [name, object3] of Object.entries(m.objects)) {
|
|
24970
|
+
const madeBy = object3.customer?.guardians?.madeBy;
|
|
24971
|
+
if (madeBy === void 0) continue;
|
|
24972
|
+
const path2 = `objects.${name}.customer.guardians.madeBy`;
|
|
24973
|
+
const field = object3.fields[madeBy];
|
|
24974
|
+
if (field?.type !== "relation" || field.to !== "person" || field.many) {
|
|
24975
|
+
contract(path2, `"${madeBy}" must be a relation of ${name} to one person`);
|
|
24976
|
+
} else if (!field.readOnly) {
|
|
24977
|
+
contract(path2, `"${madeBy}" must be readOnly: the host sets it, nobody edits it`);
|
|
24978
|
+
} else if (madeBy === object3.customer?.field) {
|
|
24979
|
+
contract(path2, "madeBy cannot be the customer field");
|
|
24980
|
+
} else if (object3.customer?.write.includes(madeBy)) {
|
|
24981
|
+
contract(path2, `"${madeBy}" is set by the host: customer.write may not list it`);
|
|
24982
|
+
}
|
|
24983
|
+
}
|
|
24655
24984
|
for (const [name, object3] of Object.entries(m.objects)) {
|
|
24656
24985
|
for (const fieldName7 of object3.customer?.requireAccess ?? []) {
|
|
24657
24986
|
const path2 = `objects.${name}.customer.requireAccess`;
|
|
@@ -24809,6 +25138,12 @@ function validateManifest(input2, options = {}) {
|
|
|
24809
25138
|
`A tool only a person on the staff may call cannot be open to ${open2.join(" and ")} callers`
|
|
24810
25139
|
);
|
|
24811
25140
|
}
|
|
25141
|
+
if (tool.personApproves && (open2.length || tool.risk === "read")) {
|
|
25142
|
+
contract(
|
|
25143
|
+
`tools.${name}.personApproves`,
|
|
25144
|
+
"A tool a person approves is a staff tool that changes something: not open to customers or the public, and not a read"
|
|
25145
|
+
);
|
|
25146
|
+
}
|
|
24812
25147
|
if (open2.length && tool.risk !== "read" && tool.risk !== "write") {
|
|
24813
25148
|
contract(
|
|
24814
25149
|
`tools.${name}.risk`,
|
|
@@ -24924,6 +25259,32 @@ function validateManifest(input2, options = {}) {
|
|
|
24924
25259
|
);
|
|
24925
25260
|
}
|
|
24926
25261
|
}
|
|
25262
|
+
for (const [object3, limit] of Object.entries(role.today ?? {})) {
|
|
25263
|
+
const tp = `${path2}.today.${object3}`;
|
|
25264
|
+
const local = object3.startsWith(`${m.id}.`) ? object3.slice(m.id.length + 1) : null;
|
|
25265
|
+
const target = local && Object.hasOwn(m.objects, local) ? m.objects[local] : void 0;
|
|
25266
|
+
if (!target) {
|
|
25267
|
+
contract(tp, `"${object3}" is not an object of this extension`);
|
|
25268
|
+
continue;
|
|
25269
|
+
}
|
|
25270
|
+
const spec = typeof limit === "string" ? { at: limit } : limit;
|
|
25271
|
+
const prefix = (p) => p.includes(".") ? p.split(".")[0] : null;
|
|
25272
|
+
const paths = [
|
|
25273
|
+
[spec.at, "datetime"],
|
|
25274
|
+
[spec.until, "datetime"],
|
|
25275
|
+
[spec.zone, "timezone"]
|
|
25276
|
+
];
|
|
25277
|
+
for (const [p, type] of paths) {
|
|
25278
|
+
if (p === void 0) continue;
|
|
25279
|
+
const field = p.split(".").length <= 2 ? resolveFieldPath(m, target, p) : void 0;
|
|
25280
|
+
if (field?.type !== type || field.many) {
|
|
25281
|
+
contract(tp, `"${p}" must be a ${type} field of ${object3}, or one relation away`);
|
|
25282
|
+
}
|
|
25283
|
+
if (prefix(p) !== prefix(spec.at)) {
|
|
25284
|
+
contract(tp, `"${p}" must be read through the same relation as "${spec.at}"`);
|
|
25285
|
+
}
|
|
25286
|
+
}
|
|
25287
|
+
}
|
|
24927
25288
|
}
|
|
24928
25289
|
for (const [name, view] of Object.entries(m.views)) {
|
|
24929
25290
|
if (!FIELD_NAME_RE.test(name)) contract(`views.${name}`, "View names must be camelCase");
|
|
@@ -25693,10 +26054,19 @@ export {
|
|
|
25693
26054
|
triggerObject,
|
|
25694
26055
|
cronIssues,
|
|
25695
26056
|
checkAutomation,
|
|
26057
|
+
MOVERS,
|
|
26058
|
+
windowBoundSchema,
|
|
26059
|
+
statesManifestSchema,
|
|
26060
|
+
staffOnlyPathsOf,
|
|
26061
|
+
moveOrigins,
|
|
26062
|
+
checkObjectStates,
|
|
26063
|
+
windowChecks,
|
|
26064
|
+
resolveFieldPath,
|
|
25696
26065
|
CAPACITY_SHOW,
|
|
25697
26066
|
CAPACITY_VALUES,
|
|
25698
26067
|
capacityManifestSchema,
|
|
25699
26068
|
checkObjectCapacity,
|
|
26069
|
+
waitlistManifestSchema,
|
|
25700
26070
|
claimsManifestSchema,
|
|
25701
26071
|
checkObjectClaims,
|
|
25702
26072
|
DOCUMENT_MAX_BYTES,
|
|
@@ -25737,12 +26107,6 @@ export {
|
|
|
25737
26107
|
OLD_VIEW_PREFIX,
|
|
25738
26108
|
renamedView,
|
|
25739
26109
|
renamedMessage,
|
|
25740
|
-
MOVERS,
|
|
25741
|
-
statesManifestSchema,
|
|
25742
|
-
staffOnlyPathsOf,
|
|
25743
|
-
moveOrigins,
|
|
25744
|
-
checkObjectStates,
|
|
25745
|
-
resolveFieldPath,
|
|
25746
26110
|
SUBSCRIPTION_GRANT_STATES,
|
|
25747
26111
|
TAX_CODE_PATTERN,
|
|
25748
26112
|
GRANT_SOURCES,
|