@sasjs/core 7.1.6 → 7.1.8

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.
@@ -60,12 +60,15 @@
60
60
  outfile=0
61
61
  )/*/STORE SOURCE*/;
62
62
 
63
- %local inref dttm ds1;
63
+ %local inref dttm ds1 replen;
64
64
  %let inref=%mf_getuniquefileref();
65
65
  %let outref=%mf_getuniquefileref();
66
66
  %if &outfile=0 %then %let outfile=&infile;
67
67
  %let ds1=%mf_getuniquename(prefix=allchars);
68
68
  %let ds2=%mf_getuniquename(prefix=startmark);
69
+ /* a blank replacement is a deletion, so the length of the replacement is read
70
+ * once and the characters are simply dropped when it is empty */
71
+ %let replen=%length(%superq(&replacevar));
69
72
 
70
73
  /* START */
71
74
  %let dttm=%sysfunc(datetime());
@@ -136,12 +139,18 @@ run;
136
139
  filename &outref &outfile recfm=n;
137
140
 
138
141
  data _null_;
139
- length replace $ %length(%superq(&replacevar));
140
- replace=symget("&replacevar");
142
+ %if &replen>0 %then %do;
143
+ length replace $ &replen;
144
+ replace=symget("&replacevar");
145
+ %end;
141
146
  file &outref;
142
147
  do until(eof);
143
148
  set &ds1 end=eof;
144
- if strt ="1" then put replace char.;
149
+ if strt ="1" then do;
150
+ %if &replen>0 %then %do;
151
+ put replace char.;
152
+ %end;
153
+ end;
145
154
  else put sourcechar char1.;
146
155
  end;
147
156
  stop;
package/package.json CHANGED
@@ -22,6 +22,17 @@
22
22
  "release": {
23
23
  "branches": [
24
24
  "main"
25
+ ],
26
+ "plugins": [
27
+ "@semantic-release/commit-analyzer",
28
+ "@semantic-release/release-notes-generator",
29
+ [
30
+ "@semantic-release/npm",
31
+ {
32
+ "npmPublish": false
33
+ }
34
+ ],
35
+ "@semantic-release/github"
25
36
  ]
26
37
  },
27
38
  "publishConfig": {
@@ -43,5 +54,5 @@
43
54
  "devDependencies": {
44
55
  "@nogoo9/gitleaks": "8.30.1-post.2"
45
56
  },
46
- "version": "7.1.6"
57
+ "version": "7.1.8"
47
58
  }
@@ -89,6 +89,7 @@
89
89
  <h4> SAS Macros </h4>
90
90
  @li mp_abort.sas
91
91
  @li mp_binarycopy.sas
92
+ @li mp_replace.sas
92
93
  @li mf_getplatform.sas
93
94
  @li mf_existfileref.sas
94
95
  @li mf_getuniquefileref.sas
@@ -281,7 +282,60 @@ run;
281
282
  %mp_binarycopy(inref=&fname2,outref=&outref)
282
283
  %end;
283
284
  %if &outlib ne 0 %then %do;
