@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,116 @@
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 { WorkspaceState } from '@elaraai/e3-types';
6
+ /**
7
+ * Create an empty workspace.
8
+ *
9
+ * Creates an undeployed workspace (state file with null package info).
10
+ * Use workspaceDeploy to deploy a package.
11
+ *
12
+ * @param repoPath - Path to .e3 repository
13
+ * @param name - Workspace name
14
+ * @throws {WorkspaceExistsError} If workspace already exists
15
+ */
16
+ export declare function workspaceCreate(repoPath: string, name: string): Promise<void>;
17
+ /**
18
+ * Remove a workspace.
19
+ *
20
+ * Objects remain until repoGc is run.
21
+ *
22
+ * @param repoPath - Path to .e3 repository
23
+ * @param name - Workspace name
24
+ * @throws {WorkspaceNotFoundError} If workspace doesn't exist
25
+ */
26
+ export declare function workspaceRemove(repoPath: string, name: string): Promise<void>;
27
+ /**
28
+ * List workspace names.
29
+ *
30
+ * @param repoPath - Path to .e3 repository
31
+ * @returns Array of workspace names
32
+ */
33
+ export declare function workspaceList(repoPath: string): Promise<string[]>;
34
+ /**
35
+ * Get the full state for a workspace.
36
+ *
37
+ * @param repoPath - Path to .e3 repository
38
+ * @param name - Workspace name
39
+ * @returns Workspace state, or null if workspace doesn't exist or is not deployed
40
+ */
41
+ export declare function workspaceGetState(repoPath: string, name: string): Promise<WorkspaceState | null>;
42
+ /**
43
+ * Get the deployed package for a workspace.
44
+ *
45
+ * @param repoPath - Path to .e3 repository
46
+ * @param name - Workspace name
47
+ * @returns Package name, version, and hash
48
+ * @throws {WorkspaceNotFoundError} If workspace doesn't exist
49
+ * @throws {WorkspaceNotDeployedError} If workspace exists but has no package deployed
50
+ */
51
+ export declare function workspaceGetPackage(repoPath: string, name: string): Promise<{
52
+ name: string;
53
+ version: string;
54
+ hash: string;
55
+ }>;
56
+ /**
57
+ * Get the root tree hash for a workspace.
58
+ *
59
+ * @param repoPath - Path to .e3 repository
60
+ * @param name - Workspace name
61
+ * @returns Root tree object hash
62
+ * @throws {WorkspaceNotFoundError} If workspace doesn't exist
63
+ * @throws {WorkspaceNotDeployedError} If workspace exists but has no package deployed
64
+ */
65
+ export declare function workspaceGetRoot(repoPath: string, name: string): Promise<string>;
66
+ /**
67
+ * Atomically update the root tree hash for a workspace.
68
+ *
69
+ * @param repoPath - Path to .e3 repository
70
+ * @param name - Workspace name
71
+ * @param hash - New root tree object hash
72
+ * @throws {WorkspaceNotFoundError} If workspace doesn't exist
73
+ * @throws {WorkspaceNotDeployedError} If workspace exists but has no package deployed
74
+ */
75
+ export declare function workspaceSetRoot(repoPath: string, name: string, hash: string): Promise<void>;
76
+ /**
77
+ * Deploy a package to a workspace.
78
+ *
79
+ * Creates the workspace if it doesn't exist. Writes state file atomically
80
+ * containing deployment info and root hash.
81
+ *
82
+ * @param repoPath - Path to .e3 repository
83
+ * @param name - Workspace name
84
+ * @param pkgName - Package name
85
+ * @param pkgVersion - Package version
86
+ */
87
+ export declare function workspaceDeploy(repoPath: string, name: string, pkgName: string, pkgVersion: string): Promise<void>;
88
+ /**
89
+ * Result of exporting a workspace
90
+ */
91
+ export interface WorkspaceExportResult {
92
+ packageHash: string;
93
+ objectCount: number;
94
+ name: string;
95
+ version: string;
96
+ }
97
+ /**
98
+ * Export a workspace as a package.
99
+ *
100
+ * 1. Read workspace state
101
+ * 2. Read deployed package structure using stored packageHash
102
+ * 3. Create new PackageObject with data.value set to current rootHash
103
+ * 4. Collect all referenced objects
104
+ * 5. Write to .zip
105
+ *
106
+ * @param repoPath - Path to .e3 repository
107
+ * @param name - Workspace name
108
+ * @param zipPath - Path to write the .zip file
109
+ * @param outputName - Package name (default: deployed package name)
110
+ * @param version - Package version (default: <pkgVersion>-<rootHash[0..8]>)
111
+ * @returns Export result with package info
112
+ * @throws {WorkspaceNotFoundError} If workspace doesn't exist
113
+ * @throws {WorkspaceNotDeployedError} If workspace exists but has no package deployed
114
+ */
115
+ export declare function workspaceExport(repoPath: string, name: string, zipPath: string, outputName?: string, version?: string): Promise<WorkspaceExportResult>;
116
+ //# sourceMappingURL=workspaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspaces.d.ts","sourceRoot":"","sources":["../../src/workspaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoBH,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAqFvE;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC,CAqBf;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,EAAE,CAAC,CAgBnB;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAMhC;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAO1D;AAED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,MAAM,CAAC,CAGjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAgBf;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAOD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,qBAAqB,CAAC,CAqGhC"}
@@ -0,0 +1,356 @@
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
+ * Workspace operations for e3 repositories.
7
+ *
8
+ * Workspaces are mutable working copies of packages. They allow:
9
+ * - Deploying a package to create a working environment
10
+ * - Modifying data (inputs/outputs)
11
+ * - Exporting changes back to a new package version
12
+ *
13
+ * State is stored in workspaces/<name>.beast2 as a single atomic file.
14
+ * No state file means the workspace does not exist.
15
+ */
16
+ import * as fs from 'fs/promises';
17
+ import { createWriteStream } from 'fs';
18
+ import * as path from 'path';
19
+ import yazl from 'yazl';
20
+ import { decodeBeast2For, encodeBeast2For } from '@elaraai/east';
21
+ import { PackageObjectType, WorkspaceStateType } from '@elaraai/e3-types';
22
+ import { objectRead, objectWrite } from './objects.js';
23
+ import { packageResolve, packageRead } from './packages.js';
24
+ import { WorkspaceNotFoundError, WorkspaceNotDeployedError, WorkspaceExistsError, isNotFoundError, } from './errors.js';
25
+ /**
26
+ * Get the path to a workspace's state file.
27
+ */
28
+ function statePath(repoPath, name) {
29
+ return path.join(repoPath, 'workspaces', `${name}.beast2`);
30
+ }
31
+ /**
32
+ * Atomically write workspace state.
33
+ */
34
+ async function writeState(repoPath, name, state) {
35
+ const wsDir = path.join(repoPath, 'workspaces');
36
+ const stateFile = statePath(repoPath, name);
37
+ // Ensure workspaces directory exists
38
+ await fs.mkdir(wsDir, { recursive: true });
39
+ const encoder = encodeBeast2For(WorkspaceStateType);
40
+ const data = encoder(state);
41
+ // Write atomically: write to temp file, then rename
42
+ const randomSuffix = Math.random().toString(36).slice(2, 10);
43
+ const tempPath = path.join(wsDir, `.${name}.${Date.now()}.${randomSuffix}.tmp`);
44
+ await fs.writeFile(tempPath, data);
45
+ await fs.rename(tempPath, stateFile);
46
+ }
47
+ /**
48
+ * Read workspace state.
49
+ * Returns { exists: false } if workspace doesn't exist.
50
+ * Returns { exists: true, deployed: false } if workspace exists but not deployed.
51
+ * Returns { exists: true, deployed: true, state } if workspace is deployed.
52
+ */
53
+ async function readState(repoPath, name) {
54
+ const stateFile = statePath(repoPath, name);
55
+ try {
56
+ const data = await fs.readFile(stateFile);
57
+ // Empty file means workspace exists but is not deployed
58
+ if (data.length === 0) {
59
+ return { exists: true, deployed: false };
60
+ }
61
+ const decoder = decodeBeast2For(WorkspaceStateType);
62
+ return { exists: true, deployed: true, state: decoder(data) };
63
+ }
64
+ catch (err) {
65
+ if (isNotFoundError(err)) {
66
+ return { exists: false };
67
+ }
68
+ throw err;
69
+ }
70
+ }
71
+ /**
72
+ * Read workspace state, throwing if workspace doesn't exist or is not deployed.
73
+ * @throws {WorkspaceNotFoundError} If workspace doesn't exist
74
+ * @throws {WorkspaceNotDeployedError} If workspace exists but has no package deployed
75
+ */
76
+ async function readStateOrThrow(repoPath, name) {
77
+ const result = await readState(repoPath, name);
78
+ if (!result.exists) {
79
+ throw new WorkspaceNotFoundError(name);
80
+ }
81
+ if (!result.deployed) {
82
+ throw new WorkspaceNotDeployedError(name);
83
+ }
84
+ return result.state;
85
+ }
86
+ /**
87
+ * Create an empty workspace.
88
+ *
89
+ * Creates an undeployed workspace (state file with null package info).
90
+ * Use workspaceDeploy to deploy a package.
91
+ *
92
+ * @param repoPath - Path to .e3 repository
93
+ * @param name - Workspace name
94
+ * @throws {WorkspaceExistsError} If workspace already exists
95
+ */
96
+ export async function workspaceCreate(repoPath, name) {
97
+ const stateFile = statePath(repoPath, name);
98
+ // Check if workspace already exists
99
+ try {
100
+ await fs.access(stateFile);
101
+ throw new WorkspaceExistsError(name);
102
+ }
103
+ catch (err) {
104
+ if (err instanceof WorkspaceExistsError)
105
+ throw err;
106
+ if (!isNotFoundError(err)) {
107
+ throw err;
108
+ }
109
+ }
110
+ // Create workspaces directory if needed
111
+ const wsDir = path.join(repoPath, 'workspaces');
112
+ await fs.mkdir(wsDir, { recursive: true });
113
+ // Create empty file to mark workspace as existing but not deployed
114
+ // We use an empty file rather than a state file since there's no valid state yet
115
+ await fs.writeFile(stateFile, '');
116
+ }
117
+ /**
118
+ * Remove a workspace.
119
+ *
120
+ * Objects remain until repoGc is run.
121
+ *
122
+ * @param repoPath - Path to .e3 repository
123
+ * @param name - Workspace name
124
+ * @throws {WorkspaceNotFoundError} If workspace doesn't exist
125
+ */
126
+ export async function workspaceRemove(repoPath, name) {
127
+ const stateFile = statePath(repoPath, name);
128
+ try {
129
+ await fs.unlink(stateFile);
130
+ }
131
+ catch (err) {
132
+ if (isNotFoundError(err)) {
133
+ throw new WorkspaceNotFoundError(name);
134
+ }
135
+ throw err;
136
+ }
137
+ }
138
+ /**
139
+ * List workspace names.
140
+ *
141
+ * @param repoPath - Path to .e3 repository
142
+ * @returns Array of workspace names
143
+ */
144
+ export async function workspaceList(repoPath) {
145
+ const workspacesDir = path.join(repoPath, 'workspaces');
146
+ const names = [];
147
+ try {
148
+ const entries = await fs.readdir(workspacesDir);
149
+ for (const entry of entries) {
150
+ if (entry.endsWith('.beast2')) {
151
+ names.push(entry.slice(0, -7)); // Remove .beast2 extension
152
+ }
153
+ }
154
+ }
155
+ catch {
156
+ // workspaces directory doesn't exist
157
+ }
158
+ return names;
159
+ }
160
+ /**
161
+ * Get the full state for a workspace.
162
+ *
163
+ * @param repoPath - Path to .e3 repository
164
+ * @param name - Workspace name
165
+ * @returns Workspace state, or null if workspace doesn't exist or is not deployed
166
+ */
167
+ export async function workspaceGetState(repoPath, name) {
168
+ const result = await readState(repoPath, name);
169
+ if (!result.exists || !result.deployed) {
170
+ return null;
171
+ }
172
+ return result.state;
173
+ }
174
+ /**
175
+ * Get the deployed package for a workspace.
176
+ *
177
+ * @param repoPath - Path to .e3 repository
178
+ * @param name - Workspace name
179
+ * @returns Package name, version, and hash
180
+ * @throws {WorkspaceNotFoundError} If workspace doesn't exist
181
+ * @throws {WorkspaceNotDeployedError} If workspace exists but has no package deployed
182
+ */
183
+ export async function workspaceGetPackage(repoPath, name) {
184
+ const state = await readStateOrThrow(repoPath, name);
185
+ return {
186
+ name: state.packageName,
187
+ version: state.packageVersion,
188
+ hash: state.packageHash,
189
+ };
190
+ }
191
+ /**
192
+ * Get the root tree hash for a workspace.
193
+ *
194
+ * @param repoPath - Path to .e3 repository
195
+ * @param name - Workspace name
196
+ * @returns Root tree object hash
197
+ * @throws {WorkspaceNotFoundError} If workspace doesn't exist
198
+ * @throws {WorkspaceNotDeployedError} If workspace exists but has no package deployed
199
+ */
200
+ export async function workspaceGetRoot(repoPath, name) {
201
+ const state = await readStateOrThrow(repoPath, name);
202
+ return state.rootHash;
203
+ }
204
+ /**
205
+ * Atomically update the root tree hash for a workspace.
206
+ *
207
+ * @param repoPath - Path to .e3 repository
208
+ * @param name - Workspace name
209
+ * @param hash - New root tree object hash
210
+ * @throws {WorkspaceNotFoundError} If workspace doesn't exist
211
+ * @throws {WorkspaceNotDeployedError} If workspace exists but has no package deployed
212
+ */
213
+ export async function workspaceSetRoot(repoPath, name, hash) {
214
+ const state = await readStateOrThrow(repoPath, name);
215
+ const newState = {
216
+ ...state,
217
+ rootHash: hash,
218
+ rootUpdatedAt: new Date(),
219
+ };
220
+ await writeState(repoPath, name, newState);
221
+ }
222
+ /**
223
+ * Deploy a package to a workspace.
224
+ *
225
+ * Creates the workspace if it doesn't exist. Writes state file atomically
226
+ * containing deployment info and root hash.
227
+ *
228
+ * @param repoPath - Path to .e3 repository
229
+ * @param name - Workspace name
230
+ * @param pkgName - Package name
231
+ * @param pkgVersion - Package version
232
+ */
233
+ export async function workspaceDeploy(repoPath, name, pkgName, pkgVersion) {
234
+ // Resolve package hash and read package object
235
+ const packageHash = await packageResolve(repoPath, pkgName, pkgVersion);
236
+ const pkg = await packageRead(repoPath, pkgName, pkgVersion);
237
+ const now = new Date();
238
+ const state = {
239
+ packageName: pkgName,
240
+ packageVersion: pkgVersion,
241
+ packageHash,
242
+ deployedAt: now,
243
+ rootHash: pkg.data.value,
244
+ rootUpdatedAt: now,
245
+ };
246
+ await writeState(repoPath, name, state);
247
+ }
248
+ /**
249
+ * Fixed mtime for deterministic zip output (Unix epoch)
250
+ */
251
+ const DETERMINISTIC_MTIME = new Date(0);
252
+ /**
253
+ * Export a workspace as a package.
254
+ *
255
+ * 1. Read workspace state
256
+ * 2. Read deployed package structure using stored packageHash
257
+ * 3. Create new PackageObject with data.value set to current rootHash
258
+ * 4. Collect all referenced objects
259
+ * 5. Write to .zip
260
+ *
261
+ * @param repoPath - Path to .e3 repository
262
+ * @param name - Workspace name
263
+ * @param zipPath - Path to write the .zip file
264
+ * @param outputName - Package name (default: deployed package name)
265
+ * @param version - Package version (default: <pkgVersion>-<rootHash[0..8]>)
266
+ * @returns Export result with package info
267
+ * @throws {WorkspaceNotFoundError} If workspace doesn't exist
268
+ * @throws {WorkspaceNotDeployedError} If workspace exists but has no package deployed
269
+ */
270
+ export async function workspaceExport(repoPath, name, zipPath, outputName, version) {
271
+ const partialPath = `${zipPath}.partial`;
272
+ // Get workspace state
273
+ const state = await readStateOrThrow(repoPath, name);
274
+ // Read the deployed package object using the stored hash
275
+ const deployedPkgData = await objectRead(repoPath, state.packageHash);
276
+ const decoder = decodeBeast2For(PackageObjectType);
277
+ const deployedPkgObject = decoder(Buffer.from(deployedPkgData));
278
+ // Determine output name and version
279
+ const finalName = outputName ?? state.packageName;
280
+ const finalVersion = version ?? `${state.packageVersion}-${state.rootHash.slice(0, 8)}`;
281
+ // Create new PackageObject with updated root
282
+ const newPkgObject = {
283
+ tasks: deployedPkgObject.tasks,
284
+ data: {
285
+ structure: deployedPkgObject.data.structure,
286
+ value: state.rootHash,
287
+ },
288
+ };
289
+ // Encode and store the new package object
290
+ const encoder = encodeBeast2For(PackageObjectType);
291
+ const pkgData = encoder(newPkgObject);
292
+ const packageHash = await objectWrite(repoPath, pkgData);
293
+ // Create zip file
294
+ const zipfile = new yazl.ZipFile();
295
+ // Track which objects we've added to avoid duplicates
296
+ const addedObjects = new Set();
297
+ // Helper to add an object to the zip
298
+ const addObject = async (hash) => {
299
+ if (addedObjects.has(hash))
300
+ return;
301
+ addedObjects.add(hash);
302
+ const data = await objectRead(repoPath, hash);
303
+ const objPath = `objects/${hash.slice(0, 2)}/${hash.slice(2)}.beast2`;
304
+ zipfile.addBuffer(Buffer.from(data), objPath, { mtime: DETERMINISTIC_MTIME });
305
+ };
306
+ // Helper to collect children from a tree object (same as packages.ts)
307
+ const collectTreeChildren = async (treeData) => {
308
+ const dataStr = Buffer.from(treeData).toString('latin1');
309
+ const hashPattern = /[a-f0-9]{64}/g;
310
+ const matches = dataStr.matchAll(hashPattern);
311
+ for (const match of matches) {
312
+ const potentialHash = match[0];
313
+ if (addedObjects.has(potentialHash))
314
+ continue;
315
+ try {
316
+ await addObject(potentialHash);
317
+ const childData = await objectRead(repoPath, potentialHash);
318
+ await collectTreeChildren(childData);
319
+ }
320
+ catch {
321
+ addedObjects.delete(potentialHash);
322
+ }
323
+ }
324
+ };
325
+ // Add the package object
326
+ await addObject(packageHash);
327
+ // Collect all task objects
328
+ for (const taskHash of newPkgObject.tasks.values()) {
329
+ await addObject(taskHash);
330
+ }
331
+ // Collect the root tree and all its children
332
+ await addObject(state.rootHash);
333
+ const rootTreeData = await objectRead(repoPath, state.rootHash);
334
+ await collectTreeChildren(rootTreeData);
335
+ // Write the package ref
336
+ const refPath = `packages/${finalName}/${finalVersion}`;
337
+ zipfile.addBuffer(Buffer.from(packageHash + '\n'), refPath, { mtime: DETERMINISTIC_MTIME });
338
+ // Finalize and write zip to disk
339
+ await new Promise((resolve, reject) => {
340
+ const writeStream = createWriteStream(partialPath);
341
+ zipfile.outputStream.pipe(writeStream);
342
+ zipfile.outputStream.on('error', reject);
343
+ writeStream.on('error', reject);
344
+ writeStream.on('close', resolve);
345
+ zipfile.end();
346
+ });
347
+ // Atomic rename to final path
348
+ await fs.rename(partialPath, zipPath);
349
+ return {
350
+ packageHash,
351
+ objectCount: addedObjects.size,
352
+ name: finalName,
353
+ version: finalVersion,
354
+ };
355
+ }
356
+ //# sourceMappingURL=workspaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspaces.js","sourceRoot":"","sources":["../../src/workspaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,IAAI,MAAM,M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;IAEH,8BAA8B;IAC9B,MAAM,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAEtC,OAAO;QACL,WAAW;QACX,WAAW,EAAE,YAAY,CAAC,IAAI;QAC9B,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,YAAY;KACtB,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@elaraai/e3-core",
3
+ "version": "0.0.1-beta.0",
4
+ "type": "module",
5
+ "description": "East Execution Engine Core - Programmatic API for e3 repository operations",
6
+ "main": "dist/src/index.js",
7
+ "types": "dist/src/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/src/index.d.ts",
11
+ "default": "./dist/src/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist/src",
16
+ "!dist/src/**/*.spec.*",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc --build",
22
+ "test": "npm run build && node --enable-source-maps --test 'dist/src/**/*.spec.js'",
23
+ "lint": "eslint .",
24
+ "lint:fix": "eslint . --fix"
25
+ },
26
+ "keywords": [
27
+ "east",
28
+ "e3",
29
+ "core",
30
+ "library"
31
+ ],
32
+ "license": "SEE LICENSE IN LICENSE",
33
+ "dependencies": {
34
+ "@elaraai/e3": "*",
35
+ "@elaraai/e3-types": "*",
36
+ "@elaraai/east": "0.0.1-beta.11",
37
+ "yauzl": "^3.2.0",
38
+ "yazl": "^2.5.1"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^22.0.0",
42
+ "@types/yauzl": "^2.10.3",
43
+ "@types/yazl": "^2.4.5",
44
+ "@typescript-eslint/eslint-plugin": "^8.47.0",
45
+ "@typescript-eslint/parser": "^8.47.0",
46
+ "eslint": "^9.0.0",
47
+ "eslint-plugin-headers": "^1.3.3",
48
+ "typescript": "^5.6.0"
49
+ }
50
+ }