@sasjs/api 0.33.0 → 0.36.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 (63) hide show
  1. package/build/browser.js +2452 -50
  2. package/build/cjs/corpus/viya/operations.js +647 -0
  3. package/build/cjs/index.js +60 -40
  4. package/build/cjs/viya/compute.js +223 -0
  5. package/build/cjs/viya/dispatch.js +141 -0
  6. package/build/cjs/viya/files.js +199 -0
  7. package/build/cjs/viya/ids.js +60 -0
  8. package/build/cjs/viya/overlay.js +79 -0
  9. package/build/cjs/viya/ports.js +5 -0
  10. package/build/cjs/viya/seed.js +120 -0
  11. package/build/cjs/viya/service.js +283 -0
  12. package/build/cjs/viya/sessions.js +114 -0
  13. package/build/cjs/viya/surface.js +1 -49
  14. package/build/cjs/viya/table.js +805 -0
  15. package/build/cjs/viya/unrecorded.js +58 -0
  16. package/build/cjs/viya/version.js +43 -0
  17. package/build/esm/corpus/viya/operations.d.ts +28 -0
  18. package/build/esm/corpus/viya/operations.d.ts.map +1 -0
  19. package/build/esm/corpus/viya/operations.js +644 -0
  20. package/build/esm/host/dispatch.d.ts +10 -0
  21. package/build/esm/host/dispatch.d.ts.map +1 -1
  22. package/build/esm/index.d.ts +12 -0
  23. package/build/esm/index.d.ts.map +1 -1
  24. package/build/esm/index.js +7 -0
  25. package/build/esm/viya/compute.d.ts +39 -0
  26. package/build/esm/viya/compute.d.ts.map +1 -0
  27. package/build/esm/viya/compute.js +219 -0
  28. package/build/esm/viya/dispatch.d.ts +35 -0
  29. package/build/esm/viya/dispatch.d.ts.map +1 -0
  30. package/build/esm/viya/dispatch.js +136 -0
  31. package/build/esm/viya/files.d.ts +33 -0
  32. package/build/esm/viya/files.d.ts.map +1 -0
  33. package/build/esm/viya/files.js +196 -0
  34. package/build/esm/viya/ids.d.ts +35 -0
  35. package/build/esm/viya/ids.d.ts.map +1 -0
  36. package/build/esm/viya/ids.js +55 -0
  37. package/build/esm/viya/overlay.d.ts +25 -0
  38. package/build/esm/viya/overlay.d.ts.map +1 -0
  39. package/build/esm/viya/overlay.js +75 -0
  40. package/build/esm/viya/ports.d.ts +12 -0
  41. package/build/esm/viya/ports.d.ts.map +1 -0
  42. package/build/esm/viya/ports.js +1 -0
  43. package/build/esm/viya/seed.d.ts +60 -0
  44. package/build/esm/viya/seed.d.ts.map +1 -0
  45. package/build/esm/viya/seed.js +111 -0
  46. package/build/esm/viya/service.d.ts +28 -0
  47. package/build/esm/viya/service.d.ts.map +1 -0
  48. package/build/esm/viya/service.js +280 -0
  49. package/build/esm/viya/sessions.d.ts +63 -0
  50. package/build/esm/viya/sessions.d.ts.map +1 -0
  51. package/build/esm/viya/sessions.js +108 -0
  52. package/build/esm/viya/surface.d.ts.map +1 -1
  53. package/build/esm/viya/surface.js +1 -49
  54. package/build/esm/viya/table.d.ts +39 -0
  55. package/build/esm/viya/table.d.ts.map +1 -0
  56. package/build/esm/viya/table.js +802 -0
  57. package/build/esm/viya/unrecorded.d.ts +24 -0
  58. package/build/esm/viya/unrecorded.d.ts.map +1 -0
  59. package/build/esm/viya/unrecorded.js +55 -0
  60. package/build/esm/viya/version.d.ts +37 -0
  61. package/build/esm/viya/version.d.ts.map +1 -0
  62. package/build/esm/viya/version.js +39 -0
  63. package/package.json +5 -2
