-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[types] add UpdateParams and LinkParams (#653)
- Loading branch information
Showing
7 changed files
with
96 additions
and
41 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
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
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
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
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
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
39 changes: 39 additions & 0 deletions
39
client/sandbox/strong-init-vite/src/typescript_test_abstract.tsx
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,39 @@ | ||
import { i, id, init, UpdateParams } from "@instantdb/admin"; | ||
|
||
const _schema = i.schema({ entities: { users: i.entity({ email: i.string() }) } }); | ||
type _AppSchema = typeof _schema; | ||
interface AppSchema extends _AppSchema {} | ||
const schema: AppSchema = _schema; | ||
|
||
const db = init({ | ||
adminToken: "...", | ||
appId: "...", | ||
schema, | ||
}); | ||
|
||
type Collection = keyof typeof schema.entities; | ||
|
||
type EntityUpdate<T extends Collection> = UpdateParams<typeof schema, T>; | ||
|
||
export const newEntity = async <T extends Collection>( | ||
type: T, | ||
props: EntityUpdate<T>, | ||
) => { | ||
const theId = id(); | ||
await db.transact(db.tx[type][theId].update(props)); | ||
return theId; | ||
}; | ||
|
||
// seems good | ||
const existing_attr_works = await newEntity("users", { email: "[email protected]" }); | ||
|
||
// @ts-expect-error | ||
const non_existing_attr_errors = await newEntity("users", { blabla: "[email protected]" }); | ||
|
||
// @ts-expect-error | ||
const wrong_type_errors = await newEntity("users", { email: 123 }); | ||
|
||
// to silence ts warnings | ||
existing_attr_works; | ||
non_existing_attr_errors; | ||
wrong_type_errors; |