@dashild/core 0.0.0-stage → 0.1.0-alpha.2
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 +47 -2
- package/dist/actions.d.ts +43 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +73 -0
- package/dist/actions.js.map +1 -0
- package/dist/index.d.ts +211 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/mapping.d.ts +109 -0
- package/dist/mapping.d.ts.map +1 -0
- package/dist/mapping.js +378 -0
- package/dist/mapping.js.map +1 -0
- package/dist/messages.d.ts +98 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +181 -0
- package/dist/messages.js.map +1 -0
- package/dist/metadata.d.ts +67 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +9 -0
- package/dist/metadata.js.map +1 -0
- package/dist/server.d.ts +209 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +778 -0
- package/dist/server.js.map +1 -0
- package/package.json +53 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Daljomar Morillo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dashild/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Declaraciones públicas y lógica isomorfa. **No puede importar React ni Prisma**: lo consume tanto el servidor como `registry.tsx` en el cliente. Sí depende de `zod`, que es isomorfo y es el mismo esquema en ambos lados.
|
|
4
|
+
|
|
5
|
+
## Superficie pública
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
// Declaraciones (datos serializables)
|
|
9
|
+
export { defineResource, definePanel, definePolicies, registerCell, registerField }
|
|
10
|
+
|
|
11
|
+
// Contrato de metadatos (DMMF → JSON)
|
|
12
|
+
export type { FieldMetadata, ModelMetadata, EnumMetadata, DashildMetadata }
|
|
13
|
+
export { METADATA_FORMAT_VERSION }
|
|
14
|
+
|
|
15
|
+
// Tabla de mapeo de tipos
|
|
16
|
+
export {
|
|
17
|
+
SCALAR_MAPPINGS, // Prisma → zod / campo / celda / dto / toDb
|
|
18
|
+
resolveFieldMapping, // campo del DMMF → mapeo resuelto
|
|
19
|
+
buildFieldSchema, // + obligatoriedad según la operación
|
|
20
|
+
buildObjectSchema, // fila completa de formulario
|
|
21
|
+
mappingContext,
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## `metadata.ts` y `mapping.ts`
|
|
26
|
+
|
|
27
|
+
Son el mismo contrato visto desde dos lados:
|
|
28
|
+
|
|
29
|
+
- `metadata.ts` define lo que el generador extrae del DMMF. Datos planos, serializables.
|
|
30
|
+
- `mapping.ts` define qué hace Dashild con cada tipo. Es la especificación ejecutable de `Architecture.md` §10.
|
|
31
|
+
|
|
32
|
+
Viven en core y no en `@dashild/prisma` porque los necesita el runtime del servidor (autoridad de validación y DTO) y el CLI (scaffold), no solo el generador. `@dashild/prisma` los re-exporta.
|
|
33
|
+
|
|
34
|
+
`mapping.ts` expone **`dto` y `toDb`**: la conversión de ida y de vuelta. Sin la vuelta, el esquema Zod promete algo que Prisma rechaza (`BigInt` como string).
|
|
35
|
+
|
|
36
|
+
## `./server`
|
|
37
|
+
|
|
38
|
+
Subpath con la superficie de servidor: `dashildAction`, extensión de Prisma y conversión a DTO. Nunca se importa desde un componente cliente.
|
|
39
|
+
|
|
40
|
+
Mantenerlo como subpath (y no como paquete aparte) evita multiplicar nombres de paquete: el bundle no arrastra Prisma porque el cliente no importa `@dashild/core/server`.
|
|
41
|
+
|
|
42
|
+
## Tests
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pnpm --filter @dashild/core test
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Compila `src` + `test` a `dist-test/` y ejecuta con `node --test`. `test/mapping.test.ts` es la especificación: 21 casos sobre el schema hostil (Decimal, BigInt, Json, enums, relaciones, opcionales, tipos desconocidos).
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Table and form actions.
|
|
3
|
+
*
|
|
4
|
+
* The declaration lives in the resource (serializable data). The handler lives
|
|
5
|
+
* in `src/dashild/actions/<model>.ts` on the server and is referenced by name.
|
|
6
|
+
*
|
|
7
|
+
* If a resource does not declare `actions`, the built-in CRUD actions are used.
|
|
8
|
+
* If it does, that is the complete list: omitting `delete` removes the delete
|
|
9
|
+
* button.
|
|
10
|
+
*/
|
|
11
|
+
import type { ActionDefinition, CurrentUser, ResourceDefinition } from "./index.js";
|
|
12
|
+
import { type Locale } from "./messages.js";
|
|
13
|
+
export type BuiltInActionName = "create" | "view" | "edit" | "delete" | "save" | "cancel";
|
|
14
|
+
export declare function isBuiltInAction(name: string): name is BuiltInActionName;
|
|
15
|
+
/** Completes an action with its built-in label/variant when it is a base name. */
|
|
16
|
+
export declare function mergeActionDefaults(action: ActionDefinition, locale?: Locale): ActionDefinition;
|
|
17
|
+
export declare function defaultTableActions(locale?: Locale): ActionDefinition[];
|
|
18
|
+
export declare function defaultFormActions(locale?: Locale): ActionDefinition[];
|
|
19
|
+
export declare function resolveTableActions(resource: ResourceDefinition, locale?: Locale): ActionDefinition[];
|
|
20
|
+
export declare function resolveFormActions(resource: ResourceDefinition, locale?: Locale): ActionDefinition[];
|
|
21
|
+
/** Finds a declared action, in table or form, by name. */
|
|
22
|
+
export declare function findAction(resource: ResourceDefinition, name: string, locale?: Locale): ActionDefinition | undefined;
|
|
23
|
+
export interface ActionContext<TUser extends CurrentUser = CurrentUser> {
|
|
24
|
+
resource: ResourceDefinition;
|
|
25
|
+
user: TUser;
|
|
26
|
+
/** Row id, for row actions. */
|
|
27
|
+
id?: string;
|
|
28
|
+
/** Form values, for form actions. */
|
|
29
|
+
values?: Record<string, unknown>;
|
|
30
|
+
/** `data` declared on the action. */
|
|
31
|
+
data?: Record<string, unknown>;
|
|
32
|
+
/** Active organization and roles resolved by policies. */
|
|
33
|
+
organizationId?: string | null;
|
|
34
|
+
roles?: string[];
|
|
35
|
+
}
|
|
36
|
+
export interface ActionResult {
|
|
37
|
+
ok: boolean;
|
|
38
|
+
message?: string;
|
|
39
|
+
/** URL to navigate to after the action (downloads, redirects). */
|
|
40
|
+
href?: string;
|
|
41
|
+
}
|
|
42
|
+
export type ActionHandler<TUser extends CurrentUser = CurrentUser> = (context: ActionContext<TUser>) => Promise<ActionResult>;
|
|
43
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","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AC,CAAC;IACjC,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,0DAA0D;IAC1D,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,aAAa,CAAC,KAAK,SAAS,WAAW,GAAG,WAAW,IAAI,CACnE,OAAO,EAAE,aAAa,CAAC,KAAK,CAAC,KAC1B,OAAO,CAAC,YAAY,CAAC,CAAC"}
|
package/dist/actions.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Table and form actions.
|
|
3
|
+
*
|
|
4
|
+
* The declaration lives in the resource (serializable data). The handler lives
|
|
5
|
+
* in `src/dashild/actions/<model>.ts` on the server and is referenced by name.
|
|
6
|
+
*
|
|
7
|
+
* If a resource does not declare `actions`, the built-in CRUD actions are used.
|
|
8
|
+
* If it does, that is the complete list: omitting `delete` removes the delete
|
|
9
|
+
* button.
|
|
10
|
+
*/
|
|
11
|
+
import { translate } from "./messages.js";
|
|
12
|
+
const BUILT_IN_NAMES = new Set([
|
|
13
|
+
"create",
|
|
14
|
+
"view",
|
|
15
|
+
"edit",
|
|
16
|
+
"delete",
|
|
17
|
+
"save",
|
|
18
|
+
"cancel",
|
|
19
|
+
]);
|
|
20
|
+
function builtIns(locale = "en") {
|
|
21
|
+
return {
|
|
22
|
+
create: {
|
|
23
|
+
name: "create",
|
|
24
|
+
label: translate(locale, "action.create"),
|
|
25
|
+
placement: "header",
|
|
26
|
+
},
|
|
27
|
+
view: { name: "view", label: translate(locale, "action.view") },
|
|
28
|
+
edit: { name: "edit", label: translate(locale, "action.edit") },
|
|
29
|
+
delete: {
|
|
30
|
+
name: "delete",
|
|
31
|
+
label: translate(locale, "action.delete"),
|
|
32
|
+
variant: "destructive",
|
|
33
|
+
confirm: translate(locale, "action.deleteConfirm"),
|
|
34
|
+
},
|
|
35
|
+
save: { name: "save", label: translate(locale, "action.save") },
|
|
36
|
+
cancel: {
|
|
37
|
+
name: "cancel",
|
|
38
|
+
label: translate(locale, "action.cancel"),
|
|
39
|
+
variant: "outline",
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export function isBuiltInAction(name) {
|
|
44
|
+
return BUILT_IN_NAMES.has(name);
|
|
45
|
+
}
|
|
46
|
+
/** Completes an action with its built-in label/variant when it is a base name. */
|
|
47
|
+
export function mergeActionDefaults(action, locale = "en") {
|
|
48
|
+
if (!isBuiltInAction(action.name))
|
|
49
|
+
return action;
|
|
50
|
+
return { ...builtIns(locale)[action.name], ...action };
|
|
51
|
+
}
|
|
52
|
+
export function defaultTableActions(locale = "en") {
|
|
53
|
+
const actions = builtIns(locale);
|
|
54
|
+
return [actions.create, actions.view, actions.edit, actions.delete].map((action) => ({ ...action }));
|
|
55
|
+
}
|
|
56
|
+
export function defaultFormActions(locale = "en") {
|
|
57
|
+
const actions = builtIns(locale);
|
|
58
|
+
return [{ ...actions.save }, { ...actions.cancel }];
|
|
59
|
+
}
|
|
60
|
+
export function resolveTableActions(resource, locale = "en") {
|
|
61
|
+
const actions = resource.table.actions ?? defaultTableActions(locale);
|
|
62
|
+
return actions.map((action) => mergeActionDefaults(action, locale));
|
|
63
|
+
}
|
|
64
|
+
export function resolveFormActions(resource, locale = "en") {
|
|
65
|
+
const actions = resource.form.actions ?? defaultFormActions(locale);
|
|
66
|
+
return actions.map((action) => mergeActionDefaults(action, locale));
|
|
67
|
+
}
|
|
68
|
+
/** Finds a declared action, in table or form, by name. */
|
|
69
|
+
export function findAction(resource, name, locale = "en") {
|
|
70
|
+
return (resolveTableActions(resource, locale).find((action) => action.name === name) ??
|
|
71
|
+
resolveFormActions(resource, locale).find((action) => action.name === name));
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,EAAE,SAAS,EAAe,MAAM,eAAe,CAAC;AAUvD,MAAM,cAAc,GAAG,IAAI,GAAG,CAAS;IACrC,QAAQ;IACR,MAAM;IACN,MAAM;IACN,QAAQ;IACR,MAAM;IACN,QAAQ;CACT,CAAC,CAAC;AAEH,SAAS,QAAQ,CACf,MAAM,GAAW,IAAI;IAErB,OAAO;QACL,MAAM,EAAE;YACN,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,eAAe,CAAC;YACzC,SAAS,EAAE,QAAQ;SACpB;QACD,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE;QAC/D,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE;QAC/D,MAAM,EAAE;YACN,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,eAAe,CAAC;YACzC,OAAO,EAAE,aAAa;YACtB,OAAO,EAAE,SAAS,CAAC,MAAM,EAAE,sBAAsB,CAAC;SACnD;QACD,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE;QAC/D,MAAM,EAAE;YACN,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,eAAe,CAAC;YACzC,OAAO,EAAE,SAAS;SACnB;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IA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,MAAM,GAAW,IAAI;IAErB,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACpE,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACtE,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,UAAU,CACxB,QAA4B,EAC5B,IAAY,EACZ,MAAM,GAAW,IAAI;IAErB,OAAO,CACL,mBAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,IAAI,CACxC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CACjC;QACD,kBAAkB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,IAAI,CACvC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CACjC,CACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dashild/core — public declarations.
|
|
3
|
+
*
|
|
4
|
+
* Everything in this file is a DATA DOCUMENT: it is imported on the server
|
|
5
|
+
* (validation, whitelist, query building) and its result is passed to the
|
|
6
|
+
* client as a serializable prop. That is why nothing here may contain closures.
|
|
7
|
+
*
|
|
8
|
+
* Types are intentionally minimal: the spike (blocks 2 and 3) closes them.
|
|
9
|
+
*/
|
|
10
|
+
import type { Locale } from "./messages.js";
|
|
11
|
+
import type { FieldFormat, FieldType } from "./mapping.js";
|
|
12
|
+
export interface NavigationDefinition {
|
|
13
|
+
label: string;
|
|
14
|
+
/** Segmento de URL del recurso. `make:resource` lo deriva del modelo. */
|
|
15
|
+
slug: string;
|
|
16
|
+
/**
|
|
17
|
+
* Icon name. The shell resolves a base list (`users`, `building`,
|
|
18
|
+
* `file-text`, `settings`, `database`, `folder`, `chart`, `package`,
|
|
19
|
+
* `shopping-cart`, `tag`, `calendar`, `mail`, `briefcase`, `credit-card`,
|
|
20
|
+
* `truck`, `layers`) and the app can add its own in
|
|
21
|
+
* `src/dashild/icons.ts`. An unknown name falls back to the generic icon
|
|
22
|
+
* en desarrollo.
|
|
23
|
+
*/
|
|
24
|
+
icon?: string;
|
|
25
|
+
group?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface PolicyReference {
|
|
28
|
+
/**
|
|
29
|
+
* Intent declaration. The resource must have a matching policy in
|
|
30
|
+
* `policies.ts`; without it, the runtime fails closed.
|
|
31
|
+
*/
|
|
32
|
+
scope: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ValidationRules {
|
|
35
|
+
required?: boolean;
|
|
36
|
+
min?: number;
|
|
37
|
+
max?: number;
|
|
38
|
+
/** Pattern as a string: the resource is data and cannot hold a RegExp. */
|
|
39
|
+
pattern?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ColumnDefinition {
|
|
42
|
+
field: string;
|
|
43
|
+
label?: string;
|
|
44
|
+
sortable?: boolean;
|
|
45
|
+
format?: FieldFormat;
|
|
46
|
+
/** Nombre registrado con `registerCell`. */
|
|
47
|
+
cell?: string;
|
|
48
|
+
/** When `field` is a relation, the related model field to display. */
|
|
49
|
+
display?: string;
|
|
50
|
+
/** Mapa valor -> tono, para celdas de tipo badge. */
|
|
51
|
+
tone?: Record<string, string>;
|
|
52
|
+
}
|
|
53
|
+
export interface FilterDefinition {
|
|
54
|
+
field: string;
|
|
55
|
+
type: "boolean" | "enum" | "relation" | "text" | "number" | "date";
|
|
56
|
+
label?: string;
|
|
57
|
+
/** Campo del modelo relacionado que se usa como etiqueta legible. */
|
|
58
|
+
display?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface FieldDefinition {
|
|
61
|
+
field: string;
|
|
62
|
+
type: FieldType;
|
|
63
|
+
label?: string;
|
|
64
|
+
/** Prisma relation name when `type` is "relation". */
|
|
65
|
+
relation?: string;
|
|
66
|
+
display?: string;
|
|
67
|
+
default?: unknown;
|
|
68
|
+
rules?: ValidationRules;
|
|
69
|
+
}
|
|
70
|
+
export type ActionPlacement = "header" | "row";
|
|
71
|
+
export type ActionVariant = "default" | "destructive" | "outline" | "secondary" | "ghost";
|
|
72
|
+
export interface ActionDefinition {
|
|
73
|
+
/**
|
|
74
|
+
* Handler name in `src/dashild/actions/<model>.ts`. Built-in names
|
|
75
|
+
* (`create`, `view`, `edit`, `delete`, `save`, `cancel`) are resolved by
|
|
76
|
+
* the shell, not by a handler.
|
|
77
|
+
*/
|
|
78
|
+
name: string;
|
|
79
|
+
label?: string;
|
|
80
|
+
/** Nombre de icono del mapa compartido. */
|
|
81
|
+
icon?: string;
|
|
82
|
+
/** Table: header or row menu. Defaults to row. */
|
|
83
|
+
placement?: ActionPlacement;
|
|
84
|
+
/** Ask for confirmation; a string is the dialog text. */
|
|
85
|
+
confirm?: boolean | string;
|
|
86
|
+
variant?: ActionVariant;
|
|
87
|
+
/** Permiso que exige; se resuelve en policies.ts (Bloque 4). */
|
|
88
|
+
requires?: string;
|
|
89
|
+
/** Link action: it does not need a handler. Supports `{id}`. */
|
|
90
|
+
href?: string;
|
|
91
|
+
/** Datos extra que recibe el handler. */
|
|
92
|
+
data?: Record<string, unknown>;
|
|
93
|
+
}
|
|
94
|
+
export interface TableDefinition {
|
|
95
|
+
searchable?: string[];
|
|
96
|
+
columns: ColumnDefinition[];
|
|
97
|
+
filters?: FilterDefinition[];
|
|
98
|
+
actions?: ActionDefinition[];
|
|
99
|
+
pageSize?: number;
|
|
100
|
+
}
|
|
101
|
+
export interface FormDefinition {
|
|
102
|
+
fields: FieldDefinition[];
|
|
103
|
+
actions?: ActionDefinition[];
|
|
104
|
+
}
|
|
105
|
+
export interface ResourceDefinition {
|
|
106
|
+
model: string;
|
|
107
|
+
navigation: NavigationDefinition;
|
|
108
|
+
policy?: PolicyReference;
|
|
109
|
+
table: TableDefinition;
|
|
110
|
+
form: FormDefinition;
|
|
111
|
+
actions?: ActionDefinition[];
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Declares a resource. Identity function: no runtime behind it, only types.
|
|
115
|
+
* types. The returned object is serializable and is passed to the client as a prop.
|
|
116
|
+
*
|
|
117
|
+
* It returns `ResourceDefinition` on purpose, not the literal: a `const` generic
|
|
118
|
+
* turns `columns` into a union where `sortable` does not exist on every
|
|
119
|
+
* variant, and the runtime would have to cast on every access.
|
|
120
|
+
*/
|
|
121
|
+
export declare function defineResource(definition: ResourceDefinition): ResourceDefinition;
|
|
122
|
+
export interface CurrentUser {
|
|
123
|
+
id: string;
|
|
124
|
+
email?: string;
|
|
125
|
+
name?: string;
|
|
126
|
+
}
|
|
127
|
+
/** Nombre de una paleta de Tailwind que el panel puede usar como primario. */
|
|
128
|
+
export type PanelColor = "amber" | "blue" | "cyan" | "emerald" | "fuchsia" | "gray" | "green" | "indigo" | "lime" | "neutral" | "orange" | "pink" | "red" | "rose" | "sky" | "slate" | "stone" | "teal" | "violet" | "yellow" | "zinc";
|
|
129
|
+
export interface PanelBrand {
|
|
130
|
+
name?: string;
|
|
131
|
+
/** Ruta o URL del logo. Si falta, se usa la inicial del nombre. */
|
|
132
|
+
logo?: string;
|
|
133
|
+
}
|
|
134
|
+
export interface PanelTheme {
|
|
135
|
+
/** Modo inicial. El usuario puede cambiarlo si `toggle` es true. */
|
|
136
|
+
defaultMode?: "light" | "dark";
|
|
137
|
+
/** Show the light/dark toggle in the header. */
|
|
138
|
+
toggle?: boolean;
|
|
139
|
+
/** Paleta primaria de shadcn. */
|
|
140
|
+
primary?: PanelColor;
|
|
141
|
+
}
|
|
142
|
+
export interface PanelSidebar {
|
|
143
|
+
/** `icon` colapsa a iconos; `offcanvas` se oculta; `none` queda fijo. */
|
|
144
|
+
collapsible?: "icon" | "offcanvas" | "none";
|
|
145
|
+
}
|
|
146
|
+
export interface PanelAuth<TUser extends CurrentUser = CurrentUser> {
|
|
147
|
+
getCurrentUser: () => Promise<TUser | null>;
|
|
148
|
+
/** Server action to sign out. If missing, the menu is not shown. */
|
|
149
|
+
signOut?: () => Promise<void>;
|
|
150
|
+
}
|
|
151
|
+
export interface PanelDefinition<TUser extends CurrentUser = CurrentUser> {
|
|
152
|
+
title: string;
|
|
153
|
+
/** UI language for built-in labels and validation messages. Defaults to `en`. */
|
|
154
|
+
locale?: Locale;
|
|
155
|
+
/** Prefijo de URL del panel, sin barra final. Ej: "/admin". */
|
|
156
|
+
path: string;
|
|
157
|
+
/**
|
|
158
|
+
* Domain the panel belongs to. Next routes by host, so Dashild uses it to
|
|
159
|
+
* generate absolute URLs and for documentation.
|
|
160
|
+
*/
|
|
161
|
+
domain?: string;
|
|
162
|
+
brand?: PanelBrand;
|
|
163
|
+
theme?: PanelTheme;
|
|
164
|
+
sidebar?: PanelSidebar;
|
|
165
|
+
/** Maximum content width, like Filament. */
|
|
166
|
+
maxContentWidth?: "sm" | "md" | "lg" | "xl" | "full";
|
|
167
|
+
resources: ResourceDefinition[];
|
|
168
|
+
auth: PanelAuth<TUser>;
|
|
169
|
+
}
|
|
170
|
+
/** Declares the panel. `auth.getCurrentUser` is the only executable part of the config. */
|
|
171
|
+
export declare function definePanel<TUser extends CurrentUser>(definition: PanelDefinition<TUser>): PanelDefinition<TUser>;
|
|
172
|
+
export interface PolicyContext<TUser extends CurrentUser = CurrentUser> {
|
|
173
|
+
user: TUser;
|
|
174
|
+
organizationId: string | null;
|
|
175
|
+
roles: string[];
|
|
176
|
+
}
|
|
177
|
+
export type PolicyPredicate<TUser extends CurrentUser = CurrentUser> = (ctx: PolicyContext<TUser>, values?: Record<string, unknown>) => boolean | Promise<boolean>;
|
|
178
|
+
export interface ResourcePolicy<TUser extends CurrentUser = CurrentUser> {
|
|
179
|
+
/**
|
|
180
|
+
* Prisma `where` fragment applied to every read and write. Returning `null`
|
|
181
|
+
* denies the whole resource.
|
|
182
|
+
*/
|
|
183
|
+
scope?: (ctx: PolicyContext<TUser>) => Record<string, unknown> | null;
|
|
184
|
+
can?: Record<string, PolicyPredicate<TUser>>;
|
|
185
|
+
}
|
|
186
|
+
export interface PoliciesDefinition<TUser extends CurrentUser = CurrentUser> {
|
|
187
|
+
organizationOf?: (user: TUser) => Promise<string | null>;
|
|
188
|
+
rolesOf?: (user: TUser) => Promise<string[]>;
|
|
189
|
+
resources: Record<string, ResourcePolicy<TUser>>;
|
|
190
|
+
}
|
|
191
|
+
/** Declares server policies. This module is never imported on the client. */
|
|
192
|
+
export declare function definePolicies<TUser extends CurrentUser = CurrentUser>(definition: PoliciesDefinition<TUser>): PoliciesDefinition<TUser>;
|
|
193
|
+
/**
|
|
194
|
+
* TODO(spike bloque 3): tipar contra `React.ComponentType`.
|
|
195
|
+
* core cannot depend on @types/react because the server imports it too.
|
|
196
|
+
*/
|
|
197
|
+
export type ComponentRenderer = (props: any) => unknown;
|
|
198
|
+
/** Registra una celda de tabla propia. Usar desde `registry.tsx`. */
|
|
199
|
+
export declare function registerCell(name: string, renderer: ComponentRenderer): void;
|
|
200
|
+
/** Registra un campo de formulario propio. Usar desde `registry.tsx`. */
|
|
201
|
+
export declare function registerField(name: string, renderer: ComponentRenderer): void;
|
|
202
|
+
/**
|
|
203
|
+
* Metadata types and the mapping table are exported here so generator,
|
|
204
|
+
* runtime and CLI share a single definition. See `metadata.ts` and
|
|
205
|
+
* `mapping.ts`.
|
|
206
|
+
*/
|
|
207
|
+
export * from "./messages.js";
|
|
208
|
+
export * from "./metadata.js";
|
|
209
|
+
export * from "./mapping.js";
|
|
210
|
+
export * from "./actions.js";
|
|
211
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE3D,MAAM,WAAW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AAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;CAC9C;AAED,MAAM,WAAW,kBAAkB,CAAC,KAAK,SAAS,WAAW,GAAG,WAAW;IACzE,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACzD,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7C,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;CAClD;AAED,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,KAAK,SAAS,WAAW,GAAG,WAAW,EACpE,UAAU,EAAE,kBAAkB,CAAC,KAAK,CAAC,GACpC,kBAAkB,CAAC,KAAK,CAAC,CAE3B;AAED;;;GAGG;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC;AAKxD,qEAAqE;AACrE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAE5E;AAED,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAE7E;AAMD;;;;GAIG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dashild/core — public declarations.
|
|
3
|
+
*
|
|
4
|
+
* Everything in this file is a DATA DOCUMENT: it is imported on the server
|
|
5
|
+
* (validation, whitelist, query building) and its result is passed to the
|
|
6
|
+
* client as a serializable prop. That is why nothing here may contain closures.
|
|
7
|
+
*
|
|
8
|
+
* Types are intentionally minimal: the spike (blocks 2 and 3) closes them.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Declares a resource. Identity function: no runtime behind it, only types.
|
|
12
|
+
* types. The returned object is serializable and is passed to the client as a prop.
|
|
13
|
+
*
|
|
14
|
+
* It returns `ResourceDefinition` on purpose, not the literal: a `const` generic
|
|
15
|
+
* turns `columns` into a union where `sortable` does not exist on every
|
|
16
|
+
* variant, and the runtime would have to cast on every access.
|
|
17
|
+
*/
|
|
18
|
+
export function defineResource(definition) {
|
|
19
|
+
return definition;
|
|
20
|
+
}
|
|
21
|
+
/** Declares the panel. `auth.getCurrentUser` is the only executable part of the config. */
|
|
22
|
+
export function definePanel(definition) {
|
|
23
|
+
return definition;
|
|
24
|
+
}
|
|
25
|
+
/** Declares server policies. This module is never imported on the client. */
|
|
26
|
+
export function definePolicies(definition) {
|
|
27
|
+
return definition;
|
|
28
|
+
}
|
|
29
|
+
const cells = new Map();
|
|
30
|
+
const fields = new Map();
|
|
31
|
+
/** Registra una celda de tabla propia. Usar desde `registry.tsx`. */
|
|
32
|
+
export function registerCell(name, renderer) {
|
|
33
|
+
cells.set(name, renderer);
|
|
34
|
+
}
|
|
35
|
+
/** Registra un campo de formulario propio. Usar desde `registry.tsx`. */
|
|
36
|
+
export function registerField(name, renderer) {
|
|
37
|
+
fields.set(name, renderer);
|
|
38
|
+
}
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// Metadata contract and mapping table
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
/**
|
|
43
|
+
* Metadata types and the mapping table are exported here so generator,
|
|
44
|
+
* runtime and CLI share a single definition. See `metadata.ts` and
|
|
45
|
+
* `mapping.ts`.
|
|
46
|
+
*/
|
|
47
|
+
export * from "./messages.js";
|
|
48
|
+
export * from "./metadata.js";
|
|
49
|
+
export * from "./mapping.js";
|
|
50
|
+
export * from "./actions.js";
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA4HH;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,UAA8B;IAC3D,OAAO,UAAU,CAAC;AACpB,CAAC;AA8ED,2FAA2F;AAC3F,MAAM,UAAU,WAAW,CACzB,UAAkC;IAElC,OAAO,UAAU,CAAC;AACpB,CAAC;AA4BD,6EAA6E;AAC7E,MAAM,UAAU,cAAc,CAC5B,UAAqC;IAErC,OAAO,UAAU,CAAC;AACpB,CAAC;AASD,MAAM,KAAK,GAAG,IAAI,GAAG,EAA6B,CAAC;AACnD,MAAM,MAAM,GAAG,IAAI,GAAG,EAA6B,CAAC;AAEpD,qEAAqE;AACrE,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,QAA2B;IACpE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC5B,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,QAA2B;IACrE,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC7B,CAAC;AAED,8EAA8E;AAC9E,sCAAsC;AACtC,8EAA8E;AAE9E;;;;GAIG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The type mapping table: Dashild's SINGLE CONTRACT.
|
|
3
|
+
*
|
|
4
|
+
* Four things depend on it:
|
|
5
|
+
*
|
|
6
|
+
* 1. El esquema Zod (autoridad en servidor, UX en cliente).
|
|
7
|
+
* 2. The default form field.
|
|
8
|
+
* 3. The default table cell format.
|
|
9
|
+
* 4. The forward (`dto`, Prisma → client) and reverse (`toDb`, client →
|
|
10
|
+
* (`toDb`, cliente → Prisma).
|
|
11
|
+
*
|
|
12
|
+
* If a type is not here, it does not exist: `make:resource` will not generate
|
|
13
|
+
* runtime will not accept it and `dashild doctor` reports it. The table is the
|
|
14
|
+
* specification; everything else consumes it.
|
|
15
|
+
*
|
|
16
|
+
* It lives in core (isomorphic) because the generator (build time), the server
|
|
17
|
+
* runtime (authority) and the client (UX) need it. It imports no React or
|
|
18
|
+
* Prisma: only `zod`, which is isomorphic.
|
|
19
|
+
*/
|
|
20
|
+
import { z } from "zod";
|
|
21
|
+
import type { EnumMetadata, FieldMetadata, ScalarKind } from "./metadata.js";
|
|
22
|
+
import { type Locale } from "./messages.js";
|
|
23
|
+
/**
|
|
24
|
+
* How a value is formatted in the table.
|
|
25
|
+
*
|
|
26
|
+
* `badge` is not a data type: it is a presentation format for discrete
|
|
27
|
+
* values (booleans, enums). The resource sets the actual tone with
|
|
28
|
+
* `ColumnDefinition.tone`.
|
|
29
|
+
*/
|
|
30
|
+
export type FieldFormat = "text" | "badge" | "number" | "currency" | "date" | "datetime" | "json";
|
|
31
|
+
/** Control de entrada por defecto. */
|
|
32
|
+
export type FieldType = "text" | "textarea" | "email" | "password" | "number" | "boolean" | "date" | "datetime" | "select" | "relation" | "json";
|
|
33
|
+
/** Operation that determines schema presence. */
|
|
34
|
+
export type Operation = "create" | "update";
|
|
35
|
+
export interface MappingContext {
|
|
36
|
+
/** Values for every enum, indexed by name. */
|
|
37
|
+
readonly enums: ReadonlyMap<string, readonly string[]>;
|
|
38
|
+
/** Locale used for validation messages. */
|
|
39
|
+
readonly locale: Locale;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Enum index to resolve `Enum` without walking the metadata again on
|
|
43
|
+
* every field.
|
|
44
|
+
*/
|
|
45
|
+
export declare function mappingContext(metadata: {
|
|
46
|
+
readonly enums: readonly EnumMetadata[];
|
|
47
|
+
}, locale?: Locale): MappingContext;
|
|
48
|
+
/** Empty context: useful when only scalars are resolved. */
|
|
49
|
+
export declare const EMPTY_MAPPING_CONTEXT: MappingContext;
|
|
50
|
+
export interface ResolvedFieldMapping {
|
|
51
|
+
/** Control de formulario por defecto. */
|
|
52
|
+
readonly field: FieldType;
|
|
53
|
+
/** Formato de celda por defecto. */
|
|
54
|
+
readonly format: FieldFormat;
|
|
55
|
+
/** Esquema del tipo, sin aplicar obligatoriedad ni nulabilidad. */
|
|
56
|
+
readonly zod: z.ZodTypeAny;
|
|
57
|
+
/** Prisma → cliente. Obligatorio: Decimal y BigInt rompen el panel sin esto. */
|
|
58
|
+
readonly dto: (value: unknown) => unknown;
|
|
59
|
+
/** Client → Prisma. The inverse of `dto`; without it validation is pointless. */
|
|
60
|
+
readonly toDb: (value: unknown) => unknown;
|
|
61
|
+
/** Does it appear in the generated table by default? */
|
|
62
|
+
readonly column: boolean;
|
|
63
|
+
/** Does it appear in the generated form by default? */
|
|
64
|
+
readonly editable: boolean;
|
|
65
|
+
/** Aviso para `dashild doctor` y para el comentario del scaffold. */
|
|
66
|
+
readonly warning?: string;
|
|
67
|
+
}
|
|
68
|
+
interface ScalarMapping {
|
|
69
|
+
readonly field: FieldType;
|
|
70
|
+
readonly format: FieldFormat;
|
|
71
|
+
readonly zod: (field: FieldMetadata, locale: Locale) => z.ZodTypeAny;
|
|
72
|
+
readonly dto: (value: unknown) => unknown;
|
|
73
|
+
readonly toDb: (value: unknown) => unknown;
|
|
74
|
+
readonly column?: boolean;
|
|
75
|
+
readonly editable?: boolean;
|
|
76
|
+
readonly warning?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Mapping by Prisma scalar type.
|
|
80
|
+
*
|
|
81
|
+
* Rules that are not in the table because they do not depend on the type (see
|
|
82
|
+
* `resolveFieldMapping`): `@id`, `@updatedAt`, `@db.Text`, `@db.Date`,
|
|
83
|
+
* `@db.Uuid`, lists and read-only fields.
|
|
84
|
+
*/
|
|
85
|
+
export declare const SCALAR_MAPPINGS: Readonly<Record<ScalarKind, ScalarMapping>>;
|
|
86
|
+
/**
|
|
87
|
+
* Resolves a DMMF field to its full mapping.
|
|
88
|
+
*
|
|
89
|
+
* It never throws: generation is total (Architecture §10.1). An unknown type
|
|
90
|
+
* type resolves to an editable text field with a warning, not an error.
|
|
91
|
+
*/
|
|
92
|
+
export declare function resolveFieldMapping(field: FieldMetadata, context?: MappingContext): ResolvedFieldMapping;
|
|
93
|
+
/**
|
|
94
|
+
* Applies the presence the operation requires:
|
|
95
|
+
*
|
|
96
|
+
* - `update`: everything is optional (partial update).
|
|
97
|
+
* - `create`: nullable if the field is not required; optional if it has
|
|
98
|
+
* `@default`, because the database fills it.
|
|
99
|
+
*/
|
|
100
|
+
export declare function buildFieldSchema(mapping: ResolvedFieldMapping, field: FieldMetadata, operation: Operation): z.ZodTypeAny;
|
|
101
|
+
/**
|
|
102
|
+
* Builds the schema for a full object (form row).
|
|
103
|
+
*
|
|
104
|
+
* It is the function the server uses as authority and the client uses for UX.
|
|
105
|
+
* Same code, two calls.
|
|
106
|
+
*/
|
|
107
|
+
export declare function buildObjectSchema(fields: readonly FieldMetadata[], context: MappingContext, operation: Operation): z.ZodObject<Record<string, z.ZodTypeAny>>;
|
|
108
|
+
export {};
|
|
109
|
+
//# sourceMappingURL=mapping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../src/mapping.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAa,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAMvD;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GACnB,MAAM,GACN,OAAO,GACP,QAAQ,GACR,UAAU,GACV,MAAM,GACN,UAAU,GACV,MAAM,CAAC;AAEX,sCAAsC;AACtC,MAAM,MAAM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