Skip to content

Commit

Permalink
Export options types, get rid of default exports
Browse files Browse the repository at this point in the history
  • Loading branch information
kossnocorp committed Jun 22, 2021
1 parent 15cee67 commit 2de3a19
Show file tree
Hide file tree
Showing 35 changed files with 17,236 additions and 218 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ See below for details.

- **BREAKING**: Moved `onMissing` to options in `getMany`.

- **BREAKING**: All modules now export functions as named exports instead of using `default`.

- **BREAKING**: `Query` type now exported from `typesaurus` or `typesaurus/types` instead of `typesaurus/query` and `typesaurus/onQuery`.

- Export options types for all functions.

- `TransactionWriteFunction` no longer expect to return a promise.

## 7.2.0 - 2021-05-25
Expand Down
16,978 changes: 16,978 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { ref } from '../ref'
import type { OperationOptions, RuntimeEnvironment, WriteModel } from '../types'
import { assertEnvironment } from '../_lib/assertEnvironment'

export type AddOptions<
Environment extends RuntimeEnvironment | undefined
> = OperationOptions<Environment>

/**
* Adds a new document with a random id to a collection.
*
Expand All @@ -23,7 +27,7 @@ import { assertEnvironment } from '../_lib/assertEnvironment'
* @param data - The data to add to
* @returns A promise to the ref
*/
export default async function add<
export async function add<
Model,
Environment extends RuntimeEnvironment | undefined = undefined
>(
Expand Down
5 changes: 2 additions & 3 deletions src/add/test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import assert from 'assert'
import { nanoid } from 'nanoid'
import add from '.'
import { add } from '.'
import { collection } from '../collection'
import get from '../get'
import { get } from '../get'
import { Ref, ref } from '../ref'
import { ServerDate } from '../types'
import { value } from '../value'
Expand Down
9 changes: 7 additions & 2 deletions src/all/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import type {
} from '../types'
import { assertEnvironment } from '../_lib/assertEnvironment'

export type AllOptionns<
Environment extends RuntimeEnvironment | undefined,
ServerTimestamps extends ServerTimestampsStrategy
> = DocOptions<ServerTimestamps> & OperationOptions<Environment>

/**
* Returns all documents in a collection.
*
Expand All @@ -34,13 +39,13 @@ import { assertEnvironment } from '../_lib/assertEnvironment'
* @param collection - The collection to get all documents from
* @returns A promise to all documents
*/
export default async function all<
export async function all<
Model,
Environment extends RuntimeEnvironment | undefined,
ServerTimestamps extends ServerTimestampsStrategy
>(
collection: Collection<Model> | CollectionGroup<Model>,
options?: DocOptions<ServerTimestamps> & OperationOptions<Environment>
options?: AllOptionns<Environment, ServerTimestamps>
): Promise<AnyDoc<Model, Environment, boolean, ServerTimestamps>[]> {
const a = await adaptor()

Expand Down
14 changes: 7 additions & 7 deletions src/all/test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import all from '../all'
import assert from 'assert'
import set from '../set'
import { nanoid } from 'nanoid'
import { add } from '../add'
import { all } from '../all'
import { collection } from '../collection'
import { get } from '../get'
import { group } from '../group'
import { Ref, ref } from '../ref'
import get from '../get'
import remove from '../remove'
import { nanoid } from 'nanoid'
import { remove } from '../remove'
import { set } from '../set'
import { subcollection } from '../subcollection'
import add from '../add'
import { group } from '../group'

describe('all', () => {
type Book = { title: string }
Expand Down
4 changes: 2 additions & 2 deletions src/batch/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { pick } from 'js-fns'
import { nanoid } from 'nanoid'
import { batch } from '.'
import { collection } from '../collection'
import get from '../get'
import { get } from '../get'
import { ref } from '../ref'
import set from '../set'
import { set } from '../set'

describe('batch', () => {
type User = { name: string; foo?: boolean }
Expand Down
24 changes: 11 additions & 13 deletions src/field/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export interface Field<_Model> {
value: any
}

function field<Model, Key extends keyof Model>(
export function field<Model, Key extends keyof Model>(
key: Key | [Key],
value: Model[Key] | UpdateValue<Model, Key>
): Field<Model>

function field<
export function field<
Model,
Key1 extends keyof Model,
Key2 extends keyof Whole<Model, Key1>
Expand All @@ -38,7 +38,7 @@ function field<
value: PartialValue<Model, Key1, Key2> | UpdateValue<Whole<Model, Key1>, Key2>
): Field<Model>

function field<
export function field<
Model,
Key1 extends keyof Model,
Key2 extends keyof Model[Key1],
Expand All @@ -48,7 +48,7 @@ function field<
value: Model[Key1][Key2][Key3] | UpdateValue<Model[Key1][Key2], Key3>
): Field<Model>

function field<
export function field<
Model,
Key1 extends keyof Model,
Key2 extends keyof Model[Key1],
Expand All @@ -61,7 +61,7 @@ function field<
| UpdateValue<Model[Key1][Key2][Key3], Key4>
): Field<Model>

function field<
export function field<
Model,
Key1 extends keyof Model,
Key2 extends keyof Model[Key1],
Expand All @@ -75,7 +75,7 @@ function field<
| UpdateValue<Model[Key1][Key2][Key3][Key4], Key5>
): Field<Model>

function field<
export function field<
Model,
Key1 extends keyof Model,
Key2 extends keyof Model[Key1],
Expand All @@ -90,7 +90,7 @@ function field<
| UpdateValue<Model[Key1][Key2][Key3][Key4][Key5], Key6>
): Field<Model>

function field<
export function field<
Model,
Key1 extends keyof Model,
Key2 extends keyof Model[Key1],
Expand All @@ -106,7 +106,7 @@ function field<
| UpdateValue<Model[Key1][Key2][Key3][Key4][Key5][Key6], Key7>
): Field<Model>

function field<
export function field<
Model,
Key1 extends keyof Model,
Key2 extends keyof Model[Key1],
Expand All @@ -123,7 +123,7 @@ function field<
| UpdateValue<Model[Key1][Key2][Key3][Key4][Key5][Key6][Key7], Key8>
): Field<Model>

