@sasjs/api 0.51.0 → 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.
@@ -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
- * The job family is a capture without a handler.
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
- // declined: the job family needs a job service
70
- //
71
- // A capture describes what the estate answers on the deploy-and-run path, and
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 },
@@ -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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,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;AAkJnD,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,CAoS3B,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 = (node) => {
90
- if (node.isFolder && idFor(node.relativePath) === id)
91
- return node.relativePath;
92
- for (const child of node.children) {
93
- const hit = walk(child);
94
- if (hit)
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 { tree } = await drive.tree('/');
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: 0,
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.map((name) => ({
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(0, limit) : items;
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: 0,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sasjs/api",
3
- "version": "0.51.0",
3
+ "version": "0.52.0",
4
4
  "description": "The SASjs Server API, described once - a generated route table, the services behind it, and the conformance corpus both hosts run",
5
5
  "license": "MIT",
6
6
  "author": "SASjs",