@eskais/app-sdk 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +74 -2
- package/dist/action/action.d.ts +133 -0
- package/dist/action/action.js +224 -0
- package/dist/action/bulk.d.ts +24 -0
- package/dist/action/bulk.js +24 -0
- package/dist/cli/cli.d.ts +2 -0
- package/dist/cli/cli.js +51 -0
- package/dist/cli/routes.d.ts +17 -0
- package/dist/cli/routes.js +36 -0
- package/dist/core/assume.d.ts +1 -0
- package/dist/core/assume.js +8 -0
- package/dist/core/constants.d.ts +359 -0
- package/dist/core/constants.js +187 -0
- package/dist/core/contracts.d.ts +107 -0
- package/dist/core/contracts.js +3 -0
- package/dist/core/data-labels.d.ts +210 -0
- package/dist/core/data-labels.js +385 -0
- package/dist/core/errors.d.ts +52 -0
- package/dist/core/errors.js +209 -0
- package/dist/core/guards.d.ts +9 -0
- package/dist/core/guards.js +14 -0
- package/dist/core/refusal.d.ts +30 -0
- package/dist/core/refusal.js +53 -0
- package/dist/dialogs/dialogs.d.ts +75 -0
- package/dist/dialogs/dialogs.js +66 -0
- package/dist/draft/draft.d.ts +36 -0
- package/dist/draft/draft.js +87 -0
- package/dist/errors/adapters.d.ts +21 -0
- package/dist/errors/adapters.js +81 -0
- package/dist/errors/define-errors.d.ts +88 -0
- package/dist/errors/define-errors.js +168 -0
- package/dist/errors/idempotency.d.ts +2 -0
- package/dist/errors/idempotency.js +13 -0
- package/dist/export/csv.d.ts +25 -0
- package/dist/export/csv.js +59 -0
- package/dist/i18n/adapters.d.ts +53 -0
- package/dist/i18n/adapters.js +56 -0
- package/dist/i18n/format.d.ts +10 -0
- package/dist/i18n/format.js +273 -0
- package/dist/i18n/labels.d.ts +10 -0
- package/dist/i18n/labels.js +227 -0
- package/dist/i18n/locale.d.ts +73 -0
- package/dist/i18n/locale.js +74 -0
- package/dist/i18n/messages.d.ts +93 -0
- package/dist/i18n/messages.js +16 -0
- package/dist/import/csv-parse.d.ts +11 -0
- package/dist/import/csv-parse.js +70 -0
- package/dist/import/import.d.ts +104 -0
- package/dist/import/import.js +266 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +45 -0
- package/dist/navigation/nav.d.ts +128 -0
- package/dist/navigation/nav.js +301 -0
- package/dist/navigation/router.d.ts +81 -0
- package/dist/navigation/router.js +249 -0
- package/dist/navigation/shortcuts.d.ts +37 -0
- package/dist/navigation/shortcuts.js +93 -0
- package/dist/next/index.d.ts +3 -0
- package/dist/next/index.js +3 -0
- package/dist/next/screen-hydration.d.ts +12 -0
- package/dist/next/screen-hydration.js +26 -0
- package/dist/next/screen.d.ts +25 -0
- package/dist/next/screen.js +44 -0
- package/dist/next/server/handler.d.ts +39 -0
- package/dist/next/server/handler.js +190 -0
- package/dist/next/server/index.d.ts +6 -0
- package/dist/next/server/index.js +6 -0
- package/dist/next/server/page.d.ts +63 -0
- package/dist/next/server/page.js +110 -0
- package/dist/next/server/prefetch.d.ts +29 -0
- package/dist/next/server/prefetch.js +97 -0
- package/dist/next/server/session.d.ts +25 -0
- package/dist/next/server/session.js +23 -0
- package/dist/next/use-next-router.d.ts +21 -0
- package/dist/next/use-next-router.js +104 -0
- package/dist/permissions/permissions.d.ts +134 -0
- package/dist/permissions/permissions.js +121 -0
- package/dist/react/data-layer.d.ts +68 -0
- package/dist/react/data-layer.js +76 -0
- package/dist/react/hooks/use-action-dialog.d.ts +25 -0
- package/dist/react/hooks/use-action-dialog.js +31 -0
- package/dist/react/hooks/use-action.d.ts +37 -0
- package/dist/react/hooks/use-action.js +125 -0
- package/dist/react/hooks/use-better-auth.d.ts +12 -0
- package/dist/react/hooks/use-better-auth.js +11 -0
- package/dist/react/hooks/use-bulk-action.d.ts +20 -0
- package/dist/react/hooks/use-bulk-action.js +24 -0
- package/dist/react/hooks/use-dialogs.d.ts +14 -0
- package/dist/react/hooks/use-dialogs.js +20 -0
- package/dist/react/hooks/use-draft.d.ts +5 -0
- package/dist/react/hooks/use-draft.js +17 -0
- package/dist/react/hooks/use-nav.d.ts +17 -0
- package/dist/react/hooks/use-nav.js +35 -0
- package/dist/react/hooks/use-new-rows.d.ts +22 -0
- package/dist/react/hooks/use-new-rows.js +24 -0
- package/dist/react/hooks/use-permissions.d.ts +13 -0
- package/dist/react/hooks/use-permissions.js +19 -0
- package/dist/react/hooks/use-reauthenticate.d.ts +6 -0
- package/dist/react/hooks/use-reauthenticate.js +11 -0
- package/dist/react/hooks/use-resource.d.ts +92 -0
- package/dist/react/hooks/use-resource.js +255 -0
- package/dist/react/hooks/use-view.d.ts +6 -0
- package/dist/react/hooks/use-view.js +24 -0
- package/dist/react/index.d.ts +15 -0
- package/dist/react/index.js +15 -0
- package/dist/react/keys.d.ts +60 -0
- package/dist/react/keys.js +71 -0
- package/dist/react/new-rows.d.ts +22 -0
- package/dist/react/new-rows.js +72 -0
- package/dist/refresh/new-rows.d.ts +13 -0
- package/dist/refresh/new-rows.js +18 -0
- package/dist/resource/form-schema.d.ts +11 -0
- package/dist/resource/form-schema.js +51 -0
- package/dist/resource/relations.d.ts +99 -0
- package/dist/resource/relations.js +194 -0
- package/dist/resource/resource-relations.d.ts +47 -0
- package/dist/resource/resource-relations.js +154 -0
- package/dist/resource/resource-schema.d.ts +9 -0
- package/dist/resource/resource-schema.js +73 -0
- package/dist/resource/resource-texts.d.ts +18 -0
- package/dist/resource/resource-texts.js +13 -0
- package/dist/resource/resource-types.d.ts +420 -0
- package/dist/resource/resource-types.js +1 -0
- package/dist/resource/resource-words.d.ts +25 -0
- package/dist/resource/resource-words.js +221 -0
- package/dist/resource/resource.d.ts +15 -0
- package/dist/resource/resource.js +280 -0
- package/dist/resource/schema.d.ts +57 -0
- package/dist/resource/schema.js +115 -0
- package/dist/services/from-page-source.d.ts +15 -0
- package/dist/services/from-page-source.js +27 -0
- package/dist/services/memory-query.d.ts +8 -0
- package/dist/services/memory-query.js +165 -0
- package/dist/services/memory-service.d.ts +33 -0
- package/dist/services/memory-service.js +291 -0
- package/dist/services/read-only-service.d.ts +18 -0
- package/dist/services/read-only-service.js +25 -0
- package/dist/services/rest-service.d.ts +65 -0
- package/dist/services/rest-service.js +222 -0
- package/dist/services/rng.d.ts +9 -0
- package/dist/services/rng.js +22 -0
- package/dist/services/spring-service.d.ts +58 -0
- package/dist/services/spring-service.js +132 -0
- package/dist/session/better-auth.d.ts +83 -0
- package/dist/session/better-auth.js +86 -0
- package/dist/session/session.d.ts +45 -0
- package/dist/session/session.js +36 -0
- package/dist/view/preferences.d.ts +35 -0
- package/dist/view/preferences.js +93 -0
- package/dist/view/view-types.d.ts +124 -0
- package/dist/view/view-types.js +1 -0
- package/dist/view/view-url.d.ts +7 -0
- package/dist/view/view-url.js +54 -0
- package/dist/view/view.d.ts +4 -0
- package/dist/view/view.js +392 -0
- package/locales/en.json +193 -0
- package/locales/es.json +193 -0
- package/package.json +88 -4
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { RelationDenied, RelationKind, RowsMode } from "../core/constants.js";
|
|
2
|
+
import type { CallContext } from "../core/contracts.js";
|
|
3
|
+
import type { AnyResource, Resource } from "./resource-types.js";
|
|
4
|
+
import type { InferOutput, StandardSchema } from "./schema.js";
|
|
5
|
+
export type BelongsTo<Row = unknown> = {
|
|
6
|
+
readonly kind: typeof RelationKind.belongsTo;
|
|
7
|
+
/** Never set: carries the related row's type to `RelationRows`. */
|
|
8
|
+
readonly rowType?: Row;
|
|
9
|
+
readonly target: () => AnyResource;
|
|
10
|
+
/** The record's field with the related id, like `customerId`. */
|
|
11
|
+
readonly key: string;
|
|
12
|
+
/** Fields the record keeps a copy of under the relation's name (`customer: { name }`): shown without a fetch. */
|
|
13
|
+
readonly snapshot?: readonly string[];
|
|
14
|
+
/** Offers to create the missing record from the form's combobox. Default true. */
|
|
15
|
+
readonly create?: boolean;
|
|
16
|
+
/** When the session can't read the related resource: show the id (default) or hide the column. */
|
|
17
|
+
readonly denied?: RelationDenied;
|
|
18
|
+
};
|
|
19
|
+
export type HasMany = {
|
|
20
|
+
readonly kind: typeof RelationKind.hasMany;
|
|
21
|
+
readonly target: () => AnyResource;
|
|
22
|
+
/** The related records' field with this record's id, like `orderId`. */
|
|
23
|
+
readonly foreignKey: string;
|
|
24
|
+
/** `RowsMode.tab` (default): a tab with its own table and path; `RowsMode.inline`: rows edited in the form. */
|
|
25
|
+
readonly mode?: RowsMode;
|
|
26
|
+
/** The tab's label; the related resource's by default. */
|
|
27
|
+
readonly label?: string;
|
|
28
|
+
};
|
|
29
|
+
export type ManyToMany<Row = unknown> = {
|
|
30
|
+
readonly kind: typeof RelationKind.manyToMany;
|
|
31
|
+
/** Never set: carries the related row's type to `RelationRows`. */
|
|
32
|
+
readonly rowType?: Row;
|
|
33
|
+
readonly target: () => AnyResource;
|
|
34
|
+
/** The record's field with the related ids, like `tagIds`. */
|
|
35
|
+
readonly key: string;
|
|
36
|
+
readonly denied?: RelationDenied;
|
|
37
|
+
};
|
|
38
|
+
export type Embeds<Output = unknown> = {
|
|
39
|
+
readonly kind: typeof RelationKind.embeds;
|
|
40
|
+
/** A subdocument's schema, or a list of them (`z.array(line)`), stored inside the record. */
|
|
41
|
+
readonly schema: StandardSchema<unknown, Output>;
|
|
42
|
+
};
|
|
43
|
+
export type Relation = BelongsTo<any> | HasMany | ManyToMany<any> | Embeds<any>;
|
|
44
|
+
export type Relations = Readonly<Record<string, Relation>>;
|
|
45
|
+
/** What each relation adds to a row once resolved: the related record, its list, or the subdocument. */
|
|
46
|
+
export type RelationRows<R> = string extends keyof R ? unknown : RelationRowsOf<R>;
|
|
47
|
+
type RelationRowsOf<R> = {
|
|
48
|
+
[Name in keyof R]?: R[Name] extends BelongsTo<infer Row> ? Row : R[Name] extends ManyToMany<infer Row> ? readonly Row[] : R[Name] extends Embeds<infer Output> ? Output : readonly unknown[];
|
|
49
|
+
};
|
|
50
|
+
type TargetOf<Row> = () => Resource<Row, any, any>;
|
|
51
|
+
/** This record points at one other: `customer: belongsTo(() => customers, { key: "customerId" })`. */
|
|
52
|
+
export declare function belongsTo<Row>(target: TargetOf<Row>, options: Omit<BelongsTo<Row>, "kind" | "target">): BelongsTo<Row>;
|
|
53
|
+
/** Lets relations name a resource by its `key`; `defineResource` registers each one it makes. */
|
|
54
|
+
export declare function registerResource(resource: AnyResource): void;
|
|
55
|
+
/**
|
|
56
|
+
* Other records point at this one: `lines: hasMany(() => orderLines, { foreignKey: "orderId" })`. When the two
|
|
57
|
+
* resources point at each other (customers have orders, an order has a customer), name it by its key,
|
|
58
|
+
* `hasMany("orders", …)`: TypeScript can't infer two resources' types from each other.
|
|
59
|
+
*/
|
|
60
|
+
export declare function hasMany(target: (() => AnyResource) | string, options: Omit<HasMany, "kind" | "target">): HasMany;
|
|
61
|
+
/** This record keeps a list of ids of others: `tags: manyToMany(() => tags, { key: "tagIds" })`. */
|
|
62
|
+
export declare function manyToMany<Row>(target: TargetOf<Row>, options: Omit<ManyToMany<Row>, "kind" | "target">): ManyToMany<Row>;
|
|
63
|
+
/** A subdocument, or a list of them, stored inside the record: `address: embeds(addressSchema)`. */
|
|
64
|
+
export declare function embeds<Schema extends StandardSchema>(schema: Schema): Embeds<InferOutput<Schema>>;
|
|
65
|
+
/** The relations a set of paths reaches (`customer.name` reaches `customer`), for `Query.include`. */
|
|
66
|
+
export declare function includeOf(relations: Relations, paths: readonly string[]): string[];
|
|
67
|
+
/** The `belongsTo` or `manyToMany` whose id field is `key` (`customerId` is `customer`'s). */
|
|
68
|
+
export declare function keyRelation(relations: Relations, key: string): [string, BelongsTo | ManyToMany] | undefined;
|
|
69
|
+
/** Splits `ids` into lists of at most `size`: Firestore's `in` takes 30, DynamoDB's BatchGetItem 100. */
|
|
70
|
+
export declare function chunkIds<Id>(ids: readonly Id[], size: number | undefined): Id[][];
|
|
71
|
+
export type RelationContext = CallContext & {
|
|
72
|
+
/** A record already at hand (a cache), by resource and id; it isn't fetched again. */
|
|
73
|
+
known?: (resource: AnyResource, id: string) => unknown;
|
|
74
|
+
/** Every record fetched, to seed a detail cache. */
|
|
75
|
+
seed?: (resource: AnyResource, record: unknown) => void;
|
|
76
|
+
/** Told once per resource that has no `getMany` and was read one id at a time. */
|
|
77
|
+
warn?: (message: string) => void;
|
|
78
|
+
/** Whether the session may read a related resource; a refused one is never fetched. */
|
|
79
|
+
canRead?: (resource: AnyResource) => boolean;
|
|
80
|
+
/** The service to read a related resource through: on a server, the one that answers there, not its HTTP client. */
|
|
81
|
+
serviceOf?: (resource: AnyResource) => AnyResource["service"];
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Adds related records to rows, never one request per row: what the server embedded (or a `snapshot` that has every
|
|
85
|
+
* field asked) stays; the rest is read with one `getMany` per relation, in chunks of the service's `batchSize`, or
|
|
86
|
+
* one `get` per distinct id when there's no `getMany`. Paths reach through relations (`customer.country.name`).
|
|
87
|
+
*/
|
|
88
|
+
export declare function resolveRelations<T>(resource: {
|
|
89
|
+
readonly relations: Relations;
|
|
90
|
+
}, rows: readonly T[], paths: readonly string[], context: RelationContext): Promise<T[]>;
|
|
91
|
+
/** A resource's records that `hasMany` rows belong to, saved with it: created, changed and removed by id. */
|
|
92
|
+
export type ChildChanges = {
|
|
93
|
+
create: Record<string, unknown>[];
|
|
94
|
+
update: Record<string, unknown>[];
|
|
95
|
+
remove: unknown[];
|
|
96
|
+
};
|
|
97
|
+
/** What to send so the stored children become `rows`: new ones (no id), changed ones, and the ids left out. */
|
|
98
|
+
export declare function childChanges(rows: readonly Record<string, unknown>[], previous: readonly Record<string, unknown>[], idOf: (row: Record<string, unknown>) => unknown): ChildChanges;
|
|
99
|
+
export {};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { RelationDenied, RelationKind, RowsMode } from "../core/constants.js";
|
|
2
|
+
import { isNumber, isRecord, isString } from "../core/guards.js";
|
|
3
|
+
import { valueAt } from "../services/memory-query.js";
|
|
4
|
+
import { assumeType } from "../core/assume.js";
|
|
5
|
+
/** This record points at one other: `customer: belongsTo(() => customers, { key: "customerId" })`. */
|
|
6
|
+
export function belongsTo(target, options) {
|
|
7
|
+
return { kind: RelationKind.belongsTo, target, ...options };
|
|
8
|
+
}
|
|
9
|
+
const byKey = new Map();
|
|
10
|
+
/** Lets relations name a resource by its `key`; `defineResource` registers each one it makes. */
|
|
11
|
+
export function registerResource(resource) {
|
|
12
|
+
byKey.set(resource.key, resource);
|
|
13
|
+
}
|
|
14
|
+
function resourceNamed(key) {
|
|
15
|
+
const found = byKey.get(key);
|
|
16
|
+
if (!found)
|
|
17
|
+
throw new Error(`No resource with the key "${key}" has been defined.`);
|
|
18
|
+
return found;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Other records point at this one: `lines: hasMany(() => orderLines, { foreignKey: "orderId" })`. When the two
|
|
22
|
+
* resources point at each other (customers have orders, an order has a customer), name it by its key,
|
|
23
|
+
* `hasMany("orders", …)`: TypeScript can't infer two resources' types from each other.
|
|
24
|
+
*/
|
|
25
|
+
export function hasMany(target, options) {
|
|
26
|
+
const thunk = isString(target) ? () => resourceNamed(target) : target;
|
|
27
|
+
return { kind: RelationKind.hasMany, target: thunk, ...options };
|
|
28
|
+
}
|
|
29
|
+
/** This record keeps a list of ids of others: `tags: manyToMany(() => tags, { key: "tagIds" })`. */
|
|
30
|
+
export function manyToMany(target, options) {
|
|
31
|
+
return { kind: RelationKind.manyToMany, target, ...options };
|
|
32
|
+
}
|
|
33
|
+
/** A subdocument, or a list of them, stored inside the record: `address: embeds(addressSchema)`. */
|
|
34
|
+
export function embeds(schema) {
|
|
35
|
+
// Workaround: `InferOutput` reads the output type back from the same schema the relation keeps.
|
|
36
|
+
return assumeType({ kind: RelationKind.embeds, schema });
|
|
37
|
+
}
|
|
38
|
+
/** The relations a set of paths reaches (`customer.name` reaches `customer`), for `Query.include`. */
|
|
39
|
+
export function includeOf(relations, paths) {
|
|
40
|
+
const found = new Set();
|
|
41
|
+
for (const path of paths) {
|
|
42
|
+
const [head = ""] = path.split(".");
|
|
43
|
+
const relation = relations[head] ?? keyRelation(relations, head)?.[1];
|
|
44
|
+
const name = relations[head] ? head : keyRelation(relations, head)?.[0];
|
|
45
|
+
if (relation && name !== undefined && relation.kind !== RelationKind.embeds)
|
|
46
|
+
found.add(name);
|
|
47
|
+
}
|
|
48
|
+
return [...found];
|
|
49
|
+
}
|
|
50
|
+
/** The `belongsTo` or `manyToMany` whose id field is `key` (`customerId` is `customer`'s). */
|
|
51
|
+
export function keyRelation(relations, key) {
|
|
52
|
+
for (const [name, relation] of Object.entries(relations)) {
|
|
53
|
+
if ((relation.kind === RelationKind.belongsTo || relation.kind === RelationKind.manyToMany) && relation.key === key)
|
|
54
|
+
return [name, relation];
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
/** Splits `ids` into lists of at most `size`: Firestore's `in` takes 30, DynamoDB's BatchGetItem 100. */
|
|
59
|
+
export function chunkIds(ids, size) {
|
|
60
|
+
const step = size === undefined || size <= 0 ? Math.max(1, ids.length) : size;
|
|
61
|
+
const chunks = [];
|
|
62
|
+
for (let start = 0; start < ids.length; start += step)
|
|
63
|
+
chunks.push(ids.slice(start, start + step));
|
|
64
|
+
return chunks;
|
|
65
|
+
}
|
|
66
|
+
const isId = (value) => isString(value) || isNumber(value);
|
|
67
|
+
function needsOf(relations, paths) {
|
|
68
|
+
const needs = new Map();
|
|
69
|
+
for (const path of paths) {
|
|
70
|
+
const [head = "", ...rest] = path.split(".");
|
|
71
|
+
const name = relations[head] ? head : keyRelation(relations, head)?.[0];
|
|
72
|
+
if (name === undefined)
|
|
73
|
+
continue;
|
|
74
|
+
const relation = relations[name];
|
|
75
|
+
if (!relation || relation.kind === RelationKind.embeds || relation.kind === RelationKind.hasMany)
|
|
76
|
+
continue;
|
|
77
|
+
const fields = needs.get(name) ?? new Set();
|
|
78
|
+
if (rest.length > 0)
|
|
79
|
+
fields.add(rest.join("."));
|
|
80
|
+
needs.set(name, fields);
|
|
81
|
+
}
|
|
82
|
+
return needs;
|
|
83
|
+
}
|
|
84
|
+
async function fetchAll(target, ids, context) {
|
|
85
|
+
const found = new Map();
|
|
86
|
+
const missing = [];
|
|
87
|
+
for (const id of ids) {
|
|
88
|
+
const known = context.known?.(target, id);
|
|
89
|
+
if (known === undefined)
|
|
90
|
+
missing.push(id);
|
|
91
|
+
else
|
|
92
|
+
found.set(id, known);
|
|
93
|
+
}
|
|
94
|
+
if (missing.length === 0)
|
|
95
|
+
return found;
|
|
96
|
+
const parsed = missing.map((id) => target.parseId(id));
|
|
97
|
+
const call = { signal: context.signal, session: context.session };
|
|
98
|
+
let records;
|
|
99
|
+
const service = context.serviceOf?.(target) ?? target.service;
|
|
100
|
+
const getMany = service.getMany;
|
|
101
|
+
if (getMany) {
|
|
102
|
+
// Perf: one request per chunk of ids, never one per row.
|
|
103
|
+
const chunks = chunkIds(parsed, service.capabilities.batchSize);
|
|
104
|
+
const pages = await Promise.all(chunks.map((chunk) => getMany.call(service, chunk, call)));
|
|
105
|
+
records = pages.flat();
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
context.warn?.(`"${target.key}" has no getMany, so ${String(missing.length)} records were read one by one; add getMany to read them in one request.`);
|
|
109
|
+
records = await Promise.all(parsed.map((id) => service.get(id, call)));
|
|
110
|
+
}
|
|
111
|
+
for (const record of records) {
|
|
112
|
+
const id = target.idKey(target.idOf(record));
|
|
113
|
+
found.set(id, record);
|
|
114
|
+
context.seed?.(target, record);
|
|
115
|
+
}
|
|
116
|
+
return found;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Adds related records to rows, never one request per row: what the server embedded (or a `snapshot` that has every
|
|
120
|
+
* field asked) stays; the rest is read with one `getMany` per relation, in chunks of the service's `batchSize`, or
|
|
121
|
+
* one `get` per distinct id when there's no `getMany`. Paths reach through relations (`customer.country.name`).
|
|
122
|
+
*/
|
|
123
|
+
export async function resolveRelations(resource, rows, paths, context) {
|
|
124
|
+
const needs = needsOf(resource.relations, paths);
|
|
125
|
+
let result = [...rows];
|
|
126
|
+
for (const [name, fields] of needs) {
|
|
127
|
+
const relation = resource.relations[name];
|
|
128
|
+
if (!relation || (relation.kind !== RelationKind.belongsTo && relation.kind !== RelationKind.manyToMany))
|
|
129
|
+
continue;
|
|
130
|
+
const target = relation.target();
|
|
131
|
+
if (context.canRead?.(target) === false)
|
|
132
|
+
continue;
|
|
133
|
+
const snapshot = relation.kind === RelationKind.belongsTo ? relation.snapshot : undefined;
|
|
134
|
+
const covered = (row) => {
|
|
135
|
+
const present = valueAt(row, name);
|
|
136
|
+
if (present === undefined || present === null)
|
|
137
|
+
return false;
|
|
138
|
+
if (snapshot === undefined)
|
|
139
|
+
return true;
|
|
140
|
+
return [...fields].every((field) => snapshot.includes(field.split(".")[0] ?? field));
|
|
141
|
+
};
|
|
142
|
+
const idsOfRow = (row) => {
|
|
143
|
+
const raw = valueAt(row, relation.key);
|
|
144
|
+
const list = Array.isArray(raw) ? raw : [raw];
|
|
145
|
+
return list.filter(isId).map(String);
|
|
146
|
+
};
|
|
147
|
+
const wanted = [...new Set(result.filter((row) => !covered(row)).flatMap(idsOfRow))];
|
|
148
|
+
// oxlint-disable-next-line no-await-in-loop -- each relation's batch is one request; relations go one after another
|
|
149
|
+
const records = wanted.length === 0 ? new Map() : await fetchAll(target, wanted, context);
|
|
150
|
+
const nested = [...fields].filter((field) => field.includes("."));
|
|
151
|
+
if (nested.length > 0 && records.size > 0) {
|
|
152
|
+
const values = [...records.values()];
|
|
153
|
+
// oxlint-disable-next-line no-await-in-loop -- a nested relation needs the records this one just read
|
|
154
|
+
const deeper = await resolveRelations(target, values, nested, context);
|
|
155
|
+
for (const record of deeper)
|
|
156
|
+
records.set(target.idKey(target.idOf(record)), record);
|
|
157
|
+
}
|
|
158
|
+
result = result.map((row) => {
|
|
159
|
+
if (covered(row) && nested.length === 0)
|
|
160
|
+
return row;
|
|
161
|
+
const ids = idsOfRow(row);
|
|
162
|
+
if (ids.length === 0)
|
|
163
|
+
return row;
|
|
164
|
+
const present = valueAt(row, name);
|
|
165
|
+
const fetched = records.get(ids[0] ?? "");
|
|
166
|
+
const value = relation.kind === RelationKind.manyToMany
|
|
167
|
+
? ids.flatMap((id) => (records.has(id) ? [records.get(id)] : []))
|
|
168
|
+
: { ...(isRecord(present) ? present : {}), ...(isRecord(fetched) ? fetched : {}) };
|
|
169
|
+
// Workaround: the row gains its relation under its name, as `RelationRows` types it.
|
|
170
|
+
return assumeType({ ...(isRecord(row) ? row : {}), [name]: value });
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
/** What to send so the stored children become `rows`: new ones (no id), changed ones, and the ids left out. */
|
|
176
|
+
export function childChanges(rows, previous, idOf) {
|
|
177
|
+
const before = new Map(previous.map((row) => [String(idOf(row)), row]));
|
|
178
|
+
const kept = new Set();
|
|
179
|
+
const create = [];
|
|
180
|
+
const update = [];
|
|
181
|
+
for (const row of rows) {
|
|
182
|
+
const id = idOf(row);
|
|
183
|
+
if (id === undefined || id === null || id === "") {
|
|
184
|
+
create.push(row);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
kept.add(String(id));
|
|
188
|
+
const old = before.get(String(id));
|
|
189
|
+
if (!old || JSON.stringify(old) !== JSON.stringify({ ...old, ...row }))
|
|
190
|
+
update.push(row);
|
|
191
|
+
}
|
|
192
|
+
const remove = previous.filter((row) => !kept.has(String(idOf(row)))).map(idOf);
|
|
193
|
+
return { create, update, remove };
|
|
194
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Relation, type Relations } from "./relations.js";
|
|
2
|
+
import type { FieldDef, FieldGroup, ResolvedField } from "./resource-types.js";
|
|
3
|
+
import { type Introspect, type SchemaProperty } from "./schema.js";
|
|
4
|
+
import type { AnyResource, ResolvedRelation } from "./resource-types.js";
|
|
5
|
+
import { type ResourceTexts } from "./resource-texts.js";
|
|
6
|
+
import type { Text } from "../i18n/locale.js";
|
|
7
|
+
export declare const defined: Set<AnyResource>;
|
|
8
|
+
/**
|
|
9
|
+
* The resources whose rows show `resource`'s records through a `belongsTo` or `manyToMany`, with the relation's
|
|
10
|
+
* name: changing one of its records refreshes their lists.
|
|
11
|
+
*/
|
|
12
|
+
export declare function dependentsOf(resource: {
|
|
13
|
+
key: string;
|
|
14
|
+
}): {
|
|
15
|
+
resource: AnyResource;
|
|
16
|
+
relation: string;
|
|
17
|
+
}[];
|
|
18
|
+
export declare function relationOf(name: string, relation: Relation): ResolvedRelation | undefined;
|
|
19
|
+
type RelationToolsContext = {
|
|
20
|
+
relations: Relations;
|
|
21
|
+
properties: () => readonly SchemaProperty[];
|
|
22
|
+
introspect: Introspect | undefined;
|
|
23
|
+
texts: ResourceTexts;
|
|
24
|
+
};
|
|
25
|
+
export declare function relationTools<T>({ relations, properties, introspect, texts }: RelationToolsContext): {
|
|
26
|
+
relationAt: (key: string) => {
|
|
27
|
+
relation: ResolvedRelation;
|
|
28
|
+
rest?: string;
|
|
29
|
+
} | undefined;
|
|
30
|
+
relationField: (field: FieldDef<T>, group?: FieldGroup<T>) => ResolvedField<T> | undefined;
|
|
31
|
+
};
|
|
32
|
+
/** What a column through a relation (`product.price`) takes from the related field: its kind, tones, alignment, labels. */
|
|
33
|
+
export declare function inheritedColumn(related: AnyResource | undefined, rest: string | undefined): {
|
|
34
|
+
tones: Partial<Record<string, string>> | undefined;
|
|
35
|
+
align: import("../index.js").Align | undefined;
|
|
36
|
+
options: import("./resource-types.js").Option[] | undefined;
|
|
37
|
+
kind: (toned: boolean) => import("../index.js").ColumnKind | undefined;
|
|
38
|
+
};
|
|
39
|
+
/** The labels of a key's values, from its field or its column, whichever declares them. */
|
|
40
|
+
export declare function valueLabelsIn(options: {
|
|
41
|
+
fields?: readonly (FieldDef<never> | FieldGroup<never>)[];
|
|
42
|
+
columns?: readonly {
|
|
43
|
+
key: string;
|
|
44
|
+
valueLabels?: Readonly<Record<string, Text>>;
|
|
45
|
+
}[];
|
|
46
|
+
}, key: string): Readonly<Record<string, Text>> | undefined;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { RelationDenied, RelationKind } from "../core/constants.js";
|
|
2
|
+
import { FieldKind, FormStage } from "../core/constants.js";
|
|
3
|
+
import { isFunction } from "../core/guards.js";
|
|
4
|
+
import { keyRelation } from "./relations.js";
|
|
5
|
+
import { columnKindOf, optionsOfEnum, propertyAt, schemaFields } from "./resource-schema.js";
|
|
6
|
+
import { isListSchema } from "./schema.js";
|
|
7
|
+
import { resourceTexts } from "./resource-texts.js";
|
|
8
|
+
export const defined = new Set();
|
|
9
|
+
/**
|
|
10
|
+
* The resources whose rows show `resource`'s records through a `belongsTo` or `manyToMany`, with the relation's
|
|
11
|
+
* name: changing one of its records refreshes their lists.
|
|
12
|
+
*/
|
|
13
|
+
export function dependentsOf(resource) {
|
|
14
|
+
const found = [];
|
|
15
|
+
for (const candidate of defined) {
|
|
16
|
+
for (const [name, relation] of Object.entries(candidate.relations)) {
|
|
17
|
+
if (relation.kind !== RelationKind.belongsTo && relation.kind !== RelationKind.manyToMany)
|
|
18
|
+
continue;
|
|
19
|
+
if (relation.target().key === resource.key)
|
|
20
|
+
found.push({ resource: candidate, relation: name });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return found;
|
|
24
|
+
}
|
|
25
|
+
export function relationOf(name, relation) {
|
|
26
|
+
if (relation.kind === RelationKind.embeds)
|
|
27
|
+
return undefined;
|
|
28
|
+
if (relation.kind === RelationKind.hasMany)
|
|
29
|
+
return {
|
|
30
|
+
name,
|
|
31
|
+
kind: relation.kind,
|
|
32
|
+
key: relation.foreignKey,
|
|
33
|
+
target: relation.target,
|
|
34
|
+
denied: RelationDenied.showId,
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
name,
|
|
38
|
+
kind: relation.kind,
|
|
39
|
+
key: relation.key,
|
|
40
|
+
target: relation.target,
|
|
41
|
+
denied: relation.denied ?? RelationDenied.showId,
|
|
42
|
+
...(relation.kind === RelationKind.belongsTo && relation.snapshot ? { snapshot: relation.snapshot } : {}),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const always = () => true;
|
|
46
|
+
const never = () => false;
|
|
47
|
+
export function relationTools({ relations, properties, introspect, texts }) {
|
|
48
|
+
const options = { introspect };
|
|
49
|
+
const ownLabel = (field) => texts.text(field.label) ?? texts.field(field.key);
|
|
50
|
+
function relationAt(key) {
|
|
51
|
+
const [head = "", ...rest] = key.split(".");
|
|
52
|
+
const named = relations[head];
|
|
53
|
+
const byName = named ? relationOf(head, named) : undefined;
|
|
54
|
+
if (byName)
|
|
55
|
+
return { relation: byName, ...(rest.length > 0 ? { rest: rest.join(".") } : {}) };
|
|
56
|
+
const byKey = rest.length === 0 ? keyRelation(relations, key) : undefined;
|
|
57
|
+
return byKey ? { relation: relationOf(byKey[0], byKey[1]) } : undefined;
|
|
58
|
+
}
|
|
59
|
+
function baseField(field, group) {
|
|
60
|
+
const property = propertyAt(properties(), field.key);
|
|
61
|
+
const readOnly = field.readOnly;
|
|
62
|
+
const hidden = field.hidden;
|
|
63
|
+
const description = texts.text(field.description) ?? texts.own(`descriptions.${field.key}`);
|
|
64
|
+
const placeholder = texts.text(field.placeholder);
|
|
65
|
+
const groupLabel = group
|
|
66
|
+
? (texts.text(group.label) ?? texts.own(`groups.${group.group}`) ?? group.group)
|
|
67
|
+
: undefined;
|
|
68
|
+
const groupDescription = texts.text(group?.description);
|
|
69
|
+
return {
|
|
70
|
+
key: field.key,
|
|
71
|
+
label: ownLabel(field) ?? property?.title ?? field.key,
|
|
72
|
+
kind: FieldKind.text,
|
|
73
|
+
required: property?.required ?? false,
|
|
74
|
+
multiple: false,
|
|
75
|
+
readOnly: isFunction(readOnly) ? readOnly : readOnly === true || property?.readOnly === true ? always : never,
|
|
76
|
+
hidden: isFunction(hidden) ? hidden : hidden === true ? always : never,
|
|
77
|
+
colSpan: field.colSpan ?? 1,
|
|
78
|
+
...(property?.type === undefined ? {} : { valueType: property.type }),
|
|
79
|
+
...(description === undefined ? {} : { description }),
|
|
80
|
+
...(placeholder === undefined ? {} : { placeholder }),
|
|
81
|
+
...(groupLabel === undefined
|
|
82
|
+
? {}
|
|
83
|
+
: { group: groupLabel, ...(groupDescription === undefined ? {} : { groupDescription }) }),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function relationField(field, group) {
|
|
87
|
+
const named = relations[field.key];
|
|
88
|
+
if (named?.kind === RelationKind.embeds) {
|
|
89
|
+
const children = schemaFields(named.schema, options.introspect).map((child) => ({
|
|
90
|
+
...child,
|
|
91
|
+
label: texts.field(`${field.key}.${child.key}`) ?? child.label,
|
|
92
|
+
}));
|
|
93
|
+
const list = isListSchema(named.schema);
|
|
94
|
+
return {
|
|
95
|
+
...baseField(field, group),
|
|
96
|
+
kind: list ? FieldKind.rows : FieldKind.object,
|
|
97
|
+
multiple: list,
|
|
98
|
+
fields: children,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const reached = relationAt(field.key);
|
|
102
|
+
if (!reached || reached.rest !== undefined)
|
|
103
|
+
return undefined;
|
|
104
|
+
const { relation } = reached;
|
|
105
|
+
const target = texts.related(relation.target());
|
|
106
|
+
if (relation.kind === RelationKind.hasMany) {
|
|
107
|
+
const childKeys = new Set(field.fields?.map((child) => child.key));
|
|
108
|
+
const children = target
|
|
109
|
+
.fields(FormStage.create)
|
|
110
|
+
.filter((child) => child.key !== relation.key && (childKeys.size === 0 || childKeys.has(child.key)));
|
|
111
|
+
return {
|
|
112
|
+
...baseField(field, group),
|
|
113
|
+
label: ownLabel(field) ?? target.label(2),
|
|
114
|
+
kind: FieldKind.rows,
|
|
115
|
+
multiple: true,
|
|
116
|
+
relation,
|
|
117
|
+
fields: children,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const declared = named?.kind === RelationKind.belongsTo ? named.create : undefined;
|
|
121
|
+
return {
|
|
122
|
+
...baseField({ ...field, key: relation.key }, group),
|
|
123
|
+
label: ownLabel(field) ??
|
|
124
|
+
texts.field(relation.key) ??
|
|
125
|
+
propertyAt(properties(), relation.key)?.title ??
|
|
126
|
+
target.label(relation.kind === RelationKind.manyToMany ? 2 : 1),
|
|
127
|
+
kind: FieldKind.resource,
|
|
128
|
+
multiple: relation.kind === RelationKind.manyToMany,
|
|
129
|
+
resource: relation.target,
|
|
130
|
+
relation,
|
|
131
|
+
create: field.create ?? declared ?? true,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return { relationAt, relationField };
|
|
135
|
+
}
|
|
136
|
+
/** What a column through a relation (`product.price`) takes from the related field: its kind, tones, alignment, labels. */
|
|
137
|
+
export function inheritedColumn(related, rest) {
|
|
138
|
+
const declared = rest === undefined ? undefined : related?.options.columns?.find((entry) => entry.key === rest);
|
|
139
|
+
const property = rest === undefined ? undefined : propertyAt(related?.properties() ?? [], rest);
|
|
140
|
+
const labels = related && rest !== undefined ? valueLabelsIn(related.options, rest) : undefined;
|
|
141
|
+
const labelOf = related && rest !== undefined ? resourceTexts(related.key, related.locale).valueLabel(rest, labels) : undefined;
|
|
142
|
+
return {
|
|
143
|
+
tones: declared?.tones,
|
|
144
|
+
align: declared?.align,
|
|
145
|
+
options: optionsOfEnum(property, labelOf),
|
|
146
|
+
kind: (toned) => declared?.as ?? (property ? columnKindOf(property, toned) : undefined),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/** The labels of a key's values, from its field or its column, whichever declares them. */
|
|
150
|
+
export function valueLabelsIn(options, key) {
|
|
151
|
+
const declared = (options.fields ?? []).flatMap((entry) => ("group" in entry ? entry.fields : [entry]));
|
|
152
|
+
return (declared.find((entry) => entry.key === key)?.valueLabels ??
|
|
153
|
+
options.columns?.find((entry) => entry.key === key)?.valueLabels);
|
|
154
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ColumnKind, FieldKind } from "../core/constants.js";
|
|
2
|
+
import type { FieldDef, FieldGroup, Option, ResolvedField } from "./resource-types.js";
|
|
3
|
+
import { type Introspect, type SchemaProperty } from "./schema.js";
|
|
4
|
+
export declare const optionsOfEnum: (property: SchemaProperty | undefined, labelOf?: (value: string) => string | undefined) => Option[] | undefined;
|
|
5
|
+
export declare function columnKindOf(property: SchemaProperty, tones: boolean): ColumnKind;
|
|
6
|
+
export declare function fieldKindOf(property: SchemaProperty | undefined): FieldKind;
|
|
7
|
+
export declare function propertyAt(properties: readonly SchemaProperty[], path: string): SchemaProperty | undefined;
|
|
8
|
+
export declare function isGroup<T>(entry: FieldDef<T> | FieldGroup<T>): entry is FieldGroup<T>;
|
|
9
|
+
export declare function schemaFields(schema: unknown, introspect?: Introspect): ResolvedField<Record<string, unknown>>[];
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ColumnKind, FieldKind, JsonFormat, JsonType } from "../core/constants.js";
|
|
2
|
+
import { zodIntrospect } from "./schema.js";
|
|
3
|
+
export const optionsOfEnum = (property, labelOf) => property?.enum?.map((value) => ({ value, label: labelOf?.(value) ?? value }));
|
|
4
|
+
export function columnKindOf(property, tones) {
|
|
5
|
+
if (property.enum)
|
|
6
|
+
return tones ? ColumnKind.status : ColumnKind.badge;
|
|
7
|
+
if (property.type === JsonType.boolean)
|
|
8
|
+
return ColumnKind.boolean;
|
|
9
|
+
if (property.type === JsonType.number || property.type === JsonType.integer)
|
|
10
|
+
return ColumnKind.number;
|
|
11
|
+
if (property.type === JsonType.array)
|
|
12
|
+
return ColumnKind.tags;
|
|
13
|
+
if (property.format === JsonFormat.uri || property.format === JsonFormat.url)
|
|
14
|
+
return ColumnKind.link;
|
|
15
|
+
if (property.format === JsonFormat.date)
|
|
16
|
+
return ColumnKind.date;
|
|
17
|
+
if (property.format === JsonFormat.dateTime)
|
|
18
|
+
return ColumnKind.datetime;
|
|
19
|
+
return ColumnKind.text;
|
|
20
|
+
}
|
|
21
|
+
const formatKinds = new Map([
|
|
22
|
+
[JsonFormat.email, FieldKind.email],
|
|
23
|
+
[JsonFormat.date, FieldKind.date],
|
|
24
|
+
[JsonFormat.dateTime, FieldKind.datetime],
|
|
25
|
+
[JsonFormat.time, FieldKind.time],
|
|
26
|
+
[JsonFormat.duration, FieldKind.duration],
|
|
27
|
+
]);
|
|
28
|
+
export function fieldKindOf(property) {
|
|
29
|
+
if (!property)
|
|
30
|
+
return FieldKind.text;
|
|
31
|
+
if (property.enum)
|
|
32
|
+
return property.enum.length <= 4 ? FieldKind.radio : FieldKind.select;
|
|
33
|
+
if (property.type === JsonType.boolean)
|
|
34
|
+
return FieldKind.switch;
|
|
35
|
+
if (property.type === JsonType.number || property.type === JsonType.integer)
|
|
36
|
+
return FieldKind.number;
|
|
37
|
+
if (property.type === JsonType.array)
|
|
38
|
+
return FieldKind.tags;
|
|
39
|
+
const byFormat = property.format === undefined ? undefined : formatKinds.get(property.format);
|
|
40
|
+
return byFormat ?? ((property.maxLength ?? 0) > 255 ? FieldKind.textarea : FieldKind.text);
|
|
41
|
+
}
|
|
42
|
+
export function propertyAt(properties, path) {
|
|
43
|
+
const [head, ...rest] = path.split(".");
|
|
44
|
+
const property = properties.find((entry) => entry.key === head);
|
|
45
|
+
if (!property || rest.length === 0)
|
|
46
|
+
return property;
|
|
47
|
+
return property.properties ? propertyAt(property.properties, rest.join(".")) : undefined;
|
|
48
|
+
}
|
|
49
|
+
export function isGroup(entry) {
|
|
50
|
+
return "group" in entry;
|
|
51
|
+
}
|
|
52
|
+
const always = () => true;
|
|
53
|
+
const never = () => false;
|
|
54
|
+
export function schemaFields(schema, introspect = zodIntrospect) {
|
|
55
|
+
return (introspect(schema) ?? []).map((property) => {
|
|
56
|
+
const options = optionsOfEnum(property);
|
|
57
|
+
return {
|
|
58
|
+
key: property.key,
|
|
59
|
+
label: property.title ?? property.key,
|
|
60
|
+
kind: fieldKindOf(property),
|
|
61
|
+
required: property.required,
|
|
62
|
+
multiple: property.type === JsonType.array,
|
|
63
|
+
readOnly: property.readOnly ? always : never,
|
|
64
|
+
hidden: never,
|
|
65
|
+
colSpan: 1,
|
|
66
|
+
...(property.description === undefined ? {} : { description: property.description }),
|
|
67
|
+
...(options ? { options } : {}),
|
|
68
|
+
...(property.minimum === undefined ? {} : { min: property.minimum }),
|
|
69
|
+
...(property.maximum === undefined ? {} : { max: property.maximum }),
|
|
70
|
+
...(property.type === undefined ? {} : { valueType: property.type }),
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Locale, type Text } from "../i18n/locale.js";
|
|
2
|
+
import type { AnyResource } from "./resource-types.js";
|
|
3
|
+
/** How a resource's definition turns into text in one locale: its own strings first, then `resources.<key>.…`. */
|
|
4
|
+
export type ResourceTexts = {
|
|
5
|
+
readonly locale: Locale | undefined;
|
|
6
|
+
text(value: Text | undefined): string | undefined;
|
|
7
|
+
/** `resources.<key>.<path>` in the locale, when it has it. */
|
|
8
|
+
own(path: string): string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* A field's label: `resources.<key>.fields.<path>`, or its `label` when the path holds more (a subdocument's
|
|
11
|
+
* fields, a relation's): `"shipping": { "label": "Envío", "city": "Ciudad" }`.
|
|
12
|
+
*/
|
|
13
|
+
field(path: string): string | undefined;
|
|
14
|
+
related(resource: AnyResource): AnyResource;
|
|
15
|
+
/** A value's label: the definition's, then `resources.<key>.values.<field>.<value>`. */
|
|
16
|
+
valueLabel(field: string, labels: Readonly<Record<string, Text>> | undefined): (value: string) => string | undefined;
|
|
17
|
+
};
|
|
18
|
+
export declare function resourceTexts(key: string, locale: Locale | undefined): ResourceTexts;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { lookup, resolveText } from "../i18n/locale.js";
|
|
2
|
+
export function resourceTexts(key, locale) {
|
|
3
|
+
const own = (path) => lookup(locale, `resources.${key}.${path}`);
|
|
4
|
+
const text = (value) => resolveText(value, locale);
|
|
5
|
+
return {
|
|
6
|
+
locale,
|
|
7
|
+
text,
|
|
8
|
+
own,
|
|
9
|
+
field: (path) => own(`fields.${path}`) ?? own(`fields.${path}.label`),
|
|
10
|
+
related: (resource) => resource.in(locale),
|
|
11
|
+
valueLabel: (field, labels) => (value) => text(labels?.[value]) ?? own(`values.${field}.${value}`),
|
|
12
|
+
};
|
|
13
|
+
}
|