@nano-app/frontend 0.3.1 → 0.3.3
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/bin/generate-stores.mjs +128 -0
- package/dist/auto-register.d.ts +6 -0
- package/dist/auto-register.js +9 -0
- package/dist/auto-register.mjs +310 -0
- package/dist/auto-register.ts +336 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +12 -2
- package/dist/state/RenderManager.d.ts +47 -0
- package/dist/state/RenderManager.js +78 -0
- package/dist/store/{ApiClient.d.ts → ApiStore.d.ts} +4 -3
- package/dist/store/{ApiClient.js → ApiStore.js} +10 -10
- package/dist/store/AppStore.d.ts +25 -0
- package/dist/store/AppStore.js +59 -0
- package/dist/store/RenderManager.d.ts +47 -0
- package/dist/store/RenderManager.js +78 -0
- package/dist/store/StateManager.d.ts +4 -0
- package/dist/store/StateManager.js +10 -0
- package/dist/store/StoreManager.d.ts +8 -9
- package/dist/store/StoreManager.js +14 -28
- package/dist/store/stores.d.ts +6 -0
- package/dist/store/stores.js +9 -0
- package/dist/ui/Controller.d.ts +13 -14
- package/dist/ui/Controller.js +41 -8
- package/dist/ui/createComponent.d.ts +17 -4
- package/dist/ui/createComponent.js +25 -18
- package/dist/utils/pathUtils.d.ts +14 -0
- package/dist/utils/pathUtils.js +43 -0
- package/package.json +8 -6
- package/dist/api/ApiClient.d.ts +0 -16
- package/dist/api/ApiClient.js +0 -69
- package/dist/api/QueryBuilder.d.ts +0 -8
- package/dist/api/QueryBuilder.js +0 -51
- package/dist/components/Controller.d.ts +0 -16
- package/dist/components/Controller.js +0 -29
- package/dist/config/index.d.ts +0 -21
- package/dist/config/index.js +0 -10
- package/dist/hooks/useComponent.d.ts +0 -8
- package/dist/hooks/useComponent.js +0 -10
- package/dist/plugin/index.d.ts +0 -11
- package/dist/plugin/index.js +0 -134
- package/dist/store/StoreClient.d.ts +0 -11
- package/dist/store/StoreClient.js +0 -40
- package/dist/store/bootstrapApp.d.ts +0 -19
- package/dist/store/bootstrapApp.js +0 -25
- package/dist/store/setStores.d.ts +0 -8
- package/dist/store/setStores.js +0 -23
- package/dist/types/api.d.ts +0 -7
- package/dist/types/api.js +0 -2
- package/dist/ui/Component.d.ts +0 -4
- package/dist/ui/Component.js +0 -49
- package/dist/ui/StoreProvider.d.ts +0 -18
- package/dist/ui/StoreProvider.js +0 -62
- package/dist/ui/defineController.d.ts +0 -23
- package/dist/ui/defineController.js +0 -14
- package/dist/ui/defineView.d.ts +0 -3
- package/dist/ui/defineView.js +0 -44
- package/dist/ui/definers.d.ts +0 -1
- package/dist/ui/definers.js +0 -59
- package/dist/ui/useComponent.d.ts +0 -2
- package/dist/ui/useComponent.js +0 -9
package/dist/config/index.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export type LocalStoreEntry = {
|
|
2
|
-
type: "local";
|
|
3
|
-
/** Path relativo a la raíz del proyecto. Ej: "src/models/app.json" */
|
|
4
|
-
path?: string;
|
|
5
|
-
/** Datos inline (alternativa a path) */
|
|
6
|
-
data?: Record<string, any>;
|
|
7
|
-
};
|
|
8
|
-
export type ApiStoreEntry = {
|
|
9
|
-
type: "api";
|
|
10
|
-
/** Prefijo base para todas las peticiones de este store. Ej: "/api/users" */
|
|
11
|
-
baseUrl?: string;
|
|
12
|
-
};
|
|
13
|
-
export type StoreEntry = LocalStoreEntry | ApiStoreEntry;
|
|
14
|
-
export type NanoAppConfig = {
|
|
15
|
-
stores: Record<string, StoreEntry>;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Define la configuración del paquete con tipado completo.
|
|
19
|
-
* Usar en nano-app.config.ts en la raíz del proyecto.
|
|
20
|
-
*/
|
|
21
|
-
export declare function defineConfig(config: NanoAppConfig): NanoAppConfig;
|
package/dist/config/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defineConfig = defineConfig;
|
|
4
|
-
/**
|
|
5
|
-
* Define la configuración del paquete con tipado completo.
|
|
6
|
-
* Usar en nano-app.config.ts en la raíz del proyecto.
|
|
7
|
-
*/
|
|
8
|
-
function defineConfig(config) {
|
|
9
|
-
return config;
|
|
10
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Controller } from "../components/Controller";
|
|
2
|
-
type useComponentParams<CI> = {
|
|
3
|
-
controller: new () => CI;
|
|
4
|
-
view: (controller: CI) => React.ReactNode;
|
|
5
|
-
};
|
|
6
|
-
export type useComponent = <CI extends Controller>(p: useComponentParams<CI>) => (params?: Object) => React.ReactNode;
|
|
7
|
-
export declare const useComponent: useComponent;
|
|
8
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useComponent = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const useComponent = ({ controller, view }) => (params = {}) => {
|
|
6
|
-
const c = (0, react_1.useMemo)(() => new controller(), [controller]);
|
|
7
|
-
c.render(params);
|
|
8
|
-
return (0, react_1.useMemo)(() => view(c), c.deps());
|
|
9
|
-
};
|
|
10
|
-
exports.useComponent = useComponent;
|
package/dist/plugin/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
type NextConfig = Record<string, any>;
|
|
2
|
-
/**
|
|
3
|
-
* Envuelve la configuración de Next.js agregando el plugin de nano-app.
|
|
4
|
-
* Usar en next.config.ts:
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* import { withNanoApp } from "@nano-app/frontend/plugin";
|
|
8
|
-
* export default withNanoApp();
|
|
9
|
-
*/
|
|
10
|
-
export declare function withNanoApp(nextConfig?: NextConfig): NextConfig;
|
|
11
|
-
export {};
|
package/dist/plugin/index.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.withNanoApp = withNanoApp;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const VIRTUAL_MODULE_ID = "@nano-app/stores";
|
|
10
|
-
const RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`;
|
|
11
|
-
/**
|
|
12
|
-
* Lee nano-app.config.ts desde la raíz del proyecto usando jiti
|
|
13
|
-
* para poder ejecutar TypeScript en Node.js sin compilar.
|
|
14
|
-
*/
|
|
15
|
-
function loadConfig(projectRoot) {
|
|
16
|
-
const configPath = path_1.default.join(projectRoot, "nano-app.config.ts");
|
|
17
|
-
if (!fs_1.default.existsSync(configPath)) {
|
|
18
|
-
throw new Error(`[nano-app] No se encontró nano-app.config.ts en ${projectRoot}`);
|
|
19
|
-
}
|
|
20
|
-
// jiti permite ejecutar TS directamente en Node.js (lo usa Next.js internamente)
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
22
|
-
const jiti = require("jiti")(projectRoot, { interopDefault: true });
|
|
23
|
-
return jiti(configPath);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Resuelve los stores del config: lee los JSONs de los paths indicados
|
|
27
|
-
* y devuelve un mapa con todos los datos ya inlineados.
|
|
28
|
-
*/
|
|
29
|
-
function resolveStores(config, projectRoot) {
|
|
30
|
-
const resolved = {};
|
|
31
|
-
Object.entries(config.stores).forEach(([name, entry]) => {
|
|
32
|
-
if (entry.type === "local") {
|
|
33
|
-
if (entry.path) {
|
|
34
|
-
const filePath = path_1.default.join(projectRoot, entry.path);
|
|
35
|
-
if (!fs_1.default.existsSync(filePath)) {
|
|
36
|
-
throw new Error(`[nano-app] Store "${name}": no se encontró el archivo ${filePath}`);
|
|
37
|
-
}
|
|
38
|
-
const raw = fs_1.default.readFileSync(filePath, "utf-8");
|
|
39
|
-
resolved[name] = { type: "local", data: JSON.parse(raw) };
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
resolved[name] = { type: "local", data: entry.data ?? {} };
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
else if (entry.type === "api") {
|
|
46
|
-
resolved[name] = { type: "api", baseUrl: entry.baseUrl ?? "/api" };
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
return resolved;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Genera el código del módulo virtual "@nano-app/stores"
|
|
53
|
-
* con todos los stores ya resueltos y serializados.
|
|
54
|
-
*/
|
|
55
|
-
function generateVirtualModule(stores) {
|
|
56
|
-
return `export const stores = ${JSON.stringify(stores, null, 2)};`;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Plugin de Webpack que:
|
|
60
|
-
* 1. Lee nano-app.config.ts en build time
|
|
61
|
-
* 2. Resuelve los paths a JSONs
|
|
62
|
-
* 3. Inyecta un módulo virtual "@nano-app/stores" con todos los datos
|
|
63
|
-
*/
|
|
64
|
-
class NanoAppPlugin {
|
|
65
|
-
projectRoot;
|
|
66
|
-
constructor(projectRoot) {
|
|
67
|
-
this.projectRoot = projectRoot;
|
|
68
|
-
}
|
|
69
|
-
apply(compiler) {
|
|
70
|
-
const pluginName = "NanoAppPlugin";
|
|
71
|
-
const projectRoot = this.projectRoot;
|
|
72
|
-
compiler.hooks.normalModuleFactory.tap(pluginName, (factory) => {
|
|
73
|
-
factory.hooks.resolve.tap(pluginName, (resolveData) => {
|
|
74
|
-
if (resolveData.request === VIRTUAL_MODULE_ID) {
|
|
75
|
-
resolveData.request = RESOLVED_VIRTUAL_MODULE_ID;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
compiler.hooks.compilation.tap(pluginName, (compilation) => {
|
|
80
|
-
compilation.hooks.normalModuleLoader.tap(pluginName, (_, module) => {
|
|
81
|
-
if (module.resource === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
82
|
-
module.loaders = [];
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
// Resuelve el módulo virtual a código generado
|
|
87
|
-
compiler.resolverFactory.hooks.resolver
|
|
88
|
-
.for("normal")
|
|
89
|
-
.tap(pluginName, (resolver) => {
|
|
90
|
-
resolver.hooks.resolve.tapAsync(pluginName, (request, resolveContext, callback) => {
|
|
91
|
-
if (request.request === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
92
|
-
const config = loadConfig(projectRoot);
|
|
93
|
-
const stores = resolveStores(config, projectRoot);
|
|
94
|
-
const code = generateVirtualModule(stores);
|
|
95
|
-
return callback(null, {
|
|
96
|
-
path: RESOLVED_VIRTUAL_MODULE_ID,
|
|
97
|
-
query: "",
|
|
98
|
-
file: true,
|
|
99
|
-
module: true,
|
|
100
|
-
source: code,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
callback();
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Envuelve la configuración de Next.js agregando el plugin de nano-app.
|
|
110
|
-
* Usar en next.config.ts:
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* import { withNanoApp } from "@nano-app/frontend/plugin";
|
|
114
|
-
* export default withNanoApp();
|
|
115
|
-
*/
|
|
116
|
-
function withNanoApp(nextConfig = {}) {
|
|
117
|
-
return {
|
|
118
|
-
...nextConfig,
|
|
119
|
-
webpack(config, options) {
|
|
120
|
-
const projectRoot = options.dir ?? process.cwd();
|
|
121
|
-
// Módulo virtual para los stores resueltos
|
|
122
|
-
config.plugins.push(new NanoAppPlugin(projectRoot));
|
|
123
|
-
// Resuelve symlinks relativos a la app consumidora (necesario para file: links)
|
|
124
|
-
config.resolve.symlinks = false;
|
|
125
|
-
// Permite que el módulo virtual sea importado
|
|
126
|
-
config.resolve.alias = {
|
|
127
|
-
...config.resolve.alias,
|
|
128
|
-
[VIRTUAL_MODULE_ID]: RESOLVED_VIRTUAL_MODULE_ID,
|
|
129
|
-
};
|
|
130
|
-
// Encadena con el webpack config del usuario si existe
|
|
131
|
-
return nextConfig.webpack?.(config, options) ?? config;
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type StoreData = Record<string, any>;
|
|
2
|
-
export declare class StoreClient {
|
|
3
|
-
private getStore;
|
|
4
|
-
private setFn;
|
|
5
|
-
private getFn;
|
|
6
|
-
constructor(initialData?: StoreData);
|
|
7
|
-
use: () => StoreData;
|
|
8
|
-
set(path: string, value: any): void;
|
|
9
|
-
get(path: string): any;
|
|
10
|
-
private manageState;
|
|
11
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StoreClient = void 0;
|
|
4
|
-
const zustand_1 = require("zustand");
|
|
5
|
-
class StoreClient {
|
|
6
|
-
getStore;
|
|
7
|
-
setFn;
|
|
8
|
-
getFn;
|
|
9
|
-
constructor(initialData = {}) {
|
|
10
|
-
this.getStore = (0, zustand_1.create)()((set, get) => {
|
|
11
|
-
this.setFn = set;
|
|
12
|
-
this.getFn = get;
|
|
13
|
-
return initialData;
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
use = () => this.getStore();
|
|
17
|
-
set(path, value) {
|
|
18
|
-
const { oNewState } = this.manageState(path, true, value);
|
|
19
|
-
this.setFn((state) => ({ ...state, ...oNewState }));
|
|
20
|
-
}
|
|
21
|
-
get(path) {
|
|
22
|
-
const { value } = this.manageState(path);
|
|
23
|
-
return value;
|
|
24
|
-
}
|
|
25
|
-
manageState(sPath, isSet = false, value) {
|
|
26
|
-
const aPath = sPath.split("/").filter(s => s !== "");
|
|
27
|
-
const lastProp = aPath.pop() || "";
|
|
28
|
-
const oNewState = aPath.length === 0
|
|
29
|
-
? this.getFn()
|
|
30
|
-
: aPath.reduce((oObject, sKey) => {
|
|
31
|
-
if (!oObject[sKey])
|
|
32
|
-
oObject[sKey] = {};
|
|
33
|
-
return oObject[sKey];
|
|
34
|
-
}, this.getFn());
|
|
35
|
-
if (isSet)
|
|
36
|
-
oNewState[lastProp] = value;
|
|
37
|
-
return { oNewState, value: lastProp ? oNewState[lastProp] : oNewState };
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.StoreClient = StoreClient;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { StoreData } from "./StoreClient";
|
|
2
|
-
export type StoreManifestEntry = {
|
|
3
|
-
type: "local" | string;
|
|
4
|
-
data: StoreData;
|
|
5
|
-
} | {
|
|
6
|
-
type: "api" | string;
|
|
7
|
-
baseUrl?: string;
|
|
8
|
-
data?: never;
|
|
9
|
-
};
|
|
10
|
-
export type AppManifest = {
|
|
11
|
-
stores: Record<string, StoreManifestEntry>;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Lee el manifest y registra todos los stores en el StoreManager.
|
|
15
|
-
* Debe llamarse una sola vez en el layout raíz de la app.
|
|
16
|
-
*/
|
|
17
|
-
export declare function bootstrapApp(manifest: {
|
|
18
|
-
stores: Record<string, any>;
|
|
19
|
-
}): void;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.bootstrapApp = bootstrapApp;
|
|
7
|
-
const ApiClient_1 = require("../api/ApiClient");
|
|
8
|
-
const StoreClient_1 = require("./StoreClient");
|
|
9
|
-
const StoreManager_1 = __importDefault(require("./StoreManager"));
|
|
10
|
-
/**
|
|
11
|
-
* Lee el manifest y registra todos los stores en el StoreManager.
|
|
12
|
-
* Debe llamarse una sola vez en el layout raíz de la app.
|
|
13
|
-
*/
|
|
14
|
-
function bootstrapApp(manifest) {
|
|
15
|
-
const { stores } = manifest;
|
|
16
|
-
Object.entries(stores).forEach(([name, config]) => {
|
|
17
|
-
if (config.type === "api") {
|
|
18
|
-
StoreManager_1.default.addStore(name, new ApiClient_1.ApiClient());
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
// type: "local" o cualquier otro — usa los datos provistos
|
|
22
|
-
StoreManager_1.default.addStore(name, new StoreClient_1.StoreClient(config.data ?? {}));
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ApiClient } from "../api/ApiClient";
|
|
2
|
-
import { StoreClient, StoreData } from "./StoreClient";
|
|
3
|
-
export type storesConfig = {
|
|
4
|
-
appData?: StoreData;
|
|
5
|
-
apiData?: StoreData;
|
|
6
|
-
stores: Record<string, ApiClient | StoreClient>;
|
|
7
|
-
};
|
|
8
|
-
export declare function setStores({ stores, appData, apiData }: storesConfig): void;
|
package/dist/store/setStores.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.setStores = setStores;
|
|
7
|
-
const ApiClient_1 = require("../api/ApiClient");
|
|
8
|
-
const StoreClient_1 = require("./StoreClient");
|
|
9
|
-
const StoreManager_1 = __importDefault(require("./StoreManager"));
|
|
10
|
-
function setStores({ stores, appData, apiData }) {
|
|
11
|
-
// Agrega los stores pasados
|
|
12
|
-
Object.entries(stores)
|
|
13
|
-
.forEach(([model, store]) => {
|
|
14
|
-
StoreManager_1.default.addStore(model, store);
|
|
15
|
-
});
|
|
16
|
-
// Inicializa la info del app y api stores
|
|
17
|
-
if (appData) {
|
|
18
|
-
StoreManager_1.default.addStore("app", new StoreClient_1.StoreClient(appData));
|
|
19
|
-
}
|
|
20
|
-
if (apiData) {
|
|
21
|
-
StoreManager_1.default.addStore("api", new ApiClient_1.ApiClient(apiData));
|
|
22
|
-
}
|
|
23
|
-
}
|
package/dist/types/api.d.ts
DELETED
package/dist/types/api.js
DELETED
package/dist/ui/Component.d.ts
DELETED
package/dist/ui/Component.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.Component = void 0;
|
|
37
|
-
class Component {
|
|
38
|
-
method = () => { };
|
|
39
|
-
// Importa dinámicamente el archivo especificado en path
|
|
40
|
-
constructor(path) {
|
|
41
|
-
Promise.resolve(`${path}`).then(s => __importStar(require(s))).then((module) => {
|
|
42
|
-
this.method = module.default;
|
|
43
|
-
})
|
|
44
|
-
.catch((error) => {
|
|
45
|
-
throw `Error importing module at ${path}: ${error}`;
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.Component = Component;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
type ResolvedStore = {
|
|
3
|
-
type: "local";
|
|
4
|
-
data: Record<string, any>;
|
|
5
|
-
} | {
|
|
6
|
-
type: "api";
|
|
7
|
-
baseUrl?: string;
|
|
8
|
-
};
|
|
9
|
-
type StoreProviderProps = {
|
|
10
|
-
stores: Record<string, ResolvedStore>;
|
|
11
|
-
children: React.ReactNode;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Inicializa los stores definidos en nano-app.config.ts (resueltos por el plugin)
|
|
15
|
-
* y los registra en el StoreManager. Debe envolver toda la app en el layout raíz.
|
|
16
|
-
*/
|
|
17
|
-
export declare function StoreProvider({ stores, children }: StoreProviderProps): React.JSX.Element;
|
|
18
|
-
export {};
|
package/dist/ui/StoreProvider.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.StoreProvider = StoreProvider;
|
|
40
|
-
const react_1 = __importStar(require("react"));
|
|
41
|
-
const ApiClient_1 = require("../api/ApiClient");
|
|
42
|
-
const StoreClient_1 = require("../store/StoreClient");
|
|
43
|
-
const StoreManager_1 = __importDefault(require("../store/StoreManager"));
|
|
44
|
-
/**
|
|
45
|
-
* Inicializa los stores definidos en nano-app.config.ts (resueltos por el plugin)
|
|
46
|
-
* y los registra en el StoreManager. Debe envolver toda la app en el layout raíz.
|
|
47
|
-
*/
|
|
48
|
-
function StoreProvider({ stores, children }) {
|
|
49
|
-
const initialized = (0, react_1.useRef)(false);
|
|
50
|
-
if (!initialized.current) {
|
|
51
|
-
initialized.current = true;
|
|
52
|
-
Object.entries(stores).forEach(([name, entry]) => {
|
|
53
|
-
if (entry.type === "api") {
|
|
54
|
-
StoreManager_1.default.addStore(name, new ApiClient_1.ApiClient(entry.baseUrl ?? "/api"));
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
StoreManager_1.default.addStore(name, new StoreClient_1.StoreClient(entry.data ?? {}));
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
return react_1.default.createElement(react_1.default.Fragment, null, children);
|
|
62
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ApiClient } from "../api/ApiClient";
|
|
2
|
-
import { StoreClient } from "../store/StoreClient";
|
|
3
|
-
export type ControllerStores = Record<string, ApiClient | StoreClient>;
|
|
4
|
-
/** Contexto disponible en onInit, onRender y todos los métodos */
|
|
5
|
-
export type ControllerContext = {
|
|
6
|
-
store: ControllerStores;
|
|
7
|
-
params: Record<string, any>;
|
|
8
|
-
};
|
|
9
|
-
export type ControllerSetup<T extends Record<string, any>> = (ctx: ControllerContext) => T;
|
|
10
|
-
export type ControllerDescriptor<T extends Record<string, any>> = {
|
|
11
|
-
_isDescriptor: true;
|
|
12
|
-
stores: string[];
|
|
13
|
-
setup: ControllerSetup<T>;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Define la lógica de un componente.
|
|
17
|
-
*
|
|
18
|
-
* @param stores - Nombres de los stores a los que se suscribe el componente.
|
|
19
|
-
* @param setup - Función que recibe el contexto (store, params) y retorna
|
|
20
|
-
* un objeto con propiedades y métodos expuestos a la view.
|
|
21
|
-
* Se ejecuta una sola vez al montar el componente.
|
|
22
|
-
*/
|
|
23
|
-
export declare function defineController<T extends Record<string, any>>(stores: string[], setup: ControllerSetup<T>): ControllerDescriptor<T>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defineController = defineController;
|
|
4
|
-
/**
|
|
5
|
-
* Define la lógica de un componente.
|
|
6
|
-
*
|
|
7
|
-
* @param stores - Nombres de los stores a los que se suscribe el componente.
|
|
8
|
-
* @param setup - Función que recibe el contexto (store, params) y retorna
|
|
9
|
-
* un objeto con propiedades y métodos expuestos a la view.
|
|
10
|
-
* Se ejecuta una sola vez al montar el componente.
|
|
11
|
-
*/
|
|
12
|
-
function defineController(stores, setup) {
|
|
13
|
-
return { _isDescriptor: true, stores, setup };
|
|
14
|
-
}
|
package/dist/ui/defineView.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { Controller } from "./Controller";
|
|
2
|
-
export declare const defineView: (controller: Controller, view: (controller: InstanceType<typeof Controller>) => React.ReactNode) => Promise<() => import("react").ReactNode>;
|
|
3
|
-
export declare const defineComponent: (controllerPath: string, viewPath: string) => Promise<() => any>;
|
package/dist/ui/defineView.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.defineComponent = exports.defineView = void 0;
|
|
37
|
-
const defineView = async (controller, view) => () => view(controller);
|
|
38
|
-
exports.defineView = defineView;
|
|
39
|
-
const defineComponent = async (controllerPath, viewPath) => {
|
|
40
|
-
const controller = (new (await Promise.resolve(`${controllerPath}`).then(s => __importStar(require(s)))).default)();
|
|
41
|
-
const view = await Promise.resolve(`${viewPath}`).then(s => __importStar(require(s)));
|
|
42
|
-
return () => view(controller);
|
|
43
|
-
};
|
|
44
|
-
exports.defineComponent = defineComponent;
|
package/dist/ui/definers.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const defineComponent: (componentName: string) => Promise<string>;
|
package/dist/ui/definers.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.defineComponent = void 0;
|
|
40
|
-
const path_1 = __importDefault(require("path"));
|
|
41
|
-
const controllersPath = path_1.default.join(process.cwd(), "src", "controllers");
|
|
42
|
-
const viewsPath = path_1.default.join(process.cwd(), "src", "views");
|
|
43
|
-
const defineComponent = async (componentName) => {
|
|
44
|
-
try {
|
|
45
|
-
const [ControllerModule, ViewModule] = await Promise.all([
|
|
46
|
-
Promise.resolve(`${path_1.default.join(controllersPath, componentName)}`).then(s => __importStar(require(s))),
|
|
47
|
-
Promise.resolve(`${path_1.default.join(viewsPath, componentName)}`).then(s => __importStar(require(s))),
|
|
48
|
-
]);
|
|
49
|
-
const controller = new ControllerModule.default();
|
|
50
|
-
// console.log(ViewModule.default?.(controller))
|
|
51
|
-
// ViewModule.default?.(controller) ?? null;
|
|
52
|
-
return '';
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
console.error(`[defineComponent] Error loading "${componentName}":`, error);
|
|
56
|
-
return '';
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
exports.defineComponent = defineComponent;
|
package/dist/ui/useComponent.js
DELETED