Skip to content

Commit e971887

Browse files
committed
Refactor: clojure-SDK Converting to the new ADR and some improvements
- moved clj-kondo config to allows other lib to use the starfederation.datastar.clojure ns for their clj-kondo configs. - refactored the base SDK unit tests
1 parent 348abe6 commit e971887

File tree

57 files changed

+773
-941
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+773
-941
lines changed

examples/clojure/hello-world/src/main/example/core.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
(fn [sse]
4747
(d*/with-open-sse sse
4848
(dotimes [i msg-count]
49-
(d*/merge-fragment! sse (->frag i))
49+
(d*/patch-elements! sse (->frag i))
5050
(Thread/sleep d))))})))
5151

5252

sdk/clojure/CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
# Release notes for the Clojure SDK
22

3+
## 2025-06-22
4+
5+
### Changed
6+
7+
- The public API has seen it's main functions renamed following the new SDK ADR.
8+
Several functions have been renamed or removed:
9+
10+
| Old | new |
11+
| ------------------- | --------------------- |
12+
| `merge-fragment!` | `patch-elements!` |
13+
| `merge-fragments!` | `patch-elements-seq!` |
14+
| `remove-fragments!` | `remove-element!` |
15+
| `merge-signals!` | `patch-signals!` |
16+
| `remove-signals` | removed |
17+
18+
- All the examples and snippets have been updated following the ADR changes.
19+
20+
### Fixed
21+
22+
- The clj-kondo config file for the SDK has been moved in a
23+
`clj-kondo.exports/starfederation.datastar.clojure/sdk` directory. This change
24+
allows for other projects to use
25+
`starfederation.datastar.clojure/XXXX/config.edn` for their clj-kondo config.
26+
327
## 2025-04-07
428

529
### Added

sdk/clojure/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Using the adapter you create ring responses in your handlers:
9393
(hk-gen/->sse-response request
9494
{hk-gen/on-open
9595
(fn [sse-gen]
96-
(d*/merge-fragment! sse-gen "<div>test</div>")
96+
(d*/patch-elements! sse-gen "<div>test</div>")
9797
(d*/close-sse! sse-gen))}))
9898

9999
```
@@ -118,9 +118,9 @@ it somewhere and use it later:
118118
(swap! !connections disj sse-gen))}))
119119

120120

121-
(defn broadcast-fragment! [fragment]
121+
(defn broadcast-elements! [elements]
122122
(doseq [c @!connections]
123-
(d*/merge-fragment! c fragment)))
123+
(d*/patch-elements! c elements)))
124124

125125
```
126126

