@elaraai/east-node-io 0.0.1-beta.1 → 0.0.1-beta.2

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 (114) hide show
  1. package/dist/compression/gzip.d.ts +108 -0
  2. package/dist/compression/gzip.d.ts.map +1 -0
  3. package/dist/compression/gzip.js +153 -0
  4. package/dist/compression/gzip.js.map +1 -0
  5. package/dist/compression/index.d.ts +308 -0
  6. package/dist/compression/index.d.ts.map +1 -0
  7. package/dist/compression/index.js +289 -0
  8. package/dist/compression/index.js.map +1 -0
  9. package/dist/compression/tar.d.ts +115 -0
  10. package/dist/compression/tar.d.ts.map +1 -0
  11. package/dist/compression/tar.js +254 -0
  12. package/dist/compression/tar.js.map +1 -0
  13. package/dist/compression/types.d.ts +124 -0
  14. package/dist/compression/types.d.ts.map +1 -0
  15. package/dist/compression/types.js +106 -0
  16. package/dist/compression/types.js.map +1 -0
  17. package/dist/compression/zip.d.ts +121 -0
  18. package/dist/compression/zip.d.ts.map +1 -0
  19. package/dist/compression/zip.js +200 -0
  20. package/dist/compression/zip.js.map +1 -0
  21. package/dist/connection/index.d.ts +78 -0
  22. package/dist/connection/index.d.ts.map +1 -0
  23. package/dist/connection/index.js +134 -0
  24. package/dist/connection/index.js.map +1 -0
  25. package/dist/format/csv.d.ts +210 -0
  26. package/dist/format/csv.d.ts.map +1 -0
  27. package/dist/format/csv.js +729 -0
  28. package/dist/format/csv.js.map +1 -0
  29. package/dist/format/index.d.ts +641 -0
  30. package/dist/format/index.d.ts.map +1 -0
  31. package/dist/format/index.js +463 -0
  32. package/dist/format/index.js.map +1 -0
  33. package/dist/format/types.d.ts +176 -0
  34. package/dist/format/types.d.ts.map +1 -0
  35. package/dist/format/types.js +122 -0
  36. package/dist/format/types.js.map +1 -0
  37. package/dist/format/xlsx.d.ts +178 -0
  38. package/dist/format/xlsx.d.ts.map +1 -0
  39. package/dist/format/xlsx.js +313 -0
  40. package/dist/format/xlsx.js.map +1 -0
  41. package/dist/format/xml.d.ts +302 -0
  42. package/dist/format/xml.d.ts.map +1 -0
  43. package/dist/format/xml.js +602 -0
  44. package/dist/format/xml.js.map +1 -0
  45. package/dist/index.d.ts +25 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +32 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/nosql/index.d.ts +503 -0
  50. package/dist/nosql/index.d.ts.map +1 -0
  51. package/dist/nosql/index.js +483 -0
  52. package/dist/nosql/index.js.map +1 -0
  53. package/dist/nosql/mongodb.d.ts +306 -0
  54. package/dist/nosql/mongodb.d.ts.map +1 -0
  55. package/dist/nosql/mongodb.js +552 -0
  56. package/dist/nosql/mongodb.js.map +1 -0
  57. package/dist/nosql/redis.d.ts +268 -0
  58. package/dist/nosql/redis.d.ts.map +1 -0
  59. package/dist/nosql/redis.js +371 -0
  60. package/dist/nosql/redis.js.map +1 -0
  61. package/dist/nosql/types.d.ts +70 -0
  62. package/dist/nosql/types.d.ts.map +1 -0
  63. package/dist/nosql/types.js +79 -0
  64. package/dist/nosql/types.js.map +1 -0
  65. package/dist/sql/index.d.ts +777 -0
  66. package/dist/sql/index.d.ts.map +1 -0
  67. package/dist/sql/index.js +515 -0
  68. package/dist/sql/index.js.map +1 -0
  69. package/dist/sql/mysql.d.ts +238 -0
  70. package/dist/sql/mysql.d.ts.map +1 -0
  71. package/dist/sql/mysql.js +396 -0
  72. package/dist/sql/mysql.js.map +1 -0
  73. package/dist/sql/postgres.d.ts +237 -0
  74. package/dist/sql/postgres.d.ts.map +1 -0
  75. package/dist/sql/postgres.js +381 -0
  76. package/dist/sql/postgres.js.map +1 -0
  77. package/dist/sql/sqlite.d.ts +217 -0
  78. package/dist/sql/sqlite.d.ts.map +1 -0
  79. package/dist/sql/sqlite.js +366 -0
  80. package/dist/sql/sqlite.js.map +1 -0
  81. package/dist/sql/types.d.ts +205 -0
  82. package/dist/sql/types.d.ts.map +1 -0
  83. package/dist/sql/types.js +175 -0
  84. package/dist/sql/types.js.map +1 -0
  85. package/dist/storage/index.d.ts +304 -0
  86. package/dist/storage/index.d.ts.map +1 -0
  87. package/dist/storage/index.js +234 -0
  88. package/dist/storage/index.js.map +1 -0
  89. package/dist/storage/s3.d.ts +373 -0
  90. package/dist/storage/s3.d.ts.map +1 -0
  91. package/dist/storage/s3.js +502 -0
  92. package/dist/storage/s3.js.map +1 -0
  93. package/dist/storage/types.d.ts +117 -0
  94. package/dist/storage/types.d.ts.map +1 -0
  95. package/dist/storage/types.js +94 -0
  96. package/dist/storage/types.js.map +1 -0
  97. package/dist/transfer/ftp.d.ts +333 -0
  98. package/dist/transfer/ftp.d.ts.map +1 -0
  99. package/dist/transfer/ftp.js +437 -0
  100. package/dist/transfer/ftp.js.map +1 -0
  101. package/dist/transfer/index.d.ts +456 -0
  102. package/dist/transfer/index.d.ts.map +1 -0
  103. package/dist/transfer/index.js +414 -0
  104. package/dist/transfer/index.js.map +1 -0
  105. package/dist/transfer/sftp.d.ts +333 -0
  106. package/dist/transfer/sftp.d.ts.map +1 -0
  107. package/dist/transfer/sftp.js +436 -0
  108. package/dist/transfer/sftp.js.map +1 -0
  109. package/dist/transfer/types.d.ts +108 -0
  110. package/dist/transfer/types.d.ts.map +1 -0
  111. package/dist/transfer/types.js +110 -0
  112. package/dist/transfer/types.js.map +1 -0
  113. package/dist/tsconfig.tsbuildinfo +1 -0
  114. package/package.json +6 -6