284
- libname &outlib JSON fileref=&fname2;
285
+ /* A service run through Viya job execution wraps its response in the
286
+ * transport envelope (>>weboutBEGIN<< ... >>weboutEND<<) - that is what the
287
+ * client frames the response with. The text path in mx_execute strips it,
288
+ * but the JSON engine has no such step and rejects the marker on line one,
289
+ * which is why an aborted child's result looked unparsable when the abort
290
+ * object inside it was perfectly good.
291
+ *
292
+ * Detection is the strip: mp_replace copies a byte at a time, so the markers
293
+ * come out wherever they sit, and a smaller output than input is the answer
294
+ * to "was there an envelope". Probing the first record instead would miss a
295
+ * marker that is not in it, which is the failure this exists to remove,
296
+ * and a result without an envelope keeps the direct libname. */
297
+ %local path2 path3 begvar endvar nil fref3 fref4 fid size2 size4;
298
+ %let fref3=%mf_getuniquefileref();
299
+ %let fref4=%mf_getuniquefileref();
300
+ %let path2=%sysfunc(pathname(&fname2));
301
+ %let path3=%sysfunc(pathname(&fref3));
302
+ %let begvar=%str(>>weboutBEGIN<<);
303
+ %let endvar=%str(>>weboutEND<<);
304
+ %let nil=;
305
+ %mp_replace(infile="&path2",findvar=begvar,replacevar=nil
306
+ ,outfile="&path3")
307
+ %mp_replace(infile="&path3",findvar=endvar,replacevar=nil
308
+ ,outfile="%sysfunc(pathname(&fref4))")
309
+ /* a copy that could not be written is not an outcome: say so, rather than
310
+ * handing the engine an empty file and failing at the libname instead */
311
+ %if %sysfunc(fexist(&fref4)) ne 1 %then %do;
312
+ %mp_abort(mac=&sysmacroname
313
+ ,msg=%str(Unable to strip the result envelope for &uri)
314
+ )
315
+ %end;
316
+ %let fid=%sysfunc(fopen(&fname2));
317
+ %let size2=%sysfunc(finfo(&fid,File Size (bytes)));
318
+ %let fid=%sysfunc(fclose(&fid));
319
+ %let fid=%sysfunc(fopen(&fref4));
320
+ %let size4=%sysfunc(finfo(&fid,File Size (bytes)));
321
+ %let fid=%sysfunc(fclose(&fid));
322
+ %if &size4 < &size2 %then %do;
323
+ /* nothing but envelope is a real outcome - a service that aborted before
324
+ * writing anything - and becomes the empty object the not-found branch
325
+ * hands back, rather than an empty file the engine cannot open */
326
+ %if &size4=0 %then %do;
327
+ data _null_;
328
+ file &fref4;
329
+ put '{}';
330
+ run;
331
+ %end;
332
+ libname &outlib JSON fileref=&fref4;
333
+ %end;
334
+ %else %do;
335
+ libname &outlib JSON fileref=&fname2;
336
+ %end;
337
+ filename &fref3 clear;
338
+ filename &fref4 clear;
285
339
  %end;
286
340
 
287
341
  %if &mdebug=0 %then %do;
@@ -210,7 +210,7 @@ filename &webref "&webrefpath";
210
210
  /* proc stp gives no job status - say so rather than imply success */
211
211
  %if "&outstatus" ne "0" %then %do;
212
212
  data &outstatus;
213
- length state $20 uri $256 errmsg $256 platform $10;
213
+ length state $256 uri $256 errmsg $256 platform $10;
214
214
  state='unknown';
215
215
  uri='';
216
216
  errmsg='proc stp returns no job status';
@@ -311,7 +311,13 @@ filename &webref "&webrefpath";
311
311
  /* the outcome, before the flow table goes away */
312
312
  %if "&outstatus" ne "0" %then %do;
313
313
  data &outstatus;
314
- length state $20 uri $256 errmsg $32767 platform $10;
314
+ /* state is copied from the flow table, so this length is a ceiling, not a
315
+ * target. mp_init's strict set includes varlenchk=ERROR, so a shorter
316
+ * one fails the step outright: OBS=0 then switches the rest of
317
+ * the session to syntax check, and every later proc reports a problem
318
+ * that has nothing to do with it. 256 matches uri and covers a state
319
+ * read out of JSON. */
320
+ length state $256 uri $256 errmsg $32767 platform $10;
315
321
  platform='SASVIYA';
316
322
  errmsg='';
317
323
  set &jobds(keep=state uri);
@@ -363,7 +369,7 @@ filename &webref "&webrefpath";
363
369
  modify &outstatus;
364
370
  errmsg=symget('abortmsg');
365
371
  replace;
366
- end;
372
+ run;
367
373
  %end;
368
374
  %end;
369
375
  /* only a ref created here may be cleared */
@@ -393,7 +399,7 @@ filename &webref "&webrefpath";
393
399
  )
394
400
  %if "&outstatus" ne "0" %then %do;
395
401
  data &outstatus;
396
- length state $20 uri $256 errmsg $32767 platform $10;
402
+ length state $256 uri $256 errmsg $32767 platform $10;
397
403
  length line $32767;
398
404
  retain state 'completed' uri '' errmsg '' platform 'SASJS' abortseen 0;
399
405
  infile &respref end=eof lrecl=32767;