@entifix/next-shell 0.20.3 → 0.21.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/README.md +16 -1
- package/dist/lib/crud/index.d.ts +1 -0
- package/dist/lib/crud/index.d.ts.map +1 -1
- package/dist/lib/crud/index.js +1 -0
- package/dist/lib/crud/index.js.map +1 -1
- package/dist/lib/crud/make-entity-crud.d.ts.map +1 -1
- package/dist/lib/crud/make-entity-crud.js +128 -58
- package/dist/lib/crud/make-entity-crud.js.map +1 -1
- package/dist/lib/crud/make-entity-crud.types.d.ts +68 -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/crud/reference-labels.d.ts +27 -0
- package/dist/lib/crud/reference-labels.d.ts.map +1 -0
- package/dist/lib/crud/reference-labels.js +159 -0
- package/dist/lib/crud/reference-labels.js.map +1 -0
- package/dist/lib/crud/regions.d.ts +25 -0
- package/dist/lib/crud/regions.d.ts.map +1 -0
- package/dist/lib/crud/regions.js +82 -0
- package/dist/lib/crud/regions.js.map +1 -0
- package/dist/lib/crud/related-columns.d.ts +29 -0
- package/dist/lib/crud/related-columns.d.ts.map +1 -0
- package/dist/lib/crud/related-columns.js +141 -0
- package/dist/lib/crud/related-columns.js.map +1 -0
- package/dist/lib/i18n/catalog/en.d.ts.map +1 -1
- package/dist/lib/i18n/catalog/en.js +6 -0
- package/dist/lib/i18n/catalog/en.js.map +1 -1
- package/dist/lib/i18n/catalog/es.d.ts +8 -0
- package/dist/lib/i18n/catalog/es.d.ts.map +1 -1
- package/dist/lib/i18n/catalog/es.js +7 -1
- package/dist/lib/i18n/catalog/es.js.map +1 -1
- package/dist/lib/i18n/catalog/index.d.ts +12 -0
- package/dist/lib/i18n/catalog/index.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/lib/crud/use-link-labels.d.ts +0 -32
- package/dist/lib/crud/use-link-labels.d.ts.map +0 -1
- package/dist/lib/crud/use-link-labels.js +0 -76
- package/dist/lib/crud/use-link-labels.js.map +0 -1
|
@@ -83,7 +83,11 @@ export interface EntityCrudLink<TAdapters, TEntity extends Entity = Entity> {
|
|
|
83
83
|
* resolving an id goes through that domain's own read path.
|
|
84
84
|
*/
|
|
85
85
|
readonly repository: AdapterKey<TAdapters, Context<EntityRepositoryTag>>;
|
|
86
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* What the picker shows for a candidate. Defaults to `'name'`. The picker's
|
|
88
|
+
* display only: a list, a read form and a confirm name the target through
|
|
89
|
+
* the member's `references` and the host's `ReferenceLabelsHost`.
|
|
90
|
+
*/
|
|
87
91
|
readonly labelProperty?: string;
|
|
88
92
|
/** Defaults to `'name'`. Must be `filterable` on the target. */
|
|
89
93
|
readonly searchProperty?: string;
|
|
@@ -114,10 +118,61 @@ export interface EntityCrudLink<TAdapters, TEntity extends Entity = Entity> {
|
|
|
114
118
|
* {@link AnyEntityLinkSourceConfig} is.
|
|
115
119
|
*/
|
|
116
120
|
export type AnyFilterGroup = FilterGroup<any>;
|
|
121
|
+
/**
|
|
122
|
+
* A column whose value lives in another entity — a price that points at the
|
|
123
|
+
* offering, the stock held of it, the brand it names — read in **one request
|
|
124
|
+
* per column per page** through the target's own read path
|
|
125
|
+
* ([ADR 0030](../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)).
|
|
126
|
+
*
|
|
127
|
+
* Matched one of two ways, never both:
|
|
128
|
+
*
|
|
129
|
+
* - `via` — a member of **this** entity that `references` the target, so the
|
|
130
|
+
* target is read by `id=in=(…)` over the page's values of it;
|
|
131
|
+
* - `match` — a member of the **target** holding this record's id, so the
|
|
132
|
+
* target is read by `<match>=in=(…)` over the page's ids. It must be
|
|
133
|
+
* `filterable` on the target.
|
|
134
|
+
*
|
|
135
|
+
* Zero matches read `—`, one reads its `member` through the target's own
|
|
136
|
+
* descriptor (money reads as money), and more than one reads as a count. The
|
|
137
|
+
* column is never sortable or filterable: its value is in another store, and a
|
|
138
|
+
* sort the server cannot run would be a lie.
|
|
139
|
+
*/
|
|
140
|
+
export interface EntityCrudRelated<TAdapters> {
|
|
141
|
+
/** The column's identity, unique among the list's columns. */
|
|
142
|
+
readonly key: string;
|
|
143
|
+
/** Catalog key for its header, e.g. `entity:product-offering.related.price`. */
|
|
144
|
+
readonly labelKey: string;
|
|
145
|
+
readonly target: EntityConstructor<Entity>;
|
|
146
|
+
/** Which adapter holds the target's repository. The column names no adapter of its own. */
|
|
147
|
+
readonly repository: AdapterKey<TAdapters, Context<EntityRepositoryTag>>;
|
|
148
|
+
readonly via?: string;
|
|
149
|
+
readonly match?: string;
|
|
150
|
+
/** Narrows the matches, AND-ed with the match — the current price, the active stock. */
|
|
151
|
+
readonly filtering?: AnyFilterGroup;
|
|
152
|
+
/** The target's member the column shows. */
|
|
153
|
+
readonly member: string;
|
|
154
|
+
/** How one match renders, in place of its member's value — a picture, say. */
|
|
155
|
+
readonly render?: (match: Entity) => ReactNode;
|
|
156
|
+
}
|
|
117
157
|
/** The keys of `TAdapters` whose value is assignable to `TValue`. */
|
|
118
158
|
export type AdapterKey<TAdapters, TValue> = {
|
|
119
159
|
[K in keyof TAdapters]: TAdapters[K] extends TValue ? K : never;
|
|
120
160
|
}[keyof TAdapters];
|
|
161
|
+
/** A related region: this entity's records that refer to another record. */
|
|
162
|
+
export interface EntityCrudRelatedListProps<TEntity extends Entity> {
|
|
163
|
+
/** Which records — those referring to the record whose page this is. Fixed, and shown as no chip. */
|
|
164
|
+
readonly filtering: FilterGroup<TEntity>;
|
|
165
|
+
/** Catalog key for the region's `h2`, and its entry in the page's section nav. */
|
|
166
|
+
readonly labelKey: string;
|
|
167
|
+
/**
|
|
168
|
+
* The members a "New" from this region opens already set — the parent
|
|
169
|
+
* record's id under the member that refers to it.
|
|
170
|
+
*/
|
|
171
|
+
readonly prefill?: Readonly<Record<string, string>>;
|
|
172
|
+
/** Where "New" goes, in place of this crud's create page with `prefill`. */
|
|
173
|
+
readonly newHref?: string;
|
|
174
|
+
readonly pageSize?: number;
|
|
175
|
+
}
|
|
121
176
|
export interface EntityCrudOptions<TAdapters, TEntity extends Entity> {
|
|
122
177
|
/** The domain shell's adapters hook, e.g. `useMarketplaceAdminAdapters`. */
|
|
123
178
|
readonly useAdapters: () => TAdapters;
|
|
@@ -182,6 +237,16 @@ export interface EntityCrudOptions<TAdapters, TEntity extends Entity> {
|
|
|
182
237
|
readonly delete?: 'confirm' | 'undo' | 'typed';
|
|
183
238
|
/** Frozen at factory time — see `use-entity-link-sources.ts`. */
|
|
184
239
|
readonly links?: readonly EntityCrudLink<TAdapters, TEntity>[];
|
|
240
|
+
/** Columns whose values live in another entity, read per page. */
|
|
241
|
+
readonly related?: readonly EntityCrudRelated<TAdapters>[];
|
|
242
|
+
/**
|
|
243
|
+
* The records that refer to this one, as regions under its form — each
|
|
244
|
+
* usually another crud's `RelatedList`, held to this record's id. Rendered
|
|
245
|
+
* for an existing record only, never on create. Not master-detail: each
|
|
246
|
+
* region writes its own records through its own owner, with its own Save,
|
|
247
|
+
* and there is no page-wide Save across stores.
|
|
248
|
+
*/
|
|
249
|
+
readonly regions?: (record: TEntity) => readonly ReactNode[];
|
|
185
250
|
/**
|
|
186
251
|
* Where the entity's served affordances come from — `GET /api/<entity>/$metadata`.
|
|
187
252
|
*
|
|
@@ -283,6 +348,8 @@ export interface EntityCrud<TEntity extends Entity> {
|
|
|
283
348
|
readonly basePath: string;
|
|
284
349
|
readonly ListPage: () => ReactElement;
|
|
285
350
|
readonly SingleViewPage: (props?: EntityCrudSingleViewProps) => ReactElement;
|
|
351
|
+
/** This entity's records referring to another record, as a region of that record's page. */
|
|
352
|
+
readonly RelatedList: (props: EntityCrudRelatedListProps<TEntity>) => ReactElement;
|
|
286
353
|
}
|
|
287
354
|
/**
|
|
288
355
|
* A picker's transport with its context tags erased.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-entity-crud.types.d.ts","sourceRoot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C,KACvC,YAAY,CAAC;CACnB;AAED;;;;;;;GAOG;AAEH,MAAM,MAAM,yBAAyB,GAAG,sBAAsB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE5E;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,qBAAqB,CAAC;IAC3C,QAAQ,CAAC,MAAM,EAAE,yBAAyB,CAAC;CAC5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/crud/make-entity-crud.types.ts"],"sourcesContent":["import type {\n EntityFacetCounterTag,\n EntityRepositoryTag,\n} from '@entifix/business';\nimport type {\n Entity,\n EntityConstructor,\n EntityFieldDescriptor,\n EntityMetadataSource,\n EntityUseCaseRunner,\n EntityWriter,\n FilterGroup,\n} from '@entifix/core';\nimport type {\n EntityDraftStore,\n EntityLinkSourceConfig,\n} from '@entifix/react-integration';\nimport type { Context } from 'effect/Context';\nimport type { CustomTypeOptions } from 'i18next';\nimport type { ReactElement, ReactNode } from 'react';\n\n/**\n * The `entity` catalog keys that carry **both** form titles, a `label` and a\n * `plural`.\n *\n * Derived from the Spanish catalog rather than written out, so the union is the\n * catalog: an entity whose subtree has no `form.editTitle`/`form.newTitle`\n * cannot be handed to {@link makeEntityCrud} at all, and adding a reference\n * entity therefore starts by adding its copy to both locales. That is the whole\n * i18n gate for this factory — a host's catalog check typically scans its\n * domain packages for `@useCase()` decorators and never `.tsx`, so a runtime\n * key here would be checked by nothing.\n *\n * `label`/`plural` joined the condition when {@link EntityCrud} began carrying\n * them, so that a workspace tab and a nav entry derived from this descriptor\n * name the entity in the catalog's own words. They are part of the **type**\n * rather than a runtime assertion in the factory, because the catalog is\n * statically known here: a missing `plural` should fail at the call site that\n * generates the screens, not on the render that first tries to title a tab.\n *\n * Keeping the key typed is what lets the generated form call `useT('entity')`\n * with a template literal and still fail the build on a typo, instead of\n * reaching for the `useTranslateKey` escape hatch that authored copy must not\n * use. `AccountLabelKey` in `../session/account-links.ts` is the same trick\n * written out by hand; this one cannot drift because it is computed.\n */\nexport type EntityCatalogKey<\n TEntityCatalog = EntityCatalogOf<TypeOptionsResources>,\n> = [TEntityCatalog] extends [never]\n ? // No host augmentation in this compilation — this package's own specs, or\n // an adopter who has not declared one. The factory still works; the key is\n // simply unchecked, which is the same trade `useTranslateKey` makes.\n string\n : {\n [K in keyof TEntityCatalog]: TEntityCatalog[K] extends {\n form: { editTitle: string; newTitle: string };\n label: string;\n plural: string;\n }\n ? K\n : never;\n }[keyof TEntityCatalog] &\n string;\n\n/**\n * The host's `entity` namespace, read back out of its own `i18next`\n * augmentation.\n *\n * ⚠️ **The `entity` catalog is the host's, not entifix's.** It names *their*\n * entities — a parameter, an offering, a sales channel — so a framework that\n * shipped one would be shipping an application's product copy. Reading it back\n * through `CustomTypeOptions` keeps the key union computed rather than written\n * out, which is what stops it drifting, while leaving the catalog where it\n * belongs. A host that declares no augmentation gets `string`, and the factory\n * still works with the gate relaxed.\n */\ntype TypeOptionsResources = CustomTypeOptions extends { resources: infer R }\n ? R\n : never;\n\ntype EntityCatalogOf<TResources> = TResources extends { entity: infer E }\n ? E\n : never;\n\n/**\n * A relation the generated form edits with a picker.\n *\n * The target is named here rather than derived, because the common case is a\n * **plain foreign key**: when the target lives in another slice's store a typed\n * `EntityLink` is both an illegal import and a cross-store join, so the member\n * is a bare `string` (`ProductSpecification.brandId` into `catalog-reference`)\n * and its `@accessor()` has no vocabulary for \"the target's name\". Hence\n * `labelProperty`/`searchProperty` are stated at the call site instead of being\n * left to `describeEntityColumns`' `'name'` default, which happens to be right\n * today and states nothing.\n *\n * `searchProperty` must be `filterable` on the **target** or the service answers\n * `400`; `useEntityLinkSource` throws at render rather than letting that surface\n * as an empty suggestion list.\n */\nexport interface EntityCrudLink<TAdapters, TEntity extends Entity = Entity> {\n /** The owning entity's accessor name, e.g. `'brandId'`. */\n readonly field: string;\n readonly entityConstructor: EntityConstructor<Entity>;\n /**\n * Which adapter holds the **target's** repository. Often a different service\n * than the record's own: `catalog-reference` is another slice's store, so\n * resolving an id goes through that domain's own read path.\n */\n readonly repository: AdapterKey<TAdapters, Context<EntityRepositoryTag>>;\n /** Defaults to `'name'`. */\n readonly labelProperty?: string;\n /** Defaults to `'name'`. Must be `filterable` on the target. */\n readonly searchProperty?: string;\n /**\n * A restriction on what may be picked **for this record**, ANDed into every\n * quick and browse request — `useEntityLinkSource`'s `baseFiltering`, built\n * from the record being edited rather than fixed at factory time.\n *\n * A record-dependent rule is the case it exists for: a parent picker that\n * must not offer the record itself or anything beneath it. That rule needs\n * more than the record — its descendants are other records — which is why\n * this is a **hook** and not a function of the record: it may load what it\n * needs through the host's own adapters, and answer `undefined` until it has.\n *\n * Called on every render of the single view, under the rules of hooks: once\n * per link, unconditionally, with `undefined` while the record loads and\n * throughout a create. `undefined` back means no restriction. Its members\n * must be `filterable` on the target, or the service answers `400`. It\n * narrows the suggestions and nothing else — the service still has to refuse\n * a value the picker would not have offered.\n */\n readonly useBaseFiltering?: (\n record: TEntity | undefined,\n ) => AnyFilterGroup | undefined;\n}\n\n/**\n * A restriction over a picker's target, with the target's type erased — the\n * link names its target only as `EntityConstructor<Entity>`, so a filter typed\n * on the real target would not be assignable. Erased for the reason\n * {@link AnyEntityLinkSourceConfig} is.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyFilterGroup = FilterGroup<any>;\n\n/** The keys of `TAdapters` whose value is assignable to `TValue`. */\nexport type AdapterKey<TAdapters, TValue> = {\n [K in keyof TAdapters]: TAdapters[K] extends TValue ? K : never;\n}[keyof TAdapters];\n\nexport interface EntityCrudOptions<TAdapters, TEntity extends Entity> {\n /** The domain shell's adapters hook, e.g. `useMarketplaceAdminAdapters`. */\n readonly useAdapters: () => TAdapters;\n /** Route prefix for both pages, e.g. `'/catalog/product-brand'`. */\n readonly basePath: string;\n /**\n * The entity's `entity` catalog key. Asserted against `@entity({ key })` at\n * factory time — the two are the same string by convention\n * (`entity:product-brand.label` mirrors `key: 'product-brand'`), and letting\n * them drift would title a form after a different entity.\n */\n readonly catalogKey: EntityCatalogKey;\n /** Which adapter holds this entity's own repository. */\n readonly repository: AdapterKey<TAdapters, Context<EntityRepositoryTag>>;\n /**\n * Members the form keeps but does not show — `id` always, plus anything a\n * transaction assigns. A hidden member still round-trips: it is dropped from\n * the rendered fields, not from the draft, so `reconstructEntity` carries it\n * back out of the seeded values.\n */\n readonly hiddenFields?: readonly string[];\n /** `<EntityColumn>` overrides for the list, for presentation metadata cannot express. */\n readonly columns?: ReactNode;\n /**\n * Extra controls beside the table's own — an `<EntityTableToolbar>`.\n *\n * Its own option rather than more `columns`, though both end up as\n * `EntityTable` children and the slots are sorted by component identity: a\n * toolbar filed under a columns prop is a name that lies, and the first thing\n * to go here is a link into a wizard, which is not a column by any reading.\n */\n readonly toolbar?: ReactNode;\n /**\n * How many rows the list asks for on its first load. Defaults to\n * `useDataLoading`'s own default.\n *\n * Raised for a vocabulary that should be seen whole: `EntityTable` nests a\n * hierarchy only within the page it was given, so a tree larger than one page\n * shows the children whose parent fell on another page as roots.\n */\n readonly pageSize?: number;\n /**\n * The filter the list opens with — a worklist, where the default view of a\n * record class is the rows someone has to act on. Shown in the filter panel\n * as the user's own, so it can be changed or cleared; unlike a link's\n * `useBaseFiltering`, it restricts nothing.\n *\n * Checked when the screen is generated against the same allowlist a service\n * applies to a query: a member that is not `filterable`, or a value of the\n * wrong type, throws here rather than answering `400` on every first load.\n */\n readonly initialFiltering?: FilterGroup<TEntity>;\n /**\n * How the record page's Delete is made safe\n * ([ADR 0026](../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)):\n * `confirm` (the default) asks in an alert dialog naming the record; `typed`\n * asks for its name to be typed first — for the records a fleet boots from;\n * `undo` deletes at once and offers Undo, which saves the record back under\n * its id, so it needs a store whose save puts a record back rather than\n * refusing an id it no longer holds.\n */\n readonly delete?: 'confirm' | 'undo' | 'typed';\n /** Frozen at factory time — see `use-entity-link-sources.ts`. */\n readonly links?: readonly EntityCrudLink<TAdapters, TEntity>[];\n /**\n * Where the entity's served affordances come from — `GET /api/<entity>/$metadata`.\n *\n * Supplying it is what turns on every served affordance:\n * Save and Delete filtered against the caller's real grants, the declared\n * verbs on the form, the row overflow menu, and the bulk bar. Omitting it\n * keeps the pre-0026 behaviour exactly, which is what every generated catalog\n * rendered before this option existed.\n *\n * A `EntityMetadataSource` rather than a URL because the two hosts reach\n * their service differently — one through the config-driven REST adapters,\n * one through a shell's own same-origin routes.\n */\n readonly metadataSource?: EntityMetadataSource;\n /**\n * Which adapter holds this entity's {@link EntityMetadataSource} — the same\n * source as {@link metadataSource}, resolved from the host's composition\n * instead of built by the caller.\n *\n * Prefer it: a source is a transport, and naming it by key keeps the module\n * that generates the screens free of the adapter that fetches, exactly as\n * {@link repository} already does for records. Supplying both is a build\n * error — two answers to where the document comes from.\n */\n readonly metadata?: AdapterKey<TAdapters, EntityMetadataSource>;\n /**\n * Which adapter runs this entity's `@useCase()` verbs — over REST against\n * the service that serves them, or in-process for records that live in the\n * browser. Resolved from the host's composition, as {@link repository} is.\n *\n * Supplying it lets the generated screens run what the served `$metadata`\n * lists for the caller: a row's menu and a form's buttons run a verb on a\n * record, and the bulk bar runs a `collection` verb over a selection,\n * reporting per row. A verb that resolves reloads what it changed; one that\n * refuses shows its coded message in the screen's error slot rather than as\n * a promise nobody catches.\n */\n readonly useCases?: AdapterKey<TAdapters, EntityUseCaseRunner>;\n /**\n * Which adapter makes this entity's saves and deletes, answering both\n * settle modes — `buildEntityRestAdapterWrite` over REST. Resolved from the\n * host's composition, as {@link repository} is.\n *\n * Omitted, the form writes through {@link repository}, and every write\n * settles. Supplied, a write the server hands to a flow keeps the form open\n * and waiting, with what was typed, until the flow settles: a completed one\n * returns to the list, and a failed one is toasted once by the\n * `PendingFlowsProvider` above while the form keeps its input.\n */\n readonly write?: AdapterKey<TAdapters, EntityWriter>;\n\n /**\n * An adapter context providing `EntityFacetCounterTag` — the REST client's\n * facets adapter, typically. Supplied, the list's filter panel shows how\n * many records hold each choice of an enum or boolean member, counted under\n * the filters in effect less that member's own.\n */\n readonly facets?: AdapterKey<TAdapters, Context<EntityFacetCounterTag>>;\n}\n\n/**\n * Props both hosts pass. A route host passes none — the slug comes from the URL\n * and a save returns to the list; the workspace tab host passes all of them.\n */\nexport interface EntityCrudSingleViewProps {\n /** Defaults to the `[slug]` route param. */\n readonly slug?: string;\n /** Defaults to navigating back to the list. */\n readonly onSaved?: () => void;\n readonly onDeleted?: () => void;\n /**\n * Where to autosave the edit. Supplying it is the whole opt-in: the form\n * seeds from the persisted draft, writes to it on every edit, and the page\n * clears it once a save or delete commits.\n *\n * A route host omits it and stays ephemeral, which is the rule stated as a\n * missing prop rather than as a flag — there is no value of \"absent\" that\n * accidentally starts persisting.\n */\n readonly draft?: EntityDraftStore;\n}\n\n/**\n * What the factory returns: a **named descriptor**, not four loose components.\n *\n * The identity fields are here so the workspace registry and the nav are derived\n * from a list of these rather than from the hand-written const maps they replace.\n */\nexport interface EntityCrud<TEntity extends Entity> {\n readonly entityConstructor: EntityConstructor<TEntity>;\n /** `@entity({ key })`, which is also `catalogKey` and the tab address payload. */\n readonly entityKey: EntityCatalogKey;\n /**\n * `@entity({ labelKey })` — how one record is named. A record tab's title.\n *\n * Read off the decorator rather than passed, so the tab strip, the nav and the\n * search results all name the entity from the one place it names itself.\n */\n readonly entityLabelKey: string;\n /** `@entity({ pluralKey })` — how the collection is named. A list tab's title. */\n readonly entityPluralKey: string;\n readonly basePath: string;\n readonly ListPage: () => ReactElement;\n readonly SingleViewPage: (props?: EntityCrudSingleViewProps) => ReactElement;\n}\n\n/**\n * A picker's transport with its context tags erased.\n *\n * The factory cannot preserve one type parameter per link — the pages that\n * build these know their adapters, the generated form only forwards them — and\n * `EntityForm.linkSources` is already `Record<string, EntityLinkSource<any>>`\n * for the same reason.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyEntityLinkSourceConfig = EntityLinkSourceConfig<Entity, any>;\n\n/**\n * One picker, resolved: the descriptor computed once at factory time, and the\n * use-cases plus adapter context the page builds per render.\n */\nexport interface EntityCrudLinkSource {\n readonly field: string;\n readonly descriptor: EntityFieldDescriptor;\n readonly config: AnyEntityLinkSourceConfig;\n}\n"],"names":[],"mappings":"AA4UA;;;CAGC,GACD,WAIC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/crud/make-entity-crud.types.ts"],"sourcesContent":["import type {\n EntityFacetCounterTag,\n EntityRepositoryTag,\n} from '@entifix/business';\nimport type {\n Entity,\n EntityConstructor,\n EntityFieldDescriptor,\n EntityMetadataSource,\n EntityUseCaseRunner,\n EntityWriter,\n FilterGroup,\n} from '@entifix/core';\nimport type {\n EntityDraftStore,\n EntityLinkSourceConfig,\n} from '@entifix/react-integration';\nimport type { Context } from 'effect/Context';\nimport type { CustomTypeOptions } from 'i18next';\nimport type { ReactElement, ReactNode } from 'react';\n\n/**\n * The `entity` catalog keys that carry **both** form titles, a `label` and a\n * `plural`.\n *\n * Derived from the Spanish catalog rather than written out, so the union is the\n * catalog: an entity whose subtree has no `form.editTitle`/`form.newTitle`\n * cannot be handed to {@link makeEntityCrud} at all, and adding a reference\n * entity therefore starts by adding its copy to both locales. That is the whole\n * i18n gate for this factory — a host's catalog check typically scans its\n * domain packages for `@useCase()` decorators and never `.tsx`, so a runtime\n * key here would be checked by nothing.\n *\n * `label`/`plural` joined the condition when {@link EntityCrud} began carrying\n * them, so that a workspace tab and a nav entry derived from this descriptor\n * name the entity in the catalog's own words. They are part of the **type**\n * rather than a runtime assertion in the factory, because the catalog is\n * statically known here: a missing `plural` should fail at the call site that\n * generates the screens, not on the render that first tries to title a tab.\n *\n * Keeping the key typed is what lets the generated form call `useT('entity')`\n * with a template literal and still fail the build on a typo, instead of\n * reaching for the `useTranslateKey` escape hatch that authored copy must not\n * use. `AccountLabelKey` in `../session/account-links.ts` is the same trick\n * written out by hand; this one cannot drift because it is computed.\n */\nexport type EntityCatalogKey<\n TEntityCatalog = EntityCatalogOf<TypeOptionsResources>,\n> = [TEntityCatalog] extends [never]\n ? // No host augmentation in this compilation — this package's own specs, or\n // an adopter who has not declared one. The factory still works; the key is\n // simply unchecked, which is the same trade `useTranslateKey` makes.\n string\n : {\n [K in keyof TEntityCatalog]: TEntityCatalog[K] extends {\n form: { editTitle: string; newTitle: string };\n label: string;\n plural: string;\n }\n ? K\n : never;\n }[keyof TEntityCatalog] &\n string;\n\n/**\n * The host's `entity` namespace, read back out of its own `i18next`\n * augmentation.\n *\n * ⚠️ **The `entity` catalog is the host's, not entifix's.** It names *their*\n * entities — a parameter, an offering, a sales channel — so a framework that\n * shipped one would be shipping an application's product copy. Reading it back\n * through `CustomTypeOptions` keeps the key union computed rather than written\n * out, which is what stops it drifting, while leaving the catalog where it\n * belongs. A host that declares no augmentation gets `string`, and the factory\n * still works with the gate relaxed.\n */\ntype TypeOptionsResources = CustomTypeOptions extends { resources: infer R }\n ? R\n : never;\n\ntype EntityCatalogOf<TResources> = TResources extends { entity: infer E }\n ? E\n : never;\n\n/**\n * A relation the generated form edits with a picker.\n *\n * The target is named here rather than derived, because the common case is a\n * **plain foreign key**: when the target lives in another slice's store a typed\n * `EntityLink` is both an illegal import and a cross-store join, so the member\n * is a bare `string` (`ProductSpecification.brandId` into `catalog-reference`)\n * and its `@accessor()` has no vocabulary for \"the target's name\". Hence\n * `labelProperty`/`searchProperty` are stated at the call site instead of being\n * left to `describeEntityColumns`' `'name'` default, which happens to be right\n * today and states nothing.\n *\n * `searchProperty` must be `filterable` on the **target** or the service answers\n * `400`; `useEntityLinkSource` throws at render rather than letting that surface\n * as an empty suggestion list.\n */\nexport interface EntityCrudLink<TAdapters, TEntity extends Entity = Entity> {\n /** The owning entity's accessor name, e.g. `'brandId'`. */\n readonly field: string;\n readonly entityConstructor: EntityConstructor<Entity>;\n /**\n * Which adapter holds the **target's** repository. Often a different service\n * than the record's own: `catalog-reference` is another slice's store, so\n * resolving an id goes through that domain's own read path.\n */\n readonly repository: AdapterKey<TAdapters, Context<EntityRepositoryTag>>;\n /**\n * What the picker shows for a candidate. Defaults to `'name'`. The picker's\n * display only: a list, a read form and a confirm name the target through\n * the member's `references` and the host's `ReferenceLabelsHost`.\n */\n readonly labelProperty?: string;\n /** Defaults to `'name'`. Must be `filterable` on the target. */\n readonly searchProperty?: string;\n /**\n * A restriction on what may be picked **for this record**, ANDed into every\n * quick and browse request — `useEntityLinkSource`'s `baseFiltering`, built\n * from the record being edited rather than fixed at factory time.\n *\n * A record-dependent rule is the case it exists for: a parent picker that\n * must not offer the record itself or anything beneath it. That rule needs\n * more than the record — its descendants are other records — which is why\n * this is a **hook** and not a function of the record: it may load what it\n * needs through the host's own adapters, and answer `undefined` until it has.\n *\n * Called on every render of the single view, under the rules of hooks: once\n * per link, unconditionally, with `undefined` while the record loads and\n * throughout a create. `undefined` back means no restriction. Its members\n * must be `filterable` on the target, or the service answers `400`. It\n * narrows the suggestions and nothing else — the service still has to refuse\n * a value the picker would not have offered.\n */\n readonly useBaseFiltering?: (\n record: TEntity | undefined,\n ) => AnyFilterGroup | undefined;\n}\n\n/**\n * A restriction over a picker's target, with the target's type erased — the\n * link names its target only as `EntityConstructor<Entity>`, so a filter typed\n * on the real target would not be assignable. Erased for the reason\n * {@link AnyEntityLinkSourceConfig} is.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyFilterGroup = FilterGroup<any>;\n\n/**\n * A column whose value lives in another entity — a price that points at the\n * offering, the stock held of it, the brand it names — read in **one request\n * per column per page** through the target's own read path\n * ([ADR 0030](../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)).\n *\n * Matched one of two ways, never both:\n *\n * - `via` — a member of **this** entity that `references` the target, so the\n * target is read by `id=in=(…)` over the page's values of it;\n * - `match` — a member of the **target** holding this record's id, so the\n * target is read by `<match>=in=(…)` over the page's ids. It must be\n * `filterable` on the target.\n *\n * Zero matches read `—`, one reads its `member` through the target's own\n * descriptor (money reads as money), and more than one reads as a count. The\n * column is never sortable or filterable: its value is in another store, and a\n * sort the server cannot run would be a lie.\n */\nexport interface EntityCrudRelated<TAdapters> {\n /** The column's identity, unique among the list's columns. */\n readonly key: string;\n /** Catalog key for its header, e.g. `entity:product-offering.related.price`. */\n readonly labelKey: string;\n readonly target: EntityConstructor<Entity>;\n /** Which adapter holds the target's repository. The column names no adapter of its own. */\n readonly repository: AdapterKey<TAdapters, Context<EntityRepositoryTag>>;\n readonly via?: string;\n readonly match?: string;\n /** Narrows the matches, AND-ed with the match — the current price, the active stock. */\n readonly filtering?: AnyFilterGroup;\n /** The target's member the column shows. */\n readonly member: string;\n /** How one match renders, in place of its member's value — a picture, say. */\n readonly render?: (match: Entity) => ReactNode;\n}\n\n/** The keys of `TAdapters` whose value is assignable to `TValue`. */\nexport type AdapterKey<TAdapters, TValue> = {\n [K in keyof TAdapters]: TAdapters[K] extends TValue ? K : never;\n}[keyof TAdapters];\n\n/** A related region: this entity's records that refer to another record. */\nexport interface EntityCrudRelatedListProps<TEntity extends Entity> {\n /** Which records — those referring to the record whose page this is. Fixed, and shown as no chip. */\n readonly filtering: FilterGroup<TEntity>;\n /** Catalog key for the region's `h2`, and its entry in the page's section nav. */\n readonly labelKey: string;\n /**\n * The members a \"New\" from this region opens already set — the parent\n * record's id under the member that refers to it.\n */\n readonly prefill?: Readonly<Record<string, string>>;\n /** Where \"New\" goes, in place of this crud's create page with `prefill`. */\n readonly newHref?: string;\n readonly pageSize?: number;\n}\n\nexport interface EntityCrudOptions<TAdapters, TEntity extends Entity> {\n /** The domain shell's adapters hook, e.g. `useMarketplaceAdminAdapters`. */\n readonly useAdapters: () => TAdapters;\n /** Route prefix for both pages, e.g. `'/catalog/product-brand'`. */\n readonly basePath: string;\n /**\n * The entity's `entity` catalog key. Asserted against `@entity({ key })` at\n * factory time — the two are the same string by convention\n * (`entity:product-brand.label` mirrors `key: 'product-brand'`), and letting\n * them drift would title a form after a different entity.\n */\n readonly catalogKey: EntityCatalogKey;\n /** Which adapter holds this entity's own repository. */\n readonly repository: AdapterKey<TAdapters, Context<EntityRepositoryTag>>;\n /**\n * Members the form keeps but does not show — `id` always, plus anything a\n * transaction assigns. A hidden member still round-trips: it is dropped from\n * the rendered fields, not from the draft, so `reconstructEntity` carries it\n * back out of the seeded values.\n */\n readonly hiddenFields?: readonly string[];\n /** `<EntityColumn>` overrides for the list, for presentation metadata cannot express. */\n readonly columns?: ReactNode;\n /**\n * Extra controls beside the table's own — an `<EntityTableToolbar>`.\n *\n * Its own option rather than more `columns`, though both end up as\n * `EntityTable` children and the slots are sorted by component identity: a\n * toolbar filed under a columns prop is a name that lies, and the first thing\n * to go here is a link into a wizard, which is not a column by any reading.\n */\n readonly toolbar?: ReactNode;\n /**\n * How many rows the list asks for on its first load. Defaults to\n * `useDataLoading`'s own default.\n *\n * Raised for a vocabulary that should be seen whole: `EntityTable` nests a\n * hierarchy only within the page it was given, so a tree larger than one page\n * shows the children whose parent fell on another page as roots.\n */\n readonly pageSize?: number;\n /**\n * The filter the list opens with — a worklist, where the default view of a\n * record class is the rows someone has to act on. Shown in the filter panel\n * as the user's own, so it can be changed or cleared; unlike a link's\n * `useBaseFiltering`, it restricts nothing.\n *\n * Checked when the screen is generated against the same allowlist a service\n * applies to a query: a member that is not `filterable`, or a value of the\n * wrong type, throws here rather than answering `400` on every first load.\n */\n readonly initialFiltering?: FilterGroup<TEntity>;\n /**\n * How the record page's Delete is made safe\n * ([ADR 0026](../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)):\n * `confirm` (the default) asks in an alert dialog naming the record; `typed`\n * asks for its name to be typed first — for the records a fleet boots from;\n * `undo` deletes at once and offers Undo, which saves the record back under\n * its id, so it needs a store whose save puts a record back rather than\n * refusing an id it no longer holds.\n */\n readonly delete?: 'confirm' | 'undo' | 'typed';\n /** Frozen at factory time — see `use-entity-link-sources.ts`. */\n readonly links?: readonly EntityCrudLink<TAdapters, TEntity>[];\n /** Columns whose values live in another entity, read per page. */\n readonly related?: readonly EntityCrudRelated<TAdapters>[];\n /**\n * The records that refer to this one, as regions under its form — each\n * usually another crud's `RelatedList`, held to this record's id. Rendered\n * for an existing record only, never on create. Not master-detail: each\n * region writes its own records through its own owner, with its own Save,\n * and there is no page-wide Save across stores.\n */\n readonly regions?: (record: TEntity) => readonly ReactNode[];\n /**\n * Where the entity's served affordances come from — `GET /api/<entity>/$metadata`.\n *\n * Supplying it is what turns on every served affordance:\n * Save and Delete filtered against the caller's real grants, the declared\n * verbs on the form, the row overflow menu, and the bulk bar. Omitting it\n * keeps the pre-0026 behaviour exactly, which is what every generated catalog\n * rendered before this option existed.\n *\n * A `EntityMetadataSource` rather than a URL because the two hosts reach\n * their service differently — one through the config-driven REST adapters,\n * one through a shell's own same-origin routes.\n */\n readonly metadataSource?: EntityMetadataSource;\n /**\n * Which adapter holds this entity's {@link EntityMetadataSource} — the same\n * source as {@link metadataSource}, resolved from the host's composition\n * instead of built by the caller.\n *\n * Prefer it: a source is a transport, and naming it by key keeps the module\n * that generates the screens free of the adapter that fetches, exactly as\n * {@link repository} already does for records. Supplying both is a build\n * error — two answers to where the document comes from.\n */\n readonly metadata?: AdapterKey<TAdapters, EntityMetadataSource>;\n /**\n * Which adapter runs this entity's `@useCase()` verbs — over REST against\n * the service that serves them, or in-process for records that live in the\n * browser. Resolved from the host's composition, as {@link repository} is.\n *\n * Supplying it lets the generated screens run what the served `$metadata`\n * lists for the caller: a row's menu and a form's buttons run a verb on a\n * record, and the bulk bar runs a `collection` verb over a selection,\n * reporting per row. A verb that resolves reloads what it changed; one that\n * refuses shows its coded message in the screen's error slot rather than as\n * a promise nobody catches.\n */\n readonly useCases?: AdapterKey<TAdapters, EntityUseCaseRunner>;\n /**\n * Which adapter makes this entity's saves and deletes, answering both\n * settle modes — `buildEntityRestAdapterWrite` over REST. Resolved from the\n * host's composition, as {@link repository} is.\n *\n * Omitted, the form writes through {@link repository}, and every write\n * settles. Supplied, a write the server hands to a flow keeps the form open\n * and waiting, with what was typed, until the flow settles: a completed one\n * returns to the list, and a failed one is toasted once by the\n * `PendingFlowsProvider` above while the form keeps its input.\n */\n readonly write?: AdapterKey<TAdapters, EntityWriter>;\n\n /**\n * An adapter context providing `EntityFacetCounterTag` — the REST client's\n * facets adapter, typically. Supplied, the list's filter panel shows how\n * many records hold each choice of an enum or boolean member, counted under\n * the filters in effect less that member's own.\n */\n readonly facets?: AdapterKey<TAdapters, Context<EntityFacetCounterTag>>;\n}\n\n/**\n * Props both hosts pass. A route host passes none — the slug comes from the URL\n * and a save returns to the list; the workspace tab host passes all of them.\n */\nexport interface EntityCrudSingleViewProps {\n /** Defaults to the `[slug]` route param. */\n readonly slug?: string;\n /** Defaults to navigating back to the list. */\n readonly onSaved?: () => void;\n readonly onDeleted?: () => void;\n /**\n * Where to autosave the edit. Supplying it is the whole opt-in: the form\n * seeds from the persisted draft, writes to it on every edit, and the page\n * clears it once a save or delete commits.\n *\n * A route host omits it and stays ephemeral, which is the rule stated as a\n * missing prop rather than as a flag — there is no value of \"absent\" that\n * accidentally starts persisting.\n */\n readonly draft?: EntityDraftStore;\n}\n\n/**\n * What the factory returns: a **named descriptor**, not four loose components.\n *\n * The identity fields are here so the workspace registry and the nav are derived\n * from a list of these rather than from the hand-written const maps they replace.\n */\nexport interface EntityCrud<TEntity extends Entity> {\n readonly entityConstructor: EntityConstructor<TEntity>;\n /** `@entity({ key })`, which is also `catalogKey` and the tab address payload. */\n readonly entityKey: EntityCatalogKey;\n /**\n * `@entity({ labelKey })` — how one record is named. A record tab's title.\n *\n * Read off the decorator rather than passed, so the tab strip, the nav and the\n * search results all name the entity from the one place it names itself.\n */\n readonly entityLabelKey: string;\n /** `@entity({ pluralKey })` — how the collection is named. A list tab's title. */\n readonly entityPluralKey: string;\n readonly basePath: string;\n readonly ListPage: () => ReactElement;\n readonly SingleViewPage: (props?: EntityCrudSingleViewProps) => ReactElement;\n /** This entity's records referring to another record, as a region of that record's page. */\n readonly RelatedList: (\n props: EntityCrudRelatedListProps<TEntity>,\n ) => ReactElement;\n}\n\n/**\n * A picker's transport with its context tags erased.\n *\n * The factory cannot preserve one type parameter per link — the pages that\n * build these know their adapters, the generated form only forwards them — and\n * `EntityForm.linkSources` is already `Record<string, EntityLinkSource<any>>`\n * for the same reason.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyEntityLinkSourceConfig = EntityLinkSourceConfig<Entity, any>;\n\n/**\n * One picker, resolved: the descriptor computed once at factory time, and the\n * use-cases plus adapter context the page builds per render.\n */\nexport interface EntityCrudLinkSource {\n readonly field: string;\n readonly descriptor: EntityFieldDescriptor;\n readonly config: AnyEntityLinkSourceConfig;\n}\n"],"names":[],"mappings":"AAmZA;;;CAGC,GACD,WAIC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ReferenceLabelRegistration } from '@entifix/business';
|
|
2
|
+
import { type ReactNode } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Reads the names of the records a screen refers to by id, and publishes them
|
|
5
|
+
* to the controls
|
|
6
|
+
* ([ADR 0030](../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)).
|
|
7
|
+
*
|
|
8
|
+
* Mounted **once by the host**, beside its other providers, with one
|
|
9
|
+
* registration per target entity — `[Constructor, repositoryContext,
|
|
10
|
+
* { labelProperty? }]` — because only the host has every target's adapter in
|
|
11
|
+
* reach. Keep `registrations` stable (a module constant or a `useMemo`).
|
|
12
|
+
*
|
|
13
|
+
* Every id a render asks for is collected and, after that commit, read in
|
|
14
|
+
* **one request per target entity**. Each label is cached per id under the
|
|
15
|
+
* target's own query scope, so a record's page reuses what its list read, and
|
|
16
|
+
* an invalidation of the target — a save, a pushed change — refreshes it.
|
|
17
|
+
*
|
|
18
|
+
* A reference to an entity no registration reads shows its raw id, muted, and
|
|
19
|
+
* `onUnregistered` is told its key once — the host decides whether that is a
|
|
20
|
+
* development warning; this mechanism does not log.
|
|
21
|
+
*/
|
|
22
|
+
export declare function ReferenceLabelsHost({ registrations, onUnregistered, children, }: {
|
|
23
|
+
registrations: ReadonlyArray<ReferenceLabelRegistration>;
|
|
24
|
+
onUnregistered?: (entityKey: string) => void;
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
}): import("react").JSX.Element;
|
|
27
|
+
//# sourceMappingURL=reference-labels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference-labels.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/reference-labels.tsx"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,0BAA0B,EAEhC,MAAM,mBAAmB,CAAC;AAc3B,OAAO,EAAE,KAAK,SAAS,EAA6B,MAAM,OAAO,CAAC;AAclE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,aAAa,EACb,cAAc,EACd,QAAQ,GACT,EAAE;IACD,aAAa,EAAE,aAAa,CAAC,0BAA0B,CAAC,CAAC;IACzD,cAAc,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,QAAQ,EAAE,SAAS,CAAC;CACrB,+BA+GA"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createReferenceLabels, ReferenceLabelsTag } from '@entifix/business';
|
|
4
|
+
import { extractMetaEntity } from '@entifix/core';
|
|
5
|
+
import { ReferenceLabelsProvider } from '@entifix/react-controls';
|
|
6
|
+
import { entityQueryScope } from '@entifix/react-integration';
|
|
7
|
+
import { useQueries, useQueryClient } from '@tanstack/react-query';
|
|
8
|
+
import { Context, Effect } from 'effect';
|
|
9
|
+
import { useMemo, useRef, useState } from 'react';
|
|
10
|
+
/**
|
|
11
|
+
* Reads the names of the records a screen refers to by id, and publishes them
|
|
12
|
+
* to the controls
|
|
13
|
+
* ([ADR 0030](../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)).
|
|
14
|
+
*
|
|
15
|
+
* Mounted **once by the host**, beside its other providers, with one
|
|
16
|
+
* registration per target entity — `[Constructor, repositoryContext,
|
|
17
|
+
* { labelProperty? }]` — because only the host has every target's adapter in
|
|
18
|
+
* reach. Keep `registrations` stable (a module constant or a `useMemo`).
|
|
19
|
+
*
|
|
20
|
+
* Every id a render asks for is collected and, after that commit, read in
|
|
21
|
+
* **one request per target entity**. Each label is cached per id under the
|
|
22
|
+
* target's own query scope, so a record's page reuses what its list read, and
|
|
23
|
+
* an invalidation of the target — a save, a pushed change — refreshes it.
|
|
24
|
+
*
|
|
25
|
+
* A reference to an entity no registration reads shows its raw id, muted, and
|
|
26
|
+
* `onUnregistered` is told its key once — the host decides whether that is a
|
|
27
|
+
* development warning; this mechanism does not log.
|
|
28
|
+
*/ export function ReferenceLabelsHost({ registrations, onUnregistered, children }) {
|
|
29
|
+
const labels = useMemo(()=>Context.get(createReferenceLabels(registrations), ReferenceLabelsTag), [
|
|
30
|
+
registrations
|
|
31
|
+
]);
|
|
32
|
+
const queryClient = useQueryClient();
|
|
33
|
+
/** Ids a render asked for that no batch holds yet, by entity key. */ const asked = useRef(new Map());
|
|
34
|
+
const [batches, setBatches] = useState([]);
|
|
35
|
+
const results = useQueries({
|
|
36
|
+
queries: batches.map((batch)=>{
|
|
37
|
+
const entityConstructor = labels.entities.get(batch.entityKey);
|
|
38
|
+
return {
|
|
39
|
+
queryKey: [
|
|
40
|
+
...entityQueryScope(entityConstructor),
|
|
41
|
+
'reference-label-batch',
|
|
42
|
+
batch.ids
|
|
43
|
+
],
|
|
44
|
+
queryFn: ()=>Effect.runPromise(labels.resolve(batch.entityKey, batch.ids)).then((found)=>{
|
|
45
|
+
for (const id of batch.ids){
|
|
46
|
+
var _found_get;
|
|
47
|
+
queryClient.setQueryData(labelKey(entityConstructor, id), (_found_get = found.get(id)) != null ? _found_get : null);
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
})
|
|
51
|
+
};
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
/** The unregistered keys `onUnregistered` was already told about. */ const reported = useRef(new Set());
|
|
55
|
+
/** Whether a flush of what renders asked for is already queued. */ const scheduled = useRef(false);
|
|
56
|
+
/**
|
|
57
|
+
* Turns everything renders asked for into one batch per target entity. Run
|
|
58
|
+
* as a microtask once the render that asked has returned — a reader re-renders
|
|
59
|
+
* on its own when its rows arrive, without this host rendering at all, so
|
|
60
|
+
* waiting for this host's commit would wait forever. A render only asks for an
|
|
61
|
+
* id nothing has cached and no batch is reading or has failed on, so the same
|
|
62
|
+
* id is never read twice.
|
|
63
|
+
*/ const flush = ()=>{
|
|
64
|
+
scheduled.current = false;
|
|
65
|
+
const next = [
|
|
66
|
+
...asked.current
|
|
67
|
+
].map(([entityKey, ids])=>({
|
|
68
|
+
entityKey,
|
|
69
|
+
ids: [
|
|
70
|
+
...ids
|
|
71
|
+
].sort()
|
|
72
|
+
}));
|
|
73
|
+
asked.current.clear();
|
|
74
|
+
setBatches((previous)=>[
|
|
75
|
+
...previous,
|
|
76
|
+
...next
|
|
77
|
+
]);
|
|
78
|
+
};
|
|
79
|
+
const failedBatches = batches.filter((_, index)=>{
|
|
80
|
+
var _results_index;
|
|
81
|
+
return (_results_index = results[index]) == null ? void 0 : _results_index.isError;
|
|
82
|
+
});
|
|
83
|
+
const pendingBatches = batches.filter((_, index)=>{
|
|
84
|
+
var _results_index;
|
|
85
|
+
return ((_results_index = results[index]) == null ? void 0 : _results_index.isPending) !== false;
|
|
86
|
+
});
|
|
87
|
+
const dataStamp = results.map((result)=>`${result.status}${result.dataUpdatedAt}`).join(',');
|
|
88
|
+
const lookup = useMemo(()=>({
|
|
89
|
+
label (entityKey, id) {
|
|
90
|
+
const entityConstructor = labels.entities.get(entityKey);
|
|
91
|
+
if (entityConstructor === undefined) {
|
|
92
|
+
if (!reported.current.has(entityKey)) {
|
|
93
|
+
reported.current.add(entityKey);
|
|
94
|
+
onUnregistered == null ? void 0 : onUnregistered(entityKey);
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
status: 'unregistered'
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const cached = readLabel(queryClient, entityConstructor, id);
|
|
101
|
+
if (cached !== undefined) return cached;
|
|
102
|
+
const holds = (batch)=>batch.entityKey === entityKey && batch.ids.includes(id);
|
|
103
|
+
if (failedBatches.some(holds)) return {
|
|
104
|
+
status: 'failed'
|
|
105
|
+
};
|
|
106
|
+
if (pendingBatches.some(holds)) return {
|
|
107
|
+
status: 'resolving'
|
|
108
|
+
};
|
|
109
|
+
let ids = asked.current.get(entityKey);
|
|
110
|
+
if (ids === undefined) {
|
|
111
|
+
ids = new Set();
|
|
112
|
+
asked.current.set(entityKey, ids);
|
|
113
|
+
}
|
|
114
|
+
ids.add(id);
|
|
115
|
+
if (!scheduled.current) {
|
|
116
|
+
scheduled.current = true;
|
|
117
|
+
queueMicrotask(flush);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
status: 'resolving'
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
noun (entityKey) {
|
|
124
|
+
const entityConstructor = labels.entities.get(entityKey);
|
|
125
|
+
return entityConstructor === undefined ? undefined : extractMetaEntity(entityConstructor);
|
|
126
|
+
}
|
|
127
|
+
}), // A new lookup whenever a batch starts, lands or fails — what the stamp
|
|
128
|
+
// tracks — so every reader re-renders.
|
|
129
|
+
[
|
|
130
|
+
labels,
|
|
131
|
+
queryClient,
|
|
132
|
+
dataStamp,
|
|
133
|
+
batches,
|
|
134
|
+
onUnregistered
|
|
135
|
+
]);
|
|
136
|
+
return /*#__PURE__*/ _jsx(ReferenceLabelsProvider, {
|
|
137
|
+
lookup: lookup,
|
|
138
|
+
children: children
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function labelKey(entityConstructor, id) {
|
|
142
|
+
return [
|
|
143
|
+
...entityQueryScope(entityConstructor),
|
|
144
|
+
'reference-label',
|
|
145
|
+
id
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
/** A cached label's state, or `undefined` when nothing is cached for the id yet. */ function readLabel(queryClient, entityConstructor, id) {
|
|
149
|
+
const state = queryClient.getQueryState(labelKey(entityConstructor, id));
|
|
150
|
+
if ((state == null ? void 0 : state.status) !== 'success') return undefined;
|
|
151
|
+
return state.data === null || state.data === undefined ? {
|
|
152
|
+
status: 'notFound'
|
|
153
|
+
} : {
|
|
154
|
+
status: 'named',
|
|
155
|
+
label: state.data
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
//# sourceMappingURL=reference-labels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/crud/reference-labels.tsx"],"sourcesContent":["'use client';\n\nimport {\n createReferenceLabels,\n type ReferenceLabel,\n type ReferenceLabelRegistration,\n ReferenceLabelsTag,\n} from '@entifix/business';\nimport { extractMetaEntity } from '@entifix/core';\nimport {\n type ReferenceLabelLookup,\n ReferenceLabelsProvider,\n type ReferenceLabelState,\n} from '@entifix/react-controls';\nimport { entityQueryScope } from '@entifix/react-integration';\nimport {\n type QueryClient,\n useQueries,\n useQueryClient,\n} from '@tanstack/react-query';\nimport { Context, Effect } from 'effect';\nimport { type ReactNode, useMemo, useRef, useState } from 'react';\n\n/** One read: the ids of one target entity a commit asked for and nothing had cached. */\ninterface Batch {\n readonly entityKey: string;\n readonly ids: readonly string[];\n}\n\n/**\n * What the per-id cache holds for a record: its label, or `null` for an id no\n * record answered — so a miss is remembered as one, not asked for again.\n */\ntype CachedLabel = ReferenceLabel | null;\n\n/**\n * Reads the names of the records a screen refers to by id, and publishes them\n * to the controls\n * ([ADR 0030](../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)).\n *\n * Mounted **once by the host**, beside its other providers, with one\n * registration per target entity — `[Constructor, repositoryContext,\n * { labelProperty? }]` — because only the host has every target's adapter in\n * reach. Keep `registrations` stable (a module constant or a `useMemo`).\n *\n * Every id a render asks for is collected and, after that commit, read in\n * **one request per target entity**. Each label is cached per id under the\n * target's own query scope, so a record's page reuses what its list read, and\n * an invalidation of the target — a save, a pushed change — refreshes it.\n *\n * A reference to an entity no registration reads shows its raw id, muted, and\n * `onUnregistered` is told its key once — the host decides whether that is a\n * development warning; this mechanism does not log.\n */\nexport function ReferenceLabelsHost({\n registrations,\n onUnregistered,\n children,\n}: {\n registrations: ReadonlyArray<ReferenceLabelRegistration>;\n onUnregistered?: (entityKey: string) => void;\n children: ReactNode;\n}) {\n const labels = useMemo(\n () => Context.get(createReferenceLabels(registrations), ReferenceLabelsTag),\n [registrations],\n );\n const queryClient = useQueryClient();\n /** Ids a render asked for that no batch holds yet, by entity key. */\n const asked = useRef(new Map<string, Set<string>>());\n const [batches, setBatches] = useState<readonly Batch[]>([]);\n\n const results = useQueries({\n queries: batches.map(batch => {\n const entityConstructor = labels.entities.get(batch.entityKey);\n return {\n queryKey: [\n ...entityQueryScope(entityConstructor as never),\n 'reference-label-batch',\n batch.ids,\n ],\n queryFn: () =>\n Effect.runPromise(labels.resolve(batch.entityKey, batch.ids)).then(\n found => {\n for (const id of batch.ids) {\n queryClient.setQueryData<CachedLabel>(\n labelKey(entityConstructor, id),\n found.get(id) ?? null,\n );\n }\n return true;\n },\n ),\n };\n }),\n });\n\n /** The unregistered keys `onUnregistered` was already told about. */\n const reported = useRef(new Set<string>());\n /** Whether a flush of what renders asked for is already queued. */\n const scheduled = useRef(false);\n /**\n * Turns everything renders asked for into one batch per target entity. Run\n * as a microtask once the render that asked has returned — a reader re-renders\n * on its own when its rows arrive, without this host rendering at all, so\n * waiting for this host's commit would wait forever. A render only asks for an\n * id nothing has cached and no batch is reading or has failed on, so the same\n * id is never read twice.\n */\n const flush = () => {\n scheduled.current = false;\n const next = [...asked.current].map(([entityKey, ids]) => ({\n entityKey,\n ids: [...ids].sort(),\n }));\n asked.current.clear();\n setBatches(previous => [...previous, ...next]);\n };\n\n const failedBatches = batches.filter((_, index) => results[index]?.isError);\n const pendingBatches = batches.filter(\n (_, index) => results[index]?.isPending !== false,\n );\n const dataStamp = results\n .map(result => `${result.status}${result.dataUpdatedAt}`)\n .join(',');\n\n const lookup = useMemo<ReferenceLabelLookup>(\n () => ({\n label(entityKey, id) {\n const entityConstructor = labels.entities.get(entityKey);\n if (entityConstructor === undefined) {\n if (!reported.current.has(entityKey)) {\n reported.current.add(entityKey);\n onUnregistered?.(entityKey);\n }\n return { status: 'unregistered' };\n }\n const cached = readLabel(queryClient, entityConstructor, id);\n if (cached !== undefined) return cached;\n const holds = (batch: Batch) =>\n batch.entityKey === entityKey && batch.ids.includes(id);\n if (failedBatches.some(holds)) return { status: 'failed' };\n if (pendingBatches.some(holds)) return { status: 'resolving' };\n let ids = asked.current.get(entityKey);\n if (ids === undefined) {\n ids = new Set();\n asked.current.set(entityKey, ids);\n }\n ids.add(id);\n if (!scheduled.current) {\n scheduled.current = true;\n queueMicrotask(flush);\n }\n return { status: 'resolving' };\n },\n noun(entityKey) {\n const entityConstructor = labels.entities.get(entityKey);\n return entityConstructor === undefined\n ? undefined\n : extractMetaEntity(entityConstructor);\n },\n }),\n // A new lookup whenever a batch starts, lands or fails — what the stamp\n // tracks — so every reader re-renders.\n [labels, queryClient, dataStamp, batches, onUnregistered],\n );\n\n return (\n <ReferenceLabelsProvider lookup={lookup}>\n {children}\n </ReferenceLabelsProvider>\n );\n}\n\nfunction labelKey(entityConstructor: unknown, id: string) {\n return [\n ...entityQueryScope(entityConstructor as never),\n 'reference-label',\n id,\n ];\n}\n\n/** A cached label's state, or `undefined` when nothing is cached for the id yet. */\nfunction readLabel(\n queryClient: QueryClient,\n entityConstructor: unknown,\n id: string,\n): ReferenceLabelState | undefined {\n const state = queryClient.getQueryState<CachedLabel>(\n labelKey(entityConstructor, id),\n );\n if (state?.status !== 'success') return undefined;\n return state.data === null || state.data === undefined\n ? { status: 'notFound' }\n : { status: 'named', label: state.data };\n}\n"],"names":["createReferenceLabels","ReferenceLabelsTag","extractMetaEntity","ReferenceLabelsProvider","entityQueryScope","useQueries","useQueryClient","Context","Effect","useMemo","useRef","useState","ReferenceLabelsHost","registrations","onUnregistered","children","labels","get","queryClient","asked","Map","batches","setBatches","results","queries","map","batch","entityConstructor","entities","entityKey","queryKey","ids","queryFn","runPromise","resolve","then","found","id","setQueryData","labelKey","reported","Set","scheduled","flush","current","next","sort","clear","previous","failedBatches","filter","_","index","isError","pendingBatches","isPending","dataStamp","result","status","dataUpdatedAt","join","lookup","label","undefined","has","add","cached","readLabel","holds","includes","some","set","queueMicrotask","noun","state","getQueryState","data"],"mappings":"AAAA;;AAEA,SACEA,qBAAqB,EAGrBC,kBAAkB,QACb,oBAAoB;AAC3B,SAASC,iBAAiB,QAAQ,gBAAgB;AAClD,SAEEC,uBAAuB,QAElB,0BAA0B;AACjC,SAASC,gBAAgB,QAAQ,6BAA6B;AAC9D,SAEEC,UAAU,EACVC,cAAc,QACT,wBAAwB;AAC/B,SAASC,OAAO,EAAEC,MAAM,QAAQ,SAAS;AACzC,SAAyBC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAclE;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,SAASC,oBAAoB,EAClCC,aAAa,EACbC,cAAc,EACdC,QAAQ,EAKT;IACC,MAAMC,SAASP,QACb,IAAMF,QAAQU,GAAG,CAACjB,sBAAsBa,gBAAgBZ,qBACxD;QAACY;KAAc;IAEjB,MAAMK,cAAcZ;IACpB,mEAAmE,GACnE,MAAMa,QAAQT,OAAO,IAAIU;IACzB,MAAM,CAACC,SAASC,WAAW,GAAGX,SAA2B,EAAE;IAE3D,MAAMY,UAAUlB,WAAW;QACzBmB,SAASH,QAAQI,GAAG,CAACC,CAAAA;YACnB,MAAMC,oBAAoBX,OAAOY,QAAQ,CAACX,GAAG,CAACS,MAAMG,SAAS;YAC7D,OAAO;gBACLC,UAAU;uBACL1B,iBAAiBuB;oB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EAAEU,EAAU;IACtD,OAAO;WACFjC,iBAAiBuB;QACpB;QACAU;KACD;AACH;AAEA,kFAAkF,GAClF,SAAS8B,UACPjD,WAAwB,EACxBS,iBAA0B,EAC1BU,EAAU;IAEV,MAAMqC,QAAQxD,YAAYyD,aAAa,CACrCpC,SAASZ,mBAAmBU;IAE9B,IAAIqC,CAAAA,yBAAAA,MAAOhB,MAAM,MAAK,WAAW,OAAOK;IACxC,OAAOW,MAAME,IAAI,KAAK,QAAQF,MAAME,IAAI,KAAKb,YACzC;QAAEL,QAAQ;IAAW,IACrB;QAAEA,QAAQ;QAASI,OAAOY,MAAME,IAAI;IAAC;AAC3C"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { EntityDraft, EntityFieldDescriptor } from '@entifix/core';
|
|
2
|
+
import { type ReactNode } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* The query parameter prefix a create page reads a member's starting value
|
|
5
|
+
* from — `?prefill.customerId=c-1` — so a related region's "New" opens with
|
|
6
|
+
* the parent record already set.
|
|
7
|
+
*/
|
|
8
|
+
export declare const PREFILL_PARAM = "prefill.";
|
|
9
|
+
/**
|
|
10
|
+
* A create page's starting values from its query string: only declared,
|
|
11
|
+
* writable members, and only as the strings a draft holds. Anything else in
|
|
12
|
+
* the query is ignored rather than written into a record.
|
|
13
|
+
*/
|
|
14
|
+
export declare function readPrefill(params: URLSearchParams | null | undefined, descriptors: readonly EntityFieldDescriptor[]): EntityDraft | undefined;
|
|
15
|
+
/** Lists a region in the record page's section nav while it is mounted. */
|
|
16
|
+
export declare function useRegion(id: string, heading: string): void;
|
|
17
|
+
/**
|
|
18
|
+
* The regions under a record's form, and — once there are two or more — a
|
|
19
|
+
* section nav above them, a `nav` landmark whose anchors mark the region in
|
|
20
|
+
* view. Composes what exists: no new organism.
|
|
21
|
+
*/
|
|
22
|
+
export declare function RecordRegions({ children }: {
|
|
23
|
+
children: ReactNode;
|
|
24
|
+
}): import("react").JSX.Element;
|
|
25
|
+
//# sourceMappingURL=regions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regions.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/regions.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,EAEL,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AAEf;;;;GAIG;AACH,eAAO,MAAM,aAAa,aAAa,CAAC;AAExC;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,EAC1C,WAAW,EAAE,SAAS,qBAAqB,EAAE,GAC5C,WAAW,GAAG,SAAS,CAUzB;AAWD,2EAA2E;AAC3E,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAG3D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,+BAiClE"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { ActiveSection, linkClassName, useT } from '@entifix/react-controls';
|
|
4
|
+
import { createContext, useCallback, useContext, useLayoutEffect, useMemo, useState } from 'react';
|
|
5
|
+
/**
|
|
6
|
+
* The query parameter prefix a create page reads a member's starting value
|
|
7
|
+
* from — `?prefill.customerId=c-1` — so a related region's "New" opens with
|
|
8
|
+
* the parent record already set.
|
|
9
|
+
*/ export const PREFILL_PARAM = 'prefill.';
|
|
10
|
+
/**
|
|
11
|
+
* A create page's starting values from its query string: only declared,
|
|
12
|
+
* writable members, and only as the strings a draft holds. Anything else in
|
|
13
|
+
* the query is ignored rather than written into a record.
|
|
14
|
+
*/ export function readPrefill(params, descriptors) {
|
|
15
|
+
const values = {};
|
|
16
|
+
for (const [name, value] of params != null ? params : []){
|
|
17
|
+
if (!name.startsWith(PREFILL_PARAM)) continue;
|
|
18
|
+
const member = name.slice(PREFILL_PARAM.length);
|
|
19
|
+
const descriptor = descriptors.find((entry)=>entry.name === member);
|
|
20
|
+
if (descriptor === undefined || descriptor.readonly) continue;
|
|
21
|
+
values[member] = value;
|
|
22
|
+
}
|
|
23
|
+
return Object.keys(values).length === 0 ? undefined : values;
|
|
24
|
+
}
|
|
25
|
+
const RegionsContext = /*#__PURE__*/ createContext(undefined);
|
|
26
|
+
/** Lists a region in the record page's section nav while it is mounted. */ export function useRegion(id, heading) {
|
|
27
|
+
const register = useContext(RegionsContext);
|
|
28
|
+
useLayoutEffect(()=>register == null ? void 0 : register({
|
|
29
|
+
id,
|
|
30
|
+
heading
|
|
31
|
+
}), [
|
|
32
|
+
register,
|
|
33
|
+
id,
|
|
34
|
+
heading
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The regions under a record's form, and — once there are two or more — a
|
|
39
|
+
* section nav above them, a `nav` landmark whose anchors mark the region in
|
|
40
|
+
* view. Composes what exists: no new organism.
|
|
41
|
+
*/ export function RecordRegions({ children }) {
|
|
42
|
+
const t = useT('shell');
|
|
43
|
+
const [regions, setRegions] = useState([]);
|
|
44
|
+
const register = useCallback((region)=>{
|
|
45
|
+
setRegions((current)=>[
|
|
46
|
+
...current,
|
|
47
|
+
region
|
|
48
|
+
]);
|
|
49
|
+
return ()=>setRegions((current)=>current.filter((entry)=>entry.id !== region.id));
|
|
50
|
+
}, []);
|
|
51
|
+
const ids = useMemo(()=>regions.map((region)=>region.id), [
|
|
52
|
+
regions
|
|
53
|
+
]);
|
|
54
|
+
return /*#__PURE__*/ _jsxs(RegionsContext.Provider, {
|
|
55
|
+
value: register,
|
|
56
|
+
children: [
|
|
57
|
+
regions.length >= 2 && /*#__PURE__*/ _jsxs("nav", {
|
|
58
|
+
"aria-label": t('regions.nav'),
|
|
59
|
+
children: [
|
|
60
|
+
/*#__PURE__*/ _jsx("ul", {
|
|
61
|
+
role: "list",
|
|
62
|
+
className: "m-0 p-0 flex list-none flex-wrap gap-s",
|
|
63
|
+
children: regions.map((region)=>/*#__PURE__*/ _jsx("li", {
|
|
64
|
+
children: /*#__PURE__*/ _jsx("a", {
|
|
65
|
+
href: `#${region.id}`,
|
|
66
|
+
"data-section": region.id,
|
|
67
|
+
className: linkClassName,
|
|
68
|
+
children: region.heading
|
|
69
|
+
})
|
|
70
|
+
}, region.id))
|
|
71
|
+
}),
|
|
72
|
+
/*#__PURE__*/ _jsx(ActiveSection, {
|
|
73
|
+
sections: ids
|
|
74
|
+
})
|
|
75
|
+
]
|
|
76
|
+
}),
|
|
77
|
+
children
|
|
78
|
+
]
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=regions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/crud/regions.tsx"],"sourcesContent":["'use client';\n\nimport type { EntityDraft, EntityFieldDescriptor } from '@entifix/core';\nimport { ActiveSection, linkClassName, useT } from '@entifix/react-controls';\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useLayoutEffect,\n useMemo,\n useState,\n} from 'react';\n\n/**\n * The query parameter prefix a create page reads a member's starting value\n * from — `?prefill.customerId=c-1` — so a related region's \"New\" opens with\n * the parent record already set.\n */\nexport const PREFILL_PARAM = 'prefill.';\n\n/**\n * A create page's starting values from its query string: only declared,\n * writable members, and only as the strings a draft holds. Anything else in\n * the query is ignored rather than written into a record.\n */\nexport function readPrefill(\n params: URLSearchParams | null | undefined,\n descriptors: readonly EntityFieldDescriptor[],\n): EntityDraft | undefined {\n const values: Record<string, string> = {};\n for (const [name, value] of params ?? []) {\n if (!name.startsWith(PREFILL_PARAM)) continue;\n const member = name.slice(PREFILL_PARAM.length);\n const descriptor = descriptors.find(entry => entry.name === member);\n if (descriptor === undefined || descriptor.readonly) continue;\n values[member] = value;\n }\n return Object.keys(values).length === 0 ? undefined : values;\n}\n\ninterface Region {\n readonly id: string;\n readonly heading: string;\n}\n\nconst RegionsContext = createContext<\n ((region: Region) => () => void) | undefined\n>(undefined);\n\n/** Lists a region in the record page's section nav while it is mounted. */\nexport function useRegion(id: string, heading: string): void {\n const register = useContext(RegionsContext);\n useLayoutEffect(() => register?.({ id, heading }), [register, id, heading]);\n}\n\n/**\n * The regions under a record's form, and — once there are two or more — a\n * section nav above them, a `nav` landmark whose anchors mark the region in\n * view. Composes what exists: no new organism.\n */\nexport function RecordRegions({ children }: { children: ReactNode }) {\n const t = useT('shell');\n const [regions, setRegions] = useState<readonly Region[]>([]);\n const register = useCallback((region: Region) => {\n setRegions(current => [...current, region]);\n return () =>\n setRegions(current => current.filter(entry => entry.id !== region.id));\n }, []);\n const ids = useMemo(() => regions.map(region => region.id), [regions]);\n\n return (\n <RegionsContext.Provider value={register}>\n {regions.length >= 2 && (\n <nav aria-label={t('regions.nav')}>\n <ul role=\"list\" className=\"m-0 p-0 flex list-none flex-wrap gap-s\">\n {regions.map(region => (\n <li key={region.id}>\n <a\n href={`#${region.id}`}\n data-section={region.id}\n className={linkClassName}\n >\n {region.heading}\n </a>\n </li>\n ))}\n </ul>\n <ActiveSection sections={ids} />\n </nav>\n )}\n {children}\n </RegionsContext.Provider>\n );\n}\n"],"names":["ActiveSection","linkClassName","useT","createContext","useCallback","useContext","useLayoutEffect","useMemo","useState","PREFILL_PARAM","readPrefill","params","descriptors","values","name","value","startsWith","member","slice","length","descriptor","find","entry","undefined","readonly","Object","keys","RegionsContext","useRegion","id","heading","register","RecordRegions","children","t","regions","setRegions","region","current","filter","ids","map","Provider","nav","aria-label","ul","role","className","li","a","href","data-section","sections"],"mappings":"AAAA;;AAGA,SAASA,aAAa,EAAEC,aAAa,EAAEC,IAAI,QAAQ,0BAA0B;AAC7E,SACEC,aAAa,EAEbC,WAAW,EACXC,UAAU,EACVC,eAAe,EACfC,OAAO,EAC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;QAACM;KAAQ;IAErE,qBACE,MAACR,eAAee,QAAQ;QAAC3B,OAAOgB;;YAC7BI,QAAQhB,MAAM,IAAI,mBACjB,MAACwB;gBAAIC,cAAYV,EAAE;;kCACjB,KAACW;wBAAGC,MAAK;wBAAOC,WAAU;kCACvBZ,QAAQM,GAAG,CAACJ,CAAAA,uBACX,KAACW;0CACC,cAAA,KAACC;oCACCC,MAAM,CAAC,CAAC,EAAEb,OAAOR,EAAE,EAAE;oCACrBsB,gBAAcd,OAAOR,EAAE;oCACvBkB,WAAW9C;8CAEVoC,OAAOP,OAAO;;+BANVO,OAAOR,EAAE;;kCAWtB,KAAC7B;wBAAcoD,UAAUZ;;;;YAG5BP;;;AAGP"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type EntityRepositoryTag } from '@entifix/business';
|
|
2
|
+
import { type Entity, type EntityConstructor, type EntityFieldDescriptor } from '@entifix/core';
|
|
3
|
+
import { Context } from 'effect';
|
|
4
|
+
import type { ReactElement } from 'react';
|
|
5
|
+
import type { EntityCrudRelated } from './make-entity-crud.types.js';
|
|
6
|
+
/**
|
|
7
|
+
* How many matches one related read asks for. A page names far fewer for a
|
|
8
|
+
* `via` column; a `match` column whose records hold more than this per page
|
|
9
|
+
* reads as the count of those it got.
|
|
10
|
+
*/
|
|
11
|
+
export declare const RELATED_PAGE_SIZE = 200;
|
|
12
|
+
/** A related column, checked when the screen is generated. */
|
|
13
|
+
export interface RelatedPlan<TAdapters> extends EntityCrudRelated<TAdapters> {
|
|
14
|
+
/** The target member's descriptor: what a match's value reads as. */
|
|
15
|
+
readonly descriptor: EntityFieldDescriptor;
|
|
16
|
+
readonly entityKey: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Checks every related column against both entities' metadata, so a mistake
|
|
20
|
+
* throws when the screen is generated rather than answering `400` per page.
|
|
21
|
+
*/
|
|
22
|
+
export declare function planRelated<TAdapters>(entityConstructor: EntityConstructor<Entity>, descriptors: readonly EntityFieldDescriptor[], related: readonly EntityCrudRelated<TAdapters>[]): RelatedPlan<TAdapters>[];
|
|
23
|
+
/**
|
|
24
|
+
* One column per related plan, its values read for the page's items in one
|
|
25
|
+
* request per column — keyed under the target's own query scope, so a write
|
|
26
|
+
* to the target refreshes it.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useRelatedColumns<TAdapters, TEntity extends Entity>(plans: readonly RelatedPlan<TAdapters>[], items: readonly TEntity[], repositoryOf: (plan: RelatedPlan<TAdapters>) => Context.Context<EntityRepositoryTag>): ReactElement[];
|
|
29
|
+
//# sourceMappingURL=related-columns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"related-columns.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/related-columns.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,mBAAmB,EAEzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAM3B,MAAM,eAAe,CAAC;AAUvB,OAAO,EAAE,OAAO,EAAU,MAAM,QAAQ,CAAC;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC,8DAA8D;AAC9D,MAAM,WAAW,WAAW,CAAC,SAAS,CAAE,SAAQ,iBAAiB,CAAC,SAAS,CAAC;IAC1E,qEAAqE;IACrE,QAAQ,CAAC,UAAU,EAAE,qBAAqB,CAAC;IAC3C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,SAAS,EACnC,iBAAiB,EAAE,iBAAiB,CAAC,MAAM,CAAC,EAC5C,WAAW,EAAE,SAAS,qBAAqB,EAAE,EAC7C,OAAO,EAAE,SAAS,iBA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