Skip to content

Commit

Permalink
Merge pull request #185 from ba-st/gs64-options
Browse files Browse the repository at this point in the history
Gs64 options
  • Loading branch information
gcotelli authored Apr 15, 2024
2 parents e719e37 + 75ed7c2 commit e60ad9e
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 80 deletions.
69 changes: 47 additions & 22 deletions source/BaselineOfStargate/BaselineOfStargate.class.st
Original file line number Diff line number Diff line change
@@ -1,37 +1,60 @@
Class {
#name : #BaselineOfStargate,
#superclass : #BaselineOf,
#category : #BaselineOfStargate
#name : 'BaselineOfStargate',
#superclass : 'BaselineOf',
#category : 'BaselineOfStargate',
#package : 'BaselineOfStargate'
}

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfStargate >> baseline: spec [

<baseline>
spec
for: #pharo
do: [ self
setUpDependencies: spec;
setUpPackages: spec.
spec
group: 'CI' with: 'Tests';
group: 'Examples' with: #('Deployment' 'Stargate-Examples');
group: 'Tools' with: #('Hyperspace-Tools');
group: 'Development' with: #('Tests' 'Tools')
]
spec for: #pharo do: [
self
setUpDependencies: spec;
setUpPackages: spec.
spec
group: 'CI' with: 'Tests';
group: 'Examples' with: #( 'Deployment' 'Stargate-Examples' );
group: 'Tools' with: #( 'Deployment' 'Hyperspace-Tools' );
group: 'Development' with: #( 'Tests' 'Tools' ) ]
]

