@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAGH,cAAc,WAAW,CAAC;AAG1B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAW5B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,YAAY,qDAQxB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,gBAAgB,qDAQ5B,CAAC;AAGF,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,86 @@
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 test utilities
11
+ export * from "./test.js";
12
+ // Export platform function definitions and implementations
13
+ export * from "./console.js";
14
+ export * from "./fs.js";
15
+ export * from "./path.js";
16
+ export * from "./crypto.js";
17
+ export * from "./time.js";
18
+ export * from "./fetch.js";
19
+ export * from "./random.js";
20
+ // Import implementations for combined export
21
+ import { ConsoleImpl } from "./console.js";
22
+ import { FileSystemImpl } from "./fs.js";
23
+ import { PathImpl } from "./path.js";
24
+ import { CryptoImpl } from "./crypto.js";
25
+ import { TimeImpl } from "./time.js";
26
+ import { FetchImpl } from "./fetch.js";
27
+ import { RandomImpl } from "./random.js";
28
+ /**
29
+ * Complete Node.js platform implementation.
30
+ *
31
+ * Pass this array to `compile()` or `compileAsync()` to enable all Node.js platform functions.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { East, NullType } from "@elaraai/east";
36
+ * import { NodePlatform, Console, FileSystem } from "@elaraai/east-node-std";
37
+ *
38
+ * const fn = East.function([], NullType, $ => {
39
+ * const content = $.let(FileSystem.readFile("data.txt"));
40
+ * $(Console.log(content));
41
+ * });
42
+ *
43
+ * // Note: Use compileAsync since TimeImpl uses async
44
+ * const compiled = fn.toIR().compileAsync(NodePlatform);
45
+ * await compiled();
46
+ * ```
47
+ */
48
+ export const NodePlatform = [
49
+ ...ConsoleImpl,
50
+ ...FileSystemImpl,
51
+ ...PathImpl,
52
+ ...CryptoImpl,
53
+ ...TimeImpl,
54
+ ...FetchImpl,
55
+ ...RandomImpl,
56
+ ];
57
+ /**
58
+ * Synchronous subset of Node.js platform (excludes Time.sleep and Fetch operations).
59
+ *
60
+ * Use this for programs that don't need async operations.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * import { East, NullType } from "@elaraai/east";
65
+ * import { NodePlatformSync, Console } from "@elaraai/east-node-std";
66
+ *
67
+ * const fn = East.function([], NullType, $ => {
68
+ * $(Console.log("Hello, World!"));
69
+ * });
70
+ *
71
+ * const compiled = fn.toIR().compile(NodePlatformSync);
72
+ * compiled();
73
+ * ```
74
+ */
75
+ export const NodePlatformSync = [
76
+ ...ConsoleImpl,
77
+ ...FileSystemImpl,
78
+ ...PathImpl,
79
+ ...CryptoImpl,
80
+ ...RandomImpl,
81
+ // TimeImpl excluded (has async sleep)
82
+ // FetchImpl excluded (all async)
83
+ ];
84
+ // Re-export all exports as a nested EastNode namespace (matching East.East pattern)
85
+ export * as EastNode from './index.js';
86
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,wBAAwB;AACxB,cAAc,WAAW,CAAC;AAE1B,2DAA2D;AAC3D,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAE5B,6CAA6C;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB,GAAG,WAAW;IACd,GAAG,cAAc;IACjB,GAAG,QAAQ;IACX,GAAG,UAAU;IACb,GAAG,QAAQ;IACX,GAAG,SAAS;IACZ,GAAG,UAAU;CAChB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC5B,GAAG,WAAW;IACd,GAAG,cAAc;IACjB,GAAG,QAAQ;IACX,GAAG,UAAU;IACb,GAAG,UAAU;IACb,sCAAsC;IACtC,iCAAiC;CACpC,CAAC;AAEF,oFAAoF;AACpF,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC"}
package/dist/path.d.ts ADDED
@@ -0,0 +1,241 @@
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 { StringType, ArrayType } from "@elaraai/east";
6
+ import type { PlatformFunction, PlatformFunctionDef } from "@elaraai/east/internal";
7
+ /**
8
+ * Joins path segments into a single path.
9
+ *
10
+ * Combines an array of path segments using the platform-specific path separator.
11
+ * Normalizes the resulting path by resolving `.` and `..` segments. Empty segments
12
+ * are ignored.
13
+ *
14
+ * This is a platform function for the East language, enabling path joining
15
+ * in East programs running on Node.js.
16
+ *
17
+ * @param segments - Array of path segments to join (e.g., ["dir", "subdir", "file.txt"])
18
+ * @returns The joined path with platform-specific separators
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const buildPath = East.function([], StringType, $ => {
23
+ * const segments = East.value(["home", "user", "documents", "file.txt"]);
24
+ * return Path.join(segments);
25
+ * // Returns: "home/user/documents/file.txt" (Unix) or "home\\user\\documents\\file.txt" (Windows)
26
+ * });
27
+ * ```
28
+ */
29
+ export declare const path_join: PlatformFunctionDef<[ReturnType<typeof ArrayType<typeof StringType>>], typeof StringType>;
30
+ /**
31
+ * Resolves a path to an absolute path.
32
+ *
33
+ * Converts a relative path to an absolute path by resolving it against the current
34
+ * working directory. If the path is already absolute, it is normalized and returned.
35
+ * Resolves `.` and `..` segments to their actual locations.
36
+ *
37
+ * This is a platform function for the East language, enabling path resolution
38
+ * in East programs running on Node.js.
39
+ *
40
+ * @param path - The path to resolve (relative or absolute)
41
+ * @returns The absolute path
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * const getAbsolutePath = East.function([], StringType, $ => {
46
+ * return Path.resolve("../documents/file.txt");
47
+ * // Returns: "/home/user/documents/file.txt" (example)
48
+ * });
49
+ * ```
50
+ */
51
+ export declare const path_resolve: PlatformFunctionDef<[typeof StringType], typeof StringType>;
52
+ /**
53
+ * Gets the directory name from a path.
54
+ *
55
+ * Extracts the directory portion of a path by removing the last segment (file name).
56
+ * Similar to the Unix `dirname` command. Trailing path separators are ignored.
57
+ *
58
+ * This is a platform function for the East language, enabling directory extraction
59
+ * in East programs running on Node.js.
60
+ *
61
+ * @param path - The file path to extract directory from
62
+ * @returns The directory portion of the path
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * const getDir = East.function([], StringType, $ => {
67
+ * return Path.dirname("/home/user/documents/file.txt");
68
+ * // Returns: "/home/user/documents"
69
+ * });
70
+ * ```
71
+ */
72
+ export declare const path_dirname: PlatformFunctionDef<[typeof StringType], typeof StringType>;
73
+ /**
74
+ * Gets the base name (file name) from a path.
75
+ *
76
+ * Extracts the last segment of a path, typically the file name. Similar to the Unix
77
+ * `basename` command. Trailing path separators are ignored.
78
+ *
79
+ * This is a platform function for the East language, enabling filename extraction
80
+ * in East programs running on Node.js.
81
+ *
82
+ * @param path - The file path to extract filename from
83
+ * @returns The file name portion of the path (including extension)
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * const getFilename = East.function([], StringType, $ => {
88
+ * return Path.basename("/home/user/documents/file.txt");
89
+ * // Returns: "file.txt"
90
+ * });
91
+ * ```
92
+ */
93
+ export declare const path_basename: PlatformFunctionDef<[typeof StringType], typeof StringType>;
94
+ /**
95
+ * Gets the file extension from a path.
96
+ *
97
+ * Extracts the file extension from a path, including the leading dot. If the path
98
+ * has no extension or ends with a dot, returns an empty string. Only returns the
99
+ * last extension if multiple dots are present.
100
+ *
101
+ * This is a platform function for the East language, enabling extension extraction
102
+ * in East programs running on Node.js.
103
+ *
104
+ * @param path - The file path to extract extension from
105
+ * @returns The file extension including the dot (e.g., ".txt"), or empty string if none
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * const getExtension = East.function([], StringType, $ => {
110
+ * return Path.extname("/home/user/documents/file.txt");
111
+ * // Returns: ".txt"
112
+ * });
113
+ * ```
114
+ */
115
+ export declare const path_extname: PlatformFunctionDef<[typeof StringType], typeof StringType>;
116
+ /**
117
+ * Node.js implementation of path platform functions.
118
+ *
119
+ * Pass this array to {@link East.compile} to enable path operations.
120
+ */
121
+ declare const PathImpl: PlatformFunction[];
122
+ /**
123
+ * Grouped path manipulation platform functions.
124
+ *
125
+ * Provides path utilities for East programs.
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * import { East, StringType } from "@elaraai/east";
130
+ * import { Path } from "@elaraai/east-node-std";
131
+ *
132
+ * const buildPath = East.function([], StringType, $ => {
133
+ * const segments = East.value(["dir", "subdir", "file.txt"]);
134
+ * const fullPath = $.let(Path.join(segments));
135
+ * const ext = $.let(Path.extname(fullPath));
136
+ * return fullPath;
137
+ * });
138
+ *
139
+ * const compiled = East.compile(buildPath.toIR(), Path.Implementation);
140
+ * await compiled(); // Returns: "dir/subdir/file.txt"
141
+ * ```
142
+ */
143
+ export declare const Path: {
144
+ /**
145
+ * Joins path segments into a single path.
146
+ *
147
+ * Combines an array of path segments using the platform-specific path separator.
148
+ * Normalizes the resulting path and ignores empty segments.
149
+ *
150
+ * @param segments - Array of path segments to join
151
+ * @returns The joined path with platform-specific separators
152
+ *
153
+ * @example
154
+ * ```ts
155
+ * const buildPath = East.function([], StringType, $ => {
156
+ * const segments = East.value(["home", "user", "file.txt"]);
157
+ * return Path.join(segments);
158
+ * });
159
+ * ```
160
+ */
161
+ readonly join: PlatformFunctionDef<[ArrayType<StringType>], StringType>;
162
+ /**
163
+ * Resolves a path to an absolute path.
164
+ *
165
+ * Converts a relative path to an absolute path by resolving it against the
166
+ * current working directory. Normalizes the path and resolves `.` and `..` segments.
167
+ *
168
+ * @param path - The path to resolve (relative or absolute)
169
+ * @returns The absolute path
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * const getAbsolutePath = East.function([], StringType, $ => {
174
+ * return Path.resolve("../documents/file.txt");
175
+ * });
176
+ * ```
177
+ */
178
+ readonly resolve: PlatformFunctionDef<[StringType], StringType>;
179
+ /**
180
+ * Gets the directory name from a path.
181
+ *
182
+ * Extracts the directory portion of a path by removing the last segment (file name).
183
+ * Trailing path separators are ignored.
184
+ *
185
+ * @param path - The file path to extract directory from
186
+ * @returns The directory portion of the path
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * const getDir = East.function([], StringType, $ => {
191
+ * return Path.dirname("/home/user/documents/file.txt");
192
+ * });
193
+ * ```
194
+ */
195
+ readonly dirname: PlatformFunctionDef<[StringType], StringType>;
196
+ /**
197
+ * Gets the base name (file name) from a path.
198
+ *
199
+ * Extracts the last segment of a path, typically the file name.
200
+ * Trailing path separators are ignored.
201
+ *
202
+ * @param path - The file path to extract filename from
203
+ * @returns The file name portion of the path (including extension)
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * const getFilename = East.function([], StringType, $ => {
208
+ * return Path.basename("/home/user/documents/file.txt");
209
+ * });
210
+ * ```
211
+ */
212
+ readonly basename: PlatformFunctionDef<[StringType], StringType>;
213
+ /**
214
+ * Gets the file extension from a path.
215
+ *
216
+ * Extracts the file extension from a path, including the leading dot.
217
+ * Returns empty string if no extension exists.
218
+ *
219
+ * @param path - The file path to extract extension from
220
+ * @returns The file extension including the dot (e.g., ".txt"), or empty string
221
+ *
222
+ * @example
223
+ * ```ts
224
+ * const getExtension = East.function([], StringType, $ => {
225
+ * return Path.extname("file.txt");
226
+ * });
227
+ *
228
+ * const compiled = East.compile(getExtension.toIR(), Path.Implementation);
229
+ * await compiled(); // Returns: ".txt"
230
+ * ```
231
+ */
232
+ readonly extname: PlatformFunctionDef<[StringType], StringType>;
233
+ /**
234
+ * Node.js implementation of path platform functions.
235
+ *
236
+ * Pass this to {@link East.compile} to enable path operations.
237
+ */
238
+ readonly Implementation: PlatformFunction[];
239
+ };
240
+ export { PathImpl };
241
+ //# sourceMappingURL=path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAQ,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAIpF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,SAAS,EAAE,mBAAmB,CAAC,CAAC,UAAU,CAAC,OAAO,SAAS,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,UAAU,CAAmE,CAAC;AAEpL;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,YAAY,EAAE,mBAAmB,CAAC,CAAC,OAAO,UAAU,CAAC,EAAE,OAAO,UAAU,CAA2D,CAAC;AAEjJ;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,YAAY,EAAE,mBAAmB,CAAC,CAAC,OAAO,UAAU,CAAC,EAAE,OAAO,UAAU,CAA2D,CAAC;AAEjJ;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,aAAa,EAAE,mBAAmB,CAAC,CAAC,OAAO,UAAU,CAAC,EAAE,OAAO,UAAU,CAA4D,CAAC;AAEnJ;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,YAAY,EAAE,mBAAmB,CAAC,CAAC,OAAO,UAAU,CAAC,EAAE,OAAO,UAAU,CAA2D,CAAC;AAEjJ;;;;GAIG;AACH,QAAA,MAAM,QAAQ,EAAE,gBAAgB,EAmD/B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,IAAI;IACb;;;;;;;;;;;;;;;;OAgBG;;IAGH;;;;;;;;;;;;;;;OAeG;;IAGH;;;;;;;;;;;;;;;OAeG;;IAGH;;;;;;;;;;;;;;;OAeG;;IAGH;;;;;;;;;;;;;;;;;;OAkBG;;IAGH;;;;OAIG;;CAEG,CAAC;AAGX,OAAO,EAAE,QAAQ,EAAE,CAAC"}
package/dist/path.js ADDED
@@ -0,0 +1,299 @@
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, ArrayType } from "@elaraai/east";
6
+ import { EastError } from "@elaraai/east/internal";
7
+ import { join, resolve, dirname, basename, extname } from "node:path";
8
+ /**
9
+ * Joins path segments into a single path.
10
+ *
11
+ * Combines an array of path segments using the platform-specific path separator.
12
+ * Normalizes the resulting path by resolving `.` and `..` segments. Empty segments
13
+ * are ignored.
14
+ *
15
+ * This is a platform function for the East language, enabling path joining
16
+ * in East programs running on Node.js.
17
+ *
18
+ * @param segments - Array of path segments to join (e.g., ["dir", "subdir", "file.txt"])
19
+ * @returns The joined path with platform-specific separators
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const buildPath = East.function([], StringType, $ => {
24
+ * const segments = East.value(["home", "user", "documents", "file.txt"]);
25
+ * return Path.join(segments);
26
+ * // Returns: "home/user/documents/file.txt" (Unix) or "home\\user\\documents\\file.txt" (Windows)
27
+ * });
28
+ * ```
29
+ */
30
+ export const path_join = East.platform("path_join", [ArrayType(StringType)], StringType);
31
+ /**
32
+ * Resolves a path to an absolute path.
33
+ *
34
+ * Converts a relative path to an absolute path by resolving it against the current
35
+ * working directory. If the path is already absolute, it is normalized and returned.
36
+ * Resolves `.` and `..` segments to their actual locations.
37
+ *
38
+ * This is a platform function for the East language, enabling path resolution
39
+ * in East programs running on Node.js.
40
+ *
41
+ * @param path - The path to resolve (relative or absolute)
42
+ * @returns The absolute path
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const getAbsolutePath = East.function([], StringType, $ => {
47
+ * return Path.resolve("../documents/file.txt");
48
+ * // Returns: "/home/user/documents/file.txt" (example)
49
+ * });
50
+ * ```
51
+ */
52
+ export const path_resolve = East.platform("path_resolve", [StringType], StringType);
53
+ /**
54
+ * Gets the directory name from a path.
55
+ *
56
+ * Extracts the directory portion of a path by removing the last segment (file name).
57
+ * Similar to the Unix `dirname` command. Trailing path separators are ignored.
58
+ *
59
+ * This is a platform function for the East language, enabling directory extraction
60
+ * in East programs running on Node.js.
61
+ *
62
+ * @param path - The file path to extract directory from
63
+ * @returns The directory portion of the path
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * const getDir = East.function([], StringType, $ => {
68
+ * return Path.dirname("/home/user/documents/file.txt");
69
+ * // Returns: "/home/user/documents"
70
+ * });
71
+ * ```
72
+ */
73
+ export const path_dirname = East.platform("path_dirname", [StringType], StringType);
74
+ /**
75
+ * Gets the base name (file name) from a path.
76
+ *
77
+ * Extracts the last segment of a path, typically the file name. Similar to the Unix
78
+ * `basename` command. Trailing path separators are ignored.
79
+ *
80
+ * This is a platform function for the East language, enabling filename extraction
81
+ * in East programs running on Node.js.
82
+ *
83
+ * @param path - The file path to extract filename from
84
+ * @returns The file name portion of the path (including extension)
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const getFilename = East.function([], StringType, $ => {
89
+ * return Path.basename("/home/user/documents/file.txt");
90
+ * // Returns: "file.txt"
91
+ * });
92
+ * ```
93
+ */
94
+ export const path_basename = East.platform("path_basename", [StringType], StringType);
95
+ /**
96
+ * Gets the file extension from a path.
97
+ *
98
+ * Extracts the file extension from a path, including the leading dot. If the path
99
+ * has no extension or ends with a dot, returns an empty string. Only returns the
100
+ * last extension if multiple dots are present.
101
+ *
102
+ * This is a platform function for the East language, enabling extension extraction
103
+ * in East programs running on Node.js.
104
+ *
105
+ * @param path - The file path to extract extension from
106
+ * @returns The file extension including the dot (e.g., ".txt"), or empty string if none
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * const getExtension = East.function([], StringType, $ => {
111
+ * return Path.extname("/home/user/documents/file.txt");
112
+ * // Returns: ".txt"
113
+ * });
114
+ * ```
115
+ */
116
+ export const path_extname = East.platform("path_extname", [StringType], StringType);
117
+ /**
118
+ * Node.js implementation of path platform functions.
119
+ *
120
+ * Pass this array to {@link East.compile} to enable path operations.
121
+ */
122
+ const PathImpl = [
123
+ path_join.implement((segments) => {
124
+ try {
125
+ return join(...segments);
126
+ }
127
+ catch (err) {
128
+ throw new EastError(`Failed to join path segments: ${err.message}`, {
129
+ location: { filename: "path_join", line: 0n, column: 0n },
130
+ cause: err
131
+ });
132
+ }
133
+ }),
134
+ path_resolve.implement((path) => {
135
+ try {
136
+ return resolve(path);
137
+ }
138
+ catch (err) {
139
+ throw new EastError(`Failed to resolve path: ${err.message}`, {
140
+ location: { filename: "path_resolve", line: 0n, column: 0n },
141
+ cause: err
142
+ });
143
+ }
144
+ }),
145
+ path_dirname.implement((path) => {
146
+ try {
147
+ return dirname(path);
148
+ }
149
+ catch (err) {
150
+ throw new EastError(`Failed to get dirname: ${err.message}`, {
151
+ location: { filename: "path_dirname", line: 0n, column: 0n },
152
+ cause: err
153
+ });
154
+ }
155
+ }),
156
+ path_basename.implement((path) => {
157
+ try {
158
+ return basename(path);
159
+ }
160
+ catch (err) {
161
+ throw new EastError(`Failed to get basename: ${err.message}`, {
162
+ location: { filename: "path_basename", line: 0n, column: 0n },
163
+ cause: err
164
+ });
165
+ }
166
+ }),
167
+ path_extname.implement((path) => {
168
+ try {
169
+ return extname(path);
170
+ }
171
+ catch (err) {
172
+ throw new EastError(`Failed to get extname: ${err.message}`, {
173
+ location: { filename: "path_extname", line: 0n, column: 0n },
174
+ cause: err
175
+ });
176
+ }
177
+ }),
178
+ ];
179
+ /**
180
+ * Grouped path manipulation platform functions.
181
+ *
182
+ * Provides path utilities for East programs.
183
+ *
184
+ * @example
185
+ * ```ts
186
+ * import { East, StringType } from "@elaraai/east";
187
+ * import { Path } from "@elaraai/east-node-std";
188
+ *
189
+ * const buildPath = East.function([], StringType, $ => {
190
+ * const segments = East.value(["dir", "subdir", "file.txt"]);
191
+ * const fullPath = $.let(Path.join(segments));
192
+ * const ext = $.let(Path.extname(fullPath));
193
+ * return fullPath;
194
+ * });
195
+ *
196
+ * const compiled = East.compile(buildPath.toIR(), Path.Implementation);
197
+ * await compiled(); // Returns: "dir/subdir/file.txt"
198
+ * ```
199
+ */
200
+ export const Path = {
201
+ /**
202
+ * Joins path segments into a single path.
203
+ *
204
+ * Combines an array of path segments using the platform-specific path separator.
205
+ * Normalizes the resulting path and ignores empty segments.
206
+ *
207
+ * @param segments - Array of path segments to join
208
+ * @returns The joined path with platform-specific separators
209
+ *
210
+ * @example
211
+ * ```ts
212
+ * const buildPath = East.function([], StringType, $ => {
213
+ * const segments = East.value(["home", "user", "file.txt"]);
214
+ * return Path.join(segments);
215
+ * });
216
+ * ```
217
+ */
218
+ join: path_join,
219
+ /**
220
+ * Resolves a path to an absolute path.
221
+ *
222
+ * Converts a relative path to an absolute path by resolving it against the
223
+ * current working directory. Normalizes the path and resolves `.` and `..` segments.
224
+ *
225
+ * @param path - The path to resolve (relative or absolute)
226
+ * @returns The absolute path
227
+ *
228
+ * @example
229
+ * ```ts
230
+ * const getAbsolutePath = East.function([], StringType, $ => {
231
+ * return Path.resolve("../documents/file.txt");
232
+ * });
233
+ * ```
234
+ */
235
+ resolve: path_resolve,
236
+ /**
237
+ * Gets the directory name from a path.
238
+ *
239
+ * Extracts the directory portion of a path by removing the last segment (file name).
240
+ * Trailing path separators are ignored.
241
+ *
242
+ * @param path - The file path to extract directory from
243
+ * @returns The directory portion of the path
244
+ *
245
+ * @example
246
+ * ```ts
247
+ * const getDir = East.function([], StringType, $ => {
248
+ * return Path.dirname("/home/user/documents/file.txt");
249
+ * });
250
+ * ```
251
+ */
252
+ dirname: path_dirname,
253
+ /**
254
+ * Gets the base name (file name) from a path.
255
+ *
256
+ * Extracts the last segment of a path, typically the file name.
257
+ * Trailing path separators are ignored.
258
+ *
259
+ * @param path - The file path to extract filename from
260
+ * @returns The file name portion of the path (including extension)
261
+ *
262
+ * @example
263
+ * ```ts
264
+ * const getFilename = East.function([], StringType, $ => {
265
+ * return Path.basename("/home/user/documents/file.txt");
266
+ * });
267
+ * ```
268
+ */
269
+ basename: path_basename,
270
+ /**
271
+ * Gets the file extension from a path.
272
+ *
273
+ * Extracts the file extension from a path, including the leading dot.
274
+ * Returns empty string if no extension exists.
275
+ *
276
+ * @param path - The file path to extract extension from
277
+ * @returns The file extension including the dot (e.g., ".txt"), or empty string
278
+ *
279
+ * @example
280
+ * ```ts
281
+ * const getExtension = East.function([], StringType, $ => {
282
+ * return Path.extname("file.txt");
283
+ * });
284
+ *
285
+ * const compiled = East.compile(getExtension.toIR(), Path.Implementation);
286
+ * await compiled(); // Returns: ".txt"
287
+ * ```
288
+ */
289
+ extname: path_extname,
290
+ /**
291
+ * Node.js implementation of path platform functions.
292
+ *
293
+ * Pass this to {@link East.compile} to enable path operations.
294
+ */
295
+ Implementation: PathImpl,
296
+ };
297
+ // Export for backwards compatibility
298
+ export { PathImpl };
299
+ //# sourceMappingURL=path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.js","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE5D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,SAAS,GAA8F,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;AAEpL;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,M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AAE,cAAc,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;gBAC5D,KAAK,EAAE,GAAG;aACb,CAAC,CAAC;QACP,CAAC;IACL,CAAC,CAAC;CACL,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG;IAChB;;;;;;;;;;;;;;;;OAgBG;IACH,IAAI,EAAE,SAAS;IAEf;;;;;;;;;;;;;;;OAeG;IACH,OAAO,EAAE,YAAY;IAErB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,EAAE,YAAY;IAErB;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,EAAE,aAAa;IAEvB;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,EAAE,YAAY;IAErB;;;;OAIG;IACH,cAAc,EAAE,QAAQ;CAClB,CAAC;AAEX,qCAAqC;AACrC,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,31 @@
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
+ * Vendored from npm package 'random' (https://github.com/transitive-bullshit/random)
7
+ * Originally by Travis Fischer, distributed under MIT license
8
+ */
9
+ import RNG, { type SeedType } from "./rng.js";
10
+ /**
11
+ * Cryptographically secure RNG using Node.js crypto.randomBytes
12
+ *
13
+ * Note: Seeding is not supported for cryptographic RNG as it uses the OS entropy source.
14
+ * The seed/clone methods are provided for API compatibility but have no effect.
15
+ */
16
+ export default class CryptoRNG extends RNG {
17
+ get name(): string;
18
+ /**
19
+ * Generate a random number in [0, 1) using crypto.randomBytes
20
+ */
21
+ next(): number;
22
+ /**
23
+ * Seeding is not supported for cryptographic RNG (no-op for API compatibility)
24
+ */
25
+ seed(_seed?: SeedType, _opts?: Record<string, unknown>): void;
26
+ /**
27
+ * Clone returns a new instance (seeding not supported)
28
+ */
29
+ clone(_seed?: SeedType, _opts?: Record<string, unknown>): RNG;
30
+ }
31
+ //# sourceMappingURL=crypto-rng.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-rng.d.ts","sourceRoot":"","sources":["../../src/random/crypto-rng.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH;;;GAGG;AAGH,OAAO,GAAG,EAAE,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,GAAG;IACtC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,IAAI,MAAM;IAQd;;OAEG;IACH,IAAI,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI7D;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,GAAG;CAGhE"}