@effect-app/infra 0.132.2 → 0.133.0-next.0
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/CHANGELOG.md +14 -0
- package/_cjs/RequestContext.cjs +23 -13
- package/_cjs/RequestContext.cjs.map +1 -1
- package/_cjs/_global.ext.cjs +7 -0
- package/_cjs/_global.ext.cjs.map +1 -1
- package/_cjs/api/codec.cjs +2 -6
- package/_cjs/api/codec.cjs.map +1 -1
- package/_cjs/api/express/schema/jwt.cjs +5 -26
- package/_cjs/api/express/schema/jwt.cjs.map +1 -1
- package/_cjs/api/setupRequest.cjs +2 -2
- package/_cjs/api/setupRequest.cjs.map +1 -1
- package/_cjs/errors.cjs +3 -1
- package/_cjs/errors.cjs.map +1 -1
- package/_cjs/services/Emailer/Sendgrid.cjs +5 -4
- package/_cjs/services/Emailer/Sendgrid.cjs.map +1 -1
- package/_cjs/services/Operations/live.cjs +12 -10
- package/_cjs/services/Operations/live.cjs.map +1 -1
- package/_cjs/services/QueueMaker/memQueue.cjs +17 -15
- package/_cjs/services/QueueMaker/memQueue.cjs.map +1 -1
- package/_cjs/services/QueueMaker/sbqueue.cjs +30 -29
- package/_cjs/services/QueueMaker/sbqueue.cjs.map +1 -1
- package/_cjs/services/QueueMaker/service.cjs +3 -3
- package/_cjs/services/QueueMaker/service.cjs.map +1 -1
- package/_cjs/services/Repository.cjs +2 -2
- package/_cjs/services/Repository.cjs.map +1 -1
- package/_cjs/services/RepositoryBase.cjs +31 -33
- package/_cjs/services/RepositoryBase.cjs.map +1 -1
- package/_cjs/services/RequestContextContainer.cjs +3 -3
- package/_cjs/services/RequestContextContainer.cjs.map +1 -1
- package/_cjs/services/Store/Cosmos.cjs +4 -4
- package/_cjs/services/Store/Cosmos.cjs.map +1 -1
- package/_cjs/services/Store/Disk.cjs +15 -13
- package/_cjs/services/Store/Disk.cjs.map +1 -1
- package/_cjs/services/Store/service.cjs +49 -40
- package/_cjs/services/Store/service.cjs.map +1 -1
- package/_cjs/services/simpledb/memdb.cjs +15 -15
- package/_cjs/services/simpledb/memdb.cjs.map +1 -1
- package/_cjs/services/simpledb/redisdb.cjs +15 -14
- package/_cjs/services/simpledb/redisdb.cjs.map +1 -1
- package/_cjs/services/simpledb/shared.cjs +3 -3
- package/_cjs/services/simpledb/shared.cjs.map +1 -1
- package/_src/RequestContext.ts +27 -28
- package/_src/_global.ext.ts +12 -4
- package/_src/_global.schema.ts +1 -1
- package/_src/api/codec.ts +3 -9
- package/_src/api/express/schema/jwt.ts +5 -32
- package/_src/api/express/schema/{routing.ts → routing.ts.bak} +10 -10
- package/_src/errors.ts +12 -5
- package/_src/services/Emailer/Sendgrid.ts +17 -14
- package/_src/services/QueueMaker/memQueue.ts +4 -3
- package/_src/services/QueueMaker/sbqueue.ts +4 -3
- package/_src/services/QueueMaker/service.ts +2 -2
- package/_src/services/Repository.ts +14 -13
- package/_src/services/RepositoryBase.ts +14 -37
- package/_src/services/Store/Cosmos.ts +23 -21
- package/_src/services/Store/Disk.ts +4 -2
- package/_src/services/Store/service.ts +59 -62
- package/_src/services/simpledb/memdb.ts +1 -2
- package/_src/services/simpledb/redisdb.ts +21 -17
- package/_src/services/simpledb/shared.ts +4 -5
- package/dist/RequestContext.d.ts +93 -77
- package/dist/RequestContext.d.ts.map +1 -1
- package/dist/RequestContext.js +24 -14
- package/dist/_global.ext.d.ts +7 -5
- package/dist/_global.ext.d.ts.map +1 -1
- package/dist/_global.ext.js +6 -2
- package/dist/_global.schema.d.ts +1 -1
- package/dist/_global.schema.d.ts.map +1 -1
- package/dist/_global.schema.js +1 -1
- package/dist/api/codec.d.ts +2 -3
- package/dist/api/codec.d.ts.map +1 -1
- package/dist/api/codec.js +3 -7
- package/dist/api/express/schema/jwt.d.ts +2 -4
- package/dist/api/express/schema/jwt.d.ts.map +1 -1
- package/dist/api/express/schema/jwt.js +5 -27
- package/dist/api/setupRequest.js +3 -3
- package/dist/errors.d.ts +6 -6
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +4 -2
- package/dist/services/Emailer/Sendgrid.d.ts +108 -108
- package/dist/services/Emailer/Sendgrid.d.ts.map +1 -1
- package/dist/services/Emailer/Sendgrid.js +6 -5
- package/dist/services/Operations/live.js +17 -15
- package/dist/services/Operations/service.d.ts +4 -4
- package/dist/services/Operations/service.d.ts.map +1 -1
- package/dist/services/QueueMaker/memQueue.d.ts +2 -2
- package/dist/services/QueueMaker/memQueue.d.ts.map +1 -1
- package/dist/services/QueueMaker/memQueue.js +17 -15
- package/dist/services/QueueMaker/sbqueue.d.ts +2 -2
- package/dist/services/QueueMaker/sbqueue.d.ts.map +1 -1
- package/dist/services/QueueMaker/sbqueue.js +26 -25
- package/dist/services/QueueMaker/service.d.ts +30 -16
- package/dist/services/QueueMaker/service.d.ts.map +1 -1
- package/dist/services/QueueMaker/service.js +4 -4
- package/dist/services/Repository.d.ts +10 -9
- package/dist/services/Repository.d.ts.map +1 -1
- package/dist/services/Repository.js +3 -3
- package/dist/services/RepositoryBase.d.ts +20 -21
- package/dist/services/RepositoryBase.d.ts.map +1 -1
- package/dist/services/RepositoryBase.js +32 -34
- package/dist/services/RequestContextContainer.d.ts +4 -4
- package/dist/services/RequestContextContainer.js +3 -3
- package/dist/services/Store/Cosmos.d.ts.map +1 -1
- package/dist/services/Store/Cosmos.js +6 -6
- package/dist/services/Store/Disk.d.ts.map +1 -1
- package/dist/services/Store/Disk.js +14 -13
- package/dist/services/Store/service.d.ts +6 -9
- package/dist/services/Store/service.d.ts.map +1 -1
- package/dist/services/Store/service.js +50 -43
- package/dist/services/simpledb/memdb.d.ts +3 -4
- package/dist/services/simpledb/memdb.d.ts.map +1 -1
- package/dist/services/simpledb/memdb.js +17 -17
- package/dist/services/simpledb/redisdb.d.ts +14 -10
- package/dist/services/simpledb/redisdb.d.ts.map +1 -1
- package/dist/services/simpledb/redisdb.js +17 -16
- package/dist/services/simpledb/shared.d.ts +24 -16
- package/dist/services/simpledb/shared.d.ts.map +1 -1
- package/dist/services/simpledb/shared.js +4 -4
- package/package.json +7 -56
- package/tsconfig.json +2 -1
- package/_cjs/api/express/makeJsonSchema.cjs +0 -151
- package/_cjs/api/express/makeJsonSchema.cjs.map +0 -1
- package/_cjs/api/express/makeJsonSchema.test.cjs +0 -50
- package/_cjs/api/express/makeJsonSchema.test.cjs.map +0 -1
- package/_cjs/api/express/makeOpenApiSpecs.cjs +0 -65
- package/_cjs/api/express/makeOpenApiSpecs.cjs.map +0 -1
- package/_cjs/api/express/schema/routing.cjs +0 -137
- package/_cjs/api/express/schema/routing.cjs.map +0 -1
- package/_cjs/api/writeDocs.cjs +0 -32
- package/_cjs/api/writeDocs.cjs.map +0 -1
- package/_cjs/test.arbs.cjs +0 -32
- package/_cjs/test.arbs.cjs.map +0 -1
- package/dist/api/express/makeJsonSchema.d.ts +0 -34
- package/dist/api/express/makeJsonSchema.d.ts.map +0 -1
- package/dist/api/express/makeJsonSchema.js +0 -131
- package/dist/api/express/makeJsonSchema.test.d.ts.map +0 -1
- package/dist/api/express/makeOpenApiSpecs.d.ts +0 -58
- package/dist/api/express/makeOpenApiSpecs.d.ts.map +0 -1
- package/dist/api/express/makeOpenApiSpecs.js +0 -55
- package/dist/api/express/schema/routing.d.ts +0 -62
- package/dist/api/express/schema/routing.d.ts.map +0 -1
- package/dist/api/express/schema/routing.js +0 -111
- package/dist/api/writeDocs.d.ts +0 -4
- package/dist/api/writeDocs.d.ts.map +0 -1
- package/dist/api/writeDocs.js +0 -24
- package/dist/test.arbs.d.ts +0 -13
- package/dist/test.arbs.d.ts.map +0 -1
- package/dist/test.arbs.js +0 -22
- /package/_src/api/express/{makeJsonSchema.test.ts → makeJsonSchema.test.ts.bak} +0 -0
- /package/_src/api/express/{makeJsonSchema.ts → makeJsonSchema.ts.bak} +0 -0
- /package/_src/api/express/{makeOpenApiSpecs.ts → makeOpenApiSpecs.ts.bak} +0 -0
- /package/_src/api/{writeDocs.ts → writeDocs.ts.bak} +0 -0
- /package/_src/{test.arbs.ts → test.arbs.ts.bak} +0 -0
package/_src/RequestContext.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
+
import { Schema2 } from "@effect-app/prelude"
|
|
1
2
|
import { RequestId, UserProfileId } from "@effect-app/prelude/ids"
|
|
3
|
+
import { useClassFeaturesForSchema } from "@effect-app/schema"
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
export class RequestContextParent extends ExtendedClass<
|
|
5
|
-
RequestContextParent,
|
|
6
|
-
RequestContextParent.ConstructorInput,
|
|
7
|
-
RequestContextParent.From,
|
|
8
|
-
RequestContextParent.Fields
|
|
9
|
-
>()({
|
|
10
|
-
_tag: literal("RequestContext"),
|
|
11
|
-
id: RequestId,
|
|
5
|
+
const fields = {
|
|
12
6
|
name: NonEmptyString255,
|
|
13
|
-
userProfile: struct({ sub: UserProfileId }).optional,
|
|
7
|
+
userProfile: struct({ sub: UserProfileId }).optional(),
|
|
14
8
|
locale: literal("en", "de"),
|
|
15
|
-
createdAt:
|
|
9
|
+
createdAt: Schema2.Date.withDefaultMake(() => new Date()) // TODO
|
|
10
|
+
} as const
|
|
11
|
+
|
|
12
|
+
@useClassFeaturesForSchema
|
|
13
|
+
export class RequestContextParent extends TaggedClass<
|
|
14
|
+
RequestContextParent
|
|
15
|
+
>()("RequestContext", {
|
|
16
|
+
id: RequestId,
|
|
17
|
+
...fields
|
|
16
18
|
}) {}
|
|
17
19
|
|
|
18
20
|
/**
|
|
@@ -20,22 +22,25 @@ export class RequestContextParent extends ExtendedClass<
|
|
|
20
22
|
* @tsplus companion RequestContext.Ops
|
|
21
23
|
*/
|
|
22
24
|
@useClassFeaturesForSchema
|
|
23
|
-
export class RequestContext extends
|
|
24
|
-
RequestContext
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
RequestContext.Fields
|
|
28
|
-
>()({
|
|
29
|
-
...RequestContextParent.omit("id"),
|
|
30
|
-
id: RequestId.withDefault,
|
|
25
|
+
export class RequestContext extends Schema2.TaggedClass<
|
|
26
|
+
RequestContext
|
|
27
|
+
>()("RequestContext", {
|
|
28
|
+
id: RequestId.withDefault(),
|
|
31
29
|
rootId: RequestId,
|
|
32
|
-
parent: RequestContextParent.optional,
|
|
33
|
-
namespace: NonEmptyString255.optional
|
|
30
|
+
parent: RequestContextParent.optional(),
|
|
31
|
+
namespace: NonEmptyString255.optional(),
|
|
32
|
+
...fields
|
|
33
|
+
// ...RequestContextParent.omit("id").extend({
|
|
34
|
+
// id: RequestId.withDefault(),
|
|
35
|
+
// rootId: RequestId,
|
|
36
|
+
// parent: RequestContextParent.optional(),
|
|
37
|
+
// namespace: NonEmptyString255.optional()
|
|
38
|
+
// })
|
|
34
39
|
}) {
|
|
35
40
|
static inherit(
|
|
36
41
|
this: void,
|
|
37
42
|
parent: RequestContext,
|
|
38
|
-
newSelf: RequestContextParent
|
|
43
|
+
newSelf: ConstructorParameters<typeof RequestContextParent>[0]
|
|
39
44
|
) {
|
|
40
45
|
return new RequestContext({
|
|
41
46
|
namespace: parent?.namespace,
|
|
@@ -65,9 +70,6 @@ export namespace RequestContextParent {
|
|
|
65
70
|
* @tsplus companion RequestContextParent.From/Ops
|
|
66
71
|
*/
|
|
67
72
|
export class From extends FromClass<typeof RequestContextParent>() {}
|
|
68
|
-
export interface ConstructorInput
|
|
69
|
-
extends ConstructorInputApi<typeof RequestContextParent> {}
|
|
70
|
-
export interface Fields extends FieldsClass<typeof RequestContextParent> {}
|
|
71
73
|
}
|
|
72
74
|
export namespace RequestContext {
|
|
73
75
|
/**
|
|
@@ -75,9 +77,6 @@ export namespace RequestContext {
|
|
|
75
77
|
* @tsplus companion RequestContext.From/Ops
|
|
76
78
|
*/
|
|
77
79
|
export class From extends FromClass<typeof RequestContext>() {}
|
|
78
|
-
export interface ConstructorInput
|
|
79
|
-
extends ConstructorInputApi<typeof RequestContext> {}
|
|
80
|
-
export interface Fields extends FieldsClass<typeof RequestContext> {}
|
|
81
80
|
}
|
|
82
81
|
/* eslint-enable */
|
|
83
82
|
//
|
package/_src/_global.ext.ts
CHANGED
|
@@ -14,10 +14,10 @@ import type {} from "@effect-app/infra/services/Operations/live"
|
|
|
14
14
|
* @tsplus global
|
|
15
15
|
*/
|
|
16
16
|
import type {} from "@effect-app/infra/services/QueueMaker/errors"
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import type {} from "@effect-app/infra/test.arbs"
|
|
17
|
+
// /**
|
|
18
|
+
// * @tsplus global
|
|
19
|
+
// */
|
|
20
|
+
// import type {} from "@effect-app/infra/test.arbs"
|
|
21
21
|
/**
|
|
22
22
|
* @tsplus global
|
|
23
23
|
*/
|
|
@@ -36,3 +36,11 @@ import type {} from "@effect-app/infra/api/setupRequest"
|
|
|
36
36
|
* @tsplus global
|
|
37
37
|
*/
|
|
38
38
|
import {} from "@effect-app/infra/api/reportError"
|
|
39
|
+
import { S } from "@effect-app/schema/schema"
|
|
40
|
+
import type { ParseOptions } from "@effect/schema/AST"
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @tsplus fluent effect/schema/Schema __call
|
|
44
|
+
*/
|
|
45
|
+
export const parseSync = <I, A>(self: S.Schema<I, A>, u: I, options?: ParseOptions | undefined) =>
|
|
46
|
+
S.parseSync(self)(u, options)
|
package/_src/_global.schema.ts
CHANGED
package/_src/api/codec.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import * as S from "@effect-app/schema"
|
|
2
|
-
import { Encoder, Parser } from "@effect-app/schema"
|
|
1
|
+
import * as S from "@effect-app/prelude/schema"
|
|
3
2
|
|
|
4
3
|
export function makeCodec<
|
|
5
4
|
To extends { id: Id },
|
|
6
|
-
ConstructorInput,
|
|
7
5
|
From,
|
|
8
|
-
Api,
|
|
9
6
|
Id
|
|
10
|
-
>(self: S.Schema<
|
|
11
|
-
|
|
12
|
-
// TODO: strict
|
|
13
|
-
const encode = Encoder.for(self)
|
|
14
|
-
return [decode, encode] as const
|
|
7
|
+
>(self: S.Schema<From, To>) {
|
|
8
|
+
return [S.parseSync(self), S.encodeSync(self)] as const
|
|
15
9
|
}
|
|
@@ -1,37 +1,10 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
3
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
4
|
-
import
|
|
5
|
-
import * as S from "@effect-app/schema"
|
|
6
|
-
import { These as Th } from "@effect-app/schema"
|
|
7
|
-
import { jwtDecode } from "jwt-decode"
|
|
8
|
-
|
|
9
|
-
export const jwtIdentifier = S.makeAnnotation<{}>()
|
|
4
|
+
import * as S from "@effect-app/prelude/schema"
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
// S.identity((u): u is string => typeof u === "string"),
|
|
13
|
-
S.identity((u): u is string => {
|
|
14
|
-
throw new Error("Cannot id JWT: " + u)
|
|
15
|
-
}),
|
|
16
|
-
S.constructor((n) => Th.succeed(n)),
|
|
17
|
-
// S.arbitrary((_) => {
|
|
18
|
-
// throw new Error("Cannot arb JWT")
|
|
19
|
-
// }), // TODO
|
|
20
|
-
// S.encoder((_) => {
|
|
21
|
-
// throw new Error("can't encode")
|
|
22
|
-
// }),
|
|
23
|
-
S.parser((p: any) => {
|
|
24
|
-
try {
|
|
25
|
-
return Th.succeed(
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
27
|
-
jwtDecode(p)
|
|
28
|
-
)
|
|
29
|
-
} catch (err) {
|
|
30
|
-
return Th.fail(S.leafE(S.parseStringE(p))) // "not a JWT: " + err as anyw
|
|
31
|
-
}
|
|
32
|
-
}),
|
|
33
|
-
S.mapApi(() => ({})),
|
|
34
|
-
S.annotate(jwtIdentifier, {})
|
|
35
|
-
)
|
|
6
|
+
import { jwtDecode } from "jwt-decode"
|
|
36
7
|
|
|
37
|
-
export const jwt = S.string
|
|
8
|
+
export const jwt = S.transform(S.string, S.unknown, (_) => jwtDecode(_), (_): string => {
|
|
9
|
+
throw new Error("not implemented")
|
|
10
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
import * as S from "@effect-app/schema"
|
|
3
|
+
import * as S from "@effect-app/prelude/schema"
|
|
4
4
|
import type { Methods } from "@effect-app/schema"
|
|
5
5
|
|
|
6
6
|
import type { JSONSchema, ParameterLocation, SubSchema } from "@effect-app/infra-adapters/Openapi/atlas-plutus"
|
|
@@ -16,14 +16,14 @@ export type Request<
|
|
|
16
16
|
HeaderA,
|
|
17
17
|
ReqA extends PathA & QueryA & BodyA,
|
|
18
18
|
PPath extends `/${string}`
|
|
19
|
-
> = S.
|
|
19
|
+
> = S.REST.ReqRes<unknown, ReqA> & {
|
|
20
20
|
method: Methods.Rest
|
|
21
21
|
path: PPath
|
|
22
|
-
Cookie?: S.ReqRes<Record<string, string>, CookieA>
|
|
23
|
-
Path?: S.ReqRes<Record<string, string>, PathA>
|
|
24
|
-
Body?: S.ReqRes<unknown, BodyA>
|
|
25
|
-
Query?: S.ReqRes<Record<string, string>, QueryA>
|
|
26
|
-
Headers?: S.ReqRes<Record<string, string>, HeaderA>
|
|
22
|
+
Cookie?: S.REST.ReqRes<Record<string, string>, CookieA>
|
|
23
|
+
Path?: S.REST.ReqRes<Record<string, string>, PathA>
|
|
24
|
+
Body?: S.REST.ReqRes<unknown, BodyA>
|
|
25
|
+
Query?: S.REST.ReqRes<Record<string, string>, QueryA>
|
|
26
|
+
Headers?: S.REST.ReqRes<Record<string, string>, HeaderA>
|
|
27
27
|
Tag: Tag<M, M>
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -39,7 +39,7 @@ export interface RouteRequestHandler<
|
|
|
39
39
|
PPath extends `/${string}`
|
|
40
40
|
> {
|
|
41
41
|
Request: Request<M, PathA, CookieA, QueryA, BodyA, HeaderA, ReqA, PPath>
|
|
42
|
-
Response?: S.ReqRes<unknown, ResA> | S.ReqResSchemed<unknown, ResA>
|
|
42
|
+
Response?: S.REST.ReqRes<unknown, ResA> // | S.REST.ReqResSchemed<unknown, ResA>
|
|
43
43
|
ResponseOpenApi?: any
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -126,7 +126,7 @@ export function makeFromSchema<ResA>(
|
|
|
126
126
|
e: RouteDescriptor<any, any, any, any, any, any, ResA, any>
|
|
127
127
|
) {
|
|
128
128
|
const jsonSchema_ = OpenApi.for
|
|
129
|
-
const jsonSchema = <E, A>(r: S.ReqRes<E, A>) => jsonSchema_(r)
|
|
129
|
+
const jsonSchema = <E, A>(r: S.REST.ReqRes<E, A>) => jsonSchema_(r)
|
|
130
130
|
const { Request: Req, Response: Res_, ResponseOpenApi } = e.handler
|
|
131
131
|
const r = ResponseOpenApi ?? Res_
|
|
132
132
|
const Res = r ? S.extractSchema(r) : S.Void
|
|
@@ -164,7 +164,7 @@ export function makeFromSchema<ResA>(
|
|
|
164
164
|
)
|
|
165
165
|
// const makeReqSchema = schema(Req)
|
|
166
166
|
|
|
167
|
-
const makeResSchema = jsonSchema_(Res
|
|
167
|
+
const makeResSchema = jsonSchema_(Res)
|
|
168
168
|
|
|
169
169
|
function makeParameters(inn: ParameterLocation) {
|
|
170
170
|
return (a: Option<JSONSchema | SubSchema>) => {
|
package/_src/errors.ts
CHANGED
|
@@ -14,14 +14,14 @@ export class NotFoundError<T extends string = string>
|
|
|
14
14
|
export class ValidationError extends Data.TaggedError("ValidationError")<{ errors: ReadonlyArray<unknown> }> {}
|
|
15
15
|
|
|
16
16
|
/** @tsplus type NotLoggedInError */
|
|
17
|
-
export class NotLoggedInError extends Data.TaggedError("NotLoggedInError")<{ message?: string }> {
|
|
17
|
+
export class NotLoggedInError extends Data.TaggedError("NotLoggedInError")<{ message?: string | undefined }> {
|
|
18
18
|
constructor(message?: string) {
|
|
19
19
|
super({ message })
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/** @tsplus type UnauthorizedError */
|
|
24
|
-
export class UnauthorizedError extends Data.TaggedError("UnauthorizedError")<{ message?: string }> {
|
|
24
|
+
export class UnauthorizedError extends Data.TaggedError("UnauthorizedError")<{ message?: string | undefined }> {
|
|
25
25
|
constructor(message?: string) {
|
|
26
26
|
super({ message })
|
|
27
27
|
}
|
|
@@ -54,7 +54,9 @@ export class CauseException<E> extends Error {
|
|
|
54
54
|
const ff = makeFiberFailure(originalCause)
|
|
55
55
|
this.name = ff.name
|
|
56
56
|
this.message = ff.message
|
|
57
|
-
|
|
57
|
+
if (ff.stack) {
|
|
58
|
+
this.stack = ff.stack
|
|
59
|
+
}
|
|
58
60
|
}
|
|
59
61
|
toJSON() {
|
|
60
62
|
return {
|
|
@@ -76,10 +78,15 @@ export class CauseException<E> extends Error {
|
|
|
76
78
|
|
|
77
79
|
/** @tsplus type OptimisticConcurrencyException */
|
|
78
80
|
export class OptimisticConcurrencyException extends Data.TaggedError("OptimisticConcurrencyException")<
|
|
79
|
-
{ type: string; id: string; current?: string; found?: string; message: string }
|
|
81
|
+
{ type: string; id: string; current?: string | undefined; found?: string | undefined; message: string }
|
|
80
82
|
> {
|
|
81
83
|
constructor(
|
|
82
|
-
args: {
|
|
84
|
+
args: {
|
|
85
|
+
readonly type: string
|
|
86
|
+
readonly id: string
|
|
87
|
+
readonly current?: string | undefined
|
|
88
|
+
readonly found?: string | undefined
|
|
89
|
+
}
|
|
83
90
|
) {
|
|
84
91
|
super({ ...args, message: `Existing ${args.type} ${args.id} record changed` })
|
|
85
92
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { dropUndefinedT } from "@effect-app/core/utils"
|
|
1
2
|
import type { EmailData } from "@sendgrid/helpers/classes/email-address.js"
|
|
2
3
|
import sgMail from "@sendgrid/mail"
|
|
3
4
|
import { inspect } from "util"
|
|
@@ -11,11 +12,11 @@ const makeSendgrid = ({ apiKey, defaultFrom, defaultReplyTo, realMail, subjectPr
|
|
|
11
12
|
return {
|
|
12
13
|
sendMail(msg_: EmailMsgOptionalFrom) {
|
|
13
14
|
return Effect.gen(function*($) {
|
|
14
|
-
const msg: EmailMsg = {
|
|
15
|
+
const msg: EmailMsg = dropUndefinedT({
|
|
15
16
|
...msg_,
|
|
16
17
|
from: msg_.from ?? defaultFrom,
|
|
17
18
|
replyTo: msg_.replyTo ?? (msg_.from ? undefined : defaultReplyTo)
|
|
18
|
-
}
|
|
19
|
+
})
|
|
19
20
|
const render = renderMessage(!realMail)
|
|
20
21
|
|
|
21
22
|
const renderedMsg_ = render(msg)
|
|
@@ -66,18 +67,20 @@ export function renderMessage(forceFake: boolean) {
|
|
|
66
67
|
let i = 0
|
|
67
68
|
const makeId = () => i++
|
|
68
69
|
return forceFake
|
|
69
|
-
? (msg: EmailMsg) =>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
? (msg: EmailMsg) =>
|
|
71
|
+
dropUndefinedT({
|
|
72
|
+
...msg,
|
|
73
|
+
to: msg.to && renderFake(msg.to, makeId),
|
|
74
|
+
cc: msg.cc && renderFake(msg.cc, makeId),
|
|
75
|
+
bcc: msg.bcc && renderFake(msg.bcc, makeId)
|
|
76
|
+
})
|
|
77
|
+
: (msg: EmailMsg) =>
|
|
78
|
+
dropUndefinedT({
|
|
79
|
+
...msg,
|
|
80
|
+
to: msg.to && renderFakeIfTest(msg.to, makeId),
|
|
81
|
+
cc: msg.cc && renderFakeIfTest(msg.cc, makeId),
|
|
82
|
+
bcc: msg.bcc && renderFakeIfTest(msg.bcc, makeId)
|
|
83
|
+
})
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MemQueue } from "@effect-app/infra-adapters/memQueue"
|
|
2
2
|
import { RequestContext } from "@effect-app/infra/RequestContext"
|
|
3
|
+
import type { Schema2 } from "@effect-app/prelude"
|
|
3
4
|
import { RequestId } from "@effect-app/prelude/ids"
|
|
4
5
|
import { Tracer } from "effect"
|
|
5
6
|
import { RequestContextContainer } from "../RequestContextContainer.js"
|
|
@@ -16,8 +17,8 @@ export function makeMemQueue<
|
|
|
16
17
|
>(
|
|
17
18
|
queueName: string,
|
|
18
19
|
queueDrainName: string,
|
|
19
|
-
schema:
|
|
20
|
-
drainSchema:
|
|
20
|
+
schema: Schema2.Schema<EvtE, Evt>,
|
|
21
|
+
drainSchema: Schema2.Schema<unknown, DrainEvt>
|
|
21
22
|
) {
|
|
22
23
|
return Effect.gen(function*($) {
|
|
23
24
|
const mem = yield* $(MemQueue)
|
|
@@ -27,7 +28,7 @@ export function makeMemQueue<
|
|
|
27
28
|
|
|
28
29
|
const wireSchema = struct({ body: schema, meta: QueueMeta })
|
|
29
30
|
const drainW = struct({ body: drainSchema, meta: QueueMeta })
|
|
30
|
-
const parseDrain = drainW.
|
|
31
|
+
const parseDrain = flow(drainW.parse, (_) => _.orDie)
|
|
31
32
|
|
|
32
33
|
return {
|
|
33
34
|
publish: (...messages) =>
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import type {} from "@azure/service-bus"
|
|
10
10
|
import { captureException } from "@effect-app/infra/errorReporter"
|
|
11
11
|
import { RequestContext } from "@effect-app/infra/RequestContext"
|
|
12
|
+
import type { Schema2 } from "@effect-app/prelude"
|
|
12
13
|
import { RequestId } from "@effect-app/prelude/ids"
|
|
13
14
|
import { struct } from "@effect-app/schema"
|
|
14
15
|
import { Tracer } from "effect"
|
|
@@ -26,15 +27,15 @@ export function makeServiceBusQueue<
|
|
|
26
27
|
>(
|
|
27
28
|
_queueName: string,
|
|
28
29
|
queueDrainName: string,
|
|
29
|
-
schema:
|
|
30
|
-
drainSchema:
|
|
30
|
+
schema: Schema2.Schema<EvtE, Evt>,
|
|
31
|
+
drainSchema: Schema2.Schema<unknown, DrainEvt>
|
|
31
32
|
) {
|
|
32
33
|
const wireSchema = struct({
|
|
33
34
|
body: schema,
|
|
34
35
|
meta: QueueMeta
|
|
35
36
|
})
|
|
36
37
|
const drainW = struct({ body: drainSchema, meta: QueueMeta })
|
|
37
|
-
const parseDrain = drainW.
|
|
38
|
+
const parseDrain = flow(drainW.parse, (_) => _.orDie)
|
|
38
39
|
|
|
39
40
|
return Effect.gen(function*($) {
|
|
40
41
|
const s = yield* $(Sender)
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// Modify = Must `set` updated items, and can return anything.
|
|
4
4
|
import type { FixEnv, PureLogT } from "@effect-app/prelude/Pure"
|
|
5
5
|
import { Pure } from "@effect-app/prelude/Pure"
|
|
6
|
+
import type { S } from "vitest/dist/reporters-O4LBziQ_.js"
|
|
6
7
|
import type { InvalidStateError, OptimisticConcurrencyException } from "../errors.js"
|
|
7
8
|
import { NotFoundError } from "../errors.js"
|
|
8
9
|
import type { Filter, PersistenceModelType } from "../services/Store.js"
|
|
@@ -76,10 +77,10 @@ export function projectEffect<
|
|
|
76
77
|
R,
|
|
77
78
|
E,
|
|
78
79
|
{
|
|
79
|
-
filter?: Filter<PM>
|
|
80
|
-
collect?: (t: PM) => Option<S>
|
|
81
|
-
limit?: number
|
|
82
|
-
skip?: number
|
|
80
|
+
filter?: Filter<PM> | undefined
|
|
81
|
+
collect?: ((t: PM) => Option<S>) | undefined
|
|
82
|
+
limit?: number | undefined
|
|
83
|
+
skip?: number | undefined
|
|
83
84
|
}
|
|
84
85
|
>
|
|
85
86
|
): Effect<R, E, S[]>
|
|
@@ -97,10 +98,10 @@ export function projectEffect<
|
|
|
97
98
|
R,
|
|
98
99
|
E,
|
|
99
100
|
{
|
|
100
|
-
filter?: QueryBuilder<PM>
|
|
101
|
-
|
|
102
|
-
limit?: number
|
|
103
|
-
skip?: number
|
|
101
|
+
filter?: QueryBuilder<PM> | undefined
|
|
102
|
+
collect?: ((t: PM) => Option<S>) | undefined
|
|
103
|
+
limit?: number | undefined
|
|
104
|
+
skip?: number | undefined
|
|
104
105
|
}
|
|
105
106
|
>
|
|
106
107
|
): Effect<R, E, Pick<PM, U>[]>
|
|
@@ -119,11 +120,11 @@ export function projectEffect<
|
|
|
119
120
|
R,
|
|
120
121
|
E,
|
|
121
122
|
{
|
|
122
|
-
filter?: Filter<PM>
|
|
123
|
-
select?: NonEmptyReadonlyArray<U>
|
|
124
|
-
collect?: (t:
|
|
125
|
-
limit?: number
|
|
126
|
-
skip?: number
|
|
123
|
+
filter?: Filter<PM> | undefined
|
|
124
|
+
select?: NonEmptyReadonlyArray<U> | undefined
|
|
125
|
+
collect?: ((t: PM) => Option<S>) | undefined
|
|
126
|
+
limit?: number | undefined
|
|
127
|
+
skip?: number | undefined
|
|
127
128
|
}
|
|
128
129
|
>
|
|
129
130
|
): Effect<R, E, S[]> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
3
|
-
import type { ParserEnv } from "@effect-app/schema/custom/Parser"
|
|
3
|
+
// import type { ParserEnv } from "@effect-app/schema/custom/Parser"
|
|
4
4
|
import type { Repository } from "./Repository.js"
|
|
5
5
|
import { StoreMaker } from "./Store.js"
|
|
6
6
|
import type { Filter, FilterArgs, FilterFunc, PersistenceModelType, StoreConfig, Where } from "./Store.js"
|
|
@@ -9,8 +9,7 @@ import type {} from "effect/Hash"
|
|
|
9
9
|
import type { Opt } from "@effect-app/core/Option"
|
|
10
10
|
import { makeCodec } from "@effect-app/infra/api/codec"
|
|
11
11
|
import { makeFilters } from "@effect-app/infra/filter"
|
|
12
|
-
import type {
|
|
13
|
-
import { EParserFor } from "@effect-app/prelude/schema"
|
|
12
|
+
import type { Schema2 } from "@effect-app/prelude"
|
|
14
13
|
import type { InvalidStateError, OptimisticConcurrencyException } from "../errors.js"
|
|
15
14
|
import { ContextMapContainer } from "./Store/ContextMapContainer.js"
|
|
16
15
|
import { QueryBuilder } from "./Store/filterApi/query.js"
|
|
@@ -32,7 +31,7 @@ export abstract class RepositoryBaseC<
|
|
|
32
31
|
events?: Iterable<Evt>
|
|
33
32
|
) => Effect<never, InvalidStateError | OptimisticConcurrencyException, void>
|
|
34
33
|
abstract readonly utils: {
|
|
35
|
-
parseMany: (a: readonly PM[]
|
|
34
|
+
parseMany: (a: readonly PM[]) => Effect<never, never, readonly T[]>
|
|
36
35
|
all: Effect<never, never, PM[]>
|
|
37
36
|
filter: FilterFunc<PM>
|
|
38
37
|
// count: (filter?: Filter<PM>) => Effect<never, never, PositiveInt>
|
|
@@ -89,12 +88,10 @@ export function makeRepo<
|
|
|
89
88
|
return <
|
|
90
89
|
ItemType extends string,
|
|
91
90
|
T extends { id: string },
|
|
92
|
-
ConstructorInput,
|
|
93
|
-
Api,
|
|
94
91
|
From extends { id: string }
|
|
95
92
|
>(
|
|
96
93
|
name: ItemType,
|
|
97
|
-
schema:
|
|
94
|
+
schema: Schema2.Schema<From, T>,
|
|
98
95
|
mapFrom: (pm: Omit<PM, "_etag">) => From,
|
|
99
96
|
mapTo: (e: From, etag: string | undefined) => PM
|
|
100
97
|
) => {
|
|
@@ -146,7 +143,7 @@ export function makeRepo<
|
|
|
146
143
|
})
|
|
147
144
|
)
|
|
148
145
|
|
|
149
|
-
const parse =
|
|
146
|
+
const parse = (e: From) => schema.parse(e).orDie
|
|
150
147
|
|
|
151
148
|
const all = allE.flatMap((_) => _.forEachEffect((_) => parse(_)))
|
|
152
149
|
|
|
@@ -162,7 +159,7 @@ export function makeRepo<
|
|
|
162
159
|
}
|
|
163
160
|
|
|
164
161
|
function find(id: T["id"]) {
|
|
165
|
-
return findE(id).flatMapOpt(
|
|
162
|
+
return findE(id).flatMapOpt(parse)
|
|
166
163
|
}
|
|
167
164
|
|
|
168
165
|
const saveAllE = (a: Iterable<From>) =>
|
|
@@ -175,7 +172,7 @@ export function makeRepo<
|
|
|
175
172
|
ret.forEach((_) => set(_.id, _._etag))
|
|
176
173
|
})
|
|
177
174
|
)
|
|
178
|
-
const encode =
|
|
175
|
+
const encode = (i: T) => schema.encodeSync(i)
|
|
179
176
|
|
|
180
177
|
const saveAll = (a: Iterable<T>) => saveAllE(a.toChunk.map(encode))
|
|
181
178
|
|
|
@@ -208,7 +205,7 @@ export function makeRepo<
|
|
|
208
205
|
})
|
|
209
206
|
}
|
|
210
207
|
|
|
211
|
-
const p =
|
|
208
|
+
const p = schema.parseSync
|
|
212
209
|
|
|
213
210
|
const r: Repository<T, PM, Evt, ItemType> = {
|
|
214
211
|
/**
|
|
@@ -301,18 +298,16 @@ export function makeStore<
|
|
|
301
298
|
return <
|
|
302
299
|
ItemType extends string,
|
|
303
300
|
T extends { id: string },
|
|
304
|
-
ConstructorInput,
|
|
305
|
-
Api,
|
|
306
301
|
E extends { id: string }
|
|
307
302
|
>(
|
|
308
303
|
name: ItemType,
|
|
309
|
-
schema:
|
|
304
|
+
schema: Schema2.Schema<E, T>,
|
|
310
305
|
mapTo: (e: E, etag: string | undefined) => PM
|
|
311
306
|
) => {
|
|
312
307
|
const [_dec, encode] = makeCodec(schema)
|
|
313
308
|
function encodeToPM() {
|
|
314
309
|
const getEtag = () => undefined
|
|
315
|
-
return
|
|
310
|
+
return (t: T) => mapToPersistenceModel(encode(t), getEtag)
|
|
316
311
|
}
|
|
317
312
|
|
|
318
313
|
function mapToPersistenceModel(
|
|
@@ -414,9 +409,9 @@ export const RepositoryBaseImpl = <Service>() => {
|
|
|
414
409
|
PM extends { id: string; _etag: string | undefined },
|
|
415
410
|
Evt = never
|
|
416
411
|
>() =>
|
|
417
|
-
<ItemType extends string, T extends { id: string },
|
|
412
|
+
<ItemType extends string, T extends { id: string }, From extends { id: string }>(
|
|
418
413
|
itemType: ItemType,
|
|
419
|
-
schema:
|
|
414
|
+
schema: Schema2.Schema<From, T>,
|
|
420
415
|
jitM?: (pm: From) => From
|
|
421
416
|
): Exact<PM, From & { _etag: string | undefined }> extends true ?
|
|
422
417
|
& (abstract new() => RepositoryBaseC1<T, PM, Evt, ItemType>)
|
|
@@ -455,9 +450,9 @@ export const RepositoryDefaultImpl = <Service>() => {
|
|
|
455
450
|
PM extends { id: string; _etag: string | undefined },
|
|
456
451
|
Evt = never
|
|
457
452
|
>() =>
|
|
458
|
-
<ItemType extends string, T extends { id: string },
|
|
453
|
+
<ItemType extends string, T extends { id: string }, From extends { id: string }>(
|
|
459
454
|
itemType: ItemType,
|
|
460
|
-
schema:
|
|
455
|
+
schema: Schema2.Schema<From, T>,
|
|
461
456
|
jitM?: (pm: From) => From
|
|
462
457
|
): Exact<PM, From & { _etag: string | undefined }> extends true ?
|
|
463
458
|
& (abstract new(
|
|
@@ -495,21 +490,3 @@ export const RepositoryDefaultImpl = <Service>() => {
|
|
|
495
490
|
return assignTag<Service>()(Cls) as any // impl is missing, but its marked protected
|
|
496
491
|
}
|
|
497
492
|
}
|
|
498
|
-
|
|
499
|
-
// @useClassFeaturesForSchema
|
|
500
|
-
// export class Shop extends Class<Shop>()({ id: string }) {}
|
|
501
|
-
|
|
502
|
-
// /**
|
|
503
|
-
// * @tsplus type ShopRepo
|
|
504
|
-
// * @tsplus companion ShopRepo.Ops
|
|
505
|
-
// */
|
|
506
|
-
// export class ShopRepo extends RepositoryDefaultImpl<ShopRepo>()<Shop & { _etag: string | undefined }>()(
|
|
507
|
-
// "Shop",
|
|
508
|
-
// Shop,
|
|
509
|
-
// (pm) => pm,
|
|
510
|
-
// (e, _etag) => ({ ...e, _etag })
|
|
511
|
-
// ) {
|
|
512
|
-
// override saveAndPublish = (items: Iterable<Shop>, events?: Iterable<unknown> | undefined) => {
|
|
513
|
-
// return this.impl.saveAndPublish(items, events)
|
|
514
|
-
// }
|
|
515
|
-
// }
|