@uniku/cli 0.5.0 → 0.5.1

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 (2) hide show
  1. package/build/bin.mjs +1 -1
  2. package/package.json +2 -2
package/build/bin.mjs CHANGED
@@ -3,5 +3,5 @@ import*as e from"@effect/platform-bun/BunRuntime";import*as t from"@effect/platf
3
3
  `)}function Ee(e){return e.hint?`Error: ${e.message}\n ${e.hint}`:`Error: ${e.message}`}const M=l.integer(`count`).pipe(l.withAlias(`n`),l.withDescription(`Number of IDs to generate`),l.withDefault(1)),N=l.boolean(`json`).pipe(l.withDescription(`Output as JSON`),l.withDefault(!1)),De=l.choiceWithValue(`uuid-version`,[[`4`,4],[`7`,7]]).pipe(l.withAlias(`v`),l.withDescription(`UUID version: 4, 7`),l.withDefault(4)),P=l.boolean(`lowercase`).pipe(l.withDescription(`Output in lowercase`),l.withDefault(!1)),F=c.make(`uuid`,{count:M,json:N,version:De,lowercase:P},r.fn(`cli.generate.uuid`)(function*({count:e,json:t,version:n,lowercase:r}){let i=yield*k,a=yield*be({count:e,version:n,lowercase:r});yield*i.write(j(a),{json:t})})).pipe(c.withDescription(`Generate UUIDs (v4 or v7)`),c.withExamples([{command:`uniku uuid -n 5 --json`,description:`Generate 5 UUIDs as a JSON array (machine-readable)`},{command:`uniku uuid -v 7`,description:`Generate a time-sortable UUID v7`},{command:`uniku uuid`,description:`Generate one random UUID v4`}])),Oe=l.string(`prefix`).pipe(l.withAlias(`p`),l.withDescription(`Type prefix, e.g. "user" for user_... (empty by default)`),l.withDefault(``)),I=c.make(`typeid`,{count:M,json:N,prefix:Oe},r.fn(`cli.generate.typeid`)(function*({count:e,json:t,prefix:n}){let r=yield*k,i=yield*ve({count:e,prefix:n});yield*r.write(j(i),{json:t})})).pipe(c.withDescription(`Generate TypeIDs`),c.withExamples([{command:`uniku typeid --prefix user`,description:`Generate a TypeID such as user_...`},{command:`uniku typeid -p api_key -n 5 --json`,description:`Generate 5 api_key TypeIDs as JSON`},{command:`uniku typeid`,description:`Generate a canonical prefixless TypeID`}])),ke=l.boolean(`monotonic`).pipe(l.withDescription(`Generate monotonically increasing ULIDs`),l.withDefault(!1)),Ae=l.string(`timestamp`).pipe(l.withDescription(`Unix timestamp in milliseconds (or "now")`),l.optional),L=c.make(`ulid`,{count:M,json:N,monotonic:ke,timestamp:Ae,lowercase:P},r.fn(`cli.generate.ulid`)(function*({count:e,json:t,monotonic:n,timestamp:r,lowercase:i}){let a=yield*k,s=o.getOrUndefined(r),c=yield*ye({count:e,monotonic:n,timestamp:s===void 0?void 0:yield*W(s),lowercase:i});yield*a.write(j(c),{json:t})})).pipe(c.withDescription(`Generate ULIDs`),c.withExamples([{command:`uniku ulid -n 10 --monotonic --json`,description:`Generate 10 strictly ordered ULIDs as a JSON array`},{command:`uniku ulid --timestamp 1720000000000`,description:`Generate a ULID for a fixed Unix timestamp (ms)`}])),je=l.integer(`size`).pipe(l.withAlias(`s`),l.withDescription(`Length of ID (1-256)`),l.withDefault(21)),Me=l.string(`alphabet`).pipe(l.withAlias(`a`),l.withDescription(`Custom alphabet or preset: hex, numeric, alpha`),l.optional),R=c.make(`nanoid`,{count:M,json:N,size:je,alphabet:Me},r.fn(`cli.generate.nanoid`)(function*({count:e,json:t,size:n,alphabet:r}){let i=yield*k,a=yield*he({count:e,size:n,alphabet:o.getOrUndefined(r)});yield*i.write(j(a),{json:t})})).pipe(c.withDescription(`Generate Nanoids`),c.withExamples([{command:`uniku nanoid -n 5 --json`,description:`Generate 5 Nanoids as a JSON array`},{command:`uniku nanoid --size 10 --alphabet hex`,description:`Generate a 10-char ID from the hex preset`}])),Ne=l.integer(`length`).pipe(l.withAlias(`l`),l.withDescription(`Length of ID (2-32)`),l.withDefault(24)),z=c.make(`cuid`,{count:M,json:N,length:Ne},r.fn(`cli.generate.cuid`)(function*({count:e,json:t,length:n}){let r=yield*k,i=yield*fe({count:e,length:n});yield*r.write(j(i),{json:t})})).pipe(c.withDescription(`Generate CUIDs (v2)`),c.withExamples([{command:`uniku cuid -n 5 --json`,description:`Generate 5 CUIDs as a JSON array`},{command:`uniku cuid --length 10`,description:`Generate a 10-char CUID`}])),Pe=l.string(`timestamp`).pipe(l.withDescription(`Unix timestamp in seconds (or "now")`),l.optional),B=c.make(`ksuid`,{count:M,json:N,timestamp:Pe},r.fn(`cli.generate.ksuid`)(function*({count:e,json:t,timestamp:n}){let r=yield*k,i=o.getOrUndefined(n),a=yield*pe({count:e,timestamp:i===void 0?void 0:yield*G(i)});yield*r.write(j(a),{json:t})})).pipe(c.withDescription(`Generate KSUIDs`),c.withExamples([{command:`uniku ksuid -n 5 --json`,description:`Generate 5 KSUIDs as a JSON array`},{command:`uniku ksuid --timestamp 1720000000`,description:`Generate a KSUID for a fixed Unix timestamp (s)`}])),Fe=l.string(`timestamp`).pipe(l.withDescription(`Unix timestamp in seconds (or "now")`),l.optional),V=c.make(`objectid`,{count:M,json:N,timestamp:Fe},r.fn(`cli.generate.objectid`)(function*({count:e,json:t,timestamp:n}){let r=yield*k,i=o.getOrUndefined(n),a=yield*ge({count:e,timestamp:i===void 0?void 0:yield*G(i)});yield*r.write(j(a),{json:t})})).pipe(c.withDescription(`Generate MongoDB ObjectIDs`),c.withExamples([{command:`uniku objectid -n 5 --json`,description:`Generate 5 ObjectIDs as a JSON array`},{command:`uniku objectid --timestamp 1720000000`,description:`Generate an ObjectID for a fixed Unix timestamp (s)`}])),Ie=l.string(`timestamp`).pipe(l.withDescription(`Unix timestamp in milliseconds (or "now")`),l.optional),Le=l.string(`node`).pipe(l.withDescription(`Node ID (0 to 2^node-bits - 1)`),l.optional),Re=l.string(`node-bits`).pipe(l.withDescription(`Number of bits allocated to the node ID (0-20, default 10)`),l.optional),H=c.make(`tsid`,{count:M,json:N,timestamp:Ie,node:Le,nodeBits:Re},r.fn(`cli.generate.tsid`)(function*({count:e,json:t,timestamp:n,node:r,nodeBits:i}){let a=yield*k,s=o.getOrUndefined(n),c=s===void 0?void 0:yield*W(s),l=o.getOrUndefined(r),u=l===void 0?void 0:yield*Je(l),d=o.getOrUndefined(i),f=yield*_e({count:e,timestamp:c,node:u,nodeBits:d===void 0?void 0:yield*Ye(d)});yield*a.write(j(f),{json:t})})).pipe(c.withDescription(`Generate TSIDs (64-bit Snowflake-style, time-sorted)`),c.withExamples([{command:`uniku tsid -n 5 --json`,description:`Generate 5 TSIDs as a JSON array`},{command:`uniku tsid --timestamp 1720000000000`,description:`Generate a TSID for a fixed Unix timestamp (ms)`},{command:`uniku tsid --node 42 --node-bits 10`,description:`Generate a TSID for a fixed node ID`}])),ze=c.make(`generate`).pipe(c.withDescription(`Generate new IDs`),c.withSubcommands([F,L,I,R,z,B,V,H]),c.withExamples([{command:`uniku generate uuid -n 5 --json`,description:`Generate 5 UUIDs as a JSON array`},{command:`uniku generate typeid --prefix user`,description:`Generate one user TypeID`},{command:`uniku generate ulid`,description:"Generate one ULID (subcommands also work top-level: `uniku ulid`)"}])),Be=F,Ve=L,He=I,Ue=R,We=z,Ge=B,Ke=V,qe=H,U=r.fn(`cli.generate.parseTimestamp`)(function*(e,t,n){if(e===`now`)return t(yield*u.currentTimeMillis);let r=Number(e);return!Number.isFinite(r)||r<0?yield*new E({code:`INVALID_TIMESTAMP`,message:`Invalid timestamp: "${e}"`,hint:n}):r}),W=e=>U(e,e=>e,`Provide a Unix timestamp in milliseconds or "now"`),G=e=>U(e,e=>Math.floor(e/1e3),`Provide a Unix timestamp in seconds or "now"`),K=r.fn(`cli.generate.parseNonNegativeInt`)(function*(e,t,n,r){let i=Number(e);return!Number.isInteger(i)||i<0?yield*new E({code:t,message:`Invalid ${n}: "${e}"`,hint:r}):i}),Je=e=>K(e,`INVALID_NODE`,`node`,`Provide a non-negative integer for --node`),Ye=e=>K(e,`INVALID_NODE_BITS`,`node-bits`,`Provide a non-negative integer (0-20) for --node-bits`);function Xe(e,t){switch(t){case`uuid`:return Ze(e);case`ulid`:return Qe(e);case`typeid`:return $e(e);case`ksuid`:return et(e);case`objectid`:return tt(e);case`cuid`:return nt(e);case`nanoid`:return rt(e);case`tsid`:return J(e)}}function q(e){return x.isValid(e)?{id:e,valid:!0,type:`uuid`,version:7}:b.isValid(e)?{id:e,valid:!0,type:`uuid`,version:4}:v.isValid(e)?{id:e,valid:!0,type:`typeid`,version:7}:y.isValid(e)?{id:e,valid:!0,type:`ulid`}:m.isValid(e)?{id:e,valid:!0,type:`ksuid`}:g.isValid(e)?{id:e,valid:!0,type:`objectid`}:J(e).valid?{id:e,valid:!0,type:`tsid`}:f.isValid(e)?{id:e,valid:!0,type:`cuid`}:h.isValid(e)?{id:e,valid:!0,type:`nanoid`}:{id:e,valid:!1,error:`malformed identifier`}}function Ze(e){return x.isValid(e)?{id:e,valid:!0,type:`uuid`,version:7}:b.isValid(e)?{id:e,valid:!0,type:`uuid`,version:4}:{id:e,valid:!1,type:`uuid`,error:`invalid UUID format`}}function Qe(e){return y.isValid(e)?{id:e,valid:!0,type:`ulid`}:{id:e,valid:!1,type:`ulid`,error:`invalid ULID format`}}function $e(e){return v.isValid(e)?{id:e,valid:!0,type:`typeid`,version:7}:{id:e,valid:!1,type:`typeid`,error:`invalid TypeID format`}}function et(e){return m.isValid(e)?{id:e,valid:!0,type:`ksuid`}:{id:e,valid:!1,type:`ksuid`,error:`invalid KSUID format`}}function tt(e){return g.isValid(e)?{id:e,valid:!0,type:`objectid`}:{id:e,valid:!1,type:`objectid`,error:`invalid ObjectID format`}}function nt(e){return f.isValid(e)?{id:e,valid:!0,type:`cuid`}:{id:e,valid:!1,type:`cuid`,error:`invalid CUID format`}}function rt(e){return h.isValid(e)?{id:e,valid:!0,type:`nanoid`}:{id:e,valid:!1,type:`nanoid`,error:`invalid Nanoid format`}}function J(e){try{return _.fromString(e),{id:e,valid:!0,type:`tsid`}}catch{return{id:e,valid:!1,type:`tsid`,error:`invalid TSID format`}}}function it(e,t){let n=t??at(e);if(!n)return null;switch(n){case`uuid`:return ot(e);case`ulid`:return st(e);case`typeid`:return ct(e);case`ksuid`:return lt(e);case`objectid`:return ut(e);case`cuid`:return dt(e);case`nanoid`:return ft(e);case`tsid`:return pt(e)}}function at(e){let t=q(e);return t.valid?t.type??null:null}function ot(e){if(x.isValid(e)){let t=x.timestamp(e),n=x.toBytes(e),r=Buffer.from(n.slice(10)).toString(`hex`);return{id:e,type:`uuid`,version:7,timestamp:new Date(t).toISOString(),timestamp_ms:t,random:r}}return b.isValid(e)?{id:e,type:`uuid`,version:4,note:`This ID type contains no decodable metadata.`}:{id:e,type:`uuid`,note:`Unrecognized UUID version.`}}function st(e){let t=y.timestamp(e),n=e.slice(10);return{id:e,type:`ulid`,timestamp:new Date(t).toISOString(),timestamp_ms:t,random:n}}function ct(e){if(!v.isValid(e))return{id:e,type:`typeid`,note:`Unrecognized TypeID format.`};let t=v.timestamp(e),n=v.toBytes(e),r=Buffer.from(n.slice(10)).toString(`hex`);return{id:e,type:`typeid`,version:7,prefix:v.prefix(e),suffix:v.suffix(e),timestamp:new Date(t).toISOString(),timestamp_ms:t,random:r}}function lt(e){let t=m.timestamp(e),n=m.toBytes(e),r=Buffer.from(n.slice(4)).toString(`hex`);return{id:e,type:`ksuid`,timestamp:new Date(t).toISOString(),timestamp_ms:t,random:r}}function ut(e){let t=g.timestamp(e),n=g.toBytes(e),r=Buffer.from(n.slice(4)).toString(`hex`);return{id:e,type:`objectid`,timestamp:new Date(t).toISOString(),timestamp_ms:t,random:r}}function dt(e){return{id:e,type:`cuid`,note:`This ID type contains no decodable metadata.`}}function ft(e){return{id:e,type:`nanoid`,note:`This ID type contains no decodable metadata.`}}function pt(e){let t;try{t=_.fromString(e)}catch{return{id:e,type:`tsid`,note:`Unrecognized TSID format.`}}let n=_.timestamp(t),r=(t&4194303n).toString(16);return{id:e,type:`tsid`,timestamp:new Date(n).toISOString(),timestamp_ms:n,random:r}}function mt(e){let t=e.indexOf(`--`),n=(t===-1?e:e.slice(0,t)).map(e=>e===`-V`?`--version`:e);if(t===-1)return n;let r=e.slice(t+1);return bt(n)?[...n,...r.map(yt)]:[...n,`--`,...r]}const ht=`\0uniku-literal:`,gt=new Set([`inspect`,`validate`]),_t=new Set([`--completions`,`--log-level`]);function vt(e){return e.startsWith(ht)?e.slice(15):e}function yt(e){return`${ht}${e}`}function bt(e){for(let t=0;t<e.length;t+=1){let n=e[t];if(n.startsWith(`-`)){_t.has(n)&&(t+=1);continue}return gt.has(n)}return!1}const xt=s.string(`id`).pipe(s.withDescription(`The ID to inspect`)),St=l.choice(`type`,C).pipe(l.withDescription(`ID type (auto-detected if omitted)`),l.optional),Ct=l.boolean(`json`).pipe(l.withDescription(`Output as JSON`),l.withDefault(!1)),wt=c.make(`inspect`,{id:xt,type:St,json:Ct},r.fn(`cli.inspect`)(function*({id:e,type:t,json:n}){let r=yield*k,i=o.getOrUndefined(t),a=vt(e),s=it(a,i);if(!s)return yield*new E({code:`UNKNOWN_ID_TYPE`,message:`Could not identify ID type for: "${a}"`,hint:`Use --type to specify the ID type`});yield*r.write(Se(s),{json:n})})).pipe(c.withDescription(`Decode and inspect an ID`),c.withExamples([{command:`uniku inspect 01J9YR2V5TZB8Q4W6X0E1N7M3S --json`,description:`Decode an ID to structured JSON (type, version, timestamp)`},{command:`uniku inspect --type uuid 3F2504E0-4F89-41D3-9A0C-0305E82C3301`,description:`Skip auto-detection`},{command:`uniku inspect -- --tricky-id`,description:`Inspect an ID that starts with a dash`}]));var Tt=class e extends S.Service()(`uniku/cli/StdinService`){static layer=a.succeed(e,e.of({readLines:r.fn(`StdinService.readLines`)(()=>r.callback(e=>{let t=[];process.stdin.on(`data`,e=>{t.push(e)}),process.stdin.on(`end`,()=>{let n=Buffer.concat(t).toString(`utf-8`).split(`
