@sasjs/api 0.29.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/build/browser.js +559 -325
  2. package/build/cjs/appstream/service.js +48 -5
  3. package/build/cjs/appstream/web.js +7 -3
  4. package/build/cjs/corpus/app.js +55 -0
  5. package/build/cjs/corpus/runner.js +7 -6
  6. package/build/cjs/host/dispatch.js +71 -0
  7. package/build/cjs/index.js +9 -2
  8. package/build/cjs/routes/generated.js +34 -0
  9. package/build/cjs/routes/overlay.js +34 -1
  10. package/build/cjs/runtime/program.js +85 -0
  11. package/build/cjs/runtime/runTimes.js +13 -0
  12. package/build/cjs/runtime/service.js +11 -13
  13. package/build/esm/appstream/service.d.ts.map +1 -1
  14. package/build/esm/appstream/service.js +48 -5
  15. package/build/esm/appstream/web.d.ts.map +1 -1
  16. package/build/esm/appstream/web.js +7 -3
  17. package/build/esm/corpus/app.d.ts +17 -0
  18. package/build/esm/corpus/app.d.ts.map +1 -0
  19. package/build/esm/corpus/app.js +52 -0
  20. package/build/esm/corpus/runner.d.ts +13 -0
  21. package/build/esm/corpus/runner.d.ts.map +1 -1
  22. package/build/esm/corpus/runner.js +5 -4
  23. package/build/esm/host/dispatch.d.ts.map +1 -1
  24. package/build/esm/host/dispatch.js +72 -1
  25. package/build/esm/index.d.ts +5 -1
  26. package/build/esm/index.d.ts.map +1 -1
  27. package/build/esm/index.js +4 -1
  28. package/build/esm/routes/generated.d.ts.map +1 -1
  29. package/build/esm/routes/generated.js +34 -0
  30. package/build/esm/routes/overlay.d.ts.map +1 -1
  31. package/build/esm/routes/overlay.js +34 -1
  32. package/build/esm/runtime/program.d.ts +56 -0
  33. package/build/esm/runtime/program.d.ts.map +1 -0
  34. package/build/esm/runtime/program.js +79 -0
  35. package/build/esm/runtime/runTimes.d.ts +11 -0
  36. package/build/esm/runtime/runTimes.d.ts.map +1 -0
  37. package/build/esm/runtime/runTimes.js +10 -0
  38. package/build/esm/runtime/service.d.ts +0 -2
  39. package/build/esm/runtime/service.d.ts.map +1 -1
  40. package/build/esm/runtime/service.js +9 -11
  41. package/package.json +1 -1
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Finding the program a request names, once, for every host.
3
+ *
4
+ * `_program` is a path the caller chose, so two things have to be decided the same
5
+ * way in every host that runs one: that the path stays inside the drive, and which
6
+ * file and run time it actually names. The first is the host's - only it knows where
7
+ * its drive starts - and the second is this module's, because "try the extension the
8
+ * name states, otherwise `<path>.<runTime>` for each runtime in turn, otherwise the
9
+ * program does not exist" is the API's rule and not a host's preference.
10
+ *
11
+ * The host supplies three things: how to resolve a caller's path against its drive
12
+ * (answering `null` for a path that leaves it), whether a resolved path exists, and
13
+ * the run times it can offer. The extension vocabulary is not one of them - that is
14
+ * the document's, and `runTimeOfPath` reads it here. Nothing here touches a filesystem, a drive or a clock,
15
+ * so the browser host can answer with the same function over its own store.
16
+ */
17
+ import { ApiError } from '../types.js';
18
+ import { DOCUMENTED_RUN_TIMES } from './runTimes.js';
19
+ /**
20
+ * The detail a refusal carries, naming the path the caller gave.
21
+ *
22
+ * Exported because the runtime service renders the same condition the same way, and
23
+ * two copies of the sentence is how the two drift: the service's envelope states it as
24
+ * `error`, and this module states it as the message a host sends when it does not
25
+ * render an envelope at all.
26
+ */
27
+ export const programNotFound = (given) => `The Program at (${given}) does not exist.`;
28
+ /** The refusal, as this module decides it: the status and that detail. */
29
+ const notThere = (given) => new ApiError(400, programNotFound(given));
30
+ /**
31
+ * The run time a path's own name states, if it states one.
32
+ *
33
+ * The vocabulary is the document's (`DOCUMENTED_RUN_TIMES`), not a host's: a host
34
+ * that cannot run Python still reads `run.py` as Python and answers separately that
35
+ * it has no such run time. `run.sas7bdat` and `run.backup` name none, and are then
36
+ * probed like a path with no extension at all - which is what the server has always
37
+ * done.
38
+ *
39
+ * The extension is read below either separator, because the server runs on Windows
40
+ * too and resolves its paths with backslashes.
41
+ */
42
+ export const runTimeOfPath = (path) => {
43
+ const file = path.split(/[\\/]/).pop() || '';
44
+ const dot = file.lastIndexOf('.');
45
+ // a leading dot names no extension: `.sas` is a file, not a suffix
46
+ const extension = dot > 0 ? file.slice(dot + 1).toLowerCase() : '';
47
+ return DOCUMENTED_RUN_TIMES.includes(extension) ? extension : undefined;
48
+ };
49
+ /**
50
+ * The program and run time a request's `_program` names.
51
+ *
52
+ * The refusal is decided here - `400`, and the detail that names the path the caller
53
+ * gave - and *rendered* by whoever called this, because that is where the two hosts
54
+ * already differ: this package's runtime routes wrap it in the failed-run envelope
55
+ * (`{ status, message, error }`, pinned in `spec/runtime.spec.ts`), and a host that
56
+ * sends the message as text keeps sending it as text. Deciding the rendering here
57
+ * would change one host's answer on the way to unifying the rule, which is not what
58
+ * the seam is for.
59
+ */
60
+ export const resolveProgram = async (given, deps) => {
61
+ const resolved = deps.resolve(given);
62
+ if (resolved === null)
63
+ throw notThere(given);
64
+ const extension = runTimeOfPath(resolved);
65
+ if (extension !== undefined) {
66
+ // the name states its run time: no probing, and a file that is not there is
67
+ // refused even if `<path>.sas` happens to exist
68
+ if (await deps.exists(resolved))
69
+ return { path: resolved, runTime: extension };
70
+ }
71
+ else {
72
+ for (const runTime of deps.runTimes) {
73
+ const candidate = `${resolved}.${runTime}`;
74
+ if (await deps.exists(candidate))
75
+ return { path: candidate, runTime };
76
+ }
77
+ }
78
+ throw notThere(given);
79
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The run times the published document states.
3
+ *
4
+ * The vocabulary is the document's, not a host's: `_program=/app/run.py` names
5
+ * Python wherever it is read, and a host that cannot run Python says so when it is
6
+ * asked to - it does not get to say the name means something else. Kept in its own
7
+ * module so the runtime service and `resolveProgram` read one list rather than two
8
+ * copies of it.
9
+ */
10
+ export declare const DOCUMENTED_RUN_TIMES: string[];
11
+ //# sourceMappingURL=runTimes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runTimes.d.ts","sourceRoot":"","sources":["../../../src/runtime/runTimes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,UAAsC,CAAA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The run times the published document states.
3
+ *
4
+ * The vocabulary is the document's, not a host's: `_program=/app/run.py` names
5
+ * Python wherever it is read, and a host that cannot run Python says so when it is
6
+ * asked to - it does not get to say the name means something else. Kept in its own
7
+ * module so the runtime service and `resolveProgram` read one list rather than two
8
+ * copies of it.
9
+ */
10
+ export const DOCUMENTED_RUN_TIMES = ['sas', 'js', 'py', 'r', 'sasviya'];
@@ -16,8 +16,6 @@ import type { CallerDirectory, SessionArtifact } from '../session/service.js';
16
16
  * else.
17
17
  */
18
18
  export declare const CODE_DEBUG = 131;
19
- /** The run times the published document states, and a host may hold fewer. */
20
- export declare const DOCUMENTED_RUN_TIMES: string[];
21
19
  /**
22
20
  * `_debug`, normalised the way sasjs/server's `parseDebugValue` normalises it.
23
21
  *
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/runtime/service.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAsB,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAG7E;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,MAAM,CAAA;AAE7B,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB,UAAsC,CAAA;AAEvE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,MAAM,GAAG,SAUzD,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,MAAM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E,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,CAAA;IAC3C;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACnC;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,+DAA+D;IAC/D,OAAO,CACL,MAAM,EAAE,OAAO,GAAG,SAAS,EAC3B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC,CAAA;IAC3B,uEAAuE;IACvE,OAAO,CACL,MAAM,EAAE,OAAO,GAAG,SAAS,EAC3B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC,CAAA;CAC5B;AA0DD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAC/B,WAAW,eAAe,EAC1B,QAAQ,aAAa,EACrB,UAAS,qBAA0B,KAClC,cAqNF,CAAA"}
@@ -16,6 +16,8 @@
16
16
  * that would carry one carries it as optional.
17
17
  */
18
18
  import { ApiError } from '../types.js';
19
+ import { DOCUMENTED_RUN_TIMES } from './runTimes.js';
20
+ import { programNotFound, runTimeOfPath } from './program.js';
19
21
  import { normaliseDrivePath } from '../drive/paths.js';
20
22
  /**
21
23
  * The value that asks for the session log.
@@ -33,8 +35,6 @@ import { normaliseDrivePath } from '../drive/paths.js';
33
35
  * else.
34
36
  */
35
37
  export const CODE_DEBUG = 131;
36
- /** The run times the published document states, and a host may hold fewer. */
37
- export const DOCUMENTED_RUN_TIMES = ['sas', 'js', 'py', 'r', 'sasviya'];
38
38
  /**
39
39
  * `_debug`, normalised the way sasjs/server's `parseDebugValue` normalises it.
40
40
  *
@@ -85,7 +85,9 @@ const timestamp = (now) => [
85
85
  */
86
86
  const newSessionId = (now) => `${timestamp(now)}-${Math.round(Math.random() * 100000)}-${now.getTime()}`;
87
87
  /** The refusal a program that cannot be found answers, as the server words it. */
88
- const notThere = (programPath) => `The Program at (${programPath}) does not exist.`;
88
+ // the wording is `resolveProgram`'s, so the module that decides the rule and the
89
+ // route that renders it cannot drift apart
90
+ const notThere = (programPath) => programNotFound(programPath);
89
91
  /**
90
92
  * The failure a run that could not be performed answers.
91
93
  *
@@ -169,14 +171,10 @@ export const createRuntimeService = (directory, runner, options = {}) => {
169
171
  * Only the extension vocabulary the document states is read, so `run.sas7bdat`
170
172
  * or `run.backup` name no run time and are left to the host.
171
173
  */
172
- const runTimeForPath = (path, request) => {
173
- const file = path.split('/').pop() || '';
174
- const dot = file.lastIndexOf('.');
175
- const extension = dot > 0 ? file.slice(dot + 1).toLowerCase() : '';
176
- if (DOCUMENTED_RUN_TIMES.includes(extension))
177
- return extension;
178
- return runTimeOf(request);
179
- };
174
+ const runTimeForPath = (path, request) =>
175
+ // the extension rule is `resolveProgram`'s; this asks it and falls back to what
176
+ // the request stated, which is the part that is this route's
177
+ runTimeOfPath(path) ?? runTimeOf(request);
180
178
  /** The run time, refused when it is absent where the document requires it, or unheld. */
181
179
  const runTimeOf = (request) => {
182
180
  if (request.runTime === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sasjs/api",
3
- "version": "0.29.0",
3
+ "version": "0.31.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",