function field<
export function field<
Model,
Key1 extends keyof Model,
Key2 extends keyof Model[Key1],
Expand All @@ -141,7 +141,7 @@ function field<
| UpdateValue<Model[Key1][Key2][Key3][Key4][Key5][Key6][Key7][Key8], Key9>
): Field<Model>

function field<
export function field<
Model,
Key1 extends keyof Model,
Key2 extends keyof Model[Key1],
Expand Down Expand Up @@ -183,8 +183,6 @@ function field<
* @param value - The value
* @returns The field object
*/
function field<Model>(key: string | string[], value: any): Field<Model> {
export function field<Model>(key: string | string[], value: any): Field<Model> {
return { key, value }
}

export default field
2 changes: 1 addition & 1 deletion src/field/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import field, { Field } from '.'
import { field, Field } from '.'
import { value } from '../value'

describe('field', () => {
Expand Down
30 changes: 14 additions & 16 deletions src/get/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@ import type {
} from '../types'
import { assertEnvironment } from '../_lib/assertEnvironment'

type Options<
Environment extends RuntimeEnvironment,
export type GetOptions<
Environment extends RuntimeEnvironment | undefined,
ServerTimestamps extends ServerTimestampsStrategy
> = DocOptions<ServerTimestamps> & OperationOptions<Environment>

/**
* @param ref - The reference to the document
*/
async function get<
export async function get<
Model,
Environment extends RuntimeEnvironment,
Environment extends RuntimeEnvironment | undefined,
ServerTimestamps extends ServerTimestampsStrategy
>(
ref: Ref<Model>,
options?: Options<Environment, ServerTimestamps>
options?: GetOptions<Environment, ServerTimestamps>
): Promise<Doc<Model> | null>

/**
* @param collection - The collection to get document from
* @param id - The document id
*/
async function get<
export async function get<
Model,
Environment extends RuntimeEnvironment,
Environment extends RuntimeEnvironment | undefined,
ServerTimestamps extends ServerTimestampsStrategy
>(
collection: Collection<Model>,
id: string,
options?: Options<Environment, ServerTimestamps>
options?: GetOptions<Environment, ServerTimestamps>
): Promise<Doc<Model> | null>

/**
Expand All @@ -61,14 +61,14 @@ async function get<
*
* @returns Promise to the document or null if not found
*/
async function get<
export async function get<
Model,
Environment extends RuntimeEnvironment,
Environment extends RuntimeEnvironment | undefined,
ServerTimestamps extends ServerTimestampsStrategy
>(
collectionOrRef: Collection<Model> | Ref<Model>,
maybeIdOrOptions?: string | Options<Environment, ServerTimestamps>,
maybeOptions?: Options<Environment, ServerTimestamps>
maybeIdOrOptions?: string | GetOptions<Environment, ServerTimestamps>,
maybeOptions?: GetOptions<Environment, ServerTimestamps>
): Promise<AnyDoc<
Model,
RuntimeEnvironment,
Expand All @@ -78,7 +78,7 @@ async function get<
const a = await adaptor()
let collection: Collection<Model>
let id: string
let options: Options<Environment, ServerTimestamps> | undefined
let options: GetOptions<Environment, ServerTimestamps> | undefined

if (collectionOrRef.__type__ === 'collection') {
collection = collectionOrRef as Collection<Model>
Expand All @@ -89,7 +89,7 @@ async function get<
collection = ref.collection
id = ref.id
options = maybeIdOrOptions as
| Options<Environment, ServerTimestamps>
| GetOptions<Environment, ServerTimestamps>
| undefined
}

Expand All @@ -107,5 +107,3 @@ async function get<
})
: null
}

