@elaraai/e3-types 1.0.108 → 1.0.110

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 (68) hide show
  1. package/dist/src/api.d.ts +382 -17
  2. package/dist/src/api.d.ts.map +1 -1
  3. package/dist/src/api.js +201 -17
  4. package/dist/src/api.js.map +1 -1
  5. package/dist/src/environment.d.ts +95 -8
  6. package/dist/src/environment.d.ts.map +1 -1
  7. package/dist/src/environment.js +102 -9
  8. package/dist/src/environment.js.map +1 -1
  9. package/dist/src/environment.spec.js +31 -19
  10. package/dist/src/environment.spec.js.map +1 -1
  11. package/dist/src/function-call.d.ts +91 -13
  12. package/dist/src/function-call.d.ts.map +1 -1
  13. package/dist/src/function-call.js +48 -4
  14. package/dist/src/function-call.js.map +1 -1
  15. package/dist/src/function-draft.d.ts +80 -0
  16. package/dist/src/function-draft.d.ts.map +1 -0
  17. package/dist/src/function-draft.js +71 -0
  18. package/dist/src/function-draft.js.map +1 -0
  19. package/dist/src/function-draft.spec.d.ts +6 -0
  20. package/dist/src/function-draft.spec.d.ts.map +1 -0
  21. package/dist/src/function-draft.spec.js +58 -0
  22. package/dist/src/function-draft.spec.js.map +1 -0
  23. package/dist/src/function.d.ts +45 -8
  24. package/dist/src/function.d.ts.map +1 -1
  25. package/dist/src/function.js +40 -7
  26. package/dist/src/function.js.map +1 -1
  27. package/dist/src/function.spec.d.ts +6 -0
  28. package/dist/src/function.spec.d.ts.map +1 -0
  29. package/dist/src/function.spec.js +61 -0
  30. package/dist/src/function.spec.js.map +1 -0
  31. package/dist/src/index.d.ts +7 -6
  32. package/dist/src/index.d.ts.map +1 -1
  33. package/dist/src/index.js +9 -7
  34. package/dist/src/index.js.map +1 -1
  35. package/dist/src/record.d.ts +81 -29
  36. package/dist/src/record.d.ts.map +1 -1
  37. package/dist/src/record.js +92 -22
  38. package/dist/src/record.js.map +1 -1
  39. package/dist/src/release.d.ts +1 -1
  40. package/dist/src/release.js +1 -1
  41. package/dist/src/structure.d.ts +18 -0
  42. package/dist/src/structure.d.ts.map +1 -1
  43. package/dist/src/structure.js +20 -0
  44. package/dist/src/structure.js.map +1 -1
  45. package/dist/src/structure.spec.js +8 -1
  46. package/dist/src/structure.spec.js.map +1 -1
  47. package/dist/src/task.d.ts +15 -2
  48. package/dist/src/task.d.ts.map +1 -1
  49. package/dist/src/task.js +14 -2
  50. package/dist/src/task.js.map +1 -1
  51. package/dist/src/task.spec.js +19 -2
  52. package/dist/src/task.spec.js.map +1 -1
  53. package/package.json +2 -2
  54. package/src/api.ts +215 -17
  55. package/src/environment.spec.ts +42 -21
  56. package/src/environment.ts +109 -9
  57. package/src/function-call.ts +52 -4
  58. package/src/function-draft.spec.ts +69 -0
  59. package/src/function-draft.ts +96 -0
  60. package/src/function.spec.ts +66 -0
  61. package/src/function.ts +44 -7
  62. package/src/index.ts +38 -2
  63. package/src/record.ts +97 -24
  64. package/src/release.ts +1 -1
  65. package/src/structure.spec.ts +9 -1
  66. package/src/structure.ts +21 -0
  67. package/src/task.spec.ts +20 -2
  68. package/src/task.ts +14 -2
package/src/function.ts CHANGED
@@ -9,8 +9,10 @@
9
9
  * An `e3.function` is a named, typed function stored in a package and
10
10
  * invoked by name with argument values over the CLI and HTTP API. It may
11
11
  * read datasets of the workspace a call runs through — its inputs — beside
