orchestore 0.1.6 → 0.1.8
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 +292 -82
- package/dist/index.cjs +14 -14
- package/dist/index.d.cts +62 -22
- package/dist/index.d.ts +62 -22
- package/dist/index.js +14 -14
- package/package.json +11 -2
package/README.md
CHANGED
|
@@ -51,8 +51,9 @@ The goal is simple:
|
|
|
51
51
|
- [Mutations](#mutations)
|
|
52
52
|
- [Methods](#methods)
|
|
53
53
|
- [Computed State (Planned)](#computed-state-planned)
|
|
54
|
-
- [Nested Slices
|
|
55
|
-
- [
|
|
54
|
+
- [Nested Slices](#nested-slices)
|
|
55
|
+
- [Reusing Slices](#reusing-slices)
|
|
56
|
+
- [Runtime Paths](#runtime-paths)
|
|
56
57
|
|
|
57
58
|
- [State Access & Subscriptions](#state-access--subscriptions)
|
|
58
59
|
- [State Snapshots](#state-snapshots)
|
|
@@ -66,6 +67,12 @@ The goal is simple:
|
|
|
66
67
|
- [Accessing Store from Slices](#accessing-store-from-slices)
|
|
67
68
|
- [Root Store Type Extension (Planned)](#root-store-type-extension-planned)
|
|
68
69
|
|
|
70
|
+
- [Lineage & Clones](#lineage--clones)
|
|
71
|
+
- [Automatic Cloning](#automatic-cloning)
|
|
72
|
+
- [Manual Cloning](#manual-cloning)
|
|
73
|
+
- [Inspecting a Lineage](#inspecting-a-lineage)
|
|
74
|
+
- [Definition Type Checking](#definition-type-checking)
|
|
75
|
+
|
|
69
76
|
- [Global Utilities](#global-utilities)
|
|
70
77
|
- [Accessing Global Utilities](#accessing-global-utilities)
|
|
71
78
|
- [Utilities Type Extension](#utilities-type-extension)
|
|
@@ -119,16 +126,17 @@ This allows state and application logic to evolve together within the same domai
|
|
|
119
126
|
|
|
120
127
|
Many common Redux patterns are automated by default:
|
|
121
128
|
|
|
122
|
-
| Traditional Redux Pattern | OrcheStore
|
|
123
|
-
| ----------------------------- |
|
|
124
|
-
| Action creators | Direct callable mutations
|
|
125
|
-
| Thunks | Built-in methods
|
|
126
|
-
| Dispatch calls | Direct function calls
|
|
127
|
-
| `PayloadAction` wrappers | Native function arguments
|
|
128
|
-
| Cross-slice imports | Root store access
|
|
129
|
-
| Shared service wiring | Global utilities
|
|
130
|
-
| Manual state tree composition | Nested slices
|
|
131
|
-
| Complex type declarations | Automatic inference
|
|
129
|
+
| Traditional Redux Pattern | OrcheStore |
|
|
130
|
+
| ----------------------------- | ----------------------------------------------- |
|
|
131
|
+
| Action creators | Direct callable mutations |
|
|
132
|
+
| Thunks | Built-in methods |
|
|
133
|
+
| Dispatch calls | Direct function calls |
|
|
134
|
+
| `PayloadAction` wrappers | Native function arguments |
|
|
135
|
+
| Cross-slice imports | Root store access |
|
|
136
|
+
| Shared service wiring | Global utilities |
|
|
137
|
+
| Manual state tree composition | Nested slices with automatic cloning & isolation |
|
|
138
|
+
| Complex type declarations | Automatic inference |
|
|
139
|
+
| Instance identity management | Lineage-based slice model (shared definition, isolated mounts) |
|
|
132
140
|
|
|
133
141
|
The result is a simpler architecture with fewer moving parts, less boilerplate, and a more direct development experience.
|
|
134
142
|
|
|
@@ -140,33 +148,35 @@ OrcheStore builds on top of Redux Toolkit while providing a higher-level API for
|
|
|
140
148
|
|
|
141
149
|
| Feature | OrcheStore | Redux Toolkit |
|
|
142
150
|
| ------------------------------ | ---------- | ------------- |
|
|
143
|
-
| Direct callable mutations | ✅ | ❌ |
|
|
144
151
|
| Multiple mutation arguments | ✅ | ❌ |
|
|
145
|
-
|
|
|
152
|
+
| Direct callable mutations | ✅ | ❌ |
|
|
146
153
|
| `PayloadAction` wrappers | ❌ | ✅ |
|
|
154
|
+
| Dispatch required | ❌ | ✅ |
|
|
147
155
|
| Built-in orchestration methods | ✅ | ❌ |
|
|
148
|
-
| Nested slice composition |
|
|
149
|
-
| Automatic path generation |
|
|
156
|
+
| Nested slice composition | ✅ (isolated context) | ⚠️ Manual (shared state) |
|
|
157
|
+
| Automatic path generation | ✅ | ⚠️ Manual |
|
|
150
158
|
| Global utilities | ✅ | ❌ |
|
|
151
159
|
| Unified slice API | ✅ | ❌ |
|
|
152
160
|
| Per-slice React hooks | ✅ | ❌ |
|
|
153
161
|
| Deep TypeScript inference | ✅ | ⚠️ Partial |
|
|
162
|
+
| Lineage & cloning model | ✅ | ❌ |
|
|
154
163
|
|
|
155
164
|
OrcheStore does not replace Redux Toolkit. Instead, it builds on top of it by automating common patterns and providing a more cohesive developer experience.
|
|
156
165
|
|
|
157
166
|
## Architecture Overview
|
|
158
167
|
|
|
159
|
-
| Layer | Responsibility
|
|
160
|
-
| ----------- |
|
|
161
|
-
| `name` | Unique slice identifier
|
|
162
|
-
| `
|
|
163
|
-
| `
|
|
164
|
-
| `
|
|
165
|
-
| `
|
|
166
|
-
| `
|
|
167
|
-
| `
|
|
168
|
-
| `
|
|
169
|
-
| `
|
|
168
|
+
| Layer | Responsibility |
|
|
169
|
+
| ----------- | ---------------------------------------- |
|
|
170
|
+
| `name` | Unique slice identifier |
|
|
171
|
+
| `path` | Hierarchical slice path |
|
|
172
|
+
| `state` | Slice data storage definition |
|
|
173
|
+
| `mutations` | Synchronous state transitions |
|
|
174
|
+
| `methods` | Orchestration and side effects |
|
|
175
|
+
| `computed` | Derived and computed state |
|
|
176
|
+
| `children` | Nested slice composition |
|
|
177
|
+
| `getState` | Imperative state access |
|
|
178
|
+
| `useSelect` | Reactive state subscriptions |
|
|
179
|
+
| `prototype` | Lineage, cloning, and instance utilities |
|
|
170
180
|
|
|
171
181
|
---
|
|
172
182
|
|
|
@@ -345,7 +355,6 @@ export default function App() {
|
|
|
345
355
|
OrcheStore exposes direct usable child slices through a unified store instance.
|
|
346
356
|
|
|
347
357
|
```tsx
|
|
348
|
-
// store.counter is equivalent to counter, import only one and use it
|
|
349
358
|
import { store } from "./store/index";
|
|
350
359
|
import { counter } from "./store/counterSlice";
|
|
351
360
|
|
|
@@ -365,6 +374,10 @@ export function CounterComponent() {
|
|
|
365
374
|
}
|
|
366
375
|
```
|
|
367
376
|
|
|
377
|
+
> 📌 If the slice is mounted only once, `store.counter` and `counter` refer to the same runtime instance and can be used interchangeably.
|
|
378
|
+
>
|
|
379
|
+
> 🔄 When a slice is mounted multiple times, each mount receives its own isolated instance. See [Reusing Slices](#reusing-slices) and [Lineage & Clones](#lineage--clones) for details.
|
|
380
|
+
|
|
368
381
|
---
|
|
369
382
|
|
|
370
383
|
# Slice Layers
|
|
@@ -385,7 +398,7 @@ const counter = createSlice({
|
|
|
385
398
|
|
|
386
399
|
methods: {},
|
|
387
400
|
|
|
388
|
-
children: {},
|
|
401
|
+
children: {},
|
|
389
402
|
|
|
390
403
|
subscribe: {}, // Planned
|
|
391
404
|
});
|
|
@@ -421,9 +434,8 @@ methods: {
|
|
|
421
434
|
|
|
422
435
|
**Rules:**
|
|
423
436
|
|
|
424
|
-
-
|
|
437
|
+
- Names should not contain `"."` or `"/"`, because they are reserved for nested slice paths
|
|
425
438
|
- Two slices cannot share the same name
|
|
426
|
-
- Registering the same slice instance multiple times with the same name is not allowed
|
|
427
439
|
|
|
428
440
|
---
|
|
429
441
|
|
|
@@ -605,80 +617,127 @@ This currently not supported
|
|
|
605
617
|
|
|
606
618
|
---
|
|
607
619
|
|
|
608
|
-
## Nested Slices
|
|
609
|
-
|
|
610
|
-
This currently not supported
|
|
620
|
+
## Nested Slices
|
|
611
621
|
|
|
612
|
-
|
|
622
|
+
Slices can be composed by registering other slice instances through the `children` property.
|
|
613
623
|
|
|
614
|
-
|
|
624
|
+
This allows related state and behavior to be organized into a hierarchical structure while preserving full type inference and ownership isolation.
|
|
615
625
|
|
|
616
626
|
```ts
|
|
617
|
-
|
|
618
|
-
|
|
627
|
+
import { products } from "./productsSlice";
|
|
628
|
+
import { categories } from "./categoriesSlice";
|
|
619
629
|
|
|
620
|
-
|
|
621
|
-
|
|
630
|
+
export const shop = createSlice({
|
|
631
|
+
name: "shop",
|
|
622
632
|
|
|
623
|
-
|
|
633
|
+
state: {},
|
|
624
634
|
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
635
|
+
children: {
|
|
636
|
+
products,
|
|
637
|
+
categories,
|
|
638
|
+
},
|
|
639
|
+
});
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
**Accessing Child Slices:**
|
|
643
|
+
|
|
644
|
+
Child slices are exposed directly on their parent slice.
|
|
645
|
+
|
|
646
|
+
```ts
|
|
647
|
+
shop.products.add(...)
|
|
648
|
+
shop.categories.create(...)
|
|
649
|
+
|
|
650
|
+
console.log(shop.products.getState());
|
|
630
651
|
```
|
|
631
652
|
|
|
632
|
-
|
|
653
|
+
Deeply nested slice hierarchies are fully supported.
|
|
654
|
+
|
|
655
|
+
```ts
|
|
656
|
+
admin.users.permissions.grant(...);
|
|
657
|
+
|
|
658
|
+
console.log(admin.users.permissions.getState());
|
|
659
|
+
```
|
|
633
660
|
|
|
634
|
-
|
|
635
|
-
- ~~Existing slice instances cannot be wrapped again with `createSlice`~~
|
|
636
|
-
- ~~Child slices must be registered through the `children` property~~
|
|
661
|
+
### Reusing Slices
|
|
637
662
|
|
|
638
|
-
|
|
663
|
+
A slice can be mounted multiple times within the same tree.
|
|
639
664
|
|
|
640
|
-
|
|
665
|
+
When the same slice definition is reused, OrcheStore automatically creates a separate mounted instance for each location.
|
|
641
666
|
|
|
642
667
|
```ts
|
|
643
|
-
|
|
668
|
+
const paginationSlice = createSlice({ ... });
|
|
644
669
|
|
|
645
|
-
|
|
670
|
+
const shopSlice = createSlice({
|
|
671
|
+
name: "shop",
|
|
672
|
+
|
|
673
|
+
state: {},
|
|
674
|
+
|
|
675
|
+
children: {
|
|
676
|
+
categories: paginationSlice,
|
|
677
|
+
products: paginationSlice,
|
|
678
|
+
},
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
const adminSlice = createSlice({
|
|
682
|
+
name: "admin",
|
|
683
|
+
|
|
684
|
+
state: {},
|
|
685
|
+
|
|
686
|
+
children: {
|
|
687
|
+
products: paginationSlice,
|
|
688
|
+
},
|
|
689
|
+
});
|
|
646
690
|
```
|
|
647
691
|
|
|
648
|
-
|
|
692
|
+
Each mounted instance has:
|
|
693
|
+
|
|
694
|
+
- its own path
|
|
695
|
+
- its own ownership context
|
|
696
|
+
- its own runtime state
|
|
697
|
+
|
|
698
|
+
**Runtime identity:**
|
|
699
|
+
|
|
700
|
+
Although all mounted slices originate from `paginationSlice`, they are not necessarily the same runtime instance.
|
|
649
701
|
|
|
650
702
|
```ts
|
|
651
|
-
|
|
703
|
+
paginationSlice === shopSlice.categories; // First mount uses the original instance
|
|
704
|
+
|
|
705
|
+
paginationSlice !== shopSlice.products; // Different mount location creates a clone
|
|
706
|
+
paginationSlice !== adminSlice.products; // Different mount location creates a clone
|
|
652
707
|
|
|
653
|
-
|
|
708
|
+
shopSlice.products !== adminSlice.products; // Independent mounted clones
|
|
654
709
|
```
|
|
655
710
|
|
|
656
|
-
|
|
711
|
+
Every mount location receives its own isolated instance.
|
|
657
712
|
|
|
658
|
-
|
|
713
|
+
For a deeper explanation of how slice reuse works, see [Lineage & Clones](#lineage--clones).
|
|
714
|
+
|
|
715
|
+
### Runtime Paths
|
|
716
|
+
|
|
717
|
+
Every slice exposes a runtime path through `slice.path`.
|
|
659
718
|
|
|
660
719
|
```ts
|
|
661
|
-
|
|
662
|
-
|
|
720
|
+
store.counter.name; // "counter"
|
|
721
|
+
store.counter.path; // "counter"
|
|
663
722
|
```
|
|
664
723
|
|
|
665
|
-
|
|
724
|
+
Nested slices automatically inherit their parent path.
|
|
666
725
|
|
|
667
726
|
```ts
|
|
668
|
-
|
|
669
|
-
|
|
727
|
+
store.admin.users.name; // "users"
|
|
728
|
+
store.admin.users.path; // "admin.users"
|
|
670
729
|
|
|
671
|
-
|
|
672
|
-
|
|
730
|
+
store.admin.users.permissions.name; // "permissions"
|
|
731
|
+
store.admin.users.permissions.path; // "admin.users.permissions"
|
|
673
732
|
```
|
|
674
733
|
|
|
675
|
-
|
|
734
|
+
**Notes:**
|
|
676
735
|
|
|
677
|
-
|
|
736
|
+
Paths are generated automatically from the slice hierarchy.
|
|
678
737
|
|
|
679
|
-
|
|
738
|
+
OrcheStore builds on the same concepts as Redux Toolkit's `reducerPath` and `combineReducers`, but automates path generation, reducer registration, and nested slice composition.
|
|
680
739
|
|
|
681
|
-
|
|
740
|
+
No manual path configuration or reducer injection is required.
|
|
682
741
|
|
|
683
742
|
---
|
|
684
743
|
|
|
@@ -906,6 +965,158 @@ this.root; // After: fully typed store
|
|
|
906
965
|
|
|
907
966
|
---
|
|
908
967
|
|
|
968
|
+
# Lineage & Clones
|
|
969
|
+
|
|
970
|
+
OrcheStore uses a lineage-based model for slice identity.
|
|
971
|
+
|
|
972
|
+
**Why?**
|
|
973
|
+
|
|
974
|
+
Slices can be used in multiple places in the store tree.
|
|
975
|
+
|
|
976
|
+
When this happens, OrcheStore creates a separate runtime instance for each usage. These instances are called **clones**.
|
|
977
|
+
|
|
978
|
+
A clone is an independent instance copy of a slice at runtime. It has its own state and runs separately from other clones, while still remaining part of a shared lineage.
|
|
979
|
+
|
|
980
|
+
A lineage (or family) is the set of all instances that come from the same slice definition.
|
|
981
|
+
|
|
982
|
+
**This means:**
|
|
983
|
+
|
|
984
|
+
- slices are not singletons
|
|
985
|
+
- a slice can appear multiple times in a tree
|
|
986
|
+
- each clone is fully isolated
|
|
987
|
+
- all instances cloned from the same slice are linked through lineage
|
|
988
|
+
|
|
989
|
+
## Automatic Cloning
|
|
990
|
+
|
|
991
|
+
When a slice is reused through `children` or `slices`, OrcheStore automatically creates a new mounted instance for each usage.
|
|
992
|
+
|
|
993
|
+
```ts
|
|
994
|
+
const paginationSlice = createSlice({ ... });
|
|
995
|
+
|
|
996
|
+
const shopSlice = createSlice({
|
|
997
|
+
name: "shop",
|
|
998
|
+
|
|
999
|
+
state: {},
|
|
1000
|
+
|
|
1001
|
+
children: {
|
|
1002
|
+
a: paginationSlice,
|
|
1003
|
+
b: paginationSlice,
|
|
1004
|
+
},
|
|
1005
|
+
});
|
|
1006
|
+
|
|
1007
|
+
const adminSlice = createSlice({
|
|
1008
|
+
name: "admin",
|
|
1009
|
+
|
|
1010
|
+
state: {},
|
|
1011
|
+
|
|
1012
|
+
children: {
|
|
1013
|
+
a: paginationSlice,
|
|
1014
|
+
},
|
|
1015
|
+
});
|
|
1016
|
+
```
|
|
1017
|
+
|
|
1018
|
+
Each mount becomes a separate runtime node:
|
|
1019
|
+
|
|
1020
|
+
```ts
|
|
1021
|
+
shopSlice.a !== shopSlice.b;
|
|
1022
|
+
shopSlice.a !== adminSlice.a;
|
|
1023
|
+
shopSlice.b !== adminSlice.a;
|
|
1024
|
+
```
|
|
1025
|
+
|
|
1026
|
+
Each instance also receives its own path and its own ownership context:
|
|
1027
|
+
|
|
1028
|
+
```ts
|
|
1029
|
+
shopSlice.a.path; // "shop.a"
|
|
1030
|
+
shopSlice.b.path; // "shop.b"
|
|
1031
|
+
adminSlice.a.path; // "admin.a"
|
|
1032
|
+
```
|
|
1033
|
+
|
|
1034
|
+
Although these instances are independent at runtime, they still belong to the same lineage.
|
|
1035
|
+
|
|
1036
|
+
## Manual Cloning
|
|
1037
|
+
|
|
1038
|
+
A new detached clone can be created manually from any slice instance:
|
|
1039
|
+
|
|
1040
|
+
```ts
|
|
1041
|
+
const clone = slice.prototype.clone();
|
|
1042
|
+
```
|
|
1043
|
+
|
|
1044
|
+
The new instance:
|
|
1045
|
+
|
|
1046
|
+
- belongs to the same lineage
|
|
1047
|
+
- starts detached from the tree
|
|
1048
|
+
- has no mounted path initially
|
|
1049
|
+
- has its own ownership context
|
|
1050
|
+
|
|
1051
|
+
## Inspecting a Lineage
|
|
1052
|
+
|
|
1053
|
+
**Get All Related Instances:**
|
|
1054
|
+
|
|
1055
|
+
Returns every instance in the lineage, **including** the current one.
|
|
1056
|
+
|
|
1057
|
+
```ts
|
|
1058
|
+
const lineage = slice.prototype.getLineage();
|
|
1059
|
+
```
|
|
1060
|
+
|
|
1061
|
+
Useful for:
|
|
1062
|
+
|
|
1063
|
+
- debugging slice reuse
|
|
1064
|
+
- inspecting mounted instances
|
|
1065
|
+
- understanding tree distribution
|
|
1066
|
+
|
|
1067
|
+
**Get Clones:**
|
|
1068
|
+
|
|
1069
|
+
Returns all lineage members **except** the current instance.
|
|
1070
|
+
|
|
1071
|
+
```ts
|
|
1072
|
+
const siblings = slice.prototype.getClones();
|
|
1073
|
+
```
|
|
1074
|
+
|
|
1075
|
+
Useful for:
|
|
1076
|
+
|
|
1077
|
+
- communicating between clones
|
|
1078
|
+
- broadcast or synchronization scenarios
|
|
1079
|
+
- comparing mounted instances
|
|
1080
|
+
|
|
1081
|
+
## Definition Type Checking
|
|
1082
|
+
|
|
1083
|
+
You can determine whether two slices belong to the same lineage:
|
|
1084
|
+
|
|
1085
|
+
You can check whether two slices belong to the same lineage:
|
|
1086
|
+
|
|
1087
|
+
```ts
|
|
1088
|
+
const isSameLineage = slice.prototype.isTypeOf(otherSlice);
|
|
1089
|
+
```
|
|
1090
|
+
|
|
1091
|
+
Returns `true` when both slices originate from the same slice definition, even if they are different runtime instances.
|
|
1092
|
+
|
|
1093
|
+
```ts
|
|
1094
|
+
const slice1 = createSlice(...);
|
|
1095
|
+
const slice2 = createSlice(...);
|
|
1096
|
+
|
|
1097
|
+
const clone1 = slice1.prototype.clone();
|
|
1098
|
+
const clone2 = clone1.prototype.clone();
|
|
1099
|
+
|
|
1100
|
+
slice1.prototype.isTypeOf(clone1); // true
|
|
1101
|
+
clone1.prototype.isTypeOf(clone2); // true
|
|
1102
|
+
clone2.prototype.isTypeOf(slice1); // true
|
|
1103
|
+
|
|
1104
|
+
slice1.prototype.isTypeOf(slice2); // false
|
|
1105
|
+
slice2.prototype.isTypeOf(clone1); // false
|
|
1106
|
+
```
|
|
1107
|
+
|
|
1108
|
+
## Summary
|
|
1109
|
+
|
|
1110
|
+
- Reusing a slice automatically creates mounted clones.
|
|
1111
|
+
- `clone()` creates a new detached lineage member.
|
|
1112
|
+
- Every clone is isolated at runtime.
|
|
1113
|
+
- All clones from the same definition belong to a shared lineage.
|
|
1114
|
+
- `getLineage()` returns all instances in a lineage.
|
|
1115
|
+
- `getClones()` returns all related instances except the current one.
|
|
1116
|
+
- `isTypeOf()` checks whether two instances belong to the same lineage.
|
|
1117
|
+
|
|
1118
|
+
---
|
|
1119
|
+
|
|
909
1120
|
# Global Utilities
|
|
910
1121
|
|
|
911
1122
|
Global utilities allow slices and the root store to access shared runtime services through `global`.
|
|
@@ -1055,15 +1266,15 @@ const counter = createSlice({
|
|
|
1055
1266
|
},
|
|
1056
1267
|
},
|
|
1057
1268
|
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1269
|
+
children: {
|
|
1270
|
+
subCounter: createSlice({
|
|
1271
|
+
name: "subCounter",
|
|
1061
1272
|
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1273
|
+
state: {
|
|
1274
|
+
value: 0,
|
|
1275
|
+
},
|
|
1276
|
+
}),
|
|
1277
|
+
},
|
|
1067
1278
|
});
|
|
1068
1279
|
```
|
|
1069
1280
|
|
|
@@ -1071,11 +1282,10 @@ Automatically produces:
|
|
|
1071
1282
|
|
|
1072
1283
|
```ts
|
|
1073
1284
|
counter.getState();
|
|
1074
|
-
// { value: number }
|
|
1075
|
-
// { value: number, subCounter: { value: number } } // Planned
|
|
1285
|
+
// { value: number, subCounter: { value: number } }
|
|
1076
1286
|
|
|
1077
|
-
|
|
1078
|
-
// { value: number }
|
|
1287
|
+
counter.subCounter.getState();
|
|
1288
|
+
// { value: number }
|
|
1079
1289
|
|
|
1080
1290
|
counter.increment(amount: number): void;
|
|
1081
1291
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var ue=Object.create;var C=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var ye=Object.getPrototypeOf,me=Object.prototype.hasOwnProperty;var he=(e,t)=>{for(var r in t)C(e,r,{get:t[r],enumerable:!0})},_=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of fe(t))!me.call(e,i)&&i!==r&&C(e,i,{get:()=>t[i],enumerable:!(o=pe(t,i))||o.enumerable});return e};var ge=(e,t,r)=>(r=e!=null?ue(ye(e)):{},_(t||!e||!e.__esModule?C(r,"default",{value:e,enumerable:!0}):r,e)),Se=e=>_(C({},"__esModule",{value:!0}),e);var Ne={};he(Ne,{StoreProvider:()=>J,configureDiagnostics:()=>K,createSlice:()=>le,createStore:()=>ce,default:()=>Ue,getGlobalUtils:()=>v,provideGlobalUtils:()=>L});module.exports=Se(Ne);var oe=require("@reduxjs/toolkit"),ne=require("react-redux");var R="all",k={diagnostics:!1,prerelease:!1},B=globalThis.console?.log?.bind?.(globalThis.console)||globalThis.console?.log,be=globalThis.console?.warn?.bind?.(globalThis.console)||globalThis.console?.warn,ve=globalThis.console?.error?.bind?.(globalThis.console)||globalThis.console?.error,xe=globalThis.console?.clear?.bind?.(globalThis.console)||globalThis.console?.clear;globalThis.console?.clear&&(globalThis.console.clear=(...e)=>{k.diagnostics=!1,xe?.(...e)});var Te=`[OrcheStore] \u{1F6A7} Pre-release Notice
|
|
2
2
|
Thank you for your interest in OrcheStore.
|
|
3
3
|
OrcheStore is currently under active development and is not yet ready for production use.
|
|
4
4
|
APIs, behavior, and internal implementation details may change without notice.
|
|
5
5
|
The first stable release is currently planned for 2026-06-30.
|
|
6
6
|
Stay tuned for updates!
|
|
7
|
-
`,
|
|
7
|
+
`,we=`[OrcheStore] Diagnostics are enabled.
|
|
8
8
|
OrcheStore may emit warnings and errors to help identify incorrect usage, invalid configurations, and potential runtime issues.
|
|
9
9
|
Runtime exceptions that stop code execution may still occur regardless of diagnostics settings.
|
|
10
10
|
Please resolve all OrcheStore warnings and errors before deploying to production.
|
|
11
11
|
Diagnostics can be configured with configureDiagnostics("off" | "errors" | "all").
|
|
12
|
-
`,
|
|
13
|
-
`,...
|
|
12
|
+
`,l={inform(e){k[e]||(k[e]=!0,R==="all"&&B?.(e==="prerelease"?Te:we))},log(...e){R==="all"&&(l.inform("diagnostics"),B?.(...e))},warn(...e){R==="all"&&(l.inform("diagnostics"),be?.(...e))},error(...e){R!=="off"&&(l.inform("diagnostics"),ve?.(...e))}};function K(e){R=e}var H=(...e)=>{let[t,r]=[e[2],e[3]],o=`${e[0]||"Received"}: `,i=e[1]!==!1?"(type: "+typeof t+")":"";if(!r?.(t))return t==null?[`${o}(type: ${t})`]:typeof t=="number"||typeof t=="bigint"||typeof t=="boolean"?[`${o}${i} ${t}`]:typeof t=="object"?[o,t]:t===""?[`${o}Empty String`]:[`${o}${i}`,t]},E=((e,t)=>H("Received",!0,e,t));E.prefixed=(e,t,r,o)=>H(e,t,r,o);var Oe=Object.assign,D=Object.getOwnPropertyDescriptor(Object,"defineProperty")?.value||Object.defineProperty,Ee=(e,t,r)=>{D(e,t,{get:r,enumerable:!0,configurable:!1})},Me=(e,t,r)=>{D(e,t,{value:r,writable:!1,enumerable:!0,configurable:!1})},u={assign:Oe,defineProp:D,defineReadonly:Ee,defineMethod:Me},Q={isArray:Array.isArray},I={get:Reflect.get,set:Reflect.set,delete:Reflect.deleteProperty};var V={InvalidStore:{InvalidType:e=>[`[OrcheStore::StoreProvider] Expected a store instance created with createStore(...).
|
|
13
|
+
`,...E(e)]}},U={GetMissingProp:e=>["[OrcheStore::global-utils] Attempted to access a global utility before it became available. Missing property",e,`
|
|
14
14
|
If this utility is optional, register it as undefined using provideGlobalUtils(...) to suppress future warnings.
|
|
15
15
|
`],DeleteProp:e=>["[OrcheStore::global-utils] Avoid deleting properties. Trying to delete property",e,`
|
|
16
16
|
Use provideGlobalUtils(...) to set them to undefined instead for type safety.
|
|
17
17
|
`],InvalidArgs:()=>`[OrcheStore::global-utils] Expected provideGlobalUtils(...) to receive a non-null object.
|
|
18
|
-
`},
|
|
18
|
+
`},N={InvalidChild:e=>`[OrcheStore::createStore] Child slice '${e}' must be a slice created with createSlice(...).`,singletonLimitation:()=>`[OrcheStore::createStore] createStore(...) was called more than once.
|
|
19
19
|
OrcheStore currently supports only a single global store instance and will return the existing store.
|
|
20
20
|
If you are creating a store inside a React component, create it only once, for example:
|
|
21
21
|
const [store] = useState(() => createStore(...));
|
|
22
|
-
Avoid useState(createStore(...)) because createStore(...) will execute on every render.`},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
`,...
|
|
30
|
-
`:" ",RequiredName:(e,
|
|
22
|
+
Avoid useState(createStore(...)) because createStore(...) will execute on every render.`},b={InvalidStore:(e,t)=>({NeverExposed:[`[OrcheStore::${e}] Slice {${t}} is not reachable from any store instance.
|
|
23
|
+
A slice must be connected to a store via one of the following:
|
|
24
|
+
\u2022 createStore({ slices: ... }) \u2014 expose it directly in the root store
|
|
25
|
+
\u2022 createSlice({ children: ... }) \u2014 attach it under another slice that is already reachable`],InvalidType:r=>[`[OrcheStore::${e}] Slice {${t}} depends on parent slice {${r.name}}, but that parent is not reachable from any store instance.
|
|
26
|
+
Fix the parent first using one of the following:
|
|
27
|
+
\u2022 createStore({ slices: ... }) \u2014 expose the parent directly in the root store
|
|
28
|
+
\u2022 createSlice({ children: ... }) \u2014 attach the parent under another parent slice that is already reachable`]}),RequiredName:()=>"[OrcheStore::createSlice] Missing required slice name. Expected a non-empty string.",InvalidName:e=>`[OrcheStore::createSlice] Slice names cannot contain '.' or '/'. Received: {${e}}`,RequiredState:e=>`[OrcheStore::createSlice] Missing required state for slice {${e}}.`,InvalidState:(e,t)=>[`[OrcheStore::createSlice]${S.target({slice:e})}Slice state must be a non-null object or a function that returns a non-null object.
|
|
29
|
+
`,...E(t)],InvalidMutation:e=>`[OrcheStore::createSlice] Mutation '${e}' must be a function.`,InvalidMethod:e=>`[OrcheStore::createSlice] Method '${e}' must be a function.`,InvalidChild:e=>`[OrcheStore::createSlice] Child slice '${e}' must be a slice created with createSlice(...).`,ReduxReducerConflict:()=>"[OrcheStore::createSlice] Redux Toolkit asyncThunk reducers are not supported inside mutations. Use methods instead."},S={target:({slice:e})=>e?` Affected slice '${e}':
|
|
30
|
+
`:" ",RequiredName:(e,t)=>`[OrcheStore::${e.module}]${S.target(e)}${t} keys must be non-empty strings.`,InvalidName:(e,t,r)=>`[OrcheStore::${e.module}]${S.target(e)}${t} names cannot contain '.' or '/'. Received: ${r}.`,ReservedKey:(e,t,r)=>`[OrcheStore::${e.module}]${S.target(e)}'${r}' is a reserved name and cannot be used as a ${t} key.`,DuplicateKey:(e,t,r)=>`[OrcheStore::${e.module}]${S.target(e)}${t} name '${r}' conflicts with another member.`};var q=new Proxy({},{get(e,t,r){return t in e||l.error(...U.GetMissingProp(t)),I.get(e,t,r)},set(e,t,r,o){return I.set(e,t,r,o)},deleteProperty(e,t){return l.warn(...U.DeleteProp(t)),I.delete(e,t)}});function v(){return q}function L(e){let t=E(e,r=>r&&typeof r=="object"&&!Q.isArray(r));return t?l.error(U.InvalidArgs(),...t):u.assign(q,e),q}var{createNodeFactory:j}={createNodeFactory({factoryName:e,instantiate:t,options:r={}}){let o=new Map,i=new Map,p=d=>{d=r.adapt?r.adapt(d):d,d=r.register?r.register(d):d;let n={familyId:Symbol("family"),path:"",children:new Map,parents:[]},a={props:d,siblings:new Set};return n.node=t(d,n,a),a.siblings.add(n.node),o.set(n.node,n),i.set(n.familyId,a),n.node},x=(d,n)=>{let a=o.get(d),s=a?i.get(a.familyId):void 0;if(!a||!s){if(n?.UnknownNode)return void n?.UnknownNode?.("",d);throw new Error(`[OrcheStore] ${e} factory: Unknown node`)}return m("",[],a,s,!0,()=>{})},y=(d,n,a,s,c)=>{let f=o.get(n),w=f?i.get(f.familyId):void 0;if(!f||!w){if(c?.UnknownNode)return void c?.UnknownNode?.(d,n);throw new Error(`[OrcheStore] ${e} factory: Unknown node`)}let h=s||o.get(a);if(!h){if(c?.UnknownParent)return void c?.UnknownParent?.(d,n,a);throw new Error(`[OrcheStore] ${e} factory: Unknown parent node`)}for(let $ of[a,...h.parents])if($===n){if(c?.InfiniteOwnership)return void c?.InfiniteOwnership?.(d,n,a);throw new Error(`[OrcheStore] ${e} factory: Infinite ownership recursion`)}let O=(h.path?`${h.path}.`:"")+d,M=[a,...h.parents];return m(O,M,f,w,!1,$=>h.children.set(d,$))};function m(...d){let[n,a,s,c,f,w]=d;if(f=f||s.parents.length>0&&(s.parents[0]!==a[0]||s.path.split(".").at(-1)!==n.split(".").at(-1)),f){let h={familyId:s.familyId,path:n,children:new Map(s.children),parents:a},O=r.clone?r.clone(c.props,s,c):c.props;s=h,s.node=t(O,h,c),o.set(s.node,h),c.siblings.add(s.node)}s.path=n,s.parents=a,w?.(s.node);for(let[h,O]of[...s.children.entries()]){let M=o.get(O),$=M?i.get(M.familyId):void 0,de=`${n}${n?".":""}${h}`;m(de,[s.node,...a],M,$,!1,X=>{X!==O&&s.children.set(h,X)})}return s.node}return{families:i,instances:o,create:p,attach:y,clone:x}}};var G=require("@reduxjs/toolkit"),ee=require("react-redux");var Y=(e,t)=>{if(e)if(t==="warn")l.warn(e);else if(t==="error")l.error(e);else throw new Error(e);else return!1},z=(e,t="",r="",o)=>typeof e!="string"||!e?!!Y(t,o?.[0]):e.includes(".")||e.includes("/")?!!Y(r,o?.[1]):!0,$e=(e,t,r,o)=>{let i=S.RequiredName(e,t),p=S.InvalidName(e,t,r);if(z(r,i,p,["error","error"])){if(o[0].includes(r))return l.error(S.ReservedKey(e,t,r));if(o[1].includes(r))return l.error(S.DuplicateKey(e,t,r))}else return;return!0},A=e=>{let t=[],r=[e.reserved,t];return(o,i,p,x)=>{let y=i?[]:{};return Object.entries(p).forEach(([m,d])=>{let n=$e(e,o,m,r)?x(m,d):void 0;n!==void 0&&(i?y.push([m,n]):y[m]=n,t.push(m))}),y}},F=(e,t)=>{let r={...e||{}};return t.objects?.forEach(o=>{r[o]=typeof r[o]=="object"&&r[o]?{...r[o]}:{}}),t.validate?.(r),t.redux?.forEach(o=>{r[o]!==void 0&&l.warn(`[OrcheStore::${t.method}] '${o}' property is a Redux Toolkit option and is ignored by OrcheStore.`)}),t.unsupported?.forEach(o=>{Object.keys(r[o]).length<1||l.warn(`[OrcheStore::${t.method}] '${o}' property is not yet supported and will be ignored.`)}),r};var{families:Re,instances:P,create:Pe,attach:W,clone:Ce}=j({factoryName:"slice",instantiate(e,t,r){let o={},i=n=>T(void 0,t,n?b.InvalidStore(n,e.name):!1),p=A({module:"createSlice",slice:e.name,reserved:["name","path","computed","root","parent","prototype","global","getState","useSelect"]}),x=p("mutation",!1,e.mutations,(n,a)=>a?._reducerDefinitionType===G.ReducerType.asyncThunk||"reducer"in{...a||{}}?l.error(b.ReduxReducerConflict()):typeof a!="function"?l.error(b.InvalidMutation(n)):(c,f)=>f?.meta?.path===t.path?a(c,...f.payload):c);t.redux=(0,G.createSlice)({name:e.name,initialState:e.state,reducers:x}),u.defineReadonly(o,"name",()=>e.name),u.defineReadonly(o,"path",()=>t.path),u.defineReadonly(o,"global",()=>v()),u.defineReadonly(o,"root",()=>i().node),u.defineReadonly(o,"parent",()=>{let n=t.parents[0];return(n?P.get(n):void 0)?.node}),u.defineMethod(o,"getState",()=>{let n=i("slice.getState").redux.getState();return t.path.split(".").forEach(a=>n=(n||{})[a]),n}),u.defineMethod(o,"useSelect",n=>{let a={global:v(),root:i("slice.useSelect").node};return(0,ee.useSelector)(s=>(t.path.split(".").forEach(c=>s=(s||{})[c]),n.apply(a,[s,a])))}),u.defineReadonly(o,"computed",()=>{});let y={},m=()=>[...r.siblings.values()||[]];u.defineReadonly(o,"prototype",()=>y),u.defineMethod(y,"clone",()=>Ce(o)),u.defineMethod(y,"getLineage",()=>m()),u.defineMethod(y,"getClones",()=>m().filter(n=>n!==o)),u.defineMethod(y,"isTypeOf",n=>r===Re.get(P.get(n)?.familyId)),Object.entries(t.redux.actions).map(([n,a])=>{o[n]=(...s)=>{i("slice mutation").redux.dispatch({...a(s),meta:{path:t.path}})}}),p("method",!1,e.methods,(n,a)=>typeof a!="function"?l.error(b.InvalidMethod(n)):o[n]=(...s)=>a.apply(o,s));let d=p("child",!0,e.children,(n,a)=>{let c=W(n,a,o,t,{UnknownNode:f=>l.error(b.InvalidChild(f))});if(c)return o[n]=c,P.get(c).reducers});return t.reducers=(n,a)=>{let s=a?.meta?.path;if(typeof s=="string"&&!s.startsWith(t.path))return n;let c={...t.redux.reducer(n,a)};for(let[f,w]of d)c[f]=w(c?.[f],a);return c},o},options:{adapt(e){return F(e,{method:"createSlice",objects:["mutations","computed","methods","children"],unsupported:["computed"],redux:["reducers","extraReducers","reducerPath","initialState","selectors"],validate(t){z(t.name,b.RequiredName(),b.InvalidName(t.name));let r=t.state;if(typeof r!="function")return void Z(t.name,r);t.state=()=>Z(t.name,r())}})},clone(e,t){let r=t.redux.getInitialState();return{...e,state:r}}}}),Z=(e,t)=>{if(typeof t!="object"){let r=b.InvalidState(e,t);throw r.every(o=>typeof o=="string")?new Error(r.join(" ")):(l.error(...r),new Error)}if(!t)throw new Error(b.RequiredState(e));return t},te=e=>Pe(e);var{instances:re,create:Ie}=j({factoryName:"slice",instantiate(e,t){let r={},o=A({module:"createStore",reserved:["name","computed","global","getState","useSelect"]});return u.defineReadonly(r,"name",()=>"default"),u.defineReadonly(r,"global",()=>v()),u.defineMethod(r,"getState",()=>t.redux.getState()),u.defineMethod(r,"useSelect",i=>{let p={global:v(),root:r};return(0,ne.useSelector)(x=>i.apply(p,[x,p]))}),t.reducers=o("slice",!1,e.slices,(i,p)=>{let y=W(i,p,r,t,{UnknownNode:m=>l.error(N.InvalidChild(m))});if(y)return r[i]=y,P.get(y).reducers}),t.redux=(0,oe.configureStore)({reducer:t.reducers}),r},options:{adapt(e){return F(e,{method:"createStore",objects:["slices"],redux:["reducer","devTools","duplicateMiddlewareCheck","enhancers","middleware","preloadedState"]})}}}),T=(e,t,r=!1)=>{if(r===!0)return[...re.values()][0];e||=t?.parents?.at?.(-1);let o=e?re.get(e):void 0,i=[];if(t&&!e?i=r===!1?[]:r.NeverExposed:o||(i=r===!1?[]:r.InvalidType(e)),i&&i.length)throw i.every(p=>typeof p=="string")?new Error(i.join(" ")):(l.error(...i),new Error);return o},ae=e=>Ie(e);var ie=ge(require("react"),1),se=require("react-redux");function J(e){let{store:t,...r}={...e||{}},o=T(t,void 0,V.InvalidStore);return ie.default.createElement(se.Provider,{...r,store:o.redux})}var le=e=>(l.inform("prerelease"),te(e)),ce=e=>(l.inform("prerelease"),T(void 0,void 0,!0)?(l.warn(N.singletonLimitation()),T(void 0,void 0,!0).node):ae(e)),Ue={createStore:ce,createSlice:le,StoreProvider:J,provideGlobalUtils:L,getGlobalUtils:v,configureDiagnostics:K};0&&(module.exports={StoreProvider,configureDiagnostics,createSlice,createStore,getGlobalUtils,provideGlobalUtils});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ProviderProps } from 'react-redux';
|
|
3
3
|
|
|
4
|
-
/**
|
|
4
|
+
/** `Record` with string keys, requiring only the value type. */
|
|
5
5
|
type Dict<Value = any> = Record<string, Value>;
|
|
6
|
+
/** `Record` with default property keys, requiring only the value type. */
|
|
7
|
+
type Obj<Value = any> = Record<PropertyKey, Value>;
|
|
6
8
|
/** Returns all tuple elements except the first. */
|
|
7
9
|
type Tail<T extends any[]> = T extends [any, ...infer R] ? R : T extends (infer U)[] ? U[] : never;
|
|
8
10
|
/** Removes properties whose value type is `never`. */
|
|
@@ -15,24 +17,44 @@ type ReadOnly<T> = T extends (...args: any[]) => any ? T : T extends readonly (i
|
|
|
15
17
|
} : T;
|
|
16
18
|
|
|
17
19
|
/** Runtime slice API exposed by createSlice(...). */
|
|
18
|
-
type slice<S, R extends Mutations<S>, M> = GlobalUtils & {
|
|
20
|
+
type slice<S extends Obj, R extends Mutations<S, C>, M, C> = GlobalUtils & {
|
|
19
21
|
/** Unique slice identifier. */
|
|
20
22
|
readonly name: string;
|
|
23
|
+
/** Fully qualified runtime path of the slice. */
|
|
24
|
+
readonly path: string;
|
|
21
25
|
/** Returns the latest immutable state snapshot. */
|
|
22
|
-
readonly getState: () => SliceState<S,
|
|
26
|
+
readonly getState: () => SliceState.State<S, C>;
|
|
23
27
|
/** Subscribes to state changes within React components. Runs with a context-bound `this` containing `root` store, `rootState` and `global` utilities. */
|
|
24
|
-
readonly useSelect: <T>(selector: (this: GlobalUtils, state: SliceState<S,
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
readonly useSelect: <T>(selector: (this: GlobalUtils, state: SliceState.State<S, C>, context: GlobalUtils) => T) => T;
|
|
29
|
+
/** Root store that owns this slice instance. */
|
|
30
|
+
root: store<any>;
|
|
31
|
+
/** Parent slice in the hierarchy, if mounted under another slice. */
|
|
32
|
+
parent: slice<any, Mutations<any, any>, any, any> | undefined;
|
|
33
|
+
/** Runtime lineage and cloning utilities for this slice instance. */
|
|
34
|
+
readonly prototype: {
|
|
35
|
+
/** Creates a new detached clone within the same lineage. */
|
|
36
|
+
readonly clone: () => slice<S, R, M, C>;
|
|
37
|
+
/** Returns all slice instances in the same lineage, including this one. */
|
|
38
|
+
readonly getLineage: () => slice<S, R, M, C>[];
|
|
39
|
+
/** Returns all sibling instances in the same lineage, excluding this one. */
|
|
40
|
+
readonly getClones: () => slice<S, R, M, C>[];
|
|
41
|
+
/** Returns true if both slices belong to the same lineage. */
|
|
42
|
+
readonly isTypeOf: (other: any) => boolean;
|
|
43
|
+
};
|
|
44
|
+
/** Collection of derived state functions. */
|
|
45
|
+
readonly computed: undefined;
|
|
46
|
+
} & OmitNever<{
|
|
28
47
|
/** Exposed mutation functions. */
|
|
29
|
-
readonly [K in Exclude<keyof R, ReservedSliceKeys>]: (...args: Tail<Parameters<R[K]>>) =>
|
|
30
|
-
} & {
|
|
48
|
+
readonly [K in Exclude<keyof R, ReservedSliceKeys>]: R[K] extends (...args: any[]) => void ? (...args: Tail<Parameters<R[K]>>) => void : never;
|
|
49
|
+
}> & OmitNever<{
|
|
31
50
|
/** Exposed method functions. */
|
|
32
|
-
readonly [K in Exclude<keyof M, ReservedSliceKeys<R>>]: M[K];
|
|
33
|
-
} & {
|
|
51
|
+
readonly [K in Exclude<keyof M, ReservedSliceKeys<R>>]: M[K] extends (...args: any[]) => void ? M[K] : never;
|
|
52
|
+
}> & OmitNever<{
|
|
53
|
+
/** Exposed children. */
|
|
54
|
+
readonly [K in Exclude<keyof C, ReservedSliceKeys<R, M>>]: C[K] extends slice<infer S, infer R, infer M, infer C> ? slice<S, R, M, C> : never;
|
|
55
|
+
}>;
|
|
34
56
|
/** Configuration object used to create a slice. */
|
|
35
|
-
type sliceOptions<S, R extends Mutations<S>, M> = {
|
|
57
|
+
type sliceOptions<S extends Obj, R extends Mutations<S, C>, M, C> = {
|
|
36
58
|
/** Unique slice identifier. */
|
|
37
59
|
name: string;
|
|
38
60
|
/** Initial state object or lazy state initializer. */
|
|
@@ -40,26 +62,44 @@ type sliceOptions<S, R extends Mutations<S>, M> = {
|
|
|
40
62
|
/** Collection of synchronous state transition functions. */
|
|
41
63
|
mutations?: R & ThisType<GlobalUtils>;
|
|
42
64
|
/** Collection of slice methods and orchestration logic. */
|
|
43
|
-
methods?: M & ThisType<slice<S, R, M> & {
|
|
65
|
+
methods?: M & ThisType<slice<S, R, M, C> & {
|
|
44
66
|
root: RootStore;
|
|
45
67
|
}>;
|
|
68
|
+
/** Collection of derived state functions. */ /** Collection of nested child slices. */
|
|
69
|
+
children?: C;
|
|
46
70
|
};
|
|
47
71
|
/** Defines the mutations available on a slice. */
|
|
48
|
-
type Mutations<S> = Dict<(state: SliceState<S,
|
|
72
|
+
type Mutations<S extends Obj, C> = Dict<(state: SliceState.Draft<S, C>, ...args: any[]) => void | SliceState.Draft<S, C>>;
|
|
49
73
|
/** Derived state shape exposed by a slice, excluding internal framework fields. */
|
|
50
|
-
|
|
74
|
+
declare namespace SliceState {
|
|
75
|
+
type InferState<C> = C extends Obj ? (C["getState"] extends () => infer S ? S extends Obj ? S : never : never) : never;
|
|
76
|
+
export type State<S extends Obj, C> = ReadOnly<Omit<S, "computed" | keyof OmitNever<{
|
|
77
|
+
[K in keyof C]: InferState<C[K]>;
|
|
78
|
+
}>> & OmitNever<{
|
|
79
|
+
[K in keyof C]: InferState<C[K]>;
|
|
80
|
+
}>>;
|
|
81
|
+
export type Draft<S extends Obj, C> = Omit<S, "computed" | keyof OmitNever<{
|
|
82
|
+
[K in keyof C]: C[K] extends AnySlice ? true : never;
|
|
83
|
+
}>> & OmitNever<{
|
|
84
|
+
[K in keyof C]: C[K] extends slice<infer S, infer _, infer __, infer C> ? Draft<S, C> : never;
|
|
85
|
+
}>;
|
|
86
|
+
export { };
|
|
87
|
+
}
|
|
51
88
|
/** Reserved slice member names that cannot be overridden by user-defined APIs. */
|
|
52
|
-
type ReservedSliceKeys<R = {}, M = {}> = ("name" | "computed" | "root" | "
|
|
89
|
+
type ReservedSliceKeys<R = {}, M = {}> = ("name" | "path" | "computed" | "root" | "parent" | "prototype" | "global" | "getState" | "useSelect") | (keyof R | keyof M);
|
|
90
|
+
type AnySlice = slice<any, Mutations<any, any>, any, any>;
|
|
53
91
|
|
|
54
92
|
/** Runtime store API exposed by createStore(...). */
|
|
55
93
|
type store<C> = OmitNever<GlobalUtils & {
|
|
94
|
+
/** Unique store identifier. Currently this is set to "default" and is nt configurable */
|
|
95
|
+
readonly name: "default";
|
|
56
96
|
/** Returns the latest immutable state snapshot. */
|
|
57
97
|
readonly getState: () => StoreState<C>;
|
|
58
98
|
/** Subscribes to state changes within React components. Runs with a context-bound `this` containing `global` utilities. */
|
|
59
99
|
readonly useSelect: <T>(selector: (this: GlobalUtils, state: StoreState<C>, context: GlobalUtils) => T) => T;
|
|
60
100
|
} & {
|
|
61
101
|
/** Exposed slices. */
|
|
62
|
-
readonly [K in Exclude<keyof C, ReservedStoreKeys>]: C[K] extends slice<infer S, infer R, infer M> ? slice<S, R, M> : never;
|
|
102
|
+
readonly [K in Exclude<keyof C, ReservedStoreKeys>]: C[K] extends slice<infer S, infer R, infer M, infer C> ? slice<S, R, M, C> : never;
|
|
63
103
|
}>;
|
|
64
104
|
/** Configuration object used to create a store. */
|
|
65
105
|
type storeOptions<C> = {
|
|
@@ -68,7 +108,7 @@ type storeOptions<C> = {
|
|
|
68
108
|
};
|
|
69
109
|
/** Derived immutable state shape of the store. */
|
|
70
110
|
type StoreState<C> = ReadOnly<OmitNever<{
|
|
71
|
-
readonly [K in Exclude<keyof C, ReservedStoreKeys>]: C[K] extends slice<infer S, infer _, infer __> ? SliceState<S,
|
|
111
|
+
readonly [K in Exclude<keyof C, ReservedStoreKeys>]: C[K] extends slice<infer S, infer _, infer __, infer C> ? SliceState.State<S, C> : never;
|
|
72
112
|
}>>;
|
|
73
113
|
/** Props accepted by the store provider component. */
|
|
74
114
|
type StoreProviderProps<T = any> = Omit<ProviderProps, "store" | "serverState" | "context"> & {
|
|
@@ -105,9 +145,9 @@ declare global {
|
|
|
105
145
|
/** Configuration object used to create a store. */
|
|
106
146
|
type StoreOptions<C> = storeOptions<C>;
|
|
107
147
|
/** Runtime slice API exposed by createSlice(...). */
|
|
108
|
-
type Slice<S, R extends Mutations<S>, M> = slice<S, R, M>;
|
|
148
|
+
type Slice<S extends Obj, R extends Mutations<S, C>, M, C> = slice<S, R, M, C>;
|
|
109
149
|
/** Configuration object used to create a slice. */
|
|
110
|
-
type SliceOptions<S, R extends Mutations<S>, M> = sliceOptions<S, R, M>;
|
|
150
|
+
type SliceOptions<S extends Obj, R extends Mutations<S, C>, M, C> = sliceOptions<S, R, M, C>;
|
|
111
151
|
}
|
|
112
152
|
}
|
|
113
153
|
|
|
@@ -120,14 +160,14 @@ declare function provideGlobalUtils(value: Partial<GlobalUtils["global"]>): Glob
|
|
|
120
160
|
declare function configureDiagnostics(level: "off" | "errors" | "all"): void;
|
|
121
161
|
|
|
122
162
|
/** Creates and initializes an OrcheStore slice. */
|
|
123
|
-
declare const createSliceWrapper: <S, R extends Mutations<S>, M>(props: sliceOptions<S, R, M>) => slice<S, R, M>;
|
|
163
|
+
declare const createSliceWrapper: <S extends Obj, R extends Mutations<S, C>, M, C>(props: sliceOptions<S, R, M, C>) => slice<S, R, M, C>;
|
|
124
164
|
/** Creates and initializes an OrcheStore instance. */
|
|
125
165
|
declare const createStoreWrapper: <T>(props: storeOptions<T>) => store<T>;
|
|
126
166
|
declare const defaultExport: {
|
|
127
167
|
/** Creates and initializes an OrcheStore instance. */
|
|
128
168
|
createStore: <T>(props: storeOptions<T>) => store<T>;
|
|
129
169
|
/** Creates and initializes an OrcheStore slice. */
|
|
130
|
-
createSlice: <S, R extends Mutations<S>, M>(props: sliceOptions<S, R, M>) => slice<S, R, M>;
|
|
170
|
+
createSlice: <S extends Obj, R extends Mutations<S, C>, M, C>(props: sliceOptions<S, R, M, C>) => slice<S, R, M, C>;
|
|
131
171
|
/** Provides an OrcheStore instance to the React component tree. */
|
|
132
172
|
StoreProvider: typeof StoreProvider;
|
|
133
173
|
/** Registers or updates application-wide global utilities. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ProviderProps } from 'react-redux';
|
|
3
3
|
|
|
4
|
-
/**
|
|
4
|
+
/** `Record` with string keys, requiring only the value type. */
|
|
5
5
|
type Dict<Value = any> = Record<string, Value>;
|
|
6
|
+
/** `Record` with default property keys, requiring only the value type. */
|
|
7
|
+
type Obj<Value = any> = Record<PropertyKey, Value>;
|
|
6
8
|
/** Returns all tuple elements except the first. */
|
|
7
9
|
type Tail<T extends any[]> = T extends [any, ...infer R] ? R : T extends (infer U)[] ? U[] : never;
|
|
8
10
|
/** Removes properties whose value type is `never`. */
|
|
@@ -15,24 +17,44 @@ type ReadOnly<T> = T extends (...args: any[]) => any ? T : T extends readonly (i
|
|
|
15
17
|
} : T;
|
|
16
18
|
|
|
17
19
|
/** Runtime slice API exposed by createSlice(...). */
|
|
18
|
-
type slice<S, R extends Mutations<S>, M> = GlobalUtils & {
|
|
20
|
+
type slice<S extends Obj, R extends Mutations<S, C>, M, C> = GlobalUtils & {
|
|
19
21
|
/** Unique slice identifier. */
|
|
20
22
|
readonly name: string;
|
|
23
|
+
/** Fully qualified runtime path of the slice. */
|
|
24
|
+
readonly path: string;
|
|
21
25
|
/** Returns the latest immutable state snapshot. */
|
|
22
|
-
readonly getState: () => SliceState<S,
|
|
26
|
+
readonly getState: () => SliceState.State<S, C>;
|
|
23
27
|
/** Subscribes to state changes within React components. Runs with a context-bound `this` containing `root` store, `rootState` and `global` utilities. */
|
|
24
|
-
readonly useSelect: <T>(selector: (this: GlobalUtils, state: SliceState<S,
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
readonly useSelect: <T>(selector: (this: GlobalUtils, state: SliceState.State<S, C>, context: GlobalUtils) => T) => T;
|
|
29
|
+
/** Root store that owns this slice instance. */
|
|
30
|
+
root: store<any>;
|
|
31
|
+
/** Parent slice in the hierarchy, if mounted under another slice. */
|
|
32
|
+
parent: slice<any, Mutations<any, any>, any, any> | undefined;
|
|
33
|
+
/** Runtime lineage and cloning utilities for this slice instance. */
|
|
34
|
+
readonly prototype: {
|
|
35
|
+
/** Creates a new detached clone within the same lineage. */
|
|
36
|
+
readonly clone: () => slice<S, R, M, C>;
|
|
37
|
+
/** Returns all slice instances in the same lineage, including this one. */
|
|
38
|
+
readonly getLineage: () => slice<S, R, M, C>[];
|
|
39
|
+
/** Returns all sibling instances in the same lineage, excluding this one. */
|
|
40
|
+
readonly getClones: () => slice<S, R, M, C>[];
|
|
41
|
+
/** Returns true if both slices belong to the same lineage. */
|
|
42
|
+
readonly isTypeOf: (other: any) => boolean;
|
|
43
|
+
};
|
|
44
|
+
/** Collection of derived state functions. */
|
|
45
|
+
readonly computed: undefined;
|
|
46
|
+
} & OmitNever<{
|
|
28
47
|
/** Exposed mutation functions. */
|
|
29
|
-
readonly [K in Exclude<keyof R, ReservedSliceKeys>]: (...args: Tail<Parameters<R[K]>>) =>
|
|
30
|
-
} & {
|
|
48
|
+
readonly [K in Exclude<keyof R, ReservedSliceKeys>]: R[K] extends (...args: any[]) => void ? (...args: Tail<Parameters<R[K]>>) => void : never;
|
|
49
|
+
}> & OmitNever<{
|
|
31
50
|
/** Exposed method functions. */
|
|
32
|
-
readonly [K in Exclude<keyof M, ReservedSliceKeys<R>>]: M[K];
|
|
33
|
-
} & {
|
|
51
|
+
readonly [K in Exclude<keyof M, ReservedSliceKeys<R>>]: M[K] extends (...args: any[]) => void ? M[K] : never;
|
|
52
|
+
}> & OmitNever<{
|
|
53
|
+
/** Exposed children. */
|
|
54
|
+
readonly [K in Exclude<keyof C, ReservedSliceKeys<R, M>>]: C[K] extends slice<infer S, infer R, infer M, infer C> ? slice<S, R, M, C> : never;
|
|
55
|
+
}>;
|
|
34
56
|
/** Configuration object used to create a slice. */
|
|
35
|
-
type sliceOptions<S, R extends Mutations<S>, M> = {
|
|
57
|
+
type sliceOptions<S extends Obj, R extends Mutations<S, C>, M, C> = {
|
|
36
58
|
/** Unique slice identifier. */
|
|
37
59
|
name: string;
|
|
38
60
|
/** Initial state object or lazy state initializer. */
|
|
@@ -40,26 +62,44 @@ type sliceOptions<S, R extends Mutations<S>, M> = {
|
|
|
40
62
|
/** Collection of synchronous state transition functions. */
|
|
41
63
|
mutations?: R & ThisType<GlobalUtils>;
|
|
42
64
|
/** Collection of slice methods and orchestration logic. */
|
|
43
|
-
methods?: M & ThisType<slice<S, R, M> & {
|
|
65
|
+
methods?: M & ThisType<slice<S, R, M, C> & {
|
|
44
66
|
root: RootStore;
|
|
45
67
|
}>;
|
|
68
|
+
/** Collection of derived state functions. */ /** Collection of nested child slices. */
|
|
69
|
+
children?: C;
|
|
46
70
|
};
|
|
47
71
|
/** Defines the mutations available on a slice. */
|
|
48
|
-
type Mutations<S> = Dict<(state: SliceState<S,
|
|
72
|
+
type Mutations<S extends Obj, C> = Dict<(state: SliceState.Draft<S, C>, ...args: any[]) => void | SliceState.Draft<S, C>>;
|
|
49
73
|
/** Derived state shape exposed by a slice, excluding internal framework fields. */
|
|
50
|
-
|
|
74
|
+
declare namespace SliceState {
|
|
75
|
+
type InferState<C> = C extends Obj ? (C["getState"] extends () => infer S ? S extends Obj ? S : never : never) : never;
|
|
76
|
+
export type State<S extends Obj, C> = ReadOnly<Omit<S, "computed" | keyof OmitNever<{
|
|
77
|
+
[K in keyof C]: InferState<C[K]>;
|
|
78
|
+
}>> & OmitNever<{
|
|
79
|
+
[K in keyof C]: InferState<C[K]>;
|
|
80
|
+
}>>;
|
|
81
|
+
export type Draft<S extends Obj, C> = Omit<S, "computed" | keyof OmitNever<{
|
|
82
|
+
[K in keyof C]: C[K] extends AnySlice ? true : never;
|
|
83
|
+
}>> & OmitNever<{
|
|
84
|
+
[K in keyof C]: C[K] extends slice<infer S, infer _, infer __, infer C> ? Draft<S, C> : never;
|
|
85
|
+
}>;
|
|
86
|
+
export { };
|
|
87
|
+
}
|
|
51
88
|
/** Reserved slice member names that cannot be overridden by user-defined APIs. */
|
|
52
|
-
type ReservedSliceKeys<R = {}, M = {}> = ("name" | "computed" | "root" | "
|
|
89
|
+
type ReservedSliceKeys<R = {}, M = {}> = ("name" | "path" | "computed" | "root" | "parent" | "prototype" | "global" | "getState" | "useSelect") | (keyof R | keyof M);
|
|
90
|
+
type AnySlice = slice<any, Mutations<any, any>, any, any>;
|
|
53
91
|
|
|
54
92
|
/** Runtime store API exposed by createStore(...). */
|
|
55
93
|
type store<C> = OmitNever<GlobalUtils & {
|
|
94
|
+
/** Unique store identifier. Currently this is set to "default" and is nt configurable */
|
|
95
|
+
readonly name: "default";
|
|
56
96
|
/** Returns the latest immutable state snapshot. */
|
|
57
97
|
readonly getState: () => StoreState<C>;
|
|
58
98
|
/** Subscribes to state changes within React components. Runs with a context-bound `this` containing `global` utilities. */
|
|
59
99
|
readonly useSelect: <T>(selector: (this: GlobalUtils, state: StoreState<C>, context: GlobalUtils) => T) => T;
|
|
60
100
|
} & {
|
|
61
101
|
/** Exposed slices. */
|
|
62
|
-
readonly [K in Exclude<keyof C, ReservedStoreKeys>]: C[K] extends slice<infer S, infer R, infer M> ? slice<S, R, M> : never;
|
|
102
|
+
readonly [K in Exclude<keyof C, ReservedStoreKeys>]: C[K] extends slice<infer S, infer R, infer M, infer C> ? slice<S, R, M, C> : never;
|
|
63
103
|
}>;
|
|
64
104
|
/** Configuration object used to create a store. */
|
|
65
105
|
type storeOptions<C> = {
|
|
@@ -68,7 +108,7 @@ type storeOptions<C> = {
|
|
|
68
108
|
};
|
|
69
109
|
/** Derived immutable state shape of the store. */
|
|
70
110
|
type StoreState<C> = ReadOnly<OmitNever<{
|
|
71
|
-
readonly [K in Exclude<keyof C, ReservedStoreKeys>]: C[K] extends slice<infer S, infer _, infer __> ? SliceState<S,
|
|
111
|
+
readonly [K in Exclude<keyof C, ReservedStoreKeys>]: C[K] extends slice<infer S, infer _, infer __, infer C> ? SliceState.State<S, C> : never;
|
|
72
112
|
}>>;
|
|
73
113
|
/** Props accepted by the store provider component. */
|
|
74
114
|
type StoreProviderProps<T = any> = Omit<ProviderProps, "store" | "serverState" | "context"> & {
|
|
@@ -105,9 +145,9 @@ declare global {
|
|
|
105
145
|
/** Configuration object used to create a store. */
|
|
106
146
|
type StoreOptions<C> = storeOptions<C>;
|
|
107
147
|
/** Runtime slice API exposed by createSlice(...). */
|
|
108
|
-
type Slice<S, R extends Mutations<S>, M> = slice<S, R, M>;
|
|
148
|
+
type Slice<S extends Obj, R extends Mutations<S, C>, M, C> = slice<S, R, M, C>;
|
|
109
149
|
/** Configuration object used to create a slice. */
|
|
110
|
-
type SliceOptions<S, R extends Mutations<S>, M> = sliceOptions<S, R, M>;
|
|
150
|
+
type SliceOptions<S extends Obj, R extends Mutations<S, C>, M, C> = sliceOptions<S, R, M, C>;
|
|
111
151
|
}
|
|
112
152
|
}
|
|
113
153
|
|
|
@@ -120,14 +160,14 @@ declare function provideGlobalUtils(value: Partial<GlobalUtils["global"]>): Glob
|
|
|
120
160
|
declare function configureDiagnostics(level: "off" | "errors" | "all"): void;
|
|
121
161
|
|
|
122
162
|
/** Creates and initializes an OrcheStore slice. */
|
|
123
|
-
declare const createSliceWrapper: <S, R extends Mutations<S>, M>(props: sliceOptions<S, R, M>) => slice<S, R, M>;
|
|
163
|
+
declare const createSliceWrapper: <S extends Obj, R extends Mutations<S, C>, M, C>(props: sliceOptions<S, R, M, C>) => slice<S, R, M, C>;
|
|
124
164
|
/** Creates and initializes an OrcheStore instance. */
|
|
125
165
|
declare const createStoreWrapper: <T>(props: storeOptions<T>) => store<T>;
|
|
126
166
|
declare const defaultExport: {
|
|
127
167
|
/** Creates and initializes an OrcheStore instance. */
|
|
128
168
|
createStore: <T>(props: storeOptions<T>) => store<T>;
|
|
129
169
|
/** Creates and initializes an OrcheStore slice. */
|
|
130
|
-
createSlice: <S, R extends Mutations<S>, M>(props: sliceOptions<S, R, M>) => slice<S, R, M>;
|
|
170
|
+
createSlice: <S extends Obj, R extends Mutations<S, C>, M, C>(props: sliceOptions<S, R, M, C>) => slice<S, R, M, C>;
|
|
131
171
|
/** Provides an OrcheStore instance to the React component tree. */
|
|
132
172
|
StoreProvider: typeof StoreProvider;
|
|
133
173
|
/** Registers or updates application-wide global utilities. */
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import{configureStore as
|
|
1
|
+
import{configureStore as ge}from"@reduxjs/toolkit";import{useSelector as Se}from"react-redux";var P="all",G={diagnostics:!1,prerelease:!1},z=globalThis.console?.log?.bind?.(globalThis.console)||globalThis.console?.log,re=globalThis.console?.warn?.bind?.(globalThis.console)||globalThis.console?.warn,oe=globalThis.console?.error?.bind?.(globalThis.console)||globalThis.console?.error,ne=globalThis.console?.clear?.bind?.(globalThis.console)||globalThis.console?.clear;globalThis.console?.clear&&(globalThis.console.clear=(...e)=>{G.diagnostics=!1,ne?.(...e)});var ae=`[OrcheStore] \u{1F6A7} Pre-release Notice
|
|
2
2
|
Thank you for your interest in OrcheStore.
|
|
3
3
|
OrcheStore is currently under active development and is not yet ready for production use.
|
|
4
4
|
APIs, behavior, and internal implementation details may change without notice.
|
|
5
5
|
The first stable release is currently planned for 2026-06-30.
|
|
6
6
|
Stay tuned for updates!
|
|
7
|
-
`,
|
|
7
|
+
`,ie=`[OrcheStore] Diagnostics are enabled.
|
|
8
8
|
OrcheStore may emit warnings and errors to help identify incorrect usage, invalid configurations, and potential runtime issues.
|
|
9
9
|
Runtime exceptions that stop code execution may still occur regardless of diagnostics settings.
|
|
10
10
|
Please resolve all OrcheStore warnings and errors before deploying to production.
|
|
11
11
|
Diagnostics can be configured with configureDiagnostics("off" | "errors" | "all").
|
|
12
|
-
`,
|
|
13
|
-
`,...
|
|
12
|
+
`,l={inform(e){G[e]||(G[e]=!0,P==="all"&&z?.(e==="prerelease"?ae:ie))},log(...e){P==="all"&&(l.inform("diagnostics"),z?.(...e))},warn(...e){P==="all"&&(l.inform("diagnostics"),re?.(...e))},error(...e){P!=="off"&&(l.inform("diagnostics"),oe?.(...e))}};function W(e){P=e}var J=(...e)=>{let[t,r]=[e[2],e[3]],o=`${e[0]||"Received"}: `,s=e[1]!==!1?"(type: "+typeof t+")":"";if(!r?.(t))return t==null?[`${o}(type: ${t})`]:typeof t=="number"||typeof t=="bigint"||typeof t=="boolean"?[`${o}${s} ${t}`]:typeof t=="object"?[o,t]:t===""?[`${o}Empty String`]:[`${o}${s}`,t]},M=((e,t)=>J("Received",!0,e,t));M.prefixed=(e,t,r,o)=>J(e,t,r,o);var se=Object.assign,k=Object.getOwnPropertyDescriptor(Object,"defineProperty")?.value||Object.defineProperty,le=(e,t,r)=>{k(e,t,{get:r,enumerable:!0,configurable:!1})},ce=(e,t,r)=>{k(e,t,{value:r,writable:!1,enumerable:!0,configurable:!1})},u={assign:se,defineProp:k,defineReadonly:le,defineMethod:ce},X={isArray:Array.isArray},I={get:Reflect.get,set:Reflect.set,delete:Reflect.deleteProperty};var _={InvalidStore:{InvalidType:e=>[`[OrcheStore::StoreProvider] Expected a store instance created with createStore(...).
|
|
13
|
+
`,...M(e)]}},U={GetMissingProp:e=>["[OrcheStore::global-utils] Attempted to access a global utility before it became available. Missing property",e,`
|
|
14
14
|
If this utility is optional, register it as undefined using provideGlobalUtils(...) to suppress future warnings.
|
|
15
15
|
`],DeleteProp:e=>["[OrcheStore::global-utils] Avoid deleting properties. Trying to delete property",e,`
|
|
16
16
|
Use provideGlobalUtils(...) to set them to undefined instead for type safety.
|
|
17
17
|
`],InvalidArgs:()=>`[OrcheStore::global-utils] Expected provideGlobalUtils(...) to receive a non-null object.
|
|
18
|
-
`},
|
|
18
|
+
`},N={InvalidChild:e=>`[OrcheStore::createStore] Child slice '${e}' must be a slice created with createSlice(...).`,singletonLimitation:()=>`[OrcheStore::createStore] createStore(...) was called more than once.
|
|
19
19
|
OrcheStore currently supports only a single global store instance and will return the existing store.
|
|
20
20
|
If you are creating a store inside a React component, create it only once, for example:
|
|
21
21
|
const [store] = useState(() => createStore(...));
|
|
22
|
-
Avoid useState(createStore(...)) because createStore(...) will execute on every render.`},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
`,...
|
|
30
|
-
`:" ",RequiredName:(e,
|
|
22
|
+
Avoid useState(createStore(...)) because createStore(...) will execute on every render.`},v={InvalidStore:(e,t)=>({NeverExposed:[`[OrcheStore::${e}] Slice {${t}} is not reachable from any store instance.
|
|
23
|
+
A slice must be connected to a store via one of the following:
|
|
24
|
+
\u2022 createStore({ slices: ... }) \u2014 expose it directly in the root store
|
|
25
|
+
\u2022 createSlice({ children: ... }) \u2014 attach it under another slice that is already reachable`],InvalidType:r=>[`[OrcheStore::${e}] Slice {${t}} depends on parent slice {${r.name}}, but that parent is not reachable from any store instance.
|
|
26
|
+
Fix the parent first using one of the following:
|
|
27
|
+
\u2022 createStore({ slices: ... }) \u2014 expose the parent directly in the root store
|
|
28
|
+
\u2022 createSlice({ children: ... }) \u2014 attach the parent under another parent slice that is already reachable`]}),RequiredName:()=>"[OrcheStore::createSlice] Missing required slice name. Expected a non-empty string.",InvalidName:e=>`[OrcheStore::createSlice] Slice names cannot contain '.' or '/'. Received: {${e}}`,RequiredState:e=>`[OrcheStore::createSlice] Missing required state for slice {${e}}.`,InvalidState:(e,t)=>[`[OrcheStore::createSlice]${b.target({slice:e})}Slice state must be a non-null object or a function that returns a non-null object.
|
|
29
|
+
`,...M(t)],InvalidMutation:e=>`[OrcheStore::createSlice] Mutation '${e}' must be a function.`,InvalidMethod:e=>`[OrcheStore::createSlice] Method '${e}' must be a function.`,InvalidChild:e=>`[OrcheStore::createSlice] Child slice '${e}' must be a slice created with createSlice(...).`,ReduxReducerConflict:()=>"[OrcheStore::createSlice] Redux Toolkit asyncThunk reducers are not supported inside mutations. Use methods instead."},b={target:({slice:e})=>e?` Affected slice '${e}':
|
|
30
|
+
`:" ",RequiredName:(e,t)=>`[OrcheStore::${e.module}]${b.target(e)}${t} keys must be non-empty strings.`,InvalidName:(e,t,r)=>`[OrcheStore::${e.module}]${b.target(e)}${t} names cannot contain '.' or '/'. Received: ${r}.`,ReservedKey:(e,t,r)=>`[OrcheStore::${e.module}]${b.target(e)}'${r}' is a reserved name and cannot be used as a ${t} key.`,DuplicateKey:(e,t,r)=>`[OrcheStore::${e.module}]${b.target(e)}${t} name '${r}' conflicts with another member.`};var K=new Proxy({},{get(e,t,r){return t in e||l.error(...U.GetMissingProp(t)),I.get(e,t,r)},set(e,t,r,o){return I.set(e,t,r,o)},deleteProperty(e,t){return l.warn(...U.DeleteProp(t)),I.delete(e,t)}});function T(){return K}function B(e){let t=M(e,r=>r&&typeof r=="object"&&!X.isArray(r));return t?l.error(U.InvalidArgs(),...t):u.assign(K,e),K}var{createNodeFactory:j}={createNodeFactory({factoryName:e,instantiate:t,options:r={}}){let o=new Map,s=new Map,p=d=>{d=r.adapt?r.adapt(d):d,d=r.register?r.register(d):d;let n={familyId:Symbol("family"),path:"",children:new Map,parents:[]},a={props:d,siblings:new Set};return n.node=t(d,n,a),a.siblings.add(n.node),o.set(n.node,n),s.set(n.familyId,a),n.node},x=(d,n)=>{let a=o.get(d),i=a?s.get(a.familyId):void 0;if(!a||!i){if(n?.UnknownNode)return void n?.UnknownNode?.("",d);throw new Error(`[OrcheStore] ${e} factory: Unknown node`)}return m("",[],a,i,!0,()=>{})},y=(d,n,a,i,c)=>{let f=o.get(n),O=f?s.get(f.familyId):void 0;if(!f||!O){if(c?.UnknownNode)return void c?.UnknownNode?.(d,n);throw new Error(`[OrcheStore] ${e} factory: Unknown node`)}let h=i||o.get(a);if(!h){if(c?.UnknownParent)return void c?.UnknownParent?.(d,n,a);throw new Error(`[OrcheStore] ${e} factory: Unknown parent node`)}for(let R of[a,...h.parents])if(R===n){if(c?.InfiniteOwnership)return void c?.InfiniteOwnership?.(d,n,a);throw new Error(`[OrcheStore] ${e} factory: Infinite ownership recursion`)}let E=(h.path?`${h.path}.`:"")+d,$=[a,...h.parents];return m(E,$,f,O,!1,R=>h.children.set(d,R))};function m(...d){let[n,a,i,c,f,O]=d;if(f=f||i.parents.length>0&&(i.parents[0]!==a[0]||i.path.split(".").at(-1)!==n.split(".").at(-1)),f){let h={familyId:i.familyId,path:n,children:new Map(i.children),parents:a},E=r.clone?r.clone(c.props,i,c):c.props;i=h,i.node=t(E,h,c),o.set(i.node,h),c.siblings.add(i.node)}i.path=n,i.parents=a,O?.(i.node);for(let[h,E]of[...i.children.entries()]){let $=o.get(E),R=$?s.get($.familyId):void 0,te=`${n}${n?".":""}${h}`;m(te,[i.node,...a],$,R,!1,L=>{L!==E&&i.children.set(h,L)})}return i.node}return{families:s,instances:o,create:p,attach:y,clone:x}}};import{ReducerType as ue,createSlice as pe}from"@reduxjs/toolkit";import{useSelector as fe}from"react-redux";var H=(e,t)=>{if(e)if(t==="warn")l.warn(e);else if(t==="error")l.error(e);else throw new Error(e);else return!1},D=(e,t="",r="",o)=>typeof e!="string"||!e?!!H(t,o?.[0]):e.includes(".")||e.includes("/")?!!H(r,o?.[1]):!0,de=(e,t,r,o)=>{let s=b.RequiredName(e,t),p=b.InvalidName(e,t,r);if(D(r,s,p,["error","error"])){if(o[0].includes(r))return l.error(b.ReservedKey(e,t,r));if(o[1].includes(r))return l.error(b.DuplicateKey(e,t,r))}else return;return!0},A=e=>{let t=[],r=[e.reserved,t];return(o,s,p,x)=>{let y=s?[]:{};return Object.entries(p).forEach(([m,d])=>{let n=de(e,o,m,r)?x(m,d):void 0;n!==void 0&&(s?y.push([m,n]):y[m]=n,t.push(m))}),y}},F=(e,t)=>{let r={...e||{}};return t.objects?.forEach(o=>{r[o]=typeof r[o]=="object"&&r[o]?{...r[o]}:{}}),t.validate?.(r),t.redux?.forEach(o=>{r[o]!==void 0&&l.warn(`[OrcheStore::${t.method}] '${o}' property is a Redux Toolkit option and is ignored by OrcheStore.`)}),t.unsupported?.forEach(o=>{Object.keys(r[o]).length<1||l.warn(`[OrcheStore::${t.method}] '${o}' property is not yet supported and will be ignored.`)}),r};var{families:ye,instances:C,create:me,attach:q,clone:he}=j({factoryName:"slice",instantiate(e,t,r){let o={},s=n=>w(void 0,t,n?v.InvalidStore(n,e.name):!1),p=A({module:"createSlice",slice:e.name,reserved:["name","path","computed","root","parent","prototype","global","getState","useSelect"]}),x=p("mutation",!1,e.mutations,(n,a)=>a?._reducerDefinitionType===ue.asyncThunk||"reducer"in{...a||{}}?l.error(v.ReduxReducerConflict()):typeof a!="function"?l.error(v.InvalidMutation(n)):(c,f)=>f?.meta?.path===t.path?a(c,...f.payload):c);t.redux=pe({name:e.name,initialState:e.state,reducers:x}),u.defineReadonly(o,"name",()=>e.name),u.defineReadonly(o,"path",()=>t.path),u.defineReadonly(o,"global",()=>T()),u.defineReadonly(o,"root",()=>s().node),u.defineReadonly(o,"parent",()=>{let n=t.parents[0];return(n?C.get(n):void 0)?.node}),u.defineMethod(o,"getState",()=>{let n=s("slice.getState").redux.getState();return t.path.split(".").forEach(a=>n=(n||{})[a]),n}),u.defineMethod(o,"useSelect",n=>{let a={global:T(),root:s("slice.useSelect").node};return fe(i=>(t.path.split(".").forEach(c=>i=(i||{})[c]),n.apply(a,[i,a])))}),u.defineReadonly(o,"computed",()=>{});let y={},m=()=>[...r.siblings.values()||[]];u.defineReadonly(o,"prototype",()=>y),u.defineMethod(y,"clone",()=>he(o)),u.defineMethod(y,"getLineage",()=>m()),u.defineMethod(y,"getClones",()=>m().filter(n=>n!==o)),u.defineMethod(y,"isTypeOf",n=>r===ye.get(C.get(n)?.familyId)),Object.entries(t.redux.actions).map(([n,a])=>{o[n]=(...i)=>{s("slice mutation").redux.dispatch({...a(i),meta:{path:t.path}})}}),p("method",!1,e.methods,(n,a)=>typeof a!="function"?l.error(v.InvalidMethod(n)):o[n]=(...i)=>a.apply(o,i));let d=p("child",!0,e.children,(n,a)=>{let c=q(n,a,o,t,{UnknownNode:f=>l.error(v.InvalidChild(f))});if(c)return o[n]=c,C.get(c).reducers});return t.reducers=(n,a)=>{let i=a?.meta?.path;if(typeof i=="string"&&!i.startsWith(t.path))return n;let c={...t.redux.reducer(n,a)};for(let[f,O]of d)c[f]=O(c?.[f],a);return c},o},options:{adapt(e){return F(e,{method:"createSlice",objects:["mutations","computed","methods","children"],unsupported:["computed"],redux:["reducers","extraReducers","reducerPath","initialState","selectors"],validate(t){D(t.name,v.RequiredName(),v.InvalidName(t.name));let r=t.state;if(typeof r!="function")return void Q(t.name,r);t.state=()=>Q(t.name,r())}})},clone(e,t){let r=t.redux.getInitialState();return{...e,state:r}}}}),Q=(e,t)=>{if(typeof t!="object"){let r=v.InvalidState(e,t);throw r.every(o=>typeof o=="string")?new Error(r.join(" ")):(l.error(...r),new Error)}if(!t)throw new Error(v.RequiredState(e));return t},V=e=>me(e);var{instances:Y,create:be}=j({factoryName:"slice",instantiate(e,t){let r={},o=A({module:"createStore",reserved:["name","computed","global","getState","useSelect"]});return u.defineReadonly(r,"name",()=>"default"),u.defineReadonly(r,"global",()=>T()),u.defineMethod(r,"getState",()=>t.redux.getState()),u.defineMethod(r,"useSelect",s=>{let p={global:T(),root:r};return Se(x=>s.apply(p,[x,p]))}),t.reducers=o("slice",!1,e.slices,(s,p)=>{let y=q(s,p,r,t,{UnknownNode:m=>l.error(N.InvalidChild(m))});if(y)return r[s]=y,C.get(y).reducers}),t.redux=ge({reducer:t.reducers}),r},options:{adapt(e){return F(e,{method:"createStore",objects:["slices"],redux:["reducer","devTools","duplicateMiddlewareCheck","enhancers","middleware","preloadedState"]})}}}),w=(e,t,r=!1)=>{if(r===!0)return[...Y.values()][0];e||=t?.parents?.at?.(-1);let o=e?Y.get(e):void 0,s=[];if(t&&!e?s=r===!1?[]:r.NeverExposed:o||(s=r===!1?[]:r.InvalidType(e)),s&&s.length)throw s.every(p=>typeof p=="string")?new Error(s.join(" ")):(l.error(...s),new Error);return o},Z=e=>be(e);import ve from"react";import{Provider as xe}from"react-redux";function ee(e){let{store:t,...r}={...e||{}},o=w(t,void 0,_.InvalidStore);return ve.createElement(xe,{...r,store:o.redux})}var Te=e=>(l.inform("prerelease"),V(e)),we=e=>(l.inform("prerelease"),w(void 0,void 0,!0)?(l.warn(N.singletonLimitation()),w(void 0,void 0,!0).node):Z(e)),Et={createStore:we,createSlice:Te,StoreProvider:ee,provideGlobalUtils:B,getGlobalUtils:T,configureDiagnostics:W};export{ee as StoreProvider,W as configureDiagnostics,Te as createSlice,we as createStore,Et as default,T as getGlobalUtils,B as provideGlobalUtils};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orchestore",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "A function-oriented architecture built on top of Redux Toolkit for simplifying and automating application development.",
|
|
5
5
|
"author": "Oussama Saadaoui",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"init": "node scripts/install.mjs",
|
|
13
13
|
"start": "tsup && node scripts/build.mjs",
|
|
14
14
|
"build": "tsup && node scripts/build.mjs",
|
|
15
|
+
"test": "node scripts/test.mjs",
|
|
15
16
|
"deploy": "tsup && node scripts/publish.mjs",
|
|
16
17
|
"check": "tsc --noEmit",
|
|
17
18
|
"lint": "eslint ."
|
|
@@ -69,6 +70,14 @@
|
|
|
69
70
|
"typescript",
|
|
70
71
|
"orchestration",
|
|
71
72
|
"state-management",
|
|
72
|
-
"state-orchestration"
|
|
73
|
+
"state-orchestration",
|
|
74
|
+
"pinia",
|
|
75
|
+
"vuex",
|
|
76
|
+
"react-pinia",
|
|
77
|
+
"react-vuex",
|
|
78
|
+
"redux-pinia",
|
|
79
|
+
"redux-vuex",
|
|
80
|
+
"store-pinia",
|
|
81
|
+
"store-vuex"
|
|
73
82
|
]
|
|
74
83
|
}
|