plug-code 1.1.1 → 1.1.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/README.md +2 -2
- package/package.json +1 -1
- package/src/core/plcAPI.tsx +7 -7
- package/types/plug-code.d.ts +2 -2
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ import { createPlugAndCode } from 'plug-code';
|
|
|
41
41
|
export const { useSystemPlc, SystemPlcRoot } = createPlugAndCode((api) => {
|
|
42
42
|
|
|
43
43
|
// Define a Sales Feature
|
|
44
|
-
api.
|
|
44
|
+
api.createFuture("sales", (api) => {
|
|
45
45
|
// Register a UI component into a slot
|
|
46
46
|
api.register("header.cart", () => <CartIcon />);
|
|
47
47
|
|
|
@@ -53,7 +53,7 @@ export const { useSystemPlc, SystemPlcRoot } = createPlugAndCode((api) => {
|
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
// Define a Logger Feature that wraps existing logic
|
|
56
|
-
api.
|
|
56
|
+
api.createFuture("logger", (api) => {
|
|
57
57
|
api.wrapCommand("sales.checkout", (next) => async (items) => {
|
|
58
58
|
console.log("Checkout started...");
|
|
59
59
|
const result = await next(items);
|
package/package.json
CHANGED
package/src/core/plcAPI.tsx
CHANGED
|
@@ -37,7 +37,7 @@ export class PlcAPI<S extends ObjectType> {
|
|
|
37
37
|
|
|
38
38
|
createFeature(name: string, setupFn: (api: PlcAPI<S>) => void): PlcAPI<S> {
|
|
39
39
|
if (this.installedFeatures.has(name)) {
|
|
40
|
-
console.warn(`[PlcFramework]
|
|
40
|
+
console.warn(`[PlcFramework] Feature '${name}' is already registered. It will be skipped to avoid conflicts.`);
|
|
41
41
|
return this;
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -45,7 +45,7 @@ export class PlcAPI<S extends ObjectType> {
|
|
|
45
45
|
setupFn(this);
|
|
46
46
|
this.installedFeatures.add(name);
|
|
47
47
|
} catch (error) {
|
|
48
|
-
console.error(`[PlcFramework] 💥
|
|
48
|
+
console.error(`[PlcFramework] 💥 Critical error initializing feature '${name}':`, error);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
return this;
|
|
@@ -187,7 +187,7 @@ export class PlcAPI<S extends ObjectType> {
|
|
|
187
187
|
try {
|
|
188
188
|
currentData = transformer.fn(currentData, context);
|
|
189
189
|
} catch (error) {
|
|
190
|
-
console.error(`[PlcAPI] Error
|
|
190
|
+
console.error(`[PlcAPI] Error in transform '${channel as string}/${transformer.id}':`, error);
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
|
|
@@ -199,7 +199,7 @@ export class PlcAPI<S extends ObjectType> {
|
|
|
199
199
|
fn: CommandFn<CommandPayload<K>, CommandResult<K>>
|
|
200
200
|
) {
|
|
201
201
|
if (this.commands.has(id as string)) {
|
|
202
|
-
console.warn(`[PlcAPI]
|
|
202
|
+
console.warn(`[PlcAPI] Overwriting command '${id as string}'`);
|
|
203
203
|
}
|
|
204
204
|
this.commands.set(id as string, fn as any);
|
|
205
205
|
}
|
|
@@ -210,7 +210,7 @@ export class PlcAPI<S extends ObjectType> {
|
|
|
210
210
|
) {
|
|
211
211
|
const currentFn = this.commands.get(id as string);
|
|
212
212
|
if (!currentFn) {
|
|
213
|
-
console.error(`[PlcAPI]
|
|
213
|
+
console.error(`[PlcAPI] Cannot wrap '${id as string}', command does not exist.`);
|
|
214
214
|
return;
|
|
215
215
|
}
|
|
216
216
|
this.commands.set(id as string, wrapper(currentFn) as any);
|
|
@@ -222,13 +222,13 @@ export class PlcAPI<S extends ObjectType> {
|
|
|
222
222
|
): Promise<CommandResult<K>> {
|
|
223
223
|
const fn = this.commands.get(id as string);
|
|
224
224
|
if (!fn) {
|
|
225
|
-
throw new Error(`[PlcAPI]
|
|
225
|
+
throw new Error(`[PlcAPI] Command '${id as string}' not found.`);
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
try {
|
|
229
229
|
return await fn(payload);
|
|
230
230
|
} catch (error) {
|
|
231
|
-
console.error(`[PlcAPI] Error
|
|
231
|
+
console.error(`[PlcAPI] Error executing '${id as string}':`, error);
|
|
232
232
|
throw error;
|
|
233
233
|
}
|
|
234
234
|
}
|
package/types/plug-code.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import * as React from 'react';
|
|
|
4
4
|
// Tipos Generales
|
|
5
5
|
// ==========================================
|
|
6
6
|
|
|
7
|
-
export type ObjectType = Record<string, any>;
|
|
7
|
+
export declare type ObjectType = Record<string, any>;
|
|
8
8
|
|
|
9
9
|
export type Slot = () => React.ReactNode;
|
|
10
10
|
|
|
@@ -52,7 +52,7 @@ export declare class PlcAPI<S extends ObjectType> {
|
|
|
52
52
|
* @param name Identificador único para debugging y prevención de duplicados.
|
|
53
53
|
* @param setupFn Función de configuración donde registras slots, comandos, etc.
|
|
54
54
|
*/
|
|
55
|
-
|
|
55
|
+
createFuture(name: string, setupFn: (api: PlcAPI<S>) => void): PlcAPI<S>;
|
|
56
56
|
|
|
57
57
|
// --- Gestión de UI (Slots & Rendering) ---
|
|
58
58
|
|