@effect-app/infra 2.3.2 → 2.3.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/CHANGELOG.md +14 -0
- package/_cjs/Model.cjs +13 -0
- package/_cjs/Model.cjs.map +1 -0
- package/_cjs/index.cjs +5 -0
- package/_cjs/services/QueueMaker/SQLQueue.cjs +14 -14
- package/_cjs/services/QueueMaker/SQLQueue.cjs.map +1 -1
- package/_cjs/services/RepositoryBase.cjs +21 -7
- package/_cjs/services/RepositoryBase.cjs.map +1 -1
- package/_cjs/services/Store/Memory.cjs +3 -2
- package/_cjs/services/Store/Memory.cjs.map +1 -1
- package/_cjs/services/Store/codeFilter.cjs +4 -0
- package/_cjs/services/Store/codeFilter.cjs.map +1 -1
- package/_cjs/services/Store/utils.cjs +0 -5
- package/_cjs/services/Store/utils.cjs.map +1 -1
- package/_cjs/services/adapters/SQL.cjs +3 -3
- package/_cjs/services/query/new-kid-interpreter.cjs +4 -4
- package/_cjs/services/query/new-kid-interpreter.cjs.map +1 -1
- package/dist/Model.d.ts +2 -0
- package/dist/Model.d.ts.map +1 -0
- package/dist/Model.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/services/QueueMaker/SQLQueue.js +16 -16
- package/dist/services/Repository/ext.d.ts +11 -11
- package/dist/services/RepositoryBase.d.ts +43 -5
- package/dist/services/RepositoryBase.d.ts.map +1 -1
- package/dist/services/RepositoryBase.js +16 -6
- package/dist/services/Store/Memory.d.ts.map +1 -1
- package/dist/services/Store/Memory.js +3 -2
- package/dist/services/Store/codeFilter.d.ts +5 -0
- package/dist/services/Store/codeFilter.d.ts.map +1 -1
- package/dist/services/Store/codeFilter.js +5 -2
- package/dist/services/Store/utils.d.ts +1 -4
- package/dist/services/Store/utils.d.ts.map +1 -1
- package/dist/services/Store/utils.js +1 -5
- package/dist/services/adapters/SQL.d.ts +1 -1
- package/dist/services/adapters/SQL.d.ts.map +1 -1
- package/dist/services/adapters/SQL.js +2 -2
- package/dist/services/query/new-kid-interpreter.d.ts +1 -1
- package/dist/services/query/new-kid-interpreter.d.ts.map +1 -1
- package/dist/services/query/new-kid-interpreter.js +2 -2
- package/package.json +12 -2
- package/src/Model.ts +1 -0
- package/src/index.ts +1 -0
- package/src/services/QueueMaker/SQLQueue.ts +15 -15
- package/src/services/RepositoryBase.ts +112 -5
- package/src/services/Store/Memory.ts +2 -1
- package/src/services/Store/codeFilter.ts +6 -1
- package/src/services/Store/utils.ts +1 -6
- package/src/services/adapters/SQL.ts +1 -1
- package/src/services/query/new-kid-interpreter.ts +1 -1
|
@@ -329,7 +329,7 @@ const dedupe = Array.dedupeWith(Equivalence.string)
|
|
|
329
329
|
/**
|
|
330
330
|
* A base implementation to create a repository.
|
|
331
331
|
*/
|
|
332
|
-
export function
|
|
332
|
+
export function makeRepoInternal<
|
|
333
333
|
Evt = never
|
|
334
334
|
>() {
|
|
335
335
|
return <
|
|
@@ -979,7 +979,7 @@ export const RepositoryBaseImpl = <Service>() => {
|
|
|
979
979
|
>
|
|
980
980
|
& RepoFunctions<T, Encoded, Evt, ItemType, IdKey, Service> =>
|
|
981
981
|
{
|
|
982
|
-
const mkRepo =
|
|
982
|
+
const mkRepo = makeRepoInternal<Evt>()(
|
|
983
983
|
itemType,
|
|
984
984
|
schema,
|
|
985
985
|
jitM ? (pm) => jitM(pm as unknown as Encoded) : (pm) => pm as any,
|
|
@@ -1052,7 +1052,7 @@ export const RepositoryDefaultImpl = <Service, Evt = never>() => {
|
|
|
1052
1052
|
jitM?: (pm: Encoded) => Encoded
|
|
1053
1053
|
) => {
|
|
1054
1054
|
if (!jitM && idKeyOrJitM !== undefined && typeof idKeyOrJitM === "function") jitM = idKeyOrJitM
|
|
1055
|
-
const mkRepo =
|
|
1055
|
+
const mkRepo = makeRepoInternal<Evt>()(
|
|
1056
1056
|
itemType,
|
|
1057
1057
|
schema,
|
|
1058
1058
|
jitM ? (pm) => jitM(pm) : (pm) => pm,
|
|
@@ -1312,7 +1312,7 @@ export const RepositoryDefaultImpl2 = <Service, Evt = never>() => {
|
|
|
1312
1312
|
return layerCache ??= Effect
|
|
1313
1313
|
.gen(function*() {
|
|
1314
1314
|
const opts = yield* options.options ?? Effect.succeed({})
|
|
1315
|
-
const mkRepo =
|
|
1315
|
+
const mkRepo = makeRepoInternal<Evt>()(
|
|
1316
1316
|
itemType,
|
|
1317
1317
|
schema,
|
|
1318
1318
|
options?.jitM ? (pm) => options.jitM!(pm) : (pm) => pm,
|
|
@@ -1320,7 +1320,8 @@ export const RepositoryDefaultImpl2 = <Service, Evt = never>() => {
|
|
|
1320
1320
|
options.idKey ?? "id" as any
|
|
1321
1321
|
)
|
|
1322
1322
|
const r = yield* mkRepo.make({ ...options, ...opts } as any)
|
|
1323
|
-
|
|
1323
|
+
const repo = new self(Object.assign(r, "ext" in opts ? opts.ext : {}))
|
|
1324
|
+
return Layer.succeed(self, repo)
|
|
1324
1325
|
})
|
|
1325
1326
|
.pipe(Layer.unwrapEffect)
|
|
1326
1327
|
}
|
|
@@ -1347,6 +1348,112 @@ export const RepositoryDefaultImpl2 = <Service, Evt = never>() => {
|
|
|
1347
1348
|
return f
|
|
1348
1349
|
}
|
|
1349
1350
|
|
|
1351
|
+
export const makeRepo = <Evt = never>() => {
|
|
1352
|
+
const f: {
|
|
1353
|
+
<
|
|
1354
|
+
ItemType extends string,
|
|
1355
|
+
R,
|
|
1356
|
+
Encoded extends { id: string },
|
|
1357
|
+
T,
|
|
1358
|
+
IdKey extends keyof T,
|
|
1359
|
+
E = never,
|
|
1360
|
+
RInitial = never,
|
|
1361
|
+
R2 = never
|
|
1362
|
+
>(
|
|
1363
|
+
itemType: ItemType,
|
|
1364
|
+
schema: S.Schema<T, Encoded, R>,
|
|
1365
|
+
options: [Evt] extends [never] ? {
|
|
1366
|
+
idKey: IdKey
|
|
1367
|
+
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
1368
|
+
partitionValue?: (a: Encoded) => string
|
|
1369
|
+
}
|
|
1370
|
+
jitM?: (pm: Encoded) => Encoded
|
|
1371
|
+
makeInitial?: Effect<readonly T[], E, RInitial>
|
|
1372
|
+
}
|
|
1373
|
+
: {
|
|
1374
|
+
idKey: IdKey
|
|
1375
|
+
jitM?: (pm: Encoded) => Encoded
|
|
1376
|
+
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
1377
|
+
partitionValue?: (a: Encoded) => string
|
|
1378
|
+
}
|
|
1379
|
+
publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect<void, never, R2>
|
|
1380
|
+
makeInitial?: Effect<readonly T[], E, RInitial>
|
|
1381
|
+
}
|
|
1382
|
+
): // TODO: drop ext
|
|
1383
|
+
Effect.Effect<RepositoryBaseC3<T, Encoded, Evt, ItemType, {}, IdKey>, E, R | RInitial | R2 | StoreMaker>
|
|
1384
|
+
<
|
|
1385
|
+
ItemType extends string,
|
|
1386
|
+
R,
|
|
1387
|
+
Encoded extends { id: string },
|
|
1388
|
+
T extends { id: unknown },
|
|
1389
|
+
E = never,
|
|
1390
|
+
RInitial = never,
|
|
1391
|
+
R2 = never
|
|
1392
|
+
>(
|
|
1393
|
+
itemType: ItemType,
|
|
1394
|
+
schema: S.Schema<T, Encoded, R>,
|
|
1395
|
+
options: [Evt] extends [never] ? {
|
|
1396
|
+
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
1397
|
+
partitionValue?: (a: Encoded) => string
|
|
1398
|
+
}
|
|
1399
|
+
jitM?: (pm: Encoded) => Encoded
|
|
1400
|
+
makeInitial?: Effect<readonly T[], E, RInitial>
|
|
1401
|
+
}
|
|
1402
|
+
: {
|
|
1403
|
+
jitM?: (pm: Encoded) => Encoded
|
|
1404
|
+
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
1405
|
+
partitionValue?: (a: Encoded) => string
|
|
1406
|
+
}
|
|
1407
|
+
publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect<void, never, R2>
|
|
1408
|
+
makeInitial?: Effect<readonly T[], E, RInitial>
|
|
1409
|
+
}
|
|
1410
|
+
): Effect.Effect<RepositoryBaseC3<T, Encoded, Evt, ItemType, {}, "id">, E, R | RInitial | R2 | StoreMaker>
|
|
1411
|
+
} = <
|
|
1412
|
+
ItemType extends string,
|
|
1413
|
+
R,
|
|
1414
|
+
Encoded extends { id: string },
|
|
1415
|
+
T,
|
|
1416
|
+
IdKey extends keyof T,
|
|
1417
|
+
E = never,
|
|
1418
|
+
RInitial = never,
|
|
1419
|
+
R2 = never
|
|
1420
|
+
>(
|
|
1421
|
+
itemType: ItemType,
|
|
1422
|
+
schema: S.Schema<T, Encoded, R>,
|
|
1423
|
+
options: [Evt] extends [never] ? {
|
|
1424
|
+
idKey?: IdKey
|
|
1425
|
+
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
1426
|
+
partitionValue?: (a: Encoded) => string
|
|
1427
|
+
}
|
|
1428
|
+
jitM?: (pm: Encoded) => Encoded
|
|
1429
|
+
makeInitial?: Effect<readonly T[], E, RInitial>
|
|
1430
|
+
}
|
|
1431
|
+
: {
|
|
1432
|
+
idKey?: IdKey
|
|
1433
|
+
jitM?: (pm: Encoded) => Encoded
|
|
1434
|
+
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
1435
|
+
partitionValue?: (a: Encoded) => string
|
|
1436
|
+
}
|
|
1437
|
+
publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect<void, never, R2>
|
|
1438
|
+
makeInitial?: Effect<readonly T[], E, RInitial>
|
|
1439
|
+
}
|
|
1440
|
+
) =>
|
|
1441
|
+
Effect.gen(function*() {
|
|
1442
|
+
const mkRepo = makeRepoInternal<Evt>()(
|
|
1443
|
+
itemType,
|
|
1444
|
+
schema,
|
|
1445
|
+
options?.jitM ? (pm) => options.jitM!(pm) : (pm) => pm,
|
|
1446
|
+
(e, _etag) => ({ ...e, _etag }),
|
|
1447
|
+
options.idKey ?? "id" as any
|
|
1448
|
+
)
|
|
1449
|
+
const r = yield* mkRepo.make(options)
|
|
1450
|
+
const repo = new RepositoryBaseC3(itemType, r)
|
|
1451
|
+
return repo
|
|
1452
|
+
})
|
|
1453
|
+
|
|
1454
|
+
return f
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1350
1457
|
const names = new Map<string, number>()
|
|
1351
1458
|
const registerName = (name: string) => {
|
|
1352
1459
|
const existing = names.get(name)
|
|
@@ -5,9 +5,10 @@ import type { NonEmptyReadonlyArray } from "effect-app"
|
|
|
5
5
|
import { NonEmptyString255 } from "effect-app/Schema"
|
|
6
6
|
import { get } from "effect-app/utils"
|
|
7
7
|
import { InfraLogger } from "../../logger.js"
|
|
8
|
+
import { codeFilter } from "./codeFilter.js"
|
|
8
9
|
import type { FilterArgs, PersistenceModelType, Store, StoreConfig } from "./service.js"
|
|
9
10
|
import { StoreMaker } from "./service.js"
|
|
10
|
-
import {
|
|
11
|
+
import { makeUpdateETag } from "./utils.js"
|
|
11
12
|
|
|
12
13
|
export function memFilter<T extends { id: string }, U extends keyof T = never>(f: FilterArgs<T, U>) {
|
|
13
14
|
type M = U extends undefined ? T : Pick<T, U>
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
3
|
-
import { Array } from "effect-app"
|
|
3
|
+
import { Array, Option } from "effect-app"
|
|
4
4
|
import { assertUnreachable, get } from "effect-app/utils"
|
|
5
5
|
import type { FilterR, FilterResult } from "./filterApi/query.js"
|
|
6
|
+
import type { Filter } from "./service.js"
|
|
6
7
|
import { compare, greaterThan, greaterThanExclusive, lowerThan, lowerThanExclusive } from "./utils.js"
|
|
7
8
|
|
|
8
9
|
const vAsArr = (v: string) => v as unknown as any[]
|
|
@@ -118,3 +119,7 @@ export const codeFilter3_ = <E>(state: readonly FilterResult[], sut: E): boolean
|
|
|
118
119
|
const s = codeFilter3__(state, sut, statements)
|
|
119
120
|
return eval(s)
|
|
120
121
|
}
|
|
122
|
+
|
|
123
|
+
export function codeFilter<E extends { id: string }, NE extends E>(filter: Filter) {
|
|
124
|
+
return (x: E) => codeFilter3_(filter, x) ? Option.some(x as unknown as NE) : Option.none()
|
|
125
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Effect, Option } from "effect-app"
|
|
2
2
|
import objectHash from "object-hash"
|
|
3
3
|
import { OptimisticConcurrencyException } from "../../errors.js"
|
|
4
|
-
import {
|
|
5
|
-
import type { Filter, PersistenceModelType, SupportedValues2 } from "./service.js"
|
|
4
|
+
import type { PersistenceModelType, SupportedValues2 } from "./service.js"
|
|
6
5
|
|
|
7
6
|
export const makeETag = <E extends PersistenceModelType<{}>>(
|
|
8
7
|
{ _etag, ...e }: E
|
|
@@ -31,10 +30,6 @@ export const makeUpdateETag =
|
|
|
31
30
|
return newE
|
|
32
31
|
})
|
|
33
32
|
|
|
34
|
-
export function codeFilter<E extends { id: string }, NE extends E>(filter: Filter) {
|
|
35
|
-
return (x: E) => codeFilter3_(filter, x) ? Option.some(x as unknown as NE) : Option.none()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
33
|
export function lowercaseIfString<T>(val: T) {
|
|
39
34
|
if (typeof val === "string") {
|
|
40
35
|
return val.toLowerCase()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * as
|
|
1
|
+
export * as SQLModel from "./SQL/Model.js"
|
|
@@ -5,7 +5,7 @@ import { toNonEmptyArray } from "effect-app/Array"
|
|
|
5
5
|
import { dropUndefinedT } from "effect-app/utils"
|
|
6
6
|
import type { FieldValues } from "../../filter/types.js"
|
|
7
7
|
import type { FieldPath } from "../../filter/types/path/eager.js"
|
|
8
|
-
import { make, type Q, type QAll } from "../query.js"
|
|
8
|
+
import { make, type Q, type QAll } from "../query/dsl.js"
|
|
9
9
|
import type { FilterResult } from "../Store/filterApi/query.js"
|
|
10
10
|
|
|
11
11
|
type Result<TFieldValues extends FieldValues, A = TFieldValues, R = never> = {
|