functype-os 0.3.0 → 0.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/dist/env/Env.d.ts CHANGED
@@ -9,6 +9,7 @@ declare const EnvCompanion: {
9
9
  getOrDefault: (name: string, defaultValue: string) => string;
10
10
  has: (name: string) => boolean;
11
11
  entries: () => List<readonly [string, string]>;
12
+ parse: <T>(name: string, parser: (value: string) => T) => Either<EnvError, T>;
12
13
  };
13
14
  declare const Env: typeof EnvConstructor & typeof EnvCompanion;
14
15
  //#endregion
package/dist/env/Env.js CHANGED
@@ -1,2 +1,2 @@
1
- import{EnvError as e}from"../errors/errors.js";import{Left as t,List as n,Option as r,Right as i}from"functype";const a=Object.assign(e=>r(process.env[e]),{get:e=>r(process.env[e]),getRequired:n=>{let r=process.env[n];return r===void 0?t(e(n)):i(r)},getOrDefault:(e,t)=>process.env[e]??t,has:e=>process.env[e]!==void 0,entries:()=>n(Object.entries(process.env).filter(e=>e[1]!==void 0).map(([e,t])=>[e,t]))});export{a as Env};
1
+ import{EnvError as e}from"../errors/errors.js";import{Left as t,List as n,Option as r,Right as i}from"functype";const a=Object.assign(e=>r(process.env[e]),{get:e=>r(process.env[e]),getRequired:n=>{let r=process.env[n];return r===void 0?t(e(n)):i(r)},getOrDefault:(e,t)=>process.env[e]??t,has:e=>process.env[e]!==void 0,entries:()=>n(Object.entries(process.env).filter(e=>e[1]!==void 0).map(([e,t])=>[e,t])),parse:(n,r)=>{let a=process.env[n];if(a===void 0)return t(e(n));try{let o=r(a);return typeof o==`number`&&isNaN(o)?t(e(n,`Cannot parse '${a}' as number for '${n}'`)):i(o)}catch(r){return t(e(n,`Failed to parse '${n}': ${r instanceof Error?r.message:String(r)}`))}}});export{a as Env};
2
2
  //# sourceMappingURL=Env.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Env.js","names":[],"sources":["../../src/env/Env.ts"],"sourcesContent":["import type { Either } from \"functype\"\nimport { Left, List, Option, Right } from \"functype\"\n\nimport { EnvError } from \"../errors/errors\"\n\nconst EnvConstructor = (name: string): Option<string> => Option(process.env[name])\n\nconst EnvCompanion = {\n get: (name: string): Option<string> => Option(process.env[name]),\n\n getRequired: (name: string): Either<EnvError, string> => {\n const value = process.env[name]\n return value !== undefined ? Right(value) : Left(EnvError(name))\n },\n\n getOrDefault: (name: string, defaultValue: string): string => process.env[name] ?? defaultValue,\n\n has: (name: string): boolean => process.env[name] !== undefined,\n\n entries: (): List<readonly [string, string]> => {\n const pairs: Readonly<Array<readonly [string, string]>> = Object.entries(process.env)\n .filter((entry): entry is [string, string] => entry[1] !== undefined)\n .map(([k, v]) => [k, v] as const)\n return List(pairs)\n },\n}\n\nexport const Env: typeof EnvConstructor & typeof EnvCompanion = Object.assign(EnvConstructor, EnvCompanion)\n"],"mappings":"gHA2BA,MAAa,EAAmD,OAAO,OAtB/C,GAAiC,EAAO,QAAQ,IAAI,GAAM,CAE7D,CACnB,IAAM,GAAiC,EAAO,QAAQ,IAAI,GAAM,CAEhE,YAAc,GAA2C,CACvD,IAAM,EAAQ,QAAQ,IAAI,GAC1B,OAAO,IAAU,IAAA,GAA2B,EAAK,EAAS,EAAK,CAAC,CAAnC,EAAM,EAAM,EAG3C,cAAe,EAAc,IAAiC,QAAQ,IAAI,IAAS,EAEnF,IAAM,GAA0B,QAAQ,IAAI,KAAU,IAAA,GAEtD,YAIS,EAHmD,OAAO,QAAQ,QAAQ,IAAI,CAClF,OAAQ,GAAqC,EAAM,KAAO,IAAA,GAAU,CACpE,KAAK,CAAC,EAAG,KAAO,CAAC,EAAG,EAAE,CAAU,CACjB,CAErB,CAE0G"}
