From 98e286dbf173dc8fe1daba7113b36bdc69a9bace Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Mon, 20 Sep 2021 17:58:48 +0200 Subject: [PATCH] refactor(api): major pkg restructure BREAKING CHANGE: major pkg restructure, migrations - migrate logging related types/classes to new thi.ng/logger pkg - see e0399a8f6 for details - migrate `exposeGlobal()` to new thi.ng/expose pkg - see 323995fd7 for details - lift /api source files to main /src folder for easier import - this pkg now only contains type defs, constants, decorators and mixins all other functionality migrated to other packages... --- packages/api/package.json | 165 ++++++++++------------ packages/api/src/{constants.ts => api.ts} | 0 packages/api/src/api/logger.ts | 29 ---- packages/api/src/{api => }/assoc.ts | 0 packages/api/src/{api => }/bind.ts | 0 packages/api/src/{api => }/buffered.ts | 0 packages/api/src/{api => }/clear.ts | 0 packages/api/src/{api => }/compare.ts | 0 packages/api/src/{api => }/contains.ts | 0 packages/api/src/{api => }/copy.ts | 0 packages/api/src/{api => }/deref.ts | 0 packages/api/src/{api => }/dissoc.ts | 0 packages/api/src/{api => }/empty.ts | 0 packages/api/src/{api => }/enable.ts | 0 packages/api/src/{api => }/equiv.ts | 0 packages/api/src/{api => }/event.ts | 0 packages/api/src/expose.ts | 32 ----- packages/api/src/{api => }/fn.ts | 0 packages/api/src/{api => }/get.ts | 0 packages/api/src/{api => }/hash.ts | 0 packages/api/src/{api => }/hiccup.ts | 0 packages/api/src/{api => }/id.ts | 0 packages/api/src/index.ts | 81 +++++------ packages/api/src/{api => }/indexed.ts | 0 packages/api/src/{api => }/into.ts | 0 packages/api/src/{api => }/keyval.ts | 0 packages/api/src/{api => }/length.ts | 0 packages/api/src/logger.ts | 45 ------ packages/api/src/{api => }/meta.ts | 0 packages/api/src/mixins/ienable.ts | 6 +- packages/api/src/mixins/inotify.ts | 6 +- packages/api/src/mixins/iwatch.ts | 4 +- packages/api/src/{api => }/null.ts | 0 packages/api/src/{api => }/object.ts | 0 packages/api/src/{api => }/path.ts | 0 packages/api/src/{api => }/predicate.ts | 0 packages/api/src/{api => }/prim.ts | 0 packages/api/src/{api => }/range.ts | 0 packages/api/src/{api => }/release.ts | 0 packages/api/src/{api => }/reset.ts | 0 packages/api/src/{api => }/select.ts | 0 packages/api/src/{api => }/seq.ts | 0 packages/api/src/{api => }/set.ts | 0 packages/api/src/{api => }/stack.ts | 0 packages/api/src/{api => }/tuple.ts | 0 packages/api/src/{api => }/typedarray.ts | 0 packages/api/src/{api => }/watch.ts | 0 47 files changed, 125 insertions(+), 243 deletions(-) rename packages/api/src/{constants.ts => api.ts} (100%) delete mode 100644 packages/api/src/api/logger.ts rename packages/api/src/{api => }/assoc.ts (100%) rename packages/api/src/{api => }/bind.ts (100%) rename packages/api/src/{api => }/buffered.ts (100%) rename packages/api/src/{api => }/clear.ts (100%) rename packages/api/src/{api => }/compare.ts (100%) rename packages/api/src/{api => }/contains.ts (100%) rename packages/api/src/{api => }/copy.ts (100%) rename packages/api/src/{api => }/deref.ts (100%) rename packages/api/src/{api => }/dissoc.ts (100%) rename packages/api/src/{api => }/empty.ts (100%) rename packages/api/src/{api => }/enable.ts (100%) rename packages/api/src/{api => }/equiv.ts (100%) rename packages/api/src/{api => }/event.ts (100%) delete mode 100644 packages/api/src/expose.ts rename packages/api/src/{api => }/fn.ts (100%) rename packages/api/src/{api => }/get.ts (100%) rename packages/api/src/{api => }/hash.ts (100%) rename packages/api/src/{api => }/hiccup.ts (100%) rename packages/api/src/{api => }/id.ts (100%) rename packages/api/src/{api => }/indexed.ts (100%) rename packages/api/src/{api => }/into.ts (100%) rename packages/api/src/{api => }/keyval.ts (100%) rename packages/api/src/{api => }/length.ts (100%) delete mode 100644 packages/api/src/logger.ts rename packages/api/src/{api => }/meta.ts (100%) rename packages/api/src/{api => }/null.ts (100%) rename packages/api/src/{api => }/object.ts (100%) rename packages/api/src/{api => }/path.ts (100%) rename packages/api/src/{api => }/predicate.ts (100%) rename packages/api/src/{api => }/prim.ts (100%) rename packages/api/src/{api => }/range.ts (100%) rename packages/api/src/{api => }/release.ts (100%) rename packages/api/src/{api => }/reset.ts (100%) rename packages/api/src/{api => }/select.ts (100%) rename packages/api/src/{api => }/seq.ts (100%) rename packages/api/src/{api => }/set.ts (100%) rename packages/api/src/{api => }/stack.ts (100%) rename packages/api/src/{api => }/tuple.ts (100%) rename packages/api/src/{api => }/typedarray.ts (100%) rename packages/api/src/{api => }/watch.ts (100%) diff --git a/packages/api/package.json b/packages/api/package.json index 386e2f8c13..e2148d4ea9 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -65,125 +65,122 @@ ".": { "import": "./index.js" }, - "./api/assoc": { - "import": "./api/assoc.js" + "./assoc": { + "import": "./assoc.js" }, - "./api/bind": { - "import": "./api/bind.js" + "./bind": { + "import": "./bind.js" }, - "./api/buffered": { - "import": "./api/buffered.js" + "./buffered": { + "import": "./buffered.js" }, - "./api/clear": { - "import": "./api/clear.js" + "./clear": { + "import": "./clear.js" }, - "./api/compare": { - "import": "./api/compare.js" + "./compare": { + "import": "./compare.js" }, - "./api/contains": { - "import": "./api/contains.js" + "./contains": { + "import": "./contains.js" }, - "./api/copy": { - "import": "./api/copy.js" + "./copy": { + "import": "./copy.js" }, - "./api/deref": { - "import": "./api/deref.js" + "./deref": { + "import": "./deref.js" }, - "./api/dissoc": { - "import": "./api/dissoc.js" + "./dissoc": { + "import": "./dissoc.js" }, - "./api/empty": { - "import": "./api/empty.js" + "./empty": { + "import": "./empty.js" }, - "./api/enable": { - "import": "./api/enable.js" + "./enable": { + "import": "./enable.js" }, - "./api/equiv": { - "import": "./api/equiv.js" + "./equiv": { + "import": "./equiv.js" }, - "./api/event": { - "import": "./api/event.js" + "./event": { + "import": "./event.js" }, - "./api/fn": { - "import": "./api/fn.js" + "./fn": { + "import": "./fn.js" }, - "./api/get": { - "import": "./api/get.js" + "./get": { + "import": "./get.js" }, - "./api/hash": { - "import": "./api/hash.js" + "./hash": { + "import": "./hash.js" }, - "./api/hiccup": { - "import": "./api/hiccup.js" + "./hiccup": { + "import": "./hiccup.js" }, - "./api/id": { - "import": "./api/id.js" + "./id": { + "import": "./id.js" }, - "./api/indexed": { - "import": "./api/indexed.js" + "./indexed": { + "import": "./indexed.js" }, - "./api/into": { - "import": "./api/into.js" + "./into": { + "import": "./into.js" }, - "./api/keyval": { - "import": "./api/keyval.js" + "./keyval": { + "import": "./keyval.js" }, - "./api/length": { - "import": "./api/length.js" + "./length": { + "import": "./length.js" }, - "./api/logger": { - "import": "./api/logger.js" + "./meta": { + "import": "./meta.js" }, - "./api/meta": { - "import": "./api/meta.js" + "./null": { + "import": "./null.js" }, - "./api/null": { - "import": "./api/null.js" + "./object": { + "import": "./object.js" }, - "./api/object": { - "import": "./api/object.js" + "./path": { + "import": "./path.js" }, - "./api/path": { - "import": "./api/path.js" + "./predicate": { + "import": "./predicate.js" }, - "./api/predicate": { - "import": "./api/predicate.js" + "./prim": { + "import": "./prim.js" }, - "./api/prim": { - "import": "./api/prim.js" + "./range": { + "import": "./range.js" }, - "./api/range": { - "import": "./api/range.js" + "./release": { + "import": "./release.js" }, - "./api/release": { - "import": "./api/release.js" + "./reset": { + "import": "./reset.js" }, - "./api/reset": { - "import": "./api/reset.js" + "./select": { + "import": "./select.js" }, - "./api/select": { - "import": "./api/select.js" + "./seq": { + "import": "./seq.js" }, - "./api/seq": { - "import": "./api/seq.js" + "./set": { + "import": "./set.js" }, - "./api/set": { - "import": "./api/set.js" + "./stack": { + "import": "./stack.js" }, - "./api/stack": { - "import": "./api/stack.js" + "./tuple": { + "import": "./tuple.js" }, - "./api/tuple": { - "import": "./api/tuple.js" + "./typedarray": { + "import": "./typedarray.js" }, - "./api/typedarray": { - "import": "./api/typedarray.js" + "./watch": { + "import": "./watch.js" }, - "./api/watch": { - "import": "./api/watch.js" - }, - "./constants": { - "import": "./constants.js" + "./api": { + "import": "./api.js" }, "./decorators/configurable": { "import": "./decorators/configurable.js" @@ -197,12 +194,6 @@ "./decorators/sealed": { "import": "./decorators/sealed.js" }, - "./expose": { - "import": "./expose.js" - }, - "./logger": { - "import": "./logger.js" - }, "./mixin": { "import": "./mixin.js" }, diff --git a/packages/api/src/constants.ts b/packages/api/src/api.ts similarity index 100% rename from packages/api/src/constants.ts rename to packages/api/src/api.ts diff --git a/packages/api/src/api/logger.ts b/packages/api/src/api/logger.ts deleted file mode 100644 index a69d039cfe..0000000000 --- a/packages/api/src/api/logger.ts +++ /dev/null @@ -1,29 +0,0 @@ -export enum LogLevel { - FINE, - DEBUG, - INFO, - WARN, - SEVERE, - NONE, -} - -export type LogLevelName = - | "FINE" - | "DEBUG" - | "INFO" - | "WARN" - | "SEVERE" - | "NONE"; - -export interface ILogger { - /** - * This logger's configured minimum log level - */ - level: LogLevel; - - fine(...args: any[]): void; - debug(...args: any[]): void; - info(...args: any[]): void; - warn(...args: any[]): void; - severe(...args: any[]): void; -} diff --git a/packages/api/src/api/assoc.ts b/packages/api/src/assoc.ts similarity index 100% rename from packages/api/src/api/assoc.ts rename to packages/api/src/assoc.ts diff --git a/packages/api/src/api/bind.ts b/packages/api/src/bind.ts similarity index 100% rename from packages/api/src/api/bind.ts rename to packages/api/src/bind.ts diff --git a/packages/api/src/api/buffered.ts b/packages/api/src/buffered.ts similarity index 100% rename from packages/api/src/api/buffered.ts rename to packages/api/src/buffered.ts diff --git a/packages/api/src/api/clear.ts b/packages/api/src/clear.ts similarity index 100% rename from packages/api/src/api/clear.ts rename to packages/api/src/clear.ts diff --git a/packages/api/src/api/compare.ts b/packages/api/src/compare.ts similarity index 100% rename from packages/api/src/api/compare.ts rename to packages/api/src/compare.ts diff --git a/packages/api/src/api/contains.ts b/packages/api/src/contains.ts similarity index 100% rename from packages/api/src/api/contains.ts rename to packages/api/src/contains.ts diff --git a/packages/api/src/api/copy.ts b/packages/api/src/copy.ts similarity index 100% rename from packages/api/src/api/copy.ts rename to packages/api/src/copy.ts diff --git a/packages/api/src/api/deref.ts b/packages/api/src/deref.ts similarity index 100% rename from packages/api/src/api/deref.ts rename to packages/api/src/deref.ts diff --git a/packages/api/src/api/dissoc.ts b/packages/api/src/dissoc.ts similarity index 100% rename from packages/api/src/api/dissoc.ts rename to packages/api/src/dissoc.ts diff --git a/packages/api/src/api/empty.ts b/packages/api/src/empty.ts similarity index 100% rename from packages/api/src/api/empty.ts rename to packages/api/src/empty.ts diff --git a/packages/api/src/api/enable.ts b/packages/api/src/enable.ts similarity index 100% rename from packages/api/src/api/enable.ts rename to packages/api/src/enable.ts diff --git a/packages/api/src/api/equiv.ts b/packages/api/src/equiv.ts similarity index 100% rename from packages/api/src/api/equiv.ts rename to packages/api/src/equiv.ts diff --git a/packages/api/src/api/event.ts b/packages/api/src/event.ts similarity index 100% rename from packages/api/src/api/event.ts rename to packages/api/src/event.ts diff --git a/packages/api/src/expose.ts b/packages/api/src/expose.ts deleted file mode 100644 index e5ce57e860..0000000000 --- a/packages/api/src/expose.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Exposes given `value` as `id` in global scope, iff `always = true` - * (default: false) or if `process.env.NODE_ENV != "production"` or if the - * `UMBRELLA_GLOBALS` env var is set to 1. - * - * @param id - - * @param value - - * @param always - - */ -export const exposeGlobal = (id: string, value: any, always = false) => { - const glob: any = - typeof global !== "undefined" - ? global - : typeof window !== "undefined" - ? window - : undefined; - if ( - glob && - (always || - (() => { - try { - return ( - process.env.NODE_ENV !== "production" || - process.env.UMBRELLA_GLOBALS === "1" - ); - } catch (e) {} - return false; - })()) - ) { - glob[id] = value; - } -}; diff --git a/packages/api/src/api/fn.ts b/packages/api/src/fn.ts similarity index 100% rename from packages/api/src/api/fn.ts rename to packages/api/src/fn.ts diff --git a/packages/api/src/api/get.ts b/packages/api/src/get.ts similarity index 100% rename from packages/api/src/api/get.ts rename to packages/api/src/get.ts diff --git a/packages/api/src/api/hash.ts b/packages/api/src/hash.ts similarity index 100% rename from packages/api/src/api/hash.ts rename to packages/api/src/hash.ts diff --git a/packages/api/src/api/hiccup.ts b/packages/api/src/hiccup.ts similarity index 100% rename from packages/api/src/api/hiccup.ts rename to packages/api/src/hiccup.ts diff --git a/packages/api/src/api/id.ts b/packages/api/src/id.ts similarity index 100% rename from packages/api/src/api/id.ts rename to packages/api/src/id.ts diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index 95a77aed98..fc8f5d5178 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -1,46 +1,43 @@ -export * from "./api/assoc"; -export * from "./api/bind"; -export * from "./api/buffered"; -export * from "./api/clear"; -export * from "./api/compare"; -export * from "./api/contains"; -export * from "./api/copy"; -export * from "./api/deref"; -export * from "./api/dissoc"; -export * from "./api/empty"; -export * from "./api/enable"; -export * from "./api/equiv"; -export * from "./api/event"; -export * from "./api/fn"; -export * from "./api/get"; -export * from "./api/hash"; -export * from "./api/hiccup"; -export * from "./api/id"; -export * from "./api/indexed"; -export * from "./api/into"; -export * from "./api/keyval"; -export * from "./api/length"; -export * from "./api/logger"; -export * from "./api/meta"; -export * from "./api/null"; -export * from "./api/object"; -export * from "./api/path"; -export * from "./api/predicate"; -export * from "./api/prim"; -export * from "./api/range"; -export * from "./api/release"; -export * from "./api/reset"; -export * from "./api/select"; -export * from "./api/seq"; -export * from "./api/set"; -export * from "./api/stack"; -export * from "./api/tuple"; -export * from "./api/typedarray"; -export * from "./api/watch"; +export * from "./assoc"; +export * from "./bind"; +export * from "./buffered"; +export * from "./clear"; +export * from "./compare"; +export * from "./contains"; +export * from "./copy"; +export * from "./deref"; +export * from "./dissoc"; +export * from "./empty"; +export * from "./enable"; +export * from "./equiv"; +export * from "./event"; +export * from "./fn"; +export * from "./get"; +export * from "./hash"; +export * from "./hiccup"; +export * from "./id"; +export * from "./indexed"; +export * from "./into"; +export * from "./keyval"; +export * from "./length"; +export * from "./meta"; +export * from "./null"; +export * from "./object"; +export * from "./path"; +export * from "./predicate"; +export * from "./prim"; +export * from "./range"; +export * from "./release"; +export * from "./reset"; +export * from "./select"; +export * from "./seq"; +export * from "./set"; +export * from "./stack"; +export * from "./tuple"; +export * from "./typedarray"; +export * from "./watch"; -export * from "./constants"; -export * from "./expose"; -export * from "./logger"; +export * from "./api"; export * from "./mixin"; export * from "./decorators/configurable"; diff --git a/packages/api/src/api/indexed.ts b/packages/api/src/indexed.ts similarity index 100% rename from packages/api/src/api/indexed.ts rename to packages/api/src/indexed.ts diff --git a/packages/api/src/api/into.ts b/packages/api/src/into.ts similarity index 100% rename from packages/api/src/api/into.ts rename to packages/api/src/into.ts diff --git a/packages/api/src/api/keyval.ts b/packages/api/src/keyval.ts similarity index 100% rename from packages/api/src/api/keyval.ts rename to packages/api/src/keyval.ts diff --git a/packages/api/src/api/length.ts b/packages/api/src/length.ts similarity index 100% rename from packages/api/src/api/length.ts rename to packages/api/src/length.ts diff --git a/packages/api/src/logger.ts b/packages/api/src/logger.ts deleted file mode 100644 index 7b9a28bd07..0000000000 --- a/packages/api/src/logger.ts +++ /dev/null @@ -1,45 +0,0 @@ -import type { ILogger } from "./api/logger"; -import { LogLevel } from "./api/logger"; - -export const NULL_LOGGER: ILogger = Object.freeze({ - level: LogLevel.NONE, - fine() {}, - debug() {}, - info() {}, - warn() {}, - severe() {}, -}); - -export class ConsoleLogger implements ILogger { - id: string; - level: LogLevel; - - constructor(id: string, level = LogLevel.FINE) { - this.id = id; - this.level = level; - } - - fine(...args: any[]): void { - this.level <= LogLevel.FINE && this.log("FINE", args); - } - - debug(...args: any[]): void { - this.level <= LogLevel.DEBUG && this.log("DEBUG", args); - } - - info(...args: any[]): void { - this.level <= LogLevel.INFO && this.log("INFO", args); - } - - warn(...args: any[]): void { - this.level <= LogLevel.WARN && this.log("WARN", args); - } - - severe(...args: any[]): void { - this.level <= LogLevel.SEVERE && this.log("SEVERE", args); - } - - protected log(level: string, args: any[]) { - console.log(`[${level}] ${this.id}:`, ...args); - } -} diff --git a/packages/api/src/api/meta.ts b/packages/api/src/meta.ts similarity index 100% rename from packages/api/src/api/meta.ts rename to packages/api/src/meta.ts diff --git a/packages/api/src/mixins/ienable.ts b/packages/api/src/mixins/ienable.ts index c884f52dd5..c831522ac5 100644 --- a/packages/api/src/mixins/ienable.ts +++ b/packages/api/src/mixins/ienable.ts @@ -1,6 +1,6 @@ -import type { IEnable } from "../api/enable"; -import type { Event } from "../api/event"; -import { EVENT_DISABLE, EVENT_ENABLE } from "../constants"; +import { EVENT_DISABLE, EVENT_ENABLE } from "../api"; +import type { IEnable } from "../enable"; +import type { Event } from "../event"; import { mixin } from "../mixin"; interface _IEnable extends IEnable { diff --git a/packages/api/src/mixins/inotify.ts b/packages/api/src/mixins/inotify.ts index 9518882107..5e3bace45c 100644 --- a/packages/api/src/mixins/inotify.ts +++ b/packages/api/src/mixins/inotify.ts @@ -1,7 +1,7 @@ -import type { Event, INotify, Listener } from "../api/event"; -import type { IObjectOf } from "../api/object"; -import { EVENT_ALL } from "../constants"; +import { EVENT_ALL } from "../api"; +import type { Event, INotify, Listener } from "../event"; import { mixin } from "../mixin"; +import type { IObjectOf } from "../object"; interface _INotify extends INotify { _listeners: IObjectOf<[Listener, any][]>; diff --git a/packages/api/src/mixins/iwatch.ts b/packages/api/src/mixins/iwatch.ts index ac2e324783..229b629b8d 100644 --- a/packages/api/src/mixins/iwatch.ts +++ b/packages/api/src/mixins/iwatch.ts @@ -1,6 +1,6 @@ -import type { IObjectOf } from "../api/object"; -import type { IWatch, Watch } from "../api/watch"; import { mixin } from "../mixin"; +import type { IObjectOf } from "../object"; +import type { IWatch, Watch } from "../watch"; interface _IWatch extends IWatch { _watches: IObjectOf>; diff --git a/packages/api/src/api/null.ts b/packages/api/src/null.ts similarity index 100% rename from packages/api/src/api/null.ts rename to packages/api/src/null.ts diff --git a/packages/api/src/api/object.ts b/packages/api/src/object.ts similarity index 100% rename from packages/api/src/api/object.ts rename to packages/api/src/object.ts diff --git a/packages/api/src/api/path.ts b/packages/api/src/path.ts similarity index 100% rename from packages/api/src/api/path.ts rename to packages/api/src/path.ts diff --git a/packages/api/src/api/predicate.ts b/packages/api/src/predicate.ts similarity index 100% rename from packages/api/src/api/predicate.ts rename to packages/api/src/predicate.ts diff --git a/packages/api/src/api/prim.ts b/packages/api/src/prim.ts similarity index 100% rename from packages/api/src/api/prim.ts rename to packages/api/src/prim.ts diff --git a/packages/api/src/api/range.ts b/packages/api/src/range.ts similarity index 100% rename from packages/api/src/api/range.ts rename to packages/api/src/range.ts diff --git a/packages/api/src/api/release.ts b/packages/api/src/release.ts similarity index 100% rename from packages/api/src/api/release.ts rename to packages/api/src/release.ts diff --git a/packages/api/src/api/reset.ts b/packages/api/src/reset.ts similarity index 100% rename from packages/api/src/api/reset.ts rename to packages/api/src/reset.ts diff --git a/packages/api/src/api/select.ts b/packages/api/src/select.ts similarity index 100% rename from packages/api/src/api/select.ts rename to packages/api/src/select.ts diff --git a/packages/api/src/api/seq.ts b/packages/api/src/seq.ts similarity index 100% rename from packages/api/src/api/seq.ts rename to packages/api/src/seq.ts diff --git a/packages/api/src/api/set.ts b/packages/api/src/set.ts similarity index 100% rename from packages/api/src/api/set.ts rename to packages/api/src/set.ts diff --git a/packages/api/src/api/stack.ts b/packages/api/src/stack.ts similarity index 100% rename from packages/api/src/api/stack.ts rename to packages/api/src/stack.ts diff --git a/packages/api/src/api/tuple.ts b/packages/api/src/tuple.ts similarity index 100% rename from packages/api/src/api/tuple.ts rename to packages/api/src/tuple.ts diff --git a/packages/api/src/api/typedarray.ts b/packages/api/src/typedarray.ts similarity index 100% rename from packages/api/src/api/typedarray.ts rename to packages/api/src/typedarray.ts diff --git a/packages/api/src/api/watch.ts b/packages/api/src/watch.ts similarity index 100% rename from packages/api/src/api/watch.ts rename to packages/api/src/watch.ts