@stonecrop/stonecrop 0.10.12 → 0.10.13
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/composables/stonecrop.js +19 -144
- package/dist/index.js +9 -6
- package/dist/plugins/index.js +4 -1
- package/dist/schema-validator.js +1 -13
- package/dist/src/composables/stonecrop.d.ts +2 -74
- package/dist/src/composables/stonecrop.d.ts.map +1 -1
- package/dist/src/doctype.d.ts +1 -27
- package/dist/src/doctype.d.ts.map +1 -1
- package/dist/src/index.d.ts +6 -9
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/plugins/index.d.ts.map +1 -1
- package/dist/src/schema-validator.d.ts +1 -62
- package/dist/src/schema-validator.d.ts.map +1 -1
- package/dist/src/stonecrop.d.ts +38 -17
- package/dist/src/stonecrop.d.ts.map +1 -1
- package/dist/src/stores/operation-log.d.ts +1 -1
- package/dist/src/types/composable.d.ts +230 -0
- package/dist/src/types/composable.d.ts.map +1 -0
- package/dist/src/types/doctype.d.ts +57 -0
- package/dist/src/types/doctype.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +6 -67
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/plugin.d.ts +37 -0
- package/dist/src/types/plugin.d.ts.map +1 -0
- package/dist/src/types/schema-validator.d.ts +64 -0
- package/dist/src/types/schema-validator.d.ts.map +1 -0
- package/dist/src/types/stonecrop.d.ts +17 -0
- package/dist/src/types/stonecrop.d.ts.map +1 -0
- package/dist/stonecrop.d.ts +192 -3
- package/dist/stonecrop.js +1509 -1517
- package/dist/stonecrop.js.map +1 -1
- package/dist/types/composable.js +0 -0
- package/dist/types/doctype.js +0 -0
- package/dist/types/index.js +7 -2
- package/dist/types/plugin.js +0 -0
- package/dist/types/schema-validator.js +13 -0
- package/dist/types/stonecrop.js +0 -0
- package/package.json +5 -5
- package/src/composables/stonecrop.ts +26 -266
- package/src/doctype.ts +2 -29
- package/src/index.ts +12 -19
- package/src/plugins/index.ts +4 -1
- package/src/schema-validator.ts +3 -66
- package/src/stonecrop.ts +147 -16
- package/src/types/composable.ts +245 -0
- package/src/types/doctype.ts +60 -0
- package/src/types/index.ts +7 -74
- package/src/types/plugin.ts +38 -0
- package/src/types/schema-validator.ts +67 -0
- package/src/types/stonecrop.ts +17 -0
package/dist/stonecrop.d.ts
CHANGED
|
@@ -50,7 +50,16 @@ export declare interface ActionRegistry {
|
|
|
50
50
|
* @public
|
|
51
51
|
*/
|
|
52
52
|
export declare type BaseStonecropReturn = {
|
|
53
|
+
/**
|
|
54
|
+
* Reactive reference to the Stonecrop singleton instance.
|
|
55
|
+
* Use this to access class methods like `getRecord()`, `addRecord()`, `runAction()`.
|
|
56
|
+
*/
|
|
53
57
|
stonecrop: Ref<Stonecrop | undefined>;
|
|
58
|
+
/**
|
|
59
|
+
* Operation log API for undo/redo functionality.
|
|
60
|
+
* Use `operationLog.undo()` and `operationLog.redo()` for user-triggered operations.
|
|
61
|
+
* Use `operationLog.startBatch()` / `operationLog.commitBatch()` for grouping operations.
|
|
62
|
+
*/
|
|
54
63
|
operationLog: OperationLogAPI;
|
|
55
64
|
};
|
|
56
65
|
|
|
@@ -71,6 +80,16 @@ export declare interface BatchOperation {
|
|
|
71
80
|
reversible: boolean;
|
|
72
81
|
}
|
|
73
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Recursively collect nested data from HST using pre-resolved schemas
|
|
85
|
+
* @param resolvedSchema - The already-resolved schema (with nested schemas embedded)
|
|
86
|
+
* @param basePath - The base path in HST (e.g., "customer.123.address")
|
|
87
|
+
* @param hstStore - The HST store instance
|
|
88
|
+
* @returns The collected data object
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
export declare function collectNestedData(resolvedSchema: SchemaTypes[], basePath: string, hstStore: HSTNode): Record<string, any>;
|
|
92
|
+
|
|
74
93
|
/**
|
|
75
94
|
* Factory function for HST creation
|
|
76
95
|
* Creates a new HSTNode proxy for hierarchical state tree navigation.
|
|
@@ -585,9 +604,13 @@ export declare class HST {
|
|
|
585
604
|
* @public
|
|
586
605
|
*/
|
|
587
606
|
export declare type HSTChangeData = {
|
|
607
|
+
/** Full HST path to the changed field */
|
|
588
608
|
path: string;
|
|
609
|
+
/** New value for the field */
|
|
589
610
|
value: any;
|
|
611
|
+
/** Field name that changed */
|
|
590
612
|
fieldname: string;
|
|
613
|
+
/** Optional record ID */
|
|
591
614
|
recordId?: string;
|
|
592
615
|
};
|
|
593
616
|
|
|
@@ -735,19 +758,77 @@ export declare type HSTOperationType = 'set' | 'delete' | 'batch' | 'transition'
|
|
|
735
758
|
* @public
|
|
736
759
|
*/
|
|
737
760
|
export declare type HSTStonecropReturn = BaseStonecropReturn & {
|
|
761
|
+
/**
|
|
762
|
+
* Generates a fully-qualified HST path for a field.
|
|
763
|
+
* Use this in nested components to create paths like "customer.123.address".
|
|
764
|
+
* @param fieldname - The field name to append to the path
|
|
765
|
+
* @param recordId - Optional record ID (defaults to current record)
|
|
766
|
+
* @returns The full HST path string
|
|
767
|
+
*/
|
|
738
768
|
provideHSTPath: (fieldname: string, recordId?: string) => string;
|
|
769
|
+
/**
|
|
770
|
+
* Handles a field value change and updates HST.
|
|
771
|
+
* Call this from form input handlers to persist changes to the store.
|
|
772
|
+
* @param changeData - Object containing path, value, fieldname, and optional recordId
|
|
773
|
+
*/
|
|
739
774
|
handleHSTChange: (changeData: HSTChangeData) => void;
|
|
775
|
+
/**
|
|
776
|
+
* Reactive reference to the HST node for this doctype/record.
|
|
777
|
+
* Use this to read current form state or subscribe to changes.
|
|
778
|
+
*/
|
|
740
779
|
hstStore: Ref<HSTNode | undefined>;
|
|
780
|
+
/**
|
|
781
|
+
* Reactive form data bound to HST.
|
|
782
|
+
* Use this as the v-model target for form inputs. Changes sync to hstStore.
|
|
783
|
+
*/
|
|
741
784
|
formData: Ref<Record<string, any>>;
|
|
785
|
+
/**
|
|
786
|
+
* Resolved schema with nested Doctype fields expanded.
|
|
787
|
+
* Use this to iterate over fields for rendering, excluding nested doctypes handled separately.
|
|
788
|
+
*/
|
|
742
789
|
resolvedSchema: Ref<SchemaTypes[]>;
|
|
790
|
+
/**
|
|
791
|
+
* Loads or initializes nested doctype data.
|
|
792
|
+
* Use this when rendering a nested form component. Checks HST first, then initializes defaults.
|
|
793
|
+
* @param parentPath - The HST path to check for existing data
|
|
794
|
+
* @param childDoctype - The nested doctype metadata
|
|
795
|
+
* @param recordId - Optional record ID (reserved for future API fetch)
|
|
796
|
+
* @returns The loaded or initialized data object
|
|
797
|
+
*/
|
|
743
798
|
loadNestedData: (parentPath: string, childDoctype: Doctype, recordId?: string) => Record<string, any>;
|
|
799
|
+
/**
|
|
800
|
+
* Collects a complete record payload with all nested data from HST.
|
|
801
|
+
* Use this before submitting to an API. Recursively includes 1:1 and 1:many nested records.
|
|
802
|
+
* @param doctype - The doctype metadata
|
|
803
|
+
* @param recordId - The record ID to collect
|
|
804
|
+
* @returns The complete record payload ready for API submission
|
|
805
|
+
*/
|
|
744
806
|
collectRecordPayload: (doctype: Doctype, recordId: string) => Record<string, any>;
|
|
807
|
+
/**
|
|
808
|
+
* Creates a nested context for a child doctype component.
|
|
809
|
+
* Use this in parent components to pass scoped handlers to child components.
|
|
810
|
+
* @param basePath - The parent HST path prefix
|
|
811
|
+
* @param childDoctype - The child doctype metadata
|
|
812
|
+
* @returns Scoped provideHSTPath and handleHSTChange functions
|
|
813
|
+
*/
|
|
745
814
|
createNestedContext: (basePath: string, childDoctype: Doctype) => {
|
|
746
815
|
provideHSTPath: (fieldname: string) => string;
|
|
747
816
|
handleHSTChange: (changeData: HSTChangeData) => void;
|
|
748
817
|
};
|
|
818
|
+
/**
|
|
819
|
+
* Loading state for async doctype resolution.
|
|
820
|
+
* True while fetching doctype by slug string from registry.
|
|
821
|
+
*/
|
|
749
822
|
isLoading: Ref<boolean>;
|
|
823
|
+
/**
|
|
824
|
+
* Error state for doctype resolution failures.
|
|
825
|
+
* Set when doctype slug lookup fails.
|
|
826
|
+
*/
|
|
750
827
|
error: Ref<Error | null>;
|
|
828
|
+
/**
|
|
829
|
+
* Resolved doctype instance.
|
|
830
|
+
* Available immediately if Doctype instance passed, after async resolution if slug string passed.
|
|
831
|
+
*/
|
|
751
832
|
resolvedDoctype: Ref<Doctype | undefined>;
|
|
752
833
|
};
|
|
753
834
|
|
|
@@ -816,8 +897,20 @@ export declare type MutableDoctype = {
|
|
|
816
897
|
* @public
|
|
817
898
|
*/
|
|
818
899
|
export declare type OperationLogAPI = {
|
|
900
|
+
/**
|
|
901
|
+
* List of all recorded operations in the log.
|
|
902
|
+
* Each operation represents a state change that can be undone/redone.
|
|
903
|
+
*/
|
|
819
904
|
operations: Ref<HSTOperation[]>;
|
|
905
|
+
/**
|
|
906
|
+
* Current position in the operation log.
|
|
907
|
+
* -1 means no operations, 0 means at first operation, etc.
|
|
908
|
+
*/
|
|
820
909
|
currentIndex: Ref<number>;
|
|
910
|
+
/**
|
|
911
|
+
* Computed snapshot of undo/redo state.
|
|
912
|
+
* Use this for UI indicators (buttons, menu state).
|
|
913
|
+
*/
|
|
821
914
|
undoRedoState: ComputedRef<{
|
|
822
915
|
canUndo: boolean;
|
|
823
916
|
canRedo: boolean;
|
|
@@ -825,20 +918,92 @@ export declare type OperationLogAPI = {
|
|
|
825
918
|
redoCount: number;
|
|
826
919
|
currentIndex: number;
|
|
827
920
|
}>;
|
|
921
|
+
/**
|
|
922
|
+
* Whether undo is currently available.
|
|
923
|
+
* True when there are operations that can be undone.
|
|
924
|
+
*/
|
|
828
925
|
canUndo: ComputedRef<boolean>;
|
|
926
|
+
/**
|
|
927
|
+
* Whether redo is currently available.
|
|
928
|
+
* True when there are undone operations that can be redone.
|
|
929
|
+
*/
|
|
829
930
|
canRedo: ComputedRef<boolean>;
|
|
931
|
+
/**
|
|
932
|
+
* Number of operations available to undo.
|
|
933
|
+
*/
|
|
830
934
|
undoCount: ComputedRef<number>;
|
|
935
|
+
/**
|
|
936
|
+
* Number of operations available to redo.
|
|
937
|
+
*/
|
|
831
938
|
redoCount: ComputedRef<number>;
|
|
939
|
+
/**
|
|
940
|
+
* Undo the last operation.
|
|
941
|
+
* @param hstStore - The HST node to apply the inverse operation to
|
|
942
|
+
* @returns True if undo succeeded, false if nothing to undo
|
|
943
|
+
*/
|
|
832
944
|
undo: (hstStore: HSTNode) => boolean;
|
|
945
|
+
/**
|
|
946
|
+
* Redo the last undone operation.
|
|
947
|
+
* @param hstStore - The HST node to apply the operation to
|
|
948
|
+
* @returns True if redo succeeded, false if nothing to redo
|
|
949
|
+
*/
|
|
833
950
|
redo: (hstStore: HSTNode) => boolean;
|
|
951
|
+
/**
|
|
952
|
+
* Start batching multiple operations together.
|
|
953
|
+
* Call before a series of changes that should be undone/redone as a unit.
|
|
954
|
+
*/
|
|
834
955
|
startBatch: () => void;
|
|
956
|
+
/**
|
|
957
|
+
* Commit the current batch of operations.
|
|
958
|
+
* @param description - Optional description for the batch
|
|
959
|
+
* @returns The batch operation ID, or null if no batch in progress
|
|
960
|
+
*/
|
|
835
961
|
commitBatch: (description?: string) => string | null;
|
|
962
|
+
/**
|
|
963
|
+
* Cancel the current batch without committing.
|
|
964
|
+
* Discards all operations added since startBatch().
|
|
965
|
+
*/
|
|
836
966
|
cancelBatch: () => void;
|
|
967
|
+
/**
|
|
968
|
+
* Clear all operations from the log.
|
|
969
|
+
* Resets the log to its initial empty state.
|
|
970
|
+
*/
|
|
837
971
|
clear: () => void;
|
|
972
|
+
/**
|
|
973
|
+
* Get all operations for a specific doctype.
|
|
974
|
+
* @param doctype - The doctype name to filter by
|
|
975
|
+
* @param recordId - Optional record ID to further filter
|
|
976
|
+
* @returns Array of matching operations
|
|
977
|
+
*/
|
|
838
978
|
getOperationsFor: (doctype: string, recordId?: string) => HSTOperation[];
|
|
979
|
+
/**
|
|
980
|
+
* Get a serializable snapshot of the operation log.
|
|
981
|
+
* Use for debugging, logging, or state persistence.
|
|
982
|
+
* @returns Snapshot containing operations and current index
|
|
983
|
+
*/
|
|
839
984
|
getSnapshot: () => OperationLogSnapshot;
|
|
985
|
+
/**
|
|
986
|
+
* Mark an operation as irreversible.
|
|
987
|
+
* Irreversible operations cannot be undone.
|
|
988
|
+
* @param operationId - The operation ID to mark
|
|
989
|
+
* @param reason - Human-readable reason why it cannot be undone
|
|
990
|
+
*/
|
|
840
991
|
markIrreversible: (operationId: string, reason: string) => void;
|
|
992
|
+
/**
|
|
993
|
+
* Log a custom action (non-HST operation).
|
|
994
|
+
* Use for tracking server calls, external side effects, etc.
|
|
995
|
+
* @param doctype - The doctype this action relates to
|
|
996
|
+
* @param actionName - Name of the action (e.g., 'save', 'submit')
|
|
997
|
+
* @param recordIds - Optional array of affected record IDs
|
|
998
|
+
* @param result - Optional result status
|
|
999
|
+
* @param error - Optional error message if result is 'failure'
|
|
1000
|
+
* @returns The logged operation ID
|
|
1001
|
+
*/
|
|
841
1002
|
logAction: (doctype: string, actionName: string, recordIds?: string[], result?: 'success' | 'failure' | 'pending', error?: string) => string;
|
|
1003
|
+
/**
|
|
1004
|
+
* Configure operation log options.
|
|
1005
|
+
* @param options - Partial configuration to merge with existing settings
|
|
1006
|
+
*/
|
|
842
1007
|
configure: (options: Partial<OperationLogConfig>) => void;
|
|
843
1008
|
};
|
|
844
1009
|
|
|
@@ -1140,6 +1305,13 @@ export declare function setFieldRollback(doctype: string, fieldname: string, ena
|
|
|
1140
1305
|
* @public
|
|
1141
1306
|
*/
|
|
1142
1307
|
export declare class Stonecrop {
|
|
1308
|
+
/**
|
|
1309
|
+
* Singleton instance of Stonecrop. Only one Stonecrop instance can exist
|
|
1310
|
+
* per application, ensuring consistent HST state and registry access.
|
|
1311
|
+
* Subsequent constructor calls return this instance instead of creating new ones.
|
|
1312
|
+
* @internal
|
|
1313
|
+
*/
|
|
1314
|
+
static _root: Stonecrop;
|
|
1143
1315
|
private hstStore;
|
|
1144
1316
|
private _operationLogStore?;
|
|
1145
1317
|
private _operationLogConfig?;
|
|
@@ -1147,7 +1319,7 @@ export declare class Stonecrop {
|
|
|
1147
1319
|
/** The registry instance containing all doctype definitions */
|
|
1148
1320
|
readonly registry: Registry;
|
|
1149
1321
|
/**
|
|
1150
|
-
* Creates a new Stonecrop instance with HST integration
|
|
1322
|
+
* Creates a new Stonecrop instance with HST integration (singleton pattern)
|
|
1151
1323
|
* @param registry - The Registry instance containing doctype definitions
|
|
1152
1324
|
* @param operationLogConfig - Optional configuration for the operation log
|
|
1153
1325
|
* @param options - Options including the data client (can be set later via setClient)
|
|
@@ -1262,7 +1434,7 @@ export declare class Stonecrop {
|
|
|
1262
1434
|
getSnapshot: () => OperationLogSnapshot;
|
|
1263
1435
|
markIrreversible: (operationId: string, reason: string) => void;
|
|
1264
1436
|
logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
|
|
1265
|
-
}, "operations" | "
|
|
1437
|
+
}, "operations" | "clientId" | "currentIndex" | "config">, Pick<{
|
|
1266
1438
|
operations: Ref< {
|
|
1267
1439
|
id: string;
|
|
1268
1440
|
type: HSTOperationType;
|
|
@@ -1551,6 +1723,23 @@ export declare class Stonecrop {
|
|
|
1551
1723
|
* @public
|
|
1552
1724
|
*/
|
|
1553
1725
|
getRecordState(doctype: string | Doctype, recordId: string): string;
|
|
1726
|
+
/**
|
|
1727
|
+
* Collect a record payload with all nested doctype fields from HST
|
|
1728
|
+
* @param doctype - The doctype metadata
|
|
1729
|
+
* @param recordId - The record ID to collect
|
|
1730
|
+
* @returns The complete record payload ready for API submission
|
|
1731
|
+
* @public
|
|
1732
|
+
*/
|
|
1733
|
+
collectRecordPayload(doctype: Doctype, recordId: string): Record<string, any>;
|
|
1734
|
+
/**
|
|
1735
|
+
* Load nested data from HST or initialize with defaults
|
|
1736
|
+
* @param parentPath - The HST path to check for existing data
|
|
1737
|
+
* @param childDoctype - The child doctype metadata
|
|
1738
|
+
* @param _recordId - Optional record ID to load
|
|
1739
|
+
* @returns The loaded or initialized data
|
|
1740
|
+
* @public
|
|
1741
|
+
*/
|
|
1742
|
+
loadNestedData(parentPath: string, childDoctype: Doctype, _recordId?: string): Record<string, any>;
|
|
1554
1743
|
}
|
|
1555
1744
|
|
|
1556
1745
|
/**
|
|
@@ -1835,7 +2024,7 @@ getOperationsFor: (doctype: string, recordId?: string) => HSTOperation[];
|
|
|
1835
2024
|
getSnapshot: () => OperationLogSnapshot;
|
|
1836
2025
|
markIrreversible: (operationId: string, reason: string) => void;
|
|
1837
2026
|
logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
|
|
1838
|
-
}, "operations" | "
|
|
2027
|
+
}, "operations" | "clientId" | "currentIndex" | "config">, Pick<{
|
|
1839
2028
|
operations: Ref< {
|
|
1840
2029
|
id: string;
|
|
1841
2030
|
type: HSTOperationType;
|