diff --git a/frontend/openapi-ts.config.ts b/frontend/openapi-ts.config.ts index ed71a8a9..9fe84523 100644 --- a/frontend/openapi-ts.config.ts +++ b/frontend/openapi-ts.config.ts @@ -14,5 +14,6 @@ export default defineConfig({ }, '@hey-api/sdk', '@tanstack/react-query', + 'zod', ], }); diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 4e746d46..ed73ab33 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -28,7 +28,8 @@ "typescript": "^5.9.3", "vite": "^7.3.1", "vite-plugin-svgr": "^4.5.0", - "vite-tsconfig-paths": "^6.1.1" + "vite-tsconfig-paths": "^6.1.1", + "zod": "^4.4.3" }, "devDependencies": { "@hey-api/openapi-ts": "^0.98.2", @@ -9795,6 +9796,15 @@ "engines": { "node": ">=10" } + }, + "node_modules/zod": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.4.3.tgz", + "integrity": "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } diff --git a/frontend/package.json b/frontend/package.json index da894318..362fc4c6 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -25,7 +25,8 @@ "typescript": "^5.9.3", "vite": "^7.3.1", "vite-plugin-svgr": "^4.5.0", - "vite-tsconfig-paths": "^6.1.1" + "vite-tsconfig-paths": "^6.1.1", + "zod": "^4.4.3" }, "scripts": { "start": "vite", diff --git a/frontend/src/client/zod.gen.ts b/frontend/src/client/zod.gen.ts new file mode 100644 index 00000000..b3259a73 --- /dev/null +++ b/frontend/src/client/zod.gen.ts @@ -0,0 +1,1214 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import * as z from 'zod'; + +/** + * Definition of a grid scan (mutually exclusive with `rotation_axis`) + */ +export const zGridScan = z.object({ + n_fast: z.coerce.bigint().gte(BigInt(1)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + step_x_um: z.number(), + step_y_um: z.number(), + vertical: z.boolean().optional().default(false), + snake: z.boolean().optional().default(false) +}); + +/** + * Definition of a crystal rotation axis + */ +export const zRotationAxis = z.object({ + name: z.string().min(1).optional().default('omega'), + step: z.number(), + start: z.number().optional().default(0), + vector: z.tuple([ + z.number(), + z.number(), + z.number() + ]), + helical_step_um: z.tuple([ + z.number(), + z.number(), + z.number() + ]).optional(), + screening_wedge_deg: z.number().optional() +}); + +/** + * Selection of an indexing algorithm used by Jungfraujoch + * + */ +export const zIndexingAlgorithm = z.enum([ + 'FFBIDX', + 'FFT', + 'FFTW', + 'Auto', + 'None' +]).default('FFBIDX'); + +/** + * Selection of an post-indexing least-square diffraction geometry refinement algorithm used by Jungfraujoch. + * BeamCenter - This option is refining both beam center and lattice (restricted to a chosen/detected Bravais lattice). + * OrientationOnly - This option is refining only orientation of the lattice. + * + */ +export const zGeomRefinementAlgorithm = z.enum([ + 'BeamCenter', + 'OrientationOnly', + 'None' +]); + +/** + * Real-space crystal lattice 3D vectors in Angstrom. + * Order is 1st vector (x,y,z), 2nd vector (x,y,z) and 3rd vector (x,y,z) + * + */ +export const zCrystalLattice = z.tuple([ + z.number(), + z.number(), + z.number(), + z.number(), + z.number(), + z.number(), + z.number(), + z.number(), + z.number() +]); + +/** + * Unit cell parameters. Necessary to run indexing. Units of angstrom and degree + */ +export const zUnitCell = z.object({ + a: z.number().gte(0), + b: z.number().gte(0), + c: z.number().gte(0), + alpha: z.number().gte(0).lte(360), + beta: z.number().gte(0).lte(360), + gamma: z.number().gte(0).lte(360) +}); + +export const zDatasetSettings = z.object({ + images_per_trigger: z.coerce.bigint().gte(BigInt(1)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional().default(BigInt(1)), + ntrigger: z.coerce.bigint().gte(BigInt(1)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional().default(BigInt(1)), + image_time_us: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + beam_x_pxl: z.number(), + beam_y_pxl: z.number(), + detector_distance_mm: z.number().gte(0), + incident_energy_keV: z.number().gte(0.001).lte(500), + file_prefix: z.string().optional().default(''), + images_per_file: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional().default(BigInt(1000)), + space_group_number: z.coerce.bigint().gte(BigInt(1)).lte(BigInt(194)).optional(), + sample_name: z.string().optional().default(''), + compression: z.enum([ + 'bslz4', + 'bszstd', + 'bszstd_rle', + 'none' + ]).optional().default('bslz4'), + total_flux: z.number().optional(), + transmission: z.number().gte(0).lte(1).optional(), + goniometer: zRotationAxis.optional(), + grid_scan: zGridScan.optional(), + header_appendix: z.unknown().optional(), + image_appendix: z.unknown().optional(), + data_reduction_factor_serialmx: z.number().gte(0).lte(1).optional().default(1), + pixel_value_low_threshold: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + run_number: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + run_name: z.string().optional(), + experiment_group: z.string().optional(), + poisson_compression: z.coerce.bigint().gte(BigInt(0)).lte(BigInt(16)).optional(), + write_nxmx_hdf5_master: z.boolean().optional().default(true), + save_calibration: z.boolean().optional(), + polarization_factor: z.number().gte(-1).lte(1).optional(), + ring_current_mA: z.number().gte(0).optional(), + sample_temperature_K: z.number().gte(0).optional(), + poni_rot1_rad: z.number().gte(-6.28318530718).lte(6.28318530718).optional().default(0), + poni_rot2_rad: z.number().gte(-6.28318530718).lte(6.28318530718).optional().default(0), + poni_rot3_rad: z.number().gte(-6.28318530718).lte(6.28318530718).optional().default(0), + unit_cell: zUnitCell.optional(), + spot_finding: z.boolean().optional().default(true), + max_spot_count: z.int().gte(10).lte(2000).optional().default(250), + detect_ice_rings: z.boolean().optional(), + async_start: z.boolean().optional().default(false), + xray_fluorescence_spectrum: z.object({ + energy_eV: z.array(z.number()), + data: z.array(z.number()) + }).optional() +}); + +/** + * NoFileWritten - no files are written at all + * NXmxOnlyData - only data files are written, no master file + * NXmxLegacy - legacy format with soft links to data files in the master file; necessary for DECTRIS Albula 4.0 and DECTRIS Neggia + * NXmxVDS - newer format with virtual dataset linking data files in the master file, also includes better metadata handling + * NXmxIntegrated - single HDF5 per dataset + * CBF - CBF format (limited metadata) + * TIFF - TIFF format (no metadata) + * + */ +export const zFileWriterFormat = z.enum([ + 'NXmxOnlyData', + 'NXmxLegacy', + 'NXmxVDS', + 'NXmxIntegrated', + 'CBF', + 'TIFF', + 'NoFileWritten' +]).default('NXmxLegacy'); + +export const zFileWriterSettings = z.object({ + overwrite: z.boolean().optional().default(false), + format: zFileWriterFormat.optional() +}); + +export const zPixelMaskStatistics = z.object({ + user_mask: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + too_high_pedestal_rms: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + wrong_gain: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional() +}); + +export const zImageBufferStatus = z.object({ + min_image_number: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + max_image_number: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + image_numbers: z.array(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), + total_slots: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + available_slots: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + in_preparation_slots: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + in_sending_slots: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + current_counter: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional() +}); + +export const zImageFormatSettings = z.object({ + summation: z.boolean(), + geometry_transform: z.boolean(), + jungfrau_conversion: z.boolean(), + jungfrau_conversion_factor_keV: z.number().gte(0.001).lte(500).optional(), + bit_depth_image: z.union([ + z.literal(8), + z.literal(16), + z.literal(32) + ]).optional(), + signed_output: z.boolean().optional(), + mask_module_edges: z.boolean().default(true), + mask_chip_edges: z.boolean().default(true), + jungfrau_mask_pixels_without_g0: z.boolean().optional().default(true), + apply_mask: z.boolean().default(false), + jungfrau_pedestal_g0_rms_limit: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional().default(BigInt(100)) +}); + +/** + * Power on of ASICs + */ +export const zDetectorPowerState = z.enum([ + 'PowerOn', + 'PowerOff', + 'Partial' +]); + +/** + * Current state of the detector + */ +export const zDetectorState = z.enum([ + 'Idle', + 'Waiting', + 'Busy', + 'Error', + 'Not connected' +]); + +export const zDetectorStatus = z.object({ + state: zDetectorState, + powerchip: zDetectorPowerState, + server_version: z.string(), + number_of_triggers_left: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + fpga_temp_degC: z.array(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })), + high_voltage_V: z.array(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })) +}); + +export const zDetectorTiming = z.enum([ + 'auto', + 'trigger', + 'burst', + 'gated' +]).default('trigger'); + +export const zDetectorSettings = z.object({ + frame_time_us: z.coerce.bigint().gte(BigInt(1)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + count_time_us: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + internal_frame_generator: z.boolean().optional().default(false), + internal_frame_generator_images: z.coerce.bigint().gte(BigInt(1)).lte(BigInt(64)).optional().default(BigInt(1)), + detector_trigger_delay_ns: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional().default(BigInt(0)), + timing: zDetectorTiming.optional(), + eiger_threshold_keV: z.number().gte(1).lte(100).optional(), + eiger_bit_depth: z.union([ + z.literal(8), + z.literal(16), + z.literal(32) + ]).optional(), + jungfrau_pedestal_g0_frames: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional().default(BigInt(2000)), + jungfrau_pedestal_g1_frames: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional().default(BigInt(300)), + jungfrau_pedestal_g2_frames: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional().default(BigInt(300)), + jungfrau_pedestal_min_image_count: z.coerce.bigint().gte(BigInt(32)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional().default(BigInt(128)), + jungfrau_storage_cell_count: z.coerce.bigint().gte(BigInt(1)).lte(BigInt(16)).optional().default(BigInt(1)), + jungfrau_storage_cell_delay_ns: z.coerce.bigint().gte(BigInt(2100)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional().default(BigInt(5000)), + jungfrau_fixed_gain_g1: z.boolean().optional().default(false), + jungfrau_use_gain_hg0: z.boolean().optional().default(false) +}); + +export const zSpotFindingSettings = z.object({ + enable: z.boolean().default(true), + indexing: z.boolean().default(true), + signal_to_noise_threshold: z.number().gte(0), + photon_count_threshold: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + min_pix_per_spot: z.coerce.bigint().gte(BigInt(1)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + max_pix_per_spot: z.coerce.bigint().gte(BigInt(1)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + high_resolution_limit: z.number(), + low_resolution_limit: z.number(), + high_resolution_limit_for_spot_count_low_res: z.number().gte(2).lte(8), + quick_integration: z.boolean().default(false), + ice_ring_width_q_recipA: z.number().gte(0).lte(1).default(0.02), + high_res_gap_Q_recipA: z.number().gte(0.1).lte(5).optional().default(1.5) +}); + +export const zAzimIntSettings = z.object({ + polarization_corr: z.boolean().default(true), + solid_angle_corr: z.boolean().default(true), + high_q_recipA: z.number().gte(0.00002).lte(10), + low_q_recipA: z.number().gte(0.00001).lte(10), + q_spacing: z.number().gte(0.00001), + azimuthal_bins: z.coerce.bigint().gte(BigInt(1)).lte(BigInt(512)).optional().default(BigInt(1)), + force_cpu: z.boolean().optional().default(false) +}); + +export const zDetectorSelection = z.object({ + id: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }) +}); + +export const zMeasurementStatistics = z.object({ + file_prefix: z.string().optional(), + run_number: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + experiment_group: z.string().optional(), + images_expected: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + images_collected: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + images_sent: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + images_written: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + images_discarded_lossy_compression: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + max_image_number_sent: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + collection_efficiency: z.number().gte(0).lte(1).optional(), + compression_ratio: z.number().gte(0).optional(), + cancelled: z.boolean().optional(), + max_receiver_delay: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + indexing_rate: z.number().optional(), + detector_width: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + detector_height: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + detector_pixel_depth: z.union([z.literal(2), z.literal(4)]).optional(), + bkg_estimate: z.number().optional(), + unit_cell: z.string().optional(), + error_pixels: z.number().optional(), + saturated_pixels: z.number().optional(), + roi_beam_pixels: z.number().optional(), + roi_beam_sum: z.number().optional() +}); + +export const zFpgaStatus = z.array(z.object({ + pci_dev_id: z.string(), + serial_number: z.string(), + fw_version: z.string(), + base_mac_addr: z.string(), + eth_link_count: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + eth_link_status: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + power_usage_W: z.number(), + fpga_temp_C: z.number(), + hbm_temp_C: z.number(), + packets_udp: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + packets_sls: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + idle: z.boolean(), + pcie_link_speed: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + pcie_link_width: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }) +})); + +export const zBrokerStatus = z.object({ + state: z.enum([ + 'Inactive', + 'Idle', + 'Busy', + 'Measuring', + 'Pedestal', + 'Error' + ]), + progress: z.number().gte(0).lte(1).optional(), + message: z.string().optional(), + message_severity: z.enum([ + 'success', + 'info', + 'warning', + 'error' + ]).optional().default('error'), + gpu_count: z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).optional(), + broker_version: z.string().optional() +}); + +/** + * x and y coordinates for plotting, it is OK to assume that both arrays have the same size; layout is optimized for Plotly + */ +export const zPlot = z.object({ + title: z.string().default(''), + x: z.array(z.number()), + y: z.array(z.number().nullable()), + z: z.array(z.number().nullable()).optional() +}); + +export const zPlotUnitX = z.enum([ + 'image_number', + 'q_recipA', + 'd_A', + 'angle_deg', + 'ADU', + 'grid_um' +]).default('image_number'); + +export const zPlots = z.object({ + title: z.string().optional(), + unit_x: zPlotUnitX, + size_x: z.number().optional(), + size_y: z.number().optional(), + plot: z.array(zPlot) +}); + +/** + * Results of a scan + */ +export const zScanResult = z.object({ + file_prefix: z.string().optional(), + rotation_unit_cell: zUnitCell.optional(), + rotation_crystal_lattice: zCrystalLattice.optional(), + images: z.array(z.object({ + efficiency: z.number(), + number: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + nx: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + ny: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + angle: z.number().optional(), + bkg: z.number().optional(), + spots: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + spots_low_res: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + spots_indexed: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + spots_ice: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + index: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + latt_count: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + pr: z.number().optional(), + b: z.number().optional(), + uc: zUnitCell.optional(), + xfel_pulseid: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + pixel_sum: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + max: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + sat: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + err: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + res: z.number().optional() + })) +}); + +export const zCalibrationStatistics = z.array(z.object({ + module_number: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + storage_cell_number: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + pedestal_g0_mean: z.number(), + pedestal_g1_mean: z.number(), + pedestal_g2_mean: z.number(), + gain_g0_mean: z.number(), + gain_g1_mean: z.number(), + gain_g2_mean: z.number(), + masked_pixels: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }) +})); + +export const zErrorMessage = z.object({ + msg: z.string(), + reason: z.enum(['WrongDAQState', 'Other']) +}); + +/** + * ROI as Q-range (or resolution range) + */ +export const zRoiAzimuthal = z.object({ + name: z.string().min(1), + q_min_recipA: z.number().gte(0.00001), + q_max_recipA: z.number().gte(0.00001) +}); + +/** + * Circular ROI + */ +export const zRoiCircle = z.object({ + name: z.string().min(1), + center_x_pxl: z.number(), + center_y_pxl: z.number(), + radius_pxl: z.number().gt(0) +}); + +/** + * Box ROI + */ +export const zRoiBox = z.object({ + name: z.string().min(1), + min_x_pxl: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + max_x_pxl: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + min_y_pxl: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + max_y_pxl: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }) +}); + +/** + * List of circular ROIs + */ +export const zRoiCircleList = z.object({ + rois: z.array(zRoiCircle).max(12) +}); + +/** + * List of box ROIs + */ +export const zRoiBoxList = z.object({ + rois: z.array(zRoiBox).max(12).optional() +}); + +/** + * List of azimuthal ROIs + */ +export const zRoiAzimList = z.object({ + rois: z.array(zRoiAzimuthal).max(12).optional() +}); + +/** + * ROI defintions + */ +export const zRoiDefinitions = z.object({ + box: zRoiBoxList, + circle: zRoiCircleList, + azim: zRoiAzimList +}); + +/** + * Settings for collection of dark images to be used for mask calculation + */ +export const zDarkMaskSettings = z.object({ + detector_threshold_keV: z.number().gte(2.5).lte(100).default(3.5), + frame_time_us: z.coerce.bigint().gte(BigInt(500)).lte(BigInt(100000)).default(BigInt(10000)), + number_of_frames: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(1000)), + max_allowed_pixel_count: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(1)), + max_frames_with_signal: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(10)) +}); + +/** + * Settings for crystallography indexing + */ +export const zIndexingSettings = z.object({ + algorithm: zIndexingAlgorithm, + fft_max_unit_cell_A: z.number().gte(50).lte(500).default(250), + fft_min_unit_cell_A: z.number().gte(5).lte(40).default(10), + fft_high_resolution_A: z.number().gte(0.5).lte(6).default(2), + fft_num_vectors: z.coerce.bigint().gte(BigInt(128)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(16384)), + tolerance: z.number().gte(0).lte(0.5), + thread_count: z.coerce.bigint().gte(BigInt(1)).lte(BigInt(64)), + geom_refinement_algorithm: zGeomRefinementAlgorithm, + unit_cell_dist_tolerance: z.number().gte(0.0001).lte(0.2001).default(0.05), + viable_cell_min_spots: z.coerce.bigint().gte(BigInt(5)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(10)), + index_ice_rings: z.boolean().default(false), + rotation_indexing: z.boolean().default(false), + rotation_indexing_min_angular_range_deg: z.number().gte(1).default(20), + rotation_indexing_angular_stride_deg: z.number().gte(0).default(0.5), + blocking: z.boolean().default(true) +}); + +/** + * Metadata for a measurement instrument + */ +export const zInstrumentMetadata = z.object({ + source_name: z.string(), + source_type: z.string().optional().default(''), + instrument_name: z.string(), + pulsed_source: z.boolean().optional().default(false), + electron_source: z.boolean().optional().default(false) +}); + +export const zDetectorModuleDirection = z.enum([ + 'Xp', + 'Xn', + 'Yp', + 'Yn' +]); + +export const zDetectorType = z.enum([ + 'EIGER', + 'JUNGFRAU', + 'DECTRIS' +]); + +export const zDetectorListElement = z.object({ + id: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + description: z.string(), + serial_number: z.string(), + base_ipv4_addr: z.string(), + udp_interface_count: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + nmodules: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + width: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + height: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + pixel_size_mm: z.number().optional(), + readout_time_ns: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + min_frame_time_ns: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + min_count_time_ns: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + type: zDetectorType.optional() +}); + +export const zDetectorList = z.object({ + detectors: z.array(zDetectorListElement), + current_id: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }) +}); + +export const zImagePusherType = z.enum([ + 'ZeroMQ', + 'HDF5', + 'CBOR', + 'TCP', + 'None' +]).default('None'); + +/** + * Informs about status of the image pusher. + * + */ +export const zImagePusherStatus = z.object({ + pusher_type: zImagePusherType, + addr: z.array(z.string()), + connected_writers: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), + images_written: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + images_write_error: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + writer_fifo_utilization: z.array(z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })).optional() +}); + +/** + * Regular rectangular geometry, first module is in the bottom left corner of the detector + */ +export const zStandardDetectorGeometry = z.object({ + nmodules: z.int().gte(1), + gap_x: z.int().gte(0).optional().default(8), + gap_y: z.int().gte(0).optional().default(36), + modules_in_row: z.int().gte(1).optional().default(1) +}); + +export const zDetectorModule = z.object({ + x0: z.number(), + y0: z.number(), + fast_axis: zDetectorModuleDirection, + slow_axis: zDetectorModuleDirection +}); + +export const zDetector = z.object({ + description: z.string().min(1), + serial_number: z.string().min(1).optional().default('Unknown'), + type: zDetectorType.optional(), + high_voltage_V: z.coerce.bigint().gte(BigInt(0)).lte(BigInt(200)).optional().default(BigInt(0)), + udp_interface_count: z.coerce.bigint().gte(BigInt(1)).lte(BigInt(2)).optional().default(BigInt(1)), + module_sync: z.boolean().optional().default(true), + sensor_thickness_um: z.number().gte(0).optional().default(320), + readout_time_ns: z.coerce.bigint().gte(BigInt(1)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + min_count_time_ns: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + min_frame_time_ns: z.coerce.bigint().gte(BigInt(0)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + calibration_file: z.array(z.string()).optional(), + hostname: z.array(z.string()).optional(), + sensor_material: z.string().optional().default('Si'), + tx_delay: z.array(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })).optional(), + base_data_ipv4_address: z.string().optional(), + standard_geometry: zStandardDetectorGeometry.optional(), + custom_geometry: z.array(zDetectorModule).optional(), + roi_mode: z.string().optional().default(''), + mirror_y: z.boolean().optional().default(true), + temp_thresold_degC: z.coerce.bigint().gte(BigInt(40)).lte(BigInt(70)).optional().default(BigInt(55)), + default_settings: zDetectorSettings.optional() +}); + +/** + * ZeroMQ configuration for Jungfraujoch software. + * This structure is used to provide default settings using configuration JSON file and is not used in HTTP. + * + */ +export const zZeromqSettings = z.object({ + send_watermark: z.coerce.bigint().gte(BigInt(2)).lte(BigInt(16384)).optional().default(BigInt(100)), + send_buffer_size: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + image_socket: z.array(z.string()).optional(), + writer_notification_socket: z.string().optional() +}); + +/** + * TCP image stream configuration for Jungfraujoch software. + * This structure is used to provide default settings using configuration JSON file and is not used in HTTP. + * + */ +export const zTcpSettings = z.object({ + send_buffer_size: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional(), + image_socket: z.string().optional(), + nwriters: z.coerce.bigint().gte(BigInt(1)).lte(BigInt(100)).optional().default(BigInt(32)) +}); + +export const zPcieDevices = z.array(z.object({ + blk: z.string().optional(), + ipv4: z.string().optional() +})); + +export const zZeromqMetadataSettings = z.object({ + enabled: z.boolean().default(true), + period_ms: z.coerce.bigint().gte(BigInt(1)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(1000)), + socket_address: z.string().optional() +}); + +export const zZeromqPreviewSettings = z.object({ + enabled: z.boolean().default(true), + period_ms: z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(1000)), + socket_address: z.string().optional() +}); + +/** + * Pool statistics for Jungfraujoch to reduce transfers between frontend and jfjoch_broker + */ +export const zJfjochStatistics = z.object({ + detector: zDetectorStatus.optional(), + detector_list: zDetectorList.optional(), + detector_settings: zDetectorSettings.optional(), + image_format_settings: zImageFormatSettings.optional(), + instrument_metadata: zInstrumentMetadata.optional(), + file_writer_settings: zFileWriterSettings.optional(), + data_processing_settings: zSpotFindingSettings.optional(), + measurement: zMeasurementStatistics.optional(), + broker: zBrokerStatus.optional(), + fpga: zFpgaStatus.optional(), + calibration: zCalibrationStatistics.optional(), + zeromq_preview: zZeromqPreviewSettings.optional(), + zeromq_metadata: zZeromqMetadataSettings.optional(), + dark_mask: zDarkMaskSettings.optional(), + pixel_mask: zPixelMaskStatistics.optional(), + roi: zRoiDefinitions.optional(), + az_int: zAzimIntSettings.optional(), + buffer: zImageBufferStatus.optional(), + indexing: zIndexingSettings.optional(), + image_pusher: zImagePusherStatus.optional() +}); + +/** + * Default settings for Jungfraujoch software. + * This structure is used to provide default settings using configuration JSON file and is not used in HTTP. + * + */ +export const zJfjochSettings = z.object({ + pcie: zPcieDevices.optional(), + zeromq: zZeromqSettings.optional(), + tcp: zTcpSettings.optional(), + instrument: zInstrumentMetadata.optional(), + file_writer: zFileWriterSettings.optional(), + detector: z.array(zDetector), + indexing: zIndexingSettings.optional(), + detector_settings: zDetectorSettings.optional(), + azim_int: zAzimIntSettings.optional(), + image_format: zImageFormatSettings.optional(), + image_buffer_MiB: z.int().gte(128).optional().default(2048), + verbose: z.boolean().optional().default(false), + receiver_threads: z.int().gte(1).lte(512).optional().default(64), + numa_policy: z.string().optional(), + frontend_directory: z.string(), + spot_finding: zSpotFindingSettings.optional(), + image_pusher: zImagePusherType, + zeromq_preview: zZeromqPreviewSettings.optional(), + zeromq_metadata: zZeromqMetadataSettings.optional(), + dark_mask: zDarkMaskSettings.optional() +}); + +/** + * Binning of frames for the plot (0 = default binning) + */ +export const zBinning = z.int().default(1); + +/** + * If measurement has goniometer axis defined, plot X-axis will represent rotation angle + * If measurement has grid scan defined, plot X-axis and Y-axis will represent grid position, Z will be used as the final value + * For still measurement the number is ignored + * + */ +export const zExperimentalCoord = z.boolean().default(false); + +/** + * Unit used for azim int. + * + */ +export const zAzintUnit = z.enum([ + 'Q_recipA', + 'd_A', + 'two_theta_deg' +]).default('Q_recipA'); + +/** + * Fill value for elements that were missed during data collection + * + */ +export const zFillValue = z.number(); + +/** + * Type of requested plot + */ +export const zPlotType = z.enum([ + 'bkg_estimate', + 'azint', + 'azint_1d', + 'spot_count', + 'spot_count_low_res', + 'spot_count_indexed', + 'spot_count_ice', + 'indexing_rate', + 'indexing_lattice_count', + 'indexing_unit_cell_length', + 'indexing_unit_cell_angle', + 'profile_radius', + 'mosaicity', + 'b_factor', + 'error_pixels', + 'saturated_pixels', + 'image_collection_efficiency', + 'receiver_delay', + 'receiver_free_send_buf', + 'strong_pixels', + 'roi_sum', + 'roi_mean', + 'roi_max_count', + 'roi_pixels', + 'roi_weighted_x', + 'roi_weighted_y', + 'packets_received', + 'max_pixel_value', + 'resolution_estimate', + 'pixel_sum', + 'processing_time', + 'beam_center_x', + 'beam_center_y', + 'integrated_reflections', + 'image_scale_factor', + 'image_scale_cc', + 'image_scale_b', + 'compression_ratio' +]); + +/** + * Name of ROI for which plot is requested + */ +export const zRoi = z.string().min(1); + +/** + * Image ID in the image buffer. Special values: -1 - last image in the buffer, -2: last indexed image in the buffer + */ +export const zImageId = z.coerce.bigint().gte(BigInt(-2)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).default(BigInt(-1)); + +/** + * Saturation value to set contrast in the preview image; if not provided, then autocontrast procedure is used + */ +export const zSaturation = z.number().gte(-32767).lte(32767); + +/** + * Background value to set contrast in the preview image + */ +export const zBackground = z.number().gte(-32767).lte(32767).default(0); + +/** + * Show spot finding results on the image + */ +export const zShowSpots = z.boolean().default(true); + +/** + * Show beam center on the image + */ +export const zShowBeamCenter = z.boolean().default(true); + +/** + * Show ROI areas on the image + */ +export const zShowRoi = z.boolean().default(false); + +/** + * Quality of JPEG image (100 - highest; 0 - lowest) + */ +export const zJpegQuality = z.coerce.bigint().gte(BigInt(0)).lte(BigInt(100)).default(BigInt(100)); + +/** + * Show user mask + */ +export const zShowUserMask = z.boolean().default(false); + +/** + * Show resolution ring, provided in Angstrom + */ +export const zResolutionRing = z.number().gte(0.1).lte(100).default(0.1); + +/** + * Show resolution estimation as a ring + */ +export const zResolutionEstimate = z.boolean().default(false); + +/** + * Color scale for preview image + */ +export const zColorScale = z.enum([ + 'indigo', + 'viridis', + 'bw', + 'wb', + 'green', + 'heat', + 'magma', + 'inferno' +]).default('indigo'); + +export const zPostStartBody = zDatasetSettings; + +export const zPostWaitUntilRunningQuery = z.object({ + timeout: z.int().gte(0).lte(3600).optional().default(60) +}); + +export const zPostWaitTillDoneQuery = z.object({ + timeout: z.int().gte(0).lte(3600).optional().default(60) +}); + +/** + * Everything OK + */ +export const zGetConfigDetectorResponse = zDetectorSettings; + +export const zPutConfigDetectorBody = zDetectorSettings; + +/** + * Everything OK + */ +export const zGetConfigIndexingResponse = zIndexingSettings; + +export const zPutConfigIndexingBody = zIndexingSettings; + +/** + * Everything OK + */ +export const zGetConfigFileWriterResponse = zFileWriterSettings; + +export const zPutConfigFileWriterBody = zFileWriterSettings; + +/** + * Everything OK + */ +export const zGetConfigInstrumentResponse = zInstrumentMetadata; + +export const zPutConfigInstrumentBody = zInstrumentMetadata; + +/** + * Everything OK + */ +export const zGetConfigImageFormatResponse = zImageFormatSettings; + +export const zPutConfigImageFormatBody = zImageFormatSettings; + +/** + * Everything OK + */ +export const zGetConfigSpotFindingResponse = zSpotFindingSettings; + +export const zPutConfigSpotFindingBody = zSpotFindingSettings; + +/** + * Everything OK + */ +export const zGetConfigAzimIntResponse = zAzimIntSettings; + +export const zPutConfigAzimIntBody = zAzimIntSettings; + +export const zPutConfigInternalGeneratorImageBody = z.string(); + +export const zPutConfigInternalGeneratorImageQuery = z.object({ + id: z.coerce.bigint().gte(BigInt(0)).lte(BigInt(127)).optional() +}); + +export const zPutConfigInternalGeneratorImageTiffBody = z.string(); + +export const zPutConfigInternalGeneratorImageTiffQuery = z.object({ + id: z.int().gte(0).lte(127).optional() +}); + +/** + * Everything OK + */ +export const zGetConfigSelectDetectorResponse = zDetectorList; + +export const zPutConfigSelectDetectorBody = zDetectorSelection; + +/** + * Everything OK + */ +export const zGetConfigZeromqPreviewResponse = zZeromqPreviewSettings; + +export const zPutConfigZeromqPreviewBody = zZeromqPreviewSettings; + +/** + * Everything OK + */ +export const zGetConfigZeromqMetadataResponse = zZeromqMetadataSettings; + +export const zPutConfigZeromqMetadataBody = zZeromqMetadataSettings; + +/** + * Everything OK + */ +export const zGetConfigDarkMaskResponse = zDarkMaskSettings; + +export const zPutConfigDarkMaskBody = zDarkMaskSettings; + +/** + * Everything OK + */ +export const zGetStatusResponse = zBrokerStatus; + +/** + * Everything OK + */ +export const zGetFpgaStatusResponse = zFpgaStatus; + +/** + * Pulse ID collected + */ +export const zGetXfelPulseIdResponse = z.array(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })); + +/** + * Event codes collected + */ +export const zGetXfelEventCodeResponse = z.array(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' })); + +/** + * Everything OK + */ +export const zGetImagePusherStatusResponse = zImagePusherStatus; + +/** + * Everything OK + */ +export const zGetDetectorStatusResponse = zDetectorStatus; + +/** + * OK + */ +export const zGetConfigRoiResponse = zRoiDefinitions; + +export const zPutConfigRoiBody = zRoiDefinitions; + +/** + * Everything OK + */ +export const zGetStatisticsResponse = zJfjochStatistics; + +/** + * Everything OK + */ +export const zGetStatisticsDataCollectionResponse = zMeasurementStatistics; + +/** + * Everything OK + */ +export const zGetStatisticsCalibrationResponse = zCalibrationStatistics; + +/** + * Binary array (4 byte; unsigned) + */ +export const zGetConfigMaskResponse = z.string(); + +/** + * User mask in binary format (4 byte; unsigned) + */ +export const zGetConfigUserMaskResponse = z.string(); + +export const zPutConfigUserMaskBody = z.string(); + +/** + * Pixel mask in TIFF format (4 byte; unsigned) + */ +export const zGetConfigMaskTiffResponse = z.string(); + +/** + * User mask in TIFF format (4 byte; unsigned) + */ +export const zGetConfigUserMaskTiffResponse = z.string(); + +export const zPutConfigUserMaskTiffBody = z.string(); + +export const zGetPreviewPedestalTiffQuery = z.object({ + gain_level: z.int(), + sc: z.int().optional() +}); + +/** + * Calibration image + */ +export const zGetPreviewPedestalTiffResponse = z.string(); + +export const zGetPreviewPlotQuery = z.object({ + binning: z.int().optional().default(1), + type: z.enum([ + 'bkg_estimate', + 'azint', + 'azint_1d', + 'spot_count', + 'spot_count_low_res', + 'spot_count_indexed', + 'spot_count_ice', + 'indexing_rate', + 'indexing_lattice_count', + 'indexing_unit_cell_length', + 'indexing_unit_cell_angle', + 'profile_radius', + 'mosaicity', + 'b_factor', + 'error_pixels', + 'saturated_pixels', + 'image_collection_efficiency', + 'receiver_delay', + 'receiver_free_send_buf', + 'strong_pixels', + 'roi_sum', + 'roi_mean', + 'roi_max_count', + 'roi_pixels', + 'roi_weighted_x', + 'roi_weighted_y', + 'packets_received', + 'max_pixel_value', + 'resolution_estimate', + 'pixel_sum', + 'processing_time', + 'beam_center_x', + 'beam_center_y', + 'integrated_reflections', + 'image_scale_factor', + 'image_scale_cc', + 'image_scale_b', + 'compression_ratio' + ]), + fill: z.number().optional(), + experimental_coord: z.boolean().optional().default(false), + azint_unit: z.enum([ + 'Q_recipA', + 'd_A', + 'two_theta_deg' + ]).optional().default('Q_recipA') +}); + +/** + * Everything OK. + */ +export const zGetPreviewPlotResponse = zPlots; + +export const zGetPreviewPlotBinQuery = z.object({ + type: z.enum([ + 'bkg_estimate', + 'azint', + 'azint_1d', + 'spot_count', + 'spot_count_low_res', + 'spot_count_indexed', + 'spot_count_ice', + 'indexing_rate', + 'indexing_lattice_count', + 'indexing_unit_cell_length', + 'indexing_unit_cell_angle', + 'profile_radius', + 'mosaicity', + 'b_factor', + 'error_pixels', + 'saturated_pixels', + 'image_collection_efficiency', + 'receiver_delay', + 'receiver_free_send_buf', + 'strong_pixels', + 'roi_sum', + 'roi_mean', + 'roi_max_count', + 'roi_pixels', + 'roi_weighted_x', + 'roi_weighted_y', + 'packets_received', + 'max_pixel_value', + 'resolution_estimate', + 'pixel_sum', + 'processing_time', + 'beam_center_x', + 'beam_center_y', + 'integrated_reflections', + 'image_scale_factor', + 'image_scale_cc', + 'image_scale_b', + 'compression_ratio' + ]), + roi: z.string().min(1).optional() +}); + +/** + * Everything OK. + */ +export const zGetPreviewPlotBinResponse = z.string(); + +/** + * Everything OK. + */ +export const zGetResultScanResponse = zScanResult; + +/** + * Return start message + */ +export const zGetImageBufferStartCborResponse = z.string(); + +export const zGetImageBufferImageCborQuery = z.object({ + id: z.coerce.bigint().gte(BigInt(-2)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional().default(BigInt(-1)) +}); + +/** + * Return image message + */ +export const zGetImageBufferImageCborResponse = z.string(); + +export const zGetImageBufferImageJpegQuery = z.object({ + id: z.coerce.bigint().gte(BigInt(-2)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional().default(BigInt(-1)), + show_user_mask: z.boolean().optional().default(false), + show_roi: z.boolean().optional().default(false), + show_spots: z.boolean().optional().default(true), + show_beam_center: z.boolean().optional().default(true), + saturation: z.number().gte(-32767).lte(32767).optional(), + jpeg_quality: z.coerce.bigint().gte(BigInt(0)).lte(BigInt(100)).optional().default(BigInt(100)), + show_res_ring: z.number().gte(0.1).lte(100).optional().default(0.1), + color: z.enum([ + 'indigo', + 'viridis', + 'bw', + 'wb', + 'green', + 'heat', + 'magma', + 'inferno' + ]).optional().default('indigo'), + show_res_est: z.boolean().optional().default(false) +}); + +/** + * Preview image + */ +export const zGetImageBufferImageJpegResponse = z.string(); + +export const zGetImageBufferImageTiffQuery = z.object({ + id: z.coerce.bigint().gte(BigInt(-2)).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).optional().default(BigInt(-1)) +}); + +/** + * Preview image + */ +export const zGetImageBufferImageTiffResponse = z.string(); + +/** + * Done + */ +export const zGetImageBufferStatusResponse = zImageBufferStatus; + +/** + * Release number of Jungfraujoch + */ +export const zGetVersionResponse = z.string();