<commit_before>(ns celestial.persistency.actions
  "Actions persistency"
  (:refer-clojure :exclude  [name type])
  (:require
    [slingshot.slingshot :refer  [throw+]]
    [subs.core :as subs :refer (validate!)]
    [clojure.core.strint :refer (<<)]
    [puny.core :refer (entity)]))

(declare unique-name)

(entity action :indices [operates-on] :intercept {:create [unique-name]})

(defn find-action-for [name type]
  (let [ids (get-action-index :operates-on type) 
        actions (map #(-> % Long/parseLong  get-action) ids)]
    (first (filter #(= (-> % :name) name) actions))))

(defn unique-name [f & [{:keys [name operates-on]} & r :as args]]
  (when (and name operates-on (find-action-for name operates-on))
    (throw+ {:type ::duplicated-action :msg (<< "action for ~{operates-on} named ~{name} already exists")}))
  (apply f args))

(def has-args {:args #{:required :Vector}})

(def action-base-validation
  {:src #{:required :String} :operates-on #{:required :String :type-exists}
   :name #{:required :String}})

(defn validate-action [{:keys [capistrano ruby name type] :as action}]
  (when (or capistrano ruby) 
    (validate! capistrano has-args :error ::invalid-cap-action))
  (validate! action action-base-validation :error ::invalid-action))

(defn- args-of [s]
  "grab args from string"
  (map #(clojure.string/escape % {\~ "" \{ "" \} ""}) (re-seq #"~\{\w+\}" s)))

;; (println (args-of "-S ~{target}"))

(defn action-args [as]
  "appends action expected arguments drived from args strings"

  )
<commit_msg>adding computed user provided values<commit_after>(ns celestial.persistency.actions
  "Actions persistency"
  (:refer-clojure :exclude  [name type])
  (:require
    [clojure.string :refer (join escape)]
    [celestial.model :refer (figure-rem)]
    [slingshot.slingshot :refer  [throw+]]
    [subs.core :as subs :refer (validate!)]
    [clojure.core.strint :refer (<<)]
    [puny.core :refer (entity)]))

(declare unique-name with-provided)

(entity action :indices [operates-on] :intercept {:create [unique-name with-provided] :update [with-provided]})

(defn- args-of [s]
  "grab args from string"
  (map #(escape % {\~ "" \{ "" \} ""}) (re-seq #"~\{\w+\}" s)))

(defn remoter [action]
  (get action (figure-rem action)))

(defn add-provided [action]
  "appends action expected arguments drived from args strings"
   (assoc action :provided (remove #{"target"} (args-of (join " " ((remoter action) :args)))))) 

(defn with-provided [f & [a1 a2 & r :as args]]
  (cond
    (map? a1) (apply f (add-provided a1) r)
    (map? a2) (apply f a1 (add-provided a2) r)
    :else (apply f args)))

(defn find-action-for [name type]
  (let [ids (get-action-index :operates-on type) 
        actions (map #(-> % Long/parseLong  get-action) ids)]
    (first (filter #(= (-> % :name) name) actions))))

(defn unique-name [f & [{:keys [name operates-on]} & r :as args]]
  (when (and name operates-on (find-action-for name operates-on))
    (throw+ {:type ::duplicated-action :msg (<< "action for ~{operates-on} named ~{name} already exists")}))
  (apply f args))

(def has-args {:args #{:required :Vector}})

(def action-base-validation
  {:src #{:required :String} :operates-on #{:required :String :type-exists}
   :name #{:required :String}})

(defn validate-action [{:keys [capistrano ruby name type] :as action}]
  (when (or capistrano ruby) 
    (validate! capistrano has-args :error ::invalid-cap-action))
  (validate! action action-base-validation :error ::invalid-action))


{'fraction_non_alphanumeric': 0.18472976837289104, 'fraction_numerical': 0.0020017157563625965, 'mean_word_length': 4.0476190476190474, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4995906', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1221, 'n_words': 350}