@sincpro/web-framework 0.4.2 → 1.0.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 +46 -40
- package/dist/core/discovery.d.ts +47 -0
- package/dist/core/discovery.js +68 -0
- package/dist/core/edit.d.ts +35 -6
- package/dist/core/edit.js +57 -4
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/meta.d.ts +7 -0
- package/dist/core/meta.js +1 -1
- package/dist/core/metas.d.ts +4 -5
- package/dist/core/rest.d.ts +8 -0
- package/dist/core/rest.js +62 -3
- package/dist/core/schema.d.ts +5 -12
- package/dist/core/trail.js +1 -4
- package/dist/react/useGroups.js +1 -2
- package/dist/react/useHistory.js +1 -1
- package/dist/react/useListing.js +6 -6
- package/dist/react/useLookup.js +2 -3
- package/dist/react/usePivot.js +0 -1
- package/dist/react/useRecord.d.ts +2 -1
- package/dist/react/useRecord.js +15 -3
- package/dist/react/useRelated.js +2 -2
- package/dist/web/list/EntitySearchBar.js +2 -2
- package/dist/web/list/search.js +1 -1
- package/dist/web/record/lines.js +16 -9
- package/dist/web/record/opening.js +1 -1
- package/dist/web/workspace/composer.js +1 -4
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -150,6 +150,12 @@ export const transport = restTransport({
|
|
|
150
150
|
});
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
+
The definition of every model — its fields, operators, hints, widgets, formulas — is read from
|
|
154
|
+
the service's discovery document (`/openapi.json` by default; `document:` names another, `null`
|
|
155
|
+
reads none), once: each answer says only its `model_version`, and another version reads the
|
|
156
|
+
document again, revalidated by its `ETag`. A form computes a published formula itself and asks the
|
|
157
|
+
server for a preview only when a change reaches something it cannot answer.
|
|
158
|
+
|
|
153
159
|
**3. The entities** — declared once: where each is read and written, and its key in the
|
|
154
160
|
workspace (`domain:kind`). `summary` only when its fields are not the conventional ones.
|
|
155
161
|
|
|
@@ -390,46 +396,46 @@ Everything is imported from `@sincpro/web-framework`.
|
|
|
390
396
|
|
|
391
397
|
## Where it stands
|
|
392
398
|
|
|
393
|
-
| Piece | What it solves
|
|
394
|
-
| --------------------------------------- |
|
|
395
|
-
| `restTransport`, `memoryTransport` | The backend, or the same engine in memory
|
|
396
|
-
| `defineMeta`, `metaFromSchema` | A model by hand, or completed from OpenAPI
|
|
397
|
-
| `useListing`, `EntityList` | N records: criteria, search bar, builder, paging
|
|
398
|
-
| `useRecord`, `factsOf`, `RecordLines` | One record: facts, relations with their real total
|
|
399
|
-
| Preloaded definitions | `FrameworkProvider metas`: the
|
|
400
|
-
| `useLookup`, `EntityPicker` | Literal search: a many2one select, ⌘K
|
|
401
|
-
| `useRecord` + `RecordField`, `dirtyOf` | Editing: hints evaluated live, preview, save with version (409), server drafts
|
|
402
|
-
| `useCommand`, `CommandButton` | An entity's actions, with a dry run before what destroys
|
|
403
|
-
| `useHistory` | Business events in `Record.Activity` (comments: backend first)
|
|
404
|
-
| `entityView` | An entity as a composer view: list, record, ⌘K search
|
|
405
|
-
| `<SincproApp>` | The application context in one place, the workspace dressed as web-ui (`webUiSkin`)
|
|
406
|
-
| `useRecordInWorkspace` | A record tells the workspace its real name and its unsaved work (composer 1.0)
|
|
407
|
-
| Paging by pages, ceiling on «more» | One page on screen, walked by the server's cursor: a million rows never freeze it
|
|
408
|
-
| `cachedTransport` | Repeated reads from memory, forgotten when a write touches the entity (on in `SincproApp`)
|
|
409
|
-
| `EntitySearchBar` | The search bar + criteria builder as a loose piece, for any `List`
|
|
410
|
-
| `EntityList` views | The same set as table, rows or board
|
|
411
|
-
| `useRelated`, `RelatedList` | A record's relation as a live list: searched and paged by the server, inside a form
|
|
412
|
-
| `EntityPicker` chooser | «see all…» opens the whole set, searched on the server: a many2one over millions
|
|
413
|
-
| `useRecord(entity, "")`, `create` | A new record: the model's defaults, saved to `create` (or `edit`), then it IS that record
|
|
414
|
-
| `retryKeys`, `Idempotency-Key` | A Command or a create retried after a lost answer runs once, not twice
|
|
415
|
-
| `entity.newRef()`, «New» in the list | The record's form with no id, in a page or a window; replaced by the record once created
|
|
416
|
-
| `EntityPicker criteria` | A many2one narrowed by another field: the invoices OF the chosen customer
|
|
417
|
-
| `chooserIn`, `entity.chooserRef()` | «see all…» as the composer's chooser: a row answers (`api.pick`)
|
|
418
|
-
| `EntityPicker` / `EntityTags` in a view | Open and choose in the workspace by themselves; the chooser carries the picker's cut
|
|
419
|
-
| `newEntityId`, `edit` on a new record | A new record born under a UUID v7 minted here: its draft and its save go through `Edit`
|
|
420
|
-
| `useGroups`, «Group by» | Groups counted by the server over the whole set; a group's rows read when it is opened
|
|
421
|
-
| `defineList`, `listView` | A named list (a fixed scope, its columns and filters) as data, and as a workspace view
|
|
422
|
-
| `EntityPicker` `browse`, `columns` | The chooser always a click away, as a table searched literally by the server
|
|
423
|
-
| `useFollowed` | A detail panel follows the record the person is on, without knowing the list
|
|
424
|
-
| `commands`, `useRowCommands` | An entity's Commands on each row, idempotent, offered only where `when` holds
|
|
425
|
-
| `summaryOf`, `cardOf`, `relationOf` | Any record at any size: name, description, state, type, picture, who made and changed it
|
|
426
|
-
| `openIn`, `RelatedRecord` | A related record opens in a modal; «Abrir en…» for the rest; never a modal over a modal
|
|
427
|
-
| Literal search everywhere | Picker: the first ten, the server's search as you type; tables: «Buscar «X»» on Enter
|
|
428
|
-
| `EntityTags` | A many2many as chips over thousands: the server's search, faces, the chosen never again
|
|
429
|
-
| `RecordField` + `entities` | A many2one / one2many drawn from the model alone, opened where the view says
|
|
430
|
-
| `EntityRecord`, `formOf` | Any entity's record screen without writing it
|
|
431
|
-
| `Trail`, `Record.Pager` | Previous / next from a record, across the server's pages
|
|
432
|
-
| `EntityList sums` | Each group says how much it adds up, summed by the server over all of it
|
|
399
|
+
| Piece | What it solves | Status |
|
|
400
|
+
| --------------------------------------- | -------------------------------------------------------------------------------------------- | ------ |
|
|
401
|
+
| `restTransport`, `memoryTransport` | The backend, or the same engine in memory | ✅ |
|
|
402
|
+
| `defineMeta`, `metaFromSchema` | A model by hand, or completed from OpenAPI | ✅ |
|
|
403
|
+
| `useListing`, `EntityList` | N records: criteria, search bar, builder, paging | ✅ |
|
|
404
|
+
| `useRecord`, `factsOf`, `RecordLines` | One record: facts, relations with their real total | ✅ |
|
|
405
|
+
| Preloaded definitions | `FrameworkProvider metas`: the models of the discovery document, or of an exported metamodel | ✅ |
|
|
406
|
+
| `useLookup`, `EntityPicker` | Literal search: a many2one select, ⌘K | ✅ |
|
|
407
|
+
| `useRecord` + `RecordField`, `dirtyOf` | Editing: hints evaluated live, preview, save with version (409), server drafts | ✅ |
|
|
408
|
+
| `useCommand`, `CommandButton` | An entity's actions, with a dry run before what destroys | ✅ |
|
|
409
|
+
| `useHistory` | Business events in `Record.Activity` (comments: backend first) | ✅ |
|
|
410
|
+
| `entityView` | An entity as a composer view: list, record, ⌘K search | ✅ |
|
|
411
|
+
| `<SincproApp>` | The application context in one place, the workspace dressed as web-ui (`webUiSkin`) | ✅ |
|
|
412
|
+
| `useRecordInWorkspace` | A record tells the workspace its real name and its unsaved work (composer 1.0) | ✅ |
|
|
413
|
+
| Paging by pages, ceiling on «more» | One page on screen, walked by the server's cursor: a million rows never freeze it | ✅ |
|
|
414
|
+
| `cachedTransport` | Repeated reads from memory, forgotten when a write touches the entity (on in `SincproApp`) | ✅ |
|
|
415
|
+
| `EntitySearchBar` | The search bar + criteria builder as a loose piece, for any `List` | ✅ |
|
|
416
|
+
| `EntityList` views | The same set as table, rows or board | ✅ |
|
|
417
|
+
| `useRelated`, `RelatedList` | A record's relation as a live list: searched and paged by the server, inside a form | ✅ |
|
|
418
|
+
| `EntityPicker` chooser | «see all…» opens the whole set, searched on the server: a many2one over millions | ✅ |
|
|
419
|
+
| `useRecord(entity, "")`, `create` | A new record: the model's defaults, saved to `create` (or `edit`), then it IS that record | ✅ |
|
|
420
|
+
| `retryKeys`, `Idempotency-Key` | A Command or a create retried after a lost answer runs once, not twice | ✅ |
|
|
421
|
+
| `entity.newRef()`, «New» in the list | The record's form with no id, in a page or a window; replaced by the record once created | ✅ |
|
|
422
|
+
| `EntityPicker criteria` | A many2one narrowed by another field: the invoices OF the chosen customer | ✅ |
|
|
423
|
+
| `chooserIn`, `entity.chooserRef()` | «see all…» as the composer's chooser: a row answers (`api.pick`) | ✅ |
|
|
424
|
+
| `EntityPicker` / `EntityTags` in a view | Open and choose in the workspace by themselves; the chooser carries the picker's cut | ✅ |
|
|
425
|
+
| `newEntityId`, `edit` on a new record | A new record born under a UUID v7 minted here: its draft and its save go through `Edit` | ✅ |
|
|
426
|
+
| `useGroups`, «Group by» | Groups counted by the server over the whole set; a group's rows read when it is opened | ✅ |
|
|
427
|
+
| `defineList`, `listView` | A named list (a fixed scope, its columns and filters) as data, and as a workspace view | ✅ |
|
|
428
|
+
| `EntityPicker` `browse`, `columns` | The chooser always a click away, as a table searched literally by the server | ✅ |
|
|
429
|
+
| `useFollowed` | A detail panel follows the record the person is on, without knowing the list | ✅ |
|
|
430
|
+
| `commands`, `useRowCommands` | An entity's Commands on each row, idempotent, offered only where `when` holds | ✅ |
|
|
431
|
+
| `summaryOf`, `cardOf`, `relationOf` | Any record at any size: name, description, state, type, picture, who made and changed it | ✅ |
|
|
432
|
+
| `openIn`, `RelatedRecord` | A related record opens in a modal; «Abrir en…» for the rest; never a modal over a modal | ✅ |
|
|
433
|
+
| Literal search everywhere | Picker: the first ten, the server's search as you type; tables: «Buscar «X»» on Enter | ✅ |
|
|
434
|
+
| `EntityTags` | A many2many as chips over thousands: the server's search, faces, the chosen never again | ✅ |
|
|
435
|
+
| `RecordField` + `entities` | A many2one / one2many drawn from the model alone, opened where the view says | ✅ |
|
|
436
|
+
| `EntityRecord`, `formOf` | Any entity's record screen without writing it | ✅ |
|
|
437
|
+
| `Trail`, `Record.Pager` | Previous / next from a record, across the server's pages | ✅ |
|
|
438
|
+
| `EntityList sums` | Each group says how much it adds up, summed by the server over all of it | ✅ |
|
|
433
439
|
|
|
434
440
|
What it does **not** do: mobile (`sincpro_mobile` has its own core), sessions and login (the
|
|
435
441
|
application's), routing (composer's), string-named widget registries, technical logs on a
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Meta } from "@sincpro/criteria";
|
|
2
|
+
/**
|
|
3
|
+
* The discovery document of a bounded context, as far as this reads it: its paths, each
|
|
4
|
+
* operation with the entities it belongs to, and the published contract of every model.
|
|
5
|
+
*
|
|
6
|
+
* Context: sincpro_framework describes a model once — JSON Schema with `x-sincpro`, under the
|
|
7
|
+
* document's `components.schemas` — and every read answers only the version of it
|
|
8
|
+
* (`model_version`). So the definition a list, a form and a select are built from is read here,
|
|
9
|
+
* once, and asked for again only when an answer says another version.
|
|
10
|
+
*/
|
|
11
|
+
export type DiscoveryDocument = {
|
|
12
|
+
paths?: Readonly<Record<string, Readonly<Record<string, DiscoveryOperation>>>>;
|
|
13
|
+
components?: {
|
|
14
|
+
schemas?: Readonly<Record<string, DocumentSchema>>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export type DiscoveryOperation = {
|
|
18
|
+
"x-sincpro-entities"?: readonly string[];
|
|
19
|
+
responses?: Readonly<Record<string, {
|
|
20
|
+
content?: Readonly<Record<string, {
|
|
21
|
+
schema?: DocumentSchema;
|
|
22
|
+
}>>;
|
|
23
|
+
}>>;
|
|
24
|
+
};
|
|
25
|
+
type DocumentSchema = {
|
|
26
|
+
$ref?: string;
|
|
27
|
+
items?: DocumentSchema;
|
|
28
|
+
anyOf?: readonly DocumentSchema[];
|
|
29
|
+
properties?: Readonly<Record<string, DocumentSchema>>;
|
|
30
|
+
"x-sincpro"?: {
|
|
31
|
+
entity?: string;
|
|
32
|
+
version?: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* The model a request to `path` answers, by the name of its contract in the document: the
|
|
37
|
+
* entity the operation says it belongs to, else the one its answer holds.
|
|
38
|
+
*
|
|
39
|
+
* modelAt(published, "/v1/projects/p1", "get") // "Project"
|
|
40
|
+
*/
|
|
41
|
+
export declare function modelAt(published: DiscoveryDocument, path: string, method: string): string | undefined;
|
|
42
|
+
/** The definition of the model named `name`, read from its contract, and its version. */
|
|
43
|
+
export declare function definitionOf(published: DiscoveryDocument, name: string): {
|
|
44
|
+
meta: Meta;
|
|
45
|
+
version: string | null;
|
|
46
|
+
} | undefined;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { metaFromContract, versionOf } from "@sincpro/criteria";
|
|
2
|
+
function nameOfRef(ref) {
|
|
3
|
+
return ref === undefined ? undefined : ref.slice(ref.lastIndexOf("/") + 1);
|
|
4
|
+
}
|
|
5
|
+
/** Whether a document path (`/v1/projects/{id}`) answers a request path (`/v1/projects/p1`). */
|
|
6
|
+
function answers(template, path) {
|
|
7
|
+
const pattern = template
|
|
8
|
+
.split("/")
|
|
9
|
+
.map((part) => /^\{[^}]+\}$/.test(part) ? "[^/]+" : part.replace(/[.*+?^$()|[\]\\]/g, "\\$&"))
|
|
10
|
+
.join("/");
|
|
11
|
+
return new RegExp(`^${pattern}$`).test(path);
|
|
12
|
+
}
|
|
13
|
+
/** The entity a schema describes, or the one its records hold: an answer's records field. */
|
|
14
|
+
function entityIn(schema, schemas, seen = new Set()) {
|
|
15
|
+
if (schema === undefined)
|
|
16
|
+
return undefined;
|
|
17
|
+
const named = nameOfRef(schema.$ref);
|
|
18
|
+
if (named !== undefined) {
|
|
19
|
+
if (seen.has(named))
|
|
20
|
+
return undefined;
|
|
21
|
+
seen.add(named);
|
|
22
|
+
const target = schemas[named];
|
|
23
|
+
return target?.["x-sincpro"]?.entity !== undefined
|
|
24
|
+
? named
|
|
25
|
+
: entityIn(target, schemas, seen);
|
|
26
|
+
}
|
|
27
|
+
for (const one of [schema.items, ...(schema.anyOf ?? [])]) {
|
|
28
|
+
const found = entityIn(one, schemas, seen);
|
|
29
|
+
if (found !== undefined)
|
|
30
|
+
return found;
|
|
31
|
+
}
|
|
32
|
+
for (const one of Object.values(schema.properties ?? {})) {
|
|
33
|
+
const found = entityIn(one, schemas, seen);
|
|
34
|
+
if (found !== undefined)
|
|
35
|
+
return found;
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The model a request to `path` answers, by the name of its contract in the document: the
|
|
41
|
+
* entity the operation says it belongs to, else the one its answer holds.
|
|
42
|
+
*
|
|
43
|
+
* modelAt(published, "/v1/projects/p1", "get") // "Project"
|
|
44
|
+
*/
|
|
45
|
+
export function modelAt(published, path, method) {
|
|
46
|
+
const schemas = published.components?.schemas ?? {};
|
|
47
|
+
for (const [template, item] of Object.entries(published.paths ?? {})) {
|
|
48
|
+
if (!answers(template, path))
|
|
49
|
+
continue;
|
|
50
|
+
const operation = item[method.toLowerCase()];
|
|
51
|
+
if (operation === undefined)
|
|
52
|
+
continue;
|
|
53
|
+
const declared = operation["x-sincpro-entities"]?.[0];
|
|
54
|
+
if (declared !== undefined && schemas[declared] !== undefined)
|
|
55
|
+
return declared;
|
|
56
|
+
const answered = operation.responses?.["200"]?.content?.["application/json"]?.schema;
|
|
57
|
+
return entityIn(answered, schemas);
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
/** The definition of the model named `name`, read from its contract, and its version. */
|
|
62
|
+
export function definitionOf(published, name) {
|
|
63
|
+
const schemas = (published.components?.schemas ?? {});
|
|
64
|
+
const contract = schemas[name];
|
|
65
|
+
if (contract?.["x-sincpro"] === undefined)
|
|
66
|
+
return undefined;
|
|
67
|
+
return { meta: metaFromContract(contract, schemas), version: versionOf(contract) };
|
|
68
|
+
}
|
package/dist/core/edit.d.ts
CHANGED
|
@@ -18,23 +18,52 @@ export type FieldState = {
|
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
20
20
|
* What a server preview said about a field. A list of records — an invoice's lines — carries
|
|
21
|
-
* each one's own in `items`,
|
|
22
|
-
* `FieldState.items`).
|
|
21
|
+
* each one's own in `items`, by the line: its identity, or its position for a line that has
|
|
22
|
+
* none (sincpro_framework's `FieldState.items`).
|
|
23
23
|
*/
|
|
24
24
|
export type ServerFieldState = Partial<FieldState> & {
|
|
25
|
-
items?:
|
|
25
|
+
items?: Readonly<Record<string, Readonly<Record<string, ServerFieldState>>>>;
|
|
26
26
|
};
|
|
27
27
|
export type FieldStates = Readonly<Record<string, ServerFieldState>>;
|
|
28
28
|
/** What the server's preview warned about, pointing where it belongs (`path`: the field, or a
|
|
29
|
-
* line's cell — `["lines",
|
|
29
|
+
* line's cell — `["lines", "0192…", "price"]`, the line by its identity, by its position when
|
|
30
|
+
* it has none). It refuses nothing. sincpro_framework's warning. */
|
|
30
31
|
export type Advice = {
|
|
31
32
|
message: string;
|
|
32
33
|
field?: string | null;
|
|
33
34
|
path?: readonly (string | number)[];
|
|
35
|
+
/** The rule that said it (`Sale.delivery_when_confirmed`), when one did. */
|
|
36
|
+
rule?: string | null;
|
|
37
|
+
/** A rule the save enforces (`@check`): the save will be refused while it holds. */
|
|
38
|
+
blocks_save?: boolean;
|
|
34
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* What a change of `name` moves, computed here when every field it reaches says how
|
|
42
|
+
* (`computes`, the formula the server published): each in the order the server runs them, a
|
|
43
|
+
* computation of a computation reading the one before. `undefined` when one of them does not
|
|
44
|
+
* say — the server's preview answers it — or the change reaches nothing.
|
|
45
|
+
*
|
|
46
|
+
* computedLocally(saleMeta, { subtotal: "25.30", discount: "1.5" }, "discount")
|
|
47
|
+
* -> { total: "22.105" }
|
|
48
|
+
*/
|
|
49
|
+
export declare function computedLocally(meta: Meta | null | undefined, values: AnyRecord, name: string): AnyRecord | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Whether a change of `name` needs the server's preview: when the model says what each change
|
|
52
|
+
* reaches (`affects`, `judged_by` — sincpro_framework publishes them in the contract), only a
|
|
53
|
+
* field that reaches something does; a model that says nothing of it is always asked.
|
|
54
|
+
*/
|
|
55
|
+
export declare function needsPreview(meta: Meta | null | undefined, name: string): boolean;
|
|
35
56
|
export declare function fieldStateOf(meta: Meta | null | undefined, name: string, values: AnyRecord, fromServer?: FieldStates): FieldState;
|
|
36
|
-
/**
|
|
37
|
-
|
|
57
|
+
/**
|
|
58
|
+
* The states the server said of one line of a list of records: under the line's identity —
|
|
59
|
+
* the same line wherever it moved — or under its position when it has none.
|
|
60
|
+
*/
|
|
61
|
+
export declare function lineStatesOf(fromServer: FieldStates | undefined, name: string, line: AnyRecord | undefined, index: number, identity: string): FieldStates | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Where the server names a line in a path, most specific first: `lines/0192…` by its identity,
|
|
64
|
+
* `lines/2` by its position — an error, a warning and a state are looked for under each.
|
|
65
|
+
*/
|
|
66
|
+
export declare function linePlacesOf(name: string, line: AnyRecord, index: number, identity: string): string[];
|
|
38
67
|
/** The fields whose value differs from the record's — what a save or a draft sends. */
|
|
39
68
|
export declare function changesOf(record: AnyRecord, values: AnyRecord): AnyRecord;
|
|
40
69
|
/** What is missing before it can be saved: a required, visible, editable field left empty. */
|
package/dist/core/edit.js
CHANGED
|
@@ -1,4 +1,41 @@
|
|
|
1
|
-
import { matches, } from "@sincpro/criteria";
|
|
1
|
+
import { matches, valueOf, } from "@sincpro/criteria";
|
|
2
|
+
/**
|
|
3
|
+
* What a change of `name` moves, computed here when every field it reaches says how
|
|
4
|
+
* (`computes`, the formula the server published): each in the order the server runs them, a
|
|
5
|
+
* computation of a computation reading the one before. `undefined` when one of them does not
|
|
6
|
+
* say — the server's preview answers it — or the change reaches nothing.
|
|
7
|
+
*
|
|
8
|
+
* computedLocally(saleMeta, { subtotal: "25.30", discount: "1.5" }, "discount")
|
|
9
|
+
* -> { total: "22.105" }
|
|
10
|
+
*/
|
|
11
|
+
export function computedLocally(meta, values, name) {
|
|
12
|
+
const reached = meta?.fields[name]?.affects ?? [];
|
|
13
|
+
if (meta == null || reached.length === 0)
|
|
14
|
+
return undefined;
|
|
15
|
+
const working = { ...values };
|
|
16
|
+
const moved = {};
|
|
17
|
+
for (const one of reached) {
|
|
18
|
+
const formula = meta.fields[one]?.computes;
|
|
19
|
+
if (formula === undefined || formula === null)
|
|
20
|
+
return undefined;
|
|
21
|
+
working[one] = valueOf(formula, working);
|
|
22
|
+
moved[one] = working[one];
|
|
23
|
+
}
|
|
24
|
+
return moved;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Whether a change of `name` needs the server's preview: when the model says what each change
|
|
28
|
+
* reaches (`affects`, `judged_by` — sincpro_framework publishes them in the contract), only a
|
|
29
|
+
* field that reaches something does; a model that says nothing of it is always asked.
|
|
30
|
+
*/
|
|
31
|
+
export function needsPreview(meta, name) {
|
|
32
|
+
const fields = Object.values(meta?.fields ?? {});
|
|
33
|
+
const says = fields.some((one) => one.affects !== undefined || one.judged_by !== undefined);
|
|
34
|
+
if (!says)
|
|
35
|
+
return true;
|
|
36
|
+
const field = meta?.fields[name];
|
|
37
|
+
return (field?.affects?.length ?? 0) > 0 || (field?.judged_by?.length ?? 0) > 0;
|
|
38
|
+
}
|
|
2
39
|
function holds(values, condition, meta) {
|
|
3
40
|
if (condition === null || condition === undefined)
|
|
4
41
|
return false;
|
|
@@ -19,9 +56,25 @@ export function fieldStateOf(meta, name, values, fromServer) {
|
|
|
19
56
|
const { items: _lines, ...server } = fromServer?.[name] ?? {};
|
|
20
57
|
return { ...own, ...server };
|
|
21
58
|
}
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
59
|
+
/**
|
|
60
|
+
* The states the server said of one line of a list of records: under the line's identity —
|
|
61
|
+
* the same line wherever it moved — or under its position when it has none.
|
|
62
|
+
*/
|
|
63
|
+
export function lineStatesOf(fromServer, name, line, index, identity) {
|
|
64
|
+
const items = fromServer?.[name]?.items ?? {};
|
|
65
|
+
const own = line?.[identity];
|
|
66
|
+
const named = own === undefined || own === null || own === "" ? undefined : items[String(own)];
|
|
67
|
+
return named ?? items[String(index)];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Where the server names a line in a path, most specific first: `lines/0192…` by its identity,
|
|
71
|
+
* `lines/2` by its position — an error, a warning and a state are looked for under each.
|
|
72
|
+
*/
|
|
73
|
+
export function linePlacesOf(name, line, index, identity) {
|
|
74
|
+
const own = line[identity];
|
|
75
|
+
return own === undefined || own === null || own === ""
|
|
76
|
+
? [`${name}/${index}`]
|
|
77
|
+
: [`${name}/${String(own)}`, `${name}/${index}`];
|
|
25
78
|
}
|
|
26
79
|
/** The fields whose value differs from the record's — what a save or a draft sends. */
|
|
27
80
|
export function changesOf(record, values) {
|
package/dist/core/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { type CachedTransport, cachedTransport, type CacheOptions, } from "./cache.js";
|
|
7
7
|
export { ENGLISH_FRAMEWORK_COPY, type FrameworkCopy, frameworkCopy, installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "./copy.js";
|
|
8
|
-
export { type Advice, adviceAt, changesOf, creationOf, defaultsOf, errorAt, errorsByField, type FieldState, fieldStateOf, type FieldStates, lineStatesOf, missingOf, pathOf, type ServerFieldState, } from "./edit.js";
|
|
8
|
+
export { type Advice, adviceAt, changesOf, computedLocally, creationOf, defaultsOf, errorAt, errorsByField, type FieldState, fieldStateOf, type FieldStates, linePlacesOf, lineStatesOf, missingOf, needsPreview, pathOf, type ServerFieldState, } from "./edit.js";
|
|
9
9
|
export { type Entity, entity, type EntityRef, type EntityRoutes, listRoute, NEW_PARAM, pathFor, PICK_PARAM, QUERY_PARAM, SCOPE_PARAM, scopeOfRef, startingValuesOf, TRAIL_PARAM, WITH_PARAM, type WriteRoute, writeRoute, } from "./entity.js";
|
|
10
10
|
export { type FormLayout, formOf } from "./form.js";
|
|
11
11
|
export { type HistoryEntry, historyOf } from "./history.js";
|
package/dist/core/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { cachedTransport, } from "./cache.js";
|
|
7
7
|
export { ENGLISH_FRAMEWORK_COPY, frameworkCopy, installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "./copy.js";
|
|
8
|
-
export { adviceAt, changesOf, creationOf, defaultsOf, errorAt, errorsByField, fieldStateOf, lineStatesOf, missingOf, pathOf, } from "./edit.js";
|
|
8
|
+
export { adviceAt, changesOf, computedLocally, creationOf, defaultsOf, errorAt, errorsByField, fieldStateOf, linePlacesOf, lineStatesOf, missingOf, needsPreview, pathOf, } from "./edit.js";
|
|
9
9
|
export { entity, listRoute, NEW_PARAM, pathFor, PICK_PARAM, QUERY_PARAM, SCOPE_PARAM, scopeOfRef, startingValuesOf, TRAIL_PARAM, WITH_PARAM, writeRoute, } from "./entity.js";
|
|
10
10
|
export { formOf } from "./form.js";
|
|
11
11
|
export { historyOf } from "./history.js";
|
package/dist/core/meta.d.ts
CHANGED
|
@@ -63,6 +63,13 @@ export declare const field: {
|
|
|
63
63
|
visible_when?: Expression | null;
|
|
64
64
|
sortable: boolean;
|
|
65
65
|
ops: Operator[];
|
|
66
|
+
widget?: string;
|
|
67
|
+
affects?: string[];
|
|
68
|
+
judged_by?: string[];
|
|
69
|
+
holds?: Expression | null;
|
|
70
|
+
computes?: import("@sincpro/criteria").Formula | null;
|
|
71
|
+
navigable?: boolean;
|
|
72
|
+
total?: string | null;
|
|
66
73
|
many?: boolean;
|
|
67
74
|
relation?: string | null;
|
|
68
75
|
identified_by?: string | null;
|
package/dist/core/meta.js
CHANGED
|
@@ -109,7 +109,7 @@ function searchTemplate(fields) {
|
|
|
109
109
|
});
|
|
110
110
|
const [only] = fields;
|
|
111
111
|
return {
|
|
112
|
-
|
|
112
|
+
selection: fields.length === 1 && only !== undefined ? like(only) : { any: fields.map(like) },
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
115
|
/** A whole definition, from its fields. See the file header. */
|
package/dist/core/metas.d.ts
CHANGED
|
@@ -2,11 +2,10 @@ import type { Meta } from "@sincpro/criteria";
|
|
|
2
2
|
/**
|
|
3
3
|
* The model definitions already known, by entity key (`"billing:invoice"`).
|
|
4
4
|
*
|
|
5
|
-
* Context: sincpro_framework
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* ask with `meta: false` and draw their labels before the rows arrive.
|
|
5
|
+
* Context: sincpro_framework publishes each model once, in the discovery document the
|
|
6
|
+
* transport reads (`core/discovery`); an answer carries only its version. This keeps the
|
|
7
|
+
* definitions ACROSS readings, so the second list of the same entity, the record opened from it
|
|
8
|
+
* and the select that points at it draw their labels before the rows arrive.
|
|
10
9
|
*
|
|
11
10
|
* Seeded, it is the preload: definitions written at build time (a snapshot of the server's,
|
|
12
11
|
* or `defineMeta`) reach the first screen with no request at all.
|
package/dist/core/rest.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ import { type Transport } from "./transport.js";
|
|
|
9
9
|
* one record (`one()`), a write (`send()`, with its `Idempotency-Key`), and its refusals as a
|
|
10
10
|
* `TransportError`, the one error every screen explains.
|
|
11
11
|
*
|
|
12
|
+
* The definition of each model — what a list, a form and a select are built from — is read
|
|
13
|
+
* from the bounded context's discovery document (`document`, `/openapi.json` by default), once,
|
|
14
|
+
* and read again only when an answer says another version of its model (`model_version`); the
|
|
15
|
+
* document is revalidated with its `ETag`, so an unchanged one costs a `304`.
|
|
16
|
+
*
|
|
12
17
|
* const transport = restTransport({
|
|
13
18
|
* base: "/v1",
|
|
14
19
|
* headers: () => ({ Authorization: `Bearer ${session.secret}` }),
|
|
@@ -21,6 +26,9 @@ export type RestOptions = {
|
|
|
21
26
|
headers?: Record<string, string> | (() => Record<string, string>);
|
|
22
27
|
/** Defaults to the global `fetch`. Inject one for tests. */
|
|
23
28
|
fetch?: typeof fetch;
|
|
29
|
+
/** Where the bounded context's discovery document is: `"/openapi.json"` by default, at the
|
|
30
|
+
* origin of `base`. `null`: none is read, and the definitions come only from `metas`. */
|
|
31
|
+
document?: string | null;
|
|
24
32
|
};
|
|
25
33
|
export declare function urlOf<T>(base: string, route: string, criteria?: Criteria<T>): string;
|
|
26
34
|
export declare function restTransport(options?: RestOptions): Transport;
|
package/dist/core/rest.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { readProblem } from "@sincpro/criteria";
|
|
2
2
|
import { RestError, restSource } from "@sincpro/criteria/rest";
|
|
3
|
+
import { definitionOf, modelAt, } from "./discovery.js";
|
|
3
4
|
import { TransportError, } from "./transport.js";
|
|
4
5
|
/** The keys of an answer that are not the record: what is left is the record's own field. */
|
|
5
|
-
const ENVELOPE = new Set(["cursor", "count", "
|
|
6
|
+
const ENVELOPE = new Set(["cursor", "count", "model_version", "dropped", "draft", "missing"]);
|
|
6
7
|
export function urlOf(base, route, criteria) {
|
|
7
8
|
const url = `${base}${route}`;
|
|
8
9
|
if (criteria === undefined)
|
|
@@ -10,10 +11,64 @@ export function urlOf(base, route, criteria) {
|
|
|
10
11
|
const joiner = url.includes("?") ? "&" : "?";
|
|
11
12
|
return `${url}${joiner}criteria=${encodeURIComponent(JSON.stringify(criteria))}`;
|
|
12
13
|
}
|
|
14
|
+
/** The path a route is asked at, without its query: what a document path is matched with. */
|
|
15
|
+
function pathOf(url) {
|
|
16
|
+
const path = url.split("?")[0] ?? url;
|
|
17
|
+
return /^https?:\/\//.test(path) ? new URL(path).pathname : path;
|
|
18
|
+
}
|
|
19
|
+
/** Where the document is: `document` as given when absolute, else at the origin of `base`. */
|
|
20
|
+
function documentUrl(base, document) {
|
|
21
|
+
if (/^https?:\/\//.test(document) || !/^https?:\/\//.test(base))
|
|
22
|
+
return document;
|
|
23
|
+
return new URL(document, base).toString();
|
|
24
|
+
}
|
|
13
25
|
export function restTransport(options = {}) {
|
|
14
26
|
const base = options.base ?? "";
|
|
15
27
|
const doFetch = options.fetch ?? ((input, init) => fetch(input, init));
|
|
16
28
|
const own = () => typeof options.headers === "function" ? options.headers() : (options.headers ?? {});
|
|
29
|
+
// The discovery document, read once; asked again — with its ETag — when an answer says a
|
|
30
|
+
// version of its model the document did not.
|
|
31
|
+
const located = options.document === null ? null : (options.document ?? "/openapi.json");
|
|
32
|
+
let held;
|
|
33
|
+
let tag = null;
|
|
34
|
+
function documentRead(fresh) {
|
|
35
|
+
if (located === null)
|
|
36
|
+
return Promise.resolve(null);
|
|
37
|
+
if (held !== undefined && !fresh)
|
|
38
|
+
return held;
|
|
39
|
+
const before = held;
|
|
40
|
+
held = (async () => {
|
|
41
|
+
try {
|
|
42
|
+
const response = await doFetch(documentUrl(base, located), {
|
|
43
|
+
headers: { ...own(), ...(tag === null ? {} : { "If-None-Match": tag }) },
|
|
44
|
+
});
|
|
45
|
+
if (response.status === 304 && before !== undefined)
|
|
46
|
+
return await before;
|
|
47
|
+
if (!response.ok)
|
|
48
|
+
return null;
|
|
49
|
+
tag = response.headers.get("etag");
|
|
50
|
+
return (await response.json());
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
})();
|
|
56
|
+
return held;
|
|
57
|
+
}
|
|
58
|
+
/** The definition of the model `url` answers; read again when `version` is not the one held. */
|
|
59
|
+
async function definitionAt(url, method, version) {
|
|
60
|
+
const published = await documentRead(false);
|
|
61
|
+
if (published === null)
|
|
62
|
+
return null;
|
|
63
|
+
const name = modelAt(published, pathOf(url), method);
|
|
64
|
+
if (name === undefined)
|
|
65
|
+
return null;
|
|
66
|
+
const known = definitionOf(published, name);
|
|
67
|
+
if (known === undefined || !version || known.version === version)
|
|
68
|
+
return known?.meta ?? null;
|
|
69
|
+
const again = await documentRead(true);
|
|
70
|
+
return (again === null ? undefined : definitionOf(again, name))?.meta ?? known.meta;
|
|
71
|
+
}
|
|
17
72
|
async function get(route, url, signal, write) {
|
|
18
73
|
const headers = write
|
|
19
74
|
? {
|
|
@@ -36,7 +91,11 @@ export function restTransport(options = {}) {
|
|
|
36
91
|
async list(route, criteria, signal) {
|
|
37
92
|
const source = restSource(`${base}${route}`, { headers: own, fetch: doFetch });
|
|
38
93
|
try {
|
|
39
|
-
|
|
94
|
+
const page = await source.read(criteria, signal);
|
|
95
|
+
return {
|
|
96
|
+
...page,
|
|
97
|
+
meta: page.meta ?? (await definitionAt(`${base}${route}`, "get", page.version)),
|
|
98
|
+
};
|
|
40
99
|
}
|
|
41
100
|
catch (error) {
|
|
42
101
|
if (error instanceof RestError)
|
|
@@ -52,7 +111,7 @@ export function restTransport(options = {}) {
|
|
|
52
111
|
throw new TransportError(route, 200, null, `${route} answered ${own.length} fields of its own (${own.join(", ")}); a record answers one`);
|
|
53
112
|
return {
|
|
54
113
|
record: answer[key],
|
|
55
|
-
meta: answer["
|
|
114
|
+
meta: await definitionAt(urlOf(base, route), "get", answer["model_version"]),
|
|
56
115
|
dropped: answer["dropped"] ?? [],
|
|
57
116
|
draft: answer["draft"] ?? null,
|
|
58
117
|
};
|
package/dist/core/schema.d.ts
CHANGED
|
@@ -2,19 +2,12 @@ import type { Meta } from "@sincpro/criteria";
|
|
|
2
2
|
/**
|
|
3
3
|
* A model definition read from a JSON Schema — what an OpenAPI document holds.
|
|
4
4
|
*
|
|
5
|
-
* Context:
|
|
6
|
-
*
|
|
5
|
+
* Context: a model a READ answers is published by sincpro_framework as its contract — JSON
|
|
6
|
+
* Schema with `x-sincpro` — and read by the transport (`metaFromContract`, `core/discovery`).
|
|
7
|
+
* What has no `x-sincpro` is a plain JSON Schema: a COMMAND's body, a value object it carries.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* `Project` schema exists. A list's definition comes from `entity_meta_data`, at runtime
|
|
11
|
-
* or preloaded (`FrameworkProvider metas`) — not from here;
|
|
12
|
-
* - the COMMANDS and the value objects are described well, and better than the meta in one
|
|
13
|
-
* place: inside a value object `entity_meta_data` sends a `Literal` and a `list[str]` as
|
|
14
|
-
* `unknown`, where the schema says `enum: ["es", "en"]` and `array<string>`.
|
|
15
|
-
*
|
|
16
|
-
* So this reads a component schema into a `Meta` — the form of a Command, a value object — and
|
|
17
|
-
* `completeMeta` fills, from it, what the server's meta left `unknown`.
|
|
9
|
+
* So this reads such a component schema into a `Meta` — the form of a Command, a value object —
|
|
10
|
+
* and `completeMeta` fills, from it, what a definition left `unknown`.
|
|
18
11
|
*
|
|
19
12
|
* const spec = metaFromSchema("ProjectSpecification", doc.components.schemas);
|
|
20
13
|
* const fixed = completeMeta(project.fields.specification.definition, spec);
|
package/dist/core/trail.js
CHANGED
|
@@ -12,10 +12,7 @@ async function page(transport, trail, cursor) {
|
|
|
12
12
|
...trail.question,
|
|
13
13
|
pagination: { ...trail.question.pagination, limit: trail.size },
|
|
14
14
|
};
|
|
15
|
-
const answer = await transport.list(trail.route,
|
|
16
|
-
...resumingFrom(sized, cursor),
|
|
17
|
-
meta: false,
|
|
18
|
-
});
|
|
15
|
+
const answer = await transport.list(trail.route, resumingFrom(sized, cursor));
|
|
19
16
|
return {
|
|
20
17
|
ids: answer.rows.map((row) => String(row[trail.key] ?? "")),
|
|
21
18
|
after: answer.cursor,
|
package/dist/react/useGroups.js
CHANGED
|
@@ -38,7 +38,6 @@ export function useGroups(listing, options = {}) {
|
|
|
38
38
|
return () => aborter.abort();
|
|
39
39
|
const criteria = {
|
|
40
40
|
...JSON.parse(question),
|
|
41
|
-
meta: false,
|
|
42
41
|
grouping: {
|
|
43
42
|
group_by: levels.map((level) => ({ ...level })),
|
|
44
43
|
...(sums === "" ? {} : { measures: measuresOf(sums.split(",")) }),
|
|
@@ -63,7 +62,7 @@ export function useGroups(listing, options = {}) {
|
|
|
63
62
|
return;
|
|
64
63
|
reading.current.add(key);
|
|
65
64
|
const { grouping: _grouping, pagination: _pagination, ...own } = bucket.criteria;
|
|
66
|
-
const first = { ...own,
|
|
65
|
+
const first = { ...own, pagination: { limit: pageSize } };
|
|
67
66
|
void transport.list(route, after === null ? first : resumingFrom(first, after)).then((page) => {
|
|
68
67
|
reading.current.delete(key);
|
|
69
68
|
setRows((now) => {
|
package/dist/react/useHistory.js
CHANGED
|
@@ -24,7 +24,7 @@ export function useHistory(entity, id, deps = []) {
|
|
|
24
24
|
return;
|
|
25
25
|
const aborter = new AbortController();
|
|
26
26
|
const criteria = {
|
|
27
|
-
|
|
27
|
+
selection: {
|
|
28
28
|
all: [
|
|
29
29
|
{ field: "entity_type", operator: "=", value: history.type },
|
|
30
30
|
{ field: "entity_id", operator: "=", value: id },
|
package/dist/react/useListing.js
CHANGED
|
@@ -17,7 +17,7 @@ export function useListing(given, own = {}) {
|
|
|
17
17
|
const cut = useListScope(entity.key);
|
|
18
18
|
const scopes = [
|
|
19
19
|
...(definition === undefined ? [] : [scopeOf(definition)]),
|
|
20
|
-
...(cut === undefined ? [] : [{
|
|
20
|
+
...(cut === undefined ? [] : [{ selection: cut }]),
|
|
21
21
|
];
|
|
22
22
|
const options = scopes.length === 0
|
|
23
23
|
? own
|
|
@@ -27,8 +27,8 @@ export function useListing(given, own = {}) {
|
|
|
27
27
|
};
|
|
28
28
|
const route = listRoute(entity.list, options.params);
|
|
29
29
|
const source = useMemo(() => resource((criteria, signal) => transport.list(route, criteria, signal)), [transport, route]);
|
|
30
|
-
//
|
|
31
|
-
//
|
|
30
|
+
// A definition already known draws the columns before the first page arrives; the one the
|
|
31
|
+
// transport reads from the discovery document comes with it.
|
|
32
32
|
const [preloaded] = useState(() => metas.get(entity.key));
|
|
33
33
|
const paging = options.paging ?? "pages";
|
|
34
34
|
const size = options.pageSize ?? options.criteria?.pagination?.limit ?? 50;
|
|
@@ -37,7 +37,7 @@ export function useListing(given, own = {}) {
|
|
|
37
37
|
...options.criteria,
|
|
38
38
|
pagination: { ...options.criteria?.pagination, limit: size },
|
|
39
39
|
};
|
|
40
|
-
const base =
|
|
40
|
+
const base = asked;
|
|
41
41
|
const reading = useReading(source, base);
|
|
42
42
|
// `pages` mode: the cursor that opens each page walked so far — page 0 opens with none.
|
|
43
43
|
const [cursors, setCursors] = useState([null]);
|
|
@@ -59,9 +59,9 @@ export function useListing(given, own = {}) {
|
|
|
59
59
|
let criteria = base;
|
|
60
60
|
const found = searchOver(meta, next.text);
|
|
61
61
|
if (found !== undefined)
|
|
62
|
-
criteria = merge(criteria, {
|
|
62
|
+
criteria = merge(criteria, { selection: found });
|
|
63
63
|
if (next.where !== undefined)
|
|
64
|
-
criteria = merge(criteria, {
|
|
64
|
+
criteria = merge(criteria, { selection: next.where });
|
|
65
65
|
if (next.order.length > 0)
|
|
66
66
|
criteria = merge(criteria, { order: [...next.order] });
|
|
67
67
|
return criteria;
|
package/dist/react/useLookup.js
CHANGED
|
@@ -12,7 +12,7 @@ export function excluding(criteria, exclude, meta) {
|
|
|
12
12
|
if (exclude === undefined || exclude.length === 0 || meta == null)
|
|
13
13
|
return criteria;
|
|
14
14
|
const out = {
|
|
15
|
-
|
|
15
|
+
selection: {
|
|
16
16
|
field: meta.get_id || meta.identity || "id",
|
|
17
17
|
operator: "not in",
|
|
18
18
|
value: [...exclude],
|
|
@@ -64,11 +64,10 @@ entity, options = {}) {
|
|
|
64
64
|
const aborter = new AbortController();
|
|
65
65
|
transport
|
|
66
66
|
.list(route, {
|
|
67
|
-
|
|
67
|
+
selection: keys.length === 1
|
|
68
68
|
? { field: key, operator: "=", value: keys[0] ?? "" }
|
|
69
69
|
: { field: key, operator: "in", value: keys },
|
|
70
70
|
pagination: { limit: keys.length },
|
|
71
|
-
meta: false,
|
|
72
71
|
}, aborter.signal)
|
|
73
72
|
.then((page) => {
|
|
74
73
|
for (const one of lookupOf(meta, page.rows, base.summary))
|
package/dist/react/usePivot.js
CHANGED
|
@@ -30,7 +30,6 @@ export function usePivot(listing, axes) {
|
|
|
30
30
|
const [rows, columns] = JSON.parse(shape);
|
|
31
31
|
const grouped = (levels) => ({
|
|
32
32
|
...JSON.parse(question),
|
|
33
|
-
meta: false,
|
|
34
33
|
grouping: {
|
|
35
34
|
group_by: levels.map((level) => ({ ...level })),
|
|
36
35
|
...(sums === "" ? {} : { measures: measuresOf(sums.split(",")) }),
|
|
@@ -65,7 +65,8 @@ export type Editing = {
|
|
|
65
65
|
set: (name: string, value: unknown) => void;
|
|
66
66
|
state: (name: string) => FieldState;
|
|
67
67
|
/** A cell of a list of records — line `index` of `name`, its `field`: the line model's hints
|
|
68
|
-
* over that line, refined by what the server's preview said of it (`items
|
|
68
|
+
* over that line, refined by what the server's preview said of it (`items`, by the line's
|
|
69
|
+
* identity, by its position when it has none). */
|
|
69
70
|
cell: (name: string, index: number, field: string) => FieldState;
|
|
70
71
|
/** The server's word on what did not validate, by where it points (`pathOf`): `discount`,
|
|
71
72
|
* `lines/1/qty`. Read a field's — its lines' included — with `errorAt`. */
|
package/dist/react/useRecord.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { changesOf, creationOf, defaultsOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, } from "../core/edit.js";
|
|
2
|
+
import { changesOf, computedLocally, creationOf, defaultsOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, } from "../core/edit.js";
|
|
3
3
|
import { pathFor, startingValuesOf, WITH_PARAM, } from "../core/entity.js";
|
|
4
4
|
import { newEntityId } from "../core/ids.js";
|
|
5
5
|
import { linesAnswered } from "../core/lines.js";
|
|
@@ -158,7 +158,19 @@ export function useRecord(entity, opened) {
|
|
|
158
158
|
};
|
|
159
159
|
const ask = (next, name) => {
|
|
160
160
|
const preview = entity.preview;
|
|
161
|
-
|
|
161
|
+
const field = name.split(".")[0] ?? name;
|
|
162
|
+
// What the server wrote down is computed here, as it would: a change whose every reach has
|
|
163
|
+
// a formula needs the server only for a rule that judges it.
|
|
164
|
+
const local = Array.isArray(next[field])
|
|
165
|
+
? undefined
|
|
166
|
+
: computedLocally(state.meta, { ...record, ...next }, field);
|
|
167
|
+
if (local !== undefined)
|
|
168
|
+
setComputed((now) => ({ ...now, ...local }));
|
|
169
|
+
const judged = (state.meta?.fields[field]?.judged_by?.length ?? 0) > 0;
|
|
170
|
+
// A change that reaches nothing — no computation, no rule — has nothing to ask the server.
|
|
171
|
+
if (preview === undefined || !needsPreview(state.meta, field))
|
|
172
|
+
return;
|
|
173
|
+
if (local !== undefined && !judged)
|
|
162
174
|
return;
|
|
163
175
|
cancelPreview();
|
|
164
176
|
pause.current = setTimeout(() => {
|
|
@@ -233,7 +245,7 @@ export function useRecord(entity, opened) {
|
|
|
233
245
|
cell: (name, index, field) => {
|
|
234
246
|
const line = (Array.isArray(values[name]) ? values[name] : [])[index];
|
|
235
247
|
const definition = state.meta?.fields[name]?.definition;
|
|
236
|
-
return fieldStateOf(definition, field, line ?? {}, lineStatesOf(fromServer, name
|
|
248
|
+
return fieldStateOf(definition, field, line ?? {}, lineStatesOf(fromServer, name, line, index, definition?.identity || "id"));
|
|
237
249
|
},
|
|
238
250
|
errors: failure instanceof TransportError ? errorsByField(failure.problem?.errors) : {},
|
|
239
251
|
advice,
|
package/dist/react/useRelated.js
CHANGED
|
@@ -21,9 +21,9 @@ export function useRelated(record, name, related, options = {}) {
|
|
|
21
21
|
const value = record.record === null ? null : record.record[own];
|
|
22
22
|
const scope = {
|
|
23
23
|
...options.criteria,
|
|
24
|
-
|
|
24
|
+
selection: {
|
|
25
25
|
all: [
|
|
26
|
-
...(options.criteria?.
|
|
26
|
+
...(options.criteria?.selection ? [options.criteria.selection] : []),
|
|
27
27
|
{ field: key, operator: "=", value: value },
|
|
28
28
|
],
|
|
29
29
|
},
|
|
@@ -22,7 +22,7 @@ export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
|
|
|
22
22
|
if (seeded.current || seed === undefined || seed === "" || meta?.search == null)
|
|
23
23
|
return;
|
|
24
24
|
seeded.current = true;
|
|
25
|
-
const where = matching(meta, seed).
|
|
25
|
+
const where = matching(meta, seed).selection;
|
|
26
26
|
if (where === undefined)
|
|
27
27
|
return;
|
|
28
28
|
const chip = filterCriteria(where, fillCopy(ui.search.literalChip, { text: seed }));
|
|
@@ -63,7 +63,7 @@ export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
|
|
|
63
63
|
: { grouping: _jsx(GroupingLevels, { fields: groupable, control: control }) }), onOpenBuilder: () => setBuilding(true), ...(meta?.search == null
|
|
64
64
|
? {}
|
|
65
65
|
: {
|
|
66
|
-
literal: (text) => matching(meta, text).
|
|
66
|
+
literal: (text) => matching(meta, text).selection ?? null,
|
|
67
67
|
}) }), building ? (_jsx(Dialog, { open: true, width: "lg", title: copy.builder, onClose: () => setBuilding(false), children: _jsx(CriteriaBuilder, { model: model, ...(whereOf(put) === undefined && listing.order.length === 0
|
|
68
68
|
? {}
|
|
69
69
|
: {
|
package/dist/web/list/search.js
CHANGED
package/dist/web/record/lines.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { choicesOf } from "@sincpro/criteria";
|
|
4
|
-
import { adviceAt, defaultsOf, errorAt, pathOf } from "../../core/edit.js";
|
|
4
|
+
import { adviceAt, defaultsOf, errorAt, linePlacesOf, pathOf, } from "../../core/edit.js";
|
|
5
5
|
import { addingOf, blankLine, lineFields, lineKey, moved, sameLine, writtenInCell, } from "../../core/lines.js";
|
|
6
6
|
import { textOf, viewOf } from "../../core/present.js";
|
|
7
7
|
import { entityFor, relationFieldOf, } from "../../core/relation.js";
|
|
@@ -153,29 +153,36 @@ export function RecordLinesEditor({ record, name, lines, look = {}, }) {
|
|
|
153
153
|
// server's `items[i]`, the error pointing at it (under its value) and its warning.
|
|
154
154
|
cellState: (line, column) => {
|
|
155
155
|
const index = indexOf(line);
|
|
156
|
-
const
|
|
156
|
+
const places = linePlacesOf(name, line, index, identity).map((one) => `${one}/${column}`);
|
|
157
157
|
const state = edit.cell(name, index, column);
|
|
158
|
-
const error =
|
|
159
|
-
|
|
158
|
+
const error = places
|
|
159
|
+
.map((at) => errorAt(edit.errors, at))
|
|
160
|
+
.find((one) => one !== undefined);
|
|
161
|
+
const warned = places.flatMap((at) => adviceAt(edit.advice, at))[0];
|
|
160
162
|
return {
|
|
161
163
|
readonly: state.readonly,
|
|
162
164
|
required: state.required,
|
|
163
165
|
hidden: !state.visible,
|
|
164
166
|
...(error === undefined ? {} : { error }),
|
|
165
|
-
...(warned === undefined
|
|
167
|
+
...(warned === undefined
|
|
168
|
+
? {}
|
|
169
|
+
: { flag: { tone: warned.blocks_save ? "bad" : "warn", label: warned.message } }),
|
|
166
170
|
};
|
|
167
171
|
},
|
|
168
172
|
// The line's own flag: what points at the line and at no cell drawn — the line as a
|
|
169
173
|
// whole, or a field it has no column for (an id the server does not know).
|
|
170
174
|
flag: (line) => {
|
|
171
|
-
const
|
|
172
|
-
const onLine = (key) => key === at ||
|
|
173
|
-
(key.startsWith(`${at}/`) &&
|
|
175
|
+
const places = linePlacesOf(name, line, indexOf(line), identity);
|
|
176
|
+
const onLine = (key) => places.some((at) => key === at ||
|
|
177
|
+
(key.startsWith(`${at}/`) &&
|
|
178
|
+
!drawn.has(key.slice(at.length + 1).split("/")[0])));
|
|
174
179
|
const error = Object.entries(edit.errors).find(([key]) => onLine(key))?.[1];
|
|
175
180
|
if (error !== undefined)
|
|
176
181
|
return { tone: "bad", label: error };
|
|
177
182
|
const warned = edit.advice.find((one) => onLine(pathOf(one.path ?? [one.field ?? ""])));
|
|
178
|
-
return warned === undefined
|
|
183
|
+
return warned === undefined
|
|
184
|
+
? null
|
|
185
|
+
: { tone: warned.blocks_save ? "bad" : "warn", label: warned.message };
|
|
179
186
|
}, editor: (draft, set, state) => {
|
|
180
187
|
if (look.editor !== undefined)
|
|
181
188
|
return look.editor(draft, set, state);
|
|
@@ -18,5 +18,5 @@ export function useRecordOpening() {
|
|
|
18
18
|
export function chooserScopeOf(entity, cut) {
|
|
19
19
|
const named = isList(entity) ? scopeOf(entity) : undefined;
|
|
20
20
|
const all = named === undefined ? cut : cut === undefined ? named : merge(named, cut);
|
|
21
|
-
return all?.
|
|
21
|
+
return all?.selection;
|
|
22
22
|
}
|
|
@@ -78,10 +78,7 @@ export function entityView(entity, options) {
|
|
|
78
78
|
meta = (await options.transport.list(route, { pagination: { limit: 1 } })).meta;
|
|
79
79
|
if (meta?.search == null)
|
|
80
80
|
return [];
|
|
81
|
-
const page = await options.transport.list(route,
|
|
82
|
-
...matching(meta, query),
|
|
83
|
-
meta: false,
|
|
84
|
-
});
|
|
81
|
+
const page = await options.transport.list(route, matching(meta, query));
|
|
85
82
|
// ⌘K writes text: of the entity's look of a choice, its name and its meta.
|
|
86
83
|
const look = presentationOf(entity).option;
|
|
87
84
|
return lookupOf(meta, page.rows, entity.summary).map((one) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "The web client of sincpro_framework: entities, lists and records bound to the metadata the server publishes, drawn with @sincpro/web-ui and arranged with @sincpro/web-composer.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,19 +23,19 @@
|
|
|
23
23
|
"printWidth": 94
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@sincpro/criteria": "^0.
|
|
27
|
-
"@sincpro/criteria-react": "^0.
|
|
26
|
+
"@sincpro/criteria": "^1.0.0",
|
|
27
|
+
"@sincpro/criteria-react": "^1.0.0",
|
|
28
28
|
"@sincpro/web-composer": "^1.5.0",
|
|
29
|
-
"@sincpro/web-ui": "^1.
|
|
29
|
+
"@sincpro/web-ui": "^1.11.1",
|
|
30
30
|
"react": ">=19",
|
|
31
31
|
"react-dom": ">=19"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@eslint/js": "^10.0.1",
|
|
35
|
-
"@sincpro/criteria": "^0.
|
|
36
|
-
"@sincpro/criteria-react": "^0.
|
|
35
|
+
"@sincpro/criteria": "^1.0.0",
|
|
36
|
+
"@sincpro/criteria-react": "^1.0.0",
|
|
37
37
|
"@sincpro/web-composer": "^1.5.0",
|
|
38
|
-
"@sincpro/web-ui": "^1.
|
|
38
|
+
"@sincpro/web-ui": "^1.11.1",
|
|
39
39
|
"@storybook/addon-a11y": "10.6.5",
|
|
40
40
|
"@storybook/addon-docs": "10.6.5",
|
|
41
41
|
"@storybook/addon-mcp": "10.6.5",
|