@@ -0,0 +1,268 @@
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
+ * Redis platform functions for East Node IO.
7
+ *
8
+ * Provides Redis key-value store operations for East programs,
9
+ * including get, set, delete, and expiration operations.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ import { StringType, IntegerType, OptionType, NullType } from "@elaraai/east";
14
+ import type { PlatformFunction } from "@elaraai/east/internal";
15
+ /**
16
+ * Connects to a Redis server.
17
+ *
18
+ * Creates a connection to a Redis server and returns an opaque handle
19
+ * for use in key-value operations.
20
+ *
21
+ * @param config - Redis connection configuration
22
+ * @returns Connection handle (opaque string)
23
+ *
24
+ * @throws {EastError} When connection fails (location: "redis_connect")
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { East, StringType, variant } from "@elaraai/east";
29
+ * import { NoSQL } from "@elaraai/east-node-io";
30
+ *
31
+ * const testConnect = East.function([], StringType, $ => {
32
+ * const config = $.let({
33
+ * host: "localhost",
34
+ * port: 6379n,
35
+ * password: variant('none', null),
36
+ * db: variant('none', null),
37
+ * keyPrefix: variant('none', null),
38
+ * });
39
+ * const conn = $.let(NoSQL.Redis.connect(config));
40
+ * $(NoSQL.Redis.close(conn));
41
+ * return $.return(conn);
42
+ * });
43
+ *
44
+ * const compiled = East.compileAsync(testConnect.toIR(), NoSQL.Redis.Implementation);
45
+ * const handle = await compiled(); // Returns connection handle string
46
+ * ```
47
+ */
48
+ export declare const redis_connect: import("@elaraai/east").AsyncPlatformDefinition<[import("@elaraai/east").StructType<{
49
+ host: StringType;
50
+ port: IntegerType;
51
+ password: OptionType<StringType>;
52
+ db: OptionType<IntegerType>;
53
+ keyPrefix: OptionType<StringType>;
54
+ }>], StringType>;
55
+ /**
56
+ * Gets a value by key from Redis.
57
+ *
58
+ * Retrieves the string value associated with the given key.
59
+ * Returns None if the key doesn't exist.
60
+ *
61
+ * @param handle - Connection handle from redis_connect()
62
+ * @param key - Key to retrieve
63
+ * @returns Option containing the value, or None if key doesn't exist
64
+ *
65
+ * @throws {EastError} When operation fails (location: "redis_get")
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * import { East, StringType, OptionType, variant } from "@elaraai/east";
70
+ * import { NoSQL } from "@elaraai/east-node-io";
71
+ *
72
+ * const getValue = East.function([StringType], OptionType(StringType), ($, key) => {
73
+ * const config = $.let({
74
+ * host: "localhost",
75
+ * port: 6379n,
76
+ * password: variant('none', null),
77
+ * db: variant('none', null),
78
+ * keyPrefix: variant('none', null),
79
+ * });
80
+ * const conn = $.let(NoSQL.Redis.connect(config));
81
+ * const value = $.let(NoSQL.Redis.get(conn, key));
82
+ * $(NoSQL.Redis.close(conn));
83
+ * return $.return(value);
84
+ * });
85
+ *
86
+ * const compiled = East.compileAsync(getValue.toIR(), NoSQL.Redis.Implementation);
87
+ * await compiled("user:42"); // variant('some', "Alice") or variant('none', null)
88
+ * ```
89
+ */
90
+ export declare const redis_get: import("@elaraai/east").AsyncPlatformDefinition<[StringType, StringType], OptionType<StringType>>;
91
+ /**
92
+ * Sets a key-value pair in Redis.
93
+ *
94
+ * Stores a string value associated with the given key.
95
+ * Overwrites existing values.
96
+ *
97
+ * @param handle - Connection handle from redis_connect()
98
+ * @param key - Key to set
99
+ * @param value - Value to store
100
+ * @returns Null on success
101
+ *
102
+ * @throws {EastError} When operation fails (location: "redis_set")
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * import { East, StringType, NullType, variant } from "@elaraai/east";
107
+ * import { NoSQL } from "@elaraai/east-node-io";
108
+ *
109
+ * const setValue = East.function([StringType, StringType], NullType, ($, key, value) => {
110
+ * const config = $.let({
111
+ * host: "localhost",
112
+ * port: 6379n,
113
+ * password: variant('none', null),
114
+ * db: variant('none', null),
115
+ * keyPrefix: variant('none', null),
116
+ * });
117
+ * const conn = $.let(NoSQL.Redis.connect(config));
118
+ * $(NoSQL.Redis.set(conn, key, value));
119
+ * $(NoSQL.Redis.close(conn));
120
+ * return $.return(null);
121
+ * });
122
+ *
123
+ * const compiled = East.compileAsync(setValue.toIR(), NoSQL.Redis.Implementation);
124
+ * await compiled("user:42", "Alice");
125
+ * ```
126
+ */
127
+ export declare const redis_set: import("@elaraai/east").AsyncPlatformDefinition<[StringType, StringType, StringType], NullType>;
128
+ /**
129
+ * Sets a key-value pair with expiration in Redis.
130
+ *
131
+ * Stores a string value with a TTL (time-to-live) in seconds.
132
+ * The key will automatically expire after the specified duration.
133
+ *
134
+ * @param handle - Connection handle from redis_connect()
135
+ * @param key - Key to set
136
+ * @param value - Value to store
137
+ * @param ttl - Time-to-live in seconds
138
+ * @returns Null on success
139
+ *
140
+ * @throws {EastError} When operation fails (location: "redis_setex")
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * import { East, StringType, NullType, variant } from "@elaraai/east";
145
+ * import { NoSQL } from "@elaraai/east-node-io";
146
+ *
147
+ * const setSession = East.function([StringType, StringType], NullType, ($, sessionId, data) => {
148
+ * const config = $.let({
149
+ * host: "localhost",
150
+ * port: 6379n,
151
+ * password: variant('none', null),
152
+ * db: variant('none', null),
153
+ * keyPrefix: variant('none', null),
154
+ * });
155
+ * const conn = $.let(NoSQL.Redis.connect(config));
156
+ * $(NoSQL.Redis.setex(conn, sessionId, data, 3600n)); // 1 hour TTL
157
+ * $(NoSQL.Redis.close(conn));
158
+ * return $.return(null);
159
+ * });
160
+ *
161
+ * const compiled = East.compileAsync(setSession.toIR(), NoSQL.Redis.Implementation);
162
+ * await compiled("session:xyz", "user_data");
163
+ * ```
164
+ */
165
+ export declare const redis_setex: import("@elaraai/east").AsyncPlatformDefinition<[StringType, StringType, StringType, IntegerType], NullType>;
166
+ /**
167
+ * Deletes a key from Redis.
168
+ *
169
+ * Removes the key and its associated value from Redis.
170
+ * Returns the number of keys deleted (0 or 1).
171
+ *
172
+ * @param handle - Connection handle from redis_connect()
173
+ * @param key - Key to delete
174
+ * @returns Number of keys deleted (0 if key didn't exist, 1 if deleted)
175
+ *
176
+ * @throws {EastError} When operation fails (location: "redis_del")
177
+ *
178
+ * @example
179
+ * ```ts
180
+ * import { East, StringType, IntegerType, variant } from "@elaraai/east";
181
+ * import { NoSQL } from "@elaraai/east-node-io";
182
+ *
183
+ * const deleteKey = East.function([StringType], IntegerType, ($, key) => {
184
+ * const config = $.let({
185
+ * host: "localhost",
186
+ * port: 6379n,
187
+ * password: variant('none', null),
188
+ * db: variant('none', null),
189
+ * keyPrefix: variant('none', null),
190
+ * });
191
+ * const conn = $.let(NoSQL.Redis.connect(config));
192
+ * const deleted = $.let(NoSQL.Redis.delete(conn, key));
193
+ * $(NoSQL.Redis.close(conn));
194
+ * return $.return(deleted);
195
+ * });
196
+ *
197
+ * const compiled = East.compileAsync(deleteKey.toIR(), NoSQL.Redis.Implementation);
198
+ * await compiled("user:42"); // 1n (deleted) or 0n (not found)
199
+ * ```
200
+ */
201
+ export declare const redis_del: import("@elaraai/east").AsyncPlatformDefinition<[StringType, StringType], IntegerType>;
202
+ /**
203
+ * Closes a Redis connection.
204
+ *
205
+ * Closes the Redis connection and releases all resources.
206
+ *
207
+ * @param handle - Connection handle from redis_connect()
208
+ * @returns Null on success
209
+ *
210
+ * @throws {EastError} When handle is invalid (location: "redis_close")
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * import { East, NullType, variant } from "@elaraai/east";
215
+ * import { NoSQL } from "@elaraai/east-node-io";
216
+ *
217
+ * const cleanup = East.function([], NullType, $ => {
218
+ * const config = $.let({
219
+ * host: "localhost",
220
+ * port: 6379n,
221
+ * password: variant('none', null),
222
+ * db: variant('none', null),
223
+ * keyPrefix: variant('none', null),
224
+ * });
225
+ * const conn = $.let(NoSQL.Redis.connect(config));
226
+ * // ... do work ...
227
+ * $(NoSQL.Redis.close(conn));
228
+ * return $.return(null);
229
+ * });
230
+ *
231
+ * const compiled = East.compileAsync(cleanup.toIR(), NoSQL.Redis.Implementation);
232
+ * await compiled();
233
+ * ```
234
+ */
235
+ export declare const redis_close: import("@elaraai/east").AsyncPlatformDefinition<[StringType], NullType>;
236
+ /**
237
+ * Closes all Redis connections.
238
+ *
239
+ * Closes all active Redis connections and releases all resources.
240
+ * Useful for test cleanup to ensure all connections are closed.
241
+ *
242
+ * @returns Null on success
243
+ *
244
+ * @example
245
+ * ```ts
246
+ * import { East, NullType } from "@elaraai/east";
247
+ * import { NoSQL } from "@elaraai/east-node-io";
248
+ *
249
+ * const cleanupAll = East.function([], NullType, $ => {
250
+ * // ... test code that may have left connections open ...
251
+ * $(NoSQL.Redis.closeAll());
252
+ * return $.return(null);
253
+ * });
254
+ *
255
+ * const compiled = East.compileAsync(cleanupAll.toIR(), NoSQL.Redis.Implementation);
256
+ * await compiled();
257
+ * ```
258
+ *
259
+ * @internal
260
+ */
261
+ export declare const redis_close_all: import("@elaraai/east").AsyncPlatformDefinition<[], NullType>;
262
+ /**
263
+ * Node.js implementation of Redis platform functions.
264
+ *
265
+ * Pass this to East.compileAsync() to enable Redis operations.
266
+ */
267
+ export declare const RedisImpl: PlatformFunction[];
268
+ //# sourceMappingURL=redis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../src/nosql/redis.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAQ,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAW,MAAM,eAAe,CAAC;AAE7F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAM/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,aAAa;;;;;;gBAA+E,CAAC;AAE1G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,SAAS,mGAA8F,CAAC;AAErH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,SAAS,iGAA4F,CAAC;AAEnH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,WAAW,8GAA2G,CAAC;AAEpI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,SAAS,wFAAmF,CAAC;AAE1G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,WAAW,yEAAsE,CAAC;AAE/F;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,eAAe,+DAAsD,CAAC;AAEnF;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,gBAAgB,EAiIvC,CAAC"}
@@ -0,0 +1,371 @@
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
+ * Redis platform functions for East Node IO.
7
+ *
8
+ * Provides Redis key-value store operations for East programs,
9
+ * including get, set, delete, and expiration operations.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ import { East, StringType, IntegerType, OptionType, NullType, variant } from "@elaraai/east";
14
+ import { EastError } from "@elaraai/east/internal";
15
+ import { Redis } from "ioredis";
16
+ import { createHandle, getConnection, closeHandle, closeAllHandles } from '../connection/index.js';
17
+ import { RedisConfigType, ConnectionHandleType } from "./types.js";
18
+ /**
19
+ * Connects to a Redis server.
20
+ *
21
+ * Creates a connection to a Redis server and returns an opaque handle
22
+ * for use in key-value operations.
23
+ *
24
+ * @param config - Redis connection configuration
25
+ * @returns Connection handle (opaque string)
26
+ *
27
+ * @throws {EastError} When connection fails (location: "redis_connect")
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { East, StringType, variant } from "@elaraai/east";
32
+ * import { NoSQL } from "@elaraai/east-node-io";
33
+ *
34
+ * const testConnect = East.function([], StringType, $ => {
35
+ * const config = $.let({
36
+ * host: "localhost",
37
+ * port: 6379n,
38
+ * password: variant('none', null),
39
+ * db: variant('none', null),
40
+ * keyPrefix: variant('none', null),
41
+ * });
42
+ * const conn = $.let(NoSQL.Redis.connect(config));
43
+ * $(NoSQL.Redis.close(conn));
44
+ * return $.return(conn);
45
+ * });
46
+ *
47
+ * const compiled = East.compileAsync(testConnect.toIR(), NoSQL.Redis.Implementation);
48
+ * const handle = await compiled(); // Returns connection handle string
49
+ * ```
50
+ */
51
+ export const redis_connect = East.asyncPlatform("redis_connect", [RedisConfigType], ConnectionHandleType);
52
+ /**
53
+ * Gets a value by key from Redis.
54
+ *
55
+ * Retrieves the string value associated with the given key.
56
+ * Returns None if the key doesn't exist.
57
+ *
58
+ * @param handle - Connection handle from redis_connect()
59
+ * @param key - Key to retrieve
60
+ * @returns Option containing the value, or None if key doesn't exist
61
+ *
62
+ * @throws {EastError} When operation fails (location: "redis_get")
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * import { East, StringType, OptionType, variant } from "@elaraai/east";
67
+ * import { NoSQL } from "@elaraai/east-node-io";
68
+ *
69
+ * const getValue = East.function([StringType], OptionType(StringType), ($, key) => {
70
+ * const config = $.let({
71
+ * host: "localhost",
72
+ * port: 6379n,
73
+ * password: variant('none', null),
74
+ * db: variant('none', null),
75
+ * keyPrefix: variant('none', null),
76
+ * });
77
+ * const conn = $.let(NoSQL.Redis.connect(config));
78
+ * const value = $.let(NoSQL.Redis.get(conn, key));
79
+ * $(NoSQL.Redis.close(conn));
80
+ * return $.return(value);
81
+ * });
82
+ *
83
+ * const compiled = East.compileAsync(getValue.toIR(), NoSQL.Redis.Implementation);
84
+ * await compiled("user:42"); // variant('some', "Alice") or variant('none', null)
85
+ * ```
86
+ */
87
+ export const redis_get = East.asyncPlatform("redis_get", [ConnectionHandleType, StringType], OptionType(StringType));
88
+ /**
89
+ * Sets a key-value pair in Redis.
90
+ *
91
+ * Stores a string value associated with the given key.
92
+ * Overwrites existing values.
93
+ *
94
+ * @param handle - Connection handle from redis_connect()
95
+ * @param key - Key to set
96
+ * @param value - Value to store
97
+ * @returns Null on success
98
+ *
99
+ * @throws {EastError} When operation fails (location: "redis_set")
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * import { East, StringType, NullType, variant } from "@elaraai/east";
104
+ * import { NoSQL } from "@elaraai/east-node-io";
105
+ *
106
+ * const setValue = East.function([StringType, StringType], NullType, ($, key, value) => {
107
+ * const config = $.let({
108
+ * host: "localhost",
109
+ * port: 6379n,
110
+ * password: variant('none', null),
111
+ * db: variant('none', null),
112
+ * keyPrefix: variant('none', null),
113
+ * });
114
+ * const conn = $.let(NoSQL.Redis.connect(config));
115
+ * $(NoSQL.Redis.set(conn, key, value));
116
+ * $(NoSQL.Redis.close(conn));
117
+ * return $.return(null);
118
+ * });
119
+ *
120
+ * const compiled = East.compileAsync(setValue.toIR(), NoSQL.Redis.Implementation);
121
+ * await compiled("user:42", "Alice");
122
+ * ```
123
+ */
124
+ export const redis_set = East.asyncPlatform("redis_set", [ConnectionHandleType, StringType, StringType], NullType);
125
+ /**
126
+ * Sets a key-value pair with expiration in Redis.
127
+ *
128
+ * Stores a string value with a TTL (time-to-live) in seconds.
129
+ * The key will automatically expire after the specified duration.
130
+ *
131
+ * @param handle - Connection handle from redis_connect()
132
+ * @param key - Key to set
133
+ * @param value - Value to store
134
+ * @param ttl - Time-to-live in seconds
135
+ * @returns Null on success
136
+ *
137
+ * @throws {EastError} When operation fails (location: "redis_setex")
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * import { East, StringType, NullType, variant } from "@elaraai/east";
142
+ * import { NoSQL } from "@elaraai/east-node-io";
143
+ *
144
+ * const setSession = East.function([StringType, StringType], NullType, ($, sessionId, data) => {
145
+ * const config = $.let({
146
+ * host: "localhost",
147
+ * port: 6379n,
148
+ * password: variant('none', null),
149
+ * db: variant('none', null),
150
+ * keyPrefix: variant('none', null),
151
+ * });
152
+ * const conn = $.let(NoSQL.Redis.connect(config));
153
+ * $(NoSQL.Redis.setex(conn, sessionId, data, 3600n)); // 1 hour TTL
154
+ * $(NoSQL.Redis.close(conn));
155
+ * return $.return(null);
156
+ * });
157
+ *
158
+ * const compiled = East.compileAsync(setSession.toIR(), NoSQL.Redis.Implementation);
159
+ * await compiled("session:xyz", "user_data");
160
+ * ```
161
+ */
162
+ export const redis_setex = East.asyncPlatform("redis_setex", [ConnectionHandleType, StringType, StringType, IntegerType], NullType);
163
+ /**
164
+ * Deletes a key from Redis.
165
+ *
166
+ * Removes the key and its associated value from Redis.
167
+ * Returns the number of keys deleted (0 or 1).
168
+ *
169
+ * @param handle - Connection handle from redis_connect()
170
+ * @param key - Key to delete
171
+ * @returns Number of keys deleted (0 if key didn't exist, 1 if deleted)
172
+ *
173
+ * @throws {EastError} When operation fails (location: "redis_del")
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * import { East, StringType, IntegerType, variant } from "@elaraai/east";
178
+ * import { NoSQL } from "@elaraai/east-node-io";
179
+ *
180
+ * const deleteKey = East.function([StringType], IntegerType, ($, key) => {
181
+ * const config = $.let({
182
+ * host: "localhost",
183
+ * port: 6379n,
184
+ * password: variant('none', null),
185
+ * db: variant('none', null),
186
+ * keyPrefix: variant('none', null),
187
+ * });
188
+ * const conn = $.let(NoSQL.Redis.connect(config));
189
+ * const deleted = $.let(NoSQL.Redis.delete(conn, key));
190
+ * $(NoSQL.Redis.close(conn));
191
+ * return $.return(deleted);
192
+ * });
193
+ *
194
+ * const compiled = East.compileAsync(deleteKey.toIR(), NoSQL.Redis.Implementation);
195
+ * await compiled("user:42"); // 1n (deleted) or 0n (not found)
196
+ * ```
197
+ */
198
+ export const redis_del = East.asyncPlatform("redis_del", [ConnectionHandleType, StringType], IntegerType);
199
+ /**
200
+ * Closes a Redis connection.
201
+ *
202
+ * Closes the Redis connection and releases all resources.
203
+ *
204
+ * @param handle - Connection handle from redis_connect()
205
+ * @returns Null on success
206
+ *
207
+ * @throws {EastError} When handle is invalid (location: "redis_close")
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * import { East, NullType, variant } from "@elaraai/east";
212
+ * import { NoSQL } from "@elaraai/east-node-io";
213
+ *
214
+ * const cleanup = East.function([], NullType, $ => {
215
+ * const config = $.let({
216
+ * host: "localhost",
217
+ * port: 6379n,
218
+ * password: variant('none', null),
219
+ * db: variant('none', null),
220
+ * keyPrefix: variant('none', null),
221
+ * });
222
+ * const conn = $.let(NoSQL.Redis.connect(config));
223
+ * // ... do work ...
224
+ * $(NoSQL.Redis.close(conn));
225
+ * return $.return(null);
226
+ * });
227
+ *
228
+ * const compiled = East.compileAsync(cleanup.toIR(), NoSQL.Redis.Implementation);
229
+ * await compiled();
230
+ * ```
231
+ */
232
+ export const redis_close = East.asyncPlatform("redis_close", [ConnectionHandleType], NullType);
233
+ /**
234
+ * Closes all Redis connections.
235
+ *
236
+ * Closes all active Redis connections and releases all resources.
237
+ * Useful for test cleanup to ensure all connections are closed.
238
+ *
239
+ * @returns Null on success
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * import { East, NullType } from "@elaraai/east";
244
+ * import { NoSQL } from "@elaraai/east-node-io";
245
+ *
246
+ * const cleanupAll = East.function([], NullType, $ => {
247
+ * // ... test code that may have left connections open ...
248
+ * $(NoSQL.Redis.closeAll());
249
+ * return $.return(null);
250
+ * });
251
+ *
252
+ * const compiled = East.compileAsync(cleanupAll.toIR(), NoSQL.Redis.Implementation);
253
+ * await compiled();
254
+ * ```
255
+ *
256
+ * @internal
257
+ */
258
+ export const redis_close_all = East.asyncPlatform("redis_close_all", [], NullType);
259
+ /**
260
+ * Node.js implementation of Redis platform functions.
261
+ *
262
+ * Pass this to East.compileAsync() to enable Redis operations.
263
+ */
264
+ export const RedisImpl = [
265
+ redis_connect.implement(async (config) => {
266
+ try {
267
+ const options = {
268
+ host: config.host,
269
+ port: Number(config.port),
270
+ };
271
+ if (config.password?.type === 'some') {
272
+ options.password = config.password.value;
273
+ }
274
+ if (config.db?.type === 'some') {
275
+ options.db = Number(config.db.value);
276
+ }
277
+ if (config.keyPrefix?.type === 'some') {
278
+ options.keyPrefix = config.keyPrefix.value;
279
+ }
280
+ const client = new Redis(options);
281
+ // Wait for connection to be ready
282
+ await new Promise((resolve, reject) => {
283
+ client.on('ready', () => resolve());
284
+ client.on('error', (err) => reject(err));
285
+ });
286
+ return createHandle(client, async () => {
287
+ await client.quit();
288
+ });
289
+ }
290
+ catch (err) {
291
+ throw new EastError(`Redis connection failed: ${err.message}`, {
292
+ location: { filename: "redis_connect", line: 0n, column: 0n },
293
+ cause: err
294
+ });
295
+ }
296
+ }),
297
+ redis_get.implement(async (handle, key) => {
298
+ try {
299
+ const client = getConnection(handle);
300
+ const value = await client.get(key);
301
+ if (value === null) {
302
+ return variant('none', null);
303
+ }
304
+ return variant('some', value);
305
+ }
306
+ catch (err) {
307
+ throw new EastError(`Redis get failed: ${err.message}`, {
308
+ location: { filename: "redis_get", line: 0n, column: 0n },
309
+ cause: err
310
+ });
311
+ }
312
+ }),
313
+ redis_set.implement(async (handle, key, value) => {
314
+ try {
315
+ const client = getConnection(handle);
316
+ await client.set(key, value);
317
+ return null;
318
+ }
319
+ catch (err) {
320
+ throw new EastError(`Redis set failed: ${err.message}`, {
321
+ location: { filename: "redis_set", line: 0n, column: 0n },
322
+ cause: err
323
+ });
324
+ }
325
+ }),
326
+ redis_setex.implement(async (handle, key, value, ttl) => {
327
+ try {
328
+ const client = getConnection(handle);
329
+ await client.setex(key, Number(ttl), value);
330
+ return null;
331
+ }
332
+ catch (err) {
333
+ throw new EastError(`Redis setex failed: ${err.message}`, {
334
+ location: { filename: "redis_setex", line: 0n, column: 0n },
335
+ cause: err
336
+ });
337
+ }
338
+ }),
339
+ redis_del.implement(async (handle, key) => {
340
+ try {
341
+ const client = getConnection(handle);
342
+ const deleted = await client.del(key);
343
+ return BigInt(deleted);
344
+ }
345
+ catch (err) {
346
+ throw new EastError(`Redis del failed: ${err.message}`, {
347
+ location: { filename: "redis_del", line: 0n, column: 0n },
348
+ cause: err
349
+ });
350
+ }
351
+ }),
352
+ redis_close.implement(async (handle) => {
353
+ try {
354
+ const client = getConnection(handle);
355
+ await client.quit();
356
+ closeHandle(handle);
357
+ return null;
358
+ }
359
+ catch (err) {
360
+ throw new EastError(`Redis close failed: ${err.message}`, {
361
+ location: { filename: "redis_close", line: 0n, column: 0n },
362
+ cause: err
363
+ });
364
+ }
365
+ }),
366
+ redis_close_all.implement(async () => {
367
+ await closeAllHandles();
368
+ return null;
369
+ }),
370
+ ];
371
+ //# sourceMappingURL=redis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis.js","sourceRoot":"","sources":["../../src/nosql/redis.ts"],"names":[],"mappings":"AAAA;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