-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add basic table and spreadsheet type interface
- Loading branch information
Showing
4 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './spreadsheet'; | ||
export * from './table'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T extends TableDefition<any, any>[]>( | ||
sheetsId: string, | ||
tables: [...T] | ||
) { | ||
const tablesSchema = Type.Intersect(tables); | ||
|
||
return { | ||
get<N extends Static<TKeyOf<typeof tablesSchema>>>( | ||
tableName: N | ||
): Static<TIndexFromPropertyKey<Intersect<T>, N>> { | ||
const itemSchema = Type.Index(tablesSchema, [tableName]); | ||
|
||
return {} as Static<typeof itemSchema>; | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TConst<N>, TObject<S>>; | ||
|
||
export function Table<N extends string, S extends TProperties>( | ||
name: N, | ||
schema: S | ||
) { | ||
return Type.Record(Type.Const(name), Type.Object(schema)); | ||
} |