@sasjs/api 0.36.0 → 0.38.0

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/build/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- /* @sasjs/api 0.36.0 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
1
+ /* @sasjs/api 0.38.0 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
2
2
  "use strict";
3
3
  var SASjsApi = (() => {
4
4
  var __defProp = Object.defineProperty;
@@ -4350,10 +4350,6 @@ var SASjsApi = (() => {
4350
4350
  reason: "no capture: the authorisation-code step needs a browser; the pass uses the password grant"
4351
4351
  },
4352
4352
  // Compute operations the scripted passes do not reach.
4353
- {
4354
- path: "/compute/sessions/{}/filerefs/_webout/content",
4355
- reason: "no capture: the adapter reads the webout fileref only when a run expects one (`expectWebout`); the execute pass submits a `%put` and reads the log"
4356
- },
4357
4353
  {
4358
4354
  path: "/compute/sessions/{}/variables/{}",
4359
4355
  reason: "no capture: the adapter reads a session variable only to report a submitted job's pid (`printPid`), which the pass does not set"
@@ -4387,6 +4383,26 @@ var SASjsApi = (() => {
4387
4383
  "Access-Control-Expose-Headers": EMULATED_HEADER
4388
4384
  });
4389
4385
 
4386
+ // src/viya/declared.ts
4387
+ var DECLARED = [
4388
+ {
4389
+ id: "GET /compute/sessions/{}/filerefs/_webout/content",
4390
+ method: "GET",
4391
+ path: "/compute/sessions/{}/filerefs/_webout/content",
4392
+ steps: [],
4393
+ // what this emulator answers, not what an estate did: 200 with the webout,
4394
+ // 404 when no program has run in the session
4395
+ statuses: [200, 404],
4396
+ queries: [],
4397
+ request: { queries: [], body: void 0 },
4398
+ // the body is the program's `_webout`, which is whatever the program wrote:
4399
+ // there is no JSON shape to record
4400
+ shape: void 0,
4401
+ declared: "The adapter fetches this only when a run expects a webout (`expectWebout`), and the recording pass submits a `%put` and reads the log instead. Without it an application cannot receive the data its service returns, so the emulator answers it from the job it just ran."
4402
+ }
4403
+ ];
4404
+ var VIYA_OPERATIONS = [...VIYA_TABLE, ...DECLARED];
4405
+
4390
4406
  // src/viya/overlay.ts
4391
4407
  var NEEDS_AUTH = "The token endpoint is answered by the host that mounts the emulator, which owns the token port.";
4392
4408
  var VIYA_OVERLAY = {
@@ -4415,9 +4431,11 @@ var SASjsApi = (() => {
4415
4431
  "GET /files/files/{}/content": { implemented: true },
4416
4432
  "PUT /files/files/{}/content": { implemented: true },
4417
4433
  // declined: the host owns the token port
4418
- "POST /SASLogon/oauth/token": { implemented: false, reason: NEEDS_AUTH }
4434
+ "POST /SASLogon/oauth/token": { implemented: false, reason: NEEDS_AUTH },
4435
+ // declared, not captured: the webout an application's service returns
4436
+ "GET /compute/sessions/{}/filerefs/_webout/content": { implemented: true }
4419
4437
  };
4420
- var assertOverlayEntries = (overlay, operations = VIYA_TABLE) => {
4438
+ var assertOverlayEntries = (overlay, operations = VIYA_OPERATIONS) => {
4421
4439
  const known2 = new Set(operations.map((operation) => operation.id));
4422
4440
  for (const id of Object.keys(overlay))
4423
4441
  if (!known2.has(id))
@@ -4543,12 +4561,13 @@ var SASjsApi = (() => {
4543
4561
  // the log is a function of the seed and the program alone, so the same
4544
4562
  // program answers the same lines whatever session it was submitted in
4545
4563
  log: logFor(this.seed, code),
4546
- state: "completed",
4564
+ state: "running",
4547
4565
  // the real clock, unlike a folder's: a client computes a session's age
4548
4566
  // from this stamp and expires it, so a fixed instant in the past is a
4549
4567
  // session that is born expired
4550
4568
  creationTimeStamp: (/* @__PURE__ */ new Date()).toISOString(),
4551
- completedTimeStamp: (/* @__PURE__ */ new Date()).toISOString(),
4569
+ // no completion stamp here: a job is finished when something finished it,
4570
+ // and the handler that knows whether anything will run sets both
4552
4571
  sessionId: session.id
4553
4572
  };
4554
4573
  session.jobs.set(id, submitted);
