Skip to content

Commit

Permalink
Move rules into db dep as it's useful for external apps
Browse files Browse the repository at this point in the history
- rules is already used by logseq-query and will be useful for
  nbb-logseq
- Updated db jobs to run in deps/db by default. Less typing but
  more importantly discourages independent libraries from depending on
  external scripts.
- Moved lint-rules task into db since it is db specific now
- Also remove nbb-logseq from top-level as all nbb compatibility is in
  deps.
  • Loading branch information
logseq-cldwalker authored and tiensonqin committed Jun 10, 2022
1 parent 6608537 commit 17d2462
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 85 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ jobs:
with:
cli: ${{ env.CLOJURE_VERSION }}

- name: Setup Babashka
uses: turtlequeue/[email protected]
with:
babashka-version: ${{ env.BABASHKA_VERSION }}

- name: Clojure cache
uses: actions/cache@v2
id: clojure-deps
Expand All @@ -79,10 +74,6 @@ jobs:
yarn cljs:test
node static/tests.js
# In this job because it depends on an npm package
- name: Load nbb compatible namespaces
run: bb test:load-namespaces-with-nbb

lint:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -118,9 +109,6 @@ jobs:
- name: Lint invalid translation entries
run: bb lang:invalid-translations

- name: Lint datalog rules
run: scripts/lint_rules.clj

e2e-test:
runs-on: ubuntu-latest

Expand Down
17 changes: 12 additions & 5 deletions .github/workflows/db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
- 'deps/db/**'
- '!deps/db/**.md'

defaults:
run:
working-directory: deps/db

env:
CLOJURE_VERSION: '1.10.1.727'
# setup-java@v2 dropped support for legacy Java version syntax.
Expand Down Expand Up @@ -50,11 +54,11 @@ jobs:
bb: ${{ env.BABASHKA_VERSION }}

- name: Fetch yarn deps
run: cd deps/db && yarn install --frozen-lockfile
run: yarn install --frozen-lockfile

# In this job because it depends on an npm package
- name: Load namespaces into nbb-logseq
run: bb test:load-all-namespaces-with-nbb deps/db
run: cd ../.. && bb test:load-all-namespaces-with-nbb deps/db

lint:
runs-on: ubuntu-latest
Expand All @@ -76,10 +80,13 @@ jobs:
bb: ${{ env.BABASHKA_VERSION }}

- name: Run clj-kondo lint
run: cd deps/db && clojure -M:clj-kondo --parallel --lint src
run: clojure -M:clj-kondo --parallel --lint src

- name: Carve lint for unused vars
run: cd deps/db && ../../scripts/carve.clj
run: ../../scripts/carve.clj

- name: Lint for vars that are too large
run: scripts/large_vars.clj deps/db/src '{:max-lines-count 30}'
run: ../../scripts/large_vars.clj src '{:max-lines-count 30}'

- name: Lint datalog rules
run: ../../scripts/lint_rules.clj
4 changes: 4 additions & 0 deletions deps/db/.carve/ignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
;; API
logseq.db/start-conn
;; API
logseq.db.rules/query-dsl-rules
;; Internal API
logseq.db.rules/rules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns ^:bb-compatible ^:nbb-compatible frontend.db.rules)
(ns ^:bb-compatible logseq.db.rules)

(def rules
(def ^:large-vars/data-var rules
;; rule "parent" is optimized for child node -> parent node nesting queries
'[[(parent ?p ?c)
[?c :block/parent ?p]]
Expand Down Expand Up @@ -58,7 +58,7 @@
;; [?e ?a ?v]))]
])

