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

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 (115) hide show
  1. package/README.md +38 -0
  2. package/dist/compression/gzip.d.ts +108 -0
  3. package/dist/compression/gzip.d.ts.map +1 -0
  4. package/dist/compression/gzip.js +153 -0
  5. package/dist/compression/gzip.js.map +1 -0
  6. package/dist/compression/index.d.ts +308 -0
  7. package/dist/compression/index.d.ts.map +1 -0
  8. package/dist/compression/index.js +289 -0
  9. package/dist/compression/index.js.map +1 -0
  10. package/dist/compression/tar.d.ts +115 -0
  11. package/dist/compression/tar.d.ts.map +1 -0
  12. package/dist/compression/tar.js +254 -0
  13. package/dist/compression/tar.js.map +1 -0
  14. package/dist/compression/types.d.ts +124 -0
  15. package/dist/compression/types.d.ts.map +1 -0
  16. package/dist/compression/types.js +106 -0
  17. package/dist/compression/types.js.map +1 -0
  18. package/dist/compression/zip.d.ts +121 -0
  19. package/dist/compression/zip.d.ts.map +1 -0
  20. package/dist/compression/zip.js +200 -0
  21. package/dist/compression/zip.js.map +1 -0
  22. package/dist/connection/index.d.ts +78 -0
  23. package/dist/connection/index.d.ts.map +1 -0
  24. package/dist/connection/index.js +134 -0
  25. package/dist/connection/index.js.map +1 -0
  26. package/dist/format/index.d.ts +421 -0
  27. package/dist/format/index.d.ts.map +1 -0
  28. package/dist/format/index.js +326 -0
  29. package/dist/format/index.js.map +1 -0
  30. package/dist/format/types.d.ts +176 -0
  31. package/dist/format/types.d.ts.map +1 -0
  32. package/dist/format/types.js +122 -0
  33. package/dist/format/types.js.map +1 -0
  34. package/dist/format/xlsx.d.ts +178 -0
  35. package/dist/format/xlsx.d.ts.map +1 -0
  36. package/dist/format/xlsx.js +313 -0
  37. package/dist/format/xlsx.js.map +1 -0
  38. package/dist/format/xml.d.ts +302 -0
  39. package/dist/format/xml.d.ts.map +1 -0
  40. package/dist/format/xml.js +602 -0
  41. package/dist/format/xml.js.map +1 -0
  42. package/dist/index.d.ts +25 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +32 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/nosql/index.d.ts +503 -0
  47. package/dist/nosql/index.d.ts.map +1 -0
  48. package/dist/nosql/index.js +483 -0
  49. package/dist/nosql/index.js.map +1 -0
  50. package/dist/nosql/mongodb.d.ts +306 -0
  51. package/dist/nosql/mongodb.d.ts.map +1 -0
  52. package/dist/nosql/mongodb.js +552 -0
  53. package/dist/nosql/mongodb.js.map +1 -0
  54. package/dist/nosql/redis.d.ts +268 -0
  55. package/dist/nosql/redis.d.ts.map +1 -0
  56. package/dist/nosql/redis.js +371 -0
  57. package/dist/nosql/redis.js.map +1 -0
  58. package/dist/nosql/types.d.ts +70 -0
  59. package/dist/nosql/types.d.ts.map +1 -0
  60. package/dist/nosql/types.js +79 -0
  61. package/dist/nosql/types.js.map +1 -0
  62. package/dist/platform.d.ts +12 -0
  63. package/dist/platform.d.ts.map +1 -0
  64. package/dist/platform.js +51 -0
  65. package/dist/platform.js.map +1 -0
  66. package/dist/sql/index.d.ts +777 -0
  67. package/dist/sql/index.d.ts.map +1 -0
  68. package/dist/sql/index.js +515 -0
  69. package/dist/sql/index.js.map +1 -0
  70. package/dist/sql/mysql.d.ts +238 -0
  71. package/dist/sql/mysql.d.ts.map +1 -0
  72. package/dist/sql/mysql.js +396 -0
  73. package/dist/sql/mysql.js.map +1 -0
  74. package/dist/sql/postgres.d.ts +237 -0
  75. package/dist/sql/postgres.d.ts.map +1 -0
  76. package/dist/sql/postgres.js +381 -0
  77. package/dist/sql/postgres.js.map +1 -0
  78. package/dist/sql/sqlite.d.ts +217 -0
  79. package/dist/sql/sqlite.d.ts.map +1 -0
  80. package/dist/sql/sqlite.js +366 -0
  81. package/dist/sql/sqlite.js.map +1 -0
  82. package/dist/sql/types.d.ts +205 -0
  83. package/dist/sql/types.d.ts.map +1 -0
  84. package/dist/sql/types.js +175 -0
  85. package/dist/sql/types.js.map +1 -0
  86. package/dist/storage/index.d.ts +304 -0
  87. package/dist/storage/index.d.ts.map +1 -0
  88. package/dist/storage/index.js +234 -0
  89. package/dist/storage/index.js.map +1 -0
  90. package/dist/storage/s3.d.ts +373 -0
  91. package/dist/storage/s3.d.ts.map +1 -0
  92. package/dist/storage/s3.js +502 -0
  93. package/dist/storage/s3.js.map +1 -0
  94. package/dist/storage/types.d.ts +117 -0
  95. package/dist/storage/types.d.ts.map +1 -0
  96. package/dist/storage/types.js +94 -0
  97. package/dist/storage/types.js.map +1 -0
  98. package/dist/transfer/ftp.d.ts +333 -0
  99. package/dist/transfer/ftp.d.ts.map +1 -0
  100. package/dist/transfer/ftp.js +437 -0
  101. package/dist/transfer/ftp.js.map +1 -0
  102. package/dist/transfer/index.d.ts +456 -0
  103. package/dist/transfer/index.d.ts.map +1 -0
  104. package/dist/transfer/index.js +414 -0
  105. package/dist/transfer/index.js.map +1 -0
  106. package/dist/transfer/sftp.d.ts +333 -0
  107. package/dist/transfer/sftp.d.ts.map +1 -0
  108. package/dist/transfer/sftp.js +436 -0
  109. package/dist/transfer/sftp.js.map +1 -0
  110. package/dist/transfer/types.d.ts +108 -0
  111. package/dist/transfer/types.d.ts.map +1 -0
  112. package/dist/transfer/types.js +110 -0
  113. package/dist/transfer/types.js.map +1 -0
  114. package/dist/tsconfig.tsbuildinfo +1 -0
  115. package/package.json +17 -9
