@elaraai/e3-core 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 (55) hide show
  1. package/LICENSE.md +50 -0
  2. package/README.md +76 -0
  3. package/dist/src/dataflow.d.ts +96 -0
  4. package/dist/src/dataflow.d.ts.map +1 -0
  5. package/dist/src/dataflow.js +433 -0
  6. package/dist/src/dataflow.js.map +1 -0
  7. package/dist/src/errors.d.ts +87 -0
  8. package/dist/src/errors.d.ts.map +1 -0
  9. package/dist/src/errors.js +178 -0
  10. package/dist/src/errors.js.map +1 -0
  11. package/dist/src/executions.d.ts +163 -0
  12. package/dist/src/executions.d.ts.map +1 -0
  13. package/dist/src/executions.js +535 -0
  14. package/dist/src/executions.js.map +1 -0
  15. package/dist/src/formats.d.ts +38 -0
  16. package/dist/src/formats.d.ts.map +1 -0
  17. package/dist/src/formats.js +115 -0
  18. package/dist/src/formats.js.map +1 -0
  19. package/dist/src/gc.d.ts +54 -0
  20. package/dist/src/gc.d.ts.map +1 -0
  21. package/dist/src/gc.js +232 -0
  22. package/dist/src/gc.js.map +1 -0
  23. package/dist/src/index.d.ts +23 -0
  24. package/dist/src/index.d.ts.map +1 -0
  25. package/dist/src/index.js +68 -0
  26. package/dist/src/index.js.map +1 -0
  27. package/dist/src/objects.d.ts +62 -0
  28. package/dist/src/objects.d.ts.map +1 -0
  29. package/dist/src/objects.js +245 -0
  30. package/dist/src/objects.js.map +1 -0
  31. package/dist/src/packages.d.ts +85 -0
  32. package/dist/src/packages.d.ts.map +1 -0
  33. package/dist/src/packages.js +355 -0
  34. package/dist/src/packages.js.map +1 -0
  35. package/dist/src/repository.d.ts +38 -0
  36. package/dist/src/repository.d.ts.map +1 -0
  37. package/dist/src/repository.js +103 -0
  38. package/dist/src/repository.js.map +1 -0
  39. package/dist/src/tasks.d.ts +63 -0
  40. package/dist/src/tasks.d.ts.map +1 -0
  41. package/dist/src/tasks.js +145 -0
  42. package/dist/src/tasks.js.map +1 -0
  43. package/dist/src/test-helpers.d.ts +44 -0
  44. package/dist/src/test-helpers.d.ts.map +1 -0
  45. package/dist/src/test-helpers.js +141 -0
  46. package/dist/src/test-helpers.js.map +1 -0
  47. package/dist/src/trees.d.ts +156 -0
  48. package/dist/src/trees.d.ts.map +1 -0
  49. package/dist/src/trees.js +607 -0
  50. package/dist/src/trees.js.map +1 -0
  51. package/dist/src/workspaces.d.ts +116 -0
  52. package/dist/src/workspaces.d.ts.map +1 -0
  53. package/dist/src/workspaces.js +356 -0
  54. package/dist/src/workspaces.js.map +1 -0
  55. package/package.json +50 -0
