@sasjs/api 0.33.0 → 0.36.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 (63) hide show
  1. package/build/browser.js +2452 -50
  2. package/build/cjs/corpus/viya/operations.js +647 -0
  3. package/build/cjs/index.js +60 -40
  4. package/build/cjs/viya/compute.js +223 -0
  5. package/build/cjs/viya/dispatch.js +141 -0
  6. package/build/cjs/viya/files.js +199 -0
  7. package/build/cjs/viya/ids.js +60 -0
  8. package/build/cjs/viya/overlay.js +79 -0
  9. package/build/cjs/viya/ports.js +5 -0
  10. package/build/cjs/viya/seed.js +120 -0
  11. package/build/cjs/viya/service.js +283 -0
  12. package/build/cjs/viya/sessions.js +114 -0
  13. package/build/cjs/viya/surface.js +1 -49
  14. package/build/cjs/viya/table.js +805 -0
  15. package/build/cjs/viya/unrecorded.js +58 -0
  16. package/build/cjs/viya/version.js +43 -0
  17. package/build/esm/corpus/viya/operations.d.ts +28 -0
  18. package/build/esm/corpus/viya/operations.d.ts.map +1 -0
  19. package/build/esm/corpus/viya/operations.js +644 -0
  20. package/build/esm/host/dispatch.d.ts +10 -0
  21. package/build/esm/host/dispatch.d.ts.map +1 -1
  22. package/build/esm/index.d.ts +12 -0
  23. package/build/esm/index.d.ts.map +1 -1
  24. package/build/esm/index.js +7 -0
  25. package/build/esm/viya/compute.d.ts +39 -0
  26. package/build/esm/viya/compute.d.ts.map +1 -0
  27. package/build/esm/viya/compute.js +219 -0
  28. package/build/esm/viya/dispatch.d.ts +35 -0
  29. package/build/esm/viya/dispatch.d.ts.map +1 -0
  30. package/build/esm/viya/dispatch.js +136 -0
  31. package/build/esm/viya/files.d.ts +33 -0
  32. package/build/esm/viya/files.d.ts.map +1 -0
  33. package/build/esm/viya/files.js +196 -0
  34. package/build/esm/viya/ids.d.ts +35 -0
  35. package/build/esm/viya/ids.d.ts.map +1 -0
  36. package/build/esm/viya/ids.js +55 -0
  37. package/build/esm/viya/overlay.d.ts +25 -0
  38. package/build/esm/viya/overlay.d.ts.map +1 -0
  39. package/build/esm/viya/overlay.js +75 -0
  40. package/build/esm/viya/ports.d.ts +12 -0
  41. package/build/esm/viya/ports.d.ts.map +1 -0
  42. package/build/esm/viya/ports.js +1 -0
  43. package/build/esm/viya/seed.d.ts +60 -0
  44. package/build/esm/viya/seed.d.ts.map +1 -0
  45. package/build/esm/viya/seed.js +111 -0
  46. package/build/esm/viya/service.d.ts +28 -0
  47. package/build/esm/viya/service.d.ts.map +1 -0
  48. package/build/esm/viya/service.js +280 -0
  49. package/build/esm/viya/sessions.d.ts +63 -0
  50. package/build/esm/viya/sessions.d.ts.map +1 -0
  51. package/build/esm/viya/sessions.js +108 -0
  52. package/build/esm/viya/surface.d.ts.map +1 -1
  53. package/build/esm/viya/surface.js +1 -49
  54. package/build/esm/viya/table.d.ts +39 -0
  55. package/build/esm/viya/table.d.ts.map +1 -0
  56. package/build/esm/viya/table.js +802 -0
  57. package/build/esm/viya/unrecorded.d.ts +24 -0
  58. package/build/esm/viya/unrecorded.d.ts.map +1 -0
  59. package/build/esm/viya/unrecorded.js +55 -0
  60. package/build/esm/viya/version.d.ts +37 -0
  61. package/build/esm/viya/version.d.ts.map +1 -0
  62. package/build/esm/viya/version.js +39 -0
  63. package/package.json +5 -2
