diff --git a/examples/index.ts b/examples/index.ts new file mode 100644 index 0000000..9d0f04f --- /dev/null +++ b/examples/index.ts @@ -0,0 +1,20 @@ +import { Type } from '@sinclair/typebox'; +import { Spreadsheet, Table } from '../src'; + +const userTable = Table('users', { + id: Type.Number(), + value: Type.String(), +}); + +const itemTable = Table('items', { + id: Type.Number(), + name: Type.String(), +}); + +const sheet = Spreadsheet('1SbX2kgAGsslbhGuB-EI_YdSAnIt3reU1_OEtWmDVOVk', [ + userTable, + itemTable, +]); + +const users = sheet.get('users'); +const items = sheet.get('items'); diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..36a87b7 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,2 @@ +export * from './spreadsheet'; +export * from './table'; diff --git a/src/spreadsheet.ts b/src/spreadsheet.ts new file mode 100644 index 0000000..884220e --- /dev/null +++ b/src/spreadsheet.ts @@ -0,0 +1,25 @@ +import { + Type, + type Static, + type TKeyOf, + type TIndexFromPropertyKey, + type Intersect, +} from '@sinclair/typebox'; +import type { TableDefition } from './table'; + +export function Spreadsheet[]>( + sheetsId: string, + tables: [...T] +) { + const tablesSchema = Type.Intersect(tables); + + return { + get>>( + tableName: N + ): Static, N>> { + const itemSchema = Type.Index(tablesSchema, [tableName]); + + return {} as Static; + }, + }; +} diff --git a/src/table.ts b/src/table.ts new file mode 100644 index 0000000..69fe30a --- /dev/null +++ b/src/table.ts @@ -0,0 +1,19 @@ +import { + Type, + type TProperties, + type TObject, + type TConst, + type TRecordOrObject, +} from '@sinclair/typebox'; + +export type TableDefition< + N extends string, + S extends TProperties +> = TRecordOrObject, TObject>; + +export function Table( + name: N, + schema: S +) { + return Type.Record(Type.Const(name), Type.Object(schema)); +}