@@ -0,0 +1,245 @@
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 * as fs from 'fs/promises';
6
+ import * as path from 'path';
7
+ import * as crypto from 'crypto';
8
+ import { Readable } from 'stream';
9
+ import { pipeline } from 'stream/promises';
10
+ import { createWriteStream } from 'fs';
11
+ import { ObjectNotFoundError, isNotFoundError } from './errors.js';
12
+ /**
13
+ * Calculate SHA256 hash of data
14
+ */
15
+ export function computeHash(data) {
16
+ return crypto.createHash('sha256').update(data).digest('hex');
17
+ }
18
+ /**
19
+ * Calculate SHA256 hash of a stream
20
+ * @internal
21
+ */
22
+ async function computeHashFromStream(stream) {
23
+ const hash = crypto.createHash('sha256');
24
+ const chunks = [];
25
+ const reader = stream.getReader();
26
+ while (true) {
27
+ const { done, value } = await reader.read();
28
+ if (done)
29
+ break;
30
+ hash.update(value);
31
+ chunks.push(value);
32
+ }
33
+ return {
34
+ hash: hash.digest('hex'),
35
+ data: chunks,
36
+ };
37
+ }
38
+ /**
39
+ * Atomically write an object to the repository
40
+ *
41
+ * @param repoPath - Path to .e3 repository
42
+ * @param data - Data to store
43
+ * @returns SHA256 hash of the data
44
+ */
45
+ export async function objectWrite(repoPath, data) {
46
+ const extension = '.beast2';
47
+ const hash = computeHash(data);
48
+ // Split hash: first 2 chars as directory
49
+ const dirName = hash.slice(0, 2);
50
+ const fileName = hash.slice(2) + extension;
51
+ const dirPath = path.join(repoPath, 'objects', dirName);
52
+ const filePath = path.join(dirPath, fileName);
53
+ // Check if already exists
54
+ try {
55
+ await fs.access(filePath);
56
+ return hash; // Already exists
57
+ }
58
+ catch {
59
+ // Doesn't exist, continue
60
+ }
61
+ // Create directory if needed
62
+ await fs.mkdir(dirPath, { recursive: true });
63
+ // Write atomically: stage in same directory (same filesystem) + rename
64
+ // Staging files use .partial extension; gc can clean up any orphaned ones
65
+ // Use random suffix to avoid collisions with concurrent writes
66
+ const randomSuffix = Math.random().toString(36).slice(2, 10);
67
+ const stagingPath = path.join(dirPath, `${fileName}.${Date.now()}.${randomSuffix}.partial`);
68
+ await fs.writeFile(stagingPath, data);
69
+ try {
70
+ await fs.rename(stagingPath, filePath);
71
+ }
72
+ catch (err) {
73
+ // If rename fails because target exists (concurrent write won), that's fine
74
+ // Clean up our staging file
75
+ try {
76
+ await fs.unlink(stagingPath);
77
+ }
78
+ catch {
79
+ // Ignore cleanup errors
80
+ }
81
+ // Verify the file exists (another writer should have created it)
82
+ try {
83
+ await fs.access(filePath);
84
+ }
85
+ catch {
86
+ // File doesn't exist and rename failed - re-throw original error
87
+ throw err;
88
+ }
89
+ }
90
+ return hash;
91
+ }
92
+ /**
93
+ * Atomically write a stream to the repository
94
+ *
95
+ * @param repoPath - Path to .e3 repository
96
+ * @param stream - Stream to store
97
+ * @returns SHA256 hash of the data
98
+ */
99
+ export async function objectWriteStream(repoPath, stream) {
100
+ const extension = '.beast2';
101
+ // First pass: compute hash while collecting data
102
+ const { hash, data } = await computeHashFromStream(stream);
103
+ // Split hash: first 2 chars as directory
104
+ const dirName = hash.slice(0, 2);
105
+ const fileName = hash.slice(2) + extension;
106
+ const dirPath = path.join(repoPath, 'objects', dirName);
107
+ const filePath = path.join(dirPath, fileName);
108
+ // Check if already exists
109
+ try {
110
+ await fs.access(filePath);
111
+ return hash; // Already exists
112
+ }
113
+ catch {
114
+ // Doesn't exist, continue
115
+ }
116
+ // Create directory if needed
117
+ await fs.mkdir(dirPath, { recursive: true });
118
+ // Write atomically: stage in same directory (same filesystem) + rename
119
+ // Staging files use .partial extension; gc can clean up any orphaned ones
120
+ // Use random suffix to avoid collisions with concurrent writes
121
+ const randomSuffix = Math.random().toString(36).slice(2, 10);
122
+ const stagingPath = path.join(dirPath, `${fileName}.${Date.now()}.${randomSuffix}.partial`);
123
+ // Reconstruct stream from collected chunks
124
+ const nodeStream = Readable.from(data);
125
+ const writeStream = createWriteStream(stagingPath);
126
+ await pipeline(nodeStream, writeStream);
127
+ try {
128
+ await fs.rename(stagingPath, filePath);
129
+ }
130
+ catch (err) {
131
+ // If rename fails because target exists (concurrent write won), that's fine
132
+ // Clean up our staging file
133
+ try {
134
+ await fs.unlink(stagingPath);
135
+ }
136
+ catch {
137
+ // Ignore cleanup errors
138
+ }
139
+ // Verify the file exists (another writer should have created it)
140
+ try {
141
+ await fs.access(filePath);
142
+ }
143
+ catch {
144
+ // File doesn't exist and rename failed - re-throw original error
145
+ throw err;
146
+ }
147
+ }
148
+ return hash;
149
+ }
150
+ /**
151
+ * Read an object from the repository
152
+ *
153
+ * @param repoPath - Path to .e3 repository
154
+ * @param hash - SHA256 hash of the object
155
+ * @returns Object data
156
+ * @throws {ObjectNotFoundError} If object not found
157
+ */
158
+ export async function objectRead(repoPath, hash) {
159
+ const extension = '.beast2';
160
+ const dirName = hash.slice(0, 2);
161
+ const fileName = hash.slice(2) + extension;
162
+ const filePath = path.join(repoPath, 'objects', dirName, fileName);
163
+ try {
164
+ return await fs.readFile(filePath);
165
+ }
166
+ catch (err) {
167
+ if (isNotFoundError(err)) {
168
+ throw new ObjectNotFoundError(hash);
169
+ }
170
+ throw err;
171
+ }
172
+ }
173
+ /**
174
+ * Check if an object exists in the repository
175
+ *
176
+ * @param repoPath - Path to .e3 repository
177
+ * @param hash - SHA256 hash of the object
178
+ * @returns true if object exists
179
+ */
180
+ export async function objectExists(repoPath, hash) {
181
+ const filePath = objectPath(repoPath, hash);
182
+ try {
183
+ await fs.access(filePath);
184
+ return true;
185
+ }
186
+ catch {
187
+ return false;
188
+ }
189
+ }
190
+ /**
191
+ * Get the filesystem path for an object
192
+ *
193
+ * @param repoPath - Path to .e3 repository
194
+ * @param hash - SHA256 hash of the object
195
+ * @returns Filesystem path: objects/<hash[0..2]>/<hash[2..]>.beast2
196
+ */
197
+ export function objectPath(repoPath, hash) {
198
+ const dirName = hash.slice(0, 2);
199
+ const fileName = hash.slice(2) + '.beast2';
200
+ return path.join(repoPath, 'objects', dirName, fileName);
201
+ }
202
+ /**
203
+ * Get the minimum unambiguous prefix length for an object hash.
204
+ *
205
+ * Scans the object store to find the shortest prefix of the given hash
206
+ * that uniquely identifies it among all stored objects.
207
+ *
208
+ * @param repoPath - Path to .e3 repository
209
+ * @param hash - Full SHA256 hash of the object
210
+ * @param minLength - Minimum prefix length to return (default: 4)
211
+ * @returns Minimum unambiguous prefix length
212
+ */
213
+ export async function objectAbbrev(repoPath, hash, minLength = 4) {
214
+ const objectsDir = path.join(repoPath, 'objects');
215
+ const targetPrefix = hash.slice(0, 2);
216
+ // Collect all hashes that share the same 2-char prefix directory
217
+ const hashes = [];
218
+ try {
219
+ const dirPath = path.join(objectsDir, targetPrefix);
220
+ const entries = await fs.readdir(dirPath);
221
+ for (const entry of entries) {
222
+ if (entry.endsWith('.beast2') && !entry.includes('.partial')) {
223
+ // Reconstruct full hash: dir prefix + filename without extension
224
+ const fullHash = targetPrefix + entry.slice(0, -7); // remove '.beast2'
225
+ hashes.push(fullHash);
226
+ }
227
+ }
228
+ }
229
+ catch {
230
+ // Directory doesn't exist - hash is unique at minimum length
231
+ return minLength;
232
+ }
233
+ // Find minimum length that disambiguates from all other hashes
234
+ let length = minLength;
235
+ while (length < hash.length) {
236
+ const prefix = hash.slice(0, length);
237
+ const conflicts = hashes.filter((h) => h !== hash && h.startsWith(prefix));
238
+ if (conflicts.length === 0) {
239
+ return length;
240
+ }
241
+ length++;
242
+ }
243
+ return hash.length;
244
+ }
245
+ //# sourceMappingURL=objects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objects.js","sourceRoot":"","sources":["../../src/objects.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnE;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,IAAgB;IAC1C,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,qBAAqB,CAClC,MAAkC;IAElC,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IACzC,MAAM,MAAM,GAAiB,EAAE,CAAC;IAEhC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAElC,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5C,IAAI,IAAI;YAAE,MAAM;QAEhB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACnB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IAED,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK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AC;QAEF,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,EAAE,CAAC;IACX,CAAC;IAED,OAAO,IAAI,CAAC,MAAM,CAAC;AACrB,CAAC"}
@@ -0,0 +1,85 @@
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 type { PackageObject } from '@elaraai/e3-types';
6
+ /**
7
+ * Result of importing a package
8
+ */
9
+ export interface PackageImportResult {
10
+ name: string;
11
+ version: string;
12
+ packageHash: string;
13
+ objectCount: number;
14
+ }
15
+ /**
16
+ * Import a package from a .zip file into the repository.
17
+ *
18
+ * Extracts objects to `objects/`, creates ref at `packages/<name>/<version>`.
19
+ *
20
+ * @param repoPath - Path to .e3 repository
21
+ * @param zipPath - Path to the .zip package file
22
+ * @returns Import result with package name, version, and stats
23
+ */
24
+ export declare function packageImport(repoPath: string, zipPath: string): Promise<PackageImportResult>;
25
+ /**
26
+ * Remove a package ref from the repository.
27
+ *
28
+ * Objects remain until gc is run.
29
+ *
30
+ * @param repoPath - Path to .e3 repository
31
+ * @param name - Package name
32
+ * @param version - Package version
33
+ * @throws {PackageNotFoundError} If package doesn't exist
34
+ */
35
+ export declare function packageRemove(repoPath: string, name: string, version: string): Promise<void>;
36
+ /**
37
+ * List all installed packages.
38
+ *
39
+ * @param repoPath - Path to .e3 repository
40
+ * @returns Array of (name, version) pairs
41
+ */
42
+ export declare function packageList(repoPath: string): Promise<Array<{
43
+ name: string;
44
+ version: string;
45
+ }>>;
46
+ /**
47
+ * Resolve a package to its PackageObject hash.
48
+ *
49
+ * @param repoPath - Path to .e3 repository
50
+ * @param name - Package name
51
+ * @param version - Package version
52
+ * @returns PackageObject hash
53
+ * @throws {PackageNotFoundError} If package doesn't exist
54
+ */
55
+ export declare function packageResolve(repoPath: string, name: string, version: string): Promise<string>;
56
+ /**
57
+ * Read and parse a PackageObject.
58
+ *
59
+ * @param repoPath - Path to .e3 repository
60
+ * @param name - Package name
61
+ * @param version - Package version
62
+ * @returns Parsed PackageObject
63
+ * @throws {PackageNotFoundError} If package doesn't exist
64
+ */
65
+ export declare function packageRead(repoPath: string, name: string, version: string): Promise<PackageObject>;
66
+ /**
67
+ * Result of exporting a package
68
+ */
69
+ export interface PackageExportResult {
70
+ packageHash: string;
71
+ objectCount: number;
72
+ }
73
+ /**
74
+ * Export a package to a .zip file.
75
+ *
76
+ * Collects the package object and all transitively referenced objects.
77
+ *
78
+ * @param repoPath - Path to .e3 repository
79
+ * @param name - Package name
80
+ * @param version - Package version
81
+ * @param zipPath - Path to write the .zip file
82
+ * @returns Export result with package hash and object count
83
+ */
84
+ export declare function packageExport(repoPath: string, name: string, version: string, zipPath: string): Promise<PackageExportResult>;
85
+ //# sourceMappingURL=packages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packages.d.ts","sourceRoot":"","sources":["../../src/packages.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgBH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAQvD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,mBAAmB,CAAC,CAkE9B;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC,CAkBf;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,GACf,OA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