@sasjs/api 0.49.0 → 0.49.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/build/browser.js +69 -40
- package/build/cjs/appstream/identity.js +2 -31
- package/build/cjs/uuid.js +30 -0
- package/build/cjs/viya/compute.js +38 -20
- package/build/cjs/viya/dispatch.js +10 -0
- package/build/cjs/viya/seed.js +34 -8
- package/build/cjs/viya/sessions.js +24 -10
- package/build/esm/appstream/identity.d.ts +1 -9
- package/build/esm/appstream/identity.d.ts.map +1 -1
- package/build/esm/appstream/identity.js +1 -30
- package/build/esm/identity/types.d.ts +2 -0
- package/build/esm/identity/types.d.ts.map +1 -1
- package/build/esm/uuid.d.ts +6 -0
- package/build/esm/uuid.d.ts.map +1 -0
- package/build/esm/uuid.js +26 -0
- package/build/esm/viya/compute.d.ts.map +1 -1
- package/build/esm/viya/compute.js +39 -21
- package/build/esm/viya/dispatch.d.ts +3 -0
- package/build/esm/viya/dispatch.d.ts.map +1 -1
- package/build/esm/viya/dispatch.js +11 -1
- package/build/esm/viya/seed.d.ts +29 -7
- package/build/esm/viya/seed.d.ts.map +1 -1
- package/build/esm/viya/seed.js +32 -7
- package/build/esm/viya/sessions.d.ts +24 -6
- package/build/esm/viya/sessions.d.ts.map +1 -1
- package/build/esm/viya/sessions.js +24 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,10 @@ Where the document is wrong, it is corrected in `sasjs/server` and re-vendored h
|
|
|
26
26
|
`createAdminService` carries the three Admin reports over the host's `AdminReports`, owning the diagnostics shape, the log-name rule and the `lines` bounds; `createDirectoryService` imports a directory over a five-method `DirectoryStore`, creating what is missing and leaving what exists; `createHomeService` stamps the interface's shell with a token derived from its bundle, so a cached page cannot pin an old build.
|
|
27
27
|
They are `async`, take a `DriveStore`, and import nothing - so the same code runs under Express and inside a service worker.
|
|
28
28
|
|
|
29
|
+
**Viya compute ownership.** A multi-user host must authenticate its caller and pass the resolved `subject` to `dispatchViya` on every compute session request. Set `subject.ownerId` to the immutable account ID from the host's identity store, never from request data. `subject.userId` still controls the username on the wire. Hosts that omit `ownerId` use `userId` as before, in a separate namespace; switching an existing host to stable IDs requires recreating any live username-scoped sessions. Ownership spans client IDs, and another owner gets the same 404 as for a missing session. Ownerless records are refused. A token without a resolved subject is refused; no subject and no token selects a shared anonymous browser mock, not an authentication boundary. Session stores are keyed by the full normalised `serverUrl`, not the 32-bit seed.
|
|
30
|
+
|
|
31
|
+
New emulated session IDs are opaque UUID v4 strings (Web Crypto is required). Job IDs still derive from their session ID and therefore change with it; clients should use the returned IDs or links rather than parse their format. This does not change externally issued Viya IDs or the emulator's seeded folder IDs and generated logs.
|
|
32
|
+
|
|
29
33
|
**The app stream** (`createAppStreamService`, `createAppStreamWebService`, `splitAppBundle`) is what a deployed folder becomes when it is an app.
|
|
30
34
|
An app is one folder, the web assets inside it (`<appLoc>/services/<streamWebFolder>`) and a UUID assigned the first time it is published; the readable name is a label with no uniqueness rule, because nothing is looked up by name - the URL is `/app/<id>/`, so two apps may be called the same thing without colliding.
|
|
31
35
|
Publishing a folder that is already published is the same app published again: it keeps its id, which is what makes a redeploy keep its URL.
|
package/build/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @sasjs/api 0.49.
|
|
1
|
+
/* @sasjs/api 0.49.1 - 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;
|
|
@@ -128,7 +128,7 @@ var SASjsApi = (() => {
|
|
|
128
128
|
isRouteGranted: () => isRouteGranted,
|
|
129
129
|
logLines: () => logLines,
|
|
130
130
|
measureDeployTree: () => measureDeployTree,
|
|
131
|
-
newAppId: () =>
|
|
131
|
+
newAppId: () => newUuidV4,
|
|
132
132
|
normaliseAppLoc: () => normaliseAppLoc,
|
|
133
133
|
normaliseAuthConfig: () => normaliseAuthConfig,
|
|
134
134
|
normaliseDiagnostics: () => normaliseDiagnostics,
|
|
@@ -522,18 +522,8 @@ var SASjsApi = (() => {
|
|
|
522
522
|
};
|
|
523
523
|
};
|
|
524
524
|
|
|
525
|
-
// src/
|
|
526
|
-
var
|
|
527
|
-
if (typeof appLoc !== "string" || appLoc === "")
|
|
528
|
-
throw new Error(
|
|
529
|
-
`App location must be a non-empty string, got ${JSON.stringify(appLoc)}.`
|
|
530
|
-
);
|
|
531
|
-
const normalised = normaliseDrivePath(appLoc);
|
|
532
|
-
if (normalised === null)
|
|
533
|
-
throw new ApiError(400, "appLoc cannot be outside drive.");
|
|
534
|
-
return normalised;
|
|
535
|
-
};
|
|
536
|
-
var newAppId = () => {
|
|
525
|
+
// src/uuid.ts
|
|
526
|
+
var newUuidV4 = () => {
|
|
537
527
|
const webCrypto = globalThis.crypto;
|
|
538
528
|
if (typeof webCrypto?.randomUUID === "function") return webCrypto.randomUUID();
|
|
539
529
|
if (typeof webCrypto?.getRandomValues !== "function")
|
|
@@ -551,6 +541,18 @@ var SASjsApi = (() => {
|
|
|
551
541
|
hex.slice(20)
|
|
552
542
|
].join("-");
|
|
553
543
|
};
|
|
544
|
+
|
|
545
|
+
// src/appstream/identity.ts
|
|
546
|
+
var normaliseAppLoc = (appLoc) => {
|
|
547
|
+
if (typeof appLoc !== "string" || appLoc === "")
|
|
548
|
+
throw new Error(
|
|
549
|
+
`App location must be a non-empty string, got ${JSON.stringify(appLoc)}.`
|
|
550
|
+
);
|
|
551
|
+
const normalised = normaliseDrivePath(appLoc);
|
|
552
|
+
if (normalised === null)
|
|
553
|
+
throw new ApiError(400, "appLoc cannot be outside drive.");
|
|
554
|
+
return normalised;
|
|
555
|
+
};
|
|
554
556
|
var APP_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
555
557
|
var isAppId = (value) => typeof value === "string" && APP_ID.test(value);
|
|
556
558
|
|
|
@@ -750,7 +752,7 @@ var SASjsApi = (() => {
|
|
|
750
752
|
);
|
|
751
753
|
}
|
|
752
754
|
const entry = {
|
|
753
|
-
id: existing ? existing.id :
|
|
755
|
+
id: existing ? existing.id : newUuidV4(),
|
|
754
756
|
// the label is the one field a redeploy inherits: everything else is
|
|
755
757
|
// what this publish states
|
|
756
758
|
name,
|
|
@@ -5541,6 +5543,10 @@ var SASjsApi = (() => {
|
|
|
5541
5543
|
const address = normaliseServerUrl(settings.serverUrl);
|
|
5542
5544
|
return hash(`url:${address || DEFAULT_SEED}`);
|
|
5543
5545
|
};
|
|
5546
|
+
var estateKeyOf = (settings = {}) => {
|
|
5547
|
+
const address = normaliseServerUrl(settings.serverUrl);
|
|
5548
|
+
return address || DEFAULT_SEED;
|
|
5549
|
+
};
|
|
5544
5550
|
var generator = (seed) => {
|
|
5545
5551
|
let state = seed >>> 0;
|
|
5546
5552
|
return () => {
|
|
@@ -5576,12 +5582,14 @@ var SASjsApi = (() => {
|
|
|
5576
5582
|
constructor(seed) {
|
|
5577
5583
|
this.seed = seed;
|
|
5578
5584
|
this.sessions = /* @__PURE__ */ new Map();
|
|
5579
|
-
this.created = 0;
|
|
5580
5585
|
}
|
|
5581
|
-
/** A new session:
|
|
5582
|
-
create() {
|
|
5586
|
+
/** A new session: opaque UUID v4, no jobs. */
|
|
5587
|
+
create(owner) {
|
|
5588
|
+
const id = newUuidV4();
|
|
5589
|
+
if (this.sessions.has(id)) throw new Error("Duplicate compute session ID.");
|
|
5583
5590
|
const session = {
|
|
5584
|
-
id
|
|
5591
|
+
id,
|
|
5592
|
+
owner,
|
|
5585
5593
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5586
5594
|
jobs: /* @__PURE__ */ new Map(),
|
|
5587
5595
|
submitted: 0
|
|
@@ -5619,11 +5627,11 @@ var SASjsApi = (() => {
|
|
|
5619
5627
|
}
|
|
5620
5628
|
};
|
|
5621
5629
|
var estates = /* @__PURE__ */ new Map();
|
|
5622
|
-
var estateFor = (seed) => {
|
|
5623
|
-
const existing = estates.get(
|
|
5630
|
+
var estateFor = (key, seed) => {
|
|
5631
|
+
const existing = estates.get(key);
|
|
5624
5632
|
if (existing) return existing;
|
|
5625
5633
|
const estate = new EmulatedEstate(seed);
|
|
5626
|
-
estates.set(
|
|
5634
|
+
estates.set(key, estate);
|
|
5627
5635
|
return estate;
|
|
5628
5636
|
};
|
|
5629
5637
|
|
|
@@ -5683,7 +5691,7 @@ var SASjsApi = (() => {
|
|
|
5683
5691
|
...itemType ? { itemType: type } : {}
|
|
5684
5692
|
}
|
|
5685
5693
|
];
|
|
5686
|
-
var estateOf = (services) => estateFor(seedOf(services.viya));
|
|
5694
|
+
var estateOf = (services) => estateFor(estateKeyOf(services.viya), seedOf(services.viya));
|
|
5687
5695
|
var contextNameFrom = (filter) => {
|
|
5688
5696
|
if (!filter) return DEFAULT_CONTEXT_NAME;
|
|
5689
5697
|
const match = /name\s*,\s*'([^']*)'|name\s*,\s*"([^"]*)"/i.exec(filter);
|
|
@@ -5760,14 +5768,25 @@ var SASjsApi = (() => {
|
|
|
5760
5768
|
])
|
|
5761
5769
|
};
|
|
5762
5770
|
};
|
|
5763
|
-
var
|
|
5771
|
+
var ownerOf = (subject) => {
|
|
5772
|
+
if (subject === void 0) return { kind: "anonymous" };
|
|
5773
|
+
if (!subject || typeof subject.userId !== "string" || !subject.userId.trim())
|
|
5774
|
+
throw new ApiError(401, "A valid caller is required.");
|
|
5775
|
+
if (subject.ownerId === void 0)
|
|
5776
|
+
return { kind: "user", key: subject.userId };
|
|
5777
|
+
if (typeof subject.ownerId !== "string" || !subject.ownerId.trim())
|
|
5778
|
+
throw new ApiError(401, "A valid caller is required.");
|
|
5779
|
+
return { kind: "account", key: subject.ownerId };
|
|
5780
|
+
};
|
|
5781
|
+
var sessionOf = (services, id, subject) => {
|
|
5782
|
+
const owner = ownerOf(subject);
|
|
5764
5783
|
const session = estateOf(services).session(id);
|
|
5765
|
-
if (!session)
|
|
5784
|
+
if (!session || !session.owner || session.owner.kind !== owner.kind || session.owner.key !== owner.key)
|
|
5766
5785
|
throw new ApiError(404, `Session with ID '${id}' was not found.`);
|
|
5767
5786
|
return session;
|
|
5768
5787
|
};
|
|
5769
|
-
var jobOf = (services, sessionId, jobId) => {
|
|
5770
|
-
const job = sessionOf(services, sessionId).jobs.get(jobId);
|
|
5788
|
+
var jobOf = (services, sessionId, jobId, subject) => {
|
|
5789
|
+
const job = sessionOf(services, sessionId, subject).jobs.get(jobId);
|
|
5771
5790
|
if (!job) throw new ApiError(404, `Job with ID '${jobId}' was not found.`);
|
|
5772
5791
|
return job;
|
|
5773
5792
|
};
|
|
@@ -5806,7 +5825,7 @@ var SASjsApi = (() => {
|
|
|
5806
5825
|
if (params.id !== EMULATED_CONTEXT_ID)
|
|
5807
5826
|
throw new ApiError(404, `Context with ID '${params.id}' was not found.`);
|
|
5808
5827
|
const body = request.body ?? {};
|
|
5809
|
-
const session = estateOf(services).create();
|
|
5828
|
+
const session = estateOf(services).create(ownerOf(request.subject));
|
|
5810
5829
|
return {
|
|
5811
5830
|
status: 201,
|
|
5812
5831
|
body: sessionBody(
|
|
@@ -5817,17 +5836,17 @@ var SASjsApi = (() => {
|
|
|
5817
5836
|
)
|
|
5818
5837
|
};
|
|
5819
5838
|
},
|
|
5820
|
-
"GET /compute/sessions/{}/state": async ({ services, params }) => {
|
|
5821
|
-
sessionOf(services, params.id);
|
|
5839
|
+
"GET /compute/sessions/{}/state": async ({ services, params, request }) => {
|
|
5840
|
+
sessionOf(services, params.id, request.subject);
|
|
5822
5841
|
return { status: 200, body: "idle" };
|
|
5823
5842
|
},
|
|
5824
|
-
"DELETE /compute/sessions/{}": async ({ services, params }) => {
|
|
5825
|
-
sessionOf(services, params.id);
|
|
5843
|
+
"DELETE /compute/sessions/{}": async ({ services, params, request }) => {
|
|
5844
|
+
sessionOf(services, params.id, request.subject);
|
|
5826
5845
|
estateOf(services).remove(params.id);
|
|
5827
5846
|
return { status: 204, body: void 0 };
|
|
5828
5847
|
},
|
|
5829
5848
|
"POST /compute/sessions/{}/jobs": async ({ services, params, request }) => {
|
|
5830
|
-
const session = sessionOf(services, params.id);
|
|
5849
|
+
const session = sessionOf(services, params.id, request.subject);
|
|
5831
5850
|
const body = request.body ?? {};
|
|
5832
5851
|
const job = estateOf(services).submit(session, body);
|
|
5833
5852
|
const execute = services.viya?.execute;
|
|
@@ -5857,9 +5876,10 @@ var SASjsApi = (() => {
|
|
|
5857
5876
|
},
|
|
5858
5877
|
"GET /compute/sessions/{}/filerefs/_webout/content": async ({
|
|
5859
5878
|
services,
|
|
5860
|
-
params
|
|
5879
|
+
params,
|
|
5880
|
+
request
|
|
5861
5881
|
}) => {
|
|
5862
|
-
const session = sessionOf(services, params.id);
|
|
5882
|
+
const session = sessionOf(services, params.id, request.subject);
|
|
5863
5883
|
const last = [...session.jobs.values()].pop();
|
|
5864
5884
|
if (!last)
|
|
5865
5885
|
throw new ApiError(
|
|
@@ -5877,15 +5897,22 @@ var SASjsApi = (() => {
|
|
|
5877
5897
|
headers: { "content-type": "text/plain" }
|
|
5878
5898
|
};
|
|
5879
5899
|
},
|
|
5880
|
-
"GET /compute/sessions/{}/jobs/{}": async ({ services, params }) => {
|
|
5900
|
+
"GET /compute/sessions/{}/jobs/{}": async ({ services, params, request }) => {
|
|
5881
5901
|
const [sessionId, jobId] = segmentsOf(params);
|
|
5882
|
-
return {
|
|
5902
|
+
return {
|
|
5903
|
+
status: 200,
|
|
5904
|
+
body: jobBody(jobOf(services, sessionId, jobId, request.subject))
|
|
5905
|
+
};
|
|
5883
5906
|
},
|
|
5884
|
-
"GET /compute/sessions/{}/jobs/{}/state": async ({
|
|
5907
|
+
"GET /compute/sessions/{}/jobs/{}/state": async ({
|
|
5908
|
+
services,
|
|
5909
|
+
params,
|
|
5910
|
+
request
|
|
5911
|
+
}) => {
|
|
5885
5912
|
const [sessionId, jobId] = segmentsOf(params);
|
|
5886
5913
|
return {
|
|
5887
5914
|
status: 200,
|
|
5888
|
-
body: jobOf(services, sessionId, jobId).state
|
|
5915
|
+
body: jobOf(services, sessionId, jobId, request.subject).state
|
|
5889
5916
|
};
|
|
5890
5917
|
},
|
|
5891
5918
|
"GET /compute/sessions/{}/jobs/{}/log/content": async ({
|
|
@@ -5894,7 +5921,7 @@ var SASjsApi = (() => {
|
|
|
5894
5921
|
request
|
|
5895
5922
|
}) => {
|
|
5896
5923
|
const [sessionId, jobId] = segmentsOf(params);
|
|
5897
|
-
const job = jobOf(services, sessionId, jobId);
|
|
5924
|
+
const job = jobOf(services, sessionId, jobId, request.subject);
|
|
5898
5925
|
const start = Number(request.query?.start ?? 0) || 0;
|
|
5899
5926
|
const limit = Number(request.query?.limit ?? 0) || 0;
|
|
5900
5927
|
const lines = job.log.slice(start, limit ? start + limit : void 0);
|
|
@@ -6473,6 +6500,8 @@ var SASjsApi = (() => {
|
|
|
6473
6500
|
}
|
|
6474
6501
|
};
|
|
6475
6502
|
try {
|
|
6503
|
+
if (request.subject === void 0 && request.token !== void 0 && (found.operation.id === "POST /compute/contexts/{}/sessions" || found.operation.path.startsWith("/compute/sessions/")))
|
|
6504
|
+
throw new ApiError(401, "A valid caller is required.");
|
|
6476
6505
|
const answer = await handler({
|
|
6477
6506
|
services,
|
|
6478
6507
|
request,
|
|
@@ -30,37 +30,8 @@ const normaliseAppLoc = (appLoc) => {
|
|
|
30
30
|
return normalised;
|
|
31
31
|
};
|
|
32
32
|
exports.normaliseAppLoc = normaliseAppLoc;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*
|
|
36
|
-
* `crypto.randomUUID` exists in Node and in a browser worker on https or localhost,
|
|
37
|
-
* which is where the mock drive runs. The fallback builds the same thing from
|
|
38
|
-
* `getRandomValues` rather than from `Math.random`, so a weaker environment does not
|
|
39
|
-
* quietly produce a weaker id.
|
|
40
|
-
*/
|
|
41
|
-
const newAppId = () => {
|
|
42
|
-
const webCrypto = globalThis.crypto;
|
|
43
|
-
if (typeof webCrypto?.randomUUID === 'function')
|
|
44
|
-
return webCrypto.randomUUID();
|
|
45
|
-
if (typeof webCrypto?.getRandomValues !== 'function')
|
|
46
|
-
throw new Error('No cryptographic source of randomness is available.');
|
|
47
|
-
const bytes = new Uint8Array(16);
|
|
48
|
-
webCrypto.getRandomValues(bytes);
|
|
49
|
-
// version 4, variant 10xx
|
|
50
|
-
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
51
|
-
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
52
|
-
const hex = Array.from(bytes)
|
|
53
|
-
.map((byte) => byte.toString(16).padStart(2, '0'))
|
|
54
|
-
.join('');
|
|
55
|
-
return [
|
|
56
|
-
hex.slice(0, 8),
|
|
57
|
-
hex.slice(8, 12),
|
|
58
|
-
hex.slice(12, 16),
|
|
59
|
-
hex.slice(16, 20),
|
|
60
|
-
hex.slice(20)
|
|
61
|
-
].join('-');
|
|
62
|
-
};
|
|
63
|
-
exports.newAppId = newAppId;
|
|
33
|
+
var uuid_js_1 = require("../uuid.js");
|
|
34
|
+
Object.defineProperty(exports, "newAppId", { enumerable: true, get: function () { return uuid_js_1.newUuidV4; } });
|
|
64
35
|
// no `i` flag: `newAppId` mints lower case and every lookup compares exactly, so
|
|
65
36
|
// a guard that accepts upper case would vouch for an id no lookup can find
|
|
66
37
|
const APP_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.newUuidV4 = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A UUID v4 for Node and browser workers. Where `randomUUID` is unavailable,
|
|
6
|
+
* build it from `getRandomValues`; do not fall back to weaker randomness.
|
|
7
|
+
*/
|
|
8
|
+
const newUuidV4 = () => {
|
|
9
|
+
const webCrypto = globalThis.crypto;
|
|
10
|
+
if (typeof webCrypto?.randomUUID === 'function')
|
|
11
|
+
return webCrypto.randomUUID();
|
|
12
|
+
if (typeof webCrypto?.getRandomValues !== 'function')
|
|
13
|
+
throw new Error('No cryptographic source of randomness is available.');
|
|
14
|
+
const bytes = new Uint8Array(16);
|
|
15
|
+
webCrypto.getRandomValues(bytes);
|
|
16
|
+
// version 4, variant 10xx
|
|
17
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
18
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
19
|
+
const hex = Array.from(bytes)
|
|
20
|
+
.map((byte) => byte.toString(16).padStart(2, '0'))
|
|
21
|
+
.join('');
|
|
22
|
+
return [
|
|
23
|
+
hex.slice(0, 8),
|
|
24
|
+
hex.slice(8, 12),
|
|
25
|
+
hex.slice(12, 16),
|
|
26
|
+
hex.slice(16, 20),
|
|
27
|
+
hex.slice(20)
|
|
28
|
+
].join('-');
|
|
29
|
+
};
|
|
30
|
+
exports.newUuidV4 = newUuidV4;
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.COMPUTE_HANDLERS = exports.contextNameFrom = exports.EMULATED_CONTEXT_ID = exports.DEFAULT_CONTEXT_NAME = void 0;
|
|
4
4
|
const types_js_1 = require("../types.js");
|
|
5
5
|
const seed_js_1 = require("./seed.js");
|
|
6
|
-
const seed_js_2 = require("./seed.js");
|
|
7
6
|
const sessions_js_1 = require("./sessions.js");
|
|
8
7
|
const ids_js_1 = require("./ids.js");
|
|
9
8
|
/**
|
|
@@ -54,7 +53,7 @@ const linksFor = (uri, type, collection = false, itemType = false) => [
|
|
|
54
53
|
...(itemType ? { itemType: type } : {})
|
|
55
54
|
}
|
|
56
55
|
];
|
|
57
|
-
const estateOf = (services) => (0, sessions_js_1.estateFor)((0,
|
|
56
|
+
const estateOf = (services) => (0, sessions_js_1.estateFor)((0, seed_js_1.estateKeyOf)(services.viya), (0, seed_js_1.seedOf)(services.viya));
|
|
58
57
|
/**
|
|
59
58
|
* The context name a client asked for.
|
|
60
59
|
*
|
|
@@ -137,15 +136,31 @@ const jobBody = (job) => {
|
|
|
137
136
|
])
|
|
138
137
|
};
|
|
139
138
|
};
|
|
140
|
-
/** The
|
|
141
|
-
const
|
|
139
|
+
/** The browser mock has an anonymous principal distinct from every named user. */
|
|
140
|
+
const ownerOf = (subject) => {
|
|
141
|
+
if (subject === undefined)
|
|
142
|
+
return { kind: 'anonymous' };
|
|
143
|
+
if (!subject || typeof subject.userId !== 'string' || !subject.userId.trim())
|
|
144
|
+
throw new types_js_1.ApiError(401, 'A valid caller is required.');
|
|
145
|
+
if (subject.ownerId === undefined)
|
|
146
|
+
return { kind: 'user', key: subject.userId };
|
|
147
|
+
if (typeof subject.ownerId !== 'string' || !subject.ownerId.trim())
|
|
148
|
+
throw new types_js_1.ApiError(401, 'A valid caller is required.');
|
|
149
|
+
return { kind: 'account', key: subject.ownerId };
|
|
150
|
+
};
|
|
151
|
+
/** Ownerless records cannot be attributed and are deliberately inaccessible. */
|
|
152
|
+
const sessionOf = (services, id, subject) => {
|
|
153
|
+
const owner = ownerOf(subject);
|
|
142
154
|
const session = estateOf(services).session(id);
|
|
143
|
-
if (!session
|
|
155
|
+
if (!session ||
|
|
156
|
+
!session.owner ||
|
|
157
|
+
session.owner.kind !== owner.kind ||
|
|
158
|
+
session.owner.key !== owner.key)
|
|
144
159
|
throw new types_js_1.ApiError(404, `Session with ID '${id}' was not found.`);
|
|
145
160
|
return session;
|
|
146
161
|
};
|
|
147
|
-
const jobOf = (services, sessionId, jobId) => {
|
|
148
|
-
const job = sessionOf(services, sessionId).jobs.get(jobId);
|
|
162
|
+
const jobOf = (services, sessionId, jobId, subject) => {
|
|
163
|
+
const job = sessionOf(services, sessionId, subject).jobs.get(jobId);
|
|
149
164
|
if (!job)
|
|
150
165
|
throw new types_js_1.ApiError(404, `Job with ID '${jobId}' was not found.`);
|
|
151
166
|
return job;
|
|
@@ -180,25 +195,25 @@ exports.COMPUTE_HANDLERS = {
|
|
|
180
195
|
if (params.id !== exports.EMULATED_CONTEXT_ID)
|
|
181
196
|
throw new types_js_1.ApiError(404, `Context with ID '${params.id}' was not found.`);
|
|
182
197
|
const body = (request.body ?? {});
|
|
183
|
-
const session = estateOf(services).create();
|
|
198
|
+
const session = estateOf(services).create(ownerOf(request.subject));
|
|
184
199
|
return {
|
|
185
200
|
status: 201,
|
|
186
201
|
body: sessionBody(services, session, body.environment?.autoExecLines ?? [], (0, ids_js_1.callerId)(request.subject))
|
|
187
202
|
};
|
|
188
203
|
},
|
|
189
|
-
'GET /compute/sessions/{}/state': async ({ services, params }) => {
|
|
190
|
-
sessionOf(services, params.id);
|
|
204
|
+
'GET /compute/sessions/{}/state': async ({ services, params, request }) => {
|
|
205
|
+
sessionOf(services, params.id, request.subject);
|
|
191
206
|
// a bare enum, not an object: the adapter calls `.trim()` on the answer, and
|
|
192
207
|
// the capture recorded no shape here because there is no JSON body
|
|
193
208
|
return { status: 200, body: 'idle' };
|
|
194
209
|
},
|
|
195
|
-
'DELETE /compute/sessions/{}': async ({ services, params }) => {
|
|
196
|
-
sessionOf(services, params.id);
|
|
210
|
+
'DELETE /compute/sessions/{}': async ({ services, params, request }) => {
|
|
211
|
+
sessionOf(services, params.id, request.subject);
|
|
197
212
|
estateOf(services).remove(params.id);
|
|
198
213
|
return { status: 204, body: undefined };
|
|
199
214
|
},
|
|
200
215
|
'POST /compute/sessions/{}/jobs': async ({ services, params, request }) => {
|
|
201
|
-
const session = sessionOf(services, params.id);
|
|
216
|
+
const session = sessionOf(services, params.id, request.subject);
|
|
202
217
|
const body = (request.body ?? {});
|
|
203
218
|
const job = estateOf(services).submit(session, body);
|
|
204
219
|
const execute = services.viya?.execute;
|
|
@@ -237,8 +252,8 @@ exports.COMPUTE_HANDLERS = {
|
|
|
237
252
|
});
|
|
238
253
|
return { status: 201, body: jobBody(job) };
|
|
239
254
|
},
|
|
240
|
-
'GET /compute/sessions/{}/filerefs/_webout/content': async ({ services, params }) => {
|
|
241
|
-
const session = sessionOf(services, params.id);
|
|
255
|
+
'GET /compute/sessions/{}/filerefs/_webout/content': async ({ services, params, request }) => {
|
|
256
|
+
const session = sessionOf(services, params.id, request.subject);
|
|
242
257
|
const last = [...session.jobs.values()].pop();
|
|
243
258
|
if (!last)
|
|
244
259
|
throw new types_js_1.ApiError(404, 'This session has no `_webout` yet: nothing has run in it.');
|
|
@@ -257,20 +272,23 @@ exports.COMPUTE_HANDLERS = {
|
|
|
257
272
|
headers: { 'content-type': 'text/plain' }
|
|
258
273
|
};
|
|
259
274
|
},
|
|
260
|
-
'GET /compute/sessions/{}/jobs/{}': async ({ services, params }) => {
|
|
275
|
+
'GET /compute/sessions/{}/jobs/{}': async ({ services, params, request }) => {
|
|
261
276
|
const [sessionId, jobId] = segmentsOf(params);
|
|
262
|
-
return {
|
|
277
|
+
return {
|
|
278
|
+
status: 200,
|
|
279
|
+
body: jobBody(jobOf(services, sessionId, jobId, request.subject))
|
|
280
|
+
};
|
|
263
281
|
},
|
|
264
|
-
'GET /compute/sessions/{}/jobs/{}/state': async ({ services, params }) => {
|
|
282
|
+
'GET /compute/sessions/{}/jobs/{}/state': async ({ services, params, request }) => {
|
|
265
283
|
const [sessionId, jobId] = segmentsOf(params);
|
|
266
284
|
return {
|
|
267
285
|
status: 200,
|
|
268
|
-
body: jobOf(services, sessionId, jobId).state
|
|
286
|
+
body: jobOf(services, sessionId, jobId, request.subject).state
|
|
269
287
|
};
|
|
270
288
|
},
|
|
271
289
|
'GET /compute/sessions/{}/jobs/{}/log/content': async ({ services, params, request }) => {
|
|
272
290
|
const [sessionId, jobId] = segmentsOf(params);
|
|
273
|
-
const job = jobOf(services, sessionId, jobId);
|
|
291
|
+
const job = jobOf(services, sessionId, jobId, request.subject);
|
|
274
292
|
const start = Number(request.query?.start ?? 0) || 0;
|
|
275
293
|
const limit = Number(request.query?.limit ?? 0) || 0;
|
|
276
294
|
const lines = job.log.slice(start, limit ? start + limit : undefined);
|
|
@@ -56,6 +56,9 @@ exports.findViyaOperation = findViyaOperation;
|
|
|
56
56
|
*
|
|
57
57
|
* `request` is the same shape the SASjs dispatch takes, so a host that already
|
|
58
58
|
* resolves a caller - a session cookie - passes `subject` rather than a token.
|
|
59
|
+
* For compute sessions a host with credentials must pass the authenticated
|
|
60
|
+
* subject on every request: a token alone is refused. No subject and no token
|
|
61
|
+
* is the anonymous browser mock, not an authentication boundary.
|
|
59
62
|
*/
|
|
60
63
|
const dispatchViya = async (services, method, path, request = {}) => {
|
|
61
64
|
const headers = (0, version_js_1.emulatedHeaders)();
|
|
@@ -98,6 +101,13 @@ const dispatchViya = async (services, method, path, request = {}) => {
|
|
|
98
101
|
}
|
|
99
102
|
};
|
|
100
103
|
try {
|
|
104
|
+
// A host must resolve credentials before compute dispatch. A missing subject
|
|
105
|
+
// is the anonymous mock only when no credential was supplied.
|
|
106
|
+
if (request.subject === undefined &&
|
|
107
|
+
request.token !== undefined &&
|
|
108
|
+
(found.operation.id === 'POST /compute/contexts/{}/sessions' ||
|
|
109
|
+
found.operation.path.startsWith('/compute/sessions/')))
|
|
110
|
+
throw new types_js_1.ApiError(401, 'A valid caller is required.');
|
|
101
111
|
const answer = await handler({
|
|
102
112
|
services,
|
|
103
113
|
request,
|
package/build/cjs/viya/seed.js
CHANGED
|
@@ -8,18 +8,27 @@
|
|
|
8
8
|
* true after the next one, and a fixture committed today must match the answer
|
|
9
9
|
* tomorrow.
|
|
10
10
|
*
|
|
11
|
-
* The seed is therefore the
|
|
12
|
-
* is the address clients already use to reach it,
|
|
13
|
-
* spelled two ways is one string. There is no
|
|
14
|
-
* a different estate with different data,
|
|
15
|
-
* data - a fixture, a screenshot, a test -
|
|
16
|
-
* because the address is all the identity
|
|
11
|
+
* The seed is therefore what the estate's *generated data* draws from, and the
|
|
12
|
+
* identity of an estate is the address clients already use to reach it,
|
|
13
|
+
* normalised so that one estate spelled two ways is one string. There is no
|
|
14
|
+
* override: an address that differs is a different estate with different data,
|
|
15
|
+
* by design. Anything that reads this data - a fixture, a screenshot, a test -
|
|
16
|
+
* has to work whatever the address is, because the address is all the identity
|
|
17
|
+
* there is.
|
|
18
|
+
*
|
|
19
|
+
* The seed is a 32-bit digest of that address, which is wide enough to vary the
|
|
20
|
+
* generated numbers and narrow enough that two distinct addresses collide on it
|
|
21
|
+
* - by birthday, roughly one pair per few-billion addresses, and a search finds
|
|
22
|
+
* one in minutes. A collision makes two estates answer with the same numbers,
|
|
23
|
+
* which is cosmetic; anything that *stores* state per estate - the live session
|
|
24
|
+
* registry - must therefore key by the full address, never by the seed, and
|
|
25
|
+
* `estateKeyOf` is that key.
|
|
17
26
|
*
|
|
18
27
|
* An emulator with no address has not said which estate it is, so every such
|
|
19
28
|
* estate shares one seed. That is the only honest default.
|
|
20
29
|
*/
|
|
21
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.drawFrom = exports.drawInt = exports.generator = exports.seedOf = exports.hash = exports.normaliseServerUrl = exports.DEFAULT_SEED = void 0;
|
|
31
|
+
exports.drawFrom = exports.drawInt = exports.generator = exports.estateKeyOf = exports.seedOf = exports.hash = exports.normaliseServerUrl = exports.DEFAULT_SEED = void 0;
|
|
23
32
|
/** The seed every emulated estate falls back to. */
|
|
24
33
|
exports.DEFAULT_SEED = 'emulated';
|
|
25
34
|
/**
|
|
@@ -83,13 +92,30 @@ exports.hash = hash;
|
|
|
83
92
|
* The number that makes this estate's generated data reproducible.
|
|
84
93
|
*
|
|
85
94
|
* The address is the only input: the same estate answers the same way every time,
|
|
86
|
-
* and a different address is a different estate.
|
|
95
|
+
* and a different address is a different estate. A 32-bit digest, so it varies
|
|
96
|
+
* the numbers - it is not the estate's identity for anything that stores state
|
|
97
|
+
* (see `estateKeyOf`).
|
|
87
98
|
*/
|
|
88
99
|
const seedOf = (settings = {}) => {
|
|
89
100
|
const address = (0, exports.normaliseServerUrl)(settings.serverUrl);
|
|
90
101
|
return (0, exports.hash)(`url:${address || exports.DEFAULT_SEED}`);
|
|
91
102
|
};
|
|
92
103
|
exports.seedOf = seedOf;
|
|
104
|
+
/**
|
|
105
|
+
* The key a per-estate store is held under: the full normalised address.
|
|
106
|
+
*
|
|
107
|
+
* The seed is a 32-bit digest of this key, and two distinct addresses collide
|
|
108
|
+
* on it - a pair exists for any such digest, and a search finds one in
|
|
109
|
+
* minutes. A registry keyed by the seed would then hand two addresses one
|
|
110
|
+
* shared store, so state is keyed by the address itself: distinct addresses
|
|
111
|
+
* are distinct stores even when their seeds are one number, and two spellings
|
|
112
|
+
* of one address (which normalise to one string) remain one store.
|
|
113
|
+
*/
|
|
114
|
+
const estateKeyOf = (settings = {}) => {
|
|
115
|
+
const address = (0, exports.normaliseServerUrl)(settings.serverUrl);
|
|
116
|
+
return address || exports.DEFAULT_SEED;
|
|
117
|
+
};
|
|
118
|
+
exports.estateKeyOf = estateKeyOf;
|
|
93
119
|
/**
|
|
94
120
|
* A uniform generator over one seed (mulberry32).
|
|
95
121
|
*
|
|
@@ -16,6 +16,7 @@ exports.estateFor = exports.EmulatedEstate = exports.logFor = void 0;
|
|
|
16
16
|
* that parses for NOTEs still gets a well-formed log, and a person reading it is
|
|
17
17
|
* not misled about what ran.
|
|
18
18
|
*/
|
|
19
|
+
const uuid_js_1 = require("../uuid.js");
|
|
19
20
|
const seed_js_1 = require("./seed.js");
|
|
20
21
|
/**
|
|
21
22
|
* The generated log for one program.
|
|
@@ -52,19 +53,24 @@ exports.logFor = logFor;
|
|
|
52
53
|
/**
|
|
53
54
|
* The sessions one estate holds.
|
|
54
55
|
*
|
|
55
|
-
* Keyed by
|
|
56
|
-
*
|
|
56
|
+
* Keyed by the estate's key - the full normalised address, not the seed it
|
|
57
|
+
* digests to - so two emulated estates in one process (a test that runs two
|
|
58
|
+
* targets, or two addresses whose 32-bit seeds collide) do not share a session
|
|
59
|
+
* namespace. See `estateKeyOf`.
|
|
57
60
|
*/
|
|
58
61
|
class EmulatedEstate {
|
|
59
62
|
constructor(seed) {
|
|
60
63
|
this.seed = seed;
|
|
61
64
|
this.sessions = new Map();
|
|
62
|
-
this.created = 0;
|
|
63
65
|
}
|
|
64
|
-
/** A new session:
|
|
65
|
-
create() {
|
|
66
|
+
/** A new session: opaque UUID v4, no jobs. */
|
|
67
|
+
create(owner) {
|
|
68
|
+
const id = (0, uuid_js_1.newUuidV4)();
|
|
69
|
+
if (this.sessions.has(id))
|
|
70
|
+
throw new Error('Duplicate compute session ID.');
|
|
66
71
|
const session = {
|
|
67
|
-
id
|
|
72
|
+
id,
|
|
73
|
+
owner,
|
|
68
74
|
createdAt: new Date().toISOString(),
|
|
69
75
|
jobs: new Map(),
|
|
70
76
|
submitted: 0
|
|
@@ -102,14 +108,22 @@ class EmulatedEstate {
|
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
110
|
exports.EmulatedEstate = EmulatedEstate;
|
|
105
|
-
/** One estate per
|
|
111
|
+
/** One estate per address, for the life of the process. */
|
|
106
112
|
const estates = new Map();
|
|
107
|
-
|
|
108
|
-
|
|
113
|
+
/**
|
|
114
|
+
* The estate one address holds, minting it on first use.
|
|
115
|
+
*
|
|
116
|
+
* Keyed by the estate's key - the full normalised address - never by the seed:
|
|
117
|
+
* the seed is a 32-bit digest of the address, two distinct addresses collide on
|
|
118
|
+
* it, and a collision must not give them one shared session store. The estate
|
|
119
|
+
* still uses the seed for its generated logs.
|
|
120
|
+
*/
|
|
121
|
+
const estateFor = (key, seed) => {
|
|
122
|
+
const existing = estates.get(key);
|
|
109
123
|
if (existing)
|
|
110
124
|
return existing;
|
|
111
125
|
const estate = new EmulatedEstate(seed);
|
|
112
|
-
estates.set(
|
|
126
|
+
estates.set(key, estate);
|
|
113
127
|
return estate;
|
|
114
128
|
};
|
|
115
129
|
exports.estateFor = estateFor;
|
|
@@ -13,15 +13,7 @@
|
|
|
13
13
|
* is the key: what the registry, the routes and the permission rules point at.
|
|
14
14
|
*/
|
|
15
15
|
export declare const normaliseAppLoc: (appLoc: string) => string;
|
|
16
|
-
|
|
17
|
-
* A new id: a version 4 UUID.
|
|
18
|
-
*
|
|
19
|
-
* `crypto.randomUUID` exists in Node and in a browser worker on https or localhost,
|
|
20
|
-
* which is where the mock drive runs. The fallback builds the same thing from
|
|
21
|
-
* `getRandomValues` rather than from `Math.random`, so a weaker environment does not
|
|
22
|
-
* quietly produce a weaker id.
|
|
23
|
-
*/
|
|
24
|
-
export declare const newAppId: () => string;
|
|
16
|
+
export { newUuidV4 as newAppId } from '../uuid.js';
|
|
25
17
|
/** Whether a string is a well-formed id: a version 4 UUID. */
|
|
26
18
|
export declare const isAppId: (value: unknown) => value is string;
|
|
27
19
|
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../src/appstream/identity.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,KAAG,MAgBhD,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../src/appstream/identity.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,KAAG,MAgBhD,CAAA;AAED,OAAO,EAAE,SAAS,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAA;AAOlD,8DAA8D;AAC9D,eAAO,MAAM,OAAO,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MACD,CAAA"}
|
|
@@ -26,36 +26,7 @@ export const normaliseAppLoc = (appLoc) => {
|
|
|
26
26
|
throw new ApiError(400, 'appLoc cannot be outside drive.');
|
|
27
27
|
return normalised;
|
|
28
28
|
};
|
|
29
|
-
|
|
30
|
-
* A new id: a version 4 UUID.
|
|
31
|
-
*
|
|
32
|
-
* `crypto.randomUUID` exists in Node and in a browser worker on https or localhost,
|
|
33
|
-
* which is where the mock drive runs. The fallback builds the same thing from
|
|
34
|
-
* `getRandomValues` rather than from `Math.random`, so a weaker environment does not
|
|
35
|
-
* quietly produce a weaker id.
|
|
36
|
-
*/
|
|
37
|
-
export const newAppId = () => {
|
|
38
|
-
const webCrypto = globalThis.crypto;
|
|
39
|
-
if (typeof webCrypto?.randomUUID === 'function')
|
|
40
|
-
return webCrypto.randomUUID();
|
|
41
|
-
if (typeof webCrypto?.getRandomValues !== 'function')
|
|
42
|
-
throw new Error('No cryptographic source of randomness is available.');
|
|
43
|
-
const bytes = new Uint8Array(16);
|
|
44
|
-
webCrypto.getRandomValues(bytes);
|
|
45
|
-
// version 4, variant 10xx
|
|
46
|
-
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
47
|
-
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
48
|
-
const hex = Array.from(bytes)
|
|
49
|
-
.map((byte) => byte.toString(16).padStart(2, '0'))
|
|
50
|
-
.join('');
|
|
51
|
-
return [
|
|
52
|
-
hex.slice(0, 8),
|
|
53
|
-
hex.slice(8, 12),
|
|
54
|
-
hex.slice(12, 16),
|
|
55
|
-
hex.slice(16, 20),
|
|
56
|
-
hex.slice(20)
|
|
57
|
-
].join('-');
|
|
58
|
-
};
|
|
29
|
+
export { newUuidV4 as newAppId } from '../uuid.js';
|
|
59
30
|
// no `i` flag: `newAppId` mints lower case and every lookup compares exactly, so
|
|
60
31
|
// a guard that accepts upper case would vouch for an id no lookup can find
|
|
61
32
|
const APP_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/identity/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,iFAAiF;AACjF,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAA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E,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../src/uuid.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,SAAS,QAAO,MAkC5B,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A UUID v4 for Node and browser workers. Where `randomUUID` is unavailable,
|
|
3
|
+
* build it from `getRandomValues`; do not fall back to weaker randomness.
|
|
4
|
+
*/
|
|
5
|
+
export const newUuidV4 = () => {
|
|
6
|
+
const webCrypto = globalThis.crypto;
|
|
7
|
+
if (typeof webCrypto?.randomUUID === 'function')
|
|
8
|
+
return webCrypto.randomUUID();
|
|
9
|
+
if (typeof webCrypto?.getRandomValues !== 'function')
|
|
10
|
+
throw new Error('No cryptographic source of randomness is available.');
|
|
11
|
+
const bytes = new Uint8Array(16);
|
|
12
|
+
webCrypto.getRandomValues(bytes);
|
|
13
|
+
// version 4, variant 10xx
|
|
14
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
15
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
16
|
+
const hex = Array.from(bytes)
|
|
17
|
+
.map((byte) => byte.toString(16).padStart(2, '0'))
|
|
18
|
+
.join('');
|
|
19
|
+
return [
|
|
20
|
+
hex.slice(0, 8),
|
|
21
|
+
hex.slice(8, 12),
|
|
22
|
+
hex.slice(12, 16),
|
|
23
|
+
hex.slice(16, 20),
|
|
24
|
+
hex.slice(20)
|
|
25
|
+
].join('-');
|
|
26
|
+
};
|
|
@@ -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;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;
|
|
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;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAMnD;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,sCAAsC,CAAA;AAEvE,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,QAAuC,CAAA;AAgDvE;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,GAAG,SAAS,KAAG,MAM5D,CAAA;AAyID,eAAO,MAAM,gBAAgB,EAAE,MAAM,CACnC,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,CAiN3B,CAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ApiError } from '../types.js';
|
|
2
|
-
import { normaliseServerUrl } from './seed.js';
|
|
3
|
-
import { seedOf } from './seed.js';
|
|
2
|
+
import { estateKeyOf, normaliseServerUrl, seedOf } from './seed.js';
|
|
4
3
|
import { estateFor } from './sessions.js';
|
|
5
4
|
import { idFor, callerId } from './ids.js';
|
|
6
5
|
/**
|
|
@@ -51,7 +50,7 @@ const linksFor = (uri, type, collection = false, itemType = false) => [
|
|
|
51
50
|
...(itemType ? { itemType: type } : {})
|
|
52
51
|
}
|
|
53
52
|
];
|
|
54
|
-
const estateOf = (services) => estateFor(seedOf(services.viya));
|
|
53
|
+
const estateOf = (services) => estateFor(estateKeyOf(services.viya), seedOf(services.viya));
|
|
55
54
|
/**
|
|
56
55
|
* The context name a client asked for.
|
|
57
56
|
*
|
|
@@ -133,15 +132,31 @@ const jobBody = (job) => {
|
|
|
133
132
|
])
|
|
134
133
|
};
|
|
135
134
|
};
|
|
136
|
-
/** The
|
|
137
|
-
const
|
|
135
|
+
/** The browser mock has an anonymous principal distinct from every named user. */
|
|
136
|
+
const ownerOf = (subject) => {
|
|
137
|
+
if (subject === undefined)
|
|
138
|
+
return { kind: 'anonymous' };
|
|
139
|
+
if (!subject || typeof subject.userId !== 'string' || !subject.userId.trim())
|
|
140
|
+
throw new ApiError(401, 'A valid caller is required.');
|
|
141
|
+
if (subject.ownerId === undefined)
|
|
142
|
+
return { kind: 'user', key: subject.userId };
|
|
143
|
+
if (typeof subject.ownerId !== 'string' || !subject.ownerId.trim())
|
|
144
|
+
throw new ApiError(401, 'A valid caller is required.');
|
|
145
|
+
return { kind: 'account', key: subject.ownerId };
|
|
146
|
+
};
|
|
147
|
+
/** Ownerless records cannot be attributed and are deliberately inaccessible. */
|
|
148
|
+
const sessionOf = (services, id, subject) => {
|
|
149
|
+
const owner = ownerOf(subject);
|
|
138
150
|
const session = estateOf(services).session(id);
|
|
139
|
-
if (!session
|
|
151
|
+
if (!session ||
|
|
152
|
+
!session.owner ||
|
|
153
|
+
session.owner.kind !== owner.kind ||
|
|
154
|
+
session.owner.key !== owner.key)
|
|
140
155
|
throw new ApiError(404, `Session with ID '${id}' was not found.`);
|
|
141
156
|
return session;
|
|
142
157
|
};
|
|
143
|
-
const jobOf = (services, sessionId, jobId) => {
|
|
144
|
-
const job = sessionOf(services, sessionId).jobs.get(jobId);
|
|
158
|
+
const jobOf = (services, sessionId, jobId, subject) => {
|
|
159
|
+
const job = sessionOf(services, sessionId, subject).jobs.get(jobId);
|
|
145
160
|
if (!job)
|
|
146
161
|
throw new ApiError(404, `Job with ID '${jobId}' was not found.`);
|
|
147
162
|
return job;
|
|
@@ -176,25 +191,25 @@ export const COMPUTE_HANDLERS = {
|
|
|
176
191
|
if (params.id !== EMULATED_CONTEXT_ID)
|
|
177
192
|
throw new ApiError(404, `Context with ID '${params.id}' was not found.`);
|
|
178
193
|
const body = (request.body ?? {});
|
|
179
|
-
const session = estateOf(services).create();
|
|
194
|
+
const session = estateOf(services).create(ownerOf(request.subject));
|
|
180
195
|
return {
|
|
181
196
|
status: 201,
|
|
182
197
|
body: sessionBody(services, session, body.environment?.autoExecLines ?? [], callerId(request.subject))
|
|
183
198
|
};
|
|
184
199
|
},
|
|
185
|
-
'GET /compute/sessions/{}/state': async ({ services, params }) => {
|
|
186
|
-
sessionOf(services, params.id);
|
|
200
|
+
'GET /compute/sessions/{}/state': async ({ services, params, request }) => {
|
|
201
|
+
sessionOf(services, params.id, request.subject);
|
|
187
202
|
// a bare enum, not an object: the adapter calls `.trim()` on the answer, and
|
|
188
203
|
// the capture recorded no shape here because there is no JSON body
|
|
189
204
|
return { status: 200, body: 'idle' };
|
|
190
205
|
},
|
|
191
|
-
'DELETE /compute/sessions/{}': async ({ services, params }) => {
|
|
192
|
-
sessionOf(services, params.id);
|
|
206
|
+
'DELETE /compute/sessions/{}': async ({ services, params, request }) => {
|
|
207
|
+
sessionOf(services, params.id, request.subject);
|
|
193
208
|
estateOf(services).remove(params.id);
|
|
194
209
|
return { status: 204, body: undefined };
|
|
195
210
|
},
|
|
196
211
|
'POST /compute/sessions/{}/jobs': async ({ services, params, request }) => {
|
|
197
|
-
const session = sessionOf(services, params.id);
|
|
212
|
+
const session = sessionOf(services, params.id, request.subject);
|
|
198
213
|
const body = (request.body ?? {});
|
|
199
214
|
const job = estateOf(services).submit(session, body);
|
|
200
215
|
const execute = services.viya?.execute;
|
|
@@ -233,8 +248,8 @@ export const COMPUTE_HANDLERS = {
|
|
|
233
248
|
});
|
|
234
249
|
return { status: 201, body: jobBody(job) };
|
|
235
250
|
},
|
|
236
|
-
'GET /compute/sessions/{}/filerefs/_webout/content': async ({ services, params }) => {
|
|
237
|
-
const session = sessionOf(services, params.id);
|
|
251
|
+
'GET /compute/sessions/{}/filerefs/_webout/content': async ({ services, params, request }) => {
|
|
252
|
+
const session = sessionOf(services, params.id, request.subject);
|
|
238
253
|
const last = [...session.jobs.values()].pop();
|
|
239
254
|
if (!last)
|
|
240
255
|
throw new ApiError(404, 'This session has no `_webout` yet: nothing has run in it.');
|
|
@@ -253,20 +268,23 @@ export const COMPUTE_HANDLERS = {
|
|
|
253
268
|
headers: { 'content-type': 'text/plain' }
|
|
254
269
|
};
|
|
255
270
|
},
|
|
256
|
-
'GET /compute/sessions/{}/jobs/{}': async ({ services, params }) => {
|
|
271
|
+
'GET /compute/sessions/{}/jobs/{}': async ({ services, params, request }) => {
|
|
257
272
|
const [sessionId, jobId] = segmentsOf(params);
|
|
258
|
-
return {
|
|
273
|
+
return {
|
|
274
|
+
status: 200,
|
|
275
|
+
body: jobBody(jobOf(services, sessionId, jobId, request.subject))
|
|
276
|
+
};
|
|
259
277
|
},
|
|
260
|
-
'GET /compute/sessions/{}/jobs/{}/state': async ({ services, params }) => {
|
|
278
|
+
'GET /compute/sessions/{}/jobs/{}/state': async ({ services, params, request }) => {
|
|
261
279
|
const [sessionId, jobId] = segmentsOf(params);
|
|
262
280
|
return {
|
|
263
281
|
status: 200,
|
|
264
|
-
body: jobOf(services, sessionId, jobId).state
|
|
282
|
+
body: jobOf(services, sessionId, jobId, request.subject).state
|
|
265
283
|
};
|
|
266
284
|
},
|
|
267
285
|
'GET /compute/sessions/{}/jobs/{}/log/content': async ({ services, params, request }) => {
|
|
268
286
|
const [sessionId, jobId] = segmentsOf(params);
|
|
269
|
-
const job = jobOf(services, sessionId, jobId);
|
|
287
|
+
const job = jobOf(services, sessionId, jobId, request.subject);
|
|
270
288
|
const start = Number(request.query?.start ?? 0) || 0;
|
|
271
289
|
const limit = Number(request.query?.limit ?? 0) || 0;
|
|
272
290
|
const lines = job.log.slice(start, limit ? start + limit : undefined);
|
|
@@ -30,6 +30,9 @@ export declare const findViyaOperation: (method: string, path: string) => ViyaMa
|
|
|
30
30
|
*
|
|
31
31
|
* `request` is the same shape the SASjs dispatch takes, so a host that already
|
|
32
32
|
* resolves a caller - a session cookie - passes `subject` rather than a token.
|
|
33
|
+
* For compute sessions a host with credentials must pass the authenticated
|
|
34
|
+
* subject on every request: a token alone is refused. No subject and no token
|
|
35
|
+
* is the anonymous browser mock, not an authentication boundary.
|
|
33
36
|
*/
|
|
34
37
|
export declare const dispatchViya: (services: Services, method: string, path: string, request?: ApiRequest) => Promise<ViyaResponse>;
|
|
35
38
|
//# sourceMappingURL=dispatch.d.ts.map
|
|
@@ -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;AA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|
|
1
|
+
import { ApiError, isApiError } from '../types.js';
|
|
2
2
|
import { VIYA_OPERATIONS } from './declared.js';
|
|
3
3
|
import { VIYA_OVERLAY } from './overlay.js';
|
|
4
4
|
import { VIYA_HANDLERS } from './service.js';
|
|
@@ -52,6 +52,9 @@ export const findViyaOperation = (method, path) => {
|
|
|
52
52
|
*
|
|
53
53
|
* `request` is the same shape the SASjs dispatch takes, so a host that already
|
|
54
54
|
* resolves a caller - a session cookie - passes `subject` rather than a token.
|
|
55
|
+
* For compute sessions a host with credentials must pass the authenticated
|
|
56
|
+
* subject on every request: a token alone is refused. No subject and no token
|
|
57
|
+
* is the anonymous browser mock, not an authentication boundary.
|
|
55
58
|
*/
|
|
56
59
|
export const dispatchViya = async (services, method, path, request = {}) => {
|
|
57
60
|
const headers = emulatedHeaders();
|
|
@@ -94,6 +97,13 @@ export const dispatchViya = async (services, method, path, request = {}) => {
|
|
|
94
97
|
}
|
|
95
98
|
};
|
|
96
99
|
try {
|
|
100
|
+
// A host must resolve credentials before compute dispatch. A missing subject
|
|
101
|
+
// is the anonymous mock only when no credential was supplied.
|
|
102
|
+
if (request.subject === undefined &&
|
|
103
|
+
request.token !== undefined &&
|
|
104
|
+
(found.operation.id === 'POST /compute/contexts/{}/sessions' ||
|
|
105
|
+
found.operation.path.startsWith('/compute/sessions/')))
|
|
106
|
+
throw new ApiError(401, 'A valid caller is required.');
|
|
97
107
|
const answer = await handler({
|
|
98
108
|
services,
|
|
99
109
|
request,
|
package/build/esm/viya/seed.d.ts
CHANGED
|
@@ -7,12 +7,21 @@
|
|
|
7
7
|
* true after the next one, and a fixture committed today must match the answer
|
|
8
8
|
* tomorrow.
|
|
9
9
|
*
|
|
10
|
-
* The seed is therefore the
|
|
11
|
-
* is the address clients already use to reach it,
|
|
12
|
-
* spelled two ways is one string. There is no
|
|
13
|
-
* a different estate with different data,
|
|
14
|
-
* data - a fixture, a screenshot, a test -
|
|
15
|
-
* because the address is all the identity
|
|
10
|
+
* The seed is therefore what the estate's *generated data* draws from, and the
|
|
11
|
+
* identity of an estate is the address clients already use to reach it,
|
|
12
|
+
* normalised so that one estate spelled two ways is one string. There is no
|
|
13
|
+
* override: an address that differs is a different estate with different data,
|
|
14
|
+
* by design. Anything that reads this data - a fixture, a screenshot, a test -
|
|
15
|
+
* has to work whatever the address is, because the address is all the identity
|
|
16
|
+
* there is.
|
|
17
|
+
*
|
|
18
|
+
* The seed is a 32-bit digest of that address, which is wide enough to vary the
|
|
19
|
+
* generated numbers and narrow enough that two distinct addresses collide on it
|
|
20
|
+
* - by birthday, roughly one pair per few-billion addresses, and a search finds
|
|
21
|
+
* one in minutes. A collision makes two estates answer with the same numbers,
|
|
22
|
+
* which is cosmetic; anything that *stores* state per estate - the live session
|
|
23
|
+
* registry - must therefore key by the full address, never by the seed, and
|
|
24
|
+
* `estateKeyOf` is that key.
|
|
16
25
|
*
|
|
17
26
|
* An emulator with no address has not said which estate it is, so every such
|
|
18
27
|
* estate shares one seed. That is the only honest default.
|
|
@@ -75,9 +84,22 @@ export declare const hash: (input: string) => number;
|
|
|
75
84
|
* The number that makes this estate's generated data reproducible.
|
|
76
85
|
*
|
|
77
86
|
* The address is the only input: the same estate answers the same way every time,
|
|
78
|
-
* and a different address is a different estate.
|
|
87
|
+
* and a different address is a different estate. A 32-bit digest, so it varies
|
|
88
|
+
* the numbers - it is not the estate's identity for anything that stores state
|
|
89
|
+
* (see `estateKeyOf`).
|
|
79
90
|
*/
|
|
80
91
|
export declare const seedOf: (settings?: ViyaSeedSettings) => number;
|
|
92
|
+
/**
|
|
93
|
+
* The key a per-estate store is held under: the full normalised address.
|
|
94
|
+
*
|
|
95
|
+
* The seed is a 32-bit digest of this key, and two distinct addresses collide
|
|
96
|
+
* on it - a pair exists for any such digest, and a search finds one in
|
|
97
|
+
* minutes. A registry keyed by the seed would then hand two addresses one
|
|
98
|
+
* shared store, so state is keyed by the address itself: distinct addresses
|
|
99
|
+
* are distinct stores even when their seeds are one number, and two spellings
|
|
100
|
+
* of one address (which normalise to one string) remain one store.
|
|
101
|
+
*/
|
|
102
|
+
export declare const estateKeyOf: (settings?: ViyaSeedSettings) => string;
|
|
81
103
|
/**
|
|
82
104
|
* A uniform generator over one seed (mulberry32).
|
|
83
105
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../../src/viya/seed.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../../src/viya/seed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;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,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,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;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,GAAI,WAAU,gBAAqB,KAAG,MAIxD,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,GAAI,WAAU,gBAAqB,KAAG,MAI7D,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"}
|
package/build/esm/viya/seed.js
CHANGED
|
@@ -7,12 +7,21 @@
|
|
|
7
7
|
* true after the next one, and a fixture committed today must match the answer
|
|
8
8
|
* tomorrow.
|
|
9
9
|
*
|
|
10
|
-
* The seed is therefore the
|
|
11
|
-
* is the address clients already use to reach it,
|
|
12
|
-
* spelled two ways is one string. There is no
|
|
13
|
-
* a different estate with different data,
|
|
14
|
-
* data - a fixture, a screenshot, a test -
|
|
15
|
-
* because the address is all the identity
|
|
10
|
+
* The seed is therefore what the estate's *generated data* draws from, and the
|
|
11
|
+
* identity of an estate is the address clients already use to reach it,
|
|
12
|
+
* normalised so that one estate spelled two ways is one string. There is no
|
|
13
|
+
* override: an address that differs is a different estate with different data,
|
|
14
|
+
* by design. Anything that reads this data - a fixture, a screenshot, a test -
|
|
15
|
+
* has to work whatever the address is, because the address is all the identity
|
|
16
|
+
* there is.
|
|
17
|
+
*
|
|
18
|
+
* The seed is a 32-bit digest of that address, which is wide enough to vary the
|
|
19
|
+
* generated numbers and narrow enough that two distinct addresses collide on it
|
|
20
|
+
* - by birthday, roughly one pair per few-billion addresses, and a search finds
|
|
21
|
+
* one in minutes. A collision makes two estates answer with the same numbers,
|
|
22
|
+
* which is cosmetic; anything that *stores* state per estate - the live session
|
|
23
|
+
* registry - must therefore key by the full address, never by the seed, and
|
|
24
|
+
* `estateKeyOf` is that key.
|
|
16
25
|
*
|
|
17
26
|
* An emulator with no address has not said which estate it is, so every such
|
|
18
27
|
* estate shares one seed. That is the only honest default.
|
|
@@ -78,12 +87,28 @@ export const hash = (input) => {
|
|
|
78
87
|
* The number that makes this estate's generated data reproducible.
|
|
79
88
|
*
|
|
80
89
|
* The address is the only input: the same estate answers the same way every time,
|
|
81
|
-
* and a different address is a different estate.
|
|
90
|
+
* and a different address is a different estate. A 32-bit digest, so it varies
|
|
91
|
+
* the numbers - it is not the estate's identity for anything that stores state
|
|
92
|
+
* (see `estateKeyOf`).
|
|
82
93
|
*/
|
|
83
94
|
export const seedOf = (settings = {}) => {
|
|
84
95
|
const address = normaliseServerUrl(settings.serverUrl);
|
|
85
96
|
return hash(`url:${address || DEFAULT_SEED}`);
|
|
86
97
|
};
|
|
98
|
+
/**
|
|
99
|
+
* The key a per-estate store is held under: the full normalised address.
|
|
100
|
+
*
|
|
101
|
+
* The seed is a 32-bit digest of this key, and two distinct addresses collide
|
|
102
|
+
* on it - a pair exists for any such digest, and a search finds one in
|
|
103
|
+
* minutes. A registry keyed by the seed would then hand two addresses one
|
|
104
|
+
* shared store, so state is keyed by the address itself: distinct addresses
|
|
105
|
+
* are distinct stores even when their seeds are one number, and two spellings
|
|
106
|
+
* of one address (which normalise to one string) remain one store.
|
|
107
|
+
*/
|
|
108
|
+
export const estateKeyOf = (settings = {}) => {
|
|
109
|
+
const address = normaliseServerUrl(settings.serverUrl);
|
|
110
|
+
return address || DEFAULT_SEED;
|
|
111
|
+
};
|
|
87
112
|
/**
|
|
88
113
|
* A uniform generator over one seed (mulberry32).
|
|
89
114
|
*
|
|
@@ -25,8 +25,17 @@ export interface EmulatedJob {
|
|
|
25
25
|
completedTimeStamp?: string;
|
|
26
26
|
sessionId: string;
|
|
27
27
|
}
|
|
28
|
+
export type SessionOwner = {
|
|
29
|
+
kind: 'account' | 'user';
|
|
30
|
+
key: string;
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'anonymous';
|
|
33
|
+
key?: never;
|
|
34
|
+
};
|
|
28
35
|
export interface EmulatedSession {
|
|
29
36
|
id: string;
|
|
37
|
+
/** Internal authorization principal, not a wire field. */
|
|
38
|
+
owner: SessionOwner;
|
|
30
39
|
/** When it was created, on the real clock: a client expires sessions by age. */
|
|
31
40
|
createdAt: string;
|
|
32
41
|
jobs: Map<string, EmulatedJob>;
|
|
@@ -59,20 +68,29 @@ export declare const logFor: (seed: number, program: string | string[]) => strin
|
|
|
59
68
|
/**
|
|
60
69
|
* The sessions one estate holds.
|
|
61
70
|
*
|
|
62
|
-
* Keyed by
|
|
63
|
-
*
|
|
71
|
+
* Keyed by the estate's key - the full normalised address, not the seed it
|
|
72
|
+
* digests to - so two emulated estates in one process (a test that runs two
|
|
73
|
+
* targets, or two addresses whose 32-bit seeds collide) do not share a session
|
|
74
|
+
* namespace. See `estateKeyOf`.
|
|
64
75
|
*/
|
|
65
76
|
export declare class EmulatedEstate {
|
|
66
77
|
private readonly seed;
|
|
67
78
|
private readonly sessions;
|
|
68
|
-
private created;
|
|
69
79
|
constructor(seed: number);
|
|
70
|
-
/** A new session:
|
|
71
|
-
create(): EmulatedSession;
|
|
80
|
+
/** A new session: opaque UUID v4, no jobs. */
|
|
81
|
+
create(owner: SessionOwner): EmulatedSession;
|
|
72
82
|
session(id: string): EmulatedSession | undefined;
|
|
73
83
|
remove(id: string): boolean;
|
|
74
84
|
/** A job accepted into a session, with the log the emulator generated for it. */
|
|
75
85
|
submit(session: EmulatedSession, job: SubmittedJob): EmulatedJob;
|
|
76
86
|
}
|
|
77
|
-
|
|
87
|
+
/**
|
|
88
|
+
* The estate one address holds, minting it on first use.
|
|
89
|
+
*
|
|
90
|
+
* Keyed by the estate's key - the full normalised address - never by the seed:
|
|
91
|
+
* the seed is a 32-bit digest of the address, two distinct addresses collide on
|
|
92
|
+
* it, and a collision must not give them one shared session store. The estate
|
|
93
|
+
* still uses the seed for its generated logs.
|
|
94
|
+
*/
|
|
95
|
+
export declare const estateFor: (key: string, seed: number) => EmulatedEstate;
|
|
78
96
|
//# sourceMappingURL=sessions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../../../src/viya/sessions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../../../src/viya/sessions.ts"],"names":[],"mappings":"AAkBA,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,MAAM,YAAY,GACtB;IAAE,IAAI,EAAE,SAAS,GAAG,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,GAAG,CAAC,EAAE,KAAK,CAAA;CAAE,CAAA;AAEhF,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,0DAA0D;IAC1D,KAAK,EAAE,YAAY,CAAA;IACnB,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;;;;;;;GAOG;AACH,qBAAa,cAAc;IAGb,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqC;gBAEjC,IAAI,EAAE,MAAM;IAEzC,8CAA8C;IAC9C,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,eAAe;IAiB5C,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;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,KAAG,cAUrD,CAAA"}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* that parses for NOTEs still gets a well-formed log, and a person reading it is
|
|
14
14
|
* not misled about what ran.
|
|
15
15
|
*/
|
|
16
|
+
import { newUuidV4 } from '../uuid.js';
|
|
16
17
|
import { drawFrom, drawInt, generator, hash } from './seed.js';
|
|
17
18
|
/**
|
|
18
19
|
* The generated log for one program.
|
|
@@ -48,19 +49,24 @@ export const logFor = (seed, program) => {
|
|
|
48
49
|
/**
|
|
49
50
|
* The sessions one estate holds.
|
|
50
51
|
*
|
|
51
|
-
* Keyed by
|
|
52
|
-
*
|
|
52
|
+
* Keyed by the estate's key - the full normalised address, not the seed it
|
|
53
|
+
* digests to - so two emulated estates in one process (a test that runs two
|
|
54
|
+
* targets, or two addresses whose 32-bit seeds collide) do not share a session
|
|
55
|
+
* namespace. See `estateKeyOf`.
|
|
53
56
|
*/
|
|
54
57
|
export class EmulatedEstate {
|
|
55
58
|
constructor(seed) {
|
|
56
59
|
this.seed = seed;
|
|
57
60
|
this.sessions = new Map();
|
|
58
|
-
this.created = 0;
|
|
59
61
|
}
|
|
60
|
-
/** A new session:
|
|
61
|
-
create() {
|
|
62
|
+
/** A new session: opaque UUID v4, no jobs. */
|
|
63
|
+
create(owner) {
|
|
64
|
+
const id = newUuidV4();
|
|
65
|
+
if (this.sessions.has(id))
|
|
66
|
+
throw new Error('Duplicate compute session ID.');
|
|
62
67
|
const session = {
|
|
63
|
-
id
|
|
68
|
+
id,
|
|
69
|
+
owner,
|
|
64
70
|
createdAt: new Date().toISOString(),
|
|
65
71
|
jobs: new Map(),
|
|
66
72
|
submitted: 0
|
|
@@ -97,13 +103,21 @@ export class EmulatedEstate {
|
|
|
97
103
|
return submitted;
|
|
98
104
|
}
|
|
99
105
|
}
|
|
100
|
-
/** One estate per
|
|
106
|
+
/** One estate per address, for the life of the process. */
|
|
101
107
|
const estates = new Map();
|
|
102
|
-
|
|
103
|
-
|
|
108
|
+
/**
|
|
109
|
+
* The estate one address holds, minting it on first use.
|
|
110
|
+
*
|
|
111
|
+
* Keyed by the estate's key - the full normalised address - never by the seed:
|
|
112
|
+
* the seed is a 32-bit digest of the address, two distinct addresses collide on
|
|
113
|
+
* it, and a collision must not give them one shared session store. The estate
|
|
114
|
+
* still uses the seed for its generated logs.
|
|
115
|
+
*/
|
|
116
|
+
export const estateFor = (key, seed) => {
|
|
117
|
+
const existing = estates.get(key);
|
|
104
118
|
if (existing)
|
|
105
119
|
return existing;
|
|
106
120
|
const estate = new EmulatedEstate(seed);
|
|
107
|
-
estates.set(
|
|
121
|
+
estates.set(key, estate);
|
|
108
122
|
return estate;
|
|
109
123
|
};
|
package/package.json
CHANGED