export default get
4 changes: 2 additions & 2 deletions src/get/test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'assert'
import get from '.'
import add from '../add'
import { get } from '.'
import { add } from '../add'
import { collection } from '../collection'
import { Ref, ref } from '../ref'

Expand Down
18 changes: 12 additions & 6 deletions src/getMany/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ import type {
} from '../types'
import { assertEnvironment } from '../_lib/assertEnvironment'

export type GetManyOptions<
Model,
Environment extends RuntimeEnvironment | undefined,
ServerTimestamps extends ServerTimestampsStrategy
> = DocOptions<ServerTimestamps> &
OperationOptions<Environment> &
OnMissingOptions<Model>

export const defaultOnMissing: OnMissing<any> = (id) => {
throw new Error(`Missing document with id ${id}`)
}
Expand Down Expand Up @@ -41,7 +49,7 @@ export const defaultOnMissing: OnMissing<any> = (id) => {
*
* @returns Promise to a list of found documents
*/
export default async function getMany<
export async function getMany<
Model,
Environment extends RuntimeEnvironment | undefined,
ServerTimestamps extends ServerTimestampsStrategy
Expand All @@ -51,10 +59,8 @@ export default async function getMany<
{
onMissing = defaultOnMissing,
...options
}: DocOptions<ServerTimestamps> &
OperationOptions<Environment> &
OnMissingOptions<Model> = {}
): Promise<AnyDoc<Model, RuntimeEnvironment, boolean, ServerTimestamps>[]> {
}: GetManyOptions<Model, Environment, ServerTimestamps> = {}
): Promise<AnyDoc<Model, Environment, boolean, ServerTimestamps>[]> {
const a = await adaptor()

assertEnvironment(a, options?.assertEnvironment)
Expand Down Expand Up @@ -96,7 +102,7 @@ export default async function getMany<
})
.filter((doc) => doc != null) as AnyDoc<
Model,
RuntimeEnvironment,
Environment,
boolean,
ServerTimestamps
>[]
Expand Down
6 changes: 3 additions & 3 deletions src/getMany/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getMany } from '.'
import { collection } from '../collection'
import set from '../set'
import getMany from '.'
import remove from '../remove'
import { remove } from '../remove'
import { set } from '../set'

describe('getMany', () => {
type Fruit = { color: string }
Expand Down
Loading

0 comments on commit 2de3a19

Please sign in to comment.