Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stayte

Package Overview
Dependencies
Maintainers
0
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stayte - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

dist/class/MemoryGluon.d.ts

1

dist/class/CookieGluon.d.ts
import { Gluon } from "./Gluon";
import { CookieSerializeOptions } from 'cookie-es';
export declare class CookieGluon<T> extends Gluon<T> {
clear(): void;
setup(options: CookieSerializeOptions): void;
set(value: T): void;
}

11

dist/class/Gluon.d.ts

@@ -9,6 +9,6 @@ import { z, ZodError, ZodType } from "zod";

export declare abstract class GluonSubscription<T> {
protected subscribers: Set<(value: T) => void>;
subscribe(callback: (value: T) => void): () => void;
protected subscribers: Set<(value: T | null) => void>;
subscribe(callback: (value: T | null) => void): () => void;
unsubscribe(): void;
protected emit(value: T): void;
protected emit(value: T | null): void;
}

@@ -19,3 +19,3 @@ export declare abstract class Gluon<T> extends GluonSubscription<T> {

static SECURE_HYDRATION: boolean;
value: T | null;
protected value: T | null;
error: ZodError | null;

@@ -28,4 +28,5 @@ private requestId;

protected parse(value: any): any;
protected update(value: T, callback: () => void): void;
protected update(value: T | null, callback?: () => void): void;
get(): T;
reset(): void;
isSSR(): boolean;

@@ -32,0 +33,0 @@ abstract setup(...args: any[]): void;

import { Gluon } from "./Gluon";
export declare class LocalGluon<T> extends Gluon<T> {
static SECURE_HYDRATION: boolean;
clear(): void;
setup(): void;
set(value: T): void;
}

@@ -7,2 +7,3 @@ import { Gluon } from "./Gluon";

static PUSH_STATE_DELAY: number;
clear(): void;
setup(options: QueryGluonOptions): void;

@@ -9,0 +10,0 @@ set(value: T): void;

import { Gluon } from "./Gluon";
export declare class SessionGluon<T> extends Gluon<T> {
static SECURE_HYDRATION: boolean;
clear(): void;
setup(): void;
set(value: T): void;
}

@@ -7,2 +7,3 @@ import { z, ZodType } from "zod";

import { SessionGluon } from "./class/SessionGluon";
import { MemoryGluon } from "./class/MemoryGluon";
export type GluonMap<T> = {

@@ -13,2 +14,3 @@ "query": QueryGluon<T>;

"session": SessionGluon<T>;
"memory": MemoryGluon<T>;
};

@@ -15,0 +17,0 @@ export declare const gluon: <U extends keyof GluonMap<any>, Schema, T = false>(name: string, options: GluonOptions<T, Schema> & {

@@ -12,5 +12,7 @@ import { Gluon, GluonOptions } from '../class/Gluon';

error?: ZodError;
gluon: Name extends Gluon<any> | ReadGluon<any> ? Name : GluonMap<Schema extends ZodType ? z.infer<Schema> : T>[U];
} : {
value: Name extends Gluon<any> | ReadGluon<any> ? NonNullable<Name["value"]> : never;
value: Name extends Gluon<any> | ReadGluon<any> ? NonNullable<ReturnType<Name["get"]>> : never;
error?: ZodError;
gluon: Name extends Gluon<any> | ReadGluon<any> ? Name : GluonMap<Name extends Gluon<any> | ReadGluon<any> ? NonNullable<ReturnType<Name["get"]>> : never>[U];
});

@@ -1,1 +0,1 @@

import{z as V}from"zod";import{useRef as w,useSyncExternalStore as W}from"react";const j=r=>r.isSSR()?r.constructor.SECURE_HYDRATION:!1,z=r=>{try{return JSON.parse(r)}catch(e){return console.error(e),r}},d=()=>typeof window>"u";var J=Object.getOwnPropertyNames,Y=Object.getOwnPropertySymbols,F=Object.prototype.hasOwnProperty;function A(r,e){return function(t,n,u){return r(t,n,u)&&e(t,n,u)}}function E(r){return function(i,t,n){if(!i||!t||typeof i!="object"||typeof t!="object")return r(i,t,n);var u=n.cache,a=u.get(i),s=u.get(t);if(a&&s)return a===t&&s===i;u.set(i,t),u.set(t,i);var l=r(i,t,n);return u.delete(i),u.delete(t),l}}function P(r){return J(r).concat(Y(r))}var R=Object.hasOwn||function(r,e){return F.call(r,e)};function g(r,e){return r||e?r===e:r===e||r!==r&&e!==e}var T="_owner",x=Object.getOwnPropertyDescriptor,C=Object.keys;function Z(r,e,i){var t=r.length;if(e.length!==t)return!1;for(;t-- >0;)if(!i.equals(r[t],e[t],t,t,r,e,i))return!1;return!0}function X(r,e){return g(r.getTime(),e.getTime())}function I(r,e,i){if(r.size!==e.size)return!1;for(var t={},n=r.entries(),u=0,a,s;(a=n.next())&&!a.done;){for(var l=e.entries(),f=!1,o=0;(s=l.next())&&!s.done;){var c=a.value,p=c[0],m=c[1],h=s.value,O=h[0],L=h[1];!f&&!t[o]&&(f=i.equals(p,O,u,o,r,e,i)&&i.equals(m,L,p,O,r,e,i))&&(t[o]=!0),o++}if(!f)return!1;u++}return!0}function K(r,e,i){var t=C(r),n=t.length;if(C(e).length!==n)return!1;for(var u;n-- >0;)if(u=t[n],u===T&&(r.$$typeof||e.$$typeof)&&r.$$typeof!==e.$$typeof||!R(e,u)||!i.equals(r[u],e[u],u,u,r,e,i))return!1;return!0}function b(r,e,i){var t=P(r),n=t.length;if(P(e).length!==n)return!1;for(var u,a,s;n-- >0;)if(u=t[n],u===T&&(r.$$typeof||e.$$typeof)&&r.$$typeof!==e.$$typeof||!R(e,u)||!i.equals(r[u],e[u],u,u,r,e,i)||(a=x(r,u),s=x(e,u),(a||s)&&(!a||!s||a.configurable!==s.configurable||a.enumerable!==s.enumerable||a.writable!==s.writable)))return!1;return!0}function Q(r,e){return g(r.valueOf(),e.valueOf())}function ee(r,e){return r.source===e.source&&r.flags===e.flags}function k(r,e,i){if(r.size!==e.size)return!1;for(var t={},n=r.values(),u,a;(u=n.next())&&!u.done;){for(var s=e.values(),l=!1,f=0;(a=s.next())&&!a.done;)!l&&!t[f]&&(l=i.equals(u.value,a.value,u.value,a.value,r,e,i))&&(t[f]=!0),f++;if(!l)return!1}return!0}function re(r,e){var i=r.length;if(e.length!==i)return!1;for(;i-- >0;)if(r[i]!==e[i])return!1;return!0}var te="[object Arguments]",ie="[object Boolean]",ne="[object Date]",ue="[object Map]",ae="[object Number]",se="[object Object]",oe="[object RegExp]",ce="[object Set]",le="[object String]",fe=Array.isArray,N=typeof ArrayBuffer=="function"&&ArrayBuffer.isView?ArrayBuffer.isView:null,G=Object.assign,pe=Object.prototype.toString.call.bind(Object.prototype.toString);function he(r){var e=r.areArraysEqual,i=r.areDatesEqual,t=r.areMapsEqual,n=r.areObjectsEqual,u=r.arePrimitiveWrappersEqual,a=r.areRegExpsEqual,s=r.areSetsEqual,l=r.areTypedArraysEqual;return function(o,c,p){if(o===c)return!0;if(o==null||c==null||typeof o!="object"||typeof c!="object")return o!==o&&c!==c;var m=o.constructor;if(m!==c.constructor)return!1;if(m===Object)return n(o,c,p);if(fe(o))return e(o,c,p);if(N!=null&&N(o))return l(o,c,p);if(m===Date)return i(o,c,p);if(m===RegExp)return a(o,c,p);if(m===Map)return t(o,c,p);if(m===Set)return s(o,c,p);var h=pe(o);return h===ne?i(o,c,p):h===oe?a(o,c,p):h===ue?t(o,c,p):h===ce?s(o,c,p):h===se?typeof o.then!="function"&&typeof c.then!="function"&&n(o,c,p):h===te?n(o,c,p):h===ie||h===ae||h===le?u(o,c,p):!1}}function de(r){var e=r.circular,i=r.createCustomConfig,t=r.strict,n={areArraysEqual:t?b:Z,areDatesEqual:X,areMapsEqual:t?A(I,b):I,areObjectsEqual:t?b:K,arePrimitiveWrappersEqual:Q,areRegExpsEqual:ee,areSetsEqual:t?A(k,b):k,areTypedArraysEqual:t?b:re};if(i&&(n=G({},n,i(n))),e){var u=E(n.areArraysEqual),a=E(n.areMapsEqual),s=E(n.areObjectsEqual),l=E(n.areSetsEqual);n=G({},n,{areArraysEqual:u,areMapsEqual:a,areObjectsEqual:s,areSetsEqual:l})}return n}function me(r){return function(e,i,t,n,u,a,s){return r(e,i,s)}}function ye(r){var e=r.circular,i=r.comparator,t=r.createState,n=r.equals,u=r.strict;if(t)return function(l,f){var o=t(),c=o.cache,p=c===void 0?e?new WeakMap:void 0:c,m=o.meta;return i(l,f,{cache:p,equals:n,meta:m,strict:u})};if(e)return function(l,f){return i(l,f,{cache:new WeakMap,equals:n,meta:void 0,strict:u})};var a={cache:void 0,equals:n,meta:void 0,strict:u};return function(l,f){return i(l,f,a)}}var D=y();y({strict:!0}),y({circular:!0}),y({circular:!0,strict:!0}),y({createInternalComparator:function(){return g}}),y({strict:!0,createInternalComparator:function(){return g}}),y({circular:!0,createInternalComparator:function(){return g}}),y({circular:!0,createInternalComparator:function(){return g},strict:!0});function y(r){r===void 0&&(r={});var e=r.circular,i=e===void 0?!1:e,t=r.createInternalComparator,n=r.createState,u=r.strict,a=u===void 0?!1:u,s=de(r),l=he(s),f=t?t(l):me(l);return ye({circular:i,comparator:l,createState:n,equals:f,strict:a})}class ${constructor(){Object.defineProperty(this,"subscribers",{enumerable:!0,configurable:!0,writable:!0,value:new Set})}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}unsubscribe(){this.subscribers.clear()}emit(e){this.subscribers.forEach(i=>i(e))}}class v extends ${constructor(e,i){super(),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(this,"value",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"error",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"requestId",{enumerable:!0,configurable:!0,writable:!0,value:null}),d()&&(this.requestId=this.getRequestId()),this.computeSchema(),this.setup(this.options.options)}computeSchema(){this.options.schema||typeof this.options.defaultValue=="number"&&(this.options.schema=V.number())}configure(e){e?.(),!this.value&&!this.error&&typeof this.options.defaultValue<"u"&&this.set(this.options.defaultValue)}getRequestId(){const e=globalThis?.request?.id??null;if(!e)throw new Error("Cannot retrieve the request id, please make sure that framework is correctly patched or you are not using static rendering");return e}parse(e){if(this.options.schema){let i=e;const t=this.options.schema._def.typeName;typeof e=="string"&&(t==="ZodObject"&&(i=z(e)),t==="ZodBoolean"&&(i=e==="true"||e==="1"),t==="ZodNumber"&&(i=Number(e)));const n=this.options.schema.safeParse(i);return n.success?(this.error=null,n.data):(this.error=n.error,null)}return e}update(e,i){const t=this.value;let n=this.error,u=this.error!==null;this.options.schema?this.value=this.parse(e):this.value=e,(!this.error||!D(n?.errors,this.error?.errors))&&(u=!1),!(!this.error&&D(t,this.value)||u)&&(this.emit(e),i())}get(){if(d()){const e=this.getRequestId();this.requestId!==e&&(this.setup(this.options.options),this.requestId=e)}return this.value}isSSR(){return this.options.ssr??!0}}Object.defineProperty(v,"SECURE_HYDRATION",{enumerable:!0,configurable:!0,writable:!0,value:!1});class S extends v{setup(e){this.configure(()=>{const i=new URL(`http://example.com${d()?globalThis?.request?.url??"":window.location.search}`);let n=new URLSearchParams(i.search).get(this.name);this.value&&!n&&(n=this.options.defaultValue),n&&(this.value=this.parse(n))})}set(e){this.update(e,()=>{if(d())return;const i=new URLSearchParams(window.location.search);let t=!1;if(i.get(this.name)||(t=!0),i.set(this.name,typeof e=="object"?JSON.stringify(e):e),t){setTimeout(()=>this.replaceState(i),S.PUSH_STATE_DELAY);return}this.replaceState(i)})}replaceState(e){window.history.replaceState({...window.history.state},"",`?${e.toString()}`)}}Object.defineProperty(S,"PUSH_STATE_DELAY",{enumerable:!0,configurable:!0,writable:!0,value:10});class U extends v{setup(){d()||this.configure(()=>{const e=localStorage.getItem(this.name);e&&(this.value=this.parse(e))})}set(e){d()||this.update(e,()=>{localStorage.setItem(this.name,typeof e=="object"?JSON.stringify(e):e)})}}Object.defineProperty(U,"SECURE_HYDRATION",{enumerable:!0,configurable:!0,writable:!0,value:!0});function ve(r,e){if(typeof r!="string")throw new TypeError("argument str must be a string");const i={},t={},n=t.decode||ge;let u=0;for(;u<r.length;){const a=r.indexOf("=",u);if(a===-1)break;let s=r.indexOf(";",u);if(s===-1)s=r.length;else if(s<a){u=r.lastIndexOf(";",a-1)+1;continue}const l=r.slice(u,a).trim();if(t?.filter&&!t?.filter(l)){u=s+1;continue}if(i[l]===void 0){let f=r.slice(a+1,s).trim();f.codePointAt(0)===34&&(f=f.slice(1,-1)),i[l]=be(f,n)}u=s+1}return i}function ge(r){return r.includes("%")?decodeURIComponent(r):r}function be(r,e){try{return e(r)}catch{return r}}const q=/^[\u0009\u0020-\u007E\u0080-\u00FF]+$/;function we(r,e,i){const t=i||{},n=t.encode||encodeURIComponent;if(typeof n!="function")throw new TypeError("option encode is invalid");if(!q.test(r))throw new TypeError("argument name is invalid");const u=n(e);if(u&&!q.test(u))throw new TypeError("argument val is invalid");let a=r+"="+u;if(t.maxAge!==void 0&&t.maxAge!==null){const s=t.maxAge-0;if(Number.isNaN(s)||!Number.isFinite(s))throw new TypeError("option maxAge is invalid");a+="; Max-Age="+Math.floor(s)}if(t.domain){if(!q.test(t.domain))throw new TypeError("option domain is invalid");a+="; Domain="+t.domain}if(t.path){if(!q.test(t.path))throw new TypeError("option path is invalid");a+="; Path="+t.path}if(t.expires){if(!Ee(t.expires)||Number.isNaN(t.expires.valueOf()))throw new TypeError("option expires is invalid");a+="; Expires="+t.expires.toUTCString()}if(t.httpOnly&&(a+="; HttpOnly"),t.secure&&(a+="; Secure"),t.priority)switch(typeof t.priority=="string"?t.priority.toLowerCase():t.priority){case"low":{a+="; Priority=Low";break}case"medium":{a+="; Priority=Medium";break}case"high":{a+="; Priority=High";break}default:throw new TypeError("option priority is invalid")}if(t.sameSite)switch(typeof t.sameSite=="string"?t.sameSite.toLowerCase():t.sameSite){case!0:{a+="; SameSite=Strict";break}case"lax":{a+="; SameSite=Lax";break}case"strict":{a+="; SameSite=Strict";break}case"none":{a+="; SameSite=None";break}default:throw new TypeError("option sameSite is invalid")}return t.partitioned&&(a+="; Partitioned"),a}function Ee(r){return Object.prototype.toString.call(r)==="[object Date]"||r instanceof Date}class qe extends v{setup(e){this.cookiesOptions=e,this.configure(()=>{const i=d()?globalThis?.__incrementalCache?.requestHeaders?.cookie??"":window.document.cookie;let n=ve(i)[this.name];this.value&&!n&&(n=this.options.defaultValue),n&&(this.value=this.parse(n))})}set(e){this.update(e,()=>{if(d())return;const i=we(this.name,typeof e=="object"?JSON.stringify(e):e,this.cookiesOptions??{});window.document.cookie=i})}}class H extends v{setup(){d()||this.configure(()=>{const e=sessionStorage.getItem(this.name);e&&(this.value=this.parse(e))})}set(e){d()||this.update(e,()=>{sessionStorage.setItem(this.name,typeof e=="object"?JSON.stringify(e):e)})}}Object.defineProperty(H,"SECURE_HYDRATION",{enumerable:!0,configurable:!0,writable:!0,value:!0});const _=(r,e)=>{if(e.from==="query")return new S(r,e);if(e.from==="local")return new U(r,e);if(e.from==="cookie")return new qe(r,e);if(e.from==="session")return new H(r,e);throw new Error("Cannot create a Gluon from this source")};class M extends ${constructor(e,i){super(),Object.defineProperty(this,"getter",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"deps",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(this,"value",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"requestId",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"unsubscribes",{enumerable:!0,configurable:!0,writable:!0,value:[]}),d()&&(this.requestId=this.getRequestId()),this.value=this.getter(),this.deps.forEach(t=>t.subscribe(()=>{this.value=this.getter(),this.emit(this.value)}))}getRequestId(){const e=globalThis?.request?.id??null;if(!e)throw new Error("Cannot retrieve the request id, please make sure that framework is correctly patched or you are not using static rendering");return e}get(){if(d()){const e=this.getRequestId();this.requestId!==e&&(this.requestId=e,this.value=this.getter())}return this.value}asSecureHydrationDeps(){return this.deps.some(e=>j(e))}}const Se=(r,e)=>new M(r,e);function B(r){return r instanceof v?j(r):r.asSecureHydrationDeps()}const Oe=(r,e)=>{const i=w(),t=w(!1),n=w(0);i.current||(i.current=typeof r=="string"?_(r,e):r);const u=w(new Proxy({value:i.current.get(),error:null},{get:(...a)=>a[1]==="value"?B(i.current)&&!t.current?null:i.current?.get():a[1]==="error"&&i.current instanceof v?i.current.error:Reflect.get(...a),set:(...a)=>i.current instanceof M?(console.error("Cannot set a ReadGluon"),!1):(a[1]==="value"&&i.current.set(a[2]),Reflect.set(...a))}));return W(a=>(t.current||(t.current=!0,B(i.current)&&n.current===0&&(n.current++,a())),i.current.subscribe(()=>{n.current++,a()})),()=>n.current,()=>n.current),u.current};export{Se as computed,_ as gluon,Oe as useGluon};
import{z as L}from"zod";import{useRef as b,useSyncExternalStore as J}from"react";const j=r=>r.isSSR()?r.constructor.SECURE_HYDRATION:!1,W=r=>{try{return JSON.parse(r)}catch(e){return console.error(e),r}},h=()=>typeof window>"u";var z=Object.getOwnPropertyNames,Y=Object.getOwnPropertySymbols,F=Object.prototype.hasOwnProperty;function A(r,e){return function(t,n,u){return r(t,n,u)&&e(t,n,u)}}function E(r){return function(i,t,n){if(!i||!t||typeof i!="object"||typeof t!="object")return r(i,t,n);var u=n.cache,a=u.get(i),s=u.get(t);if(a&&s)return a===t&&s===i;u.set(i,t),u.set(t,i);var c=r(i,t,n);return u.delete(i),u.delete(t),c}}function P(r){return z(r).concat(Y(r))}var T=Object.hasOwn||function(r,e){return F.call(r,e)};function g(r,e){return r||e?r===e:r===e||r!==r&&e!==e}var R="_owner",x=Object.getOwnPropertyDescriptor,I=Object.keys;function Z(r,e,i){var t=r.length;if(e.length!==t)return!1;for(;t-- >0;)if(!i.equals(r[t],e[t],t,t,r,e,i))return!1;return!0}function X(r,e){return g(r.getTime(),e.getTime())}function C(r,e,i){if(r.size!==e.size)return!1;for(var t={},n=r.entries(),u=0,a,s;(a=n.next())&&!a.done;){for(var c=e.entries(),f=!1,o=0;(s=c.next())&&!s.done;){var l=a.value,p=l[0],m=l[1],d=s.value,O=d[0],B=d[1];!f&&!t[o]&&(f=i.equals(p,O,u,o,r,e,i)&&i.equals(m,B,p,O,r,e,i))&&(t[o]=!0),o++}if(!f)return!1;u++}return!0}function K(r,e,i){var t=I(r),n=t.length;if(I(e).length!==n)return!1;for(var u;n-- >0;)if(u=t[n],u===R&&(r.$$typeof||e.$$typeof)&&r.$$typeof!==e.$$typeof||!T(e,u)||!i.equals(r[u],e[u],u,u,r,e,i))return!1;return!0}function w(r,e,i){var t=P(r),n=t.length;if(P(e).length!==n)return!1;for(var u,a,s;n-- >0;)if(u=t[n],u===R&&(r.$$typeof||e.$$typeof)&&r.$$typeof!==e.$$typeof||!T(e,u)||!i.equals(r[u],e[u],u,u,r,e,i)||(a=x(r,u),s=x(e,u),(a||s)&&(!a||!s||a.configurable!==s.configurable||a.enumerable!==s.enumerable||a.writable!==s.writable)))return!1;return!0}function Q(r,e){return g(r.valueOf(),e.valueOf())}function ee(r,e){return r.source===e.source&&r.flags===e.flags}function k(r,e,i){if(r.size!==e.size)return!1;for(var t={},n=r.values(),u,a;(u=n.next())&&!u.done;){for(var s=e.values(),c=!1,f=0;(a=s.next())&&!a.done;)!c&&!t[f]&&(c=i.equals(u.value,a.value,u.value,a.value,r,e,i))&&(t[f]=!0),f++;if(!c)return!1}return!0}function re(r,e){var i=r.length;if(e.length!==i)return!1;for(;i-- >0;)if(r[i]!==e[i])return!1;return!0}var te="[object Arguments]",ie="[object Boolean]",ne="[object Date]",ue="[object Map]",ae="[object Number]",se="[object Object]",oe="[object RegExp]",le="[object Set]",ce="[object String]",fe=Array.isArray,N=typeof ArrayBuffer=="function"&&ArrayBuffer.isView?ArrayBuffer.isView:null,G=Object.assign,pe=Object.prototype.toString.call.bind(Object.prototype.toString);function he(r){var e=r.areArraysEqual,i=r.areDatesEqual,t=r.areMapsEqual,n=r.areObjectsEqual,u=r.arePrimitiveWrappersEqual,a=r.areRegExpsEqual,s=r.areSetsEqual,c=r.areTypedArraysEqual;return function(o,l,p){if(o===l)return!0;if(o==null||l==null||typeof o!="object"||typeof l!="object")return o!==o&&l!==l;var m=o.constructor;if(m!==l.constructor)return!1;if(m===Object)return n(o,l,p);if(fe(o))return e(o,l,p);if(N!=null&&N(o))return c(o,l,p);if(m===Date)return i(o,l,p);if(m===RegExp)return a(o,l,p);if(m===Map)return t(o,l,p);if(m===Set)return s(o,l,p);var d=pe(o);return d===ne?i(o,l,p):d===oe?a(o,l,p):d===ue?t(o,l,p):d===le?s(o,l,p):d===se?typeof o.then!="function"&&typeof l.then!="function"&&n(o,l,p):d===te?n(o,l,p):d===ie||d===ae||d===ce?u(o,l,p):!1}}function de(r){var e=r.circular,i=r.createCustomConfig,t=r.strict,n={areArraysEqual:t?w:Z,areDatesEqual:X,areMapsEqual:t?A(C,w):C,areObjectsEqual:t?w:K,arePrimitiveWrappersEqual:Q,areRegExpsEqual:ee,areSetsEqual:t?A(k,w):k,areTypedArraysEqual:t?w:re};if(i&&(n=G({},n,i(n))),e){var u=E(n.areArraysEqual),a=E(n.areMapsEqual),s=E(n.areObjectsEqual),c=E(n.areSetsEqual);n=G({},n,{areArraysEqual:u,areMapsEqual:a,areObjectsEqual:s,areSetsEqual:c})}return n}function me(r){return function(e,i,t,n,u,a,s){return r(e,i,s)}}function ye(r){var e=r.circular,i=r.comparator,t=r.createState,n=r.equals,u=r.strict;if(t)return function(c,f){var o=t(),l=o.cache,p=l===void 0?e?new WeakMap:void 0:l,m=o.meta;return i(c,f,{cache:p,equals:n,meta:m,strict:u})};if(e)return function(c,f){return i(c,f,{cache:new WeakMap,equals:n,meta:void 0,strict:u})};var a={cache:void 0,equals:n,meta:void 0,strict:u};return function(c,f){return i(c,f,a)}}var D=y();y({strict:!0}),y({circular:!0}),y({circular:!0,strict:!0}),y({createInternalComparator:function(){return g}}),y({strict:!0,createInternalComparator:function(){return g}}),y({circular:!0,createInternalComparator:function(){return g}}),y({circular:!0,createInternalComparator:function(){return g},strict:!0});function y(r){r===void 0&&(r={});var e=r.circular,i=e===void 0?!1:e,t=r.createInternalComparator,n=r.createState,u=r.strict,a=u===void 0?!1:u,s=de(r),c=he(s),f=t?t(c):me(c);return ye({circular:i,comparator:c,createState:n,equals:f,strict:a})}class ${constructor(){Object.defineProperty(this,"subscribers",{enumerable:!0,configurable:!0,writable:!0,value:new Set})}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}unsubscribe(){this.subscribers.clear()}emit(e){this.subscribers.forEach(i=>i(e))}}class v extends ${constructor(e,i){super(),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(this,"value",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"error",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"requestId",{enumerable:!0,configurable:!0,writable:!0,value:null}),h()&&(this.requestId=this.getRequestId()),this.computeSchema(),this.setup(this.options.options)}computeSchema(){this.options.schema||typeof this.options.defaultValue=="number"&&(this.options.schema=L.number())}configure(e){e?.(),!this.value&&!this.error&&typeof this.options.defaultValue<"u"&&this.set(this.options.defaultValue)}getRequestId(){const e=globalThis?.request?.id??null;if(!e)throw new Error("Cannot retrieve the request id, please make sure that framework is correctly patched or you are not using static rendering");return e}parse(e){if(this.options.schema){let i=e;const t=this.options.schema._def.typeName;typeof e=="string"&&(t==="ZodObject"&&(i=W(e)),t==="ZodBoolean"&&(i=e==="true"||e==="1"),t==="ZodNumber"&&(i=Number(e)));const n=this.options.schema.safeParse(i);return n.success?(this.error=null,n.data):(this.error=n.error,null)}return e}update(e,i){const t=this.value;let n=this.error,u=this.error!==null;this.options.schema?this.value=this.parse(e):this.value=e,(!this.error||!D(n?.errors,this.error?.errors))&&(u=!1),!(!this.error&&D(t,this.value)||u)&&(this.emit(e),i?.())}get(){if(h()){const e=this.getRequestId();this.requestId!==e&&(this.setup(this.options.options),this.requestId=e)}return this.value}reset(){if(!this.options.defaultValue)throw new Error("Cannot reset a gluon without a default value");this.set(this.options.defaultValue)}isSSR(){return this.options.ssr??!0}}Object.defineProperty(v,"SECURE_HYDRATION",{enumerable:!0,configurable:!0,writable:!0,value:!1});class S extends v{clear(){if(h())return;this.value=null,this.emit(null);const e=new URLSearchParams(window.location.search);e.delete(this.name),window.history.replaceState({...window.history.state},"",`?${e.toString()}`)}setup(e){this.configure(()=>{const i=new URL(`http://example.com${h()?globalThis?.request?.url??"":window.location.search}`);let n=new URLSearchParams(i.search).get(this.name);this.value&&!n&&this.options?.defaultValue&&(n=this.options.defaultValue),n&&(this.value=this.parse(n))})}set(e){this.update(e,()=>{if(h())return;const i=new URLSearchParams(window.location.search);let t=!1;if(i.get(this.name)||(t=!0),i.set(this.name,typeof e=="object"?JSON.stringify(e):e),t){setTimeout(()=>this.replaceState(i),S.PUSH_STATE_DELAY);return}this.replaceState(i)})}replaceState(e){window.history.replaceState({...window.history.state},"",`?${e.toString()}`)}}Object.defineProperty(S,"PUSH_STATE_DELAY",{enumerable:!0,configurable:!0,writable:!0,value:10});class U extends v{clear(){this.value=null,this.emit(null),localStorage.removeItem(this.name)}setup(){h()||this.configure(()=>{const e=localStorage.getItem(this.name);e&&(this.value=this.parse(e))})}set(e){h()||this.update(e,()=>{localStorage.setItem(this.name,typeof e=="object"?JSON.stringify(e):e)})}}Object.defineProperty(U,"SECURE_HYDRATION",{enumerable:!0,configurable:!0,writable:!0,value:!0});function ve(r,e){if(typeof r!="string")throw new TypeError("argument str must be a string");const i={},t={},n=t.decode||ge;let u=0;for(;u<r.length;){const a=r.indexOf("=",u);if(a===-1)break;let s=r.indexOf(";",u);if(s===-1)s=r.length;else if(s<a){u=r.lastIndexOf(";",a-1)+1;continue}const c=r.slice(u,a).trim();if(t?.filter&&!t?.filter(c)){u=s+1;continue}if(i[c]===void 0){let f=r.slice(a+1,s).trim();f.codePointAt(0)===34&&(f=f.slice(1,-1)),i[c]=we(f,n)}u=s+1}return i}function ge(r){return r.includes("%")?decodeURIComponent(r):r}function we(r,e){try{return e(r)}catch{return r}}const q=/^[\u0009\u0020-\u007E\u0080-\u00FF]+$/;function be(r,e,i){const t=i||{},n=t.encode||encodeURIComponent;if(typeof n!="function")throw new TypeError("option encode is invalid");if(!q.test(r))throw new TypeError("argument name is invalid");const u=n(e);if(u&&!q.test(u))throw new TypeError("argument val is invalid");let a=r+"="+u;if(t.maxAge!==void 0&&t.maxAge!==null){const s=t.maxAge-0;if(Number.isNaN(s)||!Number.isFinite(s))throw new TypeError("option maxAge is invalid");a+="; Max-Age="+Math.floor(s)}if(t.domain){if(!q.test(t.domain))throw new TypeError("option domain is invalid");a+="; Domain="+t.domain}if(t.path){if(!q.test(t.path))throw new TypeError("option path is invalid");a+="; Path="+t.path}if(t.expires){if(!Ee(t.expires)||Number.isNaN(t.expires.valueOf()))throw new TypeError("option expires is invalid");a+="; Expires="+t.expires.toUTCString()}if(t.httpOnly&&(a+="; HttpOnly"),t.secure&&(a+="; Secure"),t.priority)switch(typeof t.priority=="string"?t.priority.toLowerCase():t.priority){case"low":{a+="; Priority=Low";break}case"medium":{a+="; Priority=Medium";break}case"high":{a+="; Priority=High";break}default:throw new TypeError("option priority is invalid")}if(t.sameSite)switch(typeof t.sameSite=="string"?t.sameSite.toLowerCase():t.sameSite){case!0:{a+="; SameSite=Strict";break}case"lax":{a+="; SameSite=Lax";break}case"strict":{a+="; SameSite=Strict";break}case"none":{a+="; SameSite=None";break}default:throw new TypeError("option sameSite is invalid")}return t.partitioned&&(a+="; Partitioned"),a}function Ee(r){return Object.prototype.toString.call(r)==="[object Date]"||r instanceof Date}class qe extends v{clear(){h()||(this.value=null,this.emit(null),window.document.cookie=`${this.name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT;`)}setup(e){this.cookiesOptions=e,this.configure(()=>{const i=h()?globalThis?.__incrementalCache?.requestHeaders?.cookie??"":window.document.cookie;let n=ve(i)[this.name];this.value&&!n&&this.options?.defaultValue&&(n=this.options.defaultValue),n&&(this.value=this.parse(n))})}set(e){this.update(e,()=>{if(h())return;const i=be(this.name,typeof e=="object"?JSON.stringify(e):e,this.cookiesOptions??{});window.document.cookie=i})}}class M extends v{clear(){this.value=null,this.emit(null),sessionStorage.removeItem(this.name)}setup(){h()||this.configure(()=>{const e=sessionStorage.getItem(this.name);e&&(this.value=this.parse(e))})}set(e){h()||this.update(e,()=>{sessionStorage.setItem(this.name,typeof e=="object"?JSON.stringify(e):e)})}}Object.defineProperty(M,"SECURE_HYDRATION",{enumerable:!0,configurable:!0,writable:!0,value:!0});class Se extends v{setup(){this.configure()}set(e){this.update(e)}}const V=(r,e)=>{if(e.from==="query")return new S(r,e);if(e.from==="local")return new U(r,e);if(e.from==="cookie")return new qe(r,e);if(e.from==="session")return new M(r,e);if(e.from==="memory")return new Se(r,e);throw new Error("Cannot create a Gluon from this source")};class H extends ${constructor(e,i){super(),Object.defineProperty(this,"getter",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"deps",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(this,"value",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"requestId",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"unsubscribes",{enumerable:!0,configurable:!0,writable:!0,value:[]}),h()&&(this.requestId=this.getRequestId()),this.value=this.getter(),this.deps.forEach(t=>t.subscribe(()=>{this.value=this.getter(),this.emit(this.value)}))}getRequestId(){const e=globalThis?.request?.id??null;if(!e)throw new Error("Cannot retrieve the request id, please make sure that framework is correctly patched or you are not using static rendering");return e}get(){if(h()){const e=this.getRequestId();this.requestId!==e&&(this.requestId=e,this.value=this.getter())}return this.value}asSecureHydrationDeps(){return this.deps.some(e=>j(e))}}const Oe=(r,e)=>new H(r,e);function _(r){return r instanceof v?j(r):r.asSecureHydrationDeps()}const je=(r,e)=>{const i=b(),t=b(!1),n=b(0);i.current||(i.current=typeof r=="string"||typeof r>"u"?V(r,e):r);const u=b(new Proxy({value:i.current.get(),error:null,gluon:i.current},{get:(...a)=>a[1]==="value"?_(i.current)&&!t.current?null:i.current?.get():a[1]==="error"&&i.current instanceof v?i.current.error:a[1]==="gluon"?i.current:Reflect.get(...a),set:(...a)=>i.current instanceof H?(console.error("Cannot set a ReadGluon"),!1):(a[1]==="value"&&i.current.set(a[2]),Reflect.set(...a))}));return J(a=>(t.current||(t.current=!0,_(i.current)&&n.current===0&&(n.current++,a())),i.current.subscribe(()=>{n.current++,a()})),()=>n.current,()=>n.current),u.current};export{Oe as computed,V as gluon,je as useGluon};
{
"name": "stayte",
"version": "0.0.7",
"version": "0.0.8",
"description": "The persistent state library for the modern web",

@@ -5,0 +5,0 @@ "exports": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc