@sincpro/web-framework 3.21.0 → 4.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 +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/copy.d.ts +4 -0
- package/dist/core/copy.js +2 -0
- 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 +2 -2
- package/dist/core/index.js +2 -2
- package/dist/core/list.d.ts +17 -11
- package/dist/core/list.js +17 -11
- package/dist/core/names.d.ts +8 -6
- package/dist/core/names.js +14 -18
- 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 +11 -9
- 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 +10 -12
- 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 +7 -7
- package/dist/react/useListing.d.ts +14 -7
- package/dist/react/useListing.js +33 -9
- package/dist/react/useLookup.js +5 -7
- 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 +49 -57
- package/dist/react/useRecordLifecycle.js +8 -9
- package/dist/react/useServiceReading.js +6 -18
- 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 +112 -0
- package/dist/web/board/Dashboard.js +106 -0
- package/dist/web/board/index.d.ts +1 -0
- package/dist/web/board/index.js +1 -0
- package/dist/web/index.d.ts +2 -0
- package/dist/web/index.js +2 -0
- 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 +23 -44
- 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/EntityTags.js +4 -4
- package/dist/web/record/RelatedList.js +2 -2
- package/dist/web/record/Wizard.d.ts +65 -0
- package/dist/web/record/Wizard.js +90 -0
- package/dist/web/record/lines.js +4 -4
- 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 +29 -8
- package/dist/web/workspace/record.js +2 -2
- package/package.json +3 -3
package/dist/core/changes.d.ts
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
import type { Change, Entity } from "@sincpro/client-framework";
|
|
1
|
+
import type { Change, Entity, RemoteOperation } from "@sincpro/client-framework";
|
|
2
2
|
/**
|
|
3
3
|
* What a write touches on a screen: the rule every reader of this package shares — the cache,
|
|
4
4
|
* the lists and records on screen, the names in a cell.
|
|
5
5
|
*
|
|
6
|
-
* Context: a write says
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* under, wherever its events live (`/issue-events/{id}`). A segment that is a key (`/F-1`) names no
|
|
11
|
-
* collection. It is generous on purpose: reading again something that did not change costs a
|
|
6
|
+
* Context: a write says what it ran in the contract's words (`Change`, @sincpro/client-framework):
|
|
7
|
+
* the operation, the entities it concerns and the keys of the records it named. What it may have
|
|
8
|
+
* changed is every reading of those entities — a list, a record, its history — whatever wire
|
|
9
|
+
* carried it. It is generous on purpose: reading again something that did not change costs a
|
|
12
10
|
* request; showing something that did is the bug.
|
|
13
11
|
*
|
|
14
|
-
* touches({
|
|
15
|
-
* touches({
|
|
12
|
+
* touches({ operation: "project.CommandCloseIssue", entities: ["Issue"], keys: … }, issues) -> true
|
|
13
|
+
* touches({ operation: "project.CommandCloseIssue", entities: ["Issue"], keys: … }, projects) -> false
|
|
16
14
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export declare function under(route: string, path: string): boolean;
|
|
21
|
-
/** The collections a write to `route` may have changed: each one its route names, and the
|
|
22
|
-
* history of each entity it writes under. */
|
|
23
|
-
export declare function touchedBy(route: string, entities: readonly Entity[]): string[];
|
|
24
|
-
/** Whether `change` may have changed what was read at `route`. */
|
|
25
|
-
export declare function touches(change: Change, route: string, entities: readonly Entity[]): boolean;
|
|
15
|
+
export declare function touches(change: Change, entity: Pick<Entity, "model">): boolean;
|
|
16
|
+
/** Whether `change` may have changed what `operation` read: one entity in common. */
|
|
17
|
+
export declare function touchesOperation(change: Change, operation: RemoteOperation): boolean;
|
package/dist/core/changes.js
CHANGED
|
@@ -2,38 +2,19 @@
|
|
|
2
2
|
* What a write touches on a screen: the rule every reader of this package shares — the cache,
|
|
3
3
|
* the lists and records on screen, the names in a cell.
|
|
4
4
|
*
|
|
5
|
-
* Context: a write says
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* under, wherever its events live (`/issue-events/{id}`). A segment that is a key (`/F-1`) names no
|
|
10
|
-
* collection. It is generous on purpose: reading again something that did not change costs a
|
|
5
|
+
* Context: a write says what it ran in the contract's words (`Change`, @sincpro/client-framework):
|
|
6
|
+
* the operation, the entities it concerns and the keys of the records it named. What it may have
|
|
7
|
+
* changed is every reading of those entities — a list, a record, its history — whatever wire
|
|
8
|
+
* carried it. It is generous on purpose: reading again something that did not change costs a
|
|
11
9
|
* request; showing something that did is the bug.
|
|
12
10
|
*
|
|
13
|
-
* touches({
|
|
14
|
-
* touches({
|
|
11
|
+
* touches({ operation: "project.CommandCloseIssue", entities: ["Issue"], keys: … }, issues) -> true
|
|
12
|
+
* touches({ operation: "project.CommandCloseIssue", entities: ["Issue"], keys: … }, projects) -> false
|
|
15
13
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return route.split("?")[0] ?? route;
|
|
14
|
+
export function touches(change, entity) {
|
|
15
|
+
return change.entities.includes(entity.model);
|
|
19
16
|
}
|
|
20
|
-
/**
|
|
21
|
-
export function
|
|
22
|
-
|
|
23
|
-
return own === path || own.startsWith(path.endsWith("/") ? path : `${path}/`);
|
|
24
|
-
}
|
|
25
|
-
/** The collections a write to `route` may have changed: each one its route names, and the
|
|
26
|
-
* history of each entity it writes under. */
|
|
27
|
-
export function touchedBy(route, entities) {
|
|
28
|
-
const path = pathOf(route);
|
|
29
|
-
const segments = path.split("/").filter((one) => one !== "");
|
|
30
|
-
const history = entities
|
|
31
|
-
.filter((one) => one.history !== undefined && under(path, pathOf(one.list)))
|
|
32
|
-
// The route up to its first key: `/issue-events/{id}` forgets `/issue-events`.
|
|
33
|
-
.map((one) => pathOf(one.history ?? "").split("/{")[0] ?? "");
|
|
34
|
-
return [...segments.map((one) => `/${one}`), ...history];
|
|
35
|
-
}
|
|
36
|
-
/** Whether `change` may have changed what was read at `route`. */
|
|
37
|
-
export function touches(change, route, entities) {
|
|
38
|
-
return touchedBy(change.route, entities).some((path) => under(route, path));
|
|
17
|
+
/** Whether `change` may have changed what `operation` read: one entity in common. */
|
|
18
|
+
export function touchesOperation(change, operation) {
|
|
19
|
+
return operation.entities.some((one) => change.entities.includes(one));
|
|
39
20
|
}
|
package/dist/core/command.d.ts
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Entity, type Operation, type OperationOptions, type OperationTransport } from "@sincpro/client-framework";
|
|
2
2
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
|
+
/** What an operation takes, as its contract types it. */
|
|
4
|
+
export type InputOf<O> = O extends Operation<infer I, unknown> ? Exclude<I, undefined> : AnyRecord;
|
|
5
|
+
/** What an operation answers, as its contract types it. */
|
|
6
|
+
export type AnswerOf<O> = O extends Operation<unknown, infer A> ? A : unknown;
|
|
3
7
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
8
|
+
* An operation of an entity called for one record — what a button runs once (`useCommand`) and a
|
|
9
|
+
* batch once per record (`useBatchCommand`): the record's id where the operation names it
|
|
10
|
+
* (`targeted`), beside what the person gave.
|
|
6
11
|
*
|
|
7
|
-
* await
|
|
8
|
-
* -> POST /invoices/F-7/confirm
|
|
12
|
+
* await callFor(operations, invoices, invoices.operations.commands.confirm, "F-7", {}, { idempotencyKey })
|
|
9
13
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* one per gesture and record, kept while it goes unanswered (`retryKeys`).
|
|
14
|
+
* The idempotency key is the caller's: one per gesture and record, kept while it goes unanswered
|
|
15
|
+
* (`retryKeys`).
|
|
13
16
|
*/
|
|
14
|
-
export declare function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
export declare function callFor<A>(transport: OperationTransport, entity: Pick<Entity, "model">, operation: Operation, id: string | undefined, input: AnyRecord, options?: OperationOptions): Promise<A>;
|
|
18
|
+
/** An entity's Commands by name, as its operations declare them. */
|
|
19
|
+
export type CommandsOf<O> = O extends {
|
|
20
|
+
readonly commands?: infer C;
|
|
21
|
+
} ? NonNullable<C> : never;
|
|
22
|
+
/** The names of an entity's Commands. */
|
|
23
|
+
export type CommandName<O> = keyof CommandsOf<O> & string;
|
|
24
|
+
/**
|
|
25
|
+
* What a screen gives a Command of an entity: its input, each field optional — the record's key
|
|
26
|
+
* is put where the operation names it (`targeted`), and the server says what is missing.
|
|
27
|
+
*/
|
|
28
|
+
export type BodyOf<O, N> = N extends keyof CommandsOf<O> ? Partial<InputOf<CommandsOf<O>[N]>> : AnyRecord;
|
|
29
|
+
/** What a Command answers: `R` when the screen writes it, else what its operation answers. */
|
|
30
|
+
export type CommandAnswer<R, O, N> = unknown extends R ? N extends keyof CommandsOf<O> ? AnswerOf<CommandsOf<O>[N]> : unknown : R;
|
package/dist/core/command.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { targeted, } from "@sincpro/client-framework";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* An operation of an entity called for one record — what a button runs once (`useCommand`) and a
|
|
4
|
+
* batch once per record (`useBatchCommand`): the record's id where the operation names it
|
|
5
|
+
* (`targeted`), beside what the person gave.
|
|
5
6
|
*
|
|
6
|
-
* await
|
|
7
|
-
* -> POST /invoices/F-7/confirm
|
|
7
|
+
* await callFor(operations, invoices, invoices.operations.commands.confirm, "F-7", {}, { idempotencyKey })
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* one per gesture and record, kept while it goes unanswered (`retryKeys`).
|
|
9
|
+
* The idempotency key is the caller's: one per gesture and record, kept while it goes unanswered
|
|
10
|
+
* (`retryKeys`).
|
|
12
11
|
*/
|
|
13
|
-
export function
|
|
14
|
-
|
|
15
|
-
const sent = bodyFor(route, id, body);
|
|
16
|
-
return transport.send(route.method, pathFor(route, id, sent), sent, signal, sending);
|
|
12
|
+
export function callFor(transport, entity, operation, id, input, options = {}) {
|
|
13
|
+
return transport.call(operation, targeted(entity, operation, id, input), options);
|
|
17
14
|
}
|
package/dist/core/copy.d.ts
CHANGED
|
@@ -122,6 +122,10 @@ export type FrameworkCopy = {
|
|
|
122
122
|
/** More were chosen than a Command runs on at once. */
|
|
123
123
|
tooMany: (size: number | null, limit: number) => string;
|
|
124
124
|
};
|
|
125
|
+
board: {
|
|
126
|
+
/** The name of a board's period row: what every tile reads over. */
|
|
127
|
+
period: string;
|
|
128
|
+
};
|
|
125
129
|
failure: {
|
|
126
130
|
/** The server could not be reached at all — nothing it said is known. */
|
|
127
131
|
unreachable: string;
|
package/dist/core/copy.js
CHANGED
|
@@ -88,6 +88,7 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
88
88
|
stop: "Stop",
|
|
89
89
|
tooMany: (size, limit) => `${size === null ? "More than " + limit : size} records are chosen; at most ${limit} at once. Narrow the search.`,
|
|
90
90
|
},
|
|
91
|
+
board: { period: "Period" },
|
|
91
92
|
failure: {
|
|
92
93
|
unreachable: "The server could not be reached",
|
|
93
94
|
unexpected: "The server answered something else",
|
|
@@ -197,6 +198,7 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
197
198
|
stop: "Detener",
|
|
198
199
|
tooMany: (size, limit) => `${size === null ? "Son más de " + limit : "Son " + size} registros elegidos; a la vez, como mucho ${limit}. Acotá la búsqueda.`,
|
|
199
200
|
},
|
|
201
|
+
board: { period: "Período" },
|
|
200
202
|
failure: {
|
|
201
203
|
unreachable: "No se pudo hablar con el servidor",
|
|
202
204
|
unexpected: "El servidor contestó otra cosa",
|
package/dist/core/edit.d.ts
CHANGED
|
@@ -117,9 +117,23 @@ export declare function creationOf(meta: Meta | null | undefined, values: AnyRec
|
|
|
117
117
|
* create through `Edit`: an application that speaks `Edit` wrote its own «Nuevo» (quipu).
|
|
118
118
|
*/
|
|
119
119
|
export declare function canCreate(entity: {
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
operations: {
|
|
121
|
+
edit?: unknown;
|
|
122
|
+
commands?: {
|
|
123
|
+
create?: unknown;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
122
126
|
}, meta: Meta | null | undefined): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* `input` with what `operation` names besides it taken from the record on screen — the record
|
|
129
|
+
* it lives under (`tenant_id`), a key a REST path holds —: the form has it, the caller does not.
|
|
130
|
+
*
|
|
131
|
+
* withTargetsOf(previewMember, { tenant_id: "acme", name: "Ana" }, { values })
|
|
132
|
+
* -> { values, tenant_id: "acme" }
|
|
133
|
+
*/
|
|
134
|
+
export declare function withTargetsOf(operation: {
|
|
135
|
+
targets: Readonly<Record<string, string>>;
|
|
136
|
+
}, record: AnyRecord, input: AnyRecord): AnyRecord;
|
|
123
137
|
/**
|
|
124
138
|
* What an edit of a STORED record sends (sincpro_framework's `Edit`): the fields the person
|
|
125
139
|
* changed, and inside them nothing the model marks `readonly` — a line keeps only its identity,
|
package/dist/core/edit.js
CHANGED
|
@@ -193,9 +193,20 @@ export function creationOf(meta, values) {
|
|
|
193
193
|
* create through `Edit`: an application that speaks `Edit` wrote its own «Nuevo» (quipu).
|
|
194
194
|
*/
|
|
195
195
|
export function canCreate(entity, meta) {
|
|
196
|
-
if (entity.create !== undefined)
|
|
196
|
+
if (entity.operations.commands?.create !== undefined)
|
|
197
197
|
return true;
|
|
198
|
-
return entity.edit !== undefined && (meta?.get_id || meta?.identity || "id") === "id";
|
|
198
|
+
return (entity.operations.edit !== undefined && (meta?.get_id || meta?.identity || "id") === "id");
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* `input` with what `operation` names besides it taken from the record on screen — the record
|
|
202
|
+
* it lives under (`tenant_id`), a key a REST path holds —: the form has it, the caller does not.
|
|
203
|
+
*
|
|
204
|
+
* withTargetsOf(previewMember, { tenant_id: "acme", name: "Ana" }, { values })
|
|
205
|
+
* -> { values, tenant_id: "acme" }
|
|
206
|
+
*/
|
|
207
|
+
export function withTargetsOf(operation, record, input) {
|
|
208
|
+
const taken = Object.values(operation.targets).filter((field) => input[field] === undefined && record[field] !== undefined);
|
|
209
|
+
return { ...Object.fromEntries(taken.map((field) => [field, record[field]])), ...input };
|
|
199
210
|
}
|
|
200
211
|
/**
|
|
201
212
|
* What an edit of a STORED record sends (sincpro_framework's `Edit`): the fields the person
|
package/dist/core/groups.d.ts
CHANGED
|
@@ -27,8 +27,9 @@ export declare function isGroupedAnswer(page: {
|
|
|
27
27
|
}): boolean;
|
|
28
28
|
/** What a grouped question was answered with when it was not groups: the list's failure. */
|
|
29
29
|
export declare class NotGrouped extends Error {
|
|
30
|
-
readonly
|
|
31
|
-
|
|
30
|
+
readonly entity: string;
|
|
31
|
+
/** `entity`: the key of the entity whose search answered no groups. */
|
|
32
|
+
constructor(entity: string);
|
|
32
33
|
}
|
|
33
34
|
/** Where a page of groups starts: the first, or past the groups already in hand. */
|
|
34
35
|
export type GroupPage = {
|
package/dist/core/groups.js
CHANGED
|
@@ -34,10 +34,11 @@ export function isGroupedAnswer(page) {
|
|
|
34
34
|
}
|
|
35
35
|
/** What a grouped question was answered with when it was not groups: the list's failure. */
|
|
36
36
|
export class NotGrouped extends Error {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
entity;
|
|
38
|
+
/** `entity`: the key of the entity whose search answered no groups. */
|
|
39
|
+
constructor(entity) {
|
|
39
40
|
super(frameworkCopy().list.notGrouped);
|
|
40
|
-
this.
|
|
41
|
+
this.entity = entity;
|
|
41
42
|
this.name = "NotGrouped";
|
|
42
43
|
}
|
|
43
44
|
}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* day/instant conversions (`installTimeZone`, `wallTimeOf`, `instantOf`, `dayOf`) are
|
|
8
8
|
* @sincpro/client-framework's — the same on every platform — and are imported from there.
|
|
9
9
|
*/
|
|
10
|
-
export { type
|
|
11
|
-
export {
|
|
10
|
+
export { type CachedOperations, cachedOperations, type CacheOptions, } from "./cache.js";
|
|
11
|
+
export { type AnswerOf, callFor, type InputOf } from "./command.js";
|
|
12
12
|
export { ENGLISH_FRAMEWORK_COPY, type FrameworkCopy, frameworkCopy, installFrameworkCopy, SPANISH_FRAMEWORK_COPY, SPANISH_FRAMEWORK_COPY_TU, } from "./copy.js";
|
|
13
13
|
export { type Advice, adviceAt, canCreate, changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorAt, errorsByField, type FieldState, fieldStateOf, type FieldStates, isEmptyValue, linePlacesOf, lineStatesOf, missingOf, needsPreview, pathOf, type ServerFieldState, } from "./edit.js";
|
|
14
14
|
export { explain } from "./explain.js";
|
package/dist/core/index.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* day/instant conversions (`installTimeZone`, `wallTimeOf`, `instantOf`, `dayOf`) are
|
|
8
8
|
* @sincpro/client-framework's — the same on every platform — and are imported from there.
|
|
9
9
|
*/
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
10
|
+
export { cachedOperations, } from "./cache.js";
|
|
11
|
+
export { callFor } from "./command.js";
|
|
12
12
|
export { ENGLISH_FRAMEWORK_COPY, frameworkCopy, installFrameworkCopy, SPANISH_FRAMEWORK_COPY, SPANISH_FRAMEWORK_COPY_TU, } from "./copy.js";
|
|
13
13
|
export { adviceAt, canCreate, changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorAt, errorsByField, fieldStateOf, isEmptyValue, linePlacesOf, lineStatesOf, missingOf, needsPreview, pathOf, } from "./edit.js";
|
|
14
14
|
export { explain } from "./explain.js";
|
package/dist/core/list.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Entity, type
|
|
2
|
-
import { type AnyRecord, type Criteria, type Expression, type Grain, type Page, type Sort } from "@sincpro/criteria";
|
|
1
|
+
import { type Entity, type OperationTransport, type ResourceRef } from "@sincpro/client-framework";
|
|
2
|
+
import { type AnyRecord, type Criteria, type Expression, type Grain, type Meta, type Page, type Sort } from "@sincpro/criteria";
|
|
3
3
|
/**
|
|
4
4
|
* What a chooser of SEVERAL is asked (composer's `pick` `question`): the entity's list opened to
|
|
5
5
|
* choose many answers a `Selection` — what was ticked, or every record its question matches —
|
|
@@ -105,7 +105,8 @@ export declare function isList<T extends AnyRecord>(given: Entity<T> | ListDefin
|
|
|
105
105
|
export declare function scopeOf<T extends AnyRecord>(list: ListDefinition<T>): Criteria<T>;
|
|
106
106
|
/** What a listing's first page depends on, besides the entity or the named list. */
|
|
107
107
|
export type ListingQuestion<T> = {
|
|
108
|
-
/**
|
|
108
|
+
/** What its search takes beside the criteria — the record it lives under:
|
|
109
|
+
* `{ tenant_id: "acme" }`. */
|
|
109
110
|
params?: Readonly<Record<string, string>>;
|
|
110
111
|
/** What the listing always asks — a scope. Search, filter and order AND it. */
|
|
111
112
|
criteria?: Criteria<T>;
|
|
@@ -113,33 +114,38 @@ export type ListingQuestion<T> = {
|
|
|
113
114
|
pageSize?: number;
|
|
114
115
|
};
|
|
115
116
|
/**
|
|
116
|
-
* The
|
|
117
|
-
* and the caller's criteria ANDed, the page size set.
|
|
117
|
+
* The entity, the input and the criteria of a listing's first page: the named list's scope, a
|
|
118
|
+
* screen's cut and the caller's criteria ANDed, the page size set.
|
|
118
119
|
*
|
|
119
120
|
* listingAsk(porCobrar, { pageSize: 25 })
|
|
120
|
-
* → {
|
|
121
|
+
* → { entity: facturas, input: {}, criteria: { selection: state = posted, pagination: { limit: 25 } } }
|
|
121
122
|
*
|
|
122
123
|
* Context: `useListing` asks it on mount and `readListing` asks it on a server, so a page read
|
|
123
124
|
* there is the very page the screen would have asked for, and hydrating it reads nothing twice.
|
|
124
125
|
*/
|
|
125
126
|
export declare function listingAsk<T extends AnyRecord>(given: Entity<T> | ListDefinition<T>, own?: ListingQuestion<T>, cut?: Expression<T>): {
|
|
126
|
-
|
|
127
|
+
entity: Entity<T>;
|
|
128
|
+
input: Readonly<Record<string, string>>;
|
|
127
129
|
criteria: Criteria<T>;
|
|
128
130
|
};
|
|
129
131
|
/**
|
|
130
132
|
* A listing's first page, read outside React — on the server that renders the screen, in a
|
|
131
|
-
* route's loader —, through the same
|
|
133
|
+
* route's loader —, through the same operations the `FrameworkProvider` is given, with its
|
|
134
|
+
* model's definition when the caller has it (`metasOf(contract)[entity.key]`). Handed to
|
|
132
135
|
* `useListing(list, { ...own, page })`, the screen starts from it and asks nothing on mount.
|
|
133
136
|
*
|
|
134
137
|
* // the loader, on the server
|
|
135
|
-
* const page = await readListing(
|
|
138
|
+
* const page = await readListing(operations, misPagos, { criteria: delColegiado });
|
|
136
139
|
* // the screen, rendered there and hydrated in the browser
|
|
137
140
|
* const listing = useListing(misPagos, { criteria: delColegiado, page });
|
|
138
141
|
*
|
|
139
142
|
* A chooser's cut (`ListScopeProvider`) lives in the screen and is not read here: a listing
|
|
140
143
|
* under one is asked with it by the screen, as a SPA does.
|
|
141
144
|
*/
|
|
142
|
-
export declare function readListing<T extends AnyRecord>(transport:
|
|
145
|
+
export declare function readListing<T extends AnyRecord>(transport: OperationTransport, given: Entity<T> | ListDefinition<T>, own?: ListingQuestion<T>, options?: {
|
|
146
|
+
signal?: AbortSignal;
|
|
147
|
+
meta?: Meta | null;
|
|
148
|
+
}): Promise<Page<T>>;
|
|
143
149
|
/**
|
|
144
150
|
* An entity's trash, as a named list: its archived records (sincpro_framework's `Archive`,
|
|
145
151
|
* `ArchivableMixin`), each row offering «Restore» when the entity declares `restore`.
|
|
@@ -147,7 +153,7 @@ export declare function readListing<T extends AnyRecord>(transport: Transport, g
|
|
|
147
153
|
* listView(trashOf(banners)) // «Papelera» in the workspace and ⌘K
|
|
148
154
|
*
|
|
149
155
|
* Context: every other reading leaves an archived record out; the backend's trash is a `Search`
|
|
150
|
-
* that names `archived_at` — the
|
|
156
|
+
* that names `archived_at` — the entity's own search, under `archived_at` not null. So this is the
|
|
151
157
|
* entity's own list under that cut, never a route of its own, and the server still decides what
|
|
152
158
|
* comes back.
|
|
153
159
|
*/
|
package/dist/core/list.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readPage, screensOperations, } from "@sincpro/client-framework";
|
|
2
2
|
import { merge, } from "@sincpro/criteria";
|
|
3
3
|
import { frameworkCopy } from "./copy.js";
|
|
4
4
|
/**
|
|
@@ -38,11 +38,11 @@ export function scopeOf(list) {
|
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
|
-
* The
|
|
42
|
-
* and the caller's criteria ANDed, the page size set.
|
|
41
|
+
* The entity, the input and the criteria of a listing's first page: the named list's scope, a
|
|
42
|
+
* screen's cut and the caller's criteria ANDed, the page size set.
|
|
43
43
|
*
|
|
44
44
|
* listingAsk(porCobrar, { pageSize: 25 })
|
|
45
|
-
* → {
|
|
45
|
+
* → { entity: facturas, input: {}, criteria: { selection: state = posted, pagination: { limit: 25 } } }
|
|
46
46
|
*
|
|
47
47
|
* Context: `useListing` asks it on mount and `readListing` asks it on a server, so a page read
|
|
48
48
|
* there is the very page the screen would have asked for, and hydrating it reads nothing twice.
|
|
@@ -58,26 +58,32 @@ export function listingAsk(given, own = {}, cut) {
|
|
|
58
58
|
const asked = parts.length === 0 ? undefined : parts.reduce((all, one) => merge(all, one));
|
|
59
59
|
const size = own.pageSize ?? asked?.pagination?.limit ?? 50;
|
|
60
60
|
return {
|
|
61
|
-
|
|
61
|
+
entity,
|
|
62
|
+
input: own.params ?? {},
|
|
62
63
|
criteria: { ...asked, pagination: { ...asked?.pagination, limit: size } },
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
66
|
/**
|
|
66
67
|
* A listing's first page, read outside React — on the server that renders the screen, in a
|
|
67
|
-
* route's loader —, through the same
|
|
68
|
+
* route's loader —, through the same operations the `FrameworkProvider` is given, with its
|
|
69
|
+
* model's definition when the caller has it (`metasOf(contract)[entity.key]`). Handed to
|
|
68
70
|
* `useListing(list, { ...own, page })`, the screen starts from it and asks nothing on mount.
|
|
69
71
|
*
|
|
70
72
|
* // the loader, on the server
|
|
71
|
-
* const page = await readListing(
|
|
73
|
+
* const page = await readListing(operations, misPagos, { criteria: delColegiado });
|
|
72
74
|
* // the screen, rendered there and hydrated in the browser
|
|
73
75
|
* const listing = useListing(misPagos, { criteria: delColegiado, page });
|
|
74
76
|
*
|
|
75
77
|
* A chooser's cut (`ListScopeProvider`) lives in the screen and is not read here: a listing
|
|
76
78
|
* under one is asked with it by the screen, as a SPA does.
|
|
77
79
|
*/
|
|
78
|
-
export function readListing(transport, given, own = {},
|
|
79
|
-
const {
|
|
80
|
-
return
|
|
80
|
+
export function readListing(transport, given, own = {}, options = {}) {
|
|
81
|
+
const { entity, input, criteria } = listingAsk(given, own);
|
|
82
|
+
return readPage(screensOperations(transport), entity, criteria, {
|
|
83
|
+
input,
|
|
84
|
+
meta: options.meta ?? null,
|
|
85
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
86
|
+
});
|
|
81
87
|
}
|
|
82
88
|
/**
|
|
83
89
|
* An entity's trash, as a named list: its archived records (sincpro_framework's `Archive`,
|
|
@@ -86,7 +92,7 @@ export function readListing(transport, given, own = {}, signal) {
|
|
|
86
92
|
* listView(trashOf(banners)) // «Papelera» in the workspace and ⌘K
|
|
87
93
|
*
|
|
88
94
|
* Context: every other reading leaves an archived record out; the backend's trash is a `Search`
|
|
89
|
-
* that names `archived_at` — the
|
|
95
|
+
* that names `archived_at` — the entity's own search, under `archived_at` not null. So this is the
|
|
90
96
|
* entity's own list under that cut, never a route of its own, and the server still decides what
|
|
91
97
|
* comes back.
|
|
92
98
|
*/
|
package/dist/core/names.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Change, type Entity, type MetaStore, type
|
|
1
|
+
import { type Change, type Entity, type MetaStore, type OperationTransport } from "@sincpro/client-framework";
|
|
2
2
|
/**
|
|
3
3
|
* The names of records by their keys — what a cell, a fact or a chip that holds only a key shows
|
|
4
4
|
* — asked in ONE request per entity, however many of them ask at once.
|
|
@@ -9,11 +9,11 @@ import { type Change, type Entity, type MetaStore, type Transport } from "@sincp
|
|
|
9
9
|
* list, narrowed to those keys (`in`), in slices of `SLICE` so no page is asked without a
|
|
10
10
|
* ceiling. A name is kept for the book's life, shared by every place that shows it, and forgotten
|
|
11
11
|
* when a write touches its entity (`changed`: a rename). Unnamed is no error — the place shows the
|
|
12
|
-
* key —; a request that fails is not kept, so the next place asks again. An entity
|
|
13
|
-
* under another record (
|
|
14
|
-
* unnamed.
|
|
12
|
+
* key —; a request that fails is not kept, so the next place asks again. An entity searched only
|
|
13
|
+
* under another record (its `search` names a record of another model) has no list to ask by key:
|
|
14
|
+
* it stays unnamed.
|
|
15
15
|
*
|
|
16
|
-
* const names = nameBook(
|
|
16
|
+
* const names = nameBook(operations, metas);
|
|
17
17
|
* await names.nameOf(tenants, "acme") -> "ACME S.R.L."
|
|
18
18
|
*/
|
|
19
19
|
export type NameBook = {
|
|
@@ -22,4 +22,6 @@ export type NameBook = {
|
|
|
22
22
|
/** A write landed: forget the names it may have changed. */
|
|
23
23
|
changed(change: Change): void;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
/** Whether an entity is searched on its own — not only under a record of another model. */
|
|
26
|
+
export declare function searchedAlone(entity: Entity): boolean;
|
|
27
|
+
export declare function nameBook(transport: OperationTransport, metas: MetaStore): NameBook;
|
package/dist/core/names.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readPage, } from "@sincpro/client-framework";
|
|
2
2
|
import { touches } from "./changes.js";
|
|
3
3
|
import { lookupOf } from "./lookup.js";
|
|
4
4
|
/** The most keys one request asks for. */
|
|
5
5
|
const SLICE = 100;
|
|
6
|
-
/**
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
return listRoute(entity.list);
|
|
10
|
-
}
|
|
11
|
-
catch {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
6
|
+
/** Whether an entity is searched on its own — not only under a record of another model. */
|
|
7
|
+
export function searchedAlone(entity) {
|
|
8
|
+
return Object.keys(entity.operations.search.targets).every((model) => model === entity.model);
|
|
14
9
|
}
|
|
15
|
-
export function nameBook(transport, metas
|
|
16
|
-
/** By entity key:
|
|
10
|
+
export function nameBook(transport, metas) {
|
|
11
|
+
/** By entity key: its model, and by record key the name, asked or answered. */
|
|
17
12
|
const known = new Map();
|
|
18
13
|
/** By entity key: the keys waiting for the next request, and how to answer each. */
|
|
19
14
|
const asking = new Map();
|
|
@@ -22,7 +17,7 @@ export function nameBook(transport, metas, entities = []) {
|
|
|
22
17
|
if (batch === undefined)
|
|
23
18
|
return;
|
|
24
19
|
asking.delete(entityKey);
|
|
25
|
-
const { entity,
|
|
20
|
+
const { entity, waiting } = batch;
|
|
26
21
|
const meta = metas.get(entity.key);
|
|
27
22
|
const field = meta?.get_id || meta?.identity || "id";
|
|
28
23
|
const keys = [...waiting.keys()];
|
|
@@ -33,7 +28,9 @@ export function nameBook(transport, metas, entities = []) {
|
|
|
33
28
|
pagination: { limit: slice.length },
|
|
34
29
|
};
|
|
35
30
|
try {
|
|
36
|
-
const page = await transport
|
|
31
|
+
const page = await readPage(transport, entity, criteria, {
|
|
32
|
+
meta: meta ?? null,
|
|
33
|
+
});
|
|
37
34
|
const named = new Map(lookupOf(page.meta ?? meta ?? null, page.rows, entity.summary).map((one) => [
|
|
38
35
|
one.id,
|
|
39
36
|
one.label,
|
|
@@ -51,10 +48,9 @@ export function nameBook(transport, metas, entities = []) {
|
|
|
51
48
|
}
|
|
52
49
|
return {
|
|
53
50
|
nameOf(entity, id) {
|
|
54
|
-
|
|
55
|
-
if (route === undefined || id === "")
|
|
51
|
+
if (!searchedAlone(entity) || id === "")
|
|
56
52
|
return Promise.resolve(undefined);
|
|
57
|
-
const shelf = known.get(entity.key) ?? {
|
|
53
|
+
const shelf = known.get(entity.key) ?? { entity, names: new Map() };
|
|
58
54
|
known.set(entity.key, shelf);
|
|
59
55
|
const kept = shelf.names.get(id);
|
|
60
56
|
if (kept !== undefined)
|
|
@@ -63,7 +59,7 @@ export function nameBook(transport, metas, entities = []) {
|
|
|
63
59
|
const batch = asking.get(entity.key);
|
|
64
60
|
if (batch !== undefined)
|
|
65
61
|
return void batch.waiting.set(id, answer);
|
|
66
|
-
asking.set(entity.key, { entity,
|
|
62
|
+
asking.set(entity.key, { entity, waiting: new Map([[id, answer]]) });
|
|
67
63
|
// Every key asked in this tick goes in the same request.
|
|
68
64
|
queueMicrotask(() => void ask(entity.key));
|
|
69
65
|
});
|
|
@@ -72,7 +68,7 @@ export function nameBook(transport, metas, entities = []) {
|
|
|
72
68
|
},
|
|
73
69
|
changed(change) {
|
|
74
70
|
for (const [entityKey, shelf] of [...known])
|
|
75
|
-
if (touches(change, shelf.
|
|
71
|
+
if (touches(change, shelf.entity))
|
|
76
72
|
known.delete(entityKey);
|
|
77
73
|
},
|
|
78
74
|
};
|
package/dist/core/server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Draft, type Entity, type
|
|
1
|
+
import { type Draft, type Entity, type OperationTransport, type ResourceRef } from "@sincpro/client-framework";
|
|
2
2
|
import type { AnyRecord, Meta } from "@sincpro/criteria";
|
|
3
3
|
/**
|
|
4
4
|
* A use case's answer read on the server that renders a page, before it is drawn — the very use
|
|
@@ -67,21 +67,22 @@ export type RecordRead<T> = {
|
|
|
67
67
|
};
|
|
68
68
|
/**
|
|
69
69
|
* One record and its model, read on the server that renders the page — the same question
|
|
70
|
-
* `useRecord` asks in the browser, through the same
|
|
70
|
+
* `useRecord` asks in the browser, through the same operations the `FrameworkProvider` is given —,
|
|
71
71
|
* so its screen arrives FILLED in the HTML, not as a skeleton, and the browser does not ask
|
|
72
72
|
* again on mount.
|
|
73
73
|
*
|
|
74
74
|
* // a route's loader or a Server Component — plain logic, no screen loaded
|
|
75
|
-
* const invoice = await readRecordOnServer(
|
|
75
|
+
* const invoice = await readRecordOnServer(operations, invoices, params.id, { meta });
|
|
76
76
|
* return <InvoicePage id={params.id} initial={invoice} />;
|
|
77
77
|
*
|
|
78
78
|
* // the page, rendered there and hydrated in the browser
|
|
79
79
|
* const invoice = useRecord(invoices, id, { initial });
|
|
80
80
|
*
|
|
81
|
-
* `opened` is what the screen opens: a record's id, `""` for a new one —
|
|
82
|
-
*
|
|
81
|
+
* `opened` is what the screen opens: a record's id, `""` for a new one — nothing is read: it
|
|
82
|
+
* starts from its model's definition (`meta`, the contract's) — or the reference the screen
|
|
83
|
+
* receives.
|
|
83
84
|
*
|
|
84
|
-
* Context: it asks through the screens' use case (`
|
|
85
|
+
* Context: it asks through the screens' use case (`screensOperations`), as `useRecord` and
|
|
85
86
|
* `readListing` do — traced like the browser's reads, with the process's context — and answers
|
|
86
87
|
* plain JSON (`RecordRead`): a Client Component is handed data, never instances. A read that
|
|
87
88
|
* fails never refuses the page, as `readOnServer`: it answers `undefined` and one WARN line on
|
|
@@ -93,7 +94,8 @@ export type RecordRead<T> = {
|
|
|
93
94
|
* Plain logic, without React or the DOM (`core/`): a route's loader, a Server Component and a
|
|
94
95
|
* script import it from `@sincpro/web-framework/core` without loading any screen.
|
|
95
96
|
*/
|
|
96
|
-
export declare function readRecordOnServer<T extends AnyRecord>(transport:
|
|
97
|
+
export declare function readRecordOnServer<T extends AnyRecord>(transport: OperationTransport, entity: Entity<T>, opened: string | ResourceRef, options?: {
|
|
97
98
|
what?: string;
|
|
98
99
|
signal?: AbortSignal;
|
|
100
|
+
meta?: Meta | null;
|
|
99
101
|
}): Promise<RecordRead<T> | undefined>;
|