redefine message as subclass of shape:record
This commit is contained in:
parent
32c4f5ced1
commit
e9f9abd4a0
7 changed files with 27 additions and 21 deletions
|
@ -4,6 +4,7 @@
|
||||||
(:use :common-lisp)
|
(:use :common-lisp)
|
||||||
(:local-nicknames (:config :scopes/config)
|
(:local-nicknames (:config :scopes/config)
|
||||||
(:message :scopes/core/message)
|
(:message :scopes/core/message)
|
||||||
|
(:shape :scopes/shape)
|
||||||
(:alx :alexandria))
|
(:alx :alexandria))
|
||||||
(:export #:*root* #:default-setup #:default-actions
|
(:export #:*root* #:default-setup #:default-actions
|
||||||
#:find-service #:setup-services
|
#:find-service #:setup-services
|
||||||
|
@ -20,7 +21,7 @@
|
||||||
(handlers :accessor handlers :initarg :handlers)))
|
(handlers :accessor handlers :initarg :handlers)))
|
||||||
|
|
||||||
(defun select (msg acts)
|
(defun select (msg acts)
|
||||||
(let ((h (message:head msg))
|
(let ((h (shape:head msg))
|
||||||
(hdlrs nil))
|
(hdlrs nil))
|
||||||
(dolist (a acts)
|
(dolist (a acts)
|
||||||
(if (match (pattern a) h)
|
(if (match (pattern a) h)
|
||||||
|
@ -107,9 +108,9 @@
|
||||||
(defun echo (ctx msg)
|
(defun echo (ctx msg)
|
||||||
(let ((sndr (message:sender msg)))
|
(let ((sndr (message:sender msg)))
|
||||||
(if sndr
|
(if sndr
|
||||||
(let* ((h (message:head msg))
|
(let* ((h (shape:head msg))
|
||||||
(new-msg (message:create `(:scopes :echo ,@(cddr h))
|
(new-msg (message:create `(:scopes :echo ,@(cddr h))
|
||||||
:data (message:data msg))))
|
:data (shape:data msg))))
|
||||||
(send sndr new-msg))
|
(send sndr new-msg))
|
||||||
(log:warn "sender missing: ~s" msg))))
|
(log:warn "sender missing: ~s" msg))))
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
(defpackage :scopes/core/message
|
(defpackage :scopes/core/message
|
||||||
(:use :common-lisp)
|
(:use :common-lisp)
|
||||||
|
(:local-nicknames (:shape :scopes/shape))
|
||||||
(:export #:message #:create
|
(:export #:message #:create
|
||||||
#:head #:data #:sender))
|
#:head #:data #:sender))
|
||||||
|
|
||||||
|
@ -9,14 +10,14 @@
|
||||||
|
|
||||||
;;;; message
|
;;;; message
|
||||||
|
|
||||||
(defclass message ()
|
(defclass message (shape:record)
|
||||||
((head :reader head :initarg :head)
|
((shape:head-fields :initform '(:domain :action :class :item))
|
||||||
(sender :reader sender :initarg :sender :initform nil)
|
(sender :reader sender :initarg :sender :initform nil)
|
||||||
(timestamp)
|
(timestamp)))
|
||||||
(data :accessor data :initarg :data :initform nil)))
|
|
||||||
|
|
||||||
(defun create (head &key data sender)
|
(defun create (head &key data sender)
|
||||||
(make-instance 'message :head head :data data :sender sender))
|
(make-instance 'message :head head :data data :sender sender))
|
||||||
|
|
||||||
(defmethod print-object ((msg message) stream)
|
(defmethod print-object ((msg message) stream)
|
||||||
(format stream "<message ~s ~s <data ~s>>" (head msg) (sender msg) (data msg)))
|
(format stream "<message ~s ~s <data ~s>>"
|
||||||
|
(shape:head msg) (sender msg) (shape:data msg)))
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
(:local-nicknames (:dom :scopes/web/dom)
|
(:local-nicknames (:dom :scopes/web/dom)
|
||||||
(:message :scopes/core/message)
|
(:message :scopes/core/message)
|
||||||
(:response :scopes/web/response)
|
(:response :scopes/web/response)
|
||||||
|
(:shape :scopes/shape)
|
||||||
(:util :scopes/util))
|
(:util :scopes/util))
|
||||||
(:import-from :scopes/web/dom #:div #:label)
|
(:import-from :scopes/web/dom #:div #:label)
|
||||||
(:export #:render-content #:response))
|
(:export #:render-content #:response))
|
||||||
|
@ -16,9 +17,9 @@
|
||||||
(defclass response (response:html-response) ())
|
(defclass response (response:html-response) ())
|
||||||
|
|
||||||
(defmethod response:render-content ((resp response) msg)
|
(defmethod response:render-content ((resp response) msg)
|
||||||
;(dom:render (dom:dlist nil (message:data msg))))
|
;(dom:render (dom:dlist nil (shape:data msg))))
|
||||||
(dom:render
|
(dom:render
|
||||||
(div nil (util:loop-plist (message:data msg) k v collect (view-field k v)))))
|
(div nil (util:loop-plist (shape:data msg) k v collect (view-field k v)))))
|
||||||
|
|
||||||
(defun view-field (label value)
|
(defun view-field (label value)
|
||||||
(div nil (label nil label) ": " value))
|
(div nil (label nil label) ": " value))
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
(defclass record ()
|
(defclass record ()
|
||||||
((head-fields :reader head-fields :initarg :head-fields
|
((head-fields :reader head-fields :initarg :head-fields
|
||||||
:initform '(:taskid :username) :allocation :class)
|
:initform '(:taskid :username) :allocation :class)
|
||||||
(head :accessor head :initarg :head)
|
(head :reader head :initarg :head)
|
||||||
(data :accessor data :initform nil)))
|
(data :accessor data :initarg :data :initform nil)))
|
||||||
|
|
||||||
(defun head-plist (track)
|
(defun head-plist (track)
|
||||||
(let (pl (hv (head track)))
|
(let (pl (hv (head track)))
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
(:core :scopes/core)
|
(:core :scopes/core)
|
||||||
(:logging :scopes/logging)
|
(:logging :scopes/logging)
|
||||||
(:message :scopes/core/message)
|
(:message :scopes/core/message)
|
||||||
|
(:shape :scopes/shape)
|
||||||
(:util :scopes/util)
|
(:util :scopes/util)
|
||||||
(:t :scopes/testing))
|
(:t :scopes/testing))
|
||||||
(:export #:run #:user #:password)
|
(:export #:run #:user #:password)
|
||||||
|
@ -24,18 +25,18 @@
|
||||||
(core:default-setup cfg 'test-receiver))
|
(core:default-setup cfg 'test-receiver))
|
||||||
|
|
||||||
(defun check-message (ctx msg)
|
(defun check-message (ctx msg)
|
||||||
(let ((key (message:head msg)))
|
(let ((key (shape:head msg)))
|
||||||
(multiple-value-bind (val found) (gethash key (expected ctx))
|
(multiple-value-bind (val found) (gethash key (expected ctx))
|
||||||
(if found
|
(if found
|
||||||
(progn
|
(progn
|
||||||
(if (not (equalp (message:data msg) val))
|
(if (not (equalp (shape:data msg) val))
|
||||||
(t:failure "data mismatch: ~s, expected: ~s" msg val))
|
(t:failure "data mismatch: ~s, expected: ~s" msg val))
|
||||||
(remhash key (expected ctx)))
|
(remhash key (expected ctx)))
|
||||||
(t:failure "unexpected: ~s" msg)))))
|
(t:failure "unexpected: ~s" msg)))))
|
||||||
|
|
||||||
(defun expect (ctx msg)
|
(defun expect (ctx msg)
|
||||||
(setf (gethash (message:head msg) (expected ctx))
|
(setf (gethash (shape:head msg) (expected ctx))
|
||||||
(message:data msg)))
|
(shape:data msg)))
|
||||||
|
|
||||||
(defun check-expected ()
|
(defun check-expected ()
|
||||||
(let ((exp (alx:hash-table-keys (expected (receiver t:*test-suite*)))))
|
(let ((exp (alx:hash-table-keys (expected (receiver t:*test-suite*)))))
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
(:local-nicknames (:config :scopes/config)
|
(:local-nicknames (:config :scopes/config)
|
||||||
(:core :scopes/core)
|
(:core :scopes/core)
|
||||||
(:message :scopes/core/message)
|
(:message :scopes/core/message)
|
||||||
|
(:shape :scopes/shape)
|
||||||
(:alx :alexandria))
|
(:alx :alexandria))
|
||||||
(:export #:config #:base-url #:api-path #:doc-path
|
(:export #:config #:base-url #:api-path #:doc-path
|
||||||
#:get-page #:send-message))
|
#:get-page #:send-message))
|
||||||
|
@ -22,7 +23,7 @@
|
||||||
|
|
||||||
(defun get-page (ctx msg)
|
(defun get-page (ctx msg)
|
||||||
(let* ((cfg (core:config ctx))
|
(let* ((cfg (core:config ctx))
|
||||||
(path (getf (message:data msg) :path))
|
(path (getf (shape:data msg) :path))
|
||||||
(url (str:concat (base-url cfg) (doc-path cfg) path)))
|
(url (str:concat (base-url cfg) (doc-path cfg) path)))
|
||||||
(dex:get url :headers '(("Accept". "text/html")))))
|
(dex:get url :headers '(("Accept". "text/html")))))
|
||||||
|
|
||||||
|
@ -30,11 +31,11 @@
|
||||||
(let* ((cfg (core:config ctx))
|
(let* ((cfg (core:config ctx))
|
||||||
(url (str:concat (base-url cfg) (api-path cfg) (msgpath msg))))
|
(url (str:concat (base-url cfg) (api-path cfg) (msgpath msg))))
|
||||||
(dex:post url
|
(dex:post url
|
||||||
:content (data-as-alist (message:data msg))
|
:content (data-as-alist (shape:data msg))
|
||||||
:headers `(("Accept" . ,(accept cfg))))))
|
:headers `(("Accept" . ,(accept cfg))))))
|
||||||
|
|
||||||
(defun msgpath (msg)
|
(defun msgpath (msg)
|
||||||
(str:join "/" (loop for p in (message:head msg)
|
(str:join "/" (loop for p in (shape:head msg)
|
||||||
when p collect (string-downcase p))))
|
when p collect (string-downcase p))))
|
||||||
|
|
||||||
(defun data-as-alist (data)
|
(defun data-as-alist (data)
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
(defpackage :scopes/web/response
|
(defpackage :scopes/web/response
|
||||||
(:use :common-lisp)
|
(:use :common-lisp)
|
||||||
(:local-nicknames (:dom :scopes/web/dom)
|
(:local-nicknames (:dom :scopes/web/dom)
|
||||||
(:message :scopes/core/message))
|
(:message :scopes/core/message)
|
||||||
|
(:shape :scopes/shape))
|
||||||
(:export #:setup
|
(:export #:setup
|
||||||
#:html-response
|
#:html-response
|
||||||
#:render #:render-content #:render-not-found))
|
#:render #:render-content #:render-not-found))
|
||||||
|
@ -31,7 +32,7 @@
|
||||||
((ctype :initform "text/html")))
|
((ctype :initform "text/html")))
|
||||||
|
|
||||||
(defmethod render-content ((resp html-response) msg)
|
(defmethod render-content ((resp html-response) msg)
|
||||||
(dom:render (dom:dlist nil (message:data msg))))
|
(dom:render (dom:dlist nil (shape:data msg))))
|
||||||
|
|
||||||
;;;; common definitions
|
;;;; common definitions
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue