@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
package/build/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- /* @sasjs/api 0.33.0 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
1
+ /* @sasjs/api 0.36.0 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
2
2
  "use strict";
3
3
  var SASjsApi = (() => {
4
4
  var __defProp = Object.defineProperty;
@@ -46,6 +46,8 @@ var SASjsApi = (() => {
46
46
  DIRECTORY_CORPUS: () => DIRECTORY_CORPUS,
47
47
  DOCUMENTED_RUN_TIMES: () => DOCUMENTED_RUN_TIMES,
48
48
  DRIVE_CORPUS: () => DRIVE_CORPUS,
49
+ EMULATED_HEADER: () => EMULATED_HEADER,
50
+ EMULATED_HEADER_VALUE: () => EMULATED_HEADER_VALUE,
49
51
  HANDLED_ROUTES: () => HANDLED_ROUTES,
50
52
  HOME_CORPUS: () => HOME_CORPUS,
51
53
  IDENTITY_CORPUS: () => IDENTITY_CORPUS,
@@ -70,6 +72,13 @@ var SASjsApi = (() => {
70
72
  SURFACE_ADAPTER_VERSION: () => SURFACE_ADAPTER_VERSION,
71
73
  TAG_CAPABILITIES: () => TAG_CAPABILITIES,
72
74
  TOP_LEVEL_ROUTES: () => TOP_LEVEL_ROUTES,
75
+ UNRECORDED: () => UNRECORDED,
76
+ VIYA_CAPTURED_AT: () => VIYA_CAPTURED_AT,
77
+ VIYA_CORPUS: () => VIYA_CORPUS,
78
+ VIYA_HANDLERS: () => VIYA_HANDLERS,
79
+ VIYA_OVERLAY: () => VIYA_OVERLAY,
80
+ VIYA_TABLE: () => VIYA_TABLE,
81
+ VIYA_TARGET_VERSION: () => VIYA_TARGET_VERSION,
73
82
  appSummary: () => appSummary,
74
83
  basename: () => basename,
75
84
  cacheControlFor: () => cacheControlFor,
@@ -95,8 +104,11 @@ var SASjsApi = (() => {
95
104
  deployTree: () => deployTree,
96
105
  dirname: () => dirname,
97
106
  dispatch: () => dispatch,
107
+ dispatchViya: () => dispatchViya,
108
+ emulatedHeaders: () => emulatedHeaders,
98
109
  escapeHtml: () => escapeHtml,
99
110
  findRoute: () => findRoute,
111
+ findViyaOperation: () => findViyaOperation,
100
112
  hasBlockedExtension: () => hasBlockedExtension,
101
113
  isApiError: () => isApiError,
102
114
  isAppId: () => isAppId,
@@ -3209,35 +3221,11 @@ var SASjsApi = (() => {
3209
3221
  var SURFACE_ADAPTER_VERSION = "6.0.2";
3210
3222
  var SURFACE = [
3211
3223
  // sas9
3212
- {
3213
- path: "/Public/example/deleteThis",
3214
- family: "sas9",
3215
- decision: "declined",
3216
- reason: "a path in a doc example or a default config value, not a call"
3217
- },
3218
- {
3219
- path: "/Public/example/myFolder",
3220
- family: "sas9",
3221
- decision: "declined",
3222
- reason: "a path in a doc example or a default config value, not a call"
3223
- },
3224
- {
3225
- path: "/Public/newDestination",
3226
- family: "sas9",
3227
- decision: "declined",
3228
- reason: "a path in a doc example or a default config value, not a call"
3229
- },
3230
- {
3231
- path: "/Public/newDestination/myFolder",
3232
- family: "sas9",
3233
- decision: "declined",
3234
- reason: "a path in a doc example or a default config value, not a call"
3235
- },
3236
3224
  {
3237
3225
  path: "/Public/seedapp",
3238
3226
  family: "sas9",
3239
3227
  decision: "declined",
3240
- reason: "a path in a doc example or a default config value, not a call"
3228
+ reason: "a default config value the client falls back to, not a call"
3241
3229
  },
3242
3230
  {
3243
3231
  path: "/SASJobExecution",
@@ -3252,12 +3240,6 @@ var SASjsApi = (() => {
3252
3240
  decision: "in",
3253
3241
  reason: "the auth flow the client speaks, and the reason the emulated paths cannot be renamed"
3254
3242
  },
3255
- {
3256
- path: "/SASLogon/home",
3257
- family: "viya-auth",
3258
- decision: "in",
3259
- reason: "the auth flow the client speaks, and the reason the emulated paths cannot be renamed"
3260
- },
3261
3243
  {
3262
3244
  path: "/SASLogon/login",
3263
3245
  family: "viya-auth",
@@ -3320,12 +3302,6 @@ var SASjsApi = (() => {
3320
3302
  decision: "declined",
3321
3303
  reason: "the SASjs API surface, answered by the server's own registered routes, not by a Viya-shaped one"
3322
3304
  },
3323
- {
3324
- path: "/SASjsApi/{}",
3325
- family: "sasjs-api",
3326
- decision: "declined",
3327
- reason: "the SASjs API surface, answered by the server's own registered routes, not by a Viya-shaped one"
3328
- },
3329
3305
  // sas9
3330
3306
  {
3331
3307
  path: "/User Folders/{}/My Folder/sasjs/runner",
@@ -3334,18 +3310,6 @@ var SASjsApi = (() => {
3334
3310
  reason: "SAS 9 and SASjs surfaces: the emulator answers Viya, and the same client reaches these on an EBI deployment"
3335
3311
  },
3336
3312
  // sasjs-api
3337
- {
3338
- path: "/api",
3339
- family: "sasjs-api",
3340
- decision: "declined",
3341
- reason: "the SASjs API surface, answered by the server's own registered routes, not by a Viya-shaped one"
3342
- },
3343
- {
3344
- path: "/api/stp/execute",
3345
- family: "sasjs-api",
3346
- decision: "declined",
3347
- reason: "the SASjs API surface, answered by the server's own registered routes, not by a Viya-shaped one"
3348
- },
3349
3313
  {
3350
3314
  path: "/auth/refresh",
3351
3315
  family: "sasjs-api",
@@ -3564,6 +3528,2444 @@ var SASjsApi = (() => {
3564
3528
  }
3565
3529
  ];
3566
3530
 
3531
+ // src/viya/table.ts
3532
+ var VIYA_TABLE = [
3533
+ {
3534
+ id: "GET /compute/contexts",
3535
+ method: "GET",
3536
+ path: "/compute/contexts",
3537
+ steps: [
3538
+ "compute/context-by-name",
3539
+ "compute/contexts",
3540
+ "compute/execute-script",
3541
+ "compute/session-create"
3542
+ ],
3543
+ statuses: [200],
3544
+ queries: ["filter", "limit"],
3545
+ request: {
3546
+ queries: ["filter", "limit"],
3547
+ body: void 0
3548
+ },
3549
+ shape: {
3550
+ accept: "string",
3551
+ count: "number",
3552
+ items: [
3553
+ {
3554
+ createdBy: "string",
3555
+ id: "string",
3556
+ links: [
3557
+ {
3558
+ href: "string",
3559
+ method: "string",
3560
+ rel: "string",
3561
+ type: "string",
3562
+ uri: "string"
3563
+ }
3564
+ ],
3565
+ name: "string",
3566
+ version: "number"
3567
+ }
3568
+ ],
3569
+ limit: "number",
3570
+ links: [
3571
+ {
3572
+ href: "string",
3573
+ itemType: "string",
3574
+ method: "string",
3575
+ rel: "string",
3576
+ type: "string",
3577
+ uri: "string"
3578
+ }
3579
+ ],
3580
+ name: "string",
3581
+ start: "number",
3582
+ version: "number"
3583
+ }
3584
+ },
3585
+ {
3586
+ id: "POST /compute/contexts/{}/sessions",
3587
+ method: "POST",
3588
+ path: "/compute/contexts/{}/sessions",
3589
+ steps: ["compute/execute-script", "compute/session-create"],
3590
+ statuses: [201],
3591
+ queries: [],
3592
+ request: {
3593
+ queries: [],
3594
+ body: {}
3595
+ },
3596
+ shape: {
3597
+ applicationName: "string",
3598
+ attributes: {
3599
+ homeDirectory: "string",
3600
+ sessionInactiveTimeout: "number"
3601
+ },
3602
+ creationTimeStamp: "string",
3603
+ environment: {
3604
+ autoExecLines: ["string"]
3605
+ },
3606
+ id: "string",
3607
+ links: [
3608
+ {
3609
+ href: "string",
3610
+ method: "string",
3611
+ rel: "string",
3612
+ type: "string",
3613
+ uri: "string"
3614
+ }
3615
+ ],
3616
+ owner: "string",
3617
+ serverId: "string",
3618
+ serviceAPIVersion: "number",
3619
+ sessionConditionCode: "number",
3620
+ state: "string",
3621
+ stateElapsedTime: "number",
3622
+ version: "number"
3623
+ }
3624
+ },
3625
+ {
3626
+ id: "DELETE /compute/sessions/{}",
3627
+ method: "DELETE",
3628
+ path: "/compute/sessions/{}",
3629
+ steps: ["compute/session-delete"],
3630
+ statuses: [204],
3631
+ queries: [],
3632
+ request: {
3633
+ queries: [],
3634
+ body: void 0
3635
+ },
3636
+ shape: void 0
3637
+ },
3638
+ {
3639
+ id: "POST /compute/sessions/{}/jobs",
3640
+ method: "POST",
3641
+ path: "/compute/sessions/{}/jobs",
3642
+ steps: ["compute/execute-script"],
3643
+ statuses: [201],
3644
+ queries: [],
3645
+ request: {
3646
+ queries: [],
3647
+ body: {
3648
+ code: "string",
3649
+ description: "string",
3650
+ name: "string",
3651
+ variables: {
3652
+ SYS_JES_JOB_URI: "string",
3653
+ _DEBUG: "number",
3654
+ _program: "string"
3655
+ },
3656
+ version: "number"
3657
+ }
3658
+ },
3659
+ shape: {
3660
+ creationTimeStamp: "string",
3661
+ id: "string",
3662
+ links: [
3663
+ {
3664
+ href: "string",
3665
+ method: "string",
3666
+ rel: "string",
3667
+ type: "string",
3668
+ uri: "string"
3669
+ }
3670
+ ],
3671
+ sessionId: "string",
3672
+ state: "string",
3673
+ stateElapsedTime: "number",
3674
+ version: "number"
3675
+ }
3676
+ },
3677
+ {
3678
+ id: "GET /compute/sessions/{}/jobs/{}",
3679
+ method: "GET",
3680
+ path: "/compute/sessions/{}/jobs/{}",
3681
+ steps: ["compute/execute-script"],
3682
+ statuses: [200],
3683
+ queries: [],
3684
+ request: {
3685
+ queries: [],
3686
+ body: void 0
3687
+ },
3688
+ shape: {
3689
+ completedTimeStamp: "string",
3690
+ creationTimeStamp: "string",
3691
+ id: "string",
3692
+ jobConditionCode: "number",
3693
+ links: [
3694
+ {
3695
+ href: "string",
3696
+ method: "string",
3697
+ rel: "string",
3698
+ type: "string",
3699
+ uri: "string"
3700
+ }
3701
+ ],
3702
+ listingStatistics: {
3703
+ lineCount: "number",
3704
+ modifiedTimeStamp: "string"
3705
+ },
3706
+ logStatistics: {
3707
+ lineCount: "number",
3708
+ modifiedTimeStamp: "string"
3709
+ },
3710
+ sessionId: "string",
3711
+ state: "string",
3712
+ stateElapsedTime: "number",
3713
+ statistics: {
3714
+ systemCpuTime: "number",
3715
+ userCpuTime: "number"
3716
+ },
3717
+ version: "number"
3718
+ }
3719
+ },
3720
+ {
3721
+ id: "GET /compute/sessions/{}/jobs/{}/log/content",
3722
+ method: "GET",
3723
+ path: "/compute/sessions/{}/jobs/{}/log/content",
3724
+ steps: ["compute/execute-script"],
3725
+ statuses: [200],
3726
+ queries: ["limit", "start"],
3727
+ request: {
3728
+ queries: ["limit", "start"],
3729
+ body: void 0
3730
+ },
3731
+ shape: {
3732
+ accept: "string",
3733
+ count: "number",
3734
+ items: [
3735
+ {
3736
+ line: "string",
3737
+ type: "string",
3738
+ version: "number"
3739
+ }
3740
+ ],
3741
+ limit: "number",
3742
+ links: [
3743
+ {
3744
+ href: "string",
3745
+ itemType: "string",
3746
+ method: "string",
3747
+ rel: "string",
3748
+ type: "string",
3749
+ uri: "string"
3750
+ }
3751
+ ],
3752
+ name: "string",
3753
+ start: "number",
3754
+ version: "number"
3755
+ }
3756
+ },
3757
+ {
3758
+ id: "GET /compute/sessions/{}/jobs/{}/state",
3759
+ method: "GET",
3760
+ path: "/compute/sessions/{}/jobs/{}/state",
3761
+ steps: ["compute/execute-script"],
3762
+ statuses: [200],
3763
+ queries: ["_action", "wait"],
3764
+ request: {
3765
+ queries: ["_action", "wait"],
3766
+ body: void 0
3767
+ },
3768
+ shape: void 0
3769
+ },
3770
+ {
3771
+ id: "GET /compute/sessions/{}/state",
3772
+ method: "GET",
3773
+ path: "/compute/sessions/{}/state",
3774
+ steps: ["compute/execute-script", "compute/session-state"],
3775
+ statuses: [200],
3776
+ queries: ["wait"],
3777
+ request: {
3778
+ queries: ["wait"],
3779
+ body: void 0
3780
+ },
3781
+ shape: void 0
3782
+ },
3783
+ {
3784
+ id: "POST /files/files",
3785
+ method: "POST",
3786
+ path: "/files/files",
3787
+ steps: ["files/create"],
3788
+ statuses: [201],
3789
+ queries: ["parentFolderUri", "typeDefName"],
3790
+ request: {
3791
+ queries: ["parentFolderUri", "typeDefName"],
3792
+ body: {
3793
+ multipart: ["file"]
3794
+ }
3795
+ },
3796
+ shape: {
3797
+ contentDisposition: "string",
3798
+ contentType: "string",
3799
+ createdBy: "string",
3800
+ creationTimeStamp: "string",
3801
+ encoding: "string",
3802
+ fileStatus: "string",
3803
+ fileVersion: "number",
3804
+ id: "string",
3805
+ links: [
3806
+ {
3807
+ href: "string",
3808
+ method: "string",
3809
+ rel: "string",
3810
+ type: "string",
3811
+ uri: "string"
3812
+ }
3813
+ ],
3814
+ modifiedBy: "string",
3815
+ modifiedTimeStamp: "string",
3816
+ name: "string",
3817
+ properties: {},
3818
+ quarantine: "boolean",
3819
+ searchable: "boolean",
3820
+ size: "number",
3821
+ typeDefName: "string",
3822
+ urlDetected: "boolean",
3823
+ version: "number",
3824
+ virusDetected: "boolean"
3825
+ }
3826
+ },
3827
+ {
3828
+ id: "GET /files/files/{}",
3829
+ method: "GET",
3830
+ path: "/files/files/{}",
3831
+ steps: ["files/replace"],
3832
+ statuses: [200],
3833
+ queries: [],
3834
+ request: {
3835
+ queries: [],
3836
+ body: void 0
3837
+ },
3838
+ shape: {
3839
+ contentDisposition: "string",
3840
+ contentType: "string",
3841
+ createdBy: "string",
3842
+ creationTimeStamp: "string",
3843
+ encoding: "string",
3844
+ fileStatus: "string",
3845
+ fileVersion: "number",
3846
+ id: "string",
3847
+ links: [
3848
+ {
3849
+ href: "string",
3850
+ method: "string",
3851
+ rel: "string",
3852
+ type: "string",
3853
+ uri: "string"
3854
+ }
3855
+ ],
3856
+ modifiedBy: "string",
3857
+ modifiedTimeStamp: "string",
3858
+ name: "string",
3859
+ properties: {
3860
+ "content.download": "string",
3861
+ "content.openInBrowser": "string",
3862
+ "content.preview": "string",
3863
+ sasIconKey: "string",
3864
+ typeRegistrant: "string"
3865
+ },
3866
+ quarantine: "boolean",
3867
+ searchable: "boolean",
3868
+ size: "number",
3869
+ typeDefName: "string",
3870
+ urlDetected: "boolean",
3871
+ version: "number",
3872
+ virusDetected: "boolean"
3873
+ }
3874
+ },
3875
+ {
3876
+ id: "PATCH /files/files/{}",
3877
+ method: "PATCH",
3878
+ path: "/files/files/{}",
3879
+ steps: ["files/create"],
3880
+ statuses: [200],
3881
+ queries: [],
3882
+ request: {
3883
+ queries: [],
3884
+ body: {
3885
+ name: "string",
3886
+ properties: {
3887
+ "content.download": "string",
3888
+ "content.openInBrowser": "string",
3889
+ "content.preview": "string",
3890
+ sasIconKey: "string",
3891
+ typeRegistrant: "string"
3892
+ }
3893
+ }
3894
+ },
3895
+ shape: {
3896
+ contentDisposition: "string",
3897
+ contentType: "string",
3898
+ createdBy: "string",
3899
+ creationTimeStamp: "string",
3900
+ encoding: "string",
3901
+ fileStatus: "string",
3902
+ fileVersion: "number",
3903
+ id: "string",
3904
+ links: [
3905
+ {
3906
+ href: "string",
3907
+ method: "string",
3908
+ rel: "string",
3909
+ type: "string",
3910
+ uri: "string"
3911
+ }
3912
+ ],
3913
+ modifiedBy: "string",
3914
+ modifiedTimeStamp: "string",
3915
+ name: "string",
3916
+ properties: {
3917
+ "content.download": "string",
3918
+ "content.openInBrowser": "string",
3919
+ "content.preview": "string",
3920
+ sasIconKey: "string",
3921
+ typeRegistrant: "string"
3922
+ },
3923
+ quarantine: "boolean",
3924
+ searchable: "boolean",
3925
+ size: "number",
3926
+ typeDefName: "string",
3927
+ urlDetected: "boolean",
3928
+ version: "number",
3929
+ virusDetected: "boolean"
3930
+ }
3931
+ },
3932
+ {
3933
+ id: "GET /files/files/{}/content",
3934
+ method: "GET",
3935
+ path: "/files/files/{}/content",
3936
+ steps: ["files/content"],
3937
+ statuses: [200],
3938
+ queries: [],
3939
+ request: {
3940
+ queries: [],
3941
+ body: void 0
3942
+ },
3943
+ shape: void 0
3944
+ },
3945
+ {
3946
+ id: "PUT /files/files/{}/content",
3947
+ method: "PUT",
3948
+ path: "/files/files/{}/content",
3949
+ steps: ["files/replace"],
3950
+ statuses: [200],
3951
+ queries: [],
3952
+ request: {
3953
+ queries: [],
3954
+ body: void 0
3955
+ },
3956
+ shape: {
3957
+ contentDisposition: "string",
3958
+ contentType: "string",
3959
+ createdBy: "string",
3960
+ creationTimeStamp: "string",
3961
+ encoding: "string",
3962
+ fileStatus: "string",
3963
+ fileVersion: "number",
3964
+ id: "string",
3965
+ links: [
3966
+ {
3967
+ href: "string",
3968
+ method: "string",
3969
+ rel: "string",
3970
+ type: "string",
3971
+ uri: "string"
3972
+ }
3973
+ ],
3974
+ modifiedBy: "string",
3975
+ modifiedTimeStamp: "string",
3976
+ name: "string",
3977
+ properties: {
3978
+ "content.download": "string",
3979
+ "content.openInBrowser": "string",
3980
+ "content.preview": "string",
3981
+ sasIconKey: "string",
3982
+ typeRegistrant: "string"
3983
+ },
3984
+ quarantine: "boolean",
3985
+ searchable: "boolean",
3986
+ size: "number",
3987
+ typeDefName: "string",
3988
+ urlDetected: "boolean",
3989
+ version: "number",
3990
+ virusDetected: "boolean"
3991
+ }
3992
+ },
3993
+ {
3994
+ id: "POST /folders/folders",
3995
+ method: "POST",
3996
+ path: "/folders/folders",
3997
+ steps: ["folders/create"],
3998
+ statuses: [201],
3999
+ queries: ["parentFolderUri"],
4000
+ request: {
4001
+ queries: ["parentFolderUri"],
4002
+ body: {
4003
+ name: "string",
4004
+ type: "string"
4005
+ }
4006
+ },
4007
+ shape: {
4008
+ createdBy: "string",
4009
+ creationTimeStamp: "string",
4010
+ id: "string",
4011
+ links: [
4012
+ {
4013
+ href: "string",
4014
+ method: "string",
4015
+ rel: "string",
4016
+ type: "string",
4017
+ uri: "string"
4018
+ }
4019
+ ],
4020
+ memberCount: "number",
4021
+ modifiedBy: "string",
4022
+ modifiedTimeStamp: "string",
4023
+ name: "string",
4024
+ parentFolderUri: "string",
4025
+ type: "string",
4026
+ version: "number"
4027
+ }
4028
+ },
4029
+ {
4030
+ id: "GET /folders/folders/{}",
4031
+ method: "GET",
4032
+ path: "/folders/folders/{}",
4033
+ steps: ["folders/delete"],
4034
+ statuses: [200],
4035
+ queries: [],
4036
+ request: {
4037
+ queries: [],
4038
+ body: void 0
4039
+ },
4040
+ shape: {
4041
+ createdBy: "string",
4042
+ creationTimeStamp: "string",
4043
+ description: "string",
4044
+ id: "string",
4045
+ links: [
4046
+ {
4047
+ href: "string",
4048
+ method: "string",
4049
+ rel: "string",
4050
+ type: "string",
4051
+ uri: "string"
4052
+ }
4053
+ ],
4054
+ memberCount: "number",
4055
+ modifiedBy: "string",
4056
+ modifiedTimeStamp: "string",
4057
+ name: "string",
4058
+ parentFolderUri: "string",
4059
+ properties: {
4060
+ allowMove: "string"
4061
+ },
4062
+ type: "string",
4063
+ version: "number"
4064
+ }
4065
+ },
4066
+ {
4067
+ id: "PATCH /folders/folders/{}",
4068
+ method: "PATCH",
4069
+ path: "/folders/folders/{}",
4070
+ steps: ["folders/delete"],
4071
+ statuses: [200],
4072
+ queries: [],
4073
+ request: {
4074
+ queries: [],
4075
+ body: {
4076
+ id: "string",
4077
+ name: "string",
4078
+ parentFolderUri: "string"
4079
+ }
4080
+ },
4081
+ shape: {
4082
+ createdBy: "string",
4083
+ creationTimeStamp: "string",
4084
+ id: "string",
4085
+ links: [
4086
+ {
4087
+ href: "string",
4088
+ method: "string",
4089
+ rel: "string",
4090
+ type: "string",
4091
+ uri: "string"
4092
+ }
4093
+ ],
4094
+ memberCount: "number",
4095
+ modifiedBy: "string",
4096
+ modifiedTimeStamp: "string",
4097
+ name: "string",
4098
+ parentFolderUri: "string",
4099
+ type: "string",
4100
+ version: "number"
4101
+ }
4102
+ },
4103
+ {
4104
+ id: "GET /folders/folders/{}/members",
4105
+ method: "GET",
4106
+ path: "/folders/folders/{}/members",
4107
+ steps: [
4108
+ "files/content",
4109
+ "files/replace",
4110
+ "folders/create",
4111
+ "folders/members"
4112
+ ],
4113
+ statuses: [200],
4114
+ queries: ["limit"],
4115
+ request: {
4116
+ queries: ["limit"],
4117
+ body: void 0
4118
+ },
4119
+ shape: {
4120
+ accept: "string",
4121
+ count: "number",
4122
+ items: [
4123
+ {
4124
+ added: "string",
4125
+ contentType: "string",
4126
+ createdBy: "string",
4127
+ creationTimeStamp: "string",
4128
+ id: "string",
4129
+ links: [
4130
+ {
4131
+ href: "string",
4132
+ method: "string",
4133
+ rel: "string",
4134
+ type: "string",
4135
+ uri: "string"
4136
+ }
4137
+ ],
4138
+ modifiedBy: "string",
4139
+ modifiedTimeStamp: "string",
4140
+ name: "string",
4141
+ parentFolderUri: "string",
4142
+ type: "string",
4143
+ uri: "string",
4144
+ version: "number"
4145
+ }
4146
+ ],
4147
+ limit: "number",
4148
+ links: [
4149
+ {
4150
+ href: "string",
4151
+ itemType: "string",
4152
+ method: "string",
4153
+ rel: "string",
4154
+ type: "string",
4155
+ uri: "string"
4156
+ }
4157
+ ],
4158
+ name: "string",
4159
+ start: "number",
4160
+ version: "number"
4161
+ }
4162
+ },
4163
+ {
4164
+ id: "GET /folders/folders/@item",
4165
+ method: "GET",
4166
+ path: "/folders/folders/@item",
4167
+ steps: [
4168
+ "files/content",
4169
+ "files/create",
4170
+ "files/replace",
4171
+ "folders/create",
4172
+ "folders/delete",
4173
+ "folders/item",
4174
+ "folders/members"
4175
+ ],
4176
+ statuses: [200, 401, 404],
4177
+ queries: ["path"],
4178
+ request: {
4179
+ queries: ["path"],
4180
+ body: void 0
4181
+ },
4182
+ shape: {
4183
+ createdBy: "string",
4184
+ creationTimeStamp: "string",
4185
+ description: "string",
4186
+ id: "string",
4187
+ links: [
4188
+ {
4189
+ href: "string",
4190
+ method: "string",
4191
+ rel: "string",
4192
+ type: "string",
4193
+ uri: "string"
4194
+ }
4195
+ ],
4196
+ memberCount: "number",
4197
+ modifiedBy: "string",
4198
+ modifiedTimeStamp: "string",
4199
+ name: "string",
4200
+ parentFolderUri: "string",
4201
+ type: "string",
4202
+ version: "number"
4203
+ }
4204
+ },
4205
+ {
4206
+ id: "GET /folders/folders/@myRecycleBin",
4207
+ method: "GET",
4208
+ path: "/folders/folders/@myRecycleBin",
4209
+ steps: ["folders/delete"],
4210
+ statuses: [200],
4211
+ queries: [],
4212
+ request: {
4213
+ queries: [],
4214
+ body: void 0
4215
+ },
4216
+ shape: {
4217
+ createdBy: "string",
4218
+ creationTimeStamp: "string",
4219
+ description: "string",
4220
+ id: "string",
4221
+ links: [
4222
+ {
4223
+ href: "string",
4224
+ method: "string",
4225
+ rel: "string",
4226
+ type: "string",
4227
+ uri: "string"
4228
+ }
4229
+ ],
4230
+ memberCount: "number",
4231
+ modifiedBy: "string",
4232
+ modifiedTimeStamp: "string",
4233
+ name: "string",
4234
+ parentFolderUri: "string",
4235
+ properties: {
4236
+ allowMove: "string"
4237
+ },
4238
+ type: "string",
4239
+ version: "number"
4240
+ }
4241
+ },
4242
+ {
4243
+ id: "GET /identities/users/@currentUser",
4244
+ method: "GET",
4245
+ path: "/identities/users/@currentUser",
4246
+ steps: ["identities/current-user"],
4247
+ statuses: [200],
4248
+ queries: [],
4249
+ request: {
4250
+ queries: [],
4251
+ body: void 0
4252
+ },
4253
+ shape: {
4254
+ addresses: [
4255
+ {
4256
+ locality: "string",
4257
+ type: "string"
4258
+ }
4259
+ ],
4260
+ emailAddresses: [
4261
+ {
4262
+ type: "string",
4263
+ value: "string"
4264
+ }
4265
+ ],
4266
+ id: "string",
4267
+ links: [
4268
+ {
4269
+ href: "string",
4270
+ method: "string",
4271
+ rel: "string",
4272
+ type: "string",
4273
+ uri: "string"
4274
+ }
4275
+ ],
4276
+ name: "string",
4277
+ providerId: "string",
4278
+ state: "string",
4279
+ version: "number"
4280
+ }
4281
+ },
4282
+ {
4283
+ id: "POST /SASLogon/oauth/token",
4284
+ method: "POST",
4285
+ path: "/SASLogon/oauth/token",
4286
+ steps: ["auth/token-refresh", "auth/token-refresh-refused"],
4287
+ statuses: [200, 401],
4288
+ queries: [],
4289
+ request: {
4290
+ queries: [],
4291
+ body: {
4292
+ multipart: ["grant_type", "refresh_token"]
4293
+ }
4294
+ },
4295
+ shape: {
4296
+ access_token: "string",
4297
+ expires_in: "number",
4298
+ id_token: "string",
4299
+ jti: "string",
4300
+ refresh_expires_in: "number",
4301
+ refresh_revocable: "boolean",
4302
+ refresh_token: "string",
4303
+ revocable: "boolean",
4304
+ scope: "string",
4305
+ token_type: "string"
4306
+ }
4307
+ },
4308
+ {
4309
+ id: "GET /types/types",
4310
+ method: "GET",
4311
+ path: "/types/types",
4312
+ steps: ["files/create"],
4313
+ statuses: [200],
4314
+ queries: ["limit"],
4315
+ request: {
4316
+ queries: ["limit"],
4317
+ body: void 0
4318
+ },
4319
+ shape: void 0
4320
+ }
4321
+ ];
4322
+
4323
+ // src/viya/unrecorded.ts
4324
+ var UNRECORDED = [
4325
+ // The recorder hands the adapter a token it obtained itself, so the calls that
4326
+ // obtain one never pass through the proxy. The capture tool records them as a
4327
+ // separate pass, which needs a client id and secret.
4328
+ {
4329
+ path: "/SASLogon",
4330
+ reason: "no capture: the pass authenticates outside the adapter, so the login root is never requested through the client"
4331
+ },
4332
+ {
4333
+ path: "/SASLogon/login",
4334
+ reason: "no capture: an interactive login; the pass presents a token instead of a form"
4335
+ },
4336
+ {
4337
+ path: "/SASLogon/login.do",
4338
+ reason: "no capture: an interactive login; the pass presents a token instead of a form"
4339
+ },
4340
+ {
4341
+ path: "/SASLogon/logout",
4342
+ reason: "no capture: the pass never signs out, because a capture run must leave the estate as it found it"
4343
+ },
4344
+ {
4345
+ path: "/SASLogon/logout.do",
4346
+ reason: "no capture: the pass never signs out, because a capture run must leave the estate as it found it"
4347
+ },
4348
+ {
4349
+ path: "/SASLogon/oauth/authorize",
4350
+ reason: "no capture: the authorisation-code step needs a browser; the pass uses the password grant"
4351
+ },
4352
+ // Compute operations the scripted passes do not reach.
4353
+ {
4354
+ path: "/compute/sessions/{}/filerefs/_webout/content",
4355
+ reason: "no capture: the adapter reads the webout fileref only when a run expects one (`expectWebout`); the execute pass submits a `%put` and reads the log"
4356
+ },
4357
+ {
4358
+ path: "/compute/sessions/{}/variables/{}",
4359
+ reason: "no capture: the adapter reads a session variable only to report a submitted job's pid (`printPid`), which the pass does not set"
4360
+ },
4361
+ {
4362
+ path: "/launcher/contexts",
4363
+ reason: "no capture: the fallback list, asked for only when the compute context list fails; a healthy estate never reaches it"
4364
+ },
4365
+ // The job path needs something deployed to run.
4366
+ {
4367
+ path: "/jobDefinitions/definitions",
4368
+ reason: "no capture: needs a job definition on the estate. The next pass deploys a service pack under its own app folder and reads the definition back"
4369
+ },
4370
+ {
4371
+ path: "/jobExecution/jobs",
4372
+ reason: "no capture: needs a deployed service to submit. The next pass deploys a service pack under its own app folder"
4373
+ },
4374
+ {
4375
+ path: "/jobExecution/jobs/{}",
4376
+ reason: "no capture: follows a submission, so it arrives with the same pass as POST /jobExecution/jobs"
4377
+ }
4378
+ ];
4379
+
4380
+ // src/viya/version.ts
4381
+ var VIYA_TARGET_VERSION = "V.04.00M0P100526";
4382
+ var VIYA_CAPTURED_AT = "2026-11-12";
4383
+ var EMULATED_HEADER = "x-sasjs-emulated";
4384
+ var EMULATED_HEADER_VALUE = `viya@${VIYA_TARGET_VERSION}`;
4385
+ var emulatedHeaders = () => ({
4386
+ [EMULATED_HEADER]: EMULATED_HEADER_VALUE,
4387
+ "Access-Control-Expose-Headers": EMULATED_HEADER
4388
+ });
4389
+
4390
+ // src/viya/overlay.ts
4391
+ var NEEDS_AUTH = "The token endpoint is answered by the host that mounts the emulator, which owns the token port.";
4392
+ var VIYA_OVERLAY = {
4393
+ // answered here
4394
+ "POST /folders/folders": { implemented: true },
4395
+ "GET /folders/folders/{}": { implemented: true },
4396
+ "PATCH /folders/folders/{}": { implemented: true },
4397
+ "GET /folders/folders/{}/members": { implemented: true },
4398
+ "GET /folders/folders/@item": { implemented: true },
4399
+ "GET /folders/folders/@myRecycleBin": { implemented: true },
4400
+ "GET /identities/users/@currentUser": { implemented: true },
4401
+ "GET /types/types": { implemented: true },
4402
+ // answered here: compute
4403
+ "GET /compute/contexts": { implemented: true },
4404
+ "POST /compute/contexts/{}/sessions": { implemented: true },
4405
+ "DELETE /compute/sessions/{}": { implemented: true },
4406
+ "POST /compute/sessions/{}/jobs": { implemented: true },
4407
+ "GET /compute/sessions/{}/jobs/{}": { implemented: true },
4408
+ "GET /compute/sessions/{}/jobs/{}/log/content": { implemented: true },
4409
+ "GET /compute/sessions/{}/jobs/{}/state": { implemented: true },
4410
+ "GET /compute/sessions/{}/state": { implemented: true },
4411
+ // answered here: files
4412
+ "POST /files/files": { implemented: true },
4413
+ "GET /files/files/{}": { implemented: true },
4414
+ "PATCH /files/files/{}": { implemented: true },
4415
+ "GET /files/files/{}/content": { implemented: true },
4416
+ "PUT /files/files/{}/content": { implemented: true },
4417
+ // declined: the host owns the token port
4418
+ "POST /SASLogon/oauth/token": { implemented: false, reason: NEEDS_AUTH }
4419
+ };
4420
+ var assertOverlayEntries = (overlay, operations = VIYA_TABLE) => {
4421
+ const known2 = new Set(operations.map((operation) => operation.id));
4422
+ for (const id of Object.keys(overlay))
4423
+ if (!known2.has(id))
4424
+ throw new Error(
4425
+ `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.`
4426
+ );
4427
+ for (const operation of operations)
4428
+ if (!(operation.id in overlay))
4429
+ throw new Error(
4430
+ `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.`
4431
+ );
4432
+ };
4433
+ assertOverlayEntries(VIYA_OVERLAY);
4434
+
4435
+ // src/viya/ports.ts
4436
+ var requireDrive = (services) => services.drive;
4437
+
4438
+ // src/viya/seed.ts
4439
+ var DEFAULT_SEED = "emulated";
4440
+ var normaliseServerUrl = (url) => {
4441
+ if (!url) return "";
4442
+ const trimmed = url.trim();
4443
+ if (!trimmed) return "";
4444
+ const match = /^(?:([a-z][a-z0-9+.-]*):\/\/)?([^/?#]+)/i.exec(trimmed);
4445
+ if (!match) return trimmed.replace(/\/+$/, "").toLowerCase();
4446
+ const scheme = (match[1] ?? "http").toLowerCase();
4447
+ let authority = match[2].toLowerCase();
4448
+ const credentials = authority.lastIndexOf("@");
4449
+ if (credentials >= 0) authority = authority.slice(credentials + 1);
4450
+ let host = authority;
4451
+ let port = "";
4452
+ if (authority.startsWith("[")) {
4453
+ const close = authority.indexOf("]");
4454
+ if (close >= 0) {
4455
+ host = authority.slice(0, close + 1);
4456
+ if (authority[close + 1] === ":") port = authority.slice(close + 2);
4457
+ }
4458
+ } else {
4459
+ const colon = authority.lastIndexOf(":");
4460
+ if (colon >= 0) {
4461
+ host = authority.slice(0, colon);
4462
+ port = authority.slice(colon + 1);
4463
+ }
4464
+ }
4465
+ const isDefault = scheme === "http" && port === "80" || scheme === "https" && port === "443";
4466
+ return `${scheme}://${host}${port && !isDefault ? `:${port}` : ""}`;
4467
+ };
4468
+ var hash = (input) => {
4469
+ let value = 2166136261;
4470
+ for (let index = 0; index < input.length; index++) {
4471
+ value ^= input.charCodeAt(index);
4472
+ value = Math.imul(value, 16777619) >>> 0;
4473
+ }
4474
+ return value >>> 0;
4475
+ };
4476
+ var seedOf = (settings = {}) => {
4477
+ if (settings.seed !== void 0 && settings.seed !== "")
4478
+ return hash(`seed:${settings.seed}`);
4479
+ const address = normaliseServerUrl(settings.serverUrl);
4480
+ return hash(`url:${address || DEFAULT_SEED}`);
4481
+ };
4482
+ var generator = (seed) => {
4483
+ let state = seed >>> 0;
4484
+ return () => {
4485
+ state = state + 1831565813 >>> 0;
4486
+ let value = state;
4487
+ value = Math.imul(value ^ value >>> 15, value | 1);
4488
+ value ^= value + Math.imul(value ^ value >>> 7, value | 61);
4489
+ return ((value ^ value >>> 14) >>> 0) / 4294967296;
4490
+ };
4491
+ };
4492
+ var drawInt = (next, bound) => Math.floor(next() * bound);
4493
+ var drawFrom = (next, values) => values[drawInt(next, values.length)];
4494
+
4495
+ // src/viya/sessions.ts
4496
+ var logFor = (seed, program) => {
4497
+ const code = Array.isArray(program) ? program.join("\n") : program;
4498
+ const next = generator(seed ^ hash(`code:${code}`));
4499
+ const rows = drawInt(next, 900) + 100;
4500
+ const seconds = (drawInt(next, 90) + 10) / 100;
4501
+ const lines = code.split("\n").map((line, index) => `${String(index + 1).padStart(3, " ")} ${line}`);
4502
+ return [
4503
+ "NOTE: Emulated compute engine - this log is generated, not produced by SAS.",
4504
+ "NOTE: No library was touched: the emulated engine has none.",
4505
+ ...lines,
4506
+ `NOTE: The data set WORK.EMULATED has ${rows} observations and 3 variables.`,
4507
+ `NOTE: DATA statement used (Total process time):`,
4508
+ `NOTE: real time ${seconds.toFixed(2)} seconds`,
4509
+ `NOTE: user cpu time ${(seconds / 2).toFixed(2)} seconds`,
4510
+ `NOTE: ${drawFrom(next, ["The emulated run completed.", "Emulation complete - no SAS was executed."])}`
4511
+ ];
4512
+ };
4513
+ var EmulatedEstate = class {
4514
+ constructor(seed) {
4515
+ this.seed = seed;
4516
+ this.sessions = /* @__PURE__ */ new Map();
4517
+ this.created = 0;
4518
+ }
4519
+ /** A new session: deterministic id, no jobs. */
4520
+ create() {
4521
+ const session = {
4522
+ id: `emulated-${this.seed.toString(16)}-ses${String(this.created++).padStart(4, "0")}`,
4523
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
4524
+ jobs: /* @__PURE__ */ new Map(),
4525
+ submitted: 0
4526
+ };
4527
+ this.sessions.set(session.id, session);
4528
+ return session;
4529
+ }
4530
+ session(id) {
4531
+ return this.sessions.get(id);
4532
+ }
4533
+ remove(id) {
4534
+ return this.sessions.delete(id);
4535
+ }
4536
+ /** A job accepted into a session, with the log the emulator generated for it. */
4537
+ submit(session, job) {
4538
+ const id = `${session.id}-job${String(session.submitted++).padStart(4, "0")}`;
4539
+ const code = job.code ?? "";
4540
+ const submitted = {
4541
+ id,
4542
+ name: job.name ?? id,
4543
+ // the log is a function of the seed and the program alone, so the same
4544
+ // program answers the same lines whatever session it was submitted in
4545
+ log: logFor(this.seed, code),
4546
+ state: "completed",
4547
+ // the real clock, unlike a folder's: a client computes a session's age
4548
+ // from this stamp and expires it, so a fixed instant in the past is a
4549
+ // session that is born expired
4550
+ creationTimeStamp: (/* @__PURE__ */ new Date()).toISOString(),
4551
+ completedTimeStamp: (/* @__PURE__ */ new Date()).toISOString(),
4552
+ sessionId: session.id
4553
+ };
4554
+ session.jobs.set(id, submitted);
4555
+ return submitted;
4556
+ }
4557
+ };
4558
+ var estates = /* @__PURE__ */ new Map();
4559
+ var estateFor = (seed) => {
4560
+ const existing = estates.get(seed);
4561
+ if (existing) return existing;
4562
+ const estate = new EmulatedEstate(seed);
4563
+ estates.set(seed, estate);
4564
+ return estate;
4565
+ };
4566
+
4567
+ // src/viya/ids.ts
4568
+ var EMULATED_NOW = "2026-01-01T00:00:00.000Z";
4569
+ var EMULATED_USER = { id: "emulated-user", name: "Emulated User" };
4570
+ var idFor = (path, kind = "folder") => {
4571
+ const hash2 = (input, seed) => {
4572
+ let value = seed;
4573
+ for (let index = 0; index < input.length; index++) {
4574
+ value ^= input.charCodeAt(index);
4575
+ value = Math.imul(value, 16777619) >>> 0;
4576
+ }
4577
+ return value.toString(16).padStart(8, "0");
4578
+ };
4579
+ const raw = hash2(`${kind}:${path}`, 2166136261) + hash2(`${kind}:${path}`, 2246822519) + hash2(`${kind}:${path}`, 3266489917) + hash2(`${kind}:${path}`, 668265263);
4580
+ const hex = raw.slice(0, 32);
4581
+ return [
4582
+ hex.slice(0, 8),
4583
+ hex.slice(8, 12),
4584
+ `4${hex.slice(13, 16)}`,
4585
+ `a${hex.slice(17, 20)}`,
4586
+ hex.slice(20, 32)
4587
+ ].join("-");
4588
+ };
4589
+ var normalisePath = (path) => {
4590
+ const collapsed = `/${path}`.replace(/\/{2,}/g, "/");
4591
+ return collapsed.length > 1 ? collapsed.replace(/\/+$/, "") : collapsed;
4592
+ };
4593
+
4594
+ // src/viya/compute.ts
4595
+ var DEFAULT_CONTEXT_NAME = "Emulated Compute Context";
4596
+ var EMULATED_CONTEXT_ID = idFor("emulated-context", "context");
4597
+ var relLinks = (type, rels) => rels.map(([rel, href]) => ({ href, uri: href, rel, method: "GET", type }));
4598
+ var linksFor = (uri, type, collection = false, itemType = false) => [
4599
+ // the collection link comes first, because that is the order the capture
4600
+ // recorded and the item shape assertion walks the first element
4601
+ ...collection ? [
4602
+ {
4603
+ href: `${uri}/members`,
4604
+ uri: `${uri}/members`,
4605
+ rel: "members",
4606
+ method: "GET",
4607
+ type,
4608
+ itemType: type
4609
+ }
4610
+ ] : [],
4611
+ {
4612
+ href: uri,
4613
+ uri,
4614
+ rel: "self",
4615
+ method: "GET",
4616
+ type,
4617
+ // the log's capture records itemType on its first link, so it is stamped
4618
+ // there rather than invented as a members link the estate does not have
4619
+ ...itemType ? { itemType: type } : {}
4620
+ }
4621
+ ];
4622
+ var estateOf = (services) => estateFor(seedOf(services.viya));
4623
+ var contextNameFrom = (filter) => {
4624
+ if (!filter) return DEFAULT_CONTEXT_NAME;
4625
+ const match = /name\s*,\s*'([^']*)'|name\s*,\s*"([^"]*)"/i.exec(filter);
4626
+ return match?.[1] ?? match?.[2] ?? DEFAULT_CONTEXT_NAME;
4627
+ };
4628
+ var contextBody = (name) => ({
4629
+ id: EMULATED_CONTEXT_ID,
4630
+ name,
4631
+ createdBy: EMULATED_USER.id,
4632
+ version: 2,
4633
+ links: linksFor(
4634
+ `/compute/contexts/${EMULATED_CONTEXT_ID}`,
4635
+ "application/vnd.sas.compute.context"
4636
+ )
4637
+ });
4638
+ var sessionBody = (services, session, autoExecLines) => {
4639
+ const { id } = session;
4640
+ const uri = `/compute/sessions/${id}`;
4641
+ return {
4642
+ id,
4643
+ applicationName: "emulated",
4644
+ owner: EMULATED_USER.id,
4645
+ serverId: idFor(
4646
+ normaliseServerUrl(services.viya?.serverUrl) || "emulated",
4647
+ "server"
4648
+ ),
4649
+ state: "idle",
4650
+ attributes: {
4651
+ homeDirectory: "/tmp/emulated",
4652
+ sessionInactiveTimeout: 3600
4653
+ },
4654
+ environment: { autoExecLines },
4655
+ // the real clock: the adapter computes a session's age from this stamp and
4656
+ // expires it against sessionInactiveTimeout
4657
+ creationTimeStamp: session.createdAt,
4658
+ serviceAPIVersion: 1,
4659
+ sessionConditionCode: 0,
4660
+ stateElapsedTime: 0,
4661
+ version: 2,
4662
+ links: relLinks("application/vnd.sas.compute.session", [
4663
+ ["self", uri],
4664
+ ["state", `${uri}/state`],
4665
+ ["log", `${uri}/log`],
4666
+ ["jobs", `${uri}/jobs`]
4667
+ ])
4668
+ };
4669
+ };
4670
+ var jobBody = (job) => {
4671
+ const uri = `/compute/sessions/${job.sessionId}/jobs/${job.id}`;
4672
+ return {
4673
+ id: job.id,
4674
+ name: job.name,
4675
+ sessionId: job.sessionId,
4676
+ state: job.state,
4677
+ creationTimeStamp: job.creationTimeStamp,
4678
+ completedTimeStamp: job.completedTimeStamp,
4679
+ jobConditionCode: 0,
4680
+ stateElapsedTime: 1,
4681
+ listingStatistics: {
4682
+ lineCount: job.log.length,
4683
+ modifiedTimeStamp: job.completedTimeStamp
4684
+ },
4685
+ logStatistics: {
4686
+ lineCount: job.log.length,
4687
+ modifiedTimeStamp: job.completedTimeStamp
4688
+ },
4689
+ statistics: { systemCpuTime: 0.01, userCpuTime: 0.02 },
4690
+ version: 2,
4691
+ links: relLinks("application/vnd.sas.compute.job", [
4692
+ ["self", uri],
4693
+ ["state", `${uri}/state`],
4694
+ ["log", `${uri}/log`],
4695
+ ["up", `/compute/sessions/${job.sessionId}`]
4696
+ ])
4697
+ };
4698
+ };
4699
+ var sessionOf = (services, id) => {
4700
+ const session = estateOf(services).session(id);
4701
+ if (!session)
4702
+ throw new ApiError(404, `Session with ID '${id}' was not found.`);
4703
+ return session;
4704
+ };
4705
+ var jobOf = (services, sessionId, jobId) => {
4706
+ const job = sessionOf(services, sessionId).jobs.get(jobId);
4707
+ if (!job) throw new ApiError(404, `Job with ID '${jobId}' was not found.`);
4708
+ return job;
4709
+ };
4710
+ var segmentsOf = (params) => params.segments;
4711
+ var COMPUTE_HANDLERS = {
4712
+ "GET /compute/contexts": async ({ request }) => {
4713
+ const limit = Number(request.query?.limit ?? 0) || 0;
4714
+ return {
4715
+ status: 200,
4716
+ body: {
4717
+ accept: "application/json",
4718
+ name: "contexts",
4719
+ start: 0,
4720
+ limit,
4721
+ count: 1,
4722
+ version: 2,
4723
+ items: [contextBody(contextNameFrom(request.query?.filter))],
4724
+ links: linksFor(
4725
+ "/compute/contexts",
4726
+ "application/vnd.sas.compute.context",
4727
+ true
4728
+ )
4729
+ }
4730
+ };
4731
+ },
4732
+ "POST /compute/contexts/{}/sessions": async ({
4733
+ services,
4734
+ params,
4735
+ request
4736
+ }) => {
4737
+ if (params.id !== EMULATED_CONTEXT_ID)
4738
+ throw new ApiError(404, `Context with ID '${params.id}' was not found.`);
4739
+ const body = request.body ?? {};
4740
+ const session = estateOf(services).create();
4741
+ return {
4742
+ status: 201,
4743
+ body: sessionBody(
4744
+ services,
4745
+ session,
4746
+ body.environment?.autoExecLines ?? []
4747
+ )
4748
+ };
4749
+ },
4750
+ "GET /compute/sessions/{}/state": async ({ services, params }) => {
4751
+ sessionOf(services, params.id);
4752
+ return { status: 200, body: "idle" };
4753
+ },
4754
+ "DELETE /compute/sessions/{}": async ({ services, params }) => {
4755
+ sessionOf(services, params.id);
4756
+ estateOf(services).remove(params.id);
4757
+ return { status: 204, body: void 0 };
4758
+ },
4759
+ "POST /compute/sessions/{}/jobs": async ({ services, params, request }) => {
4760
+ const session = sessionOf(services, params.id);
4761
+ const job = estateOf(services).submit(
4762
+ session,
4763
+ request.body ?? {}
4764
+ );
4765
+ return { status: 201, body: jobBody(job) };
4766
+ },
4767
+ "GET /compute/sessions/{}/jobs/{}": async ({ services, params }) => {
4768
+ const [sessionId, jobId] = segmentsOf(params);
4769
+ return { status: 200, body: jobBody(jobOf(services, sessionId, jobId)) };
4770
+ },
4771
+ "GET /compute/sessions/{}/jobs/{}/state": async ({ services, params }) => {
4772
+ const [sessionId, jobId] = segmentsOf(params);
4773
+ return {
4774
+ status: 200,
4775
+ body: jobOf(services, sessionId, jobId).state
4776
+ };
4777
+ },
4778
+ "GET /compute/sessions/{}/jobs/{}/log/content": async ({
4779
+ services,
4780
+ params,
4781
+ request
4782
+ }) => {
4783
+ const [sessionId, jobId] = segmentsOf(params);
4784
+ const job = jobOf(services, sessionId, jobId);
4785
+ const start = Number(request.query?.start ?? 0) || 0;
4786
+ const limit = Number(request.query?.limit ?? 0) || 0;
4787
+ const lines = job.log.slice(start, limit ? start + limit : void 0);
4788
+ return {
4789
+ status: 200,
4790
+ body: {
4791
+ accept: "application/json",
4792
+ name: "content",
4793
+ start,
4794
+ limit: limit || lines.length,
4795
+ count: job.log.length,
4796
+ version: 2,
4797
+ items: lines.map((line) => ({ line, type: "NOTE", version: 2 })),
4798
+ links: linksFor(
4799
+ `/compute/sessions/${job.sessionId}/jobs/${job.id}/log`,
4800
+ "application/vnd.sas.compute.job.log",
4801
+ false,
4802
+ true
4803
+ )
4804
+ }
4805
+ };
4806
+ }
4807
+ };
4808
+
4809
+ // src/viya/files.ts
4810
+ var contentTypeOf = (name) => {
4811
+ if (/\.sas$/i.test(name)) return "text/plain";
4812
+ if (/\.(json)$/i.test(name)) return "application/json";
4813
+ if (/\.(csv|txt|log)$/i.test(name)) return "text/plain";
4814
+ if (/\.(html?)$/i.test(name)) return "text/html";
4815
+ if (/\.(png)$/i.test(name)) return "image/png";
4816
+ if (/\.(jpe?g)$/i.test(name)) return "image/jpeg";
4817
+ return "application/octet-stream";
4818
+ };
4819
+ var fileBody = (file) => {
4820
+ const id = idFor(file.path, "file");
4821
+ const uri = `/files/files/${id}`;
4822
+ const contentType = contentTypeOf(file.name);
4823
+ return {
4824
+ id,
4825
+ name: file.name,
4826
+ contentType,
4827
+ contentDisposition: `attachment; filename="${file.name}"`,
4828
+ encoding: "UTF-8",
4829
+ size: file.size,
4830
+ fileStatus: "complete",
4831
+ fileVersion: 1,
4832
+ version: 2,
4833
+ typeDefName: "file",
4834
+ createdBy: EMULATED_USER.id,
4835
+ modifiedBy: EMULATED_USER.id,
4836
+ creationTimeStamp: EMULATED_NOW,
4837
+ modifiedTimeStamp: EMULATED_NOW,
4838
+ quarantine: false,
4839
+ searchable: true,
4840
+ virusDetected: false,
4841
+ urlDetected: false,
4842
+ properties: {
4843
+ "content.download": "true",
4844
+ "content.openInBrowser": "true",
4845
+ "content.preview": "false",
4846
+ sasIconKey: "file",
4847
+ typeRegistrant: EMULATED_USER.id
4848
+ },
4849
+ links: [
4850
+ {
4851
+ href: uri,
4852
+ uri,
4853
+ rel: "self",
4854
+ method: "GET",
4855
+ type: "application/vnd.sas.file"
4856
+ },
4857
+ {
4858
+ href: `${uri}/content`,
4859
+ uri: `${uri}/content`,
4860
+ rel: "content",
4861
+ method: "GET",
4862
+ type: "application/vnd.sas.file.content"
4863
+ }
4864
+ ]
4865
+ };
4866
+ };
4867
+ var utf8Length2 = (text2) => {
4868
+ let bytes3 = 0;
4869
+ for (const character of text2) {
4870
+ const point = character.codePointAt(0);
4871
+ bytes3 += point < 128 ? 1 : point < 2048 ? 2 : point < 65536 ? 3 : 4;
4872
+ }
4873
+ return bytes3;
4874
+ };
4875
+ var sizeOf = (contents) => typeof contents === "string" ? utf8Length2(contents) : contents.byteLength;
4876
+ var filesIn = async (drive) => {
4877
+ const walk2 = (node, found) => {
4878
+ if (!node.isFolder)
4879
+ found.push({ name: node.name, path: node.relativePath, size: 0 });
4880
+ for (const child of node.children) walk2(child, found);
4881
+ return found;
4882
+ };
4883
+ return walk2((await drive.tree("/")).tree, []);
4884
+ };
4885
+ var pathForFileId = async (drive, id) => {
4886
+ const file = (await filesIn(drive)).find(
4887
+ (candidate) => idFor(candidate.path, "file") === id
4888
+ );
4889
+ if (!file) throw new ApiError(404, `File with ID '${id}' was not found.`);
4890
+ return file.path;
4891
+ };
4892
+ var bodyOf = async (drive, path) => {
4893
+ const read = await drive.read(path);
4894
+ return {
4895
+ name: path.split("/").pop(),
4896
+ path,
4897
+ size: sizeOf(read.contents)
4898
+ };
4899
+ };
4900
+ var parentOf = async (drive, uri) => {
4901
+ if (!uri) return "/";
4902
+ const id = uri.split("/").pop();
4903
+ const tree = await drive.tree("/");
4904
+ const walk2 = (node) => {
4905
+ if (node.isFolder && idFor(node.relativePath, "folder") === id)
4906
+ return node.relativePath;
4907
+ for (const child of node.children) {
4908
+ const hit = walk2(child);
4909
+ if (hit !== void 0) return hit;
4910
+ }
4911
+ return void 0;
4912
+ };
4913
+ const found = walk2(tree.tree);
4914
+ if (found === void 0)
4915
+ throw new ApiError(404, `Folder with ID '${id}' was not found.`);
4916
+ return found;
4917
+ };
4918
+ var FILE_HANDLERS = {
4919
+ "POST /files/files": async ({ services, request }) => {
4920
+ const drive = requireDrive(services);
4921
+ const upload = request.file;
4922
+ if (!upload?.name)
4923
+ throw new ApiError(400, "A file named `file` is required.");
4924
+ const parent = await parentOf(drive, request.query?.parentFolderUri);
4925
+ const path = `${parent}/${upload.name}`.replace(/\/{2,}/g, "/");
4926
+ await drive.save(path, upload.contents);
4927
+ return { status: 201, body: fileBody(await bodyOf(drive, path)) };
4928
+ },
4929
+ "GET /files/files/{}": async ({ services, params }) => {
4930
+ const drive = requireDrive(services);
4931
+ const path = await pathForFileId(drive, params.id);
4932
+ return { status: 200, body: fileBody(await bodyOf(drive, path)) };
4933
+ },
4934
+ "PATCH /files/files/{}": async ({ services, params, request }) => {
4935
+ const drive = requireDrive(services);
4936
+ const path = await pathForFileId(drive, params.id);
4937
+ const body = request.body ?? {};
4938
+ const name = body.name ?? path.split("/").pop();
4939
+ const target = `${path.split("/").slice(0, -1).join("/")}/${name}`.replace(
4940
+ /\/{2,}/g,
4941
+ "/"
4942
+ );
4943
+ if (target !== path) await drive.rename(path, target);
4944
+ return { status: 200, body: fileBody(await bodyOf(drive, target)) };
4945
+ },
4946
+ "GET /files/files/{}/content": async ({ services, params }) => {
4947
+ const drive = requireDrive(services);
4948
+ const path = await pathForFileId(drive, params.id);
4949
+ const read = await drive.read(path);
4950
+ return {
4951
+ status: 200,
4952
+ contents: read.contents,
4953
+ headers: {
4954
+ "content-type": contentTypeOf(path.split("/").pop())
4955
+ }
4956
+ };
4957
+ },
4958
+ "PUT /files/files/{}/content": async ({ services, params, request }) => {
4959
+ const drive = requireDrive(services);
4960
+ const path = await pathForFileId(drive, params.id);
4961
+ const body = request.body;
4962
+ const contents = request.file?.contents ?? (typeof body === "string" ? body : body?.contents);
4963
+ if (contents === void 0 || contents === null)
4964
+ throw new ApiError(400, "File content is required.");
4965
+ await drive.update(path, contents);
4966
+ return { status: 200, body: fileBody(await bodyOf(drive, path)) };
4967
+ }
4968
+ };
4969
+
4970
+ // src/viya/service.ts
4971
+ var linksFor2 = (uri, collection = false) => {
4972
+ const self = {
4973
+ href: uri,
4974
+ uri,
4975
+ rel: "self",
4976
+ method: "GET",
4977
+ type: "application/vnd.sas.folder"
4978
+ };
4979
+ const members = {
4980
+ href: `${uri}/members`,
4981
+ uri: `${uri}/members`,
4982
+ rel: "members",
4983
+ method: "GET",
4984
+ type: "application/vnd.sas.collection",
4985
+ itemType: "folder"
4986
+ };
4987
+ return collection ? [members, self] : [self, members];
4988
+ };
4989
+ var folderBody = async (drive, path) => {
4990
+ const listing = await drive.list(path);
4991
+ const id = idFor(path);
4992
+ const name = path.split("/").filter(Boolean).pop() ?? "";
4993
+ const parent = path.split("/").slice(0, -1).join("/") || "/";
4994
+ return {
4995
+ id,
4996
+ name,
4997
+ description: "",
4998
+ type: "folder",
4999
+ version: 1,
5000
+ createdBy: EMULATED_USER.id,
5001
+ modifiedBy: EMULATED_USER.id,
5002
+ creationTimeStamp: EMULATED_NOW,
5003
+ modifiedTimeStamp: EMULATED_NOW,
5004
+ memberCount: listing.files.length + listing.folders.length,
5005
+ parentFolderUri: `/folders/folders/${idFor(parent)}`,
5006
+ links: linksFor2(`/folders/folders/${id}`)
5007
+ };
5008
+ };
5009
+ var recycleBin = () => {
5010
+ const path = "@myRecycleBin";
5011
+ const id = idFor(path);
5012
+ return {
5013
+ id,
5014
+ name: "Recycle Bin",
5015
+ description: "Recycle Bin",
5016
+ type: "trashFolder",
5017
+ version: 1,
5018
+ createdBy: EMULATED_USER.id,
5019
+ modifiedBy: EMULATED_USER.id,
5020
+ creationTimeStamp: EMULATED_NOW,
5021
+ modifiedTimeStamp: EMULATED_NOW,
5022
+ memberCount: 0,
5023
+ parentFolderUri: "",
5024
+ properties: { allowMove: "false" },
5025
+ links: linksFor2(`/folders/folders/${id}`)
5026
+ };
5027
+ };
5028
+ var pathFromQuery = (request) => {
5029
+ const path = request.query?.path;
5030
+ if (!path) throw new ApiError(400, "The path parameter is required.");
5031
+ return normalisePath(path);
5032
+ };
5033
+ var RECYCLE_BIN_ALIAS = "/folders/folders/@myRecycleBin";
5034
+ var isRecycleBin = (uri) => !!uri && (uri === RECYCLE_BIN_ALIAS || uri.endsWith(`/${idFor("@myRecycleBin")}`));
5035
+ var pathForId = async (drive, id) => {
5036
+ const walk2 = (node) => {
5037
+ if (node.isFolder && idFor(node.relativePath) === id)
5038
+ return node.relativePath;
5039
+ for (const child of node.children) {
5040
+ const hit = walk2(child);
5041
+ if (hit) return hit;
5042
+ }
5043
+ return void 0;
5044
+ };
5045
+ const { tree } = await drive.tree("/");
5046
+ const path = walk2(tree);
5047
+ if (!path)
5048
+ throw new ApiError(
5049
+ 404,
5050
+ `No folder matches the id ${id}. Ids are derived from paths, so an id that names no folder is one no folder ever had.`
5051
+ );
5052
+ return path;
5053
+ };
5054
+ var VIYA_HANDLERS = {
5055
+ "GET /identities/users/@currentUser": async ({ services, request }) => {
5056
+ const subject = request.subject ?? await services.identity?.authenticate(request.token);
5057
+ const id = subject?.userId ?? EMULATED_USER.id;
5058
+ return {
5059
+ status: 200,
5060
+ body: {
5061
+ id,
5062
+ name: subject?.userId ?? EMULATED_USER.name,
5063
+ providerId: "sas",
5064
+ state: "active",
5065
+ version: 1,
5066
+ addresses: [],
5067
+ emailAddresses: [],
5068
+ links: [
5069
+ {
5070
+ href: `/identities/users/${id}`,
5071
+ uri: `/identities/users/${id}`,
5072
+ rel: "self",
5073
+ method: "GET",
5074
+ type: "application/vnd.sas.identity.user"
5075
+ }
5076
+ ]
5077
+ }
5078
+ };
5079
+ },
5080
+ "GET /types/types": async () => ({
5081
+ status: 200,
5082
+ body: {
5083
+ count: 1,
5084
+ items: [
5085
+ {
5086
+ name: "file",
5087
+ type: "typeDef",
5088
+ version: 1,
5089
+ links: [{ href: "/types/types/file", rel: "self", method: "GET" }]
5090
+ }
5091
+ ]
5092
+ }
5093
+ }),
5094
+ "GET /folders/folders/@item": async ({ services, request }) => ({
5095
+ status: 200,
5096
+ body: await folderBody(requireDrive(services), pathFromQuery(request))
5097
+ }),
5098
+ "GET /folders/folders/@myRecycleBin": async () => ({
5099
+ status: 200,
5100
+ body: recycleBin()
5101
+ }),
5102
+ "GET /folders/folders/{}": async ({ services, params }) => {
5103
+ if (params.id === idFor("@myRecycleBin"))
5104
+ return { status: 200, body: recycleBin() };
5105
+ const drive = requireDrive(services);
5106
+ return {
5107
+ status: 200,
5108
+ body: await folderBody(drive, await pathForId(drive, params.id))
5109
+ };
5110
+ },
5111
+ "GET /folders/folders/{}/members": async ({ services, params, request }) => {
5112
+ const drive = requireDrive(services);
5113
+ const limit = Number(request.query?.limit ?? 0) || 0;
5114
+ if (params.id === idFor("@myRecycleBin"))
5115
+ return {
5116
+ status: 200,
5117
+ body: {
5118
+ accept: "application/json",
5119
+ name: "members",
5120
+ start: 0,
5121
+ // the query value is echoed as the sibling branch echoes it: a caller
5122
+ // that asked for five and is told zero cannot tell what happened
5123
+ limit,
5124
+ count: 0,
5125
+ version: 2,
5126
+ items: [],
5127
+ links: linksFor2(`/folders/folders/${idFor("@myRecycleBin")}`, true)
5128
+ }
5129
+ };
5130
+ const path = await pathForId(drive, params.id);
5131
+ const listing = await drive.list(path);
5132
+ const items = [
5133
+ ...listing.folders.map((name) => ({
5134
+ id: idFor(`${path}/${name}`.replace(/\/{2,}/g, "/")),
5135
+ name,
5136
+ type: "folder",
5137
+ version: 1,
5138
+ createdBy: EMULATED_USER.id,
5139
+ modifiedBy: EMULATED_USER.id,
5140
+ creationTimeStamp: EMULATED_NOW,
5141
+ modifiedTimeStamp: EMULATED_NOW,
5142
+ parentFolderUri: `/folders/folders/${idFor(path)}`,
5143
+ uri: `${path}/${name}`.replace(/\/{2,}/g, "/"),
5144
+ links: linksFor2(
5145
+ `/folders/folders/${idFor(`${path}/${name}`.replace(/\/{2,}/g, "/"))}`
5146
+ )
5147
+ })),
5148
+ ...listing.files.map((name) => ({
5149
+ id: idFor(`${path}/${name}`.replace(/\/{2,}/g, "/"), "file"),
5150
+ name,
5151
+ type: "file",
5152
+ version: 1,
5153
+ contentType: "text/plain",
5154
+ createdBy: EMULATED_USER.id,
5155
+ modifiedBy: EMULATED_USER.id,
5156
+ creationTimeStamp: EMULATED_NOW,
5157
+ modifiedTimeStamp: EMULATED_NOW,
5158
+ parentFolderUri: `/folders/folders/${idFor(path)}`,
5159
+ added: EMULATED_NOW,
5160
+ uri: `${path}/${name}`.replace(/\/{2,}/g, "/"),
5161
+ links: linksFor2(
5162
+ `/files/files/${idFor(`${path}/${name}`.replace(/\/{2,}/g, "/"), "file")}`
5163
+ )
5164
+ }))
5165
+ ];
5166
+ const page = limit > 0 ? items.slice(0, limit) : items;
5167
+ return {
5168
+ status: 200,
5169
+ body: {
5170
+ accept: "application/json",
5171
+ name: "members",
5172
+ start: 0,
5173
+ limit: limit || page.length,
5174
+ count: page.length,
5175
+ version: 2,
5176
+ items: page,
5177
+ links: linksFor2(`/folders/folders/${idFor(path)}`, true)
5178
+ }
5179
+ };
5180
+ },
5181
+ "POST /folders/folders": async ({ services, request }) => {
5182
+ const drive = requireDrive(services);
5183
+ const body = request.body ?? {};
5184
+ if (!body.name) throw new ApiError(400, "A folder name is required.");
5185
+ const parentUri = request.query?.parentFolderUri ?? body.parentFolderUri;
5186
+ const parent = parentUri ? await pathForId(drive, String(parentUri).split("/").pop()) : "/";
5187
+ const path = normalisePath(`${parent}/${body.name}`);
5188
+ await drive.mkdir(path);
5189
+ return { status: 201, body: await folderBody(drive, path) };
5190
+ },
5191
+ "PATCH /folders/folders/{}": async ({ services, request, params }) => {
5192
+ const drive = requireDrive(services);
5193
+ if (params.id === idFor("@myRecycleBin"))
5194
+ throw new ApiError(400, "The recycle bin cannot be moved or renamed.");
5195
+ const path = await pathForId(drive, params.id);
5196
+ const body = request.body ?? {};
5197
+ if (isRecycleBin(body.parentFolderUri)) {
5198
+ const removed = await folderBody(drive, path);
5199
+ await drive.rmdir(path);
5200
+ return {
5201
+ status: 200,
5202
+ body: { ...removed, parentFolderUri: String(body.parentFolderUri) }
5203
+ };
5204
+ }
5205
+ const name = body.name ?? path.split("/").pop();
5206
+ const parent = body.parentFolderUri === void 0 ? path.split("/").slice(0, -1).join("/") || "/" : body.parentFolderUri === "" ? "/" : await pathForId(
5207
+ drive,
5208
+ body.parentFolderUri.split("/").pop()
5209
+ );
5210
+ const target = normalisePath(`${parent}/${name}`);
5211
+ if (target !== path) await drive.rename(path, target);
5212
+ return { status: 200, body: await folderBody(drive, target) };
5213
+ },
5214
+ ...COMPUTE_HANDLERS,
5215
+ ...FILE_HANDLERS
5216
+ };
5217
+
5218
+ // src/viya/dispatch.ts
5219
+ var escape2 = (segment) => segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
5220
+ var compiled2 = VIYA_TABLE.filter(
5221
+ (operation) => operation.path.includes("{}")
5222
+ ).map((operation) => ({
5223
+ operation,
5224
+ pattern: new RegExp(
5225
+ "^" + operation.path.split("/").map((segment) => segment === "{}" ? "([^/]+)" : escape2(segment)).join("/") + "$",
5226
+ // the static segments ignore case, as the hosts do
5227
+ "i"
5228
+ )
5229
+ }));
5230
+ var exact2 = /* @__PURE__ */ new Map();
5231
+ for (const operation of VIYA_TABLE)
5232
+ if (!operation.path.includes("{}"))
5233
+ exact2.set(`${operation.method} ${operation.path}`.toLowerCase(), operation);
5234
+ var findViyaOperation = (method, path) => {
5235
+ const verb = method.toUpperCase();
5236
+ const clean = path.split("?")[0].replace(/\/+$/, "") || "/";
5237
+ const staticHit = exact2.get(`${verb} ${clean}`.toLowerCase());
5238
+ if (staticHit) return { operation: staticHit, segments: [] };
5239
+ for (const candidate of compiled2) {
5240
+ if (candidate.operation.method !== verb) continue;
5241
+ const match = candidate.pattern.exec(clean);
5242
+ if (match)
5243
+ return {
5244
+ operation: candidate.operation,
5245
+ segments: match.slice(1).map((segment) => {
5246
+ try {
5247
+ return decodeURIComponent(segment);
5248
+ } catch {
5249
+ return segment;
5250
+ }
5251
+ })
5252
+ };
5253
+ }
5254
+ return void 0;
5255
+ };
5256
+ var dispatchViya = async (services, method, path, request = {}) => {
5257
+ const headers = emulatedHeaders();
5258
+ const found = findViyaOperation(method, path);
5259
+ if (!found)
5260
+ return {
5261
+ status: 404,
5262
+ headers,
5263
+ body: {
5264
+ version: 2,
5265
+ httpStatusCode: 404,
5266
+ errorCode: 404,
5267
+ message: `No operation is emulated at ${method.toUpperCase()} ${path}. The emulated estate answers the client's call surface and nothing else.`
5268
+ }
5269
+ };
5270
+ const entry = VIYA_OVERLAY[found.operation.id];
5271
+ if (!entry)
5272
+ return {
5273
+ status: 501,
5274
+ headers,
5275
+ body: { message: `${found.operation.id} has no decision in the overlay.` }
5276
+ };
5277
+ if (!entry.implemented)
5278
+ return {
5279
+ status: 501,
5280
+ headers,
5281
+ body: {
5282
+ message: `${found.operation.id} is not emulated. ${entry.reason ?? ""}`.trim()
5283
+ }
5284
+ };
5285
+ const handler = VIYA_HANDLERS[found.operation.id];
5286
+ if (!handler)
5287
+ return {
5288
+ status: 501,
5289
+ headers,
5290
+ body: {
5291
+ message: `${found.operation.id} is marked implemented, but no handler answers it.`
5292
+ }
5293
+ };
5294
+ try {
5295
+ const answer = await handler({
5296
+ services,
5297
+ request,
5298
+ params: {
5299
+ id: found.segments[0],
5300
+ segments: found.segments
5301
+ }
5302
+ });
5303
+ return {
5304
+ ...answer,
5305
+ // the emulated headers are spread LAST: they are the invariant this module
5306
+ // exists to guarantee, so a handler cannot overwrite the stamp even by
5307
+ // returning headers of its own
5308
+ headers: { ...answer.headers, ...headers }
5309
+ };
5310
+ } catch (error) {
5311
+ if (isApiError(error))
5312
+ return {
5313
+ status: error.status,
5314
+ headers,
5315
+ body: error.body ?? {
5316
+ version: 2,
5317
+ httpStatusCode: error.status,
5318
+ errorCode: error.status,
5319
+ message: error.message
5320
+ }
5321
+ };
5322
+ return {
5323
+ status: 500,
5324
+ headers,
5325
+ body: {
5326
+ version: 2,
5327
+ httpStatusCode: 500,
5328
+ errorCode: 500,
5329
+ message: String(error?.message ?? error)
5330
+ }
5331
+ };
5332
+ }
5333
+ };
5334
+
5335
+ // src/corpus/viya/operations.ts
5336
+ var VIYA_CORPUS = [
5337
+ {
5338
+ route: "GET /compute/contexts",
5339
+ step: "compute/context-by-name",
5340
+ queries: ["filter", "limit"],
5341
+ statuses: [200],
5342
+ expected: 200,
5343
+ shape: {
5344
+ accept: "string",
5345
+ count: "number",
5346
+ items: [
5347
+ {
5348
+ createdBy: "string",
5349
+ id: "string",
5350
+ links: [
5351
+ {
5352
+ href: "string",
5353
+ method: "string",
5354
+ rel: "string",
5355
+ type: "string",
5356
+ uri: "string"
5357
+ }
5358
+ ],
5359
+ name: "string",
5360
+ version: "number"
5361
+ }
5362
+ ],
5363
+ limit: "number",
5364
+ links: [
5365
+ {
5366
+ href: "string",
5367
+ itemType: "string",
5368
+ method: "string",
5369
+ rel: "string",
5370
+ type: "string",
5371
+ uri: "string"
5372
+ }
5373
+ ],
5374
+ name: "string",
5375
+ start: "number",
5376
+ version: "number"
5377
+ }
5378
+ },
5379
+ {
5380
+ route: "POST /compute/contexts/{}/sessions",
5381
+ step: "compute/execute-script",
5382
+ queries: [],
5383
+ statuses: [201],
5384
+ expected: 201,
5385
+ shape: {
5386
+ applicationName: "string",
5387
+ attributes: {
5388
+ homeDirectory: "string",
5389
+ sessionInactiveTimeout: "number"
5390
+ },
5391
+ creationTimeStamp: "string",
5392
+ environment: {
5393
+ autoExecLines: ["string"]
5394
+ },
5395
+ id: "string",
5396
+ links: [
5397
+ {
5398
+ href: "string",
5399
+ method: "string",
5400
+ rel: "string",
5401
+ type: "string",
5402
+ uri: "string"
5403
+ }
5404
+ ],
5405
+ owner: "string",
5406
+ serverId: "string",
5407
+ serviceAPIVersion: "number",
5408
+ sessionConditionCode: "number",
5409
+ state: "string",
5410
+ stateElapsedTime: "number",
5411
+ version: "number"
5412
+ }
5413
+ },
5414
+ {
5415
+ route: "DELETE /compute/sessions/{}",
5416
+ step: "compute/session-delete",
5417
+ queries: [],
5418
+ statuses: [204],
5419
+ expected: 204,
5420
+ shape: void 0
5421
+ },
5422
+ {
5423
+ route: "POST /compute/sessions/{}/jobs",
5424
+ step: "compute/execute-script",
5425
+ queries: [],
5426
+ statuses: [201],
5427
+ expected: 201,
5428
+ shape: {
5429
+ creationTimeStamp: "string",
5430
+ id: "string",
5431
+ links: [
5432
+ {
5433
+ href: "string",
5434
+ method: "string",
5435
+ rel: "string",
5436
+ type: "string",
5437
+ uri: "string"
5438
+ }
5439
+ ],
5440
+ sessionId: "string",
5441
+ state: "string",
5442
+ stateElapsedTime: "number",
5443
+ version: "number"
5444
+ }
5445
+ },
5446
+ {
5447
+ route: "GET /compute/sessions/{}/jobs/{}",
5448
+ step: "compute/execute-script",
5449
+ queries: [],
5450
+ statuses: [200],
5451
+ expected: 200,
5452
+ shape: {
5453
+ completedTimeStamp: "string",
5454
+ creationTimeStamp: "string",
5455
+ id: "string",
5456
+ jobConditionCode: "number",
5457
+ links: [
5458
+ {
5459
+ href: "string",
5460
+ method: "string",
5461
+ rel: "string",
5462
+ type: "string",
5463
+ uri: "string"
5464
+ }
5465
+ ],
5466
+ listingStatistics: {
5467
+ lineCount: "number",
5468
+ modifiedTimeStamp: "string"
5469
+ },
5470
+ logStatistics: {
5471
+ lineCount: "number",
5472
+ modifiedTimeStamp: "string"
5473
+ },
5474
+ sessionId: "string",
5475
+ state: "string",
5476
+ stateElapsedTime: "number",
5477
+ statistics: {
5478
+ systemCpuTime: "number",
5479
+ userCpuTime: "number"
5480
+ },
5481
+ version: "number"
5482
+ }
5483
+ },
5484
+ {
5485
+ route: "GET /compute/sessions/{}/jobs/{}/log/content",
5486
+ step: "compute/execute-script",
5487
+ queries: ["limit", "start"],
5488
+ statuses: [200],
5489
+ expected: 200,
5490
+ shape: {
5491
+ accept: "string",
5492
+ count: "number",
5493
+ items: [
5494
+ {
5495
+ line: "string",
5496
+ type: "string",
5497
+ version: "number"
5498
+ }
5499
+ ],
5500
+ limit: "number",
5501
+ links: [
5502
+ {
5503
+ href: "string",
5504
+ itemType: "string",
5505
+ method: "string",
5506
+ rel: "string",
5507
+ type: "string",
5508
+ uri: "string"
5509
+ }
5510
+ ],
5511
+ name: "string",
5512
+ start: "number",
5513
+ version: "number"
5514
+ }
5515
+ },
5516
+ {
5517
+ route: "GET /compute/sessions/{}/jobs/{}/state",
5518
+ step: "compute/execute-script",
5519
+ queries: ["_action", "wait"],
5520
+ statuses: [200],
5521
+ expected: 200,
5522
+ shape: void 0
5523
+ },
5524
+ {
5525
+ route: "GET /compute/sessions/{}/state",
5526
+ step: "compute/execute-script",
5527
+ queries: ["wait"],
5528
+ statuses: [200],
5529
+ expected: 200,
5530
+ shape: void 0
5531
+ },
5532
+ {
5533
+ route: "POST /files/files",
5534
+ step: "files/create",
5535
+ queries: ["parentFolderUri", "typeDefName"],
5536
+ statuses: [201],
5537
+ expected: 201,
5538
+ shape: {
5539
+ contentDisposition: "string",
5540
+ contentType: "string",
5541
+ createdBy: "string",
5542
+ creationTimeStamp: "string",
5543
+ encoding: "string",
5544
+ fileStatus: "string",
5545
+ fileVersion: "number",
5546
+ id: "string",
5547
+ links: [
5548
+ {
5549
+ href: "string",
5550
+ method: "string",
5551
+ rel: "string",
5552
+ type: "string",
5553
+ uri: "string"
5554
+ }
5555
+ ],
5556
+ modifiedBy: "string",
5557
+ modifiedTimeStamp: "string",
5558
+ name: "string",
5559
+ properties: {},
5560
+ quarantine: "boolean",
5561
+ searchable: "boolean",
5562
+ size: "number",
5563
+ typeDefName: "string",
5564
+ urlDetected: "boolean",
5565
+ version: "number",
5566
+ virusDetected: "boolean"
5567
+ }
5568
+ },
5569
+ {
5570
+ route: "GET /files/files/{}",
5571
+ step: "files/replace",
5572
+ queries: [],
5573
+ statuses: [200],
5574
+ expected: 200,
5575
+ shape: {
5576
+ contentDisposition: "string",
5577
+ contentType: "string",
5578
+ createdBy: "string",
5579
+ creationTimeStamp: "string",
5580
+ encoding: "string",
5581
+ fileStatus: "string",
5582
+ fileVersion: "number",
5583
+ id: "string",
5584
+ links: [
5585
+ {
5586
+ href: "string",
5587
+ method: "string",
5588
+ rel: "string",
5589
+ type: "string",
5590
+ uri: "string"
5591
+ }
5592
+ ],
5593
+ modifiedBy: "string",
5594
+ modifiedTimeStamp: "string",
5595
+ name: "string",
5596
+ properties: {
5597
+ "content.download": "string",
5598
+ "content.openInBrowser": "string",
5599
+ "content.preview": "string",
5600
+ sasIconKey: "string",
5601
+ typeRegistrant: "string"
5602
+ },
5603
+ quarantine: "boolean",
5604
+ searchable: "boolean",
5605
+ size: "number",
5606
+ typeDefName: "string",
5607
+ urlDetected: "boolean",
5608
+ version: "number",
5609
+ virusDetected: "boolean"
5610
+ }
5611
+ },
5612
+ {
5613
+ route: "PATCH /files/files/{}",
5614
+ step: "files/create",
5615
+ queries: [],
5616
+ statuses: [200],
5617
+ expected: 200,
5618
+ shape: {
5619
+ contentDisposition: "string",
5620
+ contentType: "string",
5621
+ createdBy: "string",
5622
+ creationTimeStamp: "string",
5623
+ encoding: "string",
5624
+ fileStatus: "string",
5625
+ fileVersion: "number",
5626
+ id: "string",
5627
+ links: [
5628
+ {
5629
+ href: "string",
5630
+ method: "string",
5631
+ rel: "string",
5632
+ type: "string",
5633
+ uri: "string"
5634
+ }
5635
+ ],
5636
+ modifiedBy: "string",
5637
+ modifiedTimeStamp: "string",
5638
+ name: "string",
5639
+ properties: {
5640
+ "content.download": "string",
5641
+ "content.openInBrowser": "string",
5642
+ "content.preview": "string",
5643
+ sasIconKey: "string",
5644
+ typeRegistrant: "string"
5645
+ },
5646
+ quarantine: "boolean",
5647
+ searchable: "boolean",
5648
+ size: "number",
5649
+ typeDefName: "string",
5650
+ urlDetected: "boolean",
5651
+ version: "number",
5652
+ virusDetected: "boolean"
5653
+ }
5654
+ },
5655
+ {
5656
+ route: "GET /files/files/{}/content",
5657
+ step: "files/content",
5658
+ queries: [],
5659
+ statuses: [200],
5660
+ expected: 200,
5661
+ shape: void 0
5662
+ },
5663
+ {
5664
+ route: "PUT /files/files/{}/content",
5665
+ step: "files/replace",
5666
+ queries: [],
5667
+ statuses: [200],
5668
+ expected: 200,
5669
+ shape: {
5670
+ contentDisposition: "string",
5671
+ contentType: "string",
5672
+ createdBy: "string",
5673
+ creationTimeStamp: "string",
5674
+ encoding: "string",
5675
+ fileStatus: "string",
5676
+ fileVersion: "number",
5677
+ id: "string",
5678
+ links: [
5679
+ {
5680
+ href: "string",
5681
+ method: "string",
5682
+ rel: "string",
5683
+ type: "string",
5684
+ uri: "string"
5685
+ }
5686
+ ],
5687
+ modifiedBy: "string",
5688
+ modifiedTimeStamp: "string",
5689
+ name: "string",
5690
+ properties: {
5691
+ "content.download": "string",
5692
+ "content.openInBrowser": "string",
5693
+ "content.preview": "string",
5694
+ sasIconKey: "string",
5695
+ typeRegistrant: "string"
5696
+ },
5697
+ quarantine: "boolean",
5698
+ searchable: "boolean",
5699
+ size: "number",
5700
+ typeDefName: "string",
5701
+ urlDetected: "boolean",
5702
+ version: "number",
5703
+ virusDetected: "boolean"
5704
+ }
5705
+ },
5706
+ {
5707
+ route: "POST /folders/folders",
5708
+ step: "folders/create",
5709
+ queries: ["parentFolderUri"],
5710
+ statuses: [201],
5711
+ expected: 201,
5712
+ shape: {
5713
+ createdBy: "string",
5714
+ creationTimeStamp: "string",
5715
+ id: "string",
5716
+ links: [
5717
+ {
5718
+ href: "string",
5719
+ method: "string",
5720
+ rel: "string",
5721
+ type: "string",
5722
+ uri: "string"
5723
+ }
5724
+ ],
5725
+ memberCount: "number",
5726
+ modifiedBy: "string",
5727
+ modifiedTimeStamp: "string",
5728
+ name: "string",
5729
+ parentFolderUri: "string",
5730
+ type: "string",
5731
+ version: "number"
5732
+ }
5733
+ },
5734
+ {
5735
+ route: "GET /folders/folders/{}",
5736
+ step: "folders/delete",
5737
+ queries: [],
5738
+ statuses: [200],
5739
+ expected: 200,
5740
+ shape: {
5741
+ createdBy: "string",
5742
+ creationTimeStamp: "string",
5743
+ description: "string",
5744
+ id: "string",
5745
+ links: [
5746
+ {
5747
+ href: "string",
5748
+ method: "string",
5749
+ rel: "string",
5750
+ type: "string",
5751
+ uri: "string"
5752
+ }
5753
+ ],
5754
+ memberCount: "number",
5755
+ modifiedBy: "string",
5756
+ modifiedTimeStamp: "string",
5757
+ name: "string",
5758
+ parentFolderUri: "string",
5759
+ properties: {
5760
+ allowMove: "string"
5761
+ },
5762
+ type: "string",
5763
+ version: "number"
5764
+ }
5765
+ },
5766
+ {
5767
+ route: "PATCH /folders/folders/{}",
5768
+ step: "folders/delete",
5769
+ queries: [],
5770
+ statuses: [200],
5771
+ expected: 200,
5772
+ shape: {
5773
+ createdBy: "string",
5774
+ creationTimeStamp: "string",
5775
+ id: "string",
5776
+ links: [
5777
+ {
5778
+ href: "string",
5779
+ method: "string",
5780
+ rel: "string",
5781
+ type: "string",
5782
+ uri: "string"
5783
+ }
5784
+ ],
5785
+ memberCount: "number",
5786
+ modifiedBy: "string",
5787
+ modifiedTimeStamp: "string",
5788
+ name: "string",
5789
+ parentFolderUri: "string",
5790
+ type: "string",
5791
+ version: "number"
5792
+ }
5793
+ },
5794
+ {
5795
+ route: "GET /folders/folders/{}/members",
5796
+ step: "files/content",
5797
+ queries: ["limit"],
5798
+ statuses: [200],
5799
+ expected: 200,
5800
+ shape: {
5801
+ accept: "string",
5802
+ count: "number",
5803
+ items: [
5804
+ {
5805
+ added: "string",
5806
+ contentType: "string",
5807
+ createdBy: "string",
5808
+ creationTimeStamp: "string",
5809
+ id: "string",
5810
+ links: [
5811
+ {
5812
+ href: "string",
5813
+ method: "string",
5814
+ rel: "string",
5815
+ type: "string",
5816
+ uri: "string"
5817
+ }
5818
+ ],
5819
+ modifiedBy: "string",
5820
+ modifiedTimeStamp: "string",
5821
+ name: "string",
5822
+ parentFolderUri: "string",
5823
+ type: "string",
5824
+ uri: "string",
5825
+ version: "number"
5826
+ }
5827
+ ],
5828
+ limit: "number",
5829
+ links: [
5830
+ {
5831
+ href: "string",
5832
+ itemType: "string",
5833
+ method: "string",
5834
+ rel: "string",
5835
+ type: "string",
5836
+ uri: "string"
5837
+ }
5838
+ ],
5839
+ name: "string",
5840
+ start: "number",
5841
+ version: "number"
5842
+ }
5843
+ },
5844
+ {
5845
+ route: "GET /folders/folders/@item",
5846
+ step: "files/content",
5847
+ queries: ["path"],
5848
+ statuses: [200, 401, 404],
5849
+ expected: 200,
5850
+ shape: {
5851
+ createdBy: "string",
5852
+ creationTimeStamp: "string",
5853
+ description: "string",
5854
+ id: "string",
5855
+ links: [
5856
+ {
5857
+ href: "string",
5858
+ method: "string",
5859
+ rel: "string",
5860
+ type: "string",
5861
+ uri: "string"
5862
+ }
5863
+ ],
5864
+ memberCount: "number",
5865
+ modifiedBy: "string",
5866
+ modifiedTimeStamp: "string",
5867
+ name: "string",
5868
+ parentFolderUri: "string",
5869
+ type: "string",
5870
+ version: "number"
5871
+ }
5872
+ },
5873
+ {
5874
+ route: "GET /folders/folders/@myRecycleBin",
5875
+ step: "folders/delete",
5876
+ queries: [],
5877
+ statuses: [200],
5878
+ expected: 200,
5879
+ shape: {
5880
+ createdBy: "string",
5881
+ creationTimeStamp: "string",
5882
+ description: "string",
5883
+ id: "string",
5884
+ links: [
5885
+ {
5886
+ href: "string",
5887
+ method: "string",
5888
+ rel: "string",
5889
+ type: "string",
5890
+ uri: "string"
5891
+ }
5892
+ ],
5893
+ memberCount: "number",
5894
+ modifiedBy: "string",
5895
+ modifiedTimeStamp: "string",
5896
+ name: "string",
5897
+ parentFolderUri: "string",
5898
+ properties: {
5899
+ allowMove: "string"
5900
+ },
5901
+ type: "string",
5902
+ version: "number"
5903
+ }
5904
+ },
5905
+ {
5906
+ route: "GET /identities/users/@currentUser",
5907
+ step: "identities/current-user",
5908
+ queries: [],
5909
+ statuses: [200],
5910
+ expected: 200,
5911
+ shape: {
5912
+ addresses: [
5913
+ {
5914
+ locality: "string",
5915
+ type: "string"
5916
+ }
5917
+ ],
5918
+ emailAddresses: [
5919
+ {
5920
+ type: "string",
5921
+ value: "string"
5922
+ }
5923
+ ],
5924
+ id: "string",
5925
+ links: [
5926
+ {
5927
+ href: "string",
5928
+ method: "string",
5929
+ rel: "string",
5930
+ type: "string",
5931
+ uri: "string"
5932
+ }
5933
+ ],
5934
+ name: "string",
5935
+ providerId: "string",
5936
+ state: "string",
5937
+ version: "number"
5938
+ }
5939
+ },
5940
+ {
5941
+ route: "POST /SASLogon/oauth/token",
5942
+ step: "auth/token-refresh",
5943
+ queries: [],
5944
+ statuses: [200, 401],
5945
+ expected: 200,
5946
+ shape: {
5947
+ access_token: "string",
5948
+ expires_in: "number",
5949
+ id_token: "string",
5950
+ jti: "string",
5951
+ refresh_expires_in: "number",
5952
+ refresh_revocable: "boolean",
5953
+ refresh_token: "string",
5954
+ revocable: "boolean",
5955
+ scope: "string",
5956
+ token_type: "string"
5957
+ }
5958
+ },
5959
+ {
5960
+ route: "GET /types/types",
5961
+ step: "files/create",
5962
+ queries: ["limit"],
5963
+ statuses: [200],
5964
+ expected: 200,
5965
+ shape: void 0
5966
+ }
5967
+ ];
5968
+
3567
5969
  // src/appstream/identity.ts
3568
5970
  var normaliseAppLoc = (appLoc) => {
3569
5971
  if (typeof appLoc !== "string" || appLoc === "")