mirror of
https://github.com/penpot/penpot.git
synced 2025-01-08 16:00:19 -05:00
✨ Unify uuid under uxbox.common.uuid.
This commit is contained in:
parent
a91a8401d6
commit
9649d67883
59 changed files with 289 additions and 349 deletions
|
@ -20,12 +20,12 @@
|
|||
[uxbox.migrations]
|
||||
[uxbox.services.mutations.profile :as mt.profile]
|
||||
[uxbox.util.blob :as blob]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[vertx.util :as vu]))
|
||||
|
||||
(defn- mk-uuid
|
||||
[prefix & args]
|
||||
(uuid/namespaced uuid/oid (apply str prefix (interpose "-" args))))
|
||||
(uuid/namespaced uuid/zero (apply str prefix (interpose "-" args))))
|
||||
|
||||
;; --- Profiles creation
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
[promesa.core :as p]
|
||||
[uxbox.http.errors :as errors]
|
||||
[uxbox.http.session :as session]
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
[uxbox.common.uuid :as uuid]))
|
||||
|
||||
(defn emails-list
|
||||
[req]
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
[uxbox.services.init]
|
||||
[uxbox.services.mutations :as sm]
|
||||
[uxbox.services.queries :as sq]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[vertx.web :as vw]
|
||||
[vertx.eventbus :as ve]))
|
||||
|
||||
|
@ -75,7 +75,7 @@
|
|||
(defn logout-handler
|
||||
[req]
|
||||
(some-> (get-in req [:cookies "auth-token"])
|
||||
(uuid/from-string)
|
||||
(uuid/uuid)
|
||||
(session/delete)
|
||||
(p/then' (fn [token]
|
||||
{:status 204
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
[promesa.core :as p]
|
||||
[vertx.core :as vc]
|
||||
[uxbox.db :as db]
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
[uxbox.common.uuid :as uuid]))
|
||||
|
||||
;; --- Main API
|
||||
|
||||
|
@ -40,7 +40,7 @@
|
|||
[request]
|
||||
(try
|
||||
(when-let [token (get-in request [:cookies "auth-token"])]
|
||||
(uuid/from-string token))
|
||||
(uuid/uuid token))
|
||||
(catch java.lang.IllegalArgumentException e
|
||||
nil)))
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
[uxbox.services.queries :as sq]
|
||||
[uxbox.util.blob :as blob]
|
||||
[uxbox.util.transit :as t]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[vertx.eventbus :as ve]
|
||||
[vertx.http :as vh]
|
||||
[vertx.util :as vu]
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
[uxbox.util.svg :as svg]
|
||||
[uxbox.util.transit :as t]
|
||||
[uxbox.util.blob :as blob]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.data :as data]
|
||||
[uxbox.services.mutations.colors :as colors]
|
||||
[uxbox.services.mutations.icons :as icons]
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
[uxbox.services.queries.teams :as teams]
|
||||
[uxbox.services.mutations :as sm]
|
||||
[uxbox.services.util :as su]
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
[uxbox.common.uuid :as uuid]))
|
||||
|
||||
;; --- Helpers & Specs
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
[uxbox.services.mutations :as sm]
|
||||
[uxbox.services.mutations.profile :as profile]
|
||||
[uxbox.tasks :as tasks]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.time :as tm]))
|
||||
|
||||
(sm/defmutation ::create-demo-profile
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
[uxbox.services.mutations.images :as imgs]
|
||||
[uxbox.services.util :as su]
|
||||
[uxbox.util.blob :as blob]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.storage :as ust]
|
||||
[vertx.util :as vu]))
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
[uxbox.services.util :as su]
|
||||
[uxbox.tasks :as tasks]
|
||||
[uxbox.util.blob :as blob]
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
[uxbox.common.uuid :as uuid]))
|
||||
|
||||
;; --- Helpers & Specs
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
[uxbox.services.queries.teams :as teams]
|
||||
[uxbox.services.mutations :as sm]
|
||||
[uxbox.services.util :as su]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.storage :as ust]
|
||||
[vertx.util :as vu]))
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
[uxbox.tasks :as tasks]
|
||||
[uxbox.util.blob :as blob]
|
||||
[uxbox.util.sql :as sql]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[vertx.eventbus :as ve]))
|
||||
|
||||
;; --- Helpers & Specs
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
[uxbox.services.util :as su]
|
||||
[uxbox.util.blob :as blob]
|
||||
[uxbox.util.storage :as ust]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.time :as tm]
|
||||
[vertx.util :as vu]))
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
[uxbox.services.mutations :as sm]
|
||||
[uxbox.services.util :as su]
|
||||
[uxbox.util.blob :as blob]
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
[uxbox.common.uuid :as uuid]))
|
||||
|
||||
;; --- Helpers & Specs
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
[uxbox.services.mutations :as sm]
|
||||
[uxbox.services.util :as su]
|
||||
[uxbox.util.blob :as blob]
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
[uxbox.common.uuid :as uuid]))
|
||||
|
||||
;; --- Helpers & Specs
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
[uxbox.services.util :as su]
|
||||
[uxbox.util.blob :as blob]
|
||||
[uxbox.util.data :as data]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[vertx.core :as vc]))
|
||||
|
||||
;; --- Helpers & Specs
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
[uxbox.services.util :as su]
|
||||
[uxbox.util.blob :as blob]
|
||||
[uxbox.util.data :as data]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[vertx.core :as vc]))
|
||||
|
||||
;; --- Helpers & Specs
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
[uxbox.images :as images]
|
||||
[uxbox.services.queries :as sq]
|
||||
[uxbox.services.util :as su]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.blob :as blob]))
|
||||
|
||||
;; --- Helpers & Specs
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
[uxbox.services.queries :as sq]
|
||||
[uxbox.services.util :as su]
|
||||
[uxbox.util.blob :as blob]
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
[uxbox.common.uuid :as uuid]))
|
||||
|
||||
|
||||
;; --- Team Edition Permissions
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
[uxbox.services.util :as su]
|
||||
[uxbox.util.blob :as blob]
|
||||
[uxbox.util.data :as data]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[vertx.core :as vc]))
|
||||
|
||||
;; --- Helpers & Specs
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
[vertx.util :as vu]
|
||||
[uxbox.core :refer [system]]
|
||||
[uxbox.common.exceptions :as ex]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.dispatcher :as uds]))
|
||||
|
||||
(defn raise-not-found-if-nil
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2020 UXBOX Labs SL
|
||||
|
||||
(ns uxbox.util.uuid
|
||||
(:refer-clojure :exclude [next])
|
||||
(:require [clj-uuid :as uuid])
|
||||
(:import java.util.UUID))
|
||||
|
||||
(def ^:const zero uuid/+null+)
|
||||
(def ^:const oid uuid/+namespace-oid+)
|
||||
|
||||
(defmacro next
|
||||
[]
|
||||
`(uuid/v1))
|
||||
|
||||
(defmacro random
|
||||
"Alias for clj-uuid/v4."
|
||||
[]
|
||||
`(uuid/v4))
|
||||
|
||||
(defmacro namespaced
|
||||
[ns data]
|
||||
`(uuid/v5 ~ns ~data))
|
||||
|
||||
(defmacro str->uuid
|
||||
[s]
|
||||
`(UUID/fromString ~s))
|
||||
|
||||
(defn from-string
|
||||
"Parse string uuid representation into proper UUID instance."
|
||||
[s]
|
||||
(UUID/fromString s))
|
||||
|
||||
(defn custom
|
||||
([a] (UUID. 0 a))
|
||||
([b a] (UUID. b a)))
|
|
@ -19,7 +19,7 @@
|
|||
[uxbox.media]
|
||||
[uxbox.db :as db]
|
||||
[uxbox.util.blob :as blob]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.storage :as ust]
|
||||
[uxbox.config :as cfg]
|
||||
[vertx.util :as vu]))
|
||||
|
@ -67,7 +67,7 @@
|
|||
|
||||
(defn mk-uuid
|
||||
[prefix & args]
|
||||
(uuid/namespaced uuid/oid (apply str prefix args)))
|
||||
(uuid/namespaced uuid/zero (apply str prefix args)))
|
||||
|
||||
;; --- Profile creation
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
[promesa.core :as p]
|
||||
[mockery.core :refer [with-mock]]
|
||||
[uxbox.common.pages :as cp]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.tests.helpers :as th]))
|
||||
|
||||
(t/deftest process-change-add-obj
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
[uxbox.services.mutations :as sm]
|
||||
[uxbox.services.queries :as sq]
|
||||
[uxbox.util.storage :as ust]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.tests.helpers :as th]
|
||||
[vertx.core :as vc]))
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
[uxbox.services.queries :as sq]
|
||||
[uxbox.tests.helpers :as th]
|
||||
[uxbox.util.storage :as ust]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[vertx.util :as vu]))
|
||||
|
||||
(t/use-fixtures :once th/state-init)
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
[uxbox.services.mutations :as sm]
|
||||
[uxbox.services.queries :as sq]
|
||||
[uxbox.util.storage :as ust]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.tests.helpers :as th]
|
||||
[vertx.core :as vc]))
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
[uxbox.services.mutations :as sm]
|
||||
[uxbox.services.queries :as sq]
|
||||
[uxbox.util.storage :as ust]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.tests.helpers :as th]
|
||||
[vertx.core :as vc]))
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
[uxbox.http :as http]
|
||||
[uxbox.services.mutations :as sm]
|
||||
[uxbox.services.queries :as sq]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.tests.helpers :as th]))
|
||||
|
||||
(t/use-fixtures :once th/state-init)
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
[uxbox.services.mutations :as sm]
|
||||
[uxbox.services.queries :as sq]
|
||||
[uxbox.tests.helpers :as th]
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
[uxbox.common.uuid :as uuid]))
|
||||
|
||||
(t/use-fixtures :once th/state-init)
|
||||
(t/use-fixtures :each th/database-reset)
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
[uxbox.services.queries :as sq]
|
||||
[uxbox.tests.helpers :as th]
|
||||
[uxbox.util.storage :as ust]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[vertx.util :as vu]))
|
||||
|
||||
(t/use-fixtures :once th/state-init)
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
"A common (clj/cljs) functions and specs for pages."
|
||||
(:require
|
||||
[clojure.spec.alpha :as s]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.common.data :as d]
|
||||
[uxbox.common.exceptions :as ex]
|
||||
[uxbox.common.spec :as us]))
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#?(:clj [clojure.spec.alpha :as s]
|
||||
:cljs [cljs.spec.alpha :as s])
|
||||
[expound.alpha :as expound]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.common.exceptions :as ex]
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
|
@ -34,9 +35,7 @@
|
|||
v
|
||||
(if (string? v)
|
||||
(if (re-matches uuid-rx v)
|
||||
#?(:cljs (uuid v)
|
||||
:clj (java.util.UUID/fromString v))
|
||||
|
||||
(uuid/uuid v)
|
||||
(if (str/empty? v) nil ::s/invalid))
|
||||
::s/invalid)))
|
||||
|
||||
|
|
51
common/uxbox/common/uuid.cljc
Normal file
51
common/uxbox/common/uuid.cljc
Normal file
|
@ -0,0 +1,51 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2020 UXBOX Labs SL
|
||||
|
||||
(ns uxbox.common.uuid
|
||||
(:refer-clojure :exclude [next uuid zero?])
|
||||
#?(:clj (:import java.util.UUID))
|
||||
#?(:clj
|
||||
(:require [clj-uuid :as impl]
|
||||
[clojure.core :as c])
|
||||
:cljs
|
||||
(:require ["./uuid_impl.js" :as impl]
|
||||
[cljs.core :as c])))
|
||||
|
||||
(def zero #uuid "00000000-0000-0000-0000-000000000000")
|
||||
|
||||
(defn zero?
|
||||
[v]
|
||||
(= zero v))
|
||||
|
||||
(defn next
|
||||
[]
|
||||
#?(:clj (impl/v1)
|
||||
:cljs (impl/v1)))
|
||||
|
||||
(defn random
|
||||
"Alias for clj-uuid/v4."
|
||||
[]
|
||||
#?(:clj (impl/v4)
|
||||
:cljs (impl/v4)))
|
||||
|
||||
#?(:clj
|
||||
(defn namespaced
|
||||
[ns data]
|
||||
(impl/v5 ns data)))
|
||||
|
||||
(defn uuid
|
||||
"Parse string uuid representation into proper UUID instance."
|
||||
[s]
|
||||
#?(:clj (UUID/fromString s)
|
||||
:cljs (c/uuid s)))
|
||||
|
||||
#?(:clj
|
||||
(defn custom
|
||||
([a] (UUID. 0 a))
|
||||
([b a] (UUID. b a))))
|
178
common/uxbox/common/uuid_impl.js
Normal file
178
common/uxbox/common/uuid_impl.js
Normal file
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
* defined by the Mozilla Public License, v. 2.0.
|
||||
*
|
||||
* Copyright (c) 2020 UXBOX Labs SL
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
import cljs from "goog:cljs.core";
|
||||
|
||||
const global = goog.global;
|
||||
const crypto = global.crypto;
|
||||
|
||||
function fill(buf) {
|
||||
crypto.getRandomValues(buf);
|
||||
return buf;
|
||||
};
|
||||
|
||||
if (global.crypto === undefined) {
|
||||
console.warn("No high quality RNG available, switching back to Math.random.", platform);
|
||||
|
||||
fill = function(buf) {
|
||||
for (let i = 0, r; i < buf.length; i++) {
|
||||
if ((i & 0x03) === 0) { r = Math.random() * 0x100000000; }
|
||||
buf[i] = r >>> ((i & 0x03) << 3) & 0xff;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2010-2016 Robert Kieffer and other contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
const hexMap = [];
|
||||
for (let i = 0; i < 256; i++) {
|
||||
hexMap[i] = (i + 0x100).toString(16).substr(1);
|
||||
}
|
||||
|
||||
function toHexString(buf) {
|
||||
let i = 0;
|
||||
return (hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] + '-' +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] + '-' +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] + '-' +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] + '-' +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]]);
|
||||
}
|
||||
|
||||
const buff = new Uint8Array(16);
|
||||
|
||||
export function v4() {
|
||||
fill(buff);
|
||||
buff[6] = (buff[6] & 0x0f) | 0x40;
|
||||
buff[8] = (buff[8] & 0x3f) | 0x80;
|
||||
return cljs.uuid(toHexString(buff));
|
||||
}
|
||||
|
||||
let initialized = false;
|
||||
let node;
|
||||
let clockseq;
|
||||
let lastms = 0;
|
||||
let lastns = 0;
|
||||
|
||||
export function v1() {
|
||||
let cs = clockseq;
|
||||
|
||||
if (!initialized) {
|
||||
const seed = new Uint8Array(8)
|
||||
fill(seed);
|
||||
|
||||
// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
|
||||
node = [
|
||||
seed[0] | 0x01,
|
||||
seed[1],
|
||||
seed[2],
|
||||
seed[3],
|
||||
seed[4],
|
||||
seed[5]
|
||||
];
|
||||
|
||||
// Per 4.2.2, randomize (14 bit) clockseq
|
||||
cs = clockseq = (seed[6] << 8 | seed[7]) & 0x3fff;
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
let ms = Date.now();
|
||||
let ns = lastns + 1;
|
||||
let dt = (ms - lastms) + (ns - lastns) / 10000;
|
||||
|
||||
// Per 4.2.1.2, Bump clockseq on clock regression
|
||||
if (dt < 0) {
|
||||
cs = cs + 1 & 0x3fff;
|
||||
}
|
||||
|
||||
// Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
|
||||
// time interval
|
||||
if (dt < 0 || ms > lastms) {
|
||||
ns = 0;
|
||||
}
|
||||
|
||||
// Per 4.2.1.2 Throw error if too many uuids are requested
|
||||
if (ns >= 10000) {
|
||||
throw new Error("uuid v1 can't create more than 10M uuids/s")
|
||||
}
|
||||
|
||||
lastms = ms;
|
||||
lastns = ns;
|
||||
clockseq = cs;
|
||||
|
||||
// Per 4.1.4 - Convert from unix epoch to Gregorian epoch
|
||||
ms += 12219292800000;
|
||||
|
||||
let i = 0;
|
||||
|
||||
// `time_low`
|
||||
var tl = ((ms & 0xfffffff) * 10000 + ns) % 0x100000000;
|
||||
buff[i++] = tl >>> 24 & 0xff;
|
||||
buff[i++] = tl >>> 16 & 0xff;
|
||||
buff[i++] = tl >>> 8 & 0xff;
|
||||
buff[i++] = tl & 0xff;
|
||||
|
||||
// `time_mid`
|
||||
var tmh = (ms / 0x100000000 * 10000) & 0xfffffff;
|
||||
buff[i++] = tmh >>> 8 & 0xff;
|
||||
buff[i++] = tmh & 0xff;
|
||||
|
||||
// `time_high_and_version`
|
||||
buff[i++] = tmh >>> 24 & 0xf | 0x10; // include version
|
||||
buff[i++] = tmh >>> 16 & 0xff;
|
||||
|
||||
// `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
|
||||
buff[i++] = cs >>> 8 | 0x80;
|
||||
|
||||
// `clock_seq_low`
|
||||
buff[i++] = cs & 0xff;
|
||||
|
||||
// `node`
|
||||
for (var n = 0; n < 6; ++n) {
|
||||
buff[i + n] = node[n];
|
||||
}
|
||||
|
||||
return cljs.uuid(toHexString(buff));
|
||||
}
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
environ/environ {:mvn/version "1.1.0"}
|
||||
metosin/reitit-core {:mvn/version "0.3.10"}
|
||||
expound/expound {:mvn/version "0.7.2"}
|
||||
expound/expound {:mvn/version "0.8.4"}
|
||||
|
||||
danlentz/clj-uuid {:mvn/version "0.1.9"}
|
||||
|
||||
funcool/beicon {:mvn/version "2020.03.29-1"}
|
||||
funcool/cuerdas {:mvn/version "2020.03.26-3"}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
[uxbox.util.i18n :refer [tr]]
|
||||
[uxbox.util.router :as rt]
|
||||
[uxbox.util.time :as dt]
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
[uxbox.common.uuid :as uuid]))
|
||||
|
||||
;; ;; TODO: need a good refactor
|
||||
;;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
[uxbox.util.router :as rt]
|
||||
[uxbox.util.time :as dt]
|
||||
[uxbox.util.timers :as ts]
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
[uxbox.common.uuid :as uuid]))
|
||||
|
||||
;; --- Specs
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
[uxbox.util.webapi :as wapi]
|
||||
[uxbox.util.i18n :as i18n :refer [t tr]]
|
||||
[uxbox.util.router :as r]
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
[uxbox.common.uuid :as uuid]))
|
||||
|
||||
(s/def ::id uuid?)
|
||||
(s/def ::name string?)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
[uxbox.main.repo :as rp]
|
||||
[uxbox.util.i18n :refer [tr]]
|
||||
[uxbox.util.router :as rt]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.time :as ts]
|
||||
[uxbox.util.router :as r]
|
||||
[uxbox.util.files :as files]))
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
[uxbox.util.webapi :as wapi]
|
||||
[uxbox.util.i18n :as i18n :refer [t tr]]
|
||||
[uxbox.util.router :as r]
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
[uxbox.common.uuid :as uuid]))
|
||||
|
||||
(defn initialize-workspace-libraries []
|
||||
())
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
[uxbox.common.data :as d]
|
||||
[uxbox.common.exceptions :as ex]
|
||||
[uxbox.util.router :as rt]
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
[uxbox.common.uuid :as uuid]))
|
||||
|
||||
;; --- Specs
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
[uxbox.util.router :as rt]
|
||||
[uxbox.util.time :as dt]
|
||||
[uxbox.util.transit :as t]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.webapi :as wapi]
|
||||
#_[vendor.randomcolor])
|
||||
(:import goog.events.EventType
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"The main logic for SVG export functionality."
|
||||
(:require
|
||||
[rumext.alpha :as mf]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.math :as mth]
|
||||
[uxbox.main.geom :as geom]
|
||||
[uxbox.util.geom.point :as gpt]
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
(:require [beicon.core :as rx]
|
||||
[lentes.core :as l]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.storage :refer [storage]]))
|
||||
|
||||
;; TODO: move outside uxbox.main
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
[rumext.alpha :as mf]
|
||||
[goog.object :as gobj]
|
||||
[uxbox.main.ui.components.dropdown :refer [dropdown']]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.data :refer [classnames]]))
|
||||
|
||||
(mf/defc context-menu
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(ns uxbox.main.ui.components.dropdown
|
||||
(:require
|
||||
[rumext.alpha :as mf]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.dom :as dom]
|
||||
[goog.events :as events]
|
||||
[goog.object :as gobj])
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
[uxbox.util.dom :as dom]
|
||||
[uxbox.util.i18n :as i18n :refer [t]]
|
||||
[uxbox.util.router :as rt]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.webapi :as wapi]))
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
[uxbox.util.geom.path :as path]
|
||||
[uxbox.util.geom.point :as gpt]
|
||||
[uxbox.util.i18n :as i18n :refer [t]]
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
[uxbox.common.uuid :as uuid]))
|
||||
|
||||
;; --- Events
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
[uxbox.main.ui.modal :as modal]
|
||||
[uxbox.util.dom :as dom]
|
||||
[uxbox.util.i18n :as i18n :refer [tr t]]
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
[uxbox.common.uuid :as uuid]))
|
||||
|
||||
;; --- Refs
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
[uxbox.main.store :as st]
|
||||
[uxbox.main.data.workspace :as dw]
|
||||
[uxbox.util.i18n :as i18n :refer [t]]
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
[uxbox.common.uuid :as uuid]))
|
||||
|
||||
(mf/defc align-options
|
||||
[]
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
[uxbox.main.ui.workspace.sortable :refer [use-sortable]]
|
||||
[uxbox.util.dom :as dom]
|
||||
[uxbox.util.perf :as perf]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.i18n :as i18n :refer [t]]))
|
||||
|
||||
(def ^:private shapes-iref
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
[uxbox.main.ui.workspace.sortable :refer [use-sortable]]
|
||||
[uxbox.util.dom :as dom]
|
||||
[uxbox.util.timers :as timers]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.i18n :as i18n :refer [tr]]
|
||||
[uxbox.util.data :refer [classnames]]
|
||||
[uxbox.main.ui.components.tab-container :refer [tab-container tab-element]]
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
[uxbox.util.dom :as dom]
|
||||
[uxbox.util.geom.point :as gpt]
|
||||
[uxbox.util.perf :as perf]
|
||||
[uxbox.util.uuid :as uuid])
|
||||
[uxbox.common.uuid :as uuid])
|
||||
(:import goog.events.EventType))
|
||||
|
||||
;; --- Coordinates Widget
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
goog.provide("uxbox.util.rng_impl");
|
||||
goog.require("cljs.core");
|
||||
goog.require("goog.object");
|
||||
|
||||
goog.scope(function() {
|
||||
const self = uxbox.util.rng_impl;
|
||||
const platform = cljs.core._STAR_target_STAR_;
|
||||
|
||||
if (platform === "nodejs") {
|
||||
const crypto = require("crypto");
|
||||
|
||||
self.getBytes = function(n) {
|
||||
return crypto.randomBytes(n);
|
||||
};
|
||||
|
||||
} else {
|
||||
const gobj = goog.object;
|
||||
const global = goog.global;
|
||||
const crypto = gobj.get(global, "crypto");
|
||||
|
||||
if (crypto === undefined) {
|
||||
console.warn("No high quality RNG available, switching back to Math.random.", platform);
|
||||
|
||||
self.getBytes = function(n) {
|
||||
const buf = new Uint8Array(n);
|
||||
|
||||
for (let i = 0, r; i < n; i++) {
|
||||
if ((i & 0x03) === 0) { r = Math.random() * 0x100000000; }
|
||||
buf[i] = r >>> ((i & 0x03) << 3) & 0xff;
|
||||
}
|
||||
|
||||
return buf;
|
||||
};
|
||||
} else {
|
||||
self.getBytes = function(n) {
|
||||
const buf = new Uint8Array(n);
|
||||
crypto.getRandomValues(buf);
|
||||
return buf;
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
|
@ -1,36 +0,0 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2016-2020 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(ns uxbox.util.uuid
|
||||
"Provides a UUID v4 uuid generation.
|
||||
|
||||
In difference with builtin `random-uuid` function this
|
||||
implementation tries to use high quality RNG if is
|
||||
available (browser crypto object or nodejs crypto module).
|
||||
|
||||
If no high qualiry RNG, switches to the default Math based
|
||||
RNG with proper waring in the console."
|
||||
(:refer-clojure :exclude [zero? next])
|
||||
(:require [uxbox.util.uuid-impl :as impl]))
|
||||
|
||||
(def zero #uuid "00000000-0000-0000-0000-000000000000")
|
||||
|
||||
(defn zero?
|
||||
[v]
|
||||
(= zero v))
|
||||
|
||||
(defn next
|
||||
"Generate a v1 (time-based) UUID."
|
||||
[]
|
||||
(uuid (impl/v1)))
|
||||
|
||||
(defn random
|
||||
"Generate a v4 (random) UUID."
|
||||
[]
|
||||
(uuid (impl/v4)))
|
|
@ -1,161 +0,0 @@
|
|||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
* defined by the Mozilla Public License, v. 2.0.
|
||||
*
|
||||
* Copyright (c) 2016-2020 Andrey Antukh <niwi@niwi.nz>
|
||||
*/
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2010-2016 Robert Kieffer and other contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
goog.provide("uxbox.util.uuid_impl");
|
||||
goog.require("uxbox.util.rng_impl");
|
||||
|
||||
goog.scope(function() {
|
||||
const self = uxbox.util.uuid_impl;
|
||||
const rng = uxbox.util.rng_impl;
|
||||
|
||||
const hexMap = [];
|
||||
for (let i = 0; i < 256; i++) {
|
||||
hexMap[i] = (i + 0x100).toString(16).substr(1);
|
||||
}
|
||||
|
||||
function toHexString(buf) {
|
||||
let i = 0;
|
||||
return (hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] + '-' +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] + '-' +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] + '-' +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] + '-' +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]]);
|
||||
}
|
||||
|
||||
self.v4 = function() {
|
||||
const buf = rng.getBytes(16);
|
||||
buf[6] = (buf[6] & 0x0f) | 0x40;
|
||||
buf[8] = (buf[8] & 0x3f) | 0x80;
|
||||
return toHexString(buf);
|
||||
};
|
||||
|
||||
let initialized = false;
|
||||
let node;
|
||||
let clockseq;
|
||||
let lastms = 0;
|
||||
let lastns = 0;
|
||||
|
||||
self.v1 = function() {
|
||||
let cs = clockseq;
|
||||
|
||||
if (!initialized) {
|
||||
const seed = rng.getBytes(8);
|
||||
|
||||
// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
|
||||
node = [
|
||||
seed[0] | 0x01,
|
||||
seed[1],
|
||||
seed[2],
|
||||
seed[3],
|
||||
seed[4],
|
||||
seed[5]
|
||||
];
|
||||
|
||||
// Per 4.2.2, randomize (14 bit) clockseq
|
||||
cs = clockseq = (seed[6] << 8 | seed[7]) & 0x3fff;
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
let ms = Date.now();
|
||||
let ns = lastns + 1;
|
||||
let dt = (ms - lastms) + (ns - lastns) / 10000;
|
||||
|
||||
// Per 4.2.1.2, Bump clockseq on clock regression
|
||||
if (dt < 0) {
|
||||
cs = cs + 1 & 0x3fff;
|
||||
}
|
||||
|
||||
// Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
|
||||
// time interval
|
||||
if (dt < 0 || ms > lastms) {
|
||||
ns = 0;
|
||||
}
|
||||
|
||||
// Per 4.2.1.2 Throw error if too many uuids are requested
|
||||
if (ns >= 10000) {
|
||||
throw new Error("uuid v1 can't create more than 10M uuids/s")
|
||||
}
|
||||
|
||||
lastms = ms;
|
||||
lastns = ns;
|
||||
clockseq = cs;
|
||||
|
||||
// Per 4.1.4 - Convert from unix epoch to Gregorian epoch
|
||||
ms += 12219292800000;
|
||||
|
||||
let i = 0;
|
||||
let buf = new Uint8Array(16);
|
||||
|
||||
// `time_low`
|
||||
var tl = ((ms & 0xfffffff) * 10000 + ns) % 0x100000000;
|
||||
buf[i++] = tl >>> 24 & 0xff;
|
||||
buf[i++] = tl >>> 16 & 0xff;
|
||||
buf[i++] = tl >>> 8 & 0xff;
|
||||
buf[i++] = tl & 0xff;
|
||||
|
||||
// `time_mid`
|
||||
var tmh = (ms / 0x100000000 * 10000) & 0xfffffff;
|
||||
buf[i++] = tmh >>> 8 & 0xff;
|
||||
buf[i++] = tmh & 0xff;
|
||||
|
||||
// `time_high_and_version`
|
||||
buf[i++] = tmh >>> 24 & 0xf | 0x10; // include version
|
||||
buf[i++] = tmh >>> 16 & 0xff;
|
||||
|
||||
// `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
|
||||
buf[i++] = cs >>> 8 | 0x80;
|
||||
|
||||
// `clock_seq_low`
|
||||
buf[i++] = cs & 0xff;
|
||||
|
||||
// `node`
|
||||
for (var n = 0; n < 6; ++n) {
|
||||
buf[i + n] = node[n];
|
||||
}
|
||||
|
||||
return toHexString(buf);
|
||||
}
|
||||
});
|
|
@ -7,7 +7,7 @@
|
|||
(ns uxbox.util.workers
|
||||
"A lightweight layer on top of webworkers api."
|
||||
(:require [beicon.core :as rx]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.util.transit :as t]))
|
||||
|
||||
;; --- Implementation
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
(:require [beicon.core :as rx]
|
||||
[cuerdas.core :as str]
|
||||
[uxbox.util.transit :as t]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.worker.impl :as impl]
|
||||
[uxbox.worker.align]))
|
||||
|
||||
|
|
Loading…
Reference in a new issue