@oxog/vld 2.1.0 → 2.2.5

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.
Files changed (220) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +1296 -1235
  3. package/dist/chunks/errors-core-Cqi4-9ew.js +1 -0
  4. package/dist/chunks/index-CkbfQQ4n.js +1 -0
  5. package/dist/chunks/index-yjpbvFgw.js +1 -0
  6. package/dist/chunks/ip-validation-g5LWgy9t.js +1 -0
  7. package/dist/chunks/security-Dy24T8N7.js +1 -0
  8. package/dist/cjs/chunks/errors-core-DKPohm9I.cjs +1 -0
  9. package/dist/cjs/chunks/index-BEV9nG0N.cjs +1 -0
  10. package/dist/cjs/chunks/index-ZjHAxYdA.cjs +1 -0
  11. package/dist/cjs/chunks/ip-validation-BZqPamPC.cjs +1 -0
  12. package/dist/cjs/chunks/security-aXZVI7qW.cjs +1 -0
  13. package/dist/cjs/cli/bin.cjs +1 -505
  14. package/dist/cjs/cli/index.cjs +1 -209
  15. package/dist/cjs/codecs/index.cjs +1 -45
  16. package/dist/cjs/coercion/index.cjs +1 -588
  17. package/dist/cjs/compat/emitter.cjs +1 -184
  18. package/dist/cjs/compat/result.cjs +1 -189
  19. package/dist/cjs/errors.cjs +1 -180
  20. package/dist/cjs/index.cjs +1 -1894
  21. package/dist/cjs/kernel.cjs +1 -415
  22. package/dist/cjs/locales/af.cjs +1 -108
  23. package/dist/cjs/locales/ar.cjs +1 -108
  24. package/dist/cjs/locales/bn.cjs +1 -108
  25. package/dist/cjs/locales/da.cjs +1 -108
  26. package/dist/cjs/locales/de.cjs +1 -108
  27. package/dist/cjs/locales/en.cjs +1 -108
  28. package/dist/cjs/locales/es-MX.cjs +1 -107
  29. package/dist/cjs/locales/es.cjs +1 -96
  30. package/dist/cjs/locales/fi.cjs +1 -108
  31. package/dist/cjs/locales/fr.cjs +1 -96
  32. package/dist/cjs/locales/hi.cjs +1 -108
  33. package/dist/cjs/locales/id.cjs +1 -108
  34. package/dist/cjs/locales/index.cjs +1 -43
  35. package/dist/cjs/locales/it.cjs +1 -108
  36. package/dist/cjs/locales/ja.cjs +1 -108
  37. package/dist/cjs/locales/ko.cjs +1 -108
  38. package/dist/cjs/locales/lazy.cjs +1 -188
  39. package/dist/cjs/locales/nl.cjs +1 -108
  40. package/dist/cjs/locales/no.cjs +1 -108
  41. package/dist/cjs/locales/pl.cjs +1 -108
  42. package/dist/cjs/locales/pt-BR.cjs +1 -108
  43. package/dist/cjs/locales/pt.cjs +1 -108
  44. package/dist/cjs/locales/ru.cjs +1 -108
  45. package/dist/cjs/locales/runtime.cjs +1 -51
  46. package/dist/cjs/locales/sv.cjs +1 -108
  47. package/dist/cjs/locales/sw.cjs +1 -108
  48. package/dist/cjs/locales/th.cjs +1 -108
  49. package/dist/cjs/locales/tr.cjs +1 -108
  50. package/dist/cjs/locales/vi.cjs +1 -108
  51. package/dist/cjs/locales/zh.cjs +1 -108
  52. package/dist/cjs/mini.cjs +1 -242
  53. package/dist/cjs/pigment.cjs +1 -207
  54. package/dist/cjs/plugins/index.cjs +1 -12
  55. package/dist/cjs/registry.cjs +1 -37
  56. package/dist/cjs/v3/index.cjs +1 -425
  57. package/dist/cjs/v4/core/index.cjs +1 -894
  58. package/dist/cjs/v4/index.cjs +1 -425
  59. package/dist/cjs/v4/locales/index.cjs +1 -130
  60. package/dist/cjs/v4/mini/index.cjs +1 -509
  61. package/dist/cjs/v4-mini/index.cjs +1 -532
  62. package/dist/cjs/validators/any.cjs +1 -40
  63. package/dist/cjs/validators/array.cjs +1 -283
  64. package/dist/cjs/validators/base.cjs +1 -887
  65. package/dist/cjs/validators/base64.cjs +1 -73
  66. package/dist/cjs/validators/bigint.cjs +1 -232
  67. package/dist/cjs/validators/boolean.cjs +1 -146
  68. package/dist/cjs/validators/codec.cjs +1 -205
  69. package/dist/cjs/validators/custom.cjs +1 -71
  70. package/dist/cjs/validators/date.cjs +1 -278
  71. package/dist/cjs/validators/discriminated-union.cjs +1 -130
  72. package/dist/cjs/validators/enum.cjs +1 -154
  73. package/dist/cjs/validators/file.cjs +1 -130
  74. package/dist/cjs/validators/function.cjs +1 -63
  75. package/dist/cjs/validators/hex.cjs +1 -70
  76. package/dist/cjs/validators/index.cjs +1 -123
  77. package/dist/cjs/validators/intersection.cjs +1 -120
  78. package/dist/cjs/validators/json.cjs +1 -70
  79. package/dist/cjs/validators/lazy.cjs +1 -53
  80. package/dist/cjs/validators/literal.cjs +1 -64
  81. package/dist/cjs/validators/map.cjs +1 -218
  82. package/dist/cjs/validators/nan.cjs +1 -41
  83. package/dist/cjs/validators/never.cjs +1 -36
  84. package/dist/cjs/validators/null.cjs +1 -43
  85. package/dist/cjs/validators/number.cjs +1 -427
  86. package/dist/cjs/validators/object.cjs +1 -868
  87. package/dist/cjs/validators/promise.cjs +1 -115
  88. package/dist/cjs/validators/record.cjs +1 -262
  89. package/dist/cjs/validators/set.cjs +1 -203
  90. package/dist/cjs/validators/string-bool.cjs +1 -124
  91. package/dist/cjs/validators/string-formats.cjs +1 -168
  92. package/dist/cjs/validators/string.cjs +1 -12
  93. package/dist/cjs/validators/symbol.cjs +1 -62
  94. package/dist/cjs/validators/template-literal.cjs +1 -108
  95. package/dist/cjs/validators/tuple.cjs +1 -187
  96. package/dist/cjs/validators/uint8array.cjs +1 -106
  97. package/dist/cjs/validators/undefined.cjs +1 -43
  98. package/dist/cjs/validators/union.cjs +1 -191
  99. package/dist/cjs/validators/unknown.cjs +1 -40
  100. package/dist/cjs/validators/void.cjs +1 -48
  101. package/dist/cjs/validators/xor.cjs +1 -69
  102. package/dist/cli/bin.js +1 -406
  103. package/dist/cli/index.js +1 -205
  104. package/dist/codecs/index.js +1 -11
  105. package/dist/coercion/index.js +1 -579
  106. package/dist/compat/emitter.js +1 -180
  107. package/dist/compat/result.js +1 -170
  108. package/dist/errors-core.d.ts +20 -1
  109. package/dist/errors.js +1 -171
  110. package/dist/index.d.ts +248 -357
  111. package/dist/index.js +1 -1534
  112. package/dist/kernel.js +1 -409
  113. package/dist/locales/af.js +1 -106
  114. package/dist/locales/ar.js +1 -106
  115. package/dist/locales/bn.js +1 -106
  116. package/dist/locales/da.js +1 -106
  117. package/dist/locales/de.js +1 -106
  118. package/dist/locales/en.js +1 -106
  119. package/dist/locales/es-MX.js +1 -105
  120. package/dist/locales/es.js +1 -94
  121. package/dist/locales/fi.js +1 -106
  122. package/dist/locales/fr.js +1 -94
  123. package/dist/locales/hi.js +1 -106
  124. package/dist/locales/id.js +1 -106
  125. package/dist/locales/index.js +1 -29
  126. package/dist/locales/it.js +1 -106
  127. package/dist/locales/ja.js +1 -106
  128. package/dist/locales/ko.js +1 -106
  129. package/dist/locales/lazy.js +1 -177
  130. package/dist/locales/nl.js +1 -106
  131. package/dist/locales/no.js +1 -106
  132. package/dist/locales/pl.js +1 -106
  133. package/dist/locales/pt-BR.js +1 -106
  134. package/dist/locales/pt.js +1 -106
  135. package/dist/locales/ru.js +1 -106
  136. package/dist/locales/runtime.js +1 -41
  137. package/dist/locales/sv.js +1 -106
  138. package/dist/locales/sw.js +1 -106
  139. package/dist/locales/th.js +1 -106
  140. package/dist/locales/tr.js +1 -106
  141. package/dist/locales/vi.js +1 -106
  142. package/dist/locales/zh.js +1 -106
  143. package/dist/mini.d.ts +3 -3
  144. package/dist/mini.js +1 -156
  145. package/dist/pigment.js +1 -180
  146. package/dist/plugins/index.js +1 -1
  147. package/dist/registry.js +1 -34
  148. package/dist/utils/json-schema.d.ts +10 -1
  149. package/dist/v3/index.js +1 -46
  150. package/dist/v4/core/index.d.ts +28 -16
  151. package/dist/v4/core/index.js +1 -277
  152. package/dist/v4/index.js +1 -50
  153. package/dist/v4/locales/index.d.ts +4 -0
  154. package/dist/v4/locales/index.js +1 -77
  155. package/dist/v4/mini/index.js +1 -47
  156. package/dist/v4-mini/index.d.ts +1 -1
  157. package/dist/v4-mini/index.js +1 -75
  158. package/dist/validators/any.js +1 -37
  159. package/dist/validators/array.d.ts +7 -0
  160. package/dist/validators/array.js +1 -279
  161. package/dist/validators/base.d.ts +63 -8
  162. package/dist/validators/base.js +1 -868
  163. package/dist/validators/base64.js +1 -68
  164. package/dist/validators/bigint.js +1 -228
  165. package/dist/validators/boolean.js +1 -142
  166. package/dist/validators/codec.js +1 -200
  167. package/dist/validators/custom.js +1 -67
  168. package/dist/validators/date.js +1 -274
  169. package/dist/validators/discriminated-union.d.ts +2 -2
  170. package/dist/validators/discriminated-union.js +1 -123
  171. package/dist/validators/enum.js +1 -150
  172. package/dist/validators/file.js +1 -125
  173. package/dist/validators/function.js +1 -58
  174. package/dist/validators/hex.js +1 -65
  175. package/dist/validators/index.d.ts +1 -1
  176. package/dist/validators/index.js +1 -35
  177. package/dist/validators/intersection.js +1 -116
  178. package/dist/validators/json.js +1 -66
  179. package/dist/validators/lazy.js +1 -50
  180. package/dist/validators/literal.d.ts +7 -3
  181. package/dist/validators/literal.js +1 -60
  182. package/dist/validators/map.js +1 -214
  183. package/dist/validators/nan.js +1 -38
  184. package/dist/validators/never.js +1 -32
  185. package/dist/validators/null.js +1 -40
  186. package/dist/validators/number.d.ts +20 -1
  187. package/dist/validators/number.js +1 -423
  188. package/dist/validators/object.d.ts +12 -2
  189. package/dist/validators/object.js +1 -864
  190. package/dist/validators/promise.js +1 -111
  191. package/dist/validators/record.d.ts +11 -8
  192. package/dist/validators/record.js +1 -258
  193. package/dist/validators/set.js +1 -199
  194. package/dist/validators/string-bool.js +1 -120
  195. package/dist/validators/string-formats.d.ts +58 -62
  196. package/dist/validators/string-formats.js +1 -135
  197. package/dist/validators/string.d.ts +47 -10
  198. package/dist/validators/string.js +1 -4
  199. package/dist/validators/symbol.js +1 -58
  200. package/dist/validators/template-literal.js +1 -103
  201. package/dist/validators/tuple.d.ts +17 -13
  202. package/dist/validators/tuple.js +1 -183
  203. package/dist/validators/uint8array.js +1 -101
  204. package/dist/validators/undefined.js +1 -40
  205. package/dist/validators/union.js +1 -187
  206. package/dist/validators/unknown.js +1 -37
  207. package/dist/validators/void.js +1 -44
  208. package/dist/validators/xor.d.ts +2 -2
  209. package/dist/validators/xor.js +1 -66
  210. package/package.json +239 -238
  211. package/dist/chunks/errors-core-BeiFUtZM.js +0 -81
  212. package/dist/chunks/index-0R2ntSud.js +0 -508
  213. package/dist/chunks/index-BvH403Yy.js +0 -88
  214. package/dist/chunks/security-B0Pd_vSY.js +0 -35
  215. package/dist/chunks/string-BJRQod3t.js +0 -530
  216. package/dist/cjs/chunks/errors-core-DWxLFs2f.cjs +0 -83
  217. package/dist/cjs/chunks/index-BkI37108.cjs +0 -538
  218. package/dist/cjs/chunks/index-Cc3bjUMX.cjs +0 -91
  219. package/dist/cjs/chunks/security-Dc3Jh13T.cjs +0 -37
  220. package/dist/cjs/chunks/string-BKZrc4hs.cjs +0 -533
