@sincpro/web-framework 1.0.0 → 2.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 +207 -71
- package/dist/core/cache.d.ts +1 -2
- package/dist/core/cache.js +14 -4
- package/dist/core/explain.d.ts +15 -0
- package/dist/core/{transport.js → explain.js} +4 -17
- package/dist/core/form.d.ts +1 -1
- package/dist/core/form.js +1 -0
- package/dist/core/index.d.ts +9 -14
- package/dist/core/index.js +8 -13
- package/dist/core/list.d.ts +5 -4
- package/dist/core/list.js +1 -0
- package/dist/core/lookup.d.ts +1 -1
- package/dist/core/lookup.js +1 -0
- package/dist/core/present.js +1 -1
- package/dist/core/relation.d.ts +12 -2
- package/dist/core/relation.js +30 -2
- package/dist/core/summary.d.ts +1 -6
- package/dist/core/trail.d.ts +1 -1
- package/dist/core/trail.js +1 -0
- package/dist/errors/index.d.ts +48 -0
- package/dist/errors/index.js +56 -0
- package/dist/react/context.d.ts +1 -3
- package/dist/react/context.js +1 -2
- package/dist/react/index.d.ts +4 -1
- package/dist/react/index.js +3 -0
- package/dist/react/scope.d.ts +1 -1
- package/dist/react/scope.js +1 -1
- package/dist/react/useCommand.d.ts +15 -5
- package/dist/react/useCommand.js +7 -5
- package/dist/react/useContextValues.d.ts +15 -0
- package/dist/react/useContextValues.js +19 -0
- package/dist/react/useHistory.d.ts +1 -1
- package/dist/react/useHistory.js +1 -0
- package/dist/react/useListing.d.ts +8 -7
- package/dist/react/useListing.js +8 -7
- package/dist/react/useLookup.d.ts +1 -1
- package/dist/react/useLookup.js +1 -0
- package/dist/react/useNameOf.d.ts +13 -0
- package/dist/react/useNameOf.js +44 -0
- package/dist/react/useRecord.d.ts +1 -2
- package/dist/react/useRecord.js +1 -4
- package/dist/react/useRelated.d.ts +1 -1
- package/dist/react/useRelated.js +1 -0
- package/dist/react/useService.d.ts +38 -0
- package/dist/react/useService.js +66 -0
- package/dist/react/useSummary.d.ts +1 -1
- package/dist/react/useSummary.js +1 -0
- package/dist/telemetry/index.d.ts +45 -0
- package/dist/telemetry/index.js +55 -0
- package/dist/web/Refused.js +1 -1
- package/dist/web/list/EntityList.d.ts +5 -4
- package/dist/web/list/EntityList.js +3 -3
- package/dist/web/list/EntitySearchBar.d.ts +2 -1
- package/dist/web/list/EntitySearchBar.js +17 -11
- package/dist/web/list/presentation.d.ts +3 -3
- package/dist/web/list/presentation.js +2 -0
- package/dist/web/list/rowCommands.d.ts +16 -12
- package/dist/web/list/rowCommands.js +3 -3
- package/dist/web/record/CommandButton.d.ts +9 -6
- package/dist/web/record/CommandButton.js +1 -0
- package/dist/web/record/EntityPicker.d.ts +1 -1
- package/dist/web/record/EntityPicker.js +1 -0
- package/dist/web/record/EntityTags.d.ts +1 -1
- package/dist/web/record/EntityTags.js +1 -0
- package/dist/web/record/RelatedList.d.ts +1 -1
- package/dist/web/record/RelatedList.js +1 -0
- package/dist/web/record/control.d.ts +1 -1
- package/dist/web/record/control.js +1 -1
- package/dist/web/record/edit.js +20 -7
- package/dist/web/record/lines.js +7 -1
- package/dist/web/record/opening.d.ts +1 -1
- package/dist/web/record/opening.js +1 -0
- package/dist/web/workspace/SincproApp.d.ts +1 -2
- package/dist/web/workspace/SincproApp.js +1 -0
- package/dist/web/workspace/composer.d.ts +1 -2
- package/dist/web/workspace/composer.js +2 -2
- package/dist/web/workspace/open.d.ts +1 -1
- package/dist/web/workspace/open.js +1 -0
- package/dist/web/workspace/record.d.ts +1 -1
- package/dist/web/workspace/record.js +1 -1
- package/dist/web/workspace/workspace.d.ts +1 -1
- package/dist/web/workspace/workspace.js +1 -0
- package/package.json +48 -7
- package/dist/core/discovery.d.ts +0 -47
- package/dist/core/discovery.js +0 -68
- package/dist/core/entity.d.ts +0 -159
- package/dist/core/entity.js +0 -142
- package/dist/core/ids.d.ts +0 -17
- package/dist/core/ids.js +0 -52
- package/dist/core/memory.d.ts +0 -43
- package/dist/core/memory.js +0 -99
- package/dist/core/meta.d.ts +0 -121
- package/dist/core/meta.js +0 -130
- package/dist/core/metas.d.ts +0 -17
- package/dist/core/metas.js +0 -7
- package/dist/core/rest.d.ts +0 -34
- package/dist/core/rest.js +0 -127
- package/dist/core/retry.d.ts +0 -24
- package/dist/core/retry.js +0 -25
- package/dist/core/schema.d.ts +0 -39
- package/dist/core/schema.js +0 -128
- package/dist/core/transport.d.ts +0 -79
- package/dist/core/zone.d.ts +0 -27
- package/dist/core/zone.js +0 -75
package/dist/core/list.js
CHANGED
package/dist/core/lookup.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { type SummaryFields } from "@sincpro/client-framework";
|
|
1
2
|
import type { AnyRecord, Meta } from "@sincpro/criteria";
|
|
2
|
-
import { type SummaryFields } from "./summary.js";
|
|
3
3
|
/**
|
|
4
4
|
* A record as a choice: what a many2one select, a «share with» and ⌘K show for it.
|
|
5
5
|
*
|
package/dist/core/lookup.js
CHANGED
package/dist/core/present.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { timeZoneNow } from "@sincpro/client-framework";
|
|
1
2
|
import { choiceLabelOf, labelOf, } from "@sincpro/criteria";
|
|
2
3
|
import { frameworkCopy } from "./copy.js";
|
|
3
4
|
import { relatedOf } from "./related.js";
|
|
4
|
-
import { timeZoneNow } from "./zone.js";
|
|
5
5
|
/** Present when a field is named that the model does not declare: drawn plain, never thrown. */
|
|
6
6
|
const UNKNOWN = {
|
|
7
7
|
type: "unknown",
|
package/dist/core/relation.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { type Entity } from "@sincpro/client-framework";
|
|
1
2
|
import type { FieldMeta, Meta } from "@sincpro/criteria";
|
|
2
|
-
import type { Entity } from "./entity.js";
|
|
3
3
|
/**
|
|
4
4
|
* Which record a field of a form is about, read from the model — so a form draws a many2one
|
|
5
5
|
* as a picker of the right entity without being told.
|
|
@@ -9,6 +9,11 @@ import type { Entity } from "./entity.js";
|
|
|
9
9
|
* joined by `identified_by`. A form may name either; both mean «the customer». A relation
|
|
10
10
|
* names the other side by its AGGREGATE («Cliente»), which says nothing about where it is read
|
|
11
11
|
* — that is the entity the application declared (`entityFor`).
|
|
12
|
+
*
|
|
13
|
+
* A key may also stand alone: `tenant_id: EntityID[Tenant]` on the server is a scalar that says
|
|
14
|
+
* whose record it names (`relation: "auth.Tenant"`) with no relation field beside it. It is a
|
|
15
|
+
* many2one all the same — chosen with the picker of that entity — but only its key is in hand
|
|
16
|
+
* (`held: false`): nothing else is written beside it, and its name is asked for by key.
|
|
12
17
|
*/
|
|
13
18
|
export type RelationField = {
|
|
14
19
|
/** The relation field: `customer`. */
|
|
@@ -19,10 +24,15 @@ export type RelationField = {
|
|
|
19
24
|
target: string;
|
|
20
25
|
many: boolean;
|
|
21
26
|
field: FieldMeta;
|
|
27
|
+
/** The record it points at comes with the record (a relation field the server expands), or
|
|
28
|
+
* only its key does (`EntityID[Tenant]`): then `relation` IS the key. */
|
|
29
|
+
held: boolean;
|
|
22
30
|
};
|
|
23
31
|
export declare function relationFieldOf(meta: Meta | null | undefined, name: string): RelationField | undefined;
|
|
24
32
|
/**
|
|
25
33
|
* The declared entity a relation points at: the one that says it is that aggregate, else the
|
|
26
|
-
* one whose model definition is, else the one whose key it is (`"ventas:cliente"`)
|
|
34
|
+
* one whose model definition is, else the one whose key it is (`"ventas:cliente"`), else the one
|
|
35
|
+
* its model names (`"auth.Tenant"` → `auth:tenant`), else the only one of that kind — a context
|
|
36
|
+
* named by its own name (`sincpro-forge-auth.Tenant`) where the application keys it by alias.
|
|
27
37
|
*/
|
|
28
38
|
export declare function entityFor(entities: readonly Entity[], target: string, metaOf?: (key: string) => Meta | undefined): Entity | undefined;
|
package/dist/core/relation.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { entityKeyOf, kindOf } from "@sincpro/client-framework";
|
|
1
2
|
export function relationFieldOf(meta, name) {
|
|
2
3
|
if (!meta)
|
|
3
4
|
return undefined;
|
|
@@ -9,6 +10,7 @@ export function relationFieldOf(meta, name) {
|
|
|
9
10
|
target: field.relation,
|
|
10
11
|
many: field.many === true,
|
|
11
12
|
field,
|
|
13
|
+
held: true,
|
|
12
14
|
};
|
|
13
15
|
const own = meta.fields[name];
|
|
14
16
|
if (own?.kind === "relation")
|
|
@@ -17,14 +19,40 @@ export function relationFieldOf(meta, name) {
|
|
|
17
19
|
for (const [relation, field] of Object.entries(meta.fields))
|
|
18
20
|
if (field.kind === "relation" && field.identified_by === name)
|
|
19
21
|
return of(relation, field);
|
|
22
|
+
// A key alone that says whose record it names: the record is not in hand, its key is.
|
|
23
|
+
if (own !== undefined && own.kind !== "embedded" && own.relation)
|
|
24
|
+
return {
|
|
25
|
+
relation: name,
|
|
26
|
+
key: name,
|
|
27
|
+
target: own.relation,
|
|
28
|
+
many: own.many === true,
|
|
29
|
+
field: own,
|
|
30
|
+
held: false,
|
|
31
|
+
};
|
|
20
32
|
return undefined;
|
|
21
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Whether `target` names `one` the way a key does — by its model, `auth.Tenant` in another
|
|
36
|
+
* context or `Tenant` in its own —: the name a generated entity's key is made of (`entityKeyOf`).
|
|
37
|
+
*/
|
|
38
|
+
function namedBy(one, target) {
|
|
39
|
+
const dot = target.lastIndexOf(".");
|
|
40
|
+
if (dot === -1)
|
|
41
|
+
return one.key === entityKeyOf(one.domain, target);
|
|
42
|
+
return one.key === entityKeyOf(target.slice(0, dot), target.slice(dot + 1));
|
|
43
|
+
}
|
|
22
44
|
/**
|
|
23
45
|
* The declared entity a relation points at: the one that says it is that aggregate, else the
|
|
24
|
-
* one whose model definition is, else the one whose key it is (`"ventas:cliente"`)
|
|
46
|
+
* one whose model definition is, else the one whose key it is (`"ventas:cliente"`), else the one
|
|
47
|
+
* its model names (`"auth.Tenant"` → `auth:tenant`), else the only one of that kind — a context
|
|
48
|
+
* named by its own name (`sincpro-forge-auth.Tenant`) where the application keys it by alias.
|
|
25
49
|
*/
|
|
26
50
|
export function entityFor(entities, target, metaOf = () => undefined) {
|
|
51
|
+
const model = target.slice(target.lastIndexOf(".") + 1);
|
|
52
|
+
const ofKind = entities.filter((one) => one.kind === kindOf(model));
|
|
27
53
|
return (entities.find((one) => one.aggregate === target) ??
|
|
28
54
|
entities.find((one) => metaOf(one.key)?.aggregate === target) ??
|
|
29
|
-
entities.find((one) => one.key === target)
|
|
55
|
+
entities.find((one) => one.key === target) ??
|
|
56
|
+
entities.find((one) => namedBy(one, target)) ??
|
|
57
|
+
(ofKind.length === 1 ? ofKind[0] : undefined));
|
|
30
58
|
}
|
package/dist/core/summary.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SummaryFields, SummaryPart } from "@sincpro/client-framework";
|
|
1
2
|
import type { AnyRecord, Meta } from "@sincpro/criteria";
|
|
2
3
|
/**
|
|
3
4
|
* What is known about ANY record, the same for every entity: its name and, when it has them,
|
|
@@ -13,12 +14,6 @@ import type { AnyRecord, Meta } from "@sincpro/criteria";
|
|
|
13
14
|
* …). The name is the model's own `display`. When the backend publishes these parts in its
|
|
14
15
|
* model definition, they are read from there and the convention steps aside.
|
|
15
16
|
*/
|
|
16
|
-
export type SummaryPart = "description" | "state" | "type" | "image" | "createdAt" | "createdBy" | "updatedAt" | "updatedBy";
|
|
17
|
-
/** Which field of the entity plays each part, when it is not the conventional one.
|
|
18
|
-
* `person`: its records are people or companies — a round face, initials without a photo. */
|
|
19
|
-
export type SummaryFields = Partial<Record<SummaryPart, string>> & {
|
|
20
|
-
person?: boolean;
|
|
21
|
-
};
|
|
22
17
|
export type RecordSummary = {
|
|
23
18
|
id: string;
|
|
24
19
|
name: string;
|
package/dist/core/trail.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { type Transport } from "@sincpro/client-framework";
|
|
1
2
|
import type { Criteria } from "@sincpro/criteria";
|
|
2
|
-
import type { Transport } from "./transport.js";
|
|
3
3
|
/**
|
|
4
4
|
* Where a record was opened from: the page of the list it was a row of, so the record can go
|
|
5
5
|
* to the previous and the next one — «3 / 64» and two arrows — without going back to the list.
|
package/dist/core/trail.js
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ErrorReporter } from "@sincpro/client-framework";
|
|
2
|
+
/**
|
|
3
|
+
* An `ErrorReporter` for the browser, built from the application's own settings: a
|
|
4
|
+
* Sentry-compatible client — GlitchTip, where the backend reports too — with the application's
|
|
5
|
+
* DSN.
|
|
6
|
+
*
|
|
7
|
+
* // the application — domains/common/infrastructure/telemetry.ts
|
|
8
|
+
* import { glitchtipReporter } from "./index.js";
|
|
9
|
+
* const reporter = glitchtipReporter({ dsn: settings.glitchtip, release, environment });
|
|
10
|
+
* configureProcess({ tracer, reporter }); // entrypoints/main.tsx
|
|
11
|
+
*
|
|
12
|
+
* Context: optional on every count, like `./telemetry`: an entry of its own, `@sentry/browser`
|
|
13
|
+
* an optional peer, and only a convenience — an application with its own client wraps it with
|
|
14
|
+
* `sentryReporter` (`@sincpro/client-framework/sentry`), or hands any `ErrorReporter`.
|
|
15
|
+
*
|
|
16
|
+
* It never breaks what it serves: the SDK loads after the first render; what is reported before
|
|
17
|
+
* it is there waits (a handful), and if it is not installed or fails, reports are dropped and
|
|
18
|
+
* that is said once on the console. Nothing global: no `Sentry.init`, no handlers on `window` —
|
|
19
|
+
* this client is the reporter's own, and only what the process decides is unexpected reaches it.
|
|
20
|
+
*
|
|
21
|
+
* What it sends is narrow by default, because in an ERP a request body is an invoice and a
|
|
22
|
+
* customer: no breadcrumbs or default integrations, and every event leaves without cookies,
|
|
23
|
+
* headers, request bodies, query strings or the user's address. `beforeSend` is the
|
|
24
|
+
* application's, run after that.
|
|
25
|
+
*/
|
|
26
|
+
export type GlitchtipOptions = {
|
|
27
|
+
/** The application's DSN. Public by nature: it ships to the browser. */
|
|
28
|
+
dsn: string;
|
|
29
|
+
release?: string;
|
|
30
|
+
environment?: string;
|
|
31
|
+
/** Fraction of errors sent, 0 to 1. Default 1. */
|
|
32
|
+
sampling?: number;
|
|
33
|
+
/** The application's last word on an event: change it, or answer `null` to drop it. */
|
|
34
|
+
beforeSend?: (event: SentEvent) => SentEvent | null;
|
|
35
|
+
};
|
|
36
|
+
/** The parts of an event this reporter narrows; the rest passes as the SDK built it. */
|
|
37
|
+
export type SentEvent = {
|
|
38
|
+
request?: {
|
|
39
|
+
url?: string;
|
|
40
|
+
cookies?: unknown;
|
|
41
|
+
headers?: unknown;
|
|
42
|
+
data?: unknown;
|
|
43
|
+
query_string?: unknown;
|
|
44
|
+
};
|
|
45
|
+
user?: unknown;
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
};
|
|
48
|
+
export declare function glitchtipReporter(options: GlitchtipOptions): ErrorReporter;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const WAITING_AT_MOST = 20;
|
|
2
|
+
/** Every event leaves without what may carry a person's or a customer's data. */
|
|
3
|
+
function narrowed(event) {
|
|
4
|
+
const { user: _user, ...rest } = event;
|
|
5
|
+
if (rest.request === undefined)
|
|
6
|
+
return rest;
|
|
7
|
+
const { cookies: _c, headers: _h, data: _d, query_string: _q, ...request } = rest.request;
|
|
8
|
+
return {
|
|
9
|
+
...rest,
|
|
10
|
+
request: { ...request, ...(request.url ? { url: request.url.split("?")[0] } : {}) },
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function glitchtipReporter(options) {
|
|
14
|
+
let ready = null;
|
|
15
|
+
let failed = false;
|
|
16
|
+
const waiting = [];
|
|
17
|
+
void (async () => {
|
|
18
|
+
try {
|
|
19
|
+
const [sentry, { sentryReporter }] = await Promise.all([
|
|
20
|
+
import("@sentry/browser"),
|
|
21
|
+
import("@sincpro/client-framework/sentry"),
|
|
22
|
+
]);
|
|
23
|
+
const client = new sentry.BrowserClient({
|
|
24
|
+
dsn: options.dsn,
|
|
25
|
+
transport: sentry.makeFetchTransport,
|
|
26
|
+
stackParser: sentry.defaultStackParser,
|
|
27
|
+
integrations: [],
|
|
28
|
+
...(options.release ? { release: options.release } : {}),
|
|
29
|
+
...(options.environment ? { environment: options.environment } : {}),
|
|
30
|
+
...(options.sampling === undefined ? {} : { sampleRate: options.sampling }),
|
|
31
|
+
beforeSend: (event) => {
|
|
32
|
+
const own = narrowed(event);
|
|
33
|
+
const kept = options.beforeSend ? options.beforeSend(own) : own;
|
|
34
|
+
return kept;
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
client.init();
|
|
38
|
+
ready = sentryReporter(client);
|
|
39
|
+
for (const [error, about] of waiting.splice(0))
|
|
40
|
+
ready.report(error, about);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
failed = true;
|
|
44
|
+
waiting.length = 0;
|
|
45
|
+
console.warn("@sincpro/web-framework/errors: error reporting is off — @sentry/browser did not load", error);
|
|
46
|
+
}
|
|
47
|
+
})();
|
|
48
|
+
return {
|
|
49
|
+
report(error, about) {
|
|
50
|
+
if (ready !== null)
|
|
51
|
+
return ready.report(error, about);
|
|
52
|
+
if (!failed && waiting.length < WAITING_AT_MOST)
|
|
53
|
+
waiting.push([error, about]);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
package/dist/react/context.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
+
import { type Entity, type MetaStore, type Transport } from "@sincpro/client-framework";
|
|
1
2
|
import type { Meta } from "@sincpro/criteria";
|
|
2
|
-
import type { Entity } from "../core/entity.js";
|
|
3
|
-
import { type MetaStore } from "../core/metas.js";
|
|
4
3
|
import type { Trail } from "../core/trail.js";
|
|
5
|
-
import type { Transport } from "../core/transport.js";
|
|
6
4
|
import { type ReactNode } from "react";
|
|
7
5
|
/**
|
|
8
6
|
* Who answers, in which language a screen reads, and which model definitions are already
|
package/dist/react/context.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { metaStore } from "
|
|
3
|
+
import { installTimeZone, metaStore, } from "@sincpro/client-framework";
|
|
4
4
|
import { entityFor } from "../core/relation.js";
|
|
5
|
-
import { installTimeZone } from "../core/zone.js";
|
|
6
5
|
import { createContext, useContext, useMemo, useRef, useState } from "react";
|
|
7
6
|
const FrameworkContext = createContext(null);
|
|
8
7
|
export function FrameworkProvider({ transport, locale, metas: seed, entities = NO_ENTITIES, timeZone, children, }) {
|
package/dist/react/index.d.ts
CHANGED
|
@@ -5,12 +5,15 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { FrameworkProvider, useEntityFor, useFramework, } from "./context.js";
|
|
7
7
|
export { type ListScope, ListScopeProvider, useListScope, } from "./scope.js";
|
|
8
|
-
export { type CommandState, type Rehearsal, useCommand, } from "./useCommand.js";
|
|
8
|
+
export { type AnswerOf, type CommandState, type Rehearsal, useCommand, } from "./useCommand.js";
|
|
9
|
+
export { useContextValues } from "./useContextValues.js";
|
|
9
10
|
export { type Groups, useGroups } from "./useGroups.js";
|
|
10
11
|
export { useHistory } from "./useHistory.js";
|
|
11
12
|
export { type Listing, type ListingOptions, type Paging, useListing, } from "./useListing.js";
|
|
12
13
|
export { excluding, type Lookup, useLookup } from "./useLookup.js";
|
|
14
|
+
export { useNameOf } from "./useNameOf.js";
|
|
13
15
|
export { type PivotAxes, type PivotReading, usePivot, } from "./usePivot.js";
|
|
14
16
|
export { type Editing, type RecordReading, type RecordState, useRecord, } from "./useRecord.js";
|
|
15
17
|
export { useRelated } from "./useRelated.js";
|
|
18
|
+
export { type ServiceState, useService } from "./useService.js";
|
|
16
19
|
export { useSummaryOf } from "./useSummary.js";
|
package/dist/react/index.js
CHANGED
|
@@ -6,11 +6,14 @@
|
|
|
6
6
|
export { FrameworkProvider, useEntityFor, useFramework, } from "./context.js";
|
|
7
7
|
export { ListScopeProvider, useListScope, } from "./scope.js";
|
|
8
8
|
export { useCommand, } from "./useCommand.js";
|
|
9
|
+
export { useContextValues } from "./useContextValues.js";
|
|
9
10
|
export { useGroups } from "./useGroups.js";
|
|
10
11
|
export { useHistory } from "./useHistory.js";
|
|
11
12
|
export { useListing, } from "./useListing.js";
|
|
12
13
|
export { excluding, useLookup } from "./useLookup.js";
|
|
14
|
+
export { useNameOf } from "./useNameOf.js";
|
|
13
15
|
export { usePivot, } from "./usePivot.js";
|
|
14
16
|
export { useRecord, } from "./useRecord.js";
|
|
15
17
|
export { useRelated } from "./useRelated.js";
|
|
18
|
+
export { useService } from "./useService.js";
|
|
16
19
|
export { useSummaryOf } from "./useSummary.js";
|
package/dist/react/scope.d.ts
CHANGED
package/dist/react/scope.js
CHANGED
|
@@ -8,5 +8,5 @@ export function ListScopeProvider({ value, children, }) {
|
|
|
8
8
|
/** The cut the screen gave for the lists of `key`, or none. */
|
|
9
9
|
export function useListScope(key) {
|
|
10
10
|
const scope = useContext(Scope);
|
|
11
|
-
return scope !== null && scope.key === key ? scope.
|
|
11
|
+
return scope !== null && scope.key === key ? scope.selection : undefined;
|
|
12
12
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { type CommandAnswers, type CommandBodies, type Entity } from "@sincpro/client-framework";
|
|
1
2
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
2
|
-
import { type Entity } from "../core/entity.js";
|
|
3
3
|
/**
|
|
4
4
|
* One Command of an entity: run it, or ask first what it would do.
|
|
5
5
|
*
|
|
@@ -12,19 +12,29 @@ import { type Entity } from "../core/entity.js";
|
|
|
12
12
|
* One at a time: `busy` turns the button off, because a payment sent twice is two payments. And
|
|
13
13
|
* once sent, the same gesture keeps its `Idempotency-Key` until the server answers: a retry
|
|
14
14
|
* after a dropped request is the same payment, never a second one (`retryKeys`).
|
|
15
|
+
*
|
|
16
|
+
* A typed entity (`entity<Issue, { send: { message: string } }>`) gets its names and bodies
|
|
17
|
+
* checked: `useCommand(issues, "send").run(id, { mesage })` does not compile. TypeScript infers
|
|
18
|
+
* that only when no type argument is written — `useCommand<Issue, Answer>(…)` stays loose.
|
|
15
19
|
*/
|
|
16
20
|
export type Rehearsal = {
|
|
17
21
|
text: string;
|
|
18
22
|
data: Record<string, unknown>;
|
|
19
23
|
};
|
|
20
|
-
export type CommandState<R> = {
|
|
21
|
-
|
|
24
|
+
export type CommandState<R, B extends AnyRecord = AnyRecord> = {
|
|
25
|
+
/** Without a body, an empty one: the route may name everything. A body given is checked. */
|
|
26
|
+
run: (id?: string, body?: B) => Promise<R | undefined>;
|
|
22
27
|
/** The dry run: what it would do, nothing touched. */
|
|
23
|
-
rehearse: (id?: string, body?:
|
|
28
|
+
rehearse: (id?: string, body?: B) => Promise<Rehearsal | undefined>;
|
|
24
29
|
busy: boolean;
|
|
25
30
|
error: unknown;
|
|
26
31
|
/** The last dry run's answer, until `reset`. */
|
|
27
32
|
rehearsal: Rehearsal | null;
|
|
28
33
|
reset: () => void;
|
|
29
34
|
};
|
|
30
|
-
|
|
35
|
+
/**
|
|
36
|
+
* What a Command answers: `R` when the screen writes it, else what its entity says the Command
|
|
37
|
+
* answers (`CommandAnswers`), else `unknown`.
|
|
38
|
+
*/
|
|
39
|
+
export type AnswerOf<R, A, N> = unknown extends R ? (N extends keyof A ? A[N] : unknown) : R;
|
|
40
|
+
export declare function useCommand<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>(entity: Entity<T, C, A>, name: N): CommandState<AnswerOf<R, A, N>, C[N]>;
|
package/dist/react/useCommand.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { pathFor } from "
|
|
3
|
-
import { retryKeys } from "../core/retry.js";
|
|
2
|
+
import { bodyFor, pathFor, retryKeys, } from "@sincpro/client-framework";
|
|
4
3
|
import { useFramework } from "./context.js";
|
|
5
4
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
6
5
|
export function useCommand(entity, name) {
|
|
7
6
|
const { transport } = useFramework();
|
|
7
|
+
// A name outside the declared ones still reaches here from untyped code: say which.
|
|
8
8
|
const route = entity.commands[name];
|
|
9
9
|
if (route === undefined)
|
|
10
10
|
throw new Error(`${entity.key} declares no command "${name}"`);
|
|
@@ -25,8 +25,10 @@ export function useCommand(entity, name) {
|
|
|
25
25
|
setBusy(true);
|
|
26
26
|
setError(null);
|
|
27
27
|
const idempotencyKey = gesture.keyFor({ id, body });
|
|
28
|
+
// A Command whose body names its record (`target`) gets the id there.
|
|
29
|
+
const sent = bodyFor(route, id, body);
|
|
28
30
|
try {
|
|
29
|
-
const answer = await transport.send(route.method, pathFor(route, id,
|
|
31
|
+
const answer = await transport.send(route.method, pathFor(route, id, sent), sent, undefined, { idempotencyKey });
|
|
30
32
|
gesture.settle(null);
|
|
31
33
|
return answer;
|
|
32
34
|
}
|
|
@@ -42,8 +44,8 @@ export function useCommand(entity, name) {
|
|
|
42
44
|
}
|
|
43
45
|
}, [transport, route]);
|
|
44
46
|
return {
|
|
45
|
-
run: (id, body
|
|
46
|
-
rehearse: async (id, body
|
|
47
|
+
run: (id, body) => send(id, body ?? {}, keys.current),
|
|
48
|
+
rehearse: async (id, body) => {
|
|
47
49
|
const answer = await send(id, { ...body, dry_run: true }, retryKeys());
|
|
48
50
|
if (answer !== undefined && mounted.current)
|
|
49
51
|
setRehearsal(answer);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Context, ContextValues } from "@sincpro/client-framework";
|
|
2
|
+
/**
|
|
3
|
+
* The values of one level of the context, drawn again whenever they change.
|
|
4
|
+
*
|
|
5
|
+
* const { company_id } = useContextValues(processContext); // the company picker changed it
|
|
6
|
+
* const own = useContextValues(project.context); // only what «project» runs with
|
|
7
|
+
*
|
|
8
|
+
* Context: the context is @sincpro/client-framework's — what every use case runs with and sends
|
|
9
|
+
* to the server — and where it lives is the platform's (`ContextStore`, chosen in `main` with
|
|
10
|
+
* `configureProcess`). A screen only reads it: a level's `values` is the same object until it
|
|
11
|
+
* changes and its `watch` is bound, which is exactly what React's external stores ask for. Writing
|
|
12
|
+
* stays the level's (`processContext.set({ company_id })`), so a screen, a service and a test
|
|
13
|
+
* change it the same way and nothing here is a second store.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useContextValues<C extends object = ContextValues>(context: Context<C>): Readonly<Partial<C>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* The values of one level of the context, drawn again whenever they change.
|
|
5
|
+
*
|
|
6
|
+
* const { company_id } = useContextValues(processContext); // the company picker changed it
|
|
7
|
+
* const own = useContextValues(project.context); // only what «project» runs with
|
|
8
|
+
*
|
|
9
|
+
* Context: the context is @sincpro/client-framework's — what every use case runs with and sends
|
|
10
|
+
* to the server — and where it lives is the platform's (`ContextStore`, chosen in `main` with
|
|
11
|
+
* `configureProcess`). A screen only reads it: a level's `values` is the same object until it
|
|
12
|
+
* changes and its `watch` is bound, which is exactly what React's external stores ask for. Writing
|
|
13
|
+
* stays the level's (`processContext.set({ company_id })`), so a screen, a service and a test
|
|
14
|
+
* change it the same way and nothing here is a second store.
|
|
15
|
+
*/
|
|
16
|
+
export function useContextValues(context) {
|
|
17
|
+
const values = () => context.values;
|
|
18
|
+
return useSyncExternalStore(context.watch, values, values);
|
|
19
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { type Entity } from "@sincpro/client-framework";
|
|
1
2
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
2
|
-
import type { Entity } from "../core/entity.js";
|
|
3
3
|
import { type HistoryEntry } from "../core/history.js";
|
|
4
4
|
import { type DependencyList } from "react";
|
|
5
5
|
export declare function useHistory<T extends AnyRecord>(entity: Entity<T>, id: string, deps?: DependencyList): HistoryEntry[] | undefined;
|
package/dist/react/useHistory.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { type CommandBodies, type Entity } from "@sincpro/client-framework";
|
|
1
2
|
import { type AnyRecord, type Count, type Criteria, type Dropped, type Expression, type Meta, type ReadingStatus, type Sort } from "@sincpro/criteria";
|
|
2
|
-
import { type Entity } from "../core/entity.js";
|
|
3
3
|
import { type ListDefinition } from "../core/list.js";
|
|
4
4
|
/**
|
|
5
5
|
* N records of an entity, live: what a list draws and the gestures that drive it.
|
|
@@ -17,8 +17,9 @@ import { type ListDefinition } from "../core/list.js";
|
|
|
17
17
|
* All three refine the same reading instead of starting another. It holds state and draws
|
|
18
18
|
* nothing: `EntityList` draws it, and a screen that needs another shape draws it itself.
|
|
19
19
|
*/
|
|
20
|
-
export type Listing<T> = {
|
|
21
|
-
entity
|
|
20
|
+
export type Listing<T, C extends CommandBodies = CommandBodies> = {
|
|
21
|
+
/** Its entity, with the Commands it types (`entity<T, C>`): what `useRowCommands` checks. */
|
|
22
|
+
entity: Entity<T & AnyRecord, C>;
|
|
22
23
|
/** The named list it reads, when it was handed one (`defineList`): what `EntityList` draws
|
|
23
24
|
* by default — its columns, filters, faces, title — and how `useGroups` starts. */
|
|
24
25
|
definition?: ListDefinition<T & AnyRecord>;
|
|
@@ -46,9 +47,9 @@ export type Listing<T> = {
|
|
|
46
47
|
search: (text: string, options?: {
|
|
47
48
|
now?: boolean;
|
|
48
49
|
}) => void;
|
|
49
|
-
/** What the search bar put
|
|
50
|
-
|
|
51
|
-
filter: (
|
|
50
|
+
/** What the search bar put, as criteria's `selection`; `undefined` is nothing. */
|
|
51
|
+
selection: Expression<T> | undefined;
|
|
52
|
+
filter: (selection: Expression<T> | undefined) => void;
|
|
52
53
|
/** The order the server was asked for, by one field then the next; empty is the entity's own
|
|
53
54
|
* default. */
|
|
54
55
|
order: readonly Sort[];
|
|
@@ -94,4 +95,4 @@ export type ListingOptions<T> = {
|
|
|
94
95
|
/** `more` mode: the most rows ever on screen. 500 by default. */
|
|
95
96
|
maxRows?: number;
|
|
96
97
|
};
|
|
97
|
-
export declare function useListing<T extends AnyRecord>(given: Entity<T> | ListDefinition<T>, own?: ListingOptions<T>): Listing<T>;
|
|
98
|
+
export declare function useListing<T extends AnyRecord, C extends CommandBodies = CommandBodies>(given: Entity<T, C> | ListDefinition<T>, own?: ListingOptions<T>): Listing<T, C>;
|
package/dist/react/useListing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { listRoute } from "@sincpro/client-framework";
|
|
2
3
|
import { merge, resource, resumingFrom, searchOver, } from "@sincpro/criteria";
|
|
3
4
|
import { useReading } from "@sincpro/criteria-react";
|
|
4
|
-
import { listRoute } from "../core/entity.js";
|
|
5
5
|
import { isList, scopeOf } from "../core/list.js";
|
|
6
6
|
import { useFramework } from "./context.js";
|
|
7
7
|
import { useListScope } from "./scope.js";
|
|
@@ -12,7 +12,8 @@ export function useListing(given, own = {}) {
|
|
|
12
12
|
const { transport, locale, metas } = useFramework();
|
|
13
13
|
// A named list is its entity under a fixed scope: the scope ANDs under the caller's own.
|
|
14
14
|
const definition = isList(given) ? given : undefined;
|
|
15
|
-
|
|
15
|
+
// A named list's entity has no typed Commands of its own: the default, as `C` then is.
|
|
16
|
+
const entity = (definition?.entity ?? given);
|
|
16
17
|
// The screen's cut for this entity (a chooser's, `ListScopeProvider`) ANDs like a scope.
|
|
17
18
|
const cut = useListScope(entity.key);
|
|
18
19
|
const scopes = [
|
|
@@ -50,7 +51,7 @@ export function useListing(given, own = {}) {
|
|
|
50
51
|
const meta = reading.meta ?? known.current;
|
|
51
52
|
const [narrowing, setNarrowing] = useState({
|
|
52
53
|
text: "",
|
|
53
|
-
|
|
54
|
+
selection: undefined,
|
|
54
55
|
order: [],
|
|
55
56
|
});
|
|
56
57
|
const typing = useRef(null);
|
|
@@ -60,8 +61,8 @@ export function useListing(given, own = {}) {
|
|
|
60
61
|
const found = searchOver(meta, next.text);
|
|
61
62
|
if (found !== undefined)
|
|
62
63
|
criteria = merge(criteria, { selection: found });
|
|
63
|
-
if (next.
|
|
64
|
-
criteria = merge(criteria, { selection: next.
|
|
64
|
+
if (next.selection !== undefined)
|
|
65
|
+
criteria = merge(criteria, { selection: next.selection });
|
|
65
66
|
if (next.order.length > 0)
|
|
66
67
|
criteria = merge(criteria, { order: [...next.order] });
|
|
67
68
|
return criteria;
|
|
@@ -134,8 +135,8 @@ export function useListing(given, own = {}) {
|
|
|
134
135
|
reload: () => void reading.reload(),
|
|
135
136
|
text: narrowing.text,
|
|
136
137
|
search: (text, options) => narrow({ text }, options?.now !== true),
|
|
137
|
-
|
|
138
|
-
filter: (
|
|
138
|
+
selection: narrowing.selection,
|
|
139
|
+
filter: (selection) => narrow({ selection }, false),
|
|
139
140
|
order: narrowing.order,
|
|
140
141
|
orderBy: (order) => narrow({ order: order === null ? [] : Array.isArray(order) ? order : [order] }, false),
|
|
141
142
|
paging,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { type Entity } from "@sincpro/client-framework";
|
|
1
2
|
import { type AnyRecord, type Criteria, type Meta } from "@sincpro/criteria";
|
|
2
|
-
import type { Entity } from "../core/entity.js";
|
|
3
3
|
import { type ListDefinition } from "../core/list.js";
|
|
4
4
|
import { type LookupOption } from "../core/lookup.js";
|
|
5
5
|
/**
|
package/dist/react/useLookup.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Entity } from "@sincpro/client-framework";
|
|
2
|
+
/**
|
|
3
|
+
* The name of one record of an entity, by its key — what a field shows when it holds only the
|
|
4
|
+
* key (`EntityID[Tenant]`) and not the record it points at.
|
|
5
|
+
*
|
|
6
|
+
* Context: asked ONCE by key, the way `useLookup` names a chosen record it never saw: a page
|
|
7
|
+
* narrowed to that key, one row, read with the definition the application knows. Unnamed is no
|
|
8
|
+
* error — the field shows the key — and an entity listed under another record
|
|
9
|
+
* (`/tenants/{tenant_id}/members`) has no list to ask by key, so it stays unnamed.
|
|
10
|
+
*
|
|
11
|
+
* const name = useNameOf(tenants, record.tenant_id) ?? record.tenant_id;
|
|
12
|
+
*/
|
|
13
|
+
export declare function useNameOf(entity: Entity | undefined, id: string): string | undefined;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { listRoute } from "@sincpro/client-framework";
|
|
3
|
+
import { lookupOf } from "../core/lookup.js";
|
|
4
|
+
import { useFramework } from "./context.js";
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
/**
|
|
7
|
+
* The name of one record of an entity, by its key — what a field shows when it holds only the
|
|
8
|
+
* key (`EntityID[Tenant]`) and not the record it points at.
|
|
9
|
+
*
|
|
10
|
+
* Context: asked ONCE by key, the way `useLookup` names a chosen record it never saw: a page
|
|
11
|
+
* narrowed to that key, one row, read with the definition the application knows. Unnamed is no
|
|
12
|
+
* error — the field shows the key — and an entity listed under another record
|
|
13
|
+
* (`/tenants/{tenant_id}/members`) has no list to ask by key, so it stays unnamed.
|
|
14
|
+
*
|
|
15
|
+
* const name = useNameOf(tenants, record.tenant_id) ?? record.tenant_id;
|
|
16
|
+
*/
|
|
17
|
+
export function useNameOf(entity, id) {
|
|
18
|
+
const { transport, metas } = useFramework();
|
|
19
|
+
const [named, setNamed] = useState(undefined);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (entity === undefined || id === "")
|
|
22
|
+
return;
|
|
23
|
+
let route;
|
|
24
|
+
try {
|
|
25
|
+
route = listRoute(entity.list);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const known = metas.get(entity.key);
|
|
31
|
+
const key = known?.get_id || known?.identity || "id";
|
|
32
|
+
const aborter = new AbortController();
|
|
33
|
+
transport
|
|
34
|
+
.list(route, { selection: { field: key, operator: "=", value: id }, pagination: { limit: 1 } }, aborter.signal)
|
|
35
|
+
.then((page) => {
|
|
36
|
+
const [one] = lookupOf(page.meta ?? known ?? null, page.rows, entity.summary);
|
|
37
|
+
if (one !== undefined)
|
|
38
|
+
setNamed({ id, name: one.label });
|
|
39
|
+
})
|
|
40
|
+
.catch(() => undefined);
|
|
41
|
+
return () => aborter.abort();
|
|
42
|
+
}, [transport, metas, entity, id]);
|
|
43
|
+
return named?.id === id ? named.name : undefined;
|
|
44
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { type Draft, type Entity, type EntityRef } from "@sincpro/client-framework";
|
|
1
2
|
import type { AnyRecord, Meta } from "@sincpro/criteria";
|
|
2
3
|
import { type Advice, type FieldState } from "../core/edit.js";
|
|
3
|
-
import { type Entity, type EntityRef } from "../core/entity.js";
|
|
4
|
-
import { type Draft } from "../core/transport.js";
|
|
5
4
|
/**
|
|
6
5
|
* ONE record of an entity, with the definition of its model — read, and edited.
|
|
7
6
|
*
|