@@ -0,0 +1,124 @@
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
+ * Compression type definitions for East Node IO.
7
+ *
8
+ * Provides East type definitions for compression and decompression operations,
9
+ * supporting gzip, zip, and tar formats.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ import { StructType, OptionType, ArrayType, DictType, StringType, IntegerType, BlobType } from "@elaraai/east";
14
+ /**
15
+ * Compression level for gzip operations (0-9).
16
+ *
17
+ * - 0: No compression
18
+ * - 1-3: Fast compression
19
+ * - 4-6: Balanced (6 is default)
20
+ * - 7-9: Maximum compression
21
+ */
22
+ export declare const GzipLevelType: IntegerType;
23
+ /**
24
+ * Gzip compression options.
25
+ *
26
+ * Controls how data is compressed using gzip.
27
+ */
28
+ export declare const GzipOptionsType: StructType<{
29
+ /**
30
+ * Compression level (0-9).
31
+ * If not specified, defaults to 6.
32
+ */
33
+ level: OptionType<IntegerType>;
34
+ }>;
35
+ /**
36
+ * Compression level for zip operations (0-9).
37
+ *
38
+ * - 0: Store only (no compression)
39
+ * - 1-3: Fast compression
40
+ * - 4-6: Balanced (default is typically 6)
41
+ * - 7-9: Maximum compression
42
+ */
43
+ export declare const ZipLevelType: IntegerType;
44
+ /**
45
+ * Zip compression options.
46
+ *
47
+ * Controls how data is compressed when creating zip archives.
48
+ */
49
+ export declare const ZipOptionsType: StructType<{
50
+ /**
51
+ * Compression level (0-9).
52
+ * If not specified, defaults to 6.
53
+ */
54
+ level: OptionType<IntegerType>;
55
+ }>;
56
+ /**
57
+ * Entry in a ZIP archive.
58
+ *
59
+ * Contains the file name and its uncompressed data.
60
+ */
61
+ export declare const ZipEntryType: StructType<{
62
+ /**
63
+ * Name/path of the file within the archive.
64
+ */
65
+ name: StringType;
66
+ /**
67
+ * Uncompressed file data as bytes.
68
+ */
69
+ data: BlobType;
70
+ }>;
71
+ /**
72
+ * List of entries for creating a ZIP archive.
73
+ */
74
+ export declare const ZipEntriesType: ArrayType<StructType<{
75
+ /**
76
+ * Name/path of the file within the archive.
77
+ */
78
+ name: StringType;
79
+ /**
80
+ * Uncompressed file data as bytes.
81
+ */
82
+ data: BlobType;
83
+ }>>;
84
+ /**
85
+ * Entry in a TAR archive.
86
+ *
87
+ * Contains the file name and its data.
88
+ */
89
+ export declare const TarEntryType: StructType<{
90
+ /**
91
+ * Name/path of the file within the archive.
92
+ */
93
+ name: StringType;
94
+ /**
95
+ * File data as bytes.
96
+ */
97
+ data: BlobType;
98
+ }>;
99
+ /**
100
+ * List of entries for creating a TAR archive.
101
+ */
102
+ export declare const TarEntriesType: ArrayType<StructType<{
103
+ /**
104
+ * Name/path of the file within the archive.
105
+ */
106
+ name: StringType;
107
+ /**
108
+ * File data as bytes.
109
+ */
110
+ data: BlobType;
111
+ }>>;
112
+ /**
113
+ * Extracted files from a ZIP archive as a dictionary.
114
+ *
115
+ * Maps file names to their uncompressed data.
116
+ */
117
+ export declare const ZipExtractedType: DictType<StringType, BlobType>;
118
+ /**
119
+ * Extracted files from a TAR archive as a dictionary.
120
+ *
121
+ * Maps file names to their data.
122
+ */
123
+ export declare const TarExtractedType: DictType<StringType, BlobType>;
124
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/compression/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AAEH,OAAO,EACH,UAAU,EACV,UAAU,EACV,SAAS,EACT,QAAQ,EACR,UAAU,EACV,WAAW,EACX,QAAQ,EACX,MAAM,eAAe,CAAC;AAEvB;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,aAAc,CAAC;AAEzC;;;;GAIG;AACH,eAAO,MAAM,eAAe;IACxB;;;OAGG;;EAEL,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,aAAc,CAAC;AAExC;;;;GAIG;AACH,eAAO,MAAM,cAAc;IACvB;;;OAGG;;EAEL,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,YAAY;IACrB;;OAEG;;IAGH;;OAEG;;EAEL,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,cAAc;IAdvB;;OAEG;;IAGH;;OAEG;;GAO8C,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,YAAY;IACrB;;OAEG;;IAGH;;OAEG;;EAEL,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,cAAc;IAdvB;;OAEG;;IAGH;;OAEG;;GAO8C,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,gCAAiC,CAAC;AAE/D;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,gCAAiC,CAAC"}
@@ -0,0 +1,106 @@
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
+ * Compression type definitions for East Node IO.
7
+ *
8
+ * Provides East type definitions for compression and decompression operations,
9
+ * supporting gzip, zip, and tar formats.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ import { StructType, OptionType, ArrayType, DictType, StringType, IntegerType, BlobType, } from "@elaraai/east";
14
+ /**
15
+ * Compression level for gzip operations (0-9).
16
+ *
17
+ * - 0: No compression
18
+ * - 1-3: Fast compression
19
+ * - 4-6: Balanced (6 is default)
20
+ * - 7-9: Maximum compression
21
+ */
22
+ export const GzipLevelType = IntegerType;
23
+ /**
24
+ * Gzip compression options.
25
+ *
26
+ * Controls how data is compressed using gzip.
27
+ */
28
+ export const GzipOptionsType = StructType({
29
+ /**
30
+ * Compression level (0-9).
31
+ * If not specified, defaults to 6.
32
+ */
33
+ level: OptionType(GzipLevelType),
34
+ });
35
+ /**
36
+ * Compression level for zip operations (0-9).
37
+ *
38
+ * - 0: Store only (no compression)
39
+ * - 1-3: Fast compression
40
+ * - 4-6: Balanced (default is typically 6)
41
+ * - 7-9: Maximum compression
42
+ */
43
+ export const ZipLevelType = IntegerType;
44
+ /**
45
+ * Zip compression options.
46
+ *
47
+ * Controls how data is compressed when creating zip archives.
48
+ */
49
+ export const ZipOptionsType = StructType({
50
+ /**
51
+ * Compression level (0-9).
52
+ * If not specified, defaults to 6.
53
+ */
54
+ level: OptionType(ZipLevelType),
55
+ });
56
+ /**
57
+ * Entry in a ZIP archive.
58
+ *
59
+ * Contains the file name and its uncompressed data.
60
+ */
61
+ export const ZipEntryType = StructType({
62
+ /**
63
+ * Name/path of the file within the archive.
64
+ */
65
+ name: StringType,
66
+ /**
67
+ * Uncompressed file data as bytes.
68
+ */
69
+ data: BlobType,
70
+ });
71
+ /**
72
+ * List of entries for creating a ZIP archive.
73
+ */
74
+ export const ZipEntriesType = ArrayType(ZipEntryType);
75
+ /**
76
+ * Entry in a TAR archive.
77
+ *
78
+ * Contains the file name and its data.
79
+ */
80
+ export const TarEntryType = StructType({
81
+ /**
82
+ * Name/path of the file within the archive.
83
+ */
84
+ name: StringType,
85
+ /**
86
+ * File data as bytes.
87
+ */
88
+ data: BlobType,
89
+ });
90
+ /**
91
+ * List of entries for creating a TAR archive.
92
+ */
93
+ export const TarEntriesType = ArrayType(TarEntryType);
94
+ /**
95
+ * Extracted files from a ZIP archive as a dictionary.
96
+ *
97
+ * Maps file names to their uncompressed data.
98
+ */
99
+ export const ZipExtractedType = DictType(StringType, BlobType);
100
+ /**
101
+ * Extracted files from a TAR archive as a dictionary.
102
+ *
103
+ * Maps file names to their data.
104
+ */
105
+ export const TarExtractedType = DictType(StringType, BlobType);
106
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/compression/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AAEH,OAAO,EACH,UAAU,EACV,UAAU,EACV,SAAS,EACT,QAAQ,EACR,UAAU,EACV,WAAW,EACX,QAAQ,GACX,MAAM,eAAe,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC;AAEzC;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC;IACtC;;;OAGG;IACH,KAAK,EAAE,UAAU,CAAC,aAAa,CAAC;CACnC,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;AAExC;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;IACrC;;;OAGG;IACH,KAAK,EAAE,UAAU,CAAC,YAAY,CAAC;CAClC,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC;IACnC;;OAEG;IACH,IAAI,EAAE,UAAU;IAEhB;;OAEG;IACH,IAAI,EAAE,QAAQ;CACjB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;AAEtD;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC;IACnC;;OAEG;IACH,IAAI,EAAE,UAAU;IAEhB;;OAEG;IACH,IAAI,EAAE,QAAQ;CACjB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;AAEtD;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAE/D;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC"}
@@ -0,0 +1,121 @@
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
+ * ZIP archive platform functions for East Node IO.
7
+ *
8
+ * Provides ZIP archive creation and extraction operations for East programs,
9
+ * enabling file archiving and compression using the ZIP format.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ import { BlobType } from "@elaraai/east";
14
+ import type { PlatformFunction } from "@elaraai/east/internal";
15
+ /**
16
+ * Creates a ZIP archive from a list of files.
17
+ *
18
+ * Compresses multiple files into a single ZIP archive. Each file entry
19
+ * contains a name (path) and its data. The compression level can be
20
+ * controlled via options (0-9, where 0 is store only and 9 is maximum
21
+ * compression).
22
+ *
23
+ * This is a platform function for the East language, enabling ZIP archive
24
+ * creation in East programs running on Node.js.
25
+ *
26
+ * @param entries - List of files to include in the archive
27
+ * @param options - Compression options (level)
28
+ * @returns ZIP archive as compressed blob
29
+ *
30
+ * @throws {EastError} When compression fails due to:
31
+ * - Invalid compression level (location: "zip_compress")
32
+ * - Empty file name (location: "zip_compress")
33
+ * - Memory allocation errors (location: "zip_compress")
34
+ * - Internal compression errors (location: "zip_compress")
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { East, BlobType, StringType, variant } from "@elaraai/east";
39
+ * import { Compression } from "@elaraai/east-node-io";
40
+ *
41
+ * const createZip = East.function([StringType, StringType], BlobType, ($, file1Content, file2Content) => {
42
+ * const entries = $.let([
43
+ * {
44
+ * name: "file1.txt",
45
+ * data: file1Content.encodeUtf8(),
46
+ * },
47
+ * {
48
+ * name: "file2.txt",
49
+ * data: file2Content.encodeUtf8(),
50
+ * },
51
+ * ]);
52
+ * const options = $.let({
53
+ * level: variant('some', 9n),
54
+ * });
55
+ * const zipBlob = $.let(Compression.Zip.compress(entries, options));
56
+ * return $.return(zipBlob);
57
+ * });
58
+ *
59
+ * const compiled = East.compile(createZip.toIR(), Compression.Zip.Implementation);
60
+ * const result = compiled("Hello", "World"); // ZIP archive blob
61
+ * ```
62
+ *
63
+ * @remarks
64
+ * - Uses adm-zip library for ZIP operations
65
+ * - Default compression level is 6 if not specified
66
+ * - Level 0 stores files without compression
67
+ * - Higher levels (7-9) provide better compression but are slower
68
+ * - File names can include directory paths (e.g., "dir/file.txt")
69
+ */
70
+ export declare const zip_compress: import("@elaraai/east").PlatformDefinition<[import("@elaraai/east").ArrayType<import("@elaraai/east").StructType<{
71
+ name: import("@elaraai/east").StringType;
72
+ data: BlobType;
73
+ }>>, import("@elaraai/east").StructType<{
74
+ level: import("@elaraai/east").OptionType<import("@elaraai/east").IntegerType>;
75
+ }>], BlobType>;
76
+ /**
77
+ * Extracts files from a ZIP archive.
78
+ *
79
+ * Decompresses a ZIP archive and extracts all files into a dictionary
80
+ * mapping file names to their uncompressed data.
81
+ *
82
+ * This is a platform function for the East language, enabling ZIP archive
83
+ * extraction in East programs running on Node.js.
84
+ *
85
+ * @param zipData - ZIP archive blob
86
+ * @returns Dictionary mapping file names to their data
87
+ *
88
+ * @throws {EastError} When extraction fails due to:
89
+ * - Invalid ZIP format (location: "zip_decompress")
90
+ * - Corrupted archive (location: "zip_decompress")
91
+ * - Memory allocation errors (location: "zip_decompress")
92
+ * - Internal decompression errors (location: "zip_decompress")
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * import { East, BlobType, DictType, StringType } from "@elaraai/east";
97
+ * import { Compression } from "@elaraai/east-node-io";
98
+ *
99
+ * const extractZip = East.function([BlobType], DictType(StringType, BlobType), ($, zipBlob) => {
100
+ * const files = $.let(Compression.Zip.decompress(zipBlob));
101
+ * return $.return(files);
102
+ * });
103
+ *
104
+ * const compiled = East.compile(extractZip.toIR(), Compression.Zip.Implementation);
105
+ * const result = compiled(zipBlob);
106
+ * // Map { "file1.txt" => Uint8Array, "file2.txt" => Uint8Array }
107
+ * ```
108
+ *
109
+ * @remarks
110
+ * - Uses adm-zip library for ZIP operations
111
+ * - Automatically detects and validates ZIP format
112
+ * - Preserves directory structure in file names
113
+ */
114
+ export declare const zip_decompress: import("@elaraai/east").PlatformDefinition<[BlobType], import("@elaraai/east").DictType<import("@elaraai/east").StringType, BlobType>>;
115
+ /**
116
+ * Node.js implementation of ZIP platform functions.
117
+ *
118
+ * Pass this array to {@link East.compile} to enable ZIP archive operations.
119
+ */
120
+ export declare const ZipImpl: PlatformFunction[];
121
+ //# sourceMappingURL=zip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zip.d.ts","sourceRoot":"","sources":["../../src/compression/zip.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAQ,QAAQ,EAAa,MAAM,eAAe,CAAC;AAE1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAK/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,eAAO,MAAM,YAAY;;;;;cAA4E,CAAC;AAEtG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,cAAc,wIAAgE,CAAC;AAmE5F;;;;GAIG;AACH,eAAO,MAAM,OAAO,EAAE,gBAAgB,EAkCrC,CAAC"}
@@ -0,0 +1,200 @@
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
+ * ZIP archive platform functions for East Node IO.
7
+ *
8
+ * Provides ZIP archive creation and extraction operations for East programs,
9
+ * enabling file archiving and compression using the ZIP format.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ import { East, BlobType, SortedMap } from "@elaraai/east";
14
+ import { EastError } from "@elaraai/east/internal";
15
+ import AdmZip from "adm-zip";
16
+ import { ZipOptionsType, ZipEntriesType, ZipExtractedType } from "./types.js";
17
+ /**
18
+ * Creates a ZIP archive from a list of files.
19
+ *
20
+ * Compresses multiple files into a single ZIP archive. Each file entry
21
+ * contains a name (path) and its data. The compression level can be
22
+ * controlled via options (0-9, where 0 is store only and 9 is maximum
23
+ * compression).
24
+ *
25
+ * This is a platform function for the East language, enabling ZIP archive
26
+ * creation in East programs running on Node.js.
27
+ *
28
+ * @param entries - List of files to include in the archive
29
+ * @param options - Compression options (level)
30
+ * @returns ZIP archive as compressed blob
31
+ *
32
+ * @throws {EastError} When compression fails due to:
33
+ * - Invalid compression level (location: "zip_compress")
34
+ * - Empty file name (location: "zip_compress")
35
+ * - Memory allocation errors (location: "zip_compress")
36
+ * - Internal compression errors (location: "zip_compress")
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { East, BlobType, StringType, variant } from "@elaraai/east";
41
+ * import { Compression } from "@elaraai/east-node-io";
42
+ *
43
+ * const createZip = East.function([StringType, StringType], BlobType, ($, file1Content, file2Content) => {
44
+ * const entries = $.let([
45
+ * {
46
+ * name: "file1.txt",
47
+ * data: file1Content.encodeUtf8(),
48
+ * },
49
+ * {
50
+ * name: "file2.txt",
51
+ * data: file2Content.encodeUtf8(),
52
+ * },
53
+ * ]);
54
+ * const options = $.let({
55
+ * level: variant('some', 9n),
56
+ * });
57
+ * const zipBlob = $.let(Compression.Zip.compress(entries, options));
58
+ * return $.return(zipBlob);
59
+ * });
60
+ *
61
+ * const compiled = East.compile(createZip.toIR(), Compression.Zip.Implementation);
62
+ * const result = compiled("Hello", "World"); // ZIP archive blob
63
+ * ```
64
+ *
65
+ * @remarks
66
+ * - Uses adm-zip library for ZIP operations
67
+ * - Default compression level is 6 if not specified
68
+ * - Level 0 stores files without compression
69
+ * - Higher levels (7-9) provide better compression but are slower
70
+ * - File names can include directory paths (e.g., "dir/file.txt")
71
+ */
72
+ export const zip_compress = East.platform("zip_compress", [ZipEntriesType, ZipOptionsType], BlobType);
73
+ /**
74
+ * Extracts files from a ZIP archive.
75
+ *
76
+ * Decompresses a ZIP archive and extracts all files into a dictionary
77
+ * mapping file names to their uncompressed data.
78
+ *
79
+ * This is a platform function for the East language, enabling ZIP archive
80
+ * extraction in East programs running on Node.js.
81
+ *
82
+ * @param zipData - ZIP archive blob
83
+ * @returns Dictionary mapping file names to their data
84
+ *
85
+ * @throws {EastError} When extraction fails due to:
86
+ * - Invalid ZIP format (location: "zip_decompress")
87
+ * - Corrupted archive (location: "zip_decompress")
88
+ * - Memory allocation errors (location: "zip_decompress")
89
+ * - Internal decompression errors (location: "zip_decompress")
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * import { East, BlobType, DictType, StringType } from "@elaraai/east";
94
+ * import { Compression } from "@elaraai/east-node-io";
95
+ *
96
+ * const extractZip = East.function([BlobType], DictType(StringType, BlobType), ($, zipBlob) => {
97
+ * const files = $.let(Compression.Zip.decompress(zipBlob));
98
+ * return $.return(files);
99
+ * });
100
+ *
101
+ * const compiled = East.compile(extractZip.toIR(), Compression.Zip.Implementation);
102
+ * const result = compiled(zipBlob);
103
+ * // Map { "file1.txt" => Uint8Array, "file2.txt" => Uint8Array }
104
+ * ```
105
+ *
106
+ * @remarks
107
+ * - Uses adm-zip library for ZIP operations
108
+ * - Automatically detects and validates ZIP format
109
+ * - Preserves directory structure in file names
110
+ */
111
+ export const zip_decompress = East.platform("zip_decompress", [BlobType], ZipExtractedType);
112
+ /**
113
+ * Helper function to compress files into a ZIP archive using adm-zip.
114
+ *
115
+ * @param entries - List of file entries
116
+ * @param level - Compression level (0-9)
117
+ * @returns ZIP archive as Uint8Array
118
+ */
119
+ function compressZip(entries, level) {
120
+ // Validate level
121
+ if (level < 0 || level > 9) {
122
+ throw new EastError(`Invalid compression level: ${level}. Must be 0-9.`, {
123
+ location: { filename: "zip_compress", line: 0n, column: 0n }
124
+ });
125
+ }
126
+ const zip = new AdmZip();
127
+ for (const entry of entries) {
128
+ const name = entry.name;
129
+ const data = entry.data;
130
+ if (!name || name.length === 0) {
131
+ throw new EastError("File name cannot be empty", {
132
+ location: { filename: "zip_compress", line: 0n, column: 0n }
133
+ });
134
+ }
135
+ // Add file to ZIP archive
136
+ zip.addFile(name, Buffer.from(data));
137
+ }
138
+ // Generate ZIP buffer with specified compression level
139
+ const buffer = zip.toBuffer();
140
+ return new Uint8Array(buffer);
141
+ }
142
+ /**
143
+ * Helper function to extract files from a ZIP archive using adm-zip.
144
+ *
145
+ * @param zipData - ZIP archive data
146
+ * @returns Map of file names to their data
147
+ */
148
+ function decompressZip(zipData) {
149
+ const files = new SortedMap();
150
+ // Create AdmZip instance from buffer
151
+ const zip = new AdmZip(Buffer.from(zipData));
152
+ // Extract all entries
153
+ const zipEntries = zip.getEntries();
154
+ for (const entry of zipEntries) {
155
+ // Skip directories, only process files
156
+ if (!entry.isDirectory) {
157
+ const data = entry.getData();
158
+ files.set(entry.entryName, new Uint8Array(data));
159
+ }
160
+ }
161
+ return files;
162
+ }
163
+ /**
164
+ * Node.js implementation of ZIP platform functions.
165
+ *
166
+ * Pass this array to {@link East.compile} to enable ZIP archive operations.
167
+ */
168
+ export const ZipImpl = [
169
+ zip_compress.implement((entries, options) => {
170
+ try {
171
+ // Extract compression level (default to 6)
172
+ const level = options.level.type === "some"
173
+ ? Number(options.level.value)
174
+ : 6;
175
+ return compressZip(entries, level);
176
+ }
177
+ catch (err) {
178
+ if (err instanceof EastError)
179
+ throw err;
180
+ throw new EastError(`ZIP compression failed: ${err.message}`, {
181
+ location: { filename: "zip_compress", line: 0n, column: 0n },
182
+ cause: err
183
+ });
184
+ }
185
+ }),
186
+ zip_decompress.implement((zipData) => {
187
+ try {
188
+ return decompressZip(zipData);
189
+ }
190
+ catch (err) {
191
+ if (err instanceof EastError)
192
+ throw err;
193
+ throw new EastError(`ZIP decompression failed: ${err.message}`, {
194
+ location: { filename: "zip_decompress", line: 0n, column: 0n },
195
+ cause: err
196
+ });
197
+ }
198
+ }),
199
+ ];
200
+ //# sourceMappingURL=zip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zip.js","sourceRoot":"","sources":["../../src/compression/zip.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,QAAQ,CAAC,CAAC;AAEtG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,cAAc,CAAC,SAAS,CAAC,CACrB,OAAqC,EACvC,EAAE;QACA,IAAI,CAAC;YACD,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAChB,IAAI,GAAG,YAAY,SAAS;gBAAE,MAAM,GAAG,CAAC;YACxC,MAAM,IAAI,SAAS,CAAC,6BAA6B,GAAG,CAAC,OAAO,EAAE,EAAE;gBAC5D,QAAQ,EAAE,EAAE,QAAQ,EAAE,gBAAgB,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;gBAC9D,KAAK,EAAE,GAAG;aACb,CAAC,CAAC;QACP,CAAC;IACL,CAAC,CAAC;CACL,CAAC"}
@@ -0,0 +1,78 @@
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
+ * Creates an opaque handle for a connection object.
7
+ *
8
+ * Generates a UUID handle and stores the connection in internal storage.
9
+ * The handle can be used to retrieve the connection later.
10
+ *
11
+ * @param connection - The connection object to store
12
+ * @param cleanup - Optional cleanup function to call when closing all handles
13
+ * @returns Opaque handle (UUID string) for the connection
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const pool = new pg.Pool(config);
18
+ * const handle = createHandle(pool, async () => await pool.end());
19
+ * ```
20
+ */
21
+ export declare function createHandle(connection: any, cleanup?: () => Promise<void>): string;
22
+ /**
23
+ * Retrieves a connection object by its handle.
24
+ *
25
+ * Looks up the connection associated with the given handle.
26
+ * Throws an error if the handle is invalid or not found.
27
+ *
28
+ * @typeParam T - The expected type of the connection object
29
+ * @param handle - The opaque handle for the connection
30
+ * @returns The connection object cast to type T
31
+ *
32
+ * @throws {EastError} When handle is invalid or not found (location: "connection_handle")
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * const pool = getConnection<pg.Pool>(handle);
37
+ * const result = await pool.query(sql, params);
38
+ * ```
39
+ */
40
+ export declare function getConnection<T>(handle: string): T;
41
+ /**
42
+ * Closes and removes a connection handle.
43
+ *
44
+ * Removes the connection from internal storage. The connection object
45
+ * itself should be closed by the caller before calling this function.
46
+ *
47
+ * @param handle - The opaque handle to close
48
+ *
49
+ * @throws {EastError} When handle is invalid or not found (location: "connection_close")
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * const pool = getConnection<pg.Pool>(handle);
54
+ * await pool.end();
55
+ * closeHandle(handle);
56
+ * ```
57
+ */
58
+ export declare function closeHandle(handle: string): void;
59
+ /**
60
+ * Gets the current number of active connection handles.
61
+ *
62
+ * Useful for debugging and testing to ensure connections are properly cleaned up.
63
+ *
64
+ * @returns Number of active connection handles
65
+ *
66
+ * @internal
67
+ */
68
+ export declare function getHandleCount(): number;
69
+ /**
70
+ * Closes all active connection handles.
71
+ *
72
+ * Useful for test cleanup to ensure all connections are closed even if tests fail.
73
+ * Calls each connection's registered cleanup function, then clears all handles.
74
+ *
75
+ * @internal
76
+ */
77
+ export declare function closeAllHandles(): Promise<void>;
78
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAsBH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,CAQnF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,CAQlD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAQhD;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAYrD"}