effect-mongodb 0.1.3 → 0.1.4
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/README.md +25 -19
- package/dist/cjs/AggregationCursor.js +10 -4
- package/dist/cjs/AggregationCursor.js.map +1 -1
- package/dist/cjs/Collection.js +19 -14
- package/dist/cjs/Collection.js.map +1 -1
- package/dist/cjs/Db.js +2 -2
- package/dist/cjs/Db.js.map +1 -1
- package/dist/cjs/DocumentAggregationCursor.js +10 -4
- package/dist/cjs/DocumentAggregationCursor.js.map +1 -1
- package/dist/cjs/DocumentCollection.js +15 -9
- package/dist/cjs/DocumentCollection.js.map +1 -1
- package/dist/cjs/DocumentFindCursor.js +16 -10
- package/dist/cjs/DocumentFindCursor.js.map +1 -1
- package/dist/cjs/FindCursor.js +15 -9
- package/dist/cjs/FindCursor.js.map +1 -1
- package/dist/cjs/ListCollectionsCursor.js +10 -4
- package/dist/cjs/ListCollectionsCursor.js.map +1 -1
- package/dist/cjs/internal/schema.js +2 -2
- package/dist/cjs/internal/schema.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/AggregationCursor.d.ts +5 -5
- package/dist/dts/AggregationCursor.d.ts.map +1 -1
- package/dist/dts/Collection.d.ts +5 -6
- package/dist/dts/Collection.d.ts.map +1 -1
- package/dist/dts/DocumentAggregationCursor.d.ts +5 -5
- package/dist/dts/DocumentAggregationCursor.d.ts.map +1 -1
- package/dist/dts/DocumentCollection.d.ts +5 -5
- package/dist/dts/DocumentCollection.d.ts.map +1 -1
- package/dist/dts/DocumentFindCursor.d.ts +5 -5
- package/dist/dts/DocumentFindCursor.d.ts.map +1 -1
- package/dist/dts/FindCursor.d.ts +5 -5
- package/dist/dts/FindCursor.d.ts.map +1 -1
- package/dist/dts/ListCollectionsCursor.d.ts +5 -5
- package/dist/dts/ListCollectionsCursor.d.ts.map +1 -1
- package/dist/esm/AggregationCursor.js +8 -2
- package/dist/esm/AggregationCursor.js.map +1 -1
- package/dist/esm/Collection.js +17 -12
- package/dist/esm/Collection.js.map +1 -1
- package/dist/esm/Db.js +2 -2
- package/dist/esm/Db.js.map +1 -1
- package/dist/esm/DocumentAggregationCursor.js +8 -2
- package/dist/esm/DocumentAggregationCursor.js.map +1 -1
- package/dist/esm/DocumentCollection.js +13 -7
- package/dist/esm/DocumentCollection.js.map +1 -1
- package/dist/esm/DocumentFindCursor.js +14 -8
- package/dist/esm/DocumentFindCursor.js.map +1 -1
- package/dist/esm/FindCursor.js +13 -7
- package/dist/esm/FindCursor.js.map +1 -1
- package/dist/esm/ListCollectionsCursor.js +8 -2
- package/dist/esm/ListCollectionsCursor.js.map +1 -1
- package/dist/esm/internal/schema.js +2 -2
- package/dist/esm/internal/schema.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/AggregationCursor.ts +20 -4
- package/src/Collection.ts +34 -13
- package/src/Db.ts +2 -2
- package/src/DocumentAggregationCursor.ts +16 -3
- package/src/DocumentCollection.ts +23 -8
- package/src/DocumentFindCursor.ts +23 -9
- package/src/FindCursor.ts +22 -8
- package/src/ListCollectionsCursor.ts +20 -5
- package/src/internal/schema.ts +2 -2
- package/src/internal/version.ts +1 -1
package/src/AggregationCursor.ts
CHANGED
|
@@ -5,15 +5,31 @@ import * as Data from "effect/Data"
|
|
|
5
5
|
import * as Effect from "effect/Effect"
|
|
6
6
|
import * as F from "effect/Function"
|
|
7
7
|
import type * as ParseResult from "effect/ParseResult"
|
|
8
|
+
import type { Pipeable } from "effect/Pipeable"
|
|
9
|
+
import { pipeArguments } from "effect/Pipeable"
|
|
8
10
|
import * as Schema from "effect/Schema"
|
|
9
11
|
import * as Stream from "effect/Stream"
|
|
10
12
|
import type { AggregationCursor as MongoAggregationCursor } from "mongodb"
|
|
11
13
|
import { mongoErrorOrDie } from "./internal/mongo-error.js"
|
|
12
14
|
import * as MongoError from "./MongoError.js"
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
>
|
|
16
|
+
interface AggregationCursorFields<A, I = A, R = never> {
|
|
17
|
+
cursor: MongoAggregationCursor<unknown>
|
|
18
|
+
schema: Schema.Schema<A, I, R>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AggregationCursor<A, I = A, R = never> extends AggregationCursorFields<A, I, R>, Pipeable {
|
|
22
|
+
_tag: "AggregationCursor"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** @internal */
|
|
26
|
+
export class AggregationCursorImpl<A, I = A, R = never>
|
|
27
|
+
extends Data.TaggedClass("AggregationCursor")<AggregationCursorFields<A, I, R>>
|
|
28
|
+
implements AggregationCursor<A, I, R>
|
|
29
|
+
{
|
|
30
|
+
pipe() {
|
|
31
|
+
return pipeArguments(this, arguments)
|
|
32
|
+
}
|
|
17
33
|
}
|
|
18
34
|
|
|
19
35
|
export const toArray = <A, I, R>(
|
|
@@ -39,7 +55,7 @@ export const toStream = <A, I, R>(
|
|
|
39
55
|
|
|
40
56
|
const errorSource = <A, I, R>(cursor: AggregationCursor<A, I, R>, functionName: string) =>
|
|
41
57
|
new MongoError.CollectionErrorSource({
|
|
42
|
-
module:
|
|
58
|
+
module: AggregationCursorImpl.name,
|
|
43
59
|
functionName,
|
|
44
60
|
db: cursor.cursor.namespace.db,
|
|
45
61
|
collection: cursor.cursor.namespace.collection ?? "NO_COLLECTION_NAME"
|
package/src/Collection.ts
CHANGED
|
@@ -7,6 +7,8 @@ import * as Effect from "effect/Effect"
|
|
|
7
7
|
import * as F from "effect/Function"
|
|
8
8
|
import type * as O from "effect/Option"
|
|
9
9
|
import type * as ParseResult from "effect/ParseResult"
|
|
10
|
+
import type { Pipeable } from "effect/Pipeable"
|
|
11
|
+
import { pipeArguments } from "effect/Pipeable"
|
|
10
12
|
import * as Schema from "effect/Schema"
|
|
11
13
|
import type {
|
|
12
14
|
AggregateOptions,
|
|
@@ -42,11 +44,28 @@ import { mongoErrorOrDie } from "./internal/mongo-error.js"
|
|
|
42
44
|
import * as SchemaExt from "./internal/schema.js"
|
|
43
45
|
import * as MongoError from "./MongoError.js"
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
type CollectionFields<A extends Document, I extends Document = A, R = never> = {
|
|
46
48
|
collection: MongoCollection
|
|
47
49
|
schema: Schema.Schema<A, I, R>
|
|
48
|
-
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface Collection<A extends Document, I extends Document = A, R = never>
|
|
53
|
+
extends CollectionFields<A, I, R>, Pipeable
|
|
54
|
+
{
|
|
55
|
+
_tag: "Collection"
|
|
56
|
+
/** @internal */
|
|
57
|
+
encode: ReturnType<typeof Schema.encode<A, I, R>>
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** @internal */
|
|
61
|
+
export class CollectionImpl<A extends Document, I extends Document = A, R = never>
|
|
62
|
+
extends Data.TaggedClass("Collection")<CollectionFields<A, I, R>>
|
|
63
|
+
implements Collection<A, I, R>
|
|
64
|
+
{
|
|
49
65
|
readonly encode = Schema.encode(this.schema)
|
|
66
|
+
pipe() {
|
|
67
|
+
return pipeArguments(this, arguments)
|
|
68
|
+
}
|
|
50
69
|
}
|
|
51
70
|
|
|
52
71
|
export type FindOptions = Omit<MongoFindOptions, "projection">
|
|
@@ -68,7 +87,7 @@ export const find: {
|
|
|
68
87
|
filter?: Filter<I>,
|
|
69
88
|
options?: FindOptions
|
|
70
89
|
): FindCursor.FindCursor<A, I, R> =>
|
|
71
|
-
new FindCursor.
|
|
90
|
+
new FindCursor.FindCursorImpl<A, I, R>({
|
|
72
91
|
cursor: collection.collection.find(filter ?? {}, options),
|
|
73
92
|
schema: collection.schema
|
|
74
93
|
})
|
|
@@ -90,9 +109,9 @@ export const findOne: {
|
|
|
90
109
|
filter: Filter<I>,
|
|
91
110
|
options?: FindOptions
|
|
92
111
|
): Effect.Effect<O.Option<A>, MongoError.MongoError | ParseResult.ParseError, R> =>
|
|
93
|
-
Effect.gen(function*(
|
|
94
|
-
const value = yield*
|
|
95
|
-
return yield*
|
|
112
|
+
Effect.gen(function*() {
|
|
113
|
+
const value = yield* Effect.promise(() => collection.collection.findOne(filter, options))
|
|
114
|
+
return yield* SchemaExt.decodeNullableDocument(collection.schema, value)
|
|
96
115
|
}).pipe(
|
|
97
116
|
Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "findOne")))
|
|
98
117
|
)
|
|
@@ -306,13 +325,13 @@ export const findOneAndReplace: {
|
|
|
306
325
|
Effect.promise(() => collection.collection.findOneAndReplace(filter, replacement, options ?? {}))
|
|
307
326
|
),
|
|
308
327
|
Effect.flatMap((value) =>
|
|
309
|
-
Effect.gen(function*(
|
|
328
|
+
Effect.gen(function*() {
|
|
310
329
|
if (options?.includeResultMetadata && !!value) {
|
|
311
330
|
const result = value as unknown as MongoModifyResult<I>
|
|
312
|
-
const maybeValue = yield*
|
|
331
|
+
const maybeValue = yield* SchemaExt.decodeNullableDocument(collection.schema, result.value)
|
|
313
332
|
return { ...result, value: maybeValue }
|
|
314
333
|
}
|
|
315
|
-
return yield*
|
|
334
|
+
return yield* SchemaExt.decodeNullableDocument(collection.schema, value)
|
|
316
335
|
})
|
|
317
336
|
),
|
|
318
337
|
Effect.catchAllDefect(
|
|
@@ -339,7 +358,9 @@ export const rename: {
|
|
|
339
358
|
): Effect.Effect<Collection<A, I, R>, MongoError.MongoError, R> =>
|
|
340
359
|
F.pipe(
|
|
341
360
|
Effect.promise(() => collection.collection.rename(newName, options)),
|
|
342
|
-
Effect.map((newCollection) =>
|
|
361
|
+
Effect.map((newCollection) =>
|
|
362
|
+
new CollectionImpl<A, I, R>({ collection: newCollection, schema: collection.schema })
|
|
363
|
+
),
|
|
343
364
|
Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "rename")))
|
|
344
365
|
)
|
|
345
366
|
)
|
|
@@ -455,7 +476,7 @@ export const aggregate: {
|
|
|
455
476
|
pipeline: ReadonlyArray<Document>,
|
|
456
477
|
options?: AggregateOptions
|
|
457
478
|
): AggregationCursor.AggregationCursor<B, BI, BR> =>
|
|
458
|
-
new AggregationCursor.
|
|
479
|
+
new AggregationCursor.AggregationCursorImpl<B, BI, BR>({
|
|
459
480
|
cursor: collection.collection.aggregate([...pipeline], options),
|
|
460
481
|
schema
|
|
461
482
|
})
|
|
@@ -503,14 +524,14 @@ export const countDocuments: {
|
|
|
503
524
|
)
|
|
504
525
|
)
|
|
505
526
|
|
|
506
|
-
const isCollection = (x: unknown) => x instanceof
|
|
527
|
+
const isCollection = (x: unknown) => x instanceof CollectionImpl
|
|
507
528
|
|
|
508
529
|
const errorSource = <A extends Document, I extends Document = A, R = never>(
|
|
509
530
|
collection: Collection<A, I, R>,
|
|
510
531
|
functionName: string
|
|
511
532
|
) =>
|
|
512
533
|
new MongoError.CollectionErrorSource({
|
|
513
|
-
module:
|
|
534
|
+
module: CollectionImpl.name,
|
|
514
535
|
functionName,
|
|
515
536
|
db: collection.collection.dbName,
|
|
516
537
|
collection: collection.collection.collectionName
|
package/src/Db.ts
CHANGED
|
@@ -18,7 +18,7 @@ export const documentCollection: {
|
|
|
18
18
|
} = F.dual(
|
|
19
19
|
(args) => isDb(args[0]),
|
|
20
20
|
(db: Db, name: string): DocumentCollection.DocumentCollection =>
|
|
21
|
-
new DocumentCollection.
|
|
21
|
+
new DocumentCollection.DocumentCollectionImpl({
|
|
22
22
|
collection: db.collection(name)
|
|
23
23
|
})
|
|
24
24
|
)
|
|
@@ -67,7 +67,7 @@ export const listCollections: {
|
|
|
67
67
|
} = F.dual(
|
|
68
68
|
(args) => isDb(args[0]),
|
|
69
69
|
(db: Db, filter?: Document, options?: ListCollectionsOptions): ListCollectionsCursor.ListCollectionsCursor =>
|
|
70
|
-
new ListCollectionsCursor.
|
|
70
|
+
new ListCollectionsCursor.ListCollectionsCursorImpl({ cursor: db.listCollections(filter, options) })
|
|
71
71
|
)
|
|
72
72
|
|
|
73
73
|
export const dropCollection: {
|
|
@@ -4,14 +4,27 @@
|
|
|
4
4
|
import * as Data from "effect/Data"
|
|
5
5
|
import * as Effect from "effect/Effect"
|
|
6
6
|
import * as F from "effect/Function"
|
|
7
|
+
import type { Pipeable } from "effect/Pipeable"
|
|
8
|
+
import { pipeArguments } from "effect/Pipeable"
|
|
7
9
|
import * as Stream from "effect/Stream"
|
|
8
10
|
import type { AggregationCursor as MongoAggregationCursor, Document } from "mongodb"
|
|
9
11
|
import { mongoErrorOrDie } from "./internal/mongo-error.js"
|
|
10
12
|
import * as MongoError from "./MongoError.js"
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
type DocumentAggregationCursorFields = { cursor: MongoAggregationCursor<Document> }
|
|
15
|
+
|
|
16
|
+
export interface DocumentAggregationCursor extends DocumentAggregationCursorFields, Pipeable {
|
|
17
|
+
_tag: "DocumentAggregationCursor"
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** @internal */
|
|
21
|
+
export class DocumentAggregationCursorImpl
|
|
22
|
+
extends Data.TaggedClass("DocumentAggregationCursor")<DocumentAggregationCursorFields>
|
|
23
|
+
implements DocumentAggregationCursor
|
|
14
24
|
{
|
|
25
|
+
pipe() {
|
|
26
|
+
return pipeArguments(this, arguments)
|
|
27
|
+
}
|
|
15
28
|
}
|
|
16
29
|
|
|
17
30
|
export const toArray = (
|
|
@@ -32,7 +45,7 @@ export const toStream = (
|
|
|
32
45
|
|
|
33
46
|
const errorSource = (cursor: DocumentAggregationCursor, functionName: string) =>
|
|
34
47
|
new MongoError.CollectionErrorSource({
|
|
35
|
-
module:
|
|
48
|
+
module: DocumentAggregationCursorImpl.name,
|
|
36
49
|
functionName,
|
|
37
50
|
db: cursor.cursor.namespace.db,
|
|
38
51
|
collection: cursor.cursor.namespace.collection ?? "NO_COLLECTION_NAME"
|
|
@@ -6,6 +6,8 @@ import * as Data from "effect/Data"
|
|
|
6
6
|
import * as Effect from "effect/Effect"
|
|
7
7
|
import * as F from "effect/Function"
|
|
8
8
|
import * as O from "effect/Option"
|
|
9
|
+
import type { Pipeable } from "effect/Pipeable"
|
|
10
|
+
import { pipeArguments } from "effect/Pipeable"
|
|
9
11
|
import type * as Schema from "effect/Schema"
|
|
10
12
|
import type {
|
|
11
13
|
AggregateOptions,
|
|
@@ -43,9 +45,21 @@ import type { ModifyResult } from "./internal/modify-result.js"
|
|
|
43
45
|
import { mongoErrorOrDie } from "./internal/mongo-error.js"
|
|
44
46
|
import * as MongoError from "./MongoError.js"
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
type DocumentCollectionFields = {
|
|
47
49
|
collection: MongoCollection
|
|
48
|
-
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface DocumentCollection extends DocumentCollectionFields, Pipeable {
|
|
53
|
+
_tag: "DocumentCollection"
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @internal */
|
|
57
|
+
export class DocumentCollectionImpl extends Data.TaggedClass("DocumentCollection")<DocumentCollectionFields>
|
|
58
|
+
implements DocumentCollection
|
|
59
|
+
{
|
|
60
|
+
pipe() {
|
|
61
|
+
return pipeArguments(this, arguments)
|
|
62
|
+
}
|
|
49
63
|
}
|
|
50
64
|
|
|
51
65
|
export const find: {
|
|
@@ -61,7 +75,7 @@ export const find: {
|
|
|
61
75
|
} = F.dual(
|
|
62
76
|
(args) => isDocumentCollection(args[0]),
|
|
63
77
|
(collection: DocumentCollection, filter?: Filter<Document>, options?: FindOptions) =>
|
|
64
|
-
new DocumentFindCursor.
|
|
78
|
+
new DocumentFindCursor.DocumentFindCursorImpl(
|
|
65
79
|
{
|
|
66
80
|
cursor: collection.collection.find(filter ?? {}, options)
|
|
67
81
|
}
|
|
@@ -327,7 +341,7 @@ export const rename: {
|
|
|
327
341
|
): Effect.Effect<DocumentCollection, MongoError.MongoError> =>
|
|
328
342
|
F.pipe(
|
|
329
343
|
Effect.promise(() => collection.collection.rename(newName, options)),
|
|
330
|
-
Effect.map((collection) => new
|
|
344
|
+
Effect.map((collection) => new DocumentCollectionImpl({ collection })),
|
|
331
345
|
Effect.catchAllDefect(mongoErrorOrDie(errorSource(collection, "rename")))
|
|
332
346
|
)
|
|
333
347
|
)
|
|
@@ -431,7 +445,7 @@ export const aggregate: {
|
|
|
431
445
|
pipeline?: ReadonlyArray<Document>,
|
|
432
446
|
options?: AggregateOptions
|
|
433
447
|
): DocumentAggregationCursor.DocumentAggregationCursor =>
|
|
434
|
-
new DocumentAggregationCursor.
|
|
448
|
+
new DocumentAggregationCursor.DocumentAggregationCursorImpl({
|
|
435
449
|
cursor: collection.collection.aggregate(pipeline ? [...pipeline] : undefined, options)
|
|
436
450
|
})
|
|
437
451
|
)
|
|
@@ -489,16 +503,17 @@ export const typed: {
|
|
|
489
503
|
} = F.dual((args) => isDocumentCollection(args[0]), <A extends Document, I extends Document = A, R = never>(
|
|
490
504
|
collection: DocumentCollection,
|
|
491
505
|
schema: Schema.Schema<A, I, R>
|
|
492
|
-
): Collection.Collection<A, I, R> =>
|
|
506
|
+
): Collection.Collection<A, I, R> =>
|
|
507
|
+
new Collection.CollectionImpl<A, I, R>({ collection: collection.collection, schema }))
|
|
493
508
|
|
|
494
|
-
const isDocumentCollection = (x: unknown) => x instanceof
|
|
509
|
+
const isDocumentCollection = (x: unknown) => x instanceof DocumentCollectionImpl
|
|
495
510
|
|
|
496
511
|
const errorSource = (
|
|
497
512
|
collection: DocumentCollection,
|
|
498
513
|
functionName: string
|
|
499
514
|
) =>
|
|
500
515
|
new MongoError.CollectionErrorSource({
|
|
501
|
-
module:
|
|
516
|
+
module: DocumentCollectionImpl.name,
|
|
502
517
|
functionName,
|
|
503
518
|
db: collection.collection.dbName,
|
|
504
519
|
collection: collection.collection.collectionName
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
import * as Data from "effect/Data"
|
|
5
5
|
import * as Effect from "effect/Effect"
|
|
6
6
|
import * as F from "effect/Function"
|
|
7
|
+
import type { Pipeable } from "effect/Pipeable"
|
|
8
|
+
import { pipeArguments } from "effect/Pipeable"
|
|
7
9
|
import type * as Schema from "effect/Schema"
|
|
8
10
|
import * as Stream from "effect/Stream"
|
|
9
11
|
import type { Document, Filter, FindCursor as MongoFindCursor, Sort, SortDirection } from "mongodb"
|
|
@@ -11,9 +13,21 @@ import * as FindCursor from "./FindCursor.js"
|
|
|
11
13
|
import { mongoErrorOrDie } from "./internal/mongo-error.js"
|
|
12
14
|
import * as MongoError from "./MongoError.js"
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
type DocumentFindCursorFields = {
|
|
15
17
|
cursor: MongoFindCursor<Document>
|
|
16
|
-
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface DocumentFindCursor extends DocumentFindCursorFields, Pipeable {
|
|
21
|
+
_tag: "DocumentFindCursor"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** @internal */
|
|
25
|
+
export class DocumentFindCursorImpl extends Data.TaggedClass("DocumentFindCursor")<DocumentFindCursorFields>
|
|
26
|
+
implements DocumentFindCursor
|
|
27
|
+
{
|
|
28
|
+
pipe() {
|
|
29
|
+
return pipeArguments(this, arguments)
|
|
30
|
+
}
|
|
17
31
|
}
|
|
18
32
|
|
|
19
33
|
export const filter: {
|
|
@@ -22,7 +36,7 @@ export const filter: {
|
|
|
22
36
|
} = F.dual(
|
|
23
37
|
(args) => isDocumentFindCursor(args[0]),
|
|
24
38
|
(cursor: DocumentFindCursor, filter: Filter<Document>): DocumentFindCursor =>
|
|
25
|
-
new
|
|
39
|
+
new DocumentFindCursorImpl({ cursor: cursor.cursor.filter(filter) })
|
|
26
40
|
)
|
|
27
41
|
|
|
28
42
|
export const project: {
|
|
@@ -31,7 +45,7 @@ export const project: {
|
|
|
31
45
|
} = F.dual(
|
|
32
46
|
(args) => isDocumentFindCursor(args[0]),
|
|
33
47
|
(cursor: DocumentFindCursor, value: Document): DocumentFindCursor =>
|
|
34
|
-
new
|
|
48
|
+
new DocumentFindCursorImpl({ cursor: cursor.cursor.project(value) })
|
|
35
49
|
)
|
|
36
50
|
|
|
37
51
|
export const sort: {
|
|
@@ -40,7 +54,7 @@ export const sort: {
|
|
|
40
54
|
} = F.dual(
|
|
41
55
|
(args) => isDocumentFindCursor(args[0]),
|
|
42
56
|
(cursor: DocumentFindCursor, sort: Sort | string, direction?: SortDirection): DocumentFindCursor =>
|
|
43
|
-
new
|
|
57
|
+
new DocumentFindCursorImpl({ cursor: cursor.cursor.sort(sort, direction) })
|
|
44
58
|
)
|
|
45
59
|
|
|
46
60
|
export const limit: {
|
|
@@ -49,7 +63,7 @@ export const limit: {
|
|
|
49
63
|
} = F.dual(
|
|
50
64
|
(args) => isDocumentFindCursor(args[0]),
|
|
51
65
|
(cursor: DocumentFindCursor, value: number): DocumentFindCursor =>
|
|
52
|
-
new
|
|
66
|
+
new DocumentFindCursorImpl({ cursor: cursor.cursor.limit(value) })
|
|
53
67
|
)
|
|
54
68
|
|
|
55
69
|
export const toArray = (cursor: DocumentFindCursor): Effect.Effect<Array<Document>, MongoError.MongoError> =>
|
|
@@ -72,13 +86,13 @@ export const typed: {
|
|
|
72
86
|
} = F.dual((args) => isDocumentFindCursor(args[0]), <A, I = A, R = never>(
|
|
73
87
|
cursor: DocumentFindCursor,
|
|
74
88
|
schema: Schema.Schema<A, I, R>
|
|
75
|
-
): FindCursor.FindCursor<A, I, R> => new FindCursor.
|
|
89
|
+
): FindCursor.FindCursor<A, I, R> => new FindCursor.FindCursorImpl<A, I, R>({ cursor: cursor.cursor, schema }))
|
|
76
90
|
|
|
77
|
-
const isDocumentFindCursor = (x: unknown) => x instanceof
|
|
91
|
+
const isDocumentFindCursor = (x: unknown) => x instanceof DocumentFindCursorImpl
|
|
78
92
|
|
|
79
93
|
const errorSource = (cursor: DocumentFindCursor, functionName: string) =>
|
|
80
94
|
new MongoError.CollectionErrorSource({
|
|
81
|
-
module:
|
|
95
|
+
module: DocumentFindCursorImpl.name,
|
|
82
96
|
functionName,
|
|
83
97
|
db: cursor.cursor.namespace.db,
|
|
84
98
|
collection: cursor.cursor.namespace.collection ?? "NO_COLLECTION_NAME"
|
package/src/FindCursor.ts
CHANGED
|
@@ -6,6 +6,8 @@ import * as Effect from "effect/Effect"
|
|
|
6
6
|
import type * as E from "effect/Either"
|
|
7
7
|
import * as F from "effect/Function"
|
|
8
8
|
import type * as ParseResult from "effect/ParseResult"
|
|
9
|
+
import type { Pipeable } from "effect/Pipeable"
|
|
10
|
+
import { pipeArguments } from "effect/Pipeable"
|
|
9
11
|
import * as Schema from "effect/Schema"
|
|
10
12
|
import * as Stream from "effect/Stream"
|
|
11
13
|
import * as Tuple from "effect/Tuple"
|
|
@@ -14,10 +16,22 @@ import type { Filter } from "./internal/filter.js"
|
|
|
14
16
|
import { mongoErrorOrDie } from "./internal/mongo-error.js"
|
|
15
17
|
import * as MongoError from "./MongoError.js"
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
type FindCursorFields<A, I = A, R = never> = {
|
|
18
20
|
cursor: FindCursor_<unknown>
|
|
19
21
|
schema: Schema.Schema<A, I, R>
|
|
20
|
-
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface FindCursor<A, I = A, R = never> extends FindCursorFields<A, I, R>, Pipeable {
|
|
25
|
+
_tag: "FindCursor"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @internal */
|
|
29
|
+
export class FindCursorImpl<A, I = A, R = never> extends Data.TaggedClass("FindCursor")<FindCursorFields<A, I, R>>
|
|
30
|
+
implements FindCursor<A, I, R>
|
|
31
|
+
{
|
|
32
|
+
pipe() {
|
|
33
|
+
return pipeArguments(this, arguments)
|
|
34
|
+
}
|
|
21
35
|
}
|
|
22
36
|
|
|
23
37
|
export const filter: {
|
|
@@ -28,7 +42,7 @@ export const filter: {
|
|
|
28
42
|
<A, I extends Document, R>(
|
|
29
43
|
cursor: FindCursor<A, I, R>,
|
|
30
44
|
filter: Filter<I>
|
|
31
|
-
): FindCursor<A, I, R> => new
|
|
45
|
+
): FindCursor<A, I, R> => new FindCursorImpl({ cursor: cursor.cursor.filter(filter), schema: cursor.schema })
|
|
32
46
|
)
|
|
33
47
|
|
|
34
48
|
export const project: {
|
|
@@ -47,7 +61,7 @@ export const project: {
|
|
|
47
61
|
cursor: FindCursor<A, I, R>,
|
|
48
62
|
newSchema: Schema.Schema<B, BI, BR>,
|
|
49
63
|
value: T
|
|
50
|
-
): FindCursor<B, BI, BR> => new
|
|
64
|
+
): FindCursor<B, BI, BR> => new FindCursorImpl({ cursor: cursor.cursor.project(value), schema: newSchema })
|
|
51
65
|
)
|
|
52
66
|
|
|
53
67
|
export const sort: {
|
|
@@ -63,7 +77,7 @@ export const sort: {
|
|
|
63
77
|
cursor: FindCursor<A, I, R>,
|
|
64
78
|
sort: Sort | string,
|
|
65
79
|
direction?: SortDirection
|
|
66
|
-
): FindCursor<A, I, R> => new
|
|
80
|
+
): FindCursor<A, I, R> => new FindCursorImpl({ cursor: cursor.cursor.sort(sort, direction), schema: cursor.schema })
|
|
67
81
|
)
|
|
68
82
|
|
|
69
83
|
export const limit: {
|
|
@@ -72,7 +86,7 @@ export const limit: {
|
|
|
72
86
|
} = F.dual(
|
|
73
87
|
(args) => isFindCursor(args[0]),
|
|
74
88
|
<A, I, R>(cursor: FindCursor<A, I, R>, value: number): FindCursor<A, I, R> =>
|
|
75
|
-
new
|
|
89
|
+
new FindCursorImpl({ cursor: cursor.cursor.limit(value), schema: cursor.schema })
|
|
76
90
|
)
|
|
77
91
|
|
|
78
92
|
export const toArray = <A, I, R>(
|
|
@@ -134,11 +148,11 @@ export const toStreamEither = <A, I, R>(
|
|
|
134
148
|
)
|
|
135
149
|
}
|
|
136
150
|
|
|
137
|
-
const isFindCursor = (x: unknown): x is FindCursor<unknown> => x instanceof
|
|
151
|
+
const isFindCursor = (x: unknown): x is FindCursor<unknown> => x instanceof FindCursorImpl
|
|
138
152
|
|
|
139
153
|
const errorSource = <A, I, R>(cursor: FindCursor<A, I, R>, functionName: string) =>
|
|
140
154
|
new MongoError.CollectionErrorSource({
|
|
141
|
-
module:
|
|
155
|
+
module: FindCursorImpl.name,
|
|
142
156
|
functionName,
|
|
143
157
|
db: cursor.cursor.namespace.db,
|
|
144
158
|
collection: cursor.cursor.namespace.collection ?? "NO_COLLECTION_NAME"
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
import * as Data from "effect/Data"
|
|
5
5
|
import * as Effect from "effect/Effect"
|
|
6
6
|
import * as F from "effect/Function"
|
|
7
|
+
import type { Pipeable } from "effect/Pipeable"
|
|
8
|
+
import { pipeArguments } from "effect/Pipeable"
|
|
7
9
|
import * as Stream from "effect/Stream"
|
|
8
10
|
import type {
|
|
9
11
|
CollectionInfo as MongoCollectionInfo,
|
|
@@ -17,11 +19,24 @@ export type FullCollectionInfo = MongoCollectionInfo
|
|
|
17
19
|
|
|
18
20
|
type DefaultCollectionInfo = NameOnlyCollectionInfo | FullCollectionInfo
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
T extends DefaultCollectionInfo = DefaultCollectionInfo
|
|
22
|
-
> extends Data.TaggedClass("ListCollectionsCursor")<{
|
|
22
|
+
type ListCollectionsCursorFields<T extends DefaultCollectionInfo = DefaultCollectionInfo> = {
|
|
23
23
|
cursor: MongoListCollectionsCursor<T>
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ListCollectionsCursor<T extends DefaultCollectionInfo = DefaultCollectionInfo>
|
|
27
|
+
extends ListCollectionsCursorFields<T>, Pipeable
|
|
28
|
+
{
|
|
29
|
+
_tag: "ListCollectionsCursor"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @internal */
|
|
33
|
+
export class ListCollectionsCursorImpl<
|
|
34
|
+
T extends DefaultCollectionInfo = DefaultCollectionInfo
|
|
35
|
+
> extends Data.TaggedClass("ListCollectionsCursor")<ListCollectionsCursorFields<T>> implements Pipeable {
|
|
36
|
+
pipe() {
|
|
37
|
+
return pipeArguments(this, arguments)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
25
40
|
|
|
26
41
|
export type NameOnlyListCollectionsCursor = ListCollectionsCursor<
|
|
27
42
|
Pick<MongoCollectionInfo, "name" | "type">
|
|
@@ -47,7 +62,7 @@ export const toStream = <T extends DefaultCollectionInfo>(
|
|
|
47
62
|
|
|
48
63
|
const errorSource = (cursor: ListCollectionsCursor, functionName: string) =>
|
|
49
64
|
new MongoError.CollectionErrorSource({
|
|
50
|
-
module:
|
|
65
|
+
module: ListCollectionsCursorImpl.name,
|
|
51
66
|
functionName,
|
|
52
67
|
db: cursor.cursor.namespace.db,
|
|
53
68
|
collection: cursor.cursor.namespace.collection ?? "NO_COLLECTION_NAME"
|
package/src/internal/schema.ts
CHANGED
|
@@ -5,8 +5,8 @@ import type { Document } from "mongodb"
|
|
|
5
5
|
|
|
6
6
|
// TODO: there is probably a Schema to do this decode or using typeclass package for traverse
|
|
7
7
|
export const decodeNullableDocument = <A, I, R>(schema: Schema.Schema<A, I, R>, value: Document | null) =>
|
|
8
|
-
Effect.gen(function*(
|
|
8
|
+
Effect.gen(function*() {
|
|
9
9
|
if (value === null) return O.none()
|
|
10
|
-
const decoded = yield*
|
|
10
|
+
const decoded = yield* Schema.decodeUnknown(schema)(value)
|
|
11
11
|
return O.some(decoded)
|
|
12
12
|
})
|
package/src/internal/version.ts
CHANGED