@constela/core 0.5.0 → 0.6.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/dist/index.d.ts CHANGED
@@ -111,7 +111,14 @@ interface DataExpr {
111
111
  name: string;
112
112
  path?: string;
113
113
  }
114
- type Expression = LitExpr | StateExpr | VarExpr | BinExpr | NotExpr | ParamExpr | CondExpr | GetExpr | RouteExpr | ImportExpr | DataExpr;
114
+ /**
115
+ * Ref expression - references a DOM element by ref name
116
+ */
117
+ interface RefExpr {
118
+ expr: 'ref';
119
+ name: string;
120
+ }
121
+ type Expression = LitExpr | StateExpr | VarExpr | BinExpr | NotExpr | ParamExpr | CondExpr | GetExpr | RouteExpr | ImportExpr | DataExpr | RefExpr;
115
122
  /**
116
123
  * Number state field
117
124
  */
@@ -229,7 +236,46 @@ interface NavigateStep {
229
236
  target?: NavigateTarget;
230
237
  replace?: boolean;
231
238
  }
232
- type ActionStep = SetStep | UpdateStep | FetchStep | StorageStep | ClipboardStep | NavigateStep;
239
+ /**
240
+ * Import step - dynamically imports an external module
241
+ * Module name must be a static string for bundler optimization
242
+ */
243
+ interface ImportStep {
244
+ do: 'import';
245
+ module: string;
246
+ result: string;
247
+ onSuccess?: ActionStep[];
248
+ onError?: ActionStep[];
249
+ }
250
+ /**
251
+ * Call step - calls a function on an external library
252
+ */
253
+ interface CallStep {
254
+ do: 'call';
255
+ target: Expression;
256
+ args?: Expression[];
257
+ result?: string;
258
+ onSuccess?: ActionStep[];
259
+ onError?: ActionStep[];
260
+ }
261
+ /**
262
+ * Subscribe step - subscribes to an event on an object
263
+ * Subscription is auto-collected and disposed on lifecycle.onUnmount
264
+ */
265
+ interface SubscribeStep {
266
+ do: 'subscribe';
267
+ target: Expression;
268
+ event: string;
269
+ action: string;
270
+ }
271
+ /**
272
+ * Dispose step - manually disposes a resource
273
+ */
274
+ interface DisposeStep {
275
+ do: 'dispose';
276
+ target: Expression;
277
+ }
278
+ type ActionStep = SetStep | UpdateStep | FetchStep | StorageStep | ClipboardStep | NavigateStep | ImportStep | CallStep | SubscribeStep | DisposeStep;
233
279
  /**
234
280
  * Event handler - binds an event to an action
235
281
  */
