@entifix/business 0.23.11 → 0.23.12

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.
@@ -1,4 +1,4 @@
1
- import type { EntifixFailure, Entity, EntityId, EntityLoadRequest, EntityPage } from '@entifix/core';
1
+ import type { EntifixFailure, Entity, EntityId, EntityLoadRequest, EntityPage, UseCaseAvailability } from '@entifix/core';
2
2
  import { Context } from 'effect';
3
3
  import { Effect } from 'effect/Effect';
4
4
  /**
@@ -18,11 +18,27 @@ export type RepositoryFailure = EntifixFailure;
18
18
  * every use case, and every caller of a static or in-memory adapter would have
19
19
  * to provide a value it never reads.
20
20
  */
21
+ /**
22
+ * How a write is conditioned beyond its revision.
23
+ *
24
+ * `expect` names the states the stored record must hold for the write to
25
+ * happen — an entity's `writableWhen` on an update, its `deletableWhen` on a
26
+ * delete ([ADR 0029](../../../../../docs/adr/0029-a-verb-declares-the-states-it-is-legal-from.md)).
27
+ * An adapter conjoins it onto the write itself, never a read followed by a
28
+ * write, and answers `UnavailableInState` when the record is in another one.
29
+ *
30
+ * ⚠️ A save with `expect` is an **update**: it never creates. A record that is
31
+ * not there answers `NotFound`; a delete of one that is not there still
32
+ * succeeds, as an unconditioned delete does.
33
+ */
34
+ export interface EntityWriteOptions {
35
+ readonly expect?: UseCaseAvailability;
36
+ }
21
37
  export interface EntityRepository {
22
38
  get<TEntity extends Entity>(id: EntityId): Effect<TEntity, RepositoryFailure>;
23
39
  load<TEntity extends Entity>(request: EntityLoadRequest<TEntity>): Effect<EntityPage<TEntity>, RepositoryFailure>;
24
- save<TEntity extends Entity>(entity: TEntity): Effect<TEntity, RepositoryFailure>;
25
- delete<TEntity extends Entity>(entityOrId: EntityId | TEntity): Effect<void, RepositoryFailure>;
40
+ save<TEntity extends Entity>(entity: TEntity, options?: EntityWriteOptions): Effect<TEntity, RepositoryFailure>;
41
+ delete<TEntity extends Entity>(entityOrId: EntityId | TEntity, options?: EntityWriteOptions): Effect<void, RepositoryFailure>;
26
42
  }
27
43
  declare const EntityRepositoryTag_base: Context.ServiceClass<EntityRepositoryTag, "EntityRepositoryTag", EntityRepository>;
