@elaraai/e3-types 1.0.82 → 1.0.84

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 (47) hide show
  1. package/dist/src/api.d.ts +250 -2
  2. package/dist/src/api.d.ts.map +1 -1
  3. package/dist/src/api.js +94 -3
  4. package/dist/src/api.js.map +1 -1
  5. package/dist/src/execution.d.ts +8 -2
  6. package/dist/src/execution.d.ts.map +1 -1
  7. package/dist/src/execution.js +12 -2
  8. package/dist/src/execution.js.map +1 -1
  9. package/dist/src/execution.spec.js +5 -0
  10. package/dist/src/execution.spec.js.map +1 -1
  11. package/dist/src/function.d.ts +12 -0
  12. package/dist/src/function.d.ts.map +1 -1
  13. package/dist/src/index.d.ts +2 -2
  14. package/dist/src/index.d.ts.map +1 -1
  15. package/dist/src/index.js +4 -2
  16. package/dist/src/index.js.map +1 -1
  17. package/dist/src/record.d.ts +52 -0
  18. package/dist/src/record.d.ts.map +1 -1
  19. package/dist/src/record.js +25 -0
  20. package/dist/src/record.js.map +1 -1
  21. package/dist/src/record.spec.js +43 -6
  22. package/dist/src/record.spec.js.map +1 -1
  23. package/dist/src/release.d.ts +1 -1
  24. package/dist/src/release.js +1 -1
  25. package/dist/src/runner.d.ts +22 -7
  26. package/dist/src/runner.d.ts.map +1 -1
  27. package/dist/src/runner.js +14 -11
  28. package/dist/src/runner.js.map +1 -1
  29. package/dist/src/runner.spec.js +4 -4
  30. package/dist/src/runner.spec.js.map +1 -1
  31. package/dist/src/task.d.ts +13 -1
  32. package/dist/src/task.d.ts.map +1 -1
  33. package/dist/src/task.js +1 -1
  34. package/dist/src/task.spec.js +25 -4
  35. package/dist/src/task.spec.js.map +1 -1
  36. package/package.json +2 -2
  37. package/src/api.ts +104 -3
  38. package/src/execution.spec.ts +7 -0
  39. package/src/execution.ts +12 -2
  40. package/src/index.ts +12 -0
  41. package/src/record.spec.ts +51 -5
  42. package/src/record.ts +28 -0
  43. package/src/release.ts +1 -1
  44. package/src/runner.spec.ts +4 -4
  45. package/src/runner.ts +14 -11
  46. package/src/task.spec.ts +29 -3
  47. package/src/task.ts +1 -1
