agenda/node_modules/ajv/lib/vocabularies/applicator/properties.ts
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

58 lines
1.8 KiB
TypeScript

import type {CodeKeywordDefinition} from "../../types"
import {KeywordCxt} from "../../compile/validate"
import {propertyInData, allSchemaProperties} from "../code"
import {alwaysValidSchema, toHash, mergeEvaluated} from "../../compile/util"
import apDef from "./additionalProperties"
const def: CodeKeywordDefinition = {
keyword: "properties",
type: "object",
schemaType: "object",
code(cxt: KeywordCxt) {
const {gen, schema, parentSchema, data, it} = cxt
if (it.opts.removeAdditional === "all" && parentSchema.additionalProperties === undefined) {
apDef.code(new KeywordCxt(it, apDef, "additionalProperties"))
}
const allProps = allSchemaProperties(schema)
for (const prop of allProps) {
it.definedProperties.add(prop)
}
if (it.opts.unevaluated && allProps.length && it.props !== true) {
it.props = mergeEvaluated.props(gen, toHash(allProps), it.props)
}
const properties = allProps.filter((p) => !alwaysValidSchema(it, schema[p]))
if (properties.length === 0) return
const valid = gen.name("valid")
for (const prop of properties) {
if (hasDefault(prop)) {
applyPropertySchema(prop)
} else {
gen.if(propertyInData(gen, data, prop, it.opts.ownProperties))
applyPropertySchema(prop)
if (!it.allErrors) gen.else().var(valid, true)
gen.endIf()
}
cxt.it.definedProperties.add(prop)
cxt.ok(valid)
}
function hasDefault(prop: string): boolean | undefined {
return it.opts.useDefaults && !it.compositeRule && schema[prop].default !== undefined
}
function applyPropertySchema(prop: string): void {
cxt.subschema(
{
keyword: "properties",
schemaProp: prop,
dataProp: prop,
},
valid
)
}
},
}
export default def