@effect-app/infra 0.133.0-next.2 → 0.133.0-next.20
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 +165 -0
- package/_cjs/RequestContext.cjs +1 -1
- package/_cjs/_global.ext.cjs +1 -25
- package/_cjs/_global.ext.cjs.map +1 -1
- package/_cjs/_global.schema.cjs +1 -1
- package/_cjs/api/codec.cjs +1 -1
- package/_cjs/api/codec.cjs.map +1 -1
- package/_cjs/api/express/schema/jwt.cjs +1 -1
- package/_cjs/api/express/schema/routing.cjs +23 -0
- package/_cjs/api/express/schema/routing.cjs.map +1 -0
- package/_cjs/api/setupRequest.cjs +2 -2
- package/_cjs/api/setupRequest.cjs.map +1 -1
- package/_cjs/errors.cjs +5 -1
- package/_cjs/errors.cjs.map +1 -1
- package/_cjs/services/Operations/live.cjs +11 -12
- package/_cjs/services/Operations/live.cjs.map +1 -1
- package/_cjs/services/QueueMaker/memQueue.cjs +10 -11
- package/_cjs/services/QueueMaker/memQueue.cjs.map +1 -1
- package/_cjs/services/QueueMaker/sbqueue.cjs +4 -4
- package/_cjs/services/QueueMaker/sbqueue.cjs.map +1 -1
- package/_cjs/services/QueueMaker/service.cjs +1 -1
- package/_cjs/services/Repository.cjs +2 -2
- package/_cjs/services/Repository.cjs.map +1 -1
- package/_cjs/services/RequestContextContainer.cjs +3 -3
- package/_cjs/services/RequestContextContainer.cjs.map +1 -1
- package/_cjs/services/simpledb/redisdb.cjs +1 -1
- package/_cjs/services/simpledb/shared.cjs +1 -1
- package/_cjs/services/simpledb/shared.cjs.map +1 -1
- package/_cjs/test.arbs.cjs +9 -0
- package/_cjs/test.arbs.cjs.map +1 -0
- package/_src/_global.ext.ts +2 -27
- package/_src/_global.schema.ts +1 -1
- package/_src/api/codec.ts +1 -1
- package/_src/api/express/schema/jwt.ts +1 -1
- package/_src/api/express/schema/routing.ts +236 -0
- package/_src/errors.ts +5 -1
- package/_src/services/simpledb/redisdb.ts +1 -1
- package/_src/services/simpledb/shared.ts +1 -1
- package/_src/test.arbs.ts +23 -0
- package/dist/RequestContext.d.ts +3 -3
- package/dist/RequestContext.js +1 -1
- package/dist/_global.ext.d.ts +1 -22
- package/dist/_global.ext.d.ts.map +1 -1
- package/dist/_global.ext.js +2 -18
- package/dist/_global.schema.d.ts +1 -1
- package/dist/_global.schema.d.ts.map +1 -1
- package/dist/_global.schema.js +2 -2
- package/dist/api/codec.d.ts +1 -1
- package/dist/api/codec.d.ts.map +1 -1
- package/dist/api/codec.js +2 -2
- package/dist/api/express/schema/jwt.d.ts +1 -1
- package/dist/api/express/schema/jwt.d.ts.map +1 -1
- package/dist/api/express/schema/jwt.js +2 -2
- package/dist/api/express/schema/routing.d.ts +31 -0
- package/dist/api/express/schema/routing.d.ts.map +1 -0
- package/dist/api/express/schema/routing.js +10 -0
- package/dist/api/setupRequest.js +3 -3
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +4 -1
- package/dist/services/Emailer/service.d.ts +1 -1
- package/dist/services/Operations/live.js +16 -17
- 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 +1 -1
- package/dist/services/QueueMaker/memQueue.js +10 -11
- package/dist/services/QueueMaker/sbqueue.d.ts +1 -1
- package/dist/services/QueueMaker/sbqueue.js +4 -4
- package/dist/services/QueueMaker/service.js +1 -1
- package/dist/services/Repository.d.ts +3 -3
- package/dist/services/Repository.d.ts.map +1 -1
- package/dist/services/Repository.js +3 -3
- package/dist/services/RequestContextContainer.d.ts +3 -3
- package/dist/services/RequestContextContainer.js +3 -3
- package/dist/services/simpledb/cosmosdb.d.ts +2 -2
- package/dist/services/simpledb/diskdb.d.ts +2 -2
- package/dist/services/simpledb/memdb.d.ts +2 -2
- package/dist/services/simpledb/mongodb.d.ts +2 -2
- package/dist/services/simpledb/redisdb.d.ts +5 -5
- package/dist/services/simpledb/redisdb.d.ts.map +1 -1
- package/dist/services/simpledb/redisdb.js +2 -2
- package/dist/services/simpledb/shared.d.ts +7 -7
- package/dist/services/simpledb/shared.d.ts.map +1 -1
- package/dist/services/simpledb/shared.js +2 -2
- package/dist/services/simpledb/simpledb.d.ts +2 -2
- package/dist/test.arbs.d.ts +2 -0
- package/dist/test.arbs.d.ts.map +1 -0
- package/dist/test.arbs.js +6 -0
- package/package.json +26 -6
- package/_src/api/express/schema/routing.ts.bak +0 -241
- package/_src/test.arbs.ts.bak +0 -27
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
import * as S from "@effect-app/prelude/schema"
|
|
4
|
-
import type { Methods } from "@effect-app/schema"
|
|
5
|
-
|
|
6
|
-
import type { JSONSchema, ParameterLocation, SubSchema } from "@effect-app/infra-adapters/Openapi/atlas-plutus"
|
|
7
|
-
import { isObjectSchema } from "@effect-app/infra-adapters/Openapi/atlas-plutus"
|
|
8
|
-
import * as OpenApi from "@effect-app/infra-adapters/Openapi/index"
|
|
9
|
-
|
|
10
|
-
export type Request<
|
|
11
|
-
M,
|
|
12
|
-
PathA,
|
|
13
|
-
CookieA,
|
|
14
|
-
QueryA,
|
|
15
|
-
BodyA,
|
|
16
|
-
HeaderA,
|
|
17
|
-
ReqA extends PathA & QueryA & BodyA,
|
|
18
|
-
PPath extends `/${string}`
|
|
19
|
-
> = S.REST.ReqRes<unknown, ReqA> & {
|
|
20
|
-
method: Methods.Rest
|
|
21
|
-
path: PPath
|
|
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
|
-
Tag: Tag<M, M>
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface RouteRequestHandler<
|
|
31
|
-
M,
|
|
32
|
-
PathA,
|
|
33
|
-
CookieA,
|
|
34
|
-
QueryA,
|
|
35
|
-
BodyA,
|
|
36
|
-
HeaderA,
|
|
37
|
-
ReqA extends PathA & QueryA & BodyA,
|
|
38
|
-
ResA,
|
|
39
|
-
PPath extends `/${string}`
|
|
40
|
-
> {
|
|
41
|
-
Request: Request<M, PathA, CookieA, QueryA, BodyA, HeaderA, ReqA, PPath>
|
|
42
|
-
Response?: S.REST.ReqRes<unknown, ResA> // | S.REST.ReqResSchemed<unknown, ResA>
|
|
43
|
-
ResponseOpenApi?: any
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function asRouteDescriptionAny<R extends RouteDescriptorAny>(i: R) {
|
|
47
|
-
return i as RouteDescriptorAny
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function arrAsRouteDescriptionAny<R extends RouteDescriptorAny>(
|
|
51
|
-
arr: ReadonlyArray<R>
|
|
52
|
-
) {
|
|
53
|
-
return arr.map(asRouteDescriptionAny)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface RouteDescriptor<
|
|
57
|
-
M,
|
|
58
|
-
PathA,
|
|
59
|
-
CookieA,
|
|
60
|
-
QueryA,
|
|
61
|
-
BodyA,
|
|
62
|
-
HeaderA,
|
|
63
|
-
ReqA extends PathA & QueryA & BodyA,
|
|
64
|
-
ResA,
|
|
65
|
-
METHOD extends Methods.Rest = Methods.Rest
|
|
66
|
-
> {
|
|
67
|
-
_tag: "Schema"
|
|
68
|
-
path: `/${string}`
|
|
69
|
-
method: METHOD
|
|
70
|
-
handler: RouteRequestHandler<M, PathA, CookieA, QueryA, BodyA, HeaderA, ReqA, ResA, `/${string}`>
|
|
71
|
-
info?: {
|
|
72
|
-
tags: ReadonlyArray<string>
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export type RouteDescriptorAny = RouteDescriptor<
|
|
77
|
-
any,
|
|
78
|
-
any,
|
|
79
|
-
any,
|
|
80
|
-
any,
|
|
81
|
-
any,
|
|
82
|
-
any,
|
|
83
|
-
any,
|
|
84
|
-
any
|
|
85
|
-
>
|
|
86
|
-
|
|
87
|
-
export function makeRouteDescriptor<
|
|
88
|
-
M,
|
|
89
|
-
PathA,
|
|
90
|
-
CookieA,
|
|
91
|
-
QueryA,
|
|
92
|
-
BodyA,
|
|
93
|
-
HeaderA,
|
|
94
|
-
ReqA extends PathA & QueryA & BodyA,
|
|
95
|
-
ResA = void,
|
|
96
|
-
METHOD extends Methods.Rest = Methods.Rest
|
|
97
|
-
>(
|
|
98
|
-
path: `/${string}`,
|
|
99
|
-
method: METHOD,
|
|
100
|
-
handler: RouteRequestHandler<
|
|
101
|
-
M,
|
|
102
|
-
PathA,
|
|
103
|
-
CookieA,
|
|
104
|
-
QueryA,
|
|
105
|
-
BodyA,
|
|
106
|
-
HeaderA,
|
|
107
|
-
ReqA,
|
|
108
|
-
ResA,
|
|
109
|
-
`/${string}`
|
|
110
|
-
>
|
|
111
|
-
): RouteDescriptor<
|
|
112
|
-
M,
|
|
113
|
-
PathA,
|
|
114
|
-
CookieA,
|
|
115
|
-
QueryA,
|
|
116
|
-
BodyA,
|
|
117
|
-
HeaderA,
|
|
118
|
-
ReqA,
|
|
119
|
-
ResA,
|
|
120
|
-
METHOD
|
|
121
|
-
> {
|
|
122
|
-
return { path, handler, method, _tag: "Schema" }
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function makeFromSchema<ResA>(
|
|
126
|
-
e: RouteDescriptor<any, any, any, any, any, any, ResA, any>
|
|
127
|
-
) {
|
|
128
|
-
const jsonSchema_ = OpenApi.for
|
|
129
|
-
const jsonSchema = <E, A>(r: S.REST.ReqRes<E, A>) => jsonSchema_(r)
|
|
130
|
-
const { Request: Req, Response: Res_, ResponseOpenApi } = e.handler
|
|
131
|
-
const r = ResponseOpenApi ?? Res_
|
|
132
|
-
const Res = r ? S.extractSchema(r) : S.Void
|
|
133
|
-
// TODO EffectOption.fromNullable(Req.Headers).flatMapOpt(jsonSchema)
|
|
134
|
-
// TODO: use the path vs body etc serialisation also in the Client.
|
|
135
|
-
const makeReqQuerySchema = Effect(Option.fromNullable(Req.Query)).flatMap((_) =>
|
|
136
|
-
_.match({
|
|
137
|
-
onNone: () => Effect(Option.none),
|
|
138
|
-
onSome: (_) => jsonSchema(_).map(Option.some)
|
|
139
|
-
})
|
|
140
|
-
)
|
|
141
|
-
const makeReqHeadersSchema = Effect(Option.fromNullable(Req.Headers)).flatMap((_) =>
|
|
142
|
-
_.match({
|
|
143
|
-
onNone: () => Effect(Option.none),
|
|
144
|
-
onSome: (_) => jsonSchema(_).map(Option.some)
|
|
145
|
-
})
|
|
146
|
-
)
|
|
147
|
-
const makeReqCookieSchema = Effect(Option.fromNullable(Req.Cookie)).flatMap((_) =>
|
|
148
|
-
_.match({
|
|
149
|
-
onNone: () => Effect(Option.none),
|
|
150
|
-
onSome: (_) => jsonSchema(_).map(Option.some)
|
|
151
|
-
})
|
|
152
|
-
)
|
|
153
|
-
const makeReqPathSchema = Effect(Option.fromNullable(Req.Path)).flatMap((_) =>
|
|
154
|
-
_.match({
|
|
155
|
-
onNone: () => Effect(Option.none),
|
|
156
|
-
onSome: (_) => jsonSchema(_).map(Option.some)
|
|
157
|
-
})
|
|
158
|
-
)
|
|
159
|
-
const makeReqBodySchema = Effect(Option.fromNullable(Req.Body)).flatMap((_) =>
|
|
160
|
-
_.match({
|
|
161
|
-
onNone: () => Effect(Option.none),
|
|
162
|
-
onSome: (_) => jsonSchema(_).map(Option.some)
|
|
163
|
-
})
|
|
164
|
-
)
|
|
165
|
-
// const makeReqSchema = schema(Req)
|
|
166
|
-
|
|
167
|
-
const makeResSchema = jsonSchema_(Res)
|
|
168
|
-
|
|
169
|
-
function makeParameters(inn: ParameterLocation) {
|
|
170
|
-
return (a: Option<JSONSchema | SubSchema>) => {
|
|
171
|
-
return a
|
|
172
|
-
.flatMap((o) => (isObjectSchema(o) ? Option(o) : Option.none))
|
|
173
|
-
.map((x) => {
|
|
174
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
175
|
-
return Object.keys(x.properties!).map((p) => {
|
|
176
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
177
|
-
const schema = x.properties![p]
|
|
178
|
-
const required = Boolean(x.required?.includes(p))
|
|
179
|
-
return { name: p, in: inn, required, schema }
|
|
180
|
-
})
|
|
181
|
-
})
|
|
182
|
-
.getOrElse(() => [])
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return Effect
|
|
187
|
-
.all({
|
|
188
|
-
req: jsonSchema(Req.Model),
|
|
189
|
-
reqQuery: makeReqQuerySchema,
|
|
190
|
-
reqHeaders: makeReqHeadersSchema,
|
|
191
|
-
reqBody: makeReqBodySchema,
|
|
192
|
-
reqPath: makeReqPathSchema,
|
|
193
|
-
reqCookie: makeReqCookieSchema,
|
|
194
|
-
res: makeResSchema
|
|
195
|
-
})
|
|
196
|
-
.map((_) => {
|
|
197
|
-
// console.log("$$$ REQ", _.req)
|
|
198
|
-
const isEmpty = !e.handler.Response || e.handler.Response === S.Void
|
|
199
|
-
return {
|
|
200
|
-
path: e.path,
|
|
201
|
-
method: e.method.toLowerCase(),
|
|
202
|
-
tags: e.info?.tags,
|
|
203
|
-
description: _.req?.description,
|
|
204
|
-
summary: _.req?.summary,
|
|
205
|
-
operationId: _.req?.title,
|
|
206
|
-
parameters: [
|
|
207
|
-
...makeParameters("path")(_.reqPath),
|
|
208
|
-
...makeParameters("query")(_.reqQuery),
|
|
209
|
-
...makeParameters("header")(_.reqHeaders),
|
|
210
|
-
...makeParameters("cookie")(_.reqCookie)
|
|
211
|
-
],
|
|
212
|
-
requestBody: _
|
|
213
|
-
.reqBody
|
|
214
|
-
.map((schema) => ({
|
|
215
|
-
content: { "application/json": { schema } }
|
|
216
|
-
}))
|
|
217
|
-
.value,
|
|
218
|
-
responses: [
|
|
219
|
-
isEmpty
|
|
220
|
-
? new Response(204, { description: "Empty" })
|
|
221
|
-
: new Response(200, {
|
|
222
|
-
description: "OK",
|
|
223
|
-
content: { "application/json": { schema: _.res } }
|
|
224
|
-
}),
|
|
225
|
-
new Response(400, { description: "ValidationError" })
|
|
226
|
-
]
|
|
227
|
-
.concat(
|
|
228
|
-
e.path.includes(":") && isEmpty
|
|
229
|
-
? [new Response(404, { description: "NotFoundError" })]
|
|
230
|
-
: []
|
|
231
|
-
)
|
|
232
|
-
}
|
|
233
|
-
})
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
class Response {
|
|
237
|
-
constructor(
|
|
238
|
-
public readonly statusCode: number,
|
|
239
|
-
public readonly type: any // string | JSONSchema | SubSchema
|
|
240
|
-
) {}
|
|
241
|
-
}
|
package/_src/test.arbs.ts.bak
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// Do not import to frontend
|
|
2
|
-
|
|
3
|
-
import { setFaker } from "@effect-app/prelude/faker"
|
|
4
|
-
import type { Arbitrary } from "@effect-app/prelude/schema"
|
|
5
|
-
import { faker } from "@faker-js/faker"
|
|
6
|
-
import { Random } from "fast-check"
|
|
7
|
-
import * as fc from "fast-check"
|
|
8
|
-
import * as rand from "pure-rand"
|
|
9
|
-
|
|
10
|
-
const rnd = new Random(rand.congruential32(5))
|
|
11
|
-
|
|
12
|
-
setFaker(faker)
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @tsplus getter FastCheck generate
|
|
16
|
-
*/
|
|
17
|
-
export function generate<T>(arb: fc.Arbitrary<T>) {
|
|
18
|
-
return arb.generate(rnd, undefined)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @tsplus getter ets/Schema/Arbitrary/Gen generate
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
export function generateFromArbitrary<T>(arb: Arbitrary.Gen<T>) {
|
|
26
|
-
return generate(arb(fc))
|
|
27
|
-
}
|