datomic

Ask questions on the official Q&A site at https://ask.datomic.com!
2021-06-13T00:43:53.196500Z

@jarrodctaylor thanks a lot for the response. It looks like i do get the expected headers from curl:

< HTTP/2 200 
< date: Sun, 13 Jun 2021 00:39:24 GMT
< content-type: application/edn
< content-length: 847
< x-amzn-requestid: ef6a364c-55a7-430b-a2c0-8b2ede0e7bc5
< access-control-allow-origin: *
< access-control-allow-headers: Authorization, Content-Type
< x-amz-apigw-id: A1oFbEOxiYcFutA=
< access-control-allow-methods: GET, PUT, PATCH, POST, DELETE, OPTIONS
< x-amzn-trace-id: Root=1-60c553bc-5652c3b90fe79f8437318ff7;Sampled=0
<
full curl with -v (let me know if i need to pass more options)
➜  ion-starter git:(add-pomodoro-mode) curl -v <https://41z0jhoj4i.execute-api.us-east-2.amazonaws.com/dev/datomic/> -d :hat 
*   Trying 3.23.22.174:443...
* TCP_NODELAY set
* Connected to <http://41z0jhoj4i.execute-api.us-east-2.amazonaws.com|41z0jhoj4i.execute-api.us-east-2.amazonaws.com> (3.23.22.174) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=*.<http://execute-api.us-east-2.amazonaws.com|execute-api.us-east-2.amazonaws.com>
*  start date: Aug 29 00:00:00 2020 GMT
*  expire date: Sep 28 12:00:00 2021 GMT
*  subjectAltName: host "<http://41z0jhoj4i.execute-api.us-east-2.amazonaws.com|41z0jhoj4i.execute-api.us-east-2.amazonaws.com>" matched cert's "*.<http://execute-api.us-east-2.amazonaws.com|execute-api.us-east-2.amazonaws.com>"
*  issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x55ebe17c7e10)
&gt; POST /dev/datomic/ HTTP/2
&gt; Host: <http://41z0jhoj4i.execute-api.us-east-2.amazonaws.com|41z0jhoj4i.execute-api.us-east-2.amazonaws.com>
&gt; user-agent: curl/7.68.0
&gt; accept: */*
&gt; content-length: 4
&gt; content-type: application/x-www-form-urlencoded
&gt; 
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
* We are completely uploaded and fine
&lt; HTTP/2 200 
&lt; date: Sun, 13 Jun 2021 00:39:24 GMT
&lt; content-type: application/edn
&lt; content-length: 847
&lt; x-amzn-requestid: ef6a364c-55a7-430b-a2c0-8b2ede0e7bc5
&lt; access-control-allow-origin: *
&lt; access-control-allow-headers: Authorization, Content-Type
&lt; x-amz-apigw-id: A1oFbEOxiYcFutA=
&lt; access-control-allow-methods: GET, PUT, PATCH, POST, DELETE, OPTIONS
&lt; x-amzn-trace-id: Root=1-60c553bc-5652c3b90fe79f8437318ff7;Sampled=0
&lt; 
[[#:inv{:sku "SKU-51", :size :small, :color :yellow}]
 [#:inv{:sku "SKU-47", :size :xlarge, :color :blue}]
 [#:inv{:sku "SKU-39", :size :medium, :color :blue}]
 [#:inv{:sku "SKU-19", :size :small, :color :green}]
 [#:inv{:sku "SKU-55", :size :medium, :color :yellow}]
 [#:inv{:sku "SKU-15", :size :xlarge, :color :red}]
 [#:inv{:sku "SKU-35", :size :small, :color :blue}]
 [#:inv{:sku "SKU-27", :size :large, :color :green}]
 [#:inv{:sku "SKU-63", :size :xlarge, :color :yellow}]
 [#:inv{:sku "SKU-3", :size :small, :color :red}]
 [#:inv{:sku "SKU-43", :size :large, :color :blue}]
 [#:inv{:sku "SKU-59", :size :large, :color :yellow}]
 [#:inv{:sku "SKU-31", :size :xlarge, :color :green}]
 [#:inv{:sku "SKU-7", :size :medium, :color :red}]
 [#:inv{:sku "SKU-11", :size :large, :color :red}]
 [#:inv{:sku "SKU-23", :size :medium, :color :green}]]
* Connection #0 to host <http://41z0jhoj4i.execute-api.us-east-2.amazonaws.com|41z0jhoj4i.execute-api.us-east-2.amazonaws.com> left intact
Maybe my js/fetch call is off? the content-type? I don't see why that would be a cors issues.

jarrodctaylor 2021-06-13T01:20:23.196700Z

I do believe your issue is with the fetch call. You want to provide js as the argument. Perhaps something like

(js/fetch "<https://41z0jhoj4i.execute-api.us-east-2.amazonaws.com/dev/datomic/>"
          (clj-&gt;js {:mode    "cors"
                    :method  "POST"
                    :headers {"Content-Type" "text/plain"}
                    :body    ":hat"}))

jarrodctaylor 2021-06-13T01:20:34.196900Z

@drewverlee ^

2021-06-13T01:25:13.197300Z

Your clearly right that I would need to pass the map to clj to js. I was using lambs island fetch and I forgot to change the args when I switched to pure JS.

jarrodctaylor 2021-06-13T01:44:46.197600Z

Happens to all of us 🙂

2021-06-13T03:30:01.199600Z

I am using datomic client api and hence I have the (d/q foobar) function calls in my codebase. During testing, I want to mask out these functions and return faked ones. What’s the recommended approach to do that? Going with with-redefs or extending some protocol, if the latter, what protocol?

2021-06-14T11:16:54.204400Z

The db object implements a protocol that supplies (the implementation of) d/q. What we have in our app is a wrapper that intercepts some of those protocol functions and (possibly) amends/replaces their implementation. For one, we have a wrapper for d/q logging queries and their results to a tap.

2021-06-15T14:21:44.214Z

Hi. Can you be more concrete on a wrapper intercepting the protocol function?

2021-06-15T14:21:59.214200Z

How do you achieve this functionality?

kschltz 2021-06-15T17:13:36.215200Z

you could achieve that via a defrecord implementing said protocol

2021-06-15T17:51:00.217800Z

Yeah, we just have a deftype somewhere that forwards most calls to the ‘original’ db/`connection`/`client`, but amends their implementation:

(deftype MyWrappedDb [orig]
  datomic.impl/Queryable
  (q [_ arg-map] (println arg-map) (datomic.impl/q orig arg-map))
  ...)
That said, I’m not saying you should do this — I think its perhaps better to use dev-local to create a memory db for testing, but if you ever feel like you need to intercept calls on db values, this is a way to do so.

Joe Lane 2021-06-15T18:00:12.218700Z

@i that protocol is an impl detail and subject to change. I'd like to go back to your original problem statement. What problem will you solve when you "mask out these functions and return faked ones."?

2021-06-15T23:41:45.222200Z

I want to avoid connecting to real database for testing some functions that indirectly writes to db.

Joe Lane 2021-06-16T13:36:06.223400Z

On-Prem or cloud?

Joe Lane 2021-06-16T14:12:24.223600Z

Both https://docs.datomic.com/on-prem/peer/peer-getting-started.html and https://docs.datomic.com/cloud/dev-local.html have equivalent memory databases which you could create and tear down for every unit-test, no production-code modification required.