@@ -251,6 +297,7 @@ interface ActionDefinition {
251
297
  interface ElementNode {
252
298
  kind: 'element';
253
299
  tag: string;
300
+ ref?: string;
254
301
  props?: Record<string, Expression | EventHandler>;
255
302
  children?: ViewNode[];
256
303
  }
@@ -470,6 +517,10 @@ declare function isImportExpr(value: unknown): value is ImportExpr;
470
517
  * Checks if value is a data expression
471
518
  */
472
519
  declare function isDataExpr(value: unknown): value is DataExpr;
520
+ /**
521
+ * Checks if value is a ref expression
522
+ */
523
+ declare function isRefExpr(value: unknown): value is RefExpr;
473
524
  /**
474
525
  * Checks if value is a data source
475
526
  */
@@ -546,6 +597,22 @@ declare function isClipboardStep(value: unknown): value is ClipboardStep;
546
597
  * Checks if value is a navigate step
547
598
  */
548
599
  declare function isNavigateStep(value: unknown): value is NavigateStep;
600
+ /**
601
+ * Checks if value is an import step
602
+ */
603
+ declare function isImportStep(value: unknown): value is ImportStep;
604
+ /**
605
+ * Checks if value is a call step
606
+ */
607
+ declare function isCallStep(value: unknown): value is CallStep;
608
+ /**
609
+ * Checks if value is a subscribe step
610
+ */
611
+ declare function isSubscribeStep(value: unknown): value is SubscribeStep;
612
+ /**
613
+ * Checks if value is a dispose step
614
+ */
615
+ declare function isDisposeStep(value: unknown): value is DisposeStep;
549
616
  /**
550
617
  * Checks if value is any valid action step
551
618
  */
@@ -602,7 +669,7 @@ declare function isLifecycleHooks(value: unknown): value is LifecycleHooks;
602
669
  * This module defines error types, the ConstelaError class,
603
670
  * and factory functions for creating specific errors.
604
671
  */
605
- type ErrorCode = 'SCHEMA_INVALID' | 'UNDEFINED_STATE' | 'UNDEFINED_ACTION' | 'VAR_UNDEFINED' | 'DUPLICATE_ACTION' | 'UNSUPPORTED_VERSION' | 'COMPONENT_NOT_FOUND' | 'COMPONENT_PROP_MISSING' | 'COMPONENT_CYCLE' | 'COMPONENT_PROP_TYPE' | 'PARAM_UNDEFINED' | 'OPERATION_INVALID_FOR_TYPE' | 'OPERATION_MISSING_FIELD' | 'OPERATION_UNKNOWN' | 'EXPR_INVALID_BASE' | 'EXPR_INVALID_CONDITION' | 'EXPR_COND_ELSE_REQUIRED' | 'UNDEFINED_ROUTE_PARAM' | 'ROUTE_NOT_DEFINED' | 'UNDEFINED_IMPORT' | 'IMPORTS_NOT_DEFINED' | 'LAYOUT_MISSING_SLOT' | 'LAYOUT_NOT_FOUND' | 'INVALID_SLOT_NAME' | 'DUPLICATE_SLOT_NAME' | 'DUPLICATE_DEFAULT_SLOT' | 'SLOT_IN_LOOP' | 'INVALID_DATA_SOURCE' | 'UNDEFINED_DATA_SOURCE' | 'DATA_NOT_DEFINED' | 'UNDEFINED_DATA' | 'INVALID_STORAGE_OPERATION' | 'INVALID_STORAGE_TYPE' | 'STORAGE_SET_MISSING_VALUE' | 'INVALID_CLIPBOARD_OPERATION' | 'CLIPBOARD_WRITE_MISSING_VALUE' | 'INVALID_NAVIGATE_TARGET';
672
+ type ErrorCode = 'SCHEMA_INVALID' | 'UNDEFINED_STATE' | 'UNDEFINED_ACTION' | 'VAR_UNDEFINED' | 'DUPLICATE_ACTION' | 'UNSUPPORTED_VERSION' | 'COMPONENT_NOT_FOUND' | 'COMPONENT_PROP_MISSING' | 'COMPONENT_CYCLE' | 'COMPONENT_PROP_TYPE' | 'PARAM_UNDEFINED' | 'OPERATION_INVALID_FOR_TYPE' | 'OPERATION_MISSING_FIELD' | 'OPERATION_UNKNOWN' | 'EXPR_INVALID_BASE' | 'EXPR_INVALID_CONDITION' | 'EXPR_COND_ELSE_REQUIRED' | 'UNDEFINED_ROUTE_PARAM' | 'ROUTE_NOT_DEFINED' | 'UNDEFINED_IMPORT' | 'IMPORTS_NOT_DEFINED' | 'LAYOUT_MISSING_SLOT' | 'LAYOUT_NOT_FOUND' | 'INVALID_SLOT_NAME' | 'DUPLICATE_SLOT_NAME' | 'DUPLICATE_DEFAULT_SLOT' | 'SLOT_IN_LOOP' | 'INVALID_DATA_SOURCE' | 'UNDEFINED_DATA_SOURCE' | 'DATA_NOT_DEFINED' | 'UNDEFINED_DATA' | 'UNDEFINED_REF' | 'INVALID_STORAGE_OPERATION' | 'INVALID_STORAGE_TYPE' | 'STORAGE_SET_MISSING_VALUE' | 'INVALID_CLIPBOARD_OPERATION' | 'CLIPBOARD_WRITE_MISSING_VALUE' | 'INVALID_NAVIGATE_TARGET';
606
673
  /**
607
674
  * Custom error class for Constela validation errors
608
675
  */
@@ -739,6 +806,10 @@ declare function createDataNotDefinedError(path?: string): ConstelaError;
739
806
  * Creates an undefined data error (for DataExpr references)
740
807
  */
741
808
  declare function createUndefinedDataError(dataName: string, path?: string): ConstelaError;
809
+ /**
810
+ * Creates an undefined ref error
811
+ */
812
+ declare function createUndefinedRefError(refName: string, path?: string): ConstelaError;
742
813
  /**
743
814
  * Creates an invalid storage operation error
744
815
  */
@@ -1407,4 +1478,4 @@ declare const astSchema: {
1407
1478
  };
1408
1479
  };
