effect-mongodb 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AggregationCursor/package.json +6 -0
- package/DocumentAggregationCursor/package.json +6 -0
- package/ListCollectionsCursor/package.json +6 -0
- package/README.md +2 -2
- package/dist/cjs/AggregationCursor.js +34 -0
- package/dist/cjs/AggregationCursor.js.map +1 -0
- package/dist/cjs/Collection.js +22 -2
- package/dist/cjs/Collection.js.map +1 -1
- package/dist/cjs/Db.js +7 -1
- package/dist/cjs/Db.js.map +1 -1
- package/dist/cjs/DocumentAggregationCursor.js +27 -0
- package/dist/cjs/DocumentAggregationCursor.js.map +1 -0
- package/dist/cjs/DocumentCollection.js +15 -1
- package/dist/cjs/DocumentCollection.js.map +1 -1
- package/dist/cjs/DocumentFindCursor.js +4 -0
- package/dist/cjs/DocumentFindCursor.js.map +1 -1
- package/dist/cjs/FindCursor.js +7 -1
- package/dist/cjs/FindCursor.js.map +1 -1
- package/dist/cjs/ListCollectionsCursor.js +27 -0
- package/dist/cjs/ListCollectionsCursor.js.map +1 -0
- package/dist/cjs/index.js +7 -1
- package/dist/cjs/internal/filter.js +6 -0
- package/dist/cjs/internal/filter.js.map +1 -0
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/AggregationCursor.d.ts +18 -0
- package/dist/dts/AggregationCursor.d.ts.map +1 -0
- package/dist/dts/Collection.d.ts +41 -14
- package/dist/dts/Collection.d.ts.map +1 -1
- package/dist/dts/Db.d.ts +28 -3
- package/dist/dts/Db.d.ts.map +1 -1
- package/dist/dts/DocumentAggregationCursor.d.ts +15 -0
- package/dist/dts/DocumentAggregationCursor.d.ts.map +1 -0
- package/dist/dts/DocumentCollection.d.ts +31 -5
- package/dist/dts/DocumentCollection.d.ts.map +1 -1
- package/dist/dts/DocumentFindCursor.d.ts +1 -4
- package/dist/dts/DocumentFindCursor.d.ts.map +1 -1
- package/dist/dts/FindCursor.d.ts +15 -18
- package/dist/dts/FindCursor.d.ts.map +1 -1
- package/dist/dts/ListCollectionsCursor.d.ts +20 -0
- package/dist/dts/ListCollectionsCursor.d.ts.map +1 -0
- package/dist/dts/index.d.ts +12 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/filter.d.ts +8 -0
- package/dist/dts/internal/filter.d.ts.map +1 -0
- package/dist/esm/AggregationCursor.js +22 -0
- package/dist/esm/AggregationCursor.js.map +1 -0
- package/dist/esm/Collection.js +20 -1
- package/dist/esm/Collection.js.map +1 -1
- package/dist/esm/Db.js +6 -0
- package/dist/esm/Db.js.map +1 -1
- package/dist/esm/DocumentAggregationCursor.js +15 -0
- package/dist/esm/DocumentAggregationCursor.js.map +1 -0
- package/dist/esm/DocumentCollection.js +13 -0
- package/dist/esm/DocumentCollection.js.map +1 -1
- package/dist/esm/DocumentFindCursor.js +3 -0
- package/dist/esm/DocumentFindCursor.js.map +1 -1
- package/dist/esm/FindCursor.js +6 -1
- package/dist/esm/FindCursor.js.map +1 -1
- package/dist/esm/ListCollectionsCursor.js +15 -0
- package/dist/esm/ListCollectionsCursor.js.map +1 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/filter.js +2 -0
- package/dist/esm/internal/filter.js.map +1 -0
- package/dist/esm/internal/version.js +1 -1
- package/package.json +26 -3
- package/src/AggregationCursor.ts +37 -0
- package/src/Collection.ts +224 -22
- package/src/Db.ts +47 -3
- package/src/DocumentAggregationCursor.ts +30 -0
- package/src/DocumentCollection.ts +194 -2
- package/src/DocumentFindCursor.ts +1 -1
- package/src/FindCursor.ts +22 -21
- package/src/ListCollectionsCursor.ts +45 -0
- package/src/index.ts +15 -0
- package/src/internal/filter.ts +9 -0
- package/src/internal/version.ts +1 -1
package/src/FindCursor.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 0.0.1
|
|
3
3
|
*/
|
|
4
|
-
import type * as ParseResult from "@effect/schema/ParseResult"
|
|
5
|
-
import * as Schema from "@effect/schema/Schema"
|
|
6
4
|
import * as Data from "effect/Data"
|
|
7
5
|
import * as Effect from "effect/Effect"
|
|
6
|
+
import type * as E from "effect/Either"
|
|
8
7
|
import * as F from "effect/Function"
|
|
8
|
+
import type * as ParseResult from "effect/ParseResult"
|
|
9
|
+
import * as Schema from "effect/Schema"
|
|
9
10
|
import * as Stream from "effect/Stream"
|
|
10
11
|
import * as Tuple from "effect/Tuple"
|
|
11
12
|
import type { Document, FindCursor as FindCursor_, Sort, SortDirection } from "mongodb"
|
|
12
13
|
import * as MongoError from "./MongoError.js"
|
|
13
14
|
|
|
14
|
-
import type * as E from "effect/Either"
|
|
15
|
-
|
|
16
15
|
export class FindCursor<A, I = A, R = never> extends Data.TaggedClass("FindCursor")<{
|
|
17
16
|
cursor: FindCursor_<unknown>
|
|
18
17
|
schema: Schema.Schema<A, I, R>
|
|
@@ -21,32 +20,32 @@ export class FindCursor<A, I = A, R = never> extends Data.TaggedClass("FindCurso
|
|
|
21
20
|
export const filter: {
|
|
22
21
|
<T extends Document = Document>(
|
|
23
22
|
filter: T
|
|
24
|
-
): <A, I
|
|
25
|
-
<A, I
|
|
23
|
+
): <A, I, R>(cursor: FindCursor<A, I, R>) => FindCursor<A, I, R>
|
|
24
|
+
<A, I, R, T extends Document = Document>(
|
|
26
25
|
cursor: FindCursor<A, I, R>,
|
|
27
26
|
filter: T
|
|
28
27
|
): FindCursor<A, I, R>
|
|
29
28
|
} = F.dual(
|
|
30
29
|
(args) => isFindCursor(args[0]),
|
|
31
|
-
<A, I
|
|
30
|
+
<A, I, R, T extends Document = Document>(
|
|
32
31
|
cursor: FindCursor<A, I, R>,
|
|
33
32
|
filter: T
|
|
34
33
|
): FindCursor<A, I, R> => new FindCursor({ cursor: cursor.cursor.filter(filter), schema: cursor.schema })
|
|
35
34
|
)
|
|
36
35
|
|
|
37
36
|
export const project: {
|
|
38
|
-
<B, BI
|
|
37
|
+
<B, BI, BR, T extends Document = Document>(
|
|
39
38
|
newSchema: Schema.Schema<B, BI, BR>,
|
|
40
39
|
value: T
|
|
41
|
-
): <A, I
|
|
42
|
-
<A, B, I
|
|
40
|
+
): <A, I, R>(cursor: FindCursor<A, I, R>) => FindCursor<B, BI, BR>
|
|
41
|
+
<A, B, I, R, BI, BR, T extends Document = Document>(
|
|
43
42
|
cursor: FindCursor<A, I, R>,
|
|
44
43
|
newSchema: Schema.Schema<B, BI, BR>,
|
|
45
44
|
value: T
|
|
46
45
|
): FindCursor<B, BI, BR>
|
|
47
46
|
} = F.dual(
|
|
48
47
|
(args) => isFindCursor(args[0]),
|
|
49
|
-
<A, B, I
|
|
48
|
+
<A, B, I, R, BI, BR, T extends Document = Document>(
|
|
50
49
|
cursor: FindCursor<A, I, R>,
|
|
51
50
|
newSchema: Schema.Schema<B, BI, BR>,
|
|
52
51
|
value: T
|
|
@@ -57,15 +56,15 @@ export const sort: {
|
|
|
57
56
|
(
|
|
58
57
|
sort: Sort | string,
|
|
59
58
|
direction?: SortDirection
|
|
60
|
-
): <A, I
|
|
61
|
-
<A, I
|
|
59
|
+
): <A, I, R>(cursor: FindCursor<A, I, R>) => FindCursor<A, I, R>
|
|
60
|
+
<A, I, R>(
|
|
62
61
|
cursor: FindCursor<A, I, R>,
|
|
63
62
|
sort: Sort | string,
|
|
64
63
|
direction?: SortDirection
|
|
65
64
|
): FindCursor<A, I, R>
|
|
66
65
|
} = F.dual(
|
|
67
66
|
(args) => isFindCursor(args[0]),
|
|
68
|
-
<A, I
|
|
67
|
+
<A, I, R>(
|
|
69
68
|
cursor: FindCursor<A, I, R>,
|
|
70
69
|
sort: Sort | string,
|
|
71
70
|
direction?: SortDirection
|
|
@@ -75,15 +74,16 @@ export const sort: {
|
|
|
75
74
|
export const limit: {
|
|
76
75
|
(
|
|
77
76
|
value: number
|
|
78
|
-
): <A, I
|
|
79
|
-
<A, I
|
|
77
|
+
): <A, I, R>(cursor: FindCursor<A, I, R>) => FindCursor<A, I, R>
|
|
78
|
+
<A, I, R>(cursor: FindCursor<A, I, R>, value: number): FindCursor<A, I, R>
|
|
80
79
|
} = F.dual(
|
|
81
80
|
(args) => isFindCursor(args[0]),
|
|
82
|
-
<A, I
|
|
81
|
+
<A, I, R>(cursor: FindCursor<A, I, R>, value: number): FindCursor<A, I, R> =>
|
|
83
82
|
new FindCursor({ cursor: cursor.cursor.limit(value), schema: cursor.schema })
|
|
84
83
|
)
|
|
85
84
|
|
|
86
|
-
|
|
85
|
+
// TODO: add explicit return type for public API
|
|
86
|
+
export const toArray = <A, I, R>(cursor: FindCursor<A, I, R>) => {
|
|
87
87
|
const decode = Schema.decodeUnknown(cursor.schema)
|
|
88
88
|
return Effect.tryPromise({ try: () => cursor.cursor.toArray(), catch: F.identity }).pipe(
|
|
89
89
|
Effect.catchAll(MongoError.mongoErrorDie<ReadonlyArray<A>>("Unable to get array from mongodb cursor")),
|
|
@@ -91,7 +91,8 @@ export const toArray = <A, I = A, R = never>(cursor: FindCursor<A, I, R>) => {
|
|
|
91
91
|
)
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
// TODO: add explicit return type for public API
|
|
95
|
+
export const toArrayEither = <A, I, R>(cursor: FindCursor<A, I, R>) => {
|
|
95
96
|
const decode = Schema.decodeUnknown(cursor.schema)
|
|
96
97
|
return Effect.tryPromise({ try: () => cursor.cursor.toArray(), catch: F.identity }).pipe(
|
|
97
98
|
Effect.catchAll(MongoError.mongoErrorDie<ReadonlyArray<A>>("Unable to get array from mongodb cursor")),
|
|
@@ -106,7 +107,7 @@ export const toArrayEither = <A, I = A, R = never>(cursor: FindCursor<A, I, R>)
|
|
|
106
107
|
)
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
export const toStream = <A, I
|
|
110
|
+
export const toStream = <A, I, R>(
|
|
110
111
|
cursor: FindCursor<A, I, R>
|
|
111
112
|
): Stream.Stream<A, MongoError.MongoError | ParseResult.ParseError, R> => {
|
|
112
113
|
const decode = Schema.decodeUnknown(cursor.schema)
|
|
@@ -117,7 +118,7 @@ export const toStream = <A, I = A, R = never>(
|
|
|
117
118
|
)
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
export const toStreamEither = <A, I
|
|
121
|
+
export const toStreamEither = <A, I, R>(
|
|
121
122
|
cursor: FindCursor<A, I, R>
|
|
122
123
|
): Stream.Stream<E.Either<A, [document: unknown, error: ParseResult.ParseError]>, MongoError.MongoError, R> => {
|
|
123
124
|
const decode = Schema.decodeUnknown(cursor.schema)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.0.1
|
|
3
|
+
*/
|
|
4
|
+
import * as Data from "effect/Data"
|
|
5
|
+
import * as Effect from "effect/Effect"
|
|
6
|
+
import * as F from "effect/Function"
|
|
7
|
+
import * as Stream from "effect/Stream"
|
|
8
|
+
import type {
|
|
9
|
+
CollectionInfo as MongoCollectionInfo,
|
|
10
|
+
ListCollectionsCursor as MongoListCollectionsCursor
|
|
11
|
+
} from "mongodb"
|
|
12
|
+
import * as MongoError from "./MongoError.js"
|
|
13
|
+
|
|
14
|
+
export type NameOnlyCollectionInfo = Pick<MongoCollectionInfo, "name" | "type">
|
|
15
|
+
export type FullCollectionInfo = MongoCollectionInfo
|
|
16
|
+
|
|
17
|
+
type DefaultCollectionInfo = NameOnlyCollectionInfo | FullCollectionInfo
|
|
18
|
+
|
|
19
|
+
export class ListCollectionsCursor<
|
|
20
|
+
T extends DefaultCollectionInfo = DefaultCollectionInfo
|
|
21
|
+
> extends Data.TaggedClass("ListCollectionsCursor")<{
|
|
22
|
+
cursor: MongoListCollectionsCursor<T>
|
|
23
|
+
}> {}
|
|
24
|
+
|
|
25
|
+
export type NameOnlyListCollectionsCursor = ListCollectionsCursor<
|
|
26
|
+
Pick<MongoCollectionInfo, "name" | "type">
|
|
27
|
+
>
|
|
28
|
+
|
|
29
|
+
export type FullListCollectionsCursor = ListCollectionsCursor<MongoCollectionInfo>
|
|
30
|
+
|
|
31
|
+
export const toArray = <T extends DefaultCollectionInfo>(
|
|
32
|
+
cursor: ListCollectionsCursor<T>
|
|
33
|
+
): Effect.Effect<ReadonlyArray<T>, MongoError.MongoError> =>
|
|
34
|
+
F.pipe(
|
|
35
|
+
Effect.tryPromise({ try: () => cursor.cursor.toArray(), catch: F.identity }),
|
|
36
|
+
Effect.catchAll(MongoError.mongoErrorDie<ReadonlyArray<T>>(`${cursor._tag}.toArray error`))
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
export const toStream = <T extends DefaultCollectionInfo>(
|
|
40
|
+
cursor: ListCollectionsCursor<T>
|
|
41
|
+
): Stream.Stream<T, MongoError.MongoError> =>
|
|
42
|
+
F.pipe(
|
|
43
|
+
Stream.fromAsyncIterable(cursor.cursor, F.identity),
|
|
44
|
+
Stream.catchAll(MongoError.mongoErrorStream<T>(`${cursor._tag}.toStream error`))
|
|
45
|
+
)
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.0.1
|
|
3
|
+
*/
|
|
4
|
+
export * as AggregationCursor from "./AggregationCursor.js"
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* @since 0.0.1
|
|
3
8
|
*/
|
|
@@ -8,6 +13,11 @@ export * as Collection from "./Collection.js"
|
|
|
8
13
|
*/
|
|
9
14
|
export * as Db from "./Db.js"
|
|
10
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @since 0.0.1
|
|
18
|
+
*/
|
|
19
|
+
export * as DocumentAggregationCursor from "./DocumentAggregationCursor.js"
|
|
20
|
+
|
|
11
21
|
/**
|
|
12
22
|
* @since 0.0.1
|
|
13
23
|
*/
|
|
@@ -23,6 +33,11 @@ export * as DocumentFindCursor from "./DocumentFindCursor.js"
|
|
|
23
33
|
*/
|
|
24
34
|
export * as FindCursor from "./FindCursor.js"
|
|
25
35
|
|
|
36
|
+
/**
|
|
37
|
+
* @since 0.0.1
|
|
38
|
+
*/
|
|
39
|
+
export * as ListCollectionsCursor from "./ListCollectionsCursor.js"
|
|
40
|
+
|
|
26
41
|
/**
|
|
27
42
|
* @since 0.0.1
|
|
28
43
|
*/
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Condition, RootFilterOperators as MongoRootFilterOperators, WithId } from "mongodb"
|
|
2
|
+
|
|
3
|
+
export type RootFilterOperators<TSchema> = Omit<MongoRootFilterOperators<TSchema>, "$where"> & { $where?: string }
|
|
4
|
+
|
|
5
|
+
export type Filter<TSchema> =
|
|
6
|
+
& {
|
|
7
|
+
[P in keyof WithId<TSchema>]?: Condition<WithId<TSchema>[P]>
|
|
8
|
+
}
|
|
9
|
+
& RootFilterOperators<WithId<TSchema>>
|
package/src/internal/version.ts
CHANGED