@sasjs/adapter 4.2.3 → 4.3.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 CHANGED
@@ -153,6 +153,14 @@ The response object will contain returned tables and columns. Table names are a
153
153
 
154
154
  The adapter will also cache the logs (if debug enabled) and even the work tables. For performance, it is best to keep debug mode off.
155
155
 
156
+ ### Session Manager
157
+
158
+ To execute a script on Viya a session has to be created first which is time-consuming (~15sec). That is why a Session Manager has been created which is implementing the following logic:
159
+
160
+ 1. When the first session is requested, we also create one more session (hot session) for future requests. Please notice two pending POST requests to create a session within the same context: ![the first session request](./screenshots/session-manager-first-request.png)
161
+ 2. When a subsequent request for a session is received and there is a hot session available (not expired), this session is returned and an asynchronous request to create another hot session is sent. Please notice that there is a pending POST request to create a new session while a job has been already finished execution (POST request with status 201): ![subsequent session request](./screenshots/subsequent-session-request.png)
162
+ 3. When a subsequent request for a session is received and there is no available hot session, 2 requests are sent asynchronously to create a session. The first created session will be returned and another session will be reserved for future requests.
163
+
156
164
  ### Variable Types
157
165
 
158
166
  The SAS type (char/numeric) of the values is determined according to a set of rules:
@@ -8,18 +8,104 @@ export declare class SessionManager {
8
8
  constructor(serverUrl: string, contextName: string, requestClient: RequestClient);
9
9
  private sessions;
10
10
  private currentContext;
11
+ private settingContext;
11
12
  private _debug;
12
13
  private printedSessionState;
13
14
  get debug(): boolean;
14
15
  set debug(value: boolean);
15
- getSession(accessToken?: string): Promise<Session | undefined>;
16
+ /**
17
+ * Checks if session is valid. Session is considered valid if time since it's creation is less than 'sessionInactiveTimeout' attribute.
18
+ * @param session - session object.
19
+ * @returns - boolean indicating if session is valid.
20
+ */
21
+ private isSessionValid;
22
+ /**
23
+ * Removes session from pool of hot sessions.
24
+ * @param session - session object.
25
+ * @returns - void.
26
+ */
27
+ private removeSessionFromPool;
28
+ /**
29
+ * Filters session pool to keep only valid sessions.
30
+ * @param session - session object.
31
+ * @returns - void.
32
+ */
33
+ private removeExpiredSessions;
34
+ /**
35
+ * Throws set of errors as a single error.
36
+ * @param errors - array of errors or string.
37
+ * @param prefix - an optional final error prefix.
38
+ * @returns - never.
39
+ */
40
+ private throwErrors;
41
+ /**
42
+ * Returns session.
43
+ * If there is a hot session available, it will be returned immediately and an asynchronous request to create new hot session will be submitted.
44
+ * If there is no available session, 2 session creation requests will be submitted. The session is returned once it is created and ready.
45
+ * @param accessToken - an optional access token.
46
+ * @returns - a promise which resolves with a session.
47
+ */
48
+ getSession(accessToken?: string): Promise<Session>;
49
+ /**
50
+ * Returns error message based on the response from SAS API.
51
+ * @param err - an optional access token.
52
+ * @param accessToken - an optional access token.
53
+ * @returns - an error message.
54
+ */
55
+ private getErrorMessage;
56
+ /**
57
+ * Deletes session.
58
+ * @param id - a session id.
59
+ * @param accessToken - an optional access token.
60
+ * @returns - a promise which resolves when session is deleted.
61
+ */
16
62
  clearSession(id: string, accessToken?: string): Promise<void>;
63
+ /**
64
+ * Creates sessions in amount equal to MAX_SESSION_COUNT.
65
+ * @param accessToken - an optional access token.
66
+ * @returns - a promise which resolves when required amount of sessions is created.
67
+ */
17
68
  private createSessions;
69
+ /**
70
+ * Waits for the current context to be set.
71
+ * @returns - a promise which resolves when current context is set.
72
+ */
73
+ private waitForCurrentContext;
74
+ /**
75
+ * Creates and waits for session to be ready.
76
+ * @param accessToken - an optional access token.
77
+ * @returns - a promise which resolves with a session.
78
+ */
18
79
  private createAndWaitForSession;
80
+ /**
81
+ * Sets current context.
82
+ * @param accessToken - an optional access token.
83
+ * @returns - a promise which resolves when current context is set.
84
+ */
19
85
  private setCurrentContext;
20
- private getHeaders;
86
+ /**
87
+ * Waits for session to be ready.
88
+ * @param session - a session object.
89
+ * @param etag - an etag that can be a string or null.
90
+ * @param accessToken - an optional access token.
91
+ * @returns - a promise which resolves with a session state.
92
+ */
21
93
  private waitForSession;
94
+ /**
95
+ * Gets session state.
96
+ * @param url - a URL to get session state.
97
+ * @param etag - an etag string.
98
+ * @param accessToken - an optional access token.
99
+ * @returns - a promise which resolves with a result string and response status.
100
+ */
22
101
  private getSessionState;
102
+ /**
103
+ * Gets variable.
104
+ * @param sessionId - a session id.
105
+ * @param variable - a variable string.
106
+ * @param accessToken - an optional access token.
107
+ * @returns - a promise which resolves with a result that confirms to SessionVariable interface, etag string and status code.
108
+ */
23
109
  getVariable(sessionId: string, variable: string, accessToken?: string): Promise<{
24
110
  result: SessionVariable;
25
111
  etag: string;