@@ -0,0 +1,196 @@
1
+ import { ApiError } from '../types.js';
2
+ import { requireDrive } from './ports.js';
3
+ import { EMULATED_NOW, EMULATED_USER, idFor } from './ids.js';
4
+ const contentTypeOf = (name) => {
5
+ if (/\.sas$/i.test(name))
6
+ return 'text/plain';
7
+ if (/\.(json)$/i.test(name))
8
+ return 'application/json';
9
+ if (/\.(csv|txt|log)$/i.test(name))
10
+ return 'text/plain';
11
+ if (/\.(html?)$/i.test(name))
12
+ return 'text/html';
13
+ if (/\.(png)$/i.test(name))
14
+ return 'image/png';
15
+ if (/\.(jpe?g)$/i.test(name))
16
+ return 'image/jpeg';
17
+ return 'application/octet-stream';
18
+ };
19
+ /**
20
+ * What the estate records about a file.
21
+ *
22
+ * `properties` carries the five keys the capture recorded, with the values a
23
+ * client reads rather than placeholders: the three `content.*` flags say what can
24
+ * be done with the file, and `typeRegistrant` says who registered the type.
25
+ */
26
+ const fileBody = (file) => {
27
+ const id = idFor(file.path, 'file');
28
+ const uri = `/files/files/${id}`;
29
+ const contentType = contentTypeOf(file.name);
30
+ return {
31
+ id,
32
+ name: file.name,
33
+ contentType,
34
+ contentDisposition: `attachment; filename="${file.name}"`,
35
+ encoding: 'UTF-8',
36
+ size: file.size,
37
+ fileStatus: 'complete',
38
+ fileVersion: 1,
39
+ version: 2,
40
+ typeDefName: 'file',
41
+ createdBy: EMULATED_USER.id,
42
+ modifiedBy: EMULATED_USER.id,
43
+ creationTimeStamp: EMULATED_NOW,
44
+ modifiedTimeStamp: EMULATED_NOW,
45
+ quarantine: false,
46
+ searchable: true,
47
+ virusDetected: false,
48
+ urlDetected: false,
49
+ properties: {
50
+ 'content.download': 'true',
51
+ 'content.openInBrowser': 'true',
52
+ 'content.preview': 'false',
53
+ sasIconKey: 'file',
54
+ typeRegistrant: EMULATED_USER.id
55
+ },
56
+ links: [
57
+ {
58
+ href: uri,
59
+ uri,
60
+ rel: 'self',
61
+ method: 'GET',
62
+ type: 'application/vnd.sas.file'
63
+ },
64
+ {
65
+ href: `${uri}/content`,
66
+ uri: `${uri}/content`,
67
+ rel: 'content',
68
+ method: 'GET',
69
+ type: 'application/vnd.sas.file.content'
70
+ }
71
+ ]
72
+ };
73
+ };
74
+ /**
75
+ * The bytes in a string, counted rather than measured.
76
+ *
77
+ * `Buffer.byteLength` is not available in the browser build, and the number this
78
+ * returns is the size a client sees, so it has to be right for non-ASCII too.
79
+ */
80
+ const utf8Length = (text) => {
81
+ let bytes = 0;
82
+ for (const character of text) {
83
+ const point = character.codePointAt(0);
84
+ bytes += point < 0x80 ? 1 : point < 0x800 ? 2 : point < 0x10000 ? 3 : 4;
85
+ }
86
+ return bytes;
87
+ };
88
+ const sizeOf = (contents) => typeof contents === 'string' ? utf8Length(contents) : contents.byteLength;
89
+ /** Every file in the drive, as `path` and name. */
90
+ const filesIn = async (drive) => {
91
+ const walk = (node, found) => {
92
+ if (!node.isFolder)
93
+ found.push({ name: node.name, path: node.relativePath, size: 0 });
94
+ for (const child of node.children)
95
+ walk(child, found);
96
+ return found;
97
+ };
98
+ return walk((await drive.tree('/')).tree, []);
99
+ };
100
+ /**
101
+ * The path a file id names, or the 404 a client with a stale id expects.
102
+ *
103
+ * Resolved against the drive rather than remembered in a map: a rename changes the
104
+ * path and therefore the id, and a map would keep answering for the old one.
105
+ */
106
+ const pathForFileId = async (drive, id) => {
107
+ const file = (await filesIn(drive)).find((candidate) => idFor(candidate.path, 'file') === id);
108
+ if (!file)
109
+ throw new ApiError(404, `File with ID '${id}' was not found.`);
110
+ return file.path;
111
+ };
112
+ const bodyOf = async (drive, path) => {
113
+ const read = await drive.read(path);
114
+ return {
115
+ name: path.split('/').pop(),
116
+ path,
117
+ size: sizeOf(read.contents)
118
+ };
119
+ };
120
+ /** The parent folder a request names, or the root it means by its absence. */
121
+ const parentOf = async (drive, uri) => {
122
+ if (!uri)
123
+ return '/';
124
+ const id = uri.split('/').pop();
125
+ const tree = await drive.tree('/');
126
+ const walk = (node) => {
127
+ if (node.isFolder && idFor(node.relativePath, 'folder') === id)
128
+ return node.relativePath;
129
+ for (const child of node.children) {
130
+ const hit = walk(child);
131
+ if (hit !== undefined)
132
+ return hit;
133
+ }
134
+ return undefined;
135
+ };
136
+ const found = walk(tree.tree);
137
+ if (found === undefined)
138
+ throw new ApiError(404, `Folder with ID '${id}' was not found.`);
139
+ return found;
140
+ };
141
+ export const FILE_HANDLERS = {
142
+ 'POST /files/files': async ({ services, request }) => {
143
+ const drive = requireDrive(services);
144
+ const upload = request.file;
145
+ if (!upload?.name)
146
+ throw new ApiError(400, 'A file named `file` is required.');
147
+ const parent = await parentOf(drive, request.query?.parentFolderUri);
148
+ const path = `${parent}/${upload.name}`.replace(/\/{2,}/g, '/');
149
+ await drive.save(path, upload.contents);
150
+ return { status: 201, body: fileBody(await bodyOf(drive, path)) };
151
+ },
152
+ 'GET /files/files/{}': async ({ services, params }) => {
153
+ const drive = requireDrive(services);
154
+ const path = await pathForFileId(drive, params.id);
155
+ return { status: 200, body: fileBody(await bodyOf(drive, path)) };
156
+ },
157
+ 'PATCH /files/files/{}': async ({ services, params, request }) => {
158
+ const drive = requireDrive(services);
159
+ const path = await pathForFileId(drive, params.id);
160
+ const body = (request.body ?? {});
161
+ const name = body.name ?? path.split('/').pop();
162
+ const target = `${path.split('/').slice(0, -1).join('/')}/${name}`.replace(/\/{2,}/g, '/');
163
+ if (target !== path)
164
+ await drive.rename(path, target);
165
+ return { status: 200, body: fileBody(await bodyOf(drive, target)) };
166
+ },
167
+ 'GET /files/files/{}/content': async ({ services, params }) => {
168
+ const drive = requireDrive(services);
169
+ const path = await pathForFileId(drive, params.id);
170
+ const read = await drive.read(path);
171
+ // `contents`, not `body`: ApiResponse reserves that field for a raw body,
172
+ // e.g. the driver route that answers with the file itself. A host that maps
173
+ // `body` JSON-encodes the string and declares text/html over a quoted value.
174
+ return {
175
+ status: 200,
176
+ contents: read.contents,
177
+ headers: {
178
+ 'content-type': contentTypeOf(path.split('/').pop())
179
+ }
180
+ };
181
+ },
182
+ 'PUT /files/files/{}/content': async ({ services, params, request }) => {
183
+ const drive = requireDrive(services);
184
+ const path = await pathForFileId(drive, params.id);
185
+ // a host may hand the bytes over as the multipart part or as the body
186
+ const body = request.body;
187
+ const contents = request.file?.contents ??
188
+ (typeof body === 'string'
189
+ ? body
190
+ : body?.contents);
191
+ if (contents === undefined || contents === null)
192
+ throw new ApiError(400, 'File content is required.');
193
+ await drive.update(path, contents);
194
+ return { status: 200, body: fileBody(await bodyOf(drive, path)) };
195
+ }
196
+ };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The values that identify the emulated estate, in one place.
3
+ *
4
+ * They live apart from the handlers because two handler modules need them: the
5
+ * folder family derives a folder id, the compute family derives a context and a
6
+ * server id, and a module that imports the other's handler map to reach them
7
+ * would be a cycle.
8
+ */
9
+ /** The emulated clock: a fixed instant, so a body is reproducible. */
10
+ export declare const EMULATED_NOW = "2026-01-01T00:00:00.000Z";
11
+ /** The caller the emulated estate reports when a host does not name one. */
12
+ export declare const EMULATED_USER: {
13
+ id: string;
14
+ name: string;
15
+ };
16
+ /**
17
+ * A uuid shape from a string, deterministically.
18
+ *
19
+ * Two 32-bit FNV-1a passes give enough of a hash to fill a uuid's fields, and the
20
+ * version/variant nibbles are set so the result is a well-formed v4-shaped id.
21
+ * Collisions are possible in principle and irrelevant here: the id is a handle
22
+ * the emulator hands back, not a uniqueness guarantee.
23
+ */
24
+ export declare const idFor: (path: string, kind?: string) => string;
25
+ /**
26
+ * One folder path, however it was spelled.
27
+ *
28
+ * The adapter joins a root of '/' to a path of '/app' and sends '//app', which is
29
+ * a different string and - because an id is derived from the path - a different
30
+ * id. A client that then asks for that id is asking about a folder the drive does
31
+ * not have, so every path is collapsed to one spelling before anything derives
32
+ * from it.
33
+ */
34
+ export declare const normalisePath: (path: string) => string;
35
+ //# sourceMappingURL=ids.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../../src/viya/ids.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,sEAAsE;AACtE,eAAO,MAAM,YAAY,6BAA6B,CAAA;AAEtD,4EAA4E;AAC5E,eAAO,MAAM,aAAa;;;CAAiD,CAAA;AAE3E;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,GAAI,MAAM,MAAM,EAAE,aAAe,KAAG,MAyBrD,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,MAI5C,CAAA"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The values that identify the emulated estate, in one place.
3
+ *
4
+ * They live apart from the handlers because two handler modules need them: the
5
+ * folder family derives a folder id, the compute family derives a context and a
6
+ * server id, and a module that imports the other's handler map to reach them
7
+ * would be a cycle.
8
+ */
9
+ /** The emulated clock: a fixed instant, so a body is reproducible. */
10
+ export const EMULATED_NOW = '2026-01-01T00:00:00.000Z';
11
+ /** The caller the emulated estate reports when a host does not name one. */
12
+ export const EMULATED_USER = { id: 'emulated-user', name: 'Emulated User' };
13
+ /**
14
+ * A uuid shape from a string, deterministically.
15
+ *
16
+ * Two 32-bit FNV-1a passes give enough of a hash to fill a uuid's fields, and the
17
+ * version/variant nibbles are set so the result is a well-formed v4-shaped id.
18
+ * Collisions are possible in principle and irrelevant here: the id is a handle
19
+ * the emulator hands back, not a uniqueness guarantee.
20
+ */
21
+ export const idFor = (path, kind = 'folder') => {
22
+ const hash = (input, seed) => {
23
+ let value = seed;
24
+ for (let index = 0; index < input.length; index++) {
25
+ value ^= input.charCodeAt(index);
26
+ value = Math.imul(value, 16777619) >>> 0;
27
+ }
28
+ return value.toString(16).padStart(8, '0');
29
+ };
30
+ const raw = hash(`${kind}:${path}`, 2166136261) +
31
+ hash(`${kind}:${path}`, 2246822519) +
32
+ hash(`${kind}:${path}`, 3266489917) +
33
+ hash(`${kind}:${path}`, 668265263);
34
+ const hex = raw.slice(0, 32);
35
+ return [
36
+ hex.slice(0, 8),
37
+ hex.slice(8, 12),
38
+ `4${hex.slice(13, 16)}`,
39
+ `a${hex.slice(17, 20)}`,
40
+ hex.slice(20, 32)
41
+ ].join('-');
42
+ };
43
+ /**
44
+ * One folder path, however it was spelled.
45
+ *
46
+ * The adapter joins a root of '/' to a path of '/app' and sends '//app', which is
47
+ * a different string and - because an id is derived from the path - a different
48
+ * id. A client that then asks for that id is asking about a folder the drive does
49
+ * not have, so every path is collapsed to one spelling before anything derives
50
+ * from it.
51
+ */
52
+ export const normalisePath = (path) => {
53
+ const collapsed = `/${path}`.replace(/\/{2,}/g, '/');
54
+ return collapsed.length > 1 ? collapsed.replace(/\/+$/, '') : collapsed;
55
+ };
@@ -0,0 +1,25 @@
1
+ export interface ViyaOverlayEntry {
2
+ implemented: boolean;
3
+ /** Present when declined: what a caller is told, and why. */
4
+ reason?: string;
5
+ }
6
+ export declare const VIYA_OVERLAY: Record<string, ViyaOverlayEntry>;
7
+ /**
8
+ * Refuse an overlay and a table that do not describe the same operations.
9
+ *
10
+ * Both directions, because each covers a different mistake:
11
+ *
12
+ * - an entry the table does not have is a claim about a call no client makes,
13
+ * which is what a stale entry becomes when an operation is retired;
14
+ * - a row with no entry is a capture that landed without a decision. One loop
15
+ * is not enough: a re-capture that adds an operation would import cleanly and
16
+ * answer 501 at run time, and `dispatch.ts` says the overlay refuses exactly
17
+ * that.
18
+ *
19
+ * Called at import, and exported so the refusals themselves can be tested: a
20
+ * check that only runs on import is a check nothing can pin.
21
+ */
22
+ export declare const assertOverlayEntries: (overlay: Record<string, ViyaOverlayEntry>, operations?: Array<{
23
+ id: string;
24
+ }>) => void;
25
+ //# sourceMappingURL=overlay.d.ts.map
@@ -0,0 +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;AAYD,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CA8BzD,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,CAAc,KAC7C,IAcF,CAAA"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * What this package answers of the Viya table, and what it declines.
3
+ *
4
+ * `src/viya/table.ts` states what a capture observed. This file states the
5
+ * decision for each of those operations: a handler that answers it, or a reason
6
+ * that travels into the 501 body. Every row needs an entry, and importing this
7
+ * file throws if one is missing - the failure mode the route table already
8
+ * refuses, because a row with no decision reads exactly like a row that is about
9
+ * to be done.
10
+ *
11
+ * A declined row is not a TODO. The reason names what is missing, so a caller
12
+ * that reaches it learns why rather than that something is unimplemented.
13
+ */
14
+ import { VIYA_TABLE } from './table.js';
15
+ /**
16
+ * The token endpoint is the host's.
17
+ *
18
+ * A host that mounts the emulator owns the token port - it is the thing that
19
+ * issues what a client presents - so the emulator declines rather than inventing
20
+ * a second answer to the same question.
21
+ */
22
+ const NEEDS_AUTH = 'The token endpoint is answered by the host that mounts the emulator, which owns the token port.';
23
+ export const VIYA_OVERLAY = {
24
+ // answered here
25
+ 'POST /folders/folders': { implemented: true },
26
+ 'GET /folders/folders/{}': { implemented: true },
27
+ 'PATCH /folders/folders/{}': { implemented: true },
28
+ 'GET /folders/folders/{}/members': { implemented: true },
29
+ 'GET /folders/folders/@item': { implemented: true },
30
+ 'GET /folders/folders/@myRecycleBin': { implemented: true },
31
+ 'GET /identities/users/@currentUser': { implemented: true },
32
+ 'GET /types/types': { implemented: true },
33
+ // answered here: compute
34
+ 'GET /compute/contexts': { implemented: true },
35
+ 'POST /compute/contexts/{}/sessions': { implemented: true },
36
+ 'DELETE /compute/sessions/{}': { implemented: true },
37
+ 'POST /compute/sessions/{}/jobs': { implemented: true },
38
+ 'GET /compute/sessions/{}/jobs/{}': { implemented: true },
39
+ 'GET /compute/sessions/{}/jobs/{}/log/content': { implemented: true },
40
+ 'GET /compute/sessions/{}/jobs/{}/state': { implemented: true },
41
+ 'GET /compute/sessions/{}/state': { implemented: true },
42
+ // answered here: files
43
+ 'POST /files/files': { implemented: true },
44
+ 'GET /files/files/{}': { implemented: true },
45
+ 'PATCH /files/files/{}': { implemented: true },
46
+ 'GET /files/files/{}/content': { implemented: true },
47
+ 'PUT /files/files/{}/content': { implemented: true },
48
+ // declined: the host owns the token port
49
+ 'POST /SASLogon/oauth/token': { implemented: false, reason: NEEDS_AUTH }
50
+ };
51
+ /**
52
+ * Refuse an overlay and a table that do not describe the same operations.
53
+ *
54
+ * Both directions, because each covers a different mistake:
55
+ *
56
+ * - an entry the table does not have is a claim about a call no client makes,
57
+ * which is what a stale entry becomes when an operation is retired;
58
+ * - a row with no entry is a capture that landed without a decision. One loop
59
+ * is not enough: a re-capture that adds an operation would import cleanly and
60
+ * answer 501 at run time, and `dispatch.ts` says the overlay refuses exactly
61
+ * that.
62
+ *
63
+ * Called at import, and exported so the refusals themselves can be tested: a
64
+ * check that only runs on import is a check nothing can pin.
65
+ */
66
+ export const assertOverlayEntries = (overlay, operations = VIYA_TABLE) => {
67
+ const known = new Set(operations.map((operation) => operation.id));
68
+ for (const id of Object.keys(overlay))
69
+ if (!known.has(id))
70
+ throw new Error(`src/viya/overlay.ts names an operation the table does not have: ${id}. The table is generated from a capture, so an entry for an operation nobody observed is a claim about a call no client makes.`);
71
+ for (const operation of operations)
72
+ if (!(operation.id in overlay))
73
+ throw new Error(`src/viya/overlay.ts has no decision for ${operation.id}. Every captured operation states whether this package implements it and, when it does not, the reason it does not: add \`{ implemented: false, reason: '...' }\` until a handler exists.`);
74
+ };
75
+ assertOverlayEntries(VIYA_OVERLAY);
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The ports the emulated handlers read, in one place.
3
+ *
4
+ * `drive` is required on `Services`, so there is no absent case to answer: a host
5
+ * that mounts the emulator has one, and a `501` for a missing drive would be a
6
+ * branch nothing can reach. It lives here rather than in a handler module because
7
+ * two of them read it, and importing one handler map from the other is a cycle.
8
+ */
9
+ import type { Services } from '../host/dispatch.js';
10
+ import type { DriveService } from '../drive/service.js';
11
+ export declare const requireDrive: (services: Services) => DriveService;
12
+ //# sourceMappingURL=ports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../../src/viya/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAEvD,eAAO,MAAM,YAAY,GAAI,UAAU,QAAQ,KAAG,YAA8B,CAAA"}
@@ -0,0 +1 @@
1
+ export const requireDrive = (services) => services.drive;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * What the emulated estate derives its generated data from.
3
+ *
4
+ * The emulator cannot execute SAS, so any answer that a real engine would produce
5
+ * - a job log, a listing, a webout - is generated. Generated data is only useful
6
+ * if it is the same data twice: a screenshot taken after a build must still be
7
+ * true after the next one, and a fixture committed today must match the answer
8
+ * tomorrow.
9
+ *
10
+ * The seed is therefore the identity of the estate, and the identity of an estate
11
+ * is the address clients already use to reach it. A target that points at
12
+ * `http://localhost:5000` and a target that points at `http://127.0.0.1:5000` are
13
+ * the same estate spelled two ways, so the address is normalised before it is
14
+ * hashed - and `seed` exists for the two cases where the address is the wrong
15
+ * identity: the estate reached by a different hostname (a container name, a LAN
16
+ * address), and the port that moves between runs (CI picks an ephemeral one).
17
+ *
18
+ * Absent both, every emulated estate shares one seed. That is the only honest
19
+ * default: an emulator with no address has not told us which estate it is.
20
+ */
21
+ /** The seed every emulated estate falls back to. */
22
+ export declare const DEFAULT_SEED = "emulated";
23
+ export interface ViyaSeedSettings {
24
+ /** The address this estate answers at. */
25
+ serverUrl?: string;
26
+ /** Pins the generated data when the address is not the identity. */
27
+ seed?: string | number;
28
+ }
29
+ /**
30
+ * The address reduced to what identifies it.
31
+ *
32
+ * Lowercased host, no default port, no trailing slash, no path: `https://Viya.Example.com:443/SASDrive/`
33
+ * and `https://viya.example.com` are one estate, and a path is where a client
34
+ * lands rather than which server it is. A non-default port stays, because two
35
+ * emulators on one machine are two estates.
36
+ */
37
+ export declare const normaliseServerUrl: (url: string | undefined) => string;
38
+ /** A 32-bit FNV-1a hash, so one string becomes one number. */
39
+ export declare const hash: (input: string) => number;
40
+ /**
41
+ * The number that makes this estate's generated data reproducible.
42
+ *
43
+ * `seed` wins over the address when both are present: it is the override a host
44
+ * reaches for when the address disagrees with the estate, not a second opinion
45
+ * the address gets to overrule.
46
+ */
47
+ export declare const seedOf: (settings?: ViyaSeedSettings) => number;
48
+ /**
49
+ * A uniform generator over one seed (mulberry32).
50
+ *
51
+ * Every draw advances the same 32-bit state, so a sequence is a function of the
52
+ * seed alone - which is the whole point: the same estate answers the same way,
53
+ * and two estates answer differently.
54
+ */
55
+ export declare const generator: (seed: number) => (() => number);
56
+ /** An integer in `[0, bound)`, drawn from the generator. */
57
+ export declare const drawInt: (next: () => number, bound: number) => number;
58
+ /** A line from a list, drawn from the generator. */
59
+ export declare const drawFrom: <T>(next: () => number, values: T[]) => T;
60
+ //# sourceMappingURL=seed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../../src/viya/seed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,oDAAoD;AACpD,eAAO,MAAM,YAAY,aAAa,CAAA;AAEtC,MAAM,WAAW,gBAAgB;IAC/B,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,oEAAoE;IACpE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,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;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,GAAI,WAAU,gBAAqB,KAAG,MAOxD,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,CAAC,MAAM,MAAM,CAarD,CAAA;AAED,4DAA4D;AAC5D,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,MAAM,EAAE,OAAO,MAAM,KAAG,MAChC,CAAA;AAE5B,oDAAoD;AACpD,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,MAAM,MAAM,MAAM,EAAE,QAAQ,CAAC,EAAE,KAAG,CACxB,CAAA"}
@@ -0,0 +1,111 @@
1
+ /**
2
+ * What the emulated estate derives its generated data from.
3
+ *
4
+ * The emulator cannot execute SAS, so any answer that a real engine would produce
5
+ * - a job log, a listing, a webout - is generated. Generated data is only useful
6
+ * if it is the same data twice: a screenshot taken after a build must still be
7
+ * true after the next one, and a fixture committed today must match the answer
8
+ * tomorrow.
9
+ *
10
+ * The seed is therefore the identity of the estate, and the identity of an estate
11
+ * is the address clients already use to reach it. A target that points at
12
+ * `http://localhost:5000` and a target that points at `http://127.0.0.1:5000` are
13
+ * the same estate spelled two ways, so the address is normalised before it is
14
+ * hashed - and `seed` exists for the two cases where the address is the wrong
15
+ * identity: the estate reached by a different hostname (a container name, a LAN
16
+ * address), and the port that moves between runs (CI picks an ephemeral one).
17
+ *
18
+ * Absent both, every emulated estate shares one seed. That is the only honest
19
+ * default: an emulator with no address has not told us which estate it is.
20
+ */
21
+ /** The seed every emulated estate falls back to. */
22
+ export const DEFAULT_SEED = 'emulated';
23
+ /**
24
+ * The address reduced to what identifies it.
25
+ *
26
+ * Lowercased host, no default port, no trailing slash, no path: `https://Viya.Example.com:443/SASDrive/`
27
+ * and `https://viya.example.com` are one estate, and a path is where a client
28
+ * lands rather than which server it is. A non-default port stays, because two
29
+ * emulators on one machine are two estates.
30
+ */
31
+ export const normaliseServerUrl = (url) => {
32
+ if (!url)
33
+ return '';
34
+ const trimmed = url.trim();
35
+ if (!trimmed)
36
+ return '';
37
+ // parsed by hand rather than with `new URL`, because the browser build has no
38
+ // URL global and this module is part of it
39
+ const match = /^(?:([a-z][a-z0-9+.-]*):\/\/)?([^/?#]+)/i.exec(trimmed);
40
+ if (!match)
41
+ return trimmed.replace(/\/+$/, '').toLowerCase();
42
+ const scheme = (match[1] ?? 'http').toLowerCase();
43
+ let authority = match[2].toLowerCase();
44
+ const credentials = authority.lastIndexOf('@');
45
+ if (credentials >= 0)
46
+ authority = authority.slice(credentials + 1);
47
+ let host = authority;
48
+ let port = '';
49
+ if (authority.startsWith('[')) {
50
+ const close = authority.indexOf(']');
51
+ if (close >= 0) {
52
+ host = authority.slice(0, close + 1);
53
+ if (authority[close + 1] === ':')
54
+ port = authority.slice(close + 2);
55
+ }
56
+ }
57
+ else {
58
+ const colon = authority.lastIndexOf(':');
59
+ if (colon >= 0) {
60
+ host = authority.slice(0, colon);
61
+ port = authority.slice(colon + 1);
62
+ }
63
+ }
64
+ const isDefault = (scheme === 'http' && port === '80') ||
65
+ (scheme === 'https' && port === '443');
66
+ // a non-default port stays: two emulators on one machine are two estates
67
+ return `${scheme}://${host}${port && !isDefault ? `:${port}` : ''}`;
68
+ };
69
+ /** A 32-bit FNV-1a hash, so one string becomes one number. */
70
+ export const hash = (input) => {
71
+ let value = 2166136261;
72
+ for (let index = 0; index < input.length; index++) {
73
+ value ^= input.charCodeAt(index);
74
+ value = Math.imul(value, 16777619) >>> 0;
75
+ }
76
+ return value >>> 0;
77
+ };
78
+ /**
79
+ * The number that makes this estate's generated data reproducible.
80
+ *
81
+ * `seed` wins over the address when both are present: it is the override a host
82
+ * reaches for when the address disagrees with the estate, not a second opinion
83
+ * the address gets to overrule.
84
+ */
85
+ export const seedOf = (settings = {}) => {
86
+ if (settings.seed !== undefined && settings.seed !== '')
87
+ return hash(`seed:${settings.seed}`);
88
+ const address = normaliseServerUrl(settings.serverUrl);
89
+ return hash(`url:${address || DEFAULT_SEED}`);
90
+ };
91
+ /**
92
+ * A uniform generator over one seed (mulberry32).
93
+ *
94
+ * Every draw advances the same 32-bit state, so a sequence is a function of the
95
+ * seed alone - which is the whole point: the same estate answers the same way,
96
+ * and two estates answer differently.
97
+ */
98
+ export const generator = (seed) => {
99
+ let state = seed >>> 0;
100
+ return () => {
101
+ state = (state + 0x6d2b79f5) >>> 0;
102
+ let value = state;
103
+ value = Math.imul(value ^ (value >>> 15), value | 1);
104
+ value ^= value + Math.imul(value ^ (value >>> 7), value | 61);
105
+ return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
106
+ };
107
+ };
108
+ /** An integer in `[0, bound)`, drawn from the generator. */
109
+ export const drawInt = (next, bound) => Math.floor(next() * bound);
110
+ /** A line from a list, drawn from the generator. */
111
+ export const drawFrom = (next, values) => values[drawInt(next, values.length)];
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The Viya-shaped answers, built from the services the package already has.
3
+ *
4
+ * Each handler calls a port (`DriveService`, `IdentityService`) and returns the
5
+ * shape the capture recorded for that operation - the shape is in
6
+ * `src/viya/table.ts`, and the spec holds the two together. Nothing here
7
+ * re-implements a rule the SASjs API side already decides: a folder that does not
8
+ * exist is the drive's 404, and a path that climbs out of the root is the drive's
9
+ * refusal.
10
+ *
11
+ * Identifiers are derived from the path rather than minted, so the same folder is
12
+ * the same id on every host and every run. That is the seed rule applied to the
13
+ * one thing the emulator cannot invent per request: a client stores a folder id
14
+ * and asks for it later.
15
+ */
16
+ import type { ApiResponse, Services } from '../host/dispatch.js';
17
+ /** The handlers, keyed by the operation id the table states. */
18
+ export declare const VIYA_HANDLERS: Record<string, (context: {
19
+ services: Services;
20
+ request: {
21
+ query?: Record<string, string | undefined>;
22
+ body?: unknown;
23
+ token?: string;
24
+ subject?: unknown;
25
+ };
26
+ params: Record<string, string>;
27
+ }) => Promise<ApiResponse>>;
28
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/viya/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAmIhE,gEAAgE;AAChE,eAAO,MAAM,aAAa,EAAE,MAAM,CAChC,MAAM,EACN,CAAC,OAAO,EAAE;IACR,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,EAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;QAC1C,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,CAAA;IACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B,KAAK,OAAO,CAAC,WAAW,CAAC,CAgO3B,CAAA"}