28
44
  export declare class EntityRepositoryTag extends EntityRepositoryTag_base {
@@ -1 +1 @@
1
- {"version":3,"file":"entity.repository.d.ts","sourceRoot":"","sources":["../../src/repository/entity.repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,MAAM,EACN,QAAQ,EACR,iBAAiB,EACjB,UAAU,EACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAE/C;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,OAAO,SAAS,MAAM,EAAE,EAAE,EAAE,QAAQ,GAAG,MAAM,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAC9E,IAAI,CAAC,OAAO,SAAS,MAAM,EACzB,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAClC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC;IAClD,IAAI,CAAC,OAAO,SAAS,MAAM,EACzB,MAAM,EAAE,OAAO,GACd,MAAM,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IACtC,MAAM,CAAC,OAAO,SAAS,MAAM,EAC3B,UAAU,EAAE,QAAQ,GAAG,OAAO,GAC7B,MAAM,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;CACpC;;AAED,qBAAa,mBAAoB,SAAQ,wBAGf;CAAG"}
1
+ {"version":3,"file":"entity.repository.d.ts","sourceRoot":"","sources":["../../src/repository/entity.repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,MAAM,EACN,QAAQ,EACR,iBAAiB,EACjB,UAAU,EACV,mBAAmB,EACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAE/C;;;;;;;;;GASG;AACH;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,CAAC;CACvC;AAED,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,OAAO,SAAS,MAAM,EAAE,EAAE,EAAE,QAAQ,GAAG,MAAM,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAC9E,IAAI,CAAC,OAAO,SAAS,MAAM,EACzB,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAClC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC;IAClD,IAAI,CAAC,OAAO,SAAS,MAAM,EACzB,MAAM,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,kBAAkB,GAC3B,MAAM,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IACtC,MAAM,CAAC,OAAO,SAAS,MAAM,EAC3B,UAAU,EAAE,QAAQ,GAAG,OAAO,EAC9B,OAAO,CAAC,EAAE,kBAAkB,GAC3B,MAAM,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;CACpC;;AAED,qBAAa,mBAAoB,SAAQ,wBAGf;CAAG"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/repository/entity.repository.ts"],"sourcesContent":["import type {\n EntifixFailure,\n Entity,\n EntityId,\n EntityLoadRequest,\n EntityPage,\n} from '@entifix/core';\nimport { Context } from 'effect';\nimport { Effect } from 'effect/Effect';\n\n/**\n * What a repository fails with while the adapters move to typed failures\n * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)):\n * the old class tree, or a categorised failure — an `InvalidEnvelope` from a\n * transport, a `DuplicateKey` from a store.\n */\nexport type RepositoryFailure = EntifixFailure;\n\n/**\n * Where a use case reads and writes one entity's records.\n *\n * ⚠️ **Every method requires nothing from its environment.** An adapter that\n * needs something to do its job — a REST client's base URL, a database handle —\n * binds it when the adapter is built, so the port says only what every adapter\n * has in common. A requirement here would be one adapter's mechanism leaked into\n * every use case, and every caller of a static or in-memory adapter would have\n * to provide a value it never reads.\n */\nexport interface EntityRepository {\n get<TEntity extends Entity>(id: EntityId): Effect<TEntity, RepositoryFailure>;\n load<TEntity extends Entity>(\n request: EntityLoadRequest<TEntity>,\n ): Effect<EntityPage<TEntity>, RepositoryFailure>;\n save<TEntity extends Entity>(\n entity: TEntity,\n ): Effect<TEntity, RepositoryFailure>;\n delete<TEntity extends Entity>(\n entityOrId: EntityId | TEntity,\n ): Effect<void, RepositoryFailure>;\n}\n\nexport class EntityRepositoryTag extends Context.Service<\n EntityRepositoryTag,\n EntityRepository\n>()('EntityRepositoryTag') {}\n"],"names":["Context","EntityRepositoryTag","Service"],"mappings":"AAOA,SAASA,OAAO,QAAQ,SAAS;AAkCjC,OAAO,MAAMC,4BAA4BD,QAAQE,OAAO,GAGpD;AAAwB"}
1
+ {"version":3,"sources":["../../src/repository/entity.repository.ts"],"sourcesContent":["import type {\n EntifixFailure,\n Entity,\n EntityId,\n EntityLoadRequest,\n EntityPage,\n UseCaseAvailability,\n} from '@entifix/core';\nimport { Context } from 'effect';\nimport { Effect } from 'effect/Effect';\n\n/**\n * What a repository fails with while the adapters move to typed failures\n * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)):\n * the old class tree, or a categorised failure — an `InvalidEnvelope` from a\n * transport, a `DuplicateKey` from a store.\n */\nexport type RepositoryFailure = EntifixFailure;\n\n/**\n * Where a use case reads and writes one entity's records.\n *\n * ⚠️ **Every method requires nothing from its environment.** An adapter that\n * needs something to do its job — a REST client's base URL, a database handle —\n * binds it when the adapter is built, so the port says only what every adapter\n * has in common. A requirement here would be one adapter's mechanism leaked into\n * every use case, and every caller of a static or in-memory adapter would have\n * to provide a value it never reads.\n */\n/**\n * How a write is conditioned beyond its revision.\n *\n * `expect` names the states the stored record must hold for the write to\n * happen — an entity's `writableWhen` on an update, its `deletableWhen` on a\n * delete ([ADR 0029](../../../../../docs/adr/0029-a-verb-declares-the-states-it-is-legal-from.md)).\n * An adapter conjoins it onto the write itself, never a read followed by a\n * write, and answers `UnavailableInState` when the record is in another one.\n *\n * ⚠️ A save with `expect` is an **update**: it never creates. A record that is\n * not there answers `NotFound`; a delete of one that is not there still\n * succeeds, as an unconditioned delete does.\n */\nexport interface EntityWriteOptions {\n readonly expect?: UseCaseAvailability;\n}\n\nexport interface EntityRepository {\n get<TEntity extends Entity>(id: EntityId): Effect<TEntity, RepositoryFailure>;\n load<TEntity extends Entity>(\n request: EntityLoadRequest<TEntity>,\n ): Effect<EntityPage<TEntity>, RepositoryFailure>;\n save<TEntity extends Entity>(\n entity: TEntity,\n options?: EntityWriteOptions,\n ): Effect<TEntity, RepositoryFailure>;\n delete<TEntity extends Entity>(\n entityOrId: EntityId | TEntity,\n options?: EntityWriteOptions,\n ): Effect<void, RepositoryFailure>;\n}\n\nexport class EntityRepositoryTag extends Context.Service<\n EntityRepositoryTag,\n EntityRepository\n>()('EntityRepositoryTag') {}\n"],"names":["Context","EntityRepositoryTag","Service"],"mappings":"AAQA,SAASA,OAAO,QAAQ,SAAS;AAqDjC,OAAO,MAAMC,4BAA4BD,QAAQE,OAAO,GAGpD;AAAwB"}
@@ -1,6 +1,6 @@
1
1
  import { Entity } from '@entifix/core';
2
2
  import { Effect } from 'effect';
3
- import { EntityRepositoryTag } from '../../repository/entity.repository.js';
3
+ import { EntityRepositoryTag, type EntityWriteOptions } from '../../repository/entity.repository.js';
4
4
  import { EntityIdTag } from '../../repository/entity-mixins.repository.js';
5
5
  /**
6
6
  * Deletes an entity by id.
@@ -9,5 +9,5 @@ import { EntityIdTag } from '../../repository/entity-mixins.repository.js';
9
9
  * the only shape a caller ever has at the point of deletion (a table row, a
10
10
  * route param), so that is what this exposes.
11
11
  */
12
- export declare function deleteUCFactory<TEntity extends Entity>(): Effect.Effect<void, import("../../index.js").RepositoryFailure, EntityRepositoryTag | EntityIdTag>;
12
+ export declare function deleteUCFactory<TEntity extends Entity>(options?: EntityWriteOptions): Effect.Effect<void, import("../../index.js").RepositoryFailure, EntityRepositoryTag | EntityIdTag>;
13
13
  //# sourceMappingURL=delete.uc.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"delete.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/delete/delete.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,8CAA8C,CAAC;AAE3E;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,MAAM,wGAOrD"}
1
+ {"version":3,"file":"delete.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/delete/delete.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EACL,mBAAmB,EACnB,KAAK,kBAAkB,EACxB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,8CAA8C,CAAC;AAE3E;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,MAAM,EACpD,OAAO,CAAC,EAAE,kBAAkB,sGAQ7B"}
@@ -7,11 +7,11 @@ import { EntityIdTag } from '../../repository/entity-mixins.repository.js';
7
7
  * The repository contract also accepts a whole entity, but deleting by id is
8
8
  * the only shape a caller ever has at the point of deletion (a table row, a
9
9
  * route param), so that is what this exposes.
10
- */ export function deleteUCFactory() {
10
+ */ export function deleteUCFactory(options) {
11
11
  return Effect.gen(function*() {
12
12
  const entityRepository = yield* EntityRepositoryTag;
13
13
  const entityId = yield* EntityIdTag;
14
- yield* entityRepository.delete(entityId);
14
+ yield* entityRepository.delete(entityId, options);
15
15
  });
16
16
  }
17
17
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/use-case/delete/delete.uc.ts"],"sourcesContent":["import { Entity } from '@entifix/core';\nimport { Effect } from 'effect';\n\nimport { EntityRepositoryTag } from '../../repository/entity.repository.js';\nimport { EntityIdTag } from '../../repository/entity-mixins.repository.js';\n\n/**\n * Deletes an entity by id.\n *\n * The repository contract also accepts a whole entity, but deleting by id is\n * the only shape a caller ever has at the point of deletion (a table row, a\n * route param), so that is what this exposes.\n */\nexport function deleteUCFactory<TEntity extends Entity>() {\n return Effect.gen(function* () {\n const entityRepository = yield* EntityRepositoryTag;\n const entityId = yield* EntityIdTag;\n\n yield* entityRepository.delete<TEntity>(entityId);\n });\n}\n"],"names":["Effect","EntityRepositoryTag","EntityIdTag","deleteUCFactory","gen","entityRepository","entityId","delete"],"mappings":"AACA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,mBAAmB,QAAQ,wCAAwC;AAC5E,SAASC,WAAW,QAAQ,+CAA+C;AAE3E;;;;;;CAMC,GACD,OAAO,SAASC;IACd,OAAOH,OAAOI,GAAG,CAAC;QAChB,MAAMC,mBAAmB,OAAOJ;QAChC,MAAMK,WAAW,OAAOJ;QAExB,OAAOG,iBAAiBE,MAAM,CAAUD;IAC1C;AACF"}
1
+ {"version":3,"sources":["../../../src/use-case/delete/delete.uc.ts"],"sourcesContent":["import { Entity } from '@entifix/core';\nimport { Effect } from 'effect';\n\nimport {\n EntityRepositoryTag,\n type EntityWriteOptions,\n} from '../../repository/entity.repository.js';\nimport { EntityIdTag } from '../../repository/entity-mixins.repository.js';\n\n/**\n * Deletes an entity by id.\n *\n * The repository contract also accepts a whole entity, but deleting by id is\n * the only shape a caller ever has at the point of deletion (a table row, a\n * route param), so that is what this exposes.\n */\nexport function deleteUCFactory<TEntity extends Entity>(\n options?: EntityWriteOptions,\n) {\n return Effect.gen(function* () {\n const entityRepository = yield* EntityRepositoryTag;\n const entityId = yield* EntityIdTag;\n\n yield* entityRepository.delete<TEntity>(entityId, options);\n });\n}\n"],"names":["Effect","EntityRepositoryTag","EntityIdTag","deleteUCFactory","options","gen","entityRepository","entityId","delete"],"mappings":"AACA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SACEC,mBAAmB,QAEd,wCAAwC;AAC/C,SAASC,WAAW,QAAQ,+CAA+C;AAE3E;;;;;;CAMC,GACD,OAAO,SAASC,gBACdC,OAA4B;IAE5B,OAAOJ,OAAOK,GAAG,CAAC;QAChB,MAAMC,mBAAmB,OAAOL;QAChC,MAAMM,WAAW,OAAOL;QAExB,OAAOI,iBAAiBE,MAAM,CAAUD,UAAUH;IACpD;AACF"}
@@ -1,6 +1,6 @@
1
1
  import { Entity } from '@entifix/core';
2
2
  import { Effect } from 'effect';
3
- import { EntityRepositoryTag } from '../../repository/entity.repository.js';
3
+ import { EntityRepositoryTag, type EntityWriteOptions } from '../../repository/entity.repository.js';
4
4
  import { EntityTag } from '../../repository/entity-mixins.repository.js';
5
5
  /**
6
6
  * Persists an entity and returns whatever the repository considers the stored
@@ -12,5 +12,5 @@ import { EntityTag } from '../../repository/entity-mixins.repository.js';
12
12
  * taking them as arguments, so the same use-case saves over REST on the web and
13
13
  * over Mongo on a backend.
14
14
  */
15
- export declare function saveUCFactory<TEntity extends Entity>(): Effect.Effect<TEntity, [Effect.Effect<import("../../index.js").EntityRepository, never, EntityRepositoryTag> | Effect.Effect<Entity, never, EntityTag> | Effect.Effect<TEntity, import("../../index.js").RepositoryFailure, never>] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never, [Effect.Effect<import("../../index.js").EntityRepository, never, EntityRepositoryTag> | Effect.Effect<Entity, never, EntityTag> | Effect.Effect<TEntity, import("../../index.js").RepositoryFailure, never>] extends [Effect.Effect<infer _A_1, infer _E, infer R>] ? R : never>;
15
+ export declare function saveUCFactory<TEntity extends Entity>(options?: EntityWriteOptions): Effect.Effect<TEntity, [Effect.Effect<import("../../index.js").EntityRepository, never, EntityRepositoryTag> | Effect.Effect<Entity, never, EntityTag> | Effect.Effect<TEntity, import("../../index.js").RepositoryFailure, never>] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never, [Effect.Effect<import("../../index.js").EntityRepository, never, EntityRepositoryTag> | Effect.Effect<Entity, never, EntityTag> | Effect.Effect<TEntity, import("../../index.js").RepositoryFailure, never>] extends [Effect.Effect<infer _A_1, infer _E, infer R>] ? R : never>;
16
16
  //# sourceMappingURL=save.uc.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"save.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/save/save.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,8CAA8C,CAAC;AAEzE;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,MAAM,4jBAWnD"}
1
+ {"version":3,"file":"save.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/save/save.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EACL,mBAAmB,EACnB,KAAK,kBAAkB,EACxB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,8CAA8C,CAAC;AAEzE;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,MAAM,EAClD,OAAO,CAAC,EAAE,kBAAkB,0jBAe7B"}
@@ -10,13 +10,13 @@ import { EntityTag } from '../../repository/entity-mixins.repository.js';
10
10
  * Like {@link loadUCFactory}, this yields its inputs from context rather than
11
11
  * taking them as arguments, so the same use-case saves over REST on the web and
12
12
  * over Mongo on a backend.
13
- */ export function saveUCFactory() {
13
+ */ export function saveUCFactory(options) {
14
14
  return Effect.gen(function*() {
15
15
  const entityRepository = yield* EntityRepositoryTag;
16
16
  const entity = yield* EntityTag;
17
17
  // EntityTag is not generic, so it carries the base `Entity`; the caller
18
18
  // states the concrete type through the factory's parameter.
19
- const result = yield* entityRepository.save(entity);
19
+ const result = yield* entityRepository.save(entity, options);
20
20
  return result;
21
21
  });
22
22
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/use-case/save/save.uc.ts"],"sourcesContent":["import { Entity } from '@entifix/core';\nimport { Effect } from 'effect';\n\nimport { EntityRepositoryTag } from '../../repository/entity.repository.js';\nimport { EntityTag } from '../../repository/entity-mixins.repository.js';\n\n/**\n * Persists an entity and returns whatever the repository considers the stored\n * truth — which is not necessarily the input: a create round-trips through the\n * adapter's id generation, so the returned entity is the one callers should\n * render.\n *\n * Like {@link loadUCFactory}, this yields its inputs from context rather than\n * taking them as arguments, so the same use-case saves over REST on the web and\n * over Mongo on a backend.\n */\nexport function saveUCFactory<TEntity extends Entity>() {\n return Effect.gen(function* () {\n const entityRepository = yield* EntityRepositoryTag;\n const entity = yield* EntityTag;\n\n // EntityTag is not generic, so it carries the base `Entity`; the caller\n // states the concrete type through the factory's parameter.\n const result = yield* entityRepository.save<TEntity>(entity as TEntity);\n\n return result;\n });\n}\n"],"names":["Effect","EntityRepositoryTag","EntityTag","saveUCFactory","gen","entityRepository","entity","result","save"],"mappings":"AACA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,mBAAmB,QAAQ,wCAAwC;AAC5E,SAASC,SAAS,QAAQ,+CAA+C;AAEzE;;;;;;;;;CASC,GACD,OAAO,SAASC;IACd,OAAOH,OAAOI,GAAG,CAAC;QAChB,MAAMC,mBAAmB,OAAOJ;QAChC,MAAMK,SAAS,OAAOJ;QAEtB,wEAAwE;QACxE,4DAA4D;QAC5D,MAAMK,SAAS,OAAOF,iBAAiBG,IAAI,CAAUF;QAErD,OAAOC;IACT;AACF"}
1
+ {"version":3,"sources":["../../../src/use-case/save/save.uc.ts"],"sourcesContent":["import { Entity } from '@entifix/core';\nimport { Effect } from 'effect';\n\nimport {\n EntityRepositoryTag,\n type EntityWriteOptions,\n} from '../../repository/entity.repository.js';\nimport { EntityTag } from '../../repository/entity-mixins.repository.js';\n\n/**\n * Persists an entity and returns whatever the repository considers the stored\n * truth — which is not necessarily the input: a create round-trips through the\n * adapter's id generation, so the returned entity is the one callers should\n * render.\n *\n * Like {@link loadUCFactory}, this yields its inputs from context rather than\n * taking them as arguments, so the same use-case saves over REST on the web and\n * over Mongo on a backend.\n */\nexport function saveUCFactory<TEntity extends Entity>(\n options?: EntityWriteOptions,\n) {\n return Effect.gen(function* () {\n const entityRepository = yield* EntityRepositoryTag;\n const entity = yield* EntityTag;\n\n // EntityTag is not generic, so it carries the base `Entity`; the caller\n // states the concrete type through the factory's parameter.\n const result = yield* entityRepository.save<TEntity>(\n entity as TEntity,\n options,\n );\n\n return result;\n });\n}\n"],"names":["Effect","EntityRepositoryTag","EntityTag","saveUCFactory","options","gen","entityRepository","entity","result","save"],"mappings":"AACA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SACEC,mBAAmB,QAEd,wCAAwC;AAC/C,SAASC,SAAS,QAAQ,+CAA+C;AAEzE;;;;;;;;;CASC,GACD,OAAO,SAASC,cACdC,OAA4B;IAE5B,OAAOJ,OAAOK,GAAG,CAAC;QAChB,MAAMC,mBAAmB,OAAOL;QAChC,MAAMM,SAAS,OAAOL;QAEtB,wEAAwE;QACxE,4DAA4D;QAC5D,MAAMM,SAAS,OAAOF,iBAAiBG,IAAI,CACzCF,QACAH;QAGF,OAAOI;IACT;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entifix/business",
3
- "version": "0.23.11",
3
+ "version": "0.23.12",
4
4
  "description": "The ports every adapter implements — repository, session, token, health — and the generic get, load, save and delete use-cases.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -66,7 +66,7 @@
66
66
  },
67
67
  "dependencies": {
68
68
  "@swc/helpers": "0.5.23",
69
- "@entifix/core": "0.23.11"
69
+ "@entifix/core": "0.23.12"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "effect": "^4.0.7"