@rivetkit/framework-base 0.9.6 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mod.cjs +1 -1
- package/dist/mod.d.ts +8 -0
- package/dist/mod.js +13 -9
- package/package.json +2 -2
package/dist/mod.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=new WeakMap,S=new WeakMap,g={current:[]};let b=!1;const v=new Set,k=new Map;function C(i){const n=Array.from(i).sort((t,e)=>t instanceof f&&t.options.deps.includes(e)?1:e instanceof f&&e.options.deps.includes(t)?-1:0);for(const t of n){if(g.current.includes(t))continue;g.current.push(t),t.recompute();const e=S.get(t);if(e)for(const s of e){const o=p.get(s);o&&C(o)}}}function O(i){i.listeners.forEach(n=>n({prevVal:i.prevState,currentVal:i.state}))}function F(i){i.listeners.forEach(n=>n({prevVal:i.prevState,currentVal:i.state}))}function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=new WeakMap,S=new WeakMap,g={current:[]};let b=!1;const v=new Set,k=new Map;function C(i){const n=Array.from(i).sort((t,e)=>t instanceof f&&t.options.deps.includes(e)?1:e instanceof f&&e.options.deps.includes(t)?-1:0);for(const t of n){if(g.current.includes(t))continue;g.current.push(t),t.recompute();const e=S.get(t);if(e)for(const s of e){const o=p.get(s);o&&C(o)}}}function O(i){i.listeners.forEach(n=>n({prevVal:i.prevState,currentVal:i.state}))}function F(i){i.listeners.forEach(n=>n({prevVal:i.prevState,currentVal:i.state}))}function R(i){if(v.add(i),!b)try{for(b=!0;v.size>0;){const n=Array.from(v);v.clear();for(const t of n){const e=k.get(t)??t.prevState;t.prevState=e,O(t)}for(const t of n){const e=p.get(t);e&&(g.current.push(t),C(e))}for(const t of n){const e=p.get(t);if(e)for(const s of e)F(s)}}}finally{b=!1,g.current=[],k.clear()}}function G(i){return typeof i=="function"}class m{constructor(n,t){this.listeners=new Set,this.subscribe=e=>{var s,o;this.listeners.add(e);const h=(o=(s=this.options)==null?void 0:s.onSubscribe)==null?void 0:o.call(s,e,this);return()=>{this.listeners.delete(e),h==null||h()}},this.prevState=n,this.state=n,this.options=t}setState(n){var t,e,s;this.prevState=this.state,(t=this.options)!=null&&t.updateFn?this.state=this.options.updateFn(this.prevState)(n):G(n)?this.state=n(this.prevState):this.state=n,(s=(e=this.options)==null?void 0:e.onUpdate)==null||s.call(e),R(this)}}class f{constructor(n){this.listeners=new Set,this._subscriptions=[],this.lastSeenDepValues=[],this.getDepVals=()=>{const t=[],e=[];for(const s of this.options.deps)t.push(s.prevState),e.push(s.state);return this.lastSeenDepValues=e,{prevDepVals:t,currDepVals:e,prevVal:this.prevState??void 0}},this.recompute=()=>{var t,e;this.prevState=this.state;const{prevDepVals:s,currDepVals:o,prevVal:h}=this.getDepVals();this.state=this.options.fn({prevDepVals:s,currDepVals:o,prevVal:h}),(e=(t=this.options).onUpdate)==null||e.call(t)},this.checkIfRecalculationNeededDeeply=()=>{for(const o of this.options.deps)o instanceof f&&o.checkIfRecalculationNeededDeeply();let t=!1;const e=this.lastSeenDepValues,{currDepVals:s}=this.getDepVals();for(let o=0;o<s.length;o++)if(s[o]!==e[o]){t=!0;break}t&&this.recompute()},this.mount=()=>(this.registerOnGraph(),this.checkIfRecalculationNeededDeeply(),()=>{this.unregisterFromGraph();for(const t of this._subscriptions)t()}),this.subscribe=t=>{var e,s;this.listeners.add(t);const o=(s=(e=this.options).onSubscribe)==null?void 0:s.call(e,t,this);return()=>{this.listeners.delete(t),o==null||o()}},this.options=n,this.state=n.fn({prevDepVals:void 0,prevVal:void 0,currDepVals:this.getDepVals().currDepVals})}registerOnGraph(n=this.options.deps){for(const t of n)if(t instanceof f)t.registerOnGraph(),this.registerOnGraph(t.options.deps);else if(t instanceof m){let e=p.get(t);e||(e=new Set,p.set(t,e)),e.add(this);let s=S.get(this);s||(s=new Set,S.set(this,s)),s.add(t)}}unregisterFromGraph(n=this.options.deps){for(const t of n)if(t instanceof f)this.unregisterFromGraph(t.options.deps);else if(t instanceof m){const e=p.get(t);e&&e.delete(this);const s=S.get(this);s&&s.delete(t)}}}class I{constructor(n){const{eager:t,fn:e,...s}=n;this._derived=new f({...s,fn:()=>{},onUpdate(){e()}}),t&&e()}mount(){return this._derived.mount()}}function L(i,n={}){const t=new m({actors:{}}),e=n.hashFunction||N,s=new Map;function o(h){const r=e(h),_=s.get(r);if(_)return{..._,state:_.state};const d=new f({fn:({currDepVals:[a]})=>a.actors[r],deps:[t]});function V(){async function a(){const c=t.state.actors[r];try{const u=i.getOrCreate(c.opts.name,c.opts.key,{params:c.opts.params,createInRegion:c.opts.createInRegion,createWithInput:c.opts.createWithInput}),l=u.connect();await u.resolve(),t.setState(D=>({...D,actors:{...D.actors,[r]:{...D.actors[r],isConnected:!0,isConnecting:!1,handle:u,connection:l,isError:!1,error:null}}}))}catch(u){t.setState(l=>({...l,actors:{...l.actors,[r]:{...l.actors[r],isError:!0,isConnecting:!1,error:u}}}))}}t.setState(c=>(c.actors[r].isConnecting=!0,c.actors[r].isError=!1,c.actors[r].error=null,a(),c))}const E=new I({fn:()=>{const a=t.state.actors[r];JSON.stringify(t.prevState.actors[r].opts)===JSON.stringify(t.state.actors[r].opts)&&!a.isConnected&&!a.isConnecting&&!a.isError&&a.opts.enabled&&V()},deps:[d]});t.setState(a=>a.actors[r]?a:{...a,actors:{...a.actors,[r]:{hash:r,isConnected:!1,isConnecting:!1,connection:null,handle:null,isError:!1,error:null,opts:h}}});function y(a){t.setState(c=>{const u=c.actors[r];if(!u)throw new Error(`Actor with key "${r}" does not exist.`);let l;return typeof a=="function"?l=a(u):l=a,{...c,actors:{...c.actors,[r]:l}}})}const w=()=>{const a=d.mount(),c=E.mount();return()=>{a(),c()}};return s.set(r,{state:d,key:r,mount:w,setState:y,create:V,addEventListener}),{mount:w,setState:y,state:d,create:V,key:r}}return{getOrCreateActor:o,store:t}}function N({name:i,key:n,params:t}){return JSON.stringify({name:i,key:n,params:t})}exports.createRivetKit=L;
|
package/dist/mod.d.ts
CHANGED
|
@@ -52,6 +52,10 @@ interface ActorStateReference<AD extends AnyActorDefinition> {
|
|
|
52
52
|
* These are additional options that can be passed to the actor.
|
|
53
53
|
*/
|
|
54
54
|
params?: Record<string, string>;
|
|
55
|
+
/** Region to create the actor in if it doesn't exist. */
|
|
56
|
+
createInRegion?: string;
|
|
57
|
+
/** Input data to pass to the actor. */
|
|
58
|
+
createWithInput?: unknown;
|
|
55
59
|
/**
|
|
56
60
|
* Whether the actor is enabled.
|
|
57
61
|
* Defaults to true.
|
|
@@ -82,6 +86,10 @@ export interface ActorOptions<Registry extends AnyActorRegistry, ActorName exten
|
|
|
82
86
|
* Parameters for the actor.
|
|
83
87
|
*/
|
|
84
88
|
params?: Registry[ExtractActorsFromRegistry<Registry>]["params"];
|
|
89
|
+
/** Region to create the actor in if it doesn't exist. */
|
|
90
|
+
createInRegion?: string;
|
|
91
|
+
/** Input data to pass to the actor. */
|
|
92
|
+
createWithInput?: unknown;
|
|
85
93
|
/**
|
|
86
94
|
* Whether the actor is enabled.
|
|
87
95
|
* Defaults to true.
|
package/dist/mod.js
CHANGED
|
@@ -58,7 +58,7 @@ function G(i) {
|
|
|
58
58
|
b = !1, g.current = [], k.clear();
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
function
|
|
61
|
+
function I(i) {
|
|
62
62
|
return typeof i == "function";
|
|
63
63
|
}
|
|
64
64
|
class m {
|
|
@@ -74,7 +74,7 @@ class m {
|
|
|
74
74
|
}
|
|
75
75
|
setState(n) {
|
|
76
76
|
var t, e, s;
|
|
77
|
-
this.prevState = this.state, (t = this.options) != null && t.updateFn ? this.state = this.options.updateFn(this.prevState)(n) :
|
|
77
|
+
this.prevState = this.state, (t = this.options) != null && t.updateFn ? this.state = this.options.updateFn(this.prevState)(n) : I(n) ? this.state = n(this.prevState) : this.state = n, (s = (e = this.options) == null ? void 0 : e.onUpdate) == null || s.call(e), G(this);
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
class f {
|
|
@@ -148,7 +148,7 @@ class f {
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
class
|
|
151
|
+
class R {
|
|
152
152
|
constructor(n) {
|
|
153
153
|
const { eager: t, fn: e, ...s } = n;
|
|
154
154
|
this._derived = new f({
|
|
@@ -164,10 +164,10 @@ class N {
|
|
|
164
164
|
return this._derived.mount();
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
-
function
|
|
167
|
+
function N(i, n = {}) {
|
|
168
168
|
const t = new m({
|
|
169
169
|
actors: {}
|
|
170
|
-
}), e = n.hashFunction ||
|
|
170
|
+
}), e = n.hashFunction || L, s = /* @__PURE__ */ new Map();
|
|
171
171
|
function o(h) {
|
|
172
172
|
const r = e(h), _ = s.get(r);
|
|
173
173
|
if (_)
|
|
@@ -186,7 +186,11 @@ function R(i, n = {}) {
|
|
|
186
186
|
const u = i.getOrCreate(
|
|
187
187
|
c.opts.name,
|
|
188
188
|
c.opts.key,
|
|
189
|
-
|
|
189
|
+
{
|
|
190
|
+
params: c.opts.params,
|
|
191
|
+
createInRegion: c.opts.createInRegion,
|
|
192
|
+
createWithInput: c.opts.createWithInput
|
|
193
|
+
}
|
|
190
194
|
), l = u.connect();
|
|
191
195
|
await u.resolve(
|
|
192
196
|
/*{ signal: AbortSignal.timeout(0) }*/
|
|
@@ -222,7 +226,7 @@ function R(i, n = {}) {
|
|
|
222
226
|
}
|
|
223
227
|
t.setState((c) => (c.actors[r].isConnecting = !0, c.actors[r].isError = !1, c.actors[r].error = null, a(), c));
|
|
224
228
|
}
|
|
225
|
-
const E = new
|
|
229
|
+
const E = new R({
|
|
226
230
|
fn: () => {
|
|
227
231
|
const a = t.state.actors[r];
|
|
228
232
|
JSON.stringify(t.prevState.actors[r].opts) === JSON.stringify(t.state.actors[r].opts) && !a.isConnected && !a.isConnecting && !a.isError && a.opts.enabled && V();
|
|
@@ -286,9 +290,9 @@ function R(i, n = {}) {
|
|
|
286
290
|
store: t
|
|
287
291
|
};
|
|
288
292
|
}
|
|
289
|
-
function
|
|
293
|
+
function L({ name: i, key: n, params: t }) {
|
|
290
294
|
return JSON.stringify({ name: i, key: n, params: t });
|
|
291
295
|
}
|
|
292
296
|
export {
|
|
293
|
-
|
|
297
|
+
N as createRivetKit
|
|
294
298
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rivetkit/framework-base",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.7",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rivetkit",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"stableVersion": "0.8.0",
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@tanstack/store": "^0.7.1",
|
|
39
|
-
"@rivetkit/core": "0.9.
|
|
39
|
+
"@rivetkit/core": "0.9.7"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"dev": "vite build --watch",
|