@rilaykit/core 2.0.1 → 3.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/dist/index.d.mts +8 -10
- package/dist/index.d.ts +8 -10
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -5,18 +5,20 @@ import { z } from 'zod';
|
|
|
5
5
|
* Main configuration class for Rilay form components and workflows
|
|
6
6
|
* Manages component registration, retrieval, and configuration
|
|
7
7
|
*/
|
|
8
|
-
declare class ril {
|
|
8
|
+
declare class ril<C> {
|
|
9
9
|
private components;
|
|
10
10
|
private formRenderConfig;
|
|
11
11
|
private workflowRenderConfig;
|
|
12
|
-
static create(): ril
|
|
12
|
+
static create<CT>(): ril<CT>;
|
|
13
13
|
/**
|
|
14
14
|
* Add a component to the configuration
|
|
15
15
|
* @param type - The component type (e.g., 'text', 'email', 'heading'), used as a unique identifier.
|
|
16
16
|
* @param config - Component configuration without id and type
|
|
17
17
|
* @returns The ril instance for chaining
|
|
18
18
|
*/
|
|
19
|
-
addComponent<TProps = any>(type:
|
|
19
|
+
addComponent<NewType extends string, TProps = any>(type: NewType, config: Omit<ComponentConfig<TProps>, 'id' | 'type'>): ril<C & {
|
|
20
|
+
[K in NewType]: TProps;
|
|
21
|
+
}>;
|
|
20
22
|
/**
|
|
21
23
|
* Generic method to set any renderer type easily
|
|
22
24
|
* @param rendererType - The type of renderer to set
|
|
@@ -100,16 +102,12 @@ declare class ril {
|
|
|
100
102
|
* @returns Current workflow render configuration
|
|
101
103
|
*/
|
|
102
104
|
getWorkflowRenderConfig(): WorkflowRenderConfig;
|
|
103
|
-
/**
|
|
104
|
-
* @deprecated Use setFormRenderConfig() instead
|
|
105
|
-
*/
|
|
106
|
-
setRenderConfig(config: FormRenderConfig): this;
|
|
107
105
|
/**
|
|
108
106
|
* Get a component by its ID
|
|
109
107
|
* @param id - Component ID (which is its type)
|
|
110
108
|
* @returns Component configuration or undefined
|
|
111
109
|
*/
|
|
112
|
-
getComponent(id:
|
|
110
|
+
getComponent<T extends keyof C & string>(id: T): ComponentConfig<C[T]> | undefined;
|
|
113
111
|
/**
|
|
114
112
|
* List all registered components
|
|
115
113
|
* @returns Array of all components
|
|
@@ -418,10 +416,10 @@ interface FormRenderConfig {
|
|
|
418
416
|
readonly submitButtonRenderer?: FormSubmitButtonRenderer;
|
|
419
417
|
readonly fieldRenderer?: FieldRenderer;
|
|
420
418
|
}
|
|
421
|
-
interface FormConfiguration {
|
|
419
|
+
interface FormConfiguration<C extends Record<string, any> = Record<string, never>> {
|
|
422
420
|
readonly id: string;
|
|
423
421
|
readonly schema?: any;
|
|
424
|
-
readonly config: ril
|
|
422
|
+
readonly config: ril<C>;
|
|
425
423
|
readonly rows: FormFieldRow[];
|
|
426
424
|
readonly allFields: FormFieldConfig[];
|
|
427
425
|
readonly renderConfig?: FormRenderConfig;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,18 +5,20 @@ import { z } from 'zod';
|
|
|
5
5
|
* Main configuration class for Rilay form components and workflows
|
|
6
6
|
* Manages component registration, retrieval, and configuration
|
|
7
7
|
*/
|
|
8
|
-
declare class ril {
|
|
8
|
+
declare class ril<C> {
|
|
9
9
|
private components;
|
|
10
10
|
private formRenderConfig;
|
|
11
11
|
private workflowRenderConfig;
|
|
12
|
-
static create(): ril
|
|
12
|
+
static create<CT>(): ril<CT>;
|
|
13
13
|
/**
|
|
14
14
|
* Add a component to the configuration
|
|
15
15
|
* @param type - The component type (e.g., 'text', 'email', 'heading'), used as a unique identifier.
|
|
16
16
|
* @param config - Component configuration without id and type
|
|
17
17
|
* @returns The ril instance for chaining
|
|
18
18
|
*/
|
|
19
|
-
addComponent<TProps = any>(type:
|
|
19
|
+
addComponent<NewType extends string, TProps = any>(type: NewType, config: Omit<ComponentConfig<TProps>, 'id' | 'type'>): ril<C & {
|
|
20
|
+
[K in NewType]: TProps;
|
|
21
|
+
}>;
|
|
20
22
|
/**
|
|
21
23
|
* Generic method to set any renderer type easily
|
|
22
24
|
* @param rendererType - The type of renderer to set
|
|
@@ -100,16 +102,12 @@ declare class ril {
|
|
|
100
102
|
* @returns Current workflow render configuration
|
|
101
103
|
*/
|
|
102
104
|
getWorkflowRenderConfig(): WorkflowRenderConfig;
|
|
103
|
-
/**
|
|
104
|
-
* @deprecated Use setFormRenderConfig() instead
|
|
105
|
-
*/
|
|
106
|
-
setRenderConfig(config: FormRenderConfig): this;
|
|
107
105
|
/**
|
|
108
106
|
* Get a component by its ID
|
|
109
107
|
* @param id - Component ID (which is its type)
|
|
110
108
|
* @returns Component configuration or undefined
|
|
111
109
|
*/
|
|
112
|
-
getComponent(id:
|
|
110
|
+
getComponent<T extends keyof C & string>(id: T): ComponentConfig<C[T]> | undefined;
|
|
113
111
|
/**
|
|
114
112
|
* List all registered components
|
|
115
113
|
* @returns Array of all components
|
|
@@ -418,10 +416,10 @@ interface FormRenderConfig {
|
|
|
418
416
|
readonly submitButtonRenderer?: FormSubmitButtonRenderer;
|
|
419
417
|
readonly fieldRenderer?: FieldRenderer;
|
|
420
418
|
}
|
|
421
|
-
interface FormConfiguration {
|
|
419
|
+
interface FormConfiguration<C extends Record<string, any> = Record<string, never>> {
|
|
422
420
|
readonly id: string;
|
|
423
421
|
readonly schema?: any;
|
|
424
|
-
readonly config: ril
|
|
422
|
+
readonly config: ril<C>;
|
|
425
423
|
readonly rows: FormFieldRow[];
|
|
426
424
|
readonly allFields: FormFieldConfig[];
|
|
427
425
|
readonly renderConfig?: FormRenderConfig;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var zod=require('zod');function w(n,e){return typeof n=="function"?n(e):n}var u=class n{constructor(){this.components=new Map;this.formRenderConfig={};this.workflowRenderConfig={};}static create(){return new n}addComponent(e,r){let o={id:e,type:e,...r};return this.components.set(e,o),this}setRenderer(e,r){return e in this.formRenderConfig?this.formRenderConfig={...this.formRenderConfig,[e]:r}:e in this.workflowRenderConfig&&(this.workflowRenderConfig={...this.workflowRenderConfig,[e]:r}),this}setRenderers(e){let r={},o={};for(let[t,i]of Object.entries(e))["rowRenderer","bodyRenderer","submitButtonRenderer","fieldRenderer"].includes(t)?r[t]=i:o[t]=i;return this.formRenderConfig={...this.formRenderConfig,...r},this.workflowRenderConfig={...this.workflowRenderConfig,...o},this}setRowRenderer(e){return this.formRenderConfig={...this.formRenderConfig,rowRenderer:e},this}setBodyRenderer(e){return this.formRenderConfig={...this.formRenderConfig,bodyRenderer:e},this}setSubmitButtonRenderer(e){return this.formRenderConfig={...this.formRenderConfig,submitButtonRenderer:e},this}setFieldRenderer(e){return this.formRenderConfig={...this.formRenderConfig,fieldRenderer:e},this}setFormRenderConfig(e){return this.formRenderConfig=e,this}getFormRenderConfig(){return {...this.formRenderConfig}}setStepperRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,stepperRenderer:e},this}setWorkflowNextButtonRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,nextButtonRenderer:e},this}setWorkflowPreviousButtonRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,previousButtonRenderer:e},this}setWorkflowSkipButtonRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,skipButtonRenderer:e},this}setWorkflowRenderConfig(e){return this.workflowRenderConfig=e,this}getWorkflowRenderConfig(){return {...this.workflowRenderConfig}}setRenderConfig(e){return this.setFormRenderConfig(e)}getComponent(e){return this.components.get(e)}getAllComponents(){return Array.from(this.components.values())}hasComponent(e){return this.components.has(e)}removeComponent(e){return this.components.delete(e)}clear(){this.components.clear();}getStats(){let e=Array.from(this.components.values());return {total:e.length,byType:e.reduce((r,o)=>(r[o.type]=(r[o.type]||0)+1,r),{}),hasCustomRenderers:{row:!!this.formRenderConfig.rowRenderer,body:!!this.formRenderConfig.bodyRenderer,submitButton:!!this.formRenderConfig.submitButtonRenderer,field:!!this.formRenderConfig.fieldRenderer,stepper:!!this.workflowRenderConfig.stepperRenderer,workflowNextButton:!!this.workflowRenderConfig.nextButtonRenderer,workflowPreviousButton:!!this.workflowRenderConfig.previousButtonRenderer,workflowSkipButton:!!this.workflowRenderConfig.skipButtonRenderer}}}validate(){let e=[],r=Array.from(this.components.values()),o=r.map(a=>a.id),t=o.filter((a,s)=>o.indexOf(a)!==s);t.length>0&&e.push(`Duplicate component IDs found: ${t.join(", ")}`);let i=r.filter(a=>!a.renderer);return i.length>0&&e.push(`Components without renderer: ${i.map(a=>a.id).join(", ")}`),e}};var f=n=>async e=>{try{return await n.parseAsync(e),{isValid:!0,errors:[]}}catch(r){return r&&typeof r=="object"&&"errors"in r&&Array.isArray(r.errors)?{isValid:false,errors:r.errors.map(o=>({code:o.code,message:o.message,path:o.path?o.path.map(String):[]}))}:{isValid:false,errors:[{code:"unknown",message:r instanceof Error?r.message:"Unknown validation error"}]}}},R=n=>async(e,r,o)=>{try{let t=await n(e,r);return t===!0?{isValid:!0,errors:[]}:t===!1?{isValid:!1,errors:[{code:"validation_failed",message:"Validation failed"}]}:{isValid:!1,errors:[{code:"validation_failed",message:String(t)}]}}catch(t){return {isValid:false,errors:[{code:"validation_error",message:t instanceof Error?t.message:"Validation error"}]}}},P=(n,e="all")=>async(r,o,t)=>{let i=await Promise.all(n.map(d=>d(r,o,t)));if(e==="all"){let d=i.flatMap(l=>l.errors);return {isValid:i.every(l=>l.isValid),errors:d}}return i.some(d=>d.isValid)?{isValid:true,errors:[]}:{isValid:false,errors:i.flatMap(d=>d.errors)}},x=(n,e)=>async(r,o,t)=>n(r,o)?e(r,o,t):{isValid:true,errors:[]},v={required:(n="This field is required")=>R(e=>e==null||e===""?n:!0),email:(n="Invalid email format")=>f(zod.z.string().email(n)),minLength:(n,e)=>f(zod.z.string().min(n,e||`Minimum ${n} characters required`)),maxLength:(n,e)=>f(zod.z.string().max(n,e||`Maximum ${n} characters allowed`)),pattern:(n,e="Invalid format")=>f(zod.z.string().regex(n,e)),numberRange:(n,e,r)=>{let o=zod.z.number();return n!==void 0&&(o=o.min(n,r||`Value must be at least ${n}`)),e!==void 0&&(o=o.max(e,r||`Value must be at most ${e}`)),f(o)},url:(n="Invalid URL format")=>f(zod.z.string().url(n)),phoneNumber:(n="Invalid phone number format")=>f(zod.z.string().regex(/^\+?[\d\s\-\(\)]+$/,n)),asyncValidation:(n,e=300)=>{let r=new Map;return (o,t,i)=>new Promise(a=>{let s=`${t.fieldId}-${JSON.stringify(o)}`;r.has(s)&&clearTimeout(r.get(s));let d=setTimeout(async()=>{try{let l=await n(o,t);a(l===!0?{isValid:!0,errors:[]}:{isValid:!1,errors:[{code:"async_validation_failed",message:typeof l=="string"?l:"Async validation failed"}]});}catch(l){a({isValid:false,errors:[{code:"async_validation_error",message:l instanceof Error?l.message:"Async validation error"}]});}finally{r.delete(s);}},e);r.set(s,d);})}},b=(n,e=[])=>({isValid:n,errors:e}),S=(n,e,r)=>({code:n,message:e,path:r});var m=class{constructor(){this.name="localStorage";}async save(e,r){try{localStorage.setItem(e,JSON.stringify(r));}catch(o){throw new Error(`Failed to save to localStorage: ${o}`)}}async load(e){try{let r=localStorage.getItem(e);return r?JSON.parse(r):null}catch(r){throw new Error(`Failed to load from localStorage: ${r}`)}}async remove(e){try{localStorage.removeItem(e);}catch(r){throw new Error(`Failed to remove from localStorage: ${r}`)}}async exists(e){return localStorage.getItem(e)!==null}async list(e){let r=[];for(let o=0;o<localStorage.length;o++){let t=localStorage.key(o);t&&(!e||t.includes(e))&&r.push(t);}return r}},y=class{constructor(){this.name="sessionStorage";}async save(e,r){try{sessionStorage.setItem(e,JSON.stringify(r));}catch(o){throw new Error(`Failed to save to sessionStorage: ${o}`)}}async load(e){try{let r=sessionStorage.getItem(e);return r?JSON.parse(r):null}catch(r){throw new Error(`Failed to load from sessionStorage: ${r}`)}}async remove(e){try{sessionStorage.removeItem(e);}catch(r){throw new Error(`Failed to remove from sessionStorage: ${r}`)}}async exists(e){return sessionStorage.getItem(e)!==null}async list(e){let r=[];for(let o=0;o<sessionStorage.length;o++){let t=sessionStorage.key(o);t&&(!e||t.includes(e))&&r.push(t);}return r}},p=class{constructor(){this.name="memory";this.storage=new Map;}async save(e,r){this.storage.set(e,{...r});}async load(e){let r=this.storage.get(e);return r?{...r}:null}async remove(e){this.storage.delete(e);}async exists(e){return this.storage.has(e)}async list(e){let r=Array.from(this.storage.keys());return e?r.filter(o=>o.includes(e)):r}clear(){this.storage.clear();}},g=class{constructor(e,r=[]){this.primary=e;this.fallbacks=r;this.name="composite";}async save(e,r){let o=[this.primary,...this.fallbacks];for(let t of o)try{await t.save(e,r);return}catch(i){console.warn(`Failed to save with ${t.name}:`,i);}throw new Error("All persistence adapters failed to save")}async load(e){let r=[this.primary,...this.fallbacks];for(let o of r)try{let t=await o.load(e);if(t)return t}catch(t){console.warn(`Failed to load with ${o.name}:`,t);}return null}async remove(e){let r=[this.primary,...this.fallbacks],o=[];for(let t of r)try{await t.remove(e);}catch(i){o.push(i);}if(o.length===r.length)throw new Error(`All adapters failed to remove: ${o.map(t=>t.message).join(", ")}`)}async exists(e){let r=[this.primary,...this.fallbacks];for(let o of r)try{if(await o.exists(e))return !0}catch(t){console.warn(`Failed to check existence with ${o.name}:`,t);}return false}async list(e){try{return await this.primary.list?.(e)||[]}catch(r){console.warn("Failed to list with primary adapter:",r);for(let o of this.fallbacks)try{return await o.list?.(e)||[]}catch(t){console.warn(`Failed to list with fallback ${o.name}:`,t);}return []}}};var B={localStorage(n={}){return {adapter:new m,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...n}},sessionStorage(n={}){return {adapter:new y,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...n}},memory(n={}){return {adapter:new p,debounceMs:0,autoSave:true,saveOnStepChange:true,...n}},custom(n,e={}){return {adapter:n,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...e}}};function E(n,e,r={}){let o=e||new p;return {adapter:{name:`resilient-${n.name}`,async save(i,a){try{await n.save(i,a);}catch(s){console.warn("Primary persistence failed, using fallback:",s),await o.save(i,a);}},async load(i){try{let a=await n.load(i);if(a)return a}catch(a){console.warn("Primary persistence load failed, trying fallback:",a);}return await o.load(i)},async remove(i){let a=[];try{await n.remove(i);}catch(s){a.push(s);}try{await o.remove(i);}catch(s){a.push(s);}if(a.length===2)throw new Error(`Both adapters failed: ${a.map(s=>s.message).join(", ")}`)},async exists(i){try{if(await n.exists(i))return !0}catch(a){console.warn("Primary persistence exists check failed:",a);}try{return await o.exists(i)}catch(a){return console.warn("Fallback persistence exists check failed:",a),false}},async list(i){try{return await n.list?.(i)||[]}catch(a){console.warn("Primary persistence list failed:",a);try{return await o.list?.(i)||[]}catch(s){return console.warn("Fallback persistence list failed:",s),[]}}}},debounceMs:1e3,autoSave:true,saveOnStepChange:true,maxRetries:3,retryDelayMs:1e3,...r}}exports.CompositeAdapter=g;exports.LocalStorageAdapter=m;exports.MemoryAdapter=p;exports.SessionStorageAdapter=y;exports.combineValidators=P;exports.commonValidators=v;exports.createConditionalValidator=x;exports.createCustomValidator=R;exports.createResilientPersistence=E;exports.createValidationError=S;exports.createValidationResult=b;exports.createZodValidator=f;exports.persistence=B;exports.resolveRendererChildren=w;exports.ril=u;
|
|
1
|
+
'use strict';var zod=require('zod');function w(n,e){return typeof n=="function"?n(e):n}var g=class n{constructor(){this.components=new Map;this.formRenderConfig={};this.workflowRenderConfig={};}static create(){return new n}addComponent(e,r){let o={id:e,type:e,...r};return this.components.set(e,o),this}setRenderer(e,r){return e in this.formRenderConfig?this.formRenderConfig={...this.formRenderConfig,[e]:r}:e in this.workflowRenderConfig&&(this.workflowRenderConfig={...this.workflowRenderConfig,[e]:r}),this}setRenderers(e){let r={},o={};for(let[t,i]of Object.entries(e))["rowRenderer","bodyRenderer","submitButtonRenderer","fieldRenderer"].includes(t)?r[t]=i:o[t]=i;return this.formRenderConfig={...this.formRenderConfig,...r},this.workflowRenderConfig={...this.workflowRenderConfig,...o},this}setRowRenderer(e){return this.formRenderConfig={...this.formRenderConfig,rowRenderer:e},this}setBodyRenderer(e){return this.formRenderConfig={...this.formRenderConfig,bodyRenderer:e},this}setSubmitButtonRenderer(e){return this.formRenderConfig={...this.formRenderConfig,submitButtonRenderer:e},this}setFieldRenderer(e){return this.formRenderConfig={...this.formRenderConfig,fieldRenderer:e},this}setFormRenderConfig(e){return this.formRenderConfig=e,this}getFormRenderConfig(){return {...this.formRenderConfig}}setStepperRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,stepperRenderer:e},this}setWorkflowNextButtonRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,nextButtonRenderer:e},this}setWorkflowPreviousButtonRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,previousButtonRenderer:e},this}setWorkflowSkipButtonRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,skipButtonRenderer:e},this}setWorkflowRenderConfig(e){return this.workflowRenderConfig=e,this}getWorkflowRenderConfig(){return {...this.workflowRenderConfig}}getComponent(e){return this.components.get(e)}getAllComponents(){return Array.from(this.components.values())}hasComponent(e){return this.components.has(e)}removeComponent(e){return this.components.delete(e)}clear(){this.components.clear();}getStats(){let e=Array.from(this.components.values());return {total:e.length,byType:e.reduce((r,o)=>(r[o.type]=(r[o.type]||0)+1,r),{}),hasCustomRenderers:{row:!!this.formRenderConfig.rowRenderer,body:!!this.formRenderConfig.bodyRenderer,submitButton:!!this.formRenderConfig.submitButtonRenderer,field:!!this.formRenderConfig.fieldRenderer,stepper:!!this.workflowRenderConfig.stepperRenderer,workflowNextButton:!!this.workflowRenderConfig.nextButtonRenderer,workflowPreviousButton:!!this.workflowRenderConfig.previousButtonRenderer,workflowSkipButton:!!this.workflowRenderConfig.skipButtonRenderer}}}validate(){let e=[],r=Array.from(this.components.values()),o=r.map(a=>a.id),t=o.filter((a,s)=>o.indexOf(a)!==s);t.length>0&&e.push(`Duplicate component IDs found: ${t.join(", ")}`);let i=r.filter(a=>!a.renderer);return i.length>0&&e.push(`Components without renderer: ${i.map(a=>a.id).join(", ")}`),e}};var f=n=>async e=>{try{return await n.parseAsync(e),{isValid:!0,errors:[]}}catch(r){return r&&typeof r=="object"&&"errors"in r&&Array.isArray(r.errors)?{isValid:false,errors:r.errors.map(o=>({code:o.code,message:o.message,path:o.path?o.path.map(String):[]}))}:{isValid:false,errors:[{code:"unknown",message:r instanceof Error?r.message:"Unknown validation error"}]}}},R=n=>async(e,r,o)=>{try{let t=await n(e,r);return t===!0?{isValid:!0,errors:[]}:t===!1?{isValid:!1,errors:[{code:"validation_failed",message:"Validation failed"}]}:{isValid:!1,errors:[{code:"validation_failed",message:String(t)}]}}catch(t){return {isValid:false,errors:[{code:"validation_error",message:t instanceof Error?t.message:"Validation error"}]}}},P=(n,e="all")=>async(r,o,t)=>{let i=await Promise.all(n.map(d=>d(r,o,t)));if(e==="all"){let d=i.flatMap(l=>l.errors);return {isValid:i.every(l=>l.isValid),errors:d}}return i.some(d=>d.isValid)?{isValid:true,errors:[]}:{isValid:false,errors:i.flatMap(d=>d.errors)}},x=(n,e)=>async(r,o,t)=>n(r,o)?e(r,o,t):{isValid:true,errors:[]},v={required:(n="This field is required")=>R(e=>e==null||e===""?n:!0),email:(n="Invalid email format")=>f(zod.z.string().email(n)),minLength:(n,e)=>f(zod.z.string().min(n,e||`Minimum ${n} characters required`)),maxLength:(n,e)=>f(zod.z.string().max(n,e||`Maximum ${n} characters allowed`)),pattern:(n,e="Invalid format")=>f(zod.z.string().regex(n,e)),numberRange:(n,e,r)=>{let o=zod.z.number();return n!==void 0&&(o=o.min(n,r||`Value must be at least ${n}`)),e!==void 0&&(o=o.max(e,r||`Value must be at most ${e}`)),f(o)},url:(n="Invalid URL format")=>f(zod.z.string().url(n)),phoneNumber:(n="Invalid phone number format")=>f(zod.z.string().regex(/^\+?[\d\s\-\(\)]+$/,n)),asyncValidation:(n,e=300)=>{let r=new Map;return (o,t,i)=>new Promise(a=>{let s=`${t.fieldId}-${JSON.stringify(o)}`;r.has(s)&&clearTimeout(r.get(s));let d=setTimeout(async()=>{try{let l=await n(o,t);a(l===!0?{isValid:!0,errors:[]}:{isValid:!1,errors:[{code:"async_validation_failed",message:typeof l=="string"?l:"Async validation failed"}]});}catch(l){a({isValid:false,errors:[{code:"async_validation_error",message:l instanceof Error?l.message:"Async validation error"}]});}finally{r.delete(s);}},e);r.set(s,d);})}},b=(n,e=[])=>({isValid:n,errors:e}),S=(n,e,r)=>({code:n,message:e,path:r});var m=class{constructor(){this.name="localStorage";}async save(e,r){try{localStorage.setItem(e,JSON.stringify(r));}catch(o){throw new Error(`Failed to save to localStorage: ${o}`)}}async load(e){try{let r=localStorage.getItem(e);return r?JSON.parse(r):null}catch(r){throw new Error(`Failed to load from localStorage: ${r}`)}}async remove(e){try{localStorage.removeItem(e);}catch(r){throw new Error(`Failed to remove from localStorage: ${r}`)}}async exists(e){return localStorage.getItem(e)!==null}async list(e){let r=[];for(let o=0;o<localStorage.length;o++){let t=localStorage.key(o);t&&(!e||t.includes(e))&&r.push(t);}return r}},y=class{constructor(){this.name="sessionStorage";}async save(e,r){try{sessionStorage.setItem(e,JSON.stringify(r));}catch(o){throw new Error(`Failed to save to sessionStorage: ${o}`)}}async load(e){try{let r=sessionStorage.getItem(e);return r?JSON.parse(r):null}catch(r){throw new Error(`Failed to load from sessionStorage: ${r}`)}}async remove(e){try{sessionStorage.removeItem(e);}catch(r){throw new Error(`Failed to remove from sessionStorage: ${r}`)}}async exists(e){return sessionStorage.getItem(e)!==null}async list(e){let r=[];for(let o=0;o<sessionStorage.length;o++){let t=sessionStorage.key(o);t&&(!e||t.includes(e))&&r.push(t);}return r}},p=class{constructor(){this.name="memory";this.storage=new Map;}async save(e,r){this.storage.set(e,{...r});}async load(e){let r=this.storage.get(e);return r?{...r}:null}async remove(e){this.storage.delete(e);}async exists(e){return this.storage.has(e)}async list(e){let r=Array.from(this.storage.keys());return e?r.filter(o=>o.includes(e)):r}clear(){this.storage.clear();}},u=class{constructor(e,r=[]){this.primary=e;this.fallbacks=r;this.name="composite";}async save(e,r){let o=[this.primary,...this.fallbacks];for(let t of o)try{await t.save(e,r);return}catch(i){console.warn(`Failed to save with ${t.name}:`,i);}throw new Error("All persistence adapters failed to save")}async load(e){let r=[this.primary,...this.fallbacks];for(let o of r)try{let t=await o.load(e);if(t)return t}catch(t){console.warn(`Failed to load with ${o.name}:`,t);}return null}async remove(e){let r=[this.primary,...this.fallbacks],o=[];for(let t of r)try{await t.remove(e);}catch(i){o.push(i);}if(o.length===r.length)throw new Error(`All adapters failed to remove: ${o.map(t=>t.message).join(", ")}`)}async exists(e){let r=[this.primary,...this.fallbacks];for(let o of r)try{if(await o.exists(e))return !0}catch(t){console.warn(`Failed to check existence with ${o.name}:`,t);}return false}async list(e){try{return await this.primary.list?.(e)||[]}catch(r){console.warn("Failed to list with primary adapter:",r);for(let o of this.fallbacks)try{return await o.list?.(e)||[]}catch(t){console.warn(`Failed to list with fallback ${o.name}:`,t);}return []}}};var B={localStorage(n={}){return {adapter:new m,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...n}},sessionStorage(n={}){return {adapter:new y,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...n}},memory(n={}){return {adapter:new p,debounceMs:0,autoSave:true,saveOnStepChange:true,...n}},custom(n,e={}){return {adapter:n,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...e}}};function E(n,e,r={}){let o=e||new p;return {adapter:{name:`resilient-${n.name}`,async save(i,a){try{await n.save(i,a);}catch(s){console.warn("Primary persistence failed, using fallback:",s),await o.save(i,a);}},async load(i){try{let a=await n.load(i);if(a)return a}catch(a){console.warn("Primary persistence load failed, trying fallback:",a);}return await o.load(i)},async remove(i){let a=[];try{await n.remove(i);}catch(s){a.push(s);}try{await o.remove(i);}catch(s){a.push(s);}if(a.length===2)throw new Error(`Both adapters failed: ${a.map(s=>s.message).join(", ")}`)},async exists(i){try{if(await n.exists(i))return !0}catch(a){console.warn("Primary persistence exists check failed:",a);}try{return await o.exists(i)}catch(a){return console.warn("Fallback persistence exists check failed:",a),false}},async list(i){try{return await n.list?.(i)||[]}catch(a){console.warn("Primary persistence list failed:",a);try{return await o.list?.(i)||[]}catch(s){return console.warn("Fallback persistence list failed:",s),[]}}}},debounceMs:1e3,autoSave:true,saveOnStepChange:true,maxRetries:3,retryDelayMs:1e3,...r}}exports.CompositeAdapter=u;exports.LocalStorageAdapter=m;exports.MemoryAdapter=p;exports.SessionStorageAdapter=y;exports.combineValidators=P;exports.commonValidators=v;exports.createConditionalValidator=x;exports.createCustomValidator=R;exports.createResilientPersistence=E;exports.createValidationError=S;exports.createValidationResult=b;exports.createZodValidator=f;exports.persistence=B;exports.resolveRendererChildren=w;exports.ril=g;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {z}from'zod';function w(n,e){return typeof n=="function"?n(e):n}var u=class n{constructor(){this.components=new Map;this.formRenderConfig={};this.workflowRenderConfig={};}static create(){return new n}addComponent(e,r){let o={id:e,type:e,...r};return this.components.set(e,o),this}setRenderer(e,r){return e in this.formRenderConfig?this.formRenderConfig={...this.formRenderConfig,[e]:r}:e in this.workflowRenderConfig&&(this.workflowRenderConfig={...this.workflowRenderConfig,[e]:r}),this}setRenderers(e){let r={},o={};for(let[t,i]of Object.entries(e))["rowRenderer","bodyRenderer","submitButtonRenderer","fieldRenderer"].includes(t)?r[t]=i:o[t]=i;return this.formRenderConfig={...this.formRenderConfig,...r},this.workflowRenderConfig={...this.workflowRenderConfig,...o},this}setRowRenderer(e){return this.formRenderConfig={...this.formRenderConfig,rowRenderer:e},this}setBodyRenderer(e){return this.formRenderConfig={...this.formRenderConfig,bodyRenderer:e},this}setSubmitButtonRenderer(e){return this.formRenderConfig={...this.formRenderConfig,submitButtonRenderer:e},this}setFieldRenderer(e){return this.formRenderConfig={...this.formRenderConfig,fieldRenderer:e},this}setFormRenderConfig(e){return this.formRenderConfig=e,this}getFormRenderConfig(){return {...this.formRenderConfig}}setStepperRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,stepperRenderer:e},this}setWorkflowNextButtonRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,nextButtonRenderer:e},this}setWorkflowPreviousButtonRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,previousButtonRenderer:e},this}setWorkflowSkipButtonRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,skipButtonRenderer:e},this}setWorkflowRenderConfig(e){return this.workflowRenderConfig=e,this}getWorkflowRenderConfig(){return {...this.workflowRenderConfig}}setRenderConfig(e){return this.setFormRenderConfig(e)}getComponent(e){return this.components.get(e)}getAllComponents(){return Array.from(this.components.values())}hasComponent(e){return this.components.has(e)}removeComponent(e){return this.components.delete(e)}clear(){this.components.clear();}getStats(){let e=Array.from(this.components.values());return {total:e.length,byType:e.reduce((r,o)=>(r[o.type]=(r[o.type]||0)+1,r),{}),hasCustomRenderers:{row:!!this.formRenderConfig.rowRenderer,body:!!this.formRenderConfig.bodyRenderer,submitButton:!!this.formRenderConfig.submitButtonRenderer,field:!!this.formRenderConfig.fieldRenderer,stepper:!!this.workflowRenderConfig.stepperRenderer,workflowNextButton:!!this.workflowRenderConfig.nextButtonRenderer,workflowPreviousButton:!!this.workflowRenderConfig.previousButtonRenderer,workflowSkipButton:!!this.workflowRenderConfig.skipButtonRenderer}}}validate(){let e=[],r=Array.from(this.components.values()),o=r.map(a=>a.id),t=o.filter((a,s)=>o.indexOf(a)!==s);t.length>0&&e.push(`Duplicate component IDs found: ${t.join(", ")}`);let i=r.filter(a=>!a.renderer);return i.length>0&&e.push(`Components without renderer: ${i.map(a=>a.id).join(", ")}`),e}};var f=n=>async e=>{try{return await n.parseAsync(e),{isValid:!0,errors:[]}}catch(r){return r&&typeof r=="object"&&"errors"in r&&Array.isArray(r.errors)?{isValid:false,errors:r.errors.map(o=>({code:o.code,message:o.message,path:o.path?o.path.map(String):[]}))}:{isValid:false,errors:[{code:"unknown",message:r instanceof Error?r.message:"Unknown validation error"}]}}},R=n=>async(e,r,o)=>{try{let t=await n(e,r);return t===!0?{isValid:!0,errors:[]}:t===!1?{isValid:!1,errors:[{code:"validation_failed",message:"Validation failed"}]}:{isValid:!1,errors:[{code:"validation_failed",message:String(t)}]}}catch(t){return {isValid:false,errors:[{code:"validation_error",message:t instanceof Error?t.message:"Validation error"}]}}},P=(n,e="all")=>async(r,o,t)=>{let i=await Promise.all(n.map(d=>d(r,o,t)));if(e==="all"){let d=i.flatMap(l=>l.errors);return {isValid:i.every(l=>l.isValid),errors:d}}return i.some(d=>d.isValid)?{isValid:true,errors:[]}:{isValid:false,errors:i.flatMap(d=>d.errors)}},x=(n,e)=>async(r,o,t)=>n(r,o)?e(r,o,t):{isValid:true,errors:[]},v={required:(n="This field is required")=>R(e=>e==null||e===""?n:!0),email:(n="Invalid email format")=>f(z.string().email(n)),minLength:(n,e)=>f(z.string().min(n,e||`Minimum ${n} characters required`)),maxLength:(n,e)=>f(z.string().max(n,e||`Maximum ${n} characters allowed`)),pattern:(n,e="Invalid format")=>f(z.string().regex(n,e)),numberRange:(n,e,r)=>{let o=z.number();return n!==void 0&&(o=o.min(n,r||`Value must be at least ${n}`)),e!==void 0&&(o=o.max(e,r||`Value must be at most ${e}`)),f(o)},url:(n="Invalid URL format")=>f(z.string().url(n)),phoneNumber:(n="Invalid phone number format")=>f(z.string().regex(/^\+?[\d\s\-\(\)]+$/,n)),asyncValidation:(n,e=300)=>{let r=new Map;return (o,t,i)=>new Promise(a=>{let s=`${t.fieldId}-${JSON.stringify(o)}`;r.has(s)&&clearTimeout(r.get(s));let d=setTimeout(async()=>{try{let l=await n(o,t);a(l===!0?{isValid:!0,errors:[]}:{isValid:!1,errors:[{code:"async_validation_failed",message:typeof l=="string"?l:"Async validation failed"}]});}catch(l){a({isValid:false,errors:[{code:"async_validation_error",message:l instanceof Error?l.message:"Async validation error"}]});}finally{r.delete(s);}},e);r.set(s,d);})}},b=(n,e=[])=>({isValid:n,errors:e}),S=(n,e,r)=>({code:n,message:e,path:r});var m=class{constructor(){this.name="localStorage";}async save(e,r){try{localStorage.setItem(e,JSON.stringify(r));}catch(o){throw new Error(`Failed to save to localStorage: ${o}`)}}async load(e){try{let r=localStorage.getItem(e);return r?JSON.parse(r):null}catch(r){throw new Error(`Failed to load from localStorage: ${r}`)}}async remove(e){try{localStorage.removeItem(e);}catch(r){throw new Error(`Failed to remove from localStorage: ${r}`)}}async exists(e){return localStorage.getItem(e)!==null}async list(e){let r=[];for(let o=0;o<localStorage.length;o++){let t=localStorage.key(o);t&&(!e||t.includes(e))&&r.push(t);}return r}},y=class{constructor(){this.name="sessionStorage";}async save(e,r){try{sessionStorage.setItem(e,JSON.stringify(r));}catch(o){throw new Error(`Failed to save to sessionStorage: ${o}`)}}async load(e){try{let r=sessionStorage.getItem(e);return r?JSON.parse(r):null}catch(r){throw new Error(`Failed to load from sessionStorage: ${r}`)}}async remove(e){try{sessionStorage.removeItem(e);}catch(r){throw new Error(`Failed to remove from sessionStorage: ${r}`)}}async exists(e){return sessionStorage.getItem(e)!==null}async list(e){let r=[];for(let o=0;o<sessionStorage.length;o++){let t=sessionStorage.key(o);t&&(!e||t.includes(e))&&r.push(t);}return r}},p=class{constructor(){this.name="memory";this.storage=new Map;}async save(e,r){this.storage.set(e,{...r});}async load(e){let r=this.storage.get(e);return r?{...r}:null}async remove(e){this.storage.delete(e);}async exists(e){return this.storage.has(e)}async list(e){let r=Array.from(this.storage.keys());return e?r.filter(o=>o.includes(e)):r}clear(){this.storage.clear();}},g=class{constructor(e,r=[]){this.primary=e;this.fallbacks=r;this.name="composite";}async save(e,r){let o=[this.primary,...this.fallbacks];for(let t of o)try{await t.save(e,r);return}catch(i){console.warn(`Failed to save with ${t.name}:`,i);}throw new Error("All persistence adapters failed to save")}async load(e){let r=[this.primary,...this.fallbacks];for(let o of r)try{let t=await o.load(e);if(t)return t}catch(t){console.warn(`Failed to load with ${o.name}:`,t);}return null}async remove(e){let r=[this.primary,...this.fallbacks],o=[];for(let t of r)try{await t.remove(e);}catch(i){o.push(i);}if(o.length===r.length)throw new Error(`All adapters failed to remove: ${o.map(t=>t.message).join(", ")}`)}async exists(e){let r=[this.primary,...this.fallbacks];for(let o of r)try{if(await o.exists(e))return !0}catch(t){console.warn(`Failed to check existence with ${o.name}:`,t);}return false}async list(e){try{return await this.primary.list?.(e)||[]}catch(r){console.warn("Failed to list with primary adapter:",r);for(let o of this.fallbacks)try{return await o.list?.(e)||[]}catch(t){console.warn(`Failed to list with fallback ${o.name}:`,t);}return []}}};var B={localStorage(n={}){return {adapter:new m,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...n}},sessionStorage(n={}){return {adapter:new y,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...n}},memory(n={}){return {adapter:new p,debounceMs:0,autoSave:true,saveOnStepChange:true,...n}},custom(n,e={}){return {adapter:n,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...e}}};function E(n,e,r={}){let o=e||new p;return {adapter:{name:`resilient-${n.name}`,async save(i,a){try{await n.save(i,a);}catch(s){console.warn("Primary persistence failed, using fallback:",s),await o.save(i,a);}},async load(i){try{let a=await n.load(i);if(a)return a}catch(a){console.warn("Primary persistence load failed, trying fallback:",a);}return await o.load(i)},async remove(i){let a=[];try{await n.remove(i);}catch(s){a.push(s);}try{await o.remove(i);}catch(s){a.push(s);}if(a.length===2)throw new Error(`Both adapters failed: ${a.map(s=>s.message).join(", ")}`)},async exists(i){try{if(await n.exists(i))return !0}catch(a){console.warn("Primary persistence exists check failed:",a);}try{return await o.exists(i)}catch(a){return console.warn("Fallback persistence exists check failed:",a),false}},async list(i){try{return await n.list?.(i)||[]}catch(a){console.warn("Primary persistence list failed:",a);try{return await o.list?.(i)||[]}catch(s){return console.warn("Fallback persistence list failed:",s),[]}}}},debounceMs:1e3,autoSave:true,saveOnStepChange:true,maxRetries:3,retryDelayMs:1e3,...r}}export{g as CompositeAdapter,m as LocalStorageAdapter,p as MemoryAdapter,y as SessionStorageAdapter,P as combineValidators,v as commonValidators,x as createConditionalValidator,R as createCustomValidator,E as createResilientPersistence,S as createValidationError,b as createValidationResult,f as createZodValidator,B as persistence,w as resolveRendererChildren,u as ril};
|
|
1
|
+
import {z}from'zod';function w(n,e){return typeof n=="function"?n(e):n}var g=class n{constructor(){this.components=new Map;this.formRenderConfig={};this.workflowRenderConfig={};}static create(){return new n}addComponent(e,r){let o={id:e,type:e,...r};return this.components.set(e,o),this}setRenderer(e,r){return e in this.formRenderConfig?this.formRenderConfig={...this.formRenderConfig,[e]:r}:e in this.workflowRenderConfig&&(this.workflowRenderConfig={...this.workflowRenderConfig,[e]:r}),this}setRenderers(e){let r={},o={};for(let[t,i]of Object.entries(e))["rowRenderer","bodyRenderer","submitButtonRenderer","fieldRenderer"].includes(t)?r[t]=i:o[t]=i;return this.formRenderConfig={...this.formRenderConfig,...r},this.workflowRenderConfig={...this.workflowRenderConfig,...o},this}setRowRenderer(e){return this.formRenderConfig={...this.formRenderConfig,rowRenderer:e},this}setBodyRenderer(e){return this.formRenderConfig={...this.formRenderConfig,bodyRenderer:e},this}setSubmitButtonRenderer(e){return this.formRenderConfig={...this.formRenderConfig,submitButtonRenderer:e},this}setFieldRenderer(e){return this.formRenderConfig={...this.formRenderConfig,fieldRenderer:e},this}setFormRenderConfig(e){return this.formRenderConfig=e,this}getFormRenderConfig(){return {...this.formRenderConfig}}setStepperRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,stepperRenderer:e},this}setWorkflowNextButtonRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,nextButtonRenderer:e},this}setWorkflowPreviousButtonRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,previousButtonRenderer:e},this}setWorkflowSkipButtonRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,skipButtonRenderer:e},this}setWorkflowRenderConfig(e){return this.workflowRenderConfig=e,this}getWorkflowRenderConfig(){return {...this.workflowRenderConfig}}getComponent(e){return this.components.get(e)}getAllComponents(){return Array.from(this.components.values())}hasComponent(e){return this.components.has(e)}removeComponent(e){return this.components.delete(e)}clear(){this.components.clear();}getStats(){let e=Array.from(this.components.values());return {total:e.length,byType:e.reduce((r,o)=>(r[o.type]=(r[o.type]||0)+1,r),{}),hasCustomRenderers:{row:!!this.formRenderConfig.rowRenderer,body:!!this.formRenderConfig.bodyRenderer,submitButton:!!this.formRenderConfig.submitButtonRenderer,field:!!this.formRenderConfig.fieldRenderer,stepper:!!this.workflowRenderConfig.stepperRenderer,workflowNextButton:!!this.workflowRenderConfig.nextButtonRenderer,workflowPreviousButton:!!this.workflowRenderConfig.previousButtonRenderer,workflowSkipButton:!!this.workflowRenderConfig.skipButtonRenderer}}}validate(){let e=[],r=Array.from(this.components.values()),o=r.map(a=>a.id),t=o.filter((a,s)=>o.indexOf(a)!==s);t.length>0&&e.push(`Duplicate component IDs found: ${t.join(", ")}`);let i=r.filter(a=>!a.renderer);return i.length>0&&e.push(`Components without renderer: ${i.map(a=>a.id).join(", ")}`),e}};var f=n=>async e=>{try{return await n.parseAsync(e),{isValid:!0,errors:[]}}catch(r){return r&&typeof r=="object"&&"errors"in r&&Array.isArray(r.errors)?{isValid:false,errors:r.errors.map(o=>({code:o.code,message:o.message,path:o.path?o.path.map(String):[]}))}:{isValid:false,errors:[{code:"unknown",message:r instanceof Error?r.message:"Unknown validation error"}]}}},R=n=>async(e,r,o)=>{try{let t=await n(e,r);return t===!0?{isValid:!0,errors:[]}:t===!1?{isValid:!1,errors:[{code:"validation_failed",message:"Validation failed"}]}:{isValid:!1,errors:[{code:"validation_failed",message:String(t)}]}}catch(t){return {isValid:false,errors:[{code:"validation_error",message:t instanceof Error?t.message:"Validation error"}]}}},P=(n,e="all")=>async(r,o,t)=>{let i=await Promise.all(n.map(d=>d(r,o,t)));if(e==="all"){let d=i.flatMap(l=>l.errors);return {isValid:i.every(l=>l.isValid),errors:d}}return i.some(d=>d.isValid)?{isValid:true,errors:[]}:{isValid:false,errors:i.flatMap(d=>d.errors)}},x=(n,e)=>async(r,o,t)=>n(r,o)?e(r,o,t):{isValid:true,errors:[]},v={required:(n="This field is required")=>R(e=>e==null||e===""?n:!0),email:(n="Invalid email format")=>f(z.string().email(n)),minLength:(n,e)=>f(z.string().min(n,e||`Minimum ${n} characters required`)),maxLength:(n,e)=>f(z.string().max(n,e||`Maximum ${n} characters allowed`)),pattern:(n,e="Invalid format")=>f(z.string().regex(n,e)),numberRange:(n,e,r)=>{let o=z.number();return n!==void 0&&(o=o.min(n,r||`Value must be at least ${n}`)),e!==void 0&&(o=o.max(e,r||`Value must be at most ${e}`)),f(o)},url:(n="Invalid URL format")=>f(z.string().url(n)),phoneNumber:(n="Invalid phone number format")=>f(z.string().regex(/^\+?[\d\s\-\(\)]+$/,n)),asyncValidation:(n,e=300)=>{let r=new Map;return (o,t,i)=>new Promise(a=>{let s=`${t.fieldId}-${JSON.stringify(o)}`;r.has(s)&&clearTimeout(r.get(s));let d=setTimeout(async()=>{try{let l=await n(o,t);a(l===!0?{isValid:!0,errors:[]}:{isValid:!1,errors:[{code:"async_validation_failed",message:typeof l=="string"?l:"Async validation failed"}]});}catch(l){a({isValid:false,errors:[{code:"async_validation_error",message:l instanceof Error?l.message:"Async validation error"}]});}finally{r.delete(s);}},e);r.set(s,d);})}},b=(n,e=[])=>({isValid:n,errors:e}),S=(n,e,r)=>({code:n,message:e,path:r});var m=class{constructor(){this.name="localStorage";}async save(e,r){try{localStorage.setItem(e,JSON.stringify(r));}catch(o){throw new Error(`Failed to save to localStorage: ${o}`)}}async load(e){try{let r=localStorage.getItem(e);return r?JSON.parse(r):null}catch(r){throw new Error(`Failed to load from localStorage: ${r}`)}}async remove(e){try{localStorage.removeItem(e);}catch(r){throw new Error(`Failed to remove from localStorage: ${r}`)}}async exists(e){return localStorage.getItem(e)!==null}async list(e){let r=[];for(let o=0;o<localStorage.length;o++){let t=localStorage.key(o);t&&(!e||t.includes(e))&&r.push(t);}return r}},y=class{constructor(){this.name="sessionStorage";}async save(e,r){try{sessionStorage.setItem(e,JSON.stringify(r));}catch(o){throw new Error(`Failed to save to sessionStorage: ${o}`)}}async load(e){try{let r=sessionStorage.getItem(e);return r?JSON.parse(r):null}catch(r){throw new Error(`Failed to load from sessionStorage: ${r}`)}}async remove(e){try{sessionStorage.removeItem(e);}catch(r){throw new Error(`Failed to remove from sessionStorage: ${r}`)}}async exists(e){return sessionStorage.getItem(e)!==null}async list(e){let r=[];for(let o=0;o<sessionStorage.length;o++){let t=sessionStorage.key(o);t&&(!e||t.includes(e))&&r.push(t);}return r}},p=class{constructor(){this.name="memory";this.storage=new Map;}async save(e,r){this.storage.set(e,{...r});}async load(e){let r=this.storage.get(e);return r?{...r}:null}async remove(e){this.storage.delete(e);}async exists(e){return this.storage.has(e)}async list(e){let r=Array.from(this.storage.keys());return e?r.filter(o=>o.includes(e)):r}clear(){this.storage.clear();}},u=class{constructor(e,r=[]){this.primary=e;this.fallbacks=r;this.name="composite";}async save(e,r){let o=[this.primary,...this.fallbacks];for(let t of o)try{await t.save(e,r);return}catch(i){console.warn(`Failed to save with ${t.name}:`,i);}throw new Error("All persistence adapters failed to save")}async load(e){let r=[this.primary,...this.fallbacks];for(let o of r)try{let t=await o.load(e);if(t)return t}catch(t){console.warn(`Failed to load with ${o.name}:`,t);}return null}async remove(e){let r=[this.primary,...this.fallbacks],o=[];for(let t of r)try{await t.remove(e);}catch(i){o.push(i);}if(o.length===r.length)throw new Error(`All adapters failed to remove: ${o.map(t=>t.message).join(", ")}`)}async exists(e){let r=[this.primary,...this.fallbacks];for(let o of r)try{if(await o.exists(e))return !0}catch(t){console.warn(`Failed to check existence with ${o.name}:`,t);}return false}async list(e){try{return await this.primary.list?.(e)||[]}catch(r){console.warn("Failed to list with primary adapter:",r);for(let o of this.fallbacks)try{return await o.list?.(e)||[]}catch(t){console.warn(`Failed to list with fallback ${o.name}:`,t);}return []}}};var B={localStorage(n={}){return {adapter:new m,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...n}},sessionStorage(n={}){return {adapter:new y,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...n}},memory(n={}){return {adapter:new p,debounceMs:0,autoSave:true,saveOnStepChange:true,...n}},custom(n,e={}){return {adapter:n,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...e}}};function E(n,e,r={}){let o=e||new p;return {adapter:{name:`resilient-${n.name}`,async save(i,a){try{await n.save(i,a);}catch(s){console.warn("Primary persistence failed, using fallback:",s),await o.save(i,a);}},async load(i){try{let a=await n.load(i);if(a)return a}catch(a){console.warn("Primary persistence load failed, trying fallback:",a);}return await o.load(i)},async remove(i){let a=[];try{await n.remove(i);}catch(s){a.push(s);}try{await o.remove(i);}catch(s){a.push(s);}if(a.length===2)throw new Error(`Both adapters failed: ${a.map(s=>s.message).join(", ")}`)},async exists(i){try{if(await n.exists(i))return !0}catch(a){console.warn("Primary persistence exists check failed:",a);}try{return await o.exists(i)}catch(a){return console.warn("Fallback persistence exists check failed:",a),false}},async list(i){try{return await n.list?.(i)||[]}catch(a){console.warn("Primary persistence list failed:",a);try{return await o.list?.(i)||[]}catch(s){return console.warn("Fallback persistence list failed:",s),[]}}}},debounceMs:1e3,autoSave:true,saveOnStepChange:true,maxRetries:3,retryDelayMs:1e3,...r}}export{u as CompositeAdapter,m as LocalStorageAdapter,p as MemoryAdapter,y as SessionStorageAdapter,P as combineValidators,v as commonValidators,x as createConditionalValidator,R as createCustomValidator,E as createResilientPersistence,S as createValidationError,b as createValidationResult,f as createZodValidator,B as persistence,w as resolveRendererChildren,g as ril};
|