orchestore 0.1.4 → 0.1.5
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 +11 -11
- package/dist/index.d.cts +84 -115
- package/dist/index.d.ts +84 -115
- package/dist/index.js +12 -12
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
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
|
|
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.
|
|
@@ -9,22 +9,22 @@ OrcheStore may emit warnings and errors to help identify incorrect usage, invali
|
|
|
9
9
|
Runtime exceptions that stop code execution may still occur regardless of diagnostics settings.
|
|
10
10
|
Please resolve all OrcheStore warnings and errors before deploying to production.
|
|
11
11
|
Diagnostics can be configured with configureDiagnostics("off" | "errors" | "all").
|
|
12
|
-
`,
|
|
13
|
-
`,...
|
|
12
|
+
`,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,`
|
|
14
14
|
If this utility is optional, register it as undefined using provideGlobalUtils(...) to suppress future warnings.
|
|
15
|
-
`],DeleteProp:
|
|
15
|
+
`],DeleteProp:e=>["[OrcheStore::global-utils] Avoid deleting properties. Trying to delete property",e,`
|
|
16
16
|
Use provideGlobalUtils(...) to set them to undefined instead for type safety.
|
|
17
17
|
`],InvalidArgs:()=>`[OrcheStore::global-utils] Expected provideGlobalUtils(...) to receive a non-null object.
|
|
18
|
-
`},
|
|
18
|
+
`},T={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.`},
|
|
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
23
|
This operation requires a store created with createStore(...).
|
|
24
|
-
`,...
|
|
24
|
+
`,...g(e)],NeverExposed:[`[OrcheStore::${r}] Slice {${t}} has not been exposed in any store.
|
|
25
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::${
|
|
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
27
|
A slice can only be accessed through stores that expose it.
|
|
28
|
-
`,...
|
|
29
|
-
`,...
|
|
30
|
-
`:" ",RequiredName:
|
|
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});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,164 +1,133 @@
|
|
|
1
|
-
import { ProviderProps } from 'react-redux';
|
|
2
1
|
import React from 'react';
|
|
2
|
+
import { ProviderProps } from 'react-redux';
|
|
3
3
|
|
|
4
|
+
/** String-keyed object map. */
|
|
4
5
|
type Dict<Value = any> = Record<string, Value>;
|
|
6
|
+
/** Returns all tuple elements except the first. */
|
|
5
7
|
type Tail<T extends any[]> = T extends [any, ...infer R] ? R : T extends (infer U)[] ? U[] : never;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
declare global {
|
|
11
|
-
namespace OrcheStore {
|
|
12
|
-
/** User-defined framework type slots. */
|
|
13
|
-
interface Slots {
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
/** Resolves a type slot with validation and fallback support. */
|
|
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
|
-
/** Resolved type for application-wide global utilities. */
|
|
20
|
-
type GlobalUtils = Definition<"global", Record<PropertyKey, any>, any>;
|
|
21
|
-
/** Resolved type for the application root store. */
|
|
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;
|
|
8
|
+
/** Removes properties whose value type is `never`. */
|
|
9
|
+
type OmitNever<T> = {
|
|
10
|
+
[K in keyof T as T[K] extends never ? never : K]: T[K];
|
|
51
11
|
};
|
|
12
|
+
/** Recursively makes all object properties and array elements readonly. */
|
|
13
|
+
type ReadOnly<T> = T extends (...args: any[]) => any ? T : T extends readonly (infer U)[] ? ReadonlyArray<ReadOnly<U>> : T extends object ? {
|
|
14
|
+
readonly [K in keyof T]: ReadOnly<T[K]>;
|
|
15
|
+
} : T;
|
|
52
16
|
|
|
53
|
-
/** Reserved slice member names that cannot be overridden by user-defined APIs. */
|
|
54
|
-
type ReservedKeys<R = {}, M = {}> = "name" | "computed" | "root" | "global" | "getState" | "useSelect" | "getPath" | keyof R | keyof M;
|
|
55
|
-
/** Defines the mutations available on a slice. */
|
|
56
|
-
type Mutations<S extends Dict> = Dict<(state: Omit<S, "computed" | "children">, ...args: any[]) => void>;
|
|
57
|
-
/** Defines the computed functions available on a slice. */
|
|
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>;
|
|
59
|
-
/** Defines the methods available on a slice with contextual `this` typing. */
|
|
60
|
-
type Methods = Dict<(...args: any[]) => any>;
|
|
61
|
-
/** Exposes immutable slice state with optional runtime helpers. */
|
|
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>;
|
|
68
17
|
/** Runtime slice API exposed by createSlice(...). */
|
|
69
|
-
type slice<S
|
|
18
|
+
type slice<S, R extends Mutations<S>, M> = GlobalUtils & {
|
|
70
19
|
/** Unique slice identifier. */
|
|
71
|
-
readonly name:
|
|
72
|
-
/** Application-wide global utilities. */
|
|
73
|
-
readonly global: GlobalUtils;
|
|
74
|
-
/** Collection of derived state functions. */
|
|
75
|
-
readonly computed: {
|
|
76
|
-
readonly [K in keyof G]: (...args: Tail<Parameters<G[K]>>) => ReturnType<G[K]>;
|
|
77
|
-
};
|
|
20
|
+
readonly name: string;
|
|
78
21
|
/** Returns the latest immutable state snapshot. */
|
|
79
|
-
readonly getState: (
|
|
22
|
+
readonly getState: () => SliceState<S, true>;
|
|
80
23
|
/** Subscribes to state changes within React components. Runs with a context-bound `this` containing `root` store, `rootState` and `global` utilities. */
|
|
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
|
-
};
|
|
24
|
+
readonly useSelect: <T>(selector: (this: GlobalUtils, state: SliceState<S, true>, context: GlobalUtils) => T) => T;
|
|
84
25
|
/** Returns fully qualified runtime path of the slice. */
|
|
85
|
-
readonly getPath: (
|
|
26
|
+
readonly getPath: () => string;
|
|
86
27
|
} & {
|
|
87
28
|
/** Exposed mutation functions. */
|
|
88
|
-
readonly [K in Exclude<keyof R,
|
|
29
|
+
readonly [K in Exclude<keyof R, ReservedSliceKeys>]: (...args: Tail<Parameters<R[K]>>) => ReturnType<R[K]>;
|
|
89
30
|
} & {
|
|
90
31
|
/** Exposed method functions. */
|
|
91
|
-
readonly [K in Exclude<keyof M,
|
|
92
|
-
} & {
|
|
93
|
-
/** Exposed child slices. */
|
|
94
|
-
readonly [K in Exclude<keyof C, ReservedKeys<R, M>>]: C[K];
|
|
95
|
-
};
|
|
32
|
+
readonly [K in Exclude<keyof M, ReservedSliceKeys<R>>]: M[K];
|
|
33
|
+
} & {};
|
|
96
34
|
/** Configuration object used to create a slice. */
|
|
97
|
-
type sliceOptions<S
|
|
35
|
+
type sliceOptions<S, R extends Mutations<S>, M> = {
|
|
98
36
|
/** Unique slice identifier. */
|
|
99
|
-
name:
|
|
37
|
+
name: string;
|
|
100
38
|
/** Initial state object or lazy state initializer. */
|
|
101
39
|
state: S | (() => S);
|
|
102
40
|
/** Collection of synchronous state transition functions. */
|
|
103
|
-
mutations
|
|
104
|
-
/** Collection of derived state functions. */
|
|
105
|
-
computed?: G & ThisType<G>;
|
|
41
|
+
mutations?: R & ThisType<GlobalUtils>;
|
|
106
42
|
/** Collection of slice methods and orchestration logic. */
|
|
107
|
-
methods?: M & ThisType<slice<S, R, M
|
|
43
|
+
methods?: M & ThisType<slice<S, R, M> & {
|
|
108
44
|
root: RootStore;
|
|
109
45
|
}>;
|
|
110
|
-
/** Collection of nested child slices. */
|
|
111
|
-
children?: C;
|
|
112
|
-
};
|
|
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;
|
|
121
46
|
};
|
|
47
|
+
/** Defines the mutations available on a slice. */
|
|
48
|
+
type Mutations<S> = Dict<(state: SliceState<S, false>, ...args: any[]) => void>;
|
|
49
|
+
/** 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;
|
|
51
|
+
/** 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);
|
|
122
53
|
|
|
123
|
-
/**
|
|
124
|
-
|
|
54
|
+
/** Runtime store API exposed by createStore(...). */
|
|
55
|
+
type store<C> = OmitNever<GlobalUtils & {
|
|
56
|
+
/** Returns the latest immutable state snapshot. */
|
|
57
|
+
readonly getState: () => StoreState<C>;
|
|
58
|
+
/** Subscribes to state changes within React components. Runs with a context-bound `this` containing `global` utilities. */
|
|
59
|
+
readonly useSelect: <T>(selector: (this: GlobalUtils, state: StoreState<C>, context: GlobalUtils) => T) => T;
|
|
60
|
+
} & {
|
|
61
|
+
/** 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;
|
|
63
|
+
}>;
|
|
64
|
+
/** Configuration object used to create a store. */
|
|
65
|
+
type storeOptions<C> = {
|
|
66
|
+
/** Collection of slices. */
|
|
125
67
|
slices: C;
|
|
126
|
-
}
|
|
68
|
+
};
|
|
69
|
+
/** Derived immutable state shape of the store. */
|
|
70
|
+
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;
|
|
72
|
+
}>>;
|
|
73
|
+
/** Props accepted by the store provider component. */
|
|
74
|
+
type StoreProviderProps<T = any> = Omit<ProviderProps, "store" | "serverState" | "context"> & {
|
|
75
|
+
/** The root store instance created with `createStore(...)`. */
|
|
76
|
+
store: store<T>;
|
|
77
|
+
};
|
|
78
|
+
/** Reserved store member names that cannot be overridden by user-defined APIs. */
|
|
79
|
+
type ReservedStoreKeys<R = {}, M = {}> = ("name" | "computed" | "global" | "getState" | "useSelect") | (keyof R | keyof M);
|
|
127
80
|
|
|
128
|
-
|
|
129
|
-
|
|
81
|
+
declare global {
|
|
82
|
+
namespace OrcheStore {
|
|
83
|
+
/** User-defined framework type slots. */
|
|
84
|
+
interface Slots {
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** Resolves a type slot with validation and fallback support. */
|
|
89
|
+
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;
|
|
90
|
+
/** Resolved type for application-wide global utilities. */
|
|
91
|
+
type GlobalUtils = {
|
|
92
|
+
/** Application-wide global utilities. */
|
|
93
|
+
global: Definition<"global", Dict, any>;
|
|
94
|
+
};
|
|
95
|
+
/** Resolved type for the application root store. */
|
|
96
|
+
type RootStore = Definition<"root", store<unknown>, any>;
|
|
130
97
|
|
|
131
98
|
/** Provides an OrcheStore instance to the React component tree. */
|
|
132
|
-
declare function StoreProvider(props: StoreProviderProps): React.JSX.Element;
|
|
99
|
+
declare function StoreProvider<T>(props: StoreProviderProps<T>): React.JSX.Element;
|
|
133
100
|
|
|
134
|
-
type orchestore = {};
|
|
135
101
|
declare global {
|
|
136
|
-
type OrcheStore = orchestore;
|
|
137
102
|
namespace OrcheStore {
|
|
138
103
|
/** Runtime store API exposed by createStore(...). */
|
|
139
|
-
type Store<C
|
|
104
|
+
type Store<C> = store<C>;
|
|
140
105
|
/** Configuration object used to create a store. */
|
|
141
|
-
type StoreOptions<C
|
|
106
|
+
type StoreOptions<C> = storeOptions<C>;
|
|
142
107
|
/** Runtime slice API exposed by createSlice(...). */
|
|
143
|
-
type Slice<S
|
|
108
|
+
type Slice<S, R extends Mutations<S>, M> = slice<S, R, M>;
|
|
144
109
|
/** Configuration object used to create a slice. */
|
|
145
|
-
type SliceOptions<S
|
|
110
|
+
type SliceOptions<S, R extends Mutations<S>, M> = sliceOptions<S, R, M>;
|
|
146
111
|
}
|
|
147
112
|
}
|
|
148
113
|
|
|
149
114
|
/** Returns the current global utilities object. */
|
|
150
|
-
declare function getGlobalUtils(): GlobalUtils;
|
|
115
|
+
declare function getGlobalUtils(): GlobalUtils["global"];
|
|
151
116
|
/** Registers or updates application-wide global utilities. */
|
|
152
|
-
declare function provideGlobalUtils(value: Partial<GlobalUtils>): GlobalUtils;
|
|
117
|
+
declare function provideGlobalUtils(value: Partial<GlobalUtils["global"]>): GlobalUtils["global"];
|
|
153
118
|
|
|
154
119
|
/** Configures diagnostics output level ("off" | "errors" | "all"). */
|
|
155
120
|
declare function configureDiagnostics(level: "off" | "errors" | "all"): void;
|
|
156
121
|
|
|
157
|
-
|
|
122
|
+
/** 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>;
|
|
124
|
+
/** Creates and initializes an OrcheStore instance. */
|
|
125
|
+
declare const createStoreWrapper: <T>(props: storeOptions<T>) => store<T>;
|
|
126
|
+
declare const defaultExport: {
|
|
158
127
|
/** Creates and initializes an OrcheStore instance. */
|
|
159
|
-
createStore:
|
|
128
|
+
createStore: <T>(props: storeOptions<T>) => store<T>;
|
|
160
129
|
/** Creates and initializes an OrcheStore slice. */
|
|
161
|
-
createSlice:
|
|
130
|
+
createSlice: <S, R extends Mutations<S>, M>(props: sliceOptions<S, R, M>) => slice<S, R, M>;
|
|
162
131
|
/** Provides an OrcheStore instance to the React component tree. */
|
|
163
132
|
StoreProvider: typeof StoreProvider;
|
|
164
133
|
/** Registers or updates application-wide global utilities. */
|
|
@@ -169,4 +138,4 @@ declare const OrcheStore$1: {
|
|
|
169
138
|
configureDiagnostics: typeof configureDiagnostics;
|
|
170
139
|
};
|
|
171
140
|
|
|
172
|
-
export { type GlobalUtils, type
|
|
141
|
+
export { type GlobalUtils, type RootStore, type slice as Slice, type sliceOptions as SliceOptions, type store as Store, type storeOptions as StoreOptions, StoreProvider, configureDiagnostics, createSliceWrapper as createSlice, createStoreWrapper as createStore, defaultExport as default, getGlobalUtils, provideGlobalUtils };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,164 +1,133 @@
|
|
|
1
|
-
import { ProviderProps } from 'react-redux';
|
|
2
1
|
import React from 'react';
|
|
2
|
+
import { ProviderProps } from 'react-redux';
|
|
3
3
|
|
|
4
|
+
/** String-keyed object map. */
|
|
4
5
|
type Dict<Value = any> = Record<string, Value>;
|
|
6
|
+
/** Returns all tuple elements except the first. */
|
|
5
7
|
type Tail<T extends any[]> = T extends [any, ...infer R] ? R : T extends (infer U)[] ? U[] : never;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
declare global {
|
|
11
|
-
namespace OrcheStore {
|
|
12
|
-
/** User-defined framework type slots. */
|
|
13
|
-
interface Slots {
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
/** Resolves a type slot with validation and fallback support. */
|
|
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
|
-
/** Resolved type for application-wide global utilities. */
|
|
20
|
-
type GlobalUtils = Definition<"global", Record<PropertyKey, any>, any>;
|
|
21
|
-
/** Resolved type for the application root store. */
|
|
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;
|
|
8
|
+
/** Removes properties whose value type is `never`. */
|
|
9
|
+
type OmitNever<T> = {
|
|
10
|
+
[K in keyof T as T[K] extends never ? never : K]: T[K];
|
|
51
11
|
};
|
|
12
|
+
/** Recursively makes all object properties and array elements readonly. */
|
|
13
|
+
type ReadOnly<T> = T extends (...args: any[]) => any ? T : T extends readonly (infer U)[] ? ReadonlyArray<ReadOnly<U>> : T extends object ? {
|
|
14
|
+
readonly [K in keyof T]: ReadOnly<T[K]>;
|
|
15
|
+
} : T;
|
|
52
16
|
|
|
53
|
-
/** Reserved slice member names that cannot be overridden by user-defined APIs. */
|
|
54
|
-
type ReservedKeys<R = {}, M = {}> = "name" | "computed" | "root" | "global" | "getState" | "useSelect" | "getPath" | keyof R | keyof M;
|
|
55
|
-
/** Defines the mutations available on a slice. */
|
|
56
|
-
type Mutations<S extends Dict> = Dict<(state: Omit<S, "computed" | "children">, ...args: any[]) => void>;
|
|
57
|
-
/** Defines the computed functions available on a slice. */
|
|
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>;
|
|
59
|
-
/** Defines the methods available on a slice with contextual `this` typing. */
|
|
60
|
-
type Methods = Dict<(...args: any[]) => any>;
|
|
61
|
-
/** Exposes immutable slice state with optional runtime helpers. */
|
|
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>;
|
|
68
17
|
/** Runtime slice API exposed by createSlice(...). */
|
|
69
|
-
type slice<S
|
|
18
|
+
type slice<S, R extends Mutations<S>, M> = GlobalUtils & {
|
|
70
19
|
/** Unique slice identifier. */
|
|
71
|
-
readonly name:
|
|
72
|
-
/** Application-wide global utilities. */
|
|
73
|
-
readonly global: GlobalUtils;
|
|
74
|
-
/** Collection of derived state functions. */
|
|
75
|
-
readonly computed: {
|
|
76
|
-
readonly [K in keyof G]: (...args: Tail<Parameters<G[K]>>) => ReturnType<G[K]>;
|
|
77
|
-
};
|
|
20
|
+
readonly name: string;
|
|
78
21
|
/** Returns the latest immutable state snapshot. */
|
|
79
|
-
readonly getState: (
|
|
22
|
+
readonly getState: () => SliceState<S, true>;
|
|
80
23
|
/** Subscribes to state changes within React components. Runs with a context-bound `this` containing `root` store, `rootState` and `global` utilities. */
|
|
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
|
-
};
|
|
24
|
+
readonly useSelect: <T>(selector: (this: GlobalUtils, state: SliceState<S, true>, context: GlobalUtils) => T) => T;
|
|
84
25
|
/** Returns fully qualified runtime path of the slice. */
|
|
85
|
-
readonly getPath: (
|
|
26
|
+
readonly getPath: () => string;
|
|
86
27
|
} & {
|
|
87
28
|
/** Exposed mutation functions. */
|
|
88
|
-
readonly [K in Exclude<keyof R,
|
|
29
|
+
readonly [K in Exclude<keyof R, ReservedSliceKeys>]: (...args: Tail<Parameters<R[K]>>) => ReturnType<R[K]>;
|
|
89
30
|
} & {
|
|
90
31
|
/** Exposed method functions. */
|
|
91
|
-
readonly [K in Exclude<keyof M,
|
|
92
|
-
} & {
|
|
93
|
-
/** Exposed child slices. */
|
|
94
|
-
readonly [K in Exclude<keyof C, ReservedKeys<R, M>>]: C[K];
|
|
95
|
-
};
|
|
32
|
+
readonly [K in Exclude<keyof M, ReservedSliceKeys<R>>]: M[K];
|
|
33
|
+
} & {};
|
|
96
34
|
/** Configuration object used to create a slice. */
|
|
97
|
-
type sliceOptions<S
|
|
35
|
+
type sliceOptions<S, R extends Mutations<S>, M> = {
|
|
98
36
|
/** Unique slice identifier. */
|
|
99
|
-
name:
|
|
37
|
+
name: string;
|
|
100
38
|
/** Initial state object or lazy state initializer. */
|
|
101
39
|
state: S | (() => S);
|
|
102
40
|
/** Collection of synchronous state transition functions. */
|
|
103
|
-
mutations
|
|
104
|
-
/** Collection of derived state functions. */
|
|
105
|
-
computed?: G & ThisType<G>;
|
|
41
|
+
mutations?: R & ThisType<GlobalUtils>;
|
|
106
42
|
/** Collection of slice methods and orchestration logic. */
|
|
107
|
-
methods?: M & ThisType<slice<S, R, M
|
|
43
|
+
methods?: M & ThisType<slice<S, R, M> & {
|
|
108
44
|
root: RootStore;
|
|
109
45
|
}>;
|
|
110
|
-
/** Collection of nested child slices. */
|
|
111
|
-
children?: C;
|
|
112
|
-
};
|
|
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;
|
|
121
46
|
};
|
|
47
|
+
/** Defines the mutations available on a slice. */
|
|
48
|
+
type Mutations<S> = Dict<(state: SliceState<S, false>, ...args: any[]) => void>;
|
|
49
|
+
/** 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;
|
|
51
|
+
/** 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);
|
|
122
53
|
|
|
123
|
-
/**
|
|
124
|
-
|
|
54
|
+
/** Runtime store API exposed by createStore(...). */
|
|
55
|
+
type store<C> = OmitNever<GlobalUtils & {
|
|
56
|
+
/** Returns the latest immutable state snapshot. */
|
|
57
|
+
readonly getState: () => StoreState<C>;
|
|
58
|
+
/** Subscribes to state changes within React components. Runs with a context-bound `this` containing `global` utilities. */
|
|
59
|
+
readonly useSelect: <T>(selector: (this: GlobalUtils, state: StoreState<C>, context: GlobalUtils) => T) => T;
|
|
60
|
+
} & {
|
|
61
|
+
/** 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;
|
|
63
|
+
}>;
|
|
64
|
+
/** Configuration object used to create a store. */
|
|
65
|
+
type storeOptions<C> = {
|
|
66
|
+
/** Collection of slices. */
|
|
125
67
|
slices: C;
|
|
126
|
-
}
|
|
68
|
+
};
|
|
69
|
+
/** Derived immutable state shape of the store. */
|
|
70
|
+
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;
|
|
72
|
+
}>>;
|
|
73
|
+
/** Props accepted by the store provider component. */
|
|
74
|
+
type StoreProviderProps<T = any> = Omit<ProviderProps, "store" | "serverState" | "context"> & {
|
|
75
|
+
/** The root store instance created with `createStore(...)`. */
|
|
76
|
+
store: store<T>;
|
|
77
|
+
};
|
|
78
|
+
/** Reserved store member names that cannot be overridden by user-defined APIs. */
|
|
79
|
+
type ReservedStoreKeys<R = {}, M = {}> = ("name" | "computed" | "global" | "getState" | "useSelect") | (keyof R | keyof M);
|
|
127
80
|
|
|
128
|
-
|
|
129
|
-
|
|
81
|
+
declare global {
|
|
82
|
+
namespace OrcheStore {
|
|
83
|
+
/** User-defined framework type slots. */
|
|
84
|
+
interface Slots {
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** Resolves a type slot with validation and fallback support. */
|
|
89
|
+
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;
|
|
90
|
+
/** Resolved type for application-wide global utilities. */
|
|
91
|
+
type GlobalUtils = {
|
|
92
|
+
/** Application-wide global utilities. */
|
|
93
|
+
global: Definition<"global", Dict, any>;
|
|
94
|
+
};
|
|
95
|
+
/** Resolved type for the application root store. */
|
|
96
|
+
type RootStore = Definition<"root", store<unknown>, any>;
|
|
130
97
|
|
|
131
98
|
/** Provides an OrcheStore instance to the React component tree. */
|
|
132
|
-
declare function StoreProvider(props: StoreProviderProps): React.JSX.Element;
|
|
99
|
+
declare function StoreProvider<T>(props: StoreProviderProps<T>): React.JSX.Element;
|
|
133
100
|
|
|
134
|
-
type orchestore = {};
|
|
135
101
|
declare global {
|
|
136
|
-
type OrcheStore = orchestore;
|
|
137
102
|
namespace OrcheStore {
|
|
138
103
|
/** Runtime store API exposed by createStore(...). */
|
|
139
|
-
type Store<C
|
|
104
|
+
type Store<C> = store<C>;
|
|
140
105
|
/** Configuration object used to create a store. */
|
|
141
|
-
type StoreOptions<C
|
|
106
|
+
type StoreOptions<C> = storeOptions<C>;
|
|
142
107
|
/** Runtime slice API exposed by createSlice(...). */
|
|
143
|
-
type Slice<S
|
|
108
|
+
type Slice<S, R extends Mutations<S>, M> = slice<S, R, M>;
|
|
144
109
|
/** Configuration object used to create a slice. */
|
|
145
|
-
type SliceOptions<S
|
|
110
|
+
type SliceOptions<S, R extends Mutations<S>, M> = sliceOptions<S, R, M>;
|
|
146
111
|
}
|
|
147
112
|
}
|
|
148
113
|
|
|
149
114
|
/** Returns the current global utilities object. */
|
|
150
|
-
declare function getGlobalUtils(): GlobalUtils;
|
|
115
|
+
declare function getGlobalUtils(): GlobalUtils["global"];
|
|
151
116
|
/** Registers or updates application-wide global utilities. */
|
|
152
|
-
declare function provideGlobalUtils(value: Partial<GlobalUtils>): GlobalUtils;
|
|
117
|
+
declare function provideGlobalUtils(value: Partial<GlobalUtils["global"]>): GlobalUtils["global"];
|
|
153
118
|
|
|
154
119
|
/** Configures diagnostics output level ("off" | "errors" | "all"). */
|
|
155
120
|
declare function configureDiagnostics(level: "off" | "errors" | "all"): void;
|
|
156
121
|
|
|
157
|
-
|
|
122
|
+
/** 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>;
|
|
124
|
+
/** Creates and initializes an OrcheStore instance. */
|
|
125
|
+
declare const createStoreWrapper: <T>(props: storeOptions<T>) => store<T>;
|
|
126
|
+
declare const defaultExport: {
|
|
158
127
|
/** Creates and initializes an OrcheStore instance. */
|
|
159
|
-
createStore:
|
|
128
|
+
createStore: <T>(props: storeOptions<T>) => store<T>;
|
|
160
129
|
/** Creates and initializes an OrcheStore slice. */
|
|
161
|
-
createSlice:
|
|
130
|
+
createSlice: <S, R extends Mutations<S>, M>(props: sliceOptions<S, R, M>) => slice<S, R, M>;
|
|
162
131
|
/** Provides an OrcheStore instance to the React component tree. */
|
|
163
132
|
StoreProvider: typeof StoreProvider;
|
|
164
133
|
/** Registers or updates application-wide global utilities. */
|
|
@@ -169,4 +138,4 @@ declare const OrcheStore$1: {
|
|
|
169
138
|
configureDiagnostics: typeof configureDiagnostics;
|
|
170
139
|
};
|
|
171
140
|
|
|
172
|
-
export { type GlobalUtils, type
|
|
141
|
+
export { type GlobalUtils, type RootStore, type slice as Slice, type sliceOptions as SliceOptions, type store as Store, type storeOptions as StoreOptions, StoreProvider, configureDiagnostics, createSliceWrapper as createSlice, createStoreWrapper as createStore, defaultExport as default, getGlobalUtils, provideGlobalUtils };
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import{configureStore as
|
|
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
|
|
2
2
|
Thank you for your interest in OrcheStore.
|
|
3
3
|
OrcheStore is currently under active development and is not yet ready for production use.
|
|
4
4
|
APIs, behavior, and internal implementation details may change without notice.
|
|
5
5
|
The first stable release is currently planned for 2026-06-30.
|
|
6
6
|
Stay tuned for updates!
|
|
7
|
-
`,
|
|
7
|
+
`,B=`[OrcheStore] Diagnostics are enabled.
|
|
8
8
|
OrcheStore may emit warnings and errors to help identify incorrect usage, invalid configurations, and potential runtime issues.
|
|
9
9
|
Runtime exceptions that stop code execution may still occur regardless of diagnostics settings.
|
|
10
10
|
Please resolve all OrcheStore warnings and errors before deploying to production.
|
|
11
11
|
Diagnostics can be configured with configureDiagnostics("off" | "errors" | "all").
|
|
12
|
-
`,
|
|
13
|
-
`,...
|
|
12
|
+
`,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,`
|
|
14
14
|
If this utility is optional, register it as undefined using provideGlobalUtils(...) to suppress future warnings.
|
|
15
|
-
`],DeleteProp:
|
|
15
|
+
`],DeleteProp:e=>["[OrcheStore::global-utils] Avoid deleting properties. Trying to delete property",e,`
|
|
16
16
|
Use provideGlobalUtils(...) to set them to undefined instead for type safety.
|
|
17
17
|
`],InvalidArgs:()=>`[OrcheStore::global-utils] Expected provideGlobalUtils(...) to receive a non-null object.
|
|
18
|
-
`},
|
|
18
|
+
`},T={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.`},
|
|
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
23
|
This operation requires a store created with createStore(...).
|
|
24
|
-
`,...
|
|
24
|
+
`,...g(e)],NeverExposed:[`[OrcheStore::${r}] Slice {${t}} has not been exposed in any store.
|
|
25
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::${
|
|
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
27
|
A slice can only be accessed through stores that expose it.
|
|
28
|
-
`,...
|
|
29
|
-
`,...
|
|
30
|
-
`:" ",RequiredName:
|
|
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};
|
package/package.json
CHANGED