orchestore 0.1.2 → 0.1.4
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 +16 -8
- package/dist/index.d.cts +82 -80
- package/dist/index.d.ts +82 -80
- package/dist/index.js +16 -8
- package/package.json +5 -3
package/dist/index.cjs
CHANGED
|
@@ -1,22 +1,30 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`:" ",RequiredName:e=>`[OrcheStore::${e.module}]${g.target(e)}${e.type} keys must be non-empty strings.`,InvalidName:(e,t)=>`[OrcheStore::${e.module}]${g.target(e)}${e.type} names cannot contain '.' or '/'. Received: ${t}.`,ReservedKey:(e,t)=>`[OrcheStore::${e.module}]${g.target(e)}'${t}' is a reserved name and cannot be used as a ${e.type} key.`,DuplicateKey:(e,t)=>`[OrcheStore::${e.module}]${g.target(e)}${e.type} name '${t}' conflicts with another member.`},F=(e,t)=>{if(e)if(t==="warn")console.warn(e);else if(t==="error")console.error(e);else throw new Error(e);else return!1},D=(e,t="",r="",n)=>typeof e!="string"||!e?!!F(t,n?.[0]):e.includes(".")||e.includes("/")?!!F(r,n?.[1]):!0,ce=(e,t,r)=>{let[n,o]=[g.RequiredName(e),g.InvalidName(e,t)];if(D(t,n,o,["error","error"])){if(r[0].includes(t))return console.error(g.ReservedKey(e,t));if(r[1].includes(t))return console.error(g.DuplicateKey(e,t))}else return;return!0},C=(e,t,r,n)=>(Object.entries(t).forEach(([o,c])=>{let s=ce(e,o,r)?n(o,c):void 0;if(s===void 0)return delete t[o];t[o]=s,r[1].push(o)}),t);var x="all",$={diagnostics:!1,prerelease:!1},J=globalThis.console?.log?.bind?.(globalThis.console)||globalThis.console?.log,le=globalThis.console?.warn?.bind?.(globalThis.console)||globalThis.console?.warn,de=globalThis.console?.error?.bind?.(globalThis.console)||globalThis.console?.error,ue=globalThis.console?.clear?.bind?.(globalThis.console)||globalThis.console?.clear;globalThis.console?.clear&&(globalThis.console.clear=(...e)=>{$.diagnostics=!1,ue?.(...e)});var pe=`[OrcheStore] \u{1F6A7} Pre-release Notice
|
|
1
|
+
"use strict";var te=Object.create;var O=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var ne=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var se=(t,e)=>{for(var r in e)O(t,r,{get:e[r],enumerable:!0})},z=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of oe(e))!ie.call(t,o)&&o!==r&&O(t,o,{get:()=>e[o],enumerable:!(n=re(e,o))||n.enumerable});return t};var ae=(t,e,r)=>(r=t!=null?te(ne(t)):{},z(e||!t||!t.__esModule?O(r,"default",{value:t,enumerable:!0}):r,t)),le=t=>z(O({},"__esModule",{value:!0}),t);var Re={};se(Re,{StoreProvider:()=>k,configureDiagnostics:()=>I,createSlice:()=>K,createStore:()=>L,default:()=>Oe,getGlobalUtils:()=>g,provideGlobalUtils:()=>U});module.exports=le(Re);var Q=require("@reduxjs/toolkit");var $=require("@reduxjs/toolkit"),B=require("react-redux");var C="all",P={diagnostics:!1,prerelease:!1},F=globalThis.console?.log?.bind?.(globalThis.console)||globalThis.console?.log,ce=globalThis.console?.warn?.bind?.(globalThis.console)||globalThis.console?.warn,de=globalThis.console?.error?.bind?.(globalThis.console)||globalThis.console?.error,ue=globalThis.console?.clear?.bind?.(globalThis.console)||globalThis.console?.clear;globalThis.console?.clear&&(globalThis.console.clear=(...t)=>{P.diagnostics=!1,ue?.(...t)});var fe=`[OrcheStore] \u{1F6A7} Pre-release Notice
|
|
3
2
|
Thank you for your interest in OrcheStore.
|
|
4
3
|
OrcheStore is currently under active development and is not yet ready for production use.
|
|
5
4
|
APIs, behavior, and internal implementation details may change without notice.
|
|
6
5
|
The first stable release is currently planned for 2026-06-30.
|
|
7
6
|
Stay tuned for updates!
|
|
8
|
-
`,
|
|
7
|
+
`,pe=`[OrcheStore] Diagnostics are enabled.
|
|
9
8
|
OrcheStore may emit warnings and errors to help identify incorrect usage, invalid configurations, and potential runtime issues.
|
|
10
9
|
Runtime exceptions that stop code execution may still occur regardless of diagnostics settings.
|
|
11
10
|
Please resolve all OrcheStore warnings and errors before deploying to production.
|
|
12
11
|
Diagnostics can be configured with configureDiagnostics("off" | "errors" | "all").
|
|
13
|
-
`,i={inform(
|
|
12
|
+
`,i={inform(t){P[t]||(P[t]=!0,C==="all"&&F?.(t==="prerelease"?fe:pe))},log(...t){C==="all"&&(i.inform("diagnostics"),F?.(...t))},warn(...t){C==="all"&&(i.inform("diagnostics"),ce?.(...t))},error(...t){C!=="off"&&(i.inform("diagnostics"),de?.(...t))}};function I(t){C=t}var J=(...t)=>{let[e,r]=[t[2],t[3]],n=`${t[0]||"Received"}: `,o=t[1]!==!1?"(type: "+typeof e+")":"";if(!r?.(e))return e==null?[`${n}(type: ${e})`]:typeof e=="number"||typeof e=="bigint"||typeof e=="boolean"?[`${n}${o} ${e}`]:typeof e=="object"?[n,e]:e===""?[`${n}Empty String`]:[`${n}${o}`,e]},h=((t,e)=>J("Received",!0,t,e));h.prefixed=(t,e,r,n)=>J(t,e,r,n);var V={InvalidStore:t=>({StoreType:[`[OrcheStore::StoreProvider] Expected a store instance created with createStore(...).
|
|
13
|
+
`,...h(t)]})},R={GetMissingProp:t=>["[OrcheStore::global-utils] Attempted to access a global utility before it became available. Missing property",t,`
|
|
14
14
|
If this utility is optional, register it as undefined using provideGlobalUtils(...) to suppress future warnings.
|
|
15
|
-
`],DeleteProp:
|
|
15
|
+
`],DeleteProp:t=>["[OrcheStore::global-utils] Avoid deleting properties. Trying to delete property",t,`
|
|
16
16
|
Use provideGlobalUtils(...) to set them to undefined instead for type safety.
|
|
17
|
-
`],InvalidArgs:
|
|
18
|
-
|
|
17
|
+
`],InvalidArgs:()=>`[OrcheStore::global-utils] Expected provideGlobalUtils(...) to receive a non-null object.
|
|
18
|
+
`},y={InvalidChild:t=>`[OrcheStore::createStore] Child slice '${t}' must be a slice created with createSlice(...).`,ReduxConflict:t=>`[OrcheStore::createStore] '${t}' is a Redux Toolkit configureStore(...) option and is ignored by OrcheStore.`,singletoneLimitation:()=>`[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
|
|
22
|
+
Avoid useState(createStore(...)) because createStore(...) will execute on every render.`},d={InvalidStore:(t,e,r)=>({StoreType:[`[OrcheStore::${e}] Unable to resolve a valid store instance.
|
|
23
|
+
This operation requires a store created with createStore(...).
|
|
24
|
+
`,...h(t)],NeverExposed:[`[OrcheStore::${e}] Slice {${r}} 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::${e}] Slice {${r}} is not exposed within the target store.
|
|
27
|
+
A slice can only be accessed through stores that expose it.
|
|
28
|
+
`,...h.prefixed("Current store",!1,t)]}),RequiredName:()=>"[OrcheStore::createSlice] Missing required slice name. Expected a non-empty string.",InvalidName:t=>`[OrcheStore::createSlice] Slice names cannot contain '.' or '/'. Received: {${t}}`,RequiredState:t=>`[OrcheStore::createSlice] Missing required state for slice {${t}}.`,InvalidState:(t,e)=>[`[OrcheStore::createSlice]${m.target({slice:t})}Slice state must be a non-null object or a function that returns a non-null object.
|
|
29
|
+
`,...h(e)],InvalidMutation:t=>`[OrcheStore::createSlice] Mutation '${t}' must be a function.`,InvalidMethod:t=>`[OrcheStore::createSlice] Method '${t}' must be a function.`,InvalidChild:t=>`[OrcheStore::createSlice] Child slice '${t}' must be a slice created with createSlice(...).`,ReduxConflict:t=>`[OrcheStore::createSlice] '${t}' is a Redux Toolkit createSlice(...) option and is ignored by OrcheStore.`,ReduxReducerConflict:()=>"[OrcheStore::createSlice] Redux Toolkit asyncThunk reducers are not supported inside mutations. Use methods instead."},m={target:({slice:t})=>t?` Affected slice '${t}':
|
|
30
|
+
`:" ",RequiredName:t=>`[OrcheStore::${t.module}]${m.target(t)}${t.type} keys must be non-empty strings.`,InvalidName:(t,e)=>`[OrcheStore::${t.module}]${m.target(t)}${t.type} names cannot contain '.' or '/'. Received: ${e}.`,ReservedKey:(t,e)=>`[OrcheStore::${t.module}]${m.target(t)}'${e}' is a reserved name and cannot be used as a ${t.type} key.`,DuplicateKey:(t,e)=>`[OrcheStore::${t.module}]${m.target(t)}${t.type} name '${e}' conflicts with another member.`};var W=(t,e)=>{if(t)if(e==="warn")i.warn(t);else if(e==="error")i.error(t);else throw new Error(t);else return!1},M=(t,e="",r="",n)=>typeof t!="string"||!t?!!W(e,n?.[0]):t.includes(".")||t.includes("/")?!!W(r,n?.[1]):!0,Se=(t,e,r)=>{let n=m.RequiredName(t),o=m.InvalidName(t,e);if(M(e,n,o,["error","error"])){if(r[0].includes(e))return i.error(m.ReservedKey(t,e));if(r[1].includes(e))return i.error(m.DuplicateKey(t,e))}else return;return!0},b=(t,e,r,n)=>(Object.entries(e).forEach(([o,l])=>{let u=Se(t,o,r)?n(o,l):void 0;if(u===void 0)return delete e[o];e[o]=u,r[1].push(o)}),e);var me=Object.assign,j=Object.getOwnPropertyDescriptor(Object,"defineProperty")?.value||Object.defineProperty,ye=(t,e,r)=>{j(t,e,{get:r,enumerable:!0,configurable:!1})},ge=(t,e,r)=>{j(t,e,{value:r,writable:!1,enumerable:!0,configurable:!1})},p={assign:me,defineProp:j,defineReadonly:ye,defineMethod:ge},X={isArray:Array.isArray},E={get:Reflect.get,set:Reflect.set,delete:Reflect.deleteProperty};var A=new Proxy({},{get(t,e,r){return e in t||i.error(...R.GetMissingProp(e)),E.get(t,e,r)},set(t,e,r,n){return E.set(t,e,r,n)},deleteProperty(t,e){return i.warn(...R.DeleteProp(e)),E.delete(t,e)}});function g(){return A}function U(t){let e=h(t,r=>r&&typeof r=="object"&&!X.isArray(r));return e?i.error(R.InvalidArgs(),...e):p.assign(A,t),A}function v(t,e){let r={children:{}};return Object.keys(t).filter(o=>o.startsWith(e)).map(o=>o.split(".")).sort((o,l)=>o.length-l.length).forEach(o=>{let l=r;o.slice(0,o.length-1).forEach(u=>l=l[u]||={}),l.children||={},l.children[o[o.length-1]]={...t[o.join(".")]}}),r.children}function _(t,e){return e.split(".").forEach(r=>t=t[r]),t}var H=[],G=t=>t.name,N=(t,e)=>({module:"createSlice",type:t,slice:e.name}),xe=(t,e)=>({root:t.store,rootState:e,global:g()});function K(t){i.inform("prerelease");let e={},r=be(t),n=["name","computed","root","global","getState","useSelect","getPath"],o=[];p.defineReadonly(e,"name",()=>r.name),p.defineReadonly(e,"global",()=>g()),b(N("mutation",e),r.mutations,[n,o],(a,s)=>s?._reducerDefinitionType===$.ReducerType.asyncThunk||"reducer"in{...s||{}}?i.error(d.ReduxReducerConflict()):typeof s!="function"?i.error(d.InvalidMutation(a)):((f,x)=>s(f,...x.payload)));let l=(0,$.createSlice)({name:r.name,initialState:r.state,reducers:r.mutations}),u={path:r.name,slice:e,redux:l,children:{},exposedIn:[]};return p.defineMethod(e,"getPath",()=>G(e)),p.defineMethod(e,"getState",()=>{let a=d.InvalidStore(void 0,"slice.getState",r.name),c=w(u,void 0,a).redux.getState();return v(c,G(e))}),p.defineMethod(e,"useSelect",a=>{let s=d.InvalidStore(void 0,"slice.useSelect",r.name),c=w(u,void 0,s);return(0,B.useSelector)(f=>{let x=xe(c,v(f,""));return a.call(x,_(x.rootState,G(e)),x)})}),Object.entries(l.actions).map(([a,s])=>{e[a]=(...c)=>{let f=d.InvalidStore(void 0,"slice mutation",r.name);return w(u,void 0,f).redux.dispatch(s(c))}}),b(N("method",e),r.methods,[n,o],(a,s)=>typeof s!="function"?i.error(d.InvalidMethod(a)):e[a]=(...c)=>s.apply(e,c)),b(N("child",e),r.children,[n,o],(a,s)=>{}),H.push(u),e}var be=t=>{let e={...t||{}};if(M(e.name,d.RequiredName(),d.InvalidName(e.name)),typeof e.state=="function"){let a=e.state;e.state=()=>{let s=a();if(typeof s!="object"){let c=d.InvalidState(e.name,s);throw c.every(f=>typeof f=="string")?new Error(c.join(" ")):(i.error(...c),new Error)}if(!s)throw new Error(d.RequiredState(e.name));return s}}else{if(typeof e.state!="object"){let a=d.InvalidState(e.name,e.state);throw a.every(s=>typeof s=="string")?new Error(a.join(" ")):(i.error(...a),new Error)}if(!e.state)throw new Error(d.RequiredState(e.name))}e.mutations=typeof e.mutations=="object"&&e.mutations?{...e.mutations}:{},e.computed=typeof e.computed=="object"&&e.computed?{...e.computed}:{},e.methods=typeof e.methods=="object"&&e.methods?{...e.methods}:{},e.children=typeof e.children=="object"&&e.children?{...e.children}:{};let{reducers:r,extraReducers:n,reducerPath:o,initialState:l,selectors:u}=e;return l!==void 0&&i.warn(d.ReduxConflict("initialState")),r!==void 0&&i.warn(d.ReduxConflict("reducers")),n!==void 0&&i.warn(d.ReduxConflict("extraReducers")),o!==void 0&&i.warn(d.ReduxConflict("reducerPath")),u!==void 0&&i.warn(d.ReduxConflict("selectors")),Object.keys(e.computed).length>0&&i.warn("[OrcheStore::createSlice] Computed properties are not yet supported and will be ignored."),Object.keys(e.children).length>0&&i.warn("[OrcheStore::createSlice] Children slices are not yet supported and will be ignored."),e};function D(t){return H.find(e=>e.slice===t)}var q=(t,e,r,n,o)=>{let{redux:l,children:u}=e;return e.path=t,e.exposedIn.push(n),o[t]=l.reducer,Object.entries(u).forEach(([a,s])=>{q(t+"."+a,D(s),e.slice,n,o)}),r[t]=e.slice};var Y=require("react-redux");var T=[],ve=(t,e)=>({root:t,rootState:e,global:g()}),we=t=>({module:"createStore",type:t,slice:""});function L(t){if(T.length===1)return i.warn(y.singletoneLimitation()),T[0].store;i.inform("prerelease");let e={},r=Ce(t),n=["name","computed","global","getState","useSelect"],o=[];p.defineReadonly(e,"global",()=>g());let l={};b(we("slice"),r.slices,[n,o],(s,c)=>{let f=D(c);return f?q(s,f,e,e,l):i.error(y.InvalidChild(s))});let u=(0,Q.configureStore)({reducer:l}),a={provided:!1,store:e,redux:u};return p.defineMethod(e,"getState",()=>v(u.getState(),"")),p.defineMethod(e,"useSelect",s=>(0,Y.useSelector)(c=>{let f=ve(e,v(c,""));return s.call(f,f.rootState,f)})),T.push(a),e}var Ce=t=>{let e={...t||{}};e.slices=typeof e.slices=="object"&&e.slices?{...e.slices}:{};let{reducer:r,devTools:n,duplicateMiddlewareCheck:o,enhancers:l,middleware:u,preloadedState:a}=e;return r!==void 0&&i.warn(y.ReduxConflict("reducer")),n!==void 0&&i.warn(y.ReduxConflict("devTools")),o!==void 0&&i.warn(y.ReduxConflict("duplicateMiddlewareCheck")),l!==void 0&&i.warn(y.ReduxConflict("enhancers")),u!==void 0&&i.warn(y.ReduxConflict("middleware")),a!==void 0&&i.warn(y.ReduxConflict("preloadedState")),e};function w(t,e,r={}){let n;if((!t||e!==void 0)&&!T.find(o=>o.store===e)?n=r.StoreType:t&&!t.exposedIn.length?n=r.NeverExposed:t&&e&&!t.exposedIn.includes(e)&&(n=r.NotInTree),e=t&&e===void 0?t.exposedIn[0]:e,n)throw n.every(o=>typeof o=="string")?new Error(n.join(" ")):(i.error(...n),new Error);return T.find(o=>o.store===e)}var Z=ae(require("react"),1),ee=require("react-redux");function k(t){let{store:e,...r}={...t||{}},n=w(void 0,e,V.InvalidStore(e));return n.provided||(n.provided=!0),Z.default.createElement(ee.Provider,{...r,store:n.redux})}var Te={createStore:L,createSlice:K,StoreProvider:k,provideGlobalUtils:U,getGlobalUtils:g,configureDiagnostics:I},Oe=Te;0&&(module.exports={StoreProvider,configureDiagnostics,createSlice,createStore,getGlobalUtils,provideGlobalUtils});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { ProviderProps } from 'react-redux';
|
|
2
|
+
import React from 'react';
|
|
3
3
|
|
|
4
4
|
type Dict<Value = any> = Record<string, Value>;
|
|
5
5
|
type Tail<T extends any[]> = T extends [any, ...infer R] ? R : T extends (infer U)[] ? U[] : never;
|
|
@@ -16,33 +16,59 @@ declare global {
|
|
|
16
16
|
}
|
|
17
17
|
/** Resolves a type slot with validation and fallback support. */
|
|
18
18
|
type Definition<T, Rule, Default> = T extends keyof OrcheStore.Slots ? Exclude<OrcheStore.Slots[T], undefined | null> extends Rule ? Exclude<OrcheStore.Slots[T], undefined | null> : Default : Default;
|
|
19
|
-
/** Validation rule for the `global` type slot. */
|
|
20
|
-
type GlobalUtilsRule = Record<PropertyKey, any>;
|
|
21
|
-
/** Validation rule for the `root` type slot. */
|
|
22
|
-
type RootStoreRule = Record<PropertyKey, any>;
|
|
23
19
|
/** Resolved type for application-wide global utilities. */
|
|
24
|
-
type GlobalUtils = Definition<"global",
|
|
20
|
+
type GlobalUtils = Definition<"global", Record<PropertyKey, any>, any>;
|
|
25
21
|
/** Resolved type for the application root store. */
|
|
26
|
-
type RootStore = Definition<"root",
|
|
22
|
+
type RootStore = Definition<"root", AnyStore, any>;
|
|
23
|
+
|
|
24
|
+
/** Exposes immutable store state. */
|
|
25
|
+
type ExposedState$1<C extends Dict<AnySlice>> = {
|
|
26
|
+
readonly [K in keyof C]: ReturnType<C[K]["getState"]>;
|
|
27
|
+
};
|
|
28
|
+
/** Reserved store member names that cannot be overridden by user-defined APIs. */
|
|
29
|
+
type ReservedKeys$1<R = {}, M = {}> = "name" | "computed" | "global" | "getState" | "useSelect" | keyof R | keyof M;
|
|
30
|
+
type AnyStore = store<any>;
|
|
31
|
+
/** Runtime store API exposed by createStore(...). */
|
|
32
|
+
type store<C extends Dict<AnySlice>> = {
|
|
33
|
+
/** Application-wide global utilities. */
|
|
34
|
+
readonly global: GlobalUtils;
|
|
35
|
+
/** Returns the latest immutable state snapshot. */
|
|
36
|
+
readonly getState: () => ExposedState$1<C>;
|
|
37
|
+
/** Subscribes to state changes within React components. Runs with a context-bound `this` containing `global` utilities. */
|
|
38
|
+
readonly useSelect: <T>(selector: (this: UseSelectContext<store<C>>, state: ExposedState$1<C>, context: UseSelectContext<store<C>>) => T) => T;
|
|
39
|
+
} & {
|
|
40
|
+
/** Exposed slices. */
|
|
41
|
+
readonly [K in Exclude<keyof C, ReservedKeys$1>]: C[K];
|
|
42
|
+
};
|
|
43
|
+
/** Configuration object used to create a store. */
|
|
44
|
+
type storeOptions<C extends Dict<AnySlice>> = {
|
|
45
|
+
/** Collection of slices. */
|
|
46
|
+
slices?: C;
|
|
47
|
+
};
|
|
48
|
+
type StoreProviderProps = Omit<ProviderProps, "store" | "serverState" | "context"> & {
|
|
49
|
+
/** The root OrcheStore instance created with `createStore(...)`. */
|
|
50
|
+
store: AnyStore;
|
|
51
|
+
};
|
|
27
52
|
|
|
28
53
|
/** Reserved slice member names that cannot be overridden by user-defined APIs. */
|
|
29
|
-
type ReservedKeys
|
|
54
|
+
type ReservedKeys<R = {}, M = {}> = "name" | "computed" | "root" | "global" | "getState" | "useSelect" | "getPath" | keyof R | keyof M;
|
|
30
55
|
/** Defines the mutations available on a slice. */
|
|
31
|
-
type Mutations<S extends Dict> = Dict<(state: Omit<S, "computed">, ...args: any[]) => void>;
|
|
56
|
+
type Mutations<S extends Dict> = Dict<(state: Omit<S, "computed" | "children">, ...args: any[]) => void>;
|
|
32
57
|
/** Defines the computed functions available on a slice. */
|
|
33
|
-
type Computed<S extends Dict, C extends Dict
|
|
58
|
+
type Computed<S extends Dict, R extends Mutations<S>, M extends Methods, C extends Dict<AnySlice>> = Dict<(state: ExposedState<S, R, M, C>, ...args: any[]) => any>;
|
|
34
59
|
/** Defines the methods available on a slice with contextual `this` typing. */
|
|
35
|
-
type Methods
|
|
36
|
-
/** Defines the child slices nested within a slice. */
|
|
37
|
-
type Children = Dict<slice<any, Mutations<any>, Methods, Dict, Computed<any, any>, any>>;
|
|
60
|
+
type Methods = Dict<(...args: any[]) => any>;
|
|
38
61
|
/** Exposes immutable slice state with optional runtime helpers. */
|
|
39
|
-
type ExposedState<S extends Dict,
|
|
62
|
+
type ExposedState<S extends Dict, R extends Mutations<S>, M extends Methods, C extends Dict<AnySlice>> = DeepReadonly<Omit<S, "computed" | "children">> & {
|
|
63
|
+
children: {
|
|
64
|
+
[K in Exclude<keyof C, ReservedKeys<R, M>>]: ReturnType<C[K]["getState"]>;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
type AnySlice = slice<any, any, any, any, any>;
|
|
40
68
|
/** Runtime slice API exposed by createSlice(...). */
|
|
41
|
-
type slice<S extends Dict
|
|
69
|
+
type slice<S extends Dict, R extends Mutations<S>, M extends Methods, C extends Dict<AnySlice>, G extends Computed<S, R, M, C>, N extends string = string> = {
|
|
42
70
|
/** Unique slice identifier. */
|
|
43
71
|
readonly name: N;
|
|
44
|
-
/** Fully qualified runtime path of the slice. */
|
|
45
|
-
readonly path: string;
|
|
46
72
|
/** Application-wide global utilities. */
|
|
47
73
|
readonly global: GlobalUtils;
|
|
48
74
|
/** Collection of derived state functions. */
|
|
@@ -50,30 +76,25 @@ type slice<S extends Dict = Dict, R extends Mutations<S> = Mutations<S>, M exten
|
|
|
50
76
|
readonly [K in keyof G]: (...args: Tail<Parameters<G[K]>>) => ReturnType<G[K]>;
|
|
51
77
|
};
|
|
52
78
|
/** Returns the latest immutable state snapshot. */
|
|
53
|
-
readonly getState: () => ExposedState<S, C>;
|
|
79
|
+
readonly getState: (store?: slice<any, any, any, any, any>) => ExposedState<S, R, M, C>;
|
|
54
80
|
/** Subscribes to state changes within React components. Runs with a context-bound `this` containing `root` store, `rootState` and `global` utilities. */
|
|
55
|
-
readonly useSelect:
|
|
81
|
+
readonly useSelect: {
|
|
82
|
+
<T, Store extends AnyStore = RootStore>(selector: (this: UseSelectContext<Store>, state: ExposedState<S, R, M, C>, context: UseSelectContext<any>) => T): T;
|
|
83
|
+
};
|
|
84
|
+
/** Returns fully qualified runtime path of the slice. */
|
|
85
|
+
readonly getPath: (store?: slice<any, any, any, any, any>) => string;
|
|
56
86
|
} & {
|
|
57
87
|
/** Exposed mutation functions. */
|
|
58
|
-
readonly [K in Exclude<keyof R, ReservedKeys
|
|
88
|
+
readonly [K in Exclude<keyof R, ReservedKeys>]: (...args: Tail<Parameters<R[K]>>) => ReturnType<R[K]>;
|
|
59
89
|
} & {
|
|
60
90
|
/** Exposed method functions. */
|
|
61
|
-
readonly [K in Exclude<keyof M, ReservedKeys
|
|
91
|
+
readonly [K in Exclude<keyof M, ReservedKeys<R>>]: M[K];
|
|
62
92
|
} & {
|
|
63
93
|
/** Exposed child slices. */
|
|
64
|
-
readonly [K in Exclude<keyof C, ReservedKeys
|
|
65
|
-
};
|
|
66
|
-
/** Context available inside `useSelect`, providing access to the root store, root state snapshot, and global utilities. */
|
|
67
|
-
type UseSelectContext<RootStore extends store> = {
|
|
68
|
-
/** Root store instance. */
|
|
69
|
-
root: RootStore;
|
|
70
|
-
/** Latest root state snapshot. */
|
|
71
|
-
rootState: ReturnType<RootStore["getState"]>;
|
|
72
|
-
/** Global utilities shared across slices. */
|
|
73
|
-
global: GlobalUtils;
|
|
94
|
+
readonly [K in Exclude<keyof C, ReservedKeys<R, M>>]: C[K];
|
|
74
95
|
};
|
|
75
96
|
/** Configuration object used to create a slice. */
|
|
76
|
-
type sliceOptions<S extends Dict
|
|
97
|
+
type sliceOptions<S extends Dict, R extends Mutations<S>, M extends Methods, C extends Dict<AnySlice>, G extends Computed<S, R, M, C>, N extends string = string> = {
|
|
77
98
|
/** Unique slice identifier. */
|
|
78
99
|
name: N;
|
|
79
100
|
/** Initial state object or lazy state initializer. */
|
|
@@ -89,61 +110,49 @@ type sliceOptions<S extends Dict = Dict, R extends Mutations<S> = Mutations<S>,
|
|
|
89
110
|
/** Collection of nested child slices. */
|
|
90
111
|
children?: C;
|
|
91
112
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
|
|
100
|
-
} & {
|
|
101
|
-
/** Exposed slices. */
|
|
102
|
-
readonly [K in Exclude<keyof C, ReservedKeys>]: C[K];
|
|
113
|
+
/** Context available inside `useSelect`, providing access to the root store, root state snapshot, and global utilities. */
|
|
114
|
+
type UseSelectContext<Store extends AnyStore> = {
|
|
115
|
+
/** Root store instance. */
|
|
116
|
+
root: Store;
|
|
117
|
+
/** Latest root state snapshot. */
|
|
118
|
+
rootState: ReturnType<Store["getState"]>;
|
|
119
|
+
/** Global utilities shared across slices. */
|
|
120
|
+
global: GlobalUtils;
|
|
103
121
|
};
|
|
104
122
|
|
|
105
|
-
type orchestore = {};
|
|
106
|
-
declare global {
|
|
107
|
-
type OrcheStore = orchestore;
|
|
108
|
-
namespace OrcheStore {
|
|
109
|
-
type Store<C extends Children = Children> = store<C>;
|
|
110
|
-
/** Runtime slice API exposed by createSlice(...). */
|
|
111
|
-
type Slice<S extends Dict = Dict, R extends Mutations<S> = Mutations<S>, M extends Methods = Methods, C extends Children = Children, G extends Computed<S, C> = Computed<S, C>, N extends string = string> = slice<S, R, M, C, G, N>;
|
|
112
|
-
/** Configuration object used to create a slice. */
|
|
113
|
-
type SliceOptions<S extends Dict = Dict, R extends Mutations<S> = Mutations<S>, M extends Methods = Methods, C extends Children = Children, G extends Computed<S, C> = Computed<S, C>, N extends string = string> = sliceOptions<S, R, M, C, G, N>;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
123
|
/** Creates and initializes an OrcheStore instance. */
|
|
118
|
-
declare function createStore<C extends
|
|
124
|
+
declare function createStore<C extends Dict<AnySlice>>(props: {
|
|
119
125
|
slices: C;
|
|
120
126
|
}): store<C>;
|
|
121
127
|
|
|
122
128
|
/** Creates and initializes an OrcheStore slice. */
|
|
123
|
-
declare function createSlice<S extends Dict
|
|
129
|
+
declare function createSlice<S extends Dict, R extends Mutations<S>, M extends Methods, C extends Dict<AnySlice>, G extends Computed<S, R, M, C>, N extends string = string>(props: sliceOptions<S, R, M, C, G, N>): slice<S, R, M, C, G, N>;
|
|
124
130
|
|
|
125
|
-
type StoreProviderProps = Omit<ProviderProps, "store" | "serverState" | "context"> & {
|
|
126
|
-
/** The root OrcheStore instance created with `createStore(...)`. */
|
|
127
|
-
store: store;
|
|
128
|
-
};
|
|
129
131
|
/** Provides an OrcheStore instance to the React component tree. */
|
|
130
132
|
declare function StoreProvider(props: StoreProviderProps): React.JSX.Element;
|
|
131
133
|
|
|
134
|
+
type orchestore = {};
|
|
135
|
+
declare global {
|
|
136
|
+
type OrcheStore = orchestore;
|
|
137
|
+
namespace OrcheStore {
|
|
138
|
+
/** Runtime store API exposed by createStore(...). */
|
|
139
|
+
type Store<C extends Dict<AnySlice>> = store<C>;
|
|
140
|
+
/** Configuration object used to create a store. */
|
|
141
|
+
type StoreOptions<C extends Dict<AnySlice>> = storeOptions<C>;
|
|
142
|
+
/** Runtime slice API exposed by createSlice(...). */
|
|
143
|
+
type Slice<S extends Dict, R extends Mutations<S>, M extends Methods, C extends Dict<AnySlice>, G extends Computed<S, R, M, C>, N extends string = string> = slice<S, R, M, C, G, N>;
|
|
144
|
+
/** Configuration object used to create a slice. */
|
|
145
|
+
type SliceOptions<S extends Dict, R extends Mutations<S>, M extends Methods, C extends Dict<AnySlice>, G extends Computed<S, R, M, C>, N extends string = string> = sliceOptions<S, R, M, C, G, N>;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
132
149
|
/** Returns the current global utilities object. */
|
|
133
150
|
declare function getGlobalUtils(): GlobalUtils;
|
|
134
151
|
/** Registers or updates application-wide global utilities. */
|
|
135
152
|
declare function provideGlobalUtils(value: Partial<GlobalUtils>): GlobalUtils;
|
|
136
153
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
* Configures OrcheStore diagnostics output.
|
|
140
|
-
*
|
|
141
|
-
* Levels:
|
|
142
|
-
* - "off" - disables all output
|
|
143
|
-
* - "errors" - shows errors only
|
|
144
|
-
* - "all" - shows logs, warnings, and errors
|
|
145
|
-
*/
|
|
146
|
-
declare function configureDiagnostics(level: DiagnosticsLevel): void;
|
|
154
|
+
/** Configures diagnostics output level ("off" | "errors" | "all"). */
|
|
155
|
+
declare function configureDiagnostics(level: "off" | "errors" | "all"): void;
|
|
147
156
|
|
|
148
157
|
declare const OrcheStore$1: {
|
|
149
158
|
/** Creates and initializes an OrcheStore instance. */
|
|
@@ -156,15 +165,8 @@ declare const OrcheStore$1: {
|
|
|
156
165
|
provideGlobalUtils: typeof provideGlobalUtils;
|
|
157
166
|
/** Returns the current global utilities object. */
|
|
158
167
|
getGlobalUtils: typeof getGlobalUtils;
|
|
159
|
-
/**
|
|
160
|
-
* Configures OrcheStore diagnostics output.
|
|
161
|
-
*
|
|
162
|
-
* Levels:
|
|
163
|
-
* - "off" - disables all output
|
|
164
|
-
* - "errors" - shows errors only
|
|
165
|
-
* - "all" - shows logs, warnings, and errors
|
|
166
|
-
*/
|
|
168
|
+
/** Configures diagnostics output level ("off" | "errors" | "all"). */
|
|
167
169
|
configureDiagnostics: typeof configureDiagnostics;
|
|
168
170
|
};
|
|
169
171
|
|
|
170
|
-
export { type GlobalUtils, type orchestore as OrcheStore, type RootStore, type slice as Slice, type sliceOptions as SliceOptions, type store as Store, StoreProvider, configureDiagnostics, createSlice, createStore, OrcheStore$1 as default, getGlobalUtils, provideGlobalUtils };
|
|
172
|
+
export { type GlobalUtils, type orchestore as OrcheStore, type RootStore, type slice as Slice, type sliceOptions as SliceOptions, type store as Store, type storeOptions as StoreOptions, StoreProvider, configureDiagnostics, createSlice, createStore, OrcheStore$1 as default, getGlobalUtils, provideGlobalUtils };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { ProviderProps } from 'react-redux';
|
|
2
|
+
import React from 'react';
|
|
3
3
|
|
|
4
4
|
type Dict<Value = any> = Record<string, Value>;
|
|
5
5
|
type Tail<T extends any[]> = T extends [any, ...infer R] ? R : T extends (infer U)[] ? U[] : never;
|
|
@@ -16,33 +16,59 @@ declare global {
|
|
|
16
16
|
}
|
|
17
17
|
/** Resolves a type slot with validation and fallback support. */
|
|
18
18
|
type Definition<T, Rule, Default> = T extends keyof OrcheStore.Slots ? Exclude<OrcheStore.Slots[T], undefined | null> extends Rule ? Exclude<OrcheStore.Slots[T], undefined | null> : Default : Default;
|
|
19
|
-
/** Validation rule for the `global` type slot. */
|
|
20
|
-
type GlobalUtilsRule = Record<PropertyKey, any>;
|
|
21
|
-
/** Validation rule for the `root` type slot. */
|
|
22
|
-
type RootStoreRule = Record<PropertyKey, any>;
|
|
23
19
|
/** Resolved type for application-wide global utilities. */
|
|
24
|
-
type GlobalUtils = Definition<"global",
|
|
20
|
+
type GlobalUtils = Definition<"global", Record<PropertyKey, any>, any>;
|
|
25
21
|
/** Resolved type for the application root store. */
|
|
26
|
-
type RootStore = Definition<"root",
|
|
22
|
+
type RootStore = Definition<"root", AnyStore, any>;
|
|
23
|
+
|
|
24
|
+
/** Exposes immutable store state. */
|
|
25
|
+
type ExposedState$1<C extends Dict<AnySlice>> = {
|
|
26
|
+
readonly [K in keyof C]: ReturnType<C[K]["getState"]>;
|
|
27
|
+
};
|
|
28
|
+
/** Reserved store member names that cannot be overridden by user-defined APIs. */
|
|
29
|
+
type ReservedKeys$1<R = {}, M = {}> = "name" | "computed" | "global" | "getState" | "useSelect" | keyof R | keyof M;
|
|
30
|
+
type AnyStore = store<any>;
|
|
31
|
+
/** Runtime store API exposed by createStore(...). */
|
|
32
|
+
type store<C extends Dict<AnySlice>> = {
|
|
33
|
+
/** Application-wide global utilities. */
|
|
34
|
+
readonly global: GlobalUtils;
|
|
35
|
+
/** Returns the latest immutable state snapshot. */
|
|
36
|
+
readonly getState: () => ExposedState$1<C>;
|
|
37
|
+
/** Subscribes to state changes within React components. Runs with a context-bound `this` containing `global` utilities. */
|
|
38
|
+
readonly useSelect: <T>(selector: (this: UseSelectContext<store<C>>, state: ExposedState$1<C>, context: UseSelectContext<store<C>>) => T) => T;
|
|
39
|
+
} & {
|
|
40
|
+
/** Exposed slices. */
|
|
41
|
+
readonly [K in Exclude<keyof C, ReservedKeys$1>]: C[K];
|
|
42
|
+
};
|
|
43
|
+
/** Configuration object used to create a store. */
|
|
44
|
+
type storeOptions<C extends Dict<AnySlice>> = {
|
|
45
|
+
/** Collection of slices. */
|
|
46
|
+
slices?: C;
|
|
47
|
+
};
|
|
48
|
+
type StoreProviderProps = Omit<ProviderProps, "store" | "serverState" | "context"> & {
|
|
49
|
+
/** The root OrcheStore instance created with `createStore(...)`. */
|
|
50
|
+
store: AnyStore;
|
|
51
|
+
};
|
|
27
52
|
|
|
28
53
|
/** Reserved slice member names that cannot be overridden by user-defined APIs. */
|
|
29
|
-
type ReservedKeys
|
|
54
|
+
type ReservedKeys<R = {}, M = {}> = "name" | "computed" | "root" | "global" | "getState" | "useSelect" | "getPath" | keyof R | keyof M;
|
|
30
55
|
/** Defines the mutations available on a slice. */
|
|
31
|
-
type Mutations<S extends Dict> = Dict<(state: Omit<S, "computed">, ...args: any[]) => void>;
|
|
56
|
+
type Mutations<S extends Dict> = Dict<(state: Omit<S, "computed" | "children">, ...args: any[]) => void>;
|
|
32
57
|
/** Defines the computed functions available on a slice. */
|
|
33
|
-
type Computed<S extends Dict, C extends Dict
|
|
58
|
+
type Computed<S extends Dict, R extends Mutations<S>, M extends Methods, C extends Dict<AnySlice>> = Dict<(state: ExposedState<S, R, M, C>, ...args: any[]) => any>;
|
|
34
59
|
/** Defines the methods available on a slice with contextual `this` typing. */
|
|
35
|
-
type Methods
|
|
36
|
-
/** Defines the child slices nested within a slice. */
|
|
37
|
-
type Children = Dict<slice<any, Mutations<any>, Methods, Dict, Computed<any, any>, any>>;
|
|
60
|
+
type Methods = Dict<(...args: any[]) => any>;
|
|
38
61
|
/** Exposes immutable slice state with optional runtime helpers. */
|
|
39
|
-
type ExposedState<S extends Dict,
|
|
62
|
+
type ExposedState<S extends Dict, R extends Mutations<S>, M extends Methods, C extends Dict<AnySlice>> = DeepReadonly<Omit<S, "computed" | "children">> & {
|
|
63
|
+
children: {
|
|
64
|
+
[K in Exclude<keyof C, ReservedKeys<R, M>>]: ReturnType<C[K]["getState"]>;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
type AnySlice = slice<any, any, any, any, any>;
|
|
40
68
|
/** Runtime slice API exposed by createSlice(...). */
|
|
41
|
-
type slice<S extends Dict
|
|
69
|
+
type slice<S extends Dict, R extends Mutations<S>, M extends Methods, C extends Dict<AnySlice>, G extends Computed<S, R, M, C>, N extends string = string> = {
|
|
42
70
|
/** Unique slice identifier. */
|
|
43
71
|
readonly name: N;
|
|
44
|
-
/** Fully qualified runtime path of the slice. */
|
|
45
|
-
readonly path: string;
|
|
46
72
|
/** Application-wide global utilities. */
|
|
47
73
|
readonly global: GlobalUtils;
|
|
48
74
|
/** Collection of derived state functions. */
|
|
@@ -50,30 +76,25 @@ type slice<S extends Dict = Dict, R extends Mutations<S> = Mutations<S>, M exten
|
|
|
50
76
|
readonly [K in keyof G]: (...args: Tail<Parameters<G[K]>>) => ReturnType<G[K]>;
|
|
51
77
|
};
|
|
52
78
|
/** Returns the latest immutable state snapshot. */
|
|
53
|
-
readonly getState: () => ExposedState<S, C>;
|
|
79
|
+
readonly getState: (store?: slice<any, any, any, any, any>) => ExposedState<S, R, M, C>;
|
|
54
80
|
/** Subscribes to state changes within React components. Runs with a context-bound `this` containing `root` store, `rootState` and `global` utilities. */
|
|
55
|
-
readonly useSelect:
|
|
81
|
+
readonly useSelect: {
|
|
82
|
+
<T, Store extends AnyStore = RootStore>(selector: (this: UseSelectContext<Store>, state: ExposedState<S, R, M, C>, context: UseSelectContext<any>) => T): T;
|
|
83
|
+
};
|
|
84
|
+
/** Returns fully qualified runtime path of the slice. */
|
|
85
|
+
readonly getPath: (store?: slice<any, any, any, any, any>) => string;
|
|
56
86
|
} & {
|
|
57
87
|
/** Exposed mutation functions. */
|
|
58
|
-
readonly [K in Exclude<keyof R, ReservedKeys
|
|
88
|
+
readonly [K in Exclude<keyof R, ReservedKeys>]: (...args: Tail<Parameters<R[K]>>) => ReturnType<R[K]>;
|
|
59
89
|
} & {
|
|
60
90
|
/** Exposed method functions. */
|
|
61
|
-
readonly [K in Exclude<keyof M, ReservedKeys
|
|
91
|
+
readonly [K in Exclude<keyof M, ReservedKeys<R>>]: M[K];
|
|
62
92
|
} & {
|
|
63
93
|
/** Exposed child slices. */
|
|
64
|
-
readonly [K in Exclude<keyof C, ReservedKeys
|
|
65
|
-
};
|
|
66
|
-
/** Context available inside `useSelect`, providing access to the root store, root state snapshot, and global utilities. */
|
|
67
|
-
type UseSelectContext<RootStore extends store> = {
|
|
68
|
-
/** Root store instance. */
|
|
69
|
-
root: RootStore;
|
|
70
|
-
/** Latest root state snapshot. */
|
|
71
|
-
rootState: ReturnType<RootStore["getState"]>;
|
|
72
|
-
/** Global utilities shared across slices. */
|
|
73
|
-
global: GlobalUtils;
|
|
94
|
+
readonly [K in Exclude<keyof C, ReservedKeys<R, M>>]: C[K];
|
|
74
95
|
};
|
|
75
96
|
/** Configuration object used to create a slice. */
|
|
76
|
-
type sliceOptions<S extends Dict
|
|
97
|
+
type sliceOptions<S extends Dict, R extends Mutations<S>, M extends Methods, C extends Dict<AnySlice>, G extends Computed<S, R, M, C>, N extends string = string> = {
|
|
77
98
|
/** Unique slice identifier. */
|
|
78
99
|
name: N;
|
|
79
100
|
/** Initial state object or lazy state initializer. */
|
|
@@ -89,61 +110,49 @@ type sliceOptions<S extends Dict = Dict, R extends Mutations<S> = Mutations<S>,
|
|
|
89
110
|
/** Collection of nested child slices. */
|
|
90
111
|
children?: C;
|
|
91
112
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
|
|
100
|
-
} & {
|
|
101
|
-
/** Exposed slices. */
|
|
102
|
-
readonly [K in Exclude<keyof C, ReservedKeys>]: C[K];
|
|
113
|
+
/** Context available inside `useSelect`, providing access to the root store, root state snapshot, and global utilities. */
|
|
114
|
+
type UseSelectContext<Store extends AnyStore> = {
|
|
115
|
+
/** Root store instance. */
|
|
116
|
+
root: Store;
|
|
117
|
+
/** Latest root state snapshot. */
|
|
118
|
+
rootState: ReturnType<Store["getState"]>;
|
|
119
|
+
/** Global utilities shared across slices. */
|
|
120
|
+
global: GlobalUtils;
|
|
103
121
|
};
|
|
104
122
|
|
|
105
|
-
type orchestore = {};
|
|
106
|
-
declare global {
|
|
107
|
-
type OrcheStore = orchestore;
|
|
108
|
-
namespace OrcheStore {
|
|
109
|
-
type Store<C extends Children = Children> = store<C>;
|
|
110
|
-
/** Runtime slice API exposed by createSlice(...). */
|
|
111
|
-
type Slice<S extends Dict = Dict, R extends Mutations<S> = Mutations<S>, M extends Methods = Methods, C extends Children = Children, G extends Computed<S, C> = Computed<S, C>, N extends string = string> = slice<S, R, M, C, G, N>;
|
|
112
|
-
/** Configuration object used to create a slice. */
|
|
113
|
-
type SliceOptions<S extends Dict = Dict, R extends Mutations<S> = Mutations<S>, M extends Methods = Methods, C extends Children = Children, G extends Computed<S, C> = Computed<S, C>, N extends string = string> = sliceOptions<S, R, M, C, G, N>;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
123
|
/** Creates and initializes an OrcheStore instance. */
|
|
118
|
-
declare function createStore<C extends
|
|
124
|
+
declare function createStore<C extends Dict<AnySlice>>(props: {
|
|
119
125
|
slices: C;
|
|
120
126
|
}): store<C>;
|
|
121
127
|
|
|
122
128
|
/** Creates and initializes an OrcheStore slice. */
|
|
123
|
-
declare function createSlice<S extends Dict
|
|
129
|
+
declare function createSlice<S extends Dict, R extends Mutations<S>, M extends Methods, C extends Dict<AnySlice>, G extends Computed<S, R, M, C>, N extends string = string>(props: sliceOptions<S, R, M, C, G, N>): slice<S, R, M, C, G, N>;
|
|
124
130
|
|
|
125
|
-
type StoreProviderProps = Omit<ProviderProps, "store" | "serverState" | "context"> & {
|
|
126
|
-
/** The root OrcheStore instance created with `createStore(...)`. */
|
|
127
|
-
store: store;
|
|
128
|
-
};
|
|
129
131
|
/** Provides an OrcheStore instance to the React component tree. */
|
|
130
132
|
declare function StoreProvider(props: StoreProviderProps): React.JSX.Element;
|
|
131
133
|
|
|
134
|
+
type orchestore = {};
|
|
135
|
+
declare global {
|
|
136
|
+
type OrcheStore = orchestore;
|
|
137
|
+
namespace OrcheStore {
|
|
138
|
+
/** Runtime store API exposed by createStore(...). */
|
|
139
|
+
type Store<C extends Dict<AnySlice>> = store<C>;
|
|
140
|
+
/** Configuration object used to create a store. */
|
|
141
|
+
type StoreOptions<C extends Dict<AnySlice>> = storeOptions<C>;
|
|
142
|
+
/** Runtime slice API exposed by createSlice(...). */
|
|
143
|
+
type Slice<S extends Dict, R extends Mutations<S>, M extends Methods, C extends Dict<AnySlice>, G extends Computed<S, R, M, C>, N extends string = string> = slice<S, R, M, C, G, N>;
|
|
144
|
+
/** Configuration object used to create a slice. */
|
|
145
|
+
type SliceOptions<S extends Dict, R extends Mutations<S>, M extends Methods, C extends Dict<AnySlice>, G extends Computed<S, R, M, C>, N extends string = string> = sliceOptions<S, R, M, C, G, N>;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
132
149
|
/** Returns the current global utilities object. */
|
|
133
150
|
declare function getGlobalUtils(): GlobalUtils;
|
|
134
151
|
/** Registers or updates application-wide global utilities. */
|
|
135
152
|
declare function provideGlobalUtils(value: Partial<GlobalUtils>): GlobalUtils;
|
|
136
153
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
* Configures OrcheStore diagnostics output.
|
|
140
|
-
*
|
|
141
|
-
* Levels:
|
|
142
|
-
* - "off" - disables all output
|
|
143
|
-
* - "errors" - shows errors only
|
|
144
|
-
* - "all" - shows logs, warnings, and errors
|
|
145
|
-
*/
|
|
146
|
-
declare function configureDiagnostics(level: DiagnosticsLevel): void;
|
|
154
|
+
/** Configures diagnostics output level ("off" | "errors" | "all"). */
|
|
155
|
+
declare function configureDiagnostics(level: "off" | "errors" | "all"): void;
|
|
147
156
|
|
|
148
157
|
declare const OrcheStore$1: {
|
|
149
158
|
/** Creates and initializes an OrcheStore instance. */
|
|
@@ -156,15 +165,8 @@ declare const OrcheStore$1: {
|
|
|
156
165
|
provideGlobalUtils: typeof provideGlobalUtils;
|
|
157
166
|
/** Returns the current global utilities object. */
|
|
158
167
|
getGlobalUtils: typeof getGlobalUtils;
|
|
159
|
-
/**
|
|
160
|
-
* Configures OrcheStore diagnostics output.
|
|
161
|
-
*
|
|
162
|
-
* Levels:
|
|
163
|
-
* - "off" - disables all output
|
|
164
|
-
* - "errors" - shows errors only
|
|
165
|
-
* - "all" - shows logs, warnings, and errors
|
|
166
|
-
*/
|
|
168
|
+
/** Configures diagnostics output level ("off" | "errors" | "all"). */
|
|
167
169
|
configureDiagnostics: typeof configureDiagnostics;
|
|
168
170
|
};
|
|
169
171
|
|
|
170
|
-
export { type GlobalUtils, type orchestore as OrcheStore, type RootStore, type slice as Slice, type sliceOptions as SliceOptions, type store as Store, StoreProvider, configureDiagnostics, createSlice, createStore, OrcheStore$1 as default, getGlobalUtils, provideGlobalUtils };
|
|
172
|
+
export { type GlobalUtils, type orchestore as OrcheStore, type RootStore, type slice as Slice, type sliceOptions as SliceOptions, type store as Store, type storeOptions as StoreOptions, StoreProvider, configureDiagnostics, createSlice, createStore, OrcheStore$1 as default, getGlobalUtils, provideGlobalUtils };
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,30 @@
|
|
|
1
|
-
import{configureStore as
|
|
2
|
-
`:" ",RequiredName:e=>`[OrcheStore::${e.module}]${g.target(e)}${e.type} keys must be non-empty strings.`,InvalidName:(e,t)=>`[OrcheStore::${e.module}]${g.target(e)}${e.type} names cannot contain '.' or '/'. Received: ${t}.`,ReservedKey:(e,t)=>`[OrcheStore::${e.module}]${g.target(e)}'${t}' is a reserved name and cannot be used as a ${e.type} key.`,DuplicateKey:(e,t)=>`[OrcheStore::${e.module}]${g.target(e)}${e.type} name '${t}' conflicts with another member.`},G=(e,t)=>{if(e)if(t==="warn")console.warn(e);else if(t==="error")console.error(e);else throw new Error(e);else return!1},E=(e,t="",r="",n)=>typeof e!="string"||!e?!!G(t,n?.[0]):e.includes(".")||e.includes("/")?!!G(r,n?.[1]):!0,_=(e,t,r)=>{let[n,o]=[g.RequiredName(e),g.InvalidName(e,t)];if(E(t,n,o,["error","error"])){if(r[0].includes(t))return console.error(g.ReservedKey(e,t));if(r[1].includes(t))return console.error(g.DuplicateKey(e,t))}else return;return!0},R=(e,t,r,n)=>(Object.entries(t).forEach(([o,c])=>{let s=_(e,o,r)?n(o,c):void 0;if(s===void 0)return delete t[o];t[o]=s,r[1].push(o)}),t);var v="all",j={diagnostics:!1,prerelease:!1},A=globalThis.console?.log?.bind?.(globalThis.console)||globalThis.console?.log,B=globalThis.console?.warn?.bind?.(globalThis.console)||globalThis.console?.warn,H=globalThis.console?.error?.bind?.(globalThis.console)||globalThis.console?.error,Q=globalThis.console?.clear?.bind?.(globalThis.console)||globalThis.console?.clear;globalThis.console?.clear&&(globalThis.console.clear=(...e)=>{j.diagnostics=!1,Q?.(...e)});var Y=`[OrcheStore] \u{1F6A7} Pre-release Notice
|
|
1
|
+
import{configureStore as ce}from"@reduxjs/toolkit";import{createSlice as ne,ReducerType as ie}from"@reduxjs/toolkit";import{useSelector as se}from"react-redux";var T="all",D={diagnostics:!1,prerelease:!1},G=globalThis.console?.log?.bind?.(globalThis.console)||globalThis.console?.log,_=globalThis.console?.warn?.bind?.(globalThis.console)||globalThis.console?.warn,B=globalThis.console?.error?.bind?.(globalThis.console)||globalThis.console?.error,H=globalThis.console?.clear?.bind?.(globalThis.console)||globalThis.console?.clear;globalThis.console?.clear&&(globalThis.console.clear=(...t)=>{D.diagnostics=!1,H?.(...t)});var Q=`[OrcheStore] \u{1F6A7} Pre-release Notice
|
|
3
2
|
Thank you for your interest in OrcheStore.
|
|
4
3
|
OrcheStore is currently under active development and is not yet ready for production use.
|
|
5
4
|
APIs, behavior, and internal implementation details may change without notice.
|
|
6
5
|
The first stable release is currently planned for 2026-06-30.
|
|
7
6
|
Stay tuned for updates!
|
|
8
|
-
`,
|
|
7
|
+
`,Y=`[OrcheStore] Diagnostics are enabled.
|
|
9
8
|
OrcheStore may emit warnings and errors to help identify incorrect usage, invalid configurations, and potential runtime issues.
|
|
10
9
|
Runtime exceptions that stop code execution may still occur regardless of diagnostics settings.
|
|
11
10
|
Please resolve all OrcheStore warnings and errors before deploying to production.
|
|
12
11
|
Diagnostics can be configured with configureDiagnostics("off" | "errors" | "all").
|
|
13
|
-
`,i={inform(
|
|
12
|
+
`,i={inform(t){D[t]||(D[t]=!0,T==="all"&&G?.(t==="prerelease"?Q:Y))},log(...t){T==="all"&&(i.inform("diagnostics"),G?.(...t))},warn(...t){T==="all"&&(i.inform("diagnostics"),_?.(...t))},error(...t){T!=="off"&&(i.inform("diagnostics"),B?.(...t))}};function N(t){T=t}var K=(...t)=>{let[e,r]=[t[2],t[3]],o=`${t[0]||"Received"}: `,n=t[1]!==!1?"(type: "+typeof e+")":"";if(!r?.(e))return e==null?[`${o}(type: ${e})`]:typeof e=="number"||typeof e=="bigint"||typeof e=="boolean"?[`${o}${n} ${e}`]:typeof e=="object"?[o,e]:e===""?[`${o}Empty String`]:[`${o}${n}`,e]},h=((t,e)=>K("Received",!0,t,e));h.prefixed=(t,e,r,o)=>K(t,e,r,o);var q={InvalidStore:t=>({StoreType:[`[OrcheStore::StoreProvider] Expected a store instance created with createStore(...).
|
|
13
|
+
`,...h(t)]})},R={GetMissingProp:t=>["[OrcheStore::global-utils] Attempted to access a global utility before it became available. Missing property",t,`
|
|
14
14
|
If this utility is optional, register it as undefined using provideGlobalUtils(...) to suppress future warnings.
|
|
15
|
-
`],DeleteProp:
|
|
15
|
+
`],DeleteProp:t=>["[OrcheStore::global-utils] Avoid deleting properties. Trying to delete property",t,`
|
|
16
16
|
Use provideGlobalUtils(...) to set them to undefined instead for type safety.
|
|
17
|
-
`],InvalidArgs:
|
|
18
|
-
|
|
17
|
+
`],InvalidArgs:()=>`[OrcheStore::global-utils] Expected provideGlobalUtils(...) to receive a non-null object.
|
|
18
|
+
`},g={InvalidChild:t=>`[OrcheStore::createStore] Child slice '${t}' must be a slice created with createSlice(...).`,ReduxConflict:t=>`[OrcheStore::createStore] '${t}' is a Redux Toolkit configureStore(...) option and is ignored by OrcheStore.`,singletoneLimitation:()=>`[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
|
|
22
|
+
Avoid useState(createStore(...)) because createStore(...) will execute on every render.`},d={InvalidStore:(t,e,r)=>({StoreType:[`[OrcheStore::${e}] Unable to resolve a valid store instance.
|
|
23
|
+
This operation requires a store created with createStore(...).
|
|
24
|
+
`,...h(t)],NeverExposed:[`[OrcheStore::${e}] Slice {${r}} 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::${e}] Slice {${r}} is not exposed within the target store.
|
|
27
|
+
A slice can only be accessed through stores that expose it.
|
|
28
|
+
`,...h.prefixed("Current store",!1,t)]}),RequiredName:()=>"[OrcheStore::createSlice] Missing required slice name. Expected a non-empty string.",InvalidName:t=>`[OrcheStore::createSlice] Slice names cannot contain '.' or '/'. Received: {${t}}`,RequiredState:t=>`[OrcheStore::createSlice] Missing required state for slice {${t}}.`,InvalidState:(t,e)=>[`[OrcheStore::createSlice]${y.target({slice:t})}Slice state must be a non-null object or a function that returns a non-null object.
|
|
29
|
+
`,...h(e)],InvalidMutation:t=>`[OrcheStore::createSlice] Mutation '${t}' must be a function.`,InvalidMethod:t=>`[OrcheStore::createSlice] Method '${t}' must be a function.`,InvalidChild:t=>`[OrcheStore::createSlice] Child slice '${t}' must be a slice created with createSlice(...).`,ReduxConflict:t=>`[OrcheStore::createSlice] '${t}' is a Redux Toolkit createSlice(...) option and is ignored by OrcheStore.`,ReduxReducerConflict:()=>"[OrcheStore::createSlice] Redux Toolkit asyncThunk reducers are not supported inside mutations. Use methods instead."},y={target:({slice:t})=>t?` Affected slice '${t}':
|
|
30
|
+
`:" ",RequiredName:t=>`[OrcheStore::${t.module}]${y.target(t)}${t.type} keys must be non-empty strings.`,InvalidName:(t,e)=>`[OrcheStore::${t.module}]${y.target(t)}${t.type} names cannot contain '.' or '/'. Received: ${e}.`,ReservedKey:(t,e)=>`[OrcheStore::${t.module}]${y.target(t)}'${e}' is a reserved name and cannot be used as a ${t.type} key.`,DuplicateKey:(t,e)=>`[OrcheStore::${t.module}]${y.target(t)}${t.type} name '${e}' conflicts with another member.`};var L=(t,e)=>{if(t)if(e==="warn")i.warn(t);else if(e==="error")i.error(t);else throw new Error(t);else return!1},P=(t,e="",r="",o)=>typeof t!="string"||!t?!!L(e,o?.[0]):t.includes(".")||t.includes("/")?!!L(r,o?.[1]):!0,Z=(t,e,r)=>{let o=y.RequiredName(t),n=y.InvalidName(t,e);if(P(e,o,n,["error","error"])){if(r[0].includes(e))return i.error(y.ReservedKey(t,e));if(r[1].includes(e))return i.error(y.DuplicateKey(t,e))}else return;return!0},v=(t,e,r,o)=>(Object.entries(e).forEach(([n,l])=>{let u=Z(t,n,r)?o(n,l):void 0;if(u===void 0)return delete e[n];e[n]=u,r[1].push(n)}),e);var ee=Object.assign,I=Object.getOwnPropertyDescriptor(Object,"defineProperty")?.value||Object.defineProperty,te=(t,e,r)=>{I(t,e,{get:r,enumerable:!0,configurable:!1})},re=(t,e,r)=>{I(t,e,{value:r,writable:!1,enumerable:!0,configurable:!1})},p={assign:ee,defineProp:I,defineReadonly:te,defineMethod:re},k={isArray:Array.isArray},E={get:Reflect.get,set:Reflect.set,delete:Reflect.deleteProperty};var M=new Proxy({},{get(t,e,r){return e in t||i.error(...R.GetMissingProp(e)),E.get(t,e,r)},set(t,e,r,o){return E.set(t,e,r,o)},deleteProperty(t,e){return i.warn(...R.DeleteProp(e)),E.delete(t,e)}});function x(){return M}function z(t){let e=h(t,r=>r&&typeof r=="object"&&!k.isArray(r));return e?i.error(R.InvalidArgs(),...e):p.assign(M,t),M}function w(t,e){let r={children:{}};return Object.keys(t).filter(n=>n.startsWith(e)).map(n=>n.split(".")).sort((n,l)=>n.length-l.length).forEach(n=>{let l=r;n.slice(0,n.length-1).forEach(u=>l=l[u]||={}),l.children||={},l.children[n[n.length-1]]={...t[n.join(".")]}}),r.children}function F(t,e){return e.split(".").forEach(r=>t=t[r]),t}var J=[],j=t=>t.name,A=(t,e)=>({module:"createSlice",type:t,slice:e.name}),ae=(t,e)=>({root:t.store,rootState:e,global:x()});function V(t){i.inform("prerelease");let e={},r=le(t),o=["name","computed","root","global","getState","useSelect","getPath"],n=[];p.defineReadonly(e,"name",()=>r.name),p.defineReadonly(e,"global",()=>x()),v(A("mutation",e),r.mutations,[o,n],(a,s)=>s?._reducerDefinitionType===ie.asyncThunk||"reducer"in{...s||{}}?i.error(d.ReduxReducerConflict()):typeof s!="function"?i.error(d.InvalidMutation(a)):((f,b)=>s(f,...b.payload)));let l=ne({name:r.name,initialState:r.state,reducers:r.mutations}),u={path:r.name,slice:e,redux:l,children:{},exposedIn:[]};return p.defineMethod(e,"getPath",()=>j(e)),p.defineMethod(e,"getState",()=>{let a=d.InvalidStore(void 0,"slice.getState",r.name),c=C(u,void 0,a).redux.getState();return w(c,j(e))}),p.defineMethod(e,"useSelect",a=>{let s=d.InvalidStore(void 0,"slice.useSelect",r.name),c=C(u,void 0,s);return se(f=>{let b=ae(c,w(f,""));return a.call(b,F(b.rootState,j(e)),b)})}),Object.entries(l.actions).map(([a,s])=>{e[a]=(...c)=>{let f=d.InvalidStore(void 0,"slice mutation",r.name);return C(u,void 0,f).redux.dispatch(s(c))}}),v(A("method",e),r.methods,[o,n],(a,s)=>typeof s!="function"?i.error(d.InvalidMethod(a)):e[a]=(...c)=>s.apply(e,c)),v(A("child",e),r.children,[o,n],(a,s)=>{}),J.push(u),e}var le=t=>{let e={...t||{}};if(P(e.name,d.RequiredName(),d.InvalidName(e.name)),typeof e.state=="function"){let a=e.state;e.state=()=>{let s=a();if(typeof s!="object"){let c=d.InvalidState(e.name,s);throw c.every(f=>typeof f=="string")?new Error(c.join(" ")):(i.error(...c),new Error)}if(!s)throw new Error(d.RequiredState(e.name));return s}}else{if(typeof e.state!="object"){let a=d.InvalidState(e.name,e.state);throw a.every(s=>typeof s=="string")?new Error(a.join(" ")):(i.error(...a),new Error)}if(!e.state)throw new Error(d.RequiredState(e.name))}e.mutations=typeof e.mutations=="object"&&e.mutations?{...e.mutations}:{},e.computed=typeof e.computed=="object"&&e.computed?{...e.computed}:{},e.methods=typeof e.methods=="object"&&e.methods?{...e.methods}:{},e.children=typeof e.children=="object"&&e.children?{...e.children}:{};let{reducers:r,extraReducers:o,reducerPath:n,initialState:l,selectors:u}=e;return l!==void 0&&i.warn(d.ReduxConflict("initialState")),r!==void 0&&i.warn(d.ReduxConflict("reducers")),o!==void 0&&i.warn(d.ReduxConflict("extraReducers")),n!==void 0&&i.warn(d.ReduxConflict("reducerPath")),u!==void 0&&i.warn(d.ReduxConflict("selectors")),Object.keys(e.computed).length>0&&i.warn("[OrcheStore::createSlice] Computed properties are not yet supported and will be ignored."),Object.keys(e.children).length>0&&i.warn("[OrcheStore::createSlice] Children slices are not yet supported and will be ignored."),e};function $(t){return J.find(e=>e.slice===t)}var U=(t,e,r,o,n)=>{let{redux:l,children:u}=e;return e.path=t,e.exposedIn.push(o),n[t]=l.reducer,Object.entries(u).forEach(([a,s])=>{U(t+"."+a,$(s),e.slice,o,n)}),r[t]=e.slice};import{useSelector as de}from"react-redux";var O=[],ue=(t,e)=>({root:t,rootState:e,global:x()}),fe=t=>({module:"createStore",type:t,slice:""});function W(t){if(O.length===1)return i.warn(g.singletoneLimitation()),O[0].store;i.inform("prerelease");let e={},r=pe(t),o=["name","computed","global","getState","useSelect"],n=[];p.defineReadonly(e,"global",()=>x());let l={};v(fe("slice"),r.slices,[o,n],(s,c)=>{let f=$(c);return f?U(s,f,e,e,l):i.error(g.InvalidChild(s))});let u=ce({reducer:l}),a={provided:!1,store:e,redux:u};return p.defineMethod(e,"getState",()=>w(u.getState(),"")),p.defineMethod(e,"useSelect",s=>de(c=>{let f=ue(e,w(c,""));return s.call(f,f.rootState,f)})),O.push(a),e}var pe=t=>{let e={...t||{}};e.slices=typeof e.slices=="object"&&e.slices?{...e.slices}:{};let{reducer:r,devTools:o,duplicateMiddlewareCheck:n,enhancers:l,middleware:u,preloadedState:a}=e;return r!==void 0&&i.warn(g.ReduxConflict("reducer")),o!==void 0&&i.warn(g.ReduxConflict("devTools")),n!==void 0&&i.warn(g.ReduxConflict("duplicateMiddlewareCheck")),l!==void 0&&i.warn(g.ReduxConflict("enhancers")),u!==void 0&&i.warn(g.ReduxConflict("middleware")),a!==void 0&&i.warn(g.ReduxConflict("preloadedState")),e};function C(t,e,r={}){let o;if((!t||e!==void 0)&&!O.find(n=>n.store===e)?o=r.StoreType:t&&!t.exposedIn.length?o=r.NeverExposed:t&&e&&!t.exposedIn.includes(e)&&(o=r.NotInTree),e=t&&e===void 0?t.exposedIn[0]:e,o)throw o.every(n=>typeof n=="string")?new Error(o.join(" ")):(i.error(...o),new Error);return O.find(n=>n.store===e)}import Se from"react";import{Provider as me}from"react-redux";function X(t){let{store:e,...r}={...t||{}},o=C(void 0,e,q.InvalidStore(e));return o.provided||(o.provided=!0),Se.createElement(me,{...r,store:o.redux})}var ye={createStore:W,createSlice:V,StoreProvider:X,provideGlobalUtils:z,getGlobalUtils:x,configureDiagnostics:N},gt=ye;export{X as StoreProvider,N as configureDiagnostics,V as createSlice,W as createStore,gt as default,x as getGlobalUtils,z as provideGlobalUtils};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orchestore",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
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",
|
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
"module": "./dist/index.js",
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"scripts": {
|
|
12
|
-
"
|
|
13
|
-
"
|
|
12
|
+
"init": "node scripts/install.mjs",
|
|
13
|
+
"start": "tsup && node scripts/build.mjs",
|
|
14
|
+
"build": "tsup && node scripts/build.mjs",
|
|
15
|
+
"deploy": "tsup && node scripts/publish.mjs",
|
|
14
16
|
"check": "tsc --noEmit",
|
|
15
17
|
"lint": "eslint ."
|
|
16
18
|
},
|