@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/rest.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { readProblem } from "@sincpro/criteria";
|
|
2
|
-
import { RestError, restSource } from "@sincpro/criteria/rest";
|
|
3
|
-
import { definitionOf, modelAt, } from "./discovery.js";
|
|
4
|
-
import { TransportError, } from "./transport.js";
|
|
5
|
-
/** The keys of an answer that are not the record: what is left is the record's own field. */
|
|
6
|
-
const ENVELOPE = new Set(["cursor", "count", "model_version", "dropped", "draft", "missing"]);
|
|
7
|
-
export function urlOf(base, route, criteria) {
|
|
8
|
-
const url = `${base}${route}`;
|
|
9
|
-
if (criteria === undefined)
|
|
10
|
-
return url;
|
|
11
|
-
const joiner = url.includes("?") ? "&" : "?";
|
|
12
|
-
return `${url}${joiner}criteria=${encodeURIComponent(JSON.stringify(criteria))}`;
|
|
13
|
-
}
|
|
14
|
-
/** The path a route is asked at, without its query: what a document path is matched with. */
|
|
15
|
-
function pathOf(url) {
|
|
16
|
-
const path = url.split("?")[0] ?? url;
|
|
17
|
-
return /^https?:\/\//.test(path) ? new URL(path).pathname : path;
|
|
18
|
-
}
|
|
19
|
-
/** Where the document is: `document` as given when absolute, else at the origin of `base`. */
|
|
20
|
-
function documentUrl(base, document) {
|
|
21
|
-
if (/^https?:\/\//.test(document) || !/^https?:\/\//.test(base))
|
|
22
|
-
return document;
|
|
23
|
-
return new URL(document, base).toString();
|
|
24
|
-
}
|
|
25
|
-
export function restTransport(options = {}) {
|
|
26
|
-
const base = options.base ?? "";
|
|
27
|
-
const doFetch = options.fetch ?? ((input, init) => fetch(input, init));
|
|
28
|
-
const own = () => typeof options.headers === "function" ? options.headers() : (options.headers ?? {});
|
|
29
|
-
// The discovery document, read once; asked again — with its ETag — when an answer says a
|
|
30
|
-
// version of its model the document did not.
|
|
31
|
-
const located = options.document === null ? null : (options.document ?? "/openapi.json");
|
|
32
|
-
let held;
|
|
33
|
-
let tag = null;
|
|
34
|
-
function documentRead(fresh) {
|
|
35
|
-
if (located === null)
|
|
36
|
-
return Promise.resolve(null);
|
|
37
|
-
if (held !== undefined && !fresh)
|
|
38
|
-
return held;
|
|
39
|
-
const before = held;
|
|
40
|
-
held = (async () => {
|
|
41
|
-
try {
|
|
42
|
-
const response = await doFetch(documentUrl(base, located), {
|
|
43
|
-
headers: { ...own(), ...(tag === null ? {} : { "If-None-Match": tag }) },
|
|
44
|
-
});
|
|
45
|
-
if (response.status === 304 && before !== undefined)
|
|
46
|
-
return await before;
|
|
47
|
-
if (!response.ok)
|
|
48
|
-
return null;
|
|
49
|
-
tag = response.headers.get("etag");
|
|
50
|
-
return (await response.json());
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
})();
|
|
56
|
-
return held;
|
|
57
|
-
}
|
|
58
|
-
/** The definition of the model `url` answers; read again when `version` is not the one held. */
|
|
59
|
-
async function definitionAt(url, method, version) {
|
|
60
|
-
const published = await documentRead(false);
|
|
61
|
-
if (published === null)
|
|
62
|
-
return null;
|
|
63
|
-
const name = modelAt(published, pathOf(url), method);
|
|
64
|
-
if (name === undefined)
|
|
65
|
-
return null;
|
|
66
|
-
const known = definitionOf(published, name);
|
|
67
|
-
if (known === undefined || !version || known.version === version)
|
|
68
|
-
return known?.meta ?? null;
|
|
69
|
-
const again = await documentRead(true);
|
|
70
|
-
return (again === null ? undefined : definitionOf(again, name))?.meta ?? known.meta;
|
|
71
|
-
}
|
|
72
|
-
async function get(route, url, signal, write) {
|
|
73
|
-
const headers = write
|
|
74
|
-
? {
|
|
75
|
-
...own(),
|
|
76
|
-
"Content-Type": "application/json",
|
|
77
|
-
...(write.key === undefined ? {} : { "Idempotency-Key": write.key }),
|
|
78
|
-
}
|
|
79
|
-
: own();
|
|
80
|
-
const response = await doFetch(url, {
|
|
81
|
-
headers,
|
|
82
|
-
...(write ? { method: write.method, body: JSON.stringify(write.body) } : {}),
|
|
83
|
-
...(signal ? { signal } : {}),
|
|
84
|
-
});
|
|
85
|
-
const text = await response.text();
|
|
86
|
-
if (!response.ok)
|
|
87
|
-
throw new TransportError(route, response.status, readProblem(text), undefined);
|
|
88
|
-
return text ? JSON.parse(text) : null;
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
async list(route, criteria, signal) {
|
|
92
|
-
const source = restSource(`${base}${route}`, { headers: own, fetch: doFetch });
|
|
93
|
-
try {
|
|
94
|
-
const page = await source.read(criteria, signal);
|
|
95
|
-
return {
|
|
96
|
-
...page,
|
|
97
|
-
meta: page.meta ?? (await definitionAt(`${base}${route}`, "get", page.version)),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
if (error instanceof RestError)
|
|
102
|
-
throw new TransportError(route, error.status, error.problem, undefined);
|
|
103
|
-
throw error;
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
async one(route, signal) {
|
|
107
|
-
const answer = (await get(route, urlOf(base, route), signal));
|
|
108
|
-
const own = Object.keys(answer).filter((key) => !ENVELOPE.has(key));
|
|
109
|
-
const [key] = own;
|
|
110
|
-
if (own.length !== 1 || key === undefined)
|
|
111
|
-
throw new TransportError(route, 200, null, `${route} answered ${own.length} fields of its own (${own.join(", ")}); a record answers one`);
|
|
112
|
-
return {
|
|
113
|
-
record: answer[key],
|
|
114
|
-
meta: await definitionAt(urlOf(base, route), "get", answer["model_version"]),
|
|
115
|
-
dropped: answer["dropped"] ?? [],
|
|
116
|
-
draft: answer["draft"] ?? null,
|
|
117
|
-
};
|
|
118
|
-
},
|
|
119
|
-
async send(method, route, body, signal, sending) {
|
|
120
|
-
return (await get(route, urlOf(base, route), signal, {
|
|
121
|
-
method,
|
|
122
|
-
body,
|
|
123
|
-
key: sending?.idempotencyKey,
|
|
124
|
-
}));
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
}
|
package/dist/core/retry.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `Idempotency-Key` of a gesture: one per thing a person meant to do, the SAME one while
|
|
3
|
-
* that thing is retried.
|
|
4
|
-
*
|
|
5
|
-
* Context: a Command that got no answer — the network dropped, a proxy answered 502 — may have
|
|
6
|
-
* run. Sending it again with a new key could pay twice; with the same key the server answers
|
|
7
|
-
* what it already did (sincpro_framework's `@idempotency`). So a key lives until the server
|
|
8
|
-
* gives a definite answer: done, or refused for a reason a retry does not change. Changing the
|
|
9
|
-
* body is a different gesture, and gets a new key — the server refuses a key that comes back
|
|
10
|
-
* with another payload.
|
|
11
|
-
*
|
|
12
|
-
* const keys = retryKeys();
|
|
13
|
-
* const key = keys.keyFor(body); // the same while the previous one went unanswered
|
|
14
|
-
* try { await send(…, { idempotencyKey: key }); keys.settle(null); }
|
|
15
|
-
* catch (error) { keys.settle(error); } // kept when nobody knows what happened
|
|
16
|
-
*/
|
|
17
|
-
export type RetryKeys = {
|
|
18
|
-
keyFor: (body: unknown) => string;
|
|
19
|
-
/** What the last attempt ended in: `null` when it was answered. */
|
|
20
|
-
settle: (error: unknown) => void;
|
|
21
|
-
};
|
|
22
|
-
/** Whether a failure leaves it unknown if the Command ran — so a retry must reuse its key. */
|
|
23
|
-
export declare function unanswered(error: unknown): boolean;
|
|
24
|
-
export declare function retryKeys(make?: () => string): RetryKeys;
|
package/dist/core/retry.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { TransportError } from "./transport.js";
|
|
2
|
-
/** Whether a failure leaves it unknown if the Command ran — so a retry must reuse its key. */
|
|
3
|
-
export function unanswered(error) {
|
|
4
|
-
if (!(error instanceof TransportError))
|
|
5
|
-
return true;
|
|
6
|
-
if (error.status === null || error.status >= 500)
|
|
7
|
-
return true;
|
|
8
|
-
// The same key is still running elsewhere: retry once it completes, with that key.
|
|
9
|
-
return error.problem?.kind === "in_progress";
|
|
10
|
-
}
|
|
11
|
-
export function retryKeys(make = () => globalThis.crypto.randomUUID()) {
|
|
12
|
-
let pending = null;
|
|
13
|
-
return {
|
|
14
|
-
keyFor: (body) => {
|
|
15
|
-
const sent = JSON.stringify(body ?? null);
|
|
16
|
-
if (pending === null || pending.body !== sent)
|
|
17
|
-
pending = { body: sent, key: make() };
|
|
18
|
-
return pending.key;
|
|
19
|
-
},
|
|
20
|
-
settle: (error) => {
|
|
21
|
-
if (error === null || !unanswered(error))
|
|
22
|
-
pending = null;
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
}
|
package/dist/core/schema.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Meta } from "@sincpro/criteria";
|
|
2
|
-
/**
|
|
3
|
-
* A model definition read from a JSON Schema — what an OpenAPI document holds.
|
|
4
|
-
*
|
|
5
|
-
* Context: a model a READ answers is published by sincpro_framework as its contract — JSON
|
|
6
|
-
* Schema with `x-sincpro` — and read by the transport (`metaFromContract`, `core/discovery`).
|
|
7
|
-
* What has no `x-sincpro` is a plain JSON Schema: a COMMAND's body, a value object it carries.
|
|
8
|
-
*
|
|
9
|
-
* So this reads such a component schema into a `Meta` — the form of a Command, a value object —
|
|
10
|
-
* and `completeMeta` fills, from it, what a definition left `unknown`.
|
|
11
|
-
*
|
|
12
|
-
* const spec = metaFromSchema("ProjectSpecification", doc.components.schemas);
|
|
13
|
-
* const fixed = completeMeta(project.fields.specification.definition, spec);
|
|
14
|
-
*/
|
|
15
|
-
export type JsonSchema = {
|
|
16
|
-
type?: string | string[];
|
|
17
|
-
format?: string;
|
|
18
|
-
enum?: readonly unknown[];
|
|
19
|
-
items?: JsonSchema;
|
|
20
|
-
$ref?: string;
|
|
21
|
-
anyOf?: readonly JsonSchema[];
|
|
22
|
-
oneOf?: readonly JsonSchema[];
|
|
23
|
-
properties?: Readonly<Record<string, JsonSchema>>;
|
|
24
|
-
required?: readonly string[];
|
|
25
|
-
title?: string;
|
|
26
|
-
description?: string;
|
|
27
|
-
default?: unknown;
|
|
28
|
-
};
|
|
29
|
-
export type SchemaComponents = Readonly<Record<string, JsonSchema>>;
|
|
30
|
-
/** The definition a component schema describes. `identity` empty: a value object has none. */
|
|
31
|
-
export declare function metaFromSchema(name: string, components: SchemaComponents, options?: {
|
|
32
|
-
identity?: string;
|
|
33
|
-
}): Meta;
|
|
34
|
-
/**
|
|
35
|
-
* The server's definition, with what it left `unknown` taken from the schema — recursively
|
|
36
|
-
* into value objects. What the server DID say always wins: its labels, its operators, its
|
|
37
|
-
* hints. A field the schema does not know is left as the server sent it.
|
|
38
|
-
*/
|
|
39
|
-
export declare function completeMeta(meta: Meta, schema: Meta): Meta;
|
package/dist/core/schema.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { field } from "./meta.js";
|
|
2
|
-
const UNKNOWN = {
|
|
3
|
-
type: "unknown",
|
|
4
|
-
kind: "scalar",
|
|
5
|
-
nullable: true,
|
|
6
|
-
sortable: false,
|
|
7
|
-
ops: [],
|
|
8
|
-
};
|
|
9
|
-
function nameOfRef(ref) {
|
|
10
|
-
return ref.slice(ref.lastIndexOf("/") + 1);
|
|
11
|
-
}
|
|
12
|
-
/** `anyOf: [X, {type: "null"}]` is `X`, nullable — how pydantic writes `X | None`. */
|
|
13
|
-
function unwrap(schema) {
|
|
14
|
-
const options = schema.anyOf ?? schema.oneOf;
|
|
15
|
-
if (options === undefined)
|
|
16
|
-
return { schema, nullable: false };
|
|
17
|
-
const real = options.filter((one) => one.type !== "null");
|
|
18
|
-
const [only] = real;
|
|
19
|
-
return real.length === 1 && only !== undefined
|
|
20
|
-
? { schema: { ...only, ...pick(schema) }, nullable: real.length < options.length }
|
|
21
|
-
: { schema, nullable: real.length < options.length };
|
|
22
|
-
}
|
|
23
|
-
/** The words of the outer schema win over the ones of what it wraps. */
|
|
24
|
-
function pick(schema) {
|
|
25
|
-
return {
|
|
26
|
-
...(schema.title === undefined ? {} : { title: schema.title }),
|
|
27
|
-
...(schema.description === undefined ? {} : { description: schema.description }),
|
|
28
|
-
...(schema.default === undefined ? {} : { default: schema.default }),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function fieldFrom(raw, required, components, seen) {
|
|
32
|
-
const { schema: unwrapped, nullable } = unwrap(raw);
|
|
33
|
-
const target = unwrapped.$ref !== undefined
|
|
34
|
-
? { ...components[nameOfRef(unwrapped.$ref)], ...pick(unwrapped) }
|
|
35
|
-
: unwrapped;
|
|
36
|
-
const options = {
|
|
37
|
-
...(target.title === undefined ? {} : { label: target.title }),
|
|
38
|
-
...(target.description === undefined ? {} : { help: target.description }),
|
|
39
|
-
...(target.default === undefined ? {} : { default: target.default }),
|
|
40
|
-
...(nullable ? { nullable } : {}),
|
|
41
|
-
required: required && target.default === undefined && !nullable,
|
|
42
|
-
};
|
|
43
|
-
if (unwrapped.$ref !== undefined) {
|
|
44
|
-
const name = nameOfRef(unwrapped.$ref);
|
|
45
|
-
if (components[name] === undefined || seen.has(name))
|
|
46
|
-
return UNKNOWN;
|
|
47
|
-
if (target.properties === undefined)
|
|
48
|
-
return target.enum ? field.choice(target.enum.map(String), options) : UNKNOWN;
|
|
49
|
-
return field.embedded(metaOf(name, target, components, new Set([...seen, name])), options);
|
|
50
|
-
}
|
|
51
|
-
if (target.enum)
|
|
52
|
-
return field.choice(target.enum.map(String), options);
|
|
53
|
-
const type = Array.isArray(target.type)
|
|
54
|
-
? target.type.find((t) => t !== "null")
|
|
55
|
-
: target.type;
|
|
56
|
-
switch (type) {
|
|
57
|
-
case "string":
|
|
58
|
-
if (target.format === "date")
|
|
59
|
-
return field.date(options);
|
|
60
|
-
if (target.format === "date-time")
|
|
61
|
-
return field.datetime(options);
|
|
62
|
-
return field.text(options);
|
|
63
|
-
case "integer":
|
|
64
|
-
return field.integer(options);
|
|
65
|
-
case "number":
|
|
66
|
-
return field.number(options);
|
|
67
|
-
case "boolean":
|
|
68
|
-
return field.boolean(options);
|
|
69
|
-
case "array": {
|
|
70
|
-
const item = target.items === undefined ? undefined : unwrap(target.items).schema;
|
|
71
|
-
if (item?.$ref !== undefined) {
|
|
72
|
-
const inner = fieldFrom(item, false, components, seen);
|
|
73
|
-
return inner.kind === "embedded" && inner.definition
|
|
74
|
-
? field.embedded(inner.definition, { ...options, many: true })
|
|
75
|
-
: field.tags(options);
|
|
76
|
-
}
|
|
77
|
-
return item?.type === "string" || item?.enum ? field.tags(options) : UNKNOWN;
|
|
78
|
-
}
|
|
79
|
-
default:
|
|
80
|
-
return UNKNOWN;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function metaOf(name, schema, components, seen) {
|
|
84
|
-
const required = new Set(schema.required ?? []);
|
|
85
|
-
const fields = Object.fromEntries(Object.entries(schema.properties ?? {}).map(([key, property]) => [
|
|
86
|
-
key,
|
|
87
|
-
fieldFrom(property, required.has(key), components, seen),
|
|
88
|
-
]));
|
|
89
|
-
return {
|
|
90
|
-
aggregate: name,
|
|
91
|
-
identity: "",
|
|
92
|
-
default_order: "",
|
|
93
|
-
fields,
|
|
94
|
-
...(schema.title === undefined ? {} : { name: { default: schema.title } }),
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
/** The definition a component schema describes. `identity` empty: a value object has none. */
|
|
98
|
-
export function metaFromSchema(name, components, options = {}) {
|
|
99
|
-
const schema = components[name];
|
|
100
|
-
if (schema === undefined)
|
|
101
|
-
throw new Error(`no schema named ${name}`);
|
|
102
|
-
const meta = metaOf(name, schema, components, new Set([name]));
|
|
103
|
-
return options.identity
|
|
104
|
-
? { ...meta, identity: options.identity, get_id: options.identity }
|
|
105
|
-
: meta;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* The server's definition, with what it left `unknown` taken from the schema — recursively
|
|
109
|
-
* into value objects. What the server DID say always wins: its labels, its operators, its
|
|
110
|
-
* hints. A field the schema does not know is left as the server sent it.
|
|
111
|
-
*/
|
|
112
|
-
export function completeMeta(meta, schema) {
|
|
113
|
-
const fields = Object.fromEntries(Object.entries(meta.fields).map(([name, own]) => {
|
|
114
|
-
const known = schema.fields[name];
|
|
115
|
-
if (known === undefined)
|
|
116
|
-
return [name, own];
|
|
117
|
-
if (own.type === "unknown")
|
|
118
|
-
return [name, { ...known, ...labelsOf(own) }];
|
|
119
|
-
if (own.kind === "embedded" && own.definition && known.definition)
|
|
120
|
-
return [name, { ...own, definition: completeMeta(own.definition, known.definition) }];
|
|
121
|
-
return [name, own];
|
|
122
|
-
}));
|
|
123
|
-
return { ...meta, fields };
|
|
124
|
-
}
|
|
125
|
-
/** A label the server declared is kept over the schema's generated title. */
|
|
126
|
-
function labelsOf(own) {
|
|
127
|
-
return own.label && Object.keys(own.label).length > 0 ? { label: own.label } : {};
|
|
128
|
-
}
|
package/dist/core/transport.d.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { Criteria, Dropped, Meta, Page, Problem } from "@sincpro/criteria";
|
|
2
|
-
/**
|
|
3
|
-
* The one seam between this package and a server.
|
|
4
|
-
*
|
|
5
|
-
* Context: a list and a record are the same two questions whatever the wire is — «a page of
|
|
6
|
-
* these, under this criteria» and «this one». REST today; JSON-RPC and gRPC are the other
|
|
7
|
-
* wires sincpro_framework serves. Each of those is
|
|
8
|
-
* one adapter implementing this, and nothing above it changes. A route is a string the adapter
|
|
9
|
-
* understands: a path for REST, a method for RPC.
|
|
10
|
-
*
|
|
11
|
-
* Every adapter throws `TransportError` for a refusal, so a screen explains a failure once
|
|
12
|
-
* whichever wire it came over.
|
|
13
|
-
*/
|
|
14
|
-
export interface Transport {
|
|
15
|
-
/** A page of records under the criteria. */
|
|
16
|
-
list<T>(route: string, criteria: Criteria<T>, signal?: AbortSignal): Promise<Page<T>>;
|
|
17
|
-
/** One record, with the definition of its model. */
|
|
18
|
-
one<T>(route: string, signal?: AbortSignal): Promise<One<T>>;
|
|
19
|
-
/** A Command — a write, an action, a preview: `method` and a JSON body, its answer back. */
|
|
20
|
-
send<T>(method: Method, route: string, body: unknown, signal?: AbortSignal, options?: SendOptions): Promise<T>;
|
|
21
|
-
}
|
|
22
|
-
export type Method = "POST" | "PUT" | "PATCH" | "DELETE";
|
|
23
|
-
/**
|
|
24
|
-
* How a Command travels besides its body.
|
|
25
|
-
*
|
|
26
|
-
* Context: sincpro_framework runs a Command declared `@idempotency` once per key (REST: the
|
|
27
|
-
* `Idempotency-Key` header; 400 `IDEMPOTENCY_KEY_MISSING` without it) and answers a repeat with
|
|
28
|
-
* the first answer. That is what makes «retry» safe after a request that got no answer: the
|
|
29
|
-
* server may have created the invoice, and the same key cannot create it twice.
|
|
30
|
-
*/
|
|
31
|
-
export type SendOptions = {
|
|
32
|
-
/** One per gesture, kept while it is retried — `retryKeys()`. */
|
|
33
|
-
idempotencyKey?: string;
|
|
34
|
-
};
|
|
35
|
-
/** One record as sincpro_framework answers it (`ResponseRecord`): the record, its model. */
|
|
36
|
-
export type One<T> = {
|
|
37
|
-
record: T;
|
|
38
|
-
meta: Meta | null;
|
|
39
|
-
dropped: Dropped[];
|
|
40
|
-
/** What this caller kept of an edit between requests (sincpro_framework `Drafts`). */
|
|
41
|
-
draft: Draft | null;
|
|
42
|
-
};
|
|
43
|
-
/** A kept edit: the values typed, the version of the draft, the record version it started on. */
|
|
44
|
-
/**
|
|
45
|
-
* The caller's draft of a record (sincpro_framework's `DraftState`): the version the next edit
|
|
46
|
-
* names, the stored version it started from, and whether the record moved on since (`stale`).
|
|
47
|
-
* `values` only when a server answers them apart from the record — sincpro_framework answers the
|
|
48
|
-
* record FROM the draft instead.
|
|
49
|
-
*/
|
|
50
|
-
export type Draft = {
|
|
51
|
-
values?: Record<string, unknown>;
|
|
52
|
-
version: number;
|
|
53
|
-
origin_version?: number;
|
|
54
|
-
kept_at?: string;
|
|
55
|
-
stale?: boolean;
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* A refusal, from any wire. `problem` is what the server said about it (RFC 9457 plus the
|
|
59
|
-
* engine's `kind`, `next_step`, `guidance`) or `null` when it said nothing readable — a proxy's
|
|
60
|
-
* HTML page. `status` is `null` when the request never got an answer.
|
|
61
|
-
*/
|
|
62
|
-
export declare class TransportError extends Error {
|
|
63
|
-
readonly route: string;
|
|
64
|
-
readonly status: number | null;
|
|
65
|
-
readonly problem: Problem | null;
|
|
66
|
-
constructor(route: string, status: number | null, problem: Problem | null, message?: string);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* What a person reads about a failure: a heading, and a sentence with what happened and what
|
|
70
|
-
* to do. The server's own words first; the copy table's when it sent none.
|
|
71
|
-
*
|
|
72
|
-
* explain(new TransportError("/x", 403, { kind: "permission_denied", guidance: "Pedí acceso.", … }))
|
|
73
|
-
* -> { heading: "No tenés acceso", sentence: "Pedí acceso.", retryable: false }
|
|
74
|
-
*/
|
|
75
|
-
export declare function explain(error: unknown): {
|
|
76
|
-
heading: string;
|
|
77
|
-
sentence: string;
|
|
78
|
-
retryable: boolean;
|
|
79
|
-
};
|
package/dist/core/zone.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The time zone a date and time is read and written in — and the two conversions a form needs:
|
|
3
|
-
* the server's instant to the wall clock of that zone, and back.
|
|
4
|
-
*
|
|
5
|
-
* Context: sincpro_framework sends a `datetime` as an instant (`2026-03-12T14:30:00Z`); a person
|
|
6
|
-
* reads and types the wall clock of where the business is (10:30 in La Paz). Which zone that is
|
|
7
|
-
* belongs to whoever is above the screens — the application, the company the user works in —
|
|
8
|
-
* so it is installed once, like the framework's words (`FrameworkProvider timeZone`), and every
|
|
9
|
-
* date and time follows it. Without it, the runtime's. A date with no time (`date`) is a day of
|
|
10
|
-
* the calendar, not an instant: it is never converted.
|
|
11
|
-
*/
|
|
12
|
-
/** Install the time zone dates and times are read and written in (IANA: `"America/La_Paz"`);
|
|
13
|
-
* `undefined` goes back to the runtime's. */
|
|
14
|
-
export declare function installTimeZone(timeZone: string | undefined): void;
|
|
15
|
-
/** The time zone in use. */
|
|
16
|
-
export declare function timeZoneNow(): string;
|
|
17
|
-
/** `"2026-03-12T14:30:00Z"` → `"2026-03-12T10:30"` in `America/La_Paz`: the wall clock there,
|
|
18
|
-
* as a date-and-time control reads it. `null` when it is not an instant. */
|
|
19
|
-
export declare function wallTimeOf(instant: string, timeZone: string): string | null;
|
|
20
|
-
/**
|
|
21
|
-
* `"2026-03-12T10:30"` on the wall clock of `timeZone` → the instant, `"2026-03-12T14:30:00.000Z"`.
|
|
22
|
-
* `null` when it is not a wall time.
|
|
23
|
-
*
|
|
24
|
-
* Context: the offset depends on the instant (daylight saving), so it is asked twice: at the
|
|
25
|
-
* first guess, and again at the answer when the guess fell on the other side of a change.
|
|
26
|
-
*/
|
|
27
|
-
export declare function instantOf(wall: string, timeZone: string): string | null;
|
package/dist/core/zone.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The time zone a date and time is read and written in — and the two conversions a form needs:
|
|
3
|
-
* the server's instant to the wall clock of that zone, and back.
|
|
4
|
-
*
|
|
5
|
-
* Context: sincpro_framework sends a `datetime` as an instant (`2026-03-12T14:30:00Z`); a person
|
|
6
|
-
* reads and types the wall clock of where the business is (10:30 in La Paz). Which zone that is
|
|
7
|
-
* belongs to whoever is above the screens — the application, the company the user works in —
|
|
8
|
-
* so it is installed once, like the framework's words (`FrameworkProvider timeZone`), and every
|
|
9
|
-
* date and time follows it. Without it, the runtime's. A date with no time (`date`) is a day of
|
|
10
|
-
* the calendar, not an instant: it is never converted.
|
|
11
|
-
*/
|
|
12
|
-
let installed;
|
|
13
|
-
/** Install the time zone dates and times are read and written in (IANA: `"America/La_Paz"`);
|
|
14
|
-
* `undefined` goes back to the runtime's. */
|
|
15
|
-
export function installTimeZone(timeZone) {
|
|
16
|
-
installed = timeZone;
|
|
17
|
-
}
|
|
18
|
-
/** The time zone in use. */
|
|
19
|
-
export function timeZoneNow() {
|
|
20
|
-
return installed ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
21
|
-
}
|
|
22
|
-
const clocks = new Map();
|
|
23
|
-
/** One formatter per zone, kept: building one costs far more than using it. */
|
|
24
|
-
function clockOf(timeZone) {
|
|
25
|
-
let clock = clocks.get(timeZone);
|
|
26
|
-
if (clock === undefined) {
|
|
27
|
-
clock = new Intl.DateTimeFormat("en-US", {
|
|
28
|
-
timeZone,
|
|
29
|
-
hourCycle: "h23",
|
|
30
|
-
year: "numeric",
|
|
31
|
-
month: "2-digit",
|
|
32
|
-
day: "2-digit",
|
|
33
|
-
hour: "2-digit",
|
|
34
|
-
minute: "2-digit",
|
|
35
|
-
second: "2-digit",
|
|
36
|
-
});
|
|
37
|
-
clocks.set(timeZone, clock);
|
|
38
|
-
}
|
|
39
|
-
return clock;
|
|
40
|
-
}
|
|
41
|
-
/** The wall clock of `timeZone` at `at` (ms), as the fields of a UTC date: what to compare. */
|
|
42
|
-
function wallAt(at, timeZone) {
|
|
43
|
-
const parts = Object.fromEntries(clockOf(timeZone)
|
|
44
|
-
.formatToParts(new Date(at))
|
|
45
|
-
.map((part) => [part.type, part.value]));
|
|
46
|
-
return Date.UTC(Number(parts["year"]), Number(parts["month"]) - 1, Number(parts["day"]), Number(parts["hour"]), Number(parts["minute"]), Number(parts["second"]));
|
|
47
|
-
}
|
|
48
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
49
|
-
/** `"2026-03-12T14:30:00Z"` → `"2026-03-12T10:30"` in `America/La_Paz`: the wall clock there,
|
|
50
|
-
* as a date-and-time control reads it. `null` when it is not an instant. */
|
|
51
|
-
export function wallTimeOf(instant, timeZone) {
|
|
52
|
-
const at = Date.parse(instant);
|
|
53
|
-
if (Number.isNaN(at))
|
|
54
|
-
return null;
|
|
55
|
-
const wall = new Date(wallAt(at, timeZone));
|
|
56
|
-
return (`${wall.getUTCFullYear()}-${pad(wall.getUTCMonth() + 1)}-${pad(wall.getUTCDate())}` +
|
|
57
|
-
`T${pad(wall.getUTCHours())}:${pad(wall.getUTCMinutes())}`);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* `"2026-03-12T10:30"` on the wall clock of `timeZone` → the instant, `"2026-03-12T14:30:00.000Z"`.
|
|
61
|
-
* `null` when it is not a wall time.
|
|
62
|
-
*
|
|
63
|
-
* Context: the offset depends on the instant (daylight saving), so it is asked twice: at the
|
|
64
|
-
* first guess, and again at the answer when the guess fell on the other side of a change.
|
|
65
|
-
*/
|
|
66
|
-
export function instantOf(wall, timeZone) {
|
|
67
|
-
const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(wall);
|
|
68
|
-
if (match === null)
|
|
69
|
-
return null;
|
|
70
|
-
const [, year, month, day, hour, minute] = match.map(Number);
|
|
71
|
-
const guess = Date.UTC(year, month - 1, day, hour, minute);
|
|
72
|
-
const first = guess - (wallAt(guess, timeZone) - guess);
|
|
73
|
-
const second = guess - (wallAt(first, timeZone) - first);
|
|
74
|
-
return new Date(second).toISOString();
|
|
75
|
-
}
|