1
+ {"version":3,"file":"Env.js","names":[],"sources":["../../src/env/Env.ts"],"sourcesContent":["import type { Either } from \"functype\"\nimport { Left, List, Option, Right } from \"functype\"\n\nimport { EnvError } from \"../errors/errors\"\n\nconst EnvConstructor = (name: string): Option<string> => Option(process.env[name])\n\nconst EnvCompanion = {\n get: (name: string): Option<string> => Option(process.env[name]),\n\n getRequired: (name: string): Either<EnvError, string> => {\n const value = process.env[name]\n return value !== undefined ? Right(value) : Left(EnvError(name))\n },\n\n getOrDefault: (name: string, defaultValue: string): string => process.env[name] ?? defaultValue,\n\n has: (name: string): boolean => process.env[name] !== undefined,\n\n entries: (): List<readonly [string, string]> => {\n const pairs: Readonly<Array<readonly [string, string]>> = Object.entries(process.env)\n .filter((entry): entry is [string, string] => entry[1] !== undefined)\n .map(([k, v]) => [k, v] as const)\n return List(pairs)\n },\n\n parse: <T>(name: string, parser: (value: string) => T): Either<EnvError, T> => {\n const value = process.env[name]\n if (value === undefined) {\n return Left(EnvError(name))\n }\n try {\n const parsed = parser(value)\n if (typeof parsed === \"number\" && isNaN(parsed)) {\n return Left(EnvError(name, `Cannot parse '${value}' as number for '${name}'`))\n }\n return Right(parsed)\n } catch (error) {\n return Left(\n EnvError(name, `Failed to parse '${name}': ${error instanceof Error ? error.message : String(error)}`),\n )\n }\n },\n}\n\nexport const Env: typeof EnvConstructor & typeof EnvCompanion = Object.assign(EnvConstructor, EnvCompanion)\n"],"mappings":"gHA6CA,MAAa,EAAmD,OAAO,OAxC/C,GAAiC,EAAO,QAAQ,IAAI,GAAM,CAE7D,CACnB,IAAM,GAAiC,EAAO,QAAQ,IAAI,GAAM,CAEhE,YAAc,GAA2C,CACvD,IAAM,EAAQ,QAAQ,IAAI,GAC1B,OAAO,IAAU,IAAA,GAA2B,EAAK,EAAS,EAAK,CAAC,CAAnC,EAAM,EAAM,EAG3C,cAAe,EAAc,IAAiC,QAAQ,IAAI,IAAS,EAEnF,IAAM,GAA0B,QAAQ,IAAI,KAAU,IAAA,GAEtD,YAIS,EAHmD,OAAO,QAAQ,QAAQ,IAAI,CAClF,OAAQ,GAAqC,EAAM,KAAO,IAAA,GAAU,CACpE,KAAK,CAAC,EAAG,KAAO,CAAC,EAAG,EAAE,CAAU,CACjB,CAGpB,OAAW,EAAc,IAAsD,CAC7E,IAAM,EAAQ,QAAQ,IAAI,GAC1B,GAAI,IAAU,IAAA,GACZ,OAAO,EAAK,EAAS,EAAK,CAAC,CAE7B,GAAI,CACF,IAAM,EAAS,EAAO,EAAM,CAI5B,OAHI,OAAO,GAAW,UAAY,MAAM,EAAO,CACtC,EAAK,EAAS,EAAM,iBAAiB,EAAM,mBAAmB,EAAK,GAAG,CAAC,CAEzE,EAAM,EAAO,OACb,EAAO,CACd,OAAO,EACL,EAAS,EAAM,oBAAoB,EAAK,KAAK,aAAiB,MAAQ,EAAM,QAAU,OAAO,EAAM,GAAG,CACvG,GAGN,CAE0G"}
@@ -22,11 +22,19 @@ type ConfigError = {
22
22
  readonly candidates: readonly string[];
23
23
  readonly message: string;
24
24
  };
25
- type OsError = EnvError | PathError | FsError | ConfigError;
25
+ type ProcessError = {
26
+ readonly _tag: "ProcessError";
27
+ readonly command: string;
28
+ readonly exitCode: number | null;
29
+ readonly stderr: string;
30
+ readonly message: string;
31
+ };
32
+ type OsError = EnvError | PathError | FsError | ConfigError | ProcessError;
26
33
  declare const EnvError: (variable: string, message?: string) => EnvError;
27
34
  declare const PathError: (path: string, reason: PathError["reason"], message?: string) => PathError;
28
35
  declare const FsError: (path: string, operation: string, cause: Error) => FsError;
29
36
  declare const ConfigError: (candidates: readonly string[], message?: string) => ConfigError;
37
+ declare const ProcessError: (command: string, exitCode: number | null, stderr: string, message?: string) => ProcessError;
30
38
  //#endregion
31
- export { ConfigError, EnvError, FsError, OsError, PathError };
39
+ export { ConfigError, EnvError, FsError, OsError, PathError, ProcessError };
32
40
  //# sourceMappingURL=errors.d.ts.map