(def query-dsl-rules
(def ^:large-vars/data-var query-dsl-rules
"Rules used by frontend.db.query-dsl. The symbols ?b and ?p respectively refer
to block and page. Do not alter them as they are programatically built by the
query-dsl ns"
Expand Down
7 changes: 0 additions & 7 deletions docs/dev-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ We use [datascript](https://github.com/tonsky/datascript)'s datalog to power our
scripts/lint_rules.clj
```

### Nbb compatible

Namespaces have the metadata flag `^:nbb-compatible` indicate they are compatible with https://github.com/logseq/nbb-logseq. This compatibility is necessary in order for namespaces to be reused by the frontend and CLIs. To confirm these compatibilities, run:
```
bb test:load-namespaces-with-nbb
```

## Testing

We have unit and end to end tests.
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"main": "static/electron.js",
"devDependencies": {
"@capacitor/cli": "3.2.2",
"@logseq/nbb-logseq": "^0.5.103",
"@playwright/test": "^1.19.2",
"@tailwindcss/ui": "0.7.2",
"@types/gulp": "^4.0.7",
Expand Down
4 changes: 2 additions & 2 deletions scripts/lint_rules.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {me.tagaholic/dlint {:mvn/version "0.1.0"}
io.lambdaforge/datalog-parser {:mvn/version "0.1.11"}}
:paths ["src/main"]})
:paths ["src"]})

(ns lint-rules
"Lint datalog rules for parse-ability and unbound variables"
(:require [datalog.parser.impl :as parser-impl]
[dlint.core :as dlint]
[frontend.db.rules :as rules]))
[logseq.db.rules :as rules]))

(defn- lint-unbound-rule [rule]
(->> (dlint/lint [rule])
Expand Down
23 changes: 0 additions & 23 deletions scripts/src/logseq/tasks/nbb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,6 @@
[clojure.string :as str]
[babashka.tasks :refer [shell]]))

(defn- fetch-meta-namespaces
"Return namespaces with metadata"
[paths]
(let [{{:keys [namespace-definitions]} :analysis}
(clj-kondo/run!
{:lint paths
:config {:output {:analysis {:namespace-definitions {:meta true
:lang :cljs}}}}})
matches (keep (fn [m]
(when (:meta m)
{:ns (:name m)
:meta (:meta m)}))
namespace-definitions)]
matches))

(defn- validate-namespaces
[namespaces classpath dir]
(assert (seq namespaces) "There must be some namespaces to check")
Expand All @@ -28,14 +13,6 @@
(shell {:dir dir} "yarn nbb-logseq -cp" classpath "-e" (format "(require '[%s])" n)))
(println "Success!"))

(defn load-compatible-namespaces
"Check nbb-compatible namespaces can be required by nbb-logseq"
[]
(let [namespaces (map :ns
(filter #(get-in % [:meta :nbb-compatible])
(fetch-meta-namespaces ["src/main"])))]
(validate-namespaces namespaces "src/main" ".")))

(defn load-all-namespaces
"Check all namespaces in a directory can be required by nbb-logseq"
[dir]
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/db/model.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[frontend.state :as state]
[frontend.util :as util :refer [react]]
[logseq.graph-parser.util :as gp-util]
[frontend.db.rules :refer [rules]]
[logseq.db.rules :refer [rules]]
[logseq.db.default :as default-db]
[frontend.util.drawer :as drawer]))

Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/db/query_custom.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[frontend.db.query-react :as query-react]
[frontend.db.query-dsl :as query-dsl]
[frontend.db.model :as model]
[frontend.db.rules :as rules]
[logseq.db.rules :as rules]
[frontend.util.datalog :as datalog-util]
[clojure.walk :as walk]))

Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/db/query_dsl.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[frontend.db.model :as model]
[frontend.db.query-react :as query-react]
[frontend.db.utils :as db-utils]
[frontend.db.rules :as rules]
[logseq.db.rules :as rules]
[frontend.template :as template]
[logseq.graph-parser.text :as text]
[frontend.util.text :as text-util]
Expand Down
2 changes: 1 addition & 1 deletion src/test/frontend/util/datalog_test.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns frontend.util.datalog-test
(:require [cljs.test :refer [deftest is]]
[frontend.util.datalog :as datalog-util]
[frontend.db.rules :as rules]))
[logseq.db.rules :as rules]))

(deftest add-to-end-of-query-in
(is (= '[:find ?b
Expand Down
30 changes: 2 additions & 28 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -726,13 +726,6 @@
resolved "https://registry.yarnpkg.com/@kanru/rage-wasm/-/rage-wasm-0.2.1.tgz#dd8fdd3133992c42bf68c0086d8cad40a13bc329"
integrity sha512-sYi4F2mL6Mpcz7zbS4myasw11xLBEbgZkDMRVg9jNxTKt6Ct/LT7/vCHDmEzAFcPcPqixD5De6Ql3bJijAX0/w==

"@logseq/nbb-logseq@^0.5.103":
version "0.5.103"
resolved "https://registry.yarnpkg.com/@logseq/nbb-logseq/-/nbb-logseq-0.5.103.tgz#1084380cd54c92ca8cc94a8934cc777206e45cc0"
integrity sha512-V9UW0XrCaaadHUc6/Hp9wfGpQqkzqzoqnDGeSVZkWR6l3QwyqGi9mkhnhVcfTwAvxIfOgrfz93GcaeepV4pYNA==
dependencies:
import-meta-resolve "^1.1.1"

"@logseq/[email protected]":
version "1.3.1-1"
resolved "https://registry.yarnpkg.com/@logseq/react-tweet-embed/-/react-tweet-embed-1.3.1-1.tgz#119d22be8234de006fc35c3fa2a36f85634c5be6"
Expand Down Expand Up @@ -1855,13 +1848,6 @@ builtin-status-codes@^3.0.0:
resolved "https://registry.yarnpkg.com/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8"
integrity sha1-hZgoeOIbmOHGZCXgPQF0eI9Wnug=

builtins@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/builtins/-/builtins-4.1.0.tgz#1edd016dd91ce771a1ed6fc3b2b71fb918953250"
integrity sha512-1bPRZQtmKaO6h7qV1YHXNtr6nCK28k0Zo95KM4dXfILcZZwoHJBN1m3lfLv9LPkcOZlrSr+J1bzMaZFO98Yq0w==
dependencies:
semver "^7.0.0"

bytes@^3.0.0:
version "3.1.2"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.2.tgz#8b0beeb98605adf1b128fa4386403c009e0221a5"
Expand Down Expand Up @@ -4140,13 +4126,6 @@ import-lazy@^4.0.0:
resolved "https://registry.yarnpkg.com/import-lazy/-/import-lazy-4.0.0.tgz#e8eb627483a0a43da3c03f3e35548be5cb0cc153"
integrity sha512-rKtvo6a868b5Hu3heneU+L4yEQ4jYKLtjpnPeUdK7h0yzXGmyBTypknlkCvHFBqfX9YlorEiMM6Dnq/5atfHkw==

import-meta-resolve@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/import-meta-resolve/-/import-meta-resolve-1.1.1.tgz#244fd542fd1fae73550d4f8b3cde3bba1d7b2b18"
integrity sha512-JiTuIvVyPaUg11eTrNDx5bgQ/yMKMZffc7YSjvQeSMXy58DO2SQ8BtAf3xteZvmzvjYh14wnqNjL8XVeDy2o9A==
dependencies:
builtins "^4.0.0"

imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
Expand Down Expand Up @@ -6836,6 +6815,8 @@ [email protected]:
version "2.2.7"
resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-2.2.7.tgz#d7860826b258557510dac10680abea5ca23cf650"
integrity sha512-0n4lcGqzJFcIQLoQytLdJCE0DKSA9dkwEZRYoGrIDJZFvIT6Hbajx5mv9geqhqFiNjUgtxg8kPyDfjlhymbGFg==
dependencies:
react-icon-base "2.1.0"

react-is@^16.13.1, react-is@^16.3.1, react-is@^16.7.0:
version "16.13.1"
Expand Down Expand Up @@ -7323,13 +7304,6 @@ semver@^6.2.0, semver@^6.3.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==

semver@^7.0.0:
version "7.3.7"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.7.tgz#12c5b649afdbf9049707796e22a4028814ce523f"
integrity sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==
dependencies:
lru-cache "^6.0.0"

semver@^7.3.2, semver@^7.3.4:
version "7.3.5"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
Expand Down

0 comments on commit 17d2462

Please sign in to comment.