agenda/node_modules/ajv/lib/refs/jtd-schema.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

131 lines
2.5 KiB
TypeScript

import {SchemaObject} from "../types"
type MetaSchema = (root: boolean) => SchemaObject
const shared: MetaSchema = (root) => {
const sch: SchemaObject = {
nullable: {type: "boolean"},
metadata: {
optionalProperties: {
union: {elements: {ref: "schema"}},
},
additionalProperties: true,
},
}
if (root) sch.definitions = {values: {ref: "schema"}}
return sch
}
const emptyForm: MetaSchema = (root) => ({
optionalProperties: shared(root),
})
const refForm: MetaSchema = (root) => ({
properties: {
ref: {type: "string"},
},
optionalProperties: shared(root),
})
const typeForm: MetaSchema = (root) => ({
properties: {
type: {
enum: [
"boolean",
"timestamp",
"string",
"float32",
"float64",
"int8",
"uint8",
"int16",
"uint16",
"int32",
"uint32",
],
},
},
optionalProperties: shared(root),
})
const enumForm: MetaSchema = (root) => ({
properties: {
enum: {elements: {type: "string"}},
},
optionalProperties: shared(root),
})
const elementsForm: MetaSchema = (root) => ({
properties: {
elements: {ref: "schema"},
},
optionalProperties: shared(root),
})
const propertiesForm: MetaSchema = (root) => ({
properties: {
properties: {values: {ref: "schema"}},
},
optionalProperties: {
optionalProperties: {values: {ref: "schema"}},
additionalProperties: {type: "boolean"},
...shared(root),
},
})
const optionalPropertiesForm: MetaSchema = (root) => ({
properties: {
optionalProperties: {values: {ref: "schema"}},
},
optionalProperties: {
additionalProperties: {type: "boolean"},
...shared(root),
},
})
const discriminatorForm: MetaSchema = (root) => ({
properties: {
discriminator: {type: "string"},
mapping: {
values: {
metadata: {
union: [propertiesForm(false), optionalPropertiesForm(false)],
},
},
},
},
optionalProperties: shared(root),
})
const valuesForm: MetaSchema = (root) => ({
properties: {
values: {ref: "schema"},
},
optionalProperties: shared(root),
})
const schema: MetaSchema = (root) => ({
metadata: {
union: [
emptyForm,
refForm,
typeForm,
enumForm,
elementsForm,
propertiesForm,
optionalPropertiesForm,
discriminatorForm,
valuesForm,
].map((s) => s(root)),
},
})
const jtdMetaSchema: SchemaObject = {
definitions: {
schema: schema(false),
},
...schema(true),
}
export default jtdMetaSchema