@elaraai/east-node-std 0.0.1-beta.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.
Files changed (101) hide show
  1. package/CLA.md +26 -0
  2. package/CONTRIBUTING.md +28 -0
  3. package/README.md +135 -0
  4. package/dist/console.d.ts +192 -0
  5. package/dist/console.d.ts.map +1 -0
  6. package/dist/console.js +228 -0
  7. package/dist/console.js.map +1 -0
  8. package/dist/crypto.d.ts +212 -0
  9. package/dist/crypto.d.ts.map +1 -0
  10. package/dist/crypto.js +259 -0
  11. package/dist/crypto.js.map +1 -0
  12. package/dist/fetch.d.ts +310 -0
  13. package/dist/fetch.d.ts.map +1 -0
  14. package/dist/fetch.js +336 -0
  15. package/dist/fetch.js.map +1 -0
  16. package/dist/fs.d.ts +520 -0
  17. package/dist/fs.d.ts.map +1 -0
  18. package/dist/fs.js +630 -0
  19. package/dist/fs.js.map +1 -0
  20. package/dist/index.d.ts +59 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +86 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/path.d.ts +241 -0
  25. package/dist/path.d.ts.map +1 -0
  26. package/dist/path.js +299 -0
  27. package/dist/path.js.map +1 -0
  28. package/dist/random/crypto-rng.d.ts +31 -0
  29. package/dist/random/crypto-rng.d.ts.map +1 -0
  30. package/dist/random/crypto-rng.js +44 -0
  31. package/dist/random/crypto-rng.js.map +1 -0
  32. package/dist/random/distributions/bates.d.ts +12 -0
  33. package/dist/random/distributions/bates.d.ts.map +1 -0
  34. package/dist/random/distributions/bates.js +15 -0
  35. package/dist/random/distributions/bates.js.map +1 -0
  36. package/dist/random/distributions/bernoulli.d.ts +12 -0
  37. package/dist/random/distributions/bernoulli.d.ts.map +1 -0
  38. package/dist/random/distributions/bernoulli.js +13 -0
  39. package/dist/random/distributions/bernoulli.js.map +1 -0
  40. package/dist/random/distributions/binomial.d.ts +12 -0
  41. package/dist/random/distributions/binomial.d.ts.map +1 -0
  42. package/dist/random/distributions/binomial.js +24 -0
  43. package/dist/random/distributions/binomial.js.map +1 -0
  44. package/dist/random/distributions/exponential.d.ts +12 -0
  45. package/dist/random/distributions/exponential.d.ts.map +1 -0
  46. package/dist/random/distributions/exponential.js +13 -0
  47. package/dist/random/distributions/exponential.js.map +1 -0
  48. package/dist/random/distributions/geometric.d.ts +12 -0
  49. package/dist/random/distributions/geometric.d.ts.map +1 -0
  50. package/dist/random/distributions/geometric.js +14 -0
  51. package/dist/random/distributions/geometric.js.map +1 -0
  52. package/dist/random/distributions/irwin-hall.d.ts +12 -0
  53. package/dist/random/distributions/irwin-hall.d.ts.map +1 -0
  54. package/dist/random/distributions/irwin-hall.js +18 -0
  55. package/dist/random/distributions/irwin-hall.js.map +1 -0
  56. package/dist/random/distributions/log-normal.d.ts +12 -0
  57. package/dist/random/distributions/log-normal.d.ts.map +1 -0
  58. package/dist/random/distributions/log-normal.js +12 -0
  59. package/dist/random/distributions/log-normal.js.map +1 -0
  60. package/dist/random/distributions/normal.d.ts +13 -0
  61. package/dist/random/distributions/normal.d.ts.map +1 -0
  62. package/dist/random/distributions/normal.js +16 -0
  63. package/dist/random/distributions/normal.js.map +1 -0
  64. package/dist/random/distributions/pareto.d.ts +12 -0
  65. package/dist/random/distributions/pareto.d.ts.map +1 -0
  66. package/dist/random/distributions/pareto.js +14 -0
  67. package/dist/random/distributions/pareto.js.map +1 -0
  68. package/dist/random/distributions/poisson.d.ts +12 -0
  69. package/dist/random/distributions/poisson.d.ts.map +1 -0
  70. package/dist/random/distributions/poisson.js +81 -0
  71. package/dist/random/distributions/poisson.js.map +1 -0
  72. package/dist/random/distributions/uniform-int.d.ts +12 -0
  73. package/dist/random/distributions/uniform-int.d.ts.map +1 -0
  74. package/dist/random/distributions/uniform-int.js +16 -0
  75. package/dist/random/distributions/uniform-int.js.map +1 -0
  76. package/dist/random/distributions/uniform.d.ts +12 -0
  77. package/dist/random/distributions/uniform.d.ts.map +1 -0
  78. package/dist/random/distributions/uniform.js +10 -0
  79. package/dist/random/distributions/uniform.js.map +1 -0
  80. package/dist/random/rng.d.ts +17 -0
  81. package/dist/random/rng.d.ts.map +1 -0
  82. package/dist/random/rng.js +7 -0
  83. package/dist/random/rng.js.map +1 -0
  84. package/dist/random/xorshift128.d.ts +35 -0
  85. package/dist/random/xorshift128.d.ts.map +1 -0
  86. package/dist/random/xorshift128.js +112 -0
  87. package/dist/random/xorshift128.js.map +1 -0
  88. package/dist/random.d.ts +773 -0
  89. package/dist/random.d.ts.map +1 -0
  90. package/dist/random.js +934 -0
  91. package/dist/random.js.map +1 -0
  92. package/dist/test.d.ts +253 -0
  93. package/dist/test.d.ts.map +1 -0
  94. package/dist/test.js +407 -0
  95. package/dist/test.js.map +1 -0
  96. package/dist/time.d.ts +130 -0
  97. package/dist/time.d.ts.map +1 -0
  98. package/dist/time.js +154 -0
  99. package/dist/time.js.map +1 -0
  100. package/dist/tsconfig.tsbuildinfo +1 -0
  101. package/package.json +84 -0