@@ -1,2 +1,2 @@
1
- const e=(e,t)=>({_tag:`EnvError`,variable:e,message:t??`Environment variable '${e}' is not set`}),t=(e,t,n)=>({_tag:`PathError`,path:e,reason:t,message:n??(t===`unresolved_variable`?`Unresolved variable in path: ${e}`:`Invalid path: ${e}`)}),n=(e,t,n)=>({_tag:`FsError`,path:e,operation:t,cause:n,message:`${t} failed for '${e}': ${n.message}`}),r=(e,t)=>({_tag:`ConfigError`,candidates:e,message:t??`No config file found among candidates: ${e.join(`, `)}`});export{r as ConfigError,e as EnvError,n as FsError,t as PathError};
1
+ const e=(e,t)=>({_tag:`EnvError`,variable:e,message:t??`Environment variable '${e}' is not set`}),t=(e,t,n)=>({_tag:`PathError`,path:e,reason:t,message:n??(t===`unresolved_variable`?`Unresolved variable in path: ${e}`:`Invalid path: ${e}`)}),n=(e,t,n)=>({_tag:`FsError`,path:e,operation:t,cause:n,message:`${t} failed for '${e}': ${n.message}`}),r=(e,t)=>({_tag:`ConfigError`,candidates:e,message:t??`No config file found among candidates: ${e.join(`, `)}`}),i=(e,t,n,r)=>({_tag:`ProcessError`,command:e,exitCode:t,stderr:n,message:r??`Command '${e}' failed (exit ${t}): ${n}`});export{r as ConfigError,e as EnvError,n as FsError,t as PathError,i as ProcessError};
2
2
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../../src/errors/errors.ts"],"sourcesContent":["export type EnvError = {\n readonly _tag: \"EnvError\"\n readonly variable: string\n readonly message: string\n}\n\nexport type PathError = {\n readonly _tag: \"PathError\"\n readonly path: string\n readonly reason: \"unresolved_variable\" | \"invalid_path\"\n readonly message: string\n}\n\nexport type FsError = {\n readonly _tag: \"FsError\"\n readonly path: string\n readonly operation: string\n readonly cause: Error\n readonly message: string\n}\n\nexport type ConfigError = {\n readonly _tag: \"ConfigError\"\n readonly candidates: readonly string[]\n readonly message: string\n}\n\nexport type OsError = EnvError | PathError | FsError | ConfigError\n\nexport const EnvError = (variable: string, message?: string): EnvError => ({\n _tag: \"EnvError\",\n variable,\n message: message ?? `Environment variable '${variable}' is not set`,\n})\n\nexport const PathError = (path: string, reason: PathError[\"reason\"], message?: string): PathError => ({\n _tag: \"PathError\",\n path,\n reason,\n message:\n message ?? (reason === \"unresolved_variable\" ? `Unresolved variable in path: ${path}` : `Invalid path: ${path}`),\n})\n\nexport const FsError = (path: string, operation: string, cause: Error): FsError => ({\n _tag: \"FsError\",\n path,\n operation,\n cause,\n message: `${operation} failed for '${path}': ${cause.message}`,\n})\n\nexport const ConfigError = (candidates: readonly string[], message?: string): ConfigError => ({\n _tag: \"ConfigError\",\n candidates,\n message: message ?? `No config file found among candidates: ${candidates.join(\", \")}`,\n})\n"],"mappings":"AA6BA,MAAa,GAAY,EAAkB,KAAgC,CACzE,KAAM,WACN,WACA,QAAS,GAAW,yBAAyB,EAAS,cACvD,EAEY,GAAa,EAAc,EAA6B,KAAiC,CACpG,KAAM,YACN,OACA,SACA,QACE,IAAY,IAAW,sBAAwB,gCAAgC,IAAS,iBAAiB,KAC5G,EAEY,GAAW,EAAc,EAAmB,KAA2B,CAClF,KAAM,UACN,OACA,YACA,QACA,QAAS,GAAG,EAAU,eAAe,EAAK,KAAK,EAAM,UACtD,EAEY,GAAe,EAA+B,KAAmC,CAC5F,KAAM,cACN,aACA,QAAS,GAAW,0CAA0C,EAAW,KAAK,KAAK,GACpF"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../../src/errors/errors.ts"],"sourcesContent":["export type EnvError = {\n readonly _tag: \"EnvError\"\n readonly variable: string\n readonly message: string\n}\n\nexport type PathError = {\n readonly _tag: \"PathError\"\n readonly path: string\n readonly reason: \"unresolved_variable\" | \"invalid_path\"\n readonly message: string\n}\n\nexport type FsError = {\n readonly _tag: \"FsError\"\n readonly path: string\n readonly operation: string\n readonly cause: Error\n readonly message: string\n}\n\nexport type ConfigError = {\n readonly _tag: \"ConfigError\"\n readonly candidates: readonly string[]\n readonly message: string\n}\n\nexport type ProcessError = {\n readonly _tag: \"ProcessError\"\n readonly command: string\n readonly exitCode: number | null\n readonly stderr: string\n readonly message: string\n}\n\nexport type OsError = EnvError | PathError | FsError | ConfigError | ProcessError\n\nexport const EnvError = (variable: string, message?: string): EnvError => ({\n _tag: \"EnvError\",\n variable,\n message: message ?? `Environment variable '${variable}' is not set`,\n})\n\nexport const PathError = (path: string, reason: PathError[\"reason\"], message?: string): PathError => ({\n _tag: \"PathError\",\n path,\n reason,\n message:\n message ?? (reason === \"unresolved_variable\" ? `Unresolved variable in path: ${path}` : `Invalid path: ${path}`),\n})\n\nexport const FsError = (path: string, operation: string, cause: Error): FsError => ({\n _tag: \"FsError\",\n path,\n operation,\n cause,\n message: `${operation} failed for '${path}': ${cause.message}`,\n})\n\nexport const ConfigError = (candidates: readonly string[], message?: string): ConfigError => ({\n _tag: \"ConfigError\",\n candidates,\n message: message ?? `No config file found among candidates: ${candidates.join(\", \")}`,\n})\n\nexport const ProcessError = (\n command: string,\n exitCode: number | null,\n stderr: string,\n message?: string,\n): ProcessError => ({\n _tag: \"ProcessError\",\n command,\n exitCode,\n stderr,\n message: message ?? `Command '${command}' failed (exit ${exitCode}): ${stderr}`,\n})\n"],"mappings":"AAqCA,MAAa,GAAY,EAAkB,KAAgC,CACzE,KAAM,WACN,WACA,QAAS,GAAW,yBAAyB,EAAS,cACvD,EAEY,GAAa,EAAc,EAA6B,KAAiC,CACpG,KAAM,YACN,OACA,SACA,QACE,IAAY,IAAW,sBAAwB,gCAAgC,IAAS,iBAAiB,KAC5G,EAEY,GAAW,EAAc,EAAmB,KAA2B,CAClF,KAAM,UACN,OACA,YACA,QACA,QAAS,GAAG,EAAU,eAAe,EAAK,KAAK,EAAM,UACtD,EAEY,GAAe,EAA+B,KAAmC,CAC5F,KAAM,cACN,aACA,QAAS,GAAW,0CAA0C,EAAW,KAAK,KAAK,GACpF,EAEY,GACX,EACA,EACA,EACA,KACkB,CAClB,KAAM,eACN,UACA,WACA,SACA,QAAS,GAAW,YAAY,EAAQ,iBAAiB,EAAS,KAAK,IACxE"}
@@ -1,2 +1,2 @@
1
- import { ConfigError, EnvError, FsError, OsError, PathError } from "./errors.js";
2
- export { ConfigError, EnvError, FsError, type OsError, PathError };
1
+ import { ConfigError, EnvError, FsError, OsError, PathError, ProcessError } from "./errors.js";
2
+ export { ConfigError, EnvError, FsError, type OsError, PathError, ProcessError };
@@ -1 +1 @@
1
- import{ConfigError as e,EnvError as t,FsError as n,PathError as r}from"./errors.js";export{e as ConfigError,t as EnvError,n as FsError,r as PathError};
1
+ import{ConfigError as e,EnvError as t,FsError as n,PathError as r,ProcessError as i}from"./errors.js";export{e as ConfigError,t as EnvError,n as FsError,r as PathError,i as ProcessError};
package/dist/fs/Fs.d.ts CHANGED
@@ -2,16 +2,43 @@ import { FsError } from "../errors/errors.js";
2
2
  import { Either, List, Option, TaskResult } from "functype";
3
3
 
4
4
  //#region src/fs/Fs.d.ts
