@quickflo/quickforms 0.1.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/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # @quickforms/core
2
+
3
+ Framework-agnostic core for QuickForms - JSON Schema form generator.
4
+
5
+ ## Features
6
+
7
+ - **ComponentRegistry**: Generic registry system for component registration with tester priority
8
+ - **SchemaUtils**: JSON Schema utilities (validation via Ajv, default values, path traversal)
9
+ - **Testers**: Predicate functions for schema type detection
10
+ - **TypeScript**: Full type definitions for JSON Schema and core interfaces
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pnpm add @quickforms/core
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ### Component Registry
21
+
22
+ ```typescript
23
+ import { ComponentRegistry, rankWith, isStringType } from '@quickforms/core';
24
+
25
+ const registry = new ComponentRegistry();
26
+
27
+ // Register a component with a tester
28
+ registry.register(
29
+ 'string-input',
30
+ MyStringInputComponent,
31
+ (schema) => rankWith(1, isStringType(schema))
32
+ );
33
+
34
+ // Get the best matching component
35
+ const component = registry.getComponent({ type: 'string' });
36
+ ```
37
+
38
+ ### Schema Utilities
39
+
40
+ ```typescript
41
+ import { SchemaUtils } from '@quickforms/core';
42
+
43
+ const utils = new SchemaUtils();
44
+
45
+ // Validate data
46
+ const result = utils.validate(schema, data);
47
+ if (!result.valid) {
48
+ console.error(result.errors);
49
+ }
50
+
51
+ // Get default values
52
+ const defaults = utils.getDefaultValue(schema);
53
+
54
+ // Get schema at path
55
+ const fieldSchema = utils.getSchemaAtPath(schema, 'user.address.street');
56
+
57
+ // Check if field is required
58
+ const isRequired = utils.isRequired(schema, 'user.name');
59
+ ```
60
+
61
+ ### Testers
62
+
63
+ ```typescript
64
+ import {
65
+ rankWith,
66
+ isStringType,
67
+ isEmailFormat,
68
+ and
69
+ } from '@quickforms/core';
70
+
71
+ // Simple tester
72
+ const stringTester = (schema) => rankWith(1, isStringType(schema));
73
+
74
+ // Format-specific tester (higher priority)
75
+ const emailTester = (schema) => rankWith(2, isEmailFormat(schema));
76
+
77
+ // Combine testers
78
+ const requiredEmailTester = (schema) =>
79
+ rankWith(3, and(isEmailFormat, isRequired)(schema));
80
+ ```
81
+
82
+ ## License
83
+
84
+ MIT
@@ -0,0 +1,5 @@
1
+ export type { JSONSchema, UISchemaElement, Rule, FieldComponent, TesterFunction, RendererProps, ValidationError, ValidationResult } from './types.js';
2
+ export { ComponentRegistry } from './registry.js';
3
+ export { rankWith, isStringType, isNumberType, isIntegerType, isBooleanType, isObjectType, isArrayType, isNullType, isEnumType, hasFormat, isEmailFormat, isDateFormat, isTimeFormat, isDateTimeFormat, isUrlFormat, hasOneOf, hasAnyOf, hasAllOf, isDiscriminatedUnion, hasConditional, hasExtension, and, or, not } from './testers.js';
4
+ export { SchemaUtils } from './schemaUtils.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,UAAU,EACV,eAAe,EACf,IAAI,EACJ,cAAc,EACd,cAAc,EACd,aAAa,EACb,eAAe,EACf,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGlD,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,aAAa,EACb,YAAY,EACZ,WAAW,EACX,UAAU,EACV,UAAU,EACV,SAAS,EACT,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,oBAAoB,EACpB,cAAc,EACd,YAAY,EACZ,GAAG,EACH,EAAE,EACF,GAAG,EACJ,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ // Registry
2
+ export { ComponentRegistry } from './registry.js';
3
+ // Testers
4
+ export { rankWith, isStringType, isNumberType, isIntegerType, isBooleanType, isObjectType, isArrayType, isNullType, isEnumType, hasFormat, isEmailFormat, isDateFormat, isTimeFormat, isDateTimeFormat, isUrlFormat, hasOneOf, hasAnyOf, hasAllOf, isDiscriminatedUnion, hasConditional, hasExtension, and, or, not } from './testers.js';
5
+ // Schema utilities
6
+ export { SchemaUtils } from './schemaUtils.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,WAAW;AACX,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,UAAU;AACV,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,aAAa,EACb,YAAY,EACZ,WAAW,EACX,UAAU,EACV,UAAU,EACV,SAAS,EACT,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,oBAAoB,EACpB,cAAc,EACd,YAAY,EACZ,GAAG,EACH,EAAE,EACF,GAAG,EACJ,MAAM,cAAc,CAAC;AAEtB,mBAAmB;AACnB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { FieldComponent, JSONSchema, UISchemaElement } from './types.js';
2
+ /**
3
+ * Registry for managing component mappings
4
+ * Uses tester priority system to determine which component to use
5
+ */
6
+ export declare class ComponentRegistry<T = any> {
7
+ private components;
8
+ /**
9
+ * Register a component with a name and tester function
10
+ */
11
+ register(name: string, component: T, tester: FieldComponent<T>['tester']): void;
12
+ /**
13
+ * Register multiple components at once
14
+ */
15
+ registerAll(components: Record<string, FieldComponent<T>>): void;
16
+ /**
17
+ * Get the best matching component for a schema
18
+ * Returns null if no component matches
19
+ */
20
+ getComponent(schema: JSONSchema, uischema?: UISchemaElement): T | null;
21
+ /**
22
+ * Get all registered components as a map
23
+ */
24
+ getAllComponents(): Map<string, T>;
25
+ /**
26
+ * Check if a component is registered with a given name
27
+ */
28
+ has(name: string): boolean;
29
+ /**
30
+ * Unregister a component by name
31
+ */
32
+ unregister(name: string): boolean;
33
+ /**
34
+ * Clear all registered components
35
+ */
36
+ clear(): void;
37
+ }
38
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE9E;;;GAGG;AACH,qBAAa,iBAAiB,CAAC,CAAC,GAAG,GAAG;IACpC,OAAO,CAAC,UAAU,CAA6C;IAE/D;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,IAAI;IAI/E;;OAEG;IACH,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;IAMhE;;;OAGG;IACH,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,eAAe,GAAG,CAAC,GAAG,IAAI;IAetE;;OAEG;IACH,gBAAgB,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;IAQlC;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIjC;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Registry for managing component mappings
3
+ * Uses tester priority system to determine which component to use
4
+ */
5
+ export class ComponentRegistry {
6
+ constructor() {
7
+ this.components = new Map();
8
+ }
9
+ /**
10
+ * Register a component with a name and tester function
11
+ */
12
+ register(name, component, tester) {
13
+ this.components.set(name, { component, tester });
14
+ }
15
+ /**
16
+ * Register multiple components at once
17
+ */
18
+ registerAll(components) {
19
+ for (const [name, fieldComponent] of Object.entries(components)) {
20
+ this.components.set(name, fieldComponent);
21
+ }
22
+ }
23
+ /**
24
+ * Get the best matching component for a schema
25
+ * Returns null if no component matches
26
+ */
27
+ getComponent(schema, uischema) {
28
+ let bestMatch = null;
29
+ let highestRank = -1;
30
+ for (const [_, fieldComponent] of this.components) {
31
+ const rank = fieldComponent.tester(schema, uischema);
32
+ if (rank > highestRank) {
33
+ highestRank = rank;
34
+ bestMatch = fieldComponent.component;
35
+ }
36
+ }
37
+ return bestMatch;
38
+ }
39
+ /**
40
+ * Get all registered components as a map
41
+ */
42
+ getAllComponents() {
43
+ const map = new Map();
44
+ for (const [name, fieldComponent] of this.components) {
45
+ map.set(name, fieldComponent.component);
46
+ }
47
+ return map;
48
+ }
49
+ /**
50
+ * Check if a component is registered with a given name
51
+ */
52
+ has(name) {
53
+ return this.components.has(name);
54
+ }
55
+ /**
56
+ * Unregister a component by name
57
+ */
58
+ unregister(name) {
59
+ return this.components.delete(name);
60
+ }
61
+ /**
62
+ * Clear all registered components
63
+ */
64
+ clear() {
65
+ this.components.clear();
66
+ }
67
+ }
68
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAA9B;QACU,eAAU,GAAmC,IAAI,GAAG,EAAE,CAAC;IAoEjE,CAAC;IAlEC;;OAEG;IACH,QAAQ,CAAC,IAAY,EAAE,SAAY,EAAE,MAAmC;QACtE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;IACn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K;QACH,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,45 @@
1
+ import type { JSONSchema, ValidationResult } from './types.js';
2
+ /**
3
+ * Utility class for JSON Schema operations
4
+ */
5
+ export declare class SchemaUtils {
6
+ private ajv;
7
+ private validators;
8
+ constructor();
9
+ /**
10
+ * Validate data against a JSON Schema
11
+ */
12
+ validate(schema: JSONSchema, data: any): ValidationResult;
13
+ /**
14
+ * Generate default value for a schema
15
+ */
16
+ getDefaultValue(schema: JSONSchema): any;
17
+ /**
18
+ * Get schema at a specific path (dot notation)
19
+ * Example: "user.address.street" -> schema for street field
20
+ */
21
+ getSchemaAtPath(schema: JSONSchema, path: string): JSONSchema | null;
22
+ /**
23
+ * Check if a field at path is required
24
+ */
25
+ isRequired(schema: JSONSchema, fieldPath: string): boolean;
26
+ /**
27
+ * Get all property paths from a schema (flattened)
28
+ * Example: { user: { name: string } } -> ['user.name']
29
+ */
30
+ getPropertyPaths(schema: JSONSchema, prefix?: string): string[];
31
+ /**
32
+ * Merge multiple schemas (for allOf)
33
+ */
34
+ mergeSchemas(...schemas: JSONSchema[]): JSONSchema;
35
+ /**
36
+ * Resolve $ref references in a schema
37
+ * Note: Only handles internal references (#/$defs/...)
38
+ */
39
+ resolveRef(schema: JSONSchema, ref: string): JSONSchema | null;
40
+ /**
41
+ * Clear the validation cache
42
+ */
43
+ clearCache(): void;
44
+ }
45
+ //# sourceMappingURL=schemaUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaUtils.d.ts","sourceRoot":"","sources":["../src/schemaUtils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAmB,MAAM,YAAY,CAAC;AAEhF;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,UAAU,CAA4C;;IAW9D;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,GAAG,gBAAgB;IAiBzD;;OAEG;IACH,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,GAAG;IAkDxC;;;OAGG;IACH,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAyCpE;;OAEG;IACH,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO;IAoB1D;;;OAGG;IACH,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,GAAE,MAAW,GAAG,MAAM,EAAE;IAkBnE;;OAEG;IACH,YAAY,CAAC,GAAG,OAAO,EAAE,UAAU,EAAE,GAAG,UAAU;IA8BlD;;;OAGG;IACH,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAmB9D;;OAEG;IACH,UAAU,IAAI,IAAI;CAGnB"}
@@ -0,0 +1,217 @@
1
+ import Ajv from 'ajv';
2
+ import addFormats from 'ajv-formats';
3
+ /**
4
+ * Utility class for JSON Schema operations
5
+ */
6
+ export class SchemaUtils {
7
+ constructor() {
8
+ this.validators = new Map();
9
+ this.ajv = new Ajv({
10
+ allErrors: true,
11
+ strict: false,
12
+ validateFormats: true
13
+ });
14
+ addFormats(this.ajv);
15
+ }
16
+ /**
17
+ * Validate data against a JSON Schema
18
+ */
19
+ validate(schema, data) {
20
+ const schemaKey = JSON.stringify(schema);
21
+ let validate = this.validators.get(schemaKey);
22
+ if (!validate) {
23
+ validate = this.ajv.compile(schema);
24
+ this.validators.set(schemaKey, validate);
25
+ }
26
+ const valid = validate(data);
27
+ return {
28
+ valid: valid,
29
+ errors: (validate.errors || [])
30
+ };
31
+ }
32
+ /**
33
+ * Generate default value for a schema
34
+ */
35
+ getDefaultValue(schema) {
36
+ // Check for explicit default
37
+ if (schema.default !== undefined) {
38
+ return schema.default;
39
+ }
40
+ // Check for const
41
+ if (schema.const !== undefined) {
42
+ return schema.const;
43
+ }
44
+ // Check for enum (use first value)
45
+ if (schema.enum && schema.enum.length > 0) {
46
+ return schema.enum[0];
47
+ }
48
+ // Handle based on type
49
+ switch (schema.type) {
50
+ case 'string':
51
+ return '';
52
+ case 'number':
53
+ case 'integer':
54
+ return 0;
55
+ case 'boolean':
56
+ return false;
57
+ case 'array':
58
+ return [];
59
+ case 'object':
60
+ const obj = {};
61
+ if (schema.properties) {
62
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
63
+ // Include required fields and fields with explicit defaults
64
+ const isRequired = schema.required?.includes(key);
65
+ const hasExplicitDefault = propSchema.default !== undefined ||
66
+ propSchema.const !== undefined ||
67
+ propSchema.enum !== undefined;
68
+ if (isRequired || hasExplicitDefault) {
69
+ obj[key] = this.getDefaultValue(propSchema);
70
+ }
71
+ }
72
+ }
73
+ return obj;
74
+ case 'null':
75
+ return null;
76
+ default:
77
+ return null;
78
+ }
79
+ }
80
+ /**
81
+ * Get schema at a specific path (dot notation)
82
+ * Example: "user.address.street" -> schema for street field
83
+ */
84
+ getSchemaAtPath(schema, path) {
85
+ if (!path || path === '') {
86
+ return schema;
87
+ }
88
+ const parts = path.split('.');
89
+ let current = schema;
90
+ for (const part of parts) {
91
+ if (current.type === 'object' && current.properties) {
92
+ const nextSchema = current.properties[part];
93
+ if (!nextSchema) {
94
+ return null;
95
+ }
96
+ current = nextSchema;
97
+ }
98
+ else if (current.type === 'array') {
99
+ // Handle array index (e.g., "items.0.field")
100
+ if (!isNaN(Number(part))) {
101
+ if (Array.isArray(current.items)) {
102
+ const index = Number(part);
103
+ current = current.items[index];
104
+ }
105
+ else if (current.items) {
106
+ current = current.items;
107
+ }
108
+ else {
109
+ return null;
110
+ }
111
+ }
112
+ else {
113
+ return null;
114
+ }
115
+ }
116
+ else {
117
+ return null;
118
+ }
119
+ if (!current) {
120
+ return null;
121
+ }
122
+ }
123
+ return current;
124
+ }
125
+ /**
126
+ * Check if a field at path is required
127
+ */
128
+ isRequired(schema, fieldPath) {
129
+ const parts = fieldPath.split('.');
130
+ const fieldName = parts.pop();
131
+ const parentPath = parts.join('.');
132
+ if (!fieldName) {
133
+ return false;
134
+ }
135
+ const parentSchema = parentPath
136
+ ? this.getSchemaAtPath(schema, parentPath)
137
+ : schema;
138
+ if (!parentSchema || parentSchema.type !== 'object') {
139
+ return false;
140
+ }
141
+ return parentSchema.required?.includes(fieldName) || false;
142
+ }
143
+ /**
144
+ * Get all property paths from a schema (flattened)
145
+ * Example: { user: { name: string } } -> ['user.name']
146
+ */
147
+ getPropertyPaths(schema, prefix = '') {
148
+ const paths = [];
149
+ if (schema.type === 'object' && schema.properties) {
150
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
151
+ const fullPath = prefix ? `${prefix}.${key}` : key;
152
+ paths.push(fullPath);
153
+ // Recursively get nested paths
154
+ if (propSchema.type === 'object' && propSchema.properties) {
155
+ paths.push(...this.getPropertyPaths(propSchema, fullPath));
156
+ }
157
+ }
158
+ }
159
+ return paths;
160
+ }
161
+ /**
162
+ * Merge multiple schemas (for allOf)
163
+ */
164
+ mergeSchemas(...schemas) {
165
+ const merged = {
166
+ type: 'object',
167
+ properties: {},
168
+ required: []
169
+ };
170
+ for (const schema of schemas) {
171
+ if (schema.properties) {
172
+ merged.properties = {
173
+ ...merged.properties,
174
+ ...schema.properties
175
+ };
176
+ }
177
+ if (schema.required) {
178
+ merged.required = [
179
+ ...(merged.required || []),
180
+ ...schema.required
181
+ ];
182
+ }
183
+ // Merge other properties
184
+ if (schema.title)
185
+ merged.title = schema.title;
186
+ if (schema.description)
187
+ merged.description = schema.description;
188
+ }
189
+ return merged;
190
+ }
191
+ /**
192
+ * Resolve $ref references in a schema
193
+ * Note: Only handles internal references (#/$defs/...)
194
+ */
195
+ resolveRef(schema, ref) {
196
+ if (!ref.startsWith('#/')) {
197
+ console.warn('External references not supported:', ref);
198
+ return null;
199
+ }
200
+ const path = ref.substring(2).split('/'); // Remove '#/' and split
201
+ let current = schema;
202
+ for (const part of path) {
203
+ current = current[part];
204
+ if (!current) {
205
+ return null;
206
+ }
207
+ }
208
+ return current;
209
+ }
210
+ /**
211
+ * Clear the validation cache
212
+ */
213
+ clearCache() {
214
+ this.validators.clear();
215
+ }
216
+ }
217
+ //# sourceMappingURL=schemaUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaUtils.js","sourceRoot":"","sources":["../src/schemaUtils.ts"],"names":[],"mappings":"AAAA,OAAO,GAA8B,MAAM,KAAK,CAAC;AACjD,OAAO,UAAU,MAAM,aAAa,CAAC;AAGrC;;GAEG;AACH,MAAM,OAAO,WAAW;IAItB;QAFQ,eAAU,GAAkC,IAAI,GAAG,EAAE,CAAC;QAG5D,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC;YACjB,SAAS,EAAE,IAAI;YACf,MAAM,EAAE,KAAK;YACb,eAAe,EAAE,IAAI;SACtB,CAAC,CAAC;QACH,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,MAAkB,EAAE,IAAS;QACpC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAEzC,IAAI,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC9C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACpC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC3C,CAAC;QAED,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAE7B,OAAO;YACL,KAAK,EAAE,KAAgB;YACvB,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,IAAI,EAAE,CAAsB;SACrD,CAAC;IACJ,CAAC;IAED;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,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,IAAI,CAAC,oCAAoC,EAAE,GAAG,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,IAAI,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,wBAAwB;QAClE,IAAI,OAAO,GAAQ,MAAM,CAAC;QAE1B,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACxB,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;YACxB,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAED,OAAO,OAAqB,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,UAAU;QACR,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,60 @@
1
+ import type { JSONSchema } from './types.js';
2
+ /**
3
+ * Helper to create a ranked tester
4
+ * Returns rank if predicate is true, -1 otherwise
5
+ */
6
+ export declare const rankWith: (rank: number, predicate: boolean) => number;
7
+ /**
8
+ * Basic type testers
9
+ */
10
+ export declare const isStringType: (schema: JSONSchema) => boolean;
11
+ export declare const isNumberType: (schema: JSONSchema) => boolean;
12
+ export declare const isIntegerType: (schema: JSONSchema) => boolean;
13
+ export declare const isBooleanType: (schema: JSONSchema) => boolean;
14
+ export declare const isObjectType: (schema: JSONSchema) => boolean;
15
+ export declare const isArrayType: (schema: JSONSchema) => boolean;
16
+ export declare const isNullType: (schema: JSONSchema) => boolean;
17
+ /**
18
+ * Enum tester
19
+ */
20
+ export declare const isEnumType: (schema: JSONSchema) => boolean;
21
+ /**
22
+ * Format-specific testers
23
+ */
24
+ export declare const hasFormat: (format: string) => (schema: JSONSchema) => boolean;
25
+ export declare const isEmailFormat: (schema: JSONSchema) => boolean;
26
+ export declare const isDateFormat: (schema: JSONSchema) => boolean;
27
+ export declare const isTimeFormat: (schema: JSONSchema) => boolean;
28
+ export declare const isDateTimeFormat: (schema: JSONSchema) => boolean;
29
+ export declare const isUrlFormat: (schema: JSONSchema) => boolean;
30
+ /**
31
+ * Composition testers
32
+ */
33
+ export declare const hasOneOf: (schema: JSONSchema) => boolean;
34
+ export declare const hasAnyOf: (schema: JSONSchema) => boolean;
35
+ export declare const hasAllOf: (schema: JSONSchema) => boolean;
36
+ /**
37
+ * Discriminated union tester
38
+ */
39
+ export declare const isDiscriminatedUnion: (schema: JSONSchema) => boolean;
40
+ /**
41
+ * Conditional schema tester
42
+ */
43
+ export declare const hasConditional: (schema: JSONSchema) => boolean;
44
+ /**
45
+ * Custom extension tester factory
46
+ */
47
+ export declare const hasExtension: (extensionKey: string) => (schema: JSONSchema) => boolean;
48
+ /**
49
+ * Combines multiple testers with AND logic
50
+ */
51
+ export declare const and: (...testers: Array<(schema: JSONSchema) => boolean>) => (schema: JSONSchema) => boolean;
52
+ /**
53
+ * Combines multiple testers with OR logic
54
+ */
55
+ export declare const or: (...testers: Array<(schema: JSONSchema) => boolean>) => (schema: JSONSchema) => boolean;
56
+ /**
57
+ * Negates a tester
58
+ */
59
+ export declare const not: (tester: (schema: JSONSchema) => boolean) => (schema: JSONSchema) => boolean;
60
+ //# sourceMappingURL=testers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testers.d.ts","sourceRoot":"","sources":["../src/testers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAmB,MAAM,YAAY,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,EAAE,WAAW,OAAO,KAAG,MAE3D,CAAC;AAEF;;GAEG;AAEH,eAAO,MAAM,YAAY,GAAI,QAAQ,UAAU,KAAG,OAIjD,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,QAAQ,UAAU,KAAG,OAIjD,CAAC;AAEF,eAAO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AEF;;GAEG;AACH,eAAO,MAAM,GAAG,GAAI,GAAG,SAAS,KAAK,CAAC,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,MAC5D,QAAQ,UAAU,KAAG,OAG9B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,EAAE,GAAI,GAAG,SAAS,KAAK,CAAC,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,MAC3D,QAAQ,UAAU,KAAG,OAG9B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,GAAG,GAAI,QAAQ,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,MACjD,QAAQ,UAAU,KAAG,OAG9B,CAAC"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Helper to create a ranked tester
3
+ * Returns rank if predicate is true, -1 otherwise
4
+ */
5
+ export const rankWith = (rank, predicate) => {
6
+ return predicate ? rank : -1;
7
+ };
8
+ /**
9
+ * Basic type testers
10
+ */
11
+ export const isStringType = (schema) => {
12
+ if (schema.type === 'string')
13
+ return true;
14
+ if (schema.const !== undefined && typeof schema.const === 'string')
15
+ return true;
16
+ return false;
17
+ };
18
+ export const isNumberType = (schema) => {
19
+ if (schema.type === 'number' || schema.type === 'integer')
20
+ return true;
21
+ if (schema.const !== undefined && typeof schema.const === 'number')
22
+ return true;
23
+ return false;
24
+ };
25
+ export const isIntegerType = (schema) => {
26
+ return schema.type === 'integer';
27
+ };
28
+ export const isBooleanType = (schema) => {
29
+ if (schema.type === 'boolean')
30
+ return true;
31
+ if (schema.const !== undefined && typeof schema.const === 'boolean')
32
+ return true;
33
+ return false;
34
+ };
35
+ export const isObjectType = (schema) => {
36
+ return schema.type === 'object' || (schema.type === undefined && schema.properties !== undefined);
37
+ };
38
+ export const isArrayType = (schema) => {
39
+ return schema.type === 'array';
40
+ };
41
+ export const isNullType = (schema) => {
42
+ return schema.type === 'null';
43
+ };
44
+ /**
45
+ * Enum tester
46
+ */
47
+ export const isEnumType = (schema) => {
48
+ return Array.isArray(schema.enum) && schema.enum.length > 0;
49
+ };
50
+ /**
51
+ * Format-specific testers
52
+ */
53
+ export const hasFormat = (format) => (schema) => {
54
+ return schema.format === format;
55
+ };
56
+ export const isEmailFormat = (schema) => {
57
+ return isStringType(schema) && schema.format === 'email';
58
+ };
59
+ export const isDateFormat = (schema) => {
60
+ return isStringType(schema) && schema.format === 'date';
61
+ };
62
+ export const isTimeFormat = (schema) => {
63
+ return isStringType(schema) && schema.format === 'time';
64
+ };
65
+ export const isDateTimeFormat = (schema) => {
66
+ return isStringType(schema) && schema.format === 'date-time';
67
+ };
68
+ export const isUrlFormat = (schema) => {
69
+ return isStringType(schema) && (schema.format === 'url' || schema.format === 'uri');
70
+ };
71
+ /**
72
+ * Composition testers
73
+ */
74
+ export const hasOneOf = (schema) => {
75
+ return Array.isArray(schema.oneOf) && schema.oneOf.length > 0;
76
+ };
77
+ export const hasAnyOf = (schema) => {
78
+ return Array.isArray(schema.anyOf) && schema.anyOf.length > 0;
79
+ };
80
+ export const hasAllOf = (schema) => {
81
+ return Array.isArray(schema.allOf) && schema.allOf.length > 0;
82
+ };
83
+ /**
84
+ * Discriminated union tester
85
+ */
86
+ export const isDiscriminatedUnion = (schema) => {
87
+ return hasOneOf(schema) && schema.discriminator !== undefined;
88
+ };
89
+ /**
90
+ * Conditional schema tester
91
+ */
92
+ export const hasConditional = (schema) => {
93
+ return schema.if !== undefined;
94
+ };
95
+ /**
96
+ * Custom extension tester factory
97
+ */
98
+ export const hasExtension = (extensionKey) => (schema) => {
99
+ return schema[extensionKey] !== undefined;
100
+ };
101
+ /**
102
+ * Combines multiple testers with AND logic
103
+ */
104
+ export const and = (...testers) => {
105
+ return (schema) => {
106
+ return testers.every(tester => tester(schema));
107
+ };
108
+ };
109
+ /**
110
+ * Combines multiple testers with OR logic
111
+ */
112
+ export const or = (...testers) => {
113
+ return (schema) => {
114
+ return testers.some(tester => tester(schema));
115
+ };
116
+ };
117
+ /**
118
+ * Negates a tester
119
+ */
120
+ export const not = (tester) => {
121
+ return (schema) => {
122
+ return !tester(schema);
123
+ };
124
+ };
125
+ //# sourceMappingURL=testers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testers.js","sourceRoot":"","sources":["../src/testers.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,SAAkB,EAAU,EAAE;IACnE,OAAO,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF;;GAEG;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAkB,EAAW,EAAE;IAC1D,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC1C,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAChF,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAkB,EAAW,EAAE;IAC1D,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACvE,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAChF,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAkB,EAAW,EAAE;IAC3D,OAAO,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC;AACnC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAkB,EAAW,EAAE;IAC3D,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAC3C,IAAI,MA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ema {
5
+ type?: 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
6
+ title?: string;
7
+ description?: string;
8
+ default?: any;
9
+ const?: any;
10
+ enum?: any[];
11
+ minLength?: number;
12
+ maxLength?: number;
13
+ pattern?: string;
14
+ format?: string;
15
+ minimum?: number;
16
+ maximum?: number;
17
+ exclusiveMinimum?: number;
18
+ exclusiveMaximum?: number;
19
+ multipleOf?: number;
20
+ properties?: Record<string, JSONSchema>;
21
+ required?: string[];
22
+ additionalProperties?: boolean | JSONSchema;
23
+ patternProperties?: Record<string, JSONSchema>;
24
+ minProperties?: number;
25
+ maxProperties?: number;
26
+ items?: JSONSchema | JSONSchema[];
27
+ minItems?: number;
28
+ maxItems?: number;
29
+ uniqueItems?: boolean;
30
+ contains?: JSONSchema;
31
+ allOf?: JSONSchema[];
32
+ anyOf?: JSONSchema[];
33
+ oneOf?: JSONSchema[];
34
+ not?: JSONSchema;
35
+ if?: JSONSchema;
36
+ then?: JSONSchema;
37
+ else?: JSONSchema;
38
+ $ref?: string;
39
+ $defs?: Record<string, JSONSchema>;
40
+ definitions?: Record<string, JSONSchema>;
41
+ discriminator?: {
42
+ propertyName: string;
43
+ mapping?: Record<string, string>;
44
+ };
45
+ [key: `x-${string}`]: any;
46
+ }
47
+ /**
48
+ * UI Schema for layout and presentation hints
49
+ */
50
+ export interface UISchemaElement {
51
+ type: string;
52
+ scope?: string;
53
+ label?: string;
54
+ rule?: Rule;
55
+ options?: Record<string, any>;
56
+ elements?: UISchemaElement[];
57
+ }
58
+ /**
59
+ * Visibility rule for conditional rendering
60
+ */
61
+ export interface Rule {
62
+ effect: 'SHOW' | 'HIDE' | 'ENABLE' | 'DISABLE';
63
+ condition: {
64
+ scope: string;
65
+ schema: JSONSchema;
66
+ };
67
+ }
68
+ /**
69
+ * Component that can be registered in the registry
70
+ */
71
+ export interface FieldComponent<T = any> {
72
+ component: T;
73
+ tester: TesterFunction;
74
+ }
75
+ /**
76
+ * Function that tests if a component should be used for a schema
77
+ * Returns a number indicating priority (higher = better match)
78
+ * Returns -1 if component should not be used
79
+ */
80
+ export type TesterFunction = (schema: JSONSchema, uischema?: UISchemaElement) => number;
81
+ /**
82
+ * Props passed to field renderer components
83
+ */
84
+ export interface RendererProps {
85
+ schema: JSONSchema;
86
+ uischema?: UISchemaElement;
87
+ path: string;
88
+ data: any;
89
+ enabled: boolean;
90
+ visible: boolean;
91
+ errors?: string[];
92
+ handleChange: (path: string, value: any) => void;
93
+ }
94
+ /**
95
+ * Validation error from Ajv
96
+ */
97
+ export interface ValidationError {
98
+ instancePath: string;
99
+ schemaPath: string;
100
+ keyword: string;
101
+ params: Record<string, any>;
102
+ message?: string;
103
+ }
104
+ /**
105
+ * Result from schema validation
106
+ */
107
+ export interface ValidationResult {
108
+ valid: boolean;
109
+ errors: ValidationError[];
110
+ }
111
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,UAAU;IAEzB,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;IACjF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IAGb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,g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AE,GAAG,CAAC,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@quickflo/quickforms",
3
+ "version": "0.1.0",
4
+ "description": "Framework-agnostic core for QuickForms - JSON Schema form generator",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "dev": "tsc --watch",
21
+ "test": "vitest",
22
+ "typecheck": "tsc --noEmit"
23
+ },
24
+ "keywords": [
25
+ "jsonschema",
26
+ "forms",
27
+ "validation"
28
+ ],
29
+ "author": "",
30
+ "license": "MIT",
31
+ "dependencies": {
32
+ "ajv": "^8.12.0",
33
+ "ajv-formats": "^2.1.1"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^20.0.0",
37
+ "typescript": "^5.3.0",
38
+ "vitest": "^1.0.0"
39
+ }
40
+ }