@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.
- package/build/browser.js +616 -64
- package/build/cjs/viya/compute.js +280 -0
- package/build/cjs/viya/declared.js +38 -0
- package/build/cjs/viya/dispatch.js +3 -3
- package/build/cjs/viya/files.js +199 -0
- package/build/cjs/viya/ids.js +60 -0
- package/build/cjs/viya/overlay.js +20 -43
- package/build/cjs/viya/ports.js +5 -0
- package/build/cjs/viya/seed.js +120 -0
- package/build/cjs/viya/service.js +51 -85
- package/build/cjs/viya/sessions.js +115 -0
- package/build/cjs/viya/unrecorded.js +0 -4
- package/build/esm/host/dispatch.d.ts +10 -0
- package/build/esm/host/dispatch.d.ts.map +1 -1
- package/build/esm/viya/compute.d.ts +39 -0
- package/build/esm/viya/compute.d.ts.map +1 -0
- package/build/esm/viya/compute.js +276 -0
- package/build/esm/viya/declared.d.ts +25 -0
- package/build/esm/viya/declared.d.ts.map +1 -0
- package/build/esm/viya/declared.js +35 -0
- package/build/esm/viya/dispatch.d.ts +1 -1
- package/build/esm/viya/dispatch.d.ts.map +1 -1
- package/build/esm/viya/dispatch.js +3 -3
- package/build/esm/viya/files.d.ts +33 -0
- package/build/esm/viya/files.d.ts.map +1 -0
- package/build/esm/viya/files.js +196 -0
- package/build/esm/viya/ids.d.ts +35 -0
- package/build/esm/viya/ids.d.ts.map +1 -0
- package/build/esm/viya/ids.js +55 -0
- package/build/esm/viya/overlay.d.ts.map +1 -1
- package/build/esm/viya/overlay.js +20 -43
- package/build/esm/viya/ports.d.ts +12 -0
- package/build/esm/viya/ports.d.ts.map +1 -0
- package/build/esm/viya/ports.js +1 -0
- package/build/esm/viya/seed.d.ts +97 -0
- package/build/esm/viya/seed.d.ts.map +1 -0
- package/build/esm/viya/seed.js +111 -0
- package/build/esm/viya/service.d.ts +0 -16
- package/build/esm/viya/service.d.ts.map +1 -1
- package/build/esm/viya/service.js +10 -43
- package/build/esm/viya/sessions.d.ts +78 -0
- package/build/esm/viya/sessions.d.ts.map +1 -0
- package/build/esm/viya/sessions.js +109 -0
- package/build/esm/viya/unrecorded.d.ts.map +1 -1
- package/build/esm/viya/unrecorded.js +0 -4
- package/package.json +3 -2
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The values that identify the emulated estate, in one place.
|
|
3
|
+
*
|
|
4
|
+
* They live apart from the handlers because two handler modules need them: the
|
|
5
|
+
* folder family derives a folder id, the compute family derives a context and a
|
|
6
|
+
* server id, and a module that imports the other's handler map to reach them
|
|
7
|
+
* would be a cycle.
|
|
8
|
+
*/
|
|
9
|
+
/** The emulated clock: a fixed instant, so a body is reproducible. */
|
|
10
|
+
export declare const EMULATED_NOW = "2026-01-01T00:00:00.000Z";
|
|
11
|
+
/** The caller the emulated estate reports when a host does not name one. */
|
|
12
|
+
export declare const EMULATED_USER: {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A uuid shape from a string, deterministically.
|
|
18
|
+
*
|
|
19
|
+
* Two 32-bit FNV-1a passes give enough of a hash to fill a uuid's fields, and the
|
|
20
|
+
* version/variant nibbles are set so the result is a well-formed v4-shaped id.
|
|
21
|
+
* Collisions are possible in principle and irrelevant here: the id is a handle
|
|
22
|
+
* the emulator hands back, not a uniqueness guarantee.
|
|
23
|
+
*/
|
|
24
|
+
export declare const idFor: (path: string, kind?: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* One folder path, however it was spelled.
|
|
27
|
+
*
|
|
28
|
+
* The adapter joins a root of '/' to a path of '/app' and sends '//app', which is
|
|
29
|
+
* a different string and - because an id is derived from the path - a different
|
|
30
|
+
* id. A client that then asks for that id is asking about a folder the drive does
|
|
31
|
+
* not have, so every path is collapsed to one spelling before anything derives
|
|
32
|
+
* from it.
|
|
33
|
+
*/
|
|
34
|
+
export declare const normalisePath: (path: string) => string;
|
|
35
|
+
//# sourceMappingURL=ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../../src/viya/ids.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,sEAAsE;AACtE,eAAO,MAAM,YAAY,6BAA6B,CAAA;AAEtD,4EAA4E;AAC5E,eAAO,MAAM,aAAa;;;CAAiD,CAAA;AAE3E;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,GAAI,MAAM,MAAM,EAAE,aAAe,KAAG,MAyBrD,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,MAI5C,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The values that identify the emulated estate, in one place.
|
|
3
|
+
*
|
|
4
|
+
* They live apart from the handlers because two handler modules need them: the
|
|
5
|
+
* folder family derives a folder id, the compute family derives a context and a
|
|
6
|
+
* server id, and a module that imports the other's handler map to reach them
|
|
7
|
+
* would be a cycle.
|
|
8
|
+
*/
|
|
9
|
+
/** The emulated clock: a fixed instant, so a body is reproducible. */
|
|
10
|
+
export const EMULATED_NOW = '2026-01-01T00:00:00.000Z';
|
|
11
|
+
/** The caller the emulated estate reports when a host does not name one. */
|
|
12
|
+
export const EMULATED_USER = { id: 'emulated-user', name: 'Emulated User' };
|
|
13
|
+
/**
|
|
14
|
+
* A uuid shape from a string, deterministically.
|
|
15
|
+
*
|
|
16
|
+
* Two 32-bit FNV-1a passes give enough of a hash to fill a uuid's fields, and the
|
|
17
|
+
* version/variant nibbles are set so the result is a well-formed v4-shaped id.
|
|
18
|
+
* Collisions are possible in principle and irrelevant here: the id is a handle
|
|
19
|
+
* the emulator hands back, not a uniqueness guarantee.
|
|
20
|
+
*/
|
|
21
|
+
export const idFor = (path, kind = 'folder') => {
|
|
22
|
+
const hash = (input, seed) => {
|
|
23
|
+
let value = seed;
|
|
24
|
+
for (let index = 0; index < input.length; index++) {
|
|
25
|
+
value ^= input.charCodeAt(index);
|
|
26
|
+
value = Math.imul(value, 16777619) >>> 0;
|
|
27
|
+
}
|
|
28
|
+
return value.toString(16).padStart(8, '0');
|
|
29
|
+
};
|
|
30
|
+
const raw = hash(`${kind}:${path}`, 2166136261) +
|
|
31
|
+
hash(`${kind}:${path}`, 2246822519) +
|
|
32
|
+
hash(`${kind}:${path}`, 3266489917) +
|
|
33
|
+
hash(`${kind}:${path}`, 668265263);
|
|
34
|
+
const hex = raw.slice(0, 32);
|
|
35
|
+
return [
|
|
36
|
+
hex.slice(0, 8),
|
|
37
|
+
hex.slice(8, 12),
|
|
38
|
+
`4${hex.slice(13, 16)}`,
|
|
39
|
+
`a${hex.slice(17, 20)}`,
|
|
40
|
+
hex.slice(20, 32)
|
|
41
|
+
].join('-');
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* One folder path, however it was spelled.
|
|
45
|
+
*
|
|
46
|
+
* The adapter joins a root of '/' to a path of '/app' and sends '//app', which is
|
|
47
|
+
* a different string and - because an id is derived from the path - a different
|
|
48
|
+
* id. A client that then asks for that id is asking about a folder the drive does
|
|
49
|
+
* not have, so every path is collapsed to one spelling before anything derives
|
|
50
|
+
* from it.
|
|
51
|
+
*/
|
|
52
|
+
export const normalisePath = (path) => {
|
|
53
|
+
const collapsed = `/${path}`.replace(/\/{2,}/g, '/');
|
|
54
|
+
return collapsed.length > 1 ? collapsed.replace(/\/+$/, '') : collapsed;
|
|
55
|
+
};
|
|
@@ -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;
|
|
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,15 +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 {
|
|
15
|
-
/**
|
|
16
|
-
* The reason the session and file families carry.
|
|
17
|
-
*
|
|
18
|
-
* They need the session port and the file content routes, which this slice does
|
|
19
|
-
* not mount. Saying it once is better than saying it thirteen times in slightly
|
|
20
|
-
* different words.
|
|
21
|
-
*/
|
|
22
|
-
const NEEDS_RUNTIME = 'The emulated estate answers folders, identities and types today. This operation needs the session or file port, which the host mounting the emulator has not supplied.';
|
|
14
|
+
import { VIYA_OPERATIONS } from './declared.js';
|
|
23
15
|
/**
|
|
24
16
|
* The token endpoint is the host's.
|
|
25
17
|
*
|
|
@@ -38,40 +30,25 @@ export const VIYA_OVERLAY = {
|
|
|
38
30
|
'GET /folders/folders/@myRecycleBin': { implemented: true },
|
|
39
31
|
'GET /identities/users/@currentUser': { implemented: true },
|
|
40
32
|
'GET /types/types': { implemented: true },
|
|
41
|
-
//
|
|
42
|
-
'GET /compute/contexts': { implemented:
|
|
43
|
-
'POST /compute/contexts/{}/sessions': {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
},
|
|
47
|
-
'
|
|
48
|
-
'
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
},
|
|
52
|
-
'GET /
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
},
|
|
56
|
-
'GET /compute/sessions/{}/jobs/{}/log/content': {
|
|
57
|
-
implemented: false,
|
|
58
|
-
reason: NEEDS_RUNTIME
|
|
59
|
-
},
|
|
60
|
-
'GET /compute/sessions/{}/jobs/{}/state': {
|
|
61
|
-
implemented: false,
|
|
62
|
-
reason: NEEDS_RUNTIME
|
|
63
|
-
},
|
|
64
|
-
'GET /compute/sessions/{}/state': {
|
|
65
|
-
implemented: false,
|
|
66
|
-
reason: NEEDS_RUNTIME
|
|
67
|
-
},
|
|
68
|
-
'POST /files/files': { implemented: false, reason: NEEDS_RUNTIME },
|
|
69
|
-
'GET /files/files/{}': { implemented: false, reason: NEEDS_RUNTIME },
|
|
70
|
-
'PATCH /files/files/{}': { implemented: false, reason: NEEDS_RUNTIME },
|
|
71
|
-
'GET /files/files/{}/content': { implemented: false, reason: NEEDS_RUNTIME },
|
|
72
|
-
'PUT /files/files/{}/content': { implemented: false, reason: NEEDS_RUNTIME },
|
|
33
|
+
// answered here: compute
|
|
34
|
+
'GET /compute/contexts': { implemented: true },
|
|
35
|
+
'POST /compute/contexts/{}/sessions': { implemented: true },
|
|
36
|
+
'DELETE /compute/sessions/{}': { implemented: true },
|
|
37
|
+
'POST /compute/sessions/{}/jobs': { implemented: true },
|
|
38
|
+
'GET /compute/sessions/{}/jobs/{}': { implemented: true },
|
|
39
|
+
'GET /compute/sessions/{}/jobs/{}/log/content': { implemented: true },
|
|
40
|
+
'GET /compute/sessions/{}/jobs/{}/state': { implemented: true },
|
|
41
|
+
'GET /compute/sessions/{}/state': { implemented: true },
|
|
42
|
+
// answered here: files
|
|
43
|
+
'POST /files/files': { implemented: true },
|
|
44
|
+
'GET /files/files/{}': { implemented: true },
|
|
45
|
+
'PATCH /files/files/{}': { implemented: true },
|
|
46
|
+
'GET /files/files/{}/content': { implemented: true },
|
|
47
|
+
'PUT /files/files/{}/content': { implemented: true },
|
|
73
48
|
// declined: the host owns the token port
|
|
74
|
-
'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 }
|
|
75
52
|
};
|
|
76
53
|
/**
|
|
77
54
|
* Refuse an overlay and a table that do not describe the same operations.
|
|
@@ -88,7 +65,7 @@ export const VIYA_OVERLAY = {
|
|
|
88
65
|
* Called at import, and exported so the refusals themselves can be tested: a
|
|
89
66
|
* check that only runs on import is a check nothing can pin.
|
|
90
67
|
*/
|
|
91
|
-
export const assertOverlayEntries = (overlay, operations =
|
|
68
|
+
export const assertOverlayEntries = (overlay, operations = VIYA_OPERATIONS) => {
|
|
92
69
|
const known = new Set(operations.map((operation) => operation.id));
|
|
93
70
|
for (const id of Object.keys(overlay))
|
|
94
71
|
if (!known.has(id))
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ports the emulated handlers read, in one place.
|
|
3
|
+
*
|
|
4
|
+
* `drive` is required on `Services`, so there is no absent case to answer: a host
|
|
5
|
+
* that mounts the emulator has one, and a `501` for a missing drive would be a
|
|
6
|
+
* branch nothing can reach. It lives here rather than in a handler module because
|
|
7
|
+
* two of them read it, and importing one handler map from the other is a cycle.
|
|
8
|
+
*/
|
|
9
|
+
import type { Services } from '../host/dispatch.js';
|
|
10
|
+
import type { DriveService } from '../drive/service.js';
|
|
11
|
+
export declare const requireDrive: (services: Services) => DriveService;
|
|
12
|
+
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../../src/viya/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAEvD,eAAO,MAAM,YAAY,GAAI,UAAU,QAAQ,KAAG,YAA8B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const requireDrive = (services) => services.drive;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the emulated estate derives its generated data from.
|
|
3
|
+
*
|
|
4
|
+
* The emulator cannot execute SAS, so any answer that a real engine would produce
|
|
5
|
+
* - a job log, a listing, a webout - is generated. Generated data is only useful
|
|
6
|
+
* if it is the same data twice: a screenshot taken after a build must still be
|
|
7
|
+
* true after the next one, and a fixture committed today must match the answer
|
|
8
|
+
* tomorrow.
|
|
9
|
+
*
|
|
10
|
+
* The seed is therefore the identity of the estate, and the identity of an estate
|
|
11
|
+
* is the address clients already use to reach it. A target that points at
|
|
12
|
+
* `http://localhost:5000` and a target that points at `http://127.0.0.1:5000` are
|
|
13
|
+
* the same estate spelled two ways, so the address is normalised before it is
|
|
14
|
+
* hashed - and `seed` exists for the two cases where the address is the wrong
|
|
15
|
+
* identity: the estate reached by a different hostname (a container name, a LAN
|
|
16
|
+
* address), and the port that moves between runs (CI picks an ephemeral one).
|
|
17
|
+
*
|
|
18
|
+
* Absent both, every emulated estate shares one seed. That is the only honest
|
|
19
|
+
* default: an emulator with no address has not told us which estate it is.
|
|
20
|
+
*/
|
|
21
|
+
/** The seed every emulated estate falls back to. */
|
|
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
|
+
}
|
|
58
|
+
export interface ViyaSeedSettings {
|
|
59
|
+
/** The address this estate answers at. */
|
|
60
|
+
serverUrl?: string;
|
|
61
|
+
/** Pins the generated data when the address is not the identity. */
|
|
62
|
+
seed?: string | number;
|
|
63
|
+
/** Runs a submitted program, when the host has an engine. */
|
|
64
|
+
execute?: ViyaExecutor['execute'];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The address reduced to what identifies it.
|
|
68
|
+
*
|
|
69
|
+
* Lowercased host, no default port, no trailing slash, no path: `https://Viya.Example.com:443/SASDrive/`
|
|
70
|
+
* and `https://viya.example.com` are one estate, and a path is where a client
|
|
71
|
+
* lands rather than which server it is. A non-default port stays, because two
|
|
72
|
+
* emulators on one machine are two estates.
|
|
73
|
+
*/
|
|
74
|
+
export declare const normaliseServerUrl: (url: string | undefined) => string;
|
|
75
|
+
/** A 32-bit FNV-1a hash, so one string becomes one number. */
|
|
76
|
+
export declare const hash: (input: string) => number;
|
|
77
|
+
/**
|
|
78
|
+
* The number that makes this estate's generated data reproducible.
|
|
79
|
+
*
|
|
80
|
+
* `seed` wins over the address when both are present: it is the override a host
|
|
81
|
+
* reaches for when the address disagrees with the estate, not a second opinion
|
|
82
|
+
* the address gets to overrule.
|
|
83
|
+
*/
|
|
84
|
+
export declare const seedOf: (settings?: ViyaSeedSettings) => number;
|
|
85
|
+
/**
|
|
86
|
+
* A uniform generator over one seed (mulberry32).
|
|
87
|
+
*
|
|
88
|
+
* Every draw advances the same 32-bit state, so a sequence is a function of the
|
|
89
|
+
* seed alone - which is the whole point: the same estate answers the same way,
|
|
90
|
+
* and two estates answer differently.
|
|
91
|
+
*/
|
|
92
|
+
export declare const generator: (seed: number) => (() => number);
|
|
93
|
+
/** An integer in `[0, bound)`, drawn from the generator. */
|
|
94
|
+
export declare const drawInt: (next: () => number, bound: number) => number;
|
|
95
|
+
/** A line from a list, drawn from the generator. */
|
|
96
|
+
export declare const drawFrom: <T>(next: () => number, values: T[]) => T;
|
|
97
|
+
//# sourceMappingURL=seed.d.ts.map
|
|
@@ -0,0 +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;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,OAAO,EAAE;QACf,2DAA2D;QAC3D,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;QAC1B,4DAA4D;QAC5D,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAClC,kEAAkE;QAClE,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,sCAAsC;QACtC,SAAS,EAAE,MAAM,CAAA;KAClB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACrB;AAED,8CAA8C;AAC9C,MAAM,WAAW,OAAO;IACtB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,gFAAgF;IAChF,GAAG,EAAE,MAAM,CAAA;IACX;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAA;CAC/B;AAED,MAAM,WAAW,gBAAgB;IAC/B,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,oEAAoE;IACpE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACtB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,YAAY,CAAC,SAAS,CAAC,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"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the emulated estate derives its generated data from.
|
|
3
|
+
*
|
|
4
|
+
* The emulator cannot execute SAS, so any answer that a real engine would produce
|
|
5
|
+
* - a job log, a listing, a webout - is generated. Generated data is only useful
|
|
6
|
+
* if it is the same data twice: a screenshot taken after a build must still be
|
|
7
|
+
* true after the next one, and a fixture committed today must match the answer
|
|
8
|
+
* tomorrow.
|
|
9
|
+
*
|
|
10
|
+
* The seed is therefore the identity of the estate, and the identity of an estate
|
|
11
|
+
* is the address clients already use to reach it. A target that points at
|
|
12
|
+
* `http://localhost:5000` and a target that points at `http://127.0.0.1:5000` are
|
|
13
|
+
* the same estate spelled two ways, so the address is normalised before it is
|
|
14
|
+
* hashed - and `seed` exists for the two cases where the address is the wrong
|
|
15
|
+
* identity: the estate reached by a different hostname (a container name, a LAN
|
|
16
|
+
* address), and the port that moves between runs (CI picks an ephemeral one).
|
|
17
|
+
*
|
|
18
|
+
* Absent both, every emulated estate shares one seed. That is the only honest
|
|
19
|
+
* default: an emulator with no address has not told us which estate it is.
|
|
20
|
+
*/
|
|
21
|
+
/** The seed every emulated estate falls back to. */
|
|
22
|
+
export const DEFAULT_SEED = 'emulated';
|
|
23
|
+
/**
|
|
24
|
+
* The address reduced to what identifies it.
|
|
25
|
+
*
|
|
26
|
+
* Lowercased host, no default port, no trailing slash, no path: `https://Viya.Example.com:443/SASDrive/`
|
|
27
|
+
* and `https://viya.example.com` are one estate, and a path is where a client
|
|
28
|
+
* lands rather than which server it is. A non-default port stays, because two
|
|
29
|
+
* emulators on one machine are two estates.
|
|
30
|
+
*/
|
|
31
|
+
export const normaliseServerUrl = (url) => {
|
|
32
|
+
if (!url)
|
|
33
|
+
return '';
|
|
34
|
+
const trimmed = url.trim();
|
|
35
|
+
if (!trimmed)
|
|
36
|
+
return '';
|
|
37
|
+
// parsed by hand rather than with `new URL`, because the browser build has no
|
|
38
|
+
// URL global and this module is part of it
|
|
39
|
+
const match = /^(?:([a-z][a-z0-9+.-]*):\/\/)?([^/?#]+)/i.exec(trimmed);
|
|
40
|
+
if (!match)
|
|
41
|
+
return trimmed.replace(/\/+$/, '').toLowerCase();
|
|
42
|
+
const scheme = (match[1] ?? 'http').toLowerCase();
|
|
43
|
+
let authority = match[2].toLowerCase();
|
|
44
|
+
const credentials = authority.lastIndexOf('@');
|
|
45
|
+
if (credentials >= 0)
|
|
46
|
+
authority = authority.slice(credentials + 1);
|
|
47
|
+
let host = authority;
|
|
48
|
+
let port = '';
|
|
49
|
+
if (authority.startsWith('[')) {
|
|
50
|
+
const close = authority.indexOf(']');
|
|
51
|
+
if (close >= 0) {
|
|
52
|
+
host = authority.slice(0, close + 1);
|
|
53
|
+
if (authority[close + 1] === ':')
|
|
54
|
+
port = authority.slice(close + 2);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const colon = authority.lastIndexOf(':');
|
|
59
|
+
if (colon >= 0) {
|
|
60
|
+
host = authority.slice(0, colon);
|
|
61
|
+
port = authority.slice(colon + 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const isDefault = (scheme === 'http' && port === '80') ||
|
|
65
|
+
(scheme === 'https' && port === '443');
|
|
66
|
+
// a non-default port stays: two emulators on one machine are two estates
|
|
67
|
+
return `${scheme}://${host}${port && !isDefault ? `:${port}` : ''}`;
|
|
68
|
+
};
|
|
69
|
+
/** A 32-bit FNV-1a hash, so one string becomes one number. */
|
|
70
|
+
export const hash = (input) => {
|
|
71
|
+
let value = 2166136261;
|
|
72
|
+
for (let index = 0; index < input.length; index++) {
|
|
73
|
+
value ^= input.charCodeAt(index);
|
|
74
|
+
value = Math.imul(value, 16777619) >>> 0;
|
|
75
|
+
}
|
|
76
|
+
return value >>> 0;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* The number that makes this estate's generated data reproducible.
|
|
80
|
+
*
|
|
81
|
+
* `seed` wins over the address when both are present: it is the override a host
|
|
82
|
+
* reaches for when the address disagrees with the estate, not a second opinion
|
|
83
|
+
* the address gets to overrule.
|
|
84
|
+
*/
|
|
85
|
+
export const seedOf = (settings = {}) => {
|
|
86
|
+
if (settings.seed !== undefined && settings.seed !== '')
|
|
87
|
+
return hash(`seed:${settings.seed}`);
|
|
88
|
+
const address = normaliseServerUrl(settings.serverUrl);
|
|
89
|
+
return hash(`url:${address || DEFAULT_SEED}`);
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* A uniform generator over one seed (mulberry32).
|
|
93
|
+
*
|
|
94
|
+
* Every draw advances the same 32-bit state, so a sequence is a function of the
|
|
95
|
+
* seed alone - which is the whole point: the same estate answers the same way,
|
|
96
|
+
* and two estates answer differently.
|
|
97
|
+
*/
|
|
98
|
+
export const generator = (seed) => {
|
|
99
|
+
let state = seed >>> 0;
|
|
100
|
+
return () => {
|
|
101
|
+
state = (state + 0x6d2b79f5) >>> 0;
|
|
102
|
+
let value = state;
|
|
103
|
+
value = Math.imul(value ^ (value >>> 15), value | 1);
|
|
104
|
+
value ^= value + Math.imul(value ^ (value >>> 7), value | 61);
|
|
105
|
+
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
/** An integer in `[0, bound)`, drawn from the generator. */
|
|
109
|
+
export const drawInt = (next, bound) => Math.floor(next() * bound);
|
|
110
|
+
/** A line from a list, drawn from the generator. */
|
|
111
|
+
export const drawFrom = (next, values) => values[drawInt(next, values.length)];
|
|
@@ -14,22 +14,6 @@
|
|
|
14
14
|
* and asks for it later.
|
|
15
15
|
*/
|
|
16
16
|
import type { ApiResponse, Services } from '../host/dispatch.js';
|
|
17
|
-
/** The emulated clock: a fixed instant, so a body is reproducible. */
|
|
18
|
-
export declare const EMULATED_NOW = "2026-01-01T00:00:00.000Z";
|
|
19
|
-
/** The caller the emulated estate reports when a host does not name one. */
|
|
20
|
-
export declare const EMULATED_USER: {
|
|
21
|
-
id: string;
|
|
22
|
-
name: string;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* A uuid shape from a string, deterministically.
|
|
26
|
-
*
|
|
27
|
-
* Two 32-bit FNV-1a passes give enough of a hash to fill a uuid's fields, and the
|
|
28
|
-
* version/variant nibbles are set so the result is a well-formed v4-shaped id.
|
|
29
|
-
* Collisions are possible in principle and irrelevant here: the id is a handle
|
|
30
|
-
* the emulator hands back, not a uniqueness guarantee.
|
|
31
|
-
*/
|
|
32
|
-
export declare const idFor: (path: string, kind?: string) => string;
|
|
33
17
|
/** The handlers, keyed by the operation id the table states. */
|
|
34
18
|
export declare const VIYA_HANDLERS: Record<string, (context: {
|
|
35
19
|
services: Services;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/viya/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/viya/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAmIhE,gEAAgE;AAChE,eAAO,MAAM,aAAa,EAAE,MAAM,CAChC,MAAM,EACN,CAAC,OAAO,EAAE;IACR,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,EAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;QAC1C,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,CAAA;IACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B,KAAK,OAAO,CAAC,WAAW,CAAC,CAgO3B,CAAA"}
|
|
@@ -1,38 +1,8 @@
|
|
|
1
1
|
import { ApiError } from '../types.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A uuid shape from a string, deterministically.
|
|
8
|
-
*
|
|
9
|
-
* Two 32-bit FNV-1a passes give enough of a hash to fill a uuid's fields, and the
|
|
10
|
-
* version/variant nibbles are set so the result is a well-formed v4-shaped id.
|
|
11
|
-
* Collisions are possible in principle and irrelevant here: the id is a handle
|
|
12
|
-
* the emulator hands back, not a uniqueness guarantee.
|
|
13
|
-
*/
|
|
14
|
-
export const idFor = (path, kind = 'folder') => {
|
|
15
|
-
const hash = (input, seed) => {
|
|
16
|
-
let value = seed;
|
|
17
|
-
for (let index = 0; index < input.length; index++) {
|
|
18
|
-
value ^= input.charCodeAt(index);
|
|
19
|
-
value = Math.imul(value, 16777619) >>> 0;
|
|
20
|
-
}
|
|
21
|
-
return value.toString(16).padStart(8, '0');
|
|
22
|
-
};
|
|
23
|
-
const raw = hash(`${kind}:${path}`, 2166136261) +
|
|
24
|
-
hash(`${kind}:${path}`, 2246822519) +
|
|
25
|
-
hash(`${kind}:${path}`, 3266489917) +
|
|
26
|
-
hash(`${kind}:${path}`, 668265263);
|
|
27
|
-
const hex = raw.slice(0, 32);
|
|
28
|
-
return [
|
|
29
|
-
hex.slice(0, 8),
|
|
30
|
-
hex.slice(8, 12),
|
|
31
|
-
`4${hex.slice(13, 16)}`,
|
|
32
|
-
`a${hex.slice(17, 20)}`,
|
|
33
|
-
hex.slice(20, 32)
|
|
34
|
-
].join('-');
|
|
35
|
-
};
|
|
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';
|
|
36
6
|
const linksFor = (uri, collection = false) => {
|
|
37
7
|
const self = {
|
|
38
8
|
href: uri,
|
|
@@ -92,16 +62,11 @@ const recycleBin = () => {
|
|
|
92
62
|
links: linksFor(`/folders/folders/${id}`)
|
|
93
63
|
};
|
|
94
64
|
};
|
|
95
|
-
const requireDrive = (services) => {
|
|
96
|
-
if (!services.drive)
|
|
97
|
-
throw new ApiError(501, 'This host has no drive, so it cannot answer a folder operation.');
|
|
98
|
-
return services.drive;
|
|
99
|
-
};
|
|
100
65
|
const pathFromQuery = (request) => {
|
|
101
66
|
const path = request.query?.path;
|
|
102
67
|
if (!path)
|
|
103
68
|
throw new ApiError(400, 'The path parameter is required.');
|
|
104
|
-
return path;
|
|
69
|
+
return normalisePath(path);
|
|
105
70
|
};
|
|
106
71
|
/** The recycle-bin alias the emulator answers, which is also a valid parent. */
|
|
107
72
|
const RECYCLE_BIN_ALIAS = '/folders/folders/@myRecycleBin';
|
|
@@ -273,7 +238,7 @@ export const VIYA_HANDLERS = {
|
|
|
273
238
|
const parent = parentUri
|
|
274
239
|
? await pathForId(drive, String(parentUri).split('/').pop())
|
|
275
240
|
: '/';
|
|
276
|
-
const path = `${parent}/${body.name}
|
|
241
|
+
const path = normalisePath(`${parent}/${body.name}`);
|
|
277
242
|
await drive.mkdir(path);
|
|
278
243
|
return { status: 201, body: await folderBody(drive, path) };
|
|
279
244
|
},
|
|
@@ -305,9 +270,11 @@ export const VIYA_HANDLERS = {
|
|
|
305
270
|
: body.parentFolderUri === ''
|
|
306
271
|
? '/'
|
|
307
272
|
: await pathForId(drive, body.parentFolderUri.split('/').pop());
|
|
308
|
-
const target = `${parent}/${name}
|
|
273
|
+
const target = normalisePath(`${parent}/${name}`);
|
|
309
274
|
if (target !== path)
|
|
310
275
|
await drive.rename(path, target);
|
|
311
276
|
return { status: 200, body: await folderBody(drive, target) };
|
|
312
|
-
}
|
|
277
|
+
},
|
|
278
|
+
...COMPUTE_HANDLERS,
|
|
279
|
+
...FILE_HANDLERS
|
|
313
280
|
};
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
/** 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';
|
|
18
|
+
creationTimeStamp: 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;
|
|
26
|
+
sessionId: string;
|
|
27
|
+
}
|
|
28
|
+
export interface EmulatedSession {
|
|
29
|
+
id: string;
|
|
30
|
+
/** When it was created, on the real clock: a client expires sessions by age. */
|
|
31
|
+
createdAt: string;
|
|
32
|
+
jobs: Map<string, EmulatedJob>;
|
|
33
|
+
/** How many jobs this session has accepted, so ids are stable per session. */
|
|
34
|
+
submitted: number;
|
|
35
|
+
}
|
|
36
|
+
/** What a submitted job answers before it is run - the same for every request. */
|
|
37
|
+
export interface SubmittedJob {
|
|
38
|
+
name?: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
/**
|
|
41
|
+
* The program.
|
|
42
|
+
*
|
|
43
|
+
* A string or a list of lines: `@sasjs/adapter` posts an array of lines, and
|
|
44
|
+
* the capture recorded a string because the recorder posted one. Both are the
|
|
45
|
+
* same program, so both are accepted.
|
|
46
|
+
*/
|
|
47
|
+
code?: string | string[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The generated log for one program.
|
|
51
|
+
*
|
|
52
|
+
* Deterministic in (seed, code): the same program on the same estate answers the
|
|
53
|
+
* same lines, so a test can assert a log and a screenshot stays true. The numbers
|
|
54
|
+
* are drawn rather than fixed so that two estates do not look identical, and the
|
|
55
|
+
* generator is re-seeded from the code for each job so that one job's log does not
|
|
56
|
+
* depend on how many jobs ran before it.
|
|
57
|
+
*/
|
|
58
|
+
export declare const logFor: (seed: number, program: string | string[]) => string[];
|
|
59
|
+
/**
|
|
60
|
+
* The sessions one estate holds.
|
|
61
|
+
*
|
|
62
|
+
* Keyed by seed, so two emulated estates in one process - a test that runs two
|
|
63
|
+
* targets - do not share a session namespace.
|
|
64
|
+
*/
|
|
65
|
+
export declare class EmulatedEstate {
|
|
66
|
+
private readonly seed;
|
|
67
|
+
private readonly sessions;
|
|
68
|
+
private created;
|
|
69
|
+
constructor(seed: number);
|
|
70
|
+
/** A new session: deterministic id, no jobs. */
|
|
71
|
+
create(): EmulatedSession;
|
|
72
|
+
session(id: string): EmulatedSession | undefined;
|
|
73
|
+
remove(id: string): boolean;
|
|
74
|
+
/** A job accepted into a session, with the log the emulator generated for it. */
|
|
75
|
+
submit(session: EmulatedSession, job: SubmittedJob): EmulatedJob;
|
|
76
|
+
}
|
|
77
|
+
export declare const estateFor: (seed: number) => EmulatedEstate;
|
|
78
|
+
//# 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,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;;;;OAOG;IACH,KAAK,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAA;IACzC,iBAAiB,EAAE,MAAM,CAAA;IACzB;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,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;CAwBjE;AAKD,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,cAUxC,CAAA"}
|