1409
1480
 
1410
- export { type ActionDefinition, type ActionStep, BINARY_OPERATORS, type BinExpr, type BinaryOperator, type BooleanField, CLIPBOARD_OPERATIONS, type ClipboardOperation, type ClipboardStep, type CodeNode, type ComponentDef, type ComponentNode, type CondExpr, type ConstelaAst, ConstelaError, type ConstelaProgram, DATA_SOURCE_TYPES, DATA_TRANSFORMS, type DataExpr, type DataSource, type DataSourceType, type DataTransform, type EachNode, type ElementNode, type ErrorCode, type EventHandler, type Expression, type FetchStep, type GetExpr, HTTP_METHODS, type HttpMethod, type IfNode, type ImportExpr, type LayoutProgram, type LifecycleHooks, type ListField, type LitExpr, type MarkdownNode, NAVIGATE_TARGETS, type NavigateStep, type NavigateTarget, type NotExpr, type NumberField, type ObjectField, PARAM_TYPES, type ParamDef, type ParamExpr, type ParamType, type Program, type RouteDefinition, type RouteExpr, STORAGE_OPERATIONS, STORAGE_TYPES, type SetStep, type SlotNode, type StateExpr, type StateField, type StaticPathsDefinition, type StorageOperation, type StorageStep, type StorageType, type StringField, type TextNode, UPDATE_OPERATIONS, type UpdateOperation, type UpdateStep, type ValidationFailure, type ValidationResult, type ValidationSuccess, type VarExpr, type ViewNode, astSchema, createClipboardWriteMissingValueError, createComponentCycleError, createComponentNotFoundError, createComponentPropMissingError, createComponentPropTypeError, createCondElseRequiredError, createDataNotDefinedError, createDuplicateActionError, createDuplicateDefaultSlotError, createDuplicateSlotNameError, createImportsNotDefinedError, createInvalidClipboardOperationError, createInvalidDataSourceError, createInvalidNavigateTargetError, createInvalidSlotNameError, createInvalidStorageOperationError, createInvalidStorageTypeError, createLayoutMissingSlotError, createLayoutNotFoundError, createOperationInvalidForTypeError, createOperationMissingFieldError, createOperationUnknownError, createRouteNotDefinedError, createSchemaError, createSlotInLoopError, createStorageSetMissingValueError, createUndefinedActionError, createUndefinedDataError, createUndefinedDataSourceError, createUndefinedImportError, createUndefinedParamError, createUndefinedRouteParamError, createUndefinedStateError, createUndefinedVarError, createUnsupportedVersionError, isActionStep, isBinExpr, isBooleanField, isClipboardStep, isCodeNode, isComponentNode, isCondExpr, isConstelaError, isDataExpr, isDataSource, isEachNode, isElementNode, isEventHandler, isExpression, isFetchStep, isGetExpr, isIfNode, isImportExpr, isLayoutProgram, isLifecycleHooks, isListField, isLitExpr, isMarkdownNode, isNamedSlotNode, isNavigateStep, isNotExpr, isNumberField, isObjectField, isParamExpr, isRouteDefinition, isRouteExpr, isSetStep, isSlotNode, isStateExpr, isStateField, isStaticPathsDefinition, isStorageStep, isStringField, isTextNode, isUpdateStep, isVarExpr, isViewNode, validateAst };
1481
+ export { type ActionDefinition, type ActionStep, BINARY_OPERATORS, type BinExpr, type BinaryOperator, type BooleanField, CLIPBOARD_OPERATIONS, type CallStep, type ClipboardOperation, type ClipboardStep, type CodeNode, type ComponentDef, type ComponentNode, type CondExpr, type ConstelaAst, ConstelaError, type ConstelaProgram, DATA_SOURCE_TYPES, DATA_TRANSFORMS, type DataExpr, type DataSource, type DataSourceType, type DataTransform, type DisposeStep, type EachNode, type ElementNode, type ErrorCode, type EventHandler, type Expression, type FetchStep, type GetExpr, HTTP_METHODS, type HttpMethod, type IfNode, type ImportExpr, type ImportStep, type LayoutProgram, type LifecycleHooks, type ListField, type LitExpr, type MarkdownNode, NAVIGATE_TARGETS, type NavigateStep, type NavigateTarget, type NotExpr, type NumberField, type ObjectField, PARAM_TYPES, type ParamDef, type ParamExpr, type ParamType, type Program, type RefExpr, type RouteDefinition, type RouteExpr, STORAGE_OPERATIONS, STORAGE_TYPES, type SetStep, type SlotNode, type StateExpr, type StateField, type StaticPathsDefinition, type StorageOperation, type StorageStep, type StorageType, type StringField, type SubscribeStep, type TextNode, UPDATE_OPERATIONS, type UpdateOperation, type UpdateStep, type ValidationFailure, type ValidationResult, type ValidationSuccess, type VarExpr, type ViewNode, astSchema, createClipboardWriteMissingValueError, createComponentCycleError, createComponentNotFoundError, createComponentPropMissingError, createComponentPropTypeError, createCondElseRequiredError, createDataNotDefinedError, createDuplicateActionError, createDuplicateDefaultSlotError, createDuplicateSlotNameError, createImportsNotDefinedError, createInvalidClipboardOperationError, createInvalidDataSourceError, createInvalidNavigateTargetError, createInvalidSlotNameError, createInvalidStorageOperationError, createInvalidStorageTypeError, createLayoutMissingSlotError, createLayoutNotFoundError, createOperationInvalidForTypeError, createOperationMissingFieldError, createOperationUnknownError, createRouteNotDefinedError, createSchemaError, createSlotInLoopError, createStorageSetMissingValueError, createUndefinedActionError, createUndefinedDataError, createUndefinedDataSourceError, createUndefinedImportError, createUndefinedParamError, createUndefinedRefError, createUndefinedRouteParamError, createUndefinedStateError, createUndefinedVarError, createUnsupportedVersionError, isActionStep, isBinExpr, isBooleanField, isCallStep, isClipboardStep, isCodeNode, isComponentNode, isCondExpr, isConstelaError, isDataExpr, isDataSource, isDisposeStep, isEachNode, isElementNode, isEventHandler, isExpression, isFetchStep, isGetExpr, isIfNode, isImportExpr, isImportStep, isLayoutProgram, isLifecycleHooks, isListField, isLitExpr, isMarkdownNode, isNamedSlotNode, isNavigateStep, isNotExpr, isNumberField, isObjectField, isParamExpr, isRefExpr, isRouteDefinition, isRouteExpr, isSetStep, isSlotNode, isStateExpr, isStateField, isStaticPathsDefinition, isStorageStep, isStringField, isSubscribeStep, isTextNode, isUpdateStep, isVarExpr, isViewNode, validateAst };
package/dist/index.js CHANGED
@@ -118,6 +118,11 @@ function isDataExpr(value) {
118
118
  }
