@sasjs/api 0.51.1 → 0.52.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/README.md +4 -0
- package/build/browser.js +188 -48
- package/build/cjs/viya/job-definitions.js +126 -0
- package/build/cjs/viya/overlay.js +5 -22
- package/build/cjs/viya/service.js +59 -14
- package/build/esm/viya/job-definitions.d.ts +43 -0
- package/build/esm/viya/job-definitions.d.ts.map +1 -0
- package/build/esm/viya/job-definitions.js +121 -0
- package/build/esm/viya/overlay.d.ts.map +1 -1
- package/build/esm/viya/overlay.js +5 -22
- package/build/esm/viya/seed.d.ts +14 -0
- package/build/esm/viya/seed.d.ts.map +1 -1
- package/build/esm/viya/service.d.ts.map +1 -1
- package/build/esm/viya/service.js +59 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,6 +33,10 @@ Both lists are held against their inventory in both directions by `spec/viyaAppS
|
|
|
33
33
|
`check:app-scope` is not a CI step: it needs a checkout of the application, so it runs where that checkout exists and states so when it is not given one.
|
|
34
34
|
The operations an application's calls add are declared rather than captured (`src/viya/declared.ts`), since no recording pass driven by the adapter can observe them.
|
|
35
35
|
|
|
36
|
+
**Viya job definitions.** Create and read store inert JSON records in the parent Drive folder and expose a `getResource` member link. A host that persists Drive data can reconstruct the definitions; IDs are newly minted UUIDs and follow a parent folder move. These records are ordinary Drive files, subject to the host's existing Drive permissions and modification/removal. Creation fails with 501 by default: the Drive operations are not transactional. For an isolated mock only, a trusted host can set `services.viya.allowUntransactionalJobDefinitionCreation: true` in host configuration, never from HTTP input. The host must guarantee that no Drive mutations overlap any definition create, across all processes and all users of the underlying store (including other definition creates, folder moves and deletes). This opt-in does not enforce exclusivity or resolve the races; do not enable it in shared or parallel environments. Robust concurrency requires transactional mutation support. Existing definitions remain readable with creation disabled. This slice does not execute jobs or implement update, delete, overwrite or duplicate-name concurrency guarantees; it does not claim Viya parity for those behaviours. Existing folder IDs remain path-derived. Do not treat definition data as executable code.
|
|
37
|
+
|
|
38
|
+
**Viya folder-member authorization.** On each member request, a trusted host must set `services.viya.readJobDefinitionMetadata` to `false` unless it has independently authorized this caller to read definition files; never derive this capability from the query or body. When false, member discovery does not read file contents and hides every reserved `.sasjs-viya-job-<UUID-v4>.json` filename, including malformed records. Other files and folders remain visible. When true or omitted, historical discovery reads and exposes valid definitions, and malformed records remain ordinary files. Omission is for trusted existing/browser hosts only: multi-user hosts must set the flag per request. This flag only controls folder-member discovery, not direct definition or Drive endpoints; the host must authorize those independently. Folder ID lookup walks Drive folder listings, exposing the same recursive names available under the native folder-list grant, without file content reads or per-file stats.
|
|
39
|
+
|
|
36
40
|
**Viya job log collection.** The CLI follows a job's `log` link and pages the returned line objects. The emulator supports non-negative decimal `start` and `limit` (default 0 and 10; maximum limit 2147483647, maximum start JavaScript's safe integer), with `count` equal to the total stored lines. Malformed or repeated values are refused with 400; `type` filtering and `timeout` are not implemented and are refused. Every stored string is labelled `NOTE`, without classifying its content; `/log/content` retains its existing behavior. Defaults, validation, link details and line types are mock choices, not verified Viya behavior. A successful collection read is not evidence of SAS execution; its lines come from the configured host or the mock generator.
|
|
37
41
|
|
|
38
42
|
**Viya mock SYSJOBID.** By default every session-variable lookup retains the 501 refusal. A trusted host may set `services.viya.mockSysjobid: true` in host configuration, never from HTTP data, to enable only the exact case-sensitive name `SYSJOBID` after normal subject, estate and session ownership checks. The value is `mock-<session UUID>`, stable only for that mock session and unmistakably synthetic: it is not a process ID, a SAS value or evidence of execution. The adapter's `printPid` nevertheless labels it `PID`; do not interpret it as a real one. Unknown variables remain 501 for an authorized live session; foreign, missing, deleted or ownerless sessions return 404, and unresolved credentials return 401. No subject and no token is the shared anonymous mock identity described below, not authentication. The [SAS getVariable documentation](https://developer.sas.com/rest-apis/compute/getVariable/index.md) specifies name, value, scope and representation version 1; the committed capture records link field types, not their values. `AUTOMATIC` and the single self link and its media type are mock-specific choices, not observed Viya values. The dispatch request carries no Accept header: this mock only returns a JSON-shaped resource and does not implement or negotiate SAS's documented `text/plain` or other Accept representations. Hosts must not enable it for clients relying on content negotiation.
|
package/build/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @sasjs/api 0.
|
|
1
|
+
/* @sasjs/api 0.52.0 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
|
|
2
2
|
"use strict";
|
|
3
3
|
var SASjsApi = (() => {
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -1049,17 +1049,17 @@ var SASjsApi = (() => {
|
|
|
1049
1049
|
}
|
|
1050
1050
|
}
|
|
1051
1051
|
children(path) {
|
|
1052
|
-
const
|
|
1052
|
+
const prefix2 = path === "/" ? "/" : path + "/";
|
|
1053
1053
|
const files = [];
|
|
1054
1054
|
const folders = [];
|
|
1055
1055
|
for (const candidate of this.files.keys()) {
|
|
1056
|
-
if (!candidate.startsWith(
|
|
1057
|
-
const rest = candidate.slice(
|
|
1056
|
+
if (!candidate.startsWith(prefix2)) continue;
|
|
1057
|
+
const rest = candidate.slice(prefix2.length);
|
|
1058
1058
|
if (rest && !rest.includes("/")) files.push(rest);
|
|
1059
1059
|
}
|
|
1060
1060
|
for (const candidate of this.folders) {
|
|
1061
|
-
if (!candidate.startsWith(
|
|
1062
|
-
const rest = candidate.slice(
|
|
1061
|
+
if (!candidate.startsWith(prefix2)) continue;
|
|
1062
|
+
const rest = candidate.slice(prefix2.length);
|
|
1063
1063
|
if (rest && !rest.includes("/")) folders.push(rest);
|
|
1064
1064
|
}
|
|
1065
1065
|
return { files: files.sort(), folders: folders.sort() };
|
|
@@ -1095,12 +1095,12 @@ var SASjsApi = (() => {
|
|
|
1095
1095
|
}
|
|
1096
1096
|
async remove(path) {
|
|
1097
1097
|
if (this.files.delete(path)) return;
|
|
1098
|
-
const
|
|
1098
|
+
const prefix2 = path === "/" ? "/" : path + "/";
|
|
1099
1099
|
for (const candidate of [...this.files.keys()]) {
|
|
1100
|
-
if (candidate.startsWith(
|
|
1100
|
+
if (candidate.startsWith(prefix2)) this.files.delete(candidate);
|
|
1101
1101
|
}
|
|
1102
1102
|
for (const candidate of [...this.folders]) {
|
|
1103
|
-
if (candidate === path || candidate.startsWith(
|
|
1103
|
+
if (candidate === path || candidate.startsWith(prefix2))
|
|
1104
1104
|
this.folders.delete(candidate);
|
|
1105
1105
|
}
|
|
1106
1106
|
}
|
|
@@ -1113,10 +1113,10 @@ var SASjsApi = (() => {
|
|
|
1113
1113
|
this.files.set(to, copy);
|
|
1114
1114
|
return;
|
|
1115
1115
|
}
|
|
1116
|
-
const
|
|
1116
|
+
const prefix2 = from + "/";
|
|
1117
1117
|
const moves = [];
|
|
1118
1118
|
for (const [candidate, value] of this.files) {
|
|
1119
|
-
if (candidate.startsWith(
|
|
1119
|
+
if (candidate.startsWith(prefix2))
|
|
1120
1120
|
moves.push([candidate, to + candidate.slice(from.length), value]);
|
|
1121
1121
|
}
|
|
1122
1122
|
for (const [source] of moves) this.files.delete(source);
|
|
@@ -1125,7 +1125,7 @@ var SASjsApi = (() => {
|
|
|
1125
1125
|
this.files.set(destination, value);
|
|
1126
1126
|
}
|
|
1127
1127
|
for (const candidate of [...this.folders]) {
|
|
1128
|
-
if (candidate === from || candidate.startsWith(
|
|
1128
|
+
if (candidate === from || candidate.startsWith(prefix2)) {
|
|
1129
1129
|
this.folders.delete(candidate);
|
|
1130
1130
|
this.folders.add(to + candidate.slice(from.length));
|
|
1131
1131
|
}
|
|
@@ -3787,14 +3787,14 @@ var SASjsApi = (() => {
|
|
|
3787
3787
|
var compiled = ROUTES.filter((route) => route.path.includes("{")).map(
|
|
3788
3788
|
(route) => {
|
|
3789
3789
|
const keys = [];
|
|
3790
|
-
const
|
|
3790
|
+
const pattern2 = route.path.split("/").map((segment) => {
|
|
3791
3791
|
if (segment.startsWith("{") && segment.endsWith("}")) {
|
|
3792
3792
|
keys.push(segment.slice(1, -1));
|
|
3793
3793
|
return "([^/]+)";
|
|
3794
3794
|
}
|
|
3795
3795
|
return escape(segment);
|
|
3796
3796
|
}).join("/");
|
|
3797
|
-
return { route, keys, regex: new RegExp("^" +
|
|
3797
|
+
return { route, keys, regex: new RegExp("^" + pattern2 + "/?$", "i") };
|
|
3798
3798
|
}
|
|
3799
3799
|
);
|
|
3800
3800
|
var exact = /* @__PURE__ */ new Map();
|
|
@@ -5533,7 +5533,7 @@ var SASjsApi = (() => {
|
|
|
5533
5533
|
|
|
5534
5534
|
// src/viya/overlay.ts
|
|
5535
5535
|
var NEEDS_AUTH = "The token endpoint is answered by the host that mounts the emulator, which owns the token port.";
|
|
5536
|
-
var NEEDS_JOBS = "The emulator
|
|
5536
|
+
var NEEDS_JOBS = "The emulator stores job definitions but does not model job executions.";
|
|
5537
5537
|
var SESSION_VARIABLE_REFUSAL = "GET /compute/sessions/{}/variables/{} is not emulated. The emulator does not model session variables; the client reads these only to log the pid of a job it is about to submit (SYSJOBID), and any name it asks for is refused here rather than answered with a value the emulator did not run.";
|
|
5538
5538
|
var VIYA_OVERLAY = {
|
|
5539
5539
|
// answered here
|
|
@@ -5571,19 +5571,9 @@ var SASjsApi = (() => {
|
|
|
5571
5571
|
"PATCH /files/files/{}": { implemented: true },
|
|
5572
5572
|
"GET /files/files/{}/content": { implemented: true },
|
|
5573
5573
|
"PUT /files/files/{}/content": { implemented: true },
|
|
5574
|
-
//
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
// the emulator does not answer that path yet: a client that deploys a service
|
|
5578
|
-
// pack against an emulated estate stops here, with a reason rather than a 404.
|
|
5579
|
-
"POST /jobDefinitions/definitions": {
|
|
5580
|
-
implemented: false,
|
|
5581
|
-
reason: NEEDS_JOBS
|
|
5582
|
-
},
|
|
5583
|
-
"GET /jobDefinitions/definitions/{}": {
|
|
5584
|
-
implemented: false,
|
|
5585
|
-
reason: NEEDS_JOBS
|
|
5586
|
-
},
|
|
5574
|
+
// Definition persistence does not implement job execution.
|
|
5575
|
+
"POST /jobDefinitions/definitions": { implemented: true },
|
|
5576
|
+
"GET /jobDefinitions/definitions/{}": { implemented: true },
|
|
5587
5577
|
"POST /jobExecution/jobs": { implemented: false, reason: NEEDS_JOBS },
|
|
5588
5578
|
"GET /jobExecution/jobs/{}": { implemented: false, reason: NEEDS_JOBS },
|
|
5589
5579
|
"GET /jobExecution/jobs/{}/state": { implemented: false, reason: NEEDS_JOBS },
|
|
@@ -6567,6 +6557,116 @@ var SASjsApi = (() => {
|
|
|
6567
6557
|
}
|
|
6568
6558
|
};
|
|
6569
6559
|
|
|
6560
|
+
// src/viya/job-definitions.ts
|
|
6561
|
+
var prefix = ".sasjs-viya-job-";
|
|
6562
|
+
var fileName = (id) => `${prefix}${id}.json`;
|
|
6563
|
+
var pattern = /^\.sasjs-viya-job-([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})\.json$/;
|
|
6564
|
+
var isJobDefinitionFileName = (name) => pattern.test(name);
|
|
6565
|
+
var definitionFromFile = async (drive, folder, name) => {
|
|
6566
|
+
const match = pattern.exec(name);
|
|
6567
|
+
if (!match) return void 0;
|
|
6568
|
+
const { contents } = await drive.read(
|
|
6569
|
+
`${folder}/${name}`.replace(/\/{2,}/g, "/")
|
|
6570
|
+
);
|
|
6571
|
+
if (typeof contents !== "string") return void 0;
|
|
6572
|
+
try {
|
|
6573
|
+
const value = JSON.parse(contents);
|
|
6574
|
+
if (!value || value.id !== match[1] || typeof value.name !== "string" || typeof value.code !== "string" || typeof value.type !== "string" || !Array.isArray(value.parameters) || !Array.isArray(value.links))
|
|
6575
|
+
return void 0;
|
|
6576
|
+
return value;
|
|
6577
|
+
} catch {
|
|
6578
|
+
return void 0;
|
|
6579
|
+
}
|
|
6580
|
+
};
|
|
6581
|
+
var allNodes = (root) => [
|
|
6582
|
+
root,
|
|
6583
|
+
...root.children.flatMap(allNodes)
|
|
6584
|
+
];
|
|
6585
|
+
var JOB_DEFINITION_HANDLERS = {
|
|
6586
|
+
"POST /jobDefinitions/definitions": async ({ services, request }) => {
|
|
6587
|
+
if (services.viya?.allowUntransactionalJobDefinitionCreation !== true)
|
|
6588
|
+
throw new ApiError(
|
|
6589
|
+
501,
|
|
6590
|
+
"Job definition creation requires an isolated host opt-in; Drive mutations are not transactional."
|
|
6591
|
+
);
|
|
6592
|
+
const body = request.body;
|
|
6593
|
+
if (!body || typeof body.name !== "string" || !body.name || body.name === "." || body.name === ".." || /[/\\\u0000-\u001f]/.test(body.name) || typeof body.type !== "string" || typeof body.code !== "string" || !Array.isArray(body.parameters))
|
|
6594
|
+
throw new ApiError(400, "A name, type, code and parameters are required.");
|
|
6595
|
+
const parameters = Array.from(
|
|
6596
|
+
body.parameters,
|
|
6597
|
+
(item) => {
|
|
6598
|
+
const param = item;
|
|
6599
|
+
if (!param || typeof param.name !== "string" || typeof param.type !== "string" || typeof param.defaultValue !== "string" || param.required !== void 0 && typeof param.required !== "boolean")
|
|
6600
|
+
throw new ApiError(400, "Invalid job parameter.");
|
|
6601
|
+
return {
|
|
6602
|
+
name: param.name,
|
|
6603
|
+
type: param.type,
|
|
6604
|
+
defaultValue: param.defaultValue,
|
|
6605
|
+
required: param.required ?? false,
|
|
6606
|
+
version: 1
|
|
6607
|
+
};
|
|
6608
|
+
}
|
|
6609
|
+
);
|
|
6610
|
+
const parent = request.query?.parentFolderUri;
|
|
6611
|
+
const match = typeof parent === "string" ? parent.match(/^\/folders\/folders\/([^/]+)$/) : void 0;
|
|
6612
|
+
if (!match) throw new ApiError(400, "A parent folder URI is required.");
|
|
6613
|
+
const drive = services.drive;
|
|
6614
|
+
const nodes = allNodes((await drive.tree("/")).tree);
|
|
6615
|
+
const folder = nodes.find(
|
|
6616
|
+
(node) => node.isFolder && idFor(node.relativePath) === match[1]
|
|
6617
|
+
);
|
|
6618
|
+
if (!folder) throw new ApiError(404, "Parent folder not found.");
|
|
6619
|
+
const listing = await drive.list(folder.relativePath);
|
|
6620
|
+
const existing = await Promise.all(
|
|
6621
|
+
listing.files.map(
|
|
6622
|
+
(name) => definitionFromFile(drive, folder.relativePath, name)
|
|
6623
|
+
)
|
|
6624
|
+
);
|
|
6625
|
+
if (existing.some((definition2) => definition2?.name === body.name))
|
|
6626
|
+
throw new ApiError(409, "Job definition already exists.");
|
|
6627
|
+
const id = newUuidV4();
|
|
6628
|
+
const uri = `/jobDefinitions/definitions/${id}`;
|
|
6629
|
+
const caller = callerId(request.subject);
|
|
6630
|
+
const definition = {
|
|
6631
|
+
id,
|
|
6632
|
+
name: body.name,
|
|
6633
|
+
type: body.type,
|
|
6634
|
+
code: body.code,
|
|
6635
|
+
parameters,
|
|
6636
|
+
version: 1,
|
|
6637
|
+
createdBy: caller,
|
|
6638
|
+
modifiedBy: caller,
|
|
6639
|
+
creationTimeStamp: EMULATED_NOW,
|
|
6640
|
+
modifiedTimeStamp: EMULATED_NOW,
|
|
6641
|
+
links: [
|
|
6642
|
+
{
|
|
6643
|
+
href: uri,
|
|
6644
|
+
uri,
|
|
6645
|
+
rel: "self",
|
|
6646
|
+
method: "GET",
|
|
6647
|
+
type: "application/vnd.sas.job.definition"
|
|
6648
|
+
}
|
|
6649
|
+
]
|
|
6650
|
+
};
|
|
6651
|
+
await drive.save(
|
|
6652
|
+
`${folder.relativePath}/${fileName(id)}`.replace(/\/{2,}/g, "/"),
|
|
6653
|
+
JSON.stringify(definition)
|
|
6654
|
+
);
|
|
6655
|
+
return { status: 201, body: definition };
|
|
6656
|
+
},
|
|
6657
|
+
"GET /jobDefinitions/definitions/{}": async ({ services, params }) => {
|
|
6658
|
+
const name = fileName(params.id);
|
|
6659
|
+
if (!pattern.test(name))
|
|
6660
|
+
throw new ApiError(404, "Job definition not found.");
|
|
6661
|
+
const nodes = allNodes((await services.drive.tree("/")).tree);
|
|
6662
|
+
const node = nodes.find((item) => !item.isFolder && item.name === name);
|
|
6663
|
+
const folder = node?.relativePath.slice(0, -(name.length + 1)) || "/";
|
|
6664
|
+
const definition = node && await definitionFromFile(services.drive, folder, name);
|
|
6665
|
+
if (!definition) throw new ApiError(404, "Job definition not found.");
|
|
6666
|
+
return { status: 200, body: definition };
|
|
6667
|
+
}
|
|
6668
|
+
};
|
|
6669
|
+
|
|
6570
6670
|
// src/viya/service.ts
|
|
6571
6671
|
var linksFor2 = (uri, collection2 = false) => {
|
|
6572
6672
|
const self = {
|
|
@@ -6637,17 +6737,17 @@ var SASjsApi = (() => {
|
|
|
6637
6737
|
var RECYCLE_BIN_ALIAS = "/folders/folders/@myRecycleBin";
|
|
6638
6738
|
var isRecycleBin = (uri) => !!uri && (uri === RECYCLE_BIN_ALIAS || uri.endsWith(`/${idFor("@myRecycleBin")}`));
|
|
6639
6739
|
var pathForId = async (drive, id) => {
|
|
6640
|
-
const walk2 = (
|
|
6641
|
-
if (
|
|
6642
|
-
|
|
6643
|
-
for (const
|
|
6644
|
-
const
|
|
6645
|
-
|
|
6740
|
+
const walk2 = async (path2) => {
|
|
6741
|
+
if (idFor(path2) === id) return path2;
|
|
6742
|
+
const { folders } = await drive.list(path2);
|
|
6743
|
+
for (const name of folders) {
|
|
6744
|
+
const child = path2 === "/" ? `/${name}` : `${path2}/${name}`;
|
|
6745
|
+
const hit = await walk2(child);
|
|
6746
|
+
if (hit !== void 0) return hit;
|
|
6646
6747
|
}
|
|
6647
6748
|
return void 0;
|
|
6648
6749
|
};
|
|
6649
|
-
const
|
|
6650
|
-
const path = walk2(tree);
|
|
6750
|
+
const path = await walk2("/");
|
|
6651
6751
|
if (!path)
|
|
6652
6752
|
throw new ApiError(
|
|
6653
6753
|
404,
|
|
@@ -6760,13 +6860,15 @@ var SASjsApi = (() => {
|
|
|
6760
6860
|
"GET /folders/folders/{}/members": async ({ services, params, request }) => {
|
|
6761
6861
|
const drive = requireDrive(services);
|
|
6762
6862
|
const limit = Number(request.query?.limit ?? 0) || 0;
|
|
6863
|
+
const requestedStart = Number(request.query?.start ?? 0);
|
|
6864
|
+
const start = Number.isSafeInteger(requestedStart) && requestedStart > 0 ? requestedStart : 0;
|
|
6763
6865
|
if (params.id === idFor("@myRecycleBin"))
|
|
6764
6866
|
return {
|
|
6765
6867
|
status: 200,
|
|
6766
6868
|
body: {
|
|
6767
6869
|
accept: "application/json",
|
|
6768
6870
|
name: "members",
|
|
6769
|
-
start
|
|
6871
|
+
start,
|
|
6770
6872
|
// the query value is echoed as the sibling branch echoes it: a caller
|
|
6771
6873
|
// that asked for five and is told zero cannot tell what happened
|
|
6772
6874
|
limit,
|
|
@@ -6779,6 +6881,13 @@ var SASjsApi = (() => {
|
|
|
6779
6881
|
const path = await pathForId(drive, params.id);
|
|
6780
6882
|
const listing = await drive.list(path);
|
|
6781
6883
|
const caller = callerId(request.subject);
|
|
6884
|
+
const canReadMetadata = services.viya?.readJobDefinitionMetadata !== false;
|
|
6885
|
+
const definitions = canReadMetadata ? await Promise.all(
|
|
6886
|
+
listing.files.map((name) => definitionFromFile(drive, path, name))
|
|
6887
|
+
) : [];
|
|
6888
|
+
const definitionByFile = new Map(
|
|
6889
|
+
listing.files.map((name, index) => [name, definitions[index]])
|
|
6890
|
+
);
|
|
6782
6891
|
const items = [
|
|
6783
6892
|
...listing.folders.map((name) => ({
|
|
6784
6893
|
id: idFor(`${path}/${name}`.replace(/\/{2,}/g, "/")),
|
|
@@ -6795,7 +6904,9 @@ var SASjsApi = (() => {
|
|
|
6795
6904
|
`/folders/folders/${idFor(`${path}/${name}`.replace(/\/{2,}/g, "/"))}`
|
|
6796
6905
|
)
|
|
6797
6906
|
})),
|
|
6798
|
-
...listing.files.
|
|
6907
|
+
...listing.files.filter(
|
|
6908
|
+
(name) => !definitionByFile.get(name) && (canReadMetadata || !isJobDefinitionFileName(name))
|
|
6909
|
+
).map((name) => ({
|
|
6799
6910
|
id: idFor(`${path}/${name}`.replace(/\/{2,}/g, "/"), "file"),
|
|
6800
6911
|
name,
|
|
6801
6912
|
type: "file",
|
|
@@ -6811,15 +6922,43 @@ var SASjsApi = (() => {
|
|
|
6811
6922
|
links: linksFor2(
|
|
6812
6923
|
`/files/files/${idFor(`${path}/${name}`.replace(/\/{2,}/g, "/"), "file")}`
|
|
6813
6924
|
)
|
|
6814
|
-
}))
|
|
6925
|
+
})),
|
|
6926
|
+
...definitions.filter((definition) => definition !== void 0).map((definition) => {
|
|
6927
|
+
const uri = `/jobDefinitions/definitions/${definition.id}`;
|
|
6928
|
+
return {
|
|
6929
|
+
id: definition.id,
|
|
6930
|
+
name: definition.name,
|
|
6931
|
+
// The captured member identifies its relationship separately from
|
|
6932
|
+
// the resource kind. Other links remain emulated, not estate parity.
|
|
6933
|
+
type: "child",
|
|
6934
|
+
contentType: "jobDefinition",
|
|
6935
|
+
version: 1,
|
|
6936
|
+
createdBy: definition.createdBy,
|
|
6937
|
+
modifiedBy: definition.modifiedBy,
|
|
6938
|
+
creationTimeStamp: definition.creationTimeStamp,
|
|
6939
|
+
modifiedTimeStamp: definition.modifiedTimeStamp,
|
|
6940
|
+
parentFolderUri: `/folders/folders/${idFor(path)}`,
|
|
6941
|
+
added: definition.creationTimeStamp,
|
|
6942
|
+
uri,
|
|
6943
|
+
links: [
|
|
6944
|
+
{
|
|
6945
|
+
href: uri,
|
|
6946
|
+
uri,
|
|
6947
|
+
rel: "getResource",
|
|
6948
|
+
method: "GET",
|
|
6949
|
+
type: "application/vnd.sas.summary"
|
|
6950
|
+
}
|
|
6951
|
+
]
|
|
6952
|
+
};
|
|
6953
|
+
})
|
|
6815
6954
|
];
|
|
6816
|
-
const page = limit > 0 ? items.slice(
|
|
6955
|
+
const page = limit > 0 ? items.slice(start, start + limit) : items.slice(start);
|
|
6817
6956
|
return {
|
|
6818
6957
|
status: 200,
|
|
6819
6958
|
body: {
|
|
6820
6959
|
accept: "application/json",
|
|
6821
6960
|
name: "members",
|
|
6822
|
-
start
|
|
6961
|
+
start,
|
|
6823
6962
|
limit: limit || page.length,
|
|
6824
6963
|
count: page.length,
|
|
6825
6964
|
version: 2,
|
|
@@ -6869,7 +7008,8 @@ var SASjsApi = (() => {
|
|
|
6869
7008
|
},
|
|
6870
7009
|
...COMPUTE_HANDLERS,
|
|
6871
7010
|
...FILE_HANDLERS,
|
|
6872
|
-
...IDENTITY_HANDLERS
|
|
7011
|
+
...IDENTITY_HANDLERS,
|
|
7012
|
+
...JOB_DEFINITION_HANDLERS
|
|
6873
7013
|
};
|
|
6874
7014
|
|
|
6875
7015
|
// src/viya/dispatch.ts
|
|
@@ -10379,10 +10519,10 @@ var SASjsApi = (() => {
|
|
|
10379
10519
|
return file;
|
|
10380
10520
|
});
|
|
10381
10521
|
};
|
|
10382
|
-
var checkLogFileName = (
|
|
10383
|
-
if (!
|
|
10522
|
+
var checkLogFileName = (fileName2) => {
|
|
10523
|
+
if (!fileName2 || fileName2.includes("/") || fileName2.includes("\\") || fileName2.split(/[\\/]/).pop() !== fileName2 || !fileName2.toLowerCase().endsWith(".log"))
|
|
10384
10524
|
throw new ApiError(400, "Invalid log file name.");
|
|
10385
|
-
return
|
|
10525
|
+
return fileName2;
|
|
10386
10526
|
};
|
|
10387
10527
|
var logLines = (lines) => {
|
|
10388
10528
|
if (lines === void 0 || lines === null || lines === "")
|
|
@@ -10411,8 +10551,8 @@ var SASjsApi = (() => {
|
|
|
10411
10551
|
async logs() {
|
|
10412
10552
|
return normaliseLogFiles(await reports.logs());
|
|
10413
10553
|
},
|
|
10414
|
-
async logTail(
|
|
10415
|
-
const name = checkLogFileName(
|
|
10554
|
+
async logTail(fileName2, lines) {
|
|
10555
|
+
const name = checkLogFileName(fileName2);
|
|
10416
10556
|
const tail = await reports.logTail(name, logLines(lines));
|
|
10417
10557
|
if (tail === void 0) throw new ApiError(404, "Log file not found.");
|
|
10418
10558
|
return normaliseLogTail(tail);
|
|
@@ -12820,7 +12960,7 @@ var SASjsApi = (() => {
|
|
|
12820
12960
|
admin: createAdminService({
|
|
12821
12961
|
diagnostics: async () => CORPUS_DIAGNOSTICS,
|
|
12822
12962
|
logs: async () => [CORPUS_LOG],
|
|
12823
|
-
logTail: async (
|
|
12963
|
+
logTail: async (fileName2) => fileName2 === CORPUS_LOG.name ? CORPUS_LOG_TAIL : void 0
|
|
12824
12964
|
}),
|
|
12825
12965
|
directory: createDirectoryService(identity, CORPUS_DIRECTORY),
|
|
12826
12966
|
identity: createIdentityService(identity),
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JOB_DEFINITION_HANDLERS = exports.definitionFromFile = exports.isJobDefinitionFileName = void 0;
|
|
4
|
+
const types_js_1 = require("../types.js");
|
|
5
|
+
const uuid_js_1 = require("../uuid.js");
|
|
6
|
+
const ids_js_1 = require("./ids.js");
|
|
7
|
+
const prefix = '.sasjs-viya-job-';
|
|
8
|
+
const fileName = (id) => `${prefix}${id}.json`;
|
|
9
|
+
const pattern = /^\.sasjs-viya-job-([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})\.json$/;
|
|
10
|
+
const isJobDefinitionFileName = (name) => pattern.test(name);
|
|
11
|
+
exports.isJobDefinitionFileName = isJobDefinitionFileName;
|
|
12
|
+
/** Read only explicitly marked, well-formed records; malformed files remain ordinary files. */
|
|
13
|
+
const definitionFromFile = async (drive, folder, name) => {
|
|
14
|
+
const match = pattern.exec(name);
|
|
15
|
+
if (!match)
|
|
16
|
+
return undefined;
|
|
17
|
+
const { contents } = await drive.read(`${folder}/${name}`.replace(/\/{2,}/g, '/'));
|
|
18
|
+
if (typeof contents !== 'string')
|
|
19
|
+
return undefined;
|
|
20
|
+
try {
|
|
21
|
+
const value = JSON.parse(contents);
|
|
22
|
+
if (!value ||
|
|
23
|
+
value.id !== match[1] ||
|
|
24
|
+
typeof value.name !== 'string' ||
|
|
25
|
+
typeof value.code !== 'string' ||
|
|
26
|
+
typeof value.type !== 'string' ||
|
|
27
|
+
!Array.isArray(value.parameters) ||
|
|
28
|
+
!Array.isArray(value.links))
|
|
29
|
+
return undefined;
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.definitionFromFile = definitionFromFile;
|
|
37
|
+
const allNodes = (root) => [
|
|
38
|
+
root,
|
|
39
|
+
...root.children.flatMap(allNodes)
|
|
40
|
+
];
|
|
41
|
+
exports.JOB_DEFINITION_HANDLERS = {
|
|
42
|
+
'POST /jobDefinitions/definitions': async ({ services, request }) => {
|
|
43
|
+
if (services.viya?.allowUntransactionalJobDefinitionCreation !== true)
|
|
44
|
+
throw new types_js_1.ApiError(501, 'Job definition creation requires an isolated host opt-in; Drive mutations are not transactional.');
|
|
45
|
+
const body = request.body;
|
|
46
|
+
if (!body ||
|
|
47
|
+
typeof body.name !== 'string' ||
|
|
48
|
+
!body.name ||
|
|
49
|
+
body.name === '.' ||
|
|
50
|
+
body.name === '..' ||
|
|
51
|
+
/[/\\\u0000-\u001f]/.test(body.name) ||
|
|
52
|
+
typeof body.type !== 'string' ||
|
|
53
|
+
typeof body.code !== 'string' ||
|
|
54
|
+
!Array.isArray(body.parameters))
|
|
55
|
+
throw new types_js_1.ApiError(400, 'A name, type, code and parameters are required.');
|
|
56
|
+
const parameters = Array.from(body.parameters, (item) => {
|
|
57
|
+
const param = item;
|
|
58
|
+
if (!param ||
|
|
59
|
+
typeof param.name !== 'string' ||
|
|
60
|
+
typeof param.type !== 'string' ||
|
|
61
|
+
typeof param.defaultValue !== 'string' ||
|
|
62
|
+
(param.required !== undefined && typeof param.required !== 'boolean'))
|
|
63
|
+
throw new types_js_1.ApiError(400, 'Invalid job parameter.');
|
|
64
|
+
return {
|
|
65
|
+
name: param.name,
|
|
66
|
+
type: param.type,
|
|
67
|
+
defaultValue: param.defaultValue,
|
|
68
|
+
required: param.required ?? false,
|
|
69
|
+
version: 1
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
const parent = request.query?.parentFolderUri;
|
|
73
|
+
const match = typeof parent === 'string'
|
|
74
|
+
? parent.match(/^\/folders\/folders\/([^/]+)$/)
|
|
75
|
+
: undefined;
|
|
76
|
+
if (!match)
|
|
77
|
+
throw new types_js_1.ApiError(400, 'A parent folder URI is required.');
|
|
78
|
+
const drive = services.drive;
|
|
79
|
+
const nodes = allNodes((await drive.tree('/')).tree);
|
|
80
|
+
const folder = nodes.find((node) => node.isFolder && (0, ids_js_1.idFor)(node.relativePath) === match[1]);
|
|
81
|
+
if (!folder)
|
|
82
|
+
throw new types_js_1.ApiError(404, 'Parent folder not found.');
|
|
83
|
+
const listing = await drive.list(folder.relativePath);
|
|
84
|
+
const existing = await Promise.all(listing.files.map((name) => (0, exports.definitionFromFile)(drive, folder.relativePath, name)));
|
|
85
|
+
if (existing.some((definition) => definition?.name === body.name))
|
|
86
|
+
throw new types_js_1.ApiError(409, 'Job definition already exists.');
|
|
87
|
+
const id = (0, uuid_js_1.newUuidV4)();
|
|
88
|
+
const uri = `/jobDefinitions/definitions/${id}`;
|
|
89
|
+
const caller = (0, ids_js_1.callerId)(request.subject);
|
|
90
|
+
const definition = {
|
|
91
|
+
id,
|
|
92
|
+
name: body.name,
|
|
93
|
+
type: body.type,
|
|
94
|
+
code: body.code,
|
|
95
|
+
parameters,
|
|
96
|
+
version: 1,
|
|
97
|
+
createdBy: caller,
|
|
98
|
+
modifiedBy: caller,
|
|
99
|
+
creationTimeStamp: ids_js_1.EMULATED_NOW,
|
|
100
|
+
modifiedTimeStamp: ids_js_1.EMULATED_NOW,
|
|
101
|
+
links: [
|
|
102
|
+
{
|
|
103
|
+
href: uri,
|
|
104
|
+
uri,
|
|
105
|
+
rel: 'self',
|
|
106
|
+
method: 'GET',
|
|
107
|
+
type: 'application/vnd.sas.job.definition'
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
};
|
|
111
|
+
await drive.save(`${folder.relativePath}/${fileName(id)}`.replace(/\/{2,}/g, '/'), JSON.stringify(definition));
|
|
112
|
+
return { status: 201, body: definition };
|
|
113
|
+
},
|
|
114
|
+
'GET /jobDefinitions/definitions/{}': async ({ services, params }) => {
|
|
115
|
+
const name = fileName(params.id);
|
|
116
|
+
if (!pattern.test(name))
|
|
117
|
+
throw new types_js_1.ApiError(404, 'Job definition not found.');
|
|
118
|
+
const nodes = allNodes((await services.drive.tree('/')).tree);
|
|
119
|
+
const node = nodes.find((item) => !item.isFolder && item.name === name);
|
|
120
|
+
const folder = node?.relativePath.slice(0, -(name.length + 1)) || '/';
|
|
121
|
+
const definition = node && (await (0, exports.definitionFromFile)(services.drive, folder, name));
|
|
122
|
+
if (!definition)
|
|
123
|
+
throw new types_js_1.ApiError(404, 'Job definition not found.');
|
|
124
|
+
return { status: 200, body: definition };
|
|
125
|
+
}
|
|
126
|
+
};
|
|
@@ -23,15 +23,8 @@ const declared_js_1 = require("./declared.js");
|
|
|
23
23
|
* a second answer to the same question.
|
|
24
24
|
*/
|
|
25
25
|
const NEEDS_AUTH = 'The token endpoint is answered by the host that mounts the emulator, which owns the token port.';
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
* The deploy-and-run path is recorded - a service pack deploy creates a job
|
|
30
|
-
* definition and submits it - and this package answers the compute and content
|
|
31
|
-
* families, not that one. Saying so is the difference between a client learning
|
|
32
|
-
* what is missing and a client learning nothing.
|
|
33
|
-
*/
|
|
34
|
-
const NEEDS_JOBS = 'The emulator answers the compute and content families; the job definitions a deploy creates and the executions a run submits are not modelled yet.';
|
|
26
|
+
/** Definition storage is modelled separately from job execution. */
|
|
27
|
+
const NEEDS_JOBS = 'The emulator stores job definitions but does not model job executions.';
|
|
35
28
|
exports.SESSION_VARIABLE_REFUSAL = 'GET /compute/sessions/{}/variables/{} is not emulated. The emulator does not model session variables; the client reads these only to log the pid of a job it is about to submit (SYSJOBID), and any name it asks for is refused here rather than answered with a value the emulator did not run.';
|
|
36
29
|
exports.VIYA_OVERLAY = {
|
|
37
30
|
// answered here
|
|
@@ -69,19 +62,9 @@ exports.VIYA_OVERLAY = {
|
|
|
69
62
|
'PATCH /files/files/{}': { implemented: true },
|
|
70
63
|
'GET /files/files/{}/content': { implemented: true },
|
|
71
64
|
'PUT /files/files/{}/content': { implemented: true },
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
// the emulator does not answer that path yet: a client that deploys a service
|
|
76
|
-
// pack against an emulated estate stops here, with a reason rather than a 404.
|
|
77
|
-
'POST /jobDefinitions/definitions': {
|
|
78
|
-
implemented: false,
|
|
79
|
-
reason: NEEDS_JOBS
|
|
80
|
-
},
|
|
81
|
-
'GET /jobDefinitions/definitions/{}': {
|
|
82
|
-
implemented: false,
|
|
83
|
-
reason: NEEDS_JOBS
|
|
84
|
-
},
|
|
65
|
+
// Definition persistence does not implement job execution.
|
|
66
|
+
'POST /jobDefinitions/definitions': { implemented: true },
|
|
67
|
+
'GET /jobDefinitions/definitions/{}': { implemented: true },
|
|
85
68
|
'POST /jobExecution/jobs': { implemented: false, reason: NEEDS_JOBS },
|
|
86
69
|
'GET /jobExecution/jobs/{}': { implemented: false, reason: NEEDS_JOBS },
|
|
87
70
|
'GET /jobExecution/jobs/{}/state': { implemented: false, reason: NEEDS_JOBS },
|
|
@@ -6,6 +6,7 @@ const ports_js_1 = require("./ports.js");
|
|
|
6
6
|
const compute_js_1 = require("./compute.js");
|
|
7
7
|
const files_js_1 = require("./files.js");
|
|
8
8
|
const identity_js_1 = require("./identity.js");
|
|
9
|
+
const job_definitions_js_1 = require("./job-definitions.js");
|
|
9
10
|
const ids_js_1 = require("./ids.js");
|
|
10
11
|
const linksFor = (uri, collection = false) => {
|
|
11
12
|
const self = {
|
|
@@ -89,18 +90,19 @@ const isRecycleBin = (uri) => !!uri &&
|
|
|
89
90
|
* opposite of "a client stores an id and asks for it later".
|
|
90
91
|
*/
|
|
91
92
|
const pathForId = async (drive, id) => {
|
|
92
|
-
const walk = (
|
|
93
|
-
if (
|
|
94
|
-
return
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
const walk = async (path) => {
|
|
94
|
+
if ((0, ids_js_1.idFor)(path) === id)
|
|
95
|
+
return path;
|
|
96
|
+
const { folders } = await drive.list(path);
|
|
97
|
+
for (const name of folders) {
|
|
98
|
+
const child = path === '/' ? `/${name}` : `${path}/${name}`;
|
|
99
|
+
const hit = await walk(child);
|
|
100
|
+
if (hit !== undefined)
|
|
98
101
|
return hit;
|
|
99
102
|
}
|
|
100
103
|
return undefined;
|
|
101
104
|
};
|
|
102
|
-
const
|
|
103
|
-
const path = walk(tree);
|
|
105
|
+
const path = await walk('/');
|
|
104
106
|
if (!path)
|
|
105
107
|
throw new types_js_1.ApiError(404, `No folder matches the id ${id}. Ids are derived from paths, so an id that names no folder is one no folder ever had.`);
|
|
106
108
|
return path;
|
|
@@ -208,6 +210,10 @@ exports.VIYA_HANDLERS = {
|
|
|
208
210
|
'GET /folders/folders/{}/members': async ({ services, params, request }) => {
|
|
209
211
|
const drive = (0, ports_js_1.requireDrive)(services);
|
|
210
212
|
const limit = Number(request.query?.limit ?? 0) || 0;
|
|
213
|
+
const requestedStart = Number(request.query?.start ?? 0);
|
|
214
|
+
const start = Number.isSafeInteger(requestedStart) && requestedStart > 0
|
|
215
|
+
? requestedStart
|
|
216
|
+
: 0;
|
|
211
217
|
// the bin is not a folder in the drive, and its own body advertises this
|
|
212
218
|
// link - so a client following the answer it just received must not 404
|
|
213
219
|
if (params.id === (0, ids_js_1.idFor)('@myRecycleBin'))
|
|
@@ -216,7 +222,7 @@ exports.VIYA_HANDLERS = {
|
|
|
216
222
|
body: {
|
|
217
223
|
accept: 'application/json',
|
|
218
224
|
name: 'members',
|
|
219
|
-
start
|
|
225
|
+
start,
|
|
220
226
|
// the query value is echoed as the sibling branch echoes it: a caller
|
|
221
227
|
// that asked for five and is told zero cannot tell what happened
|
|
222
228
|
limit,
|
|
@@ -229,6 +235,11 @@ exports.VIYA_HANDLERS = {
|
|
|
229
235
|
const path = await pathForId(drive, params.id);
|
|
230
236
|
const listing = await drive.list(path);
|
|
231
237
|
const caller = (0, ids_js_1.callerId)(request.subject);
|
|
238
|
+
const canReadMetadata = services.viya?.readJobDefinitionMetadata !== false;
|
|
239
|
+
const definitions = canReadMetadata
|
|
240
|
+
? await Promise.all(listing.files.map((name) => (0, job_definitions_js_1.definitionFromFile)(drive, path, name)))
|
|
241
|
+
: [];
|
|
242
|
+
const definitionByFile = new Map(listing.files.map((name, index) => [name, definitions[index]]));
|
|
232
243
|
/**
|
|
233
244
|
* A member's `uri` is the resource, not its path.
|
|
234
245
|
*
|
|
@@ -252,7 +263,10 @@ exports.VIYA_HANDLERS = {
|
|
|
252
263
|
uri: `/folders/folders/${(0, ids_js_1.idFor)(`${path}/${name}`.replace(/\/{2,}/g, '/'))}`,
|
|
253
264
|
links: linksFor(`/folders/folders/${(0, ids_js_1.idFor)(`${path}/${name}`.replace(/\/{2,}/g, '/'))}`)
|
|
254
265
|
})),
|
|
255
|
-
...listing.files
|
|
266
|
+
...listing.files
|
|
267
|
+
.filter((name) => !definitionByFile.get(name) &&
|
|
268
|
+
(canReadMetadata || !(0, job_definitions_js_1.isJobDefinitionFileName)(name)))
|
|
269
|
+
.map((name) => ({
|
|
256
270
|
id: (0, ids_js_1.idFor)(`${path}/${name}`.replace(/\/{2,}/g, '/'), 'file'),
|
|
257
271
|
name,
|
|
258
272
|
type: 'file',
|
|
@@ -266,9 +280,39 @@ exports.VIYA_HANDLERS = {
|
|
|
266
280
|
added: ids_js_1.EMULATED_NOW,
|
|
267
281
|
uri: `/files/files/${(0, ids_js_1.idFor)(`${path}/${name}`.replace(/\/{2,}/g, '/'), 'file')}`,
|
|
268
282
|
links: linksFor(`/files/files/${(0, ids_js_1.idFor)(`${path}/${name}`.replace(/\/{2,}/g, '/'), 'file')}`)
|
|
269
|
-
}))
|
|
283
|
+
})),
|
|
284
|
+
...definitions
|
|
285
|
+
.filter((definition) => definition !== undefined)
|
|
286
|
+
.map((definition) => {
|
|
287
|
+
const uri = `/jobDefinitions/definitions/${definition.id}`;
|
|
288
|
+
return {
|
|
289
|
+
id: definition.id,
|
|
290
|
+
name: definition.name,
|
|
291
|
+
// The captured member identifies its relationship separately from
|
|
292
|
+
// the resource kind. Other links remain emulated, not estate parity.
|
|
293
|
+
type: 'child',
|
|
294
|
+
contentType: 'jobDefinition',
|
|
295
|
+
version: 1,
|
|
296
|
+
createdBy: definition.createdBy,
|
|
297
|
+
modifiedBy: definition.modifiedBy,
|
|
298
|
+
creationTimeStamp: definition.creationTimeStamp,
|
|
299
|
+
modifiedTimeStamp: definition.modifiedTimeStamp,
|
|
300
|
+
parentFolderUri: `/folders/folders/${(0, ids_js_1.idFor)(path)}`,
|
|
301
|
+
added: definition.creationTimeStamp,
|
|
302
|
+
uri,
|
|
303
|
+
links: [
|
|
304
|
+
{
|
|
305
|
+
href: uri,
|
|
306
|
+
uri,
|
|
307
|
+
rel: 'getResource',
|
|
308
|
+
method: 'GET',
|
|
309
|
+
type: 'application/vnd.sas.summary'
|
|
310
|
+
}
|
|
311
|
+
]
|
|
312
|
+
};
|
|
313
|
+
})
|
|
270
314
|
];
|
|
271
|
-
const page = limit > 0 ? items.slice(
|
|
315
|
+
const page = limit > 0 ? items.slice(start, start + limit) : items.slice(start);
|
|
272
316
|
// the envelope is what the capture recorded, including the paging fields a
|
|
273
317
|
// client reads to decide whether to ask for more
|
|
274
318
|
return {
|
|
@@ -276,7 +320,7 @@ exports.VIYA_HANDLERS = {
|
|
|
276
320
|
body: {
|
|
277
321
|
accept: 'application/json',
|
|
278
322
|
name: 'members',
|
|
279
|
-
start
|
|
323
|
+
start,
|
|
280
324
|
limit: limit || page.length,
|
|
281
325
|
count: page.length,
|
|
282
326
|
version: 2,
|
|
@@ -341,5 +385,6 @@ exports.VIYA_HANDLERS = {
|
|
|
341
385
|
},
|
|
342
386
|
...compute_js_1.COMPUTE_HANDLERS,
|
|
343
387
|
...files_js_1.FILE_HANDLERS,
|
|
344
|
-
...identity_js_1.IDENTITY_HANDLERS
|
|
388
|
+
...identity_js_1.IDENTITY_HANDLERS,
|
|
389
|
+
...job_definitions_js_1.JOB_DEFINITION_HANDLERS
|
|
345
390
|
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ApiResponse, Services } from '../host/dispatch.js';
|
|
2
|
+
import type { DriveService } from '../drive/service.js';
|
|
3
|
+
import type { Subject } from '../identity/types.js';
|
|
4
|
+
export declare const isJobDefinitionFileName: (name: string) => boolean;
|
|
5
|
+
type Parameter = {
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
defaultValue: string;
|
|
9
|
+
required: boolean;
|
|
10
|
+
version: number;
|
|
11
|
+
};
|
|
12
|
+
type Definition = {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
code: string;
|
|
16
|
+
type: string;
|
|
17
|
+
parameters: Parameter[];
|
|
18
|
+
createdBy: string;
|
|
19
|
+
modifiedBy: string;
|
|
20
|
+
creationTimeStamp: string;
|
|
21
|
+
modifiedTimeStamp: string;
|
|
22
|
+
version: number;
|
|
23
|
+
links: Array<{
|
|
24
|
+
href: string;
|
|
25
|
+
uri: string;
|
|
26
|
+
rel: string;
|
|
27
|
+
method: string;
|
|
28
|
+
type: string;
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
/** Read only explicitly marked, well-formed records; malformed files remain ordinary files. */
|
|
32
|
+
export declare const definitionFromFile: (drive: DriveService, folder: string, name: string) => Promise<Definition | undefined>;
|
|
33
|
+
export declare const JOB_DEFINITION_HANDLERS: Record<string, (context: {
|
|
34
|
+
services: Services;
|
|
35
|
+
request: {
|
|
36
|
+
query?: Record<string, string | undefined>;
|
|
37
|
+
body?: unknown;
|
|
38
|
+
subject?: Subject;
|
|
39
|
+
};
|
|
40
|
+
params: Record<string, string>;
|
|
41
|
+
}) => Promise<ApiResponse>>;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=job-definitions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job-definitions.d.ts","sourceRoot":"","sources":["../../../src/viya/job-definitions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAWnD,eAAO,MAAM,uBAAuB,GAAI,MAAM,MAAM,KAAG,OACnC,CAAA;AAEpB,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AACD,KAAK,UAAU,GAAG;IAChB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,SAAS,EAAE,CAAA;IACvB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,iBAAiB,EAAE,MAAM,CAAA;IACzB,iBAAiB,EAAE,MAAM,CAAA;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,KAAK,CAAC;QACX,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;QACX,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,EAAE,MAAM,CAAA;KACb,CAAC,CAAA;CACH,CAAA;AAED,+FAA+F;AAC/F,eAAO,MAAM,kBAAkB,GAC7B,OAAO,YAAY,EACnB,QAAQ,MAAM,EACd,MAAM,MAAM,KACX,OAAO,CAAC,UAAU,GAAG,SAAS,CAuBhC,CAAA;AAOD,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAC1C,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,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,CAAA;IACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B,KAAK,OAAO,CAAC,WAAW,CAAC,CA+G3B,CAAA"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { ApiError } from '../types.js';
|
|
2
|
+
import { newUuidV4 } from '../uuid.js';
|
|
3
|
+
import { callerId, EMULATED_NOW, idFor } from './ids.js';
|
|
4
|
+
const prefix = '.sasjs-viya-job-';
|
|
5
|
+
const fileName = (id) => `${prefix}${id}.json`;
|
|
6
|
+
const pattern = /^\.sasjs-viya-job-([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})\.json$/;
|
|
7
|
+
export const isJobDefinitionFileName = (name) => pattern.test(name);
|
|
8
|
+
/** Read only explicitly marked, well-formed records; malformed files remain ordinary files. */
|
|
9
|
+
export const definitionFromFile = async (drive, folder, name) => {
|
|
10
|
+
const match = pattern.exec(name);
|
|
11
|
+
if (!match)
|
|
12
|
+
return undefined;
|
|
13
|
+
const { contents } = await drive.read(`${folder}/${name}`.replace(/\/{2,}/g, '/'));
|
|
14
|
+
if (typeof contents !== 'string')
|
|
15
|
+
return undefined;
|
|
16
|
+
try {
|
|
17
|
+
const value = JSON.parse(contents);
|
|
18
|
+
if (!value ||
|
|
19
|
+
value.id !== match[1] ||
|
|
20
|
+
typeof value.name !== 'string' ||
|
|
21
|
+
typeof value.code !== 'string' ||
|
|
22
|
+
typeof value.type !== 'string' ||
|
|
23
|
+
!Array.isArray(value.parameters) ||
|
|
24
|
+
!Array.isArray(value.links))
|
|
25
|
+
return undefined;
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const allNodes = (root) => [
|
|
33
|
+
root,
|
|
34
|
+
...root.children.flatMap(allNodes)
|
|
35
|
+
];
|
|
36
|
+
export const JOB_DEFINITION_HANDLERS = {
|
|
37
|
+
'POST /jobDefinitions/definitions': async ({ services, request }) => {
|
|
38
|
+
if (services.viya?.allowUntransactionalJobDefinitionCreation !== true)
|
|
39
|
+
throw new ApiError(501, 'Job definition creation requires an isolated host opt-in; Drive mutations are not transactional.');
|
|
40
|
+
const body = request.body;
|
|
41
|
+
if (!body ||
|
|
42
|
+
typeof body.name !== 'string' ||
|
|
43
|
+
!body.name ||
|
|
44
|
+
body.name === '.' ||
|
|
45
|
+
body.name === '..' ||
|
|
46
|
+
/[/\\\u0000-\u001f]/.test(body.name) ||
|
|
47
|
+
typeof body.type !== 'string' ||
|
|
48
|
+
typeof body.code !== 'string' ||
|
|
49
|
+
!Array.isArray(body.parameters))
|
|
50
|
+
throw new ApiError(400, 'A name, type, code and parameters are required.');
|
|
51
|
+
const parameters = Array.from(body.parameters, (item) => {
|
|
52
|
+
const param = item;
|
|
53
|
+
if (!param ||
|
|
54
|
+
typeof param.name !== 'string' ||
|
|
55
|
+
typeof param.type !== 'string' ||
|
|
56
|
+
typeof param.defaultValue !== 'string' ||
|
|
57
|
+
(param.required !== undefined && typeof param.required !== 'boolean'))
|
|
58
|
+
throw new ApiError(400, 'Invalid job parameter.');
|
|
59
|
+
return {
|
|
60
|
+
name: param.name,
|
|
61
|
+
type: param.type,
|
|
62
|
+
defaultValue: param.defaultValue,
|
|
63
|
+
required: param.required ?? false,
|
|
64
|
+
version: 1
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
const parent = request.query?.parentFolderUri;
|
|
68
|
+
const match = typeof parent === 'string'
|
|
69
|
+
? parent.match(/^\/folders\/folders\/([^/]+)$/)
|
|
70
|
+
: undefined;
|
|
71
|
+
if (!match)
|
|
72
|
+
throw new ApiError(400, 'A parent folder URI is required.');
|
|
73
|
+
const drive = services.drive;
|
|
74
|
+
const nodes = allNodes((await drive.tree('/')).tree);
|
|
75
|
+
const folder = nodes.find((node) => node.isFolder && idFor(node.relativePath) === match[1]);
|
|
76
|
+
if (!folder)
|
|
77
|
+
throw new ApiError(404, 'Parent folder not found.');
|
|
78
|
+
const listing = await drive.list(folder.relativePath);
|
|
79
|
+
const existing = await Promise.all(listing.files.map((name) => definitionFromFile(drive, folder.relativePath, name)));
|
|
80
|
+
if (existing.some((definition) => definition?.name === body.name))
|
|
81
|
+
throw new ApiError(409, 'Job definition already exists.');
|
|
82
|
+
const id = newUuidV4();
|
|
83
|
+
const uri = `/jobDefinitions/definitions/${id}`;
|
|
84
|
+
const caller = callerId(request.subject);
|
|
85
|
+
const definition = {
|
|
86
|
+
id,
|
|
87
|
+
name: body.name,
|
|
88
|
+
type: body.type,
|
|
89
|
+
code: body.code,
|
|
90
|
+
parameters,
|
|
91
|
+
version: 1,
|
|
92
|
+
createdBy: caller,
|
|
93
|
+
modifiedBy: caller,
|
|
94
|
+
creationTimeStamp: EMULATED_NOW,
|
|
95
|
+
modifiedTimeStamp: EMULATED_NOW,
|
|
96
|
+
links: [
|
|
97
|
+
{
|
|
98
|
+
href: uri,
|
|
99
|
+
uri,
|
|
100
|
+
rel: 'self',
|
|
101
|
+
method: 'GET',
|
|
102
|
+
type: 'application/vnd.sas.job.definition'
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
};
|
|
106
|
+
await drive.save(`${folder.relativePath}/${fileName(id)}`.replace(/\/{2,}/g, '/'), JSON.stringify(definition));
|
|
107
|
+
return { status: 201, body: definition };
|
|
108
|
+
},
|
|
109
|
+
'GET /jobDefinitions/definitions/{}': async ({ services, params }) => {
|
|
110
|
+
const name = fileName(params.id);
|
|
111
|
+
if (!pattern.test(name))
|
|
112
|
+
throw new ApiError(404, 'Job definition not found.');
|
|
113
|
+
const nodes = allNodes((await services.drive.tree('/')).tree);
|
|
114
|
+
const node = nodes.find((item) => !item.isFolder && item.name === name);
|
|
115
|
+
const folder = node?.relativePath.slice(0, -(name.length + 1)) || '/';
|
|
116
|
+
const definition = node && (await definitionFromFile(services.drive, folder, name));
|
|
117
|
+
if (!definition)
|
|
118
|
+
throw new ApiError(404, 'Job definition not found.');
|
|
119
|
+
return { status: 200, body: definition };
|
|
120
|
+
}
|
|
121
|
+
};
|
|
@@ -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;AAgBD,eAAO,MAAM,wBAAwB,qSAC+P,CAAA;AAEpS,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CA+DzD,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"}
|
|
@@ -20,15 +20,8 @@ import { VIYA_OPERATIONS } from './declared.js';
|
|
|
20
20
|
* a second answer to the same question.
|
|
21
21
|
*/
|
|
22
22
|
const NEEDS_AUTH = 'The token endpoint is answered by the host that mounts the emulator, which owns the token port.';
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
* The deploy-and-run path is recorded - a service pack deploy creates a job
|
|
27
|
-
* definition and submits it - and this package answers the compute and content
|
|
28
|
-
* families, not that one. Saying so is the difference between a client learning
|
|
29
|
-
* what is missing and a client learning nothing.
|
|
30
|
-
*/
|
|
31
|
-
const NEEDS_JOBS = 'The emulator answers the compute and content families; the job definitions a deploy creates and the executions a run submits are not modelled yet.';
|
|
23
|
+
/** Definition storage is modelled separately from job execution. */
|
|
24
|
+
const NEEDS_JOBS = 'The emulator stores job definitions but does not model job executions.';
|
|
32
25
|
export const SESSION_VARIABLE_REFUSAL = 'GET /compute/sessions/{}/variables/{} is not emulated. The emulator does not model session variables; the client reads these only to log the pid of a job it is about to submit (SYSJOBID), and any name it asks for is refused here rather than answered with a value the emulator did not run.';
|
|
33
26
|
export const VIYA_OVERLAY = {
|
|
34
27
|
// answered here
|
|
@@ -66,19 +59,9 @@ export const VIYA_OVERLAY = {
|
|
|
66
59
|
'PATCH /files/files/{}': { implemented: true },
|
|
67
60
|
'GET /files/files/{}/content': { implemented: true },
|
|
68
61
|
'PUT /files/files/{}/content': { implemented: true },
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// the emulator does not answer that path yet: a client that deploys a service
|
|
73
|
-
// pack against an emulated estate stops here, with a reason rather than a 404.
|
|
74
|
-
'POST /jobDefinitions/definitions': {
|
|
75
|
-
implemented: false,
|
|
76
|
-
reason: NEEDS_JOBS
|
|
77
|
-
},
|
|
78
|
-
'GET /jobDefinitions/definitions/{}': {
|
|
79
|
-
implemented: false,
|
|
80
|
-
reason: NEEDS_JOBS
|
|
81
|
-
},
|
|
62
|
+
// Definition persistence does not implement job execution.
|
|
63
|
+
'POST /jobDefinitions/definitions': { implemented: true },
|
|
64
|
+
'GET /jobDefinitions/definitions/{}': { implemented: true },
|
|
82
65
|
'POST /jobExecution/jobs': { implemented: false, reason: NEEDS_JOBS },
|
|
83
66
|
'GET /jobExecution/jobs/{}': { implemented: false, reason: NEEDS_JOBS },
|
|
84
67
|
'GET /jobExecution/jobs/{}/state': { implemented: false, reason: NEEDS_JOBS },
|
package/build/esm/viya/seed.d.ts
CHANGED
|
@@ -70,6 +70,20 @@ export interface ViyaSeedSettings {
|
|
|
70
70
|
serverUrl?: string;
|
|
71
71
|
/** Runs a submitted program, when the host has an engine. */
|
|
72
72
|
execute?: ViyaExecutor['execute'];
|
|
73
|
+
/**
|
|
74
|
+
* Trusted host capability for folder member discovery only. Set to false
|
|
75
|
+
* when the caller lacks permission to read job-definition files. Reserved
|
|
76
|
+
* definition filenames are hidden without reading them. Omitted preserves
|
|
77
|
+
* the historical metadata-discovery behaviour. Never populate from a request.
|
|
78
|
+
*/
|
|
79
|
+
readJobDefinitionMetadata?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Trusted host opt-in for isolated mocks only. The host must ensure that no
|
|
82
|
+
* other Drive mutations (including folder moves/deletes and definition
|
|
83
|
+
* creates) overlap a create, across all processes and store users. This flag
|
|
84
|
+
* provides no locking or transactional guarantees. Never set from a request.
|
|
85
|
+
*/
|
|
86
|
+
allowUntransactionalJobDefinitionCreation?: boolean;
|
|
73
87
|
/** Trusted host-only opt-in for a synthetic session SYSJOBID; never set from HTTP. */
|
|
74
88
|
mockSysjobid?: boolean;
|
|
75
89
|
}
|
|
@@ -1 +1 @@
|
|
|
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,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAA;IACpD,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,YAAY,CAAC,SAAS,CAAC,CAAA;IACjC,sFAAsF;IACtF,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,KAAK,MAAM,GAAG,SAAS,KAAG,MA+C5D,CAAA;AAED,8DAA8D;AAC9D,eAAO,MAAM,IAAI,GAAI,OAAO,MAAM,KAAG,MASpC,CAAA;AAED;;;;;;;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"}
|
|
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,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAA;IACpD,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,YAAY,CAAC,SAAS,CAAC,CAAA;IACjC;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAA;IACnC;;;;;OAKG;IACH,yCAAyC,CAAC,EAAE,OAAO,CAAA;IAEnD,sFAAsF;IACtF,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,KAAK,MAAM,GAAG,SAAS,KAAG,MA+C5D,CAAA;AAED,8DAA8D;AAC9D,eAAO,MAAM,IAAI,GAAI,OAAO,MAAM,KAAG,MASpC,CAAA;AAED;;;;;;;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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/viya/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/viya/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAgJnD,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,CAwV3B,CAAA"}
|
|
@@ -3,6 +3,7 @@ import { requireDrive } from './ports.js';
|
|
|
3
3
|
import { COMPUTE_HANDLERS } from './compute.js';
|
|
4
4
|
import { FILE_HANDLERS } from './files.js';
|
|
5
5
|
import { IDENTITY_HANDLERS } from './identity.js';
|
|
6
|
+
import { JOB_DEFINITION_HANDLERS, definitionFromFile, isJobDefinitionFileName } from './job-definitions.js';
|
|
6
7
|
import { idFor, normalisePath, EMULATED_NOW, EMULATED_USER, callerId } from './ids.js';
|
|
7
8
|
const linksFor = (uri, collection = false) => {
|
|
8
9
|
const self = {
|
|
@@ -86,18 +87,19 @@ const isRecycleBin = (uri) => !!uri &&
|
|
|
86
87
|
* opposite of "a client stores an id and asks for it later".
|
|
87
88
|
*/
|
|
88
89
|
const pathForId = async (drive, id) => {
|
|
89
|
-
const walk = (
|
|
90
|
-
if (
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
const walk = async (path) => {
|
|
91
|
+
if (idFor(path) === id)
|
|
92
|
+
return path;
|
|
93
|
+
const { folders } = await drive.list(path);
|
|
94
|
+
for (const name of folders) {
|
|
95
|
+
const child = path === '/' ? `/${name}` : `${path}/${name}`;
|
|
96
|
+
const hit = await walk(child);
|
|
97
|
+
if (hit !== undefined)
|
|
95
98
|
return hit;
|
|
96
99
|
}
|
|
97
100
|
return undefined;
|
|
98
101
|
};
|
|
99
|
-
const
|
|
100
|
-
const path = walk(tree);
|
|
102
|
+
const path = await walk('/');
|
|
101
103
|
if (!path)
|
|
102
104
|
throw new ApiError(404, `No folder matches the id ${id}. Ids are derived from paths, so an id that names no folder is one no folder ever had.`);
|
|
103
105
|
return path;
|
|
@@ -205,6 +207,10 @@ export const VIYA_HANDLERS = {
|
|
|
205
207
|
'GET /folders/folders/{}/members': async ({ services, params, request }) => {
|
|
206
208
|
const drive = requireDrive(services);
|
|
207
209
|
const limit = Number(request.query?.limit ?? 0) || 0;
|
|
210
|
+
const requestedStart = Number(request.query?.start ?? 0);
|
|
211
|
+
const start = Number.isSafeInteger(requestedStart) && requestedStart > 0
|
|
212
|
+
? requestedStart
|
|
213
|
+
: 0;
|
|
208
214
|
// the bin is not a folder in the drive, and its own body advertises this
|
|
209
215
|
// link - so a client following the answer it just received must not 404
|
|
210
216
|
if (params.id === idFor('@myRecycleBin'))
|
|
@@ -213,7 +219,7 @@ export const VIYA_HANDLERS = {
|
|
|
213
219
|
body: {
|
|
214
220
|
accept: 'application/json',
|
|
215
221
|
name: 'members',
|
|
216
|
-
start
|
|
222
|
+
start,
|
|
217
223
|
// the query value is echoed as the sibling branch echoes it: a caller
|
|
218
224
|
// that asked for five and is told zero cannot tell what happened
|
|
219
225
|
limit,
|
|
@@ -226,6 +232,11 @@ export const VIYA_HANDLERS = {
|
|
|
226
232
|
const path = await pathForId(drive, params.id);
|
|
227
233
|
const listing = await drive.list(path);
|
|
228
234
|
const caller = callerId(request.subject);
|
|
235
|
+
const canReadMetadata = services.viya?.readJobDefinitionMetadata !== false;
|
|
236
|
+
const definitions = canReadMetadata
|
|
237
|
+
? await Promise.all(listing.files.map((name) => definitionFromFile(drive, path, name)))
|
|
238
|
+
: [];
|
|
239
|
+
const definitionByFile = new Map(listing.files.map((name, index) => [name, definitions[index]]));
|
|
229
240
|
/**
|
|
230
241
|
* A member's `uri` is the resource, not its path.
|
|
231
242
|
*
|
|
@@ -249,7 +260,10 @@ export const VIYA_HANDLERS = {
|
|
|
249
260
|
uri: `/folders/folders/${idFor(`${path}/${name}`.replace(/\/{2,}/g, '/'))}`,
|
|
250
261
|
links: linksFor(`/folders/folders/${idFor(`${path}/${name}`.replace(/\/{2,}/g, '/'))}`)
|
|
251
262
|
})),
|
|
252
|
-
...listing.files
|
|
263
|
+
...listing.files
|
|
264
|
+
.filter((name) => !definitionByFile.get(name) &&
|
|
265
|
+
(canReadMetadata || !isJobDefinitionFileName(name)))
|
|
266
|
+
.map((name) => ({
|
|
253
267
|
id: idFor(`${path}/${name}`.replace(/\/{2,}/g, '/'), 'file'),
|
|
254
268
|
name,
|
|
255
269
|
type: 'file',
|
|
@@ -263,9 +277,39 @@ export const VIYA_HANDLERS = {
|
|
|
263
277
|
added: EMULATED_NOW,
|
|
264
278
|
uri: `/files/files/${idFor(`${path}/${name}`.replace(/\/{2,}/g, '/'), 'file')}`,
|
|
265
279
|
links: linksFor(`/files/files/${idFor(`${path}/${name}`.replace(/\/{2,}/g, '/'), 'file')}`)
|
|
266
|
-
}))
|
|
280
|
+
})),
|
|
281
|
+
...definitions
|
|
282
|
+
.filter((definition) => definition !== undefined)
|
|
283
|
+
.map((definition) => {
|
|
284
|
+
const uri = `/jobDefinitions/definitions/${definition.id}`;
|
|
285
|
+
return {
|
|
286
|
+
id: definition.id,
|
|
287
|
+
name: definition.name,
|
|
288
|
+
// The captured member identifies its relationship separately from
|
|
289
|
+
// the resource kind. Other links remain emulated, not estate parity.
|
|
290
|
+
type: 'child',
|
|
291
|
+
contentType: 'jobDefinition',
|
|
292
|
+
version: 1,
|
|
293
|
+
createdBy: definition.createdBy,
|
|
294
|
+
modifiedBy: definition.modifiedBy,
|
|
295
|
+
creationTimeStamp: definition.creationTimeStamp,
|
|
296
|
+
modifiedTimeStamp: definition.modifiedTimeStamp,
|
|
297
|
+
parentFolderUri: `/folders/folders/${idFor(path)}`,
|
|
298
|
+
added: definition.creationTimeStamp,
|
|
299
|
+
uri,
|
|
300
|
+
links: [
|
|
301
|
+
{
|
|
302
|
+
href: uri,
|
|
303
|
+
uri,
|
|
304
|
+
rel: 'getResource',
|
|
305
|
+
method: 'GET',
|
|
306
|
+
type: 'application/vnd.sas.summary'
|
|
307
|
+
}
|
|
308
|
+
]
|
|
309
|
+
};
|
|
310
|
+
})
|
|
267
311
|
];
|
|
268
|
-
const page = limit > 0 ? items.slice(
|
|
312
|
+
const page = limit > 0 ? items.slice(start, start + limit) : items.slice(start);
|
|
269
313
|
// the envelope is what the capture recorded, including the paging fields a
|
|
270
314
|
// client reads to decide whether to ask for more
|
|
271
315
|
return {
|
|
@@ -273,7 +317,7 @@ export const VIYA_HANDLERS = {
|
|
|
273
317
|
body: {
|
|
274
318
|
accept: 'application/json',
|
|
275
319
|
name: 'members',
|
|
276
|
-
start
|
|
320
|
+
start,
|
|
277
321
|
limit: limit || page.length,
|
|
278
322
|
count: page.length,
|
|
279
323
|
version: 2,
|
|
@@ -338,5 +382,6 @@ export const VIYA_HANDLERS = {
|
|
|
338
382
|
},
|
|
339
383
|
...COMPUTE_HANDLERS,
|
|
340
384
|
...FILE_HANDLERS,
|
|
341
|
-
...IDENTITY_HANDLERS
|
|
385
|
+
...IDENTITY_HANDLERS,
|
|
386
|
+
...JOB_DEFINITION_HANDLERS
|
|
342
387
|
};
|
package/package.json
CHANGED