@sasjs/api 0.35.0 → 0.37.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.
Files changed (46) hide show
  1. package/build/browser.js +616 -64
  2. package/build/cjs/viya/compute.js +280 -0
  3. package/build/cjs/viya/declared.js +38 -0
  4. package/build/cjs/viya/dispatch.js +3 -3
  5. package/build/cjs/viya/files.js +199 -0
  6. package/build/cjs/viya/ids.js +60 -0
  7. package/build/cjs/viya/overlay.js +20 -43
  8. package/build/cjs/viya/ports.js +5 -0
  9. package/build/cjs/viya/seed.js +120 -0
  10. package/build/cjs/viya/service.js +51 -85
  11. package/build/cjs/viya/sessions.js +115 -0
  12. package/build/cjs/viya/unrecorded.js +0 -4
  13. package/build/esm/host/dispatch.d.ts +10 -0
  14. package/build/esm/host/dispatch.d.ts.map +1 -1
  15. package/build/esm/viya/compute.d.ts +39 -0
  16. package/build/esm/viya/compute.d.ts.map +1 -0
  17. package/build/esm/viya/compute.js +276 -0
  18. package/build/esm/viya/declared.d.ts +25 -0
  19. package/build/esm/viya/declared.d.ts.map +1 -0
  20. package/build/esm/viya/declared.js +35 -0
  21. package/build/esm/viya/dispatch.d.ts +1 -1
  22. package/build/esm/viya/dispatch.d.ts.map +1 -1
  23. package/build/esm/viya/dispatch.js +3 -3
  24. package/build/esm/viya/files.d.ts +33 -0
  25. package/build/esm/viya/files.d.ts.map +1 -0
  26. package/build/esm/viya/files.js +196 -0
  27. package/build/esm/viya/ids.d.ts +35 -0
  28. package/build/esm/viya/ids.d.ts.map +1 -0
  29. package/build/esm/viya/ids.js +55 -0
  30. package/build/esm/viya/overlay.d.ts.map +1 -1
  31. package/build/esm/viya/overlay.js +20 -43
  32. package/build/esm/viya/ports.d.ts +12 -0
  33. package/build/esm/viya/ports.d.ts.map +1 -0
  34. package/build/esm/viya/ports.js +1 -0
  35. package/build/esm/viya/seed.d.ts +97 -0
  36. package/build/esm/viya/seed.d.ts.map +1 -0
  37. package/build/esm/viya/seed.js +111 -0
  38. package/build/esm/viya/service.d.ts +0 -16
  39. package/build/esm/viya/service.d.ts.map +1 -1
  40. package/build/esm/viya/service.js +10 -43
  41. package/build/esm/viya/sessions.d.ts +78 -0
  42. package/build/esm/viya/sessions.d.ts.map +1 -0
  43. package/build/esm/viya/sessions.js +109 -0
  44. package/build/esm/viya/unrecorded.d.ts.map +1 -1
  45. package/build/esm/viya/unrecorded.js +0 -4
  46. package/package.json +3 -2