12
- * the arguments its caller passes. Unlike a task it is not part of the
13
- * dataflow graph, and triggers no recomputation.
12
+ * the arguments its caller passes, and name the records among them a call
13
+ * may pass drafts of: mutation calls that are not committed, laid over the
14
+ * record for that call alone. Unlike a task it is not part of the dataflow
15
+ * graph, and triggers no recomputation.
14
16
  *
15
17
  * The function object stores its signature explicitly so `describe` and
16
18
  * arity/type validation work from the small function object without
@@ -20,7 +22,36 @@
20
22
 
21
23
  import { StructType, StringType, ArrayType, EastTypeType, OptionType, ValueTypeOf, decodeBeast2For } from '@elaraai/east';
22
24
  import { RunnerType } from './runner.js';
23
- import { TreePathType } from './structure.js';
25
+ import { TreePathType, pathToString } from './structure.js';
26
+
27
+ /**
28
+ * What a function reads from the workspace a call runs in: a dataset, or an
29
+ * index of a record, which is read through the record's dataset.
30
+ *
31
+ * @property path - The dataset's path: for an index, its record's
32
+ * @property index - The index of the record at `path` the input reads, by its
33
+ * name on the record: the body is given the index's entries,
34
+ * `Dict<{ ik, k }, P>`, at the state the record is pinned at. `none` for the
35
+ * dataset itself
36
+ */
37
+ export const FunctionInputType = StructType({
38
+ path: TreePathType,
39
+ index: OptionType(StringType),
40
+ });
41
+ export type FunctionInputType = typeof FunctionInputType;
42
+ export type FunctionInput = ValueTypeOf<typeof FunctionInputType>;
43
+
44
+ /**
45
+ * An input as a message names it: its dataset's keypath, or, for an index of a
46
+ * record, the index and its record's keypath.
47
+ *
48
+ * @param input - The input: a function's, a task's, or one a call read
49
+ * @returns `.inputs.prices`, or `the index jobs_by_press of .records.jobs`
50
+ */
51
+ export function inputLabel(input: Pick<FunctionInput, 'path' | 'index'>): string {
52
+ const at = pathToString(input.path);
53
+ return input.index.type === 'some' ? `the index ${input.index.value} of ${at}` : at;
54
+ }
24
55
 
25
56
  /**
26
57
  * Function object stored in the object store, referenced by name from
@@ -31,10 +62,16 @@ export const FunctionObjectType = StructType({
31
62
  * Its parameters are the inputs' types, in `inputs` order, then
32
63
  * `argTypes`. */
33
64
  bodyIr: StringType,
34
- /** The datasets a call reads from the workspace it runs in, each pinned at
35
- * its hash when the call launches and passed before the caller's
36
- * arguments; empty for a function that reads none. */
37
- inputs: ArrayType(TreePathType),
65
+ /** What a call reads from the workspace it runs in ({@link FunctionInputType}):
66
+ * each dataset pinned at its hash when the call launches and passed before
67
+ * the caller's arguments, the inputs of one record — the record and any of
68
+ * its indexes — at one state of it; empty for a function that reads none. */
69
+ inputs: ArrayType(FunctionInputType),
70
+ /** The records a call may pass drafts of, by name: each a record one of
71
+ * `inputs` reads, which the call then reads with its drafts laid over it.
72
+ * A call that passes a draft of any other record is `invalid`; empty for a
73
+ * function that takes none. */
74
+ drafts: ArrayType(StringType),
38
75
  /** The types of the arguments a caller passes, after the inputs, surfaced
39
76
  * for arity/type validation and `describe` without decoding the whole
40
77
  * IR. */
package/src/index.ts CHANGED
@@ -75,6 +75,9 @@ export {
75
75
  type ToolsEnvironment,
76
76
  WorkspaceNodeEnvironmentType,
77
77
  type WorkspaceNodeEnvironment,
78
+ WorkspacePythonEnvironmentType,
79
+ type WorkspacePythonEnvironment,
80
+ decodeEnvironmentSpec,
78
81
  environmentSpecObjectHashes,
79
82
  } from './environment.js';
80
83
 
