@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,310 @@
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, IntegerType, BooleanType, DictType, OptionType, VariantType, NullType, StructType } from "@elaraai/east";
6
+ import type { PlatformFunction, PlatformFunctionDef } from "@elaraai/east/internal";
7
+ /**
8
+ * HTTP method variant type.
9
+ *
10
+ * Represents the HTTP request method for fetch operations.
11
+ * Supports standard HTTP methods: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS.
12
+ */
13
+ export declare const FetchMethod: VariantType<{
14
+ GET: NullType;
15
+ POST: NullType;
16
+ PUT: NullType;
17
+ DELETE: NullType;
18
+ PATCH: NullType;
19
+ HEAD: NullType;
20
+ OPTIONS: NullType;
21
+ }>;
22
+ /**
23
+ * HTTP request configuration structure.
24
+ *
25
+ * Complete configuration for making HTTP requests with custom methods,
26
+ * headers, and optional body content.
27
+ */
28
+ export declare const FetchRequestConfig: StructType<{
29
+ url: StringType;
30
+ method: VariantType<{
31
+ GET: NullType;
32
+ POST: NullType;
33
+ PUT: NullType;
34
+ DELETE: NullType;
35
+ PATCH: NullType;
36
+ HEAD: NullType;
37
+ OPTIONS: NullType;
38
+ }>;
39
+ headers: DictType<StringType, StringType>;
40
+ body: OptionType<StringType>;
41
+ }>;
42
+ /**
43
+ * HTTP response structure.
44
+ *
45
+ * Complete HTTP response including status code, headers, body, and success indicator.
46
+ * The `ok` field is true for status codes in the 200-299 range.
47
+ */
48
+ export declare const FetchResponse: StructType<{
49
+ status: IntegerType;
50
+ statusText: StringType;
51
+ headers: DictType<StringType, StringType>;
52
+ body: StringType;
53
+ ok: BooleanType;
54
+ }>;
55
+ /**
56
+ * Performs an HTTP GET request and returns the response body as a string.
57
+ *
58
+ * Makes a simple GET request to the specified URL and returns the response body text.
59
+ * This is a convenience function for basic GET requests without custom headers.
60
+ * Throws an error if the response status is not in the 200-299 range.
61
+ *
62
+ * This is a platform function for the East language, enabling HTTP GET requests
63
+ * in East programs running on Node.js.
64
+ *
65
+ * @param url - The URL to fetch (must be a valid HTTP/HTTPS URL)
66
+ * @returns The response body as a string
67
+ *
68
+ * @throws {EastError} When request fails:
69
+ * - Invalid URL
70
+ * - Network error
71
+ * - Non-2xx HTTP status code
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const fetchData = East.function([], StringType, $ => {
76
+ * const data = $.let(Fetch.get("https://api.example.com/data"));
77
+ * return data;
78
+ * });
79
+ * ```
80
+ */
81
+ export declare const fetch_get: PlatformFunctionDef<[typeof StringType], typeof StringType>;
82
+ /**
83
+ * Performs an HTTP POST request with a string body.
84
+ *
85
+ * Makes a POST request to the specified URL with the provided string body.
86
+ * Sets Content-Type header to "text/plain" by default. For more control over
87
+ * headers and methods, use {@link fetch_request}.
88
+ * Throws an error if the response status is not in the 200-299 range.
89
+ *
90
+ * This is a platform function for the East language, enabling HTTP POST requests
91
+ * in East programs running on Node.js.
92
+ *
93
+ * @param url - The URL to post to (must be a valid HTTP/HTTPS URL)
94
+ * @param body - The request body as a string
95
+ * @returns The response body as a string
96
+ *
97
+ * @throws {EastError} When request fails:
98
+ * - Invalid URL
99
+ * - Network error
100
+ * - Non-2xx HTTP status code
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const postData = East.function([], StringType, $ => {
105
+ * const response = $.let(Fetch.post("https://api.example.com/submit", "data"));
106
+ * return response;
107
+ * });
108
+ * ```
109
+ */
110
+ export declare const fetch_post: PlatformFunctionDef<[typeof StringType, typeof StringType], typeof StringType>;
111
+ /**
112
+ * Performs a full HTTP request with custom configuration.
113
+ *
114
+ * Makes an HTTP request with complete control over method, headers, and body.
115
+ * Returns the full response including status, headers, and body. Unlike {@link fetch_get}
116
+ * and {@link fetch_post}, this does not throw on non-2xx status codes - check the `ok`
117
+ * field in the response instead.
118
+ *
119
+ * This is a platform function for the East language, enabling full HTTP requests
120
+ * in East programs running on Node.js.
121
+ *
122
+ * @param config - The request configuration (url, method, headers, optional body)
123
+ * @returns The complete HTTP response with status, headers, and body
124
+ *
125
+ * @throws {EastError} When request fails at the network level (not for HTTP errors)
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * const makeRequest = East.function([], FetchResponse, $ => {
130
+ * const config = East.value({
131
+ * url: "https://api.example.com/data",
132
+ * method: variant("GET", null),
133
+ * headers: new Map([["Authorization", "Bearer token"]]),
134
+ * body: variant("none", null),
135
+ * }, FetchRequestConfig);
136
+ * return Fetch.request(config);
137
+ * });
138
+ * ```
139
+ */
140
+ export declare const fetch_request: PlatformFunctionDef<[typeof FetchRequestConfig], typeof FetchResponse>;
141
+ /**
142
+ * Node.js implementation of fetch platform functions.
143
+ *
144
+ * Pass this array to {@link East.compileAsync} to enable fetch operations.
145
+ */
146
+ declare const FetchImpl: PlatformFunction[];
147
+ /**
148
+ * Grouped fetch platform functions.
149
+ *
150
+ * Provides HTTP client operations using the fetch API.
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * import { East, StringType } from "@elaraai/east";
155
+ * import { Fetch } from "@elaraai/east-node-std";
156
+ *
157
+ * const getData = East.function([], StringType, $ => {
158
+ * const response = $.let(Fetch.get("https://api.example.com/data"));
159
+ * return response;
160
+ * });
161
+ *
162
+ * const compiled = await East.compileAsync(getData.toIR(), Fetch.Implementation);
163
+ * await compiled(); // Returns response body as string
164
+ * ```
165
+ */
166
+ export declare const Fetch: {
167
+ /**
168
+ * Performs an HTTP GET request and returns the response body.
169
+ *
170
+ * Makes a simple GET request to the specified URL and returns the response body text.
171
+ * Throws an error if the response status is not in the 200-299 range.
172
+ *
173
+ * @param url - The URL to fetch
174
+ * @returns The response body as a string
175
+ * @throws {EastError} When request fails or status is not 2xx
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * const fetchData = East.function([], StringType, $ => {
180
+ * return Fetch.get("https://api.example.com/data");
181
+ * });
182
+ *
183
+ * const compiled = await East.compileAsync(fetchData.toIR(), Fetch.Implementation);
184
+ * await compiled(); // Returns: response body as string
185
+ * ```
186
+ */
187
+ readonly get: PlatformFunctionDef<[StringType], StringType>;
188
+ /**
189
+ * Performs an HTTP POST request with a string body.
190
+ *
191
+ * Makes a POST request to the specified URL with the provided string body.
192
+ * Sets Content-Type to "text/plain" by default.
193
+ * Throws an error if the response status is not in the 200-299 range.
194
+ *
195
+ * @param url - The URL to post to
196
+ * @param body - The request body as a string
197
+ * @returns The response body as a string
198
+ * @throws {EastError} When request fails or status is not 2xx
199
+ *
200
+ * @example
201
+ * ```ts
202
+ * const postData = East.function([], StringType, $ => {
203
+ * return Fetch.post("https://api.example.com/submit", "data");
204
+ * });
205
+ *
206
+ * const compiled = await East.compileAsync(postData.toIR(), Fetch.Implementation);
207
+ * await compiled(); // Returns: response body as string
208
+ * ```
209
+ */
210
+ readonly post: PlatformFunctionDef<[StringType, StringType], StringType>;
211
+ /**
212
+ * Performs a full HTTP request with custom configuration.
213
+ *
214
+ * Makes an HTTP request with complete control over method, headers, and body.
215
+ * Returns the full response including status, headers, and body.
216
+ * Does not throw on non-2xx status - check the `ok` field instead.
217
+ *
218
+ * @param config - The request configuration
219
+ * @returns The complete HTTP response
220
+ * @throws {EastError} When request fails at the network level
221
+ *
222
+ * @example
223
+ * ```ts
224
+ * const makeRequest = East.function([], FetchResponse, $ => {
225
+ * const config = East.value({
226
+ * url: "https://api.example.com/data",
227
+ * method: variant("GET", null),
228
+ * headers: new Map(),
229
+ * body: variant("none", null),
230
+ * }, FetchRequestConfig);
231
+ * return Fetch.request(config);
232
+ * });
233
+ *
234
+ * const compiled = await East.compileAsync(makeRequest.toIR(), Fetch.Implementation);
235
+ * const response = await compiled(); // Returns: FetchResponse object
236
+ * ```
237
+ */
238
+ readonly request: PlatformFunctionDef<[StructType<{
239
+ url: StringType;
240
+ method: VariantType<{
241
+ GET: NullType;
242
+ POST: NullType;
243
+ PUT: NullType;
244
+ DELETE: NullType;
245
+ PATCH: NullType;
246
+ HEAD: NullType;
247
+ OPTIONS: NullType;
248
+ }>;
249
+ headers: DictType<StringType, StringType>;
250
+ body: OptionType<StringType>;
251
+ }>], StructType<{
252
+ status: IntegerType;
253
+ statusText: StringType;
254
+ headers: DictType<StringType, StringType>;
255
+ body: StringType;
256
+ ok: BooleanType;
257
+ }>>;
258
+ /**
259
+ * Node.js implementation of fetch platform functions.
260
+ *
261
+ * Pass this to {@link East.compileAsync} to enable fetch operations.
262
+ */
263
+ readonly Implementation: PlatformFunction[];
264
+ /**
265
+ * Type definitions for fetch operations.
266
+ */
267
+ readonly Types: {
268
+ /**
269
+ * HTTP method variant type (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS).
270
+ */
271
+ readonly Method: VariantType<{
272
+ GET: NullType;
273
+ POST: NullType;
274
+ PUT: NullType;
275
+ DELETE: NullType;
276
+ PATCH: NullType;
277
+ HEAD: NullType;
278
+ OPTIONS: NullType;
279
+ }>;
280
+ /**
281
+ * HTTP request configuration structure.
282
+ */
283
+ readonly RequestConfig: StructType<{
284
+ url: StringType;
285
+ method: VariantType<{
286
+ GET: NullType;
287
+ POST: NullType;
288
+ PUT: NullType;
289
+ DELETE: NullType;
290
+ PATCH: NullType;
291
+ HEAD: NullType;
292
+ OPTIONS: NullType;
293
+ }>;
294
+ headers: DictType<StringType, StringType>;
295
+ body: OptionType<StringType>;
296
+ }>;
297
+ /**
298
+ * HTTP response structure.
299
+ */
300
+ readonly Response: StructType<{
301
+ status: IntegerType;
302
+ statusText: StringType;
303
+ headers: DictType<StringType, StringType>;
304
+ body: StringType;
305
+ ok: BooleanType;
306
+ }>;
307
+ };
308
+ };
309
+ export { FetchImpl };
310
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAQ,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAoB,MAAM,eAAe,CAAC;AACtJ,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAGpF;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;;;;;;;EAQtB,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;EAK7B,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;;;;EAMxB,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,SAAS,EAAE,mBAAmB,CAAC,CAAC,OAAO,UAAU,CAAC,EAAE,OAAO,UAAU,CAAwD,CAAC;AAE3I;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,UAAU,EAAE,mBAAmB,CAAC,CAAC,OAAO,UAAU,EAAE,OAAO,UAAU,CAAC,EAAE,OAAO,UAAU,CAAqE,CAAC;AAE5K;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,aAAa,EAAE,mBAAmB,CAAC,CAAC,OAAO,kBAAkB,CAAC,EAAE,OAAO,aAAa,CAAuE,CAAC;AAEzK;;;;GAIG;AACH,QAAA,MAAM,SAAS,EAAE,gBAAgB,EA+EhC,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,KAAK;IACd;;;;;;;;;;;;;;;;;;;OAmBG;;IAGH;;;;;;;;;;;;;;;;;;;;;OAqBG;;IAGH;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;;;;;;;;;;;;;;;;;;;;;IAGH;;;;OAIG;;IAGH;;OAEG;;QAEC;;WAEG;;;;;;;;;;QAGH;;WAEG;;;;;;;;;;;;;;;QAGH;;WAEG;;;;;;;;;CAGD,CAAC;AAGX,OAAO,EAAE,SAAS,EAAE,CAAC"}
package/dist/fetch.js ADDED
@@ -0,0 +1,336 @@
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, IntegerType, BooleanType, DictType, OptionType, VariantType, NullType, StructType } from "@elaraai/east";
6
+ import { EastError } from "@elaraai/east/internal";
7
+ /**
8
+ * HTTP method variant type.
9
+ *
10
+ * Represents the HTTP request method for fetch operations.
11
+ * Supports standard HTTP methods: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS.
12
+ */
13
+ export const FetchMethod = VariantType({
14
+ GET: NullType,
15
+ POST: NullType,
16
+ PUT: NullType,
17
+ DELETE: NullType,
18
+ PATCH: NullType,
19
+ HEAD: NullType,
20
+ OPTIONS: NullType,
21
+ });
22
+ /**
23
+ * HTTP request configuration structure.
24
+ *
25
+ * Complete configuration for making HTTP requests with custom methods,
26
+ * headers, and optional body content.
27
+ */
28
+ export const FetchRequestConfig = StructType({
29
+ url: StringType,
30
+ method: FetchMethod,
31
+ headers: DictType(StringType, StringType),
32
+ body: OptionType(StringType),
33
+ });
34
+ /**
35
+ * HTTP response structure.
36
+ *
37
+ * Complete HTTP response including status code, headers, body, and success indicator.
38
+ * The `ok` field is true for status codes in the 200-299 range.
39
+ */
40
+ export const FetchResponse = StructType({
41
+ status: IntegerType,
42
+ statusText: StringType,
43
+ headers: DictType(StringType, StringType),
44
+ body: StringType,
45
+ ok: BooleanType,
46
+ });
47
+ /**
48
+ * Performs an HTTP GET request and returns the response body as a string.
49
+ *
50
+ * Makes a simple GET request to the specified URL and returns the response body text.
51
+ * This is a convenience function for basic GET requests without custom headers.
52
+ * Throws an error if the response status is not in the 200-299 range.
53
+ *
54
+ * This is a platform function for the East language, enabling HTTP GET requests
55
+ * in East programs running on Node.js.
56
+ *
57
+ * @param url - The URL to fetch (must be a valid HTTP/HTTPS URL)
58
+ * @returns The response body as a string
59
+ *
60
+ * @throws {EastError} When request fails:
61
+ * - Invalid URL
62
+ * - Network error
63
+ * - Non-2xx HTTP status code
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * const fetchData = East.function([], StringType, $ => {
68
+ * const data = $.let(Fetch.get("https://api.example.com/data"));
69
+ * return data;
70
+ * });
71
+ * ```
72
+ */
73
+ export const fetch_get = East.platform("fetch_get", [StringType], StringType);
74
+ /**
75
+ * Performs an HTTP POST request with a string body.
76
+ *
77
+ * Makes a POST request to the specified URL with the provided string body.
78
+ * Sets Content-Type header to "text/plain" by default. For more control over
79
+ * headers and methods, use {@link fetch_request}.
80
+ * Throws an error if the response status is not in the 200-299 range.
81
+ *
82
+ * This is a platform function for the East language, enabling HTTP POST requests
83
+ * in East programs running on Node.js.
84
+ *
85
+ * @param url - The URL to post to (must be a valid HTTP/HTTPS URL)
86
+ * @param body - The request body as a string
87
+ * @returns The response body as a string
88
+ *
89
+ * @throws {EastError} When request fails:
90
+ * - Invalid URL
91
+ * - Network error
92
+ * - Non-2xx HTTP status code
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * const postData = East.function([], StringType, $ => {
97
+ * const response = $.let(Fetch.post("https://api.example.com/submit", "data"));
98
+ * return response;
99
+ * });
100
+ * ```
101
+ */
102
+ export const fetch_post = East.platform("fetch_post", [StringType, StringType], StringType);
103
+ /**
104
+ * Performs a full HTTP request with custom configuration.
105
+ *
106
+ * Makes an HTTP request with complete control over method, headers, and body.
107
+ * Returns the full response including status, headers, and body. Unlike {@link fetch_get}
108
+ * and {@link fetch_post}, this does not throw on non-2xx status codes - check the `ok`
109
+ * field in the response instead.
110
+ *
111
+ * This is a platform function for the East language, enabling full HTTP requests
112
+ * in East programs running on Node.js.
113
+ *
114
+ * @param config - The request configuration (url, method, headers, optional body)
115
+ * @returns The complete HTTP response with status, headers, and body
116
+ *
117
+ * @throws {EastError} When request fails at the network level (not for HTTP errors)
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * const makeRequest = East.function([], FetchResponse, $ => {
122
+ * const config = East.value({
123
+ * url: "https://api.example.com/data",
124
+ * method: variant("GET", null),
125
+ * headers: new Map([["Authorization", "Bearer token"]]),
126
+ * body: variant("none", null),
127
+ * }, FetchRequestConfig);
128
+ * return Fetch.request(config);
129
+ * });
130
+ * ```
131
+ */
132
+ export const fetch_request = East.platform("fetch_request", [FetchRequestConfig], FetchResponse);
133
+ /**
134
+ * Node.js implementation of fetch platform functions.
135
+ *
136
+ * Pass this array to {@link East.compileAsync} to enable fetch operations.
137
+ */
138
+ const FetchImpl = [
139
+ fetch_get.implementAsync(async (url) => {
140
+ try {
141
+ const response = await fetch(url);
142
+ if (!response.ok) {
143
+ throw new EastError(`HTTP ${response.status}: ${response.statusText}`, {
144
+ location: { filename: "fetch_get", line: 0n, column: 0n }
145
+ });
146
+ }
147
+ return await response.text();
148
+ }
149
+ catch (err) {
150
+ if (err instanceof EastError)
151
+ throw err;
152
+ throw new EastError(`Failed to fetch ${url}: ${err.message}`, {
153
+ location: { filename: "fetch_get", line: 0n, column: 0n },
154
+ cause: err
155
+ });
156
+ }
157
+ }),
158
+ fetch_post.implementAsync(async (url, body) => {
159
+ try {
160
+ const response = await fetch(url, {
161
+ method: 'POST',
162
+ body: body,
163
+ headers: {
164
+ 'Content-Type': 'text/plain',
165
+ },
166
+ });
167
+ if (!response.ok) {
168
+ throw new EastError(`HTTP ${response.status}: ${response.statusText}`, {
169
+ location: { filename: "fetch_post", line: 0n, column: 0n }
170
+ });
171
+ }
172
+ return await response.text();
173
+ }
174
+ catch (err) {
175
+ if (err instanceof EastError)
176
+ throw err;
177
+ throw new EastError(`Failed to post to ${url}: ${err.message}`, {
178
+ location: { filename: "fetch_post", line: 0n, column: 0n },
179
+ cause: err
180
+ });
181
+ }
182
+ }),
183
+ fetch_request.implementAsync(async (config) => {
184
+ const url = config.url;
185
+ const method = config.method.type.toUpperCase(); // Get the variant tag
186
+ const headers = {};
187
+ // Convert Map to plain object
188
+ for (const [key, value] of config.headers) {
189
+ headers[key] = value;
190
+ }
191
+ try {
192
+ const response = await fetch(url, {
193
+ method: method,
194
+ headers,
195
+ body: config.body.value,
196
+ });
197
+ const responseHeaders = new Map();
198
+ response.headers.forEach((value, key) => {
199
+ responseHeaders.set(key, value);
200
+ });
201
+ const body = await response.text();
202
+ return {
203
+ status: BigInt(response.status),
204
+ statusText: response.statusText,
205
+ headers: responseHeaders,
206
+ body,
207
+ ok: response.ok,
208
+ };
209
+ }
210
+ catch (err) {
211
+ throw new EastError(`Failed to fetch ${url}: ${err.message}`, {
212
+ location: { filename: "fetch_request", line: 0n, column: 0n },
213
+ cause: err
214
+ });
215
+ }
216
+ }),
217
+ ];
218
+ /**
219
+ * Grouped fetch platform functions.
220
+ *
221
+ * Provides HTTP client operations using the fetch API.
222
+ *
223
+ * @example
224
+ * ```ts
225
+ * import { East, StringType } from "@elaraai/east";
226
+ * import { Fetch } from "@elaraai/east-node-std";
227
+ *
228
+ * const getData = East.function([], StringType, $ => {
229
+ * const response = $.let(Fetch.get("https://api.example.com/data"));
230
+ * return response;
231
+ * });
232
+ *
233
+ * const compiled = await East.compileAsync(getData.toIR(), Fetch.Implementation);
234
+ * await compiled(); // Returns response body as string
235
+ * ```
236
+ */
237
+ export const Fetch = {
238
+ /**
239
+ * Performs an HTTP GET request and returns the response body.
240
+ *
241
+ * Makes a simple GET request to the specified URL and returns the response body text.
242
+ * Throws an error if the response status is not in the 200-299 range.
243
+ *
244
+ * @param url - The URL to fetch
245
+ * @returns The response body as a string
246
+ * @throws {EastError} When request fails or status is not 2xx
247
+ *
248
+ * @example
249
+ * ```ts
250
+ * const fetchData = East.function([], StringType, $ => {
251
+ * return Fetch.get("https://api.example.com/data");
252
+ * });
253
+ *
254
+ * const compiled = await East.compileAsync(fetchData.toIR(), Fetch.Implementation);
255
+ * await compiled(); // Returns: response body as string
256
+ * ```
257
+ */
258
+ get: fetch_get,
259
+ /**
260
+ * Performs an HTTP POST request with a string body.
261
+ *
262
+ * Makes a POST request to the specified URL with the provided string body.
263
+ * Sets Content-Type to "text/plain" by default.
264
+ * Throws an error if the response status is not in the 200-299 range.
265
+ *
266
+ * @param url - The URL to post to
267
+ * @param body - The request body as a string
268
+ * @returns The response body as a string
269
+ * @throws {EastError} When request fails or status is not 2xx
270
+ *
271
+ * @example
272
+ * ```ts
273
+ * const postData = East.function([], StringType, $ => {
274
+ * return Fetch.post("https://api.example.com/submit", "data");
275
+ * });
276
+ *
277
+ * const compiled = await East.compileAsync(postData.toIR(), Fetch.Implementation);
278
+ * await compiled(); // Returns: response body as string
279
+ * ```
280
+ */
281
+ post: fetch_post,
282
+ /**
283
+ * Performs a full HTTP request with custom configuration.
284
+ *
285
+ * Makes an HTTP request with complete control over method, headers, and body.
286
+ * Returns the full response including status, headers, and body.
287
+ * Does not throw on non-2xx status - check the `ok` field instead.
288
+ *
289
+ * @param config - The request configuration
290
+ * @returns The complete HTTP response
291
+ * @throws {EastError} When request fails at the network level
292
+ *
293
+ * @example
294
+ * ```ts
295
+ * const makeRequest = East.function([], FetchResponse, $ => {
296
+ * const config = East.value({
297
+ * url: "https://api.example.com/data",
298
+ * method: variant("GET", null),
299
+ * headers: new Map(),
300
+ * body: variant("none", null),
301
+ * }, FetchRequestConfig);
302
+ * return Fetch.request(config);
303
+ * });
304
+ *
305
+ * const compiled = await East.compileAsync(makeRequest.toIR(), Fetch.Implementation);
306
+ * const response = await compiled(); // Returns: FetchResponse object
307
+ * ```
308
+ */
309
+ request: fetch_request,
310
+ /**
311
+ * Node.js implementation of fetch platform functions.
312
+ *
313
+ * Pass this to {@link East.compileAsync} to enable fetch operations.
314
+ */
315
+ Implementation: FetchImpl,
316
+ /**
317
+ * Type definitions for fetch operations.
318
+ */
319
+ Types: {
320
+ /**
321
+ * HTTP method variant type (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS).
322
+ */
323
+ Method: FetchMethod,
324
+ /**
325
+ * HTTP request configuration structure.
326
+ */
327
+ RequestConfig: FetchRequestConfig,
328
+ /**
329
+ * HTTP response structure.
330
+ */
331
+ Response: FetchResponse,
332
+ },
333
+ };
334
+ // Export for backwards compatibility
335
+ export { FetchImpl };
336
+ //# sourceMappingURL=fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAoB,MAAM,eAAe,CAAC;AAEtJ,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC;IACnC,GAAG,EAAE,QAAQ;IACb,IAAI,EAAE,QAAQ;IACd,GAAG,EAAE,QAAQ;IACb,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,QAAQ;IACf,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,QAAQ;CACpB,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,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