@elaraai/east-node-io 0.0.1-beta.9 → 1.0.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 (180) hide show
  1. package/CLA.md +1 -1
  2. package/CONTRIBUTING.md +3 -3
  3. package/LICENSE.md +31 -0
  4. package/README.md +56 -19
  5. package/dist/{compression → src/compression}/gzip.d.ts +1 -1
  6. package/dist/src/compression/gzip.d.ts.map +1 -0
  7. package/dist/{compression → src/compression}/gzip.js +3 -3
  8. package/dist/src/compression/gzip.js.map +1 -0
  9. package/dist/{compression → src/compression}/index.d.ts +16 -16
  10. package/dist/src/compression/index.d.ts.map +1 -0
  11. package/dist/src/compression/index.js.map +1 -0
  12. package/dist/{compression → src/compression}/tar.d.ts +2 -2
  13. package/dist/src/compression/tar.d.ts.map +1 -0
  14. package/dist/{compression → src/compression}/tar.js +7 -7
  15. package/dist/src/compression/tar.js.map +1 -0
  16. package/dist/{compression → src/compression}/types.d.ts +10 -10
  17. package/dist/src/compression/types.d.ts.map +1 -0
  18. package/dist/src/compression/types.js.map +1 -0
  19. package/dist/{compression → src/compression}/zip.d.ts +3 -3
  20. package/dist/src/compression/zip.d.ts.map +1 -0
  21. package/dist/{compression → src/compression}/zip.js +4 -4
  22. package/dist/src/compression/zip.js.map +1 -0
  23. package/dist/src/connection/index.d.ts.map +1 -0
  24. package/dist/{connection → src/connection}/index.js +2 -2
  25. package/dist/src/connection/index.js.map +1 -0
  26. package/dist/{format → src/format}/index.d.ts +77 -77
  27. package/dist/src/format/index.d.ts.map +1 -0
  28. package/dist/src/format/index.js.map +1 -0
  29. package/dist/{format → src/format}/types.d.ts +53 -53
  30. package/dist/src/format/types.d.ts.map +1 -0
  31. package/dist/src/format/types.js.map +1 -0
  32. package/dist/{format → src/format}/xlsx.d.ts +20 -20
  33. package/dist/src/format/xlsx.d.ts.map +1 -0
  34. package/dist/{format → src/format}/xlsx.js +6 -6
  35. package/dist/src/format/xlsx.js.map +1 -0
  36. package/dist/{format → src/format}/xml.d.ts +54 -54
  37. package/dist/src/format/xml.d.ts.map +1 -0
  38. package/dist/{format → src/format}/xml.js +14 -14
  39. package/dist/src/format/xml.js.map +1 -0
  40. package/dist/src/index.d.ts.map +1 -0
  41. package/dist/src/index.js.map +1 -0
  42. package/dist/{nosql → src/nosql}/index.d.ts +20 -20
  43. package/dist/src/nosql/index.d.ts.map +1 -0
  44. package/dist/src/nosql/index.js.map +1 -0
  45. package/dist/{nosql → src/nosql}/mongodb.d.ts +5 -5
  46. package/dist/src/nosql/mongodb.d.ts.map +1 -0
  47. package/dist/{nosql → src/nosql}/mongodb.js +8 -8
  48. package/dist/src/nosql/mongodb.js.map +1 -0
  49. package/dist/{nosql → src/nosql}/redis.d.ts +5 -5
  50. package/dist/src/nosql/redis.d.ts.map +1 -0
  51. package/dist/{nosql → src/nosql}/redis.js +6 -6
  52. package/dist/src/nosql/redis.js.map +1 -0
  53. package/dist/{nosql → src/nosql}/types.d.ts +10 -10
  54. package/dist/src/nosql/types.d.ts.map +1 -0
  55. package/dist/src/nosql/types.js.map +1 -0
  56. package/dist/src/platform.d.ts.map +1 -0
  57. package/dist/{platform.js → src/platform.js} +2 -0
  58. package/dist/src/platform.js.map +1 -0
  59. package/dist/src/sql/access.d.ts +243 -0
  60. package/dist/src/sql/access.d.ts.map +1 -0
  61. package/dist/src/sql/access.js +427 -0
  62. package/dist/src/sql/access.js.map +1 -0
  63. package/dist/src/sql/index.d.ts +1112 -0
  64. package/dist/src/sql/index.d.ts.map +1 -0
  65. package/dist/{sql → src/sql}/index.js +296 -4
  66. package/dist/src/sql/index.js.map +1 -0
  67. package/dist/{sql → src/sql}/mysql.d.ts +110 -32
  68. package/dist/src/sql/mysql.d.ts.map +1 -0
  69. package/dist/{sql → src/sql}/mysql.js +207 -6
  70. package/dist/src/sql/mysql.js.map +1 -0
  71. package/dist/{sql → src/sql}/postgres.d.ts +110 -32
  72. package/dist/src/sql/postgres.d.ts.map +1 -0
  73. package/dist/{sql → src/sql}/postgres.js +199 -6
  74. package/dist/src/sql/postgres.js.map +1 -0
  75. package/dist/{sql → src/sql}/sqlite.d.ts +108 -30
  76. package/dist/src/sql/sqlite.d.ts.map +1 -0
  77. package/dist/{sql → src/sql}/sqlite.js +209 -6
  78. package/dist/src/sql/sqlite.js.map +1 -0
  79. package/dist/src/sql/types.d.ts +269 -0
  80. package/dist/src/sql/types.d.ts.map +1 -0
  81. package/dist/{sql → src/sql}/types.js +65 -1
  82. package/dist/src/sql/types.js.map +1 -0
  83. package/dist/{storage → src/storage}/index.d.ts +63 -63
  84. package/dist/src/storage/index.d.ts.map +1 -0
  85. package/dist/{storage → src/storage}/index.js +1 -1
  86. package/dist/src/storage/index.js.map +1 -0
  87. package/dist/{storage → src/storage}/s3.d.ts +56 -49
  88. package/dist/src/storage/s3.d.ts.map +1 -0
  89. package/dist/{storage → src/storage}/s3.js +24 -15
  90. package/dist/src/storage/s3.js.map +1 -0
  91. package/dist/{storage → src/storage}/types.d.ts +18 -18
  92. package/dist/src/storage/types.d.ts.map +1 -0
  93. package/dist/src/storage/types.js.map +1 -0
  94. package/dist/{transfer → src/transfer}/ftp.d.ts +10 -10
  95. package/dist/src/transfer/ftp.d.ts.map +1 -0
  96. package/dist/{transfer → src/transfer}/ftp.js +6 -6
  97. package/dist/src/transfer/ftp.js.map +1 -0
  98. package/dist/{transfer → src/transfer}/index.d.ts +40 -40
  99. package/dist/src/transfer/index.d.ts.map +1 -0
  100. package/dist/src/transfer/index.js.map +1 -0
  101. package/dist/{transfer → src/transfer}/sftp.d.ts +10 -10
  102. package/dist/src/transfer/sftp.d.ts.map +1 -0
  103. package/dist/{transfer → src/transfer}/sftp.js +6 -6
  104. package/dist/src/transfer/sftp.js.map +1 -0
  105. package/dist/{transfer → src/transfer}/types.d.ts +15 -15
  106. package/dist/src/transfer/types.d.ts.map +1 -0
  107. package/dist/src/transfer/types.js.map +1 -0
  108. package/package.json +35 -54
  109. package/dist/compression/gzip.d.ts.map +0 -1
  110. package/dist/compression/gzip.js.map +0 -1
  111. package/dist/compression/index.d.ts.map +0 -1
  112. package/dist/compression/index.js.map +0 -1
  113. package/dist/compression/tar.d.ts.map +0 -1
  114. package/dist/compression/tar.js.map +0 -1
  115. package/dist/compression/types.d.ts.map +0 -1
  116. package/dist/compression/types.js.map +0 -1
  117. package/dist/compression/zip.d.ts.map +0 -1
  118. package/dist/compression/zip.js.map +0 -1
  119. package/dist/connection/index.d.ts.map +0 -1
  120. package/dist/connection/index.js.map +0 -1
  121. package/dist/format/index.d.ts.map +0 -1
  122. package/dist/format/index.js.map +0 -1
  123. package/dist/format/types.d.ts.map +0 -1
  124. package/dist/format/types.js.map +0 -1
  125. package/dist/format/xlsx.d.ts.map +0 -1
  126. package/dist/format/xlsx.js.map +0 -1
  127. package/dist/format/xml.d.ts.map +0 -1
  128. package/dist/format/xml.js.map +0 -1
  129. package/dist/index.d.ts.map +0 -1
  130. package/dist/index.js.map +0 -1
  131. package/dist/nosql/index.d.ts.map +0 -1
  132. package/dist/nosql/index.js.map +0 -1
  133. package/dist/nosql/mongodb.d.ts.map +0 -1
  134. package/dist/nosql/mongodb.js.map +0 -1
  135. package/dist/nosql/redis.d.ts.map +0 -1
  136. package/dist/nosql/redis.js.map +0 -1
  137. package/dist/nosql/types.d.ts.map +0 -1
  138. package/dist/nosql/types.js.map +0 -1
  139. package/dist/platform.d.ts.map +0 -1
  140. package/dist/platform.js.map +0 -1
  141. package/dist/sql/index.d.ts +0 -777
  142. package/dist/sql/index.d.ts.map +0 -1
  143. package/dist/sql/index.js.map +0 -1
  144. package/dist/sql/mysql.d.ts.map +0 -1
  145. package/dist/sql/mysql.js.map +0 -1
  146. package/dist/sql/postgres.d.ts.map +0 -1
  147. package/dist/sql/postgres.js.map +0 -1
  148. package/dist/sql/sqlite.d.ts.map +0 -1
  149. package/dist/sql/sqlite.js.map +0 -1
  150. package/dist/sql/types.d.ts +0 -205
  151. package/dist/sql/types.d.ts.map +0 -1
  152. package/dist/sql/types.js.map +0 -1
  153. package/dist/storage/index.d.ts.map +0 -1
  154. package/dist/storage/index.js.map +0 -1
  155. package/dist/storage/s3.d.ts.map +0 -1
  156. package/dist/storage/s3.js.map +0 -1
  157. package/dist/storage/types.d.ts.map +0 -1
  158. package/dist/storage/types.js.map +0 -1
  159. package/dist/transfer/ftp.d.ts.map +0 -1
  160. package/dist/transfer/ftp.js.map +0 -1
  161. package/dist/transfer/index.d.ts.map +0 -1
  162. package/dist/transfer/index.js.map +0 -1
  163. package/dist/transfer/sftp.d.ts.map +0 -1
  164. package/dist/transfer/sftp.js.map +0 -1
  165. package/dist/transfer/types.d.ts.map +0 -1
  166. package/dist/transfer/types.js.map +0 -1
  167. package/dist/tsconfig.tsbuildinfo +0 -1
  168. /package/dist/{compression → src/compression}/index.js +0 -0
  169. /package/dist/{compression → src/compression}/types.js +0 -0
  170. /package/dist/{connection → src/connection}/index.d.ts +0 -0
  171. /package/dist/{format → src/format}/index.js +0 -0
  172. /package/dist/{format → src/format}/types.js +0 -0
  173. /package/dist/{index.d.ts → src/index.d.ts} +0 -0
  174. /package/dist/{index.js → src/index.js} +0 -0
  175. /package/dist/{nosql → src/nosql}/index.js +0 -0
  176. /package/dist/{nosql → src/nosql}/types.js +0 -0
  177. /package/dist/{platform.d.ts → src/platform.d.ts} +0 -0
  178. /package/dist/{storage → src/storage}/types.js +0 -0
  179. /package/dist/{transfer → src/transfer}/index.js +0 -0
  180. /package/dist/{transfer → src/transfer}/types.js +0 -0
