@elaraai/e3-types 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.
@@ -0,0 +1,236 @@
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
+ * Data structure and path types for e3.
7
+ *
8
+ * Terminology:
9
+ * - **Dataset**: A location holding a value (leaf node in the data tree)
10
+ * - **Tree**: A location containing datasets or nested trees (branch node)
11
+ * - **Structure**: The shape of the data tree (what trees/datasets exist and their types)
12
+ * - **Path**: An address pointing to a dataset or tree
13
+ *
14
+ * Paths use East's keypath syntax:
15
+ * - `.field` for struct field access (backtick-quoted for special chars)
16
+ * - `[N]` for array index access (future)
17
+ * - `[key]` for dict key lookup (future)
18
+ *
19
+ * @see East serialization docs for keypath syntax details
20
+ */
21
+ import { VariantType, StringType, ArrayType, DictType, RecursiveType, printIdentifier, variant, EastTypeType } from '@elaraai/east';
22
+ /**
23
+ * Structure definition for a data tree node.
24
+ *
25
+ * Defines the shape of the data tree - which paths are datasets (hold values)
26
+ * and which are trees (hold other nodes).
27
+ *
28
+ * @remarks
29
+ * - `value`: A dataset - holds a typed value. The type is an `EastTypeValue`.
30
+ * - `struct`: A tree - has named children, each with its own structure.
31
+ *
32
+ * MVP only supports struct trees. Future: array, dict, variant trees.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * // A dataset holding an Integer value
37
+ * const dataset: Structure = variant('value', variant('Integer', null));
38
+ *
39
+ * // A tree with named children
40
+ * const tree: Structure = variant('struct', new Map([
41
+ * ['count', variant('value', variant('Integer', null))],
42
+ * ['items', variant('value', variant('Array', variant('String', null)))],
43
+ * ]));
44
+ * ```
45
+ */
46
+ export const StructureType = RecursiveType(self => VariantType({
47
+ /** Dataset: East type of the value (homoiconic EastTypeValue) */
48
+ value: EastTypeType,
49
+ /** Struct tree: named children mapping to child structures */
50
+ struct: DictType(StringType, self),
51
+ }));
52
+ // Backwards compatibility alias
53
+ /** @deprecated Use StructureType instead */
54
+ export const DatasetSchemaType = StructureType;
55
+ /**
56
+ * Path segment for navigating data trees.
57
+ *
58
+ * Uses East keypath syntax for consistency:
59
+ * - `field`: Struct field access (rendered as `.field` or `` .`field` `` if quoted)
60
+ * - `index`: Array element access (rendered as `[N]`) - future
61
+ * - `key`: Dict key lookup (rendered as `[key]`) - future
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * // Struct field access
66
+ * const segment: PathSegment = variant('field', 'sales');
67
+ *
68
+ * // Array index (future)
69
+ * const segment: PathSegment = variant('index', 0n);
70
+ * ```
71
+ */
72
+ export const PathSegmentType = VariantType({
73
+ /** Struct field access by name */
74
+ field: StringType,
75
+ // Future: case: StringType for variant case identifiers
76
+ // Future: index: IntegerType for array access
77
+ // Future: key: StringType (or polymorphic) for dict access
78
+ });
79
+ /**
80
+ * Path: sequence of segments identifying a location in a data tree.
81
+ *
82
+ * Paths point to either a dataset (leaf) or a tree (branch).
83
+ * Used by tasks to specify where inputs come from and where outputs go.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * // Path to .inputs.sales.data
88
+ * const path: TreePath = [
89
+ * variant('field', 'inputs'),
90
+ * variant('field', 'sales'),
91
+ * variant('field', 'data'),
92
+ * ];
93
+ * ```
94
+ */
95
+ export const TreePathType = ArrayType(PathSegmentType);
96
+ /**
97
+ * Converts a path to East keypath string representation.
98
+ *
99
+ * Uses East's keypath syntax: `.field` for simple identifiers,
100
+ * `` .`field` `` for identifiers needing quoting.
101
+ *
102
+ * @param path - The path to convert
103
+ * @returns A keypath string (e.g., ".inputs.sales" or ".inputs.`my/field`")
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * const path = treePath('inputs', 'sales');
108
+ * pathToString(path); // ".inputs.sales"
109
+ *
110
+ * const path2 = treePath('inputs', 'my/field');
111
+ * pathToString(path2); // ".inputs.`my/field`"
112
+ * ```
113
+ */
114
+ export function pathToString(path) {
115
+ return path.map(segment => {
116
+ if (segment.type === 'field') {
117
+ return '.' + printIdentifier(segment.value);
118
+ }
119
+ else {
120
+ throw new Error(`pathToString: unsupported path segment type: ${segment.type}`);
121
+ }
122
+ }).join('');
123
+ }
124
+ /**
125
+ * Parses an East keypath string into a path, validating against the structure.
126
+ *
127
+ * Supports `.field` syntax for struct field access.
128
+ * Backtick-quoted identifiers (`` .`field` ``) are supported for special chars.
129
+ *
130
+ * @param pathStr - A keypath string (e.g., ".inputs.sales")
131
+ * @param structure - The root structure to validate against
132
+ * @returns The parsed path and the structure at that location
133
+ *
134
+ * @throws {Error} If a field doesn't exist in the structure or path descends into a dataset
135
+ *
136
+ * @remarks
137
+ * - Empty string returns empty path (root) with the root structure
138
+ * - Path must start with `.` (no leading slash)
139
+ * - Backtick escaping: `` \` `` for literal backtick, `\\` for backslash
140
+ * - Future: will disambiguate variant cases from struct fields using structure
141
+ * - Future: will use structure to parse dict keys with correct type
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * const structure = variant('struct', new Map([
146
+ * ['inputs', variant('struct', new Map([
147
+ * ['sales', variant('value', variant('Integer', null))],
148
+ * ]))],
149
+ * ]));
150
+ *
151
+ * const { path, structure: leafStructure } = parsePath('.inputs.sales', structure);
152
+ * // path = [field('inputs'), field('sales')]
153
+ * // leafStructure = variant('value', variant('Integer', null))
154
+ * ```
155
+ */
156
+ export function parsePath(pathStr, structure) {
157
+ if (pathStr === '')
158
+ return { path: [], structure };
159
+ const segments = [];
160
+ let currentStructure = structure;
161
+ let pos = 0;
162
+ while (pos < pathStr.length) {
163
+ if (pathStr[pos] === '.') {
164
+ pos++;
165
+ // Parse identifier (TODO: export parseIdentifier from east package)
166
+ let fieldName;
167
+ // Check for backtick-quoted identifier
168
+ if (pos < pathStr.length && pathStr[pos] === '`') {
169
+ pos++;
170
+ fieldName = '';
171
+ while (pos < pathStr.length && pathStr[pos] !== '`') {
172
+ if (pathStr[pos] === '\\' && pos + 1 < pathStr.length) {
173
+ // Escape sequence
174
+ pos++;
175
+ fieldName += pathStr[pos];
176
+ }
177
+ else {
178
+ fieldName += pathStr[pos];
179
+ }
180
+ pos++;
181
+ }
182
+ if (pos < pathStr.length && pathStr[pos] === '`') {
183
+ pos++; // consume closing backtick
184
+ }
185
+ }
186
+ else {
187
+ // Simple identifier: [a-zA-Z_][a-zA-Z0-9_]*
188
+ fieldName = '';
189
+ while (pos < pathStr.length && /[a-zA-Z0-9_]/.test(pathStr[pos])) {
190
+ fieldName += pathStr[pos];
191
+ pos++;
192
+ }
193
+ }
194
+ if (fieldName.length === 0) {
195
+ throw new Error(`parsePath: expected identifier after '.' at position ${pos}`);
196
+ }
197
+ // Validate against structure
198
+ if (currentStructure.type === 'value') {
199
+ throw new Error(`parsePath: cannot descend into dataset at '${pathToString(segments)}'`);
200
+ }
201
+ // currentStructure.type === 'struct' (only other option after 'value' check)
202
+ const fields = currentStructure.value;
203
+ const childStructure = fields.get(fieldName);
204
+ if (childStructure === undefined) {
205
+ const available = [...fields.keys()].map(k => printIdentifier(k)).join(', ');
206
+ throw new Error(`parsePath: field '${fieldName}' not found at '${pathToString(segments)}'. Available: ${available}`);
207
+ }
208
+ segments.push(variant('field', fieldName));
209
+ currentStructure = childStructure;
210
+ }
211
+ else {
212
+ throw new Error(`parsePath: unexpected character at position ${pos}: '${pathStr[pos]}'`);
213
+ }
214
+ }
215
+ return { path: segments, structure: currentStructure };
216
+ }
217
+ /**
218
+ * Creates a path from field names, validating against the structure.
219
+ *
220
+ * Convenience function for the common case of navigating through struct fields.
221
+ *
222
+ * @param structure - The root structure to validate against
223
+ * @param fields - Field names to include in the path
224
+ * @returns The parsed path and the structure at that location
225
+ *
226
+ * @throws {Error} If a field doesn't exist in the structure
227
+ *
228
+ * @example
229
+ * ```ts
230
+ * const { path, structure: leafStructure } = treePath(rootStructure, 'inputs', 'sales');
231
+ * ```
232
+ */
233
+ export function treePath(structure, ...fields) {
234
+ return parsePath('.' + fields.map(printIdentifier).join('.'), struct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BAAgB,GAAG,cAAc,CAAC;QACpC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,+CAA+C,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC3F,CAAC;IACH,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC;AACzD,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,QAAQ,CAAC,SAAoB,EAAE,GAAG,MAAgB;IAChE,OAAO,SAAS,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,66 @@
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
+ * Task object types for e3.
7
+ *
8
+ * A task object defines a complete executable unit: the command IR that
9
+ * generates the exec args, where to read inputs from, and where to write output.
10
+ *
11
+ * Task objects are stored in the object store and referenced by packages.
12
+ * They are content-addressed, enabling deduplication and memoization.
13
+ *
14
+ * Input and output types are inferred from the package's structure at the
15
+ * specified paths - the task just references locations, not types.
16
+ */
17
+ import { StructType, StringType, ArrayType, ValueTypeOf } from '@elaraai/east';
18
+ /**
19
+ * Task object stored in the object store.
20
+ *
21
+ * A task is a complete executable unit that reads from input dataset paths
22
+ * and writes to an output dataset path. The commandIr is evaluated at runtime
23
+ * to produce the exec args.
24
+ *
25
+ * @remarks
26
+ * - `commandIr`: Hash of East IR object that produces exec args
27
+ * - IR signature: (inputs: Array<String>, output: String) -> Array<String>
28
+ * - `inputs` are paths to staged input .beast2 files
29
+ * - `output` is the path where output should be written
30
+ * - Returns array of strings to exec (e.g., ["sh", "-c", "python ..."])
31
+ * - `inputs`: Paths to input datasets in the data tree
32
+ * - `output`: Path to the output dataset in the data tree
33
+ *
34
+ * Types are not stored in the task - they are inferred from the package's
35
+ * structure at the specified paths. This keeps tasks simple and avoids
36
+ * redundant type information.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { variant } from '@elaraai/east';
41
+ *
42
+ * // Task with command IR that generates: ["sh", "-c", "python script.py <input> <output>"]
43
+ * const task: TaskObject = {
44
+ * commandIr: '5e7a3b...', // hash of compiled IR
45
+ * inputs: [
46
+ * [variant('field', 'inputs'), variant('field', 'sales')],
47
+ * ],
48
+ * output: [variant('field', 'tasks'), variant('field', 'train'), variant('field', 'output')],
49
+ * };
50
+ * ```
51
+ */
52
+ export declare const TaskObjectType: StructType<{
53
+ /** Hash of East IR that generates exec args: (inputs, output) -> Array<String> */
54
+ commandIr: StringType;
55
+ /** Input paths: where to read each input dataset from the data tree */
56
+ inputs: ArrayType<ArrayType<import("@elaraai/east").VariantType<{
57
+ field: StringType;
58
+ }>>>;
59
+ /** Output path: where to write the output dataset in the data tree */
60
+ output: ArrayType<import("@elaraai/east").VariantType<{
61
+ field: StringType;
62
+ }>>;
63
+ }>;
64
+ export type TaskObjectType = typeof TaskObjectType;
65
+ export type TaskObject = ValueTypeOf<typeof TaskObjectType>;
66
+ //# sourceMappingURL=task.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../../src/task.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,cAAc;IACzB,kFAAkF;;IAElF,uEAAuE;;;;IAEvE,sEAAsE;;;;EAEtE,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,cAAc,CAAC;AAEnD,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,cAAc,CAAC,CAAC"}
@@ -0,0 +1,61 @@
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
+ * Task object types for e3.
7
+ *
8
+ * A task object defines a complete executable unit: the command IR that
9
+ * generates the exec args, where to read inputs from, and where to write output.
10
+ *
11
+ * Task objects are stored in the object store and referenced by packages.
12
+ * They are content-addressed, enabling deduplication and memoization.
13
+ *
14
+ * Input and output types are inferred from the package's structure at the
15
+ * specified paths - the task just references locations, not types.
16
+ */
17
+ import { StructType, StringType, ArrayType } from '@elaraai/east';
18
+ import { TreePathType } from './structure.js';
19
+ /**
20
+ * Task object stored in the object store.
21
+ *
22
+ * A task is a complete executable unit that reads from input dataset paths
23
+ * and writes to an output dataset path. The commandIr is evaluated at runtime
24
+ * to produce the exec args.
25
+ *
26
+ * @remarks
27
+ * - `commandIr`: Hash of East IR object that produces exec args
28
+ * - IR signature: (inputs: Array<String>, output: String) -> Array<String>
29
+ * - `inputs` are paths to staged input .beast2 files
30
+ * - `output` is the path where output should be written
31
+ * - Returns array of strings to exec (e.g., ["sh", "-c", "python ..."])
32
+ * - `inputs`: Paths to input datasets in the data tree
33
+ * - `output`: Path to the output dataset in the data tree
34
+ *
35
+ * Types are not stored in the task - they are inferred from the package's
36
+ * structure at the specified paths. This keeps tasks simple and avoids
37
+ * redundant type information.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import { variant } from '@elaraai/east';
42
+ *
43
+ * // Task with command IR that generates: ["sh", "-c", "python script.py <input> <output>"]
44
+ * const task: TaskObject = {
45
+ * commandIr: '5e7a3b...', // hash of compiled IR
46
+ * inputs: [
47
+ * [variant('field', 'inputs'), variant('field', 'sales')],
48
+ * ],
49
+ * output: [variant('field', 'tasks'), variant('field', 'train'), variant('field', 'output')],
50
+ * };
51
+ * ```
52
+ */
53
+ export const TaskObjectType = StructType({
54
+ /** Hash of East IR that generates exec args: (inputs, output) -> Array<String> */
55
+ commandIr: StringType,
56
+ /** Input paths: where to read each input dataset from the data tree */
57
+ inputs: ArrayType(TreePathType),
58
+ /** Output path: where to write the output dataset in the data tree */
59
+ output: TreePathType,
60
+ });
61
+ //# sourceMappingURL=task.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task.js","sourceRoot":"","sources":["../../src/task.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAe,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;IACvC,kFAAkF;IAClF,SAAS,EAAE,UAAU;IACrB,uEAAuE;IACvE,MAAM,EAAE,SAAS,CAAC,YAAY,CAAC;IAC/B,sEAAsE;IACtE,MAAM,EAAE,YAAY;CACrB,CAAC,CAAC"}
@@ -0,0 +1,49 @@
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 state type definitions.
7
+ *
8
+ * A workspace is a mutable working copy of a package. The state tracks:
9
+ * - Which package was deployed (immutable reference via hash)
10
+ * - When the deployment occurred
11
+ * - Current root data tree hash
12
+ * - When the root was last updated
13
+ *
14
+ * State file location: workspaces/<name>/state.beast2
15
+ * No state file = workspace exists but not yet deployed.
16
+ */
17
+ import { StructType, StringType, DateTimeType, ValueTypeOf } from '@elaraai/east';
18
+ /**
19
+ * Workspace state stored in workspaces/<name>/state.beast2
20
+ *
21
+ * Contains both deployment info and current data root in a single
22
+ * atomic unit to ensure consistency.
23
+ *
24
+ * Future audit trail support:
25
+ * When we implement full audit trail, this state will move to the object
26
+ * store (content-addressed) with a ref file pointing to current state hash.
27
+ * Additional fields for the Merkle chain:
28
+ *
29
+ * previousStateHash: NullableType(StringType), // null for initial deploy
30
+ * message: StringType, // "deployed package X", "user Y wrote to dataset Z"
31
+ *
32
+ * This gives a complete history of workspace changes, similar to git commits.
33
+ */
34
+ export declare const WorkspaceStateType: StructType<{
35
+ /** Name of the deployed package */
36
+ packageName: StringType;
37
+ /** Version of the deployed package */
38
+ packageVersion: StringType;
39
+ /** Hash of the package object at deploy time (immutable reference) */
40
+ packageHash: StringType;
41
+ /** UTC datetime when the package was deployed */
42
+ deployedAt: DateTimeType;
43
+ /** Current root data tree hash */
44
+ rootHash: StringType;
45
+ /** UTC datetime when root was last updated */
46
+ rootUpdatedAt: DateTimeType;
47
+ }>;
48
+ export type WorkspaceState = ValueTypeOf<typeof WorkspaceStateType>;
49
+ //# sourceMappingURL=workspace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/workspace.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAElF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB;IAC7B,mCAAmC;;IAEnC,sCAAsC;;IAEtC,sEAAsE;;IAEtE,iDAAiD;;IAEjD,kCAAkC;;IAElC,8CAA8C;;EAE9C,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
@@ -0,0 +1,48 @@
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 state type definitions.
7
+ *
8
+ * A workspace is a mutable working copy of a package. The state tracks:
9
+ * - Which package was deployed (immutable reference via hash)
10
+ * - When the deployment occurred
11
+ * - Current root data tree hash
12
+ * - When the root was last updated
13
+ *
14
+ * State file location: workspaces/<name>/state.beast2
15
+ * No state file = workspace exists but not yet deployed.
16
+ */
17
+ import { StructType, StringType, DateTimeType } from '@elaraai/east';
18
+ /**
19
+ * Workspace state stored in workspaces/<name>/state.beast2
20
+ *
21
+ * Contains both deployment info and current data root in a single
22
+ * atomic unit to ensure consistency.
23
+ *
24
+ * Future audit trail support:
25
+ * When we implement full audit trail, this state will move to the object
26
+ * store (content-addressed) with a ref file pointing to current state hash.
27
+ * Additional fields for the Merkle chain:
28
+ *
29
+ * previousStateHash: NullableType(StringType), // null for initial deploy
30
+ * message: StringType, // "deployed package X", "user Y wrote to dataset Z"
31
+ *
32
+ * This gives a complete history of workspace changes, similar to git commits.
33
+ */
34
+ export const WorkspaceStateType = StructType({
35
+ /** Name of the deployed package */
36
+ packageName: StringType,
37
+ /** Version of the deployed package */
38
+ packageVersion: StringType,
39
+ /** Hash of the package object at deploy time (immutable reference) */
40
+ packageHash: StringType,
41
+ /** UTC datetime when the package was deployed */
42
+ deployedAt: DateTimeType,
43
+ /** Current root data tree hash */
44
+ rootHash: StringType,
45
+ /** UTC datetime when root was last updated */
46
+ rootUpdatedAt: DateTimeType,
47
+ });
48
+ //# sourceMappingURL=workspace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace.js","sourceRoot":"","sources":["../../src/workspace.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAe,MAAM,eAAe,CAAC;AAElF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;IAC3C,mCAAmC;IACnC,WAAW,EAAE,UAAU;IACvB,sCAAsC;IACtC,cAAc,EAAE,UAAU;IAC1B,sEAAsE;IACtE,WAAW,EAAE,UAAU;IACvB,iDAAiD;IACjD,UAAU,EAAE,YAAY;IACxB,kCAAkC;IAClC,QAAQ,EAAE,UAAU;IACpB,8CAA8C;IAC9C,aAAa,EAAE,YAAY;CAC5B,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@elaraai/e3-types",
3
+ "version": "0.0.1-beta.0",
4
+ "description": "Shared type definitions for e3 (East Execution Engine)",
5
+ "type": "module",
6
+ "main": "dist/src/index.js",
7
+ "types": "dist/src/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc --build",
10
+ "clean": "rm -rf dist",
11
+ "lint": "eslint .",
12
+ "lint:fix": "eslint . --fix"
13
+ },
14
+ "keywords": [
15
+ "east",
16
+ "e3",
17
+ "types"
18
+ ],
19
+ "author": "Elara AI",
20
+ "license": "SEE LICENSE IN LICENSE",
21
+ "dependencies": {
22
+ "@elaraai/east": "0.0.1-beta.11"
23
+ },
24
+ "devDependencies": {
25
+ "@typescript-eslint/eslint-plugin": "^8.47.0",
26
+ "@typescript-eslint/parser": "^8.47.0",
27
+ "eslint-plugin-headers": "^1.3.3",
28
+ "typescript": "^5.7.2"
29
+ }
30
+ }
package/src/dataset.ts ADDED
@@ -0,0 +1,126 @@
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
+ /**
7
+ * Dataset reference and tree types for e3's persistent data structures.
8
+ *
9
+ * e3 stores data as persistent trees with structural sharing (like git trees).
10
+ * Each node is either a leaf (value) or a branch (tree of refs).
11
+ */
12
+
13
+ import { VariantType, StringType, NullType, ValueTypeOf, variant, StructType, EastType } from '@elaraai/east';
14
+
15
+ /**
16
+ * Reference to data in the object store.
17
+ *
18
+ * DataRef is the fundamental building block of e3's data trees.
19
+ * Each ref points to either a value or another tree node.
20
+ *
21
+ * @remarks
22
+ * - `unassigned`: Placeholder for pending task outputs
23
+ * - `null`: Inline null value (optimization)
24
+ * - `value`: Hash of a typed value blob in objects/
25
+ * - `tree`: Hash of a tree object in objects/
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * // Pending output
30
+ * const pending: DataRef = variant('unassigned', null);
31
+ *
32
+ * // Value reference
33
+ * const ref: DataRef = variant('value', 'abc123...');
34
+ *
35
+ * // Tree reference
36
+ * const treeRef: DataRef = variant('tree', 'def456...');
37
+ * ```
38
+ */
39
+ export const DataRefType = VariantType({
40
+ /** Unassigned value (e.g., pending task output) */
41
+ unassigned: NullType,
42
+ /** Inline null value (optimization for NullType) */
43
+ null: NullType,
44
+ /** Hash of a beast2 value blob in objects/ */
45
+ value: StringType,
46
+ /** Hash of a tree object in objects/ */
47
+ tree: StringType,
48
+ });
49
+ export type DataRefType = typeof DataRefType;
50
+
51
+ export type DataRef = ValueTypeOf<typeof DataRefType>;
52
+
53
+ /**
54
+ * Singleton DataRef representing an unassigned value.
55
+ *
56
+ * Used for dataset fields that have not yet been computed (e.g., pending task outputs).
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const tree = {
61
+ * computed: variant('value', 'abc123...'),
62
+ * pending: unassignedRef,
63
+ * };
64
+ * ```
65
+ */
66
+ export const unassignedRef: DataRef = variant('unassigned', null);
67
+
68
+ /**
69
+ * Singleton DataRef representing an inline null value.
70
+ *
71
+ * Optimization for datasets with NullType fields - avoids storing a separate object.
72
+ */
73
+ export const nullRef: DataRef = variant('null', null);
74
+
75
+ /**
76
+ * Computes the DataTreeType for a given EastType.
77
+ *
78
+ * A DataTreeType is a StructType where each field is replaced with a DataRefType,
79
+ * enabling structural sharing in e3's persistent data trees.
80
+ *
81
+ * @typeParam T - The source EastType (must be a StructType for MVP)
82
+ *
83
+ * @remarks
84
+ * Currently only StructType is supported. Future versions may support
85
+ * ArrayType, DictType, VariantType, and RecursiveType.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * const PersonType = StructType({ name: StringType, age: IntegerType });
90
+ * type PersonTree = DataTreeType<typeof PersonType>;
91
+ * // Equivalent to: StructType<{ name: DataRefType, age: DataRefType }>
92
+ * ```
93
+ */
94
+ export type DataTreeType<T extends EastType> =
95
+ T extends StructType<infer Fields> ? StructType<{ [K in keyof Fields]: DataRefType }> :
96
+ never;
97
+
98
+ /**
99
+ * Creates a DataTreeType from an EastType at runtime.
100
+ *
101
+ * Transforms a StructType into a new StructType where each field
102
+ * is replaced with DataRefType.
103
+ *
104
+ * @param type - The source EastType (must be a StructType)
105
+ * @returns A new StructType with DataRefType fields
106
+ *
107
+ * @throws {Error} When the input type is not a StructType
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * const PersonType = StructType({ name: StringType, age: IntegerType });
112
+ * const PersonTreeType = DataTreeType(PersonType);
113
+ * // PersonTreeType.fields = { name: DataRefType, age: DataRefType }
114
+ * ```
115
+ */
116
+ export function DataTreeType<T extends EastType>(type: T): DataTreeType<T> {
117
+ if (type.type === "Struct") {
118
+ const fields: Record<string, DataRefType> = {};
119
+ for (const key of Object.keys(type.fields)) {
120
+ fields[key] = DataRefType;
121
+ }
122
+ return StructType(fields) as DataTreeType<T>;
123
+ } else {
124
+ throw new Error(`DataTreeType not implemented for type .${type.type}`);
125
+ }
126
+ }