@elaraai/e3-types 1.0.108 → 1.0.109
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.
- package/dist/src/api.d.ts +382 -17
- package/dist/src/api.d.ts.map +1 -1
- package/dist/src/api.js +201 -17
- package/dist/src/api.js.map +1 -1
- package/dist/src/function-call.d.ts +91 -13
- package/dist/src/function-call.d.ts.map +1 -1
- package/dist/src/function-call.js +48 -4
- package/dist/src/function-call.js.map +1 -1
- package/dist/src/function-draft.d.ts +80 -0
- package/dist/src/function-draft.d.ts.map +1 -0
- package/dist/src/function-draft.js +71 -0
- package/dist/src/function-draft.js.map +1 -0
- package/dist/src/function-draft.spec.d.ts +6 -0
- package/dist/src/function-draft.spec.d.ts.map +1 -0
- package/dist/src/function-draft.spec.js +58 -0
- package/dist/src/function-draft.spec.js.map +1 -0
- package/dist/src/function.d.ts +45 -8
- package/dist/src/function.d.ts.map +1 -1
- package/dist/src/function.js +40 -7
- package/dist/src/function.js.map +1 -1
- package/dist/src/function.spec.d.ts +6 -0
- package/dist/src/function.spec.d.ts.map +1 -0
- package/dist/src/function.spec.js +61 -0
- package/dist/src/function.spec.js.map +1 -0
- package/dist/src/index.d.ts +6 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +8 -6
- package/dist/src/index.js.map +1 -1
- package/dist/src/record.d.ts +81 -29
- package/dist/src/record.d.ts.map +1 -1
- package/dist/src/record.js +92 -22
- package/dist/src/record.js.map +1 -1
- package/dist/src/release.d.ts +1 -1
- package/dist/src/release.js +1 -1
- package/dist/src/structure.d.ts +18 -0
- package/dist/src/structure.d.ts.map +1 -1
- package/dist/src/structure.js +20 -0
- package/dist/src/structure.js.map +1 -1
- package/dist/src/structure.spec.js +8 -1
- package/dist/src/structure.spec.js.map +1 -1
- package/dist/src/task.d.ts +15 -2
- package/dist/src/task.d.ts.map +1 -1
- package/dist/src/task.js +14 -2
- package/dist/src/task.js.map +1 -1
- package/dist/src/task.spec.js +19 -2
- package/dist/src/task.spec.js.map +1 -1
- package/package.json +2 -2
- package/src/api.ts +215 -17
- package/src/function-call.ts +52 -4
- package/src/function-draft.spec.ts +69 -0
- package/src/function-draft.ts +96 -0
- package/src/function.spec.ts +66 -0
- package/src/function.ts +44 -7
- package/src/index.ts +35 -2
- package/src/record.ts +97 -24
- package/src/release.ts +1 -1
- package/src/structure.spec.ts +9 -1
- package/src/structure.ts +21 -0
- package/src/task.spec.ts +20 -2
- package/src/task.ts +14 -2
|
@@ -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
|
+
/**
|
|
7
|
+
* Function object wire: the function object's round trip, with an input that
|
|
8
|
+
* is an index of a record, and its refusal of the form before it.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { describe, it } from 'node:test';
|
|
12
|
+
import assert from 'node:assert/strict';
|
|
13
|
+
import { ArrayType, EastTypeType, IntegerType, OptionType, StringType, StructType, encodeBeast2For, equalFor, none, some, toEastTypeValue, variant } from '@elaraai/east';
|
|
14
|
+
import { FunctionObjectType, decodeFunctionObject, type FunctionObject } from './function.js';
|
|
15
|
+
import { RunnerType } from './runner.js';
|
|
16
|
+
import { TreePathType } from './structure.js';
|
|
17
|
+
|
|
18
|
+
describe('FunctionObjectType', () => {
|
|
19
|
+
const jobs = [variant('field', 'records'), variant('field', 'jobs')];
|
|
20
|
+
const presses = [variant('field', 'inputs'), variant('field', 'presses')];
|
|
21
|
+
const base: FunctionObject = {
|
|
22
|
+
bodyIr: 'a'.repeat(64),
|
|
23
|
+
inputs: [],
|
|
24
|
+
drafts: [],
|
|
25
|
+
argTypes: [toEastTypeValue(StringType)],
|
|
26
|
+
outputType: toEastTypeValue(IntegerType),
|
|
27
|
+
runner: variant('east_c', { platforms: [], decode: variant('lazy', null) }),
|
|
28
|
+
environment: none,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
it('round-trips a function that reads nothing, datasets, and an index of a record beside the record', () => {
|
|
32
|
+
const functions: FunctionObject[] = [
|
|
33
|
+
base,
|
|
34
|
+
{ ...base, inputs: [{ path: presses, index: none }], environment: some('b'.repeat(64)) },
|
|
35
|
+
{
|
|
36
|
+
...base,
|
|
37
|
+
inputs: [{ path: jobs, index: some('jobs_by_press') }, { path: jobs, index: none }],
|
|
38
|
+
drafts: ['jobs'],
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
const encode = encodeBeast2For(FunctionObjectType);
|
|
42
|
+
const same = equalFor(FunctionObjectType);
|
|
43
|
+
for (const original of functions) {
|
|
44
|
+
assert.ok(same(decodeFunctionObject(encode(original)), original), `a function with ${original.inputs.length} inputs decodes as it was encoded`);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('refuses a function object whose inputs predate the index they may name, saying to re-export the package', () => {
|
|
49
|
+
// A function object as a package exported before an input could be an
|
|
50
|
+
// index of a record: each input its dataset's path alone.
|
|
51
|
+
const older = encodeBeast2For(StructType({
|
|
52
|
+
bodyIr: StringType,
|
|
53
|
+
inputs: ArrayType(TreePathType),
|
|
54
|
+
drafts: ArrayType(StringType),
|
|
55
|
+
argTypes: ArrayType(EastTypeType),
|
|
56
|
+
outputType: EastTypeType,
|
|
57
|
+
runner: RunnerType,
|
|
58
|
+
environment: OptionType(StringType),
|
|
59
|
+
}))({ ...base, inputs: [presses] });
|
|
60
|
+
assert.throws(() => decodeFunctionObject(older), /exported by an older e3 SDK — re-export it with the current one/);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('throws for bytes of no known function shape', () => {
|
|
64
|
+
assert.throws(() => decodeFunctionObject(encodeBeast2For(IntegerType)(7n)), /re-export/);
|
|
65
|
+
});
|
|
66
|
+
});
|
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
|
|
13
|
-
*
|
|
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
|
-
/**
|
|
35
|
-
* its hash when the call launches and passed before
|
|
36
|
-
* arguments
|
|
37
|
-
|
|
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
|
@@ -91,6 +91,7 @@ export {
|
|
|
91
91
|
type ParsePackageRefResult,
|
|
92
92
|
treePath,
|
|
93
93
|
pathToString,
|
|
94
|
+
treePathToRefPath,
|
|
94
95
|
parsePath,
|
|
95
96
|
parseKeypath,
|
|
96
97
|
parseDatasetPath,
|
|
@@ -107,6 +108,9 @@ export {
|
|
|
107
108
|
|
|
108
109
|
// Function objects
|
|
109
110
|
export {
|
|
111
|
+
FunctionInputType,
|
|
112
|
+
type FunctionInput,
|
|
113
|
+
inputLabel,
|
|
110
114
|
FunctionObjectType,
|
|
111
115
|
type FunctionObject,
|
|
112
116
|
decodeFunctionObject,
|
|
@@ -118,6 +122,8 @@ export {
|
|
|
118
122
|
type FunctionCallCancel,
|
|
119
123
|
FunctionCallKeepType,
|
|
120
124
|
type FunctionCallKeep,
|
|
125
|
+
FunctionCallDraftedType,
|
|
126
|
+
type FunctionCallDrafted,
|
|
121
127
|
FunctionCallJobType,
|
|
122
128
|
type FunctionCallJob,
|
|
123
129
|
encodeFunctionCallJob,
|
|
@@ -125,6 +131,15 @@ export {
|
|
|
125
131
|
functionCallRoots,
|
|
126
132
|
} from './function-call.js';
|
|
127
133
|
|
|
134
|
+
// How a call says which of its drafts ended it
|
|
135
|
+
export {
|
|
136
|
+
functionDraftLabel,
|
|
137
|
+
functionDraftEndLine,
|
|
138
|
+
functionDraftEnded,
|
|
139
|
+
functionDraftsLaidLine,
|
|
140
|
+
functionDraftsOutlasted,
|
|
141
|
+
} from './function-draft.js';
|
|
142
|
+
|
|
128
143
|
// Record objects
|
|
129
144
|
export {
|
|
130
145
|
RecordCommitType,
|
|
@@ -149,8 +164,12 @@ export {
|
|
|
149
164
|
type RecordNestedRun,
|
|
150
165
|
RecordNestedPathType,
|
|
151
166
|
type RecordNestedPath,
|
|
152
|
-
|
|
153
|
-
|
|
167
|
+
NestedIdType,
|
|
168
|
+
NestedPathType,
|
|
169
|
+
NestedItemType,
|
|
170
|
+
nestedIdCase,
|
|
171
|
+
nestedPathCases,
|
|
172
|
+
nestedPathValue,
|
|
154
173
|
NestedEntryKeyType,
|
|
155
174
|
NestedSpanKeyType,
|
|
156
175
|
nestedSpanName,
|
|
@@ -446,7 +465,13 @@ export {
|
|
|
446
465
|
ExecuteLimitsType,
|
|
447
466
|
DiagnosticType,
|
|
448
467
|
ExecuteResultType,
|
|
468
|
+
InputReadType,
|
|
449
469
|
CallArgType,
|
|
470
|
+
FunctionDraftType,
|
|
471
|
+
FunctionDraftConflictType,
|
|
472
|
+
FunctionDraftedType,
|
|
473
|
+
FunctionDraftFailureType,
|
|
474
|
+
FunctionDraftEndType,
|
|
450
475
|
FunctionCallRequestType,
|
|
451
476
|
FunctionSignatureType,
|
|
452
477
|
OneShotRequestType,
|
|
@@ -459,6 +484,7 @@ export {
|
|
|
459
484
|
// Function calls, kept for a lifetime
|
|
460
485
|
FunctionCallStateType,
|
|
461
486
|
FunctionCallArgType,
|
|
487
|
+
FunctionCallDraftType,
|
|
462
488
|
FunctionCallSummaryType,
|
|
463
489
|
FunctionCallType,
|
|
464
490
|
FunctionCallStatusType,
|
|
@@ -534,7 +560,13 @@ export {
|
|
|
534
560
|
type ExecuteLimits,
|
|
535
561
|
type Diagnostic,
|
|
536
562
|
type ExecuteResult,
|
|
563
|
+
type InputRead,
|
|
537
564
|
type CallArg,
|
|
565
|
+
type FunctionDraft,
|
|
566
|
+
type FunctionDraftConflict,
|
|
567
|
+
type FunctionDrafted,
|
|
568
|
+
type FunctionDraftFailure,
|
|
569
|
+
type FunctionDraftEnd,
|
|
538
570
|
type FunctionCallRequest,
|
|
539
571
|
type FunctionSignature,
|
|
540
572
|
type OneShotRequest,
|
|
@@ -545,6 +577,7 @@ export {
|
|
|
545
577
|
type SplitCallPlan,
|
|
546
578
|
type FunctionCallState,
|
|
547
579
|
type FunctionCallArg,
|
|
580
|
+
type FunctionCallDraft,
|
|
548
581
|
type FunctionCallSummary,
|
|
549
582
|
type FunctionCall,
|
|
550
583
|
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
|
|
246
|
-
* from a row down — `end` for none, else one `step` and the rest.
|
|
247
|
-
* no Array, which East may change in place, so a
|
|
248
|
-
* immutable, and it sorts as an Array of its names would, a
|
|
249
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
267
|
-
*
|
|
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
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
|
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
|
|
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
|
|
298
|
-
run: RecordNestedRunType, level: RecordLevelType, tile: DateTimeType, item:
|
|
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.
|
|
20
|
+
export const E3_RELEASE = '1.0.109';
|
|
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-]+)*)?$/;
|
package/src/structure.spec.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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,
|