@entifix/business 0.1.2 → 0.1.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/README.md +3 -3
- package/dist/use-case/load/index.d.ts +2 -0
- package/dist/use-case/load/index.d.ts.map +1 -1
- package/dist/use-case/load/index.js +2 -0
- package/dist/use-case/load/index.js.map +1 -1
- package/dist/use-case/load/load-all.uc.d.ts +19 -0
- package/dist/use-case/load/load-all.uc.d.ts.map +1 -0
- package/dist/use-case/load/load-all.uc.js +35 -0
- package/dist/use-case/load/load-all.uc.js.map +1 -0
- package/dist/use-case/load/resolve-links.uc.d.ts +20 -0
- package/dist/use-case/load/resolve-links.uc.d.ts.map +1 -0
- package/dist/use-case/load/resolve-links.uc.js +23 -0
- package/dist/use-case/load/resolve-links.uc.js.map +1 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -12,9 +12,9 @@ pnpm add @entifix/business effect
|
|
|
12
12
|
|
|
13
13
|
## Entry points
|
|
14
14
|
|
|
15
|
-
| Import | What it holds
|
|
16
|
-
| ------------------- |
|
|
17
|
-
| `@entifix/business` | Port tags, `getUCFactory` / `loadUCFactory` / `saveUCFactory` / `deleteUCFactory`, `HealthRegistryLayer`, `makeShutdownRegistry` |
|
|
15
|
+
| Import | What it holds |
|
|
16
|
+
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
17
|
+
| `@entifix/business` | Port tags, `getUCFactory` / `loadUCFactory` / `saveUCFactory` / `deleteUCFactory`, `loadAllUCFactory` (every record a request keeps, page by page), `resolveLinksUCFactory` (chosen links of many records), `HealthRegistryLayer`, `makeShutdownRegistry` |
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/use-case/load/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/use-case/load/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/use-case/load/index.ts"],"sourcesContent":["export * from './load.uc.js';\n"],"names":[],"mappings":"AAAA,cAAc,eAAe"}
|
|
1
|
+
{"version":3,"sources":["../../../src/use-case/load/index.ts"],"sourcesContent":["export * from './load.uc.js';\nexport * from './load-all.uc.js';\nexport * from './resolve-links.uc.js';\n"],"names":[],"mappings":"AAAA,cAAc,eAAe;AAC7B,cAAc,mBAAmB;AACjC,cAAc,wBAAwB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Entity, EntityLoadRequest } from '@entifix/core';
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
import { EntityRepositoryTag } from '../../repository/entity.repository.js';
|
|
4
|
+
import { EntityLoadRequestTag } from '../../repository/entity-mixins.repository.js';
|
|
5
|
+
/** A request for every record it keeps: paging is the use case's to set. */
|
|
6
|
+
export type UnpagedRequest<TEntity extends Entity> = Omit<EntityLoadRequest<TEntity>, 'page' | 'pageSize'>;
|
|
7
|
+
/** How many records `loadAllUCFactory` asks the repository for at a time. */
|
|
8
|
+
export declare const LOAD_ALL_PAGE_SIZE = 100;
|
|
9
|
+
/**
|
|
10
|
+
* Every record the request in `EntityLoadRequestTag` keeps, filtered and
|
|
11
|
+
* sorted as it asks, read page by page until the repository's `total` is
|
|
12
|
+
* reached.
|
|
13
|
+
*
|
|
14
|
+
* The request's own `page` and `pageSize` are ignored: asking for one page
|
|
15
|
+
* as large as can be counted works against an in-memory source, but a real
|
|
16
|
+
* adapter would hand that size to its database.
|
|
17
|
+
*/
|
|
18
|
+
export declare function loadAllUCFactory<TEntity extends Entity>(pageSize?: number): Effect.Effect<TEntity[], import("@entifix/core").EntifixError, import("../../index.js").ConfigurationRepositoryTag | EntityRepositoryTag | EntityLoadRequestTag>;
|
|
19
|
+
//# sourceMappingURL=load-all.uc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-all.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/load/load-all.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AAEpF,4EAA4E;AAC5E,MAAM,MAAM,cAAc,CAAC,OAAO,SAAS,MAAM,IAAI,IAAI,CACvD,iBAAiB,CAAC,OAAO,CAAC,EAC1B,MAAM,GAAG,UAAU,CACpB,CAAC;AAEF,6EAA6E;AAC7E,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,MAAM,EACrD,QAAQ,GAAE,MAA2B,oKAuBtC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
import { EntityRepositoryTag } from '../../repository/entity.repository.js';
|
|
4
|
+
import { EntityLoadRequestTag } from '../../repository/entity-mixins.repository.js';
|
|
5
|
+
/** How many records `loadAllUCFactory` asks the repository for at a time. */ export const LOAD_ALL_PAGE_SIZE = 100;
|
|
6
|
+
/**
|
|
7
|
+
* Every record the request in `EntityLoadRequestTag` keeps, filtered and
|
|
8
|
+
* sorted as it asks, read page by page until the repository's `total` is
|
|
9
|
+
* reached.
|
|
10
|
+
*
|
|
11
|
+
* The request's own `page` and `pageSize` are ignored: asking for one page
|
|
12
|
+
* as large as can be counted works against an in-memory source, but a real
|
|
13
|
+
* adapter would hand that size to its database.
|
|
14
|
+
*/ export function loadAllUCFactory(pageSize = LOAD_ALL_PAGE_SIZE) {
|
|
15
|
+
return Effect.gen(function*() {
|
|
16
|
+
const entityRepository = yield* EntityRepositoryTag;
|
|
17
|
+
const entityLoadRequest = yield* EntityLoadRequestTag;
|
|
18
|
+
// EntityLoadRequestTag carries no generic type, as in `loadUCFactory`.
|
|
19
|
+
const request = entityLoadRequest;
|
|
20
|
+
const items = [];
|
|
21
|
+
for(let page = 1;; page += 1){
|
|
22
|
+
const result = yield* entityRepository.load(_extends({}, request, {
|
|
23
|
+
page,
|
|
24
|
+
pageSize
|
|
25
|
+
}));
|
|
26
|
+
items.push(...result.items);
|
|
27
|
+
// An empty page ends the read too, should `total` overstate it.
|
|
28
|
+
if (result.items.length === 0 || items.length >= result.total) {
|
|
29
|
+
return items;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=load-all.uc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/use-case/load/load-all.uc.ts"],"sourcesContent":["import { Entity, EntityLoadRequest } from '@entifix/core';\nimport { Effect } from 'effect';\n\nimport { EntityRepositoryTag } from '../../repository/entity.repository.js';\nimport { EntityLoadRequestTag } from '../../repository/entity-mixins.repository.js';\n\n/** A request for every record it keeps: paging is the use case's to set. */\nexport type UnpagedRequest<TEntity extends Entity> = Omit<\n EntityLoadRequest<TEntity>,\n 'page' | 'pageSize'\n>;\n\n/** How many records `loadAllUCFactory` asks the repository for at a time. */\nexport const LOAD_ALL_PAGE_SIZE = 100;\n\n/**\n * Every record the request in `EntityLoadRequestTag` keeps, filtered and\n * sorted as it asks, read page by page until the repository's `total` is\n * reached.\n *\n * The request's own `page` and `pageSize` are ignored: asking for one page\n * as large as can be counted works against an in-memory source, but a real\n * adapter would hand that size to its database.\n */\nexport function loadAllUCFactory<TEntity extends Entity>(\n pageSize: number = LOAD_ALL_PAGE_SIZE,\n) {\n return Effect.gen(function* () {\n const entityRepository = yield* EntityRepositoryTag;\n const entityLoadRequest = yield* EntityLoadRequestTag;\n\n // EntityLoadRequestTag carries no generic type, as in `loadUCFactory`.\n const request = entityLoadRequest as unknown as EntityLoadRequest<TEntity>;\n\n const items: TEntity[] = [];\n for (let page = 1; ; page += 1) {\n const result = yield* entityRepository.load<TEntity>({\n ...request,\n page,\n pageSize,\n });\n items.push(...result.items);\n // An empty page ends the read too, should `total` overstate it.\n if (result.items.length === 0 || items.length >= result.total) {\n return items;\n }\n }\n });\n}\n"],"names":["Effect","EntityRepositoryTag","EntityLoadRequestTag","LOAD_ALL_PAGE_SIZE","loadAllUCFactory","pageSize","gen","entityRepository","entityLoadRequest","request","items","page","result","load","push","length","total"],"mappings":";AACA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,mBAAmB,QAAQ,wCAAwC;AAC5E,SAASC,oBAAoB,QAAQ,+CAA+C;AAQpF,2EAA2E,GAC3E,OAAO,MAAMC,qBAAqB,IAAI;AAEtC;;;;;;;;CAQC,GACD,OAAO,SAASC,iBACdC,WAAmBF,kBAAkB;IAErC,OAAOH,OAAOM,GAAG,CAAC;QAChB,MAAMC,mBAAmB,OAAON;QAChC,MAAMO,oBAAoB,OAAON;QAEjC,uEAAuE;QACvE,MAAMO,UAAUD;QAEhB,MAAME,QAAmB,EAAE;QAC3B,IAAK,IAAIC,OAAO,IAAKA,QAAQ,EAAG;YAC9B,MAAMC,SAAS,OAAOL,iBAAiBM,IAAI,CAAU,aAChDJ;gBACHE;gBACAN;;YAEFK,MAAMI,IAAI,IAAIF,OAAOF,KAAK;YAC1B,gEAAgE;YAChE,IAAIE,OAAOF,KAAK,CAACK,MAAM,KAAK,KAAKL,MAAMK,MAAM,IAAIH,OAAOI,KAAK,EAAE;gBAC7D,OAAON;YACT;QACF;IACF;AACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type EntifixError, type Entity } from '@entifix/core';
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
import { EntityLinkResolverTag } from '../../repository/entity-link-resolver.repository.js';
|
|
4
|
+
/** The members of an entity that link to other records. */
|
|
5
|
+
export type LinkMember<TEntity> = {
|
|
6
|
+
[TKey in keyof TEntity & string]: TEntity[TKey] extends {
|
|
7
|
+
readonly entityConstructor: unknown;
|
|
8
|
+
readonly isLoaded: boolean;
|
|
9
|
+
} ? TKey : never;
|
|
10
|
+
}[keyof TEntity & string];
|
|
11
|
+
/**
|
|
12
|
+
* Resolves `members` of every record, in place, through the
|
|
13
|
+
* `EntityLinkResolverTag` in context, and hands the records back.
|
|
14
|
+
*
|
|
15
|
+
* A record read with its linked records (a post with its tags) then reads
|
|
16
|
+
* each through `targetOf`/`targetsOf`, with no `id → record` map built by
|
|
17
|
+
* hand. Every link resolves concurrently; one that fails fails the whole.
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveLinksUCFactory<TEntity extends Entity>(records: readonly TEntity[], members: readonly LinkMember<TEntity>[]): Effect.Effect<TEntity[], EntifixError, EntityLinkResolverTag>;
|
|
20
|
+
//# sourceMappingURL=resolve-links.uc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-links.uc.d.ts","sourceRoot":"","sources":["../../../src/use-case/load/resolve-links.uc.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,MAAM,EAEZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qDAAqD,CAAC;AAE5F,2DAA2D;AAC3D,MAAM,MAAM,UAAU,CAAC,OAAO,IAAI;KAC/B,IAAI,IAAI,MAAM,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS;QACtD,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;QACpC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;KAC5B,GACG,IAAI,GACJ,KAAK;CACV,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC;AAM1B;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,MAAM,EAC1D,OAAO,EAAE,SAAS,OAAO,EAAE,EAC3B,OAAO,EAAE,SAAS,UAAU,CAAC,OAAO,CAAC,EAAE,iEAexC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { EntityLinkResolverTag } from '../../repository/entity-link-resolver.repository.js';
|
|
3
|
+
/**
|
|
4
|
+
* Resolves `members` of every record, in place, through the
|
|
5
|
+
* `EntityLinkResolverTag` in context, and hands the records back.
|
|
6
|
+
*
|
|
7
|
+
* A record read with its linked records (a post with its tags) then reads
|
|
8
|
+
* each through `targetOf`/`targetsOf`, with no `id → record` map built by
|
|
9
|
+
* hand. Every link resolves concurrently; one that fails fails the whole.
|
|
10
|
+
*/ export function resolveLinksUCFactory(records, members) {
|
|
11
|
+
return Effect.gen(function*() {
|
|
12
|
+
const resolver = yield* EntityLinkResolverTag;
|
|
13
|
+
yield* Effect.forEach(records.flatMap((record)=>members.map((member)=>record[member].resolve(resolver))), (resolved)=>resolved, {
|
|
14
|
+
concurrency: 'unbounded',
|
|
15
|
+
discard: true
|
|
16
|
+
});
|
|
17
|
+
return [
|
|
18
|
+
...records
|
|
19
|
+
];
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=resolve-links.uc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/use-case/load/resolve-links.uc.ts"],"sourcesContent":["import {\n type EntifixError,\n type Entity,\n type EntityLinkResolver,\n} from '@entifix/core';\nimport { Effect } from 'effect';\n\nimport { EntityLinkResolverTag } from '../../repository/entity-link-resolver.repository.js';\n\n/** The members of an entity that link to other records. */\nexport type LinkMember<TEntity> = {\n [TKey in keyof TEntity & string]: TEntity[TKey] extends {\n readonly entityConstructor: unknown;\n readonly isLoaded: boolean;\n }\n ? TKey\n : never;\n}[keyof TEntity & string];\n\ntype ResolvableLink = {\n resolve(resolver: EntityLinkResolver): Effect.Effect<unknown, EntifixError>;\n};\n\n/**\n * Resolves `members` of every record, in place, through the\n * `EntityLinkResolverTag` in context, and hands the records back.\n *\n * A record read with its linked records (a post with its tags) then reads\n * each through `targetOf`/`targetsOf`, with no `id → record` map built by\n * hand. Every link resolves concurrently; one that fails fails the whole.\n */\nexport function resolveLinksUCFactory<TEntity extends Entity>(\n records: readonly TEntity[],\n members: readonly LinkMember<TEntity>[],\n) {\n return Effect.gen(function* () {\n const resolver = yield* EntityLinkResolverTag;\n yield* Effect.forEach(\n records.flatMap(record =>\n members.map(member =>\n (record[member] as ResolvableLink).resolve(resolver),\n ),\n ),\n resolved => resolved,\n { concurrency: 'unbounded', discard: true },\n );\n return [...records];\n });\n}\n"],"names":["Effect","EntityLinkResolverTag","resolveLinksUCFactory","records","members","gen","resolver","forEach","flatMap","record","map","member","resolve","resolved","concurrency","discard"],"mappings":"AAKA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,qBAAqB,QAAQ,sDAAsD;AAgB5F;;;;;;;CAOC,GACD,OAAO,SAASC,sBACdC,OAA2B,EAC3BC,OAAuC;IAEvC,OAAOJ,OAAOK,GAAG,CAAC;QAChB,MAAMC,WAAW,OAAOL;QACxB,OAAOD,OAAOO,OAAO,CACnBJ,QAAQK,OAAO,CAACC,CAAAA,SACdL,QAAQM,GAAG,CAACC,CAAAA,SACV,AAACF,MAAM,CAACE,OAAO,CAAoBC,OAAO,CAACN,aAG/CO,CAAAA,WAAYA,UACZ;YAAEC,aAAa;YAAaC,SAAS;QAAK;QAE5C,OAAO;eAAIZ;SAAQ;IACrB;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entifix/business",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
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": {
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@swc/helpers": "0.5.23",
|
|
55
|
-
"@entifix/core": "0.1.
|
|
55
|
+
"@entifix/core": "0.1.4"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"effect": ">=3.22 <4"
|
|
58
|
+
"effect": ">=3.22.2 <4"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"effect": "3.22.
|
|
61
|
+
"effect": "3.22.2"
|
|
62
62
|
}
|
|
63
63
|
}
|