@entifix/next-shell 0.13.0 → 0.15.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/lib/config/service-proxy-route.d.ts +4 -7
- package/dist/lib/config/service-proxy-route.d.ts.map +1 -1
- package/dist/lib/config/service-proxy-route.js +1 -25
- package/dist/lib/config/service-proxy-route.js.map +1 -1
- package/dist/lib/crud/entity-crud-form.d.ts +5 -3
- package/dist/lib/crud/entity-crud-form.d.ts.map +1 -1
- package/dist/lib/crud/entity-crud-form.js +2 -1
- package/dist/lib/crud/entity-crud-form.js.map +1 -1
- package/dist/lib/crud/index.d.ts +0 -1
- package/dist/lib/crud/index.d.ts.map +1 -1
- package/dist/lib/crud/index.js +0 -1
- package/dist/lib/crud/index.js.map +1 -1
- package/dist/lib/crud/make-entity-crud.d.ts +7 -12
- package/dist/lib/crud/make-entity-crud.d.ts.map +1 -1
- package/dist/lib/crud/make-entity-crud.js +154 -114
- package/dist/lib/crud/make-entity-crud.js.map +1 -1
- package/dist/lib/crud/make-entity-crud.types.d.ts +13 -1
- package/dist/lib/crud/make-entity-crud.types.d.ts.map +1 -1
- package/dist/lib/crud/make-entity-crud.types.js.map +1 -1
- package/dist/lib/session/bearer.d.ts +1 -1
- package/dist/lib/session/bearer.js +1 -1
- package/dist/lib/session/bearer.js.map +1 -1
- package/dist/lib/workspace/index.d.ts +1 -2
- package/dist/lib/workspace/index.d.ts.map +1 -1
- package/dist/lib/workspace/index.js +1 -2
- package/dist/lib/workspace/index.js.map +1 -1
- package/dist/lib/workspace/pending-flows.d.ts +48 -0
- package/dist/lib/workspace/pending-flows.d.ts.map +1 -0
- package/dist/lib/workspace/pending-flows.js +60 -0
- package/dist/lib/workspace/pending-flows.js.map +1 -0
- package/package.json +11 -11
- package/dist/lib/crud/hand-off-write.d.ts +0 -35
- package/dist/lib/crud/hand-off-write.d.ts.map +0 -1
- package/dist/lib/crud/hand-off-write.js +0 -27
- package/dist/lib/crud/hand-off-write.js.map +0 -1
- package/dist/lib/crud/pending-notice.d.ts +0 -31
- package/dist/lib/crud/pending-notice.d.ts.map +0 -1
- package/dist/lib/crud/pending-notice.js +0 -72
- package/dist/lib/crud/pending-notice.js.map +0 -1
- package/dist/lib/workspace/pending-state.d.ts +0 -85
- package/dist/lib/workspace/pending-state.d.ts.map +0 -1
- package/dist/lib/workspace/pending-state.js +0 -155
- package/dist/lib/workspace/pending-state.js.map +0 -1
- package/dist/lib/workspace/pending-transactions.d.ts +0 -44
- package/dist/lib/workspace/pending-transactions.d.ts.map +0 -1
- package/dist/lib/workspace/pending-transactions.js +0 -114
- package/dist/lib/workspace/pending-transactions.js.map +0 -1
|
@@ -12,13 +12,10 @@ export interface ServiceProxyRouteOptions {
|
|
|
12
12
|
* ⚠️ **Needed when the proxy's namespace *is* the upstream's route name.**
|
|
13
13
|
* `/api/stock/stock-item` forwards to `/api/stock-item` because `stock` names
|
|
14
14
|
* the service and `stock-item` names the entity — two different words. But
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* strips half the address
|
|
18
|
-
*
|
|
19
|
-
* Caught on the live lab rather than by any check, and the symptom is exactly
|
|
20
|
-
* the one this proxy exists to prevent — the SSE stream 404s, a pending write
|
|
21
|
-
* never settles, and every probe stays green.
|
|
15
|
+
* where the namespace and the route are the same word — `/api/realtime/flow`
|
|
16
|
+
* served by a service whose own route is `/api/realtime/flow` — stripping it
|
|
17
|
+
* strips half the address, and every probe stays green while the route
|
|
18
|
+
* 404s.
|
|
22
19
|
*/
|
|
23
20
|
readonly pathPrefix?: string;
|
|
24
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-proxy-route.d.ts","sourceRoot":"","sources":["../../../src/lib/config/service-proxy-route.ts"],"names":[],"mappings":"AAMA,KAAK,MAAM,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC;AAEtD,MAAM,WAAW,wBAAwB;IACvC,4DAA4D;IAC5D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB
|
|
1
|
+
{"version":3,"file":"service-proxy-route.d.ts","sourceRoot":"","sources":["../../../src/lib/config/service-proxy-route.ts"],"names":[],"mappings":"AAMA,KAAK,MAAM,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC;AAEtD,MAAM,WAAW,wBAAwB;IACvC,4DAA4D;IAC5D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AA2ED,eAAO,MAAM,uBAAuB,GAAI,0BAGrC,wBAAwB,eAEd,OAAO,cACJ,MAAM,KACjB,OAAO,CAAC,QAAQ,CA+DpB,CAAC"}
|
|
@@ -16,7 +16,7 @@ import { problemResponse } from './problem-response.js';
|
|
|
16
16
|
*
|
|
17
17
|
* The cookie is forwarded upstream as a bearer token. **This proxy grants
|
|
18
18
|
* nothing** — the service still verifies the token and applies its own
|
|
19
|
-
* `
|
|
19
|
+
* the endpoint's `guard`. It only carries.
|
|
20
20
|
*
|
|
21
21
|
* It also carries the **caching contract** in both directions, which it did not
|
|
22
22
|
* always: rebuilding every response as a fresh body dropped `ETag`,
|
|
@@ -62,18 +62,6 @@ import { problemResponse } from './problem-response.js';
|
|
|
62
62
|
'traceparent',
|
|
63
63
|
DEADLINE_HEADER
|
|
64
64
|
];
|
|
65
|
-
/**
|
|
66
|
-
* Whether the upstream answer must be piped rather than rebuilt.
|
|
67
|
-
*
|
|
68
|
-
* Reading a `text/event-stream` body to completion holds the request open
|
|
69
|
-
* forever and delivers nothing — no error, no timeout, and the browser's
|
|
70
|
-
* `EventSource` sits in `CONNECTING` while the service is happily emitting.
|
|
71
|
-
* It is the most likely way to build the reactive stream, see silence, and go
|
|
72
|
-
* looking in the wrong service.
|
|
73
|
-
*/ const isStreamed = (upstream)=>{
|
|
74
|
-
var _upstream_headers_get;
|
|
75
|
-
return ((_upstream_headers_get = upstream.headers.get('content-type')) == null ? void 0 : _upstream_headers_get.startsWith('text/event-stream')) === true;
|
|
76
|
-
};
|
|
77
65
|
const passThrough = (upstream)=>{
|
|
78
66
|
const headers = {};
|
|
79
67
|
for (const name of PASSED_RESPONSE_HEADERS){
|
|
@@ -127,18 +115,6 @@ export const createServiceProxyRoute = ({ baseUrl, pathPrefix })=>{
|
|
|
127
115
|
headers: passed
|
|
128
116
|
});
|
|
129
117
|
}
|
|
130
|
-
// Piped, never buffered, and never re-typed as JSON: the body is an open
|
|
131
|
-
// stream of frames, and `no-store` is correctness rather than politeness —
|
|
132
|
-
// this response is scoped to one principal.
|
|
133
|
-
if (isStreamed(upstream)) {
|
|
134
|
-
return new NextResponse(upstream.body, {
|
|
135
|
-
status: upstream.status,
|
|
136
|
-
headers: _extends({}, passed, {
|
|
137
|
-
'content-type': 'text/event-stream',
|
|
138
|
-
'cache-control': 'no-store'
|
|
139
|
-
})
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
118
|
// 204s and empty bodies must not be given a body. The upstream's content
|
|
143
119
|
// type is kept, never re-typed: a problem body re-typed as plain JSON is
|
|
144
120
|
// one the browser can no longer recognise as a failure it can decode.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/config/service-proxy-route.ts"],"sourcesContent":["import { DEADLINE_HEADER, UpstreamUnavailable } from '@entifix/core';\nimport { NextResponse } from 'next/server';\n\nimport { bearerHeader, sessionToken } from '../session/bearer.js';\nimport { problemResponse } from './problem-response.js';\n\ntype Params = { params: Promise<{ path: string[] }> };\n\nexport interface ServiceProxyRouteOptions {\n /** Where the service listens, without the `/api` suffix. */\n readonly baseUrl: string;\n /**\n * A segment to put back in front of the forwarded path.\n *\n * ⚠️ **Needed when the proxy's namespace *is* the upstream's route name.**\n * `/api/stock/stock-item` forwards to `/api/stock-item` because `stock` names\n * the service and `stock-item` names the entity — two different words. But\n * `/api/transaction/events` forwards to `/api/events`, which exists nowhere:\n * there the namespace and the route are the same word, and stripping it\n * strips half the address.\n *\n * Caught on the live lab rather than by any check, and the symptom is exactly\n * the one this proxy exists to prevent — the SSE stream 404s, a pending write\n * never settles, and every probe stays green.\n */\n readonly pathPrefix?: string;\n}\n\n/**\n * Builds a same-origin proxy for one backend service, mounted as a catch-all\n * route handler — e.g. `app/api/admin/[...path]/route.ts`.\n *\n * The browser can never call `:310N` directly: `entifix_at` is httpOnly and\n * same-origin, so a cross-origin request carries no cookie and a guarded route\n * answers `401`. Host-scoping the cookie does not help — that governs which host\n * *stores* it, not which cross-origin requests send it. Routing through the app's\n * own origin makes the cookie automatic and needs no CORS, which is the same\n * reason the credential routes are shaped this way.\n *\n * The cookie is forwarded upstream as a bearer token. **This proxy grants\n * nothing** — the service still verifies the token and applies its own\n * `requirePermission`. It only carries.\n *\n * It also carries the **caching contract** in both directions, which it did not\n * always: rebuilding every response as a fresh body dropped `ETag`,\n * `Cache-Control` and `Vary`, and forwarded no `If-None-Match`. The effect was\n * invisible and entirely wasteful — `GET /api/<entity>/$metadata` computes and\n * hashes a permission-filtered document per request, and a validator that never\n * reaches the service means it can never answer `304`. Worse, `Vary` is a\n * *correctness* header here: the document differs per caller, and one stripped\n * of `Vary: Cookie, Authorization` may be cached and served to a different\n * principal.\n *\n * A factory, because a host mounts one of these per backend it talks to, and\n * back-office-app now talks to two: marketplace-admin-service for the catalog a\n * vendor authors, marketplace-service for the platform vocabulary it is\n * classified in.\n */\n/**\n * Response headers that must survive the rebuild.\n *\n * Deliberately a short allow-list rather than copying every header: the\n * upstream's `content-length` and `content-encoding` describe *its* body, and\n * carrying them onto a response this function reconstructs is how a proxy\n * serves a truncated payload. Beside the cache validators: `retry-after`,\n * which says when an overloaded service wants to be asked again; `location`,\n * which a `202` points its tracker at; and `traceparent`, so the browser's\n * failure toast can name the trace a service logged its side under.\n */\nconst PASSED_RESPONSE_HEADERS = [\n 'etag',\n 'cache-control',\n 'vary',\n 'retry-after',\n 'location',\n 'traceparent',\n] as const;\n\n/**\n * Request headers forwarded to the service, beside the bearer it gets from\n * the session: the validator, so `$metadata` can answer `304`; the\n * idempotency key, so a retried write is recognised; the trace, so one\n * request is one trace across the hop; and the caller's remaining budget\n * ([ADR 0014](../../../../../../docs/adr/0014-retry-once-at-the-layer-above-under-a-budget.md)).\n */\nconst FORWARDED_REQUEST_HEADERS = [\n 'if-none-match',\n 'idempotency-key',\n 'traceparent',\n DEADLINE_HEADER,\n] as const;\n\n/**\n * Whether the upstream answer must be piped rather than rebuilt.\n *\n * Reading a `text/event-stream` body to completion holds the request open\n * forever and delivers nothing — no error, no timeout, and the browser's\n * `EventSource` sits in `CONNECTING` while the service is happily emitting.\n * It is the most likely way to build the reactive stream, see silence, and go\n * looking in the wrong service.\n */\nconst isStreamed = (upstream: Response): boolean =>\n upstream.headers.get('content-type')?.startsWith('text/event-stream') ===\n true;\n\nconst passThrough = (upstream: Response): Record<string, string> => {\n const headers: Record<string, string> = {};\n for (const name of PASSED_RESPONSE_HEADERS) {\n const value = upstream.headers.get(name);\n if (value !== null) headers[name] = value;\n }\n return headers;\n};\n\nexport const createServiceProxyRoute = ({\n baseUrl,\n pathPrefix,\n}: ServiceProxyRouteOptions) => {\n const forward = async (\n request: Request,\n { params }: Params,\n ): Promise<Response> => {\n const { path } = await params;\n const search = new URL(request.url).search;\n\n const headers: Record<string, string> = {\n 'content-type': 'application/json',\n ...bearerHeader(await sessionToken()),\n };\n\n for (const name of FORWARDED_REQUEST_HEADERS) {\n const value = request.headers.get(name);\n if (value !== null) headers[name] = value;\n }\n\n const hasBody = request.method !== 'GET' && request.method !== 'DELETE';\n const body = hasBody ? await request.text() : undefined;\n // Only the connection is caught. A service that answers — with anything,\n // a `500` included — is passed through below exactly as it answered.\n const upstream = await fetch(\n `${baseUrl}/api/${[pathPrefix, ...path].filter(Boolean).join('/')}${search}`,\n { method: request.method, headers, body, cache: 'no-store' },\n ).catch(() => undefined);\n\n // `502`, never the `500` an unhandled rejection becomes: the host did\n // nothing wrong, and a `500` sends whoever reads it looking for a bug in\n // the app rather than for a process that is not running.\n if (upstream === undefined) {\n return problemResponse(\n new UpstreamUnavailable(\n pathPrefix === undefined ? {} : { upstream: pathPrefix },\n ),\n {\n status: 502,\n },\n );\n }\n\n const passed = passThrough(upstream);\n\n // A `304` carries no body by definition, and neither does a `204`. Running\n // either through a body read is not merely wasteful — a `304` reconstructed\n // with a body is no longer a `304`.\n if (upstream.status === 304) {\n return new NextResponse(null, { status: 304, headers: passed });\n }\n\n // Piped, never buffered, and never re-typed as JSON: the body is an open\n // stream of frames, and `no-store` is correctness rather than politeness —\n // this response is scoped to one principal.\n if (isStreamed(upstream)) {\n return new NextResponse(upstream.body, {\n status: upstream.status,\n headers: {\n ...passed,\n 'content-type': 'text/event-stream',\n 'cache-control': 'no-store',\n },\n });\n }\n\n // 204s and empty bodies must not be given a body. The upstream's content\n // type is kept, never re-typed: a problem body re-typed as plain JSON is\n // one the browser can no longer recognise as a failure it can decode.\n const text = await upstream.text();\n return text === ''\n ? new NextResponse(null, { status: upstream.status, headers: passed })\n : new NextResponse(text, {\n status: upstream.status,\n headers: {\n ...passed,\n 'content-type':\n upstream.headers.get('content-type') ?? 'application/json',\n },\n });\n };\n\n return forward;\n};\n"],"names":["DEADLINE_HEADER","UpstreamUnavailable","NextResponse","bearerHeader","sessionToken","problemResponse","PASSED_RESPONSE_HEADERS","FORWARDED_REQUEST_HEADERS","isStreamed","upstream","headers","get","startsWith","passThrough","name","value","createServiceProxyRoute","baseUrl","pathPrefix","forward","request","params","path","search","URL","url","hasBody","method","body","text","undefined","fetch","filter","Boolean","join","cache","catch","status","passed"],"mappings":";AAAA,SAASA,eAAe,EAAEC,mBAAmB,QAAQ,gBAAgB;AACrE,SAASC,YAAY,QAAQ,cAAc;AAE3C,SAASC,YAAY,EAAEC,YAAY,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ADLINE_HEADER, UpstreamUnavailable } from '@entifix/core';\nimport { NextResponse } from 'next/server';\n\nimport { bearerHeader, sessionToken } from '../session/bearer.js';\nimport { problemResponse } from './problem-response.js';\n\ntype Params = { params: Promise<{ path: string[] }> };\n\nexport interface ServiceProxyRouteOptions {\n /** Where the service listens, without the `/api` suffix. */\n readonly baseUrl: string;\n /**\n * A segment to put back in front of the forwarded path.\n *\n * ⚠️ **Needed when the proxy's namespace *is* the upstream's route name.**\n * `/api/stock/stock-item` forwards to `/api/stock-item` because `stock` names\n * the service and `stock-item` names the entity — two different words. But\n * where the namespace and the route are the same word — `/api/realtime/flow`\n * served by a service whose own route is `/api/realtime/flow` — stripping it\n * strips half the address, and every probe stays green while the route\n * 404s.\n */\n readonly pathPrefix?: string;\n}\n\n/**\n * Builds a same-origin proxy for one backend service, mounted as a catch-all\n * route handler — e.g. `app/api/admin/[...path]/route.ts`.\n *\n * The browser can never call `:310N` directly: `entifix_at` is httpOnly and\n * same-origin, so a cross-origin request carries no cookie and a guarded route\n * answers `401`. Host-scoping the cookie does not help — that governs which host\n * *stores* it, not which cross-origin requests send it. Routing through the app's\n * own origin makes the cookie automatic and needs no CORS, which is the same\n * reason the credential routes are shaped this way.\n *\n * The cookie is forwarded upstream as a bearer token. **This proxy grants\n * nothing** — the service still verifies the token and applies its own\n * the endpoint's `guard`. It only carries.\n *\n * It also carries the **caching contract** in both directions, which it did not\n * always: rebuilding every response as a fresh body dropped `ETag`,\n * `Cache-Control` and `Vary`, and forwarded no `If-None-Match`. The effect was\n * invisible and entirely wasteful — `GET /api/<entity>/$metadata` computes and\n * hashes a permission-filtered document per request, and a validator that never\n * reaches the service means it can never answer `304`. Worse, `Vary` is a\n * *correctness* header here: the document differs per caller, and one stripped\n * of `Vary: Cookie, Authorization` may be cached and served to a different\n * principal.\n *\n * A factory, because a host mounts one of these per backend it talks to, and\n * back-office-app now talks to two: marketplace-admin-service for the catalog a\n * vendor authors, marketplace-service for the platform vocabulary it is\n * classified in.\n */\n/**\n * Response headers that must survive the rebuild.\n *\n * Deliberately a short allow-list rather than copying every header: the\n * upstream's `content-length` and `content-encoding` describe *its* body, and\n * carrying them onto a response this function reconstructs is how a proxy\n * serves a truncated payload. Beside the cache validators: `retry-after`,\n * which says when an overloaded service wants to be asked again; `location`,\n * which a `202` points its tracker at; and `traceparent`, so the browser's\n * failure toast can name the trace a service logged its side under.\n */\nconst PASSED_RESPONSE_HEADERS = [\n 'etag',\n 'cache-control',\n 'vary',\n 'retry-after',\n 'location',\n 'traceparent',\n] as const;\n\n/**\n * Request headers forwarded to the service, beside the bearer it gets from\n * the session: the validator, so `$metadata` can answer `304`; the\n * idempotency key, so a retried write is recognised; the trace, so one\n * request is one trace across the hop; and the caller's remaining budget\n * ([ADR 0014](../../../../../../docs/adr/0014-retry-once-at-the-layer-above-under-a-budget.md)).\n */\nconst FORWARDED_REQUEST_HEADERS = [\n 'if-none-match',\n 'idempotency-key',\n 'traceparent',\n DEADLINE_HEADER,\n] as const;\n\nconst passThrough = (upstream: Response): Record<string, string> => {\n const headers: Record<string, string> = {};\n for (const name of PASSED_RESPONSE_HEADERS) {\n const value = upstream.headers.get(name);\n if (value !== null) headers[name] = value;\n }\n return headers;\n};\n\nexport const createServiceProxyRoute = ({\n baseUrl,\n pathPrefix,\n}: ServiceProxyRouteOptions) => {\n const forward = async (\n request: Request,\n { params }: Params,\n ): Promise<Response> => {\n const { path } = await params;\n const search = new URL(request.url).search;\n\n const headers: Record<string, string> = {\n 'content-type': 'application/json',\n ...bearerHeader(await sessionToken()),\n };\n\n for (const name of FORWARDED_REQUEST_HEADERS) {\n const value = request.headers.get(name);\n if (value !== null) headers[name] = value;\n }\n\n const hasBody = request.method !== 'GET' && request.method !== 'DELETE';\n const body = hasBody ? await request.text() : undefined;\n // Only the connection is caught. A service that answers — with anything,\n // a `500` included — is passed through below exactly as it answered.\n const upstream = await fetch(\n `${baseUrl}/api/${[pathPrefix, ...path].filter(Boolean).join('/')}${search}`,\n { method: request.method, headers, body, cache: 'no-store' },\n ).catch(() => undefined);\n\n // `502`, never the `500` an unhandled rejection becomes: the host did\n // nothing wrong, and a `500` sends whoever reads it looking for a bug in\n // the app rather than for a process that is not running.\n if (upstream === undefined) {\n return problemResponse(\n new UpstreamUnavailable(\n pathPrefix === undefined ? {} : { upstream: pathPrefix },\n ),\n {\n status: 502,\n },\n );\n }\n\n const passed = passThrough(upstream);\n\n // A `304` carries no body by definition, and neither does a `204`. Running\n // either through a body read is not merely wasteful — a `304` reconstructed\n // with a body is no longer a `304`.\n if (upstream.status === 304) {\n return new NextResponse(null, { status: 304, headers: passed });\n }\n\n // 204s and empty bodies must not be given a body. The upstream's content\n // type is kept, never re-typed: a problem body re-typed as plain JSON is\n // one the browser can no longer recognise as a failure it can decode.\n const text = await upstream.text();\n return text === ''\n ? new NextResponse(null, { status: upstream.status, headers: passed })\n : new NextResponse(text, {\n status: upstream.status,\n headers: {\n ...passed,\n 'content-type':\n upstream.headers.get('content-type') ?? 'application/json',\n },\n });\n };\n\n return forward;\n};\n"],"names":["DEADLINE_HEADER","UpstreamUnavailable","NextResponse","bearerHeader","sessionToken","problemResponse","PASSED_RESPONSE_HEADERS","FORWARDED_REQUEST_HEADERS","passThrough","upstream","headers","name","value","get","createServiceProxyRoute","baseUrl","pathPrefix","forward","request","params","path","search","URL","url","hasBody","method","body","text","undefined","fetch","filter","Boolean","join","cache","catch","status","passed"],"mappings":";AAAA,SAASA,eAAe,EAAEC,mBAAmB,QAAQ,gBAAgB;AACrE,SAASC,YAAY,QAAQ,cAAc;AAE3C,SAASC,YAAY,EAAEC,YAAY,QAAQ,uBAAuB;AAClE,SAASC,eAAe,QAAQ,wBAAwB;AAqBxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BC,GACD;;;;;;;;;;CAUC,GACD,MAAMC,0BAA0B;IAC9B;IACA;IACA;IACA;IACA;IACA;CACD;AAED;;;;;;CAMC,GACD,MAAMC,4BAA4B;IAChC;IACA;IACA;IACAP;CACD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B,YAAYC;QAE3B,2EAA2E;QAC3E,4EAA4E;QAC5E,oCAAoC;QACpC,IAAIA,SAAS0B,MAAM,KAAK,KAAK;YAC3B,OAAO,IAAIjC,aAAa,MAAM;gBAAEiC,QAAQ;gBAAKzB,SAAS0B;YAAO;QAC/D;QAEA,yEAAyE;QACzE,yEAAyE;QACzE,sEAAsE;QACtE,MAAMT,OAAO,MAAMlB,SAASkB,IAAI;QAChC,OAAOA,SAAS,KACZ,IAAIzB,aAAa,MAAM;YAAEiC,QAAQ1B,SAAS0B,MAAM;YAAEzB,SAAS0B;QAAO,KAClE,IAAIlC,aAAayB,MAAM;YACrBQ,QAAQ1B,SAAS0B,MAAM;YACvBzB,SAAS,aACJ0B;gBACH,cAAc,GACZ3B,wBAAAA,SAASC,OAAO,CAACG,GAAG,CAAC,2BAArBJ,wBAAwC;;QAE9C;IACN;IAEA,OAAOQ;AACT,EAAE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type EntifixFailure, type Entity, type EntityConstructor, type EntityMetadataSource } from '@entifix/core';
|
|
2
2
|
import { type RenderLink } from '@entifix/react-controls';
|
|
3
3
|
import { type EntityDraftStore } from '@entifix/react-integration';
|
|
4
4
|
import type { EntityCatalogKey, EntityCrudLinkSource } from './make-entity-crud.types.js';
|
|
@@ -11,8 +11,10 @@ export interface EntityCrudFormProps<TEntity extends Entity> {
|
|
|
11
11
|
readonly entity?: TEntity;
|
|
12
12
|
readonly isLoading?: boolean;
|
|
13
13
|
readonly isSaving?: boolean;
|
|
14
|
+
/** A write handed to a flow that has not settled: the form waits, keeping its input. */
|
|
15
|
+
readonly isPending?: boolean;
|
|
14
16
|
readonly isDeleting?: boolean;
|
|
15
|
-
readonly error?:
|
|
17
|
+
readonly error?: EntifixFailure;
|
|
16
18
|
readonly onSave: (entity: TEntity) => void;
|
|
17
19
|
/** Omitted for a create — there is nothing to delete yet. */
|
|
18
20
|
readonly onDelete?: () => void;
|
|
@@ -48,5 +50,5 @@ export interface EntityCrudFormProps<TEntity extends Entity> {
|
|
|
48
50
|
* `useEntityForm` owns the draft and seeds it once, so the page keys this
|
|
49
51
|
* component by the record id to reseed when the record arrives.
|
|
50
52
|
*/
|
|
51
|
-
export declare function EntityCrudForm<TEntity extends Entity>({ entityConstructor, catalogKey, hiddenFields, links, entity, isLoading, isSaving, isDeleting, error, onSave, onDelete, backHref, renderLink, draft, metadataSource, onUseCase, }: EntityCrudFormProps<TEntity>): import("react").JSX.Element;
|
|
53
|
+
export declare function EntityCrudForm<TEntity extends Entity>({ entityConstructor, catalogKey, hiddenFields, links, entity, isLoading, isSaving, isPending, isDeleting, error, onSave, onDelete, backHref, renderLink, draft, metadataSource, onUseCase, }: EntityCrudFormProps<TEntity>): import("react").JSX.Element;
|
|
52
54
|
//# sourceMappingURL=entity-crud-form.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-crud-form.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/entity-crud-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,
|
|
1
|
+
{"version":3,"file":"entity-crud-form.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/entity-crud-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAE1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAGL,KAAK,UAAU,EAGhB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,KAAK,gBAAgB,EAEtB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,6BAA6B,CAAC;AAKrC,MAAM,WAAW,mBAAmB,CAAC,OAAO,SAAS,MAAM;IACzD,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,CA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ACV,KAAK,EACL,cAAc,EACd,SAAS,GACV,EAAE,mBAAmB,CAAC,OAAO,CAAC,+BAkH9B"}
|
|
@@ -22,7 +22,7 @@ import { validationMessagesFor } from './validation-messages.js';
|
|
|
22
22
|
*
|
|
23
23
|
* `useEntityForm` owns the draft and seeds it once, so the page keys this
|
|
24
24
|
* component by the record id to reseed when the record arrives.
|
|
25
|
-
*/ export function EntityCrudForm({ entityConstructor, catalogKey, hiddenFields, links, entity, isLoading = false, isSaving = false, isDeleting = false, error, onSave, onDelete, backHref, renderLink, draft, metadataSource, onUseCase }) {
|
|
25
|
+
*/ export function EntityCrudForm({ entityConstructor, catalogKey, hiddenFields, links, entity, isLoading = false, isSaving = false, isPending = false, isDeleting = false, error, onSave, onDelete, backHref, renderLink, draft, metadataSource, onUseCase }) {
|
|
26
26
|
const et = useT('entity');
|
|
27
27
|
const ct = useT('controls');
|
|
28
28
|
// `controls` copy, resolved here and handed down; see validationMessagesFor.
|
|
@@ -110,6 +110,7 @@ import { validationMessagesFor } from './validation-messages.js';
|
|
|
110
110
|
onUseCase: onUseCase,
|
|
111
111
|
isLoading: isLoading,
|
|
112
112
|
isSaving: isSaving,
|
|
113
|
+
isPending: isPending,
|
|
113
114
|
isDeleting: isDeleting,
|
|
114
115
|
error: error,
|
|
115
116
|
backHref: backHref,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/crud/entity-crud-form.tsx"],"sourcesContent":["'use client';\n\nimport {\n type Entity,\n type EntityConstructor,\n type EntityMetadataSource,\n reconstructEntity,\n type TransitionalFailure,\n} from '@entifix/core';\nimport {\n EntityField,\n EntityForm,\n type RenderLink,\n useT,\n useTranslateKey,\n} from '@entifix/react-controls';\nimport {\n type EntityDraftStore,\n useEntityForm,\n} from '@entifix/react-integration';\nimport { useEffect, useMemo } from 'react';\n\nimport type {\n EntityCatalogKey,\n EntityCrudLinkSource,\n} from './make-entity-crud.types.js';\nimport { useEntityAffordances } from './use-entity-affordances.js';\nimport { useEntityLinkSources } from './use-entity-link-sources.js';\nimport { validationMessagesFor } from './validation-messages.js';\n\nexport interface EntityCrudFormProps<TEntity extends Entity> {\n readonly entityConstructor: EntityConstructor<TEntity>;\n readonly catalogKey: EntityCatalogKey;\n readonly hiddenFields: readonly string[];\n readonly links: readonly EntityCrudLinkSource[];\n /** The record being edited; `undefined` means this is a create. */\n readonly entity?: TEntity;\n readonly isLoading?: boolean;\n readonly isSaving?: boolean;\n readonly isDeleting?: boolean;\n readonly error?: TransitionalFailure;\n readonly onSave: (entity: TEntity) => void;\n /** Omitted for a create — there is nothing to delete yet. */\n readonly onDelete?: () => void;\n readonly backHref: string;\n /** Renders the Back link; see `useCrudRenderLink`. */\n readonly renderLink?: RenderLink;\n /**\n * Where to autosave this form's draft. Omitted by a route host, which is what\n * keeps a plain route ephemeral; the workspace tab host supplies one.\n */\n readonly draft?: EntityDraftStore;\n /**\n * Where this caller's affordances come from. Absent keeps the pre-ADR-0026\n * behaviour: Save and Delete render unconditionally and no declared verb\n * appears — which is what every generated catalog did before it existed.\n */\n readonly metadataSource?: EntityMetadataSource;\n /** Runs a declared `entity`-bound verb on this record, by its key. */\n readonly onUseCase?: (key: string) => void;\n}\n\n/**\n * The generated create/update form. A thin wrapper over the agnostic\n * {@link EntityForm}: every field, label and validation rule comes from the\n * entity's own accessor metadata, and `reconstructEntity` derives the submit\n * rebuild from that same metadata — so nothing here is per-entity but the\n * constructor, the catalog key and the hidden-field list.\n *\n * A hidden member still round-trips. `code` is assigned by the create\n * transaction and never shown, but it is a plain writable member, so the rebuild\n * picks it out of the seeded draft; dropping it from the rendered fields is not\n * dropping it from the draft.\n *\n * `useEntityForm` owns the draft and seeds it once, so the page keys this\n * component by the record id to reseed when the record arrives.\n */\nexport function EntityCrudForm<TEntity extends Entity>({\n entityConstructor,\n catalogKey,\n hiddenFields,\n links,\n entity,\n isLoading = false,\n isSaving = false,\n isDeleting = false,\n error,\n onSave,\n onDelete,\n backHref,\n renderLink,\n draft,\n metadataSource,\n onUseCase,\n}: EntityCrudFormProps<TEntity>) {\n const et = useT('entity');\n const ct = useT('controls');\n\n // `controls` copy, resolved here and handed down; see validationMessagesFor.\n const validationMessages = useMemo(() => validationMessagesFor(ct), [ct]);\n\n // A runtime-key translator, so a message names the field by its catalog word\n // (`labelKey`) and a schema's keyed message resolves at all. Without it both\n // fell back to untranslated text inside an otherwise Spanish sentence.\n const translateKey = useTranslateKey();\n\n const form = useEntityForm<TEntity>({\n entityConstructor,\n entity,\n validationMessages,\n translateKey,\n draft,\n onSubmit: values =>\n onSave(\n reconstructEntity(entityConstructor, values, { existing: entity }),\n ),\n });\n\n const linkSources = useEntityLinkSources(links, {\n values: form.values,\n selection: form.links,\n });\n\n // Refill the relation sidecar from the ids the draft did keep.\n //\n // A draft is JSON, so it holds ids and nothing else; the instances behind them\n // die with the page. Each picker already resolves its id — that is how a\n // restored draft shows a brand's name instead of its key — so the instance is\n // in hand and only has to be handed back. Without this, a member declared\n // `linkSerialization: 'embedded'` reaches `applyEntityLinks` with an id and no\n // target, which it refuses rather than writing the wrong wire shape.\n //\n // `hydrateLink`, not `setLink`: this is a lookup landing, not a pick, so it\n // must leave the draft — and the form's dirty flag — alone.\n const { links: selection, hydrateLink } = form;\n useEffect(() => {\n for (const [field, source] of Object.entries(linkSources)) {\n const resolved = source.selected.entity;\n if (resolved !== undefined && selection[field] === undefined) {\n hydrateLink(field, resolved);\n }\n }\n }, [linkSources, selection, hydrateLink]);\n\n const affordances = useEntityAffordances(entityConstructor, metadataSource);\n\n /**\n * May this caller write the record in front of them?\n *\n * The **same authority that withholds Save**, applied one step earlier.\n * Absent metadata keeps the pre-ADR-0026 behaviour, so an un-migrated call\n * site is untouched; present metadata is authoritative, because it is what\n * the service already decided.\n *\n * ⚠️ Without this the form rendered inputs nobody could submit. Measured on\n * the stock surface: `stock-item` answers `[\"read\"]` — no role holds\n * `stock-item:write` and there is no save route — so Save was correctly\n * absent while `onHand` and `reserved` still rendered as **enabled number\n * inputs**. A vendor could type a new quantity into a field that is only ever\n * moved by a ledger, and nothing would happen and nothing would say why.\n *\n * A create is exempt: there is no record yet, so there is nothing to read and\n * a `read` mode would render an empty form with no way to fill it.\n */\n const mayWrite =\n entity === undefined ||\n affordances.metadata === undefined ||\n affordances.metadata.actions.includes('write');\n\n return (\n <EntityForm<TEntity>\n entityConstructor={entityConstructor}\n entity={entity}\n // Driven by the served descriptor rather than fixed: `edit` for a caller\n // who may write, `read` for one who may not. Passing it at all is what\n // suppresses the built-in Ver/Editar toggle, which would otherwise offer\n // a way back into inputs the service will refuse.\n mode={mayWrite ? 'edit' : 'read'}\n values={form.values}\n onFieldChange={form.setField}\n linkSources={linkSources}\n onLinkChange={form.setLink}\n errors={form.errors}\n formError={form.formError}\n onSubmit={form.submit}\n onDelete={onDelete}\n {...affordances}\n onUseCase={onUseCase}\n isLoading={isLoading}\n isSaving={isSaving}\n isDeleting={isDeleting}\n error={error}\n backHref={backHref}\n renderLink={renderLink}\n // `entity` is undefined until the record lands, so testing it alone\n // titled a loading edit form \"New\" and then relabelled it.\n title={et(\n entity || isLoading\n ? `${catalogKey}.form.editTitle`\n : `${catalogKey}.form.newTitle`,\n )}\n >\n {hiddenFields.map(field => (\n <EntityField<TEntity> key={field} field={field} hidden />\n ))}\n </EntityForm>\n );\n}\n"],"names":["reconstructEntity","EntityField","EntityForm","useT","useTranslateKey","useEntityForm","useEffect","useMemo","useEntityAffordances","useEntityLinkSources","validationMessagesFor","EntityCrudForm","entityConstructor","catalogKey","hiddenFields","links","entity","isLoading","isSaving","isDeleting","error","onSave","onDelete","backHref","renderLink","draft","metadataSource","onUseCase","et","ct","validationMessages","translateKey","form","onSubmit","values","existing","linkSources","selection","hydrateLink","field","source","Object","entries","resolved","selected","undefined","affordances","mayWrite","metadata","actions","includes","mode","onFieldChange","setField","onLinkChange","setLink","errors","formError","submit","title","map","hidden"],"mappings":"AAAA;;;AAEA,SAIEA,iBAAiB,QAEZ,gBAAgB;AACvB,SACEC,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KAAK,MAAM,CAACiC,OAAOC,OAAO,IAAIC,OAAOC,OAAO,CAACN,aAAc;YACzD,MAAMO,WAAWH,OAAOI,QAAQ,CAAC5B,MAAM;YACvC,IAAI2B,aAAaE,aAAaR,SAAS,CAACE,MAAM,KAAKM,WAAW;gBAC5DP,YAAYC,OAAOI;YACrB;QACF;IACF,GAAG;QAACP;QAAaC;QAAWC;KAAY;IAExC,MAAMQ,cAActC,qBAAqBI,mBAAmBc;IAE5D;;;;;;;;;;;;;;;;;GAiBC,GACD,MAAMqB,WACJ/B,WAAW6B,aACXC,YAAYE,QAAQ,KAAKH,aACzBC,YAAYE,QAAQ,CAACC,OAAO,CAACC,QAAQ,CAAC;IAExC,qBACE,KAAChD;QACCU,mBAAmBA;QACnBI,QAAQA;QACR,yEAAyE;QACzE,uEAAuE;QACvE,yEAAyE;QACzE,kDAAkD;QAClDmC,MAAMJ,WAAW,SAAS;QAC1Bb,QAAQF,KAAKE,MAAM;QACnBkB,eAAepB,KAAKqB,QAAQ;QAC5BjB,aAAaA;QACbkB,cAActB,KAAKuB,OAAO;QAC1BC,QAAQxB,KAAKwB,MAAM;QACnBC,WAAWzB,KAAKyB,SAAS;QACzBxB,UAAUD,KAAK0B,MAAM;QACrBpC,UAAUA;OACNwB;QACJnB,WAAWA;QACXV,WAAWA;QACXC,UAAUA;QACVC,YAAYA;QACZC,OAAOA;QACPG,UAAUA;QACVC,YAAYA;QACZ,oEAAoE;QACpE,2DAA2D;QAC3DmC,OAAO/B,GACLZ,UAAUC,YACN,GAAGJ,WAAW,eAAe,CAAC,GAC9B,GAAGA,WAAW,cAAc,CAAC;kBAGlCC,aAAa8C,GAAG,CAACrB,CAAAA,sBAChB,KAACtC;gBAAiCsC,OAAOA;gBAAOsB,MAAM;eAA3BtB;;AAInC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/crud/entity-crud-form.tsx"],"sourcesContent":["'use client';\n\nimport {\n type EntifixFailure,\n type Entity,\n type EntityConstructor,\n type EntityMetadataSource,\n reconstructEntity,\n} from '@entifix/core';\nimport {\n EntityField,\n EntityForm,\n type RenderLink,\n useT,\n useTranslateKey,\n} from '@entifix/react-controls';\nimport {\n type EntityDraftStore,\n useEntityForm,\n} from '@entifix/react-integration';\nimport { useEffect, useMemo } from 'react';\n\nimport type {\n EntityCatalogKey,\n EntityCrudLinkSource,\n} from './make-entity-crud.types.js';\nimport { useEntityAffordances } from './use-entity-affordances.js';\nimport { useEntityLinkSources } from './use-entity-link-sources.js';\nimport { validationMessagesFor } from './validation-messages.js';\n\nexport interface EntityCrudFormProps<TEntity extends Entity> {\n readonly entityConstructor: EntityConstructor<TEntity>;\n readonly catalogKey: EntityCatalogKey;\n readonly hiddenFields: readonly string[];\n readonly links: readonly EntityCrudLinkSource[];\n /** The record being edited; `undefined` means this is a create. */\n readonly entity?: TEntity;\n readonly isLoading?: boolean;\n readonly isSaving?: boolean;\n /** A write handed to a flow that has not settled: the form waits, keeping its input. */\n readonly isPending?: boolean;\n readonly isDeleting?: boolean;\n readonly error?: EntifixFailure;\n readonly onSave: (entity: TEntity) => void;\n /** Omitted for a create — there is nothing to delete yet. */\n readonly onDelete?: () => void;\n readonly backHref: string;\n /** Renders the Back link; see `useCrudRenderLink`. */\n readonly renderLink?: RenderLink;\n /**\n * Where to autosave this form's draft. Omitted by a route host, which is what\n * keeps a plain route ephemeral; the workspace tab host supplies one.\n */\n readonly draft?: EntityDraftStore;\n /**\n * Where this caller's affordances come from. Absent keeps the pre-ADR-0026\n * behaviour: Save and Delete render unconditionally and no declared verb\n * appears — which is what every generated catalog did before it existed.\n */\n readonly metadataSource?: EntityMetadataSource;\n /** Runs a declared `entity`-bound verb on this record, by its key. */\n readonly onUseCase?: (key: string) => void;\n}\n\n/**\n * The generated create/update form. A thin wrapper over the agnostic\n * {@link EntityForm}: every field, label and validation rule comes from the\n * entity's own accessor metadata, and `reconstructEntity` derives the submit\n * rebuild from that same metadata — so nothing here is per-entity but the\n * constructor, the catalog key and the hidden-field list.\n *\n * A hidden member still round-trips. `code` is assigned by the create\n * transaction and never shown, but it is a plain writable member, so the rebuild\n * picks it out of the seeded draft; dropping it from the rendered fields is not\n * dropping it from the draft.\n *\n * `useEntityForm` owns the draft and seeds it once, so the page keys this\n * component by the record id to reseed when the record arrives.\n */\nexport function EntityCrudForm<TEntity extends Entity>({\n entityConstructor,\n catalogKey,\n hiddenFields,\n links,\n entity,\n isLoading = false,\n isSaving = false,\n isPending = false,\n isDeleting = false,\n error,\n onSave,\n onDelete,\n backHref,\n renderLink,\n draft,\n metadataSource,\n onUseCase,\n}: EntityCrudFormProps<TEntity>) {\n const et = useT('entity');\n const ct = useT('controls');\n\n // `controls` copy, resolved here and handed down; see validationMessagesFor.\n const validationMessages = useMemo(() => validationMessagesFor(ct), [ct]);\n\n // A runtime-key translator, so a message names the field by its catalog word\n // (`labelKey`) and a schema's keyed message resolves at all. Without it both\n // fell back to untranslated text inside an otherwise Spanish sentence.\n const translateKey = useTranslateKey();\n\n const form = useEntityForm<TEntity>({\n entityConstructor,\n entity,\n validationMessages,\n translateKey,\n draft,\n onSubmit: values =>\n onSave(\n reconstructEntity(entityConstructor, values, { existing: entity }),\n ),\n });\n\n const linkSources = useEntityLinkSources(links, {\n values: form.values,\n selection: form.links,\n });\n\n // Refill the relation sidecar from the ids the draft did keep.\n //\n // A draft is JSON, so it holds ids and nothing else; the instances behind them\n // die with the page. Each picker already resolves its id — that is how a\n // restored draft shows a brand's name instead of its key — so the instance is\n // in hand and only has to be handed back. Without this, a member declared\n // `linkSerialization: 'embedded'` reaches `applyEntityLinks` with an id and no\n // target, which it refuses rather than writing the wrong wire shape.\n //\n // `hydrateLink`, not `setLink`: this is a lookup landing, not a pick, so it\n // must leave the draft — and the form's dirty flag — alone.\n const { links: selection, hydrateLink } = form;\n useEffect(() => {\n for (const [field, source] of Object.entries(linkSources)) {\n const resolved = source.selected.entity;\n if (resolved !== undefined && selection[field] === undefined) {\n hydrateLink(field, resolved);\n }\n }\n }, [linkSources, selection, hydrateLink]);\n\n const affordances = useEntityAffordances(entityConstructor, metadataSource);\n\n /**\n * May this caller write the record in front of them?\n *\n * The **same authority that withholds Save**, applied one step earlier.\n * Absent metadata keeps the pre-ADR-0026 behaviour, so an un-migrated call\n * site is untouched; present metadata is authoritative, because it is what\n * the service already decided.\n *\n * ⚠️ Without this the form rendered inputs nobody could submit. Measured on\n * the stock surface: `stock-item` answers `[\"read\"]` — no role holds\n * `stock-item:write` and there is no save route — so Save was correctly\n * absent while `onHand` and `reserved` still rendered as **enabled number\n * inputs**. A vendor could type a new quantity into a field that is only ever\n * moved by a ledger, and nothing would happen and nothing would say why.\n *\n * A create is exempt: there is no record yet, so there is nothing to read and\n * a `read` mode would render an empty form with no way to fill it.\n */\n const mayWrite =\n entity === undefined ||\n affordances.metadata === undefined ||\n affordances.metadata.actions.includes('write');\n\n return (\n <EntityForm<TEntity>\n entityConstructor={entityConstructor}\n entity={entity}\n // Driven by the served descriptor rather than fixed: `edit` for a caller\n // who may write, `read` for one who may not. Passing it at all is what\n // suppresses the built-in Ver/Editar toggle, which would otherwise offer\n // a way back into inputs the service will refuse.\n mode={mayWrite ? 'edit' : 'read'}\n values={form.values}\n onFieldChange={form.setField}\n linkSources={linkSources}\n onLinkChange={form.setLink}\n errors={form.errors}\n formError={form.formError}\n onSubmit={form.submit}\n onDelete={onDelete}\n {...affordances}\n onUseCase={onUseCase}\n isLoading={isLoading}\n isSaving={isSaving}\n isPending={isPending}\n isDeleting={isDeleting}\n error={error}\n backHref={backHref}\n renderLink={renderLink}\n // `entity` is undefined until the record lands, so testing it alone\n // titled a loading edit form \"New\" and then relabelled it.\n title={et(\n entity || isLoading\n ? `${catalogKey}.form.editTitle`\n : `${catalogKey}.form.newTitle`,\n )}\n >\n {hiddenFields.map(field => (\n <EntityField<TEntity> key={field} field={field} hidden />\n ))}\n </EntityForm>\n );\n}\n"],"names":["reconstructEntity","EntityField","EntityForm","useT","useTranslateKey","useEntityForm","useEffect","useMemo","useEntityAffordances","useEntityLinkSources","validationMessagesFor","EntityCrudForm","entityConstructor","catalogKey","hiddenFields","links","entity","isLoading","isSaving","isPending","isDeleting","error","onSave","onDelete","backHref","renderLink","draft","metadataSource","onUseCase","et","ct","validationMessages","translateKey","form","onSubmit","values","existing","linkSources","selection","hydrateLink","field","source","Object","entries","resolved","selected","undefined","affordances","mayWrite","metadata","actions","includes","mode","onFieldChange","setField","onLinkChange","setLink","errors","formError","submit","title","map","hidden"],"mappings":"AAAA;;;AAEA,SAKEA,iBAAiB,QACZ,gBAAgB;AACvB,SACEC,WAAW,EACXC,UAAU,EAEVC,IAAI,EACJC,eAAe,QACV,0BAA0B;AACjC,SAEEC,aAAa,QACR,6BAA6B;AACpC,SAASC,SAAS,EAAEC,OAAO,QAAQ,QAAQ;AAM3C,SAASC,oBAAoB,QAAQ,8BAA8B;AACnE,SAASC,oBAAoB,QAAQ,+BAA+B;AACpE,SAASC,qBAAqB,QAAQ,2BAA2B;AAoCjE;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,eAAuC,EACrDC,iBAAiB,EACjBC,UAAU,EACVC,YAAY,EACZC,KAAK,EACLC,MAAM,EACNC,YAAY,KAAK,EACjBC,WAAW,KAAK,EAChBC,YAAY,KAAK,EACjBC,aAAa,KAAK,EAClBC,KAAK,EACLC,MAAM,EACNC,QAAQ,EACRC,QAAQ,EACRC,UAAU,EACVC,KAAK,EACLC,cAAc,EACdC,SAAS,EACoB;IAC7B,MAAMC,KAAK1B,KAAK;IAChB,MAAM2B,KAAK3B,KAAK;IAEhB,6EAA6E;IAC7E,MAAM4B,qBAAqBxB,QAAQ,IAAMG,sBAAsBoB,KAAK;QAACA;KAAG;IAExE,6EAA6E;IAC7E,6EAA6E;IAC7E,uEAAuE;IACvE,MAAME,eAAe5B;IAErB,MAAM6B,OAAO5B,cAAuB;QAClCO;QACAI;QACAe;QACAC;QACAN;QACAQ,UAAUC,CAAAA,SACRb,OACEtB,kBAAkBY,mBAAmBuB,QAAQ;gBAAE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OA;QACPG,UAAUA;QACVC,YAAYA;QACZ,oEAAoE;QACpE,2DAA2D;QAC3DmC,OAAO/B,GACLb,UAAUC,YACN,GAAGJ,WAAW,eAAe,CAAC,GAC9B,GAAGA,WAAW,cAAc,CAAC;kBAGlCC,aAAa+C,GAAG,CAACrB,CAAAA,sBAChB,KAACvC;gBAAiCuC,OAAOA;gBAAOsB,MAAM;eAA3BtB;;AAInC"}
|
package/dist/lib/crud/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,WAAW,CAAC;AAC1B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC"}
|
package/dist/lib/crud/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/crud/index.ts"],"sourcesContent":["export * from './entity-crud-form.js';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/crud/index.ts"],"sourcesContent":["export * from './entity-crud-form.js';\nexport * from './make-entity-crud.js';\nexport * from './make-entity-crud.types.js';\nexport * from './slug.js';\nexport * from './use-crud-render-link.js';\nexport * from './use-entity-affordances.js';\nexport * from './use-entity-bulk.js';\nexport * from './use-entity-link-sources.js';\n"],"names":[],"mappings":"AAAA,cAAc,wBAAwB;AACtC,cAAc,wBAAwB;AACtC,cAAc,8BAA8B;AAC5C,cAAc,YAAY;AAC1B,cAAc,4BAA4B;AAC1C,cAAc,8BAA8B;AAC5C,cAAc,uBAAuB;AACrC,cAAc,+BAA+B"}
|
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
import { type EntityRepositoryTag } from '@entifix/business';
|
|
2
2
|
import { type Entity, type EntityConstructor } from '@entifix/core';
|
|
3
|
-
import type { TransactionSink } from '@entifix/transactions';
|
|
4
|
-
import { TransactionSinkTag } from '@entifix/transactions';
|
|
5
3
|
import { Context } from 'effect';
|
|
6
4
|
import type { EntityCrud, EntityCrudOptions } from './make-entity-crud.types.js';
|
|
7
5
|
/**
|
|
8
|
-
* What the generated pages' use-cases run against.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* records, resolves pickers and writes through exactly these ports, and
|
|
12
|
-
* rebuilding the union at each such call site is how one of them ends up
|
|
13
|
-
* missing `TransactionSinkTag` and quietly losing its optimistic treatment.
|
|
6
|
+
* What the generated pages' use-cases run against: one repository adapter.
|
|
7
|
+
* Exported because a hand-built screen — a wizard reading records and
|
|
8
|
+
* resolving pickers — runs against exactly the same.
|
|
14
9
|
*/
|
|
15
|
-
export type CrudContext = EntityRepositoryTag
|
|
10
|
+
export type CrudContext = EntityRepositoryTag;
|
|
16
11
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
12
|
+
* One repository adapter, by its key, as the context the use-cases run
|
|
13
|
+
* against.
|
|
19
14
|
*
|
|
20
15
|
* The cast is the price of naming adapters by key: `AdapterKey` narrows which
|
|
21
16
|
* names may be *offered*, but TypeScript will not carry that narrowing through
|
|
22
17
|
* an index access on a generic record.
|
|
23
18
|
*/
|
|
24
|
-
export declare function
|
|
19
|
+
export declare function crudContextOf<TAdapters>(adapters: TAdapters, repository: keyof TAdapters): Context.Context<CrudContext>;
|
|
25
20
|
export declare function makeEntityCrud<TEntity extends Entity, TAdapters>(entityConstructor: EntityConstructor<TEntity>, options: EntityCrudOptions<TAdapters, TEntity>): EntityCrud<TEntity>;
|
|
26
21
|
//# sourceMappingURL=make-entity-crud.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-entity-crud.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/make-entity-crud.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"make-entity-crud.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/make-entity-crud.tsx"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,mBAAmB,EAKzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,iBAAiB,EAavB,MAAM,eAAe,CAAC;AAUvB,OAAO,EAAS,OAAO,EAAgB,MAAM,QAAQ,CAAC;AAOtD,OAAO,KAAK,EAEV,UAAU,EAEV,iBAAiB,EAElB,MAAM,6BAA6B,CAAC;AASrC;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAE9C;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,SAAS,EACrC,QAAQ,EAAE,SAAS,EACnB,UAAU,EAAE,MAAM,SAAS,GAC1B,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAE9B;AAsID,wBAAgB,cAAc,CAAC,OAAO,SAAS,MAAM,EAAE,SAAS,EAC9D,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAC7C,OAAO,EAAE,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC,GAC7C,UAAU,CAAC,OAAO,CAAC,CAqZrB"}
|