@@ -1,180 +1 @@
1
- /**
2
- * Event Emitter Implementation
3
- *
4
- * This module provides a type-safe event emitter,
5
- * compatible with @oxog/emitter when available.
6
- */
7
- /**
8
- * Create a type-safe event emitter
9
- */
10
- function createEmitter() {
11
- const listeners = new Map();
12
- const getListeners = (event) => {
13
- if (!listeners.has(event)) {
14
- listeners.set(event, []);
15
- }
16
- return listeners.get(event);
17
- };
18
- const sortListeners = (event) => {
19
- const eventListeners = getListeners(event);
20
- eventListeners.sort((a, b) => b.priority - a.priority);
21
- };
22
- const on = (event, handler, options = {}) => {
23
- const entry = {
24
- handler,
25
- once: options.once ?? false,
26
- priority: options.priority ?? 0
27
- };
28
- getListeners(event).push(entry);
29
- sortListeners(event);
30
- // Return unsubscribe function
31
- return () => off(event, handler);
32
- };
33
- const once = (event, handler) => {
34
- return on(event, handler, { once: true });
35
- };
36
- const off = (event, handler) => {
37
- const eventListeners = listeners.get(event);
38
- if (!eventListeners)
39
- return;
40
- const index = eventListeners.findIndex((entry) => entry.handler === handler);
41
- if (index !== -1) {
42
- eventListeners.splice(index, 1);
43
- }
44
- };
45
- const emit = (event, payload) => {
46
- const eventListeners = listeners.get(event);
47
- if (!eventListeners || eventListeners.length === 0)
48
- return;
49
- // Create a copy to allow modifications during iteration
50
- const listenersToCall = [...eventListeners];
51
- for (const entry of listenersToCall) {
52
- if (entry.once) {
53
- off(event, entry.handler);
54
- }
55
- try {
56
- entry.handler(payload);
57
- }
58
- catch (error) {
59
- // Log error but don't stop other handlers
60
- console.error(`Error in event handler for "${String(event)}":`, error);
61
- }
62
- }
63
- };
64
- const emitAsync = async (event, payload) => {
65
- const eventListeners = listeners.get(event);
66
- if (!eventListeners || eventListeners.length === 0)
67
- return;
68
- // Create a copy to allow modifications during iteration
69
- const listenersToCall = [...eventListeners];
70
- for (const entry of listenersToCall) {
71
- if (entry.once) {
72
- off(event, entry.handler);
73
- }
74
- try {
75
- await entry.handler(payload);
76
- }
77
- catch (error) {
78
- // Log error but don't stop other handlers
79
- console.error(`Error in async event handler for "${String(event)}":`, error);
80
- }
81
- }
82
- };
83
- const removeAllListeners = (event) => {
84
- if (event !== undefined) {
85
- listeners.delete(event);
86
- }
87
- else {
88
- listeners.clear();
89
- }
90
- };
91
- const listenerCount = (event) => {
92
- return listeners.get(event)?.length ?? 0;
93
- };
94
- const eventNames = () => {
95
- return Array.from(listeners.keys()).filter((key) => {
96
- const eventListeners = listeners.get(key);
97
- return eventListeners !== undefined && eventListeners.length > 0;
98
- });
99
- };
100
- return {
101
- on,
102
- once,
103
- off,
104
- emit,
105
- emitAsync,
106
- removeAllListeners,
107
- listenerCount,
108
- eventNames
109
- };
110
- }
111
- /**
112
- * Mixin to add event emitter capabilities to a class
113
- */
114
- function withEmitter() {
115
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
116
- return function (Base) {
117
- return class extends Base {
118
- constructor() {
119
- super(...arguments);
120
- /** @internal */
121
- this._emitter = createEmitter();
122
- }
123
- on(event, handler, options) {
124
- return this._emitter.on(event, handler, options);
125
- }
126
- once(event, handler) {
127
- return this._emitter.once(event, handler);
128
- }
129
- off(event, handler) {
130
- this._emitter.off(event, handler);
131
- }
132
- emit(event, payload) {
133
- this._emitter.emit(event, payload);
134
- }
135
- async emitAsync(event, payload) {
136
- await this._emitter.emitAsync(event, payload);
137
- }
138
- };
139
- };
140
- }
141
- /**
142
- * Create an event bus for global event handling
143
- */
144
- function createEventBus() {
145
- const emitter = createEmitter();
146
- const createScope = () => {
147
- const unsubscribers = [];
148
- const scopedEmitter = {
149
- on: (event, handler, options) => {
150
- const unsubscribe = emitter.on(event, handler, options);
151
- unsubscribers.push(unsubscribe);
152
- return unsubscribe;
153
- },
154
- once: (event, handler) => {
155
- const unsubscribe = emitter.once(event, handler);
156
- unsubscribers.push(unsubscribe);
157
- return unsubscribe;
158
- },
159
- off: emitter.off,
160
- emit: emitter.emit,
161
- emitAsync: emitter.emitAsync,
162
- removeAllListeners: emitter.removeAllListeners,
163
- listenerCount: emitter.listenerCount,
164
- eventNames: emitter.eventNames,
165
- dispose: () => {
166
- for (const unsubscribe of unsubscribers) {
167
- unsubscribe();
168
- }
169
- unsubscribers.length = 0;
170
- }
171
- };
172
- return scopedEmitter;
173
- };
174
- return {
175
- ...emitter,
176
- createScope
177
- };
178
- }
179
-
180
- export { createEmitter, createEventBus, withEmitter };
1
+ function e(){const e=new Map,t=t=>(e.has(t)||e.set(t,[]),e.get(t)),n=(e,n,o={})=>{const s={handler:n,once:o.once??!1,priority:o.priority??0};return t(e).push(s),(e=>{t(e).sort((e,t)=>t.priority-e.priority)})(e),()=>r(e,n)},r=(t,n)=>{const r=e.get(t);if(!r)return;const o=r.findIndex(e=>e.handler===n);-1!==o&&r.splice(o,1)};return{on:n,once:(e,t)=>n(e,t,{once:!0}),off:r,emit:(t,n)=>{const o=e.get(t);if(!o||0===o.length)return;const s=[...o];for(const e of s){e.once&&r(t,e.handler);try{e.handler(n)}catch(e){console.error(`Error in event handler for "${String(t)}":`,e)}}},emitAsync:async(t,n)=>{const o=e.get(t);if(!o||0===o.length)return;const s=[...o];for(const e of s){e.once&&r(t,e.handler);try{await e.handler(n)}catch(e){console.error(`Error in async event handler for "${String(t)}":`,e)}}},removeAllListeners:t=>{void 0!==t?e.delete(t):e.clear()},listenerCount:t=>e.get(t)?.length??0,eventNames:()=>Array.from(e.keys()).filter(t=>{const n=e.get(t);return void 0!==n&&n.length>0})}}function t(){return function(t){return class extends t{constructor(){super(...arguments),this._emitter=e()}on(e,t,n){return this._emitter.on(e,t,n)}once(e,t){return this._emitter.once(e,t)}off(e,t){this._emitter.off(e,t)}emit(e,t){this._emitter.emit(e,t)}async emitAsync(e,t){await this._emitter.emitAsync(e,t)}}}}function n(){const t=e();return{...t,createScope:()=>{const e=[];return{on:(n,r,o)=>{const s=t.on(n,r,o);return e.push(s),s},once:(n,r)=>{const o=t.once(n,r);return e.push(o),o},off:t.off,emit:t.emit,emitAsync:t.emitAsync,removeAllListeners:t.removeAllListeners,listenerCount:t.listenerCount,eventNames:t.eventNames,dispose:()=>{for(const t of e)t();e.length=0}}}}}export{e as createEmitter,n as createEventBus,t as withEmitter};
@@ -1,170 +1 @@
1
- /**
2
- * Result Pattern Implementation
3
- *
4
- * This module provides a Result type for functional error handling,
5
- * compatible with @oxog/types when available.
6
- */
7
- /**
8
- * Create a success result
9
- */
10
- function Ok(data) {
11
- return { success: true, data, value: data };
12
- }
13
- /**
14
- * Create an error result
15
- */
16
- function Err(error) {
17
- return { success: false, error };
18
- }
19
- /**
20
- * Create a success result (alias)
21
- */
22
- const success = Ok;
23
- /**
24
- * Create a failure result (alias)
25
- */
26
- const failure = Err;
27
- /**
28
- * Check if result is Ok
29
- */
30
- function isOk(result) {
31
- return result.success === true;
32
- }
33
- /**
34
- * Check if result is Err
35
- */
36
- function isErr(result) {
37
- return result.success === false;
38
- }
39
- /**
40
- * Check if value is a Result
41
- */
42
- function isResult(value) {
43
- return (typeof value === 'object' &&
44
- value !== null &&
45
- 'success' in value &&
46
- typeof value.success === 'boolean');
47
- }
48
- /**
49
- * Unwrap a result, throwing the error if it's an Err
50
- */
51
- function unwrap(result) {
52
- if (isOk(result)) {
53
- return result.data;
54
- }
55
- throw result.error;
56
- }
57
- /**
58
- * Unwrap a result with a default value
59
- */
60
- function unwrapOr(result, defaultValue) {
61
- if (isOk(result)) {
62
- return result.data;
63
- }
64
- return defaultValue;
65
- }
66
- /**
67
- * Map over a successful result
68
- */
69
- function map(result, fn) {
70
- if (isOk(result)) {
71
- return Ok(fn(result.data));
72
- }
73
- return result;
74
- }
75
- /**
76
- * Map over an error result
77
- */
78
- function mapErr(result, fn) {
79
- if (isErr(result)) {
80
- return Err(fn(result.error));
81
- }
82
- return result;
83
- }
84
- /**
85
- * Chain results (flatMap)
86
- */
87
- function flatMap(result, fn) {
88
- if (isOk(result)) {
89
- return fn(result.data);
90
- }
91
- return result;
92
- }
93
- /**
94
- * Pattern match on a result
95
- */
96
- function match(result, handlers) {
97
- if (isOk(result)) {
98
- return handlers.ok(result.data);
99
- }
100
- return handlers.err(result.error);
101
- }
102
- /**
103
- * Try to execute a function and wrap the result
104
- */
105
- function tryCatch(fn) {
106
- try {
107
- return Ok(fn());
108
- }
109
- catch (error) {
110
- return Err(error instanceof Error ? error : new Error(String(error)));
111
- }
112
- }
113
- /**
114
- * Try to execute an async function and wrap the result
115
- */
116
- async function tryCatchAsync(fn) {
117
- try {
118
- return Ok(await fn());
119
- }
120
- catch (error) {
121
- return Err(error instanceof Error ? error : new Error(String(error)));
122
- }
123
- }
124
- /**
125
- * Combine multiple results into a single result
126
- * Returns Ok with array of values if all succeed, Err with first error otherwise
127
- */
128
- function all(results) {
129
- const values = [];
130
- for (const result of results) {
131
- if (isErr(result)) {
132
- return result;
133
- }
134
- values.push(result.data);
135
- }
136
- return Ok(values);
137
- }
138
- /**
139
- * Convert a nullable value to a Result
140
- */
141
- function fromNullable(value, error = new Error('Value is null or undefined')) {
142
- if (value === null || value === undefined) {
143
- return Err(error);
144
- }
145
- return Ok(value);
146
- }
147
- /**
148
- * Result utilities namespace
149
- */
150
- const ResultUtils = {
151
- Ok,
152
- Err,
153
- success,
154
- failure,
155
- isOk,
156
- isErr,
157
- isResult,
158
- unwrap,
159
- unwrapOr,
160
- map,
161
- mapErr,
162
- flatMap,
163
- match,
164
- tryCatch,
165
- tryCatchAsync,
166
- all,
167
- fromNullable
168
- };
169
-
170
- export { Err, Ok, ResultUtils, all, failure, flatMap, fromNullable, isErr, isOk, isResult, map, mapErr, match, success, tryCatch, tryCatchAsync, unwrap, unwrapOr };
1
+ function r(r){return{success:!0,data:r,value:r}}function n(r){return{success:!1,error:r}}const t=r,u=n;function e(r){return!0===r.success}function c(r){return!1===r.success}function o(r){return"object"==typeof r&&null!==r&&"success"in r&&"boolean"==typeof r.success}function a(r){if(e(r))return r.data;throw r.error}function s(r,n){return e(r)?r.data:n}function i(n,t){return e(n)?r(t(n.data)):n}function f(r,t){return c(r)?n(t(r.error)):r}function l(r,n){return e(r)?n(r.data):r}function d(r,n){return e(r)?n.ok(r.data):n.err(r.error)}function p(t){try{return r(t())}catch(r){return n(r instanceof Error?r:new Error(String(r)))}}async function y(t){try{return r(await t())}catch(r){return n(r instanceof Error?r:new Error(String(r)))}}function E(n){const t=[];for(const r of n){if(c(r))return r;t.push(r.data)}return r(t)}function h(t,u=new Error("Value is null or undefined")){return null==t?n(u):r(t)}const w={Ok:r,Err:n,success:t,failure:u,isOk:e,isErr:c,isResult:o,unwrap:a,unwrapOr:s,map:i,mapErr:f,flatMap:l,match:d,tryCatch:p,tryCatchAsync:y,all:E,fromNullable:h};export{n as Err,r as Ok,w as ResultUtils,E as all,u as failure,l as flatMap,h as fromNullable,c as isErr,e as isOk,o as isResult,i as map,f as mapErr,d as match,t as success,p as tryCatch,y as tryCatchAsync,a as unwrap,s as unwrapOr};
@@ -1,4 +1,4 @@
1
- export type VldErrorCode = 'invalid_type' | 'invalid_string' | 'string_too_small' | 'string_too_big' | 'invalid_email' | 'invalid_url' | 'invalid_uuid' | 'invalid_regex' | 'invalid_number' | 'too_small' | 'too_big' | 'not_integer' | 'not_finite' | 'not_safe' | 'invalid_boolean' | 'invalid_date' | 'invalid_array' | 'invalid_object' | 'unrecognized_keys' | 'invalid_union' | 'invalid_literal' | 'invalid_enum' | 'custom';
1
+ export type VldErrorCode = 'invalid_type' | 'invalid_string' | 'string_too_small' | 'string_too_big' | 'invalid_email' | 'invalid_url' | 'invalid_uuid' | 'invalid_regex' | 'invalid_format' | 'invalid_number' | 'too_small' | 'too_big' | 'not_integer' | 'not_finite' | 'not_safe' | 'not_multiple_of' | 'invalid_boolean' | 'invalid_date' | 'invalid_array' | 'invalid_object' | 'unrecognized_keys' | 'invalid_union' | 'invalid_key' | 'invalid_element' | 'invalid_literal' | 'invalid_value' | 'invalid_enum' | 'custom';
2
2
  export interface VldIssue {
3
3
  code: VldErrorCode;
4
4
  path: (string | number)[];
@@ -10,7 +10,22 @@ export interface VldIssue {
10
10
  maximum?: number;
11
11
  exact?: number;
12
12
  inclusive?: boolean;
13
+ origin?: string;
14
+ format?: string;
15
+ values?: unknown[];
16
+ pattern?: string;
13
17
  }
18
+ /**
19
+ * Map a JavaScript value to Zod 4's type name for `invalid_type` issues.
20
+ * Produces strings like 'string', 'number', 'boolean', 'undefined', 'null',
21
+ * 'array', 'bigint', 'symbol', 'date', 'map', 'set', 'function', 'nan',
22
+ * 'Infinity', '-Infinity', 'object'.
23
+ */
24
+ export declare function getTypeName(value: unknown): string;
25
+ /**
26
+ * Build a Zod 4-compatible `invalid_type` issue.
27
+ */
28
+ export declare function createInvalidTypeIssue(expected: string, received: string, message?: string): VldIssue;
14
29
  export interface VldErrorJSON {
15
30
  name: string;
16
31
  message: string;
@@ -26,6 +41,10 @@ export interface VldErrorJSON {
26
41
  maximum?: number;
27
42
  exact?: number;
28
43
  inclusive?: boolean;
44
+ origin?: string;
45
+ format?: string;
46
+ values?: unknown[];
47
+ pattern?: string;
29
48
  }>;
30
49
  }
31
50
  export declare class VldError extends Error {
package/dist/errors.js CHANGED
@@ -1,171 +1 @@
1
- import { vldTheme } from './pigment.js';
2
- export { V as VldError } from './chunks/errors-core-BeiFUtZM.js';
3
-
4
- // VLD Error System - Advanced error formatting and utilities
5
- /**
6
- * Convert VldError to a nested tree structure
7
- */
8
- function treeifyError(error) {
9
- const tree = { errors: [] };
10
- for (const issue of error.issues) {
11
- let currentNode = tree;
12
- const path = issue.path;
13
- // Navigate to the correct position in the tree
14
- for (let i = 0; i < path.length; i++) {
15
- const segment = path[i];
16
- const isLast = i === path.length - 1;
17
- if (typeof segment === 'string') {
18
- // Object property
19
- if (!currentNode.properties) {
20
- currentNode.properties = {};
21
- }
22
- if (!currentNode.properties[segment]) {
23
- currentNode.properties[segment] = { errors: [] };
24
- }
25
- if (isLast) {
26
- currentNode.properties[segment].errors.push(issue.message);
27
- }
28
- else {
29
- currentNode = currentNode.properties[segment];
30
- }
31
- }
32
- else if (typeof segment === 'number') {
33
- // Array index
34
- if (!currentNode.items) {
35
- currentNode.items = [];
36
- }
37
- while (currentNode.items.length <= segment) {
38
- currentNode.items.push(undefined);
39
- }
40
- if (!currentNode.items[segment]) {
41
- currentNode.items[segment] = { errors: [] };
42
- }
43
- if (isLast) {
44
- currentNode.items[segment].errors.push(issue.message);
45
- }
46
- else {
47
- currentNode = currentNode.items[segment];
48
- }
49
- }
50
- }
51
- // If path is empty, add to root errors
52
- if (path.length === 0) {
53
- tree.errors.push(issue.message);
54
- }
55
- }
56
- return tree;
57
- }
58
- /**
59
- * Convert VldError to human-readable string
60
- */
61
- function prettifyError(error, options = {}) {
62
- const { colored = true, theme = vldTheme, includeCode = false, includeDetails = false } = options;
63
- const lines = [];
64
- for (const issue of error.issues) {
65
- // Symbol and message
66
- const symbol = colored ? theme.symbol('✖') : '✖';
67
- const message = colored ? theme.error(issue.message) : issue.message;
68
- let line = `${symbol} ${message}`;
69
- // Error code
70
- if (includeCode) {
71
- const code = colored ? theme.muted(`[${issue.code}]`) : `[${issue.code}]`;
72
- line += ` ${code}`;
73
- }
74
- // Path
75
- if (issue.path.length > 0) {
76
- const pathStr = issue.path
77
- .map((segment, index) => {
78
- if (typeof segment === 'string') {
79
- const str = index === 0 ? segment : `.${segment}`;
80
- return colored ? theme.path(str) : str;
81
- }
82
- else {
83
- const str = `[${segment}]`;
84
- return colored ? theme.path(str) : str;
85
- }
86
- })
87
- .join('');
88
- const arrow = colored ? theme.muted('→ at ') : '→ at ';
89
- line += `\n ${arrow}${pathStr}`;
90
- }
91
- // Details
92
- if (includeDetails) {
93
- if (issue.expected) {
94
- const expected = colored
95
- ? theme.muted('expected: ') + theme.success(issue.expected)
96
- : `expected: ${issue.expected}`;
97
- line += `\n ${expected}`;
98
- }
99
- if (issue.received) {
100
- const received = colored
101
- ? theme.muted('received: ') + theme.warning(issue.received)
102
- : `received: ${issue.received}`;
103
- line += `\n ${received}`;
104
- }
105
- }
106
- lines.push(line);
107
- }
108
- return lines.join('\n');
109
- }
110
- /**
111
- * Convert VldError to human-readable string with full colors
112
- * Shorthand for prettifyError with colored: true
113
- */
114
- function prettifyErrorColored(error, options = {}) {
115
- return prettifyError(error, { ...options, colored: true });
116
- }
117
- /**
118
- * Convert VldError to plain text string (no colors)
119
- * Shorthand for prettifyError with colored: false
120
- */
121
- function prettifyErrorPlain(error, options = {}) {
122
- return prettifyError(error, { ...options, colored: false });
123
- }
124
- /**
125
- * Flatten VldError for simple form validation
126
- */
127
- function flattenError(error) {
128
- const formErrors = [];
129
- const fieldErrors = {};
130
- for (const issue of error.issues) {
131
- if (issue.path.length === 0) {
132
- formErrors.push(issue.message);
133
- }
134
- else {
135
- const firstPathSegment = issue.path[0];
136
- const fieldName = firstPathSegment.toString();
137
- if (!fieldErrors[fieldName]) {
138
- fieldErrors[fieldName] = [];
139
- }
140
- fieldErrors[fieldName].push(issue.message);
141
- }
142
- }
143
- return { formErrors, fieldErrors };
144
- }
145
- /**
146
- * Create a validation issue
147
- */
148
- function createIssue(code, path, message, extra) {
149
- return {
150
- code,
151
- path: [...path],
152
- message,
153
- ...extra
154
- };
155
- }
156
- /**
157
- * Helper to determine the type of a value for error messages
158
- */
159
- function getValueType(value) {
160
- if (value === null)
161
- return 'null';
162
- if (value === undefined)
163
- return 'undefined';
164
- if (Array.isArray(value))
165
- return 'array';
166
- if (value instanceof Date)
167
- return 'date';
168
- return typeof value;
169
- }
170
-
171
- export { createIssue, flattenError, getValueType, prettifyError, prettifyErrorColored, prettifyErrorPlain, treeifyError };
1
+ import{vldTheme as e}from"./pigment.js";export{V as VldError}from"./chunks/errors-core-Cqi4-9ew.js";function r(e){const r={errors:[]};for(const t of e.issues){let e=r;const s=t.path;for(let r=0;r<s.length;r++){const o=s[r],n=r===s.length-1;if("string"==typeof o)e.properties||(e.properties={}),e.properties[o]||(e.properties[o]={errors:[]}),n?e.properties[o].errors.push(t.message):e=e.properties[o];else if("number"==typeof o){for(e.items||(e.items=[]);e.items.length<=o;)e.items.push(void 0);e.items[o]||(e.items[o]={errors:[]}),n?e.items[o].errors.push(t.message):e=e.items[o]}}0===s.length&&r.errors.push(t.message)}return r}function t(r,t={}){const{colored:s=!0,theme:o=e,includeCode:n=!1,includeDetails:i=!1}=t,c=[];for(const e of r.issues){let r=`${s?o.symbol("✖"):"✖"} ${s?o.error(e.message):e.message}`;if(n){r+=` ${s?o.muted(`[${e.code}]`):`[${e.code}]`}`}if(e.path.length>0){const t=e.path.map((e,r)=>{if("string"==typeof e){const t=0===r?e:`.${e}`;return s?o.path(t):t}{const r=`[${e}]`;return s?o.path(r):r}}).join("");r+=`\n ${s?o.muted("→ at "):"→ at "}${t}`}if(i){if(e.expected){r+=`\n ${s?o.muted("expected: ")+o.success(e.expected):`expected: ${e.expected}`}`}if(e.received){r+=`\n ${s?o.muted("received: ")+o.warning(e.received):`received: ${e.received}`}`}}c.push(r)}return c.join("\n")}function s(e,r={}){return t(e,{...r,colored:!0})}function o(e,r={}){return t(e,{...r,colored:!1})}function n(e){const r=[],t={};for(const s of e.issues)if(0===s.path.length)r.push(s.message);else{const e=s.path[0].toString();t[e]||(t[e]=[]),t[e].push(s.message)}return{formErrors:r,fieldErrors:t}}function i(e,r,t,s){return{code:e,path:[...r],message:t,...s}}function c(e){return null===e?"null":void 0===e?"undefined":Array.isArray(e)?"array":e instanceof Date?"date":typeof e}export{i as createIssue,n as flattenError,c as getValueType,t as prettifyError,s as prettifyErrorColored,o as prettifyErrorPlain,r as treeifyError};