@@ -0,0 +1,109 @@
1
+ /**
2
+ * The emulated compute estate: sessions, jobs and the logs generated for them.
3
+ *
4
+ * A session is a handle a client keeps and asks about later, so it lives in the
5
+ * process that issued it - the way a real compute server's does - and it survives
6
+ * as long as the emulator does. Ids are a function of the seed and a counter
7
+ * rather than a random uuid: a session id that changes between runs would break
8
+ * every fixture that names one, which is the same rule as a folder id.
9
+ *
10
+ * Nothing here executes SAS. The engine is not present, and a log that claimed to
11
+ * be output would be a lie the first time somebody read it. The log echoes what
12
+ * was submitted and states, in the log itself, that it is generated - so a client
13
+ * that parses for NOTEs still gets a well-formed log, and a person reading it is
14
+ * not misled about what ran.
15
+ */
16
+ import { drawFrom, drawInt, generator, hash } from './seed.js';
17
+ /**
18
+ * The generated log for one program.
19
+ *
20
+ * Deterministic in (seed, code): the same program on the same estate answers the
21
+ * same lines, so a test can assert a log and a screenshot stays true. The numbers
22
+ * are drawn rather than fixed so that two estates do not look identical, and the
23
+ * generator is re-seeded from the code for each job so that one job's log does not
24
+ * depend on how many jobs ran before it.
25
+ */
26
+ export const logFor = (seed, program) => {
27
+ const code = Array.isArray(program) ? program.join('\n') : program;
28
+ // seeded from the program's TEXT, not its length: two programs of the same
29
+ // length are two programs, and a fixture that names the numbers would be
30
+ // right for both of them otherwise
31
+ const next = generator(seed ^ hash(`code:${code}`));
32
+ const rows = drawInt(next, 900) + 100;
33
+ const seconds = (drawInt(next, 90) + 10) / 100;
34
+ const lines = code
35
+ .split('\n')
36
+ .map((line, index) => `${String(index + 1).padStart(3, ' ')} ${line}`);
37
+ return [
38
+ 'NOTE: Emulated compute engine - this log is generated, not produced by SAS.',
39
+ 'NOTE: No library was touched: the emulated engine has none.',
40
+ ...lines,
41
+ `NOTE: The data set WORK.EMULATED has ${rows} observations and 3 variables.`,
42
+ `NOTE: DATA statement used (Total process time):`,
43
+ `NOTE: real time ${seconds.toFixed(2)} seconds`,
44
+ `NOTE: user cpu time ${(seconds / 2).toFixed(2)} seconds`,
45
+ `NOTE: ${drawFrom(next, ['The emulated run completed.', 'Emulation complete - no SAS was executed.'])}`
46
+ ];
47
+ };
48
+ /**
49
+ * The sessions one estate holds.
50
+ *
51
+ * Keyed by seed, so two emulated estates in one process - a test that runs two
52
+ * targets - do not share a session namespace.
53
+ */
54
+ export class EmulatedEstate {
55
+ constructor(seed) {
56
+ this.seed = seed;
57
+ this.sessions = new Map();
58
+ this.created = 0;
59
+ }
60
+ /** A new session: deterministic id, no jobs. */
61
+ create() {
62
+ const session = {
63
+ id: `emulated-${this.seed.toString(16)}-ses${String(this.created++).padStart(4, '0')}`,
64
+ createdAt: new Date().toISOString(),
65
+ jobs: new Map(),
66
+ submitted: 0
67
+ };
68
+ this.sessions.set(session.id, session);
69
+ return session;
70
+ }
71
+ session(id) {
72
+ return this.sessions.get(id);
73
+ }
74
+ remove(id) {
75
+ return this.sessions.delete(id);
76
+ }
77
+ /** A job accepted into a session, with the log the emulator generated for it. */
78
+ submit(session, job) {
79
+ const id = `${session.id}-job${String(session.submitted++).padStart(4, '0')}`;
80
+ const code = job.code ?? '';
81
+ const submitted = {
82
+ id,
83
+ name: job.name ?? id,
84
+ // the log is a function of the seed and the program alone, so the same
85
+ // program answers the same lines whatever session it was submitted in
86
+ log: logFor(this.seed, code),
87
+ state: 'running',
88
+ // the real clock, unlike a folder's: a client computes a session's age
89
+ // from this stamp and expires it, so a fixed instant in the past is a
90
+ // session that is born expired
91
+ creationTimeStamp: 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
94
+ sessionId: session.id
95
+ };
96
+ session.jobs.set(id, submitted);
97
+ return submitted;
98
+ }
99
+ }
100
+ /** One estate per seed, for the life of the process. */
101
+ const estates = new Map();
102
+ export const estateFor = (seed) => {
103
+ const existing = estates.get(seed);
104
+ if (existing)
105
+ return existing;
106
+ const estate = new EmulatedEstate(seed);
107
+ estates.set(seed, estate);
108
+ return estate;
109
+ };
@@ -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.35.0",
3
+ "version": "0.37.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",
@@ -48,7 +48,8 @@
48
48
  "check:viya": "node scripts/viya-generate.mjs --check",
49
49
  "check:builds": "node scripts/check-builds.mjs",
50
50
  "audit:gate": "node scripts/audit.mjs",
51
- "check:appstream": "node scripts/appstream-browser-check.cjs"
51
+ "check:appstream": "node scripts/appstream-browser-check.cjs",
52
+ "conformance": "node tools/viya-conformance/conformance.mjs"
52
53
  },
53
54
  "devDependencies": {
54
55
  "@semantic-release/commit-analyzer": "13.0.1",