@type-map-for/typesense
v0.1.1
Published
Compile-time TypeScript → Typesense field mapping
Readme
@type-map-for/typesense
Generate Typesense collection schemas from TypeScript interfaces at compile time.
Installation
npm install @type-map-for/typesenseUsage
import type { TypesenseFieldMap } from '@type-map-for/typesense';
interface Product {
id: string;
name: string;
price: number;
tags?: string[];
metadata: { category: string };
}
type ProductSchema = TypesenseFieldMap<Product>;
// Result: Array<{
// { name: 'id'; type: 'string'; optional: false }
// { name: 'name'; type: 'string'; optional: false }
// { name: 'price'; type: 'int32'; optional: false }
// { name: 'tags'; type: 'string[]'; optional: true }
// { name: 'metadata'; type: 'object'; optional: false }
// }>
// Use with schema validation
const productSchema: ProductSchema = [
{ name: 'id', type: 'string', optional: false },
{ name: 'name', type: 'string', optional: false },
{ name: 'price', type: 'int32', optional: false },
{ name: 'tags', type: 'string[]', optional: true },
{ name: 'metadata', type: 'object', optional: false }
] as const satisfies ProductSchema;Type Mapping
| TypeScript | Typesense |
|------------|-----------|
| string | string |
| string[] | string[] |
| number | int32 | float |
| number[] | int32[] | float[] |
| boolean | bool |
| boolean[] | bool[] |
| object | object |
| object[] | object[] |
| T \| undefined | optional: true |
Types
TypesenseField<T, K>- Schema field for propertyKof typeTTypesenseFieldMap<T>- Complete schema array for interfaceT
Contributing
Issues and pull requests welcome at github.com/nathancanine/type-map-for.
License
MIT