5
+ type FileInfo = {
6
+ readonly size: number;
7
+ readonly isFile: boolean;
8
+ readonly isDirectory: boolean;
9
+ readonly isSymbolicLink: boolean;
10
+ readonly createdAt: Date;
11
+ readonly modifiedAt: Date;
12
+ readonly accessedAt: Date;
13
+ readonly permissions: number;
14
+ };
5
15
  declare const Fs: {
6
16
  exists: (p: string) => TaskResult<boolean>;
7
17
  readFile: (p: string, encoding?: BufferEncoding) => TaskResult<string>;
8
18
  readFileOpt: (p: string, encoding?: BufferEncoding) => TaskResult<Option<string>>;
19
+ stat: (p: string) => TaskResult<FileInfo>;
20
+ copyFile: (src: string, dest: string) => TaskResult<void>;
21
+ rename: (oldPath: string, newPath: string) => TaskResult<void>;
9
22
  readdir: (p: string) => TaskResult<List<string>>;
23
+ glob: (dir: string, pattern: string) => TaskResult<List<string>>;
24
+ writeFile: (p: string, data: string, encoding?: BufferEncoding) => TaskResult<void>;
25
+ mkdir: (p: string, options?: {
26
+ recursive?: boolean;
27
+ }) => TaskResult<void>;
10
28
  existsSync: (p: string) => boolean;
11
29
  readFileSync: (p: string, encoding?: BufferEncoding) => Either<FsError, string>;
12
30
  readFileOptSync: (p: string, encoding?: BufferEncoding) => Either<FsError, Option<string>>;
31
+ statSync: (p: string) => Either<FsError, FileInfo>;
32
+ copyFileSync: (src: string, dest: string) => Either<FsError, void>;
33
+ renameSync: (oldPath: string, newPath: string) => Either<FsError, void>;
13
34
  readdirSync: (p: string) => Either<FsError, List<string>>;
35
+ writeFileSync: (p: string, data: string, encoding?: BufferEncoding) => Either<FsError, void>;
36
+ mkdirSync: (p: string, options?: {
37
+ recursive?: boolean;
38
+ }) => Either<FsError, void>;
39
+ unlink: (p: string) => TaskResult<void>;
40
+ unlinkSync: (p: string) => Either<FsError, void>;
14
41
  };
15
42
  //#endregion
16
- export { Fs };
43
+ export { FileInfo, Fs };
17
44
  //# sourceMappingURL=Fs.d.ts.map