4
4
  `).map(e=>e.trim()).filter(e=>e.length>0);e(r.succeed(n))}),process.stdin.on(`error`,t=>{e(r.fail(new E({code:`STDIN_ERROR`,message:t.message})))}),process.stdin.resume()}))}))};const Et=s.string(`id`).pipe(s.withDescription(`The ID to validate`),s.optional),Dt=l.choice(`type`,C).pipe(l.withDescription(`Expected ID type (auto-detected if omitted)`),l.optional),Ot=l.boolean(`stdin`).pipe(l.withDescription(`Read IDs from stdin (one per line)`),l.withDefault(!1)),kt=l.boolean(`json`).pipe(l.withDescription(`Output validation results as JSON`),l.withDefault(!1)),At=l.boolean(`quiet`).pipe(l.withDescription(`No output, exit code only`),l.withDefault(!1)),jt=c.make(`validate`,{id:Et,type:Dt,stdin:Ot,json:kt,quiet:At},r.fn(`cli.validate`)(function*({id:e,type:t,stdin:n,json:r,quiet:i}){let a=yield*k,s=yield*Tt,c=o.getOrUndefined(t),l;if(n){if(l=yield*s.readLines(),l.length===0)return yield*new E({code:`NO_INPUT`,message:`No IDs provided on stdin`})}else if(o.isSome(e))l=[vt(e.value)];else return yield*new E({code:`NO_INPUT`,message:`No ID provided`,hint:`Pass an ID as argument or use --stdin`});let u=l.map(e=>c?Xe(e,c):q(e));if(i||(yield*a.write(xe(u),{json:r})),u.some(e=>!e.valid))return yield*new ue({message:`One or more IDs are invalid`})})).pipe(c.withDescription(`Check if an ID is valid`),c.withExamples([{command:`uniku validate 3F2504E0-4F89-41D3-9A0C-0305E82C3301 --json`,description:`Validate one ID, result as JSON`},{command:`cat ids.txt | uniku validate --stdin --json`,description:`Validate many IDs (one per line), results as a JSON array`},{command:`uniku validate --quiet 01J9YR2V5TZB8Q4W6X0E1N7M3S`,description:`Exit code only: 0 valid, 2 invalid`}])),Mt=c.make(`uniku`).pipe(c.withDescription(`Generate and validate unique identifiers`),c.withExamples([{command:`uniku uuid -n 5 --json`,description:`Generate 5 UUIDs as a JSON array (machine-readable)`},{command:`uniku typeid --prefix user`,description:`Generate one user TypeID`},{command:`uniku ulid`,description:`Generate one ULID`},{command:`uniku inspect <id> --json`,description:`Decode an ID (type, version, timestamp) as JSON`},{command:`cat ids.txt | uniku validate --stdin --json`,description:`Validate IDs from stdin, one per line`}]),c.withSubcommands([ze,jt,wt,Be,Ve,He,Ue,We,Ge,Ke,qe])),Nt=e=>c.runWith(Mt,{version:e});function Pt(e){return e.includes(`--json`)}const Ft=w.type().pipe(w.tag(`CliError`,e=>e.exitCode),w.tag(`ValidationFailedError`,e=>e.exitCode),w.tag(`ShowHelp`,e=>+(e.errors.length>0)),w.tag(`UnrecognizedOption`,`DuplicateOption`,`MissingOption`,`MissingArgument`,`InvalidValue`,`UnknownSubcommand`,`UserError`,()=>1),w.exhaustive),It=r.fn(`cli.handleCliFailure`)(function*(e,t){yield*w.value(e).pipe(w.tag(`CliError`,`ValidationFailedError`,e=>k.use(n=>n.writeError(Ce(e),{json:Pt(t)}))),w.tag(`ShowHelp`,()=>r.void),w.tag(`UnrecognizedOption`,`DuplicateOption`,`MissingOption`,`MissingArgument`,`InvalidValue`,`UnknownSubcommand`,`UserError`,e=>ee.error(`Error: ${e.message}`)),w.exhaustive),process.exitCode=Ft(e)});var Y=class e extends S.Service()(`uniku/cli/UpdateCheckService`){static layer=a.sync(e,()=>Zt())};const X=`@uniku/cli`;function Lt(){let e=process.getuid;if(typeof e==`function`)return`uid-${e()}`;try{let e=oe().username.replace(/[^0-9A-Za-z._-]/g,`_`);return e?`user-${e}`:null}catch{return null}}function Rt(){let e=Lt(),t=e?`uniku-update-check-${e}.json`:`uniku-update-check.json`;return ce(ae(),t)}const zt=Rt();function Bt(e){let t=e.match(/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/);return t?{major:Number(t[1]),minor:Number(t[2]),patch:Number(t[3]),prerelease:t[4]??null}:null}function Vt(e,t){let n=Bt(e),r=Bt(t);return!n||!r?!1:n.major===r.major?n.minor===r.minor?n.patch===r.patch?n.prerelease===null&&r.prerelease!==null?!0:(n.prerelease!==null&&r.prerelease,!1):n.patch>r.patch:n.minor>r.minor:n.major>r.major}function Z(e){return T.option(T.string(e)).pipe(r.catch(()=>r.succeed(o.none())))}function Q(e){return o.isSome(e)&&e.value.length>0}const Ht=r.all({noUpdateNotifier:Z(`NO_UPDATE_NOTIFIER`),ci:Z(`CI`),continuousIntegration:Z(`CONTINUOUS_INTEGRATION`),nodeEnv:Z(`NODE_ENV`)});function Ut(e=process.stderr.isTTY){return Ht.pipe(r.map(t=>Q(t.noUpdateNotifier)||Q(t.ci)||Q(t.continuousIntegration)||o.isSome(t.nodeEnv)&&t.nodeEnv.value===`test`||!e))}function Wt(e,t){if(t){let t=e.isStandaloneBinary?`Download at https://github.com/jkomyno/uniku/releases`:`Run \`npm install -g ${X}\` to update`;return[``,` Update available: ${e.currentVersion} → ${e.latestVersion}`,` ${t}`,` Set NO_UPDATE_NOTIFIER=1 to disable`,``].join(`
