All files / lib/metadata _testdata.ts

100% Statements 8/8
100% Branches 0/0
100% Functions 5/5
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128        2x                                             2x                                                                                                                                                             12x     92x                       16x     96x 92x    
import type * as DB from '$lib/database.js';
import { METADATA_TYPES } from '$lib/schemas/metadata';
import { mapEntries } from '$lib/utils';
 
export const metadatas = {
	integer: { id: 'metadata_integer', type: 'integer', options: [] },
	float: { id: 'metadata_float', type: 'float', options: [] },
	date: { id: 'metadata_date', type: 'date', options: [] },
	string: { id: 'metadata_string', type: 'string', options: [] },
	boolean: { id: 'metadata_boolean ', type: 'boolean', options: [] },
	location: { id: 'metadata_location ', type: 'location', options: [] },
	boundingbox: { id: 'metadata_boundingbox ', type: 'boundingbox', options: [] },
	enum: {
		id: 'metadata_enum ',
		type: 'enum',
		options: [
			{ key: 'A', label: 'Option A', index: 1, synonyms: ['Option α'] },
			{ key: 'B', label: 'Option B', index: 0, synonyms: ['Option β'] },
			{ key: 'C', label: 'Option C', index: 2, synonyms: ['Option γ'] }
		]
	}
} as const satisfies {
	[K in DB.MetadataType]: Pick<DB.Metadata, 'id' | 'type'> & {
		options: DB.MetadataEnumVariant[];
	};
};
 
export const items: Array<{ id: string; metadata: DB.MetadataValues }> = [
	{
		id: 'item1',
		metadata: {
			metadata_integer: 10,
			metadata_float: 10.1234,
			metadata_date: new Date('2023-01-01T12:00:00Z'),
			metadata_string: 'apple',
			metadata_boolean: true,
			metadata_location: { latitude: 10.12345, longitude: 20.12345 },
			metadata_enum: 'A',
			metadata_boundingbox: { x: 10, y: 10, w: 50, h: 50 }
		}
	},
	{
		id: 'item2',
		metadata: {
			metadata_integer: 10,
			metadata_float: 10.1256,
			metadata_date: new Date('2023-01-01T12:00:30Z'),
			metadata_string: 'banana',
			metadata_boolean: false,
			metadata_location: { latitude: 10.12355, longitude: 20.12355 },
			metadata_enum: 'B',
			metadata_boundingbox: { x: 12, y: 12, w: 50, h: 50 }
		}
	},
	{
		id: 'item3',
		metadata: {
			metadata_integer: 15,
			metadata_float: 15.5678,
			metadata_date: new Date('2023-01-02T12:00:00Z'),
			metadata_string: 'apple',
			metadata_boolean: true,
			metadata_location: { latitude: 15.56789, longitude: 25.56789 },
			metadata_enum: 'A'
			// No bounding box value here
		}
	},
	{
		id: 'item4',
		metadata: {
			metadata_integer: 20,
			metadata_float: 20.0,
			metadata_date: new Date('2023-01-03T12:00:00Z'),
			metadata_string: 'orange',
			metadata_boolean: false,
			metadata_location: { latitude: 10.124, longitude: 20.124 },
			metadata_enum: 'C',
			metadata_boundingbox: { x: 11, y: 11, w: 50, h: 50 }
		}
	},
	{
		id: 'item5',
		metadata: {
			metadata_integer: 30,
			metadata_float: 20.004,
			metadata_date: new Date('2023-01-03T12:05:00Z'),
			metadata_string: 'banana',
			metadata_boolean: false,
			metadata_location: { latitude: 10.124, longitude: 20.124 },
			metadata_enum: 'B',
			metadata_boundingbox: { x: 11, y: 11, w: 50, h: 50 }
		}
	},
	{
		id: 'item6',
		metadata: {
			// No metadata_integer value here
			metadata_float: 25.0,
			metadata_date: new Date('2023-01-04T12:00:00Z'),
			metadata_string: 'grape',
			metadata_boolean: true,
			metadata_location: { latitude: 30.0, longitude: 40.0 },
			metadata_enum: 'A',
			metadata_boundingbox: { x: 15, y: 15, w: 50, h: 50 }
		}
	}
].map((item) => ({
	...item,
	metadata: Object.fromEntries(
		Object.entries(item.metadata).map(([k, v]) => [
			k,
			{
				value: v,
				manuallyModified: false,
				confidence: 1,
				alternatives: {}
			} satisfies DB.MetadataValue
		])
	)
}));
 
export const values = mapEntries(METADATA_TYPES, (typ) => [
	typ,
	items
		.filter((item) => item.metadata[`metadata_${typ}`] !== undefined)
		.map((item) => [item.id, item.metadata[`metadata_${typ}`]!.value] as const)
]);