@entifix/rest 0.23.27 → 0.24.0
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/dist/adapters/entity-use-case/make-entity-rest-use-case-runner.d.ts +8 -0
- package/dist/adapters/entity-use-case/make-entity-rest-use-case-runner.d.ts.map +1 -1
- package/dist/adapters/entity-use-case/make-entity-rest-use-case-runner.js +19 -6
- package/dist/adapters/entity-use-case/make-entity-rest-use-case-runner.js.map +1 -1
- package/package.json +4 -4
|
@@ -10,6 +10,14 @@ import type { BuildEntityRestOptions } from '../entity-rest/types.js';
|
|
|
10
10
|
* body, so a screen shows the coded message rather than a generic error. A
|
|
11
11
|
* verb that starts a flow answers `202 flowAccepted` and runs as pending; any
|
|
12
12
|
* other success is settled with the `data` of what the service answered.
|
|
13
|
+
*
|
|
14
|
+
* ⚠️ **Every call carries its own `Idempotency-Key`.** A verb's route may be
|
|
15
|
+
* remembered at the edge (`idempotent: 'edge'`), and the shell refuses such a
|
|
16
|
+
* request without a key (`idempotencyKeyMissing`) — so a runner that sent none
|
|
17
|
+
* could reach no such verb at all, while a hermetic suite that stubs the
|
|
18
|
+
* service never noticed. The key is minted once per call, so a transport retry
|
|
19
|
+
* inside it is the same request; a second click is a second decision and gets
|
|
20
|
+
* a key of its own. A route that is not idempotent ignores the header.
|
|
13
21
|
*/
|
|
14
22
|
export declare const makeEntityRestUseCaseRunner: <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, { uriConfig, configuration }: BuildEntityRestOptions) => EntityUseCaseRunner;
|
|
15
23
|
//# sourceMappingURL=make-entity-rest-use-case-runner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-entity-rest-use-case-runner.d.ts","sourceRoot":"","sources":["../../../src/adapters/entity-use-case/make-entity-rest-use-case-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,
|
|
1
|
+
{"version":3,"file":"make-entity-rest-use-case-runner.d.ts","sourceRoot":"","sources":["../../../src/adapters/entity-use-case/make-entity-rest-use-case-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EAMzB,MAAM,eAAe,CAAC;AAMvB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,2BAA2B,GAAI,OAAO,SAAS,MAAM,EAChE,mBAAmB,iBAAiB,CAAC,OAAO,CAAC,EAC7C,8BAA8B,sBAAsB,KACnD,mBA4DF,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
-
import { extractMetaEntity, ProtocolFailure, toWireSelection } from '@entifix/core';
|
|
2
|
+
import { extractMetaEntity, formatIdempotencyKey, IDEMPOTENCY_KEY_HEADER, ProtocolFailure, toWireSelection } from '@entifix/core';
|
|
3
3
|
import { Effect } from 'effect';
|
|
4
4
|
import { performHttpRequestThroughFetch } from '../../clients/fetch/index.js';
|
|
5
5
|
import { buildEntityRestAdapterMixins as adapterMixins } from '../entity-rest/build-entity-rest-adapter-mixins/index.js';
|
|
@@ -14,6 +14,14 @@ import { readWriteResponse } from '../entity-rest/read-write-response.js';
|
|
|
14
14
|
* body, so a screen shows the coded message rather than a generic error. A
|
|
15
15
|
* verb that starts a flow answers `202 flowAccepted` and runs as pending; any
|
|
16
16
|
* other success is settled with the `data` of what the service answered.
|
|
17
|
+
*
|
|
18
|
+
* ⚠️ **Every call carries its own `Idempotency-Key`.** A verb's route may be
|
|
19
|
+
* remembered at the edge (`idempotent: 'edge'`), and the shell refuses such a
|
|
20
|
+
* request without a key (`idempotencyKeyMissing`) — so a runner that sent none
|
|
21
|
+
* could reach no such verb at all, while a hermetic suite that stubs the
|
|
22
|
+
* service never noticed. The key is minted once per call, so a transport retry
|
|
23
|
+
* inside it is the same request; a second click is a second decision and gets
|
|
24
|
+
* a key of its own. A route that is not idempotent ignores the header.
|
|
17
25
|
*/ export const makeEntityRestUseCaseRunner = (entityConstructor, { uriConfig, configuration })=>{
|
|
18
26
|
var _metaEntity_key;
|
|
19
27
|
const metaEntity = extractMetaEntity(entityConstructor);
|
|
@@ -21,16 +29,21 @@ import { readWriteResponse } from '../entity-rest/read-write-response.js';
|
|
|
21
29
|
const baseUrl = (id)=>adapterMixins.buildEntityBaseUrl(configuration, {
|
|
22
30
|
uriConfig
|
|
23
31
|
}, name, id);
|
|
32
|
+
const keyed = ()=>({
|
|
33
|
+
[IDEMPOTENCY_KEY_HEADER]: formatIdempotencyKey(globalThis.crypto.randomUUID())
|
|
34
|
+
});
|
|
24
35
|
return {
|
|
25
36
|
run: (useCase, id, payload)=>Effect.gen(function*() {
|
|
26
37
|
const url = yield* baseUrl(useCase.binding === 'entity' && id != null ? String(id) : undefined);
|
|
27
38
|
const response = yield* performHttpRequestThroughFetch(_extends({
|
|
28
39
|
method: 'POST',
|
|
29
40
|
url: `${url}/${useCase.key}`
|
|
30
|
-
}, payload === undefined ? {
|
|
31
|
-
headers:
|
|
41
|
+
}, payload === undefined ? {
|
|
42
|
+
headers: keyed()
|
|
43
|
+
} : {
|
|
44
|
+
headers: _extends({}, keyed(), {
|
|
32
45
|
'Content-Type': 'application/json'
|
|
33
|
-
},
|
|
46
|
+
}),
|
|
34
47
|
body: payload
|
|
35
48
|
}));
|
|
36
49
|
return yield* readWriteResponse(response, ()=>{
|
|
@@ -46,9 +59,9 @@ import { readWriteResponse } from '../entity-rest/read-write-response.js';
|
|
|
46
59
|
const response = yield* performHttpRequestThroughFetch({
|
|
47
60
|
method: 'POST',
|
|
48
61
|
url: `${url}/${useCase.key}`,
|
|
49
|
-
headers: {
|
|
62
|
+
headers: _extends({}, keyed(), {
|
|
50
63
|
'Content-Type': 'application/json'
|
|
51
|
-
},
|
|
64
|
+
}),
|
|
52
65
|
body: {
|
|
53
66
|
selection: toWireSelection(selection)
|
|
54
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/adapters/entity-use-case/make-entity-rest-use-case-runner.ts"],"sourcesContent":["import {\n type BulkOutcome,\n type Entity,\n type EntityConstructor,\n type EntityUseCaseRunner,\n extractMetaEntity,\n ProtocolFailure,\n toWireSelection,\n} from '@entifix/core';\nimport { Effect } from 'effect';\n\nimport { performHttpRequestThroughFetch } from '../../clients/fetch/index.js';\nimport { buildEntityRestAdapterMixins as adapterMixins } from '../entity-rest/build-entity-rest-adapter-mixins/index.js';\nimport { readWriteResponse } from '../entity-rest/read-write-response.js';\nimport type { BuildEntityRestOptions } from '../entity-rest/types.js';\n\n/**\n * Runs an entity's verbs against the service that serves them, at the path the\n * shell derives from each verb's key and binding — under the same base URL the\n * entity's other adapters use, so a same-origin proxy is followed the same way\n * ([ADR 0020](../../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)).\n *\n * A refusal arrives as the failure the service sent, decoded from its problem\n * body, so a screen shows the coded message rather than a generic error. A\n * verb that starts a flow answers `202 flowAccepted` and runs as pending; any\n * other success is settled with the `data` of what the service answered.\n */\nexport const makeEntityRestUseCaseRunner = <TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n { uriConfig, configuration }: BuildEntityRestOptions,\n): EntityUseCaseRunner => {\n const metaEntity = extractMetaEntity(entityConstructor);\n const name = metaEntity.key ?? metaEntity.name;\n const baseUrl = (id?: string) =>\n adapterMixins.buildEntityBaseUrl(configuration, { uriConfig }, name, id);\n\n return {\n run: (useCase, id, payload) =>\n Effect.gen(function* () {\n const url = yield* baseUrl(\n useCase.binding === 'entity' && id != null ? String(id) : undefined,\n );\n const response = yield* performHttpRequestThroughFetch<{\n readonly data?: unknown;\n }>({\n method: 'POST',\n url: `${url}/${useCase.key}`,\n // A verb's input travels as its JSON body; a verb that takes none\n // is posted empty, as it always was.\n ...(payload === undefined\n ? {}\n : {\n headers: { 'Content-Type': 'application/json' },\n body: payload,\n }),\n });\n return yield* readWriteResponse(response, () =>\n Effect.succeed(response.body?.data),\n );\n }),\n bulk: (useCase, selection) =>\n Effect.gen(function* () {\n const url = yield* baseUrl();\n // The wire form, never the selection itself: a `Set` serializes to\n // `{}`, so a selection sent raw would lose its ids.\n const response = yield* performHttpRequestThroughFetch<{\n readonly data?: unknown;\n }>({\n method: 'POST',\n url: `${url}/${useCase.key}`,\n headers: { 'Content-Type': 'application/json' },\n body: { selection: toWireSelection(selection) },\n });\n // A bulk answer is a `bulkOutcome` envelope, one outcome per record in\n // its `data`; anything else is a peer speaking something else.\n const outcomes = response.body?.data;\n if (!Array.isArray(outcomes)) {\n return yield* new ProtocolFailure({\n reason:\n 'a bulk answer carries its outcomes in a bulkOutcome envelope',\n });\n }\n return outcomes as readonly BulkOutcome[];\n }),\n };\n};\n"],"names":["extractMetaEntity","ProtocolFailure","toWireSelection","Effect","performHttpRequestThroughFetch","buildEntityRestAdapterMixins","adapterMixins","readWriteResponse","makeEntityRestUseCaseRunner","entityConstructor","uriConfig","configuration","metaEntity","name","key","baseUrl","id","buildEntityBaseUrl","run","useCase","payload","gen","url","binding","String","undefined","response","method","headers","body","succeed","data","bulk","selection","outcomes","Array","isArray","reason"],"mappings":";AAAA,SAKEA,iBAAiB,EACjBC,eAAe,EACfC,eAAe,QACV,gBAAgB;AACvB,SAASC,MAAM,QAAQ,SAAS;AAEhC,SAASC,8BAA8B,QAAQ,+BAA+B;AAC9E,SAASC,gCAAgCC,aAAa,QAAQ,2DAA2D;AACzH,SAASC,iBAAiB,QAAQ,wCAAwC;AAG1E
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/entity-use-case/make-entity-rest-use-case-runner.ts"],"sourcesContent":["import {\n type BulkOutcome,\n type Entity,\n type EntityConstructor,\n type EntityUseCaseRunner,\n extractMetaEntity,\n formatIdempotencyKey,\n IDEMPOTENCY_KEY_HEADER,\n ProtocolFailure,\n toWireSelection,\n} from '@entifix/core';\nimport { Effect } from 'effect';\n\nimport { performHttpRequestThroughFetch } from '../../clients/fetch/index.js';\nimport { buildEntityRestAdapterMixins as adapterMixins } from '../entity-rest/build-entity-rest-adapter-mixins/index.js';\nimport { readWriteResponse } from '../entity-rest/read-write-response.js';\nimport type { BuildEntityRestOptions } from '../entity-rest/types.js';\n\n/**\n * Runs an entity's verbs against the service that serves them, at the path the\n * shell derives from each verb's key and binding — under the same base URL the\n * entity's other adapters use, so a same-origin proxy is followed the same way\n * ([ADR 0020](../../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)).\n *\n * A refusal arrives as the failure the service sent, decoded from its problem\n * body, so a screen shows the coded message rather than a generic error. A\n * verb that starts a flow answers `202 flowAccepted` and runs as pending; any\n * other success is settled with the `data` of what the service answered.\n *\n * ⚠️ **Every call carries its own `Idempotency-Key`.** A verb's route may be\n * remembered at the edge (`idempotent: 'edge'`), and the shell refuses such a\n * request without a key (`idempotencyKeyMissing`) — so a runner that sent none\n * could reach no such verb at all, while a hermetic suite that stubs the\n * service never noticed. The key is minted once per call, so a transport retry\n * inside it is the same request; a second click is a second decision and gets\n * a key of its own. A route that is not idempotent ignores the header.\n */\nexport const makeEntityRestUseCaseRunner = <TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n { uriConfig, configuration }: BuildEntityRestOptions,\n): EntityUseCaseRunner => {\n const metaEntity = extractMetaEntity(entityConstructor);\n const name = metaEntity.key ?? metaEntity.name;\n const baseUrl = (id?: string) =>\n adapterMixins.buildEntityBaseUrl(configuration, { uriConfig }, name, id);\n const keyed = () => ({\n [IDEMPOTENCY_KEY_HEADER]: formatIdempotencyKey(\n globalThis.crypto.randomUUID(),\n ),\n });\n\n return {\n run: (useCase, id, payload) =>\n Effect.gen(function* () {\n const url = yield* baseUrl(\n useCase.binding === 'entity' && id != null ? String(id) : undefined,\n );\n const response = yield* performHttpRequestThroughFetch<{\n readonly data?: unknown;\n }>({\n method: 'POST',\n url: `${url}/${useCase.key}`,\n // A verb's input travels as its JSON body; a verb that takes none\n // is posted empty, as it always was.\n ...(payload === undefined\n ? { headers: keyed() }\n : {\n headers: { ...keyed(), 'Content-Type': 'application/json' },\n body: payload,\n }),\n });\n return yield* readWriteResponse(response, () =>\n Effect.succeed(response.body?.data),\n );\n }),\n bulk: (useCase, selection) =>\n Effect.gen(function* () {\n const url = yield* baseUrl();\n // The wire form, never the selection itself: a `Set` serializes to\n // `{}`, so a selection sent raw would lose its ids.\n const response = yield* performHttpRequestThroughFetch<{\n readonly data?: unknown;\n }>({\n method: 'POST',\n url: `${url}/${useCase.key}`,\n headers: { ...keyed(), 'Content-Type': 'application/json' },\n body: { selection: toWireSelection(selection) },\n });\n // A bulk answer is a `bulkOutcome` envelope, one outcome per record in\n // its `data`; anything else is a peer speaking something else.\n const outcomes = response.body?.data;\n if (!Array.isArray(outcomes)) {\n return yield* new ProtocolFailure({\n reason:\n 'a bulk answer carries its outcomes in a bulkOutcome envelope',\n });\n }\n return outcomes as readonly BulkOutcome[];\n }),\n };\n};\n"],"names":["extractMetaEntity","formatIdempotencyKey","IDEMPOTENCY_KEY_HEADER","ProtocolFailure","toWireSelection","Effect","performHttpRequestThroughFetch","buildEntityRestAdapterMixins","adapterMixins","readWriteResponse","makeEntityRestUseCaseRunner","entityConstructor","uriConfig","configuration","metaEntity","name","key","baseUrl","id","buildEntityBaseUrl","keyed","globalThis","crypto","randomUUID","run","useCase","payload","gen","url","binding","String","undefined","response","method","headers","body","succeed","data","bulk","selection","outcomes","Array","isArray","reason"],"mappings":";AAAA,SAKEA,iBAAiB,EACjBC,oBAAoB,EACpBC,sBAAsB,EACtBC,eAAe,EACfC,eAAe,QACV,gBAAgB;AACvB,SAASC,MAAM,QAAQ,SAAS;AAEhC,SAASC,8BAA8B,QAAQ,+BAA+B;AAC9E,SAASC,gCAAgCC,aAAa,QAAQ,2DAA2D;AACzH,SAASC,iBAAiB,Q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I,WAAWnC,gBAAgBmC;oBAAW;gBAChD;gBACA,uEAAuE;gBACvE,+DAA+D;gBAC/D,MAAMC,YAAWR,iBAAAA,SAASG,IAAI,qBAAbH,eAAeK,IAAI;gBACpC,IAAI,CAACI,MAAMC,OAAO,CAACF,WAAW;oBAC5B,OAAO,OAAO,IAAIrC,gBAAgB;wBAChCwC,QACE;oBACJ;gBACF;gBACA,OAAOH;YACT;IACJ;AACF,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entifix/rest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "HTTP entity adapter for the browser: get, load, save and delete against an entifix service, plus served metadata and transaction status.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@swc/helpers": "0.5.23",
|
|
59
|
-
"@entifix/core": "0.
|
|
60
|
-
"@entifix/transactions": "0.
|
|
59
|
+
"@entifix/core": "0.24.0",
|
|
60
|
+
"@entifix/transactions": "0.24.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"effect": "4.0.7",
|
|
64
|
-
"@entifix/testing-unit": "0.
|
|
64
|
+
"@entifix/testing-unit": "0.24.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"effect": "^4.0.7"
|