5
5
  `)}let n=`\x1B[2m`,r=`\x1B[36m`,i=`\x1B[0m`,a=e.isStandaloneBinary?`Download at ${r}https://github.com/jkomyno/uniku/releases${i}`:`Run ${r}\`npm install -g ${X}\`${i} to update`;return[``,` ${n}Update available:${i} ${n}${e.currentVersion}${i} ${n}→${i} ${e.latestVersion}${i}`,` ${a}`,` ${n}Set NO_UPDATE_NOTIFIER=1 to disable${i}`,``].join(`
6
- `)}function Gt(e){return Z(`NO_COLOR`).pipe(r.map(t=>Wt(e,Q(t))))}function Kt(e,t){return o.isSome(t)&&!e.includes(`--json`)}function qt(e){try{let t=ne(e,`utf-8`),n=JSON.parse(t);if(typeof n!=`object`||!n)return null;let r=n;return typeof r.checkedAt!=`number`||!Number.isFinite(r.checkedAt)||r.latestVersion!==void 0&&typeof r.latestVersion!=`string`?null:r.latestVersion===void 0?{checkedAt:r.checkedAt}:{latestVersion:r.latestVersion,checkedAt:r.checkedAt}}catch{return null}}function Jt(e,t){try{te(se(t),{recursive:!0});let n=`${t}.tmp`;ie(n,JSON.stringify(e)),re(n,t)}catch{}}function Yt(e){return r.tryPromise({try:t=>fetch(`https://registry.npmjs.org/%40uniku%2Fcli/latest`,{headers:{Accept:`application/json`,"User-Agent":`${X}/${e}`},signal:AbortSignal.any([t,AbortSignal.timeout(5e3)])}).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();if(!t.version)throw Error(`Missing version field`);return t.version}),catch:()=>Error(`fetch failed`)}).pipe(r.catch(()=>r.succeed(null)))}function Xt(){try{return typeof __STANDALONE_BINARY__<`u`&&__STANDALONE_BINARY__===!0}catch{return!1}}function Zt(e={}){let t=e.cacheFile??zt,n=e.fetchLatestVersion??Yt,i=e.now??Date.now,a=e.isStandaloneBinary??Xt,s=e.isStderrTTY??(()=>process.stderr.isTTY),c=e.writeStderr??(e=>process.stderr.write(e));return Y.of({check:r.fn(`UpdateCheckService.check`)(function*(e){if(yield*Ut(s()))return o.none();let r=qt(t),c=i();if(r&&c-r.checkedAt<864e5)return r.latestVersion&&Vt(r.latestVersion,e)?o.some({currentVersion:e,latestVersion:r.latestVersion,isStandaloneBinary:a()}):o.none();let l=yield*n(e);return l===null?(Jt({checkedAt:c},t),o.none()):(Jt({latestVersion:l,checkedAt:c},t),Vt(l,e)?o.some({currentVersion:e,latestVersion:l,isStandaloneBinary:a()}):o.none())},r.catch(()=>r.succeed(o.none()))),notify:r.fn(`UpdateCheckService.notify`)(function*(e){let t=yield*Gt(e);yield*r.sync(()=>{c(t)})})})}var $=`0.5.0`;const Qt=Nt($),$t=a.mergeAll(k.layer,Tt.layer,Y.layer,t.layer);r.gen(function*(){let e=yield*Y,t=mt(process.argv.slice(2)),a=yield*r.forkChild(e.check($),{startImmediately:!0});yield*Qt(t).pipe(r.catch(e=>It(e,t)));let s=yield*i.join(a).pipe(r.timeoutOption(n.millis(250)));yield*i.interrupt(a);let c=o.flatten(s);Kt(t,c)&&(yield*e.notify(c.value))}).pipe(r.provide($t),e.runMain);export{};
6
+ `)}function Gt(e){return Z(`NO_COLOR`).pipe(r.map(t=>Wt(e,Q(t))))}function Kt(e,t){return o.isSome(t)&&!e.includes(`--json`)}function qt(e){try{let t=ne(e,`utf-8`),n=JSON.parse(t);if(typeof n!=`object`||!n)return null;let r=n;return typeof r.checkedAt!=`number`||!Number.isFinite(r.checkedAt)||r.latestVersion!==void 0&&typeof r.latestVersion!=`string`?null:r.latestVersion===void 0?{checkedAt:r.checkedAt}:{latestVersion:r.latestVersion,checkedAt:r.checkedAt}}catch{return null}}function Jt(e,t){try{te(se(t),{recursive:!0});let n=`${t}.tmp`;ie(n,JSON.stringify(e)),re(n,t)}catch{}}function Yt(e){return r.tryPromise({try:t=>fetch(`https://registry.npmjs.org/%40uniku%2Fcli/latest`,{headers:{Accept:`application/json`,"User-Agent":`${X}/${e}`},signal:AbortSignal.any([t,AbortSignal.timeout(5e3)])}).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();if(!t.version)throw Error(`Missing version field`);return t.version}),catch:()=>Error(`fetch failed`)}).pipe(r.catch(()=>r.succeed(null)))}function Xt(){try{return typeof __STANDALONE_BINARY__<`u`&&__STANDALONE_BINARY__===!0}catch{return!1}}function Zt(e={}){let t=e.cacheFile??zt,n=e.fetchLatestVersion??Yt,i=e.now??Date.now,a=e.isStandaloneBinary??Xt,s=e.isStderrTTY??(()=>process.stderr.isTTY),c=e.writeStderr??(e=>process.stderr.write(e));return Y.of({check:r.fn(`UpdateCheckService.check`)(function*(e){if(yield*Ut(s()))return o.none();let r=qt(t),c=i();if(r&&c-r.checkedAt<864e5)return r.latestVersion&&Vt(r.latestVersion,e)?o.some({currentVersion:e,latestVersion:r.latestVersion,isStandaloneBinary:a()}):o.none();let l=yield*n(e);return l===null?(Jt({checkedAt:c},t),o.none()):(Jt({latestVersion:l,checkedAt:c},t),Vt(l,e)?o.some({currentVersion:e,latestVersion:l,isStandaloneBinary:a()}):o.none())},r.catch(()=>r.succeed(o.none()))),notify:r.fn(`UpdateCheckService.notify`)(function*(e){let t=yield*Gt(e);yield*r.sync(()=>{c(t)})})})}var $=`0.5.1`;const Qt=Nt($),$t=a.mergeAll(k.layer,Tt.layer,Y.layer,t.layer);r.gen(function*(){let e=yield*Y,t=mt(process.argv.slice(2)),a=yield*r.forkChild(e.check($),{startImmediately:!0});yield*Qt(t).pipe(r.catch(e=>It(e,t)));let s=yield*i.join(a).pipe(r.timeoutOption(n.millis(250)));yield*i.interrupt(a);let c=o.flatten(s);Kt(t,c)&&(yield*e.notify(c.value))}).pipe(r.provide($t),e.runMain);export{};
7
7
  //# sourceMappingURL=bin.mjs.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@uniku/cli",
4
- "version": "0.5.0",
4
+ "version": "0.5.1",
5
5
  "description": "CLI tool for generating and validating unique identifiers",
6
6
  "author": {
7
7
  "name": "Alberto Schiabel",
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "@effect/platform-bun": "4.0.0-beta.93",
34
34
  "effect": "4.0.0-beta.93",
35
- "uniku": "0.3.0"
35
+ "uniku": "0.3.1"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@effect/vitest": "4.0.0-beta.93",