@elaraai/e3 1.0.107 → 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/export.d.ts.map +1 -1
- package/dist/src/export.js +13 -6
- package/dist/src/export.js.map +1 -1
- package/dist/src/export.spec.js +25 -3
- package/dist/src/export.spec.js.map +1 -1
- package/dist/src/function.d.ts +136 -57
- package/dist/src/function.d.ts.map +1 -1
- package/dist/src/function.js +47 -12
- package/dist/src/function.js.map +1 -1
- package/dist/src/function.spec.d.ts +3 -1
- package/dist/src/function.spec.d.ts.map +1 -1
- package/dist/src/function.spec.js +246 -3
- package/dist/src/function.spec.js.map +1 -1
- package/dist/src/index-input.d.ts +162 -0
- package/dist/src/index-input.d.ts.map +1 -0
- package/dist/src/index-input.js +216 -0
- package/dist/src/index-input.js.map +1 -0
- package/dist/src/index-input.spec.d.ts +6 -0
- package/dist/src/index-input.spec.d.ts.map +1 -0
- package/dist/src/index-input.spec.js +269 -0
- package/dist/src/index-input.spec.js.map +1 -0
- package/dist/src/index-read.d.ts +428 -0
- package/dist/src/index-read.d.ts.map +1 -0
- package/dist/src/index-read.js +747 -0
- package/dist/src/index-read.js.map +1 -0
- package/dist/src/index-read.spec.d.ts +6 -0
- package/dist/src/index-read.spec.d.ts.map +1 -0
- package/dist/src/index-read.spec.js +1447 -0
- package/dist/src/index-read.spec.js.map +1 -0
- package/dist/src/index.d.ts +10 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/package.d.ts.map +1 -1
- package/dist/src/package.js +3 -4
- package/dist/src/package.js.map +1 -1
- package/dist/src/record-area.d.ts +12 -0
- package/dist/src/record-area.d.ts.map +1 -1
- package/dist/src/record-area.js +26 -0
- package/dist/src/record-area.js.map +1 -1
- package/dist/src/record-area.spec.js +4 -14
- package/dist/src/record-area.spec.js.map +1 -1
- package/dist/src/record-builders.d.ts +39 -14
- package/dist/src/record-builders.d.ts.map +1 -1
- package/dist/src/record-builders.js.map +1 -1
- package/dist/src/record-entries.spec.js +2 -15
- package/dist/src/record-entries.spec.js.map +1 -1
- package/dist/src/record-index.d.ts +11 -5
- package/dist/src/record-index.d.ts.map +1 -1
- package/dist/src/record-index.js.map +1 -1
- package/dist/src/record-interval.d.ts +7 -0
- package/dist/src/record-interval.d.ts.map +1 -1
- package/dist/src/record-interval.js +7 -0
- package/dist/src/record-interval.js.map +1 -1
- package/dist/src/record-nested-programs.d.ts +63 -511
- package/dist/src/record-nested-programs.d.ts.map +1 -1
- package/dist/src/record-nested-programs.js +403 -222
- package/dist/src/record-nested-programs.js.map +1 -1
- package/dist/src/record-nested.d.ts +60 -10
- package/dist/src/record-nested.d.ts.map +1 -1
- package/dist/src/record-nested.js +65 -23
- package/dist/src/record-nested.js.map +1 -1
- package/dist/src/record-nested.spec.js +113 -34
- package/dist/src/record-nested.spec.js.map +1 -1
- package/dist/src/record-series.spec.js +6 -31
- package/dist/src/record-series.spec.js.map +1 -1
- package/dist/src/record.d.ts +9 -0
- package/dist/src/record.d.ts.map +1 -1
- package/dist/src/record.js +14 -0
- package/dist/src/record.js.map +1 -1
- package/dist/src/task.d.ts +28 -16
- package/dist/src/task.d.ts.map +1 -1
- package/dist/src/task.js +33 -5
- package/dist/src/task.js.map +1 -1
- package/dist/src/test-helpers.d.ts +35 -0
- package/dist/src/test-helpers.d.ts.map +1 -0
- package/dist/src/test-helpers.js +56 -0
- package/dist/src/test-helpers.js.map +1 -0
- package/dist/src/types.d.ts +86 -13
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/src/function.d.ts
CHANGED
|
@@ -11,17 +11,37 @@
|
|
|
11
11
|
* graph, and its result is returned inline to the caller — nothing durable
|
|
12
12
|
* is written by a call. A function may declare inputs, as a stream task
|
|
13
13
|
* does: datasets of the workspace a call reads, each pinned at its hash,
|
|
14
|
-
* beside the arguments its caller passes.
|
|
14
|
+
* beside the arguments its caller passes. It may list the records among them
|
|
15
|
+
* a call may lay unsaved edits over, its drafts: the call reads each with its
|
|
16
|
+
* drafts laid over it, and saves nothing.
|
|
15
17
|
*/
|
|
16
18
|
import { type EnvironmentDecl } from './environment.js';
|
|
17
19
|
import type { AsyncFunctionExpr, BlockBuilder, CallableAsyncFunctionExpr, CallableFunctionExpr, EastType, ExprType, FunctionExpr, SubtypeExprOrValue } from '@elaraai/east';
|
|
18
|
-
import type {
|
|
20
|
+
import type { FunctionDef, InputDef, RecordDef } from './types.js';
|
|
19
21
|
import { type FunctionRunner } from './runner.js';
|
|
20
22
|
import { type InputExprs } from './task.js';
|
|
21
23
|
/** The expression a function's body receives for each argument. */
|
|
22
24
|
type ArgExprs<T extends readonly EastType[]> = {
|
|
23
25
|
[K in keyof T]: ExprType<T[K]>;
|
|
24
26
|
};
|
|
27
|
+
/** The records a function's inputs read, which its `drafts` may list: a record
|
|
28
|
+
* among them, and the record of an index among them. An index names its
|
|
29
|
+
* record's type loosely, so with any index among the inputs the list takes
|
|
30
|
+
* any record, and the definition checks each against the inputs. */
|
|
31
|
+
type RecordsOf<Inputs extends readonly InputDef[]> = Extract<Inputs[number], {
|
|
32
|
+
readonly recordKind: 'record';
|
|
33
|
+
}> | ([Extract<Inputs[number], {
|
|
34
|
+
readonly kind: 'index';
|
|
35
|
+
}>] extends [never] ? never : RecordDef);
|
|
36
|
+
/**
|
|
37
|
+
* Whether a function's spec lists a record in `drafts`, as its definition's
|
|
38
|
+
* type says it ({@link FunctionDef}'s `Drafted`): `false` for none, `true`
|
|
39
|
+
* for at least one, and `boolean` where the list is no tuple, so that its
|
|
40
|
+
* length is not known.
|
|
41
|
+
*
|
|
42
|
+
* @typeParam Listed - The spec's `drafts`, as listed
|
|
43
|
+
*/
|
|
44
|
+
type DraftedOf<Listed extends readonly unknown[]> = number extends Listed['length'] ? boolean : Listed extends readonly [] ? false : true;
|
|
25
45
|
/**
|
|
26
46
|
* The declaration half of a function with inputs ({@link function_}'s
|
|
27
47
|
* `(name, spec, fn)` form); the body comes last as the `fn` argument.
|
|
@@ -29,15 +49,30 @@ type ArgExprs<T extends readonly EastType[]> = {
|
|
|
29
49
|
* @typeParam Inputs - The datasets a call reads from its workspace
|
|
30
50
|
* @typeParam Args - The types of the arguments a caller passes
|
|
31
51
|
* @typeParam Output - The return type
|
|
52
|
+
* @typeParam Listed - The records it lists in `drafts`, as a tuple: none
|
|
53
|
+
* unless named, so a spec declared apart from its call names them to list
|
|
54
|
+
* any (`FunctionSpec<[typeof jobs], [], IntegerType, [typeof jobs]>`)
|
|
32
55
|
*/
|
|
33
|
-
export interface FunctionSpec<Inputs extends readonly
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* call
|
|
39
|
-
*
|
|
56
|
+
export interface FunctionSpec<Inputs extends readonly InputDef[], Args extends EastType[], Output extends EastType, Listed extends readonly RecordsOf<Inputs>[] = readonly []> {
|
|
57
|
+
/** What each call reads from the workspace it runs in, in the body's
|
|
58
|
+
* parameter order before the arguments: an input, a task's output or a
|
|
59
|
+
* record of the package, or an index of a record (`e3.index`), whose
|
|
60
|
+
* parameter is the index's entries. Each dataset is read as it is stored as
|
|
61
|
+
* the call starts, pinned at its hash: one after another, waiting for no
|
|
62
|
+
* run, so a call during a run may read one before the run rewrites it and
|
|
63
|
+
* another after. The inputs of one record, the record and any of its
|
|
64
|
+
* indexes, are read at one state of it. */
|
|
40
65
|
readonly inputs: [...Inputs];
|
|
66
|
+
/** The records a call may pass drafts of, each a record one of `inputs`
|
|
67
|
+
* reads: the record itself, or an index of it, which then holds the drafts
|
|
68
|
+
* as it would after the Save. A
|
|
69
|
+
* draft is a call of one of the record's mutations that is not committed:
|
|
70
|
+
* a call reads a drafted record with its drafts laid over it, its indexes
|
|
71
|
+
* holding them as they would after the Save, and saves nothing. Listing a
|
|
72
|
+
* record says the body is fit to run over edits nobody has saved, so a
|
|
73
|
+
* function that sends a message or writes elsewhere lists none. Omitted, a
|
|
74
|
+
* call takes no draft. */
|
|
75
|
+
readonly drafts?: readonly [...Listed];
|
|
41
76
|
/** The types of the arguments a caller passes, after the inputs. */
|
|
42
77
|
readonly args: [...Args];
|
|
43
78
|
/** The return type. */
|
|
@@ -51,6 +86,49 @@ export interface FunctionSpec<Inputs extends readonly DatasetDef[], Args extends
|
|
|
51
86
|
* async; a sync `East.function` otherwise. */
|
|
52
87
|
readonly async?: boolean;
|
|
53
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Defines a named function stored in a package.
|
|
91
|
+
*
|
|
92
|
+
* The body is an ordinary East function (sync or async); its signature IS
|
|
93
|
+
* the argument list — `argTypes` / `outputType` are inferred from the East
|
|
94
|
+
* function, so there is no separate type array to keep in sync. It reads
|
|
95
|
+
* nothing of the workspace: a function that does declares `inputs`, in the
|
|
96
|
+
* `(name, spec, fn)` form.
|
|
97
|
+
*
|
|
98
|
+
* Unlike a task, a function creates no dataset tree nodes and no command IR:
|
|
99
|
+
* its body IR is stored directly as a content object, its signature lives on
|
|
100
|
+
* the function object, and the executor builds the runner argv directly at
|
|
101
|
+
* call time (which is what enables a request-time runner override).
|
|
102
|
+
*
|
|
103
|
+
* @typeParam Name - Function name (literal type)
|
|
104
|
+
* @typeParam Args - The argument types: the East function's parameters
|
|
105
|
+
* @typeParam Output - Return type
|
|
106
|
+
* @param name - Function name (unique within the package)
|
|
107
|
+
* @param fn - The East function body. Pure compute — no dataset reads; may
|
|
108
|
+
* be async (platform calls / IO).
|
|
109
|
+
* @param config - Optional runner selection. Only the known runtimes are
|
|
110
|
+
* allowed — including `custom` (symmetric with tasks; the command must
|
|
111
|
+
* speak the runner CLI convention, see {@link FunctionRunner}).
|
|
112
|
+
* @returns A FunctionDef to pass to `e3.package`
|
|
113
|
+
* @throws {Error} When the name is empty or the runner is not a known one.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const forecast = e3.function(
|
|
118
|
+
* 'forecast',
|
|
119
|
+
* East.function([IntegerType, FloatType], FloatType, ($, periods, growthRate) => {
|
|
120
|
+
* ...
|
|
121
|
+
* }),
|
|
122
|
+
* { runner: { runtime: 'east-py', platforms: ['east-py-datascience'] } },
|
|
123
|
+
* );
|
|
124
|
+
*
|
|
125
|
+
* const pkg = e3.package('planning', '1.0.0', forecast);
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export declare function function_<Name extends string, Args extends EastType[], Output extends EastType>(name: Name, fn: FunctionExpr<Args, Output> | CallableFunctionExpr<Args, Output> | AsyncFunctionExpr<Args, Output> | CallableAsyncFunctionExpr<Args, Output>, config?: {
|
|
129
|
+
runner?: FunctionRunner;
|
|
130
|
+
environment?: EnvironmentDecl;
|
|
131
|
+
}): FunctionDef<Args, Output, false>;
|
|
54
132
|
/**
|
|
55
133
|
* Defines a named function that reads the workspace as well: the `inputs` it
|
|
56
134
|
* declares, as a stream task declares them, beside the `args` its caller
|
|
@@ -59,32 +137,50 @@ export interface FunctionSpec<Inputs extends readonly DatasetDef[], Args extends
|
|
|
59
137
|
* The body's parameters are the inputs, in `inputs` order, then the
|
|
60
138
|
* arguments, in `args` order: the SDK builds the East function from their
|
|
61
139
|
* types, an async one with `async: true`. An input is what a task takes — an
|
|
62
|
-
* input, a task's output or a record of the package
|
|
63
|
-
*
|
|
64
|
-
*
|
|
140
|
+
* input, a task's output or a record of the package, or an index of a record
|
|
141
|
+
* (`e3.index`), whose parameter is the index's entries — and `e3.package`
|
|
142
|
+
* collects each with what it depends on, an index's record with it. The
|
|
143
|
+
* function is still no node of the dataflow: nothing reruns when an input
|
|
144
|
+
* changes.
|
|
65
145
|
*
|
|
66
146
|
* A call through a workspace reads each input as it is stored as the call
|
|
67
|
-
* starts, pinned at its hash, and its result names each path and hash
|
|
147
|
+
* starts, pinned at its hash, and its result names each path and hash — and,
|
|
148
|
+
* for an index, the index, with the hash its record was pinned at. The
|
|
68
149
|
* inputs are read one after another, waiting for no run, so a call during a
|
|
69
|
-
* run may read one input before the run rewrites it and another after
|
|
150
|
+
* run may read one input before the run rewrites it and another after; the
|
|
151
|
+
* inputs of one record, the record and any of its indexes, are read at one
|
|
152
|
+
* state of it. The
|
|
70
153
|
* caller passes the arguments alone. An input not assigned — one nothing has
|
|
71
154
|
* set, a task's output no run has produced since the deploy — makes the call
|
|
72
155
|
* `invalid`, naming it, and nothing runs. The package route, which has no
|
|
73
156
|
* workspace, refuses such a function.
|
|
74
157
|
*
|
|
158
|
+
* `drafts` lists the records among the inputs a call may lay unsaved edits
|
|
159
|
+
* over. A draft is a call of one of the record's mutations that is not
|
|
160
|
+
* committed: a call passes its drafts in order, reads each drafted record
|
|
161
|
+
* with them laid over it — its rows, and its indexes as they would hold them
|
|
162
|
+
* after the Save — and saves nothing. Listing a record is the author's word
|
|
163
|
+
* that the body is fit to run over edits nobody has saved; a call that passes
|
|
164
|
+
* a draft of a record the function does not list is `invalid`.
|
|
165
|
+
*
|
|
75
166
|
* @typeParam Name - Function name (literal type)
|
|
76
167
|
* @typeParam Inputs - The datasets a call reads
|
|
77
168
|
* @typeParam Args - The argument types a caller passes
|
|
78
169
|
* @typeParam Output - Return type
|
|
170
|
+
* @typeParam Listed - The records listed in `drafts`, as listed: the
|
|
171
|
+
* definition's type says whether there is any, which a page's bind reads
|
|
79
172
|
* @param name - Function name (unique within the package)
|
|
80
|
-
* @param spec - The inputs, the
|
|
81
|
-
* runner, environment and `async`
|
|
173
|
+
* @param spec - The inputs, the records a call may draft, the argument types
|
|
174
|
+
* and the return type, and the runner, environment and `async`
|
|
175
|
+
* ({@link FunctionSpec})
|
|
82
176
|
* @param fn - The body: given the inputs, then the arguments, it returns the
|
|
83
177
|
* result
|
|
84
178
|
* @returns A FunctionDef to pass to `e3.package`
|
|
85
179
|
* @throws {Error} When the name is empty or the runner is not a known one, an
|
|
86
|
-
* input is marked with `e3.partition` (a call runs as one unit),
|
|
87
|
-
*
|
|
180
|
+
* input is marked with `e3.partition` (a call runs as one unit), the runner
|
|
181
|
+
* is the `custom` runtime with inputs, or `drafts` lists what is no record,
|
|
182
|
+
* or a record none of the inputs reads — itself, or by an index of it —
|
|
183
|
+
* naming it.
|
|
88
184
|
*
|
|
89
185
|
* @example
|
|
90
186
|
* ```ts
|
|
@@ -100,50 +196,33 @@ export interface FunctionSpec<Inputs extends readonly DatasetDef[], Args extends
|
|
|
100
196
|
* // e3 call . -w dev quote '[(sku="bolt", quantity=4)]'
|
|
101
197
|
* const pkg = e3.package('planning', '1.0.0', quote);
|
|
102
198
|
* ```
|
|
103
|
-
*/
|
|
104
|
-
export declare function function_<Name extends string, Inputs extends readonly DatasetDef[], Args extends EastType[], Output extends EastType>(name: Name, spec: FunctionSpec<Inputs, Args, Output>, fn: ($: BlockBuilder<Output>, ...params: [...InputExprs<Inputs>, ...ArgExprs<Args>]) => SubtypeExprOrValue<NoInfer<Output>> | void): FunctionDef<Args, Output>;
|
|
105
|
-
/**
|
|
106
|
-
* Defines a named function stored in a package.
|
|
107
|
-
*
|
|
108
|
-
* The body is an ordinary East function (sync or async); its signature IS
|
|
109
|
-
* the argument list — `argTypes` / `outputType` are inferred from the East
|
|
110
|
-
* function, so there is no separate type array to keep in sync. It reads
|
|
111
|
-
* nothing of the workspace: a function that does declares `inputs`, in the
|
|
112
|
-
* `(name, spec, fn)` form.
|
|
113
|
-
*
|
|
114
|
-
* Unlike a task, a function creates no dataset tree nodes and no command IR:
|
|
115
|
-
* its body IR is stored directly as a content object, its signature lives on
|
|
116
|
-
* the function object, and the executor builds the runner argv directly at
|
|
117
|
-
* call time (which is what enables a request-time runner override).
|
|
118
|
-
*
|
|
119
|
-
* @typeParam Name - Function name (literal type)
|
|
120
|
-
* @typeParam Args - The argument types: the East function's parameters
|
|
121
|
-
* @typeParam Output - Return type
|
|
122
|
-
* @param name - Function name (unique within the package)
|
|
123
|
-
* @param fn - The East function body. Pure compute — no dataset reads; may
|
|
124
|
-
* be async (platform calls / IO).
|
|
125
|
-
* @param config - Optional runner selection. Only the known runtimes are
|
|
126
|
-
* allowed — including `custom` (symmetric with tasks; the command must
|
|
127
|
-
* speak the runner CLI convention, see {@link FunctionRunner}).
|
|
128
|
-
* @returns A FunctionDef to pass to `e3.package`
|
|
129
|
-
* @throws {Error} When the name is empty or the runner is not a known one.
|
|
130
199
|
*
|
|
131
200
|
* @example
|
|
132
201
|
* ```ts
|
|
133
|
-
* const
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* }),
|
|
138
|
-
* { runner: { runtime: 'east-py', platforms: ['east-py-datascience'] } },
|
|
139
|
-
* );
|
|
202
|
+
* const jobs = e3.record('jobs', DictType(StringType, JobType), {
|
|
203
|
+
* initial: new Map(),
|
|
204
|
+
* mutations: (mutation) => ({ patch: mutation.patch() }),
|
|
205
|
+
* });
|
|
140
206
|
*
|
|
141
|
-
*
|
|
207
|
+
* // How many jobs a press holds. `drafts` says a call may lay unsaved edits over jobs.
|
|
208
|
+
* const jobsOn = e3.function('jobs_on', {
|
|
209
|
+
* inputs: [jobs],
|
|
210
|
+
* drafts: [jobs],
|
|
211
|
+
* args: [StringType],
|
|
212
|
+
* output: IntegerType,
|
|
213
|
+
* }, ($, jobs, press) => {
|
|
214
|
+
* const count = $.let(0n);
|
|
215
|
+
* $.for(jobs, ($, job) => {
|
|
216
|
+
* $.if(East.equal(job.press, press), ($) => { $.assign(count, count.add(1n)); });
|
|
217
|
+
* });
|
|
218
|
+
* return count;
|
|
219
|
+
* });
|
|
220
|
+
*
|
|
221
|
+
* // As saved, then with an unsaved edit laid over jobs: nothing is saved.
|
|
222
|
+
* // e3 call . -w dev jobs_on '"P1"'
|
|
223
|
+
* // e3 call . -w dev jobs_on '"P1"' --draft jobs.patch ./edit.east
|
|
142
224
|
* ```
|
|
143
225
|
*/
|
|
144
|
-
export declare function function_<Name extends string, Args extends EastType[], Output extends EastType>(name: Name,
|
|
145
|
-
runner?: FunctionRunner;
|
|
146
|
-
environment?: EnvironmentDecl;
|
|
147
|
-
}): FunctionDef<Args, Output>;
|
|
226
|
+
export declare function function_<Name extends string, Inputs extends readonly InputDef[], Args extends EastType[], Output extends EastType, Listed extends readonly RecordsOf<Inputs>[] = readonly []>(name: Name, spec: FunctionSpec<Inputs, Args, Output, Listed>, fn: ($: BlockBuilder<Output>, ...params: [...InputExprs<Inputs>, ...ArgExprs<Args>]) => SubtypeExprOrValue<NoInfer<Output>> | void): FunctionDef<Args, Output, DraftedOf<Listed>>;
|
|
148
227
|
export {};
|
|
149
228
|
//# sourceMappingURL=function.d.ts.map
|
|
@@ -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;;;;;;;;;;;;GAYG;AAEH,OAAO,EAA2B,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,KAAK,EACV,iBAAiB,EAEjB,YAAY,EACZ,yBAAyB,EACzB,oBAAoB,EACpB,QAAQ,EACR,QAAQ,EACR,YAAY,EAEZ,kBAAkB,EACnB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAA2B,WAAW,EAAE,QAAQ,EAAgB,SAAS,EAAW,MAAM,YAAY,CAAC;AACnH,OAAO,EAAmC,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAEnF,OAAO,EAAqB,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAG/D,mEAAmE;AACnE,KAAK,QAAQ,CAAC,CAAC,SAAS,SAAS,QAAQ,EAAE,IAAI;KAC5C,CAAC,IAAI,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/B,CAAC;AAEF;;;qEAGqE;AACrE,KAAK,SAAS,CAAC,MAAM,SAAS,SAAS,QAAQ,EAAE,IAC7C,OAAO,CAAC,MAAM,CAAC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/function.js
CHANGED
|
@@ -11,42 +11,75 @@
|
|
|
11
11
|
* graph, and its result is returned inline to the caller — nothing durable
|
|
12
12
|
* is written by a call. A function may declare inputs, as a stream task
|
|
13
13
|
* does: datasets of the workspace a call reads, each pinned at its hash,
|
|
14
|
-
* beside the arguments its caller passes.
|
|
14
|
+
* beside the arguments its caller passes. It may list the records among them
|
|
15
|
+
* a call may lay unsaved edits over, its drafts: the call reads each with its
|
|
16
|
+
* drafts laid over it, and saves nothing.
|
|
15
17
|
*/
|
|
16
18
|
import { validateEnvironmentDecl } from './environment.js';
|
|
17
19
|
import { East, Expr } from '@elaraai/east';
|
|
18
20
|
import { DEFAULT_RUNNER, runnerToVariant } from './runner.js';
|
|
21
|
+
import { isRecord } from './record.js';
|
|
19
22
|
import { refusePartitioned } from './task.js';
|
|
23
|
+
import { inputDataset, inputType, withIndexReaders } from './index-input.js';
|
|
20
24
|
export function function_(name, second, third) {
|
|
21
25
|
if (!name) {
|
|
22
26
|
throw new Error('e3.function requires a non-empty name');
|
|
23
27
|
}
|
|
24
28
|
if (second instanceof Expr) {
|
|
25
29
|
const config = third;
|
|
26
|
-
return define(name, second, [], config?.runner, config?.environment);
|
|
30
|
+
return define(name, second, [], [], config?.runner, config?.environment);
|
|
27
31
|
}
|
|
28
32
|
const spec = second;
|
|
33
|
+
refusePartitioned(`e3.function '${name}'`, spec.inputs, 'and a call runs as one unit');
|
|
29
34
|
const inputs = spec.inputs;
|
|
30
|
-
|
|
31
|
-
const datasets = inputs;
|
|
32
|
-
if (datasets.length > 0 && spec.runner?.runtime === 'custom') {
|
|
35
|
+
if (inputs.length > 0 && spec.runner?.runtime === 'custom') {
|
|
33
36
|
throw new Error(`e3.function '${name}': the custom runtime takes no inputs — ` +
|
|
34
37
|
`read them on a stock runtime (east-node, east-py, east-c), or pass them as arguments`);
|
|
35
38
|
}
|
|
39
|
+
const drafts = draftedRecords(`e3.function '${name}'`, spec.drafts ?? [], inputs);
|
|
36
40
|
// East gives the body an expression of each parameter's type: the inputs',
|
|
37
41
|
// in the spec's order, then the arguments'.
|
|
38
42
|
const body = third;
|
|
39
|
-
const parameters = [...
|
|
43
|
+
const parameters = [...inputs.map(inputType), ...spec.args];
|
|
40
44
|
const bodyFn = spec.async === true
|
|
41
|
-
? East.asyncFunction(parameters, spec.output, ($, ...params) => body($, ...params))
|
|
42
|
-
: East.function(parameters, spec.output, ($, ...params) => body($, ...params));
|
|
43
|
-
return define(name, bodyFn,
|
|
45
|
+
? East.asyncFunction(parameters, spec.output, ($, ...params) => body($, ...withIndexReaders(inputs, params)))
|
|
46
|
+
: East.function(parameters, spec.output, ($, ...params) => body($, ...withIndexReaders(inputs, params)));
|
|
47
|
+
return define(name, bodyFn, inputs, drafts, spec.runner, spec.environment);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The records a function lists in `drafts`, each once, in the order listed.
|
|
51
|
+
*
|
|
52
|
+
* @param owner - The function, as a refusal names it: `e3.function 'x'`
|
|
53
|
+
* @param listed - Its `drafts`, as declared
|
|
54
|
+
* @param inputs - Its inputs
|
|
55
|
+
* @returns The records
|
|
56
|
+
* @throws {Error} Naming the entry: one that is no record, or a record none
|
|
57
|
+
* of the inputs reads, itself or by an index of it
|
|
58
|
+
*/
|
|
59
|
+
function draftedRecords(owner, listed, inputs) {
|
|
60
|
+
const read = inputs.map(inputDataset);
|
|
61
|
+
const records = [];
|
|
62
|
+
for (const entry of listed) {
|
|
63
|
+
if (!isRecord(entry)) {
|
|
64
|
+
const named = entry?.name;
|
|
65
|
+
throw new Error(`${owner}: ${typeof named === 'string' ? `'${named}', listed in drafts,` : 'an entry of drafts'} is no record — ` +
|
|
66
|
+
`a draft is a call of a record's mutation that is not committed, so only an e3.record takes one`);
|
|
67
|
+
}
|
|
68
|
+
if (!read.includes(entry)) {
|
|
69
|
+
throw new Error(`${owner}: the record '${entry.name}', listed in drafts, is read by none of its inputs — ` +
|
|
70
|
+
`list it in inputs too, or an index of it, and a call reads it with its drafts laid over it`);
|
|
71
|
+
}
|
|
72
|
+
if (!records.includes(entry))
|
|
73
|
+
records.push(entry);
|
|
74
|
+
}
|
|
75
|
+
return records;
|
|
44
76
|
}
|
|
45
77
|
/**
|
|
46
78
|
* The definition of a function: its body's IR and signature, the inputs it
|
|
47
|
-
* reads, which come first among its parameters,
|
|
79
|
+
* reads, which come first among its parameters, the records among them a
|
|
80
|
+
* call may draft, and what the inputs depend on.
|
|
48
81
|
*/
|
|
49
|
-
function define(name, fn, inputs, runner, environment) {
|
|
82
|
+
function define(name, fn, inputs, drafts, runner, environment) {
|
|
50
83
|
const resolved = runner ?? DEFAULT_RUNNER;
|
|
51
84
|
if (environment)
|
|
52
85
|
validateEnvironmentDecl(environment, name);
|
|
@@ -56,8 +89,9 @@ function define(name, fn, inputs, runner, environment) {
|
|
|
56
89
|
// with encodeEastIR and preserve source locations.
|
|
57
90
|
const eastIR = fn.toIR();
|
|
58
91
|
const fnType = Expr.type(fn);
|
|
92
|
+
// An index's record is collected as any input is.
|
|
59
93
|
const deps = new Set();
|
|
60
|
-
for (const input of inputs) {
|
|
94
|
+
for (const input of inputs.map(inputDataset)) {
|
|
61
95
|
for (const dep of input.deps)
|
|
62
96
|
deps.add(dep);
|
|
63
97
|
deps.add(input);
|
|
@@ -67,6 +101,7 @@ function define(name, fn, inputs, runner, environment) {
|
|
|
67
101
|
name,
|
|
68
102
|
body: eastIR,
|
|
69
103
|
inputs,
|
|
104
|
+
drafts,
|
|
70
105
|
argTypes: fnType.inputs.slice(inputs.length),
|
|
71
106
|
outputType: fnType.output,
|
|
72
107
|
runner: resolved,
|
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;;;;;;;;;;;;GAYG;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,MAAM;QACN,MAAM;QACN,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;QAC5C,UAAU,EAAE,MAAM,CAAC,MAAM;QACzB,MAAM,EAAE,QAAQ;QAChB,WAAW;QACX,IAAI;KACL,CAAC;AACJ,CAAC"}
|
|
@@ -2,5 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
3
|
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
import { IntegerType, StringType } from '@elaraai/east';
|
|
6
|
+
import type { FunctionDef } from './types.js';
|
|
7
|
+
export declare const exportedDrafted: FunctionDef<[StringType], IntegerType, true>;
|
|
6
8
|
//# sourceMappingURL=function.spec.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function.spec.d.ts","sourceRoot":"","sources":["../../src/function.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
1
|
+
{"version":3,"file":"function.spec.d.ts","sourceRoot":"","sources":["../../src/function.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,EAGL,WAAW,EAEX,UAAU,EAUX,MAAM,eAAe,CAAC;AAmBvB,OAAO,KAAK,EAAE,WAAW,EAAuB,MAAM,YAAY,CAAC;AAoDnE,eAAO,MAAM,eAAe,8CAKQ,CAAC"}
|