@entifix/next-shell 0.23.9 → 0.23.11
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/crud/make-entity-crud.types.d.ts +5 -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/use-entity-link-sources.d.ts.map +1 -1
- package/dist/lib/crud/use-entity-link-sources.js +4 -1
- package/dist/lib/crud/use-entity-link-sources.js.map +1 -1
- package/package.json +9 -9
|
@@ -74,7 +74,11 @@ type EntityCatalogOf<TResources> = TResources extends {
|
|
|
74
74
|
* as an empty suggestion list.
|
|
75
75
|
*/
|
|
76
76
|
export interface EntityCrudLink<TAdapters, TEntity extends Entity = Entity> {
|
|
77
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* The owning entity's accessor name, e.g. `'brandId'`: a `link`, a `string`
|
|
79
|
+
* foreign key, or a `scalarCollection` that declares `references` — a list
|
|
80
|
+
* of ids, edited one name at a time.
|
|
81
|
+
*/
|
|
78
82
|
readonly field: string;
|
|
79
83
|
readonly entityConstructor: EntityConstructor<Entity>;
|
|
80
84
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-entity-crud.types.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/make-entity-crud.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,MAAM,EACN,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,WAAW,EACZ,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,gBAAgB,CAC1B,cAAc,GAAG,eAAe,CAAC,oBAAoB,CAAC,IACpD,CAAC,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,GAIhC,MAAM,GACN;KACG,CAAC,IAAI,MAAM,cAAc,GAAG,cAAc,CAAC,CAAC,CAAC,SAAS;QACrD,IAAI,EAAE;YAAE,SAAS,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC;QAC9C,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,GACG,CAAC,GACD,KAAK;CACV,CAAC,MAAM,cAAc,CAAC,GACrB,MAAM,CAAC;AAEb;;;;;;;;;;;GAWG;AACH,KAAK,oBAAoB,GAAG,iBAAiB,SAAS;IAAE,SAAS,EAAE,MAAM,CAAC,CAAA;CAAE,GACxE,CAAC,GACD,KAAK,CAAC;AAEV,KAAK,eAAe,CAAC,UAAU,IAAI,UAAU,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GACrE,CAAC,GACD,KAAK,CAAC;AAEV;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,cAAc,CAAC,SAAS,EAAE,OAAO,SAAS,MAAM,GAAG,MAAM;IACxE
|
|
1
|
+
{"version":3,"file":"make-entity-crud.types.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/make-entity-crud.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,MAAM,EACN,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,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AC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5C;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;AAED,6EAA6E;AAC7E,MAAM,WAAW,mBAAmB,CAAC,OAAO,SAAS,MAAM;IACzD,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,2EAA2E;IAC3E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,yEAAyE;IACzE,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC7C"}
|
|
@@ -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 EntitySorting,\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 EntityCrudSuppliedRepository {\n /**\n * A hook returning the target's repository, called inside the crud's render\n * tree on every render — so a provider the host mounts above it (another\n * slice's adapters) resolves it. Same read plan as an adapter key: one read\n * per page.\n */\n readonly useRepository: () => Context<EntityRepositoryTag>;\n}\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 /**\n * Where the target's repository comes from: the key of one of this crud's\n * own adapters, or — when the target lives in another slice, whose adapter\n * this shell may not build — a repository the host supplies.\n */\n readonly repository:\n | AdapterKey<TAdapters, Context<EntityRepositoryTag>>\n | EntityCrudSuppliedRepository;\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 * The order the list opens in — a worklist again: the stock that is out\n * first, the oldest order first. The header reads as sorted by it, and a\n * click on another column replaces it.\n *\n * Checked when the screen is generated against the `sortable` allowlist a\n * service applies to a `sort` parameter: a member that is not `sortable`\n * throws here rather than answering `400` on every first load.\n */\n readonly initialSorting?: EntitySorting<TEntity>;\n /**\n * How the list reads for whoever is reading it — a hook the host supplies,\n * called on every render of the list page and of each `RelatedList`. A\n * vendor reading their own statement gets \"My payouts\" over a list with no\n * \"Vendor\" column, where an operator gets \"Vendor payouts\" and the column.\n *\n * Copy and presentation only. It decides nothing about what the reader may\n * read: the service narrows the records, and a column withheld here is a\n * column whose value the service still sends.\n */\n readonly useListView?: () => EntityCrudListView;\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 * The forms a verb that takes input opens, by the name its descriptor's\n * `form` gives. Each renders its fields inside the `<form id={formId}>` the\n * dialog's submit button targets, and calls `submit` with the verb's body.\n * A verb that takes input and names no form here is not offered: a button\n * that posted it empty could only be refused.\n */\n readonly verbForms?: Readonly<\n Record<string, (props: EntityVerbFormProps<TEntity>) => ReactNode>\n >;\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 /**\n * The list's title for whoever is reading it: the `titleKey` the host's\n * `useListView` answers, else {@link entityPluralKey}. A hook, so a host\n * titles a list's tab exactly as the page titles itself.\n */\n readonly useListTitleKey: () => 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/** What {@link EntityCrudOptions.useListView} answers for one reader. */\nexport interface EntityCrudListView {\n /**\n * The list's title, as a catalog key, in place of the entity's own\n * `pluralKey`. Also what {@link EntityCrud.useListTitleKey} answers, so a\n * host titles the list's tab the same way.\n */\n readonly titleKey?: string;\n /**\n * Columns this reader does not get, passed to `EntityTable` as\n * `hiddenColumns`: gone from the header, the settings, the filters, the sort\n * choices and the cards. A name that is not a column throws.\n */\n readonly hiddenColumns?: readonly string[];\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\n/** What a verb's form is handed: the record, its form id, and the submit. */\nexport interface EntityVerbFormProps<TEntity extends Entity> {\n readonly record: TEntity;\n /** The id the `<form>` takes, so the dialog's submit button targets it. */\n readonly formId: string;\n /** Runs the verb on the record with this body, and closes the dialog. */\n readonly submit: (payload: unknown) => void;\n}\n"],"names":[],"mappings":"AAmeA,2EAA2E,GAC3E,WAMC"}
|
|
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 EntitySorting,\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 /**\n * The owning entity's accessor name, e.g. `'brandId'`: a `link`, a `string`\n * foreign key, or a `scalarCollection` that declares `references` — a list\n * of ids, edited one name at a time.\n */\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 EntityCrudSuppliedRepository {\n /**\n * A hook returning the target's repository, called inside the crud's render\n * tree on every render — so a provider the host mounts above it (another\n * slice's adapters) resolves it. Same read plan as an adapter key: one read\n * per page.\n */\n readonly useRepository: () => Context<EntityRepositoryTag>;\n}\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 /**\n * Where the target's repository comes from: the key of one of this crud's\n * own adapters, or — when the target lives in another slice, whose adapter\n * this shell may not build — a repository the host supplies.\n */\n readonly repository:\n | AdapterKey<TAdapters, Context<EntityRepositoryTag>>\n | EntityCrudSuppliedRepository;\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 * The order the list opens in — a worklist again: the stock that is out\n * first, the oldest order first. The header reads as sorted by it, and a\n * click on another column replaces it.\n *\n * Checked when the screen is generated against the `sortable` allowlist a\n * service applies to a `sort` parameter: a member that is not `sortable`\n * throws here rather than answering `400` on every first load.\n */\n readonly initialSorting?: EntitySorting<TEntity>;\n /**\n * How the list reads for whoever is reading it — a hook the host supplies,\n * called on every render of the list page and of each `RelatedList`. A\n * vendor reading their own statement gets \"My payouts\" over a list with no\n * \"Vendor\" column, where an operator gets \"Vendor payouts\" and the column.\n *\n * Copy and presentation only. It decides nothing about what the reader may\n * read: the service narrows the records, and a column withheld here is a\n * column whose value the service still sends.\n */\n readonly useListView?: () => EntityCrudListView;\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 * The forms a verb that takes input opens, by the name its descriptor's\n * `form` gives. Each renders its fields inside the `<form id={formId}>` the\n * dialog's submit button targets, and calls `submit` with the verb's body.\n * A verb that takes input and names no form here is not offered: a button\n * that posted it empty could only be refused.\n */\n readonly verbForms?: Readonly<\n Record<string, (props: EntityVerbFormProps<TEntity>) => ReactNode>\n >;\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 /**\n * The list's title for whoever is reading it: the `titleKey` the host's\n * `useListView` answers, else {@link entityPluralKey}. A hook, so a host\n * titles a list's tab exactly as the page titles itself.\n */\n readonly useListTitleKey: () => 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/** What {@link EntityCrudOptions.useListView} answers for one reader. */\nexport interface EntityCrudListView {\n /**\n * The list's title, as a catalog key, in place of the entity's own\n * `pluralKey`. Also what {@link EntityCrud.useListTitleKey} answers, so a\n * host titles the list's tab the same way.\n */\n readonly titleKey?: string;\n /**\n * Columns this reader does not get, passed to `EntityTable` as\n * `hiddenColumns`: gone from the header, the settings, the filters, the sort\n * choices and the cards. A name that is not a column throws.\n */\n readonly hiddenColumns?: readonly string[];\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\n/** What a verb's form is handed: the record, its form id, and the submit. */\nexport interface EntityVerbFormProps<TEntity extends Entity> {\n readonly record: TEntity;\n /** The id the `<form>` takes, so the dialog's submit button targets it. */\n readonly formId: string;\n /** Runs the verb on the record with this body, and closes the dialog. */\n readonly submit: (payload: unknown) => void;\n}\n"],"names":[],"mappings":"AAueA,2EAA2E,GAC3E,WAMC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-entity-link-sources.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/use-entity-link-sources.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EAEtB,MAAM,eAAe,CAAC;AAIvB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAExE,MAAM,WAAW,2BAA2B;IAC1C,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,mBAAmB,CAAC;CACzC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,SAAS,oBAAoB,EAAE,EACtC,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,2BAA2B,GACjD,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"use-entity-link-sources.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/use-entity-link-sources.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EAEtB,MAAM,eAAe,CAAC;AAIvB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAExE,MAAM,WAAW,2BAA2B;IAC1C,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,mBAAmB,CAAC;CACzC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,SAAS,oBAAoB,EAAE,EACtC,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,2BAA2B,GACjD,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAuB1C"}
|
|
@@ -25,12 +25,15 @@ import { useEntityLinkSource } from '@entifix/react-integration';
|
|
|
25
25
|
// member that came back from storage in any other shape must read as unset
|
|
26
26
|
// rather than be handed to the picker as an id.
|
|
27
27
|
const held = readDraftString(values, link.field);
|
|
28
|
+
// A list of references holds many ids and names each one itself through
|
|
29
|
+
// the reference registry, so there is no one selected record to read.
|
|
30
|
+
const list = link.descriptor.type === 'scalarCollection';
|
|
28
31
|
// eslint-disable-next-line react-hooks/rules-of-hooks -- fixed-length loop over a factory-time array; see the note above.
|
|
29
32
|
sources[link.field] = useEntityLinkSource(link.config, {
|
|
30
33
|
descriptor: link.descriptor,
|
|
31
34
|
// An empty draft entry is "unset", not an id. Nothing enforces the
|
|
32
35
|
// reference across a store boundary, so `''` would be a dangling id.
|
|
33
|
-
selectedId: held === '' ? undefined : held,
|
|
36
|
+
selectedId: list || held === '' ? undefined : held,
|
|
34
37
|
selectedEntity: selection[link.field],
|
|
35
38
|
locale
|
|
36
39
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/crud/use-entity-link-sources.ts"],"sourcesContent":["'use client';\n\nimport {\n type Entity,\n type EntityDraft,\n type EntityLinkSelection,\n type EntityLinkSource,\n readDraftString,\n} from '@entifix/core';\nimport { useLocale } from '@entifix/react-controls';\nimport { useEntityLinkSource } from '@entifix/react-integration';\n\nimport type { EntityCrudLinkSource } from './make-entity-crud.types.js';\n\nexport interface UseEntityLinkSourcesOptions {\n /** The form's current draft — ids are the truth. */\n readonly values: EntityDraft;\n /** The picked-instance sidecar, so a chosen name needs no round trip. */\n readonly selection: EntityLinkSelection;\n}\n\n/**\n * Turns a fixed list of pickers into the `linkSources` map `EntityForm` takes.\n *\n * **Why the rule is disabled below.** `links` is built once, at factory time,\n * and closed over by the generated form — it is the same array object on every\n * render of a given component, so the hook count is fixed. That is exactly the\n * invariant `react-hooks/rules-of-hooks` exists to protect and exactly the one\n * it cannot see, because it reasons syntactically about the loop rather than\n * about the array's provenance. The loop is isolated in this module so the\n * disable is written once, with its reason, instead of once per generated form.\n *\n * The alternative — one child component per picker, reporting its source\n * upward — would put the sources one render behind the draft that feeds them,\n * which is a stale suggestion list rather than a lint error.\n */\nexport function useEntityLinkSources(\n links: readonly EntityCrudLinkSource[],\n { values, selection }: UseEntityLinkSourcesOptions,\n): Record<string, EntityLinkSource<Entity>> {\n // A localized member is searched and read in the reader's own locale.\n const locale = useLocale();\n const sources: Record<string, EntityLinkSource<Entity>> = {};\n for (const link of links) {\n // Read as a string: a relation's draft value is a foreign key, and a\n // member that came back from storage in any other shape must read as unset\n // rather than be handed to the picker as an id.\n const held = readDraftString(values, link.field);\n // eslint-disable-next-line react-hooks/rules-of-hooks -- fixed-length loop over a factory-time array; see the note above.\n sources[link.field] = useEntityLinkSource(link.config, {\n descriptor: link.descriptor,\n // An empty draft entry is \"unset\", not an id. Nothing enforces the\n // reference across a store boundary, so `''` would be a dangling id.\n selectedId: held === '' ? undefined : held,\n selectedEntity: selection[link.field],\n locale,\n });\n }\n return sources;\n}\n"],"names":["readDraftString","useLocale","useEntityLinkSource","useEntityLinkSources","links","values","selection","locale","sources","link","held","field","
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/crud/use-entity-link-sources.ts"],"sourcesContent":["'use client';\n\nimport {\n type Entity,\n type EntityDraft,\n type EntityLinkSelection,\n type EntityLinkSource,\n readDraftString,\n} from '@entifix/core';\nimport { useLocale } from '@entifix/react-controls';\nimport { useEntityLinkSource } from '@entifix/react-integration';\n\nimport type { EntityCrudLinkSource } from './make-entity-crud.types.js';\n\nexport interface UseEntityLinkSourcesOptions {\n /** The form's current draft — ids are the truth. */\n readonly values: EntityDraft;\n /** The picked-instance sidecar, so a chosen name needs no round trip. */\n readonly selection: EntityLinkSelection;\n}\n\n/**\n * Turns a fixed list of pickers into the `linkSources` map `EntityForm` takes.\n *\n * **Why the rule is disabled below.** `links` is built once, at factory time,\n * and closed over by the generated form — it is the same array object on every\n * render of a given component, so the hook count is fixed. That is exactly the\n * invariant `react-hooks/rules-of-hooks` exists to protect and exactly the one\n * it cannot see, because it reasons syntactically about the loop rather than\n * about the array's provenance. The loop is isolated in this module so the\n * disable is written once, with its reason, instead of once per generated form.\n *\n * The alternative — one child component per picker, reporting its source\n * upward — would put the sources one render behind the draft that feeds them,\n * which is a stale suggestion list rather than a lint error.\n */\nexport function useEntityLinkSources(\n links: readonly EntityCrudLinkSource[],\n { values, selection }: UseEntityLinkSourcesOptions,\n): Record<string, EntityLinkSource<Entity>> {\n // A localized member is searched and read in the reader's own locale.\n const locale = useLocale();\n const sources: Record<string, EntityLinkSource<Entity>> = {};\n for (const link of links) {\n // Read as a string: a relation's draft value is a foreign key, and a\n // member that came back from storage in any other shape must read as unset\n // rather than be handed to the picker as an id.\n const held = readDraftString(values, link.field);\n // A list of references holds many ids and names each one itself through\n // the reference registry, so there is no one selected record to read.\n const list = link.descriptor.type === 'scalarCollection';\n // eslint-disable-next-line react-hooks/rules-of-hooks -- fixed-length loop over a factory-time array; see the note above.\n sources[link.field] = useEntityLinkSource(link.config, {\n descriptor: link.descriptor,\n // An empty draft entry is \"unset\", not an id. Nothing enforces the\n // reference across a store boundary, so `''` would be a dangling id.\n selectedId: list || held === '' ? undefined : held,\n selectedEntity: selection[link.field],\n locale,\n });\n }\n return sources;\n}\n"],"names":["readDraftString","useLocale","useEntityLinkSource","useEntityLinkSources","links","values","selection","locale","sources","link","held","field","list","descriptor","type","config","selectedId","undefined","selectedEntity"],"mappings":"AAAA;AAEA,SAKEA,eAAe,QACV,gBAAgB;AACvB,SAASC,SAAS,QAAQ,0BAA0B;AACpD,SAASC,mBAAmB,QAAQ,6BAA6B;AAWjE;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,qBACdC,KAAsC,EACtC,EAAEC,MAAM,EAAEC,SAAS,EAA+B;IAElD,sEAAsE;IACtE,MAAMC,SAASN;IACf,MAAMO,UAAoD,CAAC;IAC3D,KAAK,MAAMC,QAAQL,MAAO;QACxB,qEAAqE;QACrE,2EAA2E;QAC3E,gDAAgD;QAChD,MAAMM,OAAOV,gBAAgBK,QAAQI,KAAKE,KAAK;QAC/C,wEAAwE;QACxE,sEAAsE;QACtE,MAAMC,OAAOH,KAAKI,UAAU,CAACC,IAAI,KAAK;QACtC,0HAA0H;QAC1HN,OAAO,CAACC,KAAKE,KAAK,CAAC,GAAGT,oBAAoBO,KAAKM,MAAM,EAAE;YACrDF,YAAYJ,KAAKI,UAAU;YAC3B,mEAAmE;YACnE,qEAAqE;YACrEG,YAAYJ,QAAQF,SAAS,KAAKO,YAAYP;YAC9CQ,gBAAgBZ,SAAS,CAACG,KAAKE,KAAK,CAAC;YACrCJ;QACF;IACF;IACA,OAAOC;AACT"}
|
package/package.json
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
-
"version": "0.23.
|
|
24
|
+
"version": "0.23.11",
|
|
25
25
|
"description": "Next.js application shell: back-office chrome, workspace tabs, CRUD screens derived from entity metadata, and session and proxy routes.",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"repository": {
|
|
@@ -57,17 +57,17 @@
|
|
|
57
57
|
"react": "19.3.1",
|
|
58
58
|
"react-dom": "19.3.1",
|
|
59
59
|
"zustand": "^5.1.0",
|
|
60
|
-
"@entifix/testing-unit": "0.23.
|
|
60
|
+
"@entifix/testing-unit": "0.23.11"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"idb": "^8.0.4",
|
|
64
|
-
"@entifix/authz": "0.23.
|
|
65
|
-
"@entifix/
|
|
66
|
-
"@entifix/
|
|
67
|
-
"@entifix/
|
|
68
|
-
"@entifix/
|
|
69
|
-
"@entifix/react-integration": "0.23.
|
|
70
|
-
"@entifix/transactions": "0.23.
|
|
64
|
+
"@entifix/authz": "0.23.11",
|
|
65
|
+
"@entifix/business": "0.23.11",
|
|
66
|
+
"@entifix/core": "0.23.11",
|
|
67
|
+
"@entifix/i18n": "0.23.11",
|
|
68
|
+
"@entifix/react-controls": "0.23.11",
|
|
69
|
+
"@entifix/react-integration": "0.23.11",
|
|
70
|
+
"@entifix/transactions": "0.23.11"
|
|
71
71
|
},
|
|
72
72
|
"files": [
|
|
73
73
|
"dist",
|