@@ -91,6 +94,7 @@ export {
91
94
  type ParsePackageRefResult,
92
95
  treePath,
93
96
  pathToString,
97
+ treePathToRefPath,
94
98
  parsePath,
95
99
  parseKeypath,
96
100
  parseDatasetPath,
@@ -107,6 +111,9 @@ export {
107
111
 
108
112
  // Function objects
109
113
  export {
114
+ FunctionInputType,
115
+ type FunctionInput,
116
+ inputLabel,
110
117
  FunctionObjectType,
111
118
  type FunctionObject,
112
119
  decodeFunctionObject,
@@ -118,6 +125,8 @@ export {
118
125
  type FunctionCallCancel,
119
126
  FunctionCallKeepType,
120
127
  type FunctionCallKeep,
128
+ FunctionCallDraftedType,
129
+ type FunctionCallDrafted,
121
130
  FunctionCallJobType,
122
131
  type FunctionCallJob,
123
132
  encodeFunctionCallJob,
@@ -125,6 +134,15 @@ export {
125
134
  functionCallRoots,
126
135
  } from './function-call.js';
127
136
 
137
+ // How a call says which of its drafts ended it
138
+ export {
139
+ functionDraftLabel,
140
+ functionDraftEndLine,
141
+ functionDraftEnded,
142
+ functionDraftsLaidLine,
143
+ functionDraftsOutlasted,
144
+ } from './function-draft.js';
145
+
128
146
  // Record objects
129
147
  export {
130
148
  RecordCommitType,
@@ -149,8 +167,12 @@ export {
149
167
  type RecordNestedRun,
150
168
  RecordNestedPathType,
151
169
  type RecordNestedPath,
152
- RecordNestedItemType,
153
- type RecordNestedItem,
170
+ NestedIdType,
171
+ NestedPathType,
172
+ NestedItemType,
173
+ nestedIdCase,
174
+ nestedPathCases,
175
+ nestedPathValue,
154
176
  NestedEntryKeyType,
155
177
  NestedSpanKeyType,
156
178
  nestedSpanName,
@@ -446,7 +468,13 @@ export {
446
468
  ExecuteLimitsType,
447
469
  DiagnosticType,
448
470
  ExecuteResultType,
471
+ InputReadType,
449
472
  CallArgType,
473
+ FunctionDraftType,
474
+ FunctionDraftConflictType,
475
+ FunctionDraftedType,
476
+ FunctionDraftFailureType,
477
+ FunctionDraftEndType,
450
478
  FunctionCallRequestType,
451
479
  FunctionSignatureType,
452
480
  OneShotRequestType,
@@ -459,6 +487,7 @@ export {
459
487
  // Function calls, kept for a lifetime
460
488
  FunctionCallStateType,
461
489
  FunctionCallArgType,
490
+ FunctionCallDraftType,
462
491
  FunctionCallSummaryType,
463
492
  FunctionCallType,
464
493
  FunctionCallStatusType,
@@ -534,7 +563,13 @@ export {
534
563
  type ExecuteLimits,
535
564
  type Diagnostic,
536
565
  type ExecuteResult,
566
+ type InputRead,
537
567
  type CallArg,
568
+ type FunctionDraft,
569
+ type FunctionDraftConflict,
570
+ type FunctionDrafted,
571
+ type FunctionDraftFailure,
572
+ type FunctionDraftEnd,
538
573
  type FunctionCallRequest,
539
574
  type FunctionSignature,
540
575
  type OneShotRequest,
@@ -545,6 +580,7 @@ export {
545
580
  type SplitCallPlan,
546
581
  type FunctionCallState,
547
582
  type FunctionCallArg,
583
+ type FunctionCallDraft,
548
584
  type FunctionCallSummary,
549
585
  type FunctionCall,
550
586
  type FunctionCallStatus,
package/src/record.ts CHANGED
@@ -21,7 +21,7 @@
21
21
  import {
22
22
  ArrayType, BooleanType, DateTimeType, DictType, EastTypeType, FloatType, FunctionType, IntegerType, NullType,
23
23
  OptionType, PatchType, RecursiveType, StringType, StructType, VariantType,
24
- decodeBeast2For, dictPatchOpsType, setPatchOpsType, toEastTypeValue,
24
+ decodeBeast2For, dictPatchOpsType, setPatchOpsType, toEastTypeValue, variant,
25
25
  type EastType, type EastTypeValue, type PatchTypeOf, type ValueTypeOf,
26
26
  } from '@elaraai/east';
27
27
  import { RunnerType } from './runner.js';
@@ -242,14 +242,14 @@ export type RecordNestedRunType = typeof RecordNestedRunType;
242
242
  export type RecordNestedRun = ValueTypeOf<typeof RecordNestedRunType>;
243
243
 
244
244
  /**
245
- * A path in a nested series index's key (#1434): field names, or Dict keys,
246
- * from a row down — `end` for none, else one `step` and the rest. A key holds
247
- * no Array, which East may change in place, so a path is this list: it is
248
- * immutable, and it sorts as an Array of its names would, a path before every
249
- * path it leads (`[] < ["a"] < ["a", "b"] < ["b"]`).
245
+ * A collection's place in a nested series index's key (#1434): the field
246
+ * names from a row down to it — `end` for none, else one `step` and the rest.
247
+ * A key holds no Array, which East may change in place, so a place is this
248
+ * list: it is immutable, and it sorts as an Array of its names would, a place
249
+ * before every place it leads (`[] < ["a"] < ["a", "b"] < ["b"]`).
250
250
  *
251
251
  * @property end - No more names
252
- * @property step - One name, and the path after it
252
+ * @property step - One name, and the place after it
253
253
  */
254
254
  export const RecordNestedPathType = RecursiveType((self) => VariantType({
255
255
  end: NullType,
@@ -259,43 +259,116 @@ export type RecordNestedPathType = typeof RecordNestedPathType;
259
259
  export type RecordNestedPath = ValueTypeOf<typeof RecordNestedPathType>;
260
260
 
261
261
  /**
262
- * Which item a nested series index's entry is (#1434).
262
+ * The name a nested series index's key names a collection of child rows or of
263
+ * items by, among its ids (#1540): its place's field names, joined — `members`,
264
+ * `members.tasks`. A declared field's name holds no `.`, so no two places
265
+ * share one.
263
266
  *
267
+ * @param place - The collection's place: the field names from the row down to it, a recursive step adding none
268
+ * @returns Its case of the index's ids
269
+ */
270
+ export function nestedIdCase(place: readonly string[]): string {
271
+ return place.join('.');
272
+ }
273
+
274
+ /**
275
+ * The case each step of a path down to a collection names its child rows' keys under (#1540): at each of its place's
276
+ * fields but the last, the place so far ({@link nestedIdCase}) — a tree's further steps under the last of them. What
277
+ * a reader is given a node's path in, and what reads one back, both ask here.
278
+ *
279
+ * @param place - The collection's place: the field names from the row down to it
280
+ * @returns Each step's case, from the row down; none for a collection of the row itself
281
+ */
282
+ export function nestedPathCases(place: readonly string[]): string[] {
283
+ return place.slice(0, -1).map((_, i) => nestedIdCase(place.slice(0, i + 1)));
284
+ }
285
+
286
+ /**
287
+ * A path as a nested series index's key holds it (#1540): `step { key, rest }` from the first, `end` after the last —
288
+ * a collection's place by its field names ({@link RecordNestedPathType}), or a node's path by its ids.
289
+ *
290
+ * @param keys - The path's steps, from the row down
291
+ * @returns The path, as a key's value
292
+ */
293
+ export function nestedPathValue(keys: readonly unknown[]): unknown {
294
+ return keys.reduceRight<unknown>((rest, key) => variant('step', { key, rest }), variant('end', null));
295
+ }
296
+
297
+ /**
298
+ * The ids a nested series index's key holds (#1540): a child row's key, on the
299
+ * way from a row down to a node, and an item's id — each in its own type, under
300
+ * the case of the collection it is a key of ({@link nestedIdCase}). An index of
301
+ * values alone has no id, and its variant no case.
302
+ *
303
+ * @param ids - Each collection of child rows or of items, by its case, and its Dict's key type
304
+ * @returns The ids' variant type
305
+ */
306
+ export function NestedIdType(ids: Readonly<Record<string, EastType>>) {
307
+ return VariantType(ids);
308
+ }
309
+
310
+ /**
311
+ * The path in a nested series index's key (#1434, #1540): the child rows' keys
312
+ * from a row down to a node, each an id of the index's ({@link NestedIdType}) —
313
+ * `end` for the row itself, else one `step` and the rest. A key holds no
314
+ * Array, so a path is this list, which sorts as an Array of its ids would: a
315
+ * path before every path it leads.
316
+ *
317
+ * @param id - The index's ids
318
+ * @returns The path's type
319
+ */
320
+ export function NestedPathType<I extends EastType>(id: I) {
321
+ return RecursiveType((self) => VariantType({
322
+ end: NullType,
323
+ step: StructType({ key: id, rest: self }),
324
+ }));
325
+ }
326
+
327
+ /**
328
+ * Which item a nested series index's entry is (#1434), given the path of its
329
+ * index ({@link NestedPathType}).
330
+ *
331
+ * @param id - The index's ids
332
+ * @param path - The index's path type, over those ids
333
+ * @returns The item's variant type
264
334
  * @property id - An item, by its id
265
335
  * @property at - A value, by its instant
266
- * @property under - A descendant's item filed under an ancestor: the Dict keys
267
- * from the ancestor down to the node holding it, and its id
336
+ * @property under - A descendant's item filed under an ancestor: the child rows' keys from the ancestor down to the
337
+ * node holding it, and its id
268
338
  * @property none - A total or a subtotal, of which a node has one a tile a run
269
339
  */
270
- export const RecordNestedItemType = VariantType({
271
- id: StringType,
272
- at: DateTimeType,
273
- under: StructType({ path: RecordNestedPathType, id: StringType }),
274
- none: NullType,
275
- });
276
- export type RecordNestedItemType = typeof RecordNestedItemType;
277
- export type RecordNestedItem = ValueTypeOf<typeof RecordNestedItemType>;
340
+ export function NestedItemType<I extends EastType, P extends EastType>(id: I, path: P) {
341
+ return VariantType({
342
+ id,
343
+ at: DateTimeType,
344
+ under: StructType({ path, id }),
345
+ none: NullType,
346
+ });
347
+ }
278
348
 
279
349
  /**
280
350
  * The key a nested series index files an entry under (#1434): its
281
351
  * collection, its row, the node it is about, its run, its level and tile, and
282
352
  * the item — in that order, so a node's run at one level is one contiguous
283
- * range across tiles.
353
+ * range across tiles. A child row's key and an item's id are held in their own
354
+ * types (#1540), never as text.
284
355
  *
285
356
  * @param rowKey - The record's key type
357
+ * @param id - The index's ids ({@link NestedIdType})
286
358
  * @returns The entry key's struct type
287
359
  * @property collection - The collection's place: the field names from the row down to it, a recursive step adding none
288
360
  * @property row - The record row's key
289
- * @property path - The Dict keys from the row down to the node the entry is about: `end` for the row itself
361
+ * @property path - The child rows' keys from the row down to the node the entry is about: `end` for the row itself
290
362
  * @property run - Which of the node's runs ({@link RecordNestedRunType})
291
363
  * @property level - The level the entry is filed at; a total's, the summary tile's
292
364
  * @property tile - The start of the level's tile
293
- * @property item - Which item ({@link RecordNestedItemType})
365
+ * @property item - Which item ({@link NestedItemType})
294
366
  */
295
- export function NestedEntryKeyType<K extends EastType>(rowKey: K) {
367
+ export function NestedEntryKeyType<K extends EastType, I extends EastType>(rowKey: K, id: I) {
368
+ const path = NestedPathType(id);
296
369
  return StructType({
297
- collection: RecordNestedPathType, row: rowKey, path: RecordNestedPathType,
298
- run: RecordNestedRunType, level: RecordLevelType, tile: DateTimeType, item: RecordNestedItemType,
370
+ collection: RecordNestedPathType, row: rowKey, path,
371
+ run: RecordNestedRunType, level: RecordLevelType, tile: DateTimeType, item: NestedItemType(id, path),
299
372
  });
300
373
  }
301
374
 
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.108';
20
+ export const E3_RELEASE = '1.0.110';
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-]+)*)?$/;
@@ -12,7 +12,7 @@
12
12
  import { describe, it } from 'node:test';
13
13
  import assert from 'node:assert/strict';
14
14
  import { IntegerType, equalFor, printFor, toEastTypeValue, variant } from '@elaraai/east';
15
- import { TreePathType, parseKeypath, parsePath, pathToString, type Structure, type TreePath } from './structure.js';
15
+ import { TreePathType, parseKeypath, parsePath, pathToString, treePathToRefPath, type Structure, type TreePath } from './structure.js';
16
16
 
17
17
  const equalPath = equalFor(TreePathType);
18
18
  const printPath = printFor(TreePathType);
@@ -44,6 +44,14 @@ describe('parseKeypath', () => {
44
44
  });
45
45
  });
46
46
 
47
+ describe('treePathToRefPath', () => {
48
+ it('joins a path\'s fields by a slash, unquoted, as a store keys a dataset\'s ref', () => {
49
+ assert.equal(treePathToRefPath([variant('field', 'inputs'), variant('field', 'sales')]), 'inputs/sales');
50
+ assert.equal(treePathToRefPath([variant('field', 'records'), variant('field', 'my field')]), 'records/my field');
51
+ assert.equal(treePathToRefPath([]), '', 'the root\'s');
52
+ });
53
+ });
54
+
47
55
  describe('parsePath', () => {
48
56
  const structure: Structure = variant('struct', new Map([
49
57
  ['inputs', variant('struct', new Map([
package/src/structure.ts CHANGED
@@ -132,6 +132,27 @@ export function pathToString(path: TreePath): string {
132
132
  return path.map(segment => '.' + printIdentifier(segment.value)).join('');
133
133
  }
134
134
 
135
+ /**
136
+ * A dataset's ref path, as a store keys its ref and a package's data names
137
+ * it: its fields joined by `/`, unquoted.
138
+ *
139
+ * @remarks
140
+ * The one place e3 makes the key, which the authoring package's export, every
141
+ * store, every reader of a ref and everything that matches a path to a
142
+ * record's ref share.
143
+ *
144
+ * @param path - The dataset's path
145
+ * @returns Its ref path (e.g. `inputs/sales` for `.inputs.sales`)
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * treePathToRefPath([variant('field', 'records'), variant('field', 'jobs')]); // 'records/jobs'
150
+ * ```
151
+ */
152
+ export function treePathToRefPath(path: TreePath): string {
153
+ return path.map((segment) => segment.value).join('/');
154
+ }
155
+
135
156
  /**
136
157
  * Result of parsing a path with structure validation.
137
158
  */
package/src/task.spec.ts CHANGED
@@ -26,12 +26,13 @@ import { TreePathType } from './structure.js';
26
26
  describe('TaskObjectType', () => {
27
27
  const sales = [variant('field', 'inputs'), variant('field', 'sales')];
28
28
  const rates = [variant('field', 'inputs'), variant('field', 'rates')];
29
+ const jobs = [variant('field', 'records'), variant('field', 'jobs')];
29
30
  const totals = [variant('field', 'tasks'), variant('field', 'totals'), variant('field', 'output')];
30
31
  const base: TaskObject = {
31
32
  kind: TASK_OBJECT_KIND,
32
33
  body: variant('east', { program: 'a'.repeat(64) }),
33
34
  runner: variant('east_node', { platforms: ['@elaraai/east-node-std'], decode: variant('lazy', null) }),
34
- inputs: [{ path: sales, partition: none }],
35
+ inputs: [{ path: sales, index: none, partition: none }],
35
36
  output: { path: totals, kind: variant('value', null) },
36
37
  role: variant('data', null),
37
38
  environment: none,
@@ -48,13 +49,15 @@ describe('TaskObjectType', () => {
48
49
  },
49
50
  {
50
51
  ...base,
51
- inputs: [{ path: sales, partition: some({ by: ['account', 'at.day'] }) }, { path: rates, partition: none }],
52
+ inputs: [{ path: sales, index: none, partition: some({ by: ['account', 'at.day'] }) }, { path: rates, index: none, partition: none }],
52
53
  output: { path: totals, kind: variant('dict', { merge: some('d'.repeat(64)) }) },
53
54
  },
54
55
  { ...base, output: { path: totals, kind: variant('fold', { zero: 'e'.repeat(64), combine: 'f'.repeat(64) }) } },
55
56
  { ...base, output: { path: totals, kind: variant('set', null) } },
56
57
  { ...base, runner: variant('east_py', { platforms: ['east-py-std'], decode: variant('whole', null) }) },
57
58
  { ...base, role: variant('ui', { paths: [sales], functions: ['forecast'], records: ['plans'], pages: [rates] }) },
59
+ // An index of a record, read beside the record itself
60
+ { ...base, inputs: [{ path: jobs, index: some('jobs_by_press'), partition: none }, { path: jobs, index: none, partition: none }] },
58
61
  ];
59
62
  const encode = encodeBeast2For(TaskObjectType);
60
63
  for (const original of tasks) assert.deepEqual(decodeTaskObject(encode(original)), original);
@@ -103,6 +106,21 @@ describe('TaskObjectType', () => {
103
106
  assert.throws(() => decodeTaskObject(older), /exported by an older e3 SDK — re-export it with the current one/);
104
107
  });
105
108
 
109
+ it('refuses a task object whose inputs predate the index they may name, saying to re-export the package', () => {
110
+ // An input as a package exported before an input could be an index of a
111
+ // record: its path and its partition alone.
112
+ const older = encodeBeast2For(StructType({
113
+ kind: StringType,
114
+ body: TaskBodyType,
115
+ runner: RunnerType,
116
+ inputs: ArrayType(StructType({ path: TreePathType, partition: TaskInputType.fields.partition })),
117
+ output: TaskOutputType,
118
+ role: TaskRoleType,
119
+ environment: OptionType(StringType),
120
+ }))({ ...base, inputs: [{ path: sales, partition: none }] });
121
+ assert.throws(() => decodeTaskObject(older), /exported by an older e3 SDK — re-export it with the current one/);
122
+ });
123
+
106
124
  it('refuses an object of the task shape that carries another kind tag', () => {
107
125
  assert.throws(() => decodeTaskObject(encodeBeast2For(TaskObjectType)({ ...base, kind: '$plan' })), /its kind is '\$plan', not '\$task'/);
108
126
  });
package/src/task.ts CHANGED
@@ -48,9 +48,21 @@ export const TaskPartitionType = StructType({ by: ArrayType(StringType) });
48
48
  export type TaskPartitionType = typeof TaskPartitionType;
49
49
  export type TaskPartition = ValueTypeOf<typeof TaskPartitionType>;
50
50
 
51
- /** A dataset a task reads, and whether the work may be split over it. */
51
+ /**
52
+ * A dataset a task reads, and whether the work may be split over it; or an
53
+ * index of a record, which is read through the record's dataset.
54
+ *
55
+ * @property path - The dataset's path: for an index, its record's
56
+ * @property index - The index of the record at `path` the input reads, by its
57
+ * name on the record: the body is given the index's entries,
58
+ * `Dict<{ ik, k }, P>`, at the state the record holds. `none` for the dataset
59
+ * itself
60
+ * @property partition - How the work may be split over the input; `none` for
61
+ * one every piece reads whole, as an index always is
62
+ */
52
63
  export const TaskInputType = StructType({
53
64
  path: TreePathType,
65
+ index: OptionType(StringType),
54
66
  partition: OptionType(TaskPartitionType),
55
67
  });
56
68
  export type TaskInputType = typeof TaskInputType;
@@ -135,7 +147,7 @@ export type TaskRole = ValueTypeOf<typeof TaskRoleType>;
135
147
  * kind: TASK_OBJECT_KIND,
136
148
  * body: variant('east', { program: '5e7a3b...' }),
137
149
  * runner: variant('east_node', { platforms: ['@elaraai/east-node-std'], decode: variant('lazy', null) }),
138
- * inputs: [{ path: [variant('field', 'inputs'), variant('field', 'sales')], partition: none }],
150
+ * inputs: [{ path: [variant('field', 'inputs'), variant('field', 'sales')], index: none, partition: none }],
139
151
  * output: { path: [variant('field', 'tasks'), variant('field', 'totals'), variant('field', 'output')], kind: variant('value', null) },
140
152
  * role: variant('data', null),
141
153
  * environment: none,