@@ -29,11 +29,11 @@ Index Repository On repository;
29
29
30
30
Property dependencies As array Of %String ;
31
31
32
- Property package As %Stream .GlobalBinary (%JSONINCLUDE = " INPUTONLY" ) [ Required ] ;
32
+ Property package As %Stream .GlobalBinary (%JSONINCLUDE = " INPUTONLY" );
33
33
34
34
Property size As %Integer (%JSONINCLUDE = " OUTPUTONLY" );
35
35
36
- Property manifest As %Stream .GlobalCharacter (%JSONINCLUDE = " INPUTONLY" ) [ Required ] ;
36
+ Property manifest As %Stream .GlobalCharacter (%JSONINCLUDE = " INPUTONLY" );
37
37
38
38
Property installer As %Stream .GlobalCharacter (%JSONINCLUDE = " INPUTONLY" );
39
39
@@ -55,6 +55,12 @@ Property versionPrerelease As %String [ SqlComputeCode = {Set {*} = $Piece($Piec
55
55
56
56
Property versionBuildmetadata As %String [ SqlComputeCode = {Set {*} = $Piece ({version }," +" ,2 )}, SqlComputed , SqlComputeOnChange = %%INSERT ];
57
57
58
+ Property UpLink As ZPM .UpLink (%JSONINCLUDE = " NONE" );
59
+
60
+ ForeignKey UpLinkFK (UpLink ) References ZPM .UpLink () [ OnDelete = cascade ];
61
+
62
+ Index NameUpLink On (name , UpLink );
63
+
58
64
Method nameSet (value As %String ) As %Status
59
65
{
60
66
set i%name = $$$lcase(value )
@@ -68,8 +74,9 @@ Method sizeGet() As %Integer
68
74
69
75
ClassMethod GetPackageHash (pStream As %Stream .Object ) As %String
70
76
{
71
- If '$isobject (pStream ) Set pStream = ..packageOpen (pStream )
72
- set hash = $system .Encryption .SHA1HashStream (pStream )
77
+ If (pStream =" " ) { Return " " }
78
+ If '$isobject (pStream ) { Set pStream = ..packageOpen (pStream ) }
79
+ Set hash = $system .Encryption .SHA1HashStream (pStream )
73
80
Set str =" "
74
81
For i =1 :1 :$length (hash ) {
75
82
Set str =str _$translate ($justify ($zhex ($ascii (hash , i )),2 )," " ,0 )
@@ -79,18 +86,19 @@ ClassMethod GetPackageHash(pStream As %Stream.Object) As %String
79
86
80
87
ClassMethod ServerURL () As %String
81
88
{
82
- SET host = " "
83
- IF $ISOBJECT ($GET (%request )) {
84
- set tSecure = %request .Secure
85
- SET host = %request .GetCgiEnv (" HTTP_X_FORWARDED_HOST" , %request .GetCgiEnv (" SERVER_NAME" ))
86
- set proto = %request .GetCgiEnv (" HTTP_X_FORWARDED_PROTO" , $SELECT (tSecure : " https" , 1 : " http" ))
87
- SET port = %request .GetCgiEnv (" HTTP_X_FORWARDED_PORT" , %request .GetCgiEnv (" SERVER_PORT" ))
88
- SET host = proto _ " ://" _ host
89
- IF '$LISTFIND ($LISTBUILD (80 , 443 ), port ) {
90
- SET host = host _" :" _port
89
+ Set host = " "
90
+ If $ISOBJECT ($Get (%request )) {
91
+ Set tSecure = %request .Secure
92
+ Set host = %request .GetCgiEnv (" HTTP_X_FORWARDED_HOST" , %request .GetCgiEnv (" SERVER_NAME" ))
93
+ Set proto = %request .GetCgiEnv (" HTTP_X_FORWARDED_PROTO" , $SELECT (tSecure : " https" , 1 : " http" ))
94
+ Set port = %request .GetCgiEnv (" HTTP_X_FORWARDED_PORT" , %request .GetCgiEnv (" SERVER_PORT" ))
95
+ Set host = proto _ " ://" _ host
96
+ If '$LISTFIND ($LISTBUILD (80 , 443 ), port ) {
97
+ Set host = host _" :" _port
91
98
}
92
99
}
93
- RETURN host
100
+ //Set host = host_$p(%request.Application,"/",1,*-1)
101
+ Return host
94
102
}
95
103
96
104
Method urlGet () As %String
@@ -135,6 +143,62 @@ Method versionsGet() As %ListOfDataTypes
135
143
return tList
136
144
}
137
145
146
+ ClassMethod VersionFind (pkg As %String = " " , version As %String = " " ) As %String
147
+ {
148
+ If (version = " " ) || (version = " latest" ) || (version = " *" ) {
149
+ // package was published directly in this registry - return the last version
150
+ &sql (SELECT TOP 1 Version INTO :version FROM ZPM .Package WHERE Name = :pkg AND UpLink IS NULL
151
+ ORDER BY versionMajor DESC , versionMinor DESC , versionPatch DESC , versionPrerelease DESC , versionBuildmetadata DESC
152
+ )
153
+ If SQLCODE =0 {
154
+ // found
155
+ Return version
156
+ } Else {
157
+ // find the latest version in UpLinks
158
+ Do ##class (ZPM.UpLink ).LoadPackageFromAllUpLinks (pkg , " latest" )
159
+ &sql (SELECT TOP 1 Version INTO :version FROM ZPM .Package WHERE Name = :pkg
160
+ ORDER BY versionMajor DESC , versionMinor DESC , versionPatch DESC , versionPrerelease DESC , versionBuildmetadata DESC
161
+ )
162
+ If SQLCODE =0 {
163
+ // if manifest doesn''t exists - find in uplinks
164
+ Set package = ##class (ZPM.Package ).%OpenId (pkg _" ||" _version )
165
+ If ('$IsObject (package )) { Return " " }
166
+ If (package .manifest .Size ) { Return version }
167
+ Do ##class (ZPM.UpLink ).LoadPackageFromAllUpLinks (pkg , version )
168
+ Return version
169
+ }
170
+ Return " "
171
+ }
172
+ } Else {
173
+ If ( ##class (ZPM.Package ).NameUpLinkExists (pkg , " " ) ) {
174
+ If ..%ExistsId (pkg _ " ||" _ version ) {
175
+ Return version
176
+ }
177
+ Return " "
178
+ } Else {
179
+ If ..%ExistsId (pkg _ " ||" _ version ) {
180
+ Set package = ##class (ZPM.Package ).%OpenId (pkg _" ||" _version )
181
+ If ('$IsObject (package )) { Return " " }
182
+ If (package .manifest .Size ) { Return version }
183
+ }
184
+ Do ##class (ZPM.UpLink ).LoadPackageFromAllUpLinks (pkg , version )
185
+ If ..%ExistsId (pkg _ " ||" _ version ) {
186
+ Return version
187
+ }
188
+ Return " "
189
+ }
190
+ }
191
+ }
192
+
193
+ ClassMethod DeleteExistingPackages (pkg , version ) As %Status
194
+ {
195
+ // delete all "proxy" packages
196
+ &sql (DELETE FROM ZPM .Package WHERE Name = :pkg AND UpLink IS NOT NULL )
197
+
198
+ Do ..NameVersionDelete (pkg , version )
199
+ Return 1
200
+ }
201
+
138
202
ClassMethod versionValidate (pkg As %String = " " , version As %String = " " ) As %String
139
203
{
140
204
if (pkg =" " ) {
@@ -250,7 +314,7 @@ ClassMethod LoadPackage(Path As %String, repository As %String = "", silent As %
250
314
WRITE " ArchiveSize: " _ archive .Size
251
315
}
252
316
253
- do ..%DeleteId (name _ " || " _ version )
317
+ do ..DeleteExistingPackages (name , version )
254
318
SET package = ..%New ()
255
319
SET package .name = name
256
320
Set package .description = description
@@ -281,7 +345,7 @@ ClassMethod GetDefaultBranch(path As %String) As %String
281
345
Set branch = " main"
282
346
Set ht = ##class (%Net.HttpRequest ).%New ()
283
347
Set ht .Server = " api.github.com"
284
- Set ht .SSLConfiguration = . .GetSSLConfiguration (ht . Server )
348
+ Set ht .SSLConfiguration = ##class ( ZPM.Utils ) .GetSSLConfiguration ()
285
349
Set ht .Https = 1
286
350
Set ht .Location = " /repos" _path
287
351
$$$ThrowOnError(ht .Get ())
@@ -299,7 +363,7 @@ ClassMethod DownloadPackageFromGitHub(url As %String, Output branch As %String)
299
363
Set ht = ##class (%Net.HttpRequest ).%New ()
300
364
Set ht .Server = tComponents (" host" )
301
365
If $get (tComponents (" scheme" ))=" https" {
302
- Set ht .SSLConfiguration = . .GetSSLConfiguration (ht . Server )
366
+ Set ht .SSLConfiguration = ##class ( ZPM.Utils ) .GetSSLConfiguration ()
303
367
Set ht .Https = 1
304
368
}
305
369
If $data (tComponents (" port" ), port ), port '=" " {
@@ -330,7 +394,7 @@ ClassMethod GetModuleMeta(url As %String) As %DynamicObject
330
394
Set ht = ##class (%Net.HttpRequest ).%New ()
331
395
Set ht .Server = " raw.githubusercontent.com"
332
396
If $get (tComponents (" scheme" ))=" https" {
333
- Set ht .SSLConfiguration = . .GetSSLConfiguration (ht . Server )
397
+ Set ht .SSLConfiguration = ##class ( ZPM.Utils ) .GetSSLConfiguration ()
334
398
Set ht .Https = 1
335
399
}
336
400
If $data (tComponents (" port" ), port ), port '=" " {
@@ -341,24 +405,13 @@ ClassMethod GetModuleMeta(url As %String) As %DynamicObject
341
405
If (ht .HttpResponse .StatusCode '=200 ) {
342
406
$$$ThrowStatus($$$ERROR(5001 ," Unable to download XML " _ht .Location ))
343
407
}
344
- Set tmpFolder = $$$FileTempDir
345
-
346
- Set stream =##class (%Stream.FileCharacter ).%New ()
347
- Do stream .LinkToFile (tmpFolder _" /module.xml" )
348
- Set stream .TranslateTable = " UTF8"
349
- Do stream .CopyFrom (ht .HttpResponse .Data )
350
- Do stream .%Save ()
351
408
352
- set binaryStream =##class (%Stream.FileBinary ).%New ()
353
- do binaryStream .LinkToFile (tmpFolder _" /module.xml" )
409
+ Set xPathArray (" Module/Version" )=" "
410
+ Set xPathArray (" Module/Name" )=" "
411
+ $$$ThrowOnError(##class (ZPM.Utils ).ReadXMLElements (ht .HttpResponse .Data , .xPathArray ))
354
412
355
- $$$ThrowOnError(##class (%XML.XPATH.Document ).CreateFromStream (binaryStream , .xpathdoc ))
356
- $$$ThrowOnError(xpathdoc .EvaluateExpression (" /" ," Export/Document/Module/Version/text()" , .tResults ))
357
- set jo .version = tResults .GetAt (1 ).ValueGet ()
358
- $$$ThrowOnError(xpathdoc .EvaluateExpression (" /" ," Export/Document/Module/Name/text()" , .tResults ))
359
- set jo .name = $$$lcase(tResults .GetAt (1 ).ValueGet ())
360
-
361
- Do ##class (%File ).RemoveDirectoryTree (tmpFolder )
413
+ Set jo .name = $Get (xPathArray (" Module/Name" ," text" ))
414
+ Set jo .version = $Get (xPathArray (" Module/Version" ," text" ))
362
415
363
416
return jo
364
417
}
@@ -377,6 +430,9 @@ ClassMethod UpdatePackage(jo As %DynamicObject) As %Status
377
430
If (meta .name = " " ) { $$$ThrowStatus($$$ERROR(5001 , " Package name is empty" )) }
378
431
Set tName = meta .name
379
432
Set id = " "
433
+
434
+ &sql (DELETE FROM ZPM .Package WHERE Name = :tName AND UpLink IS NOT NULL ) // delete all "proxy" packages
435
+
380
436
&sql (SELECT ID into :id FROM ZPM .Package WHERE name= :tName ORDER BY versionMajor DESC , versionMinor DESC , versionPatch DESC , versionPrerelease DESC )
381
437
If (id '=" " ) {
382
438
If (..repositoryGetStored (id )'=url ) {
@@ -432,15 +488,66 @@ ClassMethod LoadFromGitHub(Url = "")
432
488
do ##class (%File ).RemoveDirectoryTree (outputFolder )
433
489
}
434
490
435
- ClassMethod GetSSLConfiguration ( host ) As %String
491
+ ClassMethod GetTopVersion ( pkg As %String ) As %String
436
492
{
437
- NEW $NAMESPACE
438
- SET $NAMESPACE = " %SYS"
439
-
440
- IF '##class (Security.SSLConfigs ).Exists (host ) {
441
- DO ##class (Security.SSLConfigs ).Create (host )
493
+ Set version = " "
494
+ &sql (SELECT TOP 1 version INTO :version FROM ZPM .Package
495
+ WHERE name = :pkg
496
+ ORDER BY versionMajor DESC , versionMinor DESC , versionPatch DESC , versionPrerelease DESC , versionBuildmetadata DESC )
497
+ Return version
498
+ }
499
+
500
+ /// returns latest versions of packages
501
+ ClassMethod GetLatest (searchTerms As %DynamicArray = " " , Output pStatus As %Status ) As %DynamicArray
502
+ {
503
+ Set pStatus = 1
504
+ If ( '($CLASSNAME (searchTerms )=" %Library.DynamicArray" ) || (searchTerms .%Size ()=0 ) ) {
505
+ // empty query
506
+ Set searchCondition = " ( 1=1 ) "
507
+ } Else {
508
+ Set searchCondition = " ( "
509
+ Set iter = searchTerms .%GetIterator ()
510
+ Set params = 0
511
+ While iter .%GetNext (.key , .value ) {
512
+ if (key =0 ) {
513
+ Set searchCondition = searchCondition _ " ((name %MATCHES ?) OR (description %MATCHES ?) OR (keywords %MATCHES ?)) "
514
+ } else {
515
+ Set searchCondition = searchCondition _ " OR ((name %MATCHES ?) OR (description %MATCHES ?) OR (keywords %MATCHES ?))"
516
+ }
517
+ Set params (params +1 ) = value
518
+ Set params (params +2 ) = value
519
+ Set params (params +3 ) = value
520
+ Set params = params + 3
521
+ }
522
+ Set searchCondition = searchCondition _ " ) "
523
+ }
524
+ Set sql = " SELECT name, repository, description " _
525
+ " FROM ZPM.Package p1 " _
526
+ " WHERE " _ searchCondition _
527
+ " GROUP BY name " _
528
+ " ORDER BY name"
529
+ Set tStatement = ##class (%SQL.Statement ).%New ()
530
+ Set tStatus = tStatement .%Prepare (sql )
531
+ If ($$$ISERR(tStatus )) {
532
+ Set pStatus = tStatus
533
+ Return []
534
+ }
535
+ Set tResult = tStatement .%Execute (params ...)
536
+ If (tResult .%SQLCODE <0 ) {
537
+ Set pStatus = $$$ERROR(5001 , " Error executing sql statement" )
538
+ Return []
539
+ }
540
+ Set tList = []
541
+ While tResult .%Next () {
542
+ Set tPkgInfo = {
543
+ " name" : (tResult .name ),
544
+ " description" : (tResult .Description ),
545
+ " repository" : (tResult .repository ),
546
+ " versions" : [(..GetTopVersion (tResult .name ))]
547
+ }
548
+ do tList .%Push (tPkgInfo )
442
549
}
443
- QUIT host
550
+ Return tList
444
551
}
445
552
446
553
Query ListLatest (searchTerm As %String = " " ) As %SQLQuery (ROWSPEC = " name:%String,description:%String,repository:%String,version:%String" )
@@ -517,6 +624,9 @@ Storage Default
517
624
<Value name =" 18" >
518
625
<Value >versionBuildmetadata </Value >
519
626
</Value >
627
+ <Value name =" 19" >
628
+ <Value >UpLink </Value >
629
+ </Value >
520
630
</Data >
521
631
<Data name =" dependencies" >
522
632
<Attribute >dependencies </Attribute >
0 commit comments