@peterlits/snek 0.1.0 → 0.2.0-alpha.3

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/index.d.ts +129 -12
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1,9 +1,25 @@
1
+ export interface ShellOutput {
2
+ stdout: string;
3
+ stderr: string;
4
+ exitCode: number | null;
5
+ }
6
+
1
7
  /**
2
8
  * A lazy command that runs once when awaited or consumed.
3
9
  *
4
10
  * Repeated waits share the result; execution errors reject the promise.
5
11
  */
6
12
  export interface ShellCommand extends PromiseLike<void> {
13
+ /** Capture both streams; nonzero exits resolve, execution errors reject. */
14
+ nothrow(): Promise<ShellOutput>;
15
+
16
+ /**
17
+ * Merge environment overrides for this command, preserving inherited variables.
18
+ * Snapshots all own properties; keys and values must be strings.
19
+ * Throws TypeError for invalid input or after the command is consumed.
20
+ */
21
+ env(values: Record<string, string>): this;
22
+
7
23
  /**
8
24
  * Handle completion or failure, returning a Promise for the callback result.
9
25
  */
@@ -71,7 +87,12 @@ export declare const Buffer: {
71
87
  from(value: string | ArrayBuffer | Uint8Array<ArrayBuffer>): Buffer;
72
88
  };
73
89
 
74
- export interface S3ClientOptions {
90
+ export interface S3RequestOptions {
91
+ /** Positive safe integer milliseconds; defaults to the client timeout. */
92
+ timeoutMs?: number;
93
+ }
94
+
95
+ export interface S3ClientOptions extends S3RequestOptions {
75
96
  accessKeyId: string;
76
97
  secretAccessKey: string;
77
98
  bucket: string;
@@ -84,25 +105,47 @@ export interface S3ClientOptions {
84
105
 
85
106
  export interface S3PresignOptions {
86
107
  /** Defaults to "GET". */
87
- method?: "GET" | "PUT";
108
+ method?: "GET" | "PUT" | "HEAD" | "DELETE";
88
109
  /** Integer seconds from 1 to 604800. Defaults to 86400 (24 hours). */
89
110
  expiresIn?: number;
90
111
  }
91
112
 
92
- export interface S3WriteOptions {
113
+ export interface S3WriteOptions extends S3RequestOptions {
114
+ ifNoneMatch?: "*";
115
+ metadata?: Record<string, string>;
116
+ contentEncoding?: string;
117
+ contentDisposition?: string;
118
+ cacheControl?: string;
93
119
  /** Stored Content-Type; defaults to "application/octet-stream". */
94
120
  type?: string;
95
121
  }
96
122
 
123
+ export interface S3Stat {
124
+ size: number;
125
+ type: string;
126
+ etag: string;
127
+ lastModified: Date;
128
+ metadata: Record<string, string>;
129
+ contentEncoding?: string;
130
+ contentDisposition?: string;
131
+ cacheControl?: string;
132
+ }
133
+
134
+ export type S3WriteData = string | Uint8Array<ArrayBuffer> | ArrayBuffer | Blob;
135
+
97
136
  export interface S3File {
98
- /** Fresh GET, buffered in memory and decoded as UTF-8 with replacement. */
99
- text(): Promise<string>;
100
- /** Fresh GET parsed as JSON. Invalid JSON rejects with SyntaxError. */
101
- json<T = unknown>(): Promise<T>;
102
- /** Fresh GET, returning an independent ArrayBuffer. */
103
- arrayBuffer(): Promise<ArrayBuffer>;
104
- /** One PUT replacing the object. Snapshots input and resolves to its byte count. */
105
- write(data: string | Uint8Array<ArrayBuffer>, options?: S3WriteOptions): Promise<number>;
137
+ text(options?: S3RequestOptions): Promise<string>;
138
+ json<T = unknown>(options?: S3RequestOptions): Promise<T>;
139
+ arrayBuffer(options?: S3RequestOptions): Promise<ArrayBuffer>;
140
+ bytes(options?: S3RequestOptions): Promise<Uint8Array<ArrayBuffer>>;
141
+ blob(options?: S3RequestOptions): Promise<Blob>;
142
+ /** One PUT; inputs are snapshotted. Conditional writes are never retried automatically. */
143
+ write(data: S3WriteData, options?: S3WriteOptions): Promise<number>;
144
+ stat(options?: S3RequestOptions): Promise<S3Stat>;
145
+ /** Only HTTP 404 becomes false; other failures reject. */
146
+ exists(options?: S3RequestOptions): Promise<boolean>;
147
+ delete(options?: S3RequestOptions): Promise<void>;
148
+ presign(options?: S3PresignOptions): string;
106
149
  }
107
150
 
108
151
  /** Explicitly configured, path-style S3 client. No environment credential lookup. */
@@ -110,6 +153,10 @@ export declare class S3Client {
110
153
  constructor(options: S3ClientOptions);
111
154
  /** Creates a lazy reference without I/O; keys contain 1–1024 UTF-8 bytes. */
112
155
  file(key: string): S3File;
156
+ write(key: string, data: S3WriteData, options?: S3WriteOptions): Promise<number>;
157
+ stat(key: string, options?: S3RequestOptions): Promise<S3Stat>;
158
+ exists(key: string, options?: S3RequestOptions): Promise<boolean>;
159
+ delete(key: string, options?: S3RequestOptions): Promise<void>;
113
160
  /** Signs locally and synchronously, without I/O. */
114
161
  presign(key: string, options?: S3PresignOptions): string;
115
162
  }
@@ -117,6 +164,8 @@ export declare class S3Client {
117
164
  /** Read/write service and transport errors. Fields depend on the response. */
118
165
  export interface S3Error extends Error {
119
166
  name: "S3Error";
167
+ operation?: string;
168
+ key?: string;
120
169
  status?: number;
121
170
  code?: string;
122
171
  requestId?: string;
@@ -137,9 +186,21 @@ export interface CliParseResult {
137
186
  options: Record<string, string | boolean | undefined>;
138
187
  }
139
188
 
189
+ export interface CliParseConfig {
190
+ run?: boolean;
191
+ }
192
+
193
+ export interface CliCommand {
194
+ option(flags: string, description: string, config?: CliOptionConfig): this;
195
+ alias(name: string): this;
196
+ action(callback: (...args: any[]) => any): this;
197
+ }
198
+
140
199
  /** A small command-line parser with an API inspired by cac. */
141
200
  export declare class Cli {
142
201
  constructor();
202
+ command(declaration: string, description?: string): CliCommand;
203
+ runMatchedCommand(): any;
143
204
  args: string[];
144
205
  options: Record<string, string | boolean | undefined>;
145
206
  option(flags: string, description: string, config?: CliOptionConfig): this;
@@ -156,5 +217,61 @@ export declare class Cli {
156
217
  /**
157
218
  * Parse script arguments.
158
219
  */
159
- parse(args?: string[]): CliParseResult;
220
+ parse(args?: string[], config?: CliParseConfig): CliParseResult;
221
+ }
222
+
223
+ declare global {
224
+ interface ImportMeta {
225
+ dir: string;
226
+ file: string;
227
+ path: string;
228
+ url: string;
229
+ }
230
+ }
231
+
232
+ /** Create a lazy local-file reference, resolving relative paths now. */
233
+ export declare function file(path: string): LocalFile;
234
+
235
+ export interface LocalFile {
236
+ text(): Promise<string>;
237
+ json<T = unknown>(): Promise<T>;
238
+ arrayBuffer(): Promise<ArrayBuffer>;
239
+ blob(): Promise<Blob>;
240
+ /** Create or replace the file; return bytes written. Does not create parents. */
241
+ write(data: string | Uint8Array<ArrayBuffer>): Promise<number>;
242
+ /** Create or append; return bytes written. Does not create parents. */
243
+ append(data: string | Uint8Array<ArrayBuffer>): Promise<number>;
244
+ /** False for missing paths; directories and other filesystem errors reject. */
245
+ exists(): Promise<boolean>;
246
+ }
247
+
248
+ export interface FileError extends Error {
249
+ name: "FileError";
250
+ operation: string;
251
+ path: string;
252
+ code: string;
253
+ }
254
+
255
+ export interface Process {
256
+ readonly argv: string[];
257
+ readonly execPath: string;
258
+ readonly pid: number;
259
+ readonly platform: string;
260
+ readonly arch: string;
261
+ readonly version: string;
262
+ readonly env: Record<string, string | undefined>;
263
+ cwd(): string;
264
+ chdir(path: string): void;
265
+ exit(code?: number): never;
266
+ /** Integer from 0 to 255; applied after pending work completes. */
267
+ exitCode: number;
268
+ }
269
+
270
+ export declare const process: Process;
271
+
272
+ export declare class Semver {
273
+ constructor(version: string);
274
+ bump(op: "major" | "minor" | "patch" | "release" | "alpha" | "beta" | "rc"): Semver;
275
+ bump(op: "premajor" | "preminor" | "prepatch", channel?: "alpha" | "beta" | "rc"): Semver;
276
+ toString(): string;
160
277
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peterlits/snek",
3
- "version": "0.1.0",
3
+ "version": "0.2.0-alpha.3",
4
4
  "description": "TypeScript type declarations for the Snek runtime",
5
5
  "types": "./index.d.ts",
6
6
  "files": [