package/dist/fs/Fs.js CHANGED
@@ -1,2 +1,2 @@
1
- import{FsError as e}from"../errors/errors.js";import{Err as t,Left as n,List as r,Ok as i,Option as a,Right as o}from"functype";import*as s from"node:fs";import*as c from"node:fs/promises";const l=(t,n,r)=>e(t,n,r instanceof Error?r:Error(String(r))),u={exists:async e=>{try{return await c.access(e),i(!0)}catch{return i(!1)}},readFile:async(e,n=`utf8`)=>{try{return i(await c.readFile(e,{encoding:n}))}catch(n){return t(l(e,`readFile`,n))}},readFileOpt:async(e,n=`utf8`)=>{try{return i(a(await c.readFile(e,{encoding:n})))}catch(n){return n instanceof Error&&`code`in n&&n.code===`ENOENT`?i(a(void 0)):t(l(e,`readFile`,n))}},readdir:async e=>{try{return i(r(await c.readdir(e)))}catch(n){return t(l(e,`readdir`,n))}},existsSync:e=>{try{return s.accessSync(e),!0}catch{return!1}},readFileSync:(e,t=`utf8`)=>{try{return o(s.readFileSync(e,{encoding:t}))}catch(t){return n(l(e,`readFileSync`,t))}},readFileOptSync:(e,t=`utf8`)=>{try{return o(a(s.readFileSync(e,{encoding:t})))}catch(t){return t instanceof Error&&`code`in t&&t.code===`ENOENT`?o(a(void 0)):n(l(e,`readFileOptSync`,t))}},readdirSync:e=>{try{return o(r(s.readdirSync(e)))}catch(t){return n(l(e,`readdirSync`,t))}}};export{u as Fs};
1
+ import{FsError as e}from"../errors/errors.js";import{Err as t,Left as n,List as r,Ok as i,Option as a,Right as o}from"functype";import*as s from"node:fs";import*as c from"node:fs/promises";const l=e=>({size:e.size,isFile:e.isFile(),isDirectory:e.isDirectory(),isSymbolicLink:e.isSymbolicLink(),createdAt:e.birthtime,modifiedAt:e.mtime,accessedAt:e.atime,permissions:e.mode}),u=(t,n,r)=>e(t,n,r instanceof Error?r:Error(String(r))),d=(e,t)=>{let n=t.replace(/\./g,`\\.`).replace(/\*\*\//g,`{{GLOBSTAR}}`).replace(/\*\*/g,`{{GLOBSTAR}}`).replace(/\*/g,`[^/]*`).replace(/\{\{GLOBSTAR\}\}/g,`(?:.*/)?`);return RegExp(`^${n}$`).test(e)},f={exists:async e=>{try{return await c.access(e),i(!0)}catch{return i(!1)}},readFile:async(e,n=`utf8`)=>{try{return i(await c.readFile(e,{encoding:n}))}catch(n){return t(u(e,`readFile`,n))}},readFileOpt:async(e,n=`utf8`)=>{try{return i(a(await c.readFile(e,{encoding:n})))}catch(n){return n instanceof Error&&`code`in n&&n.code===`ENOENT`?i(a(void 0)):t(u(e,`readFile`,n))}},stat:async e=>{try{return i(l(await c.stat(e)))}catch(n){return t(u(e,`stat`,n))}},copyFile:async(e,n)=>{try{return await c.copyFile(e,n),i(void 0)}catch(n){return t(u(e,`copyFile`,n))}},rename:async(e,n)=>{try{return await c.rename(e,n),i(void 0)}catch(n){return t(u(e,`rename`,n))}},readdir:async e=>{try{return i(r(await c.readdir(e)))}catch(n){return t(u(e,`readdir`,n))}},glob:async(e,n)=>{try{return i(r((await c.readdir(e,{recursive:!0,encoding:`utf8`})).filter(e=>d(e,n))))}catch(n){return t(u(e,`glob`,n))}},writeFile:async(e,n,r=`utf8`)=>{try{return await c.writeFile(e,n,{encoding:r}),i(void 0)}catch(n){return t(u(e,`writeFile`,n))}},mkdir:async(e,n)=>{try{return await c.mkdir(e,n),i(void 0)}catch(n){return t(u(e,`mkdir`,n))}},existsSync:e=>{try{return s.accessSync(e),!0}catch{return!1}},readFileSync:(e,t=`utf8`)=>{try{return o(s.readFileSync(e,{encoding:t}))}catch(t){return n(u(e,`readFileSync`,t))}},readFileOptSync:(e,t=`utf8`)=>{try{return o(a(s.readFileSync(e,{encoding:t})))}catch(t){return t instanceof Error&&`code`in t&&t.code===`ENOENT`?o(a(void 0)):n(u(e,`readFileOptSync`,t))}},statSync:e=>{try{return o(l(s.statSync(e)))}catch(t){return n(u(e,`statSync`,t))}},copyFileSync:(e,t)=>{try{return s.copyFileSync(e,t),o(void 0)}catch(t){return n(u(e,`copyFileSync`,t))}},renameSync:(e,t)=>{try{return s.renameSync(e,t),o(void 0)}catch(t){return n(u(e,`renameSync`,t))}},readdirSync:e=>{try{return o(r(s.readdirSync(e)))}catch(t){return n(u(e,`readdirSync`,t))}},writeFileSync:(e,t,r=`utf8`)=>{try{return s.writeFileSync(e,t,{encoding:r}),o(void 0)}catch(t){return n(u(e,`writeFileSync`,t))}},mkdirSync:(e,t)=>{try{return s.mkdirSync(e,t),o(void 0)}catch(t){return n(u(e,`mkdirSync`,t))}},unlink:async e=>{try{return await c.unlink(e),i(void 0)}catch(n){return t(u(e,`unlink`,n))}},unlinkSync:e=>{try{return s.unlinkSync(e),o(void 0)}catch(t){return n(u(e,`unlinkSync`,t))}}};export{f as Fs};
2
2
  //# sourceMappingURL=Fs.js.map
package/dist/fs/Fs.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Fs.js","names":[],"sources":["../../src/fs/Fs.ts"],"sourcesContent":["import * as fsSync from \"node:fs\"\nimport * as fs from \"node:fs/promises\"\n\nimport type { Either, TaskResult } from \"functype\"\nimport { Err, Left, List, Ok, Option, Right } from \"functype\"\n\nimport { FsError } from \"../errors/errors\"\n\nconst toFsError = (p: string, op: string, error: unknown): FsError =>\n FsError(p, op, error instanceof Error ? error : new Error(String(error)))\n\nexport const Fs = {\n // Async methods — return TaskResult<T>\n\n exists: async (p: string): TaskResult<boolean> => {\n try {\n await fs.access(p)\n return Ok(true)\n } catch {\n return Ok(false)\n }\n },\n\n readFile: async (p: string, encoding: BufferEncoding = \"utf8\"): TaskResult<string> => {\n try {\n return Ok(await fs.readFile(p, { encoding }))\n } catch (error) {\n return Err(toFsError(p, \"readFile\", error))\n }\n },\n\n readFileOpt: async (p: string, encoding: BufferEncoding = \"utf8\"): TaskResult<Option<string>> => {\n try {\n return Ok(Option(await fs.readFile(p, { encoding })))\n } catch (error) {\n if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n return Ok(Option<string>(undefined))\n }\n return Err(toFsError(p, \"readFile\", error))\n }\n },\n\n readdir: async (p: string): TaskResult<List<string>> => {\n try {\n return Ok(List(await fs.readdir(p)))\n } catch (error) {\n return Err(toFsError(p, \"readdir\", error))\n }\n },\n\n // Sync methods — return Either<FsError, T>\n\n existsSync: (p: string): boolean => {\n try {\n fsSync.accessSync(p)\n return true\n } catch {\n return false\n }\n },\n\n readFileSync: (p: string, encoding: BufferEncoding = \"utf8\"): Either<FsError, string> => {\n try {\n return Right(fsSync.readFileSync(p, { encoding }))\n } catch (error) {\n return Left(toFsError(p, \"readFileSync\", error))\n }\n },\n\n readFileOptSync: (p: string, encoding: BufferEncoding = \"utf8\"): Either<FsError, Option<string>> => {\n try {\n return Right(Option(fsSync.readFileSync(p, { encoding })))\n } catch (error) {\n if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n return Right(Option<string>(undefined))\n }\n return Left(toFsError(p, \"readFileOptSync\", error))\n }\n },\n\n readdirSync: (p: string): Either<FsError, List<string>> => {\n try {\n return Right(List(fsSync.readdirSync(p)))\n } catch (error) {\n return Left(toFsError(p, \"readdirSync\", error))\n }\n },\n}\n"],"mappings":"6LAQA,MAAM,GAAa,EAAW,EAAY,IACxC,EAAQ,EAAG,EAAI,aAAiB,MAAQ,EAAY,MAAM,OAAO,EAAM,CAAC,CAAC,CAE9D,EAAK,CAGhB,OAAQ,KAAO,IAAmC,CAChD,GAAI,CAEF,OADA,MAAM,EAAG,OAAO,EAAE,CACX,EAAG,GAAK,MACT,CACN,OAAO,EAAG,GAAM,GAIpB,SAAU,MAAO,EAAW,EAA2B,SAA+B,CACpF,GAAI,CACF,OAAO,EAAG,MAAM,EAAG,SAAS,EAAG,CA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":["import * as fsSync from \"node:fs\"\nimport * as fs from \"node:fs/promises\"\n\nimport type { Either, TaskResult } from \"functype\"\nimport { Err, Left, List, Ok, Option, Right } from \"functype\"\n\nimport { FsError } from \"../errors/errors\"\n\nexport type FileInfo = {\n readonly size: number\n readonly isFile: boolean\n readonly isDirectory: boolean\n readonly isSymbolicLink: boolean\n readonly createdAt: Date\n readonly modifiedAt: Date\n readonly accessedAt: Date\n readonly permissions: number\n}\n\nconst toFileInfo = (stats: fsSync.Stats): FileInfo => ({\n size: stats.size,\n isFile: stats.isFile(),\n isDirectory: stats.isDirectory(),\n isSymbolicLink: stats.isSymbolicLink(),\n createdAt: stats.birthtime,\n modifiedAt: stats.mtime,\n accessedAt: stats.atime,\n permissions: stats.mode,\n})\n\nconst toFsError = (p: string, op: string, error: unknown): FsError =>\n FsError(p, op, error instanceof Error ? error : new Error(String(error)))\n\nconst matchGlob = (filePath: string, pattern: string): boolean => {\n const regex = pattern\n .replace(/\\./g, \"\\\\.\")\n .replace(/\\*\\*\\//g, \"{{GLOBSTAR}}\")\n .replace(/\\*\\*/g, \"{{GLOBSTAR}}\")\n .replace(/\\*/g, \"[^/]*\")\n .replace(/\\{\\{GLOBSTAR\\}\\}/g, \"(?:.*/)?\")\n return new RegExp(`^${regex}$`).test(filePath)\n}\n\nexport const Fs = {\n // Async methods — return TaskResult<T>\n\n exists: async (p: string): TaskResult<boolean> => {\n try {\n await fs.access(p)\n return Ok(true)\n } catch {\n return Ok(false)\n }\n },\n\n readFile: async (p: string, encoding: BufferEncoding = \"utf8\"): TaskResult<string> => {\n try {\n return Ok(await fs.readFile(p, { encoding }))\n } catch (error) {\n return Err(toFsError(p, \"readFile\", error))\n }\n },\n\n readFileOpt: async (p: string, encoding: BufferEncoding = \"utf8\"): TaskResult<Option<string>> => {\n try {\n return Ok(Option(await fs.readFile(p, { encoding })))\n } catch (error) {\n if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n return Ok(Option<string>(undefined))\n }\n return Err(toFsError(p, \"readFile\", error))\n }\n },\n\n stat: async (p: string): TaskResult<FileInfo> => {\n try {\n return Ok(toFileInfo(await fs.stat(p)))\n } catch (error) {\n return Err(toFsError(p, \"stat\", error))\n }\n },\n\n copyFile: async (src: string, dest: string): TaskResult<void> => {\n try {\n await fs.copyFile(src, dest)\n return Ok(undefined as void)\n } catch (error) {\n return Err(toFsError(src, \"copyFile\", error))\n }\n },\n\n rename: async (oldPath: string, newPath: string): TaskResult<void> => {\n try {\n await fs.rename(oldPath, newPath)\n return Ok(undefined as void)\n } catch (error) {\n return Err(toFsError(oldPath, \"rename\", error))\n }\n },\n\n readdir: async (p: string): TaskResult<List<string>> => {\n try {\n return Ok(List(await fs.readdir(p)))\n } catch (error) {\n return Err(toFsError(p, \"readdir\", error))\n }\n },\n\n glob: async (dir: string, pattern: string): TaskResult<List<string>> => {\n try {\n const entries = await fs.readdir(dir, { recursive: true, encoding: \"utf8\" })\n const matched = entries.filter((entry) => matchGlob(entry, pattern))\n return Ok(List(matched))\n } catch (error) {\n return Err(toFsError(dir, \"glob\", error))\n }\n },\n\n writeFile: async (p: string, data: string, encoding: BufferEncoding = \"utf8\"): TaskResult<void> => {\n try {\n await fs.writeFile(p, data, { encoding })\n return Ok(undefined as void)\n } catch (error) {\n return Err(toFsError(p, \"writeFile\", error))\n }\n },\n\n mkdir: async (p: string, options?: { recursive?: boolean }): TaskResult<void> => {\n try {\n await fs.mkdir(p, options)\n return Ok(undefined as void)\n } catch (error) {\n return Err(toFsError(p, \"mkdir\", error))\n }\n },\n\n // Sync methods — return Either<FsError, T>\n\n existsSync: (p: string): boolean => {\n try {\n fsSync.accessSync(p)\n return true\n } catch {\n return false\n }\n },\n\n readFileSync: (p: string, encoding: BufferEncoding = \"utf8\"): Either<FsError, string> => {\n try {\n return Right(fsSync.readFileSync(p, { encoding }))\n } catch (error) {\n return Left(toFsError(p, \"readFileSync\", error))\n }\n },\n\n readFileOptSync: (p: string, encoding: BufferEncoding = \"utf8\"): Either<FsError, Option<string>> => {\n try {\n return Right(Option(fsSync.readFileSync(p, { encoding })))\n } catch (error) {\n if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n return Right(Option<string>(undefined))\n }\n return Left(toFsError(p, \"readFileOptSync\", error))\n }\n },\n\n statSync: (p: string): Either<FsError, FileInfo> => {\n try {\n return Right(toFileInfo(fsSync.statSync(p)))\n } catch (error) {\n return Left(toFsError(p, \"statSync\", error))\n }\n },\n\n copyFileSync: (src: string, dest: string): Either<FsError, void> => {\n try {\n fsSync.copyFileSync(src, dest)\n return Right(undefined as void)\n } catch (error) {\n return Left(toFsError(src, \"copyFileSync\", error))\n }\n },\n\n renameSync: (oldPath: string, newPath: string): Either<FsError, void> => {\n try {\n fsSync.renameSync(oldPath, newPath)\n return Right(undefined as void)\n } catch (error) {\n return Left(toFsError(oldPath, \"renameSync\", error))\n }\n },\n\n readdirSync: (p: string): Either<FsError, List<string>> => {\n try {\n return Right(List(fsSync.readdirSync(p)))\n } catch (error) {\n return Left(toFsError(p, \"readdirSync\", error))\n }\n },\n\n writeFileSync: (p: string, data: string, encoding: BufferEncoding = \"utf8\"): Either<FsError, void> => {\n try {\n fsSync.writeFileSync(p, data, { encoding })\n return Right(undefined as void)\n } catch (error) {\n return Left(toFsError(p, \"writeFileSync\", error))\n }\n },\n\n mkdirSync: (p: string, options?: { recursive?: boolean }): Either<FsError, void> => {\n try {\n fsSync.mkdirSync(p, options)\n return Right(undefined as void)\n } catch (error) {\n return Left(toFsError(p, \"mkdirSync\", error))\n }\n },\n\n unlink: async (p: string): TaskResult<void> => {\n try {\n await fs.unlink(p)\n return Ok(undefined as void)\n } catch (error) {\n return Err(toFsError(p, \"unlink\", error))\n }\n },\n\n unlinkSync: (p: string): Either<FsError, void> => {\n try {\n fsSync.unlinkSync(p)\n return Right(undefined as void)\n } catch (error) {\n return Left(toFsError(p, \"unlinkSync\", error))\n }\n },\n}\n"],"mappings":"6LAmBA,MAAM,EAAc,IAAmC,CACrD,KAAM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AI,CAEF,OADA,EAAO,UAAU,EAAG,EAAQ,CACrB,EAAM,IAAA,GAAkB,OACxB,EAAO,CACd,OAAO,EAAK,EAAU,EAAG,YAAa,EAAM,CAAC,GAIjD,OAAQ,KAAO,IAAgC,CAC7C,GAAI,CAEF,OADA,MAAM,EAAG,OAAO,EAAE,CACX,EAAG,IAAA,GAAkB,OACrB,EAAO,CACd,OAAO,EAAI,EAAU,EAAG,SAAU,EAAM,CAAC,GAI7C,WAAa,GAAqC,CAChD,GAAI,CAEF,OADA,EAAO,WAAW,EAAE,CACb,EAAM,IAAA,GAAkB,OACxB,EAAO,CACd,OAAO,EAAK,EAAU,EAAG,aAAc,EAAM,CAAC,GAGnD"}
@@ -1,2 +1,2 @@
1
- import { Fs } from "./Fs.js";
2
- export { Fs };
1
+ import { FileInfo, Fs } from "./Fs.js";
2
+ export { type FileInfo, Fs };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { ConfigError, EnvError, FsError, OsError, PathError } from "./errors/errors.js";
1
+ import { ConfigError, EnvError, FsError, OsError, PathError, ProcessError } from "./errors/errors.js";
2
2
  import { ConfigResolver } from "./config/ConfigResolver.js";