sdk/clojure/deps.edn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{:paths []
22

33
:deps {sdk/sdk {:local/root "./sdk"}
4+
io.github.tonsky/clojure-plus {:mvn/version "1.6.1"}
45
io.github.paintparty/fireworks {:mvn/version "0.10.4"}
56
com.taoensso/telemere {:mvn/version "1.0.0-RC3"}
67
com.aayushatharva.brotli4j/brotli4j {:mvn/version "1.18.0"}}

sdk/clojure/doc/Write-profiles.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ When using the `->sse-response` function we can do:
4747
on-open
4848
(fn [sse]
4949
(d*/with-open-sse sse
50-
(d*/merge-fragment! sse "some big fragment")))}))
50+
(d*/patch-elements! sse "some big element")))}))
5151
```
5252

5353
This response will have the right `Content-Encoding` header and will compress

sdk/clojure/doc/maintainers-guide.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
In the whole Datastar project:
66

77
- `examples/clojure`
8+
- `site/static/code_snippets/*.clojuresnippet`
9+
- `site/static/going_deeper/*.clojuresnippet`
10+
- `site/static/how_tos/*.clojuresnippet`
811

912
In the SDK code proper `sdk/clojure`:
1013

@@ -50,9 +53,9 @@ In the SDK code proper `sdk/clojure`:
5053
- The Clojars account is managed by Ben Croker, the DNS verification is managed by Delaney.
5154
- The Clojars deploy token is also managed by Ben and added to this repo as a GH Actions Secret
5255
- Secret name: `CLOJARS_USERNAME`
53-
Value: *the clojars account username*
56+
Value: _the clojars account username_
5457
- Secret name: `CLOJARS_PASSWORD`
55-
Value: *the clojars deploy token*
58+
Value: _the clojars deploy token_
5659
- The libraries' versions are bumped in lockstep so that there is no confusion over which version of the common lib should be used with an adapter lib.
5760

5861
The Github Actions [CI workflow for clojure](../../.github/workflows/clojure-sdk.yml) will always run the tests and produce jar artifacts.

sdk/clojure/malli-schemas/src/main/starfederation/datastar/clojure/api/common_schemas.clj

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212

1313
(def event-type-schema
1414
[:enum
15-
consts/event-type-merge-fragments
16-
consts/event-type-remove-fragments
17-
consts/event-type-merge-signals
18-
consts/event-type-remove-signals
19-
consts/event-type-execute-script])
15+
consts/event-type-patch-elements
16+
consts/event-type-patch-signals])
2017

2118
(def data-lines-schema [:seqable :string])
2219

@@ -32,50 +29,45 @@
3229
(m/validate sse-options-schema {common/id 1}))
3330

3431
;; -----------------------------------------------------------------------------
35-
(def fragment-schema :string)
36-
(def fragments-schema [:seqable :string])
32+
(def elements-schema :string)
33+
(def elements-seq-schema [:seqable :string])
3734

3835

39-
(def merge-modes-schema
36+
(def patch-modes-schema
4037
[:enum
41-
consts/fragment-merge-mode-morph
42-
consts/fragment-merge-mode-inner
43-
consts/fragment-merge-mode-outer
44-
consts/fragment-merge-mode-prepend
45-
consts/fragment-merge-mode-append
46-
consts/fragment-merge-mode-before
47-
consts/fragment-merge-mode-after
48-
consts/fragment-merge-mode-upsert-attributes])
38+
consts/element-patch-mode-outer
39+
consts/element-patch-mode-inner
40+
consts/element-patch-mode-replace
41+
consts/element-patch-mode-prepend
42+
consts/element-patch-mode-append
43+
consts/element-patch-mode-before
44+
consts/element-patch-mode-after
45+
consts/element-patch-mode-remove])
4946

5047
(comment
51-
(m/validate merge-modes-schema consts/fragment-merge-mode-after)
52-
(m/validate merge-modes-schema "toto"))
48+
(m/validate patch-modes-schema consts/element-patch-mode-after)
49+
(m/validate patch-modes-schema "toto"))
5350

5451

55-
(def merge-fragment-options-schemas
52+
(def patch-element-options-schemas
5653
(mu/merge
5754
sse-options-schema
5855
(mu/optional-keys
5956
[:map
6057
[common/selector :string]
61-
[common/merge-mode merge-modes-schema]
58+
[common/patch-mode patch-modes-schema]
6259
[common/use-view-transition :boolean]])))
6360

6461
;; -----------------------------------------------------------------------------
6562
(def selector-schema :string)
6663

67-
(def remove-fragments-options-schemas
68-
(mu/merge
69-
sse-options-schema
70-
(mu/optional-keys
71-
[:map
72-
[common/use-view-transition :boolean]])))
64+
(def remove-element-options-schemas patch-element-options-schemas)
7365

7466

7567
;; -----------------------------------------------------------------------------
7668
(def signals-schema :string)
7769

78-
(def merge-signals-options-schemas
70+
(def patch-signals-options-schemas
7971
(mu/merge
8072
sse-options-schema
8173
(mu/optional-keys
@@ -86,8 +78,6 @@
8678
;; -----------------------------------------------------------------------------
8779
(def signal-paths-schema [:seqable :string])
8880

89-
(def remove-signals-options-schemas sse-options-schema)
90-
9181
;; -----------------------------------------------------------------------------
9282
(def script-content-schema :string)
9383

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(ns starfederation.datastar.clojure.api.elements-schemas
2+
(:require
3+
[malli.core :as m]
4+
[starfederation.datastar.clojure.api.common-schemas :as cs]
5+
[starfederation.datastar.clojure.api.elements]))
6+
7+
8+
(m/=> starfederation.datastar.clojure.api.elements/->patch-elements
9+
[:-> cs/elements-schema cs/patch-element-options-schemas cs/data-lines-schema])
10+
11+
12+
(m/=> starfederation.datastar.clojure.api.elements/->patch-elements-seq
13+
[:-> cs/elements-seq-schema cs/patch-element-options-schemas cs/data-lines-schema])
14+

sdk/clojure/malli-schemas/src/main/starfederation/datastar/clojure/api/fragments_schemas.clj

Lines changed: 0 additions & 17 deletions
This file was deleted.

sdk/clojure/malli-schemas/src/main/starfederation/datastar/clojure/api/scripts_schemas.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
[starfederation.datastar.clojure.api.common-schemas :as cs]
55
[starfederation.datastar.clojure.api.scripts]))
66

7-
(m/=> starfederation.datastar.clojure.api.scripts/->script
8-
[:-> cs/script-content-schema cs/execute-script-options-schemas cs/data-lines-schema])
7+
(m/=> starfederation.datastar.clojure.api.scripts/->script-tag
8+
[:-> cs/script-content-schema cs/execute-script-options-schemas :string])
99

0 commit comments

Comments
 (0)