@effect-app/infra 2.3.3 → 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.
@@ -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 makeRepo<
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 = makeRepo<Evt>()(
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 = makeRepo<Evt>()(
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 = makeRepo<Evt>()(
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
- return Layer.succeed(self, new self(Object.assign(r, "ext" in opts ? opts.ext : {})))
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)
@@ -1 +1 @@
1
- export * as Model from "./SQL/Model.js"
1
+ export * as SQLModel from "./SQL/Model.js"