zeed 1.3.0 → 1.4.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/AGENTS.md +50 -211
- package/README.md +16 -0
- package/dist/_experiments/bitcask.cjs +243 -1
- package/dist/_experiments/bitcask.cjs.map +1 -1
- package/dist/_experiments/bitcask.mjs +230 -1
- package/dist/_experiments/bitcask.mjs.map +1 -1
- package/dist/bin-BAoS4qtm.mjs +593 -0
- package/dist/{bin-SPdenYkw.mjs.map → bin-BAoS4qtm.mjs.map} +1 -1
- package/dist/bin-Ddaz2lxM.cjs +862 -0
- package/dist/{bin-Ce3i6ABn.cjs.map → bin-Ddaz2lxM.cjs.map} +1 -1
- package/dist/browser/base64.cjs +14 -1
- package/dist/browser/base64.cjs.map +1 -1
- package/dist/browser/base64.mjs +12 -1
- package/dist/browser/base64.mjs.map +1 -1
- package/dist/browser/gravatar.cjs +186 -1
- package/dist/browser/gravatar.cjs.map +1 -1
- package/dist/browser/gravatar.mjs +184 -1
- package/dist/browser/gravatar.mjs.map +1 -1
- package/dist/browser/index.cjs +14 -1
- package/dist/browser/index.mjs +8 -1
- package/dist/browser/localstorage.cjs +46 -1
- package/dist/browser/localstorage.cjs.map +1 -1
- package/dist/browser/localstorage.mjs +45 -1
- package/dist/browser/localstorage.mjs.map +1 -1
- package/dist/browser/log/index.cjs +8 -1
- package/dist/browser/log/index.mjs +5 -1
- package/dist/browser/log/log-browser-factory.cjs +65 -1
- package/dist/browser/log/log-browser-factory.cjs.map +1 -1
- package/dist/browser/log/log-browser-factory.mjs +64 -1
- package/dist/browser/log/log-browser-factory.mjs.map +1 -1
- package/dist/browser/log/log-browser.cjs +72 -1
- package/dist/browser/log/log-browser.cjs.map +1 -1
- package/dist/browser/log/log-browser.mjs +71 -1
- package/dist/browser/log/log-browser.mjs.map +1 -1
- package/dist/browser/log/log-colors.cjs +11 -1
- package/dist/browser/log/log-colors.cjs.map +1 -1
- package/dist/browser/log/log-colors.mjs +9 -1
- package/dist/browser/log/log-colors.mjs.map +1 -1
- package/dist/browser/log/log-context-browser.cjs +25 -1
- package/dist/browser/log/log-context-browser.cjs.map +1 -1
- package/dist/browser/log/log-context-browser.mjs +23 -1
- package/dist/browser/log/log-context-browser.mjs.map +1 -1
- package/dist/chunk-DQk6qfdC.mjs +18 -0
- package/dist/chunk-uaV2rQ02.cjs +53 -0
- package/dist/common/assert.cjs +22 -1
- package/dist/common/assert.cjs.map +1 -1
- package/dist/common/assert.mjs +19 -1
- package/dist/common/assert.mjs.map +1 -1
- package/dist/common/bin/index.cjs +106 -1
- package/dist/common/bin/index.cjs.map +1 -1
- package/dist/common/bin/index.mjs +98 -1
- package/dist/common/bin/index.mjs.map +1 -1
- package/dist/common/bin/lib0/binary.cjs +146 -1
- package/dist/common/bin/lib0/binary.cjs.map +1 -1
- package/dist/common/bin/lib0/binary.mjs +80 -1
- package/dist/common/bin/lib0/binary.mjs.map +1 -1
- package/dist/common/bin/lib0/buffer.cjs +42 -1
- package/dist/common/bin/lib0/buffer.cjs.map +1 -1
- package/dist/common/bin/lib0/buffer.mjs +38 -1
- package/dist/common/bin/lib0/buffer.mjs.map +1 -1
- package/dist/common/bin/lib0/create.cjs +24 -1
- package/dist/common/bin/lib0/create.cjs.map +1 -1
- package/dist/common/bin/lib0/create.mjs +21 -1
- package/dist/common/bin/lib0/create.mjs.map +1 -1
- package/dist/common/bin/lib0/decoding.cjs +325 -1
- package/dist/common/bin/lib0/decoding.cjs.map +1 -1
- package/dist/common/bin/lib0/decoding.mjs +298 -1
- package/dist/common/bin/lib0/decoding.mjs.map +1 -1
- package/dist/common/bin/lib0/encoding.cjs +404 -1
- package/dist/common/bin/lib0/encoding.cjs.map +1 -1
- package/dist/common/bin/lib0/encoding.mjs +377 -1
- package/dist/common/bin/lib0/encoding.mjs.map +1 -1
- package/dist/common/bin/lib0/string.cjs +81 -1
- package/dist/common/bin/lib0/string.cjs.map +1 -1
- package/dist/common/bin/lib0/string.mjs +71 -1
- package/dist/common/bin/lib0/string.mjs.map +1 -1
- package/dist/common/crypto/aes-sealed.cjs +34 -1
- package/dist/common/crypto/aes-sealed.cjs.map +1 -1
- package/dist/common/crypto/aes-sealed.mjs +32 -1
- package/dist/common/crypto/aes-sealed.mjs.map +1 -1
- package/dist/common/crypto/crypto.cjs +91 -1
- package/dist/common/crypto/crypto.cjs.map +1 -1
- package/dist/common/crypto/crypto.mjs +80 -1
- package/dist/common/crypto/crypto.mjs.map +1 -1
- package/dist/common/crypto/index.cjs +23 -1
- package/dist/common/crypto/index.mjs +5 -1
- package/dist/common/crypto/xaes.cjs +128 -1
- package/dist/common/crypto/xaes.cjs.map +1 -1
- package/dist/common/crypto/xaes.mjs +123 -1
- package/dist/common/crypto/xaes.mjs.map +1 -1
- package/dist/common/csv.cjs +49 -4
- package/dist/common/csv.cjs.map +1 -1
- package/dist/common/csv.mjs +46 -4
- package/dist/common/csv.mjs.map +1 -1
- package/dist/common/data/array.cjs +299 -1
- package/dist/common/data/array.cjs.map +1 -1
- package/dist/common/data/array.mjs +274 -1
- package/dist/common/data/array.mjs.map +1 -1
- package/dist/common/data/basex-secure.cjs +30 -1
- package/dist/common/data/basex-secure.mjs +3 -1
- package/dist/common/data/basex.cjs +163 -1
- package/dist/common/data/basex.cjs.map +1 -1
- package/dist/common/data/basex.mjs +152 -1
- package/dist/common/data/basex.mjs.map +1 -1
- package/dist/common/data/bin-types.mjs +1 -1
- package/dist/common/data/bin.cjs +21 -1
- package/dist/common/data/bin.mjs +3 -1
- package/dist/common/data/camelcase.cjs +27 -1
- package/dist/common/data/camelcase.cjs.map +1 -1
- package/dist/common/data/camelcase.mjs +22 -1
- package/dist/common/data/camelcase.mjs.map +1 -1
- package/dist/common/data/convert.cjs +104 -1
- package/dist/common/data/convert.cjs.map +1 -1
- package/dist/common/data/convert.mjs +88 -1
- package/dist/common/data/convert.mjs.map +1 -1
- package/dist/common/data/datauri.cjs +32 -1
- package/dist/common/data/datauri.cjs.map +1 -1
- package/dist/common/data/datauri.mjs +27 -1
- package/dist/common/data/datauri.mjs.map +1 -1
- package/dist/common/data/day-legacy.cjs +148 -1
- package/dist/common/data/day-legacy.cjs.map +1 -1
- package/dist/common/data/day-legacy.mjs +143 -1
- package/dist/common/data/day-legacy.mjs.map +1 -1
- package/dist/common/data/day.cjs +335 -1
- package/dist/common/data/day.cjs.map +1 -1
- package/dist/common/data/day.mjs +305 -1
- package/dist/common/data/day.mjs.map +1 -1
- package/dist/common/data/decimal.cjs +28 -1
- package/dist/common/data/decimal.cjs.map +1 -1
- package/dist/common/data/decimal.mjs +23 -1
- package/dist/common/data/decimal.mjs.map +1 -1
- package/dist/common/data/deep.cjs +57 -1
- package/dist/common/data/deep.cjs.map +1 -1
- package/dist/common/data/deep.mjs +54 -1
- package/dist/common/data/deep.mjs.map +1 -1
- package/dist/common/data/diff.cjs +62 -1
- package/dist/common/data/diff.cjs.map +1 -1
- package/dist/common/data/diff.mjs +60 -1
- package/dist/common/data/diff.mjs.map +1 -1
- package/dist/common/data/distributed.cjs +24 -1
- package/dist/common/data/distributed.cjs.map +1 -1
- package/dist/common/data/distributed.mjs +22 -1
- package/dist/common/data/distributed.mjs.map +1 -1
- package/dist/common/data/format.cjs +63 -1
- package/dist/common/data/format.cjs.map +1 -1
- package/dist/common/data/format.mjs +59 -1
- package/dist/common/data/format.mjs.map +1 -1
- package/dist/common/data/html.cjs +13 -1
- package/dist/common/data/html.cjs.map +1 -1
- package/dist/common/data/html.mjs +10 -1
- package/dist/common/data/html.mjs.map +1 -1
- package/dist/common/data/index.cjs +296 -1
- package/dist/common/data/index.mjs +37 -1
- package/dist/common/data/is.cjs +106 -1
- package/dist/common/data/is.cjs.map +1 -1
- package/dist/common/data/is.mjs +85 -1
- package/dist/common/data/is.mjs.map +1 -1
- package/dist/common/data/json.cjs +70 -1
- package/dist/common/data/json.cjs.map +1 -1
- package/dist/common/data/json.mjs +65 -1
- package/dist/common/data/json.mjs.map +1 -1
- package/dist/common/data/list.cjs +32 -1
- package/dist/common/data/list.cjs.map +1 -1
- package/dist/common/data/list.mjs +27 -1
- package/dist/common/data/list.mjs.map +1 -1
- package/dist/common/data/lru.mjs +1 -1
- package/dist/common/data/math.cjs +79 -1
- package/dist/common/data/math.cjs.map +1 -1
- package/dist/common/data/math.mjs +65 -1
- package/dist/common/data/math.mjs.map +1 -1
- package/dist/common/data/message.cjs +30 -1
- package/dist/common/data/message.cjs.map +1 -1
- package/dist/common/data/message.mjs +28 -1
- package/dist/common/data/message.mjs.map +1 -1
- package/dist/common/data/object-changes.cjs +66 -1
- package/dist/common/data/object-changes.cjs.map +1 -1
- package/dist/common/data/object-changes.mjs +63 -1
- package/dist/common/data/object-changes.mjs.map +1 -1
- package/dist/common/data/object.cjs +112 -1
- package/dist/common/data/object.cjs.map +1 -1
- package/dist/common/data/object.mjs +104 -1
- package/dist/common/data/object.mjs.map +1 -1
- package/dist/common/data/orderby.cjs +42 -1
- package/dist/common/data/orderby.cjs.map +1 -1
- package/dist/common/data/orderby.mjs +37 -1
- package/dist/common/data/orderby.mjs.map +1 -1
- package/dist/common/data/path.cjs +26 -1
- package/dist/common/data/path.cjs.map +1 -1
- package/dist/common/data/path.mjs +25 -1
- package/dist/common/data/path.mjs.map +1 -1
- package/dist/common/data/regexp.cjs +12 -1
- package/dist/common/data/regexp.cjs.map +1 -1
- package/dist/common/data/regexp.mjs +10 -1
- package/dist/common/data/regexp.mjs.map +1 -1
- package/dist/common/data/rounding.cjs +107 -1
- package/dist/common/data/rounding.cjs.map +1 -1
- package/dist/common/data/rounding.mjs +95 -1
- package/dist/common/data/rounding.mjs.map +1 -1
- package/dist/common/data/signal.cjs +39 -1
- package/dist/common/data/signal.cjs.map +1 -1
- package/dist/common/data/signal.mjs +38 -1
- package/dist/common/data/signal.mjs.map +1 -1
- package/dist/common/data/sortable.cjs +35 -1
- package/dist/common/data/sortable.cjs.map +1 -1
- package/dist/common/data/sortable.mjs +31 -1
- package/dist/common/data/sortable.mjs.map +1 -1
- package/dist/common/data/sorted.cjs +54 -1
- package/dist/common/data/sorted.cjs.map +1 -1
- package/dist/common/data/sorted.mjs +53 -1
- package/dist/common/data/sorted.mjs.map +1 -1
- package/dist/common/data/string-deburr.cjs +240 -1
- package/dist/common/data/string-deburr.cjs.map +1 -1
- package/dist/common/data/string-deburr.mjs +238 -1
- package/dist/common/data/string-deburr.mjs.map +1 -1
- package/dist/common/data/string-hash-fnv.cjs +69 -1
- package/dist/common/data/string-hash-fnv.cjs.map +1 -1
- package/dist/common/data/string-hash-fnv.mjs +67 -1
- package/dist/common/data/string-hash-fnv.mjs.map +1 -1
- package/dist/common/data/string-hash-pool.cjs +28 -1
- package/dist/common/data/string-hash-pool.cjs.map +1 -1
- package/dist/common/data/string-hash-pool.mjs +27 -1
- package/dist/common/data/string-hash-pool.mjs.map +1 -1
- package/dist/common/data/url.cjs +98 -2
- package/dist/common/data/url.cjs.map +1 -1
- package/dist/common/data/url.mjs +91 -2
- package/dist/common/data/url.mjs.map +1 -1
- package/dist/common/data/utils.cjs +118 -1
- package/dist/common/data/utils.cjs.map +1 -1
- package/dist/common/data/utils.mjs +107 -1
- package/dist/common/data/utils.mjs.map +1 -1
- package/dist/common/data/wordlist.cjs +531 -1
- package/dist/common/data/wordlist.cjs.map +1 -1
- package/dist/common/data/wordlist.mjs +529 -1
- package/dist/common/data/wordlist.mjs.map +1 -1
- package/dist/common/data/xrx.cjs +96 -1
- package/dist/common/data/xrx.cjs.map +1 -1
- package/dist/common/data/xrx.mjs +92 -1
- package/dist/common/data/xrx.mjs.map +1 -1
- package/dist/common/dispose-defer.cjs +133 -1
- package/dist/common/dispose-defer.cjs.map +1 -1
- package/dist/common/dispose-defer.mjs +130 -1
- package/dist/common/dispose-defer.mjs.map +1 -1
- package/dist/common/dispose-types.mjs +1 -1
- package/dist/common/dispose-utils.cjs +113 -1
- package/dist/common/dispose-utils.cjs.map +1 -1
- package/dist/common/dispose-utils.mjs +106 -1
- package/dist/common/dispose-utils.mjs.map +1 -1
- package/dist/common/exec/index.cjs +24 -1
- package/dist/common/exec/index.d.cts +1 -1
- package/dist/common/exec/index.d.mts +1 -1
- package/dist/common/exec/index.mjs +8 -1
- package/dist/common/exec/mutex.cjs +44 -1
- package/dist/common/exec/mutex.cjs.map +1 -1
- package/dist/common/exec/mutex.mjs +42 -1
- package/dist/common/exec/mutex.mjs.map +1 -1
- package/dist/common/exec/pool.cjs +181 -1
- package/dist/common/exec/pool.cjs.map +1 -1
- package/dist/common/exec/pool.d.cts +1 -1
- package/dist/common/exec/pool.d.mts +1 -1
- package/dist/common/exec/pool.mjs +180 -1
- package/dist/common/exec/pool.mjs.map +1 -1
- package/dist/common/exec/progress.cjs +149 -1
- package/dist/common/exec/progress.cjs.map +1 -1
- package/dist/common/exec/progress.d.cts +1 -1
- package/dist/common/exec/progress.d.mts +1 -1
- package/dist/common/exec/progress.mjs +148 -1
- package/dist/common/exec/progress.mjs.map +1 -1
- package/dist/common/exec/promise.cjs +113 -1
- package/dist/common/exec/promise.cjs.map +1 -1
- package/dist/common/exec/promise.mjs +103 -1
- package/dist/common/exec/promise.mjs.map +1 -1
- package/dist/common/exec/queue.cjs +125 -1
- package/dist/common/exec/queue.cjs.map +1 -1
- package/dist/common/exec/queue.d.cts +1 -1
- package/dist/common/exec/queue.d.mts +1 -1
- package/dist/common/exec/queue.mjs +124 -1
- package/dist/common/exec/queue.mjs.map +1 -1
- package/dist/common/exec/throttle-debounce.cjs +114 -1
- package/dist/common/exec/throttle-debounce.cjs.map +1 -1
- package/dist/common/exec/throttle-debounce.mjs +112 -1
- package/dist/common/exec/throttle-debounce.mjs.map +1 -1
- package/dist/common/global.cjs +22 -1
- package/dist/common/global.cjs.map +1 -1
- package/dist/common/global.mjs +19 -1
- package/dist/common/global.mjs.map +1 -1
- package/dist/common/index.cjs +559 -1
- package/dist/common/index.d.cts +1 -1
- package/dist/common/index.d.mts +1 -1
- package/dist/common/index.mjs +89 -1
- package/dist/common/localhost.cjs +16 -1
- package/dist/common/localhost.cjs.map +1 -1
- package/dist/common/localhost.mjs +14 -1
- package/dist/common/localhost.mjs.map +1 -1
- package/dist/common/log/index.cjs +34 -1
- package/dist/common/log/index.mjs +11 -1
- package/dist/common/log/log-base.cjs +40 -1
- package/dist/common/log/log-base.cjs.map +1 -1
- package/dist/common/log/log-base.mjs +31 -1
- package/dist/common/log/log-base.mjs.map +1 -1
- package/dist/common/log/log-colors.cjs +92 -1
- package/dist/common/log/log-colors.cjs.map +1 -1
- package/dist/common/log/log-colors.mjs +90 -1
- package/dist/common/log/log-colors.mjs.map +1 -1
- package/dist/common/log/log-config.cjs +15 -1
- package/dist/common/log/log-config.cjs.map +1 -1
- package/dist/common/log/log-config.mjs +14 -1
- package/dist/common/log/log-config.mjs.map +1 -1
- package/dist/common/log/log-console-capture.cjs +33 -1
- package/dist/common/log/log-console-capture.cjs.map +1 -1
- package/dist/common/log/log-console-capture.mjs +32 -1
- package/dist/common/log/log-console-capture.mjs.map +1 -1
- package/dist/common/log/log-console-original.cjs +27 -1
- package/dist/common/log/log-console-original.cjs.map +1 -1
- package/dist/common/log/log-console-original.mjs +26 -1
- package/dist/common/log/log-console-original.mjs.map +1 -1
- package/dist/common/log/log-console.cjs +39 -1
- package/dist/common/log/log-console.cjs.map +1 -1
- package/dist/common/log/log-console.mjs +38 -1
- package/dist/common/log/log-console.mjs.map +1 -1
- package/dist/common/log/log-context.cjs +109 -1
- package/dist/common/log/log-context.cjs.map +1 -1
- package/dist/common/log/log-context.mjs +108 -1
- package/dist/common/log/log-context.mjs.map +1 -1
- package/dist/common/log/log-filter.cjs +80 -1
- package/dist/common/log/log-filter.cjs.map +1 -1
- package/dist/common/log/log-filter.mjs +75 -1
- package/dist/common/log/log-filter.mjs.map +1 -1
- package/dist/common/log/log-memory.cjs +45 -1
- package/dist/common/log/log-memory.cjs.map +1 -1
- package/dist/common/log/log-memory.mjs +43 -1
- package/dist/common/log/log-memory.mjs.map +1 -1
- package/dist/common/log/log-noop.cjs +17 -1
- package/dist/common/log/log-noop.cjs.map +1 -1
- package/dist/common/log/log-noop.mjs +15 -1
- package/dist/common/log/log-noop.mjs.map +1 -1
- package/dist/common/log/log.cjs +46 -1
- package/dist/common/log/log.cjs.map +1 -1
- package/dist/common/log/log.mjs +43 -1
- package/dist/common/log/log.mjs.map +1 -1
- package/dist/common/msg/channel-debug.cjs +17 -1
- package/dist/common/msg/channel-debug.cjs.map +1 -1
- package/dist/common/msg/channel-debug.d.cts +1 -1
- package/dist/common/msg/channel-debug.d.mts +1 -1
- package/dist/common/msg/channel-debug.mjs +16 -1
- package/dist/common/msg/channel-debug.mjs.map +1 -1
- package/dist/common/msg/channel-local.cjs +28 -1
- package/dist/common/msg/channel-local.cjs.map +1 -1
- package/dist/common/msg/channel-local.d.cts +1 -1
- package/dist/common/msg/channel-local.d.mts +1 -1
- package/dist/common/msg/channel-local.mjs +26 -1
- package/dist/common/msg/channel-local.mjs.map +1 -1
- package/dist/common/msg/channel-resilient.cjs +63 -1
- package/dist/common/msg/channel-resilient.cjs.map +1 -1
- package/dist/common/msg/channel-resilient.d.cts +1 -1
- package/dist/common/msg/channel-resilient.d.mts +1 -1
- package/dist/common/msg/channel-resilient.mjs +62 -1
- package/dist/common/msg/channel-resilient.mjs.map +1 -1
- package/dist/common/msg/channel-wkwebview.cjs +35 -1
- package/dist/common/msg/channel-wkwebview.cjs.map +1 -1
- package/dist/common/msg/channel-wkwebview.d.cts +2 -1
- package/dist/common/msg/channel-wkwebview.d.mts +2 -1
- package/dist/common/msg/channel-wkwebview.mjs +34 -1
- package/dist/common/msg/channel-wkwebview.mjs.map +1 -1
- package/dist/common/msg/channel.cjs +23 -1
- package/dist/common/msg/channel.cjs.map +1 -1
- package/dist/common/msg/channel.d.cts +1 -1
- package/dist/common/msg/channel.d.mts +1 -1
- package/dist/common/msg/channel.mjs +22 -1
- package/dist/common/msg/channel.mjs.map +1 -1
- package/dist/common/msg/emitter.cjs +141 -1
- package/dist/common/msg/emitter.cjs.map +1 -1
- package/dist/common/msg/emitter.d.cts +1 -1
- package/dist/common/msg/emitter.d.mts +1 -1
- package/dist/common/msg/emitter.mjs +139 -1
- package/dist/common/msg/emitter.mjs.map +1 -1
- package/dist/common/msg/encoder.cjs +38 -1
- package/dist/common/msg/encoder.cjs.map +1 -1
- package/dist/common/msg/encoder.mjs +35 -1
- package/dist/common/msg/encoder.mjs.map +1 -1
- package/dist/common/msg/index.cjs +28 -1
- package/dist/common/msg/index.d.cts +1 -1
- package/dist/common/msg/index.d.mts +1 -1
- package/dist/common/msg/index.mjs +11 -1
- package/dist/common/msg/messages.cjs +135 -1
- package/dist/common/msg/messages.cjs.map +1 -1
- package/dist/common/msg/messages.d.cts +1 -1
- package/dist/common/msg/messages.d.mts +1 -1
- package/dist/common/msg/messages.mjs +133 -1
- package/dist/common/msg/messages.mjs.map +1 -1
- package/dist/common/msg/pipe.mjs +1 -1
- package/dist/common/msg/pubsub.cjs +78 -1
- package/dist/common/msg/pubsub.cjs.map +1 -1
- package/dist/common/msg/pubsub.d.cts +1 -1
- package/dist/common/msg/pubsub.d.mts +1 -1
- package/dist/common/msg/pubsub.mjs +76 -1
- package/dist/common/msg/pubsub.mjs.map +1 -1
- package/dist/common/msg/rpc.cjs +142 -1
- package/dist/common/msg/rpc.cjs.map +1 -1
- package/dist/common/msg/rpc.mjs +139 -1
- package/dist/common/msg/rpc.mjs.map +1 -1
- package/dist/common/network.cjs +129 -1
- package/dist/common/network.cjs.map +1 -1
- package/dist/common/network.mjs +122 -1
- package/dist/common/network.mjs.map +1 -1
- package/dist/common/platform.cjs +92 -1
- package/dist/common/platform.cjs.map +1 -1
- package/dist/common/platform.mjs +84 -1
- package/dist/common/platform.mjs.map +1 -1
- package/dist/common/schema/_sandbox/sandbox-inherit.mjs +1 -1
- package/dist/common/schema/_sandbox/sandbox.mjs +1 -1
- package/dist/common/schema/_sandbox/sandbox.xspec.mjs +1 -1
- package/dist/common/schema/export-json-schema.cjs +54 -1
- package/dist/common/schema/export-json-schema.cjs.map +1 -1
- package/dist/common/schema/export-json-schema.mjs +52 -1
- package/dist/common/schema/export-json-schema.mjs.map +1 -1
- package/dist/common/schema/export-swift.cjs +30 -2
- package/dist/common/schema/export-swift.cjs.map +1 -1
- package/dist/common/schema/export-swift.mjs +29 -2
- package/dist/common/schema/export-swift.mjs.map +1 -1
- package/dist/common/schema/export-typescript.cjs +20 -2
- package/dist/common/schema/export-typescript.cjs.map +1 -1
- package/dist/common/schema/export-typescript.mjs +19 -2
- package/dist/common/schema/export-typescript.mjs.map +1 -1
- package/dist/common/schema/index.cjs +55 -1
- package/dist/common/schema/index.mjs +12 -1
- package/dist/common/schema/parse-args.cjs +62 -2
- package/dist/common/schema/parse-args.cjs.map +1 -1
- package/dist/common/schema/parse-args.mjs +60 -2
- package/dist/common/schema/parse-args.mjs.map +1 -1
- package/dist/common/schema/parse-env.cjs +48 -3
- package/dist/common/schema/parse-env.cjs.map +1 -1
- package/dist/common/schema/parse-env.mjs +46 -3
- package/dist/common/schema/parse-env.mjs.map +1 -1
- package/dist/common/schema/parse-object.cjs +122 -1
- package/dist/common/schema/parse-object.cjs.map +1 -1
- package/dist/common/schema/parse-object.mjs +119 -1
- package/dist/common/schema/parse-object.mjs.map +1 -1
- package/dist/common/schema/schema-standard.mjs +1 -1
- package/dist/common/schema/schema.cjs +423 -1
- package/dist/common/schema/schema.cjs.map +1 -1
- package/dist/common/schema/schema.mjs +404 -1
- package/dist/common/schema/schema.mjs.map +1 -1
- package/dist/common/schema/serialize.cjs +109 -1
- package/dist/common/schema/serialize.cjs.map +1 -1
- package/dist/common/schema/serialize.mjs +107 -1
- package/dist/common/schema/serialize.mjs.map +1 -1
- package/dist/common/schema/type-test.mjs +1 -1
- package/dist/common/schema/utils.cjs +25 -1
- package/dist/common/schema/utils.cjs.map +1 -1
- package/dist/common/schema/utils.mjs +19 -1
- package/dist/common/schema/utils.mjs.map +1 -1
- package/dist/common/schema/z-collection.cjs +51 -1
- package/dist/common/schema/z-collection.mjs +27 -1
- package/dist/common/schema/z.cjs +9 -1
- package/dist/common/schema/z.mjs +3 -1
- package/dist/common/storage/index.cjs +4 -1
- package/dist/common/storage/index.mjs +3 -1
- package/dist/common/storage/memstorage.cjs +26 -1
- package/dist/common/storage/memstorage.cjs.map +1 -1
- package/dist/common/storage/memstorage.mjs +25 -1
- package/dist/common/storage/memstorage.mjs.map +1 -1
- package/dist/common/test.cjs +14 -1
- package/dist/common/test.cjs.map +1 -1
- package/dist/common/test.mjs +13 -1
- package/dist/common/test.mjs.map +1 -1
- package/dist/common/time.cjs +220 -1
- package/dist/common/time.cjs.map +1 -1
- package/dist/common/time.mjs +194 -1
- package/dist/common/time.mjs.map +1 -1
- package/dist/common/timeout.cjs +27 -1
- package/dist/common/timeout.cjs.map +1 -1
- package/dist/common/timeout.mjs +25 -1
- package/dist/common/timeout.mjs.map +1 -1
- package/dist/common/types.mjs +1 -1
- package/dist/common/utils.cjs +7 -1
- package/dist/common/utils.cjs.map +1 -1
- package/dist/common/utils.mjs +5 -1
- package/dist/common/utils.mjs.map +1 -1
- package/dist/common/uuid.cjs +307 -1
- package/dist/common/uuid.cjs.map +1 -1
- package/dist/common/uuid.mjs +284 -1
- package/dist/common/uuid.mjs.map +1 -1
- package/dist/{index-DHXVOH8h.d.cts → index-CFkMqHvX.d.cts} +1 -2
- package/dist/{index-DMaPyx9O.d.mts → index-C_3Y_s6f.d.mts} +1 -2
- package/dist/index.all.cjs +641 -1
- package/dist/index.all.d.cts +1 -1
- package/dist/index.all.d.mts +1 -1
- package/dist/index.all.mjs +113 -1
- package/dist/index.browser.cjs +576 -1
- package/dist/index.browser.d.cts +1 -1
- package/dist/index.browser.d.mts +1 -1
- package/dist/index.browser.mjs +98 -1
- package/dist/index.jsr.cjs +57 -1
- package/dist/index.jsr.mjs +6 -1
- package/dist/index.node.cjs +628 -1
- package/dist/index.node.d.cts +1 -1
- package/dist/index.node.d.mts +1 -1
- package/dist/index.node.mjs +106 -1
- package/dist/node/args.cjs +56 -1
- package/dist/node/args.cjs.map +1 -1
- package/dist/node/args.mjs +53 -1
- package/dist/node/args.mjs.map +1 -1
- package/dist/node/clipboard.cjs +18 -1
- package/dist/node/clipboard.cjs.map +1 -1
- package/dist/node/clipboard.mjs +16 -1
- package/dist/node/clipboard.mjs.map +1 -1
- package/dist/node/crypto.cjs +28 -1
- package/dist/node/crypto.cjs.map +1 -1
- package/dist/node/crypto.mjs +24 -1
- package/dist/node/crypto.mjs.map +1 -1
- package/dist/node/env.cjs +100 -4
- package/dist/node/env.cjs.map +1 -1
- package/dist/node/env.mjs +90 -4
- package/dist/node/env.mjs.map +1 -1
- package/dist/node/files-async.cjs +66 -1
- package/dist/node/files-async.cjs.map +1 -1
- package/dist/node/files-async.mjs +60 -1
- package/dist/node/files-async.mjs.map +1 -1
- package/dist/node/files.cjs +52 -1
- package/dist/node/files.cjs.map +1 -1
- package/dist/node/files.mjs +46 -1
- package/dist/node/files.mjs.map +1 -1
- package/dist/node/filestorage.cjs +100 -1
- package/dist/node/filestorage.cjs.map +1 -1
- package/dist/node/filestorage.mjs +97 -1
- package/dist/node/filestorage.mjs.map +1 -1
- package/dist/node/fs.cjs +119 -1
- package/dist/node/fs.cjs.map +1 -1
- package/dist/node/fs.mjs +101 -1
- package/dist/node/fs.mjs.map +1 -1
- package/dist/node/glob.cjs +75 -1
- package/dist/node/glob.cjs.map +1 -1
- package/dist/node/glob.mjs +73 -1
- package/dist/node/glob.mjs.map +1 -1
- package/dist/node/index.cjs +66 -1
- package/dist/node/index.mjs +16 -1
- package/dist/node/log/index.cjs +20 -1
- package/dist/node/log/index.mjs +7 -1
- package/dist/node/log/log-context-node.cjs +39 -1
- package/dist/node/log/log-context-node.cjs.map +1 -1
- package/dist/node/log/log-context-node.mjs +35 -1
- package/dist/node/log/log-context-node.mjs.map +1 -1
- package/dist/node/log/log-file-rotation.cjs +71 -1
- package/dist/node/log/log-file-rotation.cjs.map +1 -1
- package/dist/node/log/log-file-rotation.mjs +68 -1
- package/dist/node/log/log-file-rotation.mjs.map +1 -1
- package/dist/node/log/log-file.cjs +57 -1
- package/dist/node/log/log-file.cjs.map +1 -1
- package/dist/node/log/log-file.mjs +54 -1
- package/dist/node/log/log-file.mjs.map +1 -1
- package/dist/node/log/log-node.cjs +162 -1
- package/dist/node/log/log-node.cjs.map +1 -1
- package/dist/node/log/log-node.mjs +155 -1
- package/dist/node/log/log-node.mjs.map +1 -1
- package/dist/node/log/log-rotation.cjs +543 -3
- package/dist/node/log/log-rotation.cjs.map +1 -1
- package/dist/node/log/log-rotation.mjs +538 -3
- package/dist/node/log/log-rotation.mjs.map +1 -1
- package/dist/node/log/log-util.cjs +69 -3
- package/dist/node/log/log-util.cjs.map +1 -1
- package/dist/node/log/log-util.mjs +63 -3
- package/dist/node/log/log-util.mjs.map +1 -1
- package/dist/node/open-browser.cjs +20 -1
- package/dist/node/open-browser.cjs.map +1 -1
- package/dist/node/open-browser.mjs +18 -1
- package/dist/node/open-browser.mjs.map +1 -1
- package/package.json +15 -15
- package/src/common/schema/README.md +247 -66
- package/src/eslint-defaults.js +4 -0
- package/src/index.spec.ts +6 -6
- package/dist/bin-Ce3i6ABn.cjs +0 -3
- package/dist/bin-SPdenYkw.mjs +0 -3
- package/dist/chunk-0Lt9GpW0.mjs +0 -1
- package/dist/chunk-D-qHiVGv.cjs +0 -1
- package/src/common/schema/README-SCHEMA.md +0 -0
|
@@ -1,2 +1,405 @@
|
|
|
1
|
-
import{isArray
|
|
1
|
+
import { isArray, isBoolean, isFunction, isInteger, isNumber, isObject, isString } from "../data/is.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/common/schema/schema.ts
|
|
4
|
+
/**
|
|
5
|
+
* Core Type class for schema validation and type inference
|
|
6
|
+
* Implements StandardSchemaV1 for cross-library compatibility
|
|
7
|
+
*/
|
|
8
|
+
var Type = class Type {
|
|
9
|
+
type;
|
|
10
|
+
_default;
|
|
11
|
+
_optional;
|
|
12
|
+
_meta;
|
|
13
|
+
_check;
|
|
14
|
+
_object;
|
|
15
|
+
_type;
|
|
16
|
+
_union;
|
|
17
|
+
_enumValues;
|
|
18
|
+
_args;
|
|
19
|
+
_ret;
|
|
20
|
+
_info;
|
|
21
|
+
constructor(name, options = {}) {
|
|
22
|
+
this.type = name;
|
|
23
|
+
Object.assign(this, options);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Standard Schema V1 compliance property
|
|
27
|
+
* Provides a standard interface for validation and type inference
|
|
28
|
+
*/
|
|
29
|
+
get "~standard"() {
|
|
30
|
+
return {
|
|
31
|
+
version: 1,
|
|
32
|
+
vendor: "zeed",
|
|
33
|
+
validate: (value) => {
|
|
34
|
+
return this.validate(value);
|
|
35
|
+
},
|
|
36
|
+
types: {
|
|
37
|
+
input: void 0,
|
|
38
|
+
output: void 0
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Validation method for standard-schema compliance
|
|
44
|
+
*/
|
|
45
|
+
validate(value) {
|
|
46
|
+
if (value == null) {
|
|
47
|
+
if (this._optional) return { value: void 0 };
|
|
48
|
+
if (this._default !== void 0) return { value: isFunction(this._default) ? this._default(this) : this._default };
|
|
49
|
+
return { issues: [{
|
|
50
|
+
message: `Required value is missing`,
|
|
51
|
+
path: []
|
|
52
|
+
}] };
|
|
53
|
+
}
|
|
54
|
+
if (this.type === "literal" && this._default !== value) return { issues: [{
|
|
55
|
+
message: `Expected literal value ${this._default}, got ${value}`,
|
|
56
|
+
path: []
|
|
57
|
+
}] };
|
|
58
|
+
if (this._enumValues && Array.isArray(this._enumValues)) {
|
|
59
|
+
if (!this._enumValues.includes(value)) return { issues: [{
|
|
60
|
+
message: `Expected one of [${this._enumValues.join(", ")}], got ${value}`,
|
|
61
|
+
path: []
|
|
62
|
+
}] };
|
|
63
|
+
}
|
|
64
|
+
if (this._union && Array.isArray(this._union)) {
|
|
65
|
+
for (const option of this._union) {
|
|
66
|
+
const result = option.validate(value);
|
|
67
|
+
if (!result.issues) return result;
|
|
68
|
+
}
|
|
69
|
+
return { issues: [{
|
|
70
|
+
message: `Value does not match any union variant`,
|
|
71
|
+
path: []
|
|
72
|
+
}] };
|
|
73
|
+
}
|
|
74
|
+
if (this.type === "array" || this.type === "tuple") {
|
|
75
|
+
if (!Array.isArray(value)) return { issues: [{
|
|
76
|
+
message: `Expected array, got ${typeof value}`,
|
|
77
|
+
path: []
|
|
78
|
+
}] };
|
|
79
|
+
if (this.type === "tuple" && this._type) {
|
|
80
|
+
const items = this._type;
|
|
81
|
+
if (value.length !== items.length) return { issues: [{
|
|
82
|
+
message: `Expected tuple of length ${items.length}, got ${value.length}`,
|
|
83
|
+
path: []
|
|
84
|
+
}] };
|
|
85
|
+
const issues = [];
|
|
86
|
+
for (let i = 0; i < items.length; i++) {
|
|
87
|
+
const itemResult = items[i].validate(value[i]);
|
|
88
|
+
if (itemResult.issues) for (const issue of itemResult.issues) issues.push({
|
|
89
|
+
message: issue.message,
|
|
90
|
+
path: [i, ...issue.path || []]
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (issues.length > 0) return { issues };
|
|
94
|
+
} else if (this._type) {
|
|
95
|
+
const itemType = this._type;
|
|
96
|
+
const issues = [];
|
|
97
|
+
for (let i = 0; i < value.length; i++) {
|
|
98
|
+
const itemResult = itemType.validate(value[i]);
|
|
99
|
+
if (itemResult.issues) for (const issue of itemResult.issues) issues.push({
|
|
100
|
+
message: issue.message,
|
|
101
|
+
path: [i, ...issue.path || []]
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (issues.length > 0) return { issues };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (this._object) {
|
|
108
|
+
if (!isObject(value)) return { issues: [{
|
|
109
|
+
message: `Expected object, got ${typeof value}`,
|
|
110
|
+
path: []
|
|
111
|
+
}] };
|
|
112
|
+
const issues = [];
|
|
113
|
+
const obj = value;
|
|
114
|
+
for (const key in this._object) {
|
|
115
|
+
const propSchema = this._object[key];
|
|
116
|
+
const propValue = obj[key];
|
|
117
|
+
const propResult = propSchema.validate(propValue);
|
|
118
|
+
if (propResult.issues) for (const issue of propResult.issues) issues.push({
|
|
119
|
+
message: issue.message,
|
|
120
|
+
path: [key, ...issue.path || []]
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (issues.length > 0) return { issues };
|
|
124
|
+
return {
|
|
125
|
+
value,
|
|
126
|
+
issues: void 0
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (this.type === "record" && this._type) {
|
|
130
|
+
if (!isObject(value)) return { issues: [{
|
|
131
|
+
message: `Expected object, got ${typeof value}`,
|
|
132
|
+
path: []
|
|
133
|
+
}] };
|
|
134
|
+
const valueType = this._type;
|
|
135
|
+
const issues = [];
|
|
136
|
+
const obj = value;
|
|
137
|
+
for (const key in obj) {
|
|
138
|
+
const propResult = valueType.validate(obj[key]);
|
|
139
|
+
if (propResult.issues) for (const issue of propResult.issues) issues.push({
|
|
140
|
+
message: issue.message,
|
|
141
|
+
path: [key, ...issue.path || []]
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (issues.length > 0) return { issues };
|
|
145
|
+
}
|
|
146
|
+
if (this._check && !this._check(value)) return { issues: [{
|
|
147
|
+
message: `Expected ${this.type}, got ${typeof value}`,
|
|
148
|
+
path: []
|
|
149
|
+
}] };
|
|
150
|
+
return { value };
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Creates a copy of the type with new properties merged
|
|
154
|
+
*/
|
|
155
|
+
_cloneWithProps(newProps = {}) {
|
|
156
|
+
const cloned = new Type(this.type);
|
|
157
|
+
for (const prop of [
|
|
158
|
+
"_default",
|
|
159
|
+
"_optional",
|
|
160
|
+
"_meta",
|
|
161
|
+
"_check",
|
|
162
|
+
"_object",
|
|
163
|
+
"_type",
|
|
164
|
+
"_union",
|
|
165
|
+
"_enumValues",
|
|
166
|
+
"_args",
|
|
167
|
+
"_ret",
|
|
168
|
+
"_info"
|
|
169
|
+
]) if (this[prop] !== void 0) cloned[prop] = this[prop];
|
|
170
|
+
Object.assign(cloned, newProps);
|
|
171
|
+
return cloned;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Helper to copy type properties when creating new type instances
|
|
175
|
+
*/
|
|
176
|
+
static _copyTypeProperties(source, target) {
|
|
177
|
+
for (const prop of [
|
|
178
|
+
"_check",
|
|
179
|
+
"_default",
|
|
180
|
+
"_meta",
|
|
181
|
+
"_object",
|
|
182
|
+
"_type",
|
|
183
|
+
"_enumValues"
|
|
184
|
+
]) if (source[prop] !== void 0) target[prop] = source[prop];
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Marks the type as optional, meaning it can be undefined
|
|
188
|
+
* This is useful for properties that are not required.
|
|
189
|
+
*/
|
|
190
|
+
optional() {
|
|
191
|
+
return this._cloneWithProps({ _optional: true });
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Sets a default value for the type, which will be used if the value is not provided
|
|
195
|
+
* The default value can be a function that receives the schema as argument, or a static value.
|
|
196
|
+
*/
|
|
197
|
+
default(value) {
|
|
198
|
+
return this._cloneWithProps({ _default: value });
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Props / Metadata for the type, like description or other properties
|
|
202
|
+
*/
|
|
203
|
+
meta(meta) {
|
|
204
|
+
return this._cloneWithProps({ _meta: meta });
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Sets the `desc` property for the type, which is a human-readable description
|
|
208
|
+
*/
|
|
209
|
+
describe(msg) {
|
|
210
|
+
const meta = this._meta || {};
|
|
211
|
+
meta.desc = msg;
|
|
212
|
+
return this._cloneWithProps({ _meta: meta });
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Extends the type with an object, merging the properties
|
|
216
|
+
*/
|
|
217
|
+
extend(obj) {
|
|
218
|
+
if (!this._object) throw new Error("extend() can only be used on object schemas");
|
|
219
|
+
return object({
|
|
220
|
+
...this._object,
|
|
221
|
+
...obj
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Picks certain keys from an object schema
|
|
226
|
+
*/
|
|
227
|
+
pick(keys) {
|
|
228
|
+
if (!this._object) throw new Error("pick() can only be used on object schemas");
|
|
229
|
+
const pickedObj = {};
|
|
230
|
+
for (const key of Object.keys(keys)) if (key in this._object) pickedObj[key] = this._object[key];
|
|
231
|
+
return object(pickedObj);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Omits certain keys from an object schema
|
|
235
|
+
*/
|
|
236
|
+
omit(keys) {
|
|
237
|
+
if (!this._object) throw new Error("omit() can only be used on object schemas");
|
|
238
|
+
const omittedObj = { ...this._object };
|
|
239
|
+
for (const key of Object.keys(keys)) delete omittedObj[key];
|
|
240
|
+
return object(omittedObj);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Helper method to modify object properties with a transformation function
|
|
244
|
+
*/
|
|
245
|
+
_transformObjectProperties(transform, keys) {
|
|
246
|
+
if (!this._object) throw new Error("This operation can only be used on object schemas");
|
|
247
|
+
const transformedObj = {};
|
|
248
|
+
const originalObj = this._object;
|
|
249
|
+
for (const [key, typeInstance] of Object.entries(originalObj)) transformedObj[key] = transform(key, typeInstance, !keys || key in keys);
|
|
250
|
+
return object(transformedObj);
|
|
251
|
+
}
|
|
252
|
+
partial(keys) {
|
|
253
|
+
if (!this._object) throw new Error("partial() can only be used on object schemas");
|
|
254
|
+
return this._transformObjectProperties((key, type, shouldTransform) => {
|
|
255
|
+
if (!shouldTransform) return type;
|
|
256
|
+
return Type._cloneTypeWithOptional(type, true);
|
|
257
|
+
}, keys);
|
|
258
|
+
}
|
|
259
|
+
required(keys) {
|
|
260
|
+
if (!this._object) throw new Error("required() can only be used on object schemas");
|
|
261
|
+
return this._transformObjectProperties((key, type, shouldTransform) => {
|
|
262
|
+
if (!shouldTransform) return type;
|
|
263
|
+
return Type._cloneTypeWithOptional(type, false);
|
|
264
|
+
}, keys);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Helper method to clone a type with optional flag
|
|
268
|
+
*/
|
|
269
|
+
static _cloneTypeWithOptional(originalType, optional) {
|
|
270
|
+
const newType = new Type(originalType.type);
|
|
271
|
+
Type._copyTypeProperties(originalType, newType);
|
|
272
|
+
newType._optional = optional;
|
|
273
|
+
return newType;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* Creates a string type validator
|
|
278
|
+
*/
|
|
279
|
+
function string() {
|
|
280
|
+
return new Type("string", { _check: isString });
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Creates a number type validator
|
|
284
|
+
*/
|
|
285
|
+
function number() {
|
|
286
|
+
return new Type("number", { _check: isNumber });
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Creates an integer type validator
|
|
290
|
+
*/
|
|
291
|
+
function int() {
|
|
292
|
+
return new Type("int", { _check: isInteger });
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Creates a boolean type validator
|
|
296
|
+
*/
|
|
297
|
+
function boolean() {
|
|
298
|
+
return new Type("boolean", { _check: isBoolean });
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Creates a none type validator (undefined | null)
|
|
302
|
+
* Like undefined | null in TS and nil in Swift
|
|
303
|
+
*/
|
|
304
|
+
function none() {
|
|
305
|
+
return new Type("none", {
|
|
306
|
+
_check: (v) => v == null,
|
|
307
|
+
_optional: true
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Creates an any type validator that accepts any non-null value
|
|
312
|
+
*/
|
|
313
|
+
function any() {
|
|
314
|
+
return new Type("any", { _check: (v) => v != null });
|
|
315
|
+
}
|
|
316
|
+
const float = number;
|
|
317
|
+
const double = number;
|
|
318
|
+
const real = number;
|
|
319
|
+
/**
|
|
320
|
+
* Creates an object type validator with specified properties
|
|
321
|
+
*/
|
|
322
|
+
function object(tobj) {
|
|
323
|
+
return new Type("object", {
|
|
324
|
+
_check: isObject,
|
|
325
|
+
_object: tobj
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Creates a record type validator (object with string keys and uniform value type)
|
|
330
|
+
*/
|
|
331
|
+
function record(valueType) {
|
|
332
|
+
return new Type("record", {
|
|
333
|
+
_check: isObject,
|
|
334
|
+
_type: valueType
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Creates a union type validator (like `string | number | boolean`)
|
|
339
|
+
*/
|
|
340
|
+
function union(options) {
|
|
341
|
+
return new Type("union", {
|
|
342
|
+
_check: (v) => options.some((option) => option._check?.(v) ?? false),
|
|
343
|
+
_union: options
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Creates a literal value validator
|
|
348
|
+
*/
|
|
349
|
+
function literal(value) {
|
|
350
|
+
return new Type("literal", {
|
|
351
|
+
_check: (v) => v === value,
|
|
352
|
+
_default: value
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Creates a string literal union validator (like `"a" | "b" | "c"`)
|
|
357
|
+
*/
|
|
358
|
+
function stringLiterals(values) {
|
|
359
|
+
return new Type("string", {
|
|
360
|
+
_check: (v) => typeof v === "string" && values.includes(v),
|
|
361
|
+
_enumValues: values
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Creates a tuple type validator with fixed length and types e.g. [string, number, boolean]
|
|
366
|
+
*/
|
|
367
|
+
function tuple(items) {
|
|
368
|
+
return new Type("tuple", {
|
|
369
|
+
_check: (v) => Array.isArray(v) && v.length === items.length && items.every((item, i) => item._check?.(v[i]) ?? false),
|
|
370
|
+
_type: items
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Creates an array type validator for a specific item type
|
|
375
|
+
*/
|
|
376
|
+
function array(itemType) {
|
|
377
|
+
return new Type("array", {
|
|
378
|
+
_check: isArray,
|
|
379
|
+
_type: itemType
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Creates a regular function type validator
|
|
384
|
+
*/
|
|
385
|
+
function func(args, ret) {
|
|
386
|
+
return new Type("function", {
|
|
387
|
+
_check: isFunction,
|
|
388
|
+
_args: args,
|
|
389
|
+
_ret: ret
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Creates an RPC function type validator that takes one argument and returns a promise
|
|
394
|
+
*/
|
|
395
|
+
function rpc(info, ret) {
|
|
396
|
+
return new Type("rpc", {
|
|
397
|
+
_check: isFunction,
|
|
398
|
+
_info: info,
|
|
399
|
+
_ret: ret ?? none()
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
//#endregion
|
|
404
|
+
export { Type, any, array, boolean, double, float, func, int, literal, none, number, object, real, record, rpc, string, stringLiterals, tuple, union };
|
|
2
405
|
//# sourceMappingURL=schema.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.mjs","names":[],"sources":["../../../src/common/schema/schema.ts"],"sourcesContent":["// With many, many inspiration from https://github.com/badrap/valita MIT License as of 2024-09-10\n\nimport type { StandardSchemaV1 } from './schema-standard'\nimport { isArray, isBoolean, isFunction, isInteger, isNumber, isObject, isString } from '../data/is'\n\n/**\n * Metadata interface for type descriptions and additional properties\n */\nexport interface TypeMeta {\n desc?: string\n}\n\n/**\n * Core Type class for schema validation and type inference\n * Implements StandardSchemaV1 for cross-library compatibility\n */\nexport class Type<T = unknown> {\n readonly type: string\n\n _default?: any\n _optional?: boolean\n _meta?: TypeMeta\n _check?: (obj: any) => boolean\n _object?: any\n _type?: any\n _union?: any\n _enumValues?: any\n _args?: any\n _ret?: any\n _info?: any\n\n // [key: `_${string}`]: any // Allow only optional dynamic properties starting with an underscore\n\n constructor(name: string, options: Partial<Type<T>> = {}) {\n this.type = name\n Object.assign(this, options)\n }\n\n /**\n * Standard Schema V1 compliance property\n * Provides a standard interface for validation and type inference\n */\n get '~standard'(): any {\n return {\n version: 1,\n vendor: 'zeed',\n validate: (value: unknown): StandardSchemaV1.Result<T> => {\n return this.validate(value)\n },\n types: {\n input: undefined as any as T,\n output: undefined as any as T,\n },\n }\n }\n\n /**\n * Validation method for standard-schema compliance\n */\n validate(value: any): any {\n // const messages: Array<{ path: string, message: string, type: string, valid: boolean }> = []\n\n // Handle null/undefined cases\n if (value == null) {\n if (this._optional) {\n return { value: undefined as any as T }\n }\n if (this._default !== undefined) {\n const defaultValue = isFunction(this._default) ? this._default(this) : this._default\n return { value: defaultValue }\n }\n return {\n issues: [{\n message: `Required value is missing`,\n path: [],\n }],\n }\n }\n\n // Handle literal types\n if (this.type === 'literal' && this._default !== value) {\n return {\n issues: [{\n message: `Expected literal value ${this._default}, got ${value}`,\n path: [],\n }],\n }\n }\n\n // Handle string literals (enums)\n if (this._enumValues && Array.isArray(this._enumValues)) {\n if (!this._enumValues.includes(value)) {\n return {\n issues: [{\n message: `Expected one of [${this._enumValues.join(', ')}], got ${value}`,\n path: [],\n }],\n }\n }\n }\n\n // Handle union types\n if (this._union && Array.isArray(this._union)) {\n for (const option of this._union) {\n const result = (option as Type<any>).validate(value)\n if (!result.issues) {\n return result\n }\n }\n return {\n issues: [{\n message: `Value does not match any union variant`,\n path: [],\n }],\n }\n }\n\n // Handle array types\n if (this.type === 'array' || this.type === 'tuple') {\n if (!Array.isArray(value)) {\n return {\n issues: [{\n message: `Expected array, got ${typeof value}`,\n path: [],\n }],\n }\n }\n\n if (this.type === 'tuple' && this._type) {\n const items = this._type as Type<any>[]\n if (value.length !== items.length) {\n return {\n issues: [{\n message: `Expected tuple of length ${items.length}, got ${value.length}`,\n path: [],\n }],\n }\n }\n\n const issues: StandardSchemaV1.Issue[] = []\n for (let i = 0; i < items.length; i++) {\n const itemResult = items[i].validate(value[i])\n if (itemResult.issues) {\n for (const issue of itemResult.issues) {\n issues.push({\n message: issue.message,\n path: [i, ...(issue.path || [])],\n })\n }\n }\n }\n\n if (issues.length > 0) {\n return { issues }\n }\n }\n else if (this._type) {\n // Regular array with item type\n const itemType = this._type as Type<any>\n const issues: StandardSchemaV1.Issue[] = []\n\n for (let i = 0; i < value.length; i++) {\n const itemResult = itemType.validate(value[i])\n if (itemResult.issues) {\n for (const issue of itemResult.issues) {\n issues.push({\n message: issue.message,\n path: [i, ...(issue.path || [])],\n })\n }\n }\n }\n\n if (issues.length > 0) {\n return { issues }\n }\n }\n }\n\n // Handle object types\n if (this._object) {\n if (!isObject(value)) {\n return {\n issues: [{\n message: `Expected object, got ${typeof value}`,\n path: [],\n }],\n }\n }\n\n const issues: StandardSchemaV1.Issue[] = []\n const obj = value as Record<string, any>\n\n for (const key in this._object) {\n const propSchema = this._object[key] as Type<any>\n const propValue = obj[key]\n const propResult = propSchema.validate(propValue)\n\n if (propResult.issues) {\n for (const issue of propResult.issues) {\n issues.push({\n message: issue.message,\n path: [key, ...(issue.path || [])],\n })\n }\n }\n }\n\n if (issues.length > 0) {\n return { issues }\n }\n\n return { value: value as T, issues: undefined }\n }\n\n // Handle record types\n if (this.type === 'record' && this._type) {\n if (!isObject(value)) {\n return {\n issues: [{\n message: `Expected object, got ${typeof value}`,\n path: [],\n }],\n }\n }\n\n const valueType = this._type as Type<any>\n const issues: StandardSchemaV1.Issue[] = []\n const obj = value as Record<string, any>\n\n for (const key in obj) {\n const propResult = valueType.validate(obj[key])\n if (propResult.issues) {\n for (const issue of propResult.issues) {\n issues.push({\n message: issue.message,\n path: [key, ...(issue.path || [])],\n })\n }\n }\n }\n\n if (issues.length > 0) {\n return { issues }\n }\n }\n\n // Check primitive types\n if (this._check && !this._check(value)) {\n return {\n issues: [{\n message: `Expected ${this.type}, got ${typeof value}`,\n path: [],\n }],\n }\n }\n\n // Success - return the value\n return { value: value as T }\n }\n\n /**\n * Creates a copy of the type with new properties merged\n */\n private _cloneWithProps<U = T>(newProps: Partial<Type<any>> = {}): Type<U> {\n const cloned = new Type<U>(this.type)\n // Copy all existing properties\n const propertiesToCopy = ['_default', '_optional', '_meta', '_check', '_object', '_type', '_union', '_enumValues', '_args', '_ret', '_info']\n for (const prop of propertiesToCopy) {\n if ((this as any)[prop] !== undefined) {\n (cloned as any)[prop] = (this as any)[prop]\n }\n }\n // Apply new properties\n Object.assign(cloned, newProps)\n return cloned\n }\n\n /**\n * Helper to copy type properties when creating new type instances\n */\n private static _copyTypeProperties(source: Type<any>, target: Type<any>): void {\n const properties = ['_check', '_default', '_meta', '_object', '_type', '_enumValues']\n for (const prop of properties) {\n if ((source as any)[prop] !== undefined) {\n (target as any)[prop] = (source as any)[prop]\n }\n }\n }\n\n /**\n * Marks the type as optional, meaning it can be undefined\n * This is useful for properties that are not required.\n */\n optional(): Type<T | undefined> {\n return this._cloneWithProps<T | undefined>({ _optional: true })\n }\n\n /**\n * Sets a default value for the type, which will be used if the value is not provided\n * The default value can be a function that receives the schema as argument, or a static value.\n */\n default(value: T | ((schema?: this) => T)): Type<T> {\n return this._cloneWithProps<T>({ _default: value })\n }\n\n /**\n * Props / Metadata for the type, like description or other properties\n */\n meta(meta: TypeMeta): Type<T> {\n return this._cloneWithProps<T>({ _meta: meta })\n }\n\n /**\n * Sets the `desc` property for the type, which is a human-readable description\n */\n describe(msg: string): Type<T> {\n const meta = this._meta || {}\n meta.desc = msg\n return this._cloneWithProps<T>({ _meta: meta })\n }\n\n /**\n * Extends the type with an object, merging the properties\n */\n extend<O>(obj: O): Type<T & TypeObject<O>> {\n if (!this._object) {\n throw new Error('extend() can only be used on object schemas')\n }\n const newObj = { ...this._object, ...obj }\n return object(newObj) as any\n }\n\n /**\n * Picks certain keys from an object schema\n */\n pick<K extends keyof T>(keys: Record<K, true>): Type<Pick<T, K>> {\n if (!this._object) {\n throw new Error('pick() can only be used on object schemas')\n }\n const pickedObj: any = {}\n for (const key of Object.keys(keys)) {\n if (key in this._object) {\n pickedObj[key] = (this._object as any)[key]\n }\n }\n return object(pickedObj) as any\n }\n\n /**\n * Omits certain keys from an object schema\n */\n omit<K extends keyof T>(keys: Record<K, true>): Type<Omit<T, K>> {\n if (!this._object) {\n throw new Error('omit() can only be used on object schemas')\n }\n const omittedObj: any = { ...this._object }\n for (const key of Object.keys(keys)) {\n delete omittedObj[key]\n }\n return object(omittedObj) as any\n }\n\n /**\n * Helper method to modify object properties with a transformation function\n */\n private _transformObjectProperties(\n transform: (key: string, type: Type<any>, shouldTransform: boolean) => Type<any>,\n keys?: Record<string, true>,\n ): any {\n if (!this._object) {\n throw new Error('This operation can only be used on object schemas')\n }\n\n const transformedObj: any = {}\n const originalObj = this._object as any\n\n for (const [key, typeInstance] of Object.entries(originalObj)) {\n const shouldTransform = !keys || key in keys\n transformedObj[key] = transform(key, typeInstance as Type<any>, shouldTransform)\n }\n\n return object(transformedObj)\n }\n\n /**\n * Makes some or all properties of an object schema optional\n */\n partial(): Type<Partial<T>>\n partial<K extends keyof T>(keys: Record<K, true>): Type<Partial<Pick<T, K>> & Omit<T, K>>\n partial<K extends keyof T>(keys?: Record<K, true>): Type<Partial<T> | (Partial<Pick<T, K>> & Omit<T, K>)> {\n if (!this._object) {\n throw new Error('partial() can only be used on object schemas')\n }\n return this._transformObjectProperties((key, type, shouldTransform) => {\n if (!shouldTransform)\n return type\n return Type._cloneTypeWithOptional(type, true)\n }, keys)\n }\n\n /**\n * Makes some or all properties of an object schema required\n */\n required(): Type<Required<T>>\n required<K extends keyof T>(keys: Record<K, true>): Type<Required<Pick<T, K>> & Omit<T, K>>\n required<K extends keyof T>(keys?: Record<K, true>): Type<Required<T> | (Required<Pick<T, K>> & Omit<T, K>)> {\n if (!this._object) {\n throw new Error('required() can only be used on object schemas')\n }\n return this._transformObjectProperties((key, type, shouldTransform) => {\n if (!shouldTransform)\n return type\n return Type._cloneTypeWithOptional(type, false)\n }, keys)\n }\n\n /**\n * Helper method to clone a type with optional flag\n */\n private static _cloneTypeWithOptional(originalType: Type<any>, optional: boolean): Type<any> {\n const newType = new Type(originalType.type)\n Type._copyTypeProperties(originalType, newType)\n newType._optional = optional\n return newType\n }\n}\n\n/**\n * Type inference utility for extracting the TypeScript type from a schema Type\n */\nexport type Infer<T> = T extends Type<infer TT> ? TT : never\n\n// =============================================================================\n// Primitive Types\n// =============================================================================\n\n/**\n * Creates a string type validator\n */\nexport function string(): Type<string> {\n return new Type('string', {\n _check: isString,\n })\n}\n\n/**\n * Creates a number type validator\n */\nexport function number(): Type<number> {\n return new Type('number', {\n _check: isNumber,\n })\n}\n\n/**\n * Creates an integer type validator\n */\nexport function int(): Type<number> {\n return new Type('int', {\n _check: isInteger,\n })\n}\n\n/**\n * Creates a boolean type validator\n */\nexport function boolean(): Type<boolean> {\n return new Type('boolean', {\n _check: isBoolean,\n })\n}\n\n/**\n * Creates a none type validator (undefined | null)\n * Like undefined | null in TS and nil in Swift\n */\nexport function none(): Type<undefined> {\n return new Type('none', {\n _check: (v: any) => v == null,\n _optional: true,\n })\n}\n\n/**\n * Creates an any type validator that accepts any non-null value\n */\nexport function any<T = any>(): Type<T> {\n return new Type('any', {\n _check: (v: any) => v != null,\n })\n}\n\n// Aliases for number types\nexport const float = number\nexport const double = number\nexport const real = number\n\n// =============================================================================\n// Object Types\n// =============================================================================\n\n/**\n * Utility type to make object properties optional if their value type includes undefined.\n * @category Schema\n */\nexport type TypeObjectFixOptional<T> = {\n [K in keyof T as undefined extends T[K] ? K : never]?: T[K] & {}\n} & {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K] & {}\n}\n\n/**\n * Utility type for pretty-printing object types\n */\ntype TypeObjectPretty<V> = Extract<{ [K in keyof V]: V[K] }, unknown>\n\n/**\n * Main object type utility\n */\ntype TypeObject<T> = TypeObjectPretty<TypeObjectFixOptional<{\n [K in keyof T]: Infer<T[K]>\n}>>\n\n/**\n * Creates an object type validator with specified properties\n */\nexport function object<T>(tobj: T): Type<TypeObject<T>> {\n return new Type('object', {\n _check: isObject,\n _object: tobj,\n })\n}\n\n/**\n * Creates a record type validator (object with string keys and uniform value type)\n */\nexport function record<T extends Type>(valueType: T): Type<Record<string, Infer<T>>> {\n return new Type('record', {\n _check: isObject,\n _type: valueType,\n })\n}\n\n// =============================================================================\n// Union Types\n// =============================================================================\n\n/**\n * Utility type for union of types.\n * @category Schema\n */\nexport type TypeUnion<T extends Type<any>[]> = {\n [K in keyof T]: T[K] extends Type<infer U> ? U : never\n}[number]\n\n/**\n * Creates a union type validator (like `string | number | boolean`)\n */\nexport function union<T extends Type<any>[]>(options: T): Type<TypeUnion<T>> {\n return new Type('union', {\n _check: (v: any) => options.some(option => option._check?.(v) ?? false),\n _union: options,\n })\n}\n\n// =============================================================================\n// Literal Types\n// =============================================================================\n\n/**\n * Utility type for literal types.\n * @category Schema\n */\nexport type TypeLiterals = string | number | bigint | boolean\n\n/**\n * Creates a literal value validator\n */\nexport function literal<T extends TypeLiterals>(value: T): Type<T> {\n return new Type('literal', {\n _check: (v: any) => v === value,\n _default: value,\n })\n}\n\n/**\n * Creates a string literal union validator (like `\"a\" | \"b\" | \"c\"`)\n */\nexport function stringLiterals<const T extends readonly string[]>(values: T): Type<T[number]> {\n return new Type('string', {\n _check: (v: any) => typeof v === 'string' && (values as readonly string[]).includes(v),\n _enumValues: values,\n })\n}\n\n// =============================================================================\n// Collection Types\n// =============================================================================\n\n/**\n * Utility type for tuple types.\n * @category Schema\n */\nexport type TypeTuple<T extends readonly Type[]> = {\n -readonly [K in keyof T]: T[K] extends Type<infer U> ? U : never\n}\n\n/**\n * Output type for TypeArray.\n * @category Schema\n */\nexport type TypeArrayOutput<Head extends Type[], Rest extends Type | undefined> = [\n ...TypeTuple<Head>,\n ...(Rest extends Type ? Infer<Rest>[] : []),\n]\n\n/**\n * Utility type for array types.\n * @category Schema\n */\nexport type TypeArray<Head extends Type[] = Type[], Rest extends Type | undefined = Type | undefined> = Type<TypeArrayOutput<Head, Rest>>\n\n/**\n * Creates a tuple type validator with fixed length and types e.g. [string, number, boolean]\n */\nexport function tuple<const T extends readonly Type[]>(items: T): Type<TypeTuple<T>> {\n return new Type('tuple', {\n _check: (v: any) => Array.isArray(v) && v.length === items.length && items.every((item, i) => (item as Type)._check?.(v[i]) ?? false),\n _type: items,\n })\n}\n\n/**\n * Creates an array type validator for a specific item type\n */\nexport function array<T>(itemType: Type<T>): Type<T[]> {\n return new Type('array', {\n _check: isArray,\n _type: itemType,\n })\n}\n\n// =============================================================================\n// Function Types\n// =============================================================================\n\n/**\n * Creates a regular function type validator\n */\nexport function func<\n TypeFuncArgs extends [Type<unknown>, ...Type<any>[]] | [],\n TypeFuncRet = Type,\n T = (...args: TypeTuple<TypeFuncArgs>) => Infer<TypeFuncRet>,\n>(args: TypeFuncArgs, ret: TypeFuncRet): Type<T> {\n return new Type('function', {\n _check: isFunction,\n _args: args,\n _ret: ret,\n })\n}\n\n/**\n * Creates an RPC function type validator that takes one argument and returns a promise\n */\nexport function rpc<\n TypeRpcInfo extends Type<unknown> | undefined = undefined,\n TypeRpcRet extends Type<unknown> = Type<void>,\n T = TypeRpcInfo extends undefined\n ? () => Infer<TypeRpcRet>\n : (info: Infer<TypeRpcInfo>) => Infer<TypeRpcRet> | Promise<Infer<TypeRpcRet>>,\n>(info?: TypeRpcInfo, ret?: TypeRpcRet): Type<T> {\n return new Type('rpc', {\n _check: isFunction,\n _info: info,\n _ret: ret ?? none(),\n })\n}\n"],"mappings":"iIAgBA,IAAa,EAAb,MAAa,CAAkB,CAC7B,KAEA,SACA,UACA,MACA,OACA,QACA,MACA,OACA,YACA,MACA,KACA,MAIA,YAAY,EAAc,EAA4B,EAAE,CAAE,CACxD,KAAK,KAAO,EACZ,OAAO,OAAO,KAAM,EAAQ,CAO9B,GAAI,aAAmB,CACrB,MAAO,CACL,QAAS,EACT,OAAQ,OACR,SAAW,GACF,KAAK,SAAS,EAAM,CAE7B,MAAO,CACL,MAAO,IAAA,GACP,OAAQ,IAAA,GACT,CACF,CAMH,SAAS,EAAiB,CAIxB,GAAI,GAAS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AAU,CACxB,OAAS,GAAW,OAAO,GAAM,UAAa,EAA6B,SAAS,EAAE,CACtF,YAAa,EACd,CAAC,CAiCJ,SAAgB,EAAuC,EAA8B,CACnF,OAAO,IAAI,EAAK,QAAS,CACvB,OAAS,GAAW,MAAM,QAAQ,EAAE,EAAI,EAAE,SAAW,EAAM,QAAU,EAAM,OAAO,EAAM,IAAO,EAAc,SAAS,EAAE,GAAG,EAAI,GAAM,CACrI,MAAO,EACR,CAAC,CAMJ,SAAgB,EAAS,EAA8B,CACrD,OAAO,IAAI,EAAK,QAAS,CACvB,OAAQ,EACR,MAAO,EACR,CAAC,CAUJ,SAAgB,EAId,EAAoB,EAA2B,CAC/C,OAAO,IAAI,EAAK,WAAY,CAC1B,OAAQ,EACR,MAAO,EACP,KAAM,EACP,CAAC,CAMJ,SAAgB,EAMd,EAAoB,EAA2B,CAC/C,OAAO,IAAI,EAAK,MAAO,CACrB,OAAQ,EACR,MAAO,EACP,KAAM,GAAO,GAAM,CACpB,CAAC"}
|
|
1
|
+
{"version":3,"file":"schema.mjs","names":[],"sources":["../../../src/common/schema/schema.ts"],"sourcesContent":["// With many, many inspiration from https://github.com/badrap/valita MIT License as of 2024-09-10\n\nimport type { StandardSchemaV1 } from './schema-standard'\nimport { isArray, isBoolean, isFunction, isInteger, isNumber, isObject, isString } from '../data/is'\n\n/**\n * Metadata interface for type descriptions and additional properties\n */\nexport interface TypeMeta {\n desc?: string\n}\n\n/**\n * Core Type class for schema validation and type inference\n * Implements StandardSchemaV1 for cross-library compatibility\n */\nexport class Type<T = unknown> {\n readonly type: string\n\n _default?: any\n _optional?: boolean\n _meta?: TypeMeta\n _check?: (obj: any) => boolean\n _object?: any\n _type?: any\n _union?: any\n _enumValues?: any\n _args?: any\n _ret?: any\n _info?: any\n\n // [key: `_${string}`]: any // Allow only optional dynamic properties starting with an underscore\n\n constructor(name: string, options: Partial<Type<T>> = {}) {\n this.type = name\n Object.assign(this, options)\n }\n\n /**\n * Standard Schema V1 compliance property\n * Provides a standard interface for validation and type inference\n */\n get '~standard'(): any {\n return {\n version: 1,\n vendor: 'zeed',\n validate: (value: unknown): StandardSchemaV1.Result<T> => {\n return this.validate(value)\n },\n types: {\n input: undefined as any as T,\n output: undefined as any as T,\n },\n }\n }\n\n /**\n * Validation method for standard-schema compliance\n */\n validate(value: any): any {\n // const messages: Array<{ path: string, message: string, type: string, valid: boolean }> = []\n\n // Handle null/undefined cases\n if (value == null) {\n if (this._optional) {\n return { value: undefined as any as T }\n }\n if (this._default !== undefined) {\n const defaultValue = isFunction(this._default) ? this._default(this) : this._default\n return { value: defaultValue }\n }\n return {\n issues: [{\n message: `Required value is missing`,\n path: [],\n }],\n }\n }\n\n // Handle literal types\n if (this.type === 'literal' && this._default !== value) {\n return {\n issues: [{\n message: `Expected literal value ${this._default}, got ${value}`,\n path: [],\n }],\n }\n }\n\n // Handle string literals (enums)\n if (this._enumValues && Array.isArray(this._enumValues)) {\n if (!this._enumValues.includes(value)) {\n return {\n issues: [{\n message: `Expected one of [${this._enumValues.join(', ')}], got ${value}`,\n path: [],\n }],\n }\n }\n }\n\n // Handle union types\n if (this._union && Array.isArray(this._union)) {\n for (const option of this._union) {\n const result = (option as Type<any>).validate(value)\n if (!result.issues) {\n return result\n }\n }\n return {\n issues: [{\n message: `Value does not match any union variant`,\n path: [],\n }],\n }\n }\n\n // Handle array types\n if (this.type === 'array' || this.type === 'tuple') {\n if (!Array.isArray(value)) {\n return {\n issues: [{\n message: `Expected array, got ${typeof value}`,\n path: [],\n }],\n }\n }\n\n if (this.type === 'tuple' && this._type) {\n const items = this._type as Type<any>[]\n if (value.length !== items.length) {\n return {\n issues: [{\n message: `Expected tuple of length ${items.length}, got ${value.length}`,\n path: [],\n }],\n }\n }\n\n const issues: StandardSchemaV1.Issue[] = []\n for (let i = 0; i < items.length; i++) {\n const itemResult = items[i].validate(value[i])\n if (itemResult.issues) {\n for (const issue of itemResult.issues) {\n issues.push({\n message: issue.message,\n path: [i, ...(issue.path || [])],\n })\n }\n }\n }\n\n if (issues.length > 0) {\n return { issues }\n }\n }\n else if (this._type) {\n // Regular array with item type\n const itemType = this._type as Type<any>\n const issues: StandardSchemaV1.Issue[] = []\n\n for (let i = 0; i < value.length; i++) {\n const itemResult = itemType.validate(value[i])\n if (itemResult.issues) {\n for (const issue of itemResult.issues) {\n issues.push({\n message: issue.message,\n path: [i, ...(issue.path || [])],\n })\n }\n }\n }\n\n if (issues.length > 0) {\n return { issues }\n }\n }\n }\n\n // Handle object types\n if (this._object) {\n if (!isObject(value)) {\n return {\n issues: [{\n message: `Expected object, got ${typeof value}`,\n path: [],\n }],\n }\n }\n\n const issues: StandardSchemaV1.Issue[] = []\n const obj = value as Record<string, any>\n\n for (const key in this._object) {\n const propSchema = this._object[key] as Type<any>\n const propValue = obj[key]\n const propResult = propSchema.validate(propValue)\n\n if (propResult.issues) {\n for (const issue of propResult.issues) {\n issues.push({\n message: issue.message,\n path: [key, ...(issue.path || [])],\n })\n }\n }\n }\n\n if (issues.length > 0) {\n return { issues }\n }\n\n return { value: value as T, issues: undefined }\n }\n\n // Handle record types\n if (this.type === 'record' && this._type) {\n if (!isObject(value)) {\n return {\n issues: [{\n message: `Expected object, got ${typeof value}`,\n path: [],\n }],\n }\n }\n\n const valueType = this._type as Type<any>\n const issues: StandardSchemaV1.Issue[] = []\n const obj = value as Record<string, any>\n\n for (const key in obj) {\n const propResult = valueType.validate(obj[key])\n if (propResult.issues) {\n for (const issue of propResult.issues) {\n issues.push({\n message: issue.message,\n path: [key, ...(issue.path || [])],\n })\n }\n }\n }\n\n if (issues.length > 0) {\n return { issues }\n }\n }\n\n // Check primitive types\n if (this._check && !this._check(value)) {\n return {\n issues: [{\n message: `Expected ${this.type}, got ${typeof value}`,\n path: [],\n }],\n }\n }\n\n // Success - return the value\n return { value: value as T }\n }\n\n /**\n * Creates a copy of the type with new properties merged\n */\n private _cloneWithProps<U = T>(newProps: Partial<Type<any>> = {}): Type<U> {\n const cloned = new Type<U>(this.type)\n // Copy all existing properties\n const propertiesToCopy = ['_default', '_optional', '_meta', '_check', '_object', '_type', '_union', '_enumValues', '_args', '_ret', '_info']\n for (const prop of propertiesToCopy) {\n if ((this as any)[prop] !== undefined) {\n (cloned as any)[prop] = (this as any)[prop]\n }\n }\n // Apply new properties\n Object.assign(cloned, newProps)\n return cloned\n }\n\n /**\n * Helper to copy type properties when creating new type instances\n */\n private static _copyTypeProperties(source: Type<any>, target: Type<any>): void {\n const properties = ['_check', '_default', '_meta', '_object', '_type', '_enumValues']\n for (const prop of properties) {\n if ((source as any)[prop] !== undefined) {\n (target as any)[prop] = (source as any)[prop]\n }\n }\n }\n\n /**\n * Marks the type as optional, meaning it can be undefined\n * This is useful for properties that are not required.\n */\n optional(): Type<T | undefined> {\n return this._cloneWithProps<T | undefined>({ _optional: true })\n }\n\n /**\n * Sets a default value for the type, which will be used if the value is not provided\n * The default value can be a function that receives the schema as argument, or a static value.\n */\n default(value: T | ((schema?: this) => T)): Type<T> {\n return this._cloneWithProps<T>({ _default: value })\n }\n\n /**\n * Props / Metadata for the type, like description or other properties\n */\n meta(meta: TypeMeta): Type<T> {\n return this._cloneWithProps<T>({ _meta: meta })\n }\n\n /**\n * Sets the `desc` property for the type, which is a human-readable description\n */\n describe(msg: string): Type<T> {\n const meta = this._meta || {}\n meta.desc = msg\n return this._cloneWithProps<T>({ _meta: meta })\n }\n\n /**\n * Extends the type with an object, merging the properties\n */\n extend<O>(obj: O): Type<T & TypeObject<O>> {\n if (!this._object) {\n throw new Error('extend() can only be used on object schemas')\n }\n const newObj = { ...this._object, ...obj }\n return object(newObj) as any\n }\n\n /**\n * Picks certain keys from an object schema\n */\n pick<K extends keyof T>(keys: Record<K, true>): Type<Pick<T, K>> {\n if (!this._object) {\n throw new Error('pick() can only be used on object schemas')\n }\n const pickedObj: any = {}\n for (const key of Object.keys(keys)) {\n if (key in this._object) {\n pickedObj[key] = (this._object as any)[key]\n }\n }\n return object(pickedObj) as any\n }\n\n /**\n * Omits certain keys from an object schema\n */\n omit<K extends keyof T>(keys: Record<K, true>): Type<Omit<T, K>> {\n if (!this._object) {\n throw new Error('omit() can only be used on object schemas')\n }\n const omittedObj: any = { ...this._object }\n for (const key of Object.keys(keys)) {\n delete omittedObj[key]\n }\n return object(omittedObj) as any\n }\n\n /**\n * Helper method to modify object properties with a transformation function\n */\n private _transformObjectProperties(\n transform: (key: string, type: Type<any>, shouldTransform: boolean) => Type<any>,\n keys?: Record<string, true>,\n ): any {\n if (!this._object) {\n throw new Error('This operation can only be used on object schemas')\n }\n\n const transformedObj: any = {}\n const originalObj = this._object as any\n\n for (const [key, typeInstance] of Object.entries(originalObj)) {\n const shouldTransform = !keys || key in keys\n transformedObj[key] = transform(key, typeInstance as Type<any>, shouldTransform)\n }\n\n return object(transformedObj)\n }\n\n /**\n * Makes some or all properties of an object schema optional\n */\n partial(): Type<Partial<T>>\n partial<K extends keyof T>(keys: Record<K, true>): Type<Partial<Pick<T, K>> & Omit<T, K>>\n partial<K extends keyof T>(keys?: Record<K, true>): Type<Partial<T> | (Partial<Pick<T, K>> & Omit<T, K>)> {\n if (!this._object) {\n throw new Error('partial() can only be used on object schemas')\n }\n return this._transformObjectProperties((key, type, shouldTransform) => {\n if (!shouldTransform)\n return type\n return Type._cloneTypeWithOptional(type, true)\n }, keys)\n }\n\n /**\n * Makes some or all properties of an object schema required\n */\n required(): Type<Required<T>>\n required<K extends keyof T>(keys: Record<K, true>): Type<Required<Pick<T, K>> & Omit<T, K>>\n required<K extends keyof T>(keys?: Record<K, true>): Type<Required<T> | (Required<Pick<T, K>> & Omit<T, K>)> {\n if (!this._object) {\n throw new Error('required() can only be used on object schemas')\n }\n return this._transformObjectProperties((key, type, shouldTransform) => {\n if (!shouldTransform)\n return type\n return Type._cloneTypeWithOptional(type, false)\n }, keys)\n }\n\n /**\n * Helper method to clone a type with optional flag\n */\n private static _cloneTypeWithOptional(originalType: Type<any>, optional: boolean): Type<any> {\n const newType = new Type(originalType.type)\n Type._copyTypeProperties(originalType, newType)\n newType._optional = optional\n return newType\n }\n}\n\n/**\n * Type inference utility for extracting the TypeScript type from a schema Type\n */\nexport type Infer<T> = T extends Type<infer TT> ? TT : never\n\n// =============================================================================\n// Primitive Types\n// =============================================================================\n\n/**\n * Creates a string type validator\n */\nexport function string(): Type<string> {\n return new Type('string', {\n _check: isString,\n })\n}\n\n/**\n * Creates a number type validator\n */\nexport function number(): Type<number> {\n return new Type('number', {\n _check: isNumber,\n })\n}\n\n/**\n * Creates an integer type validator\n */\nexport function int(): Type<number> {\n return new Type('int', {\n _check: isInteger,\n })\n}\n\n/**\n * Creates a boolean type validator\n */\nexport function boolean(): Type<boolean> {\n return new Type('boolean', {\n _check: isBoolean,\n })\n}\n\n/**\n * Creates a none type validator (undefined | null)\n * Like undefined | null in TS and nil in Swift\n */\nexport function none(): Type<undefined> {\n return new Type('none', {\n _check: (v: any) => v == null,\n _optional: true,\n })\n}\n\n/**\n * Creates an any type validator that accepts any non-null value\n */\nexport function any<T = any>(): Type<T> {\n return new Type('any', {\n _check: (v: any) => v != null,\n })\n}\n\n// Aliases for number types\nexport const float = number\nexport const double = number\nexport const real = number\n\n// =============================================================================\n// Object Types\n// =============================================================================\n\n/**\n * Utility type to make object properties optional if their value type includes undefined.\n * @category Schema\n */\nexport type TypeObjectFixOptional<T> = {\n [K in keyof T as undefined extends T[K] ? K : never]?: T[K] & {}\n} & {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K] & {}\n}\n\n/**\n * Utility type for pretty-printing object types\n */\ntype TypeObjectPretty<V> = Extract<{ [K in keyof V]: V[K] }, unknown>\n\n/**\n * Main object type utility\n */\ntype TypeObject<T> = TypeObjectPretty<TypeObjectFixOptional<{\n [K in keyof T]: Infer<T[K]>\n}>>\n\n/**\n * Creates an object type validator with specified properties\n */\nexport function object<T>(tobj: T): Type<TypeObject<T>> {\n return new Type('object', {\n _check: isObject,\n _object: tobj,\n })\n}\n\n/**\n * Creates a record type validator (object with string keys and uniform value type)\n */\nexport function record<T extends Type>(valueType: T): Type<Record<string, Infer<T>>> {\n return new Type('record', {\n _check: isObject,\n _type: valueType,\n })\n}\n\n// =============================================================================\n// Union Types\n// =============================================================================\n\n/**\n * Utility type for union of types.\n * @category Schema\n */\nexport type TypeUnion<T extends Type<any>[]> = {\n [K in keyof T]: T[K] extends Type<infer U> ? U : never\n}[number]\n\n/**\n * Creates a union type validator (like `string | number | boolean`)\n */\nexport function union<T extends Type<any>[]>(options: T): Type<TypeUnion<T>> {\n return new Type('union', {\n _check: (v: any) => options.some(option => option._check?.(v) ?? false),\n _union: options,\n })\n}\n\n// =============================================================================\n// Literal Types\n// =============================================================================\n\n/**\n * Utility type for literal types.\n * @category Schema\n */\nexport type TypeLiterals = string | number | bigint | boolean\n\n/**\n * Creates a literal value validator\n */\nexport function literal<T extends TypeLiterals>(value: T): Type<T> {\n return new Type('literal', {\n _check: (v: any) => v === value,\n _default: value,\n })\n}\n\n/**\n * Creates a string literal union validator (like `\"a\" | \"b\" | \"c\"`)\n */\nexport function stringLiterals<const T extends readonly string[]>(values: T): Type<T[number]> {\n return new Type('string', {\n _check: (v: any) => typeof v === 'string' && (values as readonly string[]).includes(v),\n _enumValues: values,\n })\n}\n\n// =============================================================================\n// Collection Types\n// =============================================================================\n\n/**\n * Utility type for tuple types.\n * @category Schema\n */\nexport type TypeTuple<T extends readonly Type[]> = {\n -readonly [K in keyof T]: T[K] extends Type<infer U> ? U : never\n}\n\n/**\n * Output type for TypeArray.\n * @category Schema\n */\nexport type TypeArrayOutput<Head extends Type[], Rest extends Type | undefined> = [\n ...TypeTuple<Head>,\n ...(Rest extends Type ? Infer<Rest>[] : []),\n]\n\n/**\n * Utility type for array types.\n * @category Schema\n */\nexport type TypeArray<Head extends Type[] = Type[], Rest extends Type | undefined = Type | undefined> = Type<TypeArrayOutput<Head, Rest>>\n\n/**\n * Creates a tuple type validator with fixed length and types e.g. [string, number, boolean]\n */\nexport function tuple<const T extends readonly Type[]>(items: T): Type<TypeTuple<T>> {\n return new Type('tuple', {\n _check: (v: any) => Array.isArray(v) && v.length === items.length && items.every((item, i) => (item as Type)._check?.(v[i]) ?? false),\n _type: items,\n })\n}\n\n/**\n * Creates an array type validator for a specific item type\n */\nexport function array<T>(itemType: Type<T>): Type<T[]> {\n return new Type('array', {\n _check: isArray,\n _type: itemType,\n })\n}\n\n// =============================================================================\n// Function Types\n// =============================================================================\n\n/**\n * Creates a regular function type validator\n */\nexport function func<\n TypeFuncArgs extends [Type<unknown>, ...Type<any>[]] | [],\n TypeFuncRet = Type,\n T = (...args: TypeTuple<TypeFuncArgs>) => Infer<TypeFuncRet>,\n>(args: TypeFuncArgs, ret: TypeFuncRet): Type<T> {\n return new Type('function', {\n _check: isFunction,\n _args: args,\n _ret: ret,\n })\n}\n\n/**\n * Creates an RPC function type validator that takes one argument and returns a promise\n */\nexport function rpc<\n TypeRpcInfo extends Type<unknown> | undefined = undefined,\n TypeRpcRet extends Type<unknown> = Type<void>,\n T = TypeRpcInfo extends undefined\n ? () => Infer<TypeRpcRet>\n : (info: Infer<TypeRpcInfo>) => Infer<TypeRpcRet> | Promise<Infer<TypeRpcRet>>,\n>(info?: TypeRpcInfo, ret?: TypeRpcRet): Type<T> {\n return new Type('rpc', {\n _check: isFunction,\n _info: info,\n _ret: ret ?? none(),\n })\n}\n"],"mappings":";;;;;;;AAgBA,IAAa,OAAb,MAAa,KAAkB;CAC7B,AAAS;CAET;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAIA,YAAY,MAAc,UAA4B,EAAE,EAAE;AACxD,OAAK,OAAO;AACZ,SAAO,OAAO,MAAM,QAAQ;;;;;;CAO9B,IAAI,cAAmB;AACrB,SAAO;GACL,SAAS;GACT,QAAQ;GACR,WAAW,UAA+C;AACxD,WAAO,KAAK,SAAS,MAAM;;GAE7B,OAAO;IACL,OAAO;IACP,QAAQ;IACT;GACF;;;;;CAMH,SAAS,OAAiB;AAIxB,MAAI,SAAS,MAAM;AACjB,OAAI,KAA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EACR,OAAO;EACR,CAAC;;;;;AAkBJ,SAAgB,MAA6B,SAAgC;AAC3E,QAAO,IAAI,KAAK,SAAS;EACvB,SAAS,MAAW,QAAQ,MAAK,WAAU,OAAO,SAAS,EAAE,IAAI,MAAM;EACvE,QAAQ;EACT,CAAC;;;;;AAgBJ,SAAgB,QAAgC,OAAmB;AACjE,QAAO,IAAI,KAAK,WAAW;EACzB,SAAS,MAAW,MAAM;EAC1B,UAAU;EACX,CAAC;;;;;AAMJ,SAAgB,eAAkD,QAA4B;AAC5F,QAAO,IAAI,KAAK,UAAU;EACxB,SAAS,MAAW,OAAO,MAAM,YAAa,OAA6B,SAAS,EAAE;EACtF,aAAa;EACd,CAAC;;;;;AAiCJ,SAAgB,MAAuC,OAA8B;AACnF,QAAO,IAAI,KAAK,SAAS;EACvB,SAAS,MAAW,MAAM,QAAQ,EAAE,IAAI,EAAE,WAAW,MAAM,UAAU,MAAM,OAAO,MAAM,MAAO,KAAc,SAAS,EAAE,GAAG,IAAI,MAAM;EACrI,OAAO;EACR,CAAC;;;;;AAMJ,SAAgB,MAAS,UAA8B;AACrD,QAAO,IAAI,KAAK,SAAS;EACvB,QAAQ;EACR,OAAO;EACR,CAAC;;;;;AAUJ,SAAgB,KAId,MAAoB,KAA2B;AAC/C,QAAO,IAAI,KAAK,YAAY;EAC1B,QAAQ;EACR,OAAO;EACP,MAAM;EACP,CAAC;;;;;AAMJ,SAAgB,IAMd,MAAoB,KAA2B;AAC/C,QAAO,IAAI,KAAK,OAAO;EACrB,QAAQ;EACR,OAAO;EACP,MAAM,OAAO,MAAM;EACpB,CAAC"}
|
|
@@ -1,2 +1,110 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_common_data_is = require('../data/is.cjs');
|
|
3
|
+
const require_common_schema_schema = require('./schema.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/common/schema/serialize.ts
|
|
6
|
+
/**
|
|
7
|
+
* Serializes a schema Type to a plain JSON object.
|
|
8
|
+
* Functions in _check and _default will not be serialized.
|
|
9
|
+
*
|
|
10
|
+
* @param schema - The schema Type to serialize
|
|
11
|
+
* @returns A plain JSON object representing the schema
|
|
12
|
+
*/
|
|
13
|
+
function serializeSchema(schema) {
|
|
14
|
+
const result = { type: schema.type };
|
|
15
|
+
if (schema._optional !== void 0) result.optional = schema._optional;
|
|
16
|
+
if (schema._meta !== void 0) result.meta = schema._meta;
|
|
17
|
+
if (schema._default !== void 0 && !require_common_data_is.isFunction(schema._default)) result.default = schema._default;
|
|
18
|
+
if (schema._object !== void 0) {
|
|
19
|
+
result.object = {};
|
|
20
|
+
for (const [key, value] of Object.entries(schema._object)) result.object[key] = serializeSchema(value);
|
|
21
|
+
}
|
|
22
|
+
if (schema._type !== void 0) if (require_common_data_is.isArray(schema._type)) result.tupleTypes = schema._type.map((t) => serializeSchema(t));
|
|
23
|
+
else result.itemType = serializeSchema(schema._type);
|
|
24
|
+
if (schema._union !== void 0) result.union = schema._union.map((t) => serializeSchema(t));
|
|
25
|
+
if (schema._enumValues !== void 0) result.enumValues = schema._enumValues;
|
|
26
|
+
if (schema._args !== void 0) result.args = schema._args.map((t) => serializeSchema(t));
|
|
27
|
+
if (schema._ret !== void 0) result.ret = serializeSchema(schema._ret);
|
|
28
|
+
if (schema._info !== void 0) result.info = serializeSchema(schema._info);
|
|
29
|
+
if (schema.type === "literal" && schema._default !== void 0) result.literalValue = schema._default;
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Deserializes a plain JSON object back to a schema Type.
|
|
34
|
+
* Note: Custom _check functions cannot be restored and will use default validators.
|
|
35
|
+
*
|
|
36
|
+
* @param serialized - The serialized schema object
|
|
37
|
+
* @returns A reconstructed Type instance
|
|
38
|
+
*/
|
|
39
|
+
function deserializeSchema(serialized) {
|
|
40
|
+
let schema;
|
|
41
|
+
switch (serialized.type) {
|
|
42
|
+
case "string":
|
|
43
|
+
if (serialized.enumValues) schema = require_common_schema_schema.stringLiterals(serialized.enumValues);
|
|
44
|
+
else schema = require_common_schema_schema.string();
|
|
45
|
+
break;
|
|
46
|
+
case "number":
|
|
47
|
+
schema = require_common_schema_schema.number();
|
|
48
|
+
break;
|
|
49
|
+
case "int":
|
|
50
|
+
schema = require_common_schema_schema.int();
|
|
51
|
+
break;
|
|
52
|
+
case "boolean":
|
|
53
|
+
schema = require_common_schema_schema.boolean();
|
|
54
|
+
break;
|
|
55
|
+
case "none":
|
|
56
|
+
schema = require_common_schema_schema.none();
|
|
57
|
+
break;
|
|
58
|
+
case "any":
|
|
59
|
+
schema = require_common_schema_schema.any();
|
|
60
|
+
break;
|
|
61
|
+
case "object":
|
|
62
|
+
if (serialized.object) {
|
|
63
|
+
const obj = {};
|
|
64
|
+
for (const [key, value] of Object.entries(serialized.object)) obj[key] = deserializeSchema(value);
|
|
65
|
+
schema = require_common_schema_schema.object(obj);
|
|
66
|
+
} else schema = require_common_schema_schema.object({});
|
|
67
|
+
break;
|
|
68
|
+
case "record":
|
|
69
|
+
if (serialized.itemType) schema = require_common_schema_schema.record(deserializeSchema(serialized.itemType));
|
|
70
|
+
else schema = require_common_schema_schema.record(require_common_schema_schema.any());
|
|
71
|
+
break;
|
|
72
|
+
case "array":
|
|
73
|
+
if (serialized.itemType) schema = require_common_schema_schema.array(deserializeSchema(serialized.itemType));
|
|
74
|
+
else schema = require_common_schema_schema.array(require_common_schema_schema.any());
|
|
75
|
+
break;
|
|
76
|
+
case "tuple":
|
|
77
|
+
if (serialized.tupleTypes) schema = require_common_schema_schema.tuple(serialized.tupleTypes.map((t) => deserializeSchema(t)));
|
|
78
|
+
else schema = require_common_schema_schema.tuple([]);
|
|
79
|
+
break;
|
|
80
|
+
case "union":
|
|
81
|
+
if (serialized.union) schema = require_common_schema_schema.union(serialized.union.map((t) => deserializeSchema(t)));
|
|
82
|
+
else schema = require_common_schema_schema.union([]);
|
|
83
|
+
break;
|
|
84
|
+
case "literal":
|
|
85
|
+
if (serialized.literalValue !== void 0) schema = require_common_schema_schema.literal(serialized.literalValue);
|
|
86
|
+
else schema = require_common_schema_schema.any();
|
|
87
|
+
break;
|
|
88
|
+
case "function":
|
|
89
|
+
if (serialized.args && serialized.ret) schema = require_common_schema_schema.func(serialized.args.map((t) => deserializeSchema(t)), deserializeSchema(serialized.ret));
|
|
90
|
+
else schema = require_common_schema_schema.func([], require_common_schema_schema.any());
|
|
91
|
+
break;
|
|
92
|
+
case "rpc":
|
|
93
|
+
if (serialized.info && serialized.ret) schema = require_common_schema_schema.rpc(deserializeSchema(serialized.info), deserializeSchema(serialized.ret));
|
|
94
|
+
else if (serialized.ret) schema = require_common_schema_schema.rpc(void 0, deserializeSchema(serialized.ret));
|
|
95
|
+
else schema = require_common_schema_schema.rpc();
|
|
96
|
+
break;
|
|
97
|
+
default:
|
|
98
|
+
schema = require_common_schema_schema.any();
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
if (serialized.optional) schema = schema.optional();
|
|
102
|
+
if (serialized.default !== void 0) schema = schema.default(serialized.default);
|
|
103
|
+
if (serialized.meta) schema = schema.meta(serialized.meta);
|
|
104
|
+
return schema;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
exports.deserializeSchema = deserializeSchema;
|
|
109
|
+
exports.serializeSchema = serializeSchema;
|
|
2
110
|
//# sourceMappingURL=serialize.cjs.map
|