@easbot/utils 0.2.10 → 0.2.13

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/index.d.ts CHANGED
@@ -1,13 +1,12 @@
1
1
  import { ChildProcess } from 'node:child_process';
2
2
  import z, { z as z$1 } from 'zod';
3
- export { z } from 'zod';
4
3
  import { statSync } from 'node:fs';
5
4
  import * as stream from 'stream';
6
5
  import { Readable } from 'stream';
7
6
  import * as _hono_node_ws from '@hono/node-ws';
8
7
  export { createNodeWebSocket } from '@hono/node-ws';
9
8
  import * as fs from 'fs';
10
- import { Context as Context$1, Next, Hono } from 'hono';
9
+ import { Hono, Context as Context$1, Next } from 'hono';
11
10
  export { Hono, Next } from 'hono';
12
11
  import { ServerType } from '@hono/node-server';
13
12
  import { cors } from 'hono/cors';
@@ -111,6 +110,20 @@ declare namespace Shell {
111
110
  function platformShells(): string[];
112
111
  function isValid(file: string): boolean;
113
112
  function version(file: string): Promise<string | undefined>;
113
+ interface InstallOptions {
114
+ cwd?: string;
115
+ env?: Record<string, string | undefined>;
116
+ timeout?: number;
117
+ windowsHide?: boolean;
118
+ }
119
+ class InstallFailedError extends Error {
120
+ message: string;
121
+ pkg: string;
122
+ version: string;
123
+ originalError?: string | undefined;
124
+ constructor(message: string, pkg: string, version: string, originalError?: string | undefined);
125
+ }
126
+ function install(pkg: string, version?: string, installPath?: string): Promise<string>;
114
127
  interface RunOptions {
115
128
  cwd?: string;
116
129
  env?: Record<string, string | undefined>;
@@ -118,18 +131,21 @@ declare namespace Shell {
118
131
  signal?: AbortSignal;
119
132
  windowsHide?: boolean;
120
133
  shell?: boolean;
134
+ stdin?: 'null' | 'pipe';
135
+ stdout?: 'pipe' | 'ignore';
136
+ stderr?: 'pipe' | 'ignore';
121
137
  }
122
- interface SpawnOptions extends RunOptions {
123
- stdout?: 'pipe' | 'inherit' | 'null';
124
- stderr?: 'pipe' | 'inherit' | 'null';
138
+ interface SpawnOptions extends Omit<RunOptions, 'stdin' | 'stdout' | 'stderr'> {
139
+ stdout?: 'pipe' | 'inherit' | 'null' | 'ignore';
140
+ stderr?: 'pipe' | 'inherit' | 'null' | 'ignore';
125
141
  stdin?: 'pipe' | 'inherit' | 'null';
126
142
  }
127
- function run(shell: string, command: string, options?: RunOptions): Promise<{
143
+ function run(shell: string | undefined, command: string, options?: RunOptions): Promise<{
128
144
  code: number;
129
145
  stdout: string;
130
146
  stderr: string;
131
147
  }>;
132
- function spawn(shell: string, command: string, options?: SpawnOptions): {
148
+ function spawn(shell: string | undefined, command: string, options?: SpawnOptions): {
133
149
  stdout: any;
134
150
  stderr: any;
135
151
  stdin: any;
@@ -137,7 +153,37 @@ declare namespace Shell {
137
153
  exited: Promise<number>;
138
154
  kill: (signal?: string | number) => boolean;
139
155
  };
156
+ interface DollarRunOptions {
157
+ cwd?: string;
158
+ quiet?: boolean;
159
+ nothrow?: boolean;
160
+ env?: Record<string, string | undefined>;
161
+ stdin?: 'null' | 'pipe';
162
+ stdout?: 'pipe' | 'ignore';
163
+ stderr?: 'pipe' | 'ignore';
164
+ windowsHide?: boolean;
165
+ shell?: boolean;
166
+ }
167
+ function $(strings: TemplateStringsArray, ...values: unknown[]): {
168
+ quiet: () => any;
169
+ nothrow: () => any;
170
+ cwd: (dir: string) => any;
171
+ env: (env: Record<string, string | undefined>) => any;
172
+ stdin: (stdin: "null" | "pipe") => any;
173
+ stdout: (stdout: "pipe" | "ignore") => any;
174
+ stderr: (stderr: "pipe" | "ignore") => any;
175
+ text: () => Promise<string>;
176
+ lines: () => Promise<string[]>;
177
+ then: (onfulfilled: (result: {
178
+ exitCode: number;
179
+ stdout: Uint8Array;
180
+ stderr: Uint8Array;
181
+ text: () => string;
182
+ lines: () => string[];
183
+ }) => void, onrejected?: (error: Error) => void) => Promise<void>;
184
+ };
140
185
  }
186
+ declare const $: typeof Shell.$;
141
187
 
142
188
  declare function formatLocalISO(date: Date | number, includeMilliseconds?: boolean): string;
143
189
  declare function formatLocalISOCompact(date: Date | number): string;
@@ -325,6 +371,7 @@ declare abstract class NamedError extends Error {
325
371
  };
326
372
  }
327
373
 
374
+ declare const MIME_TYPES: Record<string, string>;
328
375
  declare namespace Filesystem {
329
376
  function mkdir(p: string, options?: {
330
377
  recursive?: boolean;
@@ -341,10 +388,14 @@ declare namespace Filesystem {
341
388
  function writeJson(p: string, data: unknown, mode?: number): Promise<void>;
342
389
  function writeStream(p: string, stream: ReadableStream<Uint8Array> | Readable, mode?: number): Promise<void>;
343
390
  function mimeType(p: string): string;
391
+ function dirname(p: string): string;
392
+ function basename(p: string, ext?: string): string;
393
+ function extname(p: string): string;
344
394
  function toUnixPath(p: string): string;
345
395
  function normalize(p: string): string;
346
- const normalizePath: typeof normalize;
347
396
  function resolve(p: string): string;
397
+ function isAbsolute(p: string): boolean;
398
+ function join(base: string, ...paths: string[]): string;
348
399
  function windowsPath(p: string): string;
349
400
  function overlaps(a: string, b: string): boolean;
350
401
  function contains(parent: string, child: string): boolean;
@@ -845,8 +896,8 @@ interface NodeWhichOptions {
845
896
  interface NodeSpawnOptions {
846
897
  cwd?: string;
847
898
  env?: Record<string, string | undefined>;
848
- stdout?: 'pipe' | 'inherit' | 'null';
849
- stderr?: 'pipe' | 'inherit' | 'null';
899
+ stdout?: 'pipe' | 'inherit' | 'null' | 'ignore';
900
+ stderr?: 'pipe' | 'inherit' | 'null' | 'ignore';
850
901
  stdin?: 'pipe' | 'inherit' | 'null';
851
902
  signal?: AbortSignal;
852
903
  timeout?: number | false;
@@ -857,8 +908,8 @@ interface NodeSpawnObjectArgs {
857
908
  cmd: string[];
858
909
  cwd?: string;
859
910
  env?: Record<string, string | undefined>;
860
- stdout?: 'pipe' | 'inherit' | 'null';
861
- stderr?: 'pipe' | 'inherit' | 'null';
911
+ stdout?: 'pipe' | 'inherit' | 'null' | 'ignore';
912
+ stderr?: 'pipe' | 'inherit' | 'null' | 'ignore';
862
913
  stdin?: 'pipe' | 'inherit' | 'null';
863
914
  signal?: AbortSignal;
864
915
  timeout?: number | false;
@@ -875,6 +926,11 @@ interface NodeSpawnResult {
875
926
  exitCode?: number;
876
927
  }
877
928
  declare namespace PKG {
929
+ type PackageManager = 'npm' | 'pnpm' | 'bun';
930
+ function packageManager(preferred?: PackageManager): Promise<{
931
+ name: PackageManager;
932
+ path: string;
933
+ } | undefined>;
878
934
  function which(command?: string, options?: NodeWhichOptions): Promise<string | null>;
879
935
  function whichSync(command?: string, options?: NodeWhichOptions): string | null;
880
936
  function clearWhichCache(): void;
@@ -908,6 +964,9 @@ declare namespace PKG {
908
964
  timeout?: number;
909
965
  windowsHide?: boolean;
910
966
  shell?: boolean;
967
+ stdin?: 'null' | 'pipe';
968
+ stdout?: 'pipe' | 'ignore';
969
+ stderr?: 'pipe' | 'ignore';
911
970
  }): Promise<{
912
971
  code: number;
913
972
  stdout: string;
@@ -926,21 +985,6 @@ declare namespace PKG {
926
985
  stdout: string;
927
986
  stderr: string;
928
987
  }>;
929
- function $(strings: TemplateStringsArray, ...values: unknown[]): {
930
- quiet: () => any;
931
- nothrow: () => any;
932
- cwd: (dir: string) => any;
933
- env: (env: Record<string, string | undefined>) => any;
934
- text: () => Promise<string>;
935
- lines: () => Promise<string[]>;
936
- then: (onfulfilled: (result: {
937
- exitCode: number;
938
- stdout: Uint8Array;
939
- stderr: Uint8Array;
940
- text: () => string;
941
- lines: () => string[];
942
- }) => void, onrejected?: (error: Error) => void) => Promise<void>;
943
- };
944
988
  function readableStreamToText(stream: ReadableStream<Uint8Array>): Promise<string>;
945
989
  function nodeReadableStreamToText(stream: NodeJS.ReadableStream): Promise<string>;
946
990
  function xxHash32(str: string, seed?: number): number;
@@ -964,257 +1008,6 @@ declare namespace PKG {
964
1008
  }): Generator<string>;
965
1009
  match(filepath: string): boolean;
966
1010
  }
967
- const InstallFailedError: {
968
- new (data: {
969
- message: string;
970
- pkg: string;
971
- version: string;
972
- originalError?: string | undefined;
973
- }, options?: ErrorOptions): {
974
- readonly name: "PKGInstallFailedError";
975
- readonly data: {
976
- message: string;
977
- pkg: string;
978
- version: string;
979
- originalError?: string | undefined;
980
- };
981
- schema(): z.ZodObject<{
982
- name: z.ZodLiteral<"PKGInstallFailedError">;
983
- data: z.ZodObject<{
984
- message: z.ZodString;
985
- pkg: z.ZodString;
986
- version: z.ZodString;
987
- originalError: z.ZodOptional<z.ZodString>;
988
- }, z.core.$strip>;
989
- }, z.core.$strip>;
990
- toObject(): {
991
- name: "PKGInstallFailedError";
992
- data: {
993
- message: string;
994
- pkg: string;
995
- version: string;
996
- originalError?: string | undefined;
997
- };
998
- };
999
- message: string;
1000
- stack?: string;
1001
- cause?: unknown;
1002
- };
1003
- readonly Schema: z.ZodObject<{
1004
- name: z.ZodLiteral<"PKGInstallFailedError">;
1005
- data: z.ZodObject<{
1006
- message: z.ZodString;
1007
- pkg: z.ZodString;
1008
- version: z.ZodString;
1009
- originalError: z.ZodOptional<z.ZodString>;
1010
- }, z.core.$strip>;
1011
- }, z.core.$strip>;
1012
- isInstance(input: any): input is {
1013
- readonly name: "PKGInstallFailedError";
1014
- readonly data: {
1015
- message: string;
1016
- pkg: string;
1017
- version: string;
1018
- originalError?: string | undefined;
1019
- };
1020
- schema(): z.ZodObject<{
1021
- name: z.ZodLiteral<"PKGInstallFailedError">;
1022
- data: z.ZodObject<{
1023
- message: z.ZodString;
1024
- pkg: z.ZodString;
1025
- version: z.ZodString;
1026
- originalError: z.ZodOptional<z.ZodString>;
1027
- }, z.core.$strip>;
1028
- }, z.core.$strip>;
1029
- toObject(): {
1030
- name: "PKGInstallFailedError";
1031
- data: {
1032
- message: string;
1033
- pkg: string;
1034
- version: string;
1035
- originalError?: string | undefined;
1036
- };
1037
- };
1038
- message: string;
1039
- stack?: string;
1040
- cause?: unknown;
1041
- };
1042
- create<Name extends string, Data extends z.core.$ZodType>(name: Name, data: Data): {
1043
- new (data: z.input<Data>, options?: ErrorOptions): {
1044
- readonly name: Name;
1045
- readonly data: z.core.input<Data>;
1046
- schema(): z.ZodObject<{
1047
- name: z.ZodLiteral<Name>;
1048
- data: Data;
1049
- }, z.core.$strip>;
1050
- toObject(): {
1051
- name: Name;
1052
- data: z.core.input<Data>;
1053
- };
1054
- message: string;
1055
- stack?: string;
1056
- cause?: unknown;
1057
- };
1058
- readonly Schema: z.ZodObject<{
1059
- name: z.ZodLiteral<Name>;
1060
- data: Data;
1061
- }, z.core.$strip>;
1062
- isInstance(input: any): input is InstanceType<any>;
1063
- create<Name extends string, Data extends z.core.$ZodType>(name: Name, data: Data): any;
1064
- readonly Unknown: {
1065
- new (data: {
1066
- message: string;
1067
- }, options?: ErrorOptions): {
1068
- readonly name: "UnknownError";
1069
- readonly data: {
1070
- message: string;
1071
- };
1072
- schema(): z.ZodObject<{
1073
- name: z.ZodLiteral<"UnknownError">;
1074
- data: z.ZodObject<{
1075
- message: z.ZodString;
1076
- }, z.core.$strip>;
1077
- }, z.core.$strip>;
1078
- toObject(): {
1079
- name: "UnknownError";
1080
- data: {
1081
- message: string;
1082
- };
1083
- };
1084
- message: string;
1085
- stack?: string;
1086
- cause?: unknown;
1087
- };
1088
- readonly Schema: z.ZodObject<{
1089
- name: z.ZodLiteral<"UnknownError">;
1090
- data: z.ZodObject<{
1091
- message: z.ZodString;
1092
- }, z.core.$strip>;
1093
- }, z.core.$strip>;
1094
- isInstance(input: any): input is {
1095
- readonly name: "UnknownError";
1096
- readonly data: {
1097
- message: string;
1098
- };
1099
- schema(): z.ZodObject<{
1100
- name: z.ZodLiteral<"UnknownError">;
1101
- data: z.ZodObject<{
1102
- message: z.ZodString;
1103
- }, z.core.$strip>;
1104
- }, z.core.$strip>;
1105
- toObject(): {
1106
- name: "UnknownError";
1107
- data: {
1108
- message: string;
1109
- };
1110
- };
1111
- message: string;
1112
- stack?: string;
1113
- cause?: unknown;
1114
- };
1115
- create<Name extends string, Data extends z.core.$ZodType>(name: Name, data: Data): any;
1116
- readonly Unknown: any;
1117
- isError(error: unknown): error is Error;
1118
- captureStackTrace(targetObject: object, constructorOpt?: Function): void;
1119
- prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
1120
- stackTraceLimit: number;
1121
- };
1122
- isError(error: unknown): error is Error;
1123
- captureStackTrace(targetObject: object, constructorOpt?: Function): void;
1124
- prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
1125
- stackTraceLimit: number;
1126
- };
1127
- readonly Unknown: {
1128
- new (data: {
1129
- message: string;
1130
- }, options?: ErrorOptions): {
1131
- readonly name: "UnknownError";
1132
- readonly data: {
1133
- message: string;
1134
- };
1135
- schema(): z.ZodObject<{
1136
- name: z.ZodLiteral<"UnknownError">;
1137
- data: z.ZodObject<{
1138
- message: z.ZodString;
1139
- }, z.core.$strip>;
1140
- }, z.core.$strip>;
1141
- toObject(): {
1142
- name: "UnknownError";
1143
- data: {
1144
- message: string;
1145
- };
1146
- };
1147
- message: string;
1148
- stack?: string;
1149
- cause?: unknown;
1150
- };
1151
- readonly Schema: z.ZodObject<{
1152
- name: z.ZodLiteral<"UnknownError">;
1153
- data: z.ZodObject<{
1154
- message: z.ZodString;
1155
- }, z.core.$strip>;
1156
- }, z.core.$strip>;
1157
- isInstance(input: any): input is {
1158
- readonly name: "UnknownError";
1159
- readonly data: {
1160
- message: string;
1161
- };
1162
- schema(): z.ZodObject<{
1163
- name: z.ZodLiteral<"UnknownError">;
1164
- data: z.ZodObject<{
1165
- message: z.ZodString;
1166
- }, z.core.$strip>;
1167
- }, z.core.$strip>;
1168
- toObject(): {
1169
- name: "UnknownError";
1170
- data: {
1171
- message: string;
1172
- };
1173
- };
1174
- message: string;
1175
- stack?: string;
1176
- cause?: unknown;
1177
- };
1178
- create<Name extends string, Data extends z.core.$ZodType>(name: Name, data: Data): {
1179
- new (data: z.input<Data>, options?: ErrorOptions): {
1180
- readonly name: Name;
1181
- readonly data: z.core.input<Data>;
1182
- schema(): z.ZodObject<{
1183
- name: z.ZodLiteral<Name>;
1184
- data: Data;
1185
- }, z.core.$strip>;
1186
- toObject(): {
1187
- name: Name;
1188
- data: z.core.input<Data>;
1189
- };
1190
- message: string;
1191
- stack?: string;
1192
- cause?: unknown;
1193
- };
1194
- readonly Schema: z.ZodObject<{
1195
- name: z.ZodLiteral<Name>;
1196
- data: Data;
1197
- }, z.core.$strip>;
1198
- isInstance(input: any): input is InstanceType<any>;
1199
- create<Name extends string, Data extends z.core.$ZodType>(name: Name, data: Data): any;
1200
- readonly Unknown: any;
1201
- isError(error: unknown): error is Error;
1202
- captureStackTrace(targetObject: object, constructorOpt?: Function): void;
1203
- prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
1204
- stackTraceLimit: number;
1205
- };
1206
- readonly Unknown: any;
1207
- isError(error: unknown): error is Error;
1208
- captureStackTrace(targetObject: object, constructorOpt?: Function): void;
1209
- prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
1210
- stackTraceLimit: number;
1211
- };
1212
- isError(error: unknown): error is Error;
1213
- captureStackTrace(targetObject: object, constructorOpt?: Function): void;
1214
- prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
1215
- stackTraceLimit: number;
1216
- };
1217
- function install(pkg: string, version?: string, installPath?: string): Promise<string>;
1218
1011
  const stdin: NodeJS.ReadStream & {
1219
1012
  fd: 0;
1220
1013
  };
@@ -1237,7 +1030,6 @@ declare namespace PKG {
1237
1030
  const streamingServer: typeof createStreamingServer;
1238
1031
  const webSocketServer: typeof createWebSocketServer;
1239
1032
  }
1240
- declare const $: typeof PKG.$;
1241
1033
  declare const readableStreamToText: typeof PKG.readableStreamToText;
1242
1034
  declare const whichSync: typeof PKG.whichSync;
1243
1035
 
@@ -1442,4 +1234,4 @@ declare function initLog(options: {
1442
1234
  level?: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
1443
1235
  }): Promise<void>;
1444
1236
 
1445
- export { $, Archive, AsyncQueue, Binary, type CodeSpanIndex$1 as CodeSpanIndex, Color, Context, type EasServer, Encode, EventLoop, type FenceSpan$1 as FenceSpan, Filesystem, Fn, type FormatOptions, type GitResult, Glob, Identifier, Ignore, type InlineCodeState$1 as InlineCodeState, Keybind, Lazy, Locale, Lock, Markdown, type MarkdownConfig, type MarkdownIR, type MarkdownLinkSpan, type MarkdownParseOptions, type MarkdownStyle, type MarkdownStyleSpan, type MarkdownTableMode, type MiddlewareDefinition, NamedError, type NodeSpawnObjectArgs, type NodeSpawnOptions, type NodeSpawnResult, type NodeWhichOptions, PKG, PackageRegistry, type ParseCommandResult, type ParsedFrontmatter, type ParsedVersion, PkgShell, type RPCMethod, type RenderLink, type RenderOptions, type RouteDefinition, type SSEHandler, Semver, type ServerOptions, Shell, Slug, type StreamHandler, type StyleMarker, Token, TruncateContent, type WebSocketHandler, type WebSocketRouteDefinition, Wildcard, abortAfter, abortAfterAny, buildCodeSpanIndex, chunkMarkdownIR, chunkText, chunkTextByBreakResolver, convertMarkdownTables, createInlineCodeState, createPkgShell, createRESTServer, createRPCServer, createServer, createStreamingServer, createWebSocketServer, defer, detectPlatform, escapeCommandArg, escapeCommandArgSafe, extractFrontmatter, findFenceSpanAt, findLast, fn, formatDuration, formatLocalISO, formatLocalISOCompact, formatLogTime, formatMarkdown, getDirectory, getFileExtension, getFilename, getFilenameTruncated, getTimezoneOffset, git, iife, initLog, isSafeFenceBreak, joinCommandArgs, lazy, lazyAsync, loadEnv, loadTextFile, loadTextFileAsync, markdownToIR, markdownToIRWithMeta, needsShellExecution, now, nowLocalISO, parseCommand, parseCommandWithOptions, parseFenceSpans, parseFrontmatterBlock, parseLocalISO, parseModelId, proxied, readableStreamToText, renderMarkdown, renderMarkdownWithMarkers, retry, scanParenAwareBreakpoints, serializeFrontmatter, shell, signal, startServer, truncateMiddle, updateSchema, whichSync, withTimeout, work };
1237
+ export { $, Archive, AsyncQueue, Binary, type CodeSpanIndex$1 as CodeSpanIndex, Color, Context, type EasServer, Encode, EventLoop, type FenceSpan$1 as FenceSpan, Filesystem, Fn, type FormatOptions, type GitResult, Glob, Identifier, Ignore, type InlineCodeState$1 as InlineCodeState, Keybind, Lazy, Locale, Lock, MIME_TYPES, Markdown, type MarkdownConfig, type MarkdownIR, type MarkdownLinkSpan, type MarkdownParseOptions, type MarkdownStyle, type MarkdownStyleSpan, type MarkdownTableMode, type MiddlewareDefinition, NamedError, type NodeSpawnObjectArgs, type NodeSpawnOptions, type NodeSpawnResult, type NodeWhichOptions, PKG, PackageRegistry, type ParseCommandResult, type ParsedFrontmatter, type ParsedVersion, PkgShell, type RPCMethod, type RenderLink, type RenderOptions, type RouteDefinition, type SSEHandler, Semver, type ServerOptions, Shell, Slug, type StreamHandler, type StyleMarker, Token, TruncateContent, type WebSocketHandler, type WebSocketRouteDefinition, Wildcard, abortAfter, abortAfterAny, buildCodeSpanIndex, chunkMarkdownIR, chunkText, chunkTextByBreakResolver, convertMarkdownTables, createInlineCodeState, createPkgShell, createRESTServer, createRPCServer, createServer, createStreamingServer, createWebSocketServer, defer, detectPlatform, escapeCommandArg, escapeCommandArgSafe, extractFrontmatter, findFenceSpanAt, findLast, fn, formatDuration, formatLocalISO, formatLocalISOCompact, formatLogTime, formatMarkdown, getDirectory, getFileExtension, getFilename, getFilenameTruncated, getTimezoneOffset, git, iife, initLog, isSafeFenceBreak, joinCommandArgs, lazy, lazyAsync, loadEnv, loadTextFile, loadTextFileAsync, markdownToIR, markdownToIRWithMeta, needsShellExecution, now, nowLocalISO, parseCommand, parseCommandWithOptions, parseFenceSpans, parseFrontmatterBlock, parseLocalISO, parseModelId, proxied, readableStreamToText, renderMarkdown, renderMarkdownWithMarkers, retry, scanParenAwareBreakpoints, serializeFrontmatter, shell, signal, startServer, truncateMiddle, updateSchema, whichSync, withTimeout, work };