@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,303 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRuntimeService = exports.parseDebugValue = exports.DOCUMENTED_RUN_TIMES = exports.CODE_DEBUG = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The runtime routes: running a program, and starting one.
|
|
6
|
+
*
|
|
7
|
+
* Five operations run work - `code/execute`, `code/trigger`, both `stp/execute`
|
|
8
|
+
* and `stp/trigger` - and what they have in common is the part this package can
|
|
9
|
+
* decide: who may ask, what a valid request is, the session record a trigger
|
|
10
|
+
* creates, its ownership and its retention, and what a refusal says. What it
|
|
11
|
+
* cannot decide is whether there is a SAS binary, a JavaScript worker or
|
|
12
|
+
* anything at all to hand the program to, so that is one port: `SessionRunner`.
|
|
13
|
+
*
|
|
14
|
+
* A session is a transient run - a temporary folder plus a process, producing a
|
|
15
|
+
* log and an `_webout`, then destroyed. The routes expose the record and the
|
|
16
|
+
* artefacts, never the process, which is why a mock can carry them too: it holds
|
|
17
|
+
* records and bytes as well as a host does, and it can even do the work for a
|
|
18
|
+
* run time it has. The one thing it cannot supply is a `pid`, and every response
|
|
19
|
+
* that would carry one carries it as optional.
|
|
20
|
+
*/
|
|
21
|
+
const types_js_1 = require("../types.js");
|
|
22
|
+
const paths_js_1 = require("../drive/paths.js");
|
|
23
|
+
/**
|
|
24
|
+
* The value that asks for the session log.
|
|
25
|
+
*
|
|
26
|
+
* `_debug` follows the SAS Application Broker's convention, where the value is a
|
|
27
|
+
* set of bit flags - 128 returns the log, 2 prints timing, 1 echoes the fields -
|
|
28
|
+
* so 131 is LOG + TIME + FIELDS, which is what @sasjs/core's `ms_runstp`
|
|
29
|
+
* defaults to and what the generated services test with `%if &_debug ge 131`.
|
|
30
|
+
*
|
|
31
|
+
* The two code routes force it on, because their documented response body is
|
|
32
|
+
* assembled from the webout, the log and the listing: a client that runs code
|
|
33
|
+
* and receives only the webout would be told nothing about a program that failed
|
|
34
|
+
* with an empty `_webout`. The stored-program routes leave it to the caller, so
|
|
35
|
+
* `GET /stp/execute` without `_debug` answers the program's output and nothing
|
|
36
|
+
* else.
|
|
37
|
+
*/
|
|
38
|
+
exports.CODE_DEBUG = 131;
|
|
39
|
+
/** The run times the published document states, and a host may hold fewer. */
|
|
40
|
+
exports.DOCUMENTED_RUN_TIMES = ['sas', 'js', 'py', 'r', 'sasviya'];
|
|
41
|
+
/**
|
|
42
|
+
* `_debug`, normalised the way sasjs/server's `parseDebugValue` normalises it.
|
|
43
|
+
*
|
|
44
|
+
* The parameter's one effect is whether the log comes back, and the macros test
|
|
45
|
+
* it numerically (`%if &_debug ge 131`), so a keyword cannot be handed to a
|
|
46
|
+
* program as text: `_debug=log` would arrive as the string `log`, the comparison
|
|
47
|
+
* would fail, and the caller would receive a body without the log section the
|
|
48
|
+
* same request gets from a server. Integer text is a level; any other non-empty
|
|
49
|
+
* value means "the log, please"; absent or empty means it was not asked for.
|
|
50
|
+
*
|
|
51
|
+
* `1e3` and `0x10` are text, not levels - `Number()` would read them as 1000 and
|
|
52
|
+
* 16, neither of which the macros' comparison treats as the log.
|
|
53
|
+
*/
|
|
54
|
+
const parseDebugValue = (value) => {
|
|
55
|
+
if (value === undefined || value === null || value === '')
|
|
56
|
+
return undefined;
|
|
57
|
+
if (typeof value === 'number')
|
|
58
|
+
return Number.isFinite(value) ? value : undefined;
|
|
59
|
+
const text = String(value).trim();
|
|
60
|
+
if (!text)
|
|
61
|
+
return undefined;
|
|
62
|
+
return /^[+-]?\d+$/.test(text) ? Number(text) : exports.CODE_DEBUG;
|
|
63
|
+
};
|
|
64
|
+
exports.parseDebugValue = parseDebugValue;
|
|
65
|
+
/** Two digits, for the timestamp a session id starts with. */
|
|
66
|
+
const pad = (value) => String(value).padStart(2, '0');
|
|
67
|
+
/**
|
|
68
|
+
* The timestamp a session id starts with: `YYYYMMDDHHMMSS`.
|
|
69
|
+
*
|
|
70
|
+
* Local time, which is what sasjs/server's `generateTimestamp` writes and what
|
|
71
|
+
* makes the id read as a SAS work folder name. Nothing derives from it - the id
|
|
72
|
+
* is opaque to a client - so a host in another time zone minting another string
|
|
73
|
+
* is not a divergence.
|
|
74
|
+
*/
|
|
75
|
+
const timestamp = (now) => [
|
|
76
|
+
now.getFullYear(),
|
|
77
|
+
pad(now.getMonth() + 1),
|
|
78
|
+
pad(now.getDate()),
|
|
79
|
+
pad(now.getHours()),
|
|
80
|
+
pad(now.getMinutes()),
|
|
81
|
+
pad(now.getSeconds())
|
|
82
|
+
].join('');
|
|
83
|
+
/**
|
|
84
|
+
* A session id in the shape the document shows: `20241028074744-54132-1730101664824`.
|
|
85
|
+
*
|
|
86
|
+
* The trailing milliseconds make two triggers in the same second distinct even
|
|
87
|
+
* when the random part collides, which matters because the id names a folder: a
|
|
88
|
+
* collision would put two runs in one session.
|
|
89
|
+
*/
|
|
90
|
+
const newSessionId = (now) => `${timestamp(now)}-${Math.round(Math.random() * 100000)}-${now.getTime()}`;
|
|
91
|
+
/** The refusal a program that cannot be found answers, as the server words it. */
|
|
92
|
+
const notThere = (programPath) => `The Program at (${programPath}) does not exist.`;
|
|
93
|
+
/**
|
|
94
|
+
* The failure a run that could not be performed answers.
|
|
95
|
+
*
|
|
96
|
+
* The message is sasjs/server's, verbatim, because a client keys on it: the
|
|
97
|
+
* response body is `{status: 'failure', message, error}`, where `error` is the
|
|
98
|
+
* runner's own text. A host's bug must not become a `500` here - a `500` says
|
|
99
|
+
* the API happened to break, and this says the program did not run.
|
|
100
|
+
*/
|
|
101
|
+
const failedRun = (error) => {
|
|
102
|
+
const message = 'Job execution failed.';
|
|
103
|
+
// `String(error)` keeps the prefix an Error carries (`Error: ...`), which is
|
|
104
|
+
// what the server sends: it stringifies the rejection rather than reading
|
|
105
|
+
// `.message` off it
|
|
106
|
+
throw new types_js_1.ApiError(400, message, {
|
|
107
|
+
status: 'failure',
|
|
108
|
+
message,
|
|
109
|
+
error: String(error)
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* The five runtime routes, over a host's runner.
|
|
114
|
+
*
|
|
115
|
+
* The caller passes a `Subject` and nothing else: which account that is, whether
|
|
116
|
+
* it is still active, and what it is allowed to run are resolved here, against
|
|
117
|
+
* the same directory the session routes read. A host never states a role.
|
|
118
|
+
*/
|
|
119
|
+
const createRuntimeService = (directory, runner, options = {}) => {
|
|
120
|
+
const runTimes = options.runTimes || exports.DOCUMENTED_RUN_TIMES;
|
|
121
|
+
/** The caller, refused the way the middleware refuses one. */
|
|
122
|
+
const callerOf = async (caller) => {
|
|
123
|
+
if (!caller)
|
|
124
|
+
throw new types_js_1.ApiError(401, 'Unauthorized');
|
|
125
|
+
const reader = await directory.userById(caller.userId);
|
|
126
|
+
// a deactivated account keeps a token the sign-in flow issued before it was
|
|
127
|
+
// deactivated, and the server's middleware refuses it on every route
|
|
128
|
+
if (!reader || !reader.isActive)
|
|
129
|
+
throw new types_js_1.ApiError(401, 'Unauthorized');
|
|
130
|
+
return reader;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* The program a request names, refused in the schema's own words.
|
|
134
|
+
*
|
|
135
|
+
* `_program` is caller-controlled and names a file under the host's drive, so
|
|
136
|
+
* it is resolved against the drive root before a runner sees it: a path that
|
|
137
|
+
* climbs out with `..` would otherwise let a caller run any file the service
|
|
138
|
+
* account can read, which is why sasjs/server resolves it with
|
|
139
|
+
* `resolveWithinDrive` before looking for the program. A path that leaves the
|
|
140
|
+
* drive is refused the way a program that is not there is refused - the same
|
|
141
|
+
* `400`, because saying "your path was rejected but existed" would say
|
|
142
|
+
* something about the host's filesystem.
|
|
143
|
+
*/
|
|
144
|
+
const programOf = (request) => {
|
|
145
|
+
// a refusal names the parameter its own route declared: a code route told
|
|
146
|
+
// its caller that "_program" is missing is answering about a field the
|
|
147
|
+
// route never had
|
|
148
|
+
if (request.source === 'code') {
|
|
149
|
+
if (request.code === undefined)
|
|
150
|
+
throw new types_js_1.ApiError(400, '"code" is required');
|
|
151
|
+
if (typeof request.code !== 'string')
|
|
152
|
+
throw new types_js_1.ApiError(400, '"code" must be a string');
|
|
153
|
+
if (request.code === '')
|
|
154
|
+
throw new types_js_1.ApiError(400, '"code" is not allowed to be empty');
|
|
155
|
+
return { code: request.code };
|
|
156
|
+
}
|
|
157
|
+
if (request.program === undefined)
|
|
158
|
+
throw new types_js_1.ApiError(400, '"_program" is required');
|
|
159
|
+
if (typeof request.program !== 'string')
|
|
160
|
+
throw new types_js_1.ApiError(400, '"_program" must be a string');
|
|
161
|
+
if (request.program === '')
|
|
162
|
+
throw new types_js_1.ApiError(400, '"_program" is not allowed to be empty');
|
|
163
|
+
const resolved = (0, paths_js_1.normaliseDrivePath)(request.program);
|
|
164
|
+
if (resolved === null)
|
|
165
|
+
return failedRun(notThere(request.program));
|
|
166
|
+
return { path: resolved };
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* The run time a stored program's path names, if it names one.
|
|
170
|
+
*
|
|
171
|
+
* `_program=/app/run.js` is JavaScript, and the server treats it that way
|
|
172
|
+
* before it looks for the file (`getRunTimeAndFilePath` reads the extension).
|
|
173
|
+
* Only the extension vocabulary the document states is read, so `run.sas7bdat`
|
|
174
|
+
* or `run.backup` name no run time and are left to the host.
|
|
175
|
+
*/
|
|
176
|
+
const runTimeForPath = (path, request) => {
|
|
177
|
+
const file = path.split('/').pop() || '';
|
|
178
|
+
const dot = file.lastIndexOf('.');
|
|
179
|
+
const extension = dot > 0 ? file.slice(dot + 1).toLowerCase() : '';
|
|
180
|
+
if (exports.DOCUMENTED_RUN_TIMES.includes(extension))
|
|
181
|
+
return extension;
|
|
182
|
+
return runTimeOf(request);
|
|
183
|
+
};
|
|
184
|
+
/** The run time, refused when it is absent where the document requires it, or unheld. */
|
|
185
|
+
const runTimeOf = (request) => {
|
|
186
|
+
if (request.runTime === undefined) {
|
|
187
|
+
// the code routes document `runTime` as required; a stored program's run
|
|
188
|
+
// time is the host's to resolve from the path, so absent is normal there
|
|
189
|
+
if (request.source === 'code')
|
|
190
|
+
throw new types_js_1.ApiError(400, '"runTime" is required');
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
if (typeof request.runTime !== 'string')
|
|
194
|
+
throw new types_js_1.ApiError(400, '"runTime" must be a string');
|
|
195
|
+
if (!runTimes.includes(request.runTime))
|
|
196
|
+
throw new types_js_1.ApiError(400, `"runTime" must be one of [${runTimes.join(', ')}]`);
|
|
197
|
+
return request.runTime;
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Retention, refused when it is not a positive number of minutes.
|
|
201
|
+
*
|
|
202
|
+
* A query string carries text, and the server's schema coerces it -
|
|
203
|
+
* `?expiresAfterMins=15` is the same request as `"expiresAfterMins": 15` - so
|
|
204
|
+
* the coercion is part of the contract rather than a convenience. Only a
|
|
205
|
+
* number, or text shaped like one, is read: `15abc` and `1e3` are refused (the
|
|
206
|
+
* first is not a number to Joi either, the second is not the shape a client
|
|
207
|
+
* sends), while `1.5` is accepted because `number().greater(0)` takes decimals.
|
|
208
|
+
*
|
|
209
|
+
* Retention belongs to a trigger and only to a trigger: an execute waits for
|
|
210
|
+
* the program, so an `expiresAfterMins` on its request is a session variable
|
|
211
|
+
* like any other, and validating one would refuse a request the server answers.
|
|
212
|
+
*/
|
|
213
|
+
const expiryOf = (request) => {
|
|
214
|
+
const value = request.expiresAfterMins;
|
|
215
|
+
if (value === undefined)
|
|
216
|
+
return undefined;
|
|
217
|
+
const minutes = typeof value === 'number'
|
|
218
|
+
? value
|
|
219
|
+
: typeof value === 'string' && /^\s*[+-]?\d+(\.\d+)?\s*$/.test(value)
|
|
220
|
+
? Number(value)
|
|
221
|
+
: NaN;
|
|
222
|
+
if (Number.isNaN(minutes))
|
|
223
|
+
throw new types_js_1.ApiError(400, '"expiresAfterMins" must be a number');
|
|
224
|
+
if (minutes <= 0)
|
|
225
|
+
throw new types_js_1.ApiError(400, '"expiresAfterMins" must be greater than 0');
|
|
226
|
+
return minutes;
|
|
227
|
+
};
|
|
228
|
+
/** The request, validated and normalised, with its caller resolved. */
|
|
229
|
+
const prepare = async (caller, request) => {
|
|
230
|
+
const reader = await callerOf(caller);
|
|
231
|
+
const program = programOf(request);
|
|
232
|
+
const vars = { ...(request.vars || {}) };
|
|
233
|
+
// the code routes force the log on, because their documented body is
|
|
234
|
+
// assembled from it; a stored program's caller decides, and a keyword there
|
|
235
|
+
// means the same thing a number does. A caller who did not ask for the log
|
|
236
|
+
// keeps no `_debug` key at all: a host that walks the entries to build a
|
|
237
|
+
// query string or a header map would otherwise emit `_debug=undefined`.
|
|
238
|
+
const debug = 'code' in program ? exports.CODE_DEBUG : (0, exports.parseDebugValue)(vars._debug);
|
|
239
|
+
if (debug === undefined)
|
|
240
|
+
delete vars._debug;
|
|
241
|
+
else
|
|
242
|
+
vars._debug = debug;
|
|
243
|
+
return {
|
|
244
|
+
reader,
|
|
245
|
+
program,
|
|
246
|
+
vars,
|
|
247
|
+
// a code route's run time is the one it named; a stored program's is the
|
|
248
|
+
// one its extension names, when it names one at all
|
|
249
|
+
runTime: 'code' in program
|
|
250
|
+
? runTimeOf(request)
|
|
251
|
+
: runTimeForPath(program.path, request)
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
return {
|
|
255
|
+
async execute(caller, request) {
|
|
256
|
+
const prepared = await prepare(caller, request);
|
|
257
|
+
let outcome;
|
|
258
|
+
try {
|
|
259
|
+
outcome = await runner.run({
|
|
260
|
+
program: prepared.program,
|
|
261
|
+
vars: prepared.vars,
|
|
262
|
+
runTime: prepared.runTime,
|
|
263
|
+
files: request.files
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
return failedRun(error);
|
|
268
|
+
}
|
|
269
|
+
// a program that wrote nothing is an empty body, not a missing one: the
|
|
270
|
+
// route answered, and "no output" is the answer
|
|
271
|
+
return outcome.output || { contents: '' };
|
|
272
|
+
},
|
|
273
|
+
async trigger(caller, request) {
|
|
274
|
+
const prepared = await prepare(caller, request);
|
|
275
|
+
const expiresAfterMins = expiryOf(request);
|
|
276
|
+
const session = {
|
|
277
|
+
sessionId: newSessionId(new Date()),
|
|
278
|
+
owner: prepared.reader.uid,
|
|
279
|
+
...(prepared.runTime === undefined
|
|
280
|
+
? {}
|
|
281
|
+
: { runTime: prepared.runTime }),
|
|
282
|
+
...(expiresAfterMins === undefined ? {} : { expiresAfterMins })
|
|
283
|
+
};
|
|
284
|
+
let outcome;
|
|
285
|
+
try {
|
|
286
|
+
outcome = await runner.run({
|
|
287
|
+
program: prepared.program,
|
|
288
|
+
vars: prepared.vars,
|
|
289
|
+
runTime: prepared.runTime,
|
|
290
|
+
session,
|
|
291
|
+
files: request.files
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
return failedRun(error);
|
|
296
|
+
}
|
|
297
|
+
return outcome.pid === undefined
|
|
298
|
+
? { sessionId: session.sessionId }
|
|
299
|
+
: { sessionId: session.sessionId, pid: outcome.pid };
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
exports.createRuntimeService = createRuntimeService;
|
|
@@ -18,7 +18,7 @@ exports.DEFAULT_SESSIONS = {
|
|
|
18
18
|
pid: 4242,
|
|
19
19
|
creationTimeStamp: '2026-11-07T09:00:00.000Z',
|
|
20
20
|
deathTimeStamp: '2026-11-07T09:00:04.000Z',
|
|
21
|
-
expiresAfterMins: 60
|
|
21
|
+
expiresAfterMins: { mins: 60, used: false }
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
'sess-restricted': {
|
|
@@ -57,21 +57,38 @@ const OUTPUTS = {
|
|
|
57
57
|
'sess-restricted': { contents: '' },
|
|
58
58
|
'sess-silent': { contents: '' }
|
|
59
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Sessions held in maps.
|
|
62
|
+
*
|
|
63
|
+
* The four maps are `protected` rather than `private`, because a trigger creates
|
|
64
|
+
* a session and the same object has to be able to record it - a runner that
|
|
65
|
+
* wrote a record into a second map would leave the session routes answering 404
|
|
66
|
+
* for a session that exists.
|
|
67
|
+
*/
|
|
60
68
|
class MemorySessionHost {
|
|
61
|
-
constructor(sessions =
|
|
69
|
+
constructor(sessions = {
|
|
70
|
+
...exports.DEFAULT_SESSIONS
|
|
71
|
+
}, states = {
|
|
72
|
+
...STATES
|
|
73
|
+
}, logs = { ...LOGS }, outputs = {
|
|
74
|
+
...OUTPUTS
|
|
75
|
+
}) {
|
|
62
76
|
this.sessions = sessions;
|
|
77
|
+
this.states = states;
|
|
78
|
+
this.logs = logs;
|
|
79
|
+
this.outputs = outputs;
|
|
63
80
|
}
|
|
64
81
|
async session(id) {
|
|
65
82
|
return this.sessions[id];
|
|
66
83
|
}
|
|
67
84
|
async state(id) {
|
|
68
|
-
return
|
|
85
|
+
return this.states[id];
|
|
69
86
|
}
|
|
70
87
|
async log(id) {
|
|
71
|
-
return
|
|
88
|
+
return this.logs[id];
|
|
72
89
|
}
|
|
73
90
|
async output(id) {
|
|
74
|
-
return
|
|
91
|
+
return this.outputs[id];
|
|
75
92
|
}
|
|
76
93
|
}
|
|
77
94
|
exports.MemorySessionHost = MemorySessionHost;
|
|
@@ -29,6 +29,19 @@ export interface CorpusCase {
|
|
|
29
29
|
* that always accepts writes could never produce one.
|
|
30
30
|
*/
|
|
31
31
|
unwritable?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* What the case's program produces, for a route that runs one.
|
|
34
|
+
*
|
|
35
|
+
* A mock cannot know what a program writes, so the corpus states it: a case
|
|
36
|
+
* that pins an output needs a runner that answers with one, and the output is
|
|
37
|
+
* then the only thing about the run the case asserts.
|
|
38
|
+
*/
|
|
39
|
+
runOutput?: {
|
|
40
|
+
contents: string | Uint8Array;
|
|
41
|
+
contentType?: string;
|
|
42
|
+
};
|
|
43
|
+
/** The run fails, so a case can pin the `400` a failed run answers. */
|
|
44
|
+
failingRun?: boolean;
|
|
32
45
|
request: ApiRequest;
|
|
33
46
|
expect: {
|
|
34
47
|
status: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drive.d.ts","sourceRoot":"","sources":["../../../src/corpus/drive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAE7D,MAAM,WAAW,UAAU;IACzB,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAA;IACV,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,CAAA;IAC1C,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,eAAe,CAAA;IAC1B;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,OAAO,EAAE,UAAU,CAAA;IACnB,MAAM,EAAE;QACN,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;QAC9B,yDAAyD;QACzD,KAAK,CAAC,EAAE,MAAM,CAAA;QACd;;;;WAIG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACjC;;;WAGG;QACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;QACf;;;;;;;WAOG;QACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAC3B,CAAA;CACF;AAmBD,eAAO,MAAM,YAAY,EAAE,UAAU,EAqapC,CAAA"}
|
|
1
|
+
{"version":3,"file":"drive.d.ts","sourceRoot":"","sources":["../../../src/corpus/drive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAE7D,MAAM,WAAW,UAAU;IACzB,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAA;IACV,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,CAAA;IAC1C,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,eAAe,CAAA;IAC1B;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACnE,uEAAuE;IACvE,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,OAAO,EAAE,UAAU,CAAA;IACnB,MAAM,EAAE;QACN,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;QAC9B,yDAAyD;QACzD,KAAK,CAAC,EAAE,MAAM,CAAA;QACd;;;;WAIG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACjC;;;WAGG;QACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;QACf;;;;;;;WAOG;QACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAC3B,CAAA;CACF;AAmBD,eAAO,MAAM,YAAY,EAAE,UAAU,EAqapC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../../src/corpus/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../../src/corpus/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAanD,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;IAC9B,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU,UAAU,KAAG,QAgClD,CAAA;AA2BD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAClB,UAAU,UAAU,EACpB,WAAU,QAAgC,KACzC,OAAO,CAAC,UAAU,CAepB,CAAA"}
|
|
@@ -5,7 +5,8 @@ import { MemoryAppStreamRegistry } from '../drive/registry.js';
|
|
|
5
5
|
import { createIdentityService } from '../identity/service.js';
|
|
6
6
|
import { createRecordService } from '../identity/records.js';
|
|
7
7
|
import { createSessionService } from '../session/service.js';
|
|
8
|
-
import {
|
|
8
|
+
import { createRuntimeService } from '../runtime/service.js';
|
|
9
|
+
import { MemorySessionRunner } from '../runtime/memory-runner.js';
|
|
9
10
|
import { MemoryIdentityStore } from '../identity/memory-store.js';
|
|
10
11
|
import { DEFAULT_IDENTITY } from '../identity/fixture.js';
|
|
11
12
|
import { isApiError } from '../types.js';
|
|
@@ -21,6 +22,14 @@ export const servicesFor = (testCase) => {
|
|
|
21
22
|
// has to be one the flow can sign in. Two stores built from the same fixture
|
|
22
23
|
// would let a case assert across two independent states and still pass.
|
|
23
24
|
const identity = new MemoryIdentityStore(testCase.identity || DEFAULT_IDENTITY);
|
|
25
|
+
// one runner, shared by the runtime routes and the session routes: a session a
|
|
26
|
+
// trigger creates has to be one the session routes can read
|
|
27
|
+
const runner = new MemorySessionRunner({
|
|
28
|
+
fail: testCase.failingRun,
|
|
29
|
+
outputs: testCase.runOutput
|
|
30
|
+
? { [programOf(testCase)]: testCase.runOutput }
|
|
31
|
+
: undefined
|
|
32
|
+
});
|
|
24
33
|
return {
|
|
25
34
|
drive: createDriveService(testCase.unwritable
|
|
26
35
|
? new RefusingDriveStore(testCase.seed || {})
|
|
@@ -28,9 +37,17 @@ export const servicesFor = (testCase) => {
|
|
|
28
37
|
identity: createIdentityService(identity),
|
|
29
38
|
records: createRecordService(identity),
|
|
30
39
|
registry: new MemoryAppStreamRegistry(),
|
|
31
|
-
session: createSessionService(identity,
|
|
40
|
+
session: createSessionService(identity, runner),
|
|
41
|
+
// no `runTimes` option: the default is the five the document names, so a
|
|
42
|
+
// case is never refused for a reason that belongs to one host's install
|
|
43
|
+
runtime: createRuntimeService(identity, runner)
|
|
32
44
|
};
|
|
33
45
|
};
|
|
46
|
+
/** The program a case runs, keyed the way the runner is keyed by it. */
|
|
47
|
+
const programOf = (testCase) => String(testCase.request.query?._program ??
|
|
48
|
+
testCase.request.body?._program ??
|
|
49
|
+
testCase.request.body?.code ??
|
|
50
|
+
'');
|
|
34
51
|
/**
|
|
35
52
|
* A drive that reads but refuses every write.
|
|
36
53
|
*
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The runtime routes' conformance corpus.
|
|
3
|
+
*
|
|
4
|
+
* Every status the document states for these five routes has a case, in both
|
|
5
|
+
* directions - that is what `spec/corpus-parity.spec.ts` enforces. The refusals
|
|
6
|
+
* arrived here only after sasjs/server#584 documented them: until then the
|
|
7
|
+
* document stated `200` alone, and a case pinning the `400` or the `401` would
|
|
8
|
+
* have been called drift.
|
|
9
|
+
*
|
|
10
|
+
* What a *program* does is not part of this contract. The output a case pins is
|
|
11
|
+
* the output its runner was told to produce, so the same cases hold for a host
|
|
12
|
+
* with a SAS binary and for a mock with nothing but maps - which is the point of
|
|
13
|
+
* the runner being a port.
|
|
14
|
+
*/
|
|
15
|
+
import type { CorpusCase } from './drive.js';
|
|
16
|
+
export declare const RUNTIME_CORPUS: CorpusCase[];
|
|
17
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/corpus/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAa5C,eAAO,MAAM,cAAc,EAAE,UAAU,EAyOtC,CAAA"}
|