package/dist/fs.js ADDED
@@ -0,0 +1,630 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
+ */
5
+ import { East, StringType, NullType, BooleanType, ArrayType, BlobType } from "@elaraai/east";
6
+ import { EastError } from "@elaraai/east/internal";
7
+ import { readFileSync, writeFileSync, appendFileSync, unlinkSync, existsSync, statSync, mkdirSync, readdirSync, } from "node:fs";
8
+ /**
9
+ * Reads a file as a UTF-8 string.
10
+ *
11
+ * Reads the entire contents of a file synchronously and decodes it as UTF-8 text.
12
+ * Paths are resolved relative to the current working directory.
13
+ *
14
+ * This is a platform function for the East language, enabling file reading
15
+ * in East programs running on Node.js.
16
+ *
17
+ * @param path - The file path to read (relative or absolute)
18
+ * @returns The file contents as a UTF-8 string
19
+ *
20
+ * @throws {EastError} When file cannot be read:
21
+ * - File doesn't exist: `ENOENT: no such file or directory`
22
+ * - No read permission: `EACCES: permission denied`
23
+ * - Path is a directory: `EISDIR: illegal operation on a directory`
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const readConfig = East.function([], StringType, $ => {
28
+ * const content = $.let(FileSystem.readFile("config.txt"));
29
+ * return content;
30
+ * });
31
+ * ```
32
+ */
33
+ export const fs_read_file = East.platform("fs_read_file", [StringType], StringType);
34
+ /**
35
+ * Writes a string to a file (overwrites existing content).
36
+ *
37
+ * Writes string content to a file synchronously, creating the file if it doesn't exist
38
+ * and overwriting it if it does. Content is encoded as UTF-8.
39
+ *
40
+ * This is a platform function for the East language, enabling file writing
41
+ * in East programs running on Node.js.
42
+ *
43
+ * @param path - The file path to write (relative or absolute)
44
+ * @param content - The string content to write (UTF-8 encoded)
45
+ * @returns Null
46
+ *
47
+ * @throws {EastError} When file cannot be written:
48
+ * - No write permission: `EACCES: permission denied`
49
+ * - Parent directory doesn't exist: `ENOENT: no such file or directory`
50
+ * - Path is a directory: `EISDIR: illegal operation on a directory`
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * const saveOutput = East.function([], NullType, $ => {
55
+ * $(FileSystem.writeFile("output.txt", "Hello, World!"));
56
+ * });
57
+ * ```
58
+ */
59
+ export const fs_write_file = East.platform("fs_write_file", [StringType, StringType], NullType);
60
+ /**
61
+ * Appends a string to a file.
62
+ *
63
+ * Appends string content to the end of a file synchronously, creating the file
64
+ * if it doesn't exist. Content is encoded as UTF-8.
65
+ *
66
+ * This is a platform function for the East language, enabling file appending
67
+ * in East programs running on Node.js.
68
+ *
69
+ * @param path - The file path to append to (relative or absolute)
70
+ * @param content - The string content to append (UTF-8 encoded)
71
+ * @returns Null
72
+ *
73
+ * @throws {EastError} When file cannot be appended:
74
+ * - No write permission: `EACCES: permission denied`
75
+ * - Path is a directory: `EISDIR: illegal operation on a directory`
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * const appendLog = East.function([], NullType, $ => {
80
+ * $(FileSystem.appendFile("log.txt", "New log entry\n"));
81
+ * });
82
+ * ```
83
+ */
84
+ export const fs_append_file = East.platform("fs_append_file", [StringType, StringType], NullType);
85
+ /**
86
+ * Deletes a file from the file system.
87
+ *
88
+ * Removes a file synchronously. If the file doesn't exist, an error is thrown.
89
+ * This operation cannot be undone.
90
+ *
91
+ * This is a platform function for the East language, enabling file deletion
92
+ * in East programs running on Node.js.
93
+ *
94
+ * @param path - The file path to delete (relative or absolute)
95
+ * @returns Null
96
+ *
97
+ * @throws {EastError} When file cannot be deleted:
98
+ * - File doesn't exist: `ENOENT: no such file or directory`
99
+ * - No delete permission: `EACCES: permission denied`
100
+ * - Path is a directory: `EISDIR: illegal operation on a directory`
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const cleanup = East.function([], NullType, $ => {
105
+ * $(FileSystem.deleteFile("temp.txt"));
106
+ * });
107
+ * ```
108
+ */
109
+ export const fs_delete_file = East.platform("fs_delete_file", [StringType], NullType);
110
+ /**
111
+ * Checks if a file or directory exists at the given path.
112
+ *
113
+ * Tests whether a path exists in the file system, returning true if it exists
114
+ * (whether file or directory) and false otherwise. This check is synchronous
115
+ * and does not throw errors for permission issues.
116
+ *
117
+ * This is a platform function for the East language, enabling path existence checks
118
+ * in East programs running on Node.js.
119
+ *
120
+ * @param path - The path to check (relative or absolute)
121
+ * @returns True if the path exists, false otherwise
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * const checkConfig = East.function([], BooleanType, $ => {
126
+ * return FileSystem.exists("config.txt");
127
+ * });
128
+ * ```
129
+ */
130
+ export const fs_exists = East.platform("fs_exists", [StringType], BooleanType);
131
+ /**
132
+ * Checks if a path exists and is a regular file.
133
+ *
134
+ * Tests whether a path exists and is a regular file (not a directory, symlink, etc.).
135
+ * Returns false if the path doesn't exist or is not a file. Does not throw errors
136
+ * for permission issues.
137
+ *
138
+ * This is a platform function for the East language, enabling file type checks
139
+ * in East programs running on Node.js.
140
+ *
141
+ * @param path - The path to check (relative or absolute)
142
+ * @returns True if the path exists and is a file, false otherwise
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * const checkIsFile = East.function([], BooleanType, $ => {
147
+ * return FileSystem.isFile("data.json");
148
+ * });
149
+ * ```
150
+ */
151
+ export const fs_is_file = East.platform("fs_is_file", [StringType], BooleanType);
152
+ /**
153
+ * Checks if a path exists and is a directory.
154
+ *
155
+ * Tests whether a path exists and is a directory (not a regular file).
156
+ * Returns false if the path doesn't exist or is not a directory. Does not throw
157
+ * errors for permission issues.
158
+ *
159
+ * This is a platform function for the East language, enabling directory type checks
160
+ * in East programs running on Node.js.
161
+ *
162
+ * @param path - The path to check (relative or absolute)
163
+ * @returns True if the path exists and is a directory, false otherwise
164
+ *
165
+ * @example
166
+ * ```ts
167
+ * const checkIsDir = East.function([], BooleanType, $ => {
168
+ * return FileSystem.isDirectory("src");
169
+ * });
170
+ * ```
171
+ */
172
+ export const fs_is_directory = East.platform("fs_is_directory", [StringType], BooleanType);
173
+ /**
174
+ * Creates a directory, including any necessary parent directories.
175
+ *
176
+ * Creates a directory synchronously with recursive creation enabled, meaning
177
+ * all necessary parent directories will be created if they don't exist.
178
+ * If the directory already exists, no error is thrown.
179
+ *
180
+ * This is a platform function for the East language, enabling directory creation
181
+ * in East programs running on Node.js.
182
+ *
183
+ * @param path - The directory path to create (relative or absolute)
184
+ * @returns Null
185
+ *
186
+ * @throws {EastError} When directory cannot be created:
187
+ * - No write permission: `EACCES: permission denied`
188
+ * - Path exists as a file: `EEXIST: file already exists`
189
+ *
190
+ * @example
191
+ * ```ts
192
+ * const setupDirs = East.function([], NullType, $ => {
193
+ * $(FileSystem.createDirectory("output/reports/2024"));
194
+ * });
195
+ * ```
196
+ */
197
+ export const fs_create_directory = East.platform("fs_create_directory", [StringType], NullType);
198
+ /**
199
+ * Lists the names of all files and directories within a directory.
200
+ *
201
+ * Reads the contents of a directory synchronously and returns an array of entry names
202
+ * (not full paths). The entries include both files and subdirectories. Special entries
203
+ * like "." and ".." are not included. The order is not guaranteed.
204
+ *
205
+ * This is a platform function for the East language, enabling directory listing
206
+ * in East programs running on Node.js.
207
+ *
208
+ * @param path - The directory path to read (relative or absolute)
209
+ * @returns Array of file and directory names within the directory
210
+ *
211
+ * @throws {EastError} When directory cannot be read:
212
+ * - Directory doesn't exist: `ENOENT: no such file or directory`
213
+ * - No read permission: `EACCES: permission denied`
214
+ * - Path is not a directory: `ENOTDIR: not a directory`
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * const listFiles = East.function([], ArrayType(StringType), $ => {
219
+ * return FileSystem.readDirectory("src");
220
+ * // Returns: ["index.ts", "utils", "types.ts"]
221
+ * });
222
+ * ```
223
+ */
224
+ export const fs_read_directory = East.platform("fs_read_directory", [StringType], ArrayType(StringType));
225
+ /**
226
+ * Reads a file as binary data without any encoding.
227
+ *
228
+ * Reads the entire contents of a file synchronously as raw bytes, returning
229
+ * a Blob (Uint8Array) without any text decoding. Useful for reading non-text
230
+ * files like images, PDFs, or binary data formats.
231
+ *
232
+ * This is a platform function for the East language, enabling binary file reading
233
+ * in East programs running on Node.js.
234
+ *
235
+ * @param path - The file path to read (relative or absolute)
236
+ * @returns The file contents as a Blob (binary data)
237
+ *
238
+ * @throws {EastError} When file cannot be read:
239
+ * - File doesn't exist: `ENOENT: no such file or directory`
240
+ * - No read permission: `EACCES: permission denied`
241
+ * - Path is a directory: `EISDIR: illegal operation on a directory`
242
+ *
243
+ * @example
244
+ * ```ts
245
+ * const loadImage = East.function([], BlobType, $ => {
246
+ * return FileSystem.readFileBytes("logo.png");
247
+ * });
248
+ * ```
249
+ */
250
+ export const fs_read_file_bytes = East.platform("fs_read_file_bytes", [StringType], BlobType);
251
+ /**
252
+ * Writes binary data to a file (overwrites existing content).
253
+ *
254
+ * Writes raw binary data to a file synchronously without any text encoding,
255
+ * creating the file if it doesn't exist and overwriting it if it does.
256
+ * Useful for writing non-text files like images, PDFs, or binary data formats.
257
+ *
258
+ * This is a platform function for the East language, enabling binary file writing
259
+ * in East programs running on Node.js.
260
+ *
261
+ * @param path - The file path to write (relative or absolute)
262
+ * @param content - The binary content to write (Blob/Uint8Array)
263
+ * @returns Null
264
+ *
265
+ * @throws {EastError} When file cannot be written:
266
+ * - No write permission: `EACCES: permission denied`
267
+ * - Parent directory doesn't exist: `ENOENT: no such file or directory`
268
+ * - Path is a directory: `EISDIR: illegal operation on a directory`
269
+ *
270
+ * @example
271
+ * ```ts
272
+ * const saveBinary = East.function([BlobType], NullType, ($, data) => {
273
+ * $(FileSystem.writeFileBytes("output.bin", data));
274
+ * });
275
+ * ```
276
+ */
277
+ export const fs_write_file_bytes = East.platform("fs_write_file_bytes", [StringType, BlobType], NullType);
278
+ /**
279
+ * Node.js implementation of file system platform functions.
280
+ *
281
+ * Pass this array to {@link East.compile} to enable file system operations.
282
+ */
283
+ const FileSystemImpl = [
284
+ fs_read_file.implement((path) => {
285
+ try {
286
+ return readFileSync(path, 'utf-8');
287
+ }
288
+ catch (err) {
289
+ throw new EastError(`Failed to read file ${path}: ${err.message}`, {
290
+ location: { filename: "fs_read_file", line: 0n, column: 0n },
291
+ cause: err
292
+ });
293
+ }
294
+ }),
295
+ fs_write_file.implement((path, content) => {
296
+ try {
297
+ writeFileSync(path, content, 'utf-8');
298
+ }
299
+ catch (err) {
300
+ throw new EastError(`Failed to write file ${path}: ${err.message}`, {
301
+ location: { filename: "fs_write_file", line: 0n, column: 0n },
302
+ cause: err
303
+ });
304
+ }
305
+ }),
306
+ fs_append_file.implement((path, content) => {
307
+ try {
308
+ appendFileSync(path, content, 'utf-8');
309
+ }
310
+ catch (err) {
311
+ throw new EastError(`Failed to append to file ${path}: ${err.message}`, {
312
+ location: { filename: "fs_append_file", line: 0n, column: 0n },
313
+ cause: err
314
+ });
315
+ }
316
+ }),
317
+ fs_delete_file.implement((path) => {
318
+ try {
319
+ unlinkSync(path);
320
+ }
321
+ catch (err) {
322
+ throw new EastError(`Failed to delete file ${path}: ${err.message}`, {
323
+ location: { filename: "fs_delete_file", line: 0n, column: 0n },
324
+ cause: err
325
+ });
326
+ }
327
+ }),
328
+ fs_exists.implement((path) => {
329
+ return existsSync(path);
330
+ }),
331
+ fs_is_file.implement((path) => {
332
+ try {
333
+ return existsSync(path) && statSync(path).isFile();
334
+ }
335
+ catch {
336
+ return false;
337
+ }
338
+ }),
339
+ fs_is_directory.implement((path) => {
340
+ try {
341
+ return existsSync(path) && statSync(path).isDirectory();
342
+ }
343
+ catch {
344
+ return false;
345
+ }
346
+ }),
347
+ fs_create_directory.implement((path) => {
348
+ try {
349
+ mkdirSync(path, { recursive: true });
350
+ }
351
+ catch (err) {
352
+ throw new EastError(`Failed to create directory ${path}: ${err.message}`, {
353
+ location: { filename: "fs_create_directory", line: 0n, column: 0n },
354
+ cause: err
355
+ });
356
+ }
357
+ }),
358
+ fs_read_directory.implement((path) => {
359
+ try {
360
+ return readdirSync(path);
361
+ }
362
+ catch (err) {
363
+ throw new EastError(`Failed to read directory ${path}: ${err.message}`, {
364
+ location: { filename: "fs_read_directory", line: 0n, column: 0n },
365
+ cause: err
366
+ });
367
+ }
368
+ }),
369
+ fs_read_file_bytes.implement((path) => {
370
+ try {
371
+ return readFileSync(path);
372
+ }
373
+ catch (err) {
374
+ throw new EastError(`Failed to read file bytes ${path}: ${err.message}`, {
375
+ location: { filename: "fs_read_file_bytes", line: 0n, column: 0n },
376
+ cause: err
377
+ });
378
+ }
379
+ }),
380
+ fs_write_file_bytes.implement((path, content) => {
381
+ try {
382
+ writeFileSync(path, content);
383
+ }
384
+ catch (err) {
385
+ throw new EastError(`Failed to write file bytes ${path}: ${err.message}`, {
386
+ location: { filename: "fs_write_file_bytes", line: 0n, column: 0n },
387
+ cause: err
388
+ });
389
+ }
390
+ }),
391
+ ];
392
+ /**
393
+ * Grouped file system platform functions.
394
+ *
395
+ * Provides file system operations for East programs.
396
+ *
397
+ * @example
398
+ * ```ts
399
+ * import { East, NullType } from "@elaraai/east";
400
+ * import { FileSystem } from "@elaraai/east-node-std";
401
+ *
402
+ * const processFile = East.function([], NullType, $ => {
403
+ * const content = $.let(FileSystem.readFile("input.txt"));
404
+ * $(FileSystem.writeFile("output.txt", content));
405
+ * });
406
+ *
407
+ * const compiled = East.compile(processFile.toIR(), FileSystem.Implementation);
408
+ * await compiled();
409
+ * ```
410
+ */
411
+ export const FileSystem = {
412
+ /**
413
+ * Reads a file as a UTF-8 string.
414
+ *
415
+ * Reads the entire contents of a file synchronously and decodes it as UTF-8 text.
416
+ * Paths are resolved relative to the current working directory.
417
+ *
418
+ * @param path - The file path to read (relative or absolute)
419
+ * @returns The file contents as a UTF-8 string
420
+ * @throws {EastError} When file cannot be read (ENOENT, EACCES, EISDIR)
421
+ *
422
+ * @example
423
+ * ```ts
424
+ * const readConfig = East.function([], StringType, $ => {
425
+ * const content = $.let(FileSystem.readFile("config.txt"));
426
+ * return content;
427
+ * });
428
+ *
429
+ * const compiled = East.compile(readConfig.toIR(), FileSystem.Implementation);
430
+ * await compiled(); // Returns file content as string
431
+ * ```
432
+ */
433
+ readFile: fs_read_file,
434
+ /**
435
+ * Writes a string to a file (overwrites existing content).
436
+ *
437
+ * Writes string content to a file synchronously, creating the file if it doesn't exist
438
+ * and overwriting it if it does. Content is encoded as UTF-8.
439
+ *
440
+ * @param path - The file path to write (relative or absolute)
441
+ * @param content - The string content to write (UTF-8 encoded)
442
+ * @returns Null
443
+ * @throws {EastError} When file cannot be written (EACCES, ENOENT, EISDIR)
444
+ *
445
+ * @example
446
+ * ```ts
447
+ * const saveOutput = East.function([], NullType, $ => {
448
+ * $(FileSystem.writeFile("output.txt", "Hello, World!"));
449
+ * });
450
+ *
451
+ * const compiled = East.compile(saveOutput.toIR(), FileSystem.Implementation);
452
+ * await compiled(); // File written successfully
453
+ * ```
454
+ */
455
+ writeFile: fs_write_file,
456
+ /**
457
+ * Appends a string to a file.
458
+ *
459
+ * Appends string content to the end of a file synchronously, creating the file
460
+ * if it doesn't exist. Content is encoded as UTF-8.
461
+ *
462
+ * @param path - The file path to append to (relative or absolute)
463
+ * @param content - The string content to append (UTF-8 encoded)
464
+ * @returns Null
465
+ * @throws {EastError} When file cannot be appended (EACCES, EISDIR)
466
+ *
467
+ * @example
468
+ * ```ts
469
+ * const appendLog = East.function([], NullType, $ => {
470
+ * $(FileSystem.appendFile("log.txt", "New log entry\n"));
471
+ * });
472
+ * ```
473
+ */
474
+ appendFile: fs_append_file,
475
+ /**
476
+ * Deletes a file from the file system.
477
+ *
478
+ * Removes a file synchronously. If the file doesn't exist, an error is thrown.
479
+ * This operation cannot be undone.
480
+ *
481
+ * @param path - The file path to delete (relative or absolute)
482
+ * @returns Null
483
+ * @throws {EastError} When file cannot be deleted (ENOENT, EACCES, EISDIR)
484
+ *
485
+ * @example
486
+ * ```ts
487
+ * const cleanup = East.function([], NullType, $ => {
488
+ * $(FileSystem.deleteFile("temp.txt"));
489
+ * });
490
+ * ```
491
+ */
492
+ deleteFile: fs_delete_file,
493
+ /**
494
+ * Checks if a file or directory exists at the given path.
495
+ *
496
+ * Tests whether a path exists in the file system, returning true if it exists
497
+ * (whether file or directory) and false otherwise.
498
+ *
499
+ * @param path - The path to check (relative or absolute)
500
+ * @returns True if the path exists, false otherwise
501
+ *
502
+ * @example
503
+ * ```ts
504
+ * const checkConfig = East.function([], BooleanType, $ => {
505
+ * return FileSystem.exists("config.txt");
506
+ * });
507
+ * ```
508
+ */
509
+ exists: fs_exists,
510
+ /**
511
+ * Checks if a path exists and is a regular file.
512
+ *
513
+ * Tests whether a path exists and is a regular file (not a directory, symlink, etc.).
514
+ * Returns false if the path doesn't exist or is not a file.
515
+ *
516
+ * @param path - The path to check (relative or absolute)
517
+ * @returns True if the path exists and is a file, false otherwise
518
+ *
519
+ * @example
520
+ * ```ts
521
+ * const checkIsFile = East.function([], BooleanType, $ => {
522
+ * return FileSystem.isFile("data.json");
523
+ * });
524
+ * ```
525
+ */
526
+ isFile: fs_is_file,
527
+ /**
528
+ * Checks if a path exists and is a directory.
529
+ *
530
+ * Tests whether a path exists and is a directory (not a regular file).
531
+ * Returns false if the path doesn't exist or is not a directory.
532
+ *
533
+ * @param path - The path to check (relative or absolute)
534
+ * @returns True if the path exists and is a directory, false otherwise
535
+ *
536
+ * @example
537
+ * ```ts
538
+ * const checkIsDir = East.function([], BooleanType, $ => {
539
+ * return FileSystem.isDirectory("src");
540
+ * });
541
+ * ```
542
+ */
543
+ isDirectory: fs_is_directory,
544
+ /**
545
+ * Creates a directory, including any necessary parent directories.
546
+ *
547
+ * Creates a directory synchronously with recursive creation enabled, meaning
548
+ * all necessary parent directories will be created if they don't exist.
549
+ *
550
+ * @param path - The directory path to create (relative or absolute)
551
+ * @returns Null
552
+ * @throws {EastError} When directory cannot be created (EACCES, EEXIST)
553
+ *
554
+ * @example
555
+ * ```ts
556
+ * const setupDirs = East.function([], NullType, $ => {
557
+ * $(FileSystem.createDirectory("output/reports/2024"));
558
+ * });
559
+ * ```
560
+ */
561
+ createDirectory: fs_create_directory,
562
+ /**
563
+ * Lists the names of all files and directories within a directory.
564
+ *
565
+ * Reads the contents of a directory synchronously and returns an array of entry names
566
+ * (not full paths). The entries include both files and subdirectories.
567
+ *
568
+ * @param path - The directory path to read (relative or absolute)
569
+ * @returns Array of file and directory names within the directory
570
+ * @throws {EastError} When directory cannot be read (ENOENT, EACCES, ENOTDIR)
571
+ *
572
+ * @example
573
+ * ```ts
574
+ * const listFiles = East.function([], ArrayType(StringType), $ => {
575
+ * return FileSystem.readDirectory("src");
576
+ * });
577
+ * ```
578
+ */
579
+ readDirectory: fs_read_directory,
580
+ /**
581
+ * Reads a file as binary data without any encoding.
582
+ *
583
+ * Reads the entire contents of a file synchronously as raw bytes, returning
584
+ * a Blob (Uint8Array) without any text decoding.
585
+ *
586
+ * @param path - The file path to read (relative or absolute)
587
+ * @returns The file contents as a Blob (binary data)
588
+ * @throws {EastError} When file cannot be read (ENOENT, EACCES, EISDIR)
589
+ *
590
+ * @example
591
+ * ```ts
592
+ * const loadImage = East.function([], BlobType, $ => {
593
+ * return FileSystem.readFileBytes("logo.png");
594
+ * });
595
+ * ```
596
+ */
597
+ readFileBytes: fs_read_file_bytes,
598
+ /**
599
+ * Writes binary data to a file (overwrites existing content).
600
+ *
601
+ * Writes raw binary data to a file synchronously without any text encoding,
602
+ * creating the file if it doesn't exist and overwriting it if it does.
603
+ *
604
+ * @param path - The file path to write (relative or absolute)
605
+ * @param content - The binary content to write (Blob/Uint8Array)
606
+ * @returns Null
607
+ * @throws {EastError} When file cannot be written (EACCES, ENOENT, EISDIR)
608
+ *
609
+ * @example
610
+ * ```ts
611
+ * const saveBinary = East.function([BlobType], NullType, ($, data) => {
612
+ * $(FileSystem.writeFileBytes("output.bin", data));
613
+ * });
614
+ *
615
+ * const compiled = East.compile(saveBinary.toIR(), FileSystem.Implementation);
616
+ * const binaryData = new Uint8Array([1, 2, 3, 4]);
617
+ * await compiled(binaryData); // Binary data written to file
618
+ * ```
619
+ */
620
+ writeFileBytes: fs_write_file_bytes,
621
+ /**
622
+ * Node.js implementation of file system platform functions.
623
+ *
624
+ * Pass this to {@link East.compile} to enable file system operations.
625
+ */
626
+ Implementation: FileSystemImpl,
627
+ };
628
+ // Export for backwards compatibility
629
+ export { FileSystemImpl };
630
+ //# sourceMappingURL=fs.js.map
package/dist/fs.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE7F,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EACH,YAAY,EACZ,aAAa,EACb,cAAc,EACd,UAAU,EACV,UAAU,EACV,QAAQ,EACR,SAAS,EACT,WAAW,GACd,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAgE,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,UAAU,CAAC,EAAE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AAW,EAAE,eAAe;IAE5B;;;;;;;;;;;;;;;;OAgBG;IACH,eAAe,EAAE,mBAAmB;IAEpC;;;;;;;;;;;;;;;;OAgBG;IACH,aAAa,EAAE,iBAAiB;IAEhC;;;;;;;;;;;;;;;;OAgBG;IACH,aAAa,EAAE,kBAAkB;IAEjC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,cAAc,EAAE,mBAAmB;IAEnC;;;;OAIG;IACH,cAAc,EAAE,cAAc;CACxB,CAAC;AAEX,qCAAqC;AACrC,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
+ */
5
+ /**
6
+ * East Node - Node.js platform integration for East language
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ export * from "./test.js";
11
+ export * from "./console.js";
12
+ export * from "./fs.js";
13
+ export * from "./path.js";
14
+ export * from "./crypto.js";
15
+ export * from "./time.js";
16
+ export * from "./fetch.js";
17
+ export * from "./random.js";
18
+ /**
19
+ * Complete Node.js platform implementation.
20
+ *
21
+ * Pass this array to `compile()` or `compileAsync()` to enable all Node.js platform functions.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { East, NullType } from "@elaraai/east";
26
+ * import { NodePlatform, Console, FileSystem } from "@elaraai/east-node-std";
27
+ *
28
+ * const fn = East.function([], NullType, $ => {
29
+ * const content = $.let(FileSystem.readFile("data.txt"));
30
+ * $(Console.log(content));
31
+ * });
32
+ *
33
+ * // Note: Use compileAsync since TimeImpl uses async
34
+ * const compiled = fn.toIR().compileAsync(NodePlatform);
35
+ * await compiled();
36
+ * ```
37
+ */
38
+ export declare const NodePlatform: import("@elaraai/east/internal").PlatformFunction[];
39
+ /**
40
+ * Synchronous subset of Node.js platform (excludes Time.sleep and Fetch operations).
41
+ *
42
+ * Use this for programs that don't need async operations.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * import { East, NullType } from "@elaraai/east";
47
+ * import { NodePlatformSync, Console } from "@elaraai/east-node-std";
48
+ *
49
+ * const fn = East.function([], NullType, $ => {
50
+ * $(Console.log("Hello, World!"));
51
+ * });
52
+ *
53
+ * const compiled = fn.toIR().compile(NodePlatformSync);
54
+ * compiled();
55
+ * ```
56
+ */
57
+ export declare const NodePlatformSync: import("@elaraai/east/internal").PlatformFunction[];
58
+ export * as EastNode from './index.js';
59
+ //# sourceMappingURL=index.d.ts.map