package/src/record.ts CHANGED
@@ -200,6 +200,34 @@ export const RecordIndexObjectType = StructType({
200
200
  export type RecordIndexObjectType = typeof RecordIndexObjectType;
201
201
  export type RecordIndexObject = ValueTypeOf<typeof RecordIndexObjectType>;
202
202
 
203
+ const decodeCurrentRecordIndex = decodeBeast2For(RecordIndexObjectType);
204
+
205
+ /**
206
+ * Decode a `RecordIndexObject`.
207
+ *
208
+ * @remarks
209
+ * A package-borne wire, so it changes by hard cutover: a package exported by
210
+ * an older SDK is re-exported with the current one, and this says so. A
211
+ * record's state names the index object each index was built under, so one an
212
+ * older SDK exported is read until a deploy of the re-exported package
213
+ * rebuilds the index under the current one.
214
+ *
215
+ * @param data - the stored bytes
216
+ * @returns the index object
217
+ * @throws {Error} When the bytes are not a current index object — a package
218
+ * exported by an older SDK, which is re-exported with the current one.
219
+ */
220
+ export function decodeRecordIndexObject(data: Uint8Array): RecordIndexObject {
221
+ try {
222
+ return decodeCurrentRecordIndex(data);
223
+ } catch (err) {
224
+ throw new Error(
225
+ `the index object does not decode: the package was exported by an older e3 SDK — re-export it with the current one ` +
226
+ `(${err instanceof Error ? err.message : String(err)})`,
227
+ );
228
+ }
229
+ }
230
+
203
231
  /**
204
232
  * How a migration says what it changes.
205
233
  *
package/src/release.ts CHANGED
@@ -17,7 +17,7 @@
17
17
  */
18
18
 
19
19
  /** The release of e3 this build is. */
20
- export const E3_RELEASE = '1.0.82';
20
+ export const E3_RELEASE = '1.0.84';
21
21
 
22
22
  /** A semantic version: its core, a pre-release, and build metadata. */
23
23
  const RELEASE = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
@@ -18,9 +18,9 @@ import { variant } from '@elaraai/east';
18
18
  import { withRunnerLifeline, type RunnerValue } from './runner.js';
19
19
 
20
20
  const KNOWN: Array<[string, RunnerValue, string]> = [
21
- ['east_node', variant('east_node', { platforms: ['@elaraai/east-node-std'] }), 'east-node'],
22
- ['east_py', variant('east_py', { platforms: ['east-py-std'] }), 'east-py'],
23
- ['east_c', variant('east_c', { platforms: ['east-c-std'] }), 'east-c'],
21
+ ['east_node', variant('east_node', { platforms: ['@elaraai/east-node-std'], decode: variant('lazy', null) }), 'east-node'],
22
+ ['east_py', variant('east_py', { platforms: ['east-py-std'], decode: variant('lazy', null) }), 'east-py'],
23
+ ['east_c', variant('east_c', { platforms: ['east-c-std'], decode: variant('lazy', null) }), 'east-c'],
24
24
  ];
25
25
 
26
26
  describe('withRunnerLifeline', () => {
@@ -38,7 +38,7 @@ describe('withRunnerLifeline', () => {
38
38
  });
39
39
 
40
40
  it('is a no-op on a degenerate argv and does not mutate its input', () => {
41
- const runner = variant('east_c', { platforms: [] });
41
+ const runner = variant('east_c', { platforms: [], decode: variant('lazy', null) });
42
42
  assert.deepStrictEqual(withRunnerLifeline(runner, ['east-c']), ['east-c']);
43
43
  const args = ['east-c', 'exec', 'unit.beast2'];
44
44
  const before = [...args];
package/src/runner.ts CHANGED
@@ -11,23 +11,26 @@
11
11
  * its `exec` command; `custom` names a command of the author's own.
12
12
  */
13
13
 
14
- import { VariantType, StructType, ArrayType, StringType, ValueTypeOf } from '@elaraai/east';
14
+ import { VariantType, StructType, ArrayType, StringType, UnitDecodeType, ValueTypeOf } from '@elaraai/east';
15
15
 
16
16
  /**
17
17
  * Wire representation of a runner — shared by tasks, functions and records.
18
18
  *
19
- * A known-runtime tag names a stock runner, and `platforms` names the platform
20
- * packages the units it runs load. `custom` carries a command, which e3 runs
21
- * with the arguments of a stock runner's `run`: `-i` for each input, `-o` for
22
- * the output, then the program's file. A custom task's body is its own
23
- * command, and its runner's is empty. Package authors can already execute
24
- * arbitrary commands via custom tasks, so `custom` grants no capability that
25
- * tasks don't have.
19
+ * A known-runtime tag names a stock runner: `platforms` names the platform
20
+ * packages the units it runs load, and `decode` how it reads a run unit's
21
+ * inputs — each collection `lazy`, a segment decoded as the program reaches
22
+ * it, or every input decoded `whole` before the program runs — which e3 writes
23
+ * into each run unit it stages for the runner. `custom` carries a command,
24
+ * which e3 runs with the arguments of a stock runner's `run`: `-i` for each
25
+ * input, `-o` for the output, then the program's file. A custom task's body is
26
+ * its own command, and its runner's is empty. Package authors can already
27
+ * execute arbitrary commands via custom tasks, so `custom` grants no
28
+ * capability that tasks don't have.
26
29
  */
27
30
  export const RunnerType = VariantType({
28
- east_node: StructType({ platforms: ArrayType(StringType) }),
29
- east_py: StructType({ platforms: ArrayType(StringType) }),
30
- east_c: StructType({ platforms: ArrayType(StringType) }),
31
+ east_node: StructType({ platforms: ArrayType(StringType), decode: UnitDecodeType }),
32
+ east_py: StructType({ platforms: ArrayType(StringType), decode: UnitDecodeType }),
33
+ east_c: StructType({ platforms: ArrayType(StringType), decode: UnitDecodeType }),
31
34
  custom: StructType({ command: ArrayType(StringType) }),
32
35
  });
33
36
  export type RunnerType = typeof RunnerType;
package/src/task.spec.ts CHANGED
@@ -9,10 +9,14 @@
9
9
 
10
10
  import { describe, it } from 'node:test';
11
11
  import assert from 'node:assert/strict';
12
- import { ArrayType, BlobType, IntegerType, OptionType, StringType, StructType, encodeBeast2For, none, some, variant } from '@elaraai/east';
12
+ import { ArrayType, BlobType, IntegerType, OptionType, StringType, StructType, VariantType, encodeBeast2For, none, some, variant } from '@elaraai/east';
13
13
  import {
14
14
  TASK_OBJECT_KIND,
15
+ TaskBodyType,
16
+ TaskInputType,
15
17
  TaskObjectType,
18
+ TaskOutputType,
19
+ TaskRoleType,
16
20
  decodeTaskObject,
17
21
  type TaskObject,
18
22
  } from './task.js';
@@ -26,7 +30,7 @@ describe('TaskObjectType', () => {
26
30
  const base: TaskObject = {
27
31
  kind: TASK_OBJECT_KIND,
28
32
  body: variant('east', { program: 'a'.repeat(64) }),
29
- runner: variant('east_node', { platforms: ['@elaraai/east-node-std'] }),
33
+ runner: variant('east_node', { platforms: ['@elaraai/east-node-std'], decode: variant('lazy', null) }),
30
34
  inputs: [{ path: sales, partition: none }],
31
35
  output: { path: totals, kind: variant('value', null) },
32
36
  role: variant('data', null),
@@ -49,6 +53,7 @@ describe('TaskObjectType', () => {
49
53
  },
50
54
  { ...base, output: { path: totals, kind: variant('fold', { zero: 'e'.repeat(64), combine: 'f'.repeat(64) }) } },
51
55
  { ...base, output: { path: totals, kind: variant('set', null) } },
56
+ { ...base, runner: variant('east_py', { platforms: ['east-py-std'], decode: variant('whole', null) }) },
52
57
  { ...base, role: variant('ui', { paths: [sales], functions: ['forecast'], records: ['plans'], pages: [rates] }) },
53
58
  ];
54
59
  const encode = encodeBeast2For(TaskObjectType);
@@ -71,12 +76,33 @@ describe('TaskObjectType', () => {
71
76
  output: totals,
72
77
  kind: none,
73
78
  metadata: none,
74
- runner: variant('east_node', { platforms: [] }),
79
+ runner: variant('east_node', { platforms: [], decode: variant('lazy', null) }),
75
80
  environment: none,
76
81
  });
77
82
  assert.throws(() => decodeTaskObject(older), /exported by an older e3 SDK — re-export it with the current one/);
78
83
  });
79
84
 
85
+ it('refuses a task object whose runner predates its decode, saying to re-export the package', () => {
86
+ // A stock runner as a package exported before runners said how they read
87
+ // a program's inputs: its platforms alone.
88
+ const PreDecodeRunnerType = VariantType({
89
+ east_node: StructType({ platforms: ArrayType(StringType) }),
90
+ east_py: StructType({ platforms: ArrayType(StringType) }),
91
+ east_c: StructType({ platforms: ArrayType(StringType) }),
92
+ custom: StructType({ command: ArrayType(StringType) }),
93
+ });
94
+ const older = encodeBeast2For(StructType({
95
+ kind: StringType,
96
+ body: TaskBodyType,
97
+ runner: PreDecodeRunnerType,
98
+ inputs: ArrayType(TaskInputType),
99
+ output: TaskOutputType,
100
+ role: TaskRoleType,
101
+ environment: OptionType(StringType),
102
+ }))({ ...base, runner: variant('east_node', { platforms: ['@elaraai/east-node-std'] }) });
103
+ assert.throws(() => decodeTaskObject(older), /exported by an older e3 SDK — re-export it with the current one/);
104
+ });
105
+
80
106
  it('refuses an object of the task shape that carries another kind tag', () => {
81
107
  assert.throws(() => decodeTaskObject(encodeBeast2For(TaskObjectType)({ ...base, kind: '$plan' })), /its kind is '\$plan', not '\$task'/);
82
108
  });
package/src/task.ts CHANGED
@@ -132,7 +132,7 @@ export type TaskRole = ValueTypeOf<typeof TaskRoleType>;
132
132
  * const task: TaskObject = {
133
133
  * kind: TASK_OBJECT_KIND,
134
134
  * body: variant('east', { program: '5e7a3b...' }),
135
- * runner: variant('east_node', { platforms: ['@elaraai/east-node-std'] }),
135
+ * runner: variant('east_node', { platforms: ['@elaraai/east-node-std'], decode: variant('lazy', null) }),
136
136
  * inputs: [{ path: [variant('field', 'inputs'), variant('field', 'sales')], partition: none }],
137
137
  * output: { path: [variant('field', 'tasks'), variant('field', 'totals'), variant('field', 'output')], kind: variant('value', null) },
138
138
  * role: variant('data', null),