@effect-app/infra 4.0.0-beta.68 → 4.0.0-beta.69
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 +8 -0
- package/package.json +4 -4
- package/src/QueueMaker/SQLQueue.ts +14 -6
- package/src/Store/Disk.ts +1 -1
- package/src/Store/Memory.ts +1 -1
- package/src/api/internal/events.ts +1 -1
- package/test/query.test.ts +4 -4
- package/test/requires.test.ts +2 -1
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-app/infra",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.69",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"proper-lockfile": "^4.1.2",
|
|
14
14
|
"pure-rand": "7.0.1",
|
|
15
15
|
"query-string": "^9.3.1",
|
|
16
|
-
"effect-app": "4.0.0-beta.
|
|
16
|
+
"effect-app": "4.0.0-beta.69"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@azure/cosmos": "^4.9.2",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@azure/cosmos": "^4.9.2",
|
|
41
41
|
"@azure/service-bus": "^7.9.5",
|
|
42
|
-
"@effect/vitest": "^4.0.0-beta.
|
|
42
|
+
"@effect/vitest": "^4.0.0-beta.46",
|
|
43
43
|
"@sendgrid/helpers": "^8.0.0",
|
|
44
44
|
"@sendgrid/mail": "^8.1.6",
|
|
45
45
|
"@sentry/node": "10.47.0",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"jwt-decode": "^4.0.0",
|
|
48
48
|
"redis": "^3.1.2",
|
|
49
49
|
"redlock": "^4.2.0",
|
|
50
|
-
"effect": "^4.0.0-beta.
|
|
50
|
+
"effect": "^4.0.0-beta.46",
|
|
51
51
|
"express": "^5.2.1"
|
|
52
52
|
},
|
|
53
53
|
"typesVersions": {
|
|
@@ -3,8 +3,9 @@ import { reportNonInterruptedFailure } from "@effect-app/infra/QueueMaker/errors
|
|
|
3
3
|
import { type QueueBase, QueueMeta } from "@effect-app/infra/QueueMaker/service"
|
|
4
4
|
import { subMinutes } from "date-fns"
|
|
5
5
|
import { Effect, Fiber, type NonEmptyReadonlyArray, Option, S, Tracer } from "effect-app"
|
|
6
|
-
import type
|
|
6
|
+
import { DateTimeUtcFromDate, type NonEmptyString255 } from "effect-app/Schema"
|
|
7
7
|
import { pretty } from "effect-app/utils"
|
|
8
|
+
import { Override } from "effect/unstable/schema/Model"
|
|
8
9
|
import { SqlClient } from "effect/unstable/sql"
|
|
9
10
|
import { SQLModel } from "../adapters/SQL.js"
|
|
10
11
|
import { InfraLogger } from "../logger.js"
|
|
@@ -78,31 +79,38 @@ export function makeSQLQueue<
|
|
|
78
79
|
|
|
79
80
|
const q = {
|
|
80
81
|
offer: Effect.fnUntraced(function*(body: Evt, meta: typeof QueueMeta.Type) {
|
|
82
|
+
const now = S.decodeSync(DateTimeUtcFromDate)(new Date())
|
|
81
83
|
yield* queueRepo.insertVoid({
|
|
82
84
|
body,
|
|
83
85
|
meta,
|
|
84
86
|
name: queueName,
|
|
85
87
|
processingAt: Option.none(),
|
|
86
88
|
finishedAt: Option.none(),
|
|
87
|
-
etag: crypto.randomUUID()
|
|
89
|
+
etag: crypto.randomUUID(),
|
|
90
|
+
createdAt: Override(now),
|
|
91
|
+
updatedAt: Override(now)
|
|
88
92
|
})
|
|
89
93
|
}),
|
|
90
94
|
take: Effect.gen(function*() {
|
|
91
95
|
while (true) {
|
|
96
|
+
const now = S.decodeSync(DateTimeUtcFromDate)(new Date())
|
|
92
97
|
const [first] = yield* drain.pipe(Effect.withTracerEnabled(false)) // disable sql tracer otherwise we spam it..
|
|
93
98
|
if (first) {
|
|
94
99
|
const dec = yield* decodeDrain(first)
|
|
95
|
-
const {
|
|
100
|
+
const { updatedAt, ...rest } = dec
|
|
96
101
|
return yield* drainRepo.update(
|
|
97
|
-
{ ...rest, processingAt: Option.some(new Date()) } // auto in lib , etag: crypto.randomUUID()
|
|
102
|
+
{ ...rest, updatedAt: Override(now), processingAt: Option.some(new Date()) } // auto in lib , etag: crypto.randomUUID()
|
|
98
103
|
)
|
|
99
104
|
}
|
|
100
105
|
if (first) return first
|
|
101
106
|
yield* Effect.sleep(250)
|
|
102
107
|
}
|
|
103
108
|
}),
|
|
104
|
-
finish: ({
|
|
105
|
-
|
|
109
|
+
finish: Effect.fn(function*({ updatedAt, ...q }: Drain) {
|
|
110
|
+
const now = S.decodeSync(DateTimeUtcFromDate)(new Date())
|
|
111
|
+
|
|
112
|
+
return yield* drainRepo.updateVoid({ ...q, updatedAt: Override(now), finishedAt: Option.some(new Date()) }) // auto in lib , etag: crypto.randomUUID()
|
|
113
|
+
})
|
|
106
114
|
}
|
|
107
115
|
const queue = {
|
|
108
116
|
publish: (...messages: NonEmptyReadonlyArray<Evt>) =>
|
package/src/Store/Disk.ts
CHANGED
|
@@ -142,7 +142,7 @@ export function makeDiskStore({ prefix }: StorageConfig, dir: string) {
|
|
|
142
142
|
const storesSem = Semaphore.makeUnsafe(1)
|
|
143
143
|
const primary = yield* makeDiskStoreInt(prefix, idKey, "primary", dir, name, seed, config?.defaultValues)
|
|
144
144
|
const stores = new Map<string, Store<IdKey, Encoded>>([["primary", primary]])
|
|
145
|
-
const ctx = yield* Effect.
|
|
145
|
+
const ctx = yield* Effect.context<R>()
|
|
146
146
|
const getStore = !config?.allowNamespace
|
|
147
147
|
? Effect.succeed(primary)
|
|
148
148
|
: storeId.asEffect().pipe(Effect.flatMap((namespace) => {
|
package/src/Store/Memory.ts
CHANGED
|
@@ -265,7 +265,7 @@ export const makeMemoryStore = () => ({
|
|
|
265
265
|
seed,
|
|
266
266
|
config?.defaultValues
|
|
267
267
|
)
|
|
268
|
-
const ctx = yield* Effect.
|
|
268
|
+
const ctx = yield* Effect.context<R>()
|
|
269
269
|
const stores = new Map([["primary", primary]])
|
|
270
270
|
const getStore = !config?.allowNamespace
|
|
271
271
|
? Effect.succeed(primary)
|
|
@@ -16,7 +16,7 @@ export const makeSSE = <A extends { id: any }, SI, SR>(
|
|
|
16
16
|
Effect
|
|
17
17
|
.gen(function*() {
|
|
18
18
|
const id = connId++
|
|
19
|
-
const ctx = yield* Effect.
|
|
19
|
+
const ctx = yield* Effect.context<R | SR>()
|
|
20
20
|
const res = HttpServerResponse.stream(
|
|
21
21
|
// workaround for different scoped behaviour for streams in Bun
|
|
22
22
|
// https://discord.com/channels/795981131316985866/1098177242598756412/1389646879675125861
|
package/test/query.test.ts
CHANGED
|
@@ -520,8 +520,8 @@ it(
|
|
|
520
520
|
const schema = S.Struct({
|
|
521
521
|
id: S.String,
|
|
522
522
|
createdAt: S.Date.pipe(
|
|
523
|
-
S.withDecodingDefault(() => new Date().toISOString()),
|
|
524
|
-
S.withConstructorDefault(() =>
|
|
523
|
+
S.withDecodingDefault(Effect.sync(() => new Date().toISOString())),
|
|
524
|
+
S.withConstructorDefault(Effect.sync(() => new Date()))
|
|
525
525
|
)
|
|
526
526
|
})
|
|
527
527
|
const repo = yield* makeRepo(
|
|
@@ -533,8 +533,8 @@ it(
|
|
|
533
533
|
const outputSchema = S.Struct({
|
|
534
534
|
id: S.Literal("123"),
|
|
535
535
|
createdAt: S.Date.pipe(
|
|
536
|
-
S.withDecodingDefault(() => new Date().toISOString()),
|
|
537
|
-
S.withConstructorDefault(() =>
|
|
536
|
+
S.withDecodingDefault(Effect.sync(() => new Date().toISOString())),
|
|
537
|
+
S.withConstructorDefault(Effect.sync(() => new Date()))
|
|
538
538
|
)
|
|
539
539
|
})
|
|
540
540
|
|
package/test/requires.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, expectTypeOf, it } from "@effect/vitest"
|
|
2
|
-
import { Effect, Layer, Result, S
|
|
2
|
+
import { Context, Effect, Layer, Result, S } from "effect-app"
|
|
3
3
|
import { NotLoggedInError, UnauthorizedError } from "effect-app/client"
|
|
4
4
|
import { HttpHeaders } from "effect-app/http"
|
|
5
5
|
import * as RpcX from "effect-app/rpc"
|
|
@@ -63,6 +63,7 @@ const testSuite = (_mw: typeof middleware3) =>
|
|
|
63
63
|
"works",
|
|
64
64
|
Effect.fn(function*() {
|
|
65
65
|
const defaultOpts = {
|
|
66
|
+
client: null as any, // TODO?
|
|
66
67
|
headers: HttpHeaders.fromRecordUnsafe({}),
|
|
67
68
|
payload: { _tag: "Test" },
|
|
68
69
|
clientId: 0,
|