@sasjs/api 0.16.0 → 0.17.1
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/README.md +3 -2
- package/build/browser.js +668 -87
- package/build/cjs/corpus/runner.js +19 -2
- package/build/cjs/corpus/runtime.js +238 -0
- package/build/cjs/corpus/session.js +1 -1
- package/build/cjs/host/dispatch.js +115 -1
- package/build/cjs/index.js +9 -1
- package/build/cjs/routes/generated.js +40 -0
- package/build/cjs/routes/overlay.js +18 -6
- package/build/cjs/runtime/memory-runner.js +59 -0
- package/build/cjs/runtime/service.js +303 -0
- package/build/cjs/session/memory-host.js +22 -5
- package/build/esm/corpus/drive.d.ts +13 -0
- package/build/esm/corpus/drive.d.ts.map +1 -1
- package/build/esm/corpus/runner.d.ts.map +1 -1
- package/build/esm/corpus/runner.js +19 -2
- package/build/esm/corpus/runtime.d.ts +17 -0
- package/build/esm/corpus/runtime.d.ts.map +1 -0
- package/build/esm/corpus/runtime.js +235 -0
- package/build/esm/corpus/session.js +1 -1
- package/build/esm/host/dispatch.d.ts +15 -0
- package/build/esm/host/dispatch.d.ts.map +1 -1
- package/build/esm/host/dispatch.js +115 -1
- package/build/esm/index.d.ts +6 -1
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js +3 -0
- package/build/esm/routes/generated.d.ts.map +1 -1
- package/build/esm/routes/generated.js +40 -0
- package/build/esm/routes/overlay.d.ts.map +1 -1
- package/build/esm/routes/overlay.js +18 -6
- package/build/esm/runtime/memory-runner.d.ts +38 -0
- package/build/esm/runtime/memory-runner.d.ts.map +1 -0
- package/build/esm/runtime/memory-runner.js +55 -0
- package/build/esm/runtime/service.d.ts +185 -0
- package/build/esm/runtime/service.d.ts.map +1 -0
- package/build/esm/runtime/service.js +298 -0
- package/build/esm/session/memory-host.d.ts +13 -2
- package/build/esm/session/memory-host.d.ts.map +1 -1
- package/build/esm/session/memory-host.js +22 -5
- package/build/esm/session/service.d.ts +12 -1
- package/build/esm/session/service.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
const ADMIN = { userId: 'user-admin', clientId: 'web_app' };
|
|
2
|
+
const PROGRAM = '/Public/apps/demo/run.sas';
|
|
3
|
+
const CODE = 'data _null_;\n put "hello";\nrun;';
|
|
4
|
+
const UNAUTHORIZED = 'Unauthorized';
|
|
5
|
+
const FAILED = 'Job execution failed.';
|
|
6
|
+
/** Bytes without an encoding API, as the drive corpus has them. */
|
|
7
|
+
const bytes = (...values) => Uint8Array.from(values);
|
|
8
|
+
export const RUNTIME_CORPUS = [
|
|
9
|
+
// ------------------------------------------------- GET /stp/execute
|
|
10
|
+
{
|
|
11
|
+
id: 'stp-execute-get-answers-output',
|
|
12
|
+
route: 'GET /SASjsApi/stp/execute',
|
|
13
|
+
description: 'answers the output the program produced',
|
|
14
|
+
request: { subject: ADMIN, query: { _program: PROGRAM } },
|
|
15
|
+
runOutput: { contents: 'hello from the program' },
|
|
16
|
+
expect: { status: 200, contents: 'hello from the program' }
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: 'stp-execute-get-answers-bytes',
|
|
20
|
+
route: 'GET /SASjsApi/stp/execute',
|
|
21
|
+
description: 'answers an output that is bytes as bytes',
|
|
22
|
+
request: { subject: ADMIN, query: { _program: PROGRAM } },
|
|
23
|
+
runOutput: { contents: bytes(1, 2, 3) },
|
|
24
|
+
expect: { status: 200, contents: bytes(1, 2, 3) }
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: 'stp-execute-get-missing-program',
|
|
28
|
+
route: 'GET /SASjsApi/stp/execute',
|
|
29
|
+
description: 'refuses a request that names no program',
|
|
30
|
+
request: { subject: ADMIN, query: {} },
|
|
31
|
+
expect: { status: 400, error: '"_program" is required' }
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: 'stp-execute-get-failed-run',
|
|
35
|
+
route: 'GET /SASjsApi/stp/execute',
|
|
36
|
+
description: 'answers 400 when the program could not be run',
|
|
37
|
+
request: { subject: ADMIN, query: { _program: PROGRAM } },
|
|
38
|
+
failingRun: true,
|
|
39
|
+
expect: { status: 400, error: FAILED }
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'stp-execute-get-unauthenticated',
|
|
43
|
+
route: 'GET /SASjsApi/stp/execute',
|
|
44
|
+
description: 'refuses a caller with no token',
|
|
45
|
+
request: { query: { _program: PROGRAM } },
|
|
46
|
+
expect: { status: 401, error: UNAUTHORIZED }
|
|
47
|
+
},
|
|
48
|
+
// ------------------------------------------------ POST /stp/execute
|
|
49
|
+
{
|
|
50
|
+
id: 'stp-execute-post-body-program',
|
|
51
|
+
route: 'POST /SASjsApi/stp/execute',
|
|
52
|
+
description: 'runs the program the body names',
|
|
53
|
+
request: { subject: ADMIN, body: { _program: PROGRAM } },
|
|
54
|
+
runOutput: { contents: 'hello from the body' },
|
|
55
|
+
expect: { status: 200, contents: 'hello from the body' }
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: 'stp-execute-post-query-program',
|
|
59
|
+
route: 'POST /SASjsApi/stp/execute',
|
|
60
|
+
description: 'runs the program the query names, with no body',
|
|
61
|
+
request: { subject: ADMIN, query: { _program: PROGRAM }, body: {} },
|
|
62
|
+
runOutput: { contents: 'hello from the query' },
|
|
63
|
+
expect: { status: 200, contents: 'hello from the query' }
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: 'stp-execute-post-no-program',
|
|
67
|
+
route: 'POST /SASjsApi/stp/execute',
|
|
68
|
+
description: 'refuses a request with no program in the query or the body',
|
|
69
|
+
request: { subject: ADMIN, body: {} },
|
|
70
|
+
expect: { status: 400, error: '"_program" is required' }
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: 'stp-execute-post-failed-run',
|
|
74
|
+
route: 'POST /SASjsApi/stp/execute',
|
|
75
|
+
description: 'answers 400 when the program could not be run',
|
|
76
|
+
request: { subject: ADMIN, body: { _program: PROGRAM } },
|
|
77
|
+
failingRun: true,
|
|
78
|
+
expect: { status: 400, error: FAILED }
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: 'stp-execute-post-unauthenticated',
|
|
82
|
+
route: 'POST /SASjsApi/stp/execute',
|
|
83
|
+
description: 'refuses a caller with no token, before it reads the payload',
|
|
84
|
+
request: { body: {} },
|
|
85
|
+
expect: { status: 401, error: UNAUTHORIZED }
|
|
86
|
+
},
|
|
87
|
+
// ------------------------------------------------ POST /stp/trigger
|
|
88
|
+
{
|
|
89
|
+
id: 'stp-trigger-answers-session',
|
|
90
|
+
route: 'POST /SASjsApi/stp/trigger',
|
|
91
|
+
description: 'answers the session a caller polls, and no pid from a mock',
|
|
92
|
+
request: { subject: ADMIN, query: { _program: PROGRAM } },
|
|
93
|
+
expect: { status: 200, keys: ['sessionId'] }
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: 'stp-trigger-retention',
|
|
97
|
+
route: 'POST /SASjsApi/stp/trigger',
|
|
98
|
+
description: 'accepts a retention in minutes, as the query carries it',
|
|
99
|
+
request: {
|
|
100
|
+
subject: ADMIN,
|
|
101
|
+
query: { _program: PROGRAM, expiresAfterMins: '15' }
|
|
102
|
+
},
|
|
103
|
+
expect: { status: 200, keys: ['sessionId'] }
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: 'stp-trigger-retention-not-positive',
|
|
107
|
+
route: 'POST /SASjsApi/stp/trigger',
|
|
108
|
+
description: 'refuses a retention that is not a positive number of minutes',
|
|
109
|
+
request: {
|
|
110
|
+
subject: ADMIN,
|
|
111
|
+
query: { _program: PROGRAM, expiresAfterMins: '0' }
|
|
112
|
+
},
|
|
113
|
+
expect: { status: 400, error: '"expiresAfterMins" must be greater than 0' }
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
id: 'stp-trigger-missing-program',
|
|
117
|
+
route: 'POST /SASjsApi/stp/trigger',
|
|
118
|
+
description: 'refuses a request that names no program',
|
|
119
|
+
request: { subject: ADMIN, query: {} },
|
|
120
|
+
expect: { status: 400, error: '"_program" is required' }
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: 'stp-trigger-failed-run',
|
|
124
|
+
route: 'POST /SASjsApi/stp/trigger',
|
|
125
|
+
description: 'answers 400 when the program could not be started',
|
|
126
|
+
request: { subject: ADMIN, query: { _program: PROGRAM } },
|
|
127
|
+
failingRun: true,
|
|
128
|
+
expect: { status: 400, error: FAILED }
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
id: 'stp-trigger-unauthenticated',
|
|
132
|
+
route: 'POST /SASjsApi/stp/trigger',
|
|
133
|
+
description: 'refuses a caller with no token',
|
|
134
|
+
request: { query: { _program: PROGRAM } },
|
|
135
|
+
expect: { status: 401, error: UNAUTHORIZED }
|
|
136
|
+
},
|
|
137
|
+
// ----------------------------------------------- POST /code/execute
|
|
138
|
+
{
|
|
139
|
+
id: 'code-execute-answers-output',
|
|
140
|
+
route: 'POST /SASjsApi/code/execute',
|
|
141
|
+
description: 'runs the code in the body and answers its output',
|
|
142
|
+
request: { subject: ADMIN, body: { code: CODE, runTime: 'sas' } },
|
|
143
|
+
runOutput: { contents: 'NOTE: mock run' },
|
|
144
|
+
expect: { status: 200, contents: 'NOTE: mock run' }
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
// The refusal's *message* is not pinned here: it names the run times the
|
|
148
|
+
// host holds, which is deployment data - `r` is a valid request where R is
|
|
149
|
+
// configured and a 400 where it is not - so a corpus that stated a list
|
|
150
|
+
// would be asserting one host's install. `spec/runtime.spec.ts` pins the
|
|
151
|
+
// wording against an explicit list; this states the status every host sends
|
|
152
|
+
// for a name no host holds.
|
|
153
|
+
id: 'code-execute-unknown-runtime',
|
|
154
|
+
route: 'POST /SASjsApi/code/execute',
|
|
155
|
+
description: 'refuses a run time the document does not name',
|
|
156
|
+
request: { subject: ADMIN, body: { code: CODE, runTime: 'cobol' } },
|
|
157
|
+
expect: { status: 400 }
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
id: 'code-execute-missing-code',
|
|
161
|
+
route: 'POST /SASjsApi/code/execute',
|
|
162
|
+
description: 'refuses a payload with no code',
|
|
163
|
+
request: { subject: ADMIN, body: { runTime: 'sas' } },
|
|
164
|
+
expect: { status: 400, error: '"code" is required' }
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
id: 'code-execute-empty-code',
|
|
168
|
+
route: 'POST /SASjsApi/code/execute',
|
|
169
|
+
description: 'refuses code that is present but empty',
|
|
170
|
+
request: { subject: ADMIN, body: { code: '', runTime: 'sas' } },
|
|
171
|
+
expect: { status: 400, error: '"code" is not allowed to be empty' }
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
id: 'code-execute-non-string-code',
|
|
175
|
+
route: 'POST /SASjsApi/code/execute',
|
|
176
|
+
description: 'refuses code that is not a string rather than running its text',
|
|
177
|
+
request: { subject: ADMIN, body: { code: 123, runTime: 'sas' } },
|
|
178
|
+
expect: { status: 400, error: '"code" must be a string' }
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
id: 'code-execute-failed-run',
|
|
182
|
+
route: 'POST /SASjsApi/code/execute',
|
|
183
|
+
description: 'answers 400 when the code could not be run',
|
|
184
|
+
request: { subject: ADMIN, body: { code: CODE, runTime: 'sas' } },
|
|
185
|
+
failingRun: true,
|
|
186
|
+
expect: { status: 400, error: FAILED }
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
id: 'code-execute-unauthenticated',
|
|
190
|
+
route: 'POST /SASjsApi/code/execute',
|
|
191
|
+
description: 'refuses a caller with no token, before it reads the payload',
|
|
192
|
+
request: { body: {} },
|
|
193
|
+
expect: { status: 401, error: UNAUTHORIZED }
|
|
194
|
+
},
|
|
195
|
+
// ----------------------------------------------- POST /code/trigger
|
|
196
|
+
{
|
|
197
|
+
id: 'code-trigger-answers-session',
|
|
198
|
+
route: 'POST /SASjsApi/code/trigger',
|
|
199
|
+
description: 'answers the session a caller polls, and no pid from a mock',
|
|
200
|
+
request: { subject: ADMIN, body: { code: CODE, runTime: 'sas' } },
|
|
201
|
+
expect: { status: 200, keys: ['sessionId'] }
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
id: 'code-trigger-missing-runtime',
|
|
205
|
+
route: 'POST /SASjsApi/code/trigger',
|
|
206
|
+
description: 'refuses a payload with no run time, which the document requires',
|
|
207
|
+
request: { subject: ADMIN, body: { code: CODE } },
|
|
208
|
+
expect: { status: 400, error: '"runTime" is required' }
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
id: 'code-trigger-retention-not-positive',
|
|
212
|
+
route: 'POST /SASjsApi/code/trigger',
|
|
213
|
+
description: 'refuses a retention that is not a positive number of minutes',
|
|
214
|
+
request: {
|
|
215
|
+
subject: ADMIN,
|
|
216
|
+
body: { code: CODE, runTime: 'sas', expiresAfterMins: 0 }
|
|
217
|
+
},
|
|
218
|
+
expect: { status: 400, error: '"expiresAfterMins" must be greater than 0' }
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
id: 'code-trigger-failed-run',
|
|
222
|
+
route: 'POST /SASjsApi/code/trigger',
|
|
223
|
+
description: 'answers 400 when the code could not be started',
|
|
224
|
+
request: { subject: ADMIN, body: { code: CODE, runTime: 'sas' } },
|
|
225
|
+
failingRun: true,
|
|
226
|
+
expect: { status: 400, error: FAILED }
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
id: 'code-trigger-unauthenticated',
|
|
230
|
+
route: 'POST /SASjsApi/code/trigger',
|
|
231
|
+
description: 'refuses a caller with no token',
|
|
232
|
+
request: { body: { code: CODE, runTime: 'sas' } },
|
|
233
|
+
expect: { status: 401, error: UNAUTHORIZED }
|
|
234
|
+
}
|
|
235
|
+
];
|
|
@@ -2,6 +2,7 @@ import type { DriveService } from '../drive/service.js';
|
|
|
2
2
|
import type { IdentityService } from '../identity/service.js';
|
|
3
3
|
import type { RecordService } from '../identity/records.js';
|
|
4
4
|
import type { SessionService } from '../session/service.js';
|
|
5
|
+
import type { RuntimeService } from '../runtime/service.js';
|
|
5
6
|
import type { AppStreamRegistry } from '../drive/registry.js';
|
|
6
7
|
import type { CodeService } from '../code/service.js';
|
|
7
8
|
import type { Subject } from '../identity/types.js';
|
|
@@ -19,6 +20,15 @@ export interface ApiRequest {
|
|
|
19
20
|
name: string;
|
|
20
21
|
contents: string | Uint8Array;
|
|
21
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* The multipart payload under the field names the caller chose, which is what
|
|
25
|
+
* the execute routes receive: the program sees each file as a session variable.
|
|
26
|
+
* A host that carries one file may pass `file` instead.
|
|
27
|
+
*/
|
|
28
|
+
files?: Array<{
|
|
29
|
+
name: string;
|
|
30
|
+
contents: string | Uint8Array;
|
|
31
|
+
}>;
|
|
22
32
|
/**
|
|
23
33
|
* The bearer token the request carried, for the routes that name their caller
|
|
24
34
|
* in a header rather than a body. A host that already resolved the caller - a
|
|
@@ -52,6 +62,11 @@ export interface Services {
|
|
|
52
62
|
* answers 501 for these four, naming the capability.
|
|
53
63
|
*/
|
|
54
64
|
session?: SessionService;
|
|
65
|
+
/**
|
|
66
|
+
* The execute and trigger routes, over the host's runner. Absent, they answer
|
|
67
|
+
* 501: the package can decide everything about a run except performing it.
|
|
68
|
+
*/
|
|
69
|
+
runtime?: RuntimeService;
|
|
55
70
|
/**
|
|
56
71
|
* The app streams a host has published. Absent, `DELETE /drive/deploy`
|
|
57
72
|
* answers 501 - the package cannot know a host's stream registry.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../../src/host/dispatch.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO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QAAQ,EAAE,MAAM,GAAG,UAAU,CAAA;KAAE,CAAC,CAAA;IAC9D;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,iEAAiE;IACjE,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,mBAAmB;IACnB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,uEAAuE;IACvE,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;CAC/B;AAED,MAAM,WAAW,QAAQ;IACvB,2DAA2D;IAC3D,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,YAAY,CAAA;IACnB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAA;IAC1B,yFAAyF;IACzF,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;;OAGG;IACH,QAAQ,CAAC,EAAE,iBAAiB,CAAA;CAC7B;AA2CD,eAAO,MAAM,QAAQ,GACnB,UAAU,QAAQ,EAClB,SAAS,MAAM,EACf,UAAS,UAAe,KACvB,OAAO,CAAC,WAAW,CA8jBrB,CAAA;AAED,0DAA0D;AAC1D,eAAO,MAAM,cAAc,EAAE,MAAM,EAuDlC,CAAA"}
|
|
@@ -4,6 +4,22 @@ import { ApiError } from '../types.js';
|
|
|
4
4
|
import { DEPLOY_SUCCESS } from '../drive/deploy.js';
|
|
5
5
|
/** The defaults sasjs/server's Client schema applies to an omitted lifetime. */
|
|
6
6
|
const SECONDS_IN_A_DAY = 86400;
|
|
7
|
+
/**
|
|
8
|
+
* The routes that perform work, and so find their caller before they read the
|
|
9
|
+
* payload.
|
|
10
|
+
*
|
|
11
|
+
* sasjs/server mounts `authenticateAccessToken` ahead of the router that owns
|
|
12
|
+
* these, so an anonymous request with an invalid program is a `401` there and
|
|
13
|
+
* would be a `400` here if the schema ran first. The same ordering is observable
|
|
14
|
+
* on the record routes, which is why both are resolved in one place.
|
|
15
|
+
*/
|
|
16
|
+
const RUN_ROUTES = [
|
|
17
|
+
'GET /SASjsApi/stp/execute',
|
|
18
|
+
'POST /SASjsApi/stp/execute',
|
|
19
|
+
'POST /SASjsApi/stp/trigger',
|
|
20
|
+
'POST /SASjsApi/code/execute',
|
|
21
|
+
'POST /SASjsApi/code/trigger'
|
|
22
|
+
];
|
|
7
23
|
/**
|
|
8
24
|
* The parameters the table marks required, checked before the handler runs.
|
|
9
25
|
*
|
|
@@ -54,7 +70,11 @@ export const dispatch = async (services, routeId, request = {}) => {
|
|
|
54
70
|
// flow has no caller by definition, and the drive has no identity at all.
|
|
55
71
|
const identityScoped = ['User', 'Group', 'Permission', 'Client'].includes(route.tag) ||
|
|
56
72
|
routeId === 'PATCH /SASjsApi/auth/updatePassword';
|
|
57
|
-
|
|
73
|
+
// A host that answers the run routes must have a runner; without one it is
|
|
74
|
+
// told which capability it is missing rather than sent round a login loop, so
|
|
75
|
+
// the gate is tested on the service that serves the route.
|
|
76
|
+
const runtimeScoped = RUN_ROUTES.includes(routeId);
|
|
77
|
+
if ((identityScoped && records) || (runtimeScoped && services.runtime)) {
|
|
58
78
|
const subject = request.subject ??
|
|
59
79
|
(identity ? await identity.authenticate(request.token) : undefined);
|
|
60
80
|
if (!subject) {
|
|
@@ -78,6 +98,39 @@ export const dispatch = async (services, routeId, request = {}) => {
|
|
|
78
98
|
throw new ApiError(501, `This host has no session service, so it cannot answer ${routeId}.`);
|
|
79
99
|
return services.session;
|
|
80
100
|
};
|
|
101
|
+
/** The runtime service, or the 501 a host without a runner answers. */
|
|
102
|
+
const runtimeRequired = () => {
|
|
103
|
+
if (!services.runtime)
|
|
104
|
+
throw new ApiError(501, `This host has no runtime service, so it cannot answer ${routeId}.`);
|
|
105
|
+
return services.runtime;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* The files a multipart request carried, by field name.
|
|
109
|
+
*
|
|
110
|
+
* A host with one file passes `file`; one with several passes `files`, because
|
|
111
|
+
* the field names are the caller's and a program reads them as session
|
|
112
|
+
* variables.
|
|
113
|
+
*/
|
|
114
|
+
const uploaded = () => {
|
|
115
|
+
const files = request.files || (request.file ? [request.file] : []);
|
|
116
|
+
if (!files.length)
|
|
117
|
+
return undefined;
|
|
118
|
+
return files.reduce((byName, file) => {
|
|
119
|
+
byName[file.name] = file.contents;
|
|
120
|
+
return byName;
|
|
121
|
+
}, {});
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* A program's output travels as the response body, bytes or not.
|
|
125
|
+
*
|
|
126
|
+
* The same shape `GET /session/{sessionId}/output` answers with, and for the
|
|
127
|
+
* same reason: the body is the artefact, not a value the API composed, so it
|
|
128
|
+
* is handed on as it came rather than wrapped in a JSON string.
|
|
129
|
+
*/
|
|
130
|
+
const artifact = (output) => ({
|
|
131
|
+
status: 200,
|
|
132
|
+
contents: output.contents
|
|
133
|
+
});
|
|
81
134
|
const required = () => {
|
|
82
135
|
if (!records)
|
|
83
136
|
throw new ApiError(501, `This host has no record service, so it cannot answer ${routeId}.`);
|
|
@@ -187,6 +240,62 @@ export const dispatch = async (services, routeId, request = {}) => {
|
|
|
187
240
|
};
|
|
188
241
|
case 'GET /SASjsApi/drive/filetree':
|
|
189
242
|
return { status: 200, body: await drive.tree(query._folderPath) };
|
|
243
|
+
// ------------------------------------------------------------- run times
|
|
244
|
+
//
|
|
245
|
+
// A stored program is named by a drive path and a code buffer travels in the
|
|
246
|
+
// body; either way the package decides everything about the request and the
|
|
247
|
+
// host's runner does the work.
|
|
248
|
+
case 'GET /SASjsApi/stp/execute': {
|
|
249
|
+
const output = await runtimeRequired().execute(await caller(), {
|
|
250
|
+
source: 'program',
|
|
251
|
+
program: query._program,
|
|
252
|
+
vars: { ...query },
|
|
253
|
+
files: uploaded()
|
|
254
|
+
});
|
|
255
|
+
return artifact(output);
|
|
256
|
+
}
|
|
257
|
+
case 'POST /SASjsApi/stp/execute': {
|
|
258
|
+
// the query wins over the body, which is the order the server resolves
|
|
259
|
+
// them in: an empty query value is absent in every sense that matters
|
|
260
|
+
const output = await runtimeRequired().execute(await caller(), {
|
|
261
|
+
source: 'program',
|
|
262
|
+
program: query._program || body._program,
|
|
263
|
+
vars: { ...query, ...body },
|
|
264
|
+
files: uploaded()
|
|
265
|
+
});
|
|
266
|
+
return artifact(output);
|
|
267
|
+
}
|
|
268
|
+
case 'POST /SASjsApi/stp/trigger':
|
|
269
|
+
return {
|
|
270
|
+
status: 200,
|
|
271
|
+
body: await runtimeRequired().trigger(await caller(), {
|
|
272
|
+
source: 'program',
|
|
273
|
+
program: query._program,
|
|
274
|
+
vars: { ...query },
|
|
275
|
+
expiresAfterMins: query.expiresAfterMins
|
|
276
|
+
})
|
|
277
|
+
};
|
|
278
|
+
case 'POST /SASjsApi/code/execute': {
|
|
279
|
+
const output = await runtimeRequired().execute(await caller(), {
|
|
280
|
+
source: 'code',
|
|
281
|
+
code: body.code,
|
|
282
|
+
runTime: body.runTime,
|
|
283
|
+
vars: { ...query, ...body },
|
|
284
|
+
files: uploaded()
|
|
285
|
+
});
|
|
286
|
+
return artifact(output);
|
|
287
|
+
}
|
|
288
|
+
case 'POST /SASjsApi/code/trigger':
|
|
289
|
+
return {
|
|
290
|
+
status: 200,
|
|
291
|
+
body: await runtimeRequired().trigger(await caller(), {
|
|
292
|
+
source: 'code',
|
|
293
|
+
code: body.code,
|
|
294
|
+
runTime: body.runTime,
|
|
295
|
+
vars: { ...query, ...body },
|
|
296
|
+
expiresAfterMins: body.expiresAfterMins
|
|
297
|
+
})
|
|
298
|
+
};
|
|
190
299
|
// ------------------------------------------------------------- sessions
|
|
191
300
|
case 'GET /SASjsApi/session/{sessionId}': {
|
|
192
301
|
return {
|
|
@@ -399,6 +508,11 @@ export const dispatch = async (services, routeId, request = {}) => {
|
|
|
399
508
|
export const HANDLED_ROUTES = [
|
|
400
509
|
'POST /SASjsApi/drive/deploy/upload',
|
|
401
510
|
'DELETE /SASjsApi/drive/deploy',
|
|
511
|
+
'GET /SASjsApi/stp/execute',
|
|
512
|
+
'POST /SASjsApi/stp/execute',
|
|
513
|
+
'POST /SASjsApi/stp/trigger',
|
|
514
|
+
'POST /SASjsApi/code/execute',
|
|
515
|
+
'POST /SASjsApi/code/trigger',
|
|
402
516
|
'GET /SASjsApi/session/{sessionId}',
|
|
403
517
|
'GET /SASjsApi/session/{sessionId}/log',
|
|
404
518
|
'GET /SASjsApi/session/{sessionId}/output',
|
package/build/esm/index.d.ts
CHANGED
|
@@ -41,8 +41,13 @@ export { IDENTITY_CORPUS } from './corpus/identity.js';
|
|
|
41
41
|
export { DEPLOY_CORPUS } from './corpus/deploy.js';
|
|
42
42
|
export { SESSION_CORPUS } from './corpus/session.js';
|
|
43
43
|
export { createSessionService } from './session/service.js';
|
|
44
|
-
export type { CallerDirectory, HostSession, SessionHost, SessionService, SessionStateResponse, SessionSummary } from './session/service.js';
|
|
44
|
+
export type { CallerDirectory, HostSession, SessionArtifact, SessionHost, SessionService, SessionStateResponse, SessionSummary } from './session/service.js';
|
|
45
45
|
export { DEFAULT_SESSIONS, MemorySessionHost } from './session/memory-host.js';
|
|
46
|
+
export { CODE_DEBUG, DOCUMENTED_RUN_TIMES, createRuntimeService } from './runtime/service.js';
|
|
47
|
+
export type { ProgramSource, RunOutcome, RunRequest, RunnerSession, RuntimeRequest, RuntimeService, RuntimeServiceOptions, SessionRunner, TriggerResponse } from './runtime/service.js';
|
|
48
|
+
export { MemorySessionRunner } from './runtime/memory-runner.js';
|
|
49
|
+
export type { MemoryRunnerOptions } from './runtime/memory-runner.js';
|
|
50
|
+
export { RUNTIME_CORPUS } from './corpus/runtime.js';
|
|
46
51
|
export { MemoryAppStreamRegistry, unpublishAppStream } from './drive/registry.js';
|
|
47
52
|
export type { AppStreamRegistry, UnpublishBody } from './drive/registry.js';
|
|
48
53
|
export { RECORD_CORPUS, ADMIN_SIGNED_IN, PROVIDER_MANAGED } from './corpus/records.js';
|
package/build/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,cAAc,YAAY,CAAA;AAC1B,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,OAAO,EACP,QAAQ,EACR,MAAM,EACP,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,iBAAiB,EAClB,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EACV,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,UAAU,EACX,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EACV,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,SAAS,EACT,SAAS,EACV,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAChE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAC/D,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAG7D,cAAc,2BAA2B,CAAA;AACzC,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EA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B,CAAA;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,YAAY,EACV,eAAe,EACf,WAAW,EACX,eAAe,EACf,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,cAAc,EACf,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC9E,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,sBAAsB,CAAA;AAC7B,YAAY,EACV,aAAa,EACb,UAAU,EACV,UAAU,EACV,aAAa,EACb,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,aAAa,EACb,eAAe,EAChB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAChE,YAAY,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC3E,OAAO,EACL,aAAa,EACb,eAAe,EACf,gBAAgB,EACjB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACzD,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA"}
|
package/build/esm/index.js
CHANGED
|
@@ -34,6 +34,9 @@ export { DEPLOY_CORPUS } from './corpus/deploy.js';
|
|
|
34
34
|
export { SESSION_CORPUS } from './corpus/session.js';
|
|
35
35
|
export { createSessionService } from './session/service.js';
|
|
36
36
|
export { DEFAULT_SESSIONS, MemorySessionHost } from './session/memory-host.js';
|
|
37
|
+
export { CODE_DEBUG, DOCUMENTED_RUN_TIMES, createRuntimeService } from './runtime/service.js';
|
|
38
|
+
export { MemorySessionRunner } from './runtime/memory-runner.js';
|
|
39
|
+
export { RUNTIME_CORPUS } from './corpus/runtime.js';
|
|
37
40
|
export { MemoryAppStreamRegistry, unpublishAppStream } from './drive/registry.js';
|
|
38
41
|
export { RECORD_CORPUS, ADMIN_SIGNED_IN, PROVIDER_MANAGED } from './corpus/records.js';
|
|
39
42
|
export { runCase, servicesFor } from './corpus/runner.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generated.d.ts","sourceRoot":"","sources":["../../../src/routes/generated.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,eAAO,MAAM,gBAAgB,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"generated.d.ts","sourceRoot":"","sources":["../../../src/routes/generated.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,eAAO,MAAM,gBAAgB,EAAE,cAAc,EAy9D5C,CAAA"}
|
|
@@ -316,6 +316,14 @@ export const GENERATED_ROUTES = [
|
|
|
316
316
|
{
|
|
317
317
|
status: 200,
|
|
318
318
|
description: 'Ok'
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
status: 400,
|
|
322
|
+
description: 'Invalid request: the payload is invalid, or the program could not be run'
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
status: 401,
|
|
326
|
+
description: 'Unauthorized'
|
|
319
327
|
}
|
|
320
328
|
]
|
|
321
329
|
},
|
|
@@ -422,6 +430,14 @@ export const GENERATED_ROUTES = [
|
|
|
422
430
|
{
|
|
423
431
|
status: 200,
|
|
424
432
|
description: 'Ok'
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
status: 400,
|
|
436
|
+
description: 'Invalid request: the payload is invalid, or the program could not be run'
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
status: 401,
|
|
440
|
+
description: 'Unauthorized'
|
|
425
441
|
}
|
|
426
442
|
]
|
|
427
443
|
},
|
|
@@ -1428,6 +1444,14 @@ export const GENERATED_ROUTES = [
|
|
|
1428
1444
|
{
|
|
1429
1445
|
status: 200,
|
|
1430
1446
|
description: 'Ok'
|
|
1447
|
+
},
|
|
1448
|
+
{
|
|
1449
|
+
status: 400,
|
|
1450
|
+
description: 'Invalid request: the query parameters are invalid, or the program could not be run'
|
|
1451
|
+
},
|
|
1452
|
+
{
|
|
1453
|
+
status: 401,
|
|
1454
|
+
description: 'Unauthorized'
|
|
1431
1455
|
}
|
|
1432
1456
|
]
|
|
1433
1457
|
},
|
|
@@ -1456,6 +1480,14 @@ export const GENERATED_ROUTES = [
|
|
|
1456
1480
|
{
|
|
1457
1481
|
status: 200,
|
|
1458
1482
|
description: 'Ok'
|
|
1483
|
+
},
|
|
1484
|
+
{
|
|
1485
|
+
status: 400,
|
|
1486
|
+
description: 'Invalid request: the payload is invalid, or the program could not be run'
|
|
1487
|
+
},
|
|
1488
|
+
{
|
|
1489
|
+
status: 401,
|
|
1490
|
+
description: 'Unauthorized'
|
|
1459
1491
|
}
|
|
1460
1492
|
]
|
|
1461
1493
|
},
|
|
@@ -1490,6 +1522,14 @@ export const GENERATED_ROUTES = [
|
|
|
1490
1522
|
{
|
|
1491
1523
|
status: 200,
|
|
1492
1524
|
description: 'Ok'
|
|
1525
|
+
},
|
|
1526
|
+
{
|
|
1527
|
+
status: 400,
|
|
1528
|
+
description: 'Invalid request: the payload is invalid, or the program could not be run'
|
|
1529
|
+
},
|
|
1530
|
+
{
|
|
1531
|
+
status: 401,
|
|
1532
|
+
description: 'Unauthorized'
|
|
1493
1533
|
}
|
|
1494
1534
|
]
|
|
1495
1535
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../../../src/routes/overlay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAGzD,yDAAyD;AACzD,UAAU,aAAa;IACrB,YAAY,CAAC,EAAE,UAAU,EAAE,CAAA;IAC3B;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACpC;AAED;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,aAAa,GACtC,CAAC;IAAE,WAAW,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,WAAW,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAElE,kFAAkF;AAClF,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAczD,CAAA;
|
|
1
|
+
{"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../../../src/routes/overlay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAGzD,yDAAyD;AACzD,UAAU,aAAa;IACrB,YAAY,CAAC,EAAE,UAAU,EAAE,CAAA;IAC3B;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACpC;AAED;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,aAAa,GACtC,CAAC;IAAE,WAAW,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,WAAW,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAElE,kFAAkF;AAClF,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAczD,CAAA;AA+BD,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAuNhD,CAAA;AAED,wEAAwE;AACxE,eAAO,MAAM,OAAO,EAAE,UAAU,EAA8C,CAAA"}
|
|
@@ -23,7 +23,6 @@ export const TAG_CAPABILITIES = {
|
|
|
23
23
|
* thing thirty times.
|
|
24
24
|
*/
|
|
25
25
|
const DIRECTORY = 'Synchronising with an external auth provider needs a directory port, which this package does not have: a host decides which directory it holds accounts in, and answers this itself.';
|
|
26
|
-
const RUNTIME = 'Starting a program needs a runtime port, which this package does not have: a host decides which languages it holds, and answers this itself until then.';
|
|
27
26
|
const HOST_CONFIG = "The body is the host's own configuration - ports, run times and providers - which a mock states for itself and this package cannot know.";
|
|
28
27
|
const HOST_OWNED = "The host owns this report: it describes the host's own process and files, which a browser build has no equivalent of.";
|
|
29
28
|
const WEB_BUNDLE = 'The host serves its own web bundle; there is no API decision here for this package to answer.';
|
|
@@ -87,8 +86,18 @@ export const OVERLAY = {
|
|
|
87
86
|
'GET /SASjsApi/client': { implemented: true },
|
|
88
87
|
'POST /SASjsApi/client': { implemented: true },
|
|
89
88
|
// Code - the editor's three calls, and the runtime one
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
//
|
|
90
|
+
// The runtime routes are carried over a `SessionRunner` port: the document's
|
|
91
|
+
// `RunTimeType` is validated here, the id, the record and the refusals are
|
|
92
|
+
// decided here, and performing the work is the host's. The response body is
|
|
93
|
+
// the program's own output - the log included when `_debug` asks for it - so
|
|
94
|
+
// there is no body to annotate.
|
|
95
|
+
'POST /SASjsApi/code/execute': { implemented: true },
|
|
96
|
+
'POST /SASjsApi/code/trigger': {
|
|
97
|
+
implemented: true,
|
|
98
|
+
// `pid` is the host's, and a run time without a local process omits it
|
|
99
|
+
responses: { 200: { sessionId: '' } }
|
|
100
|
+
},
|
|
92
101
|
'POST /SASjsApi/code/lint': {
|
|
93
102
|
implemented: true,
|
|
94
103
|
capabilities: ['identity']
|
|
@@ -201,9 +210,12 @@ export const OVERLAY = {
|
|
|
201
210
|
'GET /SASjsApi/session/{sessionId}/output': { implemented: true },
|
|
202
211
|
'GET /SASjsApi/session/{sessionId}/state': { implemented: true },
|
|
203
212
|
// STP - a stored program, on the runtime port
|
|
204
|
-
'GET /SASjsApi/stp/execute': { implemented:
|
|
205
|
-
'POST /SASjsApi/stp/execute': { implemented:
|
|
206
|
-
'POST /SASjsApi/stp/trigger': {
|
|
213
|
+
'GET /SASjsApi/stp/execute': { implemented: true },
|
|
214
|
+
'POST /SASjsApi/stp/execute': { implemented: true },
|
|
215
|
+
'POST /SASjsApi/stp/trigger': {
|
|
216
|
+
implemented: true,
|
|
217
|
+
responses: { 200: { sessionId: '' } }
|
|
218
|
+
},
|
|
207
219
|
// User - the accounts the identity store already holds for sign-in
|
|
208
220
|
// Reading accounts is open to any authenticated caller, which is what
|
|
209
221
|
// sasjs/server's routes do (`authenticateAccessToken` only): the document once
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A runner that needs no process, and the sessions it creates.
|
|
3
|
+
*
|
|
4
|
+
* The corpus and a browser build have the same problem: nothing to hand a
|
|
5
|
+
* program to. A memory runner answers it the way a mock should - it holds the
|
|
6
|
+
* record, the state, the log and the output of a session, and it finishes
|
|
7
|
+
* synchronously - which is why "the same API" can be checked without a SAS
|
|
8
|
+
* binary on the box. The one thing it cannot supply is a `pid`, and every
|
|
9
|
+
* response that would carry one carries it as optional.
|
|
10
|
+
*
|
|
11
|
+
* It is also a `SessionHost`, because a session a trigger created has to be one
|
|
12
|
+
* the session routes can read: two maps behind two ports would let a trigger
|
|
13
|
+
* write a record nothing can poll, which is the class of mistake the package
|
|
14
|
+
* exists to end.
|
|
15
|
+
*/
|
|
16
|
+
import { MemorySessionHost } from '../session/memory-host.js';
|
|
17
|
+
import type { SessionArtifact } from '../session/service.js';
|
|
18
|
+
import type { RunOutcome, RunRequest, SessionRunner } from './service.js';
|
|
19
|
+
export interface MemoryRunnerOptions {
|
|
20
|
+
/**
|
|
21
|
+
* What a program produces, by the code or the drive path it named.
|
|
22
|
+
*
|
|
23
|
+
* A mock cannot know what a program writes, so it writes nothing unless a test
|
|
24
|
+
* says otherwise - and a test that pins an output needs one it can state, which
|
|
25
|
+
* is what this is for.
|
|
26
|
+
*/
|
|
27
|
+
outputs?: Record<string, SessionArtifact>;
|
|
28
|
+
/** Refuse every run, so a test can pin what a failed run answers. */
|
|
29
|
+
fail?: boolean;
|
|
30
|
+
/** The process id to report, for a host that has one. */
|
|
31
|
+
pid?: number;
|
|
32
|
+
}
|
|
33
|
+
export declare class MemorySessionRunner extends MemorySessionHost implements SessionRunner {
|
|
34
|
+
private readonly options;
|
|
35
|
+
constructor(options?: MemoryRunnerOptions);
|
|
36
|
+
run(request: RunRequest): Promise<RunOutcome>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=memory-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-runner.d.ts","sourceRoot":"","sources":["../../../src/runtime/memory-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAe,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAEzE,MAAM,WAAW,mBAAmB;IAClC;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IACzC,qEAAqE;IACrE,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,yDAAyD;IACzD,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,qBAAa,mBACX,SAAQ,iBACR,YAAW,aAAa;IAEZ,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,GAAE,mBAAwB;IAIxD,GAAG,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;CAsCpD"}
|