@rilaykit/core 0.1.1-alpha.1 → 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 +21 -0
- package/dist/index.d.mts +7 -26
- package/dist/index.d.ts +7 -26
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +10 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 AND YOU CREATE
|
|
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/dist/index.d.mts
CHANGED
|
@@ -12,13 +12,11 @@ declare class ril {
|
|
|
12
12
|
static create(): ril;
|
|
13
13
|
/**
|
|
14
14
|
* Add a component to the configuration
|
|
15
|
-
* @param
|
|
16
|
-
* @param config - Component configuration without id and
|
|
15
|
+
* @param type - The component type (e.g., 'text', 'email', 'heading'), used as a unique identifier.
|
|
16
|
+
* @param config - Component configuration without id and type
|
|
17
17
|
* @returns The ril instance for chaining
|
|
18
18
|
*/
|
|
19
|
-
addComponent<TProps = any>(
|
|
20
|
-
id?: string;
|
|
21
|
-
}): this;
|
|
19
|
+
addComponent<TProps = any>(type: string, config: Omit<ComponentConfig<TProps>, 'id' | 'type'>): this;
|
|
22
20
|
/**
|
|
23
21
|
* Set custom row renderer
|
|
24
22
|
* @param renderer - Custom row renderer function
|
|
@@ -77,22 +75,10 @@ declare class ril {
|
|
|
77
75
|
setRenderConfig(config: FormRenderConfig): this;
|
|
78
76
|
/**
|
|
79
77
|
* Get a component by its ID
|
|
80
|
-
* @param id - Component ID
|
|
78
|
+
* @param id - Component ID (which is its type)
|
|
81
79
|
* @returns Component configuration or undefined
|
|
82
80
|
*/
|
|
83
81
|
getComponent(id: string): ComponentConfig | undefined;
|
|
84
|
-
/**
|
|
85
|
-
* List components by type (input or layout)
|
|
86
|
-
* @param type - Component type
|
|
87
|
-
* @returns Array of matching components
|
|
88
|
-
*/
|
|
89
|
-
getComponentsByType(type: ComponentType): ComponentConfig[];
|
|
90
|
-
/**
|
|
91
|
-
* List components by sub-type
|
|
92
|
-
* @param subType - Component sub-type
|
|
93
|
-
* @returns Array of matching components
|
|
94
|
-
*/
|
|
95
|
-
getComponentsBySubType(subType: InputType | LayoutType): ComponentConfig[];
|
|
96
82
|
/**
|
|
97
83
|
* Get components by category
|
|
98
84
|
* @param category - Component category
|
|
@@ -137,8 +123,7 @@ declare class ril {
|
|
|
137
123
|
*/
|
|
138
124
|
getStats(): {
|
|
139
125
|
total: number;
|
|
140
|
-
byType: Record<
|
|
141
|
-
bySubType: Record<string, number>;
|
|
126
|
+
byType: Record<string, number>;
|
|
142
127
|
byCategory: Record<string, number>;
|
|
143
128
|
hasCustomRenderers: {
|
|
144
129
|
row: boolean;
|
|
@@ -160,9 +145,6 @@ interface RilayLicenseConfig {
|
|
|
160
145
|
readonly environment?: 'development' | 'production';
|
|
161
146
|
readonly allowTrial?: boolean;
|
|
162
147
|
}
|
|
163
|
-
type ComponentType = 'input' | 'layout';
|
|
164
|
-
type InputType = 'text' | 'email' | 'password' | 'number' | 'select' | 'checkbox' | 'textarea' | 'file' | 'date';
|
|
165
|
-
type LayoutType = 'heading' | 'paragraph' | 'container' | 'divider' | 'spacer' | 'alert';
|
|
166
148
|
interface ValidationResult {
|
|
167
149
|
readonly isValid: boolean;
|
|
168
150
|
readonly errors: ValidationError[];
|
|
@@ -222,8 +204,7 @@ interface ComponentOptions<TProps = any> {
|
|
|
222
204
|
}
|
|
223
205
|
interface ComponentConfig<TProps = any> {
|
|
224
206
|
readonly id: string;
|
|
225
|
-
readonly type:
|
|
226
|
-
readonly subType: InputType | LayoutType;
|
|
207
|
+
readonly type: string;
|
|
227
208
|
readonly name: string;
|
|
228
209
|
readonly description?: string;
|
|
229
210
|
readonly category?: string;
|
|
@@ -633,4 +614,4 @@ declare const persistence: {
|
|
|
633
614
|
*/
|
|
634
615
|
declare function createResilientPersistence(primary: PersistenceAdapter, fallback?: PersistenceAdapter, options?: Partial<PersistenceConfig>): PersistenceConfig;
|
|
635
616
|
|
|
636
|
-
export { type CompletionConfig, type ComponentConfig, type ComponentOptions, type ComponentRenderProps, type ComponentRenderer,
|
|
617
|
+
export { type CompletionConfig, type ComponentConfig, type ComponentOptions, type ComponentRenderProps, type ComponentRenderer, CompositeAdapter, type ConditionalBranch, type ConditionalConfig, type CustomStepRenderer, type DynamicStepConfig, type FormBodyRenderer, type FormBodyRendererProps, type FormConfiguration, type FormFieldConfig, type FormFieldRow, type FormRenderConfig, type FormRowRenderer, type FormRowRendererProps, type FormSubmitButtonRenderer, type FormSubmitButtonRendererProps, LocalStorageAdapter, MemoryAdapter, type NavigationConfig, type PersistenceAdapter, type PersistenceConfig, type RetryPolicy, type RilayLicenseConfig, SessionStorageAdapter, type StepConditionalConfig, type StepConfig, type StepLifecycleHooks, type StepPermissions, type StepValidationConfig, type ValidationConfig, type ValidationContext, type ValidationError, type ValidationResult, type ValidationWarning, type ValidatorFunction, type WorkflowAnalytics, type WorkflowConfig, type WorkflowContext, type WorkflowHooks, type WorkflowNavigationRenderer, type WorkflowNavigationRendererProps, type WorkflowOptimizations, type WorkflowPersistenceData, type WorkflowPlugin, type WorkflowRenderConfig, type WorkflowStepperRenderer, type WorkflowStepperRendererProps, type WorkflowVersion, combineValidators, commonValidators, createConditionalValidator, createCustomValidator, createResilientPersistence, createValidationError, createValidationResult, createZodValidator, persistence, ril };
|
package/dist/index.d.ts
CHANGED
|
@@ -12,13 +12,11 @@ declare class ril {
|
|
|
12
12
|
static create(): ril;
|
|
13
13
|
/**
|
|
14
14
|
* Add a component to the configuration
|
|
15
|
-
* @param
|
|
16
|
-
* @param config - Component configuration without id and
|
|
15
|
+
* @param type - The component type (e.g., 'text', 'email', 'heading'), used as a unique identifier.
|
|
16
|
+
* @param config - Component configuration without id and type
|
|
17
17
|
* @returns The ril instance for chaining
|
|
18
18
|
*/
|
|
19
|
-
addComponent<TProps = any>(
|
|
20
|
-
id?: string;
|
|
21
|
-
}): this;
|
|
19
|
+
addComponent<TProps = any>(type: string, config: Omit<ComponentConfig<TProps>, 'id' | 'type'>): this;
|
|
22
20
|
/**
|
|
23
21
|
* Set custom row renderer
|
|
24
22
|
* @param renderer - Custom row renderer function
|
|
@@ -77,22 +75,10 @@ declare class ril {
|
|
|
77
75
|
setRenderConfig(config: FormRenderConfig): this;
|
|
78
76
|
/**
|
|
79
77
|
* Get a component by its ID
|
|
80
|
-
* @param id - Component ID
|
|
78
|
+
* @param id - Component ID (which is its type)
|
|
81
79
|
* @returns Component configuration or undefined
|
|
82
80
|
*/
|
|
83
81
|
getComponent(id: string): ComponentConfig | undefined;
|
|
84
|
-
/**
|
|
85
|
-
* List components by type (input or layout)
|
|
86
|
-
* @param type - Component type
|
|
87
|
-
* @returns Array of matching components
|
|
88
|
-
*/
|
|
89
|
-
getComponentsByType(type: ComponentType): ComponentConfig[];
|
|
90
|
-
/**
|
|
91
|
-
* List components by sub-type
|
|
92
|
-
* @param subType - Component sub-type
|
|
93
|
-
* @returns Array of matching components
|
|
94
|
-
*/
|
|
95
|
-
getComponentsBySubType(subType: InputType | LayoutType): ComponentConfig[];
|
|
96
82
|
/**
|
|
97
83
|
* Get components by category
|
|
98
84
|
* @param category - Component category
|
|
@@ -137,8 +123,7 @@ declare class ril {
|
|
|
137
123
|
*/
|
|
138
124
|
getStats(): {
|
|
139
125
|
total: number;
|
|
140
|
-
byType: Record<
|
|
141
|
-
bySubType: Record<string, number>;
|
|
126
|
+
byType: Record<string, number>;
|
|
142
127
|
byCategory: Record<string, number>;
|
|
143
128
|
hasCustomRenderers: {
|
|
144
129
|
row: boolean;
|
|
@@ -160,9 +145,6 @@ interface RilayLicenseConfig {
|
|
|
160
145
|
readonly environment?: 'development' | 'production';
|
|
161
146
|
readonly allowTrial?: boolean;
|
|
162
147
|
}
|
|
163
|
-
type ComponentType = 'input' | 'layout';
|
|
164
|
-
type InputType = 'text' | 'email' | 'password' | 'number' | 'select' | 'checkbox' | 'textarea' | 'file' | 'date';
|
|
165
|
-
type LayoutType = 'heading' | 'paragraph' | 'container' | 'divider' | 'spacer' | 'alert';
|
|
166
148
|
interface ValidationResult {
|
|
167
149
|
readonly isValid: boolean;
|
|
168
150
|
readonly errors: ValidationError[];
|
|
@@ -222,8 +204,7 @@ interface ComponentOptions<TProps = any> {
|
|
|
222
204
|
}
|
|
223
205
|
interface ComponentConfig<TProps = any> {
|
|
224
206
|
readonly id: string;
|
|
225
|
-
readonly type:
|
|
226
|
-
readonly subType: InputType | LayoutType;
|
|
207
|
+
readonly type: string;
|
|
227
208
|
readonly name: string;
|
|
228
209
|
readonly description?: string;
|
|
229
210
|
readonly category?: string;
|
|
@@ -633,4 +614,4 @@ declare const persistence: {
|
|
|
633
614
|
*/
|
|
634
615
|
declare function createResilientPersistence(primary: PersistenceAdapter, fallback?: PersistenceAdapter, options?: Partial<PersistenceConfig>): PersistenceConfig;
|
|
635
616
|
|
|
636
|
-
export { type CompletionConfig, type ComponentConfig, type ComponentOptions, type ComponentRenderProps, type ComponentRenderer,
|
|
617
|
+
export { type CompletionConfig, type ComponentConfig, type ComponentOptions, type ComponentRenderProps, type ComponentRenderer, CompositeAdapter, type ConditionalBranch, type ConditionalConfig, type CustomStepRenderer, type DynamicStepConfig, type FormBodyRenderer, type FormBodyRendererProps, type FormConfiguration, type FormFieldConfig, type FormFieldRow, type FormRenderConfig, type FormRowRenderer, type FormRowRendererProps, type FormSubmitButtonRenderer, type FormSubmitButtonRendererProps, LocalStorageAdapter, MemoryAdapter, type NavigationConfig, type PersistenceAdapter, type PersistenceConfig, type RetryPolicy, type RilayLicenseConfig, SessionStorageAdapter, type StepConditionalConfig, type StepConfig, type StepLifecycleHooks, type StepPermissions, type StepValidationConfig, type ValidationConfig, type ValidationContext, type ValidationError, type ValidationResult, type ValidationWarning, type ValidatorFunction, type WorkflowAnalytics, type WorkflowConfig, type WorkflowContext, type WorkflowHooks, type WorkflowNavigationRenderer, type WorkflowNavigationRendererProps, type WorkflowOptimizations, type WorkflowPersistenceData, type WorkflowPlugin, type WorkflowRenderConfig, type WorkflowStepperRenderer, type WorkflowStepperRendererProps, type WorkflowVersion, combineValidators, commonValidators, createConditionalValidator, createCustomValidator, createResilientPersistence, createValidationError, createValidationResult, createZodValidator, persistence, ril };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var zod=require('zod');var
|
|
1
|
+
'use strict';var zod=require('zod');var h=class o{constructor(){this.components=new Map;this.formRenderConfig={};this.workflowRenderConfig={};}static create(){return new o}addComponent(e,r){let t={id:e,type:e,...r};return this.components.set(e,t),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}setFormRenderConfig(e){return this.formRenderConfig=e,this}getFormRenderConfig(){return {...this.formRenderConfig}}setStepperRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,stepperRenderer:e},this}setWorkflowNavigationRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,navigationRenderer: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)}getComponentsByCategory(e){return Array.from(this.components.values()).filter(r=>r.category===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();}export(){return Object.fromEntries(this.components)}import(e){for(let[r,t]of Object.entries(e))this.components.set(r,t);return this}getStats(){let e=Array.from(this.components.values());return {total:e.length,byType:e.reduce((r,t)=>(r[t.type]=(r[t.type]||0)+1,r),{}),byCategory:e.reduce((r,t)=>{let n=t.category||"uncategorized";return r[n]=(r[n]||0)+1,r},{}),hasCustomRenderers:{row:!!this.formRenderConfig.rowRenderer,body:!!this.formRenderConfig.bodyRenderer,submitButton:!!this.formRenderConfig.submitButtonRenderer,stepper:!!this.workflowRenderConfig.stepperRenderer,workflowNavigation:!!this.workflowRenderConfig.navigationRenderer}}}validate(){let e=[],r=Array.from(this.components.values()),t=r.map(s=>s.id),n=t.filter((s,i)=>t.indexOf(s)!==i);n.length>0&&e.push(`Duplicate component IDs found: ${n.join(", ")}`);let a=r.filter(s=>!s.renderer);return a.length>0&&e.push(`Components without renderer: ${a.map(s=>s.id).join(", ")}`),e}};var m=o=>async e=>{try{return await o.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(t=>({code:t.code,message:t.message,path:t.path?t.path.map(String):[]}))}:{isValid:false,errors:[{code:"unknown",message:r instanceof Error?r.message:"Unknown validation error"}]}}},w=o=>async(e,r,t)=>{try{let n=await o(e,r);return n===!0?{isValid:!0,errors:[]}:n===!1?{isValid:!1,errors:[{code:"validation_failed",message:"Validation failed"}]}:{isValid:!1,errors:[{code:"validation_failed",message:String(n)}]}}catch(n){return {isValid:false,errors:[{code:"validation_error",message:n instanceof Error?n.message:"Validation error"}]}}},v=(o,e="all")=>async(r,t,n)=>{let a=await Promise.all(o.map(l=>l(r,t,n)));if(e==="all"){let l=a.flatMap(f=>f.errors),c=a.flatMap(f=>f.warnings||[]);return {isValid:a.every(f=>f.isValid),errors:l,warnings:c.length>0?c:void 0}}if(a.some(l=>l.isValid)){let l=a.flatMap(c=>c.warnings||[]);return {isValid:true,errors:[],warnings:l.length>0?l:void 0}}return {isValid:false,errors:a.flatMap(l=>l.errors)}},P=(o,e)=>async(r,t,n)=>o(r,t)?e(r,t,n):{isValid:true,errors:[]},b={required:(o="This field is required")=>w(e=>e==null||e===""?o:!0),email:(o="Invalid email format")=>m(zod.z.string().email(o)),minLength:(o,e)=>m(zod.z.string().min(o,e||`Minimum ${o} characters required`)),maxLength:(o,e)=>m(zod.z.string().max(o,e||`Maximum ${o} characters allowed`)),pattern:(o,e="Invalid format")=>m(zod.z.string().regex(o,e)),numberRange:(o,e,r)=>{let t=zod.z.number();return o!==void 0&&(t=t.min(o,r||`Value must be at least ${o}`)),e!==void 0&&(t=t.max(e,r||`Value must be at most ${e}`)),m(t)},url:(o="Invalid URL format")=>m(zod.z.string().url(o)),phoneNumber:(o="Invalid phone number format")=>m(zod.z.string().regex(/^\+?[\d\s\-\(\)]+$/,o)),asyncValidation:(o,e=300)=>{let r=new Map;return (t,n,a)=>new Promise(s=>{let i=`${n.fieldId}-${JSON.stringify(t)}`;r.has(i)&&clearTimeout(r.get(i));let l=setTimeout(async()=>{try{let c=await o(t,n);s(c===!0?{isValid:!0,errors:[]}:{isValid:!1,errors:[{code:"async_validation_failed",message:typeof c=="string"?c:"Async validation failed"}]});}catch(c){s({isValid:false,errors:[{code:"async_validation_error",message:c instanceof Error?c.message:"Async validation error"}]});}finally{r.delete(i);}},e);r.set(i,l);})}},k=(o,e=[],r)=>({isValid:o,errors:e,warnings:r}),V=(o,e,r)=>({code:o,message:e,path:r});var u=class{constructor(){this.name="localStorage";}async save(e,r){try{localStorage.setItem(e,JSON.stringify(r));}catch(t){throw new Error(`Failed to save to localStorage: ${t}`)}}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 t=0;t<localStorage.length;t++){let n=localStorage.key(t);n&&(!e||n.includes(e))&&r.push(n);}return r}},p=class{constructor(){this.name="sessionStorage";}async save(e,r){try{sessionStorage.setItem(e,JSON.stringify(r));}catch(t){throw new Error(`Failed to save to sessionStorage: ${t}`)}}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 t=0;t<sessionStorage.length;t++){let n=sessionStorage.key(t);n&&(!e||n.includes(e))&&r.push(n);}return r}},g=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(t=>t.includes(e)):r}clear(){this.storage.clear();}},y=class{constructor(e,r=[]){this.primary=e;this.fallbacks=r;this.name="composite";}async save(e,r){let t=[this.primary,...this.fallbacks];for(let n of t)try{await n.save(e,r);return}catch(a){console.warn(`Failed to save with ${n.name}:`,a);}throw new Error("All persistence adapters failed to save")}async load(e){let r=[this.primary,...this.fallbacks];for(let t of r)try{let n=await t.load(e);if(n)return n}catch(n){console.warn(`Failed to load with ${t.name}:`,n);}return null}async remove(e){let r=[this.primary,...this.fallbacks],t=[];for(let n of r)try{await n.remove(e);}catch(a){t.push(a);}if(t.length===r.length)throw new Error(`All adapters failed to remove: ${t.map(n=>n.message).join(", ")}`)}async exists(e){let r=[this.primary,...this.fallbacks];for(let t of r)try{if(await t.exists(e))return !0}catch(n){console.warn(`Failed to check existence with ${t.name}:`,n);}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 t of this.fallbacks)try{return await t.list?.(e)||[]}catch(n){console.warn(`Failed to list with fallback ${t.name}:`,n);}return []}}};var E={localStorage(o={}){return {adapter:new u,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...o}},sessionStorage(o={}){return {adapter:new p,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...o}},memory(o={}){return {adapter:new g,debounceMs:0,autoSave:true,saveOnStepChange:true,...o}},custom(o,e={}){return {adapter:o,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...e}}};function A(o,e,r={}){let t=e||new g;return {adapter:{name:`resilient-${o.name}`,async save(a,s){try{await o.save(a,s);}catch(i){console.warn("Primary persistence failed, using fallback:",i),await t.save(a,s);}},async load(a){try{let s=await o.load(a);if(s)return s}catch(s){console.warn("Primary persistence load failed, trying fallback:",s);}return await t.load(a)},async remove(a){let s=[];try{await o.remove(a);}catch(i){s.push(i);}try{await t.remove(a);}catch(i){s.push(i);}if(s.length===2)throw new Error(`Both adapters failed: ${s.map(i=>i.message).join(", ")}`)},async exists(a){try{if(await o.exists(a))return !0}catch(s){console.warn("Primary persistence exists check failed:",s);}try{return await t.exists(a)}catch(s){return console.warn("Fallback persistence exists check failed:",s),false}},async list(a){try{return await o.list?.(a)||[]}catch(s){console.warn("Primary persistence list failed:",s);try{return await t.list?.(a)||[]}catch(i){return console.warn("Fallback persistence list failed:",i),[]}}}},debounceMs:1e3,autoSave:true,saveOnStepChange:true,maxRetries:3,retryDelayMs:1e3,...r}}exports.CompositeAdapter=y;exports.LocalStorageAdapter=u;exports.MemoryAdapter=g;exports.SessionStorageAdapter=p;exports.combineValidators=v;exports.commonValidators=b;exports.createConditionalValidator=P;exports.createCustomValidator=w;exports.createResilientPersistence=A;exports.createValidationError=V;exports.createValidationResult=k;exports.createZodValidator=m;exports.persistence=E;exports.ril=h;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {z}from'zod';var
|
|
1
|
+
import {z}from'zod';var h=class o{constructor(){this.components=new Map;this.formRenderConfig={};this.workflowRenderConfig={};}static create(){return new o}addComponent(e,r){let t={id:e,type:e,...r};return this.components.set(e,t),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}setFormRenderConfig(e){return this.formRenderConfig=e,this}getFormRenderConfig(){return {...this.formRenderConfig}}setStepperRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,stepperRenderer:e},this}setWorkflowNavigationRenderer(e){return this.workflowRenderConfig={...this.workflowRenderConfig,navigationRenderer: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)}getComponentsByCategory(e){return Array.from(this.components.values()).filter(r=>r.category===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();}export(){return Object.fromEntries(this.components)}import(e){for(let[r,t]of Object.entries(e))this.components.set(r,t);return this}getStats(){let e=Array.from(this.components.values());return {total:e.length,byType:e.reduce((r,t)=>(r[t.type]=(r[t.type]||0)+1,r),{}),byCategory:e.reduce((r,t)=>{let n=t.category||"uncategorized";return r[n]=(r[n]||0)+1,r},{}),hasCustomRenderers:{row:!!this.formRenderConfig.rowRenderer,body:!!this.formRenderConfig.bodyRenderer,submitButton:!!this.formRenderConfig.submitButtonRenderer,stepper:!!this.workflowRenderConfig.stepperRenderer,workflowNavigation:!!this.workflowRenderConfig.navigationRenderer}}}validate(){let e=[],r=Array.from(this.components.values()),t=r.map(s=>s.id),n=t.filter((s,i)=>t.indexOf(s)!==i);n.length>0&&e.push(`Duplicate component IDs found: ${n.join(", ")}`);let a=r.filter(s=>!s.renderer);return a.length>0&&e.push(`Components without renderer: ${a.map(s=>s.id).join(", ")}`),e}};var m=o=>async e=>{try{return await o.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(t=>({code:t.code,message:t.message,path:t.path?t.path.map(String):[]}))}:{isValid:false,errors:[{code:"unknown",message:r instanceof Error?r.message:"Unknown validation error"}]}}},w=o=>async(e,r,t)=>{try{let n=await o(e,r);return n===!0?{isValid:!0,errors:[]}:n===!1?{isValid:!1,errors:[{code:"validation_failed",message:"Validation failed"}]}:{isValid:!1,errors:[{code:"validation_failed",message:String(n)}]}}catch(n){return {isValid:false,errors:[{code:"validation_error",message:n instanceof Error?n.message:"Validation error"}]}}},v=(o,e="all")=>async(r,t,n)=>{let a=await Promise.all(o.map(l=>l(r,t,n)));if(e==="all"){let l=a.flatMap(f=>f.errors),c=a.flatMap(f=>f.warnings||[]);return {isValid:a.every(f=>f.isValid),errors:l,warnings:c.length>0?c:void 0}}if(a.some(l=>l.isValid)){let l=a.flatMap(c=>c.warnings||[]);return {isValid:true,errors:[],warnings:l.length>0?l:void 0}}return {isValid:false,errors:a.flatMap(l=>l.errors)}},P=(o,e)=>async(r,t,n)=>o(r,t)?e(r,t,n):{isValid:true,errors:[]},b={required:(o="This field is required")=>w(e=>e==null||e===""?o:!0),email:(o="Invalid email format")=>m(z.string().email(o)),minLength:(o,e)=>m(z.string().min(o,e||`Minimum ${o} characters required`)),maxLength:(o,e)=>m(z.string().max(o,e||`Maximum ${o} characters allowed`)),pattern:(o,e="Invalid format")=>m(z.string().regex(o,e)),numberRange:(o,e,r)=>{let t=z.number();return o!==void 0&&(t=t.min(o,r||`Value must be at least ${o}`)),e!==void 0&&(t=t.max(e,r||`Value must be at most ${e}`)),m(t)},url:(o="Invalid URL format")=>m(z.string().url(o)),phoneNumber:(o="Invalid phone number format")=>m(z.string().regex(/^\+?[\d\s\-\(\)]+$/,o)),asyncValidation:(o,e=300)=>{let r=new Map;return (t,n,a)=>new Promise(s=>{let i=`${n.fieldId}-${JSON.stringify(t)}`;r.has(i)&&clearTimeout(r.get(i));let l=setTimeout(async()=>{try{let c=await o(t,n);s(c===!0?{isValid:!0,errors:[]}:{isValid:!1,errors:[{code:"async_validation_failed",message:typeof c=="string"?c:"Async validation failed"}]});}catch(c){s({isValid:false,errors:[{code:"async_validation_error",message:c instanceof Error?c.message:"Async validation error"}]});}finally{r.delete(i);}},e);r.set(i,l);})}},k=(o,e=[],r)=>({isValid:o,errors:e,warnings:r}),V=(o,e,r)=>({code:o,message:e,path:r});var u=class{constructor(){this.name="localStorage";}async save(e,r){try{localStorage.setItem(e,JSON.stringify(r));}catch(t){throw new Error(`Failed to save to localStorage: ${t}`)}}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 t=0;t<localStorage.length;t++){let n=localStorage.key(t);n&&(!e||n.includes(e))&&r.push(n);}return r}},p=class{constructor(){this.name="sessionStorage";}async save(e,r){try{sessionStorage.setItem(e,JSON.stringify(r));}catch(t){throw new Error(`Failed to save to sessionStorage: ${t}`)}}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 t=0;t<sessionStorage.length;t++){let n=sessionStorage.key(t);n&&(!e||n.includes(e))&&r.push(n);}return r}},g=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(t=>t.includes(e)):r}clear(){this.storage.clear();}},y=class{constructor(e,r=[]){this.primary=e;this.fallbacks=r;this.name="composite";}async save(e,r){let t=[this.primary,...this.fallbacks];for(let n of t)try{await n.save(e,r);return}catch(a){console.warn(`Failed to save with ${n.name}:`,a);}throw new Error("All persistence adapters failed to save")}async load(e){let r=[this.primary,...this.fallbacks];for(let t of r)try{let n=await t.load(e);if(n)return n}catch(n){console.warn(`Failed to load with ${t.name}:`,n);}return null}async remove(e){let r=[this.primary,...this.fallbacks],t=[];for(let n of r)try{await n.remove(e);}catch(a){t.push(a);}if(t.length===r.length)throw new Error(`All adapters failed to remove: ${t.map(n=>n.message).join(", ")}`)}async exists(e){let r=[this.primary,...this.fallbacks];for(let t of r)try{if(await t.exists(e))return !0}catch(n){console.warn(`Failed to check existence with ${t.name}:`,n);}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 t of this.fallbacks)try{return await t.list?.(e)||[]}catch(n){console.warn(`Failed to list with fallback ${t.name}:`,n);}return []}}};var E={localStorage(o={}){return {adapter:new u,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...o}},sessionStorage(o={}){return {adapter:new p,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...o}},memory(o={}){return {adapter:new g,debounceMs:0,autoSave:true,saveOnStepChange:true,...o}},custom(o,e={}){return {adapter:o,debounceMs:1e3,autoSave:true,saveOnStepChange:true,...e}}};function A(o,e,r={}){let t=e||new g;return {adapter:{name:`resilient-${o.name}`,async save(a,s){try{await o.save(a,s);}catch(i){console.warn("Primary persistence failed, using fallback:",i),await t.save(a,s);}},async load(a){try{let s=await o.load(a);if(s)return s}catch(s){console.warn("Primary persistence load failed, trying fallback:",s);}return await t.load(a)},async remove(a){let s=[];try{await o.remove(a);}catch(i){s.push(i);}try{await t.remove(a);}catch(i){s.push(i);}if(s.length===2)throw new Error(`Both adapters failed: ${s.map(i=>i.message).join(", ")}`)},async exists(a){try{if(await o.exists(a))return !0}catch(s){console.warn("Primary persistence exists check failed:",s);}try{return await t.exists(a)}catch(s){return console.warn("Fallback persistence exists check failed:",s),false}},async list(a){try{return await o.list?.(a)||[]}catch(s){console.warn("Primary persistence list failed:",s);try{return await t.list?.(a)||[]}catch(i){return console.warn("Fallback persistence list failed:",i),[]}}}},debounceMs:1e3,autoSave:true,saveOnStepChange:true,maxRetries:3,retryDelayMs:1e3,...r}}export{y as CompositeAdapter,u as LocalStorageAdapter,g as MemoryAdapter,p as SessionStorageAdapter,v as combineValidators,b as commonValidators,P as createConditionalValidator,w as createCustomValidator,A as createResilientPersistence,V as createValidationError,k as createValidationResult,m as createZodValidator,E as persistence,h as ril};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rilaykit/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Core types, configurations, and utilities for the RilayKit form library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,8 +14,16 @@
|
|
|
14
14
|
"validation",
|
|
15
15
|
"builder-pattern"
|
|
16
16
|
],
|
|
17
|
-
"author": "
|
|
17
|
+
"author": "AND YOU CREATE <contact@andyoucreate.com>",
|
|
18
18
|
"license": "MIT",
|
|
19
|
+
"homepage": "https://rilay.io",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/andyoucreate/rilay.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/andyoucreate/rilay/issues"
|
|
26
|
+
},
|
|
19
27
|
"peerDependencies": {
|
|
20
28
|
"react": ">=18.0.0",
|
|
21
29
|
"typescript": ">=5.0.0"
|