@@ -0,0 +1,427 @@
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
+ * Microsoft Access platform functions for East Node IO.
7
+ *
8
+ * Provides read-only Access database operations for East programs, including
9
+ * opening databases, listing tables, and querying table data with user-defined
10
+ * return types.
11
+ *
12
+ * Uses the mdb-reader library which supports Access 97 through Access 2019,
13
+ * including encrypted databases.
14
+ *
15
+ * **Important**: This module is read-only. The mdb-reader library cannot create
16
+ * or modify Access databases.
17
+ *
18
+ * Supported formats:
19
+ * - `.mdb` - Access 97, 2000, 2002/2003
20
+ * - `.accdb` - Access 2007, 2010, 2013, 2016, 2019
21
+ *
22
+ * @packageDocumentation
23
+ */
24
+ import { ArrayType, BlobType, BooleanType, DateTimeType, East, FloatType, IntegerType, isTypeValueEqual, NullType, OptionType, StringType, toEastTypeValue, variant } from "@elaraai/east";
25
+ import { EastError } from "@elaraai/east/internal";
26
+ import MDBReader from 'mdb-reader';
27
+ import { readFileSync } from 'fs';
28
+ import { createHandle, getConnection, closeHandle, closeAllHandles } from '../connection/index.js';
29
+ import { AccessConfigType, AccessQueryOptionsType, AccessTablesResultType, ConnectionHandleType, } from './types.js';
30
+ /**
31
+ * Opens a Microsoft Access database file.
32
+ *
33
+ * Opens an Access database file (.mdb or .accdb) and returns an opaque handle
34
+ * for use in queries. Supports Access 97 through Access 2019, including
35
+ * encrypted databases.
36
+ *
37
+ * This is a platform function for the East language, enabling Access database
38
+ * read operations in East programs running on Node.js.
39
+ *
40
+ * @param config - Access connection configuration
41
+ * @returns Connection handle (opaque string)
42
+ *
43
+ * @throws {EastError} When connection fails due to:
44
+ * - Invalid file path (location: "access_open")
45
+ * - File not found (location: "access_open")
46
+ * - Invalid password for encrypted database (location: "access_open")
47
+ * - Unsupported database format (location: "access_open")
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import { East, NullType, variant } from "@elaraai/east";
52
+ * import { SQL } from "@elaraai/east-node-io";
53
+ *
54
+ * const listTables = East.function([], NullType, ($) => {
55
+ * const config = $.let({
56
+ * path: "./database.mdb",
57
+ * password: variant('none', null),
58
+ * });
59
+ *
60
+ * const conn = $.let(SQL.Access.open(config));
61
+ * const tables = $.let(SQL.Access.tables(conn));
62
+ * $(SQL.Access.close(conn));
63
+ * $.return(null);
64
+ * });
65
+ *
66
+ * const compiled = East.compileAsync(listTables.toIR(), SQL.Access.Implementation);
67
+ * await compiled();
68
+ * ```
69
+ *
70
+ * @remarks
71
+ * - Access databases are read-only (mdb-reader does not support writes)
72
+ * - Supports encrypted databases with password option
73
+ * - Database file is read entirely into memory on open
74
+ */
75
+ export const access_open = East.asyncPlatform("access_open", [AccessConfigType], ConnectionHandleType);
76
+ /**
77
+ * Lists all table names in an Access database.
78
+ *
79
+ * Returns an array of table names available in the database.
80
+ * Only returns normal tables (not system or linked tables).
81
+ *
82
+ * @param handle - Connection handle from access_open()
83
+ * @returns Object containing array of table names
84
+ *
85
+ * @throws {EastError} When operation fails due to:
86
+ * - Invalid connection handle (location: "access_tables")
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * import { East, NullType, variant } from "@elaraai/east";
91
+ * import { SQL } from "@elaraai/east-node-io";
92
+ *
93
+ * const showTables = East.function([], NullType, ($) => {
94
+ * const config = $.let({
95
+ * path: "./database.mdb",
96
+ * password: variant('none', null),
97
+ * });
98
+ *
99
+ * const conn = $.let(SQL.Access.open(config));
100
+ * const result = $.let(SQL.Access.tables(conn));
101
+ * // result.tables contains ['Table1', 'Table2', ...]
102
+ * $(SQL.Access.close(conn));
103
+ * $.return(null);
104
+ * });
105
+ *
106
+ * const compiled = East.compileAsync(showTables.toIR(), SQL.Access.Implementation);
107
+ * await compiled();
108
+ * ```
109
+ */
110
+ export const access_tables = East.asyncPlatform("access_tables", [ConnectionHandleType], AccessTablesResultType);
111
+ /**
112
+ * Queries data from an Access database table with a user-defined return type.
113
+ *
114
+ * Reads rows from a specified table with optional column selection and pagination.
115
+ * The return type is generic, allowing users to specify the expected row structure
116
+ * for type-safe access to query results.
117
+ *
118
+ * This is a generic platform function for the East language, enabling type-safe
119
+ * Access database read operations in East programs running on Node.js.
120
+ *
121
+ * @typeParam T - The expected row type for query results
122
+ * @param handle - Connection handle from access_open()
123
+ * @param options - Query options including table name, columns, offset, and limit
124
+ * @returns Array of rows matching the specified type T
125
+ *
126
+ * @throws {EastError} When query fails due to:
127
+ * - Invalid connection handle (location: "access_query")
128
+ * - Table not found (location: "access_query")
129
+ * - Column not found (location: "access_query")
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * import { East, NullType, StructType, StringType, IntegerType, variant } from "@elaraai/east";
134
+ * import { SQL } from "@elaraai/east-node-io";
135
+ *
136
+ * // Define the expected row type
137
+ * const UserRowType = StructType({
138
+ * id: IntegerType,
139
+ * name: StringType,
140
+ * email: StringType,
141
+ * });
142
+ *
143
+ * const queryUsers = East.function([], NullType, ($) => {
144
+ * const config = $.let({
145
+ * path: "./database.mdb",
146
+ * password: variant('none', null),
147
+ * });
148
+ *
149
+ * const conn = $.let(SQL.Access.open(config));
150
+ * // Query with typed results - returns Array<UserRowType>
151
+ * const users = $.let(SQL.Access.query([UserRowType], conn, {
152
+ * table: "Users",
153
+ * columns: variant('some', ["id", "name", "email"]),
154
+ * rowOffset: variant('none', null),
155
+ * rowLimit: variant('some', 100n),
156
+ * }));
157
+ * // users is typed as Array<{ id: bigint, name: string, email: string }>
158
+ * $(SQL.Access.close(conn));
159
+ * $.return(null);
160
+ * });
161
+ *
162
+ * const compiled = East.compileAsync(queryUsers.toIR(), SQL.Access.Implementation);
163
+ * await compiled();
164
+ * ```
165
+ *
166
+ * @remarks
167
+ * - Table names are case-sensitive
168
+ * - The row type T should match the structure of the queried columns
169
+ * - All Access data types are mapped to appropriate East types
170
+ * - NULL values are preserved in the result
171
+ */
172
+ export const access_query = East.asyncGenericPlatform("access_query", ["T"], [ConnectionHandleType, AccessQueryOptionsType], ArrayType("T"));
173
+ /**
174
+ * Closes an Access database connection.
175
+ *
176
+ * Closes the database connection and releases all resources.
177
+ * The handle becomes invalid after this operation.
178
+ *
179
+ * @param handle - Connection handle from access_open()
180
+ *
181
+ * @throws {EastError} When handle is invalid (location: "access_close")
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * import { East, NullType, variant } from "@elaraai/east";
186
+ * import { SQL } from "@elaraai/east-node-io";
187
+ *
188
+ * const cleanup = East.function([], NullType, $ => {
189
+ * const config = $.let({
190
+ * path: "./database.mdb",
191
+ * password: variant('none', null),
192
+ * });
193
+ * const conn = $.let(SQL.Access.open(config));
194
+ * // ... do work ...
195
+ * $(SQL.Access.close(conn));
196
+ * return $.return(null);
197
+ * });
198
+ *
199
+ * const compiled = East.compileAsync(cleanup.toIR(), SQL.Access.Implementation);
200
+ * await compiled();
201
+ * ```
202
+ */
203
+ export const access_close = East.asyncPlatform("access_close", [ConnectionHandleType], NullType);
204
+ /**
205
+ * Closes all Access database connections.
206
+ *
207
+ * Closes all active Access connections and releases all resources.
208
+ * Useful for test cleanup to ensure all connections are closed.
209
+ *
210
+ * @returns Null on success
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * import { East, NullType } from "@elaraai/east";
215
+ * import { SQL } from "@elaraai/east-node-io";
216
+ *
217
+ * const cleanupAll = East.function([], NullType, $ => {
218
+ * // ... test code that may have left connections open ...
219
+ * $(SQL.Access.closeAll());
220
+ * return $.return(null);
221
+ * });
222
+ *
223
+ * const compiled = East.compileAsync(cleanupAll.toIR(), SQL.Access.Implementation);
224
+ * await compiled();
225
+ * ```
226
+ *
227
+ * @internal
228
+ */
229
+ export const access_close_all = East.asyncPlatform("access_close_all", [], NullType);
230
+ /**
231
+ * Node.js implementation of Access platform functions.
232
+ *
233
+ * Provides the runtime implementations for Access database operations.
234
+ * Pass this to East.compileAsync() to enable Access functionality.
235
+ */
236
+ export const AccessImpl = [
237
+ access_open.implement(async (config) => {
238
+ try {
239
+ const path = config.path;
240
+ const password = config.password?.type === 'some' ? config.password.value : undefined;
241
+ // Read the database file into a buffer
242
+ const buffer = readFileSync(path);
243
+ // Create the MDB reader with optional password
244
+ const readerOptions = password ? { password } : undefined;
245
+ const reader = new MDBReader(buffer, readerOptions);
246
+ return await Promise.resolve(createHandle(reader, async () => {
247
+ // mdb-reader doesn't have a close method, but we clean up the handle
248
+ await Promise.resolve();
249
+ }));
250
+ }
251
+ catch (err) {
252
+ throw new EastError(`Access database open failed: ${err.message}`, {
253
+ location: [{ filename: "access_open", line: 0n, column: 0n }],
254
+ cause: err
255
+ });
256
+ }
257
+ }),
258
+ access_tables.implement(async (handle) => {
259
+ try {
260
+ const reader = await Promise.resolve(getConnection(handle));
261
+ // Get only normal tables (not system or linked tables)
262
+ const tables = reader.getTableNames({
263
+ normalTables: true,
264
+ systemTables: false,
265
+ linkedTables: false
266
+ });
267
+ return { tables };
268
+ }
269
+ catch (err) {
270
+ throw new EastError(`Access tables list failed: ${err.message}`, {
271
+ location: [{ filename: "access_tables", line: 0n, column: 0n }],
272
+ cause: err
273
+ });
274
+ }
275
+ }),
276
+ access_query.implement((T) => async (...args) => {
277
+ const handle = args[0];
278
+ const options = args[1];
279
+ const rowType = T;
280
+ try {
281
+ const reader = await Promise.resolve(getConnection(handle));
282
+ const tableName = options.table;
283
+ const columns = options.columns?.type === 'some' ? options.columns.value : undefined;
284
+ const rowOffset = options.rowOffset?.type === 'some' ? Number(options.rowOffset.value) : undefined;
285
+ const rowLimit = options.rowLimit?.type === 'some' ? Number(options.rowLimit.value) : undefined;
286
+ // Get the table
287
+ const table = reader.getTable(tableName);
288
+ // Get column metadata for type validation and conversion
289
+ const columnDefs = table.getColumns();
290
+ const columnMetaMap = new Map();
291
+ for (const col of columnDefs) {
292
+ columnMetaMap.set(col.name, { type: col.type, nullable: col.nullable });
293
+ }
294
+ // Validate that the expected row type matches the Access column metadata
295
+ if (rowType.type !== 'Struct') {
296
+ throw new EastError(`Expected row type must be a Struct, got ${rowType.type}`, { location: [{ filename: "access_query", line: 0n, column: 0n }] });
297
+ }
298
+ // Note: T is EastTypeValue (IR format), not EastType (runtime format)
299
+ const structTypeValue = rowType;
300
+ for (const field of structTypeValue.value) {
301
+ const fieldName = field.name;
302
+ const fieldType = field.type;
303
+ const colMeta = columnMetaMap.get(fieldName);
304
+ if (!colMeta) {
305
+ throw new EastError(`Column '${fieldName}' not found in table '${tableName}'`, { location: [{ filename: "access_query", line: 0n, column: 0n }] });
306
+ }
307
+ // Determine expected East type based on Access column type
308
+ let expectedBaseType;
309
+ switch (colMeta.type) {
310
+ case 'boolean':
311
+ expectedBaseType = BooleanType;
312
+ break;
313
+ case 'byte':
314
+ case 'integer':
315
+ case 'long':
316
+ case 'bigint':
317
+ expectedBaseType = IntegerType;
318
+ break;
319
+ case 'float':
320
+ case 'double':
321
+ expectedBaseType = FloatType;
322
+ break;
323
+ case 'text':
324
+ case 'memo':
325
+ case 'currency':
326
+ case 'numeric':
327
+ case 'repid':
328
+ case 'datetimeextended':
329
+ expectedBaseType = StringType;
330
+ break;
331
+ case 'datetime':
332
+ expectedBaseType = DateTimeType;
333
+ break;
334
+ case 'binary':
335
+ case 'ole':
336
+ expectedBaseType = BlobType;
337
+ break;
338
+ default:
339
+ throw new EastError(`Unsupported Access column type '${colMeta.type}' for column '${fieldName}'`, { location: [{ filename: "access_query", line: 0n, column: 0n }] });
340
+ }
341
+ // Check type matches, accounting for nullable columns
342
+ const expectedType = colMeta.nullable ? OptionType(expectedBaseType) : expectedBaseType;
343
+ if (!isTypeValueEqual(fieldType, toEastTypeValue(expectedType))) {
344
+ const expectedTypeName = colMeta.nullable
345
+ ? `OptionType(${expectedBaseType.type})`
346
+ : expectedBaseType.type;
347
+ throw new EastError(`Type mismatch for column '${fieldName}': Access column is ${colMeta.type}${colMeta.nullable ? ' (nullable)' : ''}, got ${fieldType.type} but expected East type ${expectedTypeName}`, { location: [{ filename: "access_query", line: 0n, column: 0n }] });
348
+ }
349
+ }
350
+ // Get data with options
351
+ const dataOptions = {};
352
+ if (columns)
353
+ dataOptions.columns = columns;
354
+ if (rowOffset !== undefined)
355
+ dataOptions.rowOffset = rowOffset;
356
+ if (rowLimit !== undefined)
357
+ dataOptions.rowLimit = rowLimit;
358
+ const rawData = table.getData(dataOptions);
359
+ // Convert mdb-reader types to East types based on column metadata
360
+ // mdb-reader returns: integer/long/byte → number, binary/ole → Buffer
361
+ // East expects: IntegerType → bigint, BlobType → Uint8Array
362
+ const data = rawData.map((row) => {
363
+ const converted = {};
364
+ for (const [key, value] of Object.entries(row)) {
365
+ const colMeta = columnMetaMap.get(key);
366
+ if (value === null) {
367
+ // For nullable columns, wrap null in the 'none' variant
368
+ converted[key] = colMeta?.nullable ? variant('none', null) : null;
369
+ }
370
+ else {
371
+ let convertedValue;
372
+ switch (colMeta?.type) {
373
+ case 'integer':
374
+ case 'long':
375
+ case 'byte':
376
+ // Convert number to bigint for East IntegerType
377
+ convertedValue = BigInt(value);
378
+ break;
379
+ case 'binary':
380
+ case 'ole':
381
+ // Convert Buffer to Uint8Array for East BlobType
382
+ convertedValue = new Uint8Array(value);
383
+ break;
384
+ default:
385
+ // datetime → Date, boolean → boolean, float/double → number,
386
+ // text/memo → string, bigint → bigint (already correct)
387
+ convertedValue = value;
388
+ }
389
+ // For nullable columns, wrap value in the 'some' variant
390
+ converted[key] = colMeta?.nullable ? variant('some', convertedValue) : convertedValue;
391
+ }
392
+ }
393
+ return converted;
394
+ });
395
+ // Type validation is already done field-by-field above during column metadata validation
396
+ return data;
397
+ }
398
+ catch (err) {
399
+ if (err instanceof EastError) {
400
+ throw err;
401
+ }
402
+ throw new EastError(`Access query failed: ${err.message}`, {
403
+ location: [{ filename: "access_query", line: 0n, column: 0n }],
404
+ cause: err
405
+ });
406
+ }
407
+ }),
408
+ access_close.implement(async (handle) => {
409
+ try {
410
+ // Verify handle exists (mdb-reader doesn't need explicit close)
411
+ await Promise.resolve(getConnection(handle));
412
+ closeHandle(handle);
413
+ return null;
414
+ }
415
+ catch (err) {
416
+ throw new EastError(`Access close failed: ${err.message}`, {
417
+ location: [{ filename: "access_close", line: 0n, column: 0n }],
418
+ cause: err
419
+ });
420
+ }
421
+ }),
422
+ access_close_all.implement(async () => {
423
+ await closeAllHandles();
424
+ return null;
425
+ }),
426
+ ];
427
+ //# sourceMappingURL=access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.js","sourceRoot":"","sources":["../../../src/sql/access.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;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