3
3
  import { Env } from "./env/Env.js";
4
- import { Fs } from "./fs/Fs.js";
4
+ import { FileInfo, Fs } from "./fs/Fs.js";
5
5
  import { Path, expandPath, expandTilde, expandVars } from "./path/PathExpander.js";
6
6
  import { CloudProvider, CloudStorageDir, Platform, UserInfo } from "./platform/Platform.js";
7
- export { type CloudProvider, type CloudStorageDir, ConfigError, ConfigResolver, Env, EnvError, Fs, FsError, type OsError, Path, PathError, Platform, type UserInfo, expandPath, expandTilde, expandVars };
7
+ import { ExecResult, Process } from "./process/Process.js";
8
+ export { type CloudProvider, type CloudStorageDir, ConfigError, ConfigResolver, Env, EnvError, type ExecResult, type FileInfo, Fs, FsError, type OsError, Path, PathError, Platform, Process, ProcessError, type UserInfo, expandPath, expandTilde, expandVars };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{ConfigError as e,EnvError as t,FsError as n,PathError as r}from"./errors/errors.js";import{Fs as i}from"./fs/Fs.js";import{Path as a,expandPath as o,expandTilde as s,expandVars as c}from"./path/PathExpander.js";import{ConfigResolver as l}from"./config/ConfigResolver.js";import"./config/index.js";import{Env as u}from"./env/Env.js";import"./env/index.js";import"./fs/index.js";import"./path/index.js";import{Platform as d}from"./platform/Platform.js";import"./platform/index.js";export{e as ConfigError,l as ConfigResolver,u as Env,t as EnvError,i as Fs,n as FsError,a as Path,r as PathError,d as Platform,o as expandPath,s as expandTilde,c as expandVars};
1
+ import{ConfigError as e,EnvError as t,FsError as n,PathError as r,ProcessError as i}from"./errors/errors.js";import{Fs as a}from"./fs/Fs.js";import{Path as o,expandPath as s,expandTilde as c,expandVars as l}from"./path/PathExpander.js";import{ConfigResolver as u}from"./config/ConfigResolver.js";import"./config/index.js";import{Env as d}from"./env/Env.js";import"./env/index.js";import"./fs/index.js";import"./path/index.js";import{Platform as f}from"./platform/Platform.js";import"./platform/index.js";import{Process as p}from"./process/Process.js";import"./process/index.js";export{e as ConfigError,u as ConfigResolver,d as Env,t as EnvError,a as Fs,n as FsError,o as Path,r as PathError,f as Platform,p as Process,i as ProcessError,s as expandPath,c as expandTilde,l as expandVars};
@@ -0,0 +1,22 @@
1
+ import { ProcessError } from "../errors/errors.js";
2
+ import { Either, TaskResult } from "functype";
3
+
4
+ //#region src/process/Process.d.ts
5
+ type ExecResult = {
6
+ readonly stdout: string;
7
+ readonly stderr: string;
8
+ readonly exitCode: number;
9
+ };
10
+ declare const Process: {
11
+ exec: (command: string, options?: {
12
+ timeout?: number;
13
+ cwd?: string;
14
+ }) => TaskResult<ExecResult>;
15
+ execSync: (command: string, options?: {
16
+ timeout?: number;
17
+ cwd?: string;
18
+ }) => Either<ProcessError, ExecResult>;
19
+ };
20
+ //#endregion
21
+ export { ExecResult, Process };
22
+ //# sourceMappingURL=Process.d.ts.map
@@ -0,0 +1,2 @@
1
+ import{ProcessError as e}from"../errors/errors.js";import{Err as t,Left as n,Ok as r,Right as i}from"functype";import{exec as a,execSync as o}from"node:child_process";const s={exec:(n,i)=>new Promise(o=>{a(n,{timeout:i?.timeout,cwd:i?.cwd},(i,a,s)=>{o(i?t(e(n,typeof i.code==`number`?i.code:null,String(s))):r({stdout:String(a),stderr:String(s),exitCode:0}))})}),execSync:(t,r)=>{try{let e=o(t,{timeout:r?.timeout,cwd:r?.cwd,encoding:`utf8`,stdio:[`pipe`,`pipe`,`pipe`]});return i({stdout:String(e),stderr:``,exitCode:0})}catch(r){if(r instanceof Error&&`status`in r&&`stderr`in r){let i=r;return n(e(t,i.status,String(i.stderr)))}return n(e(t,null,``,r instanceof Error?r.message:String(r)))}}};export{s as Process};
2
+ //# sourceMappingURL=Process.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Process.js","names":["nodeExecSync"],"sources":["../../src/process/Process.ts"],"sourcesContent":["import { exec as execCb, execSync as nodeExecSync } from \"node:child_process\"\n\nimport type { Either, TaskResult } from \"functype\"\nimport { Err, Left, Ok, Right } from \"functype\"\n\nimport { ProcessError } from \"../errors/errors\"\n\nexport type ExecResult = {\n readonly stdout: string\n readonly stderr: string\n readonly exitCode: number\n}\n\nexport const Process = {\n exec: (command: string, options?: { timeout?: number; cwd?: string }): TaskResult<ExecResult> => {\n return new Promise((resolve) => {\n execCb(command, { timeout: options?.timeout, cwd: options?.cwd }, (error, stdout, stderr) => {\n if (error) {\n // exec callback error has `code` as exit code (number) — distinct from Node errno `code` (string)\n const exitCode = typeof error.code === \"number\" ? error.code : null\n resolve(Err(ProcessError(command, exitCode, String(stderr))))\n } else {\n resolve(Ok({ stdout: String(stdout), stderr: String(stderr), exitCode: 0 }))\n }\n })\n })\n },\n\n execSync: (command: string, options?: { timeout?: number; cwd?: string }): Either<ProcessError, ExecResult> => {\n try {\n const stdout = nodeExecSync(command, {\n timeout: options?.timeout,\n cwd: options?.cwd,\n encoding: \"utf8\",\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n })\n return Right({ stdout: String(stdout), stderr: \"\", exitCode: 0 })\n } catch (error) {\n if (error instanceof Error && \"status\" in error && \"stderr\" in error) {\n const execError = error as Error & { status: number; stderr: string }\n return Left(ProcessError(command, execError.status, String(execError.stderr)))\n }\n return Left(ProcessError(command, null, \"\", error instanceof Error ? error.message : String(error)))\n }\n },\n}\n"],"mappings":"uKAaA,MAAa,EAAU,CACrB,MAAO,EAAiB,IACf,IAAI,QAAS,GAAY,CAC9B,EAAO,EAAS,CAAE,QAAS,GAAS,QAAS,IAAK,GAAS,IAAK,EAAG,EAAO,EAAQ,IAAW,CAIzF,EAHE,EAGM,EAAI,EAAa,EADR,OAAO,EAAM,MAAS,SAAW,EAAM,KAAO,KACnB,OAAO,EAAO,CAAC,CAAC,CAEpD,EAAG,CAAE,OAAQ,OAAO,EAAO,CAAE,OAAQ,OAAO,EAAO,CAAE,SAAU,EAAG,CAAC,CAAC,EAE9E,EACF,CAGJ,UAAW,EAAiB,IAAmF,CAC7G,GAAI,CACF,IAAM,EAASA,EAAa,EAAS,CACnC,QAAS,GAAS,QAClB,IAAK,GAAS,IACd,SAAU,OACV,MAAO,CAAC,OAAQ,OAAQ,OAAO,CAChC,CAAC,CACF,OAAO,EAAM,CAAE,OAAQ,OAAO,EAAO,CAAE,OAAQ,GAAI,SAAU,EAAG,CAAC,OAC1D,EAAO,CACd,GAAI,aAAiB,OAAS,WAAY,GAAS,WAAY,EAAO,CACpE,IAAM,EAAY,EAClB,OAAO,EAAK,EAAa,EAAS,EAAU,OAAQ,OAAO,EAAU,OAAO,CAAC,CAAC,CAEhF,OAAO,EAAK,EAAa,EAAS,KAAM,GAAI,aAAiB,MAAQ,EAAM,QAAU,OAAO,EAAM,CAAC,CAAC,GAGzG"}
@@ -0,0 +1,2 @@
1
+ import { ExecResult, Process } from "./Process.js";
2
+ export { type ExecResult, Process };
@@ -0,0 +1 @@
1
+ import{Process as e}from"./Process.js";export{e as Process};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functype-os",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Functional OS utilities using functype data structures — env vars, path expansion, file ops, platform detection",
5
5
  "keywords": [
6
6
  "functype",
@@ -39,9 +39,9 @@
39
39
  "@types/node": "^24.12.0",
40
40
  "eslint-config-prettier": "^10.1.8",
41
41
  "functype": "^0.49.0",
42
- "ts-builds": "^2.5.0",
42
+ "ts-builds": "^2.5.2",
43
43
  "tsdown": "^0.20.3",
44
- "vitest": "^4.0.18"
44
+ "vitest": "^4.1.0"
45
45
  },
