diff --git a/packages/plugin-core/manifest.json b/packages/plugin-core/manifest.json index db6ab203bf..80c7f5e816 100644 --- a/packages/plugin-core/manifest.json +++ b/packages/plugin-core/manifest.json @@ -163,19 +163,26 @@ "description": "Filter by distance to a coordinate", "properties": { "latitude": { - "type": "string", + "type": "number", "title": "Latitude", - "description": "GPS latitude of a coordinate which the asset must be close to" + "description": "GPS latitude of a coordinate which the asset must be close to", + "minimum": -90, + "maximum": 90, + "precision": 0.00001 }, "longitude": { - "type": "string", + "type": "number", "title": "Longitude", - "description": "GPS longitude of a coordinate which the asset must be close to" + "description": "GPS longitude of a coordinate which the asset must be close to", + "minimum": -180, + "maximum": 180, + "precision": 0.00001 }, "radius": { "type": "number", "title": "Maximum distance", - "description": "How close in kilometres the asset must be to the given point" + "description": "How close in kilometres the asset must be to the given point", + "minimum": 0 } } } diff --git a/packages/plugin-core/src/index.ts b/packages/plugin-core/src/index.ts index e67434bb54..cbc2438f2c 100644 --- a/packages/plugin-core/src/index.ts +++ b/packages/plugin-core/src/index.ts @@ -55,7 +55,7 @@ export const assetLocationFilter = () => { WorkflowType.AssetV1, { region?: { country?: string; state?: string; city?: string }; - coordinate?: { latitude?: string; longitude?: string; radius?: number }; + coordinate?: { latitude?: number; longitude?: number; radius?: number }; } >(({ config, data }) => { if ( @@ -66,10 +66,10 @@ export const assetLocationFilter = () => { return { workflow: { continue: false } }; } - const configLat = Number.parseFloat(config.coordinate?.latitude ?? ''); - const configLon = Number.parseFloat(config.coordinate?.longitude ?? ''); + const configLat = config.coordinate?.latitude; + const configLon = config.coordinate?.longitude; - if (Number.isNaN(configLat) || Number.isNaN(configLat)) { + if (configLat === undefined || configLon === undefined) { return { workflow: { continue: true } }; } diff --git a/server/src/dtos/json-schema.dto.ts b/server/src/dtos/json-schema.dto.ts index 65b92277d5..607ccf282b 100644 --- a/server/src/dtos/json-schema.dto.ts +++ b/server/src/dtos/json-schema.dto.ts @@ -1,9 +1,7 @@ import { createZodDto } from 'nestjs-zod'; import z from 'zod'; -export const JsonSchemaTypeSchema = z - .enum(['string', 'number', 'integer', 'boolean', 'object']) - .meta({ id: 'JsonSchemaType' }); +export const JsonSchemaTypeSchema = z.enum(['string', 'number', 'boolean', 'object']).meta({ id: 'JsonSchemaType' }); const JsonSchemaPropertySchema = z .object({ @@ -12,6 +10,9 @@ const JsonSchemaPropertySchema = z description: z.string().describe('Description'), default: z.any().optional().describe('Default value'), enum: z.array(z.string()).optional().describe('Valid choices for enum types'), + minimum: z.number().optional().describe('Minimum value for number types'), + maximum: z.number().optional().describe('Maximum value for number types'), + precision: z.number().default(1).optional().describe('Smallest interval (granularity) for number types'), array: z.boolean().optional().describe('Type is an array type'), required: z.array(z.string()).optional().describe('A list of required properties'), uiHint: z.string().optional(), diff --git a/web/src/lib/components/SchemaConfiguration.svelte b/web/src/lib/components/SchemaConfiguration.svelte index 37e799984f..63b32a01e7 100644 --- a/web/src/lib/components/SchemaConfiguration.svelte +++ b/web/src/lib/components/SchemaConfiguration.svelte @@ -98,7 +98,7 @@ {:else if schema.type === 'number'} - + {:else if schema.type === 'string'} diff --git a/web/src/lib/types.ts b/web/src/lib/types.ts index 41d98df097..8903f2dd32 100644 --- a/web/src/lib/types.ts +++ b/web/src/lib/types.ts @@ -84,7 +84,7 @@ export type SearchFilter = { rating?: number | null; }; -export type JSONSchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'object'; +export type JSONSchemaType = 'string' | 'number' | 'boolean' | 'object'; export type JSONSchemaProperty = { type: JSONSchemaType; @@ -93,6 +93,9 @@ export type JSONSchemaProperty = { // eslint-disable-next-line @typescript-eslint/no-explicit-any default?: any; enum?: string[]; + minimum?: number; + maximum?: number; + precision?: number; array?: boolean; properties?: Record; required?: string[]; diff --git a/web/src/lib/utils/workflow.spec.ts b/web/src/lib/utils/workflow.spec.ts index b6492ae32a..ada68dfbcb 100644 --- a/web/src/lib/utils/workflow.spec.ts +++ b/web/src/lib/utils/workflow.spec.ts @@ -46,20 +46,6 @@ describe(getWorkflowDefaultConfig.name, () => { ).toEqual({ test: false }); }); - it('should default to 0 (integer)', () => { - expect( - getWorkflowDefaultConfig({ - type: 'object', - properties: { - test: { - type: 'integer', - }, - }, - required: ['test'], - }), - ).toEqual({ test: 0 }); - }); - it('should default to 0 (number)', () => { expect( getWorkflowDefaultConfig({ diff --git a/web/src/lib/utils/workflow.ts b/web/src/lib/utils/workflow.ts index 61702f4264..9f1da22daf 100644 --- a/web/src/lib/utils/workflow.ts +++ b/web/src/lib/utils/workflow.ts @@ -64,7 +64,6 @@ export const getWorkflowDefaultConfig = (schema: JSONSchemaProperty) => { break; } - case 'integer': case 'number': { config[key] = 0; break;