@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/web/record/edit.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import {} from "@sincpro/client-framework";
|
|
3
4
|
import { choicesOf } from "@sincpro/criteria";
|
|
4
5
|
import { frameworkCopy } from "../../core/copy.js";
|
|
5
6
|
import { errorAt } from "../../core/edit.js";
|
|
@@ -7,12 +8,19 @@ import { editableLines } from "../../core/lines.js";
|
|
|
7
8
|
import { textOf, viewOf } from "../../core/present.js";
|
|
8
9
|
import { relationFieldOf } from "../../core/relation.js";
|
|
9
10
|
import { useEntityFor, useFramework } from "../../react/context.js";
|
|
11
|
+
import { useNameOf } from "../../react/useNameOf.js";
|
|
10
12
|
import { controlFor, RelationPicker, } from "./control.js";
|
|
11
13
|
import { RecordLinesEditor } from "./lines.js";
|
|
12
14
|
import { useRecordOpening } from "./opening.js";
|
|
13
15
|
import { RecordLines } from "./record.js";
|
|
14
16
|
import { RelatedList } from "./RelatedList.js";
|
|
15
17
|
import { Checkbox, Field, FormSection, ReadValue, RelationValue, } from "@sincpro/web-ui";
|
|
18
|
+
/** A key alone, read: the name of the record it points at, asked once by key — the key until
|
|
19
|
+
* then, and when nothing answers. */
|
|
20
|
+
function KeyValue({ target, id, ...rest }) {
|
|
21
|
+
const name = useNameOf(target, id);
|
|
22
|
+
return _jsx(RelationValue, { name: name ?? id, ...rest });
|
|
23
|
+
}
|
|
16
24
|
/**
|
|
17
25
|
* One field of a record being edited, from the model: its word, whether it is required or
|
|
18
26
|
* read-only now (the hints, evaluated over what is on screen), the server's error for it, and a
|
|
@@ -99,13 +107,18 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
|
|
|
99
107
|
return null;
|
|
100
108
|
const key = edit.values[relation.key];
|
|
101
109
|
const id = key === null || key === undefined ? "" : String(key);
|
|
102
|
-
if (state.readonly)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
if (state.readonly) {
|
|
111
|
+
const opens = opening === null || id === ""
|
|
112
|
+
? {}
|
|
113
|
+
: {
|
|
114
|
+
onOpenIn: (to) => opening.open(target.ref(id), to),
|
|
115
|
+
openTargets: opening.targets,
|
|
116
|
+
};
|
|
117
|
+
// A relation held beside its key names itself; a key alone (`EntityID`) asks its name.
|
|
118
|
+
if (!relation.held)
|
|
119
|
+
return _jsx(KeyValue, { target: target, id: id, ...opens });
|
|
120
|
+
return (_jsx(RelationValue, { name: textOf(meta, relation.relation, edit.values[relation.relation], locale) ?? id, ...opens }));
|
|
121
|
+
}
|
|
109
122
|
return (_jsx(RelationPicker, { target: target, value: id, onChange: (next) => edit.set(relation.key, next), label: view.label }));
|
|
110
123
|
}
|
|
111
124
|
if (view.type === "boolean" && as === undefined)
|
package/dist/web/record/lines.js
CHANGED
|
@@ -42,7 +42,13 @@ function LineValue({ definition, field, line, set, label, invalid, locale, inCel
|
|
|
42
42
|
});
|
|
43
43
|
if (relation !== undefined && !relation.many && target !== undefined) {
|
|
44
44
|
const key = line[relation.key];
|
|
45
|
-
return (_jsx(RelationPicker, { target: target, value: key === null || key === undefined ? "" : String(key), label: label, standalone: inCell, onChange: (id, chosen) =>
|
|
45
|
+
return (_jsx(RelationPicker, { target: target, value: key === null || key === undefined ? "" : String(key), label: label, standalone: inCell, onChange: (id, chosen) =>
|
|
46
|
+
// A relation held beside its key keeps the chosen record, so the cell names it at
|
|
47
|
+
// once; a key alone (`EntityID`) is only its key — writing the record there too
|
|
48
|
+
// would put the record IN the key.
|
|
49
|
+
write(relation.held
|
|
50
|
+
? { [relation.key]: id, [relation.relation]: chosen ?? null }
|
|
51
|
+
: { [relation.key]: id }) }));
|
|
46
52
|
}
|
|
47
53
|
return controlFor({
|
|
48
54
|
value: line[field],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { type Entity, type EntityRef } from "@sincpro/client-framework";
|
|
1
2
|
import { type AnyRecord, type Criteria, type Expression } from "@sincpro/criteria";
|
|
2
|
-
import type { Entity, EntityRef } from "../../core/entity.js";
|
|
3
3
|
import { type ListDefinition } from "../../core/list.js";
|
|
4
4
|
import type { OpenTarget } from "@sincpro/web-ui";
|
|
5
5
|
import { type ReactNode } from "react";
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { type Entity, type Transport } from "@sincpro/client-framework";
|
|
1
2
|
import type { Meta } from "@sincpro/criteria";
|
|
2
3
|
import { type ComposerSkin, type ResourceRef, type ViewSpec, type WorkspaceStore } from "@sincpro/web-composer";
|
|
3
4
|
import { type CacheOptions } from "../../core/cache.js";
|
|
4
|
-
import type { Entity } from "../../core/entity.js";
|
|
5
|
-
import type { Transport } from "../../core/transport.js";
|
|
6
5
|
import { type ReactNode } from "react";
|
|
7
6
|
/**
|
|
8
7
|
* The application context in one place: who answers (the transport), in which language, which
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import {} from "@sincpro/client-framework";
|
|
3
4
|
import { Composer, installComposerCopy, SPANISH_COMPOSER_COPY, useWorkspace, } from "@sincpro/web-composer";
|
|
4
5
|
import { createRegistry } from "@sincpro/web-composer/domain";
|
|
5
6
|
import { cachedTransport } from "../../core/cache.js";
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { type Entity, type Transport } from "@sincpro/client-framework";
|
|
1
2
|
import { type AnyRecord, type Meta } from "@sincpro/criteria";
|
|
2
3
|
import type { ViewProps, ViewSpec } from "@sincpro/web-composer";
|
|
3
|
-
import { type Entity } from "../../core/entity.js";
|
|
4
4
|
import type { ListDefinition } from "../../core/list.js";
|
|
5
|
-
import type { Transport } from "../../core/transport.js";
|
|
6
5
|
import { type ComponentType } from "react";
|
|
7
6
|
/**
|
|
8
7
|
* An entity as the composer's view: one `ViewSpec` for its list (a reference without an id)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { listRoute, NEW_PARAM, scopeOfRef, } from "@sincpro/client-framework";
|
|
3
4
|
import { matching } from "@sincpro/criteria";
|
|
4
|
-
import { listRoute, NEW_PARAM, scopeOfRef, } from "../../core/entity.js";
|
|
5
5
|
import { lookupOf } from "../../core/lookup.js";
|
|
6
6
|
import { ListScopeProvider } from "../../react/scope.js";
|
|
7
7
|
import { useListing } from "../../react/useListing.js";
|
|
@@ -57,7 +57,7 @@ export function entityView(entity, options) {
|
|
|
57
57
|
// A chooser opened by a picker offers only what the picker may choose: its cut travels in
|
|
58
58
|
// the reference, and the list — the application's own too — reads under it.
|
|
59
59
|
const cut = record ? undefined : scopeOfRef(props.resource);
|
|
60
|
-
const list = cut === undefined ? (_jsx(List, { ...props })) : (_jsx(ListScopeProvider, { value: { key: entity.key,
|
|
60
|
+
const list = cut === undefined ? (_jsx(List, { ...props })) : (_jsx(ListScopeProvider, { value: { key: entity.key, selection: cut }, children: _jsx(List, { ...props }) }));
|
|
61
61
|
return _jsx(InWorkspace, { api: props.api, children: record ? _jsx(One, { ...props }) : list });
|
|
62
62
|
};
|
|
63
63
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type Entity } from "@sincpro/client-framework";
|
|
1
2
|
import type { AnyRecord, Meta } from "@sincpro/criteria";
|
|
2
3
|
import type { ResourceRef, WorkspaceApi } from "@sincpro/web-composer";
|
|
3
|
-
import type { Entity } from "../../core/entity.js";
|
|
4
4
|
import { type OpenTarget } from "@sincpro/web-ui";
|
|
5
5
|
import type { ReactNode } from "react";
|
|
6
6
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import {} from "@sincpro/client-framework";
|
|
3
4
|
import { useSummaryOf } from "../../react/useSummary.js";
|
|
4
5
|
import { openOptions, targetsFor } from "../list/openIn.js";
|
|
5
6
|
import { relationOf } from "../record/summary.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type Entity } from "@sincpro/client-framework";
|
|
1
2
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
2
3
|
import { type ViewProps } from "@sincpro/web-composer";
|
|
3
|
-
import { type Entity } from "../../core/entity.js";
|
|
4
4
|
import { type RecordReading } from "../../react/useRecord.js";
|
|
5
5
|
import { type ReactNode } from "react";
|
|
6
6
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { TRAIL_PARAM } from "@sincpro/client-framework";
|
|
3
4
|
import { labelOf, nameOf } from "@sincpro/criteria";
|
|
4
5
|
import { useCrumbs } from "@sincpro/web-composer";
|
|
5
6
|
import { frameworkCopy } from "../../core/copy.js";
|
|
6
|
-
import { TRAIL_PARAM } from "../../core/entity.js";
|
|
7
7
|
import { formOf } from "../../core/form.js";
|
|
8
8
|
import { placeOf, stepIn } from "../../core/trail.js";
|
|
9
9
|
import { useFramework } from "../../react/context.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type Entity } from "@sincpro/client-framework";
|
|
1
2
|
import { type AnyRecord } from "@sincpro/criteria";
|
|
2
3
|
import { type WorkspaceApi } from "@sincpro/web-composer";
|
|
3
|
-
import type { Entity } from "../../core/entity.js";
|
|
4
4
|
import type { RecordReading } from "../../react/useRecord.js";
|
|
5
5
|
/**
|
|
6
6
|
* A record told to the workspace it is open in: its real name and whether it holds unsaved work.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.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",
|
|
@@ -9,6 +9,18 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./core": {
|
|
14
|
+
"types": "./dist/core/index.d.ts",
|
|
15
|
+
"default": "./dist/core/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./telemetry": {
|
|
18
|
+
"types": "./dist/telemetry/index.d.ts",
|
|
19
|
+
"default": "./dist/telemetry/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./errors": {
|
|
22
|
+
"types": "./dist/errors/index.d.ts",
|
|
23
|
+
"default": "./dist/errors/index.js"
|
|
12
24
|
}
|
|
13
25
|
},
|
|
14
26
|
"publishConfig": {
|
|
@@ -23,19 +35,48 @@
|
|
|
23
35
|
"printWidth": 94
|
|
24
36
|
},
|
|
25
37
|
"peerDependencies": {
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
38
|
+
"@opentelemetry/api": "^1.10.0",
|
|
39
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.301.0",
|
|
40
|
+
"@opentelemetry/resources": "^3.1.0",
|
|
41
|
+
"@opentelemetry/sdk-trace": "^3.1.0",
|
|
42
|
+
"@sentry/browser": "^11.11.0",
|
|
43
|
+
"@sincpro/client-framework": "^0.4.0",
|
|
44
|
+
"@sincpro/criteria": "^2.0.0",
|
|
45
|
+
"@sincpro/criteria-react": "^2.0.0",
|
|
28
46
|
"@sincpro/web-composer": "^1.5.0",
|
|
29
|
-
"@sincpro/web-ui": "^
|
|
47
|
+
"@sincpro/web-ui": "^2.0.0",
|
|
30
48
|
"react": ">=19",
|
|
31
49
|
"react-dom": ">=19"
|
|
32
50
|
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"@opentelemetry/api": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"@opentelemetry/exporter-trace-otlp-http": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"@opentelemetry/resources": {
|
|
59
|
+
"optional": true
|
|
60
|
+
},
|
|
61
|
+
"@opentelemetry/sdk-trace": {
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
64
|
+
"@sentry/browser": {
|
|
65
|
+
"optional": true
|
|
66
|
+
}
|
|
67
|
+
},
|
|
33
68
|
"devDependencies": {
|
|
34
69
|
"@eslint/js": "^10.0.1",
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
70
|
+
"@opentelemetry/api": "1.10.0",
|
|
71
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.301.0",
|
|
72
|
+
"@opentelemetry/resources": "3.1.0",
|
|
73
|
+
"@opentelemetry/sdk-trace": "3.1.0",
|
|
74
|
+
"@sentry/browser": "11.11.0",
|
|
75
|
+
"@sincpro/client-framework": "^0.4.0",
|
|
76
|
+
"@sincpro/criteria": "^2.0.0",
|
|
77
|
+
"@sincpro/criteria-react": "^2.0.0",
|
|
37
78
|
"@sincpro/web-composer": "^1.5.0",
|
|
38
|
-
"@sincpro/web-ui": "^
|
|
79
|
+
"@sincpro/web-ui": "^2.0.0",
|
|
39
80
|
"@storybook/addon-a11y": "10.6.5",
|
|
40
81
|
"@storybook/addon-docs": "10.6.5",
|
|
41
82
|
"@storybook/addon-mcp": "10.6.5",
|
package/dist/core/discovery.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
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 {};
|
package/dist/core/discovery.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
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/entity.d.ts
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { type AnyRecord, type Expression } from "@sincpro/criteria";
|
|
2
|
-
import type { SummaryFields } from "./summary.js";
|
|
3
|
-
import type { Method } from "./transport.js";
|
|
4
|
-
/**
|
|
5
|
-
* Everything a screen needs to know about where an entity lives on the server, declared once.
|
|
6
|
-
*
|
|
7
|
-
* Context: a screen should not know a URL. It names the entity, and the entity says where its
|
|
8
|
-
* list is, where one record is, which Commands it takes, how it is saved and previewed, where a
|
|
9
|
-
* draft is kept and where its history is. `key` is how the workspace refers to it
|
|
10
|
-
* (`domain:kind`, the shape of a composer `ResourceRef`).
|
|
11
|
-
*
|
|
12
|
-
* The routes are declared, not guessed: sincpro_framework publishes a route per use case and
|
|
13
|
-
* its model definition does not list them (yet). A route is `"METHOD /path/{id}"` for a write.
|
|
14
|
-
*
|
|
15
|
-
* export const invoices = entity<Invoice>("billing:invoice", {
|
|
16
|
-
* list: "/invoices",
|
|
17
|
-
* create: "POST /invoices",
|
|
18
|
-
* save: "PUT /invoices/{id}",
|
|
19
|
-
* preview: "POST /invoices/preview",
|
|
20
|
-
* commands: { confirm: "POST /invoices/{id}/confirm", cancel: "POST /invoices/{id}/cancel" },
|
|
21
|
-
* history: { route: "/billing-events", type: "Invoice" },
|
|
22
|
-
* });
|
|
23
|
-
*/
|
|
24
|
-
export type Entity<T extends AnyRecord = AnyRecord> = {
|
|
25
|
-
/** `domain:kind`, e.g. `"billing:invoice"`. */
|
|
26
|
-
key: string;
|
|
27
|
-
domain: string;
|
|
28
|
-
kind: string;
|
|
29
|
-
/** Where the workspace finds it: the list without an id, one record with it — the shape of a
|
|
30
|
-
* composer `ResourceRef`, built here so no screen writes `{ domain, kind, id }` by hand. */
|
|
31
|
-
ref: (id?: string) => EntityRef;
|
|
32
|
-
/** A record that does not exist yet — the form that creates one. Its view is the record's.
|
|
33
|
-
* With `values`, the form starts with them over the model's defaults: an invoice created
|
|
34
|
-
* from its customer starts with that customer (`startingValuesOf`). */
|
|
35
|
-
newRef: (values?: AnyRecord) => EntityRef;
|
|
36
|
-
/** Its list opened to CHOOSE one: a row answers whoever asked (composer's `api.pick`). With
|
|
37
|
-
* `query`, the list opens on that literal search — what was typed in the picker; with
|
|
38
|
-
* `scope`, it offers only what the picker may choose (`scopeOfRef`). */
|
|
39
|
-
chooserRef: (query?: string, scope?: Expression) => EntityRef;
|
|
40
|
-
/** The route of its list. */
|
|
41
|
-
list: string;
|
|
42
|
-
/** The route of one record. */
|
|
43
|
-
one: (id: string) => string;
|
|
44
|
-
/** Its Commands, by name. */
|
|
45
|
-
commands: Readonly<Record<string, WriteRoute>>;
|
|
46
|
-
/** How a new record is created: the list's own route, usually. */
|
|
47
|
-
create?: WriteRoute;
|
|
48
|
-
/** How an edit is saved: the record's own route with `{id}`. */
|
|
49
|
-
save?: WriteRoute;
|
|
50
|
-
/** «What does this record become?» before saving — sincpro_framework's `Preview`. */
|
|
51
|
-
preview?: WriteRoute;
|
|
52
|
-
/** Where this caller keeps an edit between requests — sincpro_framework's `Drafts`. */
|
|
53
|
-
draft?: WriteRoute;
|
|
54
|
-
/** sincpro_framework's `Edit`: ONE route that keeps the draft, saves and discards, by its
|
|
55
|
-
* `action`. Declared, a save sends the record whole as the form holds it — not the fields
|
|
56
|
-
* that changed under `save` — and it is also where the draft is kept. */
|
|
57
|
-
edit?: WriteRoute;
|
|
58
|
-
/** Its business events: the context's events route, and the `entity_type` they carry. */
|
|
59
|
-
history?: {
|
|
60
|
-
route: string;
|
|
61
|
-
type: string;
|
|
62
|
-
};
|
|
63
|
-
/** Which fields are its description, state, picture… when they are not the conventional
|
|
64
|
-
* ones (`summaryOf`). Empty: the convention decides. */
|
|
65
|
-
summary: SummaryFields;
|
|
66
|
-
/** The aggregate it is, as a relation of another model names it (`relation: "Cliente"`).
|
|
67
|
-
* Without it, the `aggregate` of its model definition, once known. */
|
|
68
|
-
aggregate?: string;
|
|
69
|
-
/** Only carries the record type; never read. */
|
|
70
|
-
readonly _record?: T;
|
|
71
|
-
};
|
|
72
|
-
/** A composer `ResourceRef`, structurally: `core/` does not import the composer. */
|
|
73
|
-
export type EntityRef = {
|
|
74
|
-
domain: string;
|
|
75
|
-
kind: string;
|
|
76
|
-
id?: string;
|
|
77
|
-
params?: Readonly<Record<string, string>>;
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* The params that say what a reference without an id is for: `new` is the form of a record
|
|
81
|
-
* that does not exist yet, `pick` is the list opened to choose one. Params, because they are
|
|
82
|
-
* what a composer reference carries and survives a reload with.
|
|
83
|
-
*/
|
|
84
|
-
export declare const NEW_PARAM = "new";
|
|
85
|
-
export declare const PICK_PARAM = "pick";
|
|
86
|
-
/** What was typed where the chooser was asked for: its list opens on that search. */
|
|
87
|
-
export declare const QUERY_PARAM = "q";
|
|
88
|
-
/** The list a record was opened from (its `Trail`): «3 / 64» and the arrows to its neighbours. */
|
|
89
|
-
export declare const TRAIL_PARAM = "from";
|
|
90
|
-
/** What a new record starts with, as JSON: one param keeps each value's type (a number stays
|
|
91
|
-
* a number), where a param per field would turn all of them into text. */
|
|
92
|
-
export declare const WITH_PARAM = "with";
|
|
93
|
-
/** What a chooser may offer at all, as JSON: the picker's cut — its criteria, the keys it
|
|
94
|
-
* excludes, its named list's scope — that the list it opens ANDs under everything. */
|
|
95
|
-
export declare const SCOPE_PARAM = "scope";
|
|
96
|
-
/**
|
|
97
|
-
* What a new record's reference says it starts with (`newRef(values)`), or nothing.
|
|
98
|
-
*
|
|
99
|
-
* Context: a reference survives a reload and a link, so its params can be anything a person
|
|
100
|
-
* typed in the address bar — a value that is not a JSON object is not a start, never an error.
|
|
101
|
-
*/
|
|
102
|
-
export declare function startingValuesOf(ref: Pick<EntityRef, "params">): AnyRecord;
|
|
103
|
-
/**
|
|
104
|
-
* The cut a chooser's reference carries (`chooserRef(query, scope)`), or nothing.
|
|
105
|
-
*
|
|
106
|
-
* Context: a picker that may offer only some records — the contacts of the chosen customer, the
|
|
107
|
-
* tenants a project is not shared with yet — opened the workspace's chooser on the WHOLE
|
|
108
|
-
* entity, and offered the rest. The cut travels in the reference, so it survives a reload; read
|
|
109
|
-
* from an address bar it is untyped, so it is read the way criteria reads a filter from outside
|
|
110
|
-
* (`readExpression`), and one that does not read is no cut, never an error. It narrows what is
|
|
111
|
-
* OFFERED; the server still decides what may be stored.
|
|
112
|
-
*/
|
|
113
|
-
export declare function scopeOfRef(ref: Pick<EntityRef, "params">): Expression | undefined;
|
|
114
|
-
/** A write: its method and its path, `{id}` where the record's key goes. */
|
|
115
|
-
export type WriteRoute = {
|
|
116
|
-
method: Method;
|
|
117
|
-
path: string;
|
|
118
|
-
};
|
|
119
|
-
export type EntityRoutes = {
|
|
120
|
-
list: string;
|
|
121
|
-
/** With `{id}` where the key goes. Without it, `<list>/<id>` — sincpro_framework's convention. */
|
|
122
|
-
one?: string;
|
|
123
|
-
/** `"POST /invoices/{id}/confirm"`, by name. */
|
|
124
|
-
commands?: Readonly<Record<string, string>>;
|
|
125
|
-
/** `"POST /invoices"`: where a new record goes. */
|
|
126
|
-
create?: string;
|
|
127
|
-
save?: string;
|
|
128
|
-
preview?: string;
|
|
129
|
-
draft?: string;
|
|
130
|
-
/** `"PUT /invoices/{id}/edit"`: the use case that answers sincpro_framework's `Edit`. */
|
|
131
|
-
edit?: string;
|
|
132
|
-
history?: {
|
|
133
|
-
route: string;
|
|
134
|
-
type: string;
|
|
135
|
-
};
|
|
136
|
-
/** `{ image: "logo", state: "estado_pago", person: true }` — not a route, but declared once
|
|
137
|
-
* with the rest of what a screen should not have to know. */
|
|
138
|
-
summary?: SummaryFields;
|
|
139
|
-
/** `"Cliente"`: what a many2one of another model calls it, so a form resolves it alone. */
|
|
140
|
-
aggregate?: string;
|
|
141
|
-
};
|
|
142
|
-
/** `"POST /invoices/{id}/confirm"` → its method and path. A write without a method is a bug. */
|
|
143
|
-
export declare function writeRoute(text: string): WriteRoute;
|
|
144
|
-
/**
|
|
145
|
-
* The path with the record's key in place of `{id}`, and every other `{name}` taken from the
|
|
146
|
-
* body's field of that name: `POST /projects/{id}/shares/{tenant_id}/revoke` with
|
|
147
|
-
* `{ tenant_id: "acme" }`.
|
|
148
|
-
*
|
|
149
|
-
* Context: sincpro_framework reads a path parameter as a field of the use case's DTO (its
|
|
150
|
-
* wire merges `{...body, ...path_params}`), so the body already names every key a route
|
|
151
|
-
* needs — a second argument for them would say the same thing twice. A key the body lacks is
|
|
152
|
-
* the screen's bug, said before anything is sent. Without an `id`, `{id}` stays: a create or a
|
|
153
|
-
* preview of a new record has none.
|
|
154
|
-
*/
|
|
155
|
-
export declare function pathFor(route: WriteRoute, id?: string, body?: AnyRecord): string;
|
|
156
|
-
/** A list's route with its own parameters: `{ tenant_id: "acme" }` → `/projects?tenant_id=acme`.
|
|
157
|
-
* An empty value is no parameter — a filter left blank. */
|
|
158
|
-
export declare function listRoute(list: string, params?: Readonly<Record<string, string>>): string;
|
|
159
|
-
export declare function entity<T extends AnyRecord = AnyRecord>(key: string, routes: EntityRoutes): Entity<T>;
|