react-intent-engine-z 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Delpi.Kye
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,200 @@
1
+ ## 📘 react-intent-engine-z
2
+
3
+ - Intent-first orchestration engine for React
4
+ - Decouple UI from async flows, side effects, and business logic.
5
+
6
+ ---
7
+
8
+ #### ✨ Why react-intent-engine-z?
9
+
10
+ - Modern React apps often suffer from:
11
+
12
+ - Business logic leaking into components
13
+
14
+ - Complex async flows spread across hooks
15
+
16
+ - Hard-to-test side effects
17
+
18
+ - Overloaded global stores
19
+
20
+ - react-intent-engine solves this by introducing an intent-driven architecture:
21
+
22
+ - Components declare what they want to do — the engine decides how it happens.
23
+
24
+ - Works great with:
25
+
26
+ - react-scoped-store
27
+
28
+ - React Query / TanStack Query
29
+
30
+ - Hexagonal / DDD architectures
31
+
32
+ ---
33
+
34
+ #### 📦 Installation
35
+ ```ts
36
+ npm install react-intent-engine-z use-sync-external-store
37
+ ```
38
+
39
+ - use-sync-external-store is required for React 17 compatibility.
40
+
41
+ ---
42
+
43
+ #### 🧠 Mental Model
44
+ ```ts
45
+ UI
46
+ └─ emit intent
47
+
48
+ Intent Engine
49
+ ├─ async orchestration
50
+ ├─ business rules
51
+ └─ side effects
52
+ ```
53
+
54
+ ---
55
+
56
+ #### 🚀 Basic Usage
57
+ ##### 1️⃣ Create engine
58
+
59
+ ```ts
60
+ import { createIntentEngine } from "react-intent-engine-z"
61
+
62
+ export const engine = createIntentEngine({
63
+ initialState: {
64
+ auth: {
65
+ user: null,
66
+ loading: false,
67
+ },
68
+ },
69
+ effects: {
70
+ auth: {
71
+ login: async ({ email, password }) => {
72
+ await new Promise(r => setTimeout(r, 500))
73
+ return { id: 1, email }
74
+ },
75
+ },
76
+ },
77
+ })
78
+ ```
79
+
80
+ ##### 2️⃣ Register intent handlers
81
+ ```ts
82
+ engine.on("auth.login.submit", async (intent, ctx) => {
83
+ ctx.set("auth.loading", true)
84
+
85
+ const user = await ctx.effects.auth.login(intent.payload)
86
+
87
+ ctx.set("auth.user", user)
88
+ ctx.set("auth.loading", false)
89
+ })
90
+ ```
91
+
92
+ ##### 3️⃣ Provide engine to React
93
+ ```ts
94
+ import { IntentProvider } from "react-intent-engine-z"
95
+
96
+ <IntentProvider engine={engine}>
97
+ <App />
98
+ </IntentProvider>
99
+ ```
100
+
101
+ ##### 4️⃣ Emit intent from UI
102
+ ```ts
103
+ import { useIntent, useIntentState } from "react-intent-engine-z"
104
+
105
+ function LoginButton() {
106
+ const emit = useIntent()
107
+ const loading = useIntentState(s => s.auth.loading)
108
+
109
+ return (
110
+ <button
111
+ disabled={loading}
112
+ onClick={() =>
113
+ emit({
114
+ type: "auth.login.submit",
115
+ payload: { email: "a@b.com", password: "123" },
116
+ })
117
+ }
118
+ >
119
+ Login
120
+ </button>
121
+ )
122
+ }
123
+ ```
124
+
125
+ - UI components never call APIs or use cases directly.
126
+
127
+ ##### 🔄 Intent Status
128
+ - Track lifecycle state of an intent:
129
+ ```ts
130
+ import { useIntentStatus } from "react-intent-engine-z"
131
+
132
+ const status = useIntentStatus("auth.login.submit")
133
+ // idle | pending | success
134
+ ```
135
+
136
+ ---
137
+
138
+ #### 🧩 Combine with react-scoped-store
139
+ ```ts
140
+ const useLoginStore = createScopedStore(() => ({
141
+ email: "",
142
+ password: "",
143
+ }))
144
+
145
+ function LoginForm() {
146
+ const { email, password } = useLoginStore()
147
+ const emit = useIntent()
148
+
149
+ return (
150
+ <form
151
+ onSubmit={() =>
152
+ emit({
153
+ type: "auth.login.submit",
154
+ payload: { email, password },
155
+ })
156
+ }
157
+ />
158
+ )
159
+ }
160
+ ```
161
+
162
+ - react-scoped-store → local UI state
163
+
164
+ - react-intent-engine → async flow & orchestration
165
+
166
+ ---
167
+
168
+ #### 🧪 Testing (headless)
169
+ - Intent logic can be tested without React:
170
+ ```ts
171
+ await engine.emit({
172
+ type: "auth.login.submit",
173
+ payload: { email: "a@b.com", password: "123" },
174
+ })
175
+
176
+ expect(engine.store.getState().auth.user).toBeDefined()
177
+ ```
178
+
179
+ ---
180
+
181
+ #### 🧠 When to use?
182
+
183
+ - Use react-intent-engine when your app has:
184
+
185
+ - Complex async workflows
186
+
187
+ - Business logic outside UI
188
+
189
+ - Multiple side effects per action
190
+
191
+ - Large or growing teams
192
+
193
+ - Hexagonal / DDD-inspired architecture
194
+
195
+ - This library focuses on behavior and flow, not data fetching or UI state.
196
+ ---
197
+
198
+ #### 📜 License
199
+
200
+ MIT
@@ -0,0 +1,2 @@
1
+ import { Intent, IntentContext } from "./types";
2
+ export declare function createContext(store: any, emit: (intent: Intent) => Promise<void>, effects: any): IntentContext;
@@ -0,0 +1,16 @@
1
+ import { Intent, IntentHandler, Guard, Middleware } from "./types";
2
+ export declare function createIntentEngine<TState extends object>(opts: {
3
+ initialState: TState;
4
+ effects?: any;
5
+ middleware?: Middleware[];
6
+ }): {
7
+ emit: (intent: Intent) => Promise<void>;
8
+ on: (type: string, handler: IntentHandler) => void;
9
+ guard: (type: string, g: Guard) => void;
10
+ store: {
11
+ getState: () => TState;
12
+ setState: (updater: (prev: TState) => TState) => void;
13
+ subscribe: (listener: () => void) => () => boolean;
14
+ };
15
+ getStatus: (type: string) => string;
16
+ };
@@ -0,0 +1,2 @@
1
+ export { createIntentEngine } from "./engine";
2
+ export type { Intent, IntentStatus, IntentHandler, } from "./types";
@@ -0,0 +1 @@
1
+ export declare function composeMiddleware(mw: any[]): (intent: any, handler: () => Promise<void>) => Promise<void>;
@@ -0,0 +1,7 @@
1
+ type Listener = () => void;
2
+ export declare function createStore<T>(initial: T): {
3
+ getState: () => T;
4
+ setState: (updater: (prev: T) => T) => void;
5
+ subscribe: (listener: Listener) => () => boolean;
6
+ };
7
+ export {};
@@ -0,0 +1,15 @@
1
+ export type Intent<T = any> = {
2
+ type: string;
3
+ payload?: T;
4
+ };
5
+ export type IntentStatus = "idle" | "pending" | "success" | "error";
6
+ export type IntentHandler<T extends Intent = Intent> = (intent: T, ctx: IntentContext) => Promise<void> | void;
7
+ export type Guard = (ctx: IntentContext) => boolean;
8
+ export type Middleware = (intent: Intent, next: () => Promise<void>) => Promise<void>;
9
+ export type EffectMap = Record<string, any>;
10
+ export type IntentContext = {
11
+ get<T = any>(path: string): T;
12
+ set(path: string, value: any): void;
13
+ emit(intent: Intent): Promise<void>;
14
+ effects: EffectMap;
15
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react");function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=e(t);function r(t,e,n,r){return new(n||(n=Promise))(function(o,u){function i(t){try{c(r.next(t))}catch(t){u(t)}}function a(t){try{c(r.throw(t))}catch(t){u(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(i,a)}c((r=r.apply(t,e||[])).next())})}function o(t,e){var n,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=e.call(t,u)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function u(t,e,n){if(n||2===arguments.length)for(var r,o=0,u=e.length;o<u;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var i=t.createContext(null),a=i.Provider;function c(){var e=t.useContext(i);if(!e)throw new Error("Missing IntentProvider");return e}function s(t){var e={exports:{}};return t(e,e.exports),e.exports}var f="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},l=n.default.useState,d=n.default.useEffect,p=n.default.useLayoutEffect,v=n.default.useDebugValue;function S(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!f(t,n)}catch(t){return!0}}var y="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,e){var n=e(),r=l({inst:{value:n,getSnapshot:e}}),o=r[0].inst,u=r[1];return p(function(){o.value=n,o.getSnapshot=e,S(o)&&u({inst:o})},[t,n,e]),d(function(){return S(o)&&u({inst:o}),t(function(){S(o)&&u({inst:o})})},[t]),v(n),n},h={useSyncExternalStore:void 0!==n.default.useSyncExternalStore?n.default.useSyncExternalStore:y},_=s(function(t,e){"production"!==process.env.NODE_ENV&&function(){function t(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!o(t,n)}catch(t){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=n.default,o="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},u=r.useState,i=r.useEffect,a=r.useLayoutEffect,c=r.useDebugValue,s=!1,f=!1,l="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(e,n){s||void 0===r.startTransition||(s=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var l=n();if(!f){var d=n();o(l,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var p=(d=u({inst:{value:l,getSnapshot:n}}))[0].inst,v=d[1];return a(function(){p.value=l,p.getSnapshot=n,t(p)&&v({inst:p})},[e,l,n]),i(function(){return t(p)&&v({inst:p}),e(function(){t(p)&&v({inst:p})})},[e]),c(l),l};e.useSyncExternalStore=void 0!==r.useSyncExternalStore?r.useSyncExternalStore:l,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()}),E=s(function(t){"production"===process.env.NODE_ENV?t.exports=h:t.exports=_});exports.IntentProvider=a,exports.createIntentEngine=function(t){var e,n,i,a,c,s,f=(i=t.initialState,a=structuredClone(i),c=new Set,{getState:function(){return a},setState:function(t){a=t(a),c.forEach(function(t){return t()})},subscribe:function(t){return c.add(t),function(){return c.delete(t)}}}),l=null!==(e=t.effects)&&void 0!==e?e:{},d=new Map,p=new Map,v=new Map,S=(s=null!==(n=t.middleware)&&void 0!==n?n:[],function(t,e){var n=-1;return function u(i){return r(this,void 0,void 0,function(){var r;return o(this,function(o){if(i<=n)throw new Error("next() called twice");return n=i,(r=s[i])?[2,r(t,function(){return u(i+1)})]:[2,e()]})})}(0)});return{emit:function t(e){var n;return r(this,void 0,void 0,function(){var u,i=this;return o(this,function(a){switch(a.label){case 0:return u=function(t,e,n){return{get:function(e){return e.split(".").reduce(function(t,e){return null==t?void 0:t[e]},t.getState())},set:function(e,n){t.setState(function(t){for(var r,o=structuredClone(t),u=e.split("."),i=o,a=0;a<u.length-1;a++)i=i[r=u[a]]||(i[r]={});return i[u.at(-1)]=n,o})},emit:e,effects:n}}(f,t,l),(null===(n=p.get(e.type))||void 0===n?void 0:n.some(function(t){return!t(u)}))?[2]:(v.set(e.type,"pending"),[4,S(e,function(){return r(i,void 0,void 0,function(){var t,n,r;return o(this,function(o){switch(o.label){case 0:t=0,n=null!==(r=d.get(e.type))&&void 0!==r?r:[],o.label=1;case 1:return t<n.length?[4,(0,n[t])(e,u)]:[3,4];case 2:o.sent(),o.label=3;case 3:return t++,[3,1];case 4:return[2]}})})})]);case 1:return a.sent(),v.set(e.type,"success"),[2]}})})},on:function(t,e){var n;d.set(t,u(u([],null!==(n=d.get(t))&&void 0!==n?n:[],!0),[e],!1))},guard:function(t,e){var n;p.set(t,u(u([],null!==(n=p.get(t))&&void 0!==n?n:[],!0),[e],!1))},store:f,getStatus:function(t){var e;return null!==(e=v.get(t))&&void 0!==e?e:"idle"}}},exports.useEngine=c,exports.useIntent=function(){var t=c();return function(e){return t.emit(e)}},exports.useIntentState=function(t){var e=c();return E.useSyncExternalStore(e.store.subscribe,function(){return t(e.store.getState())})},exports.useIntentStatus=function(t){return c().getStatus(t)};
@@ -0,0 +1,2 @@
1
+ export * from "./core";
2
+ export * from "./react";
@@ -0,0 +1 @@
1
+ import t,{createContext as e,useContext as n}from"react";function r(t,e,n,r){return new(n||(n=Promise))(function(o,u){function i(t){try{a(r.next(t))}catch(t){u(t)}}function c(t){try{a(r.throw(t))}catch(t){u(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(i,c)}a((r=r.apply(t,e||[])).next())})}function o(t,e){var n,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=c(0),i.throw=c(1),i.return=c(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=e.call(t,u)}catch(t){c=[6,t],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}function u(t,e,n){if(n||2===arguments.length)for(var r,o=0,u=e.length;o<u;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}function i(t){var e,n,i,c,a,s,f=(i=t.initialState,c=structuredClone(i),a=new Set,{getState:function(){return c},setState:function(t){c=t(c),a.forEach(function(t){return t()})},subscribe:function(t){return a.add(t),function(){return a.delete(t)}}}),l=null!==(e=t.effects)&&void 0!==e?e:{},d=new Map,p=new Map,v=new Map,S=(s=null!==(n=t.middleware)&&void 0!==n?n:[],function(t,e){var n=-1;return function u(i){return r(this,void 0,void 0,function(){var r;return o(this,function(o){if(i<=n)throw new Error("next() called twice");return n=i,(r=s[i])?[2,r(t,function(){return u(i+1)})]:[2,e()]})})}(0)});return{emit:function t(e){var n;return r(this,void 0,void 0,function(){var u,i=this;return o(this,function(c){switch(c.label){case 0:return u=function(t,e,n){return{get:function(e){return e.split(".").reduce(function(t,e){return null==t?void 0:t[e]},t.getState())},set:function(e,n){t.setState(function(t){for(var r,o=structuredClone(t),u=e.split("."),i=o,c=0;c<u.length-1;c++)i=i[r=u[c]]||(i[r]={});return i[u.at(-1)]=n,o})},emit:e,effects:n}}(f,t,l),(null===(n=p.get(e.type))||void 0===n?void 0:n.some(function(t){return!t(u)}))?[2]:(v.set(e.type,"pending"),[4,S(e,function(){return r(i,void 0,void 0,function(){var t,n,r;return o(this,function(o){switch(o.label){case 0:t=0,n=null!==(r=d.get(e.type))&&void 0!==r?r:[],o.label=1;case 1:return t<n.length?[4,(0,n[t])(e,u)]:[3,4];case 2:o.sent(),o.label=3;case 3:return t++,[3,1];case 4:return[2]}})})})]);case 1:return c.sent(),v.set(e.type,"success"),[2]}})})},on:function(t,e){var n;d.set(t,u(u([],null!==(n=d.get(t))&&void 0!==n?n:[],!0),[e],!1))},guard:function(t,e){var n;p.set(t,u(u([],null!==(n=p.get(t))&&void 0!==n?n:[],!0),[e],!1))},store:f,getStatus:function(t){var e;return null!==(e=v.get(t))&&void 0!==e?e:"idle"}}}"function"==typeof SuppressedError&&SuppressedError;var c=e(null),a=c.Provider;function s(){var t=n(c);if(!t)throw new Error("Missing IntentProvider");return t}function f(){var t=s();return function(e){return t.emit(e)}}function l(t){var e={exports:{}};return t(e,e.exports),e.exports}var d="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},p=t.useState,v=t.useEffect,S=t.useLayoutEffect,y=t.useDebugValue;function h(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!d(t,n)}catch(t){return!0}}var _="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,e){var n=e(),r=p({inst:{value:n,getSnapshot:e}}),o=r[0].inst,u=r[1];return S(function(){o.value=n,o.getSnapshot=e,h(o)&&u({inst:o})},[t,n,e]),v(function(){return h(o)&&u({inst:o}),t(function(){h(o)&&u({inst:o})})},[t]),y(n),n},E={useSyncExternalStore:void 0!==t.useSyncExternalStore?t.useSyncExternalStore:_},O=l(function(e,n){"production"!==process.env.NODE_ENV&&function(){function e(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!o(t,n)}catch(t){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=t,o="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},u=r.useState,i=r.useEffect,c=r.useLayoutEffect,a=r.useDebugValue,s=!1,f=!1,l="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,n){s||void 0===r.startTransition||(s=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var l=n();if(!f){var d=n();o(l,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var p=(d=u({inst:{value:l,getSnapshot:n}}))[0].inst,v=d[1];return c(function(){p.value=l,p.getSnapshot=n,e(p)&&v({inst:p})},[t,l,n]),i(function(){return e(p)&&v({inst:p}),t(function(){e(p)&&v({inst:p})})},[t]),a(l),l};n.useSyncExternalStore=void 0!==r.useSyncExternalStore?r.useSyncExternalStore:l,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()}),w=l(function(t){"production"===process.env.NODE_ENV?t.exports=E:t.exports=O});function g(t){var e=s();return w.useSyncExternalStore(e.store.subscribe,function(){return t(e.store.getState())})}function b(t){return s().getStatus(t)}export{a as IntentProvider,i as createIntentEngine,s as useEngine,f as useIntent,g as useIntentState,b as useIntentStatus};
@@ -0,0 +1 @@
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ReactIntentEngine={},t.React)}(this,function(t,e){"use strict";function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=n(e);function o(t,e,n,r){return new(n||(n=Promise))(function(o,u){function i(t){try{c(r.next(t))}catch(t){u(t)}}function a(t){try{c(r.throw(t))}catch(t){u(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(i,a)}c((r=r.apply(t,e||[])).next())})}function u(t,e){var n,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=e.call(t,u)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function i(t,e,n){if(n||2===arguments.length)for(var r,o=0,u=e.length;o<u;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var a=e.createContext(null),c=a.Provider;function s(){var t=e.useContext(a);if(!t)throw new Error("Missing IntentProvider");return t}function f(t){var e={exports:{}};return t(e,e.exports),e.exports}var l="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},d=r.default.useState,p=r.default.useEffect,v=r.default.useLayoutEffect,y=r.default.useDebugValue;function S(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!l(t,n)}catch(t){return!0}}var h="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,e){var n=e(),r=d({inst:{value:n,getSnapshot:e}}),o=r[0].inst,u=r[1];return v(function(){o.value=n,o.getSnapshot=e,S(o)&&u({inst:o})},[t,n,e]),p(function(){return S(o)&&u({inst:o}),t(function(){S(o)&&u({inst:o})})},[t]),y(n),n},_={useSyncExternalStore:void 0!==r.default.useSyncExternalStore?r.default.useSyncExternalStore:h},g=f(function(t,e){"production"!==process.env.NODE_ENV&&function(){function t(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!o(t,n)}catch(t){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var n=r.default,o="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},u=n.useState,i=n.useEffect,a=n.useLayoutEffect,c=n.useDebugValue,s=!1,f=!1,l="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(e,r){s||void 0===n.startTransition||(s=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var l=r();if(!f){var d=r();o(l,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var p=(d=u({inst:{value:l,getSnapshot:r}}))[0].inst,v=d[1];return a(function(){p.value=l,p.getSnapshot=r,t(p)&&v({inst:p})},[e,l,r]),i(function(){return t(p)&&v({inst:p}),e(function(){t(p)&&v({inst:p})})},[e]),c(l),l};e.useSyncExternalStore=void 0!==n.useSyncExternalStore?n.useSyncExternalStore:l,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()}),E=f(function(t){"production"===process.env.NODE_ENV?t.exports=_:t.exports=g});t.IntentProvider=c,t.createIntentEngine=function(t){var e,n,r,a,c,s,f=(r=t.initialState,a=structuredClone(r),c=new Set,{getState:function(){return a},setState:function(t){a=t(a),c.forEach(function(t){return t()})},subscribe:function(t){return c.add(t),function(){return c.delete(t)}}}),l=null!==(e=t.effects)&&void 0!==e?e:{},d=new Map,p=new Map,v=new Map,y=(s=null!==(n=t.middleware)&&void 0!==n?n:[],function(t,e){var n=-1;return function r(i){return o(this,void 0,void 0,function(){var o;return u(this,function(u){if(i<=n)throw new Error("next() called twice");return n=i,(o=s[i])?[2,o(t,function(){return r(i+1)})]:[2,e()]})})}(0)});return{emit:function t(e){var n;return o(this,void 0,void 0,function(){var r,i=this;return u(this,function(a){switch(a.label){case 0:return r=function(t,e,n){return{get:function(e){return e.split(".").reduce(function(t,e){return null==t?void 0:t[e]},t.getState())},set:function(e,n){t.setState(function(t){for(var r,o=structuredClone(t),u=e.split("."),i=o,a=0;a<u.length-1;a++)i=i[r=u[a]]||(i[r]={});return i[u.at(-1)]=n,o})},emit:e,effects:n}}(f,t,l),(null===(n=p.get(e.type))||void 0===n?void 0:n.some(function(t){return!t(r)}))?[2]:(v.set(e.type,"pending"),[4,y(e,function(){return o(i,void 0,void 0,function(){var t,n,o;return u(this,function(u){switch(u.label){case 0:t=0,n=null!==(o=d.get(e.type))&&void 0!==o?o:[],u.label=1;case 1:return t<n.length?[4,(0,n[t])(e,r)]:[3,4];case 2:u.sent(),u.label=3;case 3:return t++,[3,1];case 4:return[2]}})})})]);case 1:return a.sent(),v.set(e.type,"success"),[2]}})})},on:function(t,e){var n;d.set(t,i(i([],null!==(n=d.get(t))&&void 0!==n?n:[],!0),[e],!1))},guard:function(t,e){var n;p.set(t,i(i([],null!==(n=p.get(t))&&void 0!==n?n:[],!0),[e],!1))},store:f,getStatus:function(t){var e;return null!==(e=v.get(t))&&void 0!==e?e:"idle"}}},t.useEngine=s,t.useIntent=function(){var t=s();return function(e){return t.emit(e)}},t.useIntentState=function(t){var e=s();return E.useSyncExternalStore(e.store.subscribe,function(){return t(e.store.getState())})},t.useIntentStatus=function(t){return s().getStatus(t)},Object.defineProperty(t,"__esModule",{value:!0})});
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ export declare const IntentProvider: import("react").Provider<any>;
3
+ export declare function useEngine(): any;
@@ -0,0 +1,4 @@
1
+ export { IntentProvider, useEngine } from "./IntentProvider";
2
+ export { useIntent } from "./useIntent";
3
+ export { useIntentState } from "./useIntentState";
4
+ export { useIntentStatus } from "./useIntentStatus";
@@ -0,0 +1,2 @@
1
+ import { Intent } from "../core/types";
2
+ export declare function useIntent(): (intent: Intent) => any;
@@ -0,0 +1 @@
1
+ export declare function useIntentState<T>(selector: (s: any) => T): T;
@@ -0,0 +1 @@
1
+ export declare function useIntentStatus(type: string): any;
@@ -0,0 +1 @@
1
+ export { useSyncExternalStore } from "use-sync-external-store/shim";
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "react-intent-engine-z",
3
+ "version": "1.0.0",
4
+ "description": "Intent-first orchestration engine for React applications",
5
+ "license": "MIT",
6
+ "author": "Delpi.Kye",
7
+
8
+ "sideEffects": false,
9
+
10
+ "main": "build/index.cjs",
11
+ "module": "build/index.esm.js",
12
+ "types": "build/index.d.ts",
13
+
14
+ "exports": {
15
+ ".": {
16
+ "types": "./build/index.d.ts",
17
+ "import": "./build/index.esm.js",
18
+ "require": "./build/index.cjs"
19
+ }
20
+ },
21
+
22
+ "files": [
23
+ "build"
24
+ ],
25
+
26
+ "scripts": {
27
+ "clean": "rimraf build",
28
+ "build": "rollup -c",
29
+ "cb": "npm run clean && npm run build",
30
+ "prepublishOnly": "npm run build"
31
+ },
32
+
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/delpikye-v/react-intent-engine.git"
36
+ },
37
+ "homepage": "https://github.com/delpikye-v/react-intent-engine#readme",
38
+ "bugs": {
39
+ "url": "https://github.com/delpikye-v/react-intent-engine/issues"
40
+ },
41
+
42
+ "keywords": [
43
+ "react",
44
+ "intent",
45
+ "intent-engine",
46
+ "orchestration",
47
+ "state-management",
48
+ "architecture",
49
+ "ddd",
50
+ "hexagonal",
51
+ "side-effects",
52
+ "async-flow",
53
+ "react-hooks",
54
+ "react-library"
55
+ ],
56
+
57
+ "peerDependencies": {
58
+ "react": ">=17"
59
+ },
60
+
61
+ "dependencies": {
62
+ "use-sync-external-store": "^1.6.0"
63
+ },
64
+
65
+ "devDependencies": {
66
+ "@rollup/plugin-commonjs": "^17.1.0",
67
+ "@rollup/plugin-node-resolve": "^11.2.1",
68
+ "@types/react": "^17.0.90",
69
+
70
+ "rimraf": "^3.0.2",
71
+ "rollup": "^2.56.3",
72
+ "rollup-plugin-peer-deps-external": "^2.2.4",
73
+ "rollup-plugin-terser": "^7.0.2",
74
+ "rollup-plugin-typescript2": "^0.29.0",
75
+
76
+ "typescript": "^4.4.2",
77
+ "tslib": "^2.3.1"
78
+ }
79
+ }