46
46
  "type": "module",
47
47
  "main": "./dist/index.js",
@@ -82,6 +82,11 @@
82
82
  "types": "./dist/errors/index.d.ts",
83
83
  "import": "./dist/errors/index.js",
84
84
  "default": "./dist/errors/index.js"
85
+ },
86
+ "./process": {
87
+ "types": "./dist/process/index.d.ts",
88
+ "import": "./dist/process/index.js",
89
+ "default": "./dist/process/index.js"
85
90
  }
86
91
  },
87
92
  "files": [
@@ -89,8 +94,8 @@
89
94
  "dist"
90
95
  ],
91
96
  "prettier": "ts-builds/prettier",
92
- "packageManager": "pnpm@10.30.3+sha512.c961d1e0a2d8e354ecaa5166b822516668b7f44cb5bd95122d590dd81922f606f5473b6d23ec4a5be05e7fcd18e8488d47d978bbe981872f1145d06e9a740017",
97
+ "packageManager": "pnpm@10.32.1+sha512.a706938f0e89ac1456b6563eab4edf1d1faf3368d1191fc5c59790e96dc918e4456ab2e67d613de1043d2e8c81f87303e6b40d4ffeca9df15ef1ad567348f2be",
93
98
  "engines": {
94
- "node": ">=18.0.0"
99
+ "node": ">=18.17.0"
95
100
  }
96
101
  }