{ #category : 'post-load actions' }
BaselineOfStargate >> configureAsTransientInstancesOfAll: aClassCollection [

aClassCollection do: #makeInstancesDbTransient
]

{ #category : 'post-load actions' }
BaselineOfStargate >> configureInstancesOfStargateJSONRPCClassesAsTransient [

self configureAsTransientInstancesOfAll: {
JsonRPCController.
JsonRPCRequestHandler }
]

{ #category : 'post-load actions' }
BaselineOfStargate >> configureInstancesOfStargateModelClassesAsTransient [

self configureAsTransientInstancesOfAll: {
HTTPBasedRESTfulAPI.
HttpRequestContext.
ResourceRESTfulController }
]

{ #category : #accessing }
{ #category : 'accessing' }
BaselineOfStargate >> projectClass [

^ MetacelloCypressBaselineProject
]

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfStargate >> setUpCorePackages: spec [

spec
package: 'Stargate-Model' with: [
spec postLoadDoIt: #configureInstancesOfStargateModelClassesAsTransient.
spec requires:
#( 'Buoy-Deployment' 'Hyperspace-Deployment'
'Teapot-Deployment' 'JSONWebToken-Deployment' ) ];
Expand All @@ -49,7 +72,7 @@ BaselineOfStargate >> setUpCorePackages: spec [
group: 'Deployment' with: extensionPackageName ]
]

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfStargate >> setUpDependencies: spec [

spec
Expand Down Expand Up @@ -82,7 +105,7 @@ BaselineOfStargate >> setUpDependencies: spec [
project: 'Launchpad-Deployment' copyFrom: 'Launchpad' with: [ spec loads: 'Deployment' ]
]

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfStargate >> setUpDeploymentPackages: spec [

self setUpCorePackages: spec.
Expand All @@ -105,7 +128,9 @@ BaselineOfStargate >> setUpDeploymentPackages: spec [
group: 'Metrics-HTTP' with: 'Stargate-Metrics-HTTP-Zinc-Extensions';
group: 'Deployment' with: 'Metrics-HTTP'.
spec
package: 'Stargate-JSON-RPC' with: [ spec requires: #( 'Core' 'JRPC-Deployment' ) ];
package: 'Stargate-JSON-RPC' with: [
spec postLoadDoIt: #configureInstancesOfStargateJSONRPCClassesAsTransient.
spec requires: #( 'Core' 'JRPC-Deployment' ) ];
group: 'JSON-RPC' with: 'Stargate-JSON-RPC';
group: 'Deployment' with: 'JSON-RPC'.
spec
Expand Down Expand Up @@ -145,7 +170,7 @@ BaselineOfStargate >> setUpDeploymentPackages: spec [
group: 'Deployment' with: 'Stargate-API-Skeleton'
]

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfStargate >> setUpPackages: spec [

self setUpDeploymentPackages: spec.
Expand All @@ -158,7 +183,7 @@ BaselineOfStargate >> setUpPackages: spec [
self setUpTestPackages: spec
]

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfStargate >> setUpTestPackages: spec [

spec
Expand Down
2 changes: 1 addition & 1 deletion source/BaselineOfStargate/package.st
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Package { #name : #BaselineOfStargate }
Package { #name : 'BaselineOfStargate' }
19 changes: 10 additions & 9 deletions source/Stargate-JSON-RPC/JRPCSelfContainedBlockHandler.class.st
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Class {
#name : #JRPCSelfContainedBlockHandler,
#superclass : #JRPCMessageSendHandler,
#name : 'JRPCSelfContainedBlockHandler',
#superclass : 'JRPCMessageSendHandler',
#instVars : [
'argumentNames'
],
#category : #'Stargate-JSON-RPC'
#category : 'Stargate-JSON-RPC',
#package : 'Stargate-JSON-RPC'
}

{ #category : #'instance creation' }
{ #category : 'instance creation' }
JRPCSelfContainedBlockHandler class >> forProcedureNamed: aString withArgumentNames: argumentNames evaluating: aBlock [

AssertionChecker enforce: [ aBlock argumentCount = argumentNames size ]
Expand All @@ -17,7 +18,7 @@ JRPCSelfContainedBlockHandler class >> forProcedureNamed: aString withArgumentNa
^ self new initializeForProcedureNamed: aString withArgumentNames: argumentNames evaluating: aBlock
]

{ #category : #evaluation }
{ #category : 'evaluation' }
JRPCSelfContainedBlockHandler >> executeWithArguments: anArrayOrDictionary [

| arguments |
Expand All @@ -31,7 +32,7 @@ JRPCSelfContainedBlockHandler >> executeWithArguments: anArrayOrDictionary [
^ self send: self messageSelector to: self receiver with: arguments
]

{ #category : #initialization }
{ #category : 'initialization' }
JRPCSelfContainedBlockHandler >> initializeForProcedureNamed: aString withArgumentNames: theArgumentNames evaluating: aBlock [

self
Expand All @@ -40,19 +41,19 @@ JRPCSelfContainedBlockHandler >> initializeForProcedureNamed: aString withArgume
argumentNames := theArgumentNames collect: #asString
]

{ #category : #accessing }
{ #category : 'accessing' }
JRPCSelfContainedBlockHandler >> messageSelector [

^ #valueWithArguments:
]

{ #category : #accessing }
{ #category : 'accessing' }
JRPCSelfContainedBlockHandler >> parametersNames [

^ argumentNames
]

{ #category : #private }
{ #category : 'private' }
JRPCSelfContainedBlockHandler >> send: aSelector to: aBlock with: arguments [

^ super send: aSelector to: aBlock with: ( Array with: arguments )
Expand Down
39 changes: 23 additions & 16 deletions source/Stargate-JSON-RPC/JsonRPCController.class.st
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
Class {
#name : #JsonRPCController,
#superclass : #Object,
#name : 'JsonRPCController',
#superclass : 'Object',
#instVars : [
'requestHandler',
'procedureDefinitions'
],
#category : #'Stargate-JSON-RPC'
#category : 'Stargate-JSON-RPC',
#package : 'Stargate-JSON-RPC',
#'gs_options' : [
'dbTransient'
]
}

{ #category : #'instance creation' }
{ #category : 'instance creation' }
JsonRPCController class >> configuredBy: configurationAction [

| options |
Expand All @@ -18,42 +22,45 @@ JsonRPCController class >> configuredBy: configurationAction [
^ self with: options
]

{ #category : #'instance creation' }
{ #category : 'instance creation' }
JsonRPCController class >> with: options [

^self new initializeWith: options
]

{ #category : #configuring }
{ #category : 'configuring' }
JsonRPCController >> configureAvailableProcedures [

procedureDefinitions do: [ :definition | definition value: requestHandler ]
]

{ #category : #accessing }
{ #category : 'accessing' }
JsonRPCController >> endpoint [

^ self requestHandler endpoint
]

{ #category : #initialization }
{ #category : 'initialization' }
JsonRPCController >> initializeWith: options [

procedureDefinitions := options at: #procedureDefinitions.
requestHandler := JsonRPCRequestHandler handling: ( options at: #endpoint ).
options at: #debugMode ifPresent: [ :boolean | requestHandler debugMode: boolean ].
options at: #errorHandlers
ifPresent: [ :handlers |
handlers do: [ :errorHandler | requestHandler addErrorHandler: errorHandler ] ]
requestHandler := JsonRPCRequestHandler handling:
(options at: #endpoint).
options
at: #debugMode
ifPresent: [ :boolean | requestHandler debugMode: boolean ].
options at: #errorHandlers ifPresent: [ :handlers |
handlers do: [ :errorHandler |
requestHandler addErrorHandler: errorHandler ] ]
]

{ #category : #accessing }
{ #category : 'accessing' }
JsonRPCController >> requestHandler [

^ requestHandler
]

{ #category : #accessing }
{ #category : 'accessing' }
JsonRPCController >> routes [

^ Array with: ( RouteSpecification handling: #POST
Expand All @@ -62,7 +69,7 @@ JsonRPCController >> routes [
requestHandler process: httpRequest within: requestContext ] )
]

{ #category : #configuring }
{ #category : 'configuring' }
JsonRPCController >> serverUrl: aServerUrl [

requestHandler serverUrl: aServerUrl.
Expand Down
41 changes: 23 additions & 18 deletions source/Stargate-JSON-RPC/JsonRPCRequestHandler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,72 @@
I represent a JSON RPC request handler. I'm capable of processing RPC calls.
"
Class {
#name : #JsonRPCRequestHandler,
#superclass : #Object,
#name : 'JsonRPCRequestHandler',
#superclass : 'Object',
#instVars : [
'messageProcessor',
'acceptNegotiator',
'resourceLocator'
],
#category : #'Stargate-JSON-RPC'
#category : 'Stargate-JSON-RPC',
#package : 'Stargate-JSON-RPC',
#'gs_options' : [
'dbTransient'
]
}

{ #category : #'instance creation' }
{ #category : 'instance creation' }
JsonRPCRequestHandler class >> handling: anEndpoint [

^ self new initializeResolvingLocationWith: ( ResourceLocator handling: anEndpoint )
]

{ #category : #configuring }
{ #category : 'configuring' }
JsonRPCRequestHandler >> addErrorHandler: anErrorHandler [

messageProcessor addErrorHandler: anErrorHandler
]

{ #category : #configuring }
{ #category : 'configuring' }
JsonRPCRequestHandler >> addHandlerNamed: aString evaluating: aBlock [

messageProcessor addHandlerNamed: aString block: aBlock
]

{ #category : #configuring }
{ #category : 'configuring' }
JsonRPCRequestHandler >> addHandlerNamed: aString withArgumentNames: argumentNames evaluating: aBlock [

messageProcessor addHandlerNamed: aString withArgumentsNamed: argumentNames evaluating: aBlock
]

{ #category : #configuring }
{ #category : 'configuring' }
JsonRPCRequestHandler >> debugMode: aBoolean [

messageProcessor debugMode: aBoolean
]

{ #category : #accessing }
{ #category : 'accessing' }
JsonRPCRequestHandler >> endpoint [

^ resourceLocator endpoint
]

{ #category : #initialization }
{ #category : 'initialization' }
JsonRPCRequestHandler >> initialize [

super initialize.
messageProcessor := JRPCMessageProcessor new.
acceptNegotiator := RESTfulControllerAcceptNegotiator
accepting: ( Array with: ZnMimeType applicationJson )
acceptNegotiator := RESTfulControllerAcceptNegotiator accepting:
(Array with: ZnMimeType applicationJson)
]

{ #category : #initialization }
{ #category : 'initialization' }
JsonRPCRequestHandler >> initializeResolvingLocationWith: aResourceLocator [

resourceLocator := aResourceLocator
]

{ #category : #API }
{ #category : 'API' }
JsonRPCRequestHandler >> process: httpRequest within: requestContext [

AssertionChecker
Expand All @@ -72,12 +76,13 @@ JsonRPCRequestHandler >> process: httpRequest within: requestContext [
raising: HTTPClientError unsupportedMediaType.
acceptNegotiator bestRepresentationFor: httpRequest.

^ ( messageProcessor handleJSON: httpRequest contents )
ifEmpty: [ ZnResponse accepted ]
ifNotEmpty: [ :rpcResponse | ZnResponse ok: ( ZnEntity json: rpcResponse ) ]
^ (messageProcessor handleJSON: httpRequest contents)
ifEmpty: [ ZnResponse accepted ]
ifNotEmpty: [ :rpcResponse |
ZnResponse ok: (ZnEntity json: rpcResponse) ]
]

{ #category : #configuring }
{ #category : 'configuring' }
JsonRPCRequestHandler >> serverUrl: aServerUrl [

resourceLocator baseUrl: aServerUrl
Expand Down
2 changes: 1 addition & 1 deletion source/Stargate-JSON-RPC/package.st
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Package { #name : #'Stargate-JSON-RPC' }
Package { #name : 'Stargate-JSON-RPC' }
Loading

0 comments on commit e60ad9e

Please sign in to comment.