@@ -4675,16 +4694,16 @@ var SASjsApi = (() => {
4675
4694
  sessionId: job.sessionId,
4676
4695
  state: job.state,
4677
4696
  creationTimeStamp: job.creationTimeStamp,
4678
- completedTimeStamp: job.completedTimeStamp,
4697
+ ...job.completedTimeStamp ? { completedTimeStamp: job.completedTimeStamp } : {},
4679
4698
  jobConditionCode: 0,
4680
4699
  stateElapsedTime: 1,
4681
4700
  listingStatistics: {
4682
4701
  lineCount: job.log.length,
4683
- modifiedTimeStamp: job.completedTimeStamp
4702
+ modifiedTimeStamp: job.completedTimeStamp ?? job.creationTimeStamp
4684
4703
  },
4685
4704
  logStatistics: {
4686
4705
  lineCount: job.log.length,
4687
- modifiedTimeStamp: job.completedTimeStamp
4706
+ modifiedTimeStamp: job.completedTimeStamp ?? job.creationTimeStamp
4688
4707
  },
4689
4708
  statistics: { systemCpuTime: 0.01, userCpuTime: 0.02 },
4690
4709
  version: 2,
@@ -4758,12 +4777,55 @@ var SASjsApi = (() => {
4758
4777
  },
4759
4778
  "POST /compute/sessions/{}/jobs": async ({ services, params, request }) => {
4760
4779
  const session = sessionOf(services, params.id);
4761
- const job = estateOf(services).submit(
4762
- session,
4763
- request.body ?? {}
4764
- );
4780
+ const body = request.body ?? {};
4781
+ const job = estateOf(services).submit(session, body);
4782
+ const execute = services.viya?.execute;
4783
+ if (!execute) {
4784
+ job.state = "completed";
4785
+ job.completedTimeStamp = (/* @__PURE__ */ new Date()).toISOString();
4786
+ return { status: 201, body: jobBody(job) };
4787
+ }
4788
+ job.state = "running";
4789
+ job.log = [];
4790
+ void execute({
4791
+ program: body.code ?? "",
4792
+ variables: body.variables,
4793
+ name: body.name,
4794
+ sessionId: session.id
4795
+ }).then((ran) => {
4796
+ job.log = ran.log.split("\n");
4797
+ job.state = ran.state ?? "completed";
4798
+ if (ran.webout !== void 0) job.webout = ran.webout;
4799
+ job.completedTimeStamp = (/* @__PURE__ */ new Date()).toISOString();
4800
+ }).catch((error) => {
4801
+ job.state = "failed";
4802
+ job.log = [`ERROR: ${error.message}`];
4803
+ job.completedTimeStamp = (/* @__PURE__ */ new Date()).toISOString();
4804
+ });
4765
4805
  return { status: 201, body: jobBody(job) };
4766
4806
  },
4807
+ "GET /compute/sessions/{}/filerefs/_webout/content": async ({
4808
+ services,
4809
+ params
4810
+ }) => {
4811
+ const session = sessionOf(services, params.id);
4812
+ const last = [...session.jobs.values()].pop();
4813
+ if (!last)
4814
+ throw new ApiError(
4815
+ 404,
4816
+ "This session has no `_webout` yet: nothing has run in it."
4817
+ );
4818
+ if (last.webout === void 0)
4819
+ throw new ApiError(
4820
+ 404,
4821
+ last.state === "running" ? `This session has no \`_webout\` yet: job '${last.id}' has not finished.` : services.viya?.execute ? `This session has no \`_webout\`: job '${last.id}' ran and produced none.` : `This session has no \`_webout\`: the host supplied no engine, so no program has run.`
4822
+ );
4823
+ return {
4824
+ status: 200,
4825
+ contents: last.webout,
4826
+ headers: { "content-type": "text/plain" }
4827
+ };
4828
+ },
4767
4829
  "GET /compute/sessions/{}/jobs/{}": async ({ services, params }) => {
4768
4830
  const [sessionId, jobId] = segmentsOf(params);
4769
4831
  return { status: 200, body: jobBody(jobOf(services, sessionId, jobId)) };
@@ -5217,7 +5279,7 @@ var SASjsApi = (() => {
5217
5279
 
5218
5280
  // src/viya/dispatch.ts
5219
5281
  var escape2 = (segment) => segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
5220
- var compiled2 = VIYA_TABLE.filter(
5282
+ var compiled2 = VIYA_OPERATIONS.filter(
5221
5283
  (operation) => operation.path.includes("{}")
5222
5284
  ).map((operation) => ({
5223
5285
  operation,
@@ -5228,7 +5290,7 @@ var SASjsApi = (() => {
5228
5290
  )
5229
5291
  }));
5230
5292
  var exact2 = /* @__PURE__ */ new Map();
5231
- for (const operation of VIYA_TABLE)
5293
+ for (const operation of VIYA_OPERATIONS)
5232
5294
  if (!operation.path.includes("{}"))
5233
5295
  exact2.set(`${operation.method} ${operation.path}`.toLowerCase(), operation);
5234
5296
  var findViyaOperation = (method, path) => {
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCodeService = void 0;
4
2
  /**
5
3
  * The code service, on its own entry point.
6
4
  *
@@ -8,5 +6,20 @@ exports.createCodeService = void 0;
8
6
  * `.sasjslint`), so it cannot be bundled for a service worker: the package root
9
7
  * stays free of it and a host that wants these routes imports `@sasjs/api/code`.
10
8
  */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.LintConfig = exports.createCodeService = void 0;
11
11
  var service_js_1 = require("./service.js");
12
12
  Object.defineProperty(exports, "createCodeService", { enumerable: true, get: function () { return service_js_1.createCodeService; } });
13
+ /**
14
+ * The configuration class the service hands the linter.
15
+ *
16
+ * A host that resolves rules from its own storage parses a `.sasjslint` and has
17
+ * to build the configuration the routes expect. Exporting the class here lets
18
+ * it build that with the linter this package bundles, instead of adding
19
+ * `@sasjs/lint` to its own dependencies and carrying a second copy to keep in
20
+ * step. What keeps the two in step is this package's exact dependency pin, not
21
+ * the export: a host that installs the linter itself still resolves whatever
22
+ * its own tree gives it.
23
+ */
24
+ var lint_1 = require("@sasjs/lint");
25
+ Object.defineProperty(exports, "LintConfig", { enumerable: true, get: function () { return lint_1.LintConfig; } });
@@ -42,15 +42,15 @@ const createCodeService = (options = {}) => {
42
42
  if (!caller)
43
43
  throw new types_js_1.ApiError(401, 'Unauthorized');
44
44
  };
45
- const configFor = (filePath) => options.lintConfig ? options.lintConfig(filePath) : undefined;
45
+ const configFor = async (filePath) => options.lintConfig ? await options.lintConfig(filePath) : undefined;
46
46
  return {
47
47
  async lint(caller, body) {
48
48
  requireCaller(caller);
49
- return (0, lint_1.lintText)(codeOf(body), configFor(body.filePath));
49
+ return (0, lint_1.lintText)(codeOf(body), await configFor(body.filePath));
50
50
  },
51
51
  async format(caller, body) {
52
52
  requireCaller(caller);
53
- return (0, lint_1.formatText)(codeOf(body), configFor(body.filePath));
53
+ return (0, lint_1.formatText)(codeOf(body), await configFor(body.filePath));
54
54
  }
55
55
  };
56
56
  };
@@ -105,16 +105,18 @@ const jobBody = (job) => {
105
105
  sessionId: job.sessionId,
106
106
  state: job.state,
107
107
  creationTimeStamp: job.creationTimeStamp,
108
- completedTimeStamp: job.completedTimeStamp,
108
+ ...(job.completedTimeStamp
109
+ ? { completedTimeStamp: job.completedTimeStamp }
110
+ : {}),
109
111
  jobConditionCode: 0,
110
112
  stateElapsedTime: 1,
111
113
  listingStatistics: {
112
114
  lineCount: job.log.length,
113
- modifiedTimeStamp: job.completedTimeStamp
115
+ modifiedTimeStamp: job.completedTimeStamp ?? job.creationTimeStamp
114
116
  },
115
117
  logStatistics: {
116
118
  lineCount: job.log.length,
117
- modifiedTimeStamp: job.completedTimeStamp
119
+ modifiedTimeStamp: job.completedTimeStamp ?? job.creationTimeStamp
118
120
  },
119
121
  statistics: { systemCpuTime: 0.01, userCpuTime: 0.02 },
120
122
  version: 2,
@@ -186,9 +188,64 @@ exports.COMPUTE_HANDLERS = {
186
188
  },
187
189
  'POST /compute/sessions/{}/jobs': async ({ services, params, request }) => {
188
190
  const session = sessionOf(services, params.id);
189
- const job = estateOf(services).submit(session, (request.body ?? {}));
191
+ const body = (request.body ?? {});
192
+ const job = estateOf(services).submit(session, body);
193
+ const execute = services.viya?.execute;
194
+ // a host with no engine has nothing to run, so the job is finished at once
195
+ if (!execute) {
196
+ job.state = 'completed';
197
+ job.completedTimeStamp = new Date().toISOString();
198
+ return { status: 201, body: jobBody(job) };
199
+ }
200
+ // the 201 is the submission, not the run: the client polls the state link,
201
+ // and `waitForResult: false` is documented to return here and poll later
202
+ job.state = 'running';
203
+ // and there is no log yet: the generated lines are what a host with NO engine
204
+ // answers, including one that says the run completed, so a running job must
205
+ // not advertise them - the run writes the log when it has one
206
+ job.log = [];
207
+ void execute({
208
+ program: body.code ?? '',
209
+ variables: body.variables,
210
+ name: body.name,
211
+ sessionId: session.id
212
+ })
213
+ .then((ran) => {
214
+ job.log = ran.log.split('\n');
215
+ job.state = ran.state ?? 'completed';
216
+ if (ran.webout !== undefined)
217
+ job.webout = ran.webout;
218
+ job.completedTimeStamp = new Date().toISOString();
219
+ })
220
+ .catch((error) => {
221
+ // a run that threw is a failed job with the reason in its log, because a
222
+ // client reads the failure from the state and the log together
223
+ job.state = 'failed';
224
+ job.log = [`ERROR: ${error.message}`];
225
+ job.completedTimeStamp = new Date().toISOString();
226
+ });
190
227
  return { status: 201, body: jobBody(job) };
191
228
  },
229
+ 'GET /compute/sessions/{}/filerefs/_webout/content': async ({ services, params }) => {
230
+ const session = sessionOf(services, params.id);
231
+ const last = [...session.jobs.values()].pop();
232
+ if (!last)
233
+ throw new types_js_1.ApiError(404, 'This session has no `_webout` yet: nothing has run in it.');
234
+ // the answer belongs to the last job submitted, not to the newest one that
235
+ // happened to produce something: a failed service must not answer with an
236
+ // earlier service's data
237
+ if (last.webout === undefined)
238
+ throw new types_js_1.ApiError(404, last.state === 'running'
239
+ ? `This session has no \`_webout\` yet: job '${last.id}' has not finished.`
240
+ : services.viya?.execute
241
+ ? `This session has no \`_webout\`: job '${last.id}' ran and produced none.`
242
+ : `This session has no \`_webout\`: the host supplied no engine, so no program has run.`);
243
+ return {
244
+ status: 200,
245
+ contents: last.webout,
246
+ headers: { 'content-type': 'text/plain' }
247
+ };
248
+ },
192
249
  'GET /compute/sessions/{}/jobs/{}': async ({ services, params }) => {
193
250
  const [sessionId, jobId] = segmentsOf(params);
194
251
  return { status: 200, body: jobBody(jobOf(services, sessionId, jobId)) };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VIYA_OPERATIONS = exports.DECLARED = void 0;
4
+ /**
5
+ * Operations the emulator must answer that no capture describes.
6
+ *
7
+ * The table is generated from what an estate answered, which is the right rule:
8
+ * a row nobody observed is a claim about a call no client makes. But a client
9
+ * does make some calls that no recording pass reaches, and an emulator that
10
+ * cannot answer them is an emulator an application cannot run on. Those rows are
11
+ * stated here, each with the reason it has no capture, and they pass through the
12
+ * same overlay ratchet as a captured one - so a declared operation still needs a
13
+ * decision about whether this package implements it.
14
+ *
15
+ * They are kept out of `src/viya/table.ts` because that file is generated: a
16
+ * hand-written row in it would be deleted by the next `npm run sync:viya`, and a
17
+ * generator that had to preserve hand edits would stop being a generator.
18
+ */
19
+ const table_js_1 = require("./table.js");
20
+ exports.DECLARED = [
21
+ {
22
+ id: 'GET /compute/sessions/{}/filerefs/_webout/content',
23
+ method: 'GET',
24
+ path: '/compute/sessions/{}/filerefs/_webout/content',
25
+ steps: [],
26
+ // what this emulator answers, not what an estate did: 200 with the webout,
27
+ // 404 when no program has run in the session
28
+ statuses: [200, 404],
29
+ queries: [],
30
+ request: { queries: [], body: undefined },
31
+ // the body is the program's `_webout`, which is whatever the program wrote:
32
+ // there is no JSON shape to record
33
+ shape: undefined,
34
+ declared: 'The adapter fetches this only when a run expects a webout (`expectWebout`), and the recording pass submits a `%put` and reads the log instead. Without it an application cannot receive the data its service returns, so the emulator answers it from the job it just ran.'
35
+ }
36
+ ];
37
+ /** Every operation the emulator answers: what an estate did, plus what it must. */
38
+ exports.VIYA_OPERATIONS = [...table_js_1.VIYA_TABLE, ...exports.DECLARED];
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dispatchViya = exports.findViyaOperation = void 0;
4
4
  const types_js_1 = require("../types.js");
5
- const table_js_1 = require("./table.js");
5
+ const declared_js_1 = require("./declared.js");
6
6
  const overlay_js_1 = require("./overlay.js");
7
7
  const service_js_1 = require("./service.js");
8
8
  const version_js_1 = require("./version.js");
9
9
  const escape = (segment) => segment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
10
- const compiled = table_js_1.VIYA_TABLE.filter((operation) => operation.path.includes('{}')).map((operation) => ({
10
+ const compiled = declared_js_1.VIYA_OPERATIONS.filter((operation) => operation.path.includes('{}')).map((operation) => ({
11
11
  operation,
12
12
  pattern: new RegExp('^' +
13
13
  operation.path
@@ -19,7 +19,7 @@ const compiled = table_js_1.VIYA_TABLE.filter((operation) => operation.path.incl
19
19
  'i')
20
20
  }));
21
21
  const exact = new Map();
22
- for (const operation of table_js_1.VIYA_TABLE)
22
+ for (const operation of declared_js_1.VIYA_OPERATIONS)
23
23
  if (!operation.path.includes('{}'))
24
24
  // keyed in lower case, because the hosts are: express's `case sensitive
25
25
  // routing` is off and the emulated estate has to match what they serve
@@ -14,7 +14,7 @@ exports.assertOverlayEntries = exports.VIYA_OVERLAY = void 0;
14
14
  * A declined row is not a TODO. The reason names what is missing, so a caller
15
15
  * that reaches it learns why rather than that something is unimplemented.
16
16
  */
17
- const table_js_1 = require("./table.js");
17
+ const declared_js_1 = require("./declared.js");
18
18
  /**
19
19
  * The token endpoint is the host's.
20
20
  *
@@ -49,7 +49,9 @@ exports.VIYA_OVERLAY = {
49
49
  'GET /files/files/{}/content': { implemented: true },
50
50
  'PUT /files/files/{}/content': { implemented: true },
51
51
  // declined: the host owns the token port
52
- 'POST /SASLogon/oauth/token': { implemented: false, reason: NEEDS_AUTH }
52
+ 'POST /SASLogon/oauth/token': { implemented: false, reason: NEEDS_AUTH },
53
+ // declared, not captured: the webout an application's service returns
54
+ 'GET /compute/sessions/{}/filerefs/_webout/content': { implemented: true }
53
55
  };
54
56
  /**
55
57
  * Refuse an overlay and a table that do not describe the same operations.
@@ -66,7 +68,7 @@ exports.VIYA_OVERLAY = {
66
68
  * Called at import, and exported so the refusals themselves can be tested: a
67
69
  * check that only runs on import is a check nothing can pin.
68
70
  */
69
- const assertOverlayEntries = (overlay, operations = table_js_1.VIYA_TABLE) => {
71
+ const assertOverlayEntries = (overlay, operations = declared_js_1.VIYA_OPERATIONS) => {
70
72
  const known = new Set(operations.map((operation) => operation.id));
71
73
  for (const id of Object.keys(overlay))
72
74
  if (!known.has(id))
@@ -88,12 +88,13 @@ class EmulatedEstate {
88
88
  // the log is a function of the seed and the program alone, so the same
89
89
  // program answers the same lines whatever session it was submitted in
90
90
  log: (0, exports.logFor)(this.seed, code),
91
- state: 'completed',
91
+ state: 'running',
92
92
  // the real clock, unlike a folder's: a client computes a session's age
93
93
  // from this stamp and expires it, so a fixed instant in the past is a
94
94
  // session that is born expired
95
95
  creationTimeStamp: new Date().toISOString(),
96
- completedTimeStamp: new Date().toISOString(),
96
+ // no completion stamp here: a job is finished when something finished it,
97
+ // and the handler that knows whether anything will run sets both
97
98
  sessionId: session.id
98
99
  };
99
100
  session.jobs.set(id, submitted);
@@ -30,10 +30,6 @@ exports.UNRECORDED = [
30
30
  reason: 'no capture: the authorisation-code step needs a browser; the pass uses the password grant'
31
31
  },
32
32
  // Compute operations the scripted passes do not reach.
33
- {
34
- path: '/compute/sessions/{}/filerefs/_webout/content',
35
- reason: 'no capture: the adapter reads the webout fileref only when a run expects one (`expectWebout`); the execute pass submits a `%put` and reads the log'
36
- },
37
33
  {
38
34
  path: '/compute/sessions/{}/variables/{}',
39
35
  reason: "no capture: the adapter reads a session variable only to report a submitted job's pid (`printPid`), which the pass does not set"
@@ -7,4 +7,16 @@
7
7
  */
8
8
  export { createCodeService } from './service.js';
9
9
  export type { CodeRequest, CodeService, CodeServiceOptions } from './service.js';
10
+ /**
11
+ * The configuration class the service hands the linter.
12
+ *
13
+ * A host that resolves rules from its own storage parses a `.sasjslint` and has
14
+ * to build the configuration the routes expect. Exporting the class here lets
15
+ * it build that with the linter this package bundles, instead of adding
16
+ * `@sasjs/lint` to its own dependencies and carrying a second copy to keep in
17
+ * step. What keeps the two in step is this package's exact dependency pin, not
18
+ * the export: a host that installs the linter itself still resolves whatever
19
+ * its own tree gives it.
20
+ */
21
+ export { LintConfig } from '@sasjs/lint';
10
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/code/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/code/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEhF;;;;;;;;;;GAUG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA"}
@@ -6,3 +6,15 @@
6
6
  * stays free of it and a host that wants these routes imports `@sasjs/api/code`.
7
7
  */
8
8
  export { createCodeService } from './service.js';
9
+ /**
10
+ * The configuration class the service hands the linter.
11
+ *
12
+ * A host that resolves rules from its own storage parses a `.sasjslint` and has
13
+ * to build the configuration the routes expect. Exporting the class here lets
14
+ * it build that with the linter this package bundles, instead of adding
15
+ * `@sasjs/lint` to its own dependencies and carrying a second copy to keep in
16
+ * step. What keeps the two in step is this package's exact dependency pin, not
17
+ * the export: a host that installs the linter itself still resolves whatever
18
+ * its own tree gives it.
19
+ */
20
+ export { LintConfig } from '@sasjs/lint';
@@ -13,8 +13,15 @@ export interface CodeServiceOptions {
13
13
  * A host resolves the nearest `.sasjslint` at or above `filePath`, so each
14
14
  * folder can carry its own rules; without one the linter's defaults apply,
15
15
  * which is what an untitled buffer lints against.
16
+ *
17
+ * It may answer with a promise. A host whose rules are files in a store it
18
+ * reads asynchronously - the browser host over its drive - holds no
19
+ * synchronous copy to hand back, and reading the rules per request is the
20
+ * point of the option rather than an overhead to cache around. A host with
21
+ * the configuration already in hand returns it directly, which the routes
22
+ * await either way.
16
23
  */
17
- lintConfig?: (filePath?: string) => LintConfig | undefined;
24
+ lintConfig?: (filePath?: string) => LintConfig | undefined | Promise<LintConfig | undefined>;
18
25
  }
19
26
  export interface CodeService {
20
27
  /** The diagnostics for a buffer. Nothing is written and nothing is executed. */
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/code/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE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AAM,WAAW,WAAW;IAC1B,gFAAgF;IAChF,IAAI,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAAA;IAC3E,4BAA4B;IAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CACxE;AAmBD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAS,kBAAuB,KAC/B,WAqBF,CAAA"}
@@ -39,15 +39,15 @@ export const createCodeService = (options = {}) => {
39
39
  if (!caller)
40
40
  throw new ApiError(401, 'Unauthorized');
41
41
  };
42
- const configFor = (filePath) => options.lintConfig ? options.lintConfig(filePath) : undefined;
42
+ const configFor = async (filePath) => options.lintConfig ? await options.lintConfig(filePath) : undefined;
43
43
  return {
44
44
  async lint(caller, body) {
45
45
  requireCaller(caller);
46
- return lintText(codeOf(body), configFor(body.filePath));
46
+ return lintText(codeOf(body), await configFor(body.filePath));
47
47
  },
48
48
  async format(caller, body) {
49
49
  requireCaller(caller);
50
- return formatText(codeOf(body), configFor(body.filePath));
50
+ return formatText(codeOf(body), await configFor(body.filePath));
51
51
  }
52
52
  };
53
53
  };
@@ -1 +1 @@
1
- {"version":3,"file":"compute.d.ts","sourceRoot":"","sources":["../../../src/viya/compute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAOhE,kFAAkF;AAClF,eAAO,MAAM,oBAAoB,6BAA6B,CAAA;AAE9D,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,QAAuC,CAAA;AA+CvE;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,GAAG,SAAS,KAAG,MAM5D,CAAA;AA6GD,eAAO,MAAM,gBAAg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 @@ const jobBody = (job) => {
101
101
  sessionId: job.sessionId,
102
102
  state: job.state,
103
103
  creationTimeStamp: job.creationTimeStamp,
104
- completedTimeStamp: job.completedTimeStamp,
104
+ ...(job.completedTimeStamp
105
+ ? { completedTimeStamp: job.completedTimeStamp }
106
+ : {}),
105
107
  jobConditionCode: 0,
106
108
  stateElapsedTime: 1,
107
109
  listingStatistics: {
108
110
  lineCount: job.log.length,
109
- modifiedTimeStamp: job.completedTimeStamp
111
+ modifiedTimeStamp: job.completedTimeStamp ?? job.creationTimeStamp
110
112
  },
111
113
  logStatistics: {
112
114
  lineCount: job.log.length,
113
- modifiedTimeStamp: job.completedTimeStamp
115
+ modifiedTimeStamp: job.completedTimeStamp ?? job.creationTimeStamp
114
116
  },
115
117
  statistics: { systemCpuTime: 0.01, userCpuTime: 0.02 },
116
118
  version: 2,
@@ -182,9 +184,64 @@ export const COMPUTE_HANDLERS = {
182
184
  },
183
185
  'POST /compute/sessions/{}/jobs': async ({ services, params, request }) => {
184
186
  const session = sessionOf(services, params.id);
185
- const job = estateOf(services).submit(session, (request.body ?? {}));
187
+ const body = (request.body ?? {});
188
+ const job = estateOf(services).submit(session, body);
189
+ const execute = services.viya?.execute;
190
+ // a host with no engine has nothing to run, so the job is finished at once
191
+ if (!execute) {
192
+ job.state = 'completed';
193
+ job.completedTimeStamp = new Date().toISOString();
194
+ return { status: 201, body: jobBody(job) };
195
+ }
196
+ // the 201 is the submission, not the run: the client polls the state link,
197
+ // and `waitForResult: false` is documented to return here and poll later
198
+ job.state = 'running';
199
+ // and there is no log yet: the generated lines are what a host with NO engine
200
+ // answers, including one that says the run completed, so a running job must
201
+ // not advertise them - the run writes the log when it has one
202
+ job.log = [];
203
+ void execute({
204
+ program: body.code ?? '',
205
+ variables: body.variables,
206
+ name: body.name,
207
+ sessionId: session.id
208
+ })
209
+ .then((ran) => {
210
+ job.log = ran.log.split('\n');
211
+ job.state = ran.state ?? 'completed';
212
+ if (ran.webout !== undefined)
213
+ job.webout = ran.webout;
214
+ job.completedTimeStamp = new Date().toISOString();
215
+ })
216
+ .catch((error) => {
217
+ // a run that threw is a failed job with the reason in its log, because a
218
+ // client reads the failure from the state and the log together
219
+ job.state = 'failed';
220
+ job.log = [`ERROR: ${error.message}`];
221
+ job.completedTimeStamp = new Date().toISOString();
222
+ });
186
223
  return { status: 201, body: jobBody(job) };
187
224
  },
225
+ 'GET /compute/sessions/{}/filerefs/_webout/content': async ({ services, params }) => {
226
+ const session = sessionOf(services, params.id);
227
+ const last = [...session.jobs.values()].pop();
228
+ if (!last)
229
+ throw new ApiError(404, 'This session has no `_webout` yet: nothing has run in it.');
230
+ // the answer belongs to the last job submitted, not to the newest one that
231
+ // happened to produce something: a failed service must not answer with an
232
+ // earlier service's data
233
+ if (last.webout === undefined)
234
+ throw new ApiError(404, last.state === 'running'
235
+ ? `This session has no \`_webout\` yet: job '${last.id}' has not finished.`
236
+ : services.viya?.execute
237
+ ? `This session has no \`_webout\`: job '${last.id}' ran and produced none.`
238
+ : `This session has no \`_webout\`: the host supplied no engine, so no program has run.`);
239
+ return {
240
+ status: 200,
241
+ contents: last.webout,
242
+ headers: { 'content-type': 'text/plain' }
243
+ };
244
+ },
188
245
  'GET /compute/sessions/{}/jobs/{}': async ({ services, params }) => {
189
246
  const [sessionId, jobId] = segmentsOf(params);
190
247
  return { status: 200, body: jobBody(jobOf(services, sessionId, jobId)) };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Operations the emulator must answer that no capture describes.
3
+ *
4
+ * The table is generated from what an estate answered, which is the right rule:
5
+ * a row nobody observed is a claim about a call no client makes. But a client
6
+ * does make some calls that no recording pass reaches, and an emulator that
7
+ * cannot answer them is an emulator an application cannot run on. Those rows are
8
+ * stated here, each with the reason it has no capture, and they pass through the
9
+ * same overlay ratchet as a captured one - so a declared operation still needs a
10
+ * decision about whether this package implements it.
11
+ *
12
+ * They are kept out of `src/viya/table.ts` because that file is generated: a
13
+ * hand-written row in it would be deleted by the next `npm run sync:viya`, and a
14
+ * generator that had to preserve hand edits would stop being a generator.
15
+ */
16
+ import { type ViyaOperation } from './table.js';
17
+ /** A row, and why it is stated rather than recorded. */
18
+ export interface DeclaredOperation extends ViyaOperation {
19
+ /** What no capture could show, and why the client still needs it. */
20
+ declared: string;
21
+ }
22
+ export declare const DECLARED: DeclaredOperation[];
23
+ /** Every operation the emulator answers: what an estate did, plus what it must. */
24
+ export declare const VIYA_OPERATIONS: ViyaOperation[];
25
+ //# sourceMappingURL=declared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declared.d.ts","sourceRoot":"","sources":["../../../src/viya/declared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,YAAY,CAAA;AAE3D,wDAAwD;AACxD,MAAM,WAAW,iBAAkB,SAAQ,aAAa;IACtD,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,eAAO,MAAM,QAAQ,EAAE,iBAAiB,EAiBvC,CAAA;AAED,mFAAmF;AACnF,eAAO,MAAM,eAAe,EAAE,aAAa,EAAiC,CAAA"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Operations the emulator must answer that no capture describes.
3
+ *
4
+ * The table is generated from what an estate answered, which is the right rule:
5
+ * a row nobody observed is a claim about a call no client makes. But a client
6
+ * does make some calls that no recording pass reaches, and an emulator that
7
+ * cannot answer them is an emulator an application cannot run on. Those rows are
8
+ * stated here, each with the reason it has no capture, and they pass through the
9
+ * same overlay ratchet as a captured one - so a declared operation still needs a
10
+ * decision about whether this package implements it.
11
+ *
12
+ * They are kept out of `src/viya/table.ts` because that file is generated: a
13
+ * hand-written row in it would be deleted by the next `npm run sync:viya`, and a
14
+ * generator that had to preserve hand edits would stop being a generator.
15
+ */
16
+ import { VIYA_TABLE } from './table.js';
17
+ export const DECLARED = [
18
+ {
19
+ id: 'GET /compute/sessions/{}/filerefs/_webout/content',
20
+ method: 'GET',
21
+ path: '/compute/sessions/{}/filerefs/_webout/content',
22
+ steps: [],
23
+ // what this emulator answers, not what an estate did: 200 with the webout,
24
+ // 404 when no program has run in the session
25
+ statuses: [200, 404],
26
+ queries: [],
27
+ request: { queries: [], body: undefined },
28
+ // the body is the program's `_webout`, which is whatever the program wrote:
29
+ // there is no JSON shape to record
30
+ shape: undefined,
31
+ declared: 'The adapter fetches this only when a run expects a webout (`expectWebout`), and the recording pass submits a `%put` and reads the log instead. Without it an application cannot receive the data its service returns, so the emulator answers it from the job it just ran.'
32
+ }
33
+ ];
34
+ /** Every operation the emulator answers: what an estate did, plus what it must. */
35
+ export const VIYA_OPERATIONS = [...VIYA_TABLE, ...DECLARED];
@@ -12,7 +12,7 @@
12
12
  * evidence about Viya.
13
13
  */
14
14
  import type { ApiRequest, ApiResponse, Services } from '../host/dispatch.js';
15
- import { type ViyaOperation } from './table.js';
15
+ import type { ViyaOperation } from './table.js';
16
16
  /** An answer that states which contract produced it. */
17
17
  export interface ViyaResponse extends ApiResponse {
18
18
  /** Always carries `x-sasjs-emulated`, including on a 404 and a 501. */
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../../src/viya/dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAE5E,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,YAAY,CAAA;AAK3D,wDAAwD;AACxD,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAChC;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,aAAa,CAAA;IACxB,sDAAsD;IACtD,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AA4BD,2EAA2E;AAC3E,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,MAAM,EACd,MAAM,MAAM,KACX,SAAS,GAAG,SA0Bd,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GACvB,UAAU,QAAQ,EAClB,QAAQ,MAAM,EACd,MAAM,MAAM,EACZ,UAAS,UAAe,KACvB,OAAO,CAAC,YAAY,CAyFtB,CAAA"}
1
+ {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../../src/viya/dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAE5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAM/C,wDAAwD;AACxD,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAChC;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,aAAa,CAAA;IACxB,sDAAsD;IACtD,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AA4BD,2EAA2E;AAC3E,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,MAAM,EACd,MAAM,MAAM,KACX,SAAS,GAAG,SA0Bd,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GACvB,UAAU,QAAQ,EAClB,QAAQ,MAAM,EACd,MAAM,MAAM,EACZ,UAAS,UAAe,KACvB,OAAO,CAAC,YAAY,CAyFtB,CAAA"}
@@ -1,10 +1,10 @@
1
1
  import { isApiError } from '../types.js';
2
- import { VIYA_TABLE } from './table.js';
2
+ import { VIYA_OPERATIONS } from './declared.js';
3
3
  import { VIYA_OVERLAY } from './overlay.js';
4
4
  import { VIYA_HANDLERS } from './service.js';
5
5
  import { emulatedHeaders } from './version.js';
6
6
  const escape = (segment) => segment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
7
- const compiled = VIYA_TABLE.filter((operation) => operation.path.includes('{}')).map((operation) => ({
7
+ const compiled = VIYA_OPERATIONS.filter((operation) => operation.path.includes('{}')).map((operation) => ({
8
8
  operation,
9
9
  pattern: new RegExp('^' +
10
10
  operation.path
@@ -16,7 +16,7 @@ const compiled = VIYA_TABLE.filter((operation) => operation.path.includes('{}'))
16
16
  'i')
17
17
  }));
18
18
  const exact = new Map();
19
- for (const operation of VIYA_TABLE)
19
+ for (const operation of VIYA_OPERATIONS)
20
20
  if (!operation.path.includes('{}'))
21
21
  // keyed in lower case, because the hosts are: express's `case sensitive
22
22
  // routing` is off and the emulated estate has to match what they serve
@@ -1 +1 @@
1
- {"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../../../src/viya/overlay.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,OAAO,CAAA;IACpB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAYD,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CA8BzD,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,GAC/B,SAAS,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,EACzC,aAAY,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAc,KAC7C,IAcF,CAAA"}
1
+ {"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../../../src/viya/overlay.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,OAAO,CAAA;IACpB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAYD,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAiCzD,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,GAC/B,SAAS,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,EACzC,aAAY,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAmB,KAClD,IAcF,CAAA"}
@@ -11,7 +11,7 @@
11
11
  * A declined row is not a TODO. The reason names what is missing, so a caller
12
12
  * that reaches it learns why rather than that something is unimplemented.
13
13
  */
14
- import { VIYA_TABLE } from './table.js';
14
+ import { VIYA_OPERATIONS } from './declared.js';
15
15
  /**
16
16
  * The token endpoint is the host's.
17
17
  *
@@ -46,7 +46,9 @@ export const VIYA_OVERLAY = {
46
46
  'GET /files/files/{}/content': { implemented: true },
47
47
  'PUT /files/files/{}/content': { implemented: true },
48
48
  // declined: the host owns the token port
49
- 'POST /SASLogon/oauth/token': { implemented: false, reason: NEEDS_AUTH }
49
+ 'POST /SASLogon/oauth/token': { implemented: false, reason: NEEDS_AUTH },
50
+ // declared, not captured: the webout an application's service returns
51
+ 'GET /compute/sessions/{}/filerefs/_webout/content': { implemented: true }
50
52
  };
51
53
  /**
52
54
  * Refuse an overlay and a table that do not describe the same operations.
@@ -63,7 +65,7 @@ export const VIYA_OVERLAY = {
63
65
  * Called at import, and exported so the refusals themselves can be tested: a
64
66
  * check that only runs on import is a check nothing can pin.
65
67
  */
66
- export const assertOverlayEntries = (overlay, operations = VIYA_TABLE) => {
68
+ export const assertOverlayEntries = (overlay, operations = VIYA_OPERATIONS) => {
67
69
  const known = new Set(operations.map((operation) => operation.id));
68
70
  for (const id of Object.keys(overlay))
69
71
  if (!known.has(id))
@@ -20,11 +20,48 @@
20
20
  */
21
21
  /** The seed every emulated estate falls back to. */
22
22
  export declare const DEFAULT_SEED = "emulated";
23
+ /**
24
+ * What a host does when the emulated estate is asked to run a program.
25
+ *
26
+ * Absent, the emulator generates a log and says so: it has no engine, which is
27
+ * the whole reason its answers are seeded. Present, the host runs the program on
28
+ * whatever engine it has and returns what the program produced - which is what
29
+ * makes an application's `_webout` real rather than generated.
30
+ */
31
+ export interface ViyaExecutor {
32
+ execute(request: {
33
+ /** The program: a string, or the lines the client sent. */
34
+ program: string | string[];
35
+ /** The session variables the client attached to the job. */
36
+ variables?: Record<string, string>;
37
+ /** The job's name, which the adapter sets to the service path. */
38
+ name?: string;
39
+ /** The session the job belongs to. */
40
+ sessionId: string;
41
+ }): Promise<ViyaRun>;
42
+ }
43
+ /** What an engine answers for one program. */
44
+ export interface ViyaRun {
45
+ /** The program's `_webout` content, when it produced one. */
46
+ webout?: string;
47
+ /** The log the program produced, as one string with lines separated by `\n`. */
48
+ log: string;
49
+ /**
50
+ * How the run ended.
51
+ *
52
+ * A client decides a service failed from the job's state, not from the log, so
53
+ * a run that failed has to say so - otherwise the webout it did not produce
54
+ * reads as data. Absent, the run completed.
55
+ */
56
+ state?: 'completed' | 'failed';
57
+ }
23
58
  export interface ViyaSeedSettings {
24
59
  /** The address this estate answers at. */
25
60
  serverUrl?: string;
26
61
  /** Pins the generated data when the address is not the identity. */
27
62
  seed?: string | number;
63
+ /** Runs a submitted program, when the host has an engine. */
64
+ execute?: ViyaExecutor['execute'];
28
65
  }
29
66
  /**
30
67
  * The address reduced to what identifies it.
@@ -1 +1 @@
1
- {"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../../src/viya/seed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,oDAAoD;AACpD,eAAO,MAAM,YAAY,aAAa,CAAA;AAEtC,MAAM,WAAW,gBAAgB;IAC/B,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,oEAAoE;IACpE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACvB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,KAAK,MAAM,GAAG,SAAS,KAAG,MA+C5D,CAAA;AAED,8DAA8D;AAC9D,eAAO,MAAM,IAAI,GAAI,OAAO,MAAM,KAAG,MASpC,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,GAAI,WAAU,gBAAqB,KAAG,MAOxD,CAAA;AAED;;;;;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AAC,CAAA;CAClC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,KAAK,MAAM,GAAG,SAAS,KAAG,MA+C5D,CAAA;AAED,8DAA8D;AAC9D,eAAO,MAAM,IAAI,GAAI,OAAO,MAAM,KAAG,MASpC,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,GAAI,WAAU,gBAAqB,KAAG,MAOxD,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,CAAC,MAAM,MAAM,CAarD,CAAA;AAED,4DAA4D;AAC5D,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,MAAM,EAAE,OAAO,MAAM,KAAG,MAChC,CAAA;AAE5B,oDAAoD;AACpD,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,MAAM,MAAM,MAAM,EAAE,QAAQ,CAAC,EAAE,KAAG,CACxB,CAAA"}
@@ -4,10 +4,25 @@ export interface EmulatedJob {
4
4
  name: string;
5
5
  /** The lines the emulated log returns, in order. */
6
6
  log: string[];
7
- /** The state every job is in: the emulator does not fail on purpose. */
8
- state: 'completed';
7
+ /** What the host's engine returned, when the host ran the program. */
8
+ webout?: string;
9
+ /**
10
+ * Where the job is.
11
+ *
12
+ * A job with no engine is completed the moment it is accepted: there is
13
+ * nothing to run. A job a host runs is `running` until the host answers,
14
+ * because the client polls this and a submission that answered `completed`
15
+ * would be a lie about work that had not happened.
16
+ */
17
+ state: 'running' | 'completed' | 'failed';
9
18
  creationTimeStamp: string;
10
- completedTimeStamp: string;
19
+ /**
20
+ * When the run finished, absent until it does.
21
+ *
22
+ * A job that has not settled has no completion time: answering one would tell
23
+ * a client that work finished at the moment it was accepted.
24
+ */
25
+ completedTimeStamp?: string;
11
26
  sessionId: string;
12
27
  }
13
28
  export interface EmulatedSession {
@@ -1 +1 @@
1
- {"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../../../src/viya/sessions.ts"],"names":[],"mappings":"AA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AEzC,gDAAgD;IAChD,MAAM,IAAI,eAAe;IAazB,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAIhD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAI3B,iFAAiF;IACjF,MAAM,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,YAAY,GAAG,WAAW;CAwBjE;AAKD,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,cAUxC,CAAA"}
@@ -84,12 +84,13 @@ export class EmulatedEstate {
84
84
  // the log is a function of the seed and the program alone, so the same
85
85
  // program answers the same lines whatever session it was submitted in
86
86
  log: logFor(this.seed, code),
87
- state: 'completed',
87
+ state: 'running',
88
88
  // the real clock, unlike a folder's: a client computes a session's age
89
89
  // from this stamp and expires it, so a fixed instant in the past is a
90
90
  // session that is born expired
91
91
  creationTimeStamp: new Date().toISOString(),
92
- completedTimeStamp: new Date().toISOString(),
92
+ // no completion stamp here: a job is finished when something finished it,
93
+ // and the handler that knows whether anything will run sets both
93
94
  sessionId: session.id
94
95
  };
95
96
  session.jobs.set(id, submitted);
@@ -1 +1 @@
1
- {"version":3,"file":"unrecorded.d.ts","sourceRoot":"","sources":["../../../src/viya/unrecorded.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAED,eAAO,MAAM,UAAU,EAAE,mBAAmB,EAoE3C,CAAA"}
1
+ {"version":3,"file":"unrecorded.d.ts","sourceRoot":"","sources":["../../../src/viya/unrecorded.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAED,eAAO,MAAM,UAAU,EAAE,mBAAmB,EA+D3C,CAAA"}
@@ -27,10 +27,6 @@ export const UNRECORDED = [
27
27
  reason: 'no capture: the authorisation-code step needs a browser; the pass uses the password grant'
28
28
  },
29
29
  // Compute operations the scripted passes do not reach.
30
- {
31
- path: '/compute/sessions/{}/filerefs/_webout/content',
32
- reason: 'no capture: the adapter reads the webout fileref only when a run expects one (`expectWebout`); the execute pass submits a `%put` and reads the log'
33
- },
34
30
  {
35
31
  path: '/compute/sessions/{}/variables/{}',
36
32
  reason: "no capture: the adapter reads a session variable only to report a submitted job's pid (`printPid`), which the pass does not set"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sasjs/api",
3
- "version": "0.36.0",
3
+ "version": "0.38.0",
4
4
  "description": "The SASjs Server API, described once - a generated route table, the services behind it, and the conformance corpus both hosts run",
5
5
  "license": "MIT",
6
6
  "author": "SASjs",
@@ -75,6 +75,6 @@
75
75
  "minimatch": "11.0.4"
76
76
  },
77
77
  "dependencies": {
78
- "@sasjs/lint": "^5.1.0"
78
+ "@sasjs/lint": "5.1.0"
79
79
  }
80
80
  }