@@ -0,0 +1,280 @@
1
+ import { ApiError } from '../types.js';
2
+ import { requireDrive } from './ports.js';
3
+ import { COMPUTE_HANDLERS } from './compute.js';
4
+ import { FILE_HANDLERS } from './files.js';
5
+ import { idFor, normalisePath, EMULATED_NOW, EMULATED_USER } from './ids.js';
6
+ const linksFor = (uri, collection = false) => {
7
+ const self = {
8
+ href: uri,
9
+ uri,
10
+ rel: 'self',
11
+ method: 'GET',
12
+ type: 'application/vnd.sas.folder'
13
+ };
14
+ const members = {
15
+ href: `${uri}/members`,
16
+ uri: `${uri}/members`,
17
+ rel: 'members',
18
+ method: 'GET',
19
+ type: 'application/vnd.sas.collection',
20
+ itemType: 'folder'
21
+ };
22
+ // a collection answer leads with the collection link, which carries the
23
+ // itemType its capture recorded
24
+ return collection ? [members, self] : [self, members];
25
+ };
26
+ const folderBody = async (drive, path) => {
27
+ const listing = await drive.list(path);
28
+ const id = idFor(path);
29
+ const name = path.split('/').filter(Boolean).pop() ?? '';
30
+ const parent = path.split('/').slice(0, -1).join('/') || '/';
31
+ return {
32
+ id,
33
+ name,
34
+ description: '',
35
+ type: 'folder',
36
+ version: 1,
37
+ createdBy: EMULATED_USER.id,
38
+ modifiedBy: EMULATED_USER.id,
39
+ creationTimeStamp: EMULATED_NOW,
40
+ modifiedTimeStamp: EMULATED_NOW,
41
+ memberCount: listing.files.length + listing.folders.length,
42
+ parentFolderUri: `/folders/folders/${idFor(parent)}`,
43
+ links: linksFor(`/folders/folders/${id}`)
44
+ };
45
+ };
46
+ const recycleBin = () => {
47
+ const path = '@myRecycleBin';
48
+ const id = idFor(path);
49
+ return {
50
+ id,
51
+ name: 'Recycle Bin',
52
+ description: 'Recycle Bin',
53
+ type: 'trashFolder',
54
+ version: 1,
55
+ createdBy: EMULATED_USER.id,
56
+ modifiedBy: EMULATED_USER.id,
57
+ creationTimeStamp: EMULATED_NOW,
58
+ modifiedTimeStamp: EMULATED_NOW,
59
+ memberCount: 0,
60
+ parentFolderUri: '',
61
+ properties: { allowMove: 'false' },
62
+ links: linksFor(`/folders/folders/${id}`)
63
+ };
64
+ };
65
+ const pathFromQuery = (request) => {
66
+ const path = request.query?.path;
67
+ if (!path)
68
+ throw new ApiError(400, 'The path parameter is required.');
69
+ return normalisePath(path);
70
+ };
71
+ /** The recycle-bin alias the emulator answers, which is also a valid parent. */
72
+ const RECYCLE_BIN_ALIAS = '/folders/folders/@myRecycleBin';
73
+ const isRecycleBin = (uri) => !!uri &&
74
+ (uri === RECYCLE_BIN_ALIAS || uri.endsWith(`/${idFor('@myRecycleBin')}`));
75
+ /**
76
+ * The path a folder id stands for, found by walking the drive.
77
+ *
78
+ * An id is derived from a path, so the drive is the index: a map would be a
79
+ * second source of truth that goes stale the moment a folder is renamed or
80
+ * moved - and would answer 404 for every id after a restart, which is the
81
+ * opposite of "a client stores an id and asks for it later".
82
+ */
83
+ const pathForId = async (drive, id) => {
84
+ const walk = (node) => {
85
+ if (node.isFolder && idFor(node.relativePath) === id)
86
+ return node.relativePath;
87
+ for (const child of node.children) {
88
+ const hit = walk(child);
89
+ if (hit)
90
+ return hit;
91
+ }
92
+ return undefined;
93
+ };
94
+ const { tree } = await drive.tree('/');
95
+ const path = walk(tree);
96
+ if (!path)
97
+ throw new ApiError(404, `No folder matches the id ${id}. Ids are derived from paths, so an id that names no folder is one no folder ever had.`);
98
+ return path;
99
+ };
100
+ /** The handlers, keyed by the operation id the table states. */
101
+ export const VIYA_HANDLERS = {
102
+ 'GET /identities/users/@currentUser': async ({ services, request }) => {
103
+ const subject = request.subject ??
104
+ (await services.identity?.authenticate(request.token));
105
+ const id = subject?.userId ?? EMULATED_USER.id;
106
+ return {
107
+ status: 200,
108
+ body: {
109
+ id,
110
+ name: subject?.userId ?? EMULATED_USER.name,
111
+ providerId: 'sas',
112
+ state: 'active',
113
+ version: 1,
114
+ addresses: [],
115
+ emailAddresses: [],
116
+ links: [
117
+ {
118
+ href: `/identities/users/${id}`,
119
+ uri: `/identities/users/${id}`,
120
+ rel: 'self',
121
+ method: 'GET',
122
+ type: 'application/vnd.sas.identity.user'
123
+ }
124
+ ]
125
+ }
126
+ };
127
+ },
128
+ 'GET /types/types': async () => ({
129
+ status: 200,
130
+ body: {
131
+ count: 1,
132
+ items: [
133
+ {
134
+ name: 'file',
135
+ type: 'typeDef',
136
+ version: 1,
137
+ links: [{ href: '/types/types/file', rel: 'self', method: 'GET' }]
138
+ }
139
+ ]
140
+ }
141
+ }),
142
+ 'GET /folders/folders/@item': async ({ services, request }) => ({
143
+ status: 200,
144
+ body: await folderBody(requireDrive(services), pathFromQuery(request))
145
+ }),
146
+ 'GET /folders/folders/@myRecycleBin': async () => ({
147
+ status: 200,
148
+ body: recycleBin()
149
+ }),
150
+ 'GET /folders/folders/{}': async ({ services, params }) => {
151
+ // the bin is addressed by id too, and it is not in the drive's tree
152
+ if (params.id === idFor('@myRecycleBin'))
153
+ return { status: 200, body: recycleBin() };
154
+ const drive = requireDrive(services);
155
+ return {
156
+ status: 200,
157
+ body: await folderBody(drive, await pathForId(drive, params.id))
158
+ };
159
+ },
160
+ 'GET /folders/folders/{}/members': async ({ services, params, request }) => {
161
+ const drive = requireDrive(services);
162
+ const limit = Number(request.query?.limit ?? 0) || 0;
163
+ // the bin is not a folder in the drive, and its own body advertises this
164
+ // link - so a client following the answer it just received must not 404
165
+ if (params.id === idFor('@myRecycleBin'))
166
+ return {
167
+ status: 200,
168
+ body: {
169
+ accept: 'application/json',
170
+ name: 'members',
171
+ start: 0,
172
+ // the query value is echoed as the sibling branch echoes it: a caller
173
+ // that asked for five and is told zero cannot tell what happened
174
+ limit,
175
+ count: 0,
176
+ version: 2,
177
+ items: [],
178
+ links: linksFor(`/folders/folders/${idFor('@myRecycleBin')}`, true)
179
+ }
180
+ };
181
+ const path = await pathForId(drive, params.id);
182
+ const listing = await drive.list(path);
183
+ const items = [
184
+ ...listing.folders.map((name) => ({
185
+ id: idFor(`${path}/${name}`.replace(/\/{2,}/g, '/')),
186
+ name,
187
+ type: 'folder',
188
+ version: 1,
189
+ createdBy: EMULATED_USER.id,
190
+ modifiedBy: EMULATED_USER.id,
191
+ creationTimeStamp: EMULATED_NOW,
192
+ modifiedTimeStamp: EMULATED_NOW,
193
+ parentFolderUri: `/folders/folders/${idFor(path)}`,
194
+ uri: `${path}/${name}`.replace(/\/{2,}/g, '/'),
195
+ links: linksFor(`/folders/folders/${idFor(`${path}/${name}`.replace(/\/{2,}/g, '/'))}`)
196
+ })),
197
+ ...listing.files.map((name) => ({
198
+ id: idFor(`${path}/${name}`.replace(/\/{2,}/g, '/'), 'file'),
199
+ name,
200
+ type: 'file',
201
+ version: 1,
202
+ contentType: 'text/plain',
203
+ createdBy: EMULATED_USER.id,
204
+ modifiedBy: EMULATED_USER.id,
205
+ creationTimeStamp: EMULATED_NOW,
206
+ modifiedTimeStamp: EMULATED_NOW,
207
+ parentFolderUri: `/folders/folders/${idFor(path)}`,
208
+ added: EMULATED_NOW,
209
+ uri: `${path}/${name}`.replace(/\/{2,}/g, '/'),
210
+ links: linksFor(`/files/files/${idFor(`${path}/${name}`.replace(/\/{2,}/g, '/'), 'file')}`)
211
+ }))
212
+ ];
213
+ const page = limit > 0 ? items.slice(0, limit) : items;
214
+ // the envelope is what the capture recorded, including the paging fields a
215
+ // client reads to decide whether to ask for more
216
+ return {
217
+ status: 200,
218
+ body: {
219
+ accept: 'application/json',
220
+ name: 'members',
221
+ start: 0,
222
+ limit: limit || page.length,
223
+ count: page.length,
224
+ version: 2,
225
+ items: page,
226
+ links: linksFor(`/folders/folders/${idFor(path)}`, true)
227
+ }
228
+ };
229
+ },
230
+ 'POST /folders/folders': async ({ services, request }) => {
231
+ const drive = requireDrive(services);
232
+ const body = (request.body ?? {});
233
+ if (!body.name)
234
+ throw new ApiError(400, 'A folder name is required.');
235
+ // the capture records the parent as a QUERY parameter, with the name in the
236
+ // body: a handler that read the body alone put every folder at the root
237
+ const parentUri = request.query?.parentFolderUri ?? body.parentFolderUri;
238
+ const parent = parentUri
239
+ ? await pathForId(drive, String(parentUri).split('/').pop())
240
+ : '/';
241
+ const path = normalisePath(`${parent}/${body.name}`);
242
+ await drive.mkdir(path);
243
+ return { status: 201, body: await folderBody(drive, path) };
244
+ },
245
+ 'PATCH /folders/folders/{}': async ({ services, request, params }) => {
246
+ const drive = requireDrive(services);
247
+ if (params.id === idFor('@myRecycleBin'))
248
+ throw new ApiError(400, 'The recycle bin cannot be moved or renamed.');
249
+ const path = await pathForId(drive, params.id);
250
+ const body = (request.body ?? {});
251
+ // the adapter removes a folder by moving it to the recycle bin, which is the
252
+ // shape the capture recorded for this verb. Both spellings arrive: the bin's
253
+ // id, and the alias the emulator itself answers with
254
+ if (isRecycleBin(body.parentFolderUri)) {
255
+ const removed = await folderBody(drive, path);
256
+ await drive.rmdir(path);
257
+ // the answer describes the folder that was moved, not the drive root -
258
+ // a client reads the id and parent from it
259
+ return {
260
+ status: 200,
261
+ body: { ...removed, parentFolderUri: String(body.parentFolderUri) }
262
+ };
263
+ }
264
+ // a move and a rename can arrive together, and an empty parent means the
265
+ // root - the same value means the root on create, so reading it as "no
266
+ // change" here was a second meaning for one string
267
+ const name = body.name ?? path.split('/').pop();
268
+ const parent = body.parentFolderUri === undefined
269
+ ? path.split('/').slice(0, -1).join('/') || '/'
270
+ : body.parentFolderUri === ''
271
+ ? '/'
272
+ : await pathForId(drive, body.parentFolderUri.split('/').pop());
273
+ const target = normalisePath(`${parent}/${name}`);
274
+ if (target !== path)
275
+ await drive.rename(path, target);
276
+ return { status: 200, body: await folderBody(drive, target) };
277
+ },
278
+ ...COMPUTE_HANDLERS,
279
+ ...FILE_HANDLERS
280
+ };
@@ -0,0 +1,63 @@
1
+ /** One submitted job, and what the emulator answered for it. */
2
+ export interface EmulatedJob {
3
+ id: string;
4
+ name: string;
5
+ /** The lines the emulated log returns, in order. */
6
+ log: string[];
7
+ /** The state every job is in: the emulator does not fail on purpose. */
8
+ state: 'completed';
9
+ creationTimeStamp: string;
10
+ completedTimeStamp: string;
11
+ sessionId: string;
12
+ }
13
+ export interface EmulatedSession {
14
+ id: string;
15
+ /** When it was created, on the real clock: a client expires sessions by age. */
16
+ createdAt: string;
17
+ jobs: Map<string, EmulatedJob>;
18
+ /** How many jobs this session has accepted, so ids are stable per session. */
19
+ submitted: number;
20
+ }
21
+ /** What a submitted job answers before it is run - the same for every request. */
22
+ export interface SubmittedJob {
23
+ name?: string;
24
+ description?: string;
25
+ /**
26
+ * The program.
27
+ *
28
+ * A string or a list of lines: `@sasjs/adapter` posts an array of lines, and
29
+ * the capture recorded a string because the recorder posted one. Both are the
30
+ * same program, so both are accepted.
31
+ */
32
+ code?: string | string[];
33
+ }
34
+ /**
35
+ * The generated log for one program.
36
+ *
37
+ * Deterministic in (seed, code): the same program on the same estate answers the
38
+ * same lines, so a test can assert a log and a screenshot stays true. The numbers
39
+ * are drawn rather than fixed so that two estates do not look identical, and the
40
+ * generator is re-seeded from the code for each job so that one job's log does not
41
+ * depend on how many jobs ran before it.
42
+ */
43
+ export declare const logFor: (seed: number, program: string | string[]) => string[];
44
+ /**
45
+ * The sessions one estate holds.
46
+ *
47
+ * Keyed by seed, so two emulated estates in one process - a test that runs two
48
+ * targets - do not share a session namespace.
49
+ */
50
+ export declare class EmulatedEstate {
51
+ private readonly seed;
52
+ private readonly sessions;
53
+ private created;
54
+ constructor(seed: number);
55
+ /** A new session: deterministic id, no jobs. */
56
+ create(): EmulatedSession;
57
+ session(id: string): EmulatedSession | undefined;
58
+ remove(id: string): boolean;
59
+ /** A job accepted into a session, with the log the emulator generated for it. */
60
+ submit(session: EmulatedSession, job: SubmittedJob): EmulatedJob;
61
+ }
62
+ export declare const estateFor: (seed: number) => EmulatedEstate;
63
+ //# sourceMappingURL=sessions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../../../src/viya/sessions.ts"],"names":[],"mappings":"AAiBA,gEAAgE;AAChE,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,oDAAoD;IACpD,GAAG,EAAE,MAAM,EAAE,CAAA;IACb,wEAAwE;IACxE,KAAK,EAAE,WAAW,CAAA;IAClB,iBAAiB,EAAE,MAAM,CAAA;IACzB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,gFAAgF;IAChF,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;IAC9B,8EAA8E;IAC9E,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,kFAAkF;AAClF,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CACzB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,GAAI,MAAM,MAAM,EAAE,SAAS,MAAM,GAAG,MAAM,EAAE,KAAG,MAAM,EAuBvE,CAAA;AAED;;;;;GAKG;AACH,qBAAa,cAAc;IAKb,OAAO,CAAC,QAAQ,CAAC,IAAI;IAJjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqC;IAE9D,OAAO,CAAC,OAAO,CAAI;gBAEU,IAAI,EAAE,MAAM;IAEzC,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;CAuBjE;AAKD,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,cAUxC,CAAA"}
@@ -0,0 +1,108 @@
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: 'completed',
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
+ completedTimeStamp: new Date().toISOString(),
93
+ sessionId: session.id
94
+ };
95
+ session.jobs.set(id, submitted);
96
+ return submitted;
97
+ }
98
+ }
99
+ /** One estate per seed, for the life of the process. */
100
+ const estates = new Map();
101
+ export const estateFor = (seed) => {
102
+ const existing = estates.get(seed);
103
+ if (existing)
104
+ return existing;
105
+ const estate = new EmulatedEstate(seed);
106
+ estates.set(seed, estate);
107
+ return estate;
108
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"surface.d.ts","sourceRoot":"","sources":["../../../src/viya/surface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,WAAW,GACX,WAAW,GACX,cAAc,GACd,YAAY,GACZ,cAAc,GACd,eAAe,GACf,WAAW,CAAA;AAEf,MAAM,WAAW,YAAY;IAC3B,2DAA2D;IAC3D,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,aAAa,CAAA;IACrB,QAAQ,EAAE,IAAI,GAAG,UAAU,CAAA;IAC3B,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAA;CACf;AAED,8DAA8D;AAC9D,eAAO,MAAM,uBAAuB,UAAU,CAAA;AAE9C,eAAO,MAAM,OAAO,EAAE,YAAY,EA8ZjC,CAAA"}
1
+ {"version":3,"file":"surface.d.ts","sourceRoot":"","sources":["../../../src/viya/surface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,WAAW,GACX,WAAW,GACX,cAAc,GACd,YAAY,GACZ,cAAc,GACd,eAAe,GACf,WAAW,CAAA;AAEf,MAAM,WAAW,YAAY;IAC3B,2DAA2D;IAC3D,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,aAAa,CAAA;IACrB,QAAQ,EAAE,IAAI,GAAG,UAAU,CAAA;IAC3B,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAA;CACf;AAED,8DAA8D;AAC9D,eAAO,MAAM,uBAAuB,UAAU,CAAA;AAE9C,eAAO,MAAM,OAAO,EAAE,YAAY,EA0WjC,CAAA"}
@@ -15,35 +15,11 @@
15
15
  export const SURFACE_ADAPTER_VERSION = '6.0.2';
16
16
  export const SURFACE = [
17
17
  // sas9
18
- {
19
- path: '/Public/example/deleteThis',
20
- family: 'sas9',
21
- decision: 'declined',
22
- reason: 'a path in a doc example or a default config value, not a call'
23
- },
24
- {
25
- path: '/Public/example/myFolder',
26
- family: 'sas9',
27
- decision: 'declined',
28
- reason: 'a path in a doc example or a default config value, not a call'
29
- },
30
- {
31
- path: '/Public/newDestination',
32
- family: 'sas9',
33
- decision: 'declined',
34
- reason: 'a path in a doc example or a default config value, not a call'
35
- },
36
- {
37
- path: '/Public/newDestination/myFolder',
38
- family: 'sas9',
39
- decision: 'declined',
40
- reason: 'a path in a doc example or a default config value, not a call'
41
- },
42
18
  {
43
19
  path: '/Public/seedapp',
44
20
  family: 'sas9',
45
21
  decision: 'declined',
46
- reason: 'a path in a doc example or a default config value, not a call'
22
+ reason: 'a default config value the client falls back to, not a call'
47
23
  },
48
24
  {
49
25
  path: '/SASJobExecution',
@@ -58,12 +34,6 @@ export const SURFACE = [
58
34
  decision: 'in',
59
35
  reason: 'the auth flow the client speaks, and the reason the emulated paths cannot be renamed'
60
36
  },
61
- {
62
- path: '/SASLogon/home',
63
- family: 'viya-auth',
64
- decision: 'in',
65
- reason: 'the auth flow the client speaks, and the reason the emulated paths cannot be renamed'
66
- },
67
37
  {
68
38
  path: '/SASLogon/login',
69
39
  family: 'viya-auth',
@@ -126,12 +96,6 @@ export const SURFACE = [
126
96
  decision: 'declined',
127
97
  reason: "the SASjs API surface, answered by the server's own registered routes, not by a Viya-shaped one"
128
98
  },
129
- {
130
- path: '/SASjsApi/{}',
131
- family: 'sasjs-api',
132
- decision: 'declined',
133
- reason: "the SASjs API surface, answered by the server's own registered routes, not by a Viya-shaped one"
134
- },
135
99
  // sas9
136
100
  {
137
101
  path: '/User Folders/{}/My Folder/sasjs/runner',
@@ -140,18 +104,6 @@ export const SURFACE = [
140
104
  reason: 'SAS 9 and SASjs surfaces: the emulator answers Viya, and the same client reaches these on an EBI deployment'
141
105
  },
142
106
  // sasjs-api
143
- {
144
- path: '/api',
145
- family: 'sasjs-api',
146
- decision: 'declined',
147
- reason: "the SASjs API surface, answered by the server's own registered routes, not by a Viya-shaped one"
148
- },
149
- {
150
- path: '/api/stp/execute',
151
- family: 'sasjs-api',
152
- decision: 'declined',
153
- reason: "the SASjs API surface, answered by the server's own registered routes, not by a Viya-shaped one"
154
- },
155
107
  {
156
108
  path: '/auth/refresh',
157
109
  family: 'sasjs-api',
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The Viya route table: every operation the capture observed.
3
+ *
4
+ * Generated by `npm run sync:viya` from a capture taken against Viya
5
+ * V.04.00M0P100526. Do not edit by hand: the capture is the evidence, and a change
6
+ * here that the capture does not support is a claim nobody can check.
7
+ *
8
+ * Values never reach this file. A path keeps its shape with `{}` for a segment
9
+ * that was an identifier, a query keeps its parameter names, and a body is a
10
+ * type sketch - the emulator generates its data from a seed, so the shape is all
11
+ * the table needs.
12
+ */
13
+ import type { HttpMethod } from '../types.js';
14
+ export interface ViyaOperation {
15
+ /** `METHOD /path`, which is what a route table matches. */
16
+ id: string;
17
+ method: HttpMethod;
18
+ /** `{}` is one path segment that was an identifier in the capture. */
19
+ path: string;
20
+ /** The scripted pass that produced it, so a reader can find the step. */
21
+ steps: string[];
22
+ /** Every status the estate answered with, as observed. */
23
+ statuses: number[];
24
+ /** Query parameter names the client sent. Values are estate data. */
25
+ queries: string[];
26
+ /**
27
+ * The request the client built: its query names, and its body's shape - a
28
+ * type sketch for JSON, parameter names for a form or multipart body, and
29
+ * undefined only where nothing could be read.
30
+ */
31
+ request?: {
32
+ queries: string[];
33
+ body?: unknown;
34
+ };
35
+ /** The body shape of the answer a client keys on. */
36
+ shape?: unknown;
37
+ }
38
+ export declare const VIYA_TABLE: ViyaOperation[];
39
+ //# sourceMappingURL=table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/viya/table.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,MAAM,WAAW,aAAa;IAC5B,2DAA2D;IAC3D,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,UAAU,CAAA;IAClB,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAA;IACZ,yEAAyE;IACzE,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,0DAA0D;IAC1D,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,qEAAqE;IACrE,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB;;;;OAIG;IACH,OAAO,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;IAC/C,qDAAqD;IACrD,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,eAAO,MAAM,UAAU,EAAE,aAAa,EAqxBrC,CAAA"}