119
119
  return true;
120
120
  }
121
+ function isRefExpr(value) {
122
+ if (!isObject(value)) return false;
123
+ if (value["expr"] !== "ref") return false;
124
+ return typeof value["name"] === "string";
125
+ }
121
126
  function isDataSource(value) {
122
127
  if (!isObject(value)) return false;
123
128
  const type = value["type"];
@@ -154,7 +159,7 @@ function isRouteDefinition(value) {
154
159
  return true;
155
160
  }
156
161
  function isExpression(value) {
157
- return isLitExpr(value) || isStateExpr(value) || isVarExpr(value) || isBinExpr(value) || isNotExpr(value) || isParamExpr(value) || isCondExpr(value) || isGetExpr(value) || isRouteExpr(value) || isImportExpr(value) || isDataExpr(value);
162
+ return isLitExpr(value) || isStateExpr(value) || isVarExpr(value) || isBinExpr(value) || isNotExpr(value) || isParamExpr(value) || isCondExpr(value) || isGetExpr(value) || isRouteExpr(value) || isImportExpr(value) || isDataExpr(value) || isRefExpr(value);
158
163
  }
159
164
  function isElementNode(value) {
160
165
  if (!isObject(value)) return false;
@@ -270,8 +275,35 @@ function isNavigateStep(value) {
270
275
  }
271
276
  return true;
272
277
  }
278
+ function isImportStep(value) {
279
+ if (!isObject(value)) return false;
280
+ if (value["do"] !== "import") return false;
281
+ if (typeof value["module"] !== "string") return false;
282
+ if (typeof value["result"] !== "string") return false;
283
+ return true;
284
+ }
285
+ function isCallStep(value) {
286
+ if (!isObject(value)) return false;
287
+ if (value["do"] !== "call") return false;
288
+ if (!isObject(value["target"])) return false;
289
+ return true;
290
+ }
291
+ function isSubscribeStep(value) {
292
+ if (!isObject(value)) return false;
293
+ if (value["do"] !== "subscribe") return false;
294
+ if (!isObject(value["target"])) return false;
295
+ if (typeof value["event"] !== "string") return false;
296
+ if (typeof value["action"] !== "string") return false;
297
+ return true;
298
+ }
299
+ function isDisposeStep(value) {
300
+ if (!isObject(value)) return false;
301
+ if (value["do"] !== "dispose") return false;
302
+ if (!isObject(value["target"])) return false;
303
+ return true;
304
+ }
273
305
  function isActionStep(value) {
274
- return isSetStep(value) || isUpdateStep(value) || isFetchStep(value) || isStorageStep(value) || isClipboardStep(value) || isNavigateStep(value);
306
+ return isSetStep(value) || isUpdateStep(value) || isFetchStep(value) || isStorageStep(value) || isClipboardStep(value) || isNavigateStep(value) || isImportStep(value) || isCallStep(value) || isSubscribeStep(value) || isDisposeStep(value);
275
307
  }
276
308
  function isNumberField(value) {
277
309
  if (!isObject(value)) return false;
@@ -563,6 +595,13 @@ function createUndefinedDataError(dataName, path) {
563
595
  path
564
596
  );
565
597
  }
598
+ function createUndefinedRefError(refName, path) {
599
+ return new ConstelaError(
600
+ "UNDEFINED_REF",
601
+ `Undefined ref reference: '${refName}' is not defined in view elements`,
602
+ path
603
+ );
604
+ }
566
605
  function createInvalidStorageOperationError(operation, path) {
567
606
  return new ConstelaError(
568
607
  "INVALID_STORAGE_OPERATION",
@@ -1612,6 +1651,7 @@ export {
1612
1651
  createUndefinedDataSourceError,
1613
1652
  createUndefinedImportError,
1614
1653
  createUndefinedParamError,
1654
+ createUndefinedRefError,
1615
1655
  createUndefinedRouteParamError,
1616
1656
  createUndefinedStateError,
1617
1657
  createUndefinedVarError,
@@ -1619,6 +1659,7 @@ export {
1619
1659
  isActionStep,
1620
1660
  isBinExpr,
1621
1661
  isBooleanField,
1662
+ isCallStep,
1622
1663
  isClipboardStep,
1623
1664
  isCodeNode,
1624
1665
  isComponentNode,
@@ -1626,6 +1667,7 @@ export {
1626
1667
  isConstelaError,
1627
1668
  isDataExpr,
1628
1669
  isDataSource,
1670
+ isDisposeStep,
1629
1671
  isEachNode,
1630
1672
  isElementNode,
1631
1673
  isEventHandler,
@@ -1634,6 +1676,7 @@ export {
1634
1676
  isGetExpr,
1635
1677
  isIfNode,
1636
1678
  isImportExpr,
1679
+ isImportStep,
1637
1680
  isLayoutProgram,
1638
1681
  isLifecycleHooks,
1639
1682
  isListField,
@@ -1645,6 +1688,7 @@ export {
1645
1688
  isNumberField,
1646
1689
  isObjectField,
1647
1690
  isParamExpr,
1691
+ isRefExpr,
1648
1692
  isRouteDefinition,
1649
1693
  isRouteExpr,
1650
1694
  isSetStep,
@@ -1654,6 +1698,7 @@ export {
1654
1698
  isStaticPathsDefinition,
1655
1699
  isStorageStep,
1656
1700
  isStringField,
1701
+ isSubscribeStep,
1657
1702
  isTextNode,
1658
1703
  isUpdateStep,
1659
1704
  isVarExpr,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/core",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Core types, schema, and validator for Constela UI framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",