@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
|
@@ -13,14 +13,15 @@
|
|
|
13
13
|
* shown, the call as the API answers it ({@link FunctionCallType}). Beside it,
|
|
14
14
|
* it keeps what the call's run needs and no reader is shown: the function
|
|
15
15
|
* object it runs, the runner it runs on, whether it runs verbose, its
|
|
16
|
-
* deadline,
|
|
16
|
+
* deadline, a request to cancel it, and what its run lays its drafts from.
|
|
17
17
|
*
|
|
18
18
|
* It is stored state (`WIRE_MIGRATION.md`): a change to its type ships a
|
|
19
19
|
* repository upgrade step.
|
|
20
20
|
*/
|
|
21
|
-
import { BooleanType, DateTimeType, IntegerType, OptionType, StringType, StructType, decodeBeast2For, encodeBeast2For, } from '@elaraai/east';
|
|
21
|
+
import { ArrayType, BooleanType, DateTimeType, DictType, IntegerType, OptionType, StringType, StructType, decodeBeast2For, encodeBeast2For, } from '@elaraai/east';
|
|
22
22
|
import { FunctionCallType } from './api.js';
|
|
23
23
|
import { RunnerType } from './runner.js';
|
|
24
|
+
import { TreePathType } from './structure.js';
|
|
24
25
|
/**
|
|
25
26
|
* A request to cancel a running call: who asked, and when.
|
|
26
27
|
*
|
|
@@ -39,12 +40,38 @@ export const FunctionCallCancelType = StructType({
|
|
|
39
40
|
*
|
|
40
41
|
* @property succeeded - A call that succeeded, or was cancelled
|
|
41
42
|
* @property failed - A call that failed, was refused (`invalid`), returned too
|
|
42
|
-
* large a value, timed out, or was lost
|
|
43
|
+
* large a value, timed out, met a `conflict` laying a draft, or was lost
|
|
43
44
|
*/
|
|
44
45
|
export const FunctionCallKeepType = StructType({
|
|
45
46
|
succeeded: IntegerType,
|
|
46
47
|
failed: IntegerType,
|
|
47
48
|
});
|
|
49
|
+
/**
|
|
50
|
+
* A record a kept call drafts, as its run lays the drafts: everything the
|
|
51
|
+
* laying reads, named as the call started, so the run reads the workspace no
|
|
52
|
+
* more and lays the same state however often it is run; and the commit the
|
|
53
|
+
* record stood at, which the call's result names.
|
|
54
|
+
*
|
|
55
|
+
* @property record - The record's name, as the call's drafts name it
|
|
56
|
+
* @property path - Where the workspace holds the record: the call's inputs at
|
|
57
|
+
* this path are read at the drafted state, and a dataset argument naming it
|
|
58
|
+
* as saved, at `base`
|
|
59
|
+
* @property base - The state the record held as the call started, which the
|
|
60
|
+
* call's drafts of it are laid over, in order
|
|
61
|
+
* @property commit - The commit the record stood at as the call started,
|
|
62
|
+
* read with `base`: a caller that holds another knows its edits were laid
|
|
63
|
+
* over newer saves
|
|
64
|
+
* @property mutations - The object of each mutation the call's drafts of the
|
|
65
|
+
* record name, by the mutation's name: the one the deployed package named
|
|
66
|
+
* when the call started, whatever is deployed since
|
|
67
|
+
*/
|
|
68
|
+
export const FunctionCallDraftedType = StructType({
|
|
69
|
+
record: StringType,
|
|
70
|
+
path: TreePathType,
|
|
71
|
+
base: StringType,
|
|
72
|
+
commit: StringType,
|
|
73
|
+
mutations: DictType(StringType, StringType),
|
|
74
|
+
});
|
|
48
75
|
/**
|
|
49
76
|
* A kept call, as its store keeps it.
|
|
50
77
|
*
|
|
@@ -61,6 +88,9 @@ export const FunctionCallKeepType = StructType({
|
|
|
61
88
|
* once its deadline and a grace have passed is lost
|
|
62
89
|
* @property cancel - A request to cancel it, once one is made
|
|
63
90
|
* @property keep - How long it is kept once it ends, by how it ended
|
|
91
|
+
* @property drafted - The records it drafts, each once, in the order its
|
|
92
|
+
* drafts first name them, with what its run lays them from and the commit
|
|
93
|
+
* each stood at; none for a call that passed no draft
|
|
64
94
|
*/
|
|
65
95
|
export const FunctionCallJobType = StructType({
|
|
66
96
|
call: FunctionCallType,
|
|
@@ -71,6 +101,7 @@ export const FunctionCallJobType = StructType({
|
|
|
71
101
|
deadline: DateTimeType,
|
|
72
102
|
cancel: OptionType(FunctionCallCancelType),
|
|
73
103
|
keep: FunctionCallKeepType,
|
|
104
|
+
drafted: ArrayType(FunctionCallDraftedType),
|
|
74
105
|
});
|
|
75
106
|
const encodeJob = encodeBeast2For(FunctionCallJobType);
|
|
76
107
|
const decodeJob = decodeBeast2For(FunctionCallJobType);
|
|
@@ -101,15 +132,28 @@ export function decodeFunctionCallJob(bytes) {
|
|
|
101
132
|
* its own, which no package names, so the call alone keeps it, and its
|
|
102
133
|
* program, for as long as it runs and is kept.
|
|
103
134
|
*
|
|
135
|
+
* A call that drafts a record names more: each draft's arguments; the state
|
|
136
|
+
* each drafted record held as the call started and the mutations its drafts
|
|
137
|
+
* run, which its run lays the drafts from; and, among its inputs once the
|
|
138
|
+
* drafts are laid, the drafted state, which nothing else names. So the drafted
|
|
139
|
+
* state lives as long as the call is kept, and is collected after it.
|
|
140
|
+
*
|
|
104
141
|
* @param job - The call
|
|
105
142
|
* @returns The hashes it names: its function object's, then its arguments' in
|
|
106
|
-
* order, then its inputs', then its
|
|
143
|
+
* order, then its inputs', then its drafts' arguments', then each drafted
|
|
144
|
+
* record's state and mutations, then its value's
|
|
107
145
|
*/
|
|
108
146
|
export function functionCallRoots(job) {
|
|
109
147
|
const { call } = job;
|
|
110
148
|
const roots = [job.functionObject, ...call.args.map((arg) => (arg.type === 'value' ? arg.value : arg.value.hash))];
|
|
111
149
|
for (const input of call.inputs)
|
|
112
150
|
roots.push(input.hash);
|
|
151
|
+
for (const draft of call.drafts) {
|
|
152
|
+
if (draft.args.type === 'some')
|
|
153
|
+
roots.push(draft.args.value);
|
|
154
|
+
}
|
|
155
|
+
for (const record of job.drafted)
|
|
156
|
+
roots.push(record.base, ...record.mutations.values());
|
|
113
157
|
if (call.state.type === 'succeeded')
|
|
114
158
|
roots.push(call.state.value.value);
|
|
115
159
|
return roots;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-call.js","sourceRoot":"","sources":["../../src/function-call.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"function-call.js","sourceRoot":"","sources":["../../src/function-call.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,GAElI,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,UAAU,CAAC;IAC/C,EAAE,EAAE,UAAU,CAAC,UAAU,CAAC;IAC1B,EAAE,EAAE,YAAY;CACjB,CAAC,CAAC;AAMH;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC;IAC7C,SAAS,EAAE,WAAW;IACtB,MAAM,EAAK,WAAW;CACvB,CAAC,CAAC;AAMH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAAC;IAChD,MAAM,EAAK,UAAU;IACrB,IAAI,EAAO,YAAY;IACvB,IAAI,EAAO,UAAU;IACrB,MAAM,EAAK,UAAU;IACrB,SAAS,EAAE,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;CAC5C,CAAC,CA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K,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChC,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM;YAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/D,CAAC;IACD,KAAK,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO;QAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;IACxF,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW;QAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACxE,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
* How a call says which of its drafts ended it (east-workspace#1619).
|
|
7
|
+
*
|
|
8
|
+
* A draft is an unsaved edit a call lays over a record its function reads. A
|
|
9
|
+
* call a draft's mutation ended `failed` or `timed_out`, before its function
|
|
10
|
+
* ran, names the draft in its result's `draftEnd` (`FunctionDraftEndType`),
|
|
11
|
+
* and says which in the first line of its stderr, for people to read: `draft
|
|
12
|
+
* jobs.patch (2 of 3) failed`, or `draft jobs.patch (2 of 3) timed out`. The
|
|
13
|
+
* mutation's own stderr follows it, as a Save returns it. A call whose timeout
|
|
14
|
+
* ended once its drafts were all laid, before its function ran, names that in
|
|
15
|
+
* its `draftEnd`, and says so in its first line instead: `drafts laid (3 of 3),
|
|
16
|
+
* and the call's timeout ended before its function ran`.
|
|
17
|
+
*
|
|
18
|
+
* A caller reads what ended a call from its `draftEnd` alone, never from the
|
|
19
|
+
* line (#1680's review): a function that ran may write the same line itself.
|
|
20
|
+
* The lines are written here, so every job that ends a call says them alike.
|
|
21
|
+
*/
|
|
22
|
+
import type { ExecuteResult, FunctionDraftFailure } from './api.js';
|
|
23
|
+
/**
|
|
24
|
+
* How a call names one of its drafts: `draft jobs.patch (2 of 3)`. A refusal
|
|
25
|
+
* of the draft begins with it, and so does the line a call it ended says so in
|
|
26
|
+
* ({@link functionDraftEndLine}).
|
|
27
|
+
*
|
|
28
|
+
* @param draft - The draft's record and mutation
|
|
29
|
+
* @param place - Its place among the call's drafts, from 1
|
|
30
|
+
* @param of - How many drafts the call passed
|
|
31
|
+
* @returns The draft's name
|
|
32
|
+
*/
|
|
33
|
+
export declare function functionDraftLabel(draft: {
|
|
34
|
+
readonly record: string;
|
|
35
|
+
readonly mutation: string;
|
|
36
|
+
}, place: number, of: number): string;
|
|
37
|
+
/**
|
|
38
|
+
* The first line of the stderr of a call a draft ended: `draft jobs.patch (2
|
|
39
|
+
* of 3) failed`, or `… timed out`.
|
|
40
|
+
*
|
|
41
|
+
* @param end - The draft, and how its mutation ended, as the call's `draftEnd`
|
|
42
|
+
* names it
|
|
43
|
+
* @returns The line, with no line end
|
|
44
|
+
*/
|
|
45
|
+
export declare function functionDraftEndLine(end: FunctionDraftFailure): string;
|
|
46
|
+
/**
|
|
47
|
+
* The draft that ended a call before its function ran, as its result's
|
|
48
|
+
* `draftEnd` names it.
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* A call whose timeout ended between two drafts' runs names the draft that
|
|
52
|
+
* did not start. One whose timeout ended once its drafts were all laid names
|
|
53
|
+
* none ({@link functionDraftsOutlasted} says so of it), and neither does a
|
|
54
|
+
* `conflict`, whose outcome names its draft itself. Neither does a call whose
|
|
55
|
+
* function ran, whatever the first line of its stderr says.
|
|
56
|
+
*
|
|
57
|
+
* @param result - A call's result: what ended it
|
|
58
|
+
* @returns The draft, or `null` when no draft's mutation ended the call
|
|
59
|
+
*/
|
|
60
|
+
export declare function functionDraftEnded(result: Pick<ExecuteResult, 'draftEnd'>): FunctionDraftFailure | null;
|
|
61
|
+
/**
|
|
62
|
+
* The first line of the stderr of a call whose timeout ended once its drafts
|
|
63
|
+
* were all laid, before its function ran: `drafts laid (3 of 3), and the
|
|
64
|
+
* call's timeout ended before its function ran`.
|
|
65
|
+
*
|
|
66
|
+
* @param of - How many drafts the call passed, every one of them laid
|
|
67
|
+
* @returns The line, with no line end
|
|
68
|
+
*/
|
|
69
|
+
export declare function functionDraftsLaidLine(of: number): string;
|
|
70
|
+
/**
|
|
71
|
+
* Whether a call's timeout ended once its drafts were all laid, before its
|
|
72
|
+
* function ran, as its result's `draftEnd` says: the time went on its drafts,
|
|
73
|
+
* and its function did not run.
|
|
74
|
+
*
|
|
75
|
+
* @param result - A call's result: what ended it
|
|
76
|
+
* @returns Whether it ended so; `false` for a call that passed no draft, one
|
|
77
|
+
* that did not time out, and one whose function ran
|
|
78
|
+
*/
|
|
79
|
+
export declare function functionDraftsOutlasted(result: Pick<ExecuteResult, 'draftEnd'>): boolean;
|
|
80
|
+
//# sourceMappingURL=function-draft.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-draft.d.ts","sourceRoot":"","sources":["../../src/function-draft.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAKpE;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAEnI;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,oBAAoB,GAAG,MAAM,CAEtE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,GAAG,oBAAoB,GAAG,IAAI,CAEvG;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,GAAG,OAAO,CAExF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
/** How each end reads in the line. */
|
|
6
|
+
const HOW = { failed: 'failed', timed_out: 'timed out' };
|
|
7
|
+
/**
|
|
8
|
+
* How a call names one of its drafts: `draft jobs.patch (2 of 3)`. A refusal
|
|
9
|
+
* of the draft begins with it, and so does the line a call it ended says so in
|
|
10
|
+
* ({@link functionDraftEndLine}).
|
|
11
|
+
*
|
|
12
|
+
* @param draft - The draft's record and mutation
|
|
13
|
+
* @param place - Its place among the call's drafts, from 1
|
|
14
|
+
* @param of - How many drafts the call passed
|
|
15
|
+
* @returns The draft's name
|
|
16
|
+
*/
|
|
17
|
+
export function functionDraftLabel(draft, place, of) {
|
|
18
|
+
return `draft ${draft.record}.${draft.mutation} (${place} of ${of})`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The first line of the stderr of a call a draft ended: `draft jobs.patch (2
|
|
22
|
+
* of 3) failed`, or `… timed out`.
|
|
23
|
+
*
|
|
24
|
+
* @param end - The draft, and how its mutation ended, as the call's `draftEnd`
|
|
25
|
+
* names it
|
|
26
|
+
* @returns The line, with no line end
|
|
27
|
+
*/
|
|
28
|
+
export function functionDraftEndLine(end) {
|
|
29
|
+
return `${functionDraftLabel(end, Number(end.place), Number(end.of))} ${HOW[end.how.type]}`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The draft that ended a call before its function ran, as its result's
|
|
33
|
+
* `draftEnd` names it.
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* A call whose timeout ended between two drafts' runs names the draft that
|
|
37
|
+
* did not start. One whose timeout ended once its drafts were all laid names
|
|
38
|
+
* none ({@link functionDraftsOutlasted} says so of it), and neither does a
|
|
39
|
+
* `conflict`, whose outcome names its draft itself. Neither does a call whose
|
|
40
|
+
* function ran, whatever the first line of its stderr says.
|
|
41
|
+
*
|
|
42
|
+
* @param result - A call's result: what ended it
|
|
43
|
+
* @returns The draft, or `null` when no draft's mutation ended the call
|
|
44
|
+
*/
|
|
45
|
+
export function functionDraftEnded(result) {
|
|
46
|
+
return result.draftEnd.type === 'some' && result.draftEnd.value.type === 'draft' ? result.draftEnd.value.value : null;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The first line of the stderr of a call whose timeout ended once its drafts
|
|
50
|
+
* were all laid, before its function ran: `drafts laid (3 of 3), and the
|
|
51
|
+
* call's timeout ended before its function ran`.
|
|
52
|
+
*
|
|
53
|
+
* @param of - How many drafts the call passed, every one of them laid
|
|
54
|
+
* @returns The line, with no line end
|
|
55
|
+
*/
|
|
56
|
+
export function functionDraftsLaidLine(of) {
|
|
57
|
+
return `drafts laid (${of} of ${of}), and the call's timeout ended before its function ran`;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Whether a call's timeout ended once its drafts were all laid, before its
|
|
61
|
+
* function ran, as its result's `draftEnd` says: the time went on its drafts,
|
|
62
|
+
* and its function did not run.
|
|
63
|
+
*
|
|
64
|
+
* @param result - A call's result: what ended it
|
|
65
|
+
* @returns Whether it ended so; `false` for a call that passed no draft, one
|
|
66
|
+
* that did not time out, and one whose function ran
|
|
67
|
+
*/
|
|
68
|
+
export function functionDraftsOutlasted(result) {
|
|
69
|
+
return result.draftEnd.type === 'some' && result.draftEnd.value.type === 'laid';
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=function-draft.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-draft.js","sourceRoot":"","sources":["../../src/function-draft.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAsBH,sCAAsC;AACtC,MAAM,GAAG,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAW,CAAC;AAElE;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAA6D,EAAE,KAAa,EAAE,EAAU;IACzH,OAAO,SAAS,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,KAAK,KAAK,OAAO,EAAE,GAAG,CAAC;AACvE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAyB;IAC5D,OAAO,GAAG,kBAAkB,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;AAC9F,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAuC;IACxE,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACxH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,EAAU;IAC/C,OAAO,gBAAgB,EAAE,OAAO,EAAE,yDAAyD,CAAC;AAC9F,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAuC;IAC7E,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC;AAClF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-draft.spec.d.ts","sourceRoot":"","sources":["../../src/function-draft.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
* How a call says which of its drafts ended it (east-workspace#1619): the
|
|
7
|
+
* lines its stderr says it in, for people to read, and the end its result
|
|
8
|
+
* names, which a caller reads it from — never the line, which a function's own
|
|
9
|
+
* stderr may say too (#1680's review).
|
|
10
|
+
*/
|
|
11
|
+
import { describe, it } from 'node:test';
|
|
12
|
+
import assert from 'node:assert/strict';
|
|
13
|
+
import { equalFor, none, some, variant } from '@elaraai/east';
|
|
14
|
+
import { FunctionDraftFailureType } from './api.js';
|
|
15
|
+
import { functionDraftEndLine, functionDraftEnded, functionDraftLabel, functionDraftsLaidLine, functionDraftsOutlasted } from './function-draft.js';
|
|
16
|
+
const sameFailure = equalFor(FunctionDraftFailureType);
|
|
17
|
+
/** A draft that ended a call, as its result names it. */
|
|
18
|
+
function draft(record, mutation, place, of, how) {
|
|
19
|
+
return { record, mutation, place, of, how: how === 'failed' ? variant('failed', null) : variant('timed_out', null) };
|
|
20
|
+
}
|
|
21
|
+
const failed = variant('failed', { exitCode: 3n });
|
|
22
|
+
const timedOut = variant('timed_out', { ms: 600000n });
|
|
23
|
+
describe('the lines a call says what of its drafts ended it in', () => {
|
|
24
|
+
it("names a draft by its record, its mutation and its place among the call's, and how many were laid", () => {
|
|
25
|
+
assert.equal(functionDraftLabel({ record: 'jobs', mutation: 'patch' }, 2, 3), 'draft jobs.patch (2 of 3)');
|
|
26
|
+
assert.equal(functionDraftEndLine(draft('jobs', 'patch', 2n, 3n, 'failed')), 'draft jobs.patch (2 of 3) failed');
|
|
27
|
+
assert.equal(functionDraftEndLine(draft('jobs', 'patch', 1n, 1n, 'timed_out')), 'draft jobs.patch (1 of 1) timed out');
|
|
28
|
+
assert.equal(functionDraftsLaidLine(3), 'drafts laid (3 of 3), and the call\'s timeout ended before its function ran');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe('what of its drafts ended a call, as its result names it', () => {
|
|
32
|
+
it('reads back the draft a call names as its end, whatever its record\'s name holds', () => {
|
|
33
|
+
const ends = [draft('jobs', 'patch', 2n, 3n, 'failed'), draft('jobs', 'move', 12n, 12n, 'timed_out'), draft('plant.jobs', 'patch', 1n, 1n, 'failed')];
|
|
34
|
+
for (const end of ends) {
|
|
35
|
+
const result = { outcome: end.how.type === 'failed' ? failed : timedOut, stderr: `${functionDraftEndLine(end)}\n`, draftEnd: some(variant('draft', end)) };
|
|
36
|
+
const read = functionDraftEnded(result);
|
|
37
|
+
assert.ok(read !== null && sameFailure(read, end), functionDraftEndLine(end));
|
|
38
|
+
assert.equal(functionDraftsOutlasted(result), false, 'a draft that ended it is no timeout once every draft was laid');
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
it('reads that a call\'s timeout ended once its drafts were all laid, naming no draft', () => {
|
|
42
|
+
const result = { outcome: timedOut, stderr: `${functionDraftsLaidLine(3)}\n`, draftEnd: some(variant('laid', { of: 3n })) };
|
|
43
|
+
assert.equal(functionDraftsOutlasted(result), true);
|
|
44
|
+
assert.equal(functionDraftEnded(result), null);
|
|
45
|
+
});
|
|
46
|
+
it('names no end for a call its drafts did not end, whatever its stderr says: a function that ran and wrote the lines itself (#1680\'s review)', () => {
|
|
47
|
+
const line = functionDraftEndLine(draft('jobs', 'patch', 1n, 1n, 'failed'));
|
|
48
|
+
const mimic = { outcome: failed, stderr: `${line}\nError: refused\n`, draftEnd: none };
|
|
49
|
+
assert.equal(functionDraftEnded(mimic), null, 'a function whose own stderr begins with a draft\'s end');
|
|
50
|
+
const outlasting = { outcome: timedOut, stderr: `${functionDraftsLaidLine(2)}\n`, draftEnd: none };
|
|
51
|
+
assert.equal(functionDraftsOutlasted(outlasting), false, 'a function whose own stderr says its drafts were laid');
|
|
52
|
+
const success = { outcome: variant('success', { value: new Uint8Array() }), stderr: `${line}\n`, draftEnd: none };
|
|
53
|
+
assert.deepEqual([functionDraftEnded(success), functionDraftsOutlasted(success)], [null, false], 'a call whose function ran to its end');
|
|
54
|
+
const conflict = { outcome: variant('conflict', { record: 'jobs', mutation: 'patch', place: 1n, of: 1n, message: 'gone' }), stderr: '', draftEnd: none };
|
|
55
|
+
assert.equal(functionDraftEnded(conflict), null, 'a conflict, whose outcome names its draft');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=function-draft.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-draft.spec.js","sourceRoot":"","sources":["../../src/function-draft.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAAiD,MAAM,UAAU,CAAC;AACnG,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAEpJ,MAAM,WAAW,GAAG,QAAQ,CAAC,wBAAwB,CAAC,CAAC;AAEvD,yDAAyD;AACzD,SAAS,KAAK,CAAC,MAAc,EAAE,QAAgB,EAAE,KAAa,EAAE,EAAU,EAAE,GAA2B;IACrG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EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAChK,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,2CAA2C,CAAC,CAAC;IAChG,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/src/function.d.ts
CHANGED
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
* An `e3.function` is a named, typed function stored in a package and
|
|
9
9
|
* invoked by name with argument values over the CLI and HTTP API. It may
|
|
10
10
|
* read datasets of the workspace a call runs through — its inputs — beside
|
|
11
|
-
* the arguments its caller passes
|
|
12
|
-
*
|
|
11
|
+
* the arguments its caller passes, and name the records among them a call
|
|
12
|
+
* may pass drafts of: mutation calls that are not committed, laid over the
|
|
13
|
+
* record for that call alone. Unlike a task it is not part of the dataflow
|
|
14
|
+
* graph, and triggers no recomputation.
|
|
13
15
|
*
|
|
14
16
|
* The function object stores its signature explicitly so `describe` and
|
|
15
17
|
* arity/type validation work from the small function object without
|
|
@@ -17,6 +19,32 @@
|
|
|
17
19
|
* non-TS clients) have the types they need to encode arguments.
|
|
18
20
|
*/
|
|
19
21
|
import { StructType, StringType, ArrayType, OptionType, ValueTypeOf } from '@elaraai/east';
|
|
22
|
+
/**
|
|
23
|
+
* What a function reads from the workspace a call runs in: a dataset, or an
|
|
24
|
+
* index of a record, which is read through the record's dataset.
|
|
25
|
+
*
|
|
26
|
+
* @property path - The dataset's path: for an index, its record's
|
|
27
|
+
* @property index - The index of the record at `path` the input reads, by its
|
|
28
|
+
* name on the record: the body is given the index's entries,
|
|
29
|
+
* `Dict<{ ik, k }, P>`, at the state the record is pinned at. `none` for the
|
|
30
|
+
* dataset itself
|
|
31
|
+
*/
|
|
32
|
+
export declare const FunctionInputType: StructType<{
|
|
33
|
+
readonly path: ArrayType<import("@elaraai/east").VariantType<{
|
|
34
|
+
readonly field: StringType;
|
|
35
|
+
}>>;
|
|
36
|
+
readonly index: OptionType<StringType>;
|
|
37
|
+
}>;
|
|
38
|
+
export type FunctionInputType = typeof FunctionInputType;
|
|
39
|
+
export type FunctionInput = ValueTypeOf<typeof FunctionInputType>;
|
|
40
|
+
/**
|
|
41
|
+
* An input as a message names it: its dataset's keypath, or, for an index of a
|
|
42
|
+
* record, the index and its record's keypath.
|
|
43
|
+
*
|
|
44
|
+
* @param input - The input: a function's, a task's, or one a call read
|
|
45
|
+
* @returns `.inputs.prices`, or `the index jobs_by_press of .records.jobs`
|
|
46
|
+
*/
|
|
47
|
+
export declare function inputLabel(input: Pick<FunctionInput, 'path' | 'index'>): string;
|
|
20
48
|
/**
|
|
21
49
|
* Function object stored in the object store, referenced by name from
|
|
22
50
|
* `PackageObject.functions`.
|
|
@@ -26,12 +54,21 @@ export declare const FunctionObjectType: StructType<{
|
|
|
26
54
|
* Its parameters are the inputs' types, in `inputs` order, then
|
|
27
55
|
* `argTypes`. */
|
|
28
56
|
readonly bodyIr: StringType;
|
|
29
|
-
/**
|
|
30
|
-
* its hash when the call launches and passed before
|
|
31
|
-
* arguments
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
57
|
+
/** What a call reads from the workspace it runs in ({@link FunctionInputType}):
|
|
58
|
+
* each dataset pinned at its hash when the call launches and passed before
|
|
59
|
+
* the caller's arguments, the inputs of one record — the record and any of
|
|
60
|
+
* its indexes — at one state of it; empty for a function that reads none. */
|
|
61
|
+
readonly inputs: ArrayType<StructType<{
|
|
62
|
+
readonly path: ArrayType<import("@elaraai/east").VariantType<{
|
|
63
|
+
readonly field: StringType;
|
|
64
|
+
}>>;
|
|
65
|
+
readonly index: OptionType<StringType>;
|
|
66
|
+
}>>;
|
|
67
|
+
/** The records a call may pass drafts of, by name: each a record one of
|
|
68
|
+
* `inputs` reads, which the call then reads with its drafts laid over it.
|
|
69
|
+
* A call that passes a draft of any other record is `invalid`; empty for a
|
|
70
|
+
* function that takes none. */
|
|
71
|
+
readonly drafts: ArrayType<StringType>;
|
|
35
72
|
/** The types of the arguments a caller passes, after the inputs, surfaced
|
|
36
73
|
* for arity/type validation and `describe` without decoding the whole
|
|
37
74
|
* IR. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../src/function.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../src/function.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAgB,UAAU,EAAE,WAAW,EAAmB,MAAM,eAAe,CAAC;AAI1H;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB;;;;;EAG5B,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAC;AACzD,MAAM,MAAM,aAAa,GAAG,WAAW,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAElE;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,MAAM,CAG/E;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB;IAC7B;;sBAEkB;;IAElB;;;kFAG8E;;;;;;;IAE9E;;;oCAGgC;;IAEhC;;cAEU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEV,wEAAwE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAExE;gEAC4D;;;;;;;;;;;;;;;;;;;;;;;;;;;IAE5D;;;OAGG;;EAEH,CAAC;AACH,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAC;AAE3D,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAIpE;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc,CASrE"}
|
package/dist/src/function.js
CHANGED
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
* An `e3.function` is a named, typed function stored in a package and
|
|
9
9
|
* invoked by name with argument values over the CLI and HTTP API. It may
|
|
10
10
|
* read datasets of the workspace a call runs through — its inputs — beside
|
|
11
|
-
* the arguments its caller passes
|
|
12
|
-
*
|
|
11
|
+
* the arguments its caller passes, and name the records among them a call
|
|
12
|
+
* may pass drafts of: mutation calls that are not committed, laid over the
|
|
13
|
+
* record for that call alone. Unlike a task it is not part of the dataflow
|
|
14
|
+
* graph, and triggers no recomputation.
|
|
13
15
|
*
|
|
14
16
|
* The function object stores its signature explicitly so `describe` and
|
|
15
17
|
* arity/type validation work from the small function object without
|
|
@@ -18,7 +20,32 @@
|
|
|
18
20
|
*/
|
|
19
21
|
import { StructType, StringType, ArrayType, EastTypeType, OptionType, decodeBeast2For } from '@elaraai/east';
|
|
20
22
|
import { RunnerType } from './runner.js';
|
|
21
|
-
import { TreePathType } from './structure.js';
|
|
23
|
+
import { TreePathType, pathToString } from './structure.js';
|
|
24
|
+
/**
|
|
25
|
+
* What a function reads from the workspace a call runs in: a dataset, or an
|
|
26
|
+
* index of a record, which is read through the record's dataset.
|
|
27
|
+
*
|
|
28
|
+
* @property path - The dataset's path: for an index, its record's
|
|
29
|
+
* @property index - The index of the record at `path` the input reads, by its
|
|
30
|
+
* name on the record: the body is given the index's entries,
|
|
31
|
+
* `Dict<{ ik, k }, P>`, at the state the record is pinned at. `none` for the
|
|
32
|
+
* dataset itself
|
|
33
|
+
*/
|
|
34
|
+
export const FunctionInputType = StructType({
|
|
35
|
+
path: TreePathType,
|
|
36
|
+
index: OptionType(StringType),
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* An input as a message names it: its dataset's keypath, or, for an index of a
|
|
40
|
+
* record, the index and its record's keypath.
|
|
41
|
+
*
|
|
42
|
+
* @param input - The input: a function's, a task's, or one a call read
|
|
43
|
+
* @returns `.inputs.prices`, or `the index jobs_by_press of .records.jobs`
|
|
44
|
+
*/
|
|
45
|
+
export function inputLabel(input) {
|
|
46
|
+
const at = pathToString(input.path);
|
|
47
|
+
return input.index.type === 'some' ? `the index ${input.index.value} of ${at}` : at;
|
|
48
|
+
}
|
|
22
49
|
/**
|
|
23
50
|
* Function object stored in the object store, referenced by name from
|
|
24
51
|
* `PackageObject.functions`.
|
|
@@ -28,10 +55,16 @@ export const FunctionObjectType = StructType({
|
|
|
28
55
|
* Its parameters are the inputs' types, in `inputs` order, then
|
|
29
56
|
* `argTypes`. */
|
|
30
57
|
bodyIr: StringType,
|
|
31
|
-
/**
|
|
32
|
-
* its hash when the call launches and passed before
|
|
33
|
-
* arguments
|
|
34
|
-
|
|
58
|
+
/** What a call reads from the workspace it runs in ({@link FunctionInputType}):
|
|
59
|
+
* each dataset pinned at its hash when the call launches and passed before
|
|
60
|
+
* the caller's arguments, the inputs of one record — the record and any of
|
|
61
|
+
* its indexes — at one state of it; empty for a function that reads none. */
|
|
62
|
+
inputs: ArrayType(FunctionInputType),
|
|
63
|
+
/** The records a call may pass drafts of, by name: each a record one of
|
|
64
|
+
* `inputs` reads, which the call then reads with its drafts laid over it.
|
|
65
|
+
* A call that passes a draft of any other record is `invalid`; empty for a
|
|
66
|
+
* function that takes none. */
|
|
67
|
+
drafts: ArrayType(StringType),
|
|
35
68
|
/** The types of the arguments a caller passes, after the inputs, surfaced
|
|
36
69
|
* for arity/type validation and `describe` without decoding the whole
|
|
37
70
|
* IR. */
|
package/dist/src/function.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function.js","sourceRoot":"","sources":["../../src/function.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"function.js","sourceRoot":"","sources":["../../src/function.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EA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AAO,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,uHAAuH;YACvH,IAAI,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CACxD,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function.spec.d.ts","sourceRoot":"","sources":["../../src/function.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -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
|
+
* Function object wire: the function object's round trip, with an input that
|
|
7
|
+
* is an index of a record, and its refusal of the form before it.
|
|
8
|
+
*/
|
|
9
|
+
import { describe, it } from 'node:test';
|
|
10
|
+
import assert from 'node:assert/strict';
|
|
11
|
+
import { ArrayType, EastTypeType, IntegerType, OptionType, StringType, StructType, encodeBeast2For, equalFor, none, some, toEastTypeValue, variant } from '@elaraai/east';
|
|
12
|
+
import { FunctionObjectType, decodeFunctionObject } from './function.js';
|
|
13
|
+
import { RunnerType } from './runner.js';
|
|
14
|
+
import { TreePathType } from './structure.js';
|
|
15
|
+
describe('FunctionObjectType', () => {
|
|
16
|
+
const jobs = [variant('field', 'records'), variant('field', 'jobs')];
|
|
17
|
+
const presses = [variant('field', 'inputs'), variant('field', 'presses')];
|
|
18
|
+
const base = {
|
|
19
|
+
bodyIr: 'a'.repeat(64),
|
|
20
|
+
inputs: [],
|
|
21
|
+
drafts: [],
|
|
22
|
+
argTypes: [toEastTypeValue(StringType)],
|
|
23
|
+
outputType: toEastTypeValue(IntegerType),
|
|
24
|
+
runner: variant('east_c', { platforms: [], decode: variant('lazy', null) }),
|
|
25
|
+
environment: none,
|
|
26
|
+
};
|
|
27
|
+
it('round-trips a function that reads nothing, datasets, and an index of a record beside the record', () => {
|
|
28
|
+
const functions = [
|
|
29
|
+
base,
|
|
30
|
+
{ ...base, inputs: [{ path: presses, index: none }], environment: some('b'.repeat(64)) },
|
|
31
|
+
{
|
|
32
|
+
...base,
|
|
33
|
+
inputs: [{ path: jobs, index: some('jobs_by_press') }, { path: jobs, index: none }],
|
|
34
|
+
drafts: ['jobs'],
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
const encode = encodeBeast2For(FunctionObjectType);
|
|
38
|
+
const same = equalFor(FunctionObjectType);
|
|
39
|
+
for (const original of functions) {
|
|
40
|
+
assert.ok(same(decodeFunctionObject(encode(original)), original), `a function with ${original.inputs.length} inputs decodes as it was encoded`);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
it('refuses a function object whose inputs predate the index they may name, saying to re-export the package', () => {
|
|
44
|
+
// A function object as a package exported before an input could be an
|
|
45
|
+
// index of a record: each input its dataset's path alone.
|
|
46
|
+
const older = encodeBeast2For(StructType({
|
|
47
|
+
bodyIr: StringType,
|
|
48
|
+
inputs: ArrayType(TreePathType),
|
|
49
|
+
drafts: ArrayType(StringType),
|
|
50
|
+
argTypes: ArrayType(EastTypeType),
|
|
51
|
+
outputType: EastTypeType,
|
|
52
|
+
runner: RunnerType,
|
|
53
|
+
environment: OptionType(StringType),
|
|
54
|
+
}))({ ...base, inputs: [presses] });
|
|
55
|
+
assert.throws(() => decodeFunctionObject(older), /exported by an older e3 SDK — re-export it with the current one/);
|
|
56
|
+
});
|
|
57
|
+
it('throws for bytes of no known function shape', () => {
|
|
58
|
+
assert.throws(() => decodeFunctionObject(encodeBeast2For(IntegerType)(7n)), /re-export/);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=function.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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