Skip to content

Commit

Permalink
Package naming
Browse files Browse the repository at this point in the history
Signed-off-by: Anders Eknert <[email protected]>
  • Loading branch information
anderseknert committed Nov 14, 2022
1 parent 24775ab commit f04e47c
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 27 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ nested access or updates, like `get-in`, `assoc-in` and `update-in`:

```clojure
(ns app
(:require [borge.by.clj-json-pointer :as json-pointer]))
(:require [clj-json-pointer.core :as jp]))

(def org
{"department"
Expand All @@ -26,31 +26,31 @@ nested access or updates, like `get-in`, `assoc-in` and `update-in`:
{"users"
[{"name" "joe" "roles" ["reports-writer"]}]}}})

(let [path (json-pointer/->vec org "/department/tech/users/1/roles") ; => ["department" "tech" 1 "users" "roles"]
roles (get-in org path)] ; => ["platform" "devops"]
(let [path (jp/->vec org "/department/tech/users/1/roles") ; => ["department" "tech" 1 "users" "roles"]
roles (get-in org path)] ; => ["platform" "devops"]
(do (something (with roles))))
```

These simple building blocks are used to implement the various operations of JSON `patch`:

```clojure
(json-pointer/patch {} ; => {}
[{"op" "add" "path" "/foo" "value" "bar"} ; => {"foo" "bar"}
{"op" "add" "path" "/bar" "value" "baz"} ; => {"foo" "bar" "bar" "baz}
{"op" "remove" "path" "/foo"} ; => {"bar" "baz"}
{"op" "replace" "path" "/bar" "value" "foo"} ; => {"bar" "foo"}
{"op" "copy" "from" "/bar" "path" "/baz"} ; => {"bar" "foo" "baz" "foo"}
{"op" "move" "from" "/baz" "path" "/foo"} ; => {"foo" "foo"}
{"op" "test" "path" "/foo" "value" "foo"}]) ; => {"foo" "foo"}
(jp/patch {} ; => {}
[{"op" "add" "path" "/foo" "value" "bar"} ; => {"foo" "bar"}
{"op" "add" "path" "/bar" "value" "baz"} ; => {"foo" "bar" "bar" "baz}
{"op" "remove" "path" "/foo"} ; => {"bar" "baz"}
{"op" "replace" "path" "/bar" "value" "foo"} ; => {"bar" "foo"}
{"op" "copy" "from" "/bar" "path" "/baz"} ; => {"bar" "foo" "baz" "foo"}
{"op" "move" "from" "/baz" "path" "/foo"} ; => {"foo" "foo"}
{"op" "test" "path" "/foo" "value" "foo"}]) ; => {"foo" "foo"}
```

Or if you so prefer, use the `apply-patch` function, which applies a single patch to the provided data structure:

```clojure
(json-pointer/apply-patch {} {"op" "add" "path" "/a" "value" 1}) ; => {"a" 1}
(jp/apply-patch {} {"op" "add" "path" "/a" "value" 1}) ; => {"a" 1}

; or, more likely:
(reduce json-pointer/apply-patch {} patches)
(reduce jp/apply-patch {} patches)
```

## Development
Expand Down
4 changes: 2 additions & 2 deletions build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
(:refer-clojure :exclude [compile])
(:require [clojure.tools.build.api :as b]))

(def version "0.1.0")
(def version "1.0.0")

(def lib 'borge.by/clj-json-pointer)
(def lib 'by.borge/clj-json-pointer)
(def basis (b/create-basis {:project "deps.edn"}))
(def class-dir "target/classes")
(def jar-file (format "target/%s-%s.jar" (name lib) version))
Expand Down
12 changes: 9 additions & 3 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{:deps {org.clojure/clojure {:mvn/version "1.11.1"}}
:paths ["src"]
:aliases
{:build {:deps {io.github.clojure/tools.build {:git/tag "v0.8.4" :git/sha "8c3cd69"}}
{:build {:deps {io.github.clojure/tools.build {:git/tag "v0.8.4" :git/sha "8c3cd69"}}
:ns-default build}
:deploy {:extra-deps {slipset/deps-deploy {:mvn/version "0.2.0"}}
:exec-fn deps-deploy.deps-deploy/deploy
:exec-args {:installer :remote
:sign-releases? true
:artifact "target/clj-json-pointer-1.0.0.jar"
:pom "target/classes/META-INF/maven/borge.by/clj-json-pointer/pom.xml"}}
:test {:extra-paths ["test"]
:extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
:main-opts ["-m" "cognitect.test-runner"]
Expand All @@ -16,5 +22,5 @@
:extra-deps {jonase/eastwood {:mvn/version "1.3.0"}}
:main-opts ["-m" "eastwood.lint" {}]}
:kibit {:extra-paths ["test"]
:extra-deps {tvaughan/kibit-runner {:mvn/version "1.0.1"}}
:main-opts ["-m" "kibit-runner.cmdline"]}}}
:extra-deps {tvaughan/kibit-runner {:mvn/version "1.0.1"}}
:main-opts ["-m" "kibit-runner.cmdline"]}}}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clj-json-pointer",
"version": "0.0.1",
"version": "1.0.0",
"private": false,
"devDependencies": {
"shadow-cljs": "2.20.7"
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>borge.by</groupId>
<groupId>by.borge</groupId>
<artifactId>clj-json-pointer</artifactId>
<name>clj-json-pointer</name>
<description>Simple Clojure(Script) library for working with JSON Pointer and JSON Patch, with no external dependencies.</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns borge.by.clj-json-pointer
(ns clj-json-pointer.core
(:require [clojure.set :as set]
[clojure.string :as str]))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns borge.by.compliance-test
(ns clj-json-pointer.compliance-test
"Implementation of the JSON patch compliance test suite from https://github.com/json-patch/json-patch-tests"
(:require [clojure.test :refer [deftest is testing]]
[borge.by.clj-json-pointer :as json-pointer])
[clj-json-pointer.core :as json-pointer])
#?(:clj (:import (clojure.lang ExceptionInfo))))

(deftest json-patch-compliance-tests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns borge.by.clj-json-pointer-test
(ns clj-json-pointer.unit-test
(:require [clojure.test :refer [deftest is testing]]
[borge.by.clj-json-pointer :refer [patch]])
[clj-json-pointer.core :refer [patch]])
#?(:clj (:import (clojure.lang ExceptionInfo))))

(deftest patch-add-test
Expand Down

0 comments on commit f04e47c

Please sign in to comment.