orchestore 0.1.5 → 0.1.7

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.cjs CHANGED
@@ -1,30 +1,30 @@
1
- "use strict";var ee=Object.create;var b=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var oe=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var ie=(e,r)=>{for(var t in r)b(e,t,{get:r[t],enumerable:!0})},K=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of te(r))!ne.call(e,n)&&n!==t&&b(e,n,{get:()=>r[n],enumerable:!(o=re(r,n))||o.enumerable});return e};var ae=(e,r,t)=>(t=e!=null?ee(oe(e)):{},K(r||!e||!e.__esModule?b(t,"default",{value:e,enumerable:!0}):t,e)),se=e=>K(b({},"__esModule",{value:!0}),e);var xe={};ie(xe,{StoreProvider:()=>G,configureDiagnostics:()=>P,createSlice:()=>Y,createStore:()=>Z,default:()=>be,getGlobalUtils:()=>m,provideGlobalUtils:()=>D});module.exports=se(xe);var X=require("@reduxjs/toolkit"),_=require("react-redux");var y="all",$={diagnostics:!1,prerelease:!1},q=globalThis.console?.log?.bind?.(globalThis.console)||globalThis.console?.log,le=globalThis.console?.warn?.bind?.(globalThis.console)||globalThis.console?.warn,ce=globalThis.console?.error?.bind?.(globalThis.console)||globalThis.console?.error,de=globalThis.console?.clear?.bind?.(globalThis.console)||globalThis.console?.clear;globalThis.console?.clear&&(globalThis.console.clear=(...e)=>{$.diagnostics=!1,de?.(...e)});var ue=`[OrcheStore] \u{1F6A7} Pre-release Notice
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
- `,pe=`[OrcheStore] Diagnostics are enabled.
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
- `,s={inform(e){$[e]||($[e]=!0,y==="all"&&q?.(e==="prerelease"?ue:pe))},log(...e){y==="all"&&(s.inform("diagnostics"),q?.(...e))},warn(...e){y==="all"&&(s.inform("diagnostics"),le?.(...e))},error(...e){y!=="off"&&(s.inform("diagnostics"),ce?.(...e))}};function P(e){y=e}var z=(...e)=>{let[r,t]=[e[2],e[3]],o=`${e[0]||"Received"}: `,n=e[1]!==!1?"(type: "+typeof r+")":"";if(!t?.(r))return r==null?[`${o}(type: ${r})`]:typeof r=="number"||typeof r=="bigint"||typeof r=="boolean"?[`${o}${n} ${r}`]:typeof r=="object"?[o,r]:r===""?[`${o}Empty String`]:[`${o}${n}`,r]},g=((e,r)=>z("Received",!0,e,r));g.prefixed=(e,r,t,o)=>z(e,r,t,o);var fe=Object.assign,M=Object.getOwnPropertyDescriptor(Object,"defineProperty")?.value||Object.defineProperty,me=(e,r,t)=>{M(e,r,{get:t,enumerable:!0,configurable:!1})},Se=(e,r,t)=>{M(e,r,{value:t,writable:!1,enumerable:!0,configurable:!1})},d={assign:fe,defineProp:M,defineReadonly:me,defineMethod:Se},L={isArray:Array.isArray},x={get:Reflect.get,set:Reflect.set,delete:Reflect.deleteProperty};var k={InvalidStore:e=>({StoreType:[`[OrcheStore::StoreProvider] Expected a store instance created with createStore(...).
13
- `,...g(e)]})},v={GetMissingProp:e=>["[OrcheStore::global-utils] Attempted to access a global utility before it became available. Missing property",e,`
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
- `},T={InvalidChild:e=>`[OrcheStore::createStore] Child slice '${e}' must be a slice created with createSlice(...).`,singletonLimitation:()=>`[OrcheStore::createStore] createStore(...) was called more than once.
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.`},u={InvalidStore:(e,r,t)=>({StoreType:[`[OrcheStore::${r}] Unable to resolve a valid store instance.
23
- This operation requires a store created with createStore(...).
24
- `,...g(e)],NeverExposed:[`[OrcheStore::${r}] Slice {${t}} has not been exposed in any store.
25
- Ensure the slice is reachable from a store instance.
26
- This can be done by exposing the slice directly through createStore({ slices: ... }) or indirectly through a parent slice using createSlice({ children: ... }).`],NotInTree:[`[OrcheStore::${r}] Slice {${t}} is not exposed within the target store.
27
- A slice can only be accessed through stores that expose it.
28
- `,...g.prefixed("Current store",!1,e)]}),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,r)=>[`[OrcheStore::createSlice]${f.target({slice:e})}Slice state must be a non-null object or a function that returns a non-null object.
29
- `,...g(r)],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."},f={target:({slice:e})=>e?` Affected slice '${e}':
30
- `:" ",RequiredName:(e,r)=>`[OrcheStore::${e.module}]${f.target(e)}${r} keys must be non-empty strings.`,InvalidName:(e,r,t)=>`[OrcheStore::${e.module}]${f.target(e)}${r} names cannot contain '.' or '/'. Received: ${t}.`,ReservedKey:(e,r,t)=>`[OrcheStore::${e.module}]${f.target(e)}'${t}' is a reserved name and cannot be used as a ${r} key.`,DuplicateKey:(e,r,t)=>`[OrcheStore::${e.module}]${f.target(e)}${r} name '${t}' conflicts with another member.`};var C=new Proxy({},{get(e,r,t){return r in e||s.error(...v.GetMissingProp(r)),x.get(e,r,t)},set(e,r,t,o){return x.set(e,r,t,o)},deleteProperty(e,r){return s.warn(...v.DeleteProp(r)),x.delete(e,r)}});function m(){return C}function D(e){let r=g(e,t=>t&&typeof t=="object"&&!L.isArray(t));return r?s.error(v.InvalidArgs(),...r):d.assign(C,e),C}function h(e,r){let t={children:{}};return Object.keys(e).filter(n=>n.startsWith(r)).map(n=>n.split(".")).sort((n,a)=>n.length-a.length).forEach(n=>{let a=t;n.slice(0,n.length-1).forEach(i=>a=a[i]||={}),a.children||={},a.children[n[n.length-1]]={...e[n.join(".")]}}),t.children}var W=(e,r)=>{if(e)if(r==="warn")s.warn(e);else if(r==="error")s.error(e);else throw new Error(e);else return!1},j=(e,r="",t="",o)=>typeof e!="string"||!e?!!W(r,o?.[0]):e.includes(".")||e.includes("/")?!!W(t,o?.[1]):!0,ge=(e,r,t,o)=>{let n=f.RequiredName(e,r),a=f.InvalidName(e,r,t);if(j(t,n,a,["error","error"])){if(o[0].includes(t))return s.error(f.ReservedKey(e,r,t));if(o[1].includes(t))return s.error(f.DuplicateKey(e,r,t))}else return;return!0},E=e=>{let r=[],t=[e.reserved,r];return(o,n,a)=>(Object.entries(n).forEach(([i,c])=>{let l=ge(e,o,i,t)?a(i,c):void 0;if(l===void 0)return delete n[i];n[i]=l,r.push(i)}),n)},O=(e,r)=>{let t={...e||{}};return r.objects?.forEach(o=>{t[o]=typeof t[o]=="object"&&t[o]?{...t[o]}:{}}),r.validate?.(t),r.redux?.forEach(o=>{t[o]!==void 0&&s.warn(`[OrcheStore::${r.method}] '${o}' property is a Redux Toolkit option and is ignored by OrcheStore.`)}),r.unsupported?.forEach(o=>{Object.keys(t[o]).length<1||s.warn(`[OrcheStore::${r.method}] '${o}' property is not yet supported and will be ignored.`)}),t};var w=require("@reduxjs/toolkit");var F=require("react-redux"),J=[],V=e=>{let r={children:{},roots:[]},t=r.slice={},o=O(e,{method:"createSlice",objects:["mutations","computed","methods","children"],unsupported:["computed","children"],redux:["reducers","extraReducers","reducerPath","initialState","selectors"],validate:ye}),n=E({module:"createSlice",slice:o.name,reserved:["name","computed","root","global","getState","useSelect","getPath"]});return n("mutation",o.mutations,(a,i)=>i?._reducerDefinitionType===w.ReducerType.asyncThunk||"reducer"in{...i||{}}?s.error(u.ReduxReducerConflict()):typeof i!="function"?s.error(u.InvalidMutation(a)):((l,A)=>i(l,...A.payload))),r.redux=(0,w.createSlice)({name:o.name,initialState:o.state,reducers:o.mutations}),d.defineReadonly(t,"name",()=>o.name),d.defineReadonly(t,"global",()=>m()),d.defineMethod(t,"getPath",()=>I(t)),d.defineMethod(t,"getState",()=>{let a=u.InvalidStore(void 0,"slice.getState",o.name),i=S(r,void 0,a).redux.getState();return h(i,I(t))}),d.defineMethod(t,"useSelect",a=>{let i=u.InvalidStore(void 0,"slice.useSelect",o.name);return S(r,void 0,i),(0,F.useSelector)(c=>{let l={global:m()};return a.call(l,h(c,I(t)),l)})}),Object.entries(r.redux.actions).map(([a,i])=>{t[a]=(...c)=>{let l=u.InvalidStore(void 0,"slice mutation",o.name);return S(r,void 0,l).redux.dispatch(i(c))}}),n("method",o.methods,(a,i)=>typeof i!="function"?s.error(u.InvalidMethod(a)):t[a]=(...c)=>i.apply(t,c)),J.push(r),t};function U(e){return J.find(r=>r.slice===e)}var N=(e,r,t,o,n)=>{let{redux:a,children:i}=r;return r.path=e,r.roots.push(o),n[e]=a.reducer,Object.entries(i).forEach(([c,l])=>{N(e+"."+c,U(l),r.slice,o,n)}),t[e]=r.slice},ye=e=>{let r=t=>{if(typeof t!="object"){let o=u.InvalidState(e.name,t);throw o.every(n=>typeof n=="string")?new Error(o.join(" ")):(s.error(...o),new Error)}if(!t)throw new Error(u.RequiredState(e.name));return t};if(j(e.name,u.RequiredName(),u.InvalidName(e.name)),typeof e.state=="function"){let t=e.state;e.state=()=>r(t())}else r(e.state)},I=e=>e.name;var R=[],B=e=>{let r={},t=r.store={},o=O(e,{method:"createStore",objects:["slices"],redux:["reducer","devTools","duplicateMiddlewareCheck","enhancers","middleware","preloadedState"]}),n=E({module:"createStore",reserved:["name","computed","global","getState","useSelect"]});d.defineReadonly(t,"name",()=>"default"),d.defineReadonly(t,"global",()=>m()),d.defineMethod(t,"getState",()=>h(r.redux.getState(),"")),d.defineMethod(t,"useSelect",i=>(0,_.useSelector)(c=>{let l={global:m()};return i.call(l,h(c,""),l)}));let a={};return n("slice",o.slices,(i,c)=>{let l=U(c);return l?N(i,l,t,t,a):s.error(T.InvalidChild(i))}),r.redux=(0,X.configureStore)({reducer:a}),R.push(r),t},S=(e,r,t={})=>{if(t===!1)return R[0];let o;if((!e||r!==void 0)&&!R.find(n=>n.store===r)?o=t.StoreType:e&&!e.roots.length?o=t.NeverExposed:e&&r&&!e.roots.includes(r)&&(o=t.NotInTree),r=e&&r===void 0?e.roots[0]:r,o)throw o.every(n=>typeof n=="string")?new Error(o.join(" ")):(s.error(...o),new Error);return R.find(n=>n.store===r)};var H=ae(require("react"),1),Q=require("react-redux");function G(e){let{store:r,...t}={...e||{}},o=S(void 0,r,k.InvalidStore(r));return H.default.createElement(Q.Provider,{...t,store:o.redux})}var Y=e=>(s.inform("prerelease"),V(e)),Z=e=>(s.inform("prerelease"),S(void 0,void 0,!1)?(s.warn(T.singletonLimitation()),S(void 0,void 0,!1).store):B(e)),be={createStore:Z,createSlice:Y,StoreProvider:G,provideGlobalUtils:D,getGlobalUtils:m,configureDiagnostics:P};0&&(module.exports={StoreProvider,configureDiagnostics,createSlice,createStore,getGlobalUtils,provideGlobalUtils});
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
- /** String-keyed object map. */
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, true>;
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, true>, context: GlobalUtils) => T) => T;
25
- /** Returns fully qualified runtime path of the slice. */
26
- readonly getPath: () => string;
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]>>) => ReturnType<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, false>, ...args: any[]) => void>;
72
+ type Mutations<S extends Obj, C> = Dict<(state: SliceState.Draft<S, C>, ...args: any[]) => void | S>;
49
73
  /** Derived state shape exposed by a slice, excluding internal framework fields. */
50
- type SliceState<S, isReadOnly> = isReadOnly extends true ? ReadOnly<S extends Dict ? Omit<S, "computed" | "children"> : S> : S extends Dict ? Omit<S, "computed" | "children"> : S;
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" | "global" | "children" | "getState" | "useSelect" | "getPath") | (keyof R | keyof M);
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, true> : never;
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
- /** String-keyed object map. */
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, true>;
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, true>, context: GlobalUtils) => T) => T;
25
- /** Returns fully qualified runtime path of the slice. */
26
- readonly getPath: () => string;
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]>>) => ReturnType<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, false>, ...args: any[]) => void>;
72
+ type Mutations<S extends Obj, C> = Dict<(state: SliceState.Draft<S, C>, ...args: any[]) => void | S>;
49
73
  /** Derived state shape exposed by a slice, excluding internal framework fields. */
50
- type SliceState<S, isReadOnly> = isReadOnly extends true ? ReadOnly<S extends Dict ? Omit<S, "computed" | "children"> : S> : S extends Dict ? Omit<S, "computed" | "children"> : S;
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" | "global" | "children" | "getState" | "useSelect" | "getPath") | (keyof R | keyof M);
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, true> : never;
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 ie}from"@reduxjs/toolkit";import{useSelector as ae}from"react-redux";var b="all",R={diagnostics:!1,prerelease:!1},U=globalThis.console?.log?.bind?.(globalThis.console)||globalThis.console?.log,J=globalThis.console?.warn?.bind?.(globalThis.console)||globalThis.console?.warn,V=globalThis.console?.error?.bind?.(globalThis.console)||globalThis.console?.error,X=globalThis.console?.clear?.bind?.(globalThis.console)||globalThis.console?.clear;globalThis.console?.clear&&(globalThis.console.clear=(...e)=>{R.diagnostics=!1,X?.(...e)});var _=`[OrcheStore] \u{1F6A7} Pre-release Notice
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
- `,B=`[OrcheStore] Diagnostics are enabled.
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
- `,s={inform(e){R[e]||(R[e]=!0,b==="all"&&U?.(e==="prerelease"?_:B))},log(...e){b==="all"&&(s.inform("diagnostics"),U?.(...e))},warn(...e){b==="all"&&(s.inform("diagnostics"),J?.(...e))},error(...e){b!=="off"&&(s.inform("diagnostics"),V?.(...e))}};function N(e){b=e}var G=(...e)=>{let[r,t]=[e[2],e[3]],o=`${e[0]||"Received"}: `,n=e[1]!==!1?"(type: "+typeof r+")":"";if(!t?.(r))return r==null?[`${o}(type: ${r})`]:typeof r=="number"||typeof r=="bigint"||typeof r=="boolean"?[`${o}${n} ${r}`]:typeof r=="object"?[o,r]:r===""?[`${o}Empty String`]:[`${o}${n}`,r]},g=((e,r)=>G("Received",!0,e,r));g.prefixed=(e,r,t,o)=>G(e,r,t,o);var H=Object.assign,$=Object.getOwnPropertyDescriptor(Object,"defineProperty")?.value||Object.defineProperty,Q=(e,r,t)=>{$(e,r,{get:t,enumerable:!0,configurable:!1})},Y=(e,r,t)=>{$(e,r,{value:t,writable:!1,enumerable:!0,configurable:!1})},d={assign:H,defineProp:$,defineReadonly:Q,defineMethod:Y},A={isArray:Array.isArray},x={get:Reflect.get,set:Reflect.set,delete:Reflect.deleteProperty};var K={InvalidStore:e=>({StoreType:[`[OrcheStore::StoreProvider] Expected a store instance created with createStore(...).
13
- `,...g(e)]})},v={GetMissingProp:e=>["[OrcheStore::global-utils] Attempted to access a global utility before it became available. Missing property",e,`
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
- `},T={InvalidChild:e=>`[OrcheStore::createStore] Child slice '${e}' must be a slice created with createSlice(...).`,singletonLimitation:()=>`[OrcheStore::createStore] createStore(...) was called more than once.
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.`},u={InvalidStore:(e,r,t)=>({StoreType:[`[OrcheStore::${r}] Unable to resolve a valid store instance.
23
- This operation requires a store created with createStore(...).
24
- `,...g(e)],NeverExposed:[`[OrcheStore::${r}] Slice {${t}} has not been exposed in any store.
25
- Ensure the slice is reachable from a store instance.
26
- This can be done by exposing the slice directly through createStore({ slices: ... }) or indirectly through a parent slice using createSlice({ children: ... }).`],NotInTree:[`[OrcheStore::${r}] Slice {${t}} is not exposed within the target store.
27
- A slice can only be accessed through stores that expose it.
28
- `,...g.prefixed("Current store",!1,e)]}),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,r)=>[`[OrcheStore::createSlice]${m.target({slice:e})}Slice state must be a non-null object or a function that returns a non-null object.
29
- `,...g(r)],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."},m={target:({slice:e})=>e?` Affected slice '${e}':
30
- `:" ",RequiredName:(e,r)=>`[OrcheStore::${e.module}]${m.target(e)}${r} keys must be non-empty strings.`,InvalidName:(e,r,t)=>`[OrcheStore::${e.module}]${m.target(e)}${r} names cannot contain '.' or '/'. Received: ${t}.`,ReservedKey:(e,r,t)=>`[OrcheStore::${e.module}]${m.target(e)}'${t}' is a reserved name and cannot be used as a ${r} key.`,DuplicateKey:(e,r,t)=>`[OrcheStore::${e.module}]${m.target(e)}${r} name '${t}' conflicts with another member.`};var P=new Proxy({},{get(e,r,t){return r in e||s.error(...v.GetMissingProp(r)),x.get(e,r,t)},set(e,r,t,o){return x.set(e,r,t,o)},deleteProperty(e,r){return s.warn(...v.DeleteProp(r)),x.delete(e,r)}});function h(){return P}function q(e){let r=g(e,t=>t&&typeof t=="object"&&!A.isArray(t));return r?s.error(v.InvalidArgs(),...r):d.assign(P,e),P}function y(e,r){let t={children:{}};return Object.keys(e).filter(n=>n.startsWith(r)).map(n=>n.split(".")).sort((n,a)=>n.length-a.length).forEach(n=>{let a=t;n.slice(0,n.length-1).forEach(i=>a=a[i]||={}),a.children||={},a.children[n[n.length-1]]={...e[n.join(".")]}}),t.children}var z=(e,r)=>{if(e)if(r==="warn")s.warn(e);else if(r==="error")s.error(e);else throw new Error(e);else return!1},M=(e,r="",t="",o)=>typeof e!="string"||!e?!!z(r,o?.[0]):e.includes(".")||e.includes("/")?!!z(t,o?.[1]):!0,Z=(e,r,t,o)=>{let n=m.RequiredName(e,r),a=m.InvalidName(e,r,t);if(M(t,n,a,["error","error"])){if(o[0].includes(t))return s.error(m.ReservedKey(e,r,t));if(o[1].includes(t))return s.error(m.DuplicateKey(e,r,t))}else return;return!0},E=e=>{let r=[],t=[e.reserved,r];return(o,n,a)=>(Object.entries(n).forEach(([i,c])=>{let l=Z(e,o,i,t)?a(i,c):void 0;if(l===void 0)return delete n[i];n[i]=l,r.push(i)}),n)},O=(e,r)=>{let t={...e||{}};return r.objects?.forEach(o=>{t[o]=typeof t[o]=="object"&&t[o]?{...t[o]}:{}}),r.validate?.(t),r.redux?.forEach(o=>{t[o]!==void 0&&s.warn(`[OrcheStore::${r.method}] '${o}' property is a Redux Toolkit option and is ignored by OrcheStore.`)}),r.unsupported?.forEach(o=>{Object.keys(t[o]).length<1||s.warn(`[OrcheStore::${r.method}] '${o}' property is not yet supported and will be ignored.`)}),t};import{createSlice as re,ReducerType as te}from"@reduxjs/toolkit";import{useSelector as oe}from"react-redux";var L=[],k=e=>{let r={children:{},roots:[]},t=r.slice={},o=O(e,{method:"createSlice",objects:["mutations","computed","methods","children"],unsupported:["computed","children"],redux:["reducers","extraReducers","reducerPath","initialState","selectors"],validate:ne}),n=E({module:"createSlice",slice:o.name,reserved:["name","computed","root","global","getState","useSelect","getPath"]});return n("mutation",o.mutations,(a,i)=>i?._reducerDefinitionType===te.asyncThunk||"reducer"in{...i||{}}?s.error(u.ReduxReducerConflict()):typeof i!="function"?s.error(u.InvalidMutation(a)):((l,I)=>i(l,...I.payload))),r.redux=re({name:o.name,initialState:o.state,reducers:o.mutations}),d.defineReadonly(t,"name",()=>o.name),d.defineReadonly(t,"global",()=>h()),d.defineMethod(t,"getPath",()=>C(t)),d.defineMethod(t,"getState",()=>{let a=u.InvalidStore(void 0,"slice.getState",o.name),i=S(r,void 0,a).redux.getState();return y(i,C(t))}),d.defineMethod(t,"useSelect",a=>{let i=u.InvalidStore(void 0,"slice.useSelect",o.name);return S(r,void 0,i),oe(c=>{let l={global:h()};return a.call(l,y(c,C(t)),l)})}),Object.entries(r.redux.actions).map(([a,i])=>{t[a]=(...c)=>{let l=u.InvalidStore(void 0,"slice mutation",o.name);return S(r,void 0,l).redux.dispatch(i(c))}}),n("method",o.methods,(a,i)=>typeof i!="function"?s.error(u.InvalidMethod(a)):t[a]=(...c)=>i.apply(t,c)),L.push(r),t};function D(e){return L.find(r=>r.slice===e)}var j=(e,r,t,o,n)=>{let{redux:a,children:i}=r;return r.path=e,r.roots.push(o),n[e]=a.reducer,Object.entries(i).forEach(([c,l])=>{j(e+"."+c,D(l),r.slice,o,n)}),t[e]=r.slice},ne=e=>{let r=t=>{if(typeof t!="object"){let o=u.InvalidState(e.name,t);throw o.every(n=>typeof n=="string")?new Error(o.join(" ")):(s.error(...o),new Error)}if(!t)throw new Error(u.RequiredState(e.name));return t};if(M(e.name,u.RequiredName(),u.InvalidName(e.name)),typeof e.state=="function"){let t=e.state;e.state=()=>r(t())}else r(e.state)},C=e=>e.name;var w=[],W=e=>{let r={},t=r.store={},o=O(e,{method:"createStore",objects:["slices"],redux:["reducer","devTools","duplicateMiddlewareCheck","enhancers","middleware","preloadedState"]}),n=E({module:"createStore",reserved:["name","computed","global","getState","useSelect"]});d.defineReadonly(t,"name",()=>"default"),d.defineReadonly(t,"global",()=>h()),d.defineMethod(t,"getState",()=>y(r.redux.getState(),"")),d.defineMethod(t,"useSelect",i=>ae(c=>{let l={global:h()};return i.call(l,y(c,""),l)}));let a={};return n("slice",o.slices,(i,c)=>{let l=D(c);return l?j(i,l,t,t,a):s.error(T.InvalidChild(i))}),r.redux=ie({reducer:a}),w.push(r),t},S=(e,r,t={})=>{if(t===!1)return w[0];let o;if((!e||r!==void 0)&&!w.find(n=>n.store===r)?o=t.StoreType:e&&!e.roots.length?o=t.NeverExposed:e&&r&&!e.roots.includes(r)&&(o=t.NotInTree),r=e&&r===void 0?e.roots[0]:r,o)throw o.every(n=>typeof n=="string")?new Error(o.join(" ")):(s.error(...o),new Error);return w.find(n=>n.store===r)};import se from"react";import{Provider as le}from"react-redux";function F(e){let{store:r,...t}={...e||{}},o=S(void 0,r,K.InvalidStore(r));return se.createElement(le,{...t,store:o.redux})}var ce=e=>(s.inform("prerelease"),k(e)),de=e=>(s.inform("prerelease"),S(void 0,void 0,!1)?(s.warn(T.singletonLimitation()),S(void 0,void 0,!1).store):W(e)),pr={createStore:de,createSlice:ce,StoreProvider:F,provideGlobalUtils:q,getGlobalUtils:h,configureDiagnostics:N};export{F as StoreProvider,N as configureDiagnostics,ce as createSlice,de as createStore,pr as default,h as getGlobalUtils,q as provideGlobalUtils};
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.5",
3
+ "version": "0.1.7",
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",