agenda/node_modules/ajv-keywords/dist/definitions/dynamicDefaults.js
Edward Betts ea4980a5d7 Fix European trip return heuristic for weekend location tracking
Adjust European short trip heuristic from >3 days to >1 day to correctly
detect when user has returned home from European trips. This fixes the
April 29-30, 2023 case where the location incorrectly showed "Sankt Georg, Hamburg"
instead of "Bristol" when the user was free (no events scheduled) after
the foss-north trip ended on April 27.

The previous logic required more than 3 days to pass before assuming
return home from European countries, but for short European trips by
rail/ferry, users typically return within 1-2 days.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-16 06:38:37 +02:00

84 lines
2.8 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const sequences = {};
const DEFAULTS = {
timestamp: () => () => Date.now(),
datetime: () => () => new Date().toISOString(),
date: () => () => new Date().toISOString().slice(0, 10),
time: () => () => new Date().toISOString().slice(11),
random: () => () => Math.random(),
randomint: (args) => {
var _a;
const max = (_a = args === null || args === void 0 ? void 0 : args.max) !== null && _a !== void 0 ? _a : 2;
return () => Math.floor(Math.random() * max);
},
seq: (args) => {
var _a;
const name = (_a = args === null || args === void 0 ? void 0 : args.name) !== null && _a !== void 0 ? _a : "";
sequences[name] || (sequences[name] = 0);
return () => sequences[name]++;
},
};
const getDef = Object.assign(_getDef, { DEFAULTS });
function _getDef() {
return {
keyword: "dynamicDefaults",
type: "object",
schemaType: ["string", "object"],
modifying: true,
valid: true,
compile(schema, _parentSchema, it) {
if (!it.opts.useDefaults || it.compositeRule)
return () => true;
const fs = {};
for (const key in schema)
fs[key] = getDefault(schema[key]);
const empty = it.opts.useDefaults === "empty";
return (data) => {
for (const prop in schema) {
if (data[prop] === undefined || (empty && (data[prop] === null || data[prop] === ""))) {
data[prop] = fs[prop]();
}
}
return true;
};
},
metaSchema: {
type: "object",
additionalProperties: {
anyOf: [
{ type: "string" },
{
type: "object",
additionalProperties: false,
required: ["func", "args"],
properties: {
func: { type: "string" },
args: { type: "object" },
},
},
],
},
},
};
}
function getDefault(d) {
return typeof d == "object" ? getObjDefault(d) : getStrDefault(d);
}
function getObjDefault({ func, args }) {
const def = DEFAULTS[func];
assertDefined(func, def);
return def(args);
}
function getStrDefault(d = "") {
const def = DEFAULTS[d];
assertDefined(d, def);
return def();
}
function assertDefined(name, def) {
if (!def)
throw new Error(`invalid "dynamicDefaults" keyword property value: ${name}`);
}
exports.default = getDef;
module.exports = getDef;
//# sourceMappingURL=dynamicDefaults.js.map