@sincpro/web-framework 3.22.0 → 4.1.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 +114 -112
- package/dist/core/cache.d.ts +20 -23
- package/dist/core/cache.js +37 -52
- package/dist/core/changes.d.ts +10 -18
- package/dist/core/changes.js +11 -30
- package/dist/core/command.d.ts +25 -11
- package/dist/core/command.js +9 -12
- package/dist/core/edit.d.ts +16 -2
- package/dist/core/edit.js +13 -2
- package/dist/core/groups.d.ts +3 -2
- package/dist/core/groups.js +4 -3
- package/dist/core/index.d.ts +3 -2
- package/dist/core/index.js +3 -2
- package/dist/core/list.d.ts +17 -11
- package/dist/core/list.js +17 -11
- package/dist/core/models.d.ts +16 -0
- package/dist/core/models.js +18 -0
- package/dist/core/names.d.ts +8 -6
- package/dist/core/names.js +16 -19
- package/dist/core/server.d.ts +9 -7
- package/dist/core/server.js +17 -21
- package/dist/core/trail.d.ts +6 -3
- package/dist/core/trail.js +2 -2
- package/dist/react/context.d.ts +13 -6
- package/dist/react/context.js +22 -10
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/useBatchCommand.d.ts +5 -5
- package/dist/react/useBatchCommand.js +12 -13
- package/dist/react/useCommand.d.ts +11 -15
- package/dist/react/useCommand.js +15 -13
- package/dist/react/useCount.d.ts +2 -2
- package/dist/react/useCounts.js +10 -9
- package/dist/react/useGroups.d.ts +1 -1
- package/dist/react/useGroups.js +22 -13
- package/dist/react/useHistory.js +9 -8
- package/dist/react/useListing.d.ts +14 -7
- package/dist/react/useListing.js +35 -10
- package/dist/react/useLookup.js +8 -9
- package/dist/react/useNameOf.d.ts +2 -2
- package/dist/react/useNameOf.js +4 -13
- package/dist/react/usePivot.d.ts +1 -1
- package/dist/react/usePivot.js +13 -7
- package/dist/react/useRecord.js +40 -57
- package/dist/react/useRecordLifecycle.js +8 -9
- package/dist/react/useServiceReading.js +6 -18
- package/dist/react/useSummary.js +2 -1
- package/dist/react/useUpload.js +9 -2
- package/dist/react/useWrites.d.ts +13 -12
- package/dist/react/useWrites.js +17 -16
- package/dist/web/board/Dashboard.d.ts +2 -2
- package/dist/web/list/EntityList.d.ts +2 -2
- package/dist/web/list/entityList/choosing.d.ts +3 -3
- package/dist/web/list/entityList/faces.d.ts +6 -6
- package/dist/web/list/entityList/grouping.d.ts +3 -3
- package/dist/web/list/entityList/opening.d.ts +4 -4
- package/dist/web/list/entityList/opening.js +2 -1
- package/dist/web/list/entityList/paging.d.ts +3 -3
- package/dist/web/list/entityList/props.d.ts +4 -4
- package/dist/web/list/entityList/rowActions.d.ts +4 -4
- package/dist/web/list/entityList/rowActions.js +1 -1
- package/dist/web/list/export.d.ts +2 -2
- package/dist/web/list/export.js +7 -8
- package/dist/web/list/presentation.d.ts +3 -3
- package/dist/web/list/records.d.ts +13 -10
- package/dist/web/list/records.js +25 -45
- package/dist/web/list/reorder.d.ts +1 -1
- package/dist/web/list/reorder.js +8 -6
- package/dist/web/list/rowCommands.d.ts +10 -9
- package/dist/web/list/rowCommands.js +14 -15
- package/dist/web/list/useEntityList.d.ts +4 -4
- package/dist/web/record/CommandButton.d.ts +8 -8
- package/dist/web/record/CommandButton.js +2 -1
- package/dist/web/record/EntityPicker.js +2 -1
- package/dist/web/record/EntityTags.js +7 -6
- package/dist/web/record/RelatedList.js +2 -2
- package/dist/web/record/ServiceButton.js +6 -1
- package/dist/web/record/choice.js +2 -1
- package/dist/web/record/edit.js +2 -1
- package/dist/web/record/lines.js +6 -5
- package/dist/web/record/richText.js +1 -1
- package/dist/web/workspace/SincproApp.d.ts +8 -6
- package/dist/web/workspace/SincproApp.js +17 -19
- package/dist/web/workspace/composer.d.ts +14 -9
- package/dist/web/workspace/composer.js +31 -8
- package/dist/web/workspace/record.js +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -33,12 +33,12 @@ be able to build it here, without asking us and without fighting us. So:
|
|
|
33
33
|
|
|
34
34
|
1. **Defaults, never cages.** Every piece comes in three levels, and any of them can be skipped:
|
|
35
35
|
|
|
36
|
-
| Level | What you write
|
|
37
|
-
| ------------ |
|
|
38
|
-
| Declarative | names of fields and entities
|
|
39
|
-
| Parts | one region of the screen is yours
|
|
40
|
-
| Hooks | your own screen over our state
|
|
41
|
-
| Loose pieces | straight to criteria, the
|
|
36
|
+
| Level | What you write | Example |
|
|
37
|
+
| ------------ | ---------------------------------------- | ------------------------------------------------------------------ |
|
|
38
|
+
| Declarative | names of fields and entities | `<EntityList listing={l} columns={["number", "state"]} />` |
|
|
39
|
+
| Parts | one region of the screen is yours | `<EntityList listing={l}><EntityList.Bar /><MyMap /></EntityList>` |
|
|
40
|
+
| Hooks | your own screen over our state | `useListing` + web-ui's `List` |
|
|
41
|
+
| Loose pieces | straight to criteria, the client, web-ui | `readPage(operations, invoices, criteria)` |
|
|
42
42
|
|
|
43
43
|
Adding a piece obliges nothing else; removing it breaks nothing else.
|
|
44
44
|
|
|
@@ -191,28 +191,32 @@ flowchart LR
|
|
|
191
191
|
@source "./";
|
|
192
192
|
```
|
|
193
193
|
|
|
194
|
-
**2. The
|
|
195
|
-
is the application's: it puts its headers
|
|
194
|
+
**2. The operations** — the one door to the backend, from @sincpro/client-framework: the
|
|
195
|
+
contract's operations over a wire. The session is the application's: it puts its headers on the
|
|
196
|
+
transport under them. The screens never name a route; REST is only its adapter's.
|
|
196
197
|
|
|
197
198
|
```ts
|
|
198
|
-
import { restTransport } from "@sincpro/client-framework";
|
|
199
|
+
import { restOperations, restTransport } from "@sincpro/client-framework";
|
|
199
200
|
|
|
200
201
|
export const transport = restTransport({
|
|
201
202
|
base: "/v1",
|
|
202
203
|
headers: () => ({ Authorization: `Bearer ${session.token}` }),
|
|
203
204
|
});
|
|
205
|
+
export const operations = restOperations(transport); // JSON-RPC: jsonRpcOperations(…)
|
|
204
206
|
```
|
|
205
207
|
|
|
206
|
-
The definition of every model — its fields, operators, hints, widgets, formulas — is
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
208
|
+
The definition of every model — its fields, operators, hints, widgets, formulas — is the
|
|
209
|
+
contract's, and each generated entity carries its own (`meta`): a face that imports an entity has
|
|
210
|
+
its model, with nothing to declare and no contract to download. An answer says only its
|
|
211
|
+
`model_version`, and nothing reads a model at runtime. `metas` (on `SincproApp`,
|
|
212
|
+
`FrameworkProvider` or `ModelDefinitions`) only replaces one. A form computes a published formula itself and asks the server
|
|
213
|
+
for a preview only when a change reaches something it cannot answer.
|
|
211
214
|
|
|
212
|
-
**3. The entities** —
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
(
|
|
215
|
+
**3. The entities** — written by `sincpro-client generate` from the contract («From the
|
|
216
|
+
contract», below): each an index over the client's operations — which one is its `search`, its
|
|
217
|
+
`get`, its `edit`, its history, its export, its Commands —, and its key in the workspace
|
|
218
|
+
(`domain:kind`). Nobody writes a route; the application only adds what the contract cannot say:
|
|
219
|
+
`summary` when its fields are not the conventional ones, and how a record looks (`presented`).
|
|
216
220
|
|
|
217
221
|
`summary` is how an application says which of its fields plays each part of a record — its
|
|
218
222
|
state, its type, its description, its picture, who made it. The convention only knows English
|
|
@@ -229,30 +233,26 @@ export const payments = {
|
|
|
229
233
|
```
|
|
230
234
|
|
|
231
235
|
```ts
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
create: "POST /invoices",
|
|
241
|
-
save: "PUT /invoices/{id}",
|
|
242
|
-
commands: { post: "POST /invoices/{id}/post" },
|
|
243
|
-
history: "/invoices/{id}/events", // its DomainEvents: a record's facts
|
|
236
|
+
// sales/adapters/generated/entities.ts — generated, never edited:
|
|
237
|
+
export const invoices = entity("sales:invoice", {
|
|
238
|
+
model: "Invoice",
|
|
239
|
+
search: operations.listInvoices,
|
|
240
|
+
get: operations.getInvoice,
|
|
241
|
+
edit: operations.editInvoice,
|
|
242
|
+
events: operations.invoiceEvents, // its DomainEvents: a record's facts
|
|
243
|
+
commands: { post: operations.postInvoice, create: operations.createInvoice },
|
|
244
244
|
});
|
|
245
245
|
```
|
|
246
246
|
|
|
247
|
-
An entity
|
|
248
|
-
|
|
247
|
+
An entity without an `edit` — a payment, an order that only its Commands move — has its records
|
|
248
|
+
drawn read only, whole: nothing on screen invites typing what nobody can store.
|
|
249
249
|
|
|
250
250
|
**How a record looks** is the client's, declared once with the entity (`presented`): its row,
|
|
251
251
|
card and option, the columns of a table of it, the colour of each value of a choice and of each
|
|
252
252
|
kind of fact in its history. Cells, rows, cards, the record's tag and its activity use them:
|
|
253
253
|
|
|
254
254
|
```ts
|
|
255
|
-
export const payments = presented(
|
|
255
|
+
export const payments = presented(generated.payments, {
|
|
256
256
|
tones: { estado: { EN_REVISION: "warn", VALIDADO: "good", RECHAZADO: "bad" } },
|
|
257
257
|
facts: { pago_aprobado: "good", pago_rechazado: "bad" }, // by a fact's `name`, or its last part
|
|
258
258
|
columns: ["periodo", "monto", "estado"],
|
|
@@ -268,7 +268,7 @@ one2many in a tab; «save / discard», the conflict, the restored draft, who mad
|
|
|
268
268
|
|
|
269
269
|
```ts
|
|
270
270
|
const views = [
|
|
271
|
-
entityView(invoices, {
|
|
271
|
+
entityView(invoices, { operations, name: "Invoices" }), // both screens, from the model
|
|
272
272
|
];
|
|
273
273
|
```
|
|
274
274
|
|
|
@@ -296,13 +296,13 @@ function InvoiceView(props: ViewProps) {
|
|
|
296
296
|
```ts
|
|
297
297
|
const views = [
|
|
298
298
|
entityView(invoices, {
|
|
299
|
-
|
|
299
|
+
operations,
|
|
300
300
|
name: "Invoices",
|
|
301
301
|
list: InvoiceList,
|
|
302
302
|
record: InvoiceView,
|
|
303
303
|
}),
|
|
304
304
|
entityView(customers, {
|
|
305
|
-
|
|
305
|
+
operations,
|
|
306
306
|
name: "Customers",
|
|
307
307
|
list: CustomerList,
|
|
308
308
|
record: CustomerView,
|
|
@@ -310,11 +310,13 @@ const views = [
|
|
|
310
310
|
];
|
|
311
311
|
```
|
|
312
312
|
|
|
313
|
-
**5. The application** —
|
|
314
|
-
cache, toasts and the workspace, in one place
|
|
313
|
+
**5. The application** — operations, models, language (web-ui's, composer's and the framework's
|
|
314
|
+
words), cache, toasts and the workspace, in one place. `transport` is only where a file goes
|
|
315
|
+
(`uploadTo`), when the app takes files:
|
|
315
316
|
|
|
316
317
|
```tsx
|
|
317
318
|
<SincproApp
|
|
319
|
+
operations={operations}
|
|
318
320
|
transport={transport}
|
|
319
321
|
views={views}
|
|
320
322
|
entities={[invoices, customers]} // a relation of a model resolves to one of these, alone
|
|
@@ -516,7 +518,7 @@ run dry) and shows it:
|
|
|
516
518
|
/>
|
|
517
519
|
```
|
|
518
520
|
|
|
519
|
-
**What a use case wrote, every screen sees.** Each write
|
|
521
|
+
**What a use case wrote, every screen sees.** Each write an operation adapter of the framework sends is
|
|
520
522
|
announced on the process's change feed (`processChanges`, client-framework) — a screen's save, a
|
|
521
523
|
use case's generated client, a panel beside. The cache forgets what it touched, and every reading
|
|
522
524
|
on screen — `useListing`, `useRecord`, `useHistory`, `useGroups`, `usePivot`, `useNameOf` — reads
|
|
@@ -524,8 +526,8 @@ again, keeping its filter, order and page; a record being edited keeps what was
|
|
|
524
526
|
never calls `reload()` after an action. A reading of an application's own follows the same feed:
|
|
525
527
|
|
|
526
528
|
```ts
|
|
527
|
-
const writes = useWrites(
|
|
528
|
-
useEffect(() => { … }, [
|
|
529
|
+
const writes = useWrites(invoices); // how many times a write named the invoices' model
|
|
530
|
+
useEffect(() => { … }, [writes]);
|
|
529
531
|
```
|
|
530
532
|
|
|
531
533
|
A bounded context with no sincpro_framework behind it declares its model by hand and is drawn the same
|
|
@@ -567,8 +569,8 @@ const balance = useServiceReading(project.Accounts.balance, [{ member_id: member
|
|
|
567
569
|
});
|
|
568
570
|
```
|
|
569
571
|
|
|
570
|
-
A record screen starts the same way. `readRecordOnServer` reads the record
|
|
571
|
-
|
|
572
|
+
A record screen starts the same way. `readRecordOnServer` reads the record with the operations the
|
|
573
|
+
provider is given, its model the contract's — plain JSON (`RecordRead`), `undefined` and one line on the log
|
|
572
574
|
when it fails — and `useRecord` starts `ready` from it (so do `useRecordScreen` and
|
|
573
575
|
`EntityRecord`, by `initial`): the HTML carries the record, not a skeleton, and the browser asks
|
|
574
576
|
nothing for it on mount. Only for the record it was read for; editing, previews, drafts and
|
|
@@ -579,7 +581,7 @@ does not match:
|
|
|
579
581
|
```tsx
|
|
580
582
|
// the Server Component
|
|
581
583
|
import { readRecordOnServer } from "@sincpro/web-framework/core";
|
|
582
|
-
const invoice = await readRecordOnServer(
|
|
584
|
+
const invoice = await readRecordOnServer(operations, invoices, params.id, { meta });
|
|
583
585
|
return <InvoicePage id={params.id} initial={invoice} />;
|
|
584
586
|
|
|
585
587
|
// the page ("use client"), under <FrameworkProvider timeZone="America/La_Paz" locale="es">
|
|
@@ -702,65 +704,65 @@ find .next/static -name '*.map' -delete
|
|
|
702
704
|
Each answers one question, and each comes in the three levels — use the component, drop to the
|
|
703
705
|
hook and draw your own, or go straight to the loose piece.
|
|
704
706
|
|
|
705
|
-
| Question | Declarative
|
|
706
|
-
| ------------------------------------- |
|
|
707
|
-
| Where is the data? | `entity()` (client-framework)
|
|
708
|
-
| The application's logic | its `Feature`s and `ApplicationService`s (client-framework)
|
|
709
|
-
| Read through a use case | its `Feature`s (client-framework)
|
|
710
|
-
| Read it on the server first | the same use case, before the page is drawn
|
|
711
|
-
| A record read on the server | `EntityRecord initial`
|
|
712
|
-
| What every use case runs with | `processContext`, `project.context` (client-framework)
|
|
713
|
-
| What happened, what broke | `./telemetry`, `./errors` (optional)
|
|
714
|
-
| What happened, on the server | `configureServerProcess` (`./telemetry/server`, optional)
|
|
715
|
-
| What broke, on the server | `reportRequestError` (`./errors/server`, optional)
|
|
716
|
-
| A page that broke | `RouteError`, in the route's error boundary
|
|
717
|
-
| What is each field? | `Meta` from the server, or `defineMeta`
|
|
718
|
-
| A value outside a model | —
|
|
719
|
-
| A file or a photo it holds | `EntityList`, `RecordField`: by its widget, as a `FileValue`
|
|
720
|
-
| A file given in the record | `RecordField` with `uploads`: `FileControl` (`DropZone`)
|
|
721
|
-
| Formatted text | `RecordField` (`widget: "html"`), `factsOf`: `RichTextControl`
|
|
722
|
-
| A person, read | `RecordField`, `factsOf`: `PersonValue` (`UserChip`)
|
|
723
|
-
| A choice's tag outside a list | `ChoiceTag`
|
|
724
|
-
| What is a record, at any size? | `cardOf`, `relationOf`
|
|
725
|
-
| How does a record look? | `presented(entity, { option, row, card, tile })`
|
|
726
|
-
| N records: search, filter, page | `EntityList`, `EntitySearchBar`
|
|
727
|
-
| A named slice (to collect, …) | `defineList` + `listView`
|
|
728
|
-
| A record's whole screen | `EntityRecord`, `entityView` without `record`
|
|
729
|
-
| One region of a record screen | `RecordScreen.*` (`Rail`, `Paper`, `Fields`, `Pages`, `Audit`…)
|
|
730
|
-
| One region of a list | `EntityList.*` (`Bar`, `Search`, `Table`, `Board`, `Pager`…)
|
|
731
|
-
| The models a face brings | `ModelDefinitions entities metas events`; `SincproApp` without `
|
|
732
|
-
| What a record screen says of it | `RecordScreen title subtitle tag creating moment actions`
|
|
733
|
-
| What hangs off a record, counted | `RecordScreen links` (`RelatedLink`: entity, `where`, title)
|
|
734
|
-
| The notices, on a hand-written screen | —
|
|
735
|
-
| A block laid out as the form | —
|
|
736
|
-
| Who is who in a history | `SincproApp people`, `FrameworkProvider people`, `ModelDefinitions people`
|
|
737
|
-
| «New» in the business's words | `EntityList create="Nueva noticia"`
|
|
738
|
-
| The list as a spreadsheet | `EntityList` «Exportar» (the entity's `export`)
|
|
739
|
-
| Spanish in tú | `SincproApp voice="tú"`
|
|
740
|
-
| Previous / next from a record | `EntityRecord` (from a list)
|
|
741
|
-
| How much each group adds up | `EntityList sums`
|
|
742
|
-
| One record: read, edit, save | `RecordField`, `factsOf`, `RecordLines`
|
|
743
|
-
| Its lines: add, edit, remove | `RecordField name="lines"` (`LineItems`)
|
|
744
|
-
| Its relations, inside it | `RelatedList`
|
|
745
|
-
| What other records hold of it | web-ui's `SmartButton` opening `entity.listRef(cut, name)`
|
|
746
|
-
| Choose one (literal search) | `EntityPicker`, `chooserIn`
|
|
747
|
-
| Choose several (many2many) | `EntityTags`
|
|
748
|
-
| A relation, from the model alone | `RecordField name="customer_id"`
|
|
749
|
-
| Open it where it belongs | `RelatedRecord`, `entityView`, `EntityList openTargets`
|
|
750
|
-
| Look at the set several ways | `EntityList views` (table, rows, board, sheet, tiles)
|
|
751
|
-
| Cross it by two fields | `EntityList pivot`
|
|
752
|
-
| Order by several fields | the bar's criteria builder
|
|
753
|
-
| Act on it (with a dry run) | `ServiceButton` (a use case), `CommandButton`, row commands
|
|
754
|
-
| What is chosen in a list | `EntityList selectable selection`
|
|
755
|
-
| Act on each chosen one | `BatchProgress`, `selectionActions={(chosen) => …}`
|
|
756
|
-
| A list's actions, by the style | `EntityList actions`, `selectionActions` (`DockAction`s)
|
|
757
|
-
| A record's actions, by the style | `EntityRecord actions`, web-ui's `Record.Dock`
|
|
758
|
-
| A use case or a Command, there | `ServiceButton`, `CommandButton` (as buttons)
|
|
759
|
-
| Delete it | `EntityRecord` (`RecordLifecycle`)
|
|
760
|
-
| Its trash | `EntityRecord` (`RecordLifecycle`), `listView(trashOf(entity))`
|
|
761
|
-
| Read again when it was written | every reading of this package, by itself
|
|
762
|
-
| What happened to it | `Record.Activity` fed by `useHistory`
|
|
763
|
-
| The application context | `SincproApp`
|
|
707
|
+
| Question | Declarative | Hook | Loose piece |
|
|
708
|
+
| ------------------------------------- | --------------------------------------------------------------------------- | ------------------------------------- | ------------------------------------------------------------ |
|
|
709
|
+
| Where is the data? | `entity()` (client-framework) | — | `restTransport`, `memoryTransport` |
|
|
710
|
+
| The application's logic | its `Feature`s and `ApplicationService`s (client-framework) | `useService` | `project.Issues.close(…)` |
|
|
711
|
+
| Read through a use case | its `Feature`s (client-framework) | `useServiceReading` | `project.Accounts.balance(…)` |
|
|
712
|
+
| Read it on the server first | the same use case, before the page is drawn | `useServiceReading(…, { initial })` | `readOnServer`, `ServerRead` |
|
|
713
|
+
| A record read on the server | `EntityRecord initial` | `useRecord(…, { initial })` | `readRecordOnServer`, `RecordRead` |
|
|
714
|
+
| What every use case runs with | `processContext`, `project.context` (client-framework) | `useContextValues` | `ContextStore` |
|
|
715
|
+
| What happened, what broke | `./telemetry`, `./errors` (optional) | — | `configureProcess({ tracer, reporter })` |
|
|
716
|
+
| What happened, on the server | `configureServerProcess` (`./telemetry/server`, optional) | — | `registerServerTracing`, `serverTracer` |
|
|
717
|
+
| What broke, on the server | `reportRequestError` (`./errors/server`, optional) | — | `registerServerErrors`, `serverReporter` |
|
|
718
|
+
| A page that broke | `RouteError`, in the route's error boundary | — | `reportError` (client-framework) |
|
|
719
|
+
| What is each field? | `Meta` from the server, or `defineMeta` | — | `textOf`, `viewOf`, `metaFromSchema` |
|
|
720
|
+
| A value outside a model | — | `useTextOf` | `moneyTextOf`, `dayTextOf`, `instantTextOf`, `numberTextOf` |
|
|
721
|
+
| A file or a photo it holds | `EntityList`, `RecordField`: by its widget, as a `FileValue` | — | `attachmentOf`, `storedFileOf`, `renditionUrl` |
|
|
722
|
+
| A file given in the record | `RecordField` with `uploads`: `FileControl` (`DropZone`) | `useUpload` | `sendFile`, `uploadRefusalOf` |
|
|
723
|
+
| Formatted text | `RecordField` (`widget: "html"`), `factsOf`: `RichTextControl` | — | `richTextPlainOf`, `holdsRichText` |
|
|
724
|
+
| A person, read | `RecordField`, `factsOf`: `PersonValue` (`UserChip`) | `useSummaryOf` | `isPersonEntity` |
|
|
725
|
+
| A choice's tag outside a list | `ChoiceTag` | — | `choiceTagOf` |
|
|
726
|
+
| What is a record, at any size? | `cardOf`, `relationOf` | `useSummaryOf` | `summaryOf` |
|
|
727
|
+
| How does a record look? | `presented(entity, { option, row, card, tile })` | — | `presentationOf` |
|
|
728
|
+
| N records: search, filter, page | `EntityList`, `EntitySearchBar` | `useListing`, `useGroups` | `readPage(operations, entity, criteria)` |
|
|
729
|
+
| A named slice (to collect, …) | `defineList` + `listView` | `useListing(list)` | `scopeOf` |
|
|
730
|
+
| A record's whole screen | `EntityRecord`, `entityView` without `record` | `useRecordScreen` | `formOf` |
|
|
731
|
+
| One region of a record screen | `RecordScreen.*` (`Rail`, `Paper`, `Fields`, `Pages`, `Audit`…) | `useScreenRecord` | web-ui's `Record.*` |
|
|
732
|
+
| One region of a list | `EntityList.*` (`Bar`, `Search`, `Table`, `Board`, `Pager`…) | `useScreenListing`, `useEntityList` | web-ui's `List.*` |
|
|
733
|
+
| The models a face brings | `ModelDefinitions entities metas events`; `SincproApp` without `operations` | — | `metasOf`, `eventMetasOf` (client-framework) |
|
|
734
|
+
| What a record screen says of it | `RecordScreen title subtitle tag creating moment actions` | `useRecordScreen` (same options) | web-ui's `Record identity`, `Record.Dock moment` |
|
|
735
|
+
| What hangs off a record, counted | `RecordScreen links` (`RelatedLink`: entity, `where`, title) | `useCounts` | `listRef` |
|
|
736
|
+
| The notices, on a hand-written screen | — | `useRecordNotices` | web-ui's `Record.Notice` |
|
|
737
|
+
| A block laid out as the form | — | `useScreenColumns` | — |
|
|
738
|
+
| Who is who in a history | `SincproApp people`, `FrameworkProvider people`, `ModelDefinitions people` | `usePeopleOf` | the application's use case |
|
|
739
|
+
| «New» in the business's words | `EntityList create="Nueva noticia"` | — | `canCreate` (`create` or `Edit`) |
|
|
740
|
+
| The list as a spreadsheet | `EntityList` «Exportar» (the entity's `export`) | — | `csvOf`, `exportColumnsOf`; `exportRoute` (client-framework) |
|
|
741
|
+
| Spanish in tú | `SincproApp voice="tú"` | — | `SPANISH_FRAMEWORK_COPY_TU`, web-ui's `SPANISH_COPY_TU` |
|
|
742
|
+
| Previous / next from a record | `EntityRecord` (from a list) | — | `placeOf`, `stepIn` (`Trail`) |
|
|
743
|
+
| How much each group adds up | `EntityList sums` | `useGroups` (`sums`) | `sumsOf`, `detailOf` |
|
|
744
|
+
| One record: read, edit, save | `RecordField`, `factsOf`, `RecordLines` | `useRecord` | `readRecord`, `operations.call(entity.operations.edit, …)` |
|
|
745
|
+
| Its lines: add, edit, remove | `RecordField name="lines"` (`LineItems`) | `useRecord` (`edit.cell`, `errorAt`) | `lineKey`, `editableLines`, `pathOf` |
|
|
746
|
+
| Its relations, inside it | `RelatedList` | `useRelated` | `relatedOf` |
|
|
747
|
+
| What other records hold of it | web-ui's `SmartButton` opening `entity.listRef(cut, name)` | `useCount` | `entity.listRef` (client-framework) |
|
|
748
|
+
| Choose one (literal search) | `EntityPicker`, `chooserIn` | `useLookup` | `lookupOf` + criteria's `matching` |
|
|
749
|
+
| Choose several (many2many) | `EntityTags` | `useLookup` (`values`) | `lookupOf` |
|
|
750
|
+
| A relation, from the model alone | `RecordField name="customer_id"` | `useEntityFor` | `relationFieldOf`, `entityFor` |
|
|
751
|
+
| Open it where it belongs | `RelatedRecord`, `entityView`, `EntityList openTargets` | — | `openIn`, `targetsFor`, `OpenInMenu` |
|
|
752
|
+
| Look at the set several ways | `EntityList views` (table, rows, board, sheet, tiles) | — | web-ui's `List.*` |
|
|
753
|
+
| Cross it by two fields | `EntityList pivot` | `usePivot` | `pivotOf` |
|
|
754
|
+
| Order by several fields | the bar's criteria builder | `listing.orderBy([...])` | criteria's `order` |
|
|
755
|
+
| Act on it (with a dry run) | `ServiceButton` (a use case), `CommandButton`, row commands | `useService`, `useCommand` | `callFor`, `operations.call` |
|
|
756
|
+
| What is chosen in a list | `EntityList selectable selection` | `useSelection` | `Selection`, `chosen`, `allMatching` (client-framework) |
|
|
757
|
+
| Act on each chosen one | `BatchProgress`, `selectionActions={(chosen) => …}` | `useBatchCommand` | `runBatch`, `keysOf` (client-framework), `sendRoute` |
|
|
758
|
+
| A list's actions, by the style | `EntityList actions`, `selectionActions` (`DockAction`s) | — | web-ui's `List.Dock`, `ViewStyleProvider` |
|
|
759
|
+
| A record's actions, by the style | `EntityRecord actions`, web-ui's `Record.Dock` | `useRecordLifecycleActions` | `DockedAction`, `ActionLook` |
|
|
760
|
+
| A use case or a Command, there | `ServiceButton`, `CommandButton` (as buttons) | `useServiceAction`/`useCommandAction` | — |
|
|
761
|
+
| Delete it | `EntityRecord` (`RecordLifecycle`) | `useRecordLifecycle` | `entity.operations.delete`, `useOperationCommand` |
|
|
762
|
+
| Its trash | `EntityRecord` (`RecordLifecycle`), `listView(trashOf(entity))` | `useRecordLifecycle` | `entity.operations.archive`, `.restore`, `trashOf` |
|
|
763
|
+
| Read again when it was written | every reading of this package, by itself | `useWrites` | `processChanges` (client-framework) |
|
|
764
|
+
| What happened to it | `Record.Activity` fed by `useHistory` | `useHistory` | `historyOf` |
|
|
765
|
+
| The application context | `SincproApp` | `useRecordInWorkspace`, `useFollowed` | `FrameworkProvider`, `webUiSkin` |
|
|
764
766
|
|
|
765
767
|
The rules behind them, in short:
|
|
766
768
|
|
|
@@ -827,13 +829,13 @@ npx sincpro-client generate contracts/project.contract.json --out src/generated/
|
|
|
827
829
|
| File | What it holds |
|
|
828
830
|
| --------------- | --------------------------------------------------------------------------------------------------- |
|
|
829
831
|
| `domain.ts` | the DTOs — every model, every operation's input and answer — with the server's own docs. Types only |
|
|
830
|
-
| `client.ts` | every operation as data, and `
|
|
831
|
-
| `entities.ts` | an `entity
|
|
832
|
+
| `client.ts` | every operation as typed data (`operations`), and `api`, implemented by `apiOf(api, operations)` |
|
|
833
|
+
| `entities.ts` | an `entity()` per model a screen lists: an index over its operations, by role, and its Commands |
|
|
832
834
|
| `contract.json` | the snapshot they came from: `metasOf(contract, "project")` preloads the definitions |
|
|
833
835
|
|
|
834
836
|
What is generated is never edited; a screen extends it (`presented(issues, { row })`, a type
|
|
835
837
|
with `&`). Keep the folder out of prettier and eslint, and let CI regenerate and compare it.
|
|
836
|
-
|
|
838
|
+
The definitions are the contract's: regenerate when the backend changes. How an
|
|
837
839
|
application adopts it — where each file goes, what is written by hand, how a hand-written screen
|
|
838
840
|
moves to the generated one — is [`docs/ADOPTION.md`](docs/ADOPTION.md).
|
|
839
841
|
|
|
@@ -853,25 +855,25 @@ moves to the generated one — is [`docs/ADOPTION.md`](docs/ADOPTION.md).
|
|
|
853
855
|
| `selection` | Filters named as criteria 2.0 and the backend read them, the search bar's included | ✅ |
|
|
854
856
|
| `useListing`, `EntityList` | N records: criteria, search bar, builder, paging | ✅ |
|
|
855
857
|
| `useRecord`, `factsOf`, `RecordLines` | One record: facts, relations with their real total | ✅ |
|
|
856
|
-
|
|
|
858
|
+
| Definitions | Each generated entity carries its model (`meta`); `metas` replaces one; no answer carries one | ✅ |
|
|
857
859
|
| `useLookup`, `EntityPicker` | Literal search: a many2one select, ⌘K | ✅ |
|
|
858
860
|
| `useRecord` + `RecordField`, `dirtyOf` | Editing: hints evaluated live, preview, save with version (409), server drafts | ✅ |
|
|
859
861
|
| `useCommand`, `CommandButton` | An entity's actions, with a dry run before what destroys | ✅ |
|
|
860
862
|
| `ServiceButton` | A use case as an action: the same gesture, its dry run the use case's own | ✅ |
|
|
861
863
|
| `useWrites`, the change feed | Every reading on screen reads again when anyone writes what it shows — a use case included | ✅ |
|
|
862
|
-
|
|
|
863
|
-
|
|
|
864
|
-
|
|
|
864
|
+
| Typed Commands (the contract's) | A name the entity does not declare, or a field its operation does not take, does not compile | ✅ |
|
|
865
|
+
| Typed answers (the contract's) | What each Command answers, typed: `run(…)` returns it with no type argument written | ✅ |
|
|
866
|
+
| A Query of the context's own | `operations.call(…)` (`/me`): neither a page nor a record, never cached | ✅ |
|
|
865
867
|
| A key alone (`EntityID`), `useNameOf` | A key that names whose record it is, drawn as a many2one; names asked in one request per entity | ✅ |
|
|
866
868
|
| `versionsOf`, `onVersionDrift` | A snapshot behind the server is told once per model — never an error | ✅ |
|
|
867
869
|
| `sincpro-client generate` | A context's DTOs, client and entities out of its exported client contract | ✅ |
|
|
868
|
-
| `metasOf`, `
|
|
870
|
+
| `metasOf`, `targeted` | Definitions from that snapshot; a Command's record written where its operation names it | ✅ |
|
|
869
871
|
| `useHistory` | Business events in `Record.Activity` (comments: backend first) | ✅ |
|
|
870
872
|
| `entityView` | An entity as a composer view: list, record, ⌘K search | ✅ |
|
|
871
873
|
| `<SincproApp>` | The application context in one place, the workspace dressed as web-ui (`webUiSkin`) | ✅ |
|
|
872
874
|
| `useRecordInWorkspace` | A record tells the workspace its real name and its unsaved work (composer 1.0) | ✅ |
|
|
873
875
|
| Paging by pages, ceiling on «more» | One page on screen, walked by the server's cursor: a million rows never freeze it | ✅ |
|
|
874
|
-
| `
|
|
876
|
+
| `cachedOperations` | Repeated Queries from memory and shared in flight, forgotten when anyone writes the entity | ✅ |
|
|
875
877
|
| `EntitySearchBar` | The search bar + criteria builder as a loose piece, for any `List` | ✅ |
|
|
876
878
|
| `EntityList` views | The same set as table, rows or board | ✅ |
|
|
877
879
|
| `useRelated`, `RelatedList` | A record's relation as a live list: searched and paged by the server, inside a form | ✅ |
|
package/dist/core/cache.d.ts
CHANGED
|
@@ -1,40 +1,39 @@
|
|
|
1
|
-
import { type Change, type
|
|
1
|
+
import { type Change, type OperationTransport } from "@sincpro/client-framework";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Operations that remember what they read, for a while, and forget it when something writes.
|
|
4
4
|
*
|
|
5
5
|
* Context: in a workspace the same questions come back all the time — the list you go back to
|
|
6
6
|
* through the breadcrumb, the record reopened from ⌘K, the select that points at the same
|
|
7
7
|
* customers, two panels on the same entity. Each one was a request. This answers a repeated
|
|
8
|
-
*
|
|
8
|
+
* Query from memory while it is fresh (`ttl`), and drops every answer of an entity the moment
|
|
9
9
|
* a write touches it: a save, a Command, a draft. Stale data after a write is worse than a
|
|
10
10
|
* request, so a write always wins.
|
|
11
11
|
*
|
|
12
|
-
* What it keys on is the question as it travels — the
|
|
13
|
-
* different filters, orders or pages never share an answer. A read that fails is not kept
|
|
12
|
+
* What it keys on is the question as it travels — the operation and its input — so two
|
|
13
|
+
* different filters, orders or pages never share an answer. A read that fails is not kept; an
|
|
14
|
+
* answer of bytes (`streamed`, an export) and a Query of no entity (the caller's own, which no
|
|
15
|
+
* write would forget) are never kept: they pass through.
|
|
14
16
|
*
|
|
15
17
|
* A question asked again while its answer is on its way joins it: two panels opening one record,
|
|
16
18
|
* a picker beside a column, are one request. Each reader may give up on its own (its `signal`);
|
|
17
19
|
* the request is cancelled only when every one of them did. A write while it flies makes its
|
|
18
20
|
* answer old: it is handed to who waited, never kept, and the next reader asks again.
|
|
19
21
|
*
|
|
20
|
-
* Who wrote does not matter. A write through
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* history of each entity it writes under (`entities`).
|
|
22
|
+
* Who wrote does not matter. A write through here forgets at once; one made elsewhere — a use
|
|
23
|
+
* case's generated client, another adapter — is told with `changed`, which is what the process's
|
|
24
|
+
* change feed carries (`processChanges`, @sincpro/client-framework). A write touches every
|
|
25
|
+
* reading of an entity it names (`touchesOperation`).
|
|
25
26
|
*
|
|
26
|
-
* A run binds it like any
|
|
27
|
-
*
|
|
28
|
-
* answer comes from memory or from the server.
|
|
27
|
+
* A run binds it like any operation adapter of the framework (`bindableOperations`), and it keeps
|
|
28
|
+
* the screens' mark of what it wraps (`markedAs`).
|
|
29
29
|
*
|
|
30
|
-
* const
|
|
31
|
-
* processChanges.follow((change) =>
|
|
32
|
-
*
|
|
30
|
+
* const operations = cachedOperations(restOperations(restTransport({ base: "/v1" })), { ttl: 30_000 });
|
|
31
|
+
* processChanges.follow((change) => operations.changed(change));
|
|
32
|
+
* operations.invalidate(["Factura"]); // forget an entity by hand
|
|
33
33
|
*/
|
|
34
|
-
export type
|
|
35
|
-
/** Forget every answer
|
|
36
|
-
|
|
37
|
-
invalidate: (path?: string) => void;
|
|
34
|
+
export type CachedOperations = OperationTransport & {
|
|
35
|
+
/** Forget every answer of an operation of these entities; every answer, with none. */
|
|
36
|
+
invalidate: (entities?: readonly string[]) => void;
|
|
38
37
|
/** A write made elsewhere: forget what it touched, as a write through here does. */
|
|
39
38
|
changed: (change: Change) => void;
|
|
40
39
|
};
|
|
@@ -43,7 +42,5 @@ export type CacheOptions = {
|
|
|
43
42
|
ttl?: number;
|
|
44
43
|
/** The clock — for tests. */
|
|
45
44
|
now?: () => number;
|
|
46
|
-
/** The application's entities: a write to one also forgets its history route. */
|
|
47
|
-
entities?: readonly Entity[];
|
|
48
45
|
};
|
|
49
|
-
export declare function
|
|
46
|
+
export declare function cachedOperations(transport: OperationTransport, options?: CacheOptions): CachedOperations;
|
package/dist/core/cache.js
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export function
|
|
1
|
+
import { bindableOperations, changeOf, markedAs, } from "@sincpro/client-framework";
|
|
2
|
+
import { touchesOperation } from "./changes.js";
|
|
3
|
+
export function cachedOperations(transport, options = {}) {
|
|
4
4
|
const ttl = options.ttl ?? 30_000;
|
|
5
5
|
const now = options.now ?? (() => Date.now());
|
|
6
|
-
const entities = options.entities ?? [];
|
|
7
6
|
const entries = new Map();
|
|
8
7
|
const flights = new Map();
|
|
9
8
|
/** The answer to `key`: kept while fresh; else the request already flying for it; else a new one. */
|
|
10
|
-
function remembered(key, read, signal) {
|
|
9
|
+
function remembered(key, operation, read, signal) {
|
|
11
10
|
if (signal?.aborted)
|
|
12
11
|
return Promise.reject(signal.reason);
|
|
13
12
|
const kept = entries.get(key);
|
|
14
13
|
if (kept !== undefined && now() - kept.at < ttl)
|
|
15
14
|
return Promise.resolve(kept.answer);
|
|
16
|
-
return awaited(key, flights.get(key) ?? fly(key, read), signal);
|
|
15
|
+
return awaited(key, flights.get(key) ?? fly(key, operation, read), signal);
|
|
17
16
|
}
|
|
18
|
-
function fly(key, read) {
|
|
17
|
+
function fly(key, operation, read) {
|
|
19
18
|
const aborter = new AbortController();
|
|
20
|
-
const flight = {
|
|
19
|
+
const flight = {
|
|
20
|
+
answer: Promise.resolve(),
|
|
21
|
+
aborter,
|
|
22
|
+
waiting: 0,
|
|
23
|
+
stale: false,
|
|
24
|
+
operation,
|
|
25
|
+
};
|
|
21
26
|
flight.answer = read(aborter.signal)
|
|
22
27
|
.then((answer) => {
|
|
23
28
|
if (!flight.stale)
|
|
24
|
-
entries.set(key, { at: now(), answer });
|
|
29
|
+
entries.set(key, { at: now(), answer, operation });
|
|
25
30
|
return answer;
|
|
26
31
|
})
|
|
27
32
|
.finally(() => {
|
|
@@ -58,71 +63,51 @@ export function cachedTransport(transport, options = {}) {
|
|
|
58
63
|
});
|
|
59
64
|
});
|
|
60
65
|
}
|
|
61
|
-
/** Forget every answer
|
|
62
|
-
*
|
|
63
|
-
const forget = (
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
const touched = (key) => targets.some((path) => under(key.split(" ", 2)[1] ?? "", path));
|
|
67
|
-
for (const key of [...entries.keys()])
|
|
68
|
-
if (touched(key))
|
|
66
|
+
/** Forget every answer `touched` says, and leave behind the ones still flying for it — one
|
|
67
|
+
* walk over each, whatever their number. */
|
|
68
|
+
const forget = (touched) => {
|
|
69
|
+
for (const [key, entry] of [...entries])
|
|
70
|
+
if (touched(entry.operation))
|
|
69
71
|
entries.delete(key);
|
|
70
72
|
for (const [key, flight] of [...flights]) {
|
|
71
|
-
if (!touched(
|
|
73
|
+
if (!touched(flight.operation))
|
|
72
74
|
continue;
|
|
73
75
|
flight.stale = true;
|
|
74
76
|
flights.delete(key);
|
|
75
77
|
}
|
|
76
78
|
};
|
|
77
|
-
const changed = (change) => forget(
|
|
78
|
-
const invalidate = (
|
|
79
|
-
if (
|
|
80
|
-
return forget(
|
|
79
|
+
const changed = (change) => forget((operation) => touchesOperation(change, operation));
|
|
80
|
+
const invalidate = (entities) => {
|
|
81
|
+
if (entities !== undefined)
|
|
82
|
+
return forget((operation) => operation.entities.some((one) => entities.includes(one)));
|
|
81
83
|
entries.clear();
|
|
82
84
|
for (const flight of flights.values())
|
|
83
85
|
flight.stale = true;
|
|
84
86
|
flights.clear();
|
|
85
87
|
};
|
|
86
|
-
|
|
88
|
+
const cached = {
|
|
87
89
|
// A call's own headers (a use case's trace) never change the answer: they travel, and the
|
|
88
90
|
// answer is kept by the question alone.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// never kept — it goes to the server every time.
|
|
97
|
-
...(transport.read === undefined
|
|
98
|
-
? {}
|
|
99
|
-
: {
|
|
100
|
-
read: (route, signal, options) => transport.read(route, signal, options),
|
|
101
|
-
}),
|
|
102
|
-
// An export streamed and a file's bytes are never an answer to keep: they pass through.
|
|
103
|
-
...(transport.download === undefined
|
|
104
|
-
? {}
|
|
105
|
-
: {
|
|
106
|
-
download: (route, signal, options) => transport.download(route, signal, options),
|
|
107
|
-
}),
|
|
108
|
-
...(transport.upload === undefined
|
|
109
|
-
? {}
|
|
110
|
-
: {
|
|
111
|
-
upload: (link, file, signal, options) => transport.upload(link, file, signal, options),
|
|
112
|
-
}),
|
|
113
|
-
async send(method, route, body, signal, sending) {
|
|
91
|
+
async call(operation, input, call = {}) {
|
|
92
|
+
// Only what a write can make old is kept: a Query of an entity. One of none — who the
|
|
93
|
+
// caller is, the context's own — passes through, as an answer of bytes does.
|
|
94
|
+
if (operation.query && !operation.streamed && operation.entities.length > 0) {
|
|
95
|
+
const { signal, ...rest } = call;
|
|
96
|
+
return remembered(`${operation.identity} ${JSON.stringify(input ?? {})}`, operation, (flying) => transport.call(operation, input, { ...rest, signal: flying }), signal);
|
|
97
|
+
}
|
|
114
98
|
try {
|
|
115
|
-
return await transport.
|
|
99
|
+
return await transport.call(operation, input, call);
|
|
116
100
|
}
|
|
117
101
|
finally {
|
|
118
102
|
// Even a refused write may have changed something (a 409 says someone else did); a
|
|
119
|
-
// preview or a dry run changes nothing (`changeOf`).
|
|
120
|
-
const change = changeOf(
|
|
103
|
+
// Query, a preview or a dry run changes nothing (`changeOf`).
|
|
104
|
+
const change = changeOf(operation, input);
|
|
121
105
|
if (change !== undefined)
|
|
122
106
|
changed(change);
|
|
123
107
|
}
|
|
124
108
|
},
|
|
125
109
|
invalidate,
|
|
126
110
|
changed,
|
|
127
|
-
}
|
|
111
|
+
};
|
|
112
|
+
return bindableOperations(markedAs(cached, transport));
|
|
128
113
|
}
|