-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd9299f
commit 9f1e32d
Showing
25 changed files
with
644 additions
and
101 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,3 @@ | ||
node_modules | ||
secrets | ||
lib |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,38 @@ | ||
import { Ref } from '../ref' | ||
|
||
/** | ||
* The document type. It contains the reference in the DB and the model data. | ||
*/ | ||
export interface Doc<Model> { | ||
__type__: 'doc' | ||
data: Model | ||
ref: Ref<Model> | ||
} | ||
|
||
/** | ||
* Creates a document object. | ||
* | ||
* @param ref - The document reference | ||
* @param data - The model data | ||
* @returns The document object | ||
* | ||
* @example | ||
* import { doc, ref, collection } from 'typesaurus' | ||
* | ||
* type User = { name: string } | ||
* const users = collection<User>('users') | ||
* | ||
* doc(ref(users, '00sHm46UWKObv2W7XK9e'), { name: 'Sasha' }) | ||
* //=> { | ||
* //=> __type__: 'doc', | ||
* //=> data: { name: 'Sasha' }, | ||
* //=> ref: {, | ||
* //=> __type__: 'ref' | ||
* //=> collection: { __type__: 'collection', path: 'users' }, | ||
* //=> id: '00sHm46UWKObv2W7XK9e' | ||
* //=> } | ||
* //=> } | ||
*/ | ||
export function doc<Model>(ref: Ref<Model>, data: Model): Doc<Model> { | ||
return { __type__: 'doc', ref, data } | ||
} |
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
Oops, something went wrong.