orchestore 0.1.8 → 0.1.9

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.js CHANGED
@@ -1,30 +1,11 @@
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
1
+ var x=globalThis.console,Ie=x?.log?.bind(x)??x?.log,Ce=x?.warn?.bind(x)??x?.warn,L=x?.error?.bind(x)??x?.error,Ke=x?.clear?.bind(x)??x?.clear,C=!1,O={logs:!0,warnings:!0,errors:!0},W=`[OrcheStore] Warning and error reporting is enabled.
2
+ Configure it with setReporting(...) to control console output.
3
+ `,T={log(e){!e?.length||!O.logs||Ie?.(...e)},warn(e){!e?.length||!O.warnings||(C||(C=!0,T.log([W])),Ce?.("[OrcheStore] Warning:",...e))},error(e){!e?.length||!O.errors||(C||(C=!0,T.log([W])),L?.("[OrcheStore] Error:",...e))},throw(e){if(!e?.length)return;if(e.every(r=>typeof r=="string")){let r=new Error(e.join(" "));throw r.name="[OrcheStore] Error",r}L?.(...e);let t=new Error;throw t.name="[OrcheStore] Error",t}};function H(e,t){if(typeof e=="boolean")e={logs:e,warnings:e,errors:e};else if(typeof e=="string")e={[e]:t};else if(!e||typeof e!="object")return;e={...e},O.logs=!!(e.logs??e.all??O.logs),O.warnings=!!(e.warnings??e.all??O.warnings),O.errors=!!(e.errors??e.all??O.errors)}function R(e,t="Got"){return e==null?[`${t}: ${e}`]:Array.isArray(e)?[`${t}: array`,e]:typeof e=="object"?[`${t}: object`,e]:typeof e=="function"?[`${t}: function`,e]:e===""?[`${t}: empty string`]:[`${t}: ${typeof e} (${e})`]}var d=(e,t,r="Slice")=>{let o={InvalidStore:i=>["Expected a store created with createStore(...).",...R(i)],NeverExposed:i=>[`Slice '${i}' is not reachable from any store. Connect it through createStore({ slices }) or createSlice({ children }).`],ParentNeverExposed:(i,s)=>[`Slice '${i}' depends on unreachable parent '${s}'. Connect the parent through createStore({ slices }) or createSlice({ children }).`],StoreNotProvided:i=>[i?`The current component is outside the React tree of StoreProvider for Store '${i}'.`:"The current component is outside the React tree of StoreProvider for the current store."]},n={InvalidName:(i,s)=>[s?`"name" must be a non-empty string without '.' or '/' (required).`:`"name" must be a valid string without '.' or '/' (optional).`,...R(i)],InvalidKey:(i,s)=>[`${i} key must be a non-empty string without '.' or '/'`,...R(s)],DuplicateKey:(i,s)=>[`${i} '${s}' conflicts with another exposed member.`],InvalidStateProp:i=>['"state" must be a non-null object or a function returning one.',...R(i)],InvalidStateClone:i=>["cloned state must be a non-null object.",...R(i)],InvalidMutation:(i,s)=>[`Mutation '${i}' must be a function.`,...R(s)],InvalidThunkReducer:i=>[`Invalid mutation '${i}', asyncThunk reducers are not supported. Use methods instead.`],InvalidPreparedReducer:i=>[`Invalid mutation '${i}', prepared reducers are not supported. Use a regular mutation or adapter method.`],InvalidMethod:(i,s)=>[`Method '${i}' must be a function.`,...R(s)],InvalidChild:(i,s)=>[`Child '${i}' must be a slice created with createSlice(...).`,...R(s)],InfiniteOwnership:i=>[`Infinite ownership recursion detected through child '${i}'.`],InvalidUtilsArgs:i=>["Expected a non-null object.",...R(i)]},a={ReduxMismatchProp:(i,s)=>[`'${i}' is a Redux Toolkit option. Use ${s} instead.`],UnsupportedReduxProp:i=>[`'${i}' is a Redux Toolkit option that is not yet supported and will be ignored.`],GetMissingUtil:i=>[`'${i}' was accessed before registration. Use setUtils(...) and/or set it to undefined if optional to suppress this warning.`]},p=(i,s)=>(...P)=>{s([`At ${e}${t?` \u2192 ${r} '${t}'
4
+ `:`
5
+ `}`,...i(...P)])};return new Proxy({},{get(i,s){if(Object.hasOwn(o,s))return p(o[s],T.throw);if(Object.hasOwn(n,s))return p(n[s],T.error);if(Object.hasOwn(a,s))return p(a[s],T.warn)}})};globalThis.console?.clear&&(globalThis.console.clear=(...e)=>{C=!1,Ke?.(...e)});var J=e=>({get:(t,r)=>{let o=t?e.get(t):void 0;return o||void r?.(t)},of:(t,r,o)=>{let n=r.parents?.at?.(-1),a=n?e.get(n):void 0;if(n){if(!a)return void(o&&d(o).ParentNeverExposed(t,n.name))}else return void(o&&d(o).NeverExposed(t));return a}});var X=new Set(["toJSON","toString"]),k=new Proxy({},{get(e,t,r){return X.has(t)||d("utils").GetMissingUtil(t.toString()),Reflect.get(e,t,r)},set(e,t,r,o){return X.add(t),Reflect.set(e,t,r,o)}});function A(){return k}function q(e){return e&&typeof e=="object"&&!Array.isArray(e)?Object.assign(k,e):d("setUtils").InvalidUtilsArgs(e),k}var B=Object.getOwnPropertyDescriptor(Object,"defineProperty")?.value||Object.defineProperty,h=(e,t,r)=>{B(e,t,{get:r,enumerable:!0,configurable:!1})},g=(e,t,r)=>{B(e,t,{value:r,writable:!1,enumerable:!0,configurable:!1})},I=(e,t,r,o,n,a)=>!n||typeof n!="string"||n.includes(".")||n.includes("/")?void d(e,t,r).InvalidKey(o,n):a.includes(n)?void d(e,t,r).DuplicateKey(o,n):n,$=(e,t,r)=>!r&&(t.name===void 0||t.name===null||t.name==="")?"untitled":!t.name||typeof t.name!="string"||t.name.includes(".")||t.name.includes("/")?(d(e).InvalidName(t.name,r),"untitled"):t.name;import{createElement as Q,createContext as V,useContext as Y}from"react";import{Provider as Z,createSelectorHook as ee}from"react-redux";import{configureStore as $e,createSlice as je,ReducerType as te}from"@reduxjs/toolkit";var re=(e,t,r)=>je({name:e,initialState:t,reducers:r}),oe=e=>$e(e);var ne=(e,t)=>{let r=V(null),o=ee(r);t.context=r,t.selector=(n,a,p)=>{if(Y(t.context))return o(p);n?d("useSelect",a,n).StoreNotProvided(e):d("useSelect",e,"Store").StoreNotProvided("")},g(t.node,"useSelect",n=>{let a={utils:A(),root:t.node};return t.selector("","",p=>n.apply(a,[p,a]))})};var ie=(e,t)=>{h(t.node,"name",()=>e),h(t.node,"utils",()=>A())},ae=e=>{let t={reducer:"'slices'",reducers:"'slices'",devTools:"",duplicateMiddlewareCheck:"",enhancers:"",middleware:"",preloadedState:""},r={...e||{}},o={};return o.name=$("createStore",r,!1),["slices"].forEach(n=>{o[n]=typeof r[n]=="object"&&r[n]?{...r[n]}:{}}),Object.entries(t).forEach(([n,a])=>{r[n]!==void 0&&(a?d("createStore",o.name,"Store").ReduxMismatchProp(n,a):d("createStore",o.name,"Store").UnsupportedReduxProp(n))}),o};var j=e=>{let{instantiate:t,afterInstantiate:r,options:o={}}=e,n=new Map,a=new Map,p=S=>{S=o.prepare?o.prepare(S):S;let l={familyId:Symbol("family"),path:"",children:new Map,parents:[]},u={props:S,siblings:new Set},c=t(S,l,u,!1);return u.siblings.add(l.node),n.set(l.node,l),a.set(l.familyId,u),r&&r(S,l,u,!1,c),l.node},i=(S,l,u)=>{let c=n.get(S),m=c?a.get(c.familyId):void 0;return!c||!m?void l?.UnknownNode?.("",S):P("",[],c,m,!0,u,()=>{})},s=(S,l,u,c,m)=>{let M=n.get(l),K=M?a.get(M.familyId):void 0;if(!M||!K)return void m?.UnknownNode?.(S,l);let w=c||n.get(u);if(!w)return void m?.UnknownParent?.(S,l,u);let v=[u,...w.parents||[]];if(v.includes(l))return void m?.InfiniteOwnership?.(S,l,u);let b=(w.path?`${w.path}.`:"")+S;return P(b,v,M,K,!1,void 0,E=>{w.children?.set(S,E)})};function P(...S){let[l,u,c,m,M,K,w]=S,v={executed:!1,payload:void 0},b=[];if(M=M||c.parents.length>0&&(c.parents[0]!==u[0]||c.path.split(".").at(-1)!==l.split(".").at(-1)),M){let E={familyId:c.familyId,path:l,children:new Map(c.children),parents:u};b[0]=o.clone?o.clone(m.props,c,m,K):m.props,b[1]=o.currentCloned?o.currentCloned(b[0]):b[0],c=E,v.payload=t(b[1],E,m,!0),v.executed=!0,n.set(c.node,E),m.siblings.add(c.node)}c.path=l,c.parents=u,w?.(c);for(let[E,G]of[...c.children.entries()]){let Te=`${l}${l?".":""}${E}`,we=a.get(G.familyId),ve=o.childCloned&&b[0]?o.childCloned(E,b[0]):void 0;P(Te,[c.node,...u],G,we,!1,ve,z=>{z!==G&&c.children.set(E,z)})}return v.executed&&r&&r(b[1],c,m,!0,v.payload),c}return{families:a,instances:n,create:p,attach:s,clone:i}};var U=(e,t,r,o)=>typeof r=="function"&&o?()=>U(e,t,r(),!1):r==null?{}:typeof r=="object"&&!Array.isArray(r)?r:o===!1?(d(e,t).InvalidStateProp(r),{}):(d(e,t).InvalidStateClone(r),{}),se=(e,t)=>{g(t.node,"getState",()=>{let r=N.of(e,t,"slice.getState")?.redux.getState();return D(t.path,r)}),g(t.node,"getInitialState",(()=>t.redux.getInitialState())),g(t.node.getInitialState,"deep",()=>t.reducer(void 0,{type:"@@INIT"}))},ce=(e,t,r)=>(o,n)=>{let a={...t.redux.reducer(o,n)};for(let[p,i]of r)a[p]=i(a?.[p],n);return a},de=(e,t)=>{if(t?.object)return t?.object;let r=e.reducer(void 0,{type:"@@CLONE"}),o=t?.transform?t.transform(r):void 0,n=o===void 0?r:o;return U("slice.clone",t?.name??"",n)},le=e=>{let t={...e.state};return Object.keys(e.children).forEach(r=>delete t[r]),{...e,state:t}},pe=(e,t)=>({...t.state[e]}),D=(e,t)=>{let r=t||{};return e.split(".").forEach(o=>{r=r?.[o]??{}}),r};var ue=(e,t,r)=>{h(t.node,"name",()=>e),h(t.node,"path",()=>t.path),h(t.node,"root",()=>N.of(e,t)?.node),h(t.node,"parent",()=>r.get(t.parents[0])?.node),h(t.node,"utils",()=>A())},fe=e=>{let t={initialState:"'state'",reducer:"'mutations'",reducers:"'mutations'",extraReducers:"'subscribe'",selectors:"'computed'",reducerPath:"nested slices throught 'children'"},r={...e||{}},o={};return o.name=$("createSlice",r,!0),o.state=U("createSlice",o.name,r.state,!0),["mutations","computed","methods","subscribe","children"].forEach(n=>{o[n]=typeof r[n]=="object"&&r[n]?{...r[n]}:{}}),Object.entries(t).forEach(([n,a])=>{r[n]!==void 0&&d("createSlice",o.name).ReduxMismatchProp(n,a)}),o};var Ue=(e,t,r,o)=>typeof o!="function"?d("createSlice",e).InvalidMethod(r,o):(...n)=>o.apply(t.node,n),ye=(e,t,r,o)=>{Object.entries(r).forEach(([n,a])=>{let p=I("createSlice",e,"Slice","method",n,o),i=p?Ue(e,t,p,a):void 0;if(!i)return delete r[p];t.node[p]=i,o.push(p)})};var Se=(e,t)=>{g(t.node,"useSelect",r=>{let o=N.of(e,t,"slice.useSelect"),n={utils:A(),root:o?.node};return o?.selector("Slice",e,a=>{let p=D(t.path,a);return r.apply(n,[p,n])})}),h(t.node,"computed",()=>{})};var Fe=(e,t,r,o)=>o?._reducerDefinitionType===te.asyncThunk?d("createSlice",e).InvalidThunkReducer(r):"reducer"in{...o||{}}?d("createSlice",e).InvalidPreparedReducer(r):typeof o!="function"?d("createSlice",e).InvalidMutation(r,o):(n,a)=>{if(a?.meta?.path===t.path)return o(n,...Array.isArray(a?.payload)?a.payload:[])},me=(e,t,r,o)=>{let n={};return Object.entries(r).forEach(([a,p])=>{let i=I("createSlice",e,"Slice","mutation",a,o),s=i?Fe(e,t,i,p):void 0;if(!s)return delete r[i];n[i]=s,o.push(i)}),n},ge=(e,t)=>{Object.entries(t.redux.actions).forEach(([r,o])=>{t.node[r]=(...n)=>{let a=N.of(e,t,"slice::mutation"),p={...n.length?o(n):o(),meta:{path:t.path}};a?.redux.dispatch(p)}})};var _=(e,t,r,o)=>(n,a,p,i,s)=>{let P=(l,u)=>(a.node[l]=u.node,s.push(l),[l,o.respone(u)]);return p?[...a.children.entries()].map(([l,u])=>P(l,u)):Object.entries(i).map(([l,u])=>{let c=I(e,n,t,r,l,s),m=c?o.attach(c,u,a.node,a,{UnknownNode:()=>d(e,n,t).InvalidChild(c,u),InfiniteOwnership:M=>d(e,n,t).InfiniteOwnership(M)}):void 0;return m?P(c,m):void delete i[c]}).filter(l=>l)};var he=(e,t,r,o,n)=>{let a={},p=()=>[...t.siblings.values()||[]];g(a,"clone",(...i)=>o(e.node,void 0,n?.(...i)).node),g(a,"getLineage",()=>p()),g(a,"getClones",()=>p().filter(i=>i!==e.node)),g(a,"isTypeOf",(i=>e.familyId===r.get(i)?.familyId)),h(e.node,"prototype",()=>a)};var Ge=j,{instances:xe,create:ke,attach:Me,clone:De}=Ge({options:{prepare:fe,clone:(e,t,r,o)=>({...e,state:de(t,o)}),currentCloned:e=>le(e),childCloned:(e,t)=>({object:pe(e,t)})},instantiate(e,t,r){t.node={};let o=["name","path","computed","root","parent","prototype","utils","getState","getInitialState","useSelect"],n=me(e.name,t,e.mutations,o);return t.redux=re(e.name,e.state,n),ue(e.name,t,xe),Se(e.name,t),se(e.name,t),he(t,r,xe,De,a=>({name:e.name,transform:a})),ge(e.name,t),ye(e.name,t,e.methods,o),o},afterInstantiate(e,t,r,o,n){let a=_e(t.node.name,t,o,e.children,n);t.reducer=ce(t.node.name,t,a)}}),_e=_("createSlice","Slice","child",{attach:Me,respone:e=>e.reducer}),be=_("createStore","Store","slice",{attach:Me,respone:e=>e.reducer}),Ae=e=>ke(e);var ze=j,{instances:Le,create:We}=ze({options:{prepare:ae},instantiate(e,t){t.node={};let r=["name","computed","utils","getState","useSelect"];return ie(e.name,t),g(t.node,"getState",()=>t.redux.getState()),ne(e.name,t),r},afterInstantiate(e,t,r,o,n){t.reducer=Object.fromEntries(be(e.name,t,o,e.slices,n)),t.redux=oe({reducer:t.reducer,devTools:e.devTools})}}),Ne=e=>We(e),N=J(Le);function Ee(e){let{store:t,...r}={...e||{}},o=N.get(t,()=>d("StoreProvider").InvalidStore(t));return Q(Z,{...r,store:o?.redux,context:o?.context})}var F=!1,Re=`[OrcheStore] \u{1F6A7} Pre-release Notice
2
6
  Thank you for your interest in OrcheStore.
3
7
  OrcheStore is currently under active development and is not yet ready for production use.
4
8
  APIs, behavior, and internal implementation details may change without notice.
5
9
  The first stable release is currently planned for 2026-06-30.
6
10
  Stay tuned for updates!
7
- `,ie=`[OrcheStore] Diagnostics are enabled.
8
- OrcheStore may emit warnings and errors to help identify incorrect usage, invalid configurations, and potential runtime issues.
9
- Runtime exceptions that stop code execution may still occur regardless of diagnostics settings.
10
- Please resolve all OrcheStore warnings and errors before deploying to production.
11
- Diagnostics can be configured with configureDiagnostics("off" | "errors" | "all").
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
- If this utility is optional, register it as undefined using provideGlobalUtils(...) to suppress future warnings.
15
- `],DeleteProp:e=>["[OrcheStore::global-utils] Avoid deleting properties. Trying to delete property",e,`
16
- Use provideGlobalUtils(...) to set them to undefined instead for type safety.
17
- `],InvalidArgs:()=>`[OrcheStore::global-utils] Expected provideGlobalUtils(...) to receive a non-null object.
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
- OrcheStore currently supports only a single global store instance and will return the existing store.
20
- If you are creating a store inside a React component, create it only once, for example:
21
- const [store] = useState(() => createStore(...));
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};
11
+ `,Oe=e=>(F||(F=!0,T.log([Re])),Ae(e)),Pe=e=>(F||(F=!0,T.log([Re])),Ne(e));var Ur={createStore:Pe,createSlice:Oe,StoreProvider:Ee,getUtils:A,setUtils:q,setReporting:H};export{Ee as StoreProvider,Oe as createSlice,Pe as createStore,Ur as default,A as getUtils,H as setReporting,q as setUtils};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "orchestore",
3
- "version": "0.1.8",
4
- "description": "A function-oriented architecture built on top of Redux Toolkit for simplifying and automating application development.",
3
+ "version": "0.1.9",
4
+ "description": "A function-oriented architecture built on top of Redux Toolkit, inspired by Vuex, that simplifies, automates, and improves state management.",
5
5
  "author": "Oussama Saadaoui",
6